diff --git a/docs_md_vuepress_pipeline/run.py b/docs_md_vuepress_pipeline/run.py index c385e42684c867eec9ef40fded69b1ca5c3d4b56..06dc9eaf85c31f8d0103e76fa1926a3454457db6 100644 --- a/docs_md_vuepress_pipeline/run.py +++ b/docs_md_vuepress_pipeline/run.py @@ -25,44 +25,140 @@ # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - +# -*- coding: utf-8 -*- + import datetime import os +from posixpath import relpath import sys +import codecs +import json +import hashlib sys.path.insert(0, os.path.abspath('.')) os.system('mkdir -p out/') os.system('mkdir -p docs_vuepress/docs') -INPUT_DOC_ROOT = os.path.join(os.getcwd(), 'docs/zh-cn') -OUTPUT_DOC_ROOT = os.path.join(os.getcwd(), 'docs_vuepress/docs') +dstConf = [ + { + 'subpath':'zh-cn', + 'permalinkPrefix':'/pages/zh-cn', + 'fixdir':'了解OpenHarmony' + }, + { + 'subpath':'zh-cn/device-dev', + 'permalinkPrefix':'/pages/zh-cn/device', + 'fixdir':'设备开发文档' + }, + { + 'subpath':'zh-cn/application-dev', + 'permalinkPrefix':'/pages/zh-cn/app', + 'fixdir':'应用开发文档' + }, + { + 'subpath':'en', + 'permalinkPrefix':'/pages/en', + 'fixdir':'overview' + }, + { + 'subpath':'en/device-dev', + 'permalinkPrefix':'/pages/en/device', + 'fixdir':'device' + }, + { + 'subpath':'en/application-dev', + 'permalinkPrefix':'/pages/en/app', + 'fixdir':'application' + }, +] + +brancheName = 'OpenHarmony-3.1-Release' # or 'master' + +def getBestSubpath(nodeInfo): + subpath = nodeInfo['dir'] + can_used = None + result = [] + for item in dstConf: + if item['subpath'] in subpath: + result.append(item) + if len(result) > 0: + depth = 0 + for re in result: + if len(re['subpath']) > depth: + depth = len(re['subpath']) + can_used = re + relpath = subpath.split(can_used['subpath']) + if len(relpath) == 0: + relpath = '' + else: + relpath = relpath[1] + return (can_used, relpath) + +rootPath = os.path.join(os.getcwd(), 'docs') +def makePermalink(nodeInfo, index, cate): + # title, dir, [md_path, chirldren], depth + can_used,_ = getBestSubpath(nodeInfo) + fullpath = os.path.join(nodeInfo['dir'], nodeInfo['md_path']) + relpath = os.path.relpath(fullpath, rootPath) + # plink = hashlib.md5(relpath.encode('utf-8')).hexdigest() + plink = '/'.join(cate) + '/' + nodeInfo['title'] + if can_used : + return os.path.join(can_used['permalinkPrefix'], plink) + return os.path.join('/pages', plink) + +def detectedFilename(nodeInfo, index): + return f'{index+1:02d}.{nodeInfo["title"]}' + +def detectedGitPath(fullpath): + relpath = os.path.relpath(fullpath, rootPath) + return f'\"{os.path.join(brancheName, relpath)}\"' + +def main(dirs): + + # INPUT_DOC_ROOT = os.path.join(os.getcwd(), f'docs/{srcDir}') + OUTPUT_DOC_ROOT = os.path.join(os.getcwd(), 'docs_vuepress/docs') + + TIME_STAMP = datetime.datetime.now().timestamp() -TIME_STAMP = datetime.datetime.now().timestamp() + handler = { + 'makePermalink':makePermalink, + 'detectedFilename':detectedFilename, + 'detectedGitPath':detectedGitPath, + } + # DOC_TREE_FILENAME = os.path.join(INPUT_DOC_ROOT, 'website-directory.md') + RAW_DOC_JSON_FILENAME = f'out/s1-raw.json' + NOT_FOUND_DOC_TREE_FILENAME = f'out/s1-not_found.txt' + ENHANCED_DOC_INDEX_FILENAME = f'out/s2-doc_index.json' + DOC_TABLE_FILENAME = f'out/s3-doc_table.json' -DOC_TREE_FILENAME = os.path.join(INPUT_DOC_ROOT, 'website-directory.md') -RAW_DOC_JSON_FILENAME = f'out/{TIME_STAMP}s1-raw.json' -NOT_FOUND_DOC_TREE_FILENAME = f'out/{TIME_STAMP}s1-not_found.txt' -ENHANCED_DOC_INDEX_FILENAME = f'out/{TIME_STAMP}s2-doc_index.json' -DOC_TABLE_FILENAME = f'out/{TIME_STAMP}s3-doc_table.json' + POSTS_DOC_TABLE_FILENAME = f'out/s4-posts_table.json' + MODIFIED_LIST_FILENAME = f'out/s4-mod.json' + NOT_FOUND_LIST_FILENAME = f'out/s4-not_mod.json' -POSTS_DOC_TABLE_FILENAME = f'out/{TIME_STAMP}s4-posts_table.json' -MODIFIED_LIST_FILENAME = f'out/{TIME_STAMP}s4-mod.json' -NOT_FOUND_LIST_FILENAME = f'out/{TIME_STAMP}s4-not_mod.json' + output_list = [] + for dirConf in dirs: + # for sources in DOC_TREE_FILENAMES: + dir = dirConf['subpath'] + INPUT_DOC_ROOT = os.path.join(rootPath, dir) + DOC_TREE_FILENAME = os.path.join(rootPath, dir, 'website.md') + tmp = parse_doc_tree_main(dirConf, INPUT_DOC_ROOT, DOC_TREE_FILENAME) + output_list.extend(tmp) + adjust_doc_tree_to_index(output_list) + with codecs.open(RAW_DOC_JSON_FILENAME, 'w', encoding='utf-8') as outputFile: + json.dump(output_list, outputFile, indent=2, ensure_ascii=False) -def main(): - parse_doc_tree_main(DOC_TREE_FILENAME, RAW_DOC_JSON_FILENAME) - check_file_list_existence(RAW_DOC_JSON_FILENAME, INPUT_DOC_ROOT, - NOT_FOUND_DOC_TREE_FILENAME) - enhance_json_info_main(RAW_DOC_JSON_FILENAME, ENHANCED_DOC_INDEX_FILENAME, - INPUT_DOC_ROOT) - copy_md_main(ENHANCED_DOC_INDEX_FILENAME, INPUT_DOC_ROOT, OUTPUT_DOC_ROOT, + check_file_list_existence(rootPath, output_list, NOT_FOUND_DOC_TREE_FILENAME) + page_indexs = enhance_json_info_main(rootPath, output_list, OUTPUT_DOC_ROOT, ENHANCED_DOC_INDEX_FILENAME, + handler) + copy_md_main(page_indexs, OUTPUT_DOC_ROOT, MODIFIED_LIST_FILENAME, NOT_FOUND_LIST_FILENAME) if __name__ == '__main__': - from step_1_parse_doc_tree import parse_doc_tree_main, check_file_list_existence - from step_2_enhance_json_info import enhance_json_info_main + from step_1_parse_doc_tree_md import parse_doc_tree_main, check_file_list_existence + # from step_1_parse_doc_tree import parse_doc_tree_main, check_file_list_existence + from step_2_enhance_json_info import enhance_json_info_main, adjust_doc_tree_to_index from step_3_copy_md import copy_md_main - main() + main(dstConf) diff --git a/docs_md_vuepress_pipeline/run.sh b/docs_md_vuepress_pipeline/run.sh index bffb555efd24ccd65578cdd75253b68a3a8eb02a..0df4f227df8f6e2e7dea5474db48e6f1280b15e5 100755 --- a/docs_md_vuepress_pipeline/run.sh +++ b/docs_md_vuepress_pipeline/run.sh @@ -1,6 +1,8 @@ #!/bin/bash rm -rf docs/ -git clone git@gitee.com:openharmony/docs.git +rm -rf docs_vuepress +rm -rf out +git clone https://gitee.com/openharmony/docs.git python run.py diff --git a/docs_md_vuepress_pipeline/step_1_parse_doc_tree_md.py b/docs_md_vuepress_pipeline/step_1_parse_doc_tree_md.py new file mode 100644 index 0000000000000000000000000000000000000000..8c6606fb59c484eb7d4c1126c06412963276380e --- /dev/null +++ b/docs_md_vuepress_pipeline/step_1_parse_doc_tree_md.py @@ -0,0 +1,194 @@ +# en/website.md +# en/application-dev/website.md +# en/device-dev/website.md +# zh-cn/website.md +# zh-cn/application-dev/website.md +# zh-cn/device-dev/website.md +import codecs +import copy +import json +import os +import re +import string + +from sympy import root + +titleReg = re.compile(r'^(#+) (.+)$') +itemReg1 = re.compile(r'\s*\- +?(.+)') +itemReg2 = re.compile(r'\s*\* +?(.+)') +mdlinkReg = re.compile(r'\s*\[(.+)\]\s*\((.+)\)') + +def parse_line(line: str, basedepth): + result = {} + titleResult = titleReg.match(line) + if titleResult: + td = titleResult.group(1) + title = titleResult.group(2) + result['isLevelTitle'] = True + result['title'] = title + result['depth'] = len(td) + else: + itemResult = itemReg1.match(line) + # deep + if itemResult : + deep = line.split('-') + if len(deep) < 2: + result['ingored'] = line + return result + else: + ndeep = len(deep[0]) + result['depth'] = ndeep + basedepth + else : + itemResult = itemReg2.match(line) + if itemResult : + deep = line.split('*') + if len(deep) < 2: + result['ingored'] = line + return result + else: + ndeep = len(deep[0]) + result['depth'] = ndeep + basedepth + # subtitle + if itemResult: + item = itemResult.group(1) + mdlinkResult = mdlinkReg.match(item) + if mdlinkResult : + subtitle = mdlinkResult.group(1) + mdpath = mdlinkResult.group(2) + + result['title'] = subtitle + result['md_path'] = mdpath + else: + result['title'] = item + else: + result['ingored'] = line + return result + +def filter_title(title: str): + title = title.replace(' ', '-') # ' ' + title = title.replace('\\', '') # '\' + title = title.replace('"', '') # "'" + return title + + +def plant_tree(lines_info: list) -> list: + last_origin_depth = 1 + current_depth = 1 + current_list = [] + depth_stack = [] + level_stack = [] + if len(lines_info) == 0: + return + index = 0 + while index < len(lines_info): + line_info = lines_info[index] + print(line_info, '; depth =', current_depth) # DEBUG + if line_info['depth'] > last_origin_depth: #current_depth: + # assert line_info['depth'] - 1 == current_depth + level_stack.append(current_list) + current_depth += 1 + current_json = copy.deepcopy(line_info) + current_json['depth'] = current_depth + current_list = [current_json] + index += 1 + depth_stack.append(last_origin_depth) + last_origin_depth = line_info['depth'] + elif line_info['depth'] == last_origin_depth: + current_json = copy.deepcopy(line_info) + current_json['depth'] = current_depth + current_list.append(current_json) + index += 1 + else: + child_list = current_list + current_list = level_stack.pop() + last_origin_depth = depth_stack.pop() + current_list[-1]['children'] = child_list + current_depth -= 1 + continue + + while level_stack: + child_list = current_list + tmplist = level_stack.pop() + if len(tmplist) == 0: + continue + current_list = tmplist + current_list[-1]['children'] = child_list + + return current_list + + +def check_file_list_existence(rootPath, file_list: list, + output_file_list: str): + not_found_list = [] + + def _check_file_existence(json_list: list): + for json_dict in json_list: + if 'children' in json_dict: + _check_file_existence(json_dict['children']) + elif 'md_path' in json_dict: + input_doc_root = json_dict['dir'] + file_abs_path = os.path.join(input_doc_root, json_dict['md_path']) + rel_path = os.path.normcase( os.path.relpath(file_abs_path, rootPath)) + if not os.path.exists(file_abs_path): + + print(json_dict['title'], 'md 文件不存在!') + not_found_list.append(rel_path) + else: + print(json_dict['title'], '没有 md 文件路径!') + not_found_list.append(f'{json_dict["title"]} :没有 md 文件路径') + + # with codecs.open(input_file_list, 'r', encoding='utf-8') as inFile: + # file_list = json.load(inFile) + + _check_file_existence(file_list) + + with codecs.open(output_file_list, 'w', encoding='utf-8') as outputFile: + for not_found_file in not_found_list: + outputFile.write(not_found_file) + outputFile.write('\n') + + # assert len(not_found_list) == 0, '目录存在无效链接!' + +def _check_level_title(subctx, lines_info): + for line in lines_info: + if 'isLevelTitle' in line: + line['title'] = subctx['fixdir'] + return + for line in lines_info: + line['depth'] += 1 + lines_info.insert(0, {'isLevelTitle':True, 'title':subctx['fixdir'], 'depth':1}) + + +def parse_doc_tree_main(subctx, input_doc_root, input_filename): + LINES_INFO = [] + basedepth = 0 + ''' STEP 1a: 读取 md 文档树,记录每一行的信息 ''' + with codecs.open(input_filename, 'r', encoding='utf-8') as inputFile: + for line in inputFile: + # line = line.translate({ord(c): None for c in string.whitespace}) + line = line.replace('@', '') + if not line: + continue + line_info = parse_line(line, basedepth+1) + if 'ingored' in line_info: + print(f"ingored: {line_info['ingored']}") + continue + + if 'isLevelTitle' in line_info: + basedepth = line_info['depth'] + line_info['dir'] = input_doc_root + # print(f'get:{json.dumps(line_info)}') + LINES_INFO.append(line_info) + # print(line_info) # DEBUG + + ''' STEP 1b: 以深度为单位统计信息,使用 stack 数据结构 ''' + _check_level_title(subctx, LINES_INFO) + output_list = plant_tree(LINES_INFO) + + return output_list + +if __name__ == '__main__': + fpath = '应用开发.md' + opath = 's1-raw.json' + parse_doc_tree_main(fpath, opath) + diff --git a/docs_md_vuepress_pipeline/step_2_enhance_json_info.py b/docs_md_vuepress_pipeline/step_2_enhance_json_info.py index b154288cbecbbc9fb6b5d6b03dbbfc156d87ecc3..fcb56add26ec40cc398b80391de76ca38031203f 100644 --- a/docs_md_vuepress_pipeline/step_2_enhance_json_info.py +++ b/docs_md_vuepress_pipeline/step_2_enhance_json_info.py @@ -25,30 +25,112 @@ # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# -*- coding: utf-8 -*- import codecs import json import os import random +import urllib.parse +import hashlib + +from numpy import array +import copy PERMALINK_SET = set() PAGE_INDEX = {} +title_replacer = { + "'":' ', + "\"":' ', + "“":' ', + "/":' ', + "\\":' ', + ":":' ', + ":":' ' + # "(":' ', + # ")":' ' +} +def adjust_title(title, patterns): + out = '' + for ind, c in enumerate(title): + if c in patterns: + out += patterns[c] + else: + out += c + return out + +def encodeUrl(url): + return urllib.parse.quote(url) + +def adjust_doc_tree_to_index(json_list: list): + for index, json_dict in enumerate(json_list): + json_dict['title'] = adjust_title(json_dict['title'], title_replacer) + if 'children' in json_dict and 'md_path' in json_dict: + nc = {'depth':json_dict['depth']+1, 'title':json_dict['title'], 'md_path':json_dict['md_path'], 'dir':json_dict['dir']} + del json_dict['md_path'] + json_dict['children'].insert(0, nc) + + if 'children' in json_dict: + adjust_doc_tree_to_index(json_dict['children']) + +def doc_tree_to_entry(index, json_dict: list, handlers, siderbar): + if 'isLevelTitle' not in json_dict: + return + + entry_name = handlers['detectedFilename'](json_dict, index) + entry = f'/{entry_name}/' + entryChildren = [] + cates = [] + cates.append(json_dict["title"]) + # cates.append(f'\"{json_dict["title"]}\"') + doc_tree_to_index(json_dict['children'], handlers, entry, entryChildren, cates, entry_name) + + siderbar[entry] = entryChildren + +def doc_tree_to_index(json_list: list, handlers, entryPath, sidebar, cates: list=[], parent_path: str='') -> None: -def doc_tree_to_index(json_list: list, parent_path: str='', parent_doc_id: str='/pages/') -> None: for index, json_dict in enumerate(json_list): - file_name = f'{(index+1):02}.{json_dict["title"]}' - permalink = parent_doc_id + f'{(index+1):02x}' + # file_name = f'{(index+1):02}.{json_dict["title"]}' + file_name = handlers['detectedFilename'](json_dict, index) + cur_cate = [cate for cate in cates] + + if 'children' in json_dict and 'md_path' in json_dict: + assert False if 'children' in json_dict: - doc_tree_to_index(json_dict['children'], os.path.join(parent_path, file_name), permalink) + cur_cate.append(json_dict["title"]) # f'\"{json_dict["title"]}\"') + sidebarNode = { + 'title' : json_dict['title'], + 'collapsable':True, + 'children':[] + } + doc_tree_to_index(json_dict['children'], handlers, entryPath, sidebarNode['children'], cur_cate, os.path.join(parent_path, file_name)) + sidebar.append(sidebarNode) else: - PAGE_INDEX[json_dict['md_path']] = { + permalink = handlers['makePermalink'](json_dict, index, cur_cate) + if permalink in PERMALINK_SET: + return + # file_name = json_dict['md_path'] + sidebarPath = file_name+'.md' + sidebarNode = [ + sidebarPath, + json_dict['title'], + permalink, + ] + sidebar.append(sidebarNode) + + fullpath = os.path.join(json_dict['dir'], json_dict['md_path']) + PAGE_INDEX[fullpath] = { # 'title': json_dict["title"], - 'target_path': os.path.join(parent_path, file_name) + '.md', + 'target_path': os.path.join(parent_path, file_name+'.md'), + 'root_path' : json_dict['dir'], + 'md_path' : json_dict['md_path'], # 'permalink': permalink, 'front matter': { - 'title': json_dict['title'], - 'permalink': permalink, + 'title': f'\"{json_dict["title"]}\"', + 'prepermalink':permalink, + 'permalink': encodeUrl(permalink), + 'relpath':handlers['detectedGitPath'](fullpath), 'navbar': 'true', 'sidebar': 'true', 'prev': 'true', @@ -56,54 +138,69 @@ def doc_tree_to_index(json_list: list, parent_path: str='', parent_doc_id: str=' 'search': 'true', 'article': 'true', 'comment': 'false', - 'editLink': 'false' + 'editLink': 'true', + 'categories': '[' + ','.join(cur_cate) + ']' } } assert permalink not in PERMALINK_SET, f'Duplicated permalink: {permalink}' PERMALINK_SET.add(permalink) - -def add_all_md_to_index(input_doc_root: str, parent_path: str='') -> None: +def add_all_md_to_index(input_doc_root: str, handlers, parent_path: str='') -> None: abs_parent_path = os.path.join(input_doc_root, parent_path) files = os.listdir(abs_parent_path) for file in files: relative_path = os.path.join(parent_path, file) + fullpath = os.path.normcase(os.path.join(input_doc_root, relative_path)) if os.path.isdir(os.path.join(abs_parent_path, file)): - add_all_md_to_index(input_doc_root, relative_path) + add_all_md_to_index(input_doc_root, handlers, relative_path) elif file[-3:] == '.md': - if relative_path in PAGE_INDEX: + if fullpath in PAGE_INDEX: pass else: - permalink = f'/pages/extra/{random.randint(0, 16777215):06x}/' - PAGE_INDEX[relative_path] = { + permalink = hashlib.md5(relative_path.encode('utf-8')).hexdigest() + permalink = f'/extras/{permalink}/' + title = file.replace('.md', '') + PAGE_INDEX[fullpath] = { # 'title': file.replace('.md', ''), - 'target_path': os.path.join('_posts/zh-cn', relative_path), + 'target_path': os.path.join('extras/', relative_path), + 'root_path' : input_doc_root, + 'md_path' : relative_path, # 'permalink': permalink, 'front matter': { - 'title': file.replace('.md', ''), - 'permalink': permalink, + 'title': f'\"{title}\"', + 'prepermalink': permalink, + 'permalink': encodeUrl(permalink), + 'relpath':handlers['detectedGitPath'](fullpath), 'navbar': 'true', 'sidebar': 'false', 'prev': 'false', 'next': 'false', - 'search': 'true', - 'article': 'true', + 'search': 'false', + 'article': 'false', 'comment': 'false', 'editLink': 'false', + 'categories': '[' + title + ']' } } -def enhance_json_info_main(input_filename, output_filename, input_doc_root): - with codecs.open(input_filename, 'r', encoding='utf-8') as inFile: - INPUT_JSON_DICT = json.load(inFile) +def enhance_json_info_main(rootPath, INPUT_JSON_DICT, output_dir_root, output_filename, handlers): + # with codecs.open(input_filename, 'r', encoding='utf-8') as inFile: + # INPUT_JSON_DICT = json.load(inFile) + sidebar = {} + for index, entry in enumerate(INPUT_JSON_DICT): + doc_tree_to_entry(index, entry, handlers, sidebar) - doc_tree_to_index(INPUT_JSON_DICT) - add_all_md_to_index(input_doc_root) + add_all_md_to_index(rootPath, handlers) + # with codecs.open(os.path.join(output_dir_root,'siderbar.json'), 'w', encoding='utf-8') as outFile: + # json.dump(sidebar, outFile, indent=2, ensure_ascii=False) + # doc_tree_to_index(INPUT_JSON_DICT, handlers) + # add_all_md_to_index(input_doc_root) with codecs.open(output_filename, 'w', encoding='utf-8') as outFile: json.dump(PAGE_INDEX, outFile, indent=2, ensure_ascii=False) + return PAGE_INDEX if __name__ == '__main__': pass diff --git a/docs_md_vuepress_pipeline/step_3_copy_md.py b/docs_md_vuepress_pipeline/step_3_copy_md.py index a0bfa9e1dcde23bfeadcdc1ff100f8060b78472b..9752b4a8d84cc936a34ccfc41239afdf2a181fa0 100644 --- a/docs_md_vuepress_pipeline/step_3_copy_md.py +++ b/docs_md_vuepress_pipeline/step_3_copy_md.py @@ -30,9 +30,65 @@ import codecs import json import os import re +import hashlib MD_DOC_INDEX = None +def findMdLink(line, patterns): + result = [] + pos = -1 + count = 0 + linkpos = [] + def isLink(line, patterns): + # file:///xxx.yyy tttt + # http[s]://adfdf + # xxx.png[gif,jpg,md] txt + # xxx.png[gif,jpg,md]#txt + # #txtsdfs + lline = line.lower() + # exts = ['.gif','.png', '.jpg','.jpeg','.md'] + for ext in patterns: + pos = lline.rfind(ext, 0) + if pos != -1: + return line[0:pos+len(ext)] + return None + + while True: + pos = line.find('![', pos+1) + if pos == -1 : + break + mpos = line.find(f'](', pos) + if mpos == -1: + break + linkpos.append([pos, mpos, -1, '']) + count += 1 + + pos = -1 + rpos = len(line) + for ind in range(0, -len(linkpos), -1): + ind -= 1 + lk = linkpos[ind] + while True: + rpos = line.rfind(')', 0, rpos) + subtxt = line[lk[1]+2:rpos] + txt = isLink(subtxt, patterns) + if txt != None: + lk[2] = rpos + lk[3] = txt + break + if rpos <= lk[1]: + break + rpos = lk[0] + + for lk in linkpos: + if lk[1] > lk[0]+2: + title = line[lk[0]+2:lk[1]] + else: + title = '' + link = lk[3] + result.append((title, link)) + return result + # MD_LINK_REGEX = re.compile('\[.*\]\((.*\.md)') # 误判情况: [xxx](xxx.md) xxx [xxx](xxx.md) # MD_LINK_REGEX = re.compile('\[.*?\]\((.*?\.md)') # 误判情况: [xxx](https://xxx.com/xxx) xxx [xxx](xxx.md) MD_LINK_REGEX = re.compile('\[[^\[]*?\]\(([^\[]*?\.md)') @@ -64,19 +120,18 @@ def resolve_md_links(md_text: str, in_md_abs_path: str, out_md_abs_path: str, continue for pattern in md_link_patterns: # 处理这一行中出现的所有 md 链接 pattern - if 'https://' in pattern: + if 'https://' in pattern or 'http://' in pattern: # 特殊情况:https://,引用了网上的 md 文件 # 解决方法:无视之 not_modified_list.append({ 'input_md': in_md_abs_path, 'output_md': out_md_abs_path, 'line_no': lineno + 1, - 'pattern': pattern, - 'handle': 'ignore', + 'link': pattern, + 'action': 'ignore', }) failed_counter += 1 continue - # 得到该文件链接指向的 工程目录绝对路径,清除掉所有 “.” “..” # source_md_abs_path: 源 md 所在的绝对路径 source_md_abs_path = os.path.normpath( @@ -92,6 +147,8 @@ def resolve_md_links(md_text: str, in_md_abs_path: str, out_md_abs_path: str, # source_md_rel_path: 源 md 文档的相对路径 source_md_rel_path = os.path.join(source_md_rel_pwd_path, source_md_name) + link_abs = os.path.join(in_md_abs_pwd_path, pattern) + source_md_rel_path = os.path.relpath(source_md_abs_path, input_doc_root) if '.md' not in source_md_rel_path: print(f'ERROR: {source_md_name}') @@ -101,44 +158,41 @@ def resolve_md_links(md_text: str, in_md_abs_path: str, out_md_abs_path: str, print(f'ERROR: {source_md_rel_pwd_path}') assert False - if source_md_rel_path not in MD_DOC_INDEX: + if source_md_abs_path not in MD_DOC_INDEX: # 如果没找到指定的 md,删掉此行,记录在案 not_modified_list.append({ 'input_md': in_md_abs_path, 'output_md': out_md_abs_path, 'line_no': lineno + 1, - 'pattern': pattern, + 'link': pattern, 'source_md_abs_path': source_md_abs_path, 'source_md_rel_path': source_md_rel_path, - 'handle': 'delete', + 'action': 'keep', }) + line = line.replace(pattern, f'https://www.openharmony.cn/404/{pattern}') failed_counter += 1 - line = '' - continue - - # 如果找到了此 md,则替换相对链接为 permalink - md_permalink = MD_DOC_INDEX[source_md_rel_path]['front matter'][ - 'permalink'] - # 最后把跳转链接插入到 md 文档中 - line = line.replace(pattern, md_permalink) - - modified_list.append({ - 'input_md': in_md_abs_path, - 'output_md': out_md_abs_path, - 'line_no': lineno + 1, - 'pattern': pattern, - 'source_md_abs_path': source_md_abs_path, - 'source_md_rel_path': source_md_rel_path, - # 'target_md_abs_path': target_md_abs_path, - 'permalink': md_permalink, - }) - replace_counter += 1 - - mod_lines.append(line) - print(f'已完成:resolve_md_links(..., {in_md_abs_path}, {out_md_abs_path})' - ) # DEBUG - print( - f'\t成功替换了:{replace_counter}个 md 链接,未能成功替换:{failed_counter}个。') # DEBUG + else : + # 如果找到了此 md,则替换相对链接为 permalink + md_permalink = MD_DOC_INDEX[source_md_abs_path]['front matter'][ + 'permalink'] + # 最后把跳转链接插入到 md 文档中 + line = line.replace(pattern, md_permalink) + + modified_list.append({ + 'input_md': in_md_abs_path, + 'output_md': out_md_abs_path, + 'line_no': lineno + 1, + 'link': pattern, + 'source_md_abs_path': source_md_abs_path, + 'source_md_rel_path': source_md_rel_path, + # 'target_md_abs_path': target_md_abs_path, + 'permalink': md_permalink, + }) + replace_counter += 1 + if line != None: + mod_lines.append(line) + # print(f'已完成:resolve_md_links(..., {in_md_abs_path}, {out_md_abs_path})') # DEBUG + # print(f'\t成功替换了:{replace_counter}个 md 链接,未能成功替换:{failed_counter}个。') # DEBUG return '\n'.join(mod_lines) @@ -152,24 +206,40 @@ def resolve_image_links(md_text, in_md_abs_path, out_md_abs_path, replace_counter = 0 failed_counter = 0 for lineno, line in enumerate(raw_lines): - img_relative_path = [] - img_relative_path += re.findall(GIF_LINK_REGEX, line) - img_relative_path += re.findall(JPG_LINK_REGEX, line) - img_relative_path += re.findall(PNG_LINK_REGEX, line) + tmplinks = findMdLink(line, ['.gif', '.jpg', '.jpeg', '.png']) + img_relative_path = [ rp[1] for rp in tmplinks] + + # img_relative_path += re.findall(GIF_LINK_REGEX, line) + # img_relative_path += re.findall(JPG_LINK_REGEX, line) + # img_relative_path += re.findall(PNG_LINK_REGEX, line) + if len(img_relative_path) == 0: # 这一行是普通文本,regex 没找到图片链接 mod_lines.append(line) else: for pattern in img_relative_path: - if 'https://' in pattern: + if 'file://' in pattern: + not_modified_list.append({ + 'input_md': in_md_abs_path, + 'output_md': out_md_abs_path, + 'line_no': lineno + 1, + 'link': pattern, + 'source_img': source_img_path, + 'action': 'delete', + }) + failed_counter += 1 + line = '' + continue + + if 'http://' in pattern or 'https://' in pattern: # 特殊情况:https://,引用了网上的图片 # 解决方法:无视之 not_modified_list.append({ 'input_md': in_md_abs_path, 'output_md': out_md_abs_path, 'line_no': lineno + 1, - 'pattern': pattern, - 'handle': 'ignore', + 'link': pattern, + 'action': 'ignore', }) failed_counter += 1 continue @@ -179,6 +249,18 @@ def resolve_image_links(md_text, in_md_abs_path, out_md_abs_path, source_img_path = os.path.normpath( os.path.join(in_md_abs_pwd_path, pattern)) if not os.path.exists(source_img_path): + # 如果没找到指定的图片,删掉此行,记录在案 + not_modified_list.append({ + 'input_md': in_md_abs_path, + 'output_md': out_md_abs_path, + 'line_no': lineno + 1, + 'link': pattern, + 'source_img': source_img_path, + 'action': 'delete', + }) + failed_counter += 1 + line = '' + continue # 如果没找到指定的图片,删掉此行,记录在案 not_modified_list.append({ 'input_md': in_md_abs_path, @@ -186,61 +268,69 @@ def resolve_image_links(md_text, in_md_abs_path, out_md_abs_path, 'line_no': lineno + 1, 'pattern': pattern, 'source_img': source_img_path, - 'handle': 'delete', + 'action': 'delete', }) failed_counter += 1 line = '' continue else: + with open(source_img_path, 'rb') as imgHandler: + bx = imgHandler.read() + fname = hashlib.md5(bx).hexdigest() + # 如果在 image 文件列表内找到了此图片,则创建 images/... 文件夹, # 移动图片文件到 images/...,更新相对路径,插入到 md 文档中 # img_pwd_path: 原图片所在文件夹的绝对路径 - img_pwd_path = '/'.join(source_img_path.split('/')[:-1]) - # source_img_rel_path: 原图片所在文件夹的相对路径(相对于 docs repo root) - source_img_rel_path = img_pwd_path.replace( - input_doc_root, '') + source_img_dir = os.path.dirname(source_img_path) + source_img_rel = os.path.relpath(source_img_dir, input_doc_root) + + source_img_fname = os.path.basename(source_img_path) + source_img_ext = os.path.splitext(source_img_fname)[-1] + out_img_fname = fname + source_img_ext.lower() + # vdoing_img_pwd_path: 复制图片所在文件夹的相对路径(相对于 public 文件夹) vdoing_img_pwd_path = os.path.join('images', - source_img_rel_path) + source_img_rel) # target_img_pwd_path: 复制图片所在文件夹的绝对路径(mv 命令的 destination) target_img_pwd_path = os.path.join(output_doc_root, vdoing_img_pwd_path) os.system(f'mkdir -p "{target_img_pwd_path}"') os.system( - f'cp "{source_img_path}" "{target_img_pwd_path}"') - # raw_img_pwd_path: 原图片所在目录的相对路径(需要替换为相对于 public 文件夹的相对路径) - raw_img_pwd_path = '/'.join(pattern.split('/')[:-1]) - line = line.replace(raw_img_pwd_path, - '/' + vdoing_img_pwd_path) + f'cp "{source_img_path}" "{target_img_pwd_path}/{out_img_fname}"') + + out_dir = os.path.dirname(out_md_abs_path) + vdoing_image_rel = os.path.relpath(target_img_pwd_path, out_dir) + vdoing_image_rel = os.path.join(vdoing_image_rel, out_img_fname) + line = line.replace(pattern, vdoing_image_rel) modified_list.append({ 'input_md': in_md_abs_path, 'output_md': out_md_abs_path, 'line_no': lineno + 1, - 'pattern': pattern, + 'link': pattern, 'source_image': source_img_path, - 'target_image': vdoing_img_pwd_path, + 'target_image': vdoing_image_rel, }) replace_counter += 1 mod_lines.append(line) - print(f'已完成:resolve_image_links(..., {in_md_abs_path}, {out_md_abs_path})' - ) # DEBUG - print(f'\t成功替换了:{replace_counter}个 image 链接,未能成功替换:{failed_counter}个。' - ) # DEBUG + # print(f'已完成:resolve_image_links(..., {in_md_abs_path}, {out_md_abs_path})') # DEBUG + # print(f'\t成功替换了:{replace_counter}个 image 链接,未能成功替换:{failed_counter}个。') # DEBUG return '\n'.join(mod_lines) -def copy_md(json_list: dict, input_doc_root, output_doc_root): - for md_path, json_dict in json_list.items(): +def copy_md(json_list: dict, output_doc_root): + for fullpath, json_dict in json_list.items(): + md_path = json_dict['md_path'] + input_doc_root = json_dict['root_path'] input_md_path = os.path.join(input_doc_root, md_path) + if not os.path.exists(input_md_path): + print(f'MD file doesn\'t exist: {input_md_path}') + continue output_md_path = os.path.join(output_doc_root, json_dict['target_path']) output_md_pwd_path = '/'.join(output_md_path.split('/')[:-1]) - os.system(f'mkdir -p {output_md_pwd_path}') - - assert os.path.exists( - input_md_path), f'MD file doesn\'t exist: {input_md_path}' + os.system(f'mkdir -p "{output_md_pwd_path}"') with codecs.open(input_md_path, 'r', encoding='utf-8') as inMd: input_md_text = inMd.read() @@ -261,16 +351,16 @@ def copy_md(json_list: dict, input_doc_root, output_doc_root): outMd.write(output_md_text) -def copy_md_main(input_filename, input_doc_root, output_doc_root, mod_list, +def copy_md_main(page_indexs, output_doc_root, mod_list, unfound_list): global MD_DOC_INDEX - - # print(input_filename) # DEBUG - with codecs.open(input_filename, 'r', encoding='utf-8') as inFile: - MD_DOC_INDEX = json.load(inFile) + MD_DOC_INDEX = page_indexs + # # print(input_filename) # DEBUG + # with codecs.open(input_filename, 'r', encoding='utf-8') as inFile: + # MD_DOC_INDEX = json.load(inFile) os.system(f'rm -rf {output_doc_root}') - copy_md(MD_DOC_INDEX, input_doc_root, output_doc_root) + copy_md(MD_DOC_INDEX, output_doc_root) ''' 保存列表记录文件 ''' with codecs.open(mod_list, 'w', encoding='utf-8') as mlf: json.dump(modified_list, mlf, indent=2, ensure_ascii=False) diff --git a/docs_md_vuepress_pipeline/test.py b/docs_md_vuepress_pipeline/test.py new file mode 100644 index 0000000000000000000000000000000000000000..bee3ce73d86b725130131bffe579982c7958c2cd --- /dev/null +++ b/docs_md_vuepress_pipeline/test.py @@ -0,0 +1,84 @@ +import os +import re + + +def findImageLink(line, patterns): + result = [] + pos = -1 + count = 0 + linkpos = [] + def isLink(line, patterns): + # file:///xxx.yyy tttt + # http[s]://adfdf + # xxx.png[gif,jpg,md] txt + # xxx.png[gif,jpg,md]#txt + # #txtsdfs + lline = line.lower() + + exts = ['gif','png', 'jpg','jpeg','md'] + for ext in exts: + pos = lline.find(ext) + if pos != -1: + return line[0:pos+len(ext)] + return None + + while True: + pos = line.find('![', pos+1) + if pos == -1 : + break + mpos = line.find(f'](', pos) + if mpos == -1: + break + linkpos.append([pos, mpos, -1, '']) + count += 1 + + pos = -1 + rpos = len(line) + for ind in range(0, -len(linkpos), -1): + ind -= 1 + lk = linkpos[ind] + while True: + rpos = line.rfind(')', 0, rpos) + subtxt = line[lk[1]+2:rpos] + txt = isLink(subtxt, patterns) + if txt != None: + lk[2] = rpos + lk[3] = txt + break + if rpos <= lk[1]: + break + rpos = lk[0] + + for lk in linkpos: + if lk[1] > lk[0]+2: + title = line[lk[0]+2:lk[1]] + else: + title = '' + link = lk[3] + result.append((title, link)) + return result + + +def adjust_title(title, patterns): + out = '' + for ind, c in enumerate(title): + if c in patterns: + out += patterns[c] + else: + out += c + return out + + +txt = '7. 重启Visual Studio Code,点击![](figures/zh-cn_image_0000001239226427.png)进入DevEco Device Tool工具界面。至此,DevEco Device Tool Ubuntu开发环境安装完成。![](figures/zh-cn_image_0000001194668634.png)' +title = adjust_title(txt, { + "'":'_', + "\"":'_', + "“":'_', + "/":'_', + "\\":'_', + "(":'_', + ")":'_' +}) + +# res = findImageLink(txt, ['gif', 'jpg', 'jpeg', 'png']) +print(title) \ No newline at end of file diff --git a/website/.gitignore b/website/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..4cf1ed1f5c68d1da8969ba8911c6bce3feecb922 --- /dev/null +++ b/website/.gitignore @@ -0,0 +1,32 @@ +.DS_Store +node_modules +/dist +docs/.vuepress/dist +docs/images +docs/01* +docs/02* +docs/03* +docs/04* +docs/05* +docs/06* +docs/extras + + +# local env files +.env.local +.env.*.local + +# Log files +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* + +# Editor directories and files +.idea +.vscode +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? diff --git a/website/docs/.vuepress/components/SIGList.vue b/website/docs/.vuepress/components/SIGList.vue index c6ddcd72721e6b2114d47face3dece63c76fe914..7e1839dc1a325405d85d3e7da419ae3ce6660660 100644 --- a/website/docs/.vuepress/components/SIGList.vue +++ b/website/docs/.vuepress/components/SIGList.vue @@ -14,7 +14,7 @@ * limitations under the License. */ `, - sidebarB: - ` + sidebarB: ` (adsbygoogle = window.adsbygoogle || []).push({}); `, - pageT: - ` + pageT: ` `, // pageTshowMode: 'article', - pageB: - ` + pageB: ` // (adsbygoogle = window.adsbygoogle || []).push({}); // `, - windowRB: - ` + windowRB: ` `, -} - +}; // module.exports = { // homeSidebarB: `
自定义模块测试
`, diff --git a/website/docs/.vuepress/config/nav.js b/website/docs/.vuepress/config/nav.js index 28b458030af8d74d08c766052c0f991d08afa64a..cbe6236e413c555946f911226910d940eab6168d 100644 --- a/website/docs/.vuepress/config/nav.js +++ b/website/docs/.vuepress/config/nav.js @@ -28,112 +28,244 @@ OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ module.exports = [ - { text: '首页', link: '/' }, - { text: '下载', link: '/download/' }, { - text: '指南', + text: "支持", items: [ { - text: '文档', - link: '/pages/010101/', - }, - { - text: '知识图谱', - items: [ - { - text: '设备开发', - link: '/pages/8f696f/', - }, - { - text: '应用开发', - link: '/pages/1fbf9f/', - } - ] - } - ] + text: "源码下载", + link: `${process.env.OFFICIAL_URL}/download`, + }, + { + text: "文档", + link: "/pages/zh-cn/了解OpenHarmony/了解OpenHarmony开源项目/", + }, + { + text: "安全", + link: `${process.env.OFFICIAL_URL}/safe`, + }, + ], }, { - text: '用户社区', + text: "学习", items: [ { - text: '用户社区', - link: '/community/introduction/' + text: "学习路径", + link: `${process.env.ATLAS_URL}/mainPlay/learnPath`, }, { - text: '角色说明', - link: '/community/role/' + text: "学院", + link: `${process.env.OFFICIAL_URL}/videoList?id=5`, }, { - text: '贡献指南', - link: '/community/contribution/' + text: "开发样例", + link: `${process.env.ATLAS_URL}/mainPlay/sample`, }, + ], + }, + { + text: "互动", + items: [ { - text: '邮件列表', - link: '/community/maillist/' + text: "新闻", + link: `${process.env.OFFICIAL_URL}/newList?id=3`, }, { - text: '商标使用指南', - link: '/community/trademark/' + text: "博客", + link: `${process.env.OFFICIAL_URL}/blogList?id=2`, }, { - text: '项目群管理制度', - link: '/community/management/' + text: "直播", + link: `${process.env.OFFICIAL_URL}/liveList?id=4`, }, - // { text: '贡献排行榜', link: '/contribution_board/' } - ] + { + text: "活动", + link: `${process.env.OFFICIAL_URL}/activitiesList?id=1`, + }, + { + text: "峰会", + link: `${process.env.OFFICIAL_URL}/summit`, + }, + ], + }, + { + text: "社区", + items: [ + { + text: "行为守则", + link: `${process.env.OFFICIAL_URL}/rule`, + }, + { + text: "贡献攻略", + link: `${process.env.OFFICIAL_URL}/contribution`, + }, + { + text: "找到兴趣组SIG", + link: `${process.env.OFFICIAL_URL}/sig`, + }, + { + text: "订阅邮箱列表", + link: `${process.env.OFFICIAL_URL}/maillist`, + }, + { + text: "社区成长路径", + link: `${process.env.OFFICIAL_URL}/role`, + }, + { + text: "项目管理委员会(PMC)", + link: `${process.env.OFFICIAL_URL}/pmc`, + }, + ], }, { - text: '成员单位', - link: '/members/' + text: "代码度量", + items: [ + { + text: "主仓代码贡献度量", + link: `https://metrics.openharmony.cn/`, + }, + ], }, { - text: 'SIG', - link: '/sig_management/' + text: "兼容性", + items: [ + { + text: "申请认证", + link: `${process.env.OFFICIAL_URL}/certification`, + }, + { + text: "测评结果", + link: `${process.env.OFFICIAL_URL}/armList?id=6`, + }, + ], }, { - text: '服务', + text: "关于我们", items: [ - { text: '兼容性认证服务', link: '/xts/' }, - // { text: 'PCS', link: '/pcs/' } - ] + { + text: "工作委员会", + link: `${process.env.OFFICIAL_URL}/management?id=13`, + }, + { + text: "技术指导委员会", + link: `${process.env.OFFICIAL_URL}/techCommitee`, + }, + { + text: "成员单位", + link: `${process.env.OFFICIAL_URL}/members`, + }, + ], }, + // { + // text: "", + // link: "/pages/000900/", + // }, +]; +// { text: '首页', link: '/' }, +// { text: '下载', link: '/download/' }, +// { +// text: '指南', +// items: [ +// { +// text: '文档', +// link: '/pages/000000/', +// }, +// { +// text: '知识图谱', +// items: [ +// { +// text: '设备开发', +// link: '/pages/8f696f/', +// }, +// { +// text: '应用开发', +// link: '/pages/1fbf9f/', +// } +// ] +// } +// ] +// }, +// { +// text: '用户社区', +// items: [ +// { +// text: '用户社区', +// link: '/community/introduction/' +// }, +// { +// text: '角色说明', +// link: '/community/role/' +// }, +// { +// text: '贡献指南', +// link: '/community/contribution/' +// }, +// { +// text: '邮件列表', +// link: '/community/maillist/' +// }, +// { +// text: '商标使用指南', +// link: '/community/trademark/' +// }, +// { +// text: '项目群管理制度', +// link: '/community/management/' +// }, +// { text: '贡献排行榜', link: '/contribution_board/' } +// ] +// }, +// { +// text: '成员单位', +// link: '/members/' +// }, +// { +// text: 'SIG', +// link: '/sig_management/' +// }, +// { +// text: '服务', +// items: [ +// { text: '兼容性认证服务', link: '/xts/' }, +// { text: 'PCS', link: '/pcs/' } +// ] +// }, - /*{ text: '探索', +/*{ text: '探索', items: [ { text: '子项目', link: '/discovery/sub-projects/'}, { text: '项目申请', link: '/discovery/projects-apply/'} ] },*/ - { - text: '活动', - items: [ - { text: '930线上见面会', link: '/activities/930_meetup/' }, - { text: 'HDC2021 OpenHarmony分论坛', link: '/activities/hdc2021/' }, - { text: 'OpenHarmony开发者成长计划', link: 'https://garden.openatom.cn:8178/mainPlay' }, - ] - }, - { - text: '开发板', link: '/supported_devices/', - }, - { - text: '关于', - items: [ - { text: '关于我们', link: '/about/' }, - { text: '反馈', link: '/about/feedback/' }, - //{ text: '鸣谢', link: '/alliances/'}, - ] - }, - { text: '旧版官网', link: 'https://openharmony.cn/old' }, - { - text: '外部链接', - items: [ - { text: 'OpenHarmony 主仓', link: 'https://gitee.com/openharmony' }, - { text: 'OpenHarmony SIG仓', link: 'https://gitee.com/openharmony-sig' }, - { text: 'OpenHarmony 三方仓', link: 'https://gitee.com/openharmony-tpc' }, - { text: 'OpenHarmony 官网仓', link: 'https://gitee.com/openharmony-sig/website' }, - { text: 'OpenHarmony Github仓', link: 'https://github.com/openharmony' }, - { text: 'Zulip平台', link: 'https://zulip.openharmony.cn' } - ] - }, -] +// { +// text: '活动', +// items: [ +// { text: '930线上见面会', link: '/activities/930_meetup/' }, +// { text: 'HDC2021 OpenHarmony分论坛', link: '/activities/hdc2021/' }, +// { text: 'OpenHarmony开发者成长计划', link: 'https://garden.openatom.cn:8178/mainPlay' }, +// ] +// }, +// { +// text: '开发板', link: '/supported_devices/', +// }, +// { +// text: '关于', +// items: [ +// { text: '关于我们', link: '/about/' }, +// { text: '反馈', link: '/about/feedback/' }, +//{ text: '鸣谢', link: '/alliances/'}, +// ] +// }, +// { text: '旧版官网', link: 'https://openharmony.cn/old' }, +// { +// text: '外部链接', +// items: [ +// { text: 'OpenHarmony 主仓', link: 'https://gitee.com/openharmony' }, +// { text: 'OpenHarmony SIG仓', link: 'https://gitee.com/openharmony-sig' }, +// { text: 'OpenHarmony 三方仓', link: 'https://gitee.com/openharmony-tpc' }, +// { text: 'OpenHarmony 官网仓', link: 'https://gitee.com/openharmony-sig/website' }, +// { text: 'OpenHarmony Github仓', link: 'https://github.com/openharmony' }, +// { text: 'Zulip平台', link: 'https://zulip.openharmony.cn' } +// ] +// }, +//] diff --git a/website/docs/.vuepress/config/sidebar.js b/website/docs/.vuepress/config/sidebar.js index e8e420ed88579575d3e12101cfa116c8b328986f..4f31746f273b46133d6fa511518f0bad23bc3054 100644 --- a/website/docs/.vuepress/config/sidebar.js +++ b/website/docs/.vuepress/config/sidebar.js @@ -102,4 +102,4 @@ module.exports = { // // ] // // } // ], -} +}; diff --git a/website/docs/.vuepress/config/themeConfig.js b/website/docs/.vuepress/config/themeConfig.js index 0c7c17e2003acc37584bd824898cc38b2f3e1f07..83a11d5cafd3d99e5ac1f976dbdfd252df39bcd8 100644 --- a/website/docs/.vuepress/config/themeConfig.js +++ b/website/docs/.vuepress/config/themeConfig.js @@ -1,9 +1,12 @@ -const nav = require('./nav.js'); -const htmlModules = require('./htmlModules.js'); -// const sidebar = require('./sidebar.js'); +const nav = require("./nav.js"); +const htmlModules = require("./htmlModules.js"); +// const sideBar = require("./sidebar.js"); // 主题配置 module.exports = { + // displayAllHeaders: true, + // repoLabel: "查看", + // docsDir: "docs", // 编辑的文件夹 nav, sidebarDepth: 2, // 侧边栏显示深度,默认1,最大2(显示到h3标题) //logo: '/img/EB-logo.png', // 导航栏logo @@ -14,15 +17,15 @@ module.exports = { searchMaxSuggestions: 10, // 搜索结果显示最大数 //lastUpdated: '上次更新', // 开启更新时间,并配置前缀文字 string | boolean (取值为git提交时间) lastUpdated: false, // 开启更新时间,并配置前缀文字 string | boolean (取值为git提交时间) - //docsDir: 'docs', // 编辑的文件夹 + editLinks: false, // 启用编辑 //editLinkText: '编辑', //*** 以下配置是Vdoing主题改动和新增的配置 ***// - category: false, // 是否打开分类功能,默认true。 如打开,会做的事情有:1. 自动生成的frontmatter包含分类字段 2.页面中显示与分类相关的信息和模块 3.自动生成分类页面(在@pages文件夹)。如关闭,则反之。 - tag: false, // 是否打开标签功能,默认true。 如打开,会做的事情有:1. 自动生成的frontmatter包含标签字段 2.页面中显示与标签相关的信息和模块 3.自动生成标签页面(在@pages文件夹)。如关闭,则反之。 - archive: false, // 是否打开归档功能,默认true。 如打开,会做的事情有:1.自动生成归档页面(在@pages文件夹)。如关闭,则反之。 + category: false, // 是否打开分类功能,默认true。 如打开,会做的事情有:1. 自动生成的frontmatter包含分类字段 2.页面中显示与分类相关的信息和模块 3.自动生成分类页面(在@pages文件夹)。如关闭,则反之。 + tag: false, // 是否打开标签功能,默认true。 如打开,会做的事情有:1. 自动生成的frontmatter包含标签字段 2.页面中显示与标签相关的信息和模块 3.自动生成标签页面(在@pages文件夹)。如关闭,则反之。 + archive: false, // 是否打开归档功能,默认true。 如打开,会做的事情有:1.自动生成归档页面(在@pages文件夹)。如关闭,则反之。 // categoryText: '随笔', // 碎片化文章(_posts文件夹的文章)预设生成的分类值,默认'随笔' // bodyBgImg: [ @@ -39,63 +42,67 @@ module.exports = { // ], // contentBgStyle: 1, // 文章内容块的背景风格,默认无. 1 => 方格 | 2 => 横线 | 3 => 竖线 | 4 => 左斜线 | 5 => 右斜线 | 6 => 点状 - updateBar: { // 最近更新栏 - showToArticle: false, // 显示到文章页底部,默认true - moreArticle: false // “更多文章”跳转的页面,默认'/archives' - }, + updateBar: { + // 最近更新栏 + showToArticle: false, // 显示到文章页底部,默认true + moreArticle: false, // “更多文章”跳转的页面,默认'/archives' + }, // rightMenuBar: false, // 是否显示右侧文章大纲栏,默认true (屏宽小于1300px下无论如何都不显示) // sidebarOpen: false, // 初始状态是否打开侧边栏,默认true - pageButton: false, // 是否显示快捷翻页按钮,默认true + pageButton: false, // 是否显示快捷翻页按钮,默认true - sidebar: 'structuring', // 侧边栏 'structuring' | { mode: 'structuring', collapsable: Boolean} | 'auto' | 自定义 温馨提示:目录页数据依赖于结构化的侧边栏数据,如果你不设置为'structuring',将无法使用目录页 - //sidebar: 'auto', + sidebar: "structuring", // 侧边栏 'structuring' | { mode: 'structuring', collapsable: Boolean} | 'auto' | 自定义 温馨提示:目录页数据依赖于结构化的侧边栏数据,如果你不设置为'structuring',将无法使用目录页 + // sidebar: "auto", //author: { - // 文章默认的作者信息,可在md文件中单独配置此信息 String | {name: String, link: String} + // 文章默认的作者信息,可在md文件中单独配置此信息 String | {name: String, link: String} // name: 'xugaoyi', // 必需 // link: 'https://github.com/xugaoyi', // 可选的 //}, - //blogger: { - // 博主信息,显示在首页侧边栏 - // avatar: 'https://cdn.jsdelivr.net/gh/xugaoyi/image_store/blog/20200103123203.jpg', - // name: 'Evan Xu', - // slogan: '前端界的小学生', - //}, + // blogger: { + // // 博主信息,显示在首页侧边栏 + // avatar: + // "https://cdn.jsdelivr.net/gh/xugaoyi/image_store/blog/20200103123203.jpg", + // name: "Evan Xu", + // slogan: "前端界的小学生", + // }, social: { // 社交图标,显示于博主信息栏和页脚栏 // iconfontCssFile: '//at.alicdn.com/t/font_1678482_u4nrnp8xp6g.css', // 可选,阿里图标库在线css文件地址,对于主题没有的图标可自由添加 icons: [ { - iconClass: 'icon-youjian', - title: '发邮件', - link: 'mailto:dev@openharmony.io', + iconClass: "icon-youjian", + title: "发邮件", + link: "mailto:dev@openharmony.io", }, { - iconClass: 'icon-gitee', - title: 'Gitee', - link: 'https://gitee.com/openharmony-sig/website', + iconClass: "icon-gitee", + title: "Gitee", + link: "https://gitee.com/openharmony-sig/website", }, { - iconClass: 'icon-bilibili', - title: 'bilibili', - link: 'https://space.bilibili.com/672606361?from=search&seid=8525419180566433845', + iconClass: "icon-bilibili", + title: "bilibili", + link: "https://space.bilibili.com/672606361?from=search&seid=8525419180566433845", }, { - iconClass: 'icon-xiangce', - title: 'xiangce', - link: '/photos/', - } + iconClass: "icon-xiangce", + title: "xiangce", + link: "/photos/", + }, ], }, footer: { // 页脚信息 createYear: 2020, // 博客创建年份 - copyrightInfo: 'OpenHarmony | MIT License', // 博客版权信息,支持a标签 - copyrightInfo: 'Copyright © ', // 博客版权信息,支持a标签 - tradeMarkUsageGuide: '| 商标使用指南', - privacyPolicy: '| 隐私政策', - usageTerms: '| 使用条款', - beian: '| 京ICP备2020036654号-3', - projects_management: '| 项目群管理制度', + copyrightInfo: + 'OpenHarmony | MIT License', // 博客版权信息,支持a标签 + copyrightInfo: "Copyright © ", // 博客版权信息,支持a标签 + tradeMarkUsageGuide: `| 商标使用指南`, + privacyPolicy: `| 隐私政策`, + usageTerms: `| 使用条款`, + beian: + '| 京ICP备2020036654号-3', + projects_management: `| 项目群管理制度`, }, - htmlModules // 插入hmtl(广告)模块 -} + htmlModules, // 插入hmtl(广告)模块 +}; diff --git a/website/docs/.vuepress/public/images/application-dev/ability/figures/page-ability-lifecycle-callbacks.png b/website/docs/.vuepress/public/images/application-dev/ability/figures/page-ability-lifecycle-callbacks.png deleted file mode 100644 index 4c94556b5c2516ad2978a9a31d833cfb2cf3dd01..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ability/figures/page-ability-lifecycle-callbacks.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ability/figures/page-ability-lifecycle.png b/website/docs/.vuepress/public/images/application-dev/ability/figures/page-ability-lifecycle.png deleted file mode 100644 index 30160c8129c6556c2784a3bb893ad4cc67332339..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ability/figures/page-ability-lifecycle.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/background-agent-scheduled-reminder/public_sys-resources/icon-note.gif b/website/docs/.vuepress/public/images/application-dev/background-agent-scheduled-reminder/public_sys-resources/icon-note.gif deleted file mode 100644 index 6314297e45c1de184204098efd4814d6dc8b1cda..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/background-agent-scheduled-reminder/public_sys-resources/icon-note.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/background-task-management/public_sys-resources/icon-note.gif b/website/docs/.vuepress/public/images/application-dev/background-task-management/public_sys-resources/icon-note.gif deleted file mode 100644 index 6314297e45c1de184204098efd4814d6dc8b1cda..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/background-task-management/public_sys-resources/icon-note.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/database/figures/zh-cn_image_0000001183386164.png b/website/docs/.vuepress/public/images/application-dev/database/figures/zh-cn_image_0000001183386164.png deleted file mode 100644 index 0538c11963b2e54fccc57d560831d41ceab82446..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/database/figures/zh-cn_image_0000001183386164.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/database/public_sys-resources/icon-note.gif b/website/docs/.vuepress/public/images/application-dev/database/public_sys-resources/icon-note.gif deleted file mode 100644 index 6314297e45c1de184204098efd4814d6dc8b1cda..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/database/public_sys-resources/icon-note.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/media/figures/zh-ch_image_20220117.jpg b/website/docs/.vuepress/public/images/application-dev/media/figures/zh-ch_image_20220117.jpg deleted file mode 100644 index bc56b9d8395873193bbad2b3faf7340c6728af60..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/media/figures/zh-ch_image_20220117.jpg and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001089359413.png b/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001089359413.png deleted file mode 100644 index 85345789b60927729e9243798fe122c64ca92687..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001089359413.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001117479776.png b/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001117479776.png deleted file mode 100644 index 9250f90cf1e377c8bb33adf9965436ed7ddbadbf..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001117479776.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001117639668.png b/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001117639668.png deleted file mode 100644 index ba3923fef0ad89fa38fa170d2680931d1eb1ea55..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001117639668.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001119560738.png b/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001119560738.png deleted file mode 100644 index 9a84c3f66275c8ea2a50b9ba9ab0ead3842274cc..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001119560738.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001152674854.png b/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001152674854.png deleted file mode 100644 index 6bef885f7c487473ca1b329d41c6414735555b42..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001152674854.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001163839541.png b/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001163839541.png deleted file mode 100644 index f278f73fb4cd0dba70cae1835dd7a45d2686038b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001163839541.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001167690688.png b/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001167690688.png deleted file mode 100644 index cb05a7cb0fa33a9d9074f4424a3851478935ff33..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001167690688.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001167850660.png b/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001167850660.png deleted file mode 100644 index 469ca774dde99530329d5e7bd62a5a40fb16237b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001167850660.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001168898456.png b/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001168898456.png deleted file mode 100644 index b62a4291cbe98e250fd9dcc65e9f91ba67445575..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001168898456.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001169221404.png b/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001169221404.png deleted file mode 100644 index c44bd561803aa0dc4cafcf0db68bf38f5ba43013..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001169221404.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001196050928.png b/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001196050928.png deleted file mode 100644 index dd75ea8e2b874aae201ecab3254fac3a7bce8fbc..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001196050928.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001213130527.png b/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001213130527.png deleted file mode 100644 index afdab82267fcd7d5eacae76eba500baa3bbecd40..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001213130527.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001213883165.png b/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001213883165.png deleted file mode 100644 index 7f99945dc6e30516a6084896b3f146af89dc2f23..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001213883165.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001214043107.png b/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001214043107.png deleted file mode 100644 index 2d8dd786a91b784794a19f8b2975616912586286..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001214043107.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001238733799.png b/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001238733799.png deleted file mode 100644 index 37736ed10ff7cd16907684dfe2c1d6bb19c61d50..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001238733799.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001238853759.png b/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001238853759.png deleted file mode 100644 index 6bf1ed8cb6d6b6d88b57e533f9efe840afee95b5..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001238853759.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001239855207.png b/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001239855207.png deleted file mode 100644 index 83ef94f222a2cc30f036057908960badedd4aeca..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001239855207.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001247125297.png b/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001247125297.png deleted file mode 100644 index 32771bf5f9639aa8ebdd1922f8088965404674ca..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001247125297.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001248045243.png b/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001248045243.png deleted file mode 100644 index 61535cb2fe6b4197e95cff8691fe27973c5ecde8..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/quick-start/figures/zh-cn_image_0000001248045243.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-js/figures/001.gif b/website/docs/.vuepress/public/images/application-dev/reference/arkui-js/figures/001.gif deleted file mode 100644 index b5bac4f696cc84f6e3116483209f51c08e0ad532..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-js/figures/001.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-js/figures/111.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-js/figures/111.png deleted file mode 100644 index e0517663d25f8f857ac08dd4bd1c36ad76190663..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-js/figures/111.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-js/figures/222.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-js/figures/222.png deleted file mode 100644 index d6ec48b52853bc5eddff3eee7978ef9c313e99aa..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-js/figures/222.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-js/figures/333.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-js/figures/333.png deleted file mode 100644 index ed5ee3a87580dd9f485988467163d3a3ea7e95b6..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-js/figures/333.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-js/figures/444.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-js/figures/444.png deleted file mode 100644 index da8624b6dbff497762753fe8b5786c3d552c78ed..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-js/figures/444.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-js/figures/grid.gif b/website/docs/.vuepress/public/images/application-dev/reference/arkui-js/figures/grid.gif deleted file mode 100644 index b6d2387c6db849678ae8897878fe3117170ea42a..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-js/figures/grid.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-js/figures/list.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-js/figures/list.png deleted file mode 100644 index 7933730b5753d05a6f5734cb3d7ebb39aeb5f173..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-js/figures/list.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-js/figures/mmmm.gif b/website/docs/.vuepress/public/images/application-dev/reference/arkui-js/figures/mmmm.gif deleted file mode 100644 index 5959ae695322f2e1eda3364d7603ec9d2ca10819..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-js/figures/mmmm.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001193704354.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001193704354.png deleted file mode 100644 index 9be62c4f9a5b1ad4b6a1d647c3b0e2d6ac57a33e..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001193704354.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001236697937.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001236697937.png deleted file mode 100644 index 8cc5fef8ddb3f1af9d6b231f9183f5094faf5434..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001236697937.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001238184345.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001238184345.png deleted file mode 100644 index 13b38a17af260f22ef850403d9351cff1860bb9c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001238184345.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/1.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/1.png deleted file mode 100644 index 3c6e9c72046d14a46ed93a1075ee580510e64f92..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/1.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/11111-5.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/11111-5.png deleted file mode 100644 index 5da42e3e14d601745274cb62d914c6600620bb25..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/11111-5.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/11111.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/11111.png deleted file mode 100644 index 5da42e3e14d601745274cb62d914c6600620bb25..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/11111.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/2-01.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/2-01.png deleted file mode 100644 index e766d36181c3d1fbd96bb0acab1b3eb670e14cd4..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/2-01.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/5.gif b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/5.gif deleted file mode 100644 index 587269a1e0647be0acb21deced4722037bb07013..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/5.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/66666.gif b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/66666.gif deleted file mode 100644 index b40f786a2f583af59e9f63d35ab1d503f51525da..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/66666.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/Blank1.gif b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/Blank1.gif deleted file mode 100644 index 2547cd4af312ee9a2cfc6c3c61b630fdcd7426f9..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/Blank1.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/Blank2.gif b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/Blank2.gif deleted file mode 100644 index fe04e9611135b8d8cd4f9ace0acf1d1a5797bf6c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/Blank2.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/Column.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/Column.png deleted file mode 100644 index 90bb7a5557e42ccc9b6509f96f54328d7a27eea1..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/Column.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/F.gif b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/F.gif deleted file mode 100644 index 070ae9d042d5211b2ccc6c187ec0f87a90d2c963..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/F.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/Flex04-2.gif b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/Flex04-2.gif deleted file mode 100644 index 18e5eef8f04c15625f4e3ae3ab050083b3acc962..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/Flex04-2.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/GIF-0.gif b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/GIF-0.gif deleted file mode 100644 index 23a03cf07feddcb9866e7ab141c212ebf01bf8b2..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/GIF-0.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/GIF-1.gif b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/GIF-1.gif deleted file mode 100644 index 52fed39eeae057043dbd00abce9ff29d2c35a56a..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/GIF-1.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/GIF-4.gif b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/GIF-4.gif deleted file mode 100644 index 5bcc79b53b227b6bd0484045d20743d9686c8e08..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/GIF-4.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/GIF.gif b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/GIF.gif deleted file mode 100644 index 8eceb3bf5313485a1fedda5768e70cdb5febc464..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/GIF.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/GIF1.gif b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/GIF1.gif deleted file mode 100644 index e97b2a2406059ce3af77ade27bb634845d807726..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/GIF1.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/GIF2.gif b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/GIF2.gif deleted file mode 100644 index b0a6fc0df420fa15f8a0e476da5fa8592bbc751b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/GIF2.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/GIF4.gif b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/GIF4.gif deleted file mode 100644 index c7532ed87726ac7591901514a7396b617daa10f0..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/GIF4.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/Image1.gif b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/Image1.gif index 21391680f6080b39cced050c88087a0d241952d9..6bc2dfa331eb3b39fc32aa6c1fa131684dff3220 100644 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/Image1.gif and b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/Image1.gif differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/Image2.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/Image2.png deleted file mode 100644 index 085d31e9bf7c5740ac3c46d04c4098e64eb3a544..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/Image2.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/Image3.gif b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/Image3.gif index ecbaeb8cc1a3ec9e1ecfd253b605be50836b1f46..209112f1e4c14478df3f44390732d4b2c70755f4 100644 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/Image3.gif and b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/Image3.gif differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/datapanel.jpg b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/datapanel.jpg deleted file mode 100644 index b12c5fb6563c7ee9d8dfa7e6af1cfe1dcfa1361c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/datapanel.jpg and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/divider.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/divider.png index 857e773f72d0cd7cd9ae13f50aa843a11aae4f97..f2deeb8445fe0f3b66d2b0facbf9e0f0ed9911ca 100644 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/divider.png and b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/divider.png differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/duande.gif b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/duande.gif deleted file mode 100644 index 7ed4e908925042a11312dd27aa1c28e8c91d8d8c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/duande.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/ellipse.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/ellipse.png deleted file mode 100644 index b85ac72fcec0f4b2eb752307d4abe05ef4795ef2..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/ellipse.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/gauge.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/gauge.png deleted file mode 100644 index 2eb96b00f11e597fcc3e3d5ef32701e0a4ef5f5b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/gauge.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/grid-3.gif b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/grid-3.gif deleted file mode 100644 index 9ead4d671531532629b2fbf2f411ce4008dde3ba..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/grid-3.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/lottie-ark-2-0-canvas-ui-animate.gif b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/lottie-ark-2-0-canvas-ui-animate.gif deleted file mode 100644 index e22d25b7aa139409766723e4ed0fd6172b85b6cf..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/lottie-ark-2-0-canvas-ui-animate.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/overlay.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/overlay.png deleted file mode 100644 index 8c8194c14b5ca1ea743782db95027035370ead7e..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/overlay.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/popup.gif b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/popup.gif index 7631bb0d995839d59a9d3876f91fd7e688c35758..3bbb23f623eb1163af382d30bc32c1c4cbe524dd 100644 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/popup.gif and b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/popup.gif differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/progress.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/progress.png deleted file mode 100644 index 0ff7595bc619e62c05376cd7b57a473dde3e9386..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/progress.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/row.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/row.png index 6bf426a5f019e76b7b3a0953643988690eb67b1e..3b44b9a41cb0fa78afcde81f82e0ad63c90de58d 100644 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/row.png and b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/row.png differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/select.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/select.png deleted file mode 100644 index 2672d45f3ed5685aa6f350c2cade469c065a13af..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/select.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/slider.gif b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/slider.gif deleted file mode 100644 index b1724791e4acb31d193a0dce267e42c99288c6bd..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/slider.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/stepper.gif b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/stepper.gif deleted file mode 100644 index 6b44b6a2adc2528e13e95bc10d2a67874226a63b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/stepper.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/swiper.gif b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/swiper.gif index 5db399f79a02f496aea43ff72e55e29a0bb05a9a..bf8d1335752f51258920d0cfc1b65190e2f53011 100644 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/swiper.gif and b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/swiper.gif differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/textarea1.gif b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/textarea1.gif deleted file mode 100644 index 5c888d43eeb0d0d3ab08e0c2922f136ed0b3d142..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/textarea1.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/textinput1.gif b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/textinput1.gif deleted file mode 100644 index 9fa5c075ecc4f157f1e66316f4b56f28ffa2007d..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/textinput1.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/toggle.gif b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/toggle.gif deleted file mode 100644 index f6b7ae5ac2bf443574de54cd4df472a8f0cd1aba..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/toggle.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/unnaming-(3).png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/unnaming-(3).png deleted file mode 100644 index 293ead152f1cde4757f85101d9c8c96bdec4dee7..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/unnaming-(3).png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/unnaming-(4).png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/unnaming-(4).png deleted file mode 100644 index e2a8cf9cf4fc88e27e7adb0ad9caf2df9ca978c6..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/unnaming-(4).png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595194.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595194.png deleted file mode 100644 index 348499bc3787a833ab3da5f87500b11c9c93773e..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595194.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595214.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595214.png deleted file mode 100644 index e544a2958b969018ff6bfe8b44bb8758c2aea61a..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595214.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595216.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595216.png deleted file mode 100644 index f410f22c1dd0ba7e1c9718eb3995de5f5033c0a6..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595216.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595220.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595220.png deleted file mode 100644 index 2eed5759714b99dc039faab67acdfe6d67bfc6ac..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595220.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595224.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595224.png deleted file mode 100644 index 72a515c8b425037a4307ef1b16def3e528aab4a0..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595224.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595226.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595226.png deleted file mode 100644 index 92a309337be0e2f4c49d0484dab0ffd19584b534..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595226.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595228.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595228.png deleted file mode 100644 index 1f4208ebcf5ffeeda0d1f5c452327c8fd8dcf7ac..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595228.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595230.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595230.png deleted file mode 100644 index b4fd4aff2fb6b7a32fcb8af41a84fbf57c26d035..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595230.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595232.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595232.png deleted file mode 100644 index 160278c82fcdf310c796609d5ee29a2a4869af9e..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595232.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595234.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595234.png deleted file mode 100644 index ec9ddc678b5a74f1e5ae78ba6a9c35618f31a589..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595234.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595238.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595238.png deleted file mode 100644 index d3db21e0e3da6d8663f59b2ddabd9e50d6eb1e6a..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595238.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755172.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755172.png deleted file mode 100644 index 5869f7cdc9a81adc7f03d07ab121c6b8433637d9..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755172.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755174.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755174.png deleted file mode 100644 index adb4986f7f26047e65e552c570e3f9e62a2037ac..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755174.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755178.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755178.png deleted file mode 100644 index 801bf97495213f41c2b196b2f170af85b156dd5b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755178.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755180.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755180.png deleted file mode 100644 index 4fb651372a67eca9de3848baa6b66cac0ee9f173..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755180.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755182.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755182.png deleted file mode 100644 index 0d9cf4d6e06b96da9b93608e7a050af71eaa5032..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755182.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755188.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755188.png deleted file mode 100644 index cb250dfc130cc329ae9dc74ddb861e8753d419c3..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755188.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755194.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755194.png deleted file mode 100644 index 4608132f8e4292a3fe0174a65a9a3f2fc428c0e7..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755194.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915130.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915130.png deleted file mode 100644 index 1ba89fa119f9a64c74b9353c20ec3d741aaad9be..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915130.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915154.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915154.png deleted file mode 100644 index f36078d6d832fa757378b72fa0739f66fe781c64..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915154.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915158.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915158.png deleted file mode 100644 index d8bdc2d4a59d0b3c5de0f8c020d30ffc5b2ead7a..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915158.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915162.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915162.png deleted file mode 100644 index 1ba89fa119f9a64c74b9353c20ec3d741aaad9be..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915162.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915178.gif b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915178.gif deleted file mode 100644 index b1808e80a0e4d055d54b886ecca3ddc8efa64b9a..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915178.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915180.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915180.png deleted file mode 100644 index 7dafd299b8e48ead7d6f783e5a370e31257e341c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915180.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915184.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915184.png deleted file mode 100644 index ee1d5493dd38de810cbfe5e41e54d507b839e9c9..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915184.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075122.gif b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075122.gif deleted file mode 100644 index b26dc8bf409987fa624f6dc0cec1c56043e7b37a..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075122.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075134.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075134.png deleted file mode 100644 index 241fe8546ea2acfdb7baf2c5e66a8af2f0d7b593..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075134.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075154.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075154.png deleted file mode 100644 index 8c06945a1790bb0a741b330fe0a9170dd2a3a92d..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075154.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075164.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075164.png deleted file mode 100644 index 45be809bdb14e8badfaac2dc8e2486864d29f763..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075164.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075166.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075166.png deleted file mode 100644 index fb7fc25c17990998ba263a8525e6a110794c0d87..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075166.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075168.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075168.png deleted file mode 100644 index 5eecca641660f12e3ad2ba7b97b97eca253a4acf..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075168.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075170.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075170.png deleted file mode 100644 index 241fe8546ea2acfdb7baf2c5e66a8af2f0d7b593..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075170.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075172.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075172.png deleted file mode 100644 index 5d649492978121a484c2a7a55d4548384c919149..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075172.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075178.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075178.png deleted file mode 100644 index 4f115a17e671fa21da2d44cd82bf7b0f3c70c0a6..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075178.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075180.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075180.png deleted file mode 100644 index 7cbe07731306eff949ff7ced4dd7eb4a374c8310..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075180.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193321136.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193321136.png deleted file mode 100644 index 72a515c8b425037a4307ef1b16def3e528aab4a0..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193321136.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193321138.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193321138.png deleted file mode 100644 index fb7fc25c17990998ba263a8525e6a110794c0d87..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193321138.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193322850.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193322850.png deleted file mode 100644 index 657eee10e270eb448fc7f7f4b24b18134a42d5dc..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193322850.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193322872.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193322872.png deleted file mode 100644 index 7cbe07731306eff949ff7ced4dd7eb4a374c8310..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193322872.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193322910.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193322910.png deleted file mode 100644 index e764c43599592d821c403aac0d3fa40d9edd22e5..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193322910.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193436448.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193436448.png deleted file mode 100644 index 2eed5759714b99dc039faab67acdfe6d67bfc6ac..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193436448.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193481094.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193481094.png deleted file mode 100644 index 1f4208ebcf5ffeeda0d1f5c452327c8fd8dcf7ac..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193481094.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193481096.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193481096.png deleted file mode 100644 index 138e011909c2d4738f3cd9671a79ea0c37cb5b87..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193481096.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193481098.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193481098.png deleted file mode 100644 index defc3c9eb037c06b894ee2e30563facb8c8375ab..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193481098.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193482814.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193482814.png deleted file mode 100644 index 45be809bdb14e8badfaac2dc8e2486864d29f763..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193482814.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193482866.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193482866.png deleted file mode 100644 index 5eecca641660f12e3ad2ba7b97b97eca253a4acf..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193482866.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193641084.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193641084.png deleted file mode 100644 index 563ce2878d24a7fa46044f201433d759c3fa9001..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193641084.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193641086.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193641086.png deleted file mode 100644 index 801bf97495213f41c2b196b2f170af85b156dd5b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193641086.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193642802.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193642802.png deleted file mode 100644 index 160278c82fcdf310c796609d5ee29a2a4869af9e..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193642802.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193642848.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193642848.png deleted file mode 100644 index 83b7a51accdda21d21a39e5e9d917d75811cb496..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193642848.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193737314.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193737314.png deleted file mode 100644 index e3b4b42aecaef72ed4a08b3566a895b3f9b12343..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193737314.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193756416.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193756416.png deleted file mode 100644 index b0b8bdc7fc7cd417340bbcda6845fd7de0098930..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193756416.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193801070.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193801070.png deleted file mode 100644 index 92a309337be0e2f4c49d0484dab0ffd19584b534..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193801070.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193801072.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193801072.png deleted file mode 100644 index b4fd4aff2fb6b7a32fcb8af41a84fbf57c26d035..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193801072.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193802788.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193802788.png deleted file mode 100644 index c1803b711d45a86552a2be4099424206a1561534..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193802788.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193802836.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193802836.png deleted file mode 100644 index ad8582f58ed05f9ac3b8962f82d8565d1f580f6c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193802836.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355087.gif b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355087.gif deleted file mode 100644 index 38502c83c52aa9229da69d638e4b9b1f5a35009b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355087.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355121.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355121.png deleted file mode 100644 index e764c43599592d821c403aac0d3fa40d9edd22e5..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355121.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355131.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355131.png deleted file mode 100644 index 138e011909c2d4738f3cd9671a79ea0c37cb5b87..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355131.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355133.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355133.png deleted file mode 100644 index 088d5a479cc188332bb7295b31aea277897faca8..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355133.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355135.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355135.png deleted file mode 100644 index 10059591af349daced4bf7abeb009209a3e90f1d..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355135.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355137.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355137.png deleted file mode 100644 index 83b7a51accdda21d21a39e5e9d917d75811cb496..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355137.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475107.gif b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475107.gif deleted file mode 100644 index b3966d0abb39044241ee174a126fcf919f402d98..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475107.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475113.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475113.png deleted file mode 100644 index 84d835e7feeac31e42c1a53670ef6c999ea4bfe2..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475113.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475123.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475123.png deleted file mode 100644 index e3b4b42aecaef72ed4a08b3566a895b3f9b12343..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475123.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475133.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475133.png deleted file mode 100644 index f0e245a5c576e92810baacaa09af99f108a010a9..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475133.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475137.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475137.png deleted file mode 100644 index defc3c9eb037c06b894ee2e30563facb8c8375ab..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475137.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475139.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475139.png deleted file mode 100644 index 9cb1361bd9aded6d58d51ae771558989977a0608..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475139.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555149.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555149.png deleted file mode 100644 index 1ba89fa119f9a64c74b9353c20ec3d741aaad9be..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555149.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555151.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555151.png deleted file mode 100644 index 1330e2e2a6395703f9c3747252c1e0a69ae6f4f0..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555151.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555155.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555155.png deleted file mode 100644 index 071919ed3a638630f33a337f920ae2e60c9c21bc..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555155.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555163.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555163.png deleted file mode 100644 index 26fb5384338291f3eb372abd526f0727ce759bdc..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555163.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555165.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555165.png deleted file mode 100644 index 50726d3e461d7a5dbfec674899fee603aaf41bee..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555165.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555167.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555167.png deleted file mode 100644 index af02181de0d07d5311b09c8d05c2a018e6e5b4cf..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555167.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555173.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555173.png deleted file mode 100644 index 657eee10e270eb448fc7f7f4b24b18134a42d5dc..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555173.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555179.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555179.png deleted file mode 100644 index cb250dfc130cc329ae9dc74ddb861e8753d419c3..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555179.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555181.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555181.png deleted file mode 100644 index b2728fd1b4e050edddf499398b44a7e3aa634109..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555181.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715141.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715141.png deleted file mode 100644 index c1803b711d45a86552a2be4099424206a1561534..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715141.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715149.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715149.png deleted file mode 100644 index b0b8bdc7fc7cd417340bbcda6845fd7de0098930..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715149.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715151.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715151.png deleted file mode 100644 index 1f4208ebcf5ffeeda0d1f5c452327c8fd8dcf7ac..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715151.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715153.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715153.png deleted file mode 100644 index 22e84d1b8951b163748a079b6d1d302148d3b6bb..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715153.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715155.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715155.png deleted file mode 100644 index 945862898489d8e008e94abbcd691aa307b18d06..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715155.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715159.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715159.png deleted file mode 100644 index 3e7218eb57566d86457a9fbd4a8ed0f0dd490c3f..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715159.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715165.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715165.png deleted file mode 100644 index f5cd637e5bf9db13e3334ca00413e3a91412c813..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715165.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238281067.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238281067.png deleted file mode 100644 index 22e84d1b8951b163748a079b6d1d302148d3b6bb..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238281067.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238281069.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238281069.png deleted file mode 100644 index 088d5a479cc188332bb7295b31aea277897faca8..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238281069.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238282783.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238282783.png deleted file mode 100644 index 10059591af349daced4bf7abeb009209a3e90f1d..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238282783.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238282827.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238282827.png deleted file mode 100644 index b2728fd1b4e050edddf499398b44a7e3aa634109..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238282827.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238401029.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238401029.png deleted file mode 100644 index d0e446b213816e4db8d67a9898da1afa7b8226ad..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238401029.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238401031.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238401031.png deleted file mode 100644 index d3db21e0e3da6d8663f59b2ddabd9e50d6eb1e6a..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238401031.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238402745.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238402745.png deleted file mode 100644 index 4608132f8e4292a3fe0174a65a9a3f2fc428c0e7..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238402745.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238402777.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238402777.png deleted file mode 100644 index f5cd637e5bf9db13e3334ca00413e3a91412c813..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238402777.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238457271.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238457271.png deleted file mode 100644 index 4fb651372a67eca9de3848baa6b66cac0ee9f173..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238457271.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238476361.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238476361.png deleted file mode 100644 index 5d649492978121a484c2a7a55d4548384c919149..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238476361.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238521019.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238521019.png deleted file mode 100644 index af02181de0d07d5311b09c8d05c2a018e6e5b4cf..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238521019.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238521021.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238521021.png deleted file mode 100644 index 3e7218eb57566d86457a9fbd4a8ed0f0dd490c3f..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238521021.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238522733.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238522733.png deleted file mode 100644 index 4f115a17e671fa21da2d44cd82bf7b0f3c70c0a6..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238522733.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238522783.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238522783.png deleted file mode 100644 index bc093379e122dcac29c4c8d04560d26bfc23d472..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238522783.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238537297.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238537297.png deleted file mode 100644 index 50726d3e461d7a5dbfec674899fee603aaf41bee..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238537297.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238556395.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238556395.png deleted file mode 100644 index 294b32cf04462b04243afb828199be9b95e6dd17..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238556395.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238601051.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238601051.png deleted file mode 100644 index 1f4208ebcf5ffeeda0d1f5c452327c8fd8dcf7ac..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238601051.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238601053.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238601053.png deleted file mode 100644 index 945862898489d8e008e94abbcd691aa307b18d06..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238601053.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238602771.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238602771.png deleted file mode 100644 index ec9ddc678b5a74f1e5ae78ba6a9c35618f31a589..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238602771.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238602821.png b/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238602821.png deleted file mode 100644 index 9cb1361bd9aded6d58d51ae771558989977a0608..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238602821.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001111680230.png b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001111680230.png deleted file mode 100644 index 58293d5e874f2aa36ecaf7282ca9e4736318092f..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001111680230.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001111680236.png b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001111680236.png deleted file mode 100644 index bc28f5056c679e189543c8ad6fba67fb56db7655..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001111680236.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001111680240.png b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001111680240.png deleted file mode 100644 index 56d32d4cd371c5374b133cb81c9c077aaf7b110d..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001111680240.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001111840132.png b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001111840132.png deleted file mode 100644 index dfcb0c5e259b3f8d7375c21712249c1e847edd67..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001111840132.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001111840136.png b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001111840136.png deleted file mode 100644 index 309d1c46f8bc396df5eaed381a5ffa2f0389d602..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001111840136.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001127125270.png b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001127125270.png deleted file mode 100644 index 43c345e521bd9c87a9fb6da469548716cd20f918..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001127125270.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001127284926.png b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001127284926.png deleted file mode 100644 index 9fa7ed21c03b072e182249f928b9929d0869cd5d..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001127284926.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001147417424.png b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001147417424.png deleted file mode 100644 index 66d73108f4d5721cfc46ad9062d4b77387e67796..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001147417424.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001158240091.png b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001158240091.png deleted file mode 100644 index e370a44cf043fc34bd8891f57faad2cd2ca05707..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001158240091.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001158240095.png b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001158240095.png deleted file mode 100644 index 9c43caf5fdfd466eafc37b793f509a6bde2b885d..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001158240095.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001158240097.png b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001158240097.png deleted file mode 100644 index b54dbc2391d1a8f16312dd02dc3d65a35ea2626f..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001158240097.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001158360079.png b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001158360079.png deleted file mode 100644 index 0d22570503febc7a7dcba0d1e870f49f32fe489a..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001158360079.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001158360085.png b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001158360085.png deleted file mode 100644 index 5c5e360f249a2002ba68ad9b94bd7f66f5d6aab1..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001158360085.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001169582302.gif b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001169582302.gif deleted file mode 100644 index 391353977d32956cde03890e501d11766dae2648..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001169582302.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001173164777.png b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001173164777.png deleted file mode 100644 index 5e4322d20ad887573ad85958bc181a1be0f85f1c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001173164777.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001174756438.gif b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001174756438.gif deleted file mode 100644 index 5eb149620499c0d1d363d274ad88a741095fc922..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001174756438.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001174756580.gif b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001174756580.gif deleted file mode 100644 index 5a297661641d1714ebc95116592a97a693293e0a..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001174756580.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001174756776.gif b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001174756776.gif deleted file mode 100644 index b1038b5da74612ac1911e1dae9d3a1de24ee46c7..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001174756776.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001174756860.gif b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001174756860.gif deleted file mode 100644 index d1288776a8086fbb9e66691b0e882784db243aba..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001174756860.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001174916742.gif b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001174916742.gif deleted file mode 100644 index c7779b378c80842817091bedf62d74378bfff055..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001174916742.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001175075286.gif b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001175075286.gif deleted file mode 100644 index 90898288928277467db40c5eb11b4ff7ae082e6e..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001175075286.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001175235138.gif b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001175235138.gif deleted file mode 100644 index 5cfb969baf3a36e231a311ca11ca538c248f6da1..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001175235138.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001182200571.png b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001182200571.png deleted file mode 100644 index a1bd96de03ca927b9d168cdbe99fa7f3f96472f3..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001182200571.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001183709904.png b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001183709904.png deleted file mode 100644 index fb34869ae9a78d655a30e62e1936840d0aa6bb4d..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001183709904.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001188771358.gif b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001188771358.gif deleted file mode 100644 index c76bef26e0b11311f02233ff17ca476ef470798a..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001188771358.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001188771430.gif b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001188771430.gif deleted file mode 100644 index 4a815c6f3db9654b71cc1d11821eab521ca7aeee..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001188771430.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001188931396.gif b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001188931396.gif deleted file mode 100644 index b5e2ed34cf960792ca65ce6d9197ac0fc5d49f8c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001188931396.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001189088264.gif b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001189088264.gif deleted file mode 100644 index 688faa61583561ccb4e54daa04a3ac6a466245ac..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001189088264.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001189089950.gif b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001189089950.gif deleted file mode 100644 index eb0c760faaf917a6935af461e0094fd8e7b8e85b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001189089950.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001189098638.gif b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001189098638.gif deleted file mode 100644 index 6ba578c8480834de8798cd311444c0499e1f0da5..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001189098638.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001189248178.gif b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001189248178.gif deleted file mode 100644 index 74ac9966962b430a0a03e68cf4f39bcfae4cc280..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001189248178.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001189249862.gif b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001189249862.gif deleted file mode 100644 index a1839308d0fdde50aefd4c818d30ea82c49b6ca6..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001189249862.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001214437889.png b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001214437889.png deleted file mode 100644 index fde616c73000d3f58fd98eea59088177221127a5..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001214437889.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001214948035.png b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001214948035.png deleted file mode 100644 index 37ae5324808a0ab50f210907ca65a09e4456a371..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001214948035.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001217008255.gif b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001217008255.gif deleted file mode 100644 index 5e38a4068976c9b5e298ff33ad4cfc711de4b2a6..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001217008255.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001217168141.gif b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001217168141.gif deleted file mode 100644 index f470f5261becb6c2d7b30f691a0794db2b1feb93..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001217168141.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001220316305.gif b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001220316305.gif deleted file mode 100644 index 365dbc42e583335f32de863120fd80ae0e7d59e5..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001220316305.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001220316655.gif b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001220316655.gif deleted file mode 100644 index 16a2d3f912b23349a5c416e5c5b74f4fd05a12aa..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001220316655.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001220396251.gif b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001220396251.gif deleted file mode 100644 index b7808565202cf12474f1282e67fde3a9c85d0e9c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001220396251.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001220396499.gif b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001220396499.gif deleted file mode 100644 index ff991f2899c847c433e41ccafd6798a386540369..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001220396499.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001220554911.gif b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001220554911.gif deleted file mode 100644 index 3fe0cd60d60a0c5d29c2625ebade3d8b0bd0cdf8..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001220554911.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001220634677.png b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001220634677.png deleted file mode 100644 index 664e50e404e5e7f6e4c4823bf1099391bfa45e33..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001220634677.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001220635011.gif b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001220635011.gif deleted file mode 100644 index d669cf40b97891ba3853be28574dceae172fe138..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001220635011.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001220635059.gif b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001220635059.gif deleted file mode 100644 index 27f8177c1c626565ce53f409bbf5a4e2f7cdba01..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001220635059.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001220778205.png b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001220778205.png deleted file mode 100644 index 62c786d7dacd69bae17ebe4074a2d429cd7f6851..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001220778205.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001220856725.png b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001220856725.png deleted file mode 100644 index cc39aec87bb14a36eb6214a2ef39d45c631d4a2b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001220856725.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001234009343.gif b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001234009343.gif deleted file mode 100644 index 20b525e82ccdead4414f89e2e226992bc85e13c3..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001234009343.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001234011019.gif b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001234011019.gif deleted file mode 100644 index 24f00c9f1aa6ec431a355f5dd2d88b920607cd05..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001234011019.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001234129289.gif b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001234129289.gif deleted file mode 100644 index 1dff7c90963c2e9a76aa63dbb434b9c55a747fba..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001234129289.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001234130975.png b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001234130975.png deleted file mode 100644 index 21d56ef14b92d136e304c4bae6ab8b1f447557bb..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001234130975.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001234287779.gif b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001234287779.gif deleted file mode 100644 index 2398192bc5df690246dad3edfb82afe618b35dfd..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001234287779.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001234289455.gif b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001234289455.gif deleted file mode 100644 index a6296483cbe2994e36e97d422588f3a9156b56eb..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001234289455.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001234289465.gif b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001234289465.gif deleted file mode 100644 index b374c821e0e426b0e50e33910f33582e8b283ac9..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001234289465.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001234327855.gif b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001234327855.gif deleted file mode 100644 index b0e9d88f7ccf69a208bdf59ab5bd9a3dee2426f6..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001234327855.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001234329527.gif b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001234329527.gif deleted file mode 100644 index 5ea0034e22041bd7fe8c5f73e655ddf367a8d5d5..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001234329527.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001234329539.gif b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001234329539.gif deleted file mode 100644 index f3e6017b6daddc0be529486e0bfaf8b39749e38f..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001234329539.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001234342189.gif b/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001234342189.gif deleted file mode 100644 index 61571b390492f0116ceec215b03d261d2ce41139..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/ui/figures/zh-cn_image_0000001234342189.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/application-dev/usb/figures/zh-cn_image_0000001237821727.png b/website/docs/.vuepress/public/images/application-dev/usb/figures/zh-cn_image_0000001237821727.png deleted file mode 100644 index b5bc068e8edca56fafa47648f6db797120d71fad..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/application-dev/usb/figures/zh-cn_image_0000001237821727.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/contribute/figures/figure1.png b/website/docs/.vuepress/public/images/contribute/figures/figure1.png deleted file mode 100644 index 7f0eac3c0daa1660c3c1847035b0ad8ea9d45720..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/contribute/figures/figure1.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/contribute/figures/figure10.png b/website/docs/.vuepress/public/images/contribute/figures/figure10.png deleted file mode 100644 index 8c5824cd5b98886582f53f395316bdbd9c27ffc6..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/contribute/figures/figure10.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/contribute/figures/figure11.png b/website/docs/.vuepress/public/images/contribute/figures/figure11.png deleted file mode 100644 index ad1a67252e6301e48fc9b576f560e4d850df9aec..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/contribute/figures/figure11.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/contribute/figures/figure12.png b/website/docs/.vuepress/public/images/contribute/figures/figure12.png deleted file mode 100644 index 6859a80da3ff1375f28f42c2a51c975e9cce5384..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/contribute/figures/figure12.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/contribute/figures/figure2.png b/website/docs/.vuepress/public/images/contribute/figures/figure2.png deleted file mode 100644 index e6d353faede88c88691655cf64830d21dbaf83d8..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/contribute/figures/figure2.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/contribute/figures/figure3.png b/website/docs/.vuepress/public/images/contribute/figures/figure3.png deleted file mode 100644 index 0bd920a13ebb4d7855986628b42d1c2888287132..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/contribute/figures/figure3.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/contribute/figures/figure4.png b/website/docs/.vuepress/public/images/contribute/figures/figure4.png deleted file mode 100644 index 6c78ea5fbd890e99244ec966e0e73705cd0d2f73..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/contribute/figures/figure4.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/contribute/figures/figure5.png b/website/docs/.vuepress/public/images/contribute/figures/figure5.png deleted file mode 100644 index 882998e48ed988005dd36b06a65b7d3fd87340e9..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/contribute/figures/figure5.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/contribute/figures/figure7.png b/website/docs/.vuepress/public/images/contribute/figures/figure7.png deleted file mode 100644 index fa5d50743d17890279cea71061708c2122f933ab..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/contribute/figures/figure7.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/contribute/figures/figure8.png b/website/docs/.vuepress/public/images/contribute/figures/figure8.png deleted file mode 100644 index 56e09890a0bb839ab66ca59dea9f6289bdd1061e..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/contribute/figures/figure8.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/contribute/figures/figure9.png b/website/docs/.vuepress/public/images/contribute/figures/figure9.png deleted file mode 100644 index 3663b39f63fe77bbf23e41786853eb30a25619d4..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/contribute/figures/figure9.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/contribute/template/figures/figure01.png b/website/docs/.vuepress/public/images/contribute/template/figures/figure01.png deleted file mode 100644 index 62e5ec7c6248ed9219503c85b076dc9a22da6c78..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/contribute/template/figures/figure01.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/contribute/template/figures/figure02.png b/website/docs/.vuepress/public/images/contribute/template/figures/figure02.png deleted file mode 100644 index 37b1f5215e362c156ca5de27145c3711cc14083b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/contribute/template/figures/figure02.png and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/driver/figures/ADC\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" "b/website/docs/.vuepress/public/images/device-dev/driver/figures/ADC\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" deleted file mode 100755 index 9b140042ffdfff77a76cc69814a0217af2ddc5df..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/driver/figures/ADC\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/driver/figures/ADC\347\211\251\347\220\206\350\277\236\347\272\277\347\244\272\346\204\217\345\233\276.png" "b/website/docs/.vuepress/public/images/device-dev/driver/figures/ADC\347\211\251\347\220\206\350\277\236\347\272\277\347\244\272\346\204\217\345\233\276.png" deleted file mode 100755 index da94f3b486edb6b269ef341b12b1816f23036c32..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/driver/figures/ADC\347\211\251\347\220\206\350\277\236\347\272\277\347\244\272\346\204\217\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/driver/figures/ADM\345\220\257\345\212\250\346\265\201\347\250\213\345\233\276.png" "b/website/docs/.vuepress/public/images/device-dev/driver/figures/ADM\345\220\257\345\212\250\346\265\201\347\250\213\345\233\276.png" deleted file mode 100644 index aa9044c2e0d345da6f52ac4209d8dba8bf357f79..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/driver/figures/ADM\345\220\257\345\212\250\346\265\201\347\250\213\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/driver/figures/ADM\346\216\247\345\210\266\346\265\201\347\250\213\345\233\276.png" "b/website/docs/.vuepress/public/images/device-dev/driver/figures/ADM\346\216\247\345\210\266\346\265\201\347\250\213\345\233\276.png" deleted file mode 100644 index 9f43c4f6510359d84d11c056ec7b0bcde705cf3c..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/driver/figures/ADM\346\216\247\345\210\266\346\265\201\347\250\213\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/driver/figures/ADM\346\222\255\346\224\276\346\265\201\347\250\213\345\233\276.png" "b/website/docs/.vuepress/public/images/device-dev/driver/figures/ADM\346\222\255\346\224\276\346\265\201\347\250\213\345\233\276.png" deleted file mode 100644 index 66891974d7202a641a268b611066b1ee988fe162..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/driver/figures/ADM\346\222\255\346\224\276\346\265\201\347\250\213\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/driver/figures/Audio\346\241\206\346\236\266\345\233\276.png" "b/website/docs/.vuepress/public/images/device-dev/driver/figures/Audio\346\241\206\346\236\266\345\233\276.png" deleted file mode 100644 index 07b4c54a4100620f2d469922c6979ba03acea654..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/driver/figures/Audio\346\241\206\346\236\266\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/driver/figures/CSI\345\217\221\351\200\201-\346\216\245\346\224\266\346\216\245\345\217\243.png" "b/website/docs/.vuepress/public/images/device-dev/driver/figures/CSI\345\217\221\351\200\201-\346\216\245\346\224\266\346\216\245\345\217\243.png" deleted file mode 100755 index 1407bc0ced6942501039f8fe041efc722882fbaa..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/driver/figures/CSI\345\217\221\351\200\201-\346\216\245\346\224\266\346\216\245\345\217\243.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/driver/figures/HAL\346\265\201\347\250\213\345\233\276.png" "b/website/docs/.vuepress/public/images/device-dev/driver/figures/HAL\346\265\201\347\250\213\345\233\276.png" deleted file mode 100644 index eb3cc69a0d77910e74f38403cfd0ec3b1e727994..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/driver/figures/HAL\346\265\201\347\250\213\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/driver/figures/HDMI\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" "b/website/docs/.vuepress/public/images/device-dev/driver/figures/HDMI\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" deleted file mode 100755 index fa578f83d99f47e868312dad99d6b38fa960e794..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/driver/figures/HDMI\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/driver/figures/HDMI\347\211\251\347\220\206\350\277\236\347\272\277\347\244\272\346\204\217\345\233\276.png" "b/website/docs/.vuepress/public/images/device-dev/driver/figures/HDMI\347\211\251\347\220\206\350\277\236\347\272\277\347\244\272\346\204\217\345\233\276.png" deleted file mode 100755 index 9c1618562e33dd6fd08d2ec7f48454a43c1e1541..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/driver/figures/HDMI\347\211\251\347\220\206\350\277\236\347\272\277\347\244\272\346\204\217\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/driver/figures/I3C\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" "b/website/docs/.vuepress/public/images/device-dev/driver/figures/I3C\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" deleted file mode 100755 index 40c7088de596e771921861c727d4813f686eda40..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/driver/figures/I3C\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/driver/figures/I3C\347\211\251\347\220\206\350\277\236\347\272\277\347\244\272\346\204\217\345\233\276.png" "b/website/docs/.vuepress/public/images/device-dev/driver/figures/I3C\347\211\251\347\220\206\350\277\236\347\272\277\347\244\272\346\204\217\345\233\276.png" deleted file mode 100755 index 08942f92cdc1c9fa6c0442537525cfcba90254a7..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/driver/figures/I3C\347\211\251\347\220\206\350\277\236\347\272\277\347\244\272\346\204\217\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/driver/figures/MIPI-CSI\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" "b/website/docs/.vuepress/public/images/device-dev/driver/figures/MIPI-CSI\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" deleted file mode 100755 index 1e5945dde90c375947137d8b5e9161018c0700f9..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/driver/figures/MIPI-CSI\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/driver/figures/logic-view-of-camera-hal-zh.png b/website/docs/.vuepress/public/images/device-dev/driver/figures/logic-view-of-camera-hal-zh.png deleted file mode 100755 index 772356a3efede5b1b8b45b27270ed79fcf9e9d01..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/driver/figures/logic-view-of-camera-hal-zh.png and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/driver/figures/\345\274\200\345\217\221\346\265\201\347\250\213\345\233\2761.png" "b/website/docs/.vuepress/public/images/device-dev/driver/figures/\345\274\200\345\217\221\346\265\201\347\250\213\345\233\2761.png" deleted file mode 100644 index 37afe238749f8f77174cb84951f14f4862a3b49e..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/driver/figures/\345\274\200\345\217\221\346\265\201\347\250\213\345\233\2761.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/driver/figures/\345\274\200\345\217\221\346\265\201\347\250\213\345\233\2762.png" "b/website/docs/.vuepress/public/images/device-dev/driver/figures/\345\274\200\345\217\221\346\265\201\347\250\213\345\233\2762.png" deleted file mode 100644 index 713903a37d72853cb7b487772ff71454df9abe5d..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/driver/figures/\345\274\200\345\217\221\346\265\201\347\250\213\345\233\2762.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/driver/figures/\346\227\240\346\234\215\345\212\241\346\250\241\345\274\217\347\273\223\346\236\204\345\233\276.png" "b/website/docs/.vuepress/public/images/device-dev/driver/figures/\346\227\240\346\234\215\345\212\241\346\250\241\345\274\217\347\273\223\346\236\204\345\233\276.png" deleted file mode 100755 index d75a35cfb12f998856d266f1d8ff0d2e5d9cea75..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/driver/figures/\346\227\240\346\234\215\345\212\241\346\250\241\345\274\217\347\273\223\346\236\204\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/driver/figures/\347\213\254\347\253\213\346\234\215\345\212\241\346\250\241\345\274\217\347\273\223\346\236\204\345\233\276.png" "b/website/docs/.vuepress/public/images/device-dev/driver/figures/\347\213\254\347\253\213\346\234\215\345\212\241\346\250\241\345\274\217\347\273\223\346\236\204\345\233\276.png" deleted file mode 100755 index f0ddcee70022751a43b9ef1da145c68094da0eab..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/driver/figures/\347\213\254\347\253\213\346\234\215\345\212\241\346\250\241\345\274\217\347\273\223\346\236\204\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/driver/figures/\347\273\237\344\270\200\346\234\215\345\212\241\346\250\241\345\274\217\347\273\223\346\236\204\345\233\276.png" "b/website/docs/.vuepress/public/images/device-dev/driver/figures/\347\273\237\344\270\200\346\234\215\345\212\241\346\250\241\345\274\217\347\273\223\346\236\204\345\233\276.png" deleted file mode 100755 index b5b755cf9753512eb3d3805334a9a30b5e05c90d..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/driver/figures/\347\273\237\344\270\200\346\234\215\345\212\241\346\250\241\345\274\217\347\273\223\346\236\204\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/kernel/figure/ELF\346\226\207\344\273\266\347\232\204\345\212\240\350\275\275\350\277\207\347\250\213.png" "b/website/docs/.vuepress/public/images/device-dev/kernel/figure/ELF\346\226\207\344\273\266\347\232\204\345\212\240\350\275\275\350\277\207\347\250\213.png" deleted file mode 100644 index 23bc27b7de00aeb9d1ff9fa349c1be4fe4559b18..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/kernel/figure/ELF\346\226\207\344\273\266\347\232\204\345\212\240\350\275\275\350\277\207\347\250\213.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/kernel/figure/ELF\346\226\207\344\273\266\347\232\204\351\223\276\346\216\245\350\277\207\347\250\213.png" "b/website/docs/.vuepress/public/images/device-dev/kernel/figure/ELF\346\226\207\344\273\266\347\232\204\351\223\276\346\216\245\350\277\207\347\250\213.png" deleted file mode 100644 index dc43aa951c78b8c9d495ab3aa6d8799309e103c9..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/kernel/figure/ELF\346\226\207\344\273\266\347\232\204\351\223\276\346\216\245\350\277\207\347\250\213.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/kernel/figure/LiteOS-M\345\206\205\346\240\270\345\212\250\346\200\201\345\212\240\350\275\275\346\236\266\346\236\204\345\233\276.png" "b/website/docs/.vuepress/public/images/device-dev/kernel/figure/LiteOS-M\345\206\205\346\240\270\345\212\250\346\200\201\345\212\240\350\275\275\346\236\266\346\236\204\345\233\276.png" deleted file mode 100644 index a460e8dbf1953929bb31be3323fc716f2cdaf9ad..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/kernel/figure/LiteOS-M\345\206\205\346\240\270\345\212\250\346\200\201\345\212\240\350\275\275\346\236\266\346\236\204\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/kernel/figure/\344\273\273\345\212\241\347\212\266\346\200\201\350\277\201\347\247\273\347\244\272\346\204\217\345\233\276.png" "b/website/docs/.vuepress/public/images/device-dev/kernel/figure/\344\273\273\345\212\241\347\212\266\346\200\201\350\277\201\347\247\273\347\244\272\346\204\217\345\233\276.png" deleted file mode 100644 index c8920829c4f329643974a00a47775aac7de4ce25..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/kernel/figure/\344\273\273\345\212\241\347\212\266\346\200\201\350\277\201\347\247\273\347\244\272\346\204\217\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/kernel/figure/\345\257\274\345\207\272\347\232\204\347\254\246\345\217\267\350\241\250\344\277\241\346\201\257.png" "b/website/docs/.vuepress/public/images/device-dev/kernel/figure/\345\257\274\345\207\272\347\232\204\347\254\246\345\217\267\350\241\250\344\277\241\346\201\257.png" deleted file mode 100644 index 87d6aaf4a5f1d7f25c2ee2c964931c71388b043d..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/kernel/figure/\345\257\274\345\207\272\347\232\204\347\254\246\345\217\267\350\241\250\344\277\241\346\201\257.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/kernel/figure/\346\226\207\344\273\266\347\263\273\347\273\237\347\232\204\346\200\273\344\275\223\347\273\223\346\236\204.png" "b/website/docs/.vuepress/public/images/device-dev/kernel/figure/\346\226\207\344\273\266\347\263\273\347\273\237\347\232\204\346\200\273\344\275\223\347\273\223\346\236\204.png" deleted file mode 100644 index d24ef3ce327be6ce5f6c685a7f27fb354b732778..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/kernel/figure/\346\226\207\344\273\266\347\263\273\347\273\237\347\232\204\346\200\273\344\275\223\347\273\223\346\236\204.png" and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/porting/figure/bes2600_board_make_menuconfig.png b/website/docs/.vuepress/public/images/device-dev/porting/figure/bes2600_board_make_menuconfig.png deleted file mode 100644 index 4269a1c86e1662fb4ddd54cd85ab5608bf3e6202..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/porting/figure/bes2600_board_make_menuconfig.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/porting/figure/bes2600_hb_env.png b/website/docs/.vuepress/public/images/device-dev/porting/figure/bes2600_hb_env.png deleted file mode 100644 index 10fa486ec6f56f490a19d5021cb7b309b372ddb9..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/porting/figure/bes2600_hb_env.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/porting/figure/bes2600_hb_set.png b/website/docs/.vuepress/public/images/device-dev/porting/figure/bes2600_hb_set.png deleted file mode 100644 index 6cadca71b5dac5a945c16754085631dab3f9a626..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/porting/figure/bes2600_hb_set.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/porting/figure/bes2600_newlib_make_menuconfig.png b/website/docs/.vuepress/public/images/device-dev/porting/figure/bes2600_newlib_make_menuconfig.png deleted file mode 100644 index 2b844544b987abcb8346e56a27098ff150707705..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/porting/figure/bes2600_newlib_make_menuconfig.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/1-11.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/1-11.png deleted file mode 100644 index 8ed1535a6bc23dc5bd02fbd5a3f1392f46ad8d83..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/1-11.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/1.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/1.png deleted file mode 100644 index 791dfeae272070b7e285ea3070ebd3b1e9100eb5..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/1.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/10.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/10.png deleted file mode 100644 index 3b7f6f4766c54f6ca1e0057fc8f869785cc63e56..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/10.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/2021-01-27_170334-10.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/2021-01-27_170334-10.png deleted file mode 100644 index 5b573a4ddfe89fe25cb1b567736823244fdb9e97..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/2021-01-27_170334-10.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/3-0.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/3-0.png deleted file mode 100644 index f354b2d27ce06bd5af6a8702c0894bf5c50a97bb..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/3-0.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/3.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/3.png deleted file mode 100644 index 91f3fa22153f501e308fab46f92f2e95995f1917..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/3.png and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/3516\346\255\243\351\235\242.png" "b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/3516\346\255\243\351\235\242.png" deleted file mode 100644 index 6975fb5fef92e35dec2de84b7e7035a39794bdf4..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/3516\346\255\243\351\235\242.png" and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/4.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/4.png deleted file mode 100644 index 3f5fa2829949e59d498da9dd5ff1f48fa0647cf1..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/4.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/5.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/5.png deleted file mode 100644 index f3a76a6922315fe595ae4214331ce322766b3b48..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/5.png and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/Hi3516\347\274\226\350\257\221\350\256\276\347\275\256\345\233\276\344\276\213-Docker\346\226\271\345\274\217.png" "b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/Hi3516\347\274\226\350\257\221\350\256\276\347\275\256\345\233\276\344\276\213-Docker\346\226\271\345\274\217.png" deleted file mode 100644 index edb1711f3c1fa906940d8cbb8d8fcdeb2badd2b6..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/Hi3516\347\274\226\350\257\221\350\256\276\347\275\256\345\233\276\344\276\213-Docker\346\226\271\345\274\217.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/Hi3518\346\255\243\350\203\214\351\235\242.png" "b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/Hi3518\346\255\243\350\203\214\351\235\242.png" deleted file mode 100644 index 3e0ff2fdbfbaca179f1320b5d53ebf755d1c84a3..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/Hi3518\346\255\243\350\203\214\351\235\242.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/Hi3518\347\274\226\350\257\221\350\256\276\347\275\256\345\233\276\344\276\213-Docker\346\226\271\345\274\217.png" "b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/Hi3518\347\274\226\350\257\221\350\256\276\347\275\256\345\233\276\344\276\213-Docker\346\226\271\345\274\217.png" deleted file mode 100644 index ffdeca24f4b017d7a35fc96999d04faaa09972e5..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/Hi3518\347\274\226\350\257\221\350\256\276\347\275\256\345\233\276\344\276\213-Docker\346\226\271\345\274\217.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/Hi3861\345\274\200\345\217\221\346\235\277\345\244\226\350\247\202\345\233\276.png" "b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/Hi3861\345\274\200\345\217\221\346\235\277\345\244\226\350\247\202\345\233\276.png" deleted file mode 100644 index 5086d2b4518cfea4040f3cc243abb2e6087af350..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/Hi3861\345\274\200\345\217\221\346\235\277\345\244\226\350\247\202\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/Hi3861\347\274\226\350\257\221\350\256\276\347\275\256\345\233\276\344\276\213-Docker\346\226\271\345\274\217.png" "b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/Hi3861\347\274\226\350\257\221\350\256\276\347\275\256\345\233\276\344\276\213-Docker\346\226\271\345\274\217.png" deleted file mode 100644 index 9e53432ce41e67ee3e93e96d78262a6ace41d383..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/Hi3861\347\274\226\350\257\221\350\256\276\347\275\256\345\233\276\344\276\213-Docker\346\226\271\345\274\217.png" and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/Snap22.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/Snap22.png deleted file mode 100644 index d94579cb7ff78a40cef6cf5d1945e742a9551e8b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/Snap22.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/Snap23.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/Snap23.png deleted file mode 100644 index 92e51762a2dcd636135f6e7856073a5b8aecd1d6..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/Snap23.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/Snap24.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/Snap24.png deleted file mode 100644 index d4996e347660921fc3f723e5b48942f1fd6636f5..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/Snap24.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/changjian1-4.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/changjian1-4.png deleted file mode 100644 index 208a4fbace342514f59f0000c4d50f5dc9321f0f..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/changjian1-4.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/changjian1.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/changjian1.png deleted file mode 100644 index 208a4fbace342514f59f0000c4d50f5dc9321f0f..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/changjian1.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/hi3516-import-projects.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/hi3516-import-projects.png deleted file mode 100644 index 6c575b3495a0503e463a71f2b50766bc2f3e1b94..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/hi3516-import-projects.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/hi3518-import-projects.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/hi3518-import-projects.png deleted file mode 100644 index d54cd737e32311492dc2058251e7cb8acf905fb5..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/hi3518-import-projects.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/hi3861-import-projects.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/hi3861-import-projects.png deleted file mode 100644 index 6eaa9eb2450ef15e7124df610712fc797c548351..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/hi3861-import-projects.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/import-project-confirm.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/import-project-confirm.png deleted file mode 100644 index 27fe1d133a31b275a2788cab1f5b37dd3450a7df..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/import-project-confirm.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/import-project.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/import-project.png deleted file mode 100644 index 5ba534eaf39165891a31c7837ae7ff4126f6414c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/import-project.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/record-the-serial-port-number.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/record-the-serial-port-number.png deleted file mode 100644 index 09f33e3992c0c1d78713eea949e4b9a19f5802ec..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/record-the-serial-port-number.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/rk3568-helloworld.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/rk3568-helloworld.png deleted file mode 100644 index da22f3989b1daa362c7471789cdaa94ffb862f75..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/rk3568-helloworld.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/rk3568-run-configuration.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/rk3568-run-configuration.png deleted file mode 100644 index 504da23ba456a9c377525e22c4630361286b5dd7..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/rk3568-run-configuration.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/setenv-bootargs.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/setenv-bootargs.png deleted file mode 100644 index 802cce4e760102043f177cb2fa71e8bd16539ba1..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/setenv-bootargs.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001073838982.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001073838982.png deleted file mode 100644 index 0bbff7eb0b5ab322e8995acf2b86d93038c8530c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001073838982.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001074287476.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001074287476.png deleted file mode 100644 index 29a273e5115ffd7a0724cde58215ffb79827576c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001074287476.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001075566984.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001075566984.png deleted file mode 100644 index dee491aaa290b425a4a6cd9e4aee61b3b05cc3dc..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001075566984.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001113969536.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001113969536.png deleted file mode 100644 index baac7b26450b8bc195a0db0bb3bb41119c0d9828..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001113969536.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001114129426.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001114129426.png deleted file mode 100644 index c5548cb227bd024b49aa3adba0a20869581448e8..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001114129426.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001117329380.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001117329380.png deleted file mode 100644 index 7bd316dfd5a64c873682bf865a79ec1f2354cc40..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001117329380.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001160649343.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001160649343.png deleted file mode 100644 index 67d8044b72056d4ed6230ccc4ad99d5e954596b6..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001160649343.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001163045527.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001163045527.png deleted file mode 100644 index d8ac531b8265f265e2bd25518b212143fc61e4cf..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001163045527.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001171455564.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001171455564.png deleted file mode 100644 index c846be0d2767953df4a3ac78408963f252af040d..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001171455564.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001171455566.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001171455566.png deleted file mode 100644 index 7de3c25e7ef2abc8d85d8bc945249f571f6bf0c3..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001171455566.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001171455574.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001171455574.png deleted file mode 100644 index 24fb00fddc1213037e63e7674b4d2ce1bf6118f6..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001171455574.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001171615534.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001171615534.png deleted file mode 100644 index b6bc36af5339ea5a4f67640e69836965b3776e17..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001171615534.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001171615542.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001171615542.png deleted file mode 100644 index 527fe8b9836daf35c8300e0e84bdb2ca390f85a5..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001171615542.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001171774086.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001171774086.png deleted file mode 100644 index 1b002b247b704150040e90ecb149d782ba8db3a8..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001171774086.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001171774098.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001171774098.png deleted file mode 100644 index b6bc36af5339ea5a4f67640e69836965b3776e17..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001171774098.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001171934032.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001171934032.png deleted file mode 100644 index 9284df45bb1415d84f0325df85b4eb5c223281e8..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001171934032.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001174595590.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001174595590.png deleted file mode 100644 index 84d42fffbd87d0e719c69b6deda9e6c5e2b2db13..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001174595590.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001177301516.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001177301516.png deleted file mode 100644 index 4cc2bbf53d65b0c66f07b330aa8881c5194328bd..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001177301516.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001177474882.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001177474882.png deleted file mode 100644 index 68b1730cb6d1b91b6e364c7301d6dcc4c9976ec7..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001177474882.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001177478136.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001177478136.png deleted file mode 100644 index fcaf25e47e2e47ecad8aebe463aeccdf1d8bf85e..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001177478136.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001177480146.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001177480146.png deleted file mode 100644 index 99ed8317b5cee8e5e9d460ff31d5c8a1a2fe343e..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001177480146.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001177608370.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001177608370.png deleted file mode 100644 index 1ba77b7feaca23043e71171824cdead7c4f8f108..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001177608370.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001177798424.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001177798424.png deleted file mode 100644 index c93b7b610138e91c0b6b171cb515f540163e731b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001177798424.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001185334336.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001185334336.png deleted file mode 100644 index a8037d1ebc95a3c9383d87678981b3ae5ccc8144..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001185334336.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001193533352.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001193533352.png deleted file mode 100644 index da22f3989b1daa362c7471789cdaa94ffb862f75..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001193533352.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001194078294.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001194078294.png deleted file mode 100644 index 35a95f501f5e3c5c8ebf187e7f29e6af0a4566b0..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001194078294.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001194668634.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001194668634.png deleted file mode 100644 index 9f418473587db76e56981c0f384bf4b8634e3911..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001194668634.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001216535397.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001216535397.png deleted file mode 100644 index ad4fd618860ca9f79e9bdc39436c3b2f9cdb72de..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001216535397.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001216535401.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001216535401.png deleted file mode 100644 index 9284df45bb1415d84f0325df85b4eb5c223281e8..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001216535401.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001216693913.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001216693913.png deleted file mode 100644 index 1b002b247b704150040e90ecb149d782ba8db3a8..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001216693913.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001216693915.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001216693915.png deleted file mode 100644 index 9284df45bb1415d84f0325df85b4eb5c223281e8..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001216693915.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001217013865.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001217013865.png deleted file mode 100644 index b6bc36af5339ea5a4f67640e69836965b3776e17..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001217013865.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001217013871.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001217013871.png deleted file mode 100644 index 39ae26ac8f3254d023d6b90a9f9bb8a8ff0c940b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001217013871.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001222781271.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001222781271.png deleted file mode 100644 index 8d396bf2fc7b36362a95c6719d202b2f057e4a46..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001222781271.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001222794413.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001222794413.png deleted file mode 100644 index 764643ce134811551984284ed5ec6b60943f8ea4..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001222794413.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001222969587.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001222969587.png deleted file mode 100644 index 1ba77b7feaca23043e71171824cdead7c4f8f108..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001222969587.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001222981447.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001222981447.png deleted file mode 100644 index 6c862cc279d2936ddec4ecda0a23e1d55a63cbee..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001222981447.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001222994321.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001222994321.png deleted file mode 100644 index 07914f4f34921b06819ceb49cf63366dcc7f8502..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001222994321.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001222997983.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001222997983.png deleted file mode 100644 index f0d98bd6deb22fc7814a42630b8565d9b5979659..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001222997983.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001222999125.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001222999125.png deleted file mode 100644 index 5a709092da504fbb090ad8d44938e435712bc0eb..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001222999125.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001223000051.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001223000051.png deleted file mode 100644 index 6117c80b45f64348ad307e64723495cdc8c45cb1..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001223000051.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001223185957.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001223185957.png deleted file mode 100644 index 764643ce134811551984284ed5ec6b60943f8ea4..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001223185957.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001238878219.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001238878219.png deleted file mode 100644 index 579d6e190d4824cb866f90f2f3e72c4493aa6f4c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001238878219.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001239348791.png b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001239348791.png deleted file mode 100644 index c6507f28b980b84c65102aa844e93f806cb490a9..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/zh-cn_image_0000001239348791.png and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\345\205\201\350\256\270Visual-Studio-Code\345\272\224\347\224\250\350\256\277\351\227\256\347\275\221\347\273\234-9.png" "b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\345\205\201\350\256\270Visual-Studio-Code\345\272\224\347\224\250\350\256\277\351\227\256\347\275\221\347\273\234-9.png" deleted file mode 100644 index afc9028fbb61db82e6f1384032bb32f56ed2ec35..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\345\205\201\350\256\270Visual-Studio-Code\345\272\224\347\224\250\350\256\277\351\227\256\347\275\221\347\273\234-9.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\345\205\201\350\256\270Visual-Studio-Code\345\272\224\347\224\250\350\256\277\351\227\256\347\275\221\347\273\234.png" "b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\345\205\201\350\256\270Visual-Studio-Code\345\272\224\347\224\250\350\256\277\351\227\256\347\275\221\347\273\234.png" deleted file mode 100644 index afc9028fbb61db82e6f1384032bb32f56ed2ec35..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\345\205\201\350\256\270Visual-Studio-Code\345\272\224\347\224\250\350\256\277\351\227\256\347\275\221\347\273\234.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\345\205\263\351\227\255\344\270\262\345\217\243\347\273\210\347\253\257-3.png" "b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\345\205\263\351\227\255\344\270\262\345\217\243\347\273\210\347\253\257-3.png" deleted file mode 100644 index 0c1f60638087d0fe56127f2f842244355afad85f..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\345\205\263\351\227\255\344\270\262\345\217\243\347\273\210\347\253\257-3.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\345\205\263\351\227\255\344\270\262\345\217\243\347\273\210\347\253\257.png" "b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\345\205\263\351\227\255\344\270\262\345\217\243\347\273\210\347\253\257.png" deleted file mode 100644 index 0c1f60638087d0fe56127f2f842244355afad85f..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\345\205\263\351\227\255\344\270\262\345\217\243\347\273\210\347\253\257.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\346\211\223\345\274\200\344\270\262\345\217\243\345\244\261\350\264\245\345\233\276-1.png" "b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\346\211\223\345\274\200\344\270\262\345\217\243\345\244\261\350\264\245\345\233\276-1.png" deleted file mode 100644 index 0eee1bbff2e54816d6be05f7f3972a83f615884d..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\346\211\223\345\274\200\344\270\262\345\217\243\345\244\261\350\264\245\345\233\276-1.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\346\211\223\345\274\200\344\270\262\345\217\243\345\244\261\350\264\245\345\233\276.png" "b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\346\211\223\345\274\200\344\270\262\345\217\243\345\244\261\350\264\245\345\233\276.png" deleted file mode 100644 index 0eee1bbff2e54816d6be05f7f3972a83f615884d..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\346\211\223\345\274\200\344\270\262\345\217\243\345\244\261\350\264\245\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\346\237\245\346\211\276Visual-Studio-Code\345\272\224\347\224\250\345\233\276-8.png" "b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\346\237\245\346\211\276Visual-Studio-Code\345\272\224\347\224\250\345\233\276-8.png" deleted file mode 100644 index c735ae362e184083329cdf710289a169ad5625d4..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\346\237\245\346\211\276Visual-Studio-Code\345\272\224\347\224\250\345\233\276-8.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\346\237\245\346\211\276Visual-Studio-Code\345\272\224\347\224\250\345\233\276.png" "b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\346\237\245\346\211\276Visual-Studio-Code\345\272\224\347\224\250\345\233\276.png" deleted file mode 100644 index c735ae362e184083329cdf710289a169ad5625d4..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\346\237\245\346\211\276Visual-Studio-Code\345\272\224\347\224\250\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\346\237\245\346\211\276\346\230\257\345\220\246\345\255\230\345\234\250\345\215\240\347\224\250\344\270\262\345\217\243\347\232\204\347\273\210\347\253\257-2.png" "b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\346\237\245\346\211\276\346\230\257\345\220\246\345\255\230\345\234\250\345\215\240\347\224\250\344\270\262\345\217\243\347\232\204\347\273\210\347\253\257-2.png" deleted file mode 100644 index cfa0ceb21f5a11d459b93721f512309c9d6da2ac..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\346\237\245\346\211\276\346\230\257\345\220\246\345\255\230\345\234\250\345\215\240\347\224\250\344\270\262\345\217\243\347\232\204\347\273\210\347\253\257-2.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\346\237\245\346\211\276\346\230\257\345\220\246\345\255\230\345\234\250\345\215\240\347\224\250\344\270\262\345\217\243\347\232\204\347\273\210\347\253\257.png" "b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\346\237\245\346\211\276\346\230\257\345\220\246\345\255\230\345\234\250\345\215\240\347\224\250\344\270\262\345\217\243\347\232\204\347\273\210\347\253\257.png" deleted file mode 100644 index cfa0ceb21f5a11d459b93721f512309c9d6da2ac..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\346\237\245\346\211\276\346\230\257\345\220\246\345\255\230\345\234\250\345\215\240\347\224\250\344\270\262\345\217\243\347\232\204\347\273\210\347\253\257.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\346\240\207\345\207\206\347\263\273\347\273\237\345\277\253\351\200\237\345\205\245\351\227\250\346\265\201\347\250\213.png" "b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\346\240\207\345\207\206\347\263\273\347\273\237\345\277\253\351\200\237\345\205\245\351\227\250\346\265\201\347\250\213.png" deleted file mode 100644 index cb0aff9ea08110a305f663126f5e26f150f89344..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\346\240\207\345\207\206\347\263\273\347\273\237\345\277\253\351\200\237\345\205\245\351\227\250\346\265\201\347\250\213.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\347\263\273\347\273\237\345\220\257\345\212\250\346\225\210\346\236\234\345\233\276.jpg" "b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\347\263\273\347\273\237\345\220\257\345\212\250\346\225\210\346\236\234\345\233\276.jpg" deleted file mode 100644 index 31c5a26705cd1da6cf9cb6f3bb356994e4ecc22e..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\347\263\273\347\273\237\345\220\257\345\212\250\346\225\210\346\236\234\345\233\276.jpg" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\347\275\221\347\273\234\344\270\215\351\200\232-\345\215\225\346\235\277\346\227\240\346\263\225\350\216\267\345\217\226\346\226\207\344\273\266\345\233\276-5.png" "b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\347\275\221\347\273\234\344\270\215\351\200\232-\345\215\225\346\235\277\346\227\240\346\263\225\350\216\267\345\217\226\346\226\207\344\273\266\345\233\276-5.png" deleted file mode 100644 index 548e03da4b76123cb67d41cbd1de4a0f33f5ef4b..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\347\275\221\347\273\234\344\270\215\351\200\232-\345\215\225\346\235\277\346\227\240\346\263\225\350\216\267\345\217\226\346\226\207\344\273\266\345\233\276-5.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\347\275\221\347\273\234\344\270\215\351\200\232-\345\215\225\346\235\277\346\227\240\346\263\225\350\216\267\345\217\226\346\226\207\344\273\266\345\233\276.png" "b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\347\275\221\347\273\234\344\270\215\351\200\232-\345\215\225\346\235\277\346\227\240\346\263\225\350\216\267\345\217\226\346\226\207\344\273\266\345\233\276.png" deleted file mode 100644 index 548e03da4b76123cb67d41cbd1de4a0f33f5ef4b..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\347\275\221\347\273\234\344\270\215\351\200\232-\345\215\225\346\235\277\346\227\240\346\263\225\350\216\267\345\217\226\346\226\207\344\273\266\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\347\275\221\347\273\234\351\230\262\347\201\253\345\242\231\350\256\276\347\275\256\345\233\276-6.png" "b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\347\275\221\347\273\234\351\230\262\347\201\253\345\242\231\350\256\276\347\275\256\345\233\276-6.png" deleted file mode 100644 index 88cba0537b5431aa266364abbe19162130f4e3ca..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\347\275\221\347\273\234\351\230\262\347\201\253\345\242\231\350\256\276\347\275\256\345\233\276-6.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\347\275\221\347\273\234\351\230\262\347\201\253\345\242\231\350\256\276\347\275\256\345\233\276.png" "b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\347\275\221\347\273\234\351\230\262\347\201\253\345\242\231\350\256\276\347\275\256\345\233\276.png" deleted file mode 100644 index 88cba0537b5431aa266364abbe19162130f4e3ca..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\347\275\221\347\273\234\351\230\262\347\201\253\345\242\231\350\256\276\347\275\256\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\277\253\351\200\237\345\205\245\351\227\250\346\265\201\347\250\213.png" "b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\277\253\351\200\237\345\205\245\351\227\250\346\265\201\347\250\213.png" deleted file mode 100644 index c453bf36bea44aad382c65cd18ea0d8abbead981..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\277\253\351\200\237\345\205\245\351\227\250\346\265\201\347\250\213.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\351\230\262\347\201\253\345\242\231\345\222\214\347\275\221\347\273\234\344\277\235\346\212\244\347\225\214\351\235\242\345\233\276-7.png" "b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\351\230\262\347\201\253\345\242\231\345\222\214\347\275\221\347\273\234\344\277\235\346\212\244\347\225\214\351\235\242\345\233\276-7.png" deleted file mode 100644 index 775ce6fe99d4894b39f2bdd613097dcaf11a37b2..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\351\230\262\347\201\253\345\242\231\345\222\214\347\275\221\347\273\234\344\277\235\346\212\244\347\225\214\351\235\242\345\233\276-7.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\351\230\262\347\201\253\345\242\231\345\222\214\347\275\221\347\273\234\344\277\235\346\212\244\347\225\214\351\235\242\345\233\276.png" "b/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\351\230\262\347\201\253\345\242\231\345\222\214\347\275\221\347\273\234\344\277\235\346\212\244\347\225\214\351\235\242\345\233\276.png" deleted file mode 100644 index 775ce6fe99d4894b39f2bdd613097dcaf11a37b2..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/quick-start/figures/\351\230\262\347\201\253\345\242\231\345\222\214\347\275\221\347\273\234\344\277\235\346\212\244\347\225\214\351\235\242\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/subsystems/figure/HiTrace\345\272\224\347\224\250\345\234\272\346\231\257.png" "b/website/docs/.vuepress/public/images/device-dev/subsystems/figure/HiTrace\345\272\224\347\224\250\345\234\272\346\231\257.png" deleted file mode 100644 index dddc8365b2905b3522d9692531d773817bb1bcab..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/subsystems/figure/HiTrace\345\272\224\347\224\250\345\234\272\346\231\257.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/subsystems/figure/USB\346\234\215\345\212\241\346\236\266\346\236\204\345\233\276.png" "b/website/docs/.vuepress/public/images/device-dev/subsystems/figure/USB\346\234\215\345\212\241\346\236\266\346\236\204\345\233\276.png" deleted file mode 100644 index 3aaf512454de1bee6a16925ec2346f894c5b724a..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/subsystems/figure/USB\346\234\215\345\212\241\346\236\266\346\236\204\345\233\276.png" and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/subsystems/figure/zh-cn_image_0000001115980740.png b/website/docs/.vuepress/public/images/device-dev/subsystems/figure/zh-cn_image_0000001115980740.png deleted file mode 100644 index 4398ed073145d97228df055f4b6eb9137482619f..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/subsystems/figure/zh-cn_image_0000001115980740.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/device-dev/subsystems/figure/zh-cn_image_0000001192123772.png b/website/docs/.vuepress/public/images/device-dev/subsystems/figure/zh-cn_image_0000001192123772.png deleted file mode 100755 index 6b0ac3897c71d9e3ad8fd0194bbd95d53cd04445..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/device-dev/subsystems/figure/zh-cn_image_0000001192123772.png and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/subsystems/figure/\344\270\232\345\212\241\350\260\203\347\224\250\346\265\201\347\250\213\345\233\276\357\274\210\350\267\250\350\256\276\345\244\207-\350\267\250\350\277\233\347\250\213\345\220\214\346\255\245\350\260\203\347\224\250\357\274\211.png" "b/website/docs/.vuepress/public/images/device-dev/subsystems/figure/\344\270\232\345\212\241\350\260\203\347\224\250\346\265\201\347\250\213\345\233\276\357\274\210\350\267\250\350\256\276\345\244\207-\350\267\250\350\277\233\347\250\213\345\220\214\346\255\245\350\260\203\347\224\250\357\274\211.png" deleted file mode 100644 index bec87564b4026335bff09e48f6f128076b76c5a0..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/subsystems/figure/\344\270\232\345\212\241\350\260\203\347\224\250\346\265\201\347\250\213\345\233\276\357\274\210\350\267\250\350\256\276\345\244\207-\350\267\250\350\277\233\347\250\213\345\220\214\346\255\245\350\260\203\347\224\250\357\274\211.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/subsystems/figure/\344\270\232\345\212\241\350\260\203\347\224\250\346\265\201\347\250\213\345\272\217\345\210\227\345\233\276.png" "b/website/docs/.vuepress/public/images/device-dev/subsystems/figure/\344\270\232\345\212\241\350\260\203\347\224\250\346\265\201\347\250\213\345\272\217\345\210\227\345\233\276.png" deleted file mode 100644 index fba8cd412fec208991aa70e2f026edfcb9b045b6..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/subsystems/figure/\344\270\232\345\212\241\350\260\203\347\224\250\346\265\201\347\250\213\345\272\217\345\210\227\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/subsystems/figure/\344\270\232\345\212\241\350\260\203\347\224\250\346\265\201\347\250\213\346\200\247\350\203\275\350\200\227\346\227\266\345\210\206\345\270\203.png" "b/website/docs/.vuepress/public/images/device-dev/subsystems/figure/\344\270\232\345\212\241\350\260\203\347\224\250\346\265\201\347\250\213\346\200\247\350\203\275\350\200\227\346\227\266\345\210\206\345\270\203.png" deleted file mode 100644 index ae69bbc6e37310dc0e1808a270292a7872de2b26..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/subsystems/figure/\344\270\232\345\212\241\350\260\203\347\224\250\346\265\201\347\250\213\346\200\247\350\203\275\350\200\227\346\227\266\345\210\206\345\270\203.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/device-dev/subsystems/figure/\345\220\214\346\255\245\351\200\232\344\277\241\345\244\204\347\220\206.png" "b/website/docs/.vuepress/public/images/device-dev/subsystems/figure/\345\220\214\346\255\245\351\200\232\344\277\241\345\244\204\347\220\206.png" deleted file mode 100644 index 585d8aac7b4857645b78ab11effbe900e5350f9d..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/device-dev/subsystems/figure/\345\220\214\346\255\245\351\200\232\344\277\241\345\244\204\347\220\206.png" and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/database/figures/zh-cn_image_0000001183386164.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/database/figures/zh-cn_image_0000001183386164.png deleted file mode 100644 index 0538c11963b2e54fccc57d560831d41ceab82446..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/database/figures/zh-cn_image_0000001183386164.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/database/public_sys-resources/icon-note.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/database/public_sys-resources/icon-note.gif deleted file mode 100644 index 6314297e45c1de184204098efd4814d6dc8b1cda..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/database/public_sys-resources/icon-note.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/media/figures/zh-cn_image_0000001182608857.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/media/figures/zh-cn_image_0000001182608857.png deleted file mode 100755 index e0777e28838f6d2455233f2068339f8548f50c67..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/media/figures/zh-cn_image_0000001182608857.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/public_sys-resources/icon-note.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/public_sys-resources/icon-note.gif deleted file mode 100755 index 6314297e45c1de184204098efd4814d6dc8b1cda..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/public_sys-resources/icon-note.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001089359413.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001089359413.png deleted file mode 100644 index 85345789b60927729e9243798fe122c64ca92687..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001089359413.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001113808114.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001113808114.png deleted file mode 100644 index da3c279ef8812b9d028a1993074430b5a06d50c9..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001113808114.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001115066116.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001115066116.png deleted file mode 100644 index 357798e173fa7e3b419cc5990aa0737925e1f7b9..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001115066116.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001118018088.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001118018088.png deleted file mode 100644 index d4e1c7bd6773fc5b3ab5b473e28593110f3c820f..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001118018088.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001152459178.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001152459178.png deleted file mode 100644 index 5ee6a55e53e57843300bd5ec0cce4a175e97a29e..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001152459178.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001155643492.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001155643492.png deleted file mode 100644 index 9e3afd2b96c1a01b3e966c37e60755d1f179363c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001155643492.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001162463400.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001162463400.png deleted file mode 100644 index 48239f38c31b907155d7b0501401ca9dd8635d73..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001162463400.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001163314102.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001163314102.png deleted file mode 100644 index 286a49def18618c79088deeb49203969ac6ce4c0..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001163314102.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001163472654.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001163472654.png deleted file mode 100644 index 5328a3c1b62eb8281e316d5ae4a6ca11694ec4a2..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001163472654.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001163632602.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001163632602.png deleted file mode 100644 index 10c5cf41ab78ea58c194fe1ed0429352e85a88a8..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001163632602.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001163915523.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001163915523.png deleted file mode 100644 index 352eaed40ac96dc5d3bae82591e5c801daaa8d56..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001163915523.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001163918627.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001163918627.png deleted file mode 100644 index 6967c6b140c7e07003fc4548989ea78d9e5fc940..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001163918627.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001164417356.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001164417356.png deleted file mode 100644 index 97795b40abbea9f58aabe62dd7643eca208315e3..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001164417356.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001164498191.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001164498191.png deleted file mode 100644 index 30efd063397893ff925743b681f943696f10512b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001164498191.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001164577336.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001164577336.png deleted file mode 100644 index 1127bbfabc9ef766284eec12c574096f8bb45ac3..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001164577336.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001166582138.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001166582138.png deleted file mode 100644 index 36dc2d05ca4eb23505a73cb0d1606afd3bf844d8..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001166582138.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001166740700.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001166740700.png deleted file mode 100644 index 9d9dc95f14cdc94007dbf04f217d496d49f9318c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001166740700.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001167690688.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001167690688.png deleted file mode 100644 index cb05a7cb0fa33a9d9074f4424a3851478935ff33..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001167690688.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001167850660.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001167850660.png deleted file mode 100644 index 469ca774dde99530329d5e7bd62a5a40fb16237b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001167850660.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001168898456.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001168898456.png deleted file mode 100644 index b62a4291cbe98e250fd9dcc65e9f91ba67445575..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001168898456.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001169221404.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001169221404.png deleted file mode 100644 index c44bd561803aa0dc4cafcf0db68bf38f5ba43013..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001169221404.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001202722349.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001202722349.png deleted file mode 100644 index 99330a4f3ef2978dd6736d96e00c88cea8d25f32..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001202722349.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001207744539.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001207744539.png deleted file mode 100644 index 5e1269e9e8fb620f8ed6051395c727590e6dc1bc..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001207744539.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001208006117.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001208006117.png deleted file mode 100644 index 5c576d84b0ca4b369cdaac5aa7de19718628bc37..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001208006117.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001208210505.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001208210505.png deleted file mode 100644 index 934b69477b4c10140f0cf8198e4248c53bdb0364..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001208210505.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001208394019.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001208394019.png deleted file mode 100644 index aa7f5ffb0d59c7ab7a1784bfde775aeccc16a424..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001208394019.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001209817299.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001209817299.png deleted file mode 100644 index aa7f5ffb0d59c7ab7a1784bfde775aeccc16a424..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001209817299.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001210018359.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001210018359.png deleted file mode 100644 index 7fe695d19f2f15a7ce9c941907f17becf0d9b849..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001210018359.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001212062065.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001212062065.png deleted file mode 100644 index 708b49814e270289c6d1c96520aa6d90ba0edb9c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001212062065.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001213130527.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001213130527.png deleted file mode 100644 index afdab82267fcd7d5eacae76eba500baa3bbecd40..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001213130527.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001213883165.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001213883165.png deleted file mode 100644 index 7f99945dc6e30516a6084896b3f146af89dc2f23..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001213883165.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001214043107.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001214043107.png deleted file mode 100644 index 2d8dd786a91b784794a19f8b2975616912586286..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001214043107.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001238733799.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001238733799.png deleted file mode 100644 index 37736ed10ff7cd16907684dfe2c1d6bb19c61d50..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001238733799.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001238853759.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001238853759.png deleted file mode 100644 index 6bf1ed8cb6d6b6d88b57e533f9efe840afee95b5..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001238853759.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000002021121901.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000002021121901.png deleted file mode 100644 index 9a84c3f66275c8ea2a50b9ba9ab0ead3842274cc..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000002021121901.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000002021121902.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000002021121902.png deleted file mode 100644 index 6bef885f7c487473ca1b329d41c6414735555b42..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000002021121902.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000002021121903.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000002021121903.png deleted file mode 100644 index ba3923fef0ad89fa38fa170d2680931d1eb1ea55..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000002021121903.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000002021121904.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000002021121904.png deleted file mode 100644 index 9250f90cf1e377c8bb33adf9965436ed7ddbadbf..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000002021121904.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000002021121905.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000002021121905.png deleted file mode 100644 index f278f73fb4cd0dba70cae1835dd7a45d2686038b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000002021121905.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000002021121906.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000002021121906.png deleted file mode 100644 index 61535cb2fe6b4197e95cff8691fe27973c5ecde8..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000002021121906.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000002021121907.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000002021121907.png deleted file mode 100644 index 32771bf5f9639aa8ebdd1922f8088965404674ca..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000002021121907.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/public_sys-resources/icon-note.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/public_sys-resources/icon-note.gif deleted file mode 100644 index 6314297e45c1de184204098efd4814d6dc8b1cda..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/quick-start/public_sys-resources/icon-note.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/apis/figures/zh-cn_image_0000001164217678.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/apis/figures/zh-cn_image_0000001164217678.png deleted file mode 100644 index 1e2cc34bf20dcd27dc9dff6a3eb6eb56dd4809c4..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/apis/figures/zh-cn_image_0000001164217678.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/apis/figures/zh-cn_image_0000001200913929.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/apis/figures/zh-cn_image_0000001200913929.png deleted file mode 100644 index 6eb89772d315b440636e8ceeda928e5db6b34e40..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/apis/figures/zh-cn_image_0000001200913929.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/apis/public_sys-resources/icon-note.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/apis/public_sys-resources/icon-note.gif deleted file mode 100644 index 6314297e45c1de184204098efd4814d6dc8b1cda..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/apis/public_sys-resources/icon-note.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/apis/public_sys-resources/icon-notice.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/apis/public_sys-resources/icon-notice.gif deleted file mode 100644 index 86024f61b691400bea99e5b1f506d9d9aef36e27..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/apis/public_sys-resources/icon-notice.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/0.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/0.png deleted file mode 100644 index 99b8f25e0fe85fdbde44a4eae2fdb208561259e6..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/0.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/000000.jpg b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/000000.jpg deleted file mode 100644 index 502180f0903ac8c51440c5bc266b0d60811572c7..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/000000.jpg and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/001.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/001.gif deleted file mode 100644 index b5bac4f696cc84f6e3116483209f51c08e0ad532..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/001.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/1-2.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/1-2.png deleted file mode 100644 index 5e7bc3dec11daa00059d3ec93d77ac15ce357a14..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/1-2.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/1-3.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/1-3.gif deleted file mode 100644 index 1346a2deeab10fd18c60e7ff184bbff436bc528f..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/1-3.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/1.jpg b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/1.jpg deleted file mode 100644 index e5bd1c300d6de63a6627c1610ec09ddf89aed768..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/1.jpg and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/11-1.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/11-1.gif deleted file mode 100644 index 7ca939d4de4d330dea962b991362b41ef0aacba9..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/11-1.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/11.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/11.png deleted file mode 100644 index cb270578b22922b3eabadd6801c08ccf6db99a00..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/11.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/111.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/111.png deleted file mode 100644 index e0517663d25f8f857ac08dd4bd1c36ad76190663..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/111.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/12.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/12.gif deleted file mode 100644 index 561e823f7a9eb432e2aedbbf84637f8be40b0337..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/12.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/2-4.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/2-4.gif deleted file mode 100644 index 82b802bf8c65f080c0d068689dc9e580840c5f55..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/2-4.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/2.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/2.png deleted file mode 100644 index e506fd8f37b0e522d5925b509def595e5db653c3..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/2.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/22.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/22.png deleted file mode 100644 index 63e63411d18c5394c103e63d15bb125bc01915d0..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/22.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/222.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/222.png deleted file mode 100644 index d6ec48b52853bc5eddff3eee7978ef9c313e99aa..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/222.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/3.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/3.png deleted file mode 100644 index b370937f36a472829e7a08a4439b4025721b0437..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/3.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/333.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/333.png deleted file mode 100644 index ed5ee3a87580dd9f485988467163d3a3ea7e95b6..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/333.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/4-0.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/4-0.gif deleted file mode 100644 index 1589d8650fa225626fb8dadf085732f92170e40f..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/4-0.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/4.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/4.gif deleted file mode 100644 index 1dc0753ba566436d3b8611f5efce0cadce36b7d0..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/4.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/444.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/444.png deleted file mode 100644 index da8624b6dbff497762753fe8b5786c3d552c78ed..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/444.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/5.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/5.gif deleted file mode 100644 index 83d8a2f9864d59fd0c64a03cafcb0bf50432ac92..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/5.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/6.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/6.gif deleted file mode 100644 index aacc036cfc90859465a0b3da908a61533b866806..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/6.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/9.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/9.gif deleted file mode 100644 index 0654ceaa02e5d502239d152e83382df901d7376f..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/9.gif and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/AnimationAPI\350\243\201\345\211\252.gif" "b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/AnimationAPI\350\243\201\345\211\252.gif" deleted file mode 100644 index 294687cdfb0cf7f2ea34f91c87d0a6394b32bff0..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/AnimationAPI\350\243\201\345\211\252.gif" and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/GIF.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/GIF.gif deleted file mode 100644 index 98bf461673a8f11366755e99b8f59baf7cc282e8..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/GIF.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/Video_2021-03-26_154549.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/Video_2021-03-26_154549.gif deleted file mode 100644 index f4d097a34aef9e583651d11133dff575345f0272..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/Video_2021-03-26_154549.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/animate-1.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/animate-1.gif deleted file mode 100644 index 6c85de05a6145492a24a9ded5d2b399776489ecc..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/animate-1.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/animate-3.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/animate-3.gif deleted file mode 100644 index 86f15fb83d5be7e8ed145d69ed8b869be40c4e45..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/animate-3.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/animate-4.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/animate-4.gif deleted file mode 100644 index 1b0d4fd3ea6759b909f1714cdb9b0f6794153d76..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/animate-4.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/animate-transform.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/animate-transform.gif deleted file mode 100644 index e83e2ce11234a97242e1f57204b96568ad248d3d..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/animate-transform.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/animate-transform2.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/animate-transform2.gif deleted file mode 100644 index 3c65871bb208133129e46956ecee119276a390a5..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/animate-transform2.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/animate-transform3.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/animate-transform3.gif deleted file mode 100644 index b29849bb066b5b5cd870c2b0b0dd1e50b9f90494..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/animate-transform3.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/barchart.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/barchart.png deleted file mode 100644 index aa4ba3f9fa64250b1b86bd6d39b6a8071d3de1c3..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/barchart.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/c3.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/c3.png deleted file mode 100644 index dca96aeb057ba12dc63365e613007e54dd268a40..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/c3.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/ellipse.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/ellipse.png deleted file mode 100644 index d0379dfc66b4d2151dae49beeb8af38c774381aa..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/ellipse.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/gauge.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/gauge.png deleted file mode 100644 index 31c0141d716059519377e1f39b9b8305370f239a..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/gauge.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/grid.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/grid.gif deleted file mode 100644 index b6d2387c6db849678ae8897878fe3117170ea42a..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/grid.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/image-animator.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/image-animator.gif deleted file mode 100644 index 8321366bdb79b9e6530d53b0f45a6465ae7b967d..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/image-animator.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/list.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/list.png deleted file mode 100644 index 7933730b5753d05a6f5734cb3d7ebb39aeb5f173..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/list.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/list6.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/list6.gif deleted file mode 100644 index 6bc775a4f7b81841450b0650917f76a3cee9945a..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/list6.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/menu13.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/menu13.gif deleted file mode 100644 index 413b6584d5939509e2052d5cf7c35ec307ff759c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/menu13.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/mmmm.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/mmmm.gif deleted file mode 100644 index 5959ae695322f2e1eda3364d7603ec9d2ca10819..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/mmmm.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/panel6.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/panel6.gif deleted file mode 100644 index a61ac61b038539afb5c2e20271a6c9761468c289..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/panel6.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/progress.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/progress.png deleted file mode 100644 index 7edb3bedb97ee4b203cd35a6ef6642740f410846..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/progress.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/sample1.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/sample1.gif deleted file mode 100644 index 6168a14aa67c866abf6185ba3a3c2ae9f595153c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/sample1.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/screenshot.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/screenshot.png deleted file mode 100644 index ddd4ee663382d41cef4f57b30e646ba423fa84bc..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/screenshot.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/slider.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/slider.png deleted file mode 100644 index d0167fe6773371fa70d8bf32c3a3953ed1e1455b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/slider.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/smoothOff.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/smoothOff.png deleted file mode 100644 index c699e78774fadbd8da8c0cc290e88294d445aa6f..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/smoothOff.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/sssssss.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/sssssss.png deleted file mode 100644 index e108f5f8f2e096b319ef5097145ab43f2ad97594..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/sssssss.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/tab.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/tab.gif deleted file mode 100644 index fea6fcac566df71d32643b81579a59bbe4e1b580..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/tab.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/text-animate-part1.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/text-animate-part1.gif deleted file mode 100644 index 4731d53600aa7dced61e10ce21505a5086280edd..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/text-animate-part1.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/text-animate-part2.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/text-animate-part2.gif deleted file mode 100644 index 6107d0c5a64f409759d4c1ba44682996f181c5f2..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/text-animate-part2.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/text-animate-part3.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/text-animate-part3.gif deleted file mode 100644 index addf2ea9fc2a9b83b8650382f9b6dc1901f4a229..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/text-animate-part3.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/text-part1.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/text-part1.png deleted file mode 100644 index c2ec8cd839cb27361a863f4c770de8053eb32755..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/text-part1.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/textPath-part1.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/textPath-part1.png deleted file mode 100644 index 79406f279f47e28a360437878959ce07d607b3ff..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/textPath-part1.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/textPath-part2.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/textPath-part2.png deleted file mode 100644 index f4823452cce3c085af33ebf1675c8517974709b0..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/textPath-part2.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/textPath-part3.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/textPath-part3.png deleted file mode 100644 index 889ef6e963acef24e01d14d363ac52a444298145..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/textPath-part3.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/textPath-part4.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/textPath-part4.png deleted file mode 100644 index 2a325881b033c685328eb51e9fedcd7e135cbf77..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/textPath-part4.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/textpath-animate1.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/textpath-animate1.gif deleted file mode 100644 index 64c013cdb72cacb96a429a4a9cf7cdeac38e783e..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/textpath-animate1.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/textpath-animate2.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/textpath-animate2.gif deleted file mode 100644 index 640fae7689352208a0680ae4e12635f6e345cbda..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/textpath-animate2.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/textpath-animate3.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/textpath-animate3.gif deleted file mode 100644 index 044f442002cf25b56b89849a4255ec7583cbfc2a..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/textpath-animate3.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/textpath-animate4.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/textpath-animate4.gif deleted file mode 100644 index 4da6410ea036e3f7c4eb725ec9ccd220349799d1..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/textpath-animate4.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/tspan-animate-part1.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/tspan-animate-part1.gif deleted file mode 100644 index a5db977af7a1a2ec2096aa76b5f82a245b832429..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/tspan-animate-part1.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/tspan-animate-part2.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/tspan-animate-part2.gif deleted file mode 100644 index e72fb4ff01bbdf45951799fb20fc7a3ca85dead0..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/tspan-animate-part2.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/tspan-animate-part3.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/tspan-animate-part3.gif deleted file mode 100644 index 871a368ff3e43f32bdfec427a35024a84e6cb441..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/tspan-animate-part3.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/tspan-animate-part4.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/tspan-animate-part4.gif deleted file mode 100644 index da89f35c1163f16e9eebac8a11c59290d4e2feda..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/tspan-animate-part4.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/tspan-part1.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/tspan-part1.png deleted file mode 100644 index 245c704bb52935d5683a8d6b2c1e23a5389e4bc5..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/tspan-part1.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127125124.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127125124.png deleted file mode 100644 index 0bdeb353cc2ec200b106de975f1478597e863c49..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127125124.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127125132.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127125132.png deleted file mode 100644 index 994f8510b56d1f66d8a40dbd0349ca61baf242cb..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127125132.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127125136.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127125136.png deleted file mode 100644 index 280d0df92bf3cfebba6610f6050939ce4d53fb1d..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127125136.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127125162.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127125162.png deleted file mode 100644 index dfee4f8cddcddd2ada89cb6d7e812fd0739d9cb8..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127125162.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127125202.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127125202.png deleted file mode 100644 index 6fed31434380106e80629feafdb374c7ba68ee51..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127125202.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127125204.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127125204.png deleted file mode 100644 index 95770e0a80cd7581b8739c852239dff75b60f655..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127125204.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127125208.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127125208.png deleted file mode 100644 index d7d5ebbd57bcdd5e5f77001aa6770ff433654be9..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127125208.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127125212.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127125212.png deleted file mode 100644 index bc43e2bfefbb6cc9fb09bc92ff0740a514dd2ff5..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127125212.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127125220.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127125220.png deleted file mode 100644 index 362c486fa6a7545fd3eaca6cf9da6c3ab56b3136..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127125220.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127284954.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127284954.png deleted file mode 100644 index 1fa94a7479a1c1ac1294575a7bd0658e5b21fac9..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127284954.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127284958.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127284958.png deleted file mode 100644 index 4d0696a9ade017acbbdfb8812dafdec5d715cac5..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127284958.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127284984.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127284984.png deleted file mode 100644 index 4cef59797fd8b9650c398562ac0b473485a9274b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127284984.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127285024.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127285024.png deleted file mode 100644 index fffc6016e519844a25a096547bc7824f7a3450b0..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127285024.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127285034.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127285034.gif deleted file mode 100644 index 17f4ea3f2983fc9a0ad21238b9345e11aa0318c3..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127285034.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127285076.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127285076.png deleted file mode 100644 index 3ecdf0c714fa633f03db339626f51e62318cbf82..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127285076.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001150719520.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001150719520.gif deleted file mode 100644 index 3658d687cad3bdb3f0b06b5ace29d75948e0a613..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001150719520.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001152588538.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001152588538.png deleted file mode 100644 index dc8f8a0cbb105c4d791bb867771bb9bc1bfbb468..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001152588538.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001152588626.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001152588626.png deleted file mode 100644 index ec8094c23fc3f601f4899bac7b148b8309f600d9..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001152588626.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001152610806.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001152610806.png deleted file mode 100644 index b3a47a84d8086ca0806bc958f745f29821c47cc2..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001152610806.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001152833768.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001152833768.gif deleted file mode 100644 index 4c7a300f18ca0f9671cacbc68590834f00ee23a1..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001152833768.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001152834002.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001152834002.png deleted file mode 100644 index 27ee8b6da1ca2a0bd728157bbd750a9cf4b228f7..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001152834002.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001152862510.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001152862510.gif deleted file mode 100644 index 601f4cc2f4871e29eee74beae214d4b82f4a47df..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001152862510.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001153427082.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001153427082.png deleted file mode 100644 index 1144db651b011598fc9192a4f8b4e67efa63e1a1..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001153427082.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001166484430.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001166484430.png deleted file mode 100644 index d6bbab16659f4b34b38a714510665ea7fd309055..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001166484430.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001166962736.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001166962736.png deleted file mode 100644 index 47f90714bcb37e4df1b698503db6893d6c2a98c4..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001166962736.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001167001464.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001167001464.png deleted file mode 100644 index 5113bc6bad4f88bc2558aae304394e00e107ce88..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001167001464.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001167046832.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001167046832.png deleted file mode 100644 index 33787429dd3205f9faac254950e95c097bd63b21..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001167046832.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001167472798.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001167472798.png deleted file mode 100644 index 151ef990edbb33e1f54632609990f6c540149a5e..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001167472798.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001167631876.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001167631876.png deleted file mode 100644 index 44ae627d6e40dd4b297eccdcf1c5dceef5a08d82..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001167631876.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001167950468.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001167950468.png deleted file mode 100644 index 904fdcf258a2dc8350ace79f0abea18aadc721e0..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001167950468.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001167953648.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001167953648.png deleted file mode 100644 index e89a1b24da145cf480cceb28ed7249b717e614bf..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001167953648.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001168111514.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001168111514.png deleted file mode 100644 index 8f6b4abcc27039c624bd21aad775db7c47a22dea..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001168111514.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001168111610.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001168111610.png deleted file mode 100644 index 4c8300af3bdf43e4d2192699b5ed4065fef451c0..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001168111610.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001168984880.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001168984880.png deleted file mode 100644 index cc1dc87c79f827c8bb5be3f3771c37f4cb8b214e..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001168984880.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001168984882.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001168984882.png deleted file mode 100644 index 24d65ef9913f6b82a6f70ac2a4e415745112b108..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001168984882.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169142476.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169142476.png deleted file mode 100644 index f4e18dbe51e815ccdfc6f594e3424850c3b93a12..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169142476.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169143586.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169143586.png deleted file mode 100644 index 1d5aedb22cb51d00b176f44c5ac5f3ad29d843f2..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169143586.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169144864.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169144864.png deleted file mode 100644 index 3cc02a6196604a6a3d64b9961c04aaaa51dc829e..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169144864.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169151508.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169151508.png deleted file mode 100644 index 9ac4a39e925322831752617b71a77d040626d251..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169151508.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169301188.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169301188.png deleted file mode 100644 index bd4f47314f89fa4bbbd2d14527dd250b5e3e141b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169301188.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169303414.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169303414.png deleted file mode 100644 index 8192453ec25d486b3923da4a25b0a6fe5034d869..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169303414.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169303416.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169303416.png deleted file mode 100644 index 68562c1006ec7c61c49c24aec99ecfd173ca055a..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169303416.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169309948.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169309948.png deleted file mode 100644 index 8253c65764c8d74e0a25404aa62fdd69d43f3c26..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169309948.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169315920.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169315920.png deleted file mode 100644 index 2f786e33181995c2b5bf5f835df4557ff3f7e9b4..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169315920.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169461910.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169461910.png deleted file mode 100644 index db54e678d8c42daca3e56dd85567c9978a9657c8..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169461910.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169463368.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169463368.png deleted file mode 100644 index e061801d6eeb27d7fee0b287414e512559a87ea9..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169463368.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169463370.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169463370.png deleted file mode 100644 index 67959174e9b810b9278a7940bc097ac0c0738c7e..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169463370.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169469914.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169469914.png deleted file mode 100644 index 42efd9018bc05408596a768cbbe309f1e46273d7..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169469914.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169470288.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169470288.png deleted file mode 100644 index 3404b29dff12b910ae1be71ebf762252895468a8..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169470288.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173164789.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173164789.png deleted file mode 100644 index 6829d2d87db5a5e28ad1ade1ca45eada97945bec..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173164789.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173164793.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173164793.png deleted file mode 100644 index 3e4169c4139b0204e7b97dc7b6deeb2389610de2..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173164793.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173164845.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173164845.png deleted file mode 100644 index b64c5df26d8c2fb403e08feb72f8979af95ea44f..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173164845.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173164853.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173164853.png deleted file mode 100644 index 8a8562ea95b31781a67259225366d4bf9b86506a..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173164853.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173164867.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173164867.png deleted file mode 100644 index 094d157e55693d0697e407f5f7299c6e2da24f56..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173164867.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173164869.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173164869.png deleted file mode 100644 index 3866e5677395048de391ed6159a0fe5572f6d91e..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173164869.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173164871.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173164871.png deleted file mode 100644 index 787fe9541b386b83b07e478651637f0f450e99f2..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173164871.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173164873.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173164873.png deleted file mode 100644 index d31b9766cc593c0be44ae1abdba2f9f45eaa024e..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173164873.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173164891.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173164891.png deleted file mode 100644 index 38a3de061a3816a2eac62ae3d43284789c0ca31f..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173164891.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173324721.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173324721.png deleted file mode 100644 index 02fe52a90168d22959c9a703951730c9e7813e8a..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173324721.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173324749.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173324749.png deleted file mode 100644 index 3dccd46b21e76a7bbbaabc1ab77a29bd72ae850d..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173324749.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173324751.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173324751.png deleted file mode 100644 index f9db5c31c8eae66244cd3f6e11336f72284bb2a6..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173324751.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173324783.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173324783.png deleted file mode 100644 index e05df70223233ed7162d57f021a167eec9d9686a..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173324783.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173324787.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173324787.png deleted file mode 100644 index 06f1abd77c6c0036539e710f09617c3ef2ce0648..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173324787.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173324797.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173324797.gif deleted file mode 100644 index 0b1bc728e1dd3c79f4a24bb1516ed752e32c74cd..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173324797.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173324843.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173324843.png deleted file mode 100644 index f627659cef03f443e01fb28b44ceb9363369b8d8..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173324843.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001178875308.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001178875308.png deleted file mode 100644 index c085790c6651bf041b772f58f5665d442caf6f4a..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001178875308.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001178886129.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001178886129.png deleted file mode 100644 index 584a2841e6dbd6db9070438c0a56e717a34b133f..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001178886129.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001179035242.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001179035242.png deleted file mode 100644 index c7311ac9226ca3c0a04cef9a51961424daf8a47a..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001179035242.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001193704354.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001193704354.png deleted file mode 100644 index 9be62c4f9a5b1ad4b6a1d647c3b0e2d6ac57a33e..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001193704354.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001198670487.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001198670487.png deleted file mode 100644 index 5ecd604af13a7917485488f641b525d15e654eee..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001198670487.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001198898293.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001198898293.png deleted file mode 100644 index 3db4286a873ef0bd14e7adeb085239a9941f918b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001198898293.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001212124299.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001212124299.png deleted file mode 100644 index 9a73bd33782f06a704ed9b288226dfa381d1d57c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001212124299.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001213192781.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001213192781.png deleted file mode 100644 index 3108e0436219c1c3a7335679cdfea962c49f454d..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001213192781.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001213193285.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001213193285.png deleted file mode 100644 index f59a10b44b9e9793bc3a9134f6c4633c8cfb49ce..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001213193285.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214460669.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214460669.png deleted file mode 100644 index 6e58c669a2976297f71d35c304e988c2884e7dc0..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214460669.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214463281.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214463281.png deleted file mode 100644 index 56c65edbcd66a2ebe9d8ef35c55eba90652bca0f..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214463281.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214463283.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214463283.png deleted file mode 100644 index cbf23e9e6897ac272a1c486edebd80d12dd44132..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214463283.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214469787.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214469787.png deleted file mode 100644 index 63b480df9e9700601da85abef015c8326095851f..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214469787.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214619417.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214619417.png deleted file mode 100644 index 5da42e3e14d601745274cb62d914c6600620bb25..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214619417.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214621177.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214621177.png deleted file mode 100644 index 01f53998ba343eb77fbd7b78414e47e1fb68819e..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214621177.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214623227.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214623227.png deleted file mode 100644 index 2f9a8bacc0f78cb141820e8188d4ae5ef03dc7c1..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214623227.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214623229.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214623229.png deleted file mode 100644 index 625b158772a6198abe3a81719cfc2bd2598bed91..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214623229.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214629745.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214629745.png deleted file mode 100644 index fea0122d3ef81899a02199c6cb265a099ad6c44f..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214629745.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214630783.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214630783.png deleted file mode 100644 index 3917378fdcb47448e7daf8ae197e6d033fd345e9..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214630783.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214703717.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214703717.png deleted file mode 100644 index 1362b8a3d98f4edf36420d3799f01476817e43d4..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214703717.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214704759.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214704759.png deleted file mode 100644 index 6afdd1b39e4bcb3664c7664a55b47b8537f4aeaa..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214704759.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214717247.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214717247.png deleted file mode 100644 index 4481b08ab897619b408425f9bfe0fd5b1fcb6ef0..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214717247.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214811029.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214811029.png deleted file mode 100644 index 1d71cee4618f1f2822cea1031c9b0e5d602e0a9b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214811029.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214822091.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214822091.png deleted file mode 100644 index 0c8973bcb7d55910c6702fe6b9b54506ad3b3727..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214822091.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214824709.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214824709.png deleted file mode 100644 index d957a62a03d1429504d89d3e7ee649d4b54a24ba..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214824709.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214837127.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214837127.png deleted file mode 100644 index 658dca4b52032016c15f77a94b3ef76c093b1d2c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214837127.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214837333.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214837333.png deleted file mode 100644 index 63f343e89f62b15c117e0148c87ac049308c3117..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214837333.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001224354967.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001224354967.png deleted file mode 100644 index 7469c1e329fc86f0ca7eec9374be7c2c03ae2d6b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001224354967.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001236697937.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001236697937.png deleted file mode 100644 index 8cc5fef8ddb3f1af9d6b231f9183f5094faf5434..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001236697937.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001238184345.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001238184345.png deleted file mode 100644 index 13b38a17af260f22ef850403d9351cff1860bb9c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001238184345.png and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/\345\205\261\344\272\253\345\205\203\347\264\240\350\275\254\345\234\272\351\273\230\350\256\244\346\225\210\346\236\234.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/\345\205\261\344\272\253\345\205\203\347\264\240\350\275\254\345\234\272\351\273\230\350\256\244\346\225\210\346\236\234.png" deleted file mode 100644 index 70aa78c1973add7bf07ec822d905c1bc98cb47f9..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/\345\205\261\344\272\253\345\205\203\347\264\240\350\275\254\345\234\272\351\273\230\350\256\244\346\225\210\346\236\234.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/\345\215\241\347\211\207\350\275\254\345\234\272.gif" "b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/\345\215\241\347\211\207\350\275\254\345\234\272.gif" deleted file mode 100644 index 62bf33b76b0c0e257efa48131d0acd2249a2bb04..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/\345\215\241\347\211\207\350\275\254\345\234\272.gif" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/\346\215\225\350\216\267.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/\346\215\225\350\216\267.png" deleted file mode 100644 index 2ed837e111c3ac1ba1eafb5b28da581ef4de5d22..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-js/figures/\346\215\225\350\216\267.png" and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/1.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/1.png deleted file mode 100644 index 3c6e9c72046d14a46ed93a1075ee580510e64f92..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/1.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/1111.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/1111.png deleted file mode 100644 index 3fbc152bb27dc98b9db8ace65a5b820c72f77879..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/1111.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/11111-5.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/11111-5.png deleted file mode 100644 index 5da42e3e14d601745274cb62d914c6600620bb25..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/11111-5.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/11111.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/11111.png deleted file mode 100644 index 5da42e3e14d601745274cb62d914c6600620bb25..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/11111.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/2-01.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/2-01.png deleted file mode 100644 index e766d36181c3d1fbd96bb0acab1b3eb670e14cd4..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/2-01.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/222.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/222.gif deleted file mode 100644 index 0befd736af77db15c203c4a5578929baf1d83e08..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/222.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/2222.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/2222.png deleted file mode 100644 index 3b1d0fd10bd28897bf3b1103e5bdba0fdb9d17f1..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/2222.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/5.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/5.gif deleted file mode 100644 index 587269a1e0647be0acb21deced4722037bb07013..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/5.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/66666.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/66666.gif deleted file mode 100644 index b40f786a2f583af59e9f63d35ab1d503f51525da..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/66666.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/AlertDialog.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/AlertDialog.gif deleted file mode 100644 index 30e89347337d9e358d4b823c7658490e032eb435..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/AlertDialog.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/AnimateTo.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/AnimateTo.gif deleted file mode 100644 index 864e3a39a57b7a45f63a07fe50545629db3527c4..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/AnimateTo.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/AttrAnimation.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/AttrAnimation.gif deleted file mode 100644 index 69cc497191325216c394de0ce00328a7c5c5fc8c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/AttrAnimation.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Blank1.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Blank1.gif deleted file mode 100644 index 2547cd4af312ee9a2cfc6c3c61b630fdcd7426f9..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Blank1.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Blank2.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Blank2.gif deleted file mode 100644 index fe04e9611135b8d8cd4f9ace0acf1d1a5797bf6c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Blank2.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Button.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Button.gif deleted file mode 100644 index bb1dd72311c866d5bf31a706d75fc1e107a5a946..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Button.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/ColumnSplit.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/ColumnSplit.gif deleted file mode 100644 index ac096bd0f149b02d46013420a9c323fe8aa5805a..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/ColumnSplit.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Counter.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Counter.gif deleted file mode 100644 index a8c10650641ca05ec76b2ff74621506bba7034f4..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Counter.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/DisplayPriorityExample.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/DisplayPriorityExample.gif deleted file mode 100644 index 5bd33e278c8c9edccf66470d2c3585792fceb4ff..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/DisplayPriorityExample.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/F.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/F.gif deleted file mode 100644 index 070ae9d042d5211b2ccc6c187ec0f87a90d2c963..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/F.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Flex01.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Flex01.gif deleted file mode 100644 index 8da8a4adcc50c16eafb2378f0bbab0706471ae8b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Flex01.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Flex03.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Flex03.gif deleted file mode 100644 index 1be92ae9b4a61f304b91c5b03f7b0e799ac679fa..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Flex03.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Flex04-2.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Flex04-2.gif deleted file mode 100644 index 18e5eef8f04c15625f4e3ae3ab050083b3acc962..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Flex04-2.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Flex04.jpg b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Flex04.jpg deleted file mode 100644 index bf5c3a49c58818ec9dec43db3c2d4c5e16949a94..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Flex04.jpg and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Flex05.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Flex05.gif deleted file mode 100644 index 791930fb1f2f681dac85167f646dbcf88d121882..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Flex05.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/GIF-4.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/GIF-4.gif deleted file mode 100644 index 5bcc79b53b227b6bd0484045d20743d9686c8e08..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/GIF-4.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/GIF.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/GIF.gif deleted file mode 100644 index 8eceb3bf5313485a1fedda5768e70cdb5febc464..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/GIF.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/GIF1.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/GIF1.gif deleted file mode 100644 index e97b2a2406059ce3af77ade27bb634845d807726..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/GIF1.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/GIF2.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/GIF2.gif deleted file mode 100644 index b0a6fc0df420fa15f8a0e476da5fa8592bbc751b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/GIF2.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/GIF4.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/GIF4.gif deleted file mode 100644 index c7532ed87726ac7591901514a7396b617daa10f0..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/GIF4.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/GestureGroup.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/GestureGroup.gif deleted file mode 100644 index 0213b777e0352ac7830bde7d9bff40edf69a1a51..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/GestureGroup.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Image1.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Image1.gif deleted file mode 100644 index 05ad0a8aa0ae63ae9193aa1c9b3f943f060220da..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Image1.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Image2.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Image2.png deleted file mode 100644 index 085d31e9bf7c5740ac3c46d04c4098e64eb3a544..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Image2.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Image3.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Image3.gif deleted file mode 100644 index ecbaeb8cc1a3ec9e1ecfd253b605be50836b1f46..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Image3.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/ImageAnimator.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/ImageAnimator.gif deleted file mode 100644 index 8b877c7bedb4021440eeac2b0a9a9c5d28377da3..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/ImageAnimator.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/KeyEvent.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/KeyEvent.gif deleted file mode 100644 index acbeb39682258aa37a6162230fa5b5bd1ed6a226..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/KeyEvent.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/ListItem.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/ListItem.gif deleted file mode 100644 index 557213e5ff5c63c5f3b3db7ffbd56e80eef688f1..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/ListItem.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/LongPressGesture.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/LongPressGesture.gif deleted file mode 100644 index 41a08cbcc0e58aadc12328ab72a8ec3f01a375ad..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/LongPressGesture.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/MediaQuery.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/MediaQuery.gif deleted file mode 100644 index 6150bbeae602c3522416fc9a6ec9fe49f55ebd2c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/MediaQuery.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Navigator.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Navigator.gif deleted file mode 100644 index 0faae458a1e97e2806130a05d9154af7a2a6d2e3..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Navigator.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/PageTransition1.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/PageTransition1.gif deleted file mode 100644 index 93c0edf4c20f9d29725065f5bdf7a5208da2e2fd..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/PageTransition1.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/PageTransition2.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/PageTransition2.gif deleted file mode 100644 index 4770183525428b6df03bf1b3eb8cc4160a1568a1..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/PageTransition2.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/PanGesture.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/PanGesture.gif deleted file mode 100644 index d98a4ebc55b1fbc7c598a08095f871f4c3ab8678..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/PanGesture.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Panel.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Panel.gif deleted file mode 100644 index 1cd6ff13714a55e253e9649c007080b47f02f791..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Panel.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/PinchGesture.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/PinchGesture.gif deleted file mode 100644 index d5b827457bbb9fbb12c8d1cbee4886dede46a048..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/PinchGesture.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Rating.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Rating.gif deleted file mode 100644 index 49922f7f7d934216dcbf8837c697d13063d101a4..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Rating.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/RotationGesture.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/RotationGesture.gif deleted file mode 100644 index 323cd3b5bf1913f6740db4ce2203a07fcb30fb5e..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/RotationGesture.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/RowSplit.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/RowSplit.gif deleted file mode 100644 index 0ea18f82170eb3309aefb8af24ef89f886718bdd..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/RowSplit.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/SharedTransition.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/SharedTransition.gif deleted file mode 100644 index 3c81f8cfffb0c4d064335c9ebc0e8c918d10035a..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/SharedTransition.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Span.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Span.gif deleted file mode 100644 index 3a2f5de773fed90a3c0c058d0b27bc0edd1f1904..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Span.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Tabs.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Tabs.gif deleted file mode 100644 index 49a1503a776598da93f4089bb079c61125a71a2e..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Tabs.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/TapGesture.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/TapGesture.gif deleted file mode 100644 index 33a9b7c1a5a408a94cd58261742a29dc7519d880..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/TapGesture.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Text1.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Text1.gif deleted file mode 100644 index 627fff6c85420f981d9ae844d0e53a77d254ac7c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Text1.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Text2.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Text2.gif deleted file mode 100644 index 8b359a2d036a69fd442145d55e23031755c925c1..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Text2.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Transition.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Transition.gif deleted file mode 100644 index e7dc2d19afd049c44c75e1288063df96326e524c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/Transition.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/alphabetindexer.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/alphabetindexer.gif deleted file mode 100644 index 438c67b65f13bfcd1ee3eb19e4f0c1265ae16278..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/alphabetindexer.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/appear.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/appear.gif deleted file mode 100644 index c18ae783333765788db1b8bf6107ee0c117ec9e6..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/appear.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/back.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/back.png deleted file mode 100644 index 4e556034506103bd7e7b491d72ef74b9eccde52c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/back.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/badge.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/badge.gif deleted file mode 100644 index 016da55bb5d98a3d2787d870bf2575fbaf383990..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/badge.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/border.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/border.gif deleted file mode 100644 index 89da584f60db920d0801f9e40138a56fd4242fd3..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/border.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/circle.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/circle.png deleted file mode 100644 index d34ba19a667f40c8dc3b4e668095bda1bd4868aa..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/circle.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/clip.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/clip.png deleted file mode 100644 index c1bfde1c57599f8cc40d0dc50179c71f4dfc2978..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/clip.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/colorGradient.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/colorGradient.png deleted file mode 100644 index 2c20e6d28a0636b8122f6377052933c33cfcffaf..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/colorGradient.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/column.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/column.gif deleted file mode 100644 index 3213fc124d255584be8f21a3074806c304953e7b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/column.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/customdialog.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/customdialog.gif deleted file mode 100644 index 17ae76b8141d65147f9774d130711f46bf332d02..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/customdialog.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/datapanel.jpg b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/datapanel.jpg deleted file mode 100644 index b12c5fb6563c7ee9d8dfa7e6af1cfe1dcfa1361c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/datapanel.jpg and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/divider.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/divider.png deleted file mode 100644 index f2deeb8445fe0f3b66d2b0facbf9e0f0ed9911ca..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/divider.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/duande.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/duande.gif deleted file mode 100644 index 7ed4e908925042a11312dd27aa1c28e8c91d8d8c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/duande.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/ellipse.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/ellipse.png deleted file mode 100644 index b85ac72fcec0f4b2eb752307d4abe05ef4795ef2..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/ellipse.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/enabled.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/enabled.gif deleted file mode 100644 index c48a9fa7aca3a160a68868d06d48f6af22ce6d87..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/enabled.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/flex.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/flex.png deleted file mode 100644 index 884eb29ed12c00641fec55f358a41f15f581c335..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/flex.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/flex02.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/flex02.png deleted file mode 100644 index f27757afb281875f5cd4fca0e4b86684cdf0f1a8..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/flex02.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/gauge.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/gauge.png deleted file mode 100644 index 2eb96b00f11e597fcc3e3d5ef32701e0a4ef5f5b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/gauge.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/grid-3.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/grid-3.gif deleted file mode 100644 index 9ead4d671531532629b2fbf2f411ce4008dde3ba..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/grid-3.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/grid.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/grid.gif deleted file mode 100644 index 1868b355aac470977ff1b36a5c1b3adf007dbfda..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/grid.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/griditem.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/griditem.gif deleted file mode 100644 index 07a8d81674d244e6ec76c0b43558890caf53062e..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/griditem.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/line.jpg b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/line.jpg deleted file mode 100644 index e3d3e1023746c03c9ad426328de0114321ac3f66..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/line.jpg and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/list.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/list.gif deleted file mode 100644 index cc49b51652e53b6caa3888b054dbea94c2f498eb..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/list.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/lottie-ark-2-0-canvas-ui-animate.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/lottie-ark-2-0-canvas-ui-animate.gif deleted file mode 100644 index e22d25b7aa139409766723e4ed0fd6172b85b6cf..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/lottie-ark-2-0-canvas-ui-animate.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/menu.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/menu.gif deleted file mode 100644 index f30a8d85e898213691abd5369c9c1008d399274b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/menu.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/motion.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/motion.gif deleted file mode 100644 index ec293bafaf6cd7204ebb231c4eee7daa504b78c3..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/motion.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/opacity.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/opacity.gif deleted file mode 100644 index b0e5e55e1af19bb46a74300bf2ae60f95225a874..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/opacity.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/overlay.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/overlay.png deleted file mode 100644 index 8c8194c14b5ca1ea743782db95027035370ead7e..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/overlay.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/path.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/path.png deleted file mode 100644 index b7c6998d7f55a75562fbf709aa84b4bd12922ae6..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/path.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/polygon.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/polygon.gif deleted file mode 100644 index 78e7436bf654889a3a04e9d2e5dd53f5fb562906..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/polygon.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/polyline.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/polyline.gif deleted file mode 100644 index 49167ceae5eb50a96334c73496ed534d25bbecf4..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/polyline.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/popup.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/popup.gif deleted file mode 100644 index 7631bb0d995839d59a9d3876f91fd7e688c35758..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/popup.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/position.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/position.gif deleted file mode 100644 index 3174da059167d3560a99d50cca06ec678cabed96..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/position.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/position2.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/position2.gif deleted file mode 100644 index ee69d15a36eda3047be045a3d037fd27a37166fe..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/position2.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/progress.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/progress.png deleted file mode 100644 index 0ff7595bc619e62c05376cd7b57a473dde3e9386..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/progress.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/q1.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/q1.png deleted file mode 100644 index cdb53d971cbadb6479cc755ae0a95cd4c0c3bff1..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/q1.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/qrcode.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/qrcode.png deleted file mode 100644 index 6b2c6040690cebf054da6dbc70c87d14c82be9d6..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/qrcode.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/rect.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/rect.png deleted file mode 100644 index ad2c71e4bcc008c0d286a05b2e969103aa06236d..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/rect.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/row.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/row.png deleted file mode 100644 index 3b44b9a41cb0fa78afcde81f82e0ad63c90de58d..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/row.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/s1.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/s1.png deleted file mode 100644 index 15e3b57fbcadac9e9c6f4c1446bd16c53845f888..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/s1.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/s3.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/s3.png deleted file mode 100644 index 3b2e35a9a29c6f849cd4e766c8fac0016b95365d..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/s3.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/s4-(1).png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/s4-(1).png deleted file mode 100644 index 4f6f99db3df495c744c612e3a2dff20d2a757a43..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/s4-(1).png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/scroll.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/scroll.gif deleted file mode 100644 index fa6a5f8e639b2b8b73bdae505da6b67800c5eb63..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/scroll.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/size.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/size.gif deleted file mode 100644 index dffa33c4389c4576d2492cd98499b71715b8ead8..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/size.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/slider.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/slider.gif deleted file mode 100644 index b1724791e4acb31d193a0dce267e42c99288c6bd..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/slider.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/stack.jpg b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/stack.jpg deleted file mode 100644 index b0e1a1070b2bdbb158e1ba66caa2269626acd1ef..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/stack.jpg and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/stepper.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/stepper.gif deleted file mode 100644 index 6b44b6a2adc2528e13e95bc10d2a67874226a63b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/stepper.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/swiper.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/swiper.gif deleted file mode 100644 index 5db399f79a02f496aea43ff72e55e29a0bb05a9a..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/swiper.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/textarea1.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/textarea1.gif deleted file mode 100644 index 5c888d43eeb0d0d3ab08e0c2922f136ed0b3d142..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/textarea1.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/textinput1.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/textinput1.gif deleted file mode 100644 index 9fa5c075ecc4f157f1e66316f4b56f28ffa2007d..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/textinput1.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/textstyle.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/textstyle.png deleted file mode 100644 index 5499902761b534f84a0405094afe2fb5d4724322..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/textstyle.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/toggle.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/toggle.gif deleted file mode 100644 index f6b7ae5ac2bf443574de54cd4df472a8f0cd1aba..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/toggle.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/unnaming-(3).png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/unnaming-(3).png deleted file mode 100644 index 293ead152f1cde4757f85101d9c8c96bdec4dee7..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/unnaming-(3).png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/unnaming-(4).png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/unnaming-(4).png deleted file mode 100644 index e2a8cf9cf4fc88e27e7adb0ad9caf2df9ca978c6..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/unnaming-(4).png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/visibility.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/visibility.gif deleted file mode 100644 index fe69ab973cfd17f540dd1da4fd04de890af95c74..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/visibility.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zIndex.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zIndex.png deleted file mode 100644 index 92ddc7d5d9ee2f87128ed8951b2294ea3c07f650..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zIndex.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595194.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595194.png deleted file mode 100644 index 348499bc3787a833ab3da5f87500b11c9c93773e..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595194.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595214.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595214.png deleted file mode 100644 index e544a2958b969018ff6bfe8b44bb8758c2aea61a..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595214.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595216.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595216.png deleted file mode 100644 index f410f22c1dd0ba7e1c9718eb3995de5f5033c0a6..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595216.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595220.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595220.png deleted file mode 100644 index 2eed5759714b99dc039faab67acdfe6d67bfc6ac..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595220.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595224.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595224.png deleted file mode 100644 index 72a515c8b425037a4307ef1b16def3e528aab4a0..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595224.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595226.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595226.png deleted file mode 100644 index 92a309337be0e2f4c49d0484dab0ffd19584b534..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595226.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595228.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595228.png deleted file mode 100644 index 1f4208ebcf5ffeeda0d1f5c452327c8fd8dcf7ac..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595228.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595230.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595230.png deleted file mode 100644 index b4fd4aff2fb6b7a32fcb8af41a84fbf57c26d035..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595230.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595232.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595232.png deleted file mode 100644 index 160278c82fcdf310c796609d5ee29a2a4869af9e..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595232.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595234.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595234.png deleted file mode 100644 index ec9ddc678b5a74f1e5ae78ba6a9c35618f31a589..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595234.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595238.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595238.png deleted file mode 100644 index d3db21e0e3da6d8663f59b2ddabd9e50d6eb1e6a..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595238.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755172.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755172.png deleted file mode 100644 index 5869f7cdc9a81adc7f03d07ab121c6b8433637d9..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755172.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755174.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755174.png deleted file mode 100644 index adb4986f7f26047e65e552c570e3f9e62a2037ac..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755174.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755178.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755178.png deleted file mode 100644 index 801bf97495213f41c2b196b2f170af85b156dd5b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755178.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755180.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755180.png deleted file mode 100644 index 4fb651372a67eca9de3848baa6b66cac0ee9f173..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755180.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755182.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755182.png deleted file mode 100644 index 0d9cf4d6e06b96da9b93608e7a050af71eaa5032..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755182.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755188.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755188.png deleted file mode 100644 index cb250dfc130cc329ae9dc74ddb861e8753d419c3..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755188.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755194.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755194.png deleted file mode 100644 index 4608132f8e4292a3fe0174a65a9a3f2fc428c0e7..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755194.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915130.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915130.png deleted file mode 100644 index 1ba89fa119f9a64c74b9353c20ec3d741aaad9be..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915130.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915154.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915154.png deleted file mode 100644 index f36078d6d832fa757378b72fa0739f66fe781c64..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915154.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915158.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915158.png deleted file mode 100644 index d8bdc2d4a59d0b3c5de0f8c020d30ffc5b2ead7a..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915158.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915162.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915162.png deleted file mode 100644 index 1ba89fa119f9a64c74b9353c20ec3d741aaad9be..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915162.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915178.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915178.gif deleted file mode 100644 index b1808e80a0e4d055d54b886ecca3ddc8efa64b9a..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915178.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915180.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915180.png deleted file mode 100644 index 7dafd299b8e48ead7d6f783e5a370e31257e341c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915180.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915184.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915184.png deleted file mode 100644 index ee1d5493dd38de810cbfe5e41e54d507b839e9c9..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915184.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075122.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075122.gif deleted file mode 100644 index b26dc8bf409987fa624f6dc0cec1c56043e7b37a..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075122.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075134.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075134.png deleted file mode 100644 index 241fe8546ea2acfdb7baf2c5e66a8af2f0d7b593..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075134.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075154.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075154.png deleted file mode 100644 index 8c06945a1790bb0a741b330fe0a9170dd2a3a92d..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075154.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075164.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075164.png deleted file mode 100644 index 45be809bdb14e8badfaac2dc8e2486864d29f763..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075164.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075166.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075166.png deleted file mode 100644 index fb7fc25c17990998ba263a8525e6a110794c0d87..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075166.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075168.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075168.png deleted file mode 100644 index 5eecca641660f12e3ad2ba7b97b97eca253a4acf..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075168.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075170.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075170.png deleted file mode 100644 index 241fe8546ea2acfdb7baf2c5e66a8af2f0d7b593..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075170.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075172.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075172.png deleted file mode 100644 index 5d649492978121a484c2a7a55d4548384c919149..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075172.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075178.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075178.png deleted file mode 100644 index 4f115a17e671fa21da2d44cd82bf7b0f3c70c0a6..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075178.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075180.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075180.png deleted file mode 100644 index 7cbe07731306eff949ff7ced4dd7eb4a374c8310..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075180.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193321136.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193321136.png deleted file mode 100644 index 72a515c8b425037a4307ef1b16def3e528aab4a0..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193321136.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193321138.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193321138.png deleted file mode 100644 index fb7fc25c17990998ba263a8525e6a110794c0d87..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193321138.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193322850.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193322850.png deleted file mode 100644 index 657eee10e270eb448fc7f7f4b24b18134a42d5dc..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193322850.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193322872.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193322872.png deleted file mode 100644 index 7cbe07731306eff949ff7ced4dd7eb4a374c8310..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193322872.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193322910.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193322910.png deleted file mode 100644 index e764c43599592d821c403aac0d3fa40d9edd22e5..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193322910.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193436448.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193436448.png deleted file mode 100644 index 2eed5759714b99dc039faab67acdfe6d67bfc6ac..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193436448.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193481094.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193481094.png deleted file mode 100644 index 1f4208ebcf5ffeeda0d1f5c452327c8fd8dcf7ac..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193481094.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193481096.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193481096.png deleted file mode 100644 index 138e011909c2d4738f3cd9671a79ea0c37cb5b87..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193481096.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193481098.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193481098.png deleted file mode 100644 index defc3c9eb037c06b894ee2e30563facb8c8375ab..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193481098.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193482814.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193482814.png deleted file mode 100644 index 45be809bdb14e8badfaac2dc8e2486864d29f763..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193482814.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193482866.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193482866.png deleted file mode 100644 index 5eecca641660f12e3ad2ba7b97b97eca253a4acf..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193482866.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193641084.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193641084.png deleted file mode 100644 index 563ce2878d24a7fa46044f201433d759c3fa9001..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193641084.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193641086.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193641086.png deleted file mode 100644 index 801bf97495213f41c2b196b2f170af85b156dd5b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193641086.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193642802.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193642802.png deleted file mode 100644 index 160278c82fcdf310c796609d5ee29a2a4869af9e..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193642802.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193642848.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193642848.png deleted file mode 100644 index 83b7a51accdda21d21a39e5e9d917d75811cb496..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193642848.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193737314.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193737314.png deleted file mode 100644 index e3b4b42aecaef72ed4a08b3566a895b3f9b12343..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193737314.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193756416.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193756416.png deleted file mode 100644 index b0b8bdc7fc7cd417340bbcda6845fd7de0098930..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193756416.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193801070.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193801070.png deleted file mode 100644 index 92a309337be0e2f4c49d0484dab0ffd19584b534..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193801070.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193801072.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193801072.png deleted file mode 100644 index b4fd4aff2fb6b7a32fcb8af41a84fbf57c26d035..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193801072.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193802788.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193802788.png deleted file mode 100644 index c1803b711d45a86552a2be4099424206a1561534..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193802788.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193802836.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193802836.png deleted file mode 100644 index ad8582f58ed05f9ac3b8962f82d8565d1f580f6c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193802836.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355087.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355087.gif deleted file mode 100644 index 38502c83c52aa9229da69d638e4b9b1f5a35009b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355087.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355121.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355121.png deleted file mode 100644 index e764c43599592d821c403aac0d3fa40d9edd22e5..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355121.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355131.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355131.png deleted file mode 100644 index 138e011909c2d4738f3cd9671a79ea0c37cb5b87..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355131.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355133.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355133.png deleted file mode 100644 index 088d5a479cc188332bb7295b31aea277897faca8..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355133.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355135.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355135.png deleted file mode 100644 index 10059591af349daced4bf7abeb009209a3e90f1d..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355135.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355137.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355137.png deleted file mode 100644 index 83b7a51accdda21d21a39e5e9d917d75811cb496..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355137.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475107.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475107.gif deleted file mode 100644 index b3966d0abb39044241ee174a126fcf919f402d98..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475107.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475113.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475113.png deleted file mode 100644 index 84d835e7feeac31e42c1a53670ef6c999ea4bfe2..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475113.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475123.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475123.png deleted file mode 100644 index e3b4b42aecaef72ed4a08b3566a895b3f9b12343..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475123.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475133.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475133.png deleted file mode 100644 index f0e245a5c576e92810baacaa09af99f108a010a9..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475133.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475137.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475137.png deleted file mode 100644 index defc3c9eb037c06b894ee2e30563facb8c8375ab..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475137.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475139.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475139.png deleted file mode 100644 index 9cb1361bd9aded6d58d51ae771558989977a0608..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475139.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555149.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555149.png deleted file mode 100644 index 1ba89fa119f9a64c74b9353c20ec3d741aaad9be..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555149.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555151.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555151.png deleted file mode 100644 index 1330e2e2a6395703f9c3747252c1e0a69ae6f4f0..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555151.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555155.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555155.png deleted file mode 100644 index 071919ed3a638630f33a337f920ae2e60c9c21bc..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555155.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555163.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555163.png deleted file mode 100644 index 26fb5384338291f3eb372abd526f0727ce759bdc..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555163.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555165.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555165.png deleted file mode 100644 index 50726d3e461d7a5dbfec674899fee603aaf41bee..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555165.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555167.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555167.png deleted file mode 100644 index af02181de0d07d5311b09c8d05c2a018e6e5b4cf..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555167.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555173.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555173.png deleted file mode 100644 index 657eee10e270eb448fc7f7f4b24b18134a42d5dc..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555173.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555179.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555179.png deleted file mode 100644 index cb250dfc130cc329ae9dc74ddb861e8753d419c3..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555179.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555181.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555181.png deleted file mode 100644 index b2728fd1b4e050edddf499398b44a7e3aa634109..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555181.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715141.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715141.png deleted file mode 100644 index c1803b711d45a86552a2be4099424206a1561534..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715141.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715149.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715149.png deleted file mode 100644 index b0b8bdc7fc7cd417340bbcda6845fd7de0098930..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715149.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715151.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715151.png deleted file mode 100644 index 1f4208ebcf5ffeeda0d1f5c452327c8fd8dcf7ac..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715151.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715153.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715153.png deleted file mode 100644 index 22e84d1b8951b163748a079b6d1d302148d3b6bb..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715153.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715155.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715155.png deleted file mode 100644 index 945862898489d8e008e94abbcd691aa307b18d06..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715155.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715159.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715159.png deleted file mode 100644 index 3e7218eb57566d86457a9fbd4a8ed0f0dd490c3f..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715159.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715165.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715165.png deleted file mode 100644 index f5cd637e5bf9db13e3334ca00413e3a91412c813..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715165.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238281067.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238281067.png deleted file mode 100644 index 22e84d1b8951b163748a079b6d1d302148d3b6bb..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238281067.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238281069.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238281069.png deleted file mode 100644 index 088d5a479cc188332bb7295b31aea277897faca8..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238281069.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238282783.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238282783.png deleted file mode 100644 index 10059591af349daced4bf7abeb009209a3e90f1d..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238282783.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238282827.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238282827.png deleted file mode 100644 index b2728fd1b4e050edddf499398b44a7e3aa634109..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238282827.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238401029.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238401029.png deleted file mode 100644 index d0e446b213816e4db8d67a9898da1afa7b8226ad..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238401029.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238401031.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238401031.png deleted file mode 100644 index d3db21e0e3da6d8663f59b2ddabd9e50d6eb1e6a..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238401031.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238402745.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238402745.png deleted file mode 100644 index 4608132f8e4292a3fe0174a65a9a3f2fc428c0e7..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238402745.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238402777.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238402777.png deleted file mode 100644 index f5cd637e5bf9db13e3334ca00413e3a91412c813..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238402777.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238457271.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238457271.png deleted file mode 100644 index 4fb651372a67eca9de3848baa6b66cac0ee9f173..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238457271.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238476361.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238476361.png deleted file mode 100644 index 5d649492978121a484c2a7a55d4548384c919149..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238476361.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238521019.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238521019.png deleted file mode 100644 index af02181de0d07d5311b09c8d05c2a018e6e5b4cf..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238521019.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238521021.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238521021.png deleted file mode 100644 index 3e7218eb57566d86457a9fbd4a8ed0f0dd490c3f..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238521021.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238522733.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238522733.png deleted file mode 100644 index 4f115a17e671fa21da2d44cd82bf7b0f3c70c0a6..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238522733.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238522783.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238522783.png deleted file mode 100644 index bc093379e122dcac29c4c8d04560d26bfc23d472..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238522783.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238537297.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238537297.png deleted file mode 100644 index 50726d3e461d7a5dbfec674899fee603aaf41bee..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238537297.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238556395.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238556395.png deleted file mode 100644 index 294b32cf04462b04243afb828199be9b95e6dd17..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238556395.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238601051.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238601051.png deleted file mode 100644 index 1f4208ebcf5ffeeda0d1f5c452327c8fd8dcf7ac..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238601051.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238601053.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238601053.png deleted file mode 100644 index 945862898489d8e008e94abbcd691aa307b18d06..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238601053.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238602771.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238602771.png deleted file mode 100644 index ec9ddc678b5a74f1e5ae78ba6a9c35618f31a589..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238602771.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238602821.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238602821.png deleted file mode 100644 index 9cb1361bd9aded6d58d51ae771558989977a0608..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238602821.png and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/\346\250\252\345\261\217\346\230\276\347\244\272.gif" "b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/\346\250\252\345\261\217\346\230\276\347\244\272.gif" deleted file mode 100644 index b4c58da1a241d9d4ea1534b67bb7cd5050e90bf6..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/\346\250\252\345\261\217\346\230\276\347\244\272.gif" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/\347\253\226\345\261\217\346\230\276\347\244\272.gif" "b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/\347\253\226\345\261\217\346\230\276\347\244\272.gif" deleted file mode 100644 index 67ccf57fd6c267e8c420b43c309c143a2dd56a45..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/\347\253\226\345\261\217\346\230\276\347\244\272.gif" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/\350\256\276\345\244\207\345\256\275\345\272\246\344\270\272LG.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/\350\256\276\345\244\207\345\256\275\345\272\246\344\270\272LG.png" deleted file mode 100644 index 6e003ab973198f6d52e559654e0848fa0aacb79e..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/\350\256\276\345\244\207\345\256\275\345\272\246\344\270\272LG.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/\350\256\276\345\244\207\345\256\275\345\272\246\344\270\272MD.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/\350\256\276\345\244\207\345\256\275\345\272\246\344\270\272MD.png" deleted file mode 100644 index e0c21d7388daa4fe32803436b7fb1630f99c2dbc..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/\350\256\276\345\244\207\345\256\275\345\272\246\344\270\272MD.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/\350\256\276\345\244\207\345\256\275\345\272\246\344\270\272SM.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/\350\256\276\345\244\207\345\256\275\345\272\246\344\270\272SM.png" deleted file mode 100644 index 9ef495d81128387b6b41c813bcfda52f6b7dff87..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/reference/arkui-ts/figures/\350\256\276\345\244\207\345\256\275\345\272\246\344\270\272SM.png" and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001063148757.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001063148757.gif deleted file mode 100755 index 2283e46371317539004c0007886500c1a81dd83a..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001063148757.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001063442797.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001063442797.png deleted file mode 100755 index 56722216f1433b27da4fc49c649c7e8cf4361a45..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001063442797.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001064068638.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001064068638.gif deleted file mode 100755 index a22665c1c2d86025245dbac4b78c5b4bd5c264df..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001064068638.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001070558189.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001070558189.png deleted file mode 100755 index 3e6c90236fa93360b187945fc9556ae735d4578f..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001070558189.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001070693737.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001070693737.png deleted file mode 100755 index fc5e2c46f89ed2972750033ff3cad82c35733752..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001070693737.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001070707559.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001070707559.png deleted file mode 100755 index 3417fe5b0259e024e475c6c1953c23afcc768584..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001070707559.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001071134933.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001071134933.png deleted file mode 100755 index 5000709da6dfadee24e10fdbd679b3a28e46578b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001071134933.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001111680230.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001111680230.png deleted file mode 100644 index 58293d5e874f2aa36ecaf7282ca9e4736318092f..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001111680230.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001111680236.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001111680236.png deleted file mode 100644 index bc28f5056c679e189543c8ad6fba67fb56db7655..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001111680236.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001111680240.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001111680240.png deleted file mode 100644 index 56d32d4cd371c5374b133cb81c9c077aaf7b110d..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001111680240.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001111840132.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001111840132.png deleted file mode 100644 index dfcb0c5e259b3f8d7375c21712249c1e847edd67..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001111840132.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001111840136.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001111840136.png deleted file mode 100644 index 309d1c46f8bc396df5eaed381a5ffa2f0389d602..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001111840136.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001117452952.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001117452952.png deleted file mode 100644 index 128187aacfa540846172eac7d4ff47a3c2a31291..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001117452952.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001127125270.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001127125270.png deleted file mode 100644 index 43c345e521bd9c87a9fb6da469548716cd20f918..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001127125270.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001127284926.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001127284926.png deleted file mode 100644 index 9fa7ed21c03b072e182249f928b9929d0869cd5d..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001127284926.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001147417424.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001147417424.png deleted file mode 100644 index 66d73108f4d5721cfc46ad9062d4b77387e67796..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001147417424.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001148858818.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001148858818.png deleted file mode 100644 index 345a2be66315d210a86c20d30c56b8b5f487c325..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001148858818.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001158240091.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001158240091.png deleted file mode 100644 index e370a44cf043fc34bd8891f57faad2cd2ca05707..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001158240091.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001158240095.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001158240095.png deleted file mode 100644 index 9c43caf5fdfd466eafc37b793f509a6bde2b885d..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001158240095.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001158240097.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001158240097.png deleted file mode 100644 index b54dbc2391d1a8f16312dd02dc3d65a35ea2626f..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001158240097.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001158360079.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001158360079.png deleted file mode 100644 index 0d22570503febc7a7dcba0d1e870f49f32fe489a..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001158360079.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001158360085.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001158360085.png deleted file mode 100644 index 5c5e360f249a2002ba68ad9b94bd7f66f5d6aab1..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001158360085.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001158896538.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001158896538.png deleted file mode 100644 index 89c8accb2a567d32f056cbbb1158c51f3baf013d..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001158896538.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001162911958.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001162911958.gif deleted file mode 100644 index 067268949d47e1cbefdc51b0d736200a4eee443f..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001162911958.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001163212980.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001163212980.gif deleted file mode 100644 index f333c9666cf9ba259ff2e5d0d883c4988659e877..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001163212980.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001163228602.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001163228602.gif deleted file mode 100644 index fc1eab30eb6a87308eaf399a89f1a755223f3995..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001163228602.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001163228638.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001163228638.gif deleted file mode 100644 index b2097084b8dda33575a19b7c97d0555dcd5c04f9..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001163228638.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001163229150.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001163229150.gif deleted file mode 100644 index d3453785e39354ba12ba98483ca3d332da070680..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001163229150.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001163372568.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001163372568.png deleted file mode 100644 index 24908708ecdc45a01ed06334f67171bca9d553ef..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001163372568.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001163375178.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001163375178.gif deleted file mode 100644 index b9cfac61024e39647871b85b72d57bc4dbd1bfa9..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001163375178.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001163388642.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001163388642.gif deleted file mode 100644 index d536b946b814de3d5b822611ac5c91c749a9d254..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001163388642.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001163531210.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001163531210.gif deleted file mode 100644 index 8d5a07d1ff67011de5d0ec6bc0c2e552db9e5cd0..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001163531210.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001163532072.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001163532072.png deleted file mode 100644 index 2ca7c5488fb83a122e7f8ea1fba1e2d59324e513..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001163532072.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001163656706.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001163656706.png deleted file mode 100644 index 5877e6f9966eb4eee0b738ee7356985f9a819714..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001163656706.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001165191390.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001165191390.gif deleted file mode 100644 index 82123adf27f2c782fe882a2c3399646ed3763629..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001165191390.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001165344988.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001165344988.png deleted file mode 100644 index 5b8b2d36da4a14abee57a064898fce0899743751..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001165344988.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001166432552.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001166432552.png deleted file mode 100644 index 72c1ad1e7e1c2100b85be89be4f0648c5ab19d57..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001166432552.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001167746622.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001167746622.png deleted file mode 100644 index f7b8012da47797dfd3909843cba9af1468fb4e89..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001167746622.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001168059158.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001168059158.png deleted file mode 100644 index 1b9259dc9c0a7cb3530e3f7d9b0225e5160b92c8..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001168059158.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001168410342.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001168410342.png deleted file mode 100644 index 3a97ead3b625041b9a3a33c8db8cd7cb79276a2d..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001168410342.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001168570318.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001168570318.png deleted file mode 100644 index 5e855312aef77f5badc0c0b0b4d5cbeac23b802f..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001168570318.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001168728272.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001168728272.png deleted file mode 100644 index 411cc11b2ac16047c5e2c8a24b3d572b9e24f768..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001168728272.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001168728872.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001168728872.png deleted file mode 100644 index d1dc59cd8ac1b5dc7da2f57d16d9a080bb449114..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001168728872.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001168888224.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001168888224.png deleted file mode 100644 index 4487bdcb98a9b1f912be17041859d7a7a246f183..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001168888224.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001168888822.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001168888822.png deleted file mode 100644 index f33eb296f27701a00461cd9231f7d9af014a3814..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001168888822.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001168956332.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001168956332.png deleted file mode 100644 index 15a7e0bdc38655a23f64bfa56c4adad9a6a199a0..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001168956332.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001169532276.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001169532276.png deleted file mode 100644 index eca2b53342a2bf63d089c835bfdae16b2608e70f..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001169532276.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001169582302.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001169582302.gif deleted file mode 100644 index 391353977d32956cde03890e501d11766dae2648..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001169582302.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001169599582.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001169599582.png deleted file mode 100644 index a4eb400dcd217074d6e76902723e9fffd34fd4bd..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001169599582.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001169678922.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001169678922.png deleted file mode 100644 index fad940f7f4fba442aa1b267c66cdc21c5d3a1d2c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001169678922.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001169759552.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001169759552.png deleted file mode 100644 index 2a2376e7e953d35b7d0fb1f6d53314bc0d7cb6b5..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001169759552.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001169918548.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001169918548.gif deleted file mode 100644 index 220d14e0637e2808211cec10173c6c4a7552b64c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001169918548.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001170008198.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001170008198.gif deleted file mode 100644 index d4b3de8f257c571e6fec3ff51795936b2d94d2f0..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001170008198.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001170167520.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001170167520.gif deleted file mode 100644 index d69156cdc0d1f1f33560148c1161618f97acb21d..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001170167520.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001170411978.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001170411978.gif deleted file mode 100644 index 218be7ed11ffd1f1f199c347f0fa90e6f6b64b53..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001170411978.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001173164777.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001173164777.png deleted file mode 100644 index 5e4322d20ad887573ad85958bc181a1be0f85f1c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001173164777.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001174756438.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001174756438.gif deleted file mode 100644 index 5eb149620499c0d1d363d274ad88a741095fc922..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001174756438.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001174756580.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001174756580.gif deleted file mode 100644 index 5a297661641d1714ebc95116592a97a693293e0a..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001174756580.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001174756776.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001174756776.gif deleted file mode 100644 index b1038b5da74612ac1911e1dae9d3a1de24ee46c7..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001174756776.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001174756860.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001174756860.gif deleted file mode 100644 index d1288776a8086fbb9e66691b0e882784db243aba..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001174756860.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001174916742.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001174916742.gif deleted file mode 100644 index c7779b378c80842817091bedf62d74378bfff055..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001174916742.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001175075286.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001175075286.gif deleted file mode 100644 index 90898288928277467db40c5eb11b4ff7ae082e6e..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001175075286.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001175235138.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001175235138.gif deleted file mode 100644 index 5cfb969baf3a36e231a311ca11ca538c248f6da1..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001175235138.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001182200571.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001182200571.png deleted file mode 100644 index c3d760c6d3f6c1e377ff2e42c0b3fb9e547ac140..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001182200571.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001183709904.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001183709904.png deleted file mode 100644 index fb34869ae9a78d655a30e62e1936840d0aa6bb4d..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001183709904.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001188771358.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001188771358.gif deleted file mode 100644 index c76bef26e0b11311f02233ff17ca476ef470798a..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001188771358.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001188771430.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001188771430.gif deleted file mode 100644 index 4a815c6f3db9654b71cc1d11821eab521ca7aeee..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001188771430.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001188931396.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001188931396.gif deleted file mode 100644 index b5e2ed34cf960792ca65ce6d9197ac0fc5d49f8c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001188931396.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001189088264.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001189088264.gif deleted file mode 100644 index 688faa61583561ccb4e54daa04a3ac6a466245ac..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001189088264.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001189089950.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001189089950.gif deleted file mode 100644 index eb0c760faaf917a6935af461e0094fd8e7b8e85b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001189089950.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001189098638.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001189098638.gif deleted file mode 100644 index 6ba578c8480834de8798cd311444c0499e1f0da5..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001189098638.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001189248178.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001189248178.gif deleted file mode 100644 index 74ac9966962b430a0a03e68cf4f39bcfae4cc280..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001189248178.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001189249862.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001189249862.gif deleted file mode 100644 index a1839308d0fdde50aefd4c818d30ea82c49b6ca6..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001189249862.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001195117633.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001195117633.png deleted file mode 100644 index 00964c1cfa5f006f2e8ac064133e23a2d8fc92aa..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001195117633.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001195119619.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001195119619.png deleted file mode 100644 index d5bed5e4ae3a322db0e4f05482913fdbd828cbed..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001195119619.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001204537865.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001204537865.png deleted file mode 100644 index 7eb0d2cc3f3dd8e239e9232e655344c864cbf679..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001204537865.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001204538065.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001204538065.png deleted file mode 100644 index 514bc6e8fcdab7ae01de64d16d92a0541954c458..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001204538065.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001204776353.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001204776353.png deleted file mode 100644 index 883981a250b68a29db2027dee82a9a19c34c8e1a..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001204776353.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001208393581.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001208393581.gif deleted file mode 100644 index a20dc90cfeff09cc98ce1e36e2f032af60f9777e..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001208393581.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001208636379.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001208636379.gif deleted file mode 100644 index e0d0662622fa12506072961b407ed888c2478d90..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001208636379.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001208771093.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001208771093.png deleted file mode 100644 index c07a237f3bff7acbb5adbe7ca0d142aa204f7f13..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001208771093.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001208771113.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001208771113.gif deleted file mode 100644 index bca4a03308a47deb0538aec9b93fe0df9addacb0..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001208771113.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001208787005.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001208787005.gif deleted file mode 100644 index 80a6d574da0827642f85fd34d1acd11caade21cf..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001208787005.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001208908643.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001208908643.gif deleted file mode 100644 index 40f7c00741880a81530581d5488c2ff96e0e7bf2..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001208908643.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001209028575.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001209028575.gif deleted file mode 100644 index 014958726f3f42a6bd92b341695c8ed03b3fd211..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001209028575.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001209033195.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001209033195.png deleted file mode 100644 index 09f170afc5fac1513c0e453a6562a4670b3750f8..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001209033195.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001210951541.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001210951541.gif deleted file mode 100644 index 883453582802ecbb94916aaefd120123c9128625..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001210951541.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001211069339.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001211069339.png deleted file mode 100644 index f835c8abc0dfbfb3b52480d31c12bfd6e77c278b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001211069339.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001211071477.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001211071477.png deleted file mode 100644 index 4f33bfa94e4e8d0a6e70e6f8332126757b320560..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001211071477.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001211225091.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001211225091.png deleted file mode 100644 index f4ac33ba8eea89d257a3ff8f5947b007abdf4215..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001211225091.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001211227617.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001211227617.png deleted file mode 100644 index 4d26b5ba589c8b9126c51b54ff4d67476771cdf2..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001211227617.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001211246571.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001211246571.gif deleted file mode 100644 index 4232ddc088cfaf7015aa3bca6622c39bbd5624a6..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001211246571.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001211383427.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001211383427.png deleted file mode 100644 index 7b8e28967b4af0d0a3e10093b0b2dfab043da52c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001211383427.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001213462329.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001213462329.png deleted file mode 100644 index 99a2f37ce14924c6c2d91f828d7ffaa8c87ec77f..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001213462329.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001213968747.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001213968747.png deleted file mode 100644 index f125f44d4a956c717f3bf1481f7161cf41e79a39..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001213968747.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001214128687.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001214128687.png deleted file mode 100644 index e42b6a7b9c128f9de2217c988fa34cd385742044..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001214128687.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001214210217.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001214210217.png deleted file mode 100644 index 4e6560056b15b9c570758670eb65311168df7e9a..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001214210217.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001214330169.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001214330169.png deleted file mode 100644 index 19ee7009247945887ceb0f8f6f471e45f3116b70..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001214330169.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001214437889.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001214437889.png deleted file mode 100644 index fde616c73000d3f58fd98eea59088177221127a5..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001214437889.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001214595111.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001214595111.png deleted file mode 100644 index 0a44a65c48f7f334e5d77e400495d455dc1283d1..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001214595111.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001214948035.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001214948035.png deleted file mode 100644 index 37ae5324808a0ab50f210907ca65a09e4456a371..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001214948035.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001214998349.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001214998349.png deleted file mode 100644 index 9c9be43d1fedfbd8660965190865110f007d8161..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001214998349.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001215079443.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001215079443.png deleted file mode 100644 index 032c5bae7d3269bd4a3bb813e9d69c9271ac9843..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001215079443.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001215113569.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001215113569.png deleted file mode 100644 index c7b4a7dfc70a6ee3ce7a837d1e8e91acc7d05d22..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001215113569.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001215199399.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001215199399.png deleted file mode 100644 index 3834601d70a5121e18af408bb6a12bbdbf54a28c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001215199399.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001215318403.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001215318403.gif deleted file mode 100644 index 5643eb93241bf15f6cb75ffaf463ada35ba13201..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001215318403.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001215433095.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001215433095.png deleted file mode 100644 index d015869874aecf7235aa892993d3d872a4cfe9df..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001215433095.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001217008255.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001217008255.gif deleted file mode 100644 index 5e38a4068976c9b5e298ff33ad4cfc711de4b2a6..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001217008255.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001217168141.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001217168141.gif deleted file mode 100644 index f470f5261becb6c2d7b30f691a0794db2b1feb93..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001217168141.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001220316305.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001220316305.gif deleted file mode 100644 index 365dbc42e583335f32de863120fd80ae0e7d59e5..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001220316305.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001220316655.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001220316655.gif deleted file mode 100644 index 16a2d3f912b23349a5c416e5c5b74f4fd05a12aa..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001220316655.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001220396251.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001220396251.gif deleted file mode 100644 index b7808565202cf12474f1282e67fde3a9c85d0e9c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001220396251.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001220396499.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001220396499.gif deleted file mode 100644 index ff991f2899c847c433e41ccafd6798a386540369..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001220396499.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001220554911.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001220554911.gif deleted file mode 100644 index 3fe0cd60d60a0c5d29c2625ebade3d8b0bd0cdf8..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001220554911.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001220634677.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001220634677.png deleted file mode 100644 index 664e50e404e5e7f6e4c4823bf1099391bfa45e33..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001220634677.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001220635011.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001220635011.gif deleted file mode 100644 index d669cf40b97891ba3853be28574dceae172fe138..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001220635011.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001220635059.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001220635059.gif deleted file mode 100644 index 27f8177c1c626565ce53f409bbf5a4e2f7cdba01..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001220635059.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001220778205.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001220778205.png deleted file mode 100644 index 62c786d7dacd69bae17ebe4074a2d429cd7f6851..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001220778205.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001220856725.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001220856725.png deleted file mode 100644 index cc39aec87bb14a36eb6214a2ef39d45c631d4a2b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001220856725.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001234009343.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001234009343.gif deleted file mode 100644 index 20b525e82ccdead4414f89e2e226992bc85e13c3..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001234009343.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001234011019.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001234011019.gif deleted file mode 100644 index 24f00c9f1aa6ec431a355f5dd2d88b920607cd05..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001234011019.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001234129289.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001234129289.gif deleted file mode 100644 index 1dff7c90963c2e9a76aa63dbb434b9c55a747fba..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001234129289.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001234130975.png b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001234130975.png deleted file mode 100644 index 21d56ef14b92d136e304c4bae6ab8b1f447557bb..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001234130975.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001234287779.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001234287779.gif deleted file mode 100644 index 2398192bc5df690246dad3edfb82afe618b35dfd..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001234287779.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001234289455.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001234289455.gif deleted file mode 100644 index a6296483cbe2994e36e97d422588f3a9156b56eb..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001234289455.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001234289465.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001234289465.gif deleted file mode 100644 index b374c821e0e426b0e50e33910f33582e8b283ac9..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001234289465.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001234327855.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001234327855.gif deleted file mode 100644 index b0e9d88f7ccf69a208bdf59ab5bd9a3dee2426f6..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001234327855.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001234329527.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001234329527.gif deleted file mode 100644 index 5ea0034e22041bd7fe8c5f73e655ddf367a8d5d5..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001234329527.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001234329539.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001234329539.gif deleted file mode 100644 index f3e6017b6daddc0be529486e0bfaf8b39749e38f..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001234329539.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001234342189.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001234342189.gif deleted file mode 100644 index 61571b390492f0116ceec215b03d261d2ce41139..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/figures/zh-cn_image_0000001234342189.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/public_sys-resources/icon-note.gif b/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/public_sys-resources/icon-note.gif deleted file mode 100644 index 6314297e45c1de184204098efd4814d6dc8b1cda..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/application-dev/ui/public_sys-resources/icon-note.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/contribute/figures/ci-portal.png b/website/docs/.vuepress/public/images/docs/zh-cn/contribute/figures/ci-portal.png deleted file mode 100644 index 91286f6c80765ff974e4998ced9544c99984c002..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/contribute/figures/ci-portal.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/contribute/figures/docs-sig.png b/website/docs/.vuepress/public/images/docs/zh-cn/contribute/figures/docs-sig.png deleted file mode 100644 index f71de06acdf9009792ec148adf52f9d071348b2c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/contribute/figures/docs-sig.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/contribute/figures/sig-task.png b/website/docs/.vuepress/public/images/docs/zh-cn/contribute/figures/sig-task.png deleted file mode 100644 index ed677967d298449ed62d5b66c405c38f86b06b09..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/contribute/figures/sig-task.png and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/contribute/figures/\345\244\215\345\210\266\350\277\234\347\250\213\344\273\223\345\272\223.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/contribute/figures/\345\244\215\345\210\266\350\277\234\347\250\213\344\273\223\345\272\223.png" deleted file mode 100755 index dc499827a432f72adda7c12a70576f5e6e2a212b..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/contribute/figures/\345\244\215\345\210\266\350\277\234\347\250\213\344\273\223\345\272\223.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/contribute/figures/\346\210\252\345\233\276\347\244\272\344\276\213.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/contribute/figures/\346\210\252\345\233\276\347\244\272\344\276\213.png" deleted file mode 100755 index 64ab1ca706103d109a124a1500ae3d8be8cc9d76..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/contribute/figures/\346\210\252\345\233\276\347\244\272\344\276\213.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/contribute/figures/\346\227\240\346\240\207\351\242\2301.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/contribute/figures/\346\227\240\346\240\207\351\242\2301.png" deleted file mode 100755 index 2cd4167075c9c44c051f74607ebadf91d4b1ad5f..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/contribute/figures/\346\227\240\346\240\207\351\242\2301.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/contribute/figures/\346\227\240\346\240\207\351\242\2302.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/contribute/figures/\346\227\240\346\240\207\351\242\2302.png" deleted file mode 100755 index 628f2eb893b83fde34be04b8a3182cce533ea704..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/contribute/figures/\346\227\240\346\240\207\351\242\2302.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/contribute/figures/\346\227\240\346\240\207\351\242\2303.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/contribute/figures/\346\227\240\346\240\207\351\242\2303.png" deleted file mode 100755 index 186247217b85db499d6a7c23d8700c5c2ba6aa2f..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/contribute/figures/\346\227\240\346\240\207\351\242\2303.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/contribute/figures/\346\227\240\346\240\207\351\242\2304.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/contribute/figures/\346\227\240\346\240\207\351\242\2304.png" deleted file mode 100755 index f8603eedddf5862bd9c80bd7f78b2e4163c26b7d..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/contribute/figures/\346\227\240\346\240\207\351\242\2304.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/contribute/figures/\351\205\215\350\211\262\347\244\272\344\276\213.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/contribute/figures/\351\205\215\350\211\262\347\244\272\344\276\213.png" deleted file mode 100755 index 7f3a10718561e54c1221fb2c08464f7cf1a144be..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/contribute/figures/\351\205\215\350\211\262\347\244\272\344\276\213.png" and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/contribute/public_sys-resources/icon-caution.gif b/website/docs/.vuepress/public/images/docs/zh-cn/contribute/public_sys-resources/icon-caution.gif deleted file mode 100755 index 6e90d7cfc2193e39e10bb58c38d01a23f045d571..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/contribute/public_sys-resources/icon-caution.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/contribute/public_sys-resources/icon-note.gif b/website/docs/.vuepress/public/images/docs/zh-cn/contribute/public_sys-resources/icon-note.gif deleted file mode 100755 index 6314297e45c1de184204098efd4814d6dc8b1cda..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/contribute/public_sys-resources/icon-note.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/contribute/public_sys-resources/icon-notice.gif b/website/docs/.vuepress/public/images/docs/zh-cn/contribute/public_sys-resources/icon-notice.gif deleted file mode 100755 index 86024f61b691400bea99e5b1f506d9d9aef36e27..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/contribute/public_sys-resources/icon-notice.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/design/figures/API-Lifecycle.png b/website/docs/.vuepress/public/images/docs/zh-cn/design/figures/API-Lifecycle.png deleted file mode 100755 index 365c6a228bccd70ce912be4958ba3e8c40bfd809..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/design/figures/API-Lifecycle.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/bundles/figure/3516dv300.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/bundles/figure/3516dv300.png deleted file mode 100644 index c4636401a20e37794d8ec28dc173e9308b2b72db..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/bundles/figure/3516dv300.png and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/bundles/figure/SCons\345\256\211\350\243\205\346\210\220\345\212\237\347\225\214\351\235\242-\347\211\210\346\234\254\350\246\201\346\261\2023-0-4\344\273\245\344\270\212-27.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/bundles/figure/SCons\345\256\211\350\243\205\346\210\220\345\212\237\347\225\214\351\235\242-\347\211\210\346\234\254\350\246\201\346\261\2023-0-4\344\273\245\344\270\212-27.png" deleted file mode 100644 index e66ca6ffae9aec5f4f5b97ceccf2e37792e95f18..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/bundles/figure/SCons\345\256\211\350\243\205\346\210\220\345\212\237\347\225\214\351\235\242-\347\211\210\346\234\254\350\246\201\346\261\2023-0-4\344\273\245\344\270\212-27.png" and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/bundles/figure/zh-cn_image_0000001141641532.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/bundles/figure/zh-cn_image_0000001141641532.png deleted file mode 100644 index 3ab29d3ee328f0bf30766b9561db445f35cd4e73..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/bundles/figure/zh-cn_image_0000001141641532.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/bundles/figure/zh-cn_image_0000001188040429.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/bundles/figure/zh-cn_image_0000001188040429.png deleted file mode 100644 index bc682a3dbd7e3de6a83a7292d9c6942c43909c98..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/bundles/figure/zh-cn_image_0000001188040429.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/bundles/figure/zh-cn_image_0000001188041297.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/bundles/figure/zh-cn_image_0000001188041297.png deleted file mode 100644 index 03aced616817cc2a54c7959b4cd3fd61bb720dfe..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/bundles/figure/zh-cn_image_0000001188041297.png and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/bundles/figure/\347\273\204\344\273\266\345\222\214\345\217\221\350\241\214\347\211\210\347\232\204\346\236\204\346\210\220-\350\213\261\346\226\207.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/bundles/figure/\347\273\204\344\273\266\345\222\214\345\217\221\350\241\214\347\211\210\347\232\204\346\236\204\346\210\220-\350\213\261\346\226\207.png" deleted file mode 100644 index 08d9dccdd2371b02f2732d0e4eb4ad9871dccdbe..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/bundles/figure/\347\273\204\344\273\266\345\222\214\345\217\221\350\241\214\347\211\210\347\232\204\346\236\204\346\210\220-\350\213\261\346\226\207.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/2\347\272\277UART\350\256\276\345\244\207\350\277\236\346\216\245\347\244\272\346\204\217\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/2\347\272\277UART\350\256\276\345\244\207\350\277\236\346\216\245\347\244\272\346\204\217\345\233\276.png" deleted file mode 100755 index 6ac63e41108abd4776621356c3034fc52b6f436f..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/2\347\272\277UART\350\256\276\345\244\207\350\277\236\346\216\245\347\244\272\346\204\217\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/4\347\272\277UART\350\256\276\345\244\207\350\277\236\346\216\245\347\244\272\346\204\217\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/4\347\272\277UART\350\256\276\345\244\207\350\277\236\346\216\245\347\244\272\346\204\217\345\233\276.png" deleted file mode 100755 index b5e82f09cd764b0cd9dc835e55f8f878b77eb91e..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/4\347\272\277UART\350\256\276\345\244\207\350\277\236\346\216\245\347\244\272\346\204\217\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/ADC\347\273\237\344\270\200\346\234\215\345\212\241.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/ADC\347\273\237\344\270\200\346\234\215\345\212\241.png" deleted file mode 100755 index 838f9a4416d901eb29b5d203b559b3dcfe29fed9..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/ADC\347\273\237\344\270\200\346\234\215\345\212\241.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/DSI\345\217\221\351\200\201-\346\216\245\346\224\266\346\216\245\345\217\243.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/DSI\345\217\221\351\200\201-\346\216\245\346\224\266\346\216\245\345\217\243.png" deleted file mode 100755 index 40a2c93c66002b00db0014471b46743a5d4620e8..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/DSI\345\217\221\351\200\201-\346\216\245\346\224\266\346\216\245\345\217\243.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/DSI\346\227\240\346\234\215\345\212\241\346\250\241\345\274\217\347\273\223\346\236\204\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/DSI\346\227\240\346\234\215\345\212\241\346\250\241\345\274\217\347\273\223\346\236\204\345\233\276.png" deleted file mode 100755 index 833ff6cc89e49ed4210dd68a502e4b304ac1c273..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/DSI\346\227\240\346\234\215\345\212\241\346\250\241\345\274\217\347\273\223\346\236\204\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/GPIO\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/GPIO\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" deleted file mode 100755 index 8c246a7f6a67005d30808fac11172b2108bc4e2d..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/GPIO\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/GPIO\346\227\240\346\234\215\345\212\241\346\250\241\345\274\217\347\273\223\346\236\204\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/GPIO\346\227\240\346\234\215\345\212\241\346\250\241\345\274\217\347\273\223\346\236\204\345\233\276.png" deleted file mode 100644 index 833ff6cc89e49ed4210dd68a502e4b304ac1c273..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/GPIO\346\227\240\346\234\215\345\212\241\346\250\241\345\274\217\347\273\223\346\236\204\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/HDF\351\251\261\345\212\250\346\250\241\345\236\213.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/HDF\351\251\261\345\212\250\346\250\241\345\236\213.png" deleted file mode 100755 index f2a5855dfeea0eaa8e4db38323b25858ef6a1e09..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/HDF\351\251\261\345\212\250\346\250\241\345\236\213.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/I2C\347\211\251\347\220\206\350\277\236\347\272\277\347\244\272\346\204\217\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/I2C\347\211\251\347\220\206\350\277\236\347\272\277\347\244\272\346\204\217\345\233\276.png" deleted file mode 100755 index e3ee2f81110f790d38a7dcb32730d6d989384848..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/I2C\347\211\251\347\220\206\350\277\236\347\272\277\347\244\272\346\204\217\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/I2C\347\273\237\344\270\200\346\234\215\345\212\241\346\250\241\345\274\217\347\273\223\346\236\204\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/I2C\347\273\237\344\270\200\346\234\215\345\212\241\346\250\241\345\274\217\347\273\223\346\236\204\345\233\276.png" deleted file mode 100644 index 838f9a4416d901eb29b5d203b559b3dcfe29fed9..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/I2C\347\273\237\344\270\200\346\234\215\345\212\241\346\250\241\345\274\217\347\273\223\346\236\204\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/I2C\350\256\276\345\244\207\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/I2C\350\256\276\345\244\207\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" deleted file mode 100755 index beda2c0154e82a787616fdfb5643fade470da175..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/I2C\350\256\276\345\244\207\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/MIPI-DSI\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/MIPI-DSI\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" deleted file mode 100755 index 0d946444c5b2014ca21110e4b73dcb6a6d4b0f18..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/MIPI-DSI\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/MIPI-DSI\346\216\245\345\217\243.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/MIPI-DSI\346\216\245\345\217\243.png" deleted file mode 100755 index 6e39de8017f25a7e4cc6f51fa77ffcc9243ad818..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/MIPI-DSI\346\216\245\345\217\243.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/MMC\347\213\254\347\253\213\346\234\215\345\212\241\346\250\241\345\274\217\347\273\223\346\236\204\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/MMC\347\213\254\347\253\213\346\234\215\345\212\241\346\250\241\345\274\217\347\273\223\346\236\204\345\233\276.png" deleted file mode 100755 index 23324872566e5affac8baa186a30b64b3257f673..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/MMC\347\213\254\347\253\213\346\234\215\345\212\241\346\250\241\345\274\217\347\273\223\346\236\204\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/PWM\347\213\254\347\253\213\346\234\215\345\212\241\346\250\241\345\274\217\347\273\223\346\236\204\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/PWM\347\213\254\347\253\213\346\234\215\345\212\241\346\250\241\345\274\217\347\273\223\346\236\204\345\233\276.png" deleted file mode 100644 index 23324872566e5affac8baa186a30b64b3257f673..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/PWM\347\213\254\347\253\213\346\234\215\345\212\241\346\250\241\345\274\217\347\273\223\346\236\204\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/PWM\350\256\276\345\244\207\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/PWM\350\256\276\345\244\207\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" deleted file mode 100755 index 339d44368a15f4e58d7711c69f136bccdbc9d6db..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/PWM\350\256\276\345\244\207\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/RTC\347\213\254\347\253\213\346\234\215\345\212\241\346\250\241\345\274\217\347\273\223\346\236\204\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/RTC\347\213\254\347\253\213\346\234\215\345\212\241\346\250\241\345\274\217\347\273\223\346\236\204\345\233\276.png" deleted file mode 100644 index 23324872566e5affac8baa186a30b64b3257f673..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/RTC\347\213\254\347\253\213\346\234\215\345\212\241\346\250\241\345\274\217\347\273\223\346\236\204\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/RTC\350\256\276\345\244\207\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/RTC\350\256\276\345\244\207\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" deleted file mode 100755 index 808e3b3197e19ec7b1183fdd974bff7090c0b362..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/RTC\350\256\276\345\244\207\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/SDIO\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/SDIO\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" deleted file mode 100755 index 09085c82c461015a312650c0a9aad57116771e0a..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/SDIO\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/SDIO\347\213\254\347\253\213\346\234\215\345\212\241\346\250\241\345\274\217\347\273\223\346\236\204\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/SDIO\347\213\254\347\253\213\346\234\215\345\212\241\346\250\241\345\274\217\347\273\223\346\236\204\345\233\276.png" deleted file mode 100644 index 23324872566e5affac8baa186a30b64b3257f673..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/SDIO\347\213\254\347\253\213\346\234\215\345\212\241\346\250\241\345\274\217\347\273\223\346\236\204\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/SDIO\347\232\204HOST-DEVICE\350\277\236\346\216\245\347\244\272\346\204\217\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/SDIO\347\232\204HOST-DEVICE\350\277\236\346\216\245\347\244\272\346\204\217\345\233\276.png" deleted file mode 100755 index 5e94b319b49153385f2cf1372a3c43aef6b834e9..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/SDIO\347\232\204HOST-DEVICE\350\277\236\346\216\245\347\244\272\346\204\217\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/SPI\344\270\273\344\273\216\350\256\276\345\244\207\350\277\236\346\216\245\347\244\272\346\204\217\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/SPI\344\270\273\344\273\216\350\256\276\345\244\207\350\277\236\346\216\245\347\244\272\346\204\217\345\233\276.png" deleted file mode 100755 index 96f68d24918dacf9244e0ad020f2e99d77f589c4..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/SPI\344\270\273\344\273\216\350\256\276\345\244\207\350\277\236\346\216\245\347\244\272\346\204\217\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/SPI\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/SPI\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" deleted file mode 100755 index b876193bfd1d4dee4fd13d943593fea050cc8e39..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/SPI\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/SPI\347\213\254\347\253\213\346\234\215\345\212\241\346\250\241\345\274\217\347\273\223\346\236\204\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/SPI\347\213\254\347\253\213\346\234\215\345\212\241\346\250\241\345\274\217\347\273\223\346\236\204\345\233\276.png" deleted file mode 100644 index 23324872566e5affac8baa186a30b64b3257f673..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/SPI\347\213\254\347\253\213\346\234\215\345\212\241\346\250\241\345\274\217\347\273\223\346\236\204\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/Sensor\351\251\261\345\212\250\346\250\241\345\236\213\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/Sensor\351\251\261\345\212\250\346\250\241\345\236\213\345\233\276.png" deleted file mode 100755 index c9661fda039f1cdf88b5df2ad9d78d8ad0d08050..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/Sensor\351\251\261\345\212\250\346\250\241\345\236\213\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/TTL\346\216\245\345\217\243.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/TTL\346\216\245\345\217\243.png" deleted file mode 100755 index 7209d111f142c3da063e0f761387c69b48725a98..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/TTL\346\216\245\345\217\243.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/Touchscreen\345\231\250\344\273\266\345\270\270\347\224\250\347\256\241\350\204\232.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/Touchscreen\345\231\250\344\273\266\345\270\270\347\224\250\347\256\241\350\204\232.png" deleted file mode 100644 index 6d33da5cc9efaa7d7d880623735e32a37f171dd8..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/Touchscreen\345\231\250\344\273\266\345\270\270\347\224\250\347\256\241\350\204\232.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/UART\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/UART\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" deleted file mode 100755 index 33ca15524892ebbad53859fab710a5309e326127..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/UART\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/UART\347\213\254\347\253\213\346\234\215\345\212\241\346\250\241\345\274\217\347\273\223\346\236\204\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/UART\347\213\254\347\253\213\346\234\215\345\212\241\346\250\241\345\274\217\347\273\223\346\236\204\345\233\276.png" deleted file mode 100644 index 23324872566e5affac8baa186a30b64b3257f673..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/UART\347\213\254\347\253\213\346\234\215\345\212\241\346\250\241\345\274\217\347\273\223\346\236\204\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/USB-Device\351\251\261\345\212\250\346\250\241\345\236\213\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/USB-Device\351\251\261\345\212\250\346\250\241\345\236\213\345\233\276.png" deleted file mode 100644 index 3766cf8117505a0d47720dcbccc1030536921bdb..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/USB-Device\351\251\261\345\212\250\346\250\241\345\236\213\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/USB-Host\351\251\261\345\212\250\346\250\241\345\236\213\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/USB-Host\351\251\261\345\212\250\346\250\241\345\236\213\345\233\276.png" deleted file mode 100644 index 6bea2992afd00b031176998278c0bcfce0f8e843..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/USB-Host\351\251\261\345\212\250\346\250\241\345\236\213\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/WLAN\346\241\206\346\236\266.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/WLAN\346\241\206\346\236\266.png" deleted file mode 100755 index 87b45b288d127e85f836d8673fda820f1069186b..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/WLAN\346\241\206\346\236\266.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/WLAN\346\250\241\345\235\227\345\274\200\346\224\276\350\203\275\345\212\233\345\210\206\345\270\203\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/WLAN\346\250\241\345\235\227\345\274\200\346\224\276\350\203\275\345\212\233\345\210\206\345\270\203\345\233\276.png" deleted file mode 100755 index 92b531d067c78063fb785c9ea802f90db1ac2e44..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/WLAN\346\250\241\345\235\227\345\274\200\346\224\276\350\203\275\345\212\233\345\210\206\345\270\203\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/Watchdog\347\213\254\347\253\213\346\234\215\345\212\241\346\250\241\345\274\217\347\273\223\346\236\204\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/Watchdog\347\213\254\347\253\213\346\234\215\345\212\241\346\250\241\345\274\217\347\273\223\346\236\204\345\233\276.png" deleted file mode 100644 index 23324872566e5affac8baa186a30b64b3257f673..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/Watchdog\347\213\254\347\253\213\346\234\215\345\212\241\346\250\241\345\274\217\347\273\223\346\236\204\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/\345\237\272\344\272\216HDF\351\251\261\345\212\250\346\241\206\346\236\266\347\232\204Display\351\251\261\345\212\250\346\250\241\345\236\213.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/\345\237\272\344\272\216HDF\351\251\261\345\212\250\346\241\206\346\236\266\347\232\204Display\351\251\261\345\212\250\346\250\241\345\236\213.png" deleted file mode 100755 index 1fa1231040f82789982f8a9b930304022bc9b2b5..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/\345\237\272\344\272\216HDF\351\251\261\345\212\250\346\241\206\346\236\266\347\232\204Display\351\251\261\345\212\250\346\250\241\345\236\213.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/\345\237\272\344\272\216HDF\351\251\261\345\212\250\346\241\206\346\236\266\347\232\204input\351\251\261\345\212\250\346\250\241\345\236\213.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/\345\237\272\344\272\216HDF\351\251\261\345\212\250\346\241\206\346\236\266\347\232\204input\351\251\261\345\212\250\346\250\241\345\236\213.png" deleted file mode 100755 index db8069cb7a0bc1dcd7906131ce87ad54cc8ea340..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/\345\237\272\344\272\216HDF\351\251\261\345\212\250\346\241\206\346\236\266\347\232\204input\351\251\261\345\212\250\346\250\241\345\236\213.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/\347\234\213\351\227\250\347\213\227\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/\347\234\213\351\227\250\347\213\227\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" deleted file mode 100755 index 1b5ffbcd060a3315eb9ac48a5f7b1a95c801c24b..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/\347\234\213\351\227\250\347\213\227\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/\351\205\215\347\275\256\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/\351\205\215\347\275\256\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" deleted file mode 100755 index 3803784ebc2200f61b79420e52b010cad1a55eab..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/driver/figures/\351\205\215\347\275\256\344\275\277\347\224\250\346\265\201\347\250\213\345\233\276.png" and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/11.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/11.png deleted file mode 100644 index ff9105c313d5755f140920bbfc2399e3ccb5e2f5..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/11.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/Failed-to-open-the-serial-port.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/Failed-to-open-the-serial-port.png deleted file mode 100644 index 0eee1bbff2e54816d6be05f7f3972a83f615884d..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/Failed-to-open-the-serial-port.png and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/U-boot\347\203\247\345\206\231\345\256\214\346\210\220\344\270\262\345\217\243\346\230\276\347\244\272\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/U-boot\347\203\247\345\206\231\345\256\214\346\210\220\344\270\262\345\217\243\346\230\276\347\244\272\345\233\276.png" deleted file mode 100755 index ad4fd618860ca9f79e9bdc39436c3b2f9cdb72de..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/U-boot\347\203\247\345\206\231\345\256\214\346\210\220\344\270\262\345\217\243\346\230\276\347\244\272\345\233\276.png" and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/download-six.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/download-six.png deleted file mode 100644 index 39ae26ac8f3254d023d6b90a9f9bb8a8ff0c940b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/download-six.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/download-zlib.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/download-zlib.png deleted file mode 100755 index 3b7f6f4766c54f6ca1e0057fc8f869785cc63e56..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/download-zlib.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/hi3516-allowing-the-visual-studio-code-application-to-access-the-network.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/hi3516-allowing-the-visual-studio-code-application-to-access-the-network.png deleted file mode 100644 index afc9028fbb61db82e6f1384032bb32f56ed2ec35..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/hi3516-allowing-the-visual-studio-code-application-to-access-the-network.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/hi3516-firewall-and-network-protection.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/hi3516-firewall-and-network-protection.png deleted file mode 100644 index 775ce6fe99d4894b39f2bdd613097dcaf11a37b2..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/hi3516-firewall-and-network-protection.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/hi3516-network-and-firewall-setting.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/hi3516-network-and-firewall-setting.png deleted file mode 100644 index 88cba0537b5431aa266364abbe19162130f4e3ca..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/hi3516-network-and-firewall-setting.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/hi3516-selecting-the-visual-studio-code-application.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/hi3516-selecting-the-visual-studio-code-application.png deleted file mode 100644 index c735ae362e184083329cdf710289a169ad5625d4..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/hi3516-selecting-the-visual-studio-code-application.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/reason-no-python-soft-link.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/reason-no-python-soft-link.png deleted file mode 100644 index b6bc36af5339ea5a4f67640e69836965b3776e17..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/reason-no-python-soft-link.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/solution-add-soft-link.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/solution-add-soft-link.png deleted file mode 100644 index 9284df45bb1415d84f0325df85b4eb5c223281e8..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/solution-add-soft-link.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/terminal-list.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/terminal-list.png deleted file mode 100644 index a680547b305cccb4d8ea6cae3cbf2d046b841ff8..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/terminal-list.png and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/\347\275\221\347\273\234\344\270\215\351\200\232-Hi3516\345\215\225\346\235\277\346\227\240\346\263\225\350\216\267\345\217\226\346\226\207\344\273\266.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/\347\275\221\347\273\234\344\270\215\351\200\232-Hi3516\345\215\225\346\235\277\346\227\240\346\263\225\350\216\267\345\217\226\346\226\207\344\273\266.png" deleted file mode 100644 index 548e03da4b76123cb67d41cbd1de4a0f33f5ef4b..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/\347\275\221\347\273\234\344\270\215\351\200\232-Hi3516\345\215\225\346\235\277\346\227\240\346\263\225\350\216\267\345\217\226\346\226\207\344\273\266.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/\350\277\220\350\241\214\346\212\245\351\224\231\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/\350\277\220\350\241\214\346\212\245\351\224\231\345\233\276.png" deleted file mode 100644 index 015c38ba5516395527bcf6715535238f02b2bad9..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/faqs/figures/\350\277\220\350\241\214\346\212\245\351\224\231\345\233\276.png" and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/get-code/figure/evolution-roadmap.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/get-code/figure/evolution-roadmap.png deleted file mode 100644 index cc507c1d7d05f67d0ea07c5c1e9a76e776f1e1f8..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/get-code/figure/evolution-roadmap.png and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/get-code/figure/\345\214\205\347\256\241\347\220\206.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/get-code/figure/\345\214\205\347\256\241\347\220\206.png" deleted file mode 100644 index d98c83b3ead8e863b4db1da755b4e743afd62f46..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/get-code/figure/\345\214\205\347\256\241\347\220\206.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/get-code/figure/\345\217\221\350\241\214\347\211\210\347\244\272\344\276\213.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/get-code/figure/\345\217\221\350\241\214\347\211\210\347\244\272\344\276\213.png" deleted file mode 100644 index a4fa09ee58922bc9b182ac688ed4553b211c452c..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/get-code/figure/\345\217\221\350\241\214\347\211\210\347\244\272\344\276\213.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/get-code/figure/\347\273\204\344\273\266\345\256\232\345\210\266.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/get-code/figure/\347\273\204\344\273\266\345\256\232\345\210\266.png" deleted file mode 100644 index 889adfe235359b5ab438ff87afb37ef4d1cf2ad9..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/get-code/figure/\347\273\204\344\273\266\345\256\232\345\210\266.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/get-code/figure/\350\256\276\347\275\256\347\274\226\350\257\221\347\225\214\351\235\242.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/get-code/figure/\350\256\276\347\275\256\347\274\226\350\257\221\347\225\214\351\235\242.png" deleted file mode 100644 index bd2829efdc6d710559efe4650ddcba6b954b525e..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/get-code/figure/\350\256\276\347\275\256\347\274\226\350\257\221\347\225\214\351\235\242.png" and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/6-pin-distribution-and-physical-connection.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/6-pin-distribution-and-physical-connection.png deleted file mode 100644 index 4b3f60fdd3b8770f9bcd847f58ecf9acf434f4f6..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/6-pin-distribution-and-physical-connection.png and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/I2C\346\227\266\345\272\217\346\265\201\347\250\213\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/I2C\346\227\266\345\272\217\346\265\201\347\250\213\345\233\276.png" deleted file mode 100644 index d633538c38e6e0c34ce21f704a023cf1bd7080e2..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/I2C\346\227\266\345\272\217\346\265\201\347\250\213\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/LED\351\227\252\347\203\201\345\233\276.gif" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/LED\351\227\252\347\203\201\345\233\276.gif" deleted file mode 100755 index 2f88e12dbefb2e2d43114a7c65823f8a7f014e28..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/LED\351\227\252\347\203\201\345\233\276.gif" and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/device-wlan-sdk-files.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/device-wlan-sdk-files.png deleted file mode 100755 index 02075cda950596315c8c79ac3ab96587edf29394..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/device-wlan-sdk-files.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/empty-feature-ability.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/empty-feature-ability.png deleted file mode 100755 index 86ddcfe8b78da2a68e70ac16f12e153a1277bcf3..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/empty-feature-ability.png and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\345\220\257\345\212\250\347\244\272\344\276\213.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\345\220\257\345\212\250\347\244\272\344\276\213.png" deleted file mode 100755 index 881c86b3f1862cd09f013a154d3882060ba8bcba..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\345\220\257\345\212\250\347\244\272\344\276\213.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\345\256\214\346\225\264\345\267\245\347\250\213\347\233\256\345\275\225.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\345\256\214\346\225\264\345\267\245\347\250\213\347\233\256\345\275\225.png" deleted file mode 100755 index 8e351841abe47da44b1b0b66eccc7e496141a90a..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\345\256\214\346\225\264\345\267\245\347\250\213\347\233\256\345\275\225.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\345\267\245\347\250\213\347\233\256\345\275\225.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\345\267\245\347\250\213\347\233\256\345\275\225.png" deleted file mode 100755 index 31fc4ae71504eab0a405ac39041db41feabcf95f..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\345\267\245\347\250\213\347\233\256\345\275\225.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\346\227\266\351\222\237\345\272\224\347\224\250\346\230\276\347\244\272\346\225\210\346\236\234\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\346\227\266\351\222\237\345\272\224\347\224\250\346\230\276\347\244\272\346\225\210\346\236\234\345\233\276.png" deleted file mode 100644 index 7ea61df009fbe2521c5e50317c34966908fd92fe..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\346\227\266\351\222\237\345\272\224\347\224\250\346\230\276\347\244\272\346\225\210\346\236\234\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\346\237\245\347\234\213\346\226\207\344\273\266\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\346\237\245\347\234\213\346\226\207\344\273\266\345\233\276.png" deleted file mode 100755 index 9d0d42f82c0e2a877c01397f038561bea07430e7..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\346\237\245\347\234\213\346\226\207\344\273\266\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\346\240\207\351\242\230\346\240\217\345\222\214\344\277\241\346\201\257\346\240\217\346\225\210\346\236\234.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\346\240\207\351\242\230\346\240\217\345\222\214\344\277\241\346\201\257\346\240\217\346\225\210\346\236\234.png" deleted file mode 100755 index a99a58a61e740148f182fb530c20227410314383..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\346\240\207\351\242\230\346\240\217\345\222\214\344\277\241\346\201\257\346\240\217\346\225\210\346\236\234.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\346\240\207\351\242\230\346\240\217\346\225\210\346\236\234.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\346\240\207\351\242\230\346\240\217\346\225\210\346\236\234.png" deleted file mode 100755 index 5dc92bd57ba2e04bac5e9e23073e861295a64e89..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\346\240\207\351\242\230\346\240\217\346\225\210\346\236\234.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\346\241\214\351\235\242.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\346\241\214\351\235\242.png" deleted file mode 100755 index 3bb036b573a5360657a2c5aa1882b497af2d9a39..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\346\241\214\351\235\242.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\346\267\273\345\212\240\351\241\265\351\235\242.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\346\267\273\345\212\240\351\241\265\351\235\242.png" deleted file mode 100755 index 95c6d05e755bd9b2801b1c50c7582f947ecd2e4d..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\346\267\273\345\212\240\351\241\265\351\235\242.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\347\251\272\346\260\224\350\264\250\351\207\217\347\233\221\346\265\213-App\346\230\276\347\244\272\346\225\210\346\236\234\345\233\276.gif" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\347\251\272\346\260\224\350\264\250\351\207\217\347\233\221\346\265\213-App\346\230\276\347\244\272\346\225\210\346\236\234\345\233\276.gif" deleted file mode 100755 index 8a82c5820ab70ec7b46e79fa4c537c78ca831e81..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\347\251\272\346\260\224\350\264\250\351\207\217\347\233\221\346\265\213-App\346\230\276\347\244\272\346\225\210\346\236\234\345\233\276.gif" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\350\276\223\345\205\245\345\275\225\345\203\217\346\214\207\344\273\244\345\220\216\344\270\262\345\217\243\346\211\223\345\215\260\346\227\245\345\277\227.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\350\276\223\345\205\245\345\275\225\345\203\217\346\214\207\344\273\244\345\220\216\344\270\262\345\217\243\346\211\223\345\215\260\346\227\245\345\277\227.png" deleted file mode 100755 index 5d9aea614e521f2a2c5e634917f16cebf24ae80d..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\350\276\223\345\205\245\345\275\225\345\203\217\346\214\207\344\273\244\345\220\216\344\270\262\345\217\243\346\211\223\345\215\260\346\227\245\345\277\227.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\350\276\223\345\205\245\346\213\215\347\205\247\346\214\207\344\273\244\345\220\216\344\270\262\345\217\243\346\211\223\345\215\260\346\227\245\345\277\227.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\350\276\223\345\205\245\346\213\215\347\205\247\346\214\207\344\273\244\345\220\216\344\270\262\345\217\243\346\211\223\345\215\260\346\227\245\345\277\227.png" deleted file mode 100755 index 1dd037de6e414565b5c1707fd0aa8bf8ff611f38..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\350\276\223\345\205\245\346\213\215\347\205\247\346\214\207\344\273\244\345\220\216\344\270\262\345\217\243\346\211\223\345\215\260\346\227\245\345\277\227.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\350\276\223\345\205\245\351\241\265\351\235\242\345\220\215\347\247\260.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\350\276\223\345\205\245\351\241\265\351\235\242\345\220\215\347\247\260.png" deleted file mode 100755 index 026f0c61d55680baf7873b421ef9c76685f2f222..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\350\276\223\345\205\245\351\241\265\351\235\242\345\220\215\347\247\260.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\350\276\223\345\205\245\351\242\204\350\247\210\346\214\207\344\273\244\345\220\216\344\270\262\345\217\243\346\211\223\345\215\260\346\227\245\345\277\227.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\350\276\223\345\205\245\351\242\204\350\247\210\346\214\207\344\273\244\345\220\216\344\270\262\345\217\243\346\211\223\345\215\260\346\227\245\345\277\227.png" deleted file mode 100755 index c4ec2b5dfbeb02b3d6c5469dbe848debfe30d188..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\350\276\223\345\205\245\351\242\204\350\247\210\346\214\207\344\273\244\345\220\216\344\270\262\345\217\243\346\211\223\345\215\260\346\227\245\345\277\227.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\350\276\223\345\207\272\351\200\200\345\207\272\346\214\207\344\273\244\345\220\216\344\270\262\345\217\243\346\211\223\345\215\260\346\227\245\345\277\227.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\350\276\223\345\207\272\351\200\200\345\207\272\346\214\207\344\273\244\345\220\216\344\270\262\345\217\243\346\211\223\345\215\260\346\227\245\345\277\227.png" deleted file mode 100755 index 8a4415351ff8f04e33bcd2d5dbb2b78a213bcbf2..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\350\276\223\345\207\272\351\200\200\345\207\272\346\214\207\344\273\244\345\220\216\344\270\262\345\217\243\346\211\223\345\215\260\346\227\245\345\277\227.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\351\241\265\351\235\242\344\275\215\347\275\256\346\214\207\347\244\272\345\231\250\346\225\210\346\236\234\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\351\241\265\351\235\242\344\275\215\347\275\256\346\214\207\347\244\272\345\231\250\346\225\210\346\236\234\345\233\276.png" deleted file mode 100755 index e987d37213d56b4badf2cb8043d9ca976044c887..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\351\241\265\351\235\242\344\275\215\347\275\256\346\214\207\347\244\272\345\231\250\346\225\210\346\236\234\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\351\242\204\350\247\210\346\225\210\346\236\234.jpg" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\351\242\204\350\247\210\346\225\210\346\236\234.jpg" deleted file mode 100755 index cce3217d3793a18521540e1a8e6ba349949ad765..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/guide/figures/\351\242\204\350\247\210\346\225\210\346\236\234.jpg" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/CPU\350\256\277\351\227\256\345\206\205\345\255\230\346\210\226\345\244\226\350\256\276\347\232\204\347\244\272\346\204\217\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/CPU\350\256\277\351\227\256\345\206\205\345\255\230\346\210\226\345\244\226\350\256\276\347\232\204\347\244\272\346\204\217\345\233\276.png" deleted file mode 100644 index 14764140174d4aed373e155871e4ee5a4c9d869d..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/CPU\350\256\277\351\227\256\345\206\205\345\255\230\346\210\226\345\244\226\350\256\276\347\232\204\347\244\272\346\204\217\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/CPU\350\256\277\351\227\256\345\206\205\345\255\230\347\244\272\346\204\217\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/CPU\350\256\277\351\227\256\345\206\205\345\255\230\347\244\272\346\204\217\345\233\276.png" deleted file mode 100644 index 0469f0ca66c61ef1423de3b9dfe6bc8210f51c8d..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/CPU\350\256\277\351\227\256\345\206\205\345\255\230\347\244\272\346\204\217\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/Futex\350\256\276\350\256\241\345\233\276.jpg" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/Futex\350\256\276\350\256\241\345\233\276.jpg" deleted file mode 100644 index b720a53cda289dfea91a4baba36645640bf0aea0..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/Futex\350\256\276\350\256\241\345\233\276.jpg" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/POSIX\346\216\245\345\217\243\346\241\206\346\236\266.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/POSIX\346\216\245\345\217\243\346\241\206\346\236\266.png" deleted file mode 100755 index d624728a9d235dfcfc597014012f8e226bfcd4f5..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/POSIX\346\216\245\345\217\243\346\241\206\346\236\266.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/VDSO\347\263\273\347\273\237\350\256\276\350\256\241.jpg" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/VDSO\347\263\273\347\273\237\350\256\276\350\256\241.jpg" deleted file mode 100644 index 633798d5a587904f92bd28f4fe8a98b08c19162d..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/VDSO\347\263\273\347\273\237\350\256\276\350\256\241.jpg" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/Vnode\345\210\233\345\273\272\346\265\201\347\250\213.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/Vnode\345\210\233\345\273\272\346\265\201\347\250\213.png" deleted file mode 100644 index 8d6b584acacbce69f2dab55a49e22598c22fd368..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/Vnode\345\210\233\345\273\272\346\265\201\347\250\213.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/free\346\265\201\347\250\213\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/free\346\265\201\347\250\213\345\233\276.png" deleted file mode 100644 index a8e6e991fc5a81574ad92c44d45bff71c450bbc3..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/free\346\265\201\347\250\213\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/malloc\351\200\232\350\277\207mmap\346\234\272\345\210\266\347\224\263\350\257\267\345\206\205\345\255\230\347\232\204\345\206\205\345\255\230\345\270\203\345\261\200.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/malloc\351\200\232\350\277\207mmap\346\234\272\345\210\266\347\224\263\350\257\267\345\206\205\345\255\230\347\232\204\345\206\205\345\255\230\345\270\203\345\261\200.png" deleted file mode 100644 index ff50b0e8ef50063df83834091a8d0c0992372599..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/malloc\351\200\232\350\277\207mmap\346\234\272\345\210\266\347\224\263\350\257\267\345\206\205\345\255\230\347\232\204\345\206\205\345\255\230\345\270\203\345\261\200.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/node\350\212\202\347\202\271\345\244\264\344\277\241\346\201\257\346\267\273\345\212\240\346\240\241\351\252\214\345\200\274.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/node\350\212\202\347\202\271\345\244\264\344\277\241\346\201\257\346\267\273\345\212\240\346\240\241\351\252\214\345\200\274.png" deleted file mode 100644 index 9a49391cd3d662305134251f4ee4261c10852106..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/node\350\212\202\347\202\271\345\244\264\344\277\241\346\201\257\346\267\273\345\212\240\346\240\241\351\252\214\345\200\274.png" and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/zh-cn_image_0000001127390512.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/zh-cn_image_0000001127390512.png deleted file mode 100644 index c2d38a9a5f1789f6ce5d2ad32eb19f2b1c847872..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/zh-cn_image_0000001127390512.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/zh-cn_image_0000001127519136.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/zh-cn_image_0000001127519136.png deleted file mode 100644 index ad13c7729857efdad9d53e20a07a1f28e85c2361..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/zh-cn_image_0000001127519136.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/zh-cn_image_0000001127520662.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/zh-cn_image_0000001127520662.png deleted file mode 100644 index 94ca9a41688c06a31b44edca5d9d3add3bfdba6f..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/zh-cn_image_0000001127520662.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/zh-cn_image_0000001132778524.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/zh-cn_image_0000001132778524.png deleted file mode 100644 index 7836a009e5e3cb6351c807daf9b927c7d3b71a86..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/zh-cn_image_0000001132778524.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/zh-cn_image_0000001132935054.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/zh-cn_image_0000001132935054.png deleted file mode 100644 index 238a15fa82b6095a13ee54bd3014ed3c08c21b4e..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/zh-cn_image_0000001132935054.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/zh-cn_image_0000001173429547.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/zh-cn_image_0000001173429547.png deleted file mode 100644 index 1d8df5ef5d0f321e976008cbf382e228d12677d6..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/zh-cn_image_0000001173429547.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/zh-cn_image_0000001173449871.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/zh-cn_image_0000001173449871.png deleted file mode 100644 index 7f5c5f4193cb03892f45906263f600478b65136c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/zh-cn_image_0000001173449871.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/zh-cn_image_0000001176974089.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/zh-cn_image_0000001176974089.png deleted file mode 100644 index 3f9a02ed3386934d341befcfbeb1a561a67955ba..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/zh-cn_image_0000001176974089.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/zh-cn_image_0000001178856385.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/zh-cn_image_0000001178856385.png deleted file mode 100644 index 25da22c730220aec03a08ca5ca5cfda5993b4a7e..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/zh-cn_image_0000001178856385.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/zh-cn_image_0000001191018697.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/zh-cn_image_0000001191018697.png deleted file mode 100644 index d5693bd916ea4f009687af8233054baedf06ddf3..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/zh-cn_image_0000001191018697.png and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\344\272\213\344\273\266\350\277\220\344\275\234\345\216\237\347\220\206\345\233\276-21.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\344\272\213\344\273\266\350\277\220\344\275\234\345\216\237\347\220\206\345\233\276-21.png" deleted file mode 100644 index 3da92ebe0448375d76e32950f301f72bc7282547..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\344\272\213\344\273\266\350\277\220\344\275\234\345\216\237\347\220\206\345\233\276-21.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\344\272\213\344\273\266\350\277\220\344\275\234\345\216\237\347\220\206\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\344\272\213\344\273\266\350\277\220\344\275\234\345\216\237\347\220\206\345\233\276.png" deleted file mode 100644 index 3da92ebe0448375d76e32950f301f72bc7282547..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\344\272\213\344\273\266\350\277\220\344\275\234\345\216\237\347\220\206\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\344\272\222\346\226\245\351\224\201\350\277\220\344\275\234\347\244\272\346\204\217\345\233\276-23.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\344\272\222\346\226\245\351\224\201\350\277\220\344\275\234\347\244\272\346\204\217\345\233\276-23.png" deleted file mode 100644 index b04bf9db5baa85756ba1a12039a160301a4ec1fd..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\344\272\222\346\226\245\351\224\201\350\277\220\344\275\234\347\244\272\346\204\217\345\233\276-23.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\344\272\222\346\226\245\351\224\201\350\277\220\344\275\234\347\244\272\346\204\217\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\344\272\222\346\226\245\351\224\201\350\277\220\344\275\234\347\244\272\346\204\217\345\233\276.png" deleted file mode 100644 index 37559a2a230b4d0a17fa07aaac2ea5ed3923b4df..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\344\272\222\346\226\245\351\224\201\350\277\220\344\275\234\347\244\272\346\204\217\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\344\273\273\345\212\241\347\212\266\346\200\201\347\244\272\346\204\217\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\344\273\273\345\212\241\347\212\266\346\200\201\347\244\272\346\204\217\345\233\276.png" deleted file mode 100644 index 75c79e501c27a2c41ff011133197eb646981b0f3..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\344\273\273\345\212\241\347\212\266\346\200\201\347\244\272\346\204\217\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\344\273\273\345\212\241\347\212\266\346\200\201\350\277\201\347\247\273\347\244\272\346\204\217\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\344\273\273\345\212\241\347\212\266\346\200\201\350\277\201\347\247\273\347\244\272\346\204\217\345\233\276.png" deleted file mode 100644 index c8920829c4f329643974a00a47775aac7de4ce25..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\344\273\273\345\212\241\347\212\266\346\200\201\350\277\201\347\247\273\347\244\272\346\204\217\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\344\277\241\345\217\267\351\207\217\350\277\220\344\275\234\347\244\272\346\204\217\345\233\276-22.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\344\277\241\345\217\267\351\207\217\350\277\220\344\275\234\347\244\272\346\204\217\345\233\276-22.png" deleted file mode 100644 index 265c77529e451d8d0c75ef5c653f318687c588cb..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\344\277\241\345\217\267\351\207\217\350\277\220\344\275\234\347\244\272\346\204\217\345\233\276-22.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\344\277\241\345\217\267\351\207\217\350\277\220\344\275\234\347\244\272\346\204\217\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\344\277\241\345\217\267\351\207\217\350\277\220\344\275\234\347\244\272\346\204\217\345\233\276.png" deleted file mode 100644 index 02437a72c3de38cbddf5233282ef9354220002bf..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\344\277\241\345\217\267\351\207\217\350\277\220\344\275\234\347\244\272\346\204\217\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\345\206\205\345\255\230\346\230\240\345\260\204\347\244\272\346\204\217\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\345\206\205\345\255\230\346\230\240\345\260\204\347\244\272\346\204\217\345\233\276.png" deleted file mode 100644 index cbd0d5b871519d388a07f2d20b655c2f42e2e384..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\345\206\205\345\255\230\346\230\240\345\260\204\347\244\272\346\204\217\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\345\206\205\345\255\230\347\224\263\350\257\267\347\244\272\346\204\217\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\345\206\205\345\255\230\347\224\263\350\257\267\347\244\272\346\204\217\345\233\276.png" deleted file mode 100644 index 9d502df58aeb0e4f01c83628c82a6a9d974765ab..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\345\206\205\345\255\230\347\224\263\350\257\267\347\244\272\346\204\217\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\345\206\205\345\255\230\351\207\212\346\224\276\347\244\272\346\204\217\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\345\206\205\345\255\230\351\207\212\346\224\276\347\244\272\346\204\217\345\233\276.png" deleted file mode 100644 index c4f9ba8dba9112333f43dfe8db6d3f046bb29631..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\345\206\205\345\255\230\351\207\212\346\224\276\347\244\272\346\204\217\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\345\206\205\346\240\270\345\220\257\345\212\250\346\265\201\347\250\213.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\345\206\205\346\240\270\345\220\257\345\212\250\346\265\201\347\250\213.png" deleted file mode 100644 index ab769d0228a005f3332d86e1443712e157c7f32d..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\345\206\205\346\240\270\345\220\257\345\212\250\346\265\201\347\250\213.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\345\206\205\346\240\270\346\236\266\346\236\204\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\345\206\205\346\240\270\346\236\266\346\236\204\345\233\276.png" deleted file mode 100644 index aab178cde608403d259af3cd10c11188e213de08..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\345\206\205\346\240\270\346\236\266\346\236\204\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\345\212\250\346\200\201\345\206\205\345\255\230\346\240\270\345\277\203\347\256\227\346\263\225-19.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\345\212\250\346\200\201\345\206\205\345\255\230\346\240\270\345\277\203\347\256\227\346\263\225-19.png" deleted file mode 100644 index 8fa49b71f46505f335a5e782cbef362f7336fdaa..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\345\212\250\346\200\201\345\206\205\345\255\230\346\240\270\345\277\203\347\256\227\346\263\225-19.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\345\212\250\346\200\201\345\206\205\345\255\230\347\256\241\347\220\206\347\273\223\346\236\204\345\233\276-20.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\345\212\250\346\200\201\345\206\205\345\255\230\347\256\241\347\220\206\347\273\223\346\236\204\345\233\276-20.png" deleted file mode 100644 index 9d98f09b73bd77ef25c732a750611bb3fb3c6b65..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\345\212\250\346\200\201\345\206\205\345\255\230\347\256\241\347\220\206\347\273\223\346\236\204\345\233\276-20.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\345\212\250\346\200\201\345\206\205\345\255\230\347\256\241\347\220\206\347\273\223\346\236\204\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\345\212\250\346\200\201\345\206\205\345\255\230\347\256\241\347\220\206\347\273\223\346\236\204\345\233\276.png" deleted file mode 100644 index e67cd13c295d19b6ce45c4749644eea42ada7f05..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\345\212\250\346\200\201\345\206\205\345\255\230\347\256\241\347\220\206\347\273\223\346\236\204\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\345\212\250\346\200\201\345\212\240\350\275\275\346\265\201\347\250\213.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\345\212\250\346\200\201\345\212\240\350\275\275\346\265\201\347\250\213.png" deleted file mode 100644 index 66f78d73d491b36b8ca9333919adefa4252b4983..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\345\212\250\346\200\201\345\212\240\350\275\275\346\265\201\347\250\213.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\345\240\206\345\206\205\345\255\230\350\212\202\347\202\271\344\277\241\346\201\257.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\345\240\206\345\206\205\345\255\230\350\212\202\347\202\271\344\277\241\346\201\257.png" deleted file mode 100644 index 131519e92cadb00d4ae33f180fba7e410120f98f..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\345\240\206\345\206\205\345\255\230\350\212\202\347\202\271\344\277\241\346\201\257.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\345\240\206\345\206\205\345\255\230\350\212\202\347\202\271\344\277\241\346\201\257\351\223\276\350\241\250.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\345\240\206\345\206\205\345\255\230\350\212\202\347\202\271\344\277\241\346\201\257\351\223\276\350\241\250.png" deleted file mode 100644 index 17c3d03c4b35ad7b8d31e9ec091d683d498a0d90..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\345\240\206\345\206\205\345\255\230\350\212\202\347\202\271\344\277\241\346\201\257\351\223\276\350\241\250.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\345\240\206\346\240\210\345\210\206\346\236\220\345\216\237\347\220\206\347\244\272\346\204\217\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\345\240\206\346\240\210\345\210\206\346\236\220\345\216\237\347\220\206\347\244\272\346\204\217\345\233\276.png" deleted file mode 100644 index 6ac9200e867f2c87d14ef89ca8c15102e83d4c10..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\345\240\206\346\240\210\345\210\206\346\236\220\345\216\237\347\220\206\347\244\272\346\204\217\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\346\226\207\344\273\266\346\237\245\346\211\276\346\265\201\347\250\213.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\346\226\207\344\273\266\346\237\245\346\211\276\346\265\201\347\250\213.png" deleted file mode 100644 index b06ce7a382707361fadf8f6864e02b973e3af39e..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\346\226\207\344\273\266\346\237\245\346\211\276\346\265\201\347\250\213.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\346\263\204\346\274\217\347\202\271\344\273\243\347\240\201\350\241\214\345\256\232\344\275\215\346\265\201\347\250\213.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\346\263\204\346\274\217\347\202\271\344\273\243\347\240\201\350\241\214\345\256\232\344\275\215\346\265\201\347\250\213.png" deleted file mode 100644 index 0b882d1347c0aa55aa855808847bfb2fad8d8693..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\346\263\204\346\274\217\347\202\271\344\273\243\347\240\201\350\241\214\345\256\232\344\275\215\346\265\201\347\250\213.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\347\211\251\347\220\206\345\206\205\345\255\230\344\275\277\347\224\250\345\210\206\345\270\203\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\347\211\251\347\220\206\345\206\205\345\255\230\344\275\277\347\224\250\345\210\206\345\270\203\345\233\276.png" deleted file mode 100644 index 317de70b8fc9a0186e0e1db74baa22b637281e47..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\347\211\251\347\220\206\345\206\205\345\255\230\344\275\277\347\224\250\345\210\206\345\270\203\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\347\250\213\345\272\217\346\211\247\350\241\214\346\265\201\347\250\213.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\347\250\213\345\272\217\346\211\247\350\241\214\346\265\201\347\250\213.png" deleted file mode 100644 index ef0759cead5eb6fcd30cefcd6a7145d43578eb1a..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\347\250\213\345\272\217\346\211\247\350\241\214\346\265\201\347\250\213.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\347\263\273\347\273\237\350\260\203\347\224\250\347\244\272\346\204\217\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\347\263\273\347\273\237\350\260\203\347\224\250\347\244\272\346\204\217\345\233\276.png" deleted file mode 100644 index 3e992223c5cfac9e45331a898cf2e86b755e5bd6..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\347\263\273\347\273\237\350\260\203\347\224\250\347\244\272\346\204\217\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\350\275\273\351\207\217\347\263\273\347\273\237\345\212\250\346\200\201\345\206\205\345\255\230\346\240\270\345\277\203\347\256\227\346\263\225.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\350\275\273\351\207\217\347\263\273\347\273\237\345\212\250\346\200\201\345\206\205\345\255\230\346\240\270\345\277\203\347\256\227\346\263\225.png" deleted file mode 100644 index bd73700c41d62b47005ad0612c74f2823a1921a9..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\350\275\273\351\207\217\347\263\273\347\273\237\345\212\250\346\200\201\345\206\205\345\255\230\346\240\270\345\277\203\347\256\227\346\263\225.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\350\277\233\347\250\213\346\240\221\347\244\272\346\204\217\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\350\277\233\347\250\213\346\240\221\347\244\272\346\204\217\345\233\276.png" deleted file mode 100644 index 6888a98f6d3acb00451b16de55c9ce95170948e6..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\350\277\233\347\250\213\346\240\221\347\244\272\346\204\217\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\350\277\233\347\250\213\347\212\266\346\200\201\350\277\201\347\247\273\347\244\272\346\204\217\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\350\277\233\347\250\213\347\212\266\346\200\201\350\277\201\347\247\273\347\244\272\346\204\217\345\233\276.png" deleted file mode 100755 index d08425a0267084587dba656c01e9d529be6782b1..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\350\277\233\347\250\213\347\212\266\346\200\201\350\277\201\347\247\273\347\244\272\346\204\217\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\351\230\237\345\210\227\350\257\273\345\206\231\346\225\260\346\215\256\346\223\215\344\275\234\347\244\272\346\204\217\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\351\230\237\345\210\227\350\257\273\345\206\231\346\225\260\346\215\256\346\223\215\344\275\234\347\244\272\346\204\217\345\233\276.png" deleted file mode 100644 index c1107463e058df1402f1b19d02b58f0ccb0898e2..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\351\230\237\345\210\227\350\257\273\345\206\231\346\225\260\346\215\256\346\223\215\344\275\234\347\244\272\346\204\217\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\351\235\231\346\200\201\345\206\205\345\255\230\347\244\272\346\204\217\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\351\235\231\346\200\201\345\206\205\345\255\230\347\244\272\346\204\217\345\233\276.png" deleted file mode 100644 index d3bf07dcb1c4e0e9207eb1cf083cb9aeae945394..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\351\235\231\346\200\201\345\206\205\345\255\230\347\244\272\346\204\217\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\351\235\236\350\277\236\347\273\255\346\200\247\345\206\205\345\255\230\345\220\210\344\270\200\347\244\272\346\204\217\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\351\235\236\350\277\236\347\273\255\346\200\247\345\206\205\345\255\230\345\220\210\344\270\200\347\244\272\346\204\217\345\233\276.png" deleted file mode 100644 index 43e98c03680a9d9d8c720818b2094905da49ec85..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/kernel/figure/\351\235\236\350\277\236\347\273\255\346\200\247\345\206\205\345\255\230\345\220\210\344\270\200\347\244\272\346\204\217\345\233\276.png" and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/HDF_WIFI.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/HDF_WIFI.png deleted file mode 100644 index 56e6ab3aee9a539c76afd3edac98f21bff0766d5..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/HDF_WIFI.png and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/OpenHarmony-\351\251\261\345\212\250\345\210\206\347\261\273.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/OpenHarmony-\351\251\261\345\212\250\345\210\206\347\261\273.png" deleted file mode 100644 index 7edac54ec2fcd1fc93330d47acb2d44fceef2710..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/OpenHarmony-\351\251\261\345\212\250\345\210\206\347\261\273.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/OpenHarmony\345\220\257\345\212\250\346\210\220\345\212\237\347\225\214\351\235\242.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/OpenHarmony\345\220\257\345\212\250\346\210\220\345\212\237\347\225\214\351\235\242.png" deleted file mode 100755 index 7d0b723345d413067e0142b2035205133c907ab0..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/OpenHarmony\345\220\257\345\212\250\346\210\220\345\212\237\347\225\214\351\235\242.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/WLAN\350\212\257\347\211\207.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/WLAN\350\212\257\347\211\207.png" deleted file mode 100644 index c325922a5ee67edb81aa526de1547716fae1a04b..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/WLAN\350\212\257\347\211\207.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/init\345\220\257\345\212\250\346\255\243\345\270\270\346\227\245\345\277\227.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/init\345\220\257\345\212\250\346\255\243\345\270\270\346\227\245\345\277\227.png" deleted file mode 100644 index a1e7f8b695bebf395ea6cfa0aed55495c4896118..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/init\345\220\257\345\212\250\346\255\243\345\270\270\346\227\245\345\277\227.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/liteos-m\345\206\205\346\240\270\346\250\241\345\235\227\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/liteos-m\345\206\205\346\240\270\346\250\241\345\235\227\345\233\276.png" deleted file mode 100755 index 2cd5f7a4c095429f8e447b17562b37051343c689..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/liteos-m\345\206\205\346\240\270\346\250\241\345\235\227\345\233\276.png" and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/zh-cn_image_0000001162805936.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/zh-cn_image_0000001162805936.png deleted file mode 100644 index 0546e82fc91c605ba78f9bb56c4de88066c8c189..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/zh-cn_image_0000001162805936.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/zh-cn_image_0000001208365855.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/zh-cn_image_0000001208365855.png deleted file mode 100644 index 3cb585b4f3780141a122563f9d05bb47c1e30dd7..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/zh-cn_image_0000001208365855.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/zh-cn_image_0000001208524821.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/zh-cn_image_0000001208524821.png deleted file mode 100644 index 2668799e706c34df82d75050e701f450e226a536..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/zh-cn_image_0000001208524821.png and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/\344\270\232\345\212\241\345\220\257\345\212\250\346\265\201\347\250\213.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/\344\270\232\345\212\241\345\220\257\345\212\250\346\265\201\347\250\213.png" deleted file mode 100644 index cbc70a899f77382e9e052c30f2a69b61764d2643..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/\344\270\232\345\212\241\345\220\257\345\212\250\346\265\201\347\250\213.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/\345\206\205\346\240\270\345\220\257\345\212\250\346\241\206\346\236\266.jpg" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/\345\206\205\346\240\270\345\220\257\345\212\250\346\241\206\346\236\266.jpg" deleted file mode 100644 index dd8e1c235633c3e42fcd1360b66b3ce3452db02d..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/\345\206\205\346\240\270\345\220\257\345\212\250\346\241\206\346\236\266.jpg" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/\345\215\225\346\235\277\351\251\261\345\212\250\351\200\202\351\205\215\346\265\201\347\250\213.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/\345\215\225\346\235\277\351\251\261\345\212\250\351\200\202\351\205\215\346\265\201\347\250\213.png" deleted file mode 100755 index c886985b8cb0db42b71a693df78a1aac20b88ac2..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/\345\215\225\346\235\277\351\251\261\345\212\250\351\200\202\351\205\215\346\265\201\347\250\213.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/\345\220\257\345\212\250\346\265\201\347\250\213.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/\345\220\257\345\212\250\346\265\201\347\250\213.png" deleted file mode 100755 index 93f747cae385fb714334d5145103d6f7ddfacd95..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/\345\220\257\345\212\250\346\265\201\347\250\213.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/\345\237\272\344\272\216linux\345\206\205\346\240\270\347\232\204OS\351\225\234\345\203\217\347\273\223\346\236\204\345\222\214\347\224\250\346\210\267\346\200\201\347\250\213\345\272\217\345\220\257\345\212\250\346\265\201\347\250\213.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/\345\237\272\344\272\216linux\345\206\205\346\240\270\347\232\204OS\351\225\234\345\203\217\347\273\223\346\236\204\345\222\214\347\224\250\346\210\267\346\200\201\347\250\213\345\272\217\345\220\257\345\212\250\346\265\201\347\250\213.png" deleted file mode 100644 index b241920b30fea1b2a432f6ba01045bbfbae7fb58..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/\345\237\272\344\272\216linux\345\206\205\346\240\270\347\232\204OS\351\225\234\345\203\217\347\273\223\346\236\204\345\222\214\347\224\250\346\210\267\346\200\201\347\250\213\345\272\217\345\220\257\345\212\250\346\265\201\347\250\213.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/\346\225\264\344\275\223\345\220\257\345\212\250\346\265\201\347\250\213.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/\346\225\264\344\275\223\345\220\257\345\212\250\346\265\201\347\250\213.png" deleted file mode 100644 index 39c6cb96611a7ced5e17bbeee96ac77ba5c1bf58..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/\346\225\264\344\275\223\345\220\257\345\212\250\346\265\201\347\250\213.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/\346\255\243\345\270\270\350\277\233\345\205\245shell\345\220\216\350\276\223\345\205\245ls\345\221\275\344\273\244\344\270\262\345\217\243\346\211\223\345\215\260.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/\346\255\243\345\270\270\350\277\233\345\205\245shell\345\220\216\350\276\223\345\205\245ls\345\221\275\344\273\244\344\270\262\345\217\243\346\211\223\345\215\260.png" deleted file mode 100644 index efb1e17b00d37b072a3032678144984e2e13b2d6..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/\346\255\243\345\270\270\350\277\233\345\205\245shell\345\220\216\350\276\223\345\205\245ls\345\221\275\344\273\244\344\270\262\345\217\243\346\211\223\345\215\260.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/\350\212\257\347\211\207\347\247\273\346\244\215\345\205\263\351\224\256\346\255\245\351\252\244.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/\350\212\257\347\211\207\347\247\273\346\244\215\345\205\263\351\224\256\346\255\245\351\252\244.png" deleted file mode 100755 index 3cbefc997a46c6175735c6e3b8b6e29ff03b05d4..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/porting/figure/\350\212\257\347\211\207\347\247\273\346\244\215\345\205\263\351\224\256\346\255\245\351\252\244.png" and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/public_sys-resources/icon-caution.gif b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/public_sys-resources/icon-caution.gif deleted file mode 100644 index 6e90d7cfc2193e39e10bb58c38d01a23f045d571..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/public_sys-resources/icon-caution.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/public_sys-resources/icon-note.gif b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/public_sys-resources/icon-note.gif deleted file mode 100644 index 6314297e45c1de184204098efd4814d6dc8b1cda..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/public_sys-resources/icon-note.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/public_sys-resources/icon-notice.gif b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/public_sys-resources/icon-notice.gif deleted file mode 100644 index 86024f61b691400bea99e5b1f506d9d9aef36e27..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/public_sys-resources/icon-notice.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/1-11.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/1-11.png deleted file mode 100644 index 8ed1535a6bc23dc5bd02fbd5a3f1392f46ad8d83..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/1-11.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/1.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/1.png deleted file mode 100644 index 791dfeae272070b7e285ea3070ebd3b1e9100eb5..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/1.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/10.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/10.png deleted file mode 100644 index 3b7f6f4766c54f6ca1e0057fc8f869785cc63e56..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/10.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/11.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/11.png deleted file mode 100644 index ff9105c313d5755f140920bbfc2399e3ccb5e2f5..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/11.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/2021-01-27_170334-10.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/2021-01-27_170334-10.png deleted file mode 100644 index 5b573a4ddfe89fe25cb1b567736823244fdb9e97..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/2021-01-27_170334-10.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/2021-01-27_170334.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/2021-01-27_170334.png deleted file mode 100644 index 5b573a4ddfe89fe25cb1b567736823244fdb9e97..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/2021-01-27_170334.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/3-0.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/3-0.png deleted file mode 100644 index f354b2d27ce06bd5af6a8702c0894bf5c50a97bb..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/3-0.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/3.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/3.png deleted file mode 100644 index 91f3fa22153f501e308fab46f92f2e95995f1917..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/3.png and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/3516\346\255\243\351\235\242.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/3516\346\255\243\351\235\242.png" deleted file mode 100644 index 6975fb5fef92e35dec2de84b7e7035a39794bdf4..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/3516\346\255\243\351\235\242.png" and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/4.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/4.png deleted file mode 100644 index 3f5fa2829949e59d498da9dd5ff1f48fa0647cf1..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/4.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/5.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/5.png deleted file mode 100644 index f3a76a6922315fe595ae4214331ce322766b3b48..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/5.png and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/Hi3516\345\215\225\346\235\277\346\255\243\351\235\242\345\244\226\350\247\202\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/Hi3516\345\215\225\346\235\277\346\255\243\351\235\242\345\244\226\350\247\202\345\233\276.png" deleted file mode 100644 index 6975fb5fef92e35dec2de84b7e7035a39794bdf4..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/Hi3516\345\215\225\346\235\277\346\255\243\351\235\242\345\244\226\350\247\202\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/Hi3516\347\274\226\350\257\221\350\256\276\347\275\256\345\233\276\344\276\213-Docker\346\226\271\345\274\217.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/Hi3516\347\274\226\350\257\221\350\256\276\347\275\256\345\233\276\344\276\213-Docker\346\226\271\345\274\217.png" deleted file mode 100644 index edb1711f3c1fa906940d8cbb8d8fcdeb2badd2b6..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/Hi3516\347\274\226\350\257\221\350\256\276\347\275\256\345\233\276\344\276\213-Docker\346\226\271\345\274\217.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/Hi3518EV300\345\215\225\346\235\277\346\255\243\351\235\242\345\244\226\350\247\202\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/Hi3518EV300\345\215\225\346\235\277\346\255\243\351\235\242\345\244\226\350\247\202\345\233\276.png" deleted file mode 100755 index 93cadcb6edf9d8b4d701faf7e070f74cc09ef553..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/Hi3518EV300\345\215\225\346\235\277\346\255\243\351\235\242\345\244\226\350\247\202\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/Hi3518\346\255\243\350\203\214\351\235\242.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/Hi3518\346\255\243\350\203\214\351\235\242.png" deleted file mode 100644 index 3e0ff2fdbfbaca179f1320b5d53ebf755d1c84a3..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/Hi3518\346\255\243\350\203\214\351\235\242.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/Hi3518\347\274\226\350\257\221\350\256\276\347\275\256\345\233\276\344\276\213-Docker\346\226\271\345\274\217.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/Hi3518\347\274\226\350\257\221\350\256\276\347\275\256\345\233\276\344\276\213-Docker\346\226\271\345\274\217.png" deleted file mode 100644 index ffdeca24f4b017d7a35fc96999d04faaa09972e5..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/Hi3518\347\274\226\350\257\221\350\256\276\347\275\256\345\233\276\344\276\213-Docker\346\226\271\345\274\217.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/Hi3861\345\274\200\345\217\221\346\235\277\345\244\226\350\247\202\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/Hi3861\345\274\200\345\217\221\346\235\277\345\244\226\350\247\202\345\233\276.png" deleted file mode 100644 index 5086d2b4518cfea4040f3cc243abb2e6087af350..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/Hi3861\345\274\200\345\217\221\346\235\277\345\244\226\350\247\202\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/Hi3861\347\274\226\350\257\221\350\256\276\347\275\256\345\233\276\344\276\213-Docker\346\226\271\345\274\217.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/Hi3861\347\274\226\350\257\221\350\256\276\347\275\256\345\233\276\344\276\213-Docker\346\226\271\345\274\217.png" deleted file mode 100644 index 9e53432ce41e67ee3e93e96d78262a6ace41d383..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/Hi3861\347\274\226\350\257\221\350\256\276\347\275\256\345\233\276\344\276\213-Docker\346\226\271\345\274\217.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/RK3568\345\274\200\345\217\221\346\235\277\346\255\243\351\235\242.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/RK3568\345\274\200\345\217\221\346\235\277\346\255\243\351\235\242.png" deleted file mode 100644 index fbd3cb48f2cb35c02595be0293733644e16020bd..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/RK3568\345\274\200\345\217\221\346\235\277\346\255\243\351\235\242.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/RK3568\345\274\200\345\217\221\346\235\277\350\203\214\351\235\242.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/RK3568\345\274\200\345\217\221\346\235\277\350\203\214\351\235\242.png" deleted file mode 100644 index 8baa9c7c75625c18979d30ab52b2a0f64e0e8349..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/RK3568\345\274\200\345\217\221\346\235\277\350\203\214\351\235\242.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/SCons\345\256\211\350\243\205\346\210\220\345\212\237\347\225\214\351\235\242-\347\211\210\346\234\254\350\246\201\346\261\2023-0-4\344\273\245\344\270\212.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/SCons\345\256\211\350\243\205\346\210\220\345\212\237\347\225\214\351\235\242-\347\211\210\346\234\254\350\246\201\346\261\2023-0-4\344\273\245\344\270\212.png" deleted file mode 100755 index e66ca6ffae9aec5f4f5b97ceccf2e37792e95f18..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/SCons\345\256\211\350\243\205\346\210\220\345\212\237\347\225\214\351\235\242-\347\211\210\346\234\254\350\246\201\346\261\2023-0-4\344\273\245\344\270\212.png" and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/Save-the-parameter-settings.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/Save-the-parameter-settings.png deleted file mode 100644 index 47231369bbeb827e70a8720b7a3d03ac58fad0c3..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/Save-the-parameter-settings.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/Snap22.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/Snap22.png deleted file mode 100644 index d94579cb7ff78a40cef6cf5d1945e742a9551e8b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/Snap22.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/Snap23.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/Snap23.png deleted file mode 100644 index 92e51762a2dcd636135f6e7856073a5b8aecd1d6..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/Snap23.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/Snap24.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/Snap24.png deleted file mode 100644 index d4996e347660921fc3f723e5b48942f1fd6636f5..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/Snap24.png and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/U-boot\347\203\247\345\206\231\345\256\214\346\210\220\344\270\262\345\217\243\346\230\276\347\244\272\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/U-boot\347\203\247\345\206\231\345\256\214\346\210\220\344\270\262\345\217\243\346\230\276\347\244\272\345\233\276.png" deleted file mode 100644 index ad4fd618860ca9f79e9bdc39436c3b2f9cdb72de..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/U-boot\347\203\247\345\206\231\345\256\214\346\210\220\344\270\262\345\217\243\346\230\276\347\244\272\345\233\276.png" and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/bootloader.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/bootloader.png deleted file mode 100644 index e674bafb0adaa4c0ff8efaf297ee52bab3165212..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/bootloader.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/button.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/button.png deleted file mode 100755 index 686385e096a24ec1906169d2b11f75030c386b9f..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/button.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/changjian1-4.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/changjian1-4.png deleted file mode 100644 index 208a4fbace342514f59f0000c4d50f5dc9321f0f..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/changjian1-4.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/changjian1.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/changjian1.png deleted file mode 100644 index 208a4fbace342514f59f0000c4d50f5dc9321f0f..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/changjian1.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/deveco-device-tool-install-sucessful.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/deveco-device-tool-install-sucessful.png deleted file mode 100644 index 0a54838f89062fd67328ef76e4a1cf770c6aee13..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/deveco-device-tool-install-sucessful.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hi3516-burning-succeeded-net.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hi3516-burning-succeeded-net.png deleted file mode 100644 index 67d8044b72056d4ed6230ccc4ad99d5e954596b6..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hi3516-burning-succeeded-net.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hi3516-import-projects.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hi3516-import-projects.png deleted file mode 100644 index 6c575b3495a0503e463a71f2b50766bc2f3e1b94..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hi3516-import-projects.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hi3516-restart-the-development-board.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hi3516-restart-the-development-board.png deleted file mode 100644 index 281958fe76a787acc5d0b98f5ea248fa5abf2405..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hi3516-restart-the-development-board.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hi3516-upload-start-burning.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hi3516-upload-start-burning.png deleted file mode 100644 index fb2db198cc61ed10136f0e3382deed352300a62b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hi3516-upload-start-burning.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hi3518-bootloader.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hi3518-bootloader.png deleted file mode 100644 index 2d67376af75fa7693ed16299de75255c08178c14..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hi3518-bootloader.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hi3518-import-projects.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hi3518-import-projects.png deleted file mode 100644 index d54cd737e32311492dc2058251e7cb8acf905fb5..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hi3518-import-projects.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hi3518-monitor.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hi3518-monitor.png deleted file mode 100644 index d287df0c64ca5e2ffc27aa1acd820cdf0e6b40c6..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hi3518-monitor.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hi3518-reboot-success.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hi3518-reboot-success.png deleted file mode 100644 index 7a063003ded7d94e8b2a030a3df855f6915c933c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hi3518-reboot-success.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hi3518-reset-success.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hi3518-reset-success.png deleted file mode 100644 index 8e3d4e7d2a36e2b880f592ec88b01b6c4bef07cc..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hi3518-reset-success.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hi3861-burning-succeeded.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hi3861-burning-succeeded.png deleted file mode 100755 index 3628f3f4778012a577d4ee28c703669eb5533594..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hi3861-burning-succeeded.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hi3861-import-projects.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hi3861-import-projects.png deleted file mode 100644 index 6eaa9eb2450ef15e7124df610712fc797c548351..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hi3861-import-projects.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hi3861-record-the-serial-port-number.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hi3861-record-the-serial-port-number.png deleted file mode 100755 index 43496f076a463ec6fbf320b358a32505284ff40f..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hi3861-record-the-serial-port-number.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hi3861-upload.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hi3861-upload.png deleted file mode 100644 index 8dde7632636856203030c2abf0867f03abaafcba..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hi3861-upload.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hisilicon-arm-linux.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hisilicon-arm-linux.png deleted file mode 100644 index 114a8e1c31ab1a58ece6b0d1e00d673256b42b2b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/hisilicon-arm-linux.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/import-project-confirm.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/import-project-confirm.png deleted file mode 100644 index 27fe1d133a31b275a2788cab1f5b37dd3450a7df..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/import-project-confirm.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/import-project.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/import-project.png deleted file mode 100644 index 5ba534eaf39165891a31c7837ae7ff4126f6414c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/import-project.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/ip-address-information.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/ip-address-information.png deleted file mode 100644 index 72dd05e3ae1eb91156df98cb1915b6264b3bbe5a..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/ip-address-information.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/monitor.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/monitor.png deleted file mode 100644 index bc935a8970e39629d2c93f6b92f96c5fa7d1a49b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/monitor.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/open-the-serial-port-tool.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/open-the-serial-port-tool.png deleted file mode 100644 index 6d350e5d4db03fecc5c1b8055b01cdf73667ed36..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/open-the-serial-port-tool.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/press-any-key-to-enter-the-system.gif b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/press-any-key-to-enter-the-system.gif deleted file mode 100644 index 5e0e2bec9e8ce82561047fe7d5f000e0d2c4f962..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/press-any-key-to-enter-the-system.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/reboot_success.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/reboot_success.png deleted file mode 100644 index 7a063003ded7d94e8b2a030a3df855f6915c933c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/reboot_success.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/record-the-serial-port-number.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/record-the-serial-port-number.png deleted file mode 100644 index 09f33e3992c0c1d78713eea949e4b9a19f5802ec..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/record-the-serial-port-number.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/reset_success.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/reset_success.png deleted file mode 100644 index 67e50038e79cf0f7c2a6bd79b48c63b7557179a4..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/reset_success.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/rk3568-helloworld.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/rk3568-helloworld.png deleted file mode 100644 index da22f3989b1daa362c7471789cdaa94ffb862f75..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/rk3568-helloworld.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/rk3568-run-configuration.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/rk3568-run-configuration.png deleted file mode 100644 index 504da23ba456a9c377525e22c4630361286b5dd7..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/rk3568-run-configuration.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/setenv-bootargs.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/setenv-bootargs.png deleted file mode 100644 index 802cce4e760102043f177cb2fa71e8bd16539ba1..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/setenv-bootargs.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/start-the-system.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/start-the-system.png deleted file mode 100644 index 5006140f00ec1195d04297cdeb26ad935fb9f0e5..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/start-the-system.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001073838982.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001073838982.png deleted file mode 100644 index 0bbff7eb0b5ab322e8995acf2b86d93038c8530c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001073838982.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001074287476.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001074287476.png deleted file mode 100644 index 29a273e5115ffd7a0724cde58215ffb79827576c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001074287476.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001075566984.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001075566984.png deleted file mode 100644 index dee491aaa290b425a4a6cd9e4aee61b3b05cc3dc..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001075566984.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001113969536.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001113969536.png deleted file mode 100644 index baac7b26450b8bc195a0db0bb3bb41119c0d9828..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001113969536.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001114129426.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001114129426.png deleted file mode 100644 index c5548cb227bd024b49aa3adba0a20869581448e8..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001114129426.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001117329380.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001117329380.png deleted file mode 100644 index 7bd316dfd5a64c873682bf865a79ec1f2354cc40..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001117329380.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001160649343.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001160649343.png deleted file mode 100644 index 67d8044b72056d4ed6230ccc4ad99d5e954596b6..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001160649343.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001163045527.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001163045527.png deleted file mode 100644 index d8ac531b8265f265e2bd25518b212143fc61e4cf..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001163045527.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001171455564.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001171455564.png deleted file mode 100644 index c846be0d2767953df4a3ac78408963f252af040d..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001171455564.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001171455566.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001171455566.png deleted file mode 100644 index 7de3c25e7ef2abc8d85d8bc945249f571f6bf0c3..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001171455566.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001171455574.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001171455574.png deleted file mode 100644 index 24fb00fddc1213037e63e7674b4d2ce1bf6118f6..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001171455574.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001171615534.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001171615534.png deleted file mode 100644 index b6bc36af5339ea5a4f67640e69836965b3776e17..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001171615534.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001171615542.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001171615542.png deleted file mode 100644 index 527fe8b9836daf35c8300e0e84bdb2ca390f85a5..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001171615542.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001171774086.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001171774086.png deleted file mode 100644 index 1b002b247b704150040e90ecb149d782ba8db3a8..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001171774086.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001171774098.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001171774098.png deleted file mode 100644 index b6bc36af5339ea5a4f67640e69836965b3776e17..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001171774098.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001171934032.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001171934032.png deleted file mode 100644 index 9284df45bb1415d84f0325df85b4eb5c223281e8..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001171934032.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001174595590.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001174595590.png deleted file mode 100644 index 84d42fffbd87d0e719c69b6deda9e6c5e2b2db13..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001174595590.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001177301516.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001177301516.png deleted file mode 100644 index 4cc2bbf53d65b0c66f07b330aa8881c5194328bd..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001177301516.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001177474882.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001177474882.png deleted file mode 100644 index 68b1730cb6d1b91b6e364c7301d6dcc4c9976ec7..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001177474882.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001177478136.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001177478136.png deleted file mode 100644 index fcaf25e47e2e47ecad8aebe463aeccdf1d8bf85e..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001177478136.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001177480146.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001177480146.png deleted file mode 100644 index 99ed8317b5cee8e5e9d460ff31d5c8a1a2fe343e..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001177480146.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001177608370.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001177608370.png deleted file mode 100644 index 1ba77b7feaca23043e71171824cdead7c4f8f108..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001177608370.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001177798424.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001177798424.png deleted file mode 100644 index c93b7b610138e91c0b6b171cb515f540163e731b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001177798424.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001185334336.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001185334336.png deleted file mode 100644 index a8037d1ebc95a3c9383d87678981b3ae5ccc8144..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001185334336.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001193533352.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001193533352.png deleted file mode 100644 index da22f3989b1daa362c7471789cdaa94ffb862f75..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001193533352.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001194078294.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001194078294.png deleted file mode 100644 index 35a95f501f5e3c5c8ebf187e7f29e6af0a4566b0..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001194078294.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001194668634.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001194668634.png deleted file mode 100644 index 9f418473587db76e56981c0f384bf4b8634e3911..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001194668634.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001216535397.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001216535397.png deleted file mode 100644 index ad4fd618860ca9f79e9bdc39436c3b2f9cdb72de..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001216535397.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001216535401.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001216535401.png deleted file mode 100644 index 9284df45bb1415d84f0325df85b4eb5c223281e8..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001216535401.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001216693913.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001216693913.png deleted file mode 100644 index 1b002b247b704150040e90ecb149d782ba8db3a8..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001216693913.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001216693915.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001216693915.png deleted file mode 100644 index 9284df45bb1415d84f0325df85b4eb5c223281e8..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001216693915.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001217013865.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001217013865.png deleted file mode 100644 index b6bc36af5339ea5a4f67640e69836965b3776e17..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001217013865.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001217013871.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001217013871.png deleted file mode 100644 index 39ae26ac8f3254d023d6b90a9f9bb8a8ff0c940b..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001217013871.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001222781271.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001222781271.png deleted file mode 100644 index 8d396bf2fc7b36362a95c6719d202b2f057e4a46..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001222781271.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001222794413.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001222794413.png deleted file mode 100644 index 764643ce134811551984284ed5ec6b60943f8ea4..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001222794413.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001222969587.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001222969587.png deleted file mode 100644 index 1ba77b7feaca23043e71171824cdead7c4f8f108..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001222969587.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001222981447.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001222981447.png deleted file mode 100644 index 6c862cc279d2936ddec4ecda0a23e1d55a63cbee..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001222981447.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001222994321.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001222994321.png deleted file mode 100644 index 07914f4f34921b06819ceb49cf63366dcc7f8502..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001222994321.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001222997983.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001222997983.png deleted file mode 100644 index f0d98bd6deb22fc7814a42630b8565d9b5979659..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001222997983.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001222999125.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001222999125.png deleted file mode 100644 index 5a709092da504fbb090ad8d44938e435712bc0eb..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001222999125.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001223000051.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001223000051.png deleted file mode 100644 index 6117c80b45f64348ad307e64723495cdc8c45cb1..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001223000051.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001223185957.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001223185957.png deleted file mode 100644 index 764643ce134811551984284ed5ec6b60943f8ea4..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001223185957.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001238878219.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001238878219.png deleted file mode 100644 index 579d6e190d4824cb866f90f2f3e72c4493aa6f4c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001238878219.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001239348791.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001239348791.png deleted file mode 100644 index c6507f28b980b84c65102aa844e93f806cb490a9..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/zh-cn_image_0000001239348791.png and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\345\205\201\350\256\270Visual-Studio-Code\345\272\224\347\224\250\350\256\277\351\227\256\347\275\221\347\273\234-9.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\345\205\201\350\256\270Visual-Studio-Code\345\272\224\347\224\250\350\256\277\351\227\256\347\275\221\347\273\234-9.png" deleted file mode 100644 index afc9028fbb61db82e6f1384032bb32f56ed2ec35..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\345\205\201\350\256\270Visual-Studio-Code\345\272\224\347\224\250\350\256\277\351\227\256\347\275\221\347\273\234-9.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\345\205\201\350\256\270Visual-Studio-Code\345\272\224\347\224\250\350\256\277\351\227\256\347\275\221\347\273\234.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\345\205\201\350\256\270Visual-Studio-Code\345\272\224\347\224\250\350\256\277\351\227\256\347\275\221\347\273\234.png" deleted file mode 100644 index afc9028fbb61db82e6f1384032bb32f56ed2ec35..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\345\205\201\350\256\270Visual-Studio-Code\345\272\224\347\224\250\350\256\277\351\227\256\347\275\221\347\273\234.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\345\205\263\351\227\255\344\270\262\345\217\243\347\273\210\347\253\257-3.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\345\205\263\351\227\255\344\270\262\345\217\243\347\273\210\347\253\257-3.png" deleted file mode 100644 index 0c1f60638087d0fe56127f2f842244355afad85f..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\345\205\263\351\227\255\344\270\262\345\217\243\347\273\210\347\253\257-3.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\345\205\263\351\227\255\344\270\262\345\217\243\347\273\210\347\253\257.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\345\205\263\351\227\255\344\270\262\345\217\243\347\273\210\347\253\257.png" deleted file mode 100644 index 0c1f60638087d0fe56127f2f842244355afad85f..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\345\205\263\351\227\255\344\270\262\345\217\243\347\273\210\347\253\257.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\346\211\223\345\274\200\344\270\262\345\217\243\345\244\261\350\264\245\345\233\276-1.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\346\211\223\345\274\200\344\270\262\345\217\243\345\244\261\350\264\245\345\233\276-1.png" deleted file mode 100644 index 0eee1bbff2e54816d6be05f7f3972a83f615884d..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\346\211\223\345\274\200\344\270\262\345\217\243\345\244\261\350\264\245\345\233\276-1.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\346\211\223\345\274\200\344\270\262\345\217\243\345\244\261\350\264\245\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\346\211\223\345\274\200\344\270\262\345\217\243\345\244\261\350\264\245\345\233\276.png" deleted file mode 100644 index 0eee1bbff2e54816d6be05f7f3972a83f615884d..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\346\211\223\345\274\200\344\270\262\345\217\243\345\244\261\350\264\245\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\346\237\245\346\211\276Visual-Studio-Code\345\272\224\347\224\250\345\233\276-8.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\346\237\245\346\211\276Visual-Studio-Code\345\272\224\347\224\250\345\233\276-8.png" deleted file mode 100644 index c735ae362e184083329cdf710289a169ad5625d4..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\346\237\245\346\211\276Visual-Studio-Code\345\272\224\347\224\250\345\233\276-8.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\346\237\245\346\211\276Visual-Studio-Code\345\272\224\347\224\250\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\346\237\245\346\211\276Visual-Studio-Code\345\272\224\347\224\250\345\233\276.png" deleted file mode 100644 index c735ae362e184083329cdf710289a169ad5625d4..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\346\237\245\346\211\276Visual-Studio-Code\345\272\224\347\224\250\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\346\237\245\346\211\276\346\230\257\345\220\246\345\255\230\345\234\250\345\215\240\347\224\250\344\270\262\345\217\243\347\232\204\347\273\210\347\253\257-2.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\346\237\245\346\211\276\346\230\257\345\220\246\345\255\230\345\234\250\345\215\240\347\224\250\344\270\262\345\217\243\347\232\204\347\273\210\347\253\257-2.png" deleted file mode 100644 index cfa0ceb21f5a11d459b93721f512309c9d6da2ac..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\346\237\245\346\211\276\346\230\257\345\220\246\345\255\230\345\234\250\345\215\240\347\224\250\344\270\262\345\217\243\347\232\204\347\273\210\347\253\257-2.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\346\237\245\346\211\276\346\230\257\345\220\246\345\255\230\345\234\250\345\215\240\347\224\250\344\270\262\345\217\243\347\232\204\347\273\210\347\253\257.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\346\237\245\346\211\276\346\230\257\345\220\246\345\255\230\345\234\250\345\215\240\347\224\250\344\270\262\345\217\243\347\232\204\347\273\210\347\253\257.png" deleted file mode 100644 index cfa0ceb21f5a11d459b93721f512309c9d6da2ac..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\346\237\245\346\211\276\346\230\257\345\220\246\345\255\230\345\234\250\345\215\240\347\224\250\344\270\262\345\217\243\347\232\204\347\273\210\347\253\257.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\346\240\207\345\207\206\347\263\273\347\273\237\345\277\253\351\200\237\345\205\245\351\227\250\346\265\201\347\250\213.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\346\240\207\345\207\206\347\263\273\347\273\237\345\277\253\351\200\237\345\205\245\351\227\250\346\265\201\347\250\213.png" deleted file mode 100644 index cb0aff9ea08110a305f663126f5e26f150f89344..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\346\240\207\345\207\206\347\263\273\347\273\237\345\277\253\351\200\237\345\205\245\351\227\250\346\265\201\347\250\213.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\347\263\273\347\273\237\345\220\257\345\212\250\346\225\210\346\236\234\345\233\276.jpg" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\347\263\273\347\273\237\345\220\257\345\212\250\346\225\210\346\236\234\345\233\276.jpg" deleted file mode 100644 index 31c5a26705cd1da6cf9cb6f3bb356994e4ecc22e..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\347\263\273\347\273\237\345\220\257\345\212\250\346\225\210\346\236\234\345\233\276.jpg" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\347\275\221\347\273\234\344\270\215\351\200\232-\345\215\225\346\235\277\346\227\240\346\263\225\350\216\267\345\217\226\346\226\207\344\273\266\345\233\276-5.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\347\275\221\347\273\234\344\270\215\351\200\232-\345\215\225\346\235\277\346\227\240\346\263\225\350\216\267\345\217\226\346\226\207\344\273\266\345\233\276-5.png" deleted file mode 100644 index 548e03da4b76123cb67d41cbd1de4a0f33f5ef4b..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\347\275\221\347\273\234\344\270\215\351\200\232-\345\215\225\346\235\277\346\227\240\346\263\225\350\216\267\345\217\226\346\226\207\344\273\266\345\233\276-5.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\347\275\221\347\273\234\344\270\215\351\200\232-\345\215\225\346\235\277\346\227\240\346\263\225\350\216\267\345\217\226\346\226\207\344\273\266\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\347\275\221\347\273\234\344\270\215\351\200\232-\345\215\225\346\235\277\346\227\240\346\263\225\350\216\267\345\217\226\346\226\207\344\273\266\345\233\276.png" deleted file mode 100644 index 548e03da4b76123cb67d41cbd1de4a0f33f5ef4b..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\347\275\221\347\273\234\344\270\215\351\200\232-\345\215\225\346\235\277\346\227\240\346\263\225\350\216\267\345\217\226\346\226\207\344\273\266\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\347\275\221\347\273\234\351\230\262\347\201\253\345\242\231\350\256\276\347\275\256\345\233\276-6.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\347\275\221\347\273\234\351\230\262\347\201\253\345\242\231\350\256\276\347\275\256\345\233\276-6.png" deleted file mode 100644 index 88cba0537b5431aa266364abbe19162130f4e3ca..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\347\275\221\347\273\234\351\230\262\347\201\253\345\242\231\350\256\276\347\275\256\345\233\276-6.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\347\275\221\347\273\234\351\230\262\347\201\253\345\242\231\350\256\276\347\275\256\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\347\275\221\347\273\234\351\230\262\347\201\253\345\242\231\350\256\276\347\275\256\345\233\276.png" deleted file mode 100644 index 88cba0537b5431aa266364abbe19162130f4e3ca..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\347\275\221\347\273\234\351\230\262\347\201\253\345\242\231\350\256\276\347\275\256\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\277\253\351\200\237\345\205\245\351\227\250\346\265\201\347\250\213.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\277\253\351\200\237\345\205\245\351\227\250\346\265\201\347\250\213.png" deleted file mode 100644 index c453bf36bea44aad382c65cd18ea0d8abbead981..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\277\253\351\200\237\345\205\245\351\227\250\346\265\201\347\250\213.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\351\230\262\347\201\253\345\242\231\345\222\214\347\275\221\347\273\234\344\277\235\346\212\244\347\225\214\351\235\242\345\233\276-7.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\351\230\262\347\201\253\345\242\231\345\222\214\347\275\221\347\273\234\344\277\235\346\212\244\347\225\214\351\235\242\345\233\276-7.png" deleted file mode 100644 index 775ce6fe99d4894b39f2bdd613097dcaf11a37b2..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\351\230\262\347\201\253\345\242\231\345\222\214\347\275\221\347\273\234\344\277\235\346\212\244\347\225\214\351\235\242\345\233\276-7.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\351\230\262\347\201\253\345\242\231\345\222\214\347\275\221\347\273\234\344\277\235\346\212\244\347\225\214\351\235\242\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\351\230\262\347\201\253\345\242\231\345\222\214\347\275\221\347\273\234\344\277\235\346\212\244\347\225\214\351\235\242\345\233\276.png" deleted file mode 100644 index 775ce6fe99d4894b39f2bdd613097dcaf11a37b2..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/quick-start/figures/\351\230\262\347\201\253\345\242\231\345\222\214\347\275\221\347\273\234\344\277\235\346\212\244\347\225\214\351\235\242\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/security/figure/1-\346\225\217\346\204\237\346\235\203\351\231\220\345\274\271\347\252\227.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/security/figure/1-\346\225\217\346\204\237\346\235\203\351\231\220\345\274\271\347\252\227.png" deleted file mode 100755 index fff1da1f834037c30a874b2fd76cad402b9ff9ce..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/security/figure/1-\346\225\217\346\204\237\346\235\203\351\231\220\345\274\271\347\252\227.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/security/figure/3-\345\272\224\347\224\250\351\232\220\347\247\201\345\243\260\346\230\216.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/security/figure/3-\345\272\224\347\224\250\351\232\220\347\247\201\345\243\260\346\230\216.png" deleted file mode 100755 index 2c729ec07bb1b74ef1936767cc3e9d19d4846835..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/security/figure/3-\345\272\224\347\224\250\351\232\220\347\247\201\345\243\260\346\230\216.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/security/figure/4-\351\232\220\347\247\201\345\243\260\346\230\216\345\217\230\346\233\264\351\200\232\347\237\245.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/security/figure/4-\351\232\220\347\247\201\345\243\260\346\230\216\345\217\230\346\233\264\351\200\232\347\237\245.png" deleted file mode 100755 index 90bf11ec3746c9fb00ea43608c5cf7d822f692e4..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/security/figure/4-\351\232\220\347\247\201\345\243\260\346\230\216\345\217\230\346\233\264\351\200\232\347\237\245.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/security/figure/5-\345\272\224\347\224\250\351\232\220\347\247\201\345\243\260\346\230\216\345\205\245\345\217\243.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/security/figure/5-\345\272\224\347\224\250\351\232\220\347\247\201\345\243\260\346\230\216\345\205\245\345\217\243.png" deleted file mode 100755 index a0821e9436b918bffb1ea3b3756fe6d4cc969f08..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/security/figure/5-\345\272\224\347\224\250\351\232\220\347\247\201\345\243\260\346\230\216\345\205\245\345\217\243.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/security/figure/6-2-\351\232\220\347\247\201\345\243\260\346\230\216\346\222\244\351\224\200.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/security/figure/6-2-\351\232\220\347\247\201\345\243\260\346\230\216\346\222\244\351\224\200.png" deleted file mode 100755 index c504f5246b2988876649a3f5d0c9059c7a0b2441..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/security/figure/6-2-\351\232\220\347\247\201\345\243\260\346\230\216\346\222\244\351\224\200.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/security/figure/DAC\346\265\201\347\250\213\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/security/figure/DAC\346\265\201\347\250\213\345\233\276.png" deleted file mode 100755 index 42300c9ca287049f03a8f90a8bba9c2cdc73e109..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/security/figure/DAC\346\265\201\347\250\213\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/security/figure/HUKS\345\212\237\350\203\275\347\273\223\346\236\204\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/security/figure/HUKS\345\212\237\350\203\275\347\273\223\346\236\204\345\233\276.png" deleted file mode 100755 index 87def1af5551ba7236979df89eaabadef1d362d8..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/security/figure/HUKS\345\212\237\350\203\275\347\273\223\346\236\204\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/security/figure/\345\256\211\345\205\250\344\277\235\351\232\234\347\244\272\346\204\217\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/security/figure/\345\256\211\345\205\250\344\277\235\351\232\234\347\244\272\346\204\217\345\233\276.png" deleted file mode 100755 index fcab754c7446d4b886cc1d68d52832b1a006370d..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/security/figure/\345\256\211\345\205\250\344\277\235\351\232\234\347\244\272\346\204\217\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/security/figure/\350\256\276\345\244\207\351\227\264\345\273\272\347\253\213\345\217\257\344\277\241\345\205\263\347\263\273\346\265\201\347\250\213\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/security/figure/\350\256\276\345\244\207\351\227\264\345\273\272\347\253\213\345\217\257\344\277\241\345\205\263\347\263\273\346\265\201\347\250\213\345\233\276.png" deleted file mode 100755 index 69ce9db229347ee2de2401fc0caef8f82d6f2035..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/security/figure/\350\256\276\345\244\207\351\227\264\345\273\272\347\253\213\345\217\257\344\277\241\345\205\263\347\263\273\346\265\201\347\250\213\345\233\276.png" and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/20200721-223604(eSpace).gif b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/20200721-223604(eSpace).gif deleted file mode 100755 index 8a5dcafb1c14c744d60590bc7ad913569a2fa92c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/20200721-223604(eSpace).gif and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/Ability\344\270\216AbilitySlice\347\232\204\345\205\263\347\263\273\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/Ability\344\270\216AbilitySlice\347\232\204\345\205\263\347\263\273\345\233\276.png" deleted file mode 100755 index d75201bb385d4a02d05c38174a5be216953da9c6..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/Ability\344\270\216AbilitySlice\347\232\204\345\205\263\347\263\273\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/Ability\345\255\220\347\263\273\347\273\237\346\241\206\346\236\266\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/Ability\345\255\220\347\263\273\347\273\237\346\241\206\346\236\266\345\233\276.png" deleted file mode 100755 index a7335c79e316dcefaa91de546cf1604644e471df..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/Ability\345\255\220\347\263\273\347\273\237\346\241\206\346\236\266\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/Ability\347\256\241\347\220\206\346\234\215\345\212\241\345\222\214\345\214\205\347\256\241\347\220\206\346\234\215\345\212\241\345\220\257\345\212\250.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/Ability\347\256\241\347\220\206\346\234\215\345\212\241\345\222\214\345\214\205\347\256\241\347\220\206\346\234\215\345\212\241\345\220\257\345\212\250.png" deleted file mode 100755 index b84f177a7d26094ea96ad7e28b9872217fe79ab8..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/Ability\347\256\241\347\220\206\346\234\215\345\212\241\345\222\214\345\214\205\347\256\241\347\220\206\346\234\215\345\212\241\345\220\257\345\212\250.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/LiteOS-A\345\271\263\345\217\260dump\347\263\273\347\273\237\345\261\236\346\200\247\350\276\223\345\207\272.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/LiteOS-A\345\271\263\345\217\260dump\347\263\273\347\273\237\345\261\236\346\200\247\350\276\223\345\207\272.png" deleted file mode 100755 index c7e8c809207f0dc8965a2f8a41b55f0ae2abe13b..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/LiteOS-A\345\271\263\345\217\260dump\347\263\273\347\273\237\345\261\236\346\200\247\350\276\223\345\207\272.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/LiteOS-M\345\271\263\345\217\260dump\347\263\273\347\273\237\345\261\236\346\200\247\350\276\223\345\207\272.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/LiteOS-M\345\271\263\345\217\260dump\347\263\273\347\273\237\345\261\236\346\200\247\350\276\223\345\207\272.png" deleted file mode 100755 index 883dccf82ef3ec1828893afa314a66ca2f23c421..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/LiteOS-M\345\271\263\345\217\260dump\347\263\273\347\273\237\345\261\236\346\200\247\350\276\223\345\207\272.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/UGO\350\247\204\345\210\231\344\277\241\346\201\257.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/UGO\350\247\204\345\210\231\344\277\241\346\201\257.png" deleted file mode 100644 index 152ef05469dc22252a9bbcf4107276a1d9f5e8b8..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/UGO\350\247\204\345\210\231\344\277\241\346\201\257.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/UIButton\347\202\271\345\207\273\346\225\210\346\236\234.gif" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/UIButton\347\202\271\345\207\273\346\225\210\346\236\234.gif" deleted file mode 100755 index 6db4ba71f91520200df7f59973e92ac2ef65f41b..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/UIButton\347\202\271\345\207\273\346\225\210\346\236\234.gif" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/ViewGroup\346\267\273\345\212\240view\345\256\236\344\276\213\346\225\210\346\236\234\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/ViewGroup\346\267\273\345\212\240view\345\256\236\344\276\213\346\225\210\346\236\234\345\233\276.png" deleted file mode 100755 index c4eee0a41d7cafb81c103c21d586c8bc0ec53e27..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/ViewGroup\346\267\273\345\212\240view\345\256\236\344\276\213\346\225\210\346\236\234\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/ril-adapter\346\250\241\345\235\227\346\236\266\346\236\204\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/ril-adapter\346\250\241\345\235\227\346\236\266\346\236\204\345\233\276.png" deleted file mode 100644 index 98917f4562e2a3beabda31362c4ff36ac8526e26..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/ril-adapter\346\250\241\345\235\227\346\236\266\346\236\204\345\233\276.png" and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/unnaming.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/unnaming.png deleted file mode 100755 index 6350269abdc028f9b1b31d544b78f380e58d7a57..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/unnaming.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001051782526.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001051782526.png deleted file mode 100755 index 0fc8c68bcb337ee51204c5b1c2ae9392ff445330..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001051782526.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001052582522.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001052582522.png deleted file mode 100755 index 165f22644ae3f7c09b8fa8c382f001348e253a67..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001052582522.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001052662559.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001052662559.png deleted file mode 100755 index f84c996217cb2da97b197580d1efd571bbae0f71..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001052662559.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001052782555.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001052782555.png deleted file mode 100755 index 07840086475ed440a052f79d59f8761a8a1e62f5..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001052782555.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001052942531.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001052942531.png deleted file mode 100755 index 646a47c2dd0c102749dff11b482493cb323a9e55..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001052942531.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001053207924.gif b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001053207924.gif deleted file mode 100755 index 6739188f22a6a9b9d76cb7af02f9e9c708735106..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001053207924.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001053247975.gif b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001053247975.gif deleted file mode 100755 index cd08beb8d1de75f196c6794a0c741b9998ec80b3..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001053247975.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001054101094.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001054101094.png deleted file mode 100755 index 57cd59a411623ac25836b4bd49221cc744db8d61..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001054101094.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001054421113.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001054421113.png deleted file mode 100755 index 1ba0a218017bbe98e2c21c8aa724900f766987ae..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001054421113.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001059334449.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001059334449.png deleted file mode 100755 index 7835524bcfb112f1f8d46596d5efff05f9689941..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001059334449.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001060200050.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001060200050.png deleted file mode 100755 index 047b5b30bdb1bc67829c96620603a6a4267a88d7..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001060200050.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001061889268.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001061889268.png deleted file mode 100755 index 2c9bf38fc2d15b946f579c6a9589562aab0e6519..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001061889268.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001062334618.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001062334618.png deleted file mode 100755 index 0ac7c0924e931695308a819010668327ed8a8680..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001062334618.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001062476933.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001062476933.png deleted file mode 100755 index 7e4b608bbffd7ae3becdc918abd6ff2b041888e5..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001062476933.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001062942690.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001062942690.png deleted file mode 100755 index c06de34e1a7e72dc162d09b1a4fa5fcd25cefab3..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001062942690.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001077724150.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001077724150.png deleted file mode 100755 index 2f6a9a6026d86bfcdd6462825334b450e481f563..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001077724150.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001077727032.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001077727032.png deleted file mode 100755 index 0077b263cf4c1ddfaf162e4ad01d2f8c2d58d13d..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001077727032.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001119924146.gif b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001119924146.gif deleted file mode 100644 index 9cd37267672d3bea422b98d95c413e26df330de8..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001119924146.gif and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001166643927.jpg b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001166643927.jpg deleted file mode 100644 index ace4cefd36637675f235df3cd596eca3ed218e6c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001166643927.jpg and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001181934155.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001181934155.png deleted file mode 100644 index 8a3b4daf5fdd4d78948488046bc404bc9ffedbbd..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001181934155.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001214727595.png b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001214727595.png deleted file mode 100644 index f5648acc87f23979f8078afcb2089ed3f834d3e5..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/zh-cn_image_0000001214727595.png and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\345\212\250\347\224\273\345\256\236\347\216\260\346\225\210\346\236\234\345\233\276.gif" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\345\212\250\347\224\273\345\256\236\347\216\260\346\225\210\346\236\234\345\233\276.gif" deleted file mode 100755 index 1eda8dc4c7f8fa35620640b5eee085b510e0f4ea..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\345\212\250\347\224\273\345\256\236\347\216\260\346\225\210\346\236\234\345\233\276.gif" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\345\214\205\347\256\241\347\220\206\345\255\220\347\263\273\347\273\237\346\241\206\346\236\266\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\345\214\205\347\256\241\347\220\206\345\255\220\347\263\273\347\273\237\346\241\206\346\236\266\345\233\276.png" deleted file mode 100755 index 330983e87925e92d7d27cbe7581993e81b812af7..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\345\214\205\347\256\241\347\220\206\345\255\220\347\263\273\347\273\237\346\241\206\346\236\266\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\345\216\273\347\224\265\350\260\203\347\224\250\346\227\266\345\272\217\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\345\216\273\347\224\265\350\260\203\347\224\250\346\227\266\345\272\217\345\233\276.png" deleted file mode 100644 index ca7bf2b79f42c07328a8342fd94b1c67013607c1..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\345\216\273\347\224\265\350\260\203\347\224\250\346\227\266\345\272\217\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\345\220\257\345\212\250\345\255\220\347\263\273\347\273\237\344\270\212\344\270\213\346\226\207.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\345\220\257\345\212\250\345\255\220\347\263\273\347\273\237\344\270\212\344\270\213\346\226\207.png" deleted file mode 100644 index e524495360609969011d8554d197ee04175e6b8f..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\345\220\257\345\212\250\345\255\220\347\263\273\347\273\237\344\270\212\344\270\213\346\226\207.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\345\233\276\347\211\2071.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\345\233\276\347\211\2071.png" deleted file mode 100755 index c9e74aefe365e0c103fbb6c128f731850d8258a4..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\345\233\276\347\211\2071.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\345\271\263\351\223\272\346\250\241\345\274\217\345\233\276\347\211\207\346\225\210\346\236\234\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\345\271\263\351\223\272\346\250\241\345\274\217\345\233\276\347\211\207\346\225\210\346\236\234\345\233\276.png" deleted file mode 100755 index a8ca6625852cfbce3d1cd156a52fd76a299084ad..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\345\271\263\351\223\272\346\250\241\345\274\217\345\233\276\347\211\207\346\225\210\346\236\234\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\345\272\224\347\224\250\345\220\257\345\212\250\346\265\201\347\250\213.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\345\272\224\347\224\250\345\220\257\345\212\250\346\265\201\347\250\213.png" deleted file mode 100755 index 2111dd19967c6f8d960a4e93891ddde7f8825225..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\345\272\224\347\224\250\345\220\257\345\212\250\346\265\201\347\250\213.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\346\217\222\344\273\266\344\276\235\350\265\226-(2).jpg" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\346\217\222\344\273\266\344\276\235\350\265\226-(2).jpg" deleted file mode 100755 index e73a82e4a5adc0d41adb548acc662f538afcd21c..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\346\217\222\344\273\266\344\276\235\350\265\226-(2).jpg" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\346\231\256\351\200\232\345\256\271\345\231\250\347\261\273\347\273\204\344\273\266\347\273\223\346\236\204.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\346\231\256\351\200\232\345\256\271\345\231\250\347\261\273\347\273\204\344\273\266\347\273\223\346\236\204.png" deleted file mode 100755 index a8954112f6b94d422bce3c1f445aa0de6c2499cc..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\346\231\256\351\200\232\345\256\271\345\231\250\347\261\273\347\273\204\344\273\266\347\273\223\346\236\204.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\346\231\256\351\200\232\347\273\204\344\273\266\346\240\221\347\273\223\346\236\204.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\346\231\256\351\200\232\347\273\204\344\273\266\346\240\221\347\273\223\346\236\204.png" deleted file mode 100755 index 276dfb6048e96d289c0074bd320ff7bfb4f1ab9d..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\346\231\256\351\200\232\347\273\204\344\273\266\346\240\221\347\273\223\346\236\204.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\346\260\264\345\271\263-\345\236\202\347\233\264\346\226\271\345\220\221\345\217\257\346\273\221\345\212\250\346\225\210\346\236\234\345\233\276.gif" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\346\260\264\345\271\263-\345\236\202\347\233\264\346\226\271\345\220\221\345\217\257\346\273\221\345\212\250\346\225\210\346\236\234\345\233\276.gif" deleted file mode 100755 index 1bd6879c1955f9131cd12ea17a2d8c0e52be6ab1..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\346\260\264\345\271\263-\345\236\202\347\233\264\346\226\271\345\220\221\345\217\257\346\273\221\345\212\250\346\225\210\346\236\234\345\233\276.gif" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\347\263\273\347\273\237\345\217\202\346\225\260\346\223\215\344\275\234\345\216\237\350\257\255.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\347\263\273\347\273\237\345\217\202\346\225\260\346\223\215\344\275\234\345\216\237\350\257\255.png" deleted file mode 100644 index 54c15c441dbb8f305ff4d6031b45c2eb8cb28d6c..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\347\263\273\347\273\237\345\217\202\346\225\260\346\223\215\344\275\234\345\216\237\350\257\255.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\347\273\204\344\273\266\346\240\221\347\273\223\346\236\204\347\244\272\346\204\217\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\347\273\204\344\273\266\346\240\221\347\273\223\346\236\204\347\244\272\346\204\217\345\233\276.png" deleted file mode 100755 index dc3dcd37c644867a2de9ba4209aaeeedcedecbe8..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\347\273\204\344\273\266\346\240\221\347\273\223\346\236\204\347\244\272\346\204\217\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\347\274\226\350\257\221\346\236\204\345\273\272\346\265\201\347\250\213.jpg" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\347\274\226\350\257\221\346\236\204\345\273\272\346\265\201\347\250\213.jpg" deleted file mode 100755 index 3e296c97b64e317bb92849d80588d5ab5419b31e..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\347\274\226\350\257\221\346\236\204\345\273\272\346\265\201\347\250\213.jpg" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\350\207\252\351\200\202\345\272\224\346\250\241\345\274\217\345\233\276\347\211\207\346\225\210\346\236\234\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\350\207\252\351\200\202\345\272\224\346\250\241\345\274\217\345\233\276\347\211\207\346\225\210\346\236\234\345\233\276.png" deleted file mode 100755 index 2e412ac913dc9b7bd4f1ff1729bfe017b02b4a7a..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\350\207\252\351\200\202\345\272\224\346\250\241\345\274\217\345\233\276\347\211\207\346\225\210\346\236\234\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\350\256\276\347\275\2562-2\347\275\221\346\240\274\345\271\266\346\267\273\345\212\2404\344\270\252button\347\273\204\344\273\266\350\277\233\350\241\214\345\270\203\345\261\200.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\350\256\276\347\275\2562-2\347\275\221\346\240\274\345\271\266\346\267\273\345\212\2404\344\270\252button\347\273\204\344\273\266\350\277\233\350\241\214\345\270\203\345\261\200.png" deleted file mode 100755 index 9d8039f69db3919dd3ddf716bc58d053948479ee..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\350\256\276\347\275\2562-2\347\275\221\346\240\274\345\271\266\346\267\273\345\212\2404\344\270\252button\347\273\204\344\273\266\350\277\233\350\241\214\345\270\203\345\261\200.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\350\277\220\350\241\214\346\212\245\351\224\231\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\350\277\220\350\241\214\346\212\245\351\224\231\345\233\276.png" deleted file mode 100644 index 015c38ba5516395527bcf6715535238f02b2bad9..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/device-dev/subsystems/figure/\350\277\220\350\241\214\346\212\245\351\224\231\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/AI\345\274\225\346\223\216\346\241\206\346\236\266.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/AI\345\274\225\346\223\216\346\241\206\346\236\266.png" deleted file mode 100644 index 40fce96c01fbe619d77851dffcb5c37b1468892f..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/AI\345\274\225\346\223\216\346\241\206\346\236\266.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/JS-FA\345\274\200\345\217\221\347\233\256\345\275\225.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/JS-FA\345\274\200\345\217\221\347\233\256\345\275\225.png" deleted file mode 100755 index 67e8ab4dfd26f4bbf7206d569831ed1f8351d9ad..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/JS-FA\345\274\200\345\217\221\347\233\256\345\275\225.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/OpenHarmony-LiteOS-A\345\206\205\346\240\270\346\236\266\346\236\204\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/OpenHarmony-LiteOS-A\345\206\205\346\240\270\346\236\266\346\236\204\345\233\276.png" deleted file mode 100755 index b2ff552d12a62fb207505772fc4c8cad29262022..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/OpenHarmony-LiteOS-A\345\206\205\346\240\270\346\236\266\346\236\204\345\233\276.png" and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/aafwk.png b/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/aafwk.png deleted file mode 100755 index 9c984fd666ab4ff18cdfb5e2035f06342249fd4a..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/aafwk.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/appexecfwk.png b/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/appexecfwk.png deleted file mode 100755 index e40a548d48af43430fed8599b30c4efcab60fa1d..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/appexecfwk.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/cesfwk_architecture_diagram.png b/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/cesfwk_architecture_diagram.png deleted file mode 100755 index c43dc2dc5c9fe130d669f0e8a5dfc27ff1faf418..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/cesfwk_architecture_diagram.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/dms-architecture_zh.png b/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/dms-architecture_zh.png deleted file mode 100644 index 588c33751dff097e9a8bb9b21d731a1ca1633ffd..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/dms-architecture_zh.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/page-ability-lifecycle-callbacks.png b/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/page-ability-lifecycle-callbacks.png deleted file mode 100755 index 4c94556b5c2516ad2978a9a31d833cfb2cf3dd01..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/page-ability-lifecycle-callbacks.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/page-ability-lifecycle.png b/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/page-ability-lifecycle.png deleted file mode 100755 index d4fff2a49bf103cb5d8763f271c847fc1b711723..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/page-ability-lifecycle.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/service-ability-lifecycle-callbacks.jpg b/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/service-ability-lifecycle-callbacks.jpg deleted file mode 100755 index d046627239c89c1ce44450f1db3e8dd623974514..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/service-ability-lifecycle-callbacks.jpg and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/service-ability-lifecycle.png b/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/service-ability-lifecycle.png deleted file mode 100755 index 66c11ca4db7900696c064461cb7f774bfcd48d49..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/service-ability-lifecycle.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_architecture-of-telephony-subsystem.png b/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_architecture-of-telephony-subsystem.png deleted file mode 100755 index a7de4844d182c5214de31a389fb084ea5552a99e..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_architecture-of-telephony-subsystem.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_image_0000001077953992.png b/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_image_0000001077953992.png deleted file mode 100755 index 128187aacfa540846172eac7d4ff47a3c2a31291..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_image_0000001077953992.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_image_0000001079026550.png b/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_image_0000001079026550.png deleted file mode 100755 index 99f14c85aa9d185ceb02bd2c376462e84629d897..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_image_0000001079026550.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_image_0000001079207198.png b/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_image_0000001079207198.png deleted file mode 100755 index c4069d0870d67b6b5eaefa1fdd426975cd5224b2..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_image_0000001079207198.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_image_0000001106694563.png b/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_image_0000001106694563.png deleted file mode 100755 index 2f6a9a6026d86bfcdd6462825334b450e481f563..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_image_0000001106694563.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_image_0000001111659738.png b/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_image_0000001111659738.png deleted file mode 100755 index 60179a923ded99ae33c2859f30570a7d5d95a3a8..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_image_0000001111659738.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_image_0000001115748088.png b/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_image_0000001115748088.png deleted file mode 100644 index 294f37c9dd23790348079f175b54d0fac58b8abf..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_image_0000001115748088.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_image_0000001115748590.png b/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_image_0000001115748590.png deleted file mode 100644 index b72003f5221553d66ae4b4183f92bcfcac595bc2..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_image_0000001115748590.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_image_0000001115819528.png b/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_image_0000001115819528.png deleted file mode 100755 index ded7f8ca0f8aa1f9bfb51a38ad37a21fed16ced9..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_image_0000001115819528.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_image_0000001162062837.png b/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_image_0000001162062837.png deleted file mode 100644 index 0cbd2f49d8ed4e7b24e1f8fdc0ba971c1fcb04f5..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_image_0000001162062837.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_image_0000001162307895.png b/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_image_0000001162307895.png deleted file mode 100755 index b1d4a9fc4a69c1b4af9fa42ae5b0d4a47f4afb74..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_image_0000001162307895.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_image_0000001162757669.png b/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_image_0000001162757669.png deleted file mode 100755 index c39795967bcd7b5ffbf611b16dd9c3c6778ebd9c..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_image_0000001162757669.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_image_ark_frontend.png b/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_image_ark_frontend.png deleted file mode 100644 index e8e9951f3f2dc5b566a3d9b36229def46c41aecd..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_image_ark_frontend.png and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_image_ark_runtime.png b/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_image_ark_runtime.png deleted file mode 100644 index 2f78e5f3e10a2b99c60ca31dc0f23ae5fb89f7a6..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/zh-cn_image_ark_runtime.png and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/\345\205\250\347\220\203\345\214\226\345\255\220\347\263\273\347\273\237\346\236\266\346\236\204\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/\345\205\250\347\220\203\345\214\226\345\255\220\347\263\273\347\273\237\346\236\266\346\236\204\345\233\276.png" deleted file mode 100755 index 0d8c52645dbee83554bfbf7fb8c5bf46bb7e3269..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/\345\205\250\347\220\203\345\214\226\345\255\220\347\263\273\347\273\237\346\236\266\346\236\204\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/\345\210\206\345\270\203\345\274\217\346\226\207\344\273\266\345\255\220\347\263\273\347\273\237\346\236\266\346\236\204\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/\345\210\206\345\270\203\345\274\217\346\226\207\344\273\266\345\255\220\347\263\273\347\273\237\346\236\266\346\236\204\345\233\276.png" deleted file mode 100644 index e3763b766aff5cf1c80c31a0ea17c527a9f70a8f..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/\345\210\206\345\270\203\345\274\217\346\226\207\344\273\266\345\255\220\347\263\273\347\273\237\346\236\266\346\236\204\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/\345\233\276\345\275\242\345\255\220\347\263\273\347\273\237\346\236\266\346\236\204\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/\345\233\276\345\275\242\345\255\220\347\263\273\347\273\237\346\236\266\346\236\204\345\233\276.png" deleted file mode 100644 index 85ea43ab9df6b54d41e6703876c2da05f082f001..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/\345\233\276\345\275\242\345\255\220\347\263\273\347\273\237\346\236\266\346\236\204\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/\345\252\222\344\275\223\345\255\220\347\263\273\347\273\237\346\236\266\346\236\204\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/\345\252\222\344\275\223\345\255\220\347\263\273\347\273\237\346\236\266\346\236\204\345\233\276.png" deleted file mode 100644 index 6cacc7470fc2c1e82e7d5306f9a5cf0d9fd5e792..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/\345\252\222\344\275\223\345\255\220\347\263\273\347\273\237\346\236\266\346\236\204\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/\345\255\220\347\263\273\347\273\237\346\236\266\346\236\204\345\233\276-5.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/\345\255\220\347\263\273\347\273\237\346\236\266\346\236\204\345\233\276-5.png" deleted file mode 100755 index 988f445370dc2b288bbbe5ec3b36f8bbdf411f5c..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/\345\255\220\347\263\273\347\273\237\346\236\266\346\236\204\345\233\276-5.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/\345\255\220\347\263\273\347\273\237\346\236\266\346\236\204\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/\345\255\220\347\263\273\347\273\237\346\236\266\346\236\204\345\233\276.png" deleted file mode 100755 index f4db33be77173dd074bb6a5ae045a9c9a5a5c82a..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/\345\255\220\347\263\273\347\273\237\346\236\266\346\236\204\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/\347\224\265\346\272\220\347\256\241\347\220\206\345\255\220\347\263\273\347\273\237\346\236\266\346\236\204\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/\347\224\265\346\272\220\347\256\241\347\220\206\345\255\220\347\263\273\347\273\237\346\236\266\346\236\204\345\233\276.png" deleted file mode 100755 index 698bf197806b9e260b6919e4eaeff2a9900b2d50..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/\347\224\265\346\272\220\347\256\241\347\220\206\345\255\220\347\263\273\347\273\237\346\236\266\346\236\204\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/\351\251\261\345\212\250\345\256\211\350\243\205\351\203\250\347\275\262\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/\351\251\261\345\212\250\345\256\211\350\243\205\351\203\250\347\275\262\345\233\276.png" deleted file mode 100644 index ee364fd6ea0a34ec5b7b79f96556b59afe012445..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/\351\251\261\345\212\250\345\256\211\350\243\205\351\203\250\347\275\262\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/\351\251\261\345\212\250\346\236\266\346\236\204\345\233\276.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/\351\251\261\345\212\250\346\236\266\346\236\204\345\233\276.png" deleted file mode 100644 index 4d8f23c4ac0bc523de713c0df43fb6bf0bbd517f..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/\351\251\261\345\212\250\346\236\266\346\236\204\345\233\276.png" and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/\351\251\261\345\212\250\346\241\206\346\236\266\344\272\244\344\272\222\346\265\201\347\250\213.png" "b/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/\351\251\261\345\212\250\346\241\206\346\236\266\344\272\244\344\272\222\346\265\201\347\250\213.png" deleted file mode 100644 index 0a4e738184f3feeb1ff0f71ec36518470e92032f..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/docs/zh-cn/readme/figures/\351\251\261\345\212\250\346\241\206\346\236\266\344\272\244\344\272\222\346\265\201\347\250\213.png" and /dev/null differ diff --git a/website/docs/.vuepress/public/images/docs/zh-cn/readme/public_sys-resources/icon-note.gif b/website/docs/.vuepress/public/images/docs/zh-cn/readme/public_sys-resources/icon-note.gif deleted file mode 100755 index 6314297e45c1de184204098efd4814d6dc8b1cda..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/docs/zh-cn/readme/public_sys-resources/icon-note.gif and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/readme/figures/OpenHarmony\345\252\222\344\275\223\346\236\266\346\236\204\345\233\276.png" "b/website/docs/.vuepress/public/images/readme/figures/OpenHarmony\345\252\222\344\275\223\346\236\266\346\236\204\345\233\276.png" deleted file mode 100644 index 37aa82a4d0e47158908f37080e1623dc8b3a5e6a..0000000000000000000000000000000000000000 Binary files "a/website/docs/.vuepress/public/images/readme/figures/OpenHarmony\345\252\222\344\275\223\346\236\266\346\236\204\345\233\276.png" and /dev/null differ diff --git a/website/docs/.vuepress/public/images/readme/figures/dp-architecture_zh.png b/website/docs/.vuepress/public/images/readme/figures/dp-architecture_zh.png deleted file mode 100755 index 58009df7a4cbee4664985e24a0f0f00ed60f88ed..0000000000000000000000000000000000000000 Binary files a/website/docs/.vuepress/public/images/readme/figures/dp-architecture_zh.png and /dev/null differ diff --git "a/website/docs/.vuepress/public/images/readme/figures/\347\224\265\346\272\220\347\256\241\347\220\206\345\255\220\347\263\273\347\273\237\346\236\266\346\236\204\345\233\276.png" "b/website/docs/.vuepress/public/images/readme/figures/\347\224\265\346\272\220\347\256\241\347\220\206\345\255\220\347\263\273\347\273\237\346\236\266\346\236\204\345\233\276.png" index da1c6d779d3e7de861385f1f82daa84b79e34f0e..698bf197806b9e260b6919e4eaeff2a9900b2d50 100644 Binary files "a/website/docs/.vuepress/public/images/readme/figures/\347\224\265\346\272\220\347\256\241\347\220\206\345\255\220\347\263\273\347\273\237\346\236\266\346\236\204\345\233\276.png" and "b/website/docs/.vuepress/public/images/readme/figures/\347\224\265\346\272\220\347\256\241\347\220\206\345\255\220\347\263\273\347\273\237\346\236\266\346\236\204\345\233\276.png" differ diff --git a/website/docs/.vuepress/search/for_es.js b/website/docs/.vuepress/search/for_es.js new file mode 100644 index 0000000000000000000000000000000000000000..ed539be0597ffc08d95cd720144f2226c2b3ae54 --- /dev/null +++ b/website/docs/.vuepress/search/for_es.js @@ -0,0 +1,224 @@ +const envs = require("../../../utils/env"); +const fs = require("fs"); +const path = require("path"); +const readline = require("readline"); +const yamljs = require("yamljs"); +const request = require("request"); +const MarkdownIt = require("markdown-it"); +const plaintext = require("markdown-it-plain-text"); +const snooze = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); + +function lf_exclude (fullpath) { + ppath = fullpath.split('\\').join('/') + if (ppath.indexOf('/extras/') != -1 || ppath.indexOf('/_posts/') != -1 || ppath.indexOf('/.vuepress/') != -1) { + console.log(`ingored : ${ppath}`) + return true + } + return false +} + +async function lstFile (dir, cb) { + let flst = []; + let arr = fs.readdirSync(dir); + for (let item of arr) { + let fullpath = path.join(dir, item); + let stats = fs.statSync(fullpath); + let isexclude = fullpath + if (stats.isDirectory()) { + isexclude += '/' + } + if (lf_exclude(isexclude)) + continue + + if (stats.isDirectory()) { + let clst = await lstFile(fullpath, cb); + flst.push(...clst); + } else { + if (cb) { + await snooze(1); + await cb(fullpath); + } else { + flst.push(fullpath); + } + } + } + return flst; +} + +function SearchDb (dstdir, esApi, domainBase) { + this.root = dstdir; + this.domainBase = domainBase; + this.esApi = esApi; + this.md = new MarkdownIt(); + this.md.use(plaintext); + + this.total = 0; + this.suc = 0; + this.ingored = 0; + this.failed = 0; +} + +SearchDb.prototype.startup = async function () { + let tlst = await lstFile(rootPath, this.genSearchElement.bind(this)); + return tlst; +}; + +SearchDb.prototype.genSearchElement = async function (fullpath) { + let rpath = path.relative(this.root, fullpath); + let filename = path.basename(rpath); + let dirname = path.dirname(rpath); + let ext = path.extname(filename); + this.total += 1; + if (ext.toLowerCase() !== ".md") { + // console.log(`ingored file ${dirname}/${filename}`); + this.ingored += 1; + return; + } + + try { + let txt = fs.readFileSync(fullpath).toString("utf-8"); + let p1 = txt.indexOf("---"); + let p2 = txt.indexOf("---", p1 + 3); + let ytxt = txt.slice(p1, p2); + let content = txt.slice(p2 + 3); + // const md = new MarkdownIt() + // md.use(plaintext) + // test yaml + let yamlobj = yamljs.parse(ytxt); + if (!yamlobj.title || !yamlobj.permalink) { + console.log( + `fill:${dirname}, ${filename}, title:${yamlobj.title}, result:yaml error` + ); + this.failed += 1; + return; + } + this.md.render(content); + content = this.md.plainText; + await this.postToEs(dirname, filename, yamlobj, content); + } catch (err) { + this.failed += 1; + console.log( + `fill:${dirname}, ${filename}, title:${yamlobj.title + }, result:${JSON.stringify(err)}` + ); + } +}; + +SearchDb.prototype.postToEs = async function ( + dirname, + filename, + yamlobj, + content +) { + let tt = + yamlobj.categories && yamlobj.categories.length > 0 + ? yamlobj.categories.concat([yamlobj.title]).join("/") + : ""; + // let tt = yamlobj.categories&&yamlobj.categories.length>0?yamlobj.categories.join('/'):'' + let articleList = [ + { + title: yamlobj.title, + breadLine: tt, + content, + author: "anonymous", + wordCount: content.length, + publishDate: yamlobj.date, + briefIntroduction: "", + url: `${this.domainBase}${yamlobj.permalink}`, + }, + ]; + const _this = this; + return new Promise((resolve, reject) => { + request.post( + { + url: this.esApi, + timeout: 1500, + json: true, + body: { articleList }, + }, + function (error, response, body) { + if (!error && response.statusCode == 200) { + console.log( + `fill:${dirname}, ${filename}, title:${yamlobj.title + }, result:${JSON.stringify(body)}` + ); + _this.suc += 1; + resolve(0); + } else { + _this.failed += 1; + console.log( + `fill:${dirname}, ${filename}, title:${yamlobj.title}, result:${error}` + ); + resolve(-1); + } + } + ); + }); +}; + +SearchDb.prototype.checkDb = async function (keywords) { + let url = `${envs.SEARCH_QUERY}?keyWord=${keywords}`; + return new Promise((resolve, reject) => { + request(url, function (error, response, body) { + if (!error && response.statusCode == 200) { + console.log(body); + resolve(body); + } else { + console.log(error); + reject(error); + } + }); + }); +}; + +let rootPath = path.join(__dirname, "../../../docs"); +let domainBase = `${process.env.DOCUMENT_URL}`; +let esApi = `${process.env.SEARCH_ENTRY}`; + +const args = process.argv.slice(2); +if (args.length >= 1) { + rootPath = path.join("./", args[0]); +} + +if (args.length >= 2) { + esApi = args[1]; +} + +if (args.length >= 3) { + domainBase = args[2]; +} + +console.log(`would build es with : ${rootPath}, domainBase ${domainBase}`); +let sdb = new SearchDb(rootPath, esApi, domainBase); +sdb + .startup() + .then((res) => { + console.log( + `build for es over:total:${sdb.total}, ingored:${sdb.ingored}, suc:${sdb.suc}, failed:${sdb.failed}` + ); + }) + .catch((err) => { + console.log( + `build for es over:total:${sdb.total}, ingored:${sdb.ingored}, suc:${sdb.suc}, failed:${sdb.failed}` + ); + console.log(`with error, ${JSON.stringify(err)}`); + }); + +// sdb.checkDb('PMC').then(res=>{ + +// }).catch(err=>{ + +// }) + +// const rl = readline.createInterface({ +// input: process.stdin, +// output: process.stdout +// }); + +// // ask user for the anme input +// rl.question(`What's your name? `, (name) => { + +// if(name == 'q') +// rl.close() + +// }); diff --git "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/01.\344\272\206\350\247\243OpenHarmony\345\274\200\346\272\220\351\241\271\347\233\256.md" "b/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/01.\344\272\206\350\247\243OpenHarmony\345\274\200\346\272\220\351\241\271\347\233\256.md" deleted file mode 100644 index db0d6f584555936ee8559e8250fb9913debf912d..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/01.\344\272\206\350\247\243OpenHarmony\345\274\200\346\272\220\351\241\271\347\233\256.md" +++ /dev/null @@ -1,407 +0,0 @@ ---- -title: 了解OpenHarmony开源项目 -permalink: /pages/010101 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:18 ---- -# OpenHarmony开源项目 - -- [项目介绍](#section1270210396435) -- [技术架构](#section2502124574318) -- [技术特性](#section12212842173518) -- [系统类型](#section145241459142416) -- [详细特征](#section25831825174419) -- [快速入门](#section44681652104210) -- [代码仓地址](#section107651249181914) -- [开发者文档](#section21031470109) -- [源码下载](#section39011923144212) -- [如何参与](#section19611528174215) -- [许可协议](#section1245517472115) -- [联系方式](#section61728335424) - -[View English](https://gitee.com/openharmony/docs/blob/master/en/OpenHarmony-Overview.md) - -## 项目介绍 - -OpenHarmony是由开放原子开源基金会(OpenAtom Foundation)孵化及运营的开源项目,目标是面向全场景、全连接、全智能时代,基于开源的方式,搭建一个智能终端设备操作系统的框架和平台,促进万物互联产业的繁荣发展。 - -## 技术架构 - -OpenHarmony整体遵从分层设计,从下向上依次为:内核层、系统服务层、框架层和应用层。系统功能按照“系统 \> 子系统 \> 组件”逐级展开,在多设备部署场景下,支持根据实际需求裁剪某些非必要的组件。OpenHarmony技术架构如下所示: - -![](https://gitee.com/openharmony/docs/raw/master/zh-cn/figures/1.png) - -**内核层** - -- 内核子系统:采用多内核(Linux内核或者LiteOS)设计,支持针对不同资源受限设备选用适合的OS内核。内核抽象层(KAL,Kernel Abstract Layer)通过屏蔽多内核差异,对上层提供基础的内核能力,包括进程/线程管理、内存管理、文件系统、网络管理和外设管理等。 - -- 驱动子系统:驱动框架(HDF)是系统硬件生态开放的基础,提供统一外设访问能力和驱动开发、管理框架。 - - -**系统服务层** - -系统服务层是OpenHarmony的核心能力集合,通过框架层对应用程序提供服务。该层包含以下几个部分: - -- 系统基本能力子系统集:为分布式应用在多设备上的运行、调度、迁移等操作提供了基础能力,由分布式软总线、分布式数据管理、分布式任务调度、公共基础库、多模输入、图形、安全、AI等子系统组成。 - -- 基础软件服务子系统集:提供公共的、通用的软件服务,由事件通知、电话、多媒体、DFX(Design For X) 等子系统组成。 - -- 增强软件服务子系统集:提供针对不同设备的、差异化的能力增强型软件服务,由智慧屏专有业务、穿戴专有业务、IoT专有业务等子系统组成。 - -- 硬件服务子系统集:提供硬件服务,由位置服务、生物特征识别、穿戴专有硬件服务、IoT专有硬件服务等子系统组成。 - - -根据不同设备形态的部署环境,基础软件服务子系统集、增强软件服务子系统集、硬件服务子系统集内部可以按子系统粒度裁剪,每个子系统内部又可以按功能粒度裁剪。 - -**框架层** - -框架层为应用开发提供了C/C++/JS等多语言的用户程序框架和Ability框架,适用于JS语言的JS UI框架,以及各种软硬件服务对外开放的多语言框架API。根据系统的组件化裁剪程度,设备支持的API也会有所不同。 - -**应用层** - -应用层包括系统应用和第三方非系统应用。应用由一个或多个FA(Feature Ability)或PA(Particle Ability)组成。其中,FA有UI界面,提供与用户交互的能力;而PA无UI界面,提供后台运行任务的能力以及统一的数据访问抽象。基于FA/PA开发的应用,能够实现特定的业务功能,支持跨设备调度与分发,为用户提供一致、高效的应用体验。 - -## 技术特性 - -1. **硬件互助,资源共享** - - 主要通过下列模块达成 - - - 分布式软总线 - - 分布式软总线是多设备终端的统一基座,为设备间的无缝互联提供了统一的分布式通信能力,能够快速发现并连接设备,高效地传输任务和数据。 - - - - 分布式数据管理 - - 分布式数据管理位于基于分布式软总线之上的能力,实现了应用程序数据和用户数据的分布式管理。用户数据不再与单一物理设备绑定,业务逻辑与数据存储分离,应用跨设备运行时数据无缝衔接,为打造一致、流畅的用户体验创造了基础条件 - - - - 分布式任务调度 - - 分布式任务调度基于分布式软总线、分布式数据管理、分布式Profile等技术特性,构建统一的分布式服务管理(发现、同步、注册、调用)机制,支持对跨设备的应用进行远程启动、远程调用、绑定/解绑、以及迁移等操作,能够根据不同设备的能力、位置、业务运行状态、资源使用情况并结合用户的习惯和意图,选择最合适的设备运行分布式任务 - - - - 设备虚拟化 - - 分布式设备虚拟化平台可以实现不同设备的资源融合、设备管理、数据处理,将周边设备作为手机能力的延伸,共同形成一个超级虚拟终端。 - - -2. **一次开发,多端部署** - - OpenHarmony提供用户程序框架、Ability框架以及UI框架,能够保证开发的应用在多终端运行时保证一致性。一次开发、多端部署。 - - 多终端软件平台API具备一致性,确保用户程序的运行兼容性。 - - - 支持在开发过程中预览终端的能力适配情况(CPU/内存/外设/软件资源等)。 - - 支持根据用户程序与软件平台的兼容性来调度用户呈现。 - -3. **统一OS,弹性部署** - - OpenHarmony通过组件化和组件弹性化等设计方法,做到硬件资源的可大可小,在多种终端设备间,按需弹性部署,全面覆盖了ARM、RISC-V、x86等各种CPU,从百KiB到GiB级别的RAM。 - - -## 系统类型 - -OpenHarmony支持如下几种系统类型: - -- 轻量系统(mini system) - - 面向MCU类处理器例如Arm Cortex-M、RISC-V 32位的设备,硬件资源极其有限,支持的设备最小内存为128KiB,可以提供多种轻量级网络协议,轻量级的图形框架,以及丰富的IOT总线读写部件等。可支撑的产品如智能家居领域的连接类模组、传感器设备、穿戴类设备等。 - -- 小型系统(small system) - - 面向应用处理器例如Arm Cortex-A的设备,支持的设备最小内存为1MiB,可以提供更高的安全能力、标准的图形框架、视频编解码的多媒体能力。可支撑的产品如智能家居领域的IP Camera、电子猫眼、路由器以及智慧出行域的行车记录仪等。 - -- 标准系统(standard system) - - 面向应用处理器例如Arm Cortex-A的设备,支持的设备最小内存为128MiB,可以提供增强的交互能力、3D GPU以及硬件合成能力、更多控件以及动效更丰富的图形能力、完整的应用框架。可支撑的产品如高端的冰箱显示屏。 - - -## 详细特征 - -在介绍OpenHarmony特性前,需要先明确以下两个基本概念: - -- 子系统 - - OpenHarmony整体遵从分层设计,从下向上依次为:内核层、系统服务层、框架层和应用层。系统功能按照“系统 \> 子系统 \> 组件”逐级展开,在多设备部署场景下,支持根据实际需求裁剪某些非必要的组件。子系统是一个逻辑概念,它具体由对应的组件构成。 - -- 组件 - - 对子系统的进一步拆分,可复用的软件单元,它包含源码、配置文件、资源文件和编译脚本;能独立构建,以二进制方式集成,具备独立验证能力的二进制单元。 - - -以下为OpenHarmony中相关的子系统简介,详细介绍见子系统Readme文档,入口:[https://gitee.com/openharmony/docs/tree/master/zh-cn/readme](https://gitee.com/openharmony/docs/tree/master/zh-cn/readme)。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

子系 统

-

简 介

-

适用范围

-

内核

-

支持适用于嵌入式设备及资源受限设备,具有小体积、高性能、低功耗等特征的LiteOS内核;支持基于linux kernel演进的适用于标准系统的linux内核。

-

小型系统

-

标准系统

-

分布式文件

-

提供本地同步JS文件接口。

-

标准系统

-

图形

-

主要包括UI组件、布局、动画、字体、输入事件、窗口管理、渲染绘制等模块,构建基于轻量OS应用框架满足硬件资源较小的物联网设备或者构建基于标准OS的应用框架满足富设备(如平板和轻智能机等)的OpenHarmony系统应用开发。

-

所有系统

-

驱动

-

OpenHarmony驱动子系统采用C面向对象编程模型构建,通过平台解耦、内核解耦,兼容不同内核,提供了归一化的驱动平台底座,旨在为开发者提供更精准、更高效的开发环境,力求做到一次开发,多系统部署。

-

所有系统

-

电源管理服务

-

电源管理服务子系统提供如下功能:重启系统;管理休眠运行锁;系统电源状态管理和查询;充电和电池状态查询和上报;显示亮灭屏状态管理,包括显示亮度调节。

-

标准系统

-

泛Sensor服务

-

泛Sensor中包含传感器和小器件,传感器用于侦测环境中所发生事件或变化,并将此消息发送至其他电子设备,小器件用于向外传递信号的设备,包括马达和LED灯,对开发者提供控制马达振动和LED灯开关的能力。

-

小型系统

-

多模输入

-

OpenHarmony旨在为开发者提供NUI(Natural User Interface)的交互方式,有别于传统操作系统的输入,在OpenHarmony上,我们将多种维度的输入整合在一起,开发者可以借助应用程序框架、系统自带的UI组件或API接口轻松地实现具有多维、自然交互特点的应用程序。具体来说,多模输入子系统目前支持传统的输入交互方式,例如按键和触控。

-

标准系统

-

启动恢复

-

启动恢复负责在内核启动之后,应用启动之前的操作系统中间层的启动。并提供系统属性查询、修改及设备恢复出厂设置的功能。

-

所有系统

-

升级服务

-

可支持OpenHarmony设备的OTA(Over The Air)升级。

-

标准系统

-

帐号

-

支持在端侧对接厂商云帐号应用,提供分布式帐号登录状态查询和更新的管理能力。

-

标准系统

-

编译构建

-

编译构建子系统提供了一个基于Gn和ninja的编译构建框架。

-

所有系统

-

测试

-

开发过程采用测试驱动开发模式,开发者基于系统新增特性可以通过开发者自己开发用例保证,对于系统已有特性的修改,也可通过修改项目中原有的测试用例保证,开发者测试旨在帮助开发者在开发阶段就能开发出高质量代码。

-

所有系统

-

数据管理

-

数据管理支持应用本地数据管理和分布式数据管理:

-
  • 支持应用本地数据管理,包括轻量级偏好数据库,关系型数据库。
  • 支持分布式数据服务,为应用程序提供不同设备间数据库数据分布式的能力。
-

标准系统

-

语言编译运行时

-

语言运行时提供了JS、C/C++语言程序的编译、执行环境,提供支撑运行时的基础库,以及关联的API接口、编译器和配套工具。

-

所有系统

-

分布式任务调度

-

提供系统服务的启动、注册、查询及管理能力。

-

所有系统

-

JS UI框架

-

JS UI框架是OpenHarmony UI开发框架,支持类Web范式编程。

-

所有系统

-

媒体

-

提供音频、视频、相机等简单有效的媒体组件开发接口,使得应用开发者轻松使用系统的多媒体资源。

-

所有系统

-

事件通知

-

公共事件管理实现了订阅、退订、发布、接收公共事件(例如亮灭屏事件、USB插拔事件)的能力。

-

标准系统

-

杂散软件服务

-

提供设置时间的能力。

-

标准系统

-

用户程序框架

-

提供包安装、卸载、运行及管理能力。

-

所有系统

-

电话服务

-

提供SIM卡、搜网、蜂窝数据、蜂窝通话、短彩信等蜂窝移动网络基础通信能力,可管理多类型通话和数据网络连接,为应用开发者提供便捷一致的通信API。

-

标准系统

-

公共基础类库

-

公共基础库存放OpenHarmony通用的基础组件。这些基础组件可被OpenHarmony各业务子系统及上层应用所使用。

-

所有系统

-

研发工具链

-

提供设备连接调试器hdc;提供了性能跟踪能力和接口;提供了性能调优框架,旨在为开发者提供一套性能调优平台,可以用来分析内存、性能等问题。

-

标准系统

-

分布式软总线

-

分布式软总线旨在为OpenHarmony系统提供跨进程或跨设备的通信能力,主要包含软总线和进程间通信两部分。其中,软总线为应用和系统提供近场设备间分布式通信的能力,提供不区分通信方式的设备发现,连接,组网和传输功能;而进程间通信则提供不区分设备内或设备间的进程间通信能力。

-

所有系统

-

XTS

-

XTS是OpenHarmony生态认证测试套件的集合,当前包括acts(application compatibility test suite)应用兼容性测试套,后续会拓展dcts(device compatibility test suite)设备兼容性测试套等。

-

所有系统

-

系统应用

-

系统应用提供了OpenHarmony标准版上的部分系统应用,如桌面、SystemUI、设置等应用,为开发者提供了构建标准版应用的具体实例,这些应用支持在所有标准版系统的设备上使用。

-

标准系统

-

DFX

-

DFX是OpenHarmony非功能属性能力,包含日志系统、应用和系统事件日志接口、事件日志订阅服务、故障信息生成采集等功能。

-

所有系统

-

全球化

-

当OpenHarmony设备或应用在全球不同区域使用时,系统和应用需要满足不同市场用户关于语言、文化习俗的需求。全球化子系统提供支持多语言、多文化的能力,包括资源管理能力和国际化能力。

-

所有系统

-

安全

-

安全子系统包括系统安全、数据安全、应用安全等模块,为OpenHarmony提供了保护系统和和用户数据的能力。安全子系统当前开源的功能,包括应用完整性保护、应用权限管理、设备认证、密钥管理服务。

-

所有系统

-
- -## 快速入门 - -入口:[/pages/extra/eec566/](/pages/extra/eec566/) - -## 代码仓地址 - -OpenHarmony主库组织地址:[https://gitee.com/openharmony](https://gitee.com/openharmony) - -OpenHarmonySIG组织地址:[https://gitee.com/openharmony-sig](https://gitee.com/openharmony-sig) - -OpenHarmony三方库组织地址:[https://gitee.com/openharmony-tpc](https://gitee.com/openharmony-tpc) - -OpenHarmony归档组织地址:[https://gitee.com/openharmony-retired](https://gitee.com/openharmony-retired) - -## 开发者文档 - -[访问官网](https://www.openharmony.cn/) - -简体中文:[OpenHarmony开发者文档](https://gitee.com/openharmony/docs/tree/master/zh-cn) - -[English Version](https://gitee.com/openharmony/docs/tree/master/en) - -## 源码下载 - -获取OpenHarmony源码:[下载说明](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/get-code/sourcecode-acquire.md) - -## 如何参与 - -参与社区:[社区介绍](https://gitee.com/openharmony/community/blob/master/README.md) - -参与贡献:[如何贡献](https://gitee.com/openharmony/docs/blob/master/zh-cn/contribute/%E5%8F%82%E4%B8%8E%E8%B4%A1%E7%8C%AE.md) - -## 许可协议 - -OpenHarmony主要遵循Apache License V2.0协议,详情请参考各代码仓LICENSE声明。 - -OpenHarmony引用三方开源软件及许可证说明,参考[第三方开源软件说明](https://gitee.com/openharmony/docs/blob/master/zh-cn/contribute/%E7%AC%AC%E4%B8%89%E6%96%B9%E5%BC%80%E6%BA%90%E8%BD%AF%E4%BB%B6%E5%8F%8A%E8%AE%B8%E5%8F%AF%E8%AF%81%E8%AF%B4%E6%98%8E.md)。 - -## 联系方式 - -网站: - -[https://openharmony.gitee.com](https://openharmony.gitee.com/) - -邮箱: - -contact@openharmony.io - diff --git "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/01.\345\206\205\346\240\270\345\255\220\347\263\273\347\273\237.md" "b/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/01.\345\206\205\346\240\270\345\255\220\347\263\273\347\273\237.md" deleted file mode 100644 index 515002a08f240aa16d087d4c01a8b20285cd0127..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/01.\345\206\205\346\240\270\345\255\220\347\263\273\347\273\237.md" +++ /dev/null @@ -1,245 +0,0 @@ ---- -title: 内核子系统 -permalink: /pages/01010201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:18 ---- -# 内核子系统 - -- [简介](#section11660541593) -- [LiteOS](#section6253122153515) -- [Linux](#section143373618411) -- [目录](#section21571344112) -- [约束](#section19647171710417) -- [使用](#section1393789267) - - [LiteOS使用说明](#section118811457303) - - [linux使用说明](#section1352114469620) - -- [构建说明](#section19369206113115) -- [相关仓](#section27639463106) - -## 简介 - -OpenHarmony针对不同量级的系统,分别使用了不同形态的内核,分别为LiteOS和Linux。在轻量系统、小型系统可以选用LiteOS;在小型系统和标准系统上可以选用Linux。 - - - - - - - - - - - - - - - - - -

系统级别

-

轻量系统

-

小型系统

-

标准系统

-

LiteOS

-

-

-

×

-

Linux

-

×

-

-

-
- -## LiteOS - -OpenHarmonyLiteOS内核是面向IoT领域的实时操作系统内核,它同时具备RTOS轻快和Linux易用的特点。 - -OpenHarmonyLiteOS内核主要包括进程和线程调度、内存管理、IPC机制、timer管理等内核基本功能。 - -OpenHarmonyLiteOS内核的源代码分为 kernel\_liteos\_a 和 kernel\_liteos\_m 这2个代码仓库,其中kernel\_liteos\_a主要针对小型系统(small system)和标准系统(standard system),而kernel\_liteos\_m则主要针对轻量系统(mini system),下面主要针对kernel\_liteos\_a代码仓库进行介绍。图1为OpenHarmony LiteOS-A内核架构图: - -**图 1** OpenHarmony LiteOS-A内核架构图 -![](/images/readme/figures/OpenHarmony-LiteOS-A内核架构图.png "OpenHarmony-LiteOS-A内核架构图") - -## Linux - -OpenHarmony的Linux内核基于开源Linux内核LTS **4.19.y / 5.10.y** 分支演进,在此基线基础上,回合CVE补丁及OpenHarmony特性,作为OpenHarmony Common Kernel基线。针对不同的芯片,各厂商合入对应的板级驱动补丁,完成对OpenHarmony的基线适配。 - -Linux社区LTS 4.19.y分支信息请查看[kernel官网](https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/log/?h=linux-4.19.y); - -Linux社区LTS 5.10.y分支信息请查看[kernel官网](https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/log/?h=linux-5.10.y)。 - -内核的Patch组成模块,在编译构建流程中,针对具体芯片平台,合入对应的架构驱动代码,进行编译对应的内核镜像。所有补丁来源均遵守GPL-2.0协议。 - -## 目录 - -``` -kernel/ -├── linux -│ ├── linux-4.19 # OpenHarmony linux-4.19 Common kernel -│ ├── linux-5.10 # OpenHarmony linux-5.10 Common kernel -│ ├── build -│ │ ├── BUILD.gn # 编译框架GN文件 -│ │ ├── kernel.mk # 内核编译文件 -│ │ └── ohos.build # 内核编译组件文件 -│ ├── patches -│ │ ├── linux-4.19 # linux-4.19 相关patch -│ │ │   └── hi3516dv300_patch -│ │ │   ├── hi3516dv300.patch # linux-4.19 hi3516dv300 SOC patch -│ │ │   └── hdf.patch # linux-4.19 hi3516dv300 hdf patch -│ │ └── linux-5.10 -│ │    └── hi3516dv300_patch -│ │    ├── hi3516dv300.patch # linux-5.10 hi3516dv300 SOC patch -│ │    └── hdf.patch # linux-5.10 hi3516dv300 hdf patch -│ └── config -│ ├── linux-4.19 -│ │   └── arch -│ │   └── arm -│ │   └── configs -│ │   ├── hi3516dv300_small_defconfig # 厂商Hisilicon对应的开源开发板Hi3516dv300小型系统的defconfig -│ │   ├── hi3516dv300_standard_defconfig # 厂商Hisilicon对应的开源开发板Hi3516dv300标准系统的defconfig -│ │   ├── small_common_defconfig # 小型系统的内核的common defconfig -│ │   └── standard_common_defconfig # 标准系统的内核的common defconfig -│ └── linux-5.10 -│ └── arch -│ └── arm -│ └── configs -│    ├── hi3516dv300_small_defconfig # 厂商Hisilicon对应的开源开发板Hi3516dv300小型系统的defconfig -│    ├── hi3516dv300_standard_defconfig # 厂商Hisilicon对应的开源开发板Hi3516dv300标准系统的defconfig -│    ├── small_common_defconfig # 小型系统的内核的common defconfig -│    └── standard_common_defconfig # 标准系统的内核的common defconfig -└── liteos_a # liteos内核基线代码 - ├── apps # 用户态的init和shell应用程序 - ├── arch # 体系架构的目录,如arm等 - │ └── arm # arm架构代码 - ├── bsd # freebsd相关的驱动和适配层模块代码引入,例如USB等 - ├── compat # 内核接口兼容性目录 - │ └── posix # posix相关接口 - ├── drivers # 内核驱动 - │ └── char # 字符设备 - │ ├── mem # 访问物理IO设备驱动 - │ ├── quickstart # 系统快速启动接口目录 - │ ├── random # 随机数设备驱动 - │ └── video # framebuffer驱动框架 - ├── fs # 文件系统模块,主要来源于NuttX开源项目 - │ ├── fat # fat文件系统 - │ ├── jffs2 # jffs2文件系统 - │ ├── include # 对外暴露头文件存放目录 - │ ├── nfs # nfs文件系统 - │ ├── proc # proc文件系统 - │ ├── ramfs # ramfs文件系统 - │ └── vfs # vfs层 - ├── kernel # 进程、内存、IPC等模块 - │ ├── base # 基础内核,包括调度、内存等模块 - │ ├── common # 内核通用组件 - │ ├── extended # 扩展内核,包括动态加载、vdso、liteipc等模块 - │ ├── include # 对外暴露头文件存放目录 - │ └── user # 加载init进程 - ├── lib # 内核的lib库 - ├── net # 网络模块,主要来源于lwip开源项目 - ├── platform # 支持不同的芯片平台代码,如Hi3516DV300等 - │ ├── hw # 时钟与中断相关逻辑代码 - │ ├── include # 对外暴露头文件存放目录 - │ └── uart # 串口相关逻辑代码 - ├── platform # 支持不同的芯片平台代码,如Hi3516DV300等 - ├── security # 安全特性相关的代码,包括进程权限管理和虚拟id映射管理 - ├── syscall # 系统调用 - └── tools # 构建工具及相关配置和代码 -``` - -## 约束 - -LiteOS: - -Hi3518EV300默认使用jffs2文件系统,Hi3516DV300默认使用FAT文件系统。若要使用其他文件系统,需要新增适配。 - -## 使用 - -### LiteOS使用说明 - -参见LiteOS-A内核[README](https://gitee.com/openharmony/kernel_liteos_a/blob/master/README_zh.md)和LiteOS-M内核[README](https://gitee.com/openharmony/kernel_liteos_m/blob/master/README_zh.md)的“使用说明”章节。 - -### linux使用说明 - -1. 合入HDF补丁 - - 在kernel/linux/build仓中,按照kernel.mk中HDF的补丁合入方法,合入不同内核版本对应的HDF内核补丁: - - ``` - $(OHOS_BUILD_HOME)/drivers/adapter/khdf/linux/patch_hdf.sh $(OHOS_BUILD_HOME) $(KERNEL_SRC_TMP_PATH) $(HDF_PATCH_FILE) - ``` - -2. 合入芯片平台驱动补丁 - - 以Hi3516DV300为例: - - 在kernel/linux/build仓中,按照kernel.mk中的芯片组件所对应的patch路径规则及命名规则,将对应的芯片组件patch放到对应路径下: - - ``` - DEVICE_PATCH_DIR := $(OHOS_BUILD_HOME)/kernel/linux/patches/${KERNEL_VERSION}/$(DEVICE_NAME)_patch - DEVICE_PATCH_FILE := $(DEVICE_PATCH_DIR)/$(DEVICE_NAME).patch - ``` - -3. 修改自己所需要编译的config - - 在kernel/linux/build仓中,按照kernel.mk中的芯片组件所对应的patch路径规则及命名规则,将对应的芯片组件config放到对应路径下: - - ``` - KERNEL_CONFIG_PATH := $(OHOS_BUILD_HOME)/kernel/linux/config/${KERNEL_VERSION} - DEFCONFIG_FILE := $(DEVICE_NAME)_$(BUILD_TYPE)_defconfig - ``` - - > **须知:** - > - >由于OpenHarmony工程的编译构建流程中会拷贝kernel/linux/linux-\*\.\*的代码环境后进行打补丁动作,在使用OpenHarmony的版本级编译命令前,需要kernel/linux/linux-\*\.\*原代码环境。 - > - >根据不同系统工程,编译完成后会在out目录下的kernel目录中生成对应实际编译的内核,基于此目录的内核,进行对应的config修改,将最后生成的\.config文件cp到config仓对应的路径文件里,即可生效。 - -## 构建说明 - -以hi3516dv300开源开发板+ubuntu x86主机开发环境为例 - -使用工程的全量编译命令,编译生成uImage内核镜像 - -``` -./build.sh --product-name Hi3516DV300 # 编译hi3516dv300镜像 - --build-target build_kernel # 编译hi3516dv300的uImage内核镜像 - --gn-args linux_kernel_version=\"linux-5.10\" # 编译指定内核版本 -``` - -## 相关仓 - -**内核子系统** - -LiteOS: - -[drivers\_liteos](https://gitee.com/openharmony/drivers_liteos/blob/master/README_zh.md) - -[kernel\_liteos\_a](https://gitee.com/openharmony/kernel_liteos_a/blob/master/README_zh.md) - -[kernel\_liteos\_m](https://gitee.com/openharmony/kernel_liteos_m/blob/master/README_zh.md) - -[device\_qemu](https://gitee.com/openharmony/device_qemu/blob/master/README_zh.md) - -[prebuilts\_lite\_sysroot](https://gitee.com/openharmony/prebuilts_lite_sysroot/blob/master/README_zh.md) - -Linux: - -[kernel\_linux\_patches](https://gitee.com/openharmony/kernel_linux_patches/blob/master/README_zh.md) - -[kernel\_linux\_config](https://gitee.com/openharmony/kernel_linux_config/blob/master/README_zh.md) - -[kernel\_linux\_build](https://gitee.com/openharmony/kernel_linux_build/blob/master/README_zh.md) - -[kernel\_linux\_4.19](https://gitee.com/openharmony/kernel_linux_4.19/blob/master/README) - -[kernel\_linux\_5.10](https://gitee.com/openharmony/kernel_linux_5.10/blob/master/README) \ No newline at end of file diff --git "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/02.\351\251\261\345\212\250\345\255\220\347\263\273\347\273\237.md" "b/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/02.\351\251\261\345\212\250\345\255\220\347\263\273\347\273\237.md" deleted file mode 100644 index 82d79f4daafb1168c2ecb39b1103a09223bf2477..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/02.\351\251\261\345\212\250\345\255\220\347\263\273\347\273\237.md" +++ /dev/null @@ -1,169 +0,0 @@ ---- -title: 驱动子系统 -permalink: /pages/01010202 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:18 ---- -# 驱动子系统 - -- [简介](#section11660541593) -- [架构](#section101721227145613) -- [目录](#section1464106163817) -- [使用](#section8496817141616) -- [安装](#section14778154275818) -- [涉及仓](#section134812226297) - -## 简介 - -OpenHarmony驱动子系统采用C面向对象编程模型构建,通过平台解耦、内核解耦,兼容不同内核,提供了归一化的驱动平台底座,旨在为开发者提供更精准、更高效的开发环境,力求做到一次开发,多系统部署。 - -为了缩减驱动开发者的驱动开发周期,降低三方设备驱动集成难度,OpenHarmony驱动子系统支持以下关键特性和能力。 - -- 弹性化的框架能力: - - 在传统的驱动框架能力的基础上,OpenHarmony驱动子系统通过构建弹性化的框架能力,可支持在百K级别到百兆级容量的终端产品形态部署。 - - -- 规范化的驱动接口: - - 定义了常见驱动接口,为驱动开发者和使用者提供丰富、稳定接口,并和未来开放的面向手机、平板、智慧屏等设备驱动接口保持API兼容性。 - - -- 组件化的驱动模型: - - 支持组件化的驱动模型,为开发者提供更精细化的驱动管理,开发者可以对驱动进行组件化拆分,使得驱动开发者可以更多关注驱动与硬件交互部分。 - - 同时系统也预置了部分模板化的驱动模型组件,如网络设备模型等。 - - -- 归一化的配置界面: - - 提供统一的配置界面,构建跨平台的配置转换和生成工具,实现跨平台的无缝切换 - - -为了方便驱动开发者更易于开发OpenHarmony驱动程序,OpenHarmony驱动子系统在DevEco集成了驱动开发套件工具,支持驱动工程管理,驱动模板生成、配置管理等界面化的操作。 - -## 架构 - -OpenHarmony驱动框架采用主从架构设计模式,围绕着框架、模型、能力库和工具四个维度能力展开构建。 - -**图 1** 驱动架构图 -![](/images/readme/figures/驱动架构图.png "驱动架构图") - -- 驱动框架 -位于framework/core目录 - - 提供驱动框架能力,主要完成驱动加载和启动功能。 - - 通过对象管理器方式可实现驱动框架的弹性化部署和扩展。 - -- 驱动模型 - 位于framework/model目录 - - 提供了模型化驱动能力,如网络设备模型。 - -- 驱动能力库 - 位于framework/ability目录 - - 提供基础驱动能力模型,如IO通信能力模型。 - -- 驱动工具 - 位于framework/tools目录 - - 提供HDI接口转换、驱动配置编译等工具。 - -- 驱动接口 - 位于lite/hdi目录 - - 提供规范化的驱动接口。 - -- Support - 位于framework/support目录 - - 提供规范化的平台驱动接口和系统接口抽象能力。 - - -## 目录 - -``` -drivers -├── adapter #适配平台差异性的代码 -├── framework #驱动框架核心代码 -└── peripheral #外设驱动代码 -``` - -## 使用 - -**图 2** 驱动框架交互流程 -![](/images/readme/figures/驱动框架交互流程.png "驱动框架交互流程") - -驱动框架完成大部分驱动加载的动作,用户只需注册自己所需的接口和配置,然后驱动框架就会解析配置的内容,完成驱动加载和初始化动作。 - -开发者基于HDF驱动框架开发的驱动主要包含三大部分: - -1、驱动程序部分 - 完成驱动的功能逻辑。 - -2、驱动配置信息 - 指示驱动的加载信息内容。 - -3、驱动资源配置 - 配置驱动的硬件配置信息。 - -驱动程序主要是完成驱动功能的开发部分: - -对于开发者首先看到的是驱动入口部分,驱动入口部分通过DriverEntry对其进行描述。 - -其中主要包含bind, init 和release三个接口。 - -``` -struct HdfDriverEntry g_deviceSample = { - .moduleVersion = 1, - .moduleName = "sample_driver", - .Bind = SampleDriverBind, - .Init = SampleDriverInit, - .Release = SampleDriverRelease, -}; -``` - -Bind接口描述:该接口的作用主要是完成驱动设备和设备服务接口的bind动作。 - -``` -int32_t SampleDriverBind(struct HdfDeviceObject *deviceObject) -{ - // TODO: Bind device service to device object. - // And you can also initialize device resources here. - return HDF_SUCCESS; -} -``` - -Init接口描述:当框架完成设备绑定动作后,就开始调用驱动初始化接口,当初始化成功后,驱动框架根据配置文件决定是否对外创建设备服务接口,还是只是对当前服务接口可见。如果Init初始化失败的话,驱动框架就会主动释放创建的设备接口等信息。 - -``` -int32_t SampleDriverInit(struct HdfDeviceObject *deviceObject) -{ - // TODO: Init hardware or other resources here. - return HDF_SUCCESS; -} -``` - -Release接口描述:当用户需要卸载驱动时,驱动框架先通过该接口通知驱动程序释放资源。然后在执行其他内部资源释放。 - -``` -void SampleDriverRelease(struct HdfDeviceObject *deviceObject) -{ - // Release all resources. - return; -} -``` - -## 安装 - -OpenHarmony驱动主要部署在内核态,当前主要采用静态链接方式,随内核子系统编译和系统镜像打包。 - -**图 3** 驱动安装部署图 -![](/images/readme/figures/驱动安装部署图.png "驱动安装部署图") - -## 涉及仓 - -**驱动子系统** - -[drivers\_framework](https://gitee.com/openharmony/drivers_framework/blob/master/README_zh.md) - -[drivers\_adapter](https://gitee.com/openharmony/drivers_adapter/blob/master/README_zh.md) - -[drivers\_adapter\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_khdf_linux/blob/master/README_zh.md) - -[drivers\_peripheral](https://gitee.com/openharmony/drivers_peripheral/blob/master/README_zh.md) - diff --git "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/03.\346\226\271\350\210\237\350\277\220\350\241\214\346\227\266\345\255\220\347\263\273\347\273\237.md" "b/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/03.\346\226\271\350\210\237\350\277\220\350\241\214\346\227\266\345\255\220\347\263\273\347\273\237.md" deleted file mode 100644 index 21bbbbf0c47859107d3539f58bdd15ebef661bd4..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/03.\346\226\271\350\210\237\350\277\220\350\241\214\346\227\266\345\255\220\347\263\273\347\273\237.md" +++ /dev/null @@ -1,78 +0,0 @@ ---- -title: 方舟运行时子系统 -permalink: /pages/01010203 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:18 ---- -# 方舟运行时子系统 - -- [方舟运行时子系统](#方舟运行时子系统) - - [简介](#简介) - - [目录](#目录) - - [使用指南](#使用指南) - - [相关仓](#相关仓) - -## 简介 - -方舟\(ARK\)是华为自研的统一编程平台,包含编译器、工具链、运行时等关键部件,支持高级语言在多种芯片平台的编译与运行,并支撑OpenHarmony操作系统及其应用和服务运行在手机、个人电脑、平板、电视、汽车和智能穿戴等多种设备上的需求。本次开源的ARK-JS提供的能力是在OpenHarmony标准系统\(standard system\)中编译和运行JavaScript语言\(本文后面简称JS\)。 - -本次开源的ARK-JS分成两个部分,分别是JS编译工具链与JS运行时。JS工具链将JS源码编译成方舟字节码\(ARK Bytecode\),JS运行时负责执行生成的方舟字节码\(后续如无特殊说明,字节码特指方舟字节码\)。 - -JS编译工具链架构: - -![](/images/readme/figures/zh-cn_image_ark_frontend.png) - -JS前端编译器,将JavaScript源码解析为AST\( Abstract Syntax Tree\)后,经过AST变换、字节码生成器、寄存器分配后由native emiter产生方舟字节码文件\(abc文件\) - -JS运行时(Runtime)架构: - -![](/images/readme/figures/zh-cn_image_ark_runtime.png) - -ARK-JS Runtime以方舟字节码文件作为输入并直接运行字节码文件,实现对应的JS语义逻辑。 - -ARK-JS Runtime主要由四个部分组成: - -- Core Runtime - - Core Runtime主要由语言无关的基础运行库组成,包括承载字节码的ARK File组件、支持Debugger的Tooling组件、负责对应系统调用的ARK Base组件等。 - -- Execution Engine - - 执行引擎目前包含执行字节码的解释器、缓存隐藏类和内联缓存、以及剖析记录运行时类型的Profiler。 - -- ECMAScript Runtime - - ECMAScript Runtime则包含了各种JS对象的分配器、垃圾回收器、以及用以支撑ECMAScript规范的内部运行库。 - -- AFFI \(ARK Foreign Function Interface\) - - AFFI是ARK JS运行时的C++语言外部函数接口。 - - -## 目录 - -``` -/ark -├── js_runtime # JS运行时组件 -├── runtime_core # 运行时公共组件 -└── ts2abc # JS语言的前端工具 -``` - -## 使用指南 - -[方舟运行时使用指南](https://gitee.com/openharmony/ark_js_runtime/blob/master/docs/ARK-Runtime-Usage-Guide-zh.md) - -## 相关仓 - -[ark\_runtime\_core](https://gitee.com/openharmony/ark_runtime_core) - -[ark\_js\_runtime](https://gitee.com/openharmony/ark_js_runtime) - -[ark\_ts2abc](https://gitee.com/openharmony/ark_ts2abc) diff --git "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/04.DFX\345\255\220\347\263\273\347\273\237.md" "b/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/04.DFX\345\255\220\347\263\273\347\273\237.md" deleted file mode 100644 index b1d20a43eac996a34ff376d573c5bede13f9a710..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/04.DFX\345\255\220\347\263\273\347\273\237.md" +++ /dev/null @@ -1,74 +0,0 @@ ---- -title: DFX子系统 -permalink: /pages/01010204 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:18 ---- -# DFX子系统 - -- [简介](#section1347419114210) -- [系统架构](#section342962219551) -- [目录](#section62815498425) -- [相关仓](#section767551120815) - -## 简介 - -在OpenHarmony中,DFX\([Design for X](https://en.wikipedia.org/wiki/Design_for_X)\)是为了提升质量属性软件设计,目前包含的内容主要有:DFR(Design for Reliability,可靠性)和DFT(Design for Testability,可测试性)特性。 - -提供以下功能: - -- HiLog流水日志。 - -- HiView插件平台。 -- FaultLoggerd应用故障收集和订阅。 -- HiAppEvent应用事件记录接口及框架。 -- HiSysEvent系统事件记录接口及服务。 - -## 系统架构 - -**图 1** 子系统架构图 - - -![](/images/readme/figures/zh-cn_image_0000001162062837.png) - -## 目录 - -``` -base/hiviewdfx # DFX主仓,用于存放编译相关配置 -├── hiview # hiview部件,包含插件平台和事件分发能力 -├── hiview_lite # hiview_lite部件,包含轻量系统的日志任务能力 -├── hilog # hilog部件,包含标准系统的流水日志能力 -├── hilog_lite # hilog_lite部件,包含轻量和小型系统的流水日志能力 -├── hievent_lite # hievent_lite部件,包含轻量系统的事件日志能力 -├── hiappevent # hiappevent部件,包含应用事件记录接口及框架 -├── hisysevent # hisysevent部件,包含系统事件记录接口及服务 -├── faultloggerd # faultloggerd部件,包含应用故障日志采集服务 -``` - -## 相关仓 - -**DFX子系统** - -[hiviewdfx\_hiview](https://gitee.com/openharmony/hiviewdfx_hiview/blob/master/README_zh.md) - -[hiviewdfx\_hilog](https://gitee.com/openharmony/hiviewdfx_hilog/blob/master/README_zh.md) - -[hiviewdfx\_hiappevent](https://gitee.com/openharmony/hiviewdfx_hiappevent/blob/master/README_zh.md) - -[hiviewdfx\_hisysevent](https://gitee.com/openharmony/hiviewdfx_hisysevent/blob/master/README_zh.md) - -[hiviewdfx\_faultloggerd](https://gitee.com/openharmony/hiviewdfx_faultloggerd/blob/master/README_zh.md) - -[hiviewdfx\_hilog\_lite](https://gitee.com/openharmony/hiviewdfx_hilog_lite/blob/master/README_zh.md) - -[hiviewdfx\_hievent\_lite](https://gitee.com/openharmony/hiviewdfx_hievent_lite/blob/master/README_zh.md) - -[hiviewdfx\_hiview\_lite](https://gitee.com/openharmony/hiviewdfx_hiview_lite/blob/master/README_zh.md) - diff --git "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/05.JS-UI\346\241\206\346\236\266\345\255\220\347\263\273\347\273\237.md" "b/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/05.JS-UI\346\241\206\346\236\266\345\255\220\347\263\273\347\273\237.md" deleted file mode 100644 index 24aeb2f2a35b9864426561e36b43983d8f348f59..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/05.JS-UI\346\241\206\346\236\266\345\255\220\347\263\273\347\273\237.md" +++ /dev/null @@ -1,133 +0,0 @@ ---- -title: JS-UI框架子系统 -permalink: /pages/01010205 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:18 ---- -# JS UI框架子系统 - -- [简介](#section11660541593) -- [目录](#section179173014915) -- [使用](#section1711605017917) -- [相关仓](#section1599816111011) - -## 简介 - -JS UI框架是OpenHarmony UI开发框架,提供基础类、容器类、画布类等UI组件和标准CSS动画能力,支持类Web范式编程。 - -- **类Web范式编程** - - JS UI框架采用类HTML和CSS Web编程语言作为页面布局和页面样式的开发语言,页面业务逻辑则支持ECMAScript规范的JavaScript语言。JS UI框架提供的类Web编程范式,可以让开发者避免编写UI状态切换的代码,视图配置信息更加直观。 - - -**图 1** JS UI框架架构 - - -![](/images/readme/figures/zh-cn_image_0000001077953992.png) - -JS UI框架包括应用层(Application)、前端框架层(Framework)、引擎层(Engine)和平台适配层(Porting Layer)。 - -- **Application** - - 应用层表示开发者使用JS UI框架开发的FA应用,这里的FA应用特指JS FA应用。 - -- **Framework** - - 前端框架层主要完成前端页面解析,以及提供MVVM(Model-View-ViewModel)开发模式、页面路由机制和自定义组件等能力。 - -- **Engine** - - 引擎层主要提供动画解析、DOM(Document Object Model)树构建、布局计算、渲染命令构建与绘制、事件管理等能力。 - -- **Porting Layer** - - 适配层主要完成对平台层进行抽象,提供抽象接口,可以对接到系统平台。比如:事件对接、渲染管线对接和系统生命周期对接等。 - - -## 目录 - -JS UI开发框架源代码在/foundation/ace下,目录结构如下图所示: - -``` -/foundation/ace -├── ace_engine # JS UI框架 -├── ace_engine_lite # 轻量级JS UI框架 -└── napi # JS API扩展Native开发模块 -``` - -## 使用 - -- JS FA开发目录 - -新建工程的JS目录如下图所示。 - -**图 2** JS FA开发目录 -![](/images/readme/figures/JS-FA开发目录.png "JS-FA开发目录") - -在工程目录中:i18n下存放多语言的json文件;pages文件夹下存放多个页面,每个页面由hml、css和js文件组成。 - -- **main \> js \> default \> i18n \> en-US.json:**此文件定义了在英文模式下页面显示的变量内容。同理,zh-CN.json中定义了中文模式下的页面内容。 - - ``` - { - "strings": { - "hello": "Hello", - "world": "World" - } - } - ``` - -- **main \> js \> default \> pages \> index \> index.hml:**此文件定义了index页面的布局、index页面中用到的组件,以及这些组件的层级关系。例如:index.hml文件中包含了一个text组件,内容为“Hello World”文本。 - - ``` -
- - {{ $t('strings.hello') }} {{title}} - -
- ``` - -- **main \> js \> default \> pages \> index \> index.css:**此文件定义了index页面的样式。例如:index.css文件定义了“container”和“title”的样式。 - - ``` - .container { - flex-direction: column; - justify-content: center; - align-items: center; - } - .title { - font-size: 100px; - } - ``` - -- **main \> js \> default \> pages \> index \> index.js:**此文件定义了index页面的业务逻辑,比如数据绑定、事件处理等。例如:变量“title”赋值为字符串“World”。 - - ``` - export default { - data: { - title: '', - }, - onInit() { - this.title = this.$t('strings.world'); - }, - } - ``` - - -## 相关仓 - -**JS UI框架子系统** - -ace\_ace\_engine - -ace\_ace\_engine\_lite - -ace\_napi - diff --git "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/06.Misc\350\275\257\344\273\266\346\234\215\345\212\241\345\255\220\347\263\273\347\273\237.md" "b/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/06.Misc\350\275\257\344\273\266\346\234\215\345\212\241\345\255\220\347\263\273\347\273\237.md" deleted file mode 100644 index cdffabf4b3015ab47c6606961f553ae78078d2c5..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/06.Misc\350\275\257\344\273\266\346\234\215\345\212\241\345\255\220\347\263\273\347\273\237.md" +++ /dev/null @@ -1,39 +0,0 @@ ---- -title: Misc软件服务子系统 -permalink: /pages/01010206 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:18 ---- -# Misc软件服务子系统 - -- [简介](#section11660541593) -- [目录](#section161941989596) -- [相关仓](#section1371113476307) - -## 简介 - -提供了设置系统时间的接口。 - -**图 1** 子系统架构图 -![](/images/readme/figures/子系统架构图.png "子系统架构图") - -## 目录 - -``` -/base/miscservices -└── time # 时间服务组件 -``` - -## 相关仓 - -**Misc软件服务子系统** - -miscservices\_time - diff --git "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/07.XTS\345\255\220\347\263\273\347\273\237.md" "b/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/07.XTS\345\255\220\347\263\273\347\273\237.md" deleted file mode 100644 index 56a08928641d28ba548bb18eebd5e776e94024c4..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/07.XTS\345\255\220\347\263\273\347\273\237.md" +++ /dev/null @@ -1,668 +0,0 @@ ---- -title: XTS子系统 -permalink: /pages/01010207 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:18 ---- -# XTS子系统 - -- [简介](#section465982318513) -- [系统类型](#section125090457443) -- [目录](#section161941989596) -- [约束](#section119744591305) -- [使用说明](#section137768191623) -- [用例开发指导](#section3695134065513) - - [C语言用例开发编译指导(适用于轻量系统产品用例开发)](#section198193336544) - - [C语言用例执行指导(适用于轻量系统产品用例开发)](#section13820233175418) - - [C++语言用例开发编译指导(适用于小型系统、标准系统用例开发)](#section3822123311540) - - [C++语言用例执行指导(适用于小型系统、标准系统用例开发)](#section128222336544) - - [JS语言用例开发指导(适用于标准系统)](#section159801435165220) - - [JS语言用例编译打包指导(适用于标准系统)](#section445519106559) - -- [相关仓](#section1371113476307) - -## 简介 - -XTS子系统是OpenHarmony生态认证测试套件的集合,当前包括acts(application compatibility test suite)应用兼容性测试套件,后续会拓展dcts(device compatibility test suite)设备兼容性测试套件等。 - -XTS子系统当前包括acts与tools软件包: - -- acts,存放acts相关测试用例源码与配置文件,其目的是帮助终端设备厂商尽早发现软件与OpenHarmony的不兼容性,确保软件在整个开发过程中满足OpenHarmony的兼容性要求。 -- tools,存放acts相关测试用例开发框架。 - -## 系统类型 - -OpenHarmony支持如下几种系统类型: - -- 轻量系统(mini system) - - 面向MCU类处理器例如Arm Cortex-M、RISC-V 32位的设备,硬件资源极其有限,支持的设备最小内存为128KiB,可以提供多种轻量级网络协议,轻量级的图形框架,以及丰富的IOT总线读写部件等。可支撑的产品如智能家居领域的连接类模组、传感器设备、穿戴类设备等。 - -- 小型系统(small system) - - 面向应用处理器例如Arm Cortex-A的设备,支持的设备最小内存为1MiB,可以提供更高的安全能力、标准的图形框架、视频编解码的多媒体能力。可支撑的产品如智能家居领域的IP Camera、电子猫眼、路由器以及智慧出行域的行车记录仪等。 - -- 标准系统(standard system) - - 面向应用处理器例如Arm Cortex-A的设备,支持的设备最小内存为128MiB,可以提供增强的交互能力、3D GPU以及硬件合成能力、更多控件以及动效更丰富的图形能力、完整的应用框架。可支撑的产品如高端的冰箱显示屏。 - - -## 目录 - -``` -/test/xts -├── acts # 测试代码存放目录 -│ └── subsystem # 标准系统子系统测试用例源码存放目录 -│ └── subsystem_lite # 轻量系统、小型系统子系统测试用例源码存放目录 -│ └── BUILD.gn # 标准系统测试用例编译配置 -│ └── build_lite # 轻量系统、小型系统测试用例编译配置存放目录 -│ └── BUILD.gn # 轻量系统、小型系统测试用例编译配置 -└── tools # 测试工具代码存放目录 -``` - -## 约束 - -轻量系统用例开发语言是C,小型系统用例开发语言是C++。 - -## 使用说明 - -**表 1** 用例级别说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

级别名称

-

基本定义

-

测试范围

-

Level0

-

冒烟

-

验证关键功能点基本功能/最基本DFX属性在最常见输入下的表现,通过表示功能基本可运行。

-

Level1

-

基本

-

验证各功能点基本功能/基本DFX属性在常见输入下的表现,通过表示功能基本可测试。

-

Level2

-

重要

-

验证各功能点的基本功能/基本DFX属性在常规输入/常见异常情况下的表现,通过表示功能基本正常可用,可开展Beta。

-

Level3

-

一般

-

验证各功能点的全部功能/全部DFX属性在各种常规/非常规输入组合下,或各种正常/异常预置条件组合下的表现。

-

Level4

-

生僻

-

验证关键功能点在极端异常预置条件下、用户难以触及的异常输入组合下的表现。

-
- -**表 2** 用例粒度说明 - - - - - - - - - - - - - - - - - - - - -

用例规模

-

被测试对象

-

测试环境

-

LargeTest

-

业务功能/全场景特性/整机及场景级DFX

-

尽量使用贴近真实的环境设备

-

MediumTest

-

模块/子系统集成至设备后的功能/DFX

-

使用真实的单设备进行验证,可进行消息模拟,尽量不对函数进行MOCK

-

SmallTest

-

模块/类/函数

-

在开发者个人环境进行测试,尽量不依赖其他模块,存在大量的MOCK

-
- -**表 3** 测试类型说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

测试类型名称

-

测试类型定义

-

Function

-

验证被测对象提供给用户的业务功能实现正确性的测试项,这里的“用户”可以是终端用户或开发者,功能包括业务功能及平台功能

-

Performance

-

验证被测对象在特定预置条件/负载模型下的处理能力的测试项,“处理能力”一般以单位时间内可处理的业务量来衡量,如呼叫/秒,帧率/秒,事件处理量/秒等

-

Power

-

验证被测对象在特定预置条件/负载模型下在一定时间内能源消耗量的测试项

-

Reliability

-

验证被测对象在正常/异常输入情况下,或业务量压力和长时间连续运行压力情况下业务表现的测试项,含稳定性、压力、故障注入、Monkey测试项

-

Security

-

验证系统对恶意威胁的防护能力,威胁包括但不限于未授权访问、使用、泄露、破坏、修改、毁灭,以保障信息的机密性、完整性和可用性; 验证系统对用户隐私的保护能力,保障用户的隐私数据被收集、使用、保有、披露和处置符合法律规范,保障用户的隐私权; 验证对各类安全规范的遵从情况,如安全设计规范、安全红线、工信部安全认证规范等,保障安全相关法律法规的合规。

-

Global

-

验证被测对象在是否具有国际化数据支持和本地化能力的测试项,包括语言显示、输入/输出习惯、时间显示、区域特性如货币时间禁忌等等

-

Compatibility

-

当被测对象为应用时,包括被测对象对于自身数据的后向兼容性、对于系统的前后向兼容性、对于不同用户数据(如播放器之音频文件格式/智能短信之用户短信内容)的兼容性测试项; 当被测对象为系统时,包括被测系统对于系统自身数据的后向兼容性、以及对于生态中常用应用的兼容性测试项;当被测对象为软件时,包括被测系统对于相关的硬件的兼容性;

-

User

-

验证被测对象在真实用户场景下的用户体验感受的测试项,注意此种情况下没有客观的“正确”与“失败”,所有的结论及评价都应该来自于用户

-

Standard

-

验证被测对象对于行业及公司内标准/协议/规范的遵从情况的测试项,注意此处的“标准”不包含任何安全标准,针对安全标准的测试项划归为“安全测试”类型

-

Safety

-

验证被测对象的Safety属性,避免产品可能对人身安全、健康以及产品本身带来的危害。

-

Resilience

-

验证被测对象的韧性属性,确保系统受攻击时承受并保持在有定义的运行状态(包括降级)、恢复并适应攻击以保障Mission达成。

-
- -## 用例开发指导 - -根据测试系统选择测试框架和对应测试用例语言。 - -**表 4** 系统和测试框架、开发语言对应关系 - - - - - - - - - - - - - - - - - - - - -

系统

-

测试框架

-

语言

-

轻量系统

-

hctest

-

c

-

小型系统

-

hcpptest

-

c++

-

标准系统

-

HJSUnit、hcpptest

-

js、c++

-
- -### C语言用例开发编译指导(适用于轻量系统产品用例开发) - -**示例:轻量系统测试用例开发** - -当前使用的测试框架是hctest,hctest测试框架支持使用C语言编写测试用例,是在开源测试框架unity的基础上进行增强和适配。 - -1. 用例目录规范:测试用例存储到test/xts/acts仓中 - - ``` - ├── acts - │ └──subsystem_lite - │ │ └── module_hal - │ │ │ └── BUILD.gn - │ │ │ └── src - │ └──build_lite - │ │ └── BUILD.gn - ``` - -2. src目录下用例编写样例。 - - 1.引用测试框架 - - ``` - #include "hctest.h" - ``` - - 2. 使用宏定义LITE\_TEST\_SUIT定义子系统、模块、测试套件名称 - - ``` - /** - * @brief register a test suit named "IntTestSuite" - * @param test subsystem name - * @param example module name - * @param IntTestSuite test suit name - */ - LITE_TEST_SUIT(test, example, IntTestSuite); - ``` - - 3. 定义Setup与TearDown - - 命名方式:测试套件名称+Setup,测试套件名称+TearDown。 - - Setup与TearDown必须存在,可以为空函数。 - - 4. 使用宏定义LITE\_TEST\_CASE写测试用例 - - 包括三个参数:测试套件名称,测试用例名称,用例属性(测试类型、用例粒度、用例级别)。 - - ``` - LITE_TEST_CASE(IntTestSuite, TestCase001, Function | MediumTest | Level1) - { - //do something - }; - ``` - - 5. 使用宏定义 RUN\_TEST\_SUITE注册测试套件 - - ``` - RUN_TEST_SUITE(IntTestSuite); - ``` - -3. 测试模块的配置文件(BUILD.gn)样例: - - 在每个测试模块目录下新建BUILD.gn编译文件,用于指定编译后静态库的名称、依赖的头文件、依赖的库等;具体写法如下: - - ``` - import("//test/xts/tools/lite/build/suite_lite.gni") - hctest_suite("ActsDemoTest") { - suite_name = "acts" - sources = [ - "src/test_demo.c", - ] - include_dirs = [ ] - cflags = [ "-Wno-error" ] - } - ``` - -4. acts下BUILD.gn增加编译选项。 - - 需要将测试模块加入到acts目录下的编译脚本中,编译脚本路径:test/xts/acts/build\_lite/BUILD.gn。 - - ``` - lite_component("acts") { - ... - if(board_name == "liteos_m") { - features += [ - ... - "//xts/acts/subsystem_lite/module_hal:ActsDemoTest" - ] - } - } - ``` - -5. 测试套件编译命令。 - - 随版本编译,debug版本编译时会同步编译acts测试套件 - - >![](/images/readme/public_sys-resources/icon-note.gif) **说明:** - >acts测试套件编译中间件为静态库,最终链接到版本镜像中 。 - - -### C语言用例执行指导(适用于轻量系统产品用例开发) - -**示例:轻量系统测试用例执行** - -将版本镜像烧录进开发板。 - -**测试步骤** - -1. 使用串口工具登录开发板,并保存串口打印信息。 -2. 重启设备,查看串口日志。 - -**测试结果分析指导** - -基于串口打印日志进行分析; - -每个测试套件执行以Start to run test suite开始,以xx Tests xx Failures xx Ignored结束。 - -### C++语言用例开发编译指导(适用于小型系统、标准系统用例开发) - -**示例:小型系统测试用例开发**(标准系统参考具体样例目录:global/i18n\_standard) - -当前使用的测试框架是hcpptest,hcpptest测试框架是在开源的googletest测试框架的基础上进行的增强和适配。 - -1. 规范用例目录:测试用例存储到test/xts/acts仓中。 - - ``` - ├── acts - │ └──subsystem_lite - │ │ └── module_posix - │ │ │ └── BUILD.gn - │ │ │ └── src - │ └──build_lite - │ │ └── BUILD.gn - ``` - -2. 测试模块src下用例编写样例: - - 1. 引用测试框架: - - 需要引用gtest.h 如:\#include "gtest/gtest.h" - - ``` - #include "gtest/gtest.h" - ``` - - 2. 定义Setup与TearDown - - ``` - using namespace std; - using namespace testing::ext; - class TestSuite: public testing::Test { - protected: - // Preset action of the test suite, which is executed before the first test case - static void SetUpTestCase(void){ - } - // Test suite cleanup action, which is executed after the last test case - static void TearDownTestCase(void){ - } - // Preset action of the test case - virtual void SetUp() - { - } - // Cleanup action of the test case - virtual void TearDown() - { - } - }; - ``` - - 3. 使用宏定义HWTEST或HWTEST\_F写测试用例 - - 普通测试用例的定义:HWTEST(测试套名称, 测试用例名称, 用例标注)。 - - 包含SetUp和TearDown的测试用例的定义 :HWTEST\_F(测试套名称, 测试用例名称,用例标注)。 - - 宏定义包括三个参数:测试套件名称,测试用例名称,用例属性(测试类型、用例粒度、用例级别)。 - - ``` - HWTEST_F(TestSuite, TestCase_0001, Function | MediumTest | Level1) { - // do something - } - ``` - -3. 测试模块下用例配置文件(BUILD.gn)样例: - - 每个测试模块目录下新建BUILD.gn编译文件,用于指定编译后可执行文件的名称、依赖的头文件、依赖的库等;具体写法如下。每个测试模块将独立编译成.bin可执行文件, 该文件可直接push到单板上进行测试。 - - 举例: - - ``` - import("//test/xts/tools/lite/build/suite_lite.gni") - hcpptest_suite("ActsDemoTest") { - suite_name = "acts" - sources = [ - "src/TestDemo.cpp" - ] - - include_dirs = [ - "src", - ... - ] - deps = [ - ... - ] - cflags = [ "-Wno-error" ] - } - - ``` - -4. acts目录下增加编译选项(BUILD.gn)样例: - - 将测试模块加入到acts目录下的编译脚本中,编译脚本为:test/xts/acts/build\_lite/BUILD.gn。 - - ``` - lite_component("acts") { - ... - else if(board_name == "liteos_a") { - features += [ - ... - "//xts/acts/subsystem_lite/module_posix:ActsDemoTest" - ] - } - } - ``` - -5. 测试套件编译命令。 - - 随版本编译,debug版本编译时会同步编译acts测试套件 - - >![](/images/readme/public_sys-resources/icon-note.gif) **说明:** - >小型系统acts独立编译成可执行文件(bin格式), 在编译产物的suites\\acts目录下归档。 - - -### C++语言用例执行指导(适用于小型系统、标准系统用例开发) - -**示例:小型系统测试用例执行** - -目前的用例执行采用nfs共享的方式,mount到单板去执行。 - -**环境搭建** - -1. 使用有限网线或无线将开发板与PC进行连接。 -2. 开发板配置IP、子网掩码、网关,确保开发板与PC处于同一个网段。 -3. PC安装nfs服务器并完成注册,启动nfs服务。 -4. 开发板配置mount命令,确保开发板可以访问PC端的nfs共享文件。 - - 格式:mount \[nfs服务器IP\]:\[/nfs共享目录\] \[/开发板目录\] nfs - - 举例: - - ``` - mount 192.168.1.10:/nfs /nfs nfs - ``` - - -**用例执行** - -测试套件执行 ActsDemoTest.bin 触发用例执行,基于串口打印日志进行分析。 - -### JS语言用例开发指导(适用于标准系统) - -当前使用的测试框架是HJSUnit,用于支撑OpenHarmony application测试(特指基于JS应用框架使用 Javascript 语言开发的 APP)进行自动化测试。 - -**用例编写基础语法** - -测试用例为 js 语言,必须满足 JavaScript 语言编程规范: - -**表 5** - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

用例语法

-

描述

-

要求

-

beforeAll

-

测试套级别的预置条件,在所有测试用例开始前执行且仅执行一次,支持一个参数:预置动作函数

-

可选

-

afterAll

-

测试套级别的清理条件,在所有测试用例结束后执行且仅执行一次,支持一个参数:清理动作函数

-

可选

-

beforeEach

-

测试用例级别的预置条件,在每条测试用例开始前执行,执行次数与 it 定义的测试用例数一致,支持一个参数:预置动作函数

-

可选

-

afterEach

-

测试用例级别的清理条件,在每条测试用例结束后执行,执行次数与 it 定义的测试用例数一致,支持一个参数:清理动作函数

-

可选

-

describe

-

定义一个测试套,支持两个参数:测试套名称和测试套函数; describe 支持嵌套,每个 describe 内均可以定义 beforeAll 、beforeEach 、afterEach 和 afterAll

-

必选

-

it

-

定义一条测试用例,支持三个参数:用例名称,过滤参数和用例函数

-

备注:

-

过滤参数:过滤参数为一个 32 位的 Int 类型参数,0 位 置1表示不筛选、默认执行;0-10 位 置1表示测试用例类型;16-18 位 置1表示测试用例规模;24-28 位 置1表示测试层级

-

测试用例类型。置位0-10分别表示:FUNCTION 方法类测试、PERFORMANCE 性能类测试、POWER 功耗类测试、RELIABILITY 可靠性测试、SECURITY 安全合规测试、GLOBAL 整体性测试、COMPATIBILITY 兼容性测试、USER 用户测试、STANDARD 标准测试、SAFETY 安全特性测试,RESILIENCE 压力测试。

-

测试用例规模。置位16-18分别表示:SMALL 小型测试、MEDIUM 中型测试、LARGE 大型测试。

-

测试层级。置位24-28分别表示:LEVEL0-0 级测试、LEVEL1-1 级测试、LEVEL2-2 级测试、LEVEL3-3 级测试、LEVEL4-4 级测试。

-

必选

-
- -用例编写语法采用 jasmine 的标准语法,格式支持ES6格式。 - -1. 规范用例目录:测试用例存储到entry/src/main/js/test目录。 - - ``` - ├── BUILD.gn - │ └──entry - │ │ └──src - │ │ │ └──main - │ │ │ │ └──js - │ │ │ │ │ └──default - │ │ │ │ │ │ └──pages - │ │ │ │ │ │ │ └──index - │ │ │ │ │ │ │ │ └──index.js # 入口文件 - │ │ │ │ │ └──test # 测试代码存放目录 - │ │ │ └── resources # hap资源存放目录 - │ │ │ └── config.json # hap配置文件 - ``` - -2. index.js示例 - - ``` - // 拉起js测试框架,加载测试用例 - import {Core, ExpectExtend} from 'deccjsunit/index' - - export default { - data: { - title: "" - }, - onInit() { - this.title = this.$t('strings.world'); - }, - onShow() { - console.info('onShow finish') - const core = Core.getInstance() - const expectExtend = new ExpectExtend({ - 'id': 'extend' - }) - core.addService('expect', expectExtend) - core.init() - const configService = core.getDefaultService('config') - configService.setConfig(this) - require('../../../test/List.test') - core.execute() - }, - onReady() { - }, - } - ``` - -3. 单元测试用例示例 - - ``` - // Example1: 使用HJSUnit进行单元测试 - describe('appInfoTest', function () { - it('app_info_test_001', 0, function () { - var info = app.getInfo() - expect(info.versionName).assertEqual('1.0') - expect(info.versionCode).assertEqual('3') - }) - }) - ``` - - -### JS语言用例编译打包指导(适用于标准系统) - -hap包编译请参考[标准系统js应用开发指导](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/build_overview-0000001055075201)。 - -## 相关仓 - -xts\_acts - -xts\_tools - diff --git "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/08.\344\272\213\344\273\266\351\200\232\347\237\245\345\255\220\347\263\273\347\273\237.md" "b/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/08.\344\272\213\344\273\266\351\200\232\347\237\245\345\255\220\347\263\273\347\273\237.md" deleted file mode 100644 index 93f2fc4bd202e9eea0d21faf44c9fbc268ea68eb..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/08.\344\272\213\344\273\266\351\200\232\347\237\245\345\255\220\347\263\273\347\273\237.md" +++ /dev/null @@ -1,59 +0,0 @@ ---- -title: 事件通知子系统 -permalink: /pages/01010208 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:18 ---- -# 事件通知子系统 - -## 简介 - -OpenHarmony通过CES(Common Event Service,公共事件服务)为应用程序提供订阅、发布、退订公共事件的能力。 - -公共事件可分为系统公共事件和自定义公共事件。 - -- 系统公共事件:系统将收集到的事件信息,根据系统策略发送给订阅该事件的用户程序。 例如:系统关键服务发布的系统事件(例如:hap安装,更新,卸载等)。 - -- 自定义公共事件:应用自定义一些公共事件用来实现跨应用的事件通信能力。 - -每个应用都可以按需订阅公共事件,订阅成功且公共事件发布,系统会把其发送给应用。这些公共事件可能来自系统、其他应用和应用自身。 - -### 架构图 - -![](/images/readme/figures/cesfwk_architecture_diagram.png "公共事件服务架构图") - -## 目录 - -``` -/base/notification/ces_standard/ -│── frameworks # 组件目录 -│ |── common/log # 日志组件目录 -│ |── core # 组件native接口内部实现 -│ ├── native # 组件native接口实现 -│── interface # 对外接口目录 -| |── innerkits # 组件native接口定义 -| |── kits/napi # 组件napi实现 -├── sa_profile # 组件服务配置 -├── services # 组件服务实现 -├── tools # 组件工具实现 -│── ohos.build # 组件编译脚本 - -``` - -## 使用说明 - -* [详细说明请参考: CommonEvent开发指南](/pages/extra/51cfde/) - -## 相关仓 - -事件通知子系统 - -**notification_ces_standard** - diff --git "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/09.\345\205\203\350\203\275\345\212\233\345\255\220\347\263\273\347\273\237.md" "b/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/09.\345\205\203\350\203\275\345\212\233\345\255\220\347\263\273\347\273\237.md" deleted file mode 100644 index 3afe7f2eaf6ee8afdb73cf392fb630ae242ce196..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/09.\345\205\203\350\203\275\345\212\233\345\255\220\347\263\273\347\273\237.md" +++ /dev/null @@ -1,147 +0,0 @@ ---- -title: 元能力子系统 -permalink: /pages/01010209 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:18 ---- -# 元能力子系统 - -## 简介 - -**元能力子系统**实现对Ability的运行及生命周期进行统一的调度和管理,应用进程能够支撑多个Ability,Ability具有跨应用进程间和同一进程内调用的能力。Ability管理服务统一调度和管理应用中各Ability,并对Ability的生命周期变更进行管理。 - -![](/images/readme/figures/aafwk.png) - -**元能力子系统架构图说明:** - -- **Ability Kit**为Ability的运行提供基础的运行环境支撑。Ability是系统调度应用的最小单元,是能够完成一个独立功能的组件,一个应用可以包含一个或多个Ability。Ability分为FA(Feature Ability)和PA(Particle Ability)两种类,其中FA支持Page Ability,PA支持Service Ability和Data Ability。 - -- **Ability管理服务(AbilityManagerService)**:用于协调各Ability运行关系、及对生命周期进行调度的系统服务。 - - Ability栈管理模块(AbilityStackManager)负责维护各个Ability之间跳转的先后关系。 - - 连接管理模块(AbilityConnectManager)是Ability管理服务对Service类型Ability连接管理的模块。 - - 数据管理模块(DataAbilityManager)是Ability管理服务对Data类型Ability管理的模块。 - - App管理服务调度模块(AppScheduler)提供Ability管理服务对用户程序管理服务进行调度管理的能力。 - - Ability调度模块(AbilityScheduler)提供对Ability进行调度管理的能力。 - - 生命周期调度模块(LifecycleDeal)是Ability管理服务对Ability的生命周期事件进行管理调度的模块。 - -**Ability生命周期介绍**(Ability Life Cycle)是Ability被调度到INACTIVE、ACTIVE、BACKGROUND等各个状态的统称(主要涉及PageAbility类型和ServiceAbility类型的Ability)。 - - - **PageAbility类型的Ability生命周期流转如下图所示** - -![PageAbility-Lifecycle](/images/readme/figures/page-ability-lifecycle.png) - - - - - **ServiceAbility类型的Ability生命周期流转如下图所示** - -![ServiceAbility-Lifecycle](/images/readme/figures/service-ability-lifecycle.png) - -**Ability生命周期状态说明:** - - - **UNINITIALIZED**:未初始状态,为临时状态,Ability被创建后会由UNINITIALIZED状态进入INITIAL状态。 - - - **INITIAL**:初始化状态,也表示停止状态,表示当前Ability未运行,Ability被启动后由INITIAL态进入INACTIVE状态。 - - - **INACTIVE**:未激活状态,表示当前窗口已显示但是无焦点状态,由于Window暂未支持焦点的概念,当前状态与ACTIVE一致。 - - - **ACTIVE**:前台激活状态,表示当前窗口已显示,并获取焦点,Ability在退到后台之前先由ACTIVE状态进入INACTIVE状态。 - - - **BACKGROUND**: 后台状态,表示当前Ability退到后台,Ability在被销毁后由BACKGROUND状态进入INITIAL状态,或者重新被激活后由BACKGROUND状态进入ACTIVE状态。 - -**PageAbility类型Ability生命周期回调如下图所示:** - -![PageAbility-Lifecycel-Callbacks](/images/readme/figures/page-ability-lifecycle-callbacks.png) - - - -**ServiceAbility类型Ability生命周期回调如下图所示:** - -![Service-Ability-Lifecycle-Callbacks](/images/readme/figures/service-ability-lifecycle-callbacks.jpg) - - - -## 目录 - -``` -foundation/ -└──foundation/aafwk/standard -   ├── frameworks -   │   └── kits -   │   └── ability # AbilityKit实现的核心代码 -   ├── interfaces -   │   └── innerkits -   │      └── want # Ability之间交互的信息载体的对外接口 - └── services - ├── abilitymgr # Ability管理服务框架代码 -   ├── common # 日志组件目录 -   ├── test # 测试目录 -   └── tools # aa命令代码目录 -``` - -## 使用说明 - -当前版本用户程序框架不具备权限管理的能力。 - -以下模块的JS接口为非正式API,仅供Launcher、Settings、SystemUI等系统应用使用,不排除对这些接口进行变更的可能性,后续版本将提供正式API。 - -- @ohos.feature_ability.d.ts - -- @ohos.napi_ability_manager.d.ts - -- abilityinfo.d.ts - -- abilitymissioninfo.d.ts - -- applicationinfo.d.ts - -- appprocessstate.ts - -- common.d.ts - -- elementname.d.ts - -- moduleinfo.d.ts - -- processinfo.d.ts - -- want.d.ts - -## **aa命令** - -**aa help** - -| 命令 | 描述 | -| ------- | ------------------ | -| aa help | 显示aa命令帮助信息 | - -**aa start** - -| 命令 | 描述 | -| --------------------------------------------------------- | ------------------------ | -| aa start [-d ] -a -b | 启动ability,设备ID 可空 | - -``` -示例: -aa start -d 12345 -a com.ohos.app.MainAbility -b com.ohos.app -``` - -**aa dump** - -| 命令 | 描述 | -| ---------- | --------------------- | -| aa dump -a | 打印栈中的Ability信息 | - -## 相关仓 -元能力子系统 - -appexecfwk_standard - -**aafwk_standard** - diff --git "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/10.\345\205\250\347\220\203\345\214\226\345\255\220\347\263\273\347\273\237.md" "b/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/10.\345\205\250\347\220\203\345\214\226\345\255\220\347\263\273\347\273\237.md" deleted file mode 100644 index 93cfed7a99385edd78a1069e685e908bbae73459..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/10.\345\205\250\347\220\203\345\214\226\345\255\220\347\263\273\347\273\237.md" +++ /dev/null @@ -1,108 +0,0 @@ ---- -title: 全球化子系统 -permalink: /pages/0101020a -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:18 ---- -# 全球化子系统 - -- [简介](#section11660541593) -- [系统架构](#section1558604311012) -- [目录](#section161941989596) -- [相关仓](#section1371113476307) - -## 简介 - -当OpenHarmony设备或应用在全球不同区域使用时,系统和应用需要满足不同市场用户关于语言、文化习俗的需求。全球化子系统提供支持多语言、多文化的能力,包括: - -- **资源管理能力** - - 根据设备类型、系统配置等信息,对系统资源和应用资源加载、解析和初始化,对外提供获取字符串、媒体等资源的接口。 - -- **国际化能力** - - 提供底层的资源回溯能力,同时对外提供丰富的国际化接口,包括时间日期格式化、数字格式化、电话号码格式化、单复数等。 - - -## 系统架构 - -**图 1** 全球化子系统架构图 - - -![](/images/readme/figures/全球化子系统架构图.png "全球化子系统架构图") - -## 目录 - -全球化子系统源代码在/base/global目录下。 - -轻量系统和小型系统的目录结构如下所示: - -``` -/base/global/ -├── i18n_lite # 国际化框架代码仓 -│ ├── frameworks # 国际化框架核心代码 -│ │ ├── i18n # 国际化模块 -│ │ │ ├── include # 接口文件 -│ │ │ ├── src # 实现代码 -│ │ │ └── test # 测试用例 -│ ├── interfaces # 国际化框架接口 -│ │ ├── kits # 应用接口 -│ │ │ ├── i18n # C/C++国际化能力接口 -│ │ │ └── js # JavaScript接口的C/C++支持 -├── resmgr_lite # 资源管理框架代码仓 -│ ├── frameworks # 资源管理框架核心代码 -│ │ ├── resmgr # 资源解析核心代码 -│ │ │ ├── include # 接口文件 -│ │ │ └── src # 实现代码 -│ ├── interfaces # 资源管理框架接口 -│ │ └── innerkits # 资源管理框架对子系统间接口 -├── cust_lite # 定制框架代码仓 -│ ├── frameworks # 定制框架核心代码 -│ │ ├── cust_lite # 定制框架模块 -│ │ │ ├── src # 实现代码 -│ │ │ └── test # 测试代码 -│ ├── interfaces # 定制框架接口 -│ │ └── innerkits # 定制框架子系统间接口 -``` - -标准系统的目录结构如下所示: - -``` -/base/global -├── i18n_standard # 国际化框架代码仓 -│ ├── frameworks # 国际化框架核心代码 -│ ├── interfaces # 国际化框架接口 -│ │ ├── js # 国际化框架JavaScript接口 -│ │ └── native # 国际化框架native接口 -├── resmgr_standard # 资源管理代码仓 -│ ├── frameworks # 资源管理核心代码 -│ │ ├── resmgr # 资源解析核心代码 -│ │ │ ├── include # 资源管理头文件 -│ │ │ ├── src # 资源管理实现代码 -│ │ │ └── test # 资源管理测试代码 -│ ├── interfaces # 资源管理接口 -│ │ ├── innerkits # 资源管理对子系统间接口 -│ │ └── js # 资源管理JavaScript接口 -``` - -## 相关仓 - -**全球化子系统** - -global\_cust\_lite - -global\_i18n\_lite - -global\_i18n\_standard - -global\_resmgr\_lite - -global\_resmgr\_standard - diff --git "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/11.\345\205\254\345\205\261\345\237\272\347\241\200\345\272\223.md" "b/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/11.\345\205\254\345\205\261\345\237\272\347\241\200\345\272\223.md" deleted file mode 100644 index 4e35241e93b29d050baa4ad7b1ad32f2d50fd89b..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/11.\345\205\254\345\205\261\345\237\272\347\241\200\345\272\223.md" +++ /dev/null @@ -1,56 +0,0 @@ ---- -title: 公共基础库 -permalink: /pages/0101020b -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:18 ---- -# 公共基础库 - -- [简介](#section11660541593) -- [目录](#section17271017133915) -- [相关仓](#section1249817110914) - -## 简介 - -公共基础类库提供了一些常用的C、C++开发增强API。包括如下部分: - -**C++部分:** - -- 文件、路径、字符串相关操作的能力增强接口; -- 读写锁、信号量、定时器、线程增强及线程池等接口; -- 安全数据容器、数据序列化等接口; -- 各子系统的错误码相关定义; -- C语言安全函数接口。 - -**C部分:** - -- 简易的数据存取接口kv\_store; -- 标准文件相关操作HAL接口; -- 其它一些内部功能,如定时器等。 - -## 目录 - -``` -/utils - ├── native # 工具类的native层实现 - ├── ndk_libraries_config # ndk库的配置目录 - └── system # 系统相关的预定义值和安全策略配 -``` - -## 相关仓 - -**公共基础库子系统** - -utils - -utils\_native - -[utils\_native\_lite](https://gitee.com/openharmony/utils_native_lite) - diff --git "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/12.\345\210\206\345\270\203\345\274\217\344\273\273\345\212\241\350\260\203\345\272\246\345\255\220\347\263\273\347\273\237.md" "b/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/12.\345\210\206\345\270\203\345\274\217\344\273\273\345\212\241\350\260\203\345\272\246\345\255\220\347\263\273\347\273\237.md" deleted file mode 100644 index 6629ffca7bbbb0a27a0f9b8eafd527c0a14fe19a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/12.\345\210\206\345\270\203\345\274\217\344\273\273\345\212\241\350\260\203\345\272\246\345\255\220\347\263\273\347\273\237.md" +++ /dev/null @@ -1,63 +0,0 @@ ---- -title: 分布式任务调度子系统 -permalink: /pages/0101020c -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:18 ---- -# 分布式任务调度子系统 - -- [简介](#section11660541593) -- [系统架构](#section13587185873516) -- [目录](#section161941989596) -- [相关仓](#section1371113476307) - -## 简介 - -分布式任务调度模块负责跨设备组件管理,提供访问和控制远程组件的能力,支持分布式场景下的应用协同。主要功能如下: - -- 远程启动元能力:跨设备拉起远端设备上的指定元能力。 -- 远程迁移元能力:将元能力跨设备迁移到远端设备。 -- 远程绑定元能力:跨设备绑定远端设备上的指定元能力。 -- 系统服务管理:提供系统服务的本地启动、注册、查询等功能;提供系统服务的跨设备查询功能。 - -## 系统架构 - -**图 1** 子系统架构图 - - -![](/images/readme/figures/dms-architecture_zh.png) - -## 目录 - -``` -/foundation/distributedschedule -├── dmsfwk # 分布式任务调度模块 -├── safwk # 系统服务框架模块 -├── samgr # 系统服务管理模块 -├── dms_fwk_lite # 轻量分布式任务调度模块 -├── safwk_lite # 轻量foundation进程 -├── samgr_lite # 轻量系统服务管理模块 -``` - -## 相关仓 - -**分布式任务调度子系统** - -distributedschedule\_dms\_fwk - -distributedschedule\_safwk - -distributedschedule\_samgr - -distributedschedule\_safwk\_lite - -hdistributedschedule\_samgr\_lite - -distributedschedule\_dms\_fwk\_lite \ No newline at end of file diff --git "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/13.\345\210\206\345\270\203\345\274\217\346\225\260\346\215\256\347\256\241\347\220\206\345\255\220\347\263\273\347\273\237.md" "b/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/13.\345\210\206\345\270\203\345\274\217\346\225\260\346\215\256\347\256\241\347\220\206\345\255\220\347\263\273\347\273\237.md" deleted file mode 100644 index 907293ea1117b874169bedd00cc305ba64b5acd5..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/13.\345\210\206\345\270\203\345\274\217\346\225\260\346\215\256\347\256\241\347\220\206\345\255\220\347\263\273\347\273\237.md" +++ /dev/null @@ -1,122 +0,0 @@ ---- -title: 分布式数据管理子系统 -permalink: /pages/0101020d -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:19 ---- -# 分布式数据管理子系统 - -- [简介](#section11660541593) -- [目录](#section161941989596) -- [说明](#section1312121216216) - - [本地数据管理说明](#section129654513264) - - [分布式数据服务说明](#section1961602912224) - -- [相关仓](#section1371113476307) - -## 简介 - -**子系统介绍** - -分布式数据管理子系统支持单设备的各种结构化数据的持久化,以及跨设备之间数据的同步、共享功能。开发者通过分布式数据管理子系统,能够方便地完成应用程序数据在不同终端设备间的无缝衔接,满足用户跨设备使用数据的一致性体验。 - -- 本地数据管理 - - 提供单设备上结构化数据的存储和访问能力。使用SQLite作为持久化存储引擎,提供了多种类型的本地数据库,分别是关系型数据库(Relational Database,RDB)和轻量级偏好数据库(Preferences),用以满足使用不同数据模型对应用数据进行持久化和访问的需求。 - - -- 分布式数据服务 - - 分布式数据服务支持数据跨设备相互同步,为用户提供在多种终端设备上一致的数据访问体验。通过结合帐号、应用和数据库三元组,分布式数据服务对数据进行隔离。在通过可信认证的设备间,分布式数据服务支持数据相互同步,提供跨设备的数据访问。 - - -**子系统架构** - -**图 1** 子系统架构图 - - -![](/images/readme/figures/zh-cn_image_0000001115748088.png) - -## 目录 - -子系统1-2层目录描述 - -``` -distributeddatamgr/ # 子系统目录 -├── appdatamgr # 本地数据管理组件目录 -└── distributeddatamgr # 分布式数据服务组件目录 - -third_party/ # 开源软件目录 -├── flatbuffers # flatbuffers代码目录 -└── sqlite # SQLite代码目录 -``` - -## 说明 - -### 本地数据管理说明 - -- 关系型数据库 - - 以下是几个基本概念: - - - **关系型数据库** - - 创建在关系模型基础上的数据库,以行和列的形式存储数据。 - - - **结果集** - - 指用户查询之后的结果集合,可以对数据进行访问。结果集提供了灵活的数据访问方式,可以更方便的拿到用户想要的数据。 - - - **SQLite数据库** - - 一款轻量级的数据库,是遵守ACID的关系型数据库组件。它是一个开源的项目 - - -- 轻量级偏好数据库 - - 以下是几个基本概念: - - - **Key-Value数据库** - - 一种以键值对存储数据的一种数据库。Key是关键字,Value是值。 - - - **非关系型数据库** - - 区别于关系数据库,不保证遵循ACID(Atomic、Consistency、Isolation及Durability)特性,不采用关系模型来组织数据,数据之间无关系,扩展性好。 - - - **偏好数据** - - 用户经常访问和使用的数据。 - - - -### 分布式数据服务说明 - -分布式数据服务(Distributed Data Service,DDS) 提供不同设备间数据库数据分布式的能力,主要采用KV数据模型: - -- **KV数据模型** - - “KV数据模型”是“Key-Value数据模型”的简称,“Key-Value”即“键-值”。它是一种NoSQL类型数据库,其数据以键值对的形式进行组织、索引和存储。 - - KV数据模型适合不涉及过多数据关系和业务关系的业务数据存储,比SQL数据库存储拥有更好的读写性能,同时在分布式场景中降低了数据库版本兼容和数据同步过程中冲突解决的复杂度而被广泛使用。分布式数据库也是基于KV数据模型,对外提供KV类型的访问接口。 - - -## 相关仓 - -分布式数据管理子系统 - -distributeddatamgr\_appdatamgr - -distributeddatamgr\_distributeddatamgr - -third\_party\_sqlite - -third\_party\_flatbuffers - diff --git "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/14.\345\210\206\345\270\203\345\274\217\346\226\207\344\273\266\345\255\220\347\263\273\347\273\237.md" "b/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/14.\345\210\206\345\270\203\345\274\217\346\226\207\344\273\266\345\255\220\347\263\273\347\273\237.md" deleted file mode 100644 index 8de4ddb15eba4a2052e310a966279cc8de224267..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/14.\345\210\206\345\270\203\345\274\217\346\226\207\344\273\266\345\255\220\347\263\273\347\273\237.md" +++ /dev/null @@ -1,293 +0,0 @@ ---- -title: 分布式文件子系统 -permalink: /pages/0101020e -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:19 ---- -# 分布式文件子系统 - -- [简介](#section104mcpsimp) - - [系统架构](#section110mcpsimp) - -- [目录结构](#section113mcpsimp) -- [约束](#section117mcpsimp) -- [说明](#section125mcpsimp) - - [接口说明](#section127mcpsimp) - - [使用说明](#section149mcpsimp) - -- [相关仓](#section178mcpsimp) - -## 简介 - -分布式文件子系统当前向应用程序提供用于的 IO 的 JS 接口。其具体包括用于管理文件的基本文件接口,用于管理目录的基本目录接口,用于获取文件信息的统计接口,用于流式读写文件的流式接口,以及接收 URI 而非绝对路径的沙盒接口。 - -### 系统架构 - -当前分布式文件子系统仅面向应用提供本地 JS 文件接口,这些接口分别通过 FileIO 模块以及 File 模块提供。架构上,分布式文件子系统实现了自研的 LibN,其抽象了 NAPI 层接口,向分布式文件子系统提供包括基本类型系统、内存管理、通用编程模型在内的基本能力。本系统对外依赖 JS 开发框架提供将 JS 接口转换为 C++ 代码的能力,依赖用户程序框架提供应用相关目录,依赖 GLIBC Runtimes 提供 IO 能力。 - -**图 1** 分布式文件子系统架构图 -![](/images/readme/figures/分布式文件子系统架构图.png "分布式文件子系统架构图") - -## 目录结构 - -``` -foundation/distributeddatamgr/distributedfile -├── interfaces # 接口层代码 -│ └── kits # 对外接口 -``` - -## 约束 - -本地 IO 接口 - -- 目前仅支持 UTF-8/16 编码; -- 目前 URI 暂不支持外部存储目录; - -## 说明 - -### 接口说明 - -当前分布式文件子系统开放本地文件目录访问接口,按照功能,其可划分为如下几种类型: - -**表 1** 接口类型表 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

接口类型

-

接口用途

-

相关模块

-

接口示例(类名.方法名)

-

基本文件接口

-

需要用户提供绝对路径或文件描述符(fd),提供创建、修改及访问文件,或修改文件权限的能力

-

@OHOS.distributedfile.fileio

-

accessSync

-

chownSync

-

chmodSync

-

基本目录接口

-

需要用户提供绝对路径,提供读取目录及判断文件类型的能力

-

@OHOS.distributedfile.fileio

-

Dir.openDirSync

-

基本Stat接口

-

需要用户提供绝对路径,提供包括文件大小、访问权限、修改时间在内的基本统计信息

-

@OHOS.distributedfile.fileio

-

Stat.statSync

-

流式文件接口

-

需要用户提供绝对路径或文件描述符,提供流式读写文件的能力

-

@OHOS.distributedfile.fileio

-

Stream.createStreamSync

-

Stream.fdopenStreamSync

-

沙盒文件接口

-

需要用户提供 URI,提供基本文件接口、基本目录接口及基本统计接口能力的子集能力,或这些能力的组合能力

-

@system.file

-

move

-

copy

-

list

-
- -其中,沙盒文件接口所使用的 URI 具体可划分为三种类型: - -**表 2** URI类型表 - - - - - - - - - - - - - - - - - - - - - - - - -

目录类型

-

路径前缀

-

访问可见性

-

说明

-

临时目录

-

internal://cache/

-

仅本应用可见

-

可读写,随时可能清除,不保证持久性。一般用作下载临时目录或缓存目录。

-

应用私有目录

-

internal://app/

-

仅本应用可见

-

随应用卸载删除。

-

外部存储

-

internal://share/

-

所有应用可见

-

随应用卸载删除。其他应用在有相应权限的情况下可读写此目录下的文件。

-
- -### 使用说明 - -当前分布式文件子系统所提供的 IO 接口,按照编程模型,可划分为如下几种类型: - -- 同步编程模型 - - 名称包含 Sync 的接口实现为同步模型。用户在调用这些接口的时候,将同步等待,直至执行完成,执行结果以函数返回值的形式返回。 - - 下例以只读的方式打开一个文件流,接着试图读取其中前 4096 个字节并将之转换为 UTF-8 编码的字符串,最后关闭该文件流。 - - ``` - import fileio from '@OHOS.distributedfile.fileio'; - - try { - var ss = fileio.Stream.createStreamSync("tmp", "r") - buf = new ArrayBuffer(4096) - ss.readSync(buf) - console.log(String.fromCharCode.apply(null, new Uint8Array(buf))) - ss.closeSync() - } - catch (e) { - console.log(e); - } - ``` - - -- 异步编程模型:Promise - - @OHOS.distributedfile.fileio 模块中,名称不含 Sync 的接口,在不提供最后一个函数型参数 callback 的时候,即实现为 Promsie 异步模型。Promise 异步模型是 OHOS 标准异步模型之一。用户在调用这些接口的时候,接口实现将异步执行任务,同时返回一个 promise 对象,其代表异步操作的结果。在返回的结果的个数超过一个时,其以对象属性的形式返回。 - - 下例通过 Promise 链依次完成:以只读方式打开文件流、尝试读取文件前 4096 个字节、显示读取内容的长度,最后关闭文件。 - - ``` - import fileio from '@OHOS.distributedfile.fileio'; - - try { - let openedStream - fileio.Stream.createStream("test.txt", "r") - .then(function (ss) { - openedStream = ss; - return ss.read(new ArrayBuffer(4096)) - }) - .then(function (res) { - console.log(res.bytesRead); - console.log(String.fromCharCode.apply(null, new Uint8Array(res.buffer))) - return openedStream.close() - }) - .then(function (undefined) { - console.log("Stream is closed") - }) - .catch(function (e) { - console.log(e) - }) - } catch (e) { - console.log(e) - } - ``` - - -- 异步编程模型:Callback - - @OHOS.distributedfile.fileio 模块中,名字不含 Sync 的接口,在提供最后一个函数性参数 callback 的时候,即实现为 Callback 异步模型。Callback 异步模型是 OHOS 标准异步模型之一。用户在调用这些接口的时候,接口实现将异步执行任务。任务执行结果以参数的形式提供给用户注册的回调函数。这些参数的第一个是 Error 或 undefined 类型,分别表示执行出错与正常。 - - 下例异步创建文件流,并在文件流的回调函数中异步读取文件的前 4096 字节,接着在读取文件的回调函数中异步关闭文件。 - - ``` - import fileio from '@OHOS.distributedfile.fileio'; - - try { - fileio.Stream.createStream("./testdir/test_stream.txt", "r", function (err, ss) { - if (!err) { - ss.read(new ArrayBuffer(4096), {}, function (err, buf, readLen) { - if (!err) { - console.log('readLen: ' + readLen) - console.log('data: ' + String.fromCharCode.apply(null, new Uint8Array(buf))) - } else { - console.log('Cannot read from the stream ' + err) - } - ss.close(function (err) { - console.log(`Stream is ${err ? 'not' : ''}closed`) - }); - }) - } else { - console.log('Cannot open the stream ' + err) - } - }) - } catch (e) { - console.log(e) - } - ``` - - -- 异步编程模型:Legacy - - @system.file 模块中的所有接口都实现为 Legacy 异步模型。用户在调用这些接口的时候,需要提供 success、fail 及 complete 三个回调。在正确提供参数的情况下,当异步任务完成后,接口会根据是否成功,分别调用 success 回调或 fail 回调,并最终调用 complete 回调。 - - 下例异步判断 URI 所指向的文件是否存在,并相应提供三个回调用于打印判断结果。 - - ``` - import file from '@system.file' - - file.access({ - uri: 'internal://app/test.txt', - success: function() { - console.log('call access success.'); - }, - fail: function(data, code) { - console.error('call fail callback fail, code: ' + code + ', data: ' + data); - }, - complete: function () { - console.log('call access finally.'); - } - }); - - console.log("file access tested done") - ``` - - -## 相关仓 - -**分布式文件** - -distributeddatamgr\_distributedfile - diff --git "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/15.\345\210\206\345\270\203\345\274\217\350\275\257\346\200\273\347\272\277\345\255\220\347\263\273\347\273\237.md" "b/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/15.\345\210\206\345\270\203\345\274\217\350\275\257\346\200\273\347\272\277\345\255\220\347\263\273\347\273\237.md" deleted file mode 100644 index e602e60033254949cec36466fc5f3aa53bd0e72d..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/15.\345\210\206\345\270\203\345\274\217\350\275\257\346\200\273\347\272\277\345\255\220\347\263\273\347\273\237.md" +++ /dev/null @@ -1,101 +0,0 @@ ---- -title: 分布式软总线子系统 -permalink: /pages/0101020f -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:19 ---- -# 分布式软总线子系统 - -- [简介](#section11660541593) -- [系统架构](#section342962219551) -- [目录](#section161941989596) -- [约束](#section119744591305) -- [使用说明](#section1312121216216) - - [进程间通信](#section129654513264) - - [软总线](#section36252592710) - -- [相关仓](#section1371113476307) - -## 简介 - -分布式软总线子系统旨在为OpenHarmony系统提供的通信相关的能力,包括:WLAN服务能力、蓝牙服务能力、软总线、进程间通信RPC(Remote Procedure Call)等通信能力。 - -WLAN服务:为用户提供WLAN基础功能、P2P(peer-to-peer)功能和WLAN消息通知的相应服务,让应用可以通过WLAN和其他设备互联互通。 - -蓝牙服务:为应用提供传统蓝牙以及低功耗蓝牙相关功能和服务。 - -软总线:为应用和系统提供近场设备间分布式通信的能力,提供不区分通信方式的设备发现,连接,组网和传输功能。 - -进程间通信:提供不区分设备内或设备间的进程间通信能力。 - -## 系统架构 - -**图 1** 分布式软总线子系统架构图 - - -![](/images/readme/figures/zh-cn_image_0000001162307895.png) - -## 目录 - -分布式软总线子系统主要代码目录结构如下: - -``` -/foundation/communication -├── bluetooth # 蓝牙功能代码 -├── dsoftbus # 软总线功能代码 -├── ipc # 进程间通信代码 -└── wifi # WLAN功能代码 -``` - -## 约束 - -- 组网限制:必须确保设备在同一个局域网中。 - -## 使用说明 - -### 进程间通信 - -在使用RPC时,请求服务的一端进程可获取提供服务一端所在进程的代理 (Proxy),并通过此代理读写数据来实现进程间的数据通信,其详细过程如下: - -1. 实现服务端及其提供的能力。 -2. 请求服务的一端会建立一个服务提供端的代理对象,这个代理对象具备和服务提供端一样的功能,若想访问服务提供端中的某个方法,只需要访问代理对象中对应的方法即可。 -3. 服务提供端处理接收到的请求,处理完之后通过驱动返回处理结果给代理对象。 -4. 代理对象将请求结果进一步返回给请求服务端。 - -### 软总线 - -- 组网 - -1. 服务启动之后,获取已经在线的设备列表。 -2. 注册上下线监听,通过回调通知感知设备列表变化。 -3. 获取设备的Id、设备名称、设备类型。 -4. 获取指定设备的设备类型,组网类型,设备能力等更多信息。 -5. 进程退出时,删除上下线监听。 - -- 传输 - -1. 创建会话服务并注册监听回调函数。 -2. 待组网设备上线后,建立与指定设备的会话。 -3. 若会话获取成功,可发送数据。 -4. 待会话不使用时,关闭已打开的会话通道。 -5. 业务明确不使用分布式传输(如进程退出)时,移除已创建的会话服务。 - -## 相关仓 - -**分布式软总线子系统** - -communication\_bluetooth - -communication\_dsoftbus - -communication\_ipc - -communication\_wifi - diff --git "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/16.\345\215\207\347\272\247\345\255\220\347\263\273\347\273\237.md" "b/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/16.\345\215\207\347\272\247\345\255\220\347\263\273\347\273\237.md" deleted file mode 100644 index 4accca34be9e2f9c203eb760792d68be1d068fb4..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/16.\345\215\207\347\272\247\345\255\220\347\263\273\347\273\237.md" +++ /dev/null @@ -1,94 +0,0 @@ ---- -title: 升级子系统 -permalink: /pages/01010210 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:19 ---- -# 升级子系统 - -- [简介](#section184mcpsimp) -- [目录](#section212mcpsimp) -- [相关仓](#section251mcpsimp) - -## 简介 - -OpenHarmony升级子系统用来支持OpenHarmony设备的OTA\(Over The Air\)升级。整个升级子系统包括如下几块: - -1. 升级包制作工具 - - 升级包制作工具是使用python开发,运行在PC端用来制作升级包的工具。它首先会打包各个升级镜像,然后对升级包进行签名,同时生成升级包执行脚本,最后制作出升级包。工具生成升级脚本,设备侧解析执行脚本。最终完成所有的升级动作。 - - 升级包里面有两个文件,包括build\_tools.zip 和update.bin。 - - - build\_tools.zip:用来辅助升级的工具,包括升级的可执行文件和升级脚本 - - update.bin:TLV编码的文件,所有的升级内容按照TLV格式序列化存储,最终生成update.bin - - 工具对update.bin 和最终生成的升级包\(zip 压缩文件\)分别进行签名。 - -2. 升级服务 - - 升级服务是用来搜索,下载和触发升级。 - -3. 升级包安装 - - 升级包安装是升级子系统的核心功能,主要包括: - - 1. 从misc分区获取升级命令,根据不同的命令执行不同的任务。 - 2. 对升级包进行解压和合法性效验。 - 3. 启动升级进程,并解析出升级脚本。 - 4. 根据升级脚本安装各个组件包。 - 5. 完成升级后,进行后处理。如清理升级包,记录升级状态等。 - -4. 升级客户端 - - 升级客户端是用来触发搜包和下载的app。 - - -在进行应用的开发前,开发者应了解以下基本概念: - -- OTA - - Over The Air 的缩写。 OTA 是无线升级的一种方式。升级包通过网络下载到设备中。由设备通过升级子系统进行升级。 - -- 全量包 - - 全量包是完整的镜像,由升级子系统将全量包写到分区,达到更新分区的目的。 - -- 差分包 - - 根据两个特定版本\(源版本,目标版本\)之间的差异,使用bsdiff生成差分数据,升级子系统根据差分数据制作差分包。 - - -## 目录 - -``` -base/update # 升级子系统仓 -├── app # 升级客户端应用代码 -├── packaging_tools # 升级包制作工具代码 -├── updater # 升级包安装代码 -│ ├── interfaces # 对外模块接口定义 -│ ├── resources # 升级子系统用户界面图片资源,包括动画,进度条图片等 -│ ├── services # 升级包安装组件逻辑代码 -│ └── utils # 升级子系统通用代码,包括字符串处理函数,文件处理函数 -└── updateservice # 升级服务引擎代码 -``` - -## 相关仓 - -**升级子系统** - -update\_app - -update\_updateservice - -update\_updater - -update\_packaging\_tools - diff --git "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/17.\345\220\257\345\212\250\346\201\242\345\244\215\345\255\220\347\263\273\347\273\237.md" "b/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/17.\345\220\257\345\212\250\346\201\242\345\244\215\345\255\220\347\263\273\347\273\237.md" deleted file mode 100644 index 9163f7f8fb35f75db9e5af1ef35a3b9618e2b5b4..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/17.\345\220\257\345\212\250\346\201\242\345\244\215\345\255\220\347\263\273\347\273\237.md" +++ /dev/null @@ -1,318 +0,0 @@ ---- -title: 启动恢复子系统 -permalink: /pages/01010211 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:19 ---- -# 启动恢复子系统 - -- [简介](#section11660541593) -- [目录](#section161941989596) -- [约束](#section1718733212019) -- [使用说明](#section8533192617117) -- [相关仓](#section1371113476307) - -## 简介 - -启动恢复负责在内核启动之后到应用启动之前的系统关键进程和服务的启动过程以及设备恢复出厂设置的功能。涉及以下组件: - -- init组件 - - 支持使用LiteOS-A内核的平台,当前包括:Hi3516DV300平台和Hi3518EV300平台。 - - 负责处理从内核加载第一个用户态进程开始,到第一个应用程序启动之间的系统服务进程启动过程。启动恢复子系统除负责加载各系统关键进程之外,还需在启动的同时设置其对应权限,并在子进程启动后对指定进程实行保活(若进程意外退出要重新启动),对于特殊进程意外退出时,启动恢复子系统还要执行系统复位操作。 - - -- appspawn应用孵化器组件 - - 支持使用LiteOS-A内核的平台,当前包括:Hi3516DV300平台和Hi3518EV300平台。 - - 负责接受应用程序框架的命令孵化应用进程,设置其对应权限,并调用应用程序框架的入口。 - -- bootstrap启动引导组件 - - 支持使用LiteOS-M内核的平台,当前包括:Hi3861平台。 - - 提供了各服务和功能的启动入口标识。在SAMGR启动时,会调用boostrap标识的入口函数,并启动系统服务。 - -- syspara系统属性组件 - - 负责提供获取与设置操作系统相关的系统属性。 - - LiteOS-M内核和LiteOS-A内核的平台,包括:Hi3861平台,Hi3516DV300平台,Hi3518EV300平台。支持的系统属性包括:默认系统属性、OEM厂商系统属性和自定义系统属性。OEM厂商部分仅提供默认值,具体值需OEM产品方按需进行调整,详见“[使用说明](#section8533192617117)”部分。 - - -## 目录 - -**表 1** 启动恢复源代码目录结构 - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

描述

-

适配平台

-

base/startup/appspawn_lite

-

应用孵化器组件,appspawn进程,负责通过IPC机制接收Ability Manager Service消息,然后根据消息解析结果启动应用进程并赋予其对应权限。

-

Hi3516DV300

-

Hi3518EV300

-

base/startup/bootstrap_lite

-

启动引导组件,启动系统核心服务外的其他服务。

-

Hi3861

-

base/startup/init_lite

-

init组件,init进程,内核完成初始化后加载的第一个用户态进程,启动后解析/etc/init.cfg配置文件,并根据解析结果拉起其他系统关键进程,同时分别赋予其对应权限。

-

Hi3516DV300

-

Hi3518EV300

-

base/startup/syspara_lite

-

系统属性组件。提供获取设备信息接口,如:产品名、品牌名、品类名、厂家名等。

-

Hi3861

-

Hi3516DV300

-

Hi3518EV300

-
- -``` -base/startup/ -├── appspawn_standard # 标准系统应用孵化器组件 -│ ├── include # 头文件目录 -│ ├── parameter # 系统参数 -│ ├── src # 服务程序源码 -│ └── test # 测试代码 -├── appspawn_lite # 小型系统应用孵化器组件 -│ └── services -│ ├── include # 应用孵化器组件头文件目录 -│ ├── src # 应用孵化器组件源文件目录 -│ └── test # 应用孵化器组件测试用例源文件目录 -├── bootstrap_lite # 启动引导组件 -│ └── services -│ └── source # 启动引导组件源文件目录 -├── init_lite # init组件 -│ ├── initsync # 分阶段启动源文件目录 -│ ├── interfaces # 对外接口目录 -│ └── services -│ ├── include # init组件头文件目录 -│ ├── src # init组件源文件目录 -│ └── test # init组件测试用例源文件目录 -└── syspara_lite # 系统属性组件 - ├── adapter # 系统属性适配层源文件目录 - ├── frameworks # 系统属性组件源文件目录 - ├── hals # 系统属性组件硬件抽象层头文件目录 - ├── interfaces # 系统属性组件对外接口目录 - └── simulator # 模拟器适配 -``` - -## 约束 - -系统属性:OEM厂商相关仅提供默认值,具体值需产品方按需进行调整。 - -## 使用说明 - -- init的配置文件 - - init配置文件包含了所有需要由init进程启动的系统关键服务的服务名、可执行文件路径、权限和其他属性信息,该文件位于代码仓库/vendor/hisilicon/hispark\_aries/init\_configs/目录,部署在/etc/下,文件名称为init.cfg,采用json格式,文件大小目前限制在100KB以内。 - - init进程启动后首先读取/etc/init.cfg,然后解析其json内容,并根据解析结果依次加载系统服务。配置文件格式和内容说明如下所示: - - -``` -{ - "jobs" : [{ - "name" : "pre-init", -------- 在init之前执行的job,可以放置一些启动进程之前的预操作(如新建文件夹等) - "cmds" : [ -------- 当前job支持的命令集合(当前cmd仅支持start/mkdir/chmod/chown/mount) - -------- 命令名称和参数(长度<=128字节)之间有且只能有一个空格 - "mkdir /testdir", -------- 创建文件夹命令,mkdir和目标文件夹之间有且只能有一个空格 - "chmod 0700 /testdir", -------- 修改权限命令,chmod 权限 目标 之间间隔有且仅有一个空格,权限必须为0xxx格式 - "chown 99 99 /testdir",-------- 修改属组命令,chown uid gid 目标 之间间隔有且仅有一个空格 - "mkdir /testdir2", - "mount vfat /dev/mmcblk0p0 /testdir2 noexec nosuid" -------- mount命令,格式为:mount 文件系统类型 source target flags data - -------- flags当前仅支持nodev、noexec、nosuid和rdonly,各项均以一个空格分开 - ] - }, { - "name" : "init", -------- job名称当前仅支持识别“pre-init”、“init”和“post-init” - "cmds" : [ -------- 单个job目前最多支持30条cmd - "start service1", -------- 启动服务命令1 - "start service2" -------- 启动服务命令2(可以根据需要调整命令在数组中的顺序,init进程将根据解析顺序依次执行) - ] - }, { - "name" : "post-init", -------- 在init之后执行的 job,可以放置一些启动进程之后的操作 - "cmds" : [] - } - ], - "services" : [{ -------- service集合(数组形式),包含了init进程需要启动的所有系统服务(当前最多支持100个服务) - "name" : "service1", -------- 当前服务的服务名,须确保非空且长度<=32字节 - "path" : "/bin/process1" -------- 当前服务的可执行文件全路径,须确保非空且长度<=64字节 - "uid" : 1, -------- 当前服务进程的uid值 - "gid" : 1, -------- 当前服务进程的gid值 - "once" : 0, -------- 当前服务进程是否为一次性进程 - 0 --- 当前服务非一次性进程,当进程因任何原因退出时,init收到SIGCHLD信号后将重新启动该服务进程 - 非0 --- 当前服务为一次性进程,当进程因任何原因退出时,init不会重新启动该服务进程 - "importance" : 1, -------- 当前服务是否为关键系统进程 - 0 --- 当前服务非关键系统进程,当进程因任何原因退出时,init不会做系统复位操作 - 非0 --- 当前服务为关键系统进程,当进程因任何原因退出时,init收到SIGCHLD信号后进行系统复位重启 - "caps" : [0, 1, 2, 5] -------- 当前服务所需的capability值,根据安全子系统已支持的capability,评估所需的capability,遵循最小权限原则配置(当前最多可配置100个值) - }, { - "name" : "service2", -------- 下一个需要init启动的服务。此处服务的顺序与启动顺序无关,启动顺序取决于上面job中的cmd顺序。 - "path" : "/bin/process2", - "uid" : 2, - "gid" : 2, - "once" : 1, - "importance" : 0, - "caps" : [ ] - } - ] -} -``` - -**表 2** cmds支持列表 - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

命令名称

-

命令格式

-

命令说明

-

start

-

start ServiceName 间隔有且仅有一个空格

-

启动服务,服务名称与文件中services数组中服务名称相同

-

mkdir

-

mkdir /xxxx/xxx 间隔有且仅有一个空格

-

创建目录

-

chmod

-

chmod 0xxx /xxx/xx 间隔有且仅有一个空格

-

修改权限,权限值必须为0xxx格式,如0755,0600等,需要遵循权限最小原则配置

-

chown

-

chown uid gid /xxx/xx 间隔有且仅有一个空格

-

修改属组

-

mount

-

mount fileSysType source target flags data

-

间隔有且仅有一个空格

-

挂载命令,其中flags目前仅支持nodev、noexec、nosuid和rdonly,其它字串均判定为data项

-
- -需要注意的是,init.cfg文件的修改需要保持json格式不被破坏,否则init进程解析失败后不会启动任何服务。对于配置的服务权限(uid/gid/capability)需要符合安全子系统要求且遵循权限最小原则。另外,对于once和importance项均为0的服务,若其在4分钟内连续退出次数超过4次,则init将终止重新启动该服务的操作。 - -- 系统参数 - - OEM厂商相关系统属性 - - Hi3516DV300,Hi3518EV300开发板需要修改vendor/hisilicon/hispark\_aries/hals/utils/sys\_param目录下源文件: - - ``` - static const char HOS_PRODUCT_TYPE[] = {"****"}; - static const char HOS_MANUFACTURE[] = {"****"}; - static const char HOS_BRAND[] = {"****"}; - static const char HOS_MARKET_NAME[] = {"****"}; - static const char HOS_PRODUCT_SERIES[] = {"****"}; - static const char HOS_PRODUCT_MODEL[] = {"****"}; - static const char HOS_SOFTWARE_MODEL[] = {"****"}; - static const char HOS_HARDWARE_MODEL[] = {"****"}; - static const char HOS_HARDWARE_PROFILE[] = {"aout:true,display:true"}; - static const char HOS_BOOTLOADER_VERSION[] = {"bootloader"}; - static const char HOS_SECURE_PATCH_LEVEL[] = {"2020-6-5"}; - static const char HOS_ABI_LIST[] = {"****"}; - ``` - - Hi3861开发板需要修改vendor/hisilicon/hispark\_pegasus/hals/utils/sys\_param目录下源文件: - - ``` - static const char HOS_PRODUCT_TYPE[] = {"****"}; - static const char HOS_MANUFACTURE[] = {"****"}; - static const char HOS_BRAND[] = {"****"}; - static const char HOS_MARKET_NAME[] = {"****"}; - static const char HOS_PRODUCT_SERIES[] = {"****"}; - static const char HOS_PRODUCT_MODEL[] = {"****"}; - static const char HOS_SOFTWARE_MODEL[] = {"****"}; - static const char HOS_HARDWARE_MODEL[] = {"****"}; - static const char HOS_HARDWARE_PROFILE[] = {"aout:true,display:true"}; - static const char HOS_BOOTLOADER_VERSION[] = {"bootloader"}; - static const char HOS_SECURE_PATCH_LEVEL[] = {"2020-6-5"}; - static const char HOS_ABI_LIST[] = {"****"}; - ``` - - - 获取默认系统属性 - - ``` - const char* value1 = GetProductType(); - printf("Product type =%s\n", value1); - const char* value2 = GetManufacture(); - printf("Manufacture =%s\n", value2); - const char* value3 = GetBrand(); - printf("GetBrand =%s\n", value3); - ``` - - - - 设置获取自定义系统属性 - - ``` - const char* defSysParam = "data of sys param ***..."; - char key[] = "rw.parameter.key"; - char value[] = "OEM-hisi-10.1.0"; - int ret = SetParameter(key, value); - char valueGet[128] = {0}; - ret = GetParameter(key, defSysParam, valueGet, 128); - printf("value = %s\n", valueGet); - ``` - - - -## 相关仓 - -启动恢复子系统 - -startup\_syspara\_lite - -startup\_appspawn\_lite - -startup\_bootstrap\_lite - -startup\_init\_lite - diff --git "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/18.\345\233\276\345\275\242\345\255\220\347\263\273\347\273\237.md" "b/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/18.\345\233\276\345\275\242\345\255\220\347\263\273\347\273\237.md" deleted file mode 100644 index ee267af9e41589bc8dd67a7fd0ad747c179db632..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/18.\345\233\276\345\275\242\345\255\220\347\263\273\347\273\237.md" +++ /dev/null @@ -1,179 +0,0 @@ ---- -title: 图形子系统 -permalink: /pages/01010212 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:19 ---- -# 图形子系统 - -- [1.1 轻量系统](#section1346303311377) - - [简介](#section1165992615384) - - [目录](#section141331948134020) - - [约束](#section15729113104112) - - [说明](#section812962919413) - - [相关仓](#section12651205434115) - -- [1.2 标准系统](#section1249610812538) - - [简介](#section1374615251510) - - [目录](#section16751364713) - - [约束](#section126494189715) - - [编译构建](#section883114292070) - - [说明](#section1351214227564) - - [相关仓](#section11578621131119) - - -图形子系统主要包括UI组件、布局、动画、字体、输入事件、窗口管理、渲染绘制等模块,构建基于轻量OS应用框架满足硬件资源较小的物联网设备或者构建基于标准OS的应用框架满足富设备(如平板和轻智能机等)的OpenHarmony系统应用开发。 - -## 1.1 轻量系统 - -### 简介 - -图形子系统主要包括UI组件、布局、动画、字体、输入事件、窗口管理、渲染绘制等模块,构建基于轻量OS的应用框架,满足硬件资源较小的物联网设备的OpenHarmony系统应用开发。 - -**图 1** 图形子系统架构图 -![](/images/readme/figures/图形子系统架构图.png "图形子系统架构图") - -各模块介绍: - -- View:应用组件,包括UIView、UIViewGoup、UIButton、UILabel、UILabelButton、UIList、UISlider等。 -- Animator:动画模块,开发者可以自定义动画。 -- Layout:布局控件,包括Flexlayout、GridLayout、ListLayout等。 -- Transform:图形变换模块,包括旋转、平移、缩放等。 -- Event:事件模块,包括click、press、drag、long press等基础事件。 -- Rendering engine:渲染绘制模块。 -- 2D graphics library:2D绘制模块,包括直线、矩形、圆、弧、图片、文字等绘制。包括软件绘制和硬件加速能力对接。 -- Multi-language:多语言模块,用于处理不用不同语言文字的换行、整形等。 -- Image library:图片处理模块,用于解析和操作不同类型和格式的图片,例如png、jpeg、ARGB8888、ARGB565等 -- WindowManager:窗口管理模块,包括窗口创建、显示隐藏、合成等处理。 -- InputManager:输入事件管理模块。 - -### 目录 - -``` -/foundation/graphic -├── surface # 共享内存 -├── ui # UI模块,包括UI控件、动画、字体等功能 -├── utils # 图形基础库和硬件适配层 -└── wms # 窗口管理和输入事件管理 -``` - -### 约束 - -- 图形组件不支持多线程并发操作,建议相关操作都在ui线程中执行; -- utils/interfaces/innerkits/graphic\_config.h文件列举了图形部分可配置功能的宏开关,需要在编译前配置,配置时需要注意部分宏开关是分平台配置的。 - -### 说明 - -参考各仓README以及test目录 - -### 相关仓 - -**图形子系统** - -graphic\_surface - -graphic\_ui - -graphic\_wms - -graphic\_utils - -## 1.2 标准系统 - -### 简介 - -**Graphic子系统** 提供了图形接口能力和窗口管理接口能力, 支持应用程序框架子系统和ACE等子系统使用。支持所有运行标准系统的设备使用。 - -其主要的结构如下图所示: - -![](/images/readme/figures/zh-cn_image_0000001115748590.png) - -- Surface - - 图形缓冲区管理接口,负责管理图形缓冲区和高效便捷的轮转缓冲区。 - -- Vsync - - 垂直同步信号管理接口,负责管理所有垂直同步信号注册和响应。 - -- WindowManager - - 窗口管理器接口,负责创建和管理窗口。 - -- WaylandProtocols - - 窗口管理器和合成器的通信协议。 - -- Compositor - - 合成器,负责合成各个图层。 - -- Renderer - - 合成器的后端渲染模块。 - -- Wayland protocols - - Wayland 进程间通信协议 - -- Shell - - 提供多窗口能力 - -- Input Manager - - 多模输入模块,负责接收事件输 - - -### 目录 - -``` -foundation/graphic/standard/ -├── frameworks # 框架代码目录 -│ ├── bootanimation # 开机动画目录 -│ ├── surface # Surface代码 -│ ├── vsync # Vsync代码 -│ └── wm # WindowManager代码 -├── interfaces # 对外接口存放目录 -│ ├── innerkits # native接口存放目录 -│ └── kits # js/napi接口存放目录 -└── utils # 小部件存放目录 -``` - -### 约束 - -语言版本:C++11及以上 - -### 编译构建 - -可以依赖的接口有: - -- graphic\_standard:libwms\_client -- graphic\_standard:libsurface -- graphic\_standard:libvsync\_client - -### 说明 - -参考各仓README以及test目录 - -### 相关仓 - -**图形子系统** - -graphic\_standard - -ace\_ace\_engine - -aafwk\_standard - -multimedia\_media\_standard - -multimedia\_camera\_standard - diff --git "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/19.\345\244\232\346\250\241\350\276\223\345\205\245\345\255\220\347\263\273\347\273\237.md" "b/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/19.\345\244\232\346\250\241\350\276\223\345\205\245\345\255\220\347\263\273\347\273\237.md" deleted file mode 100644 index 87e9a06a63ac077cbc47cee341f10b7ef51d8a5e..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/19.\345\244\232\346\250\241\350\276\223\345\205\245\345\255\220\347\263\273\347\273\237.md" +++ /dev/null @@ -1,49 +0,0 @@ ---- -title: 多模输入子系统 -permalink: /pages/01010213 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:19 ---- -# 多模输入子系统 - -- [简介](#section11660541593) -- [目录](#section14408467105) -- [使用](#section18111235161011) -- [相关仓](#section135327891219) - -## 简介 - -OpenHarmony旨在为开发者提供NUI(Natural User Interface)的交互方式,有别于传统操作系统的输入,在OpenHarmony上,我们将多种维度的输入整合在一起,开发者可以借助应用程序框架、系统自带的UI组件或API接口轻松地实现具有多维、自然交互特点的应用程序。 - -具体来说,多模输入子系统目前支持传统的输入交互方式,例如按键、触控等。 - -## 目录 - -``` -/foundation/multimodalinput/input -├── common # 公共代码 -├── interfaces # 对外接口存放目录 -│ └── native # 对外native层接口存放目录 -│ └── innerkits # 对系统内部子系统提供native层接口存放目录 -├── service # 服务框架代码 -├── sa_profile # 服务启动配置文件 -├── uinput # 输入事件注入模块 -``` - -## 使用 - -多模输入目前提供的接口为事件注入接口,该接口目前仅对系统应用开放。 - -## 相关仓 - -**多模输入子系统** - -multimodalinput\_input - diff --git "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/20.\345\252\222\344\275\223\345\255\220\347\263\273\347\273\237.md" "b/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/20.\345\252\222\344\275\223\345\255\220\347\263\273\347\273\237.md" deleted file mode 100644 index 6a12ba5120631f34855622de2e1893b3a4068f55..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/20.\345\252\222\344\275\223\345\255\220\347\263\273\347\273\237.md" +++ /dev/null @@ -1,133 +0,0 @@ ---- -title: 媒体子系统 -permalink: /pages/01010214 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:19 ---- -# 媒体子系统 - -- [简介](#section11660541593) -- [系统架构](#section11660541594) -- [目录](#section161941989596) -- [约束](#section119744591305) -- [使用说明](#section1312121216216) -- [安装](#section11914418405) -- [相关仓](#section1371113476307) - -## 简介 - -媒体子系统为开发者提供一套简单且易于理解的接口,使得开发者能够方便接入系统并使用系统的媒体资源。 - -媒体子系统包含了音视频、相机相关媒体业务,提供以下常用功能: - -- 音频播放和录制。 -- 视频播放和录制。 -- 相机拍照和录制。 - -## 系统架构 - -**图 1** OpenHarmony媒体子系统架构图 - -![](/images/readme/figures/OpenHarmony媒体架构图.png) - -- **Media**: 为应用提供播放、录制等接口,通过跨进程调用或直接调用方式,调用媒体引擎Gstreamer、Histreamer或其它引擎。 - - mini设备上,Media部件调用Histreamer支持音频播放等功能。 - - small设备上,Media部件调用recorder_lite支持音视频录制,默认调用player_lite支持音视频播放,通过设置系统属性变量debug.media_service.histreamer为1使用histreamer。详细设置方法参见[syspara系统属性组件使用说明](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/subsystems/subsys-boot-syspara.md)或者参见[syspara模块代码](https://gitee.com/openharmony/startup_syspara_lite)。 - - standard设备上,Media部件调用Gstreamer支持音视频播放、音视频录制。 -- **Audio**: Audio部件支持音频输入输出、策略管理、音频焦点管理等功能。 -- **Camera**: Camera部件提供相机操作接口,支持预览、拍照、录像。 -- **Image**: Image部件支持常见图片格式的编解码。 -- **MediaLibrary**: MediaLibrary支持本地和分布式媒体数据访问管理。 -- **Histreamer**: 轻量级媒体引擎,支持文件/网络流媒体输入,支持音视频解码播放,支持音视频编码录制,支持插件扩展。 -- **Gstreamer**: 开源GStreamer引擎,支持流媒体、音视频播放、录制等功能。 - -## 目录 - -仓目录结构如下: - -``` -/foundation/multimedia # 媒体子系统业务代码 -├── audio_lite # 小型系统音频模块 -│ ├── figures # 小型系统音频架构和流程图 -│ ├── frameworks # 小型系统音频框架实现 -│ └── interfaces # 小型系统音频模块接口 -├── audio_standard # 标准系统音频模块 -│ ├── figures # 标准系统音频架构和流程图 -│ ├── frameworks # 标准系统音频框架实现 -│ ├── interfaces # 标准系统音频模块接口 -│ ├── sa_profile # 标准系统音频服务配置 -│ └── services # 标准系统音频服务实现 -├── camera_lite # 小型系统相机模块 -│ ├── figures # 小型系统相机架构和流程图 -│ ├── frameworks # 小型系统相机框架实现 -│ └── interfaces # 小型系统相机模块接口 -├── camera_standard # 标准系统相机模块 -│ ├── figures # 标准系统相机架构和流程图 -│ ├── frameworks # 标准系统相机框架实现 -│ └── interfaces # 标准系统相机模块接口 -├── media_lite # 小型系统播放录制模块 -│ ├── figures # 小型系统播放录制架构和流程图 -│ ├── frameworks # 小型系统播放录制框架实现 -│ ├── interfaces # 小型系统播放录制模块接口 -│ └── services # 小型系统播放录制模块服务 -├── media_standard # 标准系统播放录制模块 -│ ├── figures # 标准系统播放录制架构和流程图 -│ ├── frameworks # 标准系统播放录制框架实现 -│ └── interfaces # 标准系统播放录制模块接口 -├── histreamer # HiStreamer媒体引擎 -│ └── engine # 媒体引擎 -│ ├── player # 播放器封装 -│ ├── foundation # 基础工具 -│ ├── pipeline # Pipeline框架 -│ └── plugin # 插件框架 -│ └── plugins # 平台软件插件 -└── utils # 媒体公共模块 - └── lite # 小型系统媒体公共模块 - ├── figures # 小型系统媒体公共模块架构和流程图 - ├── hals # 小型系统媒体公共硬件抽象接口 - ├── interfaces # 小型系统媒体公共模块接口 - └── src # 小型系统媒体公共模块框架实现 -``` - -## 约束 - -部分音视频格式的硬件编码、解码功能依赖设备的支持。 - -## 使用说明 - -如架构图示意,媒体提供了三大类功能接口,开发者可以根据使用诉求,综合使用一类或多类接口: - -- 应用开发者使用媒体接口实现录像、预览和播放音视频,使用可以参考[多媒体开发指南](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/subsystems/subsys-multimedia.md)。 -- 当使用简单播放录制功能时,可以使用Player和Recorder快速完成播放和录制功能。 -- 提供了一组控制相机的有效接口,可以让用户方便开发使用相机。 -- 开发者先创建camerakit组件对象,注册各种事件回调,这些事件回调是用来响应多媒体模块中事件响应的,之后调用创建camera就可以创建一个操作camera资源的对象,使用这个对象可以启动预览、录像或抓拍取流,及设置取流的相关参数。 - -## 安装 - -请提前加载内核及相关驱动,参考内核及驱动子系统readme。 - -## 相关仓 - -[multimedia\_camera\_lite](https://gitee.com/openharmony/multimedia_camera_lite) - -[multimedia\_audio\_lite](https://gitee.com/openharmony/multimedia_audio_lite) - -[multimedia\_media\_lite](https://gitee.com/openharmony/multimedia_media_lite) - -[multimedia\_utils\_lite](https://gitee.com/openharmony/multimedia_utils_lite) - -[multimedia\_histreamer](https://gitee.com/openharmony/multimedia_histreamer) - -[multimedia\_camera\_standard](https://gitee.com/openharmony/multimedia_camera_standard) - -[multimedia\_audio\_standard](https://gitee.com/openharmony/multimedia_audio_standard) - -[multimedia\_media\_standard](https://gitee.com/openharmony/multimedia_media_standard) - diff --git "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/21.\345\256\211\345\205\250\345\255\220\347\263\273\347\273\237.md" "b/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/21.\345\256\211\345\205\250\345\255\220\347\263\273\347\273\237.md" deleted file mode 100644 index 38785a0cf4d6e7b6093f4124d2c2ed2046bc2a1e..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/21.\345\256\211\345\205\250\345\255\220\347\263\273\347\273\237.md" +++ /dev/null @@ -1,110 +0,0 @@ ---- -title: 安全子系统 -permalink: /pages/01010215 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:19 ---- -# 安全子系统 - -- [简介](#section11660541593) -- [系统架构](#section342962219551) -- [目录](#section92711824195113) -- [约束](#section7715171045219) -- [使用](#section2057642312536) -- [相关仓](#section155556361910) - -## 简介 - -安全子系统包括系统安全、数据安全、应用安全等功能,为OpenHarmony提供有效保护应用和用户数据的能力。 - -安全子系统当前开源的功能,包括应用完整性保护、应用权限管理、设备认证、密钥管理服务、数据分级保护。 - -## 系统架构 - -**图 1** 子系统架构图 - - -![](/images/readme/figures/zh-cn_image_0000001079207198.png) - -**对外API**:安全子系统的对外API,部分API只针对系统应用开放; - -**应用权限管理**:为程序框架子系统提供权限管理功能,并且为上层应用提供权限申请和授权状态查询接口; - -**应用完整性校验**:提供对应用完整性校验的能力,为应用签名、应用安装校验提供能力支撑; - -**设备认证**:为分布式设备互联提供密钥协商和可信设备管理能力; - -**HUKS密钥管理**:为系统提供密钥管理服务,用于支撑基础的设备认证。 - -**数据分级保护**:提供数据分级相关的接口定义。 - -## 目录 - -``` -/base/security -├── appverify # 应用完整性校验 -├── dataclassification # 数据分级保护 -├── device_auth # 设备认证 -├── huks # HUKS密钥管理 -└── permission # 权限管理 -``` - -## 约束 - -- 应用权限管理的约束说明:本期开源包括应用本地权限管理;分布式应用权限管理在本期不开源(使用打桩实现的方式支持上层分布式业务进行联调)。 -- 设备认证的约束说明:设备认证包括同帐号设备认证与帐号无关点对点设备认证;当前已开源的是帐号无关点对点认证能力,同帐号设备认证在本期不开源(使用打桩实现的方式支持上层分布式业务进行联调)。 -- 应用完整性校验说明:应用完整性校验在OpenHarmony中使用的证书,是专为OpenHarmony生成的,涉及的公钥证书和对应的私钥均预置在OpenHarmony开源代码仓中,为开源社区提供离线签名和校验能力;在商用版本中应替换此公钥证书和对应的私钥。 - -## 使用 - -**应用权限管理** - -OpenHarmony中应用和系统服务均运行在独立的沙箱中,进程空间和程序数据都是相互隔离的,以保护应用数据的安全性;但是运行在独立沙箱中的服务或应用同时需要对外提供一些API以实现所需功能,其他独立沙箱中的应用在跨进程访问这些API时,需要系统提供一种权限管理机制对这些API的访问者进行授权。 - -应用权限管理提供了权限定义机制,允许系统服务和应用为自己的敏感API定义新的权限,其他应用必须申请此权限才能访问此敏感API; - -应用权限管理提供了权限申请机制,允许应用申请权限,这些权限由系统或者其他应用定义,权限申请通过后就能访问这个权限相关的系统或其他应用提供的敏感API; - -应用权限管理也为用户提供了一些必须的功能,方便用户查看和管理权限授予情况。 - -**应用完整性校验** - -OpenHarmony允许应用安装。为了确保应用的完整性和来源可靠,需要对安装的应用进行签名和验签。 - -应用开发阶段:开发者完成开发并生成安装包后,需要开发者对安装包进行签名,以证明安装包发布到设备的过程中没有被篡改。OpenHarmony的应用完整性校验模块提供了签名工具、签名证书生成规范,以及签名所需的公钥证书等完整的机制,支撑开发者对应用安装包签名。为了方便开源社区开发者,版本中预置了公钥证书和对应的私钥,为开源社区提供离线签名和校验能力;在商用版本中应替换此公钥证书和对应的私钥。 - -应用安装阶段:OpenHarmony程序框架子系统负责应用的安装。在接收到应用安装包之后,应用程序框架子系统需要解析安装包的签名数据,然后使用应用完整性校验模块的API对签名进行验证,只有校验成功之后才允许安装此应用. 应用完整性校验模块在校验安装包签名数据时,会使用系统预置的公钥证书进行验签。 - -**设备认证与HUKS** - -设备认证的目标是实现归一化的设备认证方案,实现覆盖1+8+N设备的设备绑定/认证方案。通常来讲,设备认证在认证阶段用于支撑软总线,不直接对上层应用提供服务。设备认证的使用主要包括如下内容: - -1. 统一可信关系建立:支持账号无关设备群组关系的建立并统一维护。业务启动/通过扫码绑定等方式与其他设备建立互信关系后,请求在本地创建帐号无关设备互信群组;业务可以通过API对可信设备群组进行查询 - -2. 统一设备认证:基于已建立的可信设备群组,提供统一的设备群组认证方案,支撑软总线的统一设备发现、连接认证、端到端加密的会话秘钥协商; - -3. 设备认证用到的相关凭证和密钥协商协议所需的算法,依赖HUKS提供支撑; - -**数据分级保护** - -在OpenHarmony中,数据分级保护模块负责提供数据分级的保护策略,并提供数据分级相关的接口定义。(OpenHarmony当前不提供实际的功能实现,依赖设备厂商实现接口对应的功能,对搭载OpenHarmony的设备上的数据提供安全保护)。 - -数据分级保护模块当前提供如下接口定义: - -1.数据分级标签设置和查询接口:对业务生成的文件数据提供设置和查询风险等级标签的接口,业务可使用该接口设定和查询落盘文件数据的风险等级,使该文件在系统中具有对应的数据风险分级标识。 - -2.基于设备安全等级的数据跨设备访问控制接口:提供基于设备安全等级的数据跨设备访问控制的接口,分布式跨设备数据传输业务可使用该接口获得对端设备可支持的数据风险等级。 - -## 相关仓 - -安全子系统 - -base/security - diff --git "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/22.\345\270\220\345\217\267\345\255\220\347\263\273\347\273\237.md" "b/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/22.\345\270\220\345\217\267\345\255\220\347\263\273\347\273\237.md" deleted file mode 100644 index a2cc357029c3de28b2ffe77dbf13c3eb5b59c381..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/22.\345\270\220\345\217\267\345\255\220\347\263\273\347\273\237.md" +++ /dev/null @@ -1,58 +0,0 @@ ---- -title: 帐号子系统 -permalink: /pages/01010216 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:19 ---- -# 帐号子系统 - -- [简介](#section11660541593) -- [子系统架构图](#section1412183212132) -- [目录](#section161941989596) -- [使用说明](#section1312121216216) -- [相关仓](#section1371113476307) - -## 简介 - -在标准系统上,帐号子系统主要提供分布式帐号登录状态管理能力,支持在端侧对接厂商云帐号应用,提供云帐号登录状态查询和更新的管理能力。 - -## 子系统架构图 - -**图 1** 帐号子系统架构图 - - -![](/images/readme/figures/zh-cn_image_0000001079026550.png) - -## 目录 - -``` -/base/account -└── os_account # 系统帐号组件 - ├── common # 公共基础模块 - ├── interfaces # 对外接口存放目录 - ├── kits # 系统帐号组件开发框架 - ├── sa_profile # 帐号SA配置文件定义目录 - ├── services # 系统帐号组件服务代码 - └── test # 系统帐号组件测试代码 - └── resource # 系统帐号组件测试资源 -``` - -## 使用说明 - -通过提供的分布式帐号管理类,可以查询和更新帐号登录状态,包括登录、登出、注销及Token失效。 - -查询和更新分布式帐号登录状态,需要系统权限,仅支持系统应用。 - -## 相关仓 - -**帐号子系统** - -account\_os\_account - diff --git "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/23.\346\263\233Sensor\345\255\220\347\263\273\347\273\237.md" "b/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/23.\346\263\233Sensor\345\255\220\347\263\273\347\273\237.md" deleted file mode 100644 index 8f1129383b27f24e6a693966a25e8500af6185da..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/23.\346\263\233Sensor\345\255\220\347\263\273\347\273\237.md" +++ /dev/null @@ -1,62 +0,0 @@ ---- -title: 泛Sensor子系统 -permalink: /pages/01010217 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:19 ---- -# 泛Sensor子系统 - -- [简介](#section11660541593) -- [目录](#section161941989596) -- [说明](#section1312121216216) -- [相关仓](#section1371113476307) - -## 简介 - -泛Sensor服务子系统提供了轻量级sensor服务基础框架,提供了如下功能: - -- Sensor列表查询 -- Sensor启停 -- Sensor订阅/去订阅 -- 设置数据上报模式等 - -泛Sensor服务框架如下图所示: - -**图1** 泛Sensor服务框架图 - -![](/images/readme/figures/zh-cn_image_0000001106694563.png) - -## 目录 - -``` -/base/sensors -├── sensor_lite # Sensor组件目录 -│ ├── frameworks # 框架代码目录 -│ ├── interfaces # Native接口目录 -│ └── services # 服务代码目录 -└── miscdevice_lite # 小器件组件目录 -``` - -## 说明 - -泛Sensor子系统中,主要包含三个模块:Sensor API、Sensor Framework和Sensor Service,详细结构见上述架构图: - -- Sensor API:提供传感器的基础API,主要包含Sensor列表查询、Sensor启停、Sensor订阅/去订阅等。 -- Sensor Framework:主要实现传感器的订阅管理,数据通道的创建、销毁、订阅与取消订阅,实现与SensorService的通信。 -- Sensor Service:主要实现HDF层数据接收、解析、分发,对Sensor服务的管理,数据上报管理以及Sensor权限管控等。 - -## 相关仓 - -**泛Sensor子系统** - -[sensors_sensor_lite](https://gitee.com/openharmony/sensors_sensor_lite/blob/master/README_zh.md) - -[sensors_miscdevice_lite](https://gitee.com/openharmony/sensors_miscdevice_lite/blob/master/README_zh.md) - diff --git "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/24.\346\265\213\350\257\225\345\255\220\347\263\273\347\273\237.md" "b/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/24.\346\265\213\350\257\225\345\255\220\347\263\273\347\273\237.md" deleted file mode 100644 index 1529fb1277b36ae56f944e2a04af57bac3316b9f..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/24.\346\265\213\350\257\225\345\255\220\347\263\273\347\273\237.md" +++ /dev/null @@ -1,885 +0,0 @@ ---- -title: 测试子系统 -permalink: /pages/01010218 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:19 ---- -# 测试子系统 -OpenHarmony为开发者提供了一套全面的自测试框架,开发者可根据测试需求开发相关测试用例,开发阶段提前发现缺陷,大幅提高代码质量。 - -本文从基础环境构建,用例开发,编译以及执行等方面介绍OpenHarmony测试框架如何运行和使用。 -## 基础环境构建 -测试框架依赖于python运行环境,在使用测试框架之前可参阅以下方式进行配置。 - - [环境配置](/pages/extra/9079c0/) - - [源码获取](/pages/extra/51fbe5/) - - -## 测试框架目录简介 -以下是测试框架的目录层级架构,在使用测试框架过程中可在相应目录查找对应组件。 -``` -test # 测试子系统 -├── developertest # 开发者测试组件 -│ ├── aw # 测试框架的静态库 -│ ├── config # 测试框架配置 -│ │ │ ... -│ │ └── user_config.xml # 用户使用配置 -│ ├── examples # 测试用例示例 -│ ├── src # 测试框架源码 -│ ├── third_party # 测试框架依赖第三方组件适配 -│ ├── reports # 测试结果报告 -│ ├── BUILD.gn # 测试框架编译入口 -│ ├── start.bat # 开发者测试入口(Windows) -│ └── start.sh # 开发者测试入口(Linux) -└── xdevice # 测试框架依赖组件 -``` -## 测试用例编写 -### 测试用例目录规划 -使用测试框架过程中,可根据以下层级关系规划测试用例目录。 -``` -subsystem # 子系统 -├── partA # 部件A -│ ├── moduleA # 模块A -│ │ ├── include -│ │ ├── src # 业务代码 -│ │ └── test # 测试目录 -│ │ ├── unittest # 单元测试 -│ │ │ ├── common # 公共用例 -│ │ │ │ ├── BUILD.gn # 测试用例编译配置 -│ │ │ │ └── testA_test.cpp # 单元测试用例源码 -│ │ │ ├── phone # 手机形态用例 -│ │ │ ├── ivi # 车机形态用例 -│ │ │ └── liteos-a # ipcamera使用liteos内核的用例 -│ │ ├── moduletest # 模块测试 -│ │ ... -│ │ -│ ├── moduleB # 模块B -│ ├── test -│ │ └── resource # 依赖资源 -│ │ ├── moduleA # 模块A -│ │ │ ├── ohos_test.xml # 资源配置文件 -│ │ ... └── 1.txt # 资源 -│ │ -│ ├── ohos_build # 编译入口配置 -│ ... -│ -... -``` -> **注意:** 测试用例根据不同设备形态差异分为通用用例和非通用用例,建议将通用用例存放在common目录下,非通用用例存放在相应设备形态目录下。 - -### 测试用例编写 -本测试框架支持多种语言用例编写,针对不同语言提供了不同的模板以供编写参考。 - -#### C++参考示例 - -- 用例源文件命名规范 - - 测试用例源文件名称和测试套内容保持一致,文件命名采用全小写+下划线方式命名,以test结尾,具体格式为:[功能]_[子功能]_test,子功能支持向下细分。 -示例: - ``` - calculator_sub_test.cpp - ``` - -- 用例示例 - ``` - /* - * Copyright (c) 2021 XXXX 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 "calculator.h" - #include - - using namespace testing::ext; - - class CalculatorSubTest : public testing::Test { - public: - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - }; - - void CalculatorSubTest::SetUpTestCase(void) - { - // input testsuit setup step,setup invoked before all testcases - } - - void CalculatorSubTest::TearDownTestCase(void) - { - // input testsuit teardown step,teardown invoked after all testcases - } - - void CalculatorSubTest::SetUp(void) - { - // input testcase setup step,setup invoked before each testcases - } - - void CalculatorSubTest::TearDown(void) - { - // input testcase teardown step,teardown invoked after each testcases - } - - /** - * @tc.name: integer_sub_001 - * @tc.desc: Verify the sub function. - * @tc.type: FUNC - * @tc.require: Issue Number - */ - HWTEST_F(CalculatorSubTest, integer_sub_001, TestSize.Level1) - { - // step 1:调用函数获取结果 - int actual = Sub(4,0); - - // Step 2:使用断言比较预期与实际结果 - EXPECT_EQ(4, actual); - } - ``` - 详细内容介绍: - 1. 添加测试用例文件头注释信息 - ``` - /* - * Copyright (c) 2021 XXXX 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. - */ - ``` - 2. 引用测试框架头文件和命名空间 - ``` - #include - - using namespace testing::ext; - ``` - 3. 添加被测试类的头文件 - ``` - #include "calculator.h" - ``` - 4. 定义测试套(测试类) - ``` - class CalculatorSubTest : public testing::Test { - public: - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - }; - - void CalculatorSubTest::SetUpTestCase(void) - { - // input testsuit setup step,setup invoked before all testcases - } - - void CalculatorSubTest::TearDownTestCase(void) - { - // input testsuit teardown step,teardown invoked after all testcases - } - - void CalculatorSubTest::SetUp(void) - { - // input testcase setup step,setup invoked before each testcases - } - - void CalculatorSubTest::TearDown(void) - { - // input testcase teardown step,teardown invoked after each testcases - } - ``` - > **注意:** 在定义测试套时,测试套名称应与编译目标保持一致,采用大驼峰风格。 - - 5. 测试用例实现,包含用例注释和逻辑实现 - ``` - /** - * @tc.name: integer_sub_001 - * @tc.desc: Verify the sub function. - * @tc.type: FUNC - * @tc.require: Issue Number - */ - HWTEST_F(CalculatorSubTest, integer_sub_001, TestSize.Level1) - { - //step 1:调用函数获取结果 - int actual = Sub(4,0); - - //Step 2:使用断言比较预期与实际结果 - EXPECT_EQ(4, actual); - } - ``` - 在编写用例时,我们提供了三种用例模板供您选择。 - - | 类型 | 描述 | - | ------------| ------------| - | HWTEST(A,B,C)| 用例执行不依赖Setup&Teardown时,可选取| - | HWTEST_F(A,B,C)| 用例执行(不含参数)依赖于Setup&Teardown时,可选取| - | HWTEST_P(A,B,C)| 用例执行(含参数)依赖于Set&Teardown时,可选取| - - 其中,参数A,B,C的含义如下: - - 参数A为测试套名。 - - 参数B为测试用例名,其命名必须遵循[功能点]_[编号]的格式,编号为3位数字,从001开始。 - - 参数C为测试用例等级,具体分为门禁level0 以及非门禁level1-level4共五个等级,其中非门禁level1-level4等级的具体选取规则为:测试用例功能越重要,level等级越低。 - - **注意:** - - 测试用例的预期结果必须有对应的断言。 - - 测试用例必须填写用例等级。 - - 测试体建议按照模板分步实现。 - - 用例描述信息按照标准格式@tc.xxx value书写,注释信息必须包含用例名称,用例类型,需求编号四项。其中用例测试类型@tc.type参数的选取,可参考下表。 - - | 测试类型名称|类型编码| - | ------------|------------| - |功能测试 |FUNC| - |性能测试 |PERF| - |可靠性测试 |RELI| - |安全测试 |SECU| - |模糊测试 |FUZZ| - - -#### JavaScript参考示例 - -- 用例源文件命名规范 - - 测试用例原文件名称采用大驼峰风格,以TEST结尾,具体格式为:[功能][子功能]TEST,子功能支持向下细分。 -示例: - ``` - AppInfoTest.js - ``` - -- 用例示例 - ``` - /* - * Copyright (C) 2021 XXXX 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. - */ - import app from '@system.app' - - import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' - - describe("AppInfoTest", function () { - beforeAll(function() { - // input testsuit setup step,setup invoked before all testcases - console.info('beforeAll caled') - }) - - afterAll(function() { - // input testsuit teardown step,teardown invoked after all testcases - console.info('afterAll caled') - }) - - beforeEach(function() { - // input testcase setup step,setup invoked before each testcases - console.info('beforeEach caled') - }) - - afterEach(function() { - // input testcase teardown step,teardown invoked after each testcases - console.info('afterEach caled') - }) - - /* - * @tc.name:appInfoTest001 - * @tc.desc:verify app info is not null - * @tc.type: FUNC - * @tc.require: Issue Number - */ - it("appInfoTest001", 0, function () { - //step 1:调用函数获取结果 - var info = app.getInfo() - - //Step 2:使用断言比较预期与实际结果 - expect(info != null).assertEqual(true) - }) - }) - ``` - 详细内容介绍: - 1. 添加测试用例文件头注释信息 - ``` - /* - * Copyright (C) 2021 XXXX 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. - */ - ``` - 2. 导入被测api和jsunit测试库 - ``` - import app from '@system.app' - - import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' - ``` - 3. 定义测试套(测试类) - ``` - describe("AppInfoTest", function () { - beforeAll(function() { - // input testsuit setup step,setup invoked before all testcases - console.info('beforeAll caled') - }) - - afterAll(function() { - // input testsuit teardown step,teardown invoked after all testcases - console.info('afterAll caled') - }) - - beforeEach(function() { - // input testcase setup step,setup invoked before each testcases - console.info('beforeEach caled') - }) - - afterEach(function() { - // input testcase teardown step,teardown invoked after each testcases - console.info('afterEach caled') - }) - ``` - 4. 测试用例实现 - ``` - /* - * @tc.name:appInfoTest001 - * @tc.desc:verify app info is not null - * @tc.type: FUNC - * @tc.require: Issue Number - */ - it("appInfoTest001", 0, function () { - //step 1:调用函数获取结果 - var info = app.getInfo() - - //Step 2:使用断言比较预期与实际结果 - expect(info != null).assertEqual(true) - }) - ``` - -### 测试用例编译文件编写 -根据测试用例目录规划,当执行某一用例时,测试框架会根据编译文件逐层查找,最终找到所需用例进行编译。下面通过不同示例来讲解gn文件如何编写。 - -#### 测试用例编译配置文件 -针对不同语言,下面提供不同的编译模板以供参考。 - -- **C++用例编译配置示例** - ``` - # Copyright (c) 2021 XXXX Device Co., Ltd. - - import("//build/test.gni") - - module_output_path = "subsystem_examples/calculator" - - config("module_private_config") { - visibility = [ ":*" ] - - include_dirs = [ "../../../include" ] - } - - ohos_unittest("CalculatorSubTest") { - module_out_path = module_output_path - - sources = [ - "../../../include/calculator.h", - "../../../src/calculator.cpp", - ] - - sources += [ "calculator_sub_test.cpp" ] - - configs = [ ":module_private_config" ] - - deps = [ "//third_party/googletest:gtest_main" ] - } - - group("unittest") { - testonly = true - deps = [":CalculatorSubTest"] - } - ``` - 详细内容如下: - - 1. 添加文件头注释信息 - ``` - # Copyright (c) 2021 XXXX Device Co., Ltd. - ``` - 2. 导入编译模板文件 - ``` - import("//build/test.gni") - ``` - 3. 指定文件输出路径 - ``` - module_output_path = "subsystem_examples/calculator" - ``` - > **说明:** 此处输出路径为部件/模块名。 - - 4. 配置依赖包含目录 - - ``` - config("module_private_config") { - visibility = [ ":*" ] - - include_dirs = [ "../../../include" ] - } - ``` - > **说明:** 一般在此处对相关配置进行设置,在测试用例编译脚本中可直接引用。 - - 5. 指定测试用例编译目标输出的文件名称 - - ``` - ohos_unittest("CalculatorSubTest") { - } - ``` - 6. 编写具体的测试用例编译脚本(添加需要参与编译的源文件、配置和依赖) - ``` - ohos_unittest("CalculatorSubTest") { - module_out_path = module_output_path - sources = [ - "../../../include/calculator.h", - "../../../src/calculator.cpp", - "../../../test/calculator_sub_test.cpp" - ] - sources += [ "calculator_sub_test.cpp" ] - configs = [ ":module_private_config" ] - deps = [ "//third_party/googletest:gtest_main" ] - } - ``` - - > **说明:根据测试类型的不同,在具体编写过程中可选择不同的测试类型:** - > - ohos_unittest:单元测试 - > - ohos_moduletest:模块测试 - > - ohos_systemtest:系统测试 - > - ohos_performancetest:性能测试 - > - ohos_securitytest:安全测试 - > - ohos_reliabilitytest:可靠性测试 - > - ohos_distributedtest:分布式测试 - - 7. 对目标测试用例文件进行条件分组 - - ``` - group("unittest") { - testonly = true - deps = [":CalculatorSubTest"] - } - ``` - > **说明:** 进行条件分组的目的在于执行用例时可以选择性的执行某一种特定类型的用例。 - -- **JavaScript用例编译配置示例** - - ``` - # Copyright (C) 2021 XXXX Device Co., Ltd. - - import("//build/test.gni") - - module_output_path = "subsystem_examples/app_info" - - ohos_js_unittest("GetAppInfoJsTest") { - module_out_path = module_output_path - - hap_profile = "./config.json" - certificate_profile = "//test/developertest/signature/openharmony_sx.p7b" - } - - group("unittest") { - testonly = true - deps = [ ":GetAppInfoJsTest" ] - } - ``` - - 详细内容如下: - - 1. 添加文件头注释信息 - - ``` - # Copyright (C) 2021 XXXX Device Co., Ltd. - ``` - 2. 导入编译模板文件 - - ``` - import("//build/test.gni") - ``` - 3. 指定文件输出路径 - - ``` - module_output_path = "subsystem_examples/app_info" - ``` - > **说明:** 此处输出路径为部件/模块名。 - - 4. 指定测试用例编译目标输出的文件名称 - - ``` - ohos_js_unittest("GetAppInfoJsTest") { - } - ``` - > **说明:** - >- 使用模板ohos_js_unittest定义js测试套,注意与C++用例区分。 - >- js测试套编译输出文件为hap类型,hap名为此处定义的测试套名,测试套名称必须以JsTest结尾。 - - 5. 指定hap包配置文件config.json和签名文件,两个配置为必选项 - - ``` - ohos_js_unittest("GetAppInfoJsTest") { - module_out_path = module_output_path - - hap_profile = "./config.json" - certificate_profile = "//test/developertest/signature/openharmony_sx.p7b" - } - ``` - config.json为hap编译所需配置文件,需要开发者根据被测sdk版本配置“target”项,其余项可默认,具体如下所示: - - ``` - { - "app": { - "bundleName": "com.example.myapplication", - "vendor": "example", - "version": { - "code": 1, - "name": "1.0" - }, - "apiVersion": { - "compatible": 4, - "target": 5 // 根据被测sdk版本进行修改,此例为sdk5 - } - }, - "deviceConfig": {}, - "module": { - "package": "com.example.myapplication", - "name": ".MyApplication", - "deviceType": [ - "phone" - ], - "distro": { - "deliveryWithInstall": true, - "moduleName": "entry", - "moduleType": "entry" - }, - "abilities": [ - { - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ], - "name": "com.example.myapplication.MainAbility", - "icon": "$media:icon", - "description": "$string:mainability_description", - "label": "MyApplication", - "type": "page", - "launchType": "standard" - } - ], - "js": [ - { - "pages": [ - "pages/index/index" - ], - "name": "default", - "window": { - "designWidth": 720, - "autoDesignWidth": false - } - } - ] - } - } - ``` - 6. 对目标测试用例文件进行条件分组 - ``` - group("unittest") { - testonly = true - deps = [ ":GetAppInfoJsTest" ] - } - ``` - > **说明:** 进行条件分组的目的在于执行用例时可以选择性的执行某一种特定类型的用例。 - -#### 编译入口配置文件ohos.build - -当完成用例编译配置文件编写后,需要进一步编写部件编译配置文件,以关联到具体的测试用例。 -``` -"partA": { - "module_list": [ - - ], - "inner_list": [ - - ], - "system_kits": [ - - ], - "test_list": [ - "//system/subsystem/partA/calculator/test:unittest" //配置模块calculator下的test - ] - } -``` -> **说明:** test_list中配置的是对应模块的测试用例。 - -### 测试用例资源配置 -测试依赖资源主要包括测试用例在执行过程中需要的图片文件,视频文件、第三方库等对外的文件资源。 - -依赖资源文件配置步骤如下: -1. 在部件的test目录下创建resource目录,在resource目录下创建对应的模块,在模块目录中存放该模块所需要的资源文件 - -2. 在resource目录下对应的模块目录中创建一个ohos_test.xml文件,文件内容格式如下: - ``` - - - - - - - - ``` -3. 在测试用例的编译配置文件中定义resource_config_file进行指引,用来指定对应的资源文件ohos_test.xml - ``` - ohos_unittest("CalculatorSubTest") { - resource_config_file = "//system/subsystem/partA/test/resource/calculator/ohos_test.xml" - } - ``` - >**说明:** - >- target_name: 测试套的名称,定义在测试目录的BUILD.gn中。preparer: 表示该测试套执行前执行的动作。 - >- src="res": 表示测试资源位于test目录下的resource目录下,src="out":表示位于out/release/$(部件)目录下。 - -## 测试用例执行 -在执行测试用例之前,针对用例使用设备的不同,需要对相应配置进行修改,修改完成即可执行测试用例。 - -### user_config.xml配置 -``` - - - - false - - false - - true - - - - - - - - - - - - - cmd - 115200 - 8 - 1 - 1 - - - - - - - - - - - - - - - - - - -``` ->**说明:** 在执行测试用例之前,若使用HDC连接设备,用例仅需配置设备IP和端口号即可,其余信息均默认不修改。 - -### Windows环境执行 -#### 测试用例编译 - -由于Windows环境下无法实现用例编译,因此执行用例前需要在Linux环境下进行用例编译,用例编译命令: -``` -./build.sh --product-name Hi3516DV300 --build-target make_test -``` -编译完成后,测试用例将自动保存在out/hi3516dv300/packages/phone/images/tests目录下。 - ->说明: Hi3516DV300为当前版本所支持的平台,make_test表示全部用例。根据不同需求,编译选项可进行不同选择: -> - --product-name # 编译产品名称(必选) -> - --build-target # 指定编译目标(可选) - -#### 搭建执行环境 -1. 在Windows环境创建测试框架目录Test,并在此目录下创建testcase目录 - -2. 从Linux环境拷贝测试框架developertest和xdevice到创建的Test目录下,拷贝编译好的测试用例到testcase目录下 - ->**说明:** 将测试框架及测试用例从Linux环境移植到Windows环境,以便后续执行。 - -3. 修改user_config.xml - ``` - - - false - - - - D:\Test\testcase\tests - - ``` - >**说明:** ``标签表示是否需要编译用例;``标签表示测试用例查找路径。 - -#### 执行用例 -1. 启动测试框架 - ``` - start.bat - ``` -2. 选择产品形态 - - 进入测试框架,系统会自动提示您选择产品形态,请根据实际的开发板进行选择。例如:Hi3516DV300。 - -3. 执行测试用例 - - 当选择完产品形态,可参考如下指令执行测试用例。 - ``` - run -t UT -ts CalculatorSubTest -tc interger_sub_00l - ``` - 执行命令参数说明: - ``` - -t [TESTTYPE]: 指定测试用例类型,有UT,MST,ST,PERF等。(必选参数) - -tp [TESTPART]: 指定部件,可独立使用。 - -tm [TESTMODULE]: 指定模块,不可独立使用,需结合-tp指定上级部件使用。 - -ts [TESTSUITE]: 指定测试套,可独立使用。 - -tc [TESTCASE]: 指定测试用例,不可独立使用,需结合-ts指定上级测试套使用。 - -h : 帮助命令。 - ``` -### Linux环境执行 -#### 远程端口映射 -为了在Linux远程服务器以及Linux虚拟机两种环境下执行测试用例,需要对端口进行远程映射,以实现与设备的数据通路连接。具体操作如下: -1. HDC Server指令: - ``` - hdc_std kill - hdc_std -m -s 0.0.0.0:8710 - ``` - >**说明:** IP和端口号为默认值。 - -2. HDC Client指令: - ``` - hdc_std -s xx.xx.xx.xx:8710 list targets - ``` - >**说明:** 此处IP填写设备侧IP地址。 - -#### 执行用例 -1. 启动测试框架 - ``` - ./start.sh - ``` -2. 选择产品形态 - - 进入测试框架,系统会自动提示您选择产品形态,请根据实际的开发板进行选择。例如:Hi3516DV300。 - -3. 执行测试用例 - - 测试框架在执行用例时会根据指令找到所需用例,自动实现用例编译,执行过程,完成自动化测试。 - ``` - run -t UT -ts CalculatorSubTest -tc interger_sub_00l - ``` - 执行命令参数说明: - ``` - -t [TESTTYPE]: 指定测试用例类型,有UT,MST,ST,PERF等。(必选参数) - -tp [TESTPART]: 指定部件,可独立使用。 - -tm [TESTMODULE]: 指定模块,不可独立使用,需结合-tp指定上级部件使用。 - -ts [TESTSUITE]: 指定测试套,可独立使用。 - -tc [TESTCASE]: 指定测试用例,不可独立使用,需结合-ts指定上级测试套使用。 - -h : 帮助命令。 - ``` - -## 测试报告日志 -当执行完测试指令,控制台会自动生成测试结果,若需要详细测试报告您可在相应的数据文档中进行查找。 - -### 测试结果 -测试结果输出根路径如下: -``` -test/developertest/reports/xxxx_xx_xx_xx_xx_xx -``` ->**说明:** 测试报告文件目录将自动生成。 - -该目录中包含以下几类结果: -| 类型 | 描述| -| ------------ | ------------ | -| result/ |测试用例格式化结果| -| log/plan_log_xxxx_xx_xx_xx_xx_xx.log | 测试用例日志 | -| summary_report.html | 测试报告汇总 | -| details_report.html | 测试报告详情 | - -### 测试框架日志 -``` -reports/platform_log_xxxx_xx_xx_xx_xx_xx.log -``` - -### 最新测试报告 -``` -reports/latest -``` - -## 涉及仓 - -[test\_xdevice](https://gitee.com/openharmony/test_xdevice/blob/master/README_zh.md) - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/25.\347\224\250\346\210\267\347\250\213\345\272\217\346\241\206\346\236\266\345\255\220\347\263\273\347\273\237.md" "b/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/25.\347\224\250\346\210\267\347\250\213\345\272\217\346\241\206\346\236\266\345\255\220\347\263\273\347\273\237.md" deleted file mode 100644 index d711815a5da495e83db059622a4b13e9e223fd57..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/25.\347\224\250\346\210\267\347\250\213\345\272\217\346\241\206\346\236\266\345\255\220\347\263\273\347\273\237.md" +++ /dev/null @@ -1,109 +0,0 @@ ---- -title: 用户程序框架子系统 -permalink: /pages/01010219 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:19 ---- -# **用户程序框架子系统** - -## 简介 - -用户程序框架子系统是OpenHarmony为开发者提供的一套开发OpenHarmony应用程序的框架。 - -**包含以下模块**: - -- **AppKit**:是用户程序框架提供给开发者的开发包,开发者基于该开发包可以开发出基于Ability组件的应用。 - -- **AppManagerService**:应用管理服务,用于管理应用运行关系、调度应用进程生命周期及状态的系统服务。 - -- **BundleManagerService**:是负责管理安装包的系统服务,常见的比如包安装、更新,卸载和包信息查询等,运行在Foundation进程。 - -应用程序框架子系统架构如下图所示: - -![](/images/readme/figures/appexecfwk.png) - - - -## 目录 - -``` -foundation/appexecfwk/standard -├── kits -│   └── appkit # Appkit实现的核心代码 -├── common -│   └── log # 日志组件目录 -├── interfaces -│   └── innerkits # 内部接口存放目录 -├── services -│   ├── appmgr # 用户程序管理服务框架代码 -│   └── bundlemgr # 包管理服务框架代码 -├── test # 测试目录 -└── tools # bm命令存放目录 -``` - -### 使用说明 - -当前版本用户程序框架不具备权限管理的能力。 - -以下模块的JS接口为非正式API,仅供Launcher、Settings、SystemUI等系统应用使用,不排除对这些接口进行变更的可能性,后续版本将提供正式API。 - -- @ohos.bundle_mgr.d.ts -- bundleinfo.d.ts -- common.d.ts -- installresult.d.ts -- moduleinfo.d.ts - - -### bm命令如下 - -**bm命令帮助** - -| 命令 | 描述 | -| ------- | ---------- | -| bm help | bm帮助命令 | - -**安装应用** - -| 命令 | 描述 | -| ----------------------------------- | -------------------------- | -| bm install -p | 通过指定路径安装一个应用包 | -| bm install -r -p | 覆盖安装一个应用包 | - -``` -示例如下: -bm install -p /data/app/ohosapp.hap -``` - -**卸载应用** - -| 命令 | 描述 | -| ----------------------------- | ------------------------ | -| bm uninstall -n | 通过指定包名卸载一个应用 | - -``` -示例如下: -bm uninstall -n com.ohos.app -``` - -**查看应用安装信息** - -| 命令 | 描述 | -| ---------- | -------------------------- | -| bm dump -a | 列出系统已经安装的所有应用 | - -## 相关仓 - -用户程序框架子系统 - -**appexecfwk_standard** - -aafwk_standard - -startup_appspawn diff --git "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/26.\347\224\265\346\272\220\347\256\241\347\220\206\345\255\220\347\263\273\347\273\237.md" "b/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/26.\347\224\265\346\272\220\347\256\241\347\220\206\345\255\220\347\263\273\347\273\237.md" deleted file mode 100644 index d6f822d8139aebe13101a626dd2980eb9ea26312..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/26.\347\224\265\346\272\220\347\256\241\347\220\206\345\255\220\347\263\273\347\273\237.md" +++ /dev/null @@ -1,78 +0,0 @@ ---- -title: 电源管理子系统 -permalink: /pages/0101021a -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:19 ---- -# 电源管理子系统 - -- [简介](#section11660541593) -- [目录](#section19472752217) -- [使用说明](#section19959125052315) -- [相关仓](#section63151229062) - -## 简介 - -电源管理子系统提供如下功能: - -1. 重启服务:系统重启和下电。 -2. 系统电源管理服务:系统电源状态管理和休眠运行锁管理。 -3. 显示相关的能耗调节:包括根据环境光调节背光亮度,和根据接近光亮灭屏。 -4. 省电模式 :在不损害主要功能和性能的前提下,提供一种低功耗操作模式 。 -5. 电池服务:支持充放电、电池和充电状态的监测,包括状态的更新和上报,还包括关机充电。 -6. 温控 :在设备温度到一定程度之后对应用、SoC、外设进行管控,限制温升 。 -7. 耗电统计: 主要包括软件耗电和硬件耗电统计,以及单个应用的耗电统计 。 -8. 轻设备电池服务。 -9. 轻设备电源管理服务。 - -**图 1** 电源管理子系统架构图 - - -![](/images/readme/figures/电源管理子系统架构图.png) - -## 目录 - -``` -/base/powermgr -├── battery_lite # 轻设备电池服务 -├── battery_manager # 电池服务 -├── battery_statistics # 耗电统计服务 -├── display_manager # 显示能效管理服务 -├── power_manager # 系统电源管理服务 -├── powermgr_lite # 轻设备电源管理服务 -└── thermal_manager # 温控和热管理服务 -``` - -## 使用说明 - -如架构图示意,电源管理提供了七个子部件,其中部分部件提供了对外接口或者公共事件通知,开发者可以根据场景使用: - -- 通过Power Manager提供的接口可以进行申请和释放休眠运行锁RunningLock、省电模式、亮度调节、重启设备、关机等操作,同时也可以通过公共事件来监听省电模式和关机状态的变化。 -- Battery Manager提供了电池信息查询的接口,同时开发者也可以通过公共事件监听电池状态和充放电状态的变化。 -- Thermal Manager提供的设备温升状态的查询接口,同时开发者也可以通过注册回调和公共事件来监听设备温升状态。 -- Battery Statistics 提供了软硬件耗电统计的功能,可以查询硬件耗电或者应用耗电情况。 - -## 相关仓 - -**电源管理子系统** - -[powermgr_power_manager](https://gitee.com/openharmony/powermgr_power_manager) - -[powermgr_display_manager](https://gitee.com/openharmony/powermgr_display_manager) - -[powermgr_battery_manager](https://gitee.com/openharmony/powermgr_battery_manager) - -[powermgr_thermal_manager](https://gitee.com/openharmony/powermgr_thermal_manager) - -[powermgr_battery_statistics](https://gitee.com/openharmony/powermgr_battery_statistics) - -[powermgr_battery_lite](https://gitee.com/openharmony/powermgr_battery_lite) - -[powermgr_powermgr_lite](https://gitee.com/openharmony/powermgr_powermgr_lite) diff --git "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/27.\347\224\265\350\257\235\346\234\215\345\212\241\345\255\220\347\263\273\347\273\237.md" "b/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/27.\347\224\265\350\257\235\346\234\215\345\212\241\345\255\220\347\263\273\347\273\237.md" deleted file mode 100644 index dcbd06068f056216a78e4675e0045604ad35786e..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/27.\347\224\265\350\257\235\346\234\215\345\212\241\345\255\220\347\263\273\347\273\237.md" +++ /dev/null @@ -1,158 +0,0 @@ ---- -title: 电话服务子系统 -permalink: /pages/0101021b -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:19 ---- -# 电话服务子系统 - -- [简介](#section104mcpsimp) -- [目录](#section119mcpsimp) -- [约束](#section123mcpsimp) -- [使用说明](#section128mcpsimp) - - [获取当前蜂窝网络信号信息](#section1458213210369) - - [观察蜂窝网络状态变化](#section750135512369) - -- [相关仓](#section152mcpsimp) - -## 简介 - -电话服务子系统,提供了一系列的API用于获取无线蜂窝网络和SIM卡相关的一些信息。应用可以通过调用API来获取当前注册网络名称、网络服务状态、信号强度以及SIM卡的相关信息。 - -各个模块主要作用如下: - -- 核心服务模块:主要功能是初始化RIL管理、SIM卡和搜网模块。 -- 通话管理模块:主要功能是管理CS(Circuit Switch,电路交换)、IMS(IP Multimedia Subsystem,IP多媒体子系统)和OTT(over the top,OTT解决方案)三种类型的通话,申请通话所需要的音视频资源,处理多路通话时产生的各种冲突。 -- 蜂窝通话模块:主要功能是实现基于运营商网络的基础通话。 -- 短彩信模块:主要功能是短信收发和彩信编解码。 -- 状态注册模块:主要功能是提供电话服务子系统各种消息事件的订阅以及取消订阅的API。 - -**图 1** 子系统架构图 - -![](/images/readme/figures/zh-cn_architecture-of-telephony-subsystem.png) - -## 目录 - -``` -base/telephony/ -├── core_service # 核心服务 -├── call_manager # 通话管理 -├── cellular_call # 蜂窝通话 -├── sms_mms # 短彩信 -└── state_registry # 状态注册 -``` - -## 约束 - -1. 目前开源的范围仅支持蜂窝通话(仅支持CS通话)和短信,不支持蜂窝数据上网,仅支持单SIM卡。 - -## 使用说明 - -### 获取当前蜂窝网络信号信息 - -1. 从@ohos.telephony.radio.d.ts中导入radio命名空间。 -2. 可以通过callback或者Promise的方式调用getSignalInformation\(slotId: number\)方法。 -3. 该接口为异步接口,结果会从callback中返回SignalInformation数组。 -4. 遍历SignalInformation数组,获取不同制式(signalType)的信号强度(signalLevel)。 - - ``` - // 引入包名 - import radio from "@ohos.telephony.radio"; - - // 参数赋值 - let slotId = 1; - - // 调用接口【callback方式】 - radio.getSignalInformation(slotId, (err, value) => { - if (err) { - // 接口调用失败,err非空 - console.error(`failed to getSignalInformation because ${err.message}`); - return; - } - // 接口调用成功,err为空 - for (let i = 0; i < value.length; i++) { - console.log(`success to getSignalInformation: type is ${value[i].signalType}, level is ${value[i].signalLevel}`); - } - }); - - // 调用接口【Promise方式】 - let promise = radio.getSignalInformation(slotId); - promise.then((value) => { - // 接口调用成功,此处可以实现成功场景分支代码。 - for (let i = 0; i < value.length; i++) { - console.log(`success to getSignalInformation: type is ${value[i].signalType}, level is ${value[i].signalLevel}`); - } - }).catch((err) => { - // 接口调用失败,此处可以实现失败场景分支代码。 - console.error(`failed to getSignalInformation because ${err.message}`); - }); - ``` - - -### 观察蜂窝网络状态变化 - -**添加观察事件** - -1. 从@ohos.telephony.observer.d.ts中导入observer命名空间。 -2. 调用on\(type: 'networkStateChange'\)方法,传入卡槽id(slotId)和收到事件的回调处理函数(callback),其中slotId为可选参数。 -3. 当网络状态发生变更时,调用者会收到回调。 - - ``` - // 引入包名 - import observer from '@ohos.telephony.observer'; - - // 开启订阅 - observer.on('networkStateChange', {slotId: 1}, (err, value) => { - if (err) { - // 接口调用失败,err非空 - console.error(`failed, because ${err.message}`); - return; - } - // 接口调用成功,err为空 - console.log(`success on. network state is ` + value); - }); - ``` - - -**停止观察** - -1. 从@ohos.telephony.observer.d.ts中导入observer命名空间。 -2. 调用off\(type: 'networkStateChange'\)方法,传入添加观察事件时的callback对象。 - - ``` - // 引入包名 - import observer from '@ohos.telephony.observer'; - - // 关闭订阅 - observer.off('networkStateChange', (err, value) => { - if (err) { - // 接口调用失败,err非空 - console.error(`failed, because ${err.message}`); - return; - } - // 接口调用成功,err为空 - console.log(`success off`); - }); - ``` - - -## 相关仓 - -**电话服务子系统** - -[telephony_core_service](https://gitee.com/openharmony/telephony_core_service/blob/master/README_zh.md) - -[telephony_call_manager](https://gitee.com/openharmony/telephony_call_manager/blob/master/README_zh.md) - -[telephony_cellular_call](https://gitee.com/openharmony/telephony_cellular_call/blob/master/README_zh.md) - -[telephony\_sms\_mms](https://gitee.com/openharmony/telephony_sms_mms/blob/master/README_zh.md) - -[telephony\_state\_registry](https://gitee.com/openharmony/telephony_state_registry/blob/master/README_zh.md) diff --git "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/28.\347\240\224\345\217\221\345\267\245\345\205\267\351\223\276\345\255\220\347\263\273\347\273\237.md" "b/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/28.\347\240\224\345\217\221\345\267\245\345\205\267\351\223\276\345\255\220\347\263\273\347\273\237.md" deleted file mode 100644 index 114e44fda0bd05b6ee64374399aadd8ce82f8ecc..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/28.\347\240\224\345\217\221\345\267\245\345\205\267\351\223\276\345\255\220\347\263\273\347\273\237.md" +++ /dev/null @@ -1,352 +0,0 @@ ---- -title: 研发工具链子系统 -permalink: /pages/0101021c -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:19 ---- -# 研发工具链子系统 - -- [简介](#section11660541593) -- [系统架构](#section342962219551) -- [目录](#section71879353610) -- [使用说明](#section3199114314427) -- [相关仓](#section1371113476307) - -## 简介 - -在OpenHarmony中,研发工具链子系统主要为开发人员提供了开发时用于调试的命令行以及追踪性能轨迹、查看性能的工具。 - -本子系统主要实现了以下功能: - -- bytrace,开发人员用于追踪进程轨迹、查看性能的一种工具,主要对内核ftrace进行了封装和扩展,来支持用户态的打点。 -- hdc,开发人员用于调试的命令行工具,通过该工具可以在windows/linux/mac等系统上与开发机或者模拟器进行交互。 -- profiler,旨在为开发者提供一套性能调优平台,可以用来分析内存、性能等问题。 - -## 系统架构 - -工具链子系统的架构图如下: - -**图 1** 研发工具链子系统架构图 - - -![](/images/readme/figures/zh-cn_image_0000001162757669.png) - -## 目录 - -``` -/developtools # 研发工具链子系统目录结构 -├── bytrace_standard # bytrace组件代码目录 -│ └── bin # bytrace组件功能实现目录 -│ └── innerkits # 对内部子系统暴露的头文件存放目录 -├── hdc_standard # hdc组件代码目录 -│ └── src # hdc组件功能实现目录 -│ └── prebuilt # 预编译目录 -├── profiler # 性能调优组件代码目录 -│ └── device # 设备侧代码目录 -│ └── host # host端代码目录 -│ └── interfaces # 模块间和对外提供的接口代码目录 -│ └── trace_analyzer # bytrace解析模块的代码目录 -│ └── protos # proto格式文件的代码目录 -``` - -## 使用说明 - -**1. bytrace** - -bytrace当前支持如下命令: - -**表 1** 命令行列表 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Option

-

Description

-

-h,--help

-

查看帮助信息

-

-b n,--buffer_size n

-

指定n(KB)内存大小用于存取trace日志,默认2MB

-

-t n,--time n

-

用来指定trace运行的时间(单位:s),取决于需要分析过程的时间

-

--trace_clock clock

-

trace输出的时钟类型,一般设备支持boot、global、mono、uptime、perf等,默认为boot

-

--trace_begin

-

启动抓trace

-

--trace_dump

-

将数据输出到指定位置(默认控制台)

-

--trace_finish

-

停止抓trace,并将数据输出到指定位置(默认控制台)

-

-l,--list_categories

-

输出手机能支持的trace模块

-

--overwrite

-

当缓冲区满的时候,将丢弃最新的信息。(默认丢弃最老的日志)

-

-o filename,--output filename

-

指定输出的目标文件名称

-

-z

-

抓取trace后进行压缩

-
- -以下是常用bytrace命令示例,供开发者参考: - -- 查询支持的label。 - - ``` - bytrace -l - 或者 - bytrace --list_categories - ``` - - -- 设置4M缓存,抓取10秒,抓取label为ability的trace信息。 - - ``` - bytrace -b 4096 -t 10 --overwrite ability > /data/mytrace.ftrace - ``` - - -- 设置trace的输出时钟为mono。 - - ``` - bytrace --trace_clock mono -b 4096 -t 10 --overwrite ability > /data/mytrace.ftrace - ``` - - -- 抓取trace后进行压缩。 - - ``` - bytrace -z -b 4096 -t 10 --overwrite ability > /data/mytrace.ftrace - ``` - - -**2. hdc** - -hdc当前支持如下命令: - -**表 2** hdc命令列表 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Option

-

Description

-

-t key

-

用于指定连接该指定设备标识key

-

-s socket

-

用于指定服务监听的socket配置

-

-h/help -v/version

-

用于显示hdc相关的帮助、版本信息

-

list targets[-v]

-

显示所有已经连接的目标设备列表

-

target mount

-

以读写模式挂载/system等分区

-

target boot [bootloader|recovery]

-

重启目标设备,默认启动系统,可支持bootloader,recover等引导模式

-

smode [off]

-

授予后台服务进程root权限, 使用off参数取消授权

-

kill

-

终止服务进程

-

tconn host[:port][-remove]

-

通过【ip地址:端口号】来指定连接的设置

-

tmode usb

-

执行后设备端对应daemon进程重启,并首先选用usb连接方式

-

tmode port port-number

-

执行后设备端对应daemon进程重启,并优先使用网络方式连接设备,如果连接设备再选择usb连接

-

fport local remote -b

-

创建端口、文件、设备转发

-

fport list

-

查看所有已建立的映射连接列表,显示的参数包括转发配置字符串,转发类型,转发参数

-

fport rm local

-

删除已映射的给定配置字符串连接(配置字符串值可以通过list获取),没有指定则删除所有

-

file send local remote

-

发送文件至远端设备

-

file recv [-a] remote local

-

从远端设备接收文件至本地

-

app install [-r/-d/-g] package

-

安装OpenHarmony package

-

app install-multiple [-rdg] --hap path

-

安装指定路径下的所有OpenHarmony package

-

app uninstall [-k] package

-

卸载OpenHarmony应用

-

hilog

-

支持查看抓取log调试信息

-

bugreport [PATH]

-

支持抓取bugreport调试信息

-

shell [command]

-

远程执行命令或进入交互命令环境

-
- -以下是常用hdc命令示例,供开发者参考: - -- 往设备中推送文件 - - ``` - hdc file send E:\c.txt /sdcard - ``` - -- 重启设备 - - ``` - hdc target boot - ``` - - -- 查看日志 - - ``` - hdc hilog - ``` - -- 进入命令行交互模式 - - ``` - hdc shell - ``` - -- 配置服务监听的socket。 - - ``` - hdc -s 192.168.1.100:1234 - ``` - - -- 重启至bootloader模式。 - - ``` - hdc target boot bootloader - ``` - -- 网络连接。 - - ``` - hdc tconn 192.168.0.100:8710 - ``` - - -**3. profiler** - -性能调优组件包含系统和应用调优框架,旨在为开发者提供一套性能调优平台,可以用来分析内存、性能等问题。 - -该组件整体分为PC端和设备端两部分,PC端最终作为deveco studio的插件进行发布,内部主要包括分为UI绘制、设备管理、进程管理、插件管理、数据导入、数据存储、 数据分析、Session管理、配置管理等模块;设备端主要包括命令行工具、服务进程、插件集合、应用程序组件等模块。设备端提供了插件扩展能力,对外提供了插件接口,基于该扩展能力可以按需定义自己的能力,并集成到框架中来,目前基于插件能力已经完成了实时内存插件和trace插件。详细内容见性能调优组件。 - -## 相关仓 - -**研发工具链子系统** - -developtools\_hdc\_standard - -developtools\_bytrace\_standard - -developtools\_profiler - diff --git "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/29.\347\263\273\347\273\237\345\272\224\347\224\250.md" "b/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/29.\347\263\273\347\273\237\345\272\224\347\224\250.md" deleted file mode 100644 index 3355019ccd6634d591e659fb5371e8208403c029..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/29.\347\263\273\347\273\237\345\272\224\347\224\250.md" +++ /dev/null @@ -1,51 +0,0 @@ ---- -title: 系统应用 -permalink: /pages/0101021d -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:19 ---- -# 系统应用 - -- [简介](#section663544819225) -- [目录](#section161941989596) -- [相关仓](#section1371113476307) - -## 简介 - -系统应用提供了OpenHarmony标准系统上的部分应用,如桌面、SystemUI、设置等,为开发者提供了构建标准系统应用的具体实例,这些应用支持在所有标准系统设备上使用。 - -系统应用目前包含如下几个应用: - -1. 桌面:提供了基本的已安装应用的展示功能和人机交互界面,是所有应用的入口。 -2. SystemUI:包含导航栏和系统状态栏两部分,导航栏提供基本页面导航功能、状态栏提供系统状态显示,如时间、充电状态等。 -3. 设置:提供了关于设备,应用管理,亮度设置等功能。 - -## 目录 - -``` -/applications/standard/ -├── launcher # 桌面应用代码仓。 -├── systemui # SystemUI应用代码。 -├── settings # 设置应用代码仓。 -├── hap # 系统应用二进制仓。 -``` - -## 相关仓 - -**系统应用** - -applications\_standard\_settings - -applications\_standard\_launcher - -applications\_standard\_systemui - -applications\_standard\_hap - diff --git "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/30.\347\274\226\350\257\221\346\236\204\345\273\272\345\255\220\347\263\273\347\273\237.md" "b/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/30.\347\274\226\350\257\221\346\236\204\345\273\272\345\255\220\347\263\273\347\273\237.md" deleted file mode 100644 index 15194d518fe0f548d1abf0705b984f6194d6b7f1..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/30.\347\274\226\350\257\221\346\236\204\345\273\272\345\255\220\347\263\273\347\273\237.md" +++ /dev/null @@ -1,76 +0,0 @@ ---- -title: 编译构建子系统 -permalink: /pages/0101021e -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:19 ---- -# 编译构建子系统 - -- [基本概念](#section175012297491) -- [运作机制](#section193961322175011) -- [轻量和小型系统](#section119041639115811) -- [标准系统](#section8750514195912) -- [相关仓](#section44651652878) - -编译构建子系统提供了一个基于gn和ninja的编译构建框架。主要提供以下功能: - -- 构建不同芯片平台的产品。如:Hi3516DV300平台。 - -- 根据产品配置可以按照组件组装打包产品需要的能力。 - -## 基本概念 - -在了解编译构建子系统的能力前,应了解如下基本概念: - -- 平台 - - 开发板和内核的组合,不同平台支持的子系统和组件不同。 - -- 子系统 - - OpenHarmony整体遵从分层设计,从下向上依次为:内核层、系统服务层、框架层和应用层。系统功能按照“系统 \> 子系统 \> 组件”逐级展开,在多设备部署场景下,支持根据实际需求裁剪某些非必要的子系统或组件。子系统是一个逻辑概念,它具体由对应的组件构成。 - -- 组件 - - 对子系统的进一步拆分,可复用的软件单元,它包含源码、配置文件、资源文件和编译脚本;能独立构建,以二进制方式集成,具备独立验证能力的二进制单元。 - -- gn - - Generate ninja的缩写,用于产生ninja文件。 - -- ninja - - ninja是一个专注于速度的小型构建系统。 - - -## 运作机制 - -OpenHarmony侧的编译构建流程主要包括编译命令行解析,调用gn,执行ninja: - -- 命令行解析:解析待编译的产品名称,加载相关配置。 -- 调用gn: 根据命令行解析的产品名称和编译类型,配置编译工具链和全局的编译选项。 -- 执行ninja:启动编译并生成对应的产品版本。 - -## 轻量和小型系统 - -轻量和小型系统的编译构建介绍请见[build\_lite](https://gitee.com/openharmony/build_lite)的Readme文档。 - -## 标准系统 - -标准系统的编译构建相关介绍请见build仓的Readme文档。 - -## 相关仓 - -**编译构建子系统** - -[build\_lite](https://gitee.com/openharmony/build_lite) - -build - diff --git "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/31.\350\257\255\350\250\200\350\277\220\350\241\214\346\227\266\345\255\220\347\263\273\347\273\237.md" "b/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/31.\350\257\255\350\250\200\350\277\220\350\241\214\346\227\266\345\255\220\347\263\273\347\273\237.md" deleted file mode 100644 index c47d7ad4086518ac07bb761a62a3b9ac94273ac6..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/31.\350\257\255\350\250\200\350\277\220\350\241\214\346\227\266\345\255\220\347\263\273\347\273\237.md" +++ /dev/null @@ -1,67 +0,0 @@ ---- -title: 语言运行时子系统 -permalink: /pages/0101021f -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:19 ---- -# 语言运行时子系统 - -- [简介](#section15963162310012) -- [目录](#section971210485617) -- [约束](#section119744591305) -- [说明](#section1312121216216) -- [相关仓](#section1371113476307) - -## 简介 - -语言运行时子系统提供了JS、C/C++语言程序的编译、执行环境,提供支撑运行时的基础库,以及关联的API接口、编译器和配套工具。当前支持的编程语言包括JS、C/C++。子系统中的组件划分也是基于编程语言维度,每个组件支持单独编译,可以基于场景进行组合和分离。 - -**图 1** 子系统架构图 - - -![](/images/readme/figures/子系统架构图-5.png) - -如上图所示,子系统提供编译器及相关工具链支撑JS、C/C++语言的运行,并提供了语言相关基础库、API 接口、JS engine能力。 - -## 目录 - -``` -/prebuilts/mingw-w64/ohos/linux-x86_64 # 提供Linux平台交叉编译工具链 - └── clang-mingw - ├── bin - ├── lib - ├── libexec - ├── NOTICE - ├── share - └── x86_64-w64-mingw32 -``` - -## 约束 - -1. 相关API接口不能擅自新增、修改和调整 -2. JS engine的实现由子系统内部约束,不对外提供配置项。 - -## 说明 - -语言基础能力支持通过库文件方式支持,部分能力会整合到Native、JS的SDK中,集成到DevEco Studio中发布使用。 - -涉及引用的三方软件及预编译工具链仓如下: - -/third\_party/boost - -/third\_party/quickjs - -/third\_party/jerryscript - -/third\_party/mingw-w64 - -## 相关仓 - -**语言运行时子系统** diff --git "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/32.AI\344\270\232\345\212\241\345\255\220\347\263\273\347\273\237.md" "b/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/32.AI\344\270\232\345\212\241\345\255\220\347\263\273\347\273\237.md" deleted file mode 100644 index d1254edda6e10306fbf76e8cca2cacb04ceab820..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/02.\344\272\206\350\247\243OpenHarmony\347\263\273\347\273\237/32.AI\344\270\232\345\212\241\345\255\220\347\263\273\347\273\237.md" +++ /dev/null @@ -1,445 +0,0 @@ ---- -title: AI业务子系统 -permalink: /pages/01010220 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:19 ---- -# AI业务子系统 - -- [简介](#section187321516154516) -- [目录](#section571610913453) -- [约束](#section5748426453) -- [使用](#section7981135212144) -- [涉及仓](#section10492183517430) -- [AI引擎开发导航](#section6808423133718) - -## 简介 - -AI业务子系统是OpenHarmony提供原生的分布式AI能力的子系统。本次开源范围是提供了统一的AI引擎框架,实现算法能力快速插件化集成。框架中主要包含插件管理、模块管理和通信管理等模块,对AI算法能力进行生命周期管理和按需部署。后续,会逐步定义统一的AI能力接口,便于AI能力的分布式调用。同时,提供适配不同推理框架层级的统一推理接口。 - -**图 1** AI引擎框架 -![](/images/readme/figures/AI引擎框架.png "AI引擎框架") - -## 目录 - -``` -/foundation/ai/engine # AI子系统主目录 -├── interfaces -│ └── kits # AI子系统对外接口 -└── services -│ ├── client # AI子系统Client模块 -│ │ ├── client_executor # Client模块执行主体 -│ │ └── communication_adapter # Client模块通信适配层,支持拓展 -│ ├── common # AI子系统公共工具、协议模块 -│ │ ├── platform -│ │ ├── protocol -│ │ └── utils -│ └── server # AI子系统服务端模块 -│ │ ├── communication_adapter # Server模块通信适配层,支持拓展 -│ │ ├── plugin -│ │ ├── asr -│ │ └── keyword_spotting # ASR算法插件参考:唤醒词识别 -│ │ └── cv -│ │ └── image_classification # CV算法插件参考:图片分类 -│ │ ├── plugin_manager -│ │ └── server_executor # Server模块执行主体 -``` - -## 约束 - -* **语言限制**:C/C++语言 - -* **操作系统限制**:OpenHarmony操作系统 - -* **AI服务启动的约束与限制**:SAMGR(System Ability Manager)启动且运行正常 - -## 使用 - -1. **AI业务子系统编译** - - 轻量级AI引擎框架模块,代码所在路径://foundation/ai/engine/services - - 编译指令如下: - - 1. **设置编译路径** - - ``` - hb set -root dir(项目代码根目录) - ``` - - 2. **设置编译产品**(执行后用方向键和回车进行选择): - - ``` - hb set -p - ``` - - 3. **执行编译**: - - ``` - hb build -f(编译全仓) - 或者 hb build ai_engine(只编译ai_engine组件) - ``` - - >**注意**:hb相关配置请参考编译构建子系统**build\_lite** - -2. **插件开发**(以唤醒词识别为例) - - 位置://foundation/ai/engine/services/server/plugin/asr/keyword\_spotting - - >**注意**:插件需要实现server提供的IPlugin接口和IPluginCallback接口 - - ``` - #include "plugin/i_plugin.h - class KWSPlugin : public IPlugin { # Keywords Spotting Plugin(KWSPlugin)继承IPlugin算法插件基类public: - KWSPlugin(); - ~KWSPlugin(); - - const long long GetVersion() const override; - const char* GetName() const override; - const char* GetInferMode() const override; - - int32_t Prepare(long long transactionId, const DataInfo &amp;inputInfo, DataInfo &amp;outputInfo) override; - int32_t SetOption(int optionType, const DataInfo &amp;inputInfo) override; - int32_t GetOption(int optionType, const DataInfo &amp;inputInfo, DataInfo &amp;outputInfo) override; - int32_t SyncProcess(IRequest *request, IResponse *&amp;response) override; - int32_t AsyncProcess(IRequest *request, IPluginCallback*callback) override; - int32_t Release(bool isFullUnload, long long transactionId, const DataInfo &amp;inputInfo) override; - . - . - . - }; - ``` - - >**注意**:SyncProcess和AsyncProcess接口只需要根据算法实际情况实现一个接口即可,另一个用空方法占位(这里KWS插件为同步算法,故异步接口为空实现)。 - - ``` - #include "aie_log.h" - #include "aie_retcode_inner.h" - . - . - . - - const long long KWSPlugin::GetVersion() const - { - return ALGOTYPE_VERSION_KWS; - } - - const char *KWSPlugin::GetName() const - { - return ALGORITHM_NAME_KWS.c_str(); - } - - const char *KWSPlugin::GetInferMode() const - { - return DEFAULT_INFER_MODE.c_str(); - } - . - . - . - int32_t KWSPlugin::AsyncProcess(IRequest *request, IPluginCallback *callback) - { - return RETCODE_SUCCESS; - } - ``` - -3. **插件SDK开发**(以唤醒词识别kws\_sdk为例) - - 位置://foundation/ai/engine/services/client/algorithm\_sdk/asr/keyword\_spotting - - 唤醒词识别SDK: - - ``` - class KWSSdk { - public: - KWSSdk(); - virtual ~KWSSdk(); - - /** - * @brief Create a new session with KWS Plugin - * - * @return Returns KWS_RETCODE_SUCCESS(0) if the operation is successful, - * returns a non-zero value otherwise. - */ - int32_t Create(); - - /** - * @brief Synchronously execute keyword spotting once - * - * @param audioInput pcm data. - * @return Returns KWS_RETCODE_SUCCESS(0) if the operation is successful, - * returns a non-zero value otherwise. - */ - int32_t SyncExecute(const Array &audioInput); - - /** - * @brief Asynchronously execute keyword spotting once - * - * @param audioInput pcm data. - * @return Returns KWS_RETCODE_SUCCESS(0) if the operation is successful, - * returns a non-zero value otherwise. - */ - int32_t AsyncExecute(const Array &audioInput); - - /** - * @brief Set callback - * - * @param callback Callback function that will be called during the process. - * @return Returns KWS_RETCODE_SUCCESS(0) if the operation is successful, - * returns a non-zero value otherwise. - */ - int32_t SetCallback(const std::shared_ptr &callback); - - /** - * @brief Destroy the created session with KWS Plugin - * - * @return Returns KWS_RETCODE_SUCCESS(0) if the operation is successful, - * returns a non-zero value otherwise. - */ - int32_t Destroy(); - ``` - - >**注意**:SDK调用AI引擎客户端接口顺序应遵循AieClientInit-\>AieClientPrepare-\>AieClientSyncProcess/AieClientAsyncProcess-\>AieClientRelease-\>AieClientDestroy,否则调用接口会返回错误码;同时应保证各个接口都有调用到,要不然会引起内存泄漏。 - - ``` - int32_t KWSSdk::KWSSdkImpl::Create() - { - if (kwsHandle_ != INVALID_KWS_HANDLE) { - HILOGE("[KWSSdkImpl]The SDK has been created"); - return KWS_RETCODE_FAILURE; - } - if (InitComponents() != RETCODE_SUCCESS) { - HILOGE("[KWSSdkImpl]Fail to init sdk components"); - return KWS_RETCODE_FAILURE; - } - int32_t retCode = AieClientInit(configInfo_, clientInfo_, algorithmInfo_, nullptr); - if (retCode != RETCODE_SUCCESS) { - HILOGE("[KWSSdkImpl]AieClientInit failed. Error code[%d]", retCode); - return KWS_RETCODE_FAILURE; - } - if (clientInfo_.clientId == INVALID_CLIENT_ID) { - HILOGE("[KWSSdkImpl]Fail to allocate client id"); - return KWS_RETCODE_FAILURE; - } - DataInfo inputInfo = { - .data = nullptr, - .length = 0, - }; - DataInfo outputInfo = { - .data = nullptr, - .length = 0, - }; - retCode = AieClientPrepare(clientInfo_, algorithmInfo_, inputInfo, outputInfo, nullptr); - if (retCode != RETCODE_SUCCESS) { - HILOGE("[KWSSdkImpl]AieclientPrepare failed. Error code[%d]", retCode); - return KWS_RETCODE_FAILURE; - } - if (outputInfo.data == nullptr || outputInfo.length <= 0) { - HILOGE("[KWSSdkImpl]The data or length of output info is invalid"); - return KWS_RETCODE_FAILURE; - } - MallocPointerGuard pointerGuard(outputInfo.data); - retCode = PluginHelper::UnSerializeHandle(outputInfo, kwsHandle_); - if (retCode != RETCODE_SUCCESS) { - HILOGE("[KWSSdkImpl]Get handle from inputInfo failed"); - return KWS_RETCODE_FAILURE; - } - return KWS_RETCODE_SUCCESS; - } - - int32_t KWSSdk::KWSSdkImpl::SyncExecute(const Array &audioInput) - { - intptr_t newHandle = 0; - Array kwsResult = { - .data = nullptr, - .size = 0 - }; - DataInfo inputInfo = { - .data = nullptr, - .length = 0 - }; - DataInfo outputInfo = { - .data = nullptr, - .length = 0 - }; - int32_t retCode = PluginHelper::SerializeInputData(kwsHandle_, audioInput, inputInfo); - if (retCode != RETCODE_SUCCESS) { - HILOGE("[KWSSdkImpl]Fail to serialize input data"); - callback_->OnError(KWS_RETCODE_SERIALIZATION_ERROR); - return RETCODE_FAILURE; - } - retCode = AieClientSyncProcess(clientInfo_, algorithmInfo_, inputInfo, outputInfo); - if (retCode != RETCODE_SUCCESS) { - HILOGE("[KWSSdkImpl]AieClientSyncProcess failed. Error code[%d]", retCode); - callback_->OnError(KWS_RETCODE_PLUGIN_EXECUTION_ERROR); - return RETCODE_FAILURE; - } - if (outputInfo.data == nullptr || outputInfo.length <= 0) { - HILOGE("[KWSSdkImpl] The data or length of outputInfo is invalid. Error code[%d]", retCode); - callback_->OnError(KWS_RETCODE_NULL_PARAM); - return RETCODE_FAILURE; - } - MallocPointerGuard pointerGuard(outputInfo.data); - retCode = PluginHelper::UnSerializeOutputData(outputInfo, newHandle, kwsResult); - if (retCode != RETCODE_SUCCESS) { - HILOGE("[KWSSdkImpl]UnSerializeOutputData failed. Error code[%d]", retCode); - callback_->OnError(KWS_RETCODE_UNSERIALIZATION_ERROR); - return retCode; - } - if (kwsHandle_ != newHandle) { - HILOGE("[KWSSdkImpl]The handle[%lld] of output data is not equal to the current handle[%lld]", - (long long)newHandle, (long long)kwsHandle_); - callback_->OnError(KWS_RETCODE_PLUGIN_SESSION_ERROR); - return RETCODE_FAILURE; - } - callback_->OnResult(kwsResult); - return RETCODE_SUCCESS; - } - - int32_t KWSSdk::KWSSdkImpl::Destroy() - { - if (kwsHandle_ == INVALID_KWS_HANDLE) { - return KWS_RETCODE_SUCCESS; - } - DataInfo inputInfo = { - .data = nullptr, - .length = 0 - }; - int32_t retCode = PluginHelper::SerializeHandle(kwsHandle_, inputInfo); - if (retCode != RETCODE_SUCCESS) { - HILOGE("[KWSSdkImpl]SerializeHandle failed. Error code[%d]", retCode); - return KWS_RETCODE_FAILURE; - } - retCode = AieClientRelease(clientInfo_, algorithmInfo_, inputInfo); - if (retCode != RETCODE_SUCCESS) { - HILOGE("[KWSSdkImpl]AieClientRelease failed. Error code[%d]", retCode); - return KWS_RETCODE_FAILURE; - } - retCode = AieClientDestroy(clientInfo_); - if (retCode != RETCODE_SUCCESS) { - HILOGE("[KWSSdkImpl]AieClientDestroy failed. Error code[%d]", retCode); - return KWS_RETCODE_FAILURE; - } - mfccProcessor_ = nullptr; - pcmIterator_ = nullptr; - callback_ = nullptr; - kwsHandle_ = INVALID_KWS_HANDLE; - return KWS_RETCODE_SUCCESS; - } - ``` - -4. **sample开发** [(参考唤醒词识别demo)](https://gitee.com/openharmony/applications_sample_camera/tree/master/ai) - - 位置://applications/sample/camera/ai/asr/keyword\_spotting - - **调用Create** - - ``` - bool KwsManager::PreparedInference() - { - if (capturer_ == nullptr) { - printf("[KwsManager] only load plugin after AudioCapturer ready\n"); - return false; - } - if (plugin_ != nullptr) { - printf("[KwsManager] stop created InferencePlugin at first\n"); - StopInference(); - } - plugin_ = std::make_shared(); - if (plugin_ == nullptr) { - printf("[KwsManager] fail to create inferencePlugin\n"); - return false; - } - if (plugin_->Create() != SUCCESS) { - printf("[KwsManager] KWSSdk fail to create.\n"); - return false; - } - std::shared_ptr callback = std::make_shared(); - if (callback == nullptr) { - printf("[KwsManager] new Callback failed.\n"); - return false; - } - plugin_->SetCallback(callback); - return true; - } - ``` - - **调用SyncExecute** - - ``` - void KwsManager::ConsumeSamples() - { - uintptr_t sampleAddr = 0; - size_t sampleSize = 0; - int32_t retCode = SUCCESS; - while (status_ == RUNNING) { - { - std::lock_guard lock(mutex_); - if (cache_ == nullptr) { - printf("[KwsManager] cache_ is nullptr.\n"); - break; - } - sampleSize = cache_->GetCapturedBuffer(sampleAddr); - } - if (sampleSize == 0 || sampleAddr == 0) { - continue; - } - Array input = { - .data = (int16_t *)(sampleAddr), - .size = sampleSize >> 1 - }; - { - std::lock_guard lock(mutex_); - if (plugin_ == nullptr) { - printf("[KwsManager] cache_ is nullptr.\n"); - break; - } - if ((retCode = plugin_->SyncExecute(input)) != SUCCESS) { - printf("[KwsManager] SyncExecute KWS failed with retCode = [%d]\n", retCode); - continue; - } - } - } - } - ``` - - **调用Destroy** - - ``` - void KwsManager::StopInference() - { - printf("[KwsManager] StopInference\n"); - if (plugin_ != nullptr) { - int ret = plugin_->Destroy(); - if (ret != SUCCESS) { - printf("[KwsManager] plugin_ destroy failed.\n"); - } - plugin_ = nullptr; - } - } - ``` - - -## 涉及仓 - -AI子系统 - -ai_engine - -依赖仓: - -build\_lite - -distributedschedule\_services\_samgr\_lite - -startup\_init\_lite - -## AI引擎开发导航 - -[《AI插件开发指南》](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/subsystems/subsys-aiframework-guide.md) \ No newline at end of file diff --git "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/03.\346\234\257\350\257\255.md" "b/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/03.\346\234\257\350\257\255.md" deleted file mode 100644 index 531630494f0619ef359d53ff31eda557a0ea5782..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/03.\346\234\257\350\257\255.md" +++ /dev/null @@ -1,112 +0,0 @@ ---- -title: 术语 -permalink: /pages/010103 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:19 ---- -# 术语 - -- [A](#section1679023922312) -- [B](#section62182102017) -- [D](#section1670294920236) -- [F](#section5406185415236) -- [H](#section891816813243) -- [I](#section10124052142516) -- [P](#section779354121411) -- [S](#section25661636182615) - -## A - -- **Ability** - - 应用的重要组成部分,是应用所具备能力的抽象。Ability分为两种类型,Feature Ability和Particle Ability。 - - -- **AbilitySlice** - - 切片,是单个可视化界面及其交互逻辑的总和,是Feature Ability的组成单元。一个Feature Ability可以包含一组业务关系密切的可视化界面,每一个可视化界面对应一个AbilitySlice。 - -- **AMS** - - Ability Manager Service,Ability管理服务。 - - -## B - -- **BMS** - - Bundle Manager Service,包管理服务。 - - -## D - -- **DevEco Studio for Embedded** - - 嵌入式设备开发IDE。 - -- **DMS** - - Distributed Management Service,分布式管理服务。 - - -## F - -- **FA** - - Feature Ability,代表有界面的Ability,用于与用户进行交互。 - - -## H - -- **HAP** - - OpenHarmony Ability Package,一个HAP文件包含应用的所有内容,由代码、资源、三方库及应用配置文件组成,其文件后缀名为.hap。 - -- **HCS** - - HDF Configuration Source是HDF驱动框架的配置描述语言,是为了实现配置代码与驱动代码解耦,以及便于配置的管理而设计的一种Key-Value为主体的文本格式。 - - -- **HC-GEN** - - HDF Configuration Generator是HCS配置转换工具,可以将HDF配置文件转换为软件可读取的文件格式。 - - -- **HDF** - - Hardware Driver Foundation,硬件驱动框架,用于提供统一外设访问能力和驱动开发、管理框架。 - - -## I - -- **IDN** - - Intelligent Distributed Networking,是OpenHarmony特有的分布式组网能力单元。开发者可以通过IDN获取分布式网络内的设备列表和设备状态信息,以及注册分布式网络内设备的在网状态变化信息。 - - -## P - -- **PA** - - Particle Ability,代表无界面的Ability,主要为Feature Ability提供支持,例如作为后台服务提供计算能力,或作为数据仓库提供数据访问能力。 - - -## S - -- **Super virtual device,超级虚拟终端** - - 亦称超级终端,通过分布式技术将多个终端的能力进行整合,存放在一个虚拟的硬件资源池里,根据业务需要统一管理和调度终端能力,来对外提供服务。 - -- **System Type,系统类型** - - Mini System,轻量系统:面向MCU类处理器,例如ARM Cortex-M、RISC-V 32位的设备,资源极其有限,参考内存≥128KiB,提供丰富的近距连接能力以及丰富的外设总线访问能力。典型产品有智能家居领域的联接类模组、传感器设备等。 - - Small System,小型系统:面向应用处理器,例如Arm Cortex-A的设备,参考内存≥1MiB,提供更高的安全能力,提供标准的图形框架,提供视频编解码的多媒体能力。典型产品有智能家居领域的IPCamera、电子猫眼、路由器以及智慧出行域的行车记录仪等。 - - Standard System,标准系统:面向应用处理器,例如Arm Cortex-A的设备,参考内存≥128MiB,提供增强的交互能力,提供3D GPU以及硬件合成能力,提供更多控件以及动效更丰富的图形能力,提供完整的应用框架。典型产品有高端的冰箱显示屏等。 - - diff --git "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/04.\347\211\210\346\234\254\350\257\264\346\230\216.md" "b/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/04.\347\211\210\346\234\254\350\257\264\346\230\216.md" deleted file mode 100644 index b6959c68a30abee36ed4e3dfec13c5c905fa18b5..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/01.\344\272\206\350\247\243OpenHarmony/04.\347\211\210\346\234\254\350\257\264\346\230\216.md" +++ /dev/null @@ -1,30 +0,0 @@ ---- -title: 版本说明 -permalink: /pages/010104 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:19 ---- -# OpenHarmony Release Notes -## OpenHarmony 3.x Releases -- [OpenHarmony v3.1 Beta (2021-12-31)](/pages/extra/d61a8a/) -- [OpenHarmony v3.0.1 LTS (2022-01-12)](/pages/extra/23d8e8/) -- [OpenHarmony v3.0 LTS (2021-09-30)](/pages/extra/096eed/) - -## OpenHarmony 2.x Releases - -- [OpenHarmony v2.2 beta2 (2021-08-04)](/pages/extra/bb5e43/) -- [OpenHarmony 2.0 Canary (2021-06-02)](/pages/extra/e47050/) -## OpenHarmony 1.x Releases -- [OpenHarmony v1.1.3 LTS (2021-09-30)](/pages/extra/ce2b2b/) -- [OpenHarmony v1.1.2 LTS (2021-08-04)](/pages/extra/055b26/) -- [OpenHarmony 1.1.1 LTS (2021-06-22)](/pages/extra/f5599c/) -- [OpenHarmony 1.1.0 LTS (2021-04-01)](/pages/extra/cada0e/) -- [OpenHarmony 1.0 (2020-09-10)](/pages/extra/d09857/) - diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/01.\350\275\273\351\207\217\344\270\216\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250\346\246\202\350\277\260.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/01.\350\275\273\351\207\217\344\270\216\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250\346\246\202\350\277\260.md" deleted file mode 100644 index f11540dd4674375d61f29ab89088dc070ec0d7b9..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/01.\350\275\273\351\207\217\344\270\216\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250\346\246\202\350\277\260.md" +++ /dev/null @@ -1,36 +0,0 @@ ---- -title: 轻量与小型系统入门概述 -permalink: /pages/01020101 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:19 ---- -# 轻量与小型系统入门概述 - -OpenHarmony轻量和小型系统适用于内存较小的IOT设备。通过本文,开发者可以快速熟悉OpenHarmony轻量和小型系统的环境搭建、编译、烧录、调测以及运行“Hello World”等。 - -轻量和小型系统的开发有以下两种方法: - -- 用Windows环境进行开发和烧录,使用Linux环境进行编译。 -- 统一使用Linux环境进行开发、编译和烧录。 - -因目前Windows系统不支持编译,暂时无法全部使用Windows环境进行开发,开发者可根据使用习惯选择合适的开发方法。 - -本文将介绍第二种方法,下方所有操作均在Linux环境下进行。 - -本文选取了三款典型开发板:Hi3861 WLAN模组、Hi3516DV300、Hi3518EV300,并基于上述三款开发板进行开发介绍。开发板的具体外观和规格可参见[本文附录](/pages/0102010401#section19352114194115),开发者可根据需要自行购买的开发板。 - -轻量和小型系统快速入门流程如下图所示,其中搭建编译环境环节可根据实际情况选择Docker方式或安装包方式其中一种即可。 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->Docker环境已经封装了相关编译工具,开发者在使用该Docker环境时可以省去Ubuntu编译环境及开发板环境的的搭建操作。 - -**图 1** 轻量和小型系统快速入门流程 -![](/images/device-dev/quick-start/figures/轻量和小型系统快速入门流程.png "轻量和小型系统快速入门流程") - diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/02.\346\220\255\345\273\272\350\275\273\351\207\217\344\270\216\345\260\217\345\236\213\347\263\273\347\273\237\347\216\257\345\242\203/01.\346\220\255\345\273\272\347\263\273\347\273\237\347\216\257\345\242\203\346\246\202\350\277\260.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/02.\346\220\255\345\273\272\350\275\273\351\207\217\344\270\216\345\260\217\345\236\213\347\263\273\347\273\237\347\216\257\345\242\203/01.\346\220\255\345\273\272\347\263\273\347\273\237\347\216\257\345\242\203\346\246\202\350\277\260.md" deleted file mode 100644 index 767b47c649a00e9618e5f8b5ea911d580857fae3..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/02.\346\220\255\345\273\272\350\275\273\351\207\217\344\270\216\345\260\217\345\236\213\347\263\273\347\273\237\347\216\257\345\242\203/01.\346\220\255\345\273\272\347\263\273\347\273\237\347\216\257\345\242\203\346\246\202\350\277\260.md" +++ /dev/null @@ -1,19 +0,0 @@ ---- -title: 搭建系统环境概述 -permalink: /pages/0102010201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:19 ---- -# 搭建系统环境概述 - -OpenHarmony可以使用DevEco Device Tool进行开发、编译、烧录、调测等。 - -当前DevEco Device Tool发布了Windows和Ubuntu两个版本,本文以Ubuntu版本进行相应开发介绍。 - diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/02.\346\220\255\345\273\272\350\275\273\351\207\217\344\270\216\345\260\217\345\236\213\347\263\273\347\273\237\347\216\257\345\242\203/02.\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/02.\346\220\255\345\273\272\350\275\273\351\207\217\344\270\216\345\260\217\345\236\213\347\263\273\347\273\237\347\216\257\345\242\203/02.\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207.md" deleted file mode 100644 index 61c55bba2fc64e30649bef94678c154e77c1577e..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/02.\346\220\255\345\273\272\350\275\273\351\207\217\344\270\216\345\260\217\345\236\213\347\263\273\347\273\237\347\216\257\345\242\203/02.\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207.md" +++ /dev/null @@ -1,86 +0,0 @@ ---- -title: 开发环境准备 -permalink: /pages/0102010202 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:19 ---- -# 开发环境准备 - -- [系统要求](#zh-cn_topic_0000001072959308_section1865184385215) -- [安装DevEco Device Tool](#zh-cn_topic_0000001072959308_section86587531620) - -DevEco Device Tool Ubuntu版本支持OpenHarmony源码开发、编译、烧录的一站式开发环境,因此,本章节为您介绍在Ubuntu环境下,如何搭建一套完整的可视化开发环境。 - -## 系统要求 - -- Ubuntu18及以上版本,内存推荐16 GB及以上。 -- 系统的用户名不能含有中文字符。 -- 只能使用普通用户角色搭建开发环境。 - -## 安装DevEco Device Tool - -DevEco Device Tool基于Visual Studio Code进行扩展,在Visual Studio Code上以插件方式运行,Visual Studio Code版本为1.60及以上。同时,DevEco Device Tool还依赖Python工具,并要求Python为3.8\~3.9版本。 - -在安装过程中,DevEco Device Tool会自动检查Visual Studio Code和Python,如果检测到Visual Studio Code、Python未安装或版本不符合要求,安装程序会自动安装Visual Studio Code和Python。 - -1. 将Ubuntu Shell环境修改为bash。 - 1. 执行如下命令,确认输出结果为bash。如果输出结果不是bash,请根据步骤2,将Ubuntu shell修改为bash。 - - ``` - ls -l /bin/sh - ``` - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001194078294.png) - - 2. 打开终端工具,执行如下命令,输入密码,然后选择**No**,将Ubuntu shell由dash修改为bash。 - - ``` - sudo dpkg-reconfigure dash - ``` - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001238878219.png) - -2. 下载[DevEco Device Tool 3.0 Beta2](https://device.harmonyos.com/cn/ide#download_beta)Linux版本,下载时,请先使用华为开发者帐号进行登录后下载。如未注册华为开发者账号,请先[注册](https://developer.huawei.com/consumer/cn/doc/start/registration-and-verification-0000001053628148)。 -3. 解压DevEco Device Tool软件包并对解压后的文件夹进行赋权。 - 1. 进入DevEco Device Tool软件包目录,执行如下命令解压软件包,其中devicetool-linux-tool-3.0.0.200.zip为软件包名称,请根据实际进行修改。 - - ``` - unzip devicetool-linux-tool-3.0.0.300.zip - ``` - - 2. 进入解压后的文件夹,执行如下命令,赋予安装文件可执行权限,其中devicetool-linux-tool-3.0.0.300.sh请根据实际进行修改。 - - ``` - chmod u+x devicetool-linux-tool-3.0.0.300.sh - ``` - -4. 执行如下命令,安装DevEco Device Tool,其中devicetool-linux-tool-3.0.0.300.sh请根据实际进行修改。 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >安装过程中,会自动检查Visual Studio Code和Python是否安装,且版本符合要求,其中Visual Studio Code为1.60及以上版本,Python为3.8\~3.9版本。如果不满足,则安装过程中会自动安装,提示“Do you want to continue?”,请输入“Y”后继续安装。 - - ``` - sudo ./devicetool-linux-tool-3.0.0.300.sh -- --install-plugins - ``` - - 安装完成后,当界面输出“Deveco Device Tool successfully installed.”时,表示DevEco Device Tool安装成功。 - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001239348791.png) - -5. 安装完成后,在Ubuntu左下角的![](/images/device-dev/quick-start/figures/zh-cn_image_0000001075566984.png)中,启动Visual Studio Code。 -6. 启动Visual Studio Code,DevEco Device Tool运行依赖C/C++、CodeLLDB插件,请点击Visual Studio Code左侧的![](/images/device-dev/quick-start/figures/button.png)按钮,分别搜索和安装C/C++、CodeLLDB插件。 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >如果在插件市场安装C/C++和CodeLLDB插件不成功,可手动下载插件后进行安装,具体请参考:[离线安装C/C++和CodeLLDB插件](https://device.harmonyos.com/cn/docs/documentation/guide/offline_plugin_install-0000001074376846)。 - - ![](/images/device-dev/quick-start/figures/deveco-device-tool-install-sucessful.png) - -7. 重启Visual Studio Code,点击![](/images/device-dev/quick-start/figures/zh-cn_image_0000001239226427.png)进入DevEco Device Tool工具界面。至此,DevEco Device Tool Ubuntu开发环境安装完成。![](/images/device-dev/quick-start/figures/zh-cn_image_0000001194668634.png) - diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/02.\346\220\255\345\273\272\350\275\273\351\207\217\344\270\216\345\260\217\345\236\213\347\263\273\347\273\237\347\216\257\345\242\203/03.\350\216\267\345\217\226\346\272\220\347\240\201.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/02.\346\220\255\345\273\272\350\275\273\351\207\217\344\270\216\345\260\217\345\236\213\347\263\273\347\273\237\347\216\257\345\242\203/03.\350\216\267\345\217\226\346\272\220\347\240\201.md" deleted file mode 100644 index a25bf2adf45340387ab4e39d0c5fdbd456326a0c..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/02.\346\220\255\345\273\272\350\275\273\351\207\217\344\270\216\345\260\217\345\236\213\347\263\273\347\273\237\347\216\257\345\242\203/03.\350\216\267\345\217\226\346\272\220\347\240\201.md" +++ /dev/null @@ -1,67 +0,0 @@ ---- -title: 获取源码 -permalink: /pages/0102010203 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:19 ---- -# 获取源码 - -- [前提条件](#section21887149017) -- [操作步骤](#section349724435812) - -## 前提条件 - -1. 注册码云gitee账号。 -2. 注册码云SSH公钥,请参考[码云帮助中心](https://gitee.com/help/articles/4191)。 -3. 安装[git客户端](https://git-scm.com/book/zh/v2/%E8%B5%B7%E6%AD%A5-%E5%AE%89%E8%A3%85-Git)和[git-lfs](https://gitee.com/vcs-all-in-one/git-lfs?_from=gitee_search#downloading)并配置用户信息。 - - ``` - git config --global user.name "yourname" - git config --global user.email "your-email-address" - git config --global credential.helper store - ``` - -4. 安装码云repo工具,可以执行如下命令。 - - ``` - curl -s https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 > /usr/local/bin/repo #如果没有权限,可下载至其他目录,并将其配置到环境变量中 - chmod a+x /usr/local/bin/repo - pip3 install -i https://repo.huaweicloud.com/repository/pypi/simple requests - ``` - - -## 操作步骤 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->Master主干为开发分支,开发者可通过Master主干获取最新特性。发布版本代码相对比较稳定,开发者可基于发布版本代码进行商用功能开发。 - -- **OpenHarmony主干代码获取** - - 方式一(推荐):通过repo + ssh下载(需注册公钥,请参考[码云帮助中心](https://gitee.com/help/articles/4191))。 - - ``` - repo init -u git@gitee.com:openharmony/manifest.git -b master --no-repo-verify - repo sync -c - repo forall -c 'git lfs pull' - ``` - - 方式二:通过repo + https下载。 - - ``` - repo init -u https://gitee.com/openharmony/manifest.git -b master --no-repo-verify - repo sync -c - repo forall -c 'git lfs pull' - ``` - -- **OpenHarmony发布版本代码获取** - - OpenHarmony发布版本获取源码方式请参考[Release-Notes](/pages/010104)。 - - diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/02.\346\220\255\345\273\272\350\275\273\351\207\217\344\270\216\345\260\217\345\236\213\347\263\273\347\273\237\347\216\257\345\242\203/04.\344\275\277\347\224\250\345\256\211\350\243\205\345\214\205\346\226\271\345\274\217\346\220\255\345\273\272\347\274\226\350\257\221\347\216\257\345\242\203.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/02.\346\220\255\345\273\272\350\275\273\351\207\217\344\270\216\345\260\217\345\236\213\347\263\273\347\273\237\347\216\257\345\242\203/04.\344\275\277\347\224\250\345\256\211\350\243\205\345\214\205\346\226\271\345\274\217\346\220\255\345\273\272\347\274\226\350\257\221\347\216\257\345\242\203.md" deleted file mode 100644 index 70e7822db140d5f56e4d0726cb29bcfc22873cde..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/02.\346\220\255\345\273\272\350\275\273\351\207\217\344\270\216\345\260\217\345\236\213\347\263\273\347\273\237\347\216\257\345\242\203/04.\344\275\277\347\224\250\345\256\211\350\243\205\345\214\205\346\226\271\345\274\217\346\220\255\345\273\272\347\274\226\350\257\221\347\216\257\345\242\203.md" +++ /dev/null @@ -1,116 +0,0 @@ ---- -title: 使用安装包方式搭建编译环境 -permalink: /pages/0102010204 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:19 ---- -# 使用安装包方式搭建编译环境 - -- [安装必要的库和工具](#section108201740181219) -- [安装hb](#section15794154618411) -- [安装LLVM\(仅OpenHarmony\_v1.x分支/标签需要\)](#section711117144296) - -使用安装包方式搭建Ubuntu编译环境步骤如下: - -1. 安装必要的库和工具:编译所需的必要工具和库(如打包、镜像制作等) -2. 安装hb:OpenHarmony编译构建命令行工具 -3. 安装LLVM\(仅OpenHarmony\_v1.x分支/标签需要\) - -想要详细了解OpenHarmony编译构建模块功能的开发者可参考[编译构建使用指南](/pages/01050301)。 - -## 安装必要的库和工具 - -使用如下apt-get命令安装编译所需的必要的库和工具: - -``` -sudo apt-get install build-essential gcc g++ make zlib* libffi-dev e2fsprogs pkg-config flex bison perl bc openssl libssl-dev libelf-dev libc6-dev-amd64 binutils binutils-dev libdwarf-dev u-boot-tools mtd-utils gcc-arm-linux-gnueabi cpio device-tree-compiler -``` - -## 安装hb - -1. 运行如下命令安装hb - - ``` - python3 -m pip install --user ohos-build - ``` - -2. 设置环境变量 - - ``` - vim ~/.bashrc - ``` - - 将以下命令拷贝到.bashrc文件的最后一行,保存并退出。 - - ``` - export PATH=~/.local/bin:$PATH - ``` - - 执行如下命令更新环境变量。 - - ``` - source ~/.bashrc - ``` - -3. 执行"hb -h",界面打印以下信息即表示安装成功: - - ``` - usage: hb - - OHOS build system - - positional arguments: - {build,set,env,clean} - build Build source code - set OHOS build settings - env Show OHOS build env - clean Clean output - - optional arguments: - -h, --help show this help message and exit - ``` - - ->![](/images/device-dev/public_sys-resources/icon-notice.gif) **须知:** ->若安装hb的过程中遇到问题,请参见下文[常见问题](/pages/0102010206)进行解决。 - -## 安装LLVM\(仅OpenHarmony\_v1.x分支/标签需要\) - ->![](/images/device-dev/public_sys-resources/icon-notice.gif) **须知:** ->如果下载的源码为OpenHarmony\_v1.x分支/标签, 请按下面的步骤安装9.0.0版本的llvm。 ->如果下载的源码为Master及非OpenHarmony\_v1.x分支/标签,可直接跳过本小节,hb会自动下载最新的llvm。 - -1. 打开Linux编译服务器终端。 -2. [下载LLVM工具](https://repo.huaweicloud.com/harmonyos/compiler/clang/9.0.0-36191/linux/llvm-linux-9.0.0-36191.tar)。 -3. 解压LLVM安装包至\~/llvm路径下。 - - ``` - tar -zxvf llvm.tar -C ~/ - ``` - -4. 设置环境变量。 - - ``` - vim ~/.bashrc - ``` - - 将以下命令拷贝到.bashrc文件的最后一行,保存并退出。 - - ``` - export PATH=~/llvm/bin:$PATH - ``` - -5. 生效环境变量。 - - ``` - source ~/.bashrc - ``` - - diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/02.\346\220\255\345\273\272\350\275\273\351\207\217\344\270\216\345\260\217\345\236\213\347\263\273\347\273\237\347\216\257\345\242\203/05.\344\275\277\347\224\250Docker\346\226\271\345\274\217\346\220\255\345\273\272\347\274\226\350\257\221\347\216\257\345\242\203.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/02.\346\220\255\345\273\272\350\275\273\351\207\217\344\270\216\345\260\217\345\236\213\347\263\273\347\273\237\347\216\257\345\242\203/05.\344\275\277\347\224\250Docker\346\226\271\345\274\217\346\220\255\345\273\272\347\274\226\350\257\221\347\216\257\345\242\203.md" deleted file mode 100644 index 0ee80a7f027a2b346697a56131191097c8a136ba..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/02.\346\220\255\345\273\272\350\275\273\351\207\217\344\270\216\345\260\217\345\236\213\347\263\273\347\273\237\347\216\257\345\242\203/05.\344\275\277\347\224\250Docker\346\226\271\345\274\217\346\220\255\345\273\272\347\274\226\350\257\221\347\216\257\345\242\203.md" +++ /dev/null @@ -1,47 +0,0 @@ ---- -title: 使用Docker方式搭建编译环境 -permalink: /pages/0102010205 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:19 ---- -# 使用Docker方式搭建编译环境 - -- [安装Docker](#section7337134183512) -- [获取Docker环境](#section15666113905015) - -使用安装包方式搭建Ubuntu编译环境步骤如下: - -1. 安装Docker -2. 获取Docker环境: - -想要详细了解OpenHarmony编译构建模块功能的开发者可参考[编译构建使用指南](/pages/01050301)。 - -## 安装Docker - -- 请参考[官方指导](https://docs.docker.com/engine/install/)。 - -## 获取Docker环境 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->不同的源码版本要匹配使用对应版本的Docker环境,本文以Master主干代码为例进行说明。 - -OpenHarmony的Docker镜像托管在[HuaweiCloud SWR](https://console.huaweicloud.com/swr/?region=cn-south-1#/app/warehouse/warehouseMangeDetail/goldensir/openharmony-docker/openharmony-docker?type=ownImage)上。开发者可以通过该镜像在很大程度上简化编译前的环境配置。下文将介绍具体使用步骤。 - -1. 获取Docker镜像。 - - ``` - docker pull swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker:0.0.6 - ``` - -2. 进入OpenHarmony代码根目录执行如下命令,从而进入Docker构建环境。 - - ``` - docker run -it -v $(pwd):/home/openharmony swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker:0.0.6 - ``` diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/02.\346\220\255\345\273\272\350\275\273\351\207\217\344\270\216\345\260\217\345\236\213\347\263\273\347\273\237\347\216\257\345\242\203/06.\345\270\270\350\247\201\351\227\256\351\242\230.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/02.\346\220\255\345\273\272\350\275\273\351\207\217\344\270\216\345\260\217\345\236\213\347\263\273\347\273\237\347\216\257\345\242\203/06.\345\270\270\350\247\201\351\227\256\351\242\230.md" deleted file mode 100644 index 2686e745b031a9c55158e3c47e74328e5c1998c8..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/02.\346\220\255\345\273\272\350\275\273\351\207\217\344\270\216\345\260\217\345\236\213\347\263\273\347\273\237\347\216\257\345\242\203/06.\345\270\270\350\247\201\351\227\256\351\242\230.md" +++ /dev/null @@ -1,125 +0,0 @@ ---- -title: 常见问题 -permalink: /pages/0102010206 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:19 ---- -# 常见问题 - -- [hb 安装过程中出现乱码、段错误](#section411894616119) -- [hb 安装过程中提示"cannot import 'sysconfig' from 'distutils'"](#section629417571626) -- [hb 安装过程中提示"module 'platform' has no attribute 'linux\_distribution'"](#section10871523332) -- [hb 安装过程中提示"Could not find a version that satisfies the requirement ohos-build"](#section47351657163213) -- [Linux编译服务器终端输入不识别的命令时提示“ImportError: No module named apt\_pkg”](#section159891252236) - -## hb 安装过程中出现乱码、段错误 - -- **现象描述** - - 执行“python3 -m pip install --user ohos-build”出现乱码、段错误(segmentation fault)。 - - -- **可能原因** - - pip版本过低。 - -- **解决办法** - - 执行如下命令升级pip。 - - ``` - python3 -m pip install -U pip - ``` - - -## hb 安装过程中提示"cannot import 'sysconfig' from 'distutils'" - -- **现象描述** - - 执行“python3 -m pip install --user ohos-build”提示"cannot import 'sysconfig' from 'distutils'" - - -- **可能原因** - - 缺少distutils模块。 - -- **解决办法** - - 执行如下命令安装。 - - ``` - sudo apt-get install python3.8-distutils - ``` - - -## hb 安装过程中提示"module 'platform' has no attribute 'linux\_distribution'" - -- **现象描述** - - 执行“python3 -m pip install --user ohos-build”提示"module 'platform' has no attribute 'linux\_distribution'" - - -- **可能原因** - - python3 pip安装兼容性问题。 - -- **解决办法** - - 执行如下命令重新安装pip。 - - ``` - sudo apt remove python3-pip - curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py - python get-pip.py - ``` - - -## hb 安装过程中提示"Could not find a version that satisfies the requirement ohos-build" - -- **现象描述** - - 执行“python3 -m pip install --user ohos-build”提示"Could not find a version that satisfies the requirement ohos-build" - - -- **可能原因** - - 可能是网络环境较差导致的安装失败。 - -- **解决办法** - 1. 请检查网络连接是否正常。如果网络有问题,请修复网络问题后重新安装。 - 2. 若网络正常,请尝试指定临时pypi源的方式安装: - - ``` - python3 -m pip install -i https://pypi.tuna.tsinghua.edu.cn/simple ohos-build - ``` - - - -## Linux编译服务器终端输入不识别的命令时提示“ImportError: No module named apt\_pkg” - -- **现象描述** - - Linux编译服务器终端输入不识别的命令时,提示"ImportError: No module named apt\_pkg" - - -- **可能原因** - - python3 apt安装兼容性问题。 - -- **解决办法** - - 执行如下命令重新安装python3-apt。 - - ``` - sudo apt-get remove python3-apt - sudo apt-get install python3-apt - ``` - - diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/01.Hi3861\345\274\200\345\217\221\346\235\277/01.\345\256\211\350\243\205\345\274\200\345\217\221\346\235\277\347\216\257\345\242\203.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/01.Hi3861\345\274\200\345\217\221\346\235\277/01.\345\256\211\350\243\205\345\274\200\345\217\221\346\235\277\347\216\257\345\242\203.md" deleted file mode 100644 index 20e5fe537b74d95abc21369590e0455a35956913..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/01.Hi3861\345\274\200\345\217\221\346\235\277/01.\345\256\211\350\243\205\345\274\200\345\217\221\346\235\277\347\216\257\345\242\203.md" +++ /dev/null @@ -1,310 +0,0 @@ ---- -title: 安装开发板环境 -permalink: /pages/010201030101 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:19 ---- -# 安装开发板环境 - -- [Hi3861工具要求](#section466851916410) - - [硬件要求](#section19202111020215) - - [软件要求](#section727451210318) - -- [安装Linux编译工具](#section497484245614) - - [安装编译依赖基础软件(仅Ubuntu 20+需要)](#section45512412251) - - [安装Scons](#section7438245172514) - - [安装python模块](#section88701892341) - - [安装gcc\_riscv32(WLAN模组类编译工具链)](#section34435451256) - - -## Hi3861工具要求 - -### 硬件要求 - -- Linux工作台 -- Hi3861开发板 -- USB Type-C线(Linux工作台通过USB与Hi3861开发板连接) - -### 软件要求 - ->![](/images/device-dev/public_sys-resources/icon-notice.gif) **须知:** ->本节描述采用安装包方式安装相关工具的操作步骤。如果使用Docker方式安装,无需安装[表1](#table6299192712513)中的相关工具,请直接从[新建应用程序](/pages/010201030102)开始操作。 - -Hi3861开发板需要的工具如下表所示。 - -**表 1** Hi3861开发板需要安装的工具 - - - - - - - - - - - - - - - - - - - -

开发工具

-

用途

-

编译基础软件包(仅ubuntu 20+需要)

-

编译依赖的基础软件包

-

SCons3.0.4+

-

编译构建工具

-

python模块:setuptools、kconfiglib、pycryptodome、six、ecdsa

-

编译构建工具

-

gcc riscv32

-

编译构建工具

-
- -## 安装Linux编译工具 - -### 安装编译依赖基础软件(仅Ubuntu 20+需要) - -执行以下命令进行安装: - -``` -sudo apt-get install build-essential gcc g++ make zlib* libffi-dev -``` - -### 安装Scons - -1. 运行如下命令,安装SCons安装包。 - - ``` - python3 -m pip install scons - ``` - -2. 运行如下命令,查看是否安装成功。如果安装成功,查询结果下图所示。 - - ``` - scons -v - ``` - - **图 1** SCons安装成功界面,版本要求3.0.4以上 - ![](/images/device-dev/quick-start/figures/SCons安装成功界面-版本要求3-0-4以上.png "SCons安装成功界面-版本要求3-0-4以上") - - -### 安装python模块 - -1. 运行如下命令,安装python模块setuptools。 - - ``` - pip3 install setuptools - ``` - -2. 安装GUI menuconfig工具(Kconfiglib),建议安装Kconfiglib 13.2.0+版本,任选如下一种方式。 - - **命令行方式:** - - ``` - sudo pip3 install kconfiglib - ``` - - - **安装包方式:** - 1. 下载.whl文件(例如:kconfiglib-13.2.0-py2.py3-none-any.whl)。 - - 下载路径:“[https://pypi.org/project/kconfiglib\#files](https://pypi.org/project/kconfiglib#files)” - - 1. 运行如下命令,安装.whl文件。 - - ``` - sudo pip3 install kconfiglib-13.2.0-py2.py3-none-any.whl - ``` - - -3. 安装pycryptodome,任选如下一种方式。 - - 安装升级文件签名依赖的Python组件包,包括:pycryptodome、six、ecdsa。安装ecdsa依赖six,请先安装six,再安装ecdsa。 - - - **命令行方式:** - - ``` - sudo pip3 install pycryptodome - ``` - - - **安装包方式:** - 1. 下载.whl文件(例如:pycryptodome-3.9.9-cp38-cp38-manylinux1\_x86\_64.whl)。 - - 下载路径:“[https://pypi.org/project/pycryptodome/\#files](https://pypi.org/project/pycryptodome/#files)”。 - - 1. 运行如下命令,安装.whl文件。 - - ``` - sudo pip3 install pycryptodome-3.9.9-cp38-cp38-manylinux1_x86_64.whl - ``` - - -4. 安装six,任选如下一种方式。 - - **命令行方式:** - - ``` - sudo pip3 install six --upgrade --ignore-installed six - ``` - - - **安装包方式:** - 1. 下载.whl文件(例如:six-1.12.0-py2.py3-none-any.whl)。 - - 下载路径:“[https://pypi.org/project/six/\#files](https://pypi.org/project/six/#files)” - - 1. 运行如下命令,安装.whl文件。 - - ``` - sudo pip3 install six-1.12.0-py2.py3-none-any.whl - ``` - - -5. 安装ecdsa,任选如下一种方式。 - - **命令行方式:** - - ``` - sudo pip3 install ecdsa - ``` - - - **安装包方式:** - 1. 下载.whl文件(例如:ecdsa-0.14.1-py2.py3-none-any.whl)。 - - 下载路径:“[https://pypi.org/project/ecdsa/\#files](https://pypi.org/project/ecdsa/#files)” - - 1. 运行如下命令,安装.whl文件。 - - ``` - sudo pip3 install ecdsa-0.14.1-py2.py3-none-any.whl - ``` - - - - -### 安装gcc\_riscv32(WLAN模组类编译工具链) - ->![](/images/device-dev/public_sys-resources/icon-notice.gif) **须知:** ->- Hi3861开发板平台仅支持使用libgcc运行时库的静态链接,不建议开发者使用libgcc运行时库的动态链接,以免产品需遵从GPLV3许可证。 ->- 通过下述步骤2-15,我们编译好了gcc\_riscv32 镜像,提供给开发者[直接下载](https://repo.huaweicloud.com/harmonyos/compiler/gcc_riscv32/7.3.0/linux/gcc_riscv32-linux-7.3.0.tar.gz)使用。直接下载 gcc\_riscv32 镜像的开发者可省略下述2-15步。 - -1. 打开Linux编译服务器终端。 -2. 环境准备,请安装"gcc, g++, bison, flex, makeinfo"软件,确保工具链能正确编译。 - - ``` - sudo apt-get install gcc && sudo apt-get install g++ && sudo apt-get install flex bison && sudo apt-get install texinfo - ``` - -3. 下载riscv-gnu-toolchain交叉编译工具链。 - - ``` - git clone --recursive https://gitee.com/mirrors/riscv-gnu-toolchain.git - ``` - -4. 打开文件夹riscv-gnu-toolchain,先删除空文件夹,以防止下载newlib,binutils,gcc时冲突。 - - ``` - cd riscv-gnu-toolchain && rm -rf riscv-newlib && rm -rf riscv-binutils && rm -rf riscv-gcc - ``` - -5. 下载riscv-newlib-3.0.0。 - - ``` - git clone -b riscv-newlib-3.0.0 https://github.com/riscv/riscv-newlib.git - ``` - -6. 下载riscv-binutils-2.31.1。 - - ``` - git clone -b riscv-binutils-2.31.1 https://github.com/riscv/riscv-binutils-gdb.git - ``` - -7. 下载riscv-gcc-7.3.0。 - - ``` - git clone -b riscv-gcc-7.3.0 https://github.com/riscv/riscv-gcc - ``` - -8. 添加riscv-gcc-7.3.0补丁。 - - 访问gcc官方补丁链接[89411](https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=026216a753ef0a757a9e368a59fa667ea422cf09;hp=2a23a1c39fb33df0277abd4486a3da64ae5e62c2),[86724](https://gcc.gnu.org/git/?p=gcc.git;a=blobdiff;f=gcc/graphite.h;h=be0a22b38942850d88feb159603bb846a8607539;hp=4e0e58c60ab83f1b8acf576e83330466775fac17;hb=b1761565882ed6a171136c2c89e597bc4dd5b6bf;hpb=fbd5f023a03f9f60c6ae36133703af5a711842a3),按照补丁链接中要求的修改,手动将变更添加到对应的.c和.h文件中,注意由于patch版本与下载的gcc版本有所偏差,行数有可能对应不上,请自行查找patch中的关键字定位到对应行。 - -9. 下载[GMP 6.1.2](https://gmplib.org/download/gmp/gmp-6.1.2.tar.bz2),并解压安装。 - - ``` - tar -xvf gmp-6.1.2.tar.bz2 && mkdir build_gmp && cd build_gmp && ../gmp-6.1.2/configure --prefix=/usr/local/gmp-6.1.2 --disable-shared --enable-cxx && make && make install - ``` - -10. 下载[mpfr-4.0.2 ](https://www.mpfr.org/mpfr-4.0.2/mpfr-4.0.2.tar.gz),并解压安装。 - - ``` - tar -xvf mpfr-4.0.2.tar.gz && mkdir build_mpfr && cd build_mpfr && ../mpfr-4.0.2/configure --prefix=/usr/local/mpfr-4.0.2 --with-gmp=/usr/local/gmp-6.1.2 --disable-shared && make && make install - ``` - -11. 下载[mpc-1.1.0](https://ftp.gnu.org/gnu/mpc/mpc-1.1.0.tar.gz) ,并解压安装。 - - ``` - tar -xvf mpc-1.1.0.tar.gz && mkdir build_mpc && cd build_mpc && ../mpc-1.1.0/configure --prefix=/usr/local/mpc-1.1.0 --with-gmp=/usr/local/gmp-6.1.2 --with-mpfr=/usr/local/mpfr-4.0.2 --disable-shared && make && make install - ``` - -12. 打开文件夹riscv-gnu-toolchain,新建工具链输出目录。 - - ``` - cd /opt && mkdir gcc_riscv32 - ``` - -13. 编译binutils。 - - ``` - mkdir build_binutils && cd build_binutils && ../riscv-binutils-gdb/configure --prefix=/opt/gcc_riscv32 --target=riscv32-unknown-elf --with-arch=rv32imc --with-abi=ilp32 --disable-__cxa_atexit --disable-libgomp --disable-libmudflap --enable-libssp --disable-libstdcxx-pch --disable-nls --disable-shared --disable-threads --disable-multilib --enable-poison-system-directories --enable-languages=c,c++ --with-gnu-as --with-gnu-ld --with-newlib --with-system-zlib CFLAGS="-fstack-protector-strong -O2 -D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now,-z,noexecstack -fPIE" CXXFLAGS="-fstack-protector-strong -O2 -D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now,-z,noexecstack -fPIE" CXXFLAGS_FOR_TARGET="-Os -mcmodel=medlow -Wall -fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -Wtrampolines -fno-short-enums -fno-short-wchar" CFLAGS_FOR_TARGET="-Os -mcmodel=medlow -Wall -fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -Wtrampolines -fno-short-enums -fno-short-wchar" --bindir=/opt/gcc_riscv32/bin --libexecdir=/opt/gcc_riscv32/riscv32 --libdir=/opt/gcc_riscv32 --includedir=/opt/gcc_riscv32 && make -j16 && make install && cd .. - ``` - -14. 编译newlib。 - - ``` - mkdir build_newlib && cd build_newlib && ../riscv-newlib/configure --prefix=/opt/gcc_riscv32 --target=riscv32-unknown-elf --with-arch=rv32imc --with-abi=ilp32 --disable-__cxa_atexit --disable-libgomp --disable-libmudflap --enable-libssp --disable-libstdcxx-pch --disable-nls --disable-shared --disable-threads --disable-multilib --enable-poison-system-directories --enable-languages=c,c++ --with-gnu-as --with-gnu-ld --with-newlib --with-system-zlib CFLAGS="-fstack-protector-strong -O2 -D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now,-z,noexecstack -fPIE" CXXFLAGS="-fstack-protector-strong -O2 -D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now,-z,noexecstack -fPIE" \CXXFLAGS_FOR_TARGET="-Os -mcmodel=medlow -Wall -fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -Wtrampolines -fno-short-enums -fno-short-wchar" CFLAGS_FOR_TARGET="-Os -mcmodel=medlow -Wall -fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -Wtrampolines -fno-short-enums -fno-short-wchar" --bindir=/opt/gcc_riscv32/bin --libexecdir=/opt/gcc_riscv32 --libdir=/opt/gcc_riscv32 --includedir=/opt/gcc_riscv32 && make -j16 && make install && cd .. - ``` - -15. 编译gcc。 - - ``` - mkdir build_gcc && cd build_gcc && ../riscv-gcc/configure --prefix=/opt/gcc_riscv32 --target=riscv32-unknown-elf --with-arch=rv32imc --with-abi=ilp32 --disable-__cxa_atexit --disable-libgomp --disable-libmudflap --enable-libssp --disable-libstdcxx-pch --disable-nls --disable-shared --disable-threads --disable-multilib --enable-poison-system-directories --enable-languages=c,c++ --with-gnu-as --with-gnu-ld --with-newlib --with-system-zlib CFLAGS="-fstack-protector-strong -O2 -D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now,-z,noexecstack -fPIE" CXXFLAGS="-fstack-protector-strong -O2 -D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now,-z,noexecstack -fPIE" LDFLAGS="-Wl,-z,relro,-z,now,-z,noexecstack" CXXFLAGS_FOR_TARGET="-Os -mcmodel=medlow -Wall -fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -Wtrampolines -fno-short-enums -fno-short-wchar" CFLAGS_FOR_TARGET="-Os -mcmodel=medlow -Wall -fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -Wtrampolines -fno-short-enums -fno-short-wchar" --with-headers="/opt/gcc-riscv32/riscv32-unknown-elf/include" --with-mpc=/usr/local/mpc-1.1.0 --with-gmp=/usr/local/gmp-6.1.2 --with-mpfr=/usr/local/mpfr-4.0.2 && make -j16 && make install - ``` - -16. 设置环境变量。 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >如果直接采用编译好的riscv32 gcc包,请先执行以下命令将压缩包解压到根目录: - >``` - >tar -xvf gcc_riscv32-linux-7.3.0.tar.gz -C ~ - >``` - - ``` - vim ~/.bashrc - ``` - - 将以下命令拷贝到.bashrc文件的最后一行,保存并退出。 - - ``` - export PATH=~/gcc_riscv32/bin:$PATH - ``` - -17. 生效环境变量。 - - ``` - source ~/.bashrc - ``` - -18. Shell命令行中输入如下命令,如果能正确显示编译器版本号,表明编译器安装成功。 - - ``` - riscv32-unknown-elf-gcc -v - ``` - - diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/01.Hi3861\345\274\200\345\217\221\346\235\277/02.\346\226\260\345\273\272\345\272\224\347\224\250\347\250\213\345\272\217.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/01.Hi3861\345\274\200\345\217\221\346\235\277/02.\346\226\260\345\273\272\345\272\224\347\224\250\347\250\213\345\272\217.md" deleted file mode 100644 index 8341d27336df116afb42baef82e48e8e3b7124b7..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/01.Hi3861\345\274\200\345\217\221\346\235\277/02.\346\226\260\345\273\272\345\272\224\347\224\250\347\250\213\345\272\217.md" +++ /dev/null @@ -1,90 +0,0 @@ ---- -title: 新建应用程序 -permalink: /pages/010201030102 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:19 ---- -# 新建应用程序 - -下方将通过修改源码的方式展示如何编写简单程序,输出“Hello world.”。请在[获取源码](/pages/0102010203)章节下载的源码目录中进行下述操作。 - -1. 确定目录结构。 - - 开发者编写业务时,务必先在./applications/sample/wifi-iot/app路径下新建一个目录(或一套目录结构),用于存放业务源码文件。 - - 例如:在app下新增业务my\_first\_app,其中hello\_world.c为业务代码,BUILD.gn为编译脚本,具体规划目录结构如下: - - ``` - . - └── applications - └── sample - └── wifi-iot - └── app - │── my_first_app - │ │── hello_world.c - │ └── BUILD.gn - └── BUILD.gn - ``` - -2. 编写业务代码。 - - 新建./applications/sample/wifi-iot/app/my\_first\_app下的hello\_world.c文件,在hello\_world.c中新建业务入口函数HelloWorld,并实现业务逻辑。并在代码最下方,使用OpenHarmony启动恢复模块接口SYS\_RUN\(\)启动业务。(SYS\_RUN定义在ohos\_init.h文件中) - - ``` - #include - #include "ohos_init.h" - #include "ohos_types.h" - - void HelloWorld(void) - { - printf("[DEMO] Hello world.\n"); - } - SYS_RUN(HelloWorld); - ``` - -3. 编写用于将业务构建成静态库的BUILD.gn文件。 - - 新建./applications/sample/wifi-iot/app/my\_first\_app下的BUILD.gn文件,并完成如下配置。 - - 如[步骤1](#li5479332115116)所述,BUILD.gn文件由三部分内容(目标、源文件、头文件路径)构成,需由开发者完成填写。 - - ``` - static_library("myapp") { - sources = [ - "hello_world.c" - ] - include_dirs = [ - "//utils/native/lite/include" - ] - } - ``` - - - static\_library中指定业务模块的编译结果,为静态库文件libmyapp.a,开发者根据实际情况完成填写。 - - sources中指定静态库.a所依赖的.c文件及其路径,若路径中包含"//"则表示绝对路径(此处为代码根路径),若不包含"//"则表示相对路径。 - - include\_dirs中指定source所需要依赖的.h文件路径。 - -4. 编写模块BUILD.gn文件,指定需参与构建的特性模块。 - - 配置./applications/sample/wifi-iot/app/BUILD.gn文件,在features字段中增加索引,使目标模块参与编译。features字段指定业务模块的路径和目标,以my\_first\_app举例,features字段配置如下。 - - ``` - import("//build/lite/config/component/lite_component.gni") - - lite_component("app") { - features = [ - "my_first_app:myapp", - ] - } - ``` - - - my\_first\_app是相对路径,指向./applications/sample/wifi-iot/app/my\_first\_app/BUILD.gn。 - - myapp是目标,指向./applications/sample/wifi-iot/app/my\_first\_app/BUILD.gn中的static\_library\("myapp"\)。 - - diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/01.Hi3861\345\274\200\345\217\221\346\235\277/03.\347\274\226\350\257\221.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/01.Hi3861\345\274\200\345\217\221\346\235\277/03.\347\274\226\350\257\221.md" deleted file mode 100644 index 00701cad7f8abce0fd006eaab9b6f7aaef869af7..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/01.Hi3861\345\274\200\345\217\221\346\235\277/03.\347\274\226\350\257\221.md" +++ /dev/null @@ -1,85 +0,0 @@ ---- -title: 编译 -permalink: /pages/010201030103 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:19 ---- -# 编译 - -- [编译(Docker方式搭建环境)](#section681942105819) -- [编译(安装包方式搭建环境)](#section17726113335715) - -本节描述如何进行Hi3861 开发板的编译,根据上方搭建Ubuntu环境方式的不同,编译方式也有所区别。 - -- 如果Ubuntu编译环境通过Docker方式安装,请参见下方[编译(Docker方式搭建环境)](#section681942105819)。 -- 如果Ubuntu编译环境通过安装包方式安装,请参见下方[编译(安装包方式搭建环境)](#section17726113335715)。 - -## 编译(Docker方式搭建环境) - -1. 请在[获取Docker环境](/pages/0102010205#section15666113905015)中进入的Docker构建环境中,执行如下命令进行编译: - - ``` - hb set(设置编译路径) - .(选择当前路径) - 选择wifiiot_hispark_pegasus@hisilicon并回车 - hb build -f(执行编译) - ``` - - **图 1** Hi3861编译设置图例-Docker方式 - ![](/images/device-dev/quick-start/figures/Hi3861编译设置图例-Docker方式.png "Hi3861编译设置图例-Docker方式") - -2. 编译结束后,出现“wifiiot\_hispark\_pegasus build success”字样,则证明构建成功。 - - >![](/images/device-dev/public_sys-resources/icon-notice.gif) **须知:** - >烧录结果文件文件获取路径:out/hispark\_pegasus/wifiiot\_hispark\_pegasus。 - - -## 编译(安装包方式搭建环境) - -1. 打开DevEco Device Tool工具,点击“View \> Terminal”,进入终端界面。 - - **图 2** IDE终端工具打开方法 - - - ![](/images/device-dev/quick-start/figures/1.png) - -2. 进入代码根路径,并在终端窗口,执行脚本命令“hb set”、“.”,选择需要编译的版本“wifiiot\_hispark\_pegasus”。 - - **图 3** 在终端界面选择目标构建版本示意图 - - - ![](/images/device-dev/quick-start/figures/3.png) - -3. 执行“hb build”启动版本构建。 - - **图 4** 在终端界面执行编译命令示意图 - - - ![](/images/device-dev/quick-start/figures/4.png) - -4. 编译结束后,如果出现“wifiiot\_hispark\_pegasus build success”字样,则证明构建成功,如下图所示。 - - **图 5** 编译成功示意图 - - - ![](/images/device-dev/quick-start/figures/5.png) - -5. 构建成功后,会在./out/wifiiot/路径中生成以下文件,使用如下命令可以查看,至此编译构建流程结束。 - - ``` - ls -l out/hispark_pegasus/wifiiot_hispark_pegasus/ - ``` - - **图 6** 编译文件存放目录示意图 - - - ![](/images/device-dev/quick-start/figures/3-0.png) - - diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/01.Hi3861\345\274\200\345\217\221\346\235\277/04.\347\203\247\345\275\225.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/01.Hi3861\345\274\200\345\217\221\346\235\277/04.\347\203\247\345\275\225.md" deleted file mode 100644 index 722fccdf32840c7fbbe1f789d4c34a2a83ce32f0..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/01.Hi3861\345\274\200\345\217\221\346\235\277/04.\347\203\247\345\275\225.md" +++ /dev/null @@ -1,93 +0,0 @@ ---- -title: 烧录 -permalink: /pages/010201030104 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:19 ---- -# 烧录 - -- [前提条件](#section1535374111495) -- [使用串口烧录](#section5551201122719) - -烧录是指将编译后的程序文件下载到芯片开发板上的动作,为后续的程序调试提供基础。DevEco Device Tool提供一键烧录功能,操作简单,能快捷、高效的完成程序烧录,提升烧录的效率。 - -DevEco Device Tool以插件方式运行,基于Visual Studio Code进行扩展,用户可点击Visual Studio Code左侧栏的![](/images/device-dev/quick-start/figures/2021-01-27_170334.png)图标打开DevEco Device Tool。 - -**Hi3861V100开发板支持串口烧录方式,Linux系统串口烧录协议为hiburn-serial。**具体操作步骤如下: - -## 前提条件 - -1. 在DevEco Device Tool工具中点击**Import Project**导入新建应用程序章节修改后的源码文件。 - - ![](/images/device-dev/quick-start/figures/import-project.png) - -2. 选择源码导入时,系统会提示该工程不是DevEco Device Tool工程,点击**Import**。 - - ![](/images/device-dev/quick-start/figures/import-project-confirm.png) - -3. MCU选择Hi3861,Board选择Hi3861,Framework选择Hb,然后点击**Import**完成导入。 - - ![](/images/device-dev/quick-start/figures/hi3861-import-projects.png) - - -## 使用串口烧录 - -1. 请连接好电脑和待烧录开发板,需要连接USB口,具体可参考[Hi3861V100开发板介绍](https://device.harmonyos.com/cn/docs/documentation/guide/quickstart-lite-introduction-hi3861-0000001105041324)[Hi3861V100开发板介绍](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/quickstart-lite-introduction-hi3861.md)。 -2. 查看并记录对应的串口号。 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >如果对应的串口异常,请根据[Hi3861V100开发板串口驱动安装](https://device.harmonyos.com/cn/docs/documentation/guide/hi3861-drivers-0000001058153433)安装USB转串口的驱动程序。 - - Window系统,打开设备管理器查看并记录对应的串口号,或在DevEco Device Tool中,点击QUICK ACCESS \> DevEco Home \> Device,查看并记录对应的串口号。 - - ![](/images/device-dev/quick-start/figures/hi3861-record-the-serial-port-number.png) - - Linux系统,在DevEco Device Tool中,点击QUICK ACCESS \> DevEco Home \> Device,查看并记录对应的串口号。 - - ![](/images/device-dev/quick-start/figures/Snap23.png) - -3. 在QUICK ACCESS \> DevEco Home \> Projects中,点击**Settings**打开工程配置界面。 - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001222999125.png) - -4. 在“hi3861”页签,设置烧录选项,包括upload\_port、upload\_protocol和upload\_partitions。 - - - upload\_port:选择已查询的串口号。 - - upload\_protocol:选择烧录协议,选择“hiburn-serial”。 - - upload\_partitions:选择待烧录的文件,默认选择hi3861\_app。 - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001177798424.png) - -5. 检查待烧录文件的烧录信息,DevEco Device Tool已预置默认的烧录文件信息,可根据实际情况进行调整。 - 1. 在“hi3861\_app”页签,在New Option选项中选择需要修改的项,例如partition\_bin(烧录文件路径)、partition\_addr(烧录文件起始地址)、partition\_length(烧录文件分区长度)等。 - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001177480146.png) - - 2. 然后在Partition Options中,分别修改上述步骤中选择的修改项。 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >在设置烧录分区起始地址和分区长度时,应根据实际待烧录文件的大小进行设置,要求设置的烧录分区大小,要大于待烧录文件的大小。 - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001223000051.png) - -6. 所有的配置都修改完成后,在工程配置页签的顶部,点击**Save**进行保存。 -7. 点击**Open**打开工程文件,然后在“PROJECT TASKS”中,点击hi3861下的**Upload**按钮,启动烧录。 - - ![](/images/device-dev/quick-start/figures/hi3861-upload.png) - -8. 启动烧录后,显示如下提示信息时,请按开发板上的RST按钮重启开发板。 - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001174595590.png) - -9. 重新上电后,界面提示如下信息时,表示烧录成功。 - - ![](/images/device-dev/quick-start/figures/hi3861-burning-succeeded.png) - - diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/01.Hi3861\345\274\200\345\217\221\346\235\277/05.\350\260\203\350\257\225\351\252\214\350\257\201.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/01.Hi3861\345\274\200\345\217\221\346\235\277/05.\350\260\203\350\257\225\351\252\214\350\257\201.md" deleted file mode 100644 index 059759bb52e3bdf53564309cca09e33ca9ada559..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/01.Hi3861\345\274\200\345\217\221\346\235\277/05.\350\260\203\350\257\225\351\252\214\350\257\201.md" +++ /dev/null @@ -1,74 +0,0 @@ ---- -title: 调试验证 -permalink: /pages/010201030105 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:19 ---- -# 调试验证 - -- [printf打印](#section42891145143811) -- [根据asm文件进行问题定位](#section754719373917) - -完成烧录之后,用户可根据需要进行调试验证。目前调试验证的方法有以下两种,开发者可以根据具体业务情况选择。 - -1. 通过printf打印日志 -2. 通过asm文件定位panic问题 - -由于本示例业务简单,采用printf打印日志的调试方式即可。下方将介绍这两种调试手段的使用方法。 - -## printf打印 - -代码中增加printf维测,信息会直接打印到串口上。开发者可在业务关键路径或业务异常位置增加日志打印,如下所示: - -``` -void HelloWorld(void) -{ - printf("[DEMO] Hello world.\n"); -} -``` - -## 根据asm文件进行问题定位 - -系统异常退出时,会在串口上打印异常退出原因调用栈信息,如下文所示。通过解析异常栈信息可以定位异常位置。 - -``` -=======KERNEL PANIC======= -**********************Call Stack********************* -Call Stack 0 -- 4860d8 addr:f784c -Call Stack 1 -- 47b2b2 addr:f788c -Call Stack 2 -- 3e562c addr:f789c -Call Stack 3 -- 4101de addr:f78ac -Call Stack 4 -- 3e5f32 addr:f78cc -Call Stack 5 -- 3f78c0 addr:f78ec -Call Stack 6 -- 3f5e24 addr:f78fc -********************Call Stack end******************* -``` - -为解析上述调用栈信息,需要使用到Hi3861\_wifiiot\_app.asm文件,该文件记录了代码中函数在Flash上的符号地址以及反汇编信息。asm文件会随版本打包一同构建输出,存放在./out/wifiiot/路径下。 - -1. 将调用栈CallStack信息保存到txt文档中,以便于编辑。(可选) -2. 打开asm文件,并搜索CallStack中的地址,列出对应的函数名 信息。通常只需找出前几个栈信息对应的函数,就可明确异常代码方向。 - - ``` - Call Stack 0 -- 4860d8 addr:f784c -- WadRecvCB - Call Stack 1 -- 47b2b2 addr:f788c -- wal_sdp_process_rx_data - Call Stack 2 -- 3e562c addr:f789c - Call Stack 3 -- 4101de addr:f78ac - Call Stack 4 -- 3e5f32 addr:f78cc - Call Stack 5 -- 3f78c0 addr:f78ec - Call Stack 6 -- 3f5e24 addr:f78fc - ``` - -3. 根据以上调用栈信息,可以定位WadRecvCB函数中出现了异常。 - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001185334336.png) - -4. 完成代码排查及修改。 - diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/01.Hi3861\345\274\200\345\217\221\346\235\277/06.\350\277\220\350\241\214.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/01.Hi3861\345\274\200\345\217\221\346\235\277/06.\350\277\220\350\241\214.md" deleted file mode 100644 index 7cc77a344b62bbae5e1f1a0877c90812f0b2622b..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/01.Hi3861\345\274\200\345\217\221\346\235\277/06.\350\277\220\350\241\214.md" +++ /dev/null @@ -1,33 +0,0 @@ ---- -title: 运行 -permalink: /pages/010201030106 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:19 ---- -# 运行 - -- [运行结果](#section18115713118) -- [下一步学习](#section9712145420182) - -## 运行结果 - -示例代码编译、烧录、运行、调测后,重启开发板后将自动在界面输出如下结果: - -``` -ready to OS start -FileSystem mount ok. -wifi init success! -[DEMO] Hello world. -``` - -## 下一步学习 - -恭喜,您已完成Hi3861开发板快速上手!建议您下一步进入[WLAN产品开发](/pages/0107010101)的学习 。 - diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/01.Hi3861\345\274\200\345\217\221\346\235\277/07.\345\270\270\350\247\201\351\227\256\351\242\230.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/01.Hi3861\345\274\200\345\217\221\346\235\277/07.\345\270\270\350\247\201\351\227\256\351\242\230.md" deleted file mode 100644 index bffd46e015f11628e381d143cad2c19bc2796595..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/01.Hi3861\345\274\200\345\217\221\346\235\277/07.\345\270\270\350\247\201\351\227\256\351\242\230.md" +++ /dev/null @@ -1,328 +0,0 @@ ---- -title: 常见问题 -permalink: /pages/010201030107 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:19 ---- -# 常见问题 - -- [编译构建过程中,提示“No module named 'Crypto'”](#section982315398121) -- [编译构建过程中,提示“No module named 'ecdsa'”](#section102035451216) -- [编译构建过程中,提示“Could not find a version that satisfies the requirement six\>=1.9.0”](#section4498158162320) -- [编译构建过程中,提示找不到“-lgcc”](#section11181036112615) -- [编译构建过程中,提示找不到“python”](#section1571810194619) -- [编译构建过程中,提示找不到“python3”](#section108385316482) -- [安装python3过程中,提示“configure: error: no acceptable C compiler found in $PATH”](#section1221016541119) -- [安装python3过程中,提示“-bash: make: command not found”](#section1913477181213) -- [安装python3过程中,提示“zlib not available”](#section108211415131210) -- [安装python3过程中,提示“No module named '\_ctypes'”](#section2062268124) -- [安装 kconfiglib时,遇到lsb\_release错误](#section691681635814) - -## 编译构建过程中,提示“No module named 'Crypto'” - -- **现象描述** - - 编译构建过程中出现以下错误: - - ``` - ModuleNotFoundError: No module named 'Crypto' - ``` - - -- **可能原因** - - 环境中未安装“Crypto”。 - - -- **解决办法** - - 方法1:通过命令“pip3 install Crypto”,在线安装。 - - 方法2:离线安装。 - - 通过网页[https://pypi.org/project/pycrypto/\#files](https://pypi.org/project/pycrypto/#files),下载源码。 - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001171615542.png) - - 将源码放置在Linux服务器中,解压,并安装“python3 setup.py install”。 - - 完成上述安装后,重新构建。 - - -## 编译构建过程中,提示“No module named 'ecdsa'” - -- **现象描述** - - 编译构建过程中出现以下错误: - - ``` - ModuleNotFoundError:No module named 'ecdsa' - ``` - - -- **可能原因** - - 环境中未安装“ecdsa”。 - - -- **解决办法** - - 方法1:通过命令“pip3 install ecdsa”,在线安装。 - - 方法2:离线安装 - - 通过网页[https://pypi.org/project/ecdsa/\#files](https://pypi.org/project/ecdsa/#files),下载安装包。 - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001171455574.png) - - 将安装包放置Linux服务器中,并安装“pip3 install ecdsa-0.15-py2.py3-none-any.whl”。 - - 完成上述安装后,重新构建。 - - -## 编译构建过程中,提示“Could not find a version that satisfies the requirement six\>=1.9.0” - -- **现象描述** - - 编译构建过程中出现以下错误: - - ``` - Could not find a version that satisfies the requirement six>=1.9.0 - ``` - - -- **可能原因** - - 环境中未安装合适的“six”。 - - -- **解决办法** - - 方法1:通过命令“pip3 install six”,在线安装。 - - 方法2:离线安装。 - - 通过网页[https://pypi.org/project/six/\#files](https://pypi.org/project/six/#files),下载安装包。 - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001217013871.png) - - 将源码放置在Linux服务器中,并安装“pip3 install six-1.14.0-py2.py3-none-any.whl”。 - - 完成上述安装后,重新构建。 - - -## 编译构建过程中,提示找不到“-lgcc” - -- **现象描述** - - 编译构建过程中出现以下错误: - - ``` - riscv32-unknown-elf-ld: cannot find -lgcc - ``` - - -- **可能原因** - - 交叉编译器gcc\_riscv32的PATH添加错误,如下,在"bin"后多添加了一个“/”,应该删除。 - - ``` - ~/gcc_riscv32/bin/:/data/toolchain/ - ``` - - -- **解决办法** - - 重新修改gcc\_riscv32的PATH,将多余的“/”删除。 - - ``` - ~/gcc_riscv32/bin:/data/toolchain/ - ``` - - -## 编译构建过程中,提示找不到“python” - -- **现象描述** - - 编译构建过程中出现以下错误: - - ``` - -bash: /usr/bin/python: No such file or directory - ``` - - -- **可能原因**1 - - 没有装python。 - -- **解决办法** - - 请使用如下命令安装Python,下方以Python3.8为例。 - - ``` - sudo apt-get install python3.8 - ``` - -- **可能原因2** - - usr/bin目录下没有python软链接 - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001171774098.png) - -- **解决办法** - - 请运行以下命令添加软链接: - - ``` - # cd /usr/bin/ - # which python3 - # ln -s /usr/local/bin/python3 python - # python --version - ``` - - 例: - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001171934032.png) - - -## 编译构建过程中,提示找不到“python3” - -- **现象描述** - - ![](/images/device-dev/quick-start/figures/11.png) - - -- **可能原因** - - 没有装python3。 - -- **解决办法** - - 请使用如下命令安装Python3。 - - ``` - sudo apt-get install python3.8 - ``` - - -## 安装python3过程中,提示“configure: error: no acceptable C compiler found in $PATH” - -- **现象描述** - - 安装python3过程中出现以下错误: - - ``` - configure: error: no acceptable C compiler found in $PATH. See 'config.log' for more details - ``` - -- **可能原因** - - 环境中未安装“gcc”。 - -- **解决办法** - 1. 通过命令“apt-get install gcc”在线安装。 - 2. 完成后,重新安装python3。 - - -## 安装python3过程中,提示“-bash: make: command not found” - -- **现象描述** - - 安装python3过程中出现以下错误: - - ``` - -bash: make: command not found - ``` - -- **可能原因** - - 环境中未安装“make”。 - -- **解决办法** - 1. 通过命令“apt-get install make”在线安装。 - 2. 完成后,重新安装python3。 - - -## 安装python3过程中,提示“zlib not available” - -- **现象描述** - - 安装python3过程中出现以下错误: - - ``` - zipimport.ZipImportError: can't decompress data; zlib not avaliable - ``` - -- **可能原因** - - 环境中未安装“zlib”。 - -- **解决办法** - - 方法1:通过命令“apt-get install zlib”在线安装。 - - 方法2:如果软件源中没有该软件,请从“www.zlib.net”下载版本代码,并离线安装。 - - ![](/images/device-dev/quick-start/figures/10.png) - - 完成下载后,通过以下命令安装: - - ``` - # tar xvf zlib-1.2.11.tar.gz - # cd zlib-1.2.11 - # ./configure - # make && make install - ``` - - 完成后,重新安装python3。 - - -## 安装python3过程中,提示“No module named '\_ctypes'” - -- **现象描述** - - 安装python3过程中出现以下错误: - - ``` - ModuleNotFoundError:No module named ‘_ctypes’ - ``` - - -- **可能原因** - - 环境中未安装“libffi”和“libffi-devel”。 - - -- **解决办法** - - 1、通过命令“apt-get install libffi\* -y”,在线安装。 - - 2、完成后,重新安装python3。 - - -## 安装 kconfiglib时,遇到lsb\_release错误 - -- **现象描述** - - 安装kconfiglib过程中遇到如下错误打印: - - ``` - subprocess.CalledProcessError: Command '('lsb_release', '-a')' returned non-zero exit status 1. - ``` - -- **可能原因** - - lsb\_release模块基于的python版本与现有python版本不一致。 - -- **解决办法** - - 执行"find / -name lsb\_release",找到lsb\_release位置并删除,如:"sudo rm -rf /usr/bin/lsb\_release"。 - - diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/02.Hi3516\345\274\200\345\217\221\346\235\277/01.\345\256\211\350\243\205\345\274\200\345\217\221\346\235\277\347\216\257\345\242\203.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/02.Hi3516\345\274\200\345\217\221\346\235\277/01.\345\256\211\350\243\205\345\274\200\345\217\221\346\235\277\347\216\257\345\242\203.md" deleted file mode 100644 index 61753bffe3453ee1d9b26837f9efa95c901b36cc..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/02.Hi3516\345\274\200\345\217\221\346\235\277/01.\345\256\211\350\243\205\345\274\200\345\217\221\346\235\277\347\216\257\345\242\203.md" +++ /dev/null @@ -1,83 +0,0 @@ ---- -title: 安装开发板环境 -permalink: /pages/010201030201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:19 ---- -# 安装开发板环境 - -- [Hi3516工具要求](#section179175261196) - - [硬件要求](#section5840424125014) - - [软件要求](#section965634210501) - -- [安装Linux服务器工具](#section182916865219) - - [安装编译依赖基础软件(仅Ubuntu 20+需要)](#section45512412251) - - [安装文件打包工具及Java虚拟机环境](#section16199102083717) - - -## Hi3516工具要求 - -### 硬件要求 - -- Hi3516DV300 IoT Camera开发板 -- USB转串口线、网线(Linux工作台通过USB转串口线、网线与Hi3516DV300 开发板连接) - -### 软件要求 - ->![](/images/device-dev/public_sys-resources/icon-notice.gif) **须知:** ->本节描述安装包方式搭建编译环境的操作步骤。如果使用Docker方式安装编译环境,请跳过此章节,直接从[新建应用程序](/pages/010201030202)开始操作。 - -Hi3516开发板对Linux服务器通用环境配置需要的工具及其用途如下表所示。 - -**表 1** Linux服务器开发工具及用途 - - - - - - - - - - - - - - - - -

开发工具

-

用途

-

编译基础软件包(仅ubuntu 20+需要)

-

编译依赖的基础软件包

-

dosfstools、mtools、mtd-utils

-

文件打包工具

-

Java 虚拟机环境

-

编译、调试和运行Java程序

-
- -## 安装Linux服务器工具 - -### 安装编译依赖基础软件(仅Ubuntu 20+需要) - -执行以下命令进行安装: - -``` -sudo apt-get install build-essential gcc g++ make zlib* libffi-dev -``` - -### 安装文件打包工具及Java虚拟机环境 - -运行如下命令,安装dosfstools、mtools、mtd-utils、Java运行时环境(JRE)和Java sdk 开发工具包。 - -``` -sudo apt-get install dosfstools mtools mtd-utils default-jre default-jdk -``` - diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/02.Hi3516\345\274\200\345\217\221\346\235\277/02.\346\226\260\345\273\272\345\272\224\347\224\250\347\250\213\345\272\217.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/02.Hi3516\345\274\200\345\217\221\346\235\277/02.\346\226\260\345\273\272\345\272\224\347\224\250\347\250\213\345\272\217.md" deleted file mode 100644 index b5a981b4227a05c26d49ef3533c3dd7f30ede5eb..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/02.Hi3516\345\274\200\345\217\221\346\235\277/02.\346\226\260\345\273\272\345\272\224\347\224\250\347\250\213\345\272\217.md" +++ /dev/null @@ -1,134 +0,0 @@ ---- -title: 新建应用程序 -permalink: /pages/010201030202 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:19 ---- -# 新建应用程序 - -下方将通过修改源码的方式展示如何编写简单程序,输出“Hello OHOS!”。请在[获取源码](/pages/0102010203)章节下载的源码目录中进行下述操作。 - -1. 新建目录及源码。 - - 新建**applications/sample/camera/apps/src/helloworld.c**目录及文件,代码如下所示,用户可以自定义修改打印内容(例如:修改OHOS为World)。当前应用程序可支持标准C及C++的代码开发。 - - ``` - #include - - int main(int argc, char **argv) - { - printf("\n************************************************\n"); - printf("\n\t\tHello OHOS!\n"); - printf("\n************************************************\n\n"); - - return 0; - } - ``` - -2. 新建编译组织文件。 - - 新建**applications/sample/camera/apps/BUILD.gn**文件,内容如下所示: - - ``` - import("//build/lite/config/component/lite_component.gni") - lite_component("hello-OHOS") { - features = [ ":helloworld" ] - } - executable("helloworld") { - output_name = "helloworld" - sources = [ "src/helloworld.c" ] - include_dirs = [] - defines = [] - cflags_c = [] - ldflags = [] - } - ``` - -3. 添加新组件。 - - 修改文件**build/lite/components/applications.json**,添加组件hello\_world\_app的配置,如下所示为applications.json文件片段,"\#\#start\#\#"和"\#\#end\#\#"之间为新增配置("\#\#start\#\#"和"\#\#end\#\#"仅用来标识位置,添加完配置后删除这两行): - - ``` - { - "components": [ - { - "component": "camera_sample_communication", - "description": "Communication related samples.", - "optional": "true", - "dirs": [ - "applications/sample/camera/communication" - ], - "targets": [ - "//applications/sample/camera/communication:sample" - ], - "rom": "", - "ram": "", - "output": [], - "adapted_kernel": [ "liteos_a" ], - "features": [], - "deps": { - "components": [], - "third_party": [] - } - }, - ##start## - { - "component": "hello_world_app", - "description": "Communication related samples.", - "optional": "true", - "dirs": [ - "applications/sample/camera/apps" - ], - "targets": [ - "//applications/sample/camera/apps:hello-OHOS" - ], - "rom": "", - "ram": "", - "output": [], - "adapted_kernel": [ "liteos_a" ], - "features": [], - "deps": { - "components": [], - "third_party": [] - } - }, - ##end## - { - "component": "camera_sample_app", - "description": "Camera related samples.", - "optional": "true", - "dirs": [ - "applications/sample/camera/launcher", - "applications/sample/camera/cameraApp", - "applications/sample/camera/setting", - "applications/sample/camera/gallery", - "applications/sample/camera/media" - ], - ``` - -4. 修改单板配置文件。 - - 修改文件**vendor/hisilicon/hispark\_taurus/config.json**,新增hello\_world\_app组件的条目,如下所示代码片段为applications子系统配置,"\#\#start\#\#"和"\#\#end\#\#"之间为新增条目("\#\#start\#\#"和"\#\#end\#\#"仅用来标识位置,添加完配置后删除这两行): - - ``` - { - "subsystem": "applications", - "components": [ - { "component": "camera_sample_app", "features":[] }, - { "component": "camera_sample_ai", "features":[] }, - ##start## - { "component": "hello_world_app", "features":[] }, - ##end## - { "component": "camera_screensaver_app", "features":[] } - ] - }, - ``` - - diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/02.Hi3516\345\274\200\345\217\221\346\235\277/03.\347\274\226\350\257\221.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/02.Hi3516\345\274\200\345\217\221\346\235\277/03.\347\274\226\350\257\221.md" deleted file mode 100644 index f9e98ac796153c88ae64b54a1c5d6818cc05e8c4..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/02.Hi3516\345\274\200\345\217\221\346\235\277/03.\347\274\226\350\257\221.md" +++ /dev/null @@ -1,40 +0,0 @@ ---- -title: 编译 -permalink: /pages/010201030203 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:19 ---- -# 编译 - -下方将介绍如何使用Hi3516开发板进行编译。使用安装包方式与docker方式搭建Ubuntu编译环境,编译步骤相同。 - -1. 请进入源码根目录,执行如下命令进行编译: - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >如果使用Docker方式搭建编译环境,请在[获取Docker环境](/pages/0102010205#section15666113905015)中进入的Docker构建环境中,执行如下命令进行编译。 - - ``` - hb set(设置编译路径) - .(选择当前路径) - 选择ipcamera_hispark_taurus并回车 - hb build -f(执行编译) - ``` - - **图 1** Hi3516编译设置图例-Docker方式 - ![](/images/device-dev/quick-start/figures/Hi3516编译设置图例-Docker方式.png "Hi3516编译设置图例-Docker方式") - -2. 编译结束后,出现“ipcamera\_hispark\_taurus build success”字样,则证明构建成功。 - - >![](/images/device-dev/public_sys-resources/icon-notice.gif) **须知:** - >烧录相关文件获取路径: - >结果文件:out/hispark\_taurus/ipcamera\_hispark\_taurus。 - >U-boot文件:device/hisilicon/hispark\_taurus/sdk\_liteos/uboot/out/boot/u-boot-hi3516dv300.bin。 - - diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/02.Hi3516\345\274\200\345\217\221\346\235\277/04.\347\203\247\345\275\225.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/02.Hi3516\345\274\200\345\217\221\346\235\277/04.\347\203\247\345\275\225.md" deleted file mode 100644 index 3ef91162a441e66a0743c124697546ff89cc5437..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/02.Hi3516\345\274\200\345\217\221\346\235\277/04.\347\203\247\345\275\225.md" +++ /dev/null @@ -1,106 +0,0 @@ ---- -title: 烧录 -permalink: /pages/010201030204 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:19 ---- -# 烧录 - -- [前提条件](#section762111572589) -- [使用网口烧录](#section12323175612487) - -烧录是指将编译后的程序文件下载到芯片开发板上的动作,为后续的程序调试提供基础。DevEco Device Tool提供一键烧录功能,操作简单,能快捷、高效的完成程序烧录,提升烧录的效率。 - -DevEco Device Tool以插件方式运行,基于Visual Studio Code进行扩展,用户可点击Visual Studio Code左侧栏的![](/images/device-dev/quick-start/figures/2021-01-27_170334.png)图标打开DevEco Device Tool。 - -Hi3516开发板的代码烧录支持USB烧录、网口烧录和串口烧录三种方式。此处仅以网口烧录为例进行说明,其它方式请参考[Hi3516DV300开发板烧录](https://device.harmonyos.com/cn/docs/documentation/guide/ide-hi3516-upload-0000001052148681#section1760842019292)。 - -## 前提条件 - -1. 在DevEco Device Tool工具中点击**Import Project**导入新建应用程序章节修改后的源码文件。 - - ![](/images/device-dev/quick-start/figures/import-project.png) - -2. 选择源码导入时,系统会提示该工程不是DevEco Device Tool工程,点击**Import**。 - - ![](/images/device-dev/quick-start/figures/import-project-confirm.png) - -3. MCU选择HiSilicom\_Arm下的Hi3516DV300,Board选择hi3516dv300,Framework选择Hb,然后点击**Import**完成导入。 - - ![](/images/device-dev/quick-start/figures/hi3516-import-projects.png) - - -## 使用网口烧录 - -1. 请连接好电脑和待烧录开发板,需要同时连接串口、网口和电源,具体可参考[Hi3516DV300开发板介绍](https://device.harmonyos.com/cn/docs/documentation/guide/quickstart-lite-introduction-hi3516-0000001152041033)。 -2. 查看并记录对应的串口号。 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >如果对应的串口异常,请根据[Hi3516DV300/Hi3518EV300开发板串口驱动安装指导](https://device.harmonyos.com/cn/docs/documentation/guide/hi3516_hi3518-drivers-0000001050743695)安装USB转串口的驱动程序。 - - Windows系统,打开设备管理器查看并记录对应的串口号,或在DevEco Device Tool中,点击QUICK ACCESS \> DevEco Home \> Device,查看并记录对应的串口号。 - - ![](/images/device-dev/quick-start/figures/record-the-serial-port-number.png) - - Linux系统,在DevEco Device Tool中,点击QUICK ACCESS \> DevEco Home \> Device,查看并记录对应的串口号。 - - ![](/images/device-dev/quick-start/figures/Snap22.png) - -3. 在QUICK ACCESS \> DevEco Home \> Projects中,点击**Settings**打开工程配置界面。 - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001222969587.png) - -4. 在“hi3516dv300”页签,设置烧录选项,包括upload\_partitions、upload\_port和upload\_protocol。 - - - upload\_partitions:选择待烧录的文件,默认情况下会同时烧录fastboot、kernel、rootfs和userfs。 - - upload\_port:选择已查询的串口号。 - - upload\_protocol:选择烧录协议,固定选择“hiburn-net”。 - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001177474882.png) - -5. 检查和设置连接开发板后的网络适配器的IP地址信息,设置方法请参考[设置Hi3516DV300网口烧录的IP地址信息](https://device.harmonyos.com/cn/docs/documentation/guide/set_ipaddress-0000001141825075)。 -6. 设置网口烧录的IP地址信息,设置如下选项: - - - upload\_net\_server\_ip:选择步骤6中设置的IP地址信息。例如192.168.1.2 - - upload\_net\_client\_mask:设置开发板的子网掩码,工具会自动根据选择的upload\_net\_server\_ip进行设置。例如255.255.255.0 - - upload\_net\_client\_gw:设置开发板的网关,工具会自动根据选择的upload\_net\_server\_ip进行设置。例如192.168.1.1 - - upload\_net\_client\_ip:设置开发板的IP地址,工具会自动根据选择的upload\_net\_server\_ip进行设置。例如192.168.1.3 - - ![](/images/device-dev/quick-start/figures/ip-address-information.png) - -7. 分别检查待烧录文件的烧录信息,DevEco Device Tool已预置默认的烧录文件信息,可根据实际情况进行调整。待烧录文件包括:fastboot、kernel、rootfs和userfs。 - 1. 在“hi3516dv300\_fastboot”页签,在New Option选项中选择需要修改的项,例如partition\_bin(烧录文件路径)、partition\_addr(烧录文件起始地址)、partition\_length(烧录文件分区长度)等。 - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001222994321.png) - - 2. 然后在Partition Options中,分别修改上述步骤中选择的修改项。 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >在设置烧录分区起始地址和分区长度时,应根据实际待烧录文件的大小进行设置,要求设置的烧录分区大小,要大于待烧录文件的大小;同时,各烧录文件的分区地址设置不能出现重叠。 - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001223185957.png) - - 3. 按照相同的方法修改kernel、rootfs和userfs的烧录文件信息。 - -8. 所有的配置都修改完成后,在工程配置页签的顶部,点击**Save**进行保存。 -9. 点击**Open**打开工程文件,然后在“PROJECT TASKS”中,点击hi3516dv300下的**Upload**按钮,启动烧录。 - - ![](/images/device-dev/quick-start/figures/hi3516-upload-start-burning.png) - -10. 启动烧录后,显示如下提示信息时,请重启开发板(下电再上电)。 - - ![](/images/device-dev/quick-start/figures/hi3516-restart-the-development-board.png) - -11. 重新上电后,界面提示如下信息时,表示烧录成功。 - - ![](/images/device-dev/quick-start/figures/hi3516-burning-succeeded-net.png) - -12. 烧录成功后,请根据镜像运行章节进行操作,启动系统。 - diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/02.Hi3516\345\274\200\345\217\221\346\235\277/05.\350\277\220\350\241\214.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/02.Hi3516\345\274\200\345\217\221\346\235\277/05.\350\277\220\350\241\214.md" deleted file mode 100644 index b4f089396db36d4ff1147baeab6624b01cb0dc30..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/02.Hi3516\345\274\200\345\217\221\346\235\277/05.\350\277\220\350\241\214.md" +++ /dev/null @@ -1,46 +0,0 @@ ---- -title: 运行 -permalink: /pages/010201030205 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:19 ---- -# 运行 - -- [镜像运行](#section11324753143912) -- [下一步学习](#section9712145420182) - -## 镜像运行 - -在完成Hi3516DV300的烧录后,还需要设置BootLoader引导程序,才能运行OpenHarmony系统。 - -1. 在Hi3516DV300任务中,点击**Configure bootloader(Boot OS)**进行配置即可。 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >DevEco Device Tool针对Hi3516DV300开发板的BootLoader设置进行了适配,无需开发者手动修改。 - - ![](/images/device-dev/quick-start/figures/bootloader.png) - -2. 提示如下图中的重启开发板的提示信息时,重启开发板,然后在控制台输出“SUCCESS”表示设置成功。 - - ![](/images/device-dev/quick-start/figures/reset_success.png) - -3. 在任务栏点击**Monitor**按钮,启动串口工具。 - - ![](/images/device-dev/quick-start/figures/monitor.png) - -4. 当界面打印回显信息,点击Enter按钮,直到界面显示OHOS \#信息,表示系统启动成功。 - - ![](/images/device-dev/quick-start/figures/reboot_success.png) - - -## 下一步学习 - -恭喜您,已完成Hi3516的快速上手!建议您下一步进入[带屏摄像头产品开发](/pages/extra/3b686a/)的学习 。 - diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/02.Hi3516\345\274\200\345\217\221\346\235\277/06.\345\270\270\350\247\201\351\227\256\351\242\230.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/02.Hi3516\345\274\200\345\217\221\346\235\277/06.\345\270\270\350\247\201\351\227\256\351\242\230.md" deleted file mode 100644 index bf93734e8aa018c2cfe99e880d5993df534b8179..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/02.Hi3516\345\274\200\345\217\221\346\235\277/06.\345\270\270\350\247\201\351\227\256\351\242\230.md" +++ /dev/null @@ -1,194 +0,0 @@ ---- -title: 常见问题 -permalink: /pages/010201030206 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:20 ---- -# 常见问题 - -- [烧写选择串口后提示“Error: Opening COMxx: Access denied”](#section627268185113) -- [Windows电脑与单板网络连接失败](#section195391036568) -- [烧写失败](#section571164016565) -- [编译构建过程中,提示找不到“python”](#section1039835245619) -- [串口无回显](#section14871149155911) - -## 烧写选择串口后提示“Error: Opening COMxx: Access denied” - -- **现象描述** - - 点击烧写并选择串口后,出现Error: Opening COMxx: Access denied。 - - **图 1** 打开串口失败图 - ![](/images/device-dev/quick-start/figures/打开串口失败图.png "打开串口失败图") - -- **可能原因** - - 串口已经被占用。 - -- **解决办法** - -1. 按图依次选择下拉框,查找带有serial-xx的终端。 - - **图 2** 查找是否存在占用串口的终端 - ![](/images/device-dev/quick-start/figures/查找是否存在占用串口的终端.png "查找是否存在占用串口的终端") - -2. 点击标号中的垃圾桶图标,关闭串口。 - - **图 3** 关闭串口终端 - ![](/images/device-dev/quick-start/figures/关闭串口终端.png "关闭串口终端") - -3. 重新点击烧写,选择串口并开始烧写程序。 - - **图 4** 重新启动烧写任务 - - - ![](/images/device-dev/quick-start/figures/changjian1.png) - - -## Windows电脑与单板网络连接失败 - -- **现象描述** - - 点击烧写并选择串口后,无法获取文件。 - - **图 5** 网络不通,单板无法获取文件图 - ![](/images/device-dev/quick-start/figures/网络不通-单板无法获取文件图.png "网络不通-单板无法获取文件图") - -- **可能原因** - - 单板网络与Windows电脑不联通。 - - Windows电脑防火墙未允许Visual Studio Code联网。 - -- **解决方法** - -1. 检查网线是否连接。 -2. 点击Windows防火墙。 - - **图 6** 网络防火墙设置图 - ![](/images/device-dev/quick-start/figures/网络防火墙设置图.png "网络防火墙设置图") - -3. 点击“允许应用通过防火墙”。 - - **图 7** 防火墙和网络保护界面图 - ![](/images/device-dev/quick-start/figures/防火墙和网络保护界面图.png "防火墙和网络保护界面图") - -4. 查找Visual Studio Code应用。 - - **图 8** 查找Visual Studio Code应用图 - ![](/images/device-dev/quick-start/figures/查找Visual-Studio-Code应用图.png "查找Visual-Studio-Code应用图") - -5. 勾选Visual Studio Code的专用和公用网络的访问权限。 - - **图 9** 允许Visual Studio Code应用访问网络 - ![](/images/device-dev/quick-start/figures/允许Visual-Studio-Code应用访问网络.png "允许Visual-Studio-Code应用访问网络") - - -## 烧写失败 - -- **现象描述** - - 点击烧写并选择串口后,出现无法烧写的情况。 - -- **可能原因** - - 安装IDE插件DevEco后未重启。 - -- **解决方法** - - 重启IDE。 - - -## 编译构建过程中,提示找不到“python” - -- **现象描述** - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001216693913.png) - -- **可能原因**1 - - 没有装python。 - -- **解决办法**1 - - 请使用如下命令安装Python,下方以Python3.8为例。 - - ``` - sudo apt-get install python3.8 - ``` - - -- **可能原因**2 - - usr/bin目录下没有python软链接。 - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001217013865.png) - -- **解决办法**2 - - 请运行以下命令: - - ``` - # cd /usr/bin/ - # which python3 - # ln -s /usr/local/bin/python3 python - # python --version - ``` - - 例: - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001216693915.png) - - -## 串口无回显 - -- **现象描述** - - 串口显示已连接,重启单板后,回车无任何回显。 - -- **可能原因1** - - 串口连接错误。 - -- **解决办法** - - 修改串口号。 - - 请查看设备管理器,确认连接单板的串口与终端中连接串口是否一致,若不一致,请按镜像运行内[步骤1](#section627268185113)修改串口号。 - - -- **可能原因2** - - 单板U-boot被损坏。 - -- **解决办法** - - 烧写U-boot。 - - 若上述步骤依旧无法连接串口,可能由于单板U-boot损坏,按下述步骤烧写U-boot。 - - -1. 获取引导文件U-boot。 - - >![](/images/device-dev/public_sys-resources/icon-notice.gif) **须知:** - >单板的U-boot文件请在开源包中获取: - >Hi3516DV300:device\\hisilicon\\hispark\_taurus\\sdk\_liteos\\uboot\\out\\boot\\u-boot-hi3516dv300.bin - >Hi3518EV300:device\\hisilicon\\hispark\_aries\\sdk\_liteos\\uboot\\out\\boot\\u-boot-hi3518ev300.bin - -2. 根据USB烧写步骤烧写U-boot文件。 - - 按照[Hi3516系列USB烧写步骤](https://device.harmonyos.com/cn/docs/documentation/guide/hi3516_upload-0000001052148681)中描述的USB烧写方法,选择对应单板的U-boot文件进行烧写。 - -3. 烧写完成后,登录串口如下图所示。 - - **图 10** U-boot烧写完成串口显示图 - ![](/images/device-dev/quick-start/figures/U-boot烧写完成串口显示图.png "U-boot烧写完成串口显示图") - - diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/03.Hi3518\345\274\200\345\217\221\346\235\277/01.\345\256\211\350\243\205\345\274\200\345\217\221\346\235\277\347\216\257\345\242\203.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/03.Hi3518\345\274\200\345\217\221\346\235\277/01.\345\256\211\350\243\205\345\274\200\345\217\221\346\235\277\347\216\257\345\242\203.md" deleted file mode 100644 index deb674bd50632bc662bfde84571033f18eedef35..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/03.Hi3518\345\274\200\345\217\221\346\235\277/01.\345\256\211\350\243\205\345\274\200\345\217\221\346\235\277\347\216\257\345\242\203.md" +++ /dev/null @@ -1,84 +0,0 @@ ---- -title: 安装开发板环境 -permalink: /pages/010201030301 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:20 ---- -# 安装开发板环境 - -- [Hi3518环境搭建](#section1724111409282) - - [硬件要求](#section487353718276) - - [软件要求](#section17315193935817) - -- [安装Linux服务器工具](#section8831868501) - - [安装编译依赖基础软件(仅Ubuntu 20+需要)](#section25911132141020) - - [安装文件打包工具](#section390214473129) - - -## Hi3518环境搭建 - -### 硬件要求 - -- Hi3518EV300 IoT Camera开发板 -- USB转串口线、网线(Linux工作台通过USB转串口线、网线与开发板连接) - -### 软件要求 - ->![](/images/device-dev/public_sys-resources/icon-notice.gif) **须知:** ->本节描述安装包方式搭建编译环境的操作步骤。如果是Docker方式安装编译环境,请跳过此章节,从[新建应用程序](/pages/010201030302)开始操作。 - -Hi3518开发板对Linux服务器通用环境配置需要的工具及其获取途径如下表所示。 - -**表 1** Linux服务器开发工具及获取途径 - - - - - - - - - - - - - - - - -

开发工具

-

用途

-

获取途径

-

编译基础软件包(仅ubuntu 20+需要)

-

编译依赖的基础软件包

-

通过互联网获取

-

dosfstools、mtools、mtd-utils

-

文件打包工具

-

通过apt-get install安装

-
- -## 安装Linux服务器工具 - -### 安装编译依赖基础软件(仅Ubuntu 20+需要) - -执行以下命令进行安装: - -``` -sudo apt-get install build-essential gcc g++ make zlib* libffi-dev -``` - -### 安装文件打包工具 - -运行如下命令,安装dosfstools,mtools,mtd-utils。 - -``` -sudo apt-get install dosfstools mtools mtd-utils -``` - diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/03.Hi3518\345\274\200\345\217\221\346\235\277/02.\346\226\260\345\273\272\345\272\224\347\224\250\347\250\213\345\272\217.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/03.Hi3518\345\274\200\345\217\221\346\235\277/02.\346\226\260\345\273\272\345\272\224\347\224\250\347\250\213\345\272\217.md" deleted file mode 100644 index 1fe78c7fa93b71dfefa31f5861cfe0e1fa2d412a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/03.Hi3518\345\274\200\345\217\221\346\235\277/02.\346\226\260\345\273\272\345\272\224\347\224\250\347\250\213\345\272\217.md" +++ /dev/null @@ -1,133 +0,0 @@ ---- -title: 新建应用程序 -permalink: /pages/010201030302 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:20 ---- -# 新建应用程序 - -下方将通过修改源码的方式展示如何编写简单程序,输出“Hello OHOS!”。请在[获取源码](/pages/0102010203)章节下载的源码目录中进行下述操作。 - -1. 新建目录及源码。 - - 新建**applications/sample/camera/apps/src/helloworld.c**目录及文件,代码如下所示,用户可以自定义修改打印内容(例如:修改OHOS为World)。当前应用程序可支持标准C及C++的代码开发。 - - ``` - #include - - int main(int argc, char **argv) - { - printf("\n************************************************\n"); - printf("\n\t\tHello OHOS!\n"); - printf("\n************************************************\n\n"); - - return 0; - } - ``` - -2. 新建编译组织文件。 - - 新建**applications/sample/camera/apps/BUILD.gn**文件,内容如下所示: - - ``` - import("//build/lite/config/component/lite_component.gni") - lite_component("hello-OHOS") { - features = [ ":helloworld" ] - } - executable("helloworld") { - output_name = "helloworld" - sources = [ "src/helloworld.c" ] - include_dirs = [] - defines = [] - cflags_c = [] - ldflags = [] - } - ``` - -3. 添加新组件。 - - 修改文件**build/lite/components/applications.json**,添加组件hello\_world\_app的配置,如下所示为applications.json文件片段,"\#\#start\#\#"和"\#\#end\#\#"之间为新增配置("\#\#start\#\#"和"\#\#end\#\#"仅用来标识位置,添加完配置后删除这两行): - - ``` - { - "components": [ - { - "component": "camera_sample_communication", - "description": "Communication related samples.", - "optional": "true", - "dirs": [ - "applications/sample/camera/communication" - ], - "targets": [ - "//applications/sample/camera/communication:sample" - ], - "rom": "", - "ram": "", - "output": [], - "adapted_kernel": [ "liteos_a" ], - "features": [], - "deps": { - "components": [], - "third_party": [] - } - }, - ##start## - { - "component": "hello_world_app", - "description": "Communication related samples.", - "optional": "true", - "dirs": [ - "applications/sample/camera/apps" - ], - "targets": [ - "//applications/sample/camera/apps:hello-OHOS" - ], - "rom": "", - "ram": "", - "output": [], - "adapted_kernel": [ "liteos_a" ], - "features": [], - "deps": { - "components": [], - "third_party": [] - } - }, - ##end## - { - "component": "camera_sample_app", - "description": "Camera related samples.", - "optional": "true", - "dirs": [ - "applications/sample/camera/launcher", - "applications/sample/camera/cameraApp", - "applications/sample/camera/setting", - "applications/sample/camera/gallery", - "applications/sample/camera/media" - ], - ``` - -4. 修改单板配置文件。 - - 修改文件**vendor/hisilicon/hispark\_aries/config.json**,新增hello\_world\_app组件的条目,如下所示代码片段为applications子系统配置,"\#\#start\#\#"和"\#\#end\#\#"之间为新增条目("\#\#start\#\#"和"\#\#end\#\#"仅用来标识位置,添加完配置后删除这两行): - - ``` - { - "subsystem": "applications", - "components": [ - ##start## - { "component": "hello_world_app", "features":[] }, - ##end## - { "component": "camera_sample_app", "features":[] } - - ] - }, - ``` - - diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/03.Hi3518\345\274\200\345\217\221\346\235\277/03.\347\274\226\350\257\221.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/03.Hi3518\345\274\200\345\217\221\346\235\277/03.\347\274\226\350\257\221.md" deleted file mode 100644 index 184c51788d2cc9b425ae40ad0d83c93540aca002..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/03.Hi3518\345\274\200\345\217\221\346\235\277/03.\347\274\226\350\257\221.md" +++ /dev/null @@ -1,39 +0,0 @@ ---- -title: 编译 -permalink: /pages/010201030303 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:20 ---- -# 编译 - -下方将介绍如何使用Hi3518开发板进行编译。使用安装包方式与docker方式搭建Ubuntu编译环境,编译命令相同。 - -1. 请进入源码根目录,执行如下命令进行编译: - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >如果使用Docker方式搭建编译环境,请在[获取Docker环境](/pages/0102010205#section15666113905015)中进入的Docker构建环境中,执行如下命令进行编译。 - - ``` - hb set(设置编译路径) - .(选择当前路径) - 选择ipcamera_hispark_aries并回车 - hb build -f(执行编译) - ``` - - **图 1** Hi3518编译设置图例-Docker方式 - ![](/images/device-dev/quick-start/figures/Hi3518编译设置图例-Docker方式.png "Hi3518编译设置图例-Docker方式") - -2. 编译结束后,出现“ipcamera\_hispark\_aries build success”字样,则证明构建成功。 - ->![](/images/device-dev/public_sys-resources/icon-notice.gif) **须知:** ->烧录相关文件获取路径: ->结果文件:out/hispark\_aries/ipcamera\_hispark\_aries。 ->U-boot文件:device/hisilicon/hispark\_aries/sdk\_liteos/uboot/out/boot/u-boot-hi3518ev300.bin。 - diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/03.Hi3518\345\274\200\345\217\221\346\235\277/04.\347\203\247\345\275\225.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/03.Hi3518\345\274\200\345\217\221\346\235\277/04.\347\203\247\345\275\225.md" deleted file mode 100644 index 9d27f107294222f64973e63b3f9c800b7ccd2828..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/03.Hi3518\345\274\200\345\217\221\346\235\277/04.\347\203\247\345\275\225.md" +++ /dev/null @@ -1,106 +0,0 @@ ---- -title: 烧录 -permalink: /pages/010201030304 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:20 ---- -# 烧录 - -- [前提条件](#section14614124417580) -- [使用串口烧录](#section195291211181215) - -烧录是指将编译后的程序文件下载到芯片开发板上的动作,为后续的程序调试提供基础。DevEco Device Tool提供一键烧录功能,操作简单,能快捷、高效的完成程序烧录,提升烧录的效率。 - -DevEco Device Tool以插件方式运行,基于Visual Studio Code进行扩展,用户可点击Visual Studio Code左侧栏的![](/images/device-dev/quick-start/figures/2021-01-27_170334.png)图标打开DevEco Device Tool。 - -Hi3518EV300开发板的代码烧录支持USB烧录和串口烧录两种方式,其中: - -- **Windows系统:支持USB烧录和串口烧录。** -- **Linux系统:支持串口烧录**。 - -Hi3861V100在Windows和Linux环境下的烧录操作完全一致,区别仅在于DevEco Device Tool环境搭建不同。 - -此处仅以Linux系统下串口烧录方式为例进行说明。 - -## 前提条件 - -1. 在DevEco Device Tool工具中点击**Import Project**导入新建应用程序章节修改后的源码文件。 - - ![](/images/device-dev/quick-start/figures/import-project.png) - -2. 选择源码导入时,系统会提示该工程不是DevEco Device Tool工程,点击**Import**。 - - ![](/images/device-dev/quick-start/figures/import-project-confirm.png) - -3. MCU选择HiSilicom\_Arm下的Hi3518EV300,Board选择hi3518ev300,Framework选择Hb,然后点击**Import**完成导入。 - - ![](/images/device-dev/quick-start/figures/hi3518-import-projects.png) - - -## 使用串口烧录 - -1. 请连接好电脑和待烧录开发板,需要同时连接串口和电源口,具体可参考[Hi3518EV300开发板介绍](https://device.harmonyos.com/cn/docs/documentation/guide/quickstart-lite-introduction-hi3518-0000001105201138)。 -2. 查看并记录对应的串口号。 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >如果对应的串口异常,请根据[Hi3516DV300/Hi3518EV300开发板串口驱动安装指导](https://device.harmonyos.com/cn/docs/documentation/guide/hi3516_hi3518-drivers-0000001050743695)安装USB转串口的驱动程序。 - - Windows系统,打开设备管理器查看并记录对应的串口号,或在DevEco Device Tool中,点击QUICK ACCESS \> DevEco Home \> Device,查看并记录对应的串口号。 - - ![](/images/device-dev/quick-start/figures/record-the-serial-port-number.png) - - Linux系统,在DevEco Device Tool中,点击QUICK ACCESS \> DevEco Home \> Device,查看并记录对应的串口号。 - - ![](/images/device-dev/quick-start/figures/Snap22.png) - -3. 在QUICK ACCESS \> DevEco Home \> Projects中,点击**Settings**打开工程配置界面。 - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001222981447.png) - -4. 在“hi3518ev300”页签,设置烧录选项,包括upload\_port、upload\_partitions和upload\_protocol。 - - - upload\_port:选择已查询的串口号。 - - upload\_protocol:选择烧录协议,固定选择“hiburn-serial”。 - - upload\_partitions:选择待烧录的文件,默认情况下会同时烧录fastboot、kernel、rootfs和userfs。 - - ![](/images/device-dev/quick-start/figures/Snap24.png) - -5. 分别检查待烧录文件的烧录信息,DevEco Device Tool已预置默认的烧录文件信息,可根据实际情况进行调整。待烧录文件包括:fastboot、kernel、rootfs和userfs。 - 1. 在“hi3518ev300\_fastboot”页签,在New Option选项中选择需要修改的项,例如partition\_bin(烧录文件路径)、partition\_addr(烧录文件起始地址)、partition\_length(烧录文件分区长度)等。 - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001177301516.png) - - 2. 然后在Partition Options中,分别修改上述步骤中选择的修改项。 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >在设置烧录分区起始地址和分区长度时,应根据实际待烧录文件的大小进行设置,遵循以下原则: - >- 要求设置的烧录分区大小,要大于待烧录文件的大小。 - >- 同时,各烧录文件的分区地址设置不能出现重叠。 - >- 总的烧录分区大小不能超过16MB。 - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001222781271.png) - - 3. 按照相同的方法修改kernel、footfs和userfs的烧录文件信息。 - -6. 所有的配置都修改完成后,在工程配置页签的顶部,点击**Save**进行保存。 -7. 点击**Open**打开工程文件,然后在“PROJECT TASKS”中,点击hi3518ev300下的**Upload**按钮,启动烧录。 - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001117329380.png) - -8. 启动烧录后,显示如下提示信息时,请重启开发板(下电再上电)。 - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001074287476.png) - -9. 重新上电后,界面提示如下信息时,表示烧录成功。 - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001073838982.png) - -10. 烧录成功后,请根据镜像运行章节进行操作,启动系统。 - diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/03.Hi3518\345\274\200\345\217\221\346\235\277/05.\350\277\220\350\241\214.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/03.Hi3518\345\274\200\345\217\221\346\235\277/05.\350\277\220\350\241\214.md" deleted file mode 100644 index 127ff03a3d61f67177f8b44613406212d76f70a1..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/03.Hi3518\345\274\200\345\217\221\346\235\277/05.\350\277\220\350\241\214.md" +++ /dev/null @@ -1,46 +0,0 @@ ---- -title: 运行 -permalink: /pages/010201030305 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:20 ---- -# 运行 - -- [镜像运行](#section1081111115589) -- [下一步学习](#section9712145420182) - -## 镜像运行 - -在完成Hi3518EV300的烧录后,还需要设置BootLoader引导程序,才能运行OpenHarmony系统。 - -1. 在Hi3518EV300任务中,点击**Configure bootloader(Boot OS)**进行配置即可。 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >DevEco Device Tool针对Hi3518EV300开发板的BootLoader设置进行了适配,无需开发者手动修改。 - - ![](/images/device-dev/quick-start/figures/hi3518-bootloader.png) - -2. 提示如下图中的重启开发板的提示信息时,重启开发板,然后在控制台输出“SUCCESS”表示设置成功。 - - ![](/images/device-dev/quick-start/figures/hi3518-reset-success.png) - -3. 在任务栏点击**Monitor**按钮,启动串口工具。 - - ![](/images/device-dev/quick-start/figures/hi3518-monitor.png) - -4. 当界面打印回显信息,点击Enter按钮,直到界面显示OHOS \#信息,表示系统启动成功。 - - ![](/images/device-dev/quick-start/figures/hi3518-reboot-success.png) - - -## 下一步学习 - -恭喜您,已完成Hi3518的快速上手!建议您下一步进入[无屏摄像头产品开发](/pages/extra/3b686a/)的学习 。 - diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/03.Hi3518\345\274\200\345\217\221\346\235\277/06.\345\270\270\350\247\201\351\227\256\351\242\230.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/03.Hi3518\345\274\200\345\217\221\346\235\277/06.\345\270\270\350\247\201\351\227\256\351\242\230.md" deleted file mode 100644 index 90f74e022b45b97a3d77e9ac0974dfd361e585a8..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/03.Hi3518\345\274\200\345\217\221\346\235\277/06.\345\270\270\350\247\201\351\227\256\351\242\230.md" +++ /dev/null @@ -1,181 +0,0 @@ ---- -title: 常见问题 -permalink: /pages/010201030306 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:20 ---- -# 常见问题 - -- [烧写选择串口后提示失败](#section1498892119619) -- [Windows电脑与单板网络连接失败](#section8512971816) -- [烧写失败](#section1767804111198) -- [编译构建过程中,提示找不到“python”](#zh-cn_topic_0000001053466255_section1039835245619) -- [串口无回显](#zh-cn_topic_0000001053466255_section14871149155911) - -## 烧写选择串口后提示失败 - -- **现象描述** - - 点击烧写并选择串口后,出现Error: Opening COMxx: Access denied。 - - **图 1** 打开串口失败图 - ![](/images/device-dev/quick-start/figures/打开串口失败图-1.png "打开串口失败图-1") - -- **可能原因** - - 串口已经被占用。 - -- **解决办法** - -1. 按图依次选择下拉框,查找带有serial-xx的终端。 - - **图 2** 查找是否存在占用串口的终端 - ![](/images/device-dev/quick-start/figures/查找是否存在占用串口的终端-2.png "查找是否存在占用串口的终端-2") - -2. 点击标号中的垃圾桶图标,关闭串口。 - - **图 3** 关闭串口终端 - ![](/images/device-dev/quick-start/figures/关闭串口终端-3.png "关闭串口终端-3") - -3. 重新点击烧写,选择串口并开始烧写程序。 - - **图 4** 重新启动烧写任务 - - - ![](/images/device-dev/quick-start/figures/changjian1-4.png) - - -## Windows电脑与单板网络连接失败 - -- **现象描述** - - 点击烧写并选择串口后,无法获取文件。 - - **图 5** 网络不通,单板无法获取文件图 - ![](/images/device-dev/quick-start/figures/网络不通-单板无法获取文件图-5.png "网络不通-单板无法获取文件图-5") - -- **可能原因** - - 单板网络与Windows电脑不联通。 - - Windows电脑防火墙未允许Visual Studio Code联网。 - -- **解决方法** - -1. 检查网线是否连接。 -2. 点击Windows防火墙。 - - **图 6** 网络防火墙设置图 - ![](/images/device-dev/quick-start/figures/网络防火墙设置图-6.png "网络防火墙设置图-6") - -3. 点击“允许应用通过防火墙”。 - - **图 7** 防火墙和网络保护界面图 - ![](/images/device-dev/quick-start/figures/防火墙和网络保护界面图-7.png "防火墙和网络保护界面图-7") - -4. 查找Visual Studio Code应用。 - - **图 8** 查找Visual Studio Code应用图 - ![](/images/device-dev/quick-start/figures/查找Visual-Studio-Code应用图-8.png "查找Visual-Studio-Code应用图-8") - -5. 勾选Visual Studio Code的专用和公用网络的访问权限。 - - **图 9** 允许Visual Studio Code应用访问网络 - ![](/images/device-dev/quick-start/figures/允许Visual-Studio-Code应用访问网络-9.png "允许Visual-Studio-Code应用访问网络-9") - - -## 烧写失败 - -- **现象描述** - - 点击烧写并选择串口后,出现无法烧写的情况。 - -- **可能原因** - - 安装IDE插件DevEco后未重启。 - -- **解决方法** - - 重启IDE。 - - -## 编译构建过程中,提示找不到“python” - -- **现象描述** - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001171774086.png) - - -- **可能原因** - - usr/bin目录下没有python软链接。 - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001171615534.png) - -- **解决办法** - - 请运行以下命令: - - ``` - # cd /usr/bin/ - # which python3 - # ln -s /usr/local/bin/python3 python - # python --version - ``` - - 例: - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001216535401.png) - - -## 串口无回显 - -- **现象描述** - - 串口显示已连接,重启单板后,回车无任何回显。 - -- **可能原因1** - - 串口连接错误。 - -- **解决办法** - - 修改串口号。 - - 请查看设备管理器,确认连接单板的串口与终端中连接串口是否一致,若不一致,请按镜像运行内[步骤1](#section1498892119619)修改串口号。 - - -- **可能原因2** - - 单板U-boot被损坏。 - -- **解决办法** - - 烧写U-boot。 - - 若上述步骤依旧无法连接串口,可能由于单板U-boot损坏,按下述步骤烧写U-boot。 - - -1. 获取引导文件U-boot。 - - >![](/images/device-dev/public_sys-resources/icon-notice.gif) **须知:** - >单板的U-boot文件请在开源包中获取: - >Hi3516DV300:device\\hisilicon\\hispark\_taurus\\sdk\_liteos\\uboot\\out\\boot\\u-boot-hi3516dv300.bin - >Hi3518EV300:device\\hisilicon\\hispark\_aries\\sdk\_liteos\\uboot\\out\\boot\\u-boot-hi3518ev300.bin - -2. 根据USB烧写步骤烧写U-boot文件。 - - 按照[Hi3518系列USB烧写步骤](https://device.harmonyos.com/cn/docs/documentation/guide/hi3518_upload-0000001057313128)中描述的USB烧写方法,选择对应单板的U-boot文件进行烧写。 - -3. 烧写完成后,登录串口如下图所示。 - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001216535397.png) - - diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/04.\351\231\204\345\275\225/01.Hi3861\345\274\200\345\217\221\346\235\277\344\273\213\347\273\215.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/04.\351\231\204\345\275\225/01.Hi3861\345\274\200\345\217\221\346\235\277\344\273\213\347\273\215.md" deleted file mode 100644 index f7969e1e69f1d735fcd80a944a3ed90b45ecca66..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/04.\351\231\204\345\275\225/01.Hi3861\345\274\200\345\217\221\346\235\277\344\273\213\347\273\215.md" +++ /dev/null @@ -1,168 +0,0 @@ ---- -title: Hi3861开发板介绍 -permalink: /pages/0102010401 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:20 ---- -# Hi3861开发板介绍 - -- [简介](#section19352114194115) -- [资源和约束](#section82610215014) -- [开发板规格](#section169054431017) -- [OpenHarmony关键特性](#section1317173016507) - -## 简介 - -Hi3861开发板是一片大约2cm\*5cm大小的开发板,是一款高度集成的2.4GHz WLAN SoC芯片,集成IEEE 802.11b/g/n基带和RF(Radio Frequency)电路。支持OpenHarmony,并配套提供开放、易用的开发和调试运行环境。 - -**图 1** Hi3861开发板外观图 -![](/images/device-dev/quick-start/figures/Hi3861开发板外观图.png "Hi3861开发板外观图") - -另外,Hi3861开发板还可以通过与Hi3861底板连接,扩充自身的外设能力,底板如下图所示。 - -**图 2** Hi3861底板外观图 - - -![](/images/device-dev/quick-start/figures/zh-cn_image_0000001171455564.png) - -- RF电路包括功率放大器PA(Power Amplifier)、低噪声放大器LNA(Low Noise Amplifier)、RF Balun、天线开关以及电源管理等模块;支持20MHz标准带宽和5MHz/10MHz窄带宽,提供最大72.2Mbit/s物理层速率。 -- Hi3861 WLAN基带支持正交频分复用(OFDM)技术,并向下兼容直接序列扩频(DSSS)和补码键控(CCK)技术,支持IEEE 802.11 b/g/n协议的各种数据速率。 -- Hi3861芯片集成高性能32bit微处理器、硬件安全引擎以及丰富的外设接口,外设接口包括SPI(Synchronous Peripheral Interface)、UART(Universal Asynchronous Receiver & Transmitter)、I2C(The Inter Integrated Circuit)、PWM(Pulse Width Modulation)、GPIO(General Purpose Input/Output)和多路ADC(Analog to Digital Converter),同时支持高速SDIO2.0(Secure Digital Input/Output)接口,最高时钟可达50MHz;芯片内置SRAM(Static Random Access Memory)和Flash,可独立运行,并支持在Flash上运行程序。 -- Hi3861芯片适用于智能家电等物联网智能终端领域。 - - **图 3** Hi3861功能框图 - - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001171455566.png) - - -## 资源和约束 - -Hi3861开发板资源十分有限,整板共2MB FLASH,352KB RAM。在编写业务代码时,需注意资源使用效率。 - -## 开发板规格 - -**表 1** Hi3861开发板规格清单 - - - - - - - - - - - - - - - - - - - - - - - - - -

规格类型

-

规格清单

-

通用规格

-
  • 1×1 2.4GHz频段(ch1~ch14)
  • PHY支持IEEE 802.11b/g/n
  • MAC支持IEEE802.11 d/e/h/i/k/v/w
-
  • 内置PA和LNA,集成TX/RX Switch、Balun等
  • 支持STA和AP形态,作为AP时最大支持6 个STA接入
  • 支持WFA WPA/WPA2 personal、WPS2.0
  • 支持与BT/BLE芯片共存的2/3/4 线PTA方案
  • 电源电压输入范围:2.3V~3.6V
-
  • IO电源电压支持1.8V和3.3V
-
  • 支持RF自校准方案
  • 低功耗:
    • Ultra Deep Sleep模式:5μA@3.3V
    • DTIM1:1.5mA@3.3V
    • DTIM3:0.8mA@3.3V
    -
-

PHY特性

-
  • 支持IEEE802.11b/g/n单天线所有的数据速率
  • 支持最大速率:72.2Mbps@HT20 MCS7
  • 支持标准20MHz带宽和5M/10M窄带宽
  • 支持STBC
  • 支持Short-GI
-

MAC特性

-
  • 支持A-MPDU,A-MSDU
  • 支持Blk-ACK
  • 支持QoS,满足不同业务服务质量需求
-

CPU子系统

-
  • 高性能 32bit微处理器,最大工作频率160MHz
  • 内嵌SRAM 352KB、ROM 288KB
  • 内嵌 2MB Flash
-

外围接口

-
  • 1个SDIO接口、2个SPI接口、2个I2C接口、3个UART接口、15个GPIO接口、7路ADC输入、6路PWM、1个I2S接口(注:上述接口通过复用实现)
  • 外部主晶体频率40M或24M
-

其他信息

-
  • 封装:QFN-32,5mm×5mm
  • 工作温度:-40℃ ~ +85℃
-
- -## OpenHarmony关键特性 - -OpenHarmony基于Hi3861平台提供了多种开放能力,提供的关键组件如下表所示。 - -**表 2** OpenHarmony关键组件列表 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

组件名

-

能力介绍

-

WLAN服务

-

提供WLAN服务能力。包括:station和hotspot模式的连接、断开、状态查询等。

-

模组外设控制

-

提供操作外设的能力。包括:I2C、I2S、ADC、UART、SPI、SDIO、GPIO、PWM、FLASH等。

-

分布式软总线

-

OpenHarmony分布式网络中,提供设备被发现、数据传输的能力。

-

设备安全绑定

-

提供在设备互联场景中,数据在设备之间的安全流转的能力。

-

基础加解密

-

提供密钥管理、加解密等能力。

-

系统服务管理

-

系统服务管理基于面向服务的架构,提供了OpenHarmony统一化的系统服务开发框架。

-

启动引导

-

提供系统服务的启动入口标识。在系统服务管理启动时,调用boostrap标识的入口函数,并启动系统服务。

-

系统属性

-

提供获取与设置系统属性的能力。

-

基础库

-

提供公共基础库能力。包括:文件操作、KV存储管理等。

-

DFX

-

提供DFX能力。包括:流水日志、时间打点等。

-

XTS

-

提供OpenHarmony生态认证测试套件的集合能力。

-
- diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/04.\351\231\204\345\275\225/02.Hi3516\345\274\200\345\217\221\346\235\277\344\273\213\347\273\215.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/04.\351\231\204\345\275\225/02.Hi3516\345\274\200\345\217\221\346\235\277\344\273\213\347\273\215.md" deleted file mode 100644 index 5588e97672e414edf29b0c342286008c89b0d71e..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/04.\351\231\204\345\275\225/02.Hi3516\345\274\200\345\217\221\346\235\277\344\273\213\347\273\215.md" +++ /dev/null @@ -1,55 +0,0 @@ ---- -title: Hi3516开发板介绍 -permalink: /pages/0102010402 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:20 ---- -# Hi3516开发板介绍 - -- [简介](#section26131214194212) -- [开发板规格](#section15192203316533) - -## 简介 - -Hi3516DV300作为新一代行业专用Smart HD IP摄像机SOC,集成新一代ISP\(Image Signal Processor\)、H.265视频压缩编码器,同时集成高性能NNIE引擎,使得Hi3516DV300在低码率、高画质、智能处理和分析、低功耗等方面引领行业水平。 - -**图 1** Hi3516单板正面外观图 - - -![](/images/device-dev/quick-start/figures/3516正面.png) - -## 开发板规格 - -**表 1** Hi3516开发板规格清单 - - - - - - - - - - - - - -

规格类型

-

规格清单

-

处理器及内部存储

-
  • Hi3516DV300芯片
  • DDR3 1GB
  • eMMC4.5,8GB容量
-

外部器件

-
  • 以太网口
  • 音频视频
    • 1路语音输入
    • 1路单声道(AC_L)输出,接3W功放(LM4871)
    • MicroHDMI(1路HDMI 1.4)
    -
  • 摄像头
    • 传感器IMX335
    • 镜头M12,焦距4mm,光圈1.8
    -
  • 显示屏
    • LCD连接器(2.35寸)
    • LCD连接器(5.5寸)
    -
  • 外部器件及接口
    • SD卡接口
    • JTAG/I2S 接口
    • ADC接口
    • 舵机接口
    • Grove连接器
    • USB2.0(Type C)
    • 功能按键3个,2个用户自定义按键,1个升级按键
    • LED指示灯,绿灯,红灯
    -
-
- diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/04.\351\231\204\345\275\225/03.Hi3518\345\274\200\345\217\221\346\235\277\344\273\213\347\273\215.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/04.\351\231\204\345\275\225/03.Hi3518\345\274\200\345\217\221\346\235\277\344\273\213\347\273\215.md" deleted file mode 100644 index 19d7a75726a1bf379fe4a9f73975fc1690990d16..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\345\205\245\351\227\250/04.\351\231\204\345\275\225/03.Hi3518\345\274\200\345\217\221\346\235\277\344\273\213\347\273\215.md" +++ /dev/null @@ -1,70 +0,0 @@ ---- -title: Hi3518开发板介绍 -permalink: /pages/0102010403 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:20 ---- -# Hi3518开发板介绍 - -- [简介](#section14815247616) -- [开发板规格](#section765112478446) - -## 简介 - -Hi3518EV300作为新一代智慧视觉处理SOC,集成新一代ISP\(Image Signal Processor\)以及H.265视频压缩编码器,同时采用先进低功耗工艺和低功耗架构设计,使其在低码率、高画质、低功耗等方面引领行业水平。 - -**图 1** Hi3518EV300单板正面外观图 -![](/images/device-dev/quick-start/figures/Hi3518EV300单板正面外观图.png "Hi3518EV300单板正面外观图") - -**图 2** Hi3518EV300单板背面外观图 - - -![](/images/device-dev/quick-start/figures/Hi3518正背面.png) - -## 开发板规格 - -**表 1** Hi3518开发板规格清单 - - - - - - - - - - - - - - - - - - - - - - -

规格类型

-

规格清单

-

处理器内核

-
  • 海思3518EV300
-

成像器件

-
  • 1/2.9 F23
-

外部接口

-
  • 外置麦克风MIC
  • 外置8Ω/1.5W扬声器
-

外部存储器接口

-
  • TF卡

    最大支持128GB(通用FAT32格式)

    -
-

WLAN协议

-
  • 支持 802.11 b/g/n
-
- diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/01.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250\347\256\200\344\273\213.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/01.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250\347\256\200\344\273\213.md" deleted file mode 100644 index ce0529f1f00bc95f8dd078327954841c1af9d02f..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/01.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250\347\256\200\344\273\213.md" +++ /dev/null @@ -1,36 +0,0 @@ ---- -title: 标准系统入门简介 -permalink: /pages/01020201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:20 ---- -# 标准系统入门简介 - -- [快速入门流程](#section7825218111517) - -开发者可通过本文快速掌握OpenHarmony标准系统的环境搭建、编译、烧录、运行等操作。标准系统的开发有以下两种方法: - -- 使用Windows环境进行开发和烧录,使用Linux环境进行编译。 -- 统一使用Linux环境进行开发、编译和烧录。 - -因目前Windows系统不支持编译,暂时无法全部使用Windows环境进行开发,开发者可根据使用习惯选择合适的开发方法。 - -本文将介绍第二种方法,**所有操作均在Linux环境下进行**。 - -## 快速入门流程 - -标准系统快速入门流程如下图所示,其中编译源码环节可根据实际情况选择docker方式或安装包方式其中一种即可。 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->Docker环境已经封装了相关编译工具,开发者在使用该Docker环境时可以省去Ubuntu编译环境及开发板环境的的搭建操作。 - -**图 1** 标准系统快速入门流程 -![](/images/device-dev/quick-start/figures/标准系统快速入门流程.png "标准系统快速入门流程") - diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207\357\274\210\344\273\205Hi3516\351\234\200\350\246\201\357\274\211.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207\357\274\210\344\273\205Hi3516\351\234\200\350\246\201\357\274\211.md" deleted file mode 100644 index 92ec208a0291e2c3856b5607251aaf98552222ba..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207\357\274\210\344\273\205Hi3516\351\234\200\350\246\201\357\274\211.md" +++ /dev/null @@ -1,86 +0,0 @@ ---- -title: 标准系统开发环境准备(仅Hi3516需要) -permalink: /pages/01020202 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:20 ---- -# 开发环境准备 - -- [系统要求](#zh-cn_topic_0000001072959308_section1865184385215) -- [安装DevEco Device Tool](#zh-cn_topic_0000001072959308_section86587531620) - -DevEco Device Tool Ubuntu版本支持OpenHarmony源码开发、编译、烧录的一站式开发环境,因此,本章节为您介绍在Ubuntu环境下,如何搭建一套完整的可视化开发环境。 - -## 系统要求 - -- Ubuntu18及以上版本,内存推荐16 GB及以上。 -- 系统的用户名不能含有中文字符。 -- 只能使用普通用户角色搭建开发环境。 - -## 安装DevEco Device Tool - -DevEco Device Tool基于Visual Studio Code进行扩展,在Visual Studio Code上以插件方式运行,Visual Studio Code版本为1.60及以上。同时,DevEco Device Tool还依赖Python工具,并要求Python为3.8\~3.9版本。 - -在安装过程中,DevEco Device Tool会自动检查Visual Studio Code和Python,如果检测到Visual Studio Code、Python未安装或版本不符合要求,安装程序会自动安装Visual Studio Code和Python。 - -1. 将Ubuntu Shell环境修改为bash。 - 1. 执行如下命令,确认输出结果为bash。如果输出结果不是bash,请根据步骤2,将Ubuntu shell修改为bash。 - - ``` - ls -l /bin/sh - ``` - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001194078294.png) - - 2. 打开终端工具,执行如下命令,输入密码,然后选择**No**,将Ubuntu shell由dash修改为bash。 - - ``` - sudo dpkg-reconfigure dash - ``` - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001238878219.png) - -2. 下载[DevEco Device Tool 3.0 Beta2](https://device.harmonyos.com/cn/ide#download_beta)Linux版本,下载时,请先使用华为开发者帐号进行登录后下载。如未注册华为开发者账号,请先[注册](https://developer.huawei.com/consumer/cn/doc/start/registration-and-verification-0000001053628148)。 -3. 解压DevEco Device Tool软件包并对解压后的文件夹进行赋权。 - 1. 进入DevEco Device Tool软件包目录,执行如下命令解压软件包,其中devicetool-linux-tool-3.0.0.200.zip为软件包名称,请根据实际进行修改。 - - ``` - unzip devicetool-linux-tool-3.0.0.300.zip - ``` - - 2. 进入解压后的文件夹,执行如下命令,赋予安装文件可执行权限,其中devicetool-linux-tool-3.0.0.300.sh请根据实际进行修改。 - - ``` - chmod u+x devicetool-linux-tool-3.0.0.300.sh - ``` - -4. 执行如下命令,安装DevEco Device Tool,其中devicetool-linux-tool-3.0.0.300.sh请根据实际进行修改。 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >安装过程中,会自动检查Visual Studio Code和Python是否安装,且版本符合要求,其中Visual Studio Code为1.60及以上版本,Python为3.8\~3.9版本。如果不满足,则安装过程中会自动安装,提示“Do you want to continue?”,请输入“Y”后继续安装。 - - ``` - sudo ./devicetool-linux-tool-3.0.0.300.sh -- --install-plugins - ``` - - 安装完成后,当界面输出“Deveco Device Tool successfully installed.”时,表示DevEco Device Tool安装成功。 - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001239348791.png) - -5. 安装完成后,在Ubuntu左下角的![](/images/device-dev/quick-start/figures/zh-cn_image_0000001075566984.png)中,启动Visual Studio Code。 -6. 启动Visual Studio Code,DevEco Device Tool运行依赖C/C++、CodeLLDB插件,请点击Visual Studio Code左侧的![](/images/device-dev/quick-start/figures/button.png)按钮,分别搜索和安装C/C++、CodeLLDB插件。 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >如果在插件市场安装C/C++和CodeLLDB插件不成功,可手动下载插件后进行安装,具体请参考:[离线安装C/C++和CodeLLDB插件](https://device.harmonyos.com/cn/docs/documentation/guide/offline_plugin_install-0000001074376846)。 - - ![](/images/device-dev/quick-start/figures/deveco-device-tool-install-sucessful.png) - -7. 重启Visual Studio Code,点击![](/images/device-dev/quick-start/figures/zh-cn_image_0000001239226427.png)进入DevEco Device Tool工具界面。至此,DevEco Device Tool Ubuntu开发环境安装完成。![](/images/device-dev/quick-start/figures/zh-cn_image_0000001194668634.png) - diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\216\267\345\217\226\346\272\220\347\240\201.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\216\267\345\217\226\346\272\220\347\240\201.md" deleted file mode 100644 index 24df6a0b56bb77fd5bf8faee11cb409154ffd315..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/03.\350\216\267\345\217\226\346\272\220\347\240\201.md" +++ /dev/null @@ -1,64 +0,0 @@ ---- -title: 获取源码 -permalink: /pages/01020203 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:20 ---- -# 获取源码 - -### 前提条件 - -1. 注册码云gitee账号。 -2. 注册码云SSH公钥,请参考[码云帮助中心](https://gitee.com/help/articles/4191)。 -3. 安装[git客户端](https://git-scm.com/book/zh/v2/%E8%B5%B7%E6%AD%A5-%E5%AE%89%E8%A3%85-Git)和[git-lfs](https://gitee.com/vcs-all-in-one/git-lfs?_from=gitee_search#downloading)并配置用户信息。 - - ``` - git config --global user.name "yourname" - git config --global user.email "your-email-address" - git config --global credential.helper store - ``` - -4. 安装码云repo工具,可以执行如下命令。 - - ``` - curl -s https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 > /usr/local/bin/repo #如果没有权限,可下载至其他目录,并将其配置到环境变量中 - chmod a+x /usr/local/bin/repo - pip3 install -i https://repo.huaweicloud.com/repository/pypi/simple requests - ``` - - -### 获取方式 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->Master主干为开发分支,开发者可通过Master主干获取最新特性。发布版本代码相对比较稳定,开发者可基于发布版本代码进行商用功能开发。 - -- **OpenHarmony主干代码获取** - - 方式一(推荐):通过repo + ssh下载(需注册公钥,请参考[码云帮助中心](https://gitee.com/help/articles/4191))。 - - ``` - repo init -u git@gitee.com:openharmony/manifest.git -b master --no-repo-verify - repo sync -c - repo forall -c 'git lfs pull' - ``` - - 方式二:通过repo + https下载。 - - ``` - repo init -u https://gitee.com/openharmony/manifest.git -b master --no-repo-verify - repo sync -c - repo forall -c 'git lfs pull' - ``` - -- **OpenHarmony发布版本代码获取** - - OpenHarmony发布版本获取源码方式请参考[Release-Notes](/pages/010104)。 - - diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/04.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/01.Hi3516\345\274\200\345\217\221\346\235\277/01.\345\210\233\345\273\272\345\272\224\347\224\250\347\250\213\345\272\217.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/04.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/01.Hi3516\345\274\200\345\217\221\346\235\277/01.\345\210\233\345\273\272\345\272\224\347\224\250\347\250\213\345\272\217.md" deleted file mode 100644 index e54af21e2ce64bd87ee67bfd474adb2c35bdd2e9..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/04.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/01.Hi3516\345\274\200\345\217\221\346\235\277/01.\345\210\233\345\273\272\345\272\224\347\224\250\347\250\213\345\272\217.md" +++ /dev/null @@ -1,143 +0,0 @@ ---- -title: 创建应用程序 -permalink: /pages/010202040101 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:20 ---- -# 创建应用程序 - -下方将通过修改源码的方式展示如何在单板上运行第一个应用程序,其中包括新建应用程序、编译、烧写、运行等步骤,最终输出“Hello World!”。 - -这里演示在原有applications子系统下,添加hello部件以及该部件下的helloworld模块。 - -示例完整目录如下。 - -``` -applications/standard/hello -├── helloworld -│ ├── BUILD.gn -│ ├── include -│ │ └── helloworld.h -│ └── src -│ └── helloworld.c -├── ohos.build -│ -productdefine/common -└── products - └── Hi3516DV300.json -``` - -下方为新建应用程序步骤,请在[获取源码](/pages/01020203)章节下载的源码目录中进行下述操作: - -1. 新建目录及源码。 - - 新建applications/standard/hello/helloworld/src/helloworld.c目录及文件,代码如下所示,用户可以自定义修改打印内容(例如:修改World为OHOS)。其中helloworld.h包含字符串打印函数HelloPrint的声明。当前应用程序可支持标准C及C++的代码开发。 - - ``` - #include - #include "helloworld.h" - - int main(int argc, char **argv) - { - HelloPrint(); - return 0; - } - - void HelloPrint() - { - printf("\n************************************************\n"); - printf("\n\t\tHello World!\n"); - printf("\n************************************************\n"); - } - ``` - - 再添加头文件applications/standard/hello/helloworld/include/helloworld.h,代码如下所示。 - - ``` - #ifndef HELLOWORLD_H - #define HELLOWORLD_H - #ifdef __cplusplus - #if __cplusplus - extern "C" { - #endif - #endif - - void HelloPrint(); - - #ifdef __cplusplus - #if __cplusplus - } - #endif - #endif - #endif // HELLOWORLD_H - ``` - -2. 新建编译组织文件。 - 1. 新建applications/standard/hello/helloworld/BUILD.gn文件,内容如下所示: - - ``` - import("//build/ohos.gni") # 导入编译模板 - ohos_executable("helloworld") { # 可执行模块 - sources = [ # 模块源码 - "src/helloworld.c" - ] - include_dirs = [ # 模块依赖头文件目录 - "include" - ] - cflags = [] - cflags_c = [] - cflags_cc = [] - ldflags = [] - configs = [] - deps =[] # 部件内部依赖 - - part_name = "hello" # 所属部件名称,必选 - install_enable = true # 是否默认安装(缺省默认不安装),可选 - } - ``` - - 2. 新建applications/standard/hello/ohos.build文件,添加hello部件描述,内容如下所示。 - - ``` - { - "subsystem": "applications", # 子系统名 - "parts": { # 包含部件 - "hello": { # 新建部件名 - "version": "1.0.0", # 版本 - "variants": [ # 变种版本 - "wearable", - "phone" - ], - "module_list": [ # 部件包含模块的gn目标 - "//applications/standard/hello/helloworld:helloworld" - ], - "inner_kits": [ # 提供给其他部件的接口 - ], - "test_list": [ # 测试用例 - ] - } - } - } - ``` - - ohos.build文件包含两个部分,第一部分subsystem说明该子系统的名称,parts定义该子系统包含的部件,要添加一个部件,需要把该部件对应的内容添加进parts中去。添加的时候需要指明该部件包含的模块module\_list,假如有提供给其它部件的接口,需要在inner\_kits中说明,假如有测试用例,需要在test\_list中说明,inner\_kits与test\_list没有也可以不添加。 - -3. 修改产品配置文件。 - - 在productdefine\\common\\products\\Hi3516DV300.json中添加对应的hello部件,直接添加到原有部件后即可。 - - ``` - "usb:usb_manager_native":{}, - "applications:prebuilt_hap":{}, - "applications:hello":{}, - "wpa_supplicant-2.9:wpa_supplicant-2.9":{}, - ``` - - diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/04.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/01.Hi3516\345\274\200\345\217\221\346\235\277/02.\347\274\226\350\257\221.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/04.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/01.Hi3516\345\274\200\345\217\221\346\235\277/02.\347\274\226\350\257\221.md" deleted file mode 100644 index 35975b28e9ed2e597c1a3418f36f1959d1cb835a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/04.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/01.Hi3516\345\274\200\345\217\221\346\235\277/02.\347\274\226\350\257\221.md" +++ /dev/null @@ -1,115 +0,0 @@ ---- -title: 编译 -permalink: /pages/010202040102 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:20 ---- -# 源码编译 - -- [使用Docker方式获取编译工具链](#section181431248132513) - - [执行prebuilts](#section111934551605) - - [安装Docker](#section1466184743915) - - [获取Docker环境](#section615912103552) - -- [使用安装包方式获取编译工具链](#section65647482593) - - [安装依赖工具](#section83441888010) - - [执行prebuilts](#section6389714142011) - -- [编译](#section92391739152318) - -安装编译工具链后,即可对源码进行编译。在Linux环境下获取编译工具链有以下两种方式,二者选其一即可: - -1. Docker方式 - - OpenHarmony标准系统为开发者提供的Docker环境已经将对应的编译工具链进行了封装,开发者可省略对应工具的安装。 - -2. 安装包方式 - - 使用安装包方式获取编译工具链时,开发者需自行安装相应的依赖工具。 - - -## 使用Docker方式获取编译工具链 - -### 执行prebuilts - -在源码根目录下执行脚本,安装编译器及二进制工具。 - -``` -bash build/prebuilts_download.sh -``` - -### 安装Docker - -请参考[官方指导](https://docs.docker.com/engine/install/)。 - -### 获取Docker环境 - -1. 获取Docker镜像。 - - ``` - docker pull swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker-standard:0.0.7 - ``` - -2. 进入源码根目录执行如下命令,从而进入Docker构建环境。 - - ``` - docker run -it -v $(pwd):/home/openharmony swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker-standard:0.0.7 - ``` - - -## 使用安装包方式获取编译工具链 - -### 安装依赖工具 - -请在终端中输入如下命令安装编译相关的依赖工具: - -``` -sudo apt-get update && sudo apt-get install binutils git git-lfs gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev ccache libgl1-mesa-dev libxml2-utils xsltproc unzip m4 bc gnutls-bin python3.8 python3-pip ruby -``` - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->以上安装命令适用于Ubuntu18.04,其他版本请根据安装包名称采用对应的安装命令。其中Python要求安装Python 3.7及以上版本,此处以Python 3.8为例。 - -### 执行prebuilts - -在源码根目录下执行脚本,安装编译器及二进制工具。 - -``` -bash build/prebuilts_download.sh -``` - -## 编译 - -1. 进入源码根目录,执行如下命令进行版本编译。 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >使用Docker方式获取编译工具链的,请直接通过[获取Docker环境](#section615912103552)最后一步进入的Docker构建环境执行如下命令。 - - ``` - ./build.sh --product-name Hi3516DV300 --ccache - ``` - -2. 检查编译结果。编译完成后,log中显示如下: - - ``` - build system image successful. - =====build Hi3516DV300 successful. - ``` - - 编译所生成的文件都归档在out/\{device\_name\}/目录下,结果镜像输出在out/\{device\_name\}/packages/phone/images/ 目录下。 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >其他模块化编译操作,可参见[编译构建指导](/pages/01050302)。 - -3. 编译源码完成,请进行镜像烧录,具体请参见[镜像烧录](/pages/010202040103)。 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->若使用Docker环境进行编译,执行exit命令即可退出Docker。 - diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/04.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/01.Hi3516\345\274\200\345\217\221\346\235\277/03.\347\203\247\345\275\225.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/04.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/01.Hi3516\345\274\200\345\217\221\346\235\277/03.\347\203\247\345\275\225.md" deleted file mode 100644 index 4040150383a49be8f0269af834bb4614bd8269a0..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/04.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/01.Hi3516\345\274\200\345\217\221\346\235\277/03.\347\203\247\345\275\225.md" +++ /dev/null @@ -1,114 +0,0 @@ ---- -title: 烧录 -permalink: /pages/010202040103 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:20 ---- -# 镜像烧录 - -- [前提条件](#section1956213516576) -- [使用网口烧录](#section14587120161217) - -标准系统烧录,在DevEco Device Tool V2.2 Beta1及以上版本支持,下方烧录操作均在DevEco Device Tool中进行。 - -DevEco Device Tool以插件方式运行,基于Visual Studio Code进行扩展,用户可点击Visual Studio Code左侧栏的![](/images/device-dev/quick-start/figures/2021-01-27_170334-10.png)图标打开DevEco Device Tool。 - -Hi3516DV300支持烧录标准系统,其烧录方式包括USB烧录、网口烧录和串口烧录三种方式,其中: - -- **Windows系统:支持USB烧录、网口烧录和串口烧录**。 -- **Linux系统:支持串口烧录和网口烧录。** - -同一种烧录方式(如网口烧录),在Windows和Linux环境下的烧录操作完全一致,区别仅在于DevEco Device Tool环境搭建不同。 - -下方以Linux系统下,网口烧录方式为例进行OpenHarmony标准系统烧录,其他两种烧录方式请参照[Hi3516DV300烧录指导](https://device.harmonyos.com/cn/docs/ide/user-guides/hi3516_upload-0000001052148681)。 - -## 前提条件 - -1. 在DevEco Device Tool工具中点击**Import Project**导入新建应用程序章节修改后的源码文件。 - - ![](/images/device-dev/quick-start/figures/import-project.png) - -2. 选择源码导入时,系统会提示该工程不是DevEco Device Tool工程,点击**Import**。 - - ![](/images/device-dev/quick-start/figures/import-project-confirm.png) - -3. MCU选择**HiSilicon\_Arm\_Linux**下的Hi3516DV300,Board选择hi3516dv300,Framework选择“Ohos-sources”,然后点击**Import**完成导入。 - - ![](/images/device-dev/quick-start/figures/hisilicon-arm-linux.png) - - -## 使用网口烧录 - -1. 请连接好电脑和待烧录开发板,需要同时连接串口和USB口,具体可参考[Hi3516DV300开发板介绍](https://device.harmonyos.com/cn/docs/documentation/guide/quickstart-lite-introduction-hi3516-0000001152041033)[Hi3516DV300开发板介绍](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/quickstart-lite-introduction-hi3516.md)。 -2. 查看并记录对应的串口号。 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >如果对应的串口异常,请根据[Hi3516DV300/Hi3518EV300开发板串口驱动安装指导](https://device.harmonyos.com/cn/docs/documentation/guide/hi3516_hi3518-drivers-0000001050743695)安装USB转串口的驱动程序。 - - Windows系统,打开设备管理器查看并记录对应的串口号,或在DevEco Device Tool中,点击QUICK ACCESS \> DevEco Home \> Device,查看并记录对应的串口号。 - - ![](/images/device-dev/quick-start/figures/record-the-serial-port-number.png) - - Linux系统,在DevEco Device Tool中,点击QUICK ACCESS \> DevEco Home \> Device,查看并记录对应的串口号。 - - ![](/images/device-dev/quick-start/figures/Snap22.png) - -3. 在QUICK ACCESS \> DevEco Home \> Projects中,点击**Settings**打开工程配置界面。 - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001177608370.png) - -4. 在“hi3516dv300”页签,设置烧录选项,包括upload\_partitions、upload\_port和upload\_protocol。 - - - upload\_partitions:选择待烧录的文件,默认情况下会同时烧录fastboot、boot、updater、misc、system、vendor和userdata。 - - upload\_port:选择已查询的串口号。 - - upload\_protocol:选择烧录协议,固定选择“hiburn-usb”。 - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001177478136.png) - -5. 分别检查待烧录文件的烧录信息,DevEco Device Tool已预置默认的烧录文件信息,可根据实际情况进行调整。待烧录文件包括:fastboot、boot、updater、misc、system、vendor和userdata。 - 1. 在“hi3516dv300\_fastboot”页签,在New Option选项中选择需要修改的项,例如partition\_bin(烧录文件路径)、partition\_addr(烧录文件起始地址)、partition\_length(烧录文件分区长度)等。 - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001222997983.png) - - 2. 然后在Partition Options中,分别修改上述步骤中选择的修改项。 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >在设置烧录分区起始地址和分区长度时,应根据实际待烧录文件的大小进行设置,要求设置的烧录分区大小,要大于待烧录文件的大小;同时,各烧录文件的分区地址设置不能出现重叠。 - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001222794413.png) - - 3. 按照相同的方法修改boot、updater和misc的烧录文件信息。 - -6. 所有的配置都修改完成后,在工程配置页签的顶部,点击**Save**进行保存。 -7. 点击**Open**打开工程文件,然后在“PROJECT TASKS”中,点击fastboot下的**Erase**按钮,擦除U-Boot。 - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001163045527.png) - -8. 执行**Erase**擦除操作后,显示如下提示信息时,请重启开发板(插拔USB连线)。 - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001114129426.png) - -9. 重新上电后,显示如下信息时,表示擦除U-Boot成功。 - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001113969536.png) - -10. 擦除完成后,点击hi3516dv300下的**Upload**按钮,启动烧录。 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >如果您是第一次在工作台烧录Hi3516DV300/Hi3518EV300开发板,可能烧录失败,提示“not find the Devices”,请根据[Hi3516DV300/Hi3518EV300开发板USB驱动安装](https://device.harmonyos.com/cn/docs/documentation/guide/usb_driver-0000001058690393)进行处理后再重新烧录。 - - ![](/images/device-dev/quick-start/figures/1-11.png) - -11. 启动烧录后,界面提示如下信息时,表示烧录成功。 - - ![](/images/device-dev/quick-start/figures/zh-cn_image_0000001160649343.png) - -12. 烧录完成后,请根据标准系统镜像运行进行下一步操作,完成系统启动。 - diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/04.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/01.Hi3516\345\274\200\345\217\221\346\235\277/04.\350\277\220\350\241\214.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/04.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/01.Hi3516\345\274\200\345\217\221\346\235\277/04.\350\277\220\350\241\214.md" deleted file mode 100644 index 0ff31fed37393bf7d8433b992331c0ce88b7d9fa..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/04.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/01.Hi3516\345\274\200\345\217\221\346\235\277/04.\350\277\220\350\241\214.md" +++ /dev/null @@ -1,73 +0,0 @@ ---- -title: 运行 -permalink: /pages/010202040104 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:20 ---- -# 镜像运行 - -- [启动系统](#section85351839162211) -- [运行“Hello World”](#section137849131182) -- [下一步](#section5600113114323) - -## 启动系统 - -烧录完成后通过以下步骤运行系统: - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->初次烧写标准系统,需要完成以下配置,后续烧写或者启动,可以跳过以下操作。 - -1. 在DevEco Device Tool中,点击Monitor,打开串口工具。 - - ![](/images/device-dev/quick-start/figures/open-the-serial-port-tool.png) - -2. 重启开发板,在倒计时结束前,按任意键进入系统。 - - ![](/images/device-dev/quick-start/figures/press-any-key-to-enter-the-system.gif) - -3. 通过以下两条命令设置启动参数。 - - ``` - setenv bootargs 'mem=640M console=ttyAMA0,115200 mmz=anonymous,0,0xA8000000,384M clk_ignore_unused rootdelay=10 hardware=Hi3516DV300 init=/init root=/dev/ram0 rw blkdevparts=mmcblk0:1M(boot),15M(kernel),20M(updater),2M(misc),3307M(system),256M(vendor),-(userdata)'; - ``` - - ``` - setenv bootcmd 'mmc read 0x0 0x82000000 0x800 0x4800; bootm 0x82000000' - ``` - - ![](/images/device-dev/quick-start/figures/setenv-bootargs.png) - -4. 保存参数设置。 - - ``` - save - ``` - - ![](/images/device-dev/quick-start/figures/Save-the-parameter-settings.png) - -5. 重启开发板,完成系统启动。 - - ``` - reset - ``` - - ![](/images/device-dev/quick-start/figures/start-the-system.png) - - -## 运行“Hello World” - -设备启动后打开串口工具,在任意目录下输入命令helloworld后回车,即出现“Hello World!”字样。 - -![](/images/device-dev/quick-start/figures/zh-cn_image_0000001193533352.png) - -## 下一步 - -恭喜!您已经完成了OpenHarmony标准系统的快速入门,接下来可[开发一个小示例](/pages/01070201),进一步熟悉OpenHarmony的开发。 - diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/04.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/02.RK3568\345\274\200\345\217\221\346\235\277/01.\345\210\233\345\273\272\345\272\224\347\224\250\347\250\213\345\272\217.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/04.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/02.RK3568\345\274\200\345\217\221\346\235\277/01.\345\210\233\345\273\272\345\272\224\347\224\250\347\250\213\345\272\217.md" deleted file mode 100644 index 9292f0e4083eeee8efc92113cb5fae8ad3018246..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/04.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/02.RK3568\345\274\200\345\217\221\346\235\277/01.\345\210\233\345\273\272\345\272\224\347\224\250\347\250\213\345\272\217.md" +++ /dev/null @@ -1,143 +0,0 @@ ---- -title: 创建应用程序 -permalink: /pages/010202040201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:20 ---- -# 创建应用程序 - -下方将通过修改源码的方式展示如何在单板上运行第一个应用程序,其中包括新建应用程序、编译、烧写、运行等步骤,最终输出“Hello World!”。 - -这里演示在原有applications子系统下,添加hello部件以及该部件下的helloworld模块。 - -示例完整目录如下。 - -``` -applications/standard/hello -├── helloworld -│ ├── BUILD.gn -│ ├── include -│ │ └── helloworld.h -│ └── src -│ └── helloworld.c -├── ohos.build -│ -productdefine/common -└── products - └── rk3568.json -``` - -下方为新建应用程序步骤,请在[获取源码](/pages/01020203)章节下载的源码目录中进行下述操作: - -1. 新建目录及源码。 - - 新建applications/standard/hello/helloworld/src/helloworld.c目录及文件,代码如下所示,用户可以自定义修改打印内容(例如:修改World为OHOS)。其中helloworld.h包含字符串打印函数HelloPrint的声明。当前应用程序可支持标准C及C++的代码开发。 - - ``` - #include - #include "helloworld.h" - - int main(int argc, char **argv) - { - HelloPrint(); - return 0; - } - - void HelloPrint() - { - printf("\n************************************************\n"); - printf("\n\t\tHello World!\n"); - printf("\n************************************************\n"); - } - ``` - - 再添加头文件applications/standard/hello/helloworld/include/helloworld.h,代码如下所示。 - - ``` - #ifndef HELLOWORLD_H - #define HELLOWORLD_H - #ifdef __cplusplus - #if __cplusplus - extern "C" { - #endif - #endif - - void HelloPrint(); - - #ifdef __cplusplus - #if __cplusplus - } - #endif - #endif - #endif // HELLOWORLD_H - ``` - -2. 新建编译组织文件。 - 1. 新建applications/standard/hello/helloworld/BUILD.gn文件,内容如下所示: - - ``` - import("//build/ohos.gni") # 导入编译模板 - ohos_executable("helloworld") { # 可执行模块 - sources = [ # 模块源码 - "src/helloworld.c" - ] - include_dirs = [ # 模块依赖头文件目录 - "include" - ] - cflags = [] - cflags_c = [] - cflags_cc = [] - ldflags = [] - configs = [] - deps =[] # 部件内部依赖 - - part_name = "hello" # 所属部件名称,必选 - install_enable = true # 是否默认安装(缺省默认不安装),可选 - } - ``` - - 2. 新建applications/standard/hello/ohos.build文件,添加hello部件描述,内容如下所示。 - - ``` - { - "subsystem": "applications", # 子系统名 - "parts": { # 包含部件 - "hello": { # 新建部件名 - "version": "1.0.0", # 版本 - "variants": [ # 变种版本 - "wearable", - "phone" - ], - "module_list": [ # 部件包含模块的gn目标 - "//applications/standard/hello/helloworld:helloworld" - ], - "inner_kits": [ # 提供给其他部件的接口 - ], - "test_list": [ # 测试用例 - ] - } - } - } - ``` - - ohos.build文件包含两个部分,第一部分subsystem说明该子系统的名称,parts定义该子系统包含的部件,要添加一个部件,需要把该部件对应的内容添加进parts中去。添加的时候需要指明该部件包含的模块module\_list,假如有提供给其它部件的接口,需要在inner\_kits中说明,假如有测试用例,需要在test\_list中说明,inner\_kits与test\_list没有也可以不添加。 - -3. 修改产品配置文件。 - - 在productdefine\\common\\products\\rk3568.json中添加对应的hello部件,直接添加到原有部件后即可。 - - ``` - "usb:usb_manager_native":{}, - "applications:prebuilt_hap":{}, - "applications:hello":{}, - "wpa_supplicant-2.9:wpa_supplicant-2.9":{}, - ``` - - diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/04.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/02.RK3568\345\274\200\345\217\221\346\235\277/02.\347\274\226\350\257\221.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/04.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/02.RK3568\345\274\200\345\217\221\346\235\277/02.\347\274\226\350\257\221.md" deleted file mode 100644 index 2eef65328b26e092bc4750c12777be3cb4a77a34..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/04.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/02.RK3568\345\274\200\345\217\221\346\235\277/02.\347\274\226\350\257\221.md" +++ /dev/null @@ -1,115 +0,0 @@ ---- -title: 编译 -permalink: /pages/010202040202 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:20 ---- -# 源码编译 - -- [使用Docker方式获取编译工具链](#section181431248132513) - - [执行prebuilts](#section111934551605) - - [安装Docker](#section1466184743915) - - [获取Docker环境](#section615912103552) - -- [使用安装包方式获取编译工具链](#section65647482593) - - [安装依赖工具](#section83441888010) - - [执行prebuilts](#section6389714142011) - -- [编译](#section92391739152318) - -安装编译工具链后,即可对源码进行编译。在Linux环境下获取编译工具链有以下两种方式,二者选其一即可: - -1. Docker方式 - - OpenHarmony标准系统为开发者提供的Docker环境已经将对应的编译工具链进行了封装,开发者可省略对应工具的安装。 - -2. 安装包方式 - - 使用安装包方式获取编译工具链时,开发者需自行安装相应的依赖工具。 - - -## 使用Docker方式获取编译工具链 - -### 执行prebuilts - -在源码根目录下执行脚本,安装编译器及二进制工具。 - -``` -bash build/prebuilts_download.sh -``` - -### 安装Docker - -请参考[官方指导](https://docs.docker.com/engine/install/)。 - -### 获取Docker环境 - -1. 获取Docker镜像。 - - ``` - docker pull swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker-standard:0.0.7 - ``` - -2. 进入源码根目录执行如下命令,从而进入Docker构建环境。 - - ``` - docker run -it -v $(pwd):/home/openharmony swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker-standard:0.0.7 - ``` - - -## 使用安装包方式获取编译工具链 - -### 安装依赖工具 - -请在终端中输入如下命令安装编译相关的依赖工具: - -``` -sudo apt-get update && sudo apt-get install binutils git git-lfs gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev ccache libgl1-mesa-dev libxml2-utils xsltproc unzip m4 bc gnutls-bin python3.8 python3-pip ruby -``` - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->以上安装命令适用于Ubuntu18.04,其他版本请根据安装包名称采用对应的安装命令。其中Python要求安装Python 3.7及以上版本,此处以Python 3.8为例。 - -### 执行prebuilts - -在源码根目录下执行脚本,安装编译器及二进制工具。 - -``` -bash build/prebuilts_download.sh -``` - -## 编译 - -1. 进入源码根目录,执行如下命令进行版本编译。 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >使用Docker方式获取编译工具链的,请直接通过[获取Docker环境](#section615912103552)最后一步进入的Docker构建环境执行如下命令。 - - ``` - ./build.sh --product-name rk3568 --ccache - ``` - -2. 检查编译结果。编译完成后,log中显示如下: - - ``` - post_process - =====build rk3568 successful. - ``` - - 编译所生成的文件都归档在out/\{device\_name\}/目录下,结果镜像输出在out/\{device\_name\}/packages/phone/images/ 目录下。 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >其他模块化编译操作,可参见[编译构建指导](/pages/01050302)。 - -3. 编译源码完成,请进行镜像烧录,具体请参见[镜像烧录](/pages/010202040103)。 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->若使用Docker环境进行编译,执行exit命令即可退出Docker。 - diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/04.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/02.RK3568\345\274\200\345\217\221\346\235\277/03.\347\203\247\345\275\225.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/04.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/02.RK3568\345\274\200\345\217\221\346\235\277/03.\347\203\247\345\275\225.md" deleted file mode 100644 index cb12fca8acb534b2d7c35c5597f6a7186501816b..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/04.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/02.RK3568\345\274\200\345\217\221\346\235\277/03.\347\203\247\345\275\225.md" +++ /dev/null @@ -1,17 +0,0 @@ ---- -title: 烧录 -permalink: /pages/010202040203 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:20 ---- -# 镜像烧录 - -请参考:[HiHope\_DAYU200烧写工具及指南](https://gitee.com/hihope_iot/docs/blob/master/HiHope_DAYU200/%E7%83%A7%E5%86%99%E5%B7%A5%E5%85%B7%E5%8F%8A%E6%8C%87%E5%8D%97/HiHope-DAYU200%E9%95%9C%E5%83%8F%E7%83%A7%E5%BD%95%E6%8C%87%E5%8D%97.pdf)。 - diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/04.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/02.RK3568\345\274\200\345\217\221\346\235\277/04.\350\277\220\350\241\214.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/04.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/02.RK3568\345\274\200\345\217\221\346\235\277/04.\350\277\220\350\241\214.md" deleted file mode 100644 index 83ed4b0bb8a87d4c8f2fa47f97ffee32b652763c..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/04.\350\277\220\350\241\214\342\200\234HelloWorld\342\200\235/02.RK3568\345\274\200\345\217\221\346\235\277/04.\350\277\220\350\241\214.md" +++ /dev/null @@ -1,36 +0,0 @@ ---- -title: 运行 -permalink: /pages/010202040204 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 镜像运行 - -- [启动系统](#section646361191511) -- [运行“Hello World”](#section11845976150) - -## 启动系统 - -镜像烧录完成并连接电源线之后,系统将会自动启动。开发板附带的屏幕呈现以下界面,表明系统已运行成功。 - -**图 1** 系统启动效果图 -![](/images/device-dev/quick-start/figures/系统启动效果图.jpg "系统启动效果图") - -## 运行“Hello World” - -- 设备启动后打开串口工具(以putty为例),波特率设置为1500000,连接设备。 - - ![](/images/device-dev/quick-start/figures/rk3568-run-configuration.png) - -- 打开串口后,在任意目录(以设备根目录为例)下输入命令helloworld后回车,即出现“Hello World!”字样。 - - ![](/images/device-dev/quick-start/figures/rk3568-helloworld.png) - - diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/05.\345\270\270\350\247\201\351\227\256\351\242\230.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/05.\345\270\270\350\247\201\351\227\256\351\242\230.md" deleted file mode 100644 index 481804e2a9d065de056d639ffe71bfd4d54a7302..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/05.\345\270\270\350\247\201\351\227\256\351\242\230.md" +++ /dev/null @@ -1,37 +0,0 @@ ---- -title: 常见问题 -permalink: /pages/01020205 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 常见问题 - -- [编译构建过程中,提示"ImportError: No module named apt\_pkg"](#section1864714601214) - -## 编译构建过程中,提示"ImportError: No module named apt\_pkg" - -- **现象描述** - - Linux编译服务器终端输入不识别的命令时,提示"ImportError: No module named apt\_pkg"。 - -- **可能原因** - - python3 apt安装兼容性问题。 - -- **解决办法** - - 执行如下命令重新安装python3-apt。 - - ``` - sudo apt-get remove python3-apt - sudo apt-get install python3-apt - ``` - - diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/06.\351\231\204\345\275\225/01.Hi3516\345\274\200\345\217\221\346\235\277\344\273\213\347\273\215.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/06.\351\231\204\345\275\225/01.Hi3516\345\274\200\345\217\221\346\235\277\344\273\213\347\273\215.md" deleted file mode 100644 index 6395e905f74b05541e79c622ec9dab09c8329011..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/06.\351\231\204\345\275\225/01.Hi3516\345\274\200\345\217\221\346\235\277\344\273\213\347\273\215.md" +++ /dev/null @@ -1,53 +0,0 @@ ---- -title: Hi3516开发板介绍 -permalink: /pages/0102020601 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# Hi3516开发板介绍 - -- [开发板简介](#zh-cn_topic_0000001053666242_section047719215429) -- [开发板规格](#zh-cn_topic_0000001053666242_section15192203316533) - -## 开发板简介 - -Hi3516DV300是新一代行业专用Smart HD IP摄像机SOC,集成新一代ISP\(Image Signal Processor\)、H.265视频压缩编码器、高性能NNIE引擎,在低码率、高画质、智能处理和分析、低功耗等方面引领行业水平。 - -**图 1** Hi3516单板正面外观图 -![](/images/device-dev/quick-start/figures/Hi3516单板正面外观图.png "Hi3516单板正面外观图") - -## 开发板规格 - -**表 1** Hi3516开发板规格清单 - - - - - - - - - - - - - -

规格类型

-

规格清单

-

处理器及内部存储

-
  • Hi3516DV300芯片
  • DDR3 1GB
  • eMMC4.5,8GB容量
-

外部器件

-
  • 以太网口
  • 音频视频
    • 1路语音输入
    • 1路单声道(AC_L)输出,接3W功放(LM4871)
    • MicroHDMI(1路HDMI 1.4)
    -
  • 摄像头
    • 传感器IMX335
    • 镜头M12,焦距4mm,光圈1.8
    -
  • 显示屏
    • LCD连接器(2.35寸)
    • LCD连接器(5.5寸)
    -
  • 外部器件及接口
    • SD卡接口
    • JTAG/I2S接口
    • ADC接口
    • 舵机接口
    • Grove连接器
    • USB2.0(Type C)
    • 功能按键3个,2个用户自定义按键,1个升级按键
    • LED指示灯,绿灯,红灯
    -
-
- diff --git "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/06.\351\231\204\345\275\225/02.RK3568\345\274\200\345\217\221\346\235\277\344\273\213\347\273\215.md" "b/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/06.\351\231\204\345\275\225/02.RK3568\345\274\200\345\217\221\346\235\277\344\273\213\347\273\215.md" deleted file mode 100644 index 65cee510b0d1de001ddbc2afc75f8f2e4c81be7c..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/02.\345\277\253\351\200\237\345\274\200\345\247\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\345\205\245\351\227\250/06.\351\231\204\345\275\225/02.RK3568\345\274\200\345\217\221\346\235\277\344\273\213\347\273\215.md" +++ /dev/null @@ -1,16 +0,0 @@ ---- -title: RK3568开发板介绍 -permalink: /pages/0102020602 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# RK3568开发板介绍 - -参见:[润和HH-SCDAYU200开发套件](https://gitee.com/hihope_iot/docs/blob/master/HiHope_DAYU200/README.md)。 \ No newline at end of file diff --git "a/website/docs/01.OpenHarmony/03.\345\205\274\345\256\271\346\200\247\344\270\216\345\256\211\345\205\250/01.\351\232\220\347\247\201\344\270\216\345\256\211\345\205\250\350\247\204\350\214\203/01.\351\232\220\347\247\201\344\277\235\346\212\244.md" "b/website/docs/01.OpenHarmony/03.\345\205\274\345\256\271\346\200\247\344\270\216\345\256\211\345\205\250/01.\351\232\220\347\247\201\344\270\216\345\256\211\345\205\250\350\247\204\350\214\203/01.\351\232\220\347\247\201\344\277\235\346\212\244.md" deleted file mode 100644 index ec6034dd619a31f440440366ab710eb78f30a40a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/03.\345\205\274\345\256\271\346\200\247\344\270\216\345\256\211\345\205\250/01.\351\232\220\347\247\201\344\270\216\345\256\211\345\205\250\350\247\204\350\214\203/01.\351\232\220\347\247\201\344\277\235\346\212\244.md" +++ /dev/null @@ -1,277 +0,0 @@ ---- -title: 隐私保护 -permalink: /pages/01030101 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 隐私保护 - -- [隐私保护概述](#section13200134331414) -- [数据分类分级](#section2371104991511) -- [通用隐私设计规则](#section10354102411162) -- [特殊品类要求](#section118861450201618) - -## 隐私保护概述 - -随着互联网及信息化的发展,个人数据在社会经济和日常生活中发挥着越来越重要的作用。与此同时,个人数据泄露的风险也在增加,消费者产品开发者需要更加有效的保护用户的个人数据,提高用户对产品的信任度。为了提升消费者的隐私体验,产品应默认设置较高级别隐私保护策略,达到保护消费者隐私的目的。 - -**基本概念** - -- **个人数据(Personal Data)** - - 与一个身份已被识别或者身份可被识别的自然人(“数据主体”)相关的任何信息;身份可识别的自然人是指其身份可以通过诸如姓名、身份证号、位置数据等识别码或者通过一个或多个与自然人的身体、生理、精神、经济、文化或者社会身份相关的特定因素来直接或者间接地被识别。个人数据包括:自然人的email地址、电话号码、生物特征(指纹)、位置数据、IP地址、医疗信息、宗教信仰、社保号、婚姻状态等。 - -- **敏感个人数据(Sensitive Personal Data)** - - 敏感个人数据是个人数据的一个重要子集,指的是涉及数据主体的最私密领域的信息或者一旦泄露可能会给数据主体造成重大不利影响的数据。欧盟等国家和地区法律定义的敏感个人数据包括种族、政治观点、宗教和哲学信仰、工会成员资格、基因数据、生物信息、健康和性生活状况、性取向等。 - - 根据业界最佳实践,敏感个人数据还包括可与自然人身份相关联的银行卡号、身份证号、护照号、口令等。敏感个人数据的处理需要更多更严格的保护措施。 - -- **公开个人数据(Public available Personal Data)** - - 数据主体主动公开的个人数据,或公开网页/应用上可访问的个人数据,包括论坛公开的发帖、评论等。 - -- **用户画像(User Profile)** - - 指对个人数据采取的任何自动化处理的方式,包括评估某个自然人特定方面的情况,尤其是为了分析和预测该自然人的工作表现、经济状况、健康、个人喜好、兴趣、可信度、行为举止、所在位置或行迹。 - -- **数据控制者(Data Controller)** - - 单独或者与他人共同确定个人数据处理的目的和手段的自然人、法人、公共机构、政府部门或其他机构。 - -- **数据处理者(Data Processor)** - - 指代表数据控制者处理个人数据的自然人、法人、公共机构、政府部门或其他机构。数据处理者必须按照数据控制者的要求对个人数据进行充分的保护。 - -- **明示同意(Explicit consent)** - - 如下几种情形GDPR法律提到可以通过数据主体明示同意的方式合法地处理数据: - - - 处理敏感个人数据。 - - 自动化决策,包括进行用户画像。 - - 向不具备充分保护水平的国家转移个人数据,并以同意作为合法性基础。 - - 实现明示同意的方式有: - - - 在收集特定数据时,弹出隐私声明告知个人数据处理相关事项,提供勾选框但不默认勾选,让数据主体勾选“我同意以上述方式处理我的个人数据”,或提供“我同意”的按钮让用户主动点击。 - - 以书面的方式明确表达同意,数据主体在书面陈述上签字。 - - 要求数据主体在系统中上传带有其签名的电子表格。 - - 采取双重验证的方式,要求数据主体邮件形式回复同意后,再次点击用于验证的邮件链接或是输入SMS验证码。 - - 用户主动输入的场景,例如用户主动输入身份证和银行卡号绑卡等场景。 - - -## 数据分类分级 - -基于数据保护目标及风险后果,即数据遭到泄露或者遭到破坏带来的法律风险对个人、组织或公众的影响对数据进行定级,分为极高、高、中、低、公开五个数据级别。 - -**表1** 数据分类分级标准 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

数据级别

-

隐私风险

-

隐私属性

-

典型示例

-

极高级

-

数据一旦识别或关联到特定个人或群体,其泄露或不当使用可能会给个人带来灾难性负面影响。

-

敏感个人数据

-

DNA、种族、宗教信仰、性取向;生物识别信息;原始通信内容;银行卡密码、磁道数据。

-

高级别

-

数据一旦识别或关联到特定个人或群体,其泄露或不当使用可能会给个人带来严重负面影响。

-

敏感个人数据

-

权威社会标识(身份证、护照等);网页浏览记录;轨迹信息;云空间上传的内容数据(图库/音频/视频等)。

-

中级别

-

数据一旦识别或关联到特定个人或群体,其泄露或不当使用可能会给个人带来重大负面影响。

-

一般个人数据

-

设备标识(IMEI, SN, OAID )、用户标识(user ID);个人基本信息(姓名,地址);手机号、邮箱等。

-

低级别

-

数据一旦识别或关联到特定个人或群体,其泄露或不当使用可能会给个人带来有限负面影响。

-

一般个人数据

-

操作系统设置信息(操作系统版本,国家/地区等);设备硬件信息(设备型号,屏幕尺寸,屏幕分辨率等);网络信息(网络连接状态,接入网络信息);设备状态(登录设备时间/时长)。

-

公开(无风险)

-

对个人或组织无不利影响的可公开数据

-

非个人数据

-

公开发布的产品介绍,公开的会议信息,外部开源的代码等。

-
- -备注:隐私保护和数据分类分级的相关定义参照GDPR中的相关内容。 - -## 通用隐私设计规则 - -为了指导厂商完成产品的隐私设计工作,我们整理了以下通用的隐私设计要求,作为OpenHarmony设备厂商产品隐私设计的指南和参考。 - -**数据收集及使用公开透明** - -采集个人数据时,应清晰、明确地告知用户,并确保告知用户的个人信息将被如何使用。 - -- 针对不同等级的个人数据需要制定针对性的隐私处理策略。 - - 敏感个人数据的采集需要获取数据主体明示同意。 - - 一般个人数据的采集需要数据主体同意或基于其他合法授权。 - - 非个人数据与中、高或极高级别个人数据关联采集,需要数据主体同意或其他合法授权,并在隐私声明中呈现。 - -- 应制定并遵从适当的隐私政策。在收集、使用留存和第三方分享用户个人数据时需要符合所有适用法律、政策和规定。如在收集个人数据前,需充分告知用户处理个人数据的种类、目的、处理方式、保留期限等,满足数据主体权利相关要求。 - - 根据以上要求,我们设计了正确示例以供参考。隐私通知/声明的参考示例如下: - - **图 1** 隐私通知/声明示例图 - - - ![](/images/device-dev/security/figure/2-应用启动预授权.png) ![](/images/device-dev/security/figure/3-应用隐私声明.png) - -- 个人数据应当基于具体、明确、合法的目的收集,不应与此目的不相符的方式作进一步处理。对于收集目的变更和用户撤销同意后再次重新使用的场景都需要用户重新同意。隐私声明变更和撤销的示例如下图: - - **图 2** 隐私通知/声明变更示例图 - - - ![](/images/device-dev/security/figure/4-隐私声明变更通知.png) - - **图 3** 撤销同意示例图 - - - ![](/images/device-dev/security/figure/6-1-隐私声明撤销.png) ![](/images/device-dev/security/figure/6-2-隐私声明撤销.png) - -- 需要提供用户查看隐私声明的入口。例如,可以在应用的“关于”界面提供查看隐私声明的入口,如示例图所示: - - **图 4** 隐私声明查看界面示例图 - - - ![](/images/device-dev/security/figure/5-应用隐私声明入口.png) - - -**数据收集及使用最小化** - -个人数据收集应与数据处理目的相关,且是适当、必要的。开发者应尽可能对个人数据进行匿名化或假名化处理,降低对数据主体的风险。仅可收集和处理与特定目的相关且必需的个人数据,不能进行与特定目的不相关的进一步处理。 - -- 敏感权限申请的时候要满足权限最小化的要求,在申请权限时,只申请获取必需的信息或资源所需要的权限。如应用不需要相机权限就能够实现其功能时,则不应该向用户申请相机权限。 -- 数据收集最小化:针对数据的收集要满足最小化要求,不收集与产品提供服务无关联的数据。如提供定位服务的产品,不应收集用户的网页浏览记录。 -- 数据使用的功能要求能够使用户受益,收集的数据不能用于一些与用户正常使用无关的功能。数据收集不能有其他与用户正常使用无关的功能存在。如不得将“生物特征”、“健康数据”等敏感个人数据用于服务改进、投放广告或营销等非业务核心功能。 -- 禁止在日志中打印敏感个人数据,如需要打印一般个人数据时,应对个人数据进行匿名化或假名化处理; - - 优先使用可以重置的标识符,如系统提供了NetworkID和DVID作为分布式场景下的设备标识符,广告业务场景下则建议使用[OAID](https://developer.huawei.com/consumer/cn/doc/development/HMSCore-Guides/oaid-0000001050783198),基于应用的分析则建议使用[ODID](https://developer.huawei.com/consumer/cn/doc/development/HMSCore-Guides/odid-0000001051063255)和[AAID](https://developer.huawei.com/consumer/cn/doc/development/HMSCore-Guides/aaid-0000001051142988),其他需要唯一标识符的场景可以使用UUID接口生成;可重置的标识符不能满足业务需求时,才选择序列号和MAC地址等永久性标识符。 - - -**数据处理选择和控制** - -对个人数据处理必须要征得用户的同意或遵守其他适用的法律法规,用户对其个人数据要有充分的控制权。 - -- 获取用户敏感权限的授权:产品弹窗提醒,向用户呈现需要获取的权限和权限使用目的,用户可通过选择决定是否进行授权及指定授权的方式,让用户对产品权限的授予和个人数据使用做到透明、可知、可控。如下图所示: - - **图 5** 敏感权限提示框示例图 - - - ![](/images/device-dev/security/figure/1-敏感权限弹窗.png) - -- 用户可以修改、取消授予的权限:当用户不同意某一权限或者数据收集时,应当允许用户使用与这部分权限和数据收集不相关的功能。如智慧屏产品上通信社交应用,用户可以拒绝授予相机权限,不应该影响与相机无关的功能操作,如语音通话。 -- 用户在产品使用过程中,针对录入个人数据的场景,需要给用户提供对个人数据的增加、删除、修改、查看的操作。 -- 需要给出硬件回收或返厂进行安全删除个人数据的机制或方法。 -- 对用户系统软件、应用软件的下载或升级,涉及修改用户隐私空间,用户对于这类行为需要有知情权和控制权,必须给用户提示,并提供给用户同意和取消的选项。 - -**数据安全** - -从技术上保证数据处理活动的安全性,包括个人数据的加密存储、安全传输等安全机制,系统应默认开启或采取安全保护措施。 - -- 对于个人数据的访问需要有保护机制,主要包括身份认证和访问控制。身份认证(如用户名、密码)限定只有经过认证的用户才能访问数据,可应用于多用户场景;访问控制(如[权限控制](/pages/01030102#li201725506375))可应用于对应用程序的限制。 -- 分布式设备个人数据安全存储要满足密钥管理和存储服务(HUKS:Huawei Universal Keystore)的要求,包括:密钥安全存储、数据安全存储。 -- 个人数据在分布式设备间传输要满足设备间的信任绑定关系和数据传输通道的安全性要求。详细信息可以参考[设备互联安全](/pages/01030102#section26153183616)。 -- 认证凭证数据(密码、口令、指纹等)须加密存储。 - -**本地化处理** - -用户数据优先在本设备进行处理,对于本设备无法处理的数据应尽可能在超级终端设备本地进行数据的处理,如果超级终端本地处理无法满足业务目的的,在数据离开超级终端设备本地时应尽可能选择匿名化。 - -**未成年人数据保护要求** - -产品专门给未成年人设计的,或者产品收集用户年龄从而可以识别到是在收集未成年人的个人数据,需结合目标市场国家的法律,专门分析未成年人个人数据保护的问题,收集未成年人数据前需要征得监护人的同意。 - -## 特殊品类要求 - -针对消费者硬件产品来说,除了满足以上的通用隐私要求以外,针对特殊品类的产品还有以下的特殊要求,在产品设计过程中参照执行。 - -**表2** 特殊品类隐私要求 - - - - - - - - - - - - - - - - - - - - - - - - - -

产品品类

-

隐私保护特殊要求

-

智能家居

-

安防类产品涉及的指纹、声纹、面部识别、虹膜等个人生物识别信息以及用户密码信息,属于敏感个人数据,应采用技术措施处理后(例如提取个人生物识别信息的摘要)再进行加密保存在产品本地。

-

智能家居

-

安防类产品涉及的音视频和图片,设备厂家作为数据控制者时,必须提供独立的隐私通知、应用界面必须有设备厂家品牌标识;音视频数据的传输和存储必须加密,非用户本人访问安防产品的音视频数据,必须获得用户授权。

-

智能家居/影音娱乐

-

带有摄像头的产品建议提供物理上可关闭功能,通过隐藏、遮盖、转向让消费者感知摄像头处于关闭状态。

-

智能家居/影音娱乐

-

带有麦克风的产品建议提供显性显示录音的状态,如录音开启时状态灯闪烁,录音关闭时状态灯熄灭。

-

移动办公

-

用户数据跨设备显示、传输等场景需要获得消费者的明示同意,给予消费者对其个人数据有充分的控制权。

-

车机

-

1、隐私通知及权限设置

-

避免在驾驶态让用户阅读隐私政策和权限设置。

-

车机应用需要考虑车辆使用时的安全性,应避免让用户在驾驶过程中进行复杂的权限设置或阅读隐私政策,比如HiCar应用应该在手机端完成应用基本权限设置和隐私政策阅读后再进行使用。

-

隐私声明在确认用户身份后告知。

-

车辆的数据会涉及车主、驾驶员和乘客,应保证隐私声明通知到了数据主体本人。建议做法是在确认使用者的身份后进行隐私声明,如需要用户登录的应用,应在账号登录后弹出隐私声明而不是账号登录之前。

-

2、共享应用个人数据保护

-

共享应用在车机重启后应退出,并对当前用户个人数据进行清除或加密,应用还应提供对历史数据进行彻底删除的功能。

-

3、消息提示

-

考虑车机的开放环境,应用在车机上进行消息提醒时,应避免直接将消息内容显示在车机上,正确的做法是仅提示有新的消息需要查看。

-
- diff --git "a/website/docs/01.OpenHarmony/03.\345\205\274\345\256\271\346\200\247\344\270\216\345\256\211\345\205\250/01.\351\232\220\347\247\201\344\270\216\345\256\211\345\205\250\350\247\204\350\214\203/02.\345\256\211\345\205\250\346\214\207\345\215\227.md" "b/website/docs/01.OpenHarmony/03.\345\205\274\345\256\271\346\200\247\344\270\216\345\256\211\345\205\250/01.\351\232\220\347\247\201\344\270\216\345\256\211\345\205\250\350\247\204\350\214\203/02.\345\256\211\345\205\250\346\214\207\345\215\227.md" deleted file mode 100644 index 45b467f975196d1443f8b49d95eed760dbb1440b..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/03.\345\205\274\345\256\271\346\200\247\344\270\216\345\256\211\345\205\250/01.\351\232\220\347\247\201\344\270\216\345\256\211\345\205\250\350\247\204\350\214\203/02.\345\256\211\345\205\250\346\214\207\345\215\227.md" +++ /dev/null @@ -1,288 +0,0 @@ ---- -title: 安全指南 -permalink: /pages/01030102 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 安全指南 - -- [安全概述](#section1521410017353) -- [硬件安全](#section2558121318351) - - [安全机制](#section1399511541896) - - [推荐做法](#section948519243104) - -- [系统安全](#section87802111361) - - [安全机制](#section149107611118) - - [推荐做法](#section1364122019112) - -- [数据安全](#section2468927364) - - [安全机制](#section1378993720111) - - [推荐做法](#section1531735481112) - -- [设备互联安全](#section26153183616) -- [应用安全](#section852593153614) - - [安全机制](#section55012136125) - - [推荐做法](#section6341102610123) - - -## 安全概述 - -OpenHarmony操作系统是一个开放的系统,开发者可以通过OpenHarmony开发灵活的服务和应用,为开发者和使用者带来便利和价值。为了达到这一目的,OpenHarmony提供了一个可以有效保护应用和用户数据的执行环境。 - -在这个执行环境中,芯片的安全能力、系统的安全能力、以及上层的安全服务一起协作,从硬件安全、系统安全、数据安全、设备互联安全、应用安全、安全更新多个维度提供安全保障。 - -**图 1** 安全保障示意图 -![](/images/device-dev/security/figure/安全保障示意图.png "安全保障示意图") - -## 硬件安全 - -### 安全机制 - -- 启动可信根 - - OpenHarmony设备采用PKI(Public Key Infrastructure)体系保护软件完整性,确保设备运行来源合法、软件未被篡改。 - - 在设备启动流程中,逐级进行软件签名校验形成安全启动链,任何一个环节的签名校验不通过即终止设备启动;安全启动链中最初执行签名校验的软硬件实体,需确保自身的合法、未被篡改。该实体即为设备的启动可信根。启动可信根可为固化在ROM中的一段代码,这段代码在芯片制造环节固化到芯片中,芯片制造完成后软件不可更改,在设备上电初始化的过程中,最先执行这段ROM中的代码,并由这段ROM代码执行后续的软件签名校验。 - - ROM中的代码在执行签名校验时,需确保用于校验的PKI公钥的合法性,OpenHarmony设备可采用eFuse/OTP等存储介质来存储公钥(如公钥哈希值),来保护公钥自身的合法性。公钥一般在设备制造环节,烧录到设备的eFuse/OTP中。 - -- 硬件隔离可信环境 - - 硬件隔离的可信环境,遵循了可信计算系统的设计理念。可信环境内外形成了两个世界:可信世界与不可信世界,两者之间存在清晰而明确的隔离边界;OpenHarmony设备在可信环境中实现了核心敏感数据的保护机制,可确保即使不可信世界的操作系统存在漏洞且被利用,也依然能确保可信环境中敏感数据的安全。 - - OpenHarmony设备的可信环境,基于硬件的安全隔离机制构建,在不同的OpenHarmony设备上芯片隔离机制略有差异,较为通用的方法是采用ARM的TrustZone技术。在部分Risc-V芯片平台上,也可能采用独立安全核的形式来构建可信环境。 - - 可信环境中,运行特定的、精简的操作系统iTrustee lite,用于管理可信环境的资源和任务调度,给OpenHarmony设备提供安全服务。密钥管理及数据安全,是可信环境中最为常见的安全服务,设备在eFuse/OTP中存有硬件唯一根密钥,可信环境可基于该密钥结合业务上下文衍生出多种密钥,给应用提供密钥管理和数据加解密相关的服务;设备核心密钥生命周期不离开可信环境。可信环境同样可提供身份认证、系统状态监控、数据安全存储等安全服务,提高设备安全性。 - -- 硬件密钥引擎 - - 密码学是信息安全的基础。数据加解密对计算机设备的核心诉求是:高效、安全。硬件加解密技术利用计算机硬件辅助软件,甚至直接取代软件,来处理数据的加解密。相比由软件实现的加解密计算,硬件实现的加解密计算更高效、更安全。 - - 由硬件来实现加解密处理,意味着部分专用的硬件资源会用于处理加解密计算任务,当加解密引擎工作的时候CPU可以并发地继续执行其他计算任务,因此硬件加解密引擎可以带来极大的性能提升,同时降低CPU负载。此外,硬件密钥引擎可以带来更高的安全性,设计良好的硬件密钥引擎,哪怕软件被攻破也依然可保护密钥不泄露,甚至可对抗电磁、辐射等物理侧信道攻击。 - - OpenHarmony设备支持硬件密钥引擎,支撑OpenHarmony系统进行数据加解密、证书验签、哈希计算等计算任务,可支持AES/RSA等主流的密码学算法。 - - -### 推荐做法 - -- 启动可信根可由一段固化在芯片中的代码和设备根密钥组成,前者一般在芯片制造阶段写入,设备生命周期内不可更改,负责在启动阶段校验设备软件证书;后者则是用于设备证书签名的私钥相对应的公钥,证书签名私钥不出PKI签名服务器,而公钥则需写入设备。为防止攻击者篡改公钥从而达到绕过签名认证的目的,写入OpenHarmony设备的公钥须确保不可篡改,可将公钥信息写入如熔丝等介质;考虑到熔丝空间有限,可仅存储公钥的哈希值,并由启动代码校验公钥的合法性。 -- 可信执行环境较为通用的做法是基于ARM TrustZone技术构建,也可根据设备的实际形态选择其他隔离机制,如TrustZone-M、独立安全核等;可信执行环境中须部署TEE OS,用于管理可信执行环境的资源及任务调度。OpenHarmony系统提供iTrustee作为TEE OS的解决方案,开发者及设备商可基于iTrustee开发并部署安全业务。 - - 并非所有OpenHarmony设备都强制要求支持可信执行环境,部分运行低敏感业务的瘦资源设备可不做强制要求;可根据实际业务场景选择是否支持可信执行环境,以及实现怎样的可信执行环境。 - -- 硬件密钥引擎须提供真随机数、公钥、对称密钥、哈希等密钥算法能力,通过在OpenHarmony系统中部署相应的驱动程序,给应用提供统一的密钥管理及密钥算法服务。 - -## 系统安全 - -### 安全机制 - -对于128KB\~128MB内存的设备,推荐使用OpenHarmony轻内核组件,在该内核下: - -- 进程隔离 - - 进程隔离是为了防止A进程读写B进程内存数据的情况发生,进程的隔离技术,一般都采用虚拟地址空间映射方式,通过MMU配置,进程A的虚拟地址和进程B的虚拟地址映射各自不同的实际的物理地址段,这样A进程通过访问虚拟地址访问的实际内存数据在非共享内存的情况下,只属于A进程,B进程无法直接访问。 - - OpenHarmony由于资源有限,对于内核态和用户态的进程采用不同的方式:所有的内核态进程共享同一块VMM空间,即所有的内核态进程之间无隔离,系统启动时内核态创建两个基本进程KProcess和KIdle,KProcess进程为内核态进程的根进程,KIdle进程为KProcess进程的子进程;但是对于每一个用户态进程均拥有自己独立的VMM空间,相互之间不可见,实现进程间隔离。 - -- 自主访问控制 - - 自主访问控制DAC(Discretionary Access Control)的思想是文件权限由文件拥有者来决定其他角色的访问权限。权限管控粒度分为三类:user\(自身\), group\(组员\),other\(其他人\),即UGO。将任意用户分类为UGO中三者之一,并采取相应的管控策略,即完成了DAC权限校验流程。 - - DAC机制依赖于进程的uid、gid等属性,需要以此作为文件创建以及文件访问过程中的特征id。文件创建时,创建者将自身uid写入文件,文件访问时,又以此作为文件归属的分类依据。 - - 每一个应用,对应一个uid。应用在创建文件时,将自身uid信息加入被创建文件的元数据\(metadata\)中,并设置UGO三个组的权限。在文件访问过程中,将以访问者uid作为访问校验主体、以文件元数据中的uid权限信息作为客体,进行权限校验。 - - 下图描述了DAC在文件访问时的鉴权过程,首先匹配进程uid和文件uid属性,其次匹配进程gid和文件gid属性,最后都匹配失败的情况,判断文件other属性是否支持进程的读、写、执行操作。同时支持忽略DAC检测机制(读、写、执行)作为一组系统特权(Capability),支持高权限(如系统服务)对低权限(三方APP)的文件管理。 - - **图 2** DAC流程图 - ![](/images/device-dev/security/figure/DAC流程图.png "DAC流程图") - -- Capability机制 - - Capability机制实际上是对root权限的具体细分。在多用户计算机系统中,一般会有一个特殊的角色拥有系统的所有权限,这个角色一般是系统管理员\(root\)。对于OpenHarmony这种需要支持三方应用生态的内核,需要将系统中的特权访问进行管控。系统需要对用户层访问内核的特权级系统调用进行限制。仅允许部分高权限应用进行特权操作。具体实现方式是内核spawn第一个用户程序INIT,其包含全部的特权能力,此后,INIT拉起其他应用框架服务,拉起过程中,对各应用框架进行相应的降权操作,为各应用保留必须的特权能力。 当应用去调用特权接口时,内核态就会通过进程ID查看当前访问者是否有权限访问目标接口。 - -- 安全启动 - - 安全启动是整个系统安全的基础,通过采用数字签名和完整性校验机制,从芯片内部固化的可信启动根开始,逐级校验每一层软件的完整性和合法性,确保最终启动的操作系统软件是厂家提供的正确合法的软件,防止攻击者对系统软件做恶意的篡改和植入,为整个系统提供初始安全的基础运行环境。 - - 在芯片上电后,由于片上ROM代码本身不可更改,因此无需校验;片上ROM基于eFuse中的非对称算法公钥hash对bootloader进行校验。这些过程都基于硬件信任根来进行,是完全可信的。经过此过程校验通过的bootloader模块可以作为后续的信任基础,此过程就是启动信任链的构造过程。Bootloader通常首先对执行环境进行一定的初始化,主要是初始化DDR以及flash读写,为进一步加载后续模块以及执行更为复杂的逻辑进行准备。Bootloader完成初始化动作后,首先完成x509证书的完整性校验,然后利用x509证书的公钥对需要校验的镜像包(kernel.bin、teeOS.bin、rootfs.bin)进行校验。 - - -### 推荐做法 - -- 自主访问控制和Capability机制是控制资源被谁可以访问的机制,建议所有权限设置都采用最小权限原则。 -- 安全启动必须要开启,信任根必须是基于芯片的不可更改的形式存在,并且在有安全升级的情况下,必须考虑安全升级后对于安全启动的影响,也就是安全升级后必须要更新对应镜像文件的签名信息或者hash值。 - -## 数据安全 - -### 安全机制 - -HUKS(Huawei Universal Keystore Service),提供了密钥管理、证书管理服务,当前在OpenHarmony上主要提供密钥管理服务,用于支撑HiChain\(设备身份认证平台\)的基础设备认证。如下是HUKS的功能结构图: - -**图 3** HUKS功能结构图 -![](/images/device-dev/security/figure/HUKS功能结构图.png "HUKS功能结构图") - -支持算法包括: - -- 认证加密:AES-128/192/256-GCM -- 签名验签:ED25519 -- 密钥协商:X25519 -- 消息认证:HMAC-SHA256/512 -- 数据摘要:SHA256/512 - -HUKS在使用中有如下约束: - -- 密钥安全存储:密钥要求存储于安全存储区域,数据不可以修改,恢复出厂设置时出厂预置的密钥不能被删除。 -- 密钥访问安全:OpenHarmony通过将不同应用数据保存在不同的位置,来实现应用间数据的隔离。通过参数结构体中包含UID和进程ID,来实现不同应用间的数据隔离。 -- 不支持并发访问:HUKS本身不考虑多个应用同时调用的情况,因为HUKS只是一个lib库,也不考虑资源的互斥。如果有多个应用都会用到HUKS服务,那么应该由每个应用各自链接一份HUKS库,并由业务传入持久化数据存储的路径,以实现应用间的数据存储分开。数据存储在各应用各自存储目录下。 - -### 推荐做法 - -对于设备认证功能,建议使用HiChain来对接HUKS,HUKS可以向HiChain等应用提供密钥的产生、导入、导出、加密/解密、存储、销毁,证书的导入和查询,秘密信息的存储等能力。 - -## 设备互联安全 - -为了实现用户数据在设备互联场景下在各个设备之间的安全流转,需要保证设备之间相互正确可信,即设备和设备之间建立信任关系,并能够在验证信任关系后,搭建安全的连接通道,实现用户数据的安全传输。设备之间的信任关系在本文档中涉及IoT主控设备和IoT设备之间建立的可信关系。设备间可信关系建立的流程如下图所示: - -**图 4** 设备间建立可信关系流程图 -![](/images/device-dev/security/figure/设备间建立可信关系流程图.png "设备间建立可信关系流程图") - -- **IoT设备互联安全** - - 设备互联支持基于OpenHarmony的IoT设备(如AI音箱、智能家居、智能穿戴等设备)与IoT主控设备间建立点对点的信任关系,并在具备信任关系的设备间,搭建安全的连接通道,实现用户数据端到端加密传输。 - - -- **IoT主控设备的IoT业务身份标识** - - IoT主控设备为不同的IoT设备管理业务生成不同的身份标识,形成不同IoT管理业务间的隔离,该标识用于IoT主控设备与IoT设备之间的认证以及通信。IoT业务身份标识为椭圆曲线公私钥对(Ed25519公私钥对)。 - - -- **IoT设备身份标识** - - IoT设备会生成各自的设备身份标识,用来与IoT主控设备通信。该身份标识同样为椭圆曲线公私钥对(Ed25519公私钥对);IoT设备私钥不出IoT设备,设备每次恢复出厂设置,会重置这个公私钥对。 - - 上述身份标识可用于IoT主控设备与IoT设备间的安全通信:当IoT主控设备与IoT设备通过信任绑定流程交换业务身份标识或设备标识后,可以进行密钥协商并建立安全通信通道。 - - -- **设备间点对点的信任绑定** - - IoT主控设备和IoT设备建立点对点信任关系的过程,实际上是相互交换IoT设备的身份标识的过程。 - - 在点对点建立信任关系的过程中,用户需要在IoT主控设备上,输入IoT设备上提供的PIN码:对于有屏幕的设备,该PIN码动态生成;对于没有屏幕的设备,该PIN码由设备生产厂家预置;PIN码的展示形式,可以是一个用户可读的数字,也可以是一个二维码。随后,IoT主控设备和IoT设备间使用PAKE协议完成认证和会话密钥协商过程,并在此基础上,通过协商出的会话密钥加密传输通道用于交换双方设备的身份标识公钥。 - - -- **IoT主控设备与IoT设备间的通信安全** - - 当建立过信任关系的IoT主控设备与IoT设备间进行通信时,双方在完成上述信任关系绑定后,基于本地存储的对端身份公钥相互进行认证;在每次通信时基于STS协议完成双向身份认证以及会话密钥协商,之后设备使用此会话密钥加密双方设备间的传输通道。 - - -## 应用安全 - -### 安全机制 - -- 应用签名管控 - - OpenHarmony应用的安装需要首先对包的完整性进行校验,具体策略是在开发阶段完成开发和调试后对安装包进行签名,这个签名需要使用指定的私钥,这个私钥就是跟验签用的公钥是一对的,一般的做法是OEM厂商生成一对公私钥,然后将公钥信息预置到设备中,而私钥就放在一个不联网的本地服务器上,这样可以确保私钥被泄露的风险尽量小,而应用在完成开发后就可以通过外置设备(例如USB)上传安装包到存放私钥的服务器上计算签名并下载签名结果到外置设备上。而安装应用时首先计算包的Hash值,一般采用SHA256算法,然后使用hash值和签名信息以及预置公钥进行验签,只有验签通过的应用才能安装。 - - 除了要证明应用来自云端认证过的,还需要证明来源,即这个应用来自合法开发者开发的,具体做法是,开发者向云端申请开发证书,开发完成后,用开发证书进行自签名,设备端存放这个证书的上一级证书,所以安装过程中,对自签名信息做校验,确保开发者的合法性。 - -- 应用权限控制 - - 由于OpenHarmony系统允许安装三方应用,所以需要对三方应用的敏感权限调用进行管控,具体实现是应用在开发阶段就需要在profile.json中指明此应用在运行过程中可能会调用哪些敏感权限,这些权限包括静态权限和动态权限,静态权限表示只需要在安装阶段注册就可以,而动态权限一般表示获取用户的敏感信息,所以需要在运行时让用户确认才可以调用,授权方式包括系统设置应用手动授权等。除了运行时对应用调用敏感权限进行管控外,还需要利用应用签名管控手段确保应用安装包已经被设备厂商进行了确认。 - - **表 1** **OpenHarmony系统权限列表** - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

OpenHarmony系统权限

-

授权方式

-

权限说明

-

ohos.permission.LISTEN_BUNDLE_CHANGE

-

system_grant(静态权限)

-

允许该应用获取应用变化消息。

-

ohos.permission.GET_BUNDLE_INFO

-

system_grant(静态权限)

-

允许该应用获取应用信息。

-

ohos.permission.INSTALL_BUNDLE

-

system_grant(静态权限)

-

允许该应用安装应用。

-

ohos.permission.CAMERA

-

user_grant(动态权限)

-

此应用可随时使用相机拍摄照片和录制视频。

-

ohos.permission.MODIFY_AUDIO_SETTINGS

-

system_grant(静态权限)

-

允许该应用修改全局音频设置,例如音量和用于输出的扬声器。

-

ohos.permission.READ_MEDIA

-

user_grant(动态权限)

-

允许该应用读取您的视频收藏。

-

ohos.permission.MICROPHONE

-

user_grant(动态权限)

-

此应用可随时使用麦克风进行录音。

-

ohos.permission.WRITE_MEDIA

-

user_grant(动态权限)

-

允许该应用写入您的音乐收藏。

-

ohos.permission.DISTRIBUTED_DATASYNC

-

user_grant(动态权限)

-

管控分布式数据传输能力。

-

ohos.permission.DISTRIBUTED_VIRTUALDEVICE

-

user_grant(动态权限)

-

允许应用使用分布式虚拟能力

-
- - -### 推荐做法 - -开发者在开发过程中需明确后续应用在运行时需要运行哪些权限,并在profile.json中进行注册,然后需要对应用进行签名,确保设备在安装这些应用时能对应用的完整性和来源进行校验。 - diff --git "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/01.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/01.\347\247\273\346\244\215\345\207\206\345\244\207/01.\347\247\273\346\244\215\351\241\273\347\237\245.md" "b/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/01.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/01.\347\247\273\346\244\215\345\207\206\345\244\207/01.\347\247\273\346\244\215\351\241\273\347\237\245.md" deleted file mode 100644 index f80c77e190a0a77dd9538bde56b0fdc4071b205a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/01.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/01.\347\247\273\346\244\215\345\207\206\345\244\207/01.\347\247\273\346\244\215\351\241\273\347\237\245.md" +++ /dev/null @@ -1,97 +0,0 @@ ---- -title: 移植须知 -permalink: /pages/0104010101 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 移植须知 - -- [移植目录](#section284217487490) -- [移植流程](#section639315306506) -- [移植规范](#section187870185219) - -本文为OpenHarmony平台系统开发人员和芯片(或模组)制造商提供基础的开发移植指导,典型的芯片架构例如cortex-m系列、risc-v系列等都可以按照本文进行移植,暂时不支持蓝牙服务。OpenHarmony是个持续演进的复杂项目,随着版本和API的改变,本文将会不断更新。 - -本文要求读者具有一定的嵌入式系统开发经验,因此它的重点未放在基本的OS基础介绍,而更多地描述OpenHarmony平台移植过程中主要操作和所需要关注的方面。 - -## 移植目录 - -OpenHarmony整体工程较为复杂,目录及实现为系统本身功能,如果不涉及复杂的特性增强,不需要关注每一层实现,移植过程中重点关注如下目录即可: - -**表 1** 移植过程中的重点目录 - - - - - - - - - - - - - - - - - - - -

目录名称

-

描述

-

/build/lite

-

OpenHarmony基础编译构建框架

-

/kernel/liteos_m

-

基础内核,其中芯片架构相关实现在arch目录下

-

/device

-

板级相关实现,各个三方厂商按照OpenHarmony规范适配实现,device下具体目录结构及移植过程参见板级系统移植

-

/vendor

-

产品级相关实现,主要由华为或者产品厂商贡献

-
- -device目录规则:device/\{芯片解决方案厂商\}/\{开发板\}。以hisilicon的hispark\_taurus为例: - -``` -device -└── hisilicon # 芯片解决方案厂商名 - ├── common # 芯片解决方案开发板公共部分 - └── hispark_taurus # 开发板名称 - ├── BUILD.gn # 开发板编译入口 - ├── hals # 芯片解决方案厂商OS硬件适配 - ├── linux # linux版本 - │ └── config.gni # linux版本编译工具链和编译选项配置 - └── liteos_a # liteos-a版本 - └── config.gni # liteos-a版本编译工具链和编译选项配置 -``` - -vendor目录规则:vendor/\{产品解决方案厂商\}/\{产品名称\}。以华为的wifiiot产品为例: - -``` -vendor # 产品解决方案厂商 -└── huawei # 产品解决方案厂商名称 - └── wifiiot # 产品名称 - ├── hals # 产品解决方案厂商OS适配 - ├── BUILD.gn # 产品编译脚本 - └── config.json # 产品配置文件 -``` - -## 移植流程 - -OpenHarmony的device目录是基础芯片的适配目录,如果在三方芯片应用过程中发现此目录下已经有完整的芯片适配,则不需要再额外移植,直接跳过移植过程进行系统应用开发即可,如果该目录下无对应的芯片移植实现,则根据本文完成移植过程。OpenHarmony三方芯片移植主要过程如下: - -**图 1** 芯片移植关键步骤 -![](/images/device-dev/porting/figure/芯片移植关键步骤.png "芯片移植关键步骤") - -## 移植规范 - -- 满足OpenHarmony[开源贡献基本规范和准则](/pages/010d01)。 -- 三方芯片适配所需要贡献的代码主要在device、vendor和arch三个目录,参照[内核目录规范](/pages/0104010201)和[板级目录规范](/pages/0104010301#section6204129143013)满足基本目录命名和使用规范。 - diff --git "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/01.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/01.\347\247\273\346\244\215\345\207\206\345\244\207/02.\347\274\226\350\257\221\346\236\204\345\273\272\351\200\202\351\205\215\346\265\201\347\250\213.md" "b/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/01.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/01.\347\247\273\346\244\215\345\207\206\345\244\207/02.\347\274\226\350\257\221\346\236\204\345\273\272\351\200\202\351\205\215\346\265\201\347\250\213.md" deleted file mode 100644 index a96c61f82dd5ca31503bebcf991821d942def70b..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/01.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/01.\347\247\273\346\244\215\345\207\206\345\244\207/02.\347\274\226\350\257\221\346\236\204\345\273\272\351\200\202\351\205\215\346\265\201\347\250\213.md" +++ /dev/null @@ -1,133 +0,0 @@ ---- -title: 编译构建适配流程 -permalink: /pages/0104010102 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 编译构建适配流程 - -- [编译构建适配流程](#section2159183845319) - -编译构建的详细介绍请见[编译构建子系统介绍](/pages/01050301)。新增三方芯片时,编译相关的适配流程如下: - -## 编译构建适配流程 - -首先,创建开发板目录,以芯片解决方案厂商realtek的“rtl8720“开发板为例,需创建device/realtek/rtl8720目录。编译相关的适配步骤如下: - -1. 编译工具链和编译选项配置。 - - 构建系统默认使用ohos-clang编译工具链,也支持芯片解决方案厂商按开发板自定义配置。开发板编译配置文件编译相关的变量如下: - - - kernel\_type: 开发板使用的内核类型,例如:"liteos\_a", "liteos\_m", "linux"。 - - kernel\_version: 开发使用的内核版本,例如:"4.19"。 - - board\_cpu: 开发板CPU类型,例如:"cortex-a7", "riscv32"。 - - board\_arch: 开发芯片arch, 例如: "armv7-a", "rv32imac"。 - - board\_toolchain: 开发板自定义的编译工具链名称,例如:"gcc-arm-none-eabi"。若为空,则使用默认为ohos-clang。 - - board\_toolchain\_prefix:编译工具链前缀,例如:"gcc-arm-none-eabi"。 - - board\_toolchain\_type:编译工具链类型,目前支持gcc和clang。例如:"gcc" ,"clang"。 - - board\_cflags:开发板配置的c文件编译选项。 - - board\_cxx\_flags:开发板配置的cpp文件编译选项。 - - board\_ld\_flags:开发板配置的链接选项。 - - 编译构建会按产品的选择的开发板,加载对应的config.gni,该文件中变量对系统组件全局可见。 - - 以芯片解决方案厂商realtek的“rtl8720“开发板为例,device/realtek/rtl8720/liteos\_m/config.gni的内容如下: - - ``` - # Kernel type, e.g. "linux", "liteos_a", "liteos_m". - kernel_type = "liteos_m" - - # Kernel version. - kernel_version = "3.0.0" - - # Board CPU type, e.g. "cortex-a7", "riscv32". - board_cpu = "real-m300" - - # Board arch, e.g. "armv7-a", "rv32imac". - board_arch = "" - - # Toolchain name used for system compiling. - # E.g. gcc-arm-none-eabi, arm-linux-harmonyeabi-gcc, ohos-clang, riscv32-unknown-elf. - # Note: The default toolchain is "ohos-clang". It's not mandatory if you use the default toochain. - board_toolchain = "gcc-arm-none-eabi" - - # The toolchain path instatlled, it's not mandatory if you have added toolchian path to your ~/.bashrc. - board_toolchain_path = - rebase_path("//prebuilts/gcc/linux-x86/arm/gcc-arm-none-eabi/bin", - root_build_dir) - - # Compiler prefix. - board_toolchain_prefix = "gcc-arm-none-eabi-" - - # Compiler type, "gcc" or "clang". - board_toolchain_type = "gcc" - - # Board related common compile flags. - board_cflags = [] - board_cxx_flags = [] - board_ld_flags = [] - ``` - -2. 开发板编译脚本。 - - 新增的开发板,对应目录下需要新增BUILD.gn文件作为开发板编译的总入口。以芯片解决方案厂商realtek的rtl8720开发板为例,对应的device/realtek/rtl8720/BUILD.gn为: - - ``` - group("rtl8720") { - ... - } - ``` - -3. 编译调试开发板。 - - 1. 任意目录执行hb set按提示设置源码路径和要编译的产品。 - - 2. 在开发板目录下执行hb build, 即可启动开发板的编译。 - -4. 编译调试产品 - - 将开发板和组件信息写入产品配置文件,该配置文件字段说明如下: - - - product\_name:产品名称,支持自定义,建议与vendor下的三级目录名称一致。 - - ohos\_version:OpenHarmony版本号,应与实际下载的版本一致。 - - device\_company:芯片解决方案厂商名称,建议与device的二级目录名称一致。 - - board:开发板名称,建议与device的三级级目录名称一致。 - - kernel\_type:内核类型,应与开发板支持的内核类型匹配。 - - kernel\_version:内核版本号,应与开发板支持的内核版本匹配。 - - subsystem:产品选择的子系统,应为OS支持的子系统,OS支持的子系统请见build/lite/components目录下的各子系统描述文件。 - - components:产品选择的某个子系统下的组件,应为某个子系统支持的组件,子系统支持的组件请见build/lite/components/子系统.json文件。 - - features:产品配置的某个组件的特性,组件支持的特性请见build/lite/components/子系统.json中对应组件的features字段。 - - 以基于“rtl8720“开发板的wifiiot模组为例,vendor/my\_company/wifiiot/config.json如下: - - ``` - { - "product_name": "wifiiot", # 产品名称 - "ohos_version": "OpenHarmony 1.0", # 使用的OS版本 - "device_company": "realtek", # 芯片解决方案厂商名称 - "board": "rtl8720", # 开发板名称 - "kernel_type": "liteos_m", # 选择的内核类型 - "kernel_version": "3.0.0", # 选择的内核版本 - "subsystems": [ - { - "subsystem": "kernel", # 选择的子系统 - "components": [ - { "component": "liteos_m", "features":[] } # 选择的组件和组件特性 - ] - }, - ... - { - 更多子系统和组件 - } - ] - } - ``` - - diff --git "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/01.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/02.\345\206\205\346\240\270\347\247\273\346\244\215/01.\347\247\273\346\244\215\346\246\202\350\277\260.md" "b/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/01.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/02.\345\206\205\346\240\270\347\247\273\346\244\215/01.\347\247\273\346\244\215\346\246\202\350\277\260.md" deleted file mode 100644 index fdfe2f315dfd3f9775ed68e0cc225c8b6824f784..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/01.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/02.\345\206\205\346\240\270\347\247\273\346\244\215/01.\347\247\273\346\244\215\346\246\202\350\277\260.md" +++ /dev/null @@ -1,75 +0,0 @@ ---- -title: 移植概述 -permalink: /pages/0104010201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 移植概述 - -- [移植场景](#section93781277367) -- [目录规范](#section18127744153119) -- [芯片架构适配点](#section137431650339) - -## 移植场景 - -芯片架构适配是可选过程,如果在liteos\_m/arch目录下已经支持对应芯片架构,则可以跳过芯片架构适配,进行单板适配过程,否则需要进行芯片架构移植工作。 - -## 目录规范 - -模组芯片使用的内核为liteos-m,liteos-m中主要分为KAL、Components、Kernel和Utils四个模块。 - -- KAL模块作为内核对外的接口依赖Components模块和Kernel模块。 -- Components模块可插拔,它依赖Kernel模块。 - -- 在Kernel模块中,其中硬件相关的代码放在kernel的arch目录中,其余为硬件无关的代码。内核功能集(task、sem等)的实现依赖硬件相关的arch代码,例如任务上下文切换、原子操作等。 -- Utils模块作为基础代码块,被其他模块依赖。 - -**图 1** liteos-m内核模块图 -![](/images/device-dev/porting/figure/liteos-m内核模块图.png "liteos-m内核模块图") - -内核的目录结构和说明如下: - -``` -. -├── arch --- 内核指令架构层代码 -│ ├── arm --- arm32架构的代码 -│ │ ├── cortex-m3 --- cortex-m3架构的代码 -│ │ │ ├── iar --- iar编译工具链实现 -│ │ │ ├── keil --- keil编译工具链实现 -│ │ │ └── xxx --- xxx编译工具链实现 -│ │ └── cortex-m4 --- cortex-m4架构的代码 -│ │ ├── iar --- iar编译工具链实现 -│ │ ├── keil --- keil编译工具链实现 -│ │ └── xxx --- xxx编译工具链实现 -│ ├── include --- 所有的arch需要实现的函数定义,内核依赖 -│ └── risc-v --- risk-v架构 -│ └── gcc --- gcc编译工具链实现 -├── components --- 移植可选组件,依赖内核,单独对外提供头文件 -├── kal --- 内核抽象层,提供内核对外接口,当前支持cmsis接口和部分posix接口 -├── kernel --- 内核最小功能集代码 -│ ├── include --- 内核最小功能集代码 -│ └── src --- 内核最小功能集代码 -└──utils --- 基础代码,作为依赖的最底层,被系统依赖 -``` - -## 芯片架构适配点 - -如内核的[目录结构](#section18127744153119)所示,arch/include定义通用的芯片架构所需要实现的函数,另外芯片架构相关的代码会有部分的汇编代码,而汇编代码会因编译工具链的不同而不同,因此在具体的芯片架构下,还包含不同工具链(iar、keil、gcc等)的实现。 - -arch/include 目录定义通用的文件以及函数列表,该目录下的所有函数在新增arch组件时都需要适配,详见每一个头文件: - -``` -los_arch.h --- 定义芯片架构初始化所需要的函数 -los_atomic.h --- 定义芯片架构所需要实现的原子操作函数 -los_context.h --- 定义芯片架构所需要实现的任务上下文相关函数 -los_interrupt.h --- 定义芯片架构所需要实现的中断和异常相关的函数 -los_timer.h --- 定义芯片架构所需要实现的系统时钟相关的函数 -``` - diff --git "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/01.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/02.\345\206\205\346\240\270\347\247\273\346\244\215/02.\345\206\205\346\240\270\345\237\272\347\241\200\351\200\202\351\205\215.md" "b/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/01.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/02.\345\206\205\346\240\270\347\247\273\346\244\215/02.\345\206\205\346\240\270\345\237\272\347\241\200\351\200\202\351\205\215.md" deleted file mode 100644 index e5c19aad240bb44a22f79b3bcfca4e1e676187f8..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/01.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/02.\345\206\205\346\240\270\347\247\273\346\244\215/02.\345\206\205\346\240\270\345\237\272\347\241\200\351\200\202\351\205\215.md" +++ /dev/null @@ -1,99 +0,0 @@ ---- -title: 内核基础适配 -permalink: /pages/0104010202 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 内核基础适配 - -- [基础适配](#section14523241594) -- [特性配置项](#section112994366592) - -芯片架构适配完成后,liteos-m提供系统运行所需的系统初始化流程和定制化配置选项。移植过程中,需要关注初始化流程中跟硬件配置相关的函数;了解内核配置选项,才能裁剪出适合单板的最小内核。 - -## 基础适配 - -如下图所示,基础适配主要分为以下两步: - -1. 启动文件startup.S和相应链接配置文件。 -2. main. c中的串口初始化和tick中断注册。 - -**图 1** 启动流程 -![](/images/device-dev/porting/figure/启动流程.png "启动流程") - -启动文件startup.S需要确保中断向量表的入口函数(例如reset\_vector)放在RAM的首地址,它由链接配置文件来指定。其中iar、keil和gcc工程的链接配置文件分别为xxx.icf、xxx.sct和xxx.ld,如果startup.S已经完成系统时钟初始化,并且能够引导到main函数,则启动文件不需要进行修改,采用厂商自带的startup.S即可,否则需要实现以上功能。 - -在main.c文件中,需要关注串口初始化UartInit和系统Tick的handler函数注册。 - -- UartInit函数表示单板串口的初始化,具体的函数名根据单板自行定义。这个函数是可选的,用户可以根据硬件单板是否支持串口来自行选择调用该函数。如果硬件单板支持串口,则该函数需要完成使能串口TX和RX通道,设置波特率。 -- HalTickStart设置tick中断的handler函数OsTickHandler。 - -对于中断向量表不可重定向的芯片,需要关闭LOSCFG\_PLATFORM\_HWI宏,并且在startup.S中新增tick中断的handler函数。 - -## 特性配置项 - -liteos\_m的完整配置能力及默认配置在los\_config.h定义,该头文件中的配置项可以根据不同的单板进行裁剪配置。 - -如果针对这些配置项需要进行不同的板级配置,则可将对应的配置项直接定义到对应单板的device/xxxx/target\_config.h文件中,其他未定义的配置项,采用los\_config.h中的默认值。 - -一份典型的配置参数如下: - -**表 1** 内核典型配置项说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

配置项

-

说明

-

LOSCFG_BASE_CORE_SWTMR

-

软件定时器特性开关,1表示打开,0表示关闭

-

LOSCFG_BASE_CORE_SWTMR_ALIGN

-

对齐软件定时器特性开,1表示打开,依赖软件定时器特性打开,0表示关闭

-

LOSCFG_BASE_IPC_MUX

-

mux功能开关,1表示打开,0表示关闭

-

LOSCFG_BASE_IPC_QUEUE

-

队列功能开关,1表示打开,0表示关闭

-

LOSCFG_BASE_CORE_TSK_LIMIT

-

除idle task之外,总的可用task个数限制,可以根据业务使用的task个数来配置,也可以设置一个较大的值,待业务稳定了,查看运行task的个数来进行配置

-

LOSCFG_BASE_IPC_SEM

-

信号量功能开关,1表示打开,0表示关闭

-

LOSCFG_PLATFORM_EXC

-

异常特性开关,1表示打开,0表示关闭

-

LOSCFG_KERNEL_PRINTF

-

打印特性开关,1表示打开,0表示关闭

-
- diff --git "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/01.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/02.\345\206\205\346\240\270\347\247\273\346\244\215/03.\345\206\205\346\240\270\347\247\273\346\244\215\351\252\214\350\257\201.md" "b/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/01.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/02.\345\206\205\346\240\270\347\247\273\346\244\215/03.\345\206\205\346\240\270\347\247\273\346\244\215\351\252\214\350\257\201.md" deleted file mode 100644 index f8e094c2c362f2f21846f1ee839cc381740acb17..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/01.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/02.\345\206\205\346\240\270\347\247\273\346\244\215/03.\345\206\205\346\240\270\347\247\273\346\244\215\351\252\214\350\257\201.md" +++ /dev/null @@ -1,72 +0,0 @@ ---- -title: 内核移植验证 -permalink: /pages/0104010203 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 内核移植验证 - -在工程device目录下添加编译main.c示例程序文件,此示例程序的主要目的是:LOS\_KernelInit完成之后,创建两个任务,循环调度延时并打印日志信息,通过此方法可以验证系统是否可正常调度以及时钟是否正常。 - -``` -VOID TaskSampleEntry2(VOID) // 任务2的入口函数 -{ - while(1) { - LOS_TaskDelay(10000); - printf("taskSampleEntry2 running...\n"); - } -} - -VOID TaskSampleEntry1(VOID) // 任务1的入口函数 -{ - while(1) { - LOS_TaskDelay(2000); - printf("taskSampleEntry1 running...\n"); - } -} - -UINT32 TaskSample(VOID) -{ - UINT32 uwRet; - UINT32 taskID1,taskID2; - TSK_INIT_PARAM_S stTask1={0}; - stTask1.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskSampleEntry1; - stTask1.uwStackSize = 0X1000; - stTask1.pcName = "taskSampleEntry1"; - stTask1.usTaskPrio = 6; //stTask1的任务优先级设定,不同于stTask2 - uwRet = LOS_TaskCreate(&taskID1, &stTask1); - - stTask1.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskSampleEntry2; - stTask1.uwStackSize = 0X1000; - stTask1.pcName = "taskSampleEntry2"; - stTask1.usTaskPrio = 7; - uwRet = LOS_TaskCreate(&taskID2, &stTask1); - - return LOS_OK; -} - -LITE_OS_SEC_TEXT_INIT int main(void) -{ - UINT32 ret; - UartInit(); // 硬件串口配置,通过串口输出调试日志,实际函数名根据单板实现不一样而不一样。 - printf("\n\rhello world!!\n\r"); - ret = LOS_KernelInit(); - TaskSample(); - if (ret == LOS_OK) { - LOS_Start(); // 开始系统调度,循环执行stTask1/stTask2任务,串口输出任务日志 - } - while (1) { - __asm volatile("wfi"); - } -} -``` - -第一个任务运行正常后,说明最小系统的核心流程基本OK;由于xts用例框架对外依赖较多,主要是utils、bootstrap的链接脚本和编译框架,暂时无法支撑内核单独跑xts;此处略过内核测试套的测试,可以通过[XTS测试套](/pages/0104010307)来覆盖最小系统是否完整移植成功。 - diff --git "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/01.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/03.\346\235\277\347\272\247\347\263\273\347\273\237\347\247\273\346\244\215/01.\347\247\273\346\244\215\346\246\202\350\277\260.md" "b/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/01.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/03.\346\235\277\347\272\247\347\263\273\347\273\237\347\247\273\346\244\215/01.\347\247\273\346\244\215\346\246\202\350\277\260.md" deleted file mode 100644 index 8ad2c92218c054c2206e9ecaaf28adc662517d2a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/01.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/03.\346\235\277\347\272\247\347\263\273\347\273\237\347\247\273\346\244\215/01.\347\247\273\346\244\215\346\246\202\350\277\260.md" +++ /dev/null @@ -1,70 +0,0 @@ ---- -title: 移植概述 -permalink: /pages/0104010301 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 移植概述 - -- [板级移植流程](#section1283115812294) -- [板级目录规范](#section6204129143013) - -## 板级移植流程 - -最小系统移植完成后,下一步进行板级系统移植,板级系统移植包含以下几步操作: - -1. 板级驱动适配。 -2. HAL层实现。 -3. XTS测试套。 -4. 业务功能验证。 - -**图 1** 单板驱动适配流程 -![](/images/device-dev/porting/figure/单板驱动适配流程.png "单板驱动适配流程") - -## 板级目录规范 - -板级系统编译适配参考[编译系统介绍](/pages/0104010102),板级相关的驱动、SDK、目录、HAL实现存放在device目录,目录结构和具体描述如下: - -``` -. -├── device --- 单板样例 -│ └── xxx --- <单板厂商名> -│ └── xxx --- <单板名>,里面包含liteos-m内核的,并且能够运行的demo -│ ├── BUILD.gn --- 定义单板的编译配置文件 -│ ├── board --- 板子特定的实现(可选,如果本单板直接提供产品级demo,则相关应用层实现放在此目录) -│ ├── liteos_m --- 根据BUILD.gn文件中的kernel_type,使用liteos_m内核 -│ │ └── config.gni --- 编译选项 -│ ├── libraries --- 板级SDK -│ │ └── include --- SDK提供对外头文件 -│ │ └── ... --- binary or source -│ ├── main.c --- main函数入口(如果产品级存在相同定义,则使用产品级配置) -│ ├── target_config.h --- 板级内核配置 -│ ├── project --- 单板级工程配置文件(如果产品级存在相同定义,则使用产品级配置) -│ └── adapter --- 单板适配上层应用组件的适配层接口,根据能力可选 -│ └── hals -│ ├── communication -│ │ └── wifi_lite -│ │ ├── ... -│ └── iot_hardware -│ ├── upgrade -│ ├── utils -│ └── wifiiot_lite -├── vendor --- 提供端到端的OpenHarmony特性产品样例 -│ └── huawei --- 厂商名字 -│ └── wifiiot --- wifiiot表示特性产品 -│ ├── app -│ │ └── main.c --- 产品的main函数入口 -│ ├── project --- 工程配置文件 -│ ├── BUILD.gn --- 工程编译入口 -│ └── config.json --- 定义产品的编译配置文件,配置产品所使用的组件等。 -└── out --- 编译过程中的输出目录 - ├── ... --- 单板/产品编译产生的bin等 -``` - diff --git "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/01.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/03.\346\235\277\347\272\247\347\263\273\347\273\237\347\247\273\346\244\215/02.\346\235\277\347\272\247\351\251\261\345\212\250\351\200\202\351\205\215.md" "b/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/01.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/03.\346\235\277\347\272\247\347\263\273\347\273\237\347\247\273\346\244\215/02.\346\235\277\347\272\247\351\251\261\345\212\250\351\200\202\351\205\215.md" deleted file mode 100644 index 34917c020d0ba6d4ba4fcab3f6658103a2890b8f..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/01.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/03.\346\235\277\347\272\247\347\263\273\347\273\237\347\247\273\346\244\215/02.\346\235\277\347\272\247\351\251\261\345\212\250\351\200\202\351\205\215.md" +++ /dev/null @@ -1,59 +0,0 @@ ---- -title: 板级驱动适配 -permalink: /pages/0104010302 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 板级驱动适配 - -板级驱动适配的主要步骤如下: - -1. SDK基于OpenHarmony提供的CMSIS/POSIX适配依赖OS的接口。 - - 板级SDK适配OS接口存在两种选择:CMSIS、POSIX,当前liteos\_m已经适配CMSIS大部分接口(覆盖:基础内核管理、线程管理、定时器、事件、互斥锁、信号量、队列等),基本可以满足直接移植,POSIX接口当前具备初步的移植能力,接口正在补全中;如果SDK原本基于CMSIS或者POSIX接口实现,理论上可以直接适配到liteos\_m中; - - 如果SDK原本基于freeRTOS等其他嵌入式OS或者本身有一层OS interface的抽象层,建议将依赖OS接口直接适配到CMSIS接口; - - 例如,某产品定义的OS interface接口,创建queue的接口原型: - - ``` - bool osif_msg_queue_create(void **pp_handle, uint32_t msg_num, uint32_t msg_size) - ``` - - 而CMSIS提供的接口原型如下: - - ``` - osMessageQueueId_t osMessageQueueNew (uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr); - ``` - - 对应的OS interface接口的原型可以按照如下适配: - - ``` - #include "CMSIS_os2.h" - osMessageQueueId_t osMessageQueueNew (uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr); - bool osif_msg_queue_create(void **pp_handle, uint32_t msg_num, uint32_t msg_size) - { - (*pp_handle) = osMessageQueueNew (msg_num, msg_size, NULL); - if((*pp_handle) == NULL){ - return FALSE; - } - return TRUE; - } - ``` - -2. 接口SDK编译问题或者基于OpenHarmony编译框架改造SDK,将SDK按照目录结构要求合入OpenHarmony的device目录中。 - - OS接口适配后,板级驱动集成到OpenHarmony也存在2种选择: - - - SDK独立编译,通过二进制形式直接链入OpenHarmony; - - SDK基于OpenHarmony改造编译框架,从长期演进及后期联调便利性角度角度考虑,建议基于GN编译框架直接改造SDK编译框架,通过源码形式链入OpenHarmony工程。 - -3. 验证SDK基本功能。 - diff --git "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/01.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/03.\346\235\277\347\272\247\347\263\273\347\273\237\347\247\273\346\244\215/03.HAL\345\261\202\345\256\236\347\216\260.md" "b/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/01.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/03.\346\235\277\347\272\247\347\263\273\347\273\237\347\247\273\346\244\215/03.HAL\345\261\202\345\256\236\347\216\260.md" deleted file mode 100644 index 217fce023821c5e4bac309b3dc509818d2373e29..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/01.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/03.\346\235\277\347\272\247\347\263\273\347\273\237\347\247\273\346\244\215/03.HAL\345\261\202\345\256\236\347\216\260.md" +++ /dev/null @@ -1,87 +0,0 @@ ---- -title: HAL层实现 -permalink: /pages/0104010303 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# HAL层实现 - -- [UTILS](#section1394788286) -- [IOT外设子系统](#section958113200811) -- [WLAN服务](#section1331917210911) - -HAL层主要功能是实现轻OpenHarmony与芯片的解耦,以下模块描述的是轻OpenHarmony系统对芯片接口的依赖情况。 - -## UTILS - -**基本介绍:** - -公共基础提供通用的基础组件,这些基础组件可被各业务子系统及上层应用所使用。基础组件依赖芯片文件系统实现,需要芯片平台提供实现文件的打开、关闭、读写、获取大小等功能。 - -**公共基础HAL层接口说明:** - -需要芯片适配相关接口的实现,对芯片文件系统接口依赖请参考[utils的HAL头文件](https://gitee.com/openharmony/utils_native_lite/tree/master/hals/file)。 - -## IOT外设子系统 - -**基本介绍** - -提供轻OpenHarmony专有的外部设备操作接口。本模块提供设备操作接口有:FLASH, GPIO, I2C, PWM, UART, WATCHDOG等。 - -**IOT外设子系统HAL层接口说明**: - -需要芯片适配相关接口的实现,对芯片设备外设接口依赖请参考[IOT外设子系统的HAL头文件](https://gitee.com/openharmony/iothardware_peripheral/tree/master/interfaces/kits)。 - -## WLAN服务 - -**基本介绍:** - -WLAN服务适用于设备接入WLAN无线局域网场景,包括: - -- 使用STA模式,作为接入方接入其他设备、路由器开启的WLAN无线局域网接入点; - -- 使用AP模式,开启无线局域网接入点,允许其他设备连接。 - - -借助WLAN服务,开发者可以实现对系统中WLAN的控制,包括开启关闭、扫描发现、连接断开等功能。 - -此外,WLAN服务还包括事件listen功能,开发者可以listen WLAN的状态,并在状态发生变化时立刻感知。 - -**WLAN服务HAL层接口说明:** - -代码路径及接口定义如下: - -``` -foundation/communication/interfaces/kits/wifi_lite/wifiservice/ -├── station_info.h -├── wifi_device_config.h -├── wifi_device.h -├── wifi_error_code.h -├── wifi_event.h -├── wifi_hotspot_config.h -├── wifi_hotspot.h -├── wifi_linked_info.h -└── wifi_scan_info.h -``` - -具体的实现需要各厂家按照定义的接口在vendor/\*\*\*/\*\*\*/\*\*\*\_adapter中实现,例如hi3861中具体实现在 - -``` -vendor/hisi/hi3861/hi3861_adapter/hals/communication/wifi_lite/wifiservice/ -├── BUILD.gn -└── source -├── wifi_device.c -├── wifi_device_util.c -├── wifi_device_util.h -└── wifi_hotspot.c -``` - -需要芯片适配相关接口的实现,对芯片设备外设接口依赖请参考[WLAN服务的头文件](https://gitee.com/openharmony/communication_wifi_lite/tree/master/interfaces/wifiservice)。 - diff --git "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/01.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/03.\346\235\277\347\272\247\347\263\273\347\273\237\347\247\273\346\244\215/04.\347\263\273\347\273\237\347\273\204\344\273\266\350\260\203\347\224\250.md" "b/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/01.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/03.\346\235\277\347\272\247\347\263\273\347\273\237\347\247\273\346\244\215/04.\347\263\273\347\273\237\347\273\204\344\273\266\350\260\203\347\224\250.md" deleted file mode 100644 index 021d5f027642e65e02ba8c2ce04621fd9fcc44c6..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/01.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/03.\346\235\277\347\272\247\347\263\273\347\273\237\347\247\273\346\244\215/04.\347\263\273\347\273\237\347\273\204\344\273\266\350\260\203\347\224\250.md" +++ /dev/null @@ -1,39 +0,0 @@ ---- -title: 系统组件调用 -permalink: /pages/0104010304 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 系统组件调用 - -- [SAMGR](#section105874301910) -- [DFX](#section20064420420) - -系统组件为上层应用提供基础能力,包括SAMGR(系统服务框架子系统)、DFX子系统等。在板级系统移植过程中,只需要选择使用即可,不用对其进行适配。 - -## SAMGR - -**基本介绍** - -系统服务框架基于面向服务的架构,提供了服务开发、服务的子功能开发、对外接口的开发、以及多服务共进程、进程间服务调用等开发能力。 - ->![](/images/device-dev/public_sys-resources/icon-notice.gif) **须知:** ->本组件在板级系统移植中必须要使用,否则其他服务组件无法运行。 - -**SAMGR使用说明,请参考:[SAMGR 使用指导](https://gitee.com/openharmony/distributedschedule_samgr_lite/blob/master/README_zh.md)** - -## DFX - -**基本介绍** - -DFX子系统主要包含DFR(Design for Reliability,可靠性)和DFT(Design for Testability,可测试性)特性,为开发者提供代码维测信息。 - -**DFX子系统使用说明,请参考:[DFX子系统使用指导](/pages/01051001)** - diff --git "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/01.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/03.\346\235\277\347\272\247\347\263\273\347\273\237\347\247\273\346\244\215/05.lwIP\347\273\204\344\273\266\351\200\202\351\205\215.md" "b/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/01.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/03.\346\235\277\347\272\247\347\263\273\347\273\237\347\247\273\346\244\215/05.lwIP\347\273\204\344\273\266\351\200\202\351\205\215.md" deleted file mode 100644 index b5f1ac5f6d57fe5d53668f980a63ec346098e2f2..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/01.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/03.\346\235\277\347\272\247\347\263\273\347\273\237\347\247\273\346\244\215/05.lwIP\347\273\204\344\273\266\351\200\202\351\205\215.md" +++ /dev/null @@ -1,77 +0,0 @@ ---- -title: lwIP组件适配 -permalink: /pages/0104010305 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# lwIP组件适配 - -lwIP是一个小型开源的TCP/IP协议栈,LiteOS-M已对开源lwIP做了适配和功能增强,lwIP代码分为两部分: - -- third_party/lwip目录下是lwIP开源代码,里面只做了少量的侵入式修改,为了适配增强功能。 - -- kernel/liteos_m/components/net/lwip-2.1目录下是lwIP适配和功能增强代码,里面提供了lwIP的默认配置文件。 - -如果需要使用lwIP组件,请按如下步骤适配: - -1. 在产品目录下新建一个目录用来存放产品的适配文件,如lwip_adapter。 - -2. 在lwip_adapter目录下新建一个目录include,用来存放适配的头文件。 - -3. 在include目录下新建目录lwip,并在lwip目录下新建头文件lwipopts.h,代码如下所示,如果默认配置不能满足产品使用,可自行根据产品使用情况修改配置,如关闭DHCP功能。 - - ``` - #ifndef _LWIP_ADAPTER_LWIPOPTS_H_ - #define _LWIP_ADAPTER_LWIPOPTS_H_ - - #include_next "lwip/lwipopts.h" - - #undef LWIP_DHCP - #define LWIP_DHCP 0 // 关闭DHCP功能 - - #endif /* _LWIP_ADAPTER_LWIPOPTS_H_ */ - ``` - -4. 将kernel/liteos_m/components/net/lwip-2.1/porting目录下的BUILD.gn复制到lwip_adapter目录下,并按如下修改。 - - ``` - import("//kernel/liteos_m/liteos.gni") - import("$LITEOSTHIRDPARTY/lwip/lwip.gni") - import("$LITEOSTOPDIR/components/net/lwip-2.1/lwip_porting.gni") - - module_switch = defined(LOSCFG_NET_LWIP_SACK) - module_name = "lwip" - kernel_module(module_name) { - sources = LWIP_PORTING_FILES + LWIPNOAPPSFILES - [ "$LWIPDIR/api/sockets.c" ] - include_dirs = [ "//utils/native/lite/include" ] - } - - #添加新增加的适配头文件路径include - config("public") { - include_dirs = [ "include" ] + LWIP_PORTING_INCLUDE_DIRS + LWIP_INCLUDE_DIRS - } - ``` - -5. 在产品的配置文件(如config.json)中设置lwIP的编译路径,即步骤4中BUILD.gn的路径。 - - ``` - { - "subsystem": "kernel", - "components": [ - { "component": "liteos_m", "features":["ohos_kernel_liteos_m_lwip_path = \"//xxx/lwip_adapter\"" ] } - ] - }, - ``` - -6. 在产品的内核编译配置文件中,如kernel_config/debug.config,打开编译lwIP的开关。 - - ``` - LOSCFG_NET_LWIP=y - ``` diff --git "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/01.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/03.\346\235\277\347\272\247\347\263\273\347\273\237\347\247\273\346\244\215/06.\344\270\211\346\226\271\347\273\204\344\273\266\351\200\202\351\205\215.md" "b/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/01.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/03.\346\235\277\347\272\247\347\263\273\347\273\237\347\247\273\346\244\215/06.\344\270\211\346\226\271\347\273\204\344\273\266\351\200\202\351\205\215.md" deleted file mode 100644 index 92eaa1c5acc54454a543e33104fbd6200eb5b89f..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/01.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/03.\346\235\277\347\272\247\347\263\273\347\273\237\347\247\273\346\244\215/06.\344\270\211\346\226\271\347\273\204\344\273\266\351\200\202\351\205\215.md" +++ /dev/null @@ -1,69 +0,0 @@ ---- -title: 三方组件适配 -permalink: /pages/0104010306 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 三方组件适配 - -如果需要使用third\_party目录下与产品相关的三方组件,可能需要对三方组件进行适配,下面以比较常用的mbedtls为例,介绍下适配步骤,注意本小节中仅介绍如何将适配的代码与OpenHarmony的编译框架融合,不会详细介绍mbedtls本身的原理和适配代码的具体逻辑,这些内容请参考mbedtls官方网站上的适配指南。 - -1. 编写适配层代码 - - 根据mbedtls官网的适配指南,编写需要的适配层代码,以适配硬件随机数举例,下面的路径都是相对third\_party/mbedtls的路径: - - 1. 拷贝include/mbedtls/config.h到ports目录下,并修改打开MBEDTLS\_ENTROPY\_HARDWARE\_ALT开关。 - 2. 在ports目录下创建entropy\_poll\_alt.c文件include并实现entropy\_poll.h中的硬件随机数接口 - 3. 在BUILD.gn中的mbedtls\_sources中增加刚才适配的entropy\_poll\_alt.c的路径 - 4. 在BIULD.gn中的lite\_library\("mbedtls\_static"\)中增加一行MBEDTLS\_CONFIG\_FILE指定新配置文件的位置 - - ``` - lite_library("mbedtks_static") { - ... - defines += ["MBEDTLS_CONFIG_FILE=<../port/config.h>"] - ... - } - ``` - - 注意,上面的修改最好都新建一个config或者新建一个xxx\_alt.c文件来修改,不要直接在原先的代码中修改,侵入式的修改会导致后续版本升级出现大量零散冲突,增加升级维护成本。 - -2. 制作patch - - 由于上面的适配是硬件相关的,上库代码时,不能直接放到通用的third\_party/mbedtls目录中,因此需要将上面的修改制作成patch,在编译之前通过打patch的方式注入到代码中。 - - 1. 首先增加设备的patch配置文件device///patch.yml - 2. 编辑device///patch.yml,增加要打的patch的信息: - - ``` - # 需要打patch的路径,路径均为相对代码根目录的路径 - third_party/mbedtls: - # 该路径下需要打的patch存放路径 - - device///third_party/mbedtls/adapter.patch - third_party/wpa_supplicant: - # 当一个路径下有多个patch的时候会依次执行patch - - device///third_party/wpa_supplicant/xxxxx.patch - - device///third_party/wpa_supplicant/yyyyy.patch - ... - ``` - - 3. 制作上述**步骤1**修改的patch并放到对应的目录即可 - -3. 使用带patch的编译 - - 想要在编译的时候带上patch,其他步骤不变,仅需要在触发编译的时候加上 --patch,例如全编译的命令编程 - - ``` - hb build -f --patch - ``` - - >![](/images/device-dev/public_sys-resources/icon-caution.gif) **注意:** - >最后一次打patch的产品信息会被记录,在进行下一次编译操作时,会对上一次的patch进行回退(即执行\`patch -p1 -R < xxx\`),回退patch失败或新增patch失败均会终止编译过程,请解决patch冲突后再次尝试编译。 - - diff --git "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/01.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/03.\346\235\277\347\272\247\347\263\273\347\273\237\347\247\273\346\244\215/07.XTS\350\256\244\350\257\201.md" "b/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/01.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/03.\346\235\277\347\272\247\347\263\273\347\273\237\347\247\273\346\244\215/07.XTS\350\256\244\350\257\201.md" deleted file mode 100644 index 9a73ece5af38dda85ec2a89e7bc089fdcfbb52e3..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/01.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/03.\346\235\277\347\272\247\347\263\273\347\273\237\347\247\273\346\244\215/07.XTS\350\256\244\350\257\201.md" +++ /dev/null @@ -1,78 +0,0 @@ ---- -title: XTS认证 -permalink: /pages/0104010307 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# XTS认证 - -- [XTS简介](#section6725155811454) - - [将XTS认证子系统加入编译组件中](#section46981118105417) - - [执行联接类模组acts测试用例](#section9489122319819) - - -## XTS简介 - -XTS是OpenHarmony生态认证测试套件的集合,当前包括acts(application compatibility test suite)应用兼容性测试套。test/xts仓当前包括acts与tools软件包: - -- acts,存放acts相关测试用例源码与配置文件,其目的是帮助终端设备厂商尽早发现软件与OpenHarmony的不兼容性,确保软件在整个开发过程中满足OpenHarmony的兼容性要求。 -- tools,存放acts相关测试用例开发框架。 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->XTS的启动依赖SAMGR系统服务。 - -适配分为两步,包括: - -1. 将XTS认证子系统加入编译组件中。 -2. 执行联接类模组acts测试用例。 - -### 将XTS认证子系统加入编译组件中 - -举例:将XTS认证子系统加入hispark\_aries产品编译组件中为例。 - -1. 在vendor/hisilicon/hispark\_aries/config.json中加入XTS认证子系统定义: - - ``` - { - "subsystem": "test", - "components": [ - { "component": "xts_acts", "features":[] }, - { "component": "xts_tools", "features":[] } - ] - }, - ``` - -2. Debug版本才会触发XTS认证子系统编译; - -### 执行联接类模组acts测试用例 - -举例:以hispark\_aries产品执行联接类模组acts测试用例为例。 - -1. 获取编译镜像。 - - 请在如下目录获取版本镜像:out/hispark\_pegasus/wifiiot\_hispark\_pegasus/。 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >判断当前版本镜像是否集成acts测试套件方法:在map文件中查看对应.a是否被编译即可。 - -2. 版本镜像烧录进开发板。 -3. 测试步骤。 - - (1)使用串口工具登录开发板,并保存串口打印信息。 - - (2)重启设备,查看串口日志。 - -4. 测试结果分析指导。 - - (1)基于串口打印日志进行分析; - - (2)每个测试套件执行以“Start to run test suite”开始,以“xx Tests xx Failures xx Ignored”结束。 - - diff --git "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/01.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/04.\345\270\270\350\247\201\351\227\256\351\242\230.md" "b/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/01.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/04.\345\270\270\350\247\201\351\227\256\351\242\230.md" deleted file mode 100644 index f2084cc0d7fdbb5ab91b7e32d3b047cf724fc9dd..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/01.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/04.\345\270\270\350\247\201\351\227\256\351\242\230.md" +++ /dev/null @@ -1,52 +0,0 @@ ---- -title: 常见问题 -permalink: /pages/01040104 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 常见问题 - -- [如何将用户的堆内存挂载进内核](#section965418378552) - -## 如何将用户的堆内存挂载进内核 - -- 内核堆内存配置的相关宏如下,用户可根据实际情况,在target\_config.h中配置: - -**表 1** 内核堆内存配置相关宏 - - - - - - - - - - - - - - - - -

宏名称

-

描述

-

LOSCFG_SYS_EXTERNAL_HEAP

-

这个宏决定系统是使用内核的内部堆内存还是用户的堆内存,默认为0(即使用内部的堆内存),大小为0x10000;如果用户需要基于外部的堆内存,那么可以将该宏设置为1。

-

LOSCFG_SYS_HEAP_ADDR

-

内核堆内存的起始地址。

-

LOSCFG_SYS_HEAP_SIZE

-

内核堆内存的大小,即LOSCFG_SYS_HEAP_ADDR指定的内存块大小。

-
- -- 注意事项: - -指定的堆内存范围务必保证没有其他模块使用,避免踩内存,破坏堆内存功能。 - diff --git "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/02.\345\260\217\345\236\213\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/01.\347\247\273\346\244\215\345\207\206\345\244\207/01.\347\247\273\346\244\215\351\241\273\347\237\245.md" "b/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/02.\345\260\217\345\236\213\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/01.\347\247\273\346\244\215\345\207\206\345\244\207/01.\347\247\273\346\244\215\351\241\273\347\237\245.md" deleted file mode 100644 index 8bcef278f06cbfb2612022267ce68b7c146f181a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/02.\345\260\217\345\236\213\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/01.\347\247\273\346\244\215\345\207\206\345\244\207/01.\347\247\273\346\244\215\351\241\273\347\237\245.md" +++ /dev/null @@ -1,111 +0,0 @@ ---- -title: 移植须知 -permalink: /pages/0104020101 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 移植须知 - - - -**表 1** OpenHarmony小型系统已适配的开发板 - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

开发板

-

内核

-

arch

-

ROM

-

RAM

-

文件系统

-

Flash 类型

-

hispark_taurus

-

LiteOS-A和linux-4.19

-

ARM cortex-a7

-

8G

-

1GB

-

VFAT、EXT4

-

eMMC4.5

-

hispark_aries

-

LiteOS-A

-

ARM cortex-a7

-

16M

-

512M

-

JFFS2

-

SPI NOR

-
- -表1中的开发板可作为待移植开发板的参考,当前LiteOS-A和linux-4.19支持的arch、ROM占用、支持的文件系统和支持的Flash类型如下表所示: - -**表 2** OpenHarmony小型系统内核移植信息表 - - - - - - - - - - - - - - - - - - - - - - -

内核

-

支持的arch

-

ROM

-

文件系统

-

Flash类型

-

LiteOS-A

-

ARMv7

-

> 2M

-

VFAT、JFFS2、YAFFS2

-

SPI NOR、NAND、EMMC

-

linux-4.19

-

ARM, ARM64、 MIPS、 X86等

-

> 5M

-

VFAT、JFFS2、YAFFS、EXT/2/3/4、NFS等等

-

NOR、NAND、EMMC等

-
- diff --git "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/02.\345\260\217\345\236\213\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/01.\347\247\273\346\244\215\345\207\206\345\244\207/02.\347\274\226\350\257\221\346\236\204\345\273\272.md" "b/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/02.\345\260\217\345\236\213\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/01.\347\247\273\346\244\215\345\207\206\345\244\207/02.\347\274\226\350\257\221\346\236\204\345\273\272.md" deleted file mode 100644 index ee4f4914ac39d24c9e3d2b0ca5458803329916cd..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/02.\345\260\217\345\236\213\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/01.\347\247\273\346\244\215\345\207\206\345\244\207/02.\347\274\226\350\257\221\346\236\204\345\273\272.md" +++ /dev/null @@ -1,155 +0,0 @@ ---- -title: 编译构建 -permalink: /pages/0104020102 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 编译构建 - -- [编译环境搭建](#section3336103410314) -- [编译构建系统介绍](#section354343816319) -- [新建芯片解决方案](#section18612153175011) - -## 编译环境搭建 - -首先请搭建OpenHarmony基础环境,步骤请参考轻量和小型系统入门[linux环境搭建](/pages/0102010204)。用户态和LiteOS-A的内核态编译均使用llvm编译器编译,安装方法在搭建基础环境中已提供。若选择移植linux内核,请执行如下命令安装gcc-arm-linux-gnueabi交叉编译工具链,用于编译linux内核态镜像: - -``` -sudo apt-get install gcc-arm-linux-gnueabi -``` - -## 编译构建系统介绍 - -编译构建流程、编译脚本编写、目录规则、独立编译单个组件、独立编译芯片解决方案等介绍请见[编译构建子系统介绍](/pages/01050301)。 - -## 新建芯片解决方案 - -了解编译框架和搭建完编译环境后,请参考如下步骤新建芯片解决方案: - -1. 新建目录 - - 芯片解决方案的目录规则为:device/\{芯片解决方案厂商\}/\{开发板\}。以海思的hispark\_taurus开发板为例,在代码根目录执行如下命令建立目录: - - ``` - mkdir -p device/hisilicon/hispark_taurus - ``` - - 芯片解决方案目录树的规则如下: - - ``` - device - └── company # 芯片解决方案厂商 - └── board # 开发板名称 - ├── BUILD.gn # 编译脚本 - ├── hals # OS南向接口适配 - ├── linux # 可选,linux内核版本 - │ └── config.gni # linux版本编译配置 - └── liteos_a # 可选,liteos内核版本 - └── config.gni # liteos_a版本编译配置 - ``` - - 以hispark\_taurus移植linux内核为例,目录树应该如下: - - ``` - device - └── hisilicon - └── hispark_tautus - ├── BUILD.gn - ├── hals - ├── ...... - └── linux - └── config.gni - ``` - - 目录树建立后开发板相关的源码放到hispark\_taurus目录下。 - -2. 配置开发板编译选项 - - [步骤1](#li20894101862)中的config.gni可配置开发板相关的编译选项,编译构建框架将会遵照该配置文件中的参数编译所有用户态OS组件。其中关键的字段说明如下: - - ``` - kernel_type: 开发板使用的内核类型,例如:“liteos_a”, “liteos_m”, “linux”。 - kernel_version: 开发板使用的内核版本,例如:“4.19”。 - board_cpu: 开发板CPU类型,例如:“cortex-a7”, “riscv32”。 - board_arch: 开发板芯片arch, 例如: “armv7-a”, “rv32imac”。 - board_toolchain: 开发板自定义的编译工具链名称,例如:“gcc-arm-none-eabi”。若为空,则使用默认为ohos-clang。 - board_toolchain_prefix:编译工具链前缀,例如:“gcc-arm-none-eabi”。 - board_toolchain_type: 编译工具链类型,目前支持gcc和clang。例如:“gcc” ,“clang”。 - board_cflags: 开发板配置的c文件编译选项。 - board_cxx_flags: 开发板配置的cpp文件编译选项。 - board_ld_flags: 开发板配置的链接选项。 - ``` - - 还以海思的hispark\_taurus开发板为例,对应的device/hisilicon/hispark\_taurus/config.gni内容如下: - - ``` - # Board CPU type, e.g. "cortex-a7", "riscv32". - board_cpu = "cortex-a7" - - # Toolchain name used for system compiling. - # E.g. gcc-arm-none-eabi, arm-linux-harmonyeabi-gcc, ohos-clang, riscv32-unknown-elf. - # Note: The default toolchain is "ohos-clang". It's not mandatory if you use the default toochain. - board_toolchain = "mips-linux-gnu-gcc" - - # The toolchain path instatlled, it's not mandatory if you have added toolchian path to your ~/.bashrc. - board_toolchain_path = - rebase_path("//prebuilts/gcc/linux-x86/arm/arm-linux-ohoseabi-gcc/bin", - root_build_dir) - - # Compiler prefix. - board_toolchain_prefix = "arm-linux-ohoseabi-" - - # Compiler type, "gcc" or "clang". - board_toolchain_type = "gcc" - - # Board related common compile flags. - board_cflags = [ - ] - board_cxx_flags = [ - ] - board_ld_flags = [] - - # Board related headfiles search path. - board_include_dirs = [] - board_include_dirs += [ rebase_path( - "//prebuilts/gcc/linux-x86/arm/arm-linux-ohoseabi-gcc/target/usr/include", - root_build_dir) ] - - # Board adapter dir for OHOS components. - board_adapter_dir = "" - - # Sysroot path. - board_configed_sysroot = "" - - # Board storage type, it used for file system generation. - storage_type = "emmc" - ``` - -3. 编写开发板编译脚本 - - 步骤1中的BUILD.gn为新增的开发板的编译入口,主要用于编译开发板相关的代码,主要为设备侧驱动、设备侧接口适配\(媒体,图形等\)和开发板的SDK等等。 - - 海思的hispark\_taurus开发板的device/hisilicon/hispark\_taurus/BUILD.gn可写成: - - ``` - # group名称建议与开发板名称一致 - group("hispark_taurus") { - deps = [ "//kernel/linux/patches:linux_kernel" ] # 拉起内核编译 - deps += [ - ...... # 开发板其他编译单元 - ] - } - ``` - -4. 编译调试 - - 在开发板目录下执行hb set和hb build即可启动芯片解决方案的编译,编译框架会以开发板下的BUILD.gn为入口启动编译。 - - diff --git "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/02.\345\260\217\345\236\213\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/02.\347\247\273\346\244\215\345\206\205\346\240\270/01.LiteOS-A\345\206\205\346\240\270.md" "b/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/02.\345\260\217\345\236\213\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/02.\347\247\273\346\244\215\345\206\205\346\240\270/01.LiteOS-A\345\206\205\346\240\270.md" deleted file mode 100644 index 8f7844bcf805be84079479fed364c7f64dee1cb3..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/02.\345\260\217\345\236\213\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/02.\347\247\273\346\244\215\345\206\205\346\240\270/01.LiteOS-A\345\206\205\346\240\270.md" +++ /dev/null @@ -1,276 +0,0 @@ ---- -title: LiteOS-A内核 -permalink: /pages/0104020201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# LiteOS-A内核 - -- [移植概述](#section14876256185510) - - [移植场景](#section1986014410569) - - [目录规范](#section10916181716564) - -- [基础适配](#section814974018565) - - [编程样例](#section10854481825) - -- [验证](#section646410453212) - -## 移植概述 - -### 移植场景 - -LiteOS-A当前支持ARMv7-a指令集架构,如果三方芯片为ARMv7-a架构,可以进行内核基础适配;否则还需要先根据芯片的架构来新增内核对该芯片架构的支持,这个工作较为复杂,不在这篇文章范围内。 - -### 目录规范 - -LiteOS-A目录规范参考[LiteOS-A 简介](https://gitee.com/openharmony/kernel_liteos_a)。 - -## 基础适配 - -LiteOS-A提供系统运行所需的系统初始化流程和定制化配置选项。移植过程中,需要关注初始化流程中跟硬件配置相关的函数。 - -如下图所示,LiteOS-A的初始化流程主要包含以下七步: - -1. 新增target\_config.h文件,并且编写单板内存相关的配置宏DDR\_MEM\_ADDR和DDR\_MEM\_SIZE,分别表示内存起始地址和内存的长度,预链接脚本board.ld.S会根据这两个宏进行展开生成链接脚本board.ld。 -2. 新增定义MMU映射全局数组\(g\_archMmuInitMapping\),指定各个内存段属性及虚实映射关系,内核启动阶段根据该表建立内存映射关系。 -3. 如果是多核,需要新增定义从核操作函数句柄\(struct SmpOps\),其中SmpOps-\>SmpCpuOn函数需要实现唤醒从核的功能;接着定义SmpRegFunc函数,调用LOS\_SmpOpsSet接口进行句柄注册;最后通过启动框架完成注册过程,即LOS\_MODULE\_INIT\(SmpRegFunc, LOS\_INIT\_LEVEL\_EARLIEST\)。 -4. 链接阶段根据链接脚本board.ld生成内核镜像。 -5. 单核CPU镜像运行入口为汇编文件reset\_vector\_up.S,多核CPU的入口为reset\_vector\_mp.S,在汇编文件中进行中断向量表初始化、MMU页表初始化等操作。 -6. reset\_vector.S汇编代码最终会跳转到C语言的main函数,进行硬件时钟、软件定时器、内存和任务等初始化,这个过程会依赖target\_config.h的特性宏配置,最后会创建SystemInit任务,并且开启任务调度OsSchedStart\(\)。 -7. SystemInit任务在单板代码中实现,其中调用DeviceManagerStart函数进行HDF驱动初始化,这个过程会调用单板代码中的驱动配置文件hdf.hcs以及drivers源码实现 - -整体启动流程如下图所示: - -**图 1** 整体启动流程 -![](/images/device-dev/porting/figure/整体启动流程.png "整体启动流程") - -从图1中可以看到,内核基础适配需要单板进行适配的代码包含三部分: - -- 新增target\_config.h文件,其中新增单板硬件配置参数和特性开关的配置参数,具体说明如下: - - **表 1** target\_config.h配置项说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

配置项

-

说明

-

OS_SYS_CLOCK

-

系统cycle的频率

-

DDR_MEM_ADDR

-

系统内存的起始地址

-

DDR_MEM_SIZE

-

系统内存的大小

-

PERIPH_PMM_BASE

-

外设寄存器的起始地址

-

PERIPH_PMM_SIZE

-

外设寄存器的长度大小

-

OS_HWI_MIN

-

系统中断最小值

-

OS_HWI_MAX

-

系统中断最大值

-

NUM_HAL_INTERRUPT_UART0

-

UART0中断号

-

UART0_REG_BASE

-

UART0寄存器基址

-

GIC_BASE_ADDR

-

GIC中断寄存器基址

-

GICD_OFFSET

-

GICD相对GIC基址的偏移地址

-

GICC_OFFSET

-

GICC相对GIC基址的偏移地址

-
- -- SystemInit函数用于单板用户态业务初始化,典型的初始化场景如图2所示: - - **图 2** 业务启动流程 - ![](/images/device-dev/porting/figure/业务启动流程.png "业务启动流程") - -- main函数用于内核基础初始化和单板内核态业务初始化,流程如下图3所示,整体由内核启动框架主导初始化流程,图中浅蓝色部分为启动框架中可接受外部模块注册启动的阶段。 - - >![](/images/device-dev/public_sys-resources/icon-caution.gif) **注意:** - >同一层级内的模块不能有依赖关系。 - - **图 3** 内核启动框架 - ![](/images/device-dev/porting/figure/内核启动框架.jpg "内核启动框架") - - **表 2** 启动框架层级 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

层级

-

说明

-

LOS_INIT_LEVEL_EARLIEST

-

最早期初始化

-

说明:不依赖架构,单板以及后续模块会对其有依赖的纯软件模块初始化

-

例如:Trace模块

-

LOS_INIT_LEVEL_ARCH_EARLY

-

架构早期初始化

-

说明:架构相关,后续模块会对其有依赖的模块初始化,如启动过程中非必需的功能,建议放到LOS_INIT_LEVEL_ARCH层

-

LOS_INIT_LEVEL_PLATFORM_EARLY

-

平台早期初始化

-

说明:单板平台、驱动相关,后续模块会对其有依赖的模块初始化,如启动过程中必需的功能,建议放到LOS_INIT_LEVEL_PLATFORM层

-

例如:uart模块

-

LOS_INIT_LEVEL_KMOD_PREVM

-

内存初始化前的内核模块初始化

-

说明:在内存初始化之前需要使能的模块初始化

-

LOS_INIT_LEVEL_VM_COMPLETE

-

基础内存就绪后的初始化

-

说明:此时内存初始化完毕,需要进行使能且不依赖进程间通讯机制与系统进程的模块初始化

-

例如:共享内存功能

-

LOS_INIT_LEVEL_ARCH

-

架构后期初始化

-

说明:架构拓展功能相关,后续模块会对其有依赖的模块初始化

-

LOS_INIT_LEVEL_PLATFORM

-

平台后期初始化

-

说明:单板平台、驱动相关,后续模块会对其有依赖的模块初始化

-

例如:驱动内核抽象层初始化(mmc、mtd)

-

LOS_INIT_LEVEL_KMOD_BASIC

-

内核基础模块初始化

-

说明:内核可拆卸的基础模块初始化

-

例如:VFS初始化

-

LOS_INIT_LEVEL_KMOD_EXTENDED

-

内核扩展模块初始化

-

说明:内核可拆卸的扩展模块初始化

-

例如:系统调用初始化、ProcFS初始化、Futex初始化、HiLog初始化、HiEvent初始化、LiteIPC初始化

-

LOS_INIT_LEVEL_KMOD_TASK

-

内核任务创建

-

说明:进行内核任务的创建(内核线程,软件定时器任务)

-

例如:资源回收系统常驻任务的创建、SystemInit任务创建、CPU占用率统计任务创建

-
- - 进行单板移植适配,推荐关注LOS\_INIT\_LEVEL\_ARCH至LOS\_INIT\_LEVEL\_KMOD\_TASK之间的层级,且尽可能拆分初始化行为进行细化阶段注册。 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >启动框架中同一层级内的注册模块不能有依赖关系,建议新增模块按照上述启动阶段进行模块初始化的拆分,按需注册启动。 - >可通过查看系统编译生成文件OHOS\_Image.map中.rodata.init.kernel.\*段内的符号表来了解当前已注册进内核启动框架中的各个模块初始化入口,以及检查新注册的模块初始化入口是否生效。 - - -### 编程样例 - -在单板SDK文件中 - -``` -/* 内核启动框架头文件 */ -#include "los_init.h" -...... - -/* 新增模块的初始化函数 */ -unsigned int OsSampleModInit(void) -{ - PRINTK("OsSampleModInit SUCCESS!\n"); - ...... -} -...... -/* 在启动框架的目标层级中注册新增模块 */ -LOS_MODULE_INIT(OsSampleModInit, LOS_INIT_LEVEL_KMOD_EXTENDED); -``` - -## 验证 - -``` -main core booting up... -OsSampleModInit SUCCESS! -releasing 1 secondary cores -cpu 1 entering scheduler -cpu 0 entering scheduler -``` - -根据上述系统启动阶段的打印可知,内核在启动时进行了该注册模块的初始化函数调用,完成该模块的初始化操作。 - -系统启动完毕后进入内核态shell,能够运行task命令能够正常显示即可。 - -``` -OHOS # help -*******************shell commands:************************* - -arp cat cd chgrp chmod chown cp cpup -date dhclient dmesg dns format free help hwi -ifconfig ipdebug kill log ls lsfd memcheck mkdir -mount netstat oom partinfo partition ping ping6 pmm -pwd reset rm rmdir sem shm stack statfs -su swtmr sync systeminfo task telnet touch umount -uname v2p virstatfs vmm watch writeproc - -``` - diff --git "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/02.\345\260\217\345\236\213\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/02.\347\247\273\346\244\215\345\206\205\346\240\270/02.Linux\345\206\205\346\240\270.md" "b/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/02.\345\260\217\345\236\213\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/02.\347\247\273\346\244\215\345\206\205\346\240\270/02.Linux\345\206\205\346\240\270.md" deleted file mode 100644 index 174e1533a8c1c6e426a4fdef02a055543faf847a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/02.\345\260\217\345\236\213\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/02.\347\247\273\346\244\215\345\206\205\346\240\270/02.Linux\345\206\205\346\240\270.md" +++ /dev/null @@ -1,131 +0,0 @@ ---- -title: Linux内核 -permalink: /pages/0104020202 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# Linux内核 - -- [移植概述](#section6282121355111) - - [基本信息](#section19589322515) - - [Bootloader](#section19062510518) - -- [适配编译和烧录启动](#section11112101695215) -- [验证](#section17318153325311) - -## 移植概述 - -Linux内核移植主要涉及基于linux内核基线合入三方芯片补丁后,进行基础的内核编译构建及验证。 - -### 基本信息 - -当前Linux内核基线是基于Linux社区 4.19 LTS版本演进,合入CVE及bugfix补丁。具体信息参考[代码库](https://gitee.com/openharmony/kernel_linux),对应repo工程代码路径为kernel/linux-4.19。 - -### Bootloader - -可以使用芯片厂商自带的Bootloader,或者是开源Uboot等加载内核镜像。比如为支持Hi3516DV300开发板,OpenHarmony引入的开源[Uboot](https://gitee.com/openharmony/device_hisilicon_third_party_uboot)。 - -## 适配编译和烧录启动 - -1. 准备内核config(特别是芯片相关的config)。 - - config文件所在源码目录:kernel/linux/config/ - - 以hi3516dv300芯片为例,可在对应的linux-4.19/arch/arm/configs/目录下新建\_small\_defconfig,如hi3516dv300\_small\_defconfig表示针对hi3516dv300小型系统的defconfig。该config文件可以由基础defconfig文件small\_common\_defconfig与该芯片相关的config组合生成。 - -2. 准备芯片补丁。 - - 补丁文件所在源码目录:kernel/linux/patches/linux-4.19 - - 以hi3516dv300芯片为例,参考已有的patch目录hi3516dv300\_small\_patch目录,新建\_patch目录,放置相关芯片补丁,注意hdf.patch等驱动补丁。 - -3. 编译。 - - 具体内核编译入口脚本位于工程目录kernel/linux/patches/下面,版本级整编命令会通过BUILD.gn进入kernel\_module\_build.sh和kernel.mk,需要在这2个文件中针对性进行patch及defconfig文件路径、编译器、芯片架构、内核Image格式等的适配。 - - 通过编译错误日志调整补丁,典型错误场景: - - (1)补丁合入失败,出现冲突,需要进行上下文适配修改。 - - (2)编译失败,内核版本差异(函数实现调整等)需要针对性进行内核适配。 - - >![](/images/device-dev/public_sys-resources/icon-caution.gif) **注意:** - >- 参考kernel.mk,在OpenHarmony工程的编译构建流程中会拷贝kernel/linux-4.19的代码环境后进行打补丁动作,在使用版本级编译命令前,需要kernel/linux-4.19保持原代码环境。 - >- 对应拷贝后的目录位于: out/<\*\*\*\>/kernel/linux-4.19,可以在该目录下进行补丁的修改适配。 - -4. 烧录启动。 - - 由于不同芯片的开发板的烧录方式不一样,此处不表述具体的烧录方式。需要注意烧录的各镜像的大小及启动参数的配置,参考hi3516dv300采用uboot启动参数: - - ``` - setenv bootargs 'mem=128M console=ttyAMA0,115200 root=/dev/mmcblk0p3 ro rootfstype=ext4 rootwait blkdevparts=mmcblk0:1M(boot),9M(kernel),50M(rootfs),50M(userfs)' - ``` - - -## 验证 - -调试init进程、启动shell和运行简单的用户态程序,验证内核移植是否成功。OpenHarmony[小型系统](/pages/01020101)的OS镜像结构以及linux用户态的启动流程如下图1所示: - -**图 1** 基于linux内核的OS镜像结构和用户态程序启动流程 -![](/images/device-dev/porting/figure/基于linux内核的OS镜像结构和用户态程序启动流程.png "基于linux内核的OS镜像结构和用户态程序启动流程") - -基于上述流程,推荐按以下步骤完成验证: - -1. 制作根文件系统镜像。 - - 请参考[新建芯片解决方案和产品解决方案](/pages/01050301)生成根文件系统镜像rootfs.img。从上图可以看到启动过程与产品配置强相关,在制作rootfs.img过程中请完成如下四种配置: - - - 组件配置 - - 产品组件配置文件vendor/\{company\}/\{product\}/config.json需配置启动恢复子系统\(startup\)的init\_lite组件和内核子系统的linux\_4\_1\_9组件。 - - - 系统服务配置 - - 系统服务配置文件vendor/\{company\}/\{product\}/init\_configs/init\_xxx.cfg需要启动shell服务。 - - - 文件系统配置 - - 文件系统配置vendor/\{company\}/\{product\}/fs.yml中需要创建“/bin/sh -\> mksh“和“/lib/ld-musl-arm.so.1 -\> libc.so“软连接,这两个文件分别是shell可执行程序和可执行程序依赖的c库。 - - - 启动配置 - - 启动配置在vendor/\{company\}/\{product\}/init\_configs/etc目录下,包括fstab、rsS和Sxxx文件,请按开发板实际情况配置。 - - 编译完成后,可通过检查产品编译输出目录下的rootfs内容,确认rootfs.img文件生成是否符合预期。 - -2. 调试init进程和shell。 - - 烧录rootfs.img并调试init进程和shell,不同厂商的开发板的烧录工具和流程可能不同,请按芯片解决方案提供的流程进行烧录。烧录rootfs.img前请确认bootloader和linux内核启动正常。如果rootfs.img被内核正常挂载,接着将运行/bin/init程序,init进程为用户态的第一个应用程序,它的运行意味着用户态的开始。 - - init程序首先会调用/etc/init.d/rcS脚本,rcS脚本执行第一条命令为"/bin/mount -a”,该命令会加载fstab文件,在fstab中的命令执行完后rcS将顺序调用Sxxx脚本完成设备节点创建和扫描、文件权限配置等操作。 - - 最后,init程序会读取init.cfg系统服务配置文件。根据步骤1中的设置,init程序将会启动shell。如果上述流程运行正常,系统则会进入shell。 - - 若串口有如下版本号日志打印,则表示init程序启动正常: - - **图 2** init启动正常日志 - ![](/images/device-dev/porting/figure/init启动正常日志.png "init启动正常日志") - - 正常进入shell后执行ls命令,串口打印信息如下图: - - **图 3** 正常进入shell后输入ls命令串口打印 - ![](/images/device-dev/porting/figure/正常进入shell后输入ls命令串口打印.png "正常进入shell后输入ls命令串口打印") - -3. 配置NFS。 - - init进程和shell正常启动后,以服务端IP为192.168.1.22、客户端IP为192.168.1.4为例,可在根目录执行如下命令开启NFS: - - ``` - ifconfig eth0 192.168.1.4 netmask 255.255.255.0 - mkdir -p /storgage/nfs - mount -t nfs -o nolock,addr=192.168.1.22 192.168.1.22:/nfs /storage/nfs - ``` - - diff --git "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/02.\345\260\217\345\236\213\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/03.\351\251\261\345\212\250\347\247\273\346\244\215/01.\347\247\273\346\244\215\346\246\202\350\277\260.md" "b/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/02.\345\260\217\345\236\213\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/03.\351\251\261\345\212\250\347\247\273\346\244\215/01.\347\247\273\346\244\215\346\246\202\350\277\260.md" deleted file mode 100644 index 382b24729bdf71c899a9cefae71a6d72735fbe43..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/02.\345\260\217\345\236\213\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/03.\351\251\261\345\212\250\347\247\273\346\244\215/01.\347\247\273\346\244\215\346\246\202\350\277\260.md" +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: 移植概述 -permalink: /pages/0104020301 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 移植概述 - -驱动主要包含两部分,平台驱动和器件驱动。平台驱动主要包括通常在SOC内的GPIO、I2C、SPI等;器件驱动则主要包含通常在SOC外的器件,如 LCD、TP、WLAN等 - -**图 1** OpenHarmony 驱动分类 -![](/images/device-dev/porting/figure/OpenHarmony-驱动分类.png "OpenHarmony-驱动分类") - -HDF驱动被设计为可以跨OS使用的驱动程序,HDF驱动框架会为驱动达成这个目标提供有力的支撑。开发HDF驱动中,请尽可能只使用HDF驱动框架提供的接口,否则会导致驱动丧失跨OS使用的特性。在开始驱动开发前,建议先了解[HDF驱动框架](/pages/0105020101)。 - diff --git "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/02.\345\260\217\345\236\213\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/03.\351\251\261\345\212\250\347\247\273\346\244\215/02.\345\271\263\345\217\260\351\251\261\345\212\250\347\247\273\346\244\215.md" "b/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/02.\345\260\217\345\236\213\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/03.\351\251\261\345\212\250\347\247\273\346\244\215/02.\345\271\263\345\217\260\351\251\261\345\212\250\347\247\273\346\244\215.md" deleted file mode 100644 index 56b813dc011c24d435370e0bbbd7f336c39a188d..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/02.\345\260\217\345\236\213\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/03.\351\251\261\345\212\250\347\247\273\346\244\215/02.\345\271\263\345\217\260\351\251\261\345\212\250\347\247\273\346\244\215.md" +++ /dev/null @@ -1,178 +0,0 @@ ---- -title: 平台驱动移植 -permalink: /pages/0104020302 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 平台驱动移植 - -在这一步,我们会在源码目录//device/vendor\_name/soc\_name/drivers 目录下创建平台驱动,如果你要移植的SOC的厂商还没有创建仓库的话,请联系[sig-devboard](https://gitee.com/openharmony/community/blob/master/sig/sig-devboard/sig_devboard_cn.md)创建。 - -建议的目录结构: - -``` -device -├── vendor_name -│ ├── drivers -│ │ │ ├── common -│ │ │ ├── Kconfig # 厂商驱动内核菜单入口 -│ │ │ └── lite.mk # 构建的入口 -│ ├── soc_name -│ │ ├── drivers -│ │ │ ├── dmac -│ │ │ ├── gpio -│ │ │ ├── i2c -│ │ │ ├── LICENSE -│ │ │ ├── mipi_dsi -│ │ │ ├── mmc -│ │ │ ├── pwm -│ │ │ ├── README.md # docs 如果需要的话 -│ │ │ ├── README_zh.md -│ │ │ ├── rtc -│ │ │ ├── spi -│ │ │ ├── uart -│ │ │ └── watchdog -│ ├── board_name -``` - -HDF为所有的平台驱动都创建了驱动模型,移植平台驱动的主要工作是向模型注入实例。 这些模型你可以在源码目录//drivers/framework/support/platform/include中找到定义。 - -本节我们会以GPIO为例,讲解如何移植平台驱动,移植过程包含以下步骤: - -1. 创建GPIO驱动 - - 在源码目录//device/vendor\_name/soc\_name/drivers/gpio中创建文件soc\_name\_gpio.c 内容模板如下: - - ``` - #include "gpio_core.h" - - // 定义GPIO结构体,如果需要的话 - struct SocNameGpioCntlr { - struct GpioCntlr cntlr; // 这是HDF GPIO驱动框架需要的结构体 - int myData; // 以下是当前驱动自身需要的 - }; - - // Bind 方法在HDF驱动中主要用户对外发布服务,这里我们不需要,直接返回成功即可 - static int32_t GpioBind(struct HdfDeviceObject *device) - { - (void)device; - return HDF_SUCCESS; - } - - // Init方法时驱动初始化的入口,我们需要在Init方法中完成模型实例的注册 - static int32_t GpioInit(struct HdfDeviceObject *device) - { - SocNameGpioCntlr *impl = CreateGpio(); // 你的创建代码 - ret = GpioCntlrAdd(&impl->cntlr); // 注册GPIO模型实例 - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: err add controller:%d", __func__, ret); - return ret; - } - return HDF_SUCCESS; - } - - // Release方法会在驱动卸载时被调用,这里主要完成资源回收 - static void GpioRelease(struct HdfDeviceObject *device) - { - // GpioCntlrFromDevice 方法能从抽象的设备对象中获得init方法注册进去的模型实例。 - struct GpioCntlr *cntlr = GpioCntlrFromDevice(device); - //资源释放... - } - - struct HdfDriverEntry g_gpioDriverEntry = { - .moduleVersion = 1, - .Bind = GpioBind, - .Init = GpioInit, - .Release = GpioRelease, - .moduleName = "SOC_NAME_gpio_driver", // 这个名字我们稍后会在配置文件中用到,用来加载驱动。 - }; - HDF_INIT(g_gpioDriverEntry); // 注册一个GPIO的驱动入口 - ``` - -2. 创建厂商驱动构建入口 - - 如前所述device/vendor\_name/drivers/lite.mk是厂商驱动的构建的入口。我们需要从这个入口开始,进行构建 - - ``` - #文件device/vendor_name/drivers/lite.mk - - SOC_VENDOR_NAME := $(subst $/",,$(LOSCFG_DEVICE_COMPANY)) - SOC_NAME := $(subst $/",,$(LOSCFG_PLATFORM)) - BOARD_NAME := $(subst $/",,$(LOSCFG_PRODUCT_NAME)) - - # 指定SOC进行构建 - LIB_SUBDIRS += $(LITEOSTOPDIR)/../../device/$(SOC_VENDOR_NAME)/$(SOC_NAME)/drivers/ - ``` - -3. 创建SOC驱动构建入口 - - ``` - #文件device/vendor_name/soc_name/drivers/lite.mk - - SOC_DRIVER_ROOT := $(LITEOSTOPDIR)/../../device/$(SOC_VENDOR_NAME)/$(SOC_NAME)/drivers/ - - # 判断如果打开了GPIO的内核编译开关 - ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_GPIO), y) - # 构建完成要链接一个叫hdf_gpio的对象 - LITEOS_BASELIB += -lhdf_gpio - # 增加构建目录gpio - LIB_SUBDIRS += $(SOC_DRIVER_ROOT)/gpio - endif - - # 后续其他驱动在此基础上追加 - ``` - -4. 创建GPIO构建入口 - - ``` - include $(LITEOSTOPDIR)/config.mk - include $(LITEOSTOPDIR)/../../drivers/adapter/khdf/liteos/lite.mk - - # 指定输出对象的名称,注意要与SOC驱动构建入口里的LITEOS_BASELIB 保持一致 - MODULE_NAME := hdf_gpio - - # 增加HDF框架的INCLUDE - LOCAL_CFLAGS += $(HDF_INCLUDE) - - # 要编译的文件 - LOCAL_SRCS += soc_name_gpio.c - - # 编译参数 - LOCAL_CFLAGS += -fstack-protector-strong -Wextra -Wall -Werror -fsigned-char -fno-strict-aliasing -fno-common - - include $(HDF_DRIVER) - ``` - -5. 配置产品加载驱动 - - 产品的所有设备信息被定义在源码文件//vendor/vendor\_name/product\_name/config/device\_info/device\_info.hcs中。 - - 平台驱动请添加到platform的host中。 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >moduleName要与驱动定义中的相同。 - - ``` - root { - ... - platform :: host { - device_gpio :: device { - device0 :: deviceNode { - policy = 0; - priority = 10; - permission = 0644; - moduleName = "SOC_NAME_gpio_driver"; - } - } - } - } - ``` - - diff --git "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/02.\345\260\217\345\236\213\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/03.\351\251\261\345\212\250\347\247\273\346\244\215/03.\345\231\250\344\273\266\351\251\261\345\212\250\347\247\273\346\244\215.md" "b/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/02.\345\260\217\345\236\213\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/03.\351\251\261\345\212\250\347\247\273\346\244\215/03.\345\231\250\344\273\266\351\251\261\345\212\250\347\247\273\346\244\215.md" deleted file mode 100644 index f24c8d3bcf2198938bc1c186add8e0f192086bba..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/02.\345\260\217\345\236\213\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/03.\351\251\261\345\212\250\347\247\273\346\244\215/03.\345\231\250\344\273\266\351\251\261\345\212\250\347\247\273\346\244\215.md" +++ /dev/null @@ -1,403 +0,0 @@ ---- -title: 器件驱动移植 -permalink: /pages/0104020303 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 器件驱动移植 - -- [LCD驱动移植](#section1574513454119) -- [TP驱动移植](#section20284142116422) -- [WLAN驱动移植](#section0969448164217) - -本章节讲解如何移植各类器件驱动。 - -## LCD驱动移植 - -移植LCD驱动的主要工作是编写一个驱动,在驱动中生成模型的实例,并完成注册。 - -这些LCD的驱动被放置在源码目录//drivers/framework/model/display/driver/panel中。 - -1. 创建Panel驱动 - - 创建HDF驱动,在驱动初始化中调用RegisterPanel接口注册模型实例。如: - - ``` - int32_t LCDxxEntryInit(struct HdfDeviceObject *object) - { - struct PanelData *panel = CreateYourPanel(); - // 注册模型实例 - if (RegisterPanel(panel) != HDF_SUCCESS) { - HDF_LOGE("%s: RegisterPanel failed", __func__); - return HDF_FAILURE; - } - return HDF_SUCCESS; - } - - struct HdfDriverEntry g_xxxxDevEntry = { - .moduleVersion = 1, - .moduleName = "LCD_XXXX", - .Init = LCDxxEntryInit, - }; - - HDF_INIT(g_xxxxDevEntry); - ``` - -2. 配置加载panel驱动 - - 产品的所有设备信息被定义在源码文件//vendor/vendor\_name/product\_name/config/device\_info/device\_info.hcs中。修改该文件,在display的host中,名为device\_lcd的device中增加配置。 - - >![](/images/device-dev/public_sys-resources/icon-caution.gif) **注意:** - >moduleName 要与panel驱动中的moduleName相同。 - - ``` - root { - ... - display :: host { - device_lcd :: device { - deviceN :: deviceNode { - policy = 0; - priority = 100; - preload = 2; - moduleName = "LCD_XXXX"; - } - } - } - } - ``` - - -## TP驱动移植 - -本节描述如何移植触摸屏驱动。触摸屏的器件驱动被放置在源码目录//drivers/framework/model/input/driver/touchscreen中。 移植触摸屏驱动主要工作是向系统注册ChipDevice模型实例。 - -详细的驱动开发指导,请参考 [TOUCHSCREEN开发指导](/pages/0105020402)。 - -1. 创建触摸屏器件驱动 - - 在上述touchscreen目录中创建名为touch\_ic\_name.c的文件。编写如下内容 - - ``` - #include "hdf_touch.h" - - static int32_t HdfXXXXChipInit(struct HdfDeviceObject *device) - { - ChipDevice *tpImpl = CreateXXXXTpImpl(); - if(RegisterChipDevice(tpImpl) != HDF_SUCCESS) { // 注册ChipDevice模型 - ReleaseXXXXTpImpl(tpImpl); - return HDF_FAILURE; - } - return HDF_SUCCESS; - } - - struct HdfDriverEntry g_touchXXXXChipEntry = { - .moduleVersion = 1, - .moduleName = "HDF_TOUCH_XXXX", // 注意这里的moduleName要与后续的配置完全一致 - .Init = HdfXXXXChipInit, - }; - - HDF_INIT(g_touchXXXXChipEntry); - ``` - - 其中ChipDevice中要实现如下方法: - - - - - - - - - - - - - - - - - - - - - - - - - -

方法

-

实现说明

-

int32_t (*Init)(ChipDevice *device)

-

实现器件初始化

-

int32_t (*Detect)(ChipDevice *device)

-

实现器件探测

-

int32_t (*Suspend)(ChipDevice *device)

-

实现器件休眠

-

int32_t (*Resume)(ChipDevice *device)

-

实现器件唤醒

-

int32_t (*DataHandle)(ChipDevice *device)

-

需要实现从器件读取数据,将触摸点数据填写入device->driver->frameData中

-

int32_t (*UpdateFirmware)(ChipDevice *device)

-

实现固件升级

-
- -2. 配置产品,加载器件驱动 - - 产品的所有设备信息被定义在源码文件//vendor/vendor\_name/product\_name/config/device\_info/device\_info.hcs中。修改该文件,在名为input的host中,名为device\_touch\_chip的device中增加配置。 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >moduleName 要与触摸屏驱动中的moduleName相同。 - - ``` - deviceN :: deviceNode { - policy = 0; - priority = 130; - preload = 0; - permission = 0660; - moduleName = "HDF_TOUCH_XXXX"; - deviceMatchAttr = "touch_XXXX_configs"; - } - ``` - - -## WLAN驱动移植 - -WLAN驱动分为两部分,一部分负责管理WLAN设备,另一个部分负责处理WLAN流量。 - -**图 1** OpenHarmony WLAN结构示意图 - - -![](/images/device-dev/porting/figure/HDF_WIFI.png) - -如图1,左半部分负责管理WLAN设备,右半部分负责WLAN流量。HDF WLAN分别为这两部分做了抽象,驱动的移植过程可以看做分别实现这两部分所需接口。这些接口有: - - - - - - - - - - - - - - - - - - - - -

接口

-

定义头文件

-

接口说明

-

HdfChipDriverFactory

-

drivers\framework\include\wifi\hdf_wlan_chipdriver_manager.h

-

ChipDriver的Factory,用于支持一个芯片多个WLAN端口

-

HdfChipDriver

-

drivers\framework\include\wifi\wifi_module.h

-

每个WLAN端口对应一个HdfChipDriver,用来管理一个特定端口

-

NetDeviceInterFace

-

drivers\framework\include\wifi\net_device.h

-

与协议栈之间的接口,如发送数据、设置网络接口状态等

-
- ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->详细的接口开发指导,请参考[WLAN开发](/pages/0105020404)。 - -具体的移植步骤如下: - -1. 创建HDF WLAN 芯片驱动 - - 在目录/device/vendor\_name/peripheral/wifi/chip\_name/ 创建文件 hdf\_wlan\_chip\_name.c。内容模板如下: - - ``` - static int32_t HdfWlanHisiChipDriverInit(struct HdfDeviceObject *device) { - static struct HdfChipDriverFactory factory = CreateChipDriverFactory(); // 需要移植者实现的方法 - struct HdfChipDriverManager *driverMgr = HdfWlanGetChipDriverMgr(); - if (driverMgr->RegChipDriver(&factory) != HDF_SUCCESS) { // 注册驱动工厂 - HDF_LOGE("%s fail: driverMgr is NULL!", __func__); - return HDF_FAILURE; - } - return HDF_SUCCESS; - } - - struct HdfDriverEntry g_hdfXXXChipEntry = { - .moduleVersion = 1, - .Init = HdfWlanXXXChipDriverInit, - .Release = HdfWlanXXXChipRelease, - .moduleName = "HDF_WIFI_CHIP_XXX" // 注意:这个名字要与配置一致 - }; - - HDF_INIT(g_hdfXXXChipEntry); - ``` - - 在上述代码的CreateChipDriverFactory方法中,需要创建一个HdfChipDriverFactory类型的对象。该对象提供如下方法 - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

接口

-

说明

-

const char *driverName

-

当前driverName

-

int32_t (*InitChip)(struct HdfWlanDevice *device)

-

初始化芯片

-

int32_t (*DeinitChip)(struct HdfWlanDevice *device)

-

去初始化芯片

-

void (*ReleaseFactory)(struct HdfChipDriverFactory *factory)

-

释放HdfChipDriverFactory对象

-

struct HdfChipDriver *(*Build)(struct HdfWlanDevice *device, uint8_t ifIndex)

-

创建一个HdfChipDriver;输入参数中,device是设备信息,ifIndex是当前创建的接口在这个芯片中的序号

-

void (*Release)(struct HdfChipDriver *chipDriver)

-

释放chipDriver

-

uint8_t (*GetMaxIFCount)(struct HdfChipDriverFactory *factory)

-

获取当前芯片支持的最大接口数

-
- - 其中Build方法负责创建一个管理指定网络接口的对象HdfChipDriver 。该对象需要提供方法: - - - - - - - - - - - - - - - - - - - - - - -

接口

-

说明

-

int32_t (*init)(struct HdfChipDriver *chipDriver, NetDevice *netDev)

-

初始化当前网络接口,这里需要向netDev提供接口NetDeviceInterFace

-

int32_t (*deinit)(struct HdfChipDriver *chipDriver, NetDevice *netDev)

-

去初始化当前网络接口

-

struct HdfMac80211BaseOps *ops

-

WLAN基础能力接口集

-

struct HdfMac80211STAOps *staOps

-

支持STA模式所需的接口集

-

struct HdfMac80211APOps *apOps

-

支持AP模式所需要的接口集

-
- -2. 编写配置文件描述驱动支持的芯片 - - 在产品配置目录下创建芯片的配置文件,保存至源码路径//vendor/vendor\_name/product\_name/config/wifi/wlan\_chip\_chip\_name.hcs - - 该文件模板如下: - - ``` - root { - wlan_config { - chip_name :& chipList { - chip_name :: chipInst { - match_attr = "hdf_wlan_chips_chip_name"; /* 这是配置匹配属性,用于提供驱动的配置根 */ - driverName = "driverName"; /* 需要与HdfChipDriverFactory中的driverName相同*/ - sdio { - vendorId = 0xXXXX; /* your vendor id */ - deviceId = [0xXXXX]; /*your supported devices */ - } - } - } - } - } - ``` - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >路径和文件中的vendor\_name、product\_name、chip\_name请替换成实际名称 - >vendorId 和 deviceId需要根据实际芯片的识别码进行填写。 - -3. 编写配置文件,加载驱动 - - 产品的所有设备信息被定义在源码文件//vendor/vendor\_name/product\_name/config/device\_info/device\_info.hcs中。修改该文件,在名为network的host中,名为device\_wlan\_chips的device中增加配置。模板如下: - - ``` - deviceN :: deviceNode { - policy = 0; - preload = 2; - moduleName = "HDF_WLAN_CHIPS"; - deviceMatchAttr = "hdf_wlan_chips_chip_name"; - serviceName = "driverName"; - } - ``` - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >moduleName 要与HDF WLAN 芯片驱动中的moduleName相同。 - -4. 修改Kconfig文件,让移植的WLAN模组出现再内核配置中 - - 在device/vendor\_name/drivers/Kconfig中增加配置菜单,模板如下 - - ``` - config DRIVERS_HDF_WIFI_chip_name - bool "Enable chip_name Host driver" - default n - depends on DRIVERS_HDF_WLAN help - Answer Y to enable chip_name Host driver. - ``` - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >请替换模板中的chip\_name为实际的芯片名称 - -5. 修改构建脚本,让驱动参与内核构建 - - 在源码文件//device/vendor\_name/drivers/lite.mk末尾追加如下内容 - - ``` - ifeq ($(LOSCFG_DRIVERS_HDF_WIFI_chip_name), y) - # 构建完成要链接一个叫hdf_wlan_chipdriver_chip_name的对象,建议按这个命名,防止冲突 - LITEOS_BASELIB += -lhdf_wlan_chipdriver_chip_name - # 增加构建目录gpio - LIB_SUBDIRS += ../peripheral/wifi/chip_name - endif - ``` - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >请替换模板中的chip\_name为实际的芯片名称 - - diff --git "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/03.\346\240\207\345\207\206\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/01.\346\240\207\345\207\206\347\263\273\347\273\237\347\247\273\346\244\215\346\214\207\345\215\227.md" "b/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/03.\346\240\207\345\207\206\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/01.\346\240\207\345\207\206\347\263\273\347\273\237\347\247\273\346\244\215\346\214\207\345\215\227.md" deleted file mode 100644 index 61c173b0f519f18afd91a9f117e4ba7148e2bffd..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/03.\346\240\207\345\207\206\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/01.\346\240\207\345\207\206\347\263\273\347\273\237\347\247\273\346\244\215\346\214\207\345\215\227.md" +++ /dev/null @@ -1,526 +0,0 @@ ---- -title: 标准系统移植指南 -permalink: /pages/01040301 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 标准系统移植指南 - -- [定义开发板](#section132mcpsimp) - - [定义SOC](#section135mcpsimp) - - [定义产品](#section145mcpsimp) - - [移植验证](#section163mcpsimp) - -- [内核移植](#section171mcpsimp) - - [1.为SOC添加内核构建的子系统](#section174mcpsimp) - - [2. 编译内核](#section182mcpsimp) - - [3. 移植验证](#section207mcpsimp) - -- [HDF驱动移植](#section210mcpsimp) - - [1. LCD](#section212mcpsimp) - - [2. 触摸屏](#section229mcpsimp) - - [3. WLAN](#section274mcpsimp) - - [4. 开发移植示例](#section11253153018415) - - -本文描述了移植一块开发板的通用步骤,和具体芯片相关的详细移植过程无法在此一一列举。后续社区还会陆续发布开发板移植的实例供开发者参考。 - -## 定义开发板 - -本文以移植名为MyProduct的开发板为例讲解移植过程,假定MyProduct是MyProductVendor公司的开发板,使用MySoCVendor公司生产的MySOC芯片作为处理器。 - -### 定义SOC - -在“//productdefine/common/device”目录下创建以SOC名字命名的json文件,并指定CPU的架构。 - -如要移植一个叫MySOC的SOC,这个SOC采用32位ARM内核。配置如下: - -//productdefine/common/device/MySOC.json - -``` -{ - "target_os": "ohos", - "target_cpu": "arm" -} -``` - -根据实际情况,这里的target\_cpu也可能是arm64 、riscv、 x86等。当前仅支持arm作为target\_cpu。 - -### 定义产品 - -在“//productdefine/common/products”目录下创建以产品名命名的json文件。该文件用于描述产品所使用的SOC 以及所需的子系统。配置如下 - -//productdefine/common/products/MyProduct.json - -``` -{ - "product_name": "MyProduct", - "product_company" : "MyProductVendor", - "product_device": "MySOC", - "version": "2.0", - "type": "standard", - "parts":{ - "ace:ace_engine_standard":{}, - "ace:napi":{}, - ... - "xts:phone_tests":{} - } -} - -``` - -主要的配置内容包括: - -1. product\_device:配置所使用的SOC -2. type:配置系统的级别, 这里直接standard即可 -3. parts:系统需要启用的子系统。子系统可以简单理解位一块独立构建的功能块。 - -已定义的子系统可以在“//build/subsystem\_config.json”中找到。当然你也可以定制子系统。 - -这里建议先拷贝Hi3516DV300 开发板的配置文件,删除掉 hisilicon\_products 这个子系统。这个子系统为Hi3516DV300 SOC编译内核,显然不适合MySOC。 - -### 移植验证 - -至此,你可以使用如下命令,启动你产品的构建了: - -``` -./build.sh --product-name MyProduct -``` - -构建完成后,可以在“//out/{device_name}/packages/phone/images”目录下看到构建出来的OpenHarmony镜像文件。 - -## 内核移植 - -这一步需要移植Linux内核,让Linux内核可以成功运行起来。 - -### 1.为SOC添加内核构建的子系统 - -修改文件 //build/subsystem\_config.json增加一个子系统. 配置如下: - -``` - "MySOCVendor_products": { - "project": "hmf/MySOCVendor_products", - "path": "device/MySOCVendor/MySOC/build", - "name": "MySOCVendor_products", - "dir": "device/MySOCVendor" - }, -``` - -接着需要修改定义产品的配置文件//productdefine/common/products/MyProduct.json,将刚刚定义的子系统加入到产品中。 - -### 2. 编译内核 - -OpenHarmony源码中提供了Linux 4.19的内核,归档在//kernel/linux-4.19。本节以该内核版本为例,讲解如何编译内核。 - -在子系统的定义中,描述了子系统构建的路径path,即\`//device/MySOCVendor/MySOC/build\`。这一节会在这个目录创建构建脚本,告诉构建系统如何构建内核。 - -建议的目录结构 - -``` -├── build -│ ├── kernel -│ │ ├── linux -│ │ ├──standard_patch_for_4_19.patch // 基于4.19版本内核的补丁 -│ ├── BUILD.gn -│ ├── ohos.build -``` - -BUILD.gn是subsystem构建的唯一入口。 - -期望的构建结果 - - - - - - - - - - - - -

文件

-

文件说明

-

$root_build_dir/packages/phone/images/uImage

-

内核镜像

-

$root_build_dir/packages/phone/images/uboot

-

bootloader镜像

-
- -### 3. 移植验证 - -启动编译,验证预期的kernel镜像是否成功生成。 - -## HDF驱动移植 - -### 1. LCD - -HDF为LCD设计了驱动模型。支持一块新的LCD,需要编写一个驱动,在驱动中生成模型的实例,并完成注册。 - -这些LCD的驱动被放置在//drivers/framework/model/display/driver/panel目录中。 - -- 创建Panel驱动 - -在驱动的Init方法中,需要调用RegisterPanel接口注册模型实例。如: - -``` -int32_t XXXInit(struct HdfDeviceObject *object) -{ - struct PanelData *panel = CreateYourPanel(); - - // 注册 - if (RegisterPanel(panel) != HDF_SUCCESS) { - HDF_LOGE("%s: RegisterPanel failed", __func__); - return HDF_FAILURE; - } - return HDF_SUCCESS; -} - -struct HdfDriverEntry g_xxxxDevEntry = { - .moduleVersion = 1, - .moduleName = "LCD_XXXX", - .Init = XXXInit, -}; - -HDF_INIT(g_xxxxDevEntry); -``` - -- 配置加载panel驱动产品的所有设备信息被定义在文件//vendor/MyProductVendor/MyProduct/config/device\_info/device\_info.hcs中。修改该文件,在display的host中,名为device\_lcd的device中增加配置。注意:moduleName 要与panel驱动中的moduleName相同。 - -``` -root { - ... - display :: host { - device_lcd :: device { - deviceN :: deviceNode { - policy = 0; - priority = 100; - preload = 2; - moduleName = "LCD_XXXX"; - } - } - } -} -``` - -更详细的驱动开发指导,请参考 [LCD](/pages/0105020401)。 - -### 2. 触摸屏 - -本节描述如何移植触摸屏驱动。触摸屏的驱动被放置在//drivers/framework/model/input/driver/touchscreen目录中。移植触摸屏驱动主要工作是向系统注册ChipDevice模型实例。 - -- 创建触摸屏器件驱动 - -在目录中创建名为touch\_ic\_name.c的文件。代码模板如下:注意:请替换ic\_name为你所适配芯片的名称。 - -``` -#include "hdf_touch.h" - -static int32_t HdfXXXXChipInit(struct HdfDeviceObject *device) -{ - ChipDevice *tpImpl = CreateXXXXTpImpl(); - if(RegisterChipDevice(tpImpl) != HDF_SUCCESS) { - ReleaseXXXXTpImpl(tpImpl); - return HDF_FAILURE; - } - return HDF_SUCCESS; -} - -struct HdfDriverEntry g_touchXXXXChipEntry = { - .moduleVersion = 1, - .moduleName = "HDF_TOUCH_XXXX", - .Init = HdfXXXXChipInit, -}; - -HDF_INIT(g_touchXXXXChipEntry); -``` - -其中ChipDevice中要提供若干方法。 - - - - - - - - - - - - - - - - - - - - - - - - -

方法

-

实现说明

-

int32_t (*Init)(ChipDevice *device)

-

器件初始化

-

int32_t (*Detect)(ChipDevice *device)

-

器件探测

-

int32_t (*Suspend)(ChipDevice *device)

-

器件休眠

-

int32_t (*Resume)(ChipDevice *device)

-

器件唤醒

-

int32_t (*DataHandle)(ChipDevice *device)

-

从器件读取数据,将触摸点数据填写入device->driver->frameData中

-

int32_t (*UpdateFirmware)(ChipDevice *device)

-

固件升级

-
- -- 配置产品,加载器件驱动 - - 产品的所有设备信息被定义在文件//vendor/MyProductVendor/MyProduct/config/device\_info/device\_info.hcs中。修改该文件,在名为input的host中,名为device\_touch\_chip的device中增加配置。注意:moduleName 要与触摸屏驱动中的moduleName相同。 - - -``` - deviceN :: deviceNode { - policy = 0; - priority = 130; - preload = 0; - permission = 0660; - moduleName = "HDF_TOUCH_XXXX"; - deviceMatchAttr = "touch_XXXX_configs"; - } -``` - -更详细的驱动开发指导,请参考 [TOUCHSCREEN](/pages/0105020402)。 - -### 3. WLAN - -Wi-Fi驱动分为两部分,一部分负责管理WLAN设备,另一个部分负责处理WLAN流量。HDF WLAN分别为这两部分做了抽象。目前支持SDIO接口的WLAN芯片。 - -**图 1** WLAN芯片 -![](/images/device-dev/porting/figure/WLAN芯片.png "WLAN芯片") - -支持一款芯片的主要工作是实现一个ChipDriver驱动。实现HDF\_WLAN\_CORE和NetDevice提供的接口。主要需要实现的接口有: - - - - - - - - - - - - - - - - - - - -

接口

-

定义头文件

-

说明

-

HdfChipDriverFactory

-

//drivers/framework/include/wifi/hdf_wlan_chipdriver_manager.h

-

ChipDriver的Factory,用于支持一个芯片多个Wi-Fi端口

-

HdfChipDriver

-

//drivers/framework/include/wifi/wifi_module.h

-

每个WLAN端口对应一个HdfChipDriver,用来管理一个特定的WLAN端口

-

NetDeviceInterFace

-

//drivers/framework/include/net/net_device.h

-

与协议栈之间的接口,如发送数据、设置网络接口状态等

-
- -建议适配按如下步骤操作: - -1.创建HDF驱动建议将代码放置在//device/MySoCVendor/peripheral/wifi/chip\_name/,文件模板如下: - -``` -static int32_t HdfWlanHisiChipDriverInit(struct HdfDeviceObject *device) { - static struct HdfChipDriverFactory factory = CreateChipDriverFactory(); - struct HdfChipDriverManager *driverMgr = HdfWlanGetChipDriverMgr(); - if (driverMgr->RegChipDriver(&factory) != HDF_SUCCESS) { - HDF_LOGE("%s fail: driverMgr is NULL!", __func__); - return HDF_FAILURE; - } - return HDF_SUCCESS; -} - -struct HdfDriverEntry g_hdfXXXChipEntry = { - .moduleVersion = 1, - .Init = HdfWlanXXXChipDriverInit, - .Release = HdfWlanXXXChipRelease, - .moduleName = "HDF_WIFI_CHIP_XXX" -}; - -HDF_INIT(g_hdfXXXChipEntry); -``` - -在CreateChipDriverFactory中,需要创建一个HdfChipDriverFactory,接口如下: - - - - - - - - - - - - - - - - - - - - - - - - - - - -

接口

-

说明

-

const char *driverName

-

当前driverName

-

int32_t (*InitChip)(struct HdfWlanDevice *device)

-

初始化芯片

-

int32_t (*DeinitChip)(struct HdfWlanDevice *device)

-

去初始化芯片

-

void (_ReleaseFactory)(struct HdfChipDriverFactory _factory)

-

释放HdfChipDriverFactory对象

-

struct HdfChipDriver _(_Build)(struct HdfWlanDevice *device, uint8_t ifIndex)

-

创建一个HdfChipDriver;输入参数中,device是设备信息,ifIndex是当前创建的接口在这个芯片中的序号

-

void (_Release)(struct HdfChipDriver _chipDriver)

-

释放chipDriver

-

uint8_t (*GetMaxIFCount)(struct HdfChipDriverFactory *factory)

-

获取当前芯片支持的最大接口数

-
- -HdfChipDriver需要实现的接口有 - - - - - - - - - - - - - - - - - - - - - -

接口

-

说明

-

int32_t (*init)(struct HdfChipDriver *chipDriver, NetDevice *netDev)

-

初始化当前网络接口,这里需要向netDev提供接口NetDeviceInterFace

-

int32_t (*deinit)(struct HdfChipDriver *chipDriver, NetDevice *netDev)

-

去初始化当前网络接口

-

struct HdfMac80211BaseOps *ops

-

WLAN基础能力接口集

-

struct HdfMac80211STAOps *staOps

-

支持STA模式所需的接口集

-

struct HdfMac80211APOps *apOps

-

支持AP模式所需要的接口集

-
- -2.编写配置文件,描述驱动支持的设备 - -在产品配置目录下创建芯片的配置文件//vendor/MyProductVendor/MyProduct/config/wifi/wlan\_chip\_chip\_name.hcs。 - -注意: 路径中的vendor\_name、product\_name、chip\_name请替换成实际名称。 - -模板如下: - -``` -root { - wlan_config { - chip_name :& chipList { - chip_name :: chipInst { - match_attr = "hdf_wlan_chips_chip_name"; /* 这是配置匹配属性,用于提供驱动的配置根 */ - driverName = "driverName"; /* 需要与HdfChipDriverFactory中的driverName相同*/ - sdio { - vendorId = 0x0296; - deviceId = [0x5347]; - } - } - } - } -} -``` - -3.编写配置文件,加载驱动 - -产品的所有设备信息被定义在文件//vendor/MyProductVendor/MyProduct/config/device\_info/device\_info.hcs中。修改该文件,在名为network的host中,名为device\_wlan\_chips的device中增加配置。注意:moduleName 要与触摸屏驱动中的moduleName相同。 - -``` - deviceN :: deviceNode { - policy = 0; - preload = 2; - moduleName = "HDF_WLAN_CHIPS"; - deviceMatchAttr = "hdf_wlan_chips_chip_name"; - serviceName = "driverName"; - } -``` - -4.构建驱动 - -- 创建内核菜单在//device/MySoCVendor/peripheral目录中创建Kconfig文件,内容模板如下: - -``` -config DRIVERS_WLAN_XXX - bool "Enable XXX WLAN Host driver" - default n - depends on DRIVERS_HDF_WIFI - help - Answer Y to enable XXX Host driver. Support chip xxx -``` - -接着修改文件//drivers/adapter/khdf/linux/model/network/wifi/Kconfig,在文件末尾加入如下代码将配置菜单加入内核中,如: - -``` -source "../../../../../device/MySoCVendor/peripheral/Kconfig" -``` - -- 创建构建脚本 - - 在//drivers/adapter/khdf/linux/model/network/wifi/Makefile文件末尾增加配置,模板如下: - - -``` -HDF_DEVICE_ROOT := $(HDF_DIR_PREFIX)/../device -obj-$(CONFIG_DRIVERS_WLAN_XXX) += $(HDF_DEVICE_ROOT)/MySoCVendor/peripheral/build/standard/ -``` - -当在内核中开启DRIVERS\_WLAN\_XXX开关时,会调用//device/MySoCVendor/peripheral/build/standard/中的makefile。更多详细的开发手册,请参考[WLAN开发](/pages/0107010101)。 - -### 4. 开发移植示例 - -开发移植示例请参考[DAYU开发板](https://gitee.com/openharmony-sig/devboard_device_hihope_build/blob/master/DAYU%20%E5%B9%B3%E5%8F%B0OpenHarmony%20%E9%80%82%E9%85%8D%E6%8C%87%E5%AF%BC%20-202108.pdf)。 - diff --git "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/03.\346\240\207\345\207\206\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/02.\344\270\200\347\247\215\345\277\253\351\200\237\347\247\273\346\244\215OpenHarmonyLinux\345\206\205\346\240\270\347\232\204\346\226\271\346\263\225.md" "b/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/03.\346\240\207\345\207\206\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/02.\344\270\200\347\247\215\345\277\253\351\200\237\347\247\273\346\244\215OpenHarmonyLinux\345\206\205\346\240\270\347\232\204\346\226\271\346\263\225.md" deleted file mode 100644 index 85cc5cdb18a9d574c5b04a46b810a71126539f1f..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/03.\346\240\207\345\207\206\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\214\207\345\257\274/02.\344\270\200\347\247\215\345\277\253\351\200\237\347\247\273\346\244\215OpenHarmonyLinux\345\206\205\346\240\270\347\232\204\346\226\271\346\263\225.md" +++ /dev/null @@ -1,320 +0,0 @@ ---- -title: 一种快速移植OpenHarmonyLinux内核的方法 -permalink: /pages/01040302 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 一种快速移植OpenHarmony Linux内核的方法 - -- [移植概述](#移植概述) -- [移植到三方芯片平台的整体思路](#移植到三方芯片平台的整体思路) - - [内核态层和用户态层](#内核态层和用户态层) - - [获得内核态层的两种方法](#获得内核态层的两种方法) - - [借助已有Linux内核来移植OpenHarmony的流程](#section1233187263176) -- [移植到三方芯片平台的步骤](#移植到三方芯片平台的步骤) - - [整体构建环境的准备](#整体构建环境的准备) - - [内核态基础代码的移植](#内核态基础代码的移植) - - [内核态必选特性HDF的移植](#内核态必选特性hdf的移植) - - [编译Image](#编译image) - - [编译和运行HDF测试用例(可选)](#编译和运行hdf测试用例-可选-) - -## 移植概述 - - -本文面向希望将OpenHarmony移植到三方芯片平台硬件的开发者,介绍一种借助三方芯片平台自带Linux内核的现有能力,快速移植OpenHarmony到三方芯片平台的方法。 - - -## 移植到三方芯片平台的整体思路 - - -### 内核态层和用户态层 - -为了更好的解释整个内核移植,首先需要介绍一些概念: - -我们可以把OpenHarmony简单的分为 - -OpenHarmony = OpenHarmony内核态层 + OpenHarmony用户态层 - -![zh-cn_image_0000001162805936](/images/device-dev/porting/figure/zh-cn_image_0000001162805936.png) - -其中OpenHarmony内核态层就是上图的紫色部分,可以看到,它主要由内核本身(如Linux Kernel,LiteOS),和一些运行在内核态的一些特性组成,比如HDF等。 - -而OpenHarmony用户态层,在上图,就是紫色之外的部分。可以看到,由下往上看,它主要由系统服务层,框架层,应用层组成。在这儿我们将这三层整体称为“OpenHarmony用户态层”。 - -为什么这么区分呢?因为我们这篇文章主要是要讨论如何快速的把OpenHarmony移植到三方芯片平台上。而OpenHarmony的用户态层,整体来说和三方芯片平台的耦合度不高,移植较为方便。而内核态层中的内核本身以及HDF驱动框架等,和三方芯片平台的耦合度较高,是移植的重难点。我们先做这个区分,就是为了先把聚光灯打到我们最需要关注的OpenHarmony内核态层上,开始分析和解题。另外说明,本文只包含Linux内核的快速移植,不包含LiteOS的移植。 - - -### 获得内核态层的两种方法 - -为了表述方便,我们在下文部分地方用“OH”代替“OpenHarmony”。 - -将OH内核态层继续分解 - -OH内核态层 = OH Linux内核 + OH内核态特性(可选特性或者必选特性,如必选特性HDF,今后的可选特性HMDFS等) - -而OH Linux内核 = 标准LTS Linux内核 + 三方SoC芯片平台代码 + OH内核态基础代码(支撑OH用户态层运行的最基础代码) - -因此OH内核态层 = 标准LTS Linux内核 + 三方SoC芯片平台代码 + OH内核态基础代码 + OH内核态特性(如HDF,今后的HMDFS等) - -![zh-cn_image_0000001208365855](/images/device-dev/porting/figure/zh-cn_image_0000001208365855.png) - -而将前两项组合,标准LTS Linux 内核 + 三方SoC芯片平台代码,其实就是一个三方Linux内核的基础组成。从上面的推导可以看出,OpenHarmony内核态层其实能够由两种方法得到: - -方法一:OH内核态层 = 三方Linux内核 + OH内核态基础代码 + OH内核态特性(如HDF,今后的HMDFS等) - -也就是直接借助三方Linux内核,再加上基础OH内核态基础代码、以及HDF等OH内核态特性。 - -方法二:OH内核态层 = OH Linux内核 + OH内核态特性(如HDF,今后的HMDFS等) - -也就是直接采用OH Linux内核,然后再加入OH的其他内核态特性。 - -当前方法二中OH Linux内核支持的三方芯片平台还不够丰富。为了能够响应三方开发者快速移植OpenHarmony的要求,下文会着重介绍方法一,即借助三方已有的Linux内核,来快速移植OpenHarmony。 - - -### 借助已有Linux内核来移植OpenHarmony的流程 - - -整个移植流程可以分为三步: - -1. 准备整体构建环境,包括将三方芯片平台的现有内核代码拷贝到OpenHarmony的整体编译环境下。 - -2. OpenHarmony内核态基础代码的移植。 - -3. OpenHarmony内核态必选特性(如HDF等)的移植。 - -详细步骤在接下来的章节中介绍。 - - -## 移植到三方芯片平台的步骤 - -下面以树莓派3b (BCM2837) 为例,演示将OpenHarmony移植到树莓派的过程。 - - -### 整体构建环境的准备 - -1. 将三方内核纳入OpenHarmony编译环境。 - - 完整编译过一遍标准Hi3516DV300内核之后,clone树莓派内核源码并复制到manifest输出目录下: - - ``` - export PROJ_ROOT=[OpenHarmony manifest] - git clone https://gitee.com/xfan1024/oh-rpi3b-kernel.git - cp -r oh-rpi3b-kernel $PROJ_ROOT/out/KERNEL_OBJ/kernel/src_tmp/linux-rpi3b - ``` - -2. 配置树莓派内核编译环境。 - ```shell - # 进入树莓派kernel目录 - cd out/KERNEL_OBJ/kernel/src_tmp/linux-rpi3b - - # 配置编译环境,使用工程项目自带的clang - export PATH=$PROJ_ROOT/prebuilts/clang/ohos/linux-x86_64/llvm/bin:$PROJ_ROOT/prebuilts/gcc/linux-x86/arm/gcc-linaro-7.5.0-arm-linux-gnueabi/bin/:$PATH - export MAKE_OPTIONS="ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- CC=clang HOSTCC=clang" - export PRODUCT_PATH=vendor/hisilicon/Hi3516DV300 - ``` - -3. 注释掉clang不识别的flag。 - - PROJ_ROOT/out/KERNEL_OBJ/kernel/src_tmp/linux-rpi3b/arch/arm/Makefile注释掉以下这一行: - - ```makefile - KBUILD_CFLAGS +=-fno-omit-frame-pointer -mapcs -mno-sched-prolog - ``` - - -### 内核态基础代码的移植 - -目前OpenHarmony内核态的基础代码,主要是日志服务相关。轻量化内核日志服务代码包含: - -``` -drivers/staging/hilog -drivers/staging/hievent -``` - -将以上代码,从OpenHarmony内核代码目录kernel/linux/linux-4.19/drivers/staging中,拷贝到out/KERNEL_OBJ/kernel/src_tmp/linux-rpi3b/drivers/staging 下。 - -在三方内核的drivers/staging/Kconfig文件内增加如下代码: -``` -source "drivers/staging/hilog/Kconfig" - -source "drivers/staging/hievent/Kconfig" - -``` - -在内核config项中打开对应的CONFIG控制宏:CONFIG_HILOG和CONFIG_HIEVENT。 - -具体日志使用说明请参见:[Hilog_lite组件介绍](https://gitee.com/openharmony/hiviewdfx_hilog_lite/blob/master/README_zh.md)。 - - -### 内核态必选特性HDF的移植 - -1. 打HDF补丁。 - - 在Linux内核打HDF补丁时,执行补丁shell脚本合入HDF补丁。 - - 1. 配置HDF补丁脚本的三个变量参数。 - 2. 获取patch_hdf.sh脚本。 - 3. 执行patch_hdf.sh脚本依次传入三个变量参数。 - - patch_hdf.sh脚本三个参数含义为:第一个入参为工程根目录路径,第二入参为内核目录路径,第三个入参为hdf补丁文件。 - - ``` - ./patch_hdf.sh [工程根目录路径] [内核目录路径] [hdf补丁文件] - ``` - - 以树莓派3b为示例介绍: - - ``` - # 进入树莓派kernel目录 - $PROJ_ROOT/drivers/adapter/khdf/linux/patch_hdf.sh \ - $PROJ_ROOT # 指定工程根目录路径 \ - $PROJ_ROOT/out/KERNEL_OBJ/kernel/src_tmp/linux-rpi3b # 打补丁的内核目录路径 \ - $PROJ_ROOT/kernel/linux/patches/linux-4.19/hi3516dv300_patch/hdf.patch # HDF补丁文件 - ``` - -2. 配置config。 - - 提供HDF基本配置,如果需要其他功能,通过menuconfig打开对应驱动开关即可。 - - HDF补丁执行成功后,默认HDF开关是关闭的,打开HDF基本配置选项如下: - - ``` - CONFIG_DRIVERS_HDF=y - CONFIG_HDF_SUPPORT_LEVEL=2 - CONFIG_DRIVERS_HDF_PLATFORM=y - CONFIG_DRIVERS_HDF_PLATFORM_MIPI_DSI=y - CONFIG_DRIVERS_HDF_PLATFORM_GPIO=y - CONFIG_DRIVERS_HDF_PLATFORM_I2C=y - CONFIG_DRIVERS_HDF_PLATFORM_UART=y - CONFIG_DRIVERS_HDF_TEST=y - ``` - - 或者通过menuconfig界面打开HDF相关配置,命令如下: - - ``` - # 生成.config配置文件 - make ${MAKE_OPTIONS} rpi3b_oh_defconfig - - # 更改HDF内核配置 - make ${MAKE_OPTIONS} menuconfig - # [*] Device Drivers - # [*] HDF driver framework support ---> - ``` - - 配置如下(在Device Drivers -> HDF driver framework support目录下): - - ![zh-cn_image_0000001208524821](/images/device-dev/porting/figure/zh-cn_image_0000001208524821.png) - - -### 编译Image - -``` -# 执行编译命令 -make ${MAKE_OPTIONS} -j33 zImage -``` - - -### 编译和运行HDF测试用例(可选) - -**简介** - -HDF(Hardware Driver Foundation)自测试用例,用于测试HDF框架和外设的基本功能,本文主要介绍HDF内核态用例测试方法。 - -**预置条件** - -测试前需要在menuconfig里检查HDF测试开关CONFIG_DRIVERS_HDF_TEST=y,代码全量编译通过。 - -**用例编译和测试方法** - - -1. 编译hdf测试用例。 - -2. 用hdc_std工具推送测试文件到设备中。 - -3. 进入设备data/test目录,执行测试文件即可。 - -用例编译和测试详细步骤如下: - -1. 编译hdf测试用例。 - - 编译hdf测试用例命令和文件路径如下: - - ``` - ./build.sh --product-name Hi3516DV300 --build-target hdf_test - ``` - - 等待编译完成。 - -2. 将测试文件移动到目标移植设备上(以树莓派为例) - - - - 1. 先在树莓派里新建data/test目录。 - ``` - mkdir -p data/test - ``` - 2. 推送依赖库和测试用例到树莓派。 - ``` - hdc_std file send XXX\out\{device_name}\hdf\hdf\libhdf_test_common.z.so /system/lib - hdc_std file send XXX\out\{device_name}\tests\unittest\hdf\config\hdf_adapter_uhdf_test_config /data/test - hdc_std file send XXX\out\{device_name}\tests\unittest\hdf\devmgr\DevMgrTest /data/test - hdc_std file send XXX\out\{device_name}\tests\unittest\hdf\osal\OsalTest /data/test - hdc_std file send XXX\out\{device_name}\tests\unittest\hdf\sbuf\SbufTest /data/test - ``` - 方法二:移动到储存卡内,启动树莓派之后装载。 - - 1. 拔掉树莓派连接电脑的串口、USB线,然后拔下数据卡。 - 2. 将数据卡插入到电脑的读取口,将编译好的zImage和测试文件夹test/下载到电脑,然后移动到数据卡的根目录下。zImage文件会被替换,请提前做好备份。 - 3. 最后将数据卡插回树莓派。 - ``` - # 让树莓派文件系统读取储存卡根目录 - mount -t vfat /dev/block/mmcblk0p1 /boot - cd /boot/[测试文件目录] - # 允许修改系统文件 - mount -o remount,rw / - # 安装测试用库 - mv libhdf_test_common.z.so /system/lib - mkdir /data/test - mv * /data/test - ``` - -3. 执行测试 - 1. 进入目录执行测试文件目录data/test。 - ``` - cd /data/test - ``` - 2. 修改文件执行权限。 - ``` - chmod 777 hdf_adapter_uhdf_test_config DevMgrTest OsalTest SbufTest - ``` - 3. 开始测试。 - ``` - ./hdf_adapter_uhdf_test_config - ./DevMgrTest - ./OsalTest - ./SbufTest - ``` - 4. 如果所有测试文件输出均显示PASSED,那么HDF功能即安装成功。 - - 示例:DevMgrTest用例成功结果显示: - ``` - ./DevMgrTest - Running main() from gmock_main.cc - [==========] Running 1 test from 1 test case. - [----------] Global test environment set-up. - [----------] 1 test from DevMgrTest - [ RUN ] DevMgrTest.DriverLoaderTest_001 - [ OK ] DevMgrTest.DriverLoaderTest_001 (0 ms) - [----------] 1 test from DevMgrTest (0 ms total) - [----------] Global test environment tear-down - Gtest xml output finished - [==========] 1 test from 1 test case ran. (0 ms total) - [ PASSED ] 1 test. - ``` diff --git "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/04.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\344\270\211\346\226\271\345\272\223\347\247\273\346\244\215\346\214\207\345\257\274/01.\346\246\202\350\277\260.md" "b/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/04.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\344\270\211\346\226\271\345\272\223\347\247\273\346\244\215\346\214\207\345\257\274/01.\346\246\202\350\277\260.md" deleted file mode 100644 index d274eed3492f45a76baea5884c800e70118198af..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/04.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\344\270\211\346\226\271\345\272\223\347\247\273\346\244\215\346\214\207\345\257\274/01.\346\246\202\350\277\260.md" +++ /dev/null @@ -1,17 +0,0 @@ ---- -title: 概述 -permalink: /pages/01040401 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 概述 - -本文为OpenHarmony开发者提供一些组织编译形式比较常见(CMakeLists、Makefile)的三方库的移植指南,该指南当前仅适用于Hi3516DV300和Hi3518EV300两个平台,文中着重介绍各编译组织方式下工具链的设置方法以及如何将该库的编译添加到OpenHarmony整个工程的构建中。 - diff --git "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/04.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\344\270\211\346\226\271\345\272\223\347\247\273\346\244\215\346\214\207\345\257\274/02.CMake\346\226\271\345\274\217\347\273\204\347\273\207\347\274\226\350\257\221\347\232\204\345\272\223\347\247\273\346\244\215.md" "b/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/04.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\344\270\211\346\226\271\345\272\223\347\247\273\346\244\215\346\214\207\345\257\274/02.CMake\346\226\271\345\274\217\347\273\204\347\273\207\347\274\226\350\257\221\347\232\204\345\272\223\347\247\273\346\244\215.md" deleted file mode 100644 index 9c52e6bfb2cae723b9f9129b2009490dc57eb7fc..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/04.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\344\270\211\346\226\271\345\272\223\347\247\273\346\244\215\346\214\207\345\257\274/02.CMake\346\226\271\345\274\217\347\273\204\347\273\207\347\274\226\350\257\221\347\232\204\345\272\223\347\247\273\346\244\215.md" +++ /dev/null @@ -1,448 +0,0 @@ ---- -title: CMake方式组织编译的库移植 -permalink: /pages/01040402 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# CMake方式组织编译的库移植 - -- [源码获取](#section1771132116245) -- [移植思路](#section9737174410328) -- [交叉编译](#section38205577332) - - [编译参考](#section1088111263418) - - [设置执行交叉编译](#section8168182883515) - -- [测试](#section6686144293611) -- [将该库编译添加到OpenHarmony工程中](#section1651053153715) - -以double-conversion库为例,其移植过程如下文所示 - -## 源码获取 - -从仓库[获取double-conversion源码](https://github.com/google/double-conversion),其目录结构如下表: - -**表 1** 源码目录结构 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

描述

-

double-conversion/cmake/

-

CMake组织编译使用到的模板

-

double-conversion/double-conversion/

-

源文件目录

-

double-conversion/msvc/

-

-

-

double-conversion/test/

-

测试用例源文件

-

double-conversion/.gitignore

-

-

-

double-conversion/AUTHORS

-

-

-

double-conversion/BUILD

-

-

-

double-conversion/CMakeLists.txt

-

CMake方式顶层编译组织文件

-

double-conversion/COPYING

-

-

-

double-conversion/Changelog

-

-

-

double-conversion/LICENSE

-

-

-

double-conversion/Makefile

-

-

-

double-conversion/README.md

-

-

-

double-conversion/SConstruct

-

-

-

double-conversion/WORKSPACE

-

-

-
- -## 移植思路 - -移植思路:通过修改工具链,交叉编译该三方库,生成OpenHarmony平台的可执行文件,最后再通过GN调用CMake的方式添加到OpenHarmony工程中。 - -## 交叉编译 - -### 编译参考 - -代码仓库的[README.md](https://github.com/google/double-conversion/blob/master/README.md)中详细介绍了使用CMake编译double-conversion库的步骤,以及测试方法。本文参考该指导设置该库的编译配置,并完成测试。若开发人员在移植过程中对该库的编译选项配置有疑惑的地方,可参考该指导。对于其他使用CMake可独立编译的三方库,在移植时可以参考其自带的编译指导。 - -### 设置执行交叉编译 - -CMake方式可通过指定工具链进行交叉编译,修改并编译该库,生成OpenHarmony平台的可执行文件,步骤如下: - -1. 设置工具链 - - 将下列clang工具链配置添加到该工程的顶层CMakeLists.txt(即[表1中的该文件](#table824211132418))中即可。 - - ``` - set(CMAKE_CROSSCOMPILING TRUE) - set(CMAKE_SYSTEM_NAME Generic) - set(CMAKE_CXX_COMPILER_ID Clang) - set(CMAKE_TOOLCHAIN_PREFIX llvm-) - #指定c编译工具(确保工具链所在路径已经添加到了PATH环境变量中)和编译标志,使用clang编译时标志中必须指定--target,否则无法交叉编译。 - set(CMAKE_C_COMPILER clang) - set(CMAKE_C_FLAGS "--target=arm-liteos -D__clang__ -march=armv7-a -w") - #指定c++编译工具(确保工具链所在路径已经添加到了PATH环境变量中)和编译标志,必须指定--target,否则无法交叉编译。 - set(CMAKE_CXX_COMPILER clang++) - set(CMAKE_CXX_FLAGS "--target=arm-liteos -D__clang__ -march=armv7-a -w") - #指定链接工具和链接标志,必须指定--target和--sysroot,其中OHOS_ROOT_PATH可通过cmake命令后缀参数来指定。 - set(MY_LINK_FLAGS "--target=arm-liteos --sysroot=${OHOS_SYSROOT_PATH}") - set(CMAKE_LINKER clang) - set(CMAKE_CXX_LINKER clang++) - set(CMAKE_C_LINKER clang) - set(CMAKE_C_LINK_EXECUTABLE - "${CMAKE_C_LINKER} ${MY_LINK_FLAGS} -o ") - set(CMAKE_CXX_LINK_EXECUTABLE - "${CMAKE_CXX_LINKER} ${MY_LINK_FLAGS} -o ") - #指定链接库的查找路径。 - set(CMAKE_SYSROOT ${OHOS_SYSROOT_PATH}) - ``` - -2. 执行编译 - - linux命令行中进入double-conversion的源文件目录(即[表1所示目录](#table824211132418)),执行下列命令: - - ``` - mkdir build && cd build - cmake .. -DBUILD_TESTING=ON -DOHOS_SYSROOT_PATH="..." - make -j - ``` - - 其中OHOS\_SYSROOT\_PATH需用绝对路径指定出sysroot目录的位置,以OpenHarmony为例即目录out/hispark\_xxx/ipcamera\_hispark\_xxx/sysroot的绝对路径。上述目录会在全量编译后生成,因此移植前先完成一次全量编译。 - -3. 查看结果 - - 步骤2操作完成后,build目录下会生成静态库文件和测试用例: - - **表 2** 编译生成文件目录结构 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

描述

-

double-conversion/build/libdouble-conversion.a

-

生成的静态库文件

-

double-conversion/build/test/

-

目录下存放生成的测试用例和相关CMake缓存文件

-

double-conversion/build/CMakeCache.txt

-

CMake构建过程中的缓存文件

-

double-conversion/build/CMakeFiles/

-

-

-

double-conversion/build/cmake_install.cmake

-

-

-

double-conversion/build/CTestTestfile.cmake

-

-

-

double-conversion/build/DartConfiguration.tcl

-

-

-

double-conversion/build/generated/

-

-

-

double-conversion/build/Makefile

-

-

-

double-conversion/build/Testing/

-

-

-
- - -## 测试 - -1. 搭建OpenHarmony环境 - - 以hi3518ev300为例,编译出OpenHarmony镜像,烧写到开发板,参考[开发Hi3518第一个示例程序](/pages/010201030305)。 - - 进入系统如下所示: - - **图 1** OpenHarmony启动成功界面 - ![](/images/device-dev/porting/figure/OpenHarmony启动成功界面.png "OpenHarmony启动成功界面") - -2. 挂载nfs目录,将[表2](#table1452412391911)中test目录下cctest可执行文件放入nfs目录 -3. 执行用例 - - 该库采用非交叉编译时用例是通过make test执行,CMake会有相关的执行结果统计;交叉编译时无法使用该方法,因此可直接执行生成的测试文件完成测试。 - - - 挂载成功后执行下列命令可列出用例所有条目: - - ``` - cd nfs - ./cctest --list - ``` - - 上述命令执行结果部分展示: - - ``` - test-bignum/Assign< - test-bignum/ShiftLeft< - test-bignum/AddUInt64< - test-bignum/AddBignum< - test-bignum/SubtractBignum< - test-bignum/MultiplyUInt32< - test-bignum/MultiplyUInt64< - test-bignum/MultiplyPowerOfTen< - test-bignum/DivideModuloIntBignum< - test-bignum/Compare< - test-bignum/PlusCompare< - test-bignum/Square< - test-bignum/AssignPowerUInt16< - test-bignum-dtoa/BignumDtoaVariousDoubles< - test-bignum-dtoa/BignumDtoaShortestVariousFloats< - test-bignum-dtoa/BignumDtoaGayShortest< - test-bignum-dtoa/BignumDtoaGayShortestSingle< - test-bignum-dtoa/BignumDtoaGayFixed< - test-bignum-dtoa/BignumDtoaGayPrecision< - test-conversions/DoubleToShortest< - test-conversions/DoubleToShortestSingle< - ... - ``` - - - 以test-bignum条目为例,执行下列命令开始测试: - - ``` - ./cctest test-bignum - ``` - - 测试结果如下则表示通过: - - ``` - Ran 13 tests. - ``` - - -## 将该库编译添加到OpenHarmony工程中 - -1. 复制库到OpenHarmony工程中 - - 拷贝已经能够成功交叉编译的库到OpenHarmony的third\_party目录,为了不修改要移植的三方库目录下的BUILD.gn文件,再添加一层目录放置新增的gn转CMake编译适配文件,新增的文件有BUILD.gn、build\_thirdparty.py、 config.gni,新增后的目录结构如下所示。 - - **表 3** 添加到工程后的目录结构 - - - - - - - - - - - - - - - - - - - -

名称

-

描述

-

openHarmony/third_party/double-conversion/BUILD.gn

-

将三方库加入工程的gn适配文件

-

openHarmony/third_party/double-conversion/build_thirdparty.py

-

GN调用shell命令脚本文件,由上面GN文件将相关命令传入,实现GN转CMake

-

openHarmony/third_party/double-conversion/config.gni

-

三方库编译配置文件,可修改该文件来配置用例是否参与构建等

-

openHarmony/third_party/double-conversion/double-conversion/

-

要移植的三方库目录

-
- -2. 添加gn到CMake适配文件 - - - **新增的BUILD.gn文件实现如下,其他采用CMake方式可独立编译的三方库移植到OpenHarmony平台时只需修改路径即可**。 - - ``` - import("config.gni") - group("double-conversion") { - if (ohos_build_thirdparty_migrated_from_fuchisa == true) { - deps = [":make"] - } - } - if (ohos_build_thirdparty_migrated_from_fuchisa == true) { - action("make") { - script = "//third_party/double-conversion/build_thirdparty.py" - outputs = ["$root_out_dir/log_dc.txt"] - exec_path = rebase_path(rebase_path("./build", ohos_third_party_dir)) - command = "rm * .* -rf && $CMAKE_TOOLS_PATH/cmake .. $CMAKE_FLAG $CMAKE_TOOLCHAIN_FLAG && make -j" - args = [ - "--path=$exec_path", - "--command=${command}" - ] - } - } - ``` - - - **新增的config.gni用于配置该库,实现如下,其他采用CMake方式可独立编译的三方库移植到OpenHarmony时只需修改CMAKE\_FLAG的配置即可。** - - ``` - #CMAKE_FLAG: config compile feature - CMAKE_FLAG = "-DBUILD_TESTING=ON -DCMAKE_CXX_STANDARD=11" - - #toolchain:follow up-layer,depend on $ohos_build_compiler - if (ohos_build_compiler == "clang") { - CMAKE_TOOLCHAIN_FLAG = "-DOHOS_SYSROOT_PATH=${ohos_root_path}prebuilts/lite/sysroot/" - } else { - CMAKE_TOOLCHAIN_FLAG = "" - } - - #CMake tools path,no need setting if this path already joined to $PATH. - CMAKE_TOOLS_PATH = "setting CMake tools path..." - ``` - - - **新增的build\_thirdparty.py实现如下,其他采用CMake方式可独立编译的三方库移植到OpenHarmony时无需修改即可使用。** - - ``` - import os - import sys - from subprocess import Popen - import argparse - import shlex - - def cmd_exec(command): - cmd = shlex.split(command) - proc = Popen(cmd) - proc.wait() - ret_code = proc.returncode - if ret_code != 0: - raise Exception("{} failed, return code is {}".format(cmd, ret_code)) - - def main(): - parser = argparse.ArgumentParser() - parser.add_argument('--path', help='Build path.') - parser.add_argument('--command', help='Build command.') - parser.add_argument('--enable', help='enable python.', nargs='*') - args = parser.parse_args() - - if args.enable: - if args.enable[0] == 'false': - return - - if args.path: - curr_dir = os.getcwd() - os.chdir(args.path) - if args.command: - if '&&' in args.command: - command = args.command.split('&&') - for data in command: - cmd_exec(data) - else: - cmd_exec(args.command) - os.chdir(curr_dir) - - if __name__ == '__main__': - sys.exit(main()) - ``` - - - 在配置文件中添加开关控制该库编译,默认设为关闭 - - 在//build/lite/ohos\_var.gni文件中添加下列配置: - - ``` - declare_args() { - ohos_build_thirdparty_migrated_from_fuchisa = true - } - ``` - -3. 编译构建 - - - 手动单独构建: - - 执行下列命令 - - ``` - hb build -T //third_party/double-conversion:double-conversion - ``` - - 编译成功则[build](#li15717101715249)目录下会生成静态库文件和测试用例 - - diff --git "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/04.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\344\270\211\346\226\271\345\272\223\347\247\273\346\244\215\346\214\207\345\257\274/03.Makefile\346\226\271\345\274\217\347\273\204\347\273\207\347\274\226\350\257\221\347\232\204\345\272\223\347\247\273\346\244\215.md" "b/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/04.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\344\270\211\346\226\271\345\272\223\347\247\273\346\244\215\346\214\207\345\257\274/03.Makefile\346\226\271\345\274\217\347\273\204\347\273\207\347\274\226\350\257\221\347\232\204\345\272\223\347\247\273\346\244\215.md" deleted file mode 100644 index 2e9e886f4d37cb2dcc7973fa398d7eb17648bf26..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/04.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\344\270\211\346\226\271\345\272\223\347\247\273\346\244\215\346\214\207\345\257\274/03.Makefile\346\226\271\345\274\217\347\273\204\347\273\207\347\274\226\350\257\221\347\232\204\345\272\223\347\247\273\346\244\215.md" +++ /dev/null @@ -1,322 +0,0 @@ ---- -title: Makefile方式组织编译的库移植 -permalink: /pages/01040403 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# Makefile方式组织编译的库移植 - -- [源码获取](#section114115321416) -- [设置交叉编译](#section81263255384) -- [测试](#section1830015913391) -- [将该库编译添加到OpenHarmony工程中](#section1898016213406) - -以yxml库为例,其移植过程如下文所示 - -## 源码获取 - -从仓库[获取yxml源码](https://github.com/getdnsapi/yxml),其目录结构如下表: - -**表 1** 源码目录结构 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

描述

-

yxml/bench/

-

benchmark相关代码

-

yxml/test/

-

测试输入输出文件,及测试脚本

-

yxml/Makefile

-

编译组织文件

-

yxml/.gitattributes

-

-

-

yxml/.gitignore

-

-

-

yxml/COPYING

-

-

-

yxml/yxml.c

-

-

-

yxml/yxml.c.in

-

-

-

yxml/yxml-gen.pl

-

-

-

yxml/yxml.h

-

-

-

yxml/yxml.md

-

-

-

yxml/yxml-states

-

-

-
- -## 设置交叉编译 - -设置Makefile的交叉编译工具链,修改并编译该库,生成OpenHarmony平台的可执行文件,步骤如下: - -1. 设置工具链 - - 将下列clang工具链配置替换掉yxml库根目录的MakeFile(即[表1中的文件](#table16520154171813))中的原有配置。 - - clang工具链配置 - - ``` - #设置交叉编译工具链,确保工具链所在路径已经添加到了PATH环境变量中 - CC:=clang - AR:=llvm-ar - #cflags中必须要添加--target及--sysroot选项 - CFLAGS:=-Wall -Wextra -Wno-unused-parameter -O2 -g --target=arm-liteos -march=armv7-a --sysroot=$(OHOS_SYSROOT_PATH) - ``` - - 原有配置 - - ``` - CC:=gcc - AR:=ar - CFLAGS:=-Wall -Wextra -Wno-unused-parameter -O2 -g - ``` - -2. 执行编译 - - linux命令行中进入yxml的源文件目录(即图1所示目录),执行下列命令: - - ``` - make test OHOS_SYSROOT_PATH=... - ``` - - 其中OHOS\_SYSROOT\_PATH需用绝对路径指定出sysroot所在目录,以OpenHarmony为例即源码根目录下out/hispark\_xxx/ipcamera\_hispark\_xxx/sysroot目录的绝对路径。上述目录会在全量编译后生成,因此移植前先完成一次全量编译。 - -3. 查看结果 - - 步骤2操作完成后,yxml下会生成out目录,里面有静态库文件和测试用例: - - **表 2** yxml编译生成目录 - - - - - - - - - - - - - -

名称

-

描述

-

openHarmony/third_party/yxml/yxml/out/lib/

-

编译生成的静态库的存放目录

-

openHarmony/third_party/yxml/yxml/out/test/

-

编译生成的测试用例及其输入输出等文件的存放目录

-
- - -## 测试 - -yxml库测试步骤与double-conversion库基本一致,可参考[CMake方式组织编译的库移植](/pages/01040402#section6686144293611)的测试过程,以下内容介绍yxml库测试用例的使用方法: - -**表 3** 生成的test目录结构示意 - - - - - - - - - - - - - - - - - - - -

名称

-

描述

-

openHarmony/third_party/yxml/yxml/out/test/test.sh

-

自动化测试脚本,由于OpenHarmony不支持脚本运行,因此无法使用,可参考其内容手动测试

-

openHarmony/third_party/yxml/yxml/out/test/test

-

用于测试的可执行文件

-

openHarmony/third_party/yxml/yxml/out/test/*.xml

-

测试输入文件

-

openHarmony/third_party/yxml/yxml/out/test/*.out

-

期望的输出文件

-
- -test.sh内容如下所示: - -``` -#!/bin/sh -for i in *.xml; do - b=`basename $i .xml` - o=${b}.out - t=${b}.test - ./test <$i >$t - if [ -n "`diff -q $o $t`" ]; then - echo "Test failed for $i:" - diff -u $o $t - exit 1 - fi -done -echo "All tests completed successfully." -``` - -由于OpenHarmony的shell中暂不支持输入输出重定向(<和\>),所以测试时需要将输入\*.xml文件内容直接复制进shell后回车,输出内容会直接展示在shell窗口。过程如下: - -下列操作假定已按照2.4节的步骤搭建OpenHarmony,挂载并进入nfs目录: - -1. 执行下列命令 - - ``` - ./test - ``` - -2. 复制\*.xml内容到shell - - 以[test目录](#table115941423164318)下pi01.xml为例,内容如下,输入到shell并回车: - - ``` - - ``` - -3. 比较shell中输出的内容与[test目录](#table115941423164318)中对应的\*.out文件是否一致 - - 输出结果如下: - - ``` - pistart SomePI - picontent abc - piend - elemstart a - elemend - ok - ``` - - 经比较与[test目录](#table115941423164318)下pi01.out内容一致,测试通过。 - - -## 将该库编译添加到OpenHarmony工程中 - -yxml库添加的过程除了适配文件build.gn和config.gni有些许变化外,其他和double-conversion库完全一致,参考[CMake方式组织编译的库移植](/pages/01040402#section1651053153715)的配置过程。要修改的适配文件及添加后的目录结构如下: - -- yxml库新增的BUILD.gn实现如下: - -``` -import("config.gni") -group("yxml") { - if (ohos_build_thirdparty_migrated_from_fuchisa == true) { - deps = [":make"] - } -} -if (ohos_build_thirdparty_migrated_from_fuchisa == true) { - action("make") { - script = "//third_party/yxml/build_thirdparty.py" - outputs = ["$target_out_dir/log_yxml.txt"] - exec_path = rebase_path(rebase_path("./yxml", root_build_dir)) - command = "make clean && $MAKE_COMMAND" - args = [ - "--path=$exec_path", - "--command=${command}" - ] - } -} -``` - -- yxml库新增的config.gni配置如下: - -``` -TEST_ENABLE = "YES" - -if (TEST_ENABLE == "YES") { - MAKE_COMMAND = "make test OHOS_SYSROOT_PATH=${ohos_root_path}prebuilts/lite/sysroot/" -} else { - MAKE_COMMAND = "make OHOS_SYSROOT_PATH=${ohos_root_path}prebuilts/lite/sysroot/" -} -``` - -- 添加完成后目录结构示意: - -**表 4** 添加到工程后的目录结构 - - - - - - - - - - - - - - - - - - - -

名称

-

描述

-

openHarmony/third_party/yxml/BUILD.gn

-

将三方库加入工程的gn适配文件

-

openHarmony/third_party/yxml/build_thirdparty.py

-

GN调用shell命令脚本文件,由上面GN文件将相关命令传入,实现GN转Makefile

-

openHarmony/third_party/yxml/config.gni

-

三方库编译配置文件,可修改该文件来配置用例是否参与构建等

-

openHarmony/third_party/yxml/yxml/

-

要移植的三方库目录

-
- diff --git "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/05.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\241\210\344\276\213/01.\345\270\246\345\261\217\350\247\243\345\206\263\346\226\271\346\241\210\344\271\213\346\201\222\347\216\204\350\212\257\347\211\207\347\247\273\346\244\215\346\241\210\344\276\213.md" "b/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/05.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\241\210\344\276\213/01.\345\270\246\345\261\217\350\247\243\345\206\263\346\226\271\346\241\210\344\271\213\346\201\222\347\216\204\350\212\257\347\211\207\347\247\273\346\244\215\346\241\210\344\276\213.md" deleted file mode 100644 index 2aec6986d48d8ea64bd0b954a6f5bcbd0298e81b..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/04.\347\247\273\346\244\215/05.\350\275\273\351\207\217\347\263\273\347\273\237\350\212\257\347\211\207\347\247\273\346\244\215\346\241\210\344\276\213/01.\345\270\246\345\261\217\350\247\243\345\206\263\346\226\271\346\241\210\344\271\213\346\201\222\347\216\204\350\212\257\347\211\207\347\247\273\346\244\215\346\241\210\344\276\213.md" +++ /dev/null @@ -1,1314 +0,0 @@ ---- -title: 带屏解决方案之恒玄芯片移植案例 -permalink: /pages/01040501 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- - - -# 轻量带屏解决方案之恒玄芯片移植案例 - -本文章基于恒玄科技`BES2600W`芯片的欧智通[Multi-modal V200Z-R开发板](https://gitee.com/openharmony/device_board_fnlink),进行轻量带屏开发板的标准移植,开发了智能开关面板样例,同时实现了`ace_engine_lite`、`graphic_ui`、`aafwk_lite`、`appexecfwk_lite`、`HDF`等部件基于`OpenHarmony LiteOS-M`内核的适配。移植架构上采用`Board`与`SoC`分离的方案,工具链`Newlib C`库与`Musl C`库可选,`LiteOS-M`内核编译采用`gn`结合`Kconfig`图形化配置等需求。 - -## 编译构建 - -### 目录规划 - -本案例在芯片移植架构方面进行了一些改进,以前的芯片适配目录规划为: - -``` -device -└── -    └── -``` - -这样会导致,小熊派`BearPi-HM Nano`开发板与润和的`HiSpark Pegasus`开发板使用小海思的`hi3861`的`SoC`时,需要在这两款开发板里面都放置一份重复的代码。为了解决该问题,本案例将单板厂商与`SoC`厂商进行分离,可以参考[Board和SoC解耦的设计思路](https://gitee.com/openharmony-sig/sig-content/blob/master/devboard/docs/board-soc-arch-design.md),并把芯片适配目录规划为: - -``` -device -├── board --- 单板厂商目录 -│   └── fnlink --- 单板厂商名字:欧智通 -│   └── v200zr --- 单板名:v200zr -└── soc --- SoC厂商目录 - └── bestechnic --- SoC厂商名字:恒玄 - └── bes2600 --- SoC Series名:bes2600是一个系列,里面包含bes2600w等SoC名 -``` - -产品样例目录规划为: - -``` -vendor -└── bestechnic --- 开发产品样例厂商目录,恒玄开发的带屏样例,因此以bestechnic命名 - └── display_demo --- 产品名字:以智能开关面板的带屏显示样例 -``` - -### 预编译适配 - -在进行移植之前,需要进行预编译适配。 - -预编译适配主要使用`hb set`命令,设置整个项目的根目录、单板目录、产品目录、单板公司名等环境变量,为编译做准备。 - -具体的预编译适配步骤如下: - -1. 在`vendor/bestechnic/display_demo`目录下新增`config.json`文件,用于描述这个产品样例所使用的单板、内核等信息,描述信息可参考如下内容: - -``` -{ - "product_name": "display_demo", --- 用于hb set进行选择时,显示的产品名称 - "type": "mini", --- 构建系统的类型,mini/small/standard - "version": "3.0", --- 构建系统的版本,1.0/2.0/3.0 - "device_company": "fnlink", --- 单板厂商名,用于编译时找到/device/board/fnlink目录 - "board": "v200zr", --- 单板名,用于编译时找到/device/board/fnlink/v200zr目录 - "kernel_type": "liteos_m", --- 内核类型,因为OpenHarmony支持多内核,一块单板可能适配了多个内核,所以需要指定某个内核进行编译 - "kernel_version": "3.0.0", --- 内核版本,一块单板可能适配了多个linux内核版本,所以需要指定某个具体的内核版本进行编译 - "subsystems": [ ] --- 选择所需要编译构建的子系统 -} -``` - -2. 在`device/board/fnlink/v200zr/liteos_m`目录下新增`config.gni`文件,用于描述这个产品样例所使用的单板、内核等信息,描述信息可参考如下内容: - -``` -# Kernel type, e.g. "linux", "liteos_a", "liteos_m". -kernel_type = "liteos_m" --- 内核类型,跟config.json中kernel_type对应 - -# Kernel version. -kernel_version = "3.0.0" --- 内核版本,跟config.json中kernel_version对应 -``` - -3. 验证`hb set`配置是否正确,输入`hb set`能够显示如下图片表示配置正确。 - - 执行`hb set`输入项目根目录,并且回车,`hb`命令会遍历所有`//vendor//`目录下的`config.json`,给出可选产品编译选项,`config.json`的`product_name`用于显示产品名,`device_company`和`board`用于关联出`//device/board//`目录,并且匹配`/config.gni`文件,如果能够匹配多个文件,表示该单板适配了多个内核,那么可以根据`config.json`的`kernel_type`和`kernel_version`来唯一匹配`config.gni`的`kernel_type`和`kernel_version`,即可确定了需要编译适配了哪个内核的单板。 -![hb set](/images/device-dev/porting/figure/bes2600_hb_set.png) - -​ 通过`hb env`可以查看选择出来的预编译环境变量。 - -![hb env](/images/device-dev/porting/figure/bes2600_hb_env.png) - -在执行`hb build`之前,需要准备好`LiteOS-M`内核适配,具体适配步骤请参[内核移植](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/porting/porting-bes2600w-on-minisystem-display-demo.md#%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D)。 - -## 内核移植 - -内核移植需要完成`LiteOS-M Kconfig`适配、`gn`的编译构建和内核启动最小适配。 - -### LiteOS-M Kconfig适配 - -在`//kernel/liteos_m`目录下执行`make menuconfig`命令,完成编译配置选项的选择。在`Makefile`文件中,会将`hb env`的结果转换成环境变量,即`PRODUCT_PATH`、`DEVICE_PATH`和`BOARD_COMPANY`。如下代码块所示: - -``` -$(foreach line,$(shell hb env | sed 's/\[OHOS INFO\]/ohos/g;s/ /_/g;s/:_/=/g' || true),$(eval $(line))) -ifneq ($(ohos_kernel),liteos_m) -$(error The selected product ($(ohos_product)) is not a liteos_m kernel type product) -endif ---- 将hb env的每一行输出转化为变量形式,例如将[OHOS INFO] device company: fnlink转换为ohos_device_company=fnlink - -…… - -ifeq ($(BOARD_COMPANY),) -BOARD_COMPANY:=$(ohos_device_company) -endif -…… -export BOARD_COMPANY ---- 将ohos_device_company转化为BOARD_COMPANY环境变量 -``` - -在`//kernel/liteos_m/Kconfig`文件中使用这些导出的环境变量,`Kconfiglib`采用`ulfalizer`开发基于`python`的版本,[源码地址](https://github.com/ulfalizer/Kconfiglib),[功能介绍连接参考](https://github.com/zephyrproject-rtos/zephyr/blob/main/scripts/kconfig/kconfiglib.py),里面用到了`orsource`关键字,其中`o`表示`optional`,表示这个文件是否存在可选,`r`表示`relative`,表示这个文件相对当前文件的相对路径。 - -``` -config SOC_COMPANY - string "SoC company name to locate soc build path" - help - This option specifies the SoC company name, used to locate the build path for soc. This option is set by the - SoC's Kconfig file, and should be exactly the same with SoC company path, and the user should generally avoid - modifying it via the menu configuration. - -orsource "../../device/board/*/Kconfig.liteos_m.shields" --- 将所有扩展板配置信息加载进来,因为单板厂商A提供扩展板可以给单板厂商B使用,所以这里使用*匹配所有的扩展板,而非BOARD_COMPANY。另外由于OpenHarmony支持多内核设计,Kconfig文件采用liteos_m作为后缀,在进行单板适配过程中,其他内核在适配过程中,可以使用对应的内核名作为后缀名进行扩展。 - -orsource "../../device/board/$(BOARD_COMPANY)/Kconfig.liteos_m.defconfig.boards" --- 加载BOARD_COMPANY的所有单板预定义配置 - -choice - prompt "Board Selection" - -orsource "../../device/board/$(BOARD_COMPANY)/Kconfig.liteos_m.boards" --- 提供Board选择列表 - -endchoice - -orsource "../../device/soc/*/Kconfig.liteos_m.defconfig" --- 加载所有SoC的默认配置定义 - -choice - prompt "SoC Series Selection" - -orsource "../../device/soc/*/Kconfig.liteos_m.series" --- 提供所有SoC Series选择列表 - -endchoice - -orsource "../../device/soc/*/Kconfig.liteos_m.soc" --- 加载所有SoC配置 -``` - -从`//kernel/liteos_m/Kconfig`文件可以看出需要在`//device/board/fnlink`目录下新增如下`Kconfig`文件进行适配: - -``` -. -├── v200zr --- v200zr单板配置目录 -│   ├── Kconfig.liteos_m.board --- 提供v200zr单板的配置选项 -│   ├── Kconfig.liteos_m.defconfig.board --- 提供v200zr单板的默认配置项 -│   └── liteos_m -│   └── config.gni -├── Kconfig.liteos_m.boards --- 提供fnlink单板厂商下Boards配置信息 -├── Kconfig.liteos_m.defconfig.boards --- 提供fnlink单板厂商下Boards默认配置信息 -├── Kconfig.liteos_m.shields --- 提供fnlink单板厂商下扩展板配置信息 -└── shields --- fnlink单板厂商的扩展板目录 - ├── v200zr-t0 --- fnlink单板厂商的扩展板v200zr-t0 - │   ├── Kconfig.liteos_m.defconfig.shield --- 扩展板v200zr-t0默认配置 - │   └── Kconfig.liteos_m.shield --- 扩展板v200zr-t0配置信息 - ├── v200zr-t1 - │   ├── Kconfig.liteos_m.defconfig.shield - │   └── Kconfig.liteos_m.shield - └── Kconfig.liteos_m.shields -``` - -在 `v200zr/Kconfig.liteos_m.board`需要配置选择该单板的选项,以及它依赖的`SoC`,如下: - -``` -config BOARD_v200zr - bool "select board v200zr" - depends on SOC_BES2600W --- v200zr单板用的bes2600w的SoC,只有 bes2600w的SoC被选择后,v200zr单板配置选项才可见,可以被选择。 -``` - -在 `v200zr/Kconfig.liteos_m.defconfig.board`需要配置选择该单板后,默认定义 `BOARD` 的名字为 `"v200zr"` ,如下: - -``` -if BOARD_v200zr -config BOARD - string --- string后没有带提示,因此用户不可见 - default "v200zr" - -endif # BOARD_v200zr -``` - -从`//kernel/liteos_m/Kconfig`文件可以看出需要在`//device/soc/bestechnic`目录下新增如下`Kconfig`文件进行适配: - -``` -. -├── bes2600 --- bes2600 SoC系列 -│   ├── Kconfig.liteos_m.defconfig.bes2600w --- bestechnic芯片厂商bes2600w SoC Series配置 -│   ├── Kconfig.liteos_m.defconfig.series --- bestechnic芯片厂商bes2600默认配置 -│   ├── Kconfig.liteos_m.series --- bestechnic芯片厂商bes2600 SoC Series配置 -│   └── Kconfig.liteos_m.soc --- bestechnic芯片厂商bes2600 SoC配置 -├── Kconfig.liteos_m.defconfig --- bestechnic芯片厂商SoC默认配置 -├── Kconfig.liteos_m.series --- bestechnic芯片厂商SoC Series配置 -└── Kconfig.liteos_m.soc --- bestechnic芯片厂商 SoC配置 -``` - -在 `bes2600/Kconfig.liteos_m.series` 需要配置`bes2600 SoC series`,以及它的芯片架构等信息,如下: - -``` -config SOC_SERIES_BES2600 --- 提供bes2600 SoC Series选项 - bool "Bestechnic 2600 Series" - select ARM --- 选择bes2600后,默认选择ARM架构 - select SOC_COMPANY_BESTECHNIC --- 选择bes2600后,默认选择bestechnic芯片公司,驱动会依赖这个宏配置,选择配置编译对应厂商的驱动 - select CPU_CORTEX_M33 --- 选择bes2600后,默认选择cortex-m33 CPU - help - Enable support for Bestechnic 2600 series -``` - -在 `bes2600/Kconfig.liteos_m.soc` 需要提供`bes2600 SoC series`下有多少个具体的`SoC`可供选择,如下: - -``` -choice - prompt "Bestechnic 2600 series SoC" - depends on SOC_SERIES_BES2600 --- 只有选择了bes2600 Series后,才会出现如下配置选项 - -config SOC_BES2600W --- 增加bes2600w SoC配置选择项 - bool "SoC BES2600w" - -endchoice -``` - -在 `bes2600/Kconfig.liteos_m.defconfig.series` 需要提供`bes2600 SoC series`选择后的默认配置,如下: - -``` -if SOC_SERIES_BES2600 --- 选择了bes2600 Series后,才会增加如下默认配置选项 - -rsource "Kconfig.liteos_m.defconfig.bes2600w" --- 增加bes2600w SoC的默认配置 - -config SOC_SERIES --- 增加SOC_SERIES的默认配置 - string - default "bes2600" - -endif -``` - -配置完成后,还需要根据 `kernel/liteos_m/Makefile` 文件配置`make menuconfig`的`defconfig`保存路径: - -``` -ifeq ($(TEE:1=y),y) -tee = _tee -endif -ifeq ($(RELEASE:1=y),y) -CONFIG ?= $(PRODUCT_PATH)/kernel_configs/release$(tee).config -else -CONFIG ?= $(PRODUCT_PATH)/kernel_configs/debug$(tee).config --- 配置文件保存在$(CONFIG)中,由产品最终定义 -endif - -…… - -update_config menuconfig: - $(HIDE)test -f "$(CONFIG)" && cp -v "$(CONFIG)" .config && menuconfig $(args) && savedefconfig --out "$(CONFIG)" -``` - -在这个例子中,`defconfig`配置路径为 `$(PRODUCT_PATH)/kernel_configs/debug.config`,创建该文件后,内容为空,产品的目录文件结构如下: - -``` -. -└── display_demo - ├── config.json - └── kernel_configs - └── debug.config -``` - -配置完成后,在 `kernel/liteos_m` 目录下执行 `make menuconfig`能够对`SoC Series`/`SoC`/`Board`进行选择,如下: - -![board make menuconfig](/images/device-dev/porting/figure/bes2600_board_make_menuconfig.png) - -结果将自动保存在`$(PRODUCT_PATH)/kernel_configs/debug.config`,下次执行`make menuconfig`时会导出保存的结果。 - -### gn编译适配 - -在上一步`Kconfig`的图形化配置后,将其生成的配置结果可以作为`gn`编译的输入,以控制不同模块是否编译。另外为了解决之前`gn`编写时,随意include的问题,内核编译做了模块化编译的设计,使得整个编译逻辑更加清晰,设计思路请参考[LiteOS-M内核BUILD.gn编写指南](https://gitee.com/caoruihong/kernel_liteos_m/wikis/LiteOS-M%E5%86%85%E6%A0%B8BUILD.gn%E7%BC%96%E5%86%99%E6%8C%87%E5%8D%97)。 - -在 `kernel/liteos_m/BUILD.gn` 中,指定了`Board`和`SoC`的编译入口为`//device/board/fnlink`和`//device/soc/bestechnic`。 - -``` -deps += [ "//device/board/$device_company" ] -deps += [ "//device/soc/$LOSCFG_SOC_COMPANY" ] -``` - -在`//device/board/fnlink/BUILD.gn`中,新增内容如下: - -``` -if (ohos_kernel_type == "liteos_m") { --- 由于多内核设计,对于LiteOS-M内核适配,需要用宏来隔离 - import("//kernel/liteos_m/liteos.gni") --- 引入内核gn编写模板 - module_name = get_path_info(rebase_path("."), "name") --- 动态获取当前文件目录作为模块名,防止目录名修改后,这里还需要跟着修改 - module_group(module_name) { --- 采用module_group模板 - modules = [ --- 添加需要编译的模块 - ] - } -} -``` - -同理`//device/soc/bestechnic/BUILD.gn`也是一样。 - -### 内核启动适配 - -内核启动适配的文件路径在 `//device/soc/bestechnic/bes2600/liteos_m/sdk/bsp/rtos/liteos/liteos_m/board.c` - -内核启动适配总体思路如下: - -1. 中断向量的初始化`os_vector_init` ,初始化中断的处理函数。 -2. 内核初始化`osKernelInitialize` 。 -3. 创建线程`board_main`,进行芯片平台初始化。 -4. 内核启动,开始调度线程`osKernelStart` 。 - -其中,本章节详细对第3步进行展开,其他几步为对内核函数调用,不作详细描述。 - -第3步中`board_main`在启动`OHOS_SystemInit`之前,需要初始化必要的动作,如下: - -``` -... - if(!ret) { - ... - OhosSystemAdapterHooks(); --- 系统启动时候设置钩子,启动OpenHarmonyOHOS_SystemInit的之前完成打印和驱动的初始化 - ... - OHOS_SystemInit(); --- 启动OpenHarmony服务,以及组件初始化 - } -.... -``` - -`OhosSystemAdapterHooks`函数在`device/soc/bestechnic/bes2600/liteos_m/components/utils/src/hm_sys.c`文件中,如下: - -``` -int OhosSystemAdapterHooks(void) -{ - init_trace_system(); --- 初始化打印函数 - DeviceManagerStart(); --- 调用DeviceManagerStart函数进行HDF驱动初始化,这个过程会调用单板代码中的驱动配置文件hdf.hcs以及drivers源码实现 - return 0; -} - -``` - -### littlefs文件系统移植 - -文件系统使用的是`littlefs`,适配过程中,需要在指定路径下放置文件系统预置文件,根据配置可自动生成文件系统镜像,可以实现自动化生成和打包到烧录包中。 - -1. 配置指定目录放置打包文件系统`config.json`,通过`flash_partition_dir`指定目录: - -``` - "flash_partition_dir": "fs" --- 表示在vendor/bestechnic/display_demo/fs目录下放置文件系统预置文件 -``` - -2. 在指定目录`vendor/bestechnic/display_demo/fs`下放置两部分内容: - - - `wifi_Download_cfg.yaml`:镜像的烧录配置文件,可以根据实际情况调整分区。 - - `/data/data`:第一个/`data`是挂载的根目录;第二个`data`是根目录里面的`data`目录,里面可以存放预置文件,或者在第二个`data`的同级目录再创建一个目录,打包的时候只认第一个`data`挂载根目录。 - -3. `config.json`中根据`wifi_Download_cfg.yaml`最后调整结果。 - - - `fs_src`配置文件系统挂载名字。 - - `fs_name`是最后生成文件系统的名字。 - - `block_size`配置成`4K`对齐,建议不修改。 - - `fs_size`是生成文件系统的大小。 - - `burn_name`是烧录`bin`名字的大小。 - - `enable` 表示是否生成这个文件系统 - -4. 在`//device/soc/bestechnic/bes2600/liteos_m/components/hdf_config/hdf.hcs`文件配置文件系统的烧录的起始地址、文件系统的大小以及读数据块的大小`block_size`等信息,参考配置如下: - -``` - misc { - fs_config { - littlefs_config { - match_attr = "littlefs_config"; - mount_points = ["/data"]; - partitions = [10]; - block_size = [4096]; - block_count = [1024]; - } - } - storage_config { - flash_config { - match_attr = "flash_config"; - partitions = [10]; - owner = [0]; - description = ["littlefs"]; - start_addr = [0xB60000]; - length = [0x400000]; - options = [3]; - } - } - } -``` - -最后在`device/soc/bestechnic/bes2600/liteos_m/components/fs/fs_init.c`中,通过`hdf`加载数据,进行读写`flash`,如下: - -``` -static int32_t FsDriverInit(struct HdfDeviceObject *object) -{ - if (object == NULL) { - return HDF_FAILURE; - } - if (object->property) { - if (FsGetResource(fs, object->property) != HDF_SUCCESS) { - HDF_LOGE("%s: FsGetResource failed", __func__); - return HDF_FAILURE; - } - } - for (int i = 0; i < sizeof(fs) / sizeof(fs[0]); i++) { - if (fs[i].mount_point == NULL) - continue; - - fs[i].lfs_cfg.read = littlefs_block_read; - fs[i].lfs_cfg.prog = littlefs_block_write; - fs[i].lfs_cfg.erase = littlefs_block_erase; - fs[i].lfs_cfg.sync = littlefs_block_sync; - - fs[i].lfs_cfg.read_size = 256; - fs[i].lfs_cfg.prog_size = 256; - fs[i].lfs_cfg.cache_size = 256; - fs[i].lfs_cfg.lookahead_size = 16; - fs[i].lfs_cfg.block_cycles = 1000; - - SetDefaultMountPath(i, fs[i].mount_point); - int ret = mount(NULL, fs[i].mount_point, "littlefs", 0, &fs[i].lfs_cfg); - HDF_LOGI("%s: mount fs on '%s' %s\n", __func__, fs[i].mount_point, (ret == 0) ? "succeed" : "failed"); - } - return HDF_SUCCESS; -} -``` - - - -### C库适配 - -在轻量系统中,C库适配比较复杂,设计思路请参考[LiteOS-M内核支持musl与newlib平滑切换方案](https://gitee.com/arvinzzz/ohos_kernel_design_specification/blob/master/liteos_m/%E6%94%AF%E6%8C%81newlib/%E5%86%85%E6%A0%B8%E9%80%82%E9%85%8Dnewlib%E6%96%B9%E6%A1%88%E6%80%9D%E8%B7%AF.md),由于我们的工具链采用 [gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2](https://gitee.com/link?target=https%3A%2F%2Fdeveloper.arm.com%2F-%2Fmedia%2FFiles%2Fdownloads%2Fgnu-rm%2F10.3-2021.10%2Fgcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2) 自带`newlib`的C库,那么系统移植整体采用`newlib`的C库。那么在内核的`make menuconfig`中选择`newlib`,如下图: - -![image-20211212191013553](/images/device-dev/porting/figure/bes2600_newlib_make_menuconfig.png) - -#### malloc适配 - -malloc适配参考[The Red Hat newlib C Library-malloc](https://sourceware.org/newlib/libc.html#malloc)。实现malloc适配有以下两种方法: - -- 实现 `_sbrk_r` 函数。这种方法中,内存分配函数使用`newlib`中的。 - -- 实现 `_malloc_r`, `_realloc_r`, `_reallocf_r`, `_free_r`, `_memalign_r`, 和 `_malloc_usable_size_r`。这种方法中,内存分配函数可以使用内核的。 - -为了方便地根据业务进行内存分配算法调优和问题定位,在这两种方法中,本案例选择后者。 - -首先,由于`newlib`中已经存在这些函数的符号,因此需要用到`gcc`的`wrap`的链接选项替换这些函数符号为内核的实现,内核的实现为 `//kernel/liteos_m/kal/libc/newlib/porting/src/malloc.c`。 - -然后,在`//device/board/fnlink/v200zr/liteos_m/config.gni`的新增这些函数的`wrap`链接选项。 - -``` -board_ld_flags += [ - "-Wl,--wrap=_malloc_r", - "-Wl,--wrap=_realloc_r", - "-Wl,--wrap=_reallocf_r", - "-Wl,--wrap=_free_r", - "-Wl,--wrap=_memalign_r", - "-Wl,--wrap=_malloc_usable_size_r", -] -``` - -#### vsprintf等适配 - -参考 https://sourceware.org/newlib/libc.html#vfprintf ,实现 `vprintf`, `vfprintf`, `printf`, `snprintf` 和`sprintf`。 - -类似`malloc`适配,首先要提供这些函数的实现,`//device/soc/bestechnic/bes2600/liteos_m/components/utils/src/printf.c`,本案例直接采用开源协议友好的实现。与`malloc`适配不同的是,这个函数由芯片原厂提供。因为就打印来说,根据项目的需要,实现可大可小,内核不方便提供统一的实现。 - -然后,在`//device/board/fnlink/v200zr/liteos_m/config.gni`的新增这些函数的wrap链接选项。 - -``` -board_ld_flags += [ - "-Wl,--wrap=printf", - "-Wl,--wrap=sprintf", - "-Wl,--wrap=snprintf", - "-Wl,--wrap=vsnprintf", - "-Wl,--wrap=vprintf", -] -``` - -#### open等适配 - -这部分实现由内核统一实现,芯片适配无须关注,内核文件`//kernel/liteos_m/kal/libc/newlib/porting/src/fs.c`,适配了`newlib`的`_read`、`_write`等函数,如下: - -``` -…… -ssize_t _read(int fd, void *buf, size_t nbyte) -{ - return LOS_Read(fd, buf, nbyte); -} - -ssize_t _write(int fd, const void *buf, size_t nbyte) -{ - return LOS_Write(fd, buf, nbyte); -} - -off_t _lseek(int fd, off_t offset, int whence) -{ - return LOS_Lseek(fd, offset, whence); -} -…… -``` - -## 板级系统移植 - -### 驱动移植 - -#### SoC芯片平台HDF驱动移植 - -驱动适配相关文件放置在`drivers/adapter/platform`中,对应有`gpio`,`i2c`,`pwm`,`spi`,`uart`,`watchdog`,都是通过`HDF`机制加载,本章节以`gpio`为例进行详细说明。 - -##### GPIO驱动适配 - -`gpio`驱动适配需要完成编译的适配、源码的适配。 - -在`//drivers/adapter/platform/gpio/BUILD.gn`文件中,描述了恒玄`gpio`驱动的编译适配。如下: - -``` -module_switch = defined(LOSCFG_DRIVERS_HDF_PLATFORM_GPIO) --- 如果打开HDF的GPIO配置开关,才进行如下编译 -module_name = get_path_info(rebase_path("."), "name") - -hdf_driver(module_name) { - sources = [] - if (defined(LOSCFG_SOC_COMPANY_BESTECHNIC)) { --- 如果打开恒玄的芯片配置开关,才进行恒玄GPIO的驱动编译 - sources += [ "gpio_bes.c" ] - } - - include_dirs = [ "." ] -} -``` - -在`//drivers/adapter/platform/gpio/gpio_bes.c`文件中,描述了恒玄`gpio`驱动的源码适配。 -首先,按照`OpenHarmony`的`HDF`驱动框架加载驱动基本适配框架,如下: - -``` -struct HdfDriverEntry g_GpioDriverEntry = { - .moduleVersion = 1, - .moduleName = "BES_GPIO_MODULE_HDF", - .Bind = GpioDriverBind, - .Init = GpioDriverInit, - .Release = GpioDriverRelease, -}; -HDF_INIT(g_GpioDriverEntry); --- 通过HDF_INIT 加载GPIO驱动 -``` - -然后,在初始化的时候会获取`hcs`参数进行初始化,如下: - -``` -static int32_t GpioDriverInit(struct HdfDeviceObject *device) -{ - int32_t ret; - struct GpioCntlr *gpioCntlr = NULL; - - if (device == NULL) { - HDF_LOGE("%s: device is NULL", __func__); - return HDF_ERR_INVALID_PARAM; - } - - gpioCntlr = GpioCntlrFromDevice(device); --- gpioCntlr节点变量就可以获取具体gpio配置 - if (gpioCntlr == NULL) { - ... -``` - -编码规范和设计思想见[bes 驱动适配PR](https://gitee.com/openharmony/drivers_adapter/pulls/278)的评论。 - -#### Board外设器件HDF驱动移植 - -`Board`外设器件表示通过`SoC`平台总线连接的外设器件,在本案例中,显示屏属于外设器件,其驱动适配放在`//device/board/fnlink/drivers/liteos_m`目录中。 - -##### 显示驱动适配 - -同`SoC`驱动适配,在`//device/board/fnlink/drivers/liteos_m/display/BUILD.gn`文件中,根据`hdf_driver`模板加载驱动模块,如下: - -``` -module_name = get_path_info(rebase_path("."), "name") -hdf_driver(module_name) { - sources = [ - "zzw395.c", - ] - include_dirs = [ - "//drivers/peripheral/display/interfaces/include", - ... - ] -} -``` - -在`//device/board/fnlink/drivers/liteos_m/display/zzw395.c`文件中,根据驱动框架加载显示驱动,如下: - -``` -static struct HdfDriverEntry g_ZZW395DriverEntry = { - .moduleVersion = 1, - .moduleName = "HDF_PANEL_ZZW395", - .Bind = PanelDriverBind, - .Init = PanelDriverInit, - .Release = PanelDriverRelease, -}; - -HDF_INIT(g_ZZW395DriverEntry); -``` - -其中的驱动参数根据`hcs`配置,在`PanelDriverInit`初始化时加载,如下: - -``` -static int32_t PanelDriverInit(struct HdfDeviceObject *object) -{ - if (object == NULL) { - return HDF_FAILURE; - } - HDF_LOGD("%s entry !!!", __func__); - if (object->property) { - if (PanelGetResource(&priv, object->property) != HDF_SUCCESS) { - HDF_LOGE("%s: PanelGetResource failed", __func__); - return HDF_FAILURE; - } - } -... -``` - -### OpenHarmony子系统适配 - -`OpenHarmony`子系统适配一般包含两部分: - -- 在`config.json`中增加对应子系统和部件,这样编译系统会将该部件纳入编译目标中。 -- 针对该部件的`HAL`层接口进行硬件适配,或者可选的软件功能适配。 - -#### communication子系统适配 - -##### wifi_lite部件适配 - -首先,在`config.json`文件中,增加`communication`子系统的`wifi_lite`部件,如下: - -``` - { - "subsystem": "communication", - "components": [ - { - "component": "wifi_lite", - "optional": "true" - } - ] - }, -``` - -`wifi_lite`部件在`//build/lite/components/communication.json`文件中,描述如下: - -``` - { - "component": "wifi_lite", -…… - "targets": [ - "//foundation/communication/wifi_lite:wifi" --- wifi_lite的编译目标 - ], -…… - }, - -``` - -在`//foundation/communication/wifi_lite/BUILD.gn`文件中,描述需要适配的接口头文件路径,如下: - -``` -config("include") { - include_dirs = [ "interfaces/wifiservice" ] --- 因为wifi_lite只提供头文件,不提供wifi的具体实现,所以wifi模块暴露出适配的目录路径提供给硬件厂商来适配,厂商提供wifi协议栈源码实现。 -} - -group("wifi") { - public_configs = [ ":include" ] -} -``` - -因为在本案例中,`wifi`属于`SoC`提供的功能,所以适配源码放在`SoC`的`//device/soc/bestechnic/hals/communication/wifi_lite/wifiservice`目录下,包含`wifi_device.c`和`wifi_hotspot.c`分别适配`wifi_device.h`和`wifi_hotspot.h`。如下: - -``` -…… -WifiErrorCode Scan(void) --- wifi_device.c中扫描wifi热点的函数,对wifi_device.h中Scan函数的适配实现 -{ - WifiErrorCode ret = ERROR_WIFI_BUSY; - - - if (IsWifiActive() != WIFI_STA_ACTIVE) - return ERROR_WIFI_IFACE_INVALID; - - if (g_HalHmosWifiInfo.scan_state == SCAN_REQUEST || - g_HalHmosWifiInfo.scan_state == SCAN_TRIGGER) - return ERROR_WIFI_BUSY; - - HalHmosWifiLock(); - ret = ((HalHmosSendEvent(HMOS_ON_WIFI_SCAN_STATE_CHANGED, NULL) == 0) ? WIFI_SUCCESS : ERROR_WIFI_BUSY); - HalHmosWifiUnLock(); - - return ret; -} -…… -int GetSignalLevel(int rssi, int band) --- wifi_hotspot.c中获取wifi信号热点函数,对wifi_hotspot.h中GetSignalLevel函数的适配实现。 -{ - if (band == HOTSPOT_BAND_TYPE_2G) { - if (rssi >= RSSI_LEVEL_4_2_G) - return RSSI_LEVEL_4; - if (rssi >= RSSI_LEVEL_3_2_G) - return RSSI_LEVEL_3; - if (rssi >= RSSI_LEVEL_2_2_G) - return RSSI_LEVEL_2; - if (rssi >= RSSI_LEVEL_1_2_G) - return RSSI_LEVEL_1; - } - - if (band == HOTSPOT_BAND_TYPE_5G) { - if (rssi >= RSSI_LEVEL_4_5_G) - return RSSI_LEVEL_4; - if (rssi >= RSSI_LEVEL_3_5_G) - return RSSI_LEVEL_3; - if (rssi >= RSSI_LEVEL_2_5_G) - return RSSI_LEVEL_2; - if (rssi >= RSSI_LEVEL_1_5_G) - return RSSI_LEVEL_1; - } - return ERROR_WIFI_INVALID_ARGS; -} -``` - -##### LWIP部件适配 - -`LiteOS-M kernel`目录下默认配置了`lwip`,因而具有编译功能,可以在`kernel`组件中指定`lwip`编译的目录。如下: - -``` - { - "subsystem": "kernel", - "components": [ - { - "component": "liteos_m", - "features": [ - "ohos_kernel_liteos_m_lwip_path = \"//device/soc/bestechnic/bes2600/liteos_m/components/net/lwip-2.1\"" --- 指定在芯片厂商目录中进行适配 - ] - } - ] - }, -``` - -在`//device/soc/bestechnic/bes2600/liteos_m/components/net/lwip-2.1/BUILD.gn`文件中,描述了`lwip`的编译,如下: - -``` -import("//kernel/liteos_m/liteos.gni") -import("$LITEOSTHIRDPARTY/lwip/lwip.gni") -import("$LITEOSTOPDIR/components/net/lwip-2.1/lwip_porting.gni") - -module_switch = defined(LOSCFG_NET_LWIP_SACK) -module_name = "lwip" -kernel_module(module_name) { - sources = LWIP_PORTING_FILES + LWIPNOAPPSFILES - - [ "$LWIPDIR/api/sockets.c" ] + [ "porting/src/ethernetif.c" ] --- 增加ethernetif.c文件,用以适配ethernet网卡的初始化适配 - defines = [ "LITEOS_LWIP=1" ] - defines += [ "CHECKSUM_BY_HARDWARE=1" ] -} - -config("public") { - defines = [ "_BSD_SOURCE=1" ] - include_dirs = - [ "porting/include" ] + LWIP_PORTING_INCLUDE_DIRS + LWIP_INCLUDE_DIRS -} - -``` - -在`//device/soc/bestechnic/bes2600/liteos_m/components/net/lwip-2.1/porting/include/lwip/lwipopts.h`文件中,说明原有`lwip`配置选项保持不变,软总线会依赖这些配置选项,并且新增硬件适配的配置项,如下: - -``` -#ifndef _PORTING_LWIPOPTS_H_ -#define _PORTING_LWIPOPTS_H_ - -#include_next "lwip/lwipopts.h" --- 保持原来的配置项不变 - -#define LWIP_NETIF_STATUS_CALLBACK 1 -#define LWIP_CHECKSUM_ON_COPY 0 -#define CHECKSUM_GEN_UDP 0 --- 新增硬件适配选项 - -#endif /* _PORTING_LWIPOPTS_H_ */ - -``` - -在`//device/soc/bestechnic/bes2600/liteos_m/components/net/lwip-2.1/porting/src/ethernetif.c`文件中,说明对`ethernet`网卡初始化的适配,如下: - -``` -err_t -ethernetif_init(struct netif *netif) -{ -…… -#ifdef CHECKSUM_BY_HARDWARE - eth_hw_checksum_init(); -#endif -…… - netif->linkoutput = low_level_output; - - netif->drv_send = liteos_low_level_output; - netif->hwaddr_len = NETIF_MAX_HWADDR_LEN; - low_level_init(netif); - driverif_init(netif); - return ERR_OK; -…… -} -``` - -#### 系统基本能力适配 - -本小节主要从移植的角度出发,分析适配过程中,需要操作或者注意的事项。 - -##### startup子系统适配 - -``startup`子系统适配`bootstrap_lite`/`syspara_lite`两个部件。请在`vendor/bestechnic_bak/display_demo/config.json`中新增对应的配置选项。 - -``` -{ - "subsystem": "startup", - "components": [ - { - "component": "bootstrap_lite" --- bootstrap_lite 部件 - }, - { - "component": "syspara_lite", --- syspara_lite 部件 - "features": [ - "enable_ohos_startup_syspara_lite_use_posix_file_api = true" - ] - } - ] -}, -``` - -适配`bootstrap_lite`部件时,需要在连接脚本文件`//device/soc/bestechnic/bes2600/liteos_m/sdk/bsp/out/best2600w_liteos/_best2001.lds`中手动新增如下段: - -``` - __zinitcall_bsp_start = .; - KEEP (*(.zinitcall.bsp0.init)) - KEEP (*(.zinitcall.bsp1.init)) - KEEP (*(.zinitcall.bsp2.init)) - KEEP (*(.zinitcall.bsp3.init)) - KEEP (*(.zinitcall.bsp4.init)) - __zinitcall_bsp_end = .; - __zinitcall_device_start = .; - KEEP (*(.zinitcall.device0.init)) - KEEP (*(.zinitcall.device1.init)) - KEEP (*(.zinitcall.device2.init)) - KEEP (*(.zinitcall.device3.init)) - KEEP (*(.zinitcall.device4.init)) - __zinitcall_device_end = .; - __zinitcall_core_start = .; - KEEP (*(.zinitcall.core0.init)) - KEEP (*(.zinitcall.core1.init)) - KEEP (*(.zinitcall.core2.init)) - KEEP (*(.zinitcall.core3.init)) - KEEP (*(.zinitcall.core4.init)) - __zinitcall_core_end = .; - __zinitcall_sys_service_start = .; - KEEP (*(.zinitcall.sys.service0.init)) - KEEP (*(.zinitcall.sys.service1.init)) - KEEP (*(.zinitcall.sys.service2.init)) - KEEP (*(.zinitcall.sys.service3.init)) - KEEP (*(.zinitcall.sys.service4.init)) - __zinitcall_sys_service_end = .; - __zinitcall_sys_feature_start = .; - KEEP (*(.zinitcall.sys.feature0.init)) - KEEP (*(.zinitcall.sys.feature1.init)) - KEEP (*(.zinitcall.sys.feature2.init)) - KEEP (*(.zinitcall.sys.feature3.init)) - KEEP (*(.zinitcall.sys.feature4.init)) - __zinitcall_sys_feature_end = .; - __zinitcall_run_start = .; - KEEP (*(.zinitcall.run0.init)) - KEEP (*(.zinitcall.run1.init)) - KEEP (*(.zinitcall.run2.init)) - KEEP (*(.zinitcall.run3.init)) - KEEP (*(.zinitcall.run4.init)) - __zinitcall_run_end = .; - __zinitcall_app_service_start = .; - KEEP (*(.zinitcall.app.service0.init)) - KEEP (*(.zinitcall.app.service1.init)) - KEEP (*(.zinitcall.app.service2.init)) - KEEP (*(.zinitcall.app.service3.init)) - KEEP (*(.zinitcall.app.service4.init)) - __zinitcall_app_service_end = .; - __zinitcall_app_feature_start = .; - KEEP (*(.zinitcall.app.feature0.init)) - KEEP (*(.zinitcall.app.feature1.init)) - KEEP (*(.zinitcall.app.feature2.init)) - KEEP (*(.zinitcall.app.feature3.init)) - KEEP (*(.zinitcall.app.feature4.init)) - __zinitcall_app_feature_end = .; - __zinitcall_test_start = .; - KEEP (*(.zinitcall.test0.init)) - KEEP (*(.zinitcall.test1.init)) - KEEP (*(.zinitcall.test2.init)) - KEEP (*(.zinitcall.test3.init)) - KEEP (*(.zinitcall.test4.init)) - __zinitcall_test_end = .; - __zinitcall_exit_start = .; - KEEP (*(.zinitcall.exit0.init)) - KEEP (*(.zinitcall.exit1.init)) - KEEP (*(.zinitcall.exit2.init)) - KEEP (*(.zinitcall.exit3.init)) - KEEP (*(.zinitcall.exit4.init)) - __zinitcall_exit_end = .; -``` - -需要新增上述段是因为`bootstrap_init`提供的对外接口,见`//utils/native/lite/include/ohos_init.h`文件,采用的是灌段的形式,最终会保存到上述链接段中。主要的服务自动初始化宏如下表格所示: - -| 接口名 | 描述 | -| ---------------------- | -------------------------------- | -| SYS_SERVICE_INIT(func) | 标识核心系统服务的初始化启动入口 | -| SYS_FEATURE_INIT(func) | 标识核心系统功能的初始化启动入口 | -| APP_SERVICE_INIT(func) | 标识应用层服务的初始化启动入口 | -| APP_FEATURE_INIT(func) | 标识应用层功能的初始化启动入口 | - -![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - 通过上面加载的组件编译出来的lib文件需要手动加入强制链接。 - -​ 如在 `vendor/bestechnic/display_demo/config.json` 中配置了`bootstrap_lite` 部件 - -``` - { - "subsystem": "startup", - "components": [ - { - "component": "bootstrap_lite" - }, - ... - ] - }, -``` - -​ `bootstrap_lite`部件会编译`//base/startup/bootstrap_lite/services/source/bootstrap_service.c`,该文件中,通过`SYS_SERVICE_INIT`将`Init`函数符号灌段到`__zinitcall_sys_service_start`和`__zinitcall_sys_service_end`中,由于`Init`函数是没有显式调用它,所以需要将它强制链接到最终的镜像。如下: - -``` -static void Init(void) -{ - static Bootstrap bootstrap; - bootstrap.GetName = GetName; - bootstrap.Initialize = Initialize; - bootstrap.MessageHandle = MessageHandle; - bootstrap.GetTaskConfig = GetTaskConfig; - bootstrap.flag = FALSE; - SAMGR_GetInstance()->RegisterService((Service *)&bootstrap); -} -SYS_SERVICE_INIT(Init); --- 通过SYS启动即SYS_INIT启动就需要强制链接生成的lib -``` - -​ 在`//base/startup/bootstrap_lite/services/source/BUILD.gn`文件中,描述了在`out/v200zr/display_demo/libs` 生成 `libbootstrap.a`,如下: - -``` -static_library("bootstrap") { - sources = [ - "bootstrap_service.c", - "system_init.c", - ] - .... -``` - -​ 那么需要在 `vendor/bestechnic/display_demo/config.json` 配置强制链接库`bootstrap`,如下: - -``` - "bin_list": [ - { - "elf_name": "wifiiot", - "bsp_target_name": "best2600w_liteos", - "signature": "false", - "burn_name": "rtos_main", - "enable": "true", - "force_link_libs": [ - "bootstrap", --- 强制链接libbootstrap.a - ... - ] - }, -``` - - - -适配`syspara_lite`部件时,系统参数会最终写到文件中进行持久化保存。在轻量系统中,文件操作相关接口有`POSIX`接口与`HalFiles`接口这两套实现。 - -因为对接内核的文件系统,采用`POSIX`相关的接口,所以`features`字段中需要增加`enable_ohos_startup_syspara_lite_use_posix_file_api = true`。 - -如果对接`HalFiles`相关的接口实现的,则无须修改。 - -在适配`GetSerial`接口时,开发板不像产线生产过程那样,会写入一个具体的`Serial Number`,因而需要确定一个数据对开发板进行唯一标识。本案例采用`WiFi Mac`地址进行适配。 - -``` -#define ETH_ALEN 6 -#define MAC_BITS 4 -#define MAC_HIGH_MASK 0xf0 -#define MAC_LOW_MASK 0x0f -#define HEX_A 0xa -#define CHAR_NUM_OFFSET 0x30 -#define CHAR_CAPITAL_OFFSET 0x37 -#define STR_END_FLAG '\0' - -typedef unsigned char u8; - -static char serialNumber[2*ETH_ALEN + 1]; --- 最后一位留作'\0'结束符标识 - - -static char Hex2Char(u8 hex) -{ - if (hex < HEX_A) { - return hex + CHAR_NUM_OFFSET; --- 将数值0转为char的'0' - } else { - return hex + CHAR_CAPITAL_OFFSET; --- 将数值0xa转为char的'A' - } -} - -const char* HalGetSerial(void) -{ - char macAddr[ETH_ALEN]; - // as devboard has no production serial number, we just - // use wifi mac address as device serial number. - if (serialNumber[0] == STR_END_FLAG) { --- 只有第一次调用时,才去获取mac地址 - extern int bwifi_get_own_mac(u8 *addr); - bwifi_get_own_mac(macAddr); --- 获取mac地址 - int j = 0; - for (int i = 0; i < ETH_ALEN; i++) { - u8 lowFour, highFour; - highFour = (macAddr[i] & MAC_HIGH_MASK) >> MAC_BITS; - serialNumber[j] = Hex2Char(highFour); - j++; - lowFour = macAddr[i] & MAC_LOW_MASK; - serialNumber[j] = Hex2Char(lowFour); - j++; - } --- 将mac地址值转化为serial number - } - return serialNumber; -} -``` - - - -##### hiviewdfx子系统适配 - -进行`hiviewdfx`子系统适配需要添加`hilog_lite`部件,直接在`config.json`文件配置即可。 - -``` -{ - "subsystem": "hiviewdfx", - "components": [ - { - "component": "hilog_lite", - "optional": "true" - } - ] -}, -``` - -配置完成之后,在`//device/soc/bestechnic/bes2600/liteos_m/components/utils/src/hm_sys.c`中注册日志输出实现函数。 - -``` -boolean HilogProc_Impl(const HiLogContent *hilogContent, uint32 len) -{ - char tempOutStr[LOG_FMT_MAX_LEN] = {0}; - if (LogContentFmt(tempOutStr, sizeof(tempOutStr), hilogContent) > 0) { - printf(tempOutStr); - } - return TRUE; -} - -HiviewRegisterHilogProc(HilogProc_Impl); -``` - -##### distributedschedule子系统适配 - -进行`distributedschedule`子系统适配需要添加`samgr_lite`部件,直接在`config.json`配置即可。 - -``` -{ - "subsystem": "distributedschedule", - "components": [ - { - "component": "samgr_lite", - "features": [ - "config_ohos_distributedschedule_samgr_lite_shared_task_size = 4096" - ] - } - ] -}, -``` - -在轻量系统中,`samgr_lite`配置的共享任务栈大小默认为`0x800`。当函数调用栈较大时,会出现栈溢出的问题。在本次适配过程中,将其调整为`0x1000`。 - -##### utils子系统适配 - -进行`utils`子系统适配需要添加`kv_store`/`js_builtin`/`timer_task`/`kal_timer`部件,直接在`config.json`配置即可。 - -``` -{ - "subsystem": "utils", - "components": [ - { - "component": "kv_store", - "features": [ - "enable_ohos_utils_native_lite_kv_store_use_posix_kv_api = true" - ] - }, - { - "component": "js_builtin" - }, - { - "component": "timer_task" - }, - { - "component": "kal_timer", - } - ] -}, -``` - -与适配`syspara_lite`部件类似,适配`kv_store`部件时,键值对会写到文件中。在轻量系统中,文件操作相关接口有`POSIX`接口与`HalFiles`接口这两套实现。因为对接内核的文件系统,采用`POSIX`相关的接口,所以`features`需要增加`enable_ohos_utils_native_lite_kv_store_use_posix_kv_api = true`。如果对接`HalFiles`相关的接口实现的,则无须修改。 - -#### 图形显示子系统适配 - -##### graphic子系统适配 - -进行`graphic`子系统适配需要添加`graphic_utils`部件,直接在`config.json`配置即可。 - -``` - "components": [ - { - "component": "graphic_utils", - "features": [ - "enable_ohos_graphic_utils_product_config = true" - ] - }, - { - "component": "ui" - } - ] - } -``` - -`graphic`配置文件见 `//vendor/bestechnic/display_demo/graphic_config/product_graphic_lite_config.h`。 - -`graphic`适配见`//device/soc/bestechnic/bes2600/liteos_m/components/ui`, 主要功能如下: - -- `display_device`:实例化`BaseGfxEngine`。 -- `touch_input`:实例化`PointerInputDevice`。 -- `UiMainTask`:初始化字体引擎,执行渲染任务等。 - -`graphic`子系统层次: - -``` -aafwk_lite + appexecfwk_lite (AMS + BMS) - | -ace_engine_lite + jerryscript + i18n_lite + resmgr_lite + utils/native/lite/... (ACE,JS引擎及其依赖) - | -graphic_ui + graphic_utils (图形框架) - | -giflib + libjpeg + libpng + qrcodegen + freetype... (图形第三方库) -``` - -图形应用示例见文件`//vendor/bestechnic/display_demo/tests/app.cpp`,如下: - -``` -/* ui app entry */ -void RunApp() -{ -#ifdef UI_TEST - AnimatorDemoStart(); --- native ui demo -#elif defined(ABILITY_TEST) - StartJSApp(); --- js demo -#endif -} - -void AppEntry(void) -{ - UiMain(); -} - -APP_FEATURE_INIT(AppEntry); -``` - -##### ace子系统适配 - -进行`ace`子系统适配需要添加`ace_engine_lite`部件,直接在`config.json`配置即可。 - - { - "subsystem": "ace", - "components": [ - { - "component": "ace_engine_lite", - "features": [ - "enable_ohos_ace_engine_lite_product_config = true" - ] - } - ] - }, - -`ace_engine_lite`部件配置文件见 `//vendor/bestechnic/display_demo/ace_lite_config/product_acelite_config.h`。 - -`ace_lite`的应用采用js语言进行开发,详细步骤如下: - -1. 用`DevEco Studio`编写js应用,参考[轻量级智能穿戴开发](https://developer.harmonyos.com/cn/docs/documentation/doc-references/lite-wearable-file-0000001176751380)。 -2. 使用预览功能进行预览,并且得到js包:`entry\.preview\intermediates\res\debug\lite\assets\js\default`。 -3. 将js包放到对应的文件系统目录下,文件系统路径为`vendor/bestechnic/display_demo/fs/data/data/js`,如下: - -``` -├── app.js -├── common -├── i18n -├── manifest.json -└── pages -``` - -4. 最终编译生成系统镜像,烧录到单板后,系统会从`app.js`加载启动`ace`的应用。 - -##### aafwk子系统适配 - -进行`aafwk`子系统适配需要添加`aafwk_lite`部件,直接在`config.json`配置即可。 - -``` - { - "subsystem": "aafwk", - "components": [ - { - "component": "aafwk_lite", - "features": [ - "enable_ohos_appexecfwk_feature_ability = true", --- 支持FA特性,即包含图形能力 - "config_ohos_aafwk_ams_task_size = 4096" --- 配置ams栈的大小 - ] - } - ] - }, -``` - -`aafwk_lite`相关的应用样例见`vendor/bestechnic/display_demo/tests/ability`目录,包含`launcher`和`js app`这两类应用,应用的函数调用流程描述如下: - -1. `launcher`应用,通过`InstallLauncher`安装`BundleName`为 `"com.huawei.launcher"`的`native ui`应用,在`AbilityMgrSliteFeature`启动后会调用`AbilityMgrHandler::StartLauncher()`启动`launcher`应用。 - -2. `StartJSApp`应用,通过`StartAbility`启动任意`Want`,通过将`want data`传递`JS_APP_PATH`, - `SetWantData(&want, JS_APP_PATH, strlen(JS_APP_PATH) + 1)`。 - -##### appexecfwk子系统适配 - -进行`appexecfwk`子系统适配需要添加`appexecfwk_lite`部件,直接在`config.json`配置即可。 - -``` - { - "subsystem": "appexecfwk", - "components": [ - { - "component": "appexecfwk_lite" - } - ] - }, -``` - -## 兼容性认证 - -### 产品兼容性规范 - -产品兼容性规范文档请参考[产品兼容性SIG介绍](https://gitee.com/openharmony-sig/compatibility/tree/master)。 - -### XTS用例 - -`XTS`测试参考资料见[xts参考资料](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/subsystems/subsys-xts-guide.md),进行`XTS`子系统适配需要添加`xts_acts`/`xts_tools`部件,直接在`config.json`配置即可,配置如下: - - { - "subsystem": "xts", - "components": [ - { "component": "xts_acts", "features": - [ - "config_ohos_xts_acts_utils_lite_kv_store_data_path = \"/data\"", - "enable_ohos_test_xts_acts_use_thirdparty_lwip = true" - ] - }, - { "component": "xts_tools", "features":[] } - ] - } - -其中, - -- `config_ohos_xts_acts_utils_lite_kv_store_data_path` 是配置挂载文件系统根目录的名字。 -- `enable_ohos_test_xts_acts_use_thirdparty_lwip` 表示如果使用`thirdparty/lwip`目录下的源码编译,则设置为`true`,否则设置为`false`。 - -全部跑完会有显示`xx Tests xx Failures xx Ignored`,如下: - -``` -... -[16:53:43:438]../../../test/xts/acts/utils_lite/kv_store_hal/src/kvstore_func_test.c:793:testKvStoreMaxSize004:PASS -[16:53:43:438]+-------------------------------------------+ -[16:53:43:438] -[16:53:43:438]----------------------- -[16:53:43:438]32 Tests 0 Failures 0 Ignored -[16:53:43:438]OK -[16:53:43:439]All the test suites finished! -``` - -### 报告提交 - -将上图`XTS`用例的情况保存为测试报告,上传到`OpenHarmony`兼容性测试网站进行认证,作为`sig`仓库转正到`master`仓库的必要条件。详细步骤如下: - -步骤1:将`XTS`测试报告压缩成`zip`文件。 - -步骤2:生成测试报告的`SHA`校验码。本案例是将`zip`文件传到在线生成`hash`的[网站]( https://tool.lmeee.com/jiami/filehash)生成`SHA`校验码。 - -步骤3:进入`OpenHarmony`[兼容性测试网站](https://www.openharmony.cn/old/#/Compatibility_test)上传报告。 - - - 其中`API Level`填写报告中的`"sdkApiLevel"`字段 - - `OS`版本号填写报告中的`"OS Version"`字段。 - -## todo - -后续会补充以下方面的移植: - -- 蓝牙 -- `bms`包安装 -- 音频播放 -- 验证运行`JS`的`bytecode` -- 分布式能力:`dsoftbus`、`dms`、`dm` -- 分布式音乐播放器样例 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/01.\345\206\205\346\240\270\346\246\202\350\277\260.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/01.\345\206\205\346\240\270\346\246\202\350\277\260.md" deleted file mode 100644 index ba0af689cb6a9af0a5dc8bf86a1710a9e16ec73a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/01.\345\206\205\346\240\270\346\246\202\350\277\260.md" +++ /dev/null @@ -1,75 +0,0 @@ ---- -title: 内核概述 -permalink: /pages/0105010101 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 内核概述 - -- [内核简介](#section1429342661510) - - [cpu体系架构支持](#section48891456112819) - - [运行机制](#section4599142312817) - - -## 内核简介 - -OpenHarmony LiteOS-M内核是面向IoT领域构建的轻量级物联网操作系统内核,具有小体积、低功耗、高性能的特点。其代码结构简单,主要包括内核最小功能集、内核抽象层、可选组件以及工程目录等。OpenHarmony LiteOS-M内核架构包含硬件相关层以及硬件无关层,如下图所示,其中硬件相关层按不同编译工具链、芯片架构分类,提供统一的HAL(Hardware Abstraction Layer)接口,提升了硬件易适配性,满足AIoT类型丰富的硬件和编译工具链的拓展;其他模块属于硬件无关层,其中基础内核模块提供基础能力,扩展模块提供网络、文件系统等组件能力,还提供错误处理、调测等能力;KAL(Kernel Abstraction Layer)模块提供统一的标准接口。 - -**图 1** 内核架构图 -![](/images/device-dev/kernel/figure/内核架构图.png "内核架构图") - -### cpu体系架构支持 - -CPU体系架构分为通用架构定义和特定架构定义两层,通用架构定义层为所有体系架构都需要支持和实现的接口,特定架构定义层为特定体系架构所特有的部分。在新增一个体系架构的时候,必须需要实现通用架构定义层,如果该体系架构还有特有的功能,可以在特定架构定义层来实现。 - -**表 1** CPU体系架构规则 - - - - - - - - - - - - - - - - - - - - -

规则

-

通用体系架构层

-

特定体系架构层

-

头文件位置

-

arch/include

-

arch/<arch>/<arch>/<toolchain>/

-

头文件命名

-

los_<function>.h

-

los_arch_<function>.h

-

函数命名

-

Halxxxx

-

Halxxxx

-
- -LiteOS-M已经支持ARM Cortex-M3、ARM Cortex-M4、ARM Cortex-M7、ARM Cortex-M33、RISC-V等主流架构,如果需要扩展CPU体系架构,请参考[芯片架构适配点](/pages/0104010201#section137431650339)。 - -### 运行机制 - -在开发板配置文件target\_config.h配置系统时钟、每秒Tick数,可以对任务、内存、IPC、异常处理模块进行裁剪配置。系统启动时,根据配置进行指定模块的初始化。内核启动流程包含外设初始化、系统时钟配置、内核初始化、操作系统启动等,详见内核启动流程图。 - -**图 2** 内核启动流程 -![](/images/device-dev/kernel/figure/内核启动流程.png "内核启动流程") - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/01.\344\270\255\346\226\255\347\256\241\347\220\206/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/01.\344\270\255\346\226\255\347\256\241\347\220\206/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" deleted file mode 100644 index 26fbe11d111b55491a4afcdcda7f09da7ad0b7e6..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/01.\344\270\255\346\226\255\347\256\241\347\220\206/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" +++ /dev/null @@ -1,50 +0,0 @@ ---- -title: 基本概念 -permalink: /pages/01050101020101 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 基本概念 - -在程序运行过程中,出现需要由CPU立即处理的事务时,CPU暂时中止当前程序的执行转而处理这个事务,这个过程叫做中断。当硬件产生中断时,通过中断号查找到其对应的中断处理程序,执行中断处理程序完成中断处理。 - -通过中断机制,在外设不需要CPU介入时,CPU可以执行其它任务;当外设需要CPU时,CPU会中断当前任务来响应中断请求。这样可以使CPU避免把大量时间耗费在等待、查询外设状态的操作上,有效提高系统实时性及执行效率。 - -下面介绍下中断的相关概念: - -- 中断号 - - 中断请求信号特定的标志,计算机能够根据中断号判断是哪个设备提出的中断请求。 - -- 中断请求 - - “紧急事件”向CPU提出申请(发一个电脉冲信号),请求中断,需要CPU暂停当前执行的任务处理该“紧急事件”,这一过程称为中断请求。 - -- 中断优先级 - - 为使系统能够及时响应并处理所有中断,系统根据中断事件的重要性和紧迫程度,将中断源分为若干个级别,称作中断优先级。 - -- 中断处理程序 - - 当外设发出中断请求后,CPU暂停当前的任务,转而响应中断请求,即执行中断处理程序。产生中断的每个设备都有相应的中断处理程序。 - -- 中断触发 - - 中断源向中断控制器发送中断信号,中断控制器对中断进行仲裁,确定优先级,将中断信号发送给CPU。中断源产生中断信号的时候,会将中断触发器置“1”,表明该中断源产生了中断,要求CPU去响应该中断。 - -- 中断向量 - - 中断服务程序的入口地址。 - -- 中断向量表 - - 存储中断向量的存储区,中断向量与中断号对应,中断向量在中断向量表中按照中断号顺序存储。 - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/01.\344\270\255\346\226\255\347\256\241\347\220\206/02.\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/01.\344\270\255\346\226\255\347\256\241\347\220\206/02.\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index 1047ec2faa6566f6fc3000a400f15abc6078495d..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/01.\344\270\255\346\226\255\347\256\241\347\220\206/02.\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,143 +0,0 @@ ---- -title: 开发指导 -permalink: /pages/01050101020102 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 开发指导 - -- [接口说明](#section158501652121514) -- [开发流程](#section11841123033618) -- [编程实例](#section460018317164) - - [结果验证](#section1048572415182) - - -当产生中断请求时,CPU暂停当前的任务,转而去响应外设请求。用户可以根据需要注册对应的中断处理程序,指定CPU响应中断请求时所执行的具体操作。 - -## 接口说明 - -OpenHarmony LiteOS-M内核的中断模块提供下面几种功能,接口详细信息可以查看API参考。 - -**表 1** 中断模块接口 - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名

-

描述

-

创建、删除中断

-

HalHwiCreate

-

中断创建,注册中断号、中断触发模式、中断优先级、中断处理程序。中断被触发时,会调用该中断处理程序。

-

HalHwiDelete

-

根据指定的中断号,删除中断。

-

打开、关闭中断

-

LOS_IntUnLock

-

开中断,使能当前处理器所有中断响应。

-

LOS_IntLock

-

关中断,关闭当前处理器所有中断响应。

-

LOS_IntRestore

-

恢复到使用LOS_IntLock、LOS_IntUnLock操作之前的中断状态。

-
- -## 开发流程 - -1. 调用中断创建接口HalHwiCreate创建中断。 -2. 调用TestHwiTrigger接口触发指定中断(该接口在测试套中定义,通过写中断控制器的相关寄存器模拟外部中断,一般的外设设备,不需要执行这一步)。 -3. 调用HalHwiDelete接口删除指定中断,此接口根据实际情况使用,判断是否需要删除中断。 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->- 根据具体硬件,配置支持的最大中断数及可设置的中断优先级个数。 ->- 中断处理程序耗时不能过长,否则会影响CPU对中断的及时响应。 ->- 中断响应过程中不能直接、间接执行引起调度的LOS\_Schedule等函数。 ->- 中断恢复LOS\_IntRestore\(\)的入参必须是与之对应的LOS\_IntLock\(\)的返回值(即关中断之前的CPSR值)。Cortex-M系列处理器中0-15中断为内部使用,因此不建议用户去申请和创建。 - -## 编程实例 - -本实例实现如下功能: - -1. 创建中断。 -2. 触发中断。 -3. 删除中断。 - -代码实现如下,演示如何创建中断和删除中断,当指定的中断号HWI\_NUM\_TEST产生中断时,会调用中断处理函数: - -``` -#include "los_interrupt.h" - -/*创建中断*/ -#define HWI_NUM_TEST 7 - -STATIC VOID HwiUsrIrq(VOID) -{ - printf("in the func HwiUsrIrq \n"); -} - -static UINT32 Example_Interrupt(VOID) -{ - UINT32 ret; - HWI_PRIOR_T hwiPrio = 3; - HWI_MODE_T mode = 0; - HWI_ARG_T arg = 0; - - /*创建中断*/ - ret = HalHwiCreate(HWI_NUM_TEST, hwiPrio, mode, (HWI_PROC_FUNC)HwiUsrIrq, arg); - if(ret == LOS_OK){ - printf("Hwi create success!\n"); - } else { - printf("Hwi create failed!\n"); - return LOS_NOK; - } - - /* 延时50个Ticks, 当有硬件中断发生时,会调用函数HwiUsrIrq*/ - LOS_TaskDelay(50); - - /*删除中断*/ - ret = HalHwiDelete(HWI_NUM_TEST); - if(ret == LOS_OK){ - printf("Hwi delete success!\n"); - } else { - printf("Hwi delete failed!\n"); - return LOS_NOK; - } - return LOS_OK; -} -``` - -### 结果验证 - -编译运行得到的结果为: - -``` -Hwi create success! -Hwi delete success! -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/02.\344\273\273\345\212\241\347\256\241\347\220\206/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/02.\344\273\273\345\212\241\347\256\241\347\220\206/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" deleted file mode 100644 index 9277e11ad7f86861c7ee9fb66f3e5ab131bf709b..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/02.\344\273\273\345\212\241\347\256\241\347\220\206/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" +++ /dev/null @@ -1,109 +0,0 @@ ---- -title: 基本概念 -permalink: /pages/01050101020201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 基本概念 - -- [任务相关概念](#section673132352511) -- [任务运行机制](#section176294469251) - -从系统角度看,任务是竞争系统资源的最小运行单元。任务可以使用或等待CPU、使用内存空间等系统资源,并独立于其它任务运行。 - -OpenHarmony LiteOS-M的任务模块可以给用户提供多个任务,实现任务间的切换,帮助用户管理业务程序流程。任务模块具有如下特性: - -- 支持多任务。 -- 一个任务表示一个线程。 -- 抢占式调度机制,高优先级的任务可打断低优先级任务,低优先级任务必须在高优先级任务阻塞或结束后才能得到调度。 -- 相同优先级任务支持时间片轮转调度方式。 -- 共有32个优先级\[0-31\],最高优先级为0,最低优先级为31。 - -## 任务相关概念 - -**任务状态** - -任务有多种运行状态。系统初始化完成后,创建的任务就可以在系统中竞争一定的资源,由内核进行调度。 - -任务状态通常分为以下四种: - -- 就绪(Ready):该任务在就绪队列中,只等待CPU。 -- 运行(Running):该任务正在执行。 -- 阻塞(Blocked):该任务不在就绪队列中。包含任务被挂起(suspend状态)、任务被延时(delay状态)、任务正在等待信号量、读写队列或者等待事件等。 -- 退出态(Dead):该任务运行结束,等待系统回收资源。 - -**任务状态迁移** - -**图 1** 任务状态示意图 -![](/images/device-dev/kernel/figure/任务状态示意图.png "任务状态示意图") - -**任务状态迁移说明:** - -- 就绪态→运行态 - - 任务创建后进入就绪态,发生任务切换时,就绪队列中最高优先级的任务被执行,从而进入运行态,同时该任务从就绪队列中移出。 - -- 运行态→阻塞态 - - 正在运行的任务发生阻塞(挂起、延时、读信号量等)时,将该任务插入到对应的阻塞队列中,任务状态由运行态变成阻塞态,然后发生任务切换,运行就绪队列中最高优先级任务。 - -- 阻塞态→就绪态(阻塞态→运行态) - - 阻塞的任务被恢复后(任务恢复、延时时间超时、读信号量超时或读到信号量等),此时被恢复的任务会被加入就绪队列,从而由阻塞态变成就绪态;此时如果被恢复任务的优先级高于正在运行任务的优先级,则会发生任务切换,该任务由就绪态变成运行态。 - -- 就绪态→阻塞态 - - 任务也有可能在就绪态时被阻塞(挂起),此时任务状态由就绪态变为阻塞态,该任务从就绪队列中删除,不会参与任务调度,直到该任务被恢复。 - -- 运行态→就绪态 - - 有更高优先级任务创建或者恢复后,会发生任务调度,此刻就绪队列中最高优先级任务变为运行态,那么原先运行的任务由运行态变为就绪态,依然在就绪队列中。 - -- 运行态→退出态 - - 运行中的任务运行结束,任务状态由运行态变为退出态。退出态包含任务运行结束的正常退出状态以及Invalid状态。例如,任务运行结束但是没有自删除,对外呈现的就是Invalid状态,即退出态。 - -- 阻塞态→退出态 - - 阻塞的任务调用删除接口,任务状态由阻塞态变为退出态。 - - -**任务ID** - -任务ID,在任务创建时通过参数返回给用户,是任务的重要标识。系统中的ID号是唯一的。用户可以通过任务ID对指定任务进行任务挂起、任务恢复、查询任务名等操作。 - -**任务优先级** - -优先级表示任务执行的优先顺序。任务的优先级决定了在发生任务切换时即将要执行的任务,就绪队列中最高优先级的任务将得到执行。 - -**任务入口函数** - -新任务得到调度后将执行的函数。该函数由用户实现,在任务创建时,通过任务创建结构体设置。 - -**任务栈** - -每个任务都拥有一个独立的栈空间,我们称为任务栈。栈空间里保存的信息包含局部变量、寄存器、函数参数、函数返回地址等。 - -**任务上下文** - -任务在运行过程中使用的一些资源,如寄存器等,称为任务上下文。当这个任务挂起时,其他任务继续执行,可能会修改寄存器等资源中的值。如果任务切换时没有保存任务上下文,可能会导致任务恢复后出现未知错误。因此在任务切换时会将切出任务的任务上下文信息,保存在自身的任务栈中,以便任务恢复后,从栈空间中恢复挂起时的上下文信息,从而继续执行挂起时被打断的代码。 - -**任务控制块TCB** - -每个任务都含有一个任务控制块\(TCB\)。TCB包含了任务上下文栈指针(stack pointer)、任务状态、任务优先级、任务ID、任务名、任务栈大小等信息。TCB可以反映出每个任务运行情况。 - -**任务切换** - -任务切换包含获取就绪队列中最高优先级任务、切出任务上下文保存、切入任务上下文恢复等动作。 - -## 任务运行机制 - -用户创建任务时,系统会初始化任务栈,预置上下文。此外,系统还会将“任务入口函数”地址放在相应位置。这样在任务第一次启动进入运行态时,将会执行“任务入口函数”。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/02.\344\273\273\345\212\241\347\256\241\347\220\206/02.\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/02.\344\273\273\345\212\241\347\256\241\347\220\206/02.\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index c8632ae79798cfdd75c074e54639ffdcf9de55c2..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/02.\344\273\273\345\212\241\347\256\241\347\220\206/02.\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,337 +0,0 @@ ---- -title: 开发指导 -permalink: /pages/01050101020202 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 开发指导 - -- [接口说明](#section158501652121514) -- [开发流程](#section783435801510) -- [编程实例](#section460018317164) - - [结果验证](#section189023104457) - - -任务创建后,内核可以执行锁任务调度,解锁任务调度,挂起,恢复,延时等操作,同时也可以设置任务优先级,获取任务优先级。 - -## 接口说明 - -OpenHarmony LiteOS-M内核的任务管理模块提供下面几种功能,接口详细信息可以查看API参考。 - -**表 1** 任务管理模块接口 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名

-

描述

-

创建和删除任务

-

LOS_TaskCreateOnly

-

创建任务,并使该任务进入suspend状态,不对该任务进行调度。如果需要调度,可以调用LOS_TaskResume使该任务进入ready状态。

-

LOS_TaskCreate

-

创建任务,并使该任务进入ready状态,如果就绪队列中没有更高优先级的任务,则运行该任务。

-

LOS_TaskDelete

-

删除指定的任务。

-

控制任务状态

-

LOS_TaskResume

-

恢复挂起的任务,使该任务进入ready状态。

-

LOS_TaskSuspend

-

挂起指定的任务,然后切换任务。

-

LOS_TaskJoin

-

挂起当前任务,等待指定任务运行结束并回收其任务控制块资源。

-

LOS_TaskDetach

-

修改任务的joinable属性为detach属性,detach属性的任务运行结束会自动回收任务控制块资源。

-

LOS_TaskDelay

-

任务延时等待,释放CPU,等待时间到期后该任务会重新进入ready状态。传入参数为Tick数目。

-

LOS_Msleep

-

传入参数为毫秒数,转换为Tick数目,调用LOS_TaskDelay。

-

LOS_TaskYield

-

当前任务时间片设置为0,释放CPU,触发调度运行就绪任务队列中优先级最高的任务。

-

控制任务调度

-

LOS_TaskLock

-

锁任务调度,但任务仍可被中断打断。

-

LOS_TaskUnlock

-

解锁任务调度。

-

LOS_Schedule

-

触发任务调度。

-

控制任务优先级

-

LOS_CurTaskPriSet

-

设置当前任务的优先级。

-

LOS_TaskPriSet

-

设置指定任务的优先级。

-

LOS_TaskPriGet

-

获取指定任务的优先级。

-

获取任务信息

-

LOS_CurTaskIDGet

-

获取当前任务的ID。

-

LOS_NextTaskIDGet

-

获取任务就绪队列中优先级最高的任务的ID。

-

LOS_NewTaskIDGet

-

等同LOS_NextTaskIDGet。

-

LOS_CurTaskNameGet

-

获取当前任务的名称。

-

LOS_TaskNameGet

-

获取指定任务的名称。

-

LOS_TaskStatusGet

-

获取指定任务的状态。

-

LOS_TaskInfoGet

-

获取指定任务的信息,包括任务状态、优先级、任务栈大小、栈顶指针SP、任务入口函数、已使用的任务栈大小等。

-

LOS_TaskIsRunning

-

获取任务模块是否已经开始调度运行。

-

任务信息维测

-

LOS_TaskSwitchInfoGet

-

获取任务切换信息,需要开启宏LOSCFG_BASE_CORE_EXC_TSK_SWITCH。

-
- -## 开发流程 - -本节介绍任务模块的典型场景开发流程: - -1. 锁任务调度LOS\_TaskLock,防止高优先级任务调度。 -2. 创建任务LOS\_TaskCreate。 -3. 解锁任务LOS\_TaskUnlock,让任务按照优先级进行调度。 -4. 延时任务LOS\_TaskDelay,任务延时等待。 -5. 挂起指定的任务LOS\_TaskSuspend,任务挂起等待恢复操作。 -6. 恢复挂起的任务LOS\_TaskResume。 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->- 执行Idle任务时,会对待回收链表中的任务控制块和任务栈进行回收。 ->- 任务名是指针,并没有分配空间,在设置任务名时,禁止将局部变量的地址赋值给任务名指针。 ->- 任务栈的大小按8字节大小对齐。确定任务栈大小的原则是,够用就行,多了浪费,少了任务栈溢出。 ->- 挂起当前任务时,如果已经锁任务调度,则无法挂起。 ->- Idle任务及软件定时器任务不能被挂起或者删除。 ->- 在中断处理函数中或者在锁任务的情况下,执行LOS\_TaskDelay会失败。 ->- 锁任务调度,并不关中断,因此任务仍可被中断打断。 ->- 锁任务调度必须和解锁任务调度配合使用。 ->- 设置任务优先级时可能会发生任务调度。 ->- 可配置的系统最大任务数是指:整个系统的任务总个数,而非用户能使用的任务个数。例如:系统软件定时器多占用一个任务资源,那么用户能使用的任务资源就会减少一个。 ->- LOS\_CurTaskPriSet和LOS\_TaskPriSet接口不能在中断中使用,也不能用于修改软件定时器任务的优先级。 ->- LOS\_TaskPriGet接口传入的task ID对应的任务未创建或者超过最大任务数,统一返回-1。 ->- 在删除任务时要保证任务申请的资源(如互斥锁、信号量等)已被释放。 - -## 编程实例 - -本实例介绍基本的任务操作方法,包含2个不同优先级任务的创建、任务延时、任务锁与解锁调度、挂起和恢复等操作,阐述任务优先级调度的机制以及各接口的应用。示例代码如下: - -``` -UINT32 g_taskHiId; -UINT32 g_taskLoId; -#define TSK_PRIOR_HI 4 -#define TSK_PRIOR_LO 5 - -UINT32 Example_TaskHi(VOID) -{ - UINT32 ret; - - printf("Enter TaskHi Handler.\n"); - - /* 延时100个Ticks,延时后该任务会挂起,执行剩余任务中最高优先级的任务(TaskLo任务) */ - ret = LOS_TaskDelay(100); - if (ret != LOS_OK) { - printf("Delay TaskHi Failed.\n"); - return LOS_NOK; - } - - /* 100个Ticks时间到了后,该任务恢复,继续执行 */ - printf("TaskHi LOS_TaskDelay Done.\n"); - - /* 挂起自身任务 */ - ret = LOS_TaskSuspend(g_taskHiId); - if (ret != LOS_OK) { - printf("Suspend TaskHi Failed.\n"); - return LOS_NOK; - } - printf("TaskHi LOS_TaskResume Success.\n"); - return ret; -} - -/* 低优先级任务入口函数 */ -UINT32 Example_TaskLo(VOID) -{ - UINT32 ret; - - printf("Enter TaskLo Handler.\n"); - - /* 延时100个Ticks,延时后该任务会挂起,执行剩余任务中最高优先级的任务 */ - ret = LOS_TaskDelay(100); - if (ret != LOS_OK) { - printf("Delay TaskLo Failed.\n"); - return LOS_NOK; - } - - printf("TaskHi LOS_TaskSuspend Success.\n"); - - /* 恢复被挂起的任务g_taskHiId */ - ret = LOS_TaskResume(g_taskHiId); - if (ret != LOS_OK) { - printf("Resume TaskHi Failed.\n"); - return LOS_NOK; - } - return ret; -} - -/* 任务测试入口函数,创建两个不同优先级的任务 */ -UINT32 Example_TskCaseEntry(VOID) -{ - UINT32 ret; - TSK_INIT_PARAM_S initParam = { 0 }; - - /* 锁任务调度,防止新创建的任务比本任务高而发生调度 */ - LOS_TaskLock(); - - printf("LOS_TaskLock() Success!\n"); - - initParam.pfnTaskEntry = (TSK_ENTRY_FUNC)Example_TaskHi; - initParam.usTaskPrio = TSK_PRIOR_HI; - initParam.pcName = "TaskHi"; - initParam.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE; - initParam.uwResved = LOS_TASK_ATTR_JOINABLE; - /* 创建高优先级任务,由于锁任务调度,任务创建成功后不会马上执行 */ - ret = LOS_TaskCreate(&g_taskHiId, &initParam); - if (ret != LOS_OK) { - LOS_TaskUnlock(); - - printf("Example_TaskHi create Failed!\n"); - return LOS_NOK; - } - - printf("Example_TaskHi create Success!\n"); - - initParam.pfnTaskEntry = (TSK_ENTRY_FUNC)Example_TaskLo; - initParam.usTaskPrio = TSK_PRIOR_LO; - initParam.pcName = "TaskLo"; - initParam.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE; - initParam.uwResved = 0; /* detach 属性 */ - - /* 创建低优先级任务,由于锁任务调度,任务创建成功后不会马上执行 */ - ret = LOS_TaskCreate(&g_taskLoId, &initParam); - if (ret != LOS_OK) { - LOS_TaskUnlock(); - printf("Example_TaskLo create Failed!\n"); - return LOS_NOK; - } - - printf("Example_TaskLo create Success!\n"); - - /* 解锁任务调度,此时会发生任务调度,执行就绪队列中最高优先级任务 */ - LOS_TaskUnlock(); - - ret = LOS_TaskJoin(g_taskHiId, NULL); - if (ret != LOS_OK) { - printf("Join Example_TaskHi Failed!\n"); - } else { - printf("Join Example_TaskHi Success!\n"); - } - return LOS_OK; -} -``` - -### 结果验证 - -编译运行得到的结果为: - -``` -LOS_TaskLock() Success! -Example_TaskHi create Success! -Example_TaskLo create Success! -Enter TaskHi Handler. -Enter TaskLo Handler. -TaskHi LOS_TaskDelay Done. -TaskHi LOS_TaskSuspend Success. -TaskHi LOS_TaskResume Success. -Join Example_TaskHi Success! -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/03.\345\206\205\345\255\230\347\256\241\347\220\206/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/03.\345\206\205\345\255\230\347\256\241\347\220\206/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" deleted file mode 100644 index c743f125a8afd9d7f2b55bd55491466d631dbb0e..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/03.\345\206\205\345\255\230\347\256\241\347\220\206/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" +++ /dev/null @@ -1,30 +0,0 @@ ---- -title: 基本概念 -permalink: /pages/01050101020301 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 基本概念 - -内存管理模块管理系统的内存资源,它是操作系统的核心模块之一,主要包括内存的初始化、分配以及释放。 - -在系统运行过程中,内存管理模块通过对内存的申请/释放来管理用户和OS对内存的使用,使内存的利用率和使用效率达到最优,同时最大限度地解决系统的内存碎片问题。 - -OpenHarmony LiteOS-M的内存管理分为静态内存管理和动态内存管理,提供内存初始化、分配、释放等功能。 - -- 动态内存:在动态内存池中分配用户指定大小的内存块。 - - 优点:按需分配。 - - 缺点:内存池中可能出现碎片。 - -- 静态内存:在静态内存池中分配用户初始化时预设(固定)大小的内存块。 - - 优点:分配和释放效率高,静态内存池中无碎片。 - - 缺点:只能申请到初始化预设大小的内存块,不能按需申请。 - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/03.\345\206\205\345\255\230\347\256\241\347\220\206/02.\351\235\231\346\200\201\345\206\205\345\255\230.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/03.\345\206\205\345\255\230\347\256\241\347\220\206/02.\351\235\231\346\200\201\345\206\205\345\255\230.md" deleted file mode 100644 index f15f0de89fb6f3f3f4ca103ce4c8757d019a4aea..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/03.\345\206\205\345\255\230\347\256\241\347\220\206/02.\351\235\231\346\200\201\345\206\205\345\255\230.md" +++ /dev/null @@ -1,195 +0,0 @@ ---- -title: 静态内存 -permalink: /pages/01050101020302 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 静态内存 - -- [运行机制](#section165473517522) -- [开发指导](#section57511620165218) - - [使用场景](#section215474911529) - - [接口说明](#section79231214539) - - [开发流程](#section1388511316548) - - [编程实例](#section17801515105519) - - [结果验证](#section11818154112319) - - -## 运行机制 - -静态内存实质上是一个静态数组,静态内存池内的块大小在初始化时设定,初始化后块大小不可变更。 - -静态内存池由一个控制块LOS\_MEMBOX\_INFO和若干相同大小的内存块LOS\_MEMBOX\_NODE构成。控制块位于内存池头部,用于内存块管理,包含内存块大小uwBlkSize,内存块数量uwBlkNum,已分配使用的内存块数量uwBlkCnt和空闲内存块链表stFreeList。内存块的申请和释放以块大小为粒度,每个内存块包含指向下一个内存块的指针pstNext。 - -**图 1** 静态内存示意图 -![](/images/device-dev/kernel/figure/静态内存示意图.png "静态内存示意图") - -## 开发指导 - -### 使用场景 - -当用户需要使用固定长度的内存时,可以通过静态内存分配的方式获取内存,一旦使用完毕,通过静态内存释放函数归还所占用内存,使之可以重复使用。 - -### 接口说明 - -OpenHarmony LiteOS-M的静态内存管理主要为用户提供以下功能,接口详细信息可以查看API参考。 - -**表 1** 静态内存模块接口 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名

-

描述

-

初始化静态内存池

-

LOS_MemboxInit

-

初始化一个静态内存池,根据入参设定其起始地址、总大小及每个内存块大小。

-

清除静态内存块内容

-

LOS_MemboxClr

-

清零从静态内存池中申请的静态内存块的内容。

-

申请、释放静态内存

-

LOS_MemboxAlloc

-

从指定的静态内存池中申请一块静态内存块。

-

LOS_MemboxFree

-

释放从静态内存池中申请的一块静态内存块。

-

获取、打印静态内存池信息

-

LOS_MemboxStatisticsGet

-

获取指定静态内存池的信息,包括内存池中总内存块数量、已经分配出去的内存块数量、每个内存块的大小。

-

LOS_ShowBox

-

打印指定静态内存池所有节点信息(打印等级是LOS_INFO_LEVEL),包括内存池起始地址、内存块大小、总内存块数量、每个空闲内存块的起始地址、所有内存块的起始地址。

-
- ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->初始化后的内存池的内存块数量,不等于总大小除于内存块大小,因为内存池的控制块和每个内存块的控制头,都存在内存开销,设置总大小时,需要将这些因素考虑进去。 - -### 开发流程 - -本节介绍使用静态内存的典型场景开发流程。 - -1. 规划一片内存区域作为静态内存池。 -2. 调用LOS\_MemboxInit初始化静态内存池。 - - 初始化会将入参指定的内存区域分割为N块(N值取决于静态内存总大小和块大小),将所有内存块挂到空闲链表,在内存起始处放置控制头。 - -3. 调用LOS\_MemboxAlloc接口分配静态内存。 - - 系统将会从空闲链表中获取第一个空闲块,并返回该内存块的起始地址。 - -4. 调用LOS\_MemboxClr接口。 - - 将入参地址对应的内存块清零。 - -5. 调用LOS\_MemboxFree接口。 - - 将该内存块加入空闲链表。 - - -### 编程实例 - -本实例执行以下步骤: - -1. 初始化一个静态内存池。 -2. 从静态内存池中申请一块静态内存。 -3. 在内存块存放一个数据。 -4. 打印出内存块中的数据。 -5. 清除内存块中的数据。 -6. 释放该内存块。 - - 示例代码如下: - - -``` -#include "los_membox.h" - -VOID Example_StaticMem(VOID) -{ - UINT32 *mem = NULL; - UINT32 blkSize = 10; - UINT32 boxSize = 100; - UINT32 boxMem[1000]; - UINT32 ret; - - /*内存池初始化*/ - ret = LOS_MemboxInit(&boxMem[0], boxSize, blkSize); - if(ret != LOS_OK) { - printf("Membox init failed!\n"); - return; - } else { - printf("Membox init success!\n"); - } - - /*申请内存块*/ - mem = (UINT32 *)LOS_MemboxAlloc(boxMem); - if (NULL == mem) { - printf("Mem alloc failed!\n"); - return; - } - printf("Mem alloc success!\n"); - - /*赋值*/ - *mem = 828; - printf("*mem = %d\n", *mem); - - /*清除内存内容*/ - LOS_MemboxClr(boxMem, mem); - printf("Mem clear success \n *mem = %d\n", *mem); - - /*释放内存*/ - ret = LOS_MemboxFree(boxMem, mem); - if (LOS_OK == ret) { - printf("Mem free success!\n"); - } else { - printf("Mem free failed!\n"); - } - - return; -} -``` - -### 结果验证 - -输出结果如下: - -``` -Membox init success! -Mem alloc success! -*mem = 828 -Mem clear success -*mem = 0 -Mem free success! -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/03.\345\206\205\345\255\230\347\256\241\347\220\206/03.\345\212\250\346\200\201\345\206\205\345\255\230.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/03.\345\206\205\345\255\230\347\256\241\347\220\206/03.\345\212\250\346\200\201\345\206\205\345\255\230.md" deleted file mode 100644 index 5f2232bc53cf5c00fb5d1f9596c66fb4d6ca5f40..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/03.\345\206\205\345\255\230\347\256\241\347\220\206/03.\345\212\250\346\200\201\345\206\205\345\255\230.md" +++ /dev/null @@ -1,264 +0,0 @@ ---- -title: 动态内存 -permalink: /pages/01050101020303 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 动态内存 - -- [运行机制](#section328282013571) -- [开发指导](#section7921151015814) - - [使用场景](#section326917198583) - - [接口说明](#section1032331584) - - [开发流程](#section07271773592) - - [编程实例](#section84931234145913) - - [结果验证](#section165233233917) - - -## 运行机制 - -动态内存管理,即在内存资源充足的情况下,根据用户需求,从系统配置的一块比较大的连续内存(内存池,也是堆内存)中分配任意大小的内存块。当用户不需要该内存块时,又可以释放回系统供下一次使用。与静态内存相比,动态内存管理的优点是按需分配,缺点是内存池中容易出现碎片。 - -OpenHarmony LiteOS-M动态内存在TLSF算法的基础上,对区间的划分进行了优化,获得更优的性能,降低了碎片率。动态内存核心算法框图如下: - -**图 1** 动态内存核心算法 -![](/images/device-dev/kernel/figure/轻量系统动态内存核心算法.png "动态内存核心算法") - -根据空闲内存块的大小,使用多个空闲链表来管理。根据内存空闲块大小分为两个部分:\[4, 127\]和\[27, 231\],如上图size class所示: - -1. 对\[4,127\]区间的内存进行等分,如上图下半部分所示,分为31个小区间,每个小区间对应内存块大小为4字节的倍数。每个小区间对应一个空闲内存链表和用于标记对应空闲内存链表是否为空的一个比特位,值为1时,空闲链表非空。\[4,127\]区间的31个小区间内存对应31个比特位进行标记链表是否为空。 -2. 大于127字节的空闲内存块,按照2的次幂区间大小进行空闲链表管理。总共分为24个小区间,每个小区间又等分为8个二级小区间,见上图上半部分的Size Class和Size SubClass部分。每个二级小区间对应一个空闲链表和用于标记对应空闲内存链表是否为空的一个比特位。总共24\*8=192个二级小区间,对应192个空闲链表和192个比特位进行标记链表是否为空。 - -例如,当有40字节的空闲内存需要插入空闲链表时,对应小区间\[40,43\],第10个空闲链表,位图标记的第10比特位。把40字节的空闲内存挂载第10个空闲链表上,并判断是否需要更新位图标记。当需要申请40字节的内存时,根据位图标记获取存在满足申请大小的内存块的空闲链表,从空闲链表上获取空闲内存节点。如果分配的节点大于需要申请的内存大小,进行分割节点操作,剩余的节点重新挂载到相应的空闲链表上。当有580字节的空闲内存需要插入空闲链表时,对应二级小区间\[2^9,2^9+2^6\],第31+2\*8=47个空闲链表,并使用位图的第47个比特位来标记链表是否为空。把580字节的空闲内存挂载第47个空闲链表上,并判断是否需要更新位图标记。当需要申请580字节的内存时,根据位图标记获取存在满足申请大小的内存块的空闲链表,从空闲链表上获取空闲内存节点。如果分配的节点大于需要申请的内存大小,进行分割节点操作,剩余的节点重新挂载到相应的空闲链表上。如果对应的空闲链表为空,则向更大的内存区间去查询是否有满足条件的空闲链表,实际计算时,会一次性查找到满足申请大小的空闲链表。 - -内存管理结构如下图所示: - -**图 2** 动态内存管理结构图 -![](/images/device-dev/kernel/figure/动态内存管理结构图.png "动态内存管理结构图") - -- 内存池池头部分 - - 内存池池头部分包含内存池信息、位图标记数组和空闲链表数组。内存池信息包含内存池起始地址及堆区域总大小,内存池属性。位图标记数组有7个32位无符号整数组成,每个比特位标记对应的空闲链表是否挂载空闲内存块节点。空闲内存链表包含223个空闲内存头节点信息,每个空闲内存头节点信息维护内存节点头和空闲链表中的前驱、后继空闲内存节点。 - -- 内存池节点部分 - - 包含3种类型节点:未使用空闲内存节点,已使用内存节点和尾节点。每个内存节点维护一个前序指针,指向内存池中上一个内存节点,还维护内存节点的大小和使用标记。空闲内存节点和已使用内存节点后面的内存区域是数据域,尾节点没有数据域。 - -一些芯片片内RAM大小无法满足要求,需要使用片外物理内存进行扩充。对于这样的多段非连续性内存,OpenHarmony LiteOS-M内核支持把多个非连续性内存逻辑上合一,用户不感知底层的多段非连续性内存区域。OpenHarmony LiteOS-M内核内存模块把不连续的内存区域作为空闲内存结点插入到空闲内存节点链表,把不同内存区域间的不连续部分标记为虚拟的已使用内存节点,从逻辑上把多个非连续性内存区域实现为一个统一的内存池。下面通过示意图说明下多段非连续性内存的运行机制: - -**图 3** 非连续性内存合一示意图 -![](/images/device-dev/kernel/figure/非连续性内存合一示意图.png "非连续性内存合一示意图") - -结合上述示意图,非连续性内存合并为一个统一的内存池的步骤如下: -1. 把多段非连续性内存区域的第一块内存区域通过调用LOS_MemInit接口进行初始化。 -2. 获取下一个内存区域的开始地址和长度,计算该内存区域和上一块内存区域的间隔大小gapSize。 -3. 把内存区域间隔部分视为虚拟的已使用节点,使用上一个内存区域的尾节点,设置其大小为gapSize+ OS_MEM_NODE_HEAD_SIZE。 -4. 把当前内存区域划分为一个空闲内存节点和一个尾节点,把空闲内存节点插入到空闲链表,并设置各个节点的前后链接关系。 -5. 如果有更多的非连续内存区域,重复上述步骤2-4。 - - -## 开发指导 - -### 使用场景 - -动态内存管理的主要工作是动态分配并管理用户申请到的内存区间。动态内存管理主要用于用户需要使用大小不等的内存块的场景,当用户需要使用内存时,可以通过操作系统的动态内存申请函数索取指定大小的内存块,一旦使用完毕,通过动态内存释放函数归还所占用内存,使之可以重复使用。 - -### 接口说明 - -OpenHarmony LiteOS-M的动态内存管理主要为用户提供以下功能,接口详细信息可以查看API参考。 - -**表 1** 动态内存模块接口 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名

-

描述

-

初始化和删除内存池

-

LOS_MemInit

-

初始化一块指定的动态内存池,大小为size。

-

LOS_MemDeInit

-

删除指定内存池,仅打开LOSCFG_MEM_MUL_POOL时有效。

-

申请、释放动态内存

-

LOS_MemAlloc

-

从指定动态内存池中申请size长度的内存。

-

LOS_MemFree

-

释放从指定动态内存中申请的内存。

-

LOS_MemRealloc

-

按size大小重新分配内存块,并将原内存块内容拷贝到新内存块。如果新内存块申请成功,则释放原内存块。

-

LOS_MemAllocAlign

-

从指定动态内存池中申请长度为size且地址按boundary字节对齐的内存。

-

获取内存池信息

-

LOS_MemPoolSizeGet

-

获取指定动态内存池的总大小。

-

LOS_MemTotalUsedGet

-

获取指定动态内存池的总使用量大小。

-

LOS_MemInfoGet

-

获取指定内存池的内存结构信息,包括空闲内存大小、已使用内存大小、空闲内存块数量、已使用的内存块数量、最大的空闲内存块大小。

-

LOS_MemPoolList

-

打印系统中已初始化的所有内存池,包括内存池的起始地址、内存池大小、空闲内存总大小、已使用内存总大小、最大的空闲内存块大小、空闲内存块数量、已使用的内存块数量。仅打开LOSCFG_MEM_MUL_POOL时有效。

-

获取内存块信息

-

LOS_MemFreeNodeShow

-

打印指定内存池的空闲内存块的大小及数量。

-

LOS_MemUsedNodeShow

-

打印指定内存池的已使用内存块的大小及数量。

-

检查指定内存池的完整性

-

LOS_MemIntegrityCheck

-

对指定内存池做完整性检查,仅打开LOSCFG_BASE_MEM_NODE_INTEGRITY_CHECK时有效。

-

增加非连续性内存区域

-

LOS_MemRegionsAdd

-

支持多段非连续性内存区域,把非连续性内存区域逻辑上整合为一个统一的内存池。仅打开LOSCFG_MEM_MUL_REGIONS时有效。如果内存池指针参数pool为空,则使用多段内存的第一个初始化为内存池,其他内存区域,作为空闲节点插入;如果内存池指针参数pool不为空,则把多段内存作为空闲节点,插入到指定的内存池。

-
- ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->- 由于动态内存管理需要管理控制块数据结构来管理内存,这些数据结构会额外消耗内存,故实际用户可使用内存总量小于配置项OS\_SYS\_MEM\_SIZE的大小。 ->- 对齐分配内存接口LOS\_MemAllocAlign/LOS\_MemMallocAlign因为要进行地址对齐,可能会额外消耗部分内存,故存在一些遗失内存,当系统释放该对齐内存时,同时回收由于对齐导致的遗失内存。 ->- 非连续性内存区域接口LOS\_MemRegionsAdd的LosMemRegion数组参数传入的非连续性内存区域需要按各个内存区域的内存开始地址升序,且内存区域不能重叠。 - -### 开发流程 - -本节介绍使用动态内存的典型场景开发流程。 - -1. 初始化LOS\_MemInit。 - - 初始一个内存池后生成一个内存池控制头、尾节点EndNode,剩余的内存被标记为FreeNode内存节点。注:EndNode作为内存池末尾的节点,size为0。 - - -1. 申请任意大小的动态内存LOS\_MemAlloc。 - - 判断动态内存池中是否存在大于申请量大小的空闲内存块空间,若存在,则划出一块内存块,以指针形式返回,若不存在,返回NULL。如果空闲内存块大于申请量,需要对内存块进行分割,剩余的部分作为空闲内存块挂载到空闲内存链表上。 - - -1. 释放动态内存LOS\_MemFree。 - - 回收内存块,供下一次使用。调用LOS\_MemFree释放内存块,则会回收内存块,并且将其标记为FreeNode。在回收内存块时,相邻的FreeNode会自动合并。 - - -### 编程实例 - -本实例执行以下步骤: - -1. 初始化一个动态内存池。 -2. 从动态内存池中申请一个内存块。 -3. 在内存块中存放一个数据。 -4. 打印出内存块中的数据。 -5. 释放该内存块。 - -示例代码如下: - -``` -#include "los_memory.h" - -#define TEST_POOL_SIZE (2*1024) -__attribute__((aligned(4))) UINT8 g_testPool[TEST_POOL_SIZE]; - -VOID Example_DynMem(VOID) -{ - UINT32 *mem = NULL; - UINT32 ret; - - /*初始化内存池*/ - ret = LOS_MemInit(g_testPool, TEST_POOL_SIZE); - if (LOS_OK == ret) { - printf("Memory pool initialized.\n"); - } else { - printf("Memory pool initialization failed.\n"); - return; - } - - /*分配内存*/ - mem = (UINT32 *)LOS_MemAlloc(g_testPool, 4); - if (NULL == mem) { - printf("Memory allocation failed.\n"); - return; - } - printf("Memory allocated.\n"); - - /*赋值*/ - *mem = 828; - printf("*mem = %d\n", *mem); - - /*释放内存*/ - ret = LOS_MemFree(g_testPool, mem); - if (LOS_OK == ret) { - printf("Memory released.\n"); - } else { - printf("Memory release failed.\n"); - } - - return; -} -``` - -### 结果验证 - -输出结果如下: - -``` -Memory pool initialized. -Memory allocated. -*mem = 828 -Memory released. -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/01.\344\272\213\344\273\266/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/01.\344\272\213\344\273\266/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" deleted file mode 100644 index 2ef5b4fcb0bc4583e203d9d5ed8f05f96e7e4b11..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/01.\344\272\213\344\273\266/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" +++ /dev/null @@ -1,63 +0,0 @@ ---- -title: 基本概念 -permalink: /pages/0105010102040101 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 基本概念 - -- [运行机制](#section1735611583011) - - [事件控制块](#section1161415384467) - - [事件运作原理](#section187761153144617) - - -事件(Event)是一种任务间的通信机制,可用于任务间的同步操作。事件的特点是: - -- 任务间的事件同步,可以一对多,也可以多对多。一对多表示一个任务可以等待多个事件,多对多表示多个任务可以等待多个事件。但是一次写事件最多触发一个任务从阻塞中醒来。 -- 事件读超时机制。 -- 只做任务间同步,不传输具体数据。 - -提供了事件初始化、事件读写、事件清零、事件销毁等接口。 - -## 运行机制 - -### 事件控制块 - -``` -/** - * 事件控制块数据结构 - */ -typedef struct tagEvent { - UINT32 uwEventID; /* 事件集合,表示已经处理(写入和清零)的事件集合 */ - LOS_DL_LIST stEventList; /* 等待特定事件的任务链表 */ -} EVENT_CB_S, *PEVENT_CB_S; -``` - -### 事件运作原理 - -**事件初始化**:会创建一个事件控制块,该控制块维护一个已处理的事件集合,以及等待特定事件的任务链表。 - -**写事件**:会向事件控制块写入指定的事件,事件控制块更新事件集合,并遍历任务链表,根据任务等待具体条件满足情况决定是否唤醒相关任务。 - -**读事件**:如果读取的事件已存在时,会直接同步返回。其他情况会根据超时时间以及事件触发情况,来决定返回时机:等待的事件条件在超时时间耗尽之前到达,阻塞任务会被直接唤醒,否则超时时间耗尽该任务才会被唤醒。 - -读事件条件满足与否取决于入参eventMask和mode,eventMask即需要关注的事件类型掩码。mode是具体处理方式,分以下三种情况: - -- LOS\_WAITMODE\_AND:逻辑与,基于接口传入的事件类型掩码eventMask,只有这些事件都已经发生才能读取成功,否则该任务将阻塞等待或者返回错误码。。 -- LOS\_WAITMODE\_OR:逻辑或,基于接口传入的事件类型掩码eventMask,只要这些事件中有任一种事件发生就可以读取成功,否则该任务将阻塞等待或者返回错误码。 -- LOS\_WAITMODE\_CLR:这是一种附加读取模式,需要与所有事件模式或任一事件模式结合使用(LOS\_WAITMODE\_AND | LOS\_WAITMODE\_CLR或 LOS\_WAITMODE\_OR | LOS\_WAITMODE\_CLR)。在这种模式下,当设置的所有事件模式或任一事件模式读取成功后,会自动清除事件控制块中对应的事件类型位。 - -**事件清零**:根据指定掩码,去对事件控制块的事件集合进行清零操作。当掩码为0时,表示将事件集合全部清零。当掩码为0xffff时,表示不清除任何事件,保持事件集合原状。 - -**事件销毁**:销毁指定的事件控制块。 - -**图 1** 事件运作原理图 -![](/images/device-dev/kernel/figure/事件运作原理图.png "事件运作原理图") - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/01.\344\272\213\344\273\266/02.\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/01.\344\272\213\344\273\266/02.\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index ec5f74aacf909e4b974cc230ed5f516276c00eb5..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/01.\344\272\213\344\273\266/02.\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,207 +0,0 @@ ---- -title: 开发指导 -permalink: /pages/0105010102040102 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 开发指导 - -- [接口说明](#section158501652121514) -- [开发流程](#section783435801510) -- [编程实例](#section460018317164) - - [实例描述](#section896412438910) - - [示例代码](#section149077554912) - - [结果验证](#section4461439172017) - - -## 接口说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名

-

描述

-

事件检测

-

LOS_EventPoll

-

根据eventID,eventMask(事件掩码),mode(事件读取模式),检查用户期待的事件是否发生。

-
须知:

当mode含LOS_WAITMODE_CLR,且用户期待的事件发生时,此时eventID中满足要求的事件会被清零,这种情况下eventID既是入参也是出参。其他情况eventID只作为入参。

-
-

初始化

-

LOS_EventInit

-

事件控制块初始化。

-

事件读

-

LOS_EventRead

-

读事件(等待事件),任务会根据timeOut(单位:tick)进行阻塞等待;

-

未读取到事件时,返回值为0;

-

正常读取到事件时,返回正值(事件发生的集合);

-

其他情况返回特定错误码。

-

事件写

-

LOS_EventWrite

-

写一个特定的事件到事件控制块。

-

事件清除

-

LOS_EventClear

-

根据events掩码,清除事件控制块中的事件。

-

事件销毁

-

LOS_EventDestroy

-

事件控制块销毁。

-
- -## 开发流程 - -事件的典型开发流程: - -1. 初始化事件控制块 -2. 阻塞读事件控制块 -3. 写入相关事件 -4. 阻塞任务被唤醒,读取事件并检查是否满足要求 -5. 处理事件控制块 -6. 事件控制块销毁 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->- 进行事件读写操作时,事件的第25位为保留位,不可以进行位设置。 ->- 对同一事件反复写入,算作一次写入。 - -## 编程实例 - -### 实例描述 - -示例中,任务Example\_TaskEntry创建一个任务Example\_Event,Example\_Event读事件阻塞,Example\_TaskEntry向该任务写事件。可以通过示例日志中打印的先后顺序理解事件操作时伴随的任务切换。 - -1. 在任务Example\_TaskEntry创建任务Example\_Event,其中任务Example\_Event优先级高于Example\_TaskEntry。 -2. 在任务Example\_Event中读事件0x00000001,阻塞,发生任务切换,执行任务Example\_TaskEntry。 -3. 在任务Example\_TaskEntry向任务Example\_Event写事件0x00000001,发生任务切换,执行任务Example\_Event。 -4. Example\_Event得以执行,直到任务结束。 -5. Example\_TaskEntry得以执行,直到任务结束。 - -### 示例代码 - -示例代码如下: - -``` -#include "los_event.h" -#include "los_task.h" -#include "securec.h" - -/* 任务ID */ -UINT32 g_testTaskId; - -/* 事件控制结构体 */ -EVENT_CB_S g_exampleEvent; - -/* 等待的事件类型 */ -#define EVENT_WAIT 0x00000001 - -/* 用例任务入口函数 */ -VOID Example_Event(VOID) -{ - UINT32 ret; - UINT32 event; - - /* 超时等待方式读事件,超时时间为100 ticks, 若100 ticks后未读取到指定事件,读事件超时,任务直接唤醒 */ - printf("Example_Event wait event 0x%x \n", EVENT_WAIT); - - event = LOS_EventRead(&g_exampleEvent, EVENT_WAIT, LOS_WAITMODE_AND, 100); - if (event == EVENT_WAIT) { - printf("Example_Event,read event :0x%x\n", event); - } else { - printf("Example_Event,read event timeout\n"); - } -} - -UINT32 Example_TaskEntry(VOID) -{ - UINT32 ret; - TSK_INIT_PARAM_S task1; - - /* 事件初始化 */ - ret = LOS_EventInit(&g_exampleEvent); - if (ret != LOS_OK) { - printf("init event failed .\n"); - return -1; - } - - /* 创建任务 */ - (VOID)memset_s(&task1, sizeof(TSK_INIT_PARAM_S), 0, sizeof(TSK_INIT_PARAM_S)); - task1.pfnTaskEntry = (TSK_ENTRY_FUNC)Example_Event; - task1.pcName = "EventTsk1"; - task1.uwStackSize = OS_TSK_DEFAULT_STACK_SIZE; - task1.usTaskPrio = 5; - ret = LOS_TaskCreate(&g_testTaskId, &task1); - if (ret != LOS_OK) { - printf("task create failed.\n"); - return LOS_NOK; - } - - /* 写g_testTaskId 等待事件 */ - printf("Example_TaskEntry write event.\n"); - - ret = LOS_EventWrite(&g_exampleEvent, EVENT_WAIT); - if (ret != LOS_OK) { - printf("event write failed.\n"); - return LOS_NOK; - } - - /* 清标志位 */ - printf("EventMask:%d\n", g_exampleEvent.uwEventID); - LOS_EventClear(&g_exampleEvent, ~g_exampleEvent.uwEventID); - printf("EventMask:%d\n", g_exampleEvent.uwEventID); - - /* 删除任务 */ - ret = LOS_TaskDelete(g_testTaskId); - if (ret != LOS_OK) { - printf("task delete failed.\n"); - return LOS_NOK; - } - - return LOS_OK; -} -``` - -### 结果验证 - -编译运行得到的结果为: - -``` -Example_Event wait event 0x1 -Example_TaskEntry write event. -Example_Event,read event :0x1 -EventMask:1 -EventMask:0 -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/02.\344\272\222\346\226\245\351\224\201/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/02.\344\272\222\346\226\245\351\224\201/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" deleted file mode 100644 index b5f1498f7b221ecd7c1f9a8360e16c1fdc60c47c..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/02.\344\272\222\346\226\245\351\224\201/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" +++ /dev/null @@ -1,32 +0,0 @@ ---- -title: 基本概念 -permalink: /pages/0105010102040201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 基本概念 - -- [运行机制](#section115161649726) - -互斥锁又称互斥型信号量,是一种特殊的二值性信号量,用于实现对共享资源的独占式处理。 - -任意时刻互斥锁的状态只有两种,开锁或闭锁。当有任务持有时,互斥锁处于闭锁状态,这个任务获得该互斥锁的所有权。当该任务释放它时,该互斥锁被开锁,任务失去该互斥锁的所有权。当一个任务持有互斥锁时,其他任务将不能再对该互斥锁进行开锁或持有。 - -多任务环境下往往存在多个任务竞争同一共享资源的应用场景,互斥锁可被用于对共享资源的保护从而实现独占式访问。另外互斥锁可以解决信号量存在的优先级翻转问题。 - -## 运行机制 - -多任务环境下会存在多个任务访问同一公共资源的场景,而有些公共资源是非共享的,需要任务进行独占式处理。互斥锁怎样来避免这种冲突呢? - -用互斥锁处理非共享资源的同步访问时,如果有任务访问该资源,则互斥锁为加锁状态。此时其他任务如果想访问这个公共资源则会被阻塞,直到互斥锁被持有该锁的任务释放后,其他任务才能重新访问该公共资源,此时互斥锁再次上锁,如此确保同一时刻只有一个任务正在访问这个公共资源,保证了公共资源操作的完整性。 - -**图 1** 互斥锁运作示意图 -![](/images/device-dev/kernel/figure/互斥锁运作示意图.png "互斥锁运作示意图") - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/02.\344\272\222\346\226\245\351\224\201/02.\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/02.\344\272\222\346\226\245\351\224\201/02.\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index 39b12da0418837be6f16a13f2f25e951f75f3681..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/02.\344\272\222\346\226\245\351\224\201/02.\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,218 +0,0 @@ ---- -title: 开发指导 -permalink: /pages/0105010102040202 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 开发指导 - -- [接口说明](#section158501652121514) -- [开发流程](#section783435801510) -- [编程实例](#section1426719434114) - - [实例描述](#section896412438910) - - [示例代码](#section149077554912) - - [结果验证](#section2059413981311) - - -## 接口说明 - -**表 1** 互斥锁模块接口 - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名

-

描述

-

互斥锁的创建和删除

-

LOS_MuxCreate

-

创建互斥锁

-

LOS_MuxDelete

-

删除指定的互斥锁

-

互斥锁的申请和释放

-

LOS_MuxPend

-

申请指定的互斥锁

-

LOS_MuxPost

-

释放指定的互斥锁

-
- -## 开发流程 - -互斥锁典型场景的开发流程: - -1. 创建互斥锁LOS\_MuxCreate。 -2. 申请互斥锁LOS\_MuxPend。 - - 申请模式有三种:无阻塞模式、永久阻塞模式、定时阻塞模式。 - - - 无阻塞模式:任务需要申请互斥锁,若该互斥锁当前没有任务持有,或者持有该互斥锁的任务和申请该互斥锁的任务为同一个任务,则申请成功。 - - 永久阻塞模式:任务需要申请互斥锁,若该互斥锁当前没有被占用,则申请成功。否则,该任务进入阻塞态,系统切换到就绪任务中优先级高者继续执行。任务进入阻塞态后,直到有其他任务释放该互斥锁,阻塞任务才会重新得以执行。 - - 定时阻塞模式:任务需要申请互斥锁,若该互斥锁当前没有被占用,则申请成功。否则该任务进入阻塞态,系统切换到就绪任务中优先级高者继续执行。任务进入阻塞态后,指定时间超时前有其他任务释放该互斥锁,或者用户指定时间超时后,阻塞任务才会重新得以执行。 - -3. 释放互斥锁LOS\_MuxPost。 - - 如果有任务阻塞于指定互斥锁,则唤醒被阻塞任务中优先级高的,该任务进入就绪态,并进行任务调度; - - 如果没有任务阻塞于指定互斥锁,则互斥锁释放成功。 - -4. 删除互斥锁LOS\_MuxDelete。 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->- 两个任务不能对同一把互斥锁加锁。如果某任务对已被持有的互斥锁加锁,则该任务会被挂起,直到持有该锁的任务对互斥锁解锁,才能执行对这把互斥锁的加锁操作。 ->- 互斥锁不能在中断服务程序中使用。 ->- LiteOS-M内核作为实时操作系统需要保证任务调度的实时性,尽量避免任务的长时间阻塞,因此在获得互斥锁之后,应该尽快释放互斥锁。 ->- 持有互斥锁的过程中,不得再调用LOS\_TaskPriSet等接口更改持有互斥锁任务的优先级。 - -## 编程实例 - -### 实例描述 - -本实例实现如下流程。 - -1. 任务Example\_TaskEntry创建一个互斥锁,锁任务调度,创建两个任务Example\_MutexTask1、Example\_MutexTask2。Example\_MutexTask2优先级高于Example\_MutexTask1,解锁任务调度。 -2. Example\_MutexTask2被调度,以永久阻塞模式申请互斥锁,并成功获取到该互斥锁,然后任务休眠100Tick,Example\_MutexTask2挂起,Example\_MutexTask1被唤醒。 -3. Example\_MutexTask1以定时阻塞模式申请互斥锁,等待时间为10Tick,因互斥锁仍被Example\_MutexTask2持有,Example\_MutexTask1挂起。10Tick超时时间到达后,Example\_MutexTask1被唤醒,以永久阻塞模式申请互斥锁,因互斥锁仍被Example\_MutexTask2持有,Example\_MutexTask1挂起。 -4. 100Tick休眠时间到达后,Example\_MutexTask2被唤醒, 释放互斥锁,唤醒Example\_MutexTask1。Example\_MutexTask1成功获取到互斥锁后,释放,删除互斥锁。 - -### 示例代码 - -示例代码如下: - -``` -#include -#include "los_mux.h" - -/* 互斥锁句柄id */ -UINT32 g_testMux; -/* 任务ID */ -UINT32 g_testTaskId01; -UINT32 g_testTaskId02; - -VOID Example_MutexTask1(VOID) -{ - UINT32 ret; - - printf("task1 try to get mutex, wait 10 ticks.\n"); - /* 申请互斥锁 */ - ret = LOS_MuxPend(g_testMux, 10); - - if (ret == LOS_OK) { - printf("task1 get mutex g_testMux.\n"); - /* 释放互斥锁 */ - LOS_MuxPost(g_testMux); - return; - } - if (ret == LOS_ERRNO_MUX_TIMEOUT ) { - printf("task1 timeout and try to get mutex, wait forever.\n"); - /* 申请互斥锁 */ - ret = LOS_MuxPend(g_testMux, LOS_WAIT_FOREVER); - if (ret == LOS_OK) { - printf("task1 wait forever, get mutex g_testMux.\n"); - /* 释放互斥锁 */ - LOS_MuxPost(g_testMux); - /* 删除互斥锁 */ - LOS_MuxDelete(g_testMux); - printf("task1 post and delete mutex g_testMux.\n"); - return; - } - } - return; -} - -VOID Example_MutexTask2(VOID) -{ - printf("task2 try to get mutex, wait forever.\n"); - /* 申请互斥锁 */ - (VOID)LOS_MuxPend(g_testMux, LOS_WAIT_FOREVER); - - printf("task2 get mutex g_testMux and suspend 100 ticks.\n"); - - /* 任务休眠100Ticks */ - LOS_TaskDelay(100); - - printf("task2 resumed and post the g_testMux\n"); - /* 释放互斥锁 */ - LOS_MuxPost(g_testMux); - return; -} - -UINT32 Example_TaskEntry(VOID) -{ - UINT32 ret; - TSK_INIT_PARAM_S task1; - TSK_INIT_PARAM_S task2; - - /* 创建互斥锁 */ - LOS_MuxCreate(&g_testMux); - - /* 锁任务调度 */ - LOS_TaskLock(); - - /* 创建任务1 */ - memset(&task1, 0, sizeof(TSK_INIT_PARAM_S)); - task1.pfnTaskEntry = (TSK_ENTRY_FUNC)Example_MutexTask1; - task1.pcName = "MutexTsk1"; - task1.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE; - task1.usTaskPrio = 5; - ret = LOS_TaskCreate(&g_testTaskId01, &task1); - if (ret != LOS_OK) { - printf("task1 create failed.\n"); - return LOS_NOK; - } - - /* 创建任务2 */ - memset(&task2, 0, sizeof(TSK_INIT_PARAM_S)); - task2.pfnTaskEntry = (TSK_ENTRY_FUNC)Example_MutexTask2; - task2.pcName = "MutexTsk2"; - task2.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE; - task2.usTaskPrio = 4; - ret = LOS_TaskCreate(&g_testTaskId02, &task2); - if (ret != LOS_OK) { - printf("task2 create failed.\n"); - return LOS_NOK; - } - - /* 解锁任务调度 */ - LOS_TaskUnlock(); - - return LOS_OK; -} -``` - -### 结果验证 - -编译运行得到的结果为: - -``` -task2 try to get mutex, wait forever. -task2 get mutex g_testMux and suspend 100 ticks. -task1 try to get mutex, wait 10 ticks. -task1 timeout and try to get mutex, wait forever. -task2 resumed and post the g_testMux -task1 wait forever, get mutex g_testMux. -task1 post and delete mutex g_testMux. -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/03.\346\266\210\346\201\257\351\230\237\345\210\227/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/03.\346\266\210\346\201\257\351\230\237\345\210\227/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" deleted file mode 100644 index 86d9a18e675a8f2b8f01f98c473ed725f79e0436..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/03.\346\266\210\346\201\257\351\230\237\345\210\227/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" +++ /dev/null @@ -1,80 +0,0 @@ ---- -title: 基本概念 -permalink: /pages/0105010102040301 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 基本概念 - -- [运行机制](#section1582619446311) - - [队列控制块](#section1648304614720) - - [队列运作原理](#section15384012164811) - - -队列又称消息队列,是一种常用于任务间通信的数据结构。队列接收来自任务或中断的不固定长度消息,并根据不同的接口确定传递的消息是否存放在队列空间中。 - -任务能够从队列里面读取消息,当队列中的消息为空时,挂起读取任务;当队列中有新消息时,挂起的读取任务被唤醒并处理新消息。任务也能够往队列里写入消息,当队列已经写满消息时,挂起写入任务;当队列中有空闲消息节点时,挂起的写入任务被唤醒并写入消息。 - -可以通过调整读队列和写队列的超时时间来调整读写接口的阻塞模式,如果将读队列和写队列的超时时间设置为0,就不会挂起任务,接口会直接返回,这就是非阻塞模式。反之,如果将都队列和写队列的超时时间设置为大于0的时间,就会以阻塞模式运行。 - -消息队列提供了异步处理机制,允许将一个消息放入队列,但不立即处理。同时队列还有缓冲消息的作用,可以使用队列实现任务异步通信,队列具有如下特性: - -- 消息以先进先出的方式排队,支持异步读写。 -- 读队列和写队列都支持超时机制。 -- 每读取一条消息,就会将该消息节点设置为空闲。 -- 发送消息类型由通信双方约定,可以允许不同长度(不超过队列的消息节点大小)的消息。 -- 一个任务能够从任意一个消息队列接收和发送消息。 -- 多个任务能够从同一个消息队列接收和发送消息。 -- 创建队列时所需的队列空间,接口内系统自行动态申请内存。 - -## 运行机制 - -### 队列控制块 - -``` -/** - * 队列控制块数据结构 - */ -typedef struct -{ - UINT8 *queue; /* 队列消息内存空间的指针 */ - UINT16 queueState; /* 队列状态 */ - UINT16 queueLen; /* 队列中消息节点个数,即队列长度 */ - UINT16 queueSize; /* 消息节点大小 */ - UINT16 queueID; /* 队列ID */ - UINT16 queueHead; /* 消息头节点位置(数组下标)*/ - UINT16 queueTail; /* 消息尾节点位置(数组下标)*/ - UINT16 readWriteableCnt[OS_READWRITE_LEN]; /* 数组下标0的元素表示队列中可读消息数, - 数组下标1的元素表示队列中可写消息数 */ - LOS_DL_LIST readWriteList[OS_READWRITE_LEN]; /* 读取或写入消息的任务等待链表, - 下标0:读取链表,下标1:写入链表 */ - LOS_DL_LIST memList; /* 内存块链表 */ -} LosQueueCB; -``` - -每个队列控制块中都含有队列状态,表示该队列的使用情况: - -- OS\_QUEUE\_UNUSED:队列未被使用。 -- OS\_QUEUE\_INUSED:队列被使用中。 - -### 队列运作原理 - -- 创建队列时,创建队列成功会返回队列ID。 -- 在队列控制块中维护着一个消息头节点位置Head和一个消息尾节点位置Tail,用于表示当前队列中消息的存储情况。Head表示队列中被占用的消息节点的起始位置。Tail表示被占用的消息节点的结束位置,也是空闲消息节点的起始位置。队列刚创建时,Head和Tail均指向队列起始位置。 -- 写队列时,根据readWriteableCnt\[1\]判断队列是否可以写入,不能对已满(readWriteableCnt\[1\]为0)队列进行写操作。写队列支持两种写入方式:向队列尾节点写入,也可以向队列头节点写入。尾节点写入时,根据Tail找到起始空闲消息节点作为数据写入对象,如果Tail已经指向队列尾部则采用回卷方式。头节点写入时,将Head的前一个节点作为数据写入对象,如果Head指向队列起始位置则采用回卷方式。 -- 读队列时,根据readWriteableCnt\[0\]判断队列是否有消息需要读取,对全部空闲(readWriteableCnt\[0\]为0)队列进行读操作会引起任务挂起。如果队列可以读取消息,则根据Head找到最先写入队列的消息节点进行读取。如果Head已经指向队列尾部则采用回卷方式。 -- 删除队列时,根据队列ID找到对应队列,把队列状态置为未使用,把队列控制块置为初始状态,并释放队列所占内存。 - -图 1 队列读写数据操作示意图 - -![](/images/device-dev/kernel/figure/zh-cn_image_0000001132935054.png) - -上图对读写队列做了示意,图中只画了尾节点写入方式,没有画头节点写入,但是两者是类似的。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/03.\346\266\210\346\201\257\351\230\237\345\210\227/02.\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/03.\346\266\210\346\201\257\351\230\237\345\210\227/02.\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index 938832b15e65ae947f197b043be20f6ca674987f..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/03.\346\266\210\346\201\257\351\230\237\345\210\227/02.\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,211 +0,0 @@ ---- -title: 开发指导 -permalink: /pages/0105010102040302 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 开发指导 - -- [接口说明](#section158501652121514) -- [开发流程](#section783435801510) -- [编程实例](#section460018317164) - - [实例描述](#section2148236125814) - - [示例代码](#section121451047155716) - - [结果验证](#section2742182082117) - - -## 接口说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名

-

描述

-

创建/删除消息队列

-

LOS_QueueCreate

-

创建一个消息队列,由系统动态申请队列空间。

-

LOS_QueueDelete

-

根据队列ID删除一个指定队列。

-

读/写队列(不带拷贝)

-

LOS_QueueRead

-

读取指定队列头节点中的数据(队列节点中的数据实际上是一个地址)。

-

LOS_QueueWrite

-

向指定队列尾节点中写入入参bufferAddr的值(即buffer的地址)。

-

LOS_QueueWriteHead

-

向指定队列头节点中写入入参bufferAddr的值(即buffer的地址)。

-

读/写队列(带拷贝)

-

LOS_QueueReadCopy

-

读取指定队列头节点中的数据。

-

LOS_QueueWriteCopy

-

向指定队列尾节点中写入入参bufferAddr中保存的数据。

-

LOS_QueueWriteHeadCopy

-

向指定队列头节点中写入入参bufferAddr中保存的数据。

-

获取队列信息

-

LOS_QueueInfoGet

-

获取指定队列的信息,包括队列ID、队列长度、消息节点大小、头节点、尾节点、可读节点数量、可写节点数量、等待读操作的任务、等待写操作的任务。

-
- -## 开发流程 - -1. 用LOS\_QueueCreate创建队列。创建成功后,可以得到队列ID。 -2. 通过LOS\_QueueWrite或者LOS\_QueueWriteCopy写队列。 -3. 通过LOS\_QueueRead或者LOS\_QueueReadCopy读队列。 -4. 通过LOS\_QueueInfoGet获取队列信息。 -5. 通过LOS\_QueueDelete删除队列。 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->- 系统支持的最大队列数是指:整个系统的队列资源总个数,而非用户能使用的个数。例如:系统软件定时器多占用一个队列资源,那么用户能使用的队列资源就会减少一个。 ->- 创建队列时传入的队列名和flags暂时未使用,作为以后的预留参数。 ->- 队列接口函数中的入参timeOut是相对时间。 ->- LOS\_QueueReadCopy和LOS\_QueueWriteCopy及LOS\_QueueWriteHeadCopy是一组接口,LOS\_QueueRead和LOS\_QueueWrite及LOS\_QueueWriteHead是一组接口,每组接口需要配套使用。 ->- 鉴于LOS\_QueueWrite和LOS\_QueueWriteHead和LOS\_QueueRead这组接口实际操作的是数据地址,用户必须保证调用LOS\_QueueRead获取到的指针所指向的内存区域在读队列期间没有被异常修改或释放,否则可能导致不可预知的后果。 ->- 鉴于LOS\_QueueWrite和LOS\_QueueWriteHead和LOS\_QueueRead这组接口实际操作的是数据地址,也就意味着实际写和读的消息长度仅仅是一个指针数据,因此用户使用这组接口之前,需确保创建队列时的消息节点大小,为一个指针的长度,避免不必要的浪费和读取失败。 - -## 编程实例 - -### 实例描述 - -创建一个队列,两个任务。任务1调用写队列接口发送消息,任务2通过读队列接口接收消息。 - -1. 通过LOS\_TaskCreate创建任务1和任务2。 -2. 通过LOS\_QueueCreate创建一个消息队列。 -3. 在任务1 SendEntry中发送消息。 -4. 在任务2 RecvEntry中接收消息。 -5. 通过LOS\_QueueDelete删除队列。 - -### 示例代码 - -示例代码如下: - -``` -#include "los_task.h" -#include "los_queue.h" -static UINT32 g_queue; -#define BUFFER_LEN 50 - -VOID SendEntry(VOID) -{ - UINT32 ret = 0; - CHAR abuf[] = "test message"; - UINT32 len = sizeof(abuf); - - ret = LOS_QueueWriteCopy(g_queue, abuf, len, 0); - if(ret != LOS_OK) { - printf("Failed to send the message. Error: %x\n", ret); - } -} - -VOID RecvEntry(VOID) -{ - UINT32 ret = 0; - CHAR readBuf[BUFFER_LEN] = {0}; - UINT32 readLen = BUFFER_LEN; - - ret = LOS_QueueReadCopy(g_queue, readBuf, &readLen, 0); - if(ret != LOS_OK) { - printf("Failed to receive the message. Error: %x\n", ret); - } - - printf("Message received: %s\n", readBuf); - - ret = LOS_QueueDelete(g_queue); - if(ret != LOS_OK) { - printf("Failed to delete the queue. Error: %x\n", ret); - } - - printf("Queue deleted.\n"); -} - -UINT32 ExampleQueue(VOID) -{ - printf("Start queue example.\n"); - UINT32 ret = 0; - UINT32 task1, task2; - TSK_INIT_PARAM_S initParam = {0}; - - initParam.pfnTaskEntry = (TSK_ENTRY_FUNC)SendEntry; - initParam.usTaskPrio = 9; - initParam.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE; - initParam.pcName = "SendQueue"; - - LOS_TaskLock(); - ret = LOS_TaskCreate(&task1, &initParam); - if(ret != LOS_OK) { - printf("Failed to create task1. Error: %x\n", ret); - return ret; - } - - initParam.pcName = "RecvQueue"; - initParam.pfnTaskEntry = (TSK_ENTRY_FUNC)RecvEntry; - initParam.usTaskPrio = 10; - ret = LOS_TaskCreate(&task2, &initParam); - if(ret != LOS_OK) { - printf("Failed to create task2. Error: %x\n", ret); - return ret; - } - - ret = LOS_QueueCreate("queue", 5, &g_queue, 0, 50); - if(ret != LOS_OK) { - printf("Failed to create the queue. Error: %x\n", ret); - } - - printf("Queue created.\n"); - LOS_TaskUnlock(); - return ret; -} -``` - -### 结果验证 - -编译运行得到的结果为: - -``` -Start queue example. -Queue created. -Message received: test message. -Queue deleted. -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/04.\344\277\241\345\217\267\351\207\217/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/04.\344\277\241\345\217\267\351\207\217/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" deleted file mode 100644 index 0c8e66b499db116cbd1e3827a8fcce446da6aee5..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/04.\344\277\241\345\217\267\351\207\217/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" +++ /dev/null @@ -1,66 +0,0 @@ ---- -title: 基本概念 -permalink: /pages/0105010102040401 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 基本概念 - -- [运行机制](#section1794010261861) - - [信号量控制块](#section11372149164815) - - [信号量运作原理](#section139726510491) - - -信号量(Semaphore)是一种实现任务间通信的机制,可以实现任务间同步或共享资源的互斥访问。 - -一个信号量的数据结构中,通常有一个计数值,用于对有效资源数的计数,表示剩下的可被使用的共享资源数,其值的含义分两种情况: - -- 0,表示该信号量当前不可获取,因此可能存在正在等待该信号量的任务。 -- 正值,表示该信号量当前可被获取。 - -以同步为目的的信号量和以互斥为目的的信号量在使用上有如下不同: - -- 用作互斥时,初始信号量计数值不为0,表示可用的共享资源个数。在需要使用共享资源前,先获取信号量,然后使用一个共享资源,使用完毕后释放信号量。这样在共享资源被取完,即信号量计数减至0时,其他需要获取信号量的任务将被阻塞,从而保证了共享资源的互斥访问。另外,当共享资源数为1时,建议使用二值信号量,一种类似于互斥锁的机制。 -- 用作同步时,初始信号量计数值为0。任务1获取信号量而阻塞,直到任务2或者某中断释放信号量,任务1才得以进入Ready或Running态,从而达到了任务间的同步。 - -## 运行机制 - -### 信号量控制块 - -``` -/** - * 信号量控制块数据结构 - */ -typedef struct { - UINT16 semStat; /* 信号量状态 */ - UINT16 semType; /* 信号量类型 */ - UINT16 semCount; /* 信号量计数 */ - UINT16 semId; /* 信号量索引号 */ - LOS_DL_LIST semList; /* 挂接阻塞于该信号量的任务 */ -} LosSemCB; -``` - -### 信号量运作原理 - -信号量初始化,为配置的N个信号量申请内存(N值可以由用户自行配置,通过LOSCFG\_BASE\_IPC\_SEM\_LIMIT宏实现),并把所有信号量初始化成未使用,加入到未使用链表中供系统使用。 - -信号量创建,从未使用的信号量链表中获取一个信号量,并设定初值。 - -信号量申请,若其计数器值大于0,则直接减1返回成功。否则任务阻塞,等待其它任务释放该信号量,等待的超时时间可设定。当任务被一个信号量阻塞时,将该任务挂到信号量等待任务队列的队尾。 - -信号量释放,若没有任务等待该信号量,则直接将计数器加1返回。否则唤醒该信号量等待任务队列上的第一个任务。 - -信号量删除,将正在使用的信号量置为未使用信号量,并挂回到未使用链表。 - -信号量允许多个任务在同一时刻访问共享资源,但会限制同一时刻访问此资源的最大任务数目。当访问资源的任务数达到该资源允许的最大数量时,会阻塞其他试图获取该资源的任务,直到有任务释放该信号量。 - -**图 1** 信号量运作示意图 -![](/images/device-dev/kernel/figure/信号量运作示意图.png "信号量运作示意图") - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/04.\344\277\241\345\217\267\351\207\217/02.\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/04.\344\277\241\345\217\267\351\207\217/02.\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index a53a73070a2a0120aed52979ad9d57c69ae15a71..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/04.\344\277\241\345\217\267\351\207\217/02.\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,219 +0,0 @@ ---- -title: 开发指导 -permalink: /pages/0105010102040402 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 开发指导 - -- [接口说明](#section158501652121514) -- [开发流程](#section783435801510) -- [编程实例](#section460018317164) - - [实例描述](#section22061718111412) - - [示例代码](#section1775922321416) - - [结果验证](#section160404016213) - - -## 接口说明 - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名

-

描述

-

创建/删除信号量

-

LOS_SemCreate

-

创建信号量,返回信号量ID

-

LOS_BinarySemCreate

-

创建二值信号量,其计数值最大为1

-

LOS_SemDelete

-

删除指定的信号量

-

申请/释放信号量

-

LOS_SemPend

-

申请指定的信号量,并设置超时时间

-

LOS_SemPost

-

释放指定的信号量

-
- -## 开发流程 - -1. 创建信号量LOS\_SemCreate,若要创建二值信号量则调用LOS\_BinarySemCreate。 -2. 申请信号量LOS\_SemPend。 -3. 释放信号量LOS\_SemPost。 -4. 删除信号量LOS\_SemDelete。 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->由于中断不能被阻塞,因此不能在中断中使用阻塞模式申请信号量。 - -## 编程实例 - -### 实例描述 - -本实例实现如下功能: - -1. 测试任务ExampleSem创建一个信号量,锁任务调度,创建两个任务ExampleSemTask1、ExampleSemTask2, ExampleSemTask2优先级高于ExampleSemTask1,两个任务中申请同一信号量,解锁任务调度后两任务阻塞,测试任务ExampleSem释放信号量。 -2. ExampleSemTask2得到信号量,被调度,然后任务休眠20Tick,ExampleSemTask2延迟,ExampleSemTask1被唤醒。 -3. ExampleSemTask1定时阻塞模式申请信号量,等待时间为10Tick,因信号量仍被ExampleSemTask2持有,ExampleSemTask1挂起,10Tick后仍未得到信号量,ExampleSemTask1被唤醒,试图以永久阻塞模式申请信号量,ExampleSemTask1挂起。 -4. 20Tick后ExampleSemTask2唤醒, 释放信号量后,ExampleSemTask1得到信号量被调度运行,最后释放信号量。 -5. ExampleSemTask1执行完,400Tick后任务ExampleSem被唤醒,执行删除信号量。 - -### 示例代码 - -示例代码如下: - -``` -#include "los_sem.h" -#include "securec.h" - -/* 任务ID */ -static UINT32 g_testTaskId01; -static UINT32 g_testTaskId02; - -/* 测试任务优先级 */ -#define TASK_PRIO_TEST 5 - -/* 信号量结构体id */ -static UINT32 g_semId; - -VOID ExampleSemTask1(VOID) -{ - UINT32 ret; - - printf("ExampleSemTask1 try get sem g_semId, timeout 10 ticks.\n"); - - /* 定时阻塞模式申请信号量,定时时间为10ticks */ - ret = LOS_SemPend(g_semId, 10); - - /* 申请到信号量 */ - if (ret == LOS_OK) { - LOS_SemPost(g_semId); - return; - } - /* 定时时间到,未申请到信号量 */ - if (ret == LOS_ERRNO_SEM_TIMEOUT) { - printf("ExampleSemTask1 timeout and try get sem g_semId wait forever.\n"); - - /*永久阻塞模式申请信号量*/ - ret = LOS_SemPend(g_semId, LOS_WAIT_FOREVER); - printf("ExampleSemTask1 wait_forever and get sem g_semId.\n"); - if (ret == LOS_OK) { - LOS_SemPost(g_semId); - return; - } - } -} - -VOID ExampleSemTask2(VOID) -{ - UINT32 ret; - printf("ExampleSemTask2 try get sem g_semId wait forever.\n"); - - /* 永久阻塞模式申请信号量 */ - ret = LOS_SemPend(g_semId, LOS_WAIT_FOREVER); - - if (ret == LOS_OK) { - printf("ExampleSemTask2 get sem g_semId and then delay 20 ticks.\n"); - } - - /* 任务休眠20 ticks */ - LOS_TaskDelay(20); - - printf("ExampleSemTask2 post sem g_semId.\n"); - /* 释放信号量 */ - LOS_SemPost(g_semId); - return; -} - -UINT32 ExampleSem(VOID) -{ - UINT32 ret; - TSK_INIT_PARAM_S task1; - TSK_INIT_PARAM_S task2; - - /* 创建信号量 */ - LOS_SemCreate(0, &g_semId); - - /* 锁任务调度 */ - LOS_TaskLock(); - - /* 创建任务1 */ - (VOID)memset_s(&task1, sizeof(TSK_INIT_PARAM_S), 0, sizeof(TSK_INIT_PARAM_S)); - task1.pfnTaskEntry = (TSK_ENTRY_FUNC)ExampleSemTask1; - task1.pcName = "TestTask1"; - task1.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE; - task1.usTaskPrio = TASK_PRIO_TEST; - ret = LOS_TaskCreate(&g_testTaskId01, &task1); - if (ret != LOS_OK) { - printf("task1 create failed.\n"); - return LOS_NOK; - } - - /* 创建任务2 */ - (VOID)memset_s(&task2, sizeof(TSK_INIT_PARAM_S), 0, sizeof(TSK_INIT_PARAM_S)); - task2.pfnTaskEntry = (TSK_ENTRY_FUNC)ExampleSemTask2; - task2.pcName = "TestTask2"; - task2.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE; - task2.usTaskPrio = (TASK_PRIO_TEST - 1); - ret = LOS_TaskCreate(&g_testTaskId02, &task2); - if (ret != LOS_OK) { - printf("task2 create failed.\n"); - return LOS_NOK; - } - - /* 解锁任务调度 */ - LOS_TaskUnlock(); - - ret = LOS_SemPost(g_semId); - - /* 任务休眠400 ticks */ - LOS_TaskDelay(400); - - /* 删除信号量 */ - LOS_SemDelete(g_semId); - return LOS_OK; -} -``` - -### 结果验证 - -编译运行得到的结果为: - -``` -ExampleSemTask2 try get sem g_semId wait forever. -ExampleSemTask2 get sem g_semId and then delay 20 ticks. -ExampleSemTask1 try get sem g_semId, timeout 10 ticks. - -ExampleSemTask1 timeout and try get sem g_semId wait forever. -ExampleSemTask2 post sem g_semId. -ExampleSemTask1 wait_forever and get sem g_semId. -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/05.\346\227\266\351\227\264\347\256\241\347\220\206/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/05.\346\227\266\351\227\264\347\256\241\347\220\206/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" deleted file mode 100644 index b630ff81499d81a5a8c6b129afa1daf50d12f25a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/05.\346\227\266\351\227\264\347\256\241\347\220\206/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" +++ /dev/null @@ -1,36 +0,0 @@ ---- -title: 基本概念 -permalink: /pages/01050101020501 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 基本概念 - -- [时间单位:](#section97172532397) - -时间管理以系统时钟为基础,给应用程序提供所有和时间有关的服务。 - -系统时钟是由定时器/计数器产生的输出脉冲触发中断产生的,一般定义为整数或长整数。输出脉冲的周期叫做一个“时钟滴答”。系统时钟也称为时标或者Tick。 - -用户以秒、毫秒为单位计时,而操作系统以Tick为单位计时,当用户需要对系统进行操作时,例如任务挂起、延时等,此时需要时间管理模块对Tick和秒/毫秒进行转换。 - -OpenHarmony LiteOS-M内核时间管理模块提供时间转换、统计功能。 - -## 时间单位: - -- Cycle - - 系统最小的计时单位。Cycle的时长由系统主时钟频率决定,系统主时钟频率就是每秒钟的Cycle数。 - -- Tick - - Tick是操作系统的基本时间单位,由用户配置的每秒Tick数决定。 - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/05.\346\227\266\351\227\264\347\256\241\347\220\206/02.\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/05.\346\227\266\351\227\264\347\256\241\347\220\206/02.\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index 1f48637fdbabb614c0744f185559b02fc88bfe80..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/05.\346\227\266\351\227\264\347\256\241\347\220\206/02.\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,170 +0,0 @@ ---- -title: 开发指导 -permalink: /pages/01050101020502 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 开发指导 - -- [接口说明](#section158501652121514) -- [开发流程](#section783435801510) -- [编程实例](#section460018317164) - - [实例描述](#section127752801718) - - [示例代码](#section321653551711) - - [结果验证](#section4366193318167) - - -用户需要了解当前系统运行的时间以及Tick与秒、毫秒之间的转换关系时,需要使用到时间管理模块的接口。 - -## 接口说明 - -OpenHarmony LiteOS-M内核的时间管理提供下面几种功能,接口详细信息可以查看API参考。 - -**表 1** 时间管理接口 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名

-

描述

-

时间转换

-

LOS_MS2Tick

-

毫秒转换成Tick

-

LOS_Tick2MS

-

Tick转化为毫秒

-

OsCpuTick2MS

-

Cycle数目转化为毫秒,使用2个UINT32类型的数值分别表示结果数值的高、低32位。

-

OsCpuTick2US

-

Cycle数目转化为微秒,使用2个UINT32类型的数值分别表示结果数值的高、低32位。

-

时间统计

-

LOS_SysClockGet

-

获取系统时钟

-

LOS_TickCountGet

-

获取自系统启动以来的Tick数

-

LOS_CyclePerTickGet

-

获取每个Tick多少Cycle数

-
- -## 开发流程 - -时间管理的典型开发流程: - -1. 根据实际需求,完成板级配置适配,并配置系统主时钟频率OS\_SYS\_CLOCK(单位Hz)和LOSCFG\_BASE\_CORE\_TICK\_PER\_SECOND。OS\_SYS\_CLOCK的默认值基于硬件平台配置。 -2. 调用时钟转换/统计接口。 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->- 时间管理不是单独的功能模块,依赖于OS\_SYS\_CLOCK和LOSCFG\_BASE\_CORE\_TICK\_PER\_SECOND两个配置选项。 ->- 系统的Tick数在关中断的情况下不进行计数,故系统Tick数不能作为准确时间使用。 ->- 配置选项维护在开发板工程的文件target\_config.h。 - -## 编程实例 - -### 实例描述 - -在下面的例子中,介绍了时间管理的基本方法,包括: - -1. 时间转换:将毫秒数转换为Tick数,或将Tick数转换为毫秒数。 -2. 时间统计:每Tick的Cycle数、自系统启动以来的Tick数和延迟后的Tick数。 - -### 示例代码 - -前提条件: - -- 使用每秒的Tick数LOSCFG\_BASE\_CORE\_TICK\_PER\_SECOND的默认值100。 -- 配好OS\_SYS\_CLOCK系统主时钟频率。 - -时间转换: - -``` -VOID Example_TransformTime(VOID) -{ - UINT32 ms; - UINT32 tick; - - tick = LOS_MS2Tick(10000); // 10000ms转换为tick - dprintf("tick = %d \n", tick); - ms = LOS_Tick2MS(100); // 100tick转换为ms - dprintf("ms = %d \n", ms); -} -``` - -时间统计和时间延迟: - -``` -VOID Example_GetTime(VOID) -{ - UINT32 cyclePerTick; - UINT64 tickCount; - - cyclePerTick = LOS_CyclePerTickGet(); - if(0 != cyclePerTick) { - dprintf("LOS_CyclePerTickGet = %d \n", cyclePerTick); - } - - tickCount = LOS_TickCountGet(); - if(0 != tickCount) { - dprintf("LOS_TickCountGet = %d \n", (UINT32)tickCount); - } - - LOS_TaskDelay(200); - tickCount = LOS_TickCountGet(); - if(0 != tickCount) { - dprintf("LOS_TickCountGet after delay = %d \n", (UINT32)tickCount); - } -} -``` - -### 结果验证 - -编译运行得到的结果为: - -时间转换: - -``` -tick = 1000 -ms = 1000 -``` - -时间统计和时间延迟: - -``` -LOS_CyclePerTickGet = 495000 -LOS_TickCountGet = 1 -LOS_TickCountGet after delay = 201 -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/06.\350\275\257\344\273\266\345\256\232\346\227\266\345\231\250/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/06.\350\275\257\344\273\266\345\256\232\346\227\266\345\231\250/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" deleted file mode 100644 index ffda536a144dd980536a92c4e53fefd8ac8a7e59..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/06.\350\275\257\344\273\266\345\256\232\346\227\266\345\231\250/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" +++ /dev/null @@ -1,67 +0,0 @@ ---- -title: 基本概念 -permalink: /pages/01050101020601 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 基本概念 - -- [运行机制](#section070665816719) - - [定时器状态](#section115453813506) - - [定时器模式](#section137521353175010) - - -软件定时器,是基于系统Tick时钟中断且由软件来模拟的定时器,当经过设定的Tick时钟计数值后会触发用户定义的回调函数。定时精度与系统Tick时钟的周期有关。 - -硬件定时器受硬件的限制,数量上不足以满足用户的实际需求,因此为了满足用户需求,提供更多的定时器,OpenHarmony LiteOS-M内核提供软件定时器功能。软件定时器扩展了定时器的数量,允许创建更多的定时业务。 - -软件定时器功能上支持: - -- 静态裁剪:能通过宏关闭软件定时器功能。 -- 软件定时器创建。 -- 软件定时器启动。 -- 软件定时器停止。 -- 软件定时器删除。 -- 软件定时器剩余Tick数获取。 - -## 运行机制 - -软件定时器是系统资源,在模块初始化的时候已经分配了一块连续的内存,系统支持的最大定时器个数由los\_config.h中的LOSCFG\_BASE\_CORE\_SWTMR\_LIMIT宏配置。 - -软件定时器使用了系统的一个队列和一个任务资源,软件定时器的触发遵循队列规则,先进先出。定时时间短的定时器总是比定时时间长的靠近队列头,满足优先被触发的准则。 - -软件定时器以Tick为基本计时单位,当用户创建并启动一个软件定时器时,OpenHarmony LiteOS-M内核会根据当前系统Tick时间及用户设置的定时间隔确定该定时器的到期Tick时间,并将该定时器控制结构挂入计时全局链表。 - -当Tick中断到来时,在Tick中断处理函数中扫描软件定时器的计时全局链表,看是否有定时器超时,若有则将超时的定时器记录下来。 - -Tick中断处理函数结束后,软件定时器任务(优先级为最高)被唤醒,在该任务中调用之前记录下来的定时器的超时回调函数。 - -### 定时器状态 - -- OS\_SWTMR\_STATUS\_UNUSED(未使用) - -系统在定时器模块初始化的时候将系统中所有定时器资源初始化成该状态。 - -- OS\_SWTMR\_STATUS\_CREATED(创建未启动/停止) - -在未使用状态下调用LOS\_SwtmrCreate接口或者启动后调用LOS\_SwtmrStop接口后,定时器将变成该状态。 - -- OS\_SWTMR\_STATUS\_TICKING(计数) - -在定时器创建后调用LOS\_SwtmrStart接口,定时器将变成该状态,表示定时器运行时的状态。 - -### 定时器模式 - -OpenHarmony LiteOS-M内核的软件定时器提供三类定时器机制: - -- 第一类是单次触发定时器,这类定时器在启动后只会触发一次定时器事件,然后定时器自动删除。 -- 第二类是周期触发定时器,这类定时器会周期性的触发定时器事件,直到用户手动地停止定时器,否则将永远持续执行下去。 -- 第三类也是单次触发定时器,但与第一类不同之处在于这类定时器超时后不会自动删除,需要调用定时器删除接口删除定时器。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/06.\350\275\257\344\273\266\345\256\232\346\227\266\345\231\250/02.\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/06.\350\275\257\344\273\266\345\256\232\346\227\266\345\231\250/02.\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index 151be9317b7f5e14e06d38e55e34c84d14bdccf9..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\237\272\347\241\200\345\206\205\346\240\270/06.\350\275\257\344\273\266\345\256\232\346\227\266\345\231\250/02.\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,232 +0,0 @@ ---- -title: 开发指导 -permalink: /pages/01050101020602 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 开发指导 - -- [接口说明](#section158501652121514) -- [开发流程](#section783435801510) -- [编程实例](#section460018317164) - - [实例描述](#section3741753191918) - - [示例代码](#section20760101182016) - - [结果验证](#section11244112818172) - - -## 接口说明 - -OpenHarmony LiteOS-M内核的软件定时器模块提供下面几种功能,接口详细信息可以查看API参考。 - -**表 1** 软件定时器接口 - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名

-

描述

-

创建、删除定时器

-

LOS_SwtmrCreate

-

创建定时器

-

LOS_SwtmrDelete

-

删除定时器

-

启动、停止定时器

-

LOS_SwtmrStart

-

启动定时器

-

LOS_SwtmrStop

-

停止定时器

-

获得软件定时器剩余Tick数

-

LOS_SwtmrTimeGet

-

获得软件定时器剩余Tick数

-
- -## 开发流程 - -软件定时器的典型开发流程: - -1. 配置软件定时器。 - - 确认配置项LOSCFG\_BASE\_CORE\_SWTMR和LOSCFG\_BASE\_IPC\_QUEUE为1打开状态; - - 配置LOSCFG\_BASE\_CORE\_SWTMR\_LIMIT最大支持的软件定时器数; - - 配置OS\_SWTMR\_HANDLE\_QUEUE\_SIZE软件定时器队列最大长度; - -2. 创建定时器LOS\_SwtmrCreate。 - - 创建一个指定计时时长、指定超时处理函数、指定触发模式的软件定时器; - - 返回函数运行结果,成功或失败; - -3. 启动定时器LOS\_SwtmrStart。 -4. 获得软件定时器剩余Tick数LOS\_SwtmrTimeGet。 -5. 停止定时器LOS\_SwtmrStop。 -6. 删除定时器LOS\_SwtmrDelete。 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->- 软件定时器的回调函数中不要做过多操作,不要使用可能引起任务挂起或者阻塞的接口或操作。 ->- 软件定时器使用了系统的一个队列和一个任务资源,软件定时器任务的优先级设定为0,且不允许修改 。 ->- 系统可配置的软件定时器资源个数是指:整个系统可使用的软件定时器资源总个数,而并非是用户可使用的软件定时器资源个数。例如:系统软件定时器多占用一个软件定时器资源数,那么用户能使用的软件定时器资源就会减少一个。 ->- 创建单次软件定时器,该定时器超时执行完回调函数后,系统会自动删除该软件定时器,并回收资源。 ->- 创建单次不自删除属性的定时器,用户需要调用定时器删除接口删除定时器,回收定时器资源,避免资源泄露。 - -## 编程实例 - -### 实例描述 - -在下面的例子中,演示如下功能: - -1. 软件定时器创建、启动、删除、暂停、重启操作。 -2. 单次软件定时器,周期软件定时器使用方法。 - -### 示例代码 - -前提条件: - -- 在los\_config.h中,将LOSCFG\_BASE\_CORE\_SWTMR配置项打开。 -- 在los\_config.h中,将LOSCFG\_BASE\_CORE\_SWTMR\_ALIGN配置项关闭,示例代码中演示代码不涉及定时器对齐。 -- 配置好LOSCFG\_BASE\_CORE\_SWTMR\_LIMIT最大支持的软件定时器数。 -- 配置好OS\_SWTMR\_HANDLE\_QUEUE\_SIZE软件定时器队列最大长度。 - -代码实现如下: - -``` -#include "los_swtmr.h" - -/* Timer count */ -UINT32 g_timerCount1 = 0; -UINT32 g_timerCount2 = 0; - -/* 任务ID */ -UINT32 g_testTaskId01; - -void Timer1_Callback(UINT32 arg) // 回调函数1 -{ - UINT32 tick_last1; - g_timerCount1++; - tick_last1 = (UINT32)LOS_TickCountGet(); // 获取当前Tick数 - printf("g_timerCount1=%d, tick_last1=%d\n", g_timerCount1, tick_last1); -} - -void Timer2_Callback(UINT32 arg) // 回调函数2 -{ - UINT32 tick_last2; - tick_last2 = (UINT32)LOS_TickCountGet(); - g_timerCount2++; - printf("g_timerCount2=%d tick_last2=%d\n", g_timerCount2, tick_last2); -} - -void Timer_example(void) -{ - UINT32 ret; - UINT32 id1; // timer id1 - UINT32 id2; // timer id2 - UINT32 tickCount; - - /*创建单次软件定时器,Tick数为1000,启动到1000Tick数时执行回调函数1 */ - LOS_SwtmrCreate(1000, LOS_SWTMR_MODE_ONCE, Timer1_Callback, &id1, 1); - - /*创建周期性软件定时器,每100Tick数执行回调函数2 */ - LOS_SwtmrCreate(100, LOS_SWTMR_MODE_PERIOD, Timer2_Callback, &id2, 1); - printf("Timer 1 created.\n"); - - LOS_SwtmrStart(id1); //启动单次软件定时器 - printf("Timer 1 started.\n"); - - LOS_TaskDelay(200); //延时200Tick数 - LOS_SwtmrTimeGet(id1, &tickCount); // 获得单次软件定时器剩余Tick数 - printf("tickCount=%d\n", tickCount); - - LOS_SwtmrStop(id1); // 停止软件定时器 - printf("Timer 1 stopped.\n"); - - LOS_SwtmrStart(id1); - LOS_TaskDelay(1000); - - LOS_SwtmrStart(id2); // 启动周期性软件定时器 - printf("Timer 2 started.\n"); - - LOS_TaskDelay(1000); - LOS_SwtmrStop(id2); - ret = LOS_SwtmrDelete(id2); // 删除软件定时器 - if (ret == LOS_OK) { - printf("Timer 2 deleted.\n"); - } -} - -UINT32 Example_TaskEntry(VOID) -{ - UINT32 ret; - TSK_INIT_PARAM_S task1; - - /* 锁任务调度 */ - LOS_TaskLock(); - - /* 创建任务1 */ - (VOID)memset(&task1, 0, sizeof(TSK_INIT_PARAM_S)); - task1.pfnTaskEntry = (TSK_ENTRY_FUNC)Timer_example; - task1.pcName = "TimerTsk"; - task1.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE; - task1.usTaskPrio = 5; - ret = LOS_TaskCreate(&g_testTaskId01, &task1); - if (ret != LOS_OK) { - printf("Failed to create the timer task.\n"); - return LOS_NOK; - } - - /* 解锁任务调度 */ - LOS_TaskUnlock(); - - return LOS_OK; -} -``` - -### 结果验证 - -编译烧录运行,输出结果如下: - -``` -Timer 1 created. -Timer 1 started. -tickCount=798 -Timer 1 stopped. -g_timerCount1=1, tick_last1=1208 -Timer 2 started. -g_timerCount2=1 tick_last2=1313 -g_timerCount2=2 tick_last2=1413 -g_timerCount2=3 tick_last2=1513 -g_timerCount2=4 tick_last2=1613 -g_timerCount2=5 tick_last2=1713 -g_timerCount2=6 tick_last2=1813 -g_timerCount2=7 tick_last2=1913 -g_timerCount2=8 tick_last2=2013 -g_timerCount2=9 tick_last2=2113 -g_timerCount2=10 tick_last2=2213 -Timer 2 deleted. -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/03.\346\211\251\345\261\225\347\273\204\344\273\266/01.C++\346\224\257\346\214\201.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/03.\346\211\251\345\261\225\347\273\204\344\273\266/01.C++\346\224\257\346\214\201.md" deleted file mode 100644 index 3f9c0c86b0c5042f64573eb4d10837e085ecb13e..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/03.\346\211\251\345\261\225\347\273\204\344\273\266/01.C++\346\224\257\346\214\201.md" +++ /dev/null @@ -1,98 +0,0 @@ ---- -title: C++支持 -permalink: /pages/010501010301 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# C++支持 - -- [基本概念](#section11374125415814) -- [运行机制](#section189351319134418) -- [开发指导](#section166302407911) - - [接口说明](#section1881825119919) - - [开发流程](#section76371145108) - - [编程实例](#section994427141111) - - -## 基本概念 - -C++作为目前使用最广泛的编程语言之一,支持类、封装、重载等特性,是在C语言基础上开发的一种面向对象的编程语言。 - -## 运行机制 - -C++代码的识别主要由编译器支持,系统主要对全局对象进行构造函数调用,进行初始化操作。 - -## 开发指导 - -### 接口说明 - -**表 1** C++支持接口 - - - - - - - - - - - - -

功能分类

-

接口名

-

描述

-

使用C++特性的前置条件

-

LOS_CppSystemInit

-

C++构造函数初始化

-
- -### 开发流程 - -使用C++特性之前,需要调用函数LOS\_CppSystemInit,实现C++构造函数初始化,其中被初始化的构造函数存在init\_array这个段中,段区间通过变量\_\_init\_array\_start\_\_、\_\_init\_array\_end\_\_传递。 - -**表 2** 参数说明 - - - - - - - - - - - - - -

参数

-

参数说明

-

__init_array_start__

-

init_array段起始位置

-

__init_array_end__

-

init_array段结束位置

-
- ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->调用该函数时,一定要在c++业务前。另外部分与系统资源强相关的类或接口,如std::thread,std::mutex等,在三方编译器使用的c库非musl c时,存在兼容性问题,不建议使用。 - -### 编程实例 - -``` -void app_init(void) -{ -...... -/* 启动阶段C++初始化 */ -LOS_CppSystemInit((UINTPTR)&__init_array_start__, (UINTPTR)&__init_array_end__); -/* C++业务 */ -...... -} -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/03.\346\211\251\345\261\225\347\273\204\344\273\266/02.CPU\345\215\240\347\224\250\347\216\207/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/03.\346\211\251\345\261\225\347\273\204\344\273\266/02.CPU\345\215\240\347\224\250\347\216\207/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" deleted file mode 100644 index 83b97293fd6293de31778fb7ae9c258c3a350409..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/03.\346\211\251\345\261\225\347\273\204\344\273\266/02.CPU\345\215\240\347\224\250\347\216\207/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" +++ /dev/null @@ -1,44 +0,0 @@ ---- -title: 基本概念 -permalink: /pages/01050101030201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:21 ---- -# 基本概念 - -- [运行机制](#section96644177124) - -CPU(中央处理器,Central Processing Unit)占用率分为系统CPU占用率和任务CPU占用率。 - -系统CPU占用率(CPU Percent)是指周期时间内系统的CPU占用率,用于表示系统一段时间内的闲忙程度,也表示CPU的负载情况。系统CPU占用率的有效表示范围为0~100,其精度(可通过配置调整)为百分比。100表示系统满负荷运转。 - -任务CPU占用率指单个任务的CPU占用率,用于表示单个任务在一段时间内的闲忙程度。任务CPU占用率的有效表示范围为0~100,其精度(可通过配置调整)为百分比。100表示在一段时间内系统一直在运行该任务。 - -用户通过系统级的CPU占用率,判断当前系统负载是否超出设计规格。 - -通过系统中各个任务的CPU占用情况,判断各个任务的CPU占用率是否符合设计的预期。 - -## 运行机制 - -OpenHarmony LiteOS-M的CPUP(CPU Percent,系统CPU占用率)采用任务级记录的方式,在任务切换时,记录任务启动时间,任务切出或者退出时间,每次当任务退出时,系统会累加整个任务的占用时间。 - -可以在target\_config.h的中对该功能进行选配。 - -OpenHarmony LiteOS-M提供以下两种CPU占用率的信息查询: - -- 系统CPU占用率。 -- 任务CPU占用率。 - -**CPU占用率的计算方法:** - -系统CPU占用率=系统中除idle任务外其他任务运行总时间/系统运行总时间 - -任务CPU占用率=任务运行总时间/系统运行总时间 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/03.\346\211\251\345\261\225\347\273\204\344\273\266/02.CPU\345\215\240\347\224\250\347\216\207/02.\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/03.\346\211\251\345\261\225\347\273\204\344\273\266/02.CPU\345\215\240\347\224\250\347\216\207/02.\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index f592b1c5436dbdb6566cfa34e7f76d357d055f52..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/03.\346\211\251\345\261\225\347\273\204\344\273\266/02.CPU\345\215\240\347\224\250\347\216\207/02.\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,176 +0,0 @@ ---- -title: 开发指导 -permalink: /pages/01050101030202 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# 开发指导 - -- [接口说明](#section158501652121514) -- [开发流程](#section783435801510) -- [编程实例](#section460018317164) - - [实例描述](#section51413507517) - - [示例代码](#section17617965523) - - [结果验证](#section1968771515188) - - -## 接口说明 - -**表 1** 功能列表 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名

-

描述

-

获取系统CPU占用率

-

LOS_SysCpuUsage

-

获取当前系统CPU占用率

-

LOS_HistorySysCpuUsage

-

获取系统历史CPU占用率

-

获取任务CPU占用率

-

LOS_TaskCpuUsage

-

获取指定任务CPU占用率

-

LOS_HistoryTaskCpuUsage

-

获取指定任务历史CPU占用率

-

LOS_AllCpuUsage

-

获取所有任务CPU占用率

-

输出任务CPU占用率

-

LOS_CpupUsageMonitor

-

输出任务历史CPU占用率

-
- -## 开发流程 - -CPU占用率的典型开发流程: - -1. 调用获取系统CPU使用率函数LOS\_SysCpuUsage。 -2. 调用获取系统历史CPU使用率函数LOS\_HistorySysCpuUsage。 -3. 调用获取指定任务CPU使用率函数LOS\_TaskCpuUsage。 - - 若任务已创建,则关中断,正常获取,恢复中断; - - 若任务未创建,则返回错误码; - -4. 调用获取指定任务历史CPU使用率函数LOS\_HistoryTaskCpuUsage。 - - 若任务已创建,则关中断,根据不同模式正常获取,恢复中断; - - 若任务未创建,则返回错误码; - -5. 调用获取所有任务CPU使用率函数LOS\_AllCpuUsage。 - - 若CPUP已初始化,则关中断,根据不同模式正常获取,恢复中断; - - 若CPUP未初始化或有非法入参,则返回错误码; - - -## 编程实例 - -### 实例描述 - -本实例实现如下功能: - -1. 创建一个用于CPUP测试的任务。 -2. 获取当前系统CPUP。 -3. 以不同模式获取历史系统CPUP。 -4. 获取创建的测试任务的CPUP。 -5. 以不同模式获取创建的测试任务的CPUP - -### 示例代码 - -前提条件: - -在target\_config.h中将LOSCFG\_BASE\_CORE\_CPUP配置项打开。 - -代码实现如下: - -``` -#include "los_task.h" -#include "los_cpup.h" -#define MODE 4 -UINT32 g_cpuTestTaskID; -VOID ExampleCpup(VOID) -{ - printf("entry cpup test example\n"); - while(1) { - usleep(100); - } -} -UINT32 ItCpupTest(VOID) -{ - UINT32 ret; - UINT32 cpupUse; - TSK_INIT_PARAM_S cpupTestTask = { 0 }; - memset(&cpupTestTask, 0, sizeof(TSK_INIT_PARAM_S)); - cpupTestTask.pfnTaskEntry = (TSK_ENTRY_FUNC)ExampleCpup; - cpupTestTask.pcName = "TestCpupTsk"; - cpupTestTask.uwStackSize = 0x800; - cpupTestTask.usTaskPrio = 5; - ret = LOS_TaskCreate(&g_cpuTestTaskID, &cpupTestTask); - if(ret != LOS_OK) { - printf("cpupTestTask create failed .\n"); - return LOS_NOK; - } - - usleep(100); - - /* 获取当前系统cpu占用率 */ - cpupUse = LOS_SysCpuUsage(); - printf("the current system cpu usage is: %u.%u\n", - cpupUse / LOS_CPUP_PRECISION_MULT, cpupUse % LOS_CPUP_PRECISION_MULT); - - cpupUse = LOS_HistorySysCpuUsage(CPU_LESS_THAN_1S); - /* 获取指定任务的cpu占用率,该测试例程中指定的任务为以上创建的cpup测试任务 */ - printf("the history system cpu usage in all time:%u.%u\n", - cpupUse / LOS_CPUP_PRECISION_MULT, cpupUse % LOS_CPUP_PRECISION_MULT); - cpupUse = LOS_TaskCpuUsage(g_cpuTestTaskID); - /* 获取指定历史任务在系统启动到现在的cpu占用率,该测试例程中指定的任务为以上创建的cpup测试任务 */ - printf("cpu usage of the cpupTestTask:\n TaskID: %d\n usage: %u.%u\n", - g_cpuTestTaskID, cpupUse / LOS_CPUP_PRECISION_MULT, cpupUse % LOS_CPUP_PRECISION_MULT); - cpupUse = LOS_HistoryTaskCpuUsage(g_cpuTestTaskID, CPU_LESS_THAN_1S); - printf("cpu usage of the cpupTestTask in all time:\n TaskID: %d\n usage: %u.%u\n", - g_cpuTestTaskID, cpupUse / LOS_CPUP_PRECISION_MULT, cpupUse % LOS_CPUP_PRECISION_MULT); - return LOS_OK; -} -``` - -### 结果验证 - -编译运行得到的结果为: - -``` -entry cpup test example -the current system cpu usage is : 1.5 - the history system cpu usage in all time: 3.0 - cpu usage of the cpupTestTask: TaskID:10 usage: 0.0 - cpu usage of the cpupTestTask in all time: TaskID:10 usage: 0.0 -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/03.\346\211\251\345\261\225\347\273\204\344\273\266/03.\346\226\207\344\273\266\347\263\273\347\273\237/01.FAT.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/03.\346\211\251\345\261\225\347\273\204\344\273\266/03.\346\226\207\344\273\266\347\263\273\347\273\237/01.FAT.md" deleted file mode 100644 index 19123d0e9d0e2a9326017cfb16252b0bf17c7f95..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/03.\346\211\251\345\261\225\347\273\204\344\273\266/03.\346\226\207\344\273\266\347\263\273\347\273\237/01.FAT.md" +++ /dev/null @@ -1,190 +0,0 @@ ---- -title: FAT -permalink: /pages/01050101030301 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# FAT - -- [基本概念](#section1772629121418) -- [开发指导](#section1149072811148) - - [驱动适配](#section19174939191414) - - [开发流程](#section131211626151513) - -- [编程实例](#section1133718619459) - - [实例描述](#section45337345313) - - [示例代码](#section119813171539) - - [结果验证](#section7987101232311) - - -## 基本概念 - -FAT文件系统是File Allocation Table(文件配置表)的简称,主要包括DBR区、FAT区、DATA区三个区域。其中,FAT区各个表项记录存储设备中对应簇的信息,包括簇是否被使用、文件下一个簇的编号、是否文件结尾等。FAT文件系统有FAT12、FAT16、FAT32等多种格式,其中,12、16、32表示对应格式中FAT表项的字节数。FAT文件系统支持多种介质,特别在可移动存储介质(U盘、SD卡、移动硬盘等)上广泛使用,使嵌入式设备和Windows、Linux等桌面系统保持很好的兼容性,方便用户管理操作文件。 - -OpenHarmony内核支持FAT12、FAT16与FAT32三种格式的FAT文件系统,具有代码量小、资源占用小、可裁切、支持多种物理介质等特性,并且与Windows、Linux等系统保持兼容,支持多设备、多分区识别等功能。OpenHarmony内核支持硬盘多分区,可以在主分区以及逻辑分区上创建FAT文件系统。 - -## 开发指导 - -### 驱动适配 - -FAT文件系统的使用需要底层MMC相关驱动的支持。在一个带MMC存储设备的板子上运行FATFS,需要: - -1、适配板端EMMC驱动,实现disk\_status、disk\_initialize、disk\_read、disk\_write、disk\_ioctl接口; - -2、新增fs\_config.h文件,配置FS\_MAX\_SS(存储设备最大sector大小)、FF\_VOLUME\_STRS(分区名)等信息,例如: - -``` -#define FF_VOLUME_STRS "system", "inner", "update", "user" -#define FS_MAX_SS 512 -#define FAT_MAX_OPEN_FILES 50 -``` - -### 开发流程 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->- FATFS文件与目录操作: -> - 单个文件大小不超过4G。 -> - 支持同时打开的文件数最大为FAT\_MAX\_OPEN\_FILES,文件夹数最大为FAT\_MAX\_OPEN\_DIRS。 -> - 暂不支持根目录管理,文件/目录名均以分区名开头,例如“user/testfile”就是在“user”分区下名为“testfile”的文件或目录。 -> - 若需要同时多次打开同一文件,必须全部使用只读方式(O\_RDONLY)。以可写方式(O\_RDWR、O\_WRONLY等)只能打开一次。 -> - 读写指针未分离,例如以O\_APPEND(追加写)方式打开文件后,读指针也在文件尾,从头读文件前需要用户手动置位。 -> - 暂不支持文件与目录的权限管理。 -> - stat及fstat接口暂不支持查询修改时间、创建时间和最后访问时间。微软FAT协议不支持1980年以前的时间。 ->- FATFS分区挂载与卸载: -> - 支持以只读属性挂载分区。当mount函数的入参为MS\_RDONLY时,所有的带有写入的接口,如write、mkdir、unlink,以及非O\_RDONLY属性的open,将均被拒绝。 -> - mount支持通过MS\_REMOUNT标记修改已挂载分区的权限。 -> - 在umount操作前,需确保所有目录及文件全部关闭。 -> - umount2支持通过MNT\_FORCE参数强制关闭所有文件与文件夹并umount,但可能造成数据丢失,请谨慎使用。 ->- FATFS支持重新划分存储设备分区、格式化分区,对应接口为fatfs\_fdisk与fatfs\_format: -> - 在fatfs\_format操作之前,若需要格式化的分区已挂载,需确保分区中的所有目录及文件全部关闭,并且分区umount。 -> - 在fatfs\_fdisk操作前,需要该设备中的所有分区均已umount。 -> - fatfs\_fdisk与fatfs\_format会造成设备数据丢失,请谨慎使用。 - -## 编程实例 - -### 实例描述 - -本实例实现以下功能: - -1. 创建目录“user/test” -2. 在“user/test”目录下创建文件“file.txt” -3. 在文件起始位置写入“Hello OpenHarmony!” -4. 将文件内容刷入设备中 -5. 设置偏移到文件起始位置 -6. 读取文件内容 -7. 关闭文件 -8. 删除文件 -9. 删除目录 - -### 示例代码 - -前提条件: - -- 系统已将MMC设备分区挂载到user目录 - -代码实现如下: - -``` -#include -#include -#include "sys/stat.h" -#include "fcntl.h" -#include "unistd.h" - -#define LOS_OK 0 -#define LOS_NOK -1 - -int FatfsTest(void) -{ - int ret; - int fd = -1; - ssize_t len; - off_t off; - char dirName[20] = "user/test"; - char fileName[20] = "user/test/file.txt"; - char writeBuf[20] = "Hello OpenHarmony!"; - char readBuf[20] = {0}; - - /* 创建目录“user/test” */ - ret = mkdir(dirName, 0777); - if (ret != LOS_OK) { - printf("mkdir failed.\n"); - return LOS_NOK; - } - - /* 创建可读写文件"user/test/file.txt" */ - fd = open(fileName, O_RDWR | O_CREAT, 0777); - if (fd < 0) { - printf("open file failed.\n"); - return LOS_NOK; - } - - /* 将writeBuf中的内容写入文件 */ - len = write(fd, writeBuf, strlen(writeBuf)); - if (len != strlen(writeBuf)) { - printf("write file failed.\n"); - return LOS_NOK; - } - - /* 将文件内容刷入存储设备中 */ - ret = fsync(fd); - if (ret != LOS_OK) { - printf("fsync failed.\n"); - return LOS_NOK; - } - - /* 将读写指针偏移至文件头 */ - off = lseek(fd, 0, SEEK_SET); - if (off != 0) { - printf("lseek failed.\n"); - return LOS_NOK; - } - - /* 将文件内容读出至readBuf中,读取长度为readBuf大小 */ - len = read(fd, readBuf, sizeof(readBuf)); - if (len != strlen(writeBuf)) { - printf("read file failed.\n"); - return LOS_NOK; - } - printf("%s\n", readBuf); - - /* 关闭文件 */ - ret = close(fd); - if (ret != LOS_OK) { - printf("close failed.\n"); - return LOS_NOK; - } - - /* 删除文件"user/test/file.txt" */ - ret = unlink(fileName); - if (ret != LOS_OK) { - printf("unlink failed.\n"); - return LOS_NOK; - } - - /* 删除目录“user/test” */ - ret = rmdir(dirName); - if (ret != LOS_OK) { - printf("rmdir failed.\n"); - return LOS_NOK; - } - - return LOS_OK; -} -``` - -### 结果验证 - -编译运行得到的结果为: - -``` -Hello OpenHarmony! -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/03.\346\211\251\345\261\225\347\273\204\344\273\266/03.\346\226\207\344\273\266\347\263\273\347\273\237/02.LittleFS/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/03.\346\211\251\345\261\225\347\273\204\344\273\266/03.\346\226\207\344\273\266\347\263\273\347\273\237/02.LittleFS/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" deleted file mode 100644 index 75cb12f5bddacbf166b14025ccdf7261a7a117b4..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/03.\346\211\251\345\261\225\347\273\204\344\273\266/03.\346\226\207\344\273\266\347\263\273\347\273\237/02.LittleFS/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" +++ /dev/null @@ -1,19 +0,0 @@ ---- -title: 基本概念 -permalink: /pages/0105010103030201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# 基本概念 - -LittleFS是一个小型的Flash文件系统,它结合日志结构(log-structured)文件系统和COW(copy-on-write)文件系统的思想,以日志结构存储元数据,以COW结构存储数据。这种特殊的存储方式,使LittleFS具有强大的掉电恢复能力(power-loss resilience\)。分配COW数据块时LittleFS采用了名为统计损耗均衡的动态损耗均衡算法,使Flash设备的寿命得到有效保障。同时LittleFS针对资源紧缺的小型设备进行设计,具有极其有限的ROM和RAM占用,并且所有RAM的使用都通过一个可配置的固定大小缓冲区进行分配,不会随文件系统的扩大占据更多的系统资源。 - -当在一个资源非常紧缺的小型设备上,寻找一个具有掉电恢复能力并支持损耗均衡的Flash文件系统时,LittleFS是一个比较好的选择。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/03.\346\211\251\345\261\225\347\273\204\344\273\266/03.\346\226\207\344\273\266\347\263\273\347\273\237/02.LittleFS/02.\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/03.\346\211\251\345\261\225\347\273\204\344\273\266/03.\346\226\207\344\273\266\347\263\273\347\273\237/02.LittleFS/02.\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index cc19d17bb85b813fcf7d28f06e4991fd96a1f393..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/03.\346\211\251\345\261\225\347\273\204\344\273\266/03.\346\226\207\344\273\266\347\263\273\347\273\237/02.LittleFS/02.\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,108 +0,0 @@ ---- -title: 开发指导 -permalink: /pages/0105010103030202 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# 开发指导 - -- [示例代码](#section1034515054620) - -移植LittleFS到新硬件设备上,需要申明lfs\_config: - -``` -const struct lfs_config cfg = { - // block device operations - .read = user_provided_block_device_read, - .prog = user_provided_block_device_prog, - .erase = user_provided_block_device_erase, - .sync = user_provided_block_device_sync, - - // block device configuration - .read_size = 16, - .prog_size = 16, - .block_size = 4096, - .block_count = 128, - .cache_size = 16, - .lookahead_size = 16, - .block_cycles = 500, -}; -``` - -其中.read,.prog,.erase,.sync分别对应该硬件平台上的底层的读写\\擦除\\同步等接口。 - -read\_size 每次读取的字节数,可以比物理读单元大以改善性能,这个数值决定了读缓存的大小,但值太大会带来更多的内存消耗。 - -prog\_size 每次写入的字节数,可以比物理写单元大以改善性能,这个数值决定了写缓存的大小,必须是read\_size的整数倍,但值太大会带来更多的内存消耗。 - -block\_size 每个擦除块的字节数,可以比物理擦除单元大,但此数值应尽可能小因为每个文件至少会占用一个块。必须是prog\_size的整数倍。 - -block\_count 可以被擦除的块数量,这取决于块设备的容量及擦除块的大小。 - -## 示例代码 - -代码实现如下: - -``` -#include "lfs.h" -#include "stdio.h" - -lfs_t lfs; -lfs_file_t file; - -const struct lfs_config cfg = { - // block device operations - .read = user_provided_block_device_read, - .prog = user_provided_block_device_prog, - .erase = user_provided_block_device_erase, - .sync = user_provided_block_device_sync, - - // block device configuration - .read_size = 16, - .prog_size = 16, - .block_size = 4096, - .block_count = 128, - .cache_size = 16, - .lookahead_size = 16, - .block_cycles = 500, -}; - -int main(void) { - // mount the filesystem - int err = lfs_mount(&lfs, &cfg); - - // reformat if we can't mount the filesystem - // this should only happen on the first boot - if (err) { - lfs_format(&lfs, &cfg); - lfs_mount(&lfs, &cfg); - } - - // read current count - uint32_t boot_count = 0; - lfs_file_open(&lfs, &file, "boot_count", LFS_O_RDWR | LFS_O_CREAT); - lfs_file_read(&lfs, &file, &boot_count, sizeof(boot_count)); - - // update boot count - boot_count += 1; - lfs_file_rewind(&lfs, &file); - lfs_file_write(&lfs, &file, &boot_count, sizeof(boot_count)); - - // remember the storage is not updated until the file is closed successfully - lfs_file_close(&lfs, &file); - - // release any resources we were using - lfs_unmount(&lfs); - - // print the boot count - printf("boot_count: %d\n", boot_count); -} -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/04.\345\206\205\346\240\270\350\260\203\346\265\213/01.\345\206\205\345\255\230\350\260\203\346\265\213/01.\345\206\205\345\255\230\344\277\241\346\201\257\347\273\237\350\256\241.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/04.\345\206\205\346\240\270\350\260\203\346\265\213/01.\345\206\205\345\255\230\350\260\203\346\265\213/01.\345\206\205\345\255\230\344\277\241\346\201\257\347\273\237\350\256\241.md" deleted file mode 100644 index 84ffd48b8e96b62ebf5e2fdab2d77747be414b19..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/04.\345\206\205\346\240\270\350\260\203\346\265\213/01.\345\206\205\345\255\230\350\260\203\346\265\213/01.\345\206\205\345\255\230\344\277\241\346\201\257\347\273\237\350\256\241.md" +++ /dev/null @@ -1,123 +0,0 @@ ---- -title: 内存信息统计 -permalink: /pages/01050101040101 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# 内存信息统计 - -- [基础概念](#section52691565235) -- [功能配置](#section470611682411) -- [开发指导](#section9368374243) - - [开发流程](#section679912407257) - - [编程实例](#section1025453412611) - - [示例代码](#section165277971315) - - [结果验证](#section3460102414271) - - -## 基础概念 - -内存信息包括内存池大小、内存使用量、剩余内存大小、最大空闲内存、内存水线、内存节点数统计、碎片率等。 - -- 内存水线:即内存池的最大使用量,每次申请和释放时,都会更新水线值,实际业务可根据该值,优化内存池大小; - -- 碎片率:衡量内存池的碎片化程度,碎片率高表现为内存池剩余内存很多,但是最大空闲内存块很小,可以用公式(fragment=100-100\*最大空闲内存块大小/剩余内存大小)来度量; - -- 其他参数:通过调用接口(详见[内存管理](/pages/01050101020301)章节接口说明),扫描内存池的节点信息,统计出相关信息。 - -## 功能配置 - -LOSCFG\_MEM\_WATERLINE:开关宏,默认打开;若关闭这个功能,在target\_config.h中将这个宏定义为0。如需获取内存水线,需要打开该配置。 - -## 开发指导 - -### 开发流程 - -关键结构体介绍: - -``` -typedef struct { - UINT32 totalUsedSize; // 内存池的内存使用量 - UINT32 totalFreeSize; // 内存池的剩余内存大小 - UINT32 maxFreeNodeSize; // 内存池的最大空闲内存块大小 - UINT32 usedNodeNum; // 内存池的非空闲内存块个数 - UINT32 freeNodeNum; // 内存池的空闲内存块个数 -#if (LOSCFG_MEM_WATERLINE == 1) // 默认打开,如需关闭,在target_config.h中将该宏设置为0 - UINT32 usageWaterLine; // 内存池的水线值 -#endif -} LOS_MEM_POOL_STATUS; -``` - -- 内存水线获取:调用LOS\_MemInfoGet接口,第1个参数是内存池首地址,第2个参数是LOS\_MEM\_POOL\_STATUS类型的句柄,其中字段usageWaterLine即水线值。 - -- 内存碎片率计算:同样调用LOS\_MemInfoGet接口,可以获取内存池的剩余内存大小和最大空闲内存块大小,然后根据公式(fragment=100-100\*最大空闲内存块大小/剩余内存大小)得出此时的动态内存池碎片率。 - -### 编程实例 - -本实例实现如下功能: - -1.创建一个监控任务,用于获取内存池的信息; - -2.调用LOS\_MemInfoGet接口,获取内存池的基础信息; - -3.利用公式算出使用率及碎片率。 - -### 示例代码 - -代码实现如下: - -``` -#include -#include -#include "los_task.h" -#include "los_memory.h" -#include "los_config.h" - -void MemInfoTaskFunc(void) -{ - LOS_MEM_POOL_STATUS poolStatus = {0}; - - /* pool为要统计信息的内存地址,此处以OS_SYS_MEM_ADDR为例 */ - void *pool = OS_SYS_MEM_ADDR; - LOS_MemInfoGet(pool, &poolStatus); - /* 算出内存池当前的碎片率百分比 */ - unsigned char fragment = 100 - poolStatus.maxFreeNodeSize * 100 / poolStatus.totalFreeSize; - /* 算出内存池当前的使用率百分比 */ - unsigned char usage = LOS_MemTotalUsedGet(pool) * 100 / LOS_MemPoolSizeGet(pool); - printf("usage = %d, fragment = %d, maxFreeSize = %d, totalFreeSize = %d, waterLine = %d\n", usage, fragment, poolStatus.maxFreeNodeSize, - poolStatus.totalFreeSize, poolStatus.usageWaterLine); -} - -int MemTest(void) -{ - unsigned int ret; - unsigned int taskID; - TSK_INIT_PARAM_S taskStatus = {0}; - taskStatus.pfnTaskEntry = (TSK_ENTRY_FUNC)MemInfoTaskFunc; - taskStatus.uwStackSize = 0x1000; - taskStatus.pcName = "memInfo"; - taskStatus.usTaskPrio = 10; - ret = LOS_TaskCreate(&taskID, &taskStatus); - if (ret != LOS_OK) { - printf("task create failed\n"); - return -1; - } - return 0; -} -``` - -### 结果验证 - -编译运行输出的结果如下: - -``` -usage = 22, fragment = 3, maxFreeSize = 49056, totalFreeSize = 50132, waterLine = 1414 -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/04.\345\206\205\346\240\270\350\260\203\346\265\213/01.\345\206\205\345\255\230\350\260\203\346\265\213/02.\345\206\205\345\255\230\346\263\204\346\274\217\346\243\200\346\265\213.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/04.\345\206\205\346\240\270\350\260\203\346\265\213/01.\345\206\205\345\255\230\350\260\203\346\265\213/02.\345\206\205\345\255\230\346\263\204\346\274\217\346\243\200\346\265\213.md" deleted file mode 100644 index 665290fc01e051d4e983664ac7e0f3eb96095575..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/04.\345\206\205\346\240\270\350\260\203\346\265\213/01.\345\206\205\345\255\230\350\260\203\346\265\213/02.\345\206\205\345\255\230\346\263\204\346\274\217\346\243\200\346\265\213.md" +++ /dev/null @@ -1,141 +0,0 @@ ---- -title: 内存泄漏检测 -permalink: /pages/01050101040102 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# 内存泄漏检测 - -- [基础概念](#section1026719436293) -- [功能配置](#section13991354162914) -- [开发指导](#section95828159308) - - [开发流程](#section369844416304) - - [编程实例](#section460801313313) - - [示例代码](#section96539275311) - - [结果验证](#section20527343183119) - - -## 基础概念 - -内存泄漏检测机制作为内核的可选功能,用于辅助定位动态内存泄漏问题。开启该功能,动态内存机制会自动记录申请内存时的函数调用关系(下文简称LR)。如果出现泄漏,就可以利用这些记录的信息,找到内存申请的地方,方便进一步确认。 - -## 功能配置 - -1. LOSCFG\_MEM\_LEAKCHECK:开关宏,默认关闭;若打开这个功能,在target\_config.h中将这个宏定义为1。 -2. LOSCFG\_MEM\_RECORD\_LR\_CNT:记录的LR层数,默认3层;每层LR消耗sizeof\(void \*\)字节数的内存。 -3. LOSCFG\_MEM\_OMIT\_LR\_CNT:忽略的LR层数,默认4层,即从调用LOS\_MemAlloc的函数开始记录,可根据实际情况调整。为啥需要这个配置?有3点原因如下: - - LOS\_MemAlloc接口内部也有函数调用; - - 外部可能对LOS\_MemAlloc接口有封装; - - LOSCFG\_MEM\_RECORD\_LR\_CNT 配置的LR层数有限; - - -正确配置这个宏,将无效的LR层数忽略,就可以记录有效的LR层数,节省内存消耗。 - -## 开发指导 - -### 开发流程 - -该调测功能可以分析关键的代码逻辑中是否存在内存泄漏。开启这个功能,每次申请内存时,会记录LR信息。在需要检测的代码段前后,调用LOS\_MemUsedNodeShow接口,每次都会打印指定内存池已使用的全部节点信息,对比前后两次的节点信息,新增的节点信息就是疑似泄漏的内存节点。通过LR,可以找到具体申请的代码位置,进一步确认是否泄漏。 - -调用LOS\_MemUsedNodeShow接口输出的节点信息格式如下:每1行为一个节点信息;第1列为节点地址,可以根据这个地址,使用GDB等手段查看节点完整信息;第2列为节点的大小,等于节点头大小+数据域大小;第3\~5列为函数调用关系LR地址,可以根据这个值,结合汇编文件,查看该节点具体申请的位置。 - -``` -node size LR[0] LR[1] LR[2] -0x10017320: 0x528 0x9b004eba 0x9b004f60 0x9b005002 -0x10017848: 0xe0 0x9b02c24e 0x9b02c246 0x9b008ef0 -0x10017928: 0x50 0x9b008ed0 0x9b068902 0x9b0687c4 -0x10017978: 0x24 0x9b008ed0 0x9b068924 0x9b0687c4 -0x1001799c: 0x30 0x9b02c24e 0x9b02c246 0x9b008ef0 -0x100179cc: 0x5c 0x9b02c24e 0x9b02c246 0x9b008ef0 -``` - ->![](/images/device-dev/public_sys-resources/icon-caution.gif) **注意:** ->开启内存检测会影响内存申请的性能,且每个内存节点都会记录LR地址,内存开销也加大。 - -### 编程实例 - -本实例实现如下功能:构建内存泄漏代码段。 - -1. 调用LOS\_MemUsedNodeShow接口,输出全部节点信息打印; -2. 申请内存,但没有释放,模拟内存泄漏; -3. 再次调用LOS\_MemUsedNodeShow接口,输出全部节点信息打印; -4. 将两次log进行对比,得出泄漏的节点信息; -5. 通过LR地址,找出泄漏的代码位置; - -### 示例代码 - -代码实现如下: - -``` -#include -#include -#include "los_memory.h" -#include "los_config.h" - -void MemLeakTest(void) -{ - LOS_MemUsedNodeShow(LOSCFG_SYS_HEAP_ADDR); - void *ptr1 = LOS_MemAlloc(LOSCFG_SYS_HEAP_ADDR, 8); - void *ptr2 = LOS_MemAlloc(LOSCFG_SYS_HEAP_ADDR, 8); - LOS_MemUsedNodeShow(LOSCFG_SYS_HEAP_ADDR); -} -``` - -### 结果验证 - -编译运行输出log如下: - -``` -node size LR[0] LR[1] LR[2] -0x20001b04: 0x24 0x08001a10 0x080035ce 0x080028fc -0x20002058: 0x40 0x08002fe8 0x08003626 0x080028fc -0x200022ac: 0x40 0x08000e0c 0x08000e56 0x0800359e -0x20002594: 0x120 0x08000e0c 0x08000e56 0x08000c8a -0x20002aac: 0x56 0x08000e0c 0x08000e56 0x08004220 - -node size LR[0] LR[1] LR[2] -0x20001b04: 0x24 0x08001a10 0x080035ce 0x080028fc -0x20002058: 0x40 0x08002fe8 0x08003626 0x080028fc -0x200022ac: 0x40 0x08000e0c 0x08000e56 0x0800359e -0x20002594: 0x120 0x08000e0c 0x08000e56 0x08000c8a -0x20002aac: 0x56 0x08000e0c 0x08000e56 0x08004220 -0x20003ac4: 0x1d 0x08001458 0x080014e0 0x080041e6 -0x20003ae0: 0x1d 0x080041ee 0x08000cc2 0x00000000 -``` - -对比两次log,差异如下,这些内存节点就是疑似泄漏的内存块: - -``` -0x20003ac4: 0x1d 0x08001458 0x080014e0 0x080041e6 -0x20003ae0: 0x1d 0x080041ee 0x08000cc2 0x00000000 -``` - -部分汇编文件如下: - -``` - MemLeakTest: - 0x80041d4: 0xb510 PUSH {R4, LR} - 0x80041d6: 0x4ca8 LDR.N R4, [PC, #0x2a0] ; g_memStart - 0x80041d8: 0x0020 MOVS R0, R4 - 0x80041da: 0xf7fd 0xf93e BL LOS_MemUsedNodeShow ; 0x800145a - 0x80041de: 0x2108 MOVS R1, #8 - 0x80041e0: 0x0020 MOVS R0, R4 - 0x80041e2: 0xf7fd 0xfbd9 BL LOS_MemAlloc ; 0x8001998 - 0x80041e6: 0x2108 MOVS R1, #8 - 0x80041e8: 0x0020 MOVS R0, R4 - 0x80041ea: 0xf7fd 0xfbd5 BL LOS_MemAlloc ; 0x8001998 - 0x80041ee: 0x0020 MOVS R0, R4 - 0x80041f0: 0xf7fd 0xf933 BL LOS_MemUsedNodeShow ; 0x800145a - 0x80041f4: 0xbd10 POP {R4, PC} - 0x80041f6: 0x0000 MOVS R0, R0 -``` - -其中,通过查找0x080041ee,就可以发现该内存节点是在MemLeakTest接口里申请的且是没有释放的。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/04.\345\206\205\346\240\270\350\260\203\346\265\213/01.\345\206\205\345\255\230\350\260\203\346\265\213/03.\350\270\251\345\206\205\345\255\230\346\243\200\346\265\213.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/04.\345\206\205\346\240\270\350\260\203\346\265\213/01.\345\206\205\345\255\230\350\260\203\346\265\213/03.\350\270\251\345\206\205\345\255\230\346\243\200\346\265\213.md" deleted file mode 100644 index 85d57aade76ff1eeec04554cfa1bfe2bc2d13d82..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/04.\345\206\205\346\240\270\350\260\203\346\265\213/01.\345\206\205\345\255\230\350\260\203\346\265\213/03.\350\270\251\345\206\205\345\255\230\346\243\200\346\265\213.md" +++ /dev/null @@ -1,98 +0,0 @@ ---- -title: 踩内存检测 -permalink: /pages/01050101040103 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# 踩内存检测 - -- [基础概念](#section17368154517335) -- [功能配置](#section4696190123420) -- [开发指导](#section672362973417) - - [开发流程](#section026014863416) - - [编程实例](#section186311302356) - - [示例代码](#section12709533354) - - [结果验证](#section81214126369) - - -## 基础概念 - -踩内存检测机制作为内核的可选功能,用于检测动态内存池的完整性。通过该机制,可以及时发现内存池是否发生了踩内存问题,并给出错误信息,便于及时发现系统问题,提高问题解决效率,降低问题定位成本。 - -## 功能配置 - -LOSCFG\_BASE\_MEM\_NODE\_INTEGRITY\_CHECK:开关宏,默认关闭;若打开这个功能,在target\_config.h中将这个宏定义为1。 - -1. 开启这个功能,每次申请内存,会实时检测内存池的完整性。 -2. 如果不开启该功能,也可以调用LOS\_MemIntegrityCheck接口检测,但是每次申请内存时,不会实时检测内存完整性,而且由于节点头没有魔鬼数字(开启时才有,省内存),检测的准确性也会相应降低,但对于系统的性能没有影响,故根据实际情况开关该功能。 - -由于该功能只会检测出哪个内存节点被破坏了,并给出前节点信息(因为内存分布是连续的,当前节点最有可能被前节点破坏)。如果要进一步确认前节点在哪里申请的,需开启内存泄漏检测功能,通过LR记录,辅助定位。 - ->![](/images/device-dev/public_sys-resources/icon-caution.gif) **注意:** ->开启该功能,节点头多了魔鬼数字字段,会增大节点头大小。由于实时检测完整性,故性能影响较大;若性能敏感的场景,可以不开启该功能,使用LOS\_MemIntegrityCheck接口检测。 - -## 开发指导 - -### 开发流程 - -通过调用LOS\_MemIntegrityCheck接口检测内存池是否发生了踩内存,如果没有踩内存问题,那么接口返回0且没有log输出;如果存在踩内存问题,那么会输出相关log,详见下文编程实例的结果输出。 - -### 编程实例 - -本实例实现如下功能: - -1. 申请两个物理上连续的内存块; -2. 通过memset构造越界访问,踩到下个节点的头4个字节; -3. 调用LOS\_MemIntegrityCheck检测是否发生踩内存。 - -### 示例代码 - -代码实现如下: - -``` -#include -#include -#include "los_memory.h" -#include "los_config.h" - -void MemIntegrityTest(void) -{ - /* 申请两个物理连续的内存块 */ - void *ptr1 = LOS_MemAlloc(LOSCFG_SYS_HEAP_ADDR, 8); - void *ptr2 = LOS_MemAlloc(LOSCFG_SYS_HEAP_ADDR, 8); - /* 第一个节点内存块大小是8字节,那么12字节的清零,会踩到第二个内存节点的节点头,构造踩内存场景 */ - memset(ptr1, 0, 8 + 4); - LOS_MemIntegrityCheck(LOSCFG_SYS_HEAP_ADDR); -} -``` - -### 结果验证 - -编译运行输出log如下: - -``` -[ERR][OsMemMagicCheckPrint], 2028, memory check error! -memory used but magic num wrong, magic num = 0x00000000 /* 提示信息,检测到哪个字段被破坏了,用例构造了将下个节点的头4个字节清零,即魔鬼数字字段 */ - - broken node head: 0x20003af0 0x00000000 0x80000020, prev node head: 0x20002ad4 0xabcddcba 0x80000020 -/* 被破坏节点和其前节点关键字段信息,分别为其前节点地址、节点的魔鬼数字、节点的sizeAndFlag;可以看出被破坏节点的魔鬼数字字段被清零,符合用例场景 */ - - broken node head LR info: /* 节点的LR信息需要开启内存检测功能才有有效输出 */ - LR[0]:0x0800414e - LR[1]:0x08000cc2 - LR[2]:0x00000000 - - pre node head LR info: /* 通过LR信息,可以在汇编文件中查找前节点是哪里申请,然后排查其使用的准确性 */ - LR[0]:0x08004144 - LR[1]:0x08000cc2 - LR[2]:0x00000000 -[ERR]Memory interity check error, cur node: 0x20003b10, pre node: 0x20003af0 /* 被破坏节点和其前节点的地址 */ -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/04.\345\206\205\346\240\270\350\260\203\346\265\213/02.\345\274\202\345\270\270\350\260\203\346\265\213.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/04.\345\206\205\346\240\270\350\260\203\346\265\213/02.\345\274\202\345\270\270\350\260\203\346\265\213.md" deleted file mode 100644 index 4f21994e25ee5bc49967bf466bb43409bc570575..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/04.\345\206\205\346\240\270\350\260\203\346\265\213/02.\345\274\202\345\270\270\350\260\203\346\265\213.md" +++ /dev/null @@ -1,342 +0,0 @@ ---- -title: 异常调测 -permalink: /pages/010501010402 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# 异常调测 - -- [基本概念](#section2741911123412) -- [运行机制](#section16618124317346) -- [接口说明](#section16111931351) -- [使用指导](#section16317163520350) - - [开发流程](#section13457839133618) - - [定位流程](#section197332323815) - - -## 基本概念 - -OpenHarmony LiteOS-M提供异常接管调测手段,帮助开发者定位分析问题。异常接管是操作系统对运行期间发生的异常情况进行处理的一系列动作,例如打印异常发生时异常类型、发生异常时的系统状态、当前函数的调用栈信息、CPU现场信息、任务调用堆栈等信息。 - -## 运行机制 - -栈帧用于保存函数调用过程中的函数参数、变量、返回值等信息。调用函数时,会创建子函数的栈帧,同时将函数入参、局部变量、寄存器入栈。栈帧从高地址向低地址生长。以ARM32 CPU架构为例,每个栈帧中都会保存PC、LR、SP和FP寄存器的历史值。LR链接寄存器(Link Register)指向函数的返回地址,FP帧指针寄存器(Frame Point)指向当前函数的父函数的栈帧起始地址。利用FP寄存器可以得到父函数的栈帧,从栈帧中获取父函数的FP,就可以得到祖父函数的栈帧,以此类推,可以追溯程序调用栈,得到函数间的调用关系。 - -当系统发生异常时,系统打印异常函数的栈帧中保存的寄存器内容,以及父函数、祖父函数的栈帧中的LR链接寄存器、FP帧指针寄存器内容,用户就可以据此追溯函数间的调用关系,定位异常原因。 - -堆栈分析原理如下图所示,实际堆栈信息根据不同CPU架构有所差异,此处仅做示意。 - -**图 1** 堆栈分析原理示意图 -![](/images/device-dev/kernel/figure/堆栈分析原理示意图.png "堆栈分析原理示意图") - -图中不同颜色的寄存器表示不同的函数。可以看到函数调用过程中,寄存器的保存。通过FP寄存器,栈回溯到异常函数的父函数,继续按照规律对栈进行解析,推出函数调用关系,方便用户定位问题。 - -## 接口说明 - -OpenHarmony LiteOS-M内核的回溯栈模块提供下面几种功能,接口详细信息可以查看API参考。 - -**表 1** 回溯栈模块接口 - - - - - - - - - - - - - - - -

功能分类

-

接口名

-

描述

-

回溯栈接口

-

LOS_BackTrace

-

打印调用处的函数调用栈关系。

-

LOS_RecordLR

-

在无法打印的场景,用该接口获取调用处的函数调用栈关系。

-
- -## 使用指导 - -### 开发流程 - -开启异常调测的典型流程如下: - -1. 配置异常接管相关宏。 - - 需要在target\_config.h头文件中修改配置: - - - - - - - - - - - - - - - - -

配置项

-

含义

-

设置值

-

LOSCFG_BACKTRACE_DEPTH

-

函数调用栈深度,默认15层

-

15

-

LOSCFG_BACKTRACE_TYPE

-

回溯栈类型:

-

0:表示关闭该功能;

-

1:表示支持Cortex-m系列硬件的函数调用栈解析;

-

2:表示用于Risc-v系列硬件的函数调用栈解析;

-

根据工具链类型设置1或2

-
- - -1. 使用示例中有问题的代码,编译、运行工程,在串口终端中查看异常信息输出。示例代码模拟异常代码,实际产品开发时使用异常调测机制定位异常问题。 - - 本示例演示异常输出,包含1个任务,该任务入口函数模拟若干函数调用,最终调用一个模拟异常的函数。代码实现如下: - - ``` - #include - #include "los_config.h" - #include "los_interrupt.h" - #include "los_task.h" - - UINT32 g_taskExcId; - #define TSK_PRIOR 4 - - /* 模拟异常函数 */ - - UINT32 Get_Result_Exception_0(UINT16 dividend){ - UINT32 divisor = 0; - UINT32 result = dividend / divisor; - return result; - } - - UINT32 Get_Result_Exception_1(UINT16 dividend){ - return Get_Result_Exception_0(dividend); - } - - UINT32 Get_Result_Exception_2(UINT16 dividend){ - return Get_Result_Exception_1(dividend); - } - - UINT32 Example_Exc(VOID) - { - UINT32 ret; - - printf("Enter Example_Exc Handler.\r\n"); - - /* 模拟函数调用 */ - ret = Get_Result_Exception_2(TSK_PRIOR); - printf("Divided result =%u.\r\n", ret); - - printf("Exit Example_Exc Handler.\r\n"); - return ret; - } - - - /* 任务测试入口函数,创建一个会发生异常的任务 */ - UINT32 Example_Exc_Entry(VOID) - { - UINT32 ret; - TSK_INIT_PARAM_S initParam; - - /* 锁任务调度,防止新创建的任务比本任务高而发生调度 */ - LOS_TaskLock(); - - printf("LOS_TaskLock() Success!\r\n"); - - initParam.pfnTaskEntry = (TSK_ENTRY_FUNC)Example_Exc; - initParam.usTaskPrio = TSK_PRIOR; - initParam.pcName = "Example_Exc"; - initParam.uwStackSize = LOSCFG_SECURE_STACK_DEFAULT_SIZE; - /* 创建高优先级任务,由于锁任务调度,任务创建成功后不会马上执行 */ - ret = LOS_TaskCreate(&g_taskExcId, &initParam); - if (ret != LOS_OK) { - LOS_TaskUnlock(); - - printf("Example_Exc create Failed!\r\n"); - return LOS_NOK; - } - - printf("Example_Exc create Success!\r\n"); - - /* 解锁任务调度,此时会发生任务调度,执行就绪队列中最高优先级任务 */ - LOS_TaskUnlock(); - - return LOS_OK; - } - ``` - - -1. 上述代码串口终端输出异常信息如下: - - ``` - entering kernel init... - LOS_TaskLock() Success! - Example_Exc create Success! - Entering scheduler - Enter Example_Exc Handler. - *************Exception Information************** - Type = 10 - ThrdPid = 4 - Phase = exc in task - FaultAddr = 0xabababab - Current task info: - Task name = Example_Exc - Task ID = 4 - Task SP = 0x200051ac - Task ST = 0x20004ff0 - Task SS = 0x200 - Exception reg dump: - PC = 0x80037da - LR = 0x80037fe - SP = 0x20005190 - R0 = 0x4 - R1 = 0x40 - R2 = 0x4 - R3 = 0x0 - R4 = 0x4040404 - R5 = 0x5050505 - R6 = 0x6060606 - R7 = 0x20005190 - R8 = 0x8080808 - R9 = 0x9090909 - R10 = 0x10101010 - R11 = 0x11111111 - R12 = 0x12121212 - PriMask = 0x0 - xPSR = 0x41000000 - ----- backtrace start ----- - backtrace 0 -- lr = 0x800381a - backtrace 1 -- lr = 0x8003836 - backtrace 2 -- lr = 0x8005a4e - backtrace 3 -- lr = 0x8000494 - backtrace 4 -- lr = 0x8008620 - backtrace 5 -- lr = 0x800282c - backtrace 6 -- lr = 0x80008a0 - backtrace 7 -- lr = 0x80099f8 - backtrace 8 -- lr = 0x800a01a - backtrace 9 -- lr = 0x800282c - backtrace 10 -- lr = 0x80008a0 - backtrace 11 -- lr = 0x80099f8 - backtrace 12 -- lr = 0x8009bf0 - backtrace 13 -- lr = 0x8009c52 - backtrace 14 -- lr = 0x80099aa - ----- backtrace end ----- - - TID Priority Status StackSize WaterLine StackPoint TopOfStack EventMask SemID name - --- -------- -------- --------- ---------- ---------- ---------- --------- ----- ---- - 0 0 Pend 0x2d0 0x104 0x200029bc 0x200027f0 0x0 0xffff Swt_Task - 1 31 Ready 0x500 0x44 0x20002f84 0x20002ac8 0x0 0xffff IdleCore000 - 2 6 Ready 0x1000 0x44 0x20003f94 0x20002fd8 0x0 0xffff TaskSampleEntry1 - 3 7 Ready 0x1000 0x44 0x20004f9c 0x20003fe0 0x0 0xffff TaskSampleEntry2 - 4 4 Running 0x200 0xec 0x200051ac 0x20004ff0 0x0 0xffff Example_Exc - - OS exception NVIC dump: - interrupt enable register, base address: 0xe000e100, size: 0x20 - 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 - interrupt pending register, base address: 0xe000e200, size: 0x20 - 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 - interrupt active register, base address: 0xe000e300, size: 0x20 - 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 - interrupt priority register, base address: 0xe000e400, size: 0xf0 - 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 - 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 - 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 - 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 - interrupt exception register, base address: 0xe000ed18, size: 0xc - 0x0 0x0 0xf0f00000 - interrupt shcsr register, base address: 0xe000ed24, size: 0x4 - 0x70008 - interrupt control register, base address: 0xe000ed04, size: 0x4 - 0x400f806 - - memory pools check: - system heap memcheck over, all passed! - memory pool check end! - ``` - - -### 定位流程 - -异常接管一般的定位步骤如下: - -1. 打开编译后生成的镜像反汇编(asm)文件。如果默认没有生成,可以使用objdump工具生成,命令为: - - ``` - arm-none-eabi-objdump -S -l XXX.elf - ``` - - -1. 搜索PC指针(指向当前正在执行的指令)在asm中的位置,找到发生异常的函数。 - - PC地址指向发生异常时程序正在执行的指令。在当前执行的二进制文件对应的asm文件中,查找PC值0x80037da,找到当前CPU正在执行的指令行,反汇编如下所示: - - ``` - UINT32 Get_Result_Exception_0(UINT16 dividend){ - 80037c8: b480 push {r7} - 80037ca: b085 sub sp, #20 - 80037cc: af00 add r7, sp, #0 - 80037ce: 4603 mov r3, r0 - 80037d0: 80fb strh r3, [r7, #6] - kernel_liteos_m\targets\cortex-m7_nucleo_f767zi_gcc/Core/Src/exc_example.c:10 - UINT32 divisor = 0; - 80037d2: 2300 movs r3, #0 - 80037d4: 60fb str r3, [r7, #12] - kernel_liteos_m\targets\cortex-m7_nucleo_f767zi_gcc/Core/Src/exc_example.c:11 - UINT32 result = dividend / divisor; - 80037d6: 88fa ldrh r2, [r7, #6] - 80037d8: 68fb ldr r3, [r7, #12] - 80037da: fbb2 f3f3 udiv r3, r2, r3 - 80037de: 60bb str r3, [r7, #8] - ``` - - -1. 可以看到: - 1. 异常时CPU正在执行的指令是udiv r3, r2, r3,其中r3取值为0,导致发生除零异常。 - 2. 异常发生在函数Get\_Result\_Exception\_0中。 - -2. 根据LR值查找异常函数的父函数。 - - 包含LR值0x80037fe的反汇编如下所示: - - ``` - 080037ec : - Get_Result_Exception_1(): - kernel_liteos_m\targets\cortex-m7_nucleo_f767zi_gcc/Core/Src/exc_example.c:15 - UINT32 Get_Result_Exception_1(UINT16 dividend){ - 80037ec: b580 push {r7, lr} - 80037ee: b082 sub sp, #8 - 80037f0: af00 add r7, sp, #0 - 80037f2: 4603 mov r3, r0 - 80037f4: 80fb strh r3, [r7, #6] - kernel_liteos_m\targets\cortex-m7_nucleo_f767zi_gcc/Core/Src/exc_example.c:16 - return Get_Result_Exception_0(dividend); - 80037f6: 88fb ldrh r3, [r7, #6] - 80037f8: 4618 mov r0, r3 - 80037fa: f7ff ffe5 bl 80037c8 - 80037fe: 4603 mov r3, r0 - ``` - - -1. LR值80037fe上一行是bl 80037c8 ,此处调用了异常函数,调用异常函数的父函数为Get\_Result\_Exception\_1\(\)。 -2. 重复步骤3,解析异常信息中backtrace start至backtrace end之间的LR值,得到调用产生异常的函数调用栈关系,找到异常原因。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/04.\345\206\205\346\240\270\350\260\203\346\265\213/03.Trace\350\260\203\346\265\213.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/04.\345\206\205\346\240\270\350\260\203\346\265\213/03.Trace\350\260\203\346\265\213.md" deleted file mode 100644 index 062dba37c887479c3d2b2002ecf4783d29fcf8b8..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/04.\345\206\205\346\240\270\350\260\203\346\265\213/03.Trace\350\260\203\346\265\213.md" +++ /dev/null @@ -1,364 +0,0 @@ ---- -title: Trace调测 -permalink: /pages/010501010403 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# Trace调测 - -- [基本概念](#section1) - -- [运行机制](#section2) - -- [接口说明](#section3) - -- [开发指导](#section4) - - - [开发流程](#section4.1) - - - [编程实例](#section4.2) - - - [实例代码](#section4.3) - - - [结果验证](#section4.4) - -## 基本概念 -Trace调测旨在帮助开发者获取内核的运行流程,各个模块、任务的执行顺序,从而可以辅助开发者定位一些时序问题或者了解内核的代码运行过程。 - -## 运行机制 -内核提供一套Hook框架,将Hook点预埋在各个模块的主要流程中, 在内核启动初期完成Trace功能的初始化,并注册Trace的处理函数到Hook中。 - -当系统触发到一个Hook点时,Trace模块会对输入信息进行封装,添加Trace帧头信息,包含事件类型、运行的cpuid、运行的任务id、运行的相对时间戳等信息; - -Trace提供2种工作模式,离线模式和在线模式。 - -离线模式会将trace frame记录到预先申请好的循环buffer中。如果循环buffer记录的frame过多则可能出现翻转,会覆盖之前的记录,故保持记录的信息始终是最新的信息。Trace循环buffer的数据可以通过shell命令导出进行详细分析,导出信息已按照时间戳信息完成排序。 - -![](/images/device-dev/kernel/figure/zh-cn_image_0000001127390512.png) - -在线模式需要配合IDE使用,实时将trace frame记录发送给IDE,IDE端进行解析并可视化展示。 - -## 接口说明 -OpenHarmony LiteOS-M内核的Trace模块提供下面几种功能,接口详细信息可以查看[API](https://gitee.com/openharmony/kernel_liteos_m/blob/master/components/trace/los_trace.h)参考。 - -**表 1** Trace模块接口说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名

-

描述

-

启停控制

-

LOS_TraceStart

-

启动Trace

-

LOS_TraceStop

-

停止Trace

-

操作Trace记录的数据

-

LOS_TraceRecordDump

-

输出Trace缓冲区数据

-

LOS_TraceRecordGet

-

获取Trace缓冲区的首地址

-

LOS_TraceReset

-

清除Trace缓冲区中的事件

-

过滤Trace记录的数据

-

LOS_TraceEventMaskSet

-

设置事件掩码,仅记录某些模块的事件

-

屏蔽某些中断号事件

-

LOS_TraceHwiFilterHookReg

-

注册过滤特定中断号事件的钩子函数

-

插桩函数

-

LOS_TRACE_EASY

-

简易插桩

-

LOS_TRACE

-

标准插桩

-
- - -1. 当用户需要针对自定义事件进行追踪时,可按规则在目标源代码中进行插桩,系统提供如下2种插桩接口: - -+ LOS_TRACE_EASY(TYPE, IDENTITY, params...) 简易插桩。 - - - 一句话插桩,用户在目标源代码中插入该接口即可。 - - - TYPE有效取值范围为[0, 0xF],表示不同的事件类型,不同取值表示的含义由用户自定义。 - - - IDENTITY类型UINTPTR,表示事件操作的主体对象。 - - - Params类型UINTPTR,表示事件的参数。 - - - 示例: - - ``` - 假设需要新增对文件(fd1、fd2)读写操作的简易插桩, - 自定义读操作为type:1, 写操作为type:2,则 - 在读fd1文件的适当位置插入: - LOS_TRACE_EASY(1, fd1, flag, size); - 在读fd2文件的适当位置插入: - LOS_TRACE_EASY(1, fd2, flag, size); - 在写fd1文件的适当位置插入: - LOS_TRACE_EASY(2, fd1, flag, size); - 在写fd2文件的适当位置插入: - LOS_TRACE_EASY(2, fd2,flag, size); - ``` - -+ LOS_TRACE(TYPE, IDENTITY, params...) 标准插桩。 - - - 相比简易插桩,支持动态过滤事件和参数裁剪,但使用上需要用户按规则来扩展。 - - - TYPE用于设置具体的事件类型,可以在头文件los_trace.h中的enum LOS_TRACE_TYPE中自定义事件类型。定义方法和规则可以参考其他事件类型。 - - - IDENTITY和Params的类型及含义同简易插桩。 - - - 示例: -``` - 1.在enum LOS_TRACE_MASK中定义事件掩码,即模块级别的事件类型。 - 定义规范为TRACE_#MOD#_FLAG,#MOD#表示模块名,例如: - TRACE_FS_FLAG = 0x4000 - 2.在enum LOS_TRACE_TYPE中定义具体事件类型。定义规范为#TYPE# = TRACE_#MOD#_FLAG | NUMBER,例如: - FS_READ = TRACE_FS_FLAG | 0; // 读文件 - FS_WRITE = TRACE_FS_FLAG | 1; // 写文件 - 3.定义事件参数。定义规范为#TYPE#_PARAMS(IDENTITY, parma1...) IDENTITY, ... - 其中的#TYPE#就是上面2中的#TYPE#,例如: - #define FS_READ_PARAMS(fp, fd, flag, size) fp, fd, flag, size - 宏定义的参数对应于Trace缓冲区中记录的事件参数,用户可对任意参数字段进行裁剪: - 当定义为空时,表示不追踪该类型事件: - #define FS_READ_PARAMS(fp, fd, flag, size) // 不追踪文件读事件 - 4.在适当位置插入代码桩。定义规范为LOS_TRACE(#TYPE#, #TYPE#_PARAMS(IDENTITY, parma1...)) - LOS_TRACE(FS_READ, fp, fd, flag, size); // 读文件的代码桩, - #TYPE#之后的入参就是上面3中的FS_READ_PARAMS函数的入参 -``` -2. 预置的Trace事件及参数均可以通过上述方式进行裁剪,参数详见kernel\include\los_trace.h。 - -3. Trace Mask事件过滤接口LOS_TraceEventMaskSet(UINT32 mask),其入参mask仅高28位生效(对应LOS_TRACE_MASK中某模块的使能位),仅用于模块的过滤,暂不支持针对某个特定事件的细粒度过滤。例如:LOS_TraceEventMaskSet(0x202),则实际设置生效的mask为0x200(TRACE_QUE_FLAG),QUE模块的所有事件均会被采集。一般建议使用的方法为: - LOS_TraceEventMaskSet(TRACE_EVENT_FLAG | TRACE_MUX_FLAG | TRACE_SEM_FLAG | TRACE_QUE_FLAG); - -4. 如果仅需要过滤简易插桩事件,通过设置Trace Mask为TRACE_MAX_FLAG即可。 - -5. Trace缓冲区有限,事件写满之后会覆盖写,用户可通过LOS_TraceRecordDump中打印的CurEvtIndex识别最新记录。 - -6. Trace的典型操作流程为:LOS_TraceStart、 LOS_TraceStop、 LOS_TraceRecordDump. - -7. 针对中断事件的Trace, 提供中断号过滤,用于解决某些场景下特定中断号频繁触发导致其他事件被覆盖的情况,用户可自定义中断过滤的规则, - - 示例如下: -``` -BOOL Example_HwiNumFilter(UINT32 hwiNum) -{ - if ((hwiNum == TIMER_INT) || (hwiNum == DMA_INT)) { - return TRUE; - } - return FALSE; -} -LOS_TraceHwiFilterHookReg(Example_HwiNumFilter); -``` -则当中断号为TIMER_INT 或者DMA_INT时,不记录中断事件。 - -## 开发指导 - -### 开发流程 - -开启Trace调测的典型流程如下: - -1. 配置Trace模块相关宏。 - -需要在target_config.h头文件中修改配置: - -| 配置项 | 含义 | 设置值 | -| ------------------------------ | ------------------------------------------------------------ | ------ | -| LOSCFG_KERNEL_TRACE | Trace模块的裁剪开关 | YES/NO | -| LOSCFG_RECORDER_MODE_OFFLINE | Trace工作模式为离线模式 | YES/NO | -| LOSCFG_RECORDER_MODE_ONLINE | Trace工作模式为在线模式 | YES/NO | -| LOSCFG_TRACE_CLIENT_INTERACT | 使能与Trace IDE (dev tools)的交互,包括数据可视化和流程控制 | YES/NO | -| LOSCFG_TRACE_FRAME_CORE_MSG | 记录CPUID、中断状态、锁任务状态 | YES/NO | -| LOSCFG_TRACE_FRAME_EVENT_COUNT | 记录事件的次序编号 | YES/NO | -| LOSCFG_TRACE_FRAME_MAX_PARAMS | 配置记录事件的最大参数个数 | INT | -| LOSCFG_TRACE_BUFFER_SIZE | 配置Trace的缓冲区大小 | INT | - -2. (可选)预置事件参数和事件桩(或使用系统默认的事件参数配置和事件桩)。 - -3. (可选)调用LOS_TraceStop停止Trace后,清除缓冲区LOS_TraceReset(系统默认已启动trace)。 - -4. (可选)调用LOS_TraceEventMaskSet设置需要追踪的事件掩码(系统默认的事件掩码仅使能中断与任务事件),事件掩码参见los_trace.h 中的LOS_TRACE_MASK定义。 - -5. 在需要记录事件的代码起始点调用LOS_TraceStart。 - -6. 在需要记录事件的代码结束点调用LOS_TraceStop。 - -7. 调用LOS_TraceRecordDump输出缓冲区数据(函数的入参为布尔型,FALSE表示格式化输出,TRUE表示输出到windows客户端)。 - - -上述第3-7步中的接口,均封装有对应的shell命令,对应关系如下 - -- LOS_TraceReset —— trace_reset - -- LOS_TraceEventMaskSet —— trace_mask - -- LOS_TraceStart —— trace_start - -- LOS_TraceStop —— trace_stop - -- LOS_TraceRecordDump —— trace_dump - -### 编程实例 - - 本实例实现如下功能: - - 1. 创建一个用于Trace测试的任务。 - - 2. 设置事件掩码。 - - 3. 启动trace。 - - 4. 停止trace。 - - 5. 格式化输出trace数据。 - -### 示例代码 - -实例代码如下: - -```C -#include "los_trace.h" -UINT32 g_traceTestTaskId; -VOID Example_Trace(VOID) -{ - UINT32 ret; - LOS_TaskDelay(10); - /* 开启trace */ - ret = LOS_TraceStart(); - if (ret != LOS_OK) { - dprintf("trace start error\n"); - return; - } - /* 触发任务切换的事件 */ - LOS_TaskDelay(1); - LOS_TaskDelay(1); - LOS_TaskDelay(1); - /* 停止trace */ - LOS_TraceStop(); - LOS_TraceRecordDump(FALSE); -} - -UINT32 Example_Trace_test(VOID){ - UINT32 ret; - TSK_INIT_PARAM_S traceTestTask; - /* 创建用于trace测试的任务 */ - memset(&traceTestTask, 0, sizeof(TSK_INIT_PARAM_S)); - traceTestTask.pfnTaskEntry = (TSK_ENTRY_FUNC)Example_Trace; - traceTestTask.pcName = "TestTraceTsk"; /* 测试任务名称 */ - traceTestTask.uwStackSize = 0x800; - traceTestTask.usTaskPrio = 5; - traceTestTask.uwResved = LOS_TASK_STATUS_DETACHED; - ret = LOS_TaskCreate(&g_traceTestTaskId, &traceTestTask); - if(ret != LOS_OK){ - dprintf("TraceTestTask create failed .\n"); - return LOS_NOK; - } - /* 系统默认情况下已启动trace, 因此可先关闭trace后清除缓存区后,再重启trace */ - LOS_TraceStop(); - LOS_TraceReset(); - /* 开启任务模块事件记录 */ - LOS_TraceEventMaskSet(TRACE_TASK_FLAG); - return LOS_OK; -} -``` - -### 结果验证 - -输出结果如下: - -```c -*******TraceInfo begin******* -clockFreq = 50000000 -CurEvtIndex = 7 -Index Time(cycles) EventType CurTask Identity params -0 0x366d5e88 0x45 0x1 0x0 0x1f 0x4 0x0 -1 0x366d74ae 0x45 0x0 0x1 0x0 0x8 0x1f -2 0x36940da6 0x45 0x1 0xc 0x1f 0x4 0x9 -3 0x3694337c 0x45 0xc 0x1 0x9 0x8 0x1f -4 0x36eea56e 0x45 0x1 0xc 0x1f 0x4 0x9 -5 0x36eec810 0x45 0xc 0x1 0x9 0x8 0x1f -6 0x3706f804 0x45 0x1 0x0 0x1f 0x4 0x0 -7 0x37070e59 0x45 0x0 0x1 0x0 0x8 0x1f -*******TraceInfo end******* -``` - -输出的事件信息包括:发生时间、事件类型、事件发生在哪个任务中、事件操作的主体对象、事件的其他参数。 - -- EventType:表示的具体事件可查阅头文件los_trace.h中的enum LOS_TRACE_TYPE。 - -- CurrentTask:表示当前运行在哪个任务中,值为taskid。 - -- Identity:表示事件操作的主体对象,可查阅头文件los_trace.h中的#TYPE#_PARAMS。 - -- params:表示的事件参数可查阅头文件los_trace.h中的#TYPE#_PARAMS。 - -下面以序号为0的输出项为例,进行说明。 - -``` -Index Time(cycles) EventType CurTask Identity params -0 0x366d5e88 0x45 0x1 0x0 0x1f 0x4 -``` - -- Time cycles可换算成时间,换算公式为cycles/clockFreq,单位为s。 - -- 0x45为TASK_SWITCH即任务切换事件,当前运行的任务taskid为0x1。 - -- Identity和params的含义需要查看TASK_SWITCH_PARAMS宏定义: - -```c -#define TASK_SWITCH_PARAMS(taskId, oldPriority, oldTaskStatus, newPriority, newTaskStatus) \ -taskId, oldPriority, oldTaskStatus, newPriority, newTaskStatus -``` - -因为#TYPE#_PARAMS(IDENTITY, parma1...) IDENTITY, ...,所以Identity为taskId(0x0),第一个参数为oldPriority(0x1f) - -> ![](/images/device-dev/public_sys-resources/icon-note.gif)**说明** - - > params的个数由LOSCFG_TRACE_FRAME_MAX_PARAMS配置,默认为3,超出的参数不会被记录,用户应自行合理配置该值。 - - 综上所述,任务由0x1切换到0x0,0x1任务的优先级为0x1f,状态为0x4,0x0任务的优先级为0x0。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/04.\345\206\205\346\240\270\350\260\203\346\265\213/04.LMS\350\260\203\346\265\213.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/04.\345\206\205\346\240\270\350\260\203\346\265\213/04.LMS\350\260\203\346\265\213.md" deleted file mode 100644 index 1b783b19d3561e23c62b9530b26164f5e8444ec8..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/04.\345\206\205\346\240\270\350\260\203\346\265\213/04.LMS\350\260\203\346\265\213.md" +++ /dev/null @@ -1,306 +0,0 @@ ---- -title: LMS调测 -permalink: /pages/010501010404 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# LMS调测 - -- [基本概念](#section1) - -- [运行机制](#section2) - -- [接口说明](#section3) - -- [开发指导](#section4) - - - [开发流程](#section4.1.1) - - - [编程实例](#section4.1.2) - - - [实例代码](#section4.1.3) - - - [结果验证](#section4.1.4) - - -## 基本概念 -LMS全称为Lite Memory Sanitizer,是一种实时检测内存操作合法性的调测工具。LMS能够实时检测缓冲区溢出(buffer overflow),释放后使用(use after free) 和重复释放(double Free), 在异常发生的第一时间通知操作系统,结合backtrace等定位手段,能准确定位到产生内存问题的代码行,极大提升内存问题定位效率。 - -## 运行机制 -LMS使用影子内存映射标记系统内存的状态,一共可标记为三个状态:可读写,不可读写,已释放。影子内存存放在内存池的尾部。 - -- 内存从堆上申请后,会将数据区的影子内存设置为“可读写”状态,并将头结点区的影子内存设置为“不可读写”状态。 - -- 内存在堆上被释放时,会将被释放内存的影子内存设置为“已释放”状态。 - -- 编译代码时,会在代码中的读写指令前插入检测函数,对地址的合法性进行检验。主要是检测访问内存的影子内存的状态值,若检测到影子内存为不可读写,则会报溢出错误;若检测到影子内存为已释放,则会报释放后使用错误。 - -- 在内存释放时,会检测被释放地址的影子内存状态值,若检测到影子内存非可读写,则会报重复释放错误。 - -## 接口说明 - -OpenHarmony LiteOS-M内核的LMS模块提供下面几种功能,接口详细信息可以查看[API](https://gitee.com/openharmony/kernel_liteos_m/blob/master/components/lms/los_lms.h)参考。 - - -1. 支持多内存池检测; - -2. 支持LOS_MemAlloc、LOS_MemAllocAlign、LOS_MemRealloc申请出的内存检测; - -3. 支持安全函数的访问检测(默认开启); - -4. 支持libc 高频函数的访问检测,包括:memset、memcpy、memmove、strcat、strcpy、strncat、strncpy。 - -5. 可动态设置的功能如下: - -**表 1** LMS模块接口说明 - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名

-

描述

-

添加指定内存池被检测

-

LOS_LmsCheckPoolAdd

-

将指定内存池的地址范围添加到LMS的内存检测链表上,当访问的地址在链表范围内时,LMS才进行合法性校验;且LOS_MemInit接口会调用该接口,默认将初始化的内存池挂入到检测链表中。

-

删除指定内存池不被检测

-

LOS_LmsCheckPoolDel

-

不检测指定内存池地址范围内的合法性校验。

-

使能指定内存段锁保护

-

LOS_LmsAddrProtect

-

为某段内存地址上锁,设置为不可读写,一旦访问则报错。

-

去能指定内存段锁保护

-

LOS_LmsAddrDisableProtect

-

为某段内存地址解锁,设置为可读写。

-
- - -## 开发指导 - -### 开发流程 - -开启LMS调测的典型流程如下: - -1. 配置LMS模块相关宏。 - - 配置LMS控制宏LOSCFG_KERNEL_LMS,默认关,在kernel/liteos_a目录下执行 make update_config命令配置"Kernel->Enable Lite Memory Sanitizer"中打开: - - | 配置项 | menuconfig选项 | 含义 | 设置值 | - | ------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | ------ | - | LOSCFG_KERNEL_LMS | Enable Lms Feature | Lms模块的裁剪开关 | YES/NO | - | LOSCFG_LMS_MAX_RECORD_POOL_NUM | Lms check pool max num | LMS支持的检测内存池最大个数 | INT | - | LOSCFG_LMS_LOAD_CHECK | Enable lms read check | LMS内存读检测的裁剪开关 | YES/NO | - | LOSCFG_LMS_STORE_CHECK | Enable lms write check | LMS内存写检测的裁剪开关 | YES/NO | - | LOSCFG_LMS_CHECK_STRICT | Enable lms strict check, byte-by-byte | LMS内存逐字节严格检测的裁剪开关 | YES/NO | - -2. 在被检测模块的编译脚本中,增加LMS检测编译选项-fsanitize=kernel-address。 - -3. 为避免编译器优化,增加-O0编译选项。 - -4. gcc与clang编译选项存在差异,参照如下示例: - - ``` - if ("$ohos_build_compiler_specified" == "gcc") { - cflags_c = [ - "-O0", - "-fsanitize=kernel-address", - ] - } else { - cflags_c = [ - "-O0", - "-fsanitize=kernel-address", - "-mllvm", - "-asan-instrumentation-with-call-threshold=0", - "-mllvm", - "-asan-stack=0", - "-mllvm", - "-asan-globals=0", - ] - } - ``` - -5. 重新编译,查看串口输出。如果检测到内存问题,会输出检测结果。 - -### 编程实例 - - 本实例实现如下功能: - - 1. 创建一个用于Lms测试的任务。 - - 2. 构造内存溢出错误和释放后使用错误。 - - 3. 添加-fsanitize=kernel-address后编译执行,观察输出结果 - -### 示例代码 - -实例代码如下: - -```C -#define PAGE_SIZE (0x1000U) -#define INDEX_MAX 20 - -UINT32 g_lmsTestTaskId; -char g_testLmsPool[2 * PAGE_SIZE]; - -STATIC VOID testPoolInit(void) -{ - UINT32 ret = LOS_MemInit(g_testLmsPool, 2 * PAGE_SIZE); - if (ret != 0) { - PRINT_ERR("%s failed, ret = 0x%x\n", __FUNCTION__, ret); - return; - } -} - -static VOID LmsTestOsmallocOverflow(VOID) -{ - PRINTK("\n######%s start ######\n", __FUNCTION__); - UINT32 i; - CHAR *str = (CHAR *)LOS_MemAlloc(g_testLmsPool, INDEX_MAX); - PRINTK("str[%2d]=0x%2x ", INDEX_MAX, str[INDEX_MAX]); /* trigger heap overflow at str[INDEX_MAX] */ - PRINTK("\n######%s stop ######\n", __FUNCTION__); -} - -static VOID LmsTestUseAfterFree(VOID) -{ - PRINTK("\n######%s start ######\n", __FUNCTION__); - UINT32 i; - CHAR *str = (CHAR *)LOS_MemAlloc(g_testLmsPool, INDEX_MAX); - LOS_MemFree(g_testLmsPool, str); - PRINTK("str[%2d]=0x%2x ", 0, str[0]); /* trigger use after free at str[0] */ - PRINTK("\n######%s stop ######\n", __FUNCTION__); -} - -VOID LmsTestCaseTask(VOID) -{ - testPoolInit(); - LmsTestOsmallocOverflow(); - LmsTestUseAfterFree(); -} - -UINT32 Example_Lms_test(VOID){ - UINT32 ret; - TSK_INIT_PARAM_S lmsTestTask; - /* 创建用于lms测试的任务 */ - memset(&lmsTestTask, 0, sizeof(TSK_INIT_PARAM_S)); - lmsTestTask.pfnTaskEntry = (TSK_ENTRY_FUNC)LmsTestCaseTask; - lmsTestTask.pcName = "TestLmsTsk"; /* 测试任务名称 */ - lmsTestTask.uwStackSize = 0x800; - lmsTestTask.usTaskPrio = 5; - lmsTestTask.uwResved = LOS_TASK_STATUS_DETACHED; - ret = LOS_TaskCreate(&g_lmsTestTaskId, &lmsTestTask); - if(ret != LOS_OK){ - PRINT_ERR("LmsTestTask create failed .\n"); - return LOS_NOK; - } - return LOS_OK; -} -``` - -### 结果验证 - -输出结果如下: - -```c -######LmsTestOsmallocOverflow start ###### -[ERR]***** Kernel Address Sanitizer Error Detected Start ***** -[ERR]Heap buffer overflow error detected -[ERR]Illegal READ address at: [0x4157a3c8] -[ERR]Shadow memory address: [0x4157be3c : 4] Shadow memory value: [2] -OsBackTrace fp = 0x402c0f88 -runTask->taskName = LmsTestCaseTask -runTask->taskID = 2 -*******backtrace begin******* -traceback fp fixed, trace using fp = 0x402c0fd0 -traceback 0 -- lr = 0x400655a4 fp = 0x402c0ff8 -traceback 1 -- lr = 0x40065754 fp = 0x402c1010 -traceback 2 -- lr = 0x40044bd0 fp = 0x402c1038 -traceback 3 -- lr = 0x40004e14 fp = 0xcacacaca - -[LMS] Dump info around address [0x4157a3c8]: - - [0x4157a3a0]: 00 00 00 00 00 00 00 00 | [0x4157be3a | 0]: 1 1 - [0x4157a3a8]: ba dc cd ab 00 00 00 00 | [0x4157be3a | 4]: 2 2 - [0x4157a3b0]: 20 00 00 80 00 00 00 00 | [0x4157be3b | 0]: 2 0 - [0x4157a3b8]: 00 00 00 00 00 00 00 00 | [0x4157be3b | 4]: 0 0 - [0x4157a3c0]: 00 00 00 00 00 00 00 00 | [0x4157be3c | 0]: 0 0 - [0x4157a3c8]: [ba] dc cd ab a8 a3 57 41 | [0x4157be3c | 4]: [2] 2 - [0x4157a3d0]: 2c 1a 00 00 00 00 00 00 | [0x4157be3d | 0]: 2 3 - [0x4157a3d8]: 00 00 00 00 00 00 00 00 | [0x4157be3d | 4]: 3 3 - [0x4157a3e0]: 00 00 00 00 00 00 00 00 | [0x4157be3e | 0]: 3 3 - [0x4157a3e8]: 00 00 00 00 00 00 00 00 | [0x4157be3e | 4]: 3 3 - [0x4157a3f0]: 00 00 00 00 00 00 00 00 | [0x4157be3f | 0]: 3 3 -[ERR]***** Kernel Address Sanitizer Error Detected End ***** -str[20]=0xffffffba -######LmsTestOsmallocOverflow stop ###### - -###### LmsTestUseAfterFree start ###### -[ERR]***** Kernel Address Sanitizer Error Detected Start ***** -[ERR]Use after free error detected -[ERR]Illegal READ address at: [0x4157a3d4] -[ERR]Shadow memory address: [0x4157be3d : 2] Shadow memory value: [3] -OsBackTrace fp = 0x402c0f90 -runTask->taskName = LmsTestCaseTask -runTask->taskID = 2 -*******backtrace begin******* -traceback fp fixed, trace using fp = 0x402c0fd8 -traceback 0 -- lr = 0x40065680 fp = 0x402c0ff8 -traceback 1 -- lr = 0x40065758 fp = 0x402c1010 -traceback 2 -- lr = 0x40044bd0 fp = 0x402c1038 -traceback 3 -- lr = 0x40004e14 fp = 0xcacacaca - -[LMS] Dump info around address [0x4157a3d4]: - - [0x4157a3a8]: ba dc cd ab 00 00 00 00 | [0x4157be3a | 4]: 2 2 - [0x4157a3b0]: 20 00 00 80 00 00 00 00 | [0x4157be3b | 0]: 2 0 - [0x4157a3b8]: 00 00 00 00 00 00 00 00 | [0x4157be3b | 4]: 0 0 - [0x4157a3c0]: 00 00 00 00 00 00 00 00 | [0x4157be3c | 0]: 0 0 - [0x4157a3c8]: ba dc cd ab a8 a3 57 41 | [0x4157be3c | 4]: 2 2 - [0x4157a3d0]: 2c 1a 00 00 [00] 00 00 00 | [0x4157be3d | 0]: 2 [3] - [0x4157a3d8]: 00 00 00 00 00 00 00 00 | [0x4157be3d | 4]: 3 3 - [0x4157a3e0]: 00 00 00 00 00 00 00 00 | [0x4157be3e | 0]: 3 3 - [0x4157a3e8]: ba dc cd ab c8 a3 57 41 | [0x4157be3e | 4]: 2 2 - [0x4157a3f0]: 0c 1a 00 00 00 00 00 00 | [0x4157be3f | 0]: 2 3 - [0x4157a3f8]: 00 00 00 00 00 00 00 00 | [0x4157be3f | 4]: 3 3 -[ERR]***** Kernel Address Sanitizer Error Detected End ***** -str[ 0]=0x 0 -######LmsTestUseAfterFree stop ###### -``` -输出的关键信息包括: -- 错误类型: - - Heap buffer overflow堆内存越界 - - Use after free 释放后使用 -- 错误操作: - - Illegal Read非法读 - - Illegal Write非法写 - - Illegal Double free重复释放 -- 上下文: - - 当前任务信息(taskName, taskId) - - 回溯栈(backtrace) -- 出错地址的内存信息: - - 内存的值、及对应影子内存的值 - - 内存地址:内存值| [影子内存地址 | 影子内存字节内偏移]:影子内存值 - - 影子内存值:0(可读可写)、3(已释放)、2(红区)、1(填充值)。 diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/05.\351\231\204\345\275\225/01.\345\206\205\346\240\270\347\274\226\347\240\201\350\247\204\350\214\203.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/05.\351\231\204\345\275\225/01.\345\206\205\346\240\270\347\274\226\347\240\201\350\247\204\350\214\203.md" deleted file mode 100644 index b680801ad1c451b69e137006f2484f0566885f9f..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/05.\351\231\204\345\275\225/01.\345\206\205\346\240\270\347\274\226\347\240\201\350\247\204\350\214\203.md" +++ /dev/null @@ -1,346 +0,0 @@ ---- -title: 内核编码规范 -permalink: /pages/010501010501 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# 内核编码规范 - -- [总体原则](#section9512812145915) -- [目录结构](#section1355317267017) -- [命名](#section1375364815017) -- [注释](#section1692516179119) -- [格式](#section10888536113) -- [宏](#section12276501124) -- [头文件](#section158507231319) -- [数据类型](#section91351731446) -- [变量](#section575493915417) -- [断言](#section13864440410) -- [函数](#section671919481745) - -此规范基于业界通用的编程规范整理而成,请内核的开发人员遵守这样的编程风格。 - -## 总体原则 - -总体原则: - -- 清晰:代码应当易于理解、易于维护、易于重构,避免晦涩语法 -- 简洁:命名简短,函数紧凑 -- 高效:通过使用算法、编译器优化选项或硬件资源提高程序效率 -- 美观:代码风格合理、一致 - -在大部分情况下,开发人员应当遵从以下规范,但也有一些例外场景。如修改第三方开源代码或大量使用开源代码接口下,应当与开源代码保持一致。请依据总体原则,灵活处理。 - -## 目录结构 - -建议按照功能模块划分子目录,子目录再定义头文件和源文件目录。 - -目录名和文件名如果没有特殊的需要,采用全小写的形式,可以使用下划线(“\_”)分割。 - -## 命名 - -推荐使用驼峰风格,具体规则如下: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

类型

-

命名风格

-

形式

-

函数、结构体类型、枚举类型、联合体类型、typedef的类型

-

大驼峰,或带有模块前缀的大驼峰

-

AaaBbb

-

XXX_AaaBbb

-

局部变量,函数参数,宏参数,结构体中字段,联合体中成员

-

小驼峰

-

aaaBBB

-

全局变量

-

带“g_”前缀的小驼峰

-

g_aaaBBB

-

宏(不含函数式宏),枚举值,goto标签

-

全大写,下划线分割

-

AAA_BBB

-

函数式宏

-

全大写下划线分割,或大驼峰,或带有模块前缀的大驼峰

-

AAA_BBB

-

AaaBbb

-

XXX_AaaBbb

-

头文件防止重复的符号

-

以下划线“_”开头以H结尾,中间为文件名的全大写并以下划线分割

-

_AAA_H

-
- -内核对外API建议采用LOS\_ModuleFunc的形式,如果有宾语则建议采用前置的方式,比如: - -``` -LOS_TaskCreate -LOS_MuxLock -``` - -kernel目录下内部模块间的接口使用OsModuleFunc的形式,比如: - -``` -OsTaskScan -OsMuxInit -``` - -## 注释 - -一般的,尽量通过清晰的软件架构,良好的符号命名来提高代码可读性;然后在需要的时候,才辅以注释说明。 - -注释是为了帮助阅读者快速读懂代码,所以要从读者的角度出发,按需注释。 - -注释内容要简洁、明了、无歧义,信息全面且不冗余。 - -文件头部要进行注释,建议注释列出:版权说明、文件功能说明,作者、创建日期、注意事项等。 - -注释风格要统一,建议优先选择/\* \*/的方式,注释符与注释内容之间要有1空格,单行、多行注释风格如下: - -``` -/* 单行注释 */ -// 单行注释 -/* - * 多行注释 - * 第二行 - */ -// 多行注释 -// 另一行 -``` - -针对代码的注释,应该置于对应代码的上方或右方。 - -代码上方的注释,与代码行间无空行,保持与代码一样的缩进。 - -代码右边的注释,与代码之间,至少留1空格。 - -建议将多条连续的右侧注释对齐,比如: - -``` -#define CONST_A 100 /* Const A */ -#define CONST_B 2000 /* Const B */ -``` - -## 格式 - -程序采用缩进风格编写,使用空格而不是制表符(’\\t’)进行缩进,每级缩进为4个空格。 - -换行时,函数左大括号另起一行放行首,并独占一行;其他左大括号跟随语句放行末。右大括号独占一行,除非后面跟着同一语句的剩余部分,如 do 语句中的 while,或者 if 语句的else/else if,或者逗号、分号。 - -一行只写一条语句。 - -比如: - -``` -struct MyType { // 跟随语句放行末,前置1空格 - ... -}; // 右大括号后面紧跟分号 -int Foo(int a) -{ // 函数左大括号独占一行,放行首 - if (a > 0) { - Foo(); // 一行只有一条语句 - Bar(); - } else { // 右大括号、"else"、以及后续的左大括号均在同一行 - ... - } // 右大括号独占一行 - ... -} -``` - -每行字符数不要超过 120 个,代码过长时应当换行,换行时将操作符留在行末,新行缩进一层或进行同类对齐,并将表示未结束的操作符或连接符号留在行末。 - -``` -// 假设下面第一行已经不满足行宽要求 -if (currentValue > MIN && // Good:换行后,布尔操作符放在行末 - currentValue < MAX) { // Good: 与(&&)操作符的两个操作数同类对齐 - DoSomething(); - ... -} -flashPara.flashEndAddr = flashPara.flashBaseAddr + // Good: 加号留在行末 - flashPara.flashSize; // Good: 加法两个操作数对齐 - -// Good:函数参数放在一行 -ReturnType result = FunctionName(paramName1, paramName2); -ReturnType result = FunctionName(paramName1, - paramName2, - paramName3); // Good:保持与上方参数对齐 -ReturnType result = FunctionName(paramName1, paramName2, - paramName3, paramName4, paramName5); // Good:参数换行,4 空格缩进 -ReturnType result = VeryVeryVeryLongFunctionName( // 行宽不满足第1个参数,直接换行 - paramName1, paramName2, paramName3); // 换行后,4 空格缩进 - -// Good:每行的参数代表一组相关性较强的数据结构,放在一行便于理解 -int result = DealWithStructLikeParams(left.x, left.y, // 表示一组相关参数 - right.x, right.y); // 表示另外一组相关参数 -``` - -包括 if/for/while/do-while 语句应使用大括号,即复合语句。 - -``` -while (condition) {} // Good:即使循环体是空,也应使用大括号 -while (condition) { - continue; // Good:continue 表示空逻辑,使用大括号 -} -``` - -case/default 语句相对 switch 缩进一层,风格如下: - -``` -switch (var) { - case 0: // Good: 缩进 - DoSomething1(); // Good: 缩进 - break; - case 1: { // Good: 带大括号格式 - DoSomething2(); - break; - } - default: - break; -} -``` - -指针类型"\*"跟随变量或者函数名,例如: - -``` -int *p1; // OK -int* p2; // Bad:跟随类型 -int*p3; // Bad:两边都没空格 -int * p4; // Bad:两边都有空格 -struct Foo *CreateFoo(void); // OK: "*"跟随函数名 -特例: -char * const VERSION = "V100"; // OK: 当有 const 修饰符时,"*"两边都有空格 -int Foo(const char * restrict p); // OK: 当有 restrict 修饰符时,"*"两边都有空格 -sz = sizeof(int*); // OK:右侧没有变量,"*"跟随类型 -``` - -## 宏 - -定义函数式宏前,应考虑能否用函数替代。对于可替代场景,建议用函数替代宏。对于有性能需求的场景,可以使用内联函数。 - -定义宏时,要使用完备的括号,例如: - -``` -#define SUM(a, b) ((a) + (b)) // 符合本规范要求. -#define SOME_CONST 100 // Good: 单独的数字无需括号 -#define ANOTHER_CONST (-1) // Good: 负数需要使用括号 -#define THE_CONST SOME_CONST // Good: 单独的标识符无需括号 -``` - -以下情况需要注意: - -- 宏参数参与 '\#', '\#\#' 操作时,不要加括号; -- 宏参数参与字符串拼接时,不要加括号; -- 宏参数作为独立部分,在赋值(包括+=, -=等)操作的某一边时,可以不加括号; -- 宏参数作为独立部分,在逗号表达式,函数或宏调用列表中,可以不加括号。 - -``` -// x 不要加括号 -#define MAKE_STR(x) #x - -// obj 不要加括号 -#define HELLO_STR(obj) "Hello, " obj - -// a, b 需要括号;而 value 可以不加括号 -#define UPDATE_VALUE(value, a, b) (value = (a) + (b)) - -// a 需要括号;而 b 可以不加括号 -#define FOO(a, b) Bar((a) + 1, b) -``` - -包含多条语句的函数式宏的实现语句必须放在 do-while\(0\)中。 - -禁止把带副作用的表达式作为参数传递给函数式宏,比如自加操作\(“a++”\)。 - -函数式宏定义中慎用 return、goto、continue、break 等改变程序流程的语句。 - -禁止宏调用参数中出现预编译指令,如\#include,\#define和\#ifdef,这样做会导致未定义的行为。 - -宏定义不以分号结尾。 - -## 头文件 - -头文件应当职责单一。 - -通常情况下,每个.c文件都应有一个相应的.h文件(并不一定同名),用于放置对外提供的函数声明、宏定义、类型定义等。如果不需要提供对外接口,可以没有对应的.h文件。 - -避免头文件循环依赖,如a.h 包含 b.h,b.h 包含 c.h,c.h 包含 a.h。 - -头文件应当自包含,即包含某个头文件,不需要引入其他头文件就可以编译。 - -头文件用\#define、\#ifndef、\#endif保护,防止重复包含;不要使用 \#pragma once。 - -禁止通过声明的方式引用外部函数接口、变量,只能通过包含头文件的方式使用其他模块或文件提供的接口。 - -建议按稳定度包含头文件,依次顺序为: 源码对应的头文件,C标准库,操作系统库,平台库,项目公共库,自己其他的依赖。 - -## 数据类型 - -基础数据类型建议使用los\_compiler.h中定义的类型,比如无符号32位整数位定义为UINT32。 - -## 变量 - -避免大量栈分配,如较大的局部数组。 - -谨慎使用全局变量,尽量不用或少用全局变量。 - -变量应当初始化后再使用。 - -禁止将局部变量的地址返回到其作用域以外。 - -指向资源句柄或描述符的变量,在资源释放后立即赋予新值(如果变量的作用域马上结束可以不赋予新值)。指向资源句柄或描述符的变量包括指针、文件描述符、socket描述符以及其它指向资源的变量。 - -## 断言 - -断言必须使用宏定义,且只能在调试版本中生效。 - -断言应当看作设计约束,禁止用断言检测程序在运行期间可能导致的错误,可能发生的错误要用错误处理代码来处理。 - -禁止在断言内改变运行环境。 - -一个断言只用于检查一个错误。 - -## 函数 - -由一个进程向另一个进程发送的数据、由应用向内核发送的数据等应当进行合法性校验,校验包括但不限于: - -- 校验数据长度 -- 校验数据范围 -- 校验数据类型和格式 -- 校验输入只包含可接受的字符(“白名单”形式) - -函数应避免使用全局变量、静态局部变量和直接的I/O操作,不可避免时,应当对读写操作进行封装。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/05.\351\231\204\345\275\225/02.\345\237\272\346\234\254\346\225\260\346\215\256\347\273\223\346\236\204/01.\345\217\214\345\220\221\351\223\276\350\241\250.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/05.\351\231\204\345\275\225/02.\345\237\272\346\234\254\346\225\260\346\215\256\347\273\223\346\236\204/01.\345\217\214\345\220\221\351\223\276\350\241\250.md" deleted file mode 100644 index b9c4859d8cee2ee343c39eced026a51aaf364b91..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/05.\351\231\204\345\275\225/02.\345\237\272\346\234\254\346\225\260\346\215\256\347\273\223\346\236\204/01.\345\217\214\345\220\221\351\223\276\350\241\250.md" +++ /dev/null @@ -1,204 +0,0 @@ ---- -title: 双向链表 -permalink: /pages/01050101050201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# 双向链表 - -- [基本概念](#section1990715203418) -- [功能说明](#section848334511411) -- [开发流程](#section01781261552) -- [编程实例](#section67569495514) - - [实例描述](#section48761994551) - - [示例代码](#section1280202685519) - - [结果验证](#section5811249105512) - - -## 基本概念 - -双向链表是指含有往前和往后两个方向的链表,即每个结点中除存放下一个节点指针外,还增加一个指向前一个节点的指针。其头指针head是唯一确定的。 - -从双向链表中的任意一个结点开始,都可以很方便地访问它的前驱结点和后继结点,这种数据结构形式使得双向链表在查找时更加方便,特别是大量数据的遍历。由于双向链表具有对称性,能方便地完成各种插入、删除等操作,但需要注意前后方向的操作。 - -## 功能说明 - -双向链表模块为用户提供下面几种功能,接口详细信息可以查看API参考。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名

-

描述

-

初始化链表

-

LOS_ListInit

-

将指定双向链表节点初始化为双向链表

-

LOS_DL_LIST_HEAD

-

定义一个双向链表节点并以该节点初始化为双向链表

-

增加节点

-

LOS_ListAdd

-

将指定节点插入到双向链表头端

-

LOS_ListTailInsert

-

将指定节点插入到双向链表尾端

-

删除节点

-

LOS_ListDelete

-

将指定节点从链表中删除

-

LOS_ListDelInit

-

将指定节点从链表中删除,并使用该节点初始化链表

-

判断双向链表是否为空

-

LOS_ListEmpty

-

判断链表是否为空

-

获取结构体信息

-

LOS_DL_LIST_ENTRY

-

获取包含链表的结构体地址,接口的第一个入参表示的是链表中的某个节点,第二个入参是要获取的结构体名称,第三个入参是链表在该结构体中的名称

-

LOS_OFF_SET_OF

-

获取指定结构体内的成员相对于结构体起始地址的偏移量

-

遍历双向链表

-

LOS_DL_LIST_FOR_EACH

-

遍历双向链表

-

LOS_DL_LIST_FOR_EACH_SAFE

-

遍历双向链表,并存储当前节点的后继节点用于安全校验

-

遍历包含双向链表的结构体

-

LOS_DL_LIST_FOR_EACH_ENTRY

-

遍历指定双向链表,获取包含该链表节点的结构体地址

-

LOS_DL_LIST_FOR_EACH_ENTRY_SAFE

-

遍历指定双向链表,获取包含该链表节点的结构体地址,并存储包含当前节点的后继节点的结构体地址

-
- -## 开发流程 - -双向链表的典型开发流程: - -1. 调用LOS\_ListInit/LOS\_DL\_LIST\_HEAD初始双向链表。 -2. 调用LOS\_ListAdd向链表插入节点。 -3. 调用LOS\_ListTailInsert向链表尾部插入节点。 -4. 调用LOS\_ListDelete删除指定节点。 -5. 调用LOS\_ListEmpty判断链表是否为空。 -6. 调用LOS\_ListDelInit删除指定节点并以此节点初始化链表。 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->- 需要注意节点指针前后方向的操作。 ->- 链表操作接口,为底层接口,不对入参进行判空,需要使用者确保传参合法。 ->- 如果链表节点的内存是动态申请的,删除节点时,要注意释放内存。 - -## 编程实例 - -### 实例描述 - -本实例实现如下功能: - -1. 初始化双向链表。 -2. 增加节点。 -3. 删除节点。 -4. 测试操作是否成功。 - -### 示例代码 - -示例代码如下: - -``` -#include "stdio.h" -#include "los_list.h" - -static UINT32 ListSample(VOID) -{ - LOS_DL_LIST listHead = {NULL,NULL}; - LOS_DL_LIST listNode1 = {NULL,NULL}; - LOS_DL_LIST listNode2 = {NULL,NULL}; - - //首先初始化链表 - printf("Initial head\n"); - LOS_ListInit(&listHead); - - //添加节点1和节点2,并校验他们的相互关系 - LOS_ListAdd(&listHead, &listNode1); - if (listNode1.pstNext == &listHead && listNode1.pstPrev == &listHead) { - printf("Add listNode1 success\n"); - } - - LOS_ListTailInsert(&listHead, &listNode2); - if (listNode2.pstNext == &listHead && listNode2.pstPrev == &listNode1) { - printf("Tail insert listNode2 success\n"); - } - - //删除两个节点 - LOS_ListDelete(&listNode1); - LOS_ListDelete(&listNode2); - - //确认链表为空 - if (LOS_ListEmpty(&listHead)) { - printf("Delete success\n"); - } - - return LOS_OK; -} -``` - -### 结果验证 - -编译运行得到的结果为: - -``` -Initial head -Add listNode1 success -Tail insert listNode2 success -Delete success -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/05.\351\231\204\345\275\225/03.\346\240\207\345\207\206\345\272\223\346\224\257\346\214\201/01.CMSIS\346\224\257\346\214\201.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/05.\351\231\204\345\275\225/03.\346\240\207\345\207\206\345\272\223\346\224\257\346\214\201/01.CMSIS\346\224\257\346\214\201.md" deleted file mode 100644 index 7a945fecf5aa6c9ae98524e07fc9a8a4a8390001..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/05.\351\231\204\345\275\225/03.\346\240\207\345\207\206\345\272\223\346\224\257\346\214\201/01.CMSIS\346\224\257\346\214\201.md" +++ /dev/null @@ -1,500 +0,0 @@ ---- -title: CMSIS支持 -permalink: /pages/01050101050301 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# CMSIS支持 - -- [基本概念](#section131091144111615) -- [开发指导](#section57653573161) - - [接口说明](#section1795910417173) - - [开发流程](#section48301225131720) - - [编程实例](#section524434761713) - - -## 基本概念 - -[CMSIS](https://developer.arm.com/tools-and-software/embedded/cmsis)是Cortex Microcontroller Software Interface Standard(Cortex微控制器软件接口标准)的缩写,是对于那些基于ARM Cortex处理器的微控制器独立于供应商的硬件抽象层。它包含多个组件层,其中之一是RTOS层,该层定义了一套通用及标准化的RTOS API接口,减少了应用开发者对特定RTOS的依赖,方便用户软件的移植重用。该套API有2个版本,分别为版本1(CMSIS-RTOS v1)和版本2(CMSIS-RTOS v2),OpenHarmony LiteOS-M仅提供其版本2的实现。 - -## 开发指导 - -### 接口说明 - -CMSIS-RTOS v2提供下面几种功能,接口详细信息可以查看API参考。 - -**表 1** CMSIS-RTOS v2接口 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名

-

描述

-

内核信息与控制

-

osKernelGetInfo

-

获取RTOS内核信息。

-

osKernelGetState

-

获取当前的RTOS内核状态。

-

osKernelGetSysTimerCount

-

获取RTOS内核系统计时器计数。

-

osKernelGetSysTimerFreq

-

获取RTOS内核系统计时器频率。

-

osKernelInitialize

-

初始化RTOS内核。

-

osKernelLock

-

锁定RTOS内核调度程序。

-

osKernelUnlock

-

解锁RTOS内核调度程序。

-

osKernelRestoreLock

-

恢复RTOS内核调度程序锁定状态。

-

osKernelResume

-

恢复RTOS内核调度程序。(暂未实现)

-

osKernelStart

-

启动RTOS内核调度程序。

-

osKernelSuspend

-

挂起RTOS内核调度程序。(暂未实现)

-

osKernelGetTickCount

-

获取RTOS内核滴答计数。

-

osKernelGetTickFreq

-

获取RTOS内核滴答频率。

-

线程管理

-

osThreadDetach

-

分离线程(线程终止时可以回收线程存储)。(暂未实现)

-

osThreadEnumerate

-

枚举活动线程。(暂未实现)

-

osThreadExit

-

终止当前正在运行的线程的执行。

-

osThreadGetCount

-

获取活动线程的数量。

-

osThreadGetId

-

返回当前正在运行的线程的线程ID。

-

osThreadGetName

-

获取线程的名称。

-

osThreadGetPriority

-

获取线程的当前优先级。

-

osThreadGetStackSize

-

获取线程的堆栈大小。

-

osThreadGetStackSpace

-

根据执行期间的堆栈水印记录获取线程的可用堆栈空间。

-

osThreadGetState

-

获取线程的当前线程状态。

-

osThreadJoin

-

等待指定线程终止。(暂未实现)

-

osThreadNew

-

创建一个线程并将其添加到活动线程中。

-

osThreadResume

-

恢复线程的执行。

-

osThreadSetPriority

-

更改线程的优先级。

-

osThreadSuspend

-

暂停执行线程。

-

osThreadTerminate

-

终止线程的执行。

-

osThreadYield

-

将控制权传递给处于就绪状态的下一个线程。

-

线程标志

-

osThreadFlagsSet

-

设置线程的指定线程标志。(暂未实现)

-

osThreadFlagsClear

-

清除当前正在运行的线程的指定线程标志。(暂未实现)

-

osThreadFlagsGet

-

获取当前正在运行的线程的当前线程标志。(暂未实现)

-

osThreadFlagsWait

-

等待当前正在运行的线程的一个或多个线程标志发出信号。(暂未实现)

-

事件标志

-

osEventFlagsGetName

-

获取事件标志对象的名称。(暂未实现)

-

osEventFlagsNew

-

创建并初始化事件标志对象。

-

osEventFlagsDelete

-

删除事件标志对象。

-

osEventFlagsSet

-

设置指定的事件标志。

-

osEventFlagsClear

-

清除指定的事件标志。

-

osEventFlagsGet

-

获取当前事件标志。

-

osEventFlagsWait

-

等待一个或多个事件标志被发出信号。

-

通用等待函数

-

osDelay

-

等待超时(时间延迟)。

-

osDelayUntil

-

等到指定时间。

-

计时器管理

-

osTimerDelete

-

删除计时器。

-

osTimerGetName

-

获取计时器的名称。(暂未实现)

-

osTimerIsRunning

-

检查计时器是否正在运行。

-

osTimerNew

-

创建和初始化计时器。

-

osTimerStart

-

启动或重新启动计时器。

-

osTimerStop

-

停止计时器。

-

互斥管理

-

osMutexAcquire

-

获取互斥或超时(如果已锁定)。

-

osMutexDelete

-

删除互斥对象。

-

osMutexGetName

-

获取互斥对象的名称。(暂未实现)

-

osMutexGetOwner

-

获取拥有互斥对象的线程。

-

osMutexNew

-

创建并初始化Mutex对象。

-

osMutexRelease

-

释放由osMutexAcquire获取的Mutex。

-

信号量

-

osSemaphoreAcquire

-

获取信号量令牌或超时(如果没有可用的令牌)。

-

osSemaphoreDelete

-

删除一个信号量对象。

-

osSemaphoreGetCount

-

获取当前信号量令牌计数。

-

osSemaphoreGetName

-

获取信号量对象的名称。(暂未实现)

-

osSemaphoreNew

-

创建并初始化一个信号量对象。

-

osSemaphoreRelease

-

释放信号量令牌,直到初始最大计数。

-

内存池

-

osMemoryPoolAlloc

-

从内存池分配一个内存块。

-

osMemoryPoolDelete

-

删除内存池对象。

-

osMemoryPoolFree

-

将分配的内存块返回到内存池。

-

osMemoryPoolGetBlockSize

-

获取内存池中的内存块大小。

-

osMemoryPoolGetCapacity

-

获取内存池中最大的内存块数。

-

osMemoryPoolGetCount

-

获取内存池中使用的内存块数。

-

osMemoryPoolGetName

-

获取内存池对象的名称。

-

osMemoryPoolGetSpace

-

获取内存池中可用的内存块数。

-

osMemoryPoolNew

-

创建并初始化一个内存池对象。

-

消息队列

-

osMessageQueueDelete

-

删除消息队列对象。

-

osMessageQueueGet

-

从队列获取消息,或者如果队列为空,则从超时获取消息。

-

osMessageQueueGetCapacity

-

获取消息队列中的最大消息数。

-

osMessageQueueGetCount

-

获取消息队列中排队的消息数。

-

osMessageQueueGetMsgSize

-

获取内存池中的最大消息大小。

-

osMessageQueueGetName

-

获取消息队列对象的名称。(暂未实现)

-

osMessageQueueGetSpace

-

获取消息队列中消息的可用插槽数。

-

osMessageQueueNew

-

创建和初始化消息队列对象。

-

osMessageQueuePut

-

如果队列已满,则将消息放入队列或超时。

-

osMessageQueueReset

-

将消息队列重置为初始空状态。(暂未实现)

-
- -### 开发流程 - -CMSIS-RTOS2组件可以作为库或源代码提供(下图显示了库)。通过添加CMSIS-RTOS2组件(通常是一些配置文件),可以将基于CMSIS的应用程序扩展为具有RTOS功能。只需包含cmsis\_os2.h头文件就可以访问RTOS API函数,这使用户应用程序能够处理RTOS内核相关事件,而在更换内核时无需重新编译源代码。 - -静态对象分配需要访问RTOS对象控制块定义。特定于实现的头文件(下图中的os\_xx .h)提供对此类控制块定义的访问。对于OpenHarmony LiteOS-M内核,由文件名以los\_开头的头文件提供,这些文件包含OpenHarmony LiteOS-M内核的这些定义。 - -![](/images/device-dev/kernel/figure/zh-cn_image_0000001132778524.png) - -### 编程实例 - -``` -#include ... -#include "cmsis_os2.h" - -/*---------------------------------------------------------------------------- - * 应用程序主线程 - *---------------------------------------------------------------------------*/ -void app_main (void *argument) { - // ... - for (;;) {} -} - -int main (void) { - // 系统初始化 - MySystemInit(); - // ... - - osKernelInitialize(); // 初始化CMSIS-RTOS - osThreadNew(app_main, NULL, NULL); // 创建应用程序主线程 - osKernelStart(); // 开始执行线程 - for (;;) {} -} -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/05.\351\231\204\345\275\225/03.\346\240\207\345\207\206\345\272\223\346\224\257\346\214\201/02.POSIX\346\224\257\346\214\201.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/05.\351\231\204\345\275\225/03.\346\240\207\345\207\206\345\272\223\346\224\257\346\214\201/02.POSIX\346\224\257\346\214\201.md" deleted file mode 100644 index c1f7c3c1ae9e59af93770cbddbb7d36f4ec56ad5..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/01.\350\275\273\351\207\217\347\263\273\347\273\237\345\206\205\346\240\270/05.\351\231\204\345\275\225/03.\346\240\207\345\207\206\345\272\223\346\224\257\346\214\201/02.POSIX\346\224\257\346\214\201.md" +++ /dev/null @@ -1,1651 +0,0 @@ ---- -title: POSIX支持 -permalink: /pages/01050101050302 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# POSIX支持 - -- [基本概念](#section1757915134139) -- [开发指导](#section1573664211318) - - [接口说明](#section10429150121317) - - [注意事项](#section109174418147) - - [编程实例](#section206149278155) - - -## 基本概念 - -OpenHarmony内核使用**musl libc**库以及自研接口,支持部分标准POSIX接口,开发者可基于POSIX标准接口开发内核之上的组件及应用。 - -## 开发指导 - -### 接口说明 - -**表 1** POSIX接口说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

类别

-

需要包含的头文件

-

接口名

-

描述

-

process

-

#include <stdlib.h>

-

void abort(void);

-

中止线程执行

-

#include <assert.h>

-

void assert(scalar expression);

-

断言为假终止线程

-

#include <pthread.h>

-

int pthread_cond_destroy(pthread_cond_t *cond);

-

销毁条件变量

-

#include <pthread.h>

-

int pthread_cond_init(pthread_cond_t *restrict cond, const pthread_condattr_t *restrict attr);

-

初始化条件变量

-

#include <pthread.h>

-

int pthread_cond_timedwait(pthread_cond_t *restrict cond, pthread_mutex_t *restrict mutex, const struct timespec *restrict abstime);

-

等待条件

-

#include <pthread.h>

-

int pthread_condattr_init(pthread_condattr_t *attr);

-

初始化条件变量属性对象

-

#include <pthread.h>

-

int pthread_mutex_unlock(pthread_mutex_t *mutex);

-

解锁互斥锁

-

#include <pthread.h>

-

int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg);

-

创建一个新的线程

-

#include <pthread.h>

-

int pthread_join(pthread_t thread, void **retval);

-

等待指定的线程结束

-

#include <pthread.h>

-

pthread_t pthread_self(void);

-

获取当前线程的ID

-

#include <pthread.h>

-

int pthread_getschedparam(pthread_t thread, int *policy, struct sched_param *param);

-

获取线程的调度策略和参数

-

#include <pthread.h>

-

int pthread_setschedparam(pthread_t thread, int policy, const struct sched_param *param);

-

设置线程的调度策略和参数

-

#include <pthread.h>

-

int pthread_mutex_init(pthread_mutex_t *__restrict m, const pthread_mutexattr_t *__restrict a);

-

初始化互斥锁

-

#include <pthread.h>

-

int pthread_mutex_lock(pthread_mutex_t *m);

-

互斥锁加锁操作

-

#include <pthread.h>

-

int pthread_mutex_trylock(pthread_mutex_t *m);

-

互斥锁尝试加锁操作

-

#include <pthread.h>

-

int pthread_mutex_destroy(pthread_mutex_t *m);

-

销毁互斥锁

-

#include <pthread.h>

-

int pthread_attr_init(pthread_attr_t *attr);

-

初始化线程属性对象

-

#include <pthread.h>

-

int pthread_attr_destroy(pthread_attr_t *attr);

-

销毁线程属性对象

-

#include <pthread.h>

-

int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize);

-

获取线程属性对象的堆栈大小

-

#include <pthread.h>

-

int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize);

-

设置线程属性对象的堆栈大小

-

#include <pthread.h>

-

int pthread_attr_getschedparam(const pthread_attr_t *attr, struct sched_param *param);

-

获取线程属性对象的调度参数属性

-

#include <pthread.h>

-

int pthread_attr_setschedparam(pthread_attr_t *attr, const struct sched_param *param);

-

设置线程属性对象的调度参数属性

-

#include <pthread.h>

-

int pthread_getname_np(pthread_t pthread, char *name, size_t len);

-

获取线程名称

-

#include <pthread.h>

-

int pthread_setname_np(pthread_t pthread, const char *name);

-

设置线程名称

-

#include <pthread.h>

-

int pthread_cond_broadcast(pthread_cond_t *c);

-

解除若干已被等待条件阻塞的线程

-

#include <pthread.h>

-

int pthread_cond_signal(pthread_cond_t *c);

-

解除被阻塞的线程

-

#include <pthread.h>

-

int pthread_cond_wait(pthread_cond_t *__restrict c, pthread_mutex_t *__restrict m);

-

等待条件

-

fs

-

-

#include <libgen.h>

-

char *dirname(char *path);

-

获取目录名

-

#include <dirent.h>

-

struct dirent *readdir(DIR *dirp);

-

读目录

-

#include <sys/stat.h>

-

int stat(const char *restrict path, struct stat *restrict buf);

-

获取文件信息

-

#include <unistd.h>

-

int unlink(const char *pathname);

-

删除文件

-

#include <fcntl.h>

-

int open(const char *path, int oflags, ...);

-

用于打开文件,如文件不存在,创建文件并打开

-

#include <nistd.h>

-

int close(int fd);

-

关闭文件

-

#include <stdio.h>

-

int rename(const char *oldpath, const char *newpath);

-

重命名指定的文件

-

#include <dirent.h>

-

DIR *opendir(const char *dirname);

-

打开指定目录

-

#include <dirent.h>

-

int closedir(DIR *dir);

-

关闭指定目录

-

#include <sys/mount.h>

-

int mount(const char *source, const char *target, const char *filesystemtype, unsigned long mountflags, const void *data);

-

挂载文件系统

-

#include <sys/mount.h>

-

int umount(const char *target);

-

卸载文件系统

-

#include <sys/mount.h>

-

int umount2(const char *target, int flag);

-

卸载文件系统

-

#include <sys/stat.h>

-

int fsync(int fd);

-

将与指定文件描述符关联的文件同步到存储设备

-

#include <sys/stat.h>

-

int mkdir(const char *pathname, mode_t mode);

-

创建目录

-

#include <unistd.h>

-

int rmdir(const char *path);

-

删除目录

-

#include <sys/stat.h>

-

int fstat(int fd, struct stat *buf);

-

获取文件状态信息

-

#include <sys/statfs.h>

-

int statfs(const char *path, struct statfs *buf);

-

获取指定路径下文件的文件系统信息

-

time

-

#include <sys/time.h>

-

int gettimeofday(struct timeval *tv, struct timezone *tz);

-

获取时间。当前暂无时区概念,tz返回为空

-

#include <time.h>

-

struct tm *gmtime(const time_t *timep);

-

将日期和时间转换为细分时间或ASCII

-

#include <time.h>

-

struct tm *localtime(const time_t *timep);

-

获取时间

-

#include <time.h>

-

struct tm *localtime_r(const time_t *timep, struct tm *result);

-

获取时间

-

#include <time.h>

-

time_t mktime(struct tm *tm);

-

将日期和时间转换为细分时间或ASCII

-

#include <time.h>

-

size_t strftime(char *s, size_t max, const char *format,const struct tm *tm);

-

格式化日期和时间字符串

-

#include <time.h>

-

time_t time(time_t *tloc);

-

获得日历时间

-

#include <sys/times.h>

-

clock_t times(struct tms *buf);

-

获取线程时间

-

#include <unistd.h>

-

int usleep(useconds_t usec);

-

休眠(微秒单位)

-

#include <time.h>

-

int nanosleep(const struct timespec *tspec1, struct timespec *tspec2);

-

暂停当前线程直到指定的时间到达

-

#include <time.h>

-

int clock_gettime(clockid_t id, struct timespec *tspec);

-

获取时钟的时间

-

#include <time.h>

-

int timer_create(clockid_t id, struct sigevent *__restrict evp, timer_t *__restrict t);

-

为线程创建计时器

-

#include <time.h>

-

int timer_delete(timer_t t);

-

为线程删除计时器

-

#include <time.h>

-

int timer_settime(timer_t t, int flags, const struct itimerspec *__restrict val, struct itimerspec *__restrict old);

-

为线程设置计时器

-

#include <time.h>

-

time_t time (time_t *t);

-

获取时间

-

#include <time.h>

-

char *strptime(const char *s, const char *format, struct tm *tm);

-

将时间的字符串表示形式转换为时间tm结构

-

util

-

#include <stdlib.h>

-

int atoi(const char *nptr);

-

字符串转换整型(int)

-

#include <stdlib.h>

-

long atol(const char *nptr);

-

字符串转换整型(long)

-

#include <stdlib.h>

-

long long atoll(const char *nptr);

-

字符串转换整型(long long)

-

#include <ctype.h>

-

int isalnum(int c);

-

检查字母数字字符

-

#include <ctype.h>

-

int isascii(int c);

-

检查ASCII

-

#include <ctype.h>

-

int isdigit(int c);

-

检查数字字符

-

#include <ctype.h>

-

int islower(int c);

-

检查小写字符

-

#include <ctype.h>

-

int isprint(int c);

-

检查任何可打印字符,包括空格

-

#include <ctype.h>

-

int isspace(int c);

-

检查空格字符

-

#include <ctype.h>

-

int isupper(int c);

-

检查所传的字符是否是大写字母

-

#include <ctype.h>

-

int isxdigit(int c);

-

判断字符是否为十六进制数

-

#include <stdlib.h>

-

long int random (void);

-

生成伪随机数

-

#include <stdlib.h>

-

void srandom(unsigned int seed);

-

初始化随机数生成器

-

#include <ctype.h>

-

int tolower(int c);

-

字母转换成小写

-

#include <ctype.h>

-

int toupper(int c);

-

字母转换成大写

-

#include <stdarg.h>

-

type va_arg(va_list ap, type);

-

获取可变参数的当前参数,返回指定类型并将指针指向下一参数

-

#include <stdarg.h>

-

void va_copy(va_list dest, va_list src);

-

复制参数

-

#include <stdarg.h>

-

void va_end(va_list ap);

-

清空va_list可变参数列表

-

#include <stdarg.h>

-

void va_start(va_list ap, last);

-

定义变长参数列表的起始位置

-

#include <string.h>

-

char *strchr(const char *s, int c);

-

在字符串中定位字符

-

#include <string.h>

-

int strcmp(const char *s1, const char *s2);

-

比较字符串

-

#include <string.h>

-

size_t strcspn(const char *s, const char *reject);

-

获取前缀子串的长度

-

#include <string.h>

-

char *strdup(const char *s);

-

字符串拷贝到新建的位置处

-

#include <string.h>

-

size_t strlen(const char *s);

-

计算字符串长度

-

#include <strings.h>

-

int strncasecmp(const char *s1, const char *s2, size_t n);

-

比较固定长度字符串(忽略大小写)

-

#include <strings.h>

-

int strcasecmp(const char *s1, const char *s2);

-

比较字符串(忽略大小写)

-

#include <string.h>

-

int strncmp(const char *s1, const char *s2, size_t n);

-

比较字符串(指定长度)

-

#include <string.h>

-

char *strrchr(const char *s, int c);

-

在字符串中定位字符

-

#include <string.h>

-

char *strstr(const char *haystack, const char *needle);

-

寻找指定的子串

-

#include <stdlib.h>

-

long int strtol(const char *nptr, char **endptr, int base);

-

将字符串转换为long型整数

-

#include <stdlib.h>

-

unsigned long int strtoul(const char *nptr, char **endptr, int base);

-

将字符串转换为unsigned long型整数

-

#include <stdlib.h>

-

unsigned long long int strtoull(const char *nptr, char **endptr,int base);

-

将字符串转换为unsigned long long型整数

-

#include <regex.h>

-

int regcomp(regex_t *preg, const char *regex, int cflags);

-

编译正则表达式

-

#include <regex.h>

-

int regexec(const regex_t *preg, const char *string, size_t nmatch,regmatch_t pmatch[], int eflags);

-

匹配正则表达式

-

#include <regex.h>

-

void regfree(regex_t *preg);

-

释放正则表达式

-

#include <string.h>

-

char *strerror(int errnum);

-

返回描述错误号的字符串

-

math

-

#include <stdlib.h>

-

int abs(int i);

-

取绝对值

-

#include <math.h>

-

double log(double x);

-

自然对数函数

-

#include <math.h>

-

double pow(double x, double y);

-

求x的指数y次幂

-

#include <math.h>

-

double round(double x);

-

从零开始,舍入到最接近的整数

-

#include <math.h>

-

double sqrt(double x);

-

平方根

-

IO

-

#include <stdio.h>

-

void clearerr(FILE *stream);

-

清除流的文件结尾和错误指示

-

#include <stdio.h>

-

int fclose(FILE *stream);

-

关闭文件流

-

#include <stdio.h>

-

FILE *fdopen(int fd, const char *mode);

-

通过文件描述符打开文件流

-

#include <stdio.h>

-

int feof(FILE *stream);

-

检测返回文件末尾指示位

-

#include <stdio.h>

-

int fflush(FILE *stream);

-

刷新流

-

#include <stdio.h>

-

char *fgets(char *s, int size, FILE *stream);

-

读取流的下一行

-

#include <stdio.h>

-

int fileno(FILE *stream);

-

返回流的文件描述符

-

#include <stdio.h>

-

FILE *fopen(const char *path, const char *mode);

-

打开流

-

#include <stdio.h>

-

int fputs(const char *s, FILE *stream);

-

向指定流写入一行

-

#include <stdio.h>

-

size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);

-

读一个流

-

#include <stdio.h>

-

int fseek(FILE *stream, long offset, int whence);

-

设置流指针的位置

-

#include <stdio.h>

-

long ftell(FILE *stream);

-

获取流指针的位置

-

#include <stdio.h>

-

size_t fwrite(const void *ptr, size_t size, size_t nmemb,FILE *stream);

-

向流写入

-

#include <stdio.h>

-

void perror(const char *s);

-

打印系统错误信息

-

#include <stdio.h>

-

void rewind(FILE *stream);

-

重新定位流

-

#include <unistd.h>

-

ssize_t write(int fd, const void *buf, size_t size);

-

写文件内容

-

#include <unistd.h>

-

ssize_t read(int fd, void *buf, size_t size);

-

读文件内容

-

net

-

#include <sys/socket.h>

-

void freeaddrinfo(struct addrinfo *res);

-

释放调用getaddrinfo所分配的动态内存

-

#include <sys/socket.h>

-

int getaddrinfo(const char *restrict nodename,const char *restrict servname,const struct addrinfo *restrict hints,struct addrinfo **restrict res);

-

网络地址和服务转换

-

#include <sys/socket.h>

-

int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen,char *restrict node, socklen_t nodelen, char *restrict service,socklen_t servicelen, int flags);

-

以协议无关的方式进行地址到名称的转换

-

#include <net/if.h>

-

unsigned int if_nametoindex(const char *ifname);

-

通过网络接口名得到索引

-

#include <arpa/inet.h>

-

in_addr_t inet_addr(const char *cp);

-

网络主机地址点分十进制形式转换位二进制形式

-

#include <arpa/inet.h>

-

char *inet_ntoa(struct in_addr in);

-

网络主机地址二进制形式转换位点分十进制形式

-

#include <arpa/inet.h>

-

const char *inet_ntop(int af, const void *src,char *dst, socklen_t size);

-

网络地址转换

-

#include <arpa/inet.h>

-

int inet_pton(int af, const char *src, void *dst);

-

网络地址转换

-

#include <sys/socket.h>

-

int listen(int sockfd, int backlog);

-

监听套接字

-

#include <sys/socket.h>

-

ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags);

-

从套接字接收消息.只支持iov大小为1的场景,且不支持ancillary消息

-

#include <sys/socket.h>

-

ssize_t send(int sockfd, const void *buf, size_t len, int flags);

-

从socket发送消息

-

#include <sys/socket.h>

-

ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags);

-

从socket发送消息。不支持ancillary消息

-

#include <sys/socket.h>

-

ssize_t sendto(int sockfd, const void *buf, size_t len, int flags,const struct sockaddr *dest_addr, socklen_t addrlen);

-

从socket发送消息

-

#include <sys/socket.h>

-

int setsockopt(int sockfd, int level, int optname,const void *optval, socklen_t optlen);

-

设置与套接字关联的选项

-

mem

-

#include <string.h>

-

int memcmp(const void *s1, const void *s2, size_t n);

-

内存比较

-

#include <string.h>

-

void *memcpy(void *dest, const void *src, size_t n);

-

内存拷贝

-

#include <string.h>

-

void *memset(void *s, int c, size_t n);

-

内存初始化

-

#include <stdlib.h>

-

void *realloc(void *ptr, size_t size);

-

重分配内存

-

#include <stdlib.h>

-

void *malloc(size_t size);

-

动态分配内存块大小

-

#include <stdlib.h>

-

void free(void *ptr);

-

释放ptr所指向的内存空间

-

IPC

-

#include <semaphore.h>

-

int sem_timedwait(sem_t *sem, const struct timespec *abs_timeout);

-

计时锁定信号量

-

#include <semaphore.h>

-

int sem_destroy(sem_t *sem);

-

销毁指定的无名信号量

-

#include <semaphore.h>

-

int sem_init(sem_t *sem, int pshared, unsigned int value);

-

创建并初始化一个无名信号量

-

#include <semaphore.h>

-

int sem_post(sem_t *sem);

-

增加信号量计数

-

#include <semaphore.h>

-

int sem_wait(sem_t *sem);

-

获取信号量

-

#include <mqueue.h>

-

mqd_t mq_open(const char *mqName, int openFlag, ...);

-

此API用于打开一个具有指定名称的已有消息队列或创建一个新的消息队列

-

#include <mqueue.h>

-

int mq_close(mqd_t personal);

-

此API用于关闭具有指定描述符的消息队列

-

#include <mqueue.h>

-

int mq_unlink(const char *mqName);

-

此API用于删除具有指定名称的消息队列

-

#include <mqueue.h>

-

int mq_send(mqd_t personal, const char *msg, size_t msgLen, unsigned int msgPrio);

-

此API用于将具有指定内容和长度的消息放入具有指定描述符的消息队列中

-

#include <mqueue.h>

-

ssize_t mq_receive(mqd_t personal, char *msg, size_t msgLen, unsigned int *msgPrio);

-

此API用于从具有指定描述符的消息队列中删除最老的消息,并将其放入msg_ptr所指向的缓冲区中

-

#include <mqueue.h>

-

int mq_timedsend(mqd_t personal, const char *msg, size_t msgLen, unsigned int msgPrio, const struct timespec *absTimeout)

-

此API用于在预定时间将具有指定内容和长度的消息放入具有描述符的消息队列中

-

#include <mqueue.h>

-

ssize_t mq_timedreceive(mqd_t personal, char *msg, size_t msgLen, unsigned int *msgPrio, const struct timespec *absTimeout);

-

此API用于从具有指定描述符的消息队列消息中获取具有指定消息内容和长度的消息

-

#include <mqueue.h>

-

int mq_setattr(mqd_t mqdes, const struct mq_attr *__restrict newattr, struct mq_attr *__restrict oldattr);

-

设置描述符指定的消息队列属性

-

version

-

#include <libc.h>

-

const char *libc_get_version_string(void);

-

获取libc版本字符串

-

#include <libc.h>

-

int libc_get_version(void);

-

获取libc版本号

-
- -### 注意事项 - -常用错误码对照表: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

C Name

-

Value

-

Description

-

含义

-

ENOERR

-

0

-

Success

-

成功

-

EPERM

-

1

-

Operation not permitted

-

操作不允许

-

ENOENT

-

2

-

No such file or directory

-

没有这样的文件或目录

-

ESRCH

-

3

-

No such process

-

没有这样的进程(暂不支持)

-

EINTR

-

4

-

Interrupted system call

-

系统调用被中断

-

EIO

-

5

-

I/O error

-

I/O错误

-

ENXIO

-

6

-

No such device or address

-

没有这样的设备或地址

-

E2BIG

-

7

-

Arg list too long

-

参数列表太长

-

ENOEXEC

-

8

-

Exec format error

-

执行格式错误

-

EBADF

-

9

-

Bad file number

-

坏的文件描述符

-

ECHILD

-

10

-

No child processes

-

没有子进程(暂不支持)

-

EAGAIN

-

11

-

Try again

-

资源暂时不可用

-

ENOMEM

-

12

-

Out of memory

-

内存溢出

-

EACCES

-

13

-

Permission denied

-

拒绝许可

-

EFAULT

-

14

-

Bad address

-

错误的地址

-

ENOTBLK

-

15

-

Block device required

-

块设备请求

-

EBUSY

-

16

-

Device or resource busy

-

设备或资源忙

-

EEXIST

-

17

-

File exists

-

文件存在

-

EXDEV

-

18

-

Cross-device link

-

无效的交叉链接

-

ENODEV

-

19

-

No such device

-

设备不存在

-

ENOTDIR

-

20

-

Not a directory

-

不是一个目录

-

EISDIR

-

21

-

Is a directory

-

是一个目录

-

EINVAL

-

22

-

Invalid argument

-

无效的参数

-

ENFILE*

-

23

-

File table overflow

-

打开太多的文件系统

-

EMFILE

-

24

-

Too many open files

-

打开的文件过多

-

EFBIG

-

27

-

File too large

-

文件太大

-

ENOSPC

-

28

-

No space left on device

-

设备上没有空间

-

ESPIPE

-

29

-

Illegal seek

-

非法移位

-

EROFS

-

30

-

Read-only file system

-

只读文件系统

-

EMLINK

-

31

-

Too many links

-

太多的链接

-

EDOM

-

33

-

Math argument out of domain

-

数值结果超出范围

-

ERANGE

-

34

-

Math result not representable

-

数值结果不具代表性

-

EDEADLK

-

35

-

Resource deadlock would occur

-

资源死锁错误

-

ENAMETOOLONG

-

36

-

Filename too long

-

文件名太长

-

ENOLCK

-

37

-

No record locks available

-

没有可用锁

-

ENOSYS

-

38

-

Function not implemented

-

功能没有实现

-

ENOTEMPTY

-

39

-

Directory not empty

-

目录不空

-

ELOOP

-

40

-

Too many symbolic links encountered

-

符号链接层次太多

-

ENOMSG

-

42

-

No message of desired type

-

没有期望类型的消息

-

EIDRM

-

43

-

Identifier removed

-

标识符删除

-

ELNRNG

-

48

-

Link number out of range

-

链接数超出范围

-

EBADR

-

53

-

Invalid request descriptor

-

请求描述符无效

-

EBADRQC

-

56

-

Invalid request code

-

无效的请求代码

-

ENOSTR

-

60

-

Device not a stream

-

设备不是字符流

-

ENODATA

-

61

-

No data available

-

无可用数据

-

ETIME

-

62

-

Timer expired

-

计时器过期

-

EPROTO

-

71

-

Protocol error

-

协议错误

-

EBADMSG

-

74

-

Not a data message

-

非数据消息

-

EOVERFLOW

-

75

-

Value too large for defined data type

-

值太大,对于定义数据类型

-

EMSGSIZE

-

90

-

Message too long

-

消息太长

-
- -### 编程实例 - -demo功能: - -创建一个线程并将父线程中的信息传递给子线程,在子线程中打印传递过来的信息和自身线程id值。 - -``` -#include -#include - -pthread_t ntid; - -void *ThreadFn(void *arg) -{ - pthread_t tid; - while(1) { - tid = pthread_self(); - printf("\n++++++++++++++ %s %s tid = %d ++++++++++++++\n", (char*)arg, __FUNCTION__, tid); - } - return ((void *)0); -} - -void DemoForTest() -{ - int err; - char* str = "Hello world"; - err = pthread_create(&ntid, NULL, ThreadFn, (void*)str); - if(err != 0) { - printf("can't create thread\n"); - } -} - -``` - -执行DemoForTest运行结果如下: - -``` -++++++++++++++ Hello world ThreadFn tid = 48 ++++++++++++++ - -++++++++++++++ Hello world ThreadFn tid = 48 ++++++++++++++ - -++++++++++++++ Hello world ThreadFn tid = 48 ++++++++++++++ -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/01.\345\206\205\346\240\270\346\246\202\350\277\260.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/01.\345\206\205\346\240\270\346\246\202\350\277\260.md" deleted file mode 100644 index aed26e1d436f1f216f05ff7d6955f88b7ae9c4d7..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/01.\345\206\205\346\240\270\346\246\202\350\277\260.md" +++ /dev/null @@ -1,110 +0,0 @@ ---- -title: 内核概述 -permalink: /pages/0105010201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# 内核概述 - -- [简介](#section6614133913129) -- [内核架构](#section827143517385) - -## 简介 - -OpenHarmony 轻量级内核是基于IoT领域轻量级物联网操作系统Huawei LiteOS内核演进发展的新一代内核,包含LiteOS-M和LiteOS-A两类内核。LiteOS-M内核主要应用于轻量系统,面向的MCU一般是百K级内存,可支持MPU隔离,业界类似的内核有FreeRTOS或ThreadX等;LiteOS-A内核主要应用于小型系统,面向设备一般是M级内存,可支持MMU隔离,业界类似的内核有Zircon或Darwin等。本开发指南适用于LiteOS-A内核。 - -为适应IoT产业的高速发展,OpenHarmony 轻量级内核不断优化和扩展,能够带给应用开发者友好的开发体验和统一开放的生态系统能力。轻量级内核LiteOS-A重要的新特性如下: - -- 新增了丰富的内核机制 - - 新增虚拟内存、系统调用、多核、轻量级IPC(Inter-Process Communication,进程间通信)、DAC(Discretionary Access Control,自主访问控制)等机制,丰富了内核能力;为了更好的兼容软件和开发者体验,新增支持多进程,使得应用之间内存隔离、相互不影响,提升系统的健壮性。 - -- 引入统一驱动框架HDF(Hardware Driver Foundation) - - 引入统一驱动框架HDF,统一驱动标准,为设备厂商提供了更统一的接入方式,使驱动更加容易移植,力求做到一次开发,多系统部署。 - -- 支持1200+标准POSIX接口 - - 更加全面的支持POSIX标准接口,使得应用软件易于开发和移植,给应用开发者提供了更友好的开发体验。 - -- 内核和硬件高解耦 - - 轻量级内核与硬件高度解耦,新增单板,内核代码不用修改。 - - -## 内核架构 - -轻量级内核主要由基础内核、扩展组件、HDF框架、POSIX接口组成。轻量级内核的文件系统、网络协议等扩展功能(没有像微内核那样运行在用户态)运行在内核地址空间,主要考虑组件之间直接函数调用比进程间通信或远程过程调用要快得多。 - -**图 1** OpenHarmony LiteOS-A内核架构图 - - -![](/images/device-dev/kernel/figure/zh-cn_image_0000001191018697.png) - -- 基础内核主要包括内核的基础机制,如调度、内存管理、中断异常等 -- 扩展组件主要包括文件系统、网络协议和安全等扩展功能 -- HDF框架是外设驱动统一标准框架 -- POSIX接口是为兼容POSIX标准的应用方便移植到OpenHarmony - -**基础内核** - -基础内核组件实现精简,主要包括内核的基础机制,如调度、内存管理、中断异常、内核通信等; - -- 进程管理:支持进程和线程,基于Task实现进程,进程独立4GiB地址空间 -- 多核调度:支持任务和中断亲核性设置,支持绑核运行 -- 实时调度:支持高优先级抢占,同优先级时间片轮转 -- 虚拟内存:支持缺页异常,内核空间静态映射到0-1GiB地址,用户空间映射到1-4GiB地址 -- 内核通信:事件、信号量、互斥锁、队列 -- 时间管理:软件定时器、系统时钟 - -**文件系统** - -轻量级内核支持FAT,JFFS2,NFS,ramfs,procfs等众多文件系统,并对外提供完整的POSIX标准的操作接口;内部使用VFS层作为统一的适配层框架,方便移植新的文件系统,各个文件系统也能自动利用VFS层提供的丰富的功能。 - -主要特性有: - -- 完整的POSIX接口支持 -- 文件级缓存\(pagecache) -- 磁盘级缓存(bcache) -- 目录缓存\(pathcache\) -- DAC能力 -- 支持嵌套挂载及文件系统堆叠等 -- 支持特性的裁剪和资源占用的灵活配置。 - -**网络协议** - -轻量级内核网络协议基于开源LWIP构建,对LWIP的RAM占用进行优化,同时提高LWIP的传输性能。 - -- 协议: IP、IPv6、 ICMP、 ND、MLD、 UDP、 TCP、IGMP、ARP、PPPoS、PPPoE -- API:socket API -- 扩展特性:多网络接口IP转发、TCP拥塞控制、RTT估计和快速恢复/快速重传 -- 应用程序:HTTP\(S\)服务、SNTP客户端、SMTP\(S\)客户端、ping工具、NetBIOS名称服务、mDNS响应程序、MQTT客户端、TFTP服务、DHCP客户端、DNS客户端、AutoIP/APIPA(零配置)、SNMP代理 - -**HDF框架** - -轻量级内核集成HDF框架,HDF框架旨在为开发者提供更精准、更高效的开发环境,力求做到一次开发,多系统部署。 - -- 支持多内核平台 -- 支持用户态驱动 -- 可配置组件化驱动模型 -- 基于消息的驱动接口模型 -- 基于对象的驱动、设备管理 -- HDI(Hardware Driver Interface)统一硬件接口 -- 支持电源管理、PnP - -**扩展组件** - -对内核功能进行扩展,可选但很重要的机制。 - -- 动态链接:支持标准ELF链接执行、加载地址随机化 -- 进程通信:支持轻量级LiteIPC,同时也支持标准的Mqueue、Pipe、Fifo、Signal等机制 -- 系统调用:支持170+系统调用,同时有支持VDSO机制 -- 权限管理:支持进程粒度的特权划分和管控,UGO三种权限配置 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\206\205\346\240\270\345\220\257\345\212\250/01.\345\206\205\346\240\270\346\200\201\345\220\257\345\212\250.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\206\205\346\240\270\345\220\257\345\212\250/01.\345\206\205\346\240\270\346\200\201\345\220\257\345\212\250.md" deleted file mode 100644 index 4bc7e904ce4c81cc5b4d071c583106ad24edb711..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\206\205\346\240\270\345\220\257\345\212\250/01.\345\206\205\346\240\270\346\200\201\345\220\257\345\212\250.md" +++ /dev/null @@ -1,148 +0,0 @@ ---- -title: 内核态启动 -permalink: /pages/010501020201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# 内核态启动 - -- [内核启动流程](#section9882154318299) -- [编程样例](#section19145114703217) - - [实例描述](#section1045483642518) - - -## 内核启动流程 - -内核启动流程包含汇编启动阶段和C语言启动阶段2部分,如图1所示。汇编启动阶段完成CPU初始设置,关闭dcache/icache,使能FPU及neon,设置MMU建立虚实地址映射,设置系统栈,清理bss段,调用C语言main函数等。C语言启动阶段包含OsMain函数及开始调度等,其中如上图所示,OsMain函数用于内核基础初始化和架构、板级初始化等,其整体由内核启动框架主导初始化流程,图中右边区域为启动框架中可接受外部模块注册启动的阶段,各个阶段的说明如下表1所示。 - -**图 1** 内核启动流程图 - - -![](/images/device-dev/kernel/figure/zh-cn_image_0000001178856385.png) - -**表 1** 启动框架层级 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

层级

-

说明

-

LOS_INIT_LEVEL_EARLIEST

-

最早期初始化

-

说明:不依赖架构,单板以及后续模块会对其有依赖的纯软件模块初始化

-

例如:Trace模块

-

LOS_INIT_LEVEL_ARCH_EARLY

-

架构早期初始化

-

说明:架构相关,后续模块会对其有依赖的模块初始化,如启动过程中非必需的功能,建议放到LOS_INIT_LEVEL_ARCH层

-

LOS_INIT_LEVEL_PLATFORM_EARLY

-

平台早期初始化

-

说明:单板平台、驱动相关,后续模块会对其有依赖的模块初始化,如启动过程中必需的功能,建议放到LOS_INIT_LEVEL_PLATFORM层

-

例如:uart模块

-

LOS_INIT_LEVEL_KMOD_PREVM

-

内存初始化前的内核模块初始化

-

说明:在内存初始化之前需要使能的模块初始化

-

LOS_INIT_LEVEL_VM_COMPLETE

-

基础内存就绪后的初始化

-

说明:此时内存初始化完毕,需要进行使能且不依赖进程间通讯机制与系统进程的模块初始化

-

例如:共享内存功能

-

LOS_INIT_LEVEL_ARCH

-

架构后期初始化

-

说明:架构拓展功能相关,后续模块会对其有依赖的模块初始化

-

LOS_INIT_LEVEL_PLATFORM

-

平台后期初始化

-

说明:单板平台、驱动相关,后续模块会对其有依赖的模块初始化

-

例如:驱动内核抽象层初始化(mmc、mtd)

-

LOS_INIT_LEVEL_KMOD_BASIC

-

内核基础模块初始化

-

说明:内核可拆卸的基础模块初始化

-

例如:VFS初始化

-

LOS_INIT_LEVEL_KMOD_EXTENDED

-

内核扩展模块初始化

-

说明:内核可拆卸的扩展模块初始化

-

例如:系统调用初始化、ProcFS初始化、Futex初始化、HiLog初始化、HiEvent初始化、LiteIPC初始化

-

LOS_INIT_LEVEL_KMOD_TASK

-

内核任务创建

-

说明:进行内核任务的创建(内核任务,软件定时器任务)

-

例如:资源回收系统常驻任务的创建、SystemInit任务创建、CPU占用率统计任务创建

-
- -## 编程样例 - -### 实例描述 - -新增一个内核模块,需要在内核初始化时进行该模块的初始化,则通过内核启动框架将该模块的初始化函数注册进内核启动流程中。 - -**示例代码** - -``` -/* 内核启动框架头文件 */ -#include "los_init.h" -...... - -/* 新增模块的初始化函数 */ -unsigned int OsSampleModInit(void) -{ - PRINTK("OsSampleModInit SUCCESS!\n"); - ...... -} -...... -/* 在启动框架的目标层级中注册新增模块 */ -LOS_MODULE_INIT(OsSampleModInit, LOS_INIT_LEVEL_KMOD_EXTENDED); -``` - -**结果验证** - -``` -main core booting up... -OsSampleModInit SUCCESS! -releasing 1 secondary cores -cpu 1 entering scheduler -cpu 0 entering scheduler -``` - -根据上述系统启动阶段的打印可知,内核在启动时进行了该注册模块的初始化函数调用,完成该模块的初始化操作。 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->启动框架中同一层级内的注册模块不能有依赖关系,建议新增模块按照上述启动阶段进行模块初始化的拆分,按需注册启动。 ->可通过查看系统编译生成文件OHOS\_Image.map中.rodata.init.kernel.\*段内的符号表来了解当前已注册进内核启动框架中的各个模块初始化入口,以及检查新注册的模块初始化入口是否生效。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\206\205\346\240\270\345\220\257\345\212\250/02.\347\224\250\346\210\267\346\200\201\345\220\257\345\212\250.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\206\205\346\240\270\345\220\257\345\212\250/02.\347\224\250\346\210\267\346\200\201\345\220\257\345\212\250.md" deleted file mode 100644 index 2dd1e6860b304a56bb93e9ab002f5a7facf8465b..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/02.\345\206\205\346\240\270\345\220\257\345\212\250/02.\347\224\250\346\210\267\346\200\201\345\220\257\345\212\250.md" +++ /dev/null @@ -1,95 +0,0 @@ ---- -title: 用户态启动 -permalink: /pages/010501020202 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# 用户态启动 - -- [用户态根进程启动](#section79911135647) - - [根进程的启动过程](#section1184317581349) - - [根进程的职责](#section1590220321759) - -- [用户态程序运行](#section194576310611) - -## 用户态根进程启动 - -根进程是系统第一个用户态进程,进程ID为1,它是所有用户态进程的祖先。 - -**图 1** 进程树示意图 -![](/images/device-dev/kernel/figure/进程树示意图.png "进程树示意图") - -### 根进程的启动过程 - -使用链接脚本将如下init启动代码放置到系统镜像指定位置。 - -``` -#define LITE_USER_SEC_ENTRY __attribute__((section(".user.entry"))) -LITE_USER_SEC_ENTRY VOID OsUserInit(VOID *args) -{ -#ifdef LOSCFG_KERNEL_DYNLOAD - sys_call3(__NR_execve, (UINTPTR)g_initPath, 0, 0); -#endif - while (true) { - } -} -``` - -系统启动阶段,OsUserInitProcess启动init进程。具体过程如下: - -1. 由内核OsLoadUserInit加载上述代码。 -2. 创建新的进程空间,启动/bin/init进程。 - -### 根进程的职责 - -- 启动关键系统程序或服务,如交互进程shell。 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >在OpenHarmony 中**init**进程通过读取/etc/init.cfg,根据配置执行指定命令,或启动指定进程(详见:[init启动引导](/pages/01050e02))。 - - -- 监控回收孤儿进程,清理子进程中的僵尸进程。 - -## 用户态程序运行 - -用户态程序常见编译方式有如下两种: - -1. [利用框架编译用户态进程](/pages/010202040101)。 -2. 手动编译 - - 实例: - - ``` - clang --target=arm-liteos --sysroot=prebuilts/lite/sysroot -o helloworld helloworld.c - ``` - - **clang**:参考[LLVM安装指导](/pages/0102010204)安装LLVM编译器。 - - **--target**:--target=arm-liteos,指定编译平台为arm-liteos。 - - **--sysroot**:--sysroot=$\{YOUR\_ROOT\_PATH\}/prebuilts/lite/sysroot,指定头文件以及依赖标准库搜索路径为prebuilts下的指定路径。 - - -用户态程序启动有如下常见方式: - -- shell命令启动进程。 - - ``` - OHOS $ exec helloworld - OHOS $ ./helloworld - OHOS $ /bin/helloworld - ``` - - -- 通过POSIX接口启动新进程。 - - Fork方法创建一个新的进程,exec类接口执行一个全新的进程。 - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/01.\344\270\255\346\226\255\345\217\212\345\274\202\345\270\270\345\244\204\347\220\206.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/01.\344\270\255\346\226\255\345\217\212\345\274\202\345\270\270\345\244\204\347\220\206.md" deleted file mode 100644 index 93df9f445db73f13a4b7fbbf29f96ef3f28d0722..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/01.\344\270\255\346\226\255\345\217\212\345\274\202\345\270\270\345\244\204\347\220\206.md" +++ /dev/null @@ -1,160 +0,0 @@ ---- -title: 中断及异常处理 -permalink: /pages/010501020301 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# 中断及异常处理 - -- [基本概念](#section439816296117) -- [运行机制](#section2792838318) -- [开发指导](#section15415165510110) - - [接口说明](#section57441612024) - - [开发流程](#section64332181221) - - [编程实例](#section204698276478) - - [结果验证](#section1466144215476) - - -## 基本概念 - -中断是指出现需要时,CPU暂停执行当前程序,转而执行新程序的过程。即在程序运行过程中,出现了一个必须由CPU立即处理的事务。此时,CPU暂时中止当前程序的执行转而处理这个事务,这个过程就叫做中断。通过中断机制,可以使CPU避免把大量时间耗费在等待、查询外设状态的操作上,大大提高系统实时性以及执行效率。 - -异常处理是操作系统对运行期间发生的异常情况(芯片硬件异常)进行处理的一系列动作,例如虚拟内存缺页异常、打印异常发生时函数的调用栈信息、CPU现场信息、任务的堆栈情况等。 - -## 运行机制 - -外设可以在没有CPU介入的情况下完成一定的工作,但某些情况下也需要CPU为其执行一定的工作。通过中断机制,在外设不需要CPU介入时,CPU可以执行其它任务,而当外设需要CPU时,产生一个中断信号,该信号连接至中断控制器。中断控制器是一方面接收其它外设中断引脚的输入,另一方面它会发出中断信号给CPU。可以通过对中断控制器编程来打开和关闭中断源、设置中断源的优先级和触发方式。常用的中断控制器有VIC(Vector Interrupt Controller)和GIC(General Interrupt Controller)。在ARM Cortex-A7中使用的中断控制器是GIC。CPU收到中断控制器发送的中断信号后,中断当前任务来响应中断请求。 - -异常处理就是可以打断CPU正常运行流程的一些事情,如未定义指令异常、试图修改只读的数据异常、不对齐的地址访问异常等。当异常发生时,CPU暂停当前的程序,先处理异常事件,然后再继续执行被异常打断的程序。 - -以ARMv7-a架构为例,中断和异常处理的入口为中断向量表,中断向量表包含各个中断和异常处理的入口函数。 - -**图 1** 中断向量表 - - -![](/images/device-dev/kernel/figure/zh-cn_image_0000001173449871.png) - -## 开发指导 - -### 接口说明 - -异常处理为内部机制,不对外提供接口,中断模块提供对外接口如下: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名称

-

描述

-

创建和删除中断

-

LOS_HwiCreate

-

中断创建,注册中断号、中断触发模式、中断优先级、中断处理程序。中断被触发时,会调用该中断处理程序

-

LOS_HwiDelete

-

删除中断

-

打开和关闭所有中断

-

LOS_IntUnLock

-

打开当前处理器所有中断响应

-

LOS_IntLock

-

关闭当前处理器所有中断响应

-

LOS_IntRestore

-

恢复到使用LOS_IntLock关闭所有中断之前的状态

-

获取系统支持的最大中断数

-

LOS_GetSystemHwiMaximum

-

获取系统支持的最大中断数

-
- -### 开发流程 - -1. 调用中断创建接口LOS\_HwiCreate创建中断。 -2. 调用LOS\_HwiDelete接口删除指定中断,此接口根据实际情况使用,判断是否需要删除中断。 - -### 编程实例 - -本实例实现如下功能: - -1. 创建中断。 -2. 删除中断。 - -代码实现如下,演示如何创建中断和删除中断,当指定的中断号HWI\_NUM\_TEST产生中断时,会调用中断处理函数: - -``` -#include "los_hwi.h" -/*中断处理函数*/ -STATIC VOID HwiUsrIrq(VOID) -{ - printf("in the func HwiUsrIrq \n"); -} - -static UINT32 Example_Interrupt(VOID) -{ - UINT32 ret; - HWI_HANDLE_T hwiNum = 7; - HWI_PRIOR_T hwiPrio = 3; - HWI_MODE_T mode = 0; - HWI_ARG_T arg = 0; - - /*创建中断*/ - ret = LOS_HwiCreate(hwiNum, hwiPrio, mode, (HWI_PROC_FUNC)HwiUsrIrq, (HwiIrqParam *)arg); - if(ret == LOS_OK){ - printf("Hwi create success!\n"); - } else { - printf("Hwi create failed!\n"); - return LOS_NOK; - } - - /* 延时50个Ticks, 当有硬件中断发生时,会调用函数HwiUsrIrq*/ - LOS_TaskDelay(50); - - /*删除中断*/ - ret = LOS_HwiDelete(hwiNum, (HwiIrqParam *)arg); - if(ret == LOS_OK){ - printf("Hwi delete success!\n"); - } else { - printf("Hwi delete failed!\n"); - return LOS_NOK; - } - return LOS_OK; -} -``` - -### 结果验证 - -编译运行得到的结果为: - -``` -Hwi create success! -Hwi delete success! -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/02.\350\277\233\347\250\213\347\256\241\347\220\206/01.\350\277\233\347\250\213.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/02.\350\277\233\347\250\213\347\256\241\347\220\206/01.\350\277\233\347\250\213.md" deleted file mode 100644 index 778892b7f55c7cfce882a300db94a9f3a9cd7e55..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/02.\350\277\233\347\250\213\347\256\241\347\220\206/01.\350\277\233\347\250\213.md" +++ /dev/null @@ -1,191 +0,0 @@ ---- -title: 进程 -permalink: /pages/01050102030201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# 进程 - -- [基本概念](#section89346055119) -- [运行机制](#section174514474512) -- [开发指导](#section159637182521) - - [接口说明](#section1153124135212) - - [开发流程](#section1533674618526) - - -## 基本概念 - -进程是系统资源管理的最小单元。OpenHarmony LiteOS-A内核提供的进程模块主要用于实现用户态进程的隔离,内核态被视为一个进程空间,不存在其它进程\(KIdle除外,KIdle进程是系统提供的空闲进程,和KProcess共享一个进程空间)。 - -- OpenHarmony 的进程模块主要为用户提供多个进程,实现了进程之间的切换和通信,帮助用户管理业务程序流程。 -- OpenHarmony 的进程采用抢占式调度机制,采用高优先级优先+同优先级时间片轮转的调度算法。 -- OpenHarmony 的进程一共有32个优先级\(0-31\),用户进程可配置的优先级有22个\(10-31\),最高优先级为10,最低优先级为31。 -- 高优先级的进程可抢占低优先级进程,低优先级进程必须在高优先级进程阻塞或结束后才能得到调度。 -- 每一个用户态进程均拥有自己独立的进程空间,相互之间不可见,实现进程间隔离。 -- 用户态根进程init由内核态创建,其它用户态子进程均由init进程fork而来。 - -**进程状态说明:** - -- 初始化(Init):进程正在被创建。 - -- 就绪(Ready):进程在就绪列表中,等待CPU调度。 -- 运行(Running):进程正在运行。 -- 阻塞(Pending):进程被阻塞挂起。本进程内所有的线程均被阻塞时,进程被阻塞挂起。 -- 僵尸(Zombies):进程运行结束,等待父进程回收其控制块资源。 - -**图 1** 进程状态迁移示意图 -![](/images/device-dev/kernel/figure/进程状态迁移示意图.png "进程状态迁移示意图") - -**进程状态迁移说明:** - -- Init→Ready: - - 进程创建或fork时,拿到该进程控制块后进入Init状态,处于进程初始化阶段,当进程初始化完成将进程插入调度队列,此时进程进入就绪状态。 - -- Ready→Running: - - 进程创建后进入就绪态,发生进程切换时,就绪列表中最高优先级的进程被执行,从而进入运行态。若此时该进程中已无其它线程处于就绪态,则进程从就绪列表删除,只处于运行态;若此时该进程中还有其它线程处于就绪态,则该进程依旧在就绪队列,此时进程的就绪态和运行态共存,但对外呈现的进程状态为运行态。 - -- Running→Pending: - - 进程在最后一个线程转为阻塞态时, 进程内所有的线程均处于阻塞态,此时进程同步进入阻塞态,然后发生进程切换。 - -- Pending→Ready: - - 阻塞进程内的任意线程恢复就绪态时,进程被加入到就绪队列,同步转为就绪态。 - -- Ready→Pending: - - 进程内的最后一个就绪态线程转为阻塞态时,进程从就绪列表中删除,进程由就绪态转为阻塞态。 - -- Running→Ready: - - 进程由运行态转为就绪态的情况有以下两种: - - 1. 有更高优先级的进程创建或者恢复后,会发生进程调度,此刻就绪列表中最高优先级进程变为运行态,那么原先运行的进程由运行态变为就绪态。 - 2. 若进程的调度策略为LOS\_SCHED\_RR,且存在同一优先级的另一个进程处于就绪态,则该进程的时间片消耗光之后,该进程由运行态转为就绪态,另一个同优先级的进程由就绪态转为运行态。 - -- Running→Zombies: - - 当进程的主线程或所有线程运行结束后,进程由运行态转为僵尸态,等待父进程回收资源。 - - -## 运行机制 - -OpenHarmony 提供的进程模块主要用于实现用户态进程的隔离,支持用户态进程的创建、退出、资源回收、设置/获取调度参数、获取进程ID、设置/获取进程组ID等功能。 - -用户态进程通过fork父进程而来,fork进程时会将父进程的进程虚拟内存空间clone到子进程,子进程实际运行时通过写时复制机制将父进程的内容按需复制到子进程的虚拟内存空间。 - -进程只是资源管理单元,实际运行是由进程内的各个线程完成的,不同进程内的线程相互切换时会进行进程空间的切换。 - -**图 2** 进程管理示意图 - - -![](/images/device-dev/kernel/figure/zh-cn_image_0000001127519136.png) - -## 开发指导 - -### 接口说明 - -**表 1** 进程管理模块接口 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名称

-

描述

-

进程调度参数控制

-

LOS_GetProcessScheduler

-

获取指定进程的调度策略

-

LOS_SetProcessScheduler

-

设置指定进程的调度参数,包括优先级和调度策略

-

LOS_GetProcessPriority

-

获取指定进程的优先级

-

LOS_SetProcessPriority

-

设置指定进程的优先级

-

等待回收子进程

-

LOS_Wait

-

等待子进程结束并回收子进程

-

进程组

-

LOS_GetProcessGroupID

-

获取指定进程的进程组ID

-

LOS_GetCurrProcessGroupID

-

获取当前进程的进程组ID

-

获取进程ID

-

LOS_GetCurrProcessID

-

获取当前进程的进程ID

-

用户及用户组

-

LOS_GetUserID

-

获取当前进程的用户ID

-

LOS_GetGroupID

-

获取当前进程的用户组ID

-

LOS_CheckInGroups

-

检查指定用户组ID是否在当前进程的用户组内

-

系统支持的最大进程数

-

LOS_GetSystemProcessMaximum

-

获取系统支持的最大进程数目

-
- -### 开发流程 - -不支持内核态进程创建,内核态不涉及进程相关开发。 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->- idle线程的数量跟随CPU核心数,每个CPU均有一个相应的idle线程。 ->- 不支持创建除KProcess和KIdle进程之外的其它内核态进程。 ->- 用户态进程通过系统调用进入内核态后创建的线程属于KProcess, 不属于当前用户态进程。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/02.\350\277\233\347\250\213\347\256\241\347\220\206/02.\344\273\273\345\212\241.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/02.\350\277\233\347\250\213\347\256\241\347\220\206/02.\344\273\273\345\212\241.md" deleted file mode 100644 index 55a41eef741d857f36fa082f31ffd7c633aff9a0..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/02.\350\277\233\347\250\213\347\256\241\347\220\206/02.\344\273\273\345\212\241.md" +++ /dev/null @@ -1,364 +0,0 @@ ---- -title: 任务 -permalink: /pages/01050102030202 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# 任务 - -- [基本概念](#section138411646175417) -- [运行机制](#section1381918945512) -- [开发指导](#section10649727135519) - - [接口说明](#section78333315555) - - [开发流程](#section16229657115514) - - [编程实例](#section2809723165612) - - -## 基本概念 - -从系统的角度看,任务Task是竞争系统资源的最小运行单元。任务可以使用或等待CPU、使用内存空间等系统资源,并独立于其它任务运行。 - -OpenHarmony 内核中使用一个任务表示一个线程。 - -OpenHarmony 内核中同优先级进程内的任务统一调度、运行。 - -OpenHarmony 内核中的任务采用抢占式调度机制,同时支持时间片轮转调度和FIFO调度方式。 - -OpenHarmony 内核的任务一共有32个优先级\(0-31\),最高优先级为0,最低优先级为31。 - -当前进程内, 高优先级的任务可抢占低优先级任务,低优先级任务必须在高优先级任务阻塞或结束后才能得到调度。 - -**任务状态说明**: - -- 初始化(Init):任务正在被创建。 - -- 就绪(Ready):任务在就绪列表中,等待CPU调度。 -- 运行(Running):任务正在运行。 -- 阻塞(Blocked):任务被阻塞挂起。Blocked状态包括:pending\(因为锁、事件、信号量等阻塞\)、suspended(主动pend)、delay\(延时阻塞\)、pendtime\(因为锁、事件、信号量时间等超时等待\)。 -- 退出(Exit):任务运行结束,等待父任务回收其控制块资源。 - -**图 1** 任务状态迁移示意图 -![](/images/device-dev/kernel/figure/任务状态迁移示意图.png "任务状态迁移示意图") - -**任务状态迁移说明:** - -- Init→Ready: - - 任务创建拿到控制块后为初始化阶段\(Init状态\),当任务初始化完成将任务插入调度队列,此时任务进入就绪状态。 - -- Ready→Running: - - 任务创建后进入就绪态,发生任务切换时,就绪列表中最高优先级的任务被执行,从而进入运行态,此刻该任务从就绪列表中删除。 - -- Running→Blocked: - - 正在运行的任务发生阻塞(挂起、延时、读信号量等)时,任务状态由运行态变成阻塞态,然后发生任务切换,运行就绪列表中剩余最高优先级任务。 - -- Blocked→Ready : - - 阻塞的任务被恢复后(任务恢复、延时时间超时、读信号量超时或读到信号量等),此时被恢复的任务会被加入就绪列表,从而由阻塞态变成就绪态。 - -- Ready→Blocked: - - 任务也有可能在就绪态时被阻塞(挂起),此时任务状态会由就绪态转变为阻塞态,该任务从就绪列表中删除,不会参与任务调度,直到该任务被恢复。 - -- Running→Ready: - - 有更高优先级任务创建或者恢复后,会发生任务调度,此刻就绪列表中最高优先级任务变为运行态,那么原先运行的任务由运行态变为就绪态,并加入就绪列表中。 - -- Running→Exit: - - 运行中的任务运行结束,任务状态由运行态变为退出态。若为设置了分离属性(LOS\_TASK\_STATUS\_DETACHED)的任务,运行结束后将直接销毁。 - - -## 运行机制 - -OpenHarmony 任务管理模块提供任务创建、任务延时、任务挂起和任务恢复、锁任务调度和解锁任务调度、根据ID查询任务控制块信息功能。 - -用户创建任务时,系统会将任务栈进行初始化,预置上下文。此外,系统还会将“任务入口函数”地址放在相应位置。这样在任务第一次启动进入运行态时,将会执行任务入口函数。 - -## 开发指导 - -### 接口说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名称

-

描述

-

任务的创建和删除

-

LOS_TaskCreateOnly

-

创建任务,并使该任务进入Init状态,不执行任务调度

-

LOS_TaskCreate

-

创建任务,并使该任务进入Ready状态,并调度

-

LOS_TaskDelete

-

删除指定的任务

-

任务状态控制

-

LOS_TaskResume

-

恢复挂起的任务

-

LOS_TaskSuspend

-

挂起指定的任务

-

LOS_TaskJoin

-

挂起当前任务,等待指定任务运行结束并回收其任务控制块资源

-

LOS_TaskDetach

-

修改任务的joinable属性为detach属性,detach属性的任务运行结束会自动回收任务控制块资源

-

LOS_TaskDelay

-

任务延时等待

-

LOS_TaskYield

-

显式放权,调整调用任务优先级的任务调度顺序

-

任务调度的控制

-

LOS_TaskLock

-

锁任务调度

-

LOS_TaskUnlock

-

解锁任务调度

-

任务优先级的控制

-

LOS_CurTaskPriSet

-

设置当前任务的优先级

-

LOS_TaskPriSet

-

设置指定任务的优先级

-

LOS_TaskPriGet

-

获取指定任务的优先级

-

任务信息获取

-

LOS_CurTaskIDGet

-

获取当前任务的ID

-

LOS_TaskInfoGet

-

获取指定任务的信息

-

任务绑核操作

-

LOS_TaskCpuAffiSet

-

绑定指定任务到指定cpu上运行,仅在多核下使用

-

LOS_TaskCpuAffiGet

-

获取指定任务的绑核信息,仅在多核下使用

-

任务调度参数的控制

-

LOS_GetTaskScheduler

-

获取指定任务的调度策略

-

LOS_SetTaskScheduler

-

设置指定任务的调度参数,包括优先级和调度策略

-

系统支持的最大任务数

-

LOS_GetSystemTaskMaximum

-

获取系统支持的最大任务数目

-
- -### 开发流程 - -任务的典型开发流程: - -1. 通过LOS\_TaskCreate创建一个任务。 - - 指定任务的执行入口函数 - - - 指定任务名 - - 指定任务的栈大小 - - 指定任务的优先级 - - 指定任务的属性,LOS\_TASK\_ATTR\_JOINABLE和LOS\_TASK\_STATUS\_DETACHED属性 - - 多核运行时,可以选择设置任务的绑核属性 - -2. 任务参与调度运行,执行用户指定的业务代码。 -3. 任务执行结束,如果设置了LOS\_TASK\_STATUS\_DETACHED属性,则自动回收任务资源,如果任务设置了LOS\_TASK\_ATTR\_JOINABLE属性,则需要调用LOS_TaskJoin回收任务资源,默认为LOS\_TASK\_STATUS\_DETACHED属性。 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->- 内核态具有最高权限,可以操作任意进程内的任务。 ->- 用户态进程通过系统调用进入内核态后创建的任务属于KProcess, 不属于当前用户态进程。 - -### 编程实例 - -代码实现如下: - -``` -UINT32 g_taskLoID; -UINT32 g_taskHiID; -#define TSK_PRIOR_HI 4 -#define TSK_PRIOR_LO 5 -UINT32 ExampleTaskHi(VOID) -{ - UINT32 ret; - PRINTK("Enter TaskHi Handler.\n"); - /* 延时2个Tick,延时后该任务会挂起,执行剩余任务中最高优先级的任务(g_taskLoID任务) */ - ret = LOS_TaskDelay(2); - if (ret != LOS_OK) { - PRINTK("Delay Task Failed.\n"); - return LOS_NOK; - } - /* 2个Tick时间到了后,该任务恢复,继续执行 */ - PRINTK("TaskHi LOS_TaskDelay Done.\n"); - /* 挂起自身任务 */ - ret = LOS_TaskSuspend(g_taskHiID); - if (ret != LOS_OK) { - PRINTK("Suspend TaskHi Failed.\n"); - return LOS_NOK; - } - PRINTK("TaskHi LOS_TaskResume Success.\n"); - return LOS_OK; -} - -/* 低优先级任务入口函数 */ -UINT32 ExampleTaskLo(VOID) -{ - UINT32 ret; - PRINTK("Enter TaskLo Handler.\n"); - /* 延时2个Tick,延时后该任务会挂起,执行剩余任务中就高优先级的任务(背景任务) */ - ret = LOS_TaskDelay(2); - if (ret != LOS_OK) { - PRINTK("Delay TaskLo Failed.\n"); - return LOS_NOK; - } - PRINTK("TaskHi LOS_TaskSuspend Success.\n"); - /* 恢复被挂起的任务g_taskHiID */ - ret = LOS_TaskResume(g_taskHiID); - if (ret != LOS_OK) { - PRINTK("Resume TaskHi Failed.\n"); - return LOS_NOK; - } - PRINTK("TaskHi LOS_TaskDelete Success.\n"); - return LOS_OK; -} -/* 任务测试入口函数,在里面创建优先级不一样的两个任务 */ -UINT32 ExampleTaskCaseEntry(VOID) -{ - UINT32 ret; - TSK_INIT_PARAM_S initParam = {0}; - - /* 锁任务调度 */ - LOS_TaskLock(); - PRINTK("LOS_TaskLock() Success!\n"); - initParam.pfnTaskEntry = (TSK_ENTRY_FUNC)ExampleTaskHi; - initParam.usTaskPrio = TSK_PRIOR_HI; - initParam.pcName = "HIGH_NAME"; - initParam.uwStackSize = LOS_TASK_MIN_STACK_SIZE; - initParam.uwResved = LOS_TASK_ATTR_JOINABLE; - - /* 创建高优先级任务,由于锁任务调度,任务创建成功后不会马上执行 */ - ret = LOS_TaskCreate(&g_taskHiID, &initParam); - if (ret != LOS_OK) { - LOS_TaskUnlock(); - PRINTK("ExampleTaskHi create Failed! ret=%d\n", ret); - return LOS_NOK; - } - PRINTK("ExampleTaskHi create Success!\n"); - - initParam.pfnTaskEntry = (TSK_ENTRY_FUNC)ExampleTaskLo; - initParam.usTaskPrio = TSK_PRIOR_LO; - initParam.pcName = "LOW_NAME"; - initParam.uwStackSize = LOS_TASK_MIN_STACK_SIZE; - initParam.uwResved = LOS_TASK_STATUS_DETACHED; - - /* 创建低优先级任务,由于锁任务调度,任务创建成功后不会马上执行 */ - ret = LOS_TaskCreate(&g_taskLoID, &initParam); - if (ret!= LOS_OK) { - LOS_TaskUnlock(); - PRINTK("ExampleTaskLo create Failed!\n"); - return LOS_NOK; - } - PRINTK("ExampleTaskLo create Success!\n"); - - /* 解锁任务调度,此时会发生任务调度,执行就绪列表中最高优先级任务 */ - LOS_TaskUnlock(); - - ret = LOS_TaskJoin(g_taskHiID, NULL); - if (ret != LOS_OK) { - PRINTK("Join ExampleTaskHi Failed!\n"); - } else { - PRINTK("Join ExampleTaskHi Success!\n"); - } - - while(1){}; - return LOS_OK; -} -``` - -编译运行得到的结果为: - -``` -LOS_TaskLock() Success! -ExampleTaskHi create Success! -ExampleTaskLo create Success! -Enter TaskHi Handler. -Enter TaskLo Handler. -TaskHi LOS_TaskDelay Done. -TaskHi LOS_TaskSuspend Success. -TaskHi LOS_TaskResume Success. -TaskHi LOS_TaskDelete Success. -Join ExampleTaskHi Success! -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/02.\350\277\233\347\250\213\347\256\241\347\220\206/03.\350\260\203\345\272\246\345\231\250.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/02.\350\277\233\347\250\213\347\256\241\347\220\206/03.\350\260\203\345\272\246\345\231\250.md" deleted file mode 100644 index 3c18cec92048677d39f877c002c30dd69581d353..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/02.\350\277\233\347\250\213\347\256\241\347\220\206/03.\350\260\203\345\272\246\345\231\250.md" +++ /dev/null @@ -1,76 +0,0 @@ ---- -title: 调度器 -permalink: /pages/01050102030203 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# 调度器 - -- [基本概念](#section123882355719) -- [运行机制](#section143015396572) -- [开发指导](#section10604192145816) - - [接口说明](#section207985910582) - - [开发流程](#section1015110331584) - - -## 基本概念 - -OpenHarmony LiteOS-A内核 了高优先级优先+同优先级时间片轮转的抢占式调度机制,系统从启动开始基于real time的时间轴向前运行,使得该调度算法具有很好的实时性。 - -OpenHarmony 的调度算法将tickless机制天然嵌入到调度算法中,一方面使得系统具有更低的功耗,另一方面也使得tick中断按需响应,减少无用的tick中断响应,进一步提高系统的实时性。 - -OpenHarmony 的进程调度策略支持SCHED\_RR,线程调度策略支持SCHED\_RR和SCHED\_FIFO。 - -OpenHarmony 调度的最小单元为线程。 - -## 运行机制 - -OpenHarmony 采用进程优先级队列+线程优先级队列的方式,进程优先级范围为0-31,共有32个进程优先级桶队列,每个桶队列对应一个线程优先级桶队列;线程优先级范围也为0-31,一个线程优先级桶队列也有32个优先级队列。 - -**图 1** 调度优先级桶队列示意图 - - -![](/images/device-dev/kernel/figure/zh-cn_image_0000001127520662.png) - -OpenHarmony 在系统启动内核初始化之后开始调度,运行过程中创建的进程或线程会被加入到调度队列,系统根据进程和线程的优先级及线程的时间片消耗情况选择最优的线程进行调度运行,线程一旦调度到就会从调度队列上删除,线程在运行过程中发生阻塞,会被加入到对应的阻塞队列中并触发一次调度,调度其它线程运行。如果调度队列上没有可以调度的线程,则系统就会选择KIdle进程的线程进行调度运行。 - -**图 2** 调度流程示意图 - - -![](/images/device-dev/kernel/figure/zh-cn_image_0000001176974089.png) - -## 开发指导 - -### 接口说明 - - - - - - - - - - - - -

功能分类

-

接口名称

-

描述

-

触发系统调度

-

LOS_Schedule

-

触发系统调度

-
- -### 开发流程 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->系统启动初始化阶段,不允许触发调度。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/03.\345\206\205\345\255\230\347\256\241\347\220\206/01.\345\240\206\345\206\205\345\255\230\347\256\241\347\220\206.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/03.\345\206\205\345\255\230\347\256\241\347\220\206/01.\345\240\206\345\206\205\345\255\230\347\256\241\347\220\206.md" deleted file mode 100644 index 80d110642535fbf837b8b9b3bb2f2b8924cba67f..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/03.\345\206\205\345\255\230\347\256\241\347\220\206/01.\345\240\206\345\206\205\345\255\230\347\256\241\347\220\206.md" +++ /dev/null @@ -1,262 +0,0 @@ ---- -title: 堆内存管理 -permalink: /pages/01050102030301 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# 堆内存管理 - -- [基本概念](#section449414395916) -- [运行机制](#section465085575911) -- [开发指导](#section577019272015) - - [使用场景](#section326917198583) - - [接口说明](#section1032331584) - - [开发流程](#section07271773592) - - [编程实例](#section84931234145913) - - [结果验证](#section165233233917) - - -## 基本概念 - -内存管理模块管理系统的内存资源,它是操作系统的核心模块之一,主要包括内存的初始化、分配以及释放。OpenHarmony LiteOS-A的堆内存管理提供内存初始化、分配、释放等功能。在系统运行过程中,堆内存管理模块通过对内存的申请/释放来管理用户和OS对内存的使用,使内存的利用率和使用效率达到最优,同时最大限度地解决系统的内存碎片问题。 - -## 运行机制 - -堆内存管理,即在内存资源充足的情况下,根据用户需求,从系统配置的一块比较大的连续内存(内存池,也是堆内存)中分配任意大小的内存块。当用户不需要该内存块时,又可以释放回系统供下一次使用。与静态内存相比,动态内存管理的优点是按需分配,缺点是内存池中容易出现碎片。OpenHarmony LiteOS-A堆内存在TLSF算法的基础上,对区间的划分进行了优化,获得更优的性能,降低了碎片率。动态内存核心算法框图如下: - -**图 1** 动态内存核心算法 -![](/images/device-dev/kernel/figure/动态内存核心算法-19.png "动态内存核心算法-19") - -根据空闲内存块的大小,使用多个空闲链表来管理。根据内存空闲块大小分为两个部分:\[4, 127\]和\[27, 231\],如上图size class所示: - -1. 对\[4,127\]区间的内存进行等分,如上图下半部分所示,分为31个小区间,每个小区间对应内存块大小为4字节的倍数。每个小区间对应一个空闲内存链表和用于标记对应空闲内存链表是否为空的一个比特位,值为1时,空闲链表非空。\[4,127\]区间的31个小区间内存对应31个比特位进行标记链表是否为空。 -2. 大于127字节的空闲内存块,按照2的次幂区间大小进行空闲链表管理。总共分为24个小区间,每个小区间又等分为8个二级小区间,见上图上半部分的Size Class和Size SubClass部分。每个二级小区间对应一个空闲链表和用于标记对应空闲内存链表是否为空的一个比特位。总共24\*8=192个二级小区间,对应192个空闲链表和192个比特位进行标记链表是否为空。 - -例如,当有40字节的空闲内存需要插入空闲链表时,对应小区间\[40,43\],第10个空闲链表,位图标记的第10比特位。把40字节的空闲内存挂载第10个空闲链表上,并判断是否需要更新位图标记。当需要申请40字节的内存时,根据位图标记获取存在满足申请大小的内存块的空闲链表,从空闲链表上获取空闲内存节点。如果分配的节点大于需要申请的内存大小,进行分割节点操作,剩余的节点重新挂载到相应的空闲链表上。当有580字节的空闲内存需要插入空闲链表时,对应二级小区间\[2^9,2^9+2^6\],第31+2\*8=47个空闲链表,并使用位图的第47个比特位来标记链表是否为空。把580字节的空闲内存挂载第47个空闲链表上,并判断是否需要更新位图标记。当需要申请580字节的内存时,根据位图标记获取存在满足申请大小的内存块的空闲链表,从空闲链表上获取空闲内存节点。如果分配的节点大于需要申请的内存大小,进行分割节点操作,剩余的节点重新挂载到相应的空闲链表上。如果对应的空闲链表为空,则向更大的内存区间去查询是否有满足条件的空闲链表,实际计算时,会一次性查找到满足申请大小的空闲链表。 - -内存管理结构如下图所示: - -**图 2** 动态内存管理结构图 -![](/images/device-dev/kernel/figure/动态内存管理结构图-20.png "动态内存管理结构图-20") - -- 内存池池头部分 - - 内存池池头部分包含内存池信息、位图标记数组和空闲链表数组。内存池信息包含内存池起始地址及堆区域总大小,内存池属性。位图标记数组有7个32位无符号整数组成,每个比特位标记对应的空闲链表是否挂载空闲内存块节点。空闲内存链表包含223个空闲内存头节点信息,每个空闲内存头节点信息维护内存节点头和空闲链表中的前驱、后继空闲内存节点。 - -- 内存池节点部分 - - 包含3种类型节点:未使用空闲内存节点,已使用内存节点和尾节点。每个内存节点维护一个前序指针,指向内存池中上一个内存节点,还维护内存节点的大小和使用标记。空闲内存节点和已使用内存节点后面的内存区域是数据域,尾节点没有数据域。 - - -## 开发指导 - -### 使用场景 - -堆内存管理的主要工作是动态分配并管理用户申请到的内存区间,主要用于用户需要使用大小不等的内存块的场景,当用户需要使用内存时,可以通过操作系统的动态内存申请函数索取指定大小的内存块。一旦使用完毕,通过内存释放函数释放所占用内存,使之可以重复使用。 - -### 接口说明 - -OpenHarmony LiteOS-A的堆内存管理主要为用户提供以下功能,接口详细信息可以查看API参考。 - -**表 1** 堆内存管理接口 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名称

-

描述

-

初始化和删除内存池

-

LOS_MemInit

-

初始化一块指定的动态内存池,大小为size

-

LOS_MemDeInit

-

删除指定内存池,仅打开LOSCFG_MEM_MUL_POOL时有效

-

申请、释放动态内存

-

LOS_MemAlloc

-

从指定动态内存池中申请size长度的内存

-

LOS_MemFree

-

释放从指定动态内存中申请的内存

-

LOS_MemRealloc

-

按size大小重新分配内存块,并将原内存块内容拷贝到新内存块。如果新内存块申请成功,则释放原内存块

-

LOS_MemAllocAlign

-

从指定动态内存池中申请长度为size且地址按boundary字节对齐的内存

-

获取内存池信息

-

LOS_MemPoolSizeGet

-

获取指定动态内存池的总大小

-

LOS_MemTotalUsedGet

-

获取指定动态内存池的总使用量大小

-

LOS_MemInfoGet

-

获取指定内存池的内存结构信息,包括空闲内存大小、已使用内存大小、空闲内存块数量、已使用的内存块数量、最大的空闲内存块大小

-

LOS_MemPoolList

-

打印系统中已初始化的所有内存池,包括内存池的起始地址、内存池大小、空闲内存总大小、已使用内存总大小、最大的空闲内存块大小、空闲内存块数量、已使用的内存块数量。仅打开LOSCFG_MEM_MUL_POOL时有效

-

获取内存块信息

-

LOS_MemFreeNodeShow

-

打印指定内存池的空闲内存块的大小及数量

-

检查指定内存池的完整性

-

LOS_MemIntegrityCheck

-

对指定内存池做完整性检查,仅打开LOSCFG_BASE_MEM_NODE_INTEGRITY_CHECK时有效

-
- ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->- 由于动态内存管理需要管理控制块数据结构来管理内存,这些数据结构会额外消耗内存,故实际用户可使用内存总量小于配置项OS\_SYS\_MEM\_SIZE的大小。 ->- 对齐分配内存接口LOS\_MemAllocAlign/LOS\_MemMallocAlign因为要进行地址对齐,可能会额外消耗部分内存,故存在一些遗失内存,当系统释放该对齐内存时,同时回收由于对齐导致的遗失内存。 - -### 开发流程 - -本节介绍使用动态内存的典型场景开发流程。 - -1. 初始化LOS\_MemInit。 - - 初始一个内存池后生成一个内存池控制头、尾节点EndNode,剩余的内存被标记为FreeNode内存节点。注:EndNode作为内存池末尾的节点,size为0。 - - -1. 申请任意大小的动态内存LOS\_MemAlloc。 - - 判断动态内存池中是否存在大于申请量大小的空闲内存块空间,若存在,则划出一块内存块,以指针形式返回,若不存在,返回NULL。如果空闲内存块大于申请量,需要对内存块进行分割,剩余的部分作为空闲内存块挂载到空闲内存链表上。 - - -1. 释放动态内存LOS\_MemFree。 - - 回收内存块,供下一次使用。调用LOS\_MemFree释放内存块,则会回收内存块,并且将其标记为FreeNode。在回收内存块时,相邻的FreeNode会自动合并。 - - -### 编程实例 - -本实例执行以下步骤: - -1. 初始化一个动态内存池。 -2. 从动态内存池中申请一个内存块。 -3. 在内存块中存放一个数据。 -4. 打印出内存块中的数据。 -5. 释放该内存块。 - -示例代码如下: - -``` -#include "los_memory.h" - -#define TEST_POOL_SIZE (2*1024*1024) -__attribute__((aligned(4))) UINT8 g_testPool[TEST_POOL_SIZE]; - -VOID Example_DynMem(VOID) -{ - UINT32 *mem = NULL; - UINT32 ret; - - /*初始化内存池*/ - ret = LOS_MemInit(g_testPool, TEST_POOL_SIZE); - if (LOS_OK == ret) { - printf("Mem init success!\n"); - } else { - printf("Mem init failed!\n"); - return; - } - - /*分配内存*/ - mem = (UINT32 *)LOS_MemAlloc(g_testPool, 4); - if (NULL == mem) { - printf("Mem alloc failed!\n"); - return; - } - printf("Mem alloc success!\n"); - - /*赋值*/ - *mem = 828; - printf("*mem = %d\n", *mem); - - /*释放内存*/ - ret = LOS_MemFree(g_testPool, mem); - if (LOS_OK == ret) { - printf("Mem free success!\n"); - } else { - printf("Mem free failed!\n"); - } - - return; -} -UINT32 ExampleDynMemEntry(VOID) -{ - UINT32 ret; - TSK_INIT_PARAM_S initParam = {0}; - initParam.pfnTaskEntry = (TSK_ENTRY_FUNC)Example_DynMem; - initParam.usTaskPrio = 10; - initParam.pcName = "Example_DynMem"; - initParam.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE; - initParam.uwResved = LOS_TASK_STATUS_DETACHED; - - /* 创建高优先级任务,由于锁任务调度,任务创建成功后不会马上执行 */ - ret = LOS_TaskCreate(&g_taskHiID, &initParam); - if (ret != LOS_OK) { - LOS_TaskUnlock(); - PRINTK("Example_DynMem create Failed! ret=%d\n", ret); - return LOS_NOK; - } - PRINTK("Example_DynMem create Success!\n"); - while(1){}; - return LOS_OK; -} -``` - -### 结果验证 - -输出结果如下: - -``` -Mem init success! -Mem alloc success! -*mem = 828 -Mem free success! -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/03.\345\206\205\345\255\230\347\256\241\347\220\206/02.\347\211\251\347\220\206\345\206\205\345\255\230\347\256\241\347\220\206.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/03.\345\206\205\345\255\230\347\256\241\347\220\206/02.\347\211\251\347\220\206\345\206\205\345\255\230\347\256\241\347\220\206.md" deleted file mode 100644 index 9fc41bfcc0aee324f1c5892d731021dd0ecba41d..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/03.\345\206\205\345\255\230\347\256\241\347\220\206/02.\347\211\251\347\220\206\345\206\205\345\255\230\347\256\241\347\220\206.md" +++ /dev/null @@ -1,241 +0,0 @@ ---- -title: 物理内存管理 -permalink: /pages/01050102030302 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# 物理内存管理 - -- [基本概念](#section210891719217) -- [运行机制](#section111355315213) -- [开发指导](#section393116496217) - - [接口说明](#section13210155619214) - - [开发流程](#section178441091231) - - [编程实例](#section1258174015319) - - [结果验证](#section515091342819) - - -## 基本概念 - -物理内存是计算机上最重要的资源之一,指的是实际的内存设备提供的、可以通过CPU总线直接进行寻址的内存空间,其主要作用是为操作系统及程序提供临时存储空间。LiteOS-A内核管理物理内存是通过分页实现的,除了内核堆占用的一部分内存外,其余可用内存均以4KiB为单位划分成页帧,内存分配和内存回收便是以页帧为单位进行操作。内核采用伙伴算法管理空闲页面,可以降低一定的内存碎片率,提高内存分配和释放的效率,但是一个很小的块往往也会阻塞一个大块的合并,导致不能分配较大的内存块。 - -## 运行机制 - -如下图所示,LiteOS-A内核的物理内存使用分布视图,主要由内核镜像、内核堆及物理页组成。内核堆部分见堆内存管理一节。 - -**图 1** 物理内存使用分布图 -![](/images/device-dev/kernel/figure/物理内存使用分布图.png "物理内存使用分布图") - -伙伴算法把所有空闲页帧分成9个内存块组,每组中内存块包含2的幂次方个页帧,例如:第0组的内存块包含2的0次方个页帧,即1个页帧;第8组的内存块包含2的8次方个页帧,即256个页帧。相同大小的内存块挂在同一个链表上进行管理。 - -- 申请内存 - - 系统申请12KiB内存,即3个页帧时,9个内存块组中索引为3的链表挂着一块大小为8个页帧的内存块满足要求,分配出12KiB内存后还剩余20KiB内存,即5个页帧,将5个页帧分成2的幂次方之和,即4跟1,尝试查找伙伴进行合并。4个页帧的内存块没有伙伴则直接插到索引为2的链表上,继续查找1个页帧的内存块是否有伙伴,索引为0的链表上此时有1个,如果两个内存块地址连续则进行合并,并将内存块挂到索引为1的链表上,否则不做处理。 - - **图 2** 内存申请示意图 - ![](/images/device-dev/kernel/figure/内存申请示意图.png "内存申请示意图") - - -- 释放内存 - - 系统释放12KiB内存,即3个页帧,将3个页帧分成2的幂次方之和,即2跟1,尝试查找伙伴进行合并,索引为1的链表上有1个内存块,若地址连续则合并,并将合并后的内存块挂到索引为2的链表上,索引为0的链表上此时也有1个,如果地址连续则进行合并,并将合并后的内存块挂到索引为1的链表上,此时继续判断是否有伙伴,重复上述操作。 - - **图 3** 内存释放示意图 - ![](/images/device-dev/kernel/figure/内存释放示意图.png "内存释放示意图") - - -## 开发指导 - -### 接口说明 - -**表 1** 物理内存管理模块接口 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名称

-

描述

-

申请物理内存

-

LOS_PhysPageAlloc

-

申请一个物理页

-

LOS_PhysPagesAlloc

-

申请物理页并挂在对应的链表上

-

LOS_PhysPagesAllocContiguous

-

申请多页地址连续的物理内存

-

释放物理内存

-

LOS_PhysPageFree

-

释放一个物理页

-

LOS_PhysPagesFree

-

释放挂在链表上的物理页

-

LOS_PhysPagesFreeContiguous

-

释放多页地址连续的物理内存

-

查询地址

-

LOS_VmPageGet

-

根据物理地址获取其对应的物理页结构体指针

-

LOS_PaddrToKVaddr

-

根据物理地址获取其对应的内核虚拟地址

-
- -### 开发流程 - -内存申请时根据需要调用相关接口,小内存申请建议使用堆内存申请相关接口,4KiB及以上内存申请可以使用上述物理内存相关接口。 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->- 物理内存申请相关接口需要在OsSysMemInit接口完成初始化之后再使用; ->- 内存申请的基本单位是页帧,即4KiB; ->- 物理内存申请时,有地址连续要求的使用LOS\_PhysPagesAllocContiguous接口,无地址连续的要求尽量使用LOS\_PhysPagesAlloc接口,将连续的大块内存留给有需要的模块使用。 - -### 编程实例 - -编程示例主要是调用申请、释放接口对内存进行操作,包括申请一个页以及多个页的示例。 - -``` -#include "los_vm_phys.h" - -#define PHYS_PAGE_SIZE 0x4000 - -// 申请一个页 -VOID OsPhysPagesAllocTest3(VOID) -{ - PADDR_T newPaddr; - VOID *kvaddr = NULL; - LosVmPage *newPage = NULL; - - newPage = LOS_PhysPageAlloc(); - if (newPage == NULL) { - printf("LOS_PhysPageAlloc fail\n"); - return; - } - printf("LOS_PhysPageAlloc success\n"); - - newPaddr = VM_PAGE_TO_PHYS(newPage); - kvaddr = OsVmPageToVaddr(newPage); - - // Handle the physical memory - - // Free the physical memory - LOS_PhysPageFree(newPage); -} - -// 申请多个页,不要求连续 -VOID OsPhysPagesAllocTest2(VOID) -{ - UINT32 sizeCount; - UINT32 count; - UINT32 size = PHYS_PAGE_SIZE; - LosVmPage *vmPageArray[PHYS_PAGE_SIZE >> PAGE_SHIFT] = { NULL }; - UINT32 i = 0; - LosVmPage *vmPage = NULL; - PADDR_T pa; - - size = LOS_Align(size, PAGE_SIZE); - if (size == 0) { - return; - } - sizeCount = size >> PAGE_SHIFT; - - LOS_DL_LIST_HEAD(pageList); - - count = LOS_PhysPagesAlloc(sizeCount, &pageList); - if (count < sizeCount) { - printf("failed to allocate enough pages (ask %zu, got %zu)\n", sizeCount, count); - goto ERROR; - } - printf("LOS_PhysPagesAlloc success\n"); - while ((vmPage = LOS_ListRemoveHeadType(&pageList, LosVmPage, node))) { - pa = vmPage->physAddr; - vmPageArray[i++] = vmPage; - // Handle the physical memory - } - - // Free the physical memory - for (i = 0; i < sizeCount; ++i) { - LOS_PhysPageFree(vmPageArray[i]); - } - - return; - -ERROR: - (VOID)LOS_PhysPagesFree(&pageList); -} - -// 申请多个连续页 -VOID OsPhysPagesAllocTest1(VOID) -{ - VOID *ptr = NULL; - LosVmPage *page = NULL; - UINT32 size = PHYS_PAGE_SIZE; - - ptr = LOS_PhysPagesAllocContiguous(ROUNDUP(size, PAGE_SIZE) >> PAGE_SHIFT); - if (ptr == NULL) { - printf("LOS_PhysPagesAllocContiguous fail\n"); - return; - } - - printf("LOS_PhysPagesAllocContiguous success\n"); - - // Handle the physical memory - - // Free the physical memory - page = OsVmVaddrToPage((VOID *)ptr); - LOS_PhysPagesFreeContiguous((VOID *)ptr, size >> PAGE_SHIFT); -} - -UINT32 ExamplePhyMemCaseEntry(VOID) -{ - OsPhysPagesAllocTest1(); - OsPhysPagesAllocTest2(); - OsPhysPagesAllocTest3(); - return LOS_OK; -} -``` - -### 结果验证 - -编译运行得到的结果为: - -``` -LOS_PhysPagesAllocContiguous success -LOS_PhysPagesAlloc success -LOS_PhysPageAlloc success -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/03.\345\206\205\345\255\230\347\256\241\347\220\206/03.\350\231\232\346\213\237\345\206\205\345\255\230\347\256\241\347\220\206.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/03.\345\206\205\345\255\230\347\256\241\347\220\206/03.\350\231\232\346\213\237\345\206\205\345\255\230\347\256\241\347\220\206.md" deleted file mode 100644 index 252601f1a90eeb0fa05c4a91430a02bb54e4f8c8..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/03.\345\206\205\345\255\230\347\256\241\347\220\206/03.\350\231\232\346\213\237\345\206\205\345\255\230\347\256\241\347\220\206.md" +++ /dev/null @@ -1,346 +0,0 @@ ---- -title: 虚拟内存管理 -permalink: /pages/01050102030303 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# 虚拟内存管理 - -- [基本概念](#section650193717411) -- [运行机制](#section072885512412) -- [开发指导](#section20956116050) - - [接口说明](#section166137221657) - - [开发流程](#section8752103914513) - - -## 基本概念 - -虚拟内存管理是计算机系统管理内存的一种技术。每个进程都有连续的虚拟地址空间,虚拟地址空间的大小由CPU的位数决定,32位的硬件平台可以提供的最大的寻址空间为0-4GiB。整个4GiB空间分成两部分,LiteOS-A内核占据3GiB的高地址空间,1GiB的低地址空间留给进程使用。各个进程空间的虚拟地址空间是独立的,代码、数据互不影响。 - -系统将虚拟内存分割为称为虚拟页的内存块,大小一般为4KiB或64KiB,LiteOS-A内核默认的页的大小是4KiB,根据需要可以对MMU(Memory Management Units)进行配置。虚拟内存管理操作的最小单位就是一个页,LiteOS-A内核中一个虚拟地址区间region包含地址连续的多个虚拟页,也可只有一个页。同样,物理内存也会按照页大小进行分割,分割后的每个内存块称为页帧。虚拟地址空间划分:内核态占高地址3GiB\(0x40000000 \~ 0xFFFFFFFF\),用户态占低地址1GiB\(0x01000000 \~ 0x3F000000\),具体见下表,详细可以查看或配置los\_vm\_zone.h。 - -**表 1** 内核态地址规划: - - - - - - - - - - - - - - - - - - - - -

Zone名称

-

描述

-

属性

-

DMA zone

-

供IO设备的DMA使用。

-

Uncache

-

Normal zone

-

加载内核代码段、数据段、堆和栈的地址区间。

-

Cache

-

high mem zone

-

可以分配连续的虚拟内存,但其所映射的物理内存不一定连续。

-

Cache

-
- -**表 2** 用户态虚地址规划: - - - - - - - - - - - - - - - - - - - - - - - - -

Zone名称

-

描述

-

属性

-

代码段

-

用户态代码段地址区间。

-

Cache

-

-

用户态堆地址区间。

-

Cache

-

-

用户态栈地址区间。

-

Cache

-

共享库

-

用于加载用户态共享库的地址区间,包括mmap所映射的区间。

-

Cache

-
- -## 运行机制 - -虚拟内存管理中,虚拟地址空间是连续的,但是其映射的物理内存并不一定是连续的,如下图所示。可执行程序加载运行,CPU访问虚拟地址空间的代码或数据时存在两种情况: - -- CPU访问的虚拟地址所在的页,如V0,已经与具体的物理页P0做映射,CPU通过找到进程对应的页表条目(详见[虚实映射](/pages/01050102030304)),根据页表条目中的物理地址信息访问物理内存中的内容并返回。 -- CPU访问的虚拟地址所在的页,如V2,没有与具体的物理页做映射,系统会触发缺页异常,系统申请一个物理页,并把相应的信息拷贝到物理页中,并且把物理页的起始地址更新到页表条目中。此时CPU重新执行访问虚拟内存的指令便能够访问到具体的代码或数据。 - -**图 1** 内存映射示意图 -![](/images/device-dev/kernel/figure/内存映射示意图.png "内存映射示意图") - -## 开发指导 - -### 接口说明 - -**表 3** 虚拟内存管理模块接口 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名称

-

描述

-

获取进程空间系列接口

-

LOS_CurrSpaceGet

-

获取当前进程空间结构体指针

-

LOS_SpaceGet

-

获取虚拟地址对应的进程空间结构体指针

-

LOS_GetKVmSpace

-

获取内核进程空间结构体指针

-

LOS_GetVmallocSpace

-

获取vmalloc空间结构体指针

-

LOS_GetVmSpaceList

-

获取进程空间链表指针

-

虚拟地址区间region相关的操作

-

LOS_RegionFind

-

根据起始地址在进程空间内查找是否存在虚拟地址区间

-

LOS_RegionRangeFind

-

根据地址区间在进程空间内查找是否存在虚拟地址区间

-

LOS_IsRegionFileValid

-

判断虚拟地址区间region是否与文件关联映射

-

LOS_RegionAlloc

-

申请空闲的虚拟地址区间

-

LOS_RegionFree

-

释放进程空间内特定的region

-

LOS_RegionEndAddr

-

获取指定地址区间region的结束地址

-

LOS_RegionSize

-

获取region的大小

-

LOS_IsRegionTypeFile

-

判断是否为文件内存映射

-

LOS_IsRegionPermUserReadOnly

-

判断地址区间是否是用户空间只读属性

-

LOS_IsRegionFlagPrivateOnly

-

判断地址区间是否是具有私有属性

-

LOS_SetRegionTypeFile

-

设置文件内存映射属性

-

LOS_IsRegionTypeDev

-

判断是否为设备内存映射

-

LOS_SetRegionTypeDev

-

设置设备内存映射属性

-

LOS_IsRegionTypeAnon

-

判断是否为匿名映射

-

LOS_SetRegionTypeAnon

-

设置匿名映射属性

-

地址校验

-

LOS_IsUserAddress

-

判断地址是否在用户态空间

-

LOS_IsUserAddressRange

-

判断地址区间是否在用户态空间

-

LOS_IsKernelAddress

-

判断地址是否在内核空间

-

LOS_IsKernelAddressRange

-

判断地址区间是否在内核空间

-

LOS_IsRangeInSpace

-

判断地址区间是否在进程空间内

-

vmalloc操作

-

LOS_VMalloc

-

vmalloc申请内存

-

LOS_VFree

-

vmalloc释放内存

-

LOS_IsVmallocAddress

-

判断地址是否是通过vmalloc申请的

-

内存申请系列接口

-

LOS_KernelMalloc

-

申请小于16KiB的内存则通过堆内存池获取,否则申请多个连续物理页

-

LOS_KernelMallocAlign

-

申请具有对齐属性的内存,申请规则:申请小于16KiB的内存则通过堆内存池获取,否则申请多个连续物理页

-

LOS_KernelFree

-

释放内核堆内存

-

LOS_KernelRealloc

-

重新分配内核内存空间

-

其他

-

LOS_PaddrQuery

-

根据虚拟地址获取对应的物理地址

-

LOS_VmSpaceFree

-

释放进程空间,包括虚拟内存区间、页表等信息

-

LOS_VmSpaceReserve

-

在进程空间中预留一块内存空间

-

LOS_VaddrToPaddrMmap

-

将指定长度的物理地址区间与虚拟地址区间做映射,需提前申请物理地址区间

-

LOS_UserSpaceVmAlloc

-

根据地址、大小、权限等信息在用户进程空间内申请地址区间region

-
- -### 开发流程 - -虚拟内存相关接口的使用: - -1. 根据进程空间获取的系列接口可以得到进程空间结构体,进而可以读取结构体相应信息。 -2. 对虚拟地址区间做相关操作: - - 通过LOS\_RegionAlloc申请虚拟地址区间; - - - 通过LOS\_RegionFind、LOS\_RegionRangeFind可以查询是否存在相应的地址区间; - - 通过LOS\_RegionFree释放虚拟地址区间。 - -3. vmalloc接口及内存申请系列接口可以在内核中根据需要申请内存。 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->内存申请系列接口申请的内存要求物理内存是连续的,当系统内存无法满足大块连续内存的申请条件时会申请失败,一般适用于小块内存的申请;vmalloc相关接口申请的内存可以获得不连续的物理内存,但其是以页(当前系统一个页为4096字节)为单位的,当需要申请以页为整数倍的内存时可以通过vmalloc申请,例如文件系统中文件读取需要较大的缓存,便可以通过vmalloc相关接口申请内存。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/03.\345\206\205\345\255\230\347\256\241\347\220\206/04.\350\231\232\345\256\236\346\230\240\345\260\204.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/03.\345\206\205\345\255\230\347\256\241\347\220\206/04.\350\231\232\345\256\236\346\230\240\345\260\204.md" deleted file mode 100644 index 6b9a4e32bc20e90d3f371caf94882ba4fb6d6926..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/03.\345\206\205\345\255\230\347\256\241\347\220\206/04.\350\231\232\345\256\236\346\230\240\345\260\204.md" +++ /dev/null @@ -1,101 +0,0 @@ ---- -title: 虚实映射 -permalink: /pages/01050102030304 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# 虚实映射 - -- [基本概念](#section9108144913615) -- [运行机制](#section12392621871) -- [开发指导](#section10264102013713) - - [接口说明](#section195320251578) - - [开发流程](#section152774210712) - - -## 基本概念 - -虚实映射是指系统通过内存管理单元(MMU,Memory Management Unit)将进程空间的虚拟地址与实际的物理地址做映射,并指定相应的访问权限、缓存属性等。程序执行时,CPU访问的是虚拟内存,通过MMU页表条目找到对应的物理内存,并做相应的代码执行或数据读写操作。MMU的映射由页表(Page Table)来描述,其中保存虚拟地址和物理地址的映射关系以及访问权限等。每个进程在创建的时候都会创建一个页表,页表由一个个页表条目(Page Table Entry, PTE)构成,每个页表条目描述虚拟地址区间与物理地址区间的映射关系。MMU中有一块页表缓存,称为快表(TLB, Translation Lookaside Buffers),做地址转换时,MMU首先在TLB中查找,如果找到对应的页表条目可直接进行转换,提高了查询效率。CPU访问内存或外设的示意图如下: - -**图 1** CPU访问内存或外设的示意图 -![](/images/device-dev/kernel/figure/CPU访问内存或外设的示意图.png "CPU访问内存或外设的示意图") - -## 运行机制 - -虚实映射其实就是一个建立页表的过程。MMU有多级页表,LiteOS-A内核采用二级页表描述进程空间。每个一级页表条目描述符占用4个字节,可表示1MiB的内存空间的映射关系,即1GiB用户空间(LiteOS-A内核中用户空间占用1GiB)的虚拟内存空间需要1024个。系统创建用户进程时,在内存中申请一块4KiB大小的内存块作为一级页表的存储区域,二级页表根据当前进程的需要做动态的内存申请。 - -- 用户程序加载启动时,会将代码段、数据段映射进虚拟内存空间(详细可参考[动态加载与链接](/pages/010501020402)),此时并没有物理页做实际的映射; -- 程序执行时,如下图粗箭头所示,CPU访问虚拟地址,通过MMU查找是否有对应的物理内存,若该虚拟地址无对应的物理地址则触发缺页异常,内核申请物理内存并将虚实映射关系及对应的属性配置信息写进页表,并把页表条目缓存至TLB,接着CPU可直接通过转换关系访问实际的物理内存; -- 若CPU访问已缓存至TLB的页表条目,无需再访问保存在内存中的页表,可加快查找速度。 - -**图 2** CPU访问内存示意图 -![](/images/device-dev/kernel/figure/CPU访问内存示意图.png "CPU访问内存示意图") - -## 开发指导 - -### 接口说明 - -**表 1** 虚实映射模块接口 - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名称

-

描述

-

MMU相关操作

-

LOS_ArchMmuQuery

-

获取进程空间虚拟地址对应的物理地址以及映射属性。

-

LOS_ArchMmuMap

-

映射进程空间虚拟地址区间与物理地址区间。

-

LOS_ArchMmuUnmap

-

解除进程空间虚拟地址区间与物理地址区间的映射关系。

-

LOS_ArchMmuChangeProt

-

修改进程空间虚拟地址区间的映射属性。

-

LOS_ArchMmuMove

-

将进程空间一个虚拟地址区间的映射关系转移至另一块未使用的虚拟地址区间重新做映射。

-
- -### 开发流程 - -虚实映射相关接口的使用: - -1. 通过LOS\_ArchMmuMap映射一块物理内存。 -2. 对映射的地址区间做相关操作: - - 通过LOS\_ArchMmuQuery可以查询相应虚拟地址区间映射的物理地址区间及映射属性; - - - 通过LOS\_ArchMmuChangeProt修改映射属性; - - 通过LOS\_ArchMmuMove做虚拟地址区间的重映射。 - -3. 通过LOS\_ArchMmuUnmap解除映射关系。 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->上述接口的使用都是基于MMU初始化完成以及相关进程页表的建立,MMU在系统启动阶段已完成初始化,进程创建的时候会建立页表,开发者无需介入操作。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/01.\344\272\213\344\273\266.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/01.\344\272\213\344\273\266.md" deleted file mode 100644 index dc6acd35830e85d539e32201f71c51b30f258578..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/01.\344\272\213\344\273\266.md" +++ /dev/null @@ -1,264 +0,0 @@ ---- -title: 事件 -permalink: /pages/01050102030401 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# 事件 - -- [基本概念](#section122115620816) -- [运行机制](#section94611116593) - - [事件控制块](#section1161415384467) - - [事件运作原理](#section187761153144617) - -- [开发指导](#section44744471891) - - [接口说明](#section172373513919) - - [开发流程](#section1118215161013) - - [编程实例](#section19986143311020) - - [实例描述](#section128221510145718) - - [编程示例](#section71507479577) - - [结果验证](#section16570171645813) - - -## 基本概念 - -事件(Event)是一种任务间通信的机制,可用于任务间的同步。 - -多任务环境下,任务之间往往需要同步操作,一个等待即是一个同步。事件可以提供一对多、多对多的同步操作。 - -- 一对多同步模型:一个任务等待多个事件的触发。可以是任意一个事件发生时唤醒任务处理事件,也可以是几个事件都发生后才唤醒任务处理事件。 -- 多对多同步模型:多个任务等待多个事件的触发。 - -OpenHarmony LiteOS-A的事件模块提供的事件,具有如下特点: - -- 任务通过创建事件控制块来触发事件或等待事件。 -- 事件间相互独立,内部实现为一个32位无符号整型,每一位标识一种事件类型。第25位不可用,因此最多可支持31种事件类型。 -- 事件仅用于任务间的同步,不提供数据传输功能。 -- 多次向事件控制块写入同一事件类型,在被清零前等效于只写入一次。 -- 多个任务可以对同一事件进行读写操作。 -- 支持事件读写超时机制。 - -## 运行机制 - -### 事件控制块 - -``` -/** - * 事件控制块数据结构 - */ -typedef struct tagEvent { - UINT32 uwEventID; /* 事件集合,表示已经处理(写入和清零)的事件集合 */ - LOS_DL_LIST stEventList; /* 等待特定事件的任务链表 */ -} EVENT_CB_S, *PEVENT_CB_S; -``` - -### 事件运作原理 - -**事件初始化**:会创建一个事件控制块,该控制块维护一个已处理的事件集合,以及等待特定事件的任务链表。 - -**写事件**:会向事件控制块写入指定的事件,事件控制块更新事件集合,并遍历任务链表,根据任务等待具体条件满足情况决定是否唤醒相关任务。 - -**读事件**:如果读取的事件已存在时,会直接同步返回。其他情况会根据超时时间以及事件触发情况,来决定返回时机:等待的事件条件在超时时间耗尽之前到达,阻塞任务会被直接唤醒,否则超时时间耗尽该任务才会被唤醒。 - -读事件条件满足与否取决于入参eventMask和mode,eventMask即需要关注的事件类型掩码。mode是具体处理方式,分以下三种情况: - -- LOS\_WAITMODE\_AND:逻辑与,基于接口传入的事件类型掩码eventMask,只有这些事件都已经发生才能读取成功,否则该任务将阻塞等待或者返回错误码。 -- LOS\_WAITMODE\_OR:逻辑或,基于接口传入的事件类型掩码eventMask,只要这些事件中有任一种事件发生就可以读取成功,否则该任务将阻塞等待或者返回错误码。 -- LOS\_WAITMODE\_CLR:这是一种附加读取模式,需要与所有事件模式或任一事件模式结合使用(LOS\_WAITMODE\_AND | LOS\_WAITMODE\_CLR或 LOS\_WAITMODE\_OR | LOS\_WAITMODE\_CLR)。在这种模式下,当设置的所有事件模式或任一事件模式读取成功后,会自动清除事件控制块中对应的事件类型位。 - -**事件清零**:根据指定掩码,去对事件控制块的事件集合进行清零操作。当掩码为0时,表示将事件集合全部清零。当掩码为0xffff时,表示不清除任何事件,保持事件集合原状。 - -**事件销毁**:销毁指定的事件控制块。 - -**图 1** 事件运作原理图 -![](/images/device-dev/kernel/figure/事件运作原理图-21.png "事件运作原理图-21") - -## 开发指导 - -### 接口说明 - -OpenHarmony LiteOS-A内核的事件模块提供下面几种功能。 - -**表 1** 事件模块接口 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名称

-

描述

-

初始化事件

-

LOS_EventInit

-

初始化一个事件控制块

-

读/写事件

-

LOS_EventRead

-

读取指定事件类型,超时时间为相对时间:单位为Tick

-

LOS_EventWrite

-

写指定的事件类型

-

清除事件

-

LOS_EventClear

-

清除指定的事件类型

-

校验事件掩码

-

LOS_EventPoll

-

根据用户传入的事件ID、事件掩码及读取模式,返回用户传入的事件是否符合预期

-

销毁事件

-

LOS_EventDestroy

-

销毁指定的事件控制块

-
- -### 开发流程 - -事件的典型开发流程: - -1. 初始化事件控制块 -2. 阻塞读事件控制块 -3. 写入相关事件 -4. 阻塞任务被唤醒,读取事件并检查是否满足要求 -5. 处理事件控制块 -6. 事件控制块销毁 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->- 进行事件读写操作时,事件的第25位为保留位,不可以进行位设置。 ->- 对同一事件反复写入,算作一次写入。 - -### 编程实例 - -### 实例描述 - -示例中,任务Example\_TaskEntry创建一个任务Example\_Event,Example\_Event读事件阻塞,Example\_TaskEntry向该任务写事件。可以通过示例日志中打印的先后顺序理解事件操作时伴随的任务切换。 - -1. 在任务Example\_TaskEntry创建任务Example\_Event,其中任务Example\_Event优先级高于Example\_TaskEntry。 -2. 在任务Example\_Event中读事件0x00000001,阻塞,发生任务切换,执行任务Example\_TaskEntry。 -3. 在任务Example\_TaskEntry向任务Example\_Event写事件0x00000001,发生任务切换,执行任务Example\_Event。 -4. Example\_Event得以执行,直到任务结束。 -5. Example\_TaskEntry得以执行,直到任务结束。 - -### 编程示例 - -示例代码如下: - -``` -#include "los_event.h" -#include "los_task.h" -#include "securec.h" - -/* 任务ID */ -UINT32 g_testTaskId; - -/* 事件控制结构体 */ -EVENT_CB_S g_exampleEvent; - -/* 等待的事件类型 */ -#define EVENT_WAIT 0x00000001 - -/* 用例任务入口函数 */ -VOID Example_Event(VOID) -{ - UINT32 event; - - /* 超时等待方式读事件,超时时间为100 ticks, 若100 ticks后未读取到指定事件,读事件超时,任务直接唤醒 */ - printf("Example_Event wait event 0x%x \n", EVENT_WAIT); - - event = LOS_EventRead(&g_exampleEvent, EVENT_WAIT, LOS_WAITMODE_AND, 100); - if (event == EVENT_WAIT) { - printf("Example_Event,read event :0x%x\n", event); - } else { - printf("Example_Event,read event timeout\n"); - } -} - -UINT32 Example_EventEntry(VOID) -{ - UINT32 ret; - TSK_INIT_PARAM_S task1; - - /* 事件初始化 */ - ret = LOS_EventInit(&g_exampleEvent); - if (ret != LOS_OK) { - printf("init event failed .\n"); - return -1; - } - - /* 创建任务 */ - (VOID)memset_s(&task1, sizeof(TSK_INIT_PARAM_S), 0, sizeof(TSK_INIT_PARAM_S)); - task1.pfnTaskEntry = (TSK_ENTRY_FUNC)Example_Event; - task1.pcName = "EventTsk1"; - task1.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE; - task1.usTaskPrio = 5; - ret = LOS_TaskCreate(&g_testTaskId, &task1); - if (ret != LOS_OK) { - printf("task create failed.\n"); - return LOS_NOK; - } - - /* 写g_testTaskId 等待事件 */ - printf("Example_TaskEntry write event.\n"); - - ret = LOS_EventWrite(&g_exampleEvent, EVENT_WAIT); - if (ret != LOS_OK) { - printf("event write failed.\n"); - return LOS_NOK; - } - - /* 清标志位 */ - printf("EventMask:%d\n", g_exampleEvent.uwEventID); - LOS_EventClear(&g_exampleEvent, ~g_exampleEvent.uwEventID); - printf("EventMask:%d\n", g_exampleEvent.uwEventID); - - /* 删除任务 */ - ret = LOS_TaskDelete(g_testTaskId); - if (ret != LOS_OK) { - printf("task delete failed.\n"); - return LOS_NOK; - } - - return LOS_OK; -} -``` - -### 结果验证 - -编译运行得到的结果为: - -``` -Example_Event wait event 0x1 -Example_TaskEntry write event. -Example_Event,read event :0x1 -EventMask:1 -EventMask:0 -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/02.\344\277\241\345\217\267\351\207\217.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/02.\344\277\241\345\217\267\351\207\217.md" deleted file mode 100644 index ef9a753f4a74adda530ca3807495da1e0d174b90..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/02.\344\277\241\345\217\267\351\207\217.md" +++ /dev/null @@ -1,286 +0,0 @@ ---- -title: 信号量 -permalink: /pages/01050102030402 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# 信号量 - -- [基本概念](#section1577111168131) -- [运行机制](#section118423019134) -- [开发指导](#section01419503131) - - [接口说明](#section1232345431312) - - [开发流程](#section154261711141419) - - [编程实例](#section658135571417) - - [实例描述](#section125244411653) - - [编程示例](#section1742105514512) - - [结果验证](#section11297301617) - - -## 基本概念 - -信号量(Semaphore)是一种实现任务间通信的机制,可以实现任务间同步或共享资源的互斥访问。 - -一个信号量的数据结构中,通常有一个计数值,用于对有效资源数的计数,表示剩下的可被使用的共享资源数,其值的含义分两种情况: - -- 0,表示该信号量当前不可获取,因此可能存在正在等待该信号量的任务。 -- 正值,表示该信号量当前可被获取。 - -以同步为目的的信号量和以互斥为目的的信号量在使用上有如下不同: - -- 用作互斥时,初始信号量计数值不为0,表示可用的共享资源个数。在需要使用共享资源前,先获取信号量,然后使用一个共享资源,使用完毕后释放信号量。这样在共享资源被取完,即信号量计数减至0时,其他需要获取信号量的任务将被阻塞,从而保证了共享资源的互斥访问。另外,当共享资源数为1时,建议使用二值信号量,一种类似于互斥锁的机制。 -- 用作同步时,初始信号量计数值为0。任务1获取信号量而阻塞,直到任务2或者某中断释放信号量,任务1才得以进入Ready或Running态,从而达到了任务间的同步。 - -## 运行机制 - -**信号量控制块** - -``` -/** - * 信号量控制块数据结构 - */ -typedef struct { - UINT16 semStat; /* 信号量状态 */ - UINT16 semType; /* 信号量类型 */ - UINT16 semCount; /* 信号量计数 */ - UINT16 semId; /* 信号量索引号 */ - LOS_DL_LIST semList; /* 挂接阻塞于该信号量的任务 */ -} LosSemCB; -``` - -**信号量运作原理** - -信号量允许多个任务在同一时刻访问共享资源,但会限制同一时刻访问此资源的最大任务数目。当访问资源的任务数达到该资源允许的最大数量时,会阻塞其他试图获取该资源的任务,直到有任务释放该信号量。 - -- 信号量初始化 - - 初始化时为配置的N个信号量申请内存(N值可以由用户自行配置,通过LOSCFG\_BASE\_IPC\_SEM\_LIMIT宏实现),并把所有信号量初始化成未使用,加入到未使用链表中供系统使用 - -- 信号量创建 - - 从未使用的信号量链表中获取一个信号量,并设定初值。 - -- 信号量申请 - - 若其计数器值大于0,则直接减1返回成功。否则任务阻塞,等待其它任务释放该信号量,等待的超时时间可设定。当任务被一个信号量阻塞时,将该任务挂到信号量等待任务队列的队尾。 - -- 信号量释放 - - 若没有任务等待该信号量,则直接将计数器加1返回。否则唤醒该信号量等待任务队列上的第一个任务。 - -- 信号量删除 - - 将正在使用的信号量置为未使用信号量,并挂回到未使用链表。 - - -运行示意图如下图所示: - -**图 1** 信号量运作示意图 -![](/images/device-dev/kernel/figure/信号量运作示意图-22.png "信号量运作示意图-22") - -## 开发指导 - -### 接口说明 - -**表 1** 信号量模块接口 - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名称

-

描述

-

创建/删除信号量

-

LOS_SemCreate

-

创建信号量,返回信号量ID

-

LOS_BinarySemCreate

-

创建二值信号量,其计数值最大为1

-

LOS_SemDelete

-

删除指定的信号量

-

申请/释放信号量

-

LOS_SemPend

-

申请指定的信号量,并设置超时时间

-

LOS_SemPost

-

释放指定的信号量

-
- -### 开发流程 - -1. 创建信号量LOS\_SemCreate,若要创建二值信号量则调用LOS\_BinarySemCreate。 -2. 申请信号量LOS\_SemPend。 -3. 释放信号量LOS\_SemPost。 -4. 删除信号量LOS\_SemDelete。 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->由于中断不能被阻塞,因此不能在中断中使用阻塞模式申请信号量。 - -### 编程实例 - -### 实例描述 - -本实例实现如下功能: - -1. 测试任务ExampleSem创建一个信号量,锁任务调度,创建两个任务ExampleSemTask1、ExampleSemTask2, ExampleSemTask2优先级高于ExampleSemTask1,两个任务中申请同一信号量,解锁任务调度后两任务阻塞,测试任务ExampleSem释放信号量。 -2. ExampleSemTask2得到信号量,被调度,然后任务休眠20Ticks,ExampleSemTask2延迟,ExampleSemTask1被唤醒。 -3. ExampleSemTask1定时阻塞模式申请信号量,等待时间为10Ticks,因信号量仍被ExampleSemTask2持有,ExampleSemTask1挂起,10Ticks后仍未得到信号量,ExampleSemTask1被唤醒,试图以永久阻塞模式申请信号量,ExampleSemTask1挂起。 -4. 20Tick后ExampleSemTask2唤醒, 释放信号量后,ExampleSemTask1得到信号量被调度运行,最后释放信号量。 -5. ExampleSemTask1执行完,400Ticks后任务ExampleSem被唤醒,执行删除信号量。 - -### 编程示例 - -示例代码如下: - -``` -#include "los_sem.h" -#include "securec.h" - -/* 任务ID */ -static UINT32 g_testTaskId01; -static UINT32 g_testTaskId02; - -/* 测试任务优先级 */ -#define TASK_PRIO_TEST 5 - -/* 信号量结构体id */ -static UINT32 g_semId; - -VOID ExampleSemTask1(VOID) -{ - UINT32 ret; - - printf("ExampleSemTask1 try get sem g_semId, timeout 10 ticks.\n"); - - /* 定时阻塞模式申请信号量,定时时间为10ticks */ - ret = LOS_SemPend(g_semId, 10); - - /* 申请到信号量 */ - if (ret == LOS_OK) { - LOS_SemPost(g_semId); - return; - } - /* 定时时间到,未申请到信号量 */ - if (ret == LOS_ERRNO_SEM_TIMEOUT) { - printf("ExampleSemTask1 timeout and try get sem g_semId wait forever.\n"); - - /*永久阻塞模式申请信号量*/ - ret = LOS_SemPend(g_semId, LOS_WAIT_FOREVER); - printf("ExampleSemTask1 wait_forever and get sem g_semId.\n"); - if (ret == LOS_OK) { - LOS_SemPost(g_semId); - return; - } - } -} - -VOID ExampleSemTask2(VOID) -{ - UINT32 ret; - printf("ExampleSemTask2 try get sem g_semId wait forever.\n"); - - /* 永久阻塞模式申请信号量 */ - ret = LOS_SemPend(g_semId, LOS_WAIT_FOREVER); - - if (ret == LOS_OK) { - printf("ExampleSemTask2 get sem g_semId and then delay 20 ticks.\n"); - } - - /* 任务休眠20 ticks */ - LOS_TaskDelay(20); - - printf("ExampleSemTask2 post sem g_semId.\n"); - /* 释放信号量 */ - LOS_SemPost(g_semId); - return; -} - -UINT32 ExampleSem(VOID) -{ - UINT32 ret; - TSK_INIT_PARAM_S task1; - TSK_INIT_PARAM_S task2; - - /* 创建信号量 */ - LOS_SemCreate(0, &g_semId); - - /* 锁任务调度 */ - LOS_TaskLock(); - - /* 创建任务1 */ - (VOID)memset_s(&task1, sizeof(TSK_INIT_PARAM_S), 0, sizeof(TSK_INIT_PARAM_S)); - task1.pfnTaskEntry = (TSK_ENTRY_FUNC)ExampleSemTask1; - task1.pcName = "TestTask1"; - task1.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE; - task1.usTaskPrio = TASK_PRIO_TEST; - ret = LOS_TaskCreate(&g_testTaskId01, &task1); - if (ret != LOS_OK) { - printf("task1 create failed .\n"); - return LOS_NOK; - } - - /* 创建任务2 */ - (VOID)memset_s(&task2, sizeof(TSK_INIT_PARAM_S), 0, sizeof(TSK_INIT_PARAM_S)); - task2.pfnTaskEntry = (TSK_ENTRY_FUNC)ExampleSemTask2; - task2.pcName = "TestTask2"; - task2.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE; - task2.usTaskPrio = (TASK_PRIO_TEST - 1); - ret = LOS_TaskCreate(&g_testTaskId02, &task2); - if (ret != LOS_OK) { - printf("task2 create failed.\n"); - return LOS_NOK; - } - - /* 解锁任务调度 */ - LOS_TaskUnlock(); - - ret = LOS_SemPost(g_semId); - - /* 任务休眠400 ticks */ - LOS_TaskDelay(400); - - /* 删除信号量 */ - LOS_SemDelete(g_semId); - return LOS_OK; -} -``` - -### 结果验证 - -编译运行得到的结果为: - -``` -ExampleSemTask2 try get sem g_semId wait forever. -ExampleSemTask2 get sem g_semId and then delay 20 ticks. -ExampleSemTask1 try get sem g_semId, timeout 10 ticks. -ExampleSemTask1 timeout and try get sem g_semId wait forever. -ExampleSemTask2 post sem g_semId. -ExampleSemTask1 wait_forever and get sem g_semId. -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/03.\344\272\222\346\226\245\351\224\201.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/03.\344\272\222\346\226\245\351\224\201.md" deleted file mode 100644 index 6a32c365a852a3eaf3e25209bf5808df139ca666..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/03.\344\272\222\346\226\245\351\224\201.md" +++ /dev/null @@ -1,330 +0,0 @@ ---- -title: 互斥锁 -permalink: /pages/01050102030403 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# 互斥锁 - -- [基本概念](#section85865329185) -- [运行机制](#section8547454201819) -- [开发指导](#section2038861117194) - - [接口说明](#section11168318131917) - - [开发流程](#section4201191122116) - - [编程实例](#section10679328202117) - - -## 基本概念 - -互斥锁又称互斥型信号量,用于实现对共享资源的独占式处理。当有任务持有时,这个任务获得该互斥锁的所有权。当该任务释放它时,任务失去该互斥锁的所有权。当一个任务持有互斥锁时,其他任务将不能再持有该互斥锁。多任务环境下往往存在多个任务竞争同一共享资源的应用场景,互斥锁可被用于对共享资源的保护从而实现独占式访问。 - -互斥锁属性包含3个属性:协议属性、优先级上限属性和类型属性。协议属性用于处理不同优先级的任务申请互斥锁,协议属性包含如下三种: - -- LOS\_MUX\_PRIO\_NONE - - 不对申请互斥锁的任务的优先级进行继承或保护操作。 - -- LOS\_MUX\_PRIO\_INHERIT - - 优先级继承属性,默认设置为该属性,对申请互斥锁的任务的优先级进行继承。在互斥锁设置为本协议属性情况下,申请互斥锁时,如果高优先级任务阻塞于互斥锁,则把持有互斥锁任务的优先级备份到任务控制块的优先级位图中,然后把任务优先级设置为和高优先级任务相同的优先级;持有互斥锁的任务释放互斥锁时,从任务控制块的优先级位图恢复任务优先级。 - -- LOS\_MUX\_PRIO\_PROTECT - - 优先级保护属性,对申请互斥锁的任务的优先级进行保护。在互斥锁设置为本协议属性情况下,申请互斥锁时,如果任务优先级小于互斥锁优先级上限,则把任务优先级备份到任务控制块的优先级位图中,然后把任务优先级设置为互斥锁优先级上限属性值;释放互斥锁时,从任务控制块的优先级位图恢复任务优先级。 - - -互斥锁的类型属性用于标记是否检测死锁,是否支持递归持有,类型属性包含如下三种: - -- LOS\_MUX\_NORMAL - - 普通互斥锁,不会检测死锁。如果任务试图对一个互斥锁重复持有,将会引起这个线程的死锁。如果试图释放一个由别的任务持有的互斥锁,或者如果一个任务试图重复释放互斥锁都会引发不可预料的结果。 - -- LOS\_MUX\_RECURSIVE - - 递归互斥锁,默认设置为该属性。在互斥锁设置为本类型属性情况下,允许同一个任务对互斥锁进行多次持有锁,持有锁次数和释放锁次数相同,其他任务才能持有该互斥锁。如果试图持有已经被其他任务持有的互斥锁,或者如果试图释放已经被释放的互斥锁,会返回错误码。 - -- LOS\_MUX\_ERRORCHECK - - 错误检测互斥锁,会自动检测死锁。在互斥锁设置为本类型属性情况下,如果任务试图对一个互斥锁重复持有,或者试图释放一个由别的任务持有的互斥锁,或者如果一个任务试图释放已经被释放的互斥锁,都会返回错误码。 - - -## 运行机制 - -多任务环境下会存在多个任务访问同一公共资源的场景,而有些公共资源是非共享的,需要任务进行独占式处理。互斥锁怎样来避免这种冲突呢? - -用互斥锁处理非共享资源的同步访问时,如果有任务访问该资源,则互斥锁为加锁状态。此时其他任务如果想访问这个公共资源则会被阻塞,直到互斥锁被持有该锁的任务释放后,其他任务才能重新访问该公共资源,此时互斥锁再次上锁,如此确保同一时刻只有一个任务正在访问这个公共资源,保证了公共资源操作的完整性。 - -**图 1** 互斥锁运作示意图 -![](/images/device-dev/kernel/figure/互斥锁运作示意图-23.png "互斥锁运作示意图-23") - -## 开发指导 - -### 接口说明 - -**表 1** 互斥锁模块接口 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名称

-

描述

-

初始化和销毁互斥锁

-

LOS_MuxInit

-

互斥锁初始化

-

LOS_MuxDestroy

-

销毁指定的互斥锁

-

互斥锁的申请和释放

-

LOS_MuxLock

-

申请指定的互斥锁

-

LOS_MuxTrylock

-

尝试申请指定的互斥锁,不阻塞

-

LOS_MuxUnlock

-

释放指定的互斥锁

-

校验互斥锁

-

LOS_MuxIsValid

-

判断互斥锁释放有效

-

初始化和销毁互斥锁属性

-

LOS_MuxAttrInit

-

互斥锁属性初始化

-

LOS_MuxAttrDestroy

-

销毁指定的互斥锁属性

-

设置和获取互斥锁属性

-

LOS_MuxAttrGetType

-

获取指定互斥锁属性的类型属性

-

LOS_MuxAttrSetType

-

设置指定互斥锁属性的类型属性

-

LOS_MuxAttrGetProtocol

-

获取指定互斥锁属性的协议属性

-

LOS_MuxAttrSetProtocol

-

设置指定互斥锁属性的协议属性

-

LOS_MuxAttrGetPrioceiling

-

获取指定互斥锁属性的优先级上限属性

-

LOS_MuxAttrSetPrioceiling

-

设置指定互斥锁属性的优先级上限属性

-

LOS_MuxGetPrioceiling

-

获取互斥锁优先级上限属性

-

LOS_MuxSetPrioceiling

-

设置互斥锁优先级上限属性

-
- -### 开发流程 - -互斥锁典型场景的开发流程: - -1. 初始化互斥锁LOS\_MuxInit。 - -2. 申请互斥锁LOS\_MuxLock。 - -申请模式有三种:无阻塞模式、永久阻塞模式、定时阻塞模式。 - -- 无阻塞模式:任务需要申请互斥锁,若该互斥锁当前没有任务持有,或者持有该互斥锁的任务和申请该互斥锁的任务为同一个任务,则申请成功; -- 永久阻塞模式:任务需要申请互斥锁,若该互斥锁当前没有被占用,则申请成功。否则,该任务进入阻塞态,系统切换到就绪任务中优先级高者继续执行。任务进入阻塞态后,直到有其他任务释放该互斥锁,阻塞任务才会重新得以执行; -- 定时阻塞模式:任务需要申请互斥锁,若该互斥锁当前没有被占用,则申请成功。否则该任务进入阻塞态,系统切换到就绪任务中优先级高者继续执行。任务进入阻塞态后,指定时间超时前有其他任务释放该互斥锁,或者用 户指定时间超时后,阻塞任务才会重新得以执行。 - -3. 释放互斥锁LOS\_MuxUnlock。 - -- 如果有任务阻塞于指定互斥锁,则唤醒被阻塞任务中优先级高的,该任务进入就绪态,并进行任务调度; -- 如果没有任务阻塞于指定互斥锁,则互斥锁释放成功。 - -4. 销毁互斥锁LOS\_MuxDestroy。 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->- 两个任务不能对同一把互斥锁加锁。如果某任务对已被持有的互斥锁加锁,则该任务会被挂起,直到持有该锁的任务对互斥锁解锁,才能执行对这把互斥锁的加锁操作。 ->- 互斥锁不能在中断服务程序中使用。 ->- LiteOS-A内核作为实时操作系统需要保证任务调度的实时性,尽量避免任务的长时间阻塞,因此在获得互斥锁之后,应该尽快释放互斥锁。 - -### 编程实例 - -**实例描述** - -本实例实现如下流程: - -1. 任务Example\_TaskEntry创建一个互斥锁,锁任务调度,创建两个任务Example\_MutexTask1、Example\_MutexTask2。Example\_MutexTask2优先级高于Example\_MutexTask1,解锁任务调度。 -2. Example\_MutexTask2被调度,以永久阻塞模式申请互斥锁,并成功获取到该互斥锁,然后任务休眠100Tick,Example\_MutexTask2挂起,Example\_MutexTask1被唤醒。 -3. Example\_MutexTask1以定时阻塞模式申请互斥锁,等待时间为10Tick,因互斥锁仍被Example\_MutexTask2持有,Example\_MutexTask1挂起。10Tick超时时间到达后,Example\_MutexTask1被唤醒,以永久阻塞模式申请互斥锁,因互斥锁仍被Example\_MutexTask2持有,Example\_MutexTask1挂起。 -4. 100Tick休眠时间到达后,Example\_MutexTask2被唤醒, 释放互斥锁,唤醒Example\_MutexTask1。Example\_MutexTask1成功获取到互斥锁后,释放,删除互斥锁。 - -**示例代码** - -示例代码如下: - -``` -#include -#include "los_mux.h" - -/* 互斥锁 */ -LosMux g_testMux; -/* 任务ID */ -UINT32 g_testTaskId01; -UINT32 g_testTaskId02; - -VOID Example_MutexTask1(VOID) -{ - UINT32 ret; - - printf("task1 try to get mutex, wait 10 ticks.\n"); - /* 申请互斥锁 */ - ret = LOS_MuxLock(&g_testMux, 10); - - if (ret == LOS_OK) { - printf("task1 get mutex g_testMux.\n"); - /* 释放互斥锁 */ - LOS_MuxUnlock(&g_testMux); - return; - } - if (ret == LOS_ETIMEDOUT ) { - printf("task1 timeout and try to get mutex, wait forever.\n"); - /* 申请互斥锁 */ - ret = LOS_MuxLock(&g_testMux, LOS_WAIT_FOREVER); - if (ret == LOS_OK) { - printf("task1 wait forever, get mutex g_testMux.\n"); - /* 释放互斥锁 */ - LOS_MuxUnlock(&g_testMux); - /* 删除互斥锁 */ - LOS_MuxDestroy(&g_testMux); - printf("task1 post and delete mutex g_testMux.\n"); - return; - } - } - return; -} - -VOID Example_MutexTask2(VOID) -{ - printf("task2 try to get mutex, wait forever.\n"); - /* 申请互斥锁 */ - (VOID)LOS_MuxLock(&g_testMux, LOS_WAIT_FOREVER); - - printf("task2 get mutex g_testMux and suspend 100 ticks.\n"); - - /* 任务休眠100Ticks */ - LOS_TaskDelay(100); - - printf("task2 resumed and post the g_testMux\n"); - /* 释放互斥锁 */ - LOS_MuxUnlock(&g_testMux); - return; -} - -UINT32 Example_MutexEntry(VOID) -{ - UINT32 ret; - TSK_INIT_PARAM_S task1; - TSK_INIT_PARAM_S task2; - - /* 初始化互斥锁 */ - LOS_MuxInit(&g_testMux, NULL); - - /* 锁任务调度 */ - LOS_TaskLock(); - - /* 创建任务1 */ - memset(&task1, 0, sizeof(TSK_INIT_PARAM_S)); - task1.pfnTaskEntry = (TSK_ENTRY_FUNC)Example_MutexTask1; - task1.pcName = "MutexTsk1"; - task1.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE; - task1.usTaskPrio = 5; - ret = LOS_TaskCreate(&g_testTaskId01, &task1); - if (ret != LOS_OK) { - printf("task1 create failed.\n"); - return LOS_NOK; - } - - /* 创建任务2 */ - memset(&task2, 0, sizeof(TSK_INIT_PARAM_S)); - task2.pfnTaskEntry = (TSK_ENTRY_FUNC)Example_MutexTask2; - task2.pcName = "MutexTsk2"; - task2.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE; - task2.usTaskPrio = 4; - ret = LOS_TaskCreate(&g_testTaskId02, &task2); - if (ret != LOS_OK) { - printf("task2 create failed.\n"); - return LOS_NOK; - } - - /* 解锁任务调度 */ - LOS_TaskUnlock(); - - return LOS_OK; -} -``` - -**结果验证** - -编译运行得到的结果为: - -``` -task1 try to get mutex, wait 10 ticks. -task2 try to get mutex, wait forever. -task2 get mutex g_testMux and suspend 100 ticks. -task1 timeout and try to get mutex, wait forever. -task2 resumed and post the g_testMux -task1 wait forever, get mutex g_testMux. -task1 post and delete mutex g_testMux. -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/04.\346\266\210\346\201\257\351\230\237\345\210\227.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/04.\346\266\210\346\201\257\351\230\237\345\210\227.md" deleted file mode 100644 index 49c964dd773ebfcba65d25436e89a3f2e664b737..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/04.\346\266\210\346\201\257\351\230\237\345\210\227.md" +++ /dev/null @@ -1,279 +0,0 @@ ---- -title: 消息队列 -permalink: /pages/01050102030404 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# 消息队列 - -- [基本概念](#section81171363232) -- [运行机制](#section1074515132316) - - [队列控制块](#section194431851201315) - - [队列运作原理](#section89875741418) - -- [开发指导](#section827981242419) - - [接口说明](#section19327151642413) - - [开发流程](#section1390154210243) - -- [编程实例](#section27132341285) - - [实例描述](#section197311443141017) - - [编程示例](#section972214490107) - - [结果验证](#section19287165416106) - - -## 基本概念 - -队列又称消息队列,是一种常用于任务间通信的数据结构。队列接收来自任务或中断的不固定长度消息,并根据不同的接口确定传递的消息是否存放在队列空间中。 - -任务能够从队列里面读取消息,当队列中的消息为空时,挂起读取任务;当队列中有新消息时,挂起的读取任务被唤醒并处理新消息。任务也能够往队列里写入消息,当队列已经写满消息时,挂起写入任务;当队列中有空闲消息节点时,挂起的写入任务被唤醒并写入消息。 - -可以通过调整读队列和写队列的超时时间来调整读写接口的阻塞模式,如果将读队列和写队列的超时时间设置为0,就不会挂起任务,接口会直接返回,这就是非阻塞模式。反之,如果将都队列和写队列的超时时间设置为大于0的时间,就会以阻塞模式运行。 - -消息队列提供了异步处理机制,允许将一个消息放入队列,但不立即处理。同时队列还有缓冲消息的作用,可以使用队列实现任务异步通信,队列具有如下特性: - -- 消息以先进先出的方式排队,支持异步读写。 -- 读队列和写队列都支持超时机制。 -- 每读取一条消息,就会将该消息节点设置为空闲。 -- 发送消息类型由通信双方约定,可以允许不同长度(不超过队列的消息节点大小)的消息。 -- 一个任务能够从任意一个消息队列接收和发送消息。 -- 多个任务能够从同一个消息队列接收和发送消息。 -- 创建队列时所需的队列空间,接口内系统自行动态申请内存。 - -## 运行机制 - -### 队列控制块 - -``` -/** - * 队列控制块数据结构 - */ -typedef struct { - UINT8 *queueHandle; /**< Pointer to a queue handle */ - UINT16 queueState; /**< Queue state */ - UINT16 queueLen; /**< Queue length */ - UINT16 queueSize; /**< Node size */ - UINT32 queueID; /**< queueID */ - UINT16 queueHead; /**< Node head */ - UINT16 queueTail; /**< Node tail */ - UINT16 readWriteableCnt[OS_QUEUE_N_RW]; /**< Count of readable or writable resources, 0:readable, 1:writable */ - LOS_DL_LIST readWriteList[OS_QUEUE_N_RW]; /**< the linked list to be read or written, 0:readlist, 1:writelist */ - LOS_DL_LIST memList; /**< Pointer to the memory linked list */ -} LosQueueCB; -``` - -每个队列控制块中都含有队列状态,表示该队列的使用情况: - -- OS\_QUEUE\_UNUSED:队列未被使用。 -- OS\_QUEUE\_INUSED:队列被使用中。 - -### 队列运作原理 - -- 创建队列时,创建队列成功会返回队列ID。 -- 在队列控制块中维护着一个消息头节点位置Head和一个消息尾节点位置Tail,用于表示当前队列中消息的存储情况。Head表示队列中被占用的消息节点的起始位置。Tail表示被占用的消息节点的结束位置,也是空闲消息节点的起始位置。队列刚创建时,Head和Tail均指向队列起始位置。 -- 写队列时,根据readWriteableCnt\[1\]判断队列是否可以写入,不能对已满(readWriteableCnt\[1\]为0)队列进行写操作。写队列支持两种写入方式:向队列尾节点写入,也可以向队列头节点写入。尾节点写入时,根据Tail找到起始空闲消息节点作为数据写入对象,如果Tail已经指向队列尾部则采用回卷方式。头节点写入时,将Head的前一个节点作为数据写入对象,如果Head指向队列起始位置则采用回卷方式。 -- 读队列时,根据readWriteableCnt\[0\]判断队列是否有消息需要读取,对全部空闲(readWriteableCnt\[0\]为0)队列进行读操作会引起任务挂起。如果队列可以读取消息,则根据Head找到最先写入队列的消息节点进行读取。如果Head已经指向队列尾部则采用回卷方式。 -- 删除队列时,根据队列ID找到对应队列,把队列状态置为未使用,把队列控制块置为初始状态,并释放队列所占内存。 - -**图 1** 队列读写数据操作示意图 -![](/images/device-dev/kernel/figure/队列读写数据操作示意图.png "队列读写数据操作示意图") - -上图对读写队列做了示意,图中只画了尾节点写入方式,没有画头节点写入,但是两者是类似的。 - -## 开发指导 - -### 接口说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名称

-

描述

-

创建/删除消息队列

-

LOS_QueueCreate

-

创建一个消息队列,由系统动态申请队列空间

-

LOS_QueueDelete

-

根据队列ID删除一个指定队列

-

读/写队列(不带拷贝)

-

LOS_QueueRead

-

读取指定队列头节点中的数据(队列节点中的数据实际上是一个地址)

-

LOS_QueueWrite

-

向指定队列尾节点中写入入参bufferAddr的值(即buffer的地址)

-

LOS_QueueWriteHead

-

向指定队列头节点中写入入参bufferAddr的值(即buffer的地址)

-

读/写队列(带拷贝)

-

LOS_QueueReadCopy

-

读取指定队列头节点中的数据

-

LOS_QueueWriteCopy

-

向指定队列尾节点中写入入参bufferAddr中保存的数据

-

LOS_QueueWriteHeadCopy

-

向指定队列头节点中写入入参bufferAddr中保存的数据

-

获取队列信息

-

LOS_QueueInfoGet

-

获取指定队列的信息,包括队列ID、队列长度、消息节点大小、头节点、尾节点、可读节点数量、可写节点数量、等待读操作的任务、等待写操作的任务

-
- -### 开发流程 - -1. 用LOS\_QueueCreate创建队列。创建成功后,可以得到队列ID。 -2. 通过LOS\_QueueWrite或者LOS\_QueueWriteCopy写队列。 -3. 通过LOS\_QueueRead或者LOS\_QueueReadCopy读队列。 -4. 通过LOS\_QueueInfoGet获取队列信息。 -5. 通过LOS\_QueueDelete删除队列。 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->- 系统支持的最大队列数是指:整个系统的队列资源总个数,而非用户能使用的个数。例如:系统软件定时器多占用一个队列资源,那么用户能使用的队列资源就会减少一个。 ->- 创建队列时传入的队列名和flags暂时未使用,作为以后的预留参数。 ->- 队列接口函数中的入参timeOut是相对时间。 ->- LOS\_QueueReadCopy和LOS\_QueueWriteCopy及LOS\_QueueWriteHeadCopy是一组接口,LOS\_QueueRead和LOS\_QueueWrite及LOS\_QueueWriteHead是一组接口,每组接口需要配套使用。 ->- 鉴于LOS\_QueueWrite和LOS\_QueueWriteHead和LOS\_QueueRead这组接口实际操作的是数据地址,用户必须保证调用LOS\_QueueRead获取到的指针所指向的内存区域在读队列期间没有被异常修改或释放,否则可能导致不可预知的后果。 ->- 鉴于LOS\_QueueWrite和LOS\_QueueWriteHead和LOS\_QueueRead这组接口实际操作的是数据地址,也就意味着实际写和读的消息长度仅仅是一个指针数据,因此用户使用这组接口之前,需确保创建队列时的消息节点大小,为一个指针的长度,避免不必要的浪费和读取失败。 - -## 编程实例 - -### 实例描述 - -创建一个队列,两个任务。任务1调用写队列接口发送消息,任务2通过读队列接口接收消息。 - -1. 通过LOS\_TaskCreate创建任务1和任务2。 -2. 通过LOS\_QueueCreate创建一个消息队列。 -3. 在任务1 SendEntry中发送消息。 -4. 在任务2 RecvEntry中接收消息。 -5. 通过LOS\_QueueDelete删除队列。 - -### 编程示例 - -示例代码如下: - -``` -#include "los_task.h" -#include "los_queue.h" -static UINT32 g_queue; -#define BUFFER_LEN 50 - -VOID SendEntry(VOID) -{ - UINT32 ret = 0; - CHAR abuf[] = "test message"; - UINT32 len = sizeof(abuf); - - ret = LOS_QueueWriteCopy(g_queue, abuf, len, 0); - if(ret != LOS_OK) { - printf("send message failure, error: %x\n", ret); - } -} - -VOID RecvEntry(VOID) -{ - UINT32 ret = 0; - CHAR readBuf[BUFFER_LEN] = {0}; - UINT32 readLen = BUFFER_LEN; - - //休眠1s - usleep(1000000); - ret = LOS_QueueReadCopy(g_queue, readBuf, &readLen, 0); - if(ret != LOS_OK) { - printf("recv message failure, error: %x\n", ret); - } - - printf("recv message: %s\n", readBuf); - - ret = LOS_QueueDelete(g_queue); - if(ret != LOS_OK) { - printf("delete the queue failure, error: %x\n", ret); - } - - printf("delete the queue success!\n"); -} - -UINT32 ExampleQueue(VOID) -{ - printf("start queue example\n"); - UINT32 ret = 0; - UINT32 task1, task2; - TSK_INIT_PARAM_S initParam = {0}; - - initParam.pfnTaskEntry = (TSK_ENTRY_FUNC)SendEntry; - initParam.usTaskPrio = 9; - initParam.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE; - initParam.pcName = "SendQueue"; - - LOS_TaskLock(); - ret = LOS_TaskCreate(&task1, &initParam); - if(ret != LOS_OK) { - printf("create task1 failed, error: %x\n", ret); - return ret; - } - - initParam.pcName = "RecvQueue"; - initParam.pfnTaskEntry = (TSK_ENTRY_FUNC)RecvEntry; - ret = LOS_TaskCreate(&task2, &initParam); - if(ret != LOS_OK) { - printf("create task2 failed, error: %x\n", ret); - return ret; - } - - ret = LOS_QueueCreate("queue", 5, &g_queue, 0, 50); - if(ret != LOS_OK) { - printf("create queue failure, error: %x\n", ret); - } - - printf("create the queue success!\n"); - LOS_TaskUnlock(); - return ret; -} -``` - -### 结果验证 - -编译运行得到的结果为: - -``` -start test example -create the queue success! -recv message: test message -delete the queue success! -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/05.\350\257\273\345\206\231\351\224\201.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/05.\350\257\273\345\206\231\351\224\201.md" deleted file mode 100644 index 76f38680b913980914b55f85d98ff0c607dbdaef..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/05.\350\257\273\345\206\231\351\224\201.md" +++ /dev/null @@ -1,147 +0,0 @@ ---- -title: 读写锁 -permalink: /pages/01050102030405 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# 读写锁 - -- [基本概念](#section4692105214260) -- [运行机制](#section1239111562720) -- [开发指导](#section11643194275) - - [接口说明](#section15335332122717) - - [开发流程](#section14774114882714) - - -## 基本概念 - -读写锁与互斥锁类似,可用来同步同一进程中的各个任务,但与互斥锁不同的是,其允许多个读操作并发重入,而写操作互斥。 - -相对于互斥锁的开锁或闭锁状态,读写锁有三种状态:读模式下的锁,写模式下的锁,无锁。 - -读写锁的使用规则: - -- 保护区无写模式下的锁,任何任务均可以为其增加读模式下的锁。 -- 保护区处于无锁状态下,才可增加写模式下的锁。 - -多任务环境下往往存在多个任务访问同一共享资源的应用场景,读模式下的锁以共享状态对保护区访问,而写模式下的锁可被用于对共享资源的保护从而实现独占式访问。 - -这种共享-独占的方式非常适合多任务中读数据频率远大于写数据频率的应用中,提高应用多任务并发度。 - -## 运行机制 - -相较于互斥锁,读写锁如何实现读模式下的锁及写模式下的锁来控制多任务的读写访问呢? - -- 若A任务首次获取了写模式下的锁,有其他任务来获取或尝试获取读模式下的锁,均无法再上锁。 - -- 若A任务获取了读模式下的锁,当有任务来获取或尝试获取读模式下的锁时,读写锁计数均加一。 - -## 开发指导 - -### 接口说明 - -**表 1** 读写锁模块接口 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名称

-

描述

-

读写锁的创建和删除

-

LOS_RwlockInit

-

创建读写锁

-

LOS_RwlockDestroy

-

删除指定的读写锁

-

读模式下的锁的申请

-

LOS_RwlockRdLock

-

申请指定的读模式下的锁

-

LOS_RwlockTryRdLock

-

尝试申请指定的读模式下的锁

-

写模式下的锁的申请

-

LOS_RwlockWrLock

-

申请指定的写模式下的锁

-

LOS_RwlockTryWrLock

-

尝试申请指定的写模式下的锁

-

读写锁的释放

-

LOS_RwlockUnLock

-

释放指定读写锁

-

读写锁有效性判断

-

LOS_RwlockIsValid

-

判断读写锁有效性

-
- -### 开发流程 - -读写锁典型场景的开发流程: - -1. 创建读写锁LOS\_RwlockInit。 - -2. 申请读模式下的锁LOS\_RwlockRdLock或写模式下的锁LOS\_RwlockWrLock。 - -申请读模式下的锁: - -- 若无人持有锁,读任务可获得锁。 -- 若有人持有锁,读任务可获得锁,读取顺序按照任务优先级。 -- 若有人(非自己)持有写模式下的锁,则当前任务无法获得锁,直到写模式下的锁释放。 - -申请写模式下的锁: - -- 若该锁当前没有任务持有,或者持有该读模式下的锁的任务和申请该锁的任务为同一个任务,则申请成功,可立即获得写模式下的锁。 -- 若该锁当前已经存在读模式下的锁,且读取任务优先级较高,则当前任务挂起,直到读模式下的锁释放。 - -3.申请读模式下的锁和写模式下的锁均有三种:无阻塞模式、永久阻塞模式、定时阻塞模式,区别在于挂起任务的时间。 - -4.释放读写锁LOS\_RwlockUnLock。 - -- 如果有任务阻塞于指定读写锁,则唤醒被阻塞任务中优先级高的,该任务进入就绪态,并进行任务调度; - -- 如果没有任务阻塞于指定读写锁,则读写锁释放成功。 - -5. 删除读写锁LOS\_RwlockDestroy。 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->- 读写锁不能在中断服务程序中使用。 ->- LiteOS-A内核作为实时操作系统需要保证任务调度的实时性,尽量避免任务的长时间阻塞,因此在获得读写锁之后,应该尽快释放该锁。 ->- 持有读写锁的过程中,不得再调用LOS\_TaskPriSet等接口更改持有读写锁任务的优先级 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/06.\347\224\250\346\210\267\346\200\201\345\277\253\351\200\237\344\272\222\346\226\245\351\224\201.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/06.\347\224\250\346\210\267\346\200\201\345\277\253\351\200\237\344\272\222\346\226\245\351\224\201.md" deleted file mode 100644 index 174b194d205a5ef79be6887c406e030811447fa6..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/06.\347\224\250\346\210\267\346\200\201\345\277\253\351\200\237\344\272\222\346\226\245\351\224\201.md" +++ /dev/null @@ -1,77 +0,0 @@ ---- -title: 用户态快速互斥锁 -permalink: /pages/01050102030406 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# 用户态快速互斥锁 - -- [基本概念](#section643519912920) -- [运行机制](#section16834132502910) - -## 基本概念 - -Futex\(Fast userspace mutex,用户态快速互斥锁\)是内核提供的一种系统调用能力,通常作为基础组件与用户态的相关锁逻辑结合组成用户态锁,是一种用户态与内核态共同作用的锁,例如用户态mutex锁、barrier与cond同步锁、读写锁。其用户态部分负责锁逻辑,内核态部分负责锁调度。 - -当用户态线程请求锁时,先在用户态进行锁状态的判断维护,若此时不产生锁的竞争,则直接在用户态进行上锁返回;反之,则需要进行线程的挂起操作,通过Futex系统调用请求内核介入来挂起线程,并维护阻塞队列。 - -当用户态线程释放锁时,先在用户态进行锁状态的判断维护,若此时没有其他线程被该锁阻塞,则直接在用户态进行解锁返回;反之,则需要进行阻塞线程的唤醒操作,通过Futex系统调用请求内核介入来唤醒阻塞队列中的线程。 - -## 运行机制 - -当用户态产生锁的竞争或释放需要进行相关线程的调度操作时,会触发Futex系统调用进入内核,此时会将用户态锁的地址传入内核,并在内核的Futex中以锁地址来区分用户态的每一把锁,因为用户态可用虚拟地址空间为1GiB,为了便于查找、管理,内核Futex采用哈希桶来存放用户态传入的锁。 - -当前哈希桶共有80个,0\~63号桶用于存放私有锁(以虚拟地址进行哈希),64\~79号桶用于存放共享锁(以物理地址进行哈希),私有/共享属性通过用户态锁的初始化以及Futex系统调用入参确定。 - -**图 1** Futex设计图 -![](/images/device-dev/kernel/figure/Futex设计图.jpg "Futex设计图") - -如图1,每个futex哈希桶中存放被futex\_list串联起来的哈希值相同的futex node,每个futex node对应一个被挂起的task,node中key值唯一标识一把用户态锁,具有相同key值的node被queue\_list串联起来表示被同一把锁阻塞的task队列。 - -Futex有以下三种操作: - -**表 1** Futex模块接口 - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名称

-

描述

-

设置线程等待

-

OsFutexWait

-

向Futex表中插入代表被阻塞的线程的node

-

唤醒被阻塞线程

-

OsFutexWake

-

唤醒一个被指定锁阻塞的线程

-

调整锁的地址

-

OsFutexRequeue

-

调整指定锁在Futex表中的位置

-
- ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->Futex系统调用通常与用户态逻辑共同组成用户态锁,故推荐使用用户态POSIX接口的锁。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/07.\344\277\241\345\217\267.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/07.\344\277\241\345\217\267.md" deleted file mode 100644 index 03ddea71ee3c79d81b569c2711e246ef78c8a6a4..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/04.\345\206\205\346\240\270\351\200\232\344\277\241\346\234\272\345\210\266/07.\344\277\241\345\217\267.md" +++ /dev/null @@ -1,99 +0,0 @@ ---- -title: 信号 -permalink: /pages/01050102030407 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# 信号 - -- [基本概念](#section172788254307) -- [运行机制](#section1249693812301) - -## 基本概念 - -信号\(signal\)是一种常用的进程间异步通信机制,用软件的方式模拟中断信号,当一个进程需要传递信息给另一个进程时,则会发送一个信号给内核,再由内核将信号传递至指定进程,而指定进程不必进行等待信号的动作。 - -## 运行机制 - -信号的运作流程分为三个部分,如表1: - -**表 1** 信号的运作流程及相关接口(用户态接口) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名称

-

描述

-

注册信号回调函数

-

signal

-

注册信号总入口及注册和去注册某信号的回调函数。

-

sigaction

-

功能同signal,但增加了信号发送相关的配置选项,目前仅支持SIGINFO结构体中的部分参数。

-

发送信号

-

kill

-

发送信号给某个进程或进程内发送消息给某线程,为某进程下的线程设置信号标志位。

-

pthread_kill

-

raise

-

alarm

-

abort

-

触发回调

-

-

由系统调用与中断触发,内核态与用户态切换前会先进入用户态指定函数并处理完相应回调函数,再回到原用户态程序继续运行。

-
- ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->信号机制为提供给用户态程序进程间通信的能力,故推荐使用上表1列出的用户态POSIX相关接口。 ->注册回调函数: ->``` ->void *signal(int sig, void (*func)(int))(int); ->``` ->a. 31 号信号,该信号用来注册该进程的回调函数处理入口,不可重复注册。 ->b. 0-30 号信号,该信号段用来注册与去注册回调函数。 ->注册回调函数: ->``` ->int sigaction(int, const struct sigaction *__restrict, struct sigaction *__restrict); ->``` ->支持信号注册的配置修改和配置获取,目前仅支持SIGINFO的选项,SIGINFO内容见sigtimedwait接口内描述。 ->发送信号: ->a. 进程接收信号存在默认行为,单不支持POSIX标准所给出的STOP及COTINUE、COREDUMP功能。 ->b. 进程无法屏蔽SIGSTOP、SIGKILL、SIGCONT信号。 ->c. 某进程后被杀死后,若其父进程不回收该进程,其转为僵尸进程。 ->d. 进程接收到某信号后,直到该进程被调度后才会执行信号回调。 ->e. 进程结束后会发送SIGCHLD信号给父进程,该发送动作无法取消。 ->f. 无法通过信号唤醒处于DELAY状态的进程。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/05.\346\227\266\351\227\264\347\256\241\347\220\206.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/05.\346\227\266\351\227\264\347\256\241\347\220\206.md" deleted file mode 100644 index 2bcc8f51e1ac0ca32403408ddf33d209c0491f38..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/05.\346\227\266\351\227\264\347\256\241\347\220\206.md" +++ /dev/null @@ -1,166 +0,0 @@ ---- -title: 时间管理 -permalink: /pages/010501020305 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# 时间管理 - -- [基本概念](#section12903185785119) -- [开发指导](#section430981720522) - - [接口说明](#section1040142705214) - - [开发流程](#section1381224710522) - - [编程实例](#section1344610245416) - - -## 基本概念 - -时间管理以系统时钟为基础。时间管理提供给应用程序所有和时间有关的服务。系统时钟是由定时/计数器产生的输出脉冲触发中断而产生的,一般定义为整数或长整数。输出脉冲的周期叫做一个“时钟滴答”。系统时钟也称为时标或者Tick。一个Tick的时长可以静态配置。用户是以秒、毫秒为单位计时,而操作系统时钟计时是以Tick为单位的,当用户需要对系统操作时,例如任务挂起、延时等,输入秒为单位的数值,此时需要时间管理模块对二者进行转换。 - -Tick与秒之间的对应关系可以配置。 - -- **Cycle** - - 系统最小的计时单位。Cycle的时长由系统主频决定,系统主频就是每秒钟的Cycle数。 - - -- **Tick** - - Tick是操作系统的基本时间单位,对应的时长由系统主频及每秒Tick数决定,由用户配置。 - - -OpenHarmony系统的时间管理模块提供时间转换、统计、延迟功能以满足用户对时间相关需求的实现。 - -## 开发指导 - -用户需要了解当前系统运行的时间以及Tick与秒、毫秒之间的转换关系时,需要使用到时间管理模块的接口。 - -### 接口说明 - -OpenHarmony LiteOS-A内核的时间管理提供下面几种功能,接口详细信息可以查看API参考。 - -**表 1** 时间管理相关接口说明 - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名称

-

描述

-

时间转换

-

LOS_MS2Tick

-

毫秒转换成Tick

-

LOS_Tick2MS

-

Tick转换成毫秒

-

时间统计

-

LOS_TickCountGet

-

获取当前Tick数

-

LOS_CyclePerTickGet

-

每个Tick的cycle数

-
- -### 开发流程 - -1. 调用时间转换接口; -2. 获取系统Tick数完成时间统计等。 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->- 获取系统Tick数需要在系统时钟使能之后。 ->- 时间管理不是单独的功能模块,依赖于los\_config.h中的OS\_SYS\_CLOCK和LOSCFG\_BASE\_CORE\_TICK\_PER\_SECOND两个配置选项。 ->- 系统的Tick数在关中断的情况下不进行计数,故系统Tick数不能作为准确时间计算。 - -### 编程实例 - -前置条件: - -- 配置好LOSCFG\_BASE\_CORE\_TICK\_PER\_SECOND,即系统每秒的Tick数。 -- 配置好OS\_SYS\_CLOCK 系统时钟频率,单位:Hz。 - -**示例代码** - -时间转换: - -``` -VOID Example_TransformTime(VOID) -{ - UINT32 uwMs; - UINT32 uwTick; - uwTick = LOS_MS2Tick(10000); //10000 ms数转换为Tick数 - PRINTK("uwTick = %d \n",uwTick); - uwMs= LOS_Tick2MS(100); //100 Tick数转换为ms数 - PRINTK("uwMs = %d \n",uwMs); -} -``` - -时间统计和时间延迟: - -``` -VOID Example_GetTime(VOID) -{ - UINT32 uwcyclePerTick; - UINT64 uwTickCount; - - uwcyclePerTick = LOS_CyclePerTickGet(); //每个Tick多少Cycle数 - if(0 != uwcyclePerTick) - { - PRINTK("LOS_CyclePerTickGet = %d \n", uwcyclePerTick); - } - - uwTickCount = LOS_TickCountGet(); //获取Tick数 - if(0 != uwTickCount) - { - PRINTK("LOS_TickCountGet = %d \n", (UINT32)uwTickCount); - } - LOS_TaskDelay(200);//延迟200 Tick - uwTickCount = LOS_TickCountGet(); - if(0 != uwTickCount) - { - PRINTK("LOS_TickCountGet after delay = %d \n", (UINT32)uwTickCount); - } -} -``` - -**结果验证** - -编译运行的结果如下: - -时间转换: - -``` -uwTick = 10000 -uwMs = 100 -``` - -时间统计和时间延迟: - -``` -LOS_CyclePerTickGet = 49500 -LOS_TickCountGet = 5042 -LOS_TickCountGet after delay = 5242 -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/06.\350\275\257\344\273\266\345\256\232\346\227\266\345\231\250.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/06.\350\275\257\344\273\266\345\256\232\346\227\266\345\231\250.md" deleted file mode 100644 index f387cf5c0835132c9ad46a2d5e42991daa5bc95e..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/06.\350\275\257\344\273\266\345\256\232\346\227\266\345\231\250.md" +++ /dev/null @@ -1,249 +0,0 @@ ---- -title: 软件定时器 -permalink: /pages/010501020306 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# 软件定时器 - -- [基本概念](#section4118241563) -- [运行机制](#section31079397569) -- [开发指导](#section18576131520577) - - [接口说明](#section3138019145719) - - [开发流程](#section1344817403575) - - [编程实例](#section114416313585) - - -## 基本概念 - -软件定时器,是基于系统Tick时钟中断且由软件来模拟的定时器,当经过设定的Tick时钟计数值后会触发用户定义的回调函数。定时精度与系统Tick时钟的周期有关。硬件定时器受硬件的限制,数量上不足以满足用户的实际需求,因此为了满足用户需求,提供更多的定时器,Huawei LiteOS操作系统提供软件定时器功能。软件定时器扩展了定时器的数量,允许创建更多的定时业务。 - -软件定时器功能上支持: - -- 静态裁剪:能通过宏关闭软件定时器功能。 -- 软件定时器创建。 -- 软件定时器启动。 -- 软件定时器停止。 -- 软件定时器删除。 -- 软件定时器剩余Tick数获取。 - -## 运行机制 - -软件定时器是系统资源,在模块初始化的时候已经分配了一块连续的内存,系统支持的最大定时器个数由los\_config.h中的LOSCFG\_BASE\_CORE\_SWTMR\_LIMIT宏配置。软件定时器使用了系统的一个队列和一个任务资源,软件定时器的触发遵循队列规则,先进先出。同一时刻设置的定时时间短的定时器总是比定时时间长的靠近队列头,满足优先被触发的准则。软件定时器以Tick为基本计时单位,当用户创建并启动一个软件定时器时,OpenHarmony系统会根据当前系统Tick时间及用户设置的定时间隔确定该定时器的到期Tick时间,并将该定时器控制结构挂入计时全局链表。 - -当Tick中断到来时,在Tick中断处理函数中扫描软件定时器的计时全局链表,看是否有定时器超时,若有则将超时的定时器记录下来。 - -Tick中断处理函数结束后,软件定时器任务(优先级为最高)被唤醒,在该任务中调用之前记录下来的定时器的超时回调函数。 - -定时器状态 - -- OS\_SWTMR\_STATUS\_UNUSED(未使用) - - 系统在定时器模块初始化的时候将系统中所有定时器资源初始化成该状态。 - -- OS\_SWTMR\_STATUS\_CREATED(创建未启动/停止) - - 在未使用状态下调用LOS\_SwtmrCreate接口或者启动后调用LOS\_SwtmrStop接口后,定时器将变成该状态。 - -- OS\_SWTMR\_STATUS\_TICKING(计数) - - 在定时器创建后调用LOS\_SwtmrStart接口,定时器将变成该状态,表示定时器运行时的状态。 - - -定时器模式 - -OpenHarmony系统的软件定时器提供三类定时器机制: - -- 第一类是单次触发定时器,这类定时器在启动后只会触发一次定时器事件,然后定时器自动删除。 -- 第二类是周期触发定时器,这类定时器会周期性的触发定时器事件,直到用户手动停止定时器,否则将永远持续执行下去。 -- 第三类也是单次触发定时器,但与第一类不同之处在于这类定时器超时后不会自动删除,需要调用定时器删除接口删除定时器。 - -## 开发指导 - -### 接口说明 - -OpenHarmony LiteOS-A内核的软件定时器模块提供下面几种功能,接口详细信息可以查看API参考。 - -**表 1** 软件定时器接口说明 - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名称

-

描述

-

创建、删除定时器

-

LOS_SwtmrCreate

-

创建软件定时器

-

LOS_SwtmrDelete

-

删除软件定时器

-

启动、停止定时器

-

LOS_SwtmrStart

-

启动软件定时器

-

LOS_SwtmrStop

-

停止软件定时器

-

获得软件定时剩余Tick数

-

LOS_SwtmrTimeGet

-

获得软件定时器剩余Tick数

-
- -### 开发流程 - -软件定时器的典型开发流程: - -1. 配置软件定时器。 - - 确认配置项LOSCFG\_BASE\_CORE\_SWTMR和LOSCFG\_BASE\_IPC\_QUEUE为打开状态; - - 配置LOSCFG\_BASE\_CORE\_SWTMR\_LIMIT最大支持的软件定时器数; - - 配置OS\_SWTMR\_HANDLE\_QUEUE\_SIZE软件定时器队列最大长度; - -2. 创建定时器LOS\_SwtmrCreate。 - - 创建一个指定计时时长、指定超时处理函数、指定触发模式的软件定时器; - - 返回函数运行结果,成功或失败; - -3. 启动定时器LOS\_SwtmrStart。 -4. 获得软件定时器剩余Tick数LOS\_SwtmrTimeGet。 -5. 停止定时器LOS\_SwtmrStop。 -6. 删除定时器LOS\_SwtmrDelete。 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->- 软件定时器的回调函数中不要做过多操作,不要使用可能引起任务挂起或者阻塞的接口或操作。 ->- 软件定时器使用了系统的一个队列和一个任务资源,软件定时器任务的优先级设定为0,且不允许修改 。 ->- 系统可配置的软件定时器资源个数是指:整个系统可使用的软件定时器资源总个数,而并非是用户可使用的软件定时器资源个数。例如:系统软件定时器多占用一个软件定时器资源数,那么用户能使用的软件定时器资源就会减少一个。 ->- 创建单次软件定时器,该定时器超时执行完回调函数后,系统会自动删除该软件定时器,并回收资源。 ->- 创建单次不自删除属性的定时器,用户需要调用定时器删除接口删除定时器,回收定时器资源,避免资源泄露。 - -### 编程实例 - -**前置条件** - -- 在los\_config.h中,将LOSCFG\_BASE\_CORE\_SWTMR配置项打开。 -- 配置好LOSCFG\_BASE\_CORE\_SWTMR\_LIMIT最大支持的软件定时器数。 -- 配置好OS\_SWTMR\_HANDLE\_QUEUE\_SIZE软件定时器队列最大长度。 - -**编程示例** - -``` -#include "los_swtmr.h" - -void Timer1_Callback(uint32_t arg); -void Timer2_Callback(uint32_t arg); - -UINT32 g_timercount1 = 0; -UINT32 g_timercount2 = 0; - -void Timer1_Callback(uint32_t arg) // 回调函数1 -{ - unsigned long tick_last1; - g_timercount1++; - tick_last1=(UINT32)LOS_TickCountGet(); // 获取当前Tick数 - PRINTK("g_timercount1=%d\n",g_timercount1); - PRINTK("tick_last1=%d\n",tick_last1); -} - -void Timer2_Callback(uint32_t arg) // 回调函数2 -{ - unsigned long tick_last2; - tick_last2=(UINT32)LOS_TickCountGet(); - g_timercount2 ++; - PRINTK("g_timercount2=%d\n",g_timercount2); - PRINTK("tick_last2=%d\n",tick_last2); -} - -void Timer_example(void) -{ - UINT16 id1; - UINT16 id2; // timer id - UINT32 uwTick; - - /* 创建单次软件定时器,Tick数为1000,启动到1000Tick数时执行回调函数1 */ - LOS_SwtmrCreate (1000, LOS_SWTMR_MODE_ONCE, Timer1_Callback, &id1, 1); - - /* 创建周期性软件定时器,每100Tick数执行回调函数2 */ - LOS_SwtmrCreate(100, LOS_SWTMR_MODE_PERIOD, Timer2_Callback, &id2, 1); - PRINTK("create Timer1 success\n"); - - LOS_SwtmrStart (id1); //启动单次软件定时器 - dprintf("start Timer1 success\n"); - LOS_TaskDelay(200); // 延时200Tick数 - LOS_SwtmrTimeGet(id1, &uwTick); // 获得单次软件定时器剩余Tick数 - PRINTK("uwTick =%d\n", uwTick); - - LOS_SwtmrStop(id1); // 停止软件定时器 - PRINTK("stop Timer1 success\n"); - - LOS_SwtmrStart(id1); - LOS_TaskDelay(1000); - LOS_SwtmrDelete(id1); // 删除软件定时器 - PRINTK("delete Timer1 success\n"); - - LOS_SwtmrStart(id2); // 启动周期性软件定时器 - PRINTK("start Timer2\n"); - - LOS_TaskDelay(1000); - LOS_SwtmrStop(id2); - LOS_SwtmrDelete(id2); -} -``` - -**运行结果** - -``` -create Timer1 success -start Timer1 success -uwTick =800 -stop Timer1 success -g_timercount1=1 -tick_last1=1201 -delete Timer1 success -start Timer2 -g_timercount2 =1 -tick_last1=1301 -g_timercount2 =2 -tick_last1=1401 -g_timercount2 =3 -tick_last1=1501 -g_timercount2 =4 -tick_last1=1601 -g_timercount2 =5 -tick_last1=1701 -g_timercount2 =6 -tick_last1=1801 -g_timercount2 =7 -tick_last1=1901 -g_timercount2 =8 -tick_last1=2001 -g_timercount2 =9 -tick_last1=2101 -g_timercount2 =10 -tick_last1=2201 -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/07.\345\216\237\345\255\220\346\223\215\344\275\234.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/07.\345\216\237\345\255\220\346\223\215\344\275\234.md" deleted file mode 100644 index ecc3ceed850b992280e441441e3a8d2df9e8a8a7..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/03.\345\237\272\347\241\200\345\206\205\346\240\270/07.\345\216\237\345\255\220\346\223\215\344\275\234.md" +++ /dev/null @@ -1,301 +0,0 @@ ---- -title: 原子操作 -permalink: /pages/010501020307 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# 原子操作 - -- [基本概念](#section1792118384594) -- [运行机制](#section1786635117596) -- [开发指导](#section2911115308) - - [接口说明](#section335914201010) - - [开发流程](#section12207371304) - - [编程实例](#section8538651511) - - -## 基本概念 - -在支持多任务的操作系统中,修改一块内存区域的数据需要“读取-修改-写入”三个步骤。然而同一内存区域的数据可能同时被多个任务访问,如果在修改数据的过程中被其他任务打断,就会造成该操作的执行结果无法预知。 - -使用开关中断的方法固然可以保证多任务执行结果符合预期,但是显然这种方法会影响系统性能。 - -ARMv6架构引入了LDREX和STREX指令,以支持对共享存储器更缜密的非阻塞同步。由此实现的原子操作能确保对同一数据的“读取-修改-写入”操作在它的执行期间不会被打断,即操作的原子性。 - -## 运行机制 - -OpenHarmony系统通过对ARMv6架构中的LDREX和STREX进行封装,向用户提供了一套原子性的操作接口。 - -- LDREX Rx, \[Ry\] - - 读取内存中的值,并标记对该段内存的独占访问: - - - 读取寄存器Ry指向的4字节内存数据,保存到Rx寄存器中。 - - 对Ry指向的内存区域添加独占访问标记。 - -- STREX Rf, Rx, \[Ry\] - - 检查内存是否有独占访问标记,如果有则更新内存值并清空标记,否则不更新内存: - - - 有独占访问标记 - - 将寄存器Rx中的值更新到寄存器Ry指向的内存。 - - 标志寄存器Rf置为0。 - - - 没有独占访问标记 - - 不更新内存。 - - 标志寄存器Rf置为1。 - - -- 判断标志寄存器 - - 标志寄存器为0时,退出循环,原子操作结束。 - - 标志寄存器为1时,继续循环,重新进行原子操作。 - - -## 开发指导 - -### 接口说明 - -OpenHarmony LiteOS-A内核的原子操作模块提供下面几种功能,接口详细信息可以查看API参考。 - -**表 1** 原子操作接口说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名称

-

描述

-

-

LOS_AtomicRead

-

读取32bit原子数据

-

LOS_Atomic64Read

-

读取64bit原子数据

-

-

LOS_AtomicSet

-

设置32bit原子数据

-

LOS_Atomic64Set

-

设置64bit原子数据

-

-

LOS_AtomicAdd

-

对32bit原子数据做加法

-

LOS_Atomic64Add

-

对64bit原子数据做加法

-

LOS_AtomicInc

-

对32bit原子数据做加1

-

LOS_Atomic64Inc

-

对64bit原子数据做加1

-

LOS_AtomicIncRet

-

对32bit原子数据做加1并返回

-

LOS_Atomic64IncRet

-

对64bit原子数据做加1并返回

-

-

LOS_AtomicSub

-

对32bit原子数据做减法

-

LOS_Atomic64Sub

-

对64bit原子数据做减法

-

LOS_AtomicDec

-

对32bit原子数据做减1

-

LOS_Atomic64Dec

-

对64bit原子数据做减1

-

LOS_AtomicDecRet

-

对32bit原子数据做减1并返回

-

LOS_Atomic64DecRet

-

对64bit原子数据做减1并返回

-

交换

-

LOS_AtomicXchgByte

-

交换8bit内存数据

-

LOS_AtomicXchg16bits

-

交换16bit内存数据

-

LOS_AtomicXchg32bits

-

交换32bit内存数据

-

LOS_AtomicXchg64bits

-

交换64bit内存数据

-

先比较后交换

-

LOS_AtomicCmpXchgByte

-

比较相同后交换8bit内存数据

-

LOS_AtomicCmpXchg16bits

-

比较相同后交换16bit内存数据

-

LOS_AtomicCmpXchg32bits

-

比较相同后交换32bit内存数据

-

LOS_AtomicCmpXchg64bits

-

比较相同后交换64bit内存数据

-
- -### 开发流程 - -有多个任务对同一个内存数据进行加减或交换等操作时,使用原子操作保证结果的可预知性。 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->原子操作接口仅支持整型数据。 - -### 编程实例 - -**实例描述** - -调用原子操作相关接口,观察结果: - -1. 创建两个任务 - - 任务一用LOS\_AtomicInc对全局变量加100次。 - - 任务二用LOS\_AtomicDec对全局变量减100次。 - -2. 子任务结束后在主任务中打印全局变量的值。 - -**示例代码** - -示例代码如下: - -``` -#include "los_hwi.h" -#include "los_atomic.h" -#include "los_task.h" - -UINT32 g_testTaskId01; -UINT32 g_testTaskId02; -Atomic g_sum; -Atomic g_count; - -UINT32 Example_Atomic01(VOID) -{ - int i = 0; - for(i = 0; i < 100; ++i) { - LOS_AtomicInc(&g_sum); - } - - LOS_AtomicInc(&g_count); - return LOS_OK; -} - -UINT32 Example_Atomic02(VOID) -{ - int i = 0; - for(i = 0; i < 100; ++i) { - LOS_AtomicDec(&g_sum); - } - - LOS_AtomicInc(&g_count); - return LOS_OK; -} - -UINT32 Example_AtomicTaskEntry(VOID) -{ - TSK_INIT_PARAM_S stTask1={0}; - stTask1.pfnTaskEntry = (TSK_ENTRY_FUNC)Example_Atomic01; - stTask1.pcName = "TestAtomicTsk1"; - stTask1.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE; - stTask1.usTaskPrio = 4; - stTask1.uwResved = LOS_TASK_STATUS_DETACHED; - - TSK_INIT_PARAM_S stTask2={0}; - stTask2.pfnTaskEntry = (TSK_ENTRY_FUNC)Example_Atomic02; - stTask2.pcName = "TestAtomicTsk2"; - stTask2.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE; - stTask2.usTaskPrio = 4; - stTask2.uwResved = LOS_TASK_STATUS_DETACHED; - - LOS_TaskLock(); - LOS_TaskCreate(&g_testTaskId01, &stTask1); - LOS_TaskCreate(&g_testTaskId02, &stTask2); - LOS_TaskUnlock(); - - while(LOS_AtomicRead(&g_count) != 2); - PRINTK("g_sum = %d\n", g_sum); - - return LOS_OK; -} -``` - -**结果验证** - -``` -g_sum = 0 -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/04.\346\211\251\345\261\225\347\273\204\344\273\266/01.\347\263\273\347\273\237\350\260\203\347\224\250.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/04.\346\211\251\345\261\225\347\273\204\344\273\266/01.\347\263\273\347\273\237\350\260\203\347\224\250.md" deleted file mode 100644 index 4968e0a2be806e8eadcbaed4bcf3c919d0ba92c9..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/04.\346\211\251\345\261\225\347\273\204\344\273\266/01.\347\263\273\347\273\237\350\260\203\347\224\250.md" +++ /dev/null @@ -1,189 +0,0 @@ ---- -title: 系统调用 -permalink: /pages/010501020401 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# 系统调用 - -- [基本概念](#section889710401734) -- [运行机制](#section195177541314) -- [开发指导](#section193492047135419) - - [开发流程](#section7165741122210) - - [编程实例](#section107131418224) - - -## 基本概念 - -OpenHarmony LiteOS-A实现了用户态与内核态的区分隔离,用户态程序不能直接访问内核资源,而系统调用则为用户态程序提供了一种访问内核资源、与内核进行交互的通道。 - -## 运行机制 - -如图1所示,用户程序通过调用System API(系统API,通常是系统提供的POSIX接口)进行内核资源访问与交互请求,POSIX接口内部会触发SVC/SWI异常,完成系统从用户态到内核态的切换,然后对接到内核的Syscall Handler(系统调用统一处理接口)进行参数解析,最终分发至具体的内核处理函数。 - -**图 1** 系统调用示意图 -![](/images/device-dev/kernel/figure/系统调用示意图.png "系统调用示意图") - -Syscall Handler的具体实现在kernel/liteos\_a/syscall/los\_syscall.c中OsArmA32SyscallHandle函数,在进入系统软中断异常时会调用此函数,并且按照kernel/liteos\_a/syscall/syscall\_lookup.h中的清单进行系统调用的入参解析,执行各系统调用最终对应的内核处理函数。 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->- 系统调用提供基础的用户态程序与内核的交互功能,不建议开发者直接使用系统调用接口,推荐使用内核提供的对外POSIX接口,若需要新增系统调用接口,详见开发指导。 ->- 内核向用户态提供的系统调用接口清单详见kernel/liteos\_a/syscall/syscall\_lookup.h,内核相应的系统调用对接函数清单详见kernel/liteos\_a/syscall/los\_syscall.h。 - -## 开发指导 - -### 开发流程 - -新增系统调用的典型开发流程如下: - -1. 在LibC库中确定并添加新增的系统调用号。 -2. 在LibC库中新增用户态的函数接口声明及实现。 -3. 在内核系统调用头文件中确定并添加新增的系统调用号及对应内核处理函数的声明。 -4. 在内核中新增该系统调用对应的内核处理函数。 - -### 编程实例 - -**示例代码**: - -1. 在LibC库syscall.h.in中新增系统调用号 - - 如下所示,其中\_\_NR\_new\_syscall\_sample为新增系统调用号: - - ``` - ... - /* 当前现有的系统调用清单 */ - /* OHOS customized syscalls, not compatible with ARM EABI */ - #define __NR_OHOS_BEGIN 500 - #define __NR_pthread_set_detach (__NR_OHOS_BEGIN + 0) - #define __NR_pthread_join (__NR_OHOS_BEGIN + 1) - #define __NR_pthread_deatch (__NR_OHOS_BEGIN + 2) - #define __NR_creat_user_thread (__NR_OHOS_BEGIN + 3) - #define __NR_processcreat (__NR_OHOS_BEGIN + 4) - #define __NR_processtart (__NR_OHOS_BEGIN + 5) - #define __NR_printf (__NR_OHOS_BEGIN + 6) - #define __NR_dumpmemory (__NR_OHOS_BEGIN + 13) - #define __NR_mkfifo (__NR_OHOS_BEGIN + 14) - #define __NR_mqclose (__NR_OHOS_BEGIN + 15) - #define __NR_realpath (__NR_OHOS_BEGIN + 16) - #define __NR_format (__NR_OHOS_BEGIN + 17) - #define __NR_shellexec (__NR_OHOS_BEGIN + 18) - #define __NR_ohoscapget (__NR_OHOS_BEGIN + 19) - #define __NR_ohoscapset (__NR_OHOS_BEGIN + 20) - - #define __NR_new_syscall_sample (__NR_OHOS_BEGIN + 21) /* 新增的系统调用号 __NR_new_syscall_sample:521 */ - - #define __NR_syscallend (__NR_OHOS_BEGIN + 22) - ... - ``` - -2. 在LibC库中新增用户态接口的声明与实现 - - ``` - #include "stdio_impl.h" - #include "syscall.h" - ... - /* 新增系统调用用户态的接口实现 */ - void newSyscallSample(int num) - { - printf("user mode: num = %d\n", num); - __syscall(SYS_new_syscall_sample, num); - return; - } - ``` - -3. 在内核系统调用头文件中新增系统调用号 - - 如下所示,在third\_party/musl/porting/liteos\_a/kernel/include/bits/syscall.h文件中,\_\_NR\_new\_syscall\_sample为新增系统调用号。 - - ``` - ... - /* 当前现有的系统调用清单 */ - /* OHOS customized syscalls, not compatible with ARM EABI */ - #define __NR_OHOS_BEGIN 500 - #define __NR_pthread_set_detach (__NR_OHOS_BEGIN + 0) - #define __NR_pthread_join (__NR_OHOS_BEGIN + 1) - #define __NR_pthread_deatch (__NR_OHOS_BEGIN + 2) - #define __NR_creat_user_thread (__NR_OHOS_BEGIN + 3) - #define __NR_processcreat (__NR_OHOS_BEGIN + 4) - #define __NR_processtart (__NR_OHOS_BEGIN + 5) - #define __NR_printf (__NR_OHOS_BEGIN + 6) - #define __NR_dumpmemory (__NR_OHOS_BEGIN + 13) - #define __NR_mkfifo (__NR_OHOS_BEGIN + 14) - #define __NR_mqclose (__NR_OHOS_BEGIN + 15) - #define __NR_realpath (__NR_OHOS_BEGIN + 16) - #define __NR_format (__NR_OHOS_BEGIN + 17) - #define __NR_shellexec (__NR_OHOS_BEGIN + 18) - #define __NR_ohoscapget (__NR_OHOS_BEGIN + 19) - #define __NR_ohoscapset (__NR_OHOS_BEGIN + 20) - - #define __NR_new_syscall_sample (__NR_OHOS_BEGIN + 21) /* 新增的系统调用号 __NR_new_syscall_sample:521 */ - - #define __NR_syscallend (__NR_OHOS_BEGIN + 22) - ... - ``` - - 在kernel/liteos\_a/syscall/syscall\_lookup.h中,增加一行SYSCALL\_HAND\_DEF\(\_\_NR\_new\_syscall\_sample, SysNewSyscallSample, void, ARG\_NUM\_1\): - - ``` - ... - /* 当前现有的系统调用清单 */ - SYSCALL_HAND_DEF(__NR_chown, SysChown, int, ARG_NUM_3) - SYSCALL_HAND_DEF(__NR_chown32, SysChown, int, ARG_NUM_3) - #ifdef LOSCFG_SECURITY_CAPABILITY - SYSCALL_HAND_DEF(__NR_ohoscapget, SysCapGet, UINT32, ARG_NUM_2) - SYSCALL_HAND_DEF(__NR_ohoscapset, SysCapSet, UINT32, ARG_NUM_1) - #endif - /* 新增系统调用 */ - SYSCALL_HAND_DEF(__NR_new_syscall_sample, SysNewSyscallSample, void, ARG_NUM_1) - ... - ``` - -4. 在内核中新增内核该系统调用对应的处理函数 - - 如下所示,在kernel/liteos\_a/syscall/los\_syscall.h中,SysNewSyscallSample为新增系统调用的内核处理函数声明: - - ``` - ... - /* 当前现有的系统调用内核处理函数声明清单 */ - extern int SysClockSettime64(clockid_t clockID, const struct timespec64 *tp); - extern int SysClockGettime64(clockid_t clockID, struct timespec64 *tp); - extern int SysClockGetres64(clockid_t clockID, struct timespec64 *tp); - extern int SysClockNanoSleep64(clockid_t clk, int flags, const struct timespec64 *req, struct timespec64 *rem); - extern int SysTimerGettime64(timer_t timerID, struct itimerspec64 *value); - extern int SysTimerSettime64(timer_t timerID, int flags, const struct itimerspec64 *value, struct itimerspec64 *oldValue); - /* 新增的系统调用内核处理函数声明 */ - extern void SysNewSyscallSample(int num); - ... - ``` - - 新增的系统调用的内核处理函数实现如下: - - ``` - include "los_printf.h" - ... - /* 新增系统调用内核处理函数的实现 */ - void SysNewSyscallSample(int num) - { - PRINTK("kernel mode: num = %d\n", num); - return; - } - ``` - - -**结果验证:** - -用户态程序调用newSyscallSample\(10\)接口,得到输出结果如下: - -``` -/* 用户态接口与内核态接口均有输出,证明系统调用已使能 */ -user mode: num = 10 -kernel mode: num = 10 -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/04.\346\211\251\345\261\225\347\273\204\344\273\266/02.\345\212\250\346\200\201\345\212\240\350\275\275\344\270\216\351\223\276\346\216\245.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/04.\346\211\251\345\261\225\347\273\204\344\273\266/02.\345\212\250\346\200\201\345\212\240\350\275\275\344\270\216\351\223\276\346\216\245.md" deleted file mode 100644 index bac35be1a021131b2c499f17ed643debbd9dcc22..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/04.\346\211\251\345\261\225\347\273\204\344\273\266/02.\345\212\250\346\200\201\345\212\240\350\275\275\344\270\216\351\223\276\346\216\245.md" +++ /dev/null @@ -1,95 +0,0 @@ ---- -title: 动态加载与链接 -permalink: /pages/010501020402 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# 动态加载与链接 - -- [基本概念](#section208951139453) -- [运行机制](#section14140155320511) -- [开发指导](#section133501496612) - - [接口说明](#section874113201669) - - [开发流程](#section196712561563) - - -## 基本概念 - -OpenHarmony系统的动态加载与链接机制主要是由内核加载器以及动态链接器构成,内核加载器用于加载应用程序以及动态链接器,动态链接器用于加载应用程序所依赖的共享库,并对应用程序和共享库进行符号重定位。与静态链接相比,动态链接是将应用程序与动态库推迟到运行时再进行链接的一种机制。 - -**动态链接的优势:** - -1. 多个应用程序可以共享一份代码,最小加载单元为页,相对静态链接可以节约磁盘和内存空间。 -2. 共享库升级时,理论上将旧版本的共享库覆盖即可(共享库中的接口向下兼容),无需重新链接。 -3. 加载地址可以进行随机化处理,防止攻击,保证安全性。 - -## 运行机制 - -**图 1** 动态加载流程 -![](/images/device-dev/kernel/figure/动态加载流程.png "动态加载流程") - -1. 内核将应用程序ELF文件的PT\_LOAD段信息映射至进程空间。对于ET\_EXEC类型的文件,根据PT\_LOAD段中p\_vaddr进行固定地址映射;对于ET\_DYN类型(位置无关的可执行程序,通过编译选项“-fPIE”得到)的文件,内核通过mmap接口选择base基址进行映射(load\_addr = base + p\_vaddr)。 -2. 若应用程序是静态链接的(静态链接不支持编译选项“-fPIE”),设置堆栈信息后跳转至应用程序ELF文件中e\_entry指定的地址并运行;若程序是动态链接的,应用程序ELF文件中会有PT\_INTERP段,保存动态链接器的路径信息(ET\_DYN类型)。musl的动态链接器是libc-musl.so的一部分,libc-musl.so的入口即动态链接器的入口。内核通过mmap接口选择base基址进行映射,设置堆栈信息后跳转至base + e\_entry(该e\_entry为动态链接器的入口)地址并运行动态链接器。 -3. 动态链接器自举并查找应用程序依赖的所有共享库并对导入符号进行重定位,最后跳转至应用程序的e\_entry(或base + e\_entry),开始运行应用程序。 - -**图 2** 程序执行流程 -![](/images/device-dev/kernel/figure/程序执行流程.png "程序执行流程") - -1. 加载器与链接器调用mmap映射PT\_LOAD段; -2. 内核调用map\_pages接口查找并映射pagecache已有的缓存; -3. 程序执行时,内存若无所需代码或数据时触发缺页中断,将elf文件内容读入内存,并将该内存块加入pagecache; -4. 将已读入文件内容的内存块与虚拟地址区间做映射; -5. 程序继续执行; - -至此,程序将在不断地缺页中断中执行。 - -## 开发指导 - -### 接口说明 - -LOS\_DoExecveFile - -**函数原型:** - -INT32 LOS\_DoExecveFile\(const CHAR \*fileName, CHAR \* const \*argv, CHAR \* const \*envp\); - -**函数功能**:根据fileName执行一个新的用户程序。 - -**参数说明:** - - - - - - - - - - - - - - - - -

参数

-

描述

-

fileName

-

二进制可执行文件名,可以是路径名。

-

argv

-

程序执行所需的参数序列,以NULL结尾。无需参数时填入NULL。

-

envp

-

程序执行所需的新的环境变量序列,以NULL结尾。无需新的环境变量时填入NULL。

-
- -### 开发流程 - -LOS\_DoExecveFile接口一般由用户通过execve系列接口利用系统调用机制调用创建新的进程,内核不能直接调用该接口启动新进程。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/04.\346\211\251\345\261\225\347\273\204\344\273\266/03.\350\231\232\346\213\237\345\212\250\346\200\201\345\205\261\344\272\253\345\272\223.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/04.\346\211\251\345\261\225\347\273\204\344\273\266/03.\350\231\232\346\213\237\345\212\250\346\200\201\345\205\261\344\272\253\345\272\223.md" deleted file mode 100644 index ba68c469ded31f0db28ec68a9952f68657c4c66e..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/04.\346\211\251\345\261\225\347\273\204\344\273\266/03.\350\231\232\346\213\237\345\212\250\346\200\201\345\205\261\344\272\253\345\272\223.md" +++ /dev/null @@ -1,60 +0,0 @@ ---- -title: 虚拟动态共享库 -permalink: /pages/010501020403 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# 虚拟动态共享库 - -- [基本概念](#section174577181688) -- [运行机制](#section546363114810) - -## 基本概念 - -VDSO(Virtual Dynamic Shared Object,虚拟动态共享库)相对于普通的动态共享库,区别在于其so文件不保存在文件系统中,存在于系统镜像中,由内核在运行时确定并提供给应用程序,故称为虚拟动态共享库。 - -OpenHarmony系统通过VDSO机制实现上层用户态程序可以快速读取内核相关数据的一种通道方法,可用于实现部分系统调用的加速,也可用于实现非系统敏感数据(硬件配置、软件配置)的快速读取。 - -## 运行机制 - -VDSO其核心思想就是内核看护一段内存,并将这段内存映射(只读)进用户态应用程序的地址空间,应用程序通过链接vdso.so后,将某些系统调用替换为直接读取这段已映射的内存从而避免系统调用达到加速的效果。 - -VDSO总体可分为数据页与代码页两部分: - -- 数据页提供内核映射给用户进程的内核时数据; -- 代码页提供屏蔽系统调用的主要逻辑; - -**图 1** VDSO系统设计 -![](/images/device-dev/kernel/figure/VDSO系统设计.jpg "VDSO系统设计") - -如图1所示,当前VDSO机制有以下几个主要步骤: - -① 内核初始化时进行VDSO数据页的创建; - -② 内核初始化时进行VDSO代码页的创建; - -③ 根据系统时钟中断不断将内核一些数据刷新进VDSO的数据页; - -④ 用户进程创建时将代码页映射进用户空间; - -⑤ 用户程序在动态链接时对VDSO的符号进行绑定; - -⑥ 当用户程序进行特定系统调用时(例如clock\_gettime\(CLOCK\_REALTIME\_COARSE, &ts\)),VDSO代码页会将其拦截; - -⑦ VDSO代码页将正常系统调用转为直接读取映射好的VDSO数据页; - -⑧ 从VDSO数据页中将数据传回VDSO代码页; - -⑨ 将从VDSO数据页获取到的数据作为结果返回给用户程序; - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->- 当前VDSO机制支持LibC库clock\_gettime接口的CLOCK\_REALTIME\_COARSE与CLOCK\_MONOTONIC\_COARSE功能,clock\_gettime接口的使用方法详见POSIX标准。用户调用C库接口clock\_gettime\(CLOCK\_REALTIME\_COARSE, &ts\)或者clock\_gettime\(CLOCK\_MONOTONIC\_COARSE, &ts\)即可使用VDSO机制。 ->- 使用VDSO机制得到的时间精度会与系统tick中断的精度保持一致,适用于对时间没有高精度要求且短时间内会高频触发clock\_gettime或gettimeofday系统调用的场景,若有高精度要求,不建议采用VDSO机制。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/04.\346\211\251\345\261\225\347\273\204\344\273\266/04.\350\275\273\351\207\217\347\272\247\350\277\233\347\250\213\351\227\264\351\200\232\344\277\241.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/04.\346\211\251\345\261\225\347\273\204\344\273\266/04.\350\275\273\351\207\217\347\272\247\350\277\233\347\250\213\351\227\264\351\200\232\344\277\241.md" deleted file mode 100644 index 5776c892ca7801372a16e85b7c1890fc85250b7a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/04.\346\211\251\345\261\225\347\273\204\344\273\266/04.\350\275\273\351\207\217\347\272\247\350\277\233\347\250\213\351\227\264\351\200\232\344\277\241.md" +++ /dev/null @@ -1,83 +0,0 @@ ---- -title: 轻量级进程间通信 -permalink: /pages/010501020404 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# 轻量级进程间通信 - -- [基本概念](#section1980994712918) -- [运行机制](#section849811592918) -- [开发指导](#section17571315171017) - - [接口说明](#section725022011103) - - -## 基本概念 - -LiteIPC是OpenHarmony LiteOS-A内核提供的一种新型IPC(Inter-Process Communication,即进程间通信)机制,不同于传统的System V IPC机制,LiteIPC主要是为RPC(Remote Procedure Call,即远程过程调用)而设计的,而且是通过设备文件的方式对上层提供接口的,而非传统的API函数方式。 - -LiteIPC中有两个主要概念,一个是ServiceManager,另一个是Service。整个系统只能有一个ServiceManager,而Service可以有多个。ServiceManager有两个主要功能:一是负责Service的注册和注销,二是负责管理Service的访问权限(只有有权限的任务(Task)可以向对应的Service发送IPC消息)。 - -## 运行机制 - -首先将需要接收IPC消息的任务通过ServiceManager注册成为一个Service,然后通过ServiceManager为该Service任务配置访问权限,即指定哪些任务可以向该Service任务发送IPC消息。LiteIPC的核心思想就是在内核态为每个Service任务维护一个IPC消息队列,该消息队列通过LiteIPC设备文件向上层用户态程序分别提供代表收取IPC消息的读操作和代表发送IPC消息的写操作。 - -## 开发指导 - -### 接口说明 - -**表 1** LiteIPC模块接口(仅LiteOS-A内部使用) - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名称

-

描述

-

模块初始化

-

OsLiteIpcInit

-

初始化LiteIPC模块

-

IPC消息内存池

-

LiteIpcPoolInit

-

初始化进程的IPC消息内存池

-

LiteIpcPoolReInit

-

重新初始化进程的IPC消息内存池

-

LiteIpcPoolDelete

-

释放进程的IPC消息内存池

-

Service管理

-

LiteIpcRemoveServiceHandle

-

删除指定的Service

-
- ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->LiteIPC模块接口都只在LiteOS-A内部使用。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/04.\346\211\251\345\261\225\347\273\204\344\273\266/05.\346\226\207\344\273\266\347\263\273\347\273\237/01.\350\231\232\346\213\237\346\226\207\344\273\266\347\263\273\347\273\237.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/04.\346\211\251\345\261\225\347\273\204\344\273\266/05.\346\226\207\344\273\266\347\263\273\347\273\237/01.\350\231\232\346\213\237\346\226\207\344\273\266\347\263\273\347\273\237.md" deleted file mode 100644 index b3b1e1654415194e409859adb7395e8fb5f9191a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/04.\346\211\251\345\261\225\347\273\204\344\273\266/05.\346\226\207\344\273\266\347\263\273\347\273\237/01.\350\231\232\346\213\237\346\226\207\344\273\266\347\263\273\347\273\237.md" +++ /dev/null @@ -1,807 +0,0 @@ ---- -title: 虚拟文件系统 -permalink: /pages/01050102040501 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# 虚拟文件系统 - -- [基本概念](#section1253851143520) -- [运行机制](#section14915913123510) -- [开发指导](#section1759563620358) - - [接口说明](#section17865142133511) - - [开发流程](#section64113023616) - - [编程实例](#section236041883618) - - -## 基本概念 - -VFS(Virtual File System)是文件系统的虚拟层,它不是一个实际的文件系统,而是一个异构文件系统之上的软件粘合层,为用户提供统一的类Unix文件操作接口。由于不同类型的文件系统接口不统一,若系统中有多个文件系统类型,访问不同的文件系统就需要使用不同的非标准接口。而通过在系统中添加VFS层,提供统一的抽象接口,屏蔽了底层异构类型的文件系统的差异,使得访问文件系统的系统调用不用关心底层的存储介质和文件系统类型,提高开发效率。 - -OpenHarmony内核中,VFS框架是通过在内存中的树结构来实现的,树的每个结点都是一个Vnode结构体,父子结点的关系以PathCache结构体保存。VFS最主要的两个功能是: - -- 查找节点。 -- 统一调用(标准)。 - -## 运行机制 - -当前,VFS层主要通过函数指针,实现对不同文件系统类型调用不同接口实现标准接口功能;通过Vnode与PathCache机制,提升路径搜索以及文件访问的性能;通过挂载点管理进行分区管理;通过FD管理进行进程间FD隔离等。下面将对这些机制进行简要说明。 - -1. 文件系统操作函数指针:VFS层通过函数指针的形式,将统一调用按照不同的文件系统类型,分发到不同文件系统中进行底层操作。各文件系统的各自实现一套Vnode操作、挂载点操作以及文件操作接口,并以函数指针结构体的形式存储于对应Vnode、挂载点、File结构体中,实现VFS层对下访问。 -2. Vnode:Vnode是具体文件或目录在VFS层的抽象封装,它屏蔽了不同文件系统的差异,实现资源的统一管理。Vnode节点主要有以下几种类型: - - - 挂载点:挂载具体文件系统,如/、/storage - - 设备节点:/dev目录下的节点,对应于一个设备,如/dev/mmcblk0 - - 文件/目录节点:对应于具体文件系统中的文件/目录,如/bin/init - - Vnode通过哈希以及LRU机制进行管理。当系统启动后,对文件或目录的访问会优先从哈希链表中查找Vnode缓存,若缓存没有命中,则并从对应文件系统中搜索目标文件或目录,创建并缓存对应的Vnode。当Vnode缓存数量达到上限时,将淘汰长时间未访问的Vnode,其中挂载点Vnode与设备节点Vnode不参与淘汰。当前系统中Vnode的规格默认为512,该规格可以通过LOSCFG\_MAX\_VNODE\_SIZE进行配置。Vnode数量过大,会造成较大的内存占用;Vnode数量过少,则会造成搜索性能下降。下图展示了Vnode的创建流程。 - - **图 1** Vnode创建流程 - ![](/images/device-dev/kernel/figure/Vnode创建流程.png "Vnode创建流程") - - -1. PathCache:PathCache是路径缓存,它通过哈希表存储,利用父节点Vnode的地址和子节点的文件名,可以从PathCache中快速查找到子节点对应的Vnode。下图展示了文件/目录的查找流程。 - - **图 2** 文件查找流程 - ![](/images/device-dev/kernel/figure/文件查找流程.png "文件查找流程") - - -1. PageCache:PageCache是内核中文件的缓存。当前PageCache仅支持缓存二进制文件,在初次访问文件时通过mmap映射到内存中,下次再访问时,直接从PageCache中读取,可以提升对同一个文件的读写速度。另外基于PageCache可实现以文件为基底的进程间通信。 -2. fd管理:Fd(File Descriptor)是描述一个打开的文件/目录的描述符。当前OpenHarmony内核中,fd总规格为896,分为三种类型: - - - 普通文件描述符,系统总规格为512。 - - Socket描述符,系统总规格为128。 - - 消息队列描述符,系统总规格为256。 - - 当前OpenHarmony内核中,对不同进程中的fd进行隔离,即进程只能访问本进程的fd,所有进程的fd映射到全局fd表中进行统一分配管理。进程的文件描述符最多有256个。 - -3. 挂载点管理:当前OpenHarmony内核中,对系统中所有挂载点通过链表进行统一管理。挂载点结构体中,记录了该挂载分区内的所有Vnode。当分区卸载时,会释放分区内的所有Vnode。 - -## 开发指导 - -### 接口说明 - -当前文件系统支持的接口如下表所示,表格中的“×”代表对应文件系统不支持该接口。 - -**表 1** 支持接口列表 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

分类

-

接口名称

-

功能

-

FAT

-

JFFS2

-

NFS

-

TMPFS

-

PROCFS

-

文件操作

-

open

-

打开文件

-

-

-

-

-

-

read/pread/readv/preadv

-

读取文件

-

-

-

-

-

-

write/pwrite/writev/pwritev

-

写入文件

-

-

-

-

-

-

lseek

-

设置文件偏移

-

-

-

-

-

×

-

close

-

关闭文件

-

-

-

-

-

-

unlink

-

删除文件

-

-

-

-

-

×

-

fstat

-

查询文件信息

-

-

-

-

-

-

fallocate

-

预分配大小

-

-

×

-

×

-

×

-

×

-

truncate

-

文件截断

-

-

-

×

-

-

×

-

link

-

创建硬链接

-

×

-

-

×

-

×

-

×

-

symlink

-

创建软链接

-

-

-

×

-

×

-

×

-

readlink

-

读取软链接

-

-

-

×

-

×

-

×

-

dup

-

复制文件句柄

-

-

-

-

-

-

fsync

-

文件内容刷入设备

-

-

×

-

×

-

×

-

×

-

ioctl

-

设备控制

-

×

-

×

-

×

-

-

×

-

fcntl

-

文件控制操作

-

-

-

-

-

-

目录操作

-

mkdir

-

创建目录

-

-

-

-

-

×

-

opendir

-

打开目录

-

-

-

-

-

-

readdir

-

读取目录

-

-

-

-

-

-

closedir

-

关闭目录

-

-

-

-

-

-

telldir

-

获取目录偏移

-

-

-

-

-

-

seekdir

-

设置目录偏移

-

-

-

-

-

-

rewinddir

-

重置目录偏移

-

-

-

-

-

×

-

scandir

-

读取目录数据

-

-

-

-

-

-

rmdir

-

删除目录

-

-

-

-

-

×

-

chdir

-

切换当前路径

-

-

-

-

-

-

getcwd

-

获取当前路径

-

-

-

-

-

-

realpath

-

相对/绝对路径转换

-

-

-

-

-

-

rename

-

文件/目录重命名

-

-

-

-

-

×

-

chmod

-

修改文件/目录属性

-

-

-

×

-

×

-

×

-

chown

-

修改文件/目录所有者

-

-

-

×

-

×

-

×

-

stat/lstat

-

查询文件/目录信息

-

-

-

-

-

-

access

-

查询文件/目录访问权限

-

-

-

-

-

-

分区操作

-

mount

-

挂载分区

-

-

-

-

-

-

umount

-

卸载分区

-

-

-

-

-

×

-

statfs

-

查询挂载分区信息

-

-

-

-

-

-

format

-

格式化分区

-

-

×

-

×

-

×

-

×

-

sync

-

分区内容刷入设备

-

-

×

-

×

-

×

-

×

-
- -### 开发流程 - -文件系统的主要开发流程包括挂载/卸载分区,以及系列目录/文件操作。 - -### 编程实例 - -代码实现如下: - -``` -#include -#include -#include "sys/stat.h" -#include "fcntl.h" -#include "unistd.h" - -#define LOS_OK 0 -#define LOS_NOK -1 - -int main(void) -{ - int ret; - int fd = -1; - ssize_t len; - off_t off; - char mntName[20] = "/storage"; - char devName[20] = "/dev/mmcblk0p0"; - char dirName[20] = "/storage/test"; - char fileName[20] = "/storage/test/file.txt"; - char writeBuf[20] = "Hello OpenHarmony!"; - char readBuf[20] = {0}; - - /* 创建目录“/storage” */ - ret = mkdir(mntName, 0777); - if (ret != LOS_OK) { - printf("mkdir failed.\n"); - return LOS_NOK; - } - - /* 挂载设备“/dev/mmcblk0p0”到“/storage” */ - ret = mount(devName, mntName, "vfat", 0, 0); - if (ret != LOS_OK) { - printf("mount failed.\n"); - return LOS_NOK; - } - - /* 创建目录“/storage/test” */ - ret = mkdir(dirName, 0777); - if (ret != LOS_OK) { - printf("mkdir failed.\n"); - return LOS_NOK; - } - - /* 创建可读写文件“/storage/test/file.txt” */ - fd = open(fileName, O_RDWR | O_CREAT, 0777); - if (fd < 0) { - printf("open file failed.\n"); - return LOS_NOK; - } - - /* 将writeBuf中的内容写入文件 */ - len = write(fd, writeBuf, strlen(writeBuf)); - if (len != strlen(writeBuf)) { - printf("write file failed.\n"); - return LOS_NOK; - } - - /* 将文件内容刷入存储设备中 */ - ret = fsync(fd); - if (ret != LOS_OK) { - printf("fsync failed.\n"); - return LOS_NOK; - } - - /* 将读写指针偏移至文件头 */ - off = lseek(fd, 0, SEEK_SET); - if (off != 0) { - printf("lseek failed.\n"); - return LOS_NOK; - } - - /* 将文件内容读出至readBuf中,读取长度为readBuf大小 */ - len = read(fd, readBuf, sizeof(readBuf)); - if (len != strlen(readBuf)) { - printf("read file failed.\n"); - return LOS_NOK; - } - printf("%s\n", readBuf); - - /* 关闭文件 */ - ret = close(fd); - if (ret != LOS_OK) { - printf("close failed.\n"); - return LOS_NOK; - } - - /* 删除文件“/storage/test/file.txt” */ - ret = unlink(fileName); - if (ret != LOS_OK) { - printf("unlink failed.\n"); - return LOS_NOK; - } - - /* 删除目录“/storage/test” */ - ret = rmdir(dirName); - if (ret != LOS_OK) { - printf("rmdir failed.\n"); - return LOS_NOK; - } - - /* 卸载分区“/storage” */ - ret = umount(mntName); - if (ret != LOS_OK) { - printf("umount failed.\n"); - return LOS_NOK; - } - - /* 删除目录“/storage” */ - ret = rmdir(mntName); - if (ret != LOS_OK) { - printf("rmdir failed.\n"); - return LOS_NOK; - } - - return LOS_OK; -} -``` - -**结果验证** - -编译运行得到的结果为: - -``` -Hello OpenHarmony! -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/04.\346\211\251\345\261\225\347\273\204\344\273\266/05.\346\226\207\344\273\266\347\263\273\347\273\237/02.\346\224\257\346\214\201\347\232\204\346\226\207\344\273\266\347\263\273\347\273\237/01.FAT.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/04.\346\211\251\345\261\225\347\273\204\344\273\266/05.\346\226\207\344\273\266\347\263\273\347\273\237/02.\346\224\257\346\214\201\347\232\204\346\226\207\344\273\266\347\263\273\347\273\237/01.FAT.md" deleted file mode 100644 index 6d2e87a5d921154ed13c2ee176fd662376bee660..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/04.\346\211\251\345\261\225\347\273\204\344\273\266/05.\346\226\207\344\273\266\347\263\273\347\273\237/02.\346\224\257\346\214\201\347\232\204\346\226\207\344\273\266\347\263\273\347\273\237/01.FAT.md" +++ /dev/null @@ -1,58 +0,0 @@ ---- -title: FAT -permalink: /pages/0105010204050201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# FAT - -- [基本概念](#section621393911385) -- [运行机制](#section10796155213381) -- [开发指导](#section144094483919) - - [开发流程](#section139086116394) - - -## 基本概念 - -FAT文件系统是File Allocation Table(文件配置表)的简称,主要包括DBR区、FAT区、DATA区三个区域。其中,FAT区各个表项记录存储设备中对应簇的信息,包括簇是否被使用、文件下一个簇的编号、是否文件结尾等。FAT文件系统有FAT12、FAT16、FAT32等多种格式,其中,12、16、32表示对应格式中FAT表项的字节数,它们同时也限制了文件系统中的最大文件大小。FAT文件系统支持多种介质,特别在可移动存储介质(U盘、SD卡、移动硬盘等)上广泛使用,使嵌入式设备和Windows、Linux等桌面系统保持很好的兼容性,方便用户管理操作文件。 - -OpenHarmony内核支持FAT12、FAT16与FAT32三种格式的FAT文件系统,具有代码量小、资源占用小、可裁切、支持多种物理介质等特性,并且与Windows、Linux等系统保持兼容,支持多设备、多分区识别等功能。OpenHarmony内核支持硬盘多分区,可以在主分区以及逻辑分区上创建FAT文件系统。 - -## 运行机制 - -FAT文件系统设计与物理布局的相关文档在互联网上非常丰富,请开发者自行搜索查看。 - -OpenHarmony LiteOS-A内核通过Bcache提升FAT文件系统性能,Bcache是block cache的简称。当发生读写时,Bcache会缓存读写扇区附近的扇区,以减少I/O次数,提高性能。Bcache的基本缓存单位为block,每个block大小一致(默认有28个block,每个block缓存64个扇区的数据)。当Bcache脏块率(脏扇区数/总扇区数)达到阈值时,会触发写回;如果脏块率未达到阈值,则不会将缓存数据写回磁盘。如果需要保证数据写回,开发者应当调用sync和fsync触发写回。FAT文件系统的部分接口也会触发写回操作(如close、umount等),但开发者不应当基于这些接口触发写回。 - -## 开发指导 - -### 开发流程 - -基本使用流程为挂载→操作→卸载。 - -SD卡或MMC的设备名为mmcblk\[x\]p\[y\],文件系统类型为“vfat”。 - -示例: - -``` -mount("/dev/mmcblk0p0", "/mnt", "vfat", 0, NULL); -``` - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->- FAT文件系统中,单个文件不能大于4 GiB。 ->- 当有两个SD卡插槽时,卡0和卡1不固定,先插上的为卡0,后插上的为卡1。 ->- 当多分区功能打开,存在多分区的情况下,卡0注册的设备节点/dev/mmcblk0\(主设备\)和/dev/mmcblk0p0\(次设备\)是同一个设备,禁止对主设备进行操作。 ->- 为避免SD卡使用异常或内存泄漏,SD卡使用过程中拔卡,用户必须先关闭正处于打开状态的文件和目录,并且卸载挂载节点。 ->- 在format操作之前,需要首先umount挂载点。 ->- 当Bcache功能生效时,需要注意: -> - 当mount函数的入参为MS\_NOSYNC时,FAT不会主动将cache的内容写回存储器件。FAT的如下接口(open、close、 unlink、rename、mkdir、rmdir、truncate)不会自动进行sync操作,速度可以提升,但是需要上层主动调用sync来进行数据同步,否则可能会数据丢失。 -> - Bcache有定时写回功能。在menuconfig中开启LOSCFG\_FS\_FAT\_CACHE\_SYNC\_THREAD选项,打开后系统会创建一个任务定时写回Bcache中的数据,默认每隔5秒检查Bcache中脏数据块比例,超过80%时进行sync操作,将Bcache中的脏数据全部写回磁盘。任务优先级、刷新时间间隔以及脏数据块比例的阈值可分别通过接口LOS\_SetSyncThreadPrio、 LOS\_SetSyncThreadInterval和LOS\_SetDirtyRatioThreshold设置。 -> - 当前cache的默认大小为28个块,每个块64个扇区。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/04.\346\211\251\345\261\225\347\273\204\344\273\266/05.\346\226\207\344\273\266\347\263\273\347\273\237/02.\346\224\257\346\214\201\347\232\204\346\226\207\344\273\266\347\263\273\347\273\237/02.JFFS2.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/04.\346\211\251\345\261\225\347\273\204\344\273\266/05.\346\226\207\344\273\266\347\263\273\347\273\237/02.\346\224\257\346\214\201\347\232\204\346\226\207\344\273\266\347\263\273\347\273\237/02.JFFS2.md" deleted file mode 100644 index 279191d27f7afd053f17a2e60bb325be0f5e07c6..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/04.\346\211\251\345\261\225\347\273\204\344\273\266/05.\346\226\207\344\273\266\347\263\273\347\273\237/02.\346\224\257\346\214\201\347\232\204\346\226\207\344\273\266\347\263\273\347\273\237/02.JFFS2.md" +++ /dev/null @@ -1,128 +0,0 @@ ---- -title: JFFS2 -permalink: /pages/0105010204050202 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# JFFS2 - -- [基本概念](#section11411110155919) -- [运行机制](#section23911025195913) -- [开发指导](#section179711119014) - -## 基本概念 - -JFFS2是Journalling Flash File System Version 2(日志文件系统)的缩写,是针对MTD设备的日志型文件系统。 - -OpenHarmony内核的JFFS2主要应用于NOR FLASH闪存,其特点是:可读写、支持数据压缩、提供了崩溃/掉电安全保护、提供“写平衡”支持等。闪存与磁盘介质有许多差异,直接将磁盘文件系统运行在闪存设备上,会导致性能和安全问题。为解决这一问题,需要实现一个特别针对闪存的文件系统,JFFS2就是这样一种文件系统。 - -## 运行机制 - -关于JFFS2文件系统的在存储设备上的实际物理布局,及文件系统本身的规格说明,请参考JFFS2的[官方规格说明文档](https://sourceware.org/jffs2/)。 - -这里仅列举几个对开发者和使用者会有一定影响的JFFS2的重要机制/特征: - -1. Mount机制及速度问题:按照JFFS2的设计,所有的文件会按照一定的规则,切分成大小不等的节点,依次存储到flash设备上。在mount流程中,需要获取到所有的这些节点信息并缓存到内存里。因此,mount速度和flash设备的大小和文件数量的多少成线性比例关系。这是JFFS2的原生设计问题,对于mount速度非常介意的用户,可以在内核编译时开启“Enable JFFS2 SUMMARY”选项,可以极大提升mount的速度。这个选项的原理是将mount需要的信息提前存储到flash上,在mount时读取并解析这块内容,使得mount的速度变得相对恒定。这个实际是空间换时间的做法,会消耗8%左右的额外空间。 -2. 写平衡的支持:由于flash设备的物理属性,读写都只能基于某个特定大小的“块”进行,为了防止某些特定的块磨损过于严重,在JFFS2中需要对写入的块进行“平衡”的管理,保证所有的块的写入次数都是相对平均的,进而保证flash设备的整体寿命。 -3. GC\(garbage collection\)机制:在JFFS2里发生删除动作,实际的物理空间并不会立即释放,而是由独立的GC线程来做空间整理和搬移等GC动作,和所有的GC机制一样,在JFFS2里的GC会对瞬时的读写性能有一定影响。另外,为了有空间能被用来做空间整理,JFFS2会对每个分区预留3块左右的空间,这个空间是用户不可见的。 -4. 压缩机制:当前使用的JFFS2,底层会自动的在每次读/写时进行解压/压缩动作,实际IO的大小和用户请求读写的大小并不会一样。特别在写入时,不能通过写入大小来和flash剩余空间的大小来预估写入一定会成功或者失败。 -5. 硬链接机制:JFFS2支持硬链接,底层实际占用的物理空间是一份,对于同一个文件的多个硬连接,并不会增加空间的占用;反之,只有当删除了所有的硬链接时,实际物理空间才会被释放。 - -## 开发指导 - -对于基于JFFS2和nor flash的开发,总体而言,与其他文件系统非常相似,因为都有VFS层来屏蔽了具体文件系统的差异,对外接口体现也都是标准的POSIX接口。 - -对于整个裸nor flash设备而言,没有集中的地方来管理和记录分区的信息。因此,需要通过其他的配置方式来传递这部分信息(当前使用的方式是在烧写镜像的时候,使用bootargs参数配置的),然后在代码中调用相应的接口来添加分区,再进行挂载动作。 - -**制作JFFS2文件系统镜像** - -使用mkfs.jffs2工具,制作镜像默认命令如下。页大小默认为4KiB,eraseblock大小默认64KiB。若实际参数与下面不同时,修改相应参数。 - -``` -./mkfs.jffs2 -d rootfs/ -o rootfs.jffs2 -``` - -**表 1** 指令含义表(更详细的介绍可以通过mkfs.jffs2 --help来查看) - - - - - - - - - - - - - - - - - - - - - - -

指令

-

含义

-

-s

-

页大小,不指定默认为4KiB

-

-e

-

eraseblock大小,不指定默认为64KiB

-

-p

-

镜像大小。在镜像文件后面,用0xFF填充至指定大小,不指定则用0xFF填充至eraseblock对齐。

-

-d

-

要制作成文件系统镜像的源目录

-

-o

-

要制成的镜像名称

-
- -**挂载JFFS2分区** - -调用int mount\(const char \*source, const char \*target, const char \*filesystemtype, unsigned long mountflags, const void \*data\)函数实现设备节点和挂载点的挂载。 - -该函数有五个参数,第一个参数const char \*source,表示设备节点,第二个参数const char \*target表示挂载点。第三个参数 const char \*filesystemtype,表示文件系统类型。 - -最后两个参数unsigned long mountflags和const void \*data表示挂载标志和数据,默认为0和NULL;这一操作也可以在Shell中使用mount命令实现,最后两个参数不需要用户给出。 - -运行命令: - -``` -OHOS # mount /dev/spinorblk1 /jffs1 jffs2 -``` - -将从串口得到如下回应信息,表明挂载成功。 - -``` -OHOS # mount /dev/spinorblk1 /jffs1 jffs2 -mount OK -``` - -挂载成功后,用户就能对norflash进行读写操作。 - -**卸载JFFS2分区** - -调用int umount\(const char \*target\)函数卸载分区,只需要正确给出挂载点即可。 - -运行命令: - -``` -OHOS # umount /jffs1 -``` - -将从串口得到如下回应信息,表明卸载成功。 - -``` -OHOS # umount /jffs1 -umount ok -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/04.\346\211\251\345\261\225\347\273\204\344\273\266/05.\346\226\207\344\273\266\347\263\273\347\273\237/02.\346\224\257\346\214\201\347\232\204\346\226\207\344\273\266\347\263\273\347\273\237/03.NFS.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/04.\346\211\251\345\261\225\347\273\204\344\273\266/05.\346\226\207\344\273\266\347\263\273\347\273\237/02.\346\224\257\346\214\201\347\232\204\346\226\207\344\273\266\347\263\273\347\273\237/03.NFS.md" deleted file mode 100644 index dda2752693eb56d2056dbdfb96759bb77099d830..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/04.\346\211\251\345\261\225\347\273\204\344\273\266/05.\346\226\207\344\273\266\347\263\273\347\273\237/02.\346\224\257\346\214\201\347\232\204\346\226\207\344\273\266\347\263\273\347\273\237/03.NFS.md" +++ /dev/null @@ -1,147 +0,0 @@ ---- -title: NFS -permalink: /pages/0105010204050203 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# NFS - -- [基本概念](#section195414101464) -- [运行机制](#section165621321194618) -- [开发指导](#section7454935184611) - -## 基本概念 - -NFS是Network File System(网络文件系统)的缩写。它最大的功能是可以通过网络,让不同的机器、不同的操作系统彼此分享其他用户的文件。因此,用户可以简单地将它看做是一个文件系统服务,在一定程度上相当于Windows环境下的共享文件夹。 - -## 运行机制 - -OpenHarmony LiteOS-A内核的NFS文件系统指的是NFS的客户端,NFS客户端能够将远程的NFS服务端分享的目录挂载到本地的机器中,运行程序和共享文件,但不占用当前系统的存储空间,在本地端的机器看起来,远程服务端的目录就好像是自己的一个磁盘一样。 - -## 开发指导 - -1. 搭建NFS服务器 - -这里以Ubuntu操作系统为例,说明服务器端设置步骤。 - -- 安装NFS服务器软件。 - -设置好Ubuntu系统的下载源,保证网络连接好的情况下执行: - -``` -sudo apt-get install nfs-kernel-server -``` - -- 创建用于挂载的目录并设置完全权限 - -``` -mkdir -p /home/sqbin/nfs -sudo chmod 777 /home/sqbin/nfs -``` - -- 设置和启动NFS server。 - -修改NFS配置文件/etc/exports,添加如下一行: - -``` -/home/sqbin/nfs *(rw,no_root_squash,async) -``` - -其中/home/sqbin/nfs是NFS共享的根目录。 - -执行以下命令启动NFS server: - -``` -sudo /etc/init.d/nfs-kernel-server start -``` - -执行以下命令重启NFS server: - -``` -sudo /etc/init.d/nfs-kernel-server restart -``` - -1. 设置单板为NFS客户端 - -本指导中的NFS客户端指运行OpenHarmony内核的设备。 - -- 硬件连接设置。 - -OpenHarmony内核设备连接到NFS服务器的网络。设置两者IP,使其处于同一网段。比如,设置NFS服务器的IP为10.67.212.178/24,设置OpenHarmony内核设备IP为10.67.212.3/24,注意:此IP为内网私有IP地址,用户使用时有差异,以用户实际IP为准。 - -OpenHarmony内核设备上的IP信息可通过ifconfig命令查看。 - -- 启动网络,确保单板到NFS服务器之间的网络通畅。 - -启动以太网或者其他类型网络,使用ping命令检查到服务器的网络是否通畅。 - -``` -OHOS # ping 10.67.212.178 -[0]Reply from 10.67.212.178: time=1ms TTL=63 -[1]Reply from 10.67.212.178: time=0ms TTL=63 -[2]Reply from 10.67.212.178: time=1ms TTL=63 -[3]Reply from 10.67.212.178: time=1ms TTL=63 ---- 10.67.212.178 ping statistics --- -4 packets transmitted, 4 received, 0 loss -``` - -客户端NFS初始化,运行命令: - -``` -OHOS # mkdir /nfs -OHOS # mount 10.67.212.178:/home/sqbin/nfs /nfs nfs 1011 1000 -``` - -将从串口得到如下回应信息,表明初始化NFS客户端成功。 - -``` -OHOS # mount 10.67.212.178:/home/sqbin/nfs /nfs nfs 1011 1000 -Mount nfs on 10.67.212.178:/home/sqbin/nfs, uid:1011, gid:1000 -Mount nfs finished. -``` - -该命令将服务器10.67.212.178上的/home/sqbin/nfs目录挂载到OpenHarmony内核设备上的/nfs上。 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->本例默认nfs server已经配置可用,即示例中服务器10.67.212.178上的/home/sqbin/nfs已配置可访问。 ->mount命令的格式为: ->``` ->mount nfs ->``` ->其中“SERVER\_IP”表示服务器的IP地址;“SERVER\_PATH”表示服务器端NFS共享目录路径;“CLIENT\_PATH”表示设备上的NFS路径,“nfs”表示客户端要挂载的路径,可以根据自己需要替换。 ->如果不想有NFS访问权限限制,可以在Linux命令行将NFS根目录权限设置成777: ->``` ->chmod -R 777 /home/sqbin/nfs ->``` ->至此,NFS客户端设置完毕。NFS文件系统已成功挂载。 - -1. 利用NFS共享文件 - -在NFS服务器下新建目录dir,并保存。在OpenHarmony内核下运行ls命令: - -``` -OHOS # ls /nfs -``` - -则可从串口得到如下回应: - -``` -OHOS # ls /nfs -Directory /nfs: -drwxr-xr-x 0 u:0 g:0 dir -``` - -可见,刚刚在NFS服务器上新建的dir目录已同步到客户端\(OpenHarmony内核系统\)的/nfs目录,两者保持同步。 - -同样地,在客户端\(OpenHarmony内核系统\)上创建文件和目录,在NFS服务器上也可以访问,读者可自行体验。 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->目前,NFS客户端仅支持NFS v3部分规范要求,因此对于规范支持不全的服务器,无法完全兼容。在开发测试过程中,建议使用Linux的NFS server,其对NFS支持很完善。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/04.\346\211\251\345\261\225\347\273\204\344\273\266/05.\346\226\207\344\273\266\347\263\273\347\273\237/02.\346\224\257\346\214\201\347\232\204\346\226\207\344\273\266\347\263\273\347\273\237/04.Ramfs.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/04.\346\211\251\345\261\225\347\273\204\344\273\266/05.\346\226\207\344\273\266\347\263\273\347\273\237/02.\346\224\257\346\214\201\347\232\204\346\226\207\344\273\266\347\263\273\347\273\237/04.Ramfs.md" deleted file mode 100644 index 00b20c87c353c24197dcbb3cec3904fde8716254..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/04.\346\211\251\345\261\225\347\273\204\344\273\266/05.\346\226\207\344\273\266\347\263\273\347\273\237/02.\346\224\257\346\214\201\347\232\204\346\226\207\344\273\266\347\263\273\347\273\237/04.Ramfs.md" +++ /dev/null @@ -1,77 +0,0 @@ ---- -title: Ramfs -permalink: /pages/0105010204050204 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# Ramfs - -- [基本概念](#section9507151014420) -- [运行机制](#section1859711263447) -- [开发指导](#section163554380448) - -## 基本概念 - -RAMFS是一个可动态调整大小的基于RAM的文件系统。RAMFS没有后备存储源。向RAMFS中进行的文件写操作也会分配目录项和页缓存,但是数据并不写回到任何其他存储介质上,掉电后数据丢失。 - -## 运行机制 - -RAMFS文件系统把所有的文件都放在 RAM 中,所以读/写操作发生在RAM中,可以用RAMFS来存储一些临时性或经常要修改的数据,例如/tmp和/var目录,这样既避免了对存储器的读写损耗,也提高了数据读写速度。 - -## 开发指导 - -挂载: - -``` -mount(NULL, "/dev/shm", "ramfs", 0, NULL) -``` - -创建目录: - -``` -mkdir(pathname, mode) -``` - -创建文件: - -``` -open(pathname, O_NONBLOCK | O_CREAT | O_RDWR, mode) -``` - -读取目录: - -``` -dir = opendir(pathname) -ptr = readdir(dir) -closedir(dir) -``` - -删除文件: - -``` -unlink(pathname) -``` - -删除目录: - -``` -rmdir(pathname) -``` - -去挂载: - -``` -umount("/dev/shm") -``` - ->![](/images/device-dev/public_sys-resources/icon-caution.gif) **注意:** ->- RAMFS只能挂载一次,一次挂载成功后,后面不能继续挂载到其他目录。 ->- RAMFS属于调测功能,默认配置为关闭,正式产品中不要使用该功能。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/04.\346\211\251\345\261\225\347\273\204\344\273\266/05.\346\226\207\344\273\266\347\263\273\347\273\237/02.\346\224\257\346\214\201\347\232\204\346\226\207\344\273\266\347\263\273\347\273\237/05.Procfs.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/04.\346\211\251\345\261\225\347\273\204\344\273\266/05.\346\226\207\344\273\266\347\263\273\347\273\237/02.\346\224\257\346\214\201\347\232\204\346\226\207\344\273\266\347\263\273\347\273\237/05.Procfs.md" deleted file mode 100644 index 964b5fcac4dfbccdc420f6a7aa22be1d5cbb0f76..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/04.\346\211\251\345\261\225\347\273\204\344\273\266/05.\346\226\207\344\273\266\347\263\273\347\273\237/02.\346\224\257\346\214\201\347\232\204\346\226\207\344\273\266\347\263\273\347\273\237/05.Procfs.md" +++ /dev/null @@ -1,98 +0,0 @@ ---- -title: Procfs -permalink: /pages/0105010204050205 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# Procfs - -- [基本概念](#section146801917174017) -- [运行机制](#section479762916408) -- [开发指导](#section1221174524014) - - [编程实例](#section52016575401) - - -## 基本概念 - -procfs是进程文件系统的简称,是一种虚拟文件系统,他用文件的形式,展示进程或其他系统信息。相比调用接口的方式获取信息,以文件操作的方式获取系统信息更为方便。 - -## 运行机制 - -OpenHarmony内核中,procfs在开机时会自动挂载到/proc目录下,仅支持内核模块创建文件节点来提供查询服务。 - -## 开发指导 - -procfs文件的创建无法使用一般的文件系统接口,需要使用ProcMkdir接口创建目录,使用CreateProcEntry接口创建文件。文件节点功能的开发就是实现read和write函数的钩子挂到CreateProcEntry创建的文件中。当用户使用读写procfs的文件时,就会调用到钩子函数来实现自定义的功能。 - -### 编程实例 - -下面我们以创建/proc/hello/world文件为例,实现如下功能: - -1.在/proc/hello/world位置创建一个文件 - -2.当读文件内容时,返回"HelloWorld!" - -3.当写文件内容时,打印写入的内容 - -``` -#include "proc_fs.h" - -static int TestRead(struct SeqBuf *buf, void *arg) -{ - LosBufPrintf(buf, "Hello World!\n"); /* 将数据打印到buffer中,这个buffer中的数据会返回到read的结果中 */ - return 0; -} - -static int TestWrite(struct ProcFile *pf, const char *buffer, size_t buflen, loff_t *ppos) -{ - if ((buffer == NULL) || (buflen <= 0)) { - return -EINVAL; - } - - PRINTK("your input is: %s\n", buffer); /* 注意和上面的read接口区别,这是对write接口输入命令的反馈,这个打印只会打印到控制台 */ - return buflen; -} -static const struct ProcFileOperations HELLO_WORLD_OPS = { - .read = TestRead, - .write = TestWrite, -}; - -void HelloWorldInit(void) -{ - /* 创建hello目录 */ - struct ProcDirEntry *dir = ProcMkdir("hello", NULL); - if (dir == NULL) { - PRINT_ERR("create dir failed!\n"); - return; - } - - /* 创建world文件 */ - struct ProcDirEntry *entry = CreateProcEntry("world", 0, dir); - if (entry == NULL) { - PRINT_ERR("create entry failed!\n"); - return; - } - - /* 将自定义的read和write钩子挂到文件中 */ - entry->procFileOps = &HELLO_WORLD_OPS; -} -``` - -**结果验证** - -启动后在shell输入如下命令 - -``` -OHOS # cat /proc/hello/world -OHOS # Hello World! -OHOS # echo "yo" > /proc/hello/world -OHOS # your input is: yo -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/04.\346\211\251\345\261\225\347\273\204\344\273\266/05.\346\226\207\344\273\266\347\263\273\347\273\237/03.\351\200\202\351\205\215\346\226\260\347\232\204\346\226\207\344\273\266\347\263\273\347\273\237.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/04.\346\211\251\345\261\225\347\273\204\344\273\266/05.\346\226\207\344\273\266\347\263\273\347\273\237/03.\351\200\202\351\205\215\346\226\260\347\232\204\346\226\207\344\273\266\347\263\273\347\273\237.md" deleted file mode 100644 index 4b282a5fd8b3c8bf4878718ea037fce07d41889f..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/04.\346\211\251\345\261\225\347\273\204\344\273\266/05.\346\226\207\344\273\266\347\263\273\347\273\237/03.\351\200\202\351\205\215\346\226\260\347\232\204\346\226\207\344\273\266\347\263\273\347\273\237.md" +++ /dev/null @@ -1,236 +0,0 @@ ---- -title: 适配新的文件系统 -permalink: /pages/01050102040503 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# 适配新的文件系统 - -- [基本概念](#section19480121811422) -- [适配Mount接口](#section147051940104212) -- [适配Lookup接口](#section11930181394317) -- [适配总结和注意事项](#section5617183014319) - -## 基本概念 - -所谓对接VFS层,其实就是指实现VFS层定义的若干接口函数,可根据文件系统的特点和需要适配其中部分接口。一般情况下,支持文件读写,最小的文件系统适配看起来是这样的: - -``` -struct MountOps g_yourFsMountOps = { - .Mount = YourMountMethod, -}; - -struct file_operations_vfs g_yourFsFileOps = { - .read = YourReadMethod, - .write = YourWriteMethod, -} - -struct VnodeOps g_yourFsVnodeOps = { - .Create = YourCreateMethod; - .Lookup = YourLookupMethod; - .Reclaim = YourReclaimMethod; -}; - -FSMAP_ENTRY(yourfs_fsmap, "your fs name", g_yourFsMountOps, TRUE, TRUE); // 注册文件系统 -``` - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->1. open和close接口不是必须要实现的接口,因为这两个接口是对文件的操作,对下层的文件系统一般是不感知的,只有当要适配的文件系统需要在open和close时做一些特别的操作时,才需要实现。 ->2. 适配文件系统,对基础知识的要求较高,适配者需要对要适配的文件系统的原理和实现具有深刻的理解,本节中不会事无巨细地介绍相关的基础知识,如果您在适配的过程中遇到疑问,建议参考kernel/liteos\_a/fs目录下已经适配好的文件系统的代码,可能就会豁然开朗。 - -## 适配Mount接口 - -Mount是文件系统第一个被调用的接口,该接口一般会读取驱动的参数,根据配置对文件系统的进行初始化,最后生成文件系统的root节点。Mount接口的定义如下: - -``` -int (*Mount)(struct Mount *mount, struct Vnode *blkDriver, const void *data); -``` - -其中,第一个参数struct Mount \*mount是Mount点的信息,适配时需要填写的是下面的变量: - -``` -struct Mount { - const struct MountOps *ops; /* Mount相关的函数钩子 */ - struct Vnode *vnodeCovered; /* Mount之后的文件系统root节点 */ - void *data; /* Mount点的私有数据 */ -}; -``` - -第二个参数struct Vnode \*blkDriver是驱动节点,可以通过这个节点访问驱动。 - -第三个参数const void \*data是mount命令传入的数据,可以根据文件系统的需要处理。 - -下面以JFFS2为例,详细看一下mount接口是如何适配的: - -``` -int VfsJffs2Bind(struct Mount *mnt, struct Vnode *blkDriver, const void *data) -{ - int ret; - int partNo; - mtd_partition *p = NULL; - struct MtdDev *mtd = NULL; - struct Vnode *pv = NULL; - struct jffs2_inode *rootNode = NULL; - - LOS_MuxLock(&g_jffs2FsLock, (uint32_t)JFFS2_WAITING_FOREVER); - - /* 首先是从驱动节点中获取文件系统需要的信息,例如jffs2读取的是分区的编号 */ - p = (mtd_partition *)((struct drv_data *)blkDriver->data)->priv; - mtd = (struct MtdDev *)(p->mtd_info); - - if (mtd == NULL || mtd->type != MTD_NORFLASH) { - LOS_MuxUnlock(&g_jffs2FsLock); - return -EINVAL; - } - - partNo = p->patitionnum; - - /* 然后生成一个文件系统的根Vnode,这里注意不要搞混rootNode和根Vnode,rootNode类型是inode,是jffs2内部维护的私有数据,而Vnode是VFS的概念,是通用的文件节点, - 这一步实际上就是把文件系统内部的私有信息保存到Vnode中,这样就可以通过Vnode直接找到文件系统中的对应文件。 - */ - ret = jffs2_mount(partNo, &rootNode); - if (ret != 0) { - LOS_MuxUnlock(&g_jffs2FsLock); - return ret; - } - - ret = VnodeAlloc(&g_jffs2Vops, &pv); - if (ret != 0) { - LOS_MuxUnlock(&g_jffs2FsLock); - goto ERROR_WITH_VNODE; - } - - /* 下面这段填写的是关于这个Vnode对应文件的相关信息,uid\gid\mode这部分信息,有的文件系统可能不支持,可以不填 */ - pv->type = VNODE_TYPE_DIR; - pv->data = (void *)rootNode; - pv->originMount = mnt; - pv->fop = &g_jffs2Fops; - mnt->data = p; - mnt->vnodeCovered = pv; - pv->uid = rootNode->i_uid; - pv->gid = rootNode->i_gid; - pv->mode = rootNode->i_mode; - - /* 这里的HashInsert是为了防止重复生成已经生成过的Vnode, 第二个参数一般会选择本文件系统内可以唯一确定某一个文件的信息,例如这里是jffs2内部inode的地址 */ - (void)VfsHashInsert(pv, rootNode->i_ino); - - g_jffs2PartList[partNo] = blkDriver; - - LOS_MuxUnlock(&g_jffs2FsLock); - - return 0; -ERROR_WITH_VNODE: - return ret; -} -... -... -const struct MountOps jffs_operations = { - .Mount = VfsJffs2Bind, - ... - ... -}; -``` - -总结: - -1. 首先从驱动节点中获取需要的私有信息。 -2. 根据私有信息,生成文件系统的根节点。 - -## 适配Lookup接口 - -Lookup是查找文件的接口,它的函数原型是: - -``` -int (*Lookup)(struct Vnode *parent, const char *name, int len, struct Vnode **vnode); -``` - -很好理解,就是从父节点parent开始,根据文件名name和文件名长度len,查找到对应的vnode返回给上层。 - -这个接口适配起来思路很清晰,给了父节点的信息和文件名,实现从父目录中查询名字为name的文件这个功能,同样以JFFS2为例: - -``` -int VfsJffs2Lookup(struct Vnode *parentVnode, const char *path, int len, struct Vnode **ppVnode) -{ - int ret; - struct Vnode *newVnode = NULL; - struct jffs2_inode *node = NULL; - struct jffs2_inode *parentNode = NULL; - - LOS_MuxLock(&g_jffs2FsLock, (uint32_t)JFFS2_WAITING_FOREVER); - - /* 首先从private data中提取父节点的信息 */ - parentNode = (struct jffs2_inode *)parentVnode->data; - - /* 然后查询得到目标节点的信息,注意这里调用的jffs2_lookup是jffs2本身的查询函数 */ - node = jffs2_lookup(parentNode, (const unsigned char *)path, len); - if (!node) { - LOS_MuxUnlock(&g_jffs2FsLock); - return -ENOENT; - } - - /* 接着先校验一下查找到的目标是否已经有现成的vnode了,这里对应之前提到的VfsHashInsert */ - (void)VfsHashGet(parentVnode->originMount, node->i_ino, &newVnode, NULL, NULL); - LOS_MuxUnlock(&g_jffs2FsLock); - if (newVnode) { - newVnode->parent = parentVnode; - *ppVnode = newVnode; - return 0; - } - - /* 如果vnode不存在,就新生成一个vnode,并填写相关信息 */ - ret = VnodeAlloc(&g_jffs2Vops, &newVnode); - if (ret != 0) { - PRINT_ERR("%s-%d, ret: %x\n", __FUNCTION__, __LINE__, ret); - (void)jffs2_iput(node); - LOS_MuxUnlock(&g_jffs2FsLock); - return ret; - } - - Jffs2SetVtype(node, newVnode); - newVnode->fop = parentVnode->fop; - newVnode->data = node; - newVnode->parent = parentVnode; - newVnode->originMount = parentVnode->originMount; - newVnode->uid = node->i_uid; - newVnode->gid = node->i_gid; - newVnode->mode = node->i_mode; - - /* 同时不要忘记将新生成的vnode插入hashtable中 */ - (void)VfsHashInsert(newVnode, node->i_ino); - - *ppVnode = newVnode; - - LOS_MuxUnlock(&g_jffs2FsLock); - return 0; -} -``` - -总结: - -1. 从父节点获取私有数据; -2. 根据私有信息查询到目标文件的私有数据; -3. 通过目标文件的私有数据生成目标Vnode。 - -## 适配总结和注意事项 - -通过上面两个接口的适配,其实可以发现一个规律,不管是什么接口,基本都遵循下面的适配步骤: - -1. 通过入参的vnode获取文件系统所需的私有数据。 -2. 使用私有数据完成接口的功能。 -3. 将结果包装成vnode或接口要求的其他返回格式,返回给上层。 - -核心的逻辑其实在使用私有数据完成接口的功能,这些接口都是些文件系统的通用功能,文件系统在移植前本身应该都有相应实现,所以关键是归纳总结出文件系统所需的私有数据是什么,将其存储在vnode中,供之后使用。一般情况下,私有数据的内容是可以唯一定位到文件在存储介质上位置的信息,大部分文件系统本身都会有类似数据结构可以直接使用,比如JFFS2的inode数据结构。 - ->![](/images/device-dev/public_sys-resources/icon-caution.gif) **注意:** ->1. 访问文件时,不一定会调用文件系统中的Lookup接口,仅在上层的路径缓存失效时才会调用到。 ->2. 通过VfsHashGet找到了已经存在的Vnode,不要直接将其作为结果返回,其储存的信息可能已经失效,请更新相应字段后再返回。 ->3. Vnode会根据内存占用在后台自动释放,需要持久保存的信息,不要只保存在Vnode中。 ->4. Reclaim接口在Vnode释放时会自动调用,请在这个接口中释放私有数据中的资源。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/01.Shell\344\273\213\347\273\215.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/01.Shell\344\273\213\347\273\215.md" deleted file mode 100644 index 7fe0a5583dc74f62c2e3e3d48e04696e2d577d8a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/01.Shell\344\273\213\347\273\215.md" +++ /dev/null @@ -1,49 +0,0 @@ ---- -title: Shell介绍 -permalink: /pages/01050102050101 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# Shell介绍 - -- [注意事项](#section12298165312328) - -OpenHarmony内核提供的Shell支持调试常用的基本功能,包含系统、文件、网络和动态加载相关命令。同时OpenHarmony内核的Shell支持添加新的命令,可以根据需求来进行定制。 - -- 系统相关命令:提供查询系统任务、内核信号量、系统软件定时器、CPU占用率、当前中断等相关信息的能力。 - -- 文件相关命令:支持基本的ls、cd等功能。 - -- 网络相关命令:支持查询接到开发板的其他设备的IP、查询本机IP、测试网络连接、设置开发板的AP和station模式等相关功能。 - - 新增命令的详细流程可参见[Shell命令开发指导](/pages/01050102050102)和[Shell命令编程实例](/pages/01050102050103)。 - - -## 注意事项 - -在使用Shell功能的过程中,需要注意以下几点: - -- Shell功能支持使用exec命令来运行可执行文件。 -- Shell功能支持默认模式下英文输入。如果出现用户在UTF-8格式下输入了中文字符的情况,只能通过回退三次来删除。 - -- Shell功能支持shell命令、文件名及目录名的Tab键联想补全。若有多个匹配项,则根据共同字符, 打印多个匹配项。对于过多的匹配项(打印多于24行),将会进行打印询问(Display all num possibilities?(y/n)),用户可输入y选择全部打印,或输入n退出打印,选择全部打印并打印超过24行后,会进行--More--提示,此时按回车键继续打印,按q键退出(支持Ctrl+c退出\)。 - -- Shell端工作目录与系统工作目录是分开的,即通过Shell端cd pwd等命令是对Shell端工作目录进行操作,通过chdir getcwd等命令是对系统工作目录进行操作,两个工作目录相互之间没有联系。当文件系统操作命令入参是相对路径时要格外注意。 - -- 在使用网络Shell指令前,需要先调用tcpip\_init函数完成网络初始化并完成telnet连接后才能起作用,内核默认不初始化tcpip\_init。 - -- 不建议使用Shell命令对/dev目录下的设备文件进行操作,这可能会引起不可预知的结果。 - -- Shell功能不符合POSIX标准,仅供调试使用。 - - >![](/images/device-dev/public_sys-resources/icon-notice.gif) **须知:** - >Shell功能仅供调试使用,在Debug版本中开启(使用时通过menuconfig在配置项中开启"LOSCFG\_DEBUG\_VERSION"编译开关进行相关控制),商用产品中禁止包含该功能。 - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/02.Shell\345\221\275\344\273\244\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/02.Shell\345\221\275\344\273\244\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index 3bda31395af06179125b73d4865a1cc605616c27..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/02.Shell\345\221\275\344\273\244\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,178 +0,0 @@ ---- -title: Shell命令开发指导 -permalink: /pages/01050102050102 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# Shell命令开发指导 - -- [开发指导](#section13408945163812) - -## 开发指导 - -新增Shell命令的典型开发流程如下: - -1. 包含如下头文件: - - ``` - #include "shell.h" - #include "shcmd.h" - ``` - -2. 注册命令。用户可以选择静态注册命令方式和系统运行时动态注册命令方式,静态注册命令方式一般用在系统常用命令注册,动态注册命令方式一般用在用户命令注册。 - - 1. 静态注册命令方式: - - 1. 通过宏的方式注册。 - - 这个宏的原型为: - - ``` - SHELLCMD_ENTRY(l, cmdType, cmdKey, paraNum, cmdHook) - ``` - - **表 1** SHELLCMD\_ENTRY参数详解 - - - - - - - - - - - - - - - - - - - - - - -

参数

-

描述

-

l

-

静态注册全局变量名(注意:不与系统中其他symbol重名)。

-

cmdType

-

命令类型:

-
  • CMD_TYPE_EX:不支持标准命令参数输入,会把用户填写的命令关键字屏蔽掉,例如:输入ls /ramfs,传入给注册函数的参数只有/ramfs,而ls命令关键字并不会被传入。

    -
  • CMD_TYPE_STD:支持的标准命令参数输入,所有输入的字符都会通过命令解析后被传入。

    -
-

cmdKey

-

命令关键字,函数在Shell中访问的名称。

-

paraNum

-

调用的执行函数的入参最大个数,暂不支持。

-

cmdHook

-

命令执行函数地址,即命令实际执行函数。

-
- - 如: - - ``` - SHELLCMD_ENTRY(ls_shellcmd, CMD_TYPE_EX, "ls", XARGS, (CMD_CBK_FUNC)osShellCmdLs) - ``` - - 2. 在build/mk/liteos\_tables\_ldflags.mk中添加相应选项: - - 如:上述“ls”命令注册时,需在build/mk/liteos\_tables\_ldflags.mk中添加“-uls\_shellcmd”。其中-u后面跟SHELLCMD\_ENTRY的第一个参数。 - - 2. 动态注册命令方式: - - 注册函数原型: - - ``` - UINT32 osCmdReg(CmdT ype cmdType, CHAR *cmdKey, UINT32 paraNum, CmdCallBackFunc cmdProc) - ``` - - **表 2** UINT32 osCmdReg参数详解 - - - - - - - - - - - - - - - - - - - -

参数

-

描述

-

cmdType

-

命令类型:

-
  • CMD_TYPE_EX:不支持标准命令参数输入,会把用户填写的命令关键字屏蔽掉,例如:输入ls /ramfs,传入给注册函数的参数只有/ramfs,而ls命令关键字并不会被传入。

    -
  • CMD_TYPE_STD:支持的标准命令参数输入,所有输入的字符都会通过命令解析后被传入。

    -
-

cmdKey

-

命令关键字,函数在Shell中访问的名称。

-

paraNum

-

调用的执行函数的入参最大个数,暂不支持该参数;当前为默认值XARGS(0xFFFFFFFF)。

-

cmdHook

-

命令执行函数地址,即命令实际执行函数。

-
- - 如: - - ``` - osCmdReg(CMD_TYPE_EX, "ls", XARGS, (CMD_CBK_FUNC)osShellCmdLs) - ``` - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >命令关键字必须是唯一的,也即两个不同的命令项不能拥有相同的命令关键字,否则只会执行其中一个。 - >Shell在执行用户命令时,如果存在多个命令关键字相同的命令,只会执行其中在"help"命令中排序在最前面的一个。 - -3. 添加内置命令函数原型。 - - ``` - UINT32 osShellCmdLs(UINT32 argc, CHAR **argv) - ``` - - **表 3** osShellCmdLs参数说明 - - - - - - - - - - - - - -

参数

-

参数描述

-

argc

-

Shell命令中,参数个数。

-

argv

-

为指针数组,每个元素指向一个字符串,可以根据选择命令类型,决定是否要把命令关键字传入给注册函数。

-
- -4. 输入Shell命令,有两种输入方式: - - 在串口工具中直接输入Shell命令。 - - - 在telnet工具中输入Shell命令(telnet使用方式详见[telnet](/pages/010501020501040309))。 - - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/03.Shell\345\221\275\344\273\244\347\274\226\347\250\213\345\256\236\344\276\213.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/03.Shell\345\221\275\344\273\244\347\274\226\347\250\213\345\256\236\344\276\213.md" deleted file mode 100644 index db54006745d629c511f6c918b32fcb835ad331b6..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/03.Shell\345\221\275\344\273\244\347\274\226\347\250\213\345\256\236\344\276\213.md" +++ /dev/null @@ -1,136 +0,0 @@ ---- -title: Shell命令编程实例 -permalink: /pages/01050102050103 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# Shell命令编程实例 - -- [实例描述](#section87143612316) -- [静态注册方式](#section1660495712314) -- [静态注册编程实例](#section1233411684113) -- [动态注册方式](#section6804126192412) -- [动态注册编程实例](#section2335121613418) - -## 实例描述 - -在下面的两个例子中,演示如何使用静态注册命令方式和动态注册命令方式新增一个Shell命令:**test**。 - -## 静态注册方式 - -开发流程如下: - -1. 定义一个新增命令所要调用的执行函数cmd\_test。 - -2. 使用SHELLCMD\_ENTRY函数添加新增命令项。 - -3. 在链接选项liteos\_tables\_ldflags.mk中添加链接该新增命令项参数。 - -4. 重新编译代码后运行。 - - -## 静态注册编程实例 - -1. 定义命令所要调用的函数cmd\_test: - - ``` - #include "shell.h" - #include "shcmd.h" - int cmd_test(void) - { - printf("hello everybody!\n"); - return 0; - } - ``` - -2. 新增命令项: - - ``` - SHELLCMD_ENTRY(test_shellcmd, CMD_TYPE_EX, "test", 0, (CMD_CBK_FUNC)cmd_test); - ``` - -3. 在链接选项中添加链接该新增命令项参数: - - 在liteos\_tables\_ldflags.mk文件的LITEOS\_TABLES\_LDFLAGS项下添加-utest\_shellcmd。 - -4. 重新编译代码: - - ``` - make clean;make - ``` - -5. 用help命令查看当前系统所有的注册命令,可以发现test命令已经注册。(以下命令集合仅供参考,以实际编译运行情况为准。) - - ``` - OHOS # help - *******************shell commands:************************* - - arp cat cd chgrp chmod chown cp cpup - date dhclient dmesg dns format free help hwi - ifconfig ipdebug kill log ls lsfd memcheck mkdir - mount netstat oom partinfo partition ping ping6 pwd - reset rm rmdir sem statfs su swtmr sync - systeminfo task telnet test tftp touch umount uname - watch writeproc - ``` - - -## 动态注册方式 - -开发流程如下: - -1. 使用osCmdReg函数添加新增命令项。 - -2. 重新编译后运行。 - - -## 动态注册编程实例 - -1. 在用户应用函数中调用osCmdReg函数动态注册命令。 - - ``` - #include "shell.h" - #include "shcmd.h" - int cmd_test(void) - { - printf("hello everybody!\n"); - return 0; - } - void app_init(void) - { - .... - .... - osCmdReg(CMD_TYPE_EX, "test", 0,(CMD_CBK_FUNC)cmd_test); - .... - } - ``` - -2. 重新编译代码: - - ``` - make clean;make - ``` - -3. 用help命令查看当前系统所有的注册命令,可以发现test命令已经注册。 - - ``` - OHOS # help - *******************shell commands:************************* - - arp cat cd chgrp chmod chown cp cpup - date dhclient dmesg dns format free help hwi - ifconfig ipdebug kill log ls lsfd memcheck mkdir - mount netstat oom partinfo partition ping ping6 pwd - reset rm rmdir sem statfs su swtmr sync - systeminfo task telnet test tftp touch umount uname - watch writeproc - ``` - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/01.cpup.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/01.cpup.md" deleted file mode 100644 index 6de3ac24228c031cca85e959ec180737e54e99b2..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/01.cpup.md" +++ /dev/null @@ -1,80 +0,0 @@ ---- -title: cpup -permalink: /pages/010501020501040101 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# cpup - -- [命令功能](#section1842161614217) -- [命令格式](#section5629527427) -- [参数说明](#section133651361023) -- [使用指南](#section156611948521) -- [使用实例](#section68501605319) -- [输出说明](#section19871522144219) - -## 命令功能 - -cpup命令用于查询系统CPU的占用率。 - -## 命令格式 - -cpup \[_mode_\] \[_taskID_\] - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

mode

-
  • 缺省:显示系统最近10s内的CPU占用率。
  • 0:显示系统最近10s内的CPU占用率。
  • 1:显示系统最近1s内的CPU占用率。
  • 其他数字:显示系统启动至今总的CPU 占用率。
-

[0,0xFFFFFFFF]

-

taskID

-

任务ID号

-

[0,0xFFFFFFFF]

-
- -## 使用指南 - -- 参数缺省时,显示系统10s前的CPU占用率。 -- 只有一个参数时,该参数为mode,显示系统相应时间前的CPU占用率。 -- 输入两个参数时,第一个参数为mode,第二个参数为taskID,显示对应ID号任务的相应时间前的CPU占用率。 - -## 使用实例 - -举例:输入cpup 1 5 - -## 输出说明 - -**示例** 指令输出结果 - -```shell -OHOS # cpup 1 5 - -pid 5 CpuUsage in 1s: 0.0 -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/02.date.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/02.date.md" deleted file mode 100644 index d28d9b533c0e321188a2bf998b0f6fecea9999e2..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/02.date.md" +++ /dev/null @@ -1,93 +0,0 @@ ---- -title: date -permalink: /pages/010501020501040102 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# date - -- [命令功能](#section56472016338) -- [命令格式](#section16635112512316) -- [参数说明](#section15896030039) -- [使用指南](#section116361036636) -- [使用实例](#section021711411237) -- [输出说明](#section17950184414312) - -## 命令功能 - -date命令用于查询系统日期和时间。 - -## 命令格式 - -- date - -- date --help - -- date +\[_Format_\] - -- date -u - - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

--help

-

使用帮助。

-

N/A

-

+Format

-

根据Format格式打印日期和时间。

-

--help中列出的占位符。

-

-u

-

显示UTC,而不是当前时区

-

N/A

-
- -## 使用指南 - -- date参数缺省时,默认显示系统UTC日期和时间。 -- --help、+Format、-u不能混合使用。 -- 目前命令不支持设置时间和日期。 - -## 使用实例 - -举例:输入 date +%Y--%m--%d - -## 输出说明 - -**示例** 按指定格式打印系统日期 - -```shell -OHOS:/$ date +%Y--%m--%d -1970--01--01 -``` \ No newline at end of file diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/03.dmesg.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/03.dmesg.md" deleted file mode 100644 index 50731b62f7ed975cfaef1f7b53a1b9315fd071cf..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/03.dmesg.md" +++ /dev/null @@ -1,128 +0,0 @@ ---- -title: dmesg -permalink: /pages/010501020501040103 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# dmesg - -- [命令功能](#section01) -- [命令格式](#section02) -- [参数说明](#section03) -- [使用指南](#section04) -- [使用实例](#section05) -- [输出说明](#section06) - -## 命令功能 - -dmesg命令用于控制内核dmesg缓存区。 - -## 命令格式 - -- dmesg - -- dmesg \[_-c/-C/-D/-E/-L/-U_\] - -- dmesg -s \[_size_\] - -- dmesg -l \[_level_\] - -- dmesg \> \[_fileA_\] - - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

-c

-

打印缓存区内容并清空缓存区。

-

N/A

-

-C

-

清空缓存区。

-

N/A

-

-D/-E

-

关闭/开启控制台打印。

-

N/A

-

-L/-U

-

关闭/开启串口打印。

-

N/A

-

-s size

-

设置缓存区大小,size是要设置的大小。

-

1-81920

-

-l level

-

设置缓存等级。

-

0 - 5

-

> fileA

-

将缓存区内容写入文件。

-

N/A

-
- -## 使用指南 - -- 该命令依赖于LOSCFG\_SHELL\_DMESG,使用时通过menuconfig在配置项中开启"Enable Shell dmesg": - - Debug ---\> Enable a Debug Version ---\> Enable Shell ---\> Enable Shell dmesg - -- dmesg参数缺省时,默认打印缓存区内容。 -- 各“ - ”选项不能混合使用。 - 1. 写入文件需确保已挂载文件系统。 - 2. 关闭串口打印会影响shell使用,建议先连接telnet再尝试关闭串口。 - - -## 使用实例 - -举例:输入dmesg \> dmesg.log。 - -## 输出说明 - -**示例** dmesg重定向到文件。 - -```shell -OHOS # dmesg > dmesg.log -Dmesg write log to dmesg.log success -``` diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/04.exec.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/04.exec.md" deleted file mode 100644 index d59d2598e166587322dbf28834c1e317a8f7264c..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/04.exec.md" +++ /dev/null @@ -1,73 +0,0 @@ ---- -title: exec -permalink: /pages/010501020501040104 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# exec - -- [命令功能](#section4643204919313) -- [命令格式](#section6553153635) -- [参数说明](#section208971157532) -- [使用指南](#section213115219413) -- [使用实例](#section13736564418) -- [输出说明](#section194005101413) - -## 命令功能 - -exec命令属于shell内置命令,目前实现最基础的执行用户态程序的功能。 - -## 命令格式 - -exec <_executable-file_\> - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

executable-file

-

有效的可执行文件。

-

N/A

-
- -## 使用指南 - -该命令当前仅支持执行有效的二进制程序,程序成功执行,默认后台运行,但与Shell共用终端,可能会导致程序打印输出与Shell输出交错显示。 - -## 使用实例 - -举例: - -输入exec helloworld。 - -## 输出说明 - -``` -OHOS # exec helloworld -OHOS # hello world! -``` - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->可执行文件执行后,先打印“OHOS \#”提示符原因:目前Shell “exec”命令执行均为后台执行,结果可能导致提示符提前打印。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/05.free.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/05.free.md" deleted file mode 100644 index 8d743531658be98e7d4028795bac5895578fc05f..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/05.free.md" +++ /dev/null @@ -1,161 +0,0 @@ ---- -title: free -permalink: /pages/010501020501040105 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# free - -- [命令功能](#section01) -- [命令格式](#section02) -- [参数说明](#section03) -- [使用指南](#section04) -- [使用实例](#section05) -- [输出说明](#section06) - -## 命令功能 - -free命令可显示系统内存的使用情况。 - -## 命令格式 - -free \[_-b | -k | -m | -g | -t_\] - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

无参数

-

以Byte为单位显示。

-

N/A

-

--help/-h

-

查看free命令支持的参数列表。

-

N/A

-

-b

-

以Byte为单位显示。

-

N/A

-

-k

-

以KiB为单位显示。

-

N/A

-

-m

-

以MiB为单位显示。

-

N/A

-

-g

-

以GiB为单位显示。

-

N/A

-

-t

-

以TiB为单位显示。

-

N/A

-
- -## 使用指南 - -无。 - -## 使用实例 - -举例:分别输入free、free -k、free -m。 - -## 输出说明 - -**示例** 以三种方式显示内存使用情况 - -```shell -OHOS:/$ free - total used free shared buffers -Mem: 2819652 2754468 65184 0 0 --/+ buffers/cache: 2754468 65184 -Swap: 0 0 0 -OHOS:/$ free -k - total used free shared buffers -Mem: 2753 2692 60 0 0 --/+ buffers/cache: 2692 60 -Swap: 0 0 0 -OHOS:/$ free -m - total used free shared buffers -Mem: 2 2 0 0 0 --/+ buffers/cache: 2 0 -Swap: 0 0 0 -``` - -**表 2** 输出元素说明 - - - - - - - - - - - - - - - - - - - - - - -

输出

-

说明

-

total

-

表示系统动态内存池总量。

-

used

-

表示已使用内存总量。

-

free

-

表示未被分配的内存大小。

-

shared

-

表示共享内存大小。

-

buffers

-

表示缓冲区内存大小。

-
diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/06.help.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/06.help.md" deleted file mode 100644 index 2633a0ca6c770a8e50f02ce5f1384b0df5efd35e..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/06.help.md" +++ /dev/null @@ -1,76 +0,0 @@ ---- -title: help -permalink: /pages/010501020501040106 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# help - -- [命令功能](#section01) -- [命令格式](#section02) -- [参数说明](#section03) -- [使用指南](#section04) -- [使用实例](#section05) -- [输出说明](#section06) - -## 命令功能 - -help命令用于显示当前操作系统内所有操作指令和部分toybox指令。 - -## 命令格式 - -help - -## 参数说明 - -无。 - -## 使用指南 - -help用于显示当前操作系统内所有操作指令。 - -## 使用实例 - -举例:输入help。 - -## 输出说明 - -**示例** 查看系统内所有操作指令 - -```shell -OHOS:/$ help -OHOS:/$ help -*******************shell commands:************************* - -arp cat cat_logmpp cd chgrp chmod -chown cp cpup date dhclient dmesg -dns format free help hi3881 hwi -ifconfig ipdebug kill log ls lsfd -memcheck mkdir mount netstat oom panicreset -partinfo partition ping ping6 pmm pwd -reset rm rmdir sem shm stack -statfs su swtmr sync systeminfo task -telnet touch umount uname v2p vmm -watch writeproc - -After shell prompt "OHOS # ": -Use ` [args ...]` to run built-in shell commands listed above. -Use `exec [args ...]` or `./ [args ...]` to run external commands. - -*******************toybox commands:************************ - -chgrp chmod chown cp date du free help ifconfig kill ls mkdir mount -mv ping ps reboot rm rmdir top touch umount uname - -Use `toybox help [command]` to show usage information for a specific command. - -Use `shell` to enter interactive legacy shell. -Use `alias` to display command aliases. -``` diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/07.hwi.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/07.hwi.md" deleted file mode 100644 index 336ce7793422668a480927cfc9361c791415f72d..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/07.hwi.md" +++ /dev/null @@ -1,175 +0,0 @@ ---- -title: hwi -permalink: /pages/010501020501040107 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# hwi - -- [命令功能](#section445335110416) -- [命令格式](#section1795712553416) -- [参数说明](#section92544592410) -- [使用指南](#section104151141252) -- [使用实例](#section11545171957) -- [输出说明](#section075617368542) - -## 命令功能 - -hwi命令查询当前中断信息 - -## 命令格式 - -hwi - -## 参数说明 - -无。 - -## 使用指南 - -- 输入hwi即显示当前中断号、中断次数及注册中断名称。 -- 若开关LOSCFG\_CPUP\_INCLUDE\_IRQ打开,则还会显示各个中断的处理时间(cycles)、CPU占用率以及中断类型。 - -## 使用实例 - -举例:输入hwi - -## 输出说明 - -- 显示中断信息(LOSCFG\_CPUP\_INCLUDE\_IRQ关闭) - -```shell -OHOS # hwi - InterruptNo Count Name - 0: 0: - 1: 1025641: - 2: 0: - 29: 824049: - 37: 0: rtc_alarm - 38: 24: uart_pl011 - 48: 3: GPIO - 59: 0: - 62: 530: MMC_IRQ - 63: 70: MMC_IRQ - 64: 280: ETH - 67: 58: tde - 68: 0: JPGE_0 - 69: 0: IVE - 70: 0: VGS - 72: 0: VEDU_0 - 73: 0: nnie0 - 74: 0: nnie_gdc0 - 75: 0: VPSS - 76: 0: VI_PROC0 - 77: 0: JPEGD_0 - 83: 49455: HIFB_SOFT_INT - 87: 0: AIO interrupt - 88: 0: VI_CAP0 - 89: 0: MIPI_RX - 90: 49455: VO int - 91: 49456: HIFB Int - 96: 17601: MMC_IRQ - 100: 0: SPI_HI35XX - 101: 0: SPI_HI35XX - 102: 0: SPI_HI35XX - -``` - -- 显示中断信息(LOSCFG\_CPUP\_INCLUDE\_IRQ打开) - -```shell -OHOS # hwi - InterruptNo Count ATime(us) CPUUSE CPUUSE10s CPUUSE1s Mode Name - 0: 0 0 0.0 0.0 0.0 normal - 1: 937031 0 0.1 0.1 0.1 normal - 2: 0 0 0.0 0.0 0.0 normal - 29: 726166 5 0.54 0.57 0.59 normal - 37: 0 0 0.0 0.0 0.0 normal rtc_alarm - 38: 17 5 0.0 0.0 0.0 normal uart_pl011 - 48: 3 4 0.0 0.0 0.0 normal GPIO - 59: 0 0 0.0 0.0 0.0 normal - 62: 531 1 0.0 0.0 0.0 normal MMC_IRQ - 63: 69 1 0.0 0.0 0.0 normal MMC_IRQ - 64: 292 2 0.0 0.0 0.0 normal ETH - 67: 54 76 0.0 0.0 0.0 shared tde - 68: 0 0 0.0 0.0 0.0 shared JPGE_0 - 69: 0 0 0.0 0.0 0.0 shared IVE - 70: 0 0 0.0 0.0 0.0 shared VGS - 72: 0 0 0.0 0.0 0.0 shared VEDU_0 - 73: 0 0 0.0 0.0 0.0 shared nnie0 - 74: 0 0 0.0 0.0 0.0 shared nnie_gdc0 - 75: 0 0 0.0 0.0 0.0 shared VPSS - 76: 0 0 0.0 0.0 0.0 shared VI_PROC0 - 77: 0 0 0.0 0.0 0.0 shared JPEGD_0 - 83: 45529 8 0.5 0.5 0.5 shared HIFB_SOFT_INT - 87: 0 0 0.0 0.0 0.0 shared AIO interrupt - 88: 0 0 0.0 0.0 0.0 shared VI_CAP0 - 89: 0 0 0.0 0.0 0.0 shared MIPI_RX - 90: 45534 11 0.6 0.7 0.7 shared VO int - 91: 45533 2 0.1 0.1 0.1 shared HIFB Int - 96: 17383 2 0.0 0.0 0.0 normal MMC_IRQ - 100: 0 0 0.0 0.0 0.0 normal SPI_HI35XX - 101: 0 0 0.0 0.0 0.0 normal SPI_HI35XX - 102: 0 0 0.0 0.0 0.0 normal SPI_HI35XX -``` - -**表 1** 输出说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

输出

-

说明

-

InterruptNo

-

中断号。

-

Count

-

中断次数。

-

Name

-

注册中断名称。

-

CYCLECOST

-

中断的处理时间(cycles)。

-

CPUUSE

-

CPU占用率。

-

CPUUSE10s

-

最近10s CPU占用率。

-

CPUUSE1s

-

最近1s CPU占用率。

-

mode

-

中断类型:

-
  • normal: 非共享中断。
  • shared: 共享中断。
-
- diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/08.kill.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/08.kill.md" deleted file mode 100644 index 254a89757d10d23ece9f9a90fa08b47dcc3d8bfd..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/08.kill.md" +++ /dev/null @@ -1,170 +0,0 @@ ---- -title: kill -permalink: /pages/010501020501040108 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# kill - -- [命令功能](#section01) -- [命令格式](#section02) -- [参数说明](#section03) -- [使用指南](#section04) -- [使用实例](#section05) -- [输出说明](#section06) - -## 命令功能 - -命令用于发送特定信号给指定进程。 - -## 命令格式 - -kill \[-l \[_signo_\] | _-s signo_ | _-signo_\] _pid..._ - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

--help

-

查看kill命令支持的参数列表

-

N/A

-

-l

-

列出信号名称和编号。

-

N/A

-

-s

-

发送信号

-

N/A

-

signo

-

信号ID。

-

[1,30]

-

pid

-

进程ID。

-

[1,MAX_INT]

-
- ->![](/images/device-dev/public_sys-resources/icon-notice.gif) **须知:** ->signo有效范围为\[0,64\],建议取值范围为\[1,30\],其余为保留内容。 - -## 使用指南 - -- 必须指定发送的信号编号及进程号。 - -- 进程编号取值范围根据系统配置变化,例如系统最大支持pid为256,则取值范围缩小为\[1-256\]。 - - -## 使用实例 - -- 查看当前进程列表,查看需要杀死的进程PID(42)。 - -``` -OHOS:/$ ps - - allCpu(%): 4.67 sys, 195.33 idle - - PID PPID PGID UID Status VirtualMem ShareMem PhysicalMem CPUUSE10s PName - 1 -1 1 0 Pending 0x33b000 0xbb000 0x4db02 0.0 init - 2 -1 2 0 Pending 0xdabc08 0 0xdabc08 1.14 KProcess - 3 1 3 7 Pending 0x72e000 0x1a3000 0x1d24c2 0.0 foundation - 4 1 4 8 Pending 0x362000 0xbb000 0x5c6ff 0.0 bundle_daemon - 5 1 5 1 Pending 0xdfa000 0x2e7000 0x1484f0 0.0 appspawn - 6 1 6 0 Pending 0x688000 0x137000 0x11bca0 0.0 media_server - 7 1 7 0 Pending 0x9d2000 0x103000 0xa1cdf 0.88 wms_server - 8 1 8 2 Pending 0x1f5000 0x48000 0x47dc2 0.2 mksh - 10 5 5 101 Pending 0x11ec000 0x2f9000 0x206047 0.93 com.huawei.launcher - 12 1 12 0 Pending 0x4d4000 0x112000 0xe0882 0.0 deviceauth_service - 13 1 13 0 Pending 0x34f000 0xbd000 0x51799 0.0 sensor_service - 14 1 14 2 Pending 0x34e000 0xb3000 0x52184 0.0 ai_server - 15 1 15 0 Pending 0x61f000 0x13b000 0x168071 0.45 softbus_server - 42 8 42 2 Pending 0x1c1000 0x3a000 0x1106a 0.9 test_demo - 43 8 43 2 Running 0x1d7000 0x3a000 0x1e577 0.0 toybox -``` - -发送信号9(SIGKILL默认行为为立即终止进程)给42号进程**test\_demo**(用户态进程):**kill -s 9 42**(kill -9 42效果相同),并查看当前进程列表,42号进程已终止。 - -``` -OHOS:/$ kill -s 9 42 -OHOS:/$ -[1] + Killed ./nfs/test_demo -OHOS:/$ ps - - allCpu(%): 4.73 sys, 195.27 idle - - PID PPID PGID UID Status VirtualMem ShareMem PhysicalMem CPUUSE10s PName - 1 -1 1 0 Pending 0x33b000 0xbb000 0x4e01c 0.0 init - 2 -1 2 0 Pending 0xda5fa4 0 0xda5fa4 1.14 KProcess - 3 1 3 7 Pending 0x72e000 0x1a3000 0x1d29dc 0.0 foundation - 4 1 4 8 Pending 0x362000 0xbb000 0x5cc19 0.0 bundle_daemon - 5 1 5 1 Pending 0xdfa000 0x2e7000 0x148a0a 0.0 appspawn - 6 1 6 0 Pending 0x688000 0x137000 0x11c1ba 0.0 media_server - 7 1 7 0 Pending 0x9d2000 0x103000 0xa21f9 0.89 wms_server - 8 1 8 2 Pending 0x1f5000 0x48000 0x482dc 0.2 mksh - 10 5 5 101 Pending 0x11ec000 0x2f9000 0x206561 0.93 com.huawei.launcher - 12 1 12 0 Pending 0x4d4000 0x112000 0xe0d9c 0.0 deviceauth_service - 13 1 13 0 Pending 0x34f000 0xbd000 0x51cb3 0.0 sensor_service - 14 1 14 2 Pending 0x34e000 0xb3000 0x5269e 0.0 ai_server - 15 1 15 0 Pending 0x61f000 0x13b000 0x16858b 0.51 softbus_server - 45 8 45 2 Running 0x1d7000 0x3a000 0x1e9f5 0.0 toybox -``` - -- 发送不存在的信号值 kill -100 31 - -## 输出说明 - -发送成功或失败输出结果如下。 - -**示例 1** 发送信号给指定进程 - -```shell -OHOS:/$ kill -s 9 42 -OHOS:/$ -[1] + Killed ./nfs/test_demo -``` - -信号发送成功会显示的提示进程已被杀死。 - -**示例 2** 信号发送失败 - -```shell -OHOS:/$ kill -100 31 -kill: Unknown signal '(null)' -``` - -信号发送失败,示例2所示原因为信号发送命令参数无效,请排查信号编号及进程编号是否有效。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/09.log.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/09.log.md" deleted file mode 100644 index 90410079d9dc96ae2380da2e24d95a9db382f298..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/09.log.md" +++ /dev/null @@ -1,92 +0,0 @@ ---- -title: log -permalink: /pages/010501020501040109 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# log - -- [命令功能](#section128219131856) -- [命令格式](#section3894181710519) -- [参数说明](#section7693122310515) -- [使用指南](#section1982111281512) -- [使用实例](#section176301333259) -- [输出说明](#section14354765415) - -## 命令功能 - -log命令用于修改&查询日志配置。 - -## 命令格式 - -log level \[_levelNum_\] - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

levelNum

-

配置日志打印等级。

-

[0,5]

-
- -## 使用指南 - -- 该命令依赖于LOSCFG\_SHELL\_LK,使用时通过menuconfig在配置项中开启"Enable Shell lk": - - Debug ---\> Enable a Debug Version ---\> Enable Shell ---\> Enable Shell lK。 - -- log level命令用于配置日志的打印等级,包括6个等级 - - TRACE\_EMG = 0, - - TRACE\_COMMON = 1, - - TRACE\_ERROR = 2, - - TRACE\_WARN = 3, - - TRACE\_INFO = 4, - - TRACE\_DEBUG = 5 - - 若level不在有效范围内,会打印提示信息。 - -- 若log level命令不加\[levelNum\]参数,则默认查看当前打印等级,并且提示使用方法。 - -- 开源小型系统源码设置level 为4或者5会有超多打印。 - -## 使用实例 - -举例:输入log level 3 - -## 输出说明 - -**示例** 设置当前日志打印级别为3 - -```shell -OHOS # log level 3 -Set current log level WARN -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/10.memcheck.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/10.memcheck.md" deleted file mode 100644 index a431bf02b5135149a5f7269193f38b67a5ed2340..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/10.memcheck.md" +++ /dev/null @@ -1,81 +0,0 @@ ---- -title: memcheck -permalink: /pages/01050102050104010a -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:22 ---- -# memcheck - -- [命令功能](#section191633812516) -- [命令格式](#section428816435510) -- [参数说明](#section1939943304411) -- [使用指南](#section228914491951) -- [使用实例](#section17373205314515) -- [输出说明](#section13406205385413) - -## 命令功能 - -检查动态申请的内存块是否完整,是否存在内存越界造成节点损坏。 - -## 命令格式 - -memcheck - -## 参数说明 - -无。 - -## 使用指南 - -- 当内存池所有节点完整时,输出"system memcheck over, all passed!"。 -- 当内存池存在节点不完整时,输出被损坏节点的内存块信息。 - -## 使用实例 - -举例: - -- 输入memcheck -- 输入memcheck出现内存越界 - -## 输出说明 - -**示例 1** 当前没有内存越界 - -```shell -OHOS # memcheck -system memcheck over, all passed! -``` - -**示例 2** 出现内存越界 - -```shell -[L0S DLnkCheckMenl 349, memory check -stFreeNodeInfo.pstPrev:0x7e0d31f3 is out of legal mem range[0x80ba5f40, 0х83d00000] -cur node: 0x81f2ce0c -pre node: 0x81f28a98 -pre node was allocated by task:sofia -uwEхcTуpe = 0х2 -puмExcBuffAddr pc = 0x803ad7a4 -puwExcBuffAddr lr = 0x803ad7a4 -puwExcBuffAddr sp = 0х80cb7de0 -puwExcBuffAddr fp = 0x80cb7dec -*******backtrace begin******* -traceback 0 -- lr = 0х8037cb84 -traceback 0 -- fp = 0х80cb7e1c -traceback 1 -- lr = 0х8037033c -traceback 1 -- fp = 0х80cb7e24 -traceback 2 -- lr = 0x8000d108 -traceback 2 -- fp = 0х80cb7e94 -traceback 3 -- lr = 0х8037c7ac -traceback 3 -- fp = 0х80cb7ea4 -traceback 4 -- lr = 0x803ad9e8 -traceback 4 -- fp = 9x11111111 -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/11.oom.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/11.oom.md" deleted file mode 100644 index b68db94e87125eedbe1e749f4ad7d5e8c3367bbf..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/11.oom.md" +++ /dev/null @@ -1,195 +0,0 @@ ---- -title: oom -permalink: /pages/01050102050104010b -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# oom - -- [命令功能](#section366714216619) -- [命令格式](#section8833164614615) -- [参数说明](#section12809111019453) -- [使用指南](#section15935131220717) -- [输出说明](#section12742311179) - -## 命令功能 - -查看和设置低内存阈值以及pagecache内存回收阈值。 - -## 命令格式 - -- oom - -- oom -i \[_interval_\] - -- oom -m \[_mem byte_\] - -- oom -r \[_mem byte_\] - -- oom -h | --help - - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

-i [interval]

-

设置oom线程任务检查的时间间隔。

-

100ms ~ 10000ms

-

-m [mem byte]

-

设置低内存阈值。

-

0MB ~ 1MB,0MB表示不做低内存阈值检查。

-

-r [mem byte]

-

设置pagecache内存回收阈值。

-

低内存阈值 ~ 系统可用最大内存。

-

-h | --help

-

使用帮助。

-

N/A

-
- -## 使用指南 - -- 参数缺省时,显示oom功能当前配置信息。 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >当系统内存不足时,会打印出内存不足的提示信息。 - -- oom -i 100 - -## 输出说明 - -**示例 1** oom缺省打印配置信息 - -```shell -OHOS:/$ oom -[oom] oom loop task status: enabled - oom low memory threshold: 0x80000(byte) - oom reclaim memory threshold: 0x500000(byte) - oom check interval: 100(microsecond) -``` - -系统内存不足时打印提示信息 - -```shell -T:20 Enter:IT MEM 00M 001 -[oom] OS is in low memory state -total physical memory: 0x1bcf000(byte), used: 0x1b50000(byte) ,free: 0x7f000(byte), low memory threshold: 0x80000(byte) -[oom] candidate victim process init pid: 1, actual phy mem byte:82602 -[oom] candidate victim process shell pid: 3, actual phy mem byte:14950e -[oom] candidate victim process testsuits app pid: 4, actual phy mem byte:1334598 -[oom] candidate victim process UserProcess12 pid: 12, actual phy mem byte:25951558 -[oom] max phy mem used process UserProcess12 pid: 12, actual phy mem 25951558 -################excFrom: User!#################### -data abort fsr:0x817, far:0x225af000 -Abort caused by a write instruction. Translation fault, page -excType: data abort -processName = UserProcess12 -processID = 12 -process aspace = 0х01000000 -> 0х3f000000 -taskName = threado -taskID = 22 -task user stack = 0х20e17000 -> 0х20e21000 -pc = 0x93969dc in /usr/bin/testsuits app ---> 0x19f9dc -ulr = 0x93969cc in /usr/bin/testsuits app ---> 0x19f9cc -usp = 0х20e20c68fp = 0x20e20c8c -R0 = 0х20e35000 -R1 = 0x225af000 -R2 = 0x0 -R3 = 0х28e35000 -R4 = 0х0 -R5 = 0х9500000 -R6 = 0х14 -R7 = 0х97822c4 -R8 = 0x970cfa8 -R9 = 0x9090909 -R10 = 0xa0a0a0a -R11 = 0x20e20c8c -R12 = 0х0 -CPSR = 0х80000010 -*******backtrace beain******* -traceback 0 -- lr = 0x9242e1c fp = 0х20e20cc4 lr in /usr/bin/testsuits apr 0x4be1c -traceback 1 -- 1r = 0х92430cc fp = 0x20e20cdc lr in /usr/bin/testsuits app --> 0x4c0cc -traceback 2 -- 1r = 0x9396ab0 fp = 0x20e20cec lr in /usr/bin/testsuits app -> 0х19fab0 -traceback 3 -- lr = 0x9393eb4 fp = 0x20e20cf4 lr in /usr/bin/testsuits ap --> 0x19ceb4 -traceback 4 -- lr = 0x92427d4 fp = 0x20e20d44 lr in /usr/bin/testsuits app --> 0x4b7d4 -traceback 5 -- 1r = 0x20c4df50 fp = 0хb0b0b0b 1r in /1ib/libc.so - -> 0x62f50 -``` - -**示例 2** 设置 oom 线程任务检查的时间间隔 - -```shell -OHOS:/$ oom -i 100 -[oom] set oom check interval (100)ms successful -``` - -**表 2** 输出说明 - - - - - - - - - - - - - - - - - - - - - - -

输出

-

说明

-

[oom] OS is in low memory state

-

total physical memory: 0x1bcf000(byte), used: 0x1b50000(byte), free: 0x7f000(byte), low memory threshold: 0x80000(byte)

-

操作系统处于低内存状态。

-

整个系统可用物理内存为0x1bcf000 byte,已经使用了 0x1b50000 byte, 还剩0x7f000 byte,当前设置的低内存阈值为0x80000 byte。

-

[oom] candidate victim process init pid: 1, actual phy mem byte: 82602

-

打印当前各个进程的内存使用情况,init进程实际使用82602byte,其中共享内存按照比例算的。

-

[oom] candidate victim process UserProcess12 pid: 12, actual phy mem byte: 25951558

-

UserProcess12进程实际使用25951558byte内存。

-

[oom] max phy mem used process UserProcess12 pid: 12, actual phy mem: 25951558

-

当前使用内存最多的进程是UserProcess12。

-

excFrom: User!

-

当系统处于低内存的情况下,UserProcess12进程再去申请内存时失败退出。

-
diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/12.pmm.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/12.pmm.md" deleted file mode 100644 index 6ed67cbfb22c6878ba0e97f4f703ff7c0b96bf02..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/12.pmm.md" +++ /dev/null @@ -1,129 +0,0 @@ ---- -title: pmm -permalink: /pages/01050102050104010c -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# pmm - -- [命令功能](#section445335110416) -- [命令格式](#section1795712553416) -- [参数说明](#section92544592410) -- [使用指南](#section104151141252) -- [使用实例](#section11545171957) -- [输出说明](#section075617368542) - -## 命令功能 - -查看系统内存物理页及pagecache物理页使用情况。 - -## 命令格式 - -pmm - -## 参数说明 - -无 - -## 使用指南 - -Debug版本才具备的命令。 - -## 使用实例 - -举例:输入pmm - -## 输出说明 - -**示例** 查看物理页使用情况 - -```shell -OHOS # pmm - - phys_seg base size free_pages - -------- ------- ---------- --------- - 0x4065552c 0x809b0000 0x07550000 22344 -order = 0, free_count = 16 -order = 1, free_count = 12 -order = 2, free_count = 8 -order = 3, free_count = 6 -order = 4, free_count = 13 -order = 5, free_count = 16 -order = 6, free_count = 12 -order = 7, free_count = 4 -order = 8, free_count = 79 -active anon 0 -inactive anon 0 -active file 1385 -inactice file 84 - -pmm pages: total = 30032, used = 7688, free = 22344 -pathCache number = 325 -pathCache memory size = 17621(B) -Vnode number = 67 -Vnode memory size = 10720(B) -``` - -**表 1** 输出说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

输出

-

说明

-

phys_seg

-

物理页控制块地址信息

-

base

-

第一个物理页地址,即物理页内存起始地址

-

size

-

物理页内存大小

-

free_pages

-

空闲物理页数量

-

active anon

-

pagecache中,活跃的匿名页数量

-

inactive anon

-

pagecache中,不活跃的匿名页数量

-

active file

-

pagecache中,活跃的文件页数量

-

inactive file

-

pagecache中,不活跃的文件页数量

-

pmm pages

-

total:总的物理页数,used:已使用的物理页数,free:空闲的物理页数

-
diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/13.reset.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/13.reset.md" deleted file mode 100644 index 0da03a510327916f443fa74a1d598b8c25d031fb..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/13.reset.md" +++ /dev/null @@ -1,46 +0,0 @@ ---- -title: reset -permalink: /pages/01050102050104010d -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# reset - -- [命令功能](#section366714216619) -- [命令格式](#section8833164614615) -- [参数说明](#section12809111019453) -- [使用指南](#section15935131220717) -- [使用实例](#section79281818476) -- [输出说明](#section12742311179) - -## 命令功能 - -reset命令用于重启设备。 - -## 命令格式 - -reset - -## 参数说明 - -无。 - -## 使用指南 - -reset命令输入后,设备会立刻重启。 - -## 使用实例 - -reset - -## 输出说明 - -无。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/14.sem.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/14.sem.md" deleted file mode 100644 index 5628a92d70acc4382823e94a9632da225df230d3..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/14.sem.md" +++ /dev/null @@ -1,136 +0,0 @@ ---- -title: sem -permalink: /pages/01050102050104010e -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# sem - -- [命令功能](#section366714216619) -- [命令格式](#section8833164614615) -- [参数说明](#section12809111019453) -- [使用指南](#section15935131220717) -- [使用实例](#section79281818476) -- [输出说明](#section1975118519456) - -## 命令功能 - -sem命令用于查询系统内核信号量相关信息。 - -## 命令格式 - -sem \[_ID__ / fulldata_\] - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

ID

-

信号ID号。

-

[0, 0xFFFFFFFF]

-

fulldata

-

查询所有在用的信号量信息,打印信息包括如下:SemID, Count, Original Count, Creater TaskEntry, Last Access Time。

-

N/A

-
- -## 使用指南 - -- 参数缺省时,显示所有的信号量的使用数及信号量总数。 -- sem后加ID,显示对应ID信号量的使用数。 -- 参数fulldata依赖于LOSCFG\_DEBUG\_SEMAPHORE,使用时通过menuconfig在配置项中开启"Enable Semaphore Debugging": - - Debug ---\> Enable a Debug Version ---\> Enable Debug LiteOS Kernel Resource ---\> Enable Semaphore Debugging - - -## 使用实例 - -举例:输入 sem fulldata - -## 输出说明 - -**示例** 查询所有在用的信号量信息 - -```shell -OHOS # sem - - SemID Count - ---------- ----- - 0x00000000 1 - - SemID Count - ---------- ----- - 0x00000001 0 - - SemID Count - ---------- ----- - 0x00000002 0 - - SemID Count - ---------- ----- - 0x00000003 1 - - SemID Count - ---------- ----- - 0x00000004 0 - - SemID Count - ---------- ----- - 0x00000005 1 - - SemID Count - ---------- ----- - 0x00000006 0 -``` - -**表 2** 输出说明 - - - - - - - - - - - - - - -

输出

-

说明

-

SemID

-

信号量ID。

-

Count

-

信号量使用数。

-
- ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->● sem命令的ID参数输入形式以十进制形式表示或十六进制形式表示皆可。 ->● sem命令的ID参数在\[0, 1023\]范围内时,返回对应ID的信号量的状态(如果对应ID的信号量未被使用则进行提示);其他取值时返回参数错误的提示。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/15.stack.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/15.stack.md" deleted file mode 100644 index 9eecbd63552d86c81f9daa1caf15bae6c4871a0f..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/15.stack.md" +++ /dev/null @@ -1,93 +0,0 @@ ---- -title: stack -permalink: /pages/01050102050104010f -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# stack - -- [命令功能](#section445335110416) -- [命令格式](#section1795712553416) -- [参数说明](#section92544592410) -- [使用指南](#section104151141252) -- [使用实例](#section11545171957) -- [输出说明](#section075617368542) - -## 命令功能 - -查看系统各堆栈使用情况。 - -## 命令格式 - -stack - -## 参数说明 - -无。 - -## 使用指南 - -无。 - -## 使用实例 - -举例:输入stack - -## 输出说明 - -**示例** 系统堆栈使用情况 - -```shell -OHOS # stack - - stack name cpu id stack addr total size used size - ---------- ------ --------- -------- -------- - svc_stack 1 0x405c4000 0x2000 0x484 - svc_stack 0 0x405c6000 0x2000 0xae4 - exc_stack 1 0x405c8000 0x1000 0x0 - exc_stack 0 0x405c9000 0x1000 0x0 -``` - -**表 1** 输出说明 - - - - - - - - - - - - - - - - - - - - - - -

输出

-

说明

-

stack name

-

系统堆栈名

-

cpu id

-

cpu 号

-

stack addr

-

栈地址

-

total size

-

堆栈大小

-

used size

-

堆栈实际使用大小

-
diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/16.su.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/16.su.md" deleted file mode 100644 index f4e8d66a1ea92947564170c9e0869248380c94ed..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/16.su.md" +++ /dev/null @@ -1,86 +0,0 @@ ---- -title: su -permalink: /pages/010501020501040110 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# su - -- [命令功能](#section297810431676) -- [命令格式](#section157131147876) -- [参数说明](#section04145521671) -- [使用指南](#section14615155610719) -- [使用实例](#section13338150985) -- [输出说明](#section125021924194613) - -## 命令功能 - -su用于变更为其他使用者的身份。 - -## 命令格式 - -su \[_uid_\] \[_gid_\] - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

uid

-

目标用户的用户id值。

-
[0,60000]

-

gid

-

目标用户的群组id值。

-
[0,60000]

-
- -## 使用指南 - -- su命令缺省切换到root用户,uid默认为0,gid为0。 -- 在su命令后的输入参数uid和gid就可以切换到该uid和gid的用户。 -- 输入参数超出范围时,会打印提醒输入正确范围参数。 - -## 使用实例 - -举例:su 1000 1000 - -## 输出说明 - -**示例** 从当前用户切换至uid为1000,gid为1000的用户 - -```shell -OHOS # ls -Directory /data/system/param: --rw-r--r-- 0 u:0 g:0 hello_1.txt -OHOS # su 1000 1000 -OHOS # touch hello 2.txt -OHOS # ls -Directory /data/system/param: --rw-r--r-- O u:1000 g:1000 hello 2.txt --гw-r--r-- 0 u:0 g:0 hello_1.txt -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/17.swtmr.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/17.swtmr.md" deleted file mode 100644 index 9504e6b6700cbf4a00bd030b13b8b0e2d1e9fe12..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/17.swtmr.md" +++ /dev/null @@ -1,156 +0,0 @@ ---- -title: swtmr -permalink: /pages/010501020501040111 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# swtmr - -- [命令功能](#section166171064814) -- [命令格式](#section424011111682) -- [参数说明](#section1268410459465) -- [使用指南](#section169806213815) -- [使用实例](#section16676026389) -- [输出说明](#section1541991614710) - -## 命令功能 - -swtmr命令用于查询系统软件定时器相关信息。 - -## 命令格式 - -swtmr \[_ID_\] - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

ID

-

软件定时器ID号。

-

[0,0xFFFFFFFF]

-
- -## 使用指南 - -- 参数缺省时,默认显示所有软件定时器的相关信息。 -- swtmr后加ID号时,显示ID对应的软件定时器相关信息。 - -## 使用实例 - -举例: - -- swtmr -- swtmr 1 - -## 输出说明 - -**示例 1** 查询所有软件定时器相关信息 - -```shell -OHOS # swtmr - -SwTmrID State Mode Interval Count Arg handlerAddr ----------- ------- ------- --------- ------- ---------- -------- -0x00000000 Ticking Period 100 77 0x40802a50 0x4037b8a0 - -SwTmrID State Mode Interval Count Arg handlerAddr ----------- ------- ------- --------- ------- ---------- -------- -0x00000001 Ticking Period 1000 876 0x00000000 0x4037fc04 - -SwTmrID State Mode Interval Count Arg handlerAddr ----------- ------- ------- --------- ------- ---------- -------- -0x00000002 Ticking Period 100 76 0x00000000 0x403727f4 - -SwTmrID State Mode Interval Count Arg handlerAddr ----------- ------- ------- --------- ------- ---------- -------- -0x00000016 Ticking NSD 10 6 0x8021e000 0x401fe7d8 - -SwTmrID State Mode Interval Count Arg handlerAddr ----------- ------- ------- --------- ------- ---------- -------- -0x00000079 Ticking NSD 30000 1749 0x406189d8 0x40160e1c -``` - -**示例 2** 查询对应 ID 的软件定时器信息 - -```shell -OHOS # swtmr 1 - -SwTmrID State Mode Interval Count Arg handlerAddr ----------- ------- ------- --------- ------- ---------- -------- -0x00000001 Ticking Period 1000 841 0x00000000 0x4037fc04 -``` - -**表 2** 输出说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

输出

-

说明

-

SwTmrID

-

软件定时器ID。

-

State

-

软件定时器状态。

-

状态可能为:"UnUsed", "Created", "Ticking"。

-

Mode

-

软件定时器模式。

-

模式可能为:"Once", "Period", "NSD(单次定时器,定时结束后不会自动删除)"。

-

Interval

-

软件定时器使用的Tick数。

-

Count

-

软件定时器已经工作的次数。

-

Arg

-

传入的参数。

-

handlerAddr

-

回调函数的地址。

-
- ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->- swtmr命令的ID参数输入形式以十进制形式表示或十六进制形式表示皆可。 ->- swtmr命令的ID参数在\[0, 当前软件定时器个数 - 1\]范围内时,返回对应ID的软件定时器的状态;其他取值时返回错误提示。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/18.systeminfo.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/18.systeminfo.md" deleted file mode 100644 index 95a4e131f34072ad9eec4b7b983e386cb8b40f8a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/18.systeminfo.md" +++ /dev/null @@ -1,113 +0,0 @@ ---- -title: systeminfo -permalink: /pages/010501020501040112 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# systeminfo - -- [命令功能](#section863016434820) -- [命令格式](#section139791817795) -- [参数说明](#section19472339164813) -- [使用指南](#section285522592) -- [使用实例](#section9471171015105) -- [输出说明](#section1657011114915) - -## 命令功能 - -systeminfo命令用于显示当前操作系统内资源使用情况,包括任务、信号量、互斥量、队列、定时器等。 - -## 命令格式 - -systeminfo - -## 参数说明 - -无。 - -## 使用指南 - -无。 - -## 使用实例 - -举例:输入systeminfo - -## 输出说明 - -**示例** 查看系统资源使用情况 - -```shell -OHOS:/$ systeminfo - - Module Used Total Enabled --------------------------------------------- - Task 96 256 YES - Sem 435 1024 YES - Queue 13 1024 YES - SwTmr 20 1024 YES -``` - -**表 1** 输出说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

输出

-

说明

-

Module

-

模块名称。

-

Used

-

当前使用量。

-

Total

-

最大可用量。

-

Enabled

-

模块是否开启。

-

Task

-

任务。

-

Sem

-

信号量。

-

Mutex

-

互斥量。

-

Queue

-

队列。

-

SwTmr

-

定时器。

-
diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/19.task.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/19.task.md" deleted file mode 100644 index 64bdce829d5b0d7b18c7eb740beabf04af8501ae..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/19.task.md" +++ /dev/null @@ -1,165 +0,0 @@ ---- -title: task -permalink: /pages/010501020501040113 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# task - -- [命令功能](#section0533181714106) -- [命令格式](#section1014412308101) -- [参数说明](#section116057158506) -- [使用指南](#section2053502951112) -- [使用实例](#section12629113381116) -- [输出说明](#section19299103465015) - -## 命令功能 - -task命令用于查询进程及线程信息。 - -## 命令格式 - -task/task -a - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

-a

-

查看更多信息。

-

N/A

-
- -## 使用指南 - -参数缺省时默认打印部分任务信息。 - -## 使用实例 - -举例:输入task - -## 输出说明 - -**示例** 查询任务部分信息 - -```shell -OHOS # task - - allCpu(%): 3.54 sys, 196.46 idle - - PID PPID PGID UID Status VirtualMem ShareMem PhysicalMem CPUUSE10s PName - 1 -1 1 0 Pending 0x33b000 0xbb000 0x4dc8b 0.0 init - 2 -1 2 0 Pending 0x193318e 0 0x193318e 1.11 KProcess - 3 1 3 7 Pending 0x730000 0x1a2000 0x1d34f6 0.0 foundation - 4 1 4 8 Pending 0x35e000 0xb8000 0x56777 0.0 bundle_daemon - 5 1 5 1 Pending 0xdfa000 0x2e7000 0x1487ce 0.0 appspawn - 6 1 6 0 Pending 0x688000 0x137000 0x11c518 0.0 media_server - 7 1 7 0 Pending 0x9d2000 0x103000 0xa1ddf 0.89 wms_server - 8 1 1 1000 Running 0x2bf000 0x8f000 0x2a8c6 0.0 shell - 9 5 5 101 Pending 0x11ea000 0x2f9000 0x20429d 0.97 com.huawei.launcher - 11 1 11 0 Pending 0x4d4000 0x112000 0xe0ad7 0.0 deviceauth_service - 12 1 12 0 Pending 0x34f000 0xbd000 0x519ee 0.0 sensor_service - 13 1 13 2 Pending 0x34e000 0xb3000 0x523d9 0.0 ai_server - 14 1 14 0 Pending 0x61f000 0x13b000 0x16841c 0.50 softbus_server - - TID PID Affi CPU Status StackSize WaterLine CPUUSE10s MEMUSE TaskName - 23 1 0x3 -1 Pending 0x3000 0xe44 0.0 0 init - 1 2 0x1 -1 Pending 0x4000 0x2c4 0.37 0 Swt_Task - 2 2 0x3 -1 Pending 0x4000 0x204 0.0 0 system_wq - 3 2 0x2 -1 Pending 0x4000 0x514 0.65 0 Swt_Task - 4 2 0x3 -1 Pending 0x1000 0x36c 0.0 0 ResourcesTask - 7 2 0x3 -1 Pending 0x4e20 0xa5c 0.0 0 PlatformWorkerThread -``` - -**表 2** 输出说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

输出

-

说明

-

PID

-

进程ID。

-

PPID

-

父进程ID。

-

PGID

-

进程组ID。

-

UID

-

用户ID。

-

Status

-

任务当前的状态。

-

CPUUSE10s

-

10秒内CPU使用率。

-

PName

-

进程名。

-

TID

-

任务ID。

-

StackSize

-

任务堆栈的大小。

-

WaterLine

-

栈使用的峰值。

-

MEMUSE

-

内存使用量。

-

TaskName

-

任务名。

-
diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/20.uname.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/20.uname.md" deleted file mode 100644 index 667fa65e6ffa66354ac2308ac12d8971067eeca0..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/20.uname.md" +++ /dev/null @@ -1,112 +0,0 @@ ---- -title: uname -permalink: /pages/010501020501040114 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# uname - -- [命令功能](#section01) -- [命令格式](#section02) -- [使用指南](#section03) -- [使用实例](#section04) -- [输出说明](#section05) - -## 命令功能 - -uname命令用于显示当前操作系统的名称,版本创建时间,系统名称,版本信息等。 - -## 命令格式 - -uname \[_-a | -s | -r | -m | -n | -v | --help_\] - -**表 1** 参数说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

--help

-

显示uname指令格式提示。

-

无参数

-

默认显示操作系统名称。

-

-a

-

显示全部信息。

-

-s

-

显示操作系统名称。

-

-r

-

显示内核发行版本。

-

-m

-

显示系统架构名称。

-

-n

-

显示主机的网络域名称。

-

-v

-

显示版本信息。

-
- -## 使用指南 - -- uname用于显示当前操作系统名称。 - -- 除参数--help和-a以外,其他参数可以相互搭配使用;uname -a 等价于 uname -srmnv。 - - -## 使用实例 - -举例: - -- uname -a -- uname -ms - -## 输出说明 - -**示例 1** 查看系统详细信息 - -```shell -OHOS:/$ uname -a -Huawei LiteOS hisilicon 2.0.0.37 Huawei LiteOS 2.0.0.37 Oct 21 2021 17:39:32 Cortex-A7 -OHOS:/$ -``` - -**示例 2** 只查看操作系统名称和系统架构名称 - -```shell -OHOS:/$ uname -ms -Huawei LiteOS Cortex-A7 -OHOS:/$ -``` diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/21.vmm.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/21.vmm.md" deleted file mode 100644 index 12dbe1b96670e5191d35f24e0852e8cbfac66f70..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/21.vmm.md" +++ /dev/null @@ -1,196 +0,0 @@ ---- -title: vmm -permalink: /pages/010501020501040115 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# vmm - -- [命令功能](#section445335110416) -- [命令格式](#section1795712553416) -- [参数说明](#section92544592410) -- [使用指南](#section104151141252) -- [使用实例](#section11545171957) -- [输出说明](#section075617368542) - -## 命令功能 - -查看进程的虚拟内存使用情况。 - -## 命令格式 - -- vmm \[_-a / -h / --help_\] - -- vmm \[_pid_\] - - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

-a

-

输出所有进程的虚拟内存使用情况。

-

N/A

-

-h | --help

-

命令格式说明。

-

N/A

-

pid

-

进程ID,说明指定进程的虚拟内存使用情况。

-

[0,63]

-
- -## 使用指南 - -命令缺省输出所有进程的虚拟内存使用情况。 - -## 使用实例 - -举例:输入vmm 3 - -## 输出说明 - -**示例** PID为3的进程虚拟内存使用信息 - -```shell -OHOS # vmm 3 - - PID aspace name base size pages - ---- ------ ---- ---- ----- ---- - 3 0x408c0118 foundation 0x01000000 0x3e000000 800 - - region name base size mmu_flags pages pg/ref - ------ ---- ---- ---- --------- ----- ----- - 0x408cb364 /bin/foundation 0x06da3000 0x00001000 CH US RD 1 1 - 0x408cb80c /bin/foundation 0x06da4000 0x00001000 CH US RD EX 1 1 - 0x408cb720 /bin/foundation 0x06da5000 0x00001000 CH US RD 1 1 - 0x408cb9a8 /bin/foundation 0x06da6000 0x00001000 CH US RD WR 1 1 - 0x413efde4 HEAP 0x12b43000 0x00015000 CH US RD WR 19 19 - 0x408c3d34 /lib/libc.so 0x23b08000 0x0004a000 CH US RD 25 2 - 0x408cbd44 /lib/libc.so 0x23b52000 0x00068000 CH US RD EX 58 10 - 0x408c3dc0 /lib/libc.so 0x23bba000 0x00002000 CH US RD WR 2 2 - 0x408cc128 /lib/libc.so 0x23bbc000 0x00002000 CH US RD WR 2 2 - 0x408d1634 MMAP 0x23bbe000 0x00005000 CH US RD WR 5 5 - 0x408c4e10 VDSO 0x23bc3000 0x00002000 CH US RD EX 2 2 - 0x408dbaec /lib/libc++.so 0x23bc5000 0x00046000 CH US RD 51 5 - 0x408deba8 /lib/libc++.so 0x23c0b000 0x0009f000 CH US RD EX 29 10 - 0x408debf4 /lib/libc++.so 0x23caa000 0x00006000 CH US RD 6 6 - 0x408c3ce0 /lib/libc++.so 0x23cb0000 0x00001000 CH US RD WR 1 1 -``` - -**表 2** 进程基本信息 - - - - - - - - - - - - - - - - - - - - - - - - - -

输出

-

说明

-

PID

-

进程ID

-

aspace

-

进程虚拟内存控制块地址信息

-

name

-

进程名

-

base

-

虚拟内存起始地址

-

size

-

虚拟内存大小

-

pages

-

已使用的物理页数量

-
- -**表 3** 虚拟内存区间信息 - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

输出

-

说明

-

region

-

虚拟区间控制块地址信息

-

name

-

虚拟区间类型

-

base

-

虚拟区间起始地址

-

size

-

虚拟区间大小

-

mmu_flags

-

虚拟区间mmu映射属性

-

pages

-

已使用的物理页数量(包括共享内存部分)

-

pg/ref

-

已使用的物理页数量

-
diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/22.watch.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/22.watch.md" deleted file mode 100644 index 4794d51569b5a0d4b08d259a13e8300e3924cc21..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/22.watch.md" +++ /dev/null @@ -1,153 +0,0 @@ ---- -title: watch -permalink: /pages/010501020501040116 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# watch - -- [命令功能](#section20643141481314) -- [命令格式](#section1075441721316) -- [参数说明](#section1472810220135) -- [使用指南](#section186772414131) -- [使用实例](#section4764192791314) -- [输出说明](#section5791253155517) - -## 命令功能 - -watch命令用于周期性的监视一个命令的运行结果。 - -## 命令格式 - -- watch - -- watch \[_-c/-n/-t/--count/--interval/-no-title/--over_\] \[_command_\] - - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

缺省值

-

取值范围

-

-c / --count

-

命令执行的总次数。

-

0xFFFFFF

-

(0,0xFFFFFF]

-

-n / --interval

-

命令周期性执行的时间间隔(s)。

-

1s

-

(0,0xFFFFFF]

-

-t / -no-title

-

关闭顶端的时间显示。

-

N/A

-

N/A

-

command

-

需要监测的命令。

-

N/A

-

N/A

-

--over

-

关闭当前监测指令。

-

N/A

-

N/A

-
- -## 使用指南 - -watch运行过程中可以执行**watch --over**结束本次watch命令。 - -## 使用实例 - -举例:watch -n 2 -c 6 task - -## 输出说明 - -**示例** watch task 结果 - -```shell -OHOS # watch -n 2 -c 6 task -Thu Jan 1 23:57:13 1970 - -OHOS # - allCpu(%): 3.55 sys, 196.45 idle - - PID PPID PGID UID Status VirtualMem ShareMem PhysicalMem CPUUSE10s PName - 1 -1 1 0 Pending 0x33b000 0xbb000 0x4dc8b 0.0 init - 2 -1 2 0 Running 0x19524f2 0 0x19524f2 1.14 KProcess - 3 1 3 7 Pending 0x730000 0x1a2000 0x1d34f6 0.0 foundation - 4 1 4 8 Pending 0x35e000 0xb8000 0x56777 0.0 bundle_daemon - 5 1 5 1 Pending 0xdfa000 0x2e7000 0x1487ce 0.0 appspawn - 6 1 6 0 Pending 0x688000 0x137000 0x11c518 0.0 media_server - 7 1 7 0 Pending 0x9d2000 0x103000 0xa1ddf 0.95 wms_server - 8 1 1 1000 Running 0x2bf000 0x8f000 0x2a8c6 0.0 shell - 9 5 5 101 Pending 0x11ea000 0x2f9000 0x20429d 1.2 com.huawei.launcher - 11 1 11 0 Pending 0x4d4000 0x112000 0xe0ad7 0.0 deviceauth_service - 12 1 12 0 Pending 0x34f000 0xbd000 0x519ee 0.0 sensor_service - 13 1 13 2 Pending 0x34e000 0xb3000 0x523d9 0.0 ai_server - 14 1 14 0 Pending 0x61f000 0x13b000 0x16841c 0.51 softbus_server - - TID PID Affi CPU Status StackSize WaterLine CPUUSE10s MEMUSE TaskName - 23 1 0x3 -1 Pending 0x3000 0xe44 0.0 0 init - 1 2 0x1 -1 Pending 0x4000 0x2c4 0.64 0 Swt_Task - 2 2 0x3 -1 Pending 0x4000 0x204 0.0 0 system_wq - 3 2 0x2 -1 Pending 0x4000 0x514 0.40 0 Swt_Task - 4 2 0x3 -1 Pending 0x1000 0x36c 0.0 0 ResourcesTask - 7 2 0x3 -1 Pending 0x4e20 0xa5c 0.0 0 PlatformWorkerThread - 8 2 0x3 -1 Pending 0x4e20 0xa6c 0.0 0 PlatformWorkerThread - 9 2 0x3 -1 Pending 0x4e20 0xa5c 0.0 0 PlatformWorkerThread - 10 2 0x3 -1 PendTime 0x4000 0x3e4 0.5 0 hi_vdec_thread - 11 2 0x3 -1 Pending 0x3000 0x4cc 0.0 0 bcache_async_task - 12 2 0x3 -1 Pending 0x2710 0x224 0.0 0 LiteOS usb pnp notify handle kt - 13 2 0x3 -1 Pending 0x4000 0x204 0.0 0 vibrator_queue - 14 2 0x3 -1 Pending 0x3000 0x37c 0.0 0 bcache_async_task - 15 2 0x3 -1 Pending 0x20000 0x3e4 0.0 0 eth_irq_Task - 16 2 0x3 -1 PendTime 0x2000 0x3a4 0.0 0 MessageDispatcher - 17 2 0x3 0 Running 0x3000 0x73c 0.0 0 shellcmd_watch - 18 2 0x3 -1 Pending 0x2710 0x3ac 0.0 0 GPIO_IRQ_TSK_0_4 -``` - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->示例中,总共有6次task命令打印,每次间隔2秒,示例1为最后一次打印详情。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/23.reboot.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/23.reboot.md" deleted file mode 100644 index 067aa674ec6accf3cad9bd56ea26a3ba205fede7..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/23.reboot.md" +++ /dev/null @@ -1,46 +0,0 @@ ---- -title: reboot -permalink: /pages/010501020501040117 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# reboot - -- [命令功能](#section01) -- [命令格式](#section02) -- [参数说明](#section03) -- [使用指南](#section04) -- [使用实例](#section05) -- [输出说明](#section06) - -## 命令功能 - -reboot命令用于重启设备。 - -## 命令格式 - -reboot - -## 参数说明 - -无。 - -## 使用指南 - -reboot命令输入后,设备会立刻重启。 - -## 使用实例 - -reboot - -## 输出说明 - -无。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/24.top.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/24.top.md" deleted file mode 100644 index 9a62f10ac0bcf2d4ca8ccfb0be4091fcad6a6a66..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/01.\347\263\273\347\273\237\345\221\275\344\273\244/24.top.md" +++ /dev/null @@ -1,189 +0,0 @@ ---- -title: top -permalink: /pages/010501020501040118 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# top - -- [命令功能](#section01) -- [命令格式](#section02) -- [参数说明](#section03) -- [使用指南](#section04) -- [使用实例](#section05) -- [输出说明](#section06) - -## 命令功能 - -top命令用于查询进程及线程信息。 - -## 命令格式 - -top \[_-a_\] - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

--help

-

查看top命令支持的参数列表。

-

N/A

-

-a

-

显示更详细的信息。

-

N/A

-
- -## 使用指南 - -参数缺省时默认打印部分任务信息。 - -## 使用实例 - -举例:输入top - -## 输出说明 - -**示例** top 命令显示详情 - -```shell -OHOS:/$ top - - allCpu(%): 4.68 sys, 195.32 idle - - PID PPID PGID UID Status VirtualMem ShareMem PhysicalMem CPUUSE10s PName - 1 -1 1 0 Pending 0x33b000 0xbb000 0x4e01c 0.0 init - 2 -1 2 0 Pending 0xd838c0 0 0xd838c0 1.16 KProcess - 3 1 3 7 Pending 0x72e000 0x1a3000 0x1d29dc 0.0 foundation - 4 1 4 8 Pending 0x362000 0xbb000 0x5cc19 0.0 bundle_daemon - 5 1 5 1 Pending 0xdfa000 0x2e7000 0x148a0a 0.0 appspawn - 6 1 6 0 Pending 0x688000 0x137000 0x11c1ba 0.0 media_server - 7 1 7 0 Pending 0x9d2000 0x103000 0xa21f9 0.87 wms_server - 8 1 8 2 Pending 0x1f5000 0x48000 0x462dc 0.0 mksh - 9 5 5 101 Pending 0x11ea000 0x2f9000 0x204561 0.94 com.huawei.launcher - 11 1 11 0 Pending 0x4d4000 0x112000 0xe0d9c 0.0 deviceauth_service - 12 1 12 0 Pending 0x34f000 0xbd000 0x51cb3 0.0 sensor_service - 13 1 13 2 Pending 0x34e000 0xb3000 0x5269e 0.0 ai_server - 14 1 14 0 Pending 0x61f000 0x13b000 0x16858b 0.45 softbus_server - 43 8 43 2 Running 0x1d7000 0x3a000 0x1e9f5 0.0 toybox - - TID PID Affi CPU Status StackSize WaterLine CPUUSE10s MEMUSE TaskName - 23 1 0x3 -1 Pending 0x3000 0xcf4 0.0 0 init - 1 2 0x1 -1 Pending 0x4000 0x2c4 0.33 0 Swt_Task - 2 2 0x3 -1 Pending 0x4000 0x204 0.0 0 system_wq - 3 2 0x2 -1 Pending 0x4000 0x514 0.75 0 Swt_Task - 4 2 0x3 -1 Pending 0x1000 0x3ac 0.0 0 ResourcesTask - 7 2 0x3 -1 Pending 0x4e20 0xa5c 0.0 0 PlatformWorkerThread - 8 2 0x3 -1 Pending 0x4e20 0xa6c 0.0 0 PlatformWorkerThread - 9 2 0x3 -1 Pending 0x4e20 0xbf4 0.0 0 PlatformWorkerThread - 10 2 0x3 -1 Pending 0x3000 0x4dc 0.0 0 bcache_async_task - 11 2 0x3 -1 PendTime 0x4000 0x3e4 0.5 0 hi_vdec_thread - 12 2 0x3 -1 Pending 0x2710 0x224 0.0 0 LiteOS usb pnp notify handle kt - 13 2 0x3 -1 Pending 0x3000 0x37c 0.0 0 bcache_async_task - 14 2 0x3 -1 Pending 0x4000 0x204 0.0 0 vibrator_queue - 15 2 0x3 -1 Pending 0x20000 0x35c 0.0 0 eth_irq_Task - 16 2 0x3 -1 PendTime 0x2000 0x354 0.0 0 MessageDispatcher - 18 2 0x3 -1 Pending 0x2710 0x200 0.0 0 GPIO_IRQ_TSK_0_4 - 19 2 0x3 -1 Pending 0x4000 0x204 0.0 0 dispWQ - 20 2 0x3 -1 Pending 0x4000 0x204 0.0 0 hdf_sensor_test_work_queue - 21 2 0x3 -1 PendTime 0x6000 0x40c 0.2 0 tcpip_thread - 22 2 0x3 -1 Pending 0x4000 0x36c 0.0 0 SendToSer - 61 2 0x3 -1 Pending 0x4000 0x244 0.0 0 USB_GIANT_Task - 63 2 0x3 -1 Pending 0x4000 0x244 0.0 0 USB_NGIAN_ISOC_Task - 64 2 0x3 -1 Pending 0x4000 0x244 0.0 0 USB_NGIAN_BULK_TasK -``` - -**表2** 输出元素说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

输出

-

说明

-

PID

-

进程ID。

-

PPID

-

父进程ID。

-

PGID

-

进程组ID。

-

UID

-

用户ID。

-

Status

-

任务当前的状态。

-

CPUUSE10s

-

10秒内CPU使用率。

-

PName

-

进程名。

-

TID

-

任务ID。

-

StackSize

-

任务堆栈的大小。

-

WaterLine

-

栈使用的峰值。

-

MEMUSE

-

内存使用量。

-

TaskName

-

任务名。

-
diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/01.cat.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/01.cat.md" deleted file mode 100644 index 91bd814e828dc3924f02f2b1695f4c623ccd9d76..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/01.cat.md" +++ /dev/null @@ -1,70 +0,0 @@ ---- -title: cat -permalink: /pages/010501020501040201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# cat - -- [命令功能](#section16710153391315) -- [命令格式](#section1699392313158) -- [参数说明](#section1677217374136) -- [使用指南](#section186772414131) -- [使用实例](#section12158131814561) -- [输出说明](#section183926225561) - -## 命令功能 - -cat用于显示文本文件的内容。 - -## 命令格式 - -cat \[_pathname_\] - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

pathname

-

文件路径。

-

已存在的文件。

-
- -## 使用指南 - -cat用于显示文本文件的内容。 - -## 使用实例 - -举例:cat hello-harmony.txt - -## 输出说明 - -**示例** 查看 hello-harmony.txt 文件的信息 - -```shell -OHOS # cat hello-harmony.txt -OHOS # Hello Harmony ;) -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/02.cd.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/02.cd.md" deleted file mode 100644 index b431e236d91dbfbe111731cfd83e16ca3ba8df2d..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/02.cd.md" +++ /dev/null @@ -1,77 +0,0 @@ ---- -title: cd -permalink: /pages/010501020501040202 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# cd - -- [命令功能](#section11690184921316) -- [命令格式](#section75695409569) -- [参数说明](#section71961353181311) -- [使用指南](#section3629759111317) -- [使用实例](#section211620301412) -- [输出说明](#section1968117214577) - -## 命令功能 - -cd命令用来改变当前目录。 - -## 命令格式 - -cd \[_path_\] - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

path

-

文件路径。

-

用户必须具有指定目录中的执行(搜索)许可权。

-
- -## 使用指南 - -- 未指定目录参数时,会跳转至根目录。 -- cd后加路径名时,跳转至该路径。 -- 路径名以 /(斜杠)开头时,表示根目录。 -- .(点)表示当前目录。 -- ..(点点)表示父目录。 -- cd - 可以在最近访问的两个目录切换。 - -## 使用实例 - -举例:cd .. - -## 输出说明 - -**示例** 显示结果如下 - -```shell -OHOS:/nfs$ cd ../ -OHOS:/$ ls -bin etc nfs sdcard system tmp vendor -dev lib proc storage test usr -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/03.chgrp.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/03.chgrp.md" deleted file mode 100644 index 234a9ed939920fd971c1792254b18e1e42d83899..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/03.chgrp.md" +++ /dev/null @@ -1,82 +0,0 @@ ---- -title: chgrp -permalink: /pages/010501020501040203 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# chgrp - -- [命令功能](#section01) -- [命令格式](#section02) -- [参数说明](#section03) -- [使用指南](#section04) -- [使用实例](#section05) -- [输出说明](#section06) - -## 命令功能 - -chgrp用于修改文件的群组。 - -## 命令格式 - -chgrp \[_group_\] \[_pathname_\] - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

group

-

文件群组。

-

[0,0xFFFFFFFF]

-

pathname

-

文件路径。

-

已存在的文件。

-
- -## 使用指南 - -- 在需要修改的文件名前加上文件群组值就可以修改该文件的所属组。 -- fatfs文件系统不支持修改用户组id。 - -## 使用实例 - -举例:chgrp 100 testfile - -## 输出说明 - -**示例** 修改 /dev目录下testfile 文件的群组为100 - -```shell -OHOS:/dev$ ll testfile --rw-r--r-- 0 0 0 0 1970-01-01 00:00 testfile -OHOS:/dev$ chgrp 100 testfile -OHOS:/dev$ ll testfile --rw-r--r-- 0 0 100 0 1970-01-01 00:00 testfile -OHOS:/dev$ -``` diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/04.chmod.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/04.chmod.md" deleted file mode 100644 index f76aa9a298e01d403e2d4b75156df6b1aebe771b..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/04.chmod.md" +++ /dev/null @@ -1,82 +0,0 @@ ---- -title: chmod -permalink: /pages/010501020501040204 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# chmod - -- [命令功能](#section01) -- [命令格式](#section02) -- [参数说明](#section03) -- [使用指南](#section04) -- [使用实例](#section05) -- [输出说明](#section06) - -## 命令功能 - -chmod用于修改文件操作权限。 - -## 命令格式 - -chmod \[_mode_\] \[_filename_\] - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

mode

-

文件或文件夹权限,用8进制表示对应User、Group、及Other(拥有者、群组、其他组)的权限。

-

[0,777]

-

filename

-

文件路径。

-

已存在的文件。

-
- -## 使用指南 - -- 在需要修改的文件名前加上文件权限值就可以修改该文件的权限值。 -- fatfs文件系统所有创建的文件和挂载节点的权限属性保持一致,目前节点的权限只有用户读写权限,group和others权限不生效;且只允许修改用户读写权限,读写权限只有rw和ro两种。其他文件系统无限制。 - -## 使用实例 - -举例:修改hello-harmony.txt 文件权限为644和777。 - -## 输出说明 - -**示例** 修改/dev目录下 hello-harmony.txt 文件的权限 - -```shell -OHOS:/dev$ chmod 644 hello-harmony.txt -OHOS:/dev$ ll hello-harmony.txt --rw-r--r-- 0 0 0 0 1970-01-01 00:00 hello-harmony.txt -OHOS:/dev$ chmod 777 hello-harmony.txt -OHOS:/dev$ ll hello-harmony.txt --rwxrwxrwx 0 0 0 0 1970-01-01 00:00 hello-harmony.txt -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/05.chown.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/05.chown.md" deleted file mode 100644 index bf7944a102f5ae6a4f90e0464ac92dfcd4da1fb9..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/05.chown.md" +++ /dev/null @@ -1,80 +0,0 @@ ---- -title: chown -permalink: /pages/010501020501040205 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# chown - -- [命令功能](#section01) -- [命令格式](#section02) -- [参数说明](#section03) -- [使用指南](#section04) -- [使用实例](#section05) -- [输出说明](#section06) - -## 命令功能 - -chown用于修改指定文件的拥有者。 - -## 命令格式 - -chown \[_owner_\] \[_pathname_\] - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

owner

-

文件拥有者。

-

[0,0xFFFFFFFF]

-

pathname

-

文件路径。

-

已存在的文件。

-
- -## 使用指南 - -修改文件的所有者,目前fatfs不支持修改。 - -## 使用实例 - -举例:chown 100 testfile - -## 输出说明 - -**示例 1** 修改 /dev下的testfile 文件的uid为100 - -```shell -OHOS:/dev$ touch testfile -OHOS:/dev$ ll testfile --rw-r--r-- 0 0 100 0 1970-01-01 00:00 testfile -OHOS:/dev$ chown 100 testfile -OHOS:/dev$ ll testfile --rw-r--r-- 0 100 100 0 1970-01-01 00:00 testfile -``` diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/06.cp.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/06.cp.md" deleted file mode 100644 index 5c5c2edd71bd05287bfe6eccd39014fb2a119806..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/06.cp.md" +++ /dev/null @@ -1,100 +0,0 @@ ---- -title: cp -permalink: /pages/010501020501040206 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# cp - -- [命令功能](#section01) -- [命令格式](#section02) -- [参数说明](#section03) -- [使用指南](#section04) -- [使用实例](#section05) -- [输出说明](#section06) - -## 命令功能 - -拷贝文件,创建一份副本。 - -## 命令格式 - -cp \[_SOURCEFILE_\] \[_DESTFILE_\] - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

--help

-

使用帮助。

-

N/A

-

SOURCEFILE

-

源文件路径。

-

目前只支持文件,不支持目录;支持多文件同时拷贝。

-

DESTFILE

-

目的文件路径。

-

支持目录以及文件。

-
- -## 使用指南 - -- 同一路径下,源文件与目的文件不能重名。 -- 源文件必须存在,且不为目录。 -- 源文件路径支持“\*”和“?”通配符,“\*”代表任意多个字符,“?”代表任意单个字符。目的路径不支持通配符。当源路径可匹配多个文件时,目的路径必须为目录。 -- 目的路径为目录时,该目录必须存在。此时目的文件以源文件命名。 -- 目的路径为文件时,所在目录必须存在。此时拷贝文件的同时为副本重命名。 -- 目的文件不存在时创建新文件,已存在则覆盖。 - -> ![](/images/device-dev/public_sys-resources/icon-notice.gif) **须知:** -> -> 拷贝系统重要资源时,会对系统造成死机等重大未知影响,如用于拷贝/dev/uartdev-1 文件时,会产生系统卡死现象。 - -## 使用实例 - -举例:cp hello-OHOS.txt hello-harmony.txt ./tmp/ - -## 输出说明 - -**示例** 同时拷贝两个文件至指定目录 - -```shell -OHOS:/$ ls -bin hello-OHOS.txt proc system vendor -dev hello-harmony.txt sdcard userdata -etc lib storage usr -OHOS:/$ mkdir tmp -OHOS:/$ cp hello-OHOS.txt hello-harmony.txt tmp/ -OHOS:/$ ll tmp -total 0 --rwxrwxrwx 1 0 0 0 1979-12-31 00:00 hello-OHOS.txt* --rwxrwxrwx 1 0 0 0 1979-12-31 00:00 hello-harmony.txt* -``` diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/07.format.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/07.format.md" deleted file mode 100644 index 92971295be6857e5d6b476ce157c3b80c9d520d0..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/07.format.md" +++ /dev/null @@ -1,85 +0,0 @@ ---- -title: format -permalink: /pages/010501020501040207 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# format - -- [命令功能](#section01) -- [命令格式](#section02) -- [参数说明](#section03) -- [使用指南](#section04) -- [使用实例](#section05) -- [输出说明](#section06) - -## 命令功能 - -format指令用于格式化磁盘。 - -## 命令格式 - -format <_dev\_inodename_\> <_sectors_\> <_option_\> \[_label_\] - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

dev_inodename

-

设备名。

-

sectors

-

分配的单元内存或扇区大小,如果输入0表示参数为空。(取值必须为0或2的幂,fat32下最大值为128,取值0表示自动选择合适的簇大小,不同size的分区,可用的簇大小范围不同,错误的簇大小指定可能导致格式化失败)。

-

option

-
格式化选项,用来选择文件系统的类型,有如下几种参数选择:
  • 0x01:FMT_FAT
  • 0x02:FMT_FAT32
  • 0x07:FMT_ANY
  • 0x08:FMT_ERASE (USB不支持该选项)
-
-

传入其他值皆为非法值,将由系统自动选择格式化方式。若格式化U盘时低格位为 1,会出现错误打印。

-

label

-

该参数为可选参数,输入值应为字符串,用来指定卷标名。当输入字符串"null"时,则把之前设置的卷标名清空。

-
- -## 使用指南 - -- format指令用于格式化磁盘,设备名可以在dev目录下查找。format时必须安装存储卡。 -- format只能格式化U盘、sd和mmc卡,对Nand flash和Nor flash格式化不起作用。 -- sectors参数必须传入合法值,传入非法参数可能引发异常。 - -## 使用实例 - -举例:输入format /dev/mmcblk1 128 2 - -## 输出说明 - -**示例** 格式化mmc卡 - -```shell -OHOS # format /dev/mmcblk1 128 2 -Format to FAT32, 128 sectors per cluster. -format /dev/mmcblk1 Success -``` diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/08.ls.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/08.ls.md" deleted file mode 100644 index 0d583c7e7381310033c020fb1efc51bb8fdaa360..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/08.ls.md" +++ /dev/null @@ -1,334 +0,0 @@ ---- -title: ls -permalink: /pages/010501020501040208 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# ls - -- [命令功能](#section01) -- [命令格式](#section02) -- [参数说明](#section03) -- [使用指南](#section04) -- [使用实例](#section05) -- [输出说明](#section06) - -## 命令功能 - -ls命令用来显示当前目录的内容。 - -## 命令格式 - -ls \[_-ACHLSZacdfhiklmnopqrstux1_\] \[_--color_\[_=auto_\]\] \[_directory..._\] - -> **说明:** 系统启动过程中已经通过 alias 为 ls=toybox ls --color=auto 、ll = ls -alF 、 la=ls -A 和 l=ls -CF 赋能,使这几个命令的初始行为就和linux相同(详细效果见输出说明)。所以若要查看help列表,请输入'toybox ls --help'。 - -## 参数说明 - -**表 1** 展示功能参数说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

--help

-

查看ls命令支持的参数列表,使用方式。

-

N/A

-

-a

-

显示所有文件包括.hidden隐藏类型的文件。

-

N/A

-

-b

-

转义非图形字符。

-

N/A

-

-c

-

使用ctime作为文件的时间戳。"ls -lc"

-

N/A

-

-d

-

只显示path名称不显示path所包含的内容。

-

N/A

-

-i

-

显示文件的节点号。

-

N/A

-

-p

-

在path名称后放一个"/"。

-

N/A

-

-q

-

显示不可打印字符比如'?'。

-

N/A

-

-s

-

统计目录和其成员所占用的内存大小,单位为1024字节。

-

N/A

-

-u

-

以文件的最后访问时间为时间戳,配合 -l 一起使用。

-

N/A

-

-A

-

列出所有文件除了.和..

-

N/A

-

-H

-

跟随命令行符号链接。

-

N/A

-

-L

-

跟随符号链接。

-

N/A

-

-Z

-

安全上下文。

-

N/A

-

path

-

path为空时,显示当前目录的内容。

-

path为无效文件名时,显示失败,提示:

-

ls error: No such directory。

-

path为有效目录路径时,会显示对应目录下的内容。

-

1.为空。

-

2.有效的目录路径。

-
- -**表2** 输出格式参数说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

-1

-

每行列出一个文件。

-

N/A

-

-c

-

列,垂直排序。

-

N/A

-

-g

-

类似于 -l 但没有所有者。

-

N/A

-

-h

-

统计path目录下文件的总大小,单位为KiB。

-

N/A

-

-l

-

详细的显示path目录下文件的信息。

-

N/A

-

-m

-

文件之间添加逗号。

-

N/A

-

-n

-

类似 -l 数字格式显示uid/gid。

-

N/A

-

-o

-

类似 -l 但显示列表不包括组。

-

N/A

-

-x

-

列,水平排序。

-

N/A

-

-ll

-

文件的时间属性显示纳秒。

-

N/A

-

--color

-

彩色打印。

-

默认配置为:device=yellow symlink=turquoise/red dir=blue socket=purple files: exe=green suid=red suidfile=redback stickydir=greenback=auto means detect if output is a tty.

-
- -**表3** 排序参数说明(默认为按首字母排序) - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

-f

-

不排序。

-

N/A

-

-r

-

按首字母反向排序。

-

N/A

-

-t

-

按文件的最后修改时间排序,最近时间为排头。

-

N/A

-

-S

-

按文件大小来排序,大文件为排头。

-

N/A

-
- -## 使用指南 - -- ls命令显示当前目录的内容。 -- ll可以显示文件的大小。 -- proc下ll无法统计文件大小,显示为0。 -- dev、proc、无法统计文件时间信息。 - -> ![](/images/device-dev/public_sys-resources/icon-notice.gif) **须知:** -> -> fatfs的文件节点信息继承其父节点,父节点号为0。故在hi3516dv300开发板上ls -i显示的文件节点号全为0。 - -## 使用实例 - -举例: - -- ls -- ll - -## 输出说明 - -**示例 1** ls命令查看当前路径下的内容 - -```shell -OHOS:/$ ls -bin etc nfs sdcard system usr -dev lib proc storage userdata vendor -``` - -**示例 2** ll命令查看当前路径下的内容 - -```shell -OHOS:/$ ll -total 20 -drwxrwxrwx 1 0 0 2048 2021-11-21 17:52 bin/ -drwxr-xr-x 0 0 0 0 1970-01-01 00:00 dev/ -drwxrwxrwx 1 0 0 2048 2021-11-21 17:52 etc/ -drwxrwxrwx 1 0 0 2048 2021-11-21 17:52 lib/ -drwxrwxrwx 0 0 0 4096 2021-10-25 02:17 nfs/ -dr-xr-xr-x 0 0 0 0 1970-01-01 00:00 proc/ -drwxrwxrwx 1 0 0 4096 1979-12-31 00:00 sdcard/ -drwxrwxrwx 1 0 0 2048 2021-11-21 17:52 storage/ -drwxrwxrwx 1 0 0 2048 2021-11-21 17:52 system/ -drwxrwxrwx 1 0 0 2048 2021-11-21 17:52 userdata/ -drwxrwxrwx 1 0 0 2048 2021-11-21 17:52 usr/ -drwxrwxrwx 1 0 0 2048 2021-11-21 17:52 vendor/ -``` diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/09.lsfd.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/09.lsfd.md" deleted file mode 100644 index 16663e1c71c224c74d776c2dec668410a69bc9f8..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/09.lsfd.md" +++ /dev/null @@ -1,80 +0,0 @@ ---- -title: lsfd -permalink: /pages/010501020501040209 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# lsfd - -- [命令功能](#section2053406181716) -- [命令格式](#section523771017172) -- [使用指南](#section27241213201719) -- [使用实例](#section442617197173) -- [输出说明](#section42491639151813) - -## 命令功能 - -lsfd命令用来显示当前已经打开的文件描述符及对应的文件名。 - -## 命令格式 - -lsfd - -## 使用指南 - -lsfd命令显示当前已经打开文件的fd号以及文件的名字。 - -## 使用实例 - -举例:输入lsfd - -## 输出说明 - -**示例** lsfd输出说明 - -```shell -OHOS # lsfd - fd filename - 3 /dev/console1 - 4 /dev/hilog - 5 /dev/hilog - 6 /dev/hilog - 7 /dev/lite_ipc - 8 /dev/hilog - 9 /dev/lite_ipc - 10 /dev/vb - 11 /dev/hilog - 12 /dev/vo - 13 /dev/hilog - 14 /dev/hilog - 15 /dev/sys - 16 /dev/lite_ipc - 17 /dev/lite_ipc - 18 /dev/hi_tde - 19 /dev/fb0 - 20 /dev/vo - 21 /dev/mmz_userdev - 22 /dev/hi_tde - 23 /dev/lite_ipc - 24 /dev/hdf/hdf_input_event1 - 25 /dev/lite_ipc - 26 /dev/mmz_userdev - 27 /dev/lite_ipc - 28 /dev/hilog - 29 /dev/hilog - 30 /dev/hdf/hdf_sensor_manager_ap - 31 /dev/hilog - 32 /dev/lite_ipc - 33 /dev/lite_ipc - 34 /dev/lite_ipc -``` - - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/10.mkdir.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/10.mkdir.md" deleted file mode 100644 index 19b97b3dc194e5a98a5c21a0a6b35773a108cd85..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/10.mkdir.md" +++ /dev/null @@ -1,138 +0,0 @@ ---- -title: mkdir -permalink: /pages/01050102050104020a -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# mkdir - -- [命令功能](#section01) -- [命令格式](#section02) -- [参数说明](#section03) -- [使用指南](#section04) -- [使用实例](#section05) -- [输出说明](#section06) - -## 命令功能 - -mkdir命令用来创建一个目录。 - -## 命令格式 - -mkdir \[_-vp_\] \[_-m mode_\] \[_dirname..._\] - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

--help

-

查看mkdir命令支持的参数列表

-

N/A

-

-m

-

设置即将创建目录的权限。

-

N/A

-

-p

-

递归逐级创建父子目录。

-

N/A

-

-v

-

打印创建目录过程中的详细信息。

-

N/A

-

directory

-

需要创建的目录。

-

N/A

-
- -## 使用指南 - -- mkdir后加所需要创建的目录名会在当前目录下创建目录。 -- mkdir后加路径,再加上需要创建的目录名,即在指定目录下创建目录。 -- mkdir后加参数,提供目录权限定制,目录逐级创建等功能。 - -> ![](/images/device-dev/public_sys-resources/icon-notice.gif) **须知:** -> -> fatfs文件系统所有创建的文件和其挂载节点的权限属性保持一致,目前节点的权限只有用户读写权限,group和others权限不生效, -> -> 且只有读写位可设置,有rw和ro两种,因此mkdir在附加-m参数时,创建的目录权限仅有777和555两种,可执行权限也不生效。 - -## 使用实例 - -举例: - -- mkdir testpath -- mkdir -m 777 testpath -- mkdir -pv testpath01/testpath02/testpath03 - -## 输出说明 - -**示例 1** 创建默认文件 - -```shell -OHOS:/tmp$ mkdir testpath -OHOS:/tmp$ ll -total 2 -drwxrwxrwx 1 0 0 2048 1979-12-31 00:00 testpath/ -``` - -**示例 2** 创建指定mode的目录 - -```shell -OHOS:/tmp$ mkdir -m 777 testpath -OHOS:/tmp$ ll -total 2 -drwxrwxrwx 1 0 0 2048 1979-12-31 00:00 testpath/ -``` - -**示例 3** 逐级创建目录 - -```shell -OHOS:/tmp$ mkdir -pv testpath01/testpath02/testpath03 -mkdir: created directory 'testpath01' -mkdir: created directory 'testpath01/testpath02' -mkdir: created directory 'testpath01/testpath02/testpath03' -OHOS:/tmp$ ll -total 2 -drwxrwxrwx 1 0 0 2048 1979-12-31 00:00 testpath01/ -OHOS:/tmp$ ll testpath01/ -total 2 -drwxrwxrwx 1 0 0 2048 1979-12-31 00:00 testpath02/ -OHOS:/tmp$ ll testpath01/testpath02/ -total 2 -drwxrwxrwx 1 0 0 2048 1979-12-31 00:00 testpath03/ -``` diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/11.mount.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/11.mount.md" deleted file mode 100644 index a780ffa784fd535227d69e72709f9256b090545b..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/11.mount.md" +++ /dev/null @@ -1,111 +0,0 @@ ---- -title: mount -permalink: /pages/01050102050104020b -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# mount - -- [命令功能](#section01) -- [命令格式](#section02) -- [参数说明](#section03) -- [使用指南](#section04) -- [使用实例](#section05) -- [输出说明](#section06) - -## 命令功能 - -mount命令用来将设备挂载到指定目录。 - -## 命令格式 - -mount \[_-f_\] \[_-t TYPE_\] \[_-o OPTION,_\] \[\[_DEVICE_\] _DIR_\] - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

--help

-

查看mount命令支持的参数列表。

-

N/A

-

-f

-

佯装挂载动作(实际不做挂载)。

-

N/A

-

-t

-

文件系统的种类。

-

TYPE:vfat, yaffs, jffs, ramfs, nfs,procfs, romfs.

-

-o

-

挂载选项。

-

N/A

-

DEVICE

-

要挂载的设备(格式为设备所在路径)。

-

系统拥有的设备。

-

DIR

-

指定目录。

-

用户必须具有指定目录中的执行(搜索)许可权。

-

N/A

-
- -## 使用指南 - -mount后加需要挂载的设备信息、指定目录以及设备文件格式,就能成功挂载文件系统到指定目录。 - -## 使用实例 - -举例:mount -t nfs 192.168.1.3:/nfs nfs - -## 输出说明 - -**示例** 将服务器端nfs目录192.168.1.3:/nfs挂载到当前系统下新建的/nfs目录: - -```shell -OHOS:/$ mkdir nfs -OHOS:/$ mount -t nfs 192.168.1.3:/nfs nfs -Mount nfs on 192.168.1.3:/nfs, uid:0, gid:0 -Mount nfs finished. -OHOS:/$ ls nfs/ -16d.xml gpio_test ohos_test.txt userfs_vfat.img -OHOS_Image.bin hello rootfs_vfat.img -dev_tools mksh_rootfs_vfat.img test_demo -``` diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/12.partinfo.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/12.partinfo.md" deleted file mode 100644 index 2c8207d8abdb646dfa1c7ee92f179af6cef0747f..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/12.partinfo.md" +++ /dev/null @@ -1,78 +0,0 @@ ---- -title: partinfo -permalink: /pages/01050102050104020c -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# partinfo - -- [命令功能](#section1777503617199) -- [命令格式](#section185501447132114) -- [参数说明](#section1304151212252) -- [使用指南](#section4566131982520) -- [使用实例](#section4351134942514) -- [输出说明](#section66689331412) - -## 命令功能 - -partinfo命令用于查看系统识别的硬盘,SD卡多分区信息。 - -## 命令格式 - -partinfo <_dev\_inodename_\> - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

dev_inodename

-

要查看的分区名字。

-

合法的分区名。

-
- -## 使用指南 - -无。 - -## 使用实例 - -举例:partinfo /dev/mmcblk0p0 - -## 输出说明 - -**示例** 查看系统分区信息 - -```shell -OHOS # partinfo /dev/mmcblk0p0 - -part info : -disk id : 0 -part_id in system: 1 -part no in disk : 0 -part no in mbr : 0 -part filesystem : 00 -part sec start : 20480 -part sec count : 102400 -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/13.partition.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/13.partition.md" deleted file mode 100644 index 18b5fcb35d38a5eed91228d6658c91ac131417e0..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/13.partition.md" +++ /dev/null @@ -1,78 +0,0 @@ ---- -title: partition -permalink: /pages/01050102050104020d -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# partition - -- [命令功能](#section255095212257) -- [命令格式](#section10258056122515) -- [参数说明](#section177200581256) -- [使用指南](#section17866411262) -- [使用实例](#section1927174202610) -- [输出说明](#section11321011223) - -## 命令功能 - -partition命令用来查看flash分区信息。 - -## 命令格式 - -partition \[_nand / spinor_\] - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

nand

-

显示nand flash分区信息。

-

N/A

-

spinor

-

显示spinor flash分区信息。

-

N/A

-
- -## 使用指南 - -- partition命令用来查看flash分区信息。 -- 仅当使能yaffs文件系统时才可以查看nand flash分区信息,使能jffs或romfs文件系统时可以查看spinor flash分区信息。 - -## 使用实例 - -举例:partition spinor - -## 输出说明 - -查看spinor flash分区信息 - -```shell -OHOS # partition spinor -spinor partition num:0, blkdev name:/dev/spinorblk0, mountpt:/, startaddr:0x00500000, length:0x00a00000 -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/14.pwd.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/14.pwd.md" deleted file mode 100644 index 57274d618aa80e7f99c3021de987f37c088a7a2f..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/14.pwd.md" +++ /dev/null @@ -1,51 +0,0 @@ ---- -title: pwd -permalink: /pages/01050102050104020e -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# pwd - -- [命令功能](#section197737712267) -- [命令格式](#section1544061016267) -- [参数说明](#section599112120262) -- [使用指南](#section66901116152615) -- [使用实例](#section7427181922612) -- [输出说明](#section116313389418) - -## 命令功能 - -pwd命令用来显示当前路径。 - -## 命令格式 - -pwd - -## 参数说明 - -无。 - -## 使用指南 - -pwd 命令将当前目录的全路径名称(从根目录)写入标准输出。全部目录使用 / (斜线)分隔。第一个 / 表示根目录, 最后一个目录是当前目录。 - -## 使用实例 - -举例:输入pwd - -## 输出说明 - -**示例** 查看当前路径 - -```shell -OHOS:/sdcard/nfs$ pwd -/sdcard/nfs -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/15.rm.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/15.rm.md" deleted file mode 100644 index 5909e504031d74aac4df9b5e2035819177768b14..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/15.rm.md" +++ /dev/null @@ -1,112 +0,0 @@ ---- -title: rm -permalink: /pages/01050102050104020f -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# rm - -- [命令功能](#section01) -- [命令格式](#section02) -- [参数说明](#section03) -- [使用指南](#section04) -- [使用实例](#section05) -- [输出说明](#section06) - -## 命令功能 - -rm命令用来删除文件或文件夹。 - -## 命令格式 - -rm \[_-fv_\] _FILE or rm_ \[_-rv_\] \[_PATH_ | _filename_\]... - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

-r

-

删除空目录或非空目录。

-

N/A

-

-f

-

强制删除:不需要确认,删除不存的文件在也不报错。

-

N/A

-

-v

-

显示删除的过程。

-

N/A

-

PATH/filename

-

要删除文件或文件夹的名称,支持输入路径。

-

N/A

-
- -## 使用指南 - -- rm命令能同时删除多个文件或文件夹。 -- rm -r命令可以删除非空目录。 -- 删除不存在的文件会报错。 - -## 使用实例 - -举例: - -- 输入rm testfile -- 输入rm -r testpath/ - -## 输出说明 - -**示例 1** 用 rm 命令删除文件 testfile - -```shell -OHOS:/$ ls -bin etc proc storage testfile usr -dev lib sdcard system userdata vendor -OHOS:/$ rm testfile -OHOS:/$ ls -bin etc proc storage userdata vendor -dev lib sdcard system usr -``` - -**示例 2** 用 rm -r 删除非空目录 testpath - -```shell -OHOS:/$ ls -bin etc proc storage testpath usr -dev lib sdcard system userdata vendor -OHOS:/$ rm -r testpath/ -OHOS:/$ ls -bin etc proc storage userdata vendor -dev lib sdcard system usr -``` diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/16.rmdir.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/16.rmdir.md" deleted file mode 100644 index a688e36b286596221af5346685ee871cd6523c4a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/16.rmdir.md" +++ /dev/null @@ -1,95 +0,0 @@ ---- -title: rmdir -permalink: /pages/010501020501040210 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# rmdir - -- [命令功能](#section01) -- [命令格式](#section02) -- [参数说明](#section03) -- [使用指南](#section04) -- [使用实例](#section05) -- [输出说明](#section06) - -## 命令功能 - -rmdir命令用来删除一个目录。 - -## 命令格式 - -rmdir \[_-p_\] \[_dirname..._\] - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

--help

-

查看rmdir命令支持的参数列表。

-

N/A

-

-p

-

删除路径。

-

N/A

-

--ignore-fail-on-non-empty

-

忽略删除非空目录导致的故障。

-

N/A

-

dir

-

需要删除目录的名称,删除目录必须为空,支持输入路径。

-

N/A

-
- -## 使用指南 - -- rmdir命令只能用来删除目录。 -- rmdir一次只能删除一个目录。 -- rmdir只能删除空目录。 - -## 使用实例 - -举例:输入rmdir dir - -## 输出说明 - -**示例** 删除一个名为 dir 的目录 - -```shell -OHOS:/test$ mkdir dir -OHOS:/test$ ls -dir -OHOS:/test$ rmdir dir/ -OHOS:/test$ ls -``` diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/17.statfs.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/17.statfs.md" deleted file mode 100644 index 327c99571d9200baba230ad4877c42deecd3ad46..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/17.statfs.md" +++ /dev/null @@ -1,79 +0,0 @@ ---- -title: statfs -permalink: /pages/010501020501040211 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# statfs - -- [命令功能](#section153921657152613) -- [命令格式](#section135391102717) -- [参数说明](#section074312314279) -- [使用指南](#section133816772712) -- [使用实例](#section526149182717) - -## 命令功能 - -statfs命令用来打印文件系统的信息,如该文件系统类型、总大小、可用大小等信息。 - -## 命令格式 - -statfs \[_directory_\] - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

directory

-

文件系统的路径。

-

必须是存在的文件系统,并且其支持statfs命令,当前支持的文件系统有:JFFS2,FAT,NFS。

-
- -## 使用指南 - -打印信息因文件系统而异。 - -## 使用实例 - -以nfs文件系统为例: - -输入statfs /nfs - -**示例** 但因nfs文件系统信息 - -```shell -OHOS # statfs ./nfs -statfs got: - f_type = 26985 - cluster_size = 512 - total_clusters = 1579575176 - free_clusters = 499254808 - avail_clusters = 499254808 - f_namelen = 255 - -./nfs - total size: 808742490112 Bytes - free size: 255618461696 Bytes -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/18.sync.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/18.sync.md" deleted file mode 100644 index 2927ced1e18470617752926882de4c14e16b3f87..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/18.sync.md" +++ /dev/null @@ -1,47 +0,0 @@ ---- -title: sync -permalink: /pages/010501020501040212 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# sync - -- [命令功能](#section1285017122274) -- [命令格式](#section4731516162712) -- [参数说明](#section9352418122714) -- [使用指南](#section10725192142717) -- [使用实例](#section414434814354) -- [输出说明](#section19618121710317) - -## 命令功能 - -sync命令用于同步缓存数据(文件系统的数据)到sd卡。 - -## 命令格式 - -sync - -## 参数说明 - -无。 - -## 使用指南 - -- sync命令用来刷新缓存,当没有sd卡插入时不进行操作。 -- 有sd卡插入时缓存信息会同步到sd卡,成功返回时无显示。 - -## 使用实例 - -举例:输入sync,有sd卡时同步到sd卡,无sd卡时不操作。 - -## 输出说明 - -无。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/19.touch.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/19.touch.md" deleted file mode 100644 index d6e225055de35d0277805eaae6b439298fa880cd..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/19.touch.md" +++ /dev/null @@ -1,102 +0,0 @@ ---- -title: touch -permalink: /pages/010501020501040213 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# touch - -- [命令功能](#section01) -- [命令格式](#section02) -- [参数说明](#section03) -- [使用指南](#section04) -- [使用实例](#section405) -- [输出说明](#section06) - -## 命令功能 - -- touch命令用来在指定的目录下创建一个不存在的空文件。 -- touch命令操作已存在的文件会成功,不会更新时间戳。 - -## 命令格式 - -touch \[_filename_\] - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

--help

-

查看touch命令支持的参数列表

-

N/A

-

filename

-

需要创建文件的名称。

-

N/A

-
- -## 使用指南 - -- touch命令用来创建一个空文件,该文件可读写。 -- 使用touch命令允许一次创建多个文件。 - - >![](/images/device-dev/public_sys-resources/icon-notice.gif) **须知:** - >在系统重要资源路径下使用touch命令创建文件,会对系统造成死机等未知影响,如在/dev路径下执行touch uartdev-0,会产生系统卡死现象。 - -## 使用实例 - -举例: - -- touch file.c -- touch testfile1 testfile2 testfile3 - -## 输出说明 - -**示例 1** 创建一个名为 file.c 的文件 - -```shell -OHOS:/tmp$ ls -OHOS:/tmp$ touch file.c -OHOS:/tmp$ ls -file.c -OHOS:/tmp$ ll -total 0 --rwxrwxrwx 1 0 0 0 1979-12-31 00:00 file.c* -``` - -**示例 2** 同时创建三个文件 - -```shell -OHOS:/tmp$ touch testfile1 testfile2 testfile3 -OHOS:/tmp$ ll -total 0 --rwxrwxrwx 1 0 0 0 1979-12-31 00:00 testfile1* --rwxrwxrwx 1 0 0 0 1979-12-31 00:00 testfile2* --rwxrwxrwx 1 0 0 0 1979-12-31 00:00 testfile3* -OHOS:/tmp$ -``` diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/20.writeproc.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/20.writeproc.md" deleted file mode 100644 index b6dcbe771922e798031d656c4e8bc4db79f8a415..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/20.writeproc.md" +++ /dev/null @@ -1,82 +0,0 @@ ---- -title: writeproc -permalink: /pages/010501020501040214 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# writeproc - -- [命令功能](#section366714216619) -- [命令格式](#section8833164614615) -- [参数说明](#section12809111019453) -- [使用指南](#section15935131220717) -- [使用实例](#section79281818476) -- [输出说明](#section12742311179) - -## 命令功能 - -proc fs支持传入字符串参数,需要每个文件实现自己的写方法。 - -## 命令格式 - -writeproc <_data_\> \>\> /proc/<_filename_\> - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

data

-

要输入的字符串,以空格为结束符,如需输入空格,请用""包裹。

-

N/A

-

filename

-

data要传入的proc文件。

-

N/A

-
- -## 使用指南 - -proc文件实现自身的write函数,调用writeproc命令后会将入参传入write函数。 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->procfs不支持多线程访问。 - -## 使用实例 - -举例:writeproc test \>\> /proc/uptime - -## 输出说明 - -OHOS \# writeproc test \>\> /proc/uptime - -\[INFO\]write buf is: test - -test \>\> /proc/uptime - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->uptime proc文件临时实现write函数,INFO日志为实现的测试函数打印的日志。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/21.umount.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/21.umount.md" deleted file mode 100644 index 876ae8fc4c2e1a500ebd28275489c28e545185ff..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/21.umount.md" +++ /dev/null @@ -1,103 +0,0 @@ ---- -title: umount -permalink: /pages/010501020501040215 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# umount - -- [命令功能](#section01) -- [命令格式](#section02) -- [参数说明](#section03) -- [使用指南](#section04) -- [使用实例](#section05) -- [输出说明](#section06) - -## 命令功能 - -umount命令用来卸载指定文件系统。 - -## 命令格式 - -umount \[_-a \[-t TYPE\]_\] \[_dir_\] - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

--help

-

查看umount命令支持的参数列表。

-

N/A

-

-a

-

卸载所有已挂载的目录。

-

N/A

-

-t

-

同-a选项一起使用,限制-a,只卸载-t所指定的文件系统类型。

-

N/A

-

dir

-

需要卸载文件系统对应的目录。

-

系统已挂载的文件系统的目录。

-
- -## 使用指南 - -umount后加上需要卸载的指定文件系统的目录,即将指定文件系统卸载。 - -## 使用实例 - -举例: - -- umount ./nfs -- umount -a -t nfs ./nfs - -## 输出说明 - -将已在./nfs挂载的文件系统卸载掉。 - -**示例 1** umount输出示例 - -```shell -OHOS:/$ umount ./nfs/ -umount ok -``` - -**示例 2** umount指定文件类型 - -```shell -OHOS:/$ umount -a -t nfs ./nfs/ -umount ok -``` diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/22.du.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/22.du.md" deleted file mode 100644 index bbdcbeddd00e1293976ac96517736a468095fdca..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/22.du.md" +++ /dev/null @@ -1,105 +0,0 @@ ---- -title: du -permalink: /pages/010501020501040216 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# du - -- [命令功能](#section01) -- [命令格式](#section02) -- [参数说明](#section03) -- [使用指南](#section04) -- [使用实例](#section05) -- [输出说明](#section06) - -## 命令功能 - -du显示指定的文件所占用的磁盘空间。 - -## 命令格式 - -du \[_-kKmh_\] \[_file..._\] - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

--help

-

查看du命令支持的参数列表。

-

N/A

-

-k

-

显示占用的块,每块1024bytes(默认)。

-

N/A

-

-K

-

显示占用的块,每块512bytes(posix)。

-

N/A

-

-m

-

兆字节为单位。

-

N/A

-

-h

-

以K,M,G为单位,提高信息的可读性(例如,1K 243M 2G)。

-

N/A

-

file

-

指定的需要统计的文件。

-

N/A

-
- -## 使用指南 - -- 不支持统计目录的大小,只支持统计文件的大小。 -- file的内容既为文件名,不能包含其所在的目录。 - -## 使用实例 - -举例:du -h testfile - -## 输出说明 - -**示例** 显示结果如下 - -```shell -OHOS:/$ du -h testfile -1.8K testfile -``` diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/23.mv.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/23.mv.md" deleted file mode 100644 index 8ee89b915080a14f2155d0350129210d91952662..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/02.\346\226\207\344\273\266\345\221\275\344\273\244/23.mv.md" +++ /dev/null @@ -1,148 +0,0 @@ ---- -title: mv -permalink: /pages/010501020501040217 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# mv - -- [命令功能](#section01) -- [命令格式](#section02) -- [参数说明](#section03) -- [使用指南](#section04) -- [使用实例](#section05) -- [输出说明](#section06) - -## 命令功能 - -移动文件 - -## 命令格式 - -mv \[_-fivn_\] _SOURCE... DEST_ - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

--help

-

使用帮助。

-

N/A

-

-f

-

通过删除目标文件强制复制。

-

N/A

-

-i

-

若指定移动的源目录或文件与目标中目录或文件同名,则会先询问是否覆盖旧文件,输入 y 直接覆盖,输入 n 取消该操作。

-

N/A

-

-n

-

不要覆盖任何已存在的文件或目录。

-

N/A

-

-v

-

目前本参数toybox官方最新代码虽然支持,但同样也不生效。

-

N/A

-

SOURCE

-

源文件路径。

-

目前只支持文件,不支持目录;支持多文件同时移动。

-

DEST

-

目的文件路径。

-

支持目录以及文件。

-
- -## 使用指南 - -- 源文件路径支持“\*”和“?”通配符,“\*”代表任意多个字符,“?”代表任意单个字符。目的路径不支持通配符。当源路径可匹配多个文件时,目的路径必须为目录。 -- 目的路径为目录时,该目录必须存在。此时目的文件以源文件命名。 -- 目的路径为文件时,所在目录必须存在。 -- 目的文件已存在则会覆盖。 - -## 使用实例 - -举例: - -- mv -i test.txt testpath/ - -- mv test?.txt testpath/ (移动 test3.txt testA.txt test_.txt) - - -## 输出说明 - -**示例 1** 显示结果如下 - -```shell -OHOS:/$ touch test.txt -OHOS:/$ mkdir testpath -OHOS:/$ touch testpath/test.txt -OHOS:/$ mv -i test.txt testpath/ -mv: overwrite 'testpath//test.txt' (Y/n):y -OHOS:/$ ls -bin etc proc storage testpath usr -dev lib sdcard system userdata vendor -OHOS:/$ cp testpath/test.txt ./ -OHOS:/$ ls -bin etc proc storage test.txt userdata vendor -dev lib sdcard system testpath usr -OHOS:/$ mv -i test.txt testpath/ -mv: overwrite 'testpath//test.txt' (Y/n):n -OHOS:/$ ls -bin etc proc storage test.txt userdata vendor -dev lib sdcard system testpath usr -``` - -**示例 2** 通配符使用 - -```shell -OHOS:/$ ls -bin etc proc storage test.txt testA.txt testpath usr -dev lib sdcard system test3.txt test_.txt userdata vendor -OHOS:/$ mv test?.txt testpath/ -OHOS:/$ ls -bin etc proc storage test.txt userdata vendor -dev lib sdcard system testpath usr -OHOS:/$ ls testpath/ -test.txt test3.txt testA.txt test_.txt -``` diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/03.\347\275\221\347\273\234\345\221\275\344\273\244/01.arp.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/03.\347\275\221\347\273\234\345\221\275\344\273\244/01.arp.md" deleted file mode 100644 index d2b0911d402214fc7e94b11a6a793d8c64a7f117..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/03.\347\275\221\347\273\234\345\221\275\344\273\244/01.arp.md" +++ /dev/null @@ -1,130 +0,0 @@ ---- -title: arp -permalink: /pages/010501020501040301 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# arp - -- [命令功能](#section201149459368) -- [命令格式](#section579813484364) -- [参数说明](#section168065311366) -- [使用指南](#section19190125723612) -- [使用实例](#section10383416372) - -## 命令功能 - -在以太网中,主机之间的通信是直接使用MAC地址(非IP地址)来通信的,所以,对于使用IP通信的协议,必须能够将IP地址转换成MAC地址,才能在局域网(以太网)内通信。解决这个问题的方法就是主机存储一张IP和MAC地址对应的表,即ARP缓存,主机要往一个局域网内的目的IP地址发送IP包时,就可以从ARP缓存表中查询到目的MAC地址。ARP缓存是由TCP/IP协议栈维护的,用户可通过ARP命令查看和修改ARP表。 - -## 命令格式 - -- arp - -- arp \[_-i IF_\] -s _IPADDR HWADDR_ - -- arp \[_-i IF_\] -d _IPADDR_ - - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

-

打印整个ARP缓存的内容。

-

N/A

-

-i IF

-

指定的网络接口(可选参数)。

-

N/A

-

-s IPADDR

-

HWADDR

-

增加一条ARP表项,后面的参数是局域网中另一台主机的IP地址及其对应的MAC地址。

-

N/A

-

-d IPADDR

-

删除一条ARP表项。

-

N/A

-
- -## 使用指南 - -- arp命令用来查询和修改TCP/IP协议栈的ARP缓存表,增加非同一子网内的IP地址的ARP表项是没有意义的,协议栈会返回失败。 -- 命令需要启动TCP/IP协议栈后才能使用。 - -## 使用实例 - -举例: - -输入arp - -**示例** 打印整个 ARP 缓存表 - -```shell -OHOS # arp -Address HWaddress Iface Type -192.168.1.10 E6:2B:99:2C:4B:20 eth0 static -``` - -**表 2** 参数说明 - - - - - - - - - - - - - - - - - - - -

参数

-

说明

-

Address

-

表示网络设备的IPv4地址。

-

HWaddress

-

表示网络设备的MAC地址。

-

Iface

-

表示该ARP表项使用的接口名。

-

Type

-

表示该ARP表项是动态的还是静态的,动态是指ARP表项由协议栈自动创建,静态是指ARP表项是由用户增加的。

-
- diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/03.\347\275\221\347\273\234\345\221\275\344\273\244/02.dhclient.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/03.\347\275\221\347\273\234\345\221\275\344\273\244/02.dhclient.md" deleted file mode 100644 index 8698b224918dfce24e536f7ca1d6f772c7ded117..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/03.\347\275\221\347\273\234\345\221\275\344\273\244/02.dhclient.md" +++ /dev/null @@ -1,109 +0,0 @@ ---- -title: dhclient -permalink: /pages/010501020501040302 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# dhclient - -- [命令功能](#section01) -- [命令格式](#section02) -- [参数说明](#section03) -- [使用指南](#section04) -- [使用实例](#section05) -- [输出说明](#section06) - -## 命令功能 - -设置和查看dhclient的参数。 - -## 命令格式 - -- dhclient <_netif name_\> - -- dhclient -x <_netif name_\> - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

-h | --help

-

查看dhclient命令支持的参数列表,及使用方式。

-

N/A

-

<netif name>

-

启动对应网卡的dhcp请求。

-

网卡名字,eth0。

-

-x <netif name>

-

关闭对应网卡的dhcp功能。

-

网卡名字,eth0。

-
- -## 使用指南 - -无。 - -## 使用实例 - -举例: - -- dhclient eth0 -- dhclient -x eth0 - - -## 输出说明 - -**示例 1** 启动网卡eth0的dhcp请求 - -```shell -OHOS:/$ dhclient eth0 -OHOS:/$ ifconfig -lo ip:127.0.0.1 netmask:255.0.0.0 gateway:127.0.0.1 - ip6: ::1/64 - HWaddr 00 MTU:0 Running Link UP -eth0 ip:192.168.1.10 netmask:255.255.255.0 gateway:192.168.1.1 - HWaddr 42:da:81:bc:58:94 MTU:1500 Running Default Link UP -OHOS:/$ -``` - -**示例 2** 关闭网卡eth0的dhcp请求 - -```shell -OHOS:/$ dhclient -x eth0 -NetifStatusCallback(eth0): nsc event: 0xf0 -OHOS:/$ ifconfig -lo ip:127.0.0.1 netmask:255.0.0.0 gateway:127.0.0.1 - ip6: ::1/64 - HWaddr 00 MTU:0 Running Link UP -eth0 ip:0.0.0.0 netmask:0.0.0.0 gateway:0.0.0.0 - HWaddr 42:da:81:bc:58:94 MTU:1500 Running Default Link UP -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/03.\347\275\221\347\273\234\345\221\275\344\273\244/03.ifconfig.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/03.\347\275\221\347\273\234\345\221\275\344\273\244/03.ifconfig.md" deleted file mode 100644 index a22b6633a7aabb1c3bc475a0955a642f2d0df5bd..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/03.\347\275\221\347\273\234\345\221\275\344\273\244/03.ifconfig.md" +++ /dev/null @@ -1,333 +0,0 @@ ---- -title: ifconfig -permalink: /pages/010501020501040303 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# ifconfig - -- [命令功能](#section01) -- [命令格式](#section02) -- [参数说明](#section03) -- [使用指南](#section04) -- [使用实例](#section05) -- [输出说明](#section06) - -## 命令功能 - -ifconfig命令用来查询和设置网卡的IP地址、网络掩码、网关、硬件mac地址等参数。并能够启用/关闭网卡。 - -## 命令格式 - -ifconfig [option] - -option: - -- \[_-a_\] - -- <_interface_\> <_address_\> \[_netmask _\] \[_gateway _\] -- \[_hw ether _\] \[_mtu _\] - -- \[_inet6 add _\] - -- \[_inet6 del _\] - -- \[_up|down_\] - - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

不带参数

-

打印所有网卡的IP地址、网络掩码、网关、硬件mac地址、MTU、运行状态等信息。

-

N/A

-

-a

-

打印协议栈收发数据信息。

-

N/A

-

interface

-

指定网卡名,比如eth0。

-

N/A

-

address

-

设置IP地址,比如192.168.1.10,需指定网卡名。

-

N/A

-

netmask

-

设置子网掩码,后面要掩码参数,比如255.255.255.0。

-

N/A

-

gateway

-

设置网关,后面跟网关参数,比如192.168.1.1。

-

N/A

-

hw ether

-

设置mac地址, 后面是MAC地址,比如00:11:22:33:44:55。目前只支持ether硬件类型。

-

N/A

-

mtu

-

设置mtu大小,后面是mtu大小,比如1000。

-
  • 仅支持ipv4情况下的范围为

    [68,1500]。

    -
  • 支持ipv6情况下的范围为

    [1280,1500]。

    -
-

add

-

设置ipv6的地址,比如2001:a:b:c:d:e:f:d,需指定网卡名和inet6。

-

N/A

-

del

-

删除ipv6的地址,需指定网卡名和inet6。

-

N/A

-

up

-

启用网卡数据处理,需指定网卡名。

-

N/A

-

down

-

关闭网卡数据处理,需指定网卡名。

-

N/A

-
- -## 使用指南 - -- 命令需要启动TCP/IP协议栈后才能使用。 -- 由于IP冲突检测需要反应时间,每次使用ifconfig设置IP后会有2S左右的延时。 - -## 使用实例 - -- ifconfig eth0 192.168.100.31 netmask 255.255.255.0 gateway 192.168.100.1 hw ether 00:49:cb:6c:a1:31 -- ifconfig -a -- ifconfig eth0 inet6 add 2001:a:b:c:d:e:f:d -- ifconfig eth0 inet6 del 2001:a:b:c:d:e:f:d - -## 输出说明 - -**示例 1** 设置网络参数 - -```shell -OHOS:/$ ifconfig eth0 192.168.100.31 netmask 255.255.255.0 gateway 192.168.100.1 hw ether 00:49:cb:6c:a1:31 -OHOS:/$ ifconfig -lo ip:127.0.0.1 netmask:255.0.0.0 gateway:127.0.0.1 - ip6: ::1/64 - HWaddr 00 MTU:0 Running Link UP -eth0 ip:192.168.100.31 netmask:255.255.255.0 gateway:192.168.100.1 - HWaddr 00:49:cb:6c:a1:31 MTU:1500 Running Default Link UP -``` - -输出的各参数说明如下表所示: - -**表 2** 参数说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

说明

-

ip

-

板子IP地址。

-

netmask

-

网络掩码。

-

gateway

-

网关。

-

HWaddr

-

板子硬件mac地址。

-

MTU

-

网络最大传输单元。

-

Running/Stop

-

网卡是否正在运行。

-

Default

-

有这项说明此网卡连接到默认网关。

-

Link UP/Down

-

网卡连接状态。

-
- -**示例 2** 获取协议栈统计信息 - -```shell -OHOS # ifconfig -a -RX packets:6922 errors:0 ip dropped:4312 link dropped:67 overrun:0 bytes:0 (0.0 B) -RX packets(ip6):3 errors:0 dropped:0 overrun:0 bytes:0 (0.0 B) -TX packets:1394 errors:0 link dropped:67 overrun:0 bytes:0(0.0 B) -TX packets(ip6):3 errors:0 overrun:0 bytes:0(0.0 B) -``` - -输出的各参数说明如下表所示: - -**表 3** ifconfig -a 参数说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

说明

-

RX packets

-

IP层已接收的正常数据包的个数。

-

RX error

-

IP层已接收的错误数据包的个数,错误类型包括长度错误,校验错误,IP option错误,IP首部protocol错误等。

-

RX dropped

-

IP层已丢弃的数据包的个数,丢弃原因包括数据包错误,封包无法转发,本地网卡处于关闭状态等。

-

RX overrun

-

MAC层向上层协议栈投递封包失败的个数,失败原因主要是协议栈资源不足。

-

RX bytes

-

IP层已接收的正常数据包的总长度,不包括重组未完成的分片的长度。

-

TX packets

-

IP层已正常发送或转发的数据包的个数。

-

TX error

-

IP层发送失败的数据包的个数,失败原因包括封包无法路由,封包在协议栈内处理失败等。

-

TX dropped

-

MAC层由于发送失败而丢弃的数据包个数,失败原因包括网卡驱动处理封包失败等。

-

TX overrun

-

暂未使用。

-

TX bytes

-

IP层已正常发送或者转发的数据包的总长度。

-
- -**示例 3** 设置IPv6的地址信息 - -```shell -OHOS:/$ ifconfig eth0 inet6 add 2001:a:b:c:d:e:f:d -NetifStatusCallback(eth0): nsc event: 0x8 -NetifStatusCallback(eth0): nsc status changed: 0 -NetifStatusCallback(eth0): nsc event: 0x200 -NetifStatusCallback(eth0): nsc event: 0x8 -NetifStatusCallback(eth0): nsc status changed: 1 -NetifStatusCallback(eth0): nsc event: 0x200 -NetifStatusCallback(eth0): nsc event: 0x200 -OHOS:/$ ifconfig -lo ip:127.0.0.1 netmask:255.0.0.0 gateway:127.0.0.1 - ip6: ::1/64 - HWaddr 00 MTU:0 Running Link UP -eth0 ip:192.168.1.10 netmask:255.255.255.0 gateway:192.168.1.1 - ip6: 2001:A:B:C:D:E:F:D/64 - HWaddr 66:2f:e5:bd:24:e6 MTU:1500 Running Default Link UP -``` - -**示例 4** 删除IPv6的地址信息 - -```shell -OHOS:/$ ifconfig eth0 inet6 del 2001:a:b:c:d:e:f:d -NetifStatusCallback(eth0): nsc event: 0x200 -OHOS:/$ ifconfig -lo ip:127.0.0.1 netmask:255.0.0.0 gateway:127.0.0.1 - ip6: ::1/64 - HWaddr 00 MTU:0 Running Link UP -eth0 ip:192.168.1.10 netmask:255.255.255.0 gateway:192.168.1.1 - HWaddr 66:2f:e5:bd:24:e6 MTU:1500 Running Default Link UP -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/03.\347\275\221\347\273\234\345\221\275\344\273\244/04.ipdebug.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/03.\347\275\221\347\273\234\345\221\275\344\273\244/04.ipdebug.md" deleted file mode 100644 index 930007ffe5584355e2c4e834db82886749710258..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/03.\347\275\221\347\273\234\345\221\275\344\273\244/04.ipdebug.md" +++ /dev/null @@ -1,72 +0,0 @@ ---- -title: ipdebug -permalink: /pages/010501020501040304 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# ipdebug - -- [命令功能](#section10191115553720) -- [命令格式](#section124061758123713) -- [使用指南](#section171837113810) -- [输出说明](#section561416467104) - -## 命令功能 - -ipdebug是控制台命令,是一个调试ipv6信息非常有用的工具,它可以显示IPV6地址前缀,邻居条目信息,目的地缓存条目以及默认的路由条目。 - -## 命令格式 - -ipdebug - -## 使用指南 - -举例:输入命令ipdebug。 - -## 输出说明 - -**示例** ipdebug打印信息如下: - -```shell -OHOS # ipdebug -================= -|| Prefix List || -================= -Prefix validLifetime Flags -============================================================================================== -2001:: 86384 1 ----------------------------------------------------------------------------------------------- -============================ -|| Neighbor Cache Entries || -============================ -2001::1 dev eth0 lladr 44:39:C4:94:5D:44 STALE Router -FE80::4639:C4FF:FE94:5D44 dev eth0 lladr 44:39:C4:94:5D:44 REACHABLE Router --------------------------------------------------------------------- -=============================== -|| Destination Cache Entries || -=============================== -2001::1 2001::1 pmtu 1500 age 152 -FE80::4639:C4FF:FE94:5D44 FE80::4639:C4FF:FE94:5D44 pmtu 1500 age 6 -2002::1 FE80::4639:C4FF:FE94:5D44 pmtu 1500 age 17 -:: :: pmtu 0 age 219 -:: :: pmtu 0 age 219 -:: :: pmtu 0 age 219 -:: :: pmtu 0 age 219 -:: :: pmtu 0 age 219 -:: :: pmtu 0 age 219 -:: :: pmtu 0 age 219 --------------------------------------------------------------------- -============================ -|| Default Router Entries || -============================ -FE80::4639:C4FF:FE94:5D44 invalidation_timer 1784 flags 0 --------------------------------------------------------------------- -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/03.\347\275\221\347\273\234\345\221\275\344\273\244/05.netstat.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/03.\347\275\221\347\273\234\345\221\275\344\273\244/05.netstat.md" deleted file mode 100644 index 9719eb8d47409685ff2fcff4e99ab8cb708beeeb..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/03.\347\275\221\347\273\234\345\221\275\344\273\244/05.netstat.md" +++ /dev/null @@ -1,109 +0,0 @@ ---- -title: netstat -permalink: /pages/010501020501040305 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# netstat - -- [命令功能](#section13469162113816) -- [命令格式](#section795712373812) -- [参数说明](#section17629431193817) -- [使用指南](#section5277153519380) -- [使用实例](#section108141437163820) -- [输出说明](#section1357015107117) - -## 命令功能 - -netstat是控制台命令,是一个监测TCP/IP网络的非常有用的工具,它可以显示实际的网络连接以及每一个网络接口设备的状态信息。netstat用于显示与TCP、UDP协议相关的统计数据,一般用于检验本设备(单板)各端口的网络连接情况。 - -## 命令格式 - -netstat - -## 参数说明 - -无。 - -## 使用指南 - -无。 - -## 使用实例 - -举例:输入netstat - -## 输出说明 - -**示例** netstat 打印信息 - -```shell -OHOS # netstat -========== total sockets 128 ====== unused sockets 119 ========== -Proto Recv-Q Send-Q Local Address Foreign Address State -tcp 0 0 192.168.1.10:578 192.168.1.3:2049 ESTABLISHED -tcp 0 0 192.168.1.10:58653 0.0.0.0:0 LISTEN -tcp 0 0 192.168.1.10:58652 0.0.0.0:0 LISTEN -tcp 0 0 192.168.1.10:58651 0.0.0.0:0 LISTEN - -Proto Recv-Q Send-Q Local Address Foreign Address -udp 0 0 127.0.0.1:62177 127.0.0.1:62178 -udp 0 0 0.0.0.0:5684 0.0.0.0:0 -udp 0 0 127.0.0.1:62179 127.0.0.1:62180 -udp 0 0 127.0.0.1:62180 127.0.0.1:62179 -udp 0 0 127.0.0.1:62178 127.0.0.1:62177 -``` - -**表 1** 输出说明 - - - - - - - - - - - - - - - - - - - - - - - - - -

输出

-

说明

-

Proto

-

协议类型。

-

Recv-Q

-

未被用户读取的数据量。

-

对于Listen TCP,此值为已完成三次握手,但是未被用户accept的TCP连接的数量。

-

Send-Q

-

对TCP连接,已发送但未确认的数据量。

-

对UDP连接,由于IP地址解析未完成而缓存的数据量。

-

Local Address

-

本地地址和端口。

-

Foreign Address

-

远程地址和端口。

-

State

-

TCP连接状态,UDP此项无意义。

-
- ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->形如“========== total sockets 32 ====== unused sockets 22 BootTime 27 s ========== ”,表示一共32个套接字,未使用套接字22个,距系统启动已经过27秒。 diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/03.\347\275\221\347\273\234\345\221\275\344\273\244/06.ntpdate.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/03.\347\275\221\347\273\234\345\221\275\344\273\244/06.ntpdate.md" deleted file mode 100644 index 810f81a5dc6f9205eb63fb644b0398eea6fa0f23..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/03.\347\275\221\347\273\234\345\221\275\344\273\244/06.ntpdate.md" +++ /dev/null @@ -1,70 +0,0 @@ ---- -title: ntpdate -permalink: /pages/010501020501040306 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# ntpdate - -- [命令功能](#section38494293815) -- [命令格式](#section5503114413387) -- [参数说明](#section136934472383) -- [使用指南](#section121401651173816) -- [使用实例](#section3431554203811) -- [输出说明](#section18638194610115) - -## 命令功能 - -命令用于从服务器同步系统时间。 - -## 命令格式 - -ntpdate \[_SERVER\_IP1_\] \[_SERVER\_IP2_\]... - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

SERVER_IP

-

NTP服务器IP。

-

N/A

-
- -## 使用指南 - -直接执行ntpdate \[_SERVER\_IP1_\] \[_SERVER\_IP2_\]... ntpdate会获取第一个有效服务器IP的时间并显示。 - -## 使用实例 - -举例:使用ntpdate命令更新系统时间:ntpdate 192.168.1.3。 - -## 输出说明 - -``` -OHOS # ntpdate 192.168.1.3 -time server 192.168.1.3: Mon Jun 13 09:24:25 2016 -``` - -因为板子和服务器时区的不同,获取后的显示时间可能和服务器时间有数小时的差别。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/03.\347\275\221\347\273\234\345\221\275\344\273\244/07.ping.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/03.\347\275\221\347\273\234\345\221\275\344\273\244/07.ping.md" deleted file mode 100644 index 78b3c17b1152ebfebb8a867c413b3e8587fc8770..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/03.\347\275\221\347\273\234\345\221\275\344\273\244/07.ping.md" +++ /dev/null @@ -1,128 +0,0 @@ ---- -title: ping -permalink: /pages/010501020501040307 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# ping - -- [命令功能](#section01) -- [命令格式](#section02) -- [参数说明](#section03) -- [使用指南](#section04) -- [使用实例](#section05) -- [输出说明](#section06) - -## 命令功能 - -ping命令用于测试网络连接是否正常。 - -## 命令格式 - -ping _\[-4\] \[-c cnt\] \[-f\] \[-i interval\] \[-q\] \[-s size\] _ - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

--help

-

查看ping命令支持的参数列表

-

N/A

-

-4

-

强制以IPV4通讯协议ping目标地址。

-

0-65500

-

-c CNT

-

执行的次数,不带本参数则默认为3次。

-

1-65535

-

-f

-

隐式的ping IPv4地址,其默认参数配置等价于"-c 15 -i 0.2"

-

N/A

-

-i interval

-

发送两次ping包的时间间隔,单位毫秒。

-

1-200

-

-q

-

隐式的ping IPv4地址,如果主机还存活,则在返回 true 后停止ping。

-

N/A

-

-s SIZE

-

设置每个ping包的大小,SIZE是以字节为单位的数据(默认为56字节)。

-

0-4088

-

IP

-

要测试是否网络连通的IPv4地址。

-

N/A

-
- -## 使用指南 - -- ping命令用来测试到目的IP的网络连接是否正常,参数为目的IP地址。 -- 如果目的IP不可达,会显示请求超时。 -- 如果显示发送错误,说明没有到目的IP的路由。 -- 命令需要启动TCP/IP协议栈后才能使用。 - -## 使用实例 - -举例:输入ping 192.168.1.3 - -## 输出说明 - -**示例** ping tftp 服务器地址 - -```shell -OHOS:/$ ping 192.168.1.3 -Ping 192.168.1.3 (192.168.1.3): 56(84) bytes. -84 bytes from 192.168.1.3: icmp_seq=0 ttl=0 time=0 ms -84 bytes from 192.168.1.3: icmp_seq=0 ttl=0 time=1 ms -84 bytes from 192.168.1.3: icmp_seq=0 ttl=0 time=0 ms - ---- 192.168.1.3 ping statistics --- -3 packets transmitted, 3 received, 0% packet loss -round-trip min/avg/max = 0/0/0 ms -``` diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/03.\347\275\221\347\273\234\345\221\275\344\273\244/08.ping6.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/03.\347\275\221\347\273\234\345\221\275\344\273\244/08.ping6.md" deleted file mode 100644 index 1f30143e494b005d624dc9813c9c274862078955..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/03.\347\275\221\347\273\234\345\221\275\344\273\244/08.ping6.md" +++ /dev/null @@ -1,139 +0,0 @@ ---- -title: ping6 -permalink: /pages/010501020501040308 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# ping6 - -- [命令功能](#section1057291313393) -- [命令格式](#section199901315123919) -- [参数说明](#section4679319113919) -- [使用指南](#section1127917226399) -- [使用实例](#section7211192553917) -- [输出说明](#section4846145221215) - -## 命令功能 - -ping6用于测试IPv6网络连接是否正常。 - -## 命令格式 - -ping6 _\[-c count\] \[-I interface / sourceAddress\] destination_ - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

-c count

-

执行的次数,不带本参数则默认为4次。

-

1~65535

-

-I interface

-

指定网卡执行IPv6 ping操作。

-

N/A

-

-I sourceAddress

-

指定源IPv6地址执行ping操作。

-

N/A

-

destination

-

目标主机地址。

-

N/A

-
- -## 使用指南 - -- 如果目的IPv6地址不可达,会显示请求超时。 -- 如果显示发送错误,说明没有到目的IPV6的路由。 -- 命令需要启动TCP/IP协议栈后才能使用。 - -## 使用实例 - -- ping6 2001:a:b:c:d:e:f:b -- ping6 -c 3 2001:a:b:c:d:e:f:b -- ping6 -I eth0 2001:a:b:c:d:e:f:b -- ping6 -I 2001:a:b:c:d:e:f:d 2001:a:b:c:d:e:f:b - -## 输出说明 - -1. 输入ping6 2001:a:b:c:d:e:f:b - - ``` - OHOS # ping6 2001:a:b:c:d:e:f:b PING 2001:A:B:C:D:E:F:B with 56 bytes of data. - 56 bytes from 2001:A:B:C:D:E:F:B : icmp_seq=1 time<1 ms - 56 bytes from 2001:A:B:C:D:E:F:B : icmp_seq=2 time<1 ms - 56 bytes from 2001:A:B:C:D:E:F:B : icmp_seq=3 time<1 ms - 56 bytes from 2001:A:B:C:D:E:F:B : icmp_seq=4 time<1 ms - --- 2001:a:b:c:d:e:f:b/64 ping statistics --- - 4 packets transmitted, 4 received, 0.00% packet loss, time 20ms - rtt min/avg/max = 0/0.00/0 ms - ``` - -2. 输入 ping6 -c 3 2001:a:b:c:d:e:f:b 指定3次进行网络测试 - - ``` - OHOS # ping6 -c 3 2001:a:b:c:d:e:f:b PING 2001:A:B:C:D:E:F:B with 56 bytes of data. - 56 bytes from 2001:A:B:C:D:E:F:B : icmp_seq=1 time<1 ms - 56 bytes from 2001:A:B:C:D:E:F:B : icmp_seq=2 time<1 ms - 56 bytes from 2001:A:B:C:D:E:F:B : icmp_seq=3 time<1 ms - --- 2001:a:b:c:d:e:f:b/64 ping statistics --- - 3 packets transmitted, 3 received, 0.00% packet loss, time 20ms - rtt min/avg/max = 0/0.00/0 ms - ``` - -3. 输入 ping6 -I eth0 2001:a:b:c:d:e:f:b 使用指定网卡接口eth0测试IPv6。 - - ``` - OHOS # ping6 -I eth0 2001:a:b:c:d:e:f:b PING 2001:A:B:C:D:E:F:B with 56 bytes of data. - 56 bytes from 2001:A:B:C:D:E:F:B : icmp_seq=1 time=10 ms - 56 bytes from 2001:A:B:C:D:E:F:B : icmp_seq=2 time<1 ms - 56 bytes from 2001:A:B:C:D:E:F:B : icmp_seq=3 time<1 ms - 56 bytes from 2001:A:B:C:D:E:F:B : icmp_seq=4 time<1 ms - --- 2001:a:b:c:d:e:f:b/64 ping statistics --- - 4 packets transmitted, 4 received, 0.00% packet loss, time 30msrtt min/avg/max = 0/2.50/10 ms - ``` - -4. 输入 ping6 -I 2001:a:b:c:d:e:f:d 2001:a:b:c:d:e:f:b 使用指定的源IPv6地址2001:a:b:c:d:e:f:d进行测试。 - - ``` - OHOS # ping6 -I 2001:a:b:c:d:e:f:d 2001:a:b:c:d:e:f:b PING 2001:A:B:C:D:E:F:B with 56 bytes of data. - 56 bytes from 2001:A:B:C:D:E:F:B : icmp_seq=1 time<1 ms - 56 bytes from 2001:A:B:C:D:E:F:B : icmp_seq=2 time<1 ms - 56 bytes from 2001:A:B:C:D:E:F:B : icmp_seq=3 time<1 ms - 56 bytes from 2001:A:B:C:D:E:F:B : icmp_seq=4 time<1 ms - --- 2001:a:b:c:d:e:f:b/64 ping statistics --- - 4 packets transmitted, 4 received, 0.00% packet loss, time 20msrtt min/avg/max = 0/0.00/0 ms - ``` - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/03.\347\275\221\347\273\234\345\221\275\344\273\244/09.telnet.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/03.\347\275\221\347\273\234\345\221\275\344\273\244/09.telnet.md" deleted file mode 100644 index 17037ff3c336f1fb2e90b1d06e40ac758392eca4..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/03.\347\275\221\347\273\234\345\221\275\344\273\244/09.telnet.md" +++ /dev/null @@ -1,82 +0,0 @@ ---- -title: telnet -permalink: /pages/010501020501040309 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# telnet - -- [命令功能](#section3551830123913) -- [命令格式](#section14897133233918) -- [参数说明](#section977718353392) -- [使用指南](#section134991538183916) -- [使用实例](#section1097414426398) -- [输出说明](#section11846624191310) - -## 命令功能 - -本命令用于启动或关闭telnet server服务。 - -## 命令格式 - -telnet \[_on | off_\] - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

on

-

启动telnet server服务。

-

N/A

-

off

-

关闭telnet server服务。

-

N/A

-
- -## 使用指南 - -- telnet启动要确保网络驱动及网络协议栈已经初始化完成,且板子的网卡是link up状态。 -- 暂时无法支持多个客户端(telnet + IP)同时连接开发板。 - - >![](/images/device-dev/public_sys-resources/icon-notice.gif) **须知:** - >telnet属于调测功能,默认配置为关闭,正式产品中禁止使用该功能。 - - -## 使用实例 - -举例:输入telnet on - -## 输出说明 - -**示例** 输入 telnet on - -```shell -OHOS # telnet on -OHOS # start telnet server successfully, waiting for connection. -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/03.\347\275\221\347\273\234\345\221\275\344\273\244/10.tftp.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/03.\347\275\221\347\273\234\345\221\275\344\273\244/10.tftp.md" deleted file mode 100644 index 6fb7835fbde870ffdff9adcbd9ea0df963d60a4f..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/04.Shell\345\221\275\344\273\244\344\275\277\347\224\250\350\257\246\350\247\243/03.\347\275\221\347\273\234\345\221\275\344\273\244/10.tftp.md" +++ /dev/null @@ -1,100 +0,0 @@ ---- -title: tftp -permalink: /pages/01050102050104030a -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# tftp - -- [命令功能](#section15142134573911) -- [命令格式](#section20958174917394) -- [参数说明](#section576613532395) -- [使用指南](#section149795134408) -- [使用实例](#section148921918114015) -- [输出说明](#section7872155631313) - -## 命令功能 - -TFTP(Trivial File Transfer Protocol,简单文件传输协议)是TCP/IP协议族中的一个用来在客户机与服务器之间进行简单文件传输的协议,提供简单、低开销的文件传输服务。端口号为69。 - -tftp命令可以从TFTP服务器上下载文件。 - -## 命令格式 - -./bin/tftp _<-g/-p\>_ _-l_ _\[FullPathLocalFile\] -r \[RemoteFile\] \[Host\]_ - -## 参数说明 - -**表 1** 参数说明 - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

取值范围

-

-g/-p

-

文件传输方向:

-
  • -g 从TFTP服务器获取文件。
  • -p 上传文件到TFTP服务器。
-

N/A

-

-l FullPathLocalFile

-

本地文件完整路径。

-

N/A

-

-r RemoteFile

-

服务端文件名。

-

N/A

-

Host

-

服务端IP。

-

N/A

-
- -## 使用指南 - -1. 在服务器端搭建TFTP服务器,并进行正确配置。 -2. OpenHarmony单板使用tftp命令上传、下载文件。 -3. 传输的文件大小是有限制的不能大于32M。 - - >![](/images/device-dev/public_sys-resources/icon-notice.gif) **须知:** - >tftp属于调测功能,默认配置为关闭,正式产品中禁止使用该功能。 - - -## 使用实例 - -举例:从服务器下载out文件。 - -## 输出说明 - -``` -OHOS # ./bin/tftp -g -l /nfs/out -r out 192.168.1.2 -TFTP transfer finish -``` - -tftp命令执行后,传输正常完成会显示TFTP transfer finish, 失败的话会显示其他的打印信息帮助定位问题。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/05.\351\255\224\346\263\225\351\224\256\344\275\277\347\224\250\346\226\271\346\263\225.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/05.\351\255\224\346\263\225\351\224\256\344\275\277\347\224\250\346\226\271\346\263\225.md" deleted file mode 100644 index 87122b8cb52a43d7fd762c87cbf3822c8b07c721..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/05.\351\255\224\346\263\225\351\224\256\344\275\277\347\224\250\346\226\271\346\263\225.md" +++ /dev/null @@ -1,51 +0,0 @@ ---- -title: 魔法键使用方法 -permalink: /pages/01050102050105 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# 魔法键使用方法 - -- [使用场景](#section2350114718546) -- [使用方法](#section3305151511559) - -## 使用场景 - -在系统运行出现无响应等情况时,可以通过魔法键功能确定系统是否被锁中断(魔法键也无响应)或者查看系统任务运行状态等信息。 - -在中断有响应的情况下,可以通过魔法键查看task信息中 cpup(CPU占用率)看是哪个任务长时间占用CPU导致系统其他任务无响应(一般为比较高优先级任务一直抢占CPU,导致低优先级任务无响应)。 - -## 使用方法 - -1. 配置宏LOSCFG\_ENABLE\_MAGICKEY。 - -魔法键依赖于宏LOSCFG\_ENABLE\_MAGICKEY,使用时通过menuconfig在配置项中开启“Enable MAGIC KEY”: - -Debug ---\> Enable MAGIC KEY;若关闭该选项,则魔法键失效。 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->1. 可以在menuconfig中,将光标移动到LOSCFG\_ENABLE\_MAGICKEY上,输入“?”,查看帮助信息。 - -2. 输入“ctrl + r”键,打开魔法键检测功能。 - -在连接UART或者USB转虚拟串口的情况下,输入“ctrl + r” 键,打开魔法键检测功能,输出 “Magic key on”;再输入一次后,则关闭魔法键检测功能,输出“Magic key off”。魔法键功能如下: - -- ctrl + z:帮助键,输出相关魔法键简单介绍; - -- ctrl + t:输出任务相关信息; - -- ctrl + p:系统主动进入panic,输出panic相关信息后,系统会挂住; - -- ctrl + e:系统进行简单完整性内存池检查,检查出错会输出相关错误信息,检查正常会输出“system memcheck over, all passed!”。 - - ->![](/images/device-dev/public_sys-resources/icon-notice.gif) **须知:** ->魔法键检测功能打开情况下,如果需要通过UART或者USB转虚拟串口输入特殊字符需避免与魔法键值重复,否则魔法键会被误触发,而原有设计功能可能出现错误。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/06.\347\224\250\346\210\267\346\200\201\345\274\202\345\270\270\344\277\241\346\201\257\350\257\264\346\230\216.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/06.\347\224\250\346\210\267\346\200\201\345\274\202\345\270\270\344\277\241\346\201\257\350\257\264\346\230\216.md" deleted file mode 100644 index 64344a9aa1bfe18836aa5e0022cbc92139c59c86..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/01.Shell/06.\347\224\250\346\210\267\346\200\201\345\274\202\345\270\270\344\277\241\346\201\257\350\257\264\346\230\216.md" +++ /dev/null @@ -1,149 +0,0 @@ ---- -title: 用户态异常信息说明 -permalink: /pages/01050102050106 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# 用户态异常信息说明 - -用户态在运行过程中,可能由于各种原因出现用户态系统异常,异常信息如下所示: - -``` -##################excFrom: User!#################### -prefetch_abort fault fsr:0x5, far:0x00000000 -Translation fault, section -excType: prefetch abort -processName = shell -processID = 3 -process aspace = 0x01000000 -> 0x3f000000 -taskName = shell -taskID = 4 -task user stack = 0x3707d000 -> 0x3717d000 -pc = 0x0 -ulr = 0x2000424 in /bin/shell ---> 0x424 -usp = 0x3717cd60fp = 0x3717cd64 -R0 = 0x1 -R1 = 0x0 -R2 = 0x0 -R3 = 0x1 -R4 = 0x3717cf58 -R5 = 0x0 -R6 = 0x3717cf54 -R7 = 0x200043c -R8 = 0x84 -R9 = 0x229a7560 -R10 = 0x0 -R11 = 0x3717cd64 -R12 = 0x0 -CPSR = 0x40000030 -*******backtrace begin******* -traceback 0 -- lr = 0x229123a4 fp = 0x0 lr in /lib/libc.so --> 0x213a4 - - PID PPID PGID UID Status CPUUSE CPUUSE10s CPUUSE1s Policy Priority MTID TaskTotal Mode PName - 1 -1 1 0 Ready 0.0 0.0 0.0 RR 28 16 1 user init - 2 -1 2 0 Pend 10.1 10.1 0.0 RR 0 0 14 kernel KProcess - 3 1 3 0 Running 0.0 0.0 0.0 RR 28 4 1 user shell - - TID PID Status StackSize WaterLine Policy Priority MEMUSE TaskName - 16 1 Ready 0x3000 0x978 RR 31 0x8b0c init - 0 2 Pend 0x1000 0x1d4 RR 5 0 ResourcesTask - 2 2 Pend 0x4000 0x4ec RR 0 0 Swt_Task - 3 2 Pend 0x4000 0x1d4 RR 1 0 system_wq - 5 2 Pend 0x4000 0x1fc RR 9 0 SendToSer - 6 2 PendTime 0x6000 0x204 RR 5 0 tcpip_thread - 7 2 Pend 0x3000 0x1fc RR 5 0 sdmci_detect - 8 2 Pend 0x4000 0x204 RR 5 0 USB_GIANT_Task - 9 2 Pend 0x4000 0x204 RR 1 0 USB_NGIAN_ISOC_Task - 10 2 Pend 0x4000 0x204 RR 2 0 USB_NGIAN_BULK_Task - 11 2 Pend 0x4000 0x690 RR 5 0xbb0 USB_EXPLR_Task - 12 2 Pend 0x4000 0x204 RR 5 0 USB_CXFER_Task - 13 2 Pend 0x20000 0x1e4 RR 3 0xac20 eth_irq_Task - 14 2 Pend 0x4000 0x1d4 RR 10 0 jffs2_gc_thread - 15 2 Pend 0x2000 0x1f4 RR 4 0 hisi_frw - 4 3 Running 0x3000 0x838 RR 31 0x1100 shell -system memcheck over, all passed! -``` - -其中,主要包含如下几方面信息: - -1. 用户态异常基本信息: - - ``` - prefetch_abort fault fsr:0x5, far:0x00000000 - Translation fault, section - excType: prefetch abort - processName = shell - processID = 3 - process aspace = 0x01000000 -> 0x3f000000 - taskName = shell - taskID = 4 - task user stack = 0x3707d000 -> 0x3717d000 - ``` - -2. 寄存器相关信息。 - - ``` - pc = 0x0 - ulr = 0x2000424 in /bin/shell ---> 0x424 - usp = 0x3717cd60fp = 0x3717cd64 - R0 = 0x1 - R1 = 0x0 - R2 = 0x0 - R3 = 0x1 - R4 = 0x3717cf58 - R5 = 0x0 - R6 = 0x3717cf54 - R7 = 0x200043c - R8 = 0x84 - R9 = 0x229a7560 - R10 = 0x0 - R11 = 0x3717cd64 - R12 = 0x0 - CPSR = 0x40000030 - ``` - -3. 调用栈信息。 - - ``` - *******backtrace begin******* - traceback 0 -- lr = 0x229123a4 fp = 0x0 lr in /lib/libc.so --> 0x213a4 - ``` - -4. 进程线程基本信息。 - - ``` - PID PPID PGID UID Status CPUUSE CPUUSE10s CPUUSE1s Policy Priority MTID TaskTotal Mode PName - 1 -1 1 0 Ready 0.0 0.0 0.0 RR 28 16 1 user init - 2 -1 2 0 Pend 10.1 10.1 0.0 RR 0 0 14 kernel KProcess - 3 1 3 0 Running 0.0 0.0 0.0 RR 28 4 1 user shell - - TID PID Status StackSize WaterLine Policy Priority MEMUSE TaskName - 16 1 Ready 0x3000 0x978 RR 31 0x8b0c init - 0 2 Pend 0x1000 0x1d4 RR 5 0 ResourcesTask - 2 2 Pend 0x4000 0x4ec RR 0 0 Swt_Task - 3 2 Pend 0x4000 0x1d4 RR 1 0 system_wq - 5 2 Pend 0x4000 0x1fc RR 9 0 SendToSer - 6 2 PendTime 0x6000 0x204 RR 5 0 tcpip_thread - 7 2 Pend 0x3000 0x1fc RR 5 0 sdmci_detect - 8 2 Pend 0x4000 0x204 RR 5 0 USB_GIANT_Task - 9 2 Pend 0x4000 0x204 RR 1 0 USB_NGIAN_ISOC_Task - 10 2 Pend 0x4000 0x204 RR 2 0 USB_NGIAN_BULK_Task - 11 2 Pend 0x4000 0x690 RR 5 0xbb0 USB_EXPLR_Task - 12 2 Pend 0x4000 0x204 RR 5 0 USB_CXFER_Task - 13 2 Pend 0x20000 0x1e4 RR 3 0xac20 eth_irq_Task - 14 2 Pend 0x4000 0x1d4 RR 10 0 jffs2_gc_thread - 15 2 Pend 0x2000 0x1f4 RR 4 0 hisi_frw - 4 3 Running 0x3000 0x838 RR 31 0x1100 shell - system memcheck over, all passed! - ``` - - 可以根据以上信息,分析用户态异常的具体原因。 - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/02.Trace.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/02.Trace.md" deleted file mode 100644 index e09457331cb1fa62e9779252a84d65c511ec22a6..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/02.Trace.md" +++ /dev/null @@ -1,526 +0,0 @@ ---- -title: Trace -permalink: /pages/010501020502 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# Trace调测 - -- [基本概念](#section1) - -- [运行机制](#section2) - -- [接口说明](#section3) - - - [内核态](#section3.1) - - - [用户态](#section3.2) - -- [开发指导](#section4) - - - [内核态开发流程](#section4.1.1) - - - [内核态编程实例](#section4.1.2) - - - [内核态实例代码](#section4.1.3) - - - [内核态结果验证](#section4.1.4) - - - [用户态开发流程](#section4.2.1) - - - [用户态编程实例](#section4.2.2) - - - [用户态实例代码](#section4.2.3) - - - [用户态结果验证](#section4.2.4) - -## 基本概念 -Trace调测旨在帮助开发者获取内核的运行流程,各个模块、任务的执行顺序,从而可以辅助开发者定位一些时序问题或者了解内核的代码运行过程。 - -## 运行机制 -内核提供一套Hook框架,将Hook点预埋在各个模块的主要流程中, 在内核启动初期完成Trace功能的初始化,并注册Trace的处理函数到Hook中。 - -当系统触发到一个Hook点时,Trace模块会对输入信息进行封装,添加Trace帧头信息,包含事件类型、运行的cpuid、运行的任务id、运行的相对时间戳等信息; - -Trace提供2种工作模式,离线模式和在线模式。 - -离线模式会将trace frame记录到预先申请好的循环buffer中。如果循环buffer记录的frame过多则可能出现翻转,会覆盖之前的记录,故保持记录的信息始终是最新的信息。Trace循环buffer的数据可以通过shell命令导出进行详细分析,导出信息已按照时间戳信息完成排序。 - -![](/images/device-dev/kernel/figure/zh-cn_image_0000001127390512.png) - -在线模式需要配合IDE使用,实时将trace frame记录发送给IDE,IDE端进行解析并可视化展示。 - -## 接口说明 - -### 内核态 - -OpenHarmony LiteOS-A内核的Trace模块提供下面几种功能,接口详细信息可以查看[API](https://gitee.com/openharmony/kernel_liteos_a/blob/master/kernel/include/los_trace.h)参考。 - -**表 1** Trace模块接口说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名

-

描述

-

启停控制

-

LOS_TraceStart

-

启动Trace

-

LOS_TraceStop

-

停止Trace

-

操作Trace记录的数据

-

LOS_TraceRecordDump

-

输出Trace缓冲区数据

-

LOS_TraceRecordGet

-

获取Trace缓冲区的首地址

-

LOS_TraceReset

-

清除Trace缓冲区中的事件

-

过滤Trace记录的数据

-

LOS_TraceEventMaskSet

-

设置事件掩码,仅记录某些模块的事件

-

屏蔽某些中断号事件

-

LOS_TraceHwiFilterHookReg

-

注册过滤特定中断号事件的钩子函数

-

插桩函数

-

LOS_TRACE_EASY

-

简易插桩

-

LOS_TRACE

-

标准插桩

-
- - -1. 当用户需要针对自定义事件进行追踪时,可按规则在目标源代码中进行插桩,系统提供如下2种插桩接口: - -+ LOS_TRACE_EASY(TYPE, IDENTITY, params...) 简易插桩。 - - - 一句话插桩,用户在目标源代码中插入该接口即可。 - - - TYPE有效取值范围为[0, 0xF],表示不同的事件类型,不同取值表示的含义由用户自定义。 - - - IDENTITY类型UINTPTR,表示事件操作的主体对象。 - - - Params类型UINTPTR,表示事件的参数。 - - - 示例: - - ``` - 假设需要新增对文件(fd1、fd2)读写操作的简易插桩, - 自定义读操作为type:1, 写操作为type:2,则 - 在读fd1文件的适当位置插入: - LOS_TRACE_EASY(1, fd1, flag, size); - 在读fd2文件的适当位置插入: - LOS_TRACE_EASY(1, fd2, flag, size); - 在写fd1文件的适当位置插入: - LOS_TRACE_EASY(2, fd1, flag, size); - 在写fd2文件的适当位置插入: - LOS_TRACE_EASY(2, fd2,flag, size); - ``` - -+ LOS_TRACE(TYPE, IDENTITY, params...) 标准插桩。 - - - 相比简易插桩,支持动态过滤事件和参数裁剪,但使用上需要用户按规则来扩展。 - - - TYPE用于设置具体的事件类型,可以在头文件los_trace.h中的enum LOS_TRACE_TYPE中自定义事件类型。定义方法和规则可以参考其他事件类型。 - - - IDENTITY和Params的类型及含义同简易插桩。 - - - 示例: -``` - 1.在enum LOS_TRACE_MASK中定义事件掩码,即模块级别的事件类型。 - 定义规范为TRACE_#MOD#_FLAG,#MOD#表示模块名,例如: - TRACE_FS_FLAG = 0x4000 - 2.在enum LOS_TRACE_TYPE中定义具体事件类型。定义规范为#TYPE# = TRACE_#MOD#_FLAG | NUMBER,例如: - FS_READ = TRACE_FS_FLAG | 0; // 读文件 - FS_WRITE = TRACE_FS_FLAG | 1; // 写文件 - 3.定义事件参数。定义规范为#TYPE#_PARAMS(IDENTITY, parma1...) IDENTITY, ... - 其中的#TYPE#就是上面2中的#TYPE#,例如: - #define FS_READ_PARAMS(fp, fd, flag, size) fp, fd, flag, size - 宏定义的参数对应于Trace缓冲区中记录的事件参数,用户可对任意参数字段进行裁剪: - 当定义为空时,表示不追踪该类型事件: - #define FS_READ_PARAMS(fp, fd, flag, size) // 不追踪文件读事件 - 4.在适当位置插入代码桩。定义规范为LOS_TRACE(#TYPE#, #TYPE#_PARAMS(IDENTITY, parma1...)) - LOS_TRACE(FS_READ, fp, fd, flag, size); // 读文件的代码桩, - #TYPE#之后的入参就是上面3中的FS_READ_PARAMS函数的入参 -``` -2. 预置的Trace事件及参数均可以通过上述方式进行裁剪,参数详见kernel\include\los_trace.h。 - -3. Trace Mask事件过滤接口LOS_TraceEventMaskSet(UINT32 mask),其入参mask仅高28位生效(对应LOS_TRACE_MASK中某模块的使能位),仅用于模块的过滤,暂不支持针对某个特定事件的细粒度过滤。例如:LOS_TraceEventMaskSet(0x202),则实际设置生效的mask为0x200(TRACE_QUE_FLAG),QUE模块的所有事件均会被采集。一般建议使用的方法为: - LOS_TraceEventMaskSet(TRACE_EVENT_FLAG | TRACE_MUX_FLAG | TRACE_SEM_FLAG | TRACE_QUE_FLAG); - -4. 如果仅需要过滤简易插桩事件,通过设置Trace Mask为TRACE_MAX_FLAG即可。 - -5. Trace缓冲区有限,事件写满之后会覆盖写,用户可通过LOS_TraceRecordDump中打印的CurEvtIndex识别最新记录。 - -6. Trace的典型操作流程为:LOS_TraceStart、 LOS_TraceStop、 LOS_TraceRecordDump. - -7. 针对中断事件的Trace, 提供中断号过滤,用于解决某些场景下特定中断号频繁触发导致其他事件被覆盖的情况,用户可自定义中断过滤的规则, - - 示例如下: -``` -BOOL Example_HwiNumFilter(UINT32 hwiNum) -{ - if ((hwiNum == TIMER_INT) || (hwiNum == DMA_INT)) { - return TRUE; - } - return FALSE; -} -LOS_TraceHwiFilterHookReg(Example_HwiNumFilter); -``` -则当中断号为TIMER_INT 或者DMA_INT时,不记录中断事件。 - -### 用户态 - -新增trace字符设备,位于"/dev/trace",通过对设备节点的read\write\ioctl,实现用户态trace的读写和控制: - -- read: 用户态读取Trace记录数据 - -- write: 用户态事件写入 - -- ioctl: 用户态Trace控制操作,包括 -```C -#define TRACE_IOC_MAGIC 'T' -#define TRACE_START _IO(TRACE_IOC_MAGIC, 1) -#define TRACE_STOP _IO(TRACE_IOC_MAGIC, 2) -#define TRACE_RESET _IO(TRACE_IOC_MAGIC, 3) -#define TRACE_DUMP _IO(TRACE_IOC_MAGIC, 4) -#define TRACE_SET_MASK _IO(TRACE_IOC_MAGIC, 5) -``` -分别对应Trace启动(LOS_TraceStart)、停止(LOS_TraceStop)、清除记录(LOS_TraceReset)、dump记录(LOS_TraceRecordDump)、设置事件过滤掩码(LOS_TraceEventMaskSet) - -具体的使用方法参见[用户态编程实例](#section4.2.2) - - - -## 开发指导 - -### 内核态开发流程 - -开启Trace调测的典型流程如下: - -1. 配置Trace模块相关宏。 - -配置Trace控制宏LOSCFG_KERNEL_TRACE,默认关,在kernel/liteos_a目录下执行 make update_config命令配置"Kernel->Enable Hook Feature->Enable Trace Feature"中打开: - -| 配置项 | menuconfig选项 | 含义 | 设置值 | -| ------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | ------ | -| LOSCFG_KERNEL_TRACE | Enable Trace Feature | Trace模块的裁剪开关 | YES/NO | -| LOSCFG_RECORDER_MODE_OFFLINE | Trace work mode ->Offline mode | Trace工作模式为离线模式 | YES/NO | -| LOSCFG_RECORDER_MODE_ONLINE | Trace work mode ->Online mode | Trace工作模式为在线模式 | YES/NO | -| LOSCFG_TRACE_CLIENT_INTERACT | Enable Trace Client Visualization and Control | 使能与Trace IDE (dev tools)的交互,包括数据可视化和流程控制 | YES/NO | -| LOSCFG_TRACE_FRAME_CORE_MSG | Enable Record more extended content ->Record cpuid, hardware interrupt status, task lock status | 记录CPUID、中断状态、锁任务状态 | YES/NO | -| LOSCFG_TRACE_FRAME_EVENT_COUNT | Enable Record more extended content ->Record event count, which indicate the sequence of happened events | 记录事件的次序编号 | YES/NO | -| LOSCFG_TRACE_FRAME_MAX_PARAMS | Record max params | 配置记录事件的最大参数个数 | INT | -| LOSCFG_TRACE_BUFFER_SIZE | Trace record buffer size | 配置Trace的缓冲区大小 | INT | - -2. (可选)预置事件参数和事件桩(或使用系统默认的事件参数配置和事件桩)。 - -3. (可选)调用LOS_TraceStop停止Trace后,清除缓冲区LOS_TraceReset(系统默认已启动trace)。 - -4. (可选)调用LOS_TraceEventMaskSet设置需要追踪的事件掩码(系统默认的事件掩码仅使能中断与任务事件),事件掩码参见los_trace.h 中的LOS_TRACE_MASK定义。 - -5. 在需要记录事件的代码起始点调用LOS_TraceStart。 - -6. 在需要记录事件的代码结束点调用LOS_TraceStop。 - -7. 调用LOS_TraceRecordDump输出缓冲区数据(函数的入参为布尔型,FALSE表示格式化输出,TRUE表示输出到Trace IDE)。 - - -上述第3-7步中的接口,均封装有对应的shell命令,开启shell后可执行相应的命令,对应关系如下: - -- LOS_TraceReset —— trace_reset - -- LOS_TraceEventMaskSet —— trace_mask - -- LOS_TraceStart —— trace_start - -- LOS_TraceStop —— trace_stop - -- LOS_TraceRecordDump —— trace_dump - -### 内核态编程实例 - - 本实例实现如下功能: - - 1. 创建一个用于Trace测试的任务。 - - 2. 设置事件掩码。 - - 3. 启动trace。 - - 4. 停止trace。 - - 5. 格式化输出trace数据。 - -### 内核态示例代码 - -实例代码如下: - -```C -#include "los_trace.h" -UINT32 g_traceTestTaskId; -VOID Example_Trace(VOID) -{ - UINT32 ret; - LOS_TaskDelay(10); - /* 开启trace */ - ret = LOS_TraceStart(); - if (ret != LOS_OK) { - dprintf("trace start error\n"); - return; - } - /* 触发任务切换的事件 */ - LOS_TaskDelay(1); - LOS_TaskDelay(1); - LOS_TaskDelay(1); - /* 停止trace */ - LOS_TraceStop(); - LOS_TraceRecordDump(FALSE); -} - -UINT32 Example_Trace_test(VOID){ - UINT32 ret; - TSK_INIT_PARAM_S traceTestTask; - /* 创建用于trace测试的任务 */ - memset(&traceTestTask, 0, sizeof(TSK_INIT_PARAM_S)); - traceTestTask.pfnTaskEntry = (TSK_ENTRY_FUNC)Example_Trace; - traceTestTask.pcName = "TestTraceTsk"; /* 测试任务名称 */ - traceTestTask.uwStackSize = 0x800; - traceTestTask.usTaskPrio = 5; - traceTestTask.uwResved = LOS_TASK_STATUS_DETACHED; - ret = LOS_TaskCreate(&g_traceTestTaskId, &traceTestTask); - if(ret != LOS_OK){ - dprintf("TraceTestTask create failed .\n"); - return LOS_NOK; - } - /* 系统默认情况下已启动trace, 因此可先关闭trace后清除缓存区后,再重启trace */ - LOS_TraceStop(); - LOS_TraceReset(); - /* 开启任务模块事件记录 */ - LOS_TraceEventMaskSet(TRACE_TASK_FLAG); - return LOS_OK; -} -LOS_MODULE_INIT(Example_Trace_test, LOS_INIT_LEVEL_KMOD_EXTENDED); -``` - -### 内核态结果验证 - -输出结果如下: - -```c -*******TraceInfo begin******* -clockFreq = 50000000 -CurEvtIndex = 7 -Index Time(cycles) EventType CurTask Identity params -0 0x366d5e88 0x45 0x1 0x0 0x1f 0x4 0x0 -1 0x366d74ae 0x45 0x0 0x1 0x0 0x8 0x1f -2 0x36940da6 0x45 0x1 0xc 0x1f 0x4 0x9 -3 0x3694337c 0x45 0xc 0x1 0x9 0x8 0x1f -4 0x36eea56e 0x45 0x1 0xc 0x1f 0x4 0x9 -5 0x36eec810 0x45 0xc 0x1 0x9 0x8 0x1f -6 0x3706f804 0x45 0x1 0x0 0x1f 0x4 0x0 -7 0x37070e59 0x45 0x0 0x1 0x0 0x8 0x1f -*******TraceInfo end******* -``` - -输出的事件信息包括:发生时间、事件类型、事件发生在哪个任务中、事件操作的主体对象、事件的其他参数。 - -- EventType:表示的具体事件可查阅头文件los_trace.h中的enum LOS_TRACE_TYPE。 - -- CurrentTask:表示当前运行在哪个任务中,值为taskid。 - -- Identity:表示事件操作的主体对象,可查阅头文件los_trace.h中的#TYPE#_PARAMS。 - -- params:表示的事件参数可查阅头文件los_trace.h中的#TYPE#_PARAMS。 - -下面以序号为0的输出项为例,进行说明。 - -``` -Index Time(cycles) EventType CurTask Identity params -0 0x366d5e88 0x45 0x1 0x0 0x1f 0x4 -``` - -- Time cycles可换算成时间,换算公式为cycles/clockFreq,单位为s。 - -- 0x45为TASK_SWITCH即任务切换事件,当前运行的任务taskid为0x1。 - -- Identity和params的含义需要查看TASK_SWITCH_PARAMS宏定义: - -```c -#define TASK_SWITCH_PARAMS(taskId, oldPriority, oldTaskStatus, newPriority, newTaskStatus) \ -taskId, oldPriority, oldTaskStatus, newPriority, newTaskStatus -``` - -因为#TYPE#_PARAMS(IDENTITY, parma1...) IDENTITY, ...,所以Identity为taskId(0x0),第一个参数为oldPriority(0x1f) - -> ![](/images/device-dev/public_sys-resources/icon-note.gif)**说明** - - > params的个数由menuconfig中Enable Trace Feature --> Record max params配置,默认为3,超出的参数不会被记录,用户应自行合理配置该值。 - - 综上所述,任务由0x1切换到0x0,0x1任务的优先级为0x1f,状态为0x4,0x0任务的优先级为0x0。 - -### 用户态开发流程 -通过在menuconfig配置"Driver->Enable TRACE DRIVER",开启Trace驱动。该配置仅在内核Enable Trace Feature后,才可在Driver的选项中可见。 -1. 打开“/dev/trace”字符文件,进行读写和IOCTL操作; -2. 系统提供用户态的trace命令,该命令位于/bin目录下,cd bin 后可执行如下命令: -- ./trace reset 清除Trace记录 - -- ./trace mask num 设置Trace事件过滤掩码 - -- ./trace start 启动Trace - -- ./trace stop 停止Trace - -- ./trace dump 0/1 格式化输出Trace记录 - -- ./trace read nBytes 读取Trace记录 - -- ./trace write type id params... 写用户态事件 - 如:./trace write 0x1 0x1001 0x2 0x3 则写入一条用户态事件,其事件类型为0x1, id为0x1001,参数有2个,分别是0x2和0x3. - - 用户态命令行的典型使用方法如下: - - ./trace start - - ./trace write 0x1 0x1001 0x2 0x3 - - ./trace stop - - ./trace dump 0 - -### 用户态编程实例 - - 本实例实现如下功能: - - 1. 打开trace字符设备。 - - 2. 设置事件掩码。 - - 3. 启动trace。 - - 4. 写trace事件。 - - 5. 停止trace。 - - 6. 格式化输出trace数据。 - -### 用户态示例代码 -实例代码如下 -```c -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define TRACE_IOC_MAGIC 'T' -#define TRACE_START _IO(TRACE_IOC_MAGIC, 1) -#define TRACE_STOP _IO(TRACE_IOC_MAGIC, 2) -#define TRACE_RESET _IO(TRACE_IOC_MAGIC, 3) -#define TRACE_DUMP _IO(TRACE_IOC_MAGIC, 4) -#define TRACE_SET_MASK _IO(TRACE_IOC_MAGIC, 5) -#define TRACE_USR_MAX_PARAMS 3 - -typedef struct { - unsigned int eventType; - uintptr_t identity; - uintptr_t params[TRACE_USR_MAX_PARAMS]; -} UsrEventInfo; - -int main(int argc, char **argv) -{ - size_t mask; - - int fd = open("/dev/trace", O_RDWR); - if (fd == -1) { - printf("Trace open failed.\n"); - exit(EXIT_FAILURE); - } - - ioctl(fd, TRACE_STOP, NULL); - ioctl(fd, TRACE_RESET, NULL); /* clear all events */ - - mask = 0x10000; /* filter kernel events */ - ioctl(fd, TRACE_SET_MASK, mask); - - ioctl(fd, TRACE_START, NULL); /* start trace */ - sleep(1); - - UsrEventInfo info = { - .eventType = 0x1, - .identity = 0x0001, - .params = {1, 2, 3}, - }; - (void)write(fd, &info, sizeof(UsrEventInfo)); - - info.eventType = 0x2; - info.identity = 0x0002; - (void)write(fd, &info, sizeof(UsrEventInfo)); - - ioctl(fd, TRACE_STOP, NULL); - ioctl(fd, TRACE_DUMP, 0); - - close(fd); - return 0; -} -``` -### 用户态结果验证 -输出结果如下: - -```c -*******TraceInfo begin******* -clockFreq = 50000000 -CurEvtIndex = 2 -Index Time(cycles) EventType CurTask Identity params -0 0x366d5e88 0xfffffff1 0x1 0x1 0x1 0x2 0x3 -1 0x366d74ae 0xfffffff2 0x1 0x2 0x1 0x2 0x3 -*******TraceInfo end******* -``` -示例代码中调用了2次write,对应产生2条Trace记录; -用户层事件的EventType高28位固定均为1(即0xfffffff0),仅低4位表示具体的事件类型。 \ No newline at end of file diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/03.Perf\350\260\203\346\265\213.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/03.Perf\350\260\203\346\265\213.md" deleted file mode 100644 index 3edce4c8c3ea9024e49934bf287bd87a33af4b01..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/03.Perf\350\260\203\346\265\213.md" +++ /dev/null @@ -1,519 +0,0 @@ ---- -title: Perf调测 -permalink: /pages/010501020503 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# Perf调测 - -- [基本概念](#section1) - -- [运行机制](#section2) - -- [接口说明](#section3) - - - [内核态](#section3.1) - - - [用户态](#section3.2) - -- [开发指导](#section4) - - - [内核态开发流程](#section4.1.1) - - - [内核态编程实例](#section4.1.2) - - - [内核态实例代码](#section4.1.3) - - - [内核态结果验证](#section4.1.4) - - - [用户态开发流程](#section4.2.1) - - - [用户态编程实例](#section4.2.2) - - - [用户态实例代码](#section4.2.3) - - - [用户态结果验证](#section4.2.4) - -## 基本概念 -Perf为性能分析工具,依赖PMU(Performance Monitoring Unit)对采样事件进行计数和上下文采集,统计出热点分布(hot spot)和热路径(hot path)。 - -## 运行机制 -基于事件采样原理,以性能事件为基础,当事件发生时,相应的事件计数器溢出发生中断,在中断处理函数中记录事件信息,包括当前的pc、当前运行的任务ID以及调用栈等信息。 - -Perf提供2种工作模式,计数模式和采样模式。 - -计数模式仅统计事件发生的次数和耗时,采样模式会收集上下文数据到环形buffer中,需要IDE进行数据解析生成热点函数与热点路径。 - -## 接口说明 - -### 内核态 - -OpenHarmony LiteOS-A内核的Perf模块提供下面几种功能,接口详细信息可以查看[API](https://gitee.com/openharmony/kernel_liteos_a/blob/master/kernel/include/los_perf.h)参考。 - -**表 1** Perf模块接口说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名

-

描述

-

开启/停止Perf采样

-

LOS_PerfStart

-

开启采样

-

LOS_PerfStop

-

停止采样

-

配置Perf采样事件

-

LOS_PerfConfig

-

配置采样事件的类型、周期等

-

读取采样数据

-

LOS_PerfDataRead

-

读取采样数据到指定地址

-

注册采样数据缓冲区的钩子函数

-

LOS_PerfNotifyHookReg

-

注册缓冲区水线到达的处理钩子

-

LOS_PerfFlushHookReg

-

注册缓冲区刷cache的钩子

-
- -1. Perf采样事件的结构体为PerfConfigAttr,详细字段含义及取值详见kernel\include\los_perf.h。 - -2. 采样数据缓冲区为环形buffer,buffer中读过的区域可以覆盖写,未被读过的区域不能被覆盖写。 - -3. 缓冲区有限,用户可通过注册水线到达的钩子进行buffer溢出提醒或buffer读操作。默认水线值为buffer总大小的1/2。 - 示例如下: - ```c - VOID Example_PerfNotifyHook(VOID) - { - CHAR buf[LOSCFG_PERF_BUFFER_SIZE] = {0}; - UINT32 len; - PRINT_DEBUG("perf buffer reach the waterline!\n"); - len = LOS_PerfDataRead(buf, LOSCFG_PERF_BUFFER_SIZE); - OsPrintBuff(buf, len); /* print data */ - } - LOS_PerfNotifyHookReg(Example_PerfNotifyHook); - ``` - -4. 若perf采样的buffer涉及到cpu 跨cache,则用户可通过注册刷cache的钩子,进行cache同步。 - 示例如下: - ```c - VOID Example_PerfFlushHook(VOID *addr, UINT32 size) - { - OsCacheFlush(addr, size); /* platform interface */ - } - LOS_PerfNotifyHookReg(Example_PerfFlushHook); - ``` - 刷cache接口视具体的平台自行配置。 - -### 用户态 - -新增perf字符设备,位于"/dev/perf",通过对设备节点的read\write\ioctl,实现用户态perf的读写和控制: - -- read: 用户态读取perf记录数据 - -- write: 用户态采样事件配置 - -- ioctl: 用户态Perf控制操作,包括 - ```C - #define PERF_IOC_MAGIC 'T' - #define PERF_START _IO(PERF_IOC_MAGIC, 1) - #define PERF_STOP _IO(PERF_IOC_MAGIC, 2) - ``` - 分别对应Perf启动(LOS_PerfStart)、停止(LOS_PerfStop) - -具体的使用方法参见[用户态编程实例](#section4.2.2) - - - -## 开发指导 - -### 内核态开发流程 - -开启Perf调测的典型流程如下: - -1. 配置Perf模块相关宏。 - - 配置Perf控制宏LOSCFG_KERNEL_PERF,默认关,在kernel/liteos_a目录下执行 make update_config命令配置"Kernel->Enable Perf Feature"中打开: - - | 配置项 | menuconfig选项 | 含义 | 设置值 | - | ------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | ------ | - | LOSCFG_KERNEL_PERF | Enable Perf Feature | Perf模块的裁剪开关 | YES/NO | - | LOSCFG_PERF_CALC_TIME_BY_TICK | Time-consuming Calc Methods->By Tick | Perf计时单位为tick | YES/NO | - | LOSCFG_PERF_CALC_TIME_BY_CYCLE | Time-consuming Calc Methods->By Cpu Cycle | Perf计时单位为cycle | YES/NO | - | LOSCFG_PERF_BUFFER_SIZE | Perf Sampling Buffer Size | Perf采样buffer的大小 | INT | - | LOSCFG_PERF_HW_PMU | Enable Hardware Pmu Events for Sampling | 使能硬件PMU事件,需要目标平台支持硬件PMU | YES/NO | - | LOSCFG_PERF_TIMED_PMU | Enable Hrtimer Period Events for Sampling | 使能高精度周期事件,需要目标平台支持高精度定时器 | YES/NO | - | LOSCFG_PERF_SW_PMU | Enable Software Events for Sampling | 使能软件事件,需要开启LOSCFG_KERNEL_HOOK | INT | - -2. 调用LOS_PerfConfig配置需要采样的事件。 - - Perf提供2种模式的配置,及3大类型的事件配置: - - 2种模式:计数模式(仅统计事件发生次数)、采样模式(收集上下文如任务ID、pc、backtrace等)。 - - 3种事件类型:CPU硬件事件(cycle、branch、icache、dcache等)、高精度周期事件(cpu clock)、OS软件事件(task switch、mux pend、irq等)。 - -3. 在需要采样的代码起始点调用LOS_PerfStart(UINT32 sectionId), 入参sectionId标记不同的采样回话id。 - -4. 在需要采样的代码结束点调用LOS_PerfStop。 - -5. 调用输出缓冲区数据的接口LOS_PerfDataRead读取采样数据,并使用IDE工具进行解析。 - - -### 内核态编程实例 - - 本实例实现如下功能: - - 1. 创建perf测试任务。 - - 2. 配置采样事件。 - - 3. 启动perf。 - - 4. 执行需要统计的算法。 - - 5. 停止perf。 - - 6. 输出统计结果。 - -### 内核态示例代码 - -前提条件:在menuconfig菜单中完成perf模块的配置。 - -实例代码如下: - -```C -#include "los_perf.h" -STATIC VOID OsPrintBuff(const CHAR *buf, UINT32 num) -{ - UINT32 i = 0; - PRINTK("num: "); - for (i = 0; i < num; i++) { - PRINTK(" %02d", i); - } - PRINTK("\n"); - PRINTK("hex: "); - for (i = 0; i < num; i++) { - PRINTK(" %02x", buf[i]); - } - PRINTK("\n"); -} - -STATIC VOID perfTestHwEvent(VOID) -{ - UINT32 ret; - CHAR *buf = NULL; - UINT32 len; - - PerfConfigAttr attr = { - .eventsCfg = { - .type = PERF_EVENT_TYPE_HW, - .events = { - [0] = {PERF_COUNT_HW_CPU_CYCLES, 0xFFFF}, - [1] = {PERF_COUNT_HW_BRANCH_INSTRUCTIONS, 0xFFFFFF00}, - }, - .eventsNr = 2, - .predivided = 1, /* cycle counter increase every 64 cycles */ - }, - .taskIds = {0}, - .taskIdsNr = 0, - .needSample = 0, - .sampleType = PERF_RECORD_IP | PERF_RECORD_CALLCHAIN, - }; - - ret = LOS_PerfConfig(&attr); - if (ret != LOS_OK) { - PRINT_ERR("perf config error %u\n", ret); - return; - } - - PRINTK("------count mode------\n"); - LOS_PerfStart(0); - test(); /* this is any test function*/ - LOS_PerfStop(); - - PRINTK("--------sample mode------ \n"); - attr.needSample = 1; - LOS_PerfConfig(&attr); - LOS_PerfStart(2); - test(); /* this is any test function*/ - LOS_PerfStop(); - - buf = LOS_MemAlloc(m_aucSysMem1, LOSCFG_PERF_BUFFER_SIZE); - if (buf == NULL) { - PRINT_ERR("buffer alloc failed\n"); - return; - } - - /* get sample data */ - len = LOS_PerfDataRead(buf, LOSCFG_PERF_BUFFER_SIZE); - OsPrintBuff(buf, len); /* print data */ - - (VOID)LOS_MemFree(m_aucSysMem1, buf); -} - -UINT32 Example_Perf_test(VOID){ - UINT32 ret; - TSK_INIT_PARAM_S perfTestTask; - /* 创建用于perf测试的任务 */ - memset(&perfTestTask, 0, sizeof(TSK_INIT_PARAM_S)); - perfTestTask.pfnTaskEntry = (TSK_ENTRY_FUNC)perfTestHwEvent; - perfTestTask.pcName = "TestPerfTsk"; /* 测试任务名称 */ - perfTestTask.uwStackSize = 0x800; - perfTestTask.usTaskPrio = 5; - perfTestTask.uwResved = LOS_TASK_STATUS_DETACHED; - ret = LOS_TaskCreate(&g_perfTestTaskId, &perfTestTask); - if(ret != LOS_OK){ - PRINT_ERR("PerfTestTask create failed.\n"); - return LOS_NOK; - } - return LOS_OK; -} -LOS_MODULE_INIT(perfTestHwEvent, LOS_INIT_LEVEL_KMOD_EXTENDED); -``` - -### 内核态结果验证 - -输出结果如下: - -```c ---------count mode---------- -[EMG] [cycles] eventType: 0xff: 5466989440 -[EMG] [branches] eventType: 0xc: 602166445 -------- sample mode---------- -[EMG] dump section data, addr: 0x8000000 length: 0x800000 -num: 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 ... -hex: 00 ef ef ef 00 00 00 00 14 00 00 00 60 00 00 00 00 00 00 00 70 88 36 40 08 00 00 00 6b 65 72 6e 65 6c 00 00 01 00 00 00 cc 55 30 40 08 00 00 00 6b 65 72 6e 65 6c 00 00 -``` - -- 针对计数模式,系统在perf stop后会打印: - - 事件名称(cycles)、事件类型(0xff)、事件发生的次数(5466989440)。 - - 当采样事件为硬件PMU事件时,打印的事件类型为实际的硬件事件id,非enum PmuHWId中定义的抽象类型。 - -- 针对采样模式,系统在perf stop后会打印采样数据的地址和长度: - - dump section data, addr: (0x8000000) length: (0x5000) - - 用户可以通过JTAG口导出该片内存,再使用IDE线下工具解析。 - - 或者通过LOS_PerfDataRead将数据读到指定地址,进行查看或进一步处理。示例中OsPrintBuff为测试接口,其按字节打印Read到的采样数据,num表示第几个字节,hex表示该字节中的数值。 - -### 用户态开发流程 -通过在menuconfig配置"Driver->Enable PERF DRIVER",开启Perf驱动。该配置仅在内核Enable Perf Feature后,才可在Driver的选项中可见。 -1. 打开“/dev/perf”字符文件,进行读写和IOCTL操作; -2. 系统提供用户态的perf命令,该命令位于/bin目录下,cd bin 后可执行如下命令: -- ./perf start [id] 启动perf采样, id 为可选项,默认值为0 - -- ./perf stop 停止perf采样 - -- ./perf read \ 从采样缓冲区中读取nBytes数据并打印内容 - -- ./perf list 罗列-e支持的具体事件 - -- ./perf stat/record [option] \ 计数/采样模式命令 - -option可选如下: - -- -e,配置采样事件。可使用./perf list 中罗列的同类型事件。 - -- -p,配置事件采样周期。 - -- -o, 指定perf采样数据结果保存的文件路径。 - -- -t,任务Id过滤(白名单),只采取指定任务中的上下文。如果不指定改参数,则默认采集所有的任务。 - -- -s, 配置采样的具体上下文类型,可查阅los_perf.h中定义的PerfSampleType。 - -- -P, 进程Id过滤(白名单),只采取指定进程中的上下文。如果不指定改参数,则默认采集所有进程。 - -- -d, 是否进行分频(事件每发生64次累计+1),该选项仅在硬件cycle事件上生效。 - -command 为待统计的子程序。 - -用户态命令行的典型使用方法如下: - -./perf list 查看可使用的事件列表, 输出如下: - -```c -cycles [Hardware event] -instruction [Hardware event] -dcache [Hardware event] -dcache-miss [Hardware event] -icache [Hardware event] -icache-miss [Hardware event] -branch [Hardware event] -branch-miss [Hardware event] -clock [Timed event] -task-switch [Software event] -irq-in [Software event] -mem-alloc [Software event] -mux-pend [Software event] -``` -./perf stat -e cycles os_dump, 输出如下: - -```c -type: 0 -events[0]: 255, 0xffff -predivided: 0 -sampleType: 0x0 -needSample: 0 -usage os_dump [--help | -l | SERVICE] - --help: shows this help - -l: only list services, do not dump them - SERVICE: dumps only service SERVICE -time used: 0.058000(s) -[cycles] eventType: 0xff [core 0]: 21720647 -[cycles] eventType: 0xff [core 1]: 13583830 -``` - -./perf record -e cycles os_dump, 输出如下: - -```c -type: 0 -events[0]: 255, 0xffff -predivided: 0 -sampleType: 0x60 -needSample: 1 -usage os_dump [--help | -l | SERVICE] - --help: shows this help - -l: only list services, do not dump them - SERVICE: dumps only service SERVICE -dump perf data, addr: 0x408643d8 length: 0x5000 -time used: 0.059000(s) -save perf data success at /storage/data/perf.data -``` -> ![](/images/device-dev/public_sys-resources/icon-note.gif)**说明** - - > 在进行./perf stat/record命令后,用户可多次执行./perf start 和 ./perf stop进行采样, 采样的事件配置为最近一次执行./perf stat/record 中设置的参数。 - -### 用户态编程实例 - - 本实例实现如下功能: - - 1. 打开perf字符设备。 - - 4. 写perf配置事件。 - - 3. 启动perf。 - - 5. 停止perf。 - - 6. 读取perf采样数据。 - -### 用户态示例代码 -实例代码如下 -```c -#include "fcntl.h" -#include "user_copy.h" -#include "sys/ioctl.h" -#include "fs/driver.h" -#include "los_dev_perf.h" -#include "los_perf.h" -#include "los_init.h" - -/* perf ioctl */ -#define PERF_IOC_MAGIC 'T' -#define PERF_START _IO(PERF_IOC_MAGIC, 1) -#define PERF_STOP _IO(PERF_IOC_MAGIC, 2) - -int main(int argc, char **argv) -{ - char *buf = NULL; - ssize_t len; - - int fd = open("/dev/perf", O_RDWR); - if (fd == -1) { - printf("Perf open failed.\n"); - exit(EXIT_FAILURE); - } - - PerfConfigAttr attr = { - .eventsCfg = { -#ifdef LOSCFG_PERF_HW_PMU - .type = PERF_EVENT_TYPE_HW, - .events = { - [0] = {PERF_COUNT_HW_CPU_CYCLES, 0xFFFF}, - }, -#elif defined LOSCFG_PERF_TIMED_PMU - .type = PERF_EVENT_TYPE_TIMED, - .events = { - [0] = {PERF_COUNT_CPU_CLOCK, 100}, - }, -#elif defined LOSCFG_PERF_SW_PMU - .type = PERF_EVENT_TYPE_SW, - .events = { - [0] = {PERF_COUNT_SW_TASK_SWITCH, 1}, - }, -#endif - .eventsNr = 1, /* 1 event */ - .predivided = 0, - }, - .taskIds = {0}, - .taskIdsNr = 0, - .processIds = {0}, - .processIdsNr = 0, - .needSample = 1, - .sampleType = PERF_RECORD_IP | PERF_RECORD_CALLCHAIN, - }; - (void)write(fd, &attr, sizeof(PerfConfigAttr)); /* perf config */ - - ioctl(fd, PERF_START, NULL); /* perf start */ - test(); - ioctl(fd, PERF_STOP, NULL); /* perf stop */ - - buf = (char *)malloc(LOSCFG_PERF_BUFFER_SIZE); - if (buf == NULL) { - printf("no memory for read perf 0x%x\n", LOSCFG_PERF_BUFFER_SIZE); - return -1; - } - - len = read(fd, buf, LOSCFG_PERF_BUFFER_SIZE); - OsPrintBuff(buf, len); /* print data */ - - free(buf); - close(fd); - return 0; -} -``` -### 用户态结果验证 -输出结果如下: - -```c -[EMG] dump section data, addr: 0x8000000 length: 0x800000 -num: 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 ... -hex: 00 ef ef ef 00 00 00 00 14 00 00 00 60 00 00 00 00 00 00 00 70 88 36 40 08 00 00 00 6b 65 72 6e 65 6c 00 00 01 00 00 00 cc 55 30 40 08 00 00 00 6b 65 72 6e 65 6c 00 00 -``` diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/04.LMS\350\260\203\346\265\213.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/04.LMS\350\260\203\346\265\213.md" deleted file mode 100644 index f18f98fe82ac1cb0cffead05b908459d5a9773f4..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/04.LMS\350\260\203\346\265\213.md" +++ /dev/null @@ -1,490 +0,0 @@ ---- -title: LMS调测 -permalink: /pages/010501020504 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# LMS调测 - -- [基本概念](#section1) - -- [运行机制](#section2) - -- [接口说明](#section3) - - - [内核态](#section3.1) - - - [用户态](#section3.2) - -- [开发指导](#section4) - - - [内核态开发流程](#section4.1.1) - - - [内核态编程实例](#section4.1.2) - - - [内核态实例代码](#section4.1.3) - - - [内核态结果验证](#section4.1.4) - - - [用户态开发流程](#section4.2.1) - - - [用户态编程实例](#section4.2.2) - - - [用户态实例代码](#section4.2.3) - - - [用户态结果验证](#section4.2.4) - -## 基本概念 -LMS全称为Lite Memory Sanitizer,是一种实时检测内存操作合法性的调测工具。LMS能够实时检测缓冲区溢出(buffer overflow),释放后使用(use after free) 和重复释放(double Free), 在异常发生的第一时间通知操作系统,结合backtrace等定位手段,能准确定位到产生内存问题的代码行,极大提升内存问题定位效率。 - -## 运行机制 -LMS使用影子内存映射标记系统内存的状态,一共可标记为三个状态:可读写,不可读写,已释放。影子内存存放在内存池的尾部。 - -- 内存从堆上申请后,会将数据区的影子内存设置为“可读写”状态,并将头结点区的影子内存设置为“不可读写”状态。 - -- 内存在堆上被释放时,会将被释放内存的影子内存设置为“已释放”状态。 - -- 编译代码时,会在代码中的读写指令前插入检测函数,对地址的合法性进行检验。主要是检测访问内存的影子内存的状态值,若检测到影子内存为不可读写,则会报溢出错误;若检测到影子内存为已释放,则会报释放后使用错误。 - -- 在内存释放时,会检测被释放地址的影子内存状态值,若检测到影子内存非可读写,则会报重复释放错误。 - -## 接口说明 - -### 内核态 - -OpenHarmony LiteOS-A内核的LMS模块提供下面几种功能,接口详细信息可以查看[API](https://gitee.com/openharmony/kernel_liteos_a/blob/master/kernel/include/los_lms.h)参考。 - - -1. 支持多内存池检测; - -2. 支持LOS_MemAlloc、LOS_MemAllocAlign、LOS_MemRealloc申请出的内存检测; - -3. 支持安全函数的访问检测(默认开启); - -4. 支持libc 高频函数的访问检测,包括:memset、memcpy、memmove、strcat、strcpy、strncat、strncpy。 - -5. 可动态设置的功能如下: - -**表 1** LMS模块接口说明 - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名

-

描述

-

添加指定内存池被检测

-

LOS_LmsCheckPoolAdd

-

将指定内存池的地址范围添加到LMS的内存检测链表上,当访问的地址在链表范围内时,LMS才进行合法性校验;且LOS_MemInit接口会调用该接口,默认将初始化的内存池挂入到检测链表中。

-

删除指定内存池不被检测

-

LOS_LmsCheckPoolDel

-

不检测指定内存池地址范围内的合法性校验。

-

使能指定内存段锁保护

-

LOS_LmsAddrProtect

-

为某段内存地址上锁,设置为不可读写,一旦访问则报错。

-

去能指定内存段锁保护

-

LOS_LmsAddrDisableProtect

-

为某段内存地址解锁,设置为可读写。

-
- - -### 用户态 - -用户态仅提供LMS检测库,不提供对外接口。 - -## 开发指导 - -### 内核态开发流程 - -开启LMS调测的典型流程如下: - -1. 配置LMS模块相关宏。 - - 配置LMS控制宏LOSCFG_KERNEL_LMS,默认关,在kernel/liteos_a目录下执行 make update_config命令配置"Kernel->Enable Lite Memory Sanitizer"中打开: - - | 配置项 | menuconfig选项 | 含义 | 设置值 | - | ------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | ------ | - | LOSCFG_KERNEL_LMS | Enable Lms Feature | Lms模块的裁剪开关 | YES/NO | - | LOSCFG_LMS_MAX_RECORD_POOL_NUM | Lms check pool max num | LMS支持的检测内存池最大个数 | INT | - | LOSCFG_LMS_LOAD_CHECK | Enable lms read check | LMS内存读检测的裁剪开关 | YES/NO | - | LOSCFG_LMS_STORE_CHECK | Enable lms write check | LMS内存写检测的裁剪开关 | YES/NO | - | LOSCFG_LMS_CHECK_STRICT | Enable lms strict check, byte-by-byte | LMS内存逐字节严格检测的裁剪开关 | YES/NO | - -2. 在被检测模块的编译脚本中,增加LMS检测编译选项-fsanitize=kernel-address。 - -3. 为避免编译器优化,增加-O0编译选项。 - -4. gcc与clang编译选项存在差异,参照如下示例: - - ``` - if ("$ohos_build_compiler_specified" == "gcc") { - cflags_c = [ - "-O0", - "-fsanitize=kernel-address", - ] - } else { - cflags_c = [ - "-O0", - "-fsanitize=kernel-address", - "-mllvm", - "-asan-instrumentation-with-call-threshold=0", - "-mllvm", - "-asan-stack=0", - "-mllvm", - "-asan-globals=0", - ] - } - ``` - -5. 重新编译,查看串口输出。如果检测到内存问题,会输出检测结果。 - -### 内核态编程实例 - - 本实例实现如下功能: - - 1. 创建一个用于Lms测试的任务。 - - 2. 构造内存溢出错误和释放后使用错误。 - - 3. 添加-fsanitize=kernel-address后编译执行,观察输出结果 - -### 内核态示例代码 - -实例代码如下: - -```C -#define PAGE_SIZE (0x1000U) -#define INDEX_MAX 20 - -UINT32 g_lmsTestTaskId; -char g_testLmsPool[2 * PAGE_SIZE]; - -STATIC VOID testPoolInit(void) -{ - UINT32 ret = LOS_MemInit(g_testLmsPool, 2 * PAGE_SIZE); - if (ret != 0) { - PRINT_ERR("%s failed, ret = 0x%x\n", __FUNCTION__, ret); - return; - } -} - -static VOID LmsTestOsmallocOverflow(VOID) -{ - PRINTK("\n######%s start ######\n", __FUNCTION__); - UINT32 i; - CHAR *str = (CHAR *)LOS_MemAlloc(g_testLmsPool, INDEX_MAX); - PRINTK("str[%2d]=0x%2x ", INDEX_MAX, str[INDEX_MAX]); /* trigger heap overflow at str[INDEX_MAX] */ - PRINTK("\n######%s stop ######\n", __FUNCTION__); -} - -static VOID LmsTestUseAfterFree(VOID) -{ - PRINTK("\n######%s start ######\n", __FUNCTION__); - UINT32 i; - CHAR *str = (CHAR *)LOS_MemAlloc(g_testLmsPool, INDEX_MAX); - LOS_MemFree(g_testLmsPool, str); - PRINTK("str[%2d]=0x%2x ", 0, str[0]); /* trigger use after free at str[0] */ - PRINTK("\n######%s stop ######\n", __FUNCTION__); -} - -VOID LmsTestCaseTask(VOID) -{ - testPoolInit(); - LmsTestOsmallocOverflow(); - LmsTestUseAfterFree(); -} - -UINT32 Example_Lms_test(VOID){ - UINT32 ret; - TSK_INIT_PARAM_S lmsTestTask; - /* 创建用于lms测试的任务 */ - memset(&lmsTestTask, 0, sizeof(TSK_INIT_PARAM_S)); - lmsTestTask.pfnTaskEntry = (TSK_ENTRY_FUNC)LmsTestCaseTask; - lmsTestTask.pcName = "TestLmsTsk"; /* 测试任务名称 */ - lmsTestTask.uwStackSize = 0x800; - lmsTestTask.usTaskPrio = 5; - lmsTestTask.uwResved = LOS_TASK_STATUS_DETACHED; - ret = LOS_TaskCreate(&g_lmsTestTaskId, &lmsTestTask); - if(ret != LOS_OK){ - PRINT_ERR("LmsTestTask create failed .\n"); - return LOS_NOK; - } - return LOS_OK; -} -LOS_MODULE_INIT(Example_Lms_test, LOS_INIT_LEVEL_KMOD_EXTENDED); -``` - -### 内核态结果验证 - -输出结果如下: - -```c -######LmsTestOsmallocOverflow start ###### -[ERR][KProcess:LmsTestCaseTask]***** Kernel Address Sanitizer Error Detected Start ***** -[ERR][KProcess:LmsTestCaseTask]Heap buffer overflow error detected -[ERR][KProcess:LmsTestCaseTask]Illegal READ address at: [0x4157a3c8] -[ERR][KProcess:LmsTestCaseTask]Shadow memory address: [0x4157be3c : 4] Shadow memory value: [2] -OsBackTrace fp = 0x402c0f88 -runTask->taskName = LmsTestCaseTask -runTask->taskID = 2 -*******backtrace begin******* -traceback fp fixed, trace using fp = 0x402c0fd0 -traceback 0 -- lr = 0x400655a4 fp = 0x402c0ff8 -traceback 1 -- lr = 0x40065754 fp = 0x402c1010 -traceback 2 -- lr = 0x40044bd0 fp = 0x402c1038 -traceback 3 -- lr = 0x40004e14 fp = 0xcacacaca - -[LMS] Dump info around address [0x4157a3c8]: - - [0x4157a3a0]: 00 00 00 00 00 00 00 00 | [0x4157be3a | 0]: 1 1 - [0x4157a3a8]: ba dc cd ab 00 00 00 00 | [0x4157be3a | 4]: 2 2 - [0x4157a3b0]: 20 00 00 80 00 00 00 00 | [0x4157be3b | 0]: 2 0 - [0x4157a3b8]: 00 00 00 00 00 00 00 00 | [0x4157be3b | 4]: 0 0 - [0x4157a3c0]: 00 00 00 00 00 00 00 00 | [0x4157be3c | 0]: 0 0 - [0x4157a3c8]: [ba] dc cd ab a8 a3 57 41 | [0x4157be3c | 4]: [2] 2 - [0x4157a3d0]: 2c 1a 00 00 00 00 00 00 | [0x4157be3d | 0]: 2 3 - [0x4157a3d8]: 00 00 00 00 00 00 00 00 | [0x4157be3d | 4]: 3 3 - [0x4157a3e0]: 00 00 00 00 00 00 00 00 | [0x4157be3e | 0]: 3 3 - [0x4157a3e8]: 00 00 00 00 00 00 00 00 | [0x4157be3e | 4]: 3 3 - [0x4157a3f0]: 00 00 00 00 00 00 00 00 | [0x4157be3f | 0]: 3 3 -[ERR][KProcess:LmsTestCaseTask]***** Kernel Address Sanitizer Error Detected End ***** -str[20]=0xffffffba -######LmsTestOsmallocOverflow stop ###### - -###### LmsTestUseAfterFree start ###### -[ERR][KProcess:LmsTestCaseTask]***** Kernel Address Sanitizer Error Detected Start ***** -[ERR][KProcess:LmsTestCaseTask]Use after free error detected -[ERR][KProcess:LmsTestCaseTask]Illegal READ address at: [0x4157a3d4] -[ERR][KProcess:LmsTestCaseTask]Shadow memory address: [0x4157be3d : 2] Shadow memory value: [3] -OsBackTrace fp = 0x402c0f90 -runTask->taskName = LmsTestCaseTask -runTask->taskID = 2 -*******backtrace begin******* -traceback fp fixed, trace using fp = 0x402c0fd8 -traceback 0 -- lr = 0x40065680 fp = 0x402c0ff8 -traceback 1 -- lr = 0x40065758 fp = 0x402c1010 -traceback 2 -- lr = 0x40044bd0 fp = 0x402c1038 -traceback 3 -- lr = 0x40004e14 fp = 0xcacacaca - -[LMS] Dump info around address [0x4157a3d4]: - - [0x4157a3a8]: ba dc cd ab 00 00 00 00 | [0x4157be3a | 4]: 2 2 - [0x4157a3b0]: 20 00 00 80 00 00 00 00 | [0x4157be3b | 0]: 2 0 - [0x4157a3b8]: 00 00 00 00 00 00 00 00 | [0x4157be3b | 4]: 0 0 - [0x4157a3c0]: 00 00 00 00 00 00 00 00 | [0x4157be3c | 0]: 0 0 - [0x4157a3c8]: ba dc cd ab a8 a3 57 41 | [0x4157be3c | 4]: 2 2 - [0x4157a3d0]: 2c 1a 00 00 [00] 00 00 00 | [0x4157be3d | 0]: 2 [3] - [0x4157a3d8]: 00 00 00 00 00 00 00 00 | [0x4157be3d | 4]: 3 3 - [0x4157a3e0]: 00 00 00 00 00 00 00 00 | [0x4157be3e | 0]: 3 3 - [0x4157a3e8]: ba dc cd ab c8 a3 57 41 | [0x4157be3e | 4]: 2 2 - [0x4157a3f0]: 0c 1a 00 00 00 00 00 00 | [0x4157be3f | 0]: 2 3 - [0x4157a3f8]: 00 00 00 00 00 00 00 00 | [0x4157be3f | 4]: 3 3 -[ERR][KProcess:LmsTestCaseTask]***** Kernel Address Sanitizer Error Detected End ***** -str[ 0]=0x 0 -######LmsTestUseAfterFree stop ###### -``` -输出的关键信息包括: -- 错误类型: - - Heap buffer overflow堆内存越界 - - Use after free 释放后使用 -- 错误操作: - - Illegal Read非法读 - - Illegal Write非法写 - - Illegal Double free重复释放 -- 上下文: - - 当前任务信息(taskName, taskId) - - 回溯栈(backtrace) -- 出错地址的内存信息: - - 内存的值、及对应影子内存的值 - - 内存地址:内存值| [影子内存地址 | 影子内存字节内偏移]:影子内存值 - - 影子内存值:0(可读可写)、3(已释放)、2(红区)、1(填充值)。 - - -### 用户态开发流程 -在待检测的app编译脚本中,添加如下参数即可, 完整示例可参见/kernel/liteos_a/apps/lms/BUILD.gn -``` -if ("$ohos_build_compiler_specified" == "gcc") { - cflags_c = [ - "-O0", - "-fsanitize=kernel-address", - "-funwind-tables", - "-fasynchronous-unwind-tables", - ] - } else { - cflags_c = [ - "-O0", - "-fsanitize=kernel-address", - "-mllvm", - "-asan-instrumentation-with-call-threshold=0", - "-mllvm", - "-asan-stack=0", - "-mllvm", - "-asan-globals=0", - "-funwind-tables", - "-fasynchronous-unwind-tables", - ] - } - ldflags = [ - "-rdynamic", - "-lunwind", - "-lusrlms", - "-Wl,--wrap=realloc", - "-Wl,--wrap=calloc", - "-Wl,--wrap=malloc", - "-Wl,--wrap=free", - "-Wl,--wrap=valloc", - "-Wl,--wrap=aligned_alloc", - "-Wl,--wrap=memset", - "-Wl,--wrap=memcpy", - "-Wl,--wrap=memmove", - "-Wl,--wrap=strcpy", - "-Wl,--wrap=strcat", - ] - deps = [ "//kernel/liteos_a/kernel/extended/lms/usr:usrlmslib" ] - ``` - -### 用户态编程实例 - - 本实例实现如下功能: - - 1. 构造内存溢出错误和释放后使用错误。 - - 2. 添加对应编译选项后,重新编译执行 - -### 用户态示例代码 -实例代码如下 -```c -static void BufWriteTest(void *buf, int start, int end) -{ - for (int i = start; i <= end; i++) { - ((char *)buf)[i] = 'a'; - } -} - -static void BufReadTest(void *buf, int start, int end) -{ - char tmp; - for (int i = start; i <= end; i++) { - tmp = ((char *)buf)[i]; - } -} - -static void LmsMallocTest(void) -{ - printf("\n-------- LmsMallocTest Start --------\n"); - char *buf = (char *)malloc(16); - BufReadTest(buf, -1, 16); - free(buf); - printf("\n-------- LmsMallocTest End --------\n"); -} - -static void LmsFreeTest(void) -{ - printf("\n-------- LmsFreeTest Start --------\n"); - char *buf = (char *)malloc(16); - free(buf); - BufReadTest(buf, 1, 1); - free(buf); - printf("\n-------- LmsFreeTest End --------\n"); -} - -int main(int argc, char * const * argv) -{ - printf("\n############### Lms Test start ###############\n"); - char *tmp = (char *)malloc(5000); - LmsMallocTest(); - LmsFreeTest(); - printf("\n############### Lms Test End ###############\n"); -} -``` -### 用户态结果验证 -输出结果如下: - -```c -***** Lite Memory Sanitizer Error Detected ***** -Heap buffer overflow error detected! -Illegal READ address at: [0x1f8b3edf] -Shadow memory address: [0x3d34d3ed : 6] Shadow memory value: [2] - -Accessable heap addr 0 -Heap red zone 2 -Heap freed buffer 3 - -Dump info around address [0x1f8b3edf]: - - [0x1f8b3eb8]: 74 55 8b 1f 74 55 8b 1f | [0x3d34d3eb | 4]: 0 0 - [0x1f8b3ec0]: f8 9c 8b 1f 00 00 00 00 | [0x3d34d3ec | 0]: 0 0 - [0x1f8b3ec8]: 00 00 00 00 9c fc fc fc | [0x3d34d3ec | 4]: 0 0 - [0x1f8b3ed0]: 21 00 00 00 41 00 00 00 | [0x3d34d3ed | 0]: 0 0 - [0x1f8b3ed8]: 60 55 8b 1f 60 55 8b [1f]| [0x3d34d3ed | 4]: 2 [2] - [0x1f8b3ee0]: 50 4e 0b 00 00 00 00 00 | [0x3d34d3ee | 0]: 0 0 - [0x1f8b3ee8]: 09 00 00 00 00 00 00 00 | [0x3d34d3ee | 4]: 0 0 - [0x1f8b3ef0]: 00 00 00 00 08 03 09 00 | [0x3d34d3ef | 0]: 2 2 - [0x1f8b3ef8]: 00 00 00 00 00 00 00 00 | [0x3d34d3ef | 4]: 2 2 -***** Lite Memory Sanitizer Error Detected End ***** - -Backtrace() returned 5 addresses - #01: [0x4d6c] -> ./sample_usr_lms - #02: <(null)+0x2004074>[0x4074] -> ./sample_usr_lms - #03: <(null)+0x2003714>[0x3714] -> ./sample_usr_lms - #04: [0x363c] -> ./sample_usr_lms - #05: <(null)+0x1f856f30>[0x56f30] -> /lib/libc.so --------- LMS_malloc_test End -------- - -***** Lite Memory Sanitizer Error Detected ***** -Use after free error detected! -Illegal Double free address at: [0x1f8b3ee0] -Shadow memory address: [0x3d34d3ee : 0] Shadow memory value: [3] - -Accessable heap addr 0 -Heap red zone 2 -Heap freed buffer 3 - - -Dump info around address [0x1f8b3ee0]: - - [0x1f8b3ec0]: f8 9c 8b 1f 00 00 00 00 | [0x3d34d3ec | 0]: 0 0 - [0x1f8b3ec8]: 00 00 00 00 fc fd fc fc | [0x3d34d3ec | 4]: 0 0 - [0x1f8b3ed0]: 21 00 00 00 20 01 00 00 | [0x3d34d3ed | 0]: 0 0 - [0x1f8b3ed8]: 60 55 8b 1f 60 55 8b 1f | [0x3d34d3ed | 4]: 2 2 - [0x1f8b3ee0]: [20] 60 9a 1f 40 61 9a 1f | [0x3d34d3ee | 0]: [3] 3 - [0x1f8b3ee8]: 60 62 9a 1f 80 63 9a 1f | [0x3d34d3ee | 4]: 3 3 - [0x1f8b3ef0]: 20 40 8b 1f 20 20 8b 1f | [0x3d34d3ef | 0]: 3 3 - [0x1f8b3ef8]: 00 00 00 00 00 00 00 00 | [0x3d34d3ef | 4]: 3 3 - [0x1f8b3f00]: 00 00 00 00 00 00 00 00 | [0x3d34d3f0 | 0]: 3 3 -***** Lite Memory Sanitizer Error Detected End ***** - -Backtrace() returned 5 addresses - #01: [0x4d6c] -> ./sample_usr_lms - #02: [0x5548] -> ./sample_usr_lms - #03: <(null)+0x2003fc4>[0x3fc4] -> ./sample_usr_lms - #04: [0x3664] -> ./sample_usr_lms - #05: <(null)+0x1f856f30>[0x56f30] -> /lib/libc.so - --------- LMS_free_test End -------- -``` -输出的Backtrace中包含地址所在的文件名,用户需查找对应文件中地址对应的代码行号。 diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/05.\350\277\233\347\250\213\350\260\203\346\265\213/01.CPU\345\215\240\347\224\250\347\216\207.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/05.\350\277\233\347\250\213\350\260\203\346\265\213/01.CPU\345\215\240\347\224\250\347\216\207.md" deleted file mode 100644 index fba5870d091025a18fbc0884f27ce5cea116fd61..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/05.\350\277\233\347\250\213\350\260\203\346\265\213/01.CPU\345\215\240\347\224\250\347\216\207.md" +++ /dev/null @@ -1,208 +0,0 @@ ---- -title: CPU占用率 -permalink: /pages/01050102050501 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# CPU占用率 - -- [基本概念](#section17683419227) -- [运行机制](#section593718536227) -- [开发指导](#section11284210152311) - - [接口说明](#section3745151592312) - - [开发流程](#section122901429182316) - - [编程实例](#section1765785212310) - - -## 基本概念 - -CPU(中央处理器,Central Processing Unit)占用率分为系统CPU占用率、进程CPU占用率、任务CPU占用率和中断CPU占用率。用户通过系统级的CPU占用率,判断当前系统负载是否超出设计规格。通过系统中各个进程/任务/中断的CPU占用情况,判断各个进程/任务/中断的CPU占用率是否符合设计的预期。 - -- 系统CPU占用率(CPU Percent) - - 指周期时间内系统的CPU占用率,用于表示系统一段时间内的闲忙程度,也表示CPU的负载情况。系统CPU占用率的有效表示范围为0~100,其精度(可通过配置调整)为百分比。100表示系统满负荷运转。 - -- 进程CPU占用率 - - 指单个进程的CPU占用率,用于表示单个进程在一段时间内的闲忙程度。进程CPU占用率的有效表示范围为0~100,其精度(可通过配置调整)为百分比。100表示在一段时间内系统一直在运行该进程。 - -- 任务CPU占用率 - - 指单个任务的CPU占用率,用于表示单个任务在一段时间内的闲忙程度。任务CPU占用率的有效表示范围为0~100,其精度(可通过配置调整)为百分比。100表示在一段时间内系统一直在运行该任务。 - -- 中断CPU占用率 - - 指单个中断的CPU占用率,用于表示单个中断在一段时间内的闲忙程度。中断CPU占用率的有效表示范围为0~100,其精度(可通过配置调整)为百分比。100表示在一段时间内系统一直在运行该中断。 - - -## 运行机制 - -OpenHarmony LiteOS-A内核CPUP(CPU Percent,CPU占用率)模块采用进程、任务和中断级记录的方式,在进程/任务切换时,记录进程/任务启动时间,进程/任务切出或者退出时,系统会累加整个进程/任务的占用时间; 在执行中断时系统会累加记录每个中断的执行时间。 - -OpenHarmony 提供以下四种CPU占用率的信息查询: - -- 系统CPU占用率 -- 进程CPU占用率 -- 任务CPU占用率 -- 中断CPU占用率 - -**CPU占用率的计算方法:** - -系统CPU占用率=系统中除idle任务外其他任务运行总时间/系统运行总时间 - -进程CPU占用率=进程运行总时间/系统运行总时间 - -任务CPU占用率=任务运行总时间/系统运行总时间 - -中断CPU占用率=中断运行总时间/系统运行总时间 - -## 开发指导 - -### 接口说明 - -**表 1** CPUP模块接口 - - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名称

-

描述

-

系统CPU占用率

-

LOS_HistorySysCpuUsage

-

获取系统历史CPU占用率

-

进程CPU占用率

-

LOS_HistoryProcessCpuUsage

-

获取指定进程历史CPU占用率

-

LOS_GetAllProcessCpuUsage

-

获取系统所有进程的历史CPU占用率

-

任务CPU占用率

-

LOS_HistoryTaskCpuUsage

-

获取指定任务历史CPU占用率

-

中断CPU占用率

-

LOS_GetAllIrqCpuUsage

-

获取系统所有中断的历史CPU占用率

-
- -### 开发流程 - -CPU占用率的典型开发流程: - -1. 调用获取系统历史CPU占用率函数LOS\_HistorySysCpuUsage。 -2. 调用获取指定进程历史CPU占用率函数LOS\_HistoryProcessCpuUsage。 - - 若进程已创建,则关中断,根据不同模式正常获取,恢复中断; - - 若进程未创建,则返回错误码; - -3. 调用获取所有进程CPU占用率函数LOS\_GetAllProcessCpuUsage。 - - 若CPUP已初始化,则关中断,根据不同模式正常获取,恢复中断; - - 若CPUP未初始化或有非法入参,则返回错误码; - -4. 调用获取指定任务历史CPU占用率函数LOS\_HistoryTaskCpuUsage。 - - 若任务已创建,则关中断,根据不同模式正常获取,恢复中断; - - 若任务未创建,则返回错误码; - -5. 调用获取所有中断CPU占用率函数LOS\_GetAllIrqCpuUsage。 - - 若CPUP已初始化,则关中断,根据不同模式正常获取,恢复中断; - - 若CPUP未初始化或有非法入参,则返回错误码; - - -### 编程实例 - -本实例实现如下功能: - -1. 创建一个用于CPUP测试的任务。 -2. 获取当前系统CPUP。 -3. 以不同模式获取历史系统CPUP。 -4. 获取创建的测试任务的CPUP。 -5. 以不同模式获取创建的测试任务的CPUP。 - -前提条件: - -在menuconfig 配置中打开cpup控制开关。 - -**示例代码** - -代码实现如下: - -``` -#include "los_task.h" -#include "los_cpup.h" -#define MODE 4 -UINT32 g_cpuTestTaskID; -VOID ExampleCpup(VOID) -{ - printf("entry cpup test example\n"); - while(1) { - usleep(100); - } -} -UINT32 ItCpupTest(VOID) -{ - UINT32 ret; - UINT32 cpupUse; - TSK_INIT_PARAM_S cpupTestTask = { 0 }; - memset(&cpupTestTask, 0, sizeof(TSK_INIT_PARAM_S)); - cpupTestTask.pfnTaskEntry = (TSK_ENTRY_FUNC)ExampleCpup; - cpupTestTask.pcName = "TestCpupTsk"; - cpupTestTask.uwStackSize = 0x800; - cpupTestTask.usTaskPrio = 5; - ret = LOS_TaskCreate(&g_cpuTestTaskID, &cpupTestTask); - if(ret != LOS_OK) { - printf("cpupTestTask create failed .\n"); - return LOS_NOK; - } - - usleep(100); - - /* 获取当前系统历史cpu占用率 */ - cpupUse = LOS_HistorySysCpuUsage(CPU_LESS_THAN_1S); - printf("the history system cpu usage in all time:%u.%u\n", - cpupUse / LOS_CPUP_PRECISION_MULT, cpupUse % LOS_CPUP_PRECISION_MULT); - /* 获取指定任务的cpu占用率,该测试例程中指定的任务为以上创建的cpup测试任务 */ - cpupUse = LOS_HistoryTaskCpuUsage(g_cpuTestTaskID, CPU_LESS_THAN_1S); - printf("cpu usage of the cpupTestTask in all time:\n TaskID: %d\n usage: %u.%u\n", - g_cpuTestTaskID, cpupUse / LOS_CPUP_PRECISION_MULT, cpupUse % LOS_CPUP_PRECISION_MULT); - return LOS_OK; -} -``` - -**结果验证** - -编译运行得到的结果为: - -``` -entry cpup test example -the history system cpu usage in all time: 3.0 -cpu usage of the cpupTestTask in all time: TaskID:10 usage: 0.0 -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/06.\345\206\205\345\255\230\350\260\203\346\265\213/01.\345\206\205\345\255\230\344\277\241\346\201\257\347\273\237\350\256\241.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/06.\345\206\205\345\255\230\350\260\203\346\265\213/01.\345\206\205\345\255\230\344\277\241\346\201\257\347\273\237\350\256\241.md" deleted file mode 100644 index 0267224c19850a166b639aefbda119eaf99f339c..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/06.\345\206\205\345\255\230\350\260\203\346\265\213/01.\345\206\205\345\255\230\344\277\241\346\201\257\347\273\237\350\256\241.md" +++ /dev/null @@ -1,119 +0,0 @@ ---- -title: 内存信息统计 -permalink: /pages/01050102050601 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# 内存信息统计 - -- [基础概念](#section52691565235) -- [功能配置](#section470611682411) -- [开发指导](#section9368374243) - - [开发流程](#section679912407257) - - [编程实例](#section1025453412611) - - -## 基础概念 - -内存信息包括内存池大小、内存使用量、剩余内存大小、最大空闲内存、内存水线、内存节点数统计、碎片率等。 - -- 内存水线:即内存池的最大使用量,每次申请和释放时,都会更新水线值,实际业务可根据该值,优化内存池大小; - -- 碎片率:衡量内存池的碎片化程度,碎片率高表现为内存池剩余内存很多,但是最大空闲内存块很小,可以用公式(fragment=100-100\*最大空闲内存块大小/剩余内存大小)来度量 - -- 其他统计信息:调用接口LOS\_MemInfoGet时,会扫描内存池的节点信息,统计出相关信息。 - -## 功能配置 - -LOSCFG\_MEM\_WATERLINE:开关宏,默认关闭;若需要打开这个功能,可以在配置项中开启“Debug-\> Enable memory pool waterline or not”。如需获取内存水线,需要打开该配置。 - -## 开发指导 - -### 开发流程 - -关键结构体介绍: - -``` -typedef struct { - UINT32 totalUsedSize; // 内存池的内存使用量 - UINT32 totalFreeSize; // 内存池的剩余内存大小 - UINT32 maxFreeNodeSize; // 内存池的最大空闲内存块大小 - UINT32 usedNodeNum; // 内存池的非空闲内存块个数 - UINT32 freeNodeNum; // 内存池的空闲内存块个数 -#if (LOSCFG_MEM_WATERLINE == 1) // 默认关闭,可以通过menuconfig配置工具打开 - UINT32 usageWaterLine; // 内存池的水线值 -#endif -} LOS_MEM_POOL_STATUS; -``` - -- 内存水线获取:调用LOS\_MemInfoGet接口,第1个参数是内存池首地址,第2个参数是LOS\_MEM\_POOL\_STATUS类型的句柄,其中字段usageWaterLine即水线值。 - -- 内存碎片率计算:同样调用LOS\_MemInfoGet接口,可以获取内存池的剩余内存大小和最大空闲内存块大小,然后根据公式(fragment=100-100\*最大空闲内存块大小/剩余内存大小)得出此时的动态内存池碎片率。 - -### 编程实例 - -本实例实现如下功能: - -1. 创建一个监控任务,用于获取内存池的信息; -2. 调用LOS\_MemInfoGet接口,获取内存池的基础信息; -3. 利用公式算出使用率及碎片率。 - -**示例代码** - -代码实现如下: - -``` -#include -#include -#include "los_task.h" -#include "los_memory.h" -#include "los_config.h" - -void MemInfoTaskFunc(void) -{ - LOS_MEM_POOL_STATUS poolStatus = {0}; - - /* pool为要统计信息的内存地址,此处以OS_SYS_MEM_ADDR为例 */ - void *pool = OS_SYS_MEM_ADDR; - LOS_MemInfoGet(pool, &poolStatus); - /* 算出内存池当前的碎片率百分比 */ - unsigned char fragment = 100 - poolStatus.maxFreeNodeSize * 100 / poolStatus.totalFreeSize; - /* 算出内存池当前的使用率百分比 */ - unsigned char usage = LOS_MemTotalUsedGet(pool) * 100 / LOS_MemPoolSizeGet(pool); - printf("usage = %d, fragment = %d, maxFreeSize = %d, totalFreeSize = %d, waterLine = %d\n", usage, fragment, poolStatus.maxFreeNodeSize, - poolStatus.totalFreeSize, poolStatus.usageWaterLine); -} - -int MemTest(void) -{ - unsigned int ret; - unsigned int taskID; - TSK_INIT_PARAM_S taskStatus = {0}; - taskStatus.pfnTaskEntry = (TSK_ENTRY_FUNC)MemInfoTaskFunc; - taskStatus.uwStackSize = 0x1000; - taskStatus.pcName = "memInfo"; - taskStatus.usTaskPrio = 10; - ret = LOS_TaskCreate(&taskID, &taskStatus); - if (ret != LOS_OK) { - printf("task create failed\n"); - return -1; - } - return 0; -} -``` - -**结果验证** - -编译运行输出的结果如下: - -``` -usage = 22, fragment = 3, maxFreeSize = 49056, totalFreeSize = 50132, waterLine = 1414 -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/06.\345\206\205\345\255\230\350\260\203\346\265\213/02.\345\206\205\345\255\230\346\263\204\346\274\217\346\243\200\346\265\213.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/06.\345\206\205\345\255\230\350\260\203\346\265\213/02.\345\206\205\345\255\230\346\263\204\346\274\217\346\243\200\346\265\213.md" deleted file mode 100644 index 4b1f4e25e83c2362c506f90f0121b07fe55c1e5d..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/06.\345\206\205\345\255\230\350\260\203\346\265\213/02.\345\206\205\345\255\230\346\263\204\346\274\217\346\243\200\346\265\213.md" +++ /dev/null @@ -1,139 +0,0 @@ ---- -title: 内存泄漏检测 -permalink: /pages/01050102050602 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# 内存泄漏检测 - -- [基础概念](#section1026719436293) -- [功能配置](#section13991354162914) -- [开发指导](#section95828159308) - - [开发流程](#section369844416304) - - [编程实例](#section460801313313) - - -## 基础概念 - -内存泄漏检测机制作为内核的可选功能,用于辅助定位动态内存泄漏问题。开启该动能,动态内存机制会自动记录申请内存时的函数调用关系(下文简称LR)。如果出现泄漏,就可以利用这些记录的信息,找到内存申请的地方,方便进一步确认。 - -## 功能配置 - -1. LOSCFG\_MEM\_LEAKCHECK:开关宏,默认关闭;如需要打开这个功能,可以在配置项中开启“Debug-\> Enable Function call stack of Mem operation recorded”。 -2. LOS\_RECORD\_LR\_CNT:记录的LR层数,默认3层;每层LR消耗sizeof\(void \*\)字节数的内存。 -3. LOS\_OMIT\_LR\_CNT:忽略的LR层数,默认2层,即从调用LOS\_MemAlloc的函数开始记录,可根据实际情况调整。为啥需要这个配置?有3点原因如下: - - LOS\_MemAlloc接口内部也有函数调用; - - 外部可能对LOS\_MemAlloc接口有封装; - - LOS\_RECORD\_LR\_CNT 配置的LR层数有限; - - -正确配置这个宏,将无效的LR层数忽略,就可以记录有效的LR层数,节省内存消耗。 - -## 开发指导 - -### 开发流程 - -该调测功能可以分析关键的代码逻辑中是否存在内存泄漏。开启这个功能,每次申请内存时,会记录LR信息。在需要检测的代码段前后,调用LOS\_MemUsedNodeShow接口,每次都会打印指定内存池已使用的全部节点信息,对比前后两次的节点信息,新增的节点信息就是疑似泄漏的内存节点。通过LR,可以找到具体申请的代码位置,进一步确认是否泄漏。 - -调用LOS\_MemUsedNodeShow接口输出的节点信息格式如下:每1行为一个节点信息;第1列为节点地址,可以根据这个地址,使用GDB等手段查看节点完整信息;第2列为节点的大小,等于节点头大小+数据域大小;第3\~5列为函数调用关系LR地址,可以根据这个值,结合汇编文件,查看该节点具体申请的位置。 - -``` -node size LR[0] LR[1] LR[2] -0x10017320: 0x528 0x9b004eba 0x9b004f60 0x9b005002 -0x10017848: 0xe0 0x9b02c24e 0x9b02c246 0x9b008ef0 -0x10017928: 0x50 0x9b008ed0 0x9b068902 0x9b0687c4 -0x10017978: 0x24 0x9b008ed0 0x9b068924 0x9b0687c4 -0x1001799c: 0x30 0x9b02c24e 0x9b02c246 0x9b008ef0 -0x100179cc: 0x5c 0x9b02c24e 0x9b02c246 0x9b008ef0 -``` - ->![](/images/device-dev/public_sys-resources/icon-caution.gif) **注意:** ->开启内存检测会影响内存申请的性能,且每个内存节点都会记录LR地址,内存开销也加大。 - -### 编程实例 - -本实例实现如下功能:构建内存泄漏代码段。 - -1. 调用OsMemUsedNodeShow接口,输出全部节点信息打印; -2. 申请内存,但没有释放,模拟内存泄漏; -3. 再次调用OsMemUsedNodeShow接口,输出全部节点信息打印; -4. 将两次log进行对比,得出泄漏的节点信息; -5. 通过LR地址,找出泄漏的代码位置; - -**示例代码** - -代码实现如下: - -``` -#include -#include -#include "los_memory.h" -#include "los_config.h" - -void MemLeakTest(void) -{ - OsMemUsedNodeShow(LOSCFG_SYS_HEAP_ADDR); - void *ptr1 = LOS_MemAlloc(LOSCFG_SYS_HEAP_ADDR, 8); - void *ptr2 = LOS_MemAlloc(LOSCFG_SYS_HEAP_ADDR, 8); - OsMemUsedNodeShow(LOSCFG_SYS_HEAP_ADDR); -} -``` - -**结果验证** - -编译运行输出log如下: - -``` -node size LR[0] LR[1] LR[2] -0x20001b04: 0x24 0x08001a10 0x080035ce 0x080028fc -0x20002058: 0x40 0x08002fe8 0x08003626 0x080028fc -0x200022ac: 0x40 0x08000e0c 0x08000e56 0x0800359e -0x20002594: 0x120 0x08000e0c 0x08000e56 0x08000c8a -0x20002aac: 0x56 0x08000e0c 0x08000e56 0x08004220 - -node size LR[0] LR[1] LR[2] -0x20001b04: 0x24 0x08001a10 0x080035ce 0x080028fc -0x20002058: 0x40 0x08002fe8 0x08003626 0x080028fc -0x200022ac: 0x40 0x08000e0c 0x08000e56 0x0800359e -0x20002594: 0x120 0x08000e0c 0x08000e56 0x08000c8a -0x20002aac: 0x56 0x08000e0c 0x08000e56 0x08004220 -0x20003ac4: 0x1d 0x08001458 0x080014e0 0x080041e6 -0x20003ae0: 0x1d 0x080041ee 0x08000cc2 0x00000000 -``` - -对比两次log,差异如下,这些内存节点就是疑似泄漏的内存块: - -``` -0x20003ac4: 0x1d 0x08001458 0x080014e0 0x080041e6 -0x20003ae0: 0x1d 0x080041ee 0x08000cc2 0x00000000 -``` - -部分汇编文件如下: - -``` - MemLeakTest: - 0x80041d4: 0xb510 PUSH {R4, LR} - 0x80041d6: 0x4ca8 LDR.N R4, [PC, #0x2a0] ; g_memStart - 0x80041d8: 0x0020 MOVS R0, R4 - 0x80041da: 0xf7fd 0xf93e BL LOS_MemUsedNodeShow ; 0x800145a - 0x80041de: 0x2108 MOVS R1, #8 - 0x80041e0: 0x0020 MOVS R0, R4 - 0x80041e2: 0xf7fd 0xfbd9 BL LOS_MemAlloc ; 0x8001998 - 0x80041e6: 0x2108 MOVS R1, #8 - 0x80041e8: 0x0020 MOVS R0, R4 - 0x80041ea: 0xf7fd 0xfbd5 BL LOS_MemAlloc ; 0x8001998 - 0x80041ee: 0x0020 MOVS R0, R4 - 0x80041f0: 0xf7fd 0xf933 BL LOS_MemUsedNodeShow ; 0x800145a - 0x80041f4: 0xbd10 POP {R4, PC} - 0x80041f6: 0x0000 MOVS R0, R0 -``` - -其中,通过查找0x080041ee,就可以发现该内存节点是在MemLeakTest接口里申请的且是没有释放的。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/06.\345\206\205\345\255\230\350\260\203\346\265\213/03.\350\270\251\345\206\205\345\255\230\346\243\200\346\265\213.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/06.\345\206\205\345\255\230\350\260\203\346\265\213/03.\350\270\251\345\206\205\345\255\230\346\243\200\346\265\213.md" deleted file mode 100644 index 17c62cc25999341c8afbbc4adeeaea19fc06ad7c..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/06.\345\206\205\345\255\230\350\260\203\346\265\213/03.\350\270\251\345\206\205\345\255\230\346\243\200\346\265\213.md" +++ /dev/null @@ -1,97 +0,0 @@ ---- -title: 踩内存检测 -permalink: /pages/01050102050603 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# 踩内存检测 - -- [基础概念](#section17368154517335) -- [功能配置](#section4696190123420) -- [开发指导](#section672362973417) - - [开发流程](#section026014863416) - - [编程实例](#section186311302356) - - -## 基础概念 - -踩内存检测机制作为内核的可选功能,用于检测动态内存池的完整性。通过该机制,可以及时发现内存池是否发生了踩内存问题,并给出错误信息,便于及时发现系统问题,提高问题解决效率,降低问题定位成本。 - -## 功能配置 - -LOSCFG\_BASE\_MEM\_NODE\_INTEGRITY\_CHECK:开关宏,默认关闭;若打开这个功能,可以在配置项中开启“Debug-\> Enable integrity check or not”。 - -1、开启这个功能,每次申请内存,会实时检测内存池的完整性。 - -2、如果不开启该功能,也可以调用LOS\_MemIntegrityCheck接口检测,但是每次申请内存时,不会实时检测内存完整性,而且由于节点头没有魔鬼数字(开启时才有,省内存),检测的准确性也会相应降低,但对于系统的性能没有影响,故根据实际情况开关该功能。 - -由于该功能只会检测出哪个内存节点被破坏了,并给出前节点信息(因为内存分布是连续的,当前节点最有可能被前节点破坏)。如果要进一步确认前节点在哪里申请的,需开启内存泄漏检测功能,通过LR记录,辅助定位。 - ->![](/images/device-dev/public_sys-resources/icon-caution.gif) **注意:** ->开启该功能,节点头多了魔鬼数字字段,会增大节点头大小。由于实时检测完整性,故性能影响较大;若性能敏感的场景,可以不开启该功能,使用LOS\_MemIntegrityCheck接口检测。 - -## 开发指导 - -### 开发流程 - -通过调用LOS\_MemIntegrityCheck接口检测内存池是否发生了踩内存,如果没有踩内存问题,那么接口返回0且没有log输出;如果存在踩内存问题,那么会输出相关log,详见下文编程实例的结果输出。 - -### 编程实例 - -本实例实现如下功能: - -1. 申请两个物理上连续的内存块; -2. 通过memset构造越界访问,踩到下个节点的头4个字节; -3. 调用LOS\_MemIntegrityCheck检测是否发生踩内存。 - -**示例代码** - -代码实现如下: - -``` -#include -#include -#include "los_memory.h" -#include "los_config.h" - -void MemIntegrityTest(void) -{ - /* 申请两个物理连续的内存块 */ - void *ptr1 = LOS_MemAlloc(LOSCFG_SYS_HEAP_ADDR, 8); - void *ptr2 = LOS_MemAlloc(LOSCFG_SYS_HEAP_ADDR, 8); - /* 第一个节点内存块大小是8字节,那么12字节的清零,会踩到第二个内存节点的节点头,构造踩内存场景 */ - memset(ptr1, 0, 8 + 4); - LOS_MemIntegrityCheck(LOSCFG_SYS_HEAP_ADDR); -} -``` - -**结果验证** - -编译运行输出log如下: - -``` -[ERR][OsMemMagicCheckPrint], 2028, memory check error! -memory used but magic num wrong, magic num = 0x00000000 /* 提示信息,检测到哪个字段被破坏了,用例构造了将下个节点的头4个字节清零,即魔鬼数字字段 */ - - broken node head: 0x20003af0 0x00000000 0x80000020, prev node head: 0x20002ad4 0xabcddcba 0x80000020 -/* 被破坏节点和其前节点关键字段信息,分别为其前节点地址、节点的魔鬼数字、节点的sizeAndFlag;可以看出被破坏节点的魔鬼数字字段被清零,符合用例场景 */ - - broken node head LR info: /* 节点的LR信息需要开启内存检测功能才有有效输出 */ - LR[0]:0x0800414e - LR[1]:0x08000cc2 - LR[2]:0x00000000 - - pre node head LR info: /* 通过LR信息,可以在汇编文件中查找前节点是哪里申请,然后排查其使用的准确性 */ - LR[0]:0x08004144 - LR[1]:0x08000cc2 - LR[2]:0x00000000 -[ERR]Memory interity check error, cur node: 0x20003b10, pre node: 0x20003af0 /* 被破坏节点和其前节点的地址 */ -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/07.\347\224\250\346\210\267\346\200\201\345\206\205\345\255\230\350\260\203\346\265\213/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/07.\347\224\250\346\210\267\346\200\201\345\206\205\345\255\230\350\260\203\346\265\213/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" deleted file mode 100644 index f56d0daca864d33318116b271db376fa857a2ae8..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/07.\347\224\250\346\210\267\346\200\201\345\206\205\345\255\230\350\260\203\346\265\213/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" +++ /dev/null @@ -1,19 +0,0 @@ ---- -title: 基本概念 -permalink: /pages/01050102050701 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# 基本概念 - -Debug版本的musl-libc库为用户提供内存泄漏检测、堆内存统计、踩内存分析以及backtrace功能等维测手段,可以提高用户态内存相关问题的定位效率。 - -采用了对malloc/free接口进行插桩,保存关键节点信息,然后程序在申请和释放内存时进行内存节点完整性校验,最后在程序结束时通过统计节点信息得到内存统计信息并根据统计信息判断内存是否泄漏的设计思想。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/07.\347\224\250\346\210\267\346\200\201\345\206\205\345\255\230\350\260\203\346\265\213/02.\350\277\220\350\241\214\346\234\272\345\210\266.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/07.\347\224\250\346\210\267\346\200\201\345\206\205\345\255\230\350\260\203\346\265\213/02.\350\277\220\350\241\214\346\234\272\345\210\266.md" deleted file mode 100644 index 3c368e174f288f6cf39856d56f29f0dff499cde6..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/07.\347\224\250\346\210\267\346\200\201\345\206\205\345\255\230\350\260\203\346\265\213/02.\350\277\220\350\241\214\346\234\272\345\210\266.md" +++ /dev/null @@ -1,71 +0,0 @@ ---- -title: 运行机制 -permalink: /pages/01050102050702 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# 运行机制 - -- [内存泄漏检查](#section142061581018) -- [堆内存统计](#section136902041337) -- [内存完整性检查](#section196491231761) - -## 内存泄漏检查 - -对于每个进程,内存调测模块维护了128个链表(当前系统的线程最大数量为128个),每个链表的索引为线程ID。 - -申请内存时:保存关键信息到内存节点控制块,根据当前线程ID将内存节点控制块挂到对应链表; - -释放内存时:根据需要释放的内存地址匹配内存节点控制块并将该控制块删除。 - -**图 1** 堆内存节点信息链表 -![](/images/device-dev/kernel/figure/堆内存节点信息链表.png "堆内存节点信息链表") - -申请内存时,返回地址会被保存到LR寄存器中。进程运行过程中,系统会在内存节点控制块中添加疑似泄漏点对应的lr等信息。如下图所示: - -**图 2** 堆内存节点信息 -![](/images/device-dev/kernel/figure/堆内存节点信息.png "堆内存节点信息") - -其中,TID表示线程ID;PID表示进程ID;ptr表示申请的内存地址;size表示申请的内存大小;lr\[n\]表示函数调用栈地址,变量n可以根据具体场景的需要进行配置。 - -释放内存时,将free等接口的入参指针与node的ptr字段进行匹配,如果相同则删除该内存节点控制块信息。 - -用户通过串口或文件等方式,将各个进程内存调测信息导出,利用addr2line工具将导出的信息转换成导致内存泄漏的代码行,便可以解决内存泄露问题。 - -**图 3** 泄漏点代码行定位流程 -![](/images/device-dev/kernel/figure/泄漏点代码行定位流程.png "泄漏点代码行定位流程") - -## 堆内存统计 - -用户态线程堆内存使用统计具有一定的实际意义,统计线程申请的堆内存占比,为用户程序的内存使用优化提供数据支持。用户态堆内存统计模块主要涉及的接口为malloc和free。如[图1](#fig4294145810543),每个进程维护128个链表,链表索引即线程ID,申请内存时系统将ptr和size信息记录在内存节点控制块中并将节点控制块挂在以线程ID为头信息的链表上,堆内存释放时根据ptr从对应的链表上移除相应的堆内存块信息;同时计算出当前线程所持有的堆内存总的使用量,并更新当前进程的堆内存使用量和堆内存使用峰值。 - -## 内存完整性检查 - -- 使用malloc申请内存(小于等于0x1c000bytes时通过堆分配算法分配) - - 用户程序申请堆内存时,在堆内存节点处添加校验值等信息,如果校验值异常,则很有可能是前一块堆内存使用越界导致的(目前无法识别校验值被野指针破坏的场景)。在内存申请、释放时校验内存节点校验值的正确性,若内存节点被破坏,校验失败时则输出tid、pid及当前被踩节点前一块堆内存申请时保存的调用栈信息,通过addr2line工具可获得具体的代码行信息,辅助用户解决问题。 - - **图 4** node节点头信息添加校验值 - ![](/images/device-dev/kernel/figure/node节点头信息添加校验值.png "node节点头信息添加校验值") - - free堆内存时,不会立即把该内存块释放掉,而是在内存中写入魔术数字0xFE,并放到free队列中\(保证在一定时间内不会再被malloc函数分配\),当有野指针或use-after-free的情况对该内存进行读取的操作时,能够发现数据异常,但是对于写操作则无法判断出来。 - - **图 5** free流程图 - ![](/images/device-dev/kernel/figure/free流程图.png "free流程图") - - -- 使用malloc申请内存(大于0x1c000bytes时通过mmap申请) - - 当malloc通过mmap申请大块内存时,在返回给用户使用的内存区间头和尾分别多申请一个页,一个页PAGE\_SIZE当前为0x1000,这两个页分别通过mprotect接口设置权限为PROT\_NONE(无可读可写权限),可以有效防止内存越界读写问题:越界读写数据时由于无读写权限而导致用户程序异常,根据异常调用栈信息可找到相应的代码逻辑。 - - **图 6** malloc通过mmap机制申请内存的内存布局 - ![](/images/device-dev/kernel/figure/malloc通过mmap机制申请内存的内存布局.png "malloc通过mmap机制申请内存的内存布局") - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/07.\347\224\250\346\210\267\346\200\201\345\206\205\345\255\230\350\260\203\346\265\213/03.\344\275\277\347\224\250\346\214\207\345\257\274/01.\346\216\245\345\217\243\350\257\264\346\230\216.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/07.\347\224\250\346\210\267\346\200\201\345\206\205\345\255\230\350\260\203\346\265\213/03.\344\275\277\347\224\250\346\214\207\345\257\274/01.\346\216\245\345\217\243\350\257\264\346\230\216.md" deleted file mode 100644 index c48255cdb17c056724b06d8429822a798c22ef0c..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/07.\347\224\250\346\210\267\346\200\201\345\206\205\345\255\230\350\260\203\346\265\213/03.\344\275\277\347\224\250\346\214\207\345\257\274/01.\346\216\245\345\217\243\350\257\264\346\230\216.md" +++ /dev/null @@ -1,68 +0,0 @@ ---- -title: 接口说明 -permalink: /pages/0105010205070301 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# 接口说明 - -**表 1** 内存调测模块接口 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名

-

描述

-

内存调测功能

-

mem_check_init

-

初始化内存检测模块。

-

watch_mem

-

获取线程级堆内存使用信息。

-

check_leak

-

检查是否有堆内存泄漏。

-

check_heap_integrity

-

检查堆内存的完整性。

-

调用栈回溯功能

-

backtrace

-

获取调用栈地址信息。

-

backtrace_symbols

-

根据地址信息获取符号信息。

-

print_trace

-

输出函数调用栈信息。

-
- diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/07.\347\224\250\346\210\267\346\200\201\345\206\205\345\255\230\350\260\203\346\265\213/03.\344\275\277\347\224\250\346\214\207\345\257\274/02.\344\275\277\347\224\250\350\257\264\346\230\216/01.\346\216\245\345\217\243\350\260\203\347\224\250\346\226\271\345\274\217.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/07.\347\224\250\346\210\267\346\200\201\345\206\205\345\255\230\350\260\203\346\265\213/03.\344\275\277\347\224\250\346\214\207\345\257\274/02.\344\275\277\347\224\250\350\257\264\346\230\216/01.\346\216\245\345\217\243\350\260\203\347\224\250\346\226\271\345\274\217.md" deleted file mode 100644 index 5aaa7aee7b264ba1c9a18fab6f53eb3116319c5a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/07.\347\224\250\346\210\267\346\200\201\345\206\205\345\255\230\350\260\203\346\265\213/03.\344\275\277\347\224\250\346\214\207\345\257\274/02.\344\275\277\347\224\250\350\257\264\346\230\216/01.\346\216\245\345\217\243\350\260\203\347\224\250\346\226\271\345\274\217.md" +++ /dev/null @@ -1,160 +0,0 @@ ---- -title: 接口调用方式 -permalink: /pages/010501020507030201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# 接口调用方式 - -- [示例代码](#section5490173592518) -- [编译](#section534302242515) -- [调测信息](#section1017419992515) -- [调用栈解析](#section1485163282417) - -## 示例代码 - -代码功能:显式调用调测模块的相关接口对用户代码进行内存校验。 - -``` -#include -#include -#include -#include // 包含提供内存调测接口声明的头文件 - -#define MALLOC_LEAK_SIZE 0x300 - -void func(void) { - char *ptr = malloc(MALLOC_LEAK_SIZE); - memset(ptr, '3', MALLOC_LEAK_SIZE); -} - -int main() -{ - mem_check_init(NULL); // 通过串口输出内存调测信息,必须在用户程序第一次申请堆内存之前调用(一般在main函数入口调用),否则调测信息不准确。 - // mem_check_init("/storage/mem_debug.txt"); // 内存调测信息输出到/storage/mem_debug.txt文件中,如果该文件创建失败,则信息通过串口输出。 - char *ptr = malloc(MALLOC_LEAK_SIZE); - memset(ptr, '1', MALLOC_LEAK_SIZE); - - watch_mem(); // 在当前代码逻辑处查看线程级内存统计信息。 - func(); - check_heap_integrity(); // 检查堆内存节点完整性。 - check_leak(); // 在当前代码逻辑处检查堆内存是否泄漏(一般在程序退出之前校验比较准确,若在malloc和free调用逻辑之间做校验,则结果不准确)。 - return 0; -} -``` - -## 编译 - -``` -$ clang -o mem_check mem_check.c -funwind-tables -rdynamic -g -mfloat-abi=softfp -mcpu=cortex-a7 -mfpu=neon-vfpv4 -target arm-liteos --sysroot=/home//harmony/out/hispark_taurus/ipcamera_hispark_taurus/sysroot $(clang -mfloat-abi=softfp -mcpu=cortex-a7 -mfpu=neon-vfpv4 -target arm-liteos -print-file-name=libunwind.a) -``` - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->- 本编译示例基于将编译器的路径写入环境变量中,即.bashrc文件中。 ->- 编译用户程序及所需的lib库时,需要添加编译选项-funwind-tables,-rdynamic,-g,用于栈回溯。 ->- -mfloat-abi=softfp,-mcpu=cortex-a7,-mfpu=neon-vfpv4编译选项用于指定具体的芯片架构、浮点数计算优化、fpu,与具体的libc库使用的编译选项保持一致,否则链接时可能出现找不到libc库文件。 ->- -target arm-liteos用于指定编译器相关库文件路径。 ->- --sysroot=/home//harmony/out/hispark\_taurus/ipcamera\_hispark\_taurus/sysroot用于指定编译器库文件搜索根目录,假设OpenHarmony工程代码存放路径为/home//harmony。其中out/hispark\_taurus/ipcamera\_hispark\_taurus路径为在编译时,hb set命令指定的具体产品,本示例选择的是ipcamera\_hispark\_taurus产品。 ->- $\(clang -mfloat-abi=softfp -mcpu=cortex-a7 -mfpu=neon-vfpv4 -target arm-liteos -print-file-name=libunwind.a\)用于指定相应的unwind库的路径。 - -## 调测信息 - -``` -OHOS # ./mem_check -OHOS # -==PID:4== Heap memory statistics(bytes): // 堆内存统计信息 - [Check point]: // check点调用栈 - #00: [0x86c] -> mem_check - #01: <(null)+0x24baf9dc>[0x219dc] -> /lib/libc.so - - [TID: 18, Used: 0x320] // 18号线程堆内存占用,当前进程仅一个线程 - -==PID:4== Total heap: 0x320 byte(s), Peak: 0x320 byte(s) - -Check heap integrity ok! // 堆内存完整性检查 - -==PID:4== Detected memory leak(s): // 内存泄漏信息及调用栈 - [Check point]: - #00: [0x2da4c] -> /lib/libc.so - #01: [0x878] -> mem_check - - [TID:18 Leak:0x320 byte(s)] Allocated from: - #00: [0x850] -> mem_check - #01: <(null)+0x24baf9dc>[0x219dc] -> /lib/libc.so - - [TID:18 Leak:0x320 byte(s)] Allocated from: - #00: [0x810] -> mem_check - #01: [0x870] -> mem_check - #02: <(null)+0x24baf9dc>[0x219dc] -> /lib/libc.so - -==PID:4== SUMMARY: 0x640 byte(s) leaked in 2 allocation(s). - -==PID:4== Detected memory leak(s): - [Check point]: - #00: [0x2da4c] -> /lib/libc.so - #01: [0x111ec] -> /lib/libc.so - - [TID:18 Leak:0x320 byte(s)] Allocated from: - #00: [0x850] -> mem_check - #01: <(null)+0x24baf9dc>[0x219dc] -> /lib/libc.so - - [TID:18 Leak:0x320 byte(s)] Allocated from: - #00: [0x810] -> mem_check - #01: [0x870] -> mem_check - #02: <(null)+0x24baf9dc>[0x219dc] -> /lib/libc.so - -==PID:4== SUMMARY: 0x640 byte(s) leaked in 2 allocation(s). - -Check heap integrity ok! -``` - -## 调用栈解析 - -提供parse\_mem\_info.sh脚本可以对调用栈进行解析,解析脚本存放的路径:kernel/liteos\_a/tools/scripts/parse\_memory/parse\_mem\_info.sh。利用脚本可以将相应的调测信息转换成具体的源码行号,如下命令所示,mem\_debug.txt保存的是内存调测信息,elf1、elf2等文件是需要解析的elf文件。 - -``` -$ ./parse_mem_info.sh mem_debug.txt elf1 elf2 elf3 ... -``` - -例如: - -``` -$ ./parse_mem_info.sh mem_debug.txt mem_check -Compiler is [gcc/llvm]: llvm -Now using addr2line ... - -==PID:4== Heap memory statistics(bytes): - [Check point]: - #00: [0x86c] at /usr1/xxx/TEST_ELF/mem_check.c:22 - #01: <(null)+0x24baf9dc>[0x219dc] -> /lib/libc.so - - [TID: 18, Used: 0x320] - -==PID:4== Total heap: 0x320 byte(s), Peak: 0x320 byte(s) - -Check heap integrity ok! - -==PID:4== Detected memory leak(s): - [Check point]: - #00: [0x2da4c] -> /lib/libc.so - #01: [0x878] at /usr1/xxx/TEST_ELF/mem_check.c:28 - - [TID:18 Leak:0x320 byte(s)] Allocated from: - #00: [0x850] at /usr1/xxx/TEST_ELF/mem_check.c:17 - #01: <(null)+0x24baf9dc>[0x219dc] -> /lib/libc.so - - [TID:18 Leak:0x320 byte(s)] Allocated from: - #00: [0x810] at /usr1/xxx/TEST_ELF/mem_check.c:9 - #01: [0x870] at /usr1/xxx/TEST_ELF/mem_check.c:24 - #02: <(null)+0x24baf9dc>[0x219dc] -> /lib/libc.so - -==PID:4== SUMMARY: 0x640 byte(s) leaked in 2 allocation(s). -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/07.\347\224\250\346\210\267\346\200\201\345\206\205\345\255\230\350\260\203\346\265\213/03.\344\275\277\347\224\250\346\214\207\345\257\274/02.\344\275\277\347\224\250\350\257\264\346\230\216/02.\345\221\275\344\273\244\350\241\214\345\217\202\346\225\260\346\226\271\345\274\217.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/07.\347\224\250\346\210\267\346\200\201\345\206\205\345\255\230\350\260\203\346\265\213/03.\344\275\277\347\224\250\346\214\207\345\257\274/02.\344\275\277\347\224\250\350\257\264\346\230\216/02.\345\221\275\344\273\244\350\241\214\345\217\202\346\225\260\346\226\271\345\274\217.md" deleted file mode 100644 index 0f9b226dd86e3120230813af287b6a6018c0bcae..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/07.\347\224\250\346\210\267\346\200\201\345\206\205\345\255\230\350\260\203\346\265\213/03.\344\275\277\347\224\250\346\214\207\345\257\274/02.\344\275\277\347\224\250\350\257\264\346\230\216/02.\345\221\275\344\273\244\350\241\214\345\217\202\346\225\260\346\226\271\345\274\217.md" +++ /dev/null @@ -1,242 +0,0 @@ ---- -title: 命令行参数方式 -permalink: /pages/010501020507030202 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# 命令行参数方式 - -- [示例代码](#section13793104782316) -- [编译](#section1676431122320) -- [使用mwatch参数命令](#section1703415132311) -- [调用栈解析](#section1880675510221) -- [使用mrecord参数命令](#section071022822210) - -对用户态进程进行内存相关的检查时,除了接口调用方式还可以通过命令行方式进行内存统计、内存泄漏或内存完整性检查。 - -``` ---mwatch:初始化内存调测功能,注册信号。内存调测信息将从串口输出; ---mrecord :初始化内存调测功能,注册信号。内存调测信息将保存至f_path文件,若f_path创建失败,则内存调测信息将从串口输出 -``` - -在待调测的进程未退出时可使用信号机制获取对应信息: - -``` -kill -35 # 查看线程级堆内存占用 -kill -36 # 检查是否存在堆内存泄漏 -kill -37 # 检查堆内存头节点是否完整 -``` - -## 示例代码 - -代码功能:构造内存问题利用命令行方式进行内存调测。 - -``` -#include -#include -#include - -#define MALLOC_LEAK_SIZE 0x300 - -void func(void) { - char *ptr = malloc(MALLOC_LEAK_SIZE); - memset(ptr, '3', MALLOC_LEAK_SIZE); -} - -int main() -{ - char *ptr = malloc(MALLOC_LEAK_SIZE); - memset(ptr, '1', MALLOC_LEAK_SIZE); - func(); - while (1); -} -``` - -## 编译 - -参考[接口调用一节](/pages/010501020507030201#section534302242515)。 - -## 使用mwatch参数命令 - -``` -OHOS # ./mem_check --mwatch // 利用task命令可以查到mem_check进程的pid为4 -OHOS # -OHOS # kill -35 4 // 查看堆内存统计信息 -OHOS # -==PID:4== Heap memory statistics(bytes): - [Check point]: - #00: [0x58dfc] -> /lib/libc.so - - [TID: 18, Used: 0x640] - -==PID:4== Total heap: 0x640 byte(s), Peak: 0x640 byte(s) - -OHOS # kill -36 4 // 检查是否存在堆内存泄漏 -OHOS # -==PID:4== Detected memory leak(s): - [Check point]: - #00: [0x2da4c] -> /lib/libc.so - #01: [0x58dfc] -> /lib/libc.so - - [TID:18 Leak:0x320 byte(s)] Allocated from: - #00: [0x724] -> mem_check - #01: <(null)+0x2555a9dc>[0x219dc] -> /lib/libc.so - - [TID:18 Leak:0x320 byte(s)] Allocated from: - #00: [0x6ec] -> mem_check - #01: [0x740] -> mem_check - #02: <(null)+0x2555a9dc>[0x219dc] -> /lib/libc.so - -==PID:4== SUMMARY: 0x640 byte(s) leaked in 2 allocation(s). - -OHOS # kill -37 4 // 检查堆内存头节点的完整性 -OHOS # -Check heap integrity ok! -``` - -## 调用栈解析 - -将调测信息保存至test.txt文件中,利用脚本进行解析,获取内存泄漏的具体行号。 - -``` -$ ./parse_mem_info.sh test.txt mem_check -Compiler is [gcc/llvm]: llvm -Now using addr2line ... - -==PID:4== Detected memory leak(s): - [Check point]: - #00: [0x2da4c] -> /lib/libc.so - #01: [0x58dfc] -> /lib/libc.so - - [TID:18 Leak:0x320 byte(s)] Allocated from: - #00: [0x724] at /usr1/xxx/TEST_ELF/mem_check.c:14 - #01: <(null)+0x2555a9dc>[0x219dc] -> /lib/libc.so - - [TID:18 Leak:0x320 byte(s)] Allocated from: - #00: [0x6ec] at /usr1/xxx/TEST_ELF/mem_check.c:8 - #01: [0x740] at /usr1/xxx/TEST_ELF/mem_check.c:19 - #02: <(null)+0x2555a9dc>[0x219dc] -> /lib/libc.so - -==PID:4== SUMMARY: 0x640 byte(s) leaked in 2 allocation(s). -``` - -## 使用mrecord参数命令 - -1. 执行用户程序并指定记录内存调测信息的文件路径 - - ``` - OHOS # ./mem_check --mrecord /storage/check.txt - ``` - -2. 利用kill -35 统计内存信息,该信息将会输出到文件中,使用cat命令查看 - - ``` - OHOS # kill -35 4 - OHOS # Memory statistics information saved in /storage/pid(4)_check.txt - - OHOS # cat /storage/pid(4)_check.txt - - ==PID:4== Heap memory statistics(bytes): - [Check point]: - #00: [0x5973c] -> /lib/libc.so - - [TID: 18, Used: 0x640] - - ==PID:4== Total heap: 0x640 byte(s), Peak: 0x640 byte(s) - ``` - -3. 利用kill -36 校验内存完整性,该信息将会输出到文件中,使用cat命令查看 - - ``` - OHOS # kill -36 4 - OHOS # Leak check information saved in /storage/pid(4)_check.txt - - OHOS # cat /storage/pid(4)_check.txt - - ==PID:4== Heap memory statistics(bytes): - [Check point]: - #00: [0x5973c] -> /lib/libc.so - - [TID: 18, Used: 0x640] - - ==PID:4== Total heap: 0x640 byte(s), Peak: 0x640 byte(s) - - ==PID:4== Detected memory leak(s): - [Check point]: - #00: [0x2e38c] -> /lib/libc.so - #01: [0x5973c] -> /lib/libc.so - - [TID:18 Leak:0x320 byte(s)] Allocated from: - #00: [0x724] -> mem_check - #01: <(null)+0x1fdd231c>[0x2231c] -> /lib/libc.so - - [TID:18 Leak:0x320 byte(s)] Allocated from: - #00: [0x6ec] -> mem_check - #01: [0x740] -> mem_check - #02: <(null)+0x1fdd231c>[0x2231c] -> /lib/libc.so - - ==PID:4== SUMMARY: 0x640 byte(s) leaked in 2 allocation(s). - ``` - -4. 利用kill -9 杀掉当前进程,进程退出后会默认校验内存完整性,该信息将会输出到文件中,使用cat命令查看 - - ``` - OHOS # kill -9 4 - OHOS # Leak check information saved in /storage/pid(4)_check.txt - - Check heap integrity ok! - - OHOS # cat /storage/pid(4)_check.txt - OHOS # - ==PID:4== Heap memory statistics(bytes): - [Check point]: - #00: [0x5973c] -> /lib/libc.so - - [TID: 18, Used: 0x640] - - ==PID:4== Total heap: 0x640 byte(s), Peak: 0x640 byte(s) - - ==PID:4== Detected memory leak(s): - [Check point]: - #00: [0x2e38c] -> /lib/libc.so - #01: [0x5973c] -> /lib/libc.so - - [TID:18 Leak:0x320 byte(s)] Allocated from: - #00: [0x724] -> mem_check - #01: <(null)+0x1fdd231c>[0x2231c] -> /lib/libc.so - - [TID:18 Leak:0x320 byte(s)] Allocated from: - #00: [0x6ec] -> mem_check - #01: [0x740] -> mem_check - #02: <(null)+0x1fdd231c>[0x2231c] -> /lib/libc.so - - ==PID:4== SUMMARY: 0x640 byte(s) leaked in 2 allocation(s). - - ==PID:4== Detected memory leak(s): - [Check point]: - #00: [0x2e38c] -> /lib/libc.so - #01: [0x11b2c] -> /lib/libc.so - - [TID:18 Leak:0x320 byte(s)] Allocated from: - #00: [0x724] -> mem_check - #01: <(null)+0x1fdd231c>[0x2231c] -> /lib/libc.so - - [TID:18 Leak:0x320 byte(s)] Allocated from: - #00: [0x6ec] -> mem_check - #01: [0x740] -> mem_check - #02: <(null)+0x1fdd231c>[0x2231c] -> /lib/libc.so - - ==PID:4== SUMMARY: 0x640 byte(s) leaked in 2 allocation(s). - ``` - - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->上述连续记录的信息会逐步追加到初始化时所指定的文件中,故最后cat文件时,文件中还包含历史记录的信息内容。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/07.\347\224\250\346\210\267\346\200\201\345\206\205\345\255\230\350\260\203\346\265\213/04.\345\270\270\350\247\201\351\227\256\351\242\230\345\234\272\346\231\257.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/07.\347\224\250\346\210\267\346\200\201\345\206\205\345\255\230\350\260\203\346\265\213/04.\345\270\270\350\247\201\351\227\256\351\242\230\345\234\272\346\231\257.md" deleted file mode 100644 index 5fd05e5b8d668a38afb4b37c9f0aa2c9112706d2..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/07.\347\224\250\346\210\267\346\200\201\345\206\205\345\255\230\350\260\203\346\265\213/04.\345\270\270\350\247\201\351\227\256\351\242\230\345\234\272\346\231\257.md" +++ /dev/null @@ -1,65 +0,0 @@ ---- -title: 常见问题场景 -permalink: /pages/01050102050704 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# 常见问题场景 - -- [UAF\(Use after free\)](#section4427132815445) -- [Double free](#section827194818458) -- [堆内存节点被踩](#section1763741216461) - -## UAF\(Use after free\) - -- 申请小块内存(不大于0x1c000字节) - - free之后: - - 读操作:读取free之后的内存大概率是魔术数字\(0xFEFEFEFE\) - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >free之后的堆内存不会立即释放进堆内存池,会先放至固定长度的队列中,并置魔术数字0xFE,队列满后会将先放至队列中的内存块释放进堆内存池 - - 写操作:无法校验。 - - -- 申请大块内存(大于0x1c000) - - 堆内存由malloc通过调用mmap接口申请,free之后若仍访问该内存,则用户程序异常(该内存区间已被unmap)。 - - -## Double free - -Double free时,用户程序将会异常退出。 - -## 堆内存节点被踩 - -- 申请小块内存(不大于0x1c000) - - 堆内存节点被踩时,用户程序将会异常退出,并输出破坏被踩节点的可能的堆内存申请调用栈,对于野指针踩内存情况无法校验出来。例如用户程序mem\_check中存在堆内存越界踩的情况,利用命令行方式可以获得踩内存的可能的具体位置。 - - ``` - OHOS # ./mem_check --mwatch - OHOS # - ==PID:6== Memory integrity information: - [TID:28 allocated addr: 0x272e1ea0, size: 0x120] The possible attacker was allocated from: - #00: [0x640e8] -> /lib/libc.so - #01: [0x21d0] -> mem_check - ``` - - 可以通过调用栈解析脚本对调用栈信息进行解析。 - - -- 申请大块内存(大于0x1c000) - - 堆内存由malloc通过mmap接口申请,申请得到的堆内存块前后各置一个size为PAGE\_SIZE大小的区间,设置无读写权限,读写操作会触发用户程序异常。 - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/08.\345\205\266\344\273\226\345\206\205\346\240\270\350\260\203\346\265\213\346\211\213\346\256\265/01.\344\270\264\347\273\210\351\201\227\350\250\200.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/08.\345\205\266\344\273\226\345\206\205\346\240\270\350\260\203\346\265\213\346\211\213\346\256\265/01.\344\270\264\347\273\210\351\201\227\350\250\200.md" deleted file mode 100644 index df9bcd7a93d83957eb45a5cf7203d4bf0d0324ee..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/08.\345\205\266\344\273\226\345\206\205\346\240\270\350\260\203\346\265\213\346\211\213\346\256\265/01.\344\270\264\347\273\210\351\201\227\350\250\200.md" +++ /dev/null @@ -1,109 +0,0 @@ ---- -title: 临终遗言 -permalink: /pages/01050102050801 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# 临终遗言 - -- [使用场景](#section158501652121514) -- [功能说明](#section1186411122215) -- [参数说明](#section1083765723015) -- [开发流程](#section783435801510) - -## 使用场景 - -在无串口的设备上,将系统异常时打印的信息保存到不丢失的存储介质上,方便对运行时问题进行定位。 - -## 功能说明 - -该调测功能提供了一种用于保存系统异常时打印信息到不丢失存储介质中的机制,用户可自行注册读写异常时打印信息的钩子函数,实现在不同存储介质上保存异常信息的能力,这样方便无串口的设备的问题定位。接口名为LOS\_ExcInfoRegHook,该函数声明在los\_config.h中,函数原型: - -``` -typedef VOID (*log_read_write_fn)(UINT32 startAddr, UINT32 space, UINT32 rwFlag, CHAR *buf); -...... -VOID LOS_ExcInfoRegHook(UINT32 startAddr, UINT32 space, CHAR *buf, log_read_write_fn hook); -``` - -## 参数说明 - -**表 1** LOS\_ExcInfoRegHook 参数说明 - - - - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

startAddr

-

存取异常信息的物理介质起始地址

-

space

-

存取的空间大小

-

buf

-

存取异常信息的内存缓冲区

-

log_read_write_fn

-

存取异常信息的函数

-
- -**表 2** log\_read\_write\_fn 参数说明 - - - - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

startAddr

-

存取异常信息的物理介质起始地址

-

space

-

存取的空间大小

-

rwFlag

-

读写标记,0为写,1为读

-

buf

-

存取异常信息的内存缓冲区

-
- -## 开发流程 - -该功能依赖于宏LOSCFG\_SAVE\_EXCINFO,使用临终遗言功能时,在配置项中开启“ Enable Saving Exception Information ”:Debug-\> Enable Saving Exception Information ;若关闭该选项,则该功能失效。功能开启后,可在SystemInit中调用LOS\_ExcInfoRegHook来注册存取异常信息的位置、大小、内存缓冲区以及存取函数。当系统进入异常时,会将异常时系统各类信息先保存在注册时传入的内存缓冲区中,最后调用注册的存取函数,将异常信息写入到物理存储介质中。 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->- 注册的存取位置不要跟其他存储重叠。 ->- 注册的内存缓冲区不能太小,建议不低于16KiB,否则异常信息会存储不完整。 ->- 注册的读写函数对应的具体存储介质的驱动功能正常,才能保证存取功能正常。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/08.\345\205\266\344\273\226\345\206\205\346\240\270\350\260\203\346\265\213\346\211\213\346\256\265/02.\345\270\270\350\247\201\351\227\256\351\242\230\345\256\232\344\275\215\346\226\271\346\263\225.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/08.\345\205\266\344\273\226\345\206\205\346\240\270\350\260\203\346\265\213\346\211\213\346\256\265/02.\345\270\270\350\247\201\351\227\256\351\242\230\345\256\232\344\275\215\346\226\271\346\263\225.md" deleted file mode 100644 index 3d43b9630ef6921debf4e70654db6af25d8e85fe..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/05.\350\260\203\346\265\213\344\270\216\345\267\245\345\205\267/08.\345\205\266\344\273\226\345\206\205\346\240\270\350\260\203\346\265\213\346\211\213\346\256\265/02.\345\270\270\350\247\201\351\227\256\351\242\230\345\256\232\344\275\215\346\226\271\346\263\225.md" +++ /dev/null @@ -1,49 +0,0 @@ ---- -title: 常见问题定位方法 -permalink: /pages/01050102050802 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# 常见问题定位方法 - -- [通过异常信息定位问题](#section695838161711) -- [内存池完整性验证](#section362917569179) -- [全局变量踩内存定位方法](#section18971311121816) - -## 通过异常信息定位问题 - -系统异常被挂起后,会在串口看到一些关键寄存器的信息,如图1所示。可通过这些信息定位到异常所在函数和其调用栈关系,为原因分析提供第一手资料。 - -图1 异常信息 - -![](/images/device-dev/kernel/figure/zh-cn_image_0000001173429547.png) - -上图中的异常信息主要解释4个标签: - -**标签1**:标识异常在内核态; - -**标签2**:标识了异常类型(数据异常时,far后的值是系统异常时CPU访问的地址); - -**标签3**:pc的值标识系统异常时执行指令的位置,klr的值一般标识pc所在函数执行完后下一条要执行的命令。(**注:标签4处 traceback 0 lr有值时不用关注klr**)。 - -**标签4**:lr 的值依次标识正常情况下PC要依次执行的指令的位置。 - -对于内核异常打印信息,确定PC和LR的具体位置的指令需要结合out目录下OHOS\_Image.asm(跟烧写的系统镜像OHOS\_Image.bin对应的汇编文件)查看,根据指令所在的位置可确认使用该指令的函数,依次确定LR位置所在的函数,即得到异常发生时的函数调用关系。 - -## 内存池完整性验证 - -仅凭上节异常信息定位的基本方法,常常无法直接定位问题所在。并且常常会因为异常的寄存器值而无法对问题进行定位。若怀疑是堆内存越界导致的问题,可以调用内存池完整性检测函数LOS\_MemIntegrityCheck进行检查。函数LOS\_MemIntegrityCheck将会对系统动态内存池所有的节点进行遍历,如果所有节点正常则函数返回0,不会有任何打印,否则将打印相关的错误信息。该函数的入参使用\(VOID \*\)OS\_SYS\_MEM\_ADDR。 - -定位堆内存越界踩的问题,一般是在可能存在问题的业务逻辑代码前后使用LOS\_MemIntegrityCheck,如果该业务代码不存在问题,则前后两次LOS\_MemIntegrityCheck调用不会失败,按前述方式逐步缩小问题定位范围。 - -## 全局变量踩内存定位方法 - -如果已知一个全局变量内存域被踩,可在OHOS\_Image.map文件中找到该全局变量所在的地址,并且特别注意该地址之前最近被使用的变量,有极大概率是前面的变量(尤其数组类型的或会被强转成其他类型的变量)在使用的过程中内存越界,破坏了这个全局变量。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/06.\351\231\204\345\275\225/01.\345\237\272\346\234\254\346\225\260\346\215\256\347\273\223\346\236\204/01.\345\217\214\345\220\221\351\223\276\350\241\250.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/06.\351\231\204\345\275\225/01.\345\237\272\346\234\254\346\225\260\346\215\256\347\273\223\346\236\204/01.\345\217\214\345\220\221\351\223\276\350\241\250.md" deleted file mode 100644 index 6a7b6a8d94aacfd1d77640d6b8800d76b48b36de..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/06.\351\231\204\345\275\225/01.\345\237\272\346\234\254\346\225\260\346\215\256\347\273\223\346\236\204/01.\345\217\214\345\220\221\351\223\276\350\241\250.md" +++ /dev/null @@ -1,242 +0,0 @@ ---- -title: 双向链表 -permalink: /pages/01050102060101 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# 双向链表 - -- [基本概念](#section1990715203418) -- [功能说明](#section848334511411) -- [开发流程](#section01781261552) - - [编程实例](#section8354175218128) - - -## 基本概念 - -双向链表是指含有往前和往后两个方向的链表,即每个结点中除存放下一个节点指针外,还增加一个指向前一个节点的指针。其头指针head是唯一确定的。从双向链表中的任意一个结点开始,都可以很方便地访问它的前驱结点和后继结点,这种数据结构形式使得双向链表在查找时更加方便,特别是大量数据的遍历。由于双向链表具有对称性,能方便地完成各种插入、删除等操作,但需要注意前后方向的操作。 - -## 功能说明 - -双向链表模块为用户提供下面几种功能,接口详细信息可以查看API参考。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名

-

描述

-

初始化链表

-

LOS_ListInit

-

将指定节点初始化为双向链表节点

-

LOS_DL_LIST_HEAD

-

定义一个节点并初始化为双向链表节点

-

增加节点

-

LOS_ListAdd

-

将指定节点插入到双向链表头端

-

LOS_ListHeadInsert

-

将指定节点插入到双向链表头端,LOS_ListAdd

-

LOS_ListTailInsert

-

将指定节点插入到双向链表尾端

-

增加链表

-

LOS_ListAddList

-

将指定链表的头端插入到双向链表头端

-

LOS_ListHeadInsertList

-

将指定链表的头端插入到双向链表头端,同LOS_ListAddList

-

LOS_ListTailInsertList

-

将指定链表的尾端插入到双向链表头端

-

删除节点

-

LOS_ListDelete

-

将指定节点从链表中删除

-

LOS_ListDelInit

-

将指定节点从链表中删除,并使用该节点初始化链表

-

判断双向链表

-

LOS_ListEmpty

-

判断链表是否为空

-

LOS_DL_LIST_IS_END

-

判断指定链表节点是否为链表尾端

-

LOS_DL_LIST_IS_ON_QUEUE

-

判断链表节点是否在双向链表里

-

获取结构体信息

-

LOS_OFF_SET_OF

-

获取指定结构体内的成员相对于结构体起始地址的偏移量

-

LOS_DL_LIST_ENTRY

-

获取双向链表中第一个链表节点所在的结构体地址,接口的第一个入参表示的是链表中的头节点,第二个入参是要获取的结构体名称,第三个入参是链表在该结构体中的名称

-

LOS_ListPeekHeadType

-

获取双向链表中第一个链表节点所在的结构体地址,接口的第一个入参表示的是链表中的头节点,第二个入参是要获取的结构体名称,第三个入参是链表在该结构体中的名称。如果链表为空,返回NULL。

-

LOS_ListRemoveHeadType

-

获取双向链表中第一个链表节点所在的结构体地址,并把第一个链表节点从链表中删除。接口的第一个入参表示的是链表中的头节点,第二个入参是要获取的结构体名称,第三个入参是链表在该结构体中的名称。如果链表为空,返回NULL。

-

LOS_ListNextType

-

获取双向链表中指定链表节点的下一个节点所在的结构体地址。接口的第一个入参表示的是链表中的头节点,第二个入参是指定的链表节点,第三个入参是要获取的结构体名称,第四个入参是链表在该结构体中的名称。如果链表节点下一个为链表头结点为空,返回NULL。

-

遍历双向链表

-

LOS_DL_LIST_FOR_EACH

-

遍历双向链表

-

LOS_DL_LIST_FOR_EACH_SAFE

-

遍历双向链表,并存储当前节点的后继节点用于安全校验

-

遍历包含双向链表的结构体

-

LOS_DL_LIST_FOR_EACH_ENTRY

-

遍历指定双向链表,获取包含该链表节点的结构体地址

-

LOS_DL_LIST_FOR_EACH_ENTRY_SAFE

-

遍历指定双向链表,获取包含该链表节点的结构体地址,并存储包含当前节点的后继节点的结构体地址

-
- -## 开发流程 - -双向链表的典型开发流程: - -1. 调用LOS\_ListInit/LOS\_DL\_LIST\_HEAD初始双向链表。 -2. 调用LOS\_ListAdd向链表插入节点。 -3. 调用LOS\_ListTailInsert向链表尾部插入节点。 -4. 调用LOS\_ListDelete删除指定节点。 -5. 调用LOS\_ListEmpty判断链表是否为空。 -6. 调用LOS\_ListDelInit删除指定节点并以此节点初始化链表。 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->- 需要注意节点指针前后方向的操作。 ->- 链表操作接口,为底层接口,不对入参进行判空,需要使用者确保传参合法。 ->- 如果链表节点的内存是动态申请的,删除节点时,要注意释放内存。 - -### 编程实例 - -**实例描述** - -本实例实现如下功能: - -1. 初始化双向链表。 -2. 增加节点。 -3. 删除节点。 -4. 测试操作是否成功。 - -``` -#include "stdio.h" -#include "los_list.h" - -static UINT32 ListSample(VOID) -{ - LOS_DL_LIST listHead = {NULL,NULL}; - LOS_DL_LIST listNode1 = {NULL,NULL}; - LOS_DL_LIST listNode2 = {NULL,NULL}; - - //首先初始化链表 - PRINTK("Initial head\n"); - LOS_ListInit(&listHead); - - //添加节点1和节点2,并校验他们的相互关系 - LOS_ListAdd(&listHead, &listNode1); - if (listNode1.pstNext == &listHead && listNode1.pstPrev == &listHead) { - PRINTK("Add listNode1 success\n"); - } - - LOS_ListTailInsert(&listHead, &listNode2); - if (listNode2.pstNext == &listHead && listNode2.pstPrev == &listNode1) { - PRINTK("Tail insert listNode2 success\n"); - } - - //删除两个节点 - LOS_ListDelete(&listNode1); - LOS_ListDelete(&listNode2); - - //确认链表为空 - if (LOS_ListEmpty(&listHead)) { - PRINTK("Delete success\n"); - } - - return LOS_OK; -} -``` - -**结果验证** - -编译运行得到的结果为: - -``` -Initial head -Add listNode1 success -Tail insert listNode2 success -Delete success -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/06.\351\231\204\345\275\225/01.\345\237\272\346\234\254\346\225\260\346\215\256\347\273\223\346\236\204/02.\344\275\215\346\223\215\344\275\234.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/06.\351\231\204\345\275\225/01.\345\237\272\346\234\254\346\225\260\346\215\256\347\273\223\346\236\204/02.\344\275\215\346\223\215\344\275\234.md" deleted file mode 100644 index 225a484e63695ba47a3a29ad27517c49fe7cb622..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/06.\351\231\204\345\275\225/01.\345\237\272\346\234\254\346\225\260\346\215\256\347\273\223\346\236\204/02.\344\275\215\346\223\215\344\275\234.md" +++ /dev/null @@ -1,138 +0,0 @@ ---- -title: 位操作 -permalink: /pages/01050102060102 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# 位操作 - -- [基本概念](#section1990715203418) -- [功能说明](#section848334511411) -- [编程实例](#section67569495514) - - [实例描述](#section33551554391) - - [结果验证](#section8931859194) - - -## 基本概念 - -位操作是指对二进制数的bit位进行操作。程序可以设置某一变量为状态字,状态字中的每一bit位(标志位)可以具有自定义的含义。 - -## 功能说明 - -系统提供标志位的置1和清0操作,可以改变标志位的内容,同时还提供获取状态字中标志位为1的最高位和最低位的功能。用户也可以对系统的寄存器进行位操作。位操作模块为用户提供下面几种功能,接口详细信息可以查看API参考。 - -**表 1** 位操作模块接口 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名称

-

描述

-

置1/清0标志位

-

LOS_BitmapSet

-

对状态字的某一标志位进行置1操作

-

LOS_BitmapClr

-

对状态字的某一标志位进行清0操作

-

获取标志位为1的bit位

-

LOS_HighBitGet

-

获取状态字中为1的最高位

-

LOS_LowBitGet

-

获取状态字中为1的最低位

-

连续bit位操作

-

LOS_BitmapSetNBits

-

对状态字的连续标志位进行置1操作

-

LOS_BitmapClrNBits

-

对状态字的连续标志位进行清0操作

-

LOS_BitmapFfz

-

获取从最低有效位开始的第一个0的bit位

-
- -## 编程实例 - -### 实例描述 - -对数据实现位操作,本实例实现如下功能: - -1. 某一标志位置1。 -2. 获取标志位为1的最高bit位。 -3. 某一标志位清0。 -4. 获取标志位为1的最低bit位。 - -``` -#include "los_bitmap.h" -#include "los_printf.h" - -static UINT32 BitSample(VOID) -{ - UINT32 flag = 0x10101010; - UINT16 pos; - - PRINTK("\nBitmap Sample!\n"); - PRINTK("The flag is 0x%8x\n", flag); - - pos = 8; - LOS_BitmapSet(&flag, pos); - PRINTK("LOS_BitmapSet:\t pos : %d, the flag is 0x%0+8x\n", pos, flag); - - pos = LOS_HighBitGet(flag); - PRINTK("LOS_HighBitGet:\t The highest one bit is %d, the flag is 0x%0+8x\n", pos, flag); - - LOS_BitmapClr(&flag, pos); - PRINTK("LOS_BitmapClr:\t pos : %d, the flag is 0x%0+8x\n", pos, flag); - - pos = LOS_LowBitGet(flag); - PRINTK("LOS_LowBitGet:\t The lowest one bit is %d, the flag is 0x%0+8x\n\n", pos, flag); - - return LOS_OK; -} -``` - -### 结果验证 - -编译运行得到的结果为: - -``` -Bitmap Sample! -The flag is 0x10101010 -LOS_BitmapSet: pos : 8, the flag is 0x10101110 -LOS_HighBitGet:The highest one bit is 28, the flag is 0x10101110 -LOS_BitmapClr: pos : 28, the flag is 0x00101110 -LOS_LowBitGet: The lowest one bit is 4, the flag is 0x00101110 -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/06.\351\231\204\345\275\225/02.\346\240\207\345\207\206\345\272\223.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/06.\351\231\204\345\275\225/02.\346\240\207\345\207\206\345\272\223.md" deleted file mode 100644 index 14cffac878bf78aa0fb767c7c22ba8b7437e6a8d..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/02.\345\260\217\345\236\213\347\263\273\347\273\237\345\206\205\346\240\270/06.\351\231\204\345\275\225/02.\346\240\207\345\207\206\345\272\223.md" +++ /dev/null @@ -1,300 +0,0 @@ ---- -title: 标准库 -permalink: /pages/010501020602 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# 标准库 - -- [标准库接口框架](#section149319478561) -- [操作实例](#section20874620185915) -- [与Linux标准库差异](#section6555642165713) - - [进程](#section11299104511409) - - [内存](#section175754484116) - - [文件系统](#section118191113134220) - - [信号](#section195939264421) - - [Time](#section20825124304213) - - -OpenHarmony内核使用musl libc库,支持标准POSIX接口,开发者可基于POSIX标准接口开发内核之上的组件及应用。 - -## 标准库接口框架 - -**图 1** POSIX接口框架 -![](/images/device-dev/kernel/figure/POSIX接口框架.png "POSIX接口框架") - -musl libc库支持POSIX标准,涉及的系统调用相关接口由OpenHarmony内核适配支持 ,以满足接口对外描述的功能要求。 - -标准库支持接口的详细情况请参考C库的API文档,其中也涵盖了与POSIX标准之间的差异说明。 - -## 操作实例 - -在本示例中,主线程创建了THREAD\_NUM个子线程,每个子线程启动后等待被主线程唤醒,主线程成功唤醒所有子线程后,子线程继续执行直至生命周期结束,同时主线程通过pthread\_join方法等待所有线程执行结束。 - -``` -#include -#include -#include - -#ifdef __cplusplus -#if __cplusplus -extern "C" { -#endif /* __cplusplus */ -#endif /* __cplusplus */ - -#define THREAD_NUM 3 -int g_startNum = 0; /* 启动的线程数 */ -int g_wakenNum = 0; /* 唤醒的线程数 */ - -struct testdata { - pthread_mutex_t mutex; - pthread_cond_t cond; -} g_td; - -/* - * 子线程入口函数 - */ -static void *ChildThreadFunc(void *arg) -{ - int rc; - pthread_t self = pthread_self(); - - /* 获取mutex锁 */ - rc = pthread_mutex_lock(&g_td.mutex); - if (rc != 0) { - printf("ERROR:take mutex lock failed, error code is %d!\n", rc); - goto EXIT; - } - - /* g_startNum计数加一,用于统计已经获得mutex锁的子线程个数 */ - g_startNum++; - - /* 等待cond条件变量 */ - rc = pthread_cond_wait(&g_td.cond, &g_td.mutex); - if (rc != 0) { - printf("ERROR: pthread condition wait failed, error code is %d!\n", rc); - (void)pthread_mutex_unlock(&g_td.mutex); - goto EXIT; - } - - /* 尝试获取mutex锁,正常场景,此处无法获取锁 */ - rc = pthread_mutex_trylock(&g_td.mutex); - if (rc == 0) { - printf("ERROR: mutex gets an abnormal lock!\n"); - goto EXIT; - } - - /* g_wakenNum计数加一,用于统计已经被cond条件变量唤醒的子线程个数 */ - g_wakenNum++; - - /* 释放mutex锁 */ - rc = pthread_mutex_unlock(&g_td.mutex); - if (rc != 0) { - printf("ERROR: mutex release failed, error code is %d!\n", rc); - goto EXIT; - } -EXIT: - return NULL; -} - -static int testcase(void) -{ - int i, rc; - pthread_t thread[THREAD_NUM]; - - /* 初始化mutex锁 */ - rc = pthread_mutex_init(&g_td.mutex, NULL); - if (rc != 0) { - printf("ERROR: mutex init failed, error code is %d!\n", rc); - goto ERROROUT; - } - - /* 初始化cond条件变量 */ - rc = pthread_cond_init(&g_td.cond, NULL); - if (rc != 0) { - printf("ERROR: pthread condition init failed, error code is %d!\n", rc); - goto ERROROUT; - } - - /* 批量创建THREAD_NUM个子线程 */ - for (i = 0; i < THREAD_NUM; i++) { - rc = pthread_create(&thread[i], NULL, ChildThreadFunc, NULL); - if (rc != 0) { - printf("ERROR: pthread create failed, error code is %d!\n", rc); - goto ERROROUT; - } - } - - /* 等待所有子线程都完成mutex锁的获取 */ - while (g_startNum < THREAD_NUM) { - usleep(100); - } - - /* 获取mutex锁,确保所有子线程都阻塞在pthread_cond_wait上 */ - rc = pthread_mutex_lock(&g_td.mutex); - if (rc != 0) { - printf("ERROR: mutex lock failed, error code is %d\n", rc); - goto ERROROUT; - } - - /* 释放mutex锁 */ - rc = pthread_mutex_unlock(&g_td.mutex); - if (rc != 0) { - printf("ERROR: mutex unlock failed, error code is %d!\n", rc); - goto ERROROUT; - } - - for (int j = 0; j < THREAD_NUM; j++) { - /* 在cond条件变量上广播信号 */ - rc = pthread_cond_signal(&g_td.cond); - if (rc != 0) { - printf("ERROR: pthread condition failed, error code is %d!\n", rc); - goto ERROROUT; - } - } - - sleep(1); - - /* 检查是否所有子线程都已被唤醒 */ - if (g_wakenNum != THREAD_NUM) { - printf("ERROR: not all threads awaken, only %d thread(s) awaken!\n", g_wakenNum); - goto ERROROUT; - } - - /* join所有子线程,即等待其结束 */ - for (i = 0; i < THREAD_NUM; i++) { - rc = pthread_join(thread[i], NULL); - if (rc != 0) { - printf("ERROR: pthread join failed, error code is %d!\n", rc); - goto ERROROUT; - } - } - - /* 销毁cond条件变量 */ - rc = pthread_cond_destroy(&g_td.cond); - if (rc != 0) { - printf("ERROR: pthread condition destroy failed, error code is %d!\n", rc); - goto ERROROUT; - } - return 0; -ERROROUT: - return -1; -} - -/* - * 示例代码主函数 - */ -int main(int argc, char *argv[]) -{ - int rc; - - /* 启动测试函数 */ - rc = testcase(); - if (rc != 0) { - printf("ERROR: testcase failed!\n"); - } - - return 0; -} -#ifdef __cplusplus -#if __cplusplus -} -#endif /* __cplusplus */ -#endif /* __cplusplus */ -``` - -## 与Linux标准库差异 - -本节描述了OpenHarmony内核承载的标准库与Linux标准库之间存在的关键差异。更多差异详见C库API文档说明。 - -### 进程 - -1. OpenHarmony用户态**进程**优先级只支持静态优先级且用户态可配置的优先级范围为10\(最高优先级\)-31\(最低优先级)。 -2. OpenHarmony用户态**线程**优先级只支持静态优先级且用户态可配置的优先级范围为0\(最高优先级\)-31\(最低优先级)。 -3. OpenHarmony进程调度策略只支持SCHED\_RR, 线程调度策略支持SCHED\_RR和SCHED\_FIFO。 - -### 内存 - -**h2****与Linux mmap的差异** - -mmap接口原型为:void \*mmap \(void \*addr, size\_t length, int prot, int flags, int fd, off\_t offset\)。 - -其中,参数fd的生命周期实现与Linux glibc存在差异。具体体现在,glibc在成功调用mmap进行映射后,可以立即释放fd句柄。在OpenHarmony内核中,不允许用户在映射成功后立即关闭相关fd,只允许在取消映射munmap后再进行fd的close操作。如果用户不进行fd的close操作,操作系统将在进程退出时对该fd进行回收。 - -**h2****代码举例** - -Linux目前支持的情况如下: - -``` -int main(int argc, char *argv[]) -{ - int fd; - void *addr = NULL; - ... - fd = open(argv[1], O_RDONLY); - if (fd == -1){ - perror("open"); - exit(EXIT_FAILURE); - } - addr = mmap(NULL, length, PROT_READ, MAP_PRIVATE, fd, offset); - if (addr == MAP_FAILED) { - perror("mmap"); - exit(EXIT_FAILURE); - } - close(fd); /* OpenHarmony does not support closing fd immediately after the mapping is successful. */ - ... - exit(EXIT_SUCCESS); -} -``` - -OpenHarmony支持的情况如下: - -``` -int main(int argc, char *argv[]) -{ - int fd; - void *addr = NULL; - ... - fd = open(argv[1], O_RDONLY); - if (fd == -1) { - perror("open"); - exit(EXIT_FAILURE); - } - addr = mmap(NULL, length, PROT_READ, MAP_PRIVATE, fd, offset); - if (addr == MAP_FAILED) { - perror("mmap"); - exit(EXIT_FAILURE); - } - ... - munmap(addr, length); - close(fd); /* Close fd after the munmap is canceled. */ - exit(EXIT_SUCCESS); -} -``` - -### 文件系统 - -**系统目录**:用户无权限修改系统目录和设备挂载目录。包含/dev,/proc,/app,/bin,/data,/etc,/lib,/system,/usr目录。 - -**用户目录**:用户可以在该目录下进行文件创建、读写,但**不能进行设备挂载**。用户目录指/storage目录。 - -除**系统目录**与**用户目录**之外,用户可以自行创建文件夹进行设备的挂载。但是要注意,已挂载的文件夹及其子文件夹不允许重复或者嵌套挂载,非空文件夹不允许挂载。 - -### 信号 - -- 信号默认行为不支持STOP、CONTINUE、COREDUMP功能。 -- 无法通过信号唤醒正在睡眠状态(举例:进程调用sleep函数进入睡眠)的进程。原因:信号机制无唤醒功能,当且仅当进程被CPU调度运行时才能处理信号内容。 -- 进程退出后会发送SIGCHLD给父进程,发送动作无法取消。 -- 信号仅支持1-30号信号,接收方收到多次同一信号,仅执行一次回调函数。 - -### Time - -OpenHarmony当前时间精度以tick计算,系统默认10ms/tick。sleep、timeout系列函数时间误差<=20ms。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/03.\346\240\207\345\207\206\347\263\273\347\273\237\345\206\205\346\240\270/01.Linux\345\206\205\346\240\270\346\246\202\350\277\260.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/03.\346\240\207\345\207\206\347\263\273\347\273\237\345\206\205\346\240\270/01.Linux\345\206\205\346\240\270\346\246\202\350\277\260.md" deleted file mode 100644 index 42694226ed682041c48d2cb7d2a37525800e20de..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/03.\346\240\207\345\207\206\347\263\273\347\273\237\345\206\205\346\240\270/01.Linux\345\206\205\346\240\270\346\246\202\350\277\260.md" +++ /dev/null @@ -1,31 +0,0 @@ ---- -title: Linux内核概述 -permalink: /pages/0105010301 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# Linux内核概述 - -- [Linux内核版本](#section152847516485) -- [OpenHarmony内核版本选择](#section2716416191715) - -面向标准系统类设备(参考内存≥128MiB),OpenHarmony选择Linux内核作为基础内核,可以对不同资源受限的设备产品配置出适合的OS内核,为上层提供基础的操作系统能力。 - -## Linux内核版本 - -Linux内核版本分为稳定版本以及长期支持LTS\(long term support\)版本。 - -稳定版本大约每三个月发布一个新版本,包含最新硬件支持、性能改进以及bug修复等。其缺点是整体维护生命周期较短,产品软件不能得到长期稳定的支持。 - -LTS为长期支持版本,“长期支持”体现在对该版本内核的长期维护(对bug和安全方面的修复),一般维护周期达到6年之久。相较于维护周期从6个月到2年不等非LTS内核版本,对一款商用产品来说并不能覆盖其产品完整的生命周期,很有可能会使产品暴露于安全漏洞的风险之中。且LTS版本更新不会包含新的特性升级,保证了版本的稳定,这对追求稳定以及安全的商用产品来说LTS版本更为适合。 - -## OpenHarmony内核版本选择 - -OpenHarmony中Linux内核从LTS版本中选择合适的版本作为内核的基础版本,目前已完成对Linux-4.19及Linux-5.10的适配及支持。 diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/03.\346\240\207\345\207\206\347\263\273\347\273\237\345\206\205\346\240\270/02.OpenHarmony\345\274\200\345\217\221\346\235\277Patch\344\275\277\347\224\250\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/03.\346\240\207\345\207\206\347\263\273\347\273\237\345\206\205\346\240\270/02.OpenHarmony\345\274\200\345\217\221\346\235\277Patch\344\275\277\347\224\250\346\214\207\345\257\274.md" deleted file mode 100644 index 7e203249f2851fdc0a8d63826ac707fe5a02e4cb..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/03.\346\240\207\345\207\206\347\263\273\347\273\237\345\206\205\346\240\270/02.OpenHarmony\345\274\200\345\217\221\346\235\277Patch\344\275\277\347\224\250\346\214\207\345\257\274.md" +++ /dev/null @@ -1,48 +0,0 @@ ---- -title: OpenHarmony开发板Patch使用指导 -permalink: /pages/0105010302 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# OpenHarmony开发板Patch使用指导 - -1. 合入HDF补丁 - - 在kernel/linux/build仓中,按照kernel.mk中HDF的补丁合入方法,合入不同内核版本对应的HDF内核补丁: - - ``` - $(OHOS_BUILD_HOME)/drivers/adapter/khdf/linux/patch_hdf.sh $(OHOS_BUILD_HOME) $(KERNEL_SRC_TMP_PATH) $(HDF_PATCH_FILE) - ``` - -2. 合入芯片平台驱动补丁 - - 以Hi3516DV300为例: - - 在kernel/linux/build仓中,按照kernel.mk中的芯片组件所对应的patch路径规则及命名规则,将对应的芯片组件patch放到对应路径下: - - ``` - DEVICE_PATCH_DIR := $(OHOS_BUILD_HOME)/kernel/linux/patches/${KERNEL_VERSION}/$(DEVICE_NAME)_patch - DEVICE_PATCH_FILE := $(DEVICE_PATCH_DIR)/$(DEVICE_NAME).patch - ``` - -3. 修改自己所需要编译的config - - 在kernel/linux/build仓中,按照kernel.mk中的芯片组件所对应的patch路径规则及命名规则,将对应的芯片组件config放到对应路径下: - - ``` - KERNEL_CONFIG_PATH := $(OHOS_BUILD_HOME)/kernel/linux/config/${KERNEL_VERSION} - DEFCONFIG_FILE := $(DEVICE_NAME)_$(BUILD_TYPE)_defconfig - ``` - - > **须知:** - > - >由于OpenHarmony工程的编译构建流程中会拷贝kernel/linux/linux-\*\.\*的代码环境后进行打补丁动作,在使用OpenHarmony的版本级编译命令前,需要kernel/linux/linux-\*\.\*原代码环境。 - > - >根据不同系统工程,编译完成后会在out目录下的kernel目录中生成对应实际编译的内核,基于此目录的内核,进行对应的config修改,将最后生成的\.config文件cp到config仓对应的路径文件里,即可生效。 diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/03.\346\240\207\345\207\206\347\263\273\347\273\237\345\206\205\346\240\270/03.Linux\345\206\205\346\240\270\347\274\226\350\257\221\344\270\216\346\236\204\345\273\272\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/03.\346\240\207\345\207\206\347\263\273\347\273\237\345\206\205\346\240\270/03.Linux\345\206\205\346\240\270\347\274\226\350\257\221\344\270\216\346\236\204\345\273\272\346\214\207\345\257\274.md" deleted file mode 100644 index 5bd58c00c9c3b641118dca778db299710873c274..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/01.\345\206\205\346\240\270/03.\346\240\207\345\207\206\347\263\273\347\273\237\345\206\205\346\240\270/03.Linux\345\206\205\346\240\270\347\274\226\350\257\221\344\270\216\346\236\204\345\273\272\346\214\207\345\257\274.md" +++ /dev/null @@ -1,25 +0,0 @@ ---- -title: Linux内核编译与构建指导 -permalink: /pages/0105010303 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# Linux内核编译与构建指导 - -以hi3516dv300开源开发板+ubuntu x86主机开发环境为例 - -使用工程的全量编译命令,编译生成uImage内核镜像 - -``` -./build.sh --product-name Hi3516DV300 # 编译hi3516dv300镜像 - --build-target build_kernel # 编译hi3516dv300的uImage内核镜像 - --gn-args linux_kernel_version=\"linux-5.10\" # 编译指定内核版本 -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/01.HDF\351\251\261\345\212\250\346\241\206\346\236\266/01.HDF\345\274\200\345\217\221\346\246\202\350\277\260.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/01.HDF\351\251\261\345\212\250\346\241\206\346\236\266/01.HDF\345\274\200\345\217\221\346\246\202\350\277\260.md" deleted file mode 100644 index 7ed370705ef5c99a280e27681f89dabbeb5a0138..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/01.HDF\351\251\261\345\212\250\346\241\206\346\236\266/01.HDF\345\274\200\345\217\221\346\246\202\350\277\260.md" +++ /dev/null @@ -1,45 +0,0 @@ ---- -title: HDF开发概述 -permalink: /pages/0105020101 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# HDF开发概述 - -- [简介](#section0649162112376) -- [驱动加载](#section68701942154319) -- [驱动服务管理](#section12453133414412) -- [驱动消息机制](#section129410710451) - -## 简介 - -HDF(Hardware Driver Foundation)驱动框架,为驱动开发者提供驱动框架能力,包括驱动加载、驱动服务管理和驱动消息机制。旨在构建统一的驱动架构平台,为驱动开发者提供更精准、更高效的开发环境,力求做到一次开发,多系统部署。 - -## 驱动加载 - -HDF驱动加载包括按需加载和按序加载。 - -- 按需加载 - - HDF框架支持驱动在系统启动过程中默认加载,或者在系统启动之后动态加载。 - -- 按序加载 - - HDF框架支持驱动在系统启动的过程中按照驱动的优先级进行加载。 - - -## 驱动服务管理 - -HDF框架可以集中管理驱动服务,开发者可直接通过HDF框架对外提供的能力接口获取驱动相关的服务。 - -## 驱动消息机制 - -HDF框架提供统一的驱动消息机制,支持用户态应用向内核态驱动发送消息,也支持内核态驱动向用户态应用发送消息。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/01.HDF\351\251\261\345\212\250\346\241\206\346\236\266/02.\351\251\261\345\212\250\345\274\200\345\217\221.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/01.HDF\351\251\261\345\212\250\346\241\206\346\236\266/02.\351\251\261\345\212\250\345\274\200\345\217\221.md" deleted file mode 100644 index 61d469feca21e3764fa3f7c208cd84a0da04f174..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/01.HDF\351\251\261\345\212\250\346\241\206\346\236\266/02.\351\251\261\345\212\250\345\274\200\345\217\221.md" +++ /dev/null @@ -1,247 +0,0 @@ ---- -title: 驱动开发 -permalink: /pages/0105020102 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# 驱动开发 - -- [驱动模型介绍](#section157425168112) -- [驱动开发步骤](#section1969312275533) - -## 驱动模型介绍 - -HDF框架以组件化的驱动模型作为核心设计思路,为开发者提供更精细化的驱动管理,让驱动开发和部署更加规范。HDF框架将一类设备驱动放在同一个host里面,开发者也可以将驱动功能分层独立开发和部署,支持一个驱动多个node,HDF驱动模型如下图所示: - -**图 1** HDF驱动模型 -![](/images/device-dev/driver/figures/HDF驱动模型.png "HDF驱动模型") - -## 驱动开发步骤 - -基于HDF框架进行驱动的开发主要分为两个部分,驱动实现和驱动配置,详细开发流程如下所示: - -1. 驱动实现 - - 驱动实现包含驱动业务代码和驱动入口注册,具体写法如下: - - - 驱动业务代码 - - ``` - #include "hdf_device_desc.h" // HDF框架对驱动开放相关能力接口的头文件 - #include "hdf_log.h" // HDF 框架提供的日志接口头文件 - - #define HDF_LOG_TAG "sample_driver" // 打印日志所包含的标签,如果不定义则用默认定义的HDF_TAG标签 - - //驱动对外提供的服务能力,将相关的服务接口绑定到HDF框架 - int32_t HdfSampleDriverBind(struct HdfDeviceObject *deviceObject) - { - HDF_LOGD("Sample driver bind success"); - return 0; - } - - // 驱动自身业务初始的接口 - int32_t HdfSampleDriverInit(struct HdfDeviceObject *deviceObject) - { - HDF_LOGD("Sample driver Init success"); - return 0; - } - - // 驱动资源释放的接口 - void HdfSampleDriverRelease(struct HdfDeviceObject *deviceObject) - { - HDF_LOGD("Sample driver release success"); - return; - } - ``` - - - 驱动入口注册到HDF框架 - - ``` - // 定义驱动入口的对象,必须为HdfDriverEntry(在hdf_device_desc.h中定义)类型的全局变量 - struct HdfDriverEntry g_sampleDriverEntry = { - .moduleVersion = 1, - .moduleName = "sample_driver", - .Bind = HdfSampleDriverBind, - .Init = HdfSampleDriverInit, - .Release = HdfSampleDriverRelease, - }; - - // 调用HDF_INIT将驱动入口注册到HDF框架中,在加载驱动时HDF框架会先调用Bind函数,再调用Init函数加载该驱动,当Init调用异常时,HDF框架会调用Release释放驱动资源并退出。 - HDF_INIT(g_sampleDriverEntry); - ``` - -2. 驱动编译 - - - liteos - - 涉及makefile和BUILD.gn修改: - - * makefile部分: - - 驱动代码的编译必须要使用HDF框架提供的Makefile模板进行编译。 - - ``` - include $(LITEOSTOPDIR)/../../drivers/adapter/khdf/liteos/lite.mk #导入hdf预定义内容,必需 - MODULE_NAME := #生成的结果文件 - LOCAL_INCLUDE := #本驱动的头文件目录 - LOCAL_SRCS := #本驱动的源代码文件 - LOCAL_CFLAGS := #自定义的编译选项 - include $(HDF_DRIVER) #导入模板makefile完成编译 - ``` - - 编译结果文件链接到内核镜像,添加到drivers/adapter/khdf/liteos目录下的hdf_lite.mk里面,示例如下: - - ``` - LITEOS_BASELIB += -lxxx #链接生成的静态库 - LIB_SUBDIRS += #驱动代码Makefile的目录 - ``` - - * BUILD.gn部分: - - 添加模块BUILD.gn参考定义如下内容: - - ``` - import("//build/lite/config/component/lite_component.gni") - import("//drivers/adapter/khdf/liteos/hdf.gni") - module_switch = defined(LOSCFG_DRIVERS_HDF_xxx) - module_name = "xxx" - hdf_driver(module_name) { - sources = [ - "xxx/xxx/xxx.c", #模块要编译的源码文件 - ] - public_configs = [ ":public" ] #使用依赖的头文件配置 - } - config("public") { #定义依赖的头文件配置 - include_dirs = [ - "xxx/xxx/xxx", #依赖的头文件目录 - ] - } - ``` - - 把新增模块的BUILD.gn所在的目录添加到/drivers/adapter/khdf/liteos/BUILD.gn里面: - - ``` - group("liteos") { - public_deps = [ ":$module_name" ] - deps = [ - "xxx/xxx", #新增模块BUILD.gn所在的目录,目录结构相对于/drivers/adapter/khdf/liteos - ] - } - ``` - - - linux - - 如果需要定义模块控制宏,需要在模块目录xxx里面添加Kconfig文件,并把Kconfig文件路径添加到drivers/adapter/khdf/linux/Kconfig里面: - - ``` - source "drivers/hdf/khdf/xxx/Kconfig" #目录为hdf模块软链接到kernel里面的目录 - ``` - - 添加模块目录到drivers/adapter/khdf/linux/Makefile: - - ``` - obj-$(CONFIG_DRIVERS_HDF) += xxx/ - ``` - - 在模块目录xxx里面添加Makefile文件,在Makefile文件里面添加模块代码编译规则: - - ``` - obj-y += xxx.o - ``` - - - - -3. 驱动配置 - - HDF使用HCS作为配置描述源码,HCS详细介绍参考[配置管理](/pages/0105020105)介绍。 - - 驱动配置包含两部分,HDF框架定义的驱动设备描述和驱动的私有配置信息,具体写法如下: - - - 驱动设备描述(必选) - - HDF框架加载驱动所需要的信息来源于HDF框架定义的驱动设备描述,因此基于HDF框架开发的驱动必须要在HDF框架定义的device\_info.hcs配置文件中添加对应的设备描述,驱动的设备描述填写如下所示: - - ``` - root { - device_info { - match_attr = "hdf_manager"; - template host { // host模板,继承该模板的节点(如下sample_host)如果使用模板中的默认值,则节点字段可以缺省 - hostName = ""; - priority = 100; - template device { - template deviceNode { - policy = 0; - priority = 100; - preload = 0; - permission = 0664; - moduleName = ""; - serviceName = ""; - deviceMatchAttr = ""; - } - } - } - sample_host :: host{ - hostName = "host0"; // host名称,host节点是用来存放某一类驱动的容器 - priority = 100; // host启动优先级(0-200),值越大优先级越低,建议默认配100,优先级相同则不保证host的加载顺序 - device_sample :: device { // sample设备节点 - device0 :: deviceNode { // sample驱动的DeviceNode节点 - policy = 1; // policy字段是驱动服务发布的策略,在驱动服务管理章节有详细介绍 - priority = 100; // 驱动启动优先级(0-200),值越大优先级越低,建议默认配100,优先级相同则不保证device的加载顺序 - preload = 0; // 驱动按需加载字段,在本章节最后的说明有详细介绍 - permission = 0664; // 驱动创建设备节点权限 - moduleName = "sample_driver"; // 驱动名称,该字段的值必须和驱动入口结构的moduleName值一致 - serviceName = "sample_service"; // 驱动对外发布服务的名称,必须唯一 - deviceMatchAttr = "sample_config"; // 驱动私有数据匹配的关键字,必须和驱动私有数据配置表中的match_attr值相等 - } - } - } - } - } - ``` - - - 驱动私有配置信息(可选) - - 如果驱动有私有配置,则可以添加一个驱动的配置文件,用来填写一些驱动的默认配置信息,HDF框架在加载驱动的时候,会将对应的配置信息获取并保存在HdfDeviceObject 中的property里面,通过Bind和Init(参考[驱动开发](#li35182436435))传递给驱动,驱动的配置信息示例如下: - - ``` - root { - SampleDriverConfig { - sample_version = 1; - sample_bus = "I2C_0"; - match_attr = "sample_config"; //该字段的值必须和device_info.hcs中的deviceMatchAttr值一致 - } - } - ``` - - 配置信息定义之后,需要将该配置文件添加到板级配置入口文件hdf.hcs(这一块可以通过OpenHarmony驱动子系统在DevEco集成驱动开发套件工具一键式配置,具体使用方法参考驱动开发套件中的介绍),示例如下: - - ``` - #include "device_info/device_info.hcs" - #include "sample/sample_config.hcs" - ``` - - - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->驱动加载方式支持按需加载和按序加载两种方式,具体使用方法如下: ->- 按需加载 -> ``` -> typedef enum { -> DEVICE_PRELOAD_ENABLE = 0, -> DEVICE_PRELOAD_ENABLE_STEP2, -> DEVICE_PRELOAD_DISABLE, -> DEVICE_PRELOAD_INVALID -> } DevicePreload; -> ``` -> 配置文件中preload 字段配成 0 (DEVICE\_PRELOAD\_ENABLE ),则系统启动过程中默认加载;配成1(DEVICE\_PRELOAD\_ENABLE\_STEP2),当系统支持快启的时候,则在系统完成之后再加载这一类驱动,否则和DEVICE\_PRELOAD\_ENABLE 含义相同;配成2(DEVICE\_PRELOAD\_DISABLE),则系统启动过程中默认不加载,支持后续动态加载,当用户态获取驱动服务(参考[消息机制](/pages/0105020104))时,如果驱动服务不存在时,HDF框架会尝试动态加载该驱动。 ->- 按序加载(需要驱动为默认加载) -> 配置文件中的priority(取值范围为整数0到200)是用来表示host和驱动的优先级,不同的host内的驱动,host的priority值越小,驱动加载优先级越高;同一个host内驱动的priority值越小,加载优先级越高。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/01.HDF\351\251\261\345\212\250\346\241\206\346\236\266/03.\351\251\261\345\212\250\346\234\215\345\212\241\347\256\241\347\220\206.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/01.HDF\351\251\261\345\212\250\346\241\206\346\236\266/03.\351\251\261\345\212\250\346\234\215\345\212\241\347\256\241\347\220\206.md" deleted file mode 100644 index fb628f7344f304f18e6ef9bf742fb1af3b0ba764..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/01.HDF\351\251\261\345\212\250\346\241\206\346\236\266/03.\351\251\261\345\212\250\346\234\215\345\212\241\347\256\241\347\220\206.md" +++ /dev/null @@ -1,178 +0,0 @@ ---- -title: 驱动服务管理 -permalink: /pages/0105020103 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# 驱动服务管理 - -- [使用场景](#section14244270117) -- [接口说明](#section1432412561722) -- [开发步骤](#section393515164416) - -驱动服务是HDF驱动设备对外提供能力的对象,由HDF框架统一管理。驱动服务管理主要包含驱动服务的发布和获取。 - -HDF框架定义了驱动对外发布服务的策略,是由配置文件中的policy字段来控制,policy字段的取值范围以及含义如下: - -``` -typedef enum { - /* 驱动不提供服务 */ - SERVICE_POLICY_NONE = 0, - /* 驱动对内核态发布服务 */ - SERVICE_POLICY_PUBLIC = 1, - /* 驱动对内核态和用户态都发布服务 */ - SERVICE_POLICY_CAPACITY = 2, - /* 驱动服务不对外发布服务,但可以被订阅 */ - SERVICE_POLICY_FRIENDLY = 3, - /* 驱动私有服务不对外发布服务,也不能被订阅 */ - SERVICE_POLICY_PRIVATE = 4, - /* 错误的服务策略 */ - SERVICE_POLICY_INVALID -} ServicePolicy; -``` - -## 使用场景 - -当驱动以接口的形式对外提供能力时,可以使用HDF框架的驱动服务管理能力。 - -## 接口说明 - -针对驱动服务管理功能,HDF框架开放了以下接口供开发者调用,如下表所示: - -**表 1** 服务管理接口 - - - - - - - - - - - - - - - - -

方法

-

描述

-

int32_t (*Bind)(struct HdfDeviceObject *deviceObject);

-

需要驱动开发者实现Bind函数,将自己的服务接口绑定到HDF框架中。

-

const struct HdfObject *DevSvcManagerClntGetService(const char *svcName);

-

获取驱动的服务。

-

int HdfDeviceSubscribeService(

-

struct HdfDeviceObject *deviceObject, const char *serviceName, struct SubscriberCallback callback);

-

订阅驱动的服务。

-
- -## 开发步骤 - -驱动服务管理的开发包括驱动服务的编写、绑定、获取或者订阅,详细步骤如下。 - -1. 驱动服务发布。 - - ``` - 驱动服务结构的定义 - struct ISampleDriverService { - struct IDeviceIoService ioService; // 服务结构的首个成员必须是IDeviceIoService类型的成员 - int32_t (*ServiceA)(void); // 驱动的第一个服务接口 - int32_t (*ServiceB)(uint32_t inputCode); // 驱动的第二个服务接口,有多个可以依次往下累加 - }; - - 驱动服务接口的实现 - int32_t SampleDriverServiceA(void) - { - // 驱动开发者实现业务逻辑 - return 0; - } - - int32_t SampleDriverServiceB(uint32_t inputCode) - { - // 驱动开发者实现业务逻辑 - return 0; - } - ``` - -2. 驱动服务绑定到HDF框架中,实现HdfDriverEntry中的Bind指针函数。 - - ``` - int32_t SampleDriverBind(struct HdfDeviceObject *deviceObject) - { - // deviceObject为HDF框架给每一个驱动创建的设备对象,用来保存设备相关的私有数据和服务接口 - if (deviceObject == NULL) { - HDF_LOGE("Sample device object is null!"); - return -1; - } - static struct ISampleDriverService sampleDriverA = { - .ServiceA = SampleDriverServiceA, - .ServiceB = SampleDriverServiceB, - }; - deviceObject->service = &sampleDriverA.ioService; - return 0; - } - ``` - -3. 驱动服务获取。 - - 驱动服务的获取有两种方式,HDF框架提供接口直接获取和HDF框架提供订阅机制获取。 - - - 通过HDF接口直接获取 - - 当明确驱动已经加载完成时,获取该驱动的服务可以通过HDF框架提供的能力接口直接获取,如下所示: - - ``` - const struct ISampleDriverService *sampleService = - (const struct ISampleDriverService *)DevSvcManagerClntGetService("sample_driver"); - if (sampleService == NULL) { - return -1; - } - sampleService->ServiceA(); - sampleService->ServiceB(5); - ``` - - - 通过HDF提供的订阅机制获取 - - 当内核态对驱动(同一个host)加载的时机不感知时,可以通过HDF框架提供的订阅机制来订阅该驱动,当该驱动加载完成时,HDF框架会将被订阅的驱动服务发布给订阅者,实现方式如下所示: - - ``` - // 订阅回调函数的编写,当被订阅的驱动加载完成后,HDF框架会将被订阅驱动的服务发布给订阅者,通过这个回调函数给订阅者使用 - // object为订阅者的私有数据,service为被订阅的服务对象 - int32_t TestDriverSubCallBack(struct HdfDeviceObject *deviceObject, const struct HdfObject *service) - { - const struct ISampleDriverService *sampleService = - (const struct ISampleDriverService *)service; - if (sampleService == NULL) { - return -1; - } - sampleService->ServiceA(); - sampleService->ServiceB(5); - } - // 订阅过程的实现 - int32_t TestDriverInit(struct HdfDeviceObject *deviceObject) - { - if (deviceObject == NULL) { - HDF_LOGE("Test driver init failed, deviceObject is null!"); - return -1; - } - struct SubscriberCallback callBack; - callBack.deviceObject = deviceObject; - callBack.OnServiceConnected = TestDriverSubCallBack; - int32_t ret = HdfDeviceSubscribeService(deviceObject, "sample_driver", callBack); - if (ret != 0) { - HDF_LOGE("Test driver subscribe sample driver failed!"); - } - return ret; - } - ``` - - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/01.HDF\351\251\261\345\212\250\346\241\206\346\236\266/04.\351\251\261\345\212\250\346\266\210\346\201\257\346\234\272\345\210\266\347\256\241\347\220\206.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/01.HDF\351\251\261\345\212\250\346\241\206\346\236\266/04.\351\251\261\345\212\250\346\266\210\346\201\257\346\234\272\345\210\266\347\256\241\347\220\206.md" deleted file mode 100644 index 325f0f31965b5c531a6eb6ae5c4bc9abee6fa6e2..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/01.HDF\351\251\261\345\212\250\346\241\206\346\236\266/04.\351\251\261\345\212\250\346\266\210\346\201\257\346\234\272\345\210\266\347\256\241\347\220\206.md" +++ /dev/null @@ -1,206 +0,0 @@ ---- -title: 驱动消息机制管理 -permalink: /pages/0105020104 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# 驱动消息机制管理 - -- [使用场景](#section33014541954) -- [接口说明](#section538852311616) -- [开发步骤](#section946912121153) - -## 使用场景 - -当用户态应用和内核态驱动需要交互时,可以使用HDF框架的消息机制来实现。 - -## 接口说明 - -消息机制的功能主要有以下两种: - -1. 用户态应用发送消息到驱动。 -2. 用户态应用接收驱动主动上报事件。 - -**表 1** 消息机制接口 - - - - - - - - - - - - - - - - - - - -

方法

-

描述

-

struct HdfIoService *HdfIoServiceBind(const char *serviceName)

-

用户态获取驱动的服务,获取该服务之后通过服务中的Dispatch方法向驱动发送消息。

-

void HdfIoServiceRecycle(struct HdfIoService *service);

-

释放驱动服务。

-

int HdfDeviceRegisterEventListener(struct HdfIoService *target, struct HdfDevEventlistener *listener);

-

用户态程序注册接收驱动上报事件的操作方法。

-

int HdfDeviceSendEvent(struct HdfDeviceObject *deviceObject, uint32_t id, struct HdfSBuf *data);

-

驱动主动上报事件接口。

-
- -## 开发步骤 - -1. 将驱动配置信息中服务策略policy字段设置为2(SERVICE\_POLICY\_CAPACITY,参考[policy定义](/pages/0105020103))。 - - ``` - device_sample :: Device { - policy = 2; - ... - } - ``` - -2. 配置驱动信息中的服务设备节点权限(permission字段)是框架给驱动创建设备节点的权限,默认是0666,驱动开发者根据驱动的实际使用场景配置驱动设备节点的权限。 -3. 在服务实现过程中,实现服务基类成员IDeviceIoService中的Dispatch方法。 - - ``` - // Dispatch是用来处理用户态发下来的消息 - int32_t SampleDriverDispatch(struct HdfDeviceObject *device, int cmdCode, struct HdfSBuf *data, struct HdfSBuf *reply) - { - HDF_LOGE("sample driver lite A dispatch"); - return 0; - } - int32_t SampleDriverBind(struct HdfDeviceObject *device) - { - HDF_LOGE("test for lite os sample driver A Open!"); - if (device == NULL) { - HDF_LOGE("test for lite os sample driver A Open failed!"); - return -1; - } - static struct ISampleDriverService sampleDriverA = { - .ioService.Dispatch = SampleDriverDispatch, - .ServiceA = SampleDriverServiceA, - .ServiceB = SampleDriverServiceB, - }; - device->service = (struct IDeviceIoService *)(&sampleDriverA); - return 0; - } - ``` - -4. 驱动定义消息处理函数中的cmd类型。 - - ``` - #define SAMPLE_WRITE_READ 1 // 读写操作码1 - ``` - -5. 用户态获取服务接口并发送消息到驱动。 - - ``` - int SendMsg(const char *testMsg) - { - if (testMsg == NULL) { - HDF_LOGE("test msg is null"); - return -1; - } - struct HdfIoService *serv = HdfIoServiceBind("sample_driver"); - if (serv == NULL) { - HDF_LOGE("fail to get service"); - return -1; - } - struct HdfSBuf *data = HdfSBufObtainDefaultSize(); - if (data == NULL) { - HDF_LOGE("fail to obtain sbuf data"); - return -1; - } - struct HdfSBuf *reply = HdfSBufObtainDefaultSize(); - if (reply == NULL) { - HDF_LOGE("fail to obtain sbuf reply"); - ret = HDF_DEV_ERR_NO_MEMORY; - goto out; - } - if (!HdfSbufWriteString(data, testMsg)) { - HDF_LOGE("fail to write sbuf"); - ret = HDF_FAILURE; - goto out; - } - int ret = serv->dispatcher->Dispatch(&serv->object, SAMPLE_WRITE_READ, data, reply); - if (ret != HDF_SUCCESS) { - HDF_LOGE("fail to send service call"); - goto out; - } - out: - HdfSBufRecycle(data); - HdfSBufRecycle(reply); - HdfIoServiceRecycle(serv); - return ret; - } - ``` - -6. 用户态接收该驱动上报的消息。 - 1. 用户态编写驱动上报消息的处理函数。 - - ``` - static int OnDevEventReceived(void *priv, uint32_t id, struct HdfSBuf *data) - { - OsalTimespec time; - OsalGetTime(&time); - HDF_LOGE("%s received event at %llu.%llu", (char *)priv, time.sec, time.usec); - - const char *string = HdfSbufReadString(data); - if (string == NULL) { - HDF_LOGE("fail to read string in event data"); - return -1; - } - HDF_LOGE("%s: dev event received: %d %s", (char *)priv, id, string); - return 0; - } - ``` - - 2. 用户态注册接收驱动上报消息的操作方法。 - - ``` - int RegisterListen() - { - struct HdfIoService *serv = HdfIoServiceBind("sample_driver"); - if (serv == NULL) { - HDF_LOGE("fail to get service"); - return -1; - } - static struct HdfDevEventlistener listener = { - .callBack = OnDevEventReceived, - .priv ="Service0" - }; - if (HdfDeviceRegisterEventListener(serv, &listener) != 0) { - HDF_LOGE("fail to register event listener"); - return -1; - } - ...... - HdfDeviceUnregisterEventListener(serv, &listener); - HdfIoServiceRecycle(serv); - return 0; - } - ``` - - 3. 驱动上报事件。 - - ``` - int32_t SampleDriverDispatch(struct HdfDeviceObject *device, int cmdCode, struct HdfSBuf *data, struct HdfSBuf *reply) - { - ... // process api call here - return HdfDeviceSendEvent(deviceObject, cmdCode, data); - } - ``` - - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/01.HDF\351\251\261\345\212\250\346\241\206\346\236\266/05.\351\205\215\347\275\256\347\256\241\347\220\206.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/01.HDF\351\251\261\345\212\250\346\241\206\346\236\266/05.\351\205\215\347\275\256\347\256\241\347\220\206.md" deleted file mode 100644 index e88af3fa6f0d19a38f1a4a7ab2052ddd09261daf..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/01.HDF\351\251\261\345\212\250\346\241\206\346\236\266/05.\351\205\215\347\275\256\347\256\241\347\220\206.md" +++ /dev/null @@ -1,450 +0,0 @@ ---- -title: 配置管理 -permalink: /pages/0105020105 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# 配置管理 - -- [配置概述](#section59914284576) -- [配置语法](#section533713333580) - - [关键字](#section4522107333) - - [基本结构](#section853042911312) - - [数据类型](#section177001259134) - - [预处理](#section14867121641) - - [注释](#section1323412417) - - [引用修改](#section193708571145) - - [节点复制](#section1487792020513) - - [删除](#section1096515391155) - - [属性引用](#section20271317611) - - [模板](#section958819191063) - -- [配置生成](#section106152531919) - - [hc-gen介绍](#section359734416616) - - -## 配置概述 - -HCS\(**H**DF **C**onfiguration **S**ource\)是HDF驱动框架的配置描述源码,内容以Key-Value为主要形式。它实现了配置代码与驱动代码解耦,便于开发者进行配置管理。 - -HC-GEN**\(H**DF **C**onfiguration **G**enerator**\)**是HCS配置转换工具,可以将HDF配置文件转换为软件可读取的文件格式: - -- 在弱性能环境中,转换为配置树源码,驱动可直接调用C代码获取配置。 -- 在高性能环境中,转换为HCB\(**H**DF **C**onfiguration **B**inary\)二进制文件,驱动可使用HDF框架提供的配置解析接口获取配置。 - -以下是使用HCB模式的典型应用场景: - -**图 1** 配置使用流程图 -![](/images/device-dev/driver/figures/配置使用流程图.png "配置使用流程图") - -HCS经过HC-GEN编译生成HCB文件,HDF驱动框架中的HCS Parser模块会从HCB文件中重建配置树,HDF驱动模块使用HCS Parser提供的配置读取接口获取配置内容。 - -## 配置语法 - -HCS的语法介绍如下: - -### 关键字 - -HCS配置语法保留了以下关键字。 - -**表 1** HCS配置语法保留关键字 - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

关键字

-

用途

-

说明

-

root

-

配置根节点

-

-

-

include

-

引用其他HCS配置文件

-

-

-

delete

-

删除节点或属性

-

只能用于操作include导入的配置树

-

template

-

定义模板节点

-

-

-

match_attr

-

用于标记节点的匹配查找属性

-

解析配置时可以使用该属性的值查找到对应节点

-
- -### 基本结构 - -HCS主要分为属性\(Attribute\)和节点\(Node\)两种结构。 - -**属性** - -属性即最小的配置单元,是一个独立的配置项。语法如下: - -``` - attribute_name = value; -``` - -- attribute\_name 是**字母、数字、下划线**的组合且必须以字母或下划线开头,字母区分大小写。 - -- value的可用格式如下: - - - 数字常量,支持二进制、八进制、十进制、十六进制数,具体参考数据类型节。 - - - 字符串,内容使用双引号\(""\)引用。 - - - 节点引用。 - - -- attribute 必须以分号\(;\)结束且必须属于一个node。 - - -**节点** - -节点是一组属性的集合,语法如下: - -``` - node_name { - module = "sample"; - ... - } -``` - -- node\_name 是**字母、数字、下划线**的组合且必须以字母或下划线开头,字母区分大小写。 - -- 大括号后无需添加结束符“;”。 - -- root为保留关键字,用于声明配置表的根节点。每个配置表必须以root节点开始。 - -- root节点中必须包含module属性,其值应该为一个字符串,用于表征该配置所属模块。 - -- 节点中可以增加match\_attr属性,其值为一个全局唯一的字符串。在解析配置时可以调用查找接口以该属性的值查找到包含该属性的节点。 - -### 数据类型 - -在属性定义中使用自动数据类型,不显式指定类型,属性支持的数据类型如下: - -**整型** - -整型长度自动推断,根据实际数据长度给与最小空间占用的类型。 - -- 二进制,0b前缀,示例:0b1010。 - -- 八进制,0前缀,示例:0664。 -- 十进制 ,无前缀,且支持有符号与无符号,示例:1024,+1024均合法。负值在读取时注意使用有符号数读取接口。 - -- 十六进制,0x前缀,示例:0xff00、0xFF。 - - -**字符串** - -字符串使用双引号\(""\)表示。 - -**数组** - -数组元素支持整型、字符串,不支持混合类型。整型数组中uint32\_t uint64\_t混用会向上转型为uint64\_t 数组。整型数组与字符串数组示例如下: - -``` -attr_foo = [0x01, 0x02, 0x03, 0x04]; -attr_bar = ["hello", "world"]; -``` - -**bool类型** - -bool类型中**true**表示真,**false**表示假。 - -### 预处理 - -**include** - -用于导入其他HCS文件。语法示例如下: - -``` -#include "foo.hcs" -#include "../bar.hcs" -``` - -- 文件名必须使用双引号\(""\),不在同一目录使用相对路径引用。被include文件也必须是合法的HCS文件。 -- 多个include,如果存在相同的节点,后者覆盖前者,其余的节点依次展开。 - -### 注释 - -支持两种注释风格。 - -- 单行注释。 - - ``` - // comment - ``` - -- 多行注释。 - - ``` - /* - comment - */ - ``` - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >多行注释不支持嵌套。 - - -### 引用修改 - -引用修改可以实现修改另外任意一个节点的内容,语法为: - -``` - node :& source_node -``` - -上述语句表示node中的内容是对source\_node节点内容的修改。示例如下: - -``` -root { - module = "sample"; - foo { - foo_ :& root.bar{ - attr = "foo"; - } - foo1 :& foo2 { - attr = 0x2; - } - foo2 { - attr = 0x1; - } - } - - bar { - attr = "bar"; - } -} -``` - -最终生成配置树为: - -``` -root { - module = "sample"; - foo { - foo2 { - attr = 0x2; - } - } - bar { - attr = "foo"; - } -} -``` - -在以上示例中,可以看到foo.foo\_节点通过引用将bar.attr属性的值修改为了"foo",foo.foo1节点通过引用将foo.foo2.attr属性的值修改为了0x2。foo.foo\_以及foo.foo1节点表示对目标节点内容的修改,其自身并不会存在最终生成的配置树中。 - -- 引用同级node,可以直接使用node名称,否则被引用的节点必须使用绝对路径,节点间使用“.”分隔,root表示根节点,格式为root开始的节点路径序列,例如root.foo.bar即为一个合法的绝对路径。 -- 如果出现修改冲突(即多处修改同一个属性),编译器将提示warning,因为这种情况下只会生效某一个修改而导致最终结果不确定。 - -### 节点复制 - -节点复制可以实现在节点定义时从另一个节点先复制内容,用于定义内容相似的节点。语法为: - -``` - node : source_node -``` - -上述语句表示在定义"node"节点时将另一个节点"source\_node"的属性复制过来。示例如下: - -``` -root { - module = "sample"; - foo { - attr_0 = 0x0; - } - bar:foo { - attr_1 = 0x1; - } -} -``` - -上述代码的最终生成配置树为: - -``` -root { - module = "sample"; - foo { - attr_0 = 0x0; - } - bar { - attr_1 = 0x1; - attr_0 = 0x0; - } -} -``` - -在上述示例中,编译后bar节点即包含attr\_0属性也包含attr\_1属性,在bar中对attr\_0的修改不会影响到foo。 - -在foo和bar在同级node中可不指定foo的路径,否则需要使用绝对路径引用,参考[引用修改](#section193708571145)。 - -### 删除 - -要对include导入的base配置树中不需要的节点或属性进行删除,可以使用delete关键字。下面的举例中sample1.hcs通过include导入了sample2.hcs中的配置内容,并使用delete删除了sample2.hcs中的attribute2属性和foo\_2节点,示例如下: - -``` -// sample2.hcs -root { - attr_1 = 0x1; - attr_2 = 0x2; - foo_2 { - t = 0x1; - } -} - -// sample1.hcs -#include "sample2.hcs" -root { - attr_2 = delete; - foo_2 : delete { - } -} -``` - -上述代码在生成过程中将会删除root.foo\_2节点与attr\_2,最终生成配置树为: - -``` -root { - attr_1 = 0x1; -} -``` - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->在同一个HCS文件中不允许使用delete,建议直接删除不需要的属性。 - -### 属性引用 - -为了在解析配置时快速定位到关联的节点,可以把节点作为属性的右值,通过读取属性查找到对应节点。语法为: - -``` - attribute = &node; -``` - -上述语句表示attribute的值是一个节点node的引用,在解析时可以用这个attribute快速定位到node,便于关联和查询其他node。示例如下: - -``` -node1 { - attributes; -} - -node2 { - attr_1 = &node1; -} -``` - -### 模板 - -模板的用途在于生成严格一致的node结构,以便对同类型node进行遍历和管理。 - -使用template关键字定义模板node,子node通过双冒号“::”声明继承关系。子节点可以改写但不能新增和删除template中的属性,子节点中没有定义的属性将使用template中的定义作为默认值。示例如下: - -``` -root { - module = "sample"; - template foo { - attr_1 = 0x1; - attr_2 = 0x2; - } - - bar :: foo { - } - - bar_1 :: foo { - attr_1 = 0x2; - } -} -``` - -生成配置树如下: - -``` -root { - module = "sample"; - bar { - attr_1 = 0x1; - attr_2 = 0x2; - } - bar_1 { - attr_1 = 0x2; - attr_2 = 0x2; - } -} -``` - -在上述示例中,bar和bar\_1节点继承了foo节点,生成配置树节点结构与foo保持了完全一致,只是属性的值不同。 - -## 配置生成 - -hc-gen是配置生成的工具,可以对HCS配置语法进行检查并把HCS源文件转化成HCB二进制文件。 - -### hc-gen介绍 - -hc-gen参数说明: - -``` -Usage: hc-gen [Options] [File] -options: - -o output file name, default same as input - -a hcb align with four bytes - -b output binary output, default enable - -t output config in C language source file style - -i output binary hex dump in C language source file style - -p prefix of generated symbol name - -d decompile hcb to hcs - -V show verbose info - -v show version - -h show this help message -``` - -生成.c/.h 配置文件方法: - -``` -hc-gen -o [OutputCFileName] -t [SourceHcsFileName] -``` - -生成HCB 配置文件方法: - -``` -hc-gen -o [OutputHcbFileName] -b [SourceHcsFileName] -``` - -反编译HCB文件为HCS方法: - -``` -hc-gen -o [OutputHcsFileName] -d [SourceHcbFileName] -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/01.HDF\351\251\261\345\212\250\346\241\206\346\236\266/06.HDF\345\274\200\345\217\221\345\256\236\344\276\213.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/01.HDF\351\251\261\345\212\250\346\241\206\346\236\266/06.HDF\345\274\200\345\217\221\345\256\236\344\276\213.md" deleted file mode 100644 index 3dacae86d80996a57945ea57458ff3135f147e7d..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/01.HDF\351\251\261\345\212\250\346\241\206\346\236\266/06.HDF\345\274\200\345\217\221\345\256\236\344\276\213.md" +++ /dev/null @@ -1,251 +0,0 @@ ---- -title: HDF开发实例 -permalink: /pages/0105020106 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# HDF开发实例 - -- [添加配置](#section27261067111) -- [编写驱动代码](#section177988005) -- [编写用户程序和驱动交互代码](#section6205173816412) - -下面基于HDF框架,提供一个完整的样例,包含配置文件的添加,驱动代码的实现以及用户态程序和驱动交互的流程。 - -## 添加配置 - -在HDF框架的配置文件(例如vendor/hisilicon/xxx/hdf_config/device\_info)中添加该驱动的配置信息,如下所示: - -``` -root { - device_info { - match_attr = "hdf_manager"; - template host { - hostName = ""; - priority = 100; - template device { - template deviceNode { - policy = 0; - priority = 100; - preload = 0; - permission = 0664; - moduleName = ""; - serviceName = ""; - deviceMatchAttr = ""; - } - } - } - sample_host :: host { - hostName = "sample_host"; - sample_device :: device { - device0 :: deviceNode { - policy = 2; - priority = 100; - preload = 1; - permission = 0664; - moduleName = "sample_driver"; - serviceName = "sample_service"; - } - } - } - } -} -``` - -## 编写驱动代码 - -基于HDF框架编写的sample驱动代码如下(编译参考 [驱动开发](/pages/0105020102)): - -``` -#include -#include -#include -#include "hdf_log.h" -#include "hdf_base.h" -#include "hdf_device_desc.h" - -#define HDF_LOG_TAG "sample_driver" - -#define SAMPLE_WRITE_READ 123 - -int32_t HdfSampleDriverDispatch( - struct HdfDeviceObject *deviceObject, int id, struct HdfSBuf *data, struct HdfSBuf *reply) -{ - HDF_LOGE("%s: received cmd %d", __func__, id); - if (id == SAMPLE_WRITE_READ) { - const char *readData = HdfSbufReadString(data); - if (readData != NULL) { - HDF_LOGE("%s: read data is: %s", __func__, readData); - } - if (!HdfSbufWriteInt32(reply, INT32_MAX)) { - HDF_LOGE("%s: reply int32 fail", __func__); - } - return HdfDeviceSendEvent(deviceObject, id, data); - } - return HDF_FAILURE; -} - -void HdfSampleDriverRelease(struct HdfDeviceObject *deviceObject) -{ - // release resources here - return; -} - -int HdfSampleDriverBind(struct HdfDeviceObject *deviceObject) -{ - if (deviceObject == NULL) { - return HDF_FAILURE; - } - static struct IDeviceIoService testService = { - .Dispatch = HdfSampleDriverDispatch, - }; - deviceObject->service = &testService; - return HDF_SUCCESS; -} - -int HdfSampleDriverInit(struct HdfDeviceObject *deviceObject) -{ - if (deviceObject == NULL) { - HDF_LOGE("%s::ptr is null!", __func__); - return HDF_FAILURE; - } - HDF_LOGE("Sample driver Init success"); - return HDF_SUCCESS; -} - -struct HdfDriverEntry g_sampleDriverEntry = { - .moduleVersion = 1, - .moduleName = "sample_driver", - .Bind = HdfSampleDriverBind, - .Init = HdfSampleDriverInit, - .Release = HdfSampleDriverRelease, -}; - -HDF_INIT(g_sampleDriverEntry); -``` - -## 编写用户程序和驱动交互代码 - -基于HDF框架编写的用户态程序和驱动交互的代码如下(代码可以放在目录drivers/adapter/uhdf下面编译,build.gn可以参考drivers/framework/sample/platform/uart/dev/build.gn): - -``` -#include -#include -#include -#include -#include "hdf_log.h" -#include "hdf_sbuf.h" -#include "hdf_io_service_if.h" - -#define HDF_LOG_TAG "sample_test" -#define SAMPLE_SERVICE_NAME "sample_service" - -#define SAMPLE_WRITE_READ 123 - -int g_replyFlag = 0; - -static int OnDevEventReceived(void *priv, uint32_t id, struct HdfSBuf *data) -{ - const char *string = HdfSbufReadString(data); - if (string == NULL) { - HDF_LOGE("fail to read string in event data"); - g_replyFlag = 1; - return HDF_FAILURE; - } - HDF_LOGE("%s: dev event received: %u %s", (char *)priv, id, string); - g_replyFlag = 1; - return HDF_SUCCESS; -} - -static int SendEvent(struct HdfIoService *serv, char *eventData) -{ - int ret = 0; - struct HdfSBuf *data = HdfSBufObtainDefaultSize(); - if (data == NULL) { - HDF_LOGE("fail to obtain sbuf data"); - return 1; - } - - struct HdfSBuf *reply = HdfSBufObtainDefaultSize(); - if (reply == NULL) { - HDF_LOGE("fail to obtain sbuf reply"); - ret = HDF_DEV_ERR_NO_MEMORY; - goto out; - } - - if (!HdfSbufWriteString(data, eventData)) { - HDF_LOGE("fail to write sbuf"); - ret = HDF_FAILURE; - goto out; - } - - ret = serv->dispatcher->Dispatch(&serv->object, SAMPLE_WRITE_READ, data, reply); - if (ret != HDF_SUCCESS) { - HDF_LOGE("fail to send service call"); - goto out; - } - - int replyData = 0; - if (!HdfSbufReadInt32(reply, &replyData)) { - HDF_LOGE("fail to get service call reply"); - ret = HDF_ERR_INVALID_OBJECT; - goto out; - } - HDF_LOGE("Get reply is: %d", replyData); -out: - HdfSBufRecycle(data); - HdfSBufRecycle(reply); - return ret; -} - -int main() -{ - char *sendData = "default event info"; - struct HdfIoService *serv = HdfIoServiceBind(SAMPLE_SERVICE_NAME); - if (serv == NULL) { - HDF_LOGE("fail to get service %s", SAMPLE_SERVICE_NAME); - return HDF_FAILURE; - } - - static struct HdfDevEventlistener listener = { - .callBack = OnDevEventReceived, - .priv ="Service0" - }; - - if (HdfDeviceRegisterEventListener(serv, &listener) != HDF_SUCCESS) { - HDF_LOGE("fail to register event listener"); - return HDF_FAILURE; - } - if (SendEvent(serv, sendData)) { - HDF_LOGE("fail to send event"); - return HDF_FAILURE; - } - - while (g_replyFlag == 0) { - sleep(1); - } - - if (HdfDeviceUnregisterEventListener(serv, &listener)) { - HDF_LOGE("fail to unregister listener"); - return HDF_FAILURE; - } - - HdfIoServiceRecycle(serv); - return HDF_SUCCESS; -} -``` - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->用户态应用程序使用了HDF框架中的消息发送接口,因此在编译用户态程序的过程中需要依赖HDF框架对外提供的hdf\_core和osal的动态库,在gn编译文件中添加如下依赖项: ->deps = \[ ->"//drivers/adapter/uhdf/manager:hdf\_core", ->"//drivers/adapter/uhdf/posix:hdf\_posix\_osal", ->\] - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/01.ADC.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/01.ADC.md" deleted file mode 100644 index c7b65be4c274e41db379e98b401bec6eebbfc3db..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/01.ADC.md" +++ /dev/null @@ -1,437 +0,0 @@ ---- -title: ADC -permalink: /pages/0105020201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# ADC - -- [概述](#section268031773165048) -- [接口说明](#section752964871810) -- [开发步骤](#section100579767165048) -- [开发实例](#section1745221471165048) - -## 概述 - -ADC(Analog to Digital Converter),即模拟-数字转换器,是一种将模拟信号转换成对应数字信号的设备,在HDF框架中,ADC模块接口适配模式采用统一服务模式,这需要一个设备服务来作为ADC模块的管理器,统一处理外部访问,这会在配置文件中有所体现。统一服务模式适合于同类型设备对象较多的情况,如ADC可能同时具备十几个控制器,采用独立服务模式需要配置更多的设备节点,且服务会占据内存资源。 - -**图 1** ADC统一服务模式 -![](/images/device-dev/driver/figures/统一服务模式结构图.png "ADC统一服务模式") - -## 接口说明 - -AdcMethod定义: - -``` -struct AdcMethod { - int32_t (*read)(struct AdcDevice *device, uint32_t channel, uint32_t *val); - int32_t (*start)(struct AdcDevice *device); - int32_t (*stop)(struct AdcDevice *device); -}; -``` - -**表 1** AdcMethod结构体成员的回调函数功能说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

函数成员

-

入参

-

出参

-

返回值

-

功能

-

read

-

device: 结构体指针,核心层ADC控制器;channel:uint32_t,传入的通道号;

-

val:uint32_t指针,要传出的信号数据;

-

HDF_STATUS相关状态

-

读取ADC采样的信号数据

-

stop

-

device: 结构体指针,核心层ADC控制器;

-

-

HDF_STATUS相关状态

-

关闭ADC设备

-

start

-

device: 结构体指针,核心层ADC控制器;

-

-

HDF_STATUS相关状态

-

开启ADC设备

-
- -## 开发步骤 - -ADC模块适配的三个环节是配置属性文件,实例化驱动入口,以及实例化核心层接口函数。 - -1. **实例化驱动入口:** - - 实例化HdfDriverEntry结构体成员。 - - 调用HDF\_INIT将HdfDriverEntry实例化对象注册到HDF框架中。 - -2. **配置属性文件:** - - 在device\_info.hcs文件中添加deviceNode描述。 - - 【可选】添加adc\_config.hcs器件属性文件。 - -3. **实例化ADC控制器对象:** - - 初始化AdcDevice成员。 - - 实例化AdcDevice成员AdcMethod。 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >实例化AdcDevice成员AdcMethod,其定义和成员说明见[接口说明](#section752964871810)。 - - -4. **驱动调试:** - - 【可选】针对新增驱动程序,建议验证驱动基本功能,例如挂载后的信息反馈,信号采集的成功与否等。 - - -## 开发实例 - -接下来以 adc\_hi35xx.c 为示例, 展示需要厂商提供哪些内容来完整实现设备功能。 - -1. 驱动开发首先需要实例化驱动入口,驱动入口必须为HdfDriverEntry(在 hdf\_device\_desc.h 中定义)类型的全局变量,且moduleName要和device\_info.hcs中保持一致。HDF框架会将所有加载的驱动的HdfDriverEntry对象首地址汇总,形成一个类似数组的段地址空间,方便上层调用。 - - 一般在加载驱动时HDF会先调用Bind函数,再调用Init函数加载该驱动。当Init调用异常时,HDF框架会调用Release释放驱动资源并退出。 - - ADC驱动入口参考: - - ADC模块这种类型的控制器会出现很多个设备挂接的情况,因而在HDF框架中首先会为这类型的设备创建一个管理器对象。这样,需要打开某个设备时,管理器对象会根据指定参数查找到指定设备。 - - ADC管理器的驱动由核心层实现,厂商不需要关注这部分内容的实现,这个但在实现Init函数的时候需要调用核心层的AdcDeviceAdd函数,它会实现相应功能。 - - ``` - static struct HdfDriverEntry g_hi35xxAdcDriverEntry = { - .moduleVersion = 1, - .Init = Hi35xxAdcInit, - .Release = Hi35xxAdcRelease, - .moduleName = "hi35xx_adc_driver",//【必要且与HCS文件里面的名字匹配】 - }; - HDF_INIT(g_hi35xxAdcDriverEntry); //调用HDF_INIT将驱动入口注册到HDF框架中 - - //核心层adc_core.c管理器服务的驱动入口 - struct HdfDriverEntry g_adcManagerEntry = { - .moduleVersion = 1, - .Init = AdcManagerInit, - .Release = AdcManagerRelease, - .moduleName = "HDF_PLATFORM_ADC_MANAGER",//这与device_info文件中device0对应 - }; - HDF_INIT(g_adcManagerEntry); - ``` - -2. 完成驱动入口注册之后,下一步请在device\_info.hcs文件中添加deviceNode信息,并在adc\_config.hcs中配置器件属性。deviceNode信息与驱动入口注册相关,器件属性值对于厂商驱动的实现以及核心层AdcDevice相关成员的默认值或限制范围有密切关系。 - - 统一服务模式的特点是device\_info文件中第一个设备节点必须为ADC管理器,其各项参数必须如下设置: - - - - - - - - - - - - - - - - - - - -

成员名

-

-

moduleName

-

固定为 HDF_PLATFORM_ADC_MANAGER

-

serviceName

-

-

policy

-

具体配置为0,不发布服务

-

deviceMatchAttr

-

没有使用,可忽略

-
- - 从第二个节点开始配置具体ADC控制器信息,此节点并不表示某一路ADC控制器,而是代表一个资源性质设备,用于描述一类ADC控制器的信息。本例只有一个ADC设备,如有多个设备,则需要在device\_info文件增加deviceNode信息,以及在adc\_config文件中增加对应的器件属性。 - - - device\_info.hcs 配置参考。 - - ``` - root { - device_info { - platform :: host { - device_adc :: device { - device0 :: deviceNode { - policy = 0; - priority = 50; - permission = 0644; - moduleName = "HDF_PLATFORM_ADC_MANAGER"; - serviceName = "HDF_PLATFORM_ADC_MANAGER"; - } - device1 :: deviceNode { - policy = 0; // 等于0,不需要发布服务 - priority = 55; // 驱动启动优先级 - permission = 0644; // 驱动创建设备节点权限 - moduleName = "hi35xx_adc_driver"; //【必要】用于指定驱动名称,需要与期望的驱动Entry中的moduleName一致; - serviceName = "HI35XX_ADC_DRIVER"; //【必要】驱动对外发布服务的名称,必须唯一 - deviceMatchAttr = "hisilicon_hi35xx_adc";//【必要】用于配置控制器私有数据,要与adc_config.hcs中对应控制器保持一致 - } // 具体的控制器信息在 adc_config.hcs 中 - } - } - } - } - ``` - - - adc\_config.hcs 配置参考。 - - ``` - root { - platform { - adc_config_hi35xx { - match_attr = "hisilicon_hi35xx_adc"; - template adc_device { - regBasePhy = 0x120e0000;//寄存器物理基地址 - regSize = 0x34; //寄存器位宽 - deviceNum = 0; //设备号 - validChannel = 0x1; //有效通道 - dataWidth = 10; //信号接收的数据位宽 - scanMode = 1; //扫描模式 - delta = 0; //delta参数 - deglitch = 0; - glitchSample = 5000; - rate = 20000; - } - device_0 :: adc_device { - deviceNum = 0; - validChannel = 0x2; - } - } - } - } - ``` - -3. 完成驱动入口注册之后,最后一步就是以核心层AdcDevice对象的初始化为核心,包括初始化厂商自定义结构体(传递参数和数据),实例化AdcDevice成员AdcMethod(让用户可以通过接口来调用驱动底层函数),实现HdfDriverEntry成员函数(Bind,Init,Release)。 - - 自定义结构体参考。 - - 从驱动的角度看,自定义结构体是参数和数据的载体,而且adc\_config.hcs文件中的数值会被HDF读入通过DeviceResourceIface来初始化结构体成员,其中一些重要数值也会传递给核心层AdcDevice对象,例如设备号、总线号等。 - - ``` - struct Hi35xxAdcDevice { - struct AdcDevice device;//【必要】是核心层控制对象,具体描述见下面 - volatile unsigned char *regBase;//【必要】寄存器基地址 - volatile unsigned char *pinCtrlBase; - uint32_t regBasePhy; //【必要】寄存器物理基地址 - uint32_t regSize; //【必要】寄存器位宽 - uint32_t deviceNum; //【必要】设备号 - uint32_t dataWidth; //【必要】信号接收的数据位宽 - uint32_t validChannel; //【必要】有效通道 - uint32_t scanMode; //【必要】扫描模式 - uint32_t delta; - uint32_t deglitch; - uint32_t glitchSample; - uint32_t rate; //【必要】采样率 - }; - - //AdcDevice是核心层控制器结构体,其中的成员在Init函数中会被赋值 - struct AdcDevice { - const struct AdcMethod *ops; - OsalSpinlock spin; - uint32_t devNum; - uint32_t chanNum; - const struct AdcLockMethod *lockOps; - void *priv; - }; - ``` - - - AdcDevice成员回调函数结构体AdcMethod的实例化,AdcLockMethod回调函数结构体本例未实现,若要实例化,可参考I2C驱动开发,其他成员在Init函数中初始化。 - - ``` - static const struct AdcMethod g_method = { - .read = Hi35xxAdcRead, - .stop = Hi35xxAdcStop, - .start = Hi35xxAdcStart, - }; - ``` - - - init函数参考 - - 入参: - - HdfDeviceObject 是整个驱动对外暴露的接口参数,具备 HCS 配置文件的信息。 - - 返回值: - - HDF\_STATUS相关状态 (下表为部分展示,如需使用其他状态,可见//drivers/framework/include/utils/hdf\_base.h中HDF\_STATUS 定义)。 - - - - - - - - - - - - - - - - - - - - - - - - - -

状态(值)

-

问题描述

-

HDF_ERR_INVALID_OBJECT

-

控制器对象非法

-

HDF_ERR_INVALID_PARAM

-

参数非法

-

HDF_ERR_MALLOC_FAIL

-

内存分配失败

-

HDF_ERR_IO

-

I/O 错误

-

HDF_SUCCESS

-

传输成功

-

HDF_FAILURE

-

传输失败

-
- - 函数说明: - - 初始化自定义结构体对象,初始化AdcDevice成员,并调用核心层AdcDeviceAdd函数。 - - ``` - static int32_t Hi35xxAdcInit(struct HdfDeviceObject *device) - { - int32_t ret; - struct DeviceResourceNode *childNode = NULL; - ... - //遍历、解析adc_config.hcs中的所有配置节点,并分别调用Hi35xxAdcParseInit函数来初始化device - DEV_RES_NODE_FOR_EACH_CHILD_NODE(device->property, childNode) { - ret = Hi35xxAdcParseInit(device, childNode);//函数定义见下 - ... - } - return ret; - } - - static int32_t Hi35xxAdcParseInit(struct HdfDeviceObject *device, struct DeviceResourceNode *node) - { - int32_t ret; - struct Hi35xxAdcDevice *hi35xx = NULL; //【必要】自定义结构体对象 - (void)device; - - hi35xx = (struct Hi35xxAdcDevice *)OsalMemCalloc(sizeof(*hi35xx)); //【必要】内存分配 - ... - ret = Hi35xxAdcReadDrs(hi35xx, node); //【必要】将adc_config文件的默认值填充到结构体中 - ... - hi35xx->regBase = OsalIoRemap(hi35xx->regBasePhy, hi35xx->regSize);//【必要】地址映射 - ... - hi35xx->pinCtrlBase = OsalIoRemap(HI35XX_ADC_IO_CONFIG_BASE, HI35XX_ADC_IO_CONFIG_SIZE); - ... - Hi35xxAdcDeviceInit(hi35xx); //【必要】ADC设备的初始化 - hi35xx->device.priv = (void *)node; //【必要】存储设备属性 - hi35xx->device.devNum = hi35xx->deviceNum;//【必要】初始化AdcDevice成员 - hi35xx->device.ops = &g_method; //【必要】AdcMethod的实例化对象的挂载 - ret = AdcDeviceAdd(&hi35xx->device); //【必要且重要】调用此函数填充核心层结构体,返回成功信号后驱动才完全接入平台核心层 - ... - return HDF_SUCCESS; - - __ERR__: - if (hi35xx != NULL) { //不成功的话,需要反向执行初始化相关函数 - if (hi35xx->regBase != NULL) { - OsalIoUnmap((void *)hi35xx->regBase); - hi35xx->regBase = NULL; - } - AdcDeviceRemove(&hi35xx->device); - OsalMemFree(hi35xx); - } - return ret; - } - ``` - - - Release 函数参考 - - 入参: - - HdfDeviceObject 是整个驱动对外暴露的接口参数,具备 HCS 配置文件的信息。 - - 返回值: - - 无。 - - 函数说明: - - 释放内存和删除控制器,该函数需要在驱动入口结构体中赋值给 Release 接口, 当HDF框架调用Init函数初始化驱动失败时,可以调用 Release 释放驱动资源。所有强制转换获取相应对象的操作**前提**是在Init函数中具备对应赋值的操作。 - - ``` - static void Hi35xxAdcRelease(struct HdfDeviceObject *device) - { - const struct DeviceResourceNode *childNode = NULL; - ... - //遍历、解析adc_config.hcs中的所有配置节点,并分别进行release操作 - DEV_RES_NODE_FOR_EACH_CHILD_NODE(device->property, childNode) { - Hi35xxAdcRemoveByNode(childNode);//函数定义见下 - } - } - - static void Hi35xxAdcRemoveByNode(const struct DeviceResourceNode *node) - { - int32_t ret; - int32_t deviceNum; - struct AdcDevice *device = NULL; - struct Hi35xxAdcDevice *hi35xx = NULL; - struct DeviceResourceIface *drsOps = NULL; - - drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); - ... - ret = drsOps->GetUint32(node, "deviceNum", (uint32_t *)&deviceNum, 0); - ... - //可以调用AdcDeviceGet函数通过设备的deviceNum获取AdcDevice对象, 以及调用AdcDeviceRemove函数来释放AdcDevice对象的内容 - device = AdcDeviceGet(deviceNum); - if (device != NULL && device->priv == node) { - AdcDevicePut(device); - AdcDeviceRemove(device); //【必要】主要是从管理器驱动那边移除AdcDevice对象 - hi35xx = (struct Hi35xxAdcDevice *)device;//【必要】通过强制转换获取自定义的对象并进行release操作 - OsalIoUnmap((void *)hi35xx->regBase); - OsalMemFree(hi35xx); - } - return - ``` - - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/02.GPIO.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/02.GPIO.md" deleted file mode 100644 index ad75e94d9e4f84816dbabc0116565af74c93c44a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/02.GPIO.md" +++ /dev/null @@ -1,429 +0,0 @@ ---- -title: GPIO -permalink: /pages/0105020202 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# GPIO - -- [概述](#section1826197354103451) -- [接口说明](#section752964871810) -- [开发步骤](#section731175315103451) -- [开发实例](#section800425816103451) - -## 概述 - -GPIO(General-purpose input/output)即通用型输入输出,在HDF框架中,GPIO的接口适配模式采用无服务模式,用于不需要在用户态提供API的设备类型,或者没有用户态和内核区分的OS系统,其关联方式是DevHandle直接指向设备对象内核态地址(DevHandle是一个void类型指针)。 - -**图 1** GPIO无服务模式结构图 -![](/images/device-dev/driver/figures/无服务模式结构图.png "GPIO无服务模式结构图") - -## 接口说明 - -GpioMethod定义: - -``` -struct GpioMethod { - int32_t (*request)(struct GpioCntlr *cntlr, uint16_t local);// 【预留】 - int32_t (*release)(struct GpioCntlr *cntlr, uint16_t local);// 【预留】 - int32_t (*write)(struct GpioCntlr *cntlr, uint16_t local, uint16_t val); - int32_t (*read)(struct GpioCntlr *cntlr, uint16_t local, uint16_t *val); - int32_t (*setDir)(struct GpioCntlr *cntlr, uint16_t local, uint16_t dir); - int32_t (*getDir)(struct GpioCntlr *cntlr, uint16_t local, uint16_t *dir); - int32_t (*toIrq)(struct GpioCntlr *cntlr, uint16_t local, uint16_t *irq);// 【预留】 - int32_t (*setIrq)(struct GpioCntlr *cntlr, uint16_t local, uint16_t mode, GpioIrqFunc func, void *arg); - int32_t (*unsetIrq)(struct GpioCntlr *cntlr, uint16_t local); - int32_t (*enableIrq)(struct GpioCntlr *cntlr, uint16_t local); - int32_t (*disableIrq)(struct GpioCntlr *cntlr, uint16_t local); -} -``` - -**表 1** GpioMethod结构体成员的回调函数功能说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

函数成员

-

入参

-

出参

-

返回值

-

功能

-

write

-

cntlr:结构体指针,核心层GPIO控制器;
local:uint16_t,GPIO端口标识号;
val:uint16_t,电平传入值;

-

-

HDF_STATUS相关状态

-

GPIO引脚写入电平值

-

read

-

cntlr:结构体指针,核心层GPIO控制器;
local:uint16_t,GPIO端口标识;

-

val:uint16_t 指针,用于传出电平值;

-

HDF_STATUS相关状态

-

GPIO引脚读取电平值

-

setDir

-

cntlr:结构体指针,核心层GPIO控制器;
local:uint16_t,GPIO端口标识号;
dir:uint16_t,管脚方向传入值;

-

-

HDF_STATUS相关状态

-

设置GPIO引脚输入/输出方向

-

getDir

-

cntlr:结构体指针,核心层GPIO控制器;
local:uint16_t,GPIO端口标识号;

-

dir:uint16_t 指针,用于传出管脚方向值;

-

HDF_STATUS相关状态

-

读GPIO引脚输入/输出方向

-

setIrq

-

cntlr:结构体指针,核心层GPIO控制器;
local:uint16_t,GPIO端口标识号;
mode:uint16_t,表示触发模式(边沿或电平);
func:函数指针,中断服务程序;
arg:void指针,中断服务程序入参;

-

-

HDF_STATUS相关状态

-

将GPIO引脚设置为中断模式

-

unsetIrq

-

cntlr:结构体指针,核心层GPIO控制器;
local:uint16_t,GPIO端口标识号;

-

-

HDF_STATUS相关状态

-

取消GPIO中断设置

-

enableIrq

-

cntlr:结构体指针,核心层GPIO控制器;
local:uint16_t,GPIO端口标识号;

-

-

HDF_STATUS相关状态

-

使能GPIO管脚中断

-

disableIrq

-

cntlr:结构体指针,核心层GPIO控制器;
local:uint16_t,GPIO端口标识号;

-

-

HDF_STATUS相关状态

-

禁止GPIO管脚中断

-
- -## 开发步骤 - -GPIO模块适配的三个环节是配置属性文件,实例化驱动入口,以及实例化核心层接口函数。GPIO控制器分组管理所有管脚,相关参数会在属性文件中有所体现;驱动入口和接口函数的实例化环节是厂商驱动接入HDF的核心环节。 - -1. **实例化驱动入口:** - - 实例化HdfDriverEntry结构体成员。 - - 调用HDF\_INIT将HdfDriverEntry实例化对象注册到HDF框架中。 - -2. **配置属性文件:** - - 在device\_info.hcs文件中添加deviceNode描述。 - - 【可选】添加gpio\_config.hcs器件属性文件。 - -3. **实例化GPIO控制器对象:** - - 初始化GpioCntlr成员。 - - 实例化GpioCntlr成员GpioMethod。 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >实例化GpioCntlr成员GpioMethod,详见[接口说明](#section752964871810)。 - - -4. **驱动调试:** - - 【可选】针对新增驱动程序,建议验证驱动基本功能,例如GPIO控制状态,中断响应情况等。 - - -## 开发实例 - -下方将以gpio\_hi35xx.c为示例,展示需要厂商提供哪些内容来完整实现设备功能。 - -1. 驱动开发首先需要实例化驱动入口,驱动入口必须为HdfDriverEntry(在 hdf\_device\_desc.h 中定义)类型的全局变量,且moduleName要和device\_info.hcs中保持一致。HDF框架会将所有加载的驱动的HdfDriverEntry对象首地址汇总,形成一个类似数组的段地址空间,方便上层调用。 - - 一般在加载驱动时HDF会先调用Bind函数,再调用Init函数加载该驱动。当Init调用异常时,HDF框架会调用Release释放驱动资源并退出。 - - GPIO 驱动入口参考: - - ``` - struct HdfDriverEntry g_gpioDriverEntry = { - .moduleVersion = 1, - .Bind = Pl061GpioBind, //GPIO不需要实现Bind,本例是一个空实现,厂商可根据自身需要添加相关操作 - .Init = Pl061GpioInit, //见Init参考 - .Release = Pl061GpioRelease, //见Release参考 - .moduleName = "hisi_pl061_driver",//【必要且需要与HCS文件中里面的moduleName匹配】 - }; - //调用HDF_INIT将驱动入口注册到HDF框架中 - HDF_INIT(g_gpioDriverEntry); - ``` - -2. 完成驱动入口注册之后,下一步请在device\_info.hcs文件中添加deviceNode信息,并在 gpio\_config.hcs 中配置器件属性。deviceNode信息与驱动入口注册相关,器件属性值与核心层GpioCntlr 成员的默认值或限制范围有密切关系。 - - 本例只有一个GPIO控制器,如有多个器件信息,则需要在device\_info文件增加deviceNode信息,以及在gpio\_config文件中增加对应的器件属性。 - - - device\_info.hcs 配置参考。 - - ``` - root { - device_info { - platform :: host { - hostName = "platform_host"; - priority = 50; - device_gpio :: device { - device0 :: deviceNode { - policy = 0; // 等于0,不需要发布服务 - priority = 10; // 驱动启动优先级 - permission = 0644; // 驱动创建设备节点权限 - moduleName = "hisi_pl061_driver"; //【必要】用于指定驱动名称,需要与期望的驱动Entry中的moduleName一致; - deviceMatchAttr = "hisilicon_hi35xx_pl061";//【必要】用于配置控制器私有数据,要与 gpio_config.hcs 中 - //对应控制器保持一致,其他控制器信息也在文件中 - } - } - } - } - } - ``` - - - gpio\_config.hcs 配置参考。 - - ``` - root { - platform { - gpio_config { - controller_0x120d0000 { - match_attr = "hisilicon_hi35xx_pl061"; //【必要】必须和device_info.hcs中的deviceMatchAttr值一致 - groupNum = 12; //【必要】GPIO组索引 需要根据设备情况填写 - bitNum = 8; //【必要】每组GPIO管脚数 - regBase = 0x120d0000;//【必要】物理基地址 - regStep = 0x1000; //【必要】寄存器偏移步进 - irqStart = 48; //【必要】开启中断 - irqShare = 0; //【必要】共享中断 - } - } - } - } - ``` - -3. 完成驱动入口注册之后,最后一步就是以核心层GpioCntlr对象的初始化为核心,包括厂商自定义结构体(传递参数和数据),实例化GpioCntlr成员GpioMethod(让用户可以通过接口来调用驱动底层函数),实现HdfDriverEntry成员函数(Bind,Init,Release)。 - - 自定义结构体参考。 - - 从驱动的角度看,自定义结构体是参数和数据的载体,而且gpio\_config.hcs文件中的数值会被HDF读入通过DeviceResourceIface来初始化结构体成员,其中一些重要数值也会传递给核心层GpioCntlr对象,例如索引、管脚数等。 - - ``` - struct Pl061GpioCntlr { - struct GpioCntlr cntlr;//【必要】 是核心层控制对象,其成员定义见下面 - volatile unsigned char *regBase; //【必要】寄存器基地址 - uint32_t phyBase; //【必要】 物理基址 - uint32_t regStep; //【必要】 寄存器偏移步进 - uint32_t irqStart; //【必要】 中断开启 - uint16_t groupNum; //【必要】 用于描述厂商的GPIO端口号的参数 - uint16_t bitNum; //【必要】 用于描述厂商的GPIO端口号的参数 - uint8_t irqShare; //【必要】 共享中断 - struct Pl061GpioGroup *groups; //【可选】 根据厂商需要设置 - }; - struct Pl061GpioGroup { //包括寄存器地址,中断号,中断函数和和锁 - volatile unsigned char *regBase; - unsigned int index; - unsigned int irq; - OsalIRQHandle irqFunc; - OsalSpinlock lock; - }; - - // GpioCntlr是核心层控制器结构体,其中的成员在Init函数中会被赋值 - struct GpioCntlr { - struct IDeviceIoService service; - struct HdfDeviceObject *device; - struct GpioMethod *ops; - struct DListHead list; - OsalSpinlock spin; - uint16_t start; - uint16_t count; - struct GpioInfo *ginfos; - void *priv; - }; - ``` - - - GpioCntlr成员回调函数结构体GpioMethod的实例化,其他成员在Init函数中初始化。 - - ``` - //GpioMethod结构体成员都是回调函数,厂商需要根据表1完成相应的函数功能。 - static struct GpioMethod g_method = { - .request = NULL, - .release = NULL, - .write = Pl061GpioWrite, //写管脚 - .read = Pl061GpioRead, //读管脚 - .setDir = Pl061GpioSetDir, //设置管脚方向 - .getDir = Pl061GpioGetDir, //获取管脚方向 - .toIrq = NULL, - .setIrq = Pl061GpioSetIrq, //设置管脚中断,如不具备此能力可忽略 - .unsetIrq = Pl061GpioUnsetIrq, //取消管脚中断设置,如不具备此能力可忽略 - .enableIrq = Pl061GpioEnableIrq, //使能管脚中断,如不具备此能力可忽略 - .disableIrq = Pl061GpioDisableIrq,//禁止管脚中断,如不具备此能力可忽略 - }; - ``` - - - Init函数参考 - - 入参: - - HdfDeviceObject这个是整个驱动对外暴露的接口参数,具备HCS配置文件的信息。 - - 返回值: - - HDF\_STATUS相关状态(下表为部分展示,如需使用其他状态,可见//drivers/framework/include/utils/hdf\_base.h中HDF\_STATUS 定义)。 - - **表 2** Init函数说明 - - - - - - - - - - - - - - - - - - - - - - - - - -

状态(值)

-

问题描述

-

HDF_ERR_INVALID_OBJECT

-

控制器对象非法

-

HDF_ERR_MALLOC_FAIL

-

内存分配失败

-

HDF_ERR_INVALID_PARAM

-

参数非法

-

HDF_ERR_IO

-

I/O 错误

-

HDF_SUCCESS

-

初始化成功

-

HDF_FAILURE

-

初始化失败

-
- - 函数说明: - - 初始化自定义结构体对象,初始化GpioCntlr成员,调用核心层GpioCntlrAdd函数,【可选】接入VFS。 - - ``` - static int32_t Pl061GpioInit(struct HdfDeviceObject *device) - { - ... - struct Pl061GpioCntlr *pl061 = &g_pl061;//利用静态全局变量完成初始化 - //static struct Pl061GpioCntlr g_pl061 = { - // .groups = NULL, - // .groupNum = PL061_GROUP_MAX, - // .bitNum = PL061_BIT_MAX, - //}; - ret = Pl061GpioReadDrs(pl061, device->property);//利用从gpio_config.HCS文件读取的属性值来初始化自定义结构体对象成员 - ... - pl061->regBase = OsalIoRemap(pl061->phyBase, pl061->groupNum * pl061->regStep);//地址映射 - ... - ret = Pl061GpioInitCntlrMem(pl061); // 内存分配 - ... - pl061->cntlr.count = pl061->groupNum * pl061->bitNum;//【必要】管脚数量计算 - pl061->cntlr.priv = (void *)device->property; //【必要】存储设备属性 - pl061->cntlr.ops = &g_method; // 【必要】GpioMethod的实例化对象的挂载 - pl061->cntlr.device = device; // 【必要】使HdfDeviceObject与GpioCntlr可以相互转化的前提 - ret = GpioCntlrAdd(&pl061->cntlr); // 【必要】调用此函数填充核心层结构体,返回成功信号后驱动才完全接入平台核心层 - ... - Pl061GpioDebugCntlr(pl061); - #ifdef PL061_GPIO_USER_SUPPORT //【可选】若支持用户级的虚拟文件系统,则接入 - if (GpioAddVfs(pl061->bitNum) != HDF_SUCCESS) { - HDF_LOGE("%s: add vfs fail!", __func__); - } - #endif - ... - } - ``` - - - Release 函数参考 - - 入参: - - HdfDeviceObject 是整个驱动对外暴露的接口参数,具备 HCS 配置文件的信息。 - - 返回值: - - 无。 - - 函数说明: - - 释放内存和删除控制器,该函数需要在驱动入口结构体中赋值给 Release 接口, 当HDF框架调用Init函数初始化驱动失败时,可以调用 Release 释放驱动资源。所有强制转换获取相应对象的操作**前提**是在Init函数中具备对应赋值的操作。 - - ``` - static void Pl061GpioRelease(struct HdfDeviceObject *device) - { - struct GpioCntlr *cntlr = NULL; - struct Pl061GpioCntlr *pl061 = NULL; - ... - cntlr = GpioCntlrFromDevice(device);//【必要】通过强制转换获取核心层控制对象 - //return (device == NULL) ? NULL : (struct GpioCntlr *)device->service; - ... - #ifdef PL061_GPIO_USER_SUPPORT - GpioRemoveVfs();//与Init中GpioAddVfs相反 - #endif - GpioCntlrRemove(cntlr); //【必要】取消设备信息、服务等内容在核心层上的挂载 - pl061 = ToPl061GpioCntlr(cntlr); //return (struct Pl061GpioCntlr *)cntlr; - Pl061GpioRleaseCntlrMem(pl061); //【必要】锁和内存的释放 - OsalIoUnmap((void *)pl061->regBase);//【必要】解除地址映射 - pl061->regBase = NULL; - } - ``` - - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/03.HDMI.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/03.HDMI.md" deleted file mode 100644 index bffa410b67974d36588b0297a2b754070f9c7d7f..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/03.HDMI.md" +++ /dev/null @@ -1,396 +0,0 @@ ---- -title: HDMI -permalink: /pages/0105020203 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# HDMI - -- [概述](#1) -- [开发步骤](#2) -- [开发实例](#3) - -## 概述 - -HDMI(High-Definition Multiface Interface)是Hitachi、Panasonic、Philips、SiliconImage、Sony、Thomson、Toshiba共同发布的一款音视频传输协议,主要用于DVD、机顶盒等音视频source到TV、显示器等sink设备的传输。传输过程遵循TMDS(Transition Minimized Differential Signaling)协议。 - -在HDF框架中,HDMI的接口适配模式采用独立服务模式,在这种模式下,每一个设备对象会独立发布一个设备服务来处理外部访问,设备管理器收到API的访问请求之后,通过提取该请求的参数,达到调用实际设备对象的相应内部方法的目的。独立服务模式可以直接借助HDFDeviceManager的服务管理能力,但需要为每个设备单独配置设备节点,增加内存占用率。 - - **图 1** HDMI统一服务模式 - -![image1](/images/device-dev/driver/figures/独立服务模式结构图.png) - -## 开发步骤 - -HDMI模块适配的三个环节是配置属性文件,实例化驱动入口以及实例化HDMI控制器对象。 - -1. **实例化驱动入口:** - - 实例化HdfDriverEntry结构体成员。 - - 调用HDF_INIT将HdfDriverEntry实例化对象注册到HDF框架中。 - -2. **配置属性文件:** - - 在device_info.hcs文件中添加deviceNode描述。 - - 【可选】添加hdmi_config.hcs器件属性文件。 - -3. **实例化HDMI控制器对象:** - - 初始化HdmiCntlr成员。 - - 实例化HdmiCntlr成员HdmiCntlrOps方法集合,其定义和成员函数说明见下文。 - - HdmiCntlrOps定义: - ```c - struct HdmiCntlrOps { - void (*hardWareInit)(struct HdmiCntlr *cntlr); - void (*hardWareStatusGet)(struct HdmiCntlr *cntlr, struct HdmiHardwareStatus *status); - void (*controllerReset)(struct HdmiCntlr *cntlr); - bool (*hotPlugStateGet)(struct HdmiCntlr *cntlr); - bool (*hotPlugInterruptStateGet)(struct HdmiCntlr *cntlr); - void (*lowPowerSet)(struct HdmiCntlr *cntlr, bool enable); - void (*tmdsModeSet)(struct HdmiCntlr *cntlr, enum HdmiTmdsModeType mode); - int32_t (*tmdsConfigSet)(struct HdmiCntlr *cntlr, struct HdmiTmdsConfig mode); - void (*infoFrameEnable)(struct HdmiCntlr *cntlr, enum HdmiPacketType infoFrameType, bool enable); - int32_t (*infoFrameSend)(struct HdmiCntlr *cntlr, enum HdmiPacketType infoFrameType, uint8_t *data, uint32_t len); - int32_t (*infoFrameDataSet)(struct HdmiCntlr *cntlr, uint32_t type, uint8_t *data, uint32_t len); - int32_t (*cecMsgSend)(struct HdmiCntlr *cntlr, struct HdmiCecMsg *msg); - void (*audioPathEnable)(struct HdmiCntlr *cntlr, bool enable); - void (*audioPathSet)(struct HdmiCntlr *cntlr, struct HdmiAudioConfigInfo *config); - void (*phyOutputEnable)(struct HdmiCntlr *cntlr, bool enable); - void (*phyOutputSet)(struct HdmiCntlr *cntlr, struct HdmiPhyCfg *cfg); - void (*blackDataSet)(struct HdmiCntlr *cntlr, bool enable); - void (*videoMuteEnable)(struct HdmiCntlr *cntlr, bool enable); - void (*videoPathSet)(struct HdmiCntlr *cntlr, struct HdmiVideoAttr *attr); - void (*audioMuteEnable)(struct HdmiCntlr *cntlr, bool enable); - void (*avmuteSet)(struct HdmiCntlr *cntlr, bool enable); - int32_t (*ddcTransfer)(struct HdmiCntlr *cntlr, struct HdmiDdcCfg *ddcCfg); - bool (*scdcSourceScrambleGet)(struct HdmiCntlr *cntlr); - int32_t (*scdcSourceScrambleSet)(struct HdmiCntlr *cntlr, bool enable); - void (*frlSet)(struct HdmiCntlr *cntlr); - int32_t (*frlEnable)(struct HdmiCntlr *cntlr, bool enable); - int32_t (*audioNctsSet)(struct HdmiCntlr *cntlr, struct HdmiFrlAudioNctsConfig *cfg); - void (*frlTrainingConfigSet)(struct HdmiCntlr *cntlr, struct HdmiFrlTrainConfig *cfg); - void (*frlTrainingStart)(struct HdmiCntlr *cntlr); - void (*frlGetTriningRslt)(struct HdmiCntlr *cntlr, struct HdmiFrlTrainRslt *rslt); - void (*hdcpRegInit)(struct HdmiCntlr *cntlr); - int32_t (*hdcpGenerateAksvAndAn)(struct HdmiCntlr *cntlr); - int32_t (*hdcpOptReg)(struct HdmiCntlr *cntlr, enum HdmiHdcpRegOptType type, uint8_t *data, uint32_t len); - void (*hdrTimerSet)(struct HdmiCntlr *cntlr, struct HdmiHdrTimerConfig *config); - }; - ``` - - 表1 HdmiCntlrOps结构体成员的回调函数功能说明 - - | 函数成员 | 入参 | 出参 | 返回值 | 功能 | - | ------------------------ | ------------------------------------------------------------ | -------------------------------------- | ------------------ | -------------------------------------------------- | - | hardWareInit | **cntlr**: 结构体指针,核心层HDMI控制器; | 无 | 无 | HDMI硬件初始化 | - | hardWareStatusGet | **cntlr**: 结构体指针,核心层HDMI控制器;
| **status**:HDMI硬件状态 ; | 无 | 获取HDMI当前硬件状态 | - | controllerReset | **cntlr**: 结构体指针,核心层HDMI控制器; | 无 | 无 | HDMI控制器复位 | - | hotPlugStateGet | **cntlr**: 结构体指针,核心层HDMI控制器; | 无 | bool: HDMI热插拔状态 | 获取HDMI热插拔状态 | - | hotPlugInterruptStateGet | **cntlr**: 结构体指针,核心层HDMI控制器; | 无 | bool: HDMI热插拔中断状态 | 获取HDMI热插拔中断状态 | - | lowPowerSet | **cntlr**: 结构体指针,核心层HDMI控制器;
**enable**: bool,使能/去使能 | 无 | 无 | 使能/去使能低功耗 | - | tmdsModeSet | **cntlr**: 结构体指针,核心层HDMI控制器;
**mode**:TMDS模式 | 无 | 无 | 设置TMDS模式 | - |tmdsConfigSet|**cntlr**: 结构体指针,核心层HDMI控制器;
**mode**: TMDS参数|无|HDF_STATUS相关状态|配置TMDS参数| - |infoFrameEnable|**cntlr**: 结构体指针,核心层HDMI控制器;
**infoFrameType**: packet类型
**enable**: bool,使能/去使能|无|无|使能/去使能infoFrame| - |infoFrameSend|**cntlr**: 结构体指针,核心层HDMI控制器;
**infoFrameType**: packet类型
**data**: infoFrame数据
**len**:数据长度|无|HDF_STATUS相关状态|发送inforFrame| - |cecMsgSend|**cntlr**: 结构体指针,核心层HDMI控制器;
**msg**: CEC消息|无|HDF_STATUS相关状态|发送CEC消息| - |audioPathEnable|**cntlr**: 结构体指针,核心层HDMI控制器;
**enable**: bool,使能/去使能|无|无|使能/去使能audio通路| - |audioPathSet|**cntlr**: 结构体指针,核心层HDMI控制器;
**config**: 配置信息|无|无|设置audio通路配置信息| - |phyOutputEnable|**cntlr**: 结构体指针,核心层HDMI控制器;
**enable**: bool,使能/去使能|无|无|使能/去使能物理层输出状态| - |phyOutputSet|**cntlr**: 结构体指针,核心层HDMI控制器;
**cfg**: 配置信息|无|无|设置物理层配置信息| - |blackDataSet|**cntlr**: 结构体指针,核心层HDMI控制器;
**enable**: bool,使能/去使能|无|无|黑屏设置| - |videoMuteEnable|**cntlr**: 结构体指针,核心层HDMI控制器;
**enable**: bool,使能/去使能|无|无|使能/去使能video静音| - |videoPathSet|**cntlr**: 结构体指针,核心层HDMI控制器;
**attr**: 配置信息|无|无|设置viedo通路配置信息| - |audioMuteEnable|**cntlr**: 结构体指针,核心层HDMI控制器;
**enable**: bool,使能/去使能|无|无|使能/去使能audio静音| - |avmuteSet|**cntlr**: 结构体指针,核心层HDMI控制器;
**enable**: bool,使能/去使能|无|无|使能/去使能声音图像消隐| - |ddcTransfer|**cntlr**: 结构体指针,核心层HDMI控制器;
**ddcCfg**:DDC配置参数|**ddcCfg**:DDC配置参数|HDF_STATUS相关状态|DDC读写数据| - |scdcSourceScrambleGet|**cntlr**: 结构体指针,核心层HDMI控制器;|无|bool,加扰状态|获取source端的加扰状态| - |scdcSourceScrambleSet|**cntlr**: 结构体指针,核心层HDMI控制器;
**enable**: bool,使能/去使能|无|HDF_STATUS相关状态|使能/去使能source端的加扰| - |frlEnable|**cntlr**: 结构体指针,核心层HDMI控制器;
**enable**: bool,使能/去使能|无|HDF_STATUS相关状态|使能/去使能FRL| - |audioNctsSet|**cntlr**: 结构体指针,核心层HDMI控制器;
**cfg**:N/CTS配 置参数|无|HDF_STATUS相关状态|设置audio的N/CTS信息| - |frlTrainingConfigSet|**cntlr**: 结构体指针,核心层HDMI控制器;
**cfg**:FRL Traning配置参数|无|无|设置FRL Traning配置信息| - |frlTrainingStart|**cntlr**: 结构体指针,核心层HDMI控制器;|无|无|开始FRL Traning流程| - |frlGetTriningRslt|**cntlr**: 结构体指针,核心层HDMI控制器;|**rslt**:FRL Traning结果|无|获取FRL Traning结果| - |hdcpRegInit|**cntlr**: 结构体指针,核心层HDMI控制器;|无|无|初始化HDCP流程相关的寄存器| - |hdcpGenerateAksvAndAn|**cntlr**: 结构体指针,核心层HDMI控制器;|无|HDF_STATUS相关状态|HDCP流程中生成aksv和an| - |hdcpOptReg|**cntlr**: 结构体指针,核心层HDMI控制器;
**type**: 操作类型
**data**: 寄存器数据
**len**: 数据长度|**data**: 寄存器数据|HDF_STATUS相关状态|HDCP流程中的相关寄存器读写操作| - |hdrTimerSet|**cntlr**: 结构体指针,核心层HDMI控制器;
**config**: timer配置信息|无|无|设置HDR相关的timer配置信息| - -## 开发实例 - -1. 驱动开发首先需要实例化驱动入口,驱动入口必须为HdfDriverEntry(在 hdf_device_desc.h 中定义)类型的全局变量,且moduleName要和device_info.hcs中保持一致。HDF框架会将所有加载的驱动的HdfDriverEntry对象首地址汇总,形成一个类似数组的段地址空间,方便上层调用。 - - 一般在加载驱动时HDF会先调用Bind函数,再调用Init函数加载该驱动。当Init调用异常时,HDF框架会调用Release释放驱动资源并退出。 - - HDMI驱动入口参考: - - ```c - struct HdfDriverEntry g_hdmiDriverEntry = { - .moduleVersion = 1, - .Bind = HdmiAdapterBind, - .Init = HdmiAdapterInit, - .Release = HdmiAdapterRelease, - .moduleName = "adapter_hdmi_driver",//【必要】与HCS里面的名字匹配 - }; - HDF_INIT(g_hdmiDriverEntry); //调用HDF_INIT将驱动入口注册到HDF框架中 - ``` - -2. 完成驱动入口注册之后,下一步请在device_info.hcs文件中添加deviceNode信息,并在hdmi_config.hcs中配置器件属性。deviceNode信息与驱动入口注册相关,器件属性值对于厂商驱动的实现以及核心层HdmiCntlr相关成员的默认值或限制范围有密切关系。 - - 从第一个节点开始配置具体HDMI控制器信息,此节点并不表示某一路HDMI控制器,而是代表一个资源性质设备,用于描述一类HDMI控制器的信息。本例只有一个HDMI控制器,如有多个控制器,则需要在device_info文件增加deviceNode信息,以及在hdmi_config文件中增加对应的器件属性。 - - - device_info.hcs 配置参考 - - ```c - root { - platform :: host { - device_hdmi :: device { - device0 :: deviceNode { - policy = 2; // 等于2,需要发布服务 - priority = 20; // 驱动启动优先级 - permission = 0644; // 驱动创建设备节点权限 - serviceName = "HDF_PLATFORM_HDMI_0"; //【必要】驱动对外发布服务的名称,必须唯一 - moduleName = "hdmi_driver"; //【必要】用于指定驱动名称,需要与期望的驱动Entry中的moduleName一致; - deviceMatchAttr = "adapter_hdmi_driver"; //【必要】用于配置控制器私有数据,要与hdmi_config.hcs中对应控制器保持一致 - } // 具体的控制器信息在 hdmi_config.hcs 中 - } - } - } - ``` - - - hdmi_config.hcs 配置参考 - - ```c - root { - platform { - hdmi_config { - template hdmi_controller { // 模板公共参数,继承该模板的节点如果使用模板中的默认值,则节点字段可以缺省 - match_attr = ""; //【必要】需要和device_info.hcs中的deviceMatchAttr值一致 - index = 0; //【必要】hdmi控制器编号 - regBasePhy = 0x10100000; //【必要】寄存器物理基地址 - regSize = 0xd1; //【必要】寄存器位宽 - irqNum = 100; //【必要】中断号 - maxTmdsClock = 300; - videoTiming = 10; - quantization = 1; - colorSpace = 0; - colorimetry = 0; - audioIfType = 0; - audioBitDepth = 1; - audioSampleRate = 2; - audioChannels = 1; - hdrColorimetry = 4; - hdrUserMode = 1; - cap = 0xd001e045; - } - controller_0x10100000 :: hdmi_controller { - match_attr = "adapter_hdmi_driver"; - index = 0; - regBasePhy = 0x10100000; - irqNum = 100; - maxTmdsClock = 400; - defTmdsClock = 300; - maxFrlRate = 600; - videoTiming = 10; - quantization = 1; - colorSpace = 0; - colorimetry = 0; - audioIfType = 0; - audioSampleRate = 2; - audioChannels = 1; - hdrColorimetry = 4; - hdrUserMode = 1; - cap = 0xd001e045; - } - } - } - } - ``` - -3. 最后一步,完成驱动入口注册之后,要以核心层HdmiCntlr对象的初始化为核心,包括厂商自定义结构体(传递参数和数据),实例化HdmiCntlr成员HdmiCntlrOps(让用户可以通过接口来调用驱动底层函数),实现HdfDriverEntry成员函数(Bind,Init,Release)。 - - - 自定义结构体参考 - - > ![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - > 从驱动角度看,自定义结构体是参数和数据的载体。HDF会读取hdmi_config.hcs文件中的数值并通过DeviceResourceIface来初始化结构体成员,且其中一些重要数值(例如设备号、总线号等)也会被传递给核心层HdmiCntlr对象。 - - ```c - struct HdmiAdapterHost { - struct HdmiCntlr *cntlr; //【必要】是核心层控制对象,具体描述如下 - volatile unsigned char *regBase;//【必要】寄存器基地址 - uint32_t regBasePhy; //【必要】寄存器物理基地址 - uint32_t regSize; //【必要】寄存器位宽 - uint32_t irqNum; //【必要】中断号 - }; - - /* HdmiCntlr是核心层控制器结构体,其中的成员在Init函数中被赋值 */ - struct HdmiCntlr { - struct IDeviceIoService service; - struct HdfDeviceObject *hdfDevObj; - struct PlatformDevice device; - struct OsalMutex mutex; - struct PlatformQueue *msgQueue; - struct HdmiCntlrCap cap; - struct HdmiAttr attr; - struct HdmiCntlrOps *ops; - uint32_t deviceIndex; - uint32_t state; // 控制器状态 - enum HdmiTmdsModeType tmdsMode; - struct HdmiDevice *hdmi; - struct HdmiInfoframe infoframe; - struct HdmiScdc *scdc; - struct HdmiDdc ddc; - struct HdmiFrl *frl; - struct HdmiHdcp *hdcp; - struct HdmiCec *cec; - struct HdmiEvent event; - struct HdmiHdr *hdr; - void *priv; - }; - ``` - - - **【重要】** HdmiCntlr成员回调函数结构体HdmiCntlrOps的实例化 - - ```c - static struct HdmiCntlrOps g_hdmiAdapterHostOps = { - .hardWareInit = HdmiAdapterHardWareInit, - .hardWareStatusGet = HdmiAdapterHardWareStatusGet, - .controllerReset = HdmiAdapterControllerReset, - .hotPlugStateGet = HdmiAdapterHotPlugStateGet, - .hotPlugInterruptStateGet = HdmiAdapterHotPlugInterruptStateGet, - .lowPowerSet = HdmiAdapterLowPowerSet, - .tmdsModeSet = HdmiAdapterTmdsModeSet, - .tmdsConfigSet = HdmiAdapterTmdsConfigSet, - .infoframeEnable = HdmiAdapterInfoframeEnable, - .infoframeSend = HdmiAdapterInfoframeSend, - .infoframeDataSet = HdmiAdapterInfoframeDataSet, - .cecMsgSend = HdmiAdapterCecMsgSend, - .audioPathEnable = HdmiAdapterAudioPathEnable, - .audioPathSet = HdmiAdapterAudioPathSet, - .phyOutputEnable = HdmiAdapterPhyOutputEnable, - .phyOutputSet = HdmiAdapterPhyOutputSet, - .blackDataSet = HdmiAdapterBlackDataSet, - .videoMuteEnable = HdmiAdapterVideoMuteEnable, - .videoPathSet = HdmiAdapterVideoPathSet, - .audioMuteEnable = HdmiAdapterAudioMuteEnable, - .avmuteSet = HdmiAdapterAvmuteSet, - .ddcTransfer = HdmiAdapterDdcTransfer, - .scdcSourceScrambleGet = HdmiAdapterScdcSourceScrambleGet, - .scdcSourceScrambleSet = HdmiAdapterScdcSourceScrambleSet, - .frlSet = HdmiAdapterFrlSet, - .frlEnable = HdmiAdapterFrlEnable, - .audioNctsSet = HdmiAdapterAudioNctsSet, - .frlTrainingConfigSet = HdmiAdapterFrlTrainingConfigSet, - .frlTrainingStart = HdmiAdapterFrlTrainingStart, - .frlGetTriningRslt = HdmiAdapterFrlGetTriningRslt, - .hdcpRegInit = HdmiAdapterHdcpRegInit, - .hdcpGenerateAksvAndAn = HdmiAdapterHdcpGenerateAksvAndAn, - .hdcpOptReg = HdmiAdapterHdcpOptReg, - .hdrTimerSet = HdmiAdapterHdrTimerSet, - }; - ``` - - - **Bind函数参考** - - > **入参:** - > HdfDeviceObject 是整个驱动对外呈现的接口参数,具备 HCS 配置文件的信息 - > - > **返回值:** - > HDF_STATUS相关状态 (下表为部分展示,如需使用其他状态,可见//drivers/framework/include/utils/hdf_base.h中HDF_STATUS 定义) - - |状态(值)|状态描述| - |:-|:-| - |HDF_ERR_INVALID_OBJECT|控制器对象非法| - |HDF_ERR_INVALID_PARAM |参数非法| - |HDF_ERR_MALLOC_FAIL |内存分配失败| - |HDF_ERR_IO |I/O 错误| - |HDF_SUCCESS |传输成功| - |HDF_FAILURE |传输失败| - - > **函数说明:** - > 初始化自定义结构体对象HdmiAdapterHost,初始化HdmiCntlr成员,调用核心层HdmiCntlrAdd函数。 - > - > HdmiCntlr,HdmiAdapterHost,HdfDeviceObject之间互相赋值,方便其他函数可以相互转化。 - - ```c - static int32_t HdmiAdapterBind(struct HdfDeviceObject *obj) - { - struct HdmiCntlr *cntlr = NULL; - struct HimciAdapterHost *host = NULL; - int32_t ret; - cntlr = (struct HdmiCntlr *)OsalMemCalloc(sizeof(struct HdmiCntlr)); - if (cntlr == NULL) { - HDF_LOGE("%s: malloc cntlr failed!", __func__); - return HDF_ERR_MALLOC_FAIL; - } - host = (struct HimciAdapterHost *)OsalMemCalloc(sizeof(struct HimciAdapterHost)); - if (host == NULL) { - HDF_LOGE("%s: malloc host failed!", __func__); - return HDF_ERR_MALLOC_FAIL; - } - cntlr->priv = (void *)host; //【必要】将host存放至cntlr的私有数据 - cntlr->ops = &g_hdmiHostOps; //【必要】HdmiCntlrOps的实例化对象的挂载 - cntlr->hdfDevObj = obj; //【必要】使HdfDeviceObject与HdmiCntlr可以相互转化的前提 - obj->service = &cntlr->service; //【必要】使HdfDeviceObject与HdmiCntlr可以相互转化的前提 - ret = HdmiAdapterCntlrParse(cntlr, obj); //【必要】 初始化 cntlr. 失败则 goto __ERR; - ... - ret = HdmiAdapterHostParse(host, obj); //【必要】 初始化 host对象的相关属性,失败则 goto __ERR; - ... - ret = HdmiAdapterHostInit(host, cntlr); //厂商自定义的初始化,失败则 goto __ERR; - ... - ret = HdmiCntlrAdd(cntlr); //调用核心层函数 失败则 goto __ERR; - ... - HDF_LOGD("HdmiAdapterBind: success."); - return HDF_SUCCESS; - __ERR: - HdmiAdapterDeleteHost(host); - HDF_LOGD("HdmiAdapterBind: fail, err = %d.", ret); - return ret; - } - ``` - - - **init函数参考** - - >**入参:** - >HdfDeviceObject 是整个驱动对外暴露的接口参数,具备 HCS 配置文件的信息 - > - >**返回值:** - >HDF_STATUS相关状态 - > - >函数说明: - > - >实现HdmiAdapterInit函数。 - - ```c - static int32_t HdmiAdapterInit(struct HdfDeviceObject *obj) - { - return HDF_SUCCESS; - } - ``` - - - **Release 函数参考** - - > **入参:** - > HdfDeviceObject 是整个驱动对外暴露的接口参数,具备 HCS 配置文件的信息 - > - > **返回值:** - > 无 - > - > **函数说明:** - > 释放内存和删除控制器,该函数需要在驱动入口结构体中赋值给 Release 接口, 当HDF框架调用Init函数初始化驱动失败时,可以调用 Release 释放驱动资源。 - - ```c - static void HdmiAdapterRelease(struct HdfDeviceObject *obj) - { - struct HdmiCntlr *cntlr = NULL; - ... - cntlr = (struct HdmiCntlr *)obj->service;//这里有HdfDeviceObject到HdmiCntlr的强制转化,通过service成员,赋值见Bind函数 - ... - HimciDeleteHost((struct HimciAdapterHost *)cntlr->priv);//厂商自定义的内存释放函数,这里有HdmiCntlr到HimciAdapterHost的强制转化 - } - ``` - > 所有强制转换获取相应对象的操作**前提**是在Init函数中具备对应赋值的操作。 diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/04.I2C.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/04.I2C.md" deleted file mode 100644 index 909a68137ca0aa42cf7431a32fad438f988a8f3b..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/04.I2C.md" +++ /dev/null @@ -1,414 +0,0 @@ ---- -title: I2C -permalink: /pages/0105020204 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# I2C - -- [概述](#section2040078630114257) -- [接口说明](#section752964871810) -- [开发步骤](#section1085786591114257) -- [开发实例](#section1773332551114257) - -## 概述 - -I2C(Inter Integrated Circuit)总线是由Philips公司开发的一种简单、双向二线制同步串行总线,在HDF框架中,I2C模块接口适配模式采用统一服务模式,这需要一个设备服务来作为I2C模块的管理器,统一处理外部访问,这会在配置文件中有所体现。统一服务模式适合于同类型设备对象较多的情况,如I2C可能同时具备十几个控制器,采用独立服务模式需要配置更多的设备节点,且服务会占据内存资源。 - -**图 1** I2C统一服务模式结构图 -![](/images/device-dev/driver/figures/统一服务模式结构图.png "I2C统一服务模式结构图") - -## 接口说明 - -I2cMethod和I2cLockMethod定义: - -``` -struct I2cMethod { -int32_t (*transfer)(struct I2cCntlr *cntlr, struct I2cMsg *msgs, int16_t count); -}; -struct I2cLockMethod {//锁机制操作结构体 - int32_t (*lock)(struct I2cCntlr *cntlr);//加锁 - void (*unlock)(struct I2cCntlr *cntlr); //解锁 -}; -``` - -**表 1** I2cMethod结构体成员的回调函数功能说明 - - - - - - - - - - - - - - - - -

函数成员

-

入参

-

出参

-

返回值

-

功能

-

transfer

-

cntlr:结构体指针,核心层I2C控制器;msgs:结构体指针,用户消息 ;count:uint16_t,消息数量

-

-

HDF_STATUS相关状态

-

传递用户消息

-
- -## 开发步骤 - -I2C模块适配的三个环节是配置属性文件,实例化驱动入口,以及实例化核心层接口函数。 - -1. **实例化驱动入口:** - - 实例化HdfDriverEntry结构体成员。 - - 调用HDF\_INIT将HdfDriverEntry实例化对象注册到HDF框架中。 - -2. **配置属性文件:** - - 在device\_info.hcs文件中添加deviceNode描述。 - - 【可选】添加i2c\_config.hcs器件属性文件。 - -3. **实例化I2C控制器对象:** - - 初始化I2cCntlr成员。 - - 实例化I2cCntlr成员I2cMethod和I2cLockMethod。 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >实例化I2cCntlr成员I2cMethod和I2cLockMethod,详见[接口说明](#section752964871810)。 - - -4. **驱动调试:** - - 【可选】针对新增驱动程序,建议验证驱动基本功能,例如挂载后的信息反馈,消息传输的成功与否等。 - - -## 开发实例 - -下方将以i2c\_hi35xx.c为示例,展示需要厂商提供哪些内容来完整实现设备功能。 - -1. 驱动开发首先需要实例化驱动入口,驱动入口必须为HdfDriverEntry(在 hdf\_device\_desc.h 中定义)类型的全局变量,且moduleName要和device\_info.hcs中保持一致。HDF框架会将所有加载的驱动的HdfDriverEntry对象首地址汇总,形成一个类似数组的段地址空间,方便上层调用。 - - 一般在加载驱动时HDF会先调用Bind函数,再调用Init函数加载该驱动。当Init调用异常时,HDF框架会调用Release释放驱动资源并退出。 - - I2C驱动入口参考: - - I2C模块这种类型的控制器会出现很多个设备挂接的情况,因而在HDF框架中首先会为这类型的设备创建一个管理器对象,并同时对外发布一个管理器服务来统一处理外部访问。这样,用户需要打开某个设备时,会先获取到管理器服务,然后管理器服务根据用户指定参数查找到指定设备。 - - I2C管理器服务的驱动由核心层实现,厂商不需要关注这部分内容的实现,这个但在实现Init函数的时候需要调用核心层的I2cCntlrAdd函数,它会实现相应功能。 - - ``` - struct HdfDriverEntry g_i2cDriverEntry = { - .moduleVersion = 1, - .Init = Hi35xxI2cInit, - .Release = Hi35xxI2cRelease, - .moduleName = "hi35xx_i2c_driver",//【必要且与config.hcs文件里面匹配】 - }; - HDF_INIT(g_i2cDriverEntry); //调用HDF_INIT将驱动入口注册到HDF框架中 - - //核心层i2c_core.c 管理器服务的驱动入口 - struct HdfDriverEntry g_i2cManagerEntry = { - .moduleVersion = 1, - .Bind = I2cManagerBind, - .Init = I2cManagerInit, - .Release = I2cManagerRelease, - .moduleName = "HDF_PLATFORM_I2C_MANAGER",//这与device_info文件中device0对应 - }; - HDF_INIT(g_i2cManagerEntry); - ``` - -2. 完成驱动入口注册之后,下一步请在device\_info.hcs文件中添加deviceNode信息,并在i2c\_config.hcs中配置器件属性。deviceNode信息与驱动入口注册相关,器件属性值对于厂商驱动的实现以及核心层I2cCntlr相关成员的默认值或限制范围有密切关系。 - - 统一服务模式的特点是device\_info文件中第一个设备节点必须为I2C管理器,其各项参数必须如[表2](#table96651915911)设置: - - **表 2** 统一服务模式的特点 - - - - - - - - - - - - - - - - - - - -

成员名

-

-

moduleName

-

固定为 HDF_PLATFORM_I2C_MANAGER

-

serviceName

-

固定为 HDF_PLATFORM_I2C_MANAGER

-

policy

-

具体配置为1或2取决于是否对用户态可见

-

deviceMatchAttr

-

没有使用,可忽略

-
- - 从第二个节点开始配置具体I2C控制器信息,此节点并不表示某一路I2C控制器,而是代表一个资源性质设备,用于描述一类I2C控制器的信息。多个控制器之间相互区分的参数是busID和reg\_pbase,这在i2c\_config文件中有所体现。 - - - device\_info.hcs 配置参考。 - - ``` - root { - device_info { - match_attr = "hdf_manager"; - device_i2c :: device { - device0 :: deviceNode { - policy = 2; - priority = 50; - permission = 0644; - moduleName = "HDF_PLATFORM_I2C_MANAGER"; - serviceName = "HDF_PLATFORM_I2C_MANAGER"; - deviceMatchAttr = "hdf_platform_i2c_manager"; - } - device1 :: deviceNode { - policy = 0; // 等于0,不需要发布服务 - priority = 55; // 驱动启动优先级 - permission = 0644; // 驱动创建设备节点权限 - moduleName = "hi35xx_i2c_driver"; //【必要】用于指定驱动名称,需要与期望的驱动Entry中的moduleName一致; - serviceName = "HI35XX_I2C_DRIVER"; //【必要】驱动对外发布服务的名称,必须唯一 - deviceMatchAttr = "hisilicon_hi35xx_i2c";//【必要】用于配置控制器私有数据,要与i2c_config.hcs中对应控制器保持一致 - // 具体的控制器信息在 i2c_config.hcs 中 - } - } - } - } - ``` - - - i2c\_config.hcs 配置参考。 - - ``` - root { - platform { - i2c_config { - match_attr = "hisilicon_hi35xx_i2c";//【必要】需要和device_info.hcs中的deviceMatchAttr值一致 - template i2c_controller { //模板公共参数,继承该模板的节点如果使用模板中的默认值,则节点字段可以缺省 - bus = 0; //【必要】i2c 识别号 - reg_pbase = 0x120b0000; //【必要】物理基地址 - reg_size = 0xd1; //【必要】寄存器位宽 - irq = 0; //【可选】根据厂商需要来使用 - freq = 400000; //【可选】根据厂商需要来使用 - clk = 50000000; //【可选】根据厂商需要来使用 - } - controller_0x120b0000 :: i2c_controller { - bus = 0; - } - controller_0x120b1000 :: i2c_controller { - bus = 1; - reg_pbase = 0x120b1000; - } - ... - } - } - } - ``` - -3. 完成驱动入口注册之后,最后一步就是以核心层I2cCntlr对象的初始化为核心,包括厂商自定义结构体(传递参数和数据),实例化I2cCntlr成员I2cMethod(让用户可以通过接口来调用驱动底层函数),实现HdfDriverEntry成员函数(Bind,Init,Release)。 - - 自定义结构体参考 - - 从驱动的角度看,自定义结构体是参数和数据的载体,而且i2c\_config.hcs文件中的数值会被HDF读入通过DeviceResourceIface来初始化结构体成员,其中一些重要数值也会传递给核心层I2cCntlr对象,例如设备号、总线号等。 - - ``` - // 厂商自定义功能结构体 - struct Hi35xxI2cCntlr { - struct I2cCntlr cntlr; //【必要】是核心层控制对象,具体描述见下面 - OsalSpinlock spin; //【必要】厂商需要基于此锁变量对各个 i2c 操作函数实现对应的加锁解锁 - volatile unsigned char *regBase; //【必要】寄存器基地址 - uint16_t regSize; //【必要】寄存器位宽 - int16_t bus; //【必要】i2c_config.hcs 文件中可读取具体值 - uint32_t clk; //【可选】厂商自定义 - uint32_t freq; //【可选】厂商自定义 - uint32_t irq; //【可选】厂商自定义 - uint32_t regBasePhy; //【必要】寄存器物理基地址 - }; - - // I2cCntlr是核心层控制器结构体,其中的成员在Init函数中会被赋值 - struct I2cCntlr { - struct OsalMutex lock; - void *owner; - int16_t busId; - void *priv; - const struct I2cMethod *ops; - const struct I2cLockMethod *lockOps; - }; - ``` - - - I2cCntlr成员回调函数结构体I2cMethod的实例化,和锁机制回调函数结构体I2cLockMethod实例化,其他成员在Init函数中初始化。 - - ``` - // i2c_hi35xx.c 中的示例 - static const struct I2cMethod g_method = { - .transfer = Hi35xxI2cTransfer, - }; - - static const struct I2cLockMethod g_lockOps = { - .lock = Hi35xxI2cLock, //加锁函数 - .unlock = Hi35xxI2cUnlock,//解锁函数 - }; - ``` - - - init函数参考 - - 入参: - - HdfDeviceObject 是整个驱动对外暴露的接口参数,具备 HCS 配置文件的信息。 - - 返回值: - - HDF\_STATUS相关状态 (下表为部分展示,如需使用其他状态,可见//drivers/framework/include/utils/hdf\_base.h中HDF\_STATUS 定义)。 - - **表 3** init函数入参及返回值参考 - - - - - - - - - - - - - - - - - - - - - - - - - -

状态(值)

-

问题描述

-

HDF_ERR_INVALID_OBJECT

-

控制器对象非法

-

HDF_ERR_INVALID_PARAM

-

参数非法

-

HDF_ERR_MALLOC_FAIL

-

内存分配失败

-

HDF_ERR_IO

-

I/O 错误

-

HDF_SUCCESS

-

传输成功

-

HDF_FAILURE

-

传输失败

-
- - 函数说明: - - 初始化自定义结构体对象,初始化I2cCntlr成员,调用核心层I2cCntlrAdd函数,【可选】接入VFS。 - - ``` - static int32_t Hi35xxI2cInit(struct HdfDeviceObject *device) - { - ... - //遍历、解析 i2c_config.hcs 中的所有配置节点,并分别进行初始化,需要调用Hi35xxI2cParseAndInit函数 - DEV_RES_NODE_FOR_EACH_CHILD_NODE(device->property, childNode) { - ret = Hi35xxI2cParseAndInit(device, childNode);//函数定义见下 - ... - } - ... - } - - static int32_t Hi35xxI2cParseAndInit(struct HdfDeviceObject *device, const struct DeviceResourceNode *node) - { - struct Hi35xxI2cCntlr *hi35xx = NULL; - ... - hi35xx = (struct Hi35xxI2cCntlr *)OsalMemCalloc(sizeof(*hi35xx)); // 内存分配 - ... - hi35xx->regBase = OsalIoRemap(hi35xx->regBasePhy, hi35xx->regSize); // 地址映射 - ... - Hi35xxI2cCntlrInit(hi35xx); // 【必要】i2c设备的初始化 - - hi35xx->cntlr.priv = (void *)node; //【必要】存储设备属性 - hi35xx->cntlr.busId = hi35xx->bus; //【必要】初始化I2cCntlr成员busId - hi35xx->cntlr.ops = &g_method; //【必要】I2cMethod的实例化对象的挂载 - hi35xx->cntlr.lockOps = &g_lockOps; //【必要】I2cLockMethod的实例化对象的挂载 - (void)OsalSpinInit(&hi35xx->spin); //【必要】锁的初始化 - ret = I2cCntlrAdd(&hi35xx->cntlr); //【必要】调用此函数填充核心层结构体,返回成功信号后驱动才完全接入平台核心层 - ... - #ifdef USER_VFS_SUPPORT - (void)I2cAddVfsById(hi35xx->cntlr.busId);//【可选】若支持用户级的虚拟文件系统,则接入 - #endif - return HDF_SUCCESS; - __ERR__: //不成功的话,需要反向执行初始化相关函数 - if (hi35xx != NULL) { - if (hi35xx->regBase != NULL) { - OsalIoUnmap((void *)hi35xx->regBase); - hi35xx->regBase = NULL; - } - OsalMemFree(hi35xx); - hi35xx = NULL; - } - return ret; - } - ``` - - - Release 函数参考 - - 入参: - - HdfDeviceObject 是整个驱动对外暴露的接口参数,具备 HCS 配置文件的信息。 - - 返回值: - - 无。 - - 函数说明: - - 释放内存和删除控制器,该函数需要在驱动入口结构体中赋值给 Release 接口, 当HDF框架调用Init函数初始化驱动失败时,可以调用 Release 释放驱动资源。 - - ``` - static void Hi35xxI2cRelease(struct HdfDeviceObject *device) - { - ... - //与Hi35xxI2cInit一样,需要将对每个节点分别进行释放 - DEV_RES_NODE_FOR_EACH_CHILD_NODE(device->property, childNode) { - Hi35xxI2cRemoveByNode(childNode);//函数定义见下 - } - } - - static void Hi35xxI2cRemoveByNode(const struct DeviceResourceNode *node) - { - ... - //【必要】可以调用 I2cCntlrGet 函数通过设备的 busid 获取 I2cCntlr 对象, 以及调用 I2cCntlrRemove 函数来释放 I2cCntlr 对象的内容 - cntlr = I2cCntlrGet(bus); - if (cntlr != NULL && cntlr->priv == node) { - ... - I2cCntlrRemove(cntlr); - //【必要】解除地址映射,锁和内存的释放 - hi35xx = (struct Hi35xxI2cCntlr *)cntlr; - OsalIoUnmap((void *)hi35xx->regBase); - (void)OsalSpinDestroy(&hi35xx->spin); - OsalMemFree(hi35xx); - } - return; - } - ``` - - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/05.I3C.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/05.I3C.md" deleted file mode 100644 index 4cd9bb5eb052b7467b9407b174c97b54510a06ed..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/05.I3C.md" +++ /dev/null @@ -1,423 +0,0 @@ ---- -title: I3C -permalink: /pages/0105020205 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# I3C - -- [概述](#1) -- [开发步骤](#2) -- [开发实例](#3) - -## 概述 - -I3C(Improved Inter Integrated Circuit)总线是由MIPI Alliance开发的一种简单、低成本的双向二线制同步串行总线。在HDF框架中,I3C模块接口适配模式采用统一服务模式,这需要一个设备服务来作为I3C模块的管理器,统一处理外部访问,这会在配置文件中有所体现。统一服务模式适合于同类型设备对象较多的情况,如I3C可能同时具备十几个控制器,采用独立服务模式需要配置更多的设备节点,且服务会占据内存资源。 - -![image1](/images/device-dev/driver/figures/统一服务模式结构图.png) - -## 开发步骤 - -I3C模块适配的四个环节是实例化驱动入口、配置属性文件、实例化I3C控制器对象以及注册中断处理子程序。 - -1. **实例化驱动入口:** - - 实例化HdfDriverEntry结构体成员。 - - 调用HDF_INIT将HdfDriverEntry实例化对象注册到HDF框架中。 - -2. **配置属性文件:** - - - 在device_info.hcs文件中添加deviceNode描述。 - - 【可选】添加i3c_config.hcs器件属性文件。 - -3. **实例化I3C控制器对象:** - - - 初始化I3cCntlr成员。 - - 实例化I3cCntlr成员I3cMethod方法集合,其定义和成员函数说明见下文。 - -4. **注册中断处理子程序:** - 为控制器注册中断处理程序,实现设备热接入和IBI(带内中断)功能。 - - I3cMethod定义: - ```c - struct I3cMethod { - int32_t (*sendCccCmd)(struct I3cCntlr *cntlr, struct I3cCccCmd *ccc); - int32_t (*transfer)(struct I3cCntlr *cntlr, struct I3cMsg *msgs, int16_t count); - int32_t (*i2cTransfer)(struct I3cCntlr *cntlr, struct I3cMsg *msgs, int16_t count); - int32_t (*setConfig)(struct I3cCntlr *cntlr, struct I3cConfig *config); - int32_t (*getConfig)(struct I3cCntlr *cntlr, struct I3cConfig *config); - int32_t (*requestIbi)(struct I3cDevice *dev); - void (*freeIbi)(struct I3cDevice *dev); - }; - ``` - - 表1 I3cMethod结构体成员的回调函数功能说明 - - |函数成员|入参|出参|返回值|功能| - |-|-|-|-|-| - |sendCccCmd|**cntlr**: 结构体指针,核心层I3C控制器;
**ccc**:传入的通用命令代码结构体指针;|**ccc**:传出的通用命令代码结构体指针;|HDF_STATUS相关状态|发送CCC(Common command Code,即通用命令代码)| - |Transfer |**cntlr**: 结构体指针,核心层I3C控制器;
**msgs**:结构体指针,用户消息 ;
**count**:int16_t,消息数量|**msgs**:结构体指针,用户消息 ;|HDF_STATUS相关状态|使用I3C模式传递用户消息| - |i2cTransfer |**cntlr**: 结构体指针,核心层I3C控制器;
**msgs**:结构体指针,用户消息 ;
**count**:int16_t,消息数量|**msgs**:结构体指针,用户消息 ;|HDF_STATUS相关状态|使用I2C模式传递用户消息| - |setConfig|**cntlr**: 结构体指针,核心层I3C控制器;
**config**: 控制器配置参数|无|HDF_STATUS相关状态|设置I3C控制器配置参数| - |getConfig|**cntlr**: 结构体指针,核心层I3C控制器;|**config**: 控制器配置参数|HDF_STATUS相关状态|获取I3C控制器配置参数| - |requestIbi|**device**: 结构体指针,核心层I3C设备;|无|HDF_STATUS相关状态|为I3C设备请求IBI(In-Bind Interrupt,即带内中断)| - |freeIbi|**device**: 结构体指针,核心层I3C设备;|无|HDF_STATUS相关状态|释放IBI| - -## 开发实例 - -1. 驱动开发首先需要实例化驱动入口,驱动入口必须为HdfDriverEntry(在 hdf_device_desc.h 中定义)类型的全局变量,且moduleName要和device_info.hcs中保持一致。HDF框架会将所有加载的驱动的HdfDriverEntry对象首地址汇总,形成一个类似数组的段地址空间,方便上层调用。 - - 一般在加载驱动时HDF会先调用Bind函数,再调用Init函数加载该驱动。当Init调用异常时,HDF框架会调用Release释放驱动资源并退出。 - - I3C驱动入口参考: - - > I3C模块这种类型的控制器会出现很多个控制器挂接的情况,因而在HDF框架中首先会为这类型的控制器创建一个管理器对象,并同时对外发布一个管理器服务来统一处理外部访问。这样,用户需要打开某个控制器时,会先获取到管理器服务,然后管理器服务根据用户指定参数查找到指定控制器。 - > - > I3C管理器服务的驱动由核心层实现,**厂商不需要关注这部分内容的实现,但在实现Init函数的时候需要调用核心层的I3cCntlrAdd函数,它会实现相应功能。** - - ```c - static struct HdfDriverEntry g_virtualI3cDriverEntry = { - .moduleVersion = 1, - .Init = VirtualI3cInit, - .Release = VirtualI3cRelease, - .moduleName = "virtual_i3c_driver",//【必要且与 HCS 里面的名字匹配】 - }; - HDF_INIT(g_virtualI3cDriverEntry); //调用HDF_INIT将驱动入口注册到HDF框架中 - - /* 核心层i3c_core.c管理器服务的驱动入口 */ - struct HdfDriverEntry g_i3cManagerEntry = { - .moduleVersion = 1, - .Init = I3cManagerInit, - .Release = I3cManagerRelease, - .moduleName = "HDF_PLATFORM_I3C_MANAGER",//这与device_info文件中device0对应 - }; - HDF_INIT(g_i3cManagerEntry); - ``` - -2. 完成驱动入口注册之后,下一步请在device_info.hcs文件中添加deviceNode信息,并在i3c_config.hcs中配置器件属性。deviceNode信息与驱动入口注册相关,器件属性值对于厂商驱动的实现以及核心层I3cCntlr相关成员的默认值或限制范围有密切关系。 - - **统一服务模式**的特点是device_info文件中第一个设备节点必须为I3C管理器,其各项参数必须如下设置: - - |成员名|值| - |-|-| - |moduleName |HDF_PLATFORM_I3C_MANAGER| - |serviceName|无(预留)| - |policy|0| - |cntlrMatchAttr| 无(预留)| - - 从第二个节点开始配置具体I3C控制器信息,此节点并不表示某一路I3C控制器,而是代表一个资源性质设备,用于描述一类I3C控制器的信息。本例只有一个I3C控制器,如有多个控制器,则需要在device_info文件增加deviceNode信息,以及在i3c_config文件中增加对应的器件属性。 - - - device_info.hcs 配置参考 - - ```c - root { - device_i3c :: device { - device0 :: deviceNode { - policy = 0; - priority = 52; - permission = 0644; - serviceName = "HDF_PLATFORM_I3C_MANAGER"; - moduleName = "HDF_PLATFORM_I3C_MANAGER"; - } - } - i3c_virtual :: deviceNode { - policy = 0; // 等于0,不需要发布服务 - priority = 56; // 驱动启动优先级 - permission = 0644; // 驱动创建设备节点权限 - moduleName = "virtual_i3c_driver"; //【必要】用于指定驱动名称,需要与期望的驱动Entry中的moduleName一致; - serviceName = "VIRTUAL_I3C_DRIVER"; //【必要】驱动对外发布服务的名称,必须唯一 - deviceMatchAttr = "virtual_i3c"; //【必要】用于配置控制器私有数据,要与i3c_config.hcs中对应控制器保持一致 - } // 具体的控制器信息在 i3c_config.hcs 中 - } - ``` - - - i3c_config.hcs 配置参考 - - ```c - root { - platform { - i3c_config { - match_attr = "virtual_i3c"; //【必要】需要和device_info.hcs中的deviceMatchAttr值一致 - template i3c_controller { // 模板公共参数,继承该模板的节点如果使用模板中的默认值,则节点字段可以缺省 - busId = 0; //【必要】i3c总线号 - busMode = 0x0; // 总线模式,0x0:纯净; 0x1:混合高速; 0x2:混合受限; 0x3: 混合低速; - regBasePhy = 0x120b0000; //【必要】物理基地址 - regSize = 0xd1; //【必要】寄存器位宽 - IrqNum = 20; //【必要】中断号 - i3cMaxRate = 12900000; //【可选】i3c模式最大时钟速率 - i3cRate = 12500000; //【可选】i3c模式时钟速率 - i2cFmRate = 1000000; //【可选】i2c FM模式时钟速率 - i2cFmPlusRate = 400000; //【可选】i2c FM+模式时钟速率 - } - controller_0 :: i3c_controller { - busId = 18; - IrqNum = 20; - } - } - } - } - ``` - -3. 配置属性文件完成后,要以核心层I3cCntlr对象的初始化为核心,包括厂商自定义结构体(传递参数和数据),实例化I3cCntlr成员I3cMethod(让用户可以通过接口来调用驱动底层函数)。 - - 此步骤需要通过实现HdfDriverEntry成员函数(Bind,Init,Release)来完成。 - - - 自定义结构体参考 - - > 从驱动的角度看,自定义结构体是参数和数据的载体,而且i3c_config.hcs文件中的数值会被HDF读入通过DeviceResourceIface来初始化结构体成员,其中一些重要数值也会传递给核心层I3cCntlr对象,例如设备号、总线号等。 - - ```c - struct VirtualI3cCntlr { - struct I3cCntlr cntlr; //【必要】是核心层控制对象,具体描述见下面 - volatile unsigned char *regBase;//【必要】寄存器基地址 - uint32_t regBasePhy; //【必要】寄存器物理基地址 - uint32_t regSize; //【必要】寄存器位宽 - uint16_t busId; //【必要】设备号 - uint16_t busMode; - uint16_t IrqNum; - uint32_t i3cMaxRate; - uint32_t i3cRate; - uint32_t i2cFmRate; - uint32_t i2cFmPlusRate; - }; - - /* I3cCntlr是核心层控制器结构体,其中的成员在Init函数中被赋值 */ - struct I3cCntlr { - OsalSpinlock lock; - void *owner; - int16_t busId; - struct I3cConfig config; - uint16_t addrSlot[(I3C_ADDR_MAX + 1) / ADDRS_PER_UINT16]; - struct I3cIbiInfo *ibiSlot[I3C_IBI_MAX]; - const struct I3cMethod *ops; - const struct I3cLockMethod *lockOps; - void *priv; - }; - ``` - - > **【重要】** I3cCntlr成员回调函数结构体I3cMethod的实例化,I3cLockMethod回调函数结构体本例未实现,若要实例化,可参考I2C驱动开发,其他成员在Init函数中初始化 - - - - **init函数参考** - - > **入参:** - > HdfDeviceObject 是整个驱动对外暴露的接口参数,具备 HCS 配置文件的信息 - > - > **返回值:** - > HDF_STATUS相关状态 (下表为部分展示,如需使用其他状态,可见//drivers/framework/include/utils/hdf_base.h中HDF_STATUS 定义) - - |状态(值)|问题描述| - |:-|:-:| - |HDF_ERR_INVALID_OBJECT|控制器对象非法| - |HDF_ERR_INVALID_PARAM |参数非法| - |HDF_ERR_MALLOC_FAIL |内存分配失败| - |HDF_ERR_IO |I/O 错误| - |HDF_SUCCESS |传输成功| - |HDF_FAILURE |传输失败| - - > **函数说明:** - > 初始化自定义结构体对象,初始化I3cCntlr成员,调用核心层I3cCntlrAdd函数。 - - ```c - static int32_t VirtualI3cParseAndInit(struct HdfDeviceObject *device, const struct DeviceResourceNode *node) - { - int32_t ret; - struct VirtualI3cCntlr *virtual = NULL; //【必要】自定义结构体对象 - (void)device; - - virtual = (struct VirtualI3cCntlr *)OsalMemCalloc(sizeof(*virtual)); //【必要】内存分配 - if (virtual == NULL) { - HDF_LOGE("%s: Malloc virtual fail!", __func__); - return HDF_ERR_MALLOC_FAIL; - } - - ret = VirtualI3cReadDrs(virtual, node); //【必要】将i3c_config文件的默认值填充到结构体中 - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: Read drs fail! ret:%d", __func__, ret); - goto __ERR__; - } - ... - virtual->regBase = OsalIoRemap(virtual->regBasePhy, virtual->regSize);//【必要】地址映射 - ret = OsalRegisterIrq(hi35xx->softIrqNum, OSAL_IRQF_TRIGGER_NONE, I3cIbiHandle, "I3C", virtual); //【必要】注册中断程序 - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: register irq failed!", __func__); - return ret; - } - ... - VirtualI3cCntlrInit(virtual); //【必要】I3C设备的初始化 - virtual->cntlr.priv = (void *)node; //【必要】存储设备属性 - virtual->cntlr.busId = virtual->busId; //【必要】初始化I3cCntlr成员 - virtual->cntlr.ops = &g_method; //【必要】I3cMethod的实例化对象的挂载 - (void)OsalSpinInit(&virtual->spin); - ret = I3cCntlrAdd(&virtual->cntlr); //【必要且重要】调用此函数将控制器添加至核心,返回成功信号后驱动才完全接入平台核心层 - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: add i3c controller failed! ret = %d", __func__, ret); - (void)OsalSpinDestroy(&virtual->spin); - goto __ERR__; - } - - return HDF_SUCCESS; - __ERR__: //若控制器添加失败,需要执行去初始化相关函数 - if (virtual != NULL) { - OsalMemFree(virtual); - virtual = NULL; - } - - return ret; - } - - static int32_t VirtualI3cInit(struct HdfDeviceObject *device) - { - int32_t ret; - const struct DeviceResourceNode *childNode = NULL; - - if (device == NULL || device->property == NULL) { - HDF_LOGE("%s: device or property is NULL", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - DEV_RES_NODE_FOR_EACH_CHILD_NODE(device->property, childNode) { - ret = VirtualI3cParseAndInit(device, childNode); - if (ret != HDF_SUCCESS) { - break; - } - } - - return ret; - } - ``` - - - **Release 函数参考** - - > **入参:** - > HdfDeviceObject 是整个驱动对外暴露的接口参数,具备 HCS 配置文件的信息 。 - > - > **返回值:** - > 无。 - > - > **函数说明:** - > 释放内存和删除控制器,该函数需要在驱动入口结构体中赋值给 Release 接口, 当HDF框架调用Init函数初始化驱动失败时,可以调用 Release 释放驱动资源。所有强制转换获取相应对象的操作**前提**是在Init函数中具备对应赋值的操作。 - - ```c - static void VirtualI3cRemoveByNode(const struct DeviceResourceNode *node) - { - int32_t ret; - int16_t busId; - struct I3cCntlr *cntlr = NULL; - struct VirtualI3cCntlr *virtual = NULL; - struct DeviceResourceIface *drsOps = NULL; - - drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); - if (drsOps == NULL || drsOps->GetUint32 == NULL) { - HDF_LOGE("%s: invalid drs ops fail!", __func__); - return; - } - - ret = drsOps->GetUint16(node, "busId", (uint16_t *)&busId, 0); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: read busId fail!", __func__); - return; - } - ... - /* 可以调用I3cCntlrGet函数通过设备的cntlrNum获取I3cCntlr对象, 以及调用I3cCntlrRemove函数来释放I3cCntlr对象的内容 */ - cntlr = I3cCntlrGet(busId); - if (cntlr != NULL && cntlr->priv == node) { - I3cCntlrPut(cntlr); - I3cCntlrRemove(cntlr); //【必要】主要是从管理器驱动那边移除I3cCntlr对象 - virtual = (struct VirtualI3cCntlr *)cntlr;//【必要】通过强制转换获取自定义的对象并进行release操作 - (void)OsalSpinDestroy(&virtual->spin); - OsalMemFree(virtual); - } - return; - } - - static void VirtualI3cRelease(struct HdfDeviceObject *device) - { - const struct DeviceResourceNode *childNode = NULL; - - HDF_LOGI("%s: enter", __func__); - - if (device == NULL || device->property == NULL) { - HDF_LOGE("%s: device or property is NULL", __func__); - return; - } - ... - //遍历、解析i3c_config.hcs中的所有配置节点,并分别进行release操作 - DEV_RES_NODE_FOR_EACH_CHILD_NODE(device->property, childNode) { - VirtualI3cRemoveByNode(childNode); //函数定义如上 - } - } - ``` - -4. 最后一步,实现中断处理程序,在中断处理程序中通过判断中断产生的地址,实现热接入、IBI等操作。 - - ```c - static int32_t VirtualI3cReservedAddrWorker(struct VirtualI3cCntlr *virtual, uint16_t addr) - { - (void)virtual; - switch (addr) { - case I3C_HOT_JOIN_ADDR: - VirtualI3cHotJoin(virtual); - break; - case I3C_RESERVED_ADDR_7H3E: - case I3C_RESERVED_ADDR_7H5E: - case I3C_RESERVED_ADDR_7H6E: - case I3C_RESERVED_ADDR_7H76: - case I3C_RESERVED_ADDR_7H7A: - case I3C_RESERVED_ADDR_7H7C: - case I3C_RESERVED_ADDR_7H7F: - /* 广播地址单比特错误的所有情形 */ - HDF_LOGW("%s: broadcast Address single bit error!", __func__); - break; - default: - HDF_LOGD("%s: Reserved address which is not supported!", __func__); - break; - } - - return HDF_SUCCESS; - } - ``` - - ```c - static int32_t I3cIbiHandle(uint32_t irq, void *data) - { - struct VirtualI3cCntlr *virtual = NULL; - struct I3cDevice *device = NULL; - uint16_t ibiAddr; - char *testStr = "Hello I3C!"; - - (void)irq; - if (data == NULL) { - HDF_LOGW("%s: data is NULL!", __func__); - return HDF_ERR_INVALID_PARAM; - } - virtual = (struct VirtualI3cCntlr *)data; - /* 【必要】获取产生中断的地址,使用CHECK_RESERVED_ADDR宏判断该地址是否为I3C保留地址 */ - ibiAddr = VirtualI3cGetIbiAddr(); - if (CHECK_RESERVED_ADDR(ibiAddr) == I3C_ADDR_RESERVED) { - HDF_LOGD("%s: Calling VirtualI3cResAddrWorker...", __func__); - return VirtualI3cReservedAddrWorker(virtual, ibiAddr); - } else { - HDF_LOGD("%s: Calling I3cCntlrIbiCallback...", __func__); - device = GetDeviceByAddr(&virtual->cntlr, ibiAddr); - if (device == NULL) { - HDF_LOGE("func:%s device is NULL!",__func__); - return HDF_ERR_MALLOC_FAIL; - } - if (device->ibi->payload > VIRTUAL_I3C_TEST_STR_LEN) { - /* 将字符串"Hello I3C!"放入IBI缓冲区内 */ - *device->ibi->data = *testStr; - } - /* 根据产生IBI的I3C设备调用IBI回调函数 */ - return I3cCntlrIbiCallback(device); - } - - return HDF_SUCCESS; - } - ``` \ No newline at end of file diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/06.MIPI-CSI.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/06.MIPI-CSI.md" deleted file mode 100644 index 8192ebc8df998b04d15229b0ca482b75077a470f..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/06.MIPI-CSI.md" +++ /dev/null @@ -1,327 +0,0 @@ ---- -title: MIPI-CSI -permalink: /pages/0105020206 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# MIPI-CSI - -- [概述](#section1_MIPI_CSIDevelop) -- [接口说明](#section2_MIPI_CSIDevelop) -- [开发步骤](#section3_MIPI_CSIDevelop) -- [开发实例](#section4_MIPI_CSIDevelop) - -## 概述 - -CSI(Camera Serial Interface)是由MIPI(Mobile Industry Processor Interface )联盟下Camera工作组指定的接口标准。在HDF框架中,MIPI-CSI的接口适配模式采用无服务模式,用于不需要在用户态提供API的设备类型,或者没有用户态和内核区分的OS系统,MIPI-CSI的接口关联方式是DevHandle直接指向设备对象内核态地址(DevHandle是一个void类型指针)。 - -图 1 无服务模式结构图 -![image1](/images/device-dev/driver/figures/无服务模式结构图.png) - -## 接口说明 - -MipiCsiCntlrMethod定义 - -```c -struct MipiCsiCntlrMethod { - int32_t (*setComboDevAttr)(struct MipiCsiCntlr *cntlr, ComboDevAttr *pAttr); - int32_t (*setPhyCmvmode)(struct MipiCsiCntlr *cntlr, uint8_t devno, PhyCmvMode cmvMode); - int32_t (*setExtDataType)(struct MipiCsiCntlr *cntlr, ExtDataType* dataType); - int32_t (*setHsMode)(struct MipiCsiCntlr *cntlr, LaneDivideMode laneDivideMode); - int32_t (*enableClock)(struct MipiCsiCntlr *cntlr, uint8_t comboDev); - int32_t (*disableClock)(struct MipiCsiCntlr *cntlr, uint8_t comboDev); - int32_t (*resetRx)(struct MipiCsiCntlr *cntlr, uint8_t comboDev); - int32_t (*unresetRx)(struct MipiCsiCntlr *cntlr, uint8_t comboDev); - int32_t (*enableSensorClock)(struct MipiCsiCntlr *cntlr, uint8_t snsClkSource); - int32_t (*disableSensorClock)(struct MipiCsiCntlr *cntlr, uint8_t snsClkSource); - int32_t (*resetSensor)(struct MipiCsiCntlr *cntlr, uint8_t snsResetSource); - int32_t (*unresetSensor)(struct MipiCsiCntlr *cntlr, uint8_t snsResetSource); -}; -``` -表1 MipiCsiCntlrMethod成员的回调函数功能说明 -| 成员函数 | 入参 | 出参 | 返回状态 | 功能 | -| ------------------ | ------------------------------------------------------------ | ---- | ------------------ | -------------------------- | -| setComboDevAttr | **cntlr**:结构体指针,MipiCsi控制器 ;
**pAttr**:结构体指针,MIPI-CSI相应配置结构体指针 | 无 | HDF_STATUS相关状态 | 写入MIPI-CSI配置 | -| setPhyCmvmode | **cntlr**:结构体指针,MipiCsi控制器 ;
**devno**:uint8_t,设备编号;
**cmvMode**:枚举类型,共模电压模式参数 | 无 | HDF_STATUS相关状态 | 设置共模电压模式 | -| setExtDataType | **cntlr**:结构体指针,MipiCsi控制器 ;
**dataType**:结构体指针,定义YUV和原始数据格式以及位深度 | 无 | HDF_STATUS相关状态 | 设置YUV和RAW数据格式和位深 | -| setHsMode | **cntlr**:结构体指针,MipiCsi控制器 ;
**laneDivideMode**:枚举类型,lane模式参数 | 无 | HDF_STATUS相关状态 | 设置MIPI RX的Lane分布 | -| enableClock | **cntlr**:结构体指针,MipiCsi控制器 ;
**comboDev**:uint8_t,通路序号 | 无 | HDF_STATUS相关状态 | 使能mipi的时钟 | -| disableClock | **cntlr**:结构体指针,MipiCsi控制器 ;
**comboDev**:uint8_t,通路序号 | 无 | HDF_STATUS相关状态 | 关闭mipi的时钟 | -| resetRx | **cntlr**:结构体指针,MipiCsi控制器 ;
**comboDev**:uint8_t,通路序号 | 无 | HDF_STATUS相关状态 | 复位MIPI RX | -| unresetRx | **cntlr**:结构体指针,MipiCsi控制器 ;
**comboDev**:uint8_t,通路序号 | 无 | HDF_STATUS相关状态 | 撤销复位MIPI RX | -| enableSensorClock | **cntlr**:结构体指针,MipiCsi控制器 ;
**snsClkSource**:uint8_t,传感器的时钟信号线号 | 无 | HDF_STATUS相关状态 | 使能mipi上的Sensor时钟 | -| disableSensorClock | **cntlr**:结构体指针,MipiCsi控制器 ;
**snsClkSource**:uint8_t,传感器的时钟信号线号 | 无 | HDF_STATUS相关状态 | 关闭mipi上的Sensor时钟 | -| resetSensor | **cntlr**:结构体指针,MipiCsi控制器 ;
**snsClkSource**:uint8_t,传感器的时钟信号线号 | 无 | HDF_STATUS相关状态 | 复位Sensor | -| unresetSensor | **cntlr**:结构体指针,MipiCsi控制器 ;
**snsClkSource**:uint8_t,传感器的时钟信号线号 | 无 | HDF_STATUS相关状态 | 撤销复位Sensor | - -## 开发步骤 - -MIPI-CSI模块适配的三个环节是配置属性文件、实例化驱动入、以及实例化核心层接口函数。 - -1. **实例化驱动入口:** - - 实例化HdfDriverEntry结构体成员。 - - 调用HDF_INIT将HdfDriverEntry实例化对象注册到HDF框架中。 - -2. **配置属性文件:** - - - 在device_info.hcs文件中添加deviceNode描述。 - - 【可选】添加mipicsi_config.hcs器件属性文件。 - -3. **实例化MIPICSI控制器对象:** - - 初始化MipiCsiCntlr成员。 - - 实例化MipiCsiCntlr成员MipiCsiCntlrMethod。 - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >实例化MipiCsiCntlr成员MipiCsiCntlrMethod,其定义和成员说明见[接口说明](#section2_MIPI_CSIDevelop)。 - -4. **驱动调试:** - - 【可选】针对新增驱动程序,建议验证驱动基本功能,例如挂载后的信息反馈,数据传输的成功与否等。 - - -## 开发实例 - -下方将以mipi_rx_hi35xx.c为示例,展示需要厂商提供哪些内容来完整实现设备功能。 - - -1. 一般来说,驱动开发首先需要在 busxx_config.hcs 中配置器件属性,并在device_info.hcs文件中添加deviceNode描述。器件属性值与核心层MipiCsiCntlr 成员的默认值或限制范围有密切关系,deviceNode信息与驱动入口注册相关。 - - **本例中MIPI控制器自身属性在源文件文件中,如有厂商需要,则在device_info文件的deviceNode增加deviceMatchAttr信息,相应增加mipicsi_config.hcs文件**。 - -- device_info.hcs 配置参考 - - ```c - root { - device_info { - match_attr = "hdf_manager"; - platform :: host { - hostName = "platform_host"; - priority = 50; - device_mipi_csi:: device { - device0 :: deviceNode { - policy = 0; - priority = 160; - permission = 0644; - moduleName = "HDF_MIPI_RX"; //【必要】用于指定驱动名称,需要与期望的驱动Entry中的moduleName一致; - serviceName = "HDF_MIPI_RX"; //【必要且唯一】驱动对外发布服务的名称 - } - } - } - } - } - ``` - -2. 完成器件属性文件的配置之后,下一步请实例化驱动入口,驱动入口必须为HdfDriverEntry(在 hdf_device_desc.h 中定义)类型的全局变量,且moduleName要和device_info.hcs中保持一致。HdfDriverEntry结构体的函数指针成员会被厂商操作函数填充,HDF框架会将所有加载的驱动的HdfDriverEntry对象首地址汇总,形成一个类似数组,方便调用。 - - 一般在加载驱动时HDF框架会先调用Bind函数,再调用Init函数加载该驱动。当Init调用异常时,HDF框架会调用Release释放驱动资源并退出。 - -- MIPI-CSI驱动入口参考 - - ```c - struct HdfDriverEntry g_mipiCsiDriverEntry = { - .moduleVersion = 1, - .Init = Hi35xxMipiCsiInit, //见Init参考 - .Release = Hi35xxMipiCsiRelease, //见Release参考 - .moduleName = "HDF_MIPI_RX", //【必要】需要与device_info.hcs 中保持一致。 - }; - HDF_INIT(g_mipiCsiDriverEntry); //调用HDF_INIT将驱动入口注册到HDF框架中 - ``` - -3. 完成驱动入口注册之后,最后一步就是以核心层MipiCsiCntlr对象的初始化为核心,实现HdfDriverEntry成员函数(Bind,Init,Release)。MipiCsiCntlr对象的初始化包括厂商自定义结构体(用于传递参数和数据)和实例化MipiCsiCntlr成员MipiCsiCntlrMethod(让用户可以通过接口来调用驱动底层函数)。 - -- 自定义结构体参考 - - > 从驱动的角度看,自定义结构体是参数和数据的载体,一般来说,config文件中的数值也会用来初始化结构体成员,本例的mipicsi器件属性在源文件中,故基本成员结构与MipiCsiCntlr无太大差异。 - - ```c - typedef struct { - /** 数据类型:8/10/12/14/16位 */ - DataType inputDataType; - /** MIPI波分复用模式 */ - MipiWdrMode wdrMode; - /** laneId: -1 - 禁用 */ - short laneId[MIPI_LANE_NUM]; - - union { - /** 用于 HI_MIPI_WDR_MODE_DT */ - short dataType[WDR_VC_NUM]; - }; - } MipiDevAttr; - - typedef struct { - /** 设备号 */ - uint8_t devno; - /** 输入模式: MIPI/LVDS/SUBLVDS/HISPI/DC */ - InputMode inputMode; - MipiDataRate dataRate; - /** MIPI Rx设备裁剪区域(与原始传感器输入图像大小相对应) */ - ImgRect imgRect; - - union { - MipiDevAttr mipiAttr; - LvdsDevAttr lvdsAttr; - }; - } ComboDevAttr; - - //MipiCsiCntlr是核心层控制器结构体,其中的成员在Init函数中会被赋值 - struct MipiCsiCntlr { - /** 当驱动程序绑定到HDF框架时,将发送此控制器提供的服务 */ - struct IDeviceIoService service; - /** 当驱动程序绑定到HDF框架时,将传入设备端指针 */ - struct HdfDeviceObject *device; - /** 设备号 */ - unsigned int devNo; - /** 控制器提供的所有接口 */ - struct MipiCsiCntlrMethod *ops; - /** 对于控制器调试的所有接口,如果未实现驱动程序,则需要null */ - struct MipiCsiCntlrDebugMethod *debugs; - /** 控制器上下文参数变量 */ - MipiDevCtx ctx; - /** 访问控制器上下文参数变量时锁定 */ - OsalSpinlock ctxLock; - /** 操作控制器时锁定方法 */ - struct OsalMutex lock; - /** 匿名数据指针,用于存储csi设备结构 */ - void *priv; - }; - ``` - -- **【重要】** MipiCsiCntlr成员回调函数结构体MipiCsiCntlrMethod的实例化,其他成员在Init函数中初始化。 - - ```c - static struct MipiCsiCntlrMethod g_method = { - .setComboDevAttr = Hi35xxSetComboDevAttr, - .setPhyCmvmode = Hi35xxSetPhyCmvmode, - .setExtDataType = Hi35xxSetExtDataType, - .setHsMode = Hi35xxSetHsMode, - .enableClock = Hi35xxEnableClock, - .disableClock = Hi35xxDisableClock, - .resetRx = Hi35xxResetRx, - .unresetRx = Hi35xxUnresetRx, - .enableSensorClock = Hi35xxEnableSensorClock, - .disableSensorClock = Hi35xxDisableSensorClock, - .resetSensor = Hi35xxResetSensor, - .unresetSensor = Hi35xxUnresetSensor - }; - ``` - -- **Init函数参考** - - > **入参:** - > HdfDeviceObject 是整个驱动对外暴露的接口参数,具备 HCS 配置文件的信息 - > - > **返回值:** - > HDF_STATUS相关状态 (下表为部分展示,如需使用其他状态,可见//drivers/framework/include/utils/hdf_base.h中HDF_STATUS 定义) - > - > | 状态(值) | 问题描述 | - > | :--------------------- | :----------: | - > | HDF_ERR_INVALID_OBJECT | 无效对象 | - > | HDF_ERR_MALLOC_FAIL | 内存分配失败 | - > | HDF_ERR_INVALID_PARAM | 无效参数 | - > | HDF_ERR_IO | I/O 错误 | - > | HDF_SUCCESS | 执行成功 | - > | HDF_FAILURE | 执行失败 | - > - > **函数说明:** - > MipiCsiCntlrMethod的实例化对象的挂载,调用MipiCsiRegisterCntlr,以及其他厂商自定义初始化操作。 - - ```c - static int32_t Hi35xxMipiCsiInit(struct HdfDeviceObject *device) - { - int32_t ret; - - HDF_LOGI("%s: enter!", __func__); - g_mipiCsi.priv = NULL; //g_mipiTx是定义的全局变量 - //static struct MipiCsiCntlr g_mipiCsi = { - //.devNo = 0 - //}; - g_mipiCsi.ops = &g_method; //MipiCsiCntlrMethod的实例化对象的挂载 - #ifdef CONFIG_HI_PROC_SHOW_SUPPORT - g_mipiCsi.debugs = &g_debugMethod; - #endif - ret = MipiCsiRegisterCntlr(&g_mipiCsi, device); //【必要】调用核心层函数和g_mipiTx初始化核心层全局变量 - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: [MipiCsiRegisterCntlr] failed!", __func__); - return ret; - } - - ret = MipiRxDrvInit(); //【必要】厂商对设备的初始化,形式不限 - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: [MipiRxDrvInit] failed.", __func__); - return ret; - } - #ifdef MIPICSI_VFS_SUPPORT - ret = MipiCsiDevModuleInit(g_mipiCsi.devNo); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: [MipiCsiDevModuleInit] failed!", __func__); - return ret; - } - #endif - - OsalSpinInit(&g_mipiCsi.ctxLock); - HDF_LOGI("%s: load mipi csi driver success!", __func__); - - return ret; - } - - //mipi_dsi_core.c核心层 - int32_t MipiCsiRegisterCntlr(struct MipiCsiCntlr *cntlr, struct HdfDeviceObject *device) - { - ... - //定义的全局变量:static struct MipiCsiHandle g_mipiCsihandle[MAX_CNTLR_CNT]; - if (g_mipiCsihandle[cntlr->devNo].cntlr == NULL) { - (void)OsalMutexInit(&g_mipiCsihandle[cntlr->devNo].lock); - (void)OsalMutexInit(&(cntlr->lock)); - - g_mipiCsihandle[cntlr->devNo].cntlr = cntlr; //初始化MipiCsiHandle成员 - g_mipiCsihandle[cntlr->devNo].priv = NULL; - cntlr->device = device; //使HdfDeviceObject与MipiCsiHandle可以相互转化的前提 - device->service = &(cntlr->service); //使HdfDeviceObject与MipiCsiHandle可以相互转化的前提 - cntlr->priv = NULL; - HDF_LOGI("%s: success.", __func__); - - return HDF_SUCCESS; - } - - HDF_LOGE("%s: cntlr already exists.", __func__); - return HDF_FAILURE; - } - ``` - -- **Release函数参考** - - > **入参:** - > HdfDeviceObject 是整个驱动对外暴露的接口参数,具备 HCS 配置文件的信息。 - > - > **返回值:** - > 无 - > - > **函数说明:** - > 该函数需要在驱动入口结构体中赋值给Release接口,当HDF框架调用Init函数初始化驱动失败时,可以调用Release释放驱动资源,该函数中需包含释放内存和删除控制器等操作。所有强制转换获取相应对象的操作**前提**是在Init函数中具备对应赋值的操作。 - - ```c - static void Hi35xxMipiCsiRelease(struct HdfDeviceObject *device) - { - struct MipiCsiCntlr *cntlr = NULL; - ... - cntlr = MipiCsiCntlrFromDevice(device); //这里有HdfDeviceObject到MipiCsiCntlr的强制转化 - //return (device == NULL) ? NULL : (struct MipiCsiCntlr *)device->service; - ... - - OsalSpinDestroy(&cntlr->ctxLock); - #ifdef MIPICSI_VFS_SUPPORT - MipiCsiDevModuleExit(cntlr->devNo); - #endif - MipiRxDrvExit(); //【必要】对厂商设备所占资源的释放 - MipiCsiUnregisterCntlr(&g_mipiCsi); //空函数 - g_mipiCsi.priv = NULL; - - HDF_LOGI("%s: unload mipi csi driver success!", __func__); - } - ``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/07.MIPI-DSI.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/07.MIPI-DSI.md" deleted file mode 100644 index 36c6912741da96295a431a8a973a1e20620ddee9..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/07.MIPI-DSI.md" +++ /dev/null @@ -1,352 +0,0 @@ ---- -title: MIPI-DSI -permalink: /pages/0105020207 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# MIPI-DSI - -- [概述](#section1266787503161538) -- [接口说明](#section752964871810) -- [开发步骤](#section545182932161538) -- [开发实例](#section1167576616161538) - -## 概述 - -DSI(Display Serial Interface)是由移动行业处理器接口联盟(Mobile Industry Processor Interface \(MIPI\) Alliance)制定的规范。在HDF框架中,MIPI-DSI的接口适配模式采用无服务模式,用于不需要在用户态提供API的设备类型,或者没有用户态和内核区分的OS系统,其关联方式是DevHandle直接指向设备对象内核态地址(DevHandle是一个void类型指针)。 - -**图 1** DSI无服务模式结构图 -![](/images/device-dev/driver/figures/无服务模式结构图.png "DSI无服务模式结构图") - -## 接口说明 - -MipiDsiCntlrMethod定义: - -``` -struct MipiDsiCntlrMethod { // 核心层结构体的成员函数 - int32_t (*setCntlrCfg)(struct MipiDsiCntlr *cntlr); - int32_t (*setCmd)(struct MipiDsiCntlr *cntlr, struct DsiCmdDesc *cmd); - int32_t (*getCmd)(struct MipiDsiCntlr *cntlr, struct DsiCmdDesc *cmd, uint32_t readLen, uint8_t *out); - void (*toHs)(struct MipiDsiCntlr *cntlr); - void (*toLp)(struct MipiDsiCntlr *cntlr); - void (*enterUlps)(struct MipiDsiCntlr *cntlr);//【可选】进入超低功耗模式 - void (*exitUlps)(struct MipiDsiCntlr *cntlr); //【可选】退出超低功耗模式 - int32_t (*powerControl)(struct MipiDsiCntlr *cntlr, uint8_t enable);//【可选】使能/去使能功耗控制 - int32_t (*attach)(struct MipiDsiCntlr *cntlr);//【可选】将一个DSI设备连接上host -}; -``` - -**表 1** MipiDsiCntlrMethod成员的回调函数功能说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

成员函数

-

入参

-

出参

-

返回状态

-

功能

-

setCntlrCfg

-

cntlr: 结构体指针,MipiDsi控制器 ;

-

-

HDF_STATUS相关状态

-

设置控制器参数

-

setCmd

-

cntlr: 结构体指针,MipiDsi控制器 ;cmd: 结构体指针,指令传入值

-

-

HDF_STATUS相关状态

-

向显示设备发送指令

-

getCmd

-

cntlr: 结构体指针,MipiDsi控制器 ;

-

cmd: 结构体指针,用于传出指令值;

-

HDF_STATUS相关状态

-

从显示设备读取信息指令

-

toHs

-

cntlr: 结构体指针,MipiDsi控制器 ;

-

-

HDF_STATUS相关状态

-

设置为高速模式

-

toLp

-

cntlr: 结构体指针,MipiDsi控制器 ;

-

-

HDF_STATUS相关状态

-

设置为低电模式

-
- -## 开发步骤 - -MIPI-DSI模块适配的三个环节是配置属性文件,实例化驱动入口,以及实例化核心层接口函数。 - -1. **实例化驱动入口:** - - 实例化HdfDriverEntry结构体成员。 - - 调用HDF\_INIT将HdfDriverEntry实例化对象注册到HDF框架中。 - -2. **配置属性文件:** - - 在device\_info.hcs文件中添加deviceNode描述。 - - 【可选】添加mipidsi\_config.hcs器件属性文件。 - -3. **实例化MIPIDSI控制器对象:** - - 初始化MipiDsiCntlr成员。 - - 实例化MipiDsiCntlr成员MipiDsiCntlrMethod。 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >实例化MipiDsiCntlr成员MipiDsiCntlrMethod,其定义和成员说明见[接口说明](#section752964871810)。 - - -4. **驱动调试:** - - 【可选】针对新增驱动程序,建议验证驱动基本功能,例如挂载后的信息反馈,数据传输的成功与否等。 - - -## 开发实例 - -下方将以mipi\_tx\_hi35xx.c为示例,展示需要厂商提供哪些内容来完整实现设备功能。 - -1. 一般来说,驱动开发首先需要在 xx\_config.hcs 中配置器件属性,并在device\_info.hcs文件中添加deviceNode描述。器件属性值与核心层MipiDsiCntlr 成员的默认值或限制范围有密切关系,deviceNode信息与驱动入口注册相关。 - - 但本例中MIPI控制器无需配置额外属性,如有厂商需要,则需要在device\_info文件的deviceNode增加deviceMatchAttr信息,以及增加mipidsi\_config文件。 - - device\_info.hcs 配置参考: - - ``` - root { - device_info { - match_attr = "hdf_manager"; - platform :: host { - hostName = "platform_host"; - priority = 50; - device_mipi_dsi:: device { - device0 :: deviceNode { - policy = 0; - priority = 150; - permission = 0644; - moduleName = "HDF_MIPI_TX"; //【必要】用于指定驱动名称,需要与期望的驱动Entry中的moduleName一致; - serviceName = "HDF_MIPI_TX"; // 【必要且唯一】驱动对外发布服务的名称 - } - } - } - } - } - ``` - -2. 完成器件属性文件的配置之后,下一步请实例化驱动入口,驱动入口必须为HdfDriverEntry(在 hdf\_device\_desc.h 中定义)类型的全局变量,且moduleName要和device\_info.hcs中保持一致。HdfDriverEntry结构体的函数指针成员会被厂商操作函数填充,HDF框架会将所有加载的驱动的HdfDriverEntry对象首地址汇总,形成一个类似数组,方便调用。 - - 一般在加载驱动时HDF框架会先调用Bind函数,再调用Init函数加载该驱动。当Init调用异常时,HDF框架会调用Release释放驱动资源并退出。 - - - MIPI-DSI驱动入口参考。 - - ``` - struct HdfDriverEntry g_mipiTxDriverEntry = { - .moduleVersion = 1, - .Init = Hi35xxMipiTxInit, //见Init参考 - .Release = Hi35xxMipiTxRelease,//见Release参考 - .moduleName = "HDF_MIPI_TX", //【必要】需要与device_info.hcs 中保持一致。 - }; - HDF_INIT(g_mipiTxDriverEntry); //调用HDF_INIT将驱动入口注册到HDF框架中 - ``` - -3. 完成驱动入口注册之后,最后一步就是以核心层MipiDsiCntlr对象的初始化为核心,包括厂商自定义结构体(传递参数和数据),实例化MipiDsiCntlr成员MipiDsiCntlrMethod(让用户可以通过接口来调用驱动底层函数),实现HdfDriverEntry成员函数(Bind,Init,Release)。 - - 自定义结构体参考。 - - 从驱动的角度看,自定义结构体是参数和数据的载体,一般来说,config文件中的数值也会用来初始化结构体成员,但本例的mipidsi无器件属性文件,故基本成员结构与MipiDsiCntlr无太大差异。 - - ``` - typedef struct { - unsigned int devno; // 设备号 - short laneId[LANE_MAX_NUM]; // lane号 - OutPutModeTag outputMode; // 输出模式选择:刷新模式,命令行模式和视频流模式 - VideoModeTag videoMode; // 显示设备的同步模式 - OutputFormatTag outputFormat; // 输出DSI图像数据格式:RGB or YUV - SyncInfoTag syncInfo; // 时序相关的设置 - unsigned int phyDataRate; // mbps - unsigned int pixelClk; // KHz - } ComboDevCfgTag; - - // MipiDsiCntlr是核心层控制器结构体,其中的成员在Init函数中会被赋值 - struct MipiDsiCntlr { - struct IDeviceIoService service; - struct HdfDeviceObject *device; - unsigned int devNo; // 设备号 - struct MipiCfg cfg; - struct MipiDsiCntlrMethod *ops; - struct OsalMutex lock; - void *priv; - }; - ``` - - - MipiDsiCntlr成员回调函数结构体MipiDsiCntlrMethod的实例化,其他成员在Init函数中初始化。 - - ``` - static struct MipiDsiCntlrMethod g_method = { - .setCntlrCfg = Hi35xxSetCntlrCfg, - .setCmd = Hi35xxSetCmd, - .getCmd = Hi35xxGetCmd, - .toHs = Hi35xxToHs, - .toLp = Hi35xxToLp, - }; - ``` - - - Init函数参考 - - 入参: - - HdfDeviceObject 是整个驱动对外暴露的接口参数,具备 HCS 配置文件的信息。 - - 返回值: - - HDF\_STATUS相关状态 (下表为部分展示,如需使用其他状态,可见//drivers/framework/include/utils/hdf\_base.h中HDF\_STATUS 定义)。 - - - - - - - - - - - - - - - - - - - - - - - - - -

状态(值)

-

问题描述

-

HDF_ERR_INVALID_OBJECT

-

无效对象

-

HDF_ERR_MALLOC_FAIL

-

内存分配失败

-

HDF_ERR_INVALID_PARAM

-

无效参数

-

HDF_ERR_IO

-

I/O 错误

-

HDF_SUCCESS

-

执行成功

-

HDF_FAILURE

-

执行失败

-
- - 函数说明: - - MipiDsiCntlrMethod的实例化对象的挂载,调用MipiDsiRegisterCntlr,以及其他厂商自定义初始化操作。 - - ``` - static int32_t Hi35xxMipiTxInit(struct HdfDeviceObject *device) - { - int32_t ret; - g_mipiTx.priv = NULL; //g_mipiTx是定义的全局变量 - //static struct MipiDsiCntlr g_mipiTx { - // .devNo=0 - //}; - g_mipiTx.ops = &g_method;//MipiDsiCntlrMethod的实例化对象的挂载 - ret = MipiDsiRegisterCntlr(&g_mipiTx, device);//【必要】调用核心层函数和g_mipiTx初始化核心层全局变量 - ... - return MipiTxDrvInit(0); //【必要】厂商对设备的初始化,形式不限 - } - - //mipi_dsi_core.c核心层 - int32_t MipiDsiRegisterCntlr(struct MipiDsiCntlr *cntlr, struct HdfDeviceObject *device) - { - ... - //定义的全局变量:static struct MipiDsiHandle g_mipiDsihandle[MAX_CNTLR_CNT]; - if (g_mipiDsihandle[cntlr->devNo].cntlr == NULL) { - (void)OsalMutexInit(&g_mipiDsihandle[cntlr->devNo].lock); - (void)OsalMutexInit(&(cntlr->lock)); - - g_mipiDsihandle[cntlr->devNo].cntlr = cntlr;//初始化MipiDsiHandle成员 - g_mipiDsihandle[cntlr->devNo].priv = NULL; - cntlr->device = device; //使HdfDeviceObject与MipiDsiHandle可以相互转化的前提 - device->service = &(cntlr->service); //使HdfDeviceObject与MipiDsiHandle可以相互转化的前提 - cntlr->priv = NULL; - ... - return HDF_SUCCESS; - } - ... - return HDF_FAILURE; - } - ``` - - - Release函数参考 - - 入参: - - HdfDeviceObject 是整个驱动对外暴露的接口参数,具备 HCS 配置文件的信息。 - - 返回值: - - 无。 - - 函数说明: - - 该函数需要在驱动入口结构体中赋值给 Release 接口, 当 HDF 框架调用 Init 函数初始化驱动失败时,可以调用 Release 释放驱动资源, 该函数中需包含释放内存和删除控制器等操作。所有强制转换获取相应对象的操作前提是在Init函数中具备对应赋值的操作。 - - ``` - static void Hi35xxMipiTxRelease(struct HdfDeviceObject *device) - { - struct MipiDsiCntlr *cntlr = NULL; - ... - cntlr = MipiDsiCntlrFromDevice(device);//这里有HdfDeviceObject到MipiDsiCntlr的强制转化 - //return (device == NULL) ? NULL : (struct MipiDsiCntlr *)device->service; - ... - MipiTxDrvExit(); //【必要】对厂商设备所占资源的释放 - MipiDsiUnregisterCntlr(&g_mipiTx); //空函数 - g_mipiTx.priv = NULL; - HDF_LOGI("%s: unload mipi_tx driver 1212!", __func__); - } - ``` - - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/08.MMC.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/08.MMC.md" deleted file mode 100644 index c0da3e2c44e9ca2fa5a83d975f51c2f4d91e5a93..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/08.MMC.md" +++ /dev/null @@ -1,565 +0,0 @@ ---- -title: MMC -permalink: /pages/0105020208 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# MMC - -- [概述](#section1846388309162704) -- [接口说明](#section752964871810) -- [开发步骤](#section1617495117162704) -- [开发实例](#section1220893490162704) - -## 概述 - -MMC(MultiMedia Card),即多媒体卡,在HDF框架中,MMC的接口适配模式采用独立服务模式,在这种模式下,每一个设备对象会独立发布一个设备服务来处理外部访问,设备管理器收到API的访问请求之后,通过提取该请求的参数,达到调用实际设备对象的相应内部方法的目的。独立服务模式可以直接借助HDFDeviceManager的服务管理能力,但需要为每个设备单独配置设备节点,增加内存占用。 - -**图 1** MMC独立服务模式结构图 -![](/images/device-dev/driver/figures/独立服务模式结构图.png "MMC独立服务模式结构图") - -## 接口说明 - -MmcCntlrOps定义: - -``` -struct MmcCntlrOps { - int32_t (*request)(struct MmcCntlr *cntlr, struct MmcCmd *cmd); - int32_t (*setClock)(struct MmcCntlr *cntlr, uint32_t clock); - int32_t (*setPowerMode)(struct MmcCntlr *cntlr, enum MmcPowerMode mode); - int32_t (*setBusWidth)(struct MmcCntlr *cntlr, enum MmcBusWidth width); - int32_t (*setBusTiming)(struct MmcCntlr *cntlr, enum MmcBusTiming timing); - int32_t (*setSdioIrq)(struct MmcCntlr *cntlr, bool enable); - int32_t (*hardwareReset)(struct MmcCntlr *cntlr); - int32_t (*systemInit)(struct MmcCntlr *cntlr); - int32_t (*setEnhanceSrobe)(struct MmcCntlr *cntlr, bool enable); - int32_t (*switchVoltage)(struct MmcCntlr *cntlr, enum MmcVolt volt); - bool (*devReadOnly)(struct MmcCntlr *cntlr); - bool (*devPluged)(struct MmcCntlr *cntlr); - bool (*devBusy)(struct MmcCntlr *cntlr); - int32_t (*tune)(struct MmcCntlr *cntlr, uint32_t cmdCode); - int32_t (*rescanSdioDev)(struct MmcCntlr *cntlr); -}; -``` - -**表 1** MmcCntlrOps结构体成员的回调函数功能说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

成员函数

-

入参

-

返回值

-

功能

-

doRequest

-

cntlr: 核心层结构体指针;mmc控制器 ;cmd: 结构体指针,传入命令值

-

HDF_STATUS相关状态

-

request相应处理

-

setClock

-

cntlr: 核心层结构体指针;mmc控制器 ;clock: 时钟传入值

-

HDF_STATUS相关状态

-

设置时钟频率

-

setPowerMode

-

cntlr: 核心层结构体指针;mmc控制器 ;mode: 枚举值(见MmcPowerMode定义),功耗模式

-

HDF_STATUS相关状态

-

设置功耗模式

-

setBusWidth

-

cntlr: 核心层结构体指针;mmc控制器 ;width: 枚举值(见MmcBusWidth定义),总线带宽

-

HDF_STATUS相关状态

-

设置总线带宽

-

setBusTiming

-

cntlr: 核心层结构体指针;mmc控制器 ;timing: 枚举值(见MmcBusTiming定义),总线时序

-

HDF_STATUS相关状态

-

设置总线时序

-

setSdioIrq

-

cntlr: 核心层结构体指针;mmc控制器 ;enable: 布尔值,控制中断

-

HDF_STATUS相关状态

-

使能/去使能SDIO中断

-

hardwareReset

-

cntlr: 核心层结构体指针;mmc控制器 ;

-

HDF_STATUS相关状态

-

复位硬件

-

systemInit

-

cntlr: 核心层结构体指针;mmc控制器 ;

-

HDF_STATUS相关状态

-

系统初始化

-

setEnhanceSrobe

-

cntlr: 核心层结构体指针,mmc控制器 ;enable: 布尔值,设置功能

-

HDF_STATUS相关状态

-

设置增强选通

-

switchVoltage

-

cntlr: 核心层结构体指针;mmc控制器 ;volt: 枚举值,电压值(3.3,1.8,1.2V);

-

HDF_STATUS相关状态

-

设置电压值

-

devReadOnly

-

cntlr: 核心层结构体指针;mmc控制器 ;

-

布尔值

-

检验设备是否只读

-

cardPluged

-

cntlr: 核心层结构体指针;mmc控制器 ;

-

布尔值

-

检验设备是否拔出

-

devBusy

-

cntlr: 核心层结构体指针;mmc控制器 ;

-

布尔值

-

检验设备是否忙碌

-

tune

-

cntlr: 核心层结构体指针;mmc控制器 ;cmdCode: uint32_t,命令代码;

-

HDF_STATUS相关状态

-

调谐

-

rescanSdioDev

-

cntlr: 核心层结构体指针;mmc控制器 ;

-

HDF_STATUS相关状态

-

扫描并添加SDIO设备

-
- -## 开发步骤 - -MMC模块适配的三个环节是配置属性文件,实例化驱动入口,以及实例化核心层接口函数。 - -1. **实例化驱动入口:** - - 实例化HdfDriverEntry结构体成员。 - - 调用HDF\_INIT将HdfDriverEntry实例化对象注册到HDF框架中。 - -2. **配置属性文件:** - - 在device\_info.hcs文件中添加deviceNode描述。 - - 【可选】添加mmc\_config.hcs器件属性文件。 - -3. **实例化MMC控制器对象:** - - 初始化MmcCntlr成员。 - - 实例化MmcCntlr成员MmcCntlrOps。 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >实例化MmcCntlr成员MmcCntlrOps,其定义和成员说明见[接口说明](#section752964871810)。 - - -4. **驱动调试:** - - 【可选】针对新增驱动程序,建议验证驱动基本功能,例如挂载后的信息反馈,设备启动是否成功等。 - - -## 开发实例 - -下方将以himci.c为示例,展示需要厂商提供哪些内容来完整实现设备功能。 - -1. 驱动开发首先需要实例化驱动入口,驱动入口必须为HdfDriverEntry(在 hdf\_device\_desc.h 中定义)类型的全局变量,且moduleName要和device\_info.hcs中保持一致。HDF框架会将所有加载的驱动的HdfDriverEntry对象首地址汇总,形成一个类似数组的段地址空间,方便上层调用。 - - 一般在加载驱动时HDF会先调用Bind函数,再调用Init函数加载该驱动。当Init调用异常时,HDF框架会调用Release释放驱动资源并退出。 - - MMC驱动入口参考: - - ``` - struct HdfDriverEntry g_mmcDriverEntry = { - .moduleVersion = 1, - .Bind = HimciMmcBind, //见Bind参考 - .Init = HimciMmcInit, //见Init参考 - .Release = HimciMmcRelease, //见Release参考 - .moduleName = "hi3516_mmc_driver",//【必要且与HCS文件中里面的moduleName匹配】 - }; - HDF_INIT(g_mmcDriverEntry); //调用HDF_INIT将驱动入口注册到HDF框架中 - ``` - -2. 完成驱动入口注册之后,下一步请在device\_info.hcs文件中添加deviceNode信息,并在mmc\_config.hcs中配置器件属性。deviceNode信息与驱动入口注册相关,器件属性值与核心层MmcCntlr成员的默认值或限制范围有密切关系。 - - 如有多个器件信息,则需要在device\_info文件增加deviceNode信息,以及在mmc\_config文件中增加对应的器件属性**。** - - - device\_info.hcs 配置参考。 - - ``` - root { - device_info { - match_attr = "hdf_manager"; - platform :: host { - hostName = "platform_host"; - priority = 50; - device_mmc:: device { - device0 :: deviceNode { - policy = 2; - priority = 10; - permission = 0644; - moduleName = "hi3516_mmc_driver"; //【必要】用于指定驱动名称,需要与驱动Entry中的moduleName一致; - serviceName = "HDF_PLATFORM_MMC_0"; //【必要】驱动对外发布服务的名称,必须唯一 - deviceMatchAttr = "hi3516_mmc_emmc";//【必要】用于配置控制器私有数据,要与 mmc_config.hcs 中对应控制器保持一致 - } - device1 :: deviceNode { - policy = 1; - priority = 20; - permission = 0644; - moduleName = "hi3516_mmc_driver"; - serviceName = "HDF_PLATFORM_MMC_1"; - deviceMatchAttr = "hi3516_mmc_sd"; //SD类型 - } - device2 :: deviceNode { - policy = 1; - priority = 30; - permission = 0644; - moduleName = "hi3516_mmc_driver"; - serviceName = "HDF_PLATFORM_MMC_2"; - deviceMatchAttr = "hi3516_mmc_sdio";//SDIO类型 - } - } - } - } - } - ``` - - - mmc\_config.hcs 配置参考。 - - ``` - root { - platform { - mmc_config { - template mmc_controller {//模板公共参数,继承该模板的节点如果使用模板中的默认值,则节点字段可以缺省 - match_attr = ""; - voltDef = 0; // 3.3V - freqMin = 50000; //【必要】最小频率值 - freqMax = 100000000; //【必要】最大频率值 - freqDef = 400000; //【必要】默认频率值 - maxBlkNum = 2048; //【必要】最大的block号 - maxBlkSize = 512; //【必要】最大的block个数 - ocrDef = 0x300000; //【必要】工作电压设置相关 - caps2 = 0; //【必要】属性寄存器相关,见mmc_caps.h 中 MmcCaps2 定义 - regSize = 0x118; //【必要】寄存器位宽 - hostId = 0; //【必要】主机号 - regBasePhy = 0x10020000;//【必要】寄存器物理基地址 - irqNum = 63; //【必要】中断号 - devType = 2; //【必要】模式选择:emmc, SD, SDIO ,COMBO - caps = 0x0001e045; //【必要】属性寄存器相关,见mmc_caps.h 中 MmcCaps 定义 - } - controller_0x10100000 :: mmc_controller { - match_attr = "hi3516_mmc_emmc";//【必要】需要和device_info.hcs中的deviceMatchAttr值一致 - hostId = 0; - regBasePhy = 0x10100000; - irqNum = 96; - devType = 0; // emmc类型 - caps = 0xd001e045; - caps2 = 0x60; - } - controller_0x100f0000 :: mmc_controller { - match_attr = "hi3516_mmc_sd"; - hostId = 1; - regBasePhy = 0x100f0000; - irqNum = 62; - devType = 1; // sd类型 - caps = 0xd001e005; - } - controller_0x10020000 :: mmc_controller { - match_attr = "hi3516_mmc_sdio"; - hostId = 2; - regBasePhy = 0x10020000; - irqNum = 63; - devType = 2; // sdio类型 - caps = 0x0001e04d; - } - } - } - } - ``` - -3. 完成驱动入口注册之后,最后一步就是以核心层MmcCntlr对象的初始化为核心,包括厂商自定义结构体(传递参数和数据),实例化MmcCntlr成员MmcCntlrOps(让用户可以通过接口来调用驱动底层函数),实现HdfDriverEntry成员函数(Bind,Init,Release)。 - - 自定义结构体参考。 - - 从驱动的角度看,自定义结构体是参数和数据的载体,而且mmc\_config.hcs文件中的数值会被HDF读入通过DeviceResourceIface来初始化结构体成员 ,一些重要数值也会传递给核心层对象。 - - ``` - struct HimciHost { - struct MmcCntlr *mmc;//【必要】核心层结构体 - struct MmcCmd *cmd; //【必要】核心层结构体,传递命令的,相关命令见枚举量 MmcCmdCode - //【可选】根据厂商驱动需要添加 - void *base; - enum HimciPowerStatus powerStatus; - uint8_t *alignedBuff; - uint32_t buffLen; - struct scatterlist dmaSg; - struct scatterlist *sg; - uint32_t dmaSgNum; - DMA_ADDR_T dmaPaddr; - uint32_t *dmaVaddr; - uint32_t irqNum; - bool isTuning; - uint32_t id; - struct OsalMutex mutex; - bool waitForEvent; - HIMCI_EVENT himciEvent; - }; - //MmcCntlr是核心层控制器结构体,其中的成员在bind函数中会被赋值 - struct MmcCntlr { - struct IDeviceIoService service; - struct HdfDeviceObject *hdfDevObj; - struct PlatformDevice device; - struct OsalMutex mutex; - struct OsalSem released; - uint32_t devType; - struct MmcDevice *curDev; - struct MmcCntlrOps *ops; - struct PlatformQueue *msgQueue; - uint16_t index; - uint16_t voltDef; - uint32_t vddBit; - uint32_t freqMin; - uint32_t freqMax; - uint32_t freqDef; - union MmcOcr ocrDef; - union MmcCaps caps; - union MmcCaps2 caps2; - uint32_t maxBlkNum; - uint32_t maxBlkSize; - uint32_t maxReqSize; - bool devPluged; - bool detecting; - void *priv; - }; - ``` - - - MmcCntlr成员回调函数结构体MmcCntlrOps的实例化,其他成员在Bind函数中初始化。 - - ``` - static struct MmcCntlrOps g_himciHostOps = { - .request = HimciDoRequest, - .setClock = HimciSetClock, - .setPowerMode = HimciSetPowerMode, - .setBusWidth = HimciSetBusWidth, - .setBusTiming = HimciSetBusTiming, - .setSdioIrq = HimciSetSdioIrq, - .hardwareReset = HimciHardwareReset, - .systemInit = HimciSystemInit, - .setEnhanceSrobe= HimciSetEnhanceSrobe, - .switchVoltage = HimciSwitchVoltage, - .devReadOnly = HimciDevReadOnly, - .devPluged = HimciCardPluged, - .devBusy = HimciDevBusy, - .tune = HimciTune, - .rescanSdioDev = HimciRescanSdioDev, - }; - ``` - - - Bind函数参考 - - 入参**:** - - HdfDeviceObject 是整个驱动对外暴露的接口参数,具备 HCS 配置文件的信息。 - - 返回值: - - HDF\_STATUS相关状态 (下表为部分展示,如需使用其他状态,可见//drivers/framework/include/utils/hdf\_base.h中HDF\_STATUS 定义)。 - - - - - - - - - - - - - - - - - - - - - - - - - -

状态(值)

-

问题描述

-

HDF_ERR_INVALID_OBJECT

-

控制器对象非法

-

HDF_ERR_MALLOC_FAIL

-

内存分配失败

-

HDF_ERR_INVALID_PARAM

-

参数非法

-

HDF_ERR_IO

-

I/O 错误

-

HDF_SUCCESS

-

初始化成功

-

HDF_FAILURE

-

初始化失败

-
- - 函数说明: - - MmcCntlr,HimciHost,HdfDeviceObject之间互相赋值,方便其他函数可以相互转化,初始化自定义结构体HimciHost对象,初始化MmcCntlr成员,调用核心层MmcCntlrAdd函数。 - - ``` - static int32_t HimciMmcBind(struct HdfDeviceObject *obj) - { - struct MmcCntlr *cntlr = NULL; - struct HimciHost *host = NULL; - int32_t ret; - cntlr = (struct MmcCntlr *)OsalMemCalloc(sizeof(struct MmcCntlr)); - host = (struct HimciHost *)OsalMemCalloc(sizeof(struct HimciHost)); - - host->mmc = cntlr; //【必要】使HimciHost与MmcCntlr可以相互转化的前提 - cntlr->priv = (void *)host; //【必要】使HimciHost与MmcCntlr可以相互转化的前提 - cntlr->ops = &g_himciHostOps; //【必要】MmcCntlrOps的实例化对象的挂载 - cntlr->hdfDevObj = obj; //【必要】使HdfDeviceObject与MmcCntlr可以相互转化的前提 - obj->service = &cntlr->service; //【必要】使HdfDeviceObject与MmcCntlr可以相互转化的前提 - ret = MmcCntlrParse(cntlr, obj); //【必要】 初始化 cntlr. 失败就 goto _ERR; - ... - ret = HimciHostParse(host, obj); //【必要】 初始化 host对象的相关属性,失败就 goto _ERR; - ... - ret = HimciHostInit(host, cntlr);//厂商自定义的初始化,失败就 goto _ERR; - ... - ret = MmcCntlrAdd(cntlr); //调用核心层函数 失败就 goto _ERR; - ... - (void)MmcCntlrAddDetectMsgToQueue(cntlr);//将卡检测消息添加到队列中。 - HDF_LOGD("HimciMmcBind: success."); - return HDF_SUCCESS; - _ERR: - HimciDeleteHost(host); - HDF_LOGD("HimciMmcBind: fail, err = %d.", ret); - return ret; - } - ``` - - - Init函数参考 - - 入参: - - HdfDeviceObject是整个驱动对外暴露的接口参数,具备HCS配置文件的信息。 - - 返回值: - - HDF\_STATUS相关状态。 - - 函数说明: - - 实现ProcMciInit。 - - ``` - static int32_t HimciMmcInit(struct HdfDeviceObject *obj) - { - static bool procInit = false; - (void)obj; - if (procInit == false) { - if (ProcMciInit() == HDF_SUCCESS) { - procInit = true; - HDF_LOGD("HimciMmcInit: proc init success."); - } - } - HDF_LOGD("HimciMmcInit: success."); - return HDF_SUCCESS; - } - ``` - - - Release函数参考 - - 入参: - - HdfDeviceObject 是整个驱动对外暴露的接口参数,具备 HCS 配置文件的信息。 - - 返回值: - - 无。 - - 函数说明: - - 释放内存和删除控制器等操作,该函数需要在驱动入口结构体中赋值给Release接口,当HDF框架调用Init函数初始化驱动失败时,可以调用 Release释放驱动资源。所有强制转换获取相应对象的操作**前提**是在Init函数中具备对应赋值的操作。 - - ``` - static void HimciMmcRelease(struct HdfDeviceObject *obj) - { - struct MmcCntlr *cntlr = NULL; - ... - cntlr = (struct MmcCntlr *)obj->service;//这里有HdfDeviceObject到MmcCntlr的强制转化,通过service成员,赋值见Bind函数 - ... - HimciDeleteHost((struct HimciHost *)cntlr->priv);//厂商自定义的内存释放函数,这里有MmcCntlr到HimciHost的强制转化 - } - ``` - - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/09.PWM.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/09.PWM.md" deleted file mode 100644 index 5043b0557c1133d187cd1fa7e1522b8aeb30e141..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/09.PWM.md" +++ /dev/null @@ -1,364 +0,0 @@ ---- -title: PWM -permalink: /pages/0105020209 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# PWM - -- [概述](#section1591602238164144) -- [接口说明](#section752964871810) -- [开发步骤](#section967396342164144) -- [开发实例](#section1883877829164144) - -## 概述 - -PWM(Pulse Width Modulator)即脉冲宽度调节器,在HDF框架中,PWM的接口适配模式采用独立服务模式,在这种模式下,每一个设备对象会独立发布一个设备服务来处理外部访问,设备管理器收到API的访问请求之后,通过提取该请求的参数,达到调用实际设备对象的相应内部方法的目的。独立服务模式可以直接借助HDFDeviceManager的服务管理能力,但需要为每个设备单独配置设备节点,增加内存占用。 - -**图 1** PWM独立服务模式结构图 -![](/images/device-dev/driver/figures/独立服务模式结构图.png "PWM独立服务模式结构图") - -## 接口说明 - -PwmMethod定义: - -``` -struct PwmMethod { - int32_t (*setConfig)(struct PwmDev *pwm, struct PwmConfig *config); - int32_t (*open)(struct PwmDev *pwm); - int32_t (*close)(struct PwmDev *pwm); -}; -``` - -**表 1** PwmMethod结构体成员的回调函数功能说明 - - - - - - - - - - - - - - - - - - - - - - - - -

成员函数

-

入参

-

返回值

-

功能

-

setConfig

-

pwm: 结构体指针,核心层PWM控制器;

-

config: 结构体指针,属性传入值;

-

HDF_STATUS相关状态

-

配置属性

-

open

-

pwm: 结构体指针,核心层PWM控制器;

-

HDF_STATUS相关状态

-

打开设备

-

close

-

pwm: 结构体指针,核心层PWM控制器;

-

HDF_STATUS相关状态

-

关闭设备

-
- -## 开发步骤 - -PWM模块适配HDF框架的三个环节是配置属性文件,实例化驱动入口,以及填充核心层接口函数。 - -1. **实例化驱动入口:** - - 实例化HdfDriverEntry结构体成员。 - - 调用HDF\_INIT将HdfDriverEntry实例化对象注册到HDF框架中。 - -2. **配置属性文件:** - - 在device\_info.hcs文件中添加deviceNode描述。 - - 【可选】添加pwm\_config.hcs器件属性文件。 - -3. **实例化PWM控制器对象:** - - 初始化PwmDev成员。 - - 实例化PwmDev成员PwmMethod。 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >实例化PwmDev成员PwmMethod,其定义和成员说明见[接口说明](#section752964871810)。 - - -4. **驱动调试:** - - 【可选】针对新增驱动程序,建议验证驱动基本功能,例如PWM控制状态,中断响应情况等。 - - -## 开发实例 - -下方将以pwm\_hi35xx.c为示例,展示需要厂商提供哪些内容来完整实现设备功能。 - -1. 驱动开发首先需要实例化驱动入口,驱动入口必须为HdfDriverEntry(在 hdf\_device\_desc.h 中定义)类型的全局变量,且moduleName要和device\_info.hcs中保持一致。HDF框架会将所有加载的驱动的HdfDriverEntry对象首地址汇总,形成一个类似数组的段地址空间,方便上层调用。 - - 一般在加载驱动时HDF会先调用Bind函数,再调用Init函数加载该驱动。当Init调用异常时,HDF框架会调用Release释放驱动资源并退出。 - - PWM驱动入口参考 - - ``` - struct HdfDriverEntry g_hdfPwm = { - .moduleVersion = 1, - .moduleName = "HDF_PLATFORM_PWM",//【必要 且与 HCS文件中里面的moduleName匹配】 - .Bind = HdfPwmBind, - .Init = HdfPwmInit, - .Release = HdfPwmRelease, - }; - //调用HDF_INIT将驱动入口注册到HDF框架中 - HDF_INIT(g_hdfPwm); - ``` - -2. 完成驱动入口注册之后,下一步请在device\_info.hcs文件中添加deviceNode信息,并在 pwm\_config.hcs 中配置器件属性。deviceNode信息与驱动入口注册相关,器件属性值与核心层PwmDev成员的默认值或限制范围有密切关系。 如有更多个器件信息,则需要在device\_info文件增加deviceNode信息,以及在pwm\_config文件中增加对应的器件属性**。** - - device\_info.hcs 配置参考。 - - ``` - root { - device_info { - platform :: host { - hostName = "platform_host"; - priority = 50; - device_pwm :: device {//为每一个 pwm 控制器配置一个HDF设备节点,存在多个时【必须】添加,否则不用 - device0 :: deviceNode { - policy = 1; // 等于1,向内核态发布服务 - priority = 80; // 驱动启动优先级 - permission = 0644;// 驱动创建设备节点权限 - moduleName = "HDF_PLATFORM_PWM"; //【必要】用于指定驱动名称,需要与期望的驱动Entry中的moduleName一致; - serviceName = "HDF_PLATFORM_PWM_0";//【必要且唯一】驱动对外发布服务的名称 - deviceMatchAttr = "hisilicon_hi35xx_pwm_0";//【必要】用于配置控制器私有数据,要与 pwm_config.hcs 中对应 - // 控制器保持一致,具体的控制器信息在 pwm_config.hcs 中 - } - device1 :: deviceNode { - policy = 1; - priority = 80; - permission = 0644; - moduleName = "HDF_PLATFORM_PWM"; - serviceName = "HDF_PLATFORM_PWM_1"; - deviceMatchAttr = "hisilicon_hi35xx_pwm_1"; - } - } - } - } - } - ``` - - - pwm\_config.hcs 配置参考。 - - ``` - root { - platform { - pwm_config { - template pwm_device { //【必要】模板配置,继承该模板的节点如果使用模板中的默认值,则节点字段可以缺省 - serviceName = ""; - match_attr = ""; - num = 0; //【必要】设备号 - base = 0x12070000; //【必要】地址映射需要 - } - device_0x12070000 :: pwm_device { - match_attr = "hisilicon_hi35xx_pwm_0";//【必要】需要和device_info.hcs中的deviceMatchAttr值一致 - } - device_0x12070020 :: pwm_device { //存在多个设备时【必须】添加,否则不用 - match_attr = "hisilicon_hi35xx_pwm_1"; - num = 1; - base = 0x12070020; //【必要】地址映射需要 - } - } - } - } - ``` - -3. 完成驱动入口注册之后,最后一步就是以核心层PwmDev对象的初始化为核心,包括厂商自定义结构体(传递参数和数据),实例化PwmDev成员PwmMethod(让用户可以通过接口来调用驱动底层函数),实现HdfDriverEntry成员函数(Bind,Init,Release)。 - - 自定义结构体参考。 - - 从驱动的角度看,自定义结构体是参数和数据的载体,而且pwm\_config.hcs文件中的数值会被HDF读入通过DeviceResourceIface来初始化结构体成员,一些重要数值也会传递给核心层对象,例如设备号等。 - - ``` - struct HiPwm { - struct PwmDev dev; //【必要】 核心层结构体 - volatile unsigned char *base; - struct HiPwmRegs *reg; // 设备属性结构体,可自定义 - bool supportPolarity; - }; - - // PwmDev是核心层控制器结构体,其中的成员在Init函数中会被赋值 - struct PwmDev { - struct IDeviceIoService service; - struct HdfDeviceObject *device; - struct PwmConfig cfg; //属性结构体,相关定义见下 - struct PwmMethod *method; //钩子函数模板 - bool busy; - uint32_t num; //设备号 - OsalSpinlock lock; - void *priv; //私有数据,一般存储自定义结构体首地址,方便调用 - }; - struct PwmConfig { - uint32_t duty; // 占空时间 nanoseconds - uint32_t period; // pwm 周期 nanoseconds - uint32_t number; // pwm 连续个数 - uint8_t polarity; // Polarity - // ------------------- | -------------- - // PWM_NORMAL_POLARITY | Normal polarity - // PWM_INVERTED_POLARITY | Inverted polarity - // - uint8_t status; // 运行状态 - // ------------------ | ----------------- - // PWM_DISABLE_STATUS | Disabled - // PWM_ENABLE_STATUS | Enabled - }; - ``` - - - PwmDev成员回调函数结构体PwmMethod的实例化,其他成员在Init函数中初始化。 - - ``` - // pwm_hi35xx.c 中的示例:钩子函数的填充 - struct PwmMethod g_pwmOps = { - .setConfig = HiPwmSetConfig,//配置属性 - }; - ``` - - - Init函数参考 - - 入参: - - HdfDeviceObject 是整个驱动对外暴露的接口参数,具备 HCS 配置文件的信息。 - - 返回值: - - HDF\_STATUS相关状态 (下表为部分展示,如需使用其他状态,可见//drivers/framework/include/utils/hdf\_base.h中HDF\_STATUS 定义)。 - - - - - - - - - - - - - - - - - - - - - - - - - -

状态(值)

-

问题描述

-

HDF_ERR_INVALID_OBJECT

-

控制器对象非法

-

HDF_ERR_MALLOC_FAIL

-

内存分配失败

-

HDF_ERR_INVALID_PARAM

-

参数非法

-

HDF_ERR_IO

-

I/O 错误

-

HDF_SUCCESS

-

初始化成功

-

HDF_FAILURE

-

初始化失败

-
- - 函数说明: - - 初始化自定义结构体对象,初始化PwmDev成员,调用核心层PwmDeviceAdd函数。 - - ``` - //此处bind函数为空函数,可与init函数结合,也可根据厂商需要实现相关操作 - static int32_t HdfPwmBind(struct HdfDeviceObject *obj) - { - (void)obj; - return HDF_SUCCESS; - } - - static int32_t HdfPwmInit(struct HdfDeviceObject *obj) - { - int ret; - struct HiPwm *hp = NULL; - ... - hp = (struct HiPwm *)OsalMemCalloc(sizeof(*hp)); - ... - ret = HiPwmProbe(hp, obj); //【必要】实现见下 - ... - return ret; - } - - static int32_t HiPwmProbe(struct HiPwm *hp, struct HdfDeviceObject *obj) - { - uint32_t tmp; - struct DeviceResourceIface *iface = NULL; - - iface = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);//初始化自定义结构体HiPwm - ... - - hp->reg = (struct HiPwmRegs *)hp->base; //初始化自定义结构体HiPwm - hp->supportPolarity = false; //初始化自定义结构体HiPwm - hp->dev.method = &g_pwmOps; //PwmMethod的实例化对象的挂载 - hp->dev.cfg.duty = PWM_DEFAULT_DUTY_CYCLE; //初始化PwmDev - hp->dev.cfg.period = PWM_DEFAULT_PERIOD; //初始化PwmDev - hp->dev.cfg.polarity = PWM_DEFAULT_POLARITY; //初始化PwmDev - hp->dev.cfg.status = PWM_DISABLE_STATUS; //初始化PwmDev - hp->dev.cfg.number = 0; //初始化PwmDev - hp->dev.busy = false; //初始化PwmDev - if (PwmDeviceAdd(obj, &(hp->dev)) != HDF_SUCCESS) {//【重要】调用核心层函数,初始化hp->dev 的设备和服务 - OsalIoUnmap((void *)hp->base); - return HDF_FAILURE; - } - return HDF_SUCCESS; - } - ``` - - - Release 函数参考 - - 入参: - - HdfDeviceObject 是整个驱动对外暴露的接口参数,具备 HCS 配置文件的信息。 - - 返回值: - - 无。 - - 函数说明: - - 释放内存和删除控制器,该函数需要在驱动入口结构体中赋值给 Release 接口, 当HDF框架调用Init函数初始化驱动失败时,可以调用 Release 释放驱动资源。 - - ``` - static void HdfPwmRelease(struct HdfDeviceObject *obj) - { - struct HiPwm *hp = NULL; - ... - hp = (struct HiPwm *)obj->service;//这里有HdfDeviceObject到HiPwm的强制转化 - ... - PwmDeviceRemove(obj, &(hp->dev));//【必要】调用核心层函数,释放PwmDev的设备和服务,这里有HiPwm到PwmDev的强制转化 - HiPwmRemove(hp); //释放HiPwm - } - ``` - - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/10.RTC.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/10.RTC.md" deleted file mode 100644 index da19c07b916aa3f715462a25ef9349aba7160b13..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/10.RTC.md" +++ /dev/null @@ -1,474 +0,0 @@ ---- -title: RTC -permalink: /pages/010502020a -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:23 ---- -# RTC - -- [概述](#section509989381142407) -- [接口说明](#section752964871810) -- [开发步骤](#section1784450860142407) -- [开发实例](#section1594883301142407) - -## 概述 - -RTC\(real-time clock\)为操作系统中的实时时钟设备,在HDF框架中,RTC的接口适配模式采用独立服务模式,在这种模式下,每一个设备对象会独立发布一个设备服务来处理外部访问,设备管理器收到API的访问请求之后,通过提取该请求的参数,达到调用实际设备对象的相应内部方法的目的。独立服务模式可以直接借助HDFDeviceManager的服务管理能力,但需要为每个设备单独配置设备节点,增加内存占用。 - -**图 1** RTC独立服务模式结构图 -![](/images/device-dev/driver/figures/独立服务模式结构图.png "RTC独立服务模式结构图") - -## 接口说明 - -RtcMethod定义: - -``` -struct RtcMethod { - int32_t (*ReadTime)(struct RtcHost *host, struct RtcTime *time); - int32_t (*WriteTime)(struct RtcHost *host, const struct RtcTime *time); - int32_t (*ReadAlarm)(struct RtcHost *host, enum RtcAlarmIndex alarmIndex, struct RtcTime *time); - int32_t (*WriteAlarm)(struct RtcHost *host, enum RtcAlarmIndex alarmIndex, const struct RtcTime *time); - int32_t (*RegisterAlarmCallback)(struct RtcHost *host, enum RtcAlarmIndex alarmIndex, RtcAlarmCallback cb); - int32_t (*AlarmInterruptEnable)(struct RtcHost *host, enum RtcAlarmIndex alarmIndex, uint8_t enable); - int32_t (*GetFreq)(struct RtcHost *host, uint32_t *freq); - int32_t (*SetFreq)(struct RtcHost *host, uint32_t freq); - int32_t (*Reset)(struct RtcHost *host); - int32_t (*ReadReg)(struct RtcHost *host, uint8_t usrDefIndex, uint8_t *value); - int32_t (*WriteReg)(struct RtcHost *host, uint8_t usrDefIndex, uint8_t value); -}; -``` - -**表 1** RtcMethod结构体成员的回调函数功能说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

函数

-

入参

-

出参

-

返回值

-

功能

-

ReadTime

-

host: 结构体指针,核心层RTC控制器 ;

-

time: 结构体指针,传出的时间值;

-

HDF_STATUS相关状态

-

读RTC时间信息

-

WriteTime

-

host: 结构体指针,核心层RTC控制器 ;time: 结构体指针,时间传入值;

-

-

HDF_STATUS相关状态

-

写RTC时间信息(包括毫秒~年)

-

ReadAlarm

-

host: 结构体指针,核心层RTC控制器 ;alarmIndex: 枚举值,闹钟报警索引 ;

-

time: 结构体指针,传出的时间值;

-

HDF_STATUS相关状态

-

读RTC报警时间信息

-

WriteAlarm

-

host: 结构体指针,核心层RTC控制器 ;alarmIndex: 枚举值,闹钟报警索引 ;time: 结构体指针,时间传入值;

-

-

HDF_STATUS相关状态

-

写RTC报警时间信息

-

RegisterAlarmCallback

-

host: 结构体指针,核心层RTC控制器 ;alarmIndex: 枚举值,闹钟报警索引 ;cb:函数指针,回调函数;

-

-

HDF_STATUS相关状态

-

注册报警超时回调函数

-

AlarmInterruptEnable

-

host: 结构体指针,核心层RTC控制器 ;alarmIndex: 枚举值,闹钟报警索引 ;enable: 布尔值,控制报警;

-

-

HDF_STATUS相关状态

-

使能/去使能RTC报警中断

-

GetFreq

-

host: 结构体指针,核心层RTC控制器 ;

-

freq: uint32_t指针,传出的频率值;

-

HDF_STATUS相关状态

-

读RTC外接晶振频率

-

SetFreq

-

host: 结构体指针,核心层RTC控制器 ;freq: uint32_t,频率传入值;

-

-

HDF_STATUS相关状态

-

配置RTC外接晶振频率

-

Reset

-

host: 结构体指针,核心层RTC控制器 ;

-

-

HDF_STATUS相关状态

-

RTC复位

-

ReadReg

-

host: 结构体指针,核心层RTC控制器 ;usrDefIndex: 结构体,用户自定义寄存器索引;

-

value: uint8_t指针,传出的寄存器值;

-

HDF_STATUS相关状态

-

按照用户定义的寄存器索引,读取对应的寄存器配置,一个索引对应一字节的配置值

-

WriteReg

-

host: 结构体指针,核心层RTC控制器 ;usrDefIndex: 结构体,用户自定义寄存器索引;value: uint8_t,寄存器传入值;

-

-

HDF_STATUS相关状态

-

按照用户定义的寄存器索引,设置对应的寄存器配置,一个索引对应一字节的配置值

-
- -## 开发步骤 - -RTC模块适配HDF框架的三个环节是配置属性文件,实例化驱动入口,以及填充核心层接口函数。 - -1. **实例化驱动入口:** - - 实例化HdfDriverEntry结构体成员。 - - 调用HDF\_INIT将HdfDriverEntry实例化对象注册到HDF框架中。 - -2. **配置属性文件:** - - 在device\_info.hcs文件中添加deviceNode描述。 - - 【可选】添加rtc\_config.hcs器件属性文件。 - -3. **实例化RTC控制器对象:** - - 初始化RtcHost成员。 - - 实例化RtcHost成员RtcMethod。 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >实例化RtcHost成员RtcMethod,其定义和成员说明见[接口说明](#section752964871810)。 - - -4. **驱动调试:** - - 【可选】针对新增驱动程序,建议验证驱动基本功能,例如RTC控制状态,中断响应情况等。 - - -## 开发实例 - -下方将以rtc\_hi35xx.c为示例,展示需要厂商提供哪些内容来完整实现设备功能。 - -1. 驱动开发首先需要实例化驱动入口,驱动入口必须为HdfDriverEntry(在 hdf\_device\_desc.h 中定义)类型的全局变量,且moduleName要和device\_info.hcs中保持一致。HDF框架会将所有加载的驱动的HdfDriverEntry对象首地址汇总,形成一个类似数组的段地址空间,方便上层调用。 - - 一般在加载驱动时HDF会先调用Bind函数,再调用Init函数加载该驱动。当Init调用异常时,HDF框架会调用Release释放驱动资源并退出。 - - RTC驱动入口参考: - - ``` - struct HdfDriverEntry g_rtcDriverEntry = { - .moduleVersion = 1, - .Bind = HiRtcBind, //见Bind参考 - .Init = HiRtcInit, //见Init参考 - .Release = HiRtcRelease, //见Release参考 - .moduleName = "HDF_PLATFORM_RTC",//【必要】且与 HCS 里面的名字匹配 - }; - //调用HDF_INIT将驱动入口注册到HDF框架中 - HDF_INIT(g_rtcDriverEntry); - ``` - -2. 完成驱动入口注册之后,下一步请在device\_info.hcs文件中添加deviceNode信息,并在 rtc\_config.hcs 中配置器件属性。deviceNode信息与驱动入口注册相关,器件属性值与核心层RtcHost成员的默认值或限制范围有密切关系。 - - 本例只有一个RTC控制器,如有多个器件信息,则需要在device\_info文件增加deviceNode信息,以及在rtc\_config文件中增加对应的器件属性。 - - - device\_info.hcs 配置参考。 - - ``` - root { - device_info { - platform :: host { - device_rtc :: device { - device0 :: deviceNode { - policy = 1; //2:用户态可见,1:内核态可见,0:不需要发布服务 - priority = 30; //优先级越大,值越小 - permission = 0644; //驱动创建设备节点权限 - moduleName = "HDF_PLATFORM_RTC"; //【必要】用于指定驱动名称,需要与驱动Entry中的moduleName一致 - serviceName = "HDF_PLATFORM_RTC"; //【必要】驱动对外发布服务的名称,必须唯一 - deviceMatchAttr = "hisilicon_hi35xx_rtc";//【必要】需要与设备hcs文件中的 match_attr 匹配 - } - } - } - } - } - ``` - - - rtc\_config.hcs 配置参考。 - - ``` - root { - platform { - rtc_config { - controller_0x12080000 { - match_attr = "hisilicon_hi35xx_rtc";//【必要】需要和device_info.hcs中的deviceMatchAttr值一致 - rtcSpiBaseAddr = 0x12080000; //地址映射相关 - regAddrLength = 0x100; //地址映射相关 - irq = 37; //中断号 - supportAnaCtrl = false; - supportLock = false; - anaCtrlAddr = 0xff; - lock0Addr = 0xff; - lock1Addr = 0xff; - lock2Addr = 0xff; - lock3Addr = 0xff; - } - } - } - } - ``` - -3. 完成驱动入口注册之后,最后一步就是以核心层RtcHost对象的初始化为核心,包括厂商自定义结构体(传递参数和数据),实例化RtcHost成员RtcMethod(让用户可以通过接口来调用驱动底层函数),实现HdfDriverEntry成员函数(Bind,Init,Release)。 - - 自定义结构体参考。 - - 从驱动的角度看,自定义结构体是参数和数据的载体,而且rtc\_config.hcs文件中的数值会被HDF读入通过DeviceResourceIface来初始化结构体成员。 - - ``` - struct RtcConfigInfo { - uint32_t spiBaseAddr; //地址映射相关 - volatile void *remapBaseAddr; //地址映射相关 - uint16_t regAddrLength; //地址映射相关 - uint8_t supportAnaCtrl; //是否支持anactrl - uint8_t supportLock; //是否支持锁 - uint8_t irq; //中断号 - uint8_t alarmIndex; //闹钟索引 - uint8_t anaCtrlAddr; //anactrl地址 - struct RtcLockAddr lockAddr; //锁地址 - RtcAlarmCallback cb; //回调函数 - struct OsalMutex mutex; //互斥锁 - }; - - // RtcHost是核心层控制器结构体,其中的成员在Init函数中会被赋值 - struct RtcHost { - struct IDeviceIoService service; - struct HdfDeviceObject *device; - struct RtcMethod *method; - void *data; - }; - ``` - - - RtcHost成员回调函数结构体RtcMethod的实例化,其他成员在Init函数中初始化。 - - ``` - // rtc_hi35xx.c 中的示例:钩子函数的填充 - static struct RtcMethod g_method = { - .ReadTime = HiRtcReadTime, - .WriteTime = HiRtcWriteTime, - .ReadAlarm = HiReadAlarm, - .WriteAlarm = HiWriteAlarm, - .RegisterAlarmCallback = HiRegisterAlarmCallback, - .AlarmInterruptEnable = HiAlarmInterruptEnable, - .GetFreq = HiGetFreq, - .SetFreq = HiSetFreq, - .Reset = HiReset, - .ReadReg = HiReadReg, - .WriteReg = HiWriteReg, - }; - ``` - - - Bind 函数参考 - - 入参: - - HdfDeviceObject 是整个驱动对外暴露的接口参数,具备 HCS 配置文件的信息。 - - 返回值: - - HDF\_STATUS相关状态 (下表为部分展示,如需使用其他状态,可见//drivers/framework/include/utils/hdf\_base.h中HDF\_STATUS 定义)。 - - **表 2** Bind 函数入参及返回值对照表 - - - - - - - - - - - - - - - - - - - - - - - - - -

状态(值)

-

问题描述

-

HDF_ERR_INVALID_OBJECT

-

控制器对象非法

-

HDF_ERR_MALLOC_FAIL

-

内存分配失败

-

HDF_ERR_INVALID_PARAM

-

参数非法

-

HDF_ERR_IO

-

I/O 错误

-

HDF_SUCCESS

-

初始化成功

-

HDF_FAILURE

-

初始化失败

-
- - 函数说明: - - 关联HdfDeviceObject对象和RtcHost。 - - ``` - static int32_t HiRtcBind(struct HdfDeviceObject *device) - { - struct RtcHost *host = NULL; - host = RtcHostCreate(device); //实际是申请内存并挂接device: host->device = device; - //使HdfDeviceObject与RtcHost可以相互转化的前提 - ... - device->service = &host->service;//使HdfDeviceObject与RtcHost可以相互转化的前提 - //方便后续通过调用RtcHostFromDevice 实现全局性质的host 使用 - return HDF_SUCCESS; - } - ``` - - - Init函数参考 - - 入参**:** - - HdfDeviceObject 是整个驱动对外暴露的接口参数,具备 HCS 配置文件的信息。 - - 返回值**:** - - HDF\_STATUS相关状态。 - - 函数说明: - - 初始化自定义结构体对象,初始化RtcHost成员。 - - ``` - static int32_t HiRtcInit(struct HdfDeviceObject *device) - { - struct RtcHost *host = NULL; - struct RtcConfigInfo *rtcInfo = NULL; - ... - host = RtcHostFromDevice(device);//这里有HdfDeviceObject到RtcHost的强制转化 - rtcInfo = OsalMemCalloc(sizeof(*rtcInfo)); - ... - //HiRtcConfigData 会从设备配置树中读取属性填充rtcInfo 的supportAnaCtrl, supportLock, spiBaseAddr, regAddrLength, irq - //为HiRtcSwInit 和HiRtcSwInit 提供参数,...函数内部处理失败后内存释放等操作 - if (HiRtcConfigData(rtcInfo, device->property) != 0) { - ... - } - if (HiRtcSwInit(rtcInfo) != 0) {//地址映射以及中断注册相关 - ... - } - if (HiRtcHwInit(rtcInfo) != 0) {//初始化anaCtrl 和 lockAddr 相关内容 - ... - } - - host->method = &g_method;//RtcMethod的实例化对象的挂载 - host->data = rtcInfo; //使RtcConfigInfo与RtcHost可以相互转化的前提 - HDF_LOGI("Hdf dev service:%s init success!", HdfDeviceGetServiceName(device)); - return HDF_SUCCESS; - } - ``` - - - Release 函数参考 - - 入参**:** - - HdfDeviceObject 是整个驱动对外暴露的接口参数,具备 HCS 配置文件的信息。 - - 返回值**:** - - 无。 - - 函数说明: - - 释放内存和删除控制器,该函数需要在驱动入口结构体中赋值给 Release 接口, 当HDF框架调用Init函数初始化驱动失败时,可以调用 Release 释放驱动资源。所有强制转换获取相应对象的操作前提是在Init或Bind函数中具备对应赋值的操作。 - - ``` - static void HiRtcRelease(struct HdfDeviceObject *device) - { - struct RtcHost *host = NULL; - struct RtcConfigInfo *rtcInfo = NULL; - ... - host = RtcHostFromDevice(device); //这里有HdfDeviceObject到RtcHost的强制转化 - rtcInfo = (struct RtcConfigInfo *)host->data;//这里有RtcHost到RtcConfigInfo的强制转化 - if (rtcInfo != NULL) { - HiRtcSwExit(rtcInfo); - OsalMemFree(rtcInfo); //释放RtcConfigInfo - host->data = NULL; - } - RtcHostDestroy(host); //释放RtcHost - } - ``` - - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/11.SDIO.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/11.SDIO.md" deleted file mode 100644 index 6c2f57e366db2489493b6f0c24f709e43fca42b0..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/11.SDIO.md" +++ /dev/null @@ -1,545 +0,0 @@ ---- -title: SDIO -permalink: /pages/010502020b -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:24 ---- -# SDIO - -- [概述](#section1347805272150053) -- [接口说明](#section752964871810) -- [开发步骤](#section581179475150053) -- [开发实例](#section2112250242150053) - -## 概述 - -SDIO由SD卡发展而来,被统称为MMC(MultiMediaCard),相关技术差别不大,在HDF框架中,SDIO的接口适配模式采用独立服务模式,在这种模式下,每一个设备对象会独立发布一个设备服务来处理外部访问,设备管理器收到API的访问请求之后,通过提取该请求的参数,达到调用实际设备对象的相应内部方法的目的。独立服务模式可以直接借助HDFDeviceManager的服务管理能力,但需要为每个设备单独配置设备节点,增加内存占用。 - -**图 1** SDIO独立服务模式结构图 -![](/images/device-dev/driver/figures/独立服务模式结构图.png "SDIO独立服务模式结构图") - -## 接口说明 - -SdioDeviceOps定义: - -``` -// 函数模板 -struct SdioDeviceOps { - int32_t (*incrAddrReadBytes)(struct SdioDevice *dev, uint8_t *data, uint32_t addr, uint32_t size); - int32_t (*incrAddrWriteBytes)(struct SdioDevice *dev, uint8_t *data, uint32_t addr, uint32_t size); - int32_t (*fixedAddrReadBytes)(struct SdioDevice *dev, uint8_t *data, uint32_t addr, uint32_t size, uint32_t scatterLen); - int32_t (*fixedAddrWriteBytes)(struct SdioDevice *dev, uint8_t *data, uint32_t addr, uint32_t size, uint32_t scatterLen); - int32_t (*func0ReadBytes)(struct SdioDevice *dev, uint8_t *data, uint32_t addr, uint32_t size); - int32_t (*func0WriteBytes)(struct SdioDevice *dev, uint8_t *data, uint32_t addr, uint32_t size); - int32_t (*setBlockSize)(struct SdioDevice *dev, uint32_t blockSize); - int32_t (*getCommonInfo)(struct SdioDevice *dev, SdioCommonInfo *info, uint32_t infoType); - int32_t (*setCommonInfo)(struct SdioDevice *dev, SdioCommonInfo *info, uint32_t infoType); - int32_t (*flushData)(struct SdioDevice *dev); - int32_t (*enableFunc)(struct SdioDevice *dev); - int32_t (*disableFunc)(struct SdioDevice *dev); - int32_t (*claimIrq)(struct SdioDevice *dev, SdioIrqHandler *irqHandler); - int32_t (*releaseIrq)(struct SdioDevice *dev); - int32_t (*findFunc)(struct SdioDevice *dev, struct SdioFunctionConfig *configData); - int32_t (*claimHost)(struct SdioDevice *dev); - int32_t (*releaseHost)(struct SdioDevice *dev); -}; -``` - -**表 1** SdioDeviceOps结构体成员的回调函数功能说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

函数

-

入参

-

出参

-

返回值

-

功能

-

incrAddrReadBytes

-

dev: 结构体指针,SDIO设备控制器;addr: uint32_t,地址值;size: uint32_t,大小

-

data: uint8_t指针,传出值;

-

HDF_STATUS相关状态

-

从指定的SDIO地址增量读取给定长度的数据

-

incrAddrWriteBytes

-

dev: 结构体指针,SDIO设备控制器;data: uint8_t指针,传入值;addr: uint32_t,地址值;size: uint32_t,大小

-

-

HDF_STATUS相关状态

-

将给定长度的数据增量写入指定的SDIO地址

-

fixedAddrReadBytes

-

dev: 结构体指针,SDIO设备控制器;addr: uint32_t,地址值;size: uint32_t,大小;scatterLen: uint32_t,数据长度;

-

data: uint8_t指针,传出值;

-

HDF_STATUS相关状态

-

从固定SDIO地址读取给定长度的数据。

-

fixedAddrWriteBytes

-

dev: 结构体指针,SDIO设备控制器;data: uint8_t指针,传入值;addr: uint32_t,地址值;size: uint32_t,大小;scatterLen: uint32_t,数据长度;

-

-

HDF_STATUS相关状态

-

将给定长度的数据写入固定SDIO地址

-

func0ReadBytes

-

dev: 结构体指针,SDIO设备控制器;addr: uint32_t,地址值;size: uint32_t,大小;

-

data: uint8_t指针,传出值;

-

HDF_STATUS相关状态

-

从SDIO函数0的地址空间读取给定长度的数据。

-

func0WriteBytes

-

dev: 结构体指针,SDIO设备控制器;data: uint8_t指针,传入值;addr: uint32_t,地址值;size: uint32_t,大小;

-

-

HDF_STATUS相关状态

-

将给定长度的数据写入SDIO函数0的地址空间。

-

setBlockSize

-

dev: 结构体指针,SDIO设备控制器;blockSize: uint32_t,Block大小

-

-

HDF_STATUS相关状态

-

设置block大小

-

getCommonInfo

-

dev: 联合体指针,SDIO设备控制器;infoType: uint32_t,info类型;

-

info: 结构体指针,传出SdioFuncInfo信息;

-

HDF_STATUS相关状态

-

获取CommonInfo,说明见下

-

setCommonInfo

-

dev: 结构体指针,SDIO设备控制器;info: 联合体指针,SdioFuncInfo信息传入;infoType: uint32_t,info类型;

-

-

HDF_STATUS相关状态

-

设置CommonInfo,说明见下

-

flushData

-

dev: 结构体指针,SDIO设备控制器;

-

-

HDF_STATUS相关状态

-

当SDIO需要重新初始化或发生意外错误时调用的函数

-

enableFunc

-

dev: 结构体指针,SDIO设备控制器;

-

-

HDF_STATUS相关状态

-

使能SDIO设备

-

disableFunc

-

dev: 结构体指针,SDIO设备控制器;

-

-

HDF_STATUS相关状态

-

去使能SDIO设备

-

claimIrq

-

dev: 结构体指针,SDIO设备控制器;irqHandler: void函数指针;

-

-

HDF_STATUS相关状态

-

注册SDIO中断

-

releaseIrq

-

dev: 结构体指针,SDIO设备控制器;

-

-

HDF_STATUS相关状态

-

释放SDIO中断

-

findFunc

-

dev: 结构体指针,SDIO设备控制器;configData: 结构体指针, SDIO函数关键信息

-

-

HDF_STATUS相关状态

-

寻找匹配的funcNum

-

claimHost

-

dev: 结构体指针,SDIO设备控制器;

-

-

HDF_STATUS相关状态

-

独占HOST

-

releaseHost

-

dev: 结构体指针,SDIO设备控制器;

-

-

HDF_STATUS相关状态

-

释放HOST

-
- ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->CommonInfo包括maxBlockNum\(单个request中最大block数\), maxBlockSize\(单个block最大字节数\), maxRequestSize\(单个Request最大字节数\), enTimeout\(最大超时时间,毫秒\), funcNum\(功能编号1\~7\), irqCap\(IRQ capabilities\), \(void \*\)data. - -## 开发步骤 - -SDIO模块适配HDF框架的三个环节是配置属性文件,实例化驱动入口,以及填充核心层接口函数。 - -1. **实例化驱动入口:** - - 实例化HdfDriverEntry结构体成员。 - - 调用HDF\_INIT将HdfDriverEntry实例化对象注册到HDF框架中。 - -2. **配置属性文件:** - - 在device\_info.hcs文件中添加deviceNode描述。 - - 【可选】添加sdio\_config.hcs器件属性文件。 - -3. **实例化SDIO控制器对象:** - - 初始化SdioDevice成员。 - - 实例化SdioDevice成员SdioDeviceOps。 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >实例化SdioDevice成员SdioDeviceOps,其定义和成员说明见[接口说明](#section752964871810)。 - - -4. **驱动调试:** - - 【可选】针对新增驱动程序,建议验证驱动基本功能,例如SDIO控制状态,中断响应情况等。 - - -## 开发实例 - -下方将以sdio\_adapter.c为示例,展示需要厂商提供哪些内容来完整实现设备功能。 - -1. 驱动开发首先需要实例化驱动入口,驱动入口必须为HdfDriverEntry(在 hdf\_device\_desc.h 中定义)类型的全局变量,且moduleName要和device\_info.hcs中保持一致。HDF框架会将所有加载的驱动的HdfDriverEntry对象首地址汇总,形成一个类似数组的段地址空间,方便上层调用。 - - 一般在加载驱动时HDF会先调用Bind函数,再调用Init函数加载该驱动。当Init调用异常时,HDF框架会调用Release释放驱动资源并退出。 - - SDIO 驱动入口参考: - - ``` - struct HdfDriverEntry g_sdioDriverEntry = { - .moduleVersion = 1, - .Bind = Hi35xxLinuxSdioBind, //见Bind参考 - .Init = Hi35xxLinuxSdioInit, //见Init参考 - .Release = Hi35xxLinuxSdioRelease,//见Release参考 - .moduleName = "HDF_PLATFORM_SDIO",//【必要 且与 HCS文件中里面的moduleName匹配】 - }; - //调用HDF_INIT将驱动入口注册到HDF框架中 - HDF_INIT(g_sdioDriverEntry); - ``` - -2. 完成驱动入口注册之后,下一步请在device\_info.hcs文件中添加deviceNode信息,并在 sdio\_config.hcs 中配置器件属性。deviceNode信息与驱动入口注册相关,器件属性值与核心层SdioDevice成员的默认值或限制范围有密切关系。 - - 本例只有一个SDIO控制器,如有多个器件信息,则需要在device\_info文件增加deviceNode信息,以及在sdio\_config文件中增加对应的器件属性。 - - - device\_info.hcs 配置参考: - - ``` - root { - device_info { - match_attr = "hdf_manager"; - platform :: host { - hostName = "platform_host"; - priority = 50; - device_sdio :: device { - device0 :: deviceNode { - policy = 1; - priority = 70; - permission = 0644; - moduleName = "HDF_PLATFORM_SDIO"; //【必要】用于指定驱动名称,需要与驱动Entry中的moduleName一致; - serviceName = "HDF_PLATFORM_MMC_2"; //【必要】驱动对外发布服务的名称,必须唯一 - deviceMatchAttr = "hisilicon_hi35xx_sdio_0";//【必要】用于配置控制器私有数据,要与sdio_config.hcs中对应控制器保持一致 - } - } - } - } - } - ``` - - - sdio\_config.hcs 配置参考: - - ``` - root { - platform { - sdio_config { - template sdio_controller { - match_attr = ""; - hostId = 2; //【必要】模式固定为2,在mmc_config.hcs有介绍 - devType = 2; //【必要】模式固定为2,在mmc_config.hcs有介绍 - } - controller_0x2dd1 :: sdio_controller { - match_attr = "hisilicon_hi35xx_sdio_0";//【必要】需要和device_info.hcs中的deviceMatchAttr值一致 - } - } - } - ``` - -3. 完成驱动入口注册之后,最后一步就是以核心层SdioDevice对象的初始化为核心,包括厂商自定义结构体(传递参数和数据),实例化SdioDevice成员SdioDeviceOps(让用户可以通过接口来调用驱动底层函数),实现HdfDriverEntry成员函数(Bind,Init,Release)。 - - 自定义结构体参考: - - 从驱动的角度看,自定义结构体是参数和数据的载体,而且sdio\_config.hcs文件中的数值会被HDF读入通过DeviceResourceIface来初始化结构体成员,一些重要数值也会传递给核心层对象。 - - ``` - typedef struct { - uint32_t maxBlockNum; // 单个request最大的block个数 - uint32_t maxBlockSize; // 单个block最大的字节数1~2048 - uint32_t maxRequestSize; // 单个request最大的字节数 1~2048 - uint32_t enTimeout; // 最大超时时间,单位毫秒,且不能超过一秒 - uint32_t funcNum; // 函数编号1~7 - uint32_t irqCap; // 中断能力 - void *data; // 私有数据 - } SdioFuncInfo; - - //SdioDevice是核心层控制器结构体,其中的成员在Bind函数中会被赋值 - struct SdioDevice { - struct SdDevice sd; - struct SdioDeviceOps *sdioOps; - struct SdioRegister sdioReg; - uint32_t functions; - struct SdioFunction *sdioFunc[SDIO_MAX_FUNCTION_NUMBER]; - struct SdioFunction *curFunction; - struct OsalThread thread; /* irq thread */ - struct OsalSem sem; - bool irqPending; - bool threadRunning; - }; - ``` - - - SdioDevice成员回调函数结构体SdioDeviceOps的实例化,其他成员在Init函数中初始化。 - - ``` - static struct SdioDeviceOps g_sdioDeviceOps = { - .incrAddrReadBytes = Hi35xxLinuxSdioIncrAddrReadBytes, - .incrAddrWriteBytes = Hi35xxLinuxSdioIncrAddrWriteBytes, - .fixedAddrReadBytes = Hi35xxLinuxSdioFixedAddrReadBytes, - .fixedAddrWriteBytes = Hi35xxLinuxSdioFixedAddrWriteBytes, - .func0ReadBytes = Hi35xxLinuxSdioFunc0ReadBytes, - .func0WriteBytes = Hi35xxLinuxSdioFunc0WriteBytes, - .setBlockSize = Hi35xxLinuxSdioSetBlockSize, - .getCommonInfo = Hi35xxLinuxSdioGetCommonInfo, - .setCommonInfo = Hi35xxLinuxSdioSetCommonInfo, - .flushData = Hi35xxLinuxSdioFlushData, - .enableFunc = Hi35xxLinuxSdioEnableFunc, - .disableFunc = Hi35xxLinuxSdioDisableFunc, - .claimIrq = Hi35xxLinuxSdioClaimIrq, - .releaseIrq = Hi35xxLinuxSdioReleaseIrq, - .findFunc = Hi35xxLinuxSdioFindFunc, - .claimHost = Hi35xxLinuxSdioClaimHost, - .releaseHost = Hi35xxLinuxSdioReleaseHost, - }; - ``` - - - Bind函数参考 - - 入参: - - HdfDeviceObject 是整个驱动对外暴露的接口参数,具备 HCS 配置文件的信息。 - - 返回值: - - HDF\_STATUS相关状态 (下表为部分展示,如需使用其他状态,可见//drivers/framework/include/utils/hdf\_base.h中HDF\_STATUS 定义)。 - - **表 2** Bind函数入参及返回值 - - - - - - - - - - - - - - - - - - - - - - - - - -

状态(值)

-

问题描述

-

HDF_ERR_INVALID_OBJECT

-

控制器对象非法

-

HDF_ERR_MALLOC_FAIL

-

内存分配失败

-

HDF_ERR_INVALID_PARAM

-

参数非法

-

HDF_ERR_IO

-

I/O 错误

-

HDF_SUCCESS

-

初始化成功

-

HDF_FAILURE

-

初始化失败

-
- - 函数说明: - - 初始化自定义结构体对象,初始化SdioCntlr成员,调用核心层SdioCntlrAdd函数,以及其他厂商自定义初始化操作。 - - ``` - static int32_t Hi35xxLinuxSdioBind(struct HdfDeviceObject *obj) - { - struct MmcCntlr *cntlr = NULL; - int32_t ret; - ... - cntlr = (struct MmcCntlr *)OsalMemCalloc(sizeof(struct MmcCntlr));// 分配内存 - ... - cntlr->ops = &g_sdioCntlrOps; //【必要】struct MmcCntlrOps g_sdioCntlrOps={ - // .rescanSdioDev = Hi35xxLinuxSdioRescan,}; - cntlr->hdfDevObj = obj; //【必要】使HdfDeviceObject与MmcCntlr可以相互转化的前提 - obj->service = &cntlr->service;//【必要】使HdfDeviceObject与MmcCntlr可以相互转化的前提 - ret = Hi35xxLinuxSdioCntlrParse(cntlr, obj);//【必要】初始化cntlr 的 index, devType, 失败则 goto _ERR; - ... - ret = MmcCntlrAdd(cntlr); //【必要】调用核心层mmc_core.c的函数, 失败则 goto _ERR; - ... - ret = MmcCntlrAllocDev(cntlr, (enum MmcDevType)cntlr->devType);//【必要】调用核心层mmc_core.c的函数, 失败则 goto _ERR; - ... - - MmcDeviceAddOps(cntlr->curDev, &g_sdioDeviceOps);//【必要】调用核心层mmc_core.c的函数, 钩子函数挂载 - HDF_LOGD("Hi35xxLinuxSdioBind: Success!"); - return HDF_SUCCESS; - - _ERR: - Hi35xxLinuxSdioDeleteCntlr(cntlr); - HDF_LOGE("Hi35xxLinuxSdioBind: Fail!"); - return HDF_FAILURE; - } - ``` - - - Init函数参考 - - 入参: - - HdfDeviceObject 是整个驱动对外暴露的接口参数,具备 HCS 配置文件的信息。 - - 返回值: - - HDF\_STATUS相关状态。 - - 函数说明: - - 无操作,可根据厂商需要添加。 - - ``` - static int32_t Hi35xxLinuxSdioInit(struct HdfDeviceObject *obj) - { - (void)obj;//无操作,可根据厂商需要添加 - HDF_LOGD("Hi35xxLinuxSdioInit: Success!"); - return HDF_SUCCESS; - } - ``` - - - Release函数参考 - - 入参: - - HdfDeviceObject 是整个驱动对外暴露的接口参数,具备 HCS 配置文件的信息。 - - 返回值: - - 无。 - - 函数说明: - - 释放内存和删除控制器,该函数需要在驱动入口结构体中赋值给 Release 接口, 当HDF框架调用Init函数初始化驱动失败时,可以调用 Release 释放驱动资源。所有强制转换获取相应对象的操作前提是在Bind函数中具备对应赋值的操作。 - - ``` - static void Hi35xxLinuxSdioRelease(struct HdfDeviceObject *obj) - { - if (obj == NULL) { - return; - } - Hi35xxLinuxSdioDeleteCntlr((struct MmcCntlr *)obj->service);//【必要】自定义的内存释放函数,这里有HdfDeviceObject到MmcCntlr的强制转化 - } - ``` - - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/12.SPI.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/12.SPI.md" deleted file mode 100644 index 304d4804915b5fb893eaf9de728211c8df0637af..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/12.SPI.md" +++ /dev/null @@ -1,462 +0,0 @@ ---- -title: SPI -permalink: /pages/010502020c -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:24 ---- -# SPI - -- [概述](#section84922229152909) -- [接口说明](#section752964871810) -- [开发步骤](#section799667984152909) -- [开发实例](#section956157227152909) - -## 概述 - -SPI即串行外设接口(Serial Peripheral Interface),在HDF框架中,SPI的接口适配模式采用独立服务模式,在这种模式下,每一个设备对象会独立发布一个设备服务来处理外部访问,设备管理器收到API的访问请求之后,通过提取该请求的参数,达到调用实际设备对象的相应内部方法的目的。独立服务模式可以直接借助HDFDeviceManager的服务管理能力,但需要为每个设备单独配置设备节点,增加内存占用。 - -**图 1** SPI独立服务模式结构图 -![](/images/device-dev/driver/figures/独立服务模式结构图.png "SPI独立服务模式结构图") - -## 接口说明 - -SpiCntlrMethod定义: - -``` -struct SpiCntlrMethod { - int32_t (*GetCfg)(struct SpiCntlr *cntlr, struct SpiCfg *cfg); - int32_t (*SetCfg)(struct SpiCntlr *cntlr, struct SpiCfg *cfg); - int32_t (*Transfer)(struct SpiCntlr *cntlr, struct SpiMsg *msg, uint32_t count); - int32_t (*Open)(struct SpiCntlr *cntlr); - int32_t (*Close)(struct SpiCntlr *cntlr); -}; -``` - -**表 1** SpiCntlrMethod结构体成员的回调函数功能说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

成员函数

-

入参

-

返回值

-

功能

-

Transfer

-

cntlr:结构体指针,核心层spi控制器;
msg:结构体指针,Spi消息;
count:uint32_t,消息个数;

-

HDF_STATUS相关状态

-

传输消息

-

SetCfg

-

cntlr;结构体指针,核心层spi控制器;
cfg:结构体指针,Spi属性;

-

HDF_STATUS相关状态

-

设置控制器属性

-

GetCfg

-

cntlr:结构体指针,核心层spi控制器;
cfg:结构体指针,Spi属性;

-

HDF_STATUS相关状态

-

获取控制器属性

-

Open

-

cntlr:结构体指针,核心层spi控制器;

-

HDF_STATUS相关状态

-

打开SPI

-

Close

-

cntlr:结构体指针,核心层spi控制器;

-

HDF_STATUS相关状态

-

关闭SPI

-
- -## 开发步骤 - -SPI模块适配HDF框架的三个环节是配置属性文件,实例化驱动入口,以及实例化核心层接口函数。 - -1. **实例化驱动入口:** - - 实例化HdfDriverEntry结构体成员。 - - 调用HDF\_INIT将HdfDriverEntry实例化对象注册到HDF框架中。 - -2. **配置属性文件:** - - 在device\_info.hcs文件中添加deviceNode描述。 - - 【可选】添加spi\_config.hcs器件属性文件。 - -3. **实例化SPI控制器对象:** - - 初始化SpiCntlr成员。 - - 实例化SpiCntlr成员SpiCntlrMethod。 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >实例化SpiCntlr成员SpiCntlrMethod,其定义和成员说明见[接口说明](#section752964871810)。 - - -4. **驱动调试:** - - 【可选】针对新增驱动程序,建议验证驱动基本功能,例如spi控制状态,中断响应情况等。 - - -## 开发实例 - -下方将以spi\_hi35xx.c为示例,展示需要厂商提供哪些内容来完整实现设备功能。 - -1. 驱动开发首先需要实例化驱动入口,驱动入口必须为HdfDriverEntry(在 hdf\_device\_desc.h 中定义)类型的全局变量,且moduleName要和device\_info.hcs中保持一致。HDF框架会将所有加载的驱动的HdfDriverEntry对象首地址汇总,形成一个类似数组的段地址空间,方便上层调用。 - - 一般在加载驱动时HDF会先调用Bind函数,再调用Init函数加载该驱动。当Init调用异常时,HDF框架会调用Release释放驱动资源并退出。 - - SPI驱动入口参考: - - ``` - struct HdfDriverEntry g_hdfSpiDevice = { - .moduleVersion = 1, - .moduleName = "HDF_PLATFORM_SPI",//【必要 且与 HCS文件中里面的moduleName匹配】 - .Bind = HdfSpiDeviceBind, //见Bind参考 - .Init = HdfSpiDeviceInit, //见Init参考 - .Release = HdfSpiDeviceRelease, //见Release参考 - }; - //调用HDF_INIT将驱动入口注册到HDF框架中 - HDF_INIT(g_hdfSpiDevice); - ``` - -2. 完成驱动入口注册之后,下一步请在device\_info.hcs文件中添加deviceNode信息,并在 spi\_config.hcs 中配置器件属性。deviceNode信息与驱动入口注册相关,器件属性值与核心层SpiCntlr 成员的默认值或限制范围有密切关系。 - - 本例只有一个SPI控制器,如有多个器件信息,则需要在device\_info文件增加deviceNode信息,以及在spi\_config文件中增加对应的器件属性。 - - - device\_info.hcs 配置参考。 - - ``` - root { - device_info { - match_attr = "hdf_manager"; - platform :: host { - hostName = "platform_host"; - priority = 50; - device_spi :: device { //为每一个 SPI 控制器配置一个HDF设备节点 - device0 :: deviceNode { - policy = 1; - priority = 60; - permission = 0644; - moduleName = "HDF_PLATFORM_SPI"; - serviceName = "HDF_PLATFORM_SPI_0"; - deviceMatchAttr = "hisilicon_hi35xx_spi_0"; - } - device1 :: deviceNode { - policy = 1; - priority = 60; - permission = 0644; - moduleName = "HDF_PLATFORM_SPI"; // 【必要】用于指定驱动名称,该字段的值必须和驱动入口结构的moduleName值一致 - serviceName = "HDF_PLATFORM_SPI_1"; // 【必要且唯一】驱动对外发布服务的名称 - deviceMatchAttr = "hisilicon_hi35xx_spi_1";// 需要与设备hcs文件中的 match_attr 匹配 - } - ... - } - } - } - } - ``` - - - spi\_config.hcs 配置参考。 - - ``` - root { - platform { - spi_config {//每一个SPI控制器配置私有数据 - template spi_controller {//模板公共参数, 继承该模板的节点如果使用模板中的默认值, 则节点字段可以缺省 - serviceName = ""; - match_attr = ""; - transferMode = 0; // 数据传输模式:中断传输(0),流控传输(1),DMA传输(2) - busNum = 0; // 总线号 - clkRate = 100000000; - bitsPerWord = 8; // 传输位宽 - mode = 19; // SPI 数据的输入输出模式 - maxSpeedHz = 0; // 最大时钟频率 - minSpeedHz = 0; // 最小时钟频率 - speed = 2000000; // 当前消息传输速度 - fifoSize = 256; // FIFO大小 - numCs = 1; // 片选号 - regBase = 0x120c0000; // 地址映射需要 - irqNum = 100; // 中断号 - REG_CRG_SPI = 0x120100e4; // CRG_REG_BASE(0x12010000) + 0x0e4 - CRG_SPI_CKEN = 0; - CRG_SPI_RST = 0; - REG_MISC_CTRL_SPI = 0x12030024; // MISC_REG_BASE(0x12030000) + 0x24 - MISC_CTRL_SPI_CS = 0; - MISC_CTRL_SPI_CS_SHIFT = 0; - } - controller_0x120c0000 :: spi_controller { - busNum = 0; //【必要】总线号 - CRG_SPI_CKEN = 0x10000; // (0x1 << 16) 0:close clk, 1:open clk - CRG_SPI_RST = 0x1; // (0x1 << 0) 0:cancel reset, 1:reset - match_attr = "hisilicon_hi35xx_spi_0";//【必要】需要和device_info.hcs中的deviceMatchAttr值一致 - } - controller_0x120c1000 :: spi_controller { - busNum = 1; - CRG_SPI_CKEN = 0x20000; // (0x1 << 17) 0:close clk, 1:open clk - CRG_SPI_RST = 0x2; // (0x1 << 1) 0:cancel reset, 1:reset - match_attr = "hisilicon_hi35xx_spi_1"; - regBase = 0x120c1000; //【必要】地址映射需要 - irqNum = 101; //【必要】中断号 - } - ... - // 【可选】可新增,但需要在 device_info.hcs 添加对应的节点 - } - } - } - ``` - -3. 完成驱动入口注册之后,最后一步就是以核心层SpiCntlr对象的初始化为核心,包括厂商自定义结构体(传递参数和数据),实例化SpiCntlr成员SpiCntlrMethod(让用户可以通过接口来调用驱动底层函数),实现HdfDriverEntry成员函数(Bind,Init,Release)。 - - 自定义结构体参考。 - - 从驱动的角度看,自定义结构体是参数和数据的载体,而且spi\_config.hcs文件中的数值会被HDF读入通过DeviceResourceIface来初始化结构体成员,一些重要数值也会传递给核心层对象,例如设备号、总线号等。 - - ``` - struct Pl022 {//对应于hcs中的参数 - struct SpiCntlr *cntlr; - struct DListHead deviceList; - struct OsalSem sem; - volatile unsigned char *phyBase; - volatile unsigned char *regBase; - uint32_t irqNum; - uint32_t busNum; - uint32_t numCs; - uint32_t curCs; - uint32_t speed; - uint32_t fifoSize; - uint32_t clkRate; - uint32_t maxSpeedHz; - uint32_t minSpeedHz; - uint32_t regCrg; - uint32_t clkEnBit; - uint32_t clkRstBit; - uint32_t regMiscCtrl; - uint32_t miscCtrlCsShift; - uint32_t miscCtrlCs; - uint16_t mode; - uint8_t bitsPerWord; - uint8_t transferMode; - }; - - //SpiCntlr是核心层控制器结构体,其中的成员在Init函数中会被赋值 - struct SpiCntlr { - struct IDeviceIoService service; - struct HdfDeviceObject *device; - uint32_t busNum; - uint32_t numCs; - uint32_t curCs; - struct OsalMutex lock; - struct SpiCntlrMethod *method; - struct DListHead list; - void *priv; - }; - ``` - - - SpiCntlr成员回调函数结构体SpiCntlrMethod的实例化,其他成员在Init函数中初始化。 - - ``` - // spi_hi35xx.c 中的示例:钩子函数的实例化 - struct SpiCntlrMethod g_method = { - .Transfer = Pl022Transfer, - .SetCfg = Pl022SetCfg, - .GetCfg = Pl022GetCfg, - .Open = Pl022Open, - .Close = Pl022Close, - }; - ``` - - - Bind 函数参考 - - 入参: - - HdfDeviceObject 是整个驱动对外暴露的接口参数,具备 HCS 配置文件的信息。 - - 返回值: - - HDF\_STATUS相关状态。 - - 函数说明: - - 将 SpiCntlr 对象同 HdfDeviceObject 进行了关联。 - - ``` - static int32_t HdfSpiDeviceBind(struct HdfDeviceObject *device) - { - ... - return (SpiCntlrCreate(device) == NULL) ? HDF_FAILURE : HDF_SUCCESS; - } - - struct SpiCntlr *SpiCntlrCreate(struct HdfDeviceObject *device) - { - struct SpiCntlr *cntlr = NULL; //创建核心层 SpiCntlr 对象 - ... - cntlr = (struct SpiCntlr *)OsalMemCalloc(sizeof(*cntlr));//分配内存 - ... - cntlr->device = device; //使HdfDeviceObject与SpiCntlr可以相互转化的前提 - device->service = &(cntlr->service);//使HdfDeviceObject与SpiCntlr可以相互转化的前提 - (void)OsalMutexInit(&cntlr->lock); //锁初始化 - DListHeadInit(&cntlr->list); //添加对应的节点 - cntlr->priv = NULL; - return cntlr; - } - ``` - - - Init函数参考 - - 入参: - - HdfDeviceObject 是整个驱动对外暴露的接口参数,具备 HCS 配置文件的信息。 - - 返回值: - - HDF\_STATUS相关状态 (下表为部分展示,如需使用其他状态,可见/drivers/framework/include/utils/hdf\_base.h中HDF\_STATUS 定义)。 - - **表 2** init函数入参和返回值 - - - - - - - - - - - - - - - - - - - - - - - - - -

状态(值)

-

问题描述

-

HDF_ERR_INVALID_OBJECT

-

控制器对象非法

-

HDF_ERR_MALLOC_FAIL

-

内存分配失败

-

HDF_ERR_INVALID_PARAM

-

参数非法

-

HDF_ERR_IO

-

I/O 错误

-

HDF_SUCCESS

-

初始化成功

-

HDF_FAILURE

-

初始化失败

-
- - 函数说明: - - 初始化自定义结构体对象,初始化SpiCntlr成员。 - - ``` - static int32_t HdfSpiDeviceInit(struct HdfDeviceObject *device) - { - int32_t ret; - struct SpiCntlr *cntlr = NULL; - ... - cntlr = SpiCntlrFromDevice(device);//这里有HdfDeviceObject到SpiCntlr的强制转化,通过service成员,赋值见Bind函数 - //return (device == NULL) ? NULL : (struct SpiCntlr *)device->service; - ... - ret = Pl022Init(cntlr, device);//【必要】实例化厂商自定义操作对象,示例见下 - ... - ret = Pl022Probe(cntlr->priv); - ... - return ret; - } - - static int32_t Pl022Init(struct SpiCntlr *cntlr, const struct HdfDeviceObject *device) - { - int32_t ret; - struct Pl022 *pl022 = NULL; - ... - pl022 = (struct Pl022 *)OsalMemCalloc(sizeof(*pl022));//申请内存 - ... - ret = SpiGetBaseCfgFromHcs(pl022, device->property); //初始化busNum, numCs, speed, fifoSize, clkRate,mode, bitsPerWord, transferMode参数值 - ... - ret = SpiGetRegCfgFromHcs(pl022, device->property); //初始化regBase, phyBase, irqNum, regCrg, clkEnBit,clkRstBit, regMiscCtrl, regMiscCtrl, miscCtrlCs,miscCtrlCsShift参数值 - ... - //计算最大,最小速度对应的频率 - pl022->maxSpeedHz = (pl022->clkRate) / ((SCR_MIN + 1) * CPSDVSR_MIN); - pl022->minSpeedHz = (pl022->clkRate) / ((SCR_MAX + 1) * CPSDVSR_MAX); - DListHeadInit(&pl022->deviceList);//初始化DList链表 - pl022->cntlr = cntlr; //使Pl022与SpiCntlr可以相互转化的前提 - cntlr->priv = pl022; //使Pl022与SpiCntlr可以相互转化的前提 - cntlr->busNum = pl022->busNum; //给SpiCntlr的busNum赋值 - cntlr->method = &g_method; //SpiCntlrMethod的实例化对象的挂载 - ... - ret = Pl022CreatAndInitDevice(pl022); - if (ret != 0) { - Pl022Release(pl022); //初始化失败就释放Pl022对象 - return ret; - } - return 0; - } - ``` - - - Release函数参考 - - 入参: - - HdfDeviceObject 是整个驱动对外暴露的接口参数,具备 HCS 配置文件的信息。 - - 返回值: - - 无。 - - 函数说明: - - 释放内存和删除控制器,该函数需要在驱动入口结构体中赋值给 Release 接口, 当HDF框架调用Init函数初始化驱动失败时,可以调用 Release 释放驱动资源。所有强制转换获取相应对象的操作**前提**是在Init函数中具备对应赋值的操作。 - - ``` - static void HdfSpiDeviceRelease(struct HdfDeviceObject *device) - { - struct SpiCntlr *cntlr = NULL; - ... - cntlr = SpiCntlrFromDevice(device);//这里有HdfDeviceObject到SpiCntlr的强制转化,通过service成员,赋值见Bind函数 - // return (device==NULL) ?NULL:(struct SpiCntlr *)device->service; - ... - if (cntlr->priv != NULL) { - Pl022Remove((struct Pl022 *)cntlr->priv);//这里有SpiCntlr到Pl022的强制转化 - } - SpiCntlrDestroy(cntlr); //释放Pl022对象 - } - ``` - - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/13.UART.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/13.UART.md" deleted file mode 100644 index 22562923f8a1c9447a9147f76a510f23f0cc0a3c..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/13.UART.md" +++ /dev/null @@ -1,560 +0,0 @@ ---- -title: UART -permalink: /pages/010502020d -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:24 ---- -# UART - -- [概述](#section1761881586154520) -- [接口说明](#section752964871810) -- [开发步骤](#section944397404154520) -- [开发实例](#section774610224154520) - -## 概述 - -UART是通用异步收发传输器(Universal Asynchronous Receiver/Transmitter)的缩写,在HDF框架中,UART的接口适配模式采用独立服务模式。在这种模式下,每一个设备对象会独立发布一个设备服务来处理外部访问,设备管理器收到API的访问请求之后,通过提取该请求的参数,达到调用实际设备对象的相应内部方法的目的。独立服务模式可以直接借助HDFDeviceManager的服务管理能力,但需要为每个设备单独配置设备节点,增加内存占用。 - -**图 1** UART独立服务模式结构图 -![](/images/device-dev/driver/figures/独立服务模式结构图.png "UART独立服务模式结构图") - -## 接口说明 - -UartHostMethod定义: - -``` -struct UartHostMethod { - int32_t (*Init)(struct UartHost *host); - int32_t (*Deinit)(struct UartHost *host); - int32_t (*Read)(struct UartHost *host, uint8_t *data, uint32_t size); - int32_t (*Write)(struct UartHost *host, uint8_t *data, uint32_t size); - int32_t (*GetBaud)(struct UartHost *host, uint32_t *baudRate); - int32_t (*SetBaud)(struct UartHost *host, uint32_t baudRate); - int32_t (*GetAttribute)(struct UartHost *host, struct UartAttribute *attribute); - int32_t (*SetAttribute)(struct UartHost *host, struct UartAttribute *attribute); - int32_t (*SetTransMode)(struct UartHost *host, enum UartTransMode mode); - int32_t (*pollEvent)(struct UartHost *host, void *filep, void *table); -}; -``` - -**表 1** UartHostMethod结构体成员的回调函数功能说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

函数

-

入参

-

出参

-

返回值

-

功能

-

Init

-

host: 结构体指针,核心层uart控制器;

-

-

HDF_STATUS相关状态

-

初始化Uart设备

-

Deinit

-

host: 结构体指针,核心层uart控制器;

-

-

HDF_STATUS相关状态

-

去初始化Uart设备

-

Read

-

host: 结构体指针,核心层uart控制器;size:uint32_t,数据大小;

-

data: uint8_t指针,传出的数据

-

HDF_STATUS相关状态

-

接收数据 RX

-

Write

-

host: 结构体指针,核心层uart控制器;data:uint8_t指针,传入数据;size:uint32_t,数据大小;

-

-

HDF_STATUS相关状态

-

发送数据 TX

-

SetBaud

-

host: 结构体指针,核心层uart控制器;baudRate: uint32_t指针,波特率传入值;

-

-

HDF_STATUS相关状态

-

设置波特率

-

GetBaud

-

host: 结构体指针,核心层uart控制器;

-

baudRate: uint32_t指针,传出的波特率;

-

HDF_STATUS相关状态

-

获取当前设置的波特率

-

GetAttribute

-

host: 结构体指针,核心层uart控制器;

-

attribute: 结构体指针,传出的属性值(见uart_if.h中UartAttribute定义)

-

HDF_STATUS相关状态

-

获取设备uart相关属性

-

SetAttribute

-

host: 结构体指针,核心层uart控制器;attribute: 结构体指针,属性传入值;

-

-

HDF_STATUS相关状态

-

设置设备uart相关属性

-

SetTransMode

-

host: 结构体指针,核心层uart控制器;mode: 枚举值(见uart_if.h中UartTransMode定义),传输模式

-

-

HDF_STATUS相关状态

-

设置传输模式

-

PollEvent

-

host: 结构体指针,核心层uart控制器;filep: void 指针,file ;table: void 指针,poll_table ;

-

-

HDF_STATUS相关状态

-

poll机制

-
- -## 开发步骤 - -UART模块适配HDF框架的三个环节是配置属性文件,实例化驱动入口,以及实例化核心层接口函数。 - -1. **实例化驱动入口:** - - 实例化HdfDriverEntry结构体成员。 - - 调用HDF\_INIT将HdfDriverEntry实例化对象注册到HDF框架中。 - -2. **配置属性文件:** - - 在device\_info.hcs文件中添加deviceNode描述。 - - 【可选】添加uart\_config.hcs器件属性文件。 - -3. **实例化UART控制器对象:** - - 初始化UartHost成员。 - - 实例化UartHost成员UartHostMethod。 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >实例化UartHost成员UartHostMethod,其定义和成员说明见[接口说明](#section752964871810)。 - - -4. **驱动调试:** - - 【可选】针对新增驱动程序,建议验证驱动基本功能,例如UART控制状态,中断响应情况等。 - - -## 开发实例 - -下方将以uart\_hi35xx.c为示例,展示需要厂商提供哪些内容来完整实现设备功能。 - -1. 驱动开发首先需要实例化驱动入口,驱动入口必须为HdfDriverEntry(在 hdf\_device\_desc.h 中定义)类型的全局变量,且moduleName要和device\_info.hcs中保持一致。HDF框架会将所有加载的驱动的HdfDriverEntry对象首地址汇总,形成一个类似数组的段地址空间,方便上层调用。 - - 一般在加载驱动时HDF会先调用Bind函数,再调用Init函数加载该驱动。当Init调用异常时,HDF框架会调用Release释放驱动资源并退出。 - - UART驱动入口参考: - - ``` - struct HdfDriverEntry g_hdfUartDevice = { - .moduleVersion = 1, - .moduleName = "HDF_PLATFORM_UART",//【必要且与 HCS 里面的名字匹配】 - .Bind = HdfUartDeviceBind, //见Bind参考 - .Init = HdfUartDeviceInit, //见Init参考 - .Release = HdfUartDeviceRelease, //见Release参考 - }; - //调用HDF_INIT将驱动入口注册到HDF框架中 - HDF_INIT(g_hdfUartDevice); - ``` - -2. 完成驱动入口注册之后,下一步请在device\_info.hcs文件中添加deviceNode信息,并在 uart\_config.hcs 中配置器件属性。deviceNode信息与驱动入口注册相关,器件属性值与核心层UartHost成员的默认值或限制范围有密切关系。 - - 本例只有一个UART控制器,如有多个器件信息,则需要在device\_info文件增加deviceNode信息,以及在uart\_config文件中增加对应的器件属性。 - - - device\_info.hcs 配置参考。 - - ``` - root { - device_info { - match_attr = "hdf_manager"; - platform :: host { - hostName = "platform_host"; - priority = 50; - device_uart :: device { - device0 :: deviceNode { - policy = 1; //驱动服务发布的策略,policy大于等于1(用户态可见为2,仅内核态可见为1); - priority = 40; //驱动启动优先级 - permission = 0644; //驱动创建设备节点权限 - moduleName = "HDF_PLATFORM_UART"; //驱动名称,该字段的值必须和驱动入口结构的moduleName值一致 - serviceName = "HDF_PLATFORM_UART_0";//驱动对外发布服务的名称,必须唯一,必须要按照HDF_PLATFORM_UART_X的格式,X为UART控制器编号 - deviceMatchAttr = "hisilicon_hi35xx_uart_0";//驱动私有数据匹配的关键字,必须和驱动私有数据配置表中的match_attr值一致 - } - device1 :: deviceNode { - policy = 2; - permission = 0644; - priority = 40; - moduleName = "HDF_PLATFORM_UART"; - serviceName = "HDF_PLATFORM_UART_1"; - deviceMatchAttr = "hisilicon_hi35xx_uart_1"; - } - ... - } - } - } - } - ``` - - - uart\_config.hcs 配置参考。 - - ``` - root { - platform { - template uart_controller {//模板公共参数, 继承该模板的节点如果使用模板中的默认值, 则节点字段可以缺省 - match_attr = ""; - num = 0; //【必要】设备号 - baudrate = 115200; //【必要】波特率,数值可按需填写 - fifoRxEn = 1; //【必要】使能接收FIFO - fifoTxEn = 1; //【必要】使能发送FIFO - flags = 4; //【必要】标志信号 - regPbase = 0x120a0000; //【必要】地址映射需要 - interrupt = 38; //【必要】中断号 - iomemCount = 0x48; //【必要】地址映射需要 - } - controller_0x120a0000 :: uart_controller { - match_attr = "hisilicon_hi35xx_uart_0";//【必要】必须和device_info.hcs中对应的设备的deviceMatchAttr值一致 - } - controller_0x120a1000 :: uart_controller { - num = 1; - baudrate = 9600; - regPbase = 0x120a1000; - interrupt = 39; - match_attr = "hisilicon_hi35xx_uart_1"; - } - ... - // 【可选】可新增,但需要在 device_info.hcs 添加对应的节点 - } - } - ``` - -3. 完成驱动入口注册之后,最后一步就是以核心层UartHost对象的初始化为核心,包括厂商自定义结构体(传递参数和数据),实例化UartHost成员UartHostMethod(让用户可以通过接口来调用驱动底层函数),实现HdfDriverEntry成员函数(Bind,Init,Release)。 - - 自定义结构体参考。 - - 从驱动的角度看,自定义结构体是参数和数据的载体,而且uart\_config.hcs文件中的数值会被HDF读入通过DeviceResourceIface来初始化结构体成员,一些重要数值也会传递给核心层对象,例如设备号等。 - - ``` - struct UartPl011Port { //接口相关的结构体 - int32_t enable; - unsigned long physBase; //物理地址 - uint32_t irqNum; //中断号 - uint32_t defaultBaudrate;//默认波特率 - uint32_t flags; //标志信号,下面三个宏与之相关 - #define PL011_FLG_IRQ_REQUESTED (1 << 0) - #define PL011_FLG_DMA_RX_REQUESTED (1 << 1) - #define PL011_FLG_DMA_TX_REQUESTED (1 << 2) - struct UartDmaTransfer *rxUdt; //DMA传输相关 - struct UartDriverData *udd; //见下 - }; - struct UartDriverData { //数据传输相关的结构体 - uint32_t num; - uint32_t baudrate; //波特率(可设置) - struct UartAttribute attr; //数据位、停止位等传输属性相关 - struct UartTransfer *rxTransfer; //缓冲区相关,可理解为FIFO结构 - wait_queue_head_t wait; //条件变量相关的排队等待信号 - int32_t count; //数据数量 - int32_t state; //uart控制器状态 - #define UART_STATE_NOT_OPENED 0 - #define UART_STATE_OPENING 1 - #define UART_STATE_USEABLE 2 - #define UART_STATE_SUSPENED 3 - uint32_t flags; //状态标志 - #define UART_FLG_DMA_RX (1 << 0) - #define UART_FLG_DMA_TX (1 << 1) - #define UART_FLG_RD_BLOCK (1 << 2) - RecvNotify recv; //函数指针类型,指向串口数据接收函数 - struct UartOps *ops; //自定义函数指针结构体,详情见device/hisilicon/drivers/uart/uart_pl011.c - void *private; //一般用来存储UartPl011Port首地址,方便调用 - }; - - // UartHost是核心层控制器结构体,其中的成员在Init函数中会被赋值 - struct UartHost { - struct IDeviceIoService service; - struct HdfDeviceObject *device; - uint32_t num; - OsalAtomic atom; - void *priv; //一般存储厂商自定义结构体首地址,方便后者被调用 - struct UartHostMethod *method; //核心层钩子函数,厂商需要实现其成员函数功能并实例化 - }; - ``` - - - UartHost成员回调函数结构体UartHostMethod的实例化,其他成员在Bind函数中初始化。 - - ``` - // uart_hi35xx.c 中的示例:钩子函数的实例化 - struct UartHostMethod g_uartHostMethod = { - .Init = Hi35xxInit, - .Deinit = Hi35xxDeinit, - .Read = Hi35xxRead, - .Write = Hi35xxWrite, - .SetBaud = Hi35xxSetBaud, - .GetBaud = Hi35xxGetBaud, - .SetAttribute = Hi35xxSetAttribute, - .GetAttribute = Hi35xxGetAttribute, - .SetTransMode = Hi35xxSetTransMode, - .pollEvent = Hi35xxPollEvent, - }; - ``` - - - Bind函数参考 - - 入参: - - HdfDeviceObject 这个是整个驱动对外暴露的接口参数,具备 HCS 配置文件的信息。 - - **返回值:** - - HDF\_STATUS相关状态 (下表为部分展示,如需使用其他状态,可见//drivers/framework/include/utils/hdf\_base.h中HDF\_STATUS 定义)。 - - **表 2** Bind函数入参和返回值 - - - - - - - - - - - - - - - - - - - - - - - - - -

状态(值)

-

问题描述

-

HDF_ERR_INVALID_OBJECT

-

控制器对象非法

-

HDF_ERR_MALLOC_FAIL

-

内存分配失败

-

HDF_ERR_INVALID_PARAM

-

参数非法

-

HDF_ERR_IO

-

I/O 错误

-

HDF_SUCCESS

-

初始化成功

-

HDF_FAILURE

-

初始化失败

-
- - 函数说明: - - 初始化自定义结构体对象,初始化UartHost成员。 - - ``` - //uart_hi35xx.c - static int32_t HdfUartDeviceBind(struct HdfDeviceObject *device) - { - ... - return (UartHostCreate(device) == NULL) ? HDF_FAILURE : HDF_SUCCESS;//【必须做】调用核心层函数 UartHostCreate - } - //uart_core.c 核心层 UartHostCreate 函数说明 - struct UartHost *UartHostCreate(struct HdfDeviceObject *device) - { - struct UartHost *host = NULL; //新建 UartHost - ... - host = (struct UartHost *)OsalMemCalloc(sizeof(*host));//分配内存 - ... - host->device = device; //【必要】使HdfDeviceObject与UartHost可以相互转化的前提 - device->service = &(host->service);//【必要】使HdfDeviceObject与UartHost可以相互转化的前提 - host->device->service->Dispatch = UartIoDispatch;//为 service 成员的 Dispatch 方法赋值 - OsalAtomicSet(&host->atom, 0); //原子量初始化或者原子量设置 - host->priv = NULL; - host->method = NULL; - return host; - } - ``` - - - Init函数参考 - - 入参**:** - - HdfDeviceObject 是整个驱动对外暴露的接口参数,具备 HCS 配置文件的信息。 - - 返回值: - - HDF\_STATUS相关状态。 - - 函数说明: - - 初始化自定义结构体对象,初始化UartHost成员,调用核心层UartAddDev函数,接入VFS。 - - ``` - int32_t HdfUartDeviceInit(struct HdfDeviceObject *device) - { - int32_t ret; - struct UartHost *host = NULL; - HDF_LOGI("%s: entry", __func__); - ... - host = UartHostFromDevice(device);//通过service成员后强制转为UartHost,赋值是在Bind函数中 - ... - ret = Hi35xxAttach(host, device); //完成UartHost对象的初始化,见下 - ... - host->method = &g_uartHostMethod; //UartHostMethod的实例化对象的挂载 - return ret; - } - //完成 UartHost 对象的初始化 - static int32_t Hi35xxAttach(struct UartHost *host, struct HdfDeviceObject *device) - { - int32_t ret; - //udd 和 port 对象是厂商自定义的结构体对象,可根据需要实现相关功能 - struct UartDriverData *udd = NULL; - struct UartPl011Port *port = NULL; - ... - // 【必要相关功能】步骤【1】~【7】主要实现对 udd 对象的实例化赋值,然后赋值给核心层UartHost对象上 - udd = (struct UartDriverData *)OsalMemCalloc(sizeof(*udd));//【1】 - ... - port = (struct UartPl011Port *)OsalMemCalloc(sizeof(struct UartPl011Port));//【2】 - ... - udd->ops = Pl011GetOps();//【3】设备开启、关闭、属性设置、发送操作等函数挂载 - udd->recv = PL011UartRecvNotify;//【4】数据接收通知函数(条件锁机制)挂载 - udd->count = 0; //【5】 - port->udd = udd; //【6】使UartPl011Port与UartDriverData可以相互转化的前提 - ret = UartGetConfigFromHcs(port, device->property);//【必要】 此步骤是将 HdfDeviceObject 的属性传递给厂商自定义结构体 - // 用于相关操作,示例代码见下 - ... - udd->private = port; //【7】 - - host->priv = udd; //【必要】使UartHost与UartDriverData可以相互转化的前提 - host->num = udd->num;//【必要】uart 设备号 - UartAddDev(host); //【必要】核心层uart_dev.c 中的函数,作用:注册了一个字符设备节点到vfs, 这样从用户态可以通过这个虚拟文件节点访问uart - return HDF_SUCCESS; - } - - static int32_t UartGetConfigFromHcs(struct UartPl011Port *port, const struct DeviceResourceNode *node) - { - uint32_t tmp, regPbase, iomemCount; - struct UartDriverData *udd = port->udd; - struct DeviceResourceIface *iface = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); - ... - //通过请求参数提取相应的值,并赋值给厂商自定义的结构体 - if (iface->GetUint32(node, "num", &udd->num, 0) != HDF_SUCCESS) { - HDF_LOGE("%s: read busNum fail", __func__); - return HDF_FAILURE; - } - ... - return 0; - } - ``` - - - Release函数参考 - - 入参: - - HdfDeviceObject 是整个驱动对外暴露的接口参数,具备 HCS 配置文件的信息。 - - 返回值: - - 无。 - - 函数说明: - - 该函数需要在驱动入口结构体中赋值给 Release 接口, 当HDF框架调用Init函数初始化驱动失败时,可以调用 Release 释放驱动资源, 该函数中需包含释放内存和删除控制器等操作。所有强制转换获取相应对象的操作**前提**是在Init函数中具备对应赋值的操作。 - - ``` - void HdfUartDeviceRelease(struct HdfDeviceObject *device) - { - struct UartHost *host = NULL; - ... - host = UartHostFromDevice(device);//这里有HdfDeviceObject到UartHost的强制转化,通过service成员,赋值见Bind函数 - ... - if (host->priv != NULL) { - Hi35xxDetach(host); //厂商自定义的内存释放函数,见下 - } - UartHostDestroy(host); //调用核心层函数释放host - } - - static void Hi35xxDetach(struct UartHost *host) - { - struct UartDriverData *udd = NULL; - struct UartPl011Port *port = NULL; - ... - udd = host->priv; //这里有UartHost到UartDriverData的转化 - ... - UartRemoveDev(host);//VFS注销 - port = udd->private;//这里有UartDriverData到UartPl011Port的转化 - if (port != NULL) { - if (port->physBase != 0) { - OsalIoUnmap((void *)port->physBase);//地址反映射 - } - (void)OsalMemFree(port); - udd->private = NULL; - } - (void)OsalMemFree(udd);//释放UartDriverData - host->priv = NULL; - } - ``` - - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/14.WatchDog.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/14.WatchDog.md" deleted file mode 100644 index e2647487c0eef52aada29e51015953c018fdfc11..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221/14.WatchDog.md" +++ /dev/null @@ -1,378 +0,0 @@ ---- -title: WatchDog -permalink: /pages/010502020e -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:24 ---- -# WatchDog - -- [概述](#section1315827527160117) -- [接口说明](#section752964871810) -- [开发步骤](#section477974542160117) -- [开发实例](#section1832270347160117) - -## 概述 - -看门狗(Watchdog),又叫看门狗计时器(Watchdog timer),是一种硬件的计时设备,在HDF框架中,Watchdog接口适配模式采用独立服务模式,在这种模式下,每一个设备对象会独立发布一个设备服务来处理外部访问,设备管理器收到API的访问请求之后,通过提取该请求的参数,达到调用实际设备对象的相应内部方法的目的。独立服务模式可以直接借助HDFDeviceManager的服务管理能力,但需要为每个设备单独配置设备节点,增加内存占用。 - -**图 1** Watchdog独立服务模式结构图 -![](/images/device-dev/driver/figures/独立服务模式结构图.png "Watchdog独立服务模式结构图") - -## 接口说明 - -WatchdogMethod定义: - -``` -struct WatchdogMethod { - int32_t (*getStatus)(struct WatchdogCntlr *wdt, int32_t *status); - int32_t (*setTimeout)(struct WatchdogCntlr *wdt, uint32_t seconds); - int32_t (*getTimeout)(struct WatchdogCntlr *wdt, uint32_t *seconds); - int32_t (*start)(struct WatchdogCntlr *wdt); - int32_t (*stop)(struct WatchdogCntlr *wdt); - int32_t (*feed)(struct WatchdogCntlr *wdt); - int32_t (*getPriv)(struct WatchdogCntlr *wdt); //【可选】如果WatchdogCntlr 中的priv成员存在,则按需实例化 - void (*releasePriv)(struct WatchdogCntlr *wdt);//【可选】 -}; -``` - -**表 1** WatchdogMethod成员的回调函数功能说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

成员函数

-

入参

-

出参

-

返回值

-

功能

-

getStatus

-

wdt: 结构体指针,核心层WDG控制器;

-

status: int32_t指针,表示狗的状态(打开或关闭);

-

HDF_STATUS相关状态

-

获取看门狗所处的状态

-

start

-

wdt: 结构体指针,核心层WDG控制器;

-

-

HDF_STATUS相关状态

-

打开开门狗

-

stop

-

wdt: 结构体指针,核心层WDG控制器;

-

-

HDF_STATUS相关状态

-

关闭开门狗

-

setTimeout

-

wdt: 结构体指针,核心层WDG控制器;seconds: uint32_t,时间传入值;

-

-

HDF_STATUS相关状态

-

设置超时时间值,单位秒,需要保证看门狗实际运行的时间符合该值

-

getTimeout

-

wdt: 结构体指针,核心层WDG控制器;

-

seconds: uint32_t,传出的时间值

-

HDF_STATUS相关状态

-

回读设置的超时时间值

-

feed

-

wdt: 结构体指针,核心层WDG控制器;

-

-

HDF_STATUS相关状态

-

喂狗

-
- -## 开发步骤 - -Watchdog模块适配HDF框架的三个环节是配置属性文件,实例化驱动入口,以及实例化核心层接口函数。 - -1. **实例化驱动入口:** - - 实例化HdfDriverEntry结构体成员。 - - 调用HDF\_INIT将HdfDriverEntry实例化对象注册到HDF框架中。 - -2. **配置属性文件:** - - 在device\_info.hcs文件中添加deviceNode描述。 - - 【可选】添加watchdog\_config.hcs器件属性文件。 - -3. **实例化Watchdog控制器对象:** - - 初始化WatchdogCntlr成员。 - - 实例化WatchdogCntlr成员WatchdogMethod。 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >实例化WatchdogCntlr成员WatchdogMethod,其定义和成员说明见[接口说明](#section752964871810)。 - - -4. **驱动调试:** - - 【可选】针对新增驱动程序,建议验证驱动基本功能,例如挂载后的信息反馈,超时时间设置的成功与否等。 - - -## 开发实例 - -下方将以watchdog\_hi35xx.c为示例,展示需要厂商提供哪些内容来完整实现设备功能。 - -1. 驱动开发首先需要实例化驱动入口,驱动入口必须为HdfDriverEntry(在 hdf\_device\_desc.h 中定义)类型的全局变量,且moduleName要和device\_info.hcs中保持一致。HDF框架会将所有加载的驱动的HdfDriverEntry对象首地址汇总,形成一个类似数组的段地址空间,方便上层调用。 - - 一般在加载驱动时HDF会先调用Bind函数,再调用Init函数加载该驱动。当Init调用异常时,HDF框架会调用Release释放驱动资源并退出。 - - Watchdog驱动入口参考: - - ``` - struct HdfDriverEntry g_watchdogDriverEntry = { - .moduleVersion = 1, - .Bind = Hi35xxWatchdogBind, //见Bind参考 - .Init = Hi35xxWatchdogInit, //见Init参考 - .Release = Hi35xxWatchdogRelease, //见Release参考 - .moduleName = "HDF_PLATFORM_WATCHDOG",//【必要且与HCS文件中里面的moduleName匹配】 - }; - HDF_INIT(g_watchdogDriverEntry);//调用HDF_INIT将驱动入口注册到HDF框架中 - ``` - -2. 完成驱动入口注册之后,下一步请在device\_info.hcs文件中添加deviceNode信息,并在 watchdog\_config.hcs 中配置器件属性。deviceNode信息与驱动入口注册相关,器件属性值与核心层WatchdogCntlr 成员的默认值或限制范围有密切关系。 - - 本例只有一个Watchdog控制器,如有多个器件信息,则需要在device\_info文件增加deviceNode信息,以及在watchdog\_config文件中增加对应的器件属性。 - - - device\_info.hcs 配置参考。 - - ``` - root { - device_info { - match_attr = "hdf_manager"; - device_watchdog :: device { // 设备节点 - device0 :: deviceNode { // 驱动的DeviceNode节点 - policy = 1; // policy字段是驱动服务发布的策略,如果需要面向用户态,则为2 - priority = 20; // 驱动启动优先级 - permission = 0644; // 驱动创建设备节点权限 - moduleName = "HDF_PLATFORM_WATCHDOG"; - // 【必要】驱动名称,该字段的值必须和驱动入口结构的moduleName值一致 - serviceName = "HDF_PLATFORM_WATCHDOG_0"; - // 【必要且唯一】驱动对外发布服务的名称 - deviceMatchAttr = "hisilicon_hi35xx_watchdog_0"; - // 【必要】驱动私有数据匹配的关键字,必须和驱动私有数据配置表中的match_attr值相等 - } - } - } - } - ``` - - - watchdog\_config.hcs 配置参考。 - - ``` - root { - platform { - template watchdog_controller {//【必要】模板配置,继承该模板的节点如果使用模板中的默认值,则节点字段可以缺省 - id = 0; - match_attr = ""; - regBase = 0x12050000; //【必要】地址映射需要 - regStep = 0x1000; //【必要】地址映射需要 - } - controller_0x12050000 :: watchdog_controller {//【必要】是作为设备驱动私有数据匹配的关键字 - match_attr = "hisilicon_hi35xx_watchdog_0"; //【必要】必须和device_info.hcs中的deviceMatchAttr值一致 - } - //存在多个 watchdog 时【必须】添加,否则不用 - ... - } - } - ``` - -3. 完成驱动入口注册之后,最后一步就是以核心层WatchdogCntlr对象的初始化为核心,包括厂商自定义结构体(传递参数和数据),实例化WatchdogCntlr成员WatchdogMethod(让用户可以通过接口来调用驱动底层函数),实现HdfDriverEntry成员函数(Bind,Init,Release)。 - - 自定义结构体参考。 - - 从驱动的角度看,自定义结构体是参数和数据的载体,而且watchdog\_config.hcs文件中的数值会被HDF读入通过DeviceResourceIface来初始化结构体成员,其中一些重要数值也会传递给核心层WatchdogCntlr对象,例如索引、管脚数等。 - - ``` - struct Hi35xxWatchdog { - struct WatchdogCntlr wdt; //【必要】是链接上下层的载体,具体描述见下面 - OsalSpinlock lock; - volatile unsigned char *regBase;//【必要】地址映射需要 - uint32_t phyBase; //【必要】地址映射需要 - uint32_t regStep; //【必要】地址映射需要 - }; - //WatchdogCntlr是核心层控制器结构体,其中的成员在Init函数中会被赋值 - struct WatchdogCntlr { - struct IDeviceIoService service;//驱动服务 - struct HdfDeviceObject *device; //驱动设备 - OsalSpinlock lock; //此变量在HDF核心层被调用来实现自旋锁功能 - struct WatchdogMethod *ops; //接口回调函数 - int16_t wdtId; //WDG设备的识别id - void *priv; //存储指针 - }; - ``` - - - WatchdogCntlr成员回调函数结构体WatchdogMethod的实例化,其他成员在Init和Bind函数中初始化。 - - ``` - static struct WatchdogMethod g_method = { - .getStatus = Hi35xxWatchdogGetStatus, - .start = Hi35xxWatchdogStart, - .stop = Hi35xxWatchdogStop, - .setTimeout = Hi35xxWatchdogSetTimeout, - .getTimeout = Hi35xxWatchdogGetTimeout, - .feed = Hi35xxWatchdogFeed, - }; - ``` - - - Init函数和Bind函数参考 - - 入参**:** - - HdfDeviceObject :HDF框架给每一个驱动创建的设备对象,用来保存设备相关的私有数据和服务接口。 - - 返回值**:** - - HDF\_STATUS相关状态 (下表为部分展示,如需使用其他状态,可见//drivers/framework/include/utils/hdf\_base.h中HDF\_STATUS 定义)。 - - **表 2** Init函数和Bind函数入参和返回值 - - - - - - - - - - - - - - - - - - - - - - -

状态(值)

-

问题描述

-

HDF_ERR_INVALID_OBJECT

-

找不到 WDG 设备

-

HDF_ERR_MALLOC_FAIL

-

内存分配失败

-

HDF_ERR_IO

-

I/O 错误

-

HDF_SUCCESS

-

初始化成功

-

HDF_FAILURE

-

初始化失败

-
- - 函数说明**:** - - 初始化自定义结构体对象,初始化WatchdogCntlr成员,调用核心层WatchdogCntlrAdd函数。 - - ``` - //一般而言,Init函数需要根据入参(HdfDeviceObject对象)的属性值初始化Hi35xxWatchdog结构体的成员, - //但本例中是在bind函数中实现的 - static int32_t Hi35xxWatchdogInit(struct HdfDeviceObject *device) - { - (void)device; - return HDF_SUCCESS; - } - - static int32_t Hi35xxWatchdogBind(struct HdfDeviceObject *device) - { - int32_t ret; - struct Hi35xxWatchdog *hwdt = NULL; - ... - hwdt = (struct Hi35xxWatchdog *)OsalMemCalloc(sizeof(*hwdt));//Hi35xxWatchdog 结构体的内存申请 - ... - hwdt->regBase = OsalIoRemap(hwdt->phyBase, hwdt->regStep); //地址映射 - ... - hwdt->wdt.priv = (void *)device->property;//【可选】此处是将设备属性的内容赋值给priv成员,但后续没有调用 priv 成员, - // 如果需要用到priv成员,需要额外实例化WatchdogMethod的getPriv和releasePriv成员函数 - hwdt->wdt.ops = &g_method; //【必要】将实例化后的对象赋值给ops成员,就可以实现顶层调用WatchdogMethod成员函数 - hwdt->wdt.device = device; //【必要】这是为了方便HdfDeviceObject与WatchdogcCntlr相互转化 - ret = WatchdogCntlrAdd(&hwdt->wdt); //【必要】调用此函数初始化核心层结构体,返回成功信号后驱动才完全接入平台核心层 - if (ret != HDF_SUCCESS) { //不成功的话,需要释放Init函数申请的资源 - OsalIoUnmap((void *)hwdt->regBase); - OsalMemFree(hwdt); - return ret; - } - return HDF_SUCCESS; - } - ``` - - - Release函数参考 - - 入参: - - HdfDeviceObject :HDF框架给每一个驱动创建的设备对象,用来保存设备相关的私有数据和服务接口。 - - 返回值**:** - - 无。 - - 函数说明**:** - - 该函数需要在驱动入口结构体中赋值给Release,当HDF框架调用Init函数初始化驱动失败时,可以调用Release释放驱动资源。该函数中需包含释放内存和删除控制器等操作。所有强制转换获取相应对象的操作**前提**是在Init函数中具备对应赋值的操作。 - - ``` - static void Hi35xxWatchdogRelease(struct HdfDeviceObject *device) - { - struct WatchdogCntlr *wdt = NULL; - struct Hi35xxWatchdog *hwdt = NULL; - ... - wdt = WatchdogCntlrFromDevice(device);//这里会通过service成员将HdfDeviceObject转化为WatchdogCntlr - //return (device == NULL) ? NULL : (struct WatchdogCntlr *)device->service; - if (wdt == NULL) { - return; - } - WatchdogCntlrRemove(wdt); //核心层函数,实际执行wdt->device->service = NULL以及cntlr->lock的释放 - hwdt = (struct Hi35xxWatchdog *)wdt; //这里将WatchdogCntlr转化为HimciHost - if (hwdt->regBase != NULL) { //解除地址映射 - OsalIoUnmap((void *)hwdt->regBase); - hwdt->regBase = NULL; - } - OsalMemFree(hwdt); //释放厂商自定义对象占用的内存 - } - ``` - - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/03.\345\271\263\345\217\260\351\251\261\345\212\250\344\275\277\347\224\250/01.ADC.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/03.\345\271\263\345\217\260\351\251\261\345\212\250\344\275\277\347\224\250/01.ADC.md" deleted file mode 100644 index 9613a8f5c14d6d1abfe439364c626da5b1901dc8..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/03.\345\271\263\345\217\260\351\251\261\345\212\250\344\275\277\347\224\250/01.ADC.md" +++ /dev/null @@ -1,278 +0,0 @@ ---- -title: ADC -permalink: /pages/0105020301 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:24 ---- -# ADC - -- [概述](#section1) -- [接口说明](#section2) -- [使用指导](#section3) - - [使用流程](#section4) - - [打开ADC设备](#section5) - - [读取AD转换结果](#section6) - - [关闭ADC设备](#section7) - -- [使用实例](#section8) - -## 概述 - -- ADC(Analog to Digital Converter),即模拟-数字转换器,是一种将模拟信号转换成对应数字信号的设备。 - -- ADC接口定义了完成ADC传输的通用方法集合,包括: - - ADC设备管理:打开或关闭ADC设备。 - - ADC读取转换结果:读取AD转换结果。 - - **图 1** ADC物理连线示意图 - ![](/images/device-dev/driver/figures/ADC物理连线示意图.png "ADC物理连线示意图") - -## 接口说明 - -**表 1** ADC驱动API接口功能介绍 - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名

-

描述

-

ADC设备管理接口

-

AdcOpen

-
打开ADC设备

-

AdcClose

-

关闭ADC设备

-

ADC读取转换结果接口

-

AdcRead

-

读取AD转换结果值

-
- -## 使用指导 - -### 使用流程 - -使用ADC设备的一般流程如[图2](#fig2)所示。 - - **图 2** ADC使用流程图 -![](/images/device-dev/driver/figures/ADC使用流程图.png "ADC使用流程图") - -### 打开ADC设备 - -在进行AD转换之前,首先要调用AdcOpen打开ADC设备。 - -```c -DevHandle AdcOpen(int16_t number); -``` - -**表 2** AdcOpen参数和返回值描述 - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

number

-

ADC设备号

-

返回值

-

返回值描述

-

NULL

-

打开ADC设备失败

-

设备句柄

-

打开的ADC设备句柄

-
- -假设系统中存在2个ADC设备,编号从0到1,那么我们现在打开1号设备。 - -```c -DevHandle adcHandle = NULL; /* ADC设备句柄 / - -/* 打开ADC设备 */ -adcHandle = AdcOpen(1); -if (adcHandle == NULL) { - HDF_LOGE("AdcOpen: failed\n"); - return; -} -``` - -### 读取AD转换结果 - -```c -int32_t AdcRead(DevHandle handle, uint32_t channel, uint32_t *val); -``` - -**表 3** AdcRead参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

ADC设备句柄

-

channel

-

ADC设备通道号

-

val

-

AD转换结果

-

返回值

-

返回值描述

-

0

-

读取成功

-

负数

-

读取失败

-
- -### 关闭ADC设备 - -ADC通信完成之后,需要关闭ADC设备。 -```c -void AdcClose(DevHandle handle); -``` -**表 4** AdcClose参数和返回值描述 - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

ADC设备句柄

-

返回值

-

返回值描述

-

-

-
- -关闭ADC设备示例: - -```c -AdcClose(adcHandle); /* 关闭ADC设备 */ -``` - -## 使用实例 - -本例程以操作开发板上的ADC设备为例,详细展示ADC接口的完整使用流程。 - -本例拟对Hi3516DV300某开发板上ADC设备进行简单的读取操作,基本硬件信息如下: - -- SOC:hi3516dv300。 - -- 原理图信息:电位器挂接在0号ADC设备1通道下。 - -本例程对测试ADC进行连续读取操作,测试ADC功能是否正常。 - -示例如下: - -```c -#include "adc_if.h" /* ADC标准接口头文件 */ -#include "hdf_log.h" /* 标准日志打印头文件 */ - -/* 设备号0,通道号1 */ -#define ADC_DEVICE_NUM 0 -#define ADC_CHANNEL_NUM 1 - -/* ADC例程总入口 */ -static int32_t TestCaseAdc(void) -{ - int32_t i; - int32_t ret; - DevHandle adcHandle; - uint32_t Readbuf[30] = {0}; - - /* 打开ADC设备 */ - adcHandle = AdcOpen(ADC_DEVICE_NUM); - if (adcHandle == NULL) { - HDF_LOGE("%s: Open ADC%u fail!", __func__, ADC_DEVICE_NUM); - return -1; - } - - /* 连续进行30次AD转换并读取转换结果 */ - for (i = 0; i < 30; i++) { - ret = AdcRead(adcHandle, ADC_CHANNEL_NUM, &Readbuf[i]); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: tp ADC write reg fail!:%d", __func__, ret); - AdcClose(adcHandle); - return -1; - } - } - HDF_LOGI("%s: ADC read successful!", __func__); - - /* 访问完毕关闭ADC设备 */ - AdcClose(adcHandle); - - return 0; -} -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/03.\345\271\263\345\217\260\351\251\261\345\212\250\344\275\277\347\224\250/02.GPIO.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/03.\345\271\263\345\217\260\351\251\261\345\212\250\344\275\277\347\224\250/02.GPIO.md" deleted file mode 100644 index 197d94cca81f59f2587855dca641d53ca399fe0f..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/03.\345\271\263\345\217\260\351\251\261\345\212\250\344\275\277\347\224\250/02.GPIO.md" +++ /dev/null @@ -1,570 +0,0 @@ ---- -title: GPIO -permalink: /pages/0105020302 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:24 ---- -# GPIO - -- [概述](#section1635911016188) -- [接口说明](#section589913442203) -- [使用指导](#section259614242196) - - [使用流程](#section103477714216) - - [确定GPIO管脚号](#section370083272117) - - [使用API操作GPIO管脚](#section13604050132118) - -- [使用实例](#section25941262111) - -## 概述 - -GPIO(General-purpose input/output)即通用型输入输出。通常,GPIO控制器通过分组的方式管理所有GPIO管脚,每组GPIO有一个或多个寄存器与之关联,通过读写寄存器完成对GPIO管脚的操作。 - -GPIO接口定义了操作GPIO管脚的标准方法集合,包括: - -- 设置管脚方向: 方向可以是输入或者输出\(暂不支持高阻态\) - -- 读写管脚电平值: 电平值可以是低电平或高电平 -- 设置管脚中断服务函数:设置一个管脚的中断响应函数,以及中断触发方式 -- 使能和禁止管脚中断:禁止或使能管脚中断 - -## 接口说明 - -**表 1** GPIO驱动API接口功能介绍 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名

-

描述

-

GPIO读写

-

GpioRead

-

读管脚电平值

-

GpioWrite

-

写管脚电平值

-

GPIO配置

-

GpioSetDir

-

设置管脚方向

-

GpioGetDir

-

获取管脚方向

-

GPIO中断设置

-

GpioSetIrq

-

设置管脚对应的中断服务函数

-

GpioUnSetIrq

-

取消管脚对应的中断服务函数

-

GpioEnableIrq

-

使能管脚中断

-

GpioDisableIrq

-

禁止管脚中断

-
- ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->本文涉及的所有接口,仅限内核态使用,不支持在用户态使用。 - -## 使用指导 - -### 使用流程 - -GPIO标准API通过GPIO管脚号来操作指定管脚,使用GPIO的一般流程如[图1](#fig16151101653713)所示。 - -**图 1** GPIO使用流程图 -![](/images/device-dev/driver/figures/GPIO使用流程图.png "GPIO使用流程图") - -### 确定GPIO管脚号 - -不同SOC芯片由于其GPIO控制器型号、参数、以及控制器驱动的不同,GPIO管脚号的换算方式不一样。 - -- Hi3516DV300 - - 控制器管理12组GPIO管脚,每组8个。 - - GPIO号 = GPIO组索引 \(0\~11\) \* 每组GPIO管脚数\(8\) + 组内偏移 - - 举例:GPIO10\_3的GPIO号 = 10 \* 8 + 3 = 83 - -- Hi3518EV300 - - 控制器管理10组GPIO管脚,每组10个。 - - GPIO号 = GPIO组索引 \(0\~9\) \* 每组GPIO管脚数\(10\) + 组内偏移 - - 举例:GPIO7\_3的GPIO管脚号 = 7 \* 10 + 3 = 73 - - -### 使用API操作GPIO管脚 - -- 设置GPIO管脚方向 - - 在进行GPIO管脚读写前,需要先通过如下函数设置GPIO管脚方向: - - int32\_t GpioSetDir\(uint16\_t gpio, uint16\_t dir\); - - **表 2** GpioSetDir参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

gpio

-

待设置的GPIO管脚号

-

dir

-

待设置的方向值

-

返回值

-

返回值描述

-

0

-

设置成功

-

负数

-

设置失败

-
- - -- 读写GPIO管脚 - - 如果要读取一个GPIO管脚电平,通过以下函数完成: - - int32\_t GpioRead\(uint16\_t gpio, uint16\_t \*val\); - - **表 3** GpioRead参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

gpio

-

待读取的GPIO管脚号

-

val

-

接收读取电平值的指针

-

返回值

-

返回值描述

-

0

-

读取成功

-

负数

-

读取失败

-
- - 如果要向GPIO管脚写入电平值,通过以下函数完成: - - int32\_t GpioWrite\(uint16\_t gpio, uint16\_t val\); - - **表 4** GpioWrite参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

gpio

-

待写入的GPIO管脚号

-

val

-

待写入的电平值

-

返回值

-

返回值描述

-

0

-

写入成功

-

负数

-

写入失败

-
- - 示例代码: - - ``` - int32_t ret; - uint16_t val; - /* 将3号GPIO管脚配置为输出 */ - ret = GpioSetDir(3, GPIO_DIR_OUT); - if (ret != 0) { - HDF_LOGE("GpioSerDir: failed, ret %d\n", ret); - return; - } - /* 向3号GPIO管脚写入低电平GPIO_VAL_LOW */ - ret = GpioWrite(3, GPIO_VAL_LOW); - if (ret != 0) { - HDF_LOGE("GpioWrite: failed, ret %d\n", ret); - return; - } - /* 将6号GPIO管脚配置为输入 */ - ret = GpioSetDir(6, GPIO_DIR_IN); - if (ret != 0) { - HDF_LOGE("GpioSetDir: failed, ret %d\n", ret); - return; - } - /* 读取6号GPIO管脚的电平值 */ - ret = GpioRead(6, &val); - ``` - - -- 设置GPIO中断 - - 如果要为一个GPIO管脚设置中断响应程序,使用如下函数: - - int32\_t GpioSetIrq\(uint16\_t gpio, uint16\_t mode, GpioIrqFunc func, void \*arg\); - - **表 5** GpioSetIrq参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

gpio

-

GPIO管脚号

-

mode

-

中断触发模式

-

func

-

中断服务程序

-

arg

-

传递给中断服务程序的入参

-

返回值

-

返回值描述

-

0

-

设置成功

-

负数

-

设置失败

-
- - >![](/images/device-dev/public_sys-resources/icon-caution.gif) **注意:** - >同一时间,只能为某个GPIO管脚设置一个中断服务函数,如果重复调用GpioSetIrq函数,则之前设置的中断服务函数会被取代。 - - 当不再需要响应中断服务函数时,使用如下函数取消中断设置: - - int32\_t GpioUnSetIrq\(uint16\_t gpio\); - - **表 6** GpioUnSetIrq参数和返回值描述 - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

gpio

-

GPIO管脚号

-

返回值

-

返回值描述

-

0

-

取消成功

-

负数

-

取消失败

-
- - 在中断服务程序设置完成后,还需要先通过如下函数使能GPIO管脚的中断: - - int32\_t GpioEnableIrq\(uint16\_t gpio\); - - **表 7** GpioEnableIrq参数和返回值描述 - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

gpio

-

GPIO管脚号

-

返回值

-

返回值描述

-

0

-

使能成功

-

负数

-

使能失败

-
- - >![](/images/device-dev/public_sys-resources/icon-caution.gif) **注意:** - >必须通过此函数使能管脚中断,之前设置的中断服务函数才能被正确响应。 - - 如果要临时屏蔽此中断,可以通过如下函数禁止GPIO管脚中断: - - int32\_t GpioDisableIrq\(uint16\_t gpio\); - - **表 8** GpioDisableIrq参数和返回值描述 - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

gpio

-

GPIO管脚号

-

返回值

-

返回值描述

-

0

-

禁止成功

-

负数

-

禁止失败

-
- - 示例代码: - - ``` - /* 中断服务函数 - */ - int32_t MyCallBackFunc(uint16_t gpio, void *data) - { - HDF_LOGI("%s: gpio:%u interrupt service in! data=%p\n", __func__, gpio, data); - return 0; - } - - int32_t ret; - /* 设置中断服务程序为MyCallBackFunc,入参为NULL,中断触发模式为上升沿触发 */ - ret = GpioSetIrq(3, OSAL_IRQF_TRIGGER_RISING, MyCallBackFunc, NULL); - if (ret != 0) { - HDF_LOGE("GpioSetIrq: failed, ret %d\n", ret); - return; - } - - /* 使能3号GPIO管脚中断 */ - ret = GpioEnableIrq(3); - if (ret != 0) { - HDF_LOGE("GpioEnableIrq: failed, ret %d\n", ret); - return; - } - - /* 禁止3号GPIO管脚中断 */ - ret = GpioDisableIrq(3); - if (ret != 0) { - HDF_LOGE("GpioDisableIrq: failed, ret %d\n", ret); - return; - } - - /* 取消3号GPIO管脚中断服务程序 */ - ret = GpioUnSetIrq(3); - if (ret != 0) { - HDF_LOGE("GpioUnSetIrq: failed, ret %d\n", ret); - return; - } - ``` - - -## 使用实例 - -本实例程序中,我们将测试一个GPIO管脚的中断触发:为管脚设置中断服务函数,触发方式为边沿触发,然后通过交替写高低电平到管脚,产生电平波动,制造触发条件,观察中断服务函数的执行。 - -首先需要选取一个空闲的GPIO管脚,本例程基于Hi3516DV300某开发板,GPIO管脚选择GPIO10\_3,换算成GPIO号为83。 - -读者可以根据自己使用的开发板,参考其原理图,选择一个空闲的GPIO管脚即可。 - -``` -#include "gpio_if.h" -#include "hdf_log.h" -#include "osal_irq.h" -#include "osal_time.h" - -static uint32_t g_irqCnt; - -/* 中断服务函数*/ -static int32_t TestCaseGpioIrqHandler(uint16_t gpio, void *data) -{ - HDF_LOGE("%s: irq triggered! on gpio:%u, data=%p", __func__, gpio, data); - g_irqCnt++; /* 如果中断服务函数触发执行,则将全局中断计数加1 */ - return GpioDisableIrq(gpio); -} - -/* 测试用例函数 */ -static int32_t TestCaseGpioIrqEdge(void) -{ - int32_t ret; - uint16_t valRead; - uint16_t mode; - uint16_t gpio = 83; /* 待测试的GPIO管脚号 */ - uint32_t timeout; - - /* 将管脚方向设置为输出 */ - ret = GpioSetDir(gpio, GPIO_DIR_OUT); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: set dir fail! ret:%d\n", __func__, ret); - return ret; - } - - /* 先禁止该管脚中断 */ - ret = GpioDisableIrq(gpio); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: disable irq fail! ret:%d\n", __func__, ret); - return ret; - } - - /* 为管脚设置中断服务函数,触发模式为上升沿和下降沿共同触发 */ - mode = OSAL_IRQF_TRIGGER_RISING | OSAL_IRQF_TRIGGER_FALLING; - HDF_LOGE("%s: mode:%0x\n", __func__, mode); - ret = GpioSetIrq(gpio, mode, TestCaseGpioIrqHandler, NULL); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: set irq fail! ret:%d\n", __func__, ret); - return ret; - } - - /* 使能此管脚中断 */ - ret = GpioEnableIrq(gpio); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: enable irq fail! ret:%d\n", __func__, ret); - (void)GpioUnSetIrq(gpio); - return ret; - } - - g_irqCnt = 0; /* 清除全局计数器 */ - timeout = 0; /* 等待时间清零 */ - /* 等待此管脚中断服务函数触发,等待超时时间为1000毫秒 */ - while (g_irqCnt <= 0 && timeout < 1000) { - (void)GpioRead(gpio, &valRead); - (void)GpioWrite(gpio, (valRead == GPIO_VAL_LOW) ? GPIO_VAL_HIGH : GPIO_VAL_LOW); - HDF_LOGE("%s: wait irq timeout:%u\n", __func__, timeout); - OsalMDelay(200); /* wait for irq trigger */ - timeout += 200; - } - (void)GpioUnSetIrq(gpio); - return (g_irqCnt > 0) ? HDF_SUCCESS : HDF_FAILURE; -} -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/03.\345\271\263\345\217\260\351\251\261\345\212\250\344\275\277\347\224\250/03.HDMI.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/03.\345\271\263\345\217\260\351\251\261\345\212\250\344\275\277\347\224\250/03.HDMI.md" deleted file mode 100644 index 02e8a41ec9a1ce45dc80a9b110e9b82ae7754b25..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/03.\345\271\263\345\217\260\351\251\261\345\212\250\344\275\277\347\224\250/03.HDMI.md" +++ /dev/null @@ -1,1016 +0,0 @@ ---- -title: HDMI -permalink: /pages/0105020303 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:24 ---- -# HDMI - -- [概述](#section1) -- [接口说明](#section2) -- [使用指导](#section3) - - [使用流程](#section4) - - [打开HDMI控制器](#section5) - - [注册热插拔回调函数](#section6) - - [读取EDID](#section7) - - [设置属性](#section8) - - [启动HDMI传输](#section10) - - [停止HDMI传输](#section11) - - [注销热插拔回调函数](#section12) - - [关闭HDMI控制器](#section13) - -- [使用实例](#section14) - -## 概述 - -- HDMI(High-Definition Multiface Interface)是Hitachi, Panasonic, Philips, SiliconImage, Sony, Thomson, Toshiba共同发布的一款音视频传输协议。 -- HDMI以主从方式工作,通常有一个Source端和一个Sink端。 -- HDMI接口定义了完成HDMI传输的通用方法集合,包括: - - - HDMI控制器管理:打开或关闭HDMI控制器 - - HDMI启动/停止传输:启动或停止HDMI传输 - - HDMI控制器设置:设置音频、视频及HDR属性,设置色彩深度、声音图像消隐等 - - HDMI读取EDID:读取Sink端原始的EDID数据 - - HDMI热插拔:注册/注销热插拔回调函数 -- HDMI物理连接如[图1](#fig1)所示: - **图 1** HDMI物理连线示意图 - ![](/images/device-dev/driver/figures/HDMI物理连线示意图.png "HDMI物理连线示意图") - -## 接口说明 - -**表 1** HDMI驱动API接口功能介绍 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名

-

描述

-

HDMI控制器管理接口

-

HdmiOpen

-
打开HDMI控制器

-

HdmiClose

-

关闭HDMI控制器

-

启动/停止HDMI传输接口

-

HdmiStart

-
启动HDMI传输

-

HdmiStop

-

停止HDMI传输

-

HDMI控制器设置接口

-

HdmiAvmuteSet

-
HDMI声音图像消隐设置

-

HdmiDeepColorSet

-

设置色彩深度

-

HdmiDeepColorGet

-

获取色彩深度

-

HdmiSetVideoAttribute

-

设置视频属性

-

HdmiSetAudioAttribute

-

设置音频属性

-

HdmiSetHdrAttribute

-

设置HDR属性

-

EDID获取接口

-

HdmiReadSinkEdid

-
HDMI读取Sink端原始EDID数据

-

HDMI热插拔相关接口

-

HdmiRegisterHpdCallbackFunc

-
注册HDMI热插拔检测回调函数

-

HdmiUnregisterHpdCallbackFunc

-

注销HDMI热插拔检测回调函数

-
- -## 使用指导 - -### 使用流程 - -使用HDMI设备的一般流程如[图2](#fig2)所示。 - -**图 2** HDMI设备使用流程图 -![](/images/device-dev/driver/figures/HDMI使用流程图.png "HDMI使用流程图") - -### 打开HDMI控制器 - -在进行HDMI通信前,首先要调用HdmiOpen打开HDMI控制器。 - -```c -DevHandle HdmiOpen(int16_t number); -``` - -**表 2** HdmiOpen参数和返回值描述 - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

number

-

HDMI控制器号

-

返回值

-

返回值描述

-

NULL

-

打开HDMI控制器失败

-

控制器句柄

-

打开的HDMI控制器句柄

-
- -假设系统中存在2个HDMI控制器,编号从0到1,那么我们现在获取0号控制器: - -```c -DevHandle hdmiHandle = NULL; /* HDMI控制器句柄 / - -/* 打开HDMI控制器 */ -hdmiHandle = HdmiOpen(0); -if (hdmiHandle == NULL) { - HDF_LOGE("HdmiOpen: failed\n"); - return; -} -``` - -### 注册热插拔检测回调函数 - -```c -int32_t HdmiRegisterHpdCallbackFunc(DevHandle handle, struct HdmiHpdCallbackInfo *callback); -``` - -**表 3** HdmiRegisterHpdCallbackFunc参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

HDMI控制器句柄

-

callback

-

热插拔回调函数信息

-

返回值

-

返回值描述

-

0

-

注册成功

-

负数

-

注册失败

-
- -注册热插拔检测回调函数示例: - -```c -/* 热插拔检测回调函数定义 */ -static void HdmiHpdHandle(void *data, bool hpd) -{ - if (data == NULL) { - HDF_LOGE("priv data is NULL"); - return; -} - - if (hpd == true) { - HDF_LOGD("HdmiHpdHandle: hot plug"); - /* 调用者添加相关处理 */ - } else { - HDF_LOGD("HdmiHpdHandle: hot unplog"); - /* 调用者添加相关处理 */ - } -} - - /* 热插拔检测回调函数注册示例 */ - struct HdmiHpdCallbackInfo info = {0}; - info.data = handle; - info.callbackFunc = HdmiHpdHandle; - ret = HdmiRegisterHpdCallbackFunc(hdmiHandle, info); - if (ret != 0) { - HDF_LOGE("HdmiRegisterHpdCallbackFunc: Register failed."); - } -``` - -### 读取EDID - -```c -int32_t HdmiReadSinkEdid(DevHandle handle, uint8_t *buffer, uint32_t len); -``` - -**表 4** HdmiReadSinkEdid参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

HDMI控制器句柄

-

buffer

-

数据缓冲区

-

len

-

数据长度

-

返回值

-

返回值描述

-

正整数

-

成功读取的原始EDID数据

-

负数或0

-

读取失败

-
- -读取Sink端的原始EDID数据示例: - -```c -int32_t len; -uint8_t edid[HDMI_EDID_MAX_LEN] = {0}; - -len = HdmiReadSinkEdid(hdmiHandle, edid, HDMI_EDID_MAX_LEN); -if (len <= 0) { - HDF_LOGE("%s: HdmiReadSinkEdid failed len = %d.", __func__, len); -} -``` - -### 设置音频、视频及HDR属性 - -#### 设置音频属性 - -```c -int32_t HdmiSetAudioAttribute(DevHandle handle, struct HdmiAudioAttr *attr); -``` - -**表 5** HdmiSetAudioAttribute参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

HDMI控制器句柄

-

attr

-

音频属性

-

返回值

-

返回值描述

-

0

-

设置成功

-

负数

-

设置失败

-
- -设置音频属性示例: - -```c -struct HdmiAudioAttr audioAttr = {0}; -int32_t ret; - -audioAttr.codingType = HDMI_AUDIO_CODING_TYPE_MP3; -audioAttr.ifType = HDMI_AUDIO_IF_TYPE_I2S; -audioAttr.bitDepth = HDMI_ADIO_BIT_DEPTH_16; -audioAttr.sampleRate = HDMI_SAMPLE_RATE_8K; -audioAttr.channels = HDMI_AUDIO_FORMAT_CHANNEL_3; -ret = HdmiSetAudioAttribute(handle, &audioAttr); -if (ret != 0) { - HDF_LOGE("HdmiSetAudioAttribute failed."); -} -``` - -#### 设置视频属性 - -```c -int32_t HdmiSetVideoAttribute(DevHandle handle, struct HdmiVideoAttr *attr); -``` - -**表 6** HdmiSetVideoAttribute参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

HDMI控制器句柄

-

attr

-

视频属性

-

返回值

-

返回值描述

-

0

-

设置成功

-

负数

-

设置失败

-
- -设置视频属性示例: - -```c -struct HdmiVideoAttr videoAttr = {0}; -int32_t ret; - -videoAttr.colorSpace = HDMI_COLOR_SPACE_YCBCR444; -videoAttr.colorimetry = HDMI_COLORIMETRY_EXTENDED; -videoAttr.extColorimetry = HDMI_EXTENDED_COLORIMETRY_BT2020_CONST_LUM; -videoAttr.quantization = HDMI_QUANTIZATION_RANGE_FULL; -ret = HdmiSetVideoAttribute(handle, &videoAttr); -if (ret != 0) { - HDF_LOGE("HdmiSetVideoAttribute failed."); -} -``` - -#### 设置HDR属性 - -```c -int32_t HdmiSetHdrAttribute(DevHandle handle, struct HdmiHdrAttr *attr); -``` - -**表 7** HdmiSetHdrAttribute参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

HDMI控制器句柄

-

attr

-

HDR属性

-

返回值

-

返回值描述

-

0

-

设置成功

-

负数

-

设置失败

-
- -设置HDR属性示例: - -```c -struct HdmiHdrAttr hdrAttr = {0}; -int32_t ret; - -hdrAttr.mode = HDMI_HDR_MODE_CEA_861_3; -hdrAttr.userMode = HDMI_HDR_USERMODE_DOLBY; -hdrAttr.eotfType = HDMI_EOTF_SMPTE_ST_2048; -hdrAttr.metadataType = HDMI_DRM_STATIC_METADATA_TYPE_1; -hdrAttr.colorimetry = HDMI_HDR_EXTENDED_COLORIMETRY_XV_YCC_709; -ret = HdmiSetHdrAttribute(handle, &hdrAttr); -if (ret != 0) { - HDF_LOGE("HdmiSetHdrAttribute failed."); -} -``` - -### 其他可选设置 - -#### 设置HDMI声音图像消隐 - -```c -int32_t HdmiAvmuteSet(DevHandle handle, bool enable); -``` - -**表 8** HdmiAvmuteSet参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

HDMI控制器句柄

-

enable

-

使能/去使能avmute

-

返回值

-

返回值描述

-

0

-

设置成功

-

负数

-

设置失败

-
- -设置声音图像消隐示例: - -```c -int32_t ret; - -ret = HdmiAvmuteSet(hdmiHandle, true); -if (ret != 0) { - HDF_LOGE("HdmiAvmuteSet failed."); -} -``` - -#### 设置色彩深度 - -```c -int32_t HdmiDeepColorSet(DevHandle handle, enum HdmiDeepColor color); -``` - -**表 9** HdmiDeepColorSet参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

HDMI控制器句柄

-

color

-

色彩深度

-

返回值

-

返回值描述

-

0

-

设置成功

-

负数

-

设置失败

-
- -设置色彩深度示例: - -```c -int32_t ret; - -ret = HdmiDeepColorSet(handle, HDMI_DEEP_COLOR_48BITS); -if (ret != 0) { - HDF_LOGE("HdmiDeepColorSet failed."); -} -``` - -#### 获取色彩深度 - -```c -int32_t HdmiDeepColorGet(DevHandle handle, enum HdmiDeepColor *color); -``` - -**表 10** HdmiDeepColorGet参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

HDMI控制器句柄

-

color

-

色彩深度

-

返回值

-

返回值描述

-

0

-

获取成功

-

负数

-

获取失败

-
- -获取色彩深度示例: - -```c -enum HdmiDeepColor color; -int32_t ret; - -ret = HdmiDeepColorGet(handle, &color); -if (ret != 0) { - HDF_LOGE("HdmiDeepColorGet failed."); -} -``` - -### 启动HDMI传输 - -```c -int32_t HdmiStart(DevHandle handle); -``` - -**表 11** HdmiStart参数和返回值描述 - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

HDMI控制器句柄

-

返回值

-

返回值描述

-

0

-

启动成功

-

负数

-

启动失败

-
- -启动HDMI传输示例: - -```c -int32_t ret; - -ret = HdmiStart(hdmiHandle); -if (ret != 0) { - HDF_LOGE("start transmission failed."); -} -``` - -### 停止HDMI传输 - -```c -int32_t HdmiStop(DevHandle handle); -``` - -**表 12** HdmiStop参数和返回值描述 - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

HDMI控制器句柄

-

返回值

-

返回值描述

-

0

-

停止成功

-

负数

-

停止失败

-
- -停止HDMI传输示例: - -```c -int32_t ret; - -ret = HdmiStop(hdmiHandle); -if (ret != 0) { - HDF_LOGE("stop transmission failed."); -} -``` - -### 注销热插拔检测回调函数 - -```c -int32_t HdmiUnregisterHpdCallbackFunc(DevHandle handle); -``` - -**表 13** HdmiUnregisterHpdCallbackFunc参数和返回值描述 - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

HDMI控制器句柄

-

返回值

-

返回值描述

-

0

-

注销成功

-

负数

-

注销失败

-
- -注销热插拔检测回调函数示例: - -```c -int32_t ret; - -ret = HdmiUnregisterHpdCallbackFunc(hdmiHandle); -if (ret != 0) { - HDF_LOGE("unregister failed."); -} -``` - -### 关闭HDMI控制器 - -```c -void HdmiClose(DevHandle handle); -``` - -**表 14** HdmiClose参数和返回值描述 - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

HDMI控制器句柄

-
- -关闭HDMI控制器示例: - -```c -HdmiClose(hdmiHandle); -``` - -## 使用实例 - -本例程以操作开发板上的HDMI设备为例,详细展示HDMI接口的完整使用流程。 - -本例拟在Hi3516DV300开发板上对虚拟驱动进行简单的传输操作: - -- SOC:hi3516dv300。 - -- HDMI控制器:使用0号HDMI控制器。 - - -示例如下: - -```c -#include "hdmi_if.h" /* HDMI标准接口头文件 */ -#include "hdf_log.h" /* 标准日志打印头文件 */ -#include "osal_time.h" /* 标准延迟&睡眠接口头文件 */ - -/* 热插拔回调函数 */ -static void HdmiHpdHandle(void *data, bool hpd) -{ - if (data == NULL) { - HDF_LOGE("priv data is NULL"); - return; - } - - if (hpd == true) { - HDF_LOGD("HdmiHpdHandle: hot plug"); - /* 调用者添加相关处理 */ - } else { - HDF_LOGD("HdmiHpdHandle: hot unplog"); - /* 调用者添加相关处理 */ - } -} - -/* 设置HDMI相关属性 */ -static int32_t TestHdmiSetAttr(DevHandle handle) -{ - enum HdmiDeepColor color; - struct HdmiVideoAttr videoAttr = {0}; - struct HdmiAudioAttr audioAttr = {0}; - struct HdmiHdrAttr hdrAttr = {0}; - int32_t ret; - - ret = HdmiDeepColorSet(handle, HDMI_DEEP_COLOR_48BITS); - - if (ret != 0) { - HDF_LOGE("HdmiDeepColorSet failed."); - return ret; - } - ret = HdmiDeepColorGet(handle, &color); - if (ret != 0) { - HDF_LOGE("HdmiDeepColorGet failed."); - return ret; - } - HDF_LOGE("HdmiDeepColorGet successful, color = %d.", color); - videoAttr.colorSpace = HDMI_COLOR_SPACE_YCBCR444; - videoAttr.colorimetry = HDMI_COLORIMETRY_EXTENDED; - videoAttr.extColorimetry = HDMI_EXTENDED_COLORIMETRY_BT2020_CONST_LUM; - videoAttr.quantization = HDMI_QUANTIZATION_RANGE_FULL; - ret = HdmiSetVideoAttribute(handle, &videoAttr); - if (ret != 0) { - HDF_LOGE("HdmiSetVideoAttribute failed."); - return ret; - } - audioAttr.codingType = HDMI_AUDIO_CODING_TYPE_MP3; - audioAttr.ifType = HDMI_AUDIO_IF_TYPE_I2S; - audioAttr.bitDepth = HDMI_ADIO_BIT_DEPTH_16; - audioAttr.sampleRate = HDMI_SAMPLE_RATE_8K; - audioAttr.channels = HDMI_AUDIO_FORMAT_CHANNEL_3; - ret = HdmiSetAudioAttribute(handle, &audioAttr); - if (ret != 0) { - HDF_LOGE("HdmiSetAudioAttribute failed."); - return ret; - } - hdrAttr.mode = HDMI_HDR_MODE_CEA_861_3; - hdrAttr.userMode = HDMI_HDR_USERMODE_DOLBY; - hdrAttr.eotfType = HDMI_EOTF_SMPTE_ST_2048; - hdrAttr.metadataType = HDMI_DRM_STATIC_METADATA_TYPE_1; - hdrAttr.colorimetry = HDMI_HDR_EXTENDED_COLORIMETRY_XV_YCC_709; - ret = HdmiSetHdrAttribute(handle, &hdrAttr); - if (ret != 0) { - HDF_LOGE("HdmiSetHdrAttribute failed."); - return ret; - } - - return 0; -} - -/* HDMI例程总入口 */ -static int32_t TestCaseHdmi(void) -{ - DevHandle handle = NULL; - int32_t ret; - - struct HdmiHpdCallbackInfo info = {0}; - uint8_t data[128] = {0}; - - HDF_LOGD("HdmiAdapterInit: successful."); - handle = HdmiOpen(0); - if (handle == NULL) { - HDF_LOGE("HdmiOpen failed."); - return ret; - } - info.data = handle; - info.callbackFunc = HdmiHpdHandle; - ret = HdmiRegisterHpdCallbackFunc(handle, &info); - if (ret != 0) { - HDF_LOGE("HdmiRegisterHpdCallbackFunc failed."); - return ret; - } - - ret = HdmiReadSinkEdid(handle, data, 128); - if (ret <= 0) { - HDF_LOGE("HdmiReadSinkEdid failed."); - return ret; - } - HDF_LOGE("HdmiReadSinkEdid successful, data[6] = %d, data[8] = %d.", data[6], data[8]); - - ret = TestHdmiSetAttr(handle); - if (ret != 0) { - HDF_LOGE("TestHdmiSetAttr failed."); - return ret; - } - - ret = HdmiStart(handle); - if (ret != 0) { - HDF_LOGE("HdmiStart failed."); - return ret; - } - - OsalMSleep(1000); - - ret = HdmiStop(handle); - if (ret != 0) { - HDF_LOGE("HdmiStop failed."); - return ret; - } - - ret = HdmiUnregisterHpdCallbackFunc(handle); - if (ret != 0) { - HDF_LOGE("HdmiUnregisterHpdCallbackFunc failed."); - return ret; - } - HdmiClose(handle); - return 0; -} - -``` \ No newline at end of file diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/03.\345\271\263\345\217\260\351\251\261\345\212\250\344\275\277\347\224\250/04.I2C.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/03.\345\271\263\345\217\260\351\251\261\345\212\250\344\275\277\347\224\250/04.I2C.md" deleted file mode 100644 index 97ab6cf95de42c11e3db3db9fafa4b44dc5dc822..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/03.\345\271\263\345\217\260\351\251\261\345\212\250\344\275\277\347\224\250/04.I2C.md" +++ /dev/null @@ -1,436 +0,0 @@ ---- -title: I2C -permalink: /pages/0105020304 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:24 ---- -# I2C - -- [概述](#section5361140416) -- [接口说明](#section545869122317) -- [使用指导](#section1695201514281) - - [使用流程](#section1338373417288) - - [打开I2C控制器](#section13751110132914) - - [进行I2C通信](#section9202183372916) - - [关闭I2C控制器](#section19481164133018) - -- [使用实例](#section5302202015300) - -## 概述 - -- I2C\(Inter Integrated Circuit\)总线是由Philips公司开发的一种简单、双向二线制同步串行总线。 -- I2C以主从方式工作,通常有一个主设备和一个或者多个从设备,主从设备通过SDA\(SerialData\)串行数据线以及SCL\(SerialClock\)串行时钟线两根线相连,如[图1 ](#fig1135561232714)所示。 - -- I2C数据的传输必须以一个起始信号作为开始条件,以一个结束信号作为传输的停止条件。数据传输以字节为单位,高位在前,逐个bit进行传输。 -- I2C总线上的每一个设备都可以作为主设备或者从设备,而且每一个设备都会对应一个唯一的地址,当主设备需要和某一个从设备通信时,通过广播的方式,将从设备地址写到总线上,如果某个从设备符合此地址,将会发出应答信号,建立传输。 - -- I2C接口定义了完成I2C传输的通用方法集合,包括: - - - I2C控制器管理: 打开或关闭I2C控制器 - - I2C消息传输:通过消息传输结构体数组进行自定义传输 - - **图 1** I2C物理连线示意图 - ![](/images/device-dev/driver/figures/I2C物理连线示意图.png "I2C物理连线示意图") - - -## 接口说明 - -**表 1** I2C驱动API接口功能介绍 - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名

-

描述

-

I2C控制器管理接口

-

I2cOpen

-

打开I2C控制器

-

I2cClose

-

关闭I2C控制器

-

I2c消息传输接口

-

I2cTransfer

-

自定义传输

-
- ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->本文涉及的所有接口,仅限内核态使用,不支持在用户态使用。 - -## 使用指导 - -### 使用流程 - -使用I2C设备的一般流程如[图2](#fig183017194234)所示。 - -**图 2** I2C设备使用流程图 -![](/images/device-dev/driver/figures/I2C设备使用流程图.png "I2C设备使用流程图") - -### 打开I2C控制器 - -在进行I2C通信前,首先要调用I2cOpen打开I2C控制器。 - -DevHandle I2cOpen\(int16\_t number\); - -**表 2** I2cOpen参数和返回值描述 - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

number

-

I2C控制器号

-

返回值

-

返回值描述

-

NULL

-

打开I2C控制器失败

-

设备句柄

-

打开的I2C控制器设备句柄

-
- -假设系统中存在8个I2C控制器,编号从0到7,那么我们现在获取3号控制器 - -``` -DevHandle i2cHandle = NULL; /* I2C控制器句柄 / - -/* 打开I2C控制器 */ -i2cHandle = I2cOpen(3); -if (i2cHandle == NULL) { - HDF_LOGE("I2cOpen: failed\n"); - return; -} -``` - -### 进行I2C通信 - -消息传输 - -int32\_t I2cTransfer\(DevHandle handle, struct I2cMsg \*msgs, int16\_t count\); - -**表 3** I2cTransfer参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

I2C控制器设备句柄

-

msgs

-

待传输数据的消息结构体数组

-

count

-

消息数组长度

-

返回值

-

返回值描述

-

正整数

-

成功传输的消息结构体数目

-

负数

-

执行失败

-
- -I2C传输消息类型为I2cMsg,每个传输消息结构体表示一次读或写,通过一个消息数组,可以执行若干次的读写组合操作。 - -``` -int32_t ret; -uint8_t wbuff[2] = { 0x12, 0x13 }; -uint8_t rbuff[2] = { 0 }; -struct I2cMsg msgs[2]; /* 自定义传输的消息结构体数组 */ -msgs[0].buf = wbuff; /* 写入的数据 */ -msgs[0].len = 2; /* 写入数据长度为2 */ -msgs[0].addr = 0x5A; /* 写入设备地址为0x5A */ -msgs[0].flags = 0; /* 传输标记为0,默认为写 */ -msgs[1].buf = rbuff; /* 要读取的数据 */ -msgs[1].len = 2; /* 读取数据长度为2 */ -msgs[1].addr = 0x5A; /* 读取设备地址为0x5A */ -msgs[1].flags = I2C_FLAG_READ /* I2C_FLAG_READ置位 */ -/* 进行一次自定义传输,传输的消息个数为2 */ -ret = I2cTransfer(i2cHandle, msgs, 2); -if (ret != 2) { - HDF_LOGE("I2cTransfer: failed, ret %d\n", ret); - return; -} -``` - ->![](/images/device-dev/public_sys-resources/icon-caution.gif) **注意:** ->- I2cMsg结构体中的设备地址不包含读写标志位,读写信息由flags成员变量的读写控制位传递。 ->- 本函数不对消息结构体个数count做限制,其最大个数度由具体I2C控制器决定。 ->- 本函数也不对每个消息结构体中的数据长度做限制,同样由具体I2C控制器决定。 ->- 本函数可能会引起系统休眠,不允许在中断上下文调用 - -### 关闭I2C控制器 - -I2C通信完成之后,需要关闭I2C控制器,关闭函数如下所示: - -void I2cClose\(DevHandle handle\); - -**表 4** I2cClose参数和返回值描述 - - - - - - - - - - -

参数

-

参数描述

-

handle

-

I2C控制器设备句柄

-
- -``` -I2cClose(i2cHandle); /* 关闭I2C控制器 */ -``` - -## 使用实例 - -本例程以操作开发板上的I2C设备为例,详细展示I2C接口的完整使用流程。 - -本例拟对Hi3516DV300某开发板上TouchPad设备进行简单的寄存器读写访问,基本硬件信息如下: - -- SOC:hi3516dv300。 - -- Touch IC:I2C地址为0x38, IC内部寄存器位宽为1字节。 - -- 原理图信息:TouchPad设备挂接在3号I2C控制器下;IC的复位管脚为3号GPIO。 - -本例程首先对Touch IC进行复位操作(开发板上电默认会给TouchIC供电,本例程不考虑供电),然后对其内部寄存器进行随机读写,测试I2C通路是否正常。 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->本例程重点在于展示I2C设备访问流程,并验证I2C通路,所以对于设备寄存器读写值不做关注,读写寄存器导致的行为由设备自身决定。 - -示例如下: - -``` -#include "i2c_if.h" /* I2C标准接口头文件 */ -#include "gpio_if.h" /* GPIO标准接口头文件 */ -#include "hdf_log.h" /* 标准日志打印头文件 */ -#include "osal_io.h" /* 标准IO读写接口头文件 */ -#include "osal_time.h" /* 标准延迟&睡眠接口头文件 */ - -/* 定义一个表示TP设备的结构体,存储i2c及gpio相关硬件信息 */ -struct TpI2cDevice { - uint16_t rstGpio; /* 复位管脚 */ - uint16_t busId; /* I2C总线号 */ - uint16_t addr; /* I2C设备地址 */ - uint16_t regLen; /* 寄存器字节宽度 */ - DevHandle i2cHandle; /* I2C控制器句柄 */ -}; - -/* I2C管脚io配置,需要查阅SOC寄存器手册 */ -#define I2C3_DATA_REG_ADDR 0x112f008c /* 3号I2C控制器SDA管脚配置寄存器地址 */ -#define I2C3_CLK_REG_ADDR 0x112f0090 /* 3号I2C控制器SCL管脚配置寄存器地址 */ -#define I2C_REG_CFG 0x5f1 /* 3号I2C控制器SDA及SCL管脚配置值 */ - -static void TpSocIoCfg(void) -{ - /* 将3号I2C控制器对应两个管脚的IO功能设置为I2C */ - OSAL_WRITEL(I2C_REG_CFG, IO_DEVICE_ADDR(I2C3_DATA_REG_ADDR)); - OSAL_WRITEL(I2C_REG_CFG, IO_DEVICE_ADDR(I2C3_CLK_REG_ADDR)); -} - -/* 对TP的复位管脚进行初始化, 拉高维持20ms, 再拉底维持50ms,最后再拉高维持20ms, 完成复位动作 */ -static int32_t TestCaseGpioInit(struct TpI2cDevice *tpDevice) -{ - int32_t ret; - - /* 设置复位管脚方向为输出 */ - ret = GpioSetDir(tpDevice->rstGpio, GPIO_DIR_OUT); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: set rst dir fail!:%d", __func__, ret); - return ret; - } - - ret = GpioWrite(tpDevice->rstGpio, GPIO_VAL_HIGH); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: set rst hight fail!:%d", __func__, ret); - return ret; - } - OsalMSleep(20); - - ret = GpioWrite(tpDevice->rstGpio, GPIO_VAL_LOW); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: set rst low fail!:%d", __func__, ret); - return ret; - } - OsalMSleep(50); - - ret = GpioWrite(tpDevice->rstGpio, GPIO_VAL_HIGH); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: set rst high fail!:%d", __func__, ret); - return ret; - } - OsalMSleep(20); - - return HDF_SUCCESS; -} - -/* 基于I2cTransfer方法封装一个寄存器读写的辅助函数, 通过flag表示读或写 */ -static int TpI2cReadWrite(struct TpI2cDevice *tpDevice, unsigned int regAddr, - unsigned char *regData, unsigned int dataLen, uint8_t flag) -{ - int index = 0; - unsigned char regBuf[4] = {0}; - struct I2cMsg msgs[2] = {0}; - - /* 单双字节寄存器长度适配 */ - if (tpDevice->regLen == 1) { - regBuf[index++] = regAddr & 0xFF; - } else { - regBuf[index++] = (regAddr >> 8) & 0xFF; - regBuf[index++] = regAddr & 0xFF; - } - - /* 填充I2cMsg消息结构 */ - msgs[0].addr = tpDevice->addr; - msgs[0].flags = 0; /* 标记为0,表示写入 */ - msgs[0].len = tpDevice->regLen; - msgs[0].buf = regBuf; - - msgs[1].addr = tpDevice->addr; - msgs[1].flags = (flag == 1) ? I2C_FLAG_READ : 0; /* 添加读标记位,表示读取 */ - msgs[1].len = dataLen; - msgs[1].buf = regData; - - if (I2cTransfer(tpDevice->i2cHandle, msgs, 2) != 2) { - HDF_LOGE("%s: i2c read err", __func__); - return HDF_FAILURE; - } - return HDF_SUCCESS; -} - -/* TP寄存器读函数 */ -static inline int TpI2cReadReg(struct TpI2cDevice *tpDevice, unsigned int regAddr, - unsigned char *regData, unsigned int dataLen) -{ - return TpI2cReadWrite(tpDevice, regAddr, regData, dataLen, 1); -} - -/* TP寄存器写函数 */ -static inline int TpI2cWriteReg(struct TpI2cDevice *tpDevice, unsigned int regAddr, - unsigned char *regData, unsigned int dataLen) -{ - return TpI2cReadWrite(tpDevice, regAddr, regData, dataLen, 0); -} - -/* I2C例程总入口 */ -static int32_t TestCaseI2c(void) -{ - int32_t i; - int32_t ret; - unsigned char bufWrite[7] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xA, 0xB, 0xC }; - unsigned char bufRead[7] = {0}; - static struct TpI2cDevice tpDevice; - - /* IO管脚功能配置 */ - TpSocIoCfg(); - - /* TP设备信息初始化 */ - tpDevice.rstGpio = 3; - tpDevice.busId = 3; - tpDevice.addr = 0x38; - tpDevice.regLen = 1; - tpDevice.i2cHandle = NULL; - - /* GPIO管脚初始化 */ - ret = TestCaseGpioInit(&tpDevice); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: gpio init fail!:%d", __func__, ret); - return ret; - } - - /* 打开I2C控制器 */ - tpDevice.i2cHandle = I2cOpen(tpDevice.busId); - if (tpDevice.i2cHandle == NULL) { - HDF_LOGE("%s: Open I2c:%u fail!", __func__, tpDevice.busId); - return -1; - } - - /* 向TP-IC的0xD5寄存器连续写7字节数据 */ - ret = TpI2cWriteReg(&tpDevice, 0xD5, bufWrite, 7); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: tp i2c write reg fail!:%d", __func__, ret); - I2cClose(tpDevice.i2cHandle); - return -1; - } - OsalMSleep(10); - - /* 从TP-IC的0xD5寄存器连续读7字节数据 */ - ret = TpI2cReadReg(&tpDevice, 0xD5, bufRead, 7); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: tp i2c read reg fail!:%d", __func__, ret); - I2cClose(tpDevice.i2cHandle); - return -1; - } - - HDF_LOGE("%s: tp i2c write&read reg success!", __func__); - for (i = 0; i < 7; i++) { - HDF_LOGE("%s: bufRead[%d] = 0x%x", __func__, i, bufRead[i]); - } - - /* 访问完毕关闭I2C控制器 */ - I2cClose(tpDevice.i2cHandle); - return ret; -} -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/03.\345\271\263\345\217\260\351\251\261\345\212\250\344\275\277\347\224\250/05.I3C.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/03.\345\271\263\345\217\260\351\251\261\345\212\250\344\275\277\347\224\250/05.I3C.md" deleted file mode 100644 index e936914f3b44318ecb283c20b0fd698cfe73c3e6..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/03.\345\271\263\345\217\260\351\251\261\345\212\250\344\275\277\347\224\250/05.I3C.md" +++ /dev/null @@ -1,633 +0,0 @@ ---- -title: I3C -permalink: /pages/0105020305 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:24 ---- -# I3C - -- [概述](#section1) -- [接口说明](#section2) -- [使用指导](#section3) - - [使用流程](#section4) - - [打开I3C控制器](#section5) - - [进行I3C通信](#section6) - - [获取I3C控制器配置](#section7) - - [配置I3C控制器](#section8) - - [请求IBI(带内中断)](#section9) - - [释放IBI(带内中断)](#section10) - - [关闭I3C控制器](#section11) - -- [使用实例](#section12) - -## 概述 - -- I3C(Improved Inter Integrated Circuit)总线是由MIPI Alliance开发的一种简单、低成本的双向二线制同步串行总线。 -- I3C总线向下兼容传统的I2C设备,同时增加了带内中断(In-Bind Interrupt)功能,支持I3C设备进行热接入操作,弥补了I2C总线需要额外增加中断线来完成中断的不足。 -- I3C总线上允许同时存在I2C设备、I3C从设备和I3C次级主设备。 -- I3C接口定义了完成I3C传输的通用方法集合,包括: - - - I3C控制器管理:打开或关闭I3C控制器。 - - I3C控制器配置:获取或配置I3C控制器参数。 - - I3C消息传输:通过消息传输结构体数组进行自定义传输。 - - I3C带内中断:请求或释放带内中断。 - - I3C的物理连接如[图1](#fig1)所示: - **图 1** I3C物理连线示意图 - ![](/images/device-dev/driver/figures/I3C物理连线示意图.png "I3C物理连线示意图") - -## 接口说明 - -**表 1** I3C驱动API接口功能介绍 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名

-

描述

-

I3C控制器管理接口

-

I3cOpen

-
打开I3C控制器

-

I3cClose

-

关闭I3C控制器

-

I3c消息传输接口

-

I3cTransfer

-

自定义传输

-

I3C控制器配置接口

-

I3cSetConfig

-
配置I3C控制器

-

I3cGetConfig

-

获取I3C控制器配置

-

I3C带内中断接口

-

I3cRequestIbi

-
请求带内中断

-

I3cFreeIbi

-

释放带内中断

-
- - - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->本文涉及的所有接口,仅限内核态使用,不支持在用户态使用。 - -## 使用指导 - -### 使用流程 - -I3C的使用流程如[图2](#fig2)所示。 - -**图 2** I3C使用流程图 -![](/images/device-dev/driver/figures/I3C使用流程图.png "I3C使用流程图") - -### 打开I3C控制器 - -在进行I3C通信前,首先要调用I3cOpen打开I3C控制器。 -```c -DevHandle I3cOpen(int16_t number); -``` - -**表 2** I3cOpen参数和返回值描述 - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

number

-

I3C控制器号

-

返回值

-

返回值描述

-

NULL

-

打开I3C控制器失败

-

控制器句柄

-

打开的I3C控制器句柄

-
- -假设系统中存在8个I3C控制器,编号从0到7,那么我们现在打开1号控制器: - -```c -DevHandle i3cHandle = NULL; /* I3C控制器句柄 / - -/* 打开I3C控制器 */ -i3cHandle = I3cOpen(1); -if (i3cHandle == NULL) { - HDF_LOGE("I3cOpen: failed\n"); - return; -} -``` - -### 进行I3C通信 - -消息传输 -```c -int32_t I3cTransfer(DevHandle handle, struct I3cMsg *msgs, int16_t count, enum TransMode mode); -``` - -**表 3** I3cTransfer参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

I3C控制器句柄

-

msgs

-

待传输数据的消息结构体数组

-

count

-

消息数组长度

-

mode

-

传输模式,0:I2C模式;1:I3C模式;2:发送CCC(Common Command Code)

-

返回值

-

返回值描述

-

正整数

-

成功传输的消息结构体数目

-

负数

-

执行失败

-
- -I3C传输消息类型为I3cMsg,每个传输消息结构体表示一次读或写,通过一个消息数组,可以执行若干次的读写组合操作。 - -```c -int32_t ret; -uint8_t wbuff[2] = { 0x12, 0x13 }; -uint8_t rbuff[2] = { 0 }; -struct I3cMsg msgs[2]; /* 自定义传输的消息结构体数组 */ -msgs[0].buf = wbuff; /* 写入的数据 */ -msgs[0].len = 2; /* 写入数据长度为2 */ -msgs[0].addr = 0x3F; /* 写入设备地址为0x3F */ -msgs[0].flags = 0; /* 传输标记为0,默认为写 */ -msgs[1].buf = rbuff; /* 要读取的数据 */ -msgs[1].len = 2; /* 读取数据长度为2 */ -msgs[1].addr = 0x3F; /* 读取设备地址为0x3F */ -msgs[1].flags = I3C_FLAG_READ /* I3C_FLAG_READ置位 */ -/* 进行一次I2C模式自定义传输,传输的消息个数为2 */ -ret = I3cTransfer(i3cHandle, msgs, 2, I2C_MODE); -if (ret != 2) { - HDF_LOGE("I3cTransfer: failed, ret %d\n", ret); - return; -} -``` - ->![](/images/device-dev/public_sys-resources/icon-caution.gif) **注意:** ->- I3cMsg结构体中的设备地址不包含读写标志位,读写信息由flags成员变量的读写控制位传递。 ->- 本函数不对消息结构体个数做限制,其最大个数度由具体I3C控制器决定。 ->- 本函数不对每个消息结构体中的数据长度做限制,同样由具体I3C控制器决定。 ->- 本函数可能会引起系统休眠,禁止在中断上下文调用。 - -### 获取I3C控制器配置 - -```c -int32_t I3cGetConfig(DevHandle handle, struct I3cConfig *config); -``` - -**表 4** I3cGetConfig参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

I3C控制器句柄

-

config

-

I3C控制器配置

-

返回值

-

返回值描述

-

0

-

获取成功

-

负数

-

获取失败

-
- -### 配置I3C控制器 - -```c -int32_t I3cSetConfig(DevHandle handle, struct I3cConfig *config); -``` - -**表 5** I3cSetConfig参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

I3C控制器句柄

-

config

-

I3C控制器配置

-

返回值

-

返回值描述

-

0

-

配置成功

-

负数

-

配置失败

-
- -### 请求IBI(带内中断) - -```c -int32_t I3cRequestIbi(DevHandle handle, uint16_t addr, I3cIbiFunc func, uint32_t payload); -``` - -**表 6** I3cRequestIbi参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

I3C控制器设备句柄

-

addr

-

I3C设备地址

-

func

-

IBI回调函数

-

payload

-

IBI有效载荷

-

返回值

-

返回值描述

-

0

-

请求成功

-

负数

-

请求失败

-
- -```c -static int32_t TestI3cIbiFunc(DevHandle handle, uint16_t addr, struct I3cIbiData data) -{ - (void)handle; - (void)addr; - HDF_LOGD("%s: %.16s", __func__, (char *)data.buf); - - return 0; -} - -int32_t I3cTestRequestIbi(void) -{ - DevHandle i3cHandle = NULL; - int32_t ret; - - /* 打开I3C控制器 */ - i3cHandle = I3cOpen(1); - if (i3cHandle == NULL) { - HDF_LOGE("I3cOpen: failed\n"); - return; -} - ret = I3cRequestIbi(i3cHandle, 0x3F, TestI3cIbiFunc, 16); - if (ret != 0) { - HDF_LOGE("%s: Requset IBI failed!", __func__); - return -1; - } - - I3cClose(i3cHandle); - HDF_LOGD("%s: Done", __func__); - - return 0; -} -``` - -### 释放IBI(带内中断) - -```c -int32_t I3cFreeIbi(DevHandle handle, uint16_t addr); -``` - -**表 7** I3cFreeIbi参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

I3C控制器设备句柄

-

addr

-

I3C设备地址

-

返回值

-

返回值描述

-

0

-

释放成功

-

负数

-

释放失败

-
- -```c -I3cFreeIbi(i3cHandle, 0x3F); /* 释放带内中断 */ -``` - -### 关闭I3C控制器 - -I3C通信完成之后,需要关闭I3C控制器,关闭函数如下所示: -```c -void I3cClose(DevHandle handle); -``` - -**表 4** I3cClose参数和返回值描述 - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

I3C控制器设备句柄

-
- - -```c -I3cClose(i3cHandle); /* 关闭I3C控制器 */ -``` - -## 使用实例 - -本例程以操作开发板上的I3C设备为例,详细展示I3C接口的完整使用流程。 - -由于Hi3516DV300系列SOC没有I3C控制器,本例拟在Hi3516DV300某开发板上对虚拟驱动进行简单的传输操作,基本硬件信息如下: - -- SOC:hi3516dv300。 - -- 虚拟:I3C地址为0x3f, 寄存器位宽为1字节。 - -- 原理图信息:虚拟I3C设备挂接在18号和19号I3C控制器下。 - -本例程进行简单的I3C传输,测试I3C通路是否正常。 - -示例如下: - -```c -#include "i3c_if.h" /* I3C标准接口头文件 */ -#include "i3c_ccc.h" /* I3C通用命令代码头文件 */ -#include "hdf_log.h" /* 标准日志打印头文件 */ -#include "osal_io.h" /* 标准IO读写接口头文件 */ -#include "osal_time.h" /* 标准延迟&睡眠接口头文件 */ - -/* 定义一个表示设备的结构体,存储信息 */ -struct TestI3cDevice { - uint16_t busNum; /* I3C总线号 */ - uint16_t addr; /* I3C设备地址 */ - uint16_t regLen; /* 寄存器字节宽度 */ - DevHandle i3cHandle; /* I3C控制器句柄 */ -}; - -/* 基于I3cTransfer方法封装一个寄存器读写的辅助函数, 通过flag表示读或写 */ -static int TestI3cReadWrite(struct TestI3cDevice *testDevice, unsigned int regAddr, - unsigned char *regData, unsigned int dataLen, uint8_t flag) -{ - int index = 0; - unsigned char regBuf[4] = {0}; - struct I3cMsg msgs[2] = {0}; - - /* 单双字节寄存器长度适配 */ - if (testDevice->regLen == 1) { - regBuf[index++] = regAddr & 0xFF; - } else { - regBuf[index++] = (regAddr >> 8) & 0xFF; - regBuf[index++] = regAddr & 0xFF; - } - - /* 填充I3cMsg消息结构 */ - msgs[0].addr = testDevice->addr; - msgs[0].flags = 0; /* 标记为0,表示写入 */ - msgs[0].len = testDevice->regLen; - msgs[0].buf = regBuf; - - msgs[1].addr = testDevice->addr; - msgs[1].flags = (flag == 1) ? I3C_FLAG_READ : 0; /* 添加读标记位,表示读取 */ - msgs[1].len = dataLen; - msgs[1].buf = regData; - - if (I3cTransfer(testDevice->i3cHandle, msgs, 2, I2C_MODE) != 2) { - HDF_LOGE("%s: i3c read err", __func__); - return HDF_FAILURE; - } - return HDF_SUCCESS; -} - -/* 寄存器读函数 */ -static inline int TestI3cReadReg(struct TestI3cDevice *testDevice, unsigned int regAddr, - unsigned char *regData, unsigned int dataLen) -{ - return TestI3cReadWrite(testDevice, regAddr, regData, dataLen, 1); -} - -/* 寄存器写函数 */ -static inline int TestI3cWriteReg(struct TestI3cDevice *testDevice, unsigned int regAddr, - unsigned char *regData, unsigned int dataLen) -{ - return TestI3cReadWrite(testDevice, regAddr, regData, dataLen, 0); -} - -/* I3C例程总入口 */ -static int32_t TestCaseI3c(void) -{ - int32_t i; - int32_t ret; - unsigned char bufWrite[7] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xA, 0xB, 0xC }; - unsigned char bufRead[7] = {0}; - static struct TestI3cDevice testDevice; - - /* 设备信息初始化 */ - testDevice.busNum = 18; - testDevice.addr = 0x3F; - testDevice.regLen = 1; - testDevice.i3cHandle = NULL; - - /* 打开I3C控制器 */ - testDevice.i3cHandle = I3cOpen(testDevice.busNum); - if (testDevice.i3cHandle == NULL) { - HDF_LOGE("%s: Open I3c:%u fail!", __func__, testDevice.busNum); - return -1; - } - - /* 向地址为0x3F的设备连续写7字节数据 */ - ret = TestI3cWriteReg(&testDevice, 0x3F, bufWrite, 7); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: test i3c write reg fail!:%d", __func__, ret); - I3cClose(testDevice.i3cHandle); - return -1; - } - OsalMSleep(10); - - /* 从地址为0x3F的设备连续读7字节数据 */ - ret = TestI3cReadReg(&testDevice, 0x3F, bufRead, 7); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: test i3c read reg fail!:%d", __func__, ret); - I3cClose(testDevice.i3cHandle); - return -1; - } - HDF_LOGI("%s: test i3c write&read reg success!", __func__); - - /* 访问完毕关闭I3C控制器 */ - I3cClose(testDevice.i3cHandle); - - return 0; -} -``` \ No newline at end of file diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/03.\345\271\263\345\217\260\351\251\261\345\212\250\344\275\277\347\224\250/06.MIPI-CSI.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/03.\345\271\263\345\217\260\351\251\261\345\212\250\344\275\277\347\224\250/06.MIPI-CSI.md" deleted file mode 100644 index a6a62e28afcef6c16369fef02447a50bba036482..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/03.\345\271\263\345\217\260\351\251\261\345\212\250\344\275\277\347\224\250/06.MIPI-CSI.md" +++ /dev/null @@ -1,779 +0,0 @@ ---- -title: MIPI-CSI -permalink: /pages/0105020306 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:24 ---- -# MIPI CSI - -- [概述](#section1_MIPI_CSIDes) - - [ComboDevAttr结构体](#section1.1_MIPI_CSIDes) - - [ExtDataType结构体](#section1.2_MIPI_CSIDes) - - [接口说明](#section1.3_MIPI_CSIDes) - -- [使用指导](#section2_MIPI_CSIDes) - - [使用流程](#section2.1_MIPI_CSIDes) - - [获取MIPI-CSI控制器操作句柄](#section2.2_MIPI_CSIDes) - - [MIPI-CSI相应配置](#section2.3_MIPI_CSIDes) - - [复位/撤销复位sensor](#section2.4_MIPI_CSIDes) - - [复位/撤销复位MIPI RX](#section2.5_MIPI_CSIDes) - - [使能/关闭MIPI的时钟](#section2.6_MIPI_CSIDes) - - [使能/关闭MIPI上的sensor时钟](#section2.7_MIPI_CSIDes) - - [释放MIPI-CSI控制器操作句柄](#section2.8_MIPI_CSIDes) -- [使用实例](#section3_MIPI_CSIDes) - -## 概述 - -- CSI(Camera Serial Interface)是由MIPI联盟下Camera工作组指定的接口标准。CSI-2是MIPI CSI第二版,主要由应用层、协议层、物理层组成,最大支持4通道数据传输、单线传输速度高达1Gb/s。 - -- 物理层支持HS(High Speed)和LP(Low Power)两种工作模式。HS模式下采用低压差分信号,功耗较大,但数据传输速率可以很高(数据速率为80M~1Gbps);LP模式下采用单端信号,数据速率很低(<10Mbps),但是相应的功耗也很低。两种模式的结合保证了MIPI总线在需要传输大量数据(如图像)时可以高速传输,而在不需要传输大数据量时又能够减少功耗。 - -- 图1显示了简化的CSI接口。D-PHY采用1对源同步的差分时钟和1~4对差分数据线来进行数据传输。数据传输采用DDR方式,即在时钟的上下边沿都有数据传输。 - - **图 1** CSI发送、接收接口 - ![](/images/device-dev/driver/figures/CSI发送-接收接口.png) - -### ComboDevAttr结构体 - -**表** **1** ComboDevAttr结构体介绍 - - - -| 名称 | 描述 | -| --------- | ----------------------------------------------------- | -| devno | 设备号 | -| inputMode | 输入模式:MIPI/LVDS/SUBSLVDS/HISPI/DC | -| dataRate | Mipi Rx,SLVS输入速率 | -| imgRect | MIPI Rx设备裁剪区域(与原始传感器输入图像大小相对应) | -| MIPIAttr | Mipi设备属性 | -| lvdsAttr | LVDS/SubLVDS/HiSPi设备属性 | - -### ExtDataType结构体 - -**表** **2** ExtDataType结构体介绍 - - - -| 名称 | 描述 | -| --------------- | ------------------------------- | -| devno | 设备号 | -| num | sensor号 | -| extDataBitWidth | 图片的位深 | -| extDataType | 定义YUV和原始数据格式以及位深度 | - -### 接口说明 - -**表 3** MIPI-CSI API接口功能介绍 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
功能分类接口名描述
获取/释放MIPI-CSI控制器操作句柄MipiCsiOpen获取MIPI-CSI控制器操作句柄
MipiCsiClose释放MIPI-CSI控制器操作句柄
MIPI-CSI相应配置MipiCsiSetComboDevAttr设置MIPI,CMOS或者LVDS相机的参数给控制器,参数包括工作模式,图像区域,图像深度,数据速率和物理通道等
MipiCsiSetExtDataType(可选)设置YUV和RAW数据格式和位深
MipiCsiSetHsMode设置MIPI RX的Lane分布。根据硬件连接的形式选择具体的mode
MipiCsiSetPhyCmvmode设置共模电压模式
复位/撤销复位SensorMipiCsiResetSensor复位Sensor
MipiCsiUnresetSensor撤销复位Sensor
复位/撤销复位MIPI RXMipiCsiResetRx复位MIPI RX。不同的s32WorkingViNum有不同的enSnsType
MipiCsiUnresetRx撤销复位MIPI RX
使能/关闭MIPI的时钟MipiCsiEnableClock使能MIPI的时钟。根据上层函数电泳传递的enSnsType参数决定是用MIPI还是LVDS
MipiCsiDisableClock关闭MIPI设备的时钟
使能/禁用MIPI上的Sensor时钟MipiCsiEnableSensorClock使能MIPI上的Sensor时钟
MipiCsiDisableSensorClock关闭Sensor的时钟
- - - - -## 使用指导 - -### 使用流程 - -使用MIPI-CSI的一般流程如[图2](#fig99821771782)所示。 - -**图 2** MIPI-CSI使用流程图 - - -![](/images/device-dev/driver/figures/MIPI-CSI使用流程图.png) - -### 获取MIPI-CSI控制器操作句柄 - -在进行MIPI-CSI进行通信前,首先要调用MipiCsiOpen获取控制器操作句柄,该函数会返回指定通道ID的控制器操作句柄。 - -```c -DevHandle MipiCsiOpen(uint8_t id); -``` - -**表 4** MipiCsiOpen的参数和返回值描述 - - - -| 参数 | 参数描述 | -| ---------- | ----------------------------------------------- | -| id | MIPI CSI通道ID | -| **返回值** | **返回值描述** | -| NULL | 获取失败 | -| 设备句柄 | 获取到指令通道的控制器操作句柄,类型为DevHandle | - -假设系统中的MIPI-CSI通道为0,获取该通道控制器操作句柄的示例如下: - -```c -DevHandle MipiCsiHandle = NULL; /* 设备句柄 */ -id = 0; /* MiPi-Csi通道ID */ - -/* 获取控制器操作句柄 */ -MipiCsiHandle = MipiCsiOpen(id); -if (MipiCsiHandle == NULL) { - HDF_LOGE("MipiCsiOpen: failed\n"); - return; -} -``` - -### MIPI-CSI相应配置 - -- 写入MIPI-CSI配置 - - ```c - int32_t MipiCsiSetComboDevAttr(DevHandle handle, ComboDevAttr *pAttr); - ``` - - **表 5** MipiCsiSetComboDevAttr的参数和返回值描述 - - - - | 参数 | 参数描述 | - | ---------- | -------------------------- | - | handle | 控制器操作句柄 | - | pAttr | MIPI-CSI相应配置结构体指针 | - | **返回值** | **返回值描述** | - | 0 | 设置成功 | - | 负数 | 设置失败 | - - ```c - int32_t ret; - struct ComboDevAttr attr; - - /* 当前配置如下 */ - (void)memset_s(&attr, sizeof(ComboDevAttr), 0, sizeof(ComboDevAttr)); - attr.devno = 0; /* 设备0 */ - attr.inputMode = INPUT_MODE_MIPI; /* 输入模式为MIPI */ - attr.dataRate = MIPI_DATA_RATE_X1; /* 每时钟输出1像素 */ - attr.imgRect.x = 0; /* 0: 图像传感器左上位置 */ - attr.imgRect.y = 0; /* 0: 图像传感器右上位置 */ - attr.imgRect.width = 2592; /* 2592: 图像传感器宽度大小 */ - attr.imgRect.height = 1944; /* 1944: 图像传感器高度尺寸 */ - /* 写入配置数据 */ - ret = MipiCsiSetComboDevAttr(MipiCsiHandle, &attr); - if (ret != 0) { - HDF_LOGE("%s: MipiCsiSetComboDevAttr fail! ret=%d\n", __func__, ret); - return -1; - } - ``` - -- 设置YUV和RAW数据格式和位深 - - ```c - int32_t MipiCsiSetExtDataType(DevHandle handle, ExtDataType* dataType); - ``` - - **表 6** MipiCsiSetExtDataType的参数和返回值描述 - - - - | 参数 | 参数描述 | - | ---------- | ------------------------------- | - | handle | 控制器操作句柄 | - | dataType | 定义YUV和原始数据格式以及位深度 | - | **返回值** | **返回值描述** | - | 0 | 设置成功 | - | 负数 | 设置失败 | - - ```c - int32_t ret; - struct ExtDataType dataType; - - /* 配置YUV和RAW数据格式和位深参数 */ - dataType.devno = 0; /* 设备0 */ - dataType.num = 0; /* sensor 0 */ - dataType.extDataBitWidth[0] = 12; /* 位深数组元素0 */ - dataType.extDataBitWidth[1] = 12; /* 位深数组元素1 */ - dataType.extDataBitWidth[2] = 12; /* 位深数组元素2 */ - - dataType.extDataType[0] = 0x39; /* 定义YUV和原始数据格式以及位深度元素0 */ - dataType.extDataType[1] = 0x39; /* 定义YUV和原始数据格式以及位深度元素1 */ - dataType.extDataType[2] = 0x39; /* 定义YUV和原始数据格式以及位深度元素2 */ - /* 设置YUV和RAW数据格式和位深 */ - ret = MipiCsiSetExtDataType(MipiCsiHandle, &dataType); - if (ret != 0) { - HDF_LOGE("%s: MipiCsiSetExtDataType fail! ret=%d\n", __func__, ret); - return -1; - } - ``` - -- 设置MIPI RX的Lane分布 - - ```c - int32_t MipiCsiSetHsMode(DevHandle handle, LaneDivideMode laneDivideMode); - ``` - - **表 7** MipiCsiSetHsMode的参数和返回值描述 - - - - | 参数 | 参数描述 | - | -------------- | -------------- | - | handle | 控制器操作句柄 | - | laneDivideMode | lane模式参数 | - | **返回值** | **返回值描述** | - | 0 | 设置成功 | - | 负数 | 设置失败 | - - ```c - int32_t ret; - enum LaneDivideMode mode; - - /* lane模式参数为0 */ - mode = LANE_DIVIDE_MODE_0; - /* 设置MIPI RX的 Lane分布 */ - ret = MipiCsiSetHsMode(MipiCsiHandle, mode); - if (ret != 0) { - HDF_LOGE("%s: MipiCsiSetHsMode fail! ret=%d\n", __func__, ret); - return -1; - } - ``` - -- 设置共模电压模式 - - ```c - int32_t MipiCsiSetPhyCmvmode(DevHandle handle, uint8_t devno, PhyCmvMode cmvMode); - ``` - - **表 8** MipiCsiSetPhyCmvmode的参数和返回值描述 - - - - | 参数 | 参数描述 | - | ---------- | ---------------- | - | handle | 控制器操作句柄 | - | cmvMode | 共模电压模式参数 | - | devno | 设备编号 | - | **返回值** | **返回值描述** | - | 0 | 设置成功 | - | 负数 | 设置失败 | - - ```c - int32_t ret; - enum PhyCmvMode mode; - uint8_t devno; - - /* 共模电压模式参数为0 */ - mode = PHY_CMV_GE1200MV; - /* 设备编号为0 */ - devno = 0; - /* 设置共模电压模式 */ - ret = MipiCsiSetPhyCmvmode(MipiCsiHandle, devno, mode); - if (ret != 0) { - HDF_LOGE("%s: MipiCsiSetPhyCmvmode fail! ret=%d\n", __func__, ret); - return -1; - } - ``` - -### 复位/撤销复位Sensor - -- 复位Sensor - - ```c - int32_t MipiCsiResetSensor(DevHandle handle, uint8_t snsResetSource); - ``` - - **表 9** MipiCsiResetSensor的参数和返回值描述 - - - - | 参数 | 参数描述 | - | -------------- | ------------------------------------------------ | - | handle | 控制器操作句柄 | - | snsResetSource | 传感器的复位信号线号,在软件中称为传感器的复位源 | - | **返回值** | **返回值描述** | - | 0 | 复位成功 | - | 负数 | 复位失败 | - - ```c - int32_t ret; - uint8_t snsResetSource; - - /* 传感器复位信号线号为0 */ - snsResetSource = 0; - /* 复位sensor */ - ret = MipiCsiResetSensor(MipiCsiHandle, snsResetSource); - if (ret != 0) { - HDF_LOGE("%s: MipiCsiResetSensor fail! ret=%d\n", __func__, ret); - return -1; - } - ``` - -- 撤销复位Sensor - - ```c - int32_t MipiCsiUnresetSensor(DevHandle handle, uint8_t snsResetSource); - ``` - - **表 10** MipiCsiUnresetSensor的参数和返回值描述 - - - - | 参数 | 参数描述 | - | -------------- | ------------------------------------------------ | - | handle | 控制器操作句柄 | - | snsResetSource | 传感器的复位信号线号,在软件中称为传感器的复位源 | - | **返回值** | **返回值描述** | - | 0 | 撤销复位成功 | - | 负数 | 撤销复位失败 | - - ```c - int32_t ret; - uint8_t snsResetSource; - - /* 传感器撤销复位信号线号为0 */ - snsResetSource = 0; - /* 撤销复位sensor */ - ret = MipiCsiUnresetSensor(MipiCsiHandle, snsResetSource); - if (ret != 0) { - HDF_LOGE("%s: MipiCsiUnresetSensor fail! ret=%d\n", __func__, ret); - return -1; - } - ``` - -### 复位/撤销复位MIPI RX - -- 复位MIPI RX - - ```c - int32_t MipiCsiResetRx(DevHandle handle, uint8_t comboDev); - ``` - - **表 11** MipiCsiResetRx的参数和返回值描述 - - - - | 参数 | 参数描述 | - | ---------- | --------------------- | - | handle | 控制器操作句柄 | - | comboDev | MIPI RX或LVDS通路序号 | - | **返回值** | **返回值描述** | - | 0 | 复位成功 | - | 负数 | 复位失败 | - - ```c - int32_t ret; - uint8_t comboDev; - - /* 通路序号为0 */ - comboDev = 0; - /* 复位MIPI RX */ - ret = MipiCsiResetRx(MipiCsiHandle, comboDev); - if (ret != 0) { - HDF_LOGE("%s: MipiCsiResetRx fail! ret=%d\n", __func__, ret); - return -1; - } - ``` - -- 撤销复位MIPI RX - - ```c - int32_t MipiCsiUnresetRx(DevHandle handle, uint8_t comboDev); - ``` - - **表 12** MipiCsiUnresetRx的参数和返回值描述 - - - - | 参数 | 参数描述 | - | ---------- | --------------------- | - | handle | 控制器操作句柄 | - | comboDev | MIPI RX或LVDS通路序号 | - | **返回值** | **返回值描述** | - | 0 | 撤销复位成功 | - | 负数 | 撤销复位失败 | - - ```c - int32_t ret; - uint8_t comboDev; - - /* 通路序号为0 */ - comboDev = 0; - /* 撤销复位MIPI RX */ - ret = MipiCsiUnresetRx(MipiCsiHandle, comboDev); - if (ret != 0) { - HDF_LOGE("%s: MipiCsiUnresetRx fail! ret=%d\n", __func__, ret); - return -1; - } - ``` - -### 使能/关闭MIPI的时钟 - -- 使能MIPI的时钟 - - ```c - int32_t MipiCsiEnableClock(DevHandle handle, uint8_t comboDev); - ``` - - **表 13** MipiCsiEnableClock的参数和返回值描述 - - - - | 参数 | 参数描述 | - | ---------- | -------------- | - | handle | 控制器操作句柄 | - | comboDev | 通路序号 | - | **返回值** | **返回值描述** | - | 0 | 使能成功 | - | 负数 | 使能失败 | - - ```c - int32_t ret; - uint8_t comboDev; - - /* 通路序号为0 */ - comboDev = 0; - /* 使能MIPI的时钟 */ - ret = MipiCsiEnableClock(MipiCsiHandle, comboDev); - if (ret != 0) { - HDF_LOGE("%s: MipiCsiEnableClock fail! ret=%d\n", __func__, ret); - return -1; - } - ``` - -- 关闭MIPI的时钟 - - ```c - int32_t MipiCsiDisableClock(DevHandle handle, uint8_t comboDev); - ``` - - **表 14** MipiCsiDisableClock的参数和返回值描述 - - - - | 参数 | 参数描述 | - | ---------- | -------------- | - | handle | 控制器操作句柄 | - | comboDev | 通路序号 | - | **返回值** | **返回值描述** | - | 0 | 关闭成功 | - | 负数 | 关闭失败 | - - ```c - int32_t ret; - uint8_t comboDev; - - /* 通路序号为0 */ - comboDev = 0; - /* 关闭MIPI的时钟 */ - ret = MipiCsiDisableClock(MipiCsiHandle, comboDev); - if (ret != 0) { - HDF_LOGE("%s: MipiCsiDisableClock fail! ret=%d\n", __func__, ret); - return -1; - } - ``` - -### 使能/关闭MIPI上的Sensor时钟 - -- 使能MIPI上的Sensor时钟 - - ```c - int32_t MipiCsiEnableSensorClock(DevHandle handle, uint8_t snsClkSource); - ``` - - **表 15** MipiCsiEnableSensorClock的参数和返回值描述 - - - - | 参数 | 参数描述 | - | ------------ | ------------------------------------------------ | - | handle | 控制器操作句柄 | - | snsClkSource | 传感器的时钟信号线号,在软件中称为传感器的时钟源 | - | **返回值** | **返回值描述** | - | 0 | 使能成功 | - | 负数 | 使能失败 | - - ```c - int32_t ret; - uint8_t snsClkSource; - - /* 传感器的时钟信号线号为0 */ - snsClkSource = 0; - /* 使能MIPI上的sensor时钟 */ - ret = MipiCsiEnableSensorClock(MipiCsiHandle, snsClkSource); - if (ret != 0) { - HDF_LOGE("%s: MipiCsiEnableSensorClock fail! ret=%d\n", __func__, ret); - return -1; - } - ``` - -- 关闭MIPI上的Sensor时钟 - - ```c - int32_t MipiCsiDisableSensorClock(DevHandle handle, uint8_t snsClkSource); - ``` - - **表 16** MipiCsiDisableSensorClock的参数和返回值描述 - - - - | 参数 | 参数描述 | - | ------------ | ------------------------------------------------ | - | handle | 控制器操作句柄 | - | snsClkSource | 传感器的时钟信号线号,在软件中称为传感器的时钟源 | - | **返回值** | **返回值描述** | - | 0 | 关闭成功 | - | 负数 | 关闭失败 | - - ```c - int32_t ret; - uint8_t snsClkSource; - - /* 传感器的时钟信号线号为0 */ - snsClkSource = 0; - /* 关闭MIPI上的Sensor时钟 */ - ret = MipiCsiDisableSensorClock(MipiCsiHandle, snsClkSource); - if (ret != 0) { - HDF_LOGE("%s: MipiCsiDisableSensorClock fail! ret=%d\n", __func__, ret); - return -1; - } - ``` - -### 释放MIPI-CSI控制器操作句柄 - -MIPI-CSI使用完成之后,需要释放控制器操作句柄,释放句柄的函数如下所示: - -```c -void MipiCsiClose(DevHandle handle); -``` - -该函数会释放掉由MipiCsiOpen申请的资源。 - -**表 17** MipiCsiClose的参数和返回值描述 - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

MIPI-CSI控制器操作句柄

-
- -```c -MipiCsiClose(MIPIHandle); /* 释放掉MIPI-CSI控制器操作句柄 */ -``` - -## 使用实例 - -MIPI-CSI完整的使用示例如下所示: - -```c -#include "hdf.h" -#include "MIPI_csi_if.h" - -void PalMipiCsiTestSample(void) -{ - uint8_t id; - int32_t ret; - uint8_t comboDev; - uint8_t snsClkSource; - uint8_t devno; - enum LaneDivideMode mode; - enum PhyCmvMode mode; - struct ComboDevAttr attr; - struct ExtDataType dataType; - DevHandle MipiCsiHandle = NULL; - - /* 控制器ID号 */ - id = 0; - /* 获取控制器操作句柄 */ - MipiCsiHandle = MipiCsiOpen(id); - if (MipiCsiHandle == NULL) { - HDF_LOGE("MipiCsiOpen: failed!\n"); - return; - } - - /* lane模式参数为0 */ - mode = LANE_DIVIDE_MODE_0; - /* 设置MIPI RX的 Lane分布 */ - ret = MipiCsiSetHsMode(MipiCsiHandle, mode); - if (ret != 0) { - HDF_LOGE("%s: MipiCsiSetHsMode fail! ret=%d\n", __func__, ret); - return; - } - - /* 通路序号为0 */ - comboDev = 0; - /* 使能MIPI的时钟 */ - ret = MipiCsiEnableClock(MipiCsiHandle, comboDev); - if (ret != 0) { - HDF_LOGE("%s: MipiCsiEnableClock fail! ret=%d\n", __func__, ret); - return; - } - - /* 复位MIPI RX */ - ret = MipiCsiResetRx(MipiCsiHandle, comboDev); - if (ret != 0) { - HDF_LOGE("%s: MipiCsiResetRx fail! ret=%d\n", __func__, ret); - return; - } - - /* 传感器的时钟信号线号为0 */ - snsClkSource = 0; - /* 使能MIPI上的sensor时钟 */ - ret = MipiCsiEnableSensorClock(MipiCsiHandle, snsClkSource); - if (ret != 0) { - HDF_LOGE("%s: MipiCsiEnableSensorClock fail! ret=%d\n", __func__, ret); - return; - } - - /* 复位sensor */ - ret = MipiCsiResetSensor(MipiCsiHandle, snsResetSource); - if (ret != 0) { - HDF_LOGE("%s: MipiCsiResetSensor fail! ret=%d\n", __func__, ret); - return; - } - - /* MIPI参数配置如下 */ - (void)memset_s(&attr, sizeof(ComboDevAttr), 0, sizeof(ComboDevAttr)); - attr.devno = 0; /* 设备0 */ - attr.inputMode = INPUT_MODE_MIPI; /* 输入模式为MIPI */ - attr.dataRate = MIPI_DATA_RATE_X1; /* 每时钟输出1像素 */ - attr.imgRect.x = 0; /* 0: 图像传感器左上位置 */ - attr.imgRect.y = 0; /* 0: 图像传感器右上位置 */ - attr.imgRect.width = 2592; /* 2592: 图像传感器宽度大小 */ - attr.imgRect.height = 1944; /* 1944: 图像传感器高度尺寸 */ - /* 写入配置数据 */ - ret = MipiCsiSetComboDevAttr(MipiCsiHandle, &attr); - if (ret != 0) { - HDF_LOGE("%s: MipiCsiSetComboDevAttr fail! ret=%d\n", __func__, ret); - return; - } - - /* 共模电压模式参数为0 */ - mode = PHY_CMV_GE1200MV; - /* 设备编号为0 */ - devno = 0; - /* 设置共模电压模式 */ - ret = MipiCsiSetPhyCmvmode(MipiCsiHandle, devno, mode); - if (ret != 0) { - HDF_LOGE("%s: MipiCsiSetPhyCmvmode fail! ret=%d\n", __func__, ret); - return; - } - - /* 通路序号为0 */ - comboDev = 0; - /* 撤销复位MIPI RX */ - ret = MipiCsiUnresetRx(MipiCsiHandle, comboDev); - if (ret != 0) { - HDF_LOGE("%s: MipiCsiUnresetRx fail! ret=%d\n", __func__, ret); - return; - } - - /* 关闭MIPI的时钟 */ - ret = MipiCsiDisableClock(MipiCsiHandle, comboDev); - if (ret != 0) { - HDF_LOGE("%s: MipiCsiDisableClock fail! ret=%d\n", __func__, ret); - return; - } - - /* 传感器撤销复位信号线号为0 */ - snsResetSource = 0; - /* 撤销复位sensor */ - ret = MipiCsiUnresetSensor(MipiCsiHandle, snsResetSource); - if (ret != 0) { - HDF_LOGE("%s: MipiCsiUnresetSensor fail! ret=%d\n", __func__, ret); - return; - } - - /* 关闭MIPI上的sensor时钟 */ - ret = MipiCsiDisableSensorClock(MipiCsiHandle, snsClkSource); - if (ret != 0) { - HDF_LOGE("%s: MipiCsiDisableSensorClock fail! ret=%d\n", __func__, ret); - return; - } - - /* 释放MIPI DSI设备句柄 */ - MipiCsiClose(MipiCsiHandle); -} -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/03.\345\271\263\345\217\260\351\251\261\345\212\250\344\275\277\347\224\250/07.MIPI-DSI.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/03.\345\271\263\345\217\260\351\251\261\345\212\250\344\275\277\347\224\250/07.MIPI-DSI.md" deleted file mode 100644 index ed7d91ecc75996ef2904958e8460086482feb04f..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/03.\345\271\263\345\217\260\351\251\261\345\212\250\344\275\277\347\224\250/07.MIPI-DSI.md" +++ /dev/null @@ -1,564 +0,0 @@ ---- -title: MIPI-DSI -permalink: /pages/0105020307 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:24 ---- -# MIPI DSI - -- [概述](#section16806142183217) -- [接口说明](#section12720125432316) -- [使用指导](#section037231715335) - - [使用流程](#section49299119344) - - [获取MIPI-DSI操作句柄](#section5126155683811) - - [MIPI-DSI相应配置](#section201164274344) - - [发送/回读控制指令](#section199401342173415) - - [释放MIPI-DSI操作句柄](#section161011610357) - -- [使用实例](#section17470126123520) - -## 概述 - -- DSI(Display Serial Interface)是由移动行业处理器接口联盟(Mobile Industry Processor Interface \(MIPI\) Alliance)制定的规范,旨在降低移动设备中显示控制器的成本。它以串行的方式发送像素数据或指令给外设\(通常是LCD或者类似的显示设备\),或从外设中读取状态信息或像素信息;它定义了主机、图像数据源和目标设备之间的串行总线和通信协议。 - -- MIPI-DSI具备高速模式和低速模式两种工作模式,全部数据通道都可以用于单向的高速传输,但只有第一个数据通道才可用于低速双向传输,从属端的状态信息、像素等是通过该数据通道返回。时钟通道专用于在高速传输数据的过程中传输同步时钟信号。 -- 图1显示了简化的DSI接口。从概念上看,符合DSI的接口与基于DBI-2和DPI-2标准的接口具有相同的功能。它向外围设备传输像素或命令数据,并且可以从外围设备读取状态或像素信息。主要区别在于,DSI对所有像素数据、命令和事件进行序列化,而在传统接口中,这些像素数据、命令和事件通常需要附加控制信号才能在并行数据总线上传输。 - - **图 1** DSI发送、接收接口 - ![](/images/device-dev/driver/figures/DSI发送-接收接口.png "DSI发送-接收接口") - - -## 接口说明 - -**表 1** MIPI-DSI API接口功能介绍 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名

-

描述

-

设置/获取当前MIPI-DSI相关配置

-

MipiDsiSetCfg

-

设置MIPI-DSI相关配置

-

MipiDsiGetCfg

-

获取当前MIPI-DSI相关配置

-

获取/释放MIPI-DSI操作句柄

-

MipiDsiOpen

-

获取MIPI-DSI操作句柄

-

MipiDsiClose

-

释放MIPI-DSI操作句柄

-

设置MIPI-DSI进入Low power模式/High speed模式

-

MipiDsiSetLpMode

-

设置MIPI-DSI进入Low power模式

-

MipiDsiSetHsMode

-

设置MIPI-DSI进入High speed模式

-

MIPI-DSI发送/回读指令

-

MipiDsiTx

-

MIPI-DSI发送相应指令的接口

-

MipiDsiRx

-

MIPI-DSI按期望长度回读的接口

-
- ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->本文涉及的所有接口,仅限内核态使用,不支持在用户态使用 - -## 使用指导 - -### 使用流程 - -使用MIPI-DSI的一般流程如[图2](#fig129103491241)所示。 - -**图 2** MIPI-DSI使用流程图 -![](/images/device-dev/driver/figures/MIPI-DSI使用流程图.png) - -### 获取MIPI-DSI操作句柄 - -在进行MIPI-DSI进行通信前,首先要调用MipiDsiOpen获取操作句柄,该函数会返回指定通道ID的操作句柄。 - -DevHandle MipiDsiOpen\(uint8\_t id\); - -**表 2** MipiDsiOpen的参数和返回值描述 - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

id

-

MIPI DSI通道ID

-

返回值

-

返回值描述

-

NULL

-

获取失败

-

设备句柄

-

获取到指令通道的操作句柄, 类型为DevHandle

-
- -假设系统中的MIPI-DSI通道为0,获取该通道操作句柄的示例如下: - -``` -DevHandle mipiDsiHandle = NULL; /* 设备句柄 */ -chnId = 0; /* MIPI-DSI通道ID */ - -/* 获取操作句柄 */ -mipiDsiHandle = MipiDsiOpen(chnId); -if (mipiDsiHandle == NULL) { - HDF_LOGE("MipiDsiOpen: failed\n"); - return; -} -``` - -### MIPI-DSI相应配置 - -- 写入MIPI-DSI配置 - -int32\_t MipiDsiSetCfg\(DevHandle handle, struct MipiCfg \*cfg\); - -**表 3** MipiDsiSetCfg的参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

操作句柄

-

cfg

-

MIPI-DSI相应配置buf 指针

-

返回值

-

返回值描述

-

0

-

设置成功

-

负数

-

设置失败

-
- -``` -int32_t ret; -struct MipiCfg cfg = {0}; - -/* 当前对接的屏幕配置如下 */ -cfg.lane = DSI_4_LANES; -cfg.mode = DSI_CMD_MODE; -cfg.burstMode = VIDEO_NON_BURST_MODE_SYNC_EVENTS; -cfg.format = FORMAT_RGB_24_BIT; -cfg.pixelClk = 174; -cfg.phyDataRate = 384; -cfg.timingInfo.hsaPixels = 50; -cfg.timingInfo.hbpPixels = 55; -cfg.timingInfo.hlinePixels = 1200; -cfg.timingInfo.yResLines = 1800; -cfg.timingInfo.vbpLines = 33; -cfg.timingInfo.vsaLines = 76; -cfg.timingInfo.vfpLines = 120; -cfg.timingInfo.xResPixels = 1342; -/* 写入配置数据 */ -ret = MipiDsiSetCfg(mipiDsiHandle, &cfg); -if (ret != 0) { - HDF_LOGE("%s: SetMipiCfg fail! ret=%d\n", __func__, ret); - return -1; -} -``` - -- 获取当前MIPI-DSI的配置 - -int32\_t MipiDsiGetCfg\(DevHandle handle, struct MipiCfg \*cfg\); - -**表 4** MipiDsiGetCfg的参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

操作句柄

-

cfg

-

MIPI-DSI相应配置buf 指针

-

返回值

-

返回值描述

-

0

-

获取成功

-

负数

-

获取失败

-
- -``` -int32_t ret; -struct MipiCfg cfg; -memset(&cfg, 0, sizeof(struct MipiCfg)); -ret = MipiDsiGetCfg(mipiDsiHandle, &cfg); -if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: GetMipiCfg fail!\n", __func__); - return HDF_FAILURE; -} -``` - -### 发送/回读控制指令 - -- 发送指令 - -int32\_t MipiDsiTx\(PalHandle handle, struct DsiCmdDesc \*cmd\); - -**表 5** MipiDsiTx的参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

操作句柄

-

cmd

-

需要发送的指令数据指针

-

返回值

-

返回值描述

-

0

-

发送成功

-

负数

-

发送失败

-
- -``` -int32_t ret; -struct DsiCmdDesc *cmd = OsalMemCalloc(sizeof(struct DsiCmdDesc)); -if (cmd == NULL) { - return HDF_FAILURE; -} -cmd->dtype = DTYPE_DCS_WRITE; -cmd->dlen = 1; -cmd->payload = OsalMemCalloc(sizeof(uint8_t)); -if (cmd->payload == NULL) { - HdfFree(cmd); - return HDF_FAILURE; -} -*(cmd->payload) = DTYPE_GEN_LWRITE; -MipiDsiSetLpMode(mipiHandle); -ret = MipiDsiTx(mipiHandle, cmd); -MipiDsiSetHsMode(mipiHandle); -if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: PalMipiDsiTx fail! ret=%d\n", __func__, ret); - HdfFree(cmd->payload); - HdfFree(cmd); - return HDF_FAILURE; -} -HdfFree(cmd->payload); -HdfFree(cmd); -``` - -- 回读指令 - -int32\_t MipiDsiRx\(DevHandle handle, struct DsiCmdDesc \*cmd, uint32\_t readLen, uint8\_t \*out\); - -**表 6** MipiDsiRx的参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

操作句柄

-

cmd

-

需要回读的指令数据指针

-

readLen

-

期望回读的数据长度

-

out

-

回读的数据buf指针

-

返回值

-

返回值描述

-

0

-

获取成功

-

负数

-

获取失败

-
- -``` -int32_t ret; -uint8_t readVal = 0; - -struct DsiCmdDesc *cmdRead = OsalMemCalloc(sizeof(struct DsiCmdDesc)); -if (cmdRead == NULL) { - return HDF_FAILURE; -} -cmdRead->dtype = DTYPE_DCS_READ; -cmdRead->dlen = 1; -cmdRead->payload = OsalMemCalloc(sizeof(uint8_t)); -if (cmdRead->payload == NULL) { - HdfFree(cmdRead); - return HDF_FAILURE; -} -*(cmdRead->payload) = DDIC_REG_STATUS; -MipiDsiSetLpMode(mipiDsiHandle); -ret = MipiDsiRx(mipiDsiHandle, cmdRead, sizeof(readVal), &readVal); -MipiDsiSetHsMode(mipiDsiHandle); -if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: MipiDsiRx fail! ret=%d\n", __func__, ret); - HdfFree(cmdRead->payload); - HdfFree(cmdRead); - return HDF_FAILURE; -} -HdfFree(cmdRead->payload); -HdfFree(cmdRead); -``` - -### 释放MIPI-DSI操作句柄 - -MIPI-DSI使用完成之后,需要释放操作句柄,释放句柄的函数如下所示: - -void MipiDsiClose\(DevHandle handle\); - -该函数会释放掉由MipiDsiOpen申请的资源。 - -**表 7** MipiDsiClose的参数和返回值描述 - - - - - - - - - - -

参数

-

参数描述

-

handle

-

MIPI-DSI操作句柄

-
- -``` -MipiDsiClose(mipiHandle); /* 释放掉MIPI-DSI操作句柄 */ -``` - -## 使用实例 - -MIPI-DSI完整的使用示例如下所示: - -``` -#include "hdf.h" -#include "mipi_dsi_if.h" - -void PalMipiDsiTestSample(void) -{ - uint8_t chnId; - int32_t ret; - DevHandle mipiDsiHandle = NULL; - - /* 设备通道编号 */ - chnId = 0; - /* 获取操作句柄 */ - mipiDsiHandle = MipiDsiOpen(chnId); - if (mipiDsiHandle == NULL) { - HDF_LOGE("MipiDsiOpen: failed!\n"); - return; - } - /* 配置相应参数 */ - struct MipiCfg cfg = {0}; - cfg.lane = DSI_4_LANES; - cfg.mode = DSI_CMD_MODE; - cfg.burstMode = VIDEO_NON_BURST_MODE_SYNC_EVENTS; - cfg.format = FORMAT_RGB_24_BIT; - cfg.pixelClk = 174; - cfg.phyDataRate = 384; - cfg.timingInfo.hsaPixels = 50; - cfg.timingInfo.hbpPixels = 55; - cfg.timingInfo.hlinePixels = 1200; - cfg.timingInfo.yResLines = 1800; - cfg.timingInfo.vbpLines = 33; - cfg.timingInfo.vsaLines = 76; - cfg.timingInfo.vfpLines = 120; - cfg.timingInfo.xResPixels = 1342; - /* 写入配置数据 */ - ret = MipiDsiSetCfg(mipiDsiHandle, &cfg); - if (ret != 0) { - HDF_LOGE("%s: SetMipiCfg fail! ret=%d\n", __func__, ret); - return; - } - /* 发送PANEL初始化指令 */ - struct DsiCmdDesc *cmd = OsalMemCalloc(sizeof(struct DsiCmdDesc)); - if (cmd == NULL) { - return; - } - cmd->dtype = DTYPE_DCS_WRITE; - cmd->dlen = 1; - cmd->payload = OsalMemCalloc(sizeof(uint8_t)); - if (cmd->payload == NULL) { - HdfFree(cmd); - return; - } - *(cmd->payload) = DTYPE_GEN_LWRITE; - MipiDsiSetLpMode(mipiHandle); - ret = MipiDsiTx(mipiHandle, cmd); - MipiDsiSetHsMode(mipiHandle); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: MipiDsiTx fail! ret=%d\n", __func__, ret); - HdfFree(cmd->payload); - HdfFree(cmd); - return; - } - HdfFree(cmd->payload); - HdfFree(cmd); - /* 回读panel状态寄存器 */ - uint8_t readVal = 0; - struct DsiCmdDesc *cmdRead = OsalMemCalloc(sizeof(struct DsiCmdDesc)); - if (cmdRead == NULL) { - return; - } - cmdRead->dtype = DTYPE_DCS_READ; - cmdRead->dlen = 1; - cmdRead->payload = OsalMemCalloc(sizeof(uint8_t)); - if (cmdRead->payload == NULL) { - HdfFree(cmdRead); - return; - } - *(cmdRead->payload) = DDIC_REG_STATUS; - MipiDsiSetLpMode(mipiDsiHandle); - ret = MipiDsiRx(mipiDsiHandle, cmdRead, sizeof(readVal), &readVal); - MipiDsiSetHsMode(mipiDsiHandle); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: MipiDsiRx fail! ret=%d\n", __func__, ret); - HdfFree(cmdRead->payload); - HdfFree(cmdRead); - return; - } - HdfFree(cmdRead->payload); - HdfFree(cmdRead); - /* 释放MIPI DSI设备句柄 */ - MipiDsiClose(handle); -} -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/03.\345\271\263\345\217\260\351\251\261\345\212\250\344\275\277\347\224\250/08.PWM.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/03.\345\271\263\345\217\260\351\251\261\345\212\250\344\275\277\347\224\250/08.PWM.md" deleted file mode 100644 index 763011a38905e5ca0c7b4ee230ef83db37c4ba8a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/03.\345\271\263\345\217\260\351\251\261\345\212\250\344\275\277\347\224\250/08.PWM.md" +++ /dev/null @@ -1,489 +0,0 @@ ---- -title: PWM -permalink: /pages/0105020308 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:24 ---- -# PWM - -- [概述](#section1_PWM_des) - - [PwmConfig结构体](#section1.1_PWM_des) -- [接口说明](#section2_PWM_des) -- [使用指导](#section3_PWM_des) - - [使用流程](#section3.1_PWM_des) - - [获取PWM设备句柄](#section3.2_PWM_des) - - [销毁PWM设备句柄](#section3.3_PWM_des) - - [使能](#section3.4_PWM_des) - - [禁用](#section3.5_PWM_des) - - [设置PWM设备周期](#section3.6_PWM_des) - - [设置PWM设备占空时间](#section3.7_PWM_des) - - [设置PWM设备极性](#section3.8_PWM_des) - - [设置PWM设备参数](#section3.9_PWM_des) - - [获取PWM设备参数](#section3.10_PWM_des) - -- [使用实例](#section3_PWM_des) - -## 概述 - -- PWM是脉冲宽度调制(Pulse Width Modulation)的缩写,是一种对模拟信号电平进行数字编码,转换为脉冲的一种技术。常用于马达控制、背光亮度调节等。 - -- PWM接口定义了操作PWM设备的通用方法集合,包括: - - PWM设备句柄获取和销毁。 - - PWM周期、占空比、极性的设置。 - - PWM使能和关闭。 - - PWM配置信息的获取和设置 - -### PwmConfig结构体 - -**表1** PwmConfig结构体介绍 - - - -| 名称 | 描述 | -| -------- | ------------------------------------------------------------ | -| duty | 占空时间,以纳秒为单位 | -| period | PWM周期,以纳秒为单位 | -| number | 要生成的方波数。正值表示将生成指定数量的方波,0表示方波将不断产生 | -| polarity | 极性:正极性/反极性 | -| status | 状态:启用状态/禁用状态 | - -## 接口说明 - -**表2** PWM设备API接口功能介绍 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
功能分类接口名描述
PWM句柄操作PwmOpen获取PWM设备驱动句柄
PwmClose释放PWM设备驱动句柄
使能/禁用PWMPwmEnable使能PWM
PwmDisable禁用PWM
PWM配置操作PwmSetPeriod设置PWM周期
PwmSetDuty设置PWM占空时间
PwmSetPolarity设置PWM极性
设置/获取PWM配置信息PwmSetConfig设置PWM设备参数
PwmGetConfig获取PWM设备参数
- - - - ->PWM当前仅限内核态使用,不支持在用户态使用。 - -## 使用指导 - -### 使用流程 - -在操作系统启动过程中,驱动管理模块根据配置文件加载PWM驱动,PWM驱动会检测PWM器件并初始化驱动。 - -使用PWM设备的一般流程如[图1](#fig1_PWM_des)所示。 - -**图 1** PWM设备使用流程图 - - -![](/images/device-dev/driver/figures/PWM设备使用流程图.png) - -### 获取PWM设备句柄 - -在操作PWM设备时,首先要调用PwmOpen获取PWM设备句柄,该函数会返回指定设备号的PWM设备句柄。 - -```c -DevHandle PwmOpen(uint32_t num); -``` - -**表3** PwmOpen参数和返回值描述 - - - -| 参数 | 参数描述 | -| ---------- | ----------------------- | -| num | PWM设备编号 | -| **返回值** | **返回值描述** | -| handle | 获取成功返回PWM设备句柄 | -| NULL | 获取失败 | - - -```c -uint32_t num = 0; /* PWM设备号 */ -DevHandle handle = NULL; - -/* 获取PWM设备句柄 */ -handle = PwmOpen(num); -if (handle == NULL) { - /* 错误处理 */ -} -``` - -### 销毁PWM设备句柄 - -关闭PWM设备,系统释放对应的资源。 - -```c -void PwmClose(DevHandle handle); -``` - -**表4** PwmClose参数描述 - - - -| 参数 | 参数描述 | -| ------ | ----------- | -| handle | PWM设备句柄 | - - -```c -/* 销毁PWM设备句柄 */ -PwmClose(handle); -``` - -### 使能 - -启用PWM设备。 - -```c -int32_t PwmEnable(DevHandle handle); -``` - -**表5** PwmEnable参数描述 - - - -| 参数 | 参数描述 | -| ---------- | -------------- | -| handle | PWM设备句柄 | -| **返回值** | **返回值描述** | -| 0 | 使能成功 | -| 负数 | 使能失败 | - -```c -int32_t ret; - -/*启用PWM设备*/ -ret = PwmEnable(handle); -if (ret != 0) { - /*错误处理*/ -} -``` - -### 禁用 - -禁用PWM设备。 - -```c -int32_t PwmDisable(DevHandle handle); -``` - -**表6** PwmDisable参数描述 - - - -| 参数 | 参数描述 | -| ---------- | -------------- | -| handle | PWM设备句柄 | -| **返回值** | **返回值描述** | -| 0 | 禁用成功 | -| 负数 | 禁用失败 | - -```c -int32_t ret; - -/*禁用PWM设备*/ -ret = PwmDisable(handle); -if (ret != 0) { - /*错误处理*/ -} -``` - -### 设置PWM设备周期 - -设置PWM设备周期。 - -```c -int32_t PwmSetPeriod(DevHandle handle, uint32_t period); -``` - -**表7** PwmSetPeriod参数描述 - - - -| 参数 | 参数描述 | -| ---------- | ------------------------ | -| handle | PWM设备句柄 | -| period | 要设置的周期,单位为纳秒 | -| **返回值** | **返回值描述** | -| 0 | 设置成功 | -| 负数 | 设置失败 | - -```c -int32_t ret; - -/*设置周期为50000000纳秒*/ -ret = PwmSetPeriod(handle, 50000000); -if (ret != 0) { - /*错误处理*/ -} -``` -### 设置PWM设备占空时间 - -设置PWM设备占空时间。 - -```c -int32_t PwmSetDuty(DevHandle handle, uint32_t duty); -``` - -**表8** PwmSetDuty参数描述 - - - -| 参数 | 参数描述 | -| ---------- | ---------------------------- | -| handle | PWM设备句柄 | -| duty | 要设置的占空时间,单位为纳秒 | -| **返回值** | **返回值描述** | -| 0 | 设置成功 | -| 负数 | 设置失败 | - -```c -int32_t ret; - -/*设置占空时间为25000000纳秒*/ -ret = PwmSetDuty(handle, 25000000); -if (ret != 0) { - /*错误处理*/ -} -``` -### 设置PWM设备极性 - -设置PWM设备极性。 - -```c -int32_t PwmSetPolarity(DevHandle handle, uint8_t polarity); -``` - -**表9** PwmSetPolarity参数描述 - - - -| 参数 | 参数描述 | -| ---------- | ------------------- | -| handle | PWM设备句柄 | -| polarity | 要设置的极性,正/反 | -| **返回值** | **返回值描述** | -| 0 | 设置成功 | -| 负数 | 设置失败 | - -```c -int32_t ret; - -/*设置极性为反*/ -ret = PwmSetPolarity(handle, PWM_INVERTED_POLARITY); -if (ret != 0) { - /*错误处理*/ -} -``` - - -### 设置PWM设备参数 - -设置PWM设备参数。 - -```c -int32_t PwmSetConfig(DevHandle handle, struct PwmConfig *config); -``` - -**表10** PwmSetConfig参数描述 - - - -| 参数 | 参数描述 | -| ---------- | -------------- | -| handle | PWM设备句柄 | -| *config | 参数指针 | -| **返回值** | **返回值描述** | -| 0 | 设置成功 | -| 负数 | 设置失败 | - -```c -int32_t ret; -struct PwmConfig pcfg; -pcfg.duty = 25000000; /*占空时间为25000000纳秒*/ -pcfg.period = 50000000; /*周期为50000000纳秒*/ -pcfg.number = 0; /*不断产生方波*/ -pcfg.polarity = PWM_INVERTED_POLARITY; /*极性为反*/ -pcfg.status = PWM_ENABLE_STATUS; /*运行状态为启用*/ - -/*设置PWM设备参数*/ -ret = PwmSetConfig(handle, &pcfg); -if (ret != 0) { - /*错误处理*/ -} -``` - -### 获取PWM设备参数 - -获取PWM设备参数。 - -```c -int32_t PwmGetConfig(DevHandle handle, struct PwmConfig *config); -``` - -**表11** PwmGetConfig参数描述 - - - -| 参数 | 参数描述 | -| ---------- | -------------- | -| handle | PWM设备句柄 | -| *config | 参数指针 | -| **返回值** | **返回值描述** | -| 0 | 获取成功 | -| 负数 | 获取失败 | - -```c -int32_t ret; -struct PwmConfig pcfg; - -/*获取PWM设备参数*/ -ret = PwmGetConfig(handle, &pcfg); -if (ret != 0) { - /*错误处理*/ -} -``` - -## 使用实例 - -PWM设备完整的使用示例如下所示,首先获取PWM设备句柄,然后设置设备周期、占空时间、极性,获取设备参数。使能,设置设备参数,禁用,最后销毁PWM设备句柄。 - -``` -void PwmTestSample(void) -{ - int32_t ret; - uint32_t num; - DevHandle handle = NULL; - - struct PwmConfig pcfg; - pcfg.duty = 20000000; /*占空时间为20000000纳秒*/ - pcfg.period = 40000000; /*周期为40000000纳秒*/ - pcfg.number = 100; /*生成100个方波*/ - pcfg.polarity = PWM_NORMAL_POLARITY; /*极性为正*/ - pcfg.status = PWM_ENABLE_STATUS; /*运行状态为启用*/ - - /* PWM设备编号,要填写实际平台上的编号 */ - num = 1; - - /* 获取PWM设备句柄 */ - handle = PwmOpen(num); - if (handle == NULL) { - HDF_LOGE("PwmOpen: failed!\n"); - return; - } - - /*设置周期为50000000纳秒*/ - ret = PwmSetPeriod(handle, 50000000); - if (ret != 0) { - HDF_LOGE("PwmSetPeriod: failed, ret %d\n", ret); - goto _ERR; - } - - /*设置占空时间为25000000纳秒*/ - ret = PwmSetDuty(handle, 25000000); - if (ret != 0) { - HDF_LOGE("PwmSetDuty: failed, ret %d\n", ret); - goto _ERR; - } - - /*设置极性为反*/ - ret = PwmSetPolarity(handle, PWM_INVERTED_POLARITY); - if (ret != 0) { - HDF_LOGE("PwmSetPolarity: failed, ret %d\n", ret); - goto _ERR; - } - - /*获取PWM设备参数*/ - ret = PwmGetConfig(handle, &pcfg); - if (ret != 0) { - HDF_LOGE("PwmGetConfig: failed, ret %d\n", ret); - goto _ERR; - } - - /*启用PWM设备*/ - ret = PwmEnable(handle); - if (ret != 0) { - HDF_LOGE("PwmEnable: failed, ret %d\n", ret); - goto _ERR; - } - - /*设置PWM设备参数*/ - ret = PwmSetConfig(handle, &pcfg); - if (ret != 0) { - HDF_LOGE("PwmSetConfig: failed, ret %d\n", ret); - goto _ERR; - } - - /*禁用PWM设备*/ - ret = PwmDisable(handle); - if (ret != 0) { - HDF_LOGE("PwmDisable: failed, ret %d\n", ret); - goto _ERR; - } - -_ERR: - /* 销毁PWM设备句柄 */ - PwmClose(handle); -} -``` diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/03.\345\271\263\345\217\260\351\251\261\345\212\250\344\275\277\347\224\250/09.RTC.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/03.\345\271\263\345\217\260\351\251\261\345\212\250\344\275\277\347\224\250/09.RTC.md" deleted file mode 100644 index 874a926c28dd113377872b921ef8984989164593..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/03.\345\271\263\345\217\260\351\251\261\345\212\250\344\275\277\347\224\250/09.RTC.md" +++ /dev/null @@ -1,954 +0,0 @@ ---- -title: RTC -permalink: /pages/0105020309 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:24 ---- -# RTC - -- [概述](#section104842041574) -- [接口说明](#section20331159102519) -- [使用指导](#section20636145604113) - - [使用流程](#section16919828134215) - - [创建RTC设备句柄](#section1131212144310) - - [销毁RTC设备句柄](#section10744117144314) - - [注册RTC定时报警回调函数](#section14839440184320) - - [操作RTC](#section161927578433) - -- [使用实例](#section1186111020456) - -## 概述 - -RTC\(real-time clock\)为操作系统中的实时时钟设备,为操作系统提供精准的实时时间和定时报警功能。当设备下电后,通过外置电池供电,RTC继续记录操作系统时间;设备上电后,RTC提供实时时钟给操作系统,确保断电后系统时间的连续性。 - -## 接口说明 - -**表 1** RTC设备API接口功能介绍 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名

-

描述

-

RTC句柄操作

-

RtcOpen

-

获取RTC设备驱动句柄

-

RtcClose

-

释放RTC设备驱动句柄

-

RTC时间操作接口

-

RtcReadTime

-

读RTC时间信息,包括年、月、星期、日、时、分、秒、毫秒

-

RtcWriteTime

-

写RTC时间信息,包括年、月、星期、日、时、分、秒、毫秒

-

RTC报警操作接口

-

RtcReadAlarm

-

读RTC报警时间信息

-

RtcWriteAlarm

-

写RTC报警时间信息

-

RtcRegisterAlarmCallback

-

注册报警超时回调函数

-

RtcAlarmInterruptEnable

-

使能/去使能RTC报警中断

-

RTC配置操作

-

RtcGetFreq

-

读RTC外接晶振频率

-

RtcSetFreq

-

配置RTC外接晶振频率

-

RtcReset

-

RTC复位

-

读写用户定义寄存器

-

RtcReadReg

-

读用户自定义寄存器

-

RtcWriteReg

-

写用户自定义寄存器

-
- ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->本文涉及的所有接口,仅限内核态使用,不支持在用户态使用。 - -## 使用指导 - -### 使用流程 - -在操作系统启动过程中,驱动管理模块根据配置文件加载RTC驱动,RTC驱动会检测RTC器件并初始化驱动。 - -使用RTC设备的一般流程如[图1](#fig1610020107333)所示。 - -**图 1** RTC设备使用流程图 -![](/images/device-dev/driver/figures/RTC设备使用流程图.png "RTC设备使用流程图") - -### 创建RTC设备句柄 - -RTC驱动加载成功后,驱动开发者使用驱动框架提供的查询接口并调用RTC设备驱动接口。 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->当前操作系统支持一个RTC设备。 - -DevHandle RtcOpen\(void\); - -**表 2** RtcOpen参数和返回值描述 - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

void

-

NA

-

返回值

-

返回值描述

-

handle

-

操作成功返回 指针类型

-

NULL

-

操作失败

-
- -``` -DevHandle handle = NULL; - -/* 获取RTC句柄 */ -handle = RtcOpen(); -if (handle == NULL) { - /* 错误处理 */ -} -``` - -### 销毁RTC设备句柄 - -销毁RTC设备句柄,系统释放对应的资源。 - -void RtcClose\(DevHandle handle\); - -**表 3** RtcClose参数描述 - - - - - - - - - -

参数

-

参数描述

-

handle

-

RTC设备句柄

-
- -``` -/* 销毁RTC句柄 */ -RtcClose(handle); -``` - -### 注册RTC定时报警回调函数 - -系统启动后需要注册RTC定时报警回调函数,报警超时后触发回调函数。 - -int32\_t RtcRegisterAlarmCallback\(DevHandle handle, enum RtcAlarmIndex alarmIndex, RtcAlarmCallback cb\); - -**表 4** RtcRegisterAlarmCallback参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

RTC设备句柄

-

alarmIndex

-

报警索引

-

cb

-

定时报警回调函数

-

返回值

-

返回值描述

-

0

-

操作成功

-

负数

-

操作失败

-
- -注册RTC\_ALARM\_INDEX\_A的定时报警处理函数, 示例如下: - -``` -/* 用户注册RTC定时报警回调函数的方法 */ -int32_t RtcAlarmACallback(enum RtcAlarmIndex alarmIndex) -{ - if (alarmIndex == RTC_ALARM_INDEX_A) { - /* 报警A的处理 */ - } else if (alarmIndex == RTC_ALARM_INDEX_B) { - /* 报警B的处理 */ - } else { - /* 错误处理 */ - } - return 0; -} -int32_t ret; -/* 注册报警A的定时回调函数 */ -ret = RtcRegisterAlarmCallback(handle, RTC_ALARM_INDEX_A, RtcAlarmACallback); -if (ret != 0) { - /* 错误处理 */ -} -``` - -### 操作RTC - -- 读取RTC时间。 - -系统从RTC读取时间信息,包括年、月、星期、日、时、分、秒、毫秒,则可以通过以下函数完成: - -int32\_t RtcReadTime\(DevHandle handle, struct RtcTime \*time\); - -**表 5** RtcReadTime参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

RTC设备句柄

-

time

-

RTC读取时间信息,包括年、月、星期、日、时、分、秒、毫秒

-

返回值

-

返回值描述

-

0

-

操作成功

-

负数

-

操作失败

-
- -``` -int32_t ret; -struct RtcTime tm; - -/* 系统从RTC读取时间信息 */ -ret = RtcReadTime(handle, &tm); -if (ret != 0) { - /* 错误处理 */ -} -``` - -- 设置RTC时间 - -设置RTC时间,则可以通过以下函数完成: - -int32\_t RtcWriteTime\(DevHandle handle, struct RtcTime \*time\); - -**表 6** RtcWriteTime参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

RTC设备句柄

-

time

-

写RTC时间信息,包括年、月、星期、日、时、分、秒、毫秒

-

返回值

-

返回值描述

-

0

-

操作成功

-

负数

-

操作失败

-
- ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->RTC起始时间为UTC 1970/01/01 Thursday 00:00:00,年的最大取值按照用户器件手册要求计算配置,星期不用配置。 - -``` -int32_t ret; -struct RtcTime tm; - -/* 设置RTC时间为 UTC 2020/01/01 00:59:00 .000 */ -tm.year = 2020; -tm.month = 01; -tm.day = 01; -tm.hour= 00; -tm.minute = 59; -tm.second = 00; -tm.millisecond = 0; -/* 写RTC时间信息 */ -ret = RtcWriteTime(handle, &tm); -if (ret != 0) { - /* 错误处理 */ -} -``` - -- 读取RTC报警时间 - -如果需要读取定时报警时间,则可以通过以下函数完成: - -int32\_t RtcReadAlarm\(DevHandle handle, enum RtcAlarmIndex alarmIndex, struct RtcTime \*time\); - -**表 7** RtcReadAlarm参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

RTC设备句柄

-

alarmIndex

-

报警索引

-

time

-

RTC报警时间信息,包括年、月、星期、日、时、分、秒、毫秒

-

返回值

-

返回值描述

-

0

-

操作成功

-

负数

-

操作失败

-
- -``` -int32_t ret; -struct RtcTime alarmTime; - -/* 读RTC_ALARM_INDEX_A索引的RTC定时报警时间信息 */ -ret = RtcReadAlarm(handle, RTC_ALARM_INDEX_A, &alarmTime); -if (ret != 0) { - /* 错误处理 */ -} -``` - -- 设置RTC报警时间 - -根据报警索引设置RTC报警时间,通过以下函数完成: - -int32\_t RtcWriteAlarm\(DevHandle handle, enum RtcAlarmIndex alarmIndex, struct RtcTime \*time\); - -**表 8** RtcWriteAlarm参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

RTC设备句柄

-

alarmIndex

-

报警索引

-

time

-

RTC报警时间信息,包括年、月、星期、日、时、分、秒、毫秒

-

返回值

-

返回值描述

-

0

-

操作成功

-

负数

-

操作失败

-
- ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->RTC起始时间为UTC 1970/01/01 Thursday 00:00:00,年的最大取值按照用户器件手册要求计算配置,星期不用配置。 - -``` -int32_t ret; -struct RtcTime alarmTime; - -/* 设置RTC报警时间为2020/01/01 00:59:59 .000 */ -alarmTime.year = 2020; -alarmTime.month = 01; -alarmTime.day = 01; -alarmTime.hour = 00; -alarmTime.minute = 59; -alarmTime.second = 59; -alarmTime.millisecond = 0; -/* 设置RTC_ALARM_INDEX_A索引的定时报警时间 */ -ret = RtcWriteAlarm(handle, RTC_ALARM_INDEX_A, &alarmTime); -if (ret != 0) { - /* 错误处理 */ -} -``` - -- 设置定时报警中断使能或去使能 - -在启动报警操作前,需要先设置报警中断使能,报警超时后会触发告警回调函数,可以通过以下函数完成: - -int32\_t RtcAlarmInterruptEnable\(DevHandle handle, enum RtcAlarmIndex alarmIndex, uint8\_t enable\); - -**表 9** RtcAlarmInterruptEnable参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

RTC设备句柄

-

alarmIndex

-

报警索引

-

enable

-

RTC报警中断配置,1:使能,0:去使能

-

返回值

-

返回值描述

-

0

-

操作成功

-

负数

-

操作失败

-
- -``` -int32_t ret; - -/* 设置RTC报警中断使能 */ -ret = RtcAlarmInterruptEnable(handle, RTC_ALARM_INDEX_A, 1); -if (ret != 0) { - /* 错误处理 */ -} -``` - -- 读取RTC外频 - -读取RTC外接晶体振荡频率,可以通过以下函数完成: - -int32\_t RtcGetFreq\(DevHandle handle, uint32\_t \*freq\); - -**表 10** RtcGetFreq参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

RTC设备句柄

-

freq

-

RTC的外接晶体振荡频率,单位(HZ)

-

返回值

-

返回值描述

-

0

-

操作成功

-

负数

-

操作失败

-
- -``` -int32_t ret; -uint32_t freq = 0; - -/* 读取RTC外接晶体振荡频率 */ -ret = RtcGetFreq(handle, &freq); -if (ret != 0) { - /* 错误处理 */ -} -``` - -- 配置RTC外频 - -配置RTC外接晶体振荡频率,可以通过以下函数完成: - -int32\_t RtcSetFreq\(DevHandle handle, uint32\_t freq\); - -**表 11** RtcSetFreq参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

RTC设备句柄

-

freq

-

RTC的外接晶体振荡频率,单位(HZ)

-

返回值

-

返回值描述

-

0

-

操作成功

-

负数

-

操作失败

-
- -``` -int32_t ret; -uint32_t freq = 32768; /* 32768 Hz */ - -/* 设置RTC外接晶体振荡频率,注意按照器件手册要求配置RTC外频 */ -ret = RtcSetFreq(handle, freq); -if (ret != 0) { - /* 错误处理 */ -} -``` - -- 复位RTC - -复位RTC,复位RTC后各配置寄存器恢复默认值,可以通过以下函数完成: - -int32\_t RtcReset\(DevHandle handle\); - -**表 12** RtcReset参数和返回值描述 - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

RTC设备句柄

-

返回值

-

返回值描述

-

0

-

操作成功

-

负数

-

操作失败

-
- -``` -int32_t ret; - -/* 复位RTC,复位RTC后各配置寄存器恢复默认值 */ -ret = RtcReset(handle); -if (ret != 0) { - /* 错误处理 */ -} -``` - -- 读取RTC自定义寄存器配置 - -按照用户定义的寄存器索引,读取对应的寄存器配置,一个索引对应一字节的配置值,通过以下函数完成: - -int32\_t RtcReadReg\(DevHandle handle, uint8\_t usrDefIndex, uint8\_t \*value\); - -**表 13** RtcReadReg参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

RTC设备句柄

-

usrDefIndex

-

用户定义的寄存器对应索引

-

value

-

寄存器值

-

返回值

-

返回值描述

-

0

-

操作成功

-

负数

-

操作失败

-
- -``` -int32_t ret; -uint8_t usrDefIndex = 0; /* 定义0索引对应用户定义的第一个寄存器*/ -uint8_t value = 0; - -/* 按照用户定义的寄存器索引,读取对应的寄存器配置,一个索引对应一字节的配置值 */ -ret = RtcReadReg(handle, usrDefIndex, &value); -if (ret != 0) { - /* 错误处理 */ -} -``` - -- 设置RTC自定义寄存器配置 - -按照用户定义的寄存器索引,设置对应的寄存器配置,一个索引对应一字节的配置值,通过以下函数完成: - -int32\_t RtcWriteReg\(DevHandle handle, uint8\_t usrDefIndex, uint8\_t value\); - -**表 14** RtcWriteReg参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

RTC设备句柄

-

usrDefIndex

-

用户定义的寄存器对应索引

-

value

-

寄存器值

-

返回值

-

返回值描述

-

0

-

操作成功

-

负数

-

操作失败

-
- -``` -int32_t ret; -uint8_t usrDefIndex = 0; /* 定义0索引对应用户定义第一个寄存器*/ -uint8_t value = 0x10; - -/* 按照用户的定义的寄存器索引,设置对应的寄存器配置,一个索引对应一字节的配置值 */ -ret = RtcWriteReg(handle, usrDefIndex, value); -if (ret != 0) { - /* 错误处理 */ -} -``` - -## 使用实例 - -本实例提供RTC接口的完整使用流程: - -1. 系统启动,驱动管理模块会识别系统当前的RTC器件; -2. 驱动管理模块完成RTC设备的初始化和设备创建; -3. 用户通过不同API,对该RTC设备进行对应的操作; -4. 关闭RTC设备,释放设备资源。 - -示例如下: - -``` -#include "rtc_if.h" -int32_t RtcAlarmACallback(enum RtcAlarmIndex alarmIndex) -{ - if (alarmIndex == RTC_ALARM_INDEX_A) { - /* 报警A的处理 */ - printf("RTC Alarm A callback function\n\r"); - } else if (alarmIndex == RTC_ALARM_INDEX_B) { - /* 报警B的处理 */ - printf("RTC Alarm B callback function\n\r"); - } else { - /* 错误处理 */ - } - return 0; -} - -void RtcTestSample(void) -{ - int32_t ret; - struct RtcTime tm; - struct RtcTime alarmTime; - uint32_t freq; - DevHandle handle = NULL; - - /* 获取RTC设备句柄 */ - handle = RtcOpen(); - if (handle == NULL) { - /* 错误处理 */ - } - /* 注册报警A的定时回调函数 */ - ret = RtcRegisterAlarmCallback(handle, RTC_ALARM_INDEX_A, RtcAlarmACallback); - if (ret != 0) { - /* 错误处理 */ - } - /* 设置RTC外接晶体振荡频率,注意按照器件手册要求配置RTC外频 */ - freq = 32768; /* 32768 Hz */ - ret = RtcSetFreq(handle, freq); - if (ret != 0) { - /* 错误处理 */ - } - /* 设置RTC报警中断使能 */ - ret = RtcAlarmInterruptEnable(handle, RTC_ALARM_INDEX_A, 1); - if (ret != 0) { - /* 错误处理 */ - } - /* 设置RTC时间为2020/01/01 00:00:10 .990 */ - tm.year = 2020; - tm.month = 01; - tm.day = 01; - tm.hour= 0; - tm.minute = 0; - tm.second = 10; - tm.millisecond = 990; - /* 写RTC时间信息 */ - ret = RtcWriteTime(handle, &tm); - if (ret != 0) { - /* 错误处理 */ - } - /* 设置RTC报警时间为2020/01/01 00:00:30 .100 */ - alarmTime.year = 2020; - alarmTime.month = 01; - alarmTime.day = 01; - alarmTime.hour = 0; - alarmTime.minute = 0; - alarmTime.second = 30; - alarmTime.millisecond = 100; - /* 设置RTC_ALARM_INDEX_A索引定时报警时间信息, 定时时间到后会打印"RTC Alarm A callback function" */ - ret = RtcWriteAlarm(handle, RTC_ALARM_INDEX_A, &alarmTime); - if (ret != 0) { - /* 错误处理 */ - } - - /* 读取RTC实时时间 */ - ret = RtcReadTime(handle, &tm); - if (ret != 0) { - /* 错误处理 */ - } - sleep(5) - printf("RTC read time:\n\r"); - printf("year-month-date-weekday hour:minute:second .millisecond %04u-%02u-%02u-%u %02u:%02u:%02u .%03u", - tm.year, tm.month, tm.day, tm.weekday, tm.hour, tm.minute, tm.second, tm.millisecond); - /* 销毁RTC设备句柄 */ - RtcClose(handle); -} -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/03.\345\271\263\345\217\260\351\251\261\345\212\250\344\275\277\347\224\250/10.SDIO.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/03.\345\271\263\345\217\260\351\251\261\345\212\250\344\275\277\347\224\250/10.SDIO.md" deleted file mode 100644 index 790f4b99e9095a3bf67879fd3d9da8a880ff9760..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/03.\345\271\263\345\217\260\351\251\261\345\212\250\344\275\277\347\224\250/10.SDIO.md" +++ /dev/null @@ -1,1076 +0,0 @@ ---- -title: SDIO -permalink: /pages/010502030a -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:24 ---- -# SDIO - -- [概述](#section1155271783811) -- [接口说明](#section12601496259) -- [使用指导](#section1878939192515) - - [使用流程](#section1490685512255) - - [打开SDIO控制器](#section10782428132616) - - [独占HOST](#section11263172312715) - - [使能SDIO设备](#section17861486271) - - [注册SDIO中断](#section521213262286) - - [进行SDIO通信](#section85661522153420) - - [释放SDIO中断](#section1683449352) - - [去使能SDIO设备](#section15379324143611) - - [释放HOST](#section536018263713) - - [关闭SDIO控制器](#section4752739183716) - -- [使用实例](#section376910122382) - -## 概述 - -- SDIO是安全数字输入输出接口(Secure Digital Input and Output)的缩写,是从SD内存卡接口的基础上演化出来的一种外设接口。SDIO接口兼容以前的SD内存卡,并且可以连接支持SDIO接口的设备。 -- SDIO的应用比较广泛,目前,有许多手机都支持SDIO功能,并且很多SDIO外设也被开发出来,使得手机外接外设更加容易。常见的SDIO外设有WLAN、GPS、CAMERA、蓝牙等。 -- SDIO总线有两端,其中一端是主机端(HOST),另一端是设备端(DEVICE)。所有的通信都是由HOST端发出命令开始的,在DEVICE端只要能解析HOST的命令,就可以同HOST进行通信了。SDIO的HOST可以连接多个DEVICE,如下图所示: - - - CLK信号:HOST给DEVICE的时钟信号。 - - VDD信号:电源信号。 - - VSS信号:Ground信号。 - - D0-3信号:4条数据线,其中,DAT1信号线复用为中断线,在1BIT模式下DAT0用来传输数据,在4BIT模式下DAT0-DAT3用来传输数据。 - - CMD信号:用于HOST发送命令和DEVICE回复响应。 - - **图 1** SDIO的HOST-DEVICE连接示意图 - ![](/images/device-dev/driver/figures/SDIO的HOST-DEVICE连接示意图.png "SDIO的HOST-DEVICE连接示意图") - -- SDIO接口定义了操作SDIO的通用方法集合,包括打开/关闭SDIO控制器、独占/释放HOST、使能/去使能设备、申请/释放中断、读写、获取/设置公共信息等。 - -## 接口说明 - -**表 1** SDIO驱动API接口功能介绍 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名

-

描述

-

SDIO设备打开/关闭接口

-

SdioOpen

-

打开指定总线号的SDIO控制器

-

SdioClose

-

关闭SDIO控制器

-

SDIO读写接口

-

SdioReadBytes

-

从指定地址开始,增量读取指定长度的数据

-

SdioWriteBytes

-

从指定地址开始,增量写入指定长度的数据

-

SdioReadBytesFromFixedAddr

-

从固定地址读取指定长度的数据

-

SdioWriteBytesToFixedAddr

-

向固定地址写入指定长度的数据

-

SdioReadBytesFromFunc0

-

从SDIO function 0的指定地址空间读取指定长度的数据

-

SdioWriteBytesToFunc0

-

向SDIO function 0的指定地址空间写入指定长度的数据

-

SDIO设置块大小接口

-

SdioSetBlockSize

-

设置块的大小

-

SDIO获取/设置公共信息接口

-

SdioGetCommonInfo

-

获取公共信息

-

SdioSetCommonInfo

-

设置公共信息

-

SDIO刷新数据接口

-

SdioFlushData

-

刷新数据

-

SDIO独占/释放HOST接口

-

SdioClaimHost

-

独占Host

-

SdioReleaseHost

-

释放Host

-

SDIO使能/去使能功能设备接口

-

SdioEnableFunc

-

使能SDIO功能设备

-

SdioDisableFunc

-

去使能SDIO功能设备

-

SDIO申请/释放中断接口

-

SdioClaimIrq

-

申请中断

-

SdioReleaseIrq

-

释放中断

-
- ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->本文涉及的所有接口,目前只支持在内核态使用,不支持在用户态使用。 - -## 使用指导 - -### 使用流程 - -使用SDIO的一般流程如[图2](#fig1969028202613)所示。 - -**图 2** SDIO使用流程图 -![](/images/device-dev/driver/figures/SDIO使用流程图.png "SDIO使用流程图") - -### 打开SDIO控制器 - -在使用SDIO进行通信前,首先要调用SdioOpen获取SDIO控制器的设备句柄,该函数会返回指定总线号的SDIO控制器的设备句柄。 - -DevHandle SdioOpen\(int16\_t mmcBusNum, struct SdioFunctionConfig \*config\); - -**表 2** SdioOpen函数的参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

mmcBusNum

-

总线号

-

config

-

SDIO功能配置信息

-

返回值

-

返回值描述

-

NULL

-

获取SDIO控制器的设备句柄失败

-

设备句柄

-

SDIO控制器的设备句柄

-
- -打开SDIO控制器的示例如下: - -``` -DevHandle handle = NULL; -struct SdioFunctionConfig config; -config.funcNr = 1; -config.vendorId = 0x123; -config.deviceId = 0x456; -/* 打开总线号为1的SDIO控制器 */ -handle = SdioOpen(1, &config); -if (handle == NULL) { - HDF_LOGE("SdioOpen: failed!\n"); -} -``` - -### 独占HOST - -获取到SDIO控制器的设备句柄之后,需要先独占HOST才能进行SDIO后续的一系列操作,独占HOST函数如下所示: - -void SdioClaimHost\(DevHandle handle\); - -**表 3** SdioClaimHost函数的参数描述 - - - - - - - - - - -

参数

-

参数描述

-

handle

-

SDIO控制器的设备句柄

-
- -独占HOST示例如下: - -``` -SdioClaimHost(handle); /* 独占HOST */ -``` - -### 使能SDIO设备 - -在访问寄存器之前,需要先使能SDIO设备,使能SDIO设备的函数如下所示: - -int32\_t SdioEnableFunc\(DevHandle handle\); - -**表 4** SdioEnableFunc函数的参数和返回值描述 - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

SDIO控制器的设备句柄

-

返回值

-

返回值描述

-

0

-

SDIO使能成功

-

负数

-

SDIO使能失败

-
- -使能SDIO设备的示例如下: - -``` -int32_t ret; -/* 使能SDIO设备 */ -ret = SdioEnableFunc(handle); -if (ret != 0) { - HDF_LOGE("SdioEnableFunc: failed, ret %d\n", ret); -} -``` - -### 注册SDIO中断 - -在通信之前,还需要注册SDIO中断,注册SDIO中断函数如下图所示: - -int32\_t SdioClaimIrq\(DevHandle handle, SdioIrqHandler \*handler\); - -**表 5** SdioClaimIrq函数的参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

SDIO控制器的设备句柄

-

handler

-

中断服务函数指针

-

返回值

-

返回值描述

-

0

-

注册中断成功

-

负数

-

注册中断失败

-
- -注册SDIO中的示例如下: - -``` -/* 中断服务函数需要根据各自平台的情况去实现 */ -static void SdioIrqFunc(void *data) -{ - if (data == NULL) { - HDF_LOGE("SdioIrqFunc: data is NULL.\n"); - return; - } - /* 需要开发者自行添加具体实现 */ -} - -int32_t ret; -/* 注册SDIO中断 */ -ret = SdioClaimIrq(handle, SdioIrqFunc); -if (ret != 0) { - HDF_LOGE("SdioClaimIrq: failed, ret %d\n", ret); -} -``` - -### 进行SDIO通信 - -- 向SDIO设备增量写入指定长度的数据 - -对应的接口函数如下所示: - -int32\_t SdioWriteBytes\(DevHandle handle, uint8\_t \*data, uint32\_t addr, uint32\_t size\); - -**表 6** SdioWriteBytes函数的参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

SDIO控制器的设备句柄

-

data

-

待写入数据的指针

-

addr

-

待写入数据的起始地址

-

size

-

待写入数据的长度

-

返回值

-

返回值描述

-

0

-

SDIO写数据成功

-

负数

-

SDIO写数据失败

-
- -向SDIO设备增量写入指定长度的数据的示例如下: - -``` -int32_t ret; -uint8_t wbuff[] = {1,2,3,4,5}; -uint32_t addr = 0x100 + 0x09; -/* 向SDIO设备起始地址0x109,增量写入5个字节的数据 */ -ret = SdioWriteBytes(handle, wbuff, addr, sizeof(wbuff) / sizeof(wbuff[0])); -if (ret != 0) { - HDF_LOGE("SdioWriteBytes: failed, ret %d\n", ret); -} -``` - -- 从SDIO设备增量读取指定长度的数据 - -对应的接口函数如下所示: - -int32\_t SdioReadBytes\(DevHandle handle, uint8\_t \*data, uint32\_t addr, uint32\_t size\); - -**表 7** SdioReadBytes函数的参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

SDIO控制器的设备句柄

-

data

-

接收读取数据的指针

-

addr

-

待读取数据的起始地址

-

size

-

待读取数据的长度

-

返回值

-

返回值描述

-

0

-

SDIO读数据成功

-

负数

-

SDIO读数据失败

-
- -从SDIO设备增量读取指定长度的数据的示例如下: - -``` -int32_t ret; -uint8_t rbuff[5] = {0}; -uint32_t addr = 0x100 + 0x09; -/* 从SDIO设备起始地址0x109,增量读取5个字节的数据 */ -ret = SdioReadBytes(handle, rbuff, addr, 5); -if (ret != 0) { - HDF_LOGE("SdioReadBytes: failed, ret %d\n", ret); -} -``` - -- 向SDIO设备的固定地址写入指定长度的数据 - - 对应的接口函数如下所示: - - int32\_t SdioWriteBytesToFixedAddr\(DevHandle handle, uint8\_t \*data, uint32\_t addr, uint32\_t size, uint32\_t scatterLen\); - - **表 8** SdioWriteBytesToFixedAddr函数的参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

SDIO控制器的设备句柄

-

data

-

待写入数据的指针

-

addr

-

待写入数据的固定地址

-

size

-

待写入数据的长度

-

scatterLen

-

集散表的长度。如果该字段不为0,则data为集散表类型。

-

返回值

-

返回值描述

-

0

-

SDIO写数据成功

-

负数

-

SDIO写数据失败

-
- - 向SDIO设备的固定地址写入指定长度的数据的示例如下: - - ``` - int32_t ret; - uint8_t wbuff[] = {1,2,3,4,5}; - uint32_t addr = 0x100 + 0x09; - /* 向SDIO设备固定地址0x109写入5个字节的数据 */ - ret = SdioWriteBytesToFixedAddr(handle, wbuff, addr, sizeof(wbuff) / sizeof(wbuff[0]), 0); - if (ret != 0) { - HDF_LOGE("SdioWriteBytesToFixedAddr: failed, ret %d\n", ret); - } - ``` - -- 从SDIO设备的固定地址读取指定长度的数据 - - 对应的接口函数如下所示: - - int32\_t SdioReadBytesFromFixedAddr\(DevHandle handle, uint8\_t \*data, uint32\_t addr, uint32\_t size, uint32\_t scatterLen\); - - **表 9** SdioReadBytesFromFixedAddr函数的参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

SDIO控制器的设备句柄

-

data

-

接收读取数据的指针

-

addr

-

待读取数据的起始地址

-

size

-

待读取数据的长度

-

scatterLen

-

集散表的长度。如果该字段不为0,则data为集散表类型。

-

返回值

-

返回值描述

-

0

-

SDIO读数据成功

-

负数

-

SDIO读数据失败

-
- - 从SDIO设备的固定地址读取指定长度的数据的示例如下: - - ``` - int32_t ret; - uint8_t rbuff[5] = {0}; - uint32_t addr = 0x100 + 0x09; - /* 从SDIO设备固定地址0x109中读取5个字节的数据 */ - ret = SdioReadBytesFromFixedAddr(handle, rbuff, addr, 5, 0); - if (ret != 0) { - HDF_LOGE("SdioReadBytesFromFixedAddr: failed, ret %d\n", ret); - } - ``` - - -- 向SDIO function 0的指定地址空间写入指定长度的数据 - -当前只支持写入一个字节的数据,对应的接口函数如下所示: - -int32\_t SdioWriteBytesToFunc0\(DevHandle handle, uint8\_t \*data, uint32\_t addr, uint32\_t size\); - -**表 10** SdioWriteBytesToFunc0函数的参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

SDIO控制器的设备句柄

-

data

-

待写入数据的指针

-

addr

-

待写入数据的起始地址

-

size

-

待写入数据的长度

-

返回值

-

返回值描述

-

0

-

SDIO写数据成功

-

负数

-

SDIO写数据失败

-
- -向SDIO function 0的指定地址空间写入指定长度的数据的示例如下: - -``` -int32_t ret; -uint8_t wbuff = 1; -/* 向SDIO function 0地址0x2中写入1字节的数据 */ -ret = SdioWriteBytesToFunc0(handle, &wbuff, 0x2, 1); -if (ret != 0) { - HDF_LOGE("SdioWriteBytesToFunc0: failed, ret %d\n", ret); -} -``` - -- 从SDIO function 0的指定地址空间读取指定长度的数据 - -当前只支持读取一个字节的数据,对应的接口函数如下所示: - -int32\_t SdioReadBytesFromFunc0\(DevHandle handle, uint8\_t \*data, uint32\_t addr, uint32\_t size\); - -**表 11** SdioReadBytesFromFunc0函数的参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

SDIO控制器的设备句柄

-

data

-

接收读取数据的指针

-

addr

-

待读取数据的起始地址

-

size

-

待读取数据的长度

-

返回值

-

返回值描述

-

0

-

SDIO读数据成功

-

负数

-

SDIO读数据失败

-
- -从SDIO function 0的指定地址空间读取指定长度的数据的示例如下: - -``` -int32_t ret; -uint8_t rbuff; -/* 从SDIO function 0设备地址0x2中读取1字节的数据 */ -ret = SdioReadBytesFromFunc0(handle, &rbuff, 0x2, 1); -if (ret != 0) { - HDF_LOGE("SdioReadBytesFromFunc0: failed, ret %d\n", ret); -} -``` - -### 释放SDIO中断 - -通信完成之后,需要释放SDIO中断,函数如下所示: - -int32\_t SdioReleaseIrq\(DevHandle handle\); - -**表 12** SdioReleaseIrq函数的参数和返回值描述 - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

SDIO控制器的设备句柄

-

返回值

-

返回值描述

-

0

-

释放SDIO中断成功

-

负数

-

释放SDIO中断失败

-
- -释放SDIO中断的示例如下: - -``` -int32_t ret; -/* 释放SDIO中断 */ -ret = SdioReleaseIrq(handle); -if (ret != 0) { - HDF_LOGE("SdioReleaseIrq: failed, ret %d\n", ret); -} -``` - -### 去使能SDIO设备 - -通信完成之后,还需要去使能SDIO设备,函数如下所示: - -int32\_t SdioDisableFunc\(DevHandle handle\); - -**表 13** SdioDisableFunc函数的参数和返回值描述 - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

SDIO控制器的设备句柄

-

返回值

-

返回值描述

-

0

-

去使能SDIO设备成功

-

负数

-

去使能SDIO设备失败

-
- -去使能SDIO设备的示例如下: - -``` -int32_t ret; -/* 去使能SDIO设备 */ -ret = SdioDisableFunc(handle); -if (ret != 0) { - HDF_LOGE("SdioDisableFunc: failed, ret %d\n", ret); -} -``` - -### 释放HOST - -通信完成之后,还需要释放去HOST,函数如下所示: - -void SdioReleaseHost\(DevHandle handle\); - -**表 14** SdioReleaseHost函数的参数描述 - - - - - - - - - - -

参数

-

参数描述

-

handle

-

SDIO控制器的设备句柄

-
- -释放HOST的示例如下: - -``` -SdioReleaseHost(handle); /* 释放HOST */ -``` - -### 关闭SDIO控制器 - -SDIO通信完成之后,最后需要关闭SDIO控制器,函数如下所示: - -void SdioClose\(DevHandle handle\); - -该函数会释放掉申请的资源。 - -**表 15** SdioClose函数的参数描述 - - - - - - - - - - -

参数

-

参数描述

-

handle

-

SDIO控制器的设备句柄

-
- -关闭SDIO控制器的示例如下: - -``` -SdioClose(handle); /* 关闭SDIO控制器 */ -``` - -## 使用实例 - -SDIO设备完整的使用示例如下所示,首先打开总线号为1的SDIO控制器,然后独占HOST、使能设备、注册中断,接着进行SDIO通信(读写等),通信完成之后,释放中断、去使能设备、释放HOST,最后关闭SDIO控制器。 - -``` -#include "hdf_log.h" -#include "sdio_if.h" - -#define TEST_FUNC_NUM 1 /* 本测试用例中,使用编号为1的I/O function */ -#define TEST_FBR_BASE_ADDR 0x100 /* 编号为1的I/O function的FBR基地址 */ -#define TEST_ADDR_OFFSET 9 /* 本测试用例中,需要读写的寄存器的地址偏移 */ -#define TEST_DATA_LEN 3 /* 本测试用例中,读写数据的长度 */ -#define TEST_BLOCKSIZE 2 /* 本测试用例中,数据块的大小,单位字节 */ - -/* 中断服务函数,需要根据各自平台的情况去实现 */ -static void SdioIrqFunc(void *data) -{ - if (data == NULL) { - HDF_LOGE("SdioIrqFunc: data is NULL.\n"); - return; - } - /* 需要开发者自行添加具体的实现 */ -} - -void SdioTestSample(void) -{ - int32_t ret; - DevHandle handle = NULL; - uint8_t data[TEST_DATA_LEN] = {0}; - struct SdioFunctionConfig config = {1, 0x123, 0x456}; - uint8_t val; - uint32_t addr; - - /* 打开总线号为1的SDIO设备 */ - handle = SdioOpen(1, &config); - if (handle == NULL) { - HDF_LOGE("SdioOpen: failed!\n"); - return; - } - /* 独占HOST */ - SdioClaimHost(handle); - /* 使能SDIO设备 */ - ret = SdioEnableFunc(handle); - if (ret != 0) { - HDF_LOGE("SdioEnableFunc: failed, ret %d\n", ret); - goto ENABLE_ERR; - } - /* 注册中断 */ - ret = SdioClaimIrq(handle, SdioIrqFunc); - if (ret != 0) { - HDF_LOGE("SdioClaimIrq: failed, ret %d\n", ret); - goto CLAIM_IRQ_ERR; - } - /* 设置块大小为2字节 */ - ret = SdioSetBlockSize(handle, TEST_BLOCKSIZE); - if (ret != 0) { - HDF_LOGE("SdioSetBlockSize: failed, ret %d\n", ret); - goto COMM_ERR; - } - /* 从SDIO设备增量地址读取3字节的数据 */ - addr = TEST_FBR_BASE_ADDR * TEST_FUNC_NUM + TEST_ADDR_OFFSET; - ret = SdioReadBytes(handle, data, addr, TEST_DATA_LEN); - if (ret != 0) { - HDF_LOGE("SdioReadBytes: failed, ret %d\n", ret); - goto COMM_ERR; - } - /* 向SDIO设备增量地址写入3字节的数据 */ - ret = SdioWriteBytes(handle, data, addr, TEST_DATA_LEN); - if (ret != 0) { - HDF_LOGE("SdioWriteBytes: failed, ret %d\n", ret); - goto COMM_ERR; - } - /* 从SDIO设备读取1字节的数据 */ - ret = SdioReadBytes(handle, &val, addr, 1); - if (ret != 0) { - HDF_LOGE("SdioReadBytes: failed, ret %d\n", ret); - goto COMM_ERR; - } - /* 向SDIO设备写入1字节的数据 */ - ret = SdioWriteBytes(handle, &val, addr, 1); - if (ret != 0) { - HDF_LOGE("SdioWriteBytes: failed, ret %d\n", ret); - goto COMM_ERR; - } - /* 从SDIO设备固定地址读取3字节的数据 */ - ret = SdioReadBytesFromFixedAddr(handle, data, addr, TEST_DATA_LEN, 0); - if (ret != 0) { - HDF_LOGE("SdioReadBytesFromFixedAddr: failed, ret %d\n", ret); - goto COMM_ERR; - } - /* 向SDIO设备固定地址写入1字节的数据 */ - ret = SdioWriteBytesToFixedAddr(handle, data, addr, 1, 0); - if (ret != 0) { - HDF_LOGE("SdioWriteBytesToFixedAddr: failed, ret %d\n", ret); - goto COMM_ERR; - } - /* 从SDIO function 0读取1字节的数据 */ - addr = 0x02; - ret = SdioReadBytesFromFunc0(handle, &val, addr, 1); - if (ret != 0) { - HDF_LOGE("SdioReadBytesFromFunc0: failed, ret %d\n", ret); - goto COMM_ERR; - } - /* 向SDIO function 0写入1字节的数据 */ - ret = SdioWriteBytesToFunc0(handle, &val, addr, 1); - if (ret != 0) { - HDF_LOGE("SdioWriteBytesToFunc0: failed, ret %d\n", ret); - goto COMM_ERR; - } -COMM_ERR: - /* 释放中断 */ - ret = SdioReleaseIrq(handle); - if (ret != 0) { - HDF_LOGE("SdioReleaseIrq: failed, ret %d\n", ret); - } -CLAIM_IRQ_ERR: - /* 去使能SDIO设备 */ - ret = SdioDisableFunc(handle); - if (ret != 0) { - HDF_LOGE("SdioDisableFunc: failed, ret %d\n", ret); - } -ENABLE_ERR: - /* 释放HOST */ - SdioReleaseHost(handle); - /* 关闭SDIO设备 */ - SdioClose(handle); -} -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/03.\345\271\263\345\217\260\351\251\261\345\212\250\344\275\277\347\224\250/11.SPI.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/03.\345\271\263\345\217\260\351\251\261\345\212\250\344\275\277\347\224\250/11.SPI.md" deleted file mode 100644 index 105349eae3cddaf9ee2a2966b1d69431ab03cddd..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/03.\345\271\263\345\217\260\351\251\261\345\212\250\344\275\277\347\224\250/11.SPI.md" +++ /dev/null @@ -1,574 +0,0 @@ ---- -title: SPI -permalink: /pages/010502030b -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:24 ---- -# SPI - -- [概述](#section193356154511) -- [接口说明](#section1325964832615) -- [使用指导](#section71363452477) - - [使用流程](#section32846814820) - - [获取SPI设备句柄](#section1927265711481) - - [获取SPI设备属性](#section541133418493) - - [配置SPI设备属性](#section7870106145010) - - [进行SPI通信](#section13324155195013) - - [销毁SPI设备句柄](#section19661632135117) - -- [使用实例](#section06541058155120) - -## 概述 - -- SPI是串行外设接口(Serial Peripheral Interface)的缩写,是一种高速的,全双工,同步的通信总线。 -- SPI是由Motorola公司开发,用于在主设备和从设备之间进行通信,常用于与闪存、实时时钟、传感器以及模数转换器等进行通信。 -- SPI以主从方式工作,通常有一个主设备和一个或者多个从设备。主设备和从设备之间一般用4根线相连,它们分别是: - - SCLK – 时钟信号,由主设备产生; - - MOSI – 主设备数据输出,从设备数据输入; - - MISO – 主设备数据输入,从设备数据输出; - - CS – 片选,从设备使能信号,由主设备控制。 - - -- 一个主设备和两个从设备的连接示意图如[图1](#fig89085710359)所示,Device A和Device B共享主设备的SCLK、MISO和MOSI三根引脚,Device A的片选CS0连接主设备的CS0,Device B的片选CS1连接主设备的CS1。 - -**图 1** SPI主从设备连接示意图。 -![](/images/device-dev/driver/figures/SPI主从设备连接示意图.png "SPI主从设备连接示意图") - -- SPI通信通常由主设备发起,通过以下步骤完成一次通信: - -1. 通过CS选中要通信的从设备,在任意时刻,一个主设备上最多只能有一个从设备被选中。 -2. 通过SCLK给选中的从设备提供时钟信号。 -3. 基于SCLK时钟信号,主设备数据通过MOSI发送给从设备,同时通过MISO接收从设备发送的数据,完成通信。 - -- 根据SCLK时钟信号的CPOL(Clock Polarity,时钟极性)和CPHA(Clock Phase,时钟相位)的不同组合,SPI有以下四种工作模式: - - CPOL=0,CPHA=0 时钟信号idle状态为低电平,第一个时钟边沿采样数据。 - - CPOL=0,CPHA=1 时钟信号idle状态为低电平,第二个时钟边沿采样数据。 - - CPOL=1,CPHA=0 时钟信号idle状态为高电平,第一个时钟边沿采样数据。 - - CPOL=1,CPHA=1 时钟信号idle状态为高电平,第二个时钟边沿采样数据。 - - -- SPI接口定义了操作SPI设备的通用方法集合,包括: - - SPI设备句柄获取和释放。 - - SPI读写: 从SPI设备读取或写入指定长度数据。 - - SPI自定义传输:通过消息传输结构体执行任意读写组合过程。 - - SPI设备配置:获取和设置SPI设备属性。 - - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->当前只支持主机模式,不支持从机模式。 - -## 接口说明 - -**表 1** SPI驱动API接口功能介绍 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名

-

描述

-

SPI设备句柄获取释放接口

-

SpiOpen

-

获取SPI设备句柄

-

SpiClose

-

释放SPI设备句柄

-

SPI读写接口

-

SpiRead

-

读取指定长度的数据

-

SpiWrite

-

写入指定长度的数据

-

SpiTransfer

-

SPI数据传输接口

-

SPI设备配置接口

-

-

SpiSetCfg

-

根据指定参数,配置SPI设备

-

SpiGetCfg

-

获取SPI设备配置参数

-
- ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->本文涉及的所有接口,仅限内核态使用,不支持在用户态使用。 - -## 使用指导 - -### 使用流程 - -使用SPI的一般流程如[图2](#fig1586912310348)所示。 - -**图 2** SPI使用流程图 -![](/images/device-dev/driver/figures/SPI使用流程图.png "SPI使用流程图") - -### 获取SPI设备句柄 - -在使用SPI进行通信时,首先要调用SpiOpen获取SPI设备句柄,该函数会返回指定总线号和片选号的SPI设备句柄。 - -DevHandle SpiOpen\(const struct SpiDevInfo \*info\); - -**表 2** SpiOpen参数和返回值描述 - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

info

-

SPI设备描述符

-

返回值

-

返回值描述

-

NULL

-

获取SPI设备句柄失败

-

设备句柄

-

对应的SPI设备句柄

-
- -假设系统中的SPI设备总线号为0,片选号为0,获取该SPI设备句柄的示例如下: - -``` -struct SpiDevInfo spiDevinfo; /* SPI设备描述符 */ -DevHandle spiHandle = NULL; /* SPI设备句柄 */ -spiDevinfo.busNum = 0; /* SPI设备总线号 */ -spiDevinfo.csNum = 0; /* SPI设备片选号 */ - -/* 获取SPI设备句柄 */ -spiHandle = SpiOpen(&spiDevinfo); -if (spiHandle == NULL) { - HDF_LOGE("SpiOpen: failed\n"); - return; -} -``` - -### 获取SPI设备属性 - -在获取到SPI设备句柄之后,需要配置SPI设备属性。配置SPI设备属性之前,可以先获取SPI设备属性,获取SPI设备属性的函数如下所示: - -int32\_t SpiGetCfg\(DevHandle handle, struct SpiCfg \*cfg\); - -**表 3** SpiGetCfg参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

SPI设备句柄

-

cfg

-

SPI设备配置参数

-

返回值

-

返回值描述

-

0

-

获取配置成功

-

负数

-

获取配置失败

-
- -``` -int32_t ret; -struct SpiCfg cfg = {0}; /* SPI配置信息*/ -ret = SpiGetCfg(spiHandle, &cfg); /* 获取SPI设备属性 */ -if (ret != 0) { - HDF_LOGE("SpiGetCfg: failed, ret %d\n", ret); -} -``` - -### 配置SPI设备属性 - -在获取到SPI设备句柄之后,需要配置SPI设备属性,配置SPI设备属性的函数如下所示: - -int32\_t SpiSetCfg\(DevHandle handle, struct SpiCfg \*cfg\); - -**表 4** SpiSetCfg参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

SPI设备句柄

-

cfg

-

SPI设备配置参数

-

返回值

-

返回值描述

-

0

-

配置成功

-

负数

-

配置失败

-
- -``` -int32_t ret; -struct SpiCfg cfg = {0}; /* SPI配置信息*/ -cfg.mode = SPI_MODE_LOOP; /* 以回环模式进行通信 */ -cfg.transferMode = PAL_SPI_POLLING_TRANSFER; /* 以轮询的方式进行通信 */ -cfg.maxSpeedHz = 115200; /* 最大传输频率 */ -cfg.bitsPerWord = 8; /* 读写位宽为8个比特 */ -ret = SpiSetCfg(spiHandle, &cfg); /* 配置SPI设备属性 */ -if (ret != 0) { - HDF_LOGE("SpiSetCfg: failed, ret %d\n", ret); -} -``` - -### 进行SPI通信 - -- 向SPI设备写入指定长度的数据 - -如果只向SPI设备写一次数据,则可以通过以下函数完成: - -int32\_t SpiWrite\(DevHandle handle, uint8\_t \*buf, uint32\_t len\); - -**表 5** SpiWrite参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

SPI设备句柄

-

buf

-

待写入数据的指针

-

len

-

待写入的数据长度

-

返回值

-

返回值描述

-

0

-

写入成功

-

负数

-

写入失败

-
- -``` -int32_t ret; -uint8_t wbuff[4] = {0x12, 0x34, 0x56, 0x78}; -/* 向SPI设备写入指定长度的数据 */ -ret = SpiWrite(spiHandle, wbuff, 4); -if (ret != 0) { - HDF_LOGE("SpiWrite: failed, ret %d\n", ret); -} -``` - -- 从SPI设备读取指定长度的数据 - -如果只读取一次数据,则可以通过以下函数完成: - -int32\_t SpiRead\(DevHandle handle, uint8\_t \*buf, uint32\_t len\); - -**表 6** SpiRead参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

SPI设备句柄

-

buf

-

待读取数据的指针

-

len

-

待读取的数据长度

-

返回值

-

返回值描述

-

0

-

读取成功

-

负数

-

读取失败

-
- -``` -int32_t ret; -uint8_t rbuff[4] = {0}; -/* 从SPI设备读取指定长度的数据 */ -ret = SpiRead(spiHandle, rbuff, 4); -if (ret != 0) { - HDF_LOGE("SpiRead: failed, ret %d\n", ret); -} -``` - -- 自定义传输 - -如果需要发起一次自定义传输,则可以通过以下函数完成: - -int32\_t SpiTransfer\(DevHandle handle, struct SpiMsg \*msgs, uint32\_t count\); - -**表 7** SpiTransfer参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

SPI设备句柄

-

msgs

-

待传输数据的数组

-

count

-

msgs数组长度

-

返回值

-

返回值描述

-

0

-

执行成功

-

负数

-

执行失败

-
- -``` -int32_t ret; -uint8_t wbuff[1] = {0x12}; -uint8_t rbuff[1] = {0}; -struct SpiMsg msg; /* 自定义传输的消息*/ -msg.wbuf = wbuff; /* 写入的数据 */ -msg.rbuf = rbuff; /* 读取的数据 */ -msg.len = 1; /* 读取、写入数据的长度都是1 */ -msg.csChange = 1; /* 进行下一次传输前关闭片选 */ -msg.delayUs = 0; /* 进行下一次传输前不进行延时 */ -msg.speed = 115200; /* 本次传输的速度 */ -/* 进行一次自定义传输,传输的msg个数为1 */ -ret = SpiTransfer(spiHandle, &msg, 1); -if (ret != 0) { - HDF_LOGE("SpiTransfer: failed, ret %d\n", ret); -} -``` - -### 销毁SPI设备句柄 - -SPI通信完成之后,需要销毁SPI设备句柄,销毁SPI设备句柄的函数如下所示: - -void SpiClose\(DevHandle handle\); - -该函数会释放掉申请的资源。 - -**表 8** SpiClose参数描述 - - - - - - - - - -

参数

-

参数描述

-

handle

-

SPI设备句柄

-
- -``` -SpiClose(spiHandle); /* 销毁SPI设备句柄 */ -``` - -## 使用实例 - -SPI设备完整的使用示例如下所示,首先获取SPI设备句柄,然后配置SPI设备属性,接着调用读写接口进行数据传输,最后销毁SPI设备句柄。 - -``` -#include "hdf_log.h" -#include "spi_if.h" - -void SpiTestSample(void) -{ - int32_t ret; - struct SpiCfg cfg; /* SPI配置信息 */ - struct SpiDevInfo spiDevinfo; /* SPI设备描述符 */ - DevHandle spiHandle = NULL; /* SPI设备句柄 */ - struct SpiMsg msg; /* 自定义传输的消息 */ - uint8_t rbuff[4] = { 0 }; - uint8_t wbuff[4] = { 0x12, 0x34, 0x56, 0x78 }; - uint8_t wbuff2[4] = { 0xa1, 0xb2, 0xc3, 0xd4 }; - - spiDevinfo.busNum = 0; /* SPI设备总线号 */ - spiDevinfo.csNum = 0; /* SPI设备片选号 */ - spiHandle = SpiOpen(&spiDevinfo); /* 根据spiDevinfo获取SPI设备句柄 */ - if (spiHandle == NULL) { - HDF_LOGE("SpiOpen: failed\n"); - return; - } - /* 获取SPI设备属性 */ - ret = SpiGetCfg(spiHandle, &cfg); - if (ret != 0) { - HDF_LOGE("SpiGetCfg: failed, ret %d\n", ret); - goto err; - } - cfg.maxSpeedHz = 115200; /* 将最大时钟频率改为115200 */ - cfg.bitsPerWord = 8; /* 传输位宽改为8比特 */ - /* 配置SPI设备属性 */ - ret = SpiSetCfg(spiHandle, &cfg); - if (ret != 0) { - HDF_LOGE("SpiSetCfg: failed, ret %d\n", ret); - goto err; - } - /* 向SPI设备写入指定长度的数据 */ - ret = SpiWrite(spiHandle, wbuff, 4); - if (ret != 0) { - HDF_LOGE("SpiWrite: failed, ret %d\n", ret); - goto err; - } - /* 从SPI设备读取指定长度的数据 */ - ret = SpiRead(spiHandle, rbuff, 4); - if (ret != 0) { - HDF_LOGE("SpiRead: failed, ret %d\n", ret); - goto err; - } - msg.wbuf = wbuff2; /* 写入的数据 */ - msg.rbuf = rbuff; /* 读取的数据 */ - msg.len = 4; /* 读取写入数据的长度为4 */ - msg.csChange = 1; /* 进行下一次传输前关闭片选 */ - msg.delayUs = 0; /* 进行下一次传输前不进行延时 */ - msg.speed = 115200; /* 本次传输的速度 */ - /* 进行一次自定义传输,传输的msg个数为1 */ - ret = SpiTransfer(spiHandle, &msg, 1); - if (ret != 0) { - HDF_LOGE("SpiTransfer: failed, ret %d\n", ret); - goto err; - } -err: - /* 销毁SPI设备句柄 */ - SpiClose(spiHandle); -} -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/03.\345\271\263\345\217\260\351\251\261\345\212\250\344\275\277\347\224\250/12.UART.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/03.\345\271\263\345\217\260\351\251\261\345\212\250\344\275\277\347\224\250/12.UART.md" deleted file mode 100644 index 918211e02e397db5a500234b750c059d53dfcc49..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/03.\345\271\263\345\217\260\351\251\261\345\212\250\344\275\277\347\224\250/12.UART.md" +++ /dev/null @@ -1,688 +0,0 @@ ---- -title: UART -permalink: /pages/010502030c -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:24 ---- -# UART - -- [概述](#section833012453535) -- [接口说明](#section1928742202715) -- [使用指导](#section12779050105412) - - [使用流程](#section1858116395510) - - [获取UART设备句柄](#section124512065617) - - [UART设置波特率](#section86881004579) - - [UART获取波特率](#section897032965712) - - [UART设置设备属性](#section129141884588) - - [UART获取设备属性](#section18689637165812) - - [设置UART传输模式](#section72713435918) - - [向UART设备写入指定长度的数据](#section128001736155919) - - [从UART设备中读取指定长度的数据](#section92851601604) - - [销毁UART设备句柄](#section1477410521406) - -- [使用实例](#section35404241311) - -## 概述 - -- UART是通用异步收发传输器(Universal Asynchronous Receiver/Transmitter)的缩写,是通用串行数据总线,用于异步通信。该总线双向通信,可以实现全双工传输。 -- UART应用比较广泛,常用于输出打印信息,也可以外接各种模块,如GPS、蓝牙等。 -- 两个UART设备的连接示意图如下,UART与其他模块一般用2线(图1)或4线(图2)相连,它们分别是: - - TX:发送数据端,和对端的RX相连; - - RX:接收数据端,和对端的TX相连; - - RTS:发送请求信号,用于指示本设备是否准备好,可接受数据,和对端CTS相连; - - CTS:允许发送信号,用于判断是否可以向对端发送数据,和对端RTS相连; - - **图 1** 2线UART设备连接示意图 - ![](/images/device-dev/driver/figures/2线UART设备连接示意图.png "2线UART设备连接示意图") - - **图 2** 4线UART设备连接示意图 - ![](/images/device-dev/driver/figures/4线UART设备连接示意图.png "4线UART设备连接示意图") - - -- UART通信之前,收发双方需要约定好一些参数:波特率、数据格式(起始位、数据位、校验位、停止位)等。通信过程中,UART通过TX发送给对端数据,通过RX接收对端发送的数据。当UART接收缓存达到预定的门限值时,RTS变为不可发送数据,对端的CTS检测到不可发送数据,则停止发送数据。 -- UART接口定义了操作UART端口的通用方法集合,包括获取、释放设备句柄、读写数据、获取和设置波特率、获取和设置设备属性。 - -## 接口说明 - -**表 1** UART驱动API接口功能介绍 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名

-

描述

-

UART获取/释放设备句柄

-

-

UartOpen

-

UART获取设备句柄

-

UartClose

-

UART释放设备句柄

-

UART读写接口

-

-

UartRead

-

从UART设备中读取指定长度的数据

-

UartWrite

-

向UART设备中写入指定长度的数据

-

UART获取/设置波特率接口

-

UartGetBaud

-

UART获取波特率

-

UartSetBaud

-

UART设置波特率

-

UART获取/设置设备属性

-

-

UartGetAttribute

-

UART获取设备属性

-

UartSetAttribute

-

UART设置设备属性

-

UART设置传输模式

-

UartSetTransMode

-

UART设置传输模式

-
- ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->本文涉及的所有接口,仅限内核态使用,不支持在用户态使用。 - -## 使用指导 - -### 使用流程 - -使用UART的一般流程如[图3](#fig99673244388)所示。 - -**图 3** UART使用流程图 -![](/images/device-dev/driver/figures/UART使用流程图.png "UART使用流程图") - -### 获取UART设备句柄 - -在使用UART进行通信时,首先要调用UartOpen获取UART设备句柄,该函数会返回指定端口号的UART设备句柄。 - -DevHandle UartOpen\(uint32\_t port\); - -**表 2** UartOpen参数和返回值描述 - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

port

-

UART设备号

-

返回值

-

返回值描述

-

NULL

-

获取UART设备句柄失败

-

设备句柄

-

UART设备句柄

-
- -假设系统中的UART端口号为3,获取该UART设备句柄的示例如下: - -``` -DevHandle handle = NULL; /* UART设备句柄 */ -uint32_t port = 3; /* UART设备端口号 */ -handle = UartOpen(port); -if (handle == NULL) { - HDF_LOGE("UartOpen: failed!\n"); - return; -} -``` - -### UART设置波特率 - -在通信之前,需要设置UART的波特率,设置波特率的函数如下所示: - -int32\_t UartSetBaud\(DevHandle handle, uint32\_t baudRate\); - -**表 3** UartSetBaud参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

UART设备句柄

-

baudRate

-

待设置的波特率值

-

返回值

-

返回值描述

-

0

-

UART设置波特率成功

-

负数

-

UART设置波特率失败

-
- -假设需要设置的UART波特率为9600,设置波特率的实例如下: - -``` -int32_t ret; -/* 设置UART波特率 */ -ret = UartSetBaud(handle, 9600); -if (ret != 0) { - HDF_LOGE("UartSetBaud: failed, ret %d\n", ret); -} -``` - -### UART获取波特率 - -设置UART的波特率后,可以通过获取波特率接口来查看UART当前的波特率,获取波特率的函数如下所示: - -int32\_t UartGetBaud\(DevHandle handle, uint32\_t \*baudRate\); - -**表 4** UartGetBaud参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

UART设备句柄

-

baudRate

-

接收波特率值的指针

-

返回值

-

返回值描述

-

0

-

UART获取波特率成功

-

负数

-

UART获取波特率失败

-
- -获取波特率的实例如下: - -``` -int32_t ret; -uint32_t baudRate; -/* 获取UART波特率 */ -ret = UartGetBaud(handle, &baudRate); -if (ret != 0) { - HDF_LOGE("UartGetBaud: failed, ret %d\n", ret); -} -``` - -### UART设置设备属性 - -在通信之前,需要设置UART的设备属性,设置设备属性的函数如下图所示: - -int32\_t UartSetAttribute\(DevHandle handle, struct UartAttribute \*attribute\); - -**表 5** UartSetAttribute参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

UART设备句柄

-

attribute

-

待设置的设备属性

-

返回值

-

返回值描述

-

0

-

UART设置设备属性成功

-

负数

-

UART设置设备属性失败

-
- -设置UART的设备属性的实例如下: - -``` -int32_t ret; -struct UartAttribute attribute; -attribute.dataBits = UART_ATTR_DATABIT_7; /* UART传输数据位宽,一次传输7个bit */ -attribute.parity = UART_ATTR_PARITY_NONE; /* UART传输数据无校检 */ -attribute.stopBits = UART_ATTR_STOPBIT_1; /* UART传输数据停止位为1位 */ -attribute.rts = UART_ATTR_RTS_DIS; /* UART禁用RTS */ -attribute.cts = UART_ATTR_CTS_DIS; /* UART禁用CTS */ -attribute.fifoRxEn = UART_ATTR_RX_FIFO_EN; /* UART使能RX FIFO */ -attribute.fifoTxEn = UART_ATTR_TX_FIFO_EN; /* UART使能TX FIFO */ -/* 设置UART设备属性 */ -ret = UartSetAttribute(handle, &attribute); -if (ret != 0) { - HDF_LOGE("UartSetAttribute: failed, ret %d\n", ret); -} -``` - -### UART获取设备属性 - -设置UART的设备属性后,可以通过获取设备属性接口来查看UART当前的设备属性,获取设备属性的函数如下图所示: - -int32\_t UartGetAttribute\(DevHandle handle, struct UartAttribute \*attribute\); - -**表 6** UartGetAttribute参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

UART设备句柄

-

attribute

-

接收UART设备属性的指针

-

返回值

-

返回值描述

-

0

-

UART获取设备属性成功

-

负数

-

UART获取设备属性失败

-
- -获取UART的设备属性的实例如下: - -``` -int32_t ret; -struct UartAttribute attribute; -/* 获取UART设备属性 */ -ret = UartGetAttribute(handle, &attribute); -if (ret != 0) { - HDF_LOGE("UartGetAttribute: failed, ret %d\n", ret); -} -``` - -### 设置UART传输模式 - -在通信之前,需要设置UART的传输模式,设置传输模式的函数如下图所示: - -int32\_t UartSetTransMode\(DevHandle handle, enum UartTransMode mode\); - -**表 7** UartSetTransMode参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

UART设备句柄

-

mode

-

待设置的传输模式,

-

返回值

-

返回值描述

-

0

-

UART设置传输模式成功

-

负数

-

UART设置传输模式失败

-
- -假设需要设置的UART传输模式为UART\_MODE\_RD\_BLOCK,设置传输模式的实例如下: - -``` -int32_t ret; -/* 设置UART传输模式 */ -ret = UartSetTransMode(handle, UART_MODE_RD_BLOCK); -if (ret != 0) { - HDF_LOGE("UartSetTransMode: failed, ret %d\n", ret); -} -``` - -### 向UART设备写入指定长度的数据 - -对应的接口函数如下所示: - -int32\_t UartWrite\(DevHandle handle, uint8\_t \*data, uint32\_t size\); - -**表 8** UartWrite参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

UART设备句柄

-

data

-

待写入数据的指针

-

size

-

待写入数据的长度

-

返回值

-

返回值描述

-

0

-

UART写数据成功

-

负数

-

UART写数据失败

-
- -写入指定长度数据的实例如下: - -``` -int32_t ret; -uint8_t wbuff[5] = {1, 2, 3, 4, 5}; -/* 向UART设备写入指定长度的数据 */ -ret = UartWrite(handle, wbuff, 5); -if (ret != 0) { - HDF_LOGE("UartWrite: failed, ret %d\n", ret); -} -``` - -### 从UART设备中读取指定长度的数据 - -对应的接口函数如下所示: - -int32\_t UartRead\(DevHandle handle, uint8\_t \*data, uint32\_t size\); - -**表 9** UartRead参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

UART设备句柄

-

data

-

接收读取数据的指针

-

size

-

待读取数据的长度

-

返回值

-

返回值描述

-

非负数

-

UART读取到的数据长度

-

负数

-

UART读取数据失败

-
- -读取指定长度数据的实例如下: - -``` -int32_t ret; -uint8_t rbuff[5] = {0}; -/* 从UART设备读取指定长度的数据 */ -ret = UartRead(handle, rbuff, 5); -if (ret < 0) { - HDF_LOGE("UartRead: failed, ret %d\n", ret); -} -``` - ->![](/images/device-dev/public_sys-resources/icon-caution.gif) **注意:** ->UART返回值为非负值,表示UART读取成功。若返回值等于0,表示UART无有效数据可以读取。若返回值大于0,表示实际读取到的数据长度,该长度小于或等于传入的参数size的大小,并且不超过当前正在使用的UART控制器规定的最大单次读取数据长度的值。 - -### 销毁UART设备句柄 - -UART通信完成之后,需要销毁UART设备句柄,函数如下所示: - -void UartClose\(DevHandle handle\); - -该函数会释放申请的资源。 - -**表 10** UartClose参数和返回值描述 - - - - - - - - - - -

参数

-

参数描述

-

handle

-

UART设备句柄

-
- -销毁UART设备句柄的实例如下: - -``` -UartClose(handle); /* 销毁UART设备句柄 * -``` - -## 使用实例 - -UART设备完整的使用示例如下所示,首先获取UART设备句柄,接着设置波特率、设备属性和传输模式,之后进行UART通信,最后销毁UART设备句柄。 - -``` -#include "hdf_log.h" -#include "uart_if.h" - -void UartTestSample(void) -{ - int32_t ret; - uint32_t port; - DevHandle handle = NULL; - uint8_t wbuff[5] = { 1, 2, 3, 4, 5 }; - uint8_t rbuff[5] = { 0 }; - struct UartAttribute attribute; - attribute.dataBits = UART_ATTR_DATABIT_7; /* UART传输数据位宽,一次传输7个bit */ - attribute.parity = UART_ATTR_PARITY_NONE; /* UART传输数据无校检 */ - attribute.stopBits = UART_ATTR_STOPBIT_1; /* UART传输数据停止位为1位 */ - attribute.rts = UART_ATTR_RTS_DIS; /* UART禁用RTS */ - attribute.cts = UART_ATTR_CTS_DIS; /* UART禁用CTS */ - attribute.fifoRxEn = UART_ATTR_RX_FIFO_EN; /* UART使能RX FIFO */ - attribute.fifoTxEn = UART_ATTR_TX_FIFO_EN; /* UART使能TX FIFO */ - /* UART设备端口号,要填写实际平台上的端口号 */ - port = 1; - /* 获取UART设备句柄 */ - handle = UartOpen(port); - if (handle == NULL) { - HDF_LOGE("UartOpen: failed!\n"); - return; - } - /* 设置UART波特率为9600 */ - ret = UartSetBaud(handle, 9600); - if (ret != 0) { - HDF_LOGE("UartSetBaud: failed, ret %d\n", ret); - goto _ERR; - } - /* 设置UART设备属性 */ - ret = UartSetAttribute(handle, &attribute); - if (ret != 0) { - HDF_LOGE("UartSetAttribute: failed, ret %d\n", ret); - goto _ERR; - } - /* 设置UART传输模式为非阻塞模式 */ - ret = UartSetTransMode(handle, UART_MODE_RD_NONBLOCK); - if (ret != 0) { - HDF_LOGE("UartSetTransMode: failed, ret %d\n", ret); - goto _ERR; - } - /* 向UART设备写入5字节的数据 */ - ret = UartWrite(handle, wbuff, 5); - if (ret != 0) { - HDF_LOGE("UartWrite: failed, ret %d\n", ret); - goto _ERR; - } - /* 从UART设备读取5字节的数据 */ - ret = UartRead(handle, rbuff, 5); - if (ret < 0) { - HDF_LOGE("UartRead: failed, ret %d\n", ret); - goto _ERR; - } -_ERR: - /* 销毁UART设备句柄 */ - UartClose(handle); -} -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/03.\345\271\263\345\217\260\351\251\261\345\212\250\344\275\277\347\224\250/13.WATCHDOG.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/03.\345\271\263\345\217\260\351\251\261\345\212\250\344\275\277\347\224\250/13.WATCHDOG.md" deleted file mode 100644 index 21dd5ff2164609c3773bec5c1ac49037afcfe32d..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/03.\345\271\263\345\217\260\351\251\261\345\212\250\344\275\277\347\224\250/13.WATCHDOG.md" +++ /dev/null @@ -1,567 +0,0 @@ ---- -title: WATCHDOG -permalink: /pages/010502030d -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:24 ---- -# WATCHDOG - -- [概述](#section14918241977) -- [接口说明](#section1180575010271) -- [使用指导](#section10103184312813) - - [使用流程](#section10181195910815) - - [打开看门狗设备](#section66089201107) - - [获取看门狗状态](#section786624341011) - - [设置超时时间](#section182386137111) - - [获取超时时间](#section1883310371114) - - [启动看门狗](#section82501405123) - - [喂狗](#section3547530101211) - - [停止看门狗](#section944595841217) - - [关闭看门狗设备](#section96561824121311) - -- [使用实例](#section1724514523135) - -## 概述 - -看门狗(watchdog),又叫看门狗计时器(watchdog timer),是一种硬件的计时设备,当系统的主程序发生某些错误时,导致未及时清除看门狗计时器的计时值,这时看门狗计时器就会对系统发出复位信号,使系统从悬停状态恢复到正常运作状态。 - -## 接口说明 - -**表 1** 看门狗 API接口功能介绍 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名

-

描述

-

打开/关闭看门狗

-

WatchdogOpen

-

打开看门狗设备

-

WatchdogClose

-

关闭看门狗设备

-

启动/停止看门狗

-

WatchdogStart

-

启动看门狗

-

WatchdogStop

-

停止看门狗

-

设置/获取超时时间

-

WatchdogSetTimeout

-

设置看门狗超时时间

-

WatchdogGetTimeout

-

获取看门狗超时时间

-

获取看门狗状态

-

WatchdogGetStatus

-

获取看门狗状态

-

清除看门狗定时器

-

WatchdogFeed

-

清除看门狗定时器(喂狗)

-
- ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->本文涉及看门狗的所有接口,仅限内核态使用,不支持在用户态使用。 - -## 使用指导 - -### 使用流程 - -使用看门狗的一般流程如[图1](#fig430533913392)所示。 - -**图 1** 看门狗使用流程图 -![](/images/device-dev/driver/figures/看门狗使用流程图.png "看门狗使用流程图") - -### 打开看门狗设备 - -在操作看门狗之前,需要使用WatchdogOpen打开一个看门狗设备,一个系统可能有多个看门狗,通过ID号来打开指定的看门狗设备: - -DevHandle WatchdogOpen\(int16\_t wdtId\); - -**表 2** WatchdogOpen参数和返回值描述 - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

wdtId

-

看门狗设备号

-

返回值

-

返回值描述

-

NULL

-

打开失败

-

DevHandle类型指针

-

看门狗设备句柄

-
- -``` -DevHandle handle = NULL; -handle = WatchdogOpen(0); /* 打开0号看门狗设备 */ -if (handle == NULL) { - HDF_LOGE("WatchdogOpen: failed, ret %d\n", ret); - return; -} -``` - -### 获取看门狗状态 - -int32\_t WatchdogGetStatus\(DevHandle handle, int32\_t \*status\); - -**表 3** WatchdogGetStatus参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

看门狗设备句柄

-

status

-

获取到的启动状态指针

-

返回值

-

返回值描述

-

0

-

获取成功

-

负数

-

获取失败

-
- -``` -int32_t ret; -int32_t status; -/* 获取Watchdog启动状态 */ -ret = WatchdogGetStatus(handle, &status); -if (ret != 0) { - HDF_LOGE("WatchdogGetStatus: failed, ret %d\n", ret); - return; -} -``` - -### 设置超时时间 - -int32\_t WatchdogSetTimeout\(DevHandle \*handle, uint32\_t seconds\); - -**表 4** WatchdogSetTimeout参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

看门狗设备句柄

-

seconds

-

超时时间,单位为秒

-

返回值

-

返回值描述

-

0

-

设置成功

-

负数

-

设置失败

-
- -``` -int32_t ret; -uint32_t timeOut = 60; -/* 设置超时时间,单位:秒 */ -ret = WatchdogSetTimeout(handle, timeOut); -if (ret != 0) { - HDF_LOGE("WatchdogSetTimeout: failed, ret %d\n", ret); - return; -} -``` - -### 获取超时时间 - -int32\_t WatchdogGetTimeout\(DevHandle \*handle, uint32\_t \*seconds\); - -**表 5** WatchdogGetTimeout参数和返回值描述 - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

看门狗设备句柄

-

seconds

-

接收超时时间的指针,单位为秒

-

返回值

-

返回值描述

-

0

-

获取成功

-

负数

-

获取失败

-
- -``` -int32_t ret; -uint32_t timeOut; -/* 获取超时时间,单位:秒 */ -ret = WatchdogGetTimeout(handle, &timeOut); -if (ret != 0) { - HDF_LOGE("WatchdogGetTimeout: failed, ret %d\n", ret); - return; -} -``` - -### 启动看门狗 - -int32\_t WatchdogStart\(DevHandle handle\); - -**表 6** WatchdogStart参数和返回值描述 - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

看门狗设备句柄

-

返回值

-

返回值描述

-

0

-

启动成功

-

负数

-

启动失败

-
- -``` -int32_t ret; -/* 启动看门狗 */ -ret = WatchdogStart(handle); -if (ret != 0) { - HDF_LOGE("WatchdogStart: failed, ret %d\n", ret); - return; -} -``` - -### 喂狗 - -int32\_t WatchdogFeed\(DevHandle handle\); - -**表 7** WatchdogFeed参数和返回值描述 - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

看门狗设备句柄

-

返回值

-

返回值描述

-

0

-

喂狗成功

-

负数

-

喂狗失败

-
- -``` -int32_t ret; -/* 喂狗 */ -ret = WatchdogFeed(handle); -if (ret != 0) { - HDF_LOGE("WatchdogFeed: failed, ret %d\n", ret); - return; -} -``` - -### 停止看门狗 - -int32\_t WatchdogStop\(DevHandle handle\); - -**表 8** WatchdogStop参数和返回值描述 - - - - - - - - - - - - - - - - - - - -

参数

-

参数描述

-

handle

-

看门狗设备句柄

-

返回值

-

返回值描述

-

0

-

停止成功

-

负数

-

停止失败

-
- -``` -int32_t ret; -/* 停止看门狗 */ -ret = WatchdogStop(handle); -if (ret != 0) { - HDF_LOGE("WatchdogStop: failed, ret %d\n", ret); - return; -} -``` - -### 关闭看门狗设备 - -当操作完毕时,使用WatchdogClose关闭打开的设备句柄: - -void WatchdogClose\(DevHandle handle\); - -**表 9** WatchdogClose参数和返回值描述 - - - - - - - - - - -

参数

-

参数描述

-

handle

-

看门狗设备句柄

-
- -``` -/* 关闭看门狗 */ -ret = WatchdogClose(handle); -``` - -## 使用实例 - -本例程提供看门狗的完整使用流程。 - -在本例程中,我们打开一个看门狗设备,设置超时时间并启动计时: - -- 首先定期喂狗,即按时清除看门狗定时器,确保系统不会因定时器超时而复位。 -- 接着再停止喂狗,观察定时器到期后系统是否发生复位行为。 - -示例如下: - -``` -#include "watchdog_if.h" -#include "hdf_log.h" -#include "osal_irq.h" -#include "osal_time.h" - -#define WATCHDOG_TEST_TIMEOUT 2 -#define WATCHDOG_TEST_FEED_TIME 6 - -static int32_t TestCaseWatchdog(void) -{ - int32_t i; - int32_t ret; - uint32_t timeout; - DevHandle handle = NULL; - - /* 打开0号看门狗设备 */ - handle = WatchdogOpen(0); - if (handle == NULL) { - HDF_LOGE("Open watchdog fail!"); - return -1; - } - - /* 设置超时时间 */ - ret = WatchdogSetTimeout(handle, WATCHDOG_TEST_TIMEOUT); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: set timeout fail! ret:%d\n", __func__, ret); - WatchdogClose(handle); - return ret; - } - - /* 回读设置的超时时间值 */ - ret = WatchdogGetTimeout(handle, &timeout); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: get timeout fail! ret:%d\n", __func__, ret); - WatchdogClose(handle); - return ret; - } - HDF_LOGI("%s: read timeout back:%u\n", __func__, timeout); - - /* 启动看门狗,开始计时 */ - ret = WatchdogStart(handle); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: satrt fail! ret:%d\n", __func__, ret); - WatchdogClose(handle); - return ret; - } - - /* 每隔1S喂狗一次 */ - for (i = 0; i < WATCHDOG_TEST_FEED_TIME; i++) { - HDF_LOGE("%s: feeding watchdog %d times... \n", __func__, i); - ret = WatchdogFeed(handle); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: feed dog fail! ret:%d\n", __func__, ret); - WatchdogClose(handle); - return ret; - } - OsalSleep(1); - } - /* 由于喂狗间隔小于超时时间,系统不会发生复位,此日志可以正常打印 */ - HDF_LOGE("%s: no reset ... feeding test OK!!!\n", __func__); - - /* 接下来持续不喂狗,使得看门狗计时器超时 */ - for (i = 0; i < WATCHDOG_TEST_FEED_TIME; i++) { - HDF_LOGE("%s: watiting dog buck %d times... \n", __func__, i); - OsalSleep(1); - } - - /* 当不喂狗时间到达之前设定的超时时间的时候,系统会发生复位,理论上观察不到此日志的打印 */ - HDF_LOGE("%s: dog has't buck!!! \n", __func__, i); - WatchdogClose(handle); - return -1; -} -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/04.\345\244\226\350\256\276\351\251\261\345\212\250\344\275\277\347\224\250/01.LCD.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/04.\345\244\226\350\256\276\351\251\261\345\212\250\344\275\277\347\224\250/01.LCD.md" deleted file mode 100644 index a01c53d67d42dbda32f74720e7ab7a73814dcc06..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/04.\345\244\226\350\256\276\351\251\261\345\212\250\344\275\277\347\224\250/01.LCD.md" +++ /dev/null @@ -1,367 +0,0 @@ ---- -title: LCD -permalink: /pages/0105020401 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:24 ---- -# LCD - -- [概述](#section141575391542) -- [接口说明](#section53793327396) -- [开发步骤](#section12394223125615) -- [开发实例](#section7441155155813) - -## 概述 - -LCD(Liquid Crystal Display)液晶显示驱动,对LCD进行上电,并通过接口初始化LCD内部寄存器,使LCD正常工作。Display驱动模型基于HDF( Hardware Driver Foundation)[驱动框架](/pages/0105020101)开发,实现跨OS、跨平台,为LCD硬件提供上下电功能、发送初始化序列功能,使LCD进入正常的工作模式,显示芯片平台侧的图像数据,基于HDF驱动框架的Display驱动模型如[图1](#fig69138814229)。 - -**图 1** 基于HDF驱动框架的Display驱动模型 -![](/images/device-dev/driver/figures/基于HDF驱动框架的Display驱动模型.png "基于HDF驱动框架的Display驱动模型") - -**Display驱动模型介绍** - -Display驱动模型主要由平台驱动层、芯片平台适配层、LCD器件驱动层三部分组成。驱动模型基于HDF驱动框架开发,通过Platform层和OSAL层提供的接口,屏蔽内核形态的差异,使得器件驱动可以便利的迁移到不同OS及芯片平台。模型向上对接Display公共hal层,支撑HDI(Hardware Display Interface)接口的实现,通过Display-HDI对图形服务提供各类驱动能力接口。 - -- Display平台驱动层:通过HDF提供的IOService数据通道,与公共Hal层对接,集中接收并处理各类上层调用指令。 -- SOC平台驱动适配层:借助此SOC适配层,实现Display驱动和SOC侧驱动解耦,主要完成芯片平台相关的参数配置,并传递平台驱动层的调用到器件驱动层。 -- LCD器件驱动层:在器件驱动层中,主要实现和器件自身强相关的驱动适配接口,例如发送初始化序列、上下电、背光设置等。 - -基于Display驱动模型开发LCD驱动,可以借助平台提供的各种能力及接口,较大程度的降低器件驱动的开发周期和难度,提升开发效率。 - -## 接口说明 - -LCD接口通常可分为MIPI DSI接口、TTL接口和LVDS接口,常用的是MIPI DSI接口和TTL接口,下面对常用的MIPI DSI接口和TTL接口作简要介绍。 - -- MIPI DSI接口 - - **图 2** MIPI DSI接口 - ![](/images/device-dev/driver/figures/MIPI-DSI接口.png "MIPI-DSI接口") - - MIPI DSI接口是MIPI(Mobile Industry Processor Interface)联盟定义的显示接口,主要用于移动终端显示屏接口,接口数据传输遵循MIPI协议,MIPI DSI接口为数据接口,传输图像数据,通常情况下MIPI DSI接口的控制信息以MIPI包形式通过MIPI DSI接口发送到对端IC,不需要额外的外设接口。 - -- TTL接口 - - **图 3** TTL接口 - ![](/images/device-dev/driver/figures/TTL接口.png "TTL接口") - - TTL(Transistor Transistor Logic)即晶体管-晶体管逻辑,TTL电平信号由TTL器件产生,TTL器件是数字集成电路的一大门类,它采用双极型工艺制造,具有高速度、低功耗和品种多等特点。 - - TTL接口是并行方式传输数据的接口,有数据信号、时钟信号和控制信号(行同步、帧同步、数据有效信号等),在控制信号控制下完成数据传输。通常TTL接口的LCD,内部寄存器读写需要额外的外设接口,比如SPI接口、I2C接口等。 - - -## 开发步骤 - -Display驱动模型基于HDF驱动框架、Platform接口及OSAL接口开发,可以做到不区分OS(LiteOS、Linux)和芯片平台(Hi35xx、Hi38xx、V3S等),为LCD器件提供统一的驱动模型。 - -1. 添加LCD驱动相关的设备描述配置。 -2. 在SOC平台驱动适配层中适配对应的芯片平台驱动。 -3. 添加器件驱动,并在驱动入口函数Init中注册Panel驱动数据,驱动数据接口主要包括如下接口: - - LCD上下电 - - 根据LCD硬件连接,使用Platform接口层提供的GPIO操作接口操作对应LCD管脚,例如复位管脚、IOVCC管脚,上电时序参考LCD供应商提供的SPEC。 - - - 发送初始化序列 - - 根据LCD硬件接口,使用Platform接口层提供的I2C、SPI、MIPI等接口,下载LCD初始化序列,初始化参数序列可以参考LCD供应商提供的SPEC。 - -4. 根据需求实现HDF框架其他接口,比如Release接口。 -5. 根据需求使用HDF框架可创建其他设备节点,用于业务逻辑或者调试功能。 - -## 开发实例 - -添加设备描述配置: - -``` -/* Display驱动相关的设备描述配置 */ -display :: host { - hostName = "display_host"; - /* Display平台驱动设备描述 */ - device_hdf_disp :: device { - device0 :: deviceNode { - policy = 2; - priority = 200; - permission = 0660; - moduleName = "HDF_DISP"; - serviceName = "hdf_disp"; - } - } - /* SOC适配层驱动设备描述 */ - device_hi35xx_disp :: device { - device0 :: deviceNode { - policy = 0; - priority = 199; - moduleName = "HI351XX_DISP"; - } - } - /* LCD器件驱动设备描述 */ - device_lcd :: device { - device0 :: deviceNode { - policy = 0; - priority = 100; - preload = 0; - moduleName = "LCD_Sample"; - } - device1 :: deviceNode { - policy = 0; - priority = 100; - preload = 2; - moduleName = "LCD_SampleXX"; - } - } -} -``` - -SOC适配层驱动,以Hi35xx系列芯片为例,需要在本层驱动中适配MIPI等和芯片平台相关的配置,示例如下: - -``` -static int32_t MipiDsiInit(struct PanelInfo *info) -{ - int32_t ret; - struct DevHandle *mipiHandle = NULL; - struct MipiCfg cfg; - - mipiHandle = MipiDsiOpen(0); - if (mipiHandle == NULL) { - HDF_LOGE("%s: MipiDsiOpen failure", __func__); - return HDF_FAILURE; - } - cfg.lane = info->mipi.lane; - cfg.mode = info->mipi.mode; - cfg.format = info->mipi.format; - cfg.burstMode = info->mipi.burstMode; - cfg.timing.xPixels = info->width; - cfg.timing.hsaPixels = info->hsw; - cfg.timing.hbpPixels = info->hbp; - cfg.timing.hlinePixels = info->width + info->hbp + info->hfp + info->hsw; - cfg.timing.vsaLines = info->vsw; - cfg.timing.vbpLines = info->vbp; - cfg.timing.vfpLines = info->vfp; - cfg.timing.ylines = info->height; - /* 0 : no care */ - cfg.timing.edpiCmdSize = 0; - cfg.pixelClk = CalcPixelClk(info); - cfg.phyDataRate = CalcDataRate(info); - /* config mipi device */ - ret = MipiDsiSetCfg(mipiHandle, &cfg); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s:MipiDsiSetCfg failure", __func__); - } - MipiDsiClose(mipiHandle); - HDF_LOGI("%s:pixelClk = %d, phyDataRate = %d\n", __func__, - cfg.pixelClk, cfg.phyDataRate); - return ret; -} -``` - -LCD器件驱动示例如下: - -``` -#define RESET_GPIO 5 -#define MIPI_DSI0 0 -#define BLK_PWM1 1 -#define PWM_MAX_PERIOD 100000 -/* backlight setting */ -#define MIN_LEVEL 0 -#define MAX_LEVEL 255 -#define DEFAULT_LEVEL 100 - -#define WIDTH 480 -#define HEIGHT 960 -#define HORIZONTAL_BACK_PORCH 20 -#define HORIZONTAL_FRONT_PORCH 20 -#define HORIZONTAL_SYNC_WIDTH 10 -#define VERTIACL_BACK_PORCH 14 -#define VERTIACL_FRONT_PORCH 16 -#define VERTIACL_SYNC_WIDTH 2 -#define FRAME_RATE 60 - -/* Panel Info结构体结构体 */ -struct PanelInfo { - uint32_t width; - uint32_t height; - uint32_t hbp; - uint32_t hfp; - uint32_t hsw; - uint32_t vbp; - uint32_t vfp; - uint32_t vsw; - uint32_t frameRate; - enum LcdIntfType intfType; - enum IntfSync intfSync; - struct MipiDsiDesc mipi; - struct BlkDesc blk; - struct PwmCfg pwm; -}; - -/* LCD屏的初始化序列 */ -static uint8_t g_payLoad0[] = { 0xF0, 0x5A, 0x5A }; -static uint8_t g_payLoad1[] = { 0xF1, 0xA5, 0xA5 }; -static uint8_t g_payLoad2[] = { 0xB3, 0x03, 0x03, 0x03, 0x07, 0x05, 0x0D, 0x0F, 0x11, 0x13, 0x09, 0x0B }; -static uint8_t g_payLoad3[] = { 0xB4, 0x03, 0x03, 0x03, 0x06, 0x04, 0x0C, 0x0E, 0x10, 0x12, 0x08, 0x0A }; -static uint8_t g_payLoad4[] = { 0xB0, 0x54, 0x32, 0x23, 0x45, 0x44, 0x44, 0x44, 0x44, 0x60, 0x00, 0x60, 0x1C }; -static uint8_t g_payLoad5[] = { 0xB1, 0x32, 0x84, 0x02, 0x87, 0x12, 0x00, 0x50, 0x1C }; -static uint8_t g_payLoad6[] = { 0xB2, 0x73, 0x09, 0x08 }; -static uint8_t g_payLoad7[] = { 0xB6, 0x5C, 0x5C, 0x05 }; -static uint8_t g_payLoad8[] = { 0xB8, 0x23, 0x41, 0x32, 0x30, 0x03 }; -static uint8_t g_payLoad9[] = { 0xBC, 0xD2, 0x0E, 0x63, 0x63, 0x5A, 0x32, 0x22, 0x14, 0x22, 0x03 }; -static uint8_t g_payLoad10[] = { 0xb7, 0x41 }; -static uint8_t g_payLoad11[] = { 0xC1, 0x0c, 0x10, 0x04, 0x0c, 0x10, 0x04 }; -static uint8_t g_payLoad12[] = { 0xC2, 0x10, 0xE0 }; -static uint8_t g_payLoad13[] = { 0xC3, 0x22, 0x11 }; -static uint8_t g_payLoad14[] = { 0xD0, 0x07, 0xFF }; -static uint8_t g_payLoad15[] = { 0xD2, 0x63, 0x0B, 0x08, 0x88 }; -static uint8_t g_payLoad16[] = { 0xC6, 0x08, 0x15, 0xFF, 0x10, 0x16, 0x80, 0x60 }; -static uint8_t g_payLoad17[] = { 0xc7, 0x04 }; -static uint8_t g_payLoad18[] = { - 0xC8, 0x7C, 0x50, 0x3B, 0x2C, 0x25, 0x16, 0x1C, 0x08, 0x27, 0x2B, 0x2F, 0x52, 0x43, 0x4C, 0x40, - 0x3D, 0x30, 0x1E, 0x06, 0x7C, 0x50, 0x3B, 0x2C, 0x25, 0x16, 0x1C, 0x08, 0x27, 0x2B, 0x2F, 0x52, - 0x43, 0x4C, 0x40, 0x3D, 0x30, 0x1E, 0x06 -}; -static uint8_t g_payLoad19[] = { 0x11 }; -static uint8_t g_payLoad20[] = { 0x29 }; - -struct DsiCmdDesc g_OnCmd[] = { - { 0x29, 0, sizeof(g_payLoad0), g_payLoad0 }, - { 0x29, 0, sizeof(g_payLoad1), g_payLoad1 }, - { 0x29, 0, sizeof(g_payLoad2), g_payLoad2 }, - { 0x29, 0, sizeof(g_payLoad3), g_payLoad3 }, - { 0x29, 0, sizeof(g_payLoad4), g_payLoad4 }, - { 0x29, 0, sizeof(g_payLoad5), g_payLoad5 }, - { 0x29, 0, sizeof(g_payLoad6), g_payLoad6 }, - { 0x29, 0, sizeof(g_payLoad7), g_payLoad7 }, - { 0x29, 0, sizeof(g_payLoad8), g_payLoad8 }, - { 0x29, 0, sizeof(g_payLoad9), g_payLoad9 }, - { 0x23, 0, sizeof(g_payLoad10), g_payLoad10 }, - { 0x29, 0, sizeof(g_payLoad11), g_payLoad11 }, - { 0x29, 0, sizeof(g_payLoad12), g_payLoad12 }, - { 0x29, 0, sizeof(g_payLoad13), g_payLoad13 }, - { 0x29, 0, sizeof(g_payLoad14), g_payLoad14 }, - { 0x29, 0, sizeof(g_payLoad15), g_payLoad15 }, - { 0x29, 0, sizeof(g_payLoad16), g_payLoad16 }, - { 0x23, 0, sizeof(g_payLoad17), g_payLoad17 }, - { 0x29, 1, sizeof(g_payLoad18), g_payLoad18 }, - { 0x05, 120, sizeof(g_payLoad19), g_payLoad19 }, - { 0x05, 120, sizeof(g_payLoad20), g_payLoad20 }, -}; -static DevHandle g_mipiHandle = NULL; -static DevHandle g_pwmHandle = NULL; - -/* 设置Reset Pin脚状态 */ -static int32_t LcdResetOn(void) -{ - int32_t ret; - ret = GpioSetDir(RESET_GPIO, GPIO_DIR_OUT); - if (ret != HDF_SUCCESS) { - HDF_LOGE("GpioSetDir failure, ret:%d", ret); - return HDF_FAILURE; - } - ret = GpioWrite(RESET_GPIO, GPIO_VAL_HIGH); - if (ret != HDF_SUCCESS) { - HDF_LOGE("GpioWrite failure, ret:%d", ret); - return HDF_FAILURE; - } - /* delay 20ms */ - OsalMSleep(20); - return HDF_SUCCESS; -} - -static int32_t SampleInit(void) -{ - /* 获取MIPI DSI设备操作句柄 */ - g_mipiHandle = MipiDsiOpen(MIPI_DSI0); - if (g_mipiHandle == NULL) { - HDF_LOGE("%s: MipiDsiOpen failure", __func__); - return HDF_FAILURE; - } - return HDF_SUCCESS; -} - -static int32_t SampleOn(void) -{ - int32_t ret; - /* LCD上电序列 */ - ret = LcdResetOn(); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: LcdResetOn failure", __func__); - return HDF_FAILURE; - } - if (g_mipiHandle == NULL) { - HDF_LOGE("%s: g_mipiHandle is null", __func__); - return HDF_FAILURE; - } - /* 使用mipi下发初始化序列 */ - int32_t count = sizeof(g_OnCmd) / sizeof(g_OnCmd[0]); - int32_t i; - for (i = 0; i < count; i++) { - ret = MipiDsiTx(g_mipiHandle, &(g_OnCmd[i])); - if (ret != HDF_SUCCESS) { - HDF_LOGE("MipiDsiTx failure"); - return HDF_FAILURE; - } - } - /* 将mipi切换到HS模式 */ - MipiDsiSetHsMode(g_mipiHandle); - return HDF_SUCCESS; -} - -/* PanelInfo结构体变量 */ -static struct PanelInfo g_panelInfo = { - .width = WIDTH, /* width */ - .height = HEIGHT, /* height */ - .hbp = HORIZONTAL_BACK_PORCH, /* horizontal back porch */ - .hfp = HORIZONTAL_FRONT_PORCH, /* horizontal front porch */ - .hsw = HORIZONTAL_SYNC_WIDTH, /* horizontal sync width */ - .vbp = VERTIACL_BACK_PORCH, /* vertiacl back porch */ - .vfp = VERTIACL_FRONT_PORCH, /* vertiacl front porch */ - .vsw = VERTIACL_SYNC_WIDTH, /* vertiacl sync width */ - .frameRate = FRAME_RATE, /* frame rate */ - .intfType = MIPI_DSI, /* panel interface type */ - .intfSync = OUTPUT_USER, /* output timming type */ - /* mipi config info */ - .mipi = { DSI_2_LANES, DSI_VIDEO_MODE, VIDEO_BURST_MODE, FORMAT_RGB_24_BIT }, - /* backlight config info */ - .blk = { BLK_PWM, MIN_LEVEL, MAX_LEVEL, DEFAULT_LEVEL }, - .pwm = { BLK_PWM1, PWM_MAX_PERIOD }, -}; - -/* 器件驱动需要适配的基础接口 */ -static struct PanelData g_panelData = { - .info = &g_panelInfo, - .init = SampleInit, - .on = SampleOn, - .off = SampleOff, - .setBacklight = SampleSetBacklight, -}; - -/* 器件驱动入口函数 */ -int32_t SampleEntryInit(struct HdfDeviceObject *object) -{ - HDF_LOGI("%s: enter", __func__); - if (object == NULL) { - HDF_LOGE("%s: param is null!", __func__); - return HDF_FAILURE; - } - /* 器件驱动接口注册,ops提供给平台驱动调用 */ - if (PanelDataRegister(&g_panelData) != HDF_SUCCESS) { - HDF_LOGE("%s: PanelDataRegister error!", __func__); - return HDF_FAILURE; - } - return HDF_SUCCESS; -} - -struct HdfDriverEntry g_sampleDevEntry = { - .moduleVersion = 1, - .moduleName = "LCD_SAMPLE", - .Init = SampleEntryInit, -}; - -HDF_INIT(g_sampleDevEntry); -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/04.\345\244\226\350\256\276\351\251\261\345\212\250\344\275\277\347\224\250/02.TOUCHSCREEN.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/04.\345\244\226\350\256\276\351\251\261\345\212\250\344\275\277\347\224\250/02.TOUCHSCREEN.md" deleted file mode 100644 index 7f3ffb7b1c8444e35f47fa22e847ce3b43b7c415..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/04.\345\244\226\350\256\276\351\251\261\345\212\250\344\275\277\347\224\250/02.TOUCHSCREEN.md" +++ /dev/null @@ -1,418 +0,0 @@ ---- -title: TOUCHSCREEN -permalink: /pages/0105020402 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:24 ---- -# TOUCHSCREEN - -- [概述](#section175431838101617) -- [接口说明](#section105459441659) -- [开发步骤](#section65745222184) -- [开发实例](#section263714411191) - - [设备描述配置](#section18249155619195) - - [板级配置及器件私有配置](#section3571192072014) - - [添加器件驱动](#section6356758162015) - - -## 概述 - -- **Touchscreen驱动主要任务** - - Touchscreen驱动用于驱动触摸屏使其正常工作,该驱动主要完成如下工作:对触摸屏驱动IC进行上电、配置硬件管脚并初始化其状态、注册中断、配置通信接口(I2C或SPI)、设定Input相关配置、下载及更新固件等操作。 - - -- **Touchscreen驱动层次说明** - - 本节主要介绍基于Input驱动模型开发touchscreen器件驱动,Input模型整体的框架如[图1](#fig6251184817261)。 - - Input驱动模型基于HDF驱动框架、Platform接口、OSAL接口进行开发,向上对接规范化的驱动接口HDI(Hardware Driver Interface)层,通过Input-HDI层对外提供硬件能力,即上层Input service可以通过HDI接口层获取相应的驱动能力,进而操控touchscreen等输入设备。 - - -**图 1** 基于HDF驱动框架的Input驱动模型 -![](/images/device-dev/driver/figures/基于HDF驱动框架的input驱动模型.png "基于HDF驱动框架的input驱动模型") - -- **Input驱动模型介绍** - - Input驱动模型核心部分由设备管理层、公共驱动层、器件驱动层组成。器件产生的数据借助平台数据通道能力从内核传递到用户态,驱动模型通过配置文件适配不同器件及硬件平台,提高开发者的器件驱动开发效率。如下部分为模型各部分的说明: - - - Input设备管理:为各类输入设备驱动提供Input设备的注册、注销接口,同时统一管理Input设备列表。 - - - Input平台驱动:指各类Input设备的公共抽象驱动(例如触摸屏的公共驱动),负责对板级硬件进行初始化、硬件中断处理、向manager注册Input设备等。 - - - Input器件驱动:指各器件厂家的差异化驱动,通过适配平台驱动预留的差异化接口,实现器件驱动开发量最小化。 - - - Input数据通道:提供一套通用的数据上报通道,各类别的Input设备驱动均可用此通道上报Input事件。 - - - Input配置解析:负责对Input设备的板级配置及器件私有配置进行解析及管理。 - - -- **基于HDF驱动框架开发器件驱动的优势** - - 在HDF(Hardware Driver Foundation)[驱动管理框架](/pages/0105020102)的基础上,Input驱动模型调用OSAL接口层和Platfom接口层提供的基础接口进行开发,包括bus通信接口、操作系统原生接口(memory、lock、thread、timer等)。由于OSAL接口和Platform接口屏蔽了芯片平台差异,所以基于Input驱动模型实现的touchscreen驱动可以进行跨平台、跨OS迁移,以便逐步实现驱动的一次开发,多端部署。 - - -## 接口说明 - -Touchscreen器件的硬件接口相对简单,根据PIN脚的属性,可以简单分为如下三类: - -- 电源接口 -- IO控制接口 -- 通信接口 - -**图 2** Touchscreen器件常用管脚 -![](/images/device-dev/driver/figures/Touchscreen器件常用管脚.png "Touchscreen器件常用管脚") - -如上图所示的三类接口,分别做简要说明如下: - -1. **电源接口** - - LDO\_1P8:1.8V数字电路 - - LDO\_3P3:3.3V模拟电路 - - 通常情况下,touchscreen驱动IC和LCD驱动IC是相互分离的,这种情况下,touchscreen驱动IC一般同时需要1.8V和3.3V两路供电。随着芯片演进,业内已有touchscreen驱动IC和LCD驱动IC集成在一颗IC中的芯片案例,对touchscreen而言,只需要关注1.8V供电即可,其内部需要的3.3V电源,会在驱动IC内部从LCD的VSP电源(典型值5.5V)中分出来。 - -2. **IO控制接口** - - Reset:reset管脚,用于在系统休眠、唤醒时,由主机侧对驱动IC进行复位操作。 - - INT:中断管脚,需要在驱动初始化时,配置为输入上拉状态。在驱动IC检测到外部触摸信号后,通过操作中断管脚来触发中断,器件驱动则会在中断处理函数中进行报点数据读取等操作。 - -3. **通信接口** - - I2C:由于touchscreen的报点数据量相对较少,所以一般选用I2C方式传输数据。I2C的具体协议及对应操作接口,可以参考Platform接口层中的[“I2C”使用指南](/pages/0105020304#section5361140416)。 - - SPI:部分厂商,由于需要传递的数据不止报点坐标,而是需要获取基础容值,数据量较大,所以会选用SPI通信方式。SPI的具体协议及对应操作接口,可以参考Platform接口层中的[“SPI” 使用指南](/pages/010502030b#section193356154511)。 - - -## 开发步骤 - -Input驱动模型是基于HDF框架、Platform接口和OSAL接口开发,不区分操作系统和芯片平台,为touchscreen等输入器件提供统一的驱动开发架构。 - -如下以touchscreen器件驱动为例,说明Input驱动模型的完整加载流程: - -(1)设备描述配置:由开发者参考已有模板进行设备描述配置,包括驱动加载顺序、板级硬件信息、器件私有数据信息等。 - -(2)加载Input设备管理驱动:Input设备管理驱动由HDF驱动加载,完成设备manager的创建并对其初始化。 - -(3)加载平台驱动:平台驱动由HDF框架加载,主要完成板级配置解析及硬件初始化,并提供器件注册接口。 - -(4)加载器件驱动:器件驱动也由HDF框架加载,完成器件设备的实例化,包括器件私有配置解析和平台预留的差异化接口适配。 - -(5)器件设备向平台驱动注册:将实例化的器件设备向平台驱动注册,实现设备和驱动的绑定,并完成中断注册、上下电等器件初始化工作。 - -(6)Input设备注册:在器件初始化完成后,实例化Input设备,并将其注册到Input manager进行管理。 - -请参考如下相关步骤: - -1. 设备描述配置 - - 目前Input驱动基于HDF驱动框架编写,驱动的加载启动由HDF驱动管理框架统一处理。首先需要在对应的配置文件中,将驱动信息注册进去,如是否加载、加载优先级,此后HDF驱动框架会逐一启动注册过的驱动模块。驱动的相关配置请参考[HDF驱动框架配置指导](/pages/0105020102#section1969312275533)。 - -2. 板级配置及Touchscreen器件私有配置 - - 配置对应的IO管脚功能,例如对单板上为touchscreen设计预留的I2C Pin脚,需设置对应的寄存器,使其选择I2C的通信功能。 - -3. 实现器件差异化适配接口 - - 根据硬件单板设计的通信接口,使用Platform接口层提供的管脚操作接口配置对应的复位管脚、中断管脚以及电源操作,对于GPIO的操作,可参考[GPIO操作接口指导](/pages/0105020302#section1635911016188) - - -## 开发实例 - -本实例提供touchscreen驱动开发示例,并简要对具体关键点进行开发说明。 - -### 设备描述配置 - -如下配置主要包含Input驱动模型各模块层级信息,具体原理可参考[HDF驱动开发指南](/pages/0105020102),HDF框架依据该配置信息实现对Input模型各模块的依次加载等。 - -``` -input :: host { - hostName = "input_host"; - priority = 100; - device_input_manager :: device { - device0 :: deviceNode { - policy = 2; // 向外发布服务 - priority = 100; // 加载优先级,在input模块内,manager模块优先级应为最高 - preload = 0; // 加载该驱动 0:加载 1:不加载 - permission = 0660; - moduleName = "HDF_INPUT_MANAGER"; - serviceName = "input_dev_manager"; - deviceMatchAttr = ""; - } - } - device_hdf_touch :: device { - device0 :: deviceNode { - policy = 2; - priority = 120; - preload = 0; - permission = 0660; - moduleName = "HDF_TOUCH"; - serviceName = "event1"; - deviceMatchAttr = "touch_device1"; - } - } - - device_touch_chip :: device { - device0 :: deviceNode { - policy = 0; - priority = 130; - preload = 0; - permission = 0660; - moduleName = "HDF_TOUCH_SAMPLE"; - serviceName = "hdf_touch_sample_service"; - deviceMatchAttr = "zsj_sample_5p5"; - } - } -} -``` - -### 板级配置及器件私有配置 - -如下配置包含板级硬件配置及器件私有数据配置,实际业务开发时,可根据具体需求增删及修改如下配置文件信息。 - -``` -root { - input_config { - touchConfig { - touch0 { - boardConfig { - match_attr = "touch_device1"; - inputAttr { - inputType = 0; // 0代表触摸屏 - solutionX = 480; - solutionY = 960; - devName = "main_touch"; // 设备名称 - } - busConfig { - busType = 0; // 0代表I2C - busNum = 6; - clkGpio = 86; - dataGpio = 87; - i2cClkIomux = [0x114f0048, 0x403]; // i2c_clk对应pin的寄存器配置 - i2cDataIomux = [0x114f004c, 0x403]; // i2c_data对应pin的寄存器配置 - } - pinConfig { - rstGpio = 3; - intGpio = 4; - rstRegCfg = [0x112f0094, 0x400]; // reset对应pin的寄存器配置 - intRegCfg = [0x112f0098, 0x400]; // interrupt对应pin的寄存器配置 - } - powerConfig { - vccType = 2; // 1代表LDO、2代表GPIO、3代表PMIC - vccNum = 20; // GPIO号为20 - vccValue = 1800; // 电压幅值为1800mV - vciType = 1; - vciNum = 12; - vciValue = 3300; - } - featureConfig { - capacitanceTest = 0; - gestureMode = 0; - gloverMOde = 0; - coverMode = 0; - chargerMode = 0; - knuckleMode = 0; - } - } - chipConfig { - template touchChip { - match_attr = ""; - chipName = "sample"; - vendorName = "zsj"; - chipInfo = "AAAA11222"; // 1~4字符代表产品名,5~6字符代表IC型号,7~9字符代表模型型号 - busType = 0; - deviceAddr = 0x5D; - irqFlag = 2; // 1代表上升沿触发,2代表下降沿触发,4代表高电平触发,8代表低电平触发 - maxSpeed = 400; - chipVersion = 0; - powerSequence { - /* 上电时序的配置含义说明: - [类型, 状态, 方向 , 延时] - 0代表空,1代表vcc电源(1.8V),2代表VCI电源(3.3V),3代表复位管脚,4代表中断管脚 - 0代表下电或拉低,1代表上电或拉高,2代表无操作 - 0代表输入方向,1代表输出方向,2代表无操作 - 代表延时多少毫秒, 例如20代表延时20ms - */ - powerOnSeq = [4, 0, 1, 0, - 3, 0, 1, 10, - 3, 1, 2, 60, - 4, 2, 0, 0]; - suspendSeq = [3, 0, 2, 10]; - resumeSeq = [3, 1, 2, 10]; - powerOffSeq = [3, 0, 2, 10, - 1, 0, 2, 20]; - } - } - chip0 :: touchChip { - match_attr = "zsj_sample_5p5"; - chipInfo = "ZIDN45100"; - chipVersion = 0; - } - } - } - } - } -} -``` - -### 添加器件驱动 - -在器件驱动中,主要实现了平台预留的差异化接口,以器件数据获取及解析进行示例说明。具体开发过程,需要根据实际使用的单板及器件进行适配。 - -``` -/* 将从器件中读取到的报点数据解析为坐标 */ -static void ParsePointData(ChipDevice *device, FrameData *frame, uint8_t *buf, uint8_t pointNum) -{ - int32_t resX = device->driver->boardCfg->attr.resolutionX; - int32_t resY = device->driver->boardCfg->attr.resolutionY; - - for (int32_t i = 0; i < pointNum; i++) { - frame->fingers[i].y = (buf[GT_POINT_SIZE * i + GT_X_LOW] & ONE_BYTE_MASK) | - ((buf[GT_POINT_SIZE * i + GT_X_HIGH] & ONE_BYTE_MASK) << ONE_BYTE_OFFSET); - frame->fingers[i].x = (buf[GT_POINT_SIZE * i + GT_Y_LOW] & ONE_BYTE_MASK) | - ((buf[GT_POINT_SIZE * i + GT_Y_HIGH] & ONE_BYTE_MASK) << ONE_BYTE_OFFSET); - frame->fingers[i].valid = true; - } -} -/* 从器件中获取报点数据 */ -static int32_t ChipDataHandle(ChipDevice *device) -{ - int32_t ret; - uint8_t touchStatus = 0; - uint8_t pointNum; - uint8_t buf[GT_POINT_SIZE * MAX_SUPPORT_POINT] = {0}; - InputI2cClient *i2cClient = &device->driver->i2cClient; - uint8_t reg[GT_ADDR_LEN] = {0}; - FrameData *frame = &device->driver->frameData; - reg[0] = (GT_BUF_STATE_ADDR >> ONE_BYTE_OFFSET) & ONE_BYTE_MASK; - reg[1] = GT_BUF_STATE_ADDR & ONE_BYTE_MASK; - ret = InputI2cRead(i2cClient, reg, GT_ADDR_LEN, &touchStatus, 1); - if (ret < 0 || touchStatus == GT_EVENT_INVALID) { - return HDF_FAILURE; - } - OsalMutexLock(&device->driver->mutex); - (void)memset_s(frame, sizeof(FrameData), 0, sizeof(FrameData)); - if (touchStatus == GT_EVENT_UP) { - frame->realPointNum = 0; - frame->definedEvent = TOUCH_UP; - goto exit; - } - reg[0] = (GT_X_LOW_BYTE_BASE >> ONE_BYTE_OFFSET) & ONE_BYTE_MASK; - reg[1] = GT_X_LOW_BYTE_BASE & ONE_BYTE_MASK; - pointNum = touchStatus & GT_FINGER_NUM_MASK; - if (pointNum <= 0 || pointNum > MAX_SUPPORT_POINT) { - HDF_LOGE("%s: pointNum is invalid, %d", __func__, pointNum); - (void)ChipCleanBuffer(i2cClient); - OsalMutexUnlock(&device->driver->mutex); - return HDF_FAILURE; - } - frame->realPointNum = pointNum; - frame->definedEvent = TOUCH_DOWN; - /* 从寄存器中读取报点值 */ - (void)InputI2cRead(i2cClient, reg, GT_ADDR_LEN, buf, GT_POINT_SIZE * pointNum); - /* 解析报点值 */ - ParsePointData(device, frame, buf, pointNum); -exit: - OsalMutexUnlock(&device->driver->mutex); - if (ChipCleanBuffer(i2cClient) != HDF_SUCCESS) { - return HDF_FAILURE; - } - return HDF_SUCCESS; -} - -static struct TouchChipOps g_sampleChipOps = { - .Init = ChipInit, - .Detect = ChipDetect, - .Resume = ChipResume, - .Suspend = ChipSuspend, - .DataHandle = ChipDataHandle, -}; - -static TouchChipCfg *ChipConfigInstance(struct HdfDeviceObject *device) -{ - TouchChipCfg *chipCfg = (TouchChipCfg *)OsalMemAlloc(sizeof(TouchChipCfg)); - if (chipCfg == NULL) { - HDF_LOGE("%s: instance chip config failed", __func__); - return NULL; - } - (void)memset_s(chipCfg, sizeof(TouchChipCfg), 0, sizeof(TouchChipCfg)); - /* 解析器件私有配置 */ - if (ParseTouchChipConfig(device->property, chipCfg) != HDF_SUCCESS) { - HDF_LOGE("%s: parse chip config failed", __func__); - OsalMemFree(chipCfg); - chipCfg = NULL; - } - return chipCfg; -} - -static ChipDevice *ChipDeviceInstance(void) -{ - ChipDevice *chipDev = (ChipDevice *)OsalMemAlloc(sizeof(ChipDevice)); - if (chipDev == NULL) { - HDF_LOGE("%s: instance chip device failed", __func__); - return NULL; - } - (void)memset_s(chipDev, sizeof(ChipDevice), 0, sizeof(ChipDevice)); - return chipDev; -} - -static void FreeChipConfig(TouchChipCfg *config) -{ - if (config->pwrSeq.pwrOn.buf != NULL) { - OsalMemFree(config->pwrSeq.pwrOn.buf); - } - if (config->pwrSeq.pwrOff.buf != NULL) { - OsalMemFree(config->pwrSeq.pwrOff.buf); - } - OsalMemFree(config); -} - -static int32_t HdfSampleChipInit(struct HdfDeviceObject *device) -{ - TouchChipCfg *chipCfg = NULL; - ChipDevice *chipDev = NULL; - HDF_LOGE("%s: enter", __func__); - if (device == NULL) { - return HDF_ERR_INVALID_PARAM; - } - /* 器件私有配置解析 */ - chipCfg = ChipConfigInstance(device); - if (chipCfg == NULL) { - return HDF_ERR_MALLOC_FAIL; - } - /* 器件设备实例化 */ - chipDev = ChipDeviceInstance(); - if (chipDev == NULL) { - goto freeCfg; - } - chipDev->chipCfg = chipCfg; - chipDev->ops = &g_sampleChipOps; - chipDev->chipName = chipCfg->chipName; - chipDev->vendorName = chipCfg->vendorName; - - /* 器件设备注册到平台驱动 */ - if (RegisterChipDevice(chipDev) != HDF_SUCCESS) { - goto freeDev; - } - HDF_LOGI("%s: exit succ, chipName = %s", __func__, chipCfg->chipName); - return HDF_SUCCESS; - -freeDev: - OsalMemFree(chipDev); -freeCfg: - FreeChipConfig(chipCfg); - return HDF_FAILURE; -} - -struct HdfDriverEntry g_touchSampleChipEntry = { - .moduleVersion = 1, - .moduleName = "HDF_TOUCH_SAMPLE", - .Init = HdfSampleChipInit, -}; - -HDF_INIT(g_touchSampleChipEntry); -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/04.\345\244\226\350\256\276\351\251\261\345\212\250\344\275\277\347\224\250/03.SENSOR.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/04.\345\244\226\350\256\276\351\251\261\345\212\250\344\275\277\347\224\250/03.SENSOR.md" deleted file mode 100644 index ff18827d4ebf4ce125c5ea77da9abaad3b8a0481..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/04.\345\244\226\350\256\276\351\251\261\345\212\250\344\275\277\347\224\250/03.SENSOR.md" +++ /dev/null @@ -1,905 +0,0 @@ ---- -title: SENSOR -permalink: /pages/0105020403 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:24 ---- -# SENSOR - -- [概述](##概述) - - [功能简介](###功能简介) - - [运作机制](###运作机制) - -- [开发指导](##开发指导) - - [接口说明](#section188213414114) - - [开发步骤](#section7893102915819) - - [开发实例](#section257750691) - - [调测验证](#section106021256121219) - - -## 概述 - -### 功能简介 - -Sensor设备作为外接设备重要组成模块,通过Sensor驱动模型屏蔽硬件器件差异,为上层Sensor服务系统提供稳定的Sensor基础能力接口,包括Sensor列表查询、Sensor启停、Sensor订阅及取消订阅,Sensor参数配置等功能;Sensor设备驱动的开发是基于HDF驱动框架基础上,结合操作系统适配层(OSAL)和平台驱动接口(比如I2C/SPI/UART总线等平台资源)能力,屏蔽不同操作系统和平台总线资源差异,实现Sensor驱动“一次开发,多系统部署”的目标。Sensor驱动模型如[图1](#fig10451455446)所示: - -**图 1** Sensor驱动模型图 - - -### 运作机制 - -通过介绍Sensor驱动模型的加载以及运行流程,对模型内部关键组件以及关联组件之间的关系进行了划分,整体加载流程如[图2](#Sensor驱动模型图)所示: - -**图 2** Sensor驱动模型运行图 - - - -Sensor驱动模型以标准系统Hi3516DV300产品中的加速度传感器驱动为例,介绍整个驱动加载及运行流程: - -1. 从device info HCS 的Sensor Host读取Sensor设备管理配置信息。 -2. HDF配置框架从HCB数据库解析Sensor设备管理配置信息,并关联对应设备驱动。 -3. 加载并初始化Sensor设备管理驱动。 -4. Sensor设备管理驱动向HDI发布Sensor基础能力接口。 -5. 从device info HCS 的Sensor Host读取加速度传感器驱动配置信息。 -6. 加载加速度传感器抽象驱动,调用初始化接口,完成Sensor器件驱动资源分配和数据处理队列创建。 -7. 从accel_xxx_config HCS读取加速度传感器差异化驱动配置和私有化配置信息。 -8. 加速度传感器差异化驱动,调用通用配置解析接口,完成器件属性信息解析,器件寄存器解析。 -9. 加速度传感器差异化驱动完成器件探测,并分配加速度传感器配置资源,完成加速度传感器差异化接口注册。 -10. 加速度传感器探测成功之后,加速度传感器差异化驱动通知加速度传感器抽象驱动,注册加速度传感器设备到Sensor设备管理中。 - -## 开发指导 - -### 接口说明 - -Sensor驱动模型对外开放的API接口能力如下: - -- 提供Sensor HDI(Hardware Driver Interface)能力接口,简化服务开发。 -- 提供Sensor驱动模型能力接口: - - 依赖HDF驱动框架实现Sensor器件驱动的注册,加载,去注册,器件探测等能力。 - - 提供同一类型Sensor器件驱动归一接口, 寄存器配置解析操作接口,总线访问抽象接口,平台抽象接口。 -- 提供开发者实现的能力接口:依赖HDF驱动框架的HCS(HDF Configuration Source)配置管理,根据同类型Sensor差异化配置,实现Sensor器件参数序列化配置和器件部分操作接口,简化Sensor器件驱动开发。 - -Sensor驱动模型对外开放的API接口能力的具体实现参考[表1](#table203963834718): - -**表 1** Sensor驱动模型对外API接口功能介绍 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名

-

功能描述

-

查询操作

-

int32_t GetAllSensors(struct SensorInformation **sensorInfo, int32_t *count)

-

获取系统中注册的所有传感器信息,一组完整传感器信息包括传感器名字、设备厂商、固件版本号、硬件版本号、传感器类型编号、传感器标识、最大量程、精度、功耗。

-

配置操作

-

int32_t Enable(int32_t sensorId)

-

使能指定传感器设备,只有数据订阅者使能传感器后,才能获取订阅的传感器数据。

-

int32_t Disable(int32_t sensorId)

-

去使能指定传感器设备。

-

int32_t SetBatch(iint32_t sensorId, int64_t samplingInterval, int64_t reportInterval)

-

设置指定传感器的数据采样间隔和数据上报间隔。

-

int32_t SetMode(int32_t sensorId, int32_t mode)

-

设置指定传感器的工作模式,不同的工作模式,上报数据方式不同。

-

int32_t SetOption(int32_t sensorId, uint32_t option)

-

设置指定传感器量程,精度等可选配置。

-

数据订阅操作

-

int32_t Register(sensorId, RecordDataCallback cb);

-

订阅者根据不同sensorId注册传感器数据回调函数,系统会将获取到的传感器数据上报给订阅者。

-

int32_t Unregister(sensorId, RecordDataCallback cb)

-

订阅者根据sensorId和回调函数注销对应订阅者的传感器数据回调函数。

-
-Sensor驱动模型对驱动开发者开放的功能接口,驱动开发者无需实现,直接使用,参考[表2](#table1156812588320): - - **表2** Sensor驱动模型对驱动开发者开放的功能接口列表 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名

-

功能描述

-

设备管理操作接口

-

int32_t AddSensorDevice(const struct SensorDeviceInfo *deviceInfo)

-

添加当前类型的传感器设备到传感器设备管理。

-

int32_t DeleteSensorDevice(const struct SensorBasicInfo *sensorBaseInfo)

-

删除传感器设备管理里指定的传感器设备。

-

int32_t ReportSensorEvent(const struct SensorReportEvent *events)

-

上报指定类型传感器的数据到用户侧。

-

Sensor抽象总线

-

int32_t ReadSensor(struct SensorBusCfg *busCfg, uint16_t regAddr, uint8_t *data, uint16_t dataLen)

-

按照配置的总线方式,读取传感器寄存器配置数据。

-

int32_t WriteSensor(struct SensorBusCfg *busCfg, uint8_t *writeData, uint16_t len)

-

按照配置的总线方式,将传感器配置数据写入寄存器。

-

通用配置操作接口

-

int32_t SetSensorRegCfgArray(struct SensorBusCfg *busCfg, const struct SensorRegCfgGroupNode *group);

-

根据传感器总线类型信息,下发寄存器分组配置。

-

配置解析操作接口

-

-

int32_t GetSensorBaseConfigData(const struct DeviceResourceNode *node, struct SensorCfgData *config)

-

根据传感器设备HCS资源配置,获取传感器信息,总线配置信息,属性配置等基本配置信息,并初始化对应的基本配置数据结构体。

-

int32_t ParseSensorRegConfig(struct SensorCfgData *config)

-

根据传感器设备HCS资源配置,解析寄存器分组信息,并初始化配置数据结构体。

-

void ReleaseSensorAllRegConfig(struct SensorCfgData *config)

-

释放传感器配置数据结构体里分配的资源。

-

int32_t GetSensorBusHandle(struct SensorBusCfg *busCfg)

-

获取传感器总线句柄信息。

-

int32_t ReleaseSensorBusHandle(struct SensorBusCfg *busCfg)

-

释放传感器句柄信息。

-
- -Sensor驱动模型要求驱动开发者实现的接口功能,参考[表3](#table1083014911336): - -**表 3** Sensor驱动模型要求驱动开发者实现的接口列表 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名

-

功能描述

-

基本功能操作

-

int32_t init(void)

-

传感器设备探测成功后,需要对传感器设备初始化配置。

-

int32_t Enable(void)

-

根据当前传感器设备的HCS配置,下发传感器设备使能操作组的寄存器配置。

-

int32_t Disable(void)

-

根据当前传感器设备的HCS配置,下发传感器设备去使能操作组的寄存器配置。

-

int32_t SetBatch(int64_t samplingInterval, int64_t reportInterval)

-

根据数据采样率和数据上报间隔,配置当前传感器设备的数据上报线程处理时间。

-

int32_t SetMode(int32_t mode)

-

配置当前传感器设备数据上报方式。

-

int32_t SetOption(uint32_t option)

-

根据可选配置、下发量程和精度等寄存器配置。

-

void ReadSensorData(void)

-

实现传感器的数据读取函数。

-
-接口实现参考[开发实例](#section257750691)章节。 - -### 开发步骤 -1. 基于HDF驱动框架,按照驱动Driver Entry程序,完成加速度抽象驱动开发,主要由Bind、Init、Release、Dispatch函数接口实现。 -2. 完成加速度传感器驱动的设备信息配置。 -3. 完成加速度传感器抽象驱动内部接口开发,包括Enable、Disable、SetBatch、SetMode、SetOption、AccelCreateCfgData、AccelReleaseCfgData、AccelRegisterChipOps接口实现。 -4. 基于HDF驱动框架,按照驱动Driver Entry程序,完成加速度传感器差异化驱动开发,主要有Bind、Init、Release、Dispatch函数接口实现。 -5. 完成加速度传感器差异化驱动中差异化接口ReadData函数实现。 -6. 新增文件脚本适配。 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** -> ->- 传感器驱动模型已经提供一部分能力集,包括驱动设备管理能力、抽象总线和平台操作接口能力、通用配置操作接口能力、配置解析操作接口能力,接口参考[表2](#table1156812588320)。 -> ->- 需要开发人员实现部分有:传感器部分操作接口([表3](#table1083014911336))和传感器HCS差异化数据配置。 -> - 驱动基本功能验证。 - -### 开发实例 - -基于HDF驱动模型,加载启动加速度计传感器驱动,代码形式如下,具体原理可参考[HDF驱动开发指南](/pages/0105020102)。本例中加速度传感器选择博世BMI160,其通讯接口方式选择I2C。 - -1. 加速度传感器驱动入口注册 - - - 加速度传感器驱动入口函数实现 - - ``` - /* 注册加速度计传感器入口数据结构体对象 */ - struct HdfDriverEntry g_sensorAccelDevEntry = { - .moduleVersion = 1, //加速度计传感器模块版本号 - .moduleName = "HDF_SENSOR_ACCEL", //加速度计传感器模块名,要与device_info.hcs文件里的加速度计moduleName字段值一样 - .Bind = BindAccelDriver, // 加速度计传感器绑定函数 - .Init = InitAccelDriver, // 加速度计传感器初始化函数 - .Release = ReleaseAccelDriver, // 加速度计传感器资源释放函数 - }; - - /* 调用HDF_INIT将驱动入口注册到HDF框架中,在加载驱动时HDF框架会先调用Bind函数,再调用Init函数加载该驱动,当Init调用异常时,HDF框架会调用Release释放驱动资源并退出 */ - HDF_INIT(g_sensorAccelDevEntry); - ``` - - - 加速度传感器设备配置描述 - - 加速度传感器模型使用HCS作为配置描述源码,HCS配置字段请参考[配置管理](/pages/0105020105)介绍。 - - ``` - /* 加速度计传感器设备HCS配置 */ - device_sensor_accel :: device { - device0 :: deviceNode { - policy = 1; // 驱动服务发布的策略 - priority = 110; // 驱动启动优先级(0-200),值越大优先级越低,建议配置为100,优先级相同则不保证device的加载顺序 - preload = 0; // 驱动按需加载字段,0表示加载,2表示不加载 - permission = 0664; // 驱动创建设备节点权限 - moduleName = "HDF_SENSOR_ACCEL"; // 驱动名称,该字段的值必须和驱动入口结构的moduleName值一致 - serviceName = "sensor_accel"; // 驱动对外发布服务的名称,必须唯一 - deviceMatchAttr = "hdf_sensor_accel_driver"; // 驱动私有数据匹配的关键字,必须和驱动私有数据配置表中的match_attr值相等 - } - } - ``` - -2. 加速度传感器驱动操作接口实现 - - 开发者需要根据每种类型的传感器实现归一化接口。 - - ``` - /* 不使用函数暂时置空 */ - static int32_t SetAccelInfo(struct SensorBasicInfo *info) - { - (void)info; - - return HDF_ERR_NOT_SUPPORT; - } - /* 下发使能寄存器组的配置 */ - static int32_t SetAccelEnable(void) - { - int32_t ret; - struct AccelDrvData *drvData = AccelGetDrvData(); - - CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM); - CHECK_NULL_PTR_RETURN_VALUE(drvData->accelCfg, HDF_ERR_INVALID_PARAM); - - if (drvData->enable) { - HDF_LOGE("%s: Accel sensor is enabled", __func__); - return HDF_SUCCESS; - } - - ret = SetSensorRegCfgArray(&drvData->accelCfg->busCfg, drvData->accelCfg->regCfgGroup[SENSOR_ENABLE_GROUP]); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: Accel sensor enable config failed", __func__); - return ret; - } - - ret = OsalTimerCreate(&drvData->accelTimer, SENSOR_TIMER_MIN_TIME, AccelTimerEntry, (uintptr_t)drvData); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: Accel create timer failed[%d]", __func__, ret); - return ret; - } - - ret = OsalTimerStartLoop(&drvData->accelTimer); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: Accel start timer failed[%d]", __func__, ret); - return ret; - } - drvData->enable = true; - - return HDF_SUCCESS; - } - /* 下发去使能寄存器组的配置 */ - static int32_t SetAccelDisable(void) - { - int32_t ret; - struct AccelDrvData *drvData = AccelGetDrvData(); - - CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM); - CHECK_NULL_PTR_RETURN_VALUE(drvData->accelCfg, HDF_ERR_INVALID_PARAM); - - if (!drvData->enable) { - HDF_LOGE("%s: Accel sensor had disable", __func__); - return HDF_SUCCESS; - } - - ret = SetSensorRegCfgArray(&drvData->accelCfg->busCfg, drvData->accelCfg->regCfgGroup[SENSOR_DISABLE_GROUP]); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: Accel sensor disable config failed", __func__); - return ret; - } - - ret = OsalTimerDelete(&drvData->accelTimer); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: Accel delete timer failed", __func__); - return ret; - } - drvData->enable = false; - - return HDF_SUCCESS; - } - /* 配置传感器采样率和数据上报间隔 */ - static int32_t SetAccelBatch(int64_t samplingInterval, int64_t interval) - { - (void)interval; - - struct AccelDrvData *drvData = NULL; - - drvData = AccelGetDrvData(); - CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM); - - drvData->interval = samplingInterval; - - return HDF_SUCCESS; - } - /* 设置传感器工作模式,当前支持实时模式 */ - static int32_t SetAccelMode(int32_t mode) - { - return (mode == SENSOR_WORK_MODE_REALTIME) ? HDF_SUCCESS : HDF_FAILURE; - } - - static int32_t SetAccelOption(uint32_t option) - { - (void)option; - return HDF_SUCCESS; - } - - /* 设置传感器可选配置 */ - static int32_t SetAccelOption(uint32_t option) - { - (void)option; - return HDF_ERR_NOT_SUPPORT; - } - ``` - -3. 加速度传感器驱动初始化和去初始化 - - ``` - /* 加速度计传感器驱动对外提供的服务绑定到HDF框架 */ - int32_t AccelBindDriver(struct HdfDeviceObject *device) - { - CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM); - - struct AccelDrvData *drvData = (struct AccelDrvData *)OsalMemCalloc(sizeof(*drvData)); - if (drvData == NULL) { - HDF_LOGE("%s: Malloc accel drv data fail!", __func__); - return HDF_ERR_MALLOC_FAIL; - } - - drvData->ioService.Dispatch = DispatchAccel; - drvData->device = device; - device->service = &drvData->ioService; - g_accelDrvData = drvData; - return HDF_SUCCESS; - } - - /* 挂载加速度计传感器驱动归一化的接口函数 */ - static int32_t InitAccelOps(struct SensorCfgData *config, struct SensorDeviceInfo *deviceInfo) - { - CHECK_NULL_PTR_RETURN_VALUE(config, HDF_ERR_INVALID_PARAM); - - deviceInfo->ops.Enable = SetAccelEnable; - deviceInfo->ops.Disable = SetAccelDisable; - deviceInfo->ops.SetBatch = SetAccelBatch; - deviceInfo->ops.SetMode = SetAccelMode; - deviceInfo->ops.SetOption = SetAccelOption; - - if (memcpy_s(&deviceInfo->sensorInfo, sizeof(deviceInfo->sensorInfo), - &config->sensorInfo, sizeof(config->sensorInfo)) != EOK) { - HDF_LOGE("%s: Copy sensor info failed", __func__); - return HDF_FAILURE; - } - - return HDF_SUCCESS; - } - /* 提供给差异化驱动的初始化接口,完成加速度器件基本配置信息解析(加速度信息,加速度总线配置,加速度器件探测寄存器配置),器件探测,器件寄存器解析 */ - static int32_t InitAccelAfterDetected(struct SensorCfgData *config) - { - struct SensorDeviceInfo deviceInfo; - CHECK_NULL_PTR_RETURN_VALUE(config, HDF_ERR_INVALID_PARAM); - /* 初始化加速度计接口函数 */ - if (InitAccelOps(config, &deviceInfo) != HDF_SUCCESS) { - HDF_LOGE("%s: Init accel ops failed", __func__); - return HDF_FAILURE; - } - /* 注册加速度计设备到传感器管理模块 */ - if (AddSensorDevice(&deviceInfo) != HDF_SUCCESS) { - HDF_LOGE("%s: Add accel device failed", __func__); - return HDF_FAILURE; - } - /* 器件寄存器解析 */ - if (ParseSensorRegConfig(config) != HDF_SUCCESS) { - HDF_LOGE("%s: Parse sensor register failed", __func__); - (void)DeleteSensorDevice(&config->sensorInfo); - ReleaseSensorAllRegConfig(config); - return HDF_FAILURE; - } - return HDF_SUCCESS; - } - struct SensorCfgData *AccelCreateCfgData(const struct DeviceResourceNode *node) - { - …… - /* 如果探测不到器件在位,返回进行下个器件探测 */ - if (drvData->detectFlag) { - HDF_LOGE("%s: Accel sensor have detected", __func__); - return NULL; - } - if (drvData->accelCfg == NULL) { - HDF_LOGE("%s: Accel accelCfg pointer NULL", __func__); - return NULL; - } - /* 设备基本配置信息解析 */ - if (GetSensorBaseConfigData(node, drvData->accelCfg) != HDF_SUCCESS) { - HDF_LOGE("%s: Get sensor base config failed", __func__); - goto BASE_CONFIG_EXIT; - } - /* 如果探测不到器件在位,返回进行下个器件探测 */ - if (DetectSensorDevice(drvData->accelCfg) != HDF_SUCCESS) { - HDF_LOGI("%s: Accel sensor detect device no exist", __func__); - drvData->detectFlag = false; - goto BASE_CONFIG_EXIT; - } - drvData->detectFlag = true; - /* 器件寄存器解析 */ - if (InitAccelAfterDetected(drvData->accelCfg) != HDF_SUCCESS) { - HDF_LOGE("%s: Accel sensor detect device no exist", __func__); - goto INIT_EXIT; - } - return drvData->accelCfg; - …… - } - /* 加速度计传感器驱动初始化入口函数,主要功能为对传感器私有数据的结构体对象进行初始化,传感器HCS数据配置对象空间分配,传感器HCS数据配置初始化入口函数调用,传感器设备探测是否在位功能,传感器数据上报定时器创建,传感器归一化接口挂载,传感器设备注册功能 */ - int32_t InitAccelDriver(struct HdfDeviceObject *device) - { - int32_t AccelInitDriver(struct HdfDeviceObject *device) - { - …… - /* 工作队列资源初始化 */ - if (InitAccelData(drvData) != HDF_SUCCESS) { - HDF_LOGE("%s: Init accel config failed", __func__); - return HDF_FAILURE; - } - /* 分配加速度配置信息资源 */ - drvData->accelCfg = (struct SensorCfgData *)OsalMemCalloc(sizeof(*drvData->accelCfg)); - if (drvData->accelCfg == NULL) { - HDF_LOGE("%s: Malloc accel config data failed", __func__); - return HDF_FAILURE; - } - /* 挂接寄存器分组信息 */ - drvData->accelCfg->regCfgGroup = &g_regCfgGroup[0]; - …… - return HDF_SUCCESS; - } - - /* 释放驱动初始化时分配的资源 */ - void AccelReleaseDriver(struct HdfDeviceObject *device) - { - CHECK_NULL_PTR_RETURN(device); - struct AccelDrvData *drvData = (struct AccelDrvData *)device->service; - CHECK_NULL_PTR_RETURN(drvData); - /* 器件在位,释放已分配资源 */ - if (drvData->detectFlag) { - AccelReleaseCfgData(drvData->accelCfg); - } - OsalMemFree(drvData->accelCfg); - drvData->accelCfg = NULL; - /* 器件在位,销毁工作队列资源 */ - HdfWorkDestroy(&drvData->accelWork); - HdfWorkQueueDestroy(&drvData->accelWorkQueue); - OsalMemFree(drvData); - } - ``` - -4. 加速度传感器差异化驱动私有HCS配置实现 - - - 为了方便开发者使用传感器HCS私有配置,在sensor_common.hcs里面定义通用的传感器配置模板,加速度传感器直接引用模板修改对应的属性值即可。 - - ``` - accel sensor common config template - root { - sensorAccelConfig { - accelChipConfig { - /* 传感器设备信息模板 */ - template sensorInfo { - sensorName = "accelerometer"; // 加速度计名字,字符最大长度16字节 - vendorName = "borsh_bmi160"; // 传感器设备厂商,字符最大长度16字节 - firmwareVersion = "1.0"; // 传感器固件版本号,默认1.0,字符最大长度16字节 - hardwareVersion = "1.0"; // 传感器硬件版本号,默认1.0,字符最大长度16字节 - sensorTypeId = 1; // 传感器类型编号,详见{@link SensorTypeTag} - sensorId = 1; // 传感器的标识号,有传感器驱动开发者定义,推荐用{@link SensorTypeTag}枚举 - maxRange = 8; // 传感器的最大量程,根据开发者需要配置 - accuracy = 0; // 传感器的精度,与上报数据配合使用,上报数据结构体{@link SensorEvents } - power = 230; // 传感器的功耗 - } - /* 传感器使用的总线类型和配置信息模板 */ - template sensorBusConfig { - busType = 0; // 0:i2c 1:spi - busNum = 6; // 芯片上分配给传感器的器件号 - busAddr = 0; // 芯片上分配给传感器的地址 - regWidth = 1; // 传感器寄存器地址宽度 - regBigEndian = 0; // 传感器寄存器大小端 - } - /* 传感器设备属性模板 */ - template sensorAttr { - chipName = ""; // 传感器芯片名字 - chipIdRegister = 0xf; // 传感器在位检测寄存器地址 - chipIdValue = 0xd1; // 校验传感器在位检测寄存器值 - } - } - } - } - ``` - - - 开发者使用传感器HCS配置,在accel_config.hcs里面配置通用的传感器模板,加速度传感器直接引用模板并修改对应的属性值,在此基础上新增寄存器配置,生成accel_bmi160_config.hcs配置文件。 - - ``` - /* 根据不同器件硬件差异,修改模板配置,不修改的就会默认采用模板配置 */ - #include "accel_config.hcs" - root { - accel_bmi160_chip_config : sensorConfig { - match_attr = "hdf_sensor_accel_bmi160_driver"; - sensorInfo :: sensorDeviceInfo { - vendorName = "borsh_bmi160"; // max string length is 16 bytes - sensorTypeId = 1; // enum SensorTypeTag - sensorId = 1; // user define sensor id - } - sensorBusConfig:: sensorBusInfo { - busType = 0; // 0:i2c 1:spi - busNum = 6; - busAddr = 0x68; - regWidth = 1; // 1btye - } - sensorIdAttr :: sensorIdInfo{ - chipName = "bmi160"; - chipIdRegister = 0x00; - chipIdValue = 0xd1; - } - sensorRegConfig { - /* regAddr: register address - value: config register value - len: size of value - mask: mask of value - delay: config register delay time (ms) - opsType: enum SensorOpsType 0-none 1-read 2-write 3-read_check 4-update_bit - calType: enum SensorBitCalType 0-none 1-set 2-revert 3-xor 4-left shift 5-right shift - shiftNum: shift bits - debug: 0-no debug 1-debug - save: 0-no save 1-save - */ - /* regAddr, value, mask, len, delay, opsType, calType, shiftNum, debug, save */ - /* 初始化寄存器组 */ - initSeqConfig = [ - 0x7e, 0xb6, 0xff, 1, 5, 2, 0, 0, 0, 0, - 0x7e, 0x10, 0xff, 1, 5, 2, 0, 0, 0, 0 - ]; - /* 使能寄存器组 */ - enableSeqConfig = [ - 0x7e, 0x11, 0xff, 1, 5, 2, 0, 0, 0, 0, - 0x41, 0x03, 0xff, 1, 0, 2, 0, 0, 0, 0, - 0x40, 0x08, 0xff, 1, 0, 2, 0, 0, 0, 0 - ]; - /* 去使能寄存器组 */ - disableSeqConfig = [ - 0x7e, 0x10, 0xff, 1, 5, 2, 0, 0, 0, 0 - ]; - } - } - } - ``` - -5. 加速度传感器差异化驱动实现 - - - 定义加速度传感器差异化驱动对应的HdfDriverEntry对象,其中Driver Entry入口函数定义如下: - - ``` - struct HdfDriverEntry g_accelBmi160DevEntry = { - .moduleVersion = 1, - .moduleName = "HDF_SENSOR_ACCEL_BMI160", - .Bind = Bmi160BindDriver, - .Init = Bmi160InitDriver, - .Release = Bmi160ReleaseDriver, - }; - HDF_INIT(g_accelBmi160DevEntry); - ``` - - - Bind驱动接口实例化。 - - ``` - int32_t Bmi160BindDriver(struct HdfDeviceObject *device) - { - CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM); - struct Bmi160DrvData *drvData = (struct Bmi160DrvData *)OsalMemCalloc(sizeof(*drvData)); - if (drvData == NULL) { - HDF_LOGE("%s: Malloc Bmi160 drv data fail", __func__); - return HDF_ERR_MALLOC_FAIL; - } - drvData->ioService.Dispatch = DispatchBMI160; - drvData->device = device; - device->service = &drvData->ioService; - g_bmi160DrvData = drvData; - return HDF_SUCCESS; - } - ``` - - - Init驱动接口实例化。 - - ``` - int32_t Bmi160InitDriver(struct HdfDeviceObject *device) - { - …… - /* 加速度计差异化初始化配置 */ - ret = InitAccelPreConfig(); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: Init BMI160 bus mux config", __func__); - return HDF_FAILURE; - } - /* 创建传感器配置数据接口,完成器件探测,私有数据配置解析 */ - drvData->sensorCfg = AccelCreateCfgData(device->property); - if (drvData->sensorCfg == NULL) { - return HDF_ERR_NOT_SUPPORT; - } - /* 注册差异化接口 */ - ops.Init = NULL; - ops.ReadData = ReadBmi160Data; - ret = AccelRegisterChipOps(&ops); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: Register BMI160 accel failed", __func__); - return HDF_FAILURE; - } - /* 初始化器件配置 *、 - ret = InitBmi160(drvData->sensorCfg); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: Init BMI160 accel failed", __func__); - return HDF_FAILURE; - } - return HDF_SUCCESS; - } - ``` - - - Release驱动接口实例化。 - - ``` - void Bmi160ReleaseDriver(struct HdfDeviceObject *device) - { - CHECK_NULL_PTR_RETURN(device); - struct Bmi160DrvData *drvData = (struct Bmi160DrvData *)device->service; - CHECK_NULL_PTR_RETURN(drvData); - AccelReleaseCfgData(drvData->sensorCfg); - drvData->sensorCfg = NULL; - OsalMemFree(drvData); - } - ``` - -6. 加速度传感器差异化函数接口实现 - - 需要开发者实现的ReadBmi160Data接口函数,在Bmi160InitDriver函数里面注册此函数。 - - ``` - int32_t ReadBmi160Data(struct SensorCfgData *data) - { - int32_t ret; - struct AccelData rawData = { 0, 0, 0 }; - int32_t tmp[ACCEL_AXIS_NUM]; - struct SensorReportEvent event; - (void)memset_s(&event, sizeof(event), 0, sizeof(event)); - ret = ReadBmi160RawData(data, &rawData, &event.timestamp); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: BMI160 read raw data failed", __func__); - return HDF_FAILURE; - } - event.sensorId = SENSOR_TAG_ACCELEROMETER; - event.option = 0; - event.mode = SENSOR_WORK_MODE_REALTIME; - …… - ret = ReportSensorEvent(&event); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: BMI160 report data failed", __func__); - } - return ret; - } - ``` - -7. 主要的数据结构 - - ``` - /* 传感器2g对应灵敏度转换值 */ - #define BMI160_ACC_SENSITIVITY_2G 61 - /* 传感器数据采样寄存器地址 */ - #define BMI160_ACCEL_X_LSB_ADDR 0X12 - #define BMI160_ACCEL_X_MSB_ADDR 0X13 - #define BMI160_ACCEL_Y_LSB_ADDR 0X14 - #define BMI160_ACCEL_Y_MSB_ADDR 0X15 - #define BMI160_ACCEL_Z_LSB_ADDR 0X16 - #define BMI160_ACCEL_Z_MSB_ADDR 0X17 - #define BMI160_STATUS_ADDR 0X1B - /* 传感器数据维度 */ - enum AccelAxisNum { - ACCEL_X_AXIS = 0, - ACCEL_Y_AXIS = 1, - ACCEL_Z_AXIS = 2, - ACCEL_AXIS_NUM = 3, - }; - /* 传感器每个维度值 */ - struct AccelData { - int32_t x; - int32_t y; - int32_t z; - }; - /* 传感器私有数据结构体 */ - struct AccelDrvData { - struct IDeviceIoService ioService; - struct HdfDeviceObject *device; - HdfWorkQueue accelWorkQueue; - HdfWork accelWork; - OsalTimer accelTimer; - bool detectFlag; - bool enable; - int64_t interval; - struct SensorCfgData *accelCfg; - struct AccelOpsCall ops; - }; - /* 差异化适配函数 */ - struct AccelOpsCall { - int32_t (*Init)(struct SensorCfgData *data); - int32_t (*ReadData)(struct SensorCfgData *data); - }; - ``` - -### 调测验证 - -驱动开发完成后,在传感器单元测试里面开发自测试用例,验证驱动基本功能。测试环境采用开发者自测试平台。 - -``` -static int32_t g_sensorDataFlag = 0; //标识是否上报传感器数据 -static const struct SensorInterface *g_sensorDev = nullptr; //保持获取的传感器接口实例地址 - -/* 订阅者注册数据上报函数 */ -static int SensorTestDataCallback(struct SensorEvents *event) -{ - if (event == nullptr) { - return -1; - } - float *data = (float*)event->data; - printf("time [%lld] sensor id [%d] x-[%f] y-[%f] z-[%f]\n\r", event->timestamp, - event->sensorId, (*data), *(data + 1), *(data + g_axisZ)); - if (*data > 1e-5) { - g_sensorDataFlag = 1; - } - return 0; -} -/* 用例执行前,初始化传感器接口实例 */ -void HdfSensorTest::SetUpTestCase() -{ - g_sensorDev = NewSensorInterfaceInstance(); - if (g_sensorDev == nullptr) { - printf("test sensorHdi get Module instace failed\n\r"); - } -} -/* 用例资源释放 */ -void HdfSensorTest::TearDownTestCase() -{ - if (g_sensorDev != nullptr) { - FreeSensorInterfaceInstance(); - g_sensorDev = nullptr; - } -} -/* 传感器驱动测试验证 */ -HWTEST_F(HdfSensorTest,TestAccelDriver_001, TestSize.Level0) -{ - int32_t sensorInterval = 1000000000; // 数据采样率单位纳秒 - int32_t pollTime = 5; // 数据采样时间单位秒 - int32_t accelSensorId = 1; // 加速度传感器类型标识为1 - int32_t count = 0; - int ret; - struct SensorInformation *sensorInfo = nullptr; - - ret = g_sensorDev->Register(0, TraditionSensorTestDataCallback) - EXPECT_EQ(SENSOR_NULL_PTR, ret); - - ret = g_sensorDev->GetAllSensors(&sensorInfo, &count); - EXPECT_EQ(0, ret); - if (sensorInfo == nullptr) { - EXPECT_NE(nullptr, sensorInfo); - return; - } - /* 打印获取的传感器列表 */ - for (int i = 0; i < count; i++) { - printf("get sensoriId[%d], info name[%s]\n\r", sensorInfo[i]->sensorId, sensorInfo[i]->sensorName); - } - ret = g_sensorDev->Enable(accelSensorId); - EXPECT_EQ(0, ret); - g_sensorDataFlag = 0; - - ret = g_sensorDev->SetBatch(accelSensorId, sensorInterval, pollTime); - EXPECT_EQ(0, ret); - /* 在时间pollTime内,观察输出打印数据 */ - OsalSleep(pollTime); - EXPECT_EQ(1, g_sensorDataFlag); - - ret = g_sensorDev->Disable(accelSensorId); - g_sensorDataFlag = 0; - EXPECT_EQ(0, ret); - - ret = g_sensorDev->Unregister(0, TraditionSensorTestDataCallback); - EXPECT_EQ(0, ret); -} -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/04.\345\244\226\350\256\276\351\251\261\345\212\250\344\275\277\347\224\250/04.WLAN.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/04.\345\244\226\350\256\276\351\251\261\345\212\250\344\275\277\347\224\250/04.WLAN.md" deleted file mode 100644 index e520026b34ee0ff4dcc5ab5cf97914bd18d1187a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/04.\345\244\226\350\256\276\351\251\261\345\212\250\344\275\277\347\224\250/04.WLAN.md" +++ /dev/null @@ -1,627 +0,0 @@ ---- -title: WLAN -permalink: /pages/0105020404 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:24 ---- -# WLAN - -- [概述](#section729758162218) - - [WLAN驱动接口架构](#section178022416377) - -- [接口说明](#section7331102018815) -- [开发步骤](#section15957746172412) -- [开发实例](#section1395253612512) - -## 概述 - -WLAN是基于HDF(Hardware Driver Foundation)驱动框架开发的模块,该模块可实现跨操作系统迁移,自适应器件差异,模块化拼装编译等功能。各WLAN厂商驱动开发人员可根据WLAN模块提供的向下统一接口适配各自的驱动代码,实现如下能力:建立/关闭WLAN热点、扫描、关联WLAN热点等;对HDI层向上提供能力如下:设置MAC地址、设置发射功率、获取设备的MAC地址等。[WLAN模块框架图](#fig4415112614415)如下: - -**图 1** WLAN框架 -![](/images/device-dev/driver/figures/WLAN框架.png "WLAN框架") - -### WLAN驱动接口架构 - -WLAN模块有三部分对外开放的API接口,如[下图2](#fig1492411431166)所示: - -1. 对HDI层提供的能力接口。 - -2. 驱动直接调用WLAN模块能力接口。 - -3. 提供给各厂商实现的能力接口。 - -**图 2** WLAN模块开放能力分布图 -![](/images/device-dev/driver/figures/WLAN模块开放能力分布图.png "WLAN模块开放能力分布图") - -## 接口说明 - -WLAN驱动模块提供给驱动开发人员可直接调用的能力接口,主要功能有:创建/释放WifiModule、关联/取消关联、申请/释放NetBuf、lwip的pbuf和NetBuf的相互转换等。提供的部分接口说明如[表1](#table1521573319472)所示: - -**表 1** 可直接调用的接口 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

头文件

-

接口名称

-

功能描述

-

wifi_module.h

-

-

struct WifiModule *WifiModuleCreate(const struct HdfConfigWifiModuleConfig *config);

-

基于HDF开发WLAN驱动时,创建一个WifiModule。

-

void WifiModuleDelete(struct WifiModule *module);

-

基于HDF开发WLAN驱动时,删除并释放WifiModule所有数据。

-

int32_t DelFeature(struct WifiModule *module, uint16_t featureType);

-

基于HDF开发WLAN驱动时,从WifiModule删除一个功能组件。

-

int32_t AddFeature(struct WifiModule *module, uint16_t featureType, struct WifiFeature *featureData);

-

基于HDF开发WLAN驱动时,注册一个功能组件到WifiModule。

-

wifi_mac80211_ops.h

-

int32_t (*startAp)(NetDevice *netDev);

-

启动AP。

-

int32_t (*stopAp)(NetDevice *netDev);

-

停止AP。

-

int32_t (*connect)(NetDevice *netDev, WifiConnectParams *param);

-

开始关联。

-

int32_t (*disconnect)(NetDevice *netDev, uint16_t reasonCode);

-

取消关联。

-

hdf_netbuf.h

-

static inline void NetBufQueueInit(struct NetBufQueue *q);

-

初始化NetBuf队列。

-

struct NetBuf *NetBufAlloc(uint32_t size);

-

申请NetBuf。

-

void NetBufFree(struct NetBuf *nb);

-

释放NetBuf。

-

struct NetBuf *Pbuf2NetBuf(const struct NetDevice *netdev, struct pbuf *lwipBuf);

-

lwip的pbuf转换为NetBuf。

-

struct pbuf *NetBuf2Pbuf(const struct NetBuf *nb);

-

NetBuf转换为lwip的pbuf。

-
- -同时WLAN驱动模块也提供了需要驱动开发人员实现的能力接口,主要功能有:初始化/注销NetDevice、打开/关闭NetDevice、获取NetDevice的状态等。提供的部分接口说明如[表2](#table74613501475)所示: - -**表 2** 需要开发人员实现的接口 - - - - - - - - - - - - - - - - - - - - - - - - - - - -

头文件

-

接口名称

-

功能描述

-

net_device.h

-

int32_t (*init)(struct NetDevice *netDev);

-

初始化NetDevice。

-

struct NetDevStats *(*getStats)(struct NetDevice *netDev);

-

获取NetDevice的状态。

-

int32_t (*setMacAddr)(struct NetDevice *netDev, void *addr);

-

设置Mac地址。

-

void (*deInit)(struct NetDevice *netDev);

-

注销NetDevice。

-

int32_t (*open)(struct NetDevice *netDev);

-

打开NetDevice。

-

int32_t (*stop)(struct NetDevice *netDev);

-

关闭NetDevice。

-
- -WLAN驱动模块对HDI层提供的能力接口,主要功能有:创建/销毁 IWiFi对象、设置MAC地址等。提供的部分接口说明如[表3](#table141076311618)所示: - -**表 3** HAL层对外接口 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

头文件

-

接口名称

-

功能描述

-

wifi_hal.h

-

-

int32_t WifiConstruct(struct IWiFi **wifiInstance);

-

创建IWiFi对象,提供IWiFi基本能力。

-

int32_t WifiDestruct(struct IWiFi **wifiInstance);

-

销毁IWiFi对象。

-

int32_t (*start)(struct IWiFi *);

-

创建HAL和驱动之间的通道及获取驱动支持的网卡信息。

-

int32_t (*stop)(struct IWiFi *);

-

销毁通道。

-

wifi_hal_base_feature.h

-

int32_t (*getFeatureType)(const struct IWiFiBaseFeature *);

-

获取特性的类型。

-

int32_t (*setMacAddress)(const struct IWiFiBaseFeature *, unsigned char *, uint8_t);

-

设置MAC地址。

-

int32_t (*getDeviceMacAddress)(const struct IWiFiBaseFeature *, unsigned char *, uint8_t);

-

获取设备持久化的MAC地址。

-

int32_t (*setTxPower)(const struct IWiFiBaseFeature *, int32_t);

-

设置发射功率。

-
- -## 开发步骤 - -WLAN驱动基于HDF框架和PLATFORM框架开发,不区分OS和芯片平台,为不同厂商的WLAN模组提供统一的驱动模型,各WLAN模组厂商根据如下指导适配WLAN驱动框架。 - -1. 通过wifi\_config.hcs文件,配置硬件参数:module\(不同feature\),芯片等。 -2. 解析配置文件, 生成全量配置的结构体对象。 -3. Module初始化,创建Module。 -4. 挂接chip,初始化chip。 -5. 总线初始化。 -6. 上层wpa业务挂接。 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->以上驱动框架适配步骤一部分已经提供(详细见开发实例),待开发人员实现的部分有:1、根据硬件,修改配置参数;2、适配挂接chip;3、测试自验证。 - -## 开发实例 - -本例程提供WLAN模块初始化过程的完整使用流程。示例如下(以hi3881WLAN芯片为例): - -1、根据硬件,修改配置参数。 - -``` -/* 根据硬件参数,通过wlan_platform.hcs配置相关参数,以下是WLAN平台配置的示例 */ -hisi :& deviceList { - device0 :: deviceInst { - deviceInstId = 0; - powers { - power0 { - powerSeqDelay = 0; /* 电源序列延时 */ - powerType = 1; /* 电源类型:0--总是打开;1--GPIO */ - gpioId = 1; /* GPIO管脚号 */ - activeLevel=1; /* 有效电平:0--低;1--高 */ - } - power1 { - powerSeqDelay = 0; /* 电源序列延时 */ - powerType = 0; /* 电源类型:0--总是打开;1--GPIO */ - } - } - reset { - resetType = 0; /* 复位类型:0--不管理;1--GPIO */ - gpioId = 2; /* GPIO管脚号 */ - activeLevel=1; /* 有效电平:0--低;1--高 */ - resetHoldTime = 30; /* 复位配置后的等待时间(ms) */ - } - bootUpTimeout = 30; /* 启动超时时间(ms) */ - bus { - busType = 0; /* 总线类型:0-sdio */ - busId = 2; /* 总线号 */ - funcNum = [1]; /* SDIO功能号 */ - timeout = 1000; /* 读/写数据的超时时间 */ - blockSize = 512; /* 读/写数据的块大小 */ - } - } -} -/* 每一块芯片添加配置文件wlan_chip_<芯片名>.hcs(如:wlan_chip_hi3881.hcs),配置相关参数。以下是hi3881的配置示例 */ -root { - wlan_config { - hi3881 :& chipList { - chipHi3881 :: chipInst { - match_attr = "hdf_wlan_chips_hi3881"; /* 配置匹配标识 */ - chipName = "hi3881"; /* WLAN芯片的名称 */ - sdio { - vendorId = 0x0296; /* 厂商Id */ - deviceId = [0x5347]; /* 设备Id */ - } - } - } - } -} -``` - -2、适配挂接WLAN芯片的初始化和去初始化、WLAN芯片驱动的初始化和去初始化 - -``` -/* WLAN初始化挂接流程 */ -#include "hdf_device_desc.h" -#include "hdf_wifi_product.h" -#include "hdf_log.h" -#include "osal_mem.h" -#include "hdf_wlan_chipdriver_manager.h" -#include "securec.h" -#include "wifi_module.h" -#include "hi_wifi_api.h" -#include "hi_types_base.h" - -#define HDF_LOG_TAG Hi3881Driver - -/* WLAN芯片的初始化和去初始化函数 */ -int32_t InitHi3881Chip(struct HdfWlanDevice *device); -int32_t DeinitHi3881Chip(struct HdfWlanDevice *device); -/* WLAN芯片驱动的初始化和去初始化函数 */ -int32_t Hi3881Deinit(struct HdfChipDriver* chipDriver, struct NetDevice *netDevice); -int32_t Hi3881Init(struct HdfChipDriver* chipDriver, struct NetDevice *netDevice); - -/* 初始化mac80211与芯片侧的函数挂接 */ -hi_void HiMac80211Init(struct HdfChipDriver *chipDriver); - -static const char* const HI3881_DRIVER_NAME = "hisi"; - -/* WLAN芯片驱动挂接以及mac80211与芯片侧的函数挂接 */ -static struct HdfChipDriver *BuildHi3881Driver(struct HdfWlanDevice *device, uint8_t ifIndex) -{ - struct HdfChipDriver *specificDriver = NULL; - if (device == NULL) { - HDF_LOGE("%s fail : channel is NULL", __func__); - return NULL; - } - (void)device; - (void)ifIndex; - specificDriver = (struct HdfChipDriver *)OsalMemCalloc(sizeof(struct HdfChipDriver)); - if (specificDriver == NULL) { - HDF_LOGE("%s fail: OsalMemCalloc fail!", __func__); - return NULL; - } - if (memset_s(specificDriver, sizeof(struct HdfChipDriver), 0, sizeof(struct HdfChipDriver)) != EOK) { - HDF_LOGE("%s fail: memset_s fail!", __func__); - OsalMemFree(specificDriver); - return NULL; - } - - if (strcpy_s(specificDriver->name, MAX_WIFI_COMPONENT_NAME_LEN, HI3881_DRIVER_NAME) != EOK) { - HDF_LOGE("%s fail : strcpy_s fail", __func__); - OsalMemFree(specificDriver); - return NULL; - } - specificDriver->init = Hi3881Init; - specificDriver->deinit = Hi3881Deinit; - - HiMac80211Init(specificDriver); - - return specificDriver; -} - -/* 释放WLAN芯片驱动 */ -static void ReleaseHi3881Driver(struct HdfChipDriver *chipDriver) -{ - if (chipDriver == NULL) { - return; - } - if (strcmp(chipDriver->name, HI3881_DRIVER_NAME) != 0) { - HDF_LOGE("%s:Not my driver!", __func__); - return; - } - OsalMemFree(chipDriver); -} - -static uint8_t GetHi3881GetMaxIFCount(struct HdfChipDriverFactory *factory) { - (void)factory; - return 1; -} - -/* WLAN芯片相关函数的注册 */ -static int32_t HDFWlanRegHisiDriverFactory(void) -{ - static struct HdfChipDriverFactory tmpFactory = { 0 }; - struct HdfChipDriverManager *driverMgr = NULL; - driverMgr = HdfWlanGetChipDriverMgr(); - if (driverMgr == NULL && driverMgr->RegChipDriver != NULL) { - HDF_LOGE("%s fail: driverMgr is NULL!", __func__); - return HDF_FAILURE; - } - tmpFactory.driverName = HI3881_DRIVER_NAME; - tmpFactory.GetMaxIFCount = GetHi3881GetMaxIFCount; - tmpFactory.InitChip = InitHi3881Chip; - tmpFactory.DeinitChip = DeinitHi3881Chip; - tmpFactory.Build = BuildHi3881Driver; - tmpFactory.Release = ReleaseHi3881Driver; - tmpFactory.ReleaseFactory = NULL; - if (driverMgr->RegChipDriver(&tmpFactory) != HDF_SUCCESS) { - HDF_LOGE("%s fail: driverMgr is NULL!", __func__); - return HDF_FAILURE; - } - - return HDF_SUCCESS; -} - -static int32_t HdfWlanHisiChipDriverInit(struct HdfDeviceObject *device) -{ - (void)device; - return HDFWlanRegHisiDriverFactory(); -} - -struct HdfDriverEntry g_hdfHisiChipEntry = { - .moduleVersion = 1, - .Init = HdfWlanHisiChipDriverInit, - .moduleName = "HDF_WLAN_CHIPS" -}; - -HDF_INIT(g_hdfHisiChipEntry); -``` - -``` -#include "hdf_wifi_product.h" -#include "hi_wifi_api.h" -#if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION) -#include "oal_thread.h" -#include "osal_time.h" -#endif -#include "wifi_mac80211_ops.h" -#include "wal_cfg80211.h" -#include "net_adpater.h" -#include "hdf_wlan_utils.h" - -#define HDF_LOG_TAG Hi3881Driver - -/* WLAN芯片的初始化函数 */ -int32_t InitHi3881Chip(struct HdfWlanDevice *device) -{ - uint8_t maxPortCount = 1; - int32_t ret = HI_SUCCESS; - uint8_t maxRetryCount = 2; - if (device == NULL) { - HDF_LOGE("%s:NULL ptr!", __func__); - return HI_FAIL; - } - - do { - if (ret != HI_SUCCESS) { - if (device->reset != NULL && device->reset->Reset != NULL) { - device->reset->Reset(device->reset); - } - HDF_LOGE("%s:Retry init hi3881!last ret=%d", __func__, ret); - } - ret = hi_wifi_init(maxPortCount); - } while (ret != 0 && --maxRetryCount > 0); - - if (ret != 0) { - HDF_LOGE("%s:Init hi3881 driver failed!", __func__); - return ret; - } - return HI_SUCCESS; -} - -/* WLAN芯片的去初始化函数 */ -int32_t DeinitHi3881Chip(struct HdfWlanDevice *device) -{ - (void)device; - int32_t ret = hi_wifi_deinit(); - if (ret != 0) { - HDF_LOGE("%s:Deinit failed!ret=%d", __func__, ret); - } - return ret; -} - -/* WLAN芯片驱动的初始化函数 */ -int32_t Hi3881Init(struct HdfChipDriver *chipDriver, struct NetDevice *netDevice) -{ - HDF_LOGI("%s: start...", __func__); - hi_u16 mode = wal_get_vap_mode(); - int32_t ret; - nl80211_iftype_uint8 type; - (void)chipDriver; - - if (mode >= WAL_WIFI_MODE_BUTT) { - oam_error_log1(0, 0, "wal_init_drv_netdev:: invalid mode[%d]", mode); - return HI_FAIL; - } - - if (mode == WAL_WIFI_MODE_STA) { - type = NL80211_IFTYPE_STATION; - } else if (mode == WAL_WIFI_MODE_AP) { - type = NL80211_IFTYPE_AP; - } else { - oam_error_log1(0, 0, "wal_init_drv_netdev:: invalid mode[%d]", mode); - return HI_FAIL; - } - - ret = wal_init_drv_wlan_netdev(type, WAL_PHY_MODE_11N, netDevice); - if (ret != HI_SUCCESS) { - oam_error_log2(0, OAM_SF_ANY, "wal_init_drv_netdev %s failed.l_return:%d\n", netDevice->name, ret); - } - return ret; -} - -/* WLAN芯片驱动的去初始化函数 */ -int32_t Hi3881Deinit(struct HdfChipDriver *chipDriver, struct NetDevice *netDevice) -{ - (void)chipDriver; - int32_t ret = wal_deinit_drv_wlan_netdev(netDevice); - if (ret != HDF_SUCCESS) { - return ret; - } - return ReleasePlatformNetDevice(netDevice); -} -``` - -3、在芯片侧初始化过程中调用netdev的init和add接口进行初始化netdev,并挂接netdev的一些函数指针 - -``` -hi_s32 wal_init_drv_wlan_netdev(nl80211_iftype_uint8 type, wal_phy_mode mode, hi_char* ifname, hi_u32* len) -{ - oal_net_device_stru *netdev = HI_NULL; - - ...... - /* 初始化网络设备,获取对应的实例。*/ - netdev = NetDeviceInit(ifname, *len, LITE_OS); - oal_wireless_dev *wdev = (oal_wireless_dev *)oal_mem_alloc(OAL_MEM_POOL_ID_LOCAL, sizeof(oal_wireless_dev)); - ret = wal_init_netif(type, netdev, wdev); - - ...... - - return HI_SUCCESS; -} -/* 挂接netdev的一些函数指针,详细挂接函数{@link NetDeviceInterFace} */ -oal_net_device_ops_stru g_wal_net_dev_ops = -{ - .getStats = wal_netdev_get_stats, - .open = wal_netdev_open, - .stop = wal_netdev_stop, - .xmit = hmac_bridge_vap_xmit, - .ioctl = wal_net_device_ioctl, - .changeMtu = oal_net_device_change_mtu, - .init = oal_net_device_init, - .deInit = oal_net_free_netdev, -#if (defined(_PRE_WLAN_FEATURE_FLOWCTL) || defined(_PRE_WLAN_FEATURE_OFFLOAD_FLOWCTL)) - .selectQueue = wal_netdev_select_queue, -#endif - .setMacAddr = wal_netdev_set_mac_addr, -#if (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION) - .netifNotify = HI_NULL, -#endif - .specialEtherTypeProcess = SpecialEtherTypeProcess, -}; - -hi_s32 wal_init_netif(nl80211_iftype_uint8 type, oal_net_device_stru *netdev, const oal_wireless_dev *wdev) -{ - /* 添加网络设备到协议栈 */ - hi_u32 ret = NetDeviceAdd(netdev, (Protocol80211IfType)type); - - ...... - - return HI_SUCCESS; -} -``` - -4、WifiMac80211Ops中的函数挂接实现。 - -``` -/* 挂接mac80211的一些函数指针 */ - -/* 驱动需要实现的MAC层基本能力的控制接口 */ -static struct HdfMac80211BaseOps g_baseOps = { - .SetMode = WalSetMode, - .AddKey = WalAddKey, - .DelKey = WalDelKey, - .SetDefaultKey = WalSetDefaultKey, - .GetDeviceMacAddr = WalGetDeviceMacAddr, - .SetMacAddr = WalSetMacAddr, - .SetTxPower = WalSetTxPower, - .GetValidFreqsWithBand = WalGetValidFreqsWithBand, - .GetHwCapability = WalGetHwCapability -}; - -/* 驱动需要实现的MAC层STA能力的控制接口 */ -static struct HdfMac80211STAOps g_staOps = { - .Connect = WalConnect, - .Disconnect = WalDisconnect, - .StartScan = WalStartScan, - .AbortScan = WalAbortScan, - .SetScanningMacAddress = WalSetScanningMacAddress, -}; - -/* 驱动需要实现的MAC层AP能力的控制接口 */ -static struct HdfMac80211APOps g_apOps = { - .ConfigAp = WalConfigAp, - .StartAp = WalStartAp, - .StopAp = WalStopAp, - .ConfigBeacon = WalChangeBeacon, - .DelStation = WalDelStation, - .SetCountryCode = WalSetCountryCode, - .GetAssociatedStasCount = WalGetAssociatedStasCount, - .GetAssociatedStasInfo = WalGetAssociatedStasInfo -}; - -/* 初始化mac80211与芯片侧的函数挂接 */ -hi_void HiMac80211Init(struct HdfChipDriver *chipDriver) -{ - if (chipDriver == NULL) { - oam_error_log(0, OAM_SF_ANY, "%s:input is NULL!", __func__); - return; - } - chipDriver->ops = &g_baseOps; - chipDriver->staOps = &g_staOps; - chipDriver->apOps = &g_apOps; -} -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/04.\345\244\226\350\256\276\351\251\261\345\212\250\344\275\277\347\224\250/05.AUDIO.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/04.\345\244\226\350\256\276\351\251\261\345\212\250\344\275\277\347\224\250/05.AUDIO.md" deleted file mode 100644 index 37c51932a5f88bfb743d5996364ff691b5f18fe5..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/04.\345\244\226\350\256\276\351\251\261\345\212\250\344\275\277\347\224\250/05.AUDIO.md" +++ /dev/null @@ -1,1422 +0,0 @@ ---- -title: AUDIO -permalink: /pages/0105020405 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:24 ---- -# AUDIO - -- **[Audio驱动概述](#section1000)** - -- **[Audio驱动框架介绍](#section2000)** - -- **[Audio驱动开发](#section3000)** - - - **[Audio ADM模块框架介绍](#section3100)** - - [启动流程](#section3111) - - [播放流程](#section3112) - - [控制流程](#section3113) - - - **[Audio驱动开发步骤](#section3200)** - - [已有平台开发](#section3221) - - [新平台开发](#section3222) - -- **[Audio驱动开发实例](#section4000)** - - [Codec驱动开发实例](#section4100) - - [Codec数据结构填充](#section4111) - - [codecDevice和codecDai设备初始化](#section4112) - - [Codec操作函数集实现](#section4113) - - [Codec注册绑定到HDF](#section4114) - - [HCS配置流程](#section4115) - - [Accessory驱动开发实例](#section4200) - - [Accessory数据结构填充](#section4221) - - [accessoryDevice和accessoryDai设备初始化](#section4222) - - [Accessory操作函数集实现](#section4223) - - [Accessory注册绑定到HDF](#section4224) - - [HCS配置流程](#section4225) - - [Platform驱动开发实例](#section4300) - - [Platform数据结构填充](#section4331) - - [dmaDevice设备初始化](#section4332) - - [DMA操作函数集实现](#section4333) - - [Platform注册绑定到HDF](#section4334) - - [HCS配置流程](#section4335) - - [Dai驱动开发实例](#section4400) - - [Dai数据结构填充](#section4441) - - [daiDevice设备初始化](#section4442) - - [Dai操作函数集实现](#section4443) - - [Dai注册绑定到HDF](#section4444) - - [HCS配置流程](#section4445) - - [Makefile中添加编译配置](#section4500) - - [源码结构与目录](#section4600) - -- **[使用HAL的开发步骤与实例](#section5000)** - - [HAL模块使用步骤](#section5100) - - [HAL使用实例](#section5200) - -- **[总结](#section9999)** - -# Audio驱动概述 - -多媒体系统是物联网设备开发中不可缺少的一部分,Audio作为其中重要的一个模块,Audio驱动模型的构建显得尤为重要。 - -本文主要介绍基于HDF(Hardware Driver Foundation)驱动框架开发的Audio驱动,包括Audio驱动的架构组成和功能部件。芯片厂商可以根据此驱动架构,进行各自驱动的开发及HAL层接口的调用。 - - - -# Audio驱动框架介绍 - -Audio驱动框架基于[HDF驱动框架](https://device.harmonyos.com/cn/docs/documentation/guide/driver-hdf-overview-0000001051715456)实现。Audio驱动架构组成: -![](/images/device-dev/driver/figures/Audio框架图.png) - -驱动架构主要由以下几部分组成。 -- HDI adapter : 实现Audio HAL层驱动(HDI接口适配),给Audio服务(frameworks)提供所需的音频硬件驱动能力接口。包含 Audio Manager、Audio Adapter、 Audio Control、Audio Capture、Audio Render 等接口对象。 -- Audio Interface Lib : 配合内核中的Audio Driver Model使用,实现音频硬件的控制、录音数据的读取、播放数据的写入。它里面包括Stream_ctrl_common 通用层,主要是为了和上层的audio HDI adapter 层进行对接。 -- ADM(Audio Driver Model): 音频驱动框架模型,向上服务于多媒体音频子系统,便于系统开发者能够更便捷的根据场景来开发应用。向下服务于具体的设备厂商,对于Codec和DSP设备厂商来说,可根据ADM模块提供的向下统一接口适配各自的驱动代码,就可以实现快速开发和适配OpenHarmony系统。 -- Audio Control Dispatch : 接收lib层的控制指令并将控制指令分发到驱动层。 -- Audio Stream Dispatch : 接收lib层的数据并将数据分发到驱动层。 - -- Card Manager : 多声卡管理模块。每个声卡含有Dai、Platform、Codec、Accessory、Dsp、Sapm模块。 -- Platform Driver : 驱动适配层。 -- SAPM(Smart Audio Power Manager) : 电源管理模块,对整个ADM电源进行功耗策略优化。 - -# Audio驱动开发 - -以下将基于Audio驱动框架,并以Hi3516DV300平台为例,介绍相关驱动开发的具体步骤。 - -## Audio ADM模块框架介绍 -Audio驱动对HDI层提供三个服务hdf_audio_render、hdf_audio_capture、hdf_audio_control。开发板dev目录下 驱动服务节点如下: - -```c -# ls -l hdf_audio* -crw-rw---- 1 system system 248, 6 1970-01-01 00:00 hdf_audio_capture //音频数据录音流服务。 -crw-rw---- 1 system system 248, 4 1970-01-01 00:00 hdf_audio_codec_dev0 //音频声卡设备0名称。 -crw-rw---- 1 system system 248, 4 1970-01-01 00:00 hdf_audio_codec_dev1 //音频声卡设备1名称。 -crw-rw---- 1 system system 248, 5 1970-01-01 00:00 hdf_audio_control //音频控制流服务。 -crw-rw---- 1 system system 248, 7 1970-01-01 00:00 hdf_audio_render //音频数据播放流务。 -``` - -音频声卡设备包括的驱动服务: - -hdf_audio_codec_dev0 -- dma_service_0 : dma 服务 -- dai_service : cpu dai 服务 -- codec_service_0 : codec 服务(特指内置codec) -- dsp_service_0 : dsp 服务(可选项) - -hdf_audio_codec_dev1 -- dma_service_0 : dma 服务 -- dai_service : cpu dai 服务 -- codec_service_1 : accessory 服务(特指smartPA) -- dsp_service_0 : dsp 服务(可选项) - -### 启动流程 - -![](/images/device-dev/driver/figures/ADM启动流程图.png) - -1. 系统启动时audio模块的Platform、Codec、Accessory、Dsp、Dai各个驱动首先被加载,各驱动从各自私有配置文件中获取配置信息,并将获取的配置信息保存到各驱动的Data数据结构中。 - -2. 各驱动模块调用ADM注册接口将自己添加到各驱动模块的链表中。 - -3. ADM模块读取hdf_audio_driver_0和hdf_audio_driver_1配置信息,加载各模块的具体设备。 - -4. ADM模块调用各模块的初始化函数对各模块设备进行初始化。 - -5. 将初始化成功的音频设备添加到cardManager链表。 - -### 播放流程 -![=](/images/device-dev/driver/figures/ADM播放流程图.png) -1. 播放音频时,Interface Lib层通过播放流服务下发Render Open指令,Audio Stream Dispatch服务收到指令后分别调用各模块的函数接口对指令进行下发。 - -2. Interface Lib层通过控制服务下发通路选择指令,Control Dispatch控制服务收到指令后调用Dai模块接口设置通路。 - -3. Interface Lib层通过播放流服务下发硬件参数,Audio Stream Dispatch服务收到参数后分别调用各模块参数设置接口,对硬件参数进行设置。 - -4. Interface Lib层通过播放流服务下发播放启动指令,Audio Stream Dispatch服务收到指令后分别调用各模块启动接口,对各模块进行启动设置。 - -5. Interface Lib层通过播放流服务下发音频数据,Audio Stream Dispatch服务收到数据后调用Platform AudioPcmWrite接口将音频数据传给Dma。 - -6. Interface Lib层通过播放流服务下发播放停止指令,Audio Stream Dispatch服务收到指令后分别调用各模块停止接口,对各模块进行停止设置。 - -7. Interface Lib层通过播放流服务下发Render Close指令,Audio Stream Dispatch服务收到指令后调用Platform AudioRenderClose对已申请资源进行释放。 - -### 控制流程 - -![](/images/device-dev/driver/figures/ADM控制流程图.png) - -1. 设置音量,首先Interface Lib层通过控制服务下发获取音量范围指令,Control Dispatch控制服务收到指令后进行解析,并调用Codec模块Get函数,获取可设置音量的范围。 -2. Interface Lib层通过控制服务下发设置音量指令,Control Dispatch控制服务收到指令后进行解析,并调用Codec模块Set函数设置音量。 - -## Audio驱动开发步骤 - -### 已有平台开发 - -ADM适配已有平台(Hi3516DV300)Codec或Accessory(Smart PA)的驱动开发流程: - -![](/images/device-dev/driver/figures/开发流程图1.png) - -- 根据芯片说明将相关寄存器信息配置到Codec或Smart PA的私有HCS中。 - -- 如果新添加Codec或Smart PA和已适配Codec或Smart PA的工作流程相同则不需要实现Codec或Smart PA的操作函数集和配置编译文件。 - - -- 进行编译调试验证。 - -### 新平台开发 - -ADM适配新平台Audio驱动开发流程: - -![](/images/device-dev/driver/figures/开发流程图2.png) - -Audio驱动需要将Audio相关的Codec(可选)、Dai、DMA、DSP(可选)、Smart PA(可选)驱动进行适配。 - -- 根据芯片说明将各模块驱动的寄存器信息配置到各模块的私有配置文件中。 - -- 实现各模块的操作函数集。 - -- 修改配置Audio模块编译文件。 - -- 进行编译调试验证。 - - - -# Audio驱动开发实例 - -代码路径:drivers/peripheral/audio - -下面以Hi3516DV300为例,介绍audio的codec驱动、accessory驱动、dai驱动、platform驱动开发步骤。 - -## Codec驱动开发实例 -代码路径:drivers/peripheral/audio/chipsets/hi3516dv300/codec - -codec驱动开发主要包含如下几个重要步骤: -1. 定义填充一个具体的codec -2. 实现codec回调函数 -3. 注册绑定到HDF框架 -4. 配置HCS和Makefile - -### Codec数据结构填充 - -Codec模块需要填充如下3个结构体: - -- g_codecData:codec设备的操作函数集和私有数据集。 - -- g_codecDaiDeviceOps:codecDai的操作函数集,包括启动传输和参数配置等函数接口。 - -- g_codecDaiData:codec的数字音频接口的操作函数集和私有数据集。 - -```c -struct CodecData g_codecData = { - .Init = CodecDeviceInit, // codec设备初始化(适配新平台需重新实现) - .Read = AudioDeviceReadReg, // 读寄存器(现有框架已实现,无需适配) - .Write = AudioDeviceWriteReg, // 写寄存器(现有框架已实现,无需适配) -}; - -struct AudioDaiOps g_codecDaiDeviceOps = { - .Startup = CodecDaiStartup, // 启动传输(适配新平台需重新实现) - .HwParams = CodecDaiHwParams, // 参数配置(适配新平台需重新实现) -}; - -struct DaiData g_codecDaiData = { - .DaiInit = CodecDaiDeviceInit, // codecdai设备初始化(适配新平台需重新实现) - .ops = &g_codecDaiDeviceOps, //codecdai操作函数 -}; -``` - -### codecDevice和codecDai设备初始化 - -CodecDeviceInit将完成AIAO的设置、寄存器默认值初始化、g_audioControls插入到controls链、电源管理初始化、通路选择设置等。 - -```c -int32_t CodecDeviceInit(struct AudioCard *audioCard, struct CodecDevice *codec) -{ - ... - /* hi3516平台AIAO的Set和Get 注册*/ - CodecSetCtlFunc(codec->devData, AudioCodecAiaoGetCtrlOps, AudioCodecAiaoSetCtrlOps) - ... - /* hi3516平台codec寄存器IoRemap*/ - CodecHalSysInit(); - ... - /* hi3516平台codec寄存器默认值初始化*/ - CodecRegDefaultInit(codec->devData->regCfgGroup); - ... - /* hi3516平台g_audioControls 挂到Control链表上*/ - AudioAddControls(audioCard, codec->devData->controls, codec->devData->numControls); - ... - /* hi3516平台codec加载到sapm*/ - AudioSapmNewComponents(audioCard, codec->devData->sapmComponents, codec->devData->numSapmComponent); - ... - /* hi3516平台codec加挂到通路选择链表上*/ - AudioSapmAddRoutes(audioCard, g_audioRoutes, HDF_ARRAY_SIZE(g_audioRoutes); - ... - AudioSapmNewControls(audioCard); - ... - /* hi3516平台codec电源管理*/ - AudioSapmSleep(audioCard); - ... - return HDF_SUCCESS; -} -``` - -CodecDaiDeviceInit将完成codecDai侧初始化,hi3516此处未涉及,接口保留: - -```c -int32_t CodecDaiDeviceInit(struct AudioCard *card, const struct DaiDevice *device) - -{ - ... - AUDIO_DRIVER_LOG_DEBUG("codec dai device name: %s\n", device->devDaiName); - (void)card; - return HDF_SUCCESS; -} -``` - -### Codec操作函数集实现 - -codec模块当前封装了OSAL读写寄存器的Read、Write函数。 - -如新增平台无法使用OSAL的Read、Write函数来操作寄存器,则此Read、Write函数接口需自行实现。 - -```c -int32_t AudioDeviceReadReg(unsigned long virtualAddress, uint32_t reg, uint32_t *val) -{ - ... - *val = OSAL_READL((void *)((uintptr_t)(virtualAddress + reg))); - return HDF_SUCCESS; -} - -int32_t AudioDeviceWriteReg(unsigned long virtualAddress, uint32_t reg, uint32_t value) -{ - OSAL_WRITEL(value, (void *)((uintptr_t)(virtualAddress + reg))); - return HDF_SUCCESS; -} -``` - -CodecDaiStartup为启动时的一些设置。 - -```c -int32_t CodecDaiStartup(const struct AudioCard *card, const struct DaiDevice *device) -{ - int32_t ret; - ... - (void)card; - ret = CodecSetAdcTuneEnable(device->devData->regCfgGroup); - ... - return HDF_SUCCESS; -} -``` - -CodecDaiHwParams为参数配置,包括采样率、位宽等。 - -```c -int32_t CodecDaiHwParams(const struct AudioCard *card, const struct AudioPcmHwParams *param) -{ - unsigned int bitWidth; - struct CodecDaiParamsVal codecDaiParamsVal; - ... - int ret = AudioFramatToBitWidth(param->format, &bitWidth); - ... - codecDaiParamsVal.frequencyVal = param->rate; - codecDaiParamsVal.formatVal = bitWidth; - ret = CodecDaiParamsUpdate(card->rtd->codecDai->devData->regCfgGroup, codecDaiParamsVal); - ... - return HDF_SUCCESS; -} -``` - -### Codec注册绑定到HDF - -此处依赖HDF框架的驱动实现方式,具体流程可参考[HDF驱动框架](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/driver/driver-hdf.md)指导。 - -填充g_codecDriverEntry结构体,moduleName与device_info.hcs中的moduleName匹配,实现Bind、Init、Release函数指针。 - -drivers/peripheral/audio/chipsets/hi3516dv300/codec/src/hi3516_codec_adapter.c - -```c -struct HdfDriverEntry g_codecDriverEntry = { - .moduleVersion = 1, - .moduleName = "CODEC_HI3516", - .Bind = CodecDriverBind, - .Init = CodecDriverInit, - .Release = CodecDriverRelease, -}; -HDF_INIT(g_codecDriverEntry); -``` - -CodecDriverBind:将HDF中device绑定到codec,将codec service注册到HDF框架。 - -```c -static int32_t CodecDriverBind(struct HdfDeviceObject *device) -{ - struct CodecHost *codecHost = (struct CodecHost *)OsalMemCalloc(sizeof(*codecHost)); - ... - codecHost->device = device; - device->service = &codecHost->service; - return HDF_SUCCESS; -} -``` - -CodecDriverInit:获取codecServive名字和私有寄存器配置,并通过AudioRegisterCodec插入到链表中。 - -```c -static int32_t CodecDriverInit(struct HdfDeviceObject *device) -{ - ... - CodecGetConfigInfo(device, &g_codecData); - CodecSetConfigInfo(&g_codecData, &g_codecDaiData); - CodecGetServiceName(device, &g_codecData.drvCodecName); - CodecGetDaiName(device, &g_codecDaiData.drvDaiName); - AudioRegisterCodec(device, &g_codecData, &g_codecDaiData); - ... - return HDF_SUCCESS; -} -``` - -CodecDriverRelease:释放驱动资源。 - -```c -static void CodecDriverRelease(struct HdfDeviceObject *device) -{ - codecHost = (struct CodecHost *)device->service; - OsalMemFree(codecHost); -} -``` - -### HCS配置流程 - -hcs中配置驱动节点、加载顺序、服务名称等。hcs语法可参考HDF框架的[配置管理](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/driver/driver-hdf-manage.md)。 - -标准系统配置文件路径: - -vendor/hisilicon/Hi3516DV300/hdf_config/khdf/ - -小型系统配置文件路径: - -vendor/hisilicon/hispark_taurus/hdf_config/ - -**device_info.hcs中配置Codec设备信息** - -添加Codec节点配置。修改如下配置中的moduleName,该名字会与HdfDriverEntry结构体中moduleName进行匹配,一般情况需体现出硬件平台名称。例:moduleName = "CODEC_HI3516"。 - -代码片段如下: - -```c - audio :: host { - device_codec :: device { - device0 :: deviceNode { - policy = 1; // codec模块只对内核提供服务 - priority = 50; // codec模块需在HDF_AUDIO模块之前加载 - preload = 0; - permission = 0666; - moduleName = "CODEC_HI3516"; // 名字会与HdfDriverEntry结构体中moduleName进行匹配 - serviceName = "codec_service_0"; // 对外提供的服务名称 - deviceMatchAttr = "hdf_codec_driver"; //私有配置属性名称,通过此名称匹配对应的私有数据(包含寄存器配置) - } - } -``` - -**audio_config.hcs中配置私有依赖** - -配置audio_card设备依赖的codec、platform、dai、dsp、accessory之间的依赖关系。 - -代码片段如下: - -```c -root { - platfrom { - ... - controller_0x120c1001 :: card_controller { - //配置私有数据属性名称,与device_info.hcs中的deviceMatchAttr对应 - match_attr = "hdf_audio_driver_1"; - serviceName = "hdf_audio_smartpa_dev0"; //对外提供的服务名称 - accessoryName = "codec_service_1"; //外置codec服务名称 - platformName = "dma_service_0"; //dma服务 - cpuDaiName = "dai_service"; //cpu dai 服务 - accessoryDaiName = "accessory_dai"; //外置dai - dspName = "dsp_service_0"; //dsp服务名称 - dspDaiName = "dsp_dai"; //dsp dai - } - } -} -``` - -**codec_config.hcs中配置私有寄存器** - -与配置在device_info.hcs中codec的deviceMatchAttr匹配,目前配置中包含寄存器配置。 - -绑定控制功能配置主要是将控制功能及其寄存器参数按统一的结构规范,配置在HCS文件中并获取与解析后增加到控制链表中。 - -- regConfig:寄存器与控制功能配置组名称。 - -- ctrlParamsSeqConfig:控制功能寄存器配置组名称。 - -- daiStartupSeqConfig:Dai启动配置配置组名称。 - -- daiParamsSeqConfig:播放参数配置组名称。 - -- resetSeqConfig:重置过程寄存器配置组名称。 - -- initSeqConfig:初始化过程寄存器配置组名称。 - -- controlsConfig:控制功能配置组,其中array index(具体业务场景)和 iface(与HAL保持一致)为固定的值。 - -``` -array index -0:Main Playback Volume -1:Main Capture Volume -2:Playback Mute -3:Capture Mute -4:Mic Left Gain -5:Mic Right Gain -6:External Codec Enable -7:Internally Codec Enable -8:Render Channel Mode -9:Capture Channel Mode -iface -0:virtual dac device -1:virtual adc device -2:virtual adc device -3:virtual mixer device -4:Codec device -5:PGA device -6:AIAO device -``` - -ctrlParamsSeqConfig:控制功能寄存器配置组,其中item与controlsConfig组中的item位置顺序一一对应,表示某一功能对应的寄存器配置。 - -```c - root { - platfrom { - template codec_controller { - match_attr = ""; - serviceName = ""; - codecDaiName = ""; - } - controller_0x120c1030 :: codec_controller { - match_attr = "hdf_codec_driver"; - serviceName = "codec_service_0"; - codecDaiName = "codec_dai"; - - /* 3516寄存器基地址 */ - idInfo { - chipName = "hi3516"; //codec名字 - chipIdRegister = 0x113c0000; //codec 基地址 - chipIdSize = 0x1000; //codec 地址偏移 - } - - /* 寄存器配置,包含各种寄存器配置信息 */ - regConfig { - /* reg: register address - rreg: register address - shift: shift bits - rshift: rshift bits - min: min value - max: max value - mask: mask of value - invert: enum InvertVal 0-uninvert 1-invert - value: value - */ - - /* reg, value */ - initSeqConfig = [ - 0x14, 0x04000002, - 0x18, 0xFD200004, - 0x1C, 0x00180018, - 0x20, 0x83830028, - 0x24, 0x00005C5C, - 0x28, 0x00130000, - 0x30, 0xFF035A00, - 0x34, 0x08000001, - 0x38, 0x06062424, - 0x3C, 0x1E1EC001, - 0x14, 0x04000002 - ]; - - /* control function config - array index, iface, enable*/ - controlsConfig = [ - 0, 0, 0, - 1, 1, 1, - 2, 0, 1, - 3, 1, 1, - 4, 2, 1, - 5, 2, 1, - 8, 6, 0, - 9, 6, 0, - ]; - /* control function register config - reg, rreg, shift, rshift, min, max, mask, invert, value */ - ctrlParamsSeqConfig = [ - 0x3c, 0x3c, 24, 24, 0x0, 0x57, 0x7F, 1, 0, //"Main Capture Volume" - 0x38, 0x38, 31, 31, 0x0, 0x1, 0x1, 0, 0, //"Playback Mute" - 0x3c, 0x3c, 31, 31, 0x0, 0x1, 0x1, 0, 0, //"Capture Mute" - 0x20, 0x20, 16, 16, 0x0, 0xF, 0x1F, 0, 0, //"Mic Left Gain" - 0x20, 0x20, 24, 24, 0x0, 0xF, 0x1F, 0, 0, //"Mic Right Gain" - 0x2000, 0x2000, 16, 16, 0x0, 0x7, 0x7, 0, 0, //"Render Channel Mode" - 0x1000, 0x1000, 16, 16, 0x0, 0x7, 0x7, 0, 0 //"Capture Channel Mode" - ]; - - /* 上层下发参数后,写入音频相关信息的寄存器 - reg, rreg, shift, rshift, min, max, mask, invert, value */ - daiParamsSeqConfig = [ - 0x30, 0x30, 13, 13, 0x0, 0x1F, 0x1F, 0, 0x0, // i2s_frequency - 0x1C, 0x1C, 6, 6, 0x0, 0x3, 0x3, 0, 0x0, // adc_mode_sel - 0x30, 0x30, 22, 22, 0x0, 0x3, 0x3, 0, 0x0, // i2s_datawith - ]; - - /* 电源管理功能寄存器配置 - reg, rreg, shift, rshift, min, max, mask, invert, value */ - ctrlSapmParamsSeqConfig = [ - 0x20, 0x20, 23, 23, 0x0, 0x1, 0x1, 0, 0, //LPGA MIC 0 -- connect MIC - 0x20, 0x20, 31, 31, 0x0, 0x1, 0x1, 0, 0, //RPGA MIC 0 -- connect MIC - 0x30, 0x30, 27, 27, 0x0, 0x1, 0x1, 0, 0, //dacl to dacr mixer - 0x30, 0x30, 26, 26, 0x0, 0x1, 0x1, 0, 0 //dacr to dacl mixer - ]; - - /* - 电源管理组件配置 - componentName: 功能名称,{"ADCL", "ADCR", "DACL", "DACR", "LPGA", "RPGA", "SPKL", "SPKR", "MIC"} 数组索引。 - sapmType,compNameIndex,reg, mask,shift,invert, kcontrolNews,kcontrolsNum - */ - sapmComponent = [ - 10, 0, 0x20, 0x1, 15, 1, 0, 0, //ADCL - 10, 1, 0x20, 0x1, 14, 1, 0, 0, //ADCR - 11, 2, 0x14, 0x1, 11, 1, 0, 0, //DACL - 11, 3, 0x14, 0x1, 12, 1, 0, 0, //DACR - 8, 4, 0x20, 0x1, 13, 1, 1, 1, //LPGA - 8, 5, 0x20, 0x1, 12, 1, 2, 1, //RPGA - 15, 6, 0, 0x1, 0, 0, 3, 1, //SPKL - 15, 7, 0, 0x1, 0, 0, 4, 1, //SPKR - 0, 8, 0, 0x1, 0, 0, 0, 0 //MIC - ]; - - /* 电源管理功能配置 - array index, iface, enable - */ - sapmConfig = [ - 0, 5, 1, - 1, 5, 1, - 2, 0, 1, - 3, 0, 1 - ]; - } - } - } -} -``` - -在C代码中读取HCS配置文件来寄存器配置。 - -```c -static int32_t CodecDriverInit(struct HdfDeviceObject *device) -{ - ... - CodecGetConfigInfo(device, &g_codecData) ; - CodecSetConfigInfo(&g_codecData, &g_codecDaiData); - ... - return HDF_SUCCESS; -} -``` - -Codec注册时入参device中已有controller_0x120c1030的节点信息,只需要解析其中的节点就可以获取配置信息。 - -```c -int32_t CodecGetConfigInfo(const struct HdfDeviceObject *device, struct CodecData *codecData) -{ - codecData->regConfig = (struct AudioRegCfgData *)OsalMemCalloc(sizeof(*(codecData->regConfig))); - CodecGetRegConfig(device, codecData->regConfig); - return HDF_SUCCESS; -} -``` - -配置信息获取,配置节点。 - -```c -int32_t CodecGetRegConfig(const struct HdfDeviceObject *device, struct AudioRegCfgData *configData) -{ - ... - drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); - ... - idNode = drsOps->GetChildNode(root, "idInfo"); - ParseAudioAttr(drsOps, idNode, &configData->audioIdInfo); - regCfgNode = drsOps->GetChildNode(root, "regConfig"); - ... - DEV_RES_NODE_FOR_EACH_ATTR(regCfgNode, regAttr) { - ... - return HDF_SUCCESS; -} -``` - -regConfig节点中子项的配置信息获取并使用。在框架进行配置文件解析后,可直接替换代码中的寄存器信息。 - -```c -int32_t CodecDeviceInit(struct AudioCard *audioCard, struct CodecDevice *codec) -{ -... - if (CodecRegDefaultInit(codec->devData->regCfgGroup) != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("CodecRegDefaultInit failed."); - return HDF_FAILURE; - } -... - return HDF_SUCCESS; -} -``` - - - -## Accessory驱动开发实例 -代码路径:drivers/peripheral/audio/chipsets/tfa9879/accessory - -SmartPA归属于Accessory驱动的一种,开发步骤类似于codec: -1. 定义填充一个具体的accessory -2. 实现accessory回调函数 -3. 注册绑定到HDF框架 -4. 配置HCS和Makefile。 - -### Accessory数据结构填充 - -Accessory模块需要填充如下3个结构体: - -- g_tfa9879Data :accessory设备操作函数集,其中包含HCS文件中的配置信息,且定义与映射了accessory设备的初始化、读写寄存器的方法函数。 - -- g_tfa9879DaiDeviceOps :accessory设备DAI的数据集,其中定义与映射了accessory设备DAI的操作集。 - -- g_tfa9879DaiData :accessory设备DAI的数据集,其中定义与映射了accessory设备的数据访问接口的驱动名、初始化和操作集。 - -```c -struct AccessoryData g_tfa9879Data = { - .Init = Tfa9879DeviceInit, - .Read = AccessoryDeviceRegRead, - .Write = AccessoryDeviceRegWrite, -}; - -struct AudioDaiOps g_tfa9879DaiDeviceOps = { - .Startup = Tfa9879DaiStartup, - .HwParams = Tfa9879DaiHwParams, -}; - -struct DaiData g_tfa9879DaiData = { - .drvDaiName = "accessory_dai", - .DaiInit = Tfa9879DaiDeviceInit, - .ops = &g_tfa9879DaiDeviceOps, -}; -``` - -### accessoryDevice和accessoryDai设备初始化 - -设备初始化入口函数为Tfa9879DeviceInit,其中主要包括设置SmartPA I2C设备地址,获取配置数据、初始化(含重置)设备寄存器和绑定控制功能配置到控制链表中,当前Demo实现中也包括了Hi3516DV300设备的相关寄存器初始化,如初始化GPIO引脚等。 - -```c -int32_t Tfa9879DeviceInit(struct AudioCard *audioCard, const struct AccessoryDevice *device) -{ - int32_t ret; - ... - g_accessoryTransferData.i2cDevAddr = TFA9879_I2C_DEV_ADDR; // 0x6D - // 获取配置数据 - ret = AccessoryDeviceCfgGet(device->devData, &g_accessoryTransferData); - ... - // 初始化GPIO引脚 - ret = Hi35xxGpioPinInit(); - ... - // 初始化设备寄存器 - ret = AccessoryDeviceCtrlRegInit(); - ... - // 绑定功能控制配置 - ret = AudioAddControls(audioCard, g_accessoryTransferData.accessoryControls, - g_accessoryTransferData.accessoryCfgCtrlCount); - ... -} -``` - -I2C读写寄存器公用函数:AccessoryI2cReadWrite - -```c -int32_t AccessoryI2cReadWrite(struct AudioAddrConfig *regAttr, uint16_t rwFlag) -{ - int32_t ret; - DevHandle i2cHandle; - int16_t transferMsgCount = 1; - uint8_t regs[I2C_REG_LEN]; - struct I2cMsg msgs[I2C_MSG_NUM]; - ... - i2cHandle = I2cOpen(I2C_BUS_NUM); - ... - if (rwFlag == I2C_FLAG_READ) { - transferMsgCount = I2C_MSG_NUM; - } - ret = AccessoryI2cMsgFill(regAttr, rwFlag, regs, msgs); - ... - ret = I2cTransfer(i2cHandle, msgs, transferMsgCount); - ... - AccessoryI2cRelease(msgs, transferMsgCount, i2cHandle); - return HDF_SUCCESS; -} -``` - -### Accessory操作函数集实现 - -AccessoryDeviceRegRead和AccessoryDeviceRegWrite 2个回调函数中,调用I2C读写寄存器公用函数AccessoryI2cReadWrite,读写控制寄存器的值。 - -```c -int32_t AccessoryDeviceRegRead(const struct AccessoryDevice *codec, uint32_t reg, uint32_t *val) -{ - int32_t ret; - struct AudioAddrConfig regAttr; - ... - (void)codec; - regAttr.addr = (uint8_t)reg; - regAttr.value = 0; - ret = AccessoryI2cReadWrite(®Attr, I2C_FLAG_READ); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("failed."); - return HDF_FAILURE; - } - *val = regAttr.value; - ... - return HDF_SUCCESS; -} - -int32_t AccessoryDeviceRegWrite(const struct AccessoryDevice *codec, uint32_t reg, uint32_t value) -{ - int32_t ret; - struct AudioAddrConfig regAttr; - (void)codec; - regAttr.addr = (uint8_t)reg; - regAttr.value = (uint16_t)value; - ret = AccessoryI2cReadWrite(®Attr, 0); - ... - return HDF_SUCCESS; -} -``` - -Tfa9879DaiStartup为启动时的一些设置,代码片段如下: - -```c -int32_t Tfa9879DaiStartup(const struct AudioCard *card, const struct DaiDevice *device) -{ - int ret; - (void)card; - (void)device; - // 设置SmartPA的工作状态 - ret = Tfa9879WorkStatusEnable(); - ... - return HDF_SUCCESS; -} - -``` - -Tfa9879DaiHwParams为下发播放参数接口函数,代码片段如下: - -```c -int32_t Tfa9879DaiHwParams(const struct AudioCard *card, const struct AudioPcmHwParams *param) -{ - int32_t ret; - uint16_t frequency, bitWidth; - struct DaiParamsVal daiParamsVal; - (void)card; - ... - // 匹配采样率 - ret = AcessoryDeviceFrequencyParse(param->rate, &frequency); - ... - // 匹配位宽 - ret = Tfa9879FormatParse(param->format, &bitWidth); - ... - daiParamsVal.frequencyVal = frequency; - daiParamsVal.formatVal = bitWidth; - daiParamsVal.channelVal = param->channels; // 匹配声道 - ret = AccessoryDaiParamsUpdate(daiParamsVal); - ... - return HDF_SUCCESS; -} -``` - -### Accessory注册绑定到HDF - -此处依赖HDF框架的驱动实现方式,具体流程可参考[HDF驱动框架](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/driver/driver-hdf.md)。 - -填充g_tfa9879DriverEntry结构体,moduleName与device_info.hcs中的moduleName匹配,实现Bind、Init、Release函数指针。 - -drivers/peripheral/audio/chipsets/tfa9879/accessory/src/tfa9879_accessory_adapter.c - -```c -static int32_t Tfa9879DriverBind(struct HdfDeviceObject *device) -{ - (void)device; - AUDIO_DRIVER_LOG_INFO("success!"); - return HDF_SUCCESS; -} - -static int32_t Tfa9879DriverInit(struct HdfDeviceObject *device) -{ - int32_t ret; - ... - // 获取HCS中的配置数据 - ret = AccessoryGetConfigInfo(device, &g_tfa9879Data); - ... - ret = ret = GetServiceName(device); - ... - ret = AudioRegisterAccessory(device, &g_tfa9879Data, &g_tfa9879DaiData); - .... - return HDF_SUCCESS; -} - -/* HdfDriverEntry definitions */ -struct HdfDriverEntry g_tfa9879DriverEntry = { - .moduleVersion = 1, - .moduleName = "CODEC_TFA9879", - .Bind = Tfa9879DriverBind, - .Init = Tfa9879DriverInit, - .Release = NULL, -}; -HDF_INIT(g_tfa9879DriverEntry); -``` - -### HCS配置流程 - -配置过程可参考Codec驱动开发实例[HCS配置流程](#section4115)章节。 - - - -## Platform驱动开发实例 -代码路径:drivers/peripheral/audio/chipsets/hi3516dv300/soc - -在Audio驱动开发中,platform为DMA驱动的适配。platform驱动开发主要包含如下几个重要步骤: -1. 定义填充一个具体的platform -2. 实现platform回调函数 -3. 注册绑定到HDF框架 -4. 配置HCS和Makefile - -### Platform数据结构填充 - -Platform模块需要填充如下2个结构体: - -- g_platformData :platform设备私有配置,其中包含platform设备的初始化和操作函数。 - -- g_dmaDeviceOps :Dma设备操作函数集,包含了DMA一些通用接口的封装。 - -```c -struct AudioDmaOps g_dmaDeviceOps = { - .DmaBufAlloc = Hi3516DmaBufAlloc, // dma内存申请函数接口 - .DmaBufFree = Hi3516DmaBufFree, // dma内存释放函数接口 - .DmaRequestChannel = Hi3516DmaRequestChannel, // dma申请通道函数接口 - .DmaConfigChannel = Hi3516DmaConfigChannel, // dma通道配置函数接口 - .DmaPrep = Hi3516DmaPrep, // dma准备函数接口 - .DmaSubmit = Hi3516DmaSubmit, // dma submit函数接口 - .DmaPending = Hi3516DmaPending, // dma pending函数接口 - .DmaPause = Hi3516DmaPause, // dma 暂停、停止函数接口 - .DmaResume = Hi3516DmaResume, // dma 恢复函数接口 - .DmaPointer = Hi3516DmaPointer, // dma获取当前播放或录音位置函数接口 -}; - -struct PlatformData g_platformData = { - .PlatformInit = AudioDmaDeviceInit, //dma设备初始化接口 - .ops = &g_dmaDeviceOps, -}; -``` - -### dmaDevice设备初始化 - -设备初始化入口函数为AudioDmaDeviceInit,其中主要包括设置3516平台特有的AIAO初始化等。 - -```c -int32_t AudioDmaDeviceInit(const struct AudioCard *card, const struct PlatformDevice *platformDevice) -{ -... - AiaoHalSysInit(); - /* PIN MUX */ - AiaoSysPinMux(); - /* CLK reset */ - AiaoClockReset(); - /* aiao init */ - AiaoDeviceInit(chnId); -... - return HDF_SUCCESS; -} -``` - -### DMA操作函数集实现 - -Dma设备操作函数集,包含了DMA通用接口的封装。如通用接口不能满足开发要求,可自行实现新的DMA回调函数。 - -```c -int32_t Hi3516DmaBufAlloc(struct PlatformData *data, const enum AudioStreamType streamType); -int32_t Hi3516DmaBufFree(struct PlatformData *data, const enum AudioStreamType streamType); -int32_t Hi3516DmaRequestChannel(const struct PlatformData *data); -int32_t Hi3516DmaConfigChannel(const struct PlatformData *data); -int32_t Hi3516DmaPrep(const struct PlatformData *data); -int32_t Hi3516DmaSubmit(const struct PlatformData *data); -int32_t Hi3516DmaPending(struct PlatformData *data); -int32_t Hi3516DmaPause(struct PlatformData *data); -int32_t Hi3516DmaResume(const struct PlatformData *data); -int32_t Hi3516DmaPointer(struct PlatformData *data, uint32_t *pointer); -``` - -### Platform注册绑定到HDF - -此处依赖HDF框架的驱动实现方式,具体流程可参考[HDF驱动框架](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/driver/driver-hdf.md)。 - -- 填充g_platformDriverEntry结构体 -- moduleName与device_info.hcs中的moduleName匹配 -- 实现Bind、Init、Release函数指针。 - -drivers/peripheral/audio/chipsets/hi3516dv300/soc/src/hi3516_dma_adapter.c - -```c -static int32_t Hi3516DmaDriverInit(struct HdfDeviceObject *device) -{ -... - OsalMutexInit(&g_platformData.renderBufInfo.buffMutex); - OsalMutexInit(&g_platformData.captureBufInfo.buffMutex); - g_platformData.platformInitFlag = false; - ret = AudioSocRegisterPlatform(device, &g_platformData); -... - return HDF_SUCCESS; -} - -static void Hi3516DmaDriverRelease(struct HdfDeviceObject *device) -{ - struct PlatformHost *platformHost = NULL; -... - platformHost = (struct PlatformHost *)device->service; -... - OsalMutexDestroy(&g_platformData.renderBufInfo.buffMutex); - OsalMutexDestroy(&g_platformData.captureBufInfo.buffMutex); - OsalMemFree(platformHost); -} - -/* HdfDriverEntry definitions */ -struct HdfDriverEntry g_platformDriverEntry = { - .moduleVersion = 1, - .moduleName = "DMA_HI3516", - .Bind = Hi3516DmaDriverBind, - .Init = Hi3516DmaDriverInit, - .Release = Hi3516DmaDriverRelease, -}; -HDF_INIT(g_platformDriverEntry); -``` - -### HCS配置流程 - -配置过程可参考Codec驱动开发实例[HCS配置流程](#section4115)章节。 - - - -## Dai驱动开发实例 -代码路径:drivers/peripheral/audio/chipsets/hi3516dv300/soc - -Dai驱动开发主要包含如下几个重要步骤: -1. 定义填充一个具体的dai -2. 实现dai回调函数 -3. 注册绑定到HDF框架 -4. 配置HCS和Makefile - -### Dai数据结构填充 - -Dai模块需要填充如下2个结构体: - -- g_daiData :dai设备私有配置,其中包含dai设备的初始化、读写寄存器、操作函数。 - -- g_daiDeviceOps :dai设备操作函数集,包含了dai的参数设置、触发、启动。 - -```c -struct AudioDaiOps g_daiDeviceOps = { - .HwParams = DaiHwParams, - .Trigger = DaiTrigger, - .Startup = DaiStartup, -}; - -struct DaiData g_daiData = { - .DaiInit = DaiDeviceInit, - .Read = AudioDeviceReadReg, - .Write = AudioDeviceWriteReg, - .ops = &g_daiDeviceOps, -}; -``` - -### daiDevice设备初始化 - -设备初始化入口函数为DaiDeviceInit,其中主要包括设置dai的配置信息初始化,添加到Controls等。 - -```c -int32_t DaiDeviceInit(struct AudioCard *audioCard, const struct DaiDevice *dai) -{ -... - struct DaiData *data = dai->devData; - struct AudioRegCfgData *regConfig = dai->devData->regConfig; -... - g_regCodecBase = OsalIoRemap(CODEC_REG_BASE, CODEC_MAX_REG_SIZE); -... - data->regVirtualAddr = (uintptr_t)g_regCodecBase; - DaiSetConfigInfo(data); - AudioAddControls(audioCard, data->controls, data->numControls); - I2c6PinInit(); -... - data->daiInitFlag = true; - return HDF_SUCCESS; -} -``` - -### Dai操作函数集实现 - -AudioDeviceReadReg和AudioDeviceWriteReg在3516平台均未使用,作为接口预留。 - -DaiHwParams中主要完成一些pcm流信息的设置。 - -```c -int32_t DaiHwParams(const struct AudioCard *card, const struct AudioPcmHwParams *param) -{ - uint32_t bitWidth; - struct DaiDevice *device = card->rtd->cpuDai; -... - DaiCheckSampleRate(param->rate); - struct DaiData *data = DaiDataFromCard(card); - data->pcmInfo.channels = param->channels; -... - AudioFramatToBitWidth(param->format, &bitWidth); -... - data->pcmInfo.bitWidth = bitWidth; - data->pcmInfo.rate = param->rate; - data->pcmInfo.streamType = param->streamType; - data->regVirtualAddr = (uintptr_t)g_regDaiBase; -... - DaiParamsUpdate(device); - data->regVirtualAddr = (uintptr_t)g_regCodecBase; - return HDF_SUCCESS; -} -``` - -DaiTrigger在3516平台也未使用,作为接口预留。 - -DaiStartup为dai的启动函数,主要包括更新初始化寄存器配置、配置I2S等。 - -```c -int32_t DaiStartup(const struct AudioCard *card, const struct DaiDevice *device) -{ - struct AudioMixerControl *regCfgItem = NULL; -... - regCfgItem = device->devData->regConfig->audioRegParams[AUDIO_DAI_STARTUP_PATAM_GROUP]->regCfgItem; - itemNum = device->devData->regConfig->audioRegParams[AUDIO_DAI_STARTUP_PATAM_GROUP]->itemNum; - - device->devData->regVirtualAddr = (uintptr_t)g_regDaiBase; - for (int i = 0; i < itemNum; i++) { - int ret = AudioUpdateDaiRegBits(device, ®CfgItem[i], regCfgItem[i].value); - if (ret != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("set frequency fail."); - return HDF_FAILURE; - } - } - device->devData->regVirtualAddr = (uintptr_t)g_regCodecBase; - - if (I2sPinInit() != HDF_SUCCESS) { - AUDIO_DRIVER_LOG_ERR("I2sPinInit fail."); - } - - return HDF_SUCCESS; -} -``` - -### Dai注册绑定到HDF - -此处依赖HDF框架的驱动实现方式,具体流程可参考[HDF驱动框架](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/driver/driver-hdf.md)。 - -- 填充g_daiDriverEntry结构体 -- moduleName与device_info.hcs中的moduleName匹配 -- 实现Bind、Init、Release函数指针 - -drivers/peripheral/audio/chipsets/hi3516dv300/soc/src/hi3516_dai_adapter.c - -```c -static int32_t DaiDriverBind(struct HdfDeviceObject *device) -{ -... - struct DaiHost *daiHost = (struct DaiHost *)OsalMemCalloc(sizeof(*daiHost)); -... - daiHost->device = device; - device->service = &daiHost->service; - g_daiData.daiInitFlag = false; -... - return HDF_SUCCESS; -} - -static int32_t DaiDriverInit(struct HdfDeviceObject *device) -{ -... - DaiGetConfigInfo(device, &g_daiData); - DaiGetServiceName(device); -... - OsalMutexInit(&g_daiData.mutex); - AudioSocRegisterDai(device, &g_daiData); -... - return HDF_SUCCESS; -} - -static void DaiDriverRelease(struct HdfDeviceObject *device) -{ -... - OsalMutexDestroy(&g_daiData.mutex); -... - struct DaiHost *daiHost = (struct DaiHost *)device->service; -... - OsalMemFree(daiHost); -} - -/* HdfDriverEntry definitions */ -struct HdfDriverEntry g_daiDriverEntry = { - .moduleVersion = 1, - .moduleName = "DAI_HI3516", - .Bind = DaiDriverBind, - .Init = DaiDriverInit, - .Release = DaiDriverRelease, -}; -HDF_INIT(g_daiDriverEntry); -``` - -### HCS配置流程 - -配置过程可参考Codec驱动开发实例[HCS配置流程](#section4115)章节。 - - - -## Makefile中添加编译配置 - -添加新增文件到对应的config中,将其编译链接到内核镜像。 - -标准系统(linux):drivers/adapter/khdf/linux/model/audio/Makefile - -```makefile -obj-$(CONFIG_DRIVERS_HDF_AUDIO_CODEC) += \ -$(KHDF_AUDIO_HI3516DV300_DIR)/../tfa9879/accessory/src/tfa9879_accessory_adapter.o \ -$(KHDF_AUDIO_HI3516DV300_DIR)/../tfa9879/accessory/src/tfa9879_accessory_impl.o \ -$(KHDF_AUDIO_HI3516DV300_DIR)/codec/src/hi3516_codec_adapter.o \ -$(KHDF_AUDIO_HI3516DV300_DIR)/codec/src/hi3516_codec_impl.o \ -$(KHDF_AUDIO_HI3516DV300_DIR)/codec/src/hi3516_codec_ops.o \ -$(KHDF_AUDIO_HI3516DV300_DIR)/dsp/src/dsp_adapter.o \ -$(KHDF_AUDIO_HI3516DV300_DIR)/soc/src/hi3516_dai_adapter.o \ -$(KHDF_AUDIO_HI3516DV300_DIR)/soc/src/hi3516_dai_ops.o \ -$(KHDF_AUDIO_HI3516DV300_DIR)/soc/src/hi3516_aiao_impl.o \ -$(KHDF_AUDIO_HI3516DV300_DIR)/soc/src/hi3516_dma_ops.o \ -$(KHDF_AUDIO_HI3516DV300_DIR)/soc/src/hi3516_dma_adapter.o \ -$(KHDF_AUDIO_HI3516DV300_DIR)/codec/src/hi3516_codec_adapter.o -``` - -小型系统(liteOS):drivers/adapter/khdf/liteos/model/audio/Makefile - -```makefile -LOCAL_SRCS += \ -$(KHDF_AUDIO_HI3516DV300_DIR)/../tfa9879/accessory/src/tfa9879_accessory_adapter.c \ -$(KHDF_AUDIO_HI3516DV300_DIR)/../tfa9879/accessory/src/tfa9879_accessory_impl.c \ -$(KHDF_AUDIO_HI3516DV300_DIR)/codec/src/hi3516_codec_adapter.c \ -$(KHDF_AUDIO_HI3516DV300_DIR)/codec/src/hi3516_codec_impl.c \ -$(KHDF_AUDIO_HI3516DV300_DIR)/codec/src/hi3516_codec_ops.c \ -$(KHDF_AUDIO_HI3516DV300_DIR)/dsp/src/dsp_adapter.c \ -$(KHDF_AUDIO_HI3516DV300_DIR)/soc/src/hi3516_dai_adapter.c \ -$(KHDF_AUDIO_HI3516DV300_DIR)/soc/src/hi3516_dai_ops.c \ -$(KHDF_AUDIO_HI3516DV300_DIR)/soc/src/hi3516_aiao_impl.c \ -$(KHDF_AUDIO_HI3516DV300_DIR)/soc/src/hi3516_dma_ops.c \ -$(KHDF_AUDIO_HI3516DV300_DIR)/soc/src/hi3516_dma_adapter.c -``` - - - -## 源码结构与目录 - -实现驱动接口头文件中的函数。以Hi3516为例,目录架构如下: - -驱动实现示例代码路径:drivers\peripheral\audio\chipsets\ - -``` -├── hi3516dv300 -│   ├── codec -│   │   ├── include -│   │   │   ├── hi3516_codec_impl.h -│   │   │   └── hi3516_codec_ops.h -│   │   ├── src -│   │   │   ├── hi3516_codec_adapter.c // codec驱动入口 -│   │   │   ├── hi3516_codec_impl.c // codec硬件相关操作实现 -│   │   │   └── hi3516_codec_ops.c // codec驱动函数接口实现 -│   │   └── test -│   │   └── unittest -│   ├── dsp -│   │   └── include -│   │   └── dsp_ops.h -│   │   └── src -│   │   └── dsp_adapter.c // dsp驱动入口 -│   │   └── dsp_ops.c -│   └── soc -│   ├── include -│   │   ├── hi3516_aiao_impl.h -│   │   ├── hi3516_dai_ops.h -│   │   └── hi3516_dma_ops.h -│   ├── src -│   │   ├── hi3516_aiao_impl.c -│   │   ├── hi3516_dai_adapter.c //dai驱动入口 -│   │   ├── hi3516_dai_ops.c -│   │   ├── hi3516_dma_adapter.c //dma驱动入口 -│   │   └── hi3516_dma_ops.c -│   └── test -│   └── unittest -└── tfa9879 -    └── accessory -    ├── include -    │   └── tfa9879_accessory_impl.h -    └── src -    ├── tfa9879_accessory_adapter.c // accessory驱动入口 -    └── tfa9879_accessory_impl.c -``` - -hcs文件与目录 - -``` -标准系统: -vendor/hisilicon/Hi3516DV300/ -└── hdf_config - └── khdf - ├── audio - │   ├── audio_config.hcs - │   ├── codec_config.hcs - │   ├── dai_config.hcs - │   ├── dma_config.hcs - │   └── dsp_config.hcs - ├── device_info - │   └── device_info.hcs - └── hdf.hcs - -小型系统: -vendor/hisilicon/hispark_taurus/ -├── config.json -└── hdf_config - ├── audio - │   ├── audio_config.hcs - │   ├── codec_config.hcs - │   ├── dai_config.hcs - │   ├── dma_config.hcs - │   └── dsp_config.hcs - ├── device_info - │   └── device_info.hcs - └── hdf.hcs -``` - - - -# 使用HAL的开发步骤与实例 -代码路径:drivers/peripheral/audio/hal - -## HAL模块使用步骤 - -![](/images/device-dev/driver/figures/HAL流程图.png) - -1. 使用入口函数GetAudioManagerFuncs()获取函数方法。 - -2. 获取所支持的声卡信息GetAllAdapters(),加载对应的声卡LoadAdapter()。 - -3. 创建播放类CreateRender()或者录音类,下发音频文件音频相关属性。 - -4. 调用创建好的播放类中挂载的方法调用render->control.Start()、render->RenderFrame()进行下发开始命令,音频数据循环下发。 - -5. 播放过程中可调用其他控制命令对播放业务进行控制操作,例如调节音量、暂停、静音等render->control.Pause()、 render->control.Resume()、 render->volume.SetVolume()。 - -6. 播放业务完成后,下发停止命令、销毁播放类、卸载声卡。 - - 1. render->control.Stop(); - - 2. adapter->DestroyRender(); - - 3. manager->UnloadAdapter(); - -## HAL使用实例 - -```c -#include -#include -#include "audio_types.h" -#include -#include "audio_manager.h" - - /* so动态库引用打开 */ -char *soPathHdi = "/system/lib/libhdi_audio.z.so"; -void *g_handle = dlopen(soPathHdi , 1); - -int32_t FrameStart(void *param) -{ -... - /* 循环进行下发音频数据 */ - do { - readSize = (remainingDataSize > bufferSize) ? bufferSize : remainingDataSize; - numRead = fread(frame, 1, readSize, g_file); - if (numRead > 0) { - ret = render->RenderFrame(render, frame, numRead, &replyBytes); - if (ret == HDF_ERR_INVALID_OBJECT) { - LOG_FUN_ERR("Render already stop!"); - break; - } - remainingDataSize -= numRead; - } - /* 暂停等待函数 */ - while (g_waitSleep) { - printf("music pause now.\n"); - pthread_cond_wait(&g_functionCond, &g_mutex); - printf("music resume now.\n"); - } - } while (!g_closeEnd && numRead > 0 && remainingDataSize > 0); -... -} - -static void *hal_main() -{ - /* 映射入口函数及调用 */ - struct AudioManager *(*getAudioManager)() = - (struct AudioManager *(*)())(dlsym(g_handle, "GetAudioManagerFuncs")); - struct AudioManager *manager = getAudioManager(); - - /* 获取声卡列表 */ - struct AudioAdapterDescriptor *descs = NULL; - int32_t size = 0; - int32_t ret = manager->GetAllAdapters(manager, &descs, &size); - - /* 根据用户指定的声卡名称和端口描述进行匹配声卡及端口 */ - enum AudioPortDirection port = PORT_OUT; // 端口类型为OUT,放音 - struct AudioPort renderPort; - char * adapterNameCase = "usb"; - int32_t index = SwitchAdapter(descs, adapterNameCase, port, &renderPort, size); - - /* 根据匹配到的声卡信息进行加载声卡 */ - struct AudioAdapter *adapter = NULL; - struct AudioAdapterDescriptor *desc = &descs[index]; // 根据匹配到的声卡信息获取对应设备 - manager->LoadAdapter(manager, desc, &adapter); //加载声卡,获取声卡方法实例 - - /* 创建播放类 */ - struct AudioRender *render; - struct AudioDeviceDescriptor devDesc; - struct AudioSampleAttributes attrs; - InitDevDesc(&devDesc, renderPort.portId); //初始化设置设备参数 - WavHeadAnalysis(g_file, &attrs); // 解析音频文件设置Attributes - adapter->CreateRender(adapter, &devDesc, &attrs, &render); - - /* 下发音频数播放 */ - render->control.Start((AudioHandle)render); // 下发控制命令start,准备动作 - pthread_create(&g_tids, NULL, (void *)(&FrameStart), &g_str); // 起线程进行播放 - - /* 控制命令 */ - render->control.Pause((AudioHandle)render); // 下发进行暂停操作 - render->control.Resume((AudioHandle)render); // 恢复操作 - render->volume.SetVolume((AudioHandle)render, 0.5); // 设置音量 - - /* 停止播放,销毁播放类 */ - render->control.Stop((AudioHandle)render); - adapter->DestroyRender(adapter, render); - /* 卸载声卡 */ - manager->UnloadAdapter(manager, adapter); -} -``` - - - -# 总结 - -以上就是基于Audio驱动框架进行移植开发过程中,所涉及的所有关键适配点。重点介绍了 Audio驱动适配方法、HDI层接口使用方法。开发者可以根据不同芯片进行适配,方便简单。希望通过本次的文档,您能初步掌握基于HDF框架的Audio驱动开发。 \ No newline at end of file diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/04.\345\244\226\350\256\276\351\251\261\345\212\250\344\275\277\347\224\250/06.USB.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/04.\345\244\226\350\256\276\351\251\261\345\212\250\344\275\277\347\224\250/06.USB.md" deleted file mode 100644 index 83d23cdb8800e440736baa95df9247c8fbb6fd9f..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/04.\345\244\226\350\256\276\351\251\261\345\212\250\344\275\277\347\224\250/06.USB.md" +++ /dev/null @@ -1,1564 +0,0 @@ ---- -title: USB -permalink: /pages/0105020406 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:24 ---- -# USB - -- [概述](#section127mcpsimp) - - [接口说明](#section141mcpsimp) - -- [开发指导](#section581mcpsimp) - - [Host DDK API驱动开发步骤](#section584mcpsimp) - - [Host RAW API驱动开发步骤](#section594mcpsimp) - - [Device DDK API驱动开发步骤](#section600mcpsimp) - -- [开发实例](#section607mcpsimp) - - [Host DDK API驱动开发](#section609mcpsimp) - - [Host RAW API驱动开发](#section612mcpsimp) - - [Device DDK API驱动开发](#section615mcpsimp) - - -## 概述 - -USB Host部分,主要包括协议封装、设备管理、驱动安装与卸载等。 - -USB Device部分,支持USB功能设备的开发,提供USB设备相关功能,主要包括设备管理、配置管理、IO管理,实现USB功能设备创建、配置、数据通信等。 - -USB Host驱动模型如下图1所示: - -**图 1** USB Host驱动模型图 -![](/images/device-dev/driver/figures/USB-Host驱动模型图.png "USB-Host驱动模型图") - -**图 2** USB Device驱动模型图 -![](/images/device-dev/driver/figures/USB-Device驱动模型图.png "USB-Device驱动模型图") - -USB驱动模型对外开放的API接口能力如下: - -- Usb Host DDK提供给用户态可直接调用的驱动能力接口,按照功能分类三大类:DDK初始化类、对interface对象操作类、对request对象操作类,可以提供DDK初始化、interface绑定和释放,打开和关闭操作,request的申请和释放,同步和异步传输等。 -- Usb Deivce DDK提供设备管理、IO管理、配置管理,主要功能有:创建和删除设备、获取和打开接口、同步和异步传输等。 - -### 接口说明 - -USB驱动模型Host侧开放的API接口功能,参考[图1](#fig1649563542917)。 - -**表 1** USB驱动模型Host侧开放的API接口功能介绍 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

头文件

-

接口名称

-

功能描述

-

usb_ddk_interface.h

-

int32_t UsbInitHostSdk(struct UsbSession **session);

-

USB主机端驱动开发工具包初始化

-

int32_t UsbExitHostSdk(const struct UsbSession *session);

-

USB主机端驱动开发工具包退出

-

const struct UsbInterface *UsbClaimInterface(const struct UsbSession *session, uint8_t busNum, uint8_t usbAddr, uint8_t interfaceIndex);

-

获取USB接口对象

-

int UsbReleaseInterface(const struct UsbInterface *interfaceObj);

-

释放USB接口对象

-

int UsbAddOrRemoveInterface(const struct UsbSession *session, uint8_t busNum, uint8_t usbAddr, uint8_t interfaceIndex, UsbInterfaceStatus status);

-

增加移除接口

-

UsbInterfaceHandle *UsbOpenInterface(const struct UsbInterface *interfaceObj);

-

打开USB对象接口

-

int32_t UsbCloseInterface(const UsbInterfaceHandle *interfaceHandle);

-

关闭USB接口对象

-

int32_t UsbSelectInterfaceSetting(const UsbInterfaceHandle *interfaceHandle, uint8_t settingIndex, struct UsbInterface **interfaceObj);

-

设置可选配置

-

int32_t UsbGetPipeInfo(const UsbInterfaceHandle *interfaceHandle, uint8_t settingIndex, uint8_t pipeId, struct UsbPipeInfo *pipeInfo);

-

获取指定可选设置的管道信息

-

int32_t UsbClearInterfaceHalt(const UsbInterfaceHandle *interfaceHandle, uint8_t pipeAddress);

-

清除指定索引的管道状态

-

struct UsbRequest *UsbAllocRequest(const UsbInterfaceHandle *interfaceHandle, int isoPackets, int length);

-

分配请求对象

-

int UsbFreeRequest(const struct UsbRequest *request);

-

释放请求对象

-

int UsbSubmitRequestAsync(const struct UsbRequest *request);

-

发送异步请求

-

int32_t UsbFillRequest(const struct UsbRequest *request, const UsbInterfaceHandle *interfaceHandle, const struct UsbRequestParams *params);

-

填充请求

-

sint UsbCancelRequest(const struct UsbRequest *request);

-

取消异步请求

-

int UsbSubmitRequestSync(const struct UsbRequest *request);

-

发送同步请求

-

usb_raw_api.h

-

int UsbRawInit(struct UsbSession **session);

-

USB驱动开发工具包专家模式初始化

-

int UsbRawExit(const struct UsbSession *session);

-

USB驱动开发工具包专家模式退出

-

UsbRawHandle *UsbRawOpenDevice(const struct UsbSession *session, uint8_t busNum, uint8_t usbAddr);

-

打开USB设备对象

-

int UsbRawCloseDevice(const UsbRawHandle *devHandle);

-

关闭USB设备对象

-

int UsbRawSendControlRequest(const struct UsbRawRequest *request, const UsbRawHandle *devHandle, const struct UsbControlRequestData *requestData);

-

执行同步控制传输

-

int UsbRawSendBulkRequest(const struct UsbRawRequest *request, const UsbRawHandle *devHandle, const struct UsbRequestData *requestData);

-

执行同步批量传输

-

int UsbRawSendInterruptRequest(const struct UsbRawRequest *request, const UsbRawHandle *devHandle, const struct UsbRequestData *requestData);

-

执行同步中断传输

-

int UsbRawGetConfigDescriptor(const UsbRawDevice *rawDev, uint8_t configIndex, struct UsbRawConfigDescriptor **config);

-

获取给定设备指定ID的设备配置描述符

-

void UsbRawFreeConfigDescriptor(const struct UsbRawConfigDescriptor *config);

-

释放配置描述符内存空间

-

int UsbRawGetConfiguration(const UsbRawHandle *devHandle, int *config);

-

获取当前激活配置

-

int UsbRawSetConfiguration(const UsbRawHandle *devHandle, int config);

-

设置当前激活配置

-

int UsbRawGetDescriptor(const struct UsbRawRequest *request, const UsbRawHandle *devHandle, const struct UsbRawDescriptorParam *param, const unsigned char *data);

-

获取描述符信息

-

UsbRawDevice *UsbRawGetDevice(const UsbRawHandle *devHandle);

-

由设备句柄获取设备指针

-

int UsbRawGetDeviceDescriptor(const UsbRawDevice *rawDev, struct UsbDeviceDescriptor *desc);

-

获取给定设备的USB设备描述符

-

int UsbRawClaimInterface(const UsbRawHandle *devHandle, int interfaceNumber);

-

声明给定设备句柄上的接口

-

int UsbRawReleaseInterface(const UsbRawHandle *devHandle, int interfaceNumber);

-

释放之前声明的接口

-

int UsbRawResetDevice(const UsbRawHandle *devHandle);

-

复位设备

-

struct UsbRawRequest *UsbRawAllocRequest(const UsbRawHandle *devHandle, int isoPackets, int length);

-

分配一个带有指定数量的同步包描述符的传输请求

-

int UsbRawFreeRequest(const struct UsbRawRequest *request);

-

释放之前分配的传输请求

-

int UsbRawFillBulkRequest(const struct UsbRawRequest *request, const UsbRawHandle *devHandle, const struct UsbRawFillRequestData *fillData);

-

填充批量传输请求所需信息

-

int UsbRawFillControlSetup(const unsigned char *setup, const struct UsbControlRequestData *requestData);

-

填充控制传输设置包所需信息

-

int UsbRawFillControlRequest(const struct UsbRawRequest *request, const UsbRawHandle *devHandle, const struct UsbRawFillRequestData *fillData);

-

填充控制传输请求所需信息

-

int UsbRawFillInterruptRequest(const struct UsbRawRequest *request, const UsbRawHandle *devHandle, const struct UsbRawFillRequestData *fillData);

-

填充中断传输请求所需信息

-

int UsbRawFillIsoRequest(const struct UsbRawRequest *request, const UsbRawHandle *devHandle, const struct UsbRawFillRequestData *fillData);

-

填充同步传输(Isochronous Transfers)请求所需信息

-

int UsbRawSubmitRequest(const struct UsbRawRequest *request);

-

提交一个传输请求

-

int UsbRawCancelRequest(const struct UsbRawRequest *request);

-

取消一个传输请求

-

int UsbRawHandleRequests(const UsbRawHandle *devHandle);

-

传输请求事件完成处理

-
- -USB驱动模型Device侧开放的API接口功能,参考[图2](#fig8847615103013)。 - -**表 2** USB驱动模型Device侧开放的API接口功能介绍 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

头文件

-

头文件

-

功能描述

-

usbfn_device.h

-

const struct UsbFnDevice *UsbFnCreateDevice(const char *udcName, const struct UsbFnDescriptorData *descriptor);

-

创建Usb设备

-

int UsbFnRemoveDevice(struct UsbFnDevice *fnDevice);

-

删除Usb设备

-

const struct UsbFnDevice *UsbFnGetDevice(const char *udcName);

-

获取Usb设备

-

usbfn_interface.h

-

int UsbFnStartRecvInterfaceEvent(struct UsbFnInterface *interface, uint32_t eventMask, UsbFnEventCallback callback, void *context);

-

开始接受Event事件

-

int UsbFnStopRecvInterfaceEvent(struct UsbFnInterface *interface);

-

停止接受Event事件

-

UsbFnInterfaceHandle UsbFnOpenInterface(struct UsbFnInterface *interface);

-

打开一个接口

-

int UsbFnCloseInterface(UsbFnInterfaceHandle handle);

-

关闭一个接口

-

int UsbFnGetInterfacePipeInfo(struct UsbFnInterface *interface, uint8_t pipeId, struct UsbFnPipeInfo *info);

-

获取管道信息

-

int UsbFnSetInterfaceProp(const struct UsbFnInterface *interface, const char *name, const char *value);

-

设置自定义属性

-

usbfn_request.h

-

struct UsbFnRequest *UsbFnAllocCtrlRequest(UsbFnInterfaceHandle handle, uint32_t len);

-

申请一个控制请求

-

struct UsbFnRequest *UsbFnAllocRequest(UsbFnInterfaceHandle handle, uint8_t pipe, uint32_t len);

-

申请一个数据请求

-

int UsbFnFreeRequest(struct UsbFnRequest *req);

-

释放一个请求

-

int UsbFnSubmitRequestAsync(struct UsbFnRequest *req);

-

发送异步请求

-

int UsbFnSubmitRequestSync(struct UsbFnRequest *req, uint32_t timeout);

-

发送同步请求

-

int UsbFnCancelRequest(struct UsbFnRequest *req);

-

取消请求

-
- -## 开发指导 - -USB驱动是基于HDF框架、PLATFORM和OSAL基础接口进行开发,不区分操作系统和芯片平台,为不同USB器件提供统一的驱动模型。本篇开发指导以串口为例,分别介绍USB Host和USB Device驱动开发。 - -### 开发步骤 - -### Host DDK API驱动开发步骤 - -1. 驱动匹配表配置。 -2. 初始化Host DDK。 -3. 待步骤2初始化完后获取UsbInterface接口对象。 -4. 打开步骤3获取到的UsbInterface接口对象,获取相应接口的UsbInterfaceHandle对象。 -5. 根据步骤4获取到的UsbInterfaceHandle对象,获取指定索引为pipeIndex的pipeInfo信息。 -6. 为步骤4获取到的UsbInterfaceHandle预先分配待发送的IO Request对象。 -7. 根据输入参数params填充步骤6预先分配的IO Request。 -8. 提交IO Request对象,可以选择同步或异步两种模式。 - -### Host RAW API驱动开发步骤 - -1. 驱动匹配表配置。 -2. 初始化Host RAW,并打开USB设备,然后获取描述符,通过描述符获取接口、端点信息。 -3. 分配Request,并根据传输类型使用相应接口对Request进行填充。 -4. 提交IO Request对象,可以选择同步或异步两种模式。 - -### Device DDK API驱动开发步骤 - -1. 构造描述符。 -2. 创建设备,使用步骤1构造的描述符实例化一个USB设备。 -3. 根据创建的设备获取接口(UsbFnDeviceGetInterface),获取Pipe信息(UsbFnInterfaceGetPipeInfo),打开接口获取Handle(UsbFnInterfaceOpen),根据Handle和Pipe号获取Request(UsbFnRequestAlloc)。 -4. 接收Event事件(UsbFnInterfaceStartRecvEvent)如Enable、Setup等事件,回调函数(UsbFnEventCallback)中对Event事件做出响应。 -5. 收发数据,可以选择同步异步发送模式。 - -## 开发实例 - -本实例提供USB串口驱动开发示例,并简要对具体关键点进行开发说明。 - -### Host DDK API驱动开发 - -``` -root { - module = "usb_pnp_device"; - usb_pnp_config { - match_attr = "usb_pnp_match"; - usb_pnp_device_id = "UsbPnpDeviceId"; - UsbPnpDeviceId { - idTableList = [ - "host_acm_table" - ]; - host_acm_table { - //驱动模块名,该字段的值必须和驱动入口结构的moduleName一致 - moduleName = "usbhost_acm"; - //驱动对外发布服务的名称,必须唯一 - serviceName = "usbhost_acm_pnp_service"; - //驱动私有数据匹配关键字 - deviceMatchAttr = "usbhost_acm_pnp_matchAttr"; - //从该字段开始(包含该字段)之后数据长度,以byte为单位 - length = 21; - //USB驱动匹配规则vendorId+productId+interfaceSubClass+interfaceProtocol+interfaceNumber - matchFlag = 0x0303; - //厂商编号 - vendorId = 0x12D1; - //产品编号 - productId = 0x5000; - //设备出厂编号,低16位 - bcdDeviceLow = 0x0000; - //设备出厂编号,高16位 - bcdDeviceHigh = 0x0000; - //USB分配的设备类代码 - deviceClass = 0; - //USB分配的子类代码 - deviceSubClass = 0; - //USB分配的设备协议代码 - deviceProtocol = 0; - //接口类型,根据实际需要可填写多个 - interfaceClass = [0]; - //接口子类型,根据实际需要可填写多个 - interfaceSubClass = [2, 0]; - //接口所遵循的协议,根据实际需要可填写多个 - interfaceProtocol = [1, 2]; - //接口的编号,根据实际需要可填写多个 - interfaceNumber = [2, 3]; - } - } - } -} - -#include "usb_serial.h" -#include "hdf_base.h" -#include "hdf_log.h" -#include "osal_mem.h" -#include "osal_time.h" -#include "securec.h" -#include "usb_ddk_interface.h" -#include "hdf_usb_pnp_manage.h" - -#define HDF_LOG_TAG USB_HOST_ACM -#define STR_LEN 512 - -static struct UsbRequest *g_syncRequest = NULL; -static struct UsbRequest *g_ctrlCmdRequest = NULL; -static bool g_acmReleaseFlag = false; -static uint8_t *g_acmReadBuffer = NULL; -... -static int SerialCtrlMsg(struct AcmDevice *acm, uint8_t request, - uint16_t value, void *buf, uint16_t len) -{ - int ret; - uint16_t index = acm->intPipe->interfaceId; - struct UsbControlParams controlParams; - struct UsbRequestParams params; - if (acm == NULL || buf == NULL) { - HDF_LOGE("%s:invalid param", __func__); - return HDF_ERR_IO; - } - if (acm->ctrlReq == NULL) { - acm->ctrlReq = UsbAllocRequest(acm->ctrDevHandle, 0, len); - if (acm->ctrlReq == NULL) { - HDF_LOGE("%s: UsbAllocRequest failed", __func__); - return HDF_ERR_IO; - } - } - - controlParams.request = request; - controlParams.target = USB_REQUEST_TARGET_INTERFACE; - controlParams.reqType = USB_REQUEST_TYPE_CLASS; - controlParams.directon = USB_REQUEST_DIR_TO_DEVICE; - controlParams.value = value; - controlParams.index = index; - controlParams.data = buf; - controlParams.size = len; - - params.interfaceId = USB_CTRL_INTERFACE_ID; - params.pipeAddress = acm->ctrPipe->pipeAddress; - params.pipeId = acm->ctrPipe->pipeId; - params.requestType = USB_REQUEST_PARAMS_CTRL_TYPE; - params.timeout = USB_CTRL_SET_TIMEOUT; - params.ctrlReq = UsbControlSetUp(&controlParams); - ret = UsbFillRequest(acm->ctrlReq, acm->ctrDevHandle, ¶ms); - if (HDF_SUCCESS != ret) { - HDF_LOGE("%s: failed, ret=%d ", __func__, ret); - return ret; - } - ret = UsbSubmitRequestSync(acm->ctrlReq); //发送同步IO Request - if (HDF_SUCCESS != ret) { - HDF_LOGE("UsbSubmitRequestSync failed, ret=%d ", ret); - return ret; - } - if (!acm->ctrlReq->compInfo.status) { - HDF_LOGE("%s status=%d ", __func__, acm->ctrlReq->compInfo.status); - } - return HDF_SUCCESS; -} -... -static struct UsbInterface *GetUsbInterfaceById(const struct AcmDevice *acm, - uint8_t interfaceIndex) -{ - struct UsbInterface *tmpIf = NULL; - tmpIf = (struct UsbInterface *)UsbClaimInterface(acm->session, acm->busNum, - acm->devAddr, interfaceIndex); //获取UsbInterface接口对象 - return tmpIf; -} -... -static struct UsbPipeInfo *EnumePipe(const struct AcmDevice *acm, - uint8_t interfaceIndex, UsbPipeType pipeType, UsbPipeDirection pipeDirection) -{ - uint8_t i; - int ret; - struct UsbInterfaceInfo *info = NULL; - UsbInterfaceHandle *interfaceHandle = NULL; - if (pipeType == USB_PIPE_TYPE_CONTROL) - { - info = &acm->ctrIface->info; - interfaceHandle = acm->ctrDevHandle; - } - else - { - info = &acm->iface[interfaceIndex]->info; - interfaceHandle = InterfaceIdToHandle(acm, info->interfaceIndex); - } - - for (i = 0; i <= info->pipeNum; i++) { - struct UsbPipeInfo p; - ret = UsbGetPipeInfo(interfaceHandle, info->curAltSetting, i, &p);//获取指定索引为i的pipeInfo信息 - if (ret < 0) { - continue; - } - if ((p.pipeDirection == pipeDirection) && (p.pipeType == pipeType)) { - struct UsbPipeInfo *pi = OsalMemCalloc(sizeof(*pi)); - if (pi == NULL) { - HDF_LOGE("%s: Alloc pipe failed", __func__); - return NULL; - } - p.interfaceId = info->interfaceIndex; - *pi = p; - return pi; - } - } - return NULL; -} - -static struct UsbPipeInfo *GetPipe(const struct AcmDevice *acm, - UsbPipeType pipeType, UsbPipeDirection pipeDirection) -{ - uint8_t i; - if (acm == NULL) { - HDF_LOGE("%s: invalid params", __func__); - return NULL; - } - for (i = 0; i < acm->interfaceCnt; i++) { - struct UsbPipeInfo *p = NULL; - if (!acm->iface[i]) { - continue; - } - p = EnumePipe(acm, i, pipeType, pipeDirection); - if (p == NULL) { - continue; - } - return p; - } - return NULL; -} - -/* HdfDriverEntry implementations */ -static int32_t UsbSerialDriverBind(struct HdfDeviceObject *device) -{ - struct UsbPnpNotifyServiceInfo *info = NULL; - errno_t err; - struct AcmDevice *acm = NULL; - if (device == NULL) { - HDF_LOGE("%s: device is null", __func__); - return HDF_ERR_INVALID_OBJECT; - } - acm = (struct AcmDevice *)OsalMemCalloc(sizeof(*acm)); - if (acm == NULL) { - HDF_LOGE("%s: Alloc usb serial device failed", __func__); - return HDF_FAILURE; - } - if (OsalMutexInit(&acm->lock) != HDF_SUCCESS) { - HDF_LOGE("%s:%d OsalMutexInit failed", __func__, __LINE__); - goto error; - } - info = (struct UsbPnpNotifyServiceInfo *)device->priv; - if (info != NULL) { - HDF_LOGD("%s:%d busNum=%d,devAddr=%d,interfaceLength=%d", - __func__, __LINE__, info->busNum, info->devNum, info->interfaceLength); - acm->busNum = info->busNum; - acm->devAddr = info->devNum; - acm->interfaceCnt = info->interfaceLength; - err = memcpy_s((void *)(acm->interfaceIndex), USB_MAX_INTERFACES, - (const void*)info->interfaceNumber, info->interfaceLength); - if (err != EOK) { - HDF_LOGE("%s:%d memcpy_s failed err=%d", - __func__, __LINE__, err); - goto lock_error; - } - } else { - HDF_LOGE("%s:%d info is NULL!", __func__, __LINE__); - goto lock_error; - } - acm->device = device; - device->service = &(acm->service); - acm->device->service->Dispatch = UsbSerialDeviceDispatch; - HDF_LOGD("UsbSerialDriverBind=========================OK"); - return HDF_SUCCESS; - -lock_error: - if (OsalMutexDestroy(&acm->lock)) { - HDF_LOGE("%s:%d OsalMutexDestroy failed", __func__, __LINE__); - } -error: - OsalMemFree(acm); - acm = NULL; - return HDF_FAILURE; -} -... -static int AcmAllocReadRequests(struct AcmDevice *acm) -{ - int ret; - struct UsbRequestParams readParams; - for (int i = 0; i < ACM_NR; i++) { - acm->readReq[i] = UsbAllocRequest(InterfaceIdToHandle(acm, acm->dataInPipe->interfaceId), 0, acm->readSize); //分配待发送的readReq IO Request对象 - if (!acm->readReq[i]) { - HDF_LOGE("readReq request failed"); - goto error; - } - readParams.userData = (void *)acm; - readParams.pipeAddress = acm->dataInPipe->pipeAddress; - readParams.pipeId = acm->dataInPipe->pipeId; - readParams.interfaceId = acm->dataInPipe->interfaceId; - readParams.callback = AcmReadBulk; - readParams.requestType = USB_REQUEST_PARAMS_DATA_TYPE; - readParams.timeout = USB_CTRL_SET_TIMEOUT; - readParams.dataReq.numIsoPackets = 0; - readParams.dataReq.directon = (acm->dataInPipe->pipeDirection >> USB_PIPE_DIR_OFFSET) & 0x1; - readParams.dataReq.length = acm->readSize; - ret = UsbFillRequest(acm->readReq[i], InterfaceIdToHandle(acm, acm->dataInPipe->interfaceId), &readParams); //填充待发送的readReq对象 - if (HDF_SUCCESS != ret) { - HDF_LOGE("%s: UsbFillRequest failed, ret=%d n", __func__, ret); - goto error; - } - } - return HDF_SUCCESS; - -error: - AcmFreeReadRequests(acm); - return HDF_ERR_MALLOC_FAIL; -} - -static int AcmAllocNotifyRequest(struct AcmDevice *acm) -{ - int ret; - struct UsbRequestParams intParams = {}; - acm->notifyReq = UsbAllocRequest(InterfaceIdToHandle(acm, acm->intPipe->interfaceId), 0, acm->intSize); //分配待发送的中断IO Request对象 - if (!acm->notifyReq) { - HDF_LOGE("notifyReq request failed"); - return HDF_ERR_MALLOC_FAIL; - } - intParams.userData = (void *)acm; - intParams.pipeAddress = acm->intPipe->pipeAddress; - intParams.pipeId = acm->intPipe->pipeId; - intParams.interfaceId = acm->intPipe->interfaceId; - intParams.callback = AcmCtrlIrq; - intParams.requestType = USB_REQUEST_PARAMS_DATA_TYPE; - intParams.timeout = USB_CTRL_SET_TIMEOUT; - intParams.dataReq.numIsoPackets = 0; - intParams.dataReq.directon = (acm->intPipe->pipeDirection >> USB_PIPE_DIR_OFFSET) & DIRECTION_MASK; - intParams.dataReq.length = acm->intSize; - ret = UsbFillRequest(acm->notifyReq, InterfaceIdToHandle(acm, acm->intPipe->interfaceId), &intParams); //填充预先分配的中断IO Request - if (HDF_SUCCESS != ret) { - HDF_LOGE("%s: UsbFillRequest failed, ret=%d n", __func__, ret); - goto error; - } - return HDF_SUCCESS; - -error: - AcmFreeNotifyReqeust(acm); - return ret; -} - -static void AcmReleaseInterfaces(struct AcmDevice *acm) -{ - for (int i = 0; i < acm->interfaceCnt; i++) { - if (acm->iface[i]) { - UsbReleaseInterface(acm->iface[i]); - acm->iface[i] = NULL; - } - } - if (acm->ctrIface) { - UsbReleaseInterface(acm->ctrIface); - acm->ctrIface = NULL; - } -} - -static int32_t AcmClaimInterfaces(struct AcmDevice *acm) -{ - for (int i = 0; i < acm->interfaceCnt; i++) { - acm->iface[i] = GetUsbInterfaceById((const struct AcmDevice *)acm, acm->interfaceIndex[i]); //获取UsbInterface接口对象 - if (acm->iface[i] == NULL) { - HDF_LOGE("%s: interface%d is null", __func__, acm->interfaceIndex[i]); - goto error; - } - } - - acm->ctrIface = GetUsbInterfaceById((const struct AcmDevice *)acm, USB_CTRL_INTERFACE_ID); //获取控制接口对应的UsbInterface接口对象 - if (acm->ctrIface == NULL) { - HDF_LOGE("%s: GetUsbInterfaceById null", __func__); - goto error; - } - - return HDF_SUCCESS; - - error: - AcmReleaseInterfaces(acm); - return HDF_FAILURE; -} - -static void AcmCloseInterfaces(struct AcmDevice *acm) -{ - for (int i = 0; i < acm->interfaceCnt; i++) { - if (acm->devHandle[i]) { - UsbCloseInterface(acm->devHandle[i]); - acm->devHandle[i] = NULL; - } - } - if (acm->ctrDevHandle) { - UsbCloseInterface(acm->ctrDevHandle); - acm->ctrDevHandle = NULL; - } -} - -static int32_t AcmOpenInterfaces(struct AcmDevice *acm) -{ - for (int i = 0; i < acm->interfaceCnt; i++) { - if (acm->iface[i]) { - acm->devHandle[i] = UsbOpenInterface(acm->iface[i]); //打开获取到的UsbInterface接口对象 - if (acm->devHandle[i] == NULL) { - HDF_LOGE("%s: UsbOpenInterface null", __func__); - goto error; - } - } - } - acm->ctrDevHandle = UsbOpenInterface(acm->ctrIface); - if (acm->ctrDevHandle == NULL) { - HDF_LOGE("%s: ctrDevHandle UsbOpenInterface null", __func__); - goto error; - } - - return HDF_SUCCESS; - -error: - AcmCloseInterfaces(acm); - return HDF_FAILURE; -} - -static int32_t AcmGetPipes(struct AcmDevice *acm) -{ - acm->dataInPipe = GetPipe(acm, USB_PIPE_TYPE_BULK, USB_PIPE_DIRECTION_IN);//获取dataInPipe的pipeInfo信息 - if (acm->dataInPipe == NULL) { - HDF_LOGE("dataInPipe is NULL"); - goto error; - } - - acm->dataOutPipe = GetPipe(acm, USB_PIPE_TYPE_BULK, USB_PIPE_DIRECTION_OUT);//获取dataOutPipe的pipeInfo信息 - if (acm->dataOutPipe == NULL) { - HDF_LOGE("dataOutPipe is NULL"); - goto error; - } - - acm->ctrPipe = EnumePipe(acm, acm->ctrIface->info.interfaceIndex, USB_PIPE_TYPE_CONTROL, USB_PIPE_DIRECTION_OUT); //获取控制pipe的pipeInfo信息 - if (acm->ctrPipe == NULL) { - HDF_LOGE("ctrPipe is NULL"); - goto error; - } - - acm->intPipe = GetPipe(acm, USB_PIPE_TYPE_INTERRUPT, USB_PIPE_DIRECTION_IN);//获取中断pipe的pipeInfo信息 - if (acm->intPipe == NULL) { - HDF_LOGE("intPipe is NULL"); - goto error; - } - - acm->readSize = acm->dataInPipe->maxPacketSize; - acm->writeSize = acm->dataOutPipe->maxPacketSize; - acm->ctrlSize = acm->ctrPipe->maxPacketSize; - acm->intSize = acm->intPipe->maxPacketSize; - - return HDF_SUCCESS; - -error: - AcmFreePipes(acm); - return HDF_FAILURE; -} - -static void AcmFreeRequests(struct AcmDevice *acm) -{ - if (g_syncRequest != NULL) { - UsbFreeRequest(g_syncRequest); - g_syncRequest = NULL; - } - AcmFreeReadRequests(acm); - AcmFreeNotifyReqeust(acm); - AcmFreeWriteRequests(acm); - AcmWriteBufFree(acm); -} - -static int32_t AcmAllocRequests(struct AcmDevice *acm) -{ - int32_t ret; - - if (AcmWriteBufAlloc(acm) < 0) { - HDF_LOGE("%s: AcmWriteBufAlloc failed", __func__); - return HDF_ERR_MALLOC_FAIL; - } - - for (int i = 0; i < ACM_NW; i++) { - struct AcmWb *snd = &(acm->wb[i]); - snd->request = UsbAllocRequest(InterfaceIdToHandle(acm, acm->dataOutPipe->interfaceId), 0, acm->writeSize); //分配待发送的IO Request对象 - snd->instance = acm; - if (snd->request == NULL) { - HDF_LOGE("%s:%d snd request failed", __func__, __LINE__); - goto error_alloc_write_req; - } - } - - ret = AcmAllocNotifyRequest(acm); //分配并填充中断IO Request对象 - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s:%d AcmAllocNotifyRequest failed", __func__, __LINE__); - goto error_alloc_int_req; - } - - ret = AcmAllocReadRequests(acm); //分配并填充readReq IO Request对象 - if (ret) { - HDF_LOGE("%s:%d AcmAllocReadRequests failed", __func__, __LINE__); - goto error_alloc_read_req; - } - - return HDF_SUCCESS; - -error_alloc_read_req: - AcmFreeNotifyReqeust(acm); -error_alloc_int_req: - AcmFreeWriteRequests(acm); -error_alloc_write_req: - AcmWriteBufFree(acm); - return HDF_FAILURE; -} - -static int32_t AcmInit(struct AcmDevice *acm) -{ - int32_t ret; - struct UsbSession *session = NULL; - - if (acm->initFlag == true) { - HDF_LOGE("%s:%d: initFlag is true", __func__, __LINE__); - return HDF_SUCCESS; - } - - ret = UsbInitHostSdk(NULL); //初始化Host DDK - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: UsbInitHostSdk failed", __func__); - return HDF_ERR_IO; - } - acm->session = session; - - ret = AcmClaimInterfaces(acm); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: AcmClaimInterfaces failed", __func__); - goto error_claim_interfaces; - } - - ret = AcmOpenInterfaces(acm); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: AcmOpenInterfaces failed", __func__); - goto error_open_interfaces; - } - - ret = AcmGetPipes(acm); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: AcmGetPipes failed", __func__); - goto error_get_pipes; - } - - ret = AcmAllocRequests(acm); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: AcmAllocRequests failed", __func__); - goto error_alloc_reqs; - } - - acm->lineCoding.dwDTERate = CpuToLe32(DATARATE); - acm->lineCoding.bCharFormat = CHARFORMAT; - acm->lineCoding.bParityType = USB_CDC_NO_PARITY; - acm->lineCoding.bDataBits = USB_CDC_1_STOP_BITS; - acm->initFlag = true; - - HDF_LOGD("%s:%d========OK", __func__, __LINE__); - return HDF_SUCCESS; - -error_alloc_reqs: - AcmFreePipes(acm); -error_get_pipes: - AcmCloseInterfaces(acm); -error_open_interfaces: - AcmReleaseInterfaces(acm); -error_claim_interfaces: - UsbExitHostSdk(acm->session); - acm->session = NULL; - return ret; -} - -static void AcmRelease(struct AcmDevice *acm) -{ - if (acm->initFlag == false) { - HDF_LOGE("%s:%d: initFlag is false", __func__, __LINE__); - return; - } - - AcmFreeRequests(acm); - AcmFreePipes(acm); - AcmCloseInterfaces(acm); - AcmReleaseInterfaces(acm); - UsbExitHostSdk(acm->session); - acm->session = NULL; - - acm->initFlag = false; -} - -static int32_t UsbSerialDriverInit(struct HdfDeviceObject *device) -{ - int32_t ret; - struct AcmDevice *acm = NULL; - - if (device == NULL) { - HDF_LOGE("%s: device is null", __func__); - return HDF_ERR_INVALID_OBJECT; - } - acm = (struct AcmDevice *)device->service; - OsalMutexInit(&acm->readLock); - OsalMutexInit(&acm->writeLock); - HDF_LOGD("%s:%d busNum=%d,devAddr=%d", - __func__, __LINE__, acm->busNum, acm->devAddr); - - ret = UsbSerialDeviceAlloc(acm); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: Serial Device alloc failed", __func__); - } - - acm->initFlag = false; - g_acmReleaseFlag = false; - - HDF_LOGD("%s:%d init ok!", __func__, __LINE__); - - return ret; -} - -static void UsbSerialDriverRelease(struct HdfDeviceObject *device) -{ - struct AcmDevice *acm = NULL; - - if (device == NULL) { - HDF_LOGE("%s: device is NULL", __func__); - return; - } - acm = (struct AcmDevice *)device->service; - if (acm == NULL) { - HDF_LOGE("%s: acm is null", __func__); - return; - } - - g_acmReleaseFlag = true; - - if (acm->initFlag == true) { - HDF_LOGE("%s:%d AcmRelease", __func__, __LINE__); - AcmRelease(acm); - } - UsbSeriaDevicelFree(acm); - OsalMutexDestroy(&acm->writeLock); - OsalMutexDestroy(&acm->readLock); - OsalMutexDestroy(&acm->lock); - OsalMemFree(acm); - acm = NULL; - HDF_LOGD("%s:%d exit", __func__, __LINE__); -} - -struct HdfDriverEntry g_usbSerialDriverEntry = { - .moduleVersion = 1, - .moduleName = "usbhost_acm", //驱动模块名称,必须与hcs文件中配置的名称一致 - .Bind = UsbSerialDriverBind, - .Init = UsbSerialDriverInit, - .Release = UsbSerialDriverRelease, -}; -HDF_INIT(g_usbSerialDriverEntry); -``` - -### Host RAW API驱动开发 - -``` -root { - module = "usb_pnp_device"; - usb_pnp_config { - match_attr = "usb_pnp_match"; - usb_pnp_device_id = "UsbPnpDeviceId"; - UsbPnpDeviceId { - idTableList = [ - "host_acm_rawapi_table" - ]; - host_acm_rawapi_table { //驱动配置匹配表信息 - //驱动模块名,该字段的值必须和驱动入口结构的moduleName一致 - moduleName = "usbhost_acm_rawapi"; - //驱动对外发布服务的名称,必须唯一 - serviceName = "usbhost_acm_rawapi_service"; - //驱动私有数据匹配关键字 - deviceMatchAttr = "usbhost_acm_rawapi_matchAttr"; - //从该字段开始(包含该字段)之后数据长度,以byte为单位 - length = 21; - //USB驱动匹配规则vendorId+productId+interfaceSubClass+interfaceProtocol+interfaceNumber - matchFlag = 0x0303; - //厂商编号 - vendorId = 0x12D1; - //产品编号 - productId = 0x5000; - //设备出厂编号,低16位 - bcdDeviceLow = 0x0000; - //设备出厂编号,高16位 - bcdDeviceHigh = 0x0000; - //USB分配的设备类代码 - deviceClass = 0; - //USB分配的子类代码 - deviceSubClass = 0; - //USB分配的设备协议代码 - deviceProtocol = 0; - //接口类型,根据实际需要可填写多个 - interfaceClass = [0]; - //接口子类型,根据实际需要可填写多个 - interfaceSubClass = [2, 0]; - //接口所遵循的协议,根据实际需要可填写多个 - interfaceProtocol = [1, 2]; - //接口的编号,根据实际需要可填写多个 - interfaceNumber = [2, 3]; - } - } - } -} - -#include "usb_serial_rawapi.h" -#include -#include "osal_mem.h" -#include "osal_time.h" -#include "securec.h" -#include "hdf_base.h" -#include "hdf_log.h" -#include "hdf_usb_pnp_manage.h" - -#define HDF_LOG_TAG USB_HOST_ACM_RAW_API -#define USB_CTRL_REQ_SIZE 64 -#define USB_IO_THREAD_STACK_SIZE 8192 -#define USB_RAW_IO_SLEEP_MS_TIME 100 -#define USB_RAW_IO_STOP_WAIT_MAX_TIME 3 - -static struct UsbRawRequest *g_syncRequest = NULL; -static UsbRawIoProcessStatusType g_stopIoStatus = USB_RAW_IO_PROCESS_RUNNING; -struct OsalMutex g_stopIoLock; -static bool g_rawAcmReleaseFlag = false; -...... - -static int UsbGetConfigDescriptor(UsbRawHandle *devHandle, struct UsbRawConfigDescriptor **config) -{ - UsbRawDevice *dev = NULL; - int activeConfig; - int ret; - - if (devHandle == NULL) { - HDF_LOGE("%s:%d devHandle is NULL", - __func__, __LINE__); - return HDF_ERR_INVALID_PARAM; - } - - ret = UsbRawGetConfiguration(devHandle, &activeConfig); - if (ret) { - HDF_LOGE("%s:%d UsbRawGetConfiguration failed, ret=%d", - __func__, __LINE__, ret); - return HDF_FAILURE; - } - HDF_LOGE("%s:%d activeConfig=%d", __func__, __LINE__, activeConfig); - dev = UsbRawGetDevice(devHandle); - if (dev == NULL) { - HDF_LOGE("%s:%d UsbRawGetDevice failed", - __func__, __LINE__); - return HDF_FAILURE; - } - - ret = UsbRawGetConfigDescriptor(dev, activeConfig, config); - if (ret) { - HDF_LOGE("UsbRawGetConfigDescriptor failed, ret=%dn", ret); - return HDF_FAILURE; - } - - return HDF_SUCCESS; -} -... -static int UsbAllocWriteRequests(struct AcmDevice *acm) -{ - int i; - - for (i = 0; i < ACM_NW; i++) { - struct AcmWb *snd = &acm->wb[i]; - snd->request = UsbRawAllocRequest(acm->devHandle, 0, acm->dataOutEp->maxPacketSize); - snd->instance = acm; - if (snd->request == NULL) { - HDF_LOGE("%s: UsbRawAllocRequest failed", __func__); - return HDF_ERR_MALLOC_FAIL; - } - } - - return HDF_SUCCESS; -} -... -/* HdfDriverEntry implementations */ -static int32_t UsbSerialDriverBind(struct HdfDeviceObject *device) -{ - struct AcmDevice *acm = NULL; - struct UsbPnpNotifyServiceInfo *info = NULL; - errno_t err; - - if (device == NULL) { - HDF_LOGE("%s: device is null", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - acm = (struct AcmDevice *)OsalMemCalloc(sizeof(*acm)); - if (acm == NULL) { - HDF_LOGE("%s: Alloc usb serial device failed", __func__); - return HDF_FAILURE; - } - if (OsalMutexInit(&acm->lock) != HDF_SUCCESS) { - HDF_LOGE("%s:%d OsalMutexInit failed", __func__, __LINE__); - goto error; - } - - info = (struct UsbPnpNotifyServiceInfo *)device->priv; - if (info != NULL) { - acm->busNum = info->busNum; - acm->devAddr = info->devNum; - acm->interfaceCnt = info->interfaceLength; - err = memcpy_s((void *)(acm->interfaceIndex), USB_MAX_INTERFACES, - (const void*)info->interfaceNumber, info->interfaceLength); - if (err != EOK) { - HDF_LOGE("%s:%d memcpy_s failed err=%d", - __func__, __LINE__, err); - goto lock_error; - } - } else { - HDF_LOGE("%s:%d info is NULL!", __func__, __LINE__); - goto lock_error; - } - - device->service = &(acm->service); - device->service->Dispatch = UsbSerialDeviceDispatch; - acm->device = device; - HDF_LOGD("UsbSerialDriverBind=========================OK"); - return HDF_SUCCESS; - -lock_error: - if (OsalMutexDestroy(&acm->lock)) { - HDF_LOGE("%s:%d OsalMutexDestroy failed", __func__, __LINE__); - } -error: - OsalMemFree(acm); - acm = NULL; - return HDF_FAILURE; -} -... -static int UsbAllocReadRequests(struct AcmDevice *acm) -{ - struct UsbRawFillRequestData reqData; - int size = acm->dataInEp->maxPacketSize; - int ret; - - for (int i = 0; i < ACM_NR; i++) { - acm->readReq[i] = UsbRawAllocRequest(acm->devHandle, 0, size); - if (!acm->readReq[i]) { - HDF_LOGE("readReq request failed"); - return HDF_ERR_MALLOC_FAIL; - } - - reqData.endPoint = acm->dataInEp->addr; - reqData.numIsoPackets = 0; - reqData.callback = AcmReadBulkCallback; - reqData.userData = (void *)acm; - reqData.timeout = USB_CTRL_SET_TIMEOUT; - reqData.length = size; - - ret = UsbRawFillBulkRequest(acm->readReq[i], acm->devHandle, &reqData); - if (ret) { - HDF_LOGE("%s: FillBulkRequest failed, ret=%d n", - __func__, ret); - return HDF_FAILURE; - } - } - - return HDF_SUCCESS; -} -... -static int UsbAllocNotifyRequest(struct AcmDevice *acm) -{ - struct UsbRawFillRequestData fillRequestData; - int size = acm->notifyEp->maxPacketSize; - int ret; - - acm->notifyReq = UsbRawAllocRequest(acm->devHandle, 0, size); - if (!acm->notifyReq) { - HDF_LOGE("notifyReq request failed"); - return HDF_ERR_MALLOC_FAIL; - } - - fillRequestData.endPoint = acm->notifyEp->addr; - fillRequestData.length = size; - fillRequestData.numIsoPackets = 0; - fillRequestData.callback = AcmNotifyReqCallback; - fillRequestData.userData = (void *)acm; - fillRequestData.timeout = USB_CTRL_SET_TIMEOUT; - - ret = UsbRawFillInterruptRequest(acm->notifyReq, acm->devHandle, &fillRequestData); - if (ret) { - HDF_LOGE("%s: FillInterruptRequest failed, ret=%d", __func__, ret); - return HDF_FAILURE; - } - - return HDF_SUCCESS; -} -... -static int32_t UsbSerialInit(struct AcmDevice *acm) -{ - struct UsbSession *session = NULL; - UsbRawHandle *devHandle = NULL; - int32_t ret; - - if (acm->initFlag == true) { - HDF_LOGE("%s:%d: initFlag is true", __func__, __LINE__); - return HDF_SUCCESS; - } - - ret = UsbRawInit(NULL); - if (ret) { - HDF_LOGE("%s:%d UsbRawInit failed", __func__, __LINE__); - return HDF_ERR_IO; - } - acm->session = session; - - devHandle = UsbRawOpenDevice(session, acm->busNum, acm->devAddr); - if (devHandle == NULL) { - HDF_LOGE("%s:%d UsbRawOpenDevice failed", __func__, __LINE__); - ret = HDF_FAILURE; - goto err_open_device; - } - acm->devHandle = devHandle; - ret = UsbGetConfigDescriptor(devHandle, &acm->config); - if (ret) { - HDF_LOGE("%s:%d UsbGetConfigDescriptor failed", __func__, __LINE__); - ret = HDF_FAILURE; - goto err_get_desc; - } - ret = UsbParseConfigDescriptor(acm, acm->config); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s:%d UsbParseConfigDescriptor failed", __func__, __LINE__); - ret = HDF_FAILURE; - goto err_parse_desc; - } - - ret = AcmWriteBufAlloc(acm); - if (ret < 0) { - HDF_LOGE("%s:%d AcmWriteBufAlloc failed", __func__, __LINE__); - ret = HDF_FAILURE; - goto err_alloc_write_buf; - } - ret = UsbAllocWriteRequests(acm); - if (ret < 0) { - HDF_LOGE("%s:%d UsbAllocWriteRequests failed", __func__, __LINE__); - ret = HDF_FAILURE; - goto err_alloc_write_reqs; - } - ret = UsbAllocNotifyRequest(acm); - if (ret) { - HDF_LOGE("%s:%d UsbAllocNotifyRequests failed", __func__, __LINE__); - goto err_alloc_notify_req; - } - ret = UsbAllocReadRequests(acm); - if (ret) { - HDF_LOGE("%s:%d UsbAllocReadRequests failed", __func__, __LINE__); - goto err_alloc_read_reqs; - } - ret = UsbStartIo(acm); - if (ret) { - HDF_LOGE("%s:%d UsbAllocReadRequests failed", __func__, __LINE__); - goto err_start_io; - } - - acm->lineCoding.dwDTERate = CpuToLe32(DATARATE); - acm->lineCoding.bCharFormat = CHARFORMAT; - acm->lineCoding.bParityType = USB_CDC_NO_PARITY; - acm->lineCoding.bDataBits = USB_CDC_1_STOP_BITS; - - ret = UsbRawSubmitRequest(acm->notifyReq); - if (ret) { - HDF_LOGE("%s:%d UsbRawSubmitRequest failed", __func__, __LINE__); - goto err_submit_req; - } - - acm->initFlag = true; - - HDF_LOGD("%s:%d=========================OK", __func__, __LINE__); - - return HDF_SUCCESS; - -err_submit_req: - UsbStopIo(acm); -err_start_io: - UsbFreeReadRequests(acm); -err_alloc_read_reqs: - UsbFreeNotifyReqeust(acm); - err_alloc_notify_req: - UsbFreeWriteRequests(acm); -err_alloc_write_reqs: - AcmWriteBufFree(acm); -err_alloc_write_buf: - UsbReleaseInterfaces(acm); -err_parse_desc: - UsbRawFreeConfigDescriptor(acm->config); - acm->config = NULL; -err_get_desc: - (void)UsbRawCloseDevice(devHandle); -err_open_device: - UsbRawExit(acm->session); - - return ret; -} - -static void UsbSerialRelease(struct AcmDevice *acm) -{ - if (acm->initFlag == false) { - HDF_LOGE("%s:%d: initFlag is false", __func__, __LINE__); - return; - } - - /* stop io thread and release all resources */ - UsbStopIo(acm); - if (g_syncRequest != NULL) { - UsbRawFreeRequest(g_syncRequest); - g_syncRequest = NULL; - } - UsbFreeReadRequests(acm); - UsbFreeNotifyReqeust(acm); - UsbFreeWriteRequests(acm); - AcmWriteBufFree(acm); - (void)UsbRawCloseDevice(acm->devHandle); - UsbReleaseInterfaces(acm); - UsbRawFreeConfigDescriptor(acm->config); - acm->config = NULL; - UsbRawExit(acm->session); - - acm->initFlag = false; -} - -static int32_t UsbSerialDriverInit(struct HdfDeviceObject *device) -{ - struct AcmDevice *acm = NULL; - int32_t ret; - - if (device == NULL) { - HDF_LOGE("%s:%d device is null", __func__, __LINE__); - return HDF_ERR_INVALID_OBJECT; - } - acm = (struct AcmDevice *)device->service; - OsalMutexInit(&acm->readLock); - OsalMutexInit(&acm->writeLock); - - ret = UsbSerialDeviceAlloc(acm); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s:%d UsbSerialDeviceAlloc failed", __func__, __LINE__); - } - - acm->initFlag = false; - g_rawAcmReleaseFlag = false; - - HDF_LOGD("%s:%d init ok!", __func__, __LINE__); - - return ret; -} - -static void UsbSerialDriverRelease(struct HdfDeviceObject *device) -{ - struct AcmDevice *acm = NULL; - if (device == NULL) { - HDF_LOGE("%s: device is NULL", __func__); - return; - } - - acm = (struct AcmDevice *)device->service; - if (acm == NULL) { - HDF_LOGE("%s: acm is null", __func__); - return; - } - - g_rawAcmReleaseFlag = true; - - if (acm->initFlag == true) { - HDF_LOGE("%s:%d UsbSerialRelease", __func__, __LINE__); - UsbSerialRelease(acm); - } - UsbSeriaDevicelFree(acm); - OsalMutexDestroy(&acm->writeLock); - OsalMutexDestroy(&acm->readLock); - OsalMutexDestroy(&acm->lock); - OsalMemFree(acm); - acm = NULL; - HDF_LOGD("%s:%d exit", __func__, __LINE__); -} - -struct HdfDriverEntry g_usbSerialRawDriverEntry = { - .moduleVersion = 1, - .moduleName = "usbhost_acm_rawapi", //驱动模块名称,必须与hcs文件中配置的名称一致 - .Bind = UsbSerialDriverBind, - .Init = UsbSerialDriverInit, - .Release = UsbSerialDriverRelease, -}; -HDF_INIT(g_usbSerialRawDriverEntry); -``` - -### Device DDK API驱动开发 - -USB ACM设备核心代码路径为drivers/peripheral/usb/gadget/function/acm/cdcacm.c,其使用示例如下所示,首先根据描述符创建设备,然后获取接口,打开接口,获取Pipe信息,接收Event事件,接着进行USB通信(读写等),设备卸载时候,关闭接口,停止Event接收,删除设备。 - -``` -1、创建设备 -static int32_t AcmCreateFuncDevice(struct UsbAcmDevice *acm, - struct DeviceResourceIface *iface) -{ - struct UsbFnDevice *fnDev = NULL; -struct UsbFnDescriptorData descData; -uint8_t useHcs; - ... -if (useHcs == 0) { - descData.type = USBFN_DESC_DATA_TYPE_DESC; - descData.descriptor = &g_masterFuncDevice; -} else { - descData.type = USBFN_DESC_DATA_TYPE_PROP; - descData.property = device->property; -} -/* 创建设备 */ - fnDev = (struct UsbFnDevice *)UsbFnDeviceCreate(acm->udcName, &descData); - if (fnDev == NULL) { - HDF_LOGE("%s: create usb function device failed", __func__); - return HDF_FAILURE; - } - ... -} -2、获取接口,打开接口,获取Pipe信息 -static int32_t AcmParseEachPipe(struct UsbAcmDevice *acm, struct UsbAcmInterface *iface) -{ - ... - for (i = 0; i < fnIface->info.numPipes; i++) { - struct UsbFnPipeInfo pipeInfo; -/* 获取pipe信息 */ - ret = UsbFnInterfaceGetPipeInfo(fnIface, i, &pipeInfo); - ... - } - return HDF_SUCCESS; -} -/* 获取接口,打开接口获取handle */ -static int32_t AcmParseEachIface(struct UsbAcmDevice *acm, struct UsbFnDevice *fnDev) -{ - ... - for (i = 0; i < fnDev->numInterfaces; i++) { - /* 获取接口 */ - fnIface = (struct UsbFnInterface *)UsbFnDeviceGetInterface(fnDev, i); - ... - /* 打开接口 */ - handle = UsbFnInterfaceOpen(fnIface); - ... - } - return HDF_SUCCESS; -} -3、接收Event事件 -static int32_t AcmAllocCtrlRequests(struct UsbAcmDevice *acm, int num) -{ - ... - req = UsbFnCtrlRequestAlloc(acm->ctrlIface.handle, - sizeof(struct UsbCdcLineCoding) + sizeof(struct UsbCdcLineCoding)); - ... -} -static int32_t AcmDriverInit(struct HdfDeviceObject *device) -{ -... -/* 开始接收Event */ - ret = UsbFnInterfaceStartRecvEvent(acm->ctrlIface.fn, 0xff, UsbAcmEventCallback, acm); - ... -} -4、进行USB通信(读写等) -static int32_t AcmSendNotifyRequest(struct UsbAcmDevice *acm, uint8_t type, - uint16_t value, void *data, uint32_t length) -{ -... -/* 异步发送 */ - ret = UsbFnRequestSubmitAsync(req); - ... -} -5、关闭接口,停止Event接收,删除设备 -static int32_t AcmReleaseFuncDevice(struct UsbAcmDevice *acm) -{ -int32_t ret; -/* 关闭接口 */ - (void)UsbFnInterfaceClose(acm->ctrlIface.handle); -(void)UsbFnInterfaceClose(acm->dataIface.handle); -/* 停止接收Event */ -(void)UsbFnInterfaceStopRecvEvent(acm->ctrlIface.fn); -/* 删除设备 */ - ret = UsbFnDeviceRemove(acm->fnDev); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: remove usb function device failed", __func__); - } - return ret; -} -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/04.\345\244\226\350\256\276\351\251\261\345\212\250\344\275\277\347\224\250/07.CAMERA.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/04.\345\244\226\350\256\276\351\251\261\345\212\250\344\275\277\347\224\250/07.CAMERA.md" deleted file mode 100644 index 2cd03a0b7744e602172bb7c804b787ab171b30ac..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/02.\351\251\261\345\212\250/04.\345\244\226\350\256\276\351\251\261\345\212\250\344\275\277\347\224\250/07.CAMERA.md" +++ /dev/null @@ -1,685 +0,0 @@ ---- -title: CAMERA -permalink: /pages/0105020407 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:24 ---- -# Camera - -- [Camera](#camera) - - [概述](#概述) - - [开发指导](#开发指导) - - [HDI接口说明](#hdi接口说明) - - [开发步骤](#开发步骤) - - [开发实例](#开发实例) - - -## 概述 - -OpenHarmony相机驱动框架模型对上实现相机HDI(Hardware Driver Interface)接口,对下实现相机Pipeline模型,管理相机各个硬件设备。 -该驱动框架模型内部分为三层,依次为HDI实现层、框架层和适配层,各层基本概念如下: -+ **HDI实现层**:对上实现OHOS(OpenHarmony Operation System)相机标准南向接口。 - -+ **框架层**:对接HDI实现层的控制、流的转发,实现数据通路的搭建,管理相机各个硬件设备等功能。 - -+ **适配层**:屏蔽底层芯片和OS(Operation System)差异,支持多平台适配。 - -**** -**图 1** 基于HDF驱动框架的Camera驱动模型 -![](/images/device-dev/driver/figures/logic-view-of-camera-hal-zh.png) - -1. 系统启动时创建CameraDeviceHost进程。进程创建后,首先枚举底层设备,创建(也可以通过配置表创建)管理设备树的DeviceManager类及其内部各个底层设备的对象,创建对应的CameraHost类实例并且将其注册到UHDF服务中,方便上层通过UHDF服务获取底层CameraDeviceHost的服务,从而操作底层设备。 - -2. Service通过CameraDeviceHost服务获取CameraHost实例,CameraHost可以获取底层的Camera能力,打开手电筒、调用Open接口打开Camera创建连接、创建DeviceManager(负责底层硬件模块上电)、创建CameraDevice(向上提供设备控制接口)。创建CameraDevice时会实例化PipelineCore的各个子模块,其中StreamPiplineCore负责创建Pipeline,MetaQueueManager负责上报meta。 - -3. Service通过底层的CameraDevice配置流、创建Stream类。StreamPipelineStrategy模块通过上层下发的模式和查询配置表创建对应流的Node连接方式,StreamPipelineBuilder模块创建Node实例并且连接返回该Pipline给StreamPipelineDispatcher。StreamPipelineDispatcher提供统一的Pipline调用管理。 - -4. Service通过Stream控制整个流的操作,AttachBufferQueue接口将从显示模块申请的BufferQueue下发到底层,由CameraDeviceDriverModel自行管理buffer,当Capture接口下发命令后,底层开始向上传递buffer。Pipeline的IspNode依次从BufferQueue获取指定数量buffer,然后下发到底层ISP(Image Signal Processor,图像信号处理器)硬件,ISP填充完之后将buffer传递给CameraDeviceDriverModel,CameraDeviceDriverModel通过循环线程将buffer填充到已经创建好的Pipeline中,各个Node处理后通过回调传递给上层,同时buffer返回BufferQueue等待下一次下发。 - -5. Service通过Capture接口下发拍照命令。ChangeToOfflineStream接口查询拍照buffer位置,如果ISP已经出图,并且图像数据已经送到IPP node,可以将普通拍照流转换为离线流,否则直接走关闭流程。ChangeToOfflineStream接口通过传递StreamInfo使离线流获取到普通流的流信息,并且通过配置表确认离线流的具体Node连接方式,创建离线流的Node连接(如果已创建则通过CloseCamera释放非离线流所需的Node),等待buffer从底层Pipeline回传到上层再释放持有的Pipeline相关资源。 - -6. Service通过CameraDevice的UpdateSettings接口向下发送CaptureSetting参数,CameraDeviceDriverModel通过StreamPipelineDispatcher模块向各个Node转发,StartStreamingCapture和Capture接口携带的CaptureSetting通过StreamPipelineDispatcher模块向该流所属的Node转发。 - -7. Service通过EnableResult和DisableResult接口控制底层meta的上报。如果需要底层meta上报,pipeline会创建CameraDeviceDriverModel内部的一个Bufferqueue用来收集和传递meta,根据StreamPipelineStrategy模块查询配置表并通过StreamPipelineBuilder创建和连接Node,MetaQueueManager下发buffer至底层,底层相关Node填充数据,MetaQueueManager模块再调用上层回调传递给上层。 - -8. Service调用CameraDevice的Close接口,CameraDevice调用对应的DeviceManager模块对各个硬件下电;如果此时在Ipp的SubPipeline中存在OfflineStream,则需要保留OfflineStream,直到执行完毕。 - -9. 动态帧率控制。在StreamOperator中起一个CollectBuffer线程,CollectBuffer线程从每一路stream的BufferQueue中获取buffer,如果某一路流的帧率需要控制(为sensor出帧帧率的1/n),可以根据需求控制每一帧的buffer打包,并决定是否collect此路流的buffer(比如sensor出帧帧率为120fps,预览流的帧率为30fps,CollectBuffer线程collect预览流的buffer时,每隔4fps collect一次)。 - -## 开发指导 - -### HDI接口说明 -旨在了解HDI接口的作用及函数参数的传递规则,详情可见[Camera驱动子系统HDI使用说明](https://gitee.com/openharmony/drivers_peripheral/blob/master/camera/README_zh.md)。 - - -### 开发步骤 - -下面分步骤描述了Camera驱动框架的主要接口,包括注册、检测;创建、捕获和销毁流;打开和关闭设备等接口(为了更清晰的展示和描述主要功能的实现部分,该章节删除了部分判错和LOG源码)。 -1. 注册CameraHost - - 定义Camera的HdfDriverEntry结构体,该结构体中定义了CameraHost初始化的方法。 - - ``` - struct HdfDriverEntry g_cameraHostDriverEntry = { - .moduleVersion = 1, - .moduleName = "camera_service", - .Bind = HdfCameraHostDriverBind, - .Init = HdfCameraHostDriverInit, - .Release = HdfCameraHostDriverRelease, - }; - HDF_INIT(g_cameraHostDriverEntry); // 将Camera的HdfDriverEntry结构体注册到HDF上 - ``` - -2. CameraHost初始化 - - 步骤1中提到的HdfCameraHostDriverBind接口提供了CameraServiceDispatch和CameraHostStubInstance的注册。这两个接口一个是远端调用CameraHost的方法,如OpenCamera(),SetFlashlight()等,另外一个是Camera设备的初始化,在开机时被调用。 - - ``` - int HdfCameraHostDriverBind(HdfDeviceObject *deviceObject) - { - HDF_LOGI("HdfCameraHostDriverBind enter!"); - if (deviceObject == nullptr) { - HDF_LOGE("HdfCameraHostDriverBind: HdfDeviceObject is NULL !"); - return HDF_FAILURE; - } - HdfCameraService *hdfCameraService = reinterpret_cast(OsalMemAlloc(sizeof(HdfCameraService))); - if (hdfCameraService == nullptr) { - HDF_LOGE("HdfCameraHostDriverBind OsalMemAlloc HdfCameraService failed!"); - return HDF_FAILURE; - } - hdfCameraService->ioservice.Dispatch = CameraServiceDispatch; // 提供远端CameraHost调用方法 - hdfCameraService->ioservice.Open = nullptr; - hdfCameraService->ioservice.Release = nullptr; - hdfCameraService->instance = CameraHostStubInstance(); // 初始化Camera设备 - deviceObject->service = &hdfCameraService->ioservice; - return HDF_SUCCESS; - } - ``` - - 下面的函数是远端CameraHost调用的方法: - - ``` - int32_t CameraHostStub::CameraHostServiceStubOnRemoteRequest(int cmdId, MessageParcel &data, - MessageParcel &reply, MessageOption &option) - { - switch(cmdId) { - case CMD_CAMERA_HOST_SET_CALLBACK: { - return CameraHostStubSetCallback(data, reply, option); - } - case CMD_CAMERA_HOST_GET_CAMERAID: { - return CameraHostStubGetCameraIds(data, reply, option); - } - case CMD_CAMERA_HOST_GET_CAMERA_ABILITY: { - return CameraHostStubGetCameraAbility(data, reply, option); - } - case CMD_CAMERA_HOST_OPEN_CAMERA: { - return CameraHostStubOpenCamera(data, reply, option); - } - case CMD_CAMERA_HOST_SET_FLASH_LIGHT: { - return CameraHostStubSetFlashlight(data, reply, option); - } - default: { - HDF_LOGE("%s: not support cmd %d", __func__, cmdId); - return HDF_ERR_INVALID_PARAM; - } - } - return HDF_SUCCESS; - } - ``` - - CameraHostStubInstance()接口最终调用CameraHostImpl::Init()方法,该方法会获取物理Camera,并对DeviceManager和PipelineCore进行初始化。 - -3. 获取CamerHost - - 调用Get()接口从远端CameraService中获取CameraHost对象。get()方法如下: - - ``` - sptr ICameraHost::Get(const char *serviceName) - { - do { - using namespace OHOS::HDI::ServiceManager::V1_0; - auto servMgr = IServiceManager::Get(); - if (servMgr == nullptr) { - HDF_LOGE("%s: IServiceManager failed!", __func__); - break; - } - auto remote = servMgr->GetService(serviceName); // 根据serviceName名称获取CameraHost - if (remote != nullptr) { - sptr hostSptr = iface_cast(remote); // 将CameraHostProxy对象返回给调用者,该对象中包含OpenCamera()等方法。 - return hostSptr; - } - HDF_LOGE("%s: GetService failed! serviceName = %s", __func__, serviceName); - } while(false); - HDF_LOGE("%s: get %s failed!", __func__, serviceName); - return nullptr; - } - ``` - -4. OpenCamera()接口 - - CameraHostProxy对象中有五个方法,分别是SetCallback、GetCameraIds、GetCameraAbility、OpenCamera和SetFlashlight。下面着重描述OpenCamera接口。 - CameraHostProxy的OpenCamera()接口通过CMD_CAMERA_HOST_OPEN_CAMERA调用远端CameraHostStubOpenCamera()接口并获取ICameraDevice对象。 - - ``` - CamRetCode CameraHostProxy::OpenCamera(const std::string &cameraId, const OHOS::sptr &callback, OHOS::sptr &pDevice) - { - int32_t ret = Remote()->SendRequest(CMD_CAMERA_HOST_REMOTE_OPEN_CAMERA, data, reply, option); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ret); - return INVALID_ARGUMENT; - } - CamRetCode retCode = static_cast(reply.ReadInt32()); - bool flag = reply.ReadBool(); - if (flag) { - sptr remoteCameraDevice = reply.ReadRemoteObject(); - if (remoteCameraDevice == nullptr) { - HDF_LOGE("%{public}s: CameraHostProxy remoteCameraDevice is null", __func__); - } - pDevice = OHOS::iface_cast(remoteCameraDevice); - } - return retCode; - } - ``` - - Remote()->SendRequest调用上文提到的CameraHostServiceStubOnRemoteRequest(),根据cmdId进入CameraHostStubOpenCamera()接口,最终调用CameraHostImpl::OpenCamera(),该接口获取了CameraDevice并对硬件进行上电等操作。 - - ``` - CamRetCode CameraHostImpl::OpenCamera(const std::string &cameraId, const OHOS::sptr &callback, OHOS::sptr &device) - { - std::shared_ptr cameraDevice = std::static_pointer_cast(itr->second); - if (cameraDevice == nullptr) { - CAMERA_LOGE("camera device is null."); - return INSUFFICIENT_RESOURCES; - } - CamRetCode ret = cameraDevice->SetCallback(callback); - if (ret != NO_ERROR) { - CAMERA_LOGW("set camera device callback faild."); - return ret; - } - CameraHostConfig *config = CameraHostConfig::GetInstance(); - if (config == nullptr) { - return INVALID_ARGUMENT; - } - std::vector phyCameraIds; - RetCode rc = config->GetPhysicCameraIds(cameraId, phyCameraIds); - if (rc != RC_OK) { - CAMERA_LOGE("get physic cameraId failed."); - return DEVICE_ERROR; - } - if (CameraPowerUp(cameraId, phyCameraIds) != RC_OK) { // 对Camera硬件上电 - CAMERA_LOGE("camera powerup failed."); - CameraPowerDown(phyCameraIds); - return DEVICE_ERROR; - } - - auto sptrDevice = deviceBackup_.find(cameraId); - if (sptrDevice == deviceBackup_.end()) { - deviceBackup_[cameraId] = cameraDevice.get(); - } - device = deviceBackup_[cameraId]; - cameraDevice->SetStatus(true); - return NO_ERROR; - } - ``` - -5. GetStreamOperator()接口 - - CameraDeviceImpl定义了GetStreamOperator、UpdateSettings、SetResultMode和GetEnabledResult等方法,获取流操作方法如下: - - ``` - CamRetCode CameraDeviceImpl::GetStreamOperator(const OHOS::sptr &callback, - OHOS::sptr &streamOperator) - { - if (callback == nullptr) { - CAMERA_LOGW("input callback is null."); - return INVALID_ARGUMENT; - } - spCameraDeciceCallback_ = callback; - if (spStreamOperator_ == nullptr) { - // 这里new了一个spStreamOperator对象传递给调用者,以便对stream进行各种操作。 - spStreamOperator_ = new(std::nothrow) StreamOperatorImpl(spCameraDeciceCallback_, shared_from_this()); - if (spStreamOperator_ == nullptr) { - CAMERA_LOGW("create stream operator failed."); - return DEVICE_ERROR; - } - ismOperator_ = spStreamOperator_; - } - streamOperator = ismOperator_; - - spStreamOperator_->SetRequestCallback([this](){ - cameraDeciceCallback_->OnError(REQUEST_TIMEOUT, 0); - }); - } - ``` - -6. 创建流 - - 调用CreateStreams创建流前需要填充StreamInfo结构体,具体内容如下: - - ``` - using StreamInfo = struct _StreamInfo { - int streamId_; - int width_; // 数据流宽 - int height_; // 数据流高 - int format_; // 数据流格式,如PIXEL_FMT_YCRCB_420_SP - int datasapce_; - StreamIntent intent_; // StreamIntent 如PREVIEW - bool tunneledMode_; - OHOS::sptr bufferQueue_; // 数据流bufferQueue可用streamCustomer->CreateProducer()接口创建 - int minFrameDuration_; - EncodeType encodeType_; - }; - ``` - - CreateStreams()接口是StreamOperatorImpl类中的方法,该接口的主要作用是创建一个StreamBase对象,通过StreamBase的Init方法初始化CreateBufferPool等操作。 - - ``` - RetCode StreamOperatorImpl::CreateStream(const std::shared_ptr& streamInfo) - { - static std::map typeMap = { - {PREVIEW, "PREVIEW"}, - {VIDEO, "VIDEO"}, - {STILL_CAPTURE, "STILL_CAPTURE"}, - {POST_VIEW, "POST_VIEW"}, {ANALYZE, "ANALYZE"}, - {CUSTOM, "CUSTOM"} - }; - - auto itr = typeMap.find(streamInfo->intent_); - if (itr == typeMap.end()) { - CAMERA_LOGE("do not support stream type. [type = %{public}d]", streamInfo->intent_); - return RC_ERROR; - } - std::shared_ptr stream = StreamFactory::Instance().CreateShared(itr->second); // 创建StreamBase实例 - RetCode rc = stream->Init(streamInfo); - return RC_OK; - } - ``` - -7. 配置流 - - CommitStreams()是配置流的接口,必须在创建流之后调用,其主要作用是初始化Pipeline和创建Pipeline。 - - ``` - CamRetCode StreamOperatorImpl::CommitStreams(OperationMode mode, const std::shared_ptr& modeSetting) - { - auto cameraDevice = cameraDevice_.lock(); - if (cameraDevice == nullptr) { - CAMERA_LOGE("camera device closed."); - return CAMERA_CLOSED; - } - std::shared_ptr PipelineCore = - std::static_pointer_cast(cameraDevice)->GetPipelineCore(); - if (PipelineCore == nullptr) { - CAMERA_LOGE("get pipeline core failed."); - return CAMERA_CLOSED; - } - - streamPipeCore_ = PipelineCore->GetStreamPipelineCore(); - if (streamPipeCore_ == nullptr) { - CAMERA_LOGE("get stream pipeline core failed."); - return DEVICE_ERROR; - } - - RetCode rc = streamPipeCore_->Init(); // 对pipelinecore的初始化 - if (rc != RC_OK) { - CAMERA_LOGE("stream pipeline core init failed."); - return DEVICE_ERROR; - } - rc = streamPipeCore_->CreatePipeline(mode); // 创建一个pipeline - if (rc != RC_OK) { - CAMERA_LOGE("create pipeline failed."); - return INVALID_ARGUMENT; - } - return NO_ERROR; - } - ``` - -8. 捕获图像 - - 在调用Capture()接口前需要先填充CaptureInfo结构体,具体内容如下: - - ``` - using CaptureInfo = struct _CaptureInfo { - std::vector streamIds_; //需要Capture的streamIds - std::shared_ptr captureSetting_; // 这里填充camera ability 可通过CameraHost 的GetCameraAbility()接口获取 - bool enableShutterCallback_; - }; - ``` - - StreamOperatorImpl中的Capture方法主要调用CreateCapture()接口去捕获数据流: - - ``` - CamRetCode StreamOperatorImpl::Capture(int captureId, const std::shared_ptr& captureInfo, bool isStreaming) - { - if (!ValidCaptureInfo(captureId, captureInfo)) { - CAMERA_LOGE("capture streamIds is empty. [captureId = %d]", captureId); - return INVALID_ARGUMENT; - } - std::shared_ptr cameraCapture = nullptr; - RetCode rc = CreateCapture(captureId, captureInfo, isStreaming, cameraCapture); - if (rc != RC_OK) { - CAMERA_LOGE("create capture is failed."); - return DEVICE_ERROR; - } - - { - std::unique_lock lock(captureMutex_); - camerCaptureMap_.insert(std::make_pair(captureId, cameraCapture)); - } - - rc = StartThread(); - if (rc != RC_OK) { - CAMERA_LOGE("preview start failed."); - return DEVICE_ERROR; - } - return NO_ERROR; - } - ``` - -9. 取消捕获和释放离线流 - - StreamOperatorImpl类中的CancelCapture()接口的主要作用是根据captureId取消数据流的捕获。 - - ``` - CamRetCode StreamOperatorImpl::CancelCapture(int captureId) - { - auto itr = camerCaptureMap_.find(captureId); //根据captureId 在Map中查找对应的CameraCapture对象 - RetCode rc = itr->second->Cancel(); //调用CameraCapture中Cancel方法结束数据捕获 - std::unique_lock lock(captureMutex_); - camerCaptureMap_.erase(itr); //擦除该CameraCapture对象 - return NO_ERROR; - } - ``` - - StreamOperatorImpl类中的ReleaseStreams接口的主要作用是释放之前通过CreateStream()和CommitStreams()接口创建的流,并销毁Pipeline。 - - ``` - CamRetCode StreamOperatorImpl::ReleaseStreams(const std::vector& streamIds) - { - RetCode rc = DestroyStreamPipeline(streamIds); //销毁该streamIds 的pipeline - rc = DestroyHostStreamMgr(streamIds); - rc = DestroyStreams(streamIds); //销毁该streamIds 的 Stream - return NO_ERROR; - } - ``` - -10. 关闭Camera设备 - - 调用CameraDeviceImpl中的Close()来关闭CameraDevice,该接口调用deviceManager中的PowerDown()来给设备下电。 - - -## 开发实例 - -在/drivers/peripheral/camera/hal/init目录下有一个关于Camera的demo,开机后会在/system/bin下生成可执行文件ohos_camera_demo,该demo可以完成camera的预览,拍照等基础功能。下面我们就以此demo为例讲述怎样用HDI接口去编写预览PreviewOn()和拍照CaptureON()的用例。 - -1. 在main函数中构造一个Hos3516Demo对象,该对象中有对camera初始化、启停流、释放等控制的方法。下面mainDemo->InitSensors()函数为初始化CameraHost,mainDemo->InitCameraDevice()函数为初始化CameraDevice。 - - ``` - int main(int argc, char** argv) - { - RetCode rc = RC_OK; - auto mainDemo = std::make_shared(); - rc = mainDemo->InitSensors(); // 初始化CameraHost - if (rc == RC_ERROR) { - CAMERA_LOGE("main test: mainDemo->InitSensors() error\n"); - return -1; - } - - rc = mainDemo->InitCameraDevice(); // 初始化CameraDevice - if (rc == RC_ERROR) { - CAMERA_LOGE("main test: mainDemo->InitCameraDevice() error\n"); - return -1; - } - - rc = PreviewOn(0, mainDemo); // 配流和启流 - if (rc != RC_OK) { - CAMERA_LOGE("main test: PreviewOn() error demo exit"); - return -1; - } - - ManuList(mainDemo, argc, argv); // 打印菜单到控制台 - - return RC_OK; - } - ``` - - 初始化CameraHost函数实现如下,这里调用了HDI接口ICameraHost::Get()去获取demoCameraHost,并对其设置回调函数。 - - ``` - RetCode Hos3516Demo::InitSensors() - { - demoCameraHost_ = ICameraHost::Get(DEMO_SERVICE_NAME); - if (demoCameraHost_ == nullptr) { - CAMERA_LOGE("demo test: ICameraHost::Get error"); - return RC_ERROR; - } - - hostCallback_ = new CameraHostCallback(); - rc = demoCameraHost_->SetCallback(hostCallback_); - return RC_OK; - } - ``` - - 初始化CameraDevice函数实现如下,这里调用了GetCameraIds(cameraIds_),GetCameraAbility(cameraId, ability_),OpenCamera(cameraIds_.front(), callback, demoCameraDevice_)等接口实现了demoCameraHost的获取。 - - ``` - RetCode Hos3516Demo::InitCameraDevice() - { - (void)demoCameraHost_->GetCameraIds(cameraIds_); - const std::string cameraId = cameraIds_.front(); - demoCameraHost_->GetCameraAbility(cameraId, ability_); - - sptr callback = new CameraDeviceCallback(); - rc = demoCameraHost_->OpenCamera(cameraIds_.front(), callback, demoCameraDevice_); - return RC_OK; - } - ``` - -2. PreviewOn()接口包含配置流、开启预览流和启动Capture动作。该接口执行完成后Camera预览通路已经开始运转并开启了两路流,一路流是preview,另外一路流是capture或者video,两路流中仅对preview流进行capture动作。 - - ``` - static RetCode PreviewOn(int mode, const std::shared_ptr& mainDemo) - { - rc = mainDemo->StartPreviewStream(); // 配置preview流 - if (mode == 0) { - rc = mainDemo->StartCaptureStream(); // 配置capture流 - } else { - rc = mainDemo->StartVideoStream(); // 配置video流 - } - - rc = mainDemo->CaptureON(STREAM_ID_PREVIEW, CAPTURE_ID_PREVIEW, CAPTURE_PREVIEW); // 将preview流capture - return RC_OK; - } - ``` - - StartCaptureStream()、StartVideoStream()和StartPreviewStream()接口都会调用CreateStream()接口,只是传入的参数不同。 - - ``` - RetCode Hos3516Demo::StartVideoStream() - { - RetCode rc = RC_OK; - if (isVideoOn_ == 0) { - isVideoOn_ = 1; - rc = CreateStream(STREAM_ID_VIDEO, streamCustomerVideo_, VIDEO); // 如需启preview或者capture流更改该接口参数即可。 - } - return RC_OK; - } - ``` - - CreateStream()方法调用HDI接口去配置和创建流,首先调用HDI接口去获取StreamOperation对象,然后创建一个StreamInfo。调用CreateStreams()和CommitStreams()实际创建流并配置流。 - - ``` - RetCode Hos3516Demo::CreateStreams(const int streamIdSecond, StreamIntent intent) - { - std::vector> streamInfos; - std::vector>().swap(streamInfos); - GetStreamOpt(); // 获取StreamOperator对象 - std::shared_ptr previewStreamInfo = std::make_shared(); - SetStreamInfo(previewStreamInfo, streamCustomerPreview_, STREAM_ID_PREVIEW, PREVIEW); // 填充StreamInfo - if (previewStreamInfo->bufferQueue_ == nullptr) { - CAMERA_LOGE("demo test: CreateStream CreateProducer(); is nullptr\n"); - return RC_ERROR; - } - streamInfos.push_back(previewStreamInfo); - - std::shared_ptr secondStreamInfo = std::make_shared(); - if (streamIdSecond == STREAM_ID_CAPTURE) { - SetStreamInfo(secondStreamInfo, streamCustomerCapture_, STREAM_ID_CAPTURE, intent); - } else { - SetStreamInfo(secondStreamInfo, streamCustomerVideo_, STREAM_ID_VIDEO, intent); - } - - if (secondStreamInfo->bufferQueue_ == nullptr) { - CAMERA_LOGE("demo test: CreateStreams CreateProducer() secondStreamInfo is nullptr\n"); - return RC_ERROR; - } - streamInfos.push_back(secondStreamInfo); - - rc = streamOperator_->CreateStreams(streamInfos); // 创建流 - if (rc != Camera::NO_ERROR) { - CAMERA_LOGE("demo test: CreateStream CreateStreams error\n"); - return RC_ERROR; - } - - rc = streamOperator_->CommitStreams(Camera::NORMAL, ability_); - if (rc != Camera::NO_ERROR) { - CAMERA_LOGE("demo test: CreateStream CommitStreams error\n"); - std::vector streamIds = {STREAM_ID_PREVIEW, streamIdSecond}; - streamOperator_->ReleaseStreams(streamIds); - return RC_ERROR; - } - return RC_OK; - } - ``` - - CaptureON()接口调用streamOperator的Capture()方法获取camera数据并轮转buffer,拉起一个线程接收相应类型的数据。 - - ``` - RetCode Hos3516Demo::CaptureON(const int streamId, const int captureId, CaptureMode mode) - { - std::shared_ptr captureInfo = std::make_shared(); // 创建并填充CaptureInfo - captureInfo->streamIds_ = {streamId}; - captureInfo->captureSetting_ = ability_; - captureInfo->enableShutterCallback_ = false; - - int rc = streamOperator_->Capture(captureId, captureInfo, true); // 实际capture开始,buffer轮转开始 - if (mode == CAPTURE_PREVIEW) { - streamCustomerPreview_->ReceiveFrameOn(nullptr); // 创建预览线程接收递上来的buffer - } else if (mode == CAPTURE_SNAPSHOT) { - streamCustomerCapture_->ReceiveFrameOn([this](void* addr, const uint32_t size) { // 创建capture线程通过StoreImage回调接收递上来的buffer - StoreImage(addr, size); - }); - } else if (mode == CAPTURE_VIDEO) { - OpenVideoFile(); - streamCustomerVideo_->ReceiveFrameOn([this](void* addr, const uint32_t size) {// 创建Video线程通过StoreVideo回调接收递上来的buffer - StoreVideo(addr, size); - }); - } - return RC_OK; - } - ``` - -3. ManuList()函数从控制台通过fgets()接口获取字符,不同字符所对应demo支持的功能不同,并打印出该demo所支持功能的菜单。 - - ``` - static void ManuList(const std::shared_ptr& mainDemo, - const int argc, char** argv) - { - int idx, c; - int awb = 1; - constexpr char shortOptions[] = "h:cwvaqof:"; - c = getopt_long(argc, argv, shortOptions, longOptions, &idx); - while(1) { - switch (c) { - case 'h': - c = PutMenuAndGetChr(); // 打印菜单 - break; - - case 'f': - FlashLightTest(mainDemo); // 手电筒功能测试 - c = PutMenuAndGetChr(); - break; - case 'o': - OfflineTest(mainDemo); // Offline功能测试 - c = PutMenuAndGetChr(); - break; - case 'c': - CaptureTest(mainDemo); // Capture功能测试 - c = PutMenuAndGetChr(); - break; - case 'w': // AWB功能测试 - if (awb) { - mainDemo->SetAwbMode(OHOS_CAMERA_AWB_MODE_INCANDESCENT); - } else { - mainDemo->SetAwbMode(OHOS_CAMERA_AWB_MODE_OFF); - } - awb = !awb; - c = PutMenuAndGetChr(); - break; - case 'a': // AE功能测试 - mainDemo->SetAeExpo(); - c = PutMenuAndGetChr(); - break; - case 'v': // Video功能测试 - VideoTest(mainDemo); - c = PutMenuAndGetChr(); - break; - case 'q': // 退出demo - PreviewOff(mainDemo); - mainDemo->QuitDemo(); - exit(EXIT_SUCCESS); - - default: - CAMERA_LOGE("main test: command error please retry input command"); - c = PutMenuAndGetChr(); - break; - } - } - } - ``` - - PutMenuAndGetChr()接口打印了demo程序的菜单,并调用fgets()等待从控制台输入命令,内容如下: - - ``` - static int PutMenuAndGetChr(void) - { - constexpr uint32_t inputCount = 50; - int c = 0; - char strs[inputCount]; - Usage(stdout); - CAMERA_LOGD("pls input command(input -q exit this app)\n"); - fgets(strs, inputCount, stdin); - - for (int i = 0; i < inputCount; i++) { - if (strs[i] != '-') { - c = strs[i]; - break; - } - } - return c; - } - ``` - - 控制台输出菜单详情如下: - - ``` - "Options:\n" - "-h | --help Print this message\n" - "-o | --offline stream offline test\n" - "-c | --capture capture one picture\n" - "-w | --set WB Set white balance Cloudy\n" - "-v | --video capture Viedeo of 10s\n" - "-a | --Set AE Set Auto exposure\n" - "-f | --Set Flashlight Set flashlight ON 5s OFF\n" - "-q | --quit stop preview and quit this app\n"); - ``` - - demo中其他功能会调用不同的HDI接口去实现,与PreviewOn()接口类似,这里不再赘述,具体详情可以参见[ohos_camera_demo](https://gitee.com/openharmony/drivers_peripheral/tree/master/camera/hal/init)。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/03.\347\274\226\350\257\221\346\236\204\345\273\272/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\347\274\226\350\257\221\346\236\204\345\273\272\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/03.\347\274\226\350\257\221\346\236\204\345\273\272/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\347\274\226\350\257\221\346\236\204\345\273\272\346\214\207\345\257\274.md" deleted file mode 100644 index e40ce9a063e0225991f38263c66f62369d7ccca1..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/03.\347\274\226\350\257\221\346\236\204\345\273\272/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\347\274\226\350\257\221\346\236\204\345\273\272\346\214\207\345\257\274.md" +++ /dev/null @@ -1,1012 +0,0 @@ ---- -title: 轻量和小型系统编译构建指导 -permalink: /pages/01050301 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:24 ---- -# 轻量和小型系统编译构建指导 - -- [概述](#section10958256161119) - - [基本概念](#section1732301411128) - - [目录结构](#section1588744014121) - - [构建流程](#section15761735134) - -- [配置规则](#section2345183962710) - - [组件](#section142532518308) - - [芯片解决方案](#section121501451143710) - - [产品解决方案](#section134549283435) - -- [使用指导](#section13754457192211) - - [前提条件](#section31651120233) - - [hb工具使用说明](#section1133304172313) - - [新增组件](#section167110415315) - - [新增芯片解决方案](#section1474718565412) - - [新增产品解决方案](#section1097623294220) - -- [常见问题](#section19909721104319) - - [编译构建过程中,提示“usr/sbin/ninja: invalid option -- w”](#section138233464318) - - [编译构建过程中,提示“/usr/bin/ld: cannot find -lncurses”](#section151033911442) - - [编译构建过程中,提示“line 77: mcopy: command not found”](#section19811838104418) - - [编译构建过程中,提示“riscv32-unknown-elf-gcc: error trying to exec 'cc1': execvp: No such file or directory”](#section03111118451) - - [编译构建过程中,提示“No module named 'Crypto'”](#section69981127125013) - - [编译构建过程中,提示“xx.sh : xx unexpected operator”](#section967617530505) - - -## 概述 - -一个基于gn和ninja的构建系统,以支持OpenHarmony组件化开发为目标,提供以下基本功能: - -- 支持按组件拼装产品并编译。 - -- 独立构建芯片解决方案厂商源码。 -- 独立构建单个组件。 - -### 基本概念 - -在使用编译构建子系统前,应了解如下基本概念: - -- 子系统 - - 子系统是一个逻辑概念,它由一个或多个具体的组件组成。OpenHarmony整体遵从分层设计,从下向上依次为:内核层、系统服务层、框架层和应用层。系统功能按照“系统 \> 子系统 \> 组件”逐级展开,在多设备部署场景下,支持根据实际需求裁剪某些非必要的子系统或组件。 - - -- 组件 - - 系统最小的可复用、可配置、可裁剪的功能单元。组件具备目录独立可并行开发、可独立编译、可独立测试的特征。 - -- gn - - Generate ninja的缩写,用于产生ninja文件。 - -- ninja - - ninja是一个专注于速度的小型构建系统。 - -- hb - - OpenHarmony的命令行工具,用来执行编译命令。 - - -### 目录结构 - -``` -build/lite -├── components # 组件描述文件 -├── figure # readme中的图片 -├── hb # hb pip安装包源码 -├── make_rootfs # 文件系统镜像制作脚本 -├── config # 编译配置项 -│ ├── component # 组件相关的模板定义 -│ ├── kernel # 内核相关的编译配置 -│ └── subsystem # 子系统编译配置 -├── platform # ld脚本 -├── testfwk # 测试编译框架 -└── toolchain # 编译工具链配置,包括:编译器路径、编译选项、链接选项等 -``` - -### 构建流程 - -编译构建流程如[图1 ](#fig9744112715161)所示,主要分设置和编译两步: - -**图 1** 编译构建流程 -![](/images/device-dev/subsystems/figure/编译构建流程.jpg "编译构建流程") - -1. hb set: 设置OpenHarmony源码目录和要编译的产品。 -2. hb build: 编译产品、开发板或者组件。编译主要过程如下: - - 读取编译配置:根据产品选择的开发板,读取开发板config.gni文件内容,主要包括编译工具链、编译链接命令和选项等。 - - 调用gn:调用gn gen命令,读取产品配置生成产品解决方案out目录和ninja文件。 - - 调用ninja:调用ninja -C out/board/product启动编译。 - - 系统镜像打包:将组件编译产物打包,设置文件属性和权限,制作文件系统镜像。 - - -## 配置规则 - -为了实现芯片解决方案、产品解决方案与OpenHarmony是解耦的、可插拔的,组件、芯片解决方案和产品解决方案的路径、目录树和配置需遵循一定的规则,具体如下: - -### 组件 - -组件源码路径命名规则为:**\{领域\}/\{子系统\}/\{组件\}**,组件目录树规则如下: - ->![](/images/device-dev/public_sys-resources/icon-caution.gif) **注意:** ->组件的名称、源码路径、功能简介、是否必选、编译目标、RAM、ROM、编译输出、已适配的内核、可配置的特性和依赖等属性定义在build/lite/components目录下对应子系统的json文件中,新增组件时需要在对应子系统json文件中添加相应的组件定义。产品所配置的组件必须在某个子系统中被定义过,否则会校验失败。 - -``` -component -├── interfaces -│ ├── innerkits # 系统内接口,组件间使用 -│ └── kits # 应用接口,应用开发者使用 -├── frameworks # framework实现 -├── services # service实现 -└── BUILD.gn # 组件编译脚本 -``` - -以泛sensor子系统的sensor服务组件为例,组件属性定义描述文件字段说明如下: - -``` -{ - "components": [ - { - "component": "sensor_lite", # 组件名称 - "description": "Sensor services", # 组件一句话功能描述 - "optional": "true", # 组件是否为最小系统必选 - "dirs": [ # 组件源码路径 - "base/sensors/sensor_lite" - ], - "targets": [ # 组件编译入口 - "//base/sensors/sensor_lite/services:sensor_service" - ], - "rom": "92KB", # 组件ROM值 - "ram": "~200KB", # 组件RAM估值 - "output": [ "libsensor_frameworks.so" ], # 组件编译输出 - "adapted_kernel": [ "liteos_a" ], # 组件已适配的内核 - "features": [], # 组件可配置的特性 - "deps": { - "components": [ # 组件依赖的其他组件 - "samgr_lite", - "ipc_lite" - - ], - "third_party": [ # 组件依赖的三方开源软件 - "bounds_checking_function" - ] - } - } - ] -} -``` - -组件BUILD.gn的编写建议如下: - -- 编译目标名称与组件一致。 -- 组件对外可配置的特性变量需声明在该组件BUILD.gn中,特性变量命名规则:ohos\_\{subsystem\}\_\{component\}\_\{feature\}。特性在组件描述中也需要同步定义,在产品配置文件config.json中按需配置。 -- 宏定义规则:OHOS\_\{SUBSYSTEM\}\_\{COMPONENT\}\_\{FEATURE\} - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >组件的编译脚本语言为gn,gn的基本用法请见https://gn.googlesource.com/gn/+/master/docs/quick_start.md。 组件即为gn定义的编译目标,可以为静态库、动态库、可执行文件或group。 - - -以图形的UI组件为例,foundation/graphic/ui/BUILD.gn文件如下: - -``` - # 声明组件可配置的特性 - declare_args() { - enable_ohos_graphic_ui_animator = false # 动效特性开关 - ohos_ohos_graphic_ui_font = "vector" # 可配置的字体类型,vector或者bitmap - } - - # 组件基础功能 - shared_library("base") { - sources = [ - ...... - ] - include_dirs = [ - ...... - ] - } - - # 仅在animator开启时编译 - if(enable_ohos_graphic_ui_animator ) { - shared_library("animator") { - sources = [ - ...... - ] - include_dirs = [ - ...... - ] - deps = [ :base ] - } - } - ...... - # target名称建议与组件名称一致, 组件target类型可以是executable(bin文件),shared_library(动态库.so),static_library(静态库.a),group等等 - executable("ui") { - deps = [ - ":base" - ] - - # animator特性由产品配置 - if(enable_ohos_graphic_ui_animator ) { - deps += [ - "animator" - ] - } - } -``` - -### 芯片解决方案 - -- 芯片解决方案是指基于某款开发板的完整解决方案,包含驱动、设备侧接口适配、开发板sdk等。 -- 芯片解决方案是一个特殊的组件,源码路径规则为:**device/\{芯片解决方案厂商\}/\{开发板\}**。 -- 芯片解决方案组件会随产品选择的开发板默认编译。 - -芯片解决方案目录树规则如下: - -``` -device -└── company # 芯片解决方案厂商 - └── board # 开发板名称 - ├── BUILD.gn # 编译脚本 - ├── hals # OS南向接口适配 - ├── linux # 可选,linux内核版本 - │ └── config.gni # linux版本编译配置 - └── liteos_a # 可选,liteos内核版本 - └── config.gni # liteos_a版本编译配置 -``` - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->config.gni为开发板编译相关的配置,编译时会采用该配置文件中的参数编译所有OS组件,编译阶段系统全局可见。 - -config.gni的关键字段介绍如下: - -``` -kernel_type: 开发板使用的内核类型,例如:“liteos_a”, “liteos_m”, “linux”。 -kernel_version: 开发使用的内核版本,例如:“4.19”。 -board_cpu: 开发板CPU类型,例如:“cortex-a7”, “riscv32”。 -board_arch: 开发芯片arch, 例如: “armv7-a”, “rv32imac”。 -board_toolchain: 开发板自定义的编译工具链名称,例如:“gcc-arm-none-eabi”。若为空,则使用默认为ohos-clang。 -board_toolchain_prefix:编译工具链前缀,例如:“gcc-arm-none-eabi”。 -board_toolchain_type: 编译工具链类型,目前支持gcc和clang。例如:“gcc” ,“clang”。 -board_cflags: 开发板配置的c文件编译选项。 -board_cxx_flags: 开发板配置的cpp文件编译选项。 -board_ld_flags: 开发板配置的链接选项。 -``` - -### 产品解决方案 - -产品解决方案为基于开发板的完整产品,主要包含产品对OS的适配、组件拼装配置、启动配置和文件系统配置等。产品解决方案的源码路径规则为:**vendor/\{产品解决方案厂商\}/\{产品名称\}**_。_产品解决方案也是一个特殊的组件。 - -产品解决方案的目录树规则如下: - -``` -vendor -└── company # 产品解决方案厂商 - ├── product # 产品名称 - │ ├── init_configs - │ │ ├── etc # init进程启动配置(可选,仅linux内核需要) - │ │ └── init.cfg # 系统服务启动配置 - │ ├── hals # 产品解决方案OS适配 - │ ├── BUILD.gn # 产品编译脚本 - │ └── config.json # 产品配置文件 - │ └── fs.yml # 文件系统打包配置 - └── ...... -``` - ->![](/images/device-dev/public_sys-resources/icon-caution.gif) **注意:** ->**新增产品须按如上的规则创建目录和文件,编译构建系统将按该规则扫描已配置的产品。** - -关键的目录和文件详细介绍如下: - -1. **vendor/company/product/init\_configs/etc** - - 该文件夹中包含rcS脚本,Sxxx脚本和fstab脚本。init进程在启动系统服务之前执行这些脚本。执行的流程为“rcS-\>fstab-\>S00-xxx“。Sxxx脚本中的内容与开发板和产品需要有关,主要包括设备节点的创建、创建目录、扫描设备节点、修改文件权限等等。这些文件在产品编译的BUILD.gn中按需拷贝到产品out目录中,最终打包到rootfs镜像中。 - -2. **vendor/company/product/init\_configs/init.cfg** - - init进程启动服务的配置文件,当前支持解析的命令有: - - - start: 启动某个服务 - - mkdir: 创建文件夹 - - chmod: 修改指定路径/文件的权限 - - chown: 修改指定路径/文件的属组 - - mount: 挂载命令 - - 该文件中的各个字段的解释如下: - - ``` - { - "jobs" : [{ # job数组,一个job对应一个命令集合。job的执行顺序:pre-init -> init -> post-init。 - "name" : "pre-init", - "cmds" : [ - "mkdir /storage/data", # 创建目录 - "chmod 0755 /storage/data", # 修改权限,权限值的格式为0xxx, 如0755 - "mkdir /storage/data/log", - "chmod 0755 /storage/data/log", - "chown 4 4 /storage/data/log", # 修改属组,第一个数字为uid, 第二个数字为gid - ...... - "mount vfat /dev/mmcblock0 /sdcard rw,umask=000" # 挂载,格式为: mount [文件系统类型] [source] [target] [flags] [data] - # 其中flags仅支持:nodev、noexec、nosuid和rdonly - ] - }, { - "name" : "init", - "cmds" : [ # 按cmds数组顺序启动启动服务 - "start shell", # 注意:start与服务名称之间有且只有一个空格 - ...... - "start service1" - ] - }, { - "name" : "post-init", # 最后执行的job, init进程启动完成后的处理(如驱动初始化后再mount设备) - "cmds" : [] - } - ], - "services" : [{ # service数组,一个service对应一个进程 - "name" : "shell", # 服务名称 - "path" : ["/sbin/getty", "-n", "-l", "/bin/sh", "-L", "115200", "ttyS000", "vt100"], # 可执行文件全路径,path必须为第一个元素 - "uid" : 0, # 进程的uid,须与二进制文件的uid保持一致 - "gid" : 0, # 进程的gid,须与二进制文件的gid保持一致 - "once" : 0, # 是否为一次性进程,1:进程退出后,init不在重新拉起。0:常驻进程,进程若退出,init将重新拉起 - "importance" : 0, # 是否为关键进程,1:是关键进程,若进程退出,init将会重启单板。0:非关键进程,若进程退出,init不会重启单板 - "caps" : [4294967295] - }, - ...... - ] - } - ``` - -3. **vendor/company/product/init\_configs/hals** - - 解决方案厂商对OS的适配,需要实现的接口请见各个组件的readme说明文档。 - -4. **vendor/company/product/config.json** - - config.json为编译构建的主入口,包含了开发板、OS组件和内核等配置信息。 - - 以基于hispark\_taurus开发板的ipcamera产品为例,配置文件如下: - - ``` - { - "product_name": "ipcamera", # 产品名称 - "version": "3.0", # config.json的版本号, 固定"3.0" - "type": "small", # 系统类型, 可选[mini, small, standard] - "ohos_version": "OpenHarmony 1.0", # 选择的OS版本 - "device_company": "hisilicon", # 芯片厂商 - "board": "hispark_taurus", # 开发板名称 - "kernel_type": "liteos_a", # 选择的内核类型 - "kernel_version": "3.0.0", # 选择的内核版本 - "subsystems": [ - { - "subsystem": "aafwk", # 选择的子系统 - "components": [ - { "component": "ability", "features":[ "enable_ohos_appexecfwk_feature_ability = true" ] } # 选择的组件和组件特性配置 - ] - }, - { - ...... - } - ...... - 更多子系统和组件 - } - } - ``` - -5. **vendor/company/product/fs.yml** - - 该文件用于配置文件系统镜像制作过程,将编译产物打包成文件系统镜像,比如用户态根文件系统rootfs.img和可读写的userfs.img。它由多个列表组成,每个列表对应一个文件系统。字段说明如下: - - ``` - fs_dir_name: 必填,声明文件系统文件名, 如rootfs、userfs - fs_dirs: 选填,配置out下文件目录与文件系统文件目录的映射关系,每个文件目录对应一个列表 - source_dir: 选填,out下目标文件目录,若缺失则将根据target_dir在文件系统下创建空目录 - target_dir: 必填,文件系统下对应文件目录 - ignore_files:选填,声明拷贝忽略文件 - dir_mode: 选填,文件目录权限,默认755 - file_mode: 选填,该文件目录下所有文件的权限,默认555 - fs_filemode: 选填,配置需要特殊声明权限的文件,每个文件对应一个列表 - file_dir: 必填,文件系统下具体文件路径 - file_mode: 必填,文件权限声明 - fs_symlink: 选填,配置文件系统软连接 - fs_make_cmd: 必填,配置需要制作文件系统脚本,OS提供的脚本在build/lite/make_rootfs下, 支持linux,liteos内核和ext4、jffs2、vfat格式。也支持芯片解决方案厂商自定义。 - fs_attr: 选填,根据配置项动态调整文件系统 - ``` - - 其中fs\_symlink、fs\_make\_cmd字段支持以下变量: - - - $\{root\_path\} - - 代码根目录,对应gn的$\{ohos\_root\_path\} - - - $\{out\_path\} - - 产品out目录,对应gn的$\{root\_out\_dir\} - - - $\{fs\_dir\} - - 文件系统目录,由以下变量拼接而成 - - - $\{root\_path\} - - $\{fs\_dir\_name\} - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >fs.yml是可选的,对于没有文件系统的设备可不配置。 - -6. **vendor/company/product/BUILD.gn** - - 产品编译的入口,主要用于编译解决方案厂商源码和拷贝启动配置文件。如果某个产品被选择为要编译的产品,那么对应产品目录下的BUILD.gn会默认编译。一个典型的产品编译BUILD.gn应该如下: - - ``` - group("product") { # target名称需与product名称即三级目录名称一致 - deps = [] - # 拷贝init配置 - deps += [ "init_configs" ] - # 其他 - ...... - } - ``` - - -## 使用指导 - -### 前提条件 - -开发环境需安装gn、ninja构建工具、python 3.7.4及以上和hb。安装方法请见[搭建系统基础环境](/pages/extra/770961/)。 - -### hb工具使用说明 - -hb是OpenHarmony的命令行工具,用来执行编译命令。以下对hb的常用命令进行说明。 - -**hb set** - -``` -hb set -h -usage: hb set [-h] [-root [ROOT_PATH]] [-p] - -optional arguments: - -h, --help show this help message and exit - -root [ROOT_PATH], --root_path [ROOT_PATH] - Set OHOS root path - -p, --product Set OHOS board and kernel -``` - -- hb set 后无参数,进入默认设置流程 -- hb set -root dir可直接设置代码根目录 -- hb set -p设置要编译的产品 - -**hb env** - -查看当前设置信息 - -``` -hb env -[OHOS INFO] root path: xxx -[OHOS INFO] board: hispark_taurus -[OHOS INFO] kernel: liteos -[OHOS INFO] product: ipcamera -[OHOS INFO] product path: xxx/vendor/hisilicon/ipcamera -[OHOS INFO] device path: xxx/device/hisilicon/hispark_taurus/sdk_linux_4.19 -``` - -**hb build** - -``` -hb build -h -usage: hb build [-h] [-b BUILD_TYPE] [-c COMPILER] [-t [TEST [TEST ...]]] - [--dmverity] [--tee] [-p PRODUCT] [-f] [-n] - [-T [TARGET [TARGET ...]]] [-v] [-shs] [--patch] - [component [component ...]] - -positional arguments: - component name of the component - -optional arguments: - -h, --help show this help message and exit - -b BUILD_TYPE, --build_type BUILD_TYPE - release or debug version - -c COMPILER, --compiler COMPILER - specify compiler - -t [TEST [TEST ...]], --test [TEST [TEST ...]] - compile test suit - --dmverity Enable dmverity - --tee Enable tee - -p PRODUCT, --product PRODUCT - build a specified product with - {product_name}@{company}, eg: camera@huawei - -f, --full full code compilation - -n, --ndk compile ndk - -T [TARGET [TARGET ...]], --target [TARGET [TARGET ...]] - Compile single target - -v, --verbose show all command lines while building - -shs, --sign_haps_by_server - sign haps by server - --patch apply product patch before compiling - - --dmverity Enable dmverity - -p PRODUCT, --product PRODUCT - build a specified product with - {product_name}@{company}, eg: ipcamera@hisilcon - -f, --full full code compilation - -T [TARGET [TARGET ...]], --target [TARGET [TARGET ...]] - Compile single target -``` - -- hb build后无参数,会按照设置好的代码路径、产品进行编译,编译选项使用与之前保持一致。-f 选项将删除当前产品所有编译产品,等同于hb clean + hb build. -- hb build \{component\_name\}:基于设置好的产品对应的单板、内核,单独编译组件(e.g.:hb build kv\_store\)。 -- hb build -p ipcamera@hisilicon:免set编译产品,该命令可以跳过set步骤,直接编译产品。 -- 在device/device\_company/board下单独执行hb build会进入内核选择界面,选择完成后会根据当前路径的单板、选择的内核编译出仅包含内核、驱动的镜像。 - -**hb clean** - -清除out目录对应产品的编译产物,仅保留args.gn、build.log。清除指定路径可输入路径参数:hb clean out/board/product,默认将清除当前hb set的产品对应out路径。 - -``` -hb clean -usage: hb clean [-h] [out_path] - -positional arguments: - out_path clean a specified path. - -optional arguments: - -h, --help show this help message and exit -``` - -### 新增组件 - -本小节介绍如何新增一个组件,首先确定组件归属的子系统和组件名称,然后按如下步骤新增: - -1. 源码开发完成后,添加组件编译脚本。 - - 以编译组件hello\_world可执行文件为例,applications/sample/hello\_world/BUILD.gn可以写为: - - ``` - executable("hello_world") { - include_dirs = [ - "include", - ] - sources = [ - "src/hello_world.c" - ] - } - ``` - - 如上编译脚本,可编译出一个可在OpenHarmony上运行的名为hello\_world的可执行文件。 - - 单独编译该组件,hb set任意选择一款产品,然后使用-T选项单独编译组件: - - ``` - hb build -f -T //applications/sample/hello_world - ``` - - 组件在开发板上功能验证完成后,可按[步骤2\~4](#li11471037297)将组件配置到产品中。 - -2. 添加组件描述。 - - 组件描述位于build/lite/components下,新增的组件需加入对应子系统的json文件中。一个组件描述必选的字段有: - - - component:组件名称。 - - description:组件的一句话功能描述。 - - optional:组件是否为系统可选。 - - dirs:组件源码路径。 - - targets:组件编译入口。 - - 以将hello\_world组件加入应用子系统为例,在applications.json中添加hello\_world对象: - - ``` - { - "components": [ - { - "component": "hello_world", - "description": "Hello world.", - "optional": "true", - "dirs": [ - "applications/sample/hello_world" - ], - "targets": [ - "//applications/sample/hello_world" - ] - }, - ... - ] - } - ``` - -3. 将组件配置到产品。 - - 产品的配置文件config.json位于vendor/company/product/下,产品配置文件需包含产品名称、OpenHarmony版本号、device厂商、开发板、内核类型、内核版本号,以及配置的子系统和组件。以将hello\_world组件加入产品配置文件my\_product.json中为例,加入hello\_wolrd对象: - - ``` - { - "product_name": "hello_world_test", - "ohos_version": "OpenHarmony 1.0", - "device_company": "hisilicon", - "board": "hispark_taurus", - "kernel_type": "liteos_a", - "kernel_version": "1.0.0", - "subsystems": [ - { - "subsystem": "applications", - "components": [ - { "component": "hello_world", "features":[] } - ] - }, - ... - ] - } - ``` - -4. 编译产品。 - - 1. 代码根目录输入hb set选择对应产品。 - - 2. 执行hb build。 - - -### 新增芯片解决方案 - -编译构建支持添加新的芯片解决方案厂商,具体步骤如下: - -1. 创建芯片解决方案目录。 - - 按照[芯片解决方案配置规则](#section2345183962710)创建目录,以芯片厂商realtek的“rtl8720“开发板为例, 在代码根目录执行: - - ``` - mkdir -p device/realtek/rtl8720 - ``` - -2. 创建内核适配目录,并编写开发板编译配置config.gni文件。 - - 以realtek的“rtl8720“开发板的liteos\_a适配为例,device/realtek/rtl8720/liteos\_a/config.gni的内容如下: - - ``` - # Kernel type, e.g. "linux", "liteos_a", "liteos_m". - kernel_type = "liteos_a" - - # Kernel version. - kernel_version = "3.0.0" - - # Board CPU type, e.g. "cortex-a7", "riscv32". - board_cpu = "real-m300" - - # Board arch, e.g. "armv7-a", "rv32imac". - board_arch = "" - - # Toolchain name used for system compiling. - # E.g. gcc-arm-none-eabi, arm-linux-harmonyeabi-gcc, ohos-clang, riscv32-unknown-elf. - # Note: The default toolchain is "ohos-clang". It's not mandatory if you use the default toochain. - board_toolchain = "gcc-arm-none-eabi" - - # The toolchain path instatlled, it's not mandatory if you have added toolchian path to your ~/.bashrc. - board_toolchain_path = - rebase_path("//prebuilts/gcc/linux-x86/arm/gcc-arm-none-eabi/bin", - root_build_dir) - - # Compiler prefix. - board_toolchain_prefix = "gcc-arm-none-eabi-" - - # Compiler type, "gcc" or "clang". - board_toolchain_type = "gcc" - - # Board related common compile flags. - board_cflags = [] - board_cxx_flags = [] - board_ld_flags = [] - ``` - -3. 编写编译脚本。 - - 在开发板目录下创建BUILD.gn,target名称应与开发板名称一致。以realtek的rtl8720开发板为例,device/realtek/rtl8720/BUILD.gn内容可以是: - - ``` - group("rtl8720") { # target类型也可以shared_library, static_library, executable - # 具体内容 - ...... - } - ``` - -4. 编译芯片解决方案。 - - 在开发板目录下执行hb build,即可启动芯片解决方案的编译。 - - -### 新增产品解决方案 - -编译构建支持芯片解决方案和组件的灵活拼装,形成定制化的产品解决方案。具体步骤如下: - -1. 创建产品目录 - - 按照[产品解决方案配置规则](#section2345183962710)创建产品目录,以基于“rtl8720“开发板的wifiiot模组为例,在代码根目录执行: - - ``` - mkdir -p vendor/my_company/wifiiot - ``` - -2. 拼装产品 - - 在新建的产品目录下新建config.json文件,以步骤1中的wifiiot为例,vendor/my\_company/wifiiot/config.json可以是: - - ``` - { - "product_name": "wifiiot", # 产品名称 - "version": "3.0", # config.json的版本号, 固定"3.0" - "type": "small", # 系统类型, 可选[mini, small, standard] - "ohos_version": "OpenHarmony 1.0", # 使用的OS版本 - "device_company": "realtek", # 芯片解决方案厂商名称 - "board": "rtl8720", # 开发板名称 - "kernel_type": "liteos_m", # 选择的内核类型 - "kernel_version": "3.0.0", # 选择的内核版本 - "subsystems": [ - { - "subsystem": "kernel", # 选择的子系统 - "components": [ - { "component": "liteos_m", "features":[] } # 选择的组件和组件特性 - ] - }, - ... - { - 更多子系统和组件 - } - ] - } - ``` - - 注意:编译构建系统编译前会对device\_company,board,kernel\_type,kernel\_version、subsystem、component字段进行有效性检查,其中device\_company,board,kernel\_type,kernel\_version应与已知的芯片解决方案匹配,subsystem、component应与build/lite/components下的组件描述匹配。 - -3. 适配OS接口 - - 在产品目录下创建hals目录,并将产品解决方案对OS适配的源码和编译脚本放入该目录下。 - -4. 配置系统服务 - - 在产品目录下创建init\_configs目录,并在init\_configs目录下创建init.cfg文件,按需配置要启动的系统服务。 - -5. 配置init进程(仅linux内核需要) - - 在init\_configs目录下创建etc目录,然后在etc下创建init.d文件夹和fstab文件。最后按产品需求在init.d文件下创建并编辑rcS文件和Sxxx文件。 - -6. 配置文件系统镜像(可选,仅支持文件系统的开发板需要) - - 在产品目录下创建fs.yml文件。fs.yml需按产品实际情况配置,一个典型的fs.yml文件如下: - - ``` - - - fs_dir_name: rootfs # 镜像的名称 - fs_dirs: - - - # 将编译生成的out/my_board/my_product/bin目录下的文件拷贝到rootfs/bin中,并忽略测试bin - source_dir: bin - target_dir: bin - ignore_files: - - Test.bin - - TestSuite.bin - - - # 将编译生成的out/my_board/my_product/libs目录下的文件拷贝到rootfs/lib中,忽略所有.a文件,并设置文件和文件夹的权限为644和755 - source_dir: libs - target_dir: lib - ignore_files: - - .a - dir_mode: 755 - file_mode: 644 - - - source_dir: usr/lib - target_dir: usr/lib - ignore_files: - - .a - dir_mode: 755 - file_mode: 644 - - - source_dir: config - target_dir: etc - - - source_dir: system - target_dir: system - - - source_dir: sbin - target_dir: sbin - - - source_dir: usr/bin - target_dir: usr/bin - - - source_dir: usr/sbin - target_dir: usr/sbin - - - # 创建一个proc空目录 - target_dir: proc - - - target_dir: mnt - - - target_dir: opt - - - target_dir: tmp - - - target_dir: var - - - target_dir: sys - - - source_dir: etc - target_dir: etc - - - source_dir: vendor - target_dir: vendor - - - target_dir: storage - - fs_filemode: - - - file_dir: lib/ld-uClibc-0.9.33.2.so - file_mode: 555 - - - file_dir: lib/ld-2.24.so - file_mode: 555 - - - file_dir: etc/init.cfg - file_mode: 400 - fs_symlink: - - - # 在rootfs/lib下创建软连接ld-musl-arm.so.1 -> libc.so - source: libc.so - link_name: ${fs_dir}/lib/ld-musl-arm.so.1 - - - source: mksh - link_name: ${fs_dir}/bin/sh - - - source: mksh - link_name: ${fs_dir}/bin/shell - fs_make_cmd: - # 使用脚本将rootfs制作为ext4格式的image - - ${root_path}/build/lite/make_rootfs/rootfsimg_linux.sh ${fs_dir} ext4 - - - fs_dir_name: userfs - fs_dirs: - - - source_dir: storage/etc - target_dir: etc - - - source_dir: data - target_dir: data - fs_make_cmd: - - ${root_path}/build/lite/make_rootfs/rootfsimg_linux.sh ${fs_dir} ext4 - - ``` - -7. 配置产品Patch(可选,视产品涉及组件是否需要打补丁而定) - - 在产品目录下创建patch.yml文件。patch.yml需按产品实际情况配置,一个典型的patch.yml文件如下: - - ``` - # 需要打patch的路径 - foundation/communication/dsoftbus: - # 该路径下需要打的patch存放路径 - - foundation/communication/dsoftbus/1.patch - - foundation/communication/dsoftbus/2.patch - third_party/wpa_supplicant: - - third_party/wpa_supplicant/1.patch - - third_party/wpa_supplicant/2.patch - - third_party/wpa_supplicant/3.patch - ... - ``` - - 配置完成后,编译时增加--patch参数,即可在产品编译前将配置的Patch文件打到对应目录中,再进行编译: - - ``` - hb build -f --patch - ``` - -8. 编写编译脚本 - - 在产品目录下创建BUILD.gn文件,按产品实际情况编写脚本。以步骤1中的wifiiot为例,BUILD.gn示例如下: - - ``` - group("wifiiot") { # target名称与产品名一致 - deps = [] - # 拷贝init配置 - deps += [ "init_configs" ] - # 将hals加入编译 - deps += [ "hals" ] - # 其他 - ...... - } - ``` - -9. 编译产品。 - - 在代码根目录执行hb set按提示选择新增的产品,然后执行hb build即可启动编译。 - - -## 常见问题 - -### 编译构建过程中,提示“usr/sbin/ninja: invalid option -- w” - -- **现象描述:** - - 编译失败,提示“usr/sbin/ninja: invalid option -- w”。 - -- **可能原因:** - - 编译环境中ninja版本太低,不支持--w选项。 - -- **解决办法:** - - 卸载环境中ninja和gn,按照[获取工具](/pages/010b02)。 - - -### 编译构建过程中,提示“/usr/bin/ld: cannot find -lncurses” - -- **现象描述:** - - 编译失败,提示“/usr/bin/ld: cannot find -lncurses”。 - -- **可能原因:** - - 编译环境ncurses库缺失。 - -- **解决办法:** - - ``` - sudo apt-get install lib32ncurses5-dev - ``` - - -### 编译构建过程中,提示“line 77: mcopy: command not found” - -- **现象描述:** - - ​编译失败,提示“line 77: mcopy: command not found”。 - -- **可能原因:** - - 编译环境未安装mcopy。 - -- **解决办法:** - - ``` - ​sudo apt-get install dosfstools mtools - ``` - - -### 编译构建过程中,提示“riscv32-unknown-elf-gcc: error trying to exec 'cc1': execvp: No such file or directory” - -- **现象描述:** - - 编译失败,提示“riscv32-unknown-elf-gcc: error trying to exec 'cc1': execvp: No such file or directory”。 - -- ​**可能原因:** - - 当前用户对riscv编译器路径下的文件访问权限不够。 - -- ​**解决办法:** - - 查询gcc\_riscv32所在目录。 - - ``` - which riscv32-unknown-elf-gcc - ``` - - 使用chmod命令修改目录权限为755。 - - -### 编译构建过程中,提示“No module named 'Crypto'” - -- **现象描述:** - - 编译失败,提示“No module named 'Crypto'”。 - -- **可能原因:** - - python3未安装Crypto。 - -- **解决办法:** - 1. 查询Python版本号。 - - ``` - python3 --version - ``` - - 2. 需使用python3.7以上版本,然后安装pycryptodome。 - - ``` - sudo pip3 install pycryptodome - ``` - - - -### 编译构建过程中,提示“xx.sh : xx unexpected operator” - -- **现象描述:** - - 编译失败:“xx.sh \[: xx unexpected operator”。 - -- **可能原因:** - - 编译环境shell不是bash。 - -- **解决办法:** - - ``` - sudo rm -rf /bin/sh - sudo ln -s /bin/bash /bin/sh - ``` - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/03.\347\274\226\350\257\221\346\236\204\345\273\272/02.\346\240\207\345\207\206\347\263\273\347\273\237\347\274\226\350\257\221\346\236\204\345\273\272\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/03.\347\274\226\350\257\221\346\236\204\345\273\272/02.\346\240\207\345\207\206\347\263\273\347\273\237\347\274\226\350\257\221\346\236\204\345\273\272\346\214\207\345\257\274.md" deleted file mode 100644 index cd8b7a07322d64c8cfe81dc9060552f6d1e1c093..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/03.\347\274\226\350\257\221\346\236\204\345\273\272/02.\346\240\207\345\207\206\347\263\273\347\273\237\347\274\226\350\257\221\346\236\204\345\273\272\346\214\207\345\257\274.md" +++ /dev/null @@ -1,248 +0,0 @@ ---- -title: 标准系统编译构建指导 -permalink: /pages/01050302 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:24 ---- -# 标准系统编译构建指导 - -- [概述](#section17466112012244) - - [基本概念](#section445513507246) - - [运作机制](#section12541217142510) - - [约束与限制](#section886933762513) - -- [编译构建使用指导](#section16901215262) - - [目录结构](#section109065332264) - - [编译命令](#section123265539266) - - [开发步骤](#section591084422719) - - -## 概述 - -编译构建子系统提供了一个基于gn和ninja的编译构建框架。主要提供以下功能: - -- 构建不同芯片平台的产品。如:Hi3516DV300平台。 - -- 根据产品配置,按照组件组装打包产品需要的能力。 - -### 基本概念 - -在了解编译构建子系统的能力前,应了解如下基本概念: - -- 平台 - - 开发板和内核的组合,不同平台支持的子系统和组件不同。 - -- 子系统 - - OpenHarmony整体遵从分层设计,从下向上依次为:内核层、系统服务层、框架层和应用层。系统功能按照“系统 \> 子系统 \> 组件”逐级展开,在多设备部署场景下,支持根据实际需求裁剪某些非必要的子系统或组件。子系统是一个逻辑概念,它具体由对应的组件构成。 - -- 组件 - - 对子系统的进一步拆分,可复用的软件单元,它包含源码、配置文件、资源文件和编译脚本;能独立构建,以二进制方式集成,具备独立验证能力的二进制单元。 - -- gn - - Generate ninja的缩写,用于产生ninja文件。 - -- ninja - - ninja是一个专注于速度的小型构建系统。 - - -### 运作机制 - -OpenHarmony侧的编译构建流程主要包括编译命令行解析,调用gn,执行ninja: - -- 命令行解析:解析待编译的产品名称,加载相关配置。 -- 调用gn: 根据命令行解析的产品名称和编译类型,配置编译工具链和全局的编译选项。 -- 执行ninja:启动编译并生成对应的产品版本。 - -### 约束与限制 - -- 需按照[源码获取](/pages/extra/51fbe5/)指导下载全量源码(采用方式三获取)。 -- 编译环境需要Ubuntu18.04及以上版本。 -- 安装编译所需的程序包。 - - 安装命令: - - ``` - sudo apt-get install binutils git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev ccache libgl1-mesa-dev libxml2-utils xsltproc unzip m4 - ``` - - -## 编译构建使用指导 - -### 目录结构 - -``` -/build # 编译构建主目录 -├── config # 编译相关的配置项 -├── core -│ └── gn # 编译入口BUILD.gn配置 -├── loader # 各个组件配置加载、模板生成 -├── ohos # OpenHarmony编译打包流程配置 -│ ├── kits # kits编译打包模板和处理流程 -│ ├── ndk # ndk模板和处理流程 -│ ├── notice # notice模板和处理流程 -│ ├── packages # 版本打包模板和处理流程 -│ ├── sa_profile # sa模板和处理流程 -│ ├── sdk # sdk模板和处理流程,包括sdk中包含的模块配置 -│ └── testfwk # 测试相关的处理 -├── scripts # 编译相关的python脚本 -├── templates # c/c++编译模板定义 -└── toolchain # 编译工具链配置 -``` - -### 编译命令 - -- 代码根目录下执行全量版本的编译命令: - - ``` - ./build.sh --product-name {product_name} - ``` - - \{product\_name\}为当前版本支持的平台。比如:Hi3516DV300等。 - - 编译完成后,结果镜像保存在 out/{device_name}/packages/phone/images/ 目录下。 - -- 编译命令支持选项: - - ``` - --product-name # 必须 编译的产品名称,如:Hi3516DV300 - --build-target # 可选 指定编译目标,可以指定多个 - --gn-args # 可选 gn参数,支持指定多个 - --ccache # 可选 编译使用ccache,需要本地安装ccache - ``` - - -### 开发步骤 - -1. 添加组件。 - - 本节以添加一个自定义的组件为例,描述如何编译组件,编译库、编译可执行文件等。 - - 示例组件partA由feature1、feature2和feature3组成,feature1的编译目标为一个动态库,feature2的目标为一个可执行程序,feature3的目标为一个etc配置文件。 - - 示例组件partA的配置需要添加到一个子系统中,本次示例将添加到subsystem\_examples子系统中(subsystem\_examples子系统定义在test/examples/目录)。 - - 示例组件partA的完整目录结构如下: - - ``` - test/examples/partA - ├── feature1 - │ ├── BUILD.gn - │ ├── include - │ │ └── helloworld1.h - │ └── src - │ └── helloworld1.cpp - ├── feature2 - │ ├── BUILD.gn - │ ├── include - │ │ └── helloworld2.h - │ └── src - │ └── helloworld2.cpp - └── feature3 - ├── BUILD.gn - └── src - └── config.conf - ``` - - 示例1:编写动态库gn脚本test/examples/partA/feature1/BUILD.gn,示例如下: - - ``` - config("helloworld_lib_config") { - include_dirs = [ "include" ] - } - - ohos_shared_library("helloworld_lib") { - sources = [ - "include/helloworld1.h", - "src/helloworld1.cpp", - ] - public_configs = [ ":helloworld_lib_config" ] - part_name = "partA" - } - ``` - - 示例2:编写可执行文件gn脚本test/examples/partA/feature2/BUILD.gn,示例如下: - - ``` - ohos_executable("helloworld_bin") { - sources = [ - "src/helloworld2.cpp" - ] - include_dirs = [ "include" ] - deps = [ # 依赖组件内模块 - "../feature1:helloworld_lib" - ] - external_deps = [ "partB:module1" ] # (可选)如果有跨组件的依赖,格式为“组件名:模块名” - install_enable = true # 可执行程序缺省不安装,需要安装时需要指定 - part_name = "partA" - } - ``` - - 示例3:编写etc模块gn脚本test/examples/partA/feature3/BUILD.gn,示例如下: - - ``` - ohos_prebuilt_etc("feature3_etc") { - source = "src/config.conf" - relative_install_dir = "init" #可选,模块安装相对路径,相对于默认安装路径;默认在/system/etc目录 - part_name = "partA" - } - ``` - - 示例4:在子系统的ohos.build中添加组件配置:test/examples/ohos.build。每个子系统有一个ohos.build配置文件,在子系统的根目录下。示例如下: - - ``` - "partA": { - "module_list": [ - "//test/examples/partA/feature1:helloworld_lib", - "//test/examples/partA/feature2:helloworld_bin", - "//test/examples/partA/feature3:feature3_etc", - ], - "inner_kits": [ - - ], - "system_kits": [ - - ], - "test_list": [ - - ] - } - ``` - - 一个组件包含module\_list、inner\_kits、system\_kits、test\_list四个部分的声明,其中: - - - module\_list:组件所包含的模块列表; - - inner\_kits:组件提供给其它组件调用的接口,其他组件的模块可以在external\_deps中添加依赖的模块; - - system\_kits:组件提供给开发者开发应用的接口; - - test\_list:组件中对应模块的测试用例; - -2. 将组件添加到产品配置中。 - - 在产品的配置中添加组件,产品对应的配置文件:productdefine/common/products/\{product-name\}.json。 - - 在产品配置文件中添加 "subsystem\_examples:partA",表示该产品中会编译并打包partA到版本中。 - -3. 编译。 - - 以编译Hi3516DV300为例,编译命令如下: - - ``` - ./build.sh --product-name Hi3516DV300 --ccache - ``` - -4. 编译输出。 - - 编译所生成的文件都归档在out/hi3516dv300/目录下,结果镜像输出在 out/hi3516dv300/packages/phone/images/ 目录下。 - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/03.\347\274\226\350\257\221\346\236\204\345\273\272/03.\346\236\204\345\273\272\347\263\273\347\273\237\347\274\226\347\240\201\350\247\204\350\214\203\345\222\214\346\234\200\344\275\263\345\256\236\350\267\265\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/03.\347\274\226\350\257\221\346\236\204\345\273\272/03.\346\236\204\345\273\272\347\263\273\347\273\237\347\274\226\347\240\201\350\247\204\350\214\203\345\222\214\346\234\200\344\275\263\345\256\236\350\267\265\346\214\207\345\257\274.md" deleted file mode 100644 index edff2f463f7fa191c39ed55a902dd9c337c011ae..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/03.\347\274\226\350\257\221\346\236\204\345\273\272/03.\346\236\204\345\273\272\347\263\273\347\273\237\347\274\226\347\240\201\350\247\204\350\214\203\345\222\214\346\234\200\344\275\263\345\256\236\350\267\265\346\214\207\345\257\274.md" +++ /dev/null @@ -1,538 +0,0 @@ ---- -title: 构建系统编码规范和最佳实践指导 -permalink: /pages/01050303 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:24 ---- -# 构建系统编码规范与最佳实践 - -## 概述 - -gn是generate ninja的缩写,它是一个元编译系统(meta-build system),是ninja的前端,gn和ninja结合起来,完成OpenHarmony操作系统的编译任务。 - -### gn简介 - -- 目前采用gn的大型软件系统有:Chromium,Fuchsia和OpenHarmony。 -- gn语法自设计之初就自带局限性,比如不能求list的长度,不支持通配符等。这些局限性源于其 **有所为有所不为** 的设计哲学,见https://gn.googlesource.com/gn/+/main/docs/language.md#Design-philosophy。 所以在使用gn的过程中,如果发现某件事情用gn实现起来很复杂,请先停下来思考这件事情是否真的需要做。 -- 关于gn的更多详情见gn官方文档,见https://gn.googlesource.com/gn/+/main/docs/。 - -### 本文的目标读者和覆盖范围 - -目标读者为OpenHarmony的开发者。本文主要讨论gn的编码风格和使用gn过程中容易出现的问题,不讨论gn的语法,如需了解gn基础知识,见gn reference文档,见https://gn.googlesource.com/gn/+/main/docs/reference.md。 - -### 总体原则 - -在保证功能可用的前提下,脚本需要满足易于阅读,便于维护,良好的扩展性和性能等要求。 - -## 代码风格 - -### 命名 - -总体上遵循Linux kernel的命名风格,即**小写字母+下划线**的命名风格。 - -#### 局部变量 - -我们这里对局部变量的定义为:在某作用域内,且不向下传递的变量。 - -为了更好的区别于全局变量,局部变量统一采用**下划线开头**。 - -``` -# 例1 -action("some_action") { - ... - # _output是个局部变量,所以使用下划线开头 - _output = "${target_out_dir}/${target_name}.out" - outputs = [ _output ] - args = [ - ... - "--output", - rebase_path(_output, root_build_dir), - ... - ] - ... -} -``` - -#### 全局变量 - -全局变量使用**小写字母**开头。 - -如果变量值可以被gn args修改,则需要使用declare_args来声明,否则不要使用declare_args。 - -``` -# 例2 -declare_args() { - # 可以通过gn args来修改some_feature的值 - some_feature = false -} -``` - -#### 目标命名 - -目标命名采用**小写字母+下划线**的命名方式。 - -模板中的**子目标**命名方式采用"${target_name}+双下划线+后缀"的命名方式。这样做有两点好处: - -- 加入"${target_name}"可以防止子目标重名。 - -- 加入双下划线可以很方便地区分出子目标属于哪一个模块,方便在出现问题时快速定位。 - - ``` - # 例3 - template("ohos_shared_library") { - # "{target_name}"(主目标名)+"__"(双下划线)+"notice"(后缀) - _notice_target = "${target_name}__notice" - collect_notice(_notice_target) { - ... - } - shared_library(target_name) { - ... - } - } - ``` - -#### 自定义模板的命名 - -推荐采用**动宾短语**的形式来命名。 - -``` -# 例4 -# Good -template("compile_resources") { - ... -} -``` - -### 格式化 - -gn脚本在提交之前需要执行格式化。格式化可以保证代码对齐,换行等风格的统一。使用gn自带的format工具即可。命令如下: - -```shell -$ gn format path-to-BUILD.gn -``` - -gn format会按照字母序对import文件做排序,如果想保证import的顺序,可以添加空注释行。 - -假设原来的import顺序为: - -``` -# 例5 -import("//b.gni") -import("//a.gni") -``` - -经过format之后变为: - -``` -import("//a.gni") -import("//b.gni") -``` - -如果想保证原有的import顺序,可以添加空注释行。 - -``` -import("//b.gni") -# Comment to keep import order -import("//a.gni") -``` - -## 编码实践 - -### 实践原则 - -编译脚本实质上完成了两件工作: - -1. **描述模块之间依赖关系(deps)** - - 实践过程中,最常出现的问题是**依赖关系缺失**。 - -2. **描述模块编译的规则(rule)** - - 实践过程中,容易出现的问题是**输入和输出不明确**。 - -依赖缺失会导致两个问题: - -- **概率性编译错误** - - ``` - # 例6 - # 依赖关系缺失,导致概率性编译出错 - shared_library("a") { - ... - } - shared_library("b") { - ... - ldflags = [ "-la" ] - deps = [] - ... - } - group("images") { - deps = [ ":b" ] - } - ``` - - 上面的例子中,libb.so在链接的时候会链接liba.so,实质上构成b依赖a,但是b的依赖列表(deps)却没有声明对a的依赖。由于编译是并发执行的,如果libb.so在链接的时候liba.so还没有编译出来,就会出现编译错误。 - - 由于liba.so也有可能在libb.so之前编译出来,所以依赖缺失导致的编译错误是概率性的。 - -- **依赖关系缺失导致模块没有参与编译** - - 还是上面的例子,如果我们指定ninja编译目标为images,由于images仅仅依赖b,所以a不会参与编译。由于b实质上依赖a, 这时b在链接时会出现必现错误。 - -有一种不太常见的问题是**过多的依赖**。**过多的依赖会降低并发,导致编译变慢**。见下面的例子: - -_compile_js_target不需要依赖 _compile_resource_target,增加这层依赖,会导致 _compile_js_target在 _compile_resource_target编译完成之后才能开始编译。 - -``` -# 例7 -# 过多的依赖导致编译变慢 -template("too_much_deps") { - ... - _gen_resource_target = "${target_name}__res" - action(_gen_resource_target) { - ... - } - - _compile_resouce_target = "${target_name}__compile_res" - action(_compile_resource_target) { - deps = [":$_gen_resource_target"] - ... - } - - _compile_js_target = "${target_name}__js" - action(_compile_js_target) { - # 这个deps不需要 - deps = [":$_compile_resource_target"] - } -} -``` - -输入不明确会导致: - -- **代码修改了,但增量编译时却没有参与编译。** -- **当使用缓存时,代码发生变化,但是缓存仍然命中。** - -下面的例子中,foo.py引用了bar.py中的函数。bar.py实质上是foo.py的输入,需要将bar.py添加到implict_input_action的input或者depfile中去。否则,修改bar.py,模块implict_input_action将不会重新编译。 - -``` -# 例8 -action("implict_input_action") { - script = "//path-to-foo.py" - ... -} -``` - -``` -#!/usr/bin/env -# Contents of foo.py -import bar -... -bar.some_function() -... -``` - -输出不明确会导致: - -- **隐式的输出** -- **当使用缓存时,隐式输出无法从缓存中获得** - -下面的例子中,foo.py会生成两个文件,a.out和b.out,但是implict_output_action的输出只声明了a.out。这种情况下,b.out实质上就是一个隐式输出。缓存中只会存储a.out,不会存储b.out,当缓存命中时,b.out就编译不出来了。 - -``` -# 例9 -action("implict_output_action") { - outputs = ["${target_out_dir}/a.out"] - script = "//path-to-foo.py" - ... -} -``` - -``` -#!/usr/bin/env -# Contents of foo.py -... -write_file("b.out") -write_file("a.out") -... -``` - -### 模板 - -**不要使用gn的原生模板,使用编译系统提供的模板** - -所谓gn原生模板,是指source_set,shared_library, static_library, action, executable,group这六个模板。 - -不推荐使用原生模板的原因有二: - -- **原生模板是最小功能模板**,无法提供external_deps的解析,notice收集,安装信息生成等的额外功能,这些额外功能最好是随着模块编译时同时生成,所以必须对原生模板做额外的扩展才能满足实际的需求。 - -- 当输入文件依赖的文件发生变化时,gn原生的action模板不能自动感知不到这种编译,无法重新编译。见例8 - - - - 原生模板和编译系统提供的模板之间的对应关系: - - | 编译系统提供的模板 | 原生模板 | - | :------------------ | -------------- | - | ohos_shared_library | shared_library | - | ohos_source_set | source_set | - | ohos_executable | executable | - | ohos_static_library | static_library | - | action_with_pydeps | action | - | ohos_group | group | - - -### 使用python脚本 - -action中的script推荐使用python脚本,不推荐使用shell脚本。相比于shell脚本,python脚本: - -- python语法友好,不会因为少写一个空格就导致奇怪的错误。 -- python脚本有很强的可读性。 -- 可维护性强,可调试。 -- OpenHarmony对python任务做了缓存,可以加快编译速度。 - -### rebase_path - -- 仅在向action的参数列表中(args)调用rebase_path。 - - ``` - # 例10 - template("foo") { - action(target_name) { - ... - args = [ - # 仅在args中调用rebase_path - "--bar=" + rebase_path(invoker.bar, root_build_dir), - ... - ] - ... - } - } - - foo("good") { - bar = something - ... - } - ``` - -- 同一变量做两次rebase_path会出现意想不到的结果。 - - ``` - # 例11 - template("foo") { - action(target_name) { - ... - args = [ - # bar被执行了两次rebase_path, 传递的bar的值已经不对了 - "--bar=" + rebase_path(invoker.bar, root_build_dir), - ... - ] - ... - } - } - - foo("bad") { - # 不要在这里调用rebase_path - bar = rebase_path(some_value,root_build_dir) - ... - } - ``` - -### 模块间数据分享 - -模块间数据分享是很常见的事情,比如A模块想要知道B模块的输出和deps。 - -- 同一BUILD.gn之间数据分享 - - 同一BUILD.gn之间数据可以通过定义全局变量的方式来共享。 - - 下面的例子中,模块a的输出是模块b的输入,可以通过定义全局变量的方式来共享给b - - ``` - # 例12 - _output_a = get_label_info(":a", "out_dir") + "/a.out" - action("a") { - outputs = _output_a - ... - } - action("b") { - inputs = [_output_a] - ... - } - ``` - -- 不同BUILD.gn之间数据分享 - - 不同BUILD.gn之间传递数据,最好的办法是将需要共享的数据保存成文件,然后不同模块之间通过文件来传递和共享数据。这种场景比较复杂,读者可以参照OpenHarmony的hap编译过程的write_meta_data。 - -### forward_variable_from - -- 自定义模板需要首先将testonly传递(forward)进来。因为该模板的target有可能被testonly的目标依赖。 - - ``` - # 例13 - # 自定义模板首先要传递testonly - template("foo") { - forward_variable_from(invoker, ["testonly"]) - ... - } - ``` - -- 不推荐使用*来forward变量,需要的变量应该**显式地,一个一个地**被forward进来。 - - ``` - # 例14 - # Bad,使用*forward变量 - template("foo") { - forward_variable_from(invoker, "*") - ... - } - - # Good, 显式地,一个一个地forward变量 - template("bar") { - # - forward_variable_from(invoker, [ - "testonly", - "deps", - ... - ]) - ... - } - ``` - -### target_name - -target_name会随着作用域变化而变化,使用时需要注意。 - -``` -# 例15 -# target_name会随着作用域变化而变化 -template("foo") { - # 此时打印出来的target_name为"${target_name}" - print(target_name) - _code_gen_target = "${target_name}__gen" - code_gen(_code_gen_target) { - # 此时打印出来的target_name为"${target_name}__gen" - print(target_name) - ... - } - _compile_gen_target = "${target_name}__compile" - compile(_compile_gen_target) { - # 此时打印出来的target_name为"${target_name}__compile" - print(target_name) - ... - } - ... -} -``` - -### public_configs - -如果模块需要向外export头文件,请使用public_configs。 - -``` -# 例16 -# b依赖a,会同时继承a的headers -config("headers") { - include_dirs = ["//path-to-headers"] - ... -} -shared_library("a") { - public_configs = [":headers"] - ... -} -executable("b") { - deps = [":a"] - ... -} -``` - -### template - -自定义模板中必须有一个子目标的名字是target_name。该子目标会作为template的主目标。其他子目标都应该被主目标依赖,否则子目标不会被编译。 - -``` -# 例17 -# 自定义模板中必须有一个子目标的名字是target_name -template("foo") { - _code_gen_target = "${target_name}__gen" - code_gen(_code_gen_target) { - ... - } - _compile_gen_target = "${target_name}__compile" - compile(_compile_gen_target) { - # 此时打印出来的target_name为"${target_name}__compile" - print(target_name) - ... - } - ... - group(target_name) { - deps = [ - # 由于_compile_gen_target依赖了_code_gen_target,所以主目标只需要依赖_compile_gen_target即可。 - ":$_compile_gen_target" - ] - } -} -``` - -### set_source_assignment_filter - -set_source_assignment_filter除了可以过滤sources,还可以用来过滤其他变量。过滤完成后记得将过滤器和sources置空。 - -``` -# 例18 -# 使用set_source_assignment_filter过滤依赖, 挑选label符合*:*_res的添加到依赖列表中 -_deps = [] -foreach(_possible_dep, invoker.deps) { - set_source_assignment_filter(["*:*_res"]) - _label = get_label_info(_possible_dep, "label_no_toolchain") - sources = [] - sources = [ _label ] - if (sources = []) { - _deps += _sources - } -} -sources = [] -set_source_assignment_filter([]) -``` - -最新版本上set_source_assignment_filter被filter_include和filter_exclude取代。 - -### 部件内依赖采用deps,跨部件依赖采用external_deps - -- 部件在OpenHarmony上指能提供某个能力的一组模块。 -- 在模块定义的时候可以声明part_name,用来表明当前模块属于哪个部件。 - -- 每个部件会声明其inner-kit,供其他部件调用。部件innerkit的声明见源码中的ohos.build。 -- 部件间依赖只能依赖innerkit,不能依赖非innerkit的模块。 - -- 如果a模块和b模块的part_name相同,那么a、b模块属于同一个部件,a,b模块之间的依赖关系可以用deps来声明。 - -- 如果a、b模块的part_name不同,那么a、b模块不属于同一个部件,a、b模块之间的依赖关系需要通过external_deps来声明,依赖方式为"部件名:模块名"的方式。见例19。 - - ``` - # 例19 - shared_library("a") { - ... - external_deps = ["part_name_of_b:b"] - ... - } - ``` - - - - - - - - - - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/04.\345\210\206\345\270\203\345\274\217\350\277\234\347\250\213\345\220\257\345\212\250.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/04.\345\210\206\345\270\203\345\274\217\350\277\234\347\250\213\345\220\257\345\212\250.md" deleted file mode 100644 index e8a06cfdc71775c11e12d91963335fb85d9980fa..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/04.\345\210\206\345\270\203\345\274\217\350\277\234\347\250\213\345\220\257\345\212\250.md" +++ /dev/null @@ -1,126 +0,0 @@ ---- -title: 分布式远程启动 -permalink: /pages/010504 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:24 ---- -# 分布式远程启动 - -- [概述](#section186634310418) -- [基本概念](#section982651246) -- [接口说明](#section125479541744) -- [约束与限制](#section1165911177314) -- [开发步骤](#section34171333656) - -## 概述 - -分布式任务调度模块,通过主从设备服务代理机制,在OpenHarmony操作系统上建立起分布式服务平台,支持主设备\(搭载OpenHarmony的智慧屏设备\)启动从设备\(IP Camera、运动手表等小内存OpenHarmony设备\)FA的能力。 - -以智慧屏节目开播提醒为例,智慧屏上在喜欢的节目菜单中,点击“开播后提醒我”按钮,等节目开播后,智慧屏会拉起运动手表上的节目开播提醒FA。通过该FA用户可以快速知道喜欢的节目已经开始,达到协同互助的作用。 - -## 基本概念 - -- FA - - Feature Ability代表有界面的Ability,用于与用户进行交互。 - - -- 远程启动 - - 即跨设备启动FA,与本地启动FA相对应。 - - -## 接口说明 - -智慧屏端分布式开放能力如下表,包含在AbilitySlice类中,具体的API接口详见OpenHarmony应用接入接口文档: - -**表 1** 分布式远程启动FA的API接口功能介绍 - - - - - - - - - - -

接口名

-

描述

-

void startAbility(Want want)

-

远程启动FA,Want参数命名以实际开发平台API为准。

-
- -**表 2** 参数Want功能介绍 - - - - - - - - - - - - -

参数名

-

类型

-

说明

-

want

-

ohos.aafwk.content.Want

-

当开发者需要调用该接口启动远程FA时,需要显式指定待启动FA的设备id、bundleName和abilityName。

-
- -## 约束与限制 - -- 支持主设备侧远程启动从设备侧FA,不支持从设备远程启动主设备FA。 -- 远程启动前必须确保OpenHarmony设备间分布式组网成功(需要在同一网段内,可互相ping通),否则无法远程启动。 -- 当前只支持拥有共同公钥信息的主从设备间FA(即主从设备的FA使用相同华为证书)的拉起。 - -## 开发步骤 - -智慧屏侧通过如下操作启动从设备侧FA,从设备侧FA默认已开发。 - -1. 打开DevEco Studio,完成智慧屏侧FA开发。 -2. 获取目标在线从设备的设备ID。 - - ``` - // 引入设备选择头文件 - import ohos.distributedschedule.interwork.DeviceInfo; - import ohos.distributedschedule.interwork.DeviceManager; - - // 获取在线设备列表 - List deviceInfoListOnline = DeviceManager.getDmsDeviceList(DeviceInfo.FLAG_GET_ONLINE_DEVICE); - String remote_device_id; - if (deviceInfoListOnline.size() > 0) - { - remote_device_id = deviceInfoListOnline[0].GetDeviceId(); // 获取在线列表中第一台设备的设备ID - } - ``` - -3. 构造want,首先使用ElementName类表明需要启动的远端设备ID,包名,Ability类名,传入want中,然后设置want中的分布式标志位Want.FLAG\_ABILITYSLICE\_MULTI\_DEVICE表示需要远程启动。 - - ``` - // 引入相关头文件 - import ohos.aafwk.ability.Ability; - import ohos.aafwk.content.Want; - import ohos.bundle.ElementName; - - // 启动远程设备FA - Want want = new Want(); // 封装启动远端FA的Want - // 使用步骤2中获取的设备ID,并指定FA信息 - ElementName name = new ElementName(remote_device_id, "com.huawei.remote_package_name", "remote_class_name"); - want.setElement(name); // 将待启动的FA信息添加到Want中 - want.setFlags(Want.FLAG_ABILITYSLICE_MULTI_DEVICE); // 设置分布式标记,若不设置将无法使用分布式能力 - startAbility(want); // 按照Want启动指定FA,Want参数命名以实际开发平台API为准 - ``` - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/05.\345\233\276\345\275\242\345\233\276\345\203\217/01.\345\233\276\345\275\242\345\233\276\345\203\217\346\246\202\350\277\260.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/05.\345\233\276\345\275\242\345\233\276\345\203\217/01.\345\233\276\345\275\242\345\233\276\345\203\217\346\246\202\350\277\260.md" deleted file mode 100644 index 2d92fa110c689117581860f194510d7ceccb48ba..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/05.\345\233\276\345\275\242\345\233\276\345\203\217/01.\345\233\276\345\275\242\345\233\276\345\203\217\346\246\202\350\277\260.md" +++ /dev/null @@ -1,62 +0,0 @@ ---- -title: 图形图像概述 -permalink: /pages/01050501 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:24 ---- -# 图形图像概述 - -- [UI组件](#section1987017145112) -- [布局](#section662016231612) -- [动画](#section73736284117) -- [Input事件](#section672194012114) -- [渲染](#section14338859916) - -OpenHarmony图形系统,提供基础UI组件和容器类组件,包括button、image、label、list、animator、scroll view、swipe view、font、clock、chart、canvas、slider、layout等。同时提供截屏、导出组件树的DFX能力。模块内部实现组件渲染、动画、输入事件分发等功能。 - -## UI组件 - -实现各种控件,如按钮、文本、进度条等各种基本控件。 - -提供界面切换、图片序列帧等复杂控件。 - -## 布局 - -实现网格布局、灵活布局(如居中、左对齐、右对齐)。 - -布局为一次性布局。布局函数每运行一次,会计算一次控件的位置,但是控件位置由其他方式改变时(如拖动),其他相关联的控件位置不会自动发生变化,需要重新调用一次布局函数。 - -## 动画 - -根据tick事件,由Task Manager周期性调用回调函数处理属性变化,然后触发刷新重新绘制组件,达到组件动画效果。 - -提供动画的开始/停止、暂停/恢复、创建/销毁等各种操作 ,用于实现动画效果。 - -## Input事件 - -Input事件包括触摸屏触摸输入事件和物理按键输入事件,GUI引擎每运行一次,Input Manager会读取一次所有注册的硬件设备的输入,转化为各种事件供UI控件使用。 - -## 渲染 - -- 2D图形渲染 - - 实现线、矩形、三角形、弧线的绘制操作。 - - -- 图像渲染 - - 实现各种类型图片的绘制API,如RGB565、RGB888、ARGB8888、PNG、JPG格式。 - - -- 字体渲染 - - 支持矢量字体的实时绘制。 - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/05.\345\233\276\345\275\242\345\233\276\345\203\217/02.\345\256\271\345\231\250\347\261\273\347\273\204\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/05.\345\233\276\345\275\242\345\233\276\345\203\217/02.\345\256\271\345\231\250\347\261\273\347\273\204\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index 016d63d0007bd0f3a229911348df109efd07af20..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/05.\345\233\276\345\275\242\345\233\276\345\203\217/02.\345\256\271\345\231\250\347\261\273\347\273\204\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,257 +0,0 @@ ---- -title: 容器类组件开发指导 -permalink: /pages/01050502 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:24 ---- -# 容器类组件开发指导 - -- [UIViewGroup](#section145471898812) -- [使用场景](#section0916112362216) -- [接口说明](#section12641756192212) -- [开发步骤](#section5412161692311) -- [UIScrollView](#section174961523161315) -- [使用场景](#section8937101902413) -- [接口说明](#section14789133142420) -- [开发步骤](#section1769754422417) - -容器类组件,指能包含其它UI组件的组件,容器类组件继承于UIViewGroup(带Add方法),基于实际组件的使用场景,将需要增加其他子组件的组件,放置到容器类继承结构下。如UIAnalogClock内,通常会Add需要的计步信息,时分秒图标等。 - -**图 1** 普通容器类组件结构 -![](/images/device-dev/subsystems/figure/普通容器类组件结构.png "普通容器类组件结构") - -RootView、UIAbstractScroll、UIPicker组件从UIViewGroup继承,UIList、UIScrollView、UISwipeView组件从UIAbstractScroll继承。 - -## UIViewGroup - -## 使用场景 - -UIViewGroup是容器类组件基类,实现增加、删除、插入等操作,通过增加方法可以添加子组件。普通容器类组件子组件需要设置位置信息,位置信息为相对父组件的相对坐标。组件树结构如下图: - -**图 2** 组件树结构示意图 -![](/images/device-dev/subsystems/figure/组件树结构示意图.png "组件树结构示意图") - -往根节点rootView里添加ViewGroup1容器组件和View1组件,往ViewGroup1容器组件里再添加View2组件和ViewGroup2容器组件,在View1之后添加View3组件。 - -- 关于渲染:容器类组件在渲染时会遍历所有子组件OnDraw方法,以达到刷新所有组件的目的。 -- 关于坐标:子组件位置信息为相对父组件的相对坐标,系统在渲染时计算绝对坐标并显示。 -- 关于树结构遍历:UIViewGroup提供如下方法实现遍历、查找、管理组件树。 - -## 接口说明 - -**表 1** ViewGroup接口说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

方法

-

功能

-

virtual void Add(UIView* view)

-

添加子组件

-

virtual void Insert(UIView* prevView, UIView* insertView)

-

插入子组件

-

virtual void Remove(UIView* view)

-

删除子组件

-

virtual void RemoveAll()

-

删除所有子组件

-

virtual void GetTargetView(const Point& point, UIView** last)

-

获取目标视图

-

virtual void MoveChildByOffset(int16_t x, int16_t y)

-

偏移子组件

-

UIView* GetChildrenHead() const

-

获取视图头节点

-

UIView* GetChildrenTail() const

-

获取视图最后那个节点

-

virtual UIView* GetChildById(const char* id) const override

-

通过id获取子视图

-
- -## 开发步骤 - -1. 构造button实例并设置坐标信息。 - - ``` - UILabelButton* btn1 = new UILabelButton(); - btn1->SetPosition(0, 0, 100, 50); - btn1->SetText("btn1"); - - UILabelButton* btn2 = new UILabelButton(); - btn2->SetPosition(50, 50, 100, 50); - btn2->SetText("btn2"); - - UILabelButton* btn3 = new UILabelButton(); - btn3->SetPosition(100, 100, 100, 50); - btn3->SetText("btn3"); - ``` - -2. 构造UIViewGroup实例,并设置坐标信息。 - - ``` - UIViewGroup* group = new UIViewGroup(); - group->SetPosition(0, 0, 300, 300); - ``` - -3. 使用Add方法添加Button实例到UIViewGroup。 - - ``` - group->Add(btn1); - group->Add(btn2); - group->Add(btn3); - ``` - -4. 检查ViewGroup效果如下图所示。 - - **图 3** ViewGroup添加view实例效果图 - ![](/images/device-dev/subsystems/figure/ViewGroup添加view实例效果图.png "ViewGroup添加view实例效果图") - - -## UIScrollView - -## 使用场景 - -UIScrollView提供可滑动的容器类组件,子组件可在触摸事件驱动下上下、左右滑动,并提供水平和垂直方向的游标显示功能。 - -## 接口说明 - -**表 2** ScrollView接口说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

方法

-

功能

-

void ScrollBy(int16_t xDistance, int16_t yDistance)

-

移动视图

-

void SetScrollbarWidth(uint8_t width)

-

设置滑动条宽度

-

void SetHorizontalScrollState(bool state)

-

设置水平滑动状态

-

bool GetHorizontalScrollState() const

-

获取水平是否可滑动状态

-

void SetVerticalScrollState(bool state)

-

设置垂直滑动状态

-

bool GetVerticalScrollState() const

-

获取垂直是否可滑动状态

-

void SetXScrollBarVisible(bool state)

-

设置X轴滑动条是否可见

-

void SetYScrollBarVisible(bool state)

-

设置Y轴滑动条是否可见

-

void RegisterScrollListener(OnScrollListener* scrollListener)

-

注册滑动事件回调类

-

void RefreshScrollBar()

-

刷新滑动条

-

virtual void OnScrollStart() {}

-

滚动开始回调函数

-

virtual void OnScrollEnd() {}

-

滚动结束回调函数

-

uint8_t GetScrollState() const

-

获取滚动状态

-

void SetScrollState(uint8_t state)

-

设置滚动状态

-
- -## 开发步骤 - -添加两个button子组件,并显示水平、垂直方向游标。 - -``` -scrollView* scroll = new UIScrollView(); -scroll->SetStyle(STYLE_BACKGROUND_COLOR, Color::Red().full); -scroll->SetPosition(0,0, 200, 200); -scroll->SetXScrollBarVisible(true); -scroll->SetYScrollBarVisible(true); -UILabelButton* button1 = new UILabelButton(); -button1->SetText("button1"); -button1->SetPosition(0, 0, 300, 300); -UILabelButton* button2 = new UILabelButton(); -button2->SetText("button2"); -button2->SetPosition(0, 300, 300, 300); -scroll->Add(button1); -scroll->Add(button2); -``` - -**图 4** 水平、垂直方向可滑动效果图 -![](/images/device-dev/subsystems/figure/水平-垂直方向可滑动效果图.gif "水平-垂直方向可滑动效果图") - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/05.\345\233\276\345\275\242\345\233\276\345\203\217/03.\345\270\203\345\261\200\345\256\271\345\231\250\347\261\273\347\273\204\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/05.\345\233\276\345\275\242\345\233\276\345\203\217/03.\345\270\203\345\261\200\345\256\271\345\231\250\347\261\273\347\273\204\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index cbb3d5f254230abb001224358a2fe7eb8a392af4..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/05.\345\233\276\345\275\242\345\233\276\345\203\217/03.\345\270\203\345\261\200\345\256\271\345\231\250\347\261\273\347\273\204\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,229 +0,0 @@ ---- -title: 布局容器类组件开发指导 -permalink: /pages/01050503 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:24 ---- -# 布局容器类组件开发指导 - -- [UISwipeView](#section13631719181717) -- [使用场景](#section11299120102617) -- [接口说明](#section767434119261) -- [开发步骤(水平滑动,不可循环)](#section111911175287) -- [开发步骤(水平滑动,可循环)](#section1976914915282) -- [GridLayout](#section46819199173) -- [使用场景](#section831618247294) -- [接口说明](#section597214622912) -- [开发步骤](#section1418253410306) - -布局类容器组件由视图基础类组成,通过直接设置视图位置,可以达到嵌套和重叠布局的目的;通过设置布局类型和边距达到规格化布局子组件的目的;通过调用相关接口可实现根据父组件及兄弟节点布局视图的目的。 - -## UISwipeView - -## 使用场景 - -UISwipeView继承UIViewGroup,除提供容器类组件Add、Remove、Insert等方法外还提供按页面滑动功能,滑动结束后当前页面居中对齐显示。该组件分为水平方向和垂直方向,通过Add方法添加的子组件会根据Add的顺序和UISwipeView方向自动水平对齐或则垂直对齐。 - -## 接口说明 - -**表 1** SwipeView接口说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

方法

-

功能

-

void SetCurrentPage(uint16_t index);

-

设置当前页

-

uint16_t GetCurrentPage()

-

获取当前页

-

UIView* GetCurrentView() const

-

获取当前页组件

-

void SetOnSwipeListener(OnSwipeListener& onSwipeListener)

-

设置滑动回调类

-

void SetAnimatorTime(uint16_t time);

-

设置动画事件

-

void SetLoopState(bool loop)

-

设置是否循环

-

UIView* GetViewByIndex(uint16_t index);

-

通过index获取view

-
- -## 开发步骤(水平滑动,不可循环) - -1. 创建一个水平滑动的UISwipeView。 - - ``` - UISwipeView* swipe = new UISwipeView(UISwipeView::HORIZONTAL); - ``` - -2. 向UISwipeView中添加子组件。 - - ``` - UILabelButton* button1 = new UILabelButton(); - button1->SetPosition(0, 0, g_ButtonW, g_ButtonH); - button1->SetText("button1"); - swipe->Add(button1); - UILabelButton* button2 = new UILabelButton(); - button2->SetPosition(0, 0, g_ButtonW, g_ButtonH); - button2->SetText("button2"); - swipe->Add(button2); - UILabelButton* button3 = new UILabelButton(); - button3->SetPosition(0, 0, g_ButtonW, g_ButtonH); - button3->SetText("button3"); - swipe->Add(button3); - ``` - -3. 检查实现效果,水平滑动,不可循环。 - - **图 1** UISwipeView水平滑动效果图 - - - ![](/images/device-dev/subsystems/figure/zh-cn_image_0000001053247975.gif) - - -## 开发步骤(水平滑动,可循环) - -1. 创建一个水平滑动的UISwipeView并添加子组件。 - - ``` - UISwipeView* swipe = new UISwipeView(UISwipeView::HORIZONTAL); - UILabelButton* button1 = new UILabelButton(); - button1->SetPosition(0, 0, g_ButtonW, g_ButtonH); - button1->SetText("button1"); - swipe->Add(button1); - UILabelButton* button2 = new UILabelButton(); - button2->SetPosition(0, 0, g_ButtonW, g_ButtonH); - button2->SetText("button2"); - swipe->Add(button2); - UILabelButton* button3 = new UILabelButton(); - button3->SetPosition(0, 0, g_ButtonW, g_ButtonH); - button3->SetText("button3"); - swipe->Add(button3); - ``` - -2. 设置UISwipeView循环滑动。 - - ``` - swipe->SetLoopState(true); - ``` - -3. 检查实现效果,水平循环滑动。 - - **图 2** UISwipeView水平滑动循环效果图 - - - ![](/images/device-dev/subsystems/figure/zh-cn_image_0000001053207924.gif) - - -## GridLayout - -## 使用场景 - -提供基础布局能力,可设置网格行数和列数,通过Add方法添加的子组件在调用LayoutChildren\(\)方法后自动进行排列布局。 - -## 接口说明 - -**表 2** GridLayout接口说明 - - - - - - - - - - - - - - - - -

方法

-

功能

-

void SetRows(const uint16_t& rows)

-

设置行数

-

void SetCols(const uint16_t& cols)

-

设置列数

-

void LayoutChildren(bool needInvalidate = false)

-

布局子组件

-
- -## 开发步骤 - -1. 构造GridLayout并设置位置、大小信息。 - - ``` - GridLayout* layout_ = new GridLayout(); - layout_->SetPosition(0, g_y, HROIZONTAL_RESOLUTION, 200); - layout_->SetLayoutDirection(LAYOUT_HOR); - layout_->SetRows(2); - layout_->SetCols(2); - ``` - -2. 构造子组件button。 - - ``` - UILabelButton* bt1 = new UILabelButton(); - bt1->SetPosition(0,0,100,50); - bt1->SetText("bt1"); - UILabelButton* bt2 = new UILabelButton(); - bt2->SetPosition(0, 0, 100, 50); - bt2->SetText("bt2"); - UILabelButton* bt3 = new UILabelButton(); - bt3->SetPosition(0, 0, 100, 50); - bt3->SetText("bt3"); - UILabelButton* bt4 = new UILabelButton(); - bt4->SetPosition(0, 0, 100, 50); - bt4->SetText("bt4"); - ``` - -3. 添加子组件并调用LayoutChildren\(\)。 - - ``` - layout_->Add(bt1); - layout_->Add(bt2); - layout_->Add(bt3); - layout_->Add(bt4); - layout_->LayoutChildren(); - ``` - -4. 检查button组件布局效果如下图所示。 - - **图 3** 设置2\*2网格并添加4个button组件进行布局 - ![](/images/device-dev/subsystems/figure/设置2-2网格并添加4个button组件进行布局.png "设置2-2网格并添加4个button组件进行布局") - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/05.\345\233\276\345\275\242\345\233\276\345\203\217/04.\346\231\256\351\200\232\347\273\204\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/05.\345\233\276\345\275\242\345\233\276\345\203\217/04.\346\231\256\351\200\232\347\273\204\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index 9c19f7e1264b8d576dac259a9175f41821f7bd38..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/05.\345\233\276\345\275\242\345\233\276\345\203\217/04.\346\231\256\351\200\232\347\273\204\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,568 +0,0 @@ ---- -title: 普通组件开发指导 -permalink: /pages/01050504 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:24 ---- -# 普通组件开发指导 - -- [UIButton](#section145353310214) -- [使用场景](#section1169616141577) -- [接口说明](#section341211538315) -- [开发步骤](#section22501726193214) -- [UIImageView](#section19523161611259) -- [使用场景](#section1274484210400) -- [接口说明](#section74981992411) -- [开发步骤(自适应)](#section144341333134114) -- [开发步骤(平铺模式)](#section97178160421) -- [UILabel](#section16588132012911) -- [使用场景](#section6870195634218) -- [接口说明](#section2012714510433) -- [开发步骤(默认模式)](#section83221538114410) -- [开发步骤(背景色和透明度)](#section933360204510) -- [开发步骤(字符间距)](#section19447826124518) -- [开发步骤(大小自适应)](#section101711842154617) -- [开发步骤(省略号模式)](#section1249519410471) -- [开发步骤(滚动模式)](#section15643122618478) - -普通组件均继承于基类UIView,不可以添加子组件,常用的普通组件有button、image、label等。 - -**图 1** 普通组件树结构 -![](/images/device-dev/subsystems/figure/普通组件树结构.png "普通组件树结构") - -UIView为基础类,UIAbstractProgress、UIArcLabel(旋转字体)、UIButton(按键)、UICanvas(画布)、UILabel(字体)、UIImageView(图片)从UIView继承。UIBoxProgress、UICircleProgress从UIAbstractProgress继承,UILabelButton和UIRepeatButton从UIButton继承,UIImageAnimatorView和UITextureMapper从UIImageView继承。 - -## UIButton - -## 使用场景 - -UIButton组件,提供可点击功能,同时可设置不同状态下样式。 - -## 接口说明 - -**表 1** button接口说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

方法

-

功能

-

void SetImageSrc (const char *defaultImgSrc, const char *triggeredImgSrc)

-

设置button图片

-

void SetImagePosition (const int16_t x, const int16_t y)

-

设置button图片位置

-

int16_t GetImageX () const

-

获取图片X坐标

-

int16_t GetImageY () const

-

获取图片Y坐标

-

const ImageInfo* GetCurImageSrc() const

-

获取当前状态图片

-

Style& GetStyleForState (ButtonState state)

-

设置button当前状态的style

-

voidSetStyleForState (const Style &style, ButtonState state)

-

设置button指定状态的style

-

void Disable ()

-

去使能button

-

void Enable ()

-

使能button

-
- -## 开发步骤 - -1. 实现点击事件。 - - ``` - class TestBtnOnClickListener : public OHOS::UIView::OnClickListener { - bool OnClick(UIView& view, const ClickEvent& event) override - { - int16_t width = view.GetWidth() + 10; - int16_t height = view.GetHeight() + 10; - view.Resize(width, height); - view.Invalidate(); - return true; - } - }; - ``` - -2. 创建一个UIButton。 - - ``` - UIButton* button = new UIButton(); - button->SetPosition(50, 50); - button->SetWidth(100); - button->SetHeight(50); - ``` - -3. 给UIButton注册点击事件回调。 - - ``` - button->SetOnClickListener(new TestBtnOnClickListener()); - ``` - -4. 检查Button点击效果如下图所示,Button逐渐变大。 - - **图 2** UIButton点击效果 - ![](/images/device-dev/subsystems/figure/UIButton点击效果.gif "UIButton点击效果") - - -## UIImageView - -## 使用场景 - -图片组件,提供图片显示,透明度设置,图片旋转、缩放功能。支持的图片格式为RGB565、RGB888、RGBA8888、PNG、JPG。 - -## 接口说明 - -**表 2** image接口说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

方法

-

功能

-

void SetSrc (const char *src)

-

设置二进制图片路径

-

void SetSrc (const ImageInfo *src)

-

设置图片指针

-

void SetAutoEnable (bool enable)

-

设置组件大小跟随image大小变化

-

const void* GetSrcType () const

-

获取图片类型

-

bool GetAutoEnable () const

-

获取组件大小是否跟随image大小变化

-

void SetBlurLevel(BlurLevel level)

-

设置模糊等级

-

BlurLevel GetBlurLevel() const

-

获取模糊等级

-

void SetTransformAlgorithm(TransformAlgorithm algorithm)

-

设置旋转算法

-

TransformAlgorithm GetTransformAlgorithm() const

-

获取旋转算法

-
- -## 开发步骤(自适应) - -1. 创建一个UIImageView。 - - ``` - UIImageView* imageView = new UIImageView(); - imageView->SetPosition(0, 30); - ``` - -2. 设置二进制格式的图片。 - - ``` - imageView->SetSrc("..\\config\\images\\A021_001.bin"); - ``` - -3. 检查UIImageView控件大小与图片相同。 - - **图 3** 自适应模式图片效果图 - ![](/images/device-dev/subsystems/figure/自适应模式图片效果图.png "自适应模式图片效果图") - - -## 开发步骤(平铺模式) - -1. 创建一个UIImageView。 - - ``` - UIImageView* imageView = new UIImageView(); - imageView->SetPosition(0, 30); - ``` - -2. 设置图片。 - - ``` - imageView->SetSrc("..\\config\\images\\A021_001.bin"); - ``` - -3. 取消图片自适应,设置图片大小,平铺显示效果。 - - ``` - imageView->SetAutoEnable(false); - imageView->Resize(454, 150); - ``` - -4. 检查UIImageView控件显示为平铺效果。 - - **图 4** 平铺模式图片效果图 - ![](/images/device-dev/subsystems/figure/平铺模式图片效果图.png "平铺模式图片效果图") - - -## UILabel - -## 使用场景 - -标签(label)是在一块区域上显示文本字符串的组件,可设置区域背景色、文字的显示样式和长文本的显示效果等。 - -## 接口说明 - -**表 3** label接口说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

方法

-

功能

-

void SetText(const char* text);

-

设置文字

-

const char* GetText() const;

-

获取text

-

void SetLineBreakMode(const uint8_t lineBreakMode);

-

设置label模式,例如截断,自动扩展等。

-

uint8_t GetLineBreakMode() const

-

获取label模式

-

void SetTextColor(ColorType color)

-

设置文本颜色

-

ColorType GetTextColor() const

-

获取文本颜色

-

void SetAlign(UITextLanguageAlignment horizontalAlign,

-

UITextLanguageAlignment verticalAlign = TEXT_ALIGNMENT_TOP);

-

设置文本对齐方式

-

UITextLanguageAlignment GetHorAlign() const

-

获取文本水平对齐方式

-

UITextLanguageAlignment GetVerAlign() const

-

获取文本竖直对齐方式

-

void SetDirect(UITextLanguageDirect direct)

-

设置文本显示方向

-

UITextLanguageDirect GetDirect() const

-

获取文本显示方向

-

void SetFontId(uint8_t fontId);

-

设置动态字体id

-

uint8_t GetFontId() const

-

获取动态字体id

-

void SetFont(const char *name, uint8_t size);

-

设置字的名字和大小

-

void SetAnimatorSpeed(uint16_t animSpeed);

-

设置字体旋转的速度

-

uint16_t GetTextWidth();

-

获取字体的宽

-

uint16_t GetTextHeight();

-

获取字体的高

-

void SetRollStartPos(int16_t pos)

-

设置旋转的位置

-

int16_t GetRollStartPos() const

-

获取旋转的位置

-

void SetTextRotation(LabelRotateDegree angle)

-

设置文本旋转角度枚举值

-

LabelRotateDegree GetTextRotation() const

-

获取文本旋转角度枚举值

-

uint16_t GetTextRotateDegree() const

-

获取文本旋转角度数值

-
- -## 开发步骤(默认模式) - -1. 创建label,设置大小和位置信息。 - - ``` - UILabel* label = new UILabel(); - label->SetPosition(x, y); - label->Resize(width, height); - ``` - -2. 设置字形信息。 - - ``` - label->SetFont("SourceHanSansSC-Regular.otf", 30); - ``` - -3. 设置文本数据。 - - ``` - label->SetText("label"); - ``` - -4. 检查label大小和显示效果正常,如下图所示。 - - ![](/images/device-dev/subsystems/figure/zh-cn_image_0000001051782526.png) - - -## 开发步骤(背景色和透明度) - -1. 创建label,设置大小和位置信息。 - - ``` - UILabel* label = new UILabel(); - label->SetPosition(x, y); - label->Resize(width, height); - ``` - -2. 设置字形信息。 - - ``` - label->SetFont("SourceHanSansSC-Regular.otf", 30); - ``` - -3. 设置背景颜色及透明度效果。 - - ``` - label->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); - label->SetStyle(STYLE_BACKGROUND_OPA, 127); - label->SetText("Label"); - ``` - -4. 检查label背景色为Gray,如下图所示。 - - ![](/images/device-dev/subsystems/figure/zh-cn_image_0000001052582522.png) - - -## 开发步骤(字符间距) - -1. 创建label,设置大小和位置信息。 - - ``` - UILabel* label = new UILabel(); - label->SetPosition(x, y); - label->Resize(width, height); - ``` - -2. 设置字形信息。 - - ``` - label->SetFont("SourceHanSansSC-Regular.otf", 30); - ``` - -3. 设置字体颜色和字间距效果。 - - ``` - label->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); - label->SetStyle(STYLE_LETTER_SPACE, 5); - label->SetText("Label"); - ``` - -4. 检查label字符间距为5,如下图所示。 - - ![](/images/device-dev/subsystems/figure/zh-cn_image_0000001052942531.png) - - -## 开发步骤(大小自适应) - -当文本过长时,可根据文本信息自动调整label组件大小,也可以设置文本截断或者文本滚动效果。 - -1. 创建label,设置大小和位置信息。 - - ``` - UILabel* label = new UILabel(); - label->SetPosition(x, y); - label->Resize(width, height); - ``` - -2. 设置字形信息。 - - ``` - label->SetFont("SourceHanSansSC-Regular.otf", 30); - ``` - -3. 设置字体颜色为Gray,组件大小自适应文本内容。 - - ``` - label->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); - label->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - label->SetText("123\n567890"); - ``` - -4. 检查label大小自适应文本内容,如下图所示。 - - ![](/images/device-dev/subsystems/figure/zh-cn_image_0000001052782555.png) - - -## 开发步骤(省略号模式) - -省略号模式指文本内容显示不下时,在末尾显示省略号。 - -1. 创建label,设置大小和位置信息。 - - ``` - UILabel* label = new UILabel(); - label->SetPosition(x, y); - label->Resize(width, height); - ``` - -2. 设置字形信息。 - - ``` - label->SetFont("SourceHanSansSC-Regular.otf", 30); - ``` - -3. 设置换行模式为DOT模式 - - ``` - label->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); - label->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); - label->SetText("123567890"); - ``` - -4. 检查label DOT模式效果,如下图所示,末尾显示省略号。 - - ![](/images/device-dev/subsystems/figure/zh-cn_image_0000001052662559.png) - - -## 开发步骤(滚动模式) - -文本滚动显示。 - -1. 创建label,设置大小和位置信息。 - - ``` - UILabel* label = new UILabel(); - label->SetPosition(x, y); - label->Resize(width, height); - ``` - -2. 设置字形信息。 - - ``` - label->SetFont("SourceHanSansSC-Regular.otf", 30); - ``` - -3. 设置换行模式为滚动模式 - - ``` - label->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); - label->SetStyle(STYLE_BACKGROUND_OPA, 127); - label->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); - label->SetText("123567890"); - ``` - -4. 检查label滚动模式效果,如下图所示。 - - ![](/images/device-dev/subsystems/figure/20200721-223604(eSpace).gif) - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/05.\345\233\276\345\275\242\345\233\276\345\203\217/05.\345\212\250\347\224\273\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/05.\345\233\276\345\275\242\345\233\276\345\203\217/05.\345\212\250\347\224\273\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index 12635536691b5ab8de7afdab60183afd2285680f..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/05.\345\233\276\345\275\242\345\233\276\345\203\217/05.\345\212\250\347\224\273\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,203 +0,0 @@ ---- -title: 动画开发指导 -permalink: /pages/01050505 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 动画开发指导 - -- [使用场景](#section726685714018) -- [接口说明](#section85794718418) -- [开发步骤](#section14101161317435) - -## 使用场景 - -UI动画通过task处理机制每个tick调用一下用户设置的callback函数来实现,具体实现为AnimatorManager、Animator、AnimatorCallback三个类实现。 - -- AnimatorManager:AnimatorManager为单例,在Init函数执行时将自己注册到系统task回调函数中,系统task机制保证每个tick会调用一下AnimatorManager的callback函数,同时AnimatorManager用来管理Animator实例。 -- Animator:Animator中可以设置动画相关的属性,包括动画的起止时间,动画开始和停止,动画状态的设置和获取等。 -- AnimatorCallback:具体每一个tick动画所要做的内容在AnimatorCallback类中实现,开发者需要自己实现Callback方法,动画执行时在Callback实现相应功能。 - -## 接口说明 - -**表 1** 动画接口说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

子模块

-

方法

-

功能

-

Animator

-

void Start ()

-

动画开始

-

Animator

-

void Stop ()

-

动画停止

-

Animator

-

void Pause ()

-

动画暂停

-

Animator

-

void Resume ()

-

动画恢复

-

Animator

-

uint8_t GetState () const

-

获取动画当前状态

-

Animator

-

void SetState (uint8_t state)

-

设置动画当前状态

-

Animator

-

uint32_t GetTime () const

-

获取动画总持续时间

-

Animator

-

void SetTime (uint32_t time)

-

设置动画总持续时间

-

Animator

-

uint32_t GetRunTime () const

-

获取动画当前已经持续的时间

-

Animator

-

void SetRunTime (uint32_t runTime)

-

设置动画当前已经持续的时间

-

Animator

-

bool IsRepeat () const

-

获取动画是否循环播放

-

AnimatorCallback

-

virtual void Callback (UIView *view)=0

-

由用户实现,动画回调函数

-

AnimatorCallback

-

virtual void OnStop(UIView& view) {}

-

由用户实现,动画停止后的回调函数

-

AnimatorManager

-

static AnimatorManager* GetInstance()

-

获取AnimatorManager实例

-

AnimatorManager

-

void Add (Animator *animator)

-

添加动画

-

AnimatorManager

-

void Remove(const Animator* animator);

-

删除动画

-
- -## 开发步骤 - -1. 实现AnimatorCallback的回调函数。 - - ``` - class AnimatorCallbackDemo : public OHOS::AnimatorCallback { - public: - AnimatorCallbackDemo(int16_t startPos, int16_t endPos, uint16_t time) - : start_(startPos), end_(endPos), time_(time), curTime_(0) {} - - virtual void Callback(OHOS::UIView* view) - { - curTime_++; - int16_t pos = EasingEquation::CubicEaseIn(start_, end_, curTime_, time_); - view->Invalidate(); - view->SetPosition(pos, view->GetY()); - view->Invalidate(); - } - protected: - int16_t start_; - int16_t end_; - uint16_t time_; - uint16_t curTime_; - }; - ``` - -2. 将AnimatorCallback添加到Animator中。 - - ``` - UIImageView* image = new UIImageView(); - image->SetSrc("..\\config\\images\\A021_001.bin"); - image->SetPosition(0, 50); - AnimatorCallbackDemo* callback = new AnimatorCallbackDemo(0, 338, 60); - Animator* animator = new Animator(callback, image, 0, true); - ``` - -3. 将Animator添加到AnimatorManager中。 - - ``` - AnimatorManager::GetInstance()->Add(animator); - ``` - -4. 点击下图下方的按钮,检查对应的动画运行效果。 - - **图 1** 动画实现效果图 - ![](/images/device-dev/subsystems/figure/动画实现效果图.gif "动画实现效果图") - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/06.\345\252\222\344\275\223/01.\347\233\270\346\234\272/01.\347\233\270\346\234\272\345\274\200\345\217\221\346\246\202\350\277\260.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/06.\345\252\222\344\275\223/01.\347\233\270\346\234\272/01.\347\233\270\346\234\272\345\274\200\345\217\221\346\246\202\350\277\260.md" deleted file mode 100644 index aaffaf80723057fe448a7d1a8df24d2f27d531af..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/06.\345\252\222\344\275\223/01.\347\233\270\346\234\272/01.\347\233\270\346\234\272\345\274\200\345\217\221\346\246\202\350\277\260.md" +++ /dev/null @@ -1,128 +0,0 @@ ---- -title: 相机开发概述 -permalink: /pages/0105060101 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 相机开发概述 - -- [基本概念](#section175012297491) -- [运作机制](#section193961322175011) - -## 基本概念 - -相机是OpenHarmony多媒体进程提供的服务之一,提供了相机的录像、预览、拍照功能,支持多用户并发取流。 - -在进行应用的开发前,开发者应了解以下基本概念: - -- 视频帧 - - 视频流指的是将一系列图片数据按照固定时间间隔排列形成的数据流,每一张图片数据成为一帧,这样的一帧称为视频帧。 - -- 帧速率\(FPS: Frames Per Second\) - - 视频播放每秒钟刷新图片的速度,或是视频每秒的帧数,帧速率越高,视频的观感越流畅。 - -- 分辨率 - - 每一帧的图片信息都是由像素点组成的,分辨率描述了一张图片中像素点的个数。例如1920\*1080\(1080P\),是指图片宽1920像素,高1080像素。 - - -## 运作机制 - -- 多媒体服务进程 - - 多媒体服务作为系统服务,在系统启动时由Init进程拉起,并初始化和分配媒体硬件资源(内存/显示硬件/图像传感器/编解码器等)。初始化过程解析配置文件,确定了多媒体各个服务的能力和资源上限,通常由OEM厂商通过配置文件进行配置。相机服务在多媒体进程初始化时有以下配置项: - - - 内存池:所有媒体服务依赖于内存池中的内存轮转运行 - - 图像传感器:包括了传感器类型、分辨率、ISP等 - - 图像处理器:分辨率、码率、图像翻转等 - - 图像编码器:编码格式、码率、分辨率等 - - -- 关键类的解释 - - 应用通过持有下面4个类,配置和使用Camera的功能,包括了Camera类和它的三个异步回调类,三类回调分别对应了不同类型的异步处理场景,详见[表1](#table486418149411)。 - - **表 1** 关键类的解释 - - - - - - - - - - - - - - - - - - - - - - - - -

对象

-

用途

-

举例

-

Camera

-

对相机进行静态配置(通过配置类),触发相机基本功能

-

拍照/录像/预览

-

CameraDeviceCallback

-

处理相机硬件状态变化

-

可用/不可用

-

CameraStateCallback

-

处理camera自身状态变化

-

创建/释放

-

FrameStateCallback

-

处理帧状态的变化

-

拍照开始和结束/帧率发生变化

-
- -- 流的传递 - - Surface是多媒体传递音视频的基本数据结构,Camera一般作为Surface中数据的生产者,在不同的场景下有特定的消费者。 - - 相机的预览和录像输出均为视频流,拍照输出为图像帧,二者均通过Surface类进行传递。Surface类可以屏蔽进程内/跨进程的场景,进行多媒体信息流的传递。 - - 以录像为例,用户首先创建Recorder实例,并从Recorder中获取对应Surface,再将此Surface传递给Camera实例,此时Camera将作为生产者向Surface注入视频流,而Recorder作为消费者从Surface中取出视频流进行保存,用户的行为类似桥接,把二者通过Surface连接起来。 - - 类似的,用户也可以自行创建Surface传递给Camera实例,并实现消费者逻辑(例如通过网络传输视频流,或是将拍照的帧数据保存成图片文件)。 - - 图形图像模块也通过Surface从Camera获取流资源,具体步骤详见[图形图像开发指导](/pages/01050501)。 - -- 相机运行流程 - 1. Camera创建流程 - - 本进程通过CameraManager创建Camera实例,并从服务端绑定camera设备,创建成功后异步通知developer。类之间的时序图如下: - - **图 1** Camera创建时序图 - - - ![](/images/device-dev/subsystems/figure/zh-cn_image_0000001054101094.png) - - 1. Camera录像/预览流程 - - 开发者首先通过CameraKit创建Camera,然后FrameConfig类对录像或者预览帧属性进行配置。录像/预览时序如下: - - **图 2** Camera录像/预览时序图 - - - ![](/images/device-dev/subsystems/figure/zh-cn_image_0000001054421113.png) - - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/06.\345\252\222\344\275\223/01.\347\233\270\346\234\272/02.\346\213\215\347\205\247\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/06.\345\252\222\344\275\223/01.\347\233\270\346\234\272/02.\346\213\215\347\205\247\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index 43a4103e5c42cd1ee0ed8a50a6888fa0746e6898..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/06.\345\252\222\344\275\223/01.\347\233\270\346\234\272/02.\346\213\215\347\205\247\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,458 +0,0 @@ ---- -title: 拍照开发指导 -permalink: /pages/0105060102 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 拍照开发指导 - -- [使用场景](#section1963312376119) -- [接口说明](#section56549532016) -- [约束与限制](#section1165911177314) -- [开发步骤](#section138543918214) - -## 使用场景 - -使用Camera产生图片帧(拍照)。 - -## 接口说明 - -**表 1** API列表 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

类名

-

接口名

-

描述

-

CameraKit

-

int32_t GetCameraIds(std::list<string> cameraList)

-

获取cameraId列表

-

CameraKit

-

CameraAbility& GetCameraAbility(string cameraId)

-

获取指定camera的能力

-

CameraKit

-

void RegisterCameraDeviceCallback(CameraDeviceCallback* callback, EventHandler* handler)

-

注册camera设备状态回调

-

CameraKit

-

void UnregisterCameraDeviceCallback(CameraDeviceCallback* callback)

-

去注册camera设备状态回调

-

CameraKit

-

void CreateCamera(string cameraId, CameraStateCallback* callback, EventHandler* handler)

-

创建camera实例

-

CameraKit

-

const CameraInfo *GetCameraInfo(std::string cameraId);

-

创建cameraInfo实例

-

Camera

-

string GetCameraId()

-

获取cameraID

-

Camera

-

CameraConfig& GetCameraConfig()

-

获取camera配置信息

-

Camera

-

FrameConfig& GetFrameConfig(int32_t type)

-

获取捕获帧类型

-

Camera

-

void Configure(CameraConfig& config)

-

配置camera

-

Camera

-

void Release()

-

释放camera

-

Camera

-

int TriggerLoopingCapture(FrameConfig& frameConfig)

-

开始循环帧捕获

-

Camera

-

void StopLoopingCapture()

-

停止循环帧捕获

-

Camera

-

int32_t TriggerSingleCapture(FrameConfig& frameConfig)

-

抓图

-

CameraConfig

-

void SetFrameStateCallback(FrameStateCallback* callback, EventHandler* handler);

-

设置帧状态回调

-

CameraConfig

-

static CameraConfig* CreateCameraConfig()

-

创建camera配置信息实例

-

CameraAbility

-

std::list<Size> GetSupportedSizes(int format)

-

根据类型获取支持输出图像尺寸大小

-

CameraAbility

-

std::list<T> GetParameterRange(uint32_t key)

-

获取支持的参数范围

-

CameraAbility

-

std::list<int32_t> GetSupportedAfModes() const;

-

获取支持的自动对焦模式列表

-

CameraAbility

-

std::list<int32_t> GetSupportedAeModes() const;

-

获取支持的自动曝光模式列表

-

CameraDevice

-

CameraDeviceCallback()

-

camera设备回调类构造函数

-

CameraDevice

-

void OnCameraStatus​(std::string cameraId, int32_t status)

-

camera设备状态变化时的回调

-

CameraStateCallback

-

CameraStateCallback​()

-

camera状态回调类构造函数

-

CameraStateCallback

-

void OnConfigured​(Camera& camera)

-

camera配置成功回调

-

CameraStateCallback

-

void OnConfigureFailed​(Camera& camera,int32_t errorCode)

-

camera配置失败回调

-

CameraStateCallback

-

void OnCreated​(Camera& camera)

-

camera创建成功回调

-

CameraStateCallback

-

void OnCreateFailed​(std::string cameraId,int32_t errorCode)

-

camera创建失败回调

-

CameraStateCallback

-

void OnReleased​(Camera& camera)

-

camera释放回调

-

FrameStateCallback

-

FrameStateCallback​()

-

帧状态回调类构造函数

-

FrameStateCallback

-

void OnFrameFinished(Camera& camera, FrameConfig& frameConfig, FrameResult& frameResult)

-

拍照帧完成回调

-

FrameStateCallback

-

void OnFrameError​(Camera& camera, FrameConfig& frameConfig, int32_t errorCode, FrameResult& frameResult)

-

拍照帧异常回调

-

FrameConfig

-

int32_t GetFrameConfigType()

-

获取帧配置类型

-

FrameConfig

-

std::list<OHOS::Surface> GetSurfaces()

-

获取帧配置的surface

-

FrameConfig

-

void AddSurface(OHOS::AGP::UISurface& surface);

-

添加surface

-

FrameConfig

-

void RemoveSurface(OHOS::AGP::UISurface& surface);

-

删除surface

-

FrameConfig

-

void GetVendorParameter(uint8_t *value, uint32_t len);

-

获取自定义参数

-

FrameConfig

-

void SetVendorParameter(uint8_t *value, uint32_t len);

-

设置自定义参数

-

CameraInfo

-

int32_t GetCameraType() const;

-

获取相机类型

-

CameraInfo

-

int32_t GetCameraFacingType() const;

-

获取相机朝向

-
- -## 约束与限制 - -无。 - -## 开发步骤 - -1. 实现设备状态回调的派生类,用户在设备状态发生变更(如新插入相机设备/相机掉线)时,自定义操作。 - - ``` - class SampleCameraDeviceCallback : public CameraDeviceCallback { - void OnCameraStatus(std::string cameraId, int32_t status) override - { - //do something when camera is available/unavailable - } - }; - ``` - -2. 实现帧事件回调的派生类,这里在拿到帧数据以后将其转存为文件。 - - ``` - static void SampleSaveCapture(const char *p, uint32_t size) - { - cout << "Start saving picture" << endl; - struct timeval tv; - gettimeofday(&tv, NULL); - struct tm *ltm = localtime(&tv.tv_sec); - if (ltm != nullptr) { - ostringstream ss("Capture_"); - ss << "Capture" << ltm->tm_hour << "-" << ltm->tm_min << "-" << ltm->tm_sec << ".jpg"; - - ofstream pic("/sdcard/" + ss.str(), ofstream::out | ofstream::trunc); - cout << "write " << size << " bytes" << endl; - pic.write(p, size); - cout << "Saving picture end" << endl; - } - } - - class TestFrameStateCallback : public FrameStateCallback { - void OnFrameFinished(Camera &camera, FrameConfig &fc, FrameResult &result) override - { - cout << "Receive frame complete inform." << endl; - if (fc.GetFrameConfigType() == FRAME_CONFIG_CAPTURE) { - cout << "Capture frame received." << endl; - list surfaceList = fc.GetSurfaces(); - for (Surface *surface : surfaceList) { - SurfaceBuffer *buffer = surface->AcquireBuffer(); - if (buffer != nullptr) { - char *virtAddr = static_cast(buffer->GetVirAddr()); - if (virtAddr != nullptr) { - SampleSaveCapture(virtAddr, buffer->GetSize()); - } - surface->ReleaseBuffer(buffer); - } - delete surface; - } - delete &fc; - } - } - }; - ``` - -3. 实现相机状态回调的派生类,当相机状态发生变化(配置成功/失败,创建成功/失败\)时,自定义操作。 - - ``` - class SampleCameraStateMng : public CameraStateCallback { - public: - SampleCameraStateMng() = delete; - SampleCameraStateMng(EventHandler &eventHdlr) : eventHdlr_(eventHdlr) {} - ~SampleCameraStateMng() - { - if (recordFd_ != -1) { - close(recordFd_); - } - } - void OnCreated(Camera &c) override - { - cout << "Sample recv OnCreate camera." << endl; - auto config = CameraConfig::CreateCameraConfig(); - config->SetFrameStateCallback(&fsCb_, &eventHdlr_); - c.Configure(*config); - cam_ = &c; - } - void OnCreateFailed(const std::string cameraId, int32_t errorCode) override {} - void OnReleased(Camera &c) override {} - }; - ``` - -4. 创建CameraKit,用于创建和获取camera信息。 - - ``` - CameraKit *camKit = CameraKit::GetInstance(); - list camList = camKit->GetCameraIds(); - string camId; - for (auto &cam : camList) { - cout << "camera name:" << cam << endl; - const CameraAbility *ability = camKit->GetCameraAbility(cam); - /* find camera which fits user's ability */ - list sizeList = ability->GetSupportedSizes(0); - if (find(sizeList.begin(), sizeList.end(), CAM_PIC_1080P) != sizeList.end()) { - camId = cam; - break; - } - } - ``` - -5. 创建Camera实例。 - - ``` - EventHandler eventHdlr; // Create a thread to handle callback events - SampleCameraStateMng CamStateMng(eventHdlr); - - camKit->CreateCamera(camId, CamStateMng, eventHdlr); - ``` - -6. 根据[步骤1](#li378084192111)、[步骤2](#li8716104682913)、[步骤3](#li6671035102514)中的回调设计,camera实例创建成功后会进行配置操作,主流程中app需要设计同步机制。 - - ``` - void OnCreated(Camera &c) override - { - cout << "Sample recv OnCreate camera." << endl; - auto config = CameraConfig::CreateCameraConfig(); - config->SetFrameStateCallback(&fsCb_, &eventHdlr_); - c.Configure(*config); - cam_ = &c; - } - - void Capture() - { - if (cam_ == nullptr) { - cout << "Camera is not ready." << endl; - return; - } - FrameConfig *fc = new FrameConfig(FRAME_CONFIG_CAPTURE); - Surface *surface = Surface::CreateSurface(); - if (surface == nullptr) { - delete fc; - return; - } - surface->SetWidthAndHeight(1920, 1080); /* 1920:width,1080:height */ - fc->AddSurface(*surface); - cam_->TriggerSingleCapture(*fc); - } - ``` - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/06.\345\252\222\344\275\223/01.\347\233\270\346\234\272/03.\345\275\225\345\203\217\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/06.\345\252\222\344\275\223/01.\347\233\270\346\234\272/03.\345\275\225\345\203\217\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index bae2c72e3170a46d7d6ba41fe228691e9bad033a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/06.\345\252\222\344\275\223/01.\347\233\270\346\234\272/03.\345\275\225\345\203\217\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,56 +0,0 @@ ---- -title: 录像开发指导 -permalink: /pages/0105060103 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 录像开发指导 - -- [使用场景](#section186634310418) -- [接口说明](#section125479541744) -- [约束与限制](#section1165911177314) -- [开发步骤](#section1196016315516) - -## 使用场景 - -使用camera采集视频码流。 - -## 接口说明 - -参考“拍照开发指导”的“接口说明”。 - -## 约束与限制 - -无。 - -## 开发步骤 - -1. 参考“拍照开发指导”中步骤1、步骤2、步骤3、步骤4。 -2. 获取录像FrameConfig。 - - ``` - /* 从recorder获取surface */ - Surface *surface = recorder_->GetSurface(0); - surface->SetWidthAndHeight(1920, 1080); - surface->SetQueueSize(3); - surface->SetSize(1024 * 1024); - /* 将surface配置到帧配置中 */ - FrameConfig *fc = new FrameConfig(FRAME_CONFIG_RECORD); - fc->AddSurface(*surface); - ``` - -3. 开启和停止录像。 - - ``` - stateCallback->camera_->TriggerLoopingCapture(*fc); // 开始录像 - stateCallback->camera_->StopLoopingCapture(); // 结束录像 - ``` - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/06.\345\252\222\344\275\223/01.\347\233\270\346\234\272/04.\351\242\204\350\247\210\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/06.\345\252\222\344\275\223/01.\347\233\270\346\234\272/04.\351\242\204\350\247\210\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index 21d86a957fcb6b39edc1df41675119f489fd4e6c..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/06.\345\252\222\344\275\223/01.\347\233\270\346\234\272/04.\351\242\204\350\247\210\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,56 +0,0 @@ ---- -title: 预览开发指导 -permalink: /pages/0105060104 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 预览开发指导 - -- [使用场景](#section186634310418) -- [接口说明](#section125479541744) -- [约束与限制](#section1165911177314) -- [开发步骤](#section34171333656) - -## 使用场景 - -使用camera产生视频流并播放。 - -## 接口说明 - -参考“拍照开发指导”的“接口说明”。 - -## 约束与限制 - -无。 - -## 开发步骤 - -1. 参考“拍照开发指导”中步骤1、步骤2、步骤3、步骤4。 -2. 设置预览显示的区域。 - - ``` - Surface *surface = Surface::CreateSurface(); - /* 设置显示区域 */ - surface->SetUserData("region_position_x", "480"); // 矩形左上角横坐标 - surface->SetUserData("region_position_y", "270"); // 矩形左上角纵坐标 - surface->SetUserData("region_width", "960"); // 宽 - surface->SetUserData("region_height", "540"); // 高 - - fc->AddSurface(*surface); - ``` - -3. 开始和结束预览。 - - ``` - stateCallback->camera_->TriggerLoopingCapture(*fc); // start previewing - stateCallback->camera_->StopLoopingCapture(); // stop previewing - ``` - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/06.\345\252\222\344\275\223/02.\351\237\263\350\247\206\351\242\221/01.\351\237\263\350\247\206\351\242\221\345\274\200\345\217\221\346\246\202\350\277\260.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/06.\345\252\222\344\275\223/02.\351\237\263\350\247\206\351\242\221/01.\351\237\263\350\247\206\351\242\221\345\274\200\345\217\221\346\246\202\350\277\260.md" deleted file mode 100644 index ea53674bd6c3768e0977dc21eb776d4fb9fd58b4..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/06.\345\252\222\344\275\223/02.\351\237\263\350\247\206\351\242\221/01.\351\237\263\350\247\206\351\242\221\345\274\200\345\217\221\346\246\202\350\277\260.md" +++ /dev/null @@ -1,94 +0,0 @@ ---- -title: 音视频开发概述 -permalink: /pages/0105060201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 音视频开发概述 - -- [基本概念](#section967213571204) -- [编解码规格](#section1582020483111) - -OpenHarmony音视频包括音视频播放和录制。 - -- OpenHarmony音视频播放模块支持音视频播放业务的开发,主要包括音视频文件和音视频流播放、音量和播放进度控制等。 -- OpenHarmony录制模块支持音视频录制业务的开发,提供音视频录制相关的功能,包括设置录制视频画面尺寸、音视频编码码率、编码器类型、视频帧率、音频采样率、录制文件输出格式等。 - -## 基本概念 - -在进行应用的开发OpenHarmony前,开发者应了解以下基本概念: - -- 流媒体技术 - - 流媒体技术是把连续的影像和声音信息进行编码处理后放在网络服务器上,让浏览者一边下载、一边观看与收听,而不需要等整个多媒体文件下载完成就可以即时观看、收听的技术。 - - -- 视频帧率 - - 帧率是用于测量显示帧数的度量,帧数就是在每秒钟时间里传输的图片数量。每秒钟帧数 \(FPS\) 越多,所显示的画面就会越流畅。 - -- 码率 - - 码率就是数据传输时单位时间传送的数据位数,常用单位是kbps即千位每秒。 - -- 采样率 - - 采样率为每秒从连续信号中提取并组成离散信号的采样个数,单位用赫兹(Hz)来表示。 - - -## 编解码规格 - -OpenHarmony音视频编解码能力取决于具体设备类型,以当前已支持的开发板为例,规格见下表: - -**表 1** 不同开发板编解码规格 - - - - - - - - - - - - - - - - - - - - - - - - -

设备类型

-

开发板类型

-

解码规格

-

编码规格

-

带屏摄像头类产品

-

Hi3516

-
  • 音频解码:支持MPEG-4 AAC Profile (AAC LC)、MPEG Audio Layer 3 (MP3)格式解码,支持单/双声道,支持MPEG-4(.mp4,.m4a)、MP3(.mp3)容器格式。
  • 视频解码:支持H.265 HEVC/H.264 AVC格式解码(限自身编码码流),支持MPEG-4(.mp4)容器格式。
-
  • 音频编码:支持音频AAC_LC编码,支持单/双声道,支持MPEG-4(.mp4)容器格式。
  • 视频编码:支持视频H.264/H.265编码,支持MPEG-4(.mp4)容器格式。
-

无屏摄像头类产品

-

Hi3518

-
  • 音频解码:支持MPEG-4 AAC Profile (AAC LC)、MPEG Audio Layer 3 (MP3)格式解码,支持单/双声道,支持MPEG-4(.mp4,.m4a)、MP3(.mp3)容器格式。
  • 视频解码:-
-
  • 音频编码:支持音频AAC_LC编码,支持单/双声道,支持MPEG-4(.mp4)容器格式。
  • 视频编码:支持视频H.264/H.265编码,支持MPEG-4(.mp4)容器格式。
-

WLAN连接类设备

-

Hi3861

-

-

-

-

-
- -Hi3516和Hi3518更多详细的编解码规格请参考开发板自带的资料。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/06.\345\252\222\344\275\223/02.\351\237\263\350\247\206\351\242\221/02.\351\237\263\350\247\206\351\242\221\346\222\255\346\224\276\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/06.\345\252\222\344\275\223/02.\351\237\263\350\247\206\351\242\221/02.\351\237\263\350\247\206\351\242\221\346\222\255\346\224\276\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index 5e32c989bb2949703fb856d9d404acde37418bc4..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/06.\345\252\222\344\275\223/02.\351\237\263\350\247\206\351\242\221/02.\351\237\263\350\247\206\351\242\221\346\222\255\346\224\276\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,355 +0,0 @@ ---- -title: 音视频播放开发指导 -permalink: /pages/0105060202 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 音视频播放开发指导 - -- [使用场景](#section186634310418) -- [接口说明](#section125479541744) -- [约束与限制](#section1165911177314) -- [开发步骤](#section34171333656) - -## 使用场景 - -音视频播放是将音视频文件或音视频流数据进行解码并通过输出设备进行播放的过程,同时对播放任务进行管理。 - -## 接口说明 - -音视频播放API接口功能如下,具体的API详见接口文档。 - -**表 1** 音视频播放API接口 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

类名

-

接口名

-

描述

-

Player

-

int32_t SetSource(const Source &source);

-

设置播放源

-

Player

-

int32_t Prepare();

-

准备播放

-

Player

-

int32_t Play();

-

开始播放

-

Player

-

bool IsPlaying()

-

判断是否播放中

-

Player

-

int32_t Pause();

-

暂停播放

-

Player

-

int32_t Stop();

-

停止播放

-

Player

-

int32_t Rewind(int_64 mSeconds, int32_t mode);

-

改变播放位置

-

Player

-

int32_t SetVolume(float leftVolume, float rightVolume);

-

设置音量,包括左声道和右声道。

-

Player

-

int32_t SetVideoSurface(Surface *surface)

-

设置播放窗口

-

Player

-

int32_t EnableSingleLooping(bool loop)

-

设置循环播放

-

Player

-

bool IsSingleLooping();

-

判断是否循环播放

-

Player

-

int32_t GetCurrentTime(int64_t &time) const;

-

获取当前播放时长

-

Player

-

int32_t GetDuration(int64_t &duration) const;

-

获取总播放时长

-

Player

-

int32_t GetVideoWidth(int32_t &videoWidth);

-

获取视频源宽度

-

Player

-

int32_t GetVideoHeight(int32_t &videoHeight);

-

获取视频源高度

-

Player

-

int32_t Reset();

-

重置播放器

-

Player

-

int32_t Release();

-

释放播放器资源

-

Player

-

void SetPlayerCallback(const std::shared_ptr<PlayerCallback> &cb);

-

设置播放回调函数

-

Source

-

Source(const std::string& uri);

-

基于uri创建Source实例

-

Source

-

Source(const std::shared_ptr<StreamSource> &stream, const Format &formats);

-

基于流创建Source实例

-

Source

-

SourceType GetSourceType() const;

-

获取源类型

-

Source

-

const std::string &GetSourceUri() const;

-

获取音视频uri

-

Source

-

const std::shared_ptr<StreamSource> &GetSourceStream() const;

-

获取音视频流

-

Source

-

const Format &GetSourceStreamFormat() const;

-

获取音视频流格式

-

Format

-

bool PutIntValue(const std::string &key, int32_t value);

-

设置整数类型的元数据

-

Format

-

bool PutLongValue(const std::string &key, int64_t value);

-

设置长整数类型的元数据

-

Format

-

bool PutFloatValue(const std::string &key, float value);

-

设置单精度浮点类型的元数据

-

Format

-

bool PutDoubleValue(const std::string &key, double value);

-

设置双精度浮点类型的元数据

-

Format

-

bool PutStringValue(const std::string &key, const std::string &value);

-

设置字符串类型的元数据

-

Format

-

bool GetIntValue(const std::string &key, int32_t &value) const;

-

获取整数类型的元数据值

-

Format

-

bool GetLongValue(const std::string &key, int64_t &value) const;

-

获取长整数类型的元数据值

-

Format

-

bool GetFloatValue(const std::string &key, float &value) const;

-

获取单精度浮点类型的元数据值

-

Format

-

bool GetDoubleValue(const std::string &key, double &value) const;

-

获取双精度浮点类型的元数据值

-

Format

-

bool GetStringValue(const std::string &key, std::string &value) const;

-

获取字符串类型的元数据值

-

Format

-

const std::map<std::string, FormatData *> &GetFormatMap() const;

-

获取元数据映射表

-

Format

-

bool CopyFrom(const Format &format);

-

用输入Format设置所有元数据

-
- -## 约束与限制 - -输入源为音视频流时,不支持播放进度控制和获取文件时长。 - -## 开发步骤 - -1. 实现PlayerCallback回调,通过SetPlayerCallback函数进行绑定,用于事件处理。 - - ``` - class TestPlayerCallback : public PlayerCallback{ - void OnPlaybackComplete() override - { - //此处实现代码用于处理文件播放完成的事件 - } - void OnError(int32_t errorType, int32_t errorCode) override - { - //此处实现代码处理错误事件 - } - void OnInfo(int type, int extra) override - { - //此处实现代码处理普通事件 - } - void OnRewindToComplete() override - { - //此处实现代码处理进度控制完成的事件 - } - }; - - ``` - -2. 创建Player实例,设置播放源并开始播放。 - - ``` - Player *player = new Player(); - std::shared_ptr callback = std::make_shared(); - player->SetPlayerCallback(callback);//设置player回调 - std::string uri(filePath);//此处filePath为本地文件路径 - Source source(uri);//保存uri到source实例 - player->SetSource(source);//将source设置到player - player->Prepare();//准备播放 - player->SetVideoSurface(surface);//设置播放窗口 - player->Play();//开始播放 - ``` - -3. 根据场景需要进行播放控制。 - - ``` - player->SetVolume(lvolume, rvolume);//设置左右声道声音 - player->EnableSingleLooping(true);//设置循环播放 - player->Pause();//暂停 - player->Play();//继续播放 - ``` - -4. 播放任务结束后,进行资源释放。 - - ``` - player->Stop(); //停止播放 - player->Release();//释放资源 - ``` - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/06.\345\252\222\344\275\223/02.\351\237\263\350\247\206\351\242\221/03.\351\237\263\350\247\206\351\242\221\345\275\225\345\210\266\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/06.\345\252\222\344\275\223/02.\351\237\263\350\247\206\351\242\221/03.\351\237\263\350\247\206\351\242\221\345\275\225\345\210\266\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index 5128f4fbae1ac82273d7b5055217a023a82eea26..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/06.\345\252\222\344\275\223/02.\351\237\263\350\247\206\351\242\221/03.\351\237\263\350\247\206\351\242\221\345\275\225\345\210\266\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,300 +0,0 @@ ---- -title: 音视频录制开发指导 -permalink: /pages/0105060203 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 音视频录制开发指导 - -- [使用场景](#section186634310418) -- [接口说明](#section125479541744) -- [约束与限制](#section1165911177314) -- [开发步骤](#section34171333656) - -## 使用场景 - -音视频录制的主要功能是录制音视频,并根据设置的编码格式、采样率、码率等参数封装输出文件。 - -## 接口说明 - -音视频录制API接口如下,具体的API详见接口文档。 - -**表 1** 音视频录制API接口 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

类名

-

接口名

-

功能

-

Recorder

-

int32_t SetVideoSource(VideoSourceType source, int32_t &sourceId)

-

设置录制视频源

-

Recorder

-

int32_t SetVideoEncoder(int32_t sourceId, VideoCodecFormat encoder)

-

设置录制的视频编码器类型

-

Recorder

-

int32_t SetVideoSize(int32_t sourceId, int32_t width, int32_t height)

-

设置录制的视频宽和高

-

Recorder

-

int32_t SetVideoFrameRate(int32_t sourceId, int32_t frameRate)

-

设置要录制的视频帧率

-

Recorder

-

int32_t SetVideoEncodingBitRate(int32_t sourceId, int32_t rate)

-

设置录制视频编码的码率

-

Recorder

-

int32_t SetCaptureRate(int32_t sourceId, double fps)

-

设置视频帧的捕获帧率

-

Recorder

-

std::shared_ptr<OHOS::Surface> GetSurface(int32_t sourceId);

-

获取对应输入源的surface

-

Recorder

-

int32_t SetAudioSource(AudioSourceType source, int32_t &sourceId)

-

设置录制音频源

-

Recorder

-

int32_t SetAudioEncoder(int32_t sourceId, AudioCodecFormat encoder)

-

设置录制的音频编码器类型

-

Recorder

-

int32_t SetAudioSampleRate(int32_t sourceId, int32_t rate)

-

设置录制的音频采样率

-

Recorder

-

int32_t SetAudioChannels(int32_t sourceId, int32_t num)

-

设置要录制的音频通道数

-

Recorder

-

int32_t SetAudioEncodingBitRate(int32_t sourceId, int32_t bitRate)

-

设置录制音频编码的码率

-

Recorder

-

int32_t SetMaxDuration(int32_t duration)

-

设置录制文件的最大时长

-

Recorder

-

int32_t SetOutputFormat(OutputFormatType format)

-

设置输出文件格式

-

Recorder

-

int32_t SetOutputPath(const string &path);

-

设置输出文件保存路径

-

Recorder

-

int32_t SetOutputFile(int32_t fd)

-

设置输出文件的fd

-

Recorder

-

int32_t SetNextOutputFile(int32_t fd);

-

设置下一个输出文件的fd

-

Recorder

-

int32_t SetMaxFileSize(int64_t size)

-

设置录制会话的最大文件大小

-

Recorder

-

int32_t SetRecorderCallback(const std::shared_ptr<RecorderCallback> &callback)

-

注册录制侦听器回调

-

Recorder

-

int32_t Prepare()

-

准备录制

-

Recorder

-

int32_t Start()

-

开始录制

-

Recorder

-

int32_t Pause()

-

暂停录制

-

Recorder

-

int32_t Resume()

-

恢复录制

-

Recorder

-

int32_t Stop(bool block)

-

停止录制

-

Recorder

-

int32_t Reset();

-

重置录制

-

Recorder

-

int32_t Release()

-

释放录制资源

-

Recorder

-

int32_t SetFileSplitDuration(FileSplitType type, int64_t timestamp, uint32_t duration)

-

设置切分录像

-

Recorder

-

int32_t SetParameter(int32_t sourceId, const Format &format)

-

设置录制的扩展参数

-
- -## 约束与限制 - -无。 - -## 开发步骤 - -1. 创建Recorder实例。 - - ``` - Recorder *recorder = new Recorder(); - ``` - -2. 设置Recorder参数,包括设置音视频源信息,音视频编码格式,采样率,码率,视频宽高等信息。 - - ``` - int32_t sampleRate = 48000; - int32_t channelCount = 1; - AudioCodecFormat audioFormat = AAC_LC; - AudioSourceType inputSource = AUDIO_MIC; - int32_t audioEncodingBitRate = sampleRate; - VideoSourceType source = VIDEO_SOURCE_SURFACE_ES; - int32_t frameRate = 30; - double fps = 30; - int32_t rate = 4096; - int32_t sourceId = 0; - int32_t audioSourceId = 0; - int32_t width = 1920; - int32_t height = 1080; - VideoCodecFormat encoder = H264; - recorder->SetVideoSource(source, sourceId ); // 设置视频源,获得sourceId - recorder->SetVideoEncoder(sourceId, encoder); // 设置视频编码格式 - recorder->SetVideoSize(sourceId, width, height); // 设置视频宽高 - recorder->SetVideoFrameRate(sourceId, frameRate); // 设置视频帧率 - recorder->SetVideoEncodingBitRate(sourceId, rate); // 设置视频编码码率 - recorder->SetCaptureRate(sourceId, fps); // 设置视频帧的捕获帧率 - recorder->SetAudioSource(inputSource, audioSourceId); // 设置音频源,获得audioSourceId - recorder->SetAudioEncoder(audioSourceId, audioFormat); // 设置音频编码格式 - recorder->SetAudioSampleRate(audioSourceId, sampleRate); // 设置音频采样率 - recorder->SetAudioChannels(audioSourceId, channelCount); // 设置音频通道数 - recorder->SetAudioEncodingBitRate(audioSourceId, audioEncodingBitRate); // 设置音频编码码率 - ``` - -3. 准备录制,Recorder进行录制前的准备工作。 - - ``` - recorder->Prepare(); // 准备录制 - ``` - -4. 开始录制,Recorder会根据设置的音频源和视频源进行录制。 - - ``` - recorder->Start(); // 开始录制 - ``` - -5. 结束录制,释放资源。 - - ``` - recorder->Stop(); // 停止录制 - recorder->Release(); // 释放录制资源 - ``` - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/07.\345\205\254\345\205\261\345\237\272\347\241\200/01.\345\205\254\345\205\261\345\237\272\347\241\200\345\272\223\346\246\202\350\277\260.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/07.\345\205\254\345\205\261\345\237\272\347\241\200/01.\345\205\254\345\205\261\345\237\272\347\241\200\345\272\223\346\246\202\350\277\260.md" deleted file mode 100644 index de573dbcb99171ee2ab1e89952d71301959b784c..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/07.\345\205\254\345\205\261\345\237\272\347\241\200/01.\345\205\254\345\205\261\345\237\272\347\241\200\345\272\223\346\246\202\350\277\260.md" +++ /dev/null @@ -1,23 +0,0 @@ ---- -title: 公共基础库概述 -permalink: /pages/01050701 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 公共基础库概述 - -公共基础库存放OpenHarmony通用的基础组件。这些基础组件可被OpenHarmony各业务子系统及上层应用所使用。 - -公共基础库在不同平台上提供的能力: - -LiteOS-M内核\(Hi3861平台\):KV存储、文件操作、IoT外设控制、Dump系统属性。 - -LiteOS-A内核\(Hi3516、Hi3518平台\):KV存储、定时器、数据和文件存储的JS API、Dump系统属性。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/07.\345\205\254\345\205\261\345\237\272\347\241\200/02.\345\205\254\345\205\261\345\237\272\347\241\200\345\272\223\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/07.\345\205\254\345\205\261\345\237\272\347\241\200/02.\345\205\254\345\205\261\345\237\272\347\241\200\345\272\223\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index 763d6e265a1cb4064196f3cd4ead64b1721ca427..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/07.\345\205\254\345\205\261\345\237\272\347\241\200/02.\345\205\254\345\205\261\345\237\272\347\241\200\345\272\223\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,309 +0,0 @@ ---- -title: 公共基础库开发指导 -permalink: /pages/01050702 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 公共基础库开发指导 - -- [接口说明](#section1633115419401) -- [开发步骤](#section17450172710292) - - [LiteOS-A内核\(Hi3516、Hi3518平台\)KV存储的native应用开发步骤:](#section258354119295) - - [Dump系统属性在LiteOS-M内核平台使用指南:](#section9179161863014) - - [Dump系统属性在LiteOS-A内核平台使用指南:](#section3179121853017) - - -## 接口说明 - -**表 1** 文件操作接口说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

接口名

-

描述

-

int UtilsFileOpen(const char* path, int oflag, int mode)

-

打开或创建文件

-

int UtilsFileClose(int fd)

-

关闭文件

-

int UtilsFileRead(int fd, char *buf, unsigned int len)

-

读取特定长度的文件数据

-

int UtilsFileWrite(int fd, const char *buf, unsigned int len)

-

向文件写入特定大小的数据

-

int UtilsFileDelete(const char *path)

-

删除指定文件

-

int UtilsFileStat(const char *path, unsigned int *fileSize)

-

获取文件大小

-

int UtilsFileSeek(int fd, int offset, unsigned int whence)

-

重新定位文件读/写偏移量

-

int UtilsFileCopy(const char* src, const char* dest)

-

将源文件复制一份并存储到目标文件

-

int UtilsFileMove(const char* src, const char* dest)

-

将源文件移动到指定目标文件

-
- -文件操作使用示例: - -``` -// open && write -char fileName[] = "testfile"; -static const char def[] = "utils_file_operation implement."; -int fd = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS | O_TRUNC_FS, 0); -printf("file handle = %d\n", fd); -int ret = UtilsFileWrite(fd, def, strlen(def)); -printf("write ret = %d\n", ret); - -// seek -ret = UtilsFileSeek(fd, 5, SEEK_SET_FS); -printf("lseek ret = %d\n", ret); - -// read && close -char buf[64] = {0}; -int readLen = UtilsFileRead(fd, buf, 64); -ret = UtilsFileClose(fd); -printf("read len = %d : buf = %s\n", readLen, buf); - -// stat -int fileLen = 0; -ret = UtilsFileStat(fileName, &fileLen); -printf("file size = %d\n", fileLen); - -// delete -ret = UtilsFileDelete(fileName); -printf("delete ret = %d\n", ret); -``` - -**表 2** KV存储接口说明 - - - - - - - - - - - - - - - - -

接口名

-

描述

-

int UtilsGetValue(const char* key, char* value, unsigned int len)

-

提供给上层应用根据key获取对应数据项

-

int UtilsSetValue(const char* key, const char* value)

-

提供给上层应用用于存储/更新key对应数据项

-

int UtilsDeleteValue(const char* key)

-

提供给上层应用删除key对应数据项

-
- -KV存储使用示例: - -``` -// set -char key[] = "rw.sys.version_100"; -char value[] = "Hello kv operation implement!"; -int ret = UtilsSetValue(key, value); -printf("UtilsSetValue set ret = %d\n", ret); - -// get -char temp[128] = {0}; -ret = UtilsGetValue(key, temp, 128); -printf("UtilsGetValue get ret = %d, temp = %s\n", ret, temp); - -// delete -ret = UtilsDeleteValue(key); -printf("UtilsDeleteValue delete ret = %d\n", ret); -``` - - - - -
- -## 开发步骤 - -### LiteOS-A内核\(Hi3516、Hi3518平台\)KV存储的native应用开发步骤: - -1. 基于AbilityKit开发KV存储的native应用。 - - 基于KV存储提供的接口编写用户程序,并编译出so(libLauncher.so)文件。 - - ``` - // set - char key[] = "rw.sys.version_100"; - char value[] = "Hello kv operation implement!"; - int ret = UtilsSetValue(key, value); - printf("UtilsSetValue set ret = %d\n", ret); - - // get - char temp[128] = {0}; - ret = UtilsGetValue(key, temp, 128); - printf("UtilsGetValue get ret = %d, temp = %s\n", ret, temp); - - // delete - ret = UtilsDeleteValue(key); - printf("UtilsDeleteValue delete ret = %d\n", ret); - ``` - - - 编写config.json文件,内容如下: - - ``` - { - "app": { - "bundleName": "com.huawei.launcher", - "vendor": "huawei", - "version": { - "code": 1, - "name": "1.0" - } - }, - "deviceConfig": { - "default": { - "reqSdk": { - "compatible": "zsdk 1.0.0", - "target": "zsdk 1.0.1" - }, - "keepAlive": false - }, - "smartCamera": { - "reqSdk": { - "compatible": "zsdk 1.0.0", - "target": "zsdk 1.0.1" - }, - "keepAlive": false - } - }, - "module": { - "package": "com.huawei.launcher", - "name": ".MyHarmonyAbilityPackage", - "deviceType": [ - "phone", "tv","tablet", "pc","car","smartWatch","sportsWatch","smartCamera" - ], - "distro": { - "deliveryWithInstall": true, - "moduleName": "Launcher", - "moduleType": "entry" - }, - "abilities": [{ - "name": "MainAbility", - "icon": "res/drawable/phone.png", - "label": "test app 1", - "launchType": "standard", - "type": "page" - }, - { - "name": "SecondAbility", - "icon": "res/drawable/phone.png", - "label": "test app 2", - "launchType": "standard", - "type": "page" - }, - { - "name": "ServiceAbility", - "icon": "res/drawable/phone.png", - "label": "test app 2", - "launchType": "standard", - "type": "service" - } - ] - } - } - ``` - - - 生成hap包。 - - - 按照如下目录结构存放文件,res/drawable下面放置资源文件: - - ![](/images/device-dev/subsystems/figure/unnaming.png) - - - 将上述文件打包生成zip包,修改后缀为.hap,例如Launcher.hap - -2. 连接单板,通过串口向单板发送安装KV存储native应用的命令。 - - ``` - ./nfs/dev_tools/bin/bm install -p /nfs/Launcher.hap - ``` - -3. 通过串口向单板发送运行KV存储native应用的命令。 - - ``` - ./nfs/dev_tools/bin/aa start -p com.huawei.launcher -n ServiceAbility - ``` - - -### Dump系统属性在LiteOS-M内核平台使用指南: - -1. 连接单板,通过串口向单板发送AT+SYSPARA命令。 - - ``` - AT+SYSPARA - ``` - - **图 1** LiteOS-M平台dump系统属性输出 - ![](/images/device-dev/subsystems/figure/LiteOS-M平台dump系统属性输出.png "LiteOS-M平台dump系统属性输出") - - -### Dump系统属性在LiteOS-A内核平台使用指南: - -1. 连接单板,运行bin路径下的os\_dump加参数--help,查看os\_dump使用指导。 - - ``` - ./bin/os_dump --help - ``` - -2. os\_dump加参数-l,查看当前系统有哪些模块支持获取属性。 - - ``` - ./bin/os_dump -l - ``` - -3. os\_dump加参数syspara,查看当前系统属性 - - ``` - ./bin/os_dump syspara - ``` - - **图 2** LiteOS-A平台dump系统属性输出 - ![](/images/device-dev/subsystems/figure/LiteOS-A平台dump系统属性输出.png "LiteOS-A平台dump系统属性输出") - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/07.\345\205\254\345\205\261\345\237\272\347\241\200/03.\345\205\254\345\205\261\345\237\272\347\241\200\345\272\223\345\270\270\350\247\201\351\227\256\351\242\230.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/07.\345\205\254\345\205\261\345\237\272\347\241\200/03.\345\205\254\345\205\261\345\237\272\347\241\200\345\272\223\345\270\270\350\247\201\351\227\256\351\242\230.md" deleted file mode 100644 index 526782e5d615aba5967d6909935075297d53fdb1..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/07.\345\205\254\345\205\261\345\237\272\347\241\200/03.\345\205\254\345\205\261\345\237\272\347\241\200\345\272\223\345\270\270\350\247\201\351\227\256\351\242\230.md" +++ /dev/null @@ -1,35 +0,0 @@ ---- -title: 公共基础库常见问题 -permalink: /pages/01050703 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 公共基础库常见问题 - -- [1.LiteOS-A内核\(Hi3516、Hi3518平台\)KV存储路径设置错误,导致KV存储运行失败](#section2041345718513) - -## 1.LiteOS-A内核\(Hi3516、Hi3518平台\)KV存储路径设置错误,导致KV存储运行失败 - -**现象描述** - -LiteOS-A内核\(Hi3516、Hi3518平台\)直接调用KV存储提供的接口,各参数正常的情况下,编译可执行程序运行失败。 - -**可能原因** - -直接运行编译出的可执行文件,没有将程序基于AbilityKit转换成应用,不能由BMS在应用安装时正确设置应用数据存储路径,导致KV存储运行失败。 - -**解决办法** - -显示调用KV存储的UtilsSetEnv接口,设置数据存储路径。 - -``` -UtilsSetEnv("/storage/com.huawei.kv"); -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/08.AI\346\241\206\346\236\266/01.\346\246\202\350\277\260.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/08.AI\346\241\206\346\236\266/01.\346\246\202\350\277\260.md" deleted file mode 100644 index 6c91caf4ebf0f5331be63ba8fa46bbfb043f31f6..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/08.AI\346\241\206\346\236\266/01.\346\246\202\350\277\260.md" +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: 概述 -permalink: /pages/01050801 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# AI引擎框架开发指南 - -AI业务子系统是OpenHarmony提供原生的分布式AI能力的子系统。AI业务子系统提供了统一的AI引擎框架,实现算法能力快速插件化集成。框架中主要包含插件管理、模块管理和通信管理等模块,完成对AI算法能力的生命周期管理和按需部署。插件管理主要实现插件的生命周期管理及插件的按需部署,快速集成AI能力插件;模块管理主要实现任务的调度及管理客户端的实例;通信管理主要实现客户端和服务端之间的跨进程通信及引擎与插件之间的数据传输。后续,会逐步定义统一的AI能力接口,便于AI能力的分布式调用。同时,提供适配不同推理框架层级的统一推理接口。AI引擎框架如下[图1](#fig143186187187)所示。 - -**图 1** AI引擎框架 - - -![](/images/device-dev/subsystems/figure/zh-cn_image_0000001077727032.png) - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/08.AI\346\241\206\346\236\266/02.\346\220\255\345\273\272\347\216\257\345\242\203.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/08.AI\346\241\206\346\236\266/02.\346\220\255\345\273\272\347\216\257\345\242\203.md" deleted file mode 100644 index f618e40564045b0f8bc9e93919bad2c5808e84c5..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/08.AI\346\241\206\346\236\266/02.\346\220\255\345\273\272\347\216\257\345\242\203.md" +++ /dev/null @@ -1,18 +0,0 @@ ---- -title: 搭建环境 -permalink: /pages/01050802 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 搭建环境 - -1. 准备开发板:Hi3516DV300,Hi3518EV300 -2. [下载源码](/pages/extra/51fbe5/) - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/08.AI\346\241\206\346\236\266/03.\346\212\200\346\234\257\350\247\204\350\214\203/01.\344\273\243\347\240\201\347\256\241\347\220\206\350\247\204\350\214\203.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/08.AI\346\241\206\346\236\266/03.\346\212\200\346\234\257\350\247\204\350\214\203/01.\344\273\243\347\240\201\347\256\241\347\220\206\350\247\204\350\214\203.md" deleted file mode 100644 index 284d5d47825350300e595636100443356aa6f520..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/08.AI\346\241\206\346\236\266/03.\346\212\200\346\234\257\350\247\204\350\214\203/01.\344\273\243\347\240\201\347\256\241\347\220\206\350\247\204\350\214\203.md" +++ /dev/null @@ -1,53 +0,0 @@ ---- -title: 代码管理规范 -permalink: /pages/0105080301 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 代码管理规范 - -- [建议:插件与北向SDK在AI引擎指定的路径下进行代码开发](#section17176374131) -- [规则:插件提供的全部对外接口,统一存放在AI业务子系统interfaces/kits目录](#section2551029111312) -- [规则:插件编译输出路径必须是在/usr/lib](#section97021558121310) - -AI引擎框架包含client、server和common三个主要模块,其中client提供server端连接管理功能,北向SDK在算法对外接口中需封装调用client提供的公共接口;server提供插件加载以及任务管理等功能,各Plugin实现由server提供的插件接口,完成插件接入;common提供与平台相关的操作方法、引擎协议以及相关工具类,供其他各模块调用。 - -AI引擎框架各模块之间的代码依赖关系如下[图1](#fig171811112818)所示: - -**图 1** ****AI引擎代码依赖关系 - - -![](/images/device-dev/subsystems/figure/插件依赖-(2).jpg) - -## 建议:插件与北向SDK在AI引擎指定的路径下进行代码开发 - -在AI引擎框架的整体规划中,北向SDK属于client端的一部分,插件由server端调用,属于server端的一部分,因此AI引擎框架为接入的插件与北向SDK规划的路径: - -- SDK代码路径://foundation/ai/engine/services/client/algorithm\_sdk - - e.g. //foundation/ai/engine/services/client/algorithm\_sdk/cv - - e.g. //foundation/ai/engine/services/client/algorithm\_sdk/nlu - -- 插件代码路径://foundation/ai/engine/services/server/plugin - - e.g. //foundation/ai/engine/services/server/plugin/cv - - e.g. //foundation/ai/engine/services/server/plugin/nlu - - -## 规则:插件提供的全部对外接口,统一存放在AI业务子系统interfaces/kits目录 - -北向SDK对外接口是AI业务子系统提供能力的对外暴露方式,按照OpenHarmony的接口管理要求,需统一存放在各子系统的interfaces/kits目录中。当前AI业务子系统插件对外接口路径为//foundation/ai/engine/interfaces/kits,不同插件可在该路径下添加目录,比如增加cv插件,则在路径//foundation/ai/engine/interfaces/kits/cv下面存放接口文件。 - -## 规则:插件编译输出路径必须是在/usr/lib - -server端加载插件是采用dlopen方式,只支持在/usr/lib路径进行,因此插件在编译so时,需要在编译配置文件中指定输出路径为/usr/lib。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/08.AI\346\241\206\346\236\266/03.\346\212\200\346\234\257\350\247\204\350\214\203/02.\345\221\275\345\220\215\350\247\204\350\214\203.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/08.AI\346\241\206\346\236\266/03.\346\212\200\346\234\257\350\247\204\350\214\203/02.\345\221\275\345\220\215\350\247\204\350\214\203.md" deleted file mode 100644 index 26ac43bb097db47ebefa09870bba99a7062d05e1..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/08.AI\346\241\206\346\236\266/03.\346\212\200\346\234\257\350\247\204\350\214\203/02.\345\221\275\345\220\215\350\247\204\350\214\203.md" +++ /dev/null @@ -1,32 +0,0 @@ ---- -title: 命名规范 -permalink: /pages/0105080302 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 命名规范 - -- [SDK命名规则:领域\_关键词<\_其他信息1\_其他信息2\_…\>\_sdk.so](#section62071110121516) -- [插件命名规则:领域\_关键词<\_其他信息1\_其他信息2\_…\>.so](#section1665562841519) - -## SDK命名规则:领域\_关键词<\_其他信息1\_其他信息2\_…\>\_sdk.so - -关于领域,建议使用当前主流简称,比如图片视频相关的使用"cv",语音识别相关的使用“asr”,翻译相关的使用“translation”等,存在其他领域的可增加定义;关键词则需要恰当准确的描述所对应插件的算法能力,比如唤醒词识别,则使用keyword\_spotting;对于其他信息,比如插件支持的芯片类型、国内海外等信息,可在关键词与“SDK”之间依次添加,每个信息之间以下划线连接;北向sdk命名,必须以“SDK”结尾。 - -例如:唤醒词识别插件对应 的SDK,只支持麒麟9000芯片,适用于中国国内地区适用,则对应的SDK命名为:asr\_keyword\_spotting\_kirin9000\_china\_sdk.so - -## 插件命名规则:领域\_关键词<\_其他信息1\_其他信息2\_…\>.so - -插件命名的领域、关键词、其他信息等名词解释与要求,均与sdk命名要求保持一致。 - -插件与sdk存在一一对应的关系,故两者命名在领域、关键词、其他信息上要保持一致,两者唯一的不同之处在于sdk命名多了个“\_sdk”结尾;比如插件命名为“asr\_keyword\_spotting.so”,则对应北向SDK命名为“asr\_keyword\_spotting\_sdk.so”。 - -例如:唤醒词识别插件对应的SDK,只支持麒麟9000芯片,适用于中国国内地区适用,则对应的插件命名为:asr\_keyword\_spotting\_kirin9000\_china.so - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/08.AI\346\241\206\346\236\266/03.\346\212\200\346\234\257\350\247\204\350\214\203/03.\346\216\245\345\217\243\345\274\200\345\217\221\350\247\204\350\214\203.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/08.AI\346\241\206\346\236\266/03.\346\212\200\346\234\257\350\247\204\350\214\203/03.\346\216\245\345\217\243\345\274\200\345\217\221\350\247\204\350\214\203.md" deleted file mode 100644 index cbe6a6f7f7a1be84fdfe5660536db2e71326d390..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/08.AI\346\241\206\346\236\266/03.\346\212\200\346\234\257\350\247\204\350\214\203/03.\346\216\245\345\217\243\345\274\200\345\217\221\350\247\204\350\214\203.md" +++ /dev/null @@ -1,150 +0,0 @@ ---- -title: 接口开发规范 -permalink: /pages/0105080303 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 接口开发规范 - -- [规则:SDK需按算法调用顺序,封装client对外提供接口;对于异步插件对应的SDK,需要实现client提供的回调接口IClientCb](#section15872017171616) -- [规则:SDK接口实现中,需要保存与client交互的相关通用数据](#section011283741612) -- [建议:SDK实现client定义的IServiceDeadCb接口](#section1199125331613) -- [规则:SDK与plugin需要使用编解码模块,将特定算法数据转换成AI引擎的通用数据类型](#section93139389171) -- [规则:在SDK中,对以编解码返回的出参数据类型,需要进行内存释放,否则会出现内存泄漏](#section1698441814183) -- [规则:plugin需要实现server定义的IPlugin接口,并使用宏PLUGIN\_INTERFACE\_IMPL对外提供插件函数指针](#section20850717196) -- [规则:plugin需要使用AI引擎提供的统一数据通道](#section1493821732019) - -## 规则:SDK需按算法调用顺序,封装client对外提供接口;对于异步插件对应的SDK,需要实现client提供的回调接口IClientCb - -AI引擎的client端对外提供的接口包括AieClientInit、AieClientPrepare、AieClientSyncProcess、AieClientAsyncProcess、AieClientRelease、AieClientDestroy、AieClientSetOption、AieClientGetOption,sdk需要根据插件的北向接口按照顺序至少封装AieClientInit、AieClientPrepare、AieClientSyncProcess/AieClientAsyncProcess、AieClientRelease、AieClientDestroy五个接口,否则会出现调用问题或者内存泄漏。比如封装过程遗漏了AieClientprepare接口,则server端无法完成插件加载,故后面的接口都无法调用成功。 - -对于异步插件,sdk需要实现IClientCb接口,用于接收来自client端的算法推理结果,并将该结果返回给三方调用者。 - -## 规则:SDK接口实现中,需要保存与client交互的相关通用数据 - -AI引擎将的client端采用单例实现,对接多个SDK,因此各SDK需要保存与client交互的通用数据,用于连接server端进行任务推理、结果返回等;需保存数据包含clientInfo、algorithmInfo、configInfo三种数据类型,定义在SDK的成员变量里即可。 - -## 建议:SDK实现client定义的IServiceDeadCb接口 - -Server端是系统常驻进程,以系统能力的形式为多个client提供服务;client定义的IServiceDeadCb接口,是在server端异常死亡后,会被触发调用。这种异常场景,sdk可在死亡通知接口中,实现相关操作,比如停止调用或者再次拉起server端等。 - -IServiceDeadCb接口实现示例: - -``` -class ServiceDeadCb : public IServiceDeadCb { -public: -ServiceDeadCb() = default; -~ServiceDeadCb() override = default; -void OnServiceDead() override -{ -printf("[ServiceDeadCb]OnServiceDead Callback happens"); -} -}; -``` - -如上示例,SDK可在OnServiceDead\(\)方法中实现自己的操作,比如停止所有的接口调用等等。 - -## 规则:SDK与plugin需要使用编解码模块,将特定算法数据转换成AI引擎的通用数据类型 - -插件的推理数据,会由三方调用者通过client、server传递到插件中;不同的算法所需要的数据类型是不一致的,比如cv的需要图片数据、asr的需要语音数据;为了适配数据类型的差异,AI引擎对外提供了对基本数据类型的编解码能力,将不同数据类型转换为AI引擎可以使用的通用数据类型。 - -编码后的数据类型定义: - -``` -struct DataInfo { -unsigned char *data; -int length; -} DataInfo; - -``` - -如上示例,DataInfo数据结构包括指向数据内存的指针和数据长度两个变量组成。 - -框架接口使用方法: - -1.添加依赖的头文件:"utils/encdec/include/encdec.h"。 - -2.添加build.gn中的依赖项: - -include\_dirs添加"//foundation/ai/engine/services/common"。 - -deps添加"//foundation/ai/engine/services/common/utils/encdec:encdec" 。 - -3.编解码示例: - -``` -// 编码调用函数示例:arg1,arg2,arg3等为需编码的变量,dataInfo为编码后的结果 -retCode = ProcessEncode(dataInfo, arg1, arg2, arg3) //可以接收任意多个参数 -// 解码调用函数示例:dataInfo为需要解码的信息,arg1,arg2,arg3等为解码后的结果 -retCode = ProcessDecode(dataInfo, arg1, arg2, arg3) //可以接收任意多个参数 -``` - -注意: - -- 编码和解码调用时的参数顺序需要保证一致。 -- 编码后dataInfo的内存需要调用者手动进行释放。 -- server端和client端的内存是分开管理和释放的。 -- 如果包含共享内存的指针,不需要额外处理。 -- 如果其他类型的指针,则需要解引用后使用ProcessEncode/ ProcessDecode。 -- 该编解码模块未适配class数据类型,不建议使用。 - -## 规则:在SDK中,对以编解码返回的出参数据类型,需要进行内存释放,否则会出现内存泄漏 - -编码得到的通用数据,本质上是将不同类型数据封装在同一块内存中,然后将这块内存的首地址与长度封装到结构体中。通过编码返回到sdk中的出参数据,在插件中申请了内存,但插件无法释放,否则sdk将无法拿到数据;因此sdk在拿到数据之后,需要对内存进行释放。 - -内存释放示例: - -``` -DataInfo outputInfo = { -.data = nullptr, -.length = 0, -}; -AieClientPrepare(clientInfo_, algorithmInfo_, inputInfo, outputInfo, nullptr); -if (outputInfo.data != nullptr) { -free(outputInfo.data); -outputInfo.data = nullptr; -outputInfo.length = 0; -} -``` - -## 规则:plugin需要实现server定义的IPlugin接口,并使用宏PLUGIN\_INTERFACE\_IMPL对外提供插件函数指针 - -Server端管理的插件内部接口实现逻辑各不相同,为了统一插件的加载流程,AI引擎定义了插件接口IPlugin;在运行态,插件是以动态链接库的形式被AI引擎框架通过dlopen方式加载,各插件需要使用PLUGIN\_INTERFACE\_IMPL语句对外暴露函数指针,否则插件将无法被正常加载使用。 - -## 规则:plugin需要使用AI引擎提供的统一数据通道 - -AI Engine在server与插件之间,提供了一个统一的数据通道,用来处理来自sdk的推理请求和来自插件的结果返回;plugin在推理接口中,需按数据通道完成请求数据的获取以及推理结果的封装。 - -数据通道使用示例: - -``` -int SyncProcess(IRequest *request, IResponse *&response) -{ -HILOGI("[IvpPlugin]Begin SyncProcess"); -if (request == nullptr) { -HILOGE("[IvpPlugin]SyncProcess request is nullptr"); -return RETCODE_NULL_PARAM; -} -DataInfo inputInfo = request->GetMsg(); -if (inputInfo.data == nullptr) { -HILOGE("[IvpPlugin]InputInfo data is nullptr"); -return RETCODE_NULL_PARAM; -} - -... - -response = IResponse::Create(request); -response->SetResult(outputInfo); -return RETCODE_SUCCESS; -} -``` - -示例中request和response是数据通道的内容主体,server端会将数据封装在request中,传递到插件,插件进行算法处理之后,则需要将结果封装成response进行返回。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/08.AI\346\241\206\346\236\266/04.\345\274\200\345\217\221\346\214\207\345\257\274/01.SDK\345\274\200\345\217\221\350\277\207\347\250\213.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/08.AI\346\241\206\346\236\266/04.\345\274\200\345\217\221\346\214\207\345\257\274/01.SDK\345\274\200\345\217\221\350\277\207\347\250\213.md" deleted file mode 100644 index 20f1fc3a7b5c5f6d2aecdbe5002398df1ebe0f47..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/08.AI\346\241\206\346\236\266/04.\345\274\200\345\217\221\346\214\207\345\257\274/01.SDK\345\274\200\345\217\221\350\277\207\347\250\213.md" +++ /dev/null @@ -1,175 +0,0 @@ ---- -title: SDK开发过程 -permalink: /pages/0105080401 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# SDK开发过程 - -SDK头文件的功能实现是基于对SDK的调用映射到对client的调用。Client端提供的接口如下[表1](#table203963834718)所示。 - -**表 1** Client端提供的接口 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

接口名

-

接口说明

-

参数要求

-

int AieClientInit(const ConfigInfo &configInfo, ClientInfo &clientInfo, const AlgorithmInfo &algorithmInfo, IServiceDeadCb *cb)

-

作用:链接并初始化引擎服务,激活跨进程调用。

-

返回值:0为成功,其他返回值失败。

-

configInfo(NOT NULL):引擎相关初始化配置数据;

-

clientInfo(NOT NULL):引擎客户端信息;

-

algorithmInfo(NOT NULL):调用算法信息;

-

cb(可为NULL):死亡回调 对象;

-

int AieClientPrepare(const ClientInfo &clientInfo, const AlgorithmInfo &algorithmInfo, const DataInfo &inputInfo, DataInfo &outputInfo, IClientCb *cb)

-

作用:加载算法插件。

-

返回值: 0为成功,其他返回值失败。

-

clientInfo(NOT NULL):引擎客户端信息;

-

algorithmInfo(NOT NULL):调用算法信息;

-

inputInfo(可为NULL):加载算法插件时输入所需信息;

-

outputInfo(可为NULL):加载算法插件之后如需返回信息则通过此出参返回;

-

cb:异步算法通过此回调返回运算结果,因此异步算法此结构体不能为空;若为同步算法,传入空值即可;

-

int AieClientAsyncProcess(const ClientInfo &clientInfo, const AlgorithmInfo &algorithmInfo, const DataInfo &inputInfo)

-

作用:执行异步算法。

-

返回值:0为成功,其他返回值失败。

-

clientInfo(NOT NULL):引擎客户端信息;

-

algorithmInfo(NOT NULL):调用算法信息;

-

inputInfo(可为NULL):算法运算入参;

-

int AieClientSyncProcess(const ClientInfo &clientInfo, const AlgorithmInfo &algorithmInfo, const DataInfo &inputInfo, DataInfo &outputInfo)

-

作用:执行同步算法。

-

返回值:0为成功,其他返回值失败。

-

clientInfo(NOT NULL):引擎客户端信息;

-

algorithmInfo(NOT NULL):调用算法信息;

-

inputInfo(可为NULL):算法运算入参;

-

outputInfo(可为NULL):同步算法运算结果出参;

-

int AieClientRelease(const ClientInfo &clientInfo, const AlgorithmInfo &algorithmInfo, const DataInfo &inputInfo)

-

作用:卸载算法插件。

-

返回值:0为成功,其他返回值失败。

-

clientInfo(NOT NULL):引擎客户端信息;

-

algorithmInfo(NOT NULL):卸载算法插件的相关信息;

-

inputInfo(可为NULL):调用卸载接口时的输入信息;

-

int AieClientDestroy(ClientInfo &clientInfo)

-

作用:断开与服务端的链接,释放相关缓存。

-

返回值:0为成功,其他返回值失败。

-

clientInfo(NOT NULL):所要销毁的引擎客户端信息;

-

int AieClientSetOption(const ClientInfo &clientInfo, int optionType, const DataInfo &inputInfo)

-

作用:设置配置项,可将一些算法的拓展信息通过此接口传入插件。

-

返回值:0为成功,其他返回值失败。

-

clientInfo(NOT NULL):引擎客户端信息;

-

optionType (NOT NULL):算法配置项,算法插件可根据需要利用此状态位;

-

inputInfo(可为NULL):插件可根据需要通过此入参设置算法参数信息;

-

int AieClientGetOption(const ClientInfo &clientInfo, int optionType, const DataInfo &inputInfo, DataInfo &outputInfo)

-

作用:给定特定的optionType和inputInfo,获取其对应的配置项信息。

-

返回值:0为成功,其他返回值失败。

-

clientInfo(NOT NULL):引擎客户端信息;

-

optionType(NOT NULL):所获取配置项信息的对应算法状态位;

-

inputInfo(可为NULL):所获取配置项信息的对应算法参数信息;

-

outputInfo(可为NULL):所要获取的配置项信息返回结果;

-
- -其中,ConfigInfo,ClientInfo,AlgorithmInfo,DataInfo的数据结构如下[表2](#table22154317482)所示。 - -**表 2** ConfigInfo,ClientInfo,AlgorithmInfo,DataInfo的数据结构 - - - - - - - - - - - - - - - - - - - - - - - - -

结构体名称

-

说明

-

属性

-

ConfigInfo

-

算法配置项信息。

-

const char *description:配置项信息主体;

-

ClientInfo

-

客户端信息。

-

long long clientVersion:客户端设备版本号(当前还未启用);

-

int clientId:客户端ID;

-

int sessionId:会话ID;

-

uid_t serverUid:server端UID;

-

uid_t clientUid:client端UID;

-

int extendLen:拓展信息(extendMsg)长度;

-

unsigned char *extendMsg:拓展信息主体;

-

AlgorithmInfo

-

算法信息。

-

long long clientVersion:客户端设备版本号(当前还未启用);

-

bool isAsync:是否为异步执行;

-

int algorithmType:引擎框架根据插件加载顺序分配的算法类型ID;

-

long long algorithmVersion:算法版本号;

-

bool isCloud:是否上云(当前还未启用);

-

int operateId:执行ID(当前还未启用);

-

int requestId:请求ID,标识每次request,以对应执行结果;

-

int extendLen:拓展信息(extendMsg)长度;

-

unsigned char *extendMsg:拓展信息主体;

-

DataInfo

-

算法数据入参(inputInfo)、接口调用结果出参(outputInfo)。

-

unsigned char *data:数据主体;

-

int length:数据(data)长度;

-
- -具体开发过程可参考唤醒词识别SDK开发示例。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/08.AI\346\241\206\346\236\266/04.\345\274\200\345\217\221\346\214\207\345\257\274/02.\346\217\222\344\273\266\347\232\204\345\274\200\345\217\221\350\277\207\347\250\213.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/08.AI\346\241\206\346\236\266/04.\345\274\200\345\217\221\346\214\207\345\257\274/02.\346\217\222\344\273\266\347\232\204\345\274\200\345\217\221\350\277\207\347\250\213.md" deleted file mode 100644 index e255293e828630e07dbca97fc71768331baf5402..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/08.AI\346\241\206\346\236\266/04.\345\274\200\345\217\221\346\214\207\345\257\274/02.\346\217\222\344\273\266\347\232\204\345\274\200\345\217\221\350\277\207\347\250\213.md" +++ /dev/null @@ -1,274 +0,0 @@ ---- -title: 插件的开发过程 -permalink: /pages/0105080402 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 插件的开发过程 - -AI引擎框架规定了一套算法插件接入规范,各插件需实现规定接口以实现获取插件版本信息、算法推理类型、同步执行算法、异步执行算法、加载算法插件、卸载算法插件、设置算法配置信息、获取指定算法配置信息等功能。(同步算法实现SyncProcess接口,异步算法实现AsyncProcess接口)。 - -1)算法插件类IPlugin接口设计如下[表1](#table1329717488505)所示。 - -**表 1** 算法插件类IPlugin接口设计 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

接口名

-

接口说明

-

参数要求

-

const long long GetVersion() const;

-

作用:获取插件版本信息。

-

返回值:版本号(long long)

-

-

-

const char *GetInferMode() const;

-

作用:获取算法推理类型。

-

返回值:"SYNC" or "ASYNC";

-

-

-

int SyncProcess(IRequest *request, IResponse *&response);

-

作用:执行插件同步算法。

-

返回值:0为成功,其他返回值失败。

-

request(NOT NULL):用于向算法插件传递请求内容;引擎服务端与插件的数据通道;

-

response(NOT NULL):作为出参用于接收算法插件发回的同步算法执行结果,引擎服务端与插件的数据通道;

-

int AsyncProcess(IRequest *request, IPluginAlgorithmCallback *callback);

-

作用:执行异步算法。

-

返回值:0为成功,其他返回值失败。

-

request(NOT NULL):用于向算法插件传递请求内容;引擎服务端与插件的数据通道。

-

callback(NOT NULL):算法插件异步执行结果通过此回调返回引擎服务端;

-

int Prepare(long long transactionId, const DataInfo &inputInfo, DataInfo &outputInfo);

-

作用:加载算法插件。

-

返回值:0为成功,其他返回值失败。

-

transactionId(NOT NULL):事务ID,用于标记客户端+会话信息;

-

inputInfo(可为NULL):加载算法插件传入的一些信息;

-

outputInfo(可为NULL):调用加载接口时的出参,返回相关执行结果;

-

int Release(bool isFullUnload, long long transactionId, const DataInfo &inputInfo);

-

作用:卸载相关算法插件。

-

返回值:0为成功,其他返回值失败。

-

isFullUnload(NOT NULL):表示此插件是否只剩一个client调用,否则不能直接卸载插件,需等最后一个client来进行卸载;

-

transactionId(NOT NULL):事务ID,用于标记客户端+会话信息;

-

inputInfo(可为NULL):卸载算法插件传入的一些信息;

-

int SetOption(int optionType, const DataInfo &inputInfo);

-

作用:设置配置项,可将一些算法的拓展信息通过此接口传入插件。

-

返回值:0为成功,其他返回值失败。

-

optionType (NOT NULL):算法配置项,算法插件可根据需要利用此状态位;

-

inputInfo(可为NULL):插件可根据需要通过此入参设置算法参数信息;

-

int GetOption(int optionType, const DataInfo &inputInfo, DataInfo &outputInfo);

-

作用:给定特定的optionType和inputInfo,获取其对应的配置项信息。

-

返回值:0为成功,其他返回值失败。

-

optionType(NOT NULL):所获取配置项信息的对应算法状态位;

-

inputInfo(可为NULL):所获取配置项信息的对应算法参数信息;

-

outputInfo(可为NULL):所要获取的配置项信息返回结果;

-
- -算法插件类接口:Prepare、SyncProcess、AsyncProcess、Release、SetOption、GetOption分别于客户端接口AieClientPrepare、AieClientSyncProcess、AieClientAsyncProcess、AieClientRelease、AieClientSetOption、AieClientGetOption一一对应;GetInferMode接口用于返回算法执行类型——同步或异步。 - -2)算法插件回调类IPluginCallback 接口设计如[表2](#table461192635114)所示。 - -**表 2** 算法插件回调类IPluginCallback 接口设计 - - - - - - - - - - - - -

接口名

-

接口说明

-

参数要求

-

void OnEvent(PluginEvent event, IResponse *response);

-

作用:插件通过此回调返回异步算法执行结果。

-

event:算法执行结果枚举,‘ON_PLUGIN_SUCCEED’或 ‘ON_PLUGIN_FAIL’(成功或者失败);

-

response:算法执行结果封装;

-
- -Request、Response是ai引擎服务端与算法插件进行通信的对象。Request封装了调用方的请求、输入数据等,而插件主要通过Response将运算之后的结果返回给AI引擎服务端。 - -Request类的属性如下[表3](#table16273647125120)所示。 - -**表 3** Request类的属性 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

属性名称

-

属性说明

-

默认值

-

innerSequenceId_

-

类型:long long

-

作用:暂未启用。

-

0

-

requestId_

-

类型:int

-

作用:标识请求序列,用于绑定返回运算结果。

-

0

-

operationId_

-

类型:int

-

作用:目前暂未启用。

-

0

-

transactionId_

-

类型:long long

-

作用:事务ID,唯一标识clientId+sessionId。

-

0

-

algoPluginType_

-

类型:int

-

作用:引擎框架根据插件加载顺序分配的算法类型的ID。

-

0

-

msg_

-

类型:DataInfo

-

作用:存放调用算法接口的输入数据。

-

.data = nullptr

-

.length = 0

-
- -Response类的属性如下[表4](#table1798597135212)所示。 - -**表 4** Response类的属性 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

属性名称

-

属性说明

-

默认值

-

innerSequenceId_

-

类型:long long

-

作用:暂未启用。

-

0

-

requestId_

-

类型:int

-

作用:标识请求序列,用于绑定返回运算结果。

-

0

-

retCode__

-

类型:int

-

作用:异步执行算法推理结果码。

-

0

-

retDesc_

-

类型:string

-

作用:暂未启用。

-

-

-

transactionId_

-

类型:long long

-

作用:事务ID,唯一标识clientId+sessionId。

-

0

-

algoPluginType_

-

类型:int

-

作用:引擎框架根据插件加载顺序分配的算法类型的ID。

-

INVALID_ALGO_PLUGIN_TYPE(-1)

-

result_

-

类型:DataInfo

-

作用:存放异步算法推理结果。

-

.data = nullptr

-

.length = 0

-
- -具体开发过程可参考唤醒词识别插件开发示例。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/08.AI\346\241\206\346\236\266/04.\345\274\200\345\217\221\346\214\207\345\257\274/03.\351\205\215\347\275\256\346\226\207\344\273\266\347\232\204\345\274\200\345\217\221\350\277\207\347\250\213.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/08.AI\346\241\206\346\236\266/04.\345\274\200\345\217\221\346\214\207\345\257\274/03.\351\205\215\347\275\256\346\226\207\344\273\266\347\232\204\345\274\200\345\217\221\350\277\207\347\250\213.md" deleted file mode 100644 index 618d6312c8b9c12f34b7fa55de68272212a0b3f7..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/08.AI\346\241\206\346\236\266/04.\345\274\200\345\217\221\346\214\207\345\257\274/03.\351\205\215\347\275\256\346\226\207\344\273\266\347\232\204\345\274\200\345\217\221\350\277\207\347\250\213.md" +++ /dev/null @@ -1,23 +0,0 @@ ---- -title: 配置文件的开发过程 -permalink: /pages/0105080403 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 配置文件的开发过程 - -开发者开发的SDK通过AlgorithmInfo结构体中algorithmVersion以及algorithmType识别出具体的插件类型,实现插件能力的调用。因此开发者需完成以下步骤: - -1. 代码路径//foundation/ai/engine/services/common/protocol/plugin\_config/plugin\_config\_ini/目录中添加插件的配置文件。 -2. 代码路径//foundation/ai/engine/services/common/protocol/plugin\_config/aie\_algorithm\_type.h文件中添加算法类型。 -3. 代码路径//foundation/ai/engine/services/server/plugin\_manager/include/aie\_plugin\_info.h文件中添加唤醒词识别的算法名称及其在ALGORITHM\_TYPE\_ID\_LITS中的序号。 - -具体开发过程可参考唤醒词识别配置文件开发示例。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/08.AI\346\241\206\346\236\266/05.\345\274\200\345\217\221\347\244\272\344\276\213/01.\345\224\244\351\206\222\350\257\215\350\257\206\345\210\253SDK\347\232\204\345\274\200\345\217\221\347\244\272\344\276\213.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/08.AI\346\241\206\346\236\266/05.\345\274\200\345\217\221\347\244\272\344\276\213/01.\345\224\244\351\206\222\350\257\215\350\257\206\345\210\253SDK\347\232\204\345\274\200\345\217\221\347\244\272\344\276\213.md" deleted file mode 100644 index 6b5723859446b19ddc25a2a8e0740ff7b8fa6ad8..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/08.AI\346\241\206\346\236\266/05.\345\274\200\345\217\221\347\244\272\344\276\213/01.\345\224\244\351\206\222\350\257\215\350\257\206\345\210\253SDK\347\232\204\345\274\200\345\217\221\347\244\272\344\276\213.md" +++ /dev/null @@ -1,94 +0,0 @@ ---- -title: 唤醒词识别SDK的开发示例 -permalink: /pages/0105080501 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 唤醒词识别SDK的开发示例 - -1. 在//foundation/ai/engine /interfaces/kits目录中添加唤醒词识别SDK的API接口定义,该接口可用三方应用的调用。如下代码片段即为唤醒词识别定义的API接口示例,其相关代码参考路径为://foundation/ai/engine /interfaces/kits/asr/keyword\_spotting。 - - ``` - class KWSSdk { - public: - KWSSdk(); - virtual ~KWSSdk(); - - // 定义了创建唤醒词检测工具包的方法 - int32_t Create(); - - // 定义了同步执行唤醒词检测任务的方法 - int32_t SyncExecute(const Array &audioInput); - - // 定义了设置唤醒词检测回调器的方法 - int32_t SetCallback(const std::shared_ptr &callback); - - // 定义了销毁唤醒词工具包的方法,释放与插件的会话信息。 - int32_t Destroy(); - }; - ``` - -2. 在//foundation/ai/engine/services/client/algorithm\_sdk的目录中增加SDK中API接口的具体实现,调用client端提供的接口,实现算法插件能力的使用。如下代码片段即为唤醒词识别的API接口中create方法的具体实现示例,更多详细代码可参考://foundation/ai/engine/services/client/algorithm\_sdk/asr/keyword\_spotting。 - - ``` - int32_t KWSSdk::KWSSdkImpl::Create() - { - if (kwsHandle_ != INVALID_KWS_HANDLE) { - HILOGE("[KWSSdkImpl]The SDK has been created"); - return KWS_RETCODE_FAILURE; - } - if (InitComponents() != RETCODE_SUCCESS) { - HILOGE("[KWSSdkImpl]Fail to init sdk components"); - return KWS_RETCODE_FAILURE; - } - // 调用client端提供的接口AieClientInit,实现初始化引擎服务,激活跨进程调用 - int32_t retCode = AieClientInit(configInfo_, clientInfo_, algorithmInfo_, nullptr); - if (retCode != RETCODE_SUCCESS) { - HILOGE("[KWSSdkImpl]AieClientInit failed. Error code[%d]", retCode); - return KWS_RETCODE_FAILURE; - } - if (clientInfo_.clientId == INVALID_CLIENT_ID) { - HILOGE("[KWSSdkImpl]Fail to allocate client id"); - return KWS_RETCODE_FAILURE; - } - DataInfo inputInfo = { - .data = nullptr, - .length = 0, - }; - DataInfo outputInfo = { - .data = nullptr, - .length = 0, - }; - // 调用client端提供的接口AieClientPrepare,实现加载算法插件 - retCode = AieClientPrepare(clientInfo_, algorithmInfo_, inputInfo, outputInfo, nullptr); - if (retCode != RETCODE_SUCCESS) { - HILOGE("[KWSSdkImpl]AieclientPrepare failed. Error code[%d]", retCode); - return KWS_RETCODE_FAILURE; - } - if (outputInfo.data == nullptr || outputInfo.length <= 0) { - HILOGE("[KWSSdkImpl]The data or length of output info is invalid"); - return KWS_RETCODE_FAILURE; - } - MallocPointerGuard pointerGuard(outputInfo.data); - retCode = PluginHelper::UnSerializeHandle(outputInfo, kwsHandle_); - if (retCode != RETCODE_SUCCESS) { - HILOGE("[KWSSdkImpl]Get handle from inputInfo failed"); - return KWS_RETCODE_FAILURE; - } - return KWS_RETCODE_SUCCESS; - } - ``` - - 上述代码为API接口的具体实现,从上述示例的代码中,SDK中create接口的具体实现即为下述示例代码中create方法,该方法调用了AI引擎框架client端开放接口AieClientInit,AieClientPrepare,从而实现与server端建立连接及加载算法模型的能力。 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >SDK调用AI引擎client端接口顺序应遵循AieClientInit-\>AieClientPrepare-\>AieClientSyncProcess/AieClientAsyncProcess-\>AieClientRelease-\>AieClientDestroy,否则调用接口会返回错误码。 - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/08.AI\346\241\206\346\236\266/05.\345\274\200\345\217\221\347\244\272\344\276\213/02.\345\224\244\351\206\222\350\257\215\350\257\206\345\210\253\346\217\222\344\273\266\347\232\204\345\274\200\345\217\221\347\244\272\344\276\213.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/08.AI\346\241\206\346\236\266/05.\345\274\200\345\217\221\347\244\272\344\276\213/02.\345\224\244\351\206\222\350\257\215\350\257\206\345\210\253\346\217\222\344\273\266\347\232\204\345\274\200\345\217\221\347\244\272\344\276\213.md" deleted file mode 100644 index 222e4212df7f27f11ce2a54ca800ee005ae7e4db..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/08.AI\346\241\206\346\236\266/05.\345\274\200\345\217\221\347\244\272\344\276\213/02.\345\224\244\351\206\222\350\257\215\350\257\206\345\210\253\346\217\222\344\273\266\347\232\204\345\274\200\345\217\221\347\244\272\344\276\213.md" +++ /dev/null @@ -1,104 +0,0 @@ ---- -title: 唤醒词识别插件的开发示例 -permalink: /pages/0105080502 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 唤醒词识别插件的开发示例 - -1. 在//foundation/ai/engine/services/server/plugin的目录中添加唤醒词识别插件的接口定义,并实现AI能力的调用。如下代码片段即实现唤醒词识别的算法插件的接口定义。更多插件开发的相关代码参考路径如下://foundation/ai/engine/services/server/plugin/asr/keyword\_spotting - - ``` - #include "plugin/i_plugin.h - class KWSPlugin : public IPlugin { - public: - KWSPlugin(); - ~KWSPlugin(); - const long long GetVersion() const override; - const char* GetName() const override; - const char* GetInferMode() const override; - int32_t Prepare(long long transactionId, const DataInfo &amp;inputInfo, DataInfo &amp;outputInfo) override; - int32_t SetOption(int optionType, const DataInfo &amp;inputInfo) override; - int32_t GetOption(int optionType, const DataInfo &amp;inputInfo, DataInfo &amp;outputInfo) override; - int32_t SyncProcess(IRequest *request, IResponse *&amp;response) override; - int32_t AsyncProcess(IRequest *request, IPluginCallback*callback) override; - int32_t Release(bool isFullUnload, long long transactionId, const DataInfo &amp;inputInfo) override; - }; - ``` - - 上述代码实现server提供的IPlugin接口。唤醒词识别的sample中调用的client端接口与插件中的接口对应关系及其实现功能如表[1](#table567211582104)所示。 - - **表 1** 唤醒词识别中client端接口与插件接口对应关系 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

client端定义的接口

-

插件中定义的接口

-

功能

-

AieClientPrepare

-

Prepare

-

提供推理算法插件初始化功能,以唤醒词识别为例:加载唤醒词识别模型,将固定位置(/sdcard/wenwen_inst.wk)模型加载至内存。

-

AieClientSyncProcess

-

SyncProcess

-

提供同步执行推理算法的能力,以唤醒词识别为例:实现同步执行音频推理算法,判断音频中是否存在唤醒词。

-

AieClientAsyncProcess

-

AsyncProcess

-

提供异步执行推理算法的能力,当前唤醒词识别场景不涉及,但开发者可根据具体场景自行实现。

-

AieClientSetOption

-

SetOption

-

提供手动设置算法相关配置项,如置信度阈值、时延等超参数的能力,当前唤醒词识别场景未涉及。开发者可视具体场景自行实现。

-

AieClientGetOption

-

GetOption

-

提供获取算法相关配置项,以唤醒词识别为例:获取唤醒词模型中输入输出的规模,输入规模即为唤醒词识别模型要求输入的MFCC特征的维度(固定值:4000),输出规模即为结果的置信度得分维度(固定值:2)。

-

AieClientRelease

-

Release

-

提供卸载算法模型功能,以唤醒词识别为例:实现卸载相关模型,并将特征处理器中的动态内存清理。

-
- - 注意: - - 1.接口AieClientInit、AieClientDestroy分别用于与server端建立和断开连接,未调用到插件算法中,因此插件中无需定义与之对应的接口。 - - 2.唤醒词识别插件需要使用PLUGIN\_INTERFACE\_IMPL语句对外暴露函数指针,否则插件将无法被正常加载使用。 - - ``` - PLUGIN_INTERFACE_IMPL(KWSPlugin); - ``` - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/08.AI\346\241\206\346\236\266/05.\345\274\200\345\217\221\347\244\272\344\276\213/03.\345\224\244\351\206\222\350\257\215\350\257\206\345\210\253\351\205\215\347\275\256\346\226\207\344\273\266\347\232\204\345\274\200\345\217\221\347\244\272\344\276\213.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/08.AI\346\241\206\346\236\266/05.\345\274\200\345\217\221\347\244\272\344\276\213/03.\345\224\244\351\206\222\350\257\215\350\257\206\345\210\253\351\205\215\347\275\256\346\226\207\344\273\266\347\232\204\345\274\200\345\217\221\347\244\272\344\276\213.md" deleted file mode 100644 index 2fea667e307451e2504f6f200619f4244fc652fa..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/08.AI\346\241\206\346\236\266/05.\345\274\200\345\217\221\347\244\272\344\276\213/03.\345\224\244\351\206\222\350\257\215\350\257\206\345\210\253\351\205\215\347\275\256\346\226\207\344\273\266\347\232\204\345\274\200\345\217\221\347\244\272\344\276\213.md" +++ /dev/null @@ -1,67 +0,0 @@ ---- -title: 唤醒词识别配置文件的开发示例 -permalink: /pages/0105080503 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 唤醒词识别配置文件的开发示例 - -1. 代码路径//foundation/ai/engine/services/common/protocol/plugin\_config/plugin\_config\_ini/中添加唤醒词识别的配置文件 - - ``` - [base] - supported_boards = hi3516dv300 - related_sessions = asr_keyword_spotting+20001002 - - //[asr_keyword_spotting+20001002]的命名规则为[算法名称+算法version] - [asr_keyword_spotting+20001002] - AID = asr_keyword_spotting - VersionCode = 20001002 - VersionName = 2.00.01.002 - XPU = NNIE - District = China - // 编译出的插件so所在的位置 - FullPath = /usr/lib/libasr_keyword_spotting.so - Chipset = ALL - ChkSum = '' - Key = '' - ``` - -2. 代码路径//foundation/ai/engine/services/common/protocol/plugin\_config/aie\_algorithm\_type.h文件中添加唤醒词识别算法类型id。 - - ``` - // 唤醒词识别的算法类型id与唤醒词识别在ALGORITHM_TYPE_ID_LITS中的序号一一对应 - const int ALGORITHM_TYPE_KWS = 3; - ``` - -3. 代码路径//foundation/ai/engine/services/server/plugin\_manager/include/aie\_plugin\_info.h文件中添加唤醒词识别算法名称及在ALGORITHM\_TYPE\_ID\_LITS中的序号 - - ``` - const std::string ALGORITHM_ID_SAMPLE_1 = "sample_plugin_1"; - const std::string ALGORITHM_ID_SAMPLE_2 = "sample_plugin_2"; - const std::string ALGORITHM_ID_IVP = "cv_human_detect"; - // 添加唤醒词识别的算法名称asr_keyword_spotting - // 算法的变量名称与ALGORITHM_TYPE_ID_LIST中算法typeId命名相同,例如;ALGORITHM_ID_KWS - const std::string ALGORITHM_ID_KWS = "asr_keyword_spotting"; - const std::string ALGORITHM_ID_IC = "cv_image_classification"; - const std::string ALGORITHM_ID_INVALID = "invalid algorithm id"; - - const std::vector ALGORITHM_TYPE_ID_LIST = { - ALGORITHM_ID_SAMPLE_1, - ALGORITHM_ID_SAMPLE_2, - ALGORITHM_ID_IVP, - // 添加唤醒词识别在ALGORITHM_TYPE_ID_LITS中的序号,通过该序号可获得唤醒词识别的算法名称 - // 唤醒词识别的算法名称和唤醒词识别在ALGORITHM_TYPE_ID_LITS中的序号顺序需保持一致 - ALGORITHM_ID_KWS, - ALGORITHM_ID_IC, - }; - ``` - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/09.Sensor\346\234\215\345\212\241/01.Sensor\346\234\215\345\212\241\345\255\220\347\263\273\346\246\202\350\277\260.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/09.Sensor\346\234\215\345\212\241/01.Sensor\346\234\215\345\212\241\345\255\220\347\263\273\346\246\202\350\277\260.md" deleted file mode 100644 index 0406e5bf65d9a8d29bafaed99ff6872238e8c6cc..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/09.Sensor\346\234\215\345\212\241/01.Sensor\346\234\215\345\212\241\345\255\220\347\263\273\346\246\202\350\277\260.md" +++ /dev/null @@ -1,112 +0,0 @@ ---- -title: Sensor服务子系概述 -permalink: /pages/01050901 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# Sensor服务子系概述 - -- [简介](#section667413271505) -- [接口说明](#section7255104114110) - -## 简介 - -Sensor服务子系统提供了轻量级传感器服务基础框架,您可以使用该框架接口实现传感器列表查询、传感器控制、传感器订阅去订阅等功能。轻量级传感器服务框架如下图所示: - -**图1** Sensor服务框架图 - -![](/images/device-dev/subsystems/figure/zh-cn_image_0000001077724150.png) - -- Sensor API:提供传感器的基础API,主要包含查询传感器的列表、订阅/取消传感器数据、执行控制命令等,简化应用开发。 -- Sensor Framework:主要实现传感器的订阅管理、数据通道的创建、销毁等,实现与传感器服务层的通信。 -- Sensor Service:主要实现HDF层数据接收、解析、分发,对设备传感器的管理,数据上报管理以及传感器权限管控等。 - -## 接口说明 - -**表 1** Sensor服务框架API接口功能介绍 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

接口名

-

接口说明

-

参数要求

-

int32_t GetAllSensors(SensorInfo **sensorInfo, int32_t *count)

-

作用:获取系统中所有传感器的信息。

-

返回值:0表示成功,其他返回值表示失败。

-

sensorInfo(NOT NULL):输出系统中所有传感器的信息;

-

count(NOT NULL):输出系统中所有传感器的数量。

-

int32_t SubscribeSensor(int32_t sensorTypeId, SensorUser *user)

-

作用:订阅传感器数据,系统会将获取到的传感器数据上报给订阅者。

-

返回值: 0为成功,其他返回值表示失败。

-

sensorTypeId:唯一标识一个传感器类型;

-

user(NOT NULL):传感器的用户,用于从传感器获取数据,一般一个用户只属于一个传感器。

-

int32_t UnsubscribeSensor(int32_t sensorTypeId, SensorUser *user)

-

作用:去订阅传感器数据,系统将取消传感器数据上报给订阅者。

-

返回值:0为成功,其他返回值表示失败。

-

sensorTypeId:唯一标识一个传感器类型;

-

user(NOT NULL):传感器的用户,用于从传感器获取数据,一般一个用户只属于一个传感器。

-

int32_t SetBatch(int32_t sensorTypeId, SensorUser *user, int64_t samplingInterval, int64_t reportInterval)

-

作用:设置传感器的数据采样间隔和数据上报间隔

-

返回值:0为成功,其他返回值表示失败。

-

sensorTypeId:唯一标识一个传感器类型;

-

user(NOT NULL):传感器的用户,用于从传感器获取数据,一般一个用户只属于一个传感器;

-

samplingInterval:传感器数据采样间隔,单位纳秒;

-

reportInterval:传感器数据上报间隔,单位纳秒。

-

int32_t ActivateSensor(int32_t sensorTypeId, SensorUser *user)

-

作用:使能一个传感器订阅用户。

-

返回值:0为成功,其他返回值表示失败。

-

sensorTypeId:唯一标识一个传感器类型;

-

user(NOT NULL):传感器的用户,用于从传感器获取数据,一般一个用户只属于一个传感器。

-

int32_t DeactivateSensor(int32_t sensorTypeId, SensorUser *user)

-

作用:去使能一个传感器订阅用户

-

返回值:0为成功,其他返回值表示失败。

-

sensorTypeId:唯一标识一个传感器类型;

-

user(NOT NULL):传感器的用户,用于从传感器获取数据,一般一个用户只属于一个传感器。

-

int32_t SetMode(int32_t sensorTypeId, SensorUser *user, int32_t mode)

-

作用:设置传感器的工作模式

-

返回值:0为成功,其他返回值表示失败。

-

sensorTypeId:唯一标识一个传感器类型;

-

user(NOT NULL):传感器的用户,用于从传感器获取数据,一般一个用户只属于一个传感器;

-

mode:传感器的数据上报模式。

-
- diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/09.Sensor\346\234\215\345\212\241/02.Sensor\346\234\215\345\212\241\345\255\220\347\263\273\344\275\277\347\224\250\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/09.Sensor\346\234\215\345\212\241/02.Sensor\346\234\215\345\212\241\345\255\220\347\263\273\344\275\277\347\224\250\346\214\207\345\257\274.md" deleted file mode 100644 index 66355aec9753997cdb64dfcd62a3f748402554ab..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/09.Sensor\346\234\215\345\212\241/02.Sensor\346\234\215\345\212\241\345\255\220\347\263\273\344\275\277\347\224\250\346\214\207\345\257\274.md" +++ /dev/null @@ -1,85 +0,0 @@ ---- -title: Sensor服务子系使用指导 -permalink: /pages/01050902 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# Sensor服务子系使用指导 - -- [使用步骤](#section18816105182315) - -下面使用步骤以sensorTypeId为0的传感器为例,其他类型的传感器使用方式类似。 - -## 使用步骤 - -1. 导入需要的包 - -``` -#include "sensor_agent.h" -#include "sensor_agent_type.h" -``` - -1. 创建传感器回调函数 - -``` -void SensorDataCallbackImpl(SensorEvent *event) -{ - if(event == NULL){ - return; - } - float *sensorData=(float *)event->data; -} -``` - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->回调函数的格式为RecordSensorCallback类型。 - -1. 获取设备支持sensor列表 - -``` -SensorInfo *sensorInfo = (SensorInfo *)NULL; -int32_t count = 0; -int32_t ret = GetAllSensors(&sensorInfo, &count); -``` - -1. 创建的传感器用户 - -``` -SensorUser sensorUser; -sensorUser.callback = SensorDataCallbackImpl; //成员变量callback指向创建的回调方法 -``` - -1. 使能传感器 - -``` -int32_t ret = ActivateSensor(0, &sensorUser); -``` - -1. 订阅传感器数据 - -``` -int32_t ret = SubscribeSensor(0, &sensorUser); -``` - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->到这步就可以在实现的回调方法中获取到传感器数据。 - -1. 取消传感器数据订阅 - -``` -int32_t ret = UnsubscribeSensor(0, &sensorUser); -``` - -1. 去使能一个传感器 - -``` -int32_t ret = DeactivateSensor(0, &sensorUser); -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/09.Sensor\346\234\215\345\212\241/03.Sensor\346\234\215\345\212\241\345\255\220\347\263\273\344\275\277\347\224\250\345\256\236\344\276\213.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/09.Sensor\346\234\215\345\212\241/03.Sensor\346\234\215\345\212\241\345\255\220\347\263\273\344\275\277\347\224\250\345\256\236\344\276\213.md" deleted file mode 100644 index 7e071c14dedc1461e5867980f973d6dc5ca2569d..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/09.Sensor\346\234\215\345\212\241/03.Sensor\346\234\215\345\212\241\345\255\220\347\263\273\344\275\277\347\224\250\345\256\236\344\276\213.md" +++ /dev/null @@ -1,74 +0,0 @@ ---- -title: Sensor服务子系使用实例 -permalink: /pages/01050903 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# Sensor服务子系使用实例 - -使用实例以sensorTypeId为0的传感器为例,其他类型的传感器使用方式类似。 - -``` -#include "sensor_agent.h" -#include "sensor_agent_type.h" -#include "stdio.h" - -void SensorDataCallbackImpl(SensorEvent *event) -{ - if(event == NULL){ - return; - } - float *sensorData=(float *)event->data; - for(int32_t i = 0; i < (int32_t)(event->dataLen / sizeof(uint8_t *)); i++){ - printf("SensorDataCallbackImpl data: %f", *(sensorData + i)); - } -} - -/* 测试用例函数 */ -static int32_t TestSensorService(void) -{ - SensorUser sensorUser; - sensorUser.callback = SensorDataCallbackImpl; - SensorInfo *sensorInfo = (SensorInfo *)NULL; - int32_t count = 0; - // 获取设备的sensor列表 - int32_t ret = GetAllSensors(&sensorInfo, &count); - if (ret != 0) { - printf("GetAllSensors failed! ret: %d", ret); - return ret; - } - // 使能传感器 - ret = ActivateSensor(0, &sensorUser); - if (ret != 0) { - printf("ActivateSensorfailed! ret: %d", ret); - return ret; - } - // 订阅传感器数据 - ret = SubscribeSensor(0, &sensorUser); - if (ret != 0) { - printf("SubscribeSensor! ret: %d", ret); - return ret; - } - sleep(10); - // 取消传感器数据订阅 - ret = UnsubscribeSensor(0, &sensorUser); - if (ret != 0) { - printf("UnsubscribeSensor! ret: %d", ret); - return ret; - } - // 去使能传感器 - ret = DeactivateSensor(0, &sensorUser); - if (ret != 0) { - printf("DeactivateSensor! ret: %d", ret); - return ret; - } -} -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/10.\347\224\250\346\210\267\347\250\213\345\272\217\346\241\206\346\236\266/01.\346\246\202\350\277\260.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/10.\347\224\250\346\210\267\347\250\213\345\272\217\346\241\206\346\236\266/01.\346\246\202\350\277\260.md" deleted file mode 100644 index 3b5e9c6e463580cb0ab5e452b3f458396aa48983..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/10.\347\224\250\346\210\267\347\250\213\345\272\217\346\241\206\346\236\266/01.\346\246\202\350\277\260.md" +++ /dev/null @@ -1,153 +0,0 @@ ---- -title: 概述 -permalink: /pages/01050a01 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 概述 - -- [基本概念](#section72601941194812) -- [Ability子系统](#section14633111813374) -- [包管理子系统](#section1341146154412) -- [运作机制](#section94302021112717) -- [约束与限制](#section89534912527) - -用户程序框架是OpenHarmony为开发者提供开发OpenHarmony应用的开发框架,包含两个模块:Ability子系统和包管理子系统。 - -## 基本概念 - -开发者在开发前需要先了解以下基本概念,方便开发者更好的理解OpenHarmony用户程序框架。 - -## Ability子系统 - -Ability子系统是管理OpenHarmony应用运行状态的开发框架。 - -**图 1** Ability子系统框架图 -![](/images/device-dev/subsystems/figure/Ability子系统框架图.png "Ability子系统框架图") - -- **Ability**:系统调度应用的最小单元,是能够完成一个独立功能的组件,一个应用可以包含一个或多个Ability。Ability分为两种类型:Page类型的Ability和Service类型的Ability。 - - **Page类型的Ability**:带有界面,为用户提供人机交互的能力。 - - - **Service类型的Ability**:不带界面,为用户提供后台任务机制。 - - - -- **AbilitySlice**:单个页面及其控制逻辑的总和,是Page类型Ability特有的组件,一个Page类型的Ability可以包含多个AbilitySlice,此时,这些页面提供的业务能力应当是高度相关的。 - - **图 2** Ability与AbilitySlice的关系图 - ![](/images/device-dev/subsystems/figure/Ability与AbilitySlice的关系图.png "Ability与AbilitySlice的关系图") - -- **生命周期**:Ability被调度到启动、激活、隐藏和退出等各个状态的统称。 - - **图 3** Ability生命周期流转 - - - ![](/images/device-dev/subsystems/figure/图片1.png) - - - **OnStart\(\)** - - 系统首次创建Page实例时触发该回调。对于一个Page实例,该回调在其生命周期过程中仅触发一次,Page在该逻辑后进入INACTIVE状态。开发者必须重写该方法,并在此配置默认展示的AbilitySlice。 - - - **OnActive\(\)** - - Page会在进入INACTIVE状态后来到前台,然后系统调用此回调。Page在此之后进入ACTIVE状态,该状态是应用与用户交互的状态。Page将保持在此状态,除非某类事件发生导致Page失去焦点,比如用户点击返回键或导航到其他Page。 - - 当此类事件发生时,会触发Page回到INACTIVE状态,系统将调用OnInactive\(\)回调。此后,Page可能重新回到ACTIVE状态,系统将再次调用OnActive\(\)回调。因此,开发者通常需要成对实现OnActive\(\)和OnInactive\(\),并在OnActive\(\)中获取在OnInactive\(\)中被释放的资源。 - - - **OnInactive\(\)** - - 当Page失去焦点时,系统将调用此回调,此后Page进入INACTIVE状态。开发者可以在此回调中实现Page失去焦点时应表现的恰当行为。 - - - **OnBackground\(\)** - - 如果Page不再对用户可见,系统将可能根据资源状况调用此回调,此后Page进入BACKGROUND状态。开发者应该在此回调中释放Page不可见时无用的资源,或在此回调中执行较为耗时的状态保存操作。 - - - **OnForeground\(\)** - - 处于BACKGROUND状态的Page仍然驻留在内存中,当重新回到前台时(比如用户重新导航到此Page),系统将先调用OnForeground\(\)回调使Page回到INACTIVE状态,然后调用OnActive\(\)回调使Page回到ACTIVE状态。开发者应当在此回调中重新申请在OnBackground\(\)中释放的资源。轻量化设备目前不支持该接口。 - - - **OnStop\(\)** - - 此回调表示系统正在销毁Page。销毁Page的可能原因包括: - - - 用户通过系统管理能力显式关闭Page,例如使用任务管理器关闭Page。 - - 用户行为触发Page的TerminateAbility\(\)方法调用,例如使用应用的退出功能。 - - 配置变更导致系统暂时销毁Page并重建。 - - 系统出于资源管理目的,自动触发对处于BACKGROUND状态Page的销毁。 - - -- **AbilityKit**:Ability框架提供给开发者的开发包,开发者基于该开发包可以开发出基于Ability组件的应用。基于Ability组件开发的应用有两种类型:基于Javascript语言开发的Ability(JS Ability)和基于C/C++语言开发的Ability(Native Ability)。JS应用开发框架是开发者开发JS Ability所用到框架,是在AbilityKit基础封装的包含js UI组件的一套方便开发者能够迅速开发Ability应用的框架。 -- **AbilityLoader**:负责注册和加载开发者Ability的模块。开发者开发的Ability先要调用AbilityLoader的注册接口注册到框架中,接着Ability启动时会被实例化。 - -- **AbilityManager**:负责AbilityKit和Ability管理服务进行IPC的通信。 - -- **EventHandler**:AbilityKit提供给开发者的用于在Ability中实现线程间通信的一个模块。 - -- **AbilityManagerService**:元能力运行管理服务。该服务用于协调各Ability运行关系、及生命周期进行调度的系统服务。其中,服务启动模块负责Ability管理服务的启动、注册等。服务接口管理模块负责Ability管理服务对外能力的管理。进程管理模块负责Ability应用所在进程的启动和销毁、及其进程信息维护等功能。Ability栈管理模块负责维护各个Ability之间跳转的先后关系。生命周期调度模块是Ability管理服务根据系统当前的操作调度Ability进入相应的状态的模块。连接管理模块是Ability管理服务对Service类型Ability连接管理的模块 - -- **AppSpawn**:负责创建Ability应用所在进程的系统服务,该服务有较高的权限,为Ability应用设置相应的权限,并预加载一些通用的模块,加速应用的启动。 - - -## 包管理子系统 - -包管理子系统是OpenHarmony为开发者提供的安装包管理框架。 - -**图 4** 包管理子系统框架图 -![](/images/device-dev/subsystems/figure/包管理子系统框架图.png "包管理子系统框架图") - -- **BundleKit**:是包管理服务对外提供的接口,有安装/卸载接口、包信息查询接口、包状态变化listen接口。 -- **包扫描器**:用来解析本地预制或者安装的安装包,提取里面的各种信息,供管理子模块进行管理,持久化。 -- **包安装子模块**:安装,卸载,升级一个包;包安装服务是一个单独进程和包管理服务通过IPC进行通信,该服务用于创建、删除安装目录和数据目录等,具有较高的权限。 - -- **包管理子模块**:管理安装包相关的信息,存储持久化包信息。 - -- **包安全管理子模块**:签名检查、权限授予、权限管理。 - - -## 运作机制 - -Ability子系统的核心模块是Ability管理服务、包管理子系统的核心模块是包管理服务,这两个服务是系统级服务,借助系统服务框架Samgr实现服务的注册与发现,并对其他进程提供Ability管理服务和包管理服务。Ability管理服务和包管理服务通过AbilityKit和BundleKit以接口的形式向外提供服务。 - -**图 5** Ability管理服务和包管理服务启动 -![](/images/device-dev/subsystems/figure/Ability管理服务和包管理服务启动.png "Ability管理服务和包管理服务启动") - -Ability管理服务和包管理服务启动后,就可以安装OpenHarmony应用和启动运行OpenHarmony应用。 - -**图 6** 应用启动流程 -![](/images/device-dev/subsystems/figure/应用启动流程.png "应用启动流程") - -桌面为Ability管理服务启动的第一个OpenHarmony应用。桌面启动后,用户可以在桌面上点击安装的OpenHarmony应用并启动该应用。上图6为从桌面启动一个已安装应用的交互流程。 - -从图中可知,Ability管理服务负责协调Ability之间的显示隐藏,包管理服务负责Ability信息的存储查询。 - -## 约束与限制 - -- 语言版本 - - - C++11版本或以上 - - -- 框架针对不同的芯片平台和底层OS能力,规格有所区别 - - - Cortex-M RAM/ROM: - - - RAM:建议大于20K - - - ROM: \> 300K (包含JS应用开发框架,UIKit及引擎等强相关子系统) - - - Cortex-A RAM/ROM: - - - RAM:建议大于2M - - - ROM:\> 2M (包含JS应用开发框架,UIKit及引擎等强相关子系统) - - - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/10.\347\224\250\346\210\267\347\250\213\345\272\217\346\241\206\346\236\266/02.\346\220\255\345\273\272\347\216\257\345\242\203.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/10.\347\224\250\346\210\267\347\250\213\345\272\217\346\241\206\346\236\266/02.\346\220\255\345\273\272\347\216\257\345\242\203.md" deleted file mode 100644 index 2185914efba40f0586ce847f68d3047c4654c4f4..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/10.\347\224\250\346\210\267\347\250\213\345\272\217\346\241\206\346\236\266/02.\346\220\255\345\273\272\347\216\257\345\242\203.md" +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: 搭建环境 -permalink: /pages/01050a02 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 搭建环境 - -- 开发板:Hi3516DV300 - -- [下载源码](/pages/extra/51fbe5/) -- [编译用户程序框架](/pages/01010219) - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/10.\347\224\250\346\210\267\347\250\213\345\272\217\346\241\206\346\236\266/03.\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/10.\347\224\250\346\210\267\347\250\213\345\272\217\346\241\206\346\236\266/03.\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index 2b74d9f88bb2493a0c69b3099c7c975f672d0b64..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/10.\347\224\250\346\210\267\347\250\213\345\272\217\346\241\206\346\236\266/03.\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,722 +0,0 @@ ---- -title: 开发指导 -permalink: /pages/01050a03 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 开发指导 - -- [场景介绍](#section93012287133) -- [接口说明](#section11821047161319) -- [开发步骤](#section10514141679) - - [创建Service类型的Ability](#section19921154214315) - - [包管理接口使用指导](#section1724016743217) - - [Hap包打包](#section171771212328) - - -## 场景介绍 - -- 带界面的Ability的应用,比如:新闻类的应用、视频类的应用、导航类的应用、支付类的应用等等,目前我们看到的大部分应用都是带有界面的用于人机交互的应用。 - -- 不带界面的Ability应用,比如:音乐播放器能在后台播放音乐、后台提供计算服务、导航服务的各类应用等。 - -- 不管是带界面的Ability应用还是不带界面的Ability应用,都要打包成Hap包,最终发布到应用市场,用户通过应用市场下载安装相应的应用。 - -## 接口说明 - -**表 1** Ability子系统的对外接口 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

接口名称

-

接口描述

-

Want *WantParseUri(const char *uri)

-

反序列化接口,由字符串生成Want对象。

-

const char *WantToUri(Want want)

-

序列化,把Want对象生成字符串。

-

void SetWantElement(Want *want, ElementName element);

-

设置ElementName对象。

-

void SetWantData(Want *want, const void *data, uint16_t dataLength)

-

设置数据。

-

bool SetWantSvcIdentity(Want *want, SvcIdentity sid)

-

设置SvcIdentity。

-

void ClearWant(Want *want)

-

清除Want的内部内存数据。

-

void SetMainRoute(const std::string &entry)

-

设置AbilitySlice主路由。

-

void SetUIContent(RootView *rootView)

-

设置布局资源。

-

void OnStart(const Want& intent)

-

Ability生命周期状态回调,Ability启动时被回调。

-

void OnStop()

-

Ability生命周期状态回调,Ability销毁时被回调。

-

void OnActive(const Want& intent)

-

Ability生命周期状态回调,Ability显示时被回调。

-

void OnInactive()

-

Ability生命周期状态回调,Ability隐藏时被回调。

-

void OnBackground()

-

Ability生命周期状态回调,Ability退到后台时被回调。

-

const SvcIdentity *OnConnect(const Want &want)

-

Service类型Ability第一次连接时被回调。

-

void OnDisconnect(const Want &want);

-

Service类型Ability断开连接被回调。

-

void MsgHandle(uint32_t funcId, IpcIo *request, IpcIo *reply);

-

Service类型Ability接收消息处理。

-

void Dump(const std::string &extra)

-

dump Ability信息。

-

void Present(AbilitySlice *abilitySlice, const Want &want)

-

发起AbilitySlice跳转。

-

void Terminate()

-

退出当前AbilitySlice。

-

void SetUIContent(RootView *rootView)

-

设置当前AbilitySlice所在Ability的布局资源。

-

void OnStart(const Want& want)

-

AbilitySlice生命周期状态回调,AbilitySlice启动时被回调。

-

void OnStop()

-

AbilitySlice生命周期状态回调,AbilitySlice销毁时被回调。

-

void OnActive(const Want& want)

-

AbilitySlice生命周期状态回调,AbilitySlice显示时被回调。

-

void OnInactive()

-

AbilitySlice生命周期状态回调,AbilitySlice隐藏时被回调。

-

void OnBackground()

-

AbilitySlice生命周期状态回调,AbilitySlice退到后台时被回调。

-

int StartAbility(const Want &want)

-

启动Ability。

-

int StopAbility(const Want &want)

-

停止Service类型的Ability。

-

int TerminateAbility()

-

销毁当前的Ability。

-

int ConnectAbility(const Want &want, const IAbilityConnection &conn, void *data);

-

绑定Service类型的Ability。

-

int DisconnectAbility(const IAbilityConnection &conn)

-

解绑Service类型的Ability。

-

const char *GetBundleName()

-

获取当前ability的对应应用的包名。

-

const char *GetSrcPath()

-

获取当前ability的对应应用的安装路径。

-

const char *GetDataPath()

-

获取当前ability的对应应用的数据路径。

-

int StartAbility(const Want *want)

-

启动Ability,该接口可以不需要在基于Ability开发的应用中使用。

-

int ConnectAbility(const Want *want, const IAbilityConnection *conn, void *data);

-

绑定Service类型的Ability,该接口可以不需要在基于Ability开发的应用中使用。

-

int DisconnectAbility(const IAbilityConnection *conn);

-

解绑Service类型的Ability,该接口可以不需要在基于Ability开发的应用中使用。

-

int StopAbility(const Want *want)

-

停止Service类型的Ability,该接口可以不需要在基于Ability开发的应用中使用。

-

void (*OnAbilityConnectDone)(ElementName *elementName, SvcIdentity *serviceSid, int resultCode, void *data)

-

绑定Service Ability的回调。

-

void (*OnAbilityDisconnectDone)(ElementName *elementName, int resultCode, void *data)

-

解绑Service Ability的回调。

-

void PostTask(const Task& task)

-

投递任务到异步线程进行处理。

-

void PostQuit()

-

退出当前线程的消息循环。

-

static AbilityEventHandler* GetCurrentHandler()

-

获取当前线程的事件处理器。

-

void Run()

-

执行当前线程的消息循环。

-

#define REGISTER_AA(className)

-

注册开发者的Ability到框架中。

-

#define REGISTER_AS(className)

-

注册开发者的AbilitySlice到框架中。

-
- -## 开发步骤 - -### 创建Service类型的Ability - -1. 在my\_service\_ability.h中创建Ability的子类MyServiceAbility。 - - ``` - class MyServiceAbility: public Ability { - protected: - void OnStart(const Want& want); - const SvcIdentity *OnConnect(const Want &want) override; - void MsgHandle(uint32_t funcId, IpcIo *request, IpcIo *reply) override; - }; - ``` - -2. 调用REGISTER\_AA宏将ServiceAbility注册到应用框架中,以便应用框架实例化开发者的MyServiceAbility。 - - ``` - #include "my_service_ability.h" - - REGISTER_AA(ServiceAbility) - - void MyServiceAbility::OnStart(const Want& want) - { - printf("ServiceAbility::OnStart\n"); - Ability::OnStart(want); - } - - const SvcIdentity *MyServiceAbility::OnConnect(const Want &want) - { - printf("ServiceAbility::OnConnect\n"); - return Ability::OnConnect(want); - } - - void MyServiceAbility::MsgHandle(uint32_t funcId, IpcIo *request, IpcIo *reply) - { - printf("ServiceAbility::MsgHandle, funcId is %u\n", funcId); - int result = 0; - if (funcId == 0) { - result = IpcIoPopInt32(request) + IpcIoPopInt32(request); - } - // push data - IpcIoPushInt32(reply, result); - } - ``` - -3. 实现Service相关的生命周期方法。Service也是一种Ability,Ability为服务提供了以下生命周期方法,用户可以重写这些方法来添加自己的处理。用户在重写的方法里,需要调用父类对应的方法。 - - OnStart\(\) - - 该方法在创建Service的时候调用,用于做一些Service初始化且耗时较短的工作,在Service的整个生命周期只会调用一次。 - - ``` - void MyServiceAbility::OnStart(const Want& want) - { - printf("ServiceAbility::OnStart\n"); - Ability::OnStart(want); - } - ``` - - - OnConnect​\(\) - - 在组件和服务连接时调用,该方法返回SvcIdentity,组件可以通过它,与服务交互。 - - ``` - const SvcIdentity *MyServiceAbility::OnConnect(const Want &want) - { - printf("ServiceAbility::OnConnect\n"); - return Ability::OnConnect(want); - } - ``` - - - OnDisconnect​\(\) - - 在组件与绑定的Service断开连接时调用。 - - - OnStop\(\) - - 在Service销毁时调用。Service应通过实现此方法来清理任何资源,如关闭线程、注册的侦听器等。 - -4. 重写消息处理方法。 - - MsgHandle是Service用来处理客户端消息的方法。其中funcId是客户端传过来的消息类型,request是客户端传过来的序列化请求参数。如果用户在处理完成之后想要把结果传回去,需要把结果序列化后写入reply中。 - - ``` - void ServiceAbility::MsgHandle(uint32_t funcId, IpcIo *request, IpcIo *reply) - { - printf("ServiceAbility::MsgHandle, funcId is %d\n", funcId); - int result = 0; - if (funcId == PLUS) { - result = IpcIoPopInt32(request) + IpcIoPopInt32(request); - } - // push data - IpcIoPushInt32(reply, result); - } - ``` - -5. 注册Service。 - - Service也需要在应用清单文件config.json中进行注册,注册类型type需要设置为service。 - - ``` - "abilities": [{ - "name": "ServiceAbility", - "icon": "res/drawable/phone.png", - "label": "test app 2", - "launchType": "standard", - "type": "service", - "visible": true - } - ] - ``` - -6. 启动Service。 - - Ability为用户提供了StartAbility\(\)方法来启动另外一个Ability,因为Service也是Ability的一种,开发者同样可以通过将Want传递给该方法来启动Service。 - - 开发者可以通过Want的SetWantElement \(\)来设置目标服务信息。ElementName结构体的两个主要参数:第一个参数为包名称;第二个参数为目标Ability。 - - ``` - { - Want want = { nullptr }; - ElementName element = { nullptr }; - SetElementBundleName(&element, "com.company.appname"); - SetElementAbilityName(&element, "ServiceAbility"); - SetWantElement(&want, element); - StartAbility(want); - ClearElement(&element); - ClearWant(&want); - } - ``` - - StartAbility\(\) 方法会立即执行,如果Service尚未运行,则系统首先会调用OnStart\(\)。 - - - 停止Service。 - - Service一旦创建就会一直保持在后台运行,开发者可以通过调用StopAbility\(\)来停止Service。 - -7. 连接Service。 - - 如果Service需要与Page Ability或其他应用组件中的Service进行交互,则应创建用于连接的Service。Service支持其他Ability通过ConnectAbility\(\)与其进行连接,ConnectAbility\(\)需要传入目标Service的Want,以及IAbilityConnection的实例来处理回调。IAbilityConnection提供了两个方法供用户实现,OnAbilityConnectDone\(\)用来处理连接的回调,OnAbilityDisconnectDone\(\)用来处理断开连接的回调。 - - ``` - { - // ability创建IAbilityConnection对象和定义IAbilityConnection的两个方法实现 - IAbilityConnection abilityConnection = new IAbilityConnection(); - abilityConnection->OnAbilityConnectDone = OnAbilityConnectDone; - abilityConnection->OnAbilityDisconnectDone = OnAbilityDisconnectDone; - - void OnAbilityConnectDone(ElementName *elementName, SvcIdentity *serviceSid, - int resultCode, void *data) - { - if (resultCode != 0) { - return; - } - // push data - IpcIo request; - char dataBuffer[IPC_IO_DATA_MAX]; - IpcIoInit(&request, dataBuffer, IPC_IO_DATA_MAX, 0); - IpcIoPushInt32(&request, 10); - IpcIoPushInt32(&request, 6); - - // send and getReply - IpcIo reply; - uintptr_t ptr = 0; - if (Transact(nullptr, *serviceSid, 0, &request, &reply, - LITEIPC_FLAG_DEFAULT, &ptr) != LITEIPC_OK) { - printf("transact error\n"); - return; - } - int result = IpcIoPopInt32(&reply); - printf("execute add method, result is %d\n", result); - if (ptr != 0) { - FreeBuffer(nullptr, reinterpret_cast(ptr)); - } - } - - void OnAbilityDisconnectDone(ElementName *elementName, - int resultCode, void *data) - { - printf("elementName is %s, %s\n", - elementName->bundleName, elementName->abilityName); - } - } - ``` - - - 发起connect和disconnect。 - - ``` - { - // ability发起connect - Want want = { nullptr }; - ElementName element = { nullptr }; - SetElementBundleName(&element, "com.company.appname"); - SetElementAbilityName(&element, "ServiceAbility"); - SetWantElement(&want, element); - ConnectAbility(want, *abilityConnection, this); - - // ability发起disconnect - DisconnectAbility(*abilityConnection); - } - ``` - - - -### 包管理接口使用指导 - -**安装应用** - -安装接口只能给内置的系统应用使用。根据应用的安装路径,可以在安装应用时进行选择: - -- 将应用安装到系统默认的文件目录/storage/app/。 -- 将应用安装到系统外挂的存储介质中,例如micro sdcard。 - -这两种选择可以在创建InstallParam实例的时候指定,当InstallParam的成员变量installLocation为 INSTALL\_LOCATION\_INTERNAL\_ONLY时,意味着应用将会被安装到/storage/app/目录下;当InstallParam的成员变量installLocation为INSTALL\_LOCATION\_PREFER\_EXTERNAL时,意味着应用将被安装到存储介质,其安装目录是/sdcard/app/。由于安装应用的过程是异步的,所以需要使用类似信号量的机制来确保安装的回调可以被执行。 - -安装应用的步骤如下(示例代码以安装到系统目录为例): - -1. 将经过安全签名的应用放置于指定的目录下。 -2. 创建InstallParam实例和信号量。 - - ``` - InstallParam installParam = { - .installLocation = INSTALL_LOCATION_INTERNAL_ONLY, // 安装到系统目录 - .keepData = false - }; - static sem_t g_sem; - ``` - -3. 定义回调函数。 - - ``` - static void InstallCallback(const uint8_t resultCode, const void *resultMessage) - { - std::string strMessage = reinterpret_cast(resultMessage); - if (!strMessage.empty()) { - printf("install resultMessage is %s, %d\n", strMessage.c_str(),resultCode); - } - sem_post(&g_sem); - } - ``` - -4. 调用Install接口。 - - ``` - const uint32_t WAIT_TIMEOUT = 30; - sem_init(&g_sem, 0, 0); - std::string installPath = “/storage/bundle/demo.hap”; // hap包的存储路径 - bool result = Install(installPath.c_str(), &installParam, InstallCallback); - struct timespec ts = {}; - clock_gettime(CLOCK_REALTIME, &ts); - ts.tv_sec += WAIT_TIMEOUT; // 超时即释放信号量 - sem_timedwait(&g_sem, &ts); - ``` - - -**卸载应用** - -卸载应用的时候可以选择是否保留应用的数据,开发者可以通过创建的InstallParam实例的成员变量keepData来确定。当keepData为true, 卸载应用之后将保留应用的数据,当keepData为false时,卸载应用之后将不会保留应用的数据。 - -1. 创建InstallParam实例和信号量。 - - ``` - static sem_t g_sem; - InstallParam installParam = { - .installLocation = 1, - .keepData = false // 不保留应用数据 - }; - ``` - -2. 定义回调函数。 - - ``` - static void UninstallCallback(const uint8_t resultCode, const void *resultMessage) - { - std::string strMessage = reinterpret_cast(resultMessage); - if (!strMessage.empty()) { - printf("uninstall resultMessage is %s\n", strMessage.c_str()); - g_resultMessage = strMessage; - } - g_resultCode = resultCode; - sem_post(&g_sem); - } - ``` - -3. 调用Uninstall接口。 - - ``` - sem_init(&g_sem, 0, 0); - const uint32_t WAIT_TIMEOUT = 30; - std::string BUNDLE_NAME = “com.huawei.demo”; // 卸载应用的包名 - Uninstall(BUNDLE_NAME.c_str(), &installParam, UninstallCallback); - struct timespec ts = {}; - clock_gettime(CLOCK_REALTIME, &ts); - ts.tv_sec += WAIT_TIMEOUT; - sem_timedwait(&g_sem, &ts); - ``` - - -**查询已安装应用的包信息** - -开发者可以利用BundleManager提供的接口GetBundleInfo来查询系统内已安装应用的包信息。 - -1. 创建以及初始化BundleInfo。 - - ``` - BundleInfo bundleInfo; - (void) memset_s(&bundleInfo, sizeof(BundleInfo), 0, sizeof(BundleInfo)); - ``` - -2. 调用GetBundleInfo接口,指定查询应用的包名,同时指定flag来确定获取的BundleInfo中是否含有元能力信息(实例代码以含有元能力信息为例)。 - - ``` - std::string BUNDLE_NAME = "com.huawei.demo"; - uint8_t ret = GetBundleInfo(BUNDLE_NAME.c_str(), 1, &bundleInfo); // flags = 1,获取包信息中含有元能力信息 - ``` - -3. 使用完获取的BundleInfo之后,要及时清理掉其内部所占用的内存空间避免内存泄漏。 - - ``` - ClearBundleInfo(&bundleInfo); - ``` - - -### Hap包打包 - -打包工具一般集成到开发工具或者ide中,开发者一般不涉及直接使用该工具,下面的介绍开发者可以作为了解。打包工具的jar包在开源代码中的位置:developtools/packing\_tool/jar。 - -- 打包命令行参数 - - **表 2** 打包所需要的资源文件描述 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

命令参数

-

对应的资源文件

-

说明

-

是否可缺省

-

--mode

-

-

-

为“hap”字段,打包生成hap

-

-

--json-path

-

清单文件config.json

-

-

-

-

--resources-path

-

资源文件resources

-

-

-

-

--assets-path

-

资源文件assets

-

-

-

-

--lib-path

-

依赖库文件

-

-

-

-

--shared-libs-path

-

共享库文件

-

针对系统应用的共享库,特殊情况下使用

-

-

--ability-so-path

-

主功能so文件

-

-

-

-

--index-path

-

资源索引

-

资源索引文件由资源生成工具生成,由资源流水线会集成该工具

-

-

--out-path

-

-

-

生成的hap包输出路径,默认为当前目录

-

-

--force

-

-

-

是否覆盖原有同名文件,默认为false

-

-
- -- 打包示例 - - 开发视图 - - ![](/images/device-dev/subsystems/figure/zh-cn_image_0000001062942690.png) - - - 编译视图 - - ![](/images/device-dev/subsystems/figure/zh-cn_image_0000001062334618.png) - - - 使用打包工具执行以下命令打包: - - ![](/images/device-dev/subsystems/figure/zh-cn_image_0000001062476933.png) - - ``` - $ java -jar hmos_app_packing_tool.jar --mode hap --json-path ./config.json --assets-path ./assets/ --ability-so-path ./libentry.so --index-path ./resources.index --out-path out/entry.hap --force true - ``` - - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/10.\347\224\250\346\210\267\347\250\213\345\272\217\346\241\206\346\236\266/04.\345\274\200\345\217\221\345\256\236\344\276\213.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/10.\347\224\250\346\210\267\347\250\213\345\272\217\346\241\206\346\236\266/04.\345\274\200\345\217\221\345\256\236\344\276\213.md" deleted file mode 100644 index 2f8dac51b8a851cdb313c7784de2972145cd491b..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/10.\347\224\250\346\210\267\347\250\213\345\272\217\346\241\206\346\236\266/04.\345\274\200\345\217\221\345\256\236\344\276\213.md" +++ /dev/null @@ -1,17 +0,0 @@ ---- -title: 开发实例 -permalink: /pages/01050a04 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 开发实例 - -开发实例可参考[开源项目中的示例](https://gitee.com/openharmony/aafwk_aafwk_lite/tree/master/frameworks/ability_lite/example) - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/11.OTA\345\215\207\347\272\247.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/11.OTA\345\215\207\347\272\247.md" deleted file mode 100644 index 02394e714af02ee9ae66b818cf46441604a15f08..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/11.OTA\345\215\207\347\272\247.md" +++ /dev/null @@ -1,371 +0,0 @@ ---- -title: OTA升级 -permalink: /pages/01050b -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# OTA升级 - -- [约束与限制](#section691733275418) -- [生成公私钥对](#section94411533155010) -- [生成升级包](#section632383718539) -- [上传升级包](#section5772112473213) -- [下载升级包](#section251732474917) -- [厂商应用集成OTA能力](#section298217330534) -- [API应用场景-默认场景](#section7685171192916) - - [开发指导](#section0745926153017) - - [示例代码](#section1337111363306) - -- [API应用场景-定制场景](#section1686395317306) - - [开发指导](#section524515314317) - - [示例代码](#section525974743120) - -- [系统升级](#section151997114334) - -OTA(Over the Air)提供对设备远程升级的能力,可以让您的设备(如IP摄像头等),轻松支持远程升级能力。目前仅支持全量包升级,暂不支持差分包升级。全量包升级是将新系统全部内容做成升级包,进行升级;差分包升级是将新老系统的差异内容做成升级包,进行升级。 - -## 约束与限制 - -- 支持基于Hi3861/Hi3518EV300/Hi3516DV300芯片的开源套件。 -- 对Hi3518EV300/Hi3516DV300开源套件,设备需要支持SD卡(VFAT格式)。 - -## 生成公私钥对 - -1. 准备工作:在Windows PC 上,下载安装OpenSSL工具,并配置环境变量。OpenSSL下载路径: - - [http://slproweb.com/products/Win32OpenSSL.html](http://slproweb.com/products/Win32OpenSSL.html) - -2. 在tools\\update\_tools\\update\_pkg\_tools目录下,下载升级包制作工具,保存到Windows本地路径,例如D:\\ota\_tools。 -3. 如图,运行ota\_tools\\key下的Generate\_public\_private\_key.bat ,生成公钥Metis\_PUBLIC.key、私钥private.key和公钥对应的数组public\_arr.txt文件,请妥善保管私钥private.key。 - - **图 1** 生成公私钥对 - - - ![](/images/device-dev/subsystems/figure/zh-cn_image_0000001060200050.png) - -4. 用public\_arr.txt里面的全部内容替换OTA模块base\\update\\ota\_lite\\frameworks\\source\\verify\\hota\_verify.c中的g\_pubKeyBuf 。 - - 示例,public\_arr.txt内容 - - ``` - 0x30,0x82,0x1,0xa,0x2,0x82,0x1,0x1,0x0,0xc7,0x8c,0xf3,0x91,0xa1,0x98,0xbf,0xb1,0x8c, - 0xbe,0x22,0xde,0x32,0xb2,0xfa,0xec,0x2c,0x69,0xf6,0x8f,0x43,0xa7,0xb7,0x6f,0x1e,0x4a,0x97, - 0x4b,0x27,0x5d,0x56,0x33,0x9a,0x73,0x4e,0x7c,0xf8,0xfd,0x1a,0xf0,0xe4,0x50,0xda,0x2b,0x8, - 0x74,0xe6,0x28,0xcc,0xc8,0x22,0x1,0xa8,0x14,0x9,0x46,0x46,0x6a,0x10,0xcd,0x39,0xd,0xf3, - 0x4a,0x7f,0x1,0x63,0x21,0x33,0x74,0xc6,0x4a,0xeb,0x68,0x40,0x55,0x3,0x80,0x1d,0xd9,0xbc, - 0xd4,0xb0,0x4a,0x84,0xb7,0xac,0x43,0x1d,0x76,0x3a,0x61,0x40,0x23,0x3,0x88,0xcc,0x80,0xe, - 0x75,0x10,0xe4,0xad,0xac,0xb6,0x4c,0x90,0x8,0x17,0x26,0x21,0xff,0xbe,0x1,0x82,0x16,0x76, - 0x9a,0x1c,0xee,0x8e,0xd9,0xb0,0xea,0xd5,0x50,0x61,0xcc,0x9c,0x2e,0x78,0x15,0x2d,0x1f,0x8b, - 0x94,0x77,0x30,0x39,0x70,0xcf,0x16,0x22,0x82,0x99,0x7c,0xe2,0x55,0x37,0xd4,0x76,0x9e,0x4b, - 0xfe,0x48,0x26,0xc,0xff,0xd9,0x59,0x6f,0x77,0xc6,0x92,0xdd,0xce,0x23,0x68,0x83,0xbd,0xd4, - 0xeb,0x5,0x1b,0x2a,0x7e,0xda,0x9a,0x59,0x93,0x41,0x7b,0x4d,0xef,0x19,0x89,0x4,0x8d,0x5, - 0x7d,0xbc,0x3,0x1f,0x77,0xe6,0x3d,0xa5,0x32,0xf5,0x4,0xb7,0x9c,0xe9,0xfa,0x6e,0xc,0x9f, - 0x4,0x62,0xfe,0x2a,0x5f,0xbf,0xeb,0x9a,0x73,0xa8,0x2a,0x72,0xe3,0xf0,0x57,0x56,0x5c,0x59, - 0x14,0xdd,0x79,0x11,0x42,0x3a,0x48,0xf7,0xe8,0x80,0xb1,0xaf,0x1c,0x40,0xa2,0xc6,0xec,0xf5, - 0x67,0xc1,0x88,0xf6,0x26,0x5c,0xd3,0x11,0x5,0x11,0xed,0xb1,0x45,0x2,0x3,0x1,0x0,0x1, - ``` - - 示例,OTA模块的公钥 - - ``` - #define PUBKEY_LENGTH 270 - - static uint8 g_pubKeyBuf[PUBKEY_LENGTH] = { - 0x30, 0x82, 0x01, 0x0A, 0x02, 0x82, 0x01, 0x01, 0x00, 0xBF, 0xAA, 0xA5, 0xB3, 0xC2, 0x78, 0x5E, - 0x63, 0x07, 0x84, 0xCF, 0x37, 0xF0, 0x45, 0xE8, 0xB9, 0x6E, 0xEF, 0x04, 0x88, 0xD3, 0x43, 0x06, - ``` - -5. 对Hi3518EV300/Hi3516DV300套件,在上一步的基础上,还需用public\_arr.txt里面的全部内容替换uboot模块device\\hisilicon\\third\_party\\uboot\\u-boot-2020.01\\product\\hiupdate\\verify\\update\_public\_key.c中的g\_pub\_key中的全部内容。 - - 示例,uboot模块的公钥 - - ``` - static unsigned char g_pub_key[PUBKEY_LEN] = { - 0x30, 0x82, 0x01, 0x0A, 0x02, 0x82, 0x01, 0x01, - 0x00, 0xBF, 0xAA, 0xA5, 0xB3, 0xC2, 0x78, 0x5E, - ``` - - -## 生成升级包 - -1. 在ota\_tools\\Components目录下,归放需要升级的文件。 - - **图 2** 原始镜像归放位置 - - - ![](/images/device-dev/subsystems/figure/zh-cn_image_0000001061889268.png) - - **表 1** 升级包内的文件 - - - - - - - - - - - - - - - - - - - - - - -

包内文件名

-

说明

-

u-boot.bin

-

将编译生成的u-boot-hi351XevX00.bin文件重命名后得到。

-

kernel.bin

-

将编译生成的liteos.bin/kernel文件重命名后得到。

-

rootfs.img

-

将编译生成的rootfs_xxxxx.img文件重命名后得到。

-

config

-

与开发板类型和内核类型相关,参考开源套件的SD卡烧写说明。

-

OTA.tag

-

共32字节,内容为:“package_type:otaA1S2D3F4G5H6J7K8”;其中后16字节为随机数,需要随版本变化。

-
- -2. 修改ota\_tools\\xml下的packet\_harmony.xml文件,配置compAddr分区名,对应ota\_tools\\Components\\的文件,其它项不需修改,作为扩展项预留。 - - 示例,配置组件信息 - - ``` - - - .\Components\rootfs_jffs2.img - .\Components\liteos.bin - .\Components\userfs_jffs2.img - - ``` - -3. 将生成的公私钥路径配置到ota\_tools\\xml路径下的packet\_harmony.xml中。 - - 示例,配置公私钥路径 - - ``` - - .\key\private.key - .\key\Metis_PUBLIC.key - - ``` - -4. 在ota\_tools\\VersionDefine.bat中设置产品名称、软件版本号(用于防回滚校验)。 - - 示例,配置产品名称和版本号 - - ``` - set FILE_PRODUCT_NAME=Hisi - - @rem 设置软件版本号 不要超过16位 - set SOFTWARE_VER=OpenHarmony 1.1 - ``` - -5. 执行ota\_tools下的Make\_Harmony\_PKG.bat,生成升级包Hisi\_OpenHarmony 1.1.bin。升级包通过SHA256+RSA2048方式签名,保证完整性和合法性。 - - **图 3** 升级包制作工具 - - - ![](/images/device-dev/subsystems/figure/zh-cn_image_0000001059334449.png) - - -## 上传升级包 - -将升级包Hisi\_OpenHarmony 1.1.bin上传到厂商的OTA服务器。 - -## 下载升级包 - -1. 厂商应用从OTA服务器下载Hisi\_OpenHarmony 1.1.bin。 -2. 对Hi3518EV300/Hi3516DV300开源套件,需要插入SD卡\(容量\>100MBytes\)。 - -## 厂商应用集成OTA能力 - -- 调用OTA模块的动态库libhota.so,对应头文件位于:base\\update\\ota\_lite\\interfaces\\kits\\hota\_partition.h&hota\_updater.h; -- libhota.so对应的源码路径为base\\update\\ota\_lite\\frameworks\\source。 -- API的使用方法,见本文“API应用场景”和API文档的OTA接口章节。 -- 如果需要适配开发板,请参考HAL层头文件:base\\update\\ota\_lite\\hals\\hal\_hota\_board.h。 - -## API应用场景-默认场景 - -升级包是按照上文“生成公私钥对”和“生成升级包”章节制作的。 - -### **开发指导** - -1. 应用侧通过下载,获取当前设备升级包后,调用HotaInit接口初始化OTA模块。 -2. 调用HotaWrite接口传入升级包数据流,接口内部实现校验、解析及写入升级数据流。 -3. 写入完成后,调用HotaRestart接口重启系统。 - - 升级过程中,使用HotaCancel接口可以取消升级。 - - -### **示例代码** - -使用OpenHarmony的“升级包格式和校验方法“进行升级。 - -``` -int main(int argc, char **argv) -{ - printf("this is update print!\r\n"); - if (HotaInit(NULL, NULL) < 0) { - printf("ota update init fail!\r\n"); - return -1; - } - int fd = open(OTA_PKG_FILE, O_RDWR, S_IRUSR | S_IWUSR); - if (fd < 0) { - printf("file open failed, fd = %d\r\n", fd); - (void)HotaCancel(); - return -1; - } - int offset = 0; - int fileLen = lseek(fd, 0, SEEK_END); - int leftLen = fileLen; - while (leftLen > 0) { - if (lseek(fd, offset, SEEK_SET) < 0) { - close(fd); - printf("lseek fail!\r\n"); - (void)HotaCancel(); - return -1; - } - int tmpLen = leftLen >= READ_BUF_LEN ? READ_BUF_LEN : leftLen; - (void)memset_s(g_readBuf, READ_BUF_LEN, 0, READ_BUF_LEN); - if (read(fd, g_readBuf, tmpLen) < 0) { - close(fd); - printf("read fail!\r\n"); - (void)HotaCancel(); - return -1; - } - if (HotaWrite((unsigned char *)g_readBuf, offset, tmpLen) != 0) { - printf("ota write fail!\r\n"); - close(fd); - (void)HotaCancel(); - return -1; - } - offset += READ_BUF_LEN; - leftLen -= tmpLen; - } - close(fd); - printf("ota write finish!\r\n"); - printf("device will reboot in 10s...\r\n"); - sleep(10); - (void)HotaRestart(); - return 0; -} -``` - -## API应用场景-定制场景 - -升级包不是按照上文“生成公私钥对”和“生成升级包”章节制作的,是通过其它方式制作的。 - -### **开发指导** - -1. 应用侧通过下载,获取当前设备升级包后,调用HotaInit接口初始化。 -2. 使用HotaSetPackageType接口设置NOT\_USE\_DEFAULT\_PKG,使用"定制"流程。 -3. 调用HotaWrite接口传入升级包数据流,写入设备。 -4. 写入完成后,调用HotaRead接口读取数据,厂商可以自行校验升级包。 -5. 调用HotaSetBootSettings设置启动标记,在重启后需要进入uboot模式时使用(可选)。 -6. 调用HotaRestart接口,进行重启。 - - 升级过程中,使用HotaCancel接口可以取消升级。 - - -### **示例代码** - -使用非OpenHarmony的“升级包格式和校验方法“进行升级。 - -``` -int main(int argc, char **argv) -{ - printf("this is update print!\r\n"); - if (HotaInit(NULL, NULL) < 0) { - printf("ota update init fail!\r\n"); - (void)HotaCancel(); - return -1; - } - (void)HotaSetPackageType(NOT_USE_DEFAULT_PKG); - int fd = open(OTA_PKG_FILE, O_RDWR, S_IRUSR | S_IWUSR); - if (fd < 0) { - printf("file open failed, fd = %d\r\n", fd); - (void)HotaCancel(); - return -1; - } - int offset = 0; - int fileLen = lseek(fd, 0, SEEK_END); - int leftLen = fileLen; - while (leftLen > 0) { - if (lseek(fd, offset, SEEK_SET) < 0) { - close(fd); - printf("lseek fail!\r\n"); - (void)HotaCancel(); - return -1; - } - int tmpLen = leftLen >= READ_BUF_LEN ? READ_BUF_LEN : leftLen; - (void)memset_s(g_readBuf, READ_BUF_LEN, 0, READ_BUF_LEN); - if (read(fd, g_readBuf, tmpLen) < 0) { - close(fd); - printf("read fail!\r\n"); - (void)HotaCancel(); - return -1; - } - if (HotaWrite((unsigned char *)g_readBuf, offset, tmpLen) != 0) { - printf("ota write fail!\r\n"); - close(fd); - (void)HotaCancel(); - return -1; - } - offset += READ_BUF_LEN; - leftLen -= tmpLen; - } - close(fd); - printf("ota write finish!\r\n"); - leftLen = fileLen; - while (leftLen > 0) { - int tmpLen = leftLen >= READ_BUF_LEN ? READ_BUF_LEN : leftLen; - (void)memset_s(g_readBuf, READ_BUF_LEN, 0, READ_BUF_LEN); - if (HotaRead(offset, READ_BUF_LEN, (unsigned char *)g_readBuf) != 0) {} - printf("ota write fail!\r\n"); - (void)HotaCancel(); - return -1; - } - /* do your verify and parse */ - offset += READ_BUF_LEN; - leftLen -= tmpLen; - } - /* set your boot settings */ - (void)HotaSetBootSettings(); - printf("device will reboot in 10s...\r\n"); - sleep(10); - (void)HotaRestart(); - return 0; -} -``` - -## 系统升级 - -厂商应用调用OTA模块的API,OTA模块执行升级包的签名验证、版本防回滚、烧写落盘功能,升级完成后自动重启系统。 - -对Hi3518EV300/Hi3516DV300开源套件,在需要实现防回滚功能的版本中,需要增加LOCAL\_VERSION的值,如"ohos default 1.0"-\>"ohos default 1.1",LOCAL\_VERSION在device\\hisilicon\\third\_party\\uboot\\u-boot-2020.01\\product\\hiupdate\\ota\_update\\ota\_local\_info.c中。 - -示例,增加版本号 - -``` -const char *get_local_version(void) -{ -#if defined(CONFIG_TARGET_HI3516EV200) || \ - defined(CONFIG_TARGET_HI3516DV300) || \ - defined(CONFIG_TARGET_HI3518EV300) -#define LOCAL_VERSION "ohos default 1.0" /* increase: default release version */ -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/12.\347\224\265\350\257\235\346\234\215\345\212\241/01.\347\224\265\350\257\235\346\234\215\345\212\241\346\246\202\350\277\260.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/12.\347\224\265\350\257\235\346\234\215\345\212\241/01.\347\224\265\350\257\235\346\234\215\345\212\241\346\246\202\350\277\260.md" deleted file mode 100644 index 3b2b1d134ff804fdd7dd0296c04d532a6a958073..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/12.\347\224\265\350\257\235\346\234\215\345\212\241/01.\347\224\265\350\257\235\346\234\215\345\212\241\346\246\202\350\277\260.md" +++ /dev/null @@ -1,55 +0,0 @@ ---- -title: 电话服务概述 -permalink: /pages/01050c01 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 电话服务概述 - -- [概述](#section184mcpsimp) -- [基本概念](#section187mcpsimp) -- [运作机制](#section194mcpsimp) -- [约束与限制](#section205mcpsimp) - -## 概述 - -本指南简要介绍了Modem厂商库的集成、初始化、业务请求响应和事件上报的方法,并通过通话业务的具体开发实例呈现厂商库的适配开发过程,供不同Modem芯片的开发者参考,从而帮助其高效地实现电话相关业务功能的开发。 - -## 基本概念 - -- Telephony Service:电话服务子系统核心服务层。主要功能是初始化RIL管理类、SIM卡和搜网模块;获取RIL Adapter服务,通过注册回调服务,实现与RIL Adapter的通信功能;通过发布订阅,来实现与通话、短信等功能模块之间的通信。 -- RIL Adapter:电话服务子系统RIL适配层。该层主要包括厂商库加载,业务接口实现。用于屏蔽不同Modem厂商的硬件差异,为上层提供统一的接口,通过注册HDF服务与上层接口通信。 -- HDF:硬件驱动框架(Hardware Driver Foundation)。用于提供统一外设访问能力和驱动开发、管理框架。 -- hdc\_std:OpenHarmony设备连接器(OpenHarmony Device Connector)。是OpenHarmony为开发人员提供的用于设备连接调试的命令行工具。 - -## 运作机制 - -**图 1** RIL Adapter模块架构图 - - -![](/images/device-dev/subsystems/figure/ril-adapter模块架构图.png) - -RIL Adapter模块架构如图1所示,内部主要分为hril\_hdf、hril和vendorlib三层。 - -- hril\_hdf:RIL Adapter的唯一入口,主要负责Modem厂商库的加载。其中,modem\_adapter实现了单一固件对不同Modem的适配。 - - 其实现机制为:在加载Modem厂商库之前,从kernel获取Modem的设备型号,根据此型号加载对应的Modem厂商库。 - -- hril:OpenHarmony无线接口层(OpenHarmony Radio Interface Layer)。与Telephony Service交互的接口实现部分,实现了Telephony Service和vendorlib通信的功能,包括SIM卡、搜网、蜂窝数据、蜂窝通话和短彩信等。 -- vendorlib:Modem厂商库文件。不同的Modem厂商根据RIL Adapter提供的标准化接口或ID,进行Modem厂商库的开发(vendorlib由Modem厂商提供)。 - -hril\_hdf执行后,将动态加载vendorlib,vendorlib可以从hril\_hdf中获取处理响应和上报的函数指针,该过程结束后,hril\_hdf才可通过vendorlib与Modem通信。 - -## 约束与限制 - -**规格限制:** - -需要设备厂商至少支持一个Modem,如果不支持任何Modem,无需实现厂商库接口。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/12.\347\224\265\350\257\235\346\234\215\345\212\241/02.\347\224\265\350\257\235\346\234\215\345\212\241\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/12.\347\224\265\350\257\235\346\234\215\345\212\241/02.\347\224\265\350\257\235\346\234\215\345\212\241\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index 8410eff8d770ff477c5033cc09e0a3bcff99ae95..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/12.\347\224\265\350\257\235\346\234\215\345\212\241/02.\347\224\265\350\257\235\346\234\215\345\212\241\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,623 +0,0 @@ ---- -title: 电话服务开发指导 -permalink: /pages/01050c02 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 电话服务开发指导 - -- [Modem厂商库初始化开发指导](#section211mcpsimp) - - [场景介绍](#section213mcpsimp) - - [接口说明](#section811343241215) - - [开发步骤](#section51031144122) - - [调测验证](#section5351151517132) - -- [Modem业务请求及响应开发指导](#section295mcpsimp) - - [场景介绍](#section297mcpsimp) - - [接口说明](#section9503155219134) - - [开发步骤](#section17190412101414) - - [调测验证](#section10207938171413) - -- [Modem事件上报开发指导](#section390mcpsimp) - - [场景介绍](#section401mcpsimp) - - [接口说明](#section191193791518) - - [开发步骤](#section16394112401512) - - [调测验证](#section16999174401516) - - [开发实例](#section33444350167) - -- [Modem厂商库集成指导](#section590mcpsimp) - - [编译设置](#section592mcpsimp) - - [调测验证](#section620mcpsimp) - - -## Modem厂商库初始化开发指导 - -### 场景介绍 - -Modem厂商库初始化是指在厂商库里实现const HRilOps \*RilInitOps\(const struct HRilReport \*reportOps\)函数,在该函数里处理三个重要的功能: - -- 接收RIL Adapter事件回调的函数指针,当Modem有业务事件上报时,调用对应的函数指针,把事件上报给RIL Adapter。 -- 创建读取Modem设备节点的线程,在该线程里会循环地读取Modem上报的事件,并把接收的Modem信息解析为具体业务相关的事件进行上报。 -- 返回业务请求接口的函数指针给RIL Adapter。 - -### 接口说明 - -Modem厂商库初始化接口。 - -**表 1** Modem厂商库初始化接口功能介绍 - - - - - - - - - - -

接口名

-

描述

-

const HRilOps *RilInitOps(const struct HRilReport * reportOps)

-

接口功能:Modem厂商库运行的入口。

-

参数reportOps:RIL Adapter传入的事件回调函数指针。

-

返回值:业务请求接口的函数指针。

-
- -### 开发步骤 - -1. RilInitOps接口中设置RIL Adapter传入的事件回调函数指针。 - - ``` - // 定义Modem厂商库回调函数指针 - static struct HRilReport g_reportOps = { - OnCallReport, // 通话相关业务回调函数 - OnDataReport, // 蜂窝数据相关业务回调函数 - OnModemReport, // Modem相关业务回调函数 - OnNetworkReport, // 搜网相关业务回调函数 - OnSimReport, // SIM卡相关业务回调函数 - OnSmsReport // 短信相关业务回调函数 - }; - ``` - - -1. 创建主线程g\_reader,开启消息循环。 - - ``` - pthread_attr_t t; - pthread_attr_init(&t); - pthread_attr_setdetachstate(&t, PTHREAD_CREATE_DETACHED); - ret = pthread_create(&g_reader, &t, ReaderLoop, &t); // 创建线程 - ``` - - -1. 在g\_eventListeners线程用open\(\)打开Modem设备节点,并创建g\_reader线程循环读取处理Modem上报的消息。 - - ``` - g_fd = open(g_devicePath, O_RDWR); // 打开设备节点,入参g_devicePath是Modem设备节点 - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - ret = pthread_create(&g_eventListeners, &attr, EventListeners, NULL); - ``` - - -1. 返回业务请求接口的函数指针。 - - ``` - // call模块业务请求接口结构体 - typedef struct { - // 获取呼叫列表 - void (*GetCallList)(ReqDataInfo *requestInfo, const void *data, size_t dataLen); - // 拨打电话 - void (*Dial)(ReqDataInfo *requestInfo, const void *data, size_t dataLen); - // 挂断电话 - void (*Hangup)(ReqDataInfo *requestInfo, const void *data, size_t dataLen); - // 拒接来电 - void (*Reject)(ReqDataInfo *requestInfo, const void *data, size_t dataLen); - // 接听来电 - void (*Answer)(ReqDataInfo *requestInfo, const void *data, size_t dataLen); - } HRilCallReq; - - // call模块回调函数指针 - static const HRilCallReq g_callReqOps = { - .GetCallList = ReqGetCallList, // 获取呼叫列表接口 - .Dial = ReqDial, // 拨打电话接口 - .Hangup = ReqHangup, // 挂断电话接口 - .Reject = ReqReject, // 拒接来电接口 - .Answer = ReqAnswer, // 接听来电接口 - }; - - // 业务请求结构体 - typedef struct { - const HRilCallReq *callOps; // 通话相关业务请求结构体指针 - const HRilSimReq *simOps; // SIM卡相关业务请求结构体指针 - const HRilSmsReq *smsOps; // 短彩信相关业务请求结构体指针 - const HRilDataReq *dataOps; // 蜂窝数据相关业务请求结构体指针 - const HRilNetworkReq *networkOps; // 搜网相关业务请求结构体指针 - const HRilModemReq *modemOps; // Modem相关业务请求结构体指针 - } HRilOps; - - // 业务请求接口定义 - HRilOps g_hrilOps = { - .callOps = &g_callReqOps, // 定义通话业务请求接口 - .simOps = &g_simReqOps, // 定义SIM卡业务请求接口 - .smsOps = &g_smsReqOps, // 定义短彩信业务请求接口 - .networkOps = &g_networkReqOps, // 定义蜂窝数据业务请求接口 - .dataOps = &g_dataReqOps, // 定义搜网业务请求接口 - .modemOps = &g_modemReqOps, // 定义Modem业务请求接口 - }; - ``` - - -### 调测验证 - -1. 用[hdc\_std工具](/pages/01090202#section05992022154916)连接调试设备,把编译生成的libril\_vendor.z.so库文件(参见[Modem厂商库集成指导](#section590mcpsimp))通过以下命令推到/system/lib/目录下。 - - ``` - hdc_std file send libril_vendor.z.so /system/lib/ - ``` - -2. 执行hdc\_std shell sync,hdc\_std shell reboot重启设备。 - - ``` - hdc_std shell sync - hdc_std shell reboot - ``` - -3. 执行hdc\_std shell hilog,根据日志查看函数RilInitOps\(\)是否正确执行完成。如下调测验证日志供参考: - - ``` - 01-01 05:13:23.071 136 2319 D 00000/RilAdapterInit: [RilAdapterDispatch-(hril_hdf.c:55)] sbuf IPC obtain test success! - 01-01 05:13:23.071 136 2319 D 00000/RilAdapterInit: [LoadVendor-(hril_hdf.c:33)] RilInit rilInit start - 01-01 05:13:23.071 136 2319 D 00000/RilAdapterInit: [LoadVendor -(hril_hdf.c:45)] RilInit rilInit completed - ``` - - -## Modem业务请求及响应开发指导 - -### 场景介绍 - -Modem业务请求及响应是指RIL Adapter收到电话服务具体业务请求后,调用Modem厂商库初始化获得的函数指针,把具体业务请求发送给厂商库,厂商库根据业务请求ID做相应的业务处理。 - -### 接口说明 - -Modem业务请求及响应接口。 - -**表 2** Modem业务请求及响应接口功能介绍(以拨号功能模块为例) - - - - - - - - - - - - - -

接口名

-

描述

-

void ReqDial(ReqDataInfo *requestInfo, const void *data, size_t dataLen);

-

接口功能:对拨号请求进行处理。

-

参数requestInfo:请求类型信息。

-

参数data:被叫号码信息。

-

参数dataLen:数据长度。

-

返回值:无。

-

void (*OnCallReport)(struct ReportInfo reportInfo, const void *data, size_t dataLen);

-

接口功能:对通话业务执行结果进行响应,即当请求业务执行完成后,Modem将该请求执行的结果上报给RIL Adapter。

-

参数reportInfo:返回类型信息。

-

参数data:返回数据。

-

参数dataLen:数据长度。

-

返回值:无。

-
- -### 开发步骤 - -1. 在ReqDial\(\)接口中对拨号请求进行处理。 - - ``` - // 拨号请求接口实现 - void ReqDial(ReqDataInfo *requestInfo, const void *data, size_t dataLen) - { - HRilDial *pDial = NULL; - char cmd[MAX_BUFF_SIZE] = {0}; - const char *clir = NULL; - int ret; - int err = HRIL_ERR_SUCCESS; - struct ReportInfo reportInfo = {}; - ResponseInfo *pResponse = NULL; - if (data == NULL) { - TELEPHONY_LOGE("data is null!!!"); - err = HRIL_ERR_INVALID_PARAMETER; - reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0); - OnCallReport(reportInfo, NULL, 0); - return; - } - pDial = (HRilDial *)data; - switch (pDial->clir) { - case CALL_CLIR_INVOCATION: - clir = "I"; - break; /* invocation */ - case CALL_CLIR_SUPPRESSION: - clir = "i"; - break; /* suppression */ - case CALL_CLIR_SUBSCRIPTION_DEFUALT: - default: - clir = ""; - break; /* subscription default */ - } - (void)sprintf_s(cmd, MAX_BUFF_SIZE, "ATD%s%s;", pDial->address, clir); - ret = SendCommandLock(cmd, NULL, 0, &pResponse); // 发送AT指令 - ...... - } - ``` - -2. 在Modem执行完拨号命令后,调用OnCallReport\(\)回调函数,把该请求执行的结果上报给RIL Adapter。 - - ``` - ret = SendCommandLock(cmd, NULL, 0, &pResponse); - if (ret != 0 || (pResponse != NULL && pResponse->success == 0)) { - TELEPHONY_LOGE("ATD send failed"); - err = HRIL_ERR_GENERIC_FAILURE; - } - reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0); - OnCallReport(reportInfo, NULL, 0); // 调用通话相关回调函数 - ``` - - -### 调测验证 - -1. 用[hdc\_std工具](/pages/01090202#section05992022154916)工具连接调试设备,把编译生成的libril\_vendor.z.so库文件通过以下命令推到/system/lib/目录下。 - - ``` - hdc_std file send libril_vendor.z.so /system/lib/ - ``` - -2. 执行hdc\_std shell sync,hdc\_std shell reboot重启设备。 - - ``` - hdc_std shell sync - hdc_std shell reboot - ``` - -3. hdc\_std shell后执行./system/bin/ril\_adapter\_test,输入编号1,根据提示输入电话号码,测试拨打电话功能。 - - ``` - hdc_std shell - # ./system/bin/ril_adapter_test - ----> Test Enter --------->Call--------------------- - - 1----> RilUnitTest::OnRequestCallDialTest - 2----> RilUnitTest:: OnRequestCallHangupTest - 3----> RilUnitTest:: OnRequestCallAnswerTest - 4----> RilUnitTest::OnRequestCallGetCurrentCallsStatusTest - 5----> RilUnitTest::OnRequestRefusedCallTest - - 1 - ``` - -4. 另开一个终端窗口,执行hdc\_std shell hilog,通过日志查看函数ReqDial\(\)是否正确执行完成。如下调测验证日志供参考: - - ``` - 01-01 05:27:27.419 136 408 D 02b01/Rilvendor: [SendCommandLock-(at_support.c:210)] SendCommandLock enter, cmd: ATD17620373527 - 01-01 05:27:27.419 136 408 D 02b01/Rilvendor: [SendCommandLock-(at_support.c:231)] SendCommandLock() command ATD17620373527 - 01-01 05:27:27.419 136 408 D 02b01/Rilvendor: [WriteATCommand-(channel.c:115)] WriteATCommand enter, cmd:ATD17620373527 - 01-01 05:27:27.421 136 187 D 02b01/Rilvendor: [ReadResponse-(channel.c:94)] g_bufferCur : - 01-01 05:27:27.421 136 187 D 02b01/Rilvendor: OK - 01-01 05:27:27.422 136 187 D 02b01/Rilvendor: [ProcessResponse-(at_support.c:144)] processLine line = OK - 01-01 05:27:27.422 136 187 D 02b01/Rilvendor: [ReadResponse-(channel.c:81)] ReadResponse enter - 01-01 05:27:27.422 136 187 D 02b01/Rilvendor: [ProcessLastResponse-(channel.c:37)] last data more than one line , FindEndOfLine g_bufferCur: - 01-01 05:27:27.422 136 187 E 02b01/Rilvendor: [ProcessLastResponse-(channel.c:39)] g_bufferCur endLine is null - 01-01 05:27:27.422 136 187 E 02b01/Rilvendor:^ORIG:1,0 - 01-01 05:27:27.422 136 408 E 02b01/Rilvendor: [SendCommandLock-(at_support.c:234)] processLine line = ^ORIG:1,0 - 01-01 05:27:27.422 136 408 E 02b01/Rilvendor: [SendCommandLock-(vendor_report.c:234)] enter to [^ORIG:1,0]:(null) - 01-01 05:27:27.422 136 408 E 02b01/Rilvendor: [SendCommandLock-(at_support.c:264)] err = 0, cmd:ADT17620373527 - ``` - - -## Modem事件上报开发指导 - -### 场景介绍 - -Modem事件上报是指在厂商库的Modem设备节点读取线程,循环读取到Modem主动上报的消息后,对Modem上报事件进行解析,然后上报给RIL Adapter。 - -### 接口说明 - -Modem事件上报接口。 - -**表 3** Modem事件上报接口功能介绍 - - - - - - - - - - -

接口名

-

描述

-

void OnNotifyOps(const char *s, const char *smsPdu)

-

接口功能:对Modem上报的事件进行分发处理。

-

参数s:AT指令前缀。

-

参数smsPdu:短信PDU信息。

-

返回值:无。

-
- -### 开发步骤 - -1. 在Modem设备节点读取线程g\_reader里调用OnNotifyOps\(\)解析具体的Modem上报事件,判断命令类型,并调用OnXxxReport\(\)把解析得到的各模块事件上报给hril业务层。 - - ``` - // 将Modem上报数据解析为对应模块的主动上报事件 - void OnNotifyOps(const char *s, const char *smsPdu) - { - int ret = 0; - struct ReportInfo reportInfo = {0}; - reportInfo.error = HRIL_ERR_SUCCESS; - reportInfo.type = HRIL_NOTIFICATION; - if (GetRadioState() == HRIL_RADIO_POWER_STATE_UNAVAILABLE) { - return; - } - TELEPHONY_LOGD("enter to [%{public}s]:%{public}s", s, smsPdu); - // 通过AT指令判断主动上报命令类型 - if (ReportStrWith(s, "+CRING:") || ReportStrWith(s, "RING") || ReportStrWith(s, "IRING") || - ReportStrWith(s, "NO CARRIER") || ReportStrWith(s, "+CCWA") || ReportStrWith(s, "^CCALLSTATE") || - ReportStrWith(s, "^CEND") || ReportStrWith(s, "^CCWA")) { - reportInfo.notifyId = HNOTI_CALL_STATE_UPDATED; - OnCallReport(reportInfo, NULL, 0); - } else if (ReportStrWith(s, "+CMT:")) { - reportInfo.notifyId = HNOTI_SMS_NEW_SMS; - OnSmsReport(reportInfo, (void *)smsPdu, strlen(smsPdu)); - } - // 将各模块事件上报给hril业务层 - ...... - } - ``` - - -1. hril业务层将上报事件分发给Telephony Service。 - - ``` - // 呼叫状态主动上报 - int32_t HRilCall::CallStateUpdated( - int32_t slotId, int32_t notifyType, const HRilErrno e, const void *response, size_t responseLen) - { - struct HdfSBuf *dataSbuf = HdfSBufTypedObtain(SBUF_IPC); - if (serviceCallbackNotify_ == nullptr) { - TELEPHONY_LOGE("RilAdapter serviceCallbackNotify_ is null"); - HdfSBufRecycle(dataSbuf); - return HDF_FAILURE; - } - // 分发处理 - int32_t ret = serviceCallbackNotify_->dispatcher->Dispatch( - serviceCallbackNotify_, HNOTI_CALL_STATE_UPDATED, dataSbuf, nullptr); - if (ret != HDF_SUCCESS) { - HdfSBufRecycle(dataSbuf); - return HDF_FAILURE; - } - HdfSBufRecycle(dataSbuf); - return HDF_SUCCESS; - } - ``` - - -### 调测验证 - -1. 用[hdc\_std工具](/pages/01090202#section05992022154916)工具连接调试设备,把编译生成的libril\_vendor.z.so库文件通过以下命令推到/system/lib/目录下。 - - ``` - hdc_std file send libril_vendor.z.so /system/lib/ - ``` - -2. 执行hdc\_std shell sync,hdc\_std shell reboot重启设备。 - - ``` - hdc_std shell sync - hdc_std shell reboot - ``` - -3. hdc\_std shell后执行./system/bin/ril\_adapter\_test,输入编号1,根据提示输入电话号码,测试拨打电话功能。 - - ``` - hdc_std shell - # ./system/bin/ril_adapter_test - ----> Test Enter --------->Call--------------------- - - 1----> RilUnitTest::OnRequestCallDialTest - 2----> RilUnitTest:: OnRequestCallHangupTest - 3----> RilUnitTest:: OnRequestCallAnswerTest - 4----> RilUnitTest::OnRequestCallGetCurrentCallsStatusTest - 5----> RilUnitTest::OnRequestRefusedCallTest - - 1 - ``` - -4. 另开一个终端窗口,执行hdc\_std shell hilog,通过日志查看函数OnNotifyOps\(\)是否正确执行完成。如下调测验证日志供参考: - - ``` - 01-01 00:08:01.334 546 551 D 02b01/TelRilTest: [DialResponse-(tel_ril_call.cpp:280)] DialResponse --> radioResponseInfo->serial:2, radioResponseInfo->error:0 - 01-01 00:08:01.334 546 557 D 02b01/TelRilTest: [ProcessEvent-(tel_ril_test.cpp:1262)] TelRilTest::DemoHandler::ProcessEvent --> eventId:101 - 01-01 00:08:01.334 143 512 D 02b01/Rilvendor: [ReadResponse-(channel.c:93)] g_bufferCur : - 01-01 00:08:01.334 143 512 D 02b01/Rilvendor: ^ORIG:1,0 - 01-01 00:08:01.334 143 512 D 02b01/Rilvendor: [ReadResponse-(channel.c:108)] AT< ^ORIG:1,0 - 01-01 00:08:01.334 143 512 D 02b01/Rilvendor: [ProcessResponse-(at_support.c:137)] processLine line = ^ORIG:1,0 - 01-01 00:08:01.334 143 512 D 02b01/Rilvendor: [OnNotifyOps-(vendor_report.c:126)] enter to [^ORIG:1,0]:(null) - 01-01 00:08:01.335 143 512 W 02b01/Rilvendor: [OnNotifyOps-(vendor_report.c:167)] enter to is unrecognized command: ^ORIG:1,0 - 01-01 00:08:01.335 143 512 D 02b01/Rilvendor: [ProcessLastResponse-(channel.c:37)] last data more than one line , FindEndOfLine g_bufferCur: - 01-01 00:08:01.335 143 512 E 02b01/Rilvendor: [ProcessLastResponse-(channel.c:39)] g_bufferCur endLine is null - 01-01 00:08:01.336 143 512 D 02b01/Rilvendor: [ReadResponse-(channel.c:93)] g_bufferCur : - 01-01 00:08:01.336 143 512 D 02b01/Rilvendor: ^CCALLSTATE: 1,0,1 - 01-01 00:08:01.336 143 512 D 02b01/Rilvendor: [ReadResponse-(channel.c:108)] AT< ^CCALLSTATE: 1,0,1 - 01-01 00:08:01.336 143 512 D 02b01/Rilvendor: [ProcessResponse-(at_support.c:137)] processLine line = ^CCALLSTATE: 1,0,1 - 01-01 00:08:01.336 143 512 D 02b01/Rilvendor: [OnNotifyOps-(vendor_report.c:126)] enter to [^CCALLSTATE: 1,0,1]:(null) - 01-01 00:08:01.336 546 551 D 02b01/CoreService: [OnRemoteRequest-(tel_ril_manager.cpp:80)] RilManager OnRemoteRequest code:1001 - 01-01 00:08:01.336 546 551 D 02b01/CoreService: [NotifyObserver-(observer_handler.cpp:76)] handler->SendEvent:8 - ``` - - -### 开发实例 - -- **去电开发实例** - - 去电的调用流程示例如下图所示: - - **图 1** 去电调用时序图 - ![](/images/device-dev/subsystems/figure/去电调用时序图.png "去电调用时序图") - - 当应用触发去电动作时,RIL Adapter会接收到拨打电话的请求,hril调用对应的拨打电话的接口ReqDial\(\)。在该接口里会把电话服务传过来的数据封装为对应的AT指令发送到Modem,Modem执行完拨号命令后通过OnCallReport\(\)接口把响应结果上报给RIL Adapter。 - - ``` - // call模块回调函数指针 - static const HRilCallReq g_callReqOps = { - .GetCallList = ReqGetCallList, // 获取呼叫列表接口 - .Dial = ReqDial, // 拨打电话接口 - .Hangup = ReqHangup, // 挂断电话接口 - .Reject = ReqReject, // 拒接来电接口 - .Answer = ReqAnswer, // 接听来电接口 - }; - - // 系统业务请求接口定义 - HRilOps g_hrilOps = { - .callOps = &g_callReqOps, // 定义通话业务请求接口 - .simOps = &g_simReqOps, // 定义SIM卡业务请求接口 - .smsOps = &g_smsReqOps, // 定义短彩信业务请求接口 - .networkOps = &g_networkReqOps, // 定义蜂窝数据业务请求接口 - .dataOps = &g_dataReqOps, // 定义搜网业务请求接口 - .modemOps = &g_modemReqOps, // 定义Modem业务请求接口 - }; - - // 拨号请求接口实现 - void ReqDial(ReqDataInfo *requestInfo, const void *data, size_t dataLen) - { - HRilDial *pDial = NULL; - char cmd[MAX_BUFF_SIZE] = {0}; - const char *clir = NULL; - int ret; - int err = HRIL_ERR_SUCCESS; - struct ReportInfo reportInfo = {}; - ResponseInfo *pResponse = NULL; - if (data == NULL) { - TELEPHONY_LOGE("data is null!!!"); - err = HRIL_ERR_INVALID_PARAMETER; - reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0); - OnCallReport(reportInfo, NULL, 0); - return; - } - pDial = (HRilDial *)data; - switch (pDial->clir) { - case CALL_CLIR_INVOCATION: - clir = "I"; - break; /* invocation */ - case CALL_CLIR_SUPPRESSION: - clir = "i"; - break; /* suppression */ - case CALL_CLIR_SUBSCRIPTION_DEFUALT: - default: - clir = ""; - break; /* subscription default */ - } - (void)sprintf_s(cmd, MAX_BUFF_SIZE, "ATD%s%s;", pDial->address, clir); - ret = SendCommandLock(cmd, NULL, 0, &pResponse); // 发送AT命令 - if (ret != 0) { - err = HRIL_ERR_CMD_SEND_FAILURE; - TELEPHONY_LOGE("ATD send failed"); - } else { - if (pResponse != NULL && pResponse->success == 0) { - TELEPHONY_LOGE("ReqDial return ERROR"); - err = HRIL_ERR_CMD_NO_CARRIER; - } - } - reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0); - OnCallReport(reportInfo, NULL, 0); // 调用通话相关业务回调函数 - FreeResponseInfo(pResponse); - } - ``` - - -- **来电开发实例** - - 来电的调用流程示例如下图所示: - - **图 2** 来电调用时序图 - - - ![](/images/device-dev/subsystems/figure/zh-cn_image_0000001214727595.png) - - Modem设备节点读取线程g\_reader会循环读取Modem上报的消息,当Modem接收到来电时会主动上报来电相关的信息; - - 当该线程通过调用OnNotifyOps\(\)解析到Modem上报的数据是以"+CRING"、"RING"等字符开头时,表示有来电事件,然后通过OnCallReport\(reportInfo, NULL, 0\)上报给RIL Adapter完成来电事件上报。 - - ``` - // 将Modem上报数据解析为对应模块的主动上报事件 - void OnNotifyOps(const char *s, const char *smsPdu) - { - int ret = 0; - struct ReportInfo reportInfo = {0}; - reportInfo.error = HRIL_ERR_SUCCESS; - reportInfo.type = HRIL_NOTIFICATION; - if (GetRadioState() == HRIL_RADIO_POWER_STATE_UNAVAILABLE) { - return; - } - TELEPHONY_LOGD("enter to [%{public}s]:%{public}s", s, smsPdu); - // 通过AT指令判断主动上报命令类型 - if (ReportStrWith(s, "+CRING:") || ReportStrWith(s, "RING") || ReportStrWith(s, "IRING") || - ReportStrWith(s, "NO CARRIER") || ReportStrWith(s, "+CCWA") || ReportStrWith(s, "^CCALLSTATE") || - ReportStrWith(s, "^CEND") || ReportStrWith(s, "^CCWA")) { - reportInfo.notifyId = HNOTI_CALL_STATE_UPDATED; - OnCallReport(reportInfo, NULL, 0); // 调用通话相关业务回调函数 - } else if (ReportStrWith(s, "+CMT:")) { - reportInfo.notifyId = HNOTI_SMS_NEW_SMS; - OnSmsReport(reportInfo, (void *)smsPdu, strlen(smsPdu)); - } - // add your codes - ...... - } - ``` - - -## Modem厂商库集成指导 - -### 编译设置 - -Modem厂商库可通过BUILD.gn编译为一个动态库,在RIL Adapter启动时用dlopen方式加载到系统中,然后执行厂商库的初始化操作(参见[Modem厂商库初始化开发指导](#section211mcpsimp)),BUILD.gn编写示例如下: - -``` -import("//build/ohos.gni") -RIL_ADAPTER = "//base/telephony" -ohos_shared_library("ril_vendor") { // Modem厂商库名称 - sources = [ // 编译源文件 - "at_call.c", - "at_data.c", - "xxx.c", - ] - include_dirs = [ // 包含的头文件目录 - "$RIL_ADAPTER/ril_adapter/vendor/include", - "$RIL_ADAPTER/ril_adapter/interfaces/innerkits", - "include", - ] - deps = [ // 内部依赖 - "//drivers/adapter/uhdf2/osal:libhdf_utils", - "//base/telephony/core_service/utils:libtelephony_common", - ] - external_deps = [ "hilog:libhilog" ] // 外部依赖 - - part_name = "ril_adapter" // 部件名称 - subsystem_name = "telephony" // 子系统名称 -} -``` - -### 调测验证 - -1. 编译代码。 -2. 查看/out/{device_name}/telephony/ril\_adapter目录是否存在libril\_vendor.z.so,存在证明集成成功。否则检查代码,重新编译验证。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/13.\345\256\211\345\205\250/01.\346\246\202\350\277\260.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/13.\345\256\211\345\205\250/01.\346\246\202\350\277\260.md" deleted file mode 100644 index 9ad93434bc06735da3122b7ffbf05d61c91fef5b..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/13.\345\256\211\345\205\250/01.\346\246\202\350\277\260.md" +++ /dev/null @@ -1,72 +0,0 @@ ---- -title: 概述 -permalink: /pages/01050d01 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 概述 - -- [基本概念](#section175012297491) -- [约束与限制](#section2029921310472) - -OpenHarmony安全子系统目前提供给开发者的安全能力主要包含应用可信、权限管理、设备可信。涉及以下几个模块: - -- 应用验签 - - 为了确保应用内容的完整性,系统通过应用签名和Profile对应用的来源进行管控,同时对于调试应用,还可通过验签接口验证应用和设备的UDID是否匹配,确保应用安装在了正确的设备上。 - -- 应用权限管理 - - 应用权限是管理应用访问系统资源和使用系统能力的一种通用方式,应用在开发阶段需要在profile.json中指明此应用在运行过程中可能会调用哪些权限,其中静态权限表示只需要在安装阶段注册就可以,而动态权限一般表示涉及到敏感信息,所以需要用户进行动态授权。 - -- 可信设备群组管理 - - 提供基于群组概念的同华为账号群组、点对点群组(如二维码、碰一碰等)的设备安全可信关系的创建和查询,分布式应用可基于该能力进行设备间的可信认证,然后向分布式软总线请求设备间安全会话。 - - -## 基本概念 - -在进行依赖验签组件的应用开发前,开发者应了解以下基本概念: - -- Samgr - - Samgr\(System Ability Manager\)系统能力管理,在OpenHarmony上作为一个管理系统能力的模块,详见系统服务框架子系统。 - - -- BMS - - BMS\(Bundle Manager Service\)包管理管理,在OpenHarmony上主要负责应用的安装、卸载和数据管理。 - - -- 授权文件 - - 本文中的授权文件,指HarmonyAppProvision,简称profile。HarmonyAppProvision采用json文件格式进行描述。 - - -- 调试应用 - - 指开发者从应用市场申请调试证书与调试授权文件,并以此签名的hap包。 - - -- 发布应用 - - 指开发者从应用市场申请发布证书与发布授权文件,以此签名的hap包,上传至应用市场,并由应用市场正式发布的hap包。 - - -- OpenHarmony签名应用 - - OpenHarmony开源了一个根CA的证书和密钥,以此根CA签发的签名证书和授权文件签名的应用。 - - -## 约束与限制 - -- 仅支持以下三类应用的验签:应用市场调试应用、应用市场发布应用、OpenHarmony签名应用。 -- 若对应用市场调试应用验签,则本机UDID需要在授权文件授权调试的UDID列表中。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/13.\345\256\211\345\205\250/02.\345\272\224\347\224\250\351\252\214\347\255\276\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/13.\345\256\211\345\205\250/02.\345\272\224\347\224\250\351\252\214\347\255\276\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index e8162e82047470a22ed79a5dc031c61d8a479139..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/13.\345\256\211\345\205\250/02.\345\272\224\347\224\250\351\252\214\347\255\276\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,109 +0,0 @@ ---- -title: 应用验签开发指导 -permalink: /pages/01050d02 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 应用验签开发指导 - -- [场景介绍](#section18502174174019) -- [验签流程](#section554632717226) -- [接口说明](#section1633115419401) -- [开发步骤](#section4207112818418) - - [生成OpenHarmony签名应用](#section167151429133312) - - -## 场景介绍 - -为了确保应用的完整性和来源可靠,OpenHarmony需要对应用进行签名和验签。 - -- 应用开发阶段:开发者完成开发并生成安装包后,需要开发者对安装包进行签名,以证明安装包发布到设备的过程中没有被篡改。OpenHarmony的应用完整性校验模块提供了签名工具、签名证书生成规范,以及签名所需的公钥证书等完整的机制,支撑开发者对应用安装包签名。为了方便开源社区开发者,版本中预置了公钥证书和对应的私钥,为开源社区提供离线签名和校验能力;在OpenHarmony商用版本中应替换此公钥证书和对应的私钥。 -- 应用安装阶段:OpenHarmony用户程序框架子系统负责应用的安装。在接收到应用安装包之后,应用程序框架子系统需要解析安装包的签名数据,然后使用应用完整性校验模块的API对签名进行验证,只有校验成功之后才允许安装此应用. 应用完整性校验模块在校验安装包签名数据时,会使用系统预置的公钥证书进行验签。 - -## 验签流程 - -未经签名的Hap包的压缩方式是ZIP格式,简单分为文件块,中心目录(Central directory)块,中心目录结尾(EOCD,End of central directory record)块。 - -经过签名的Hap包,在文件块,和中心目录块之间,插入了签名块。签名块由整包签名数据块(data sign block)、授权文件签名数据块(profile sign block)和签名头(sign head)组成,如下图所示。 - -**图 1** 经过签名的Hap包结构 - - -![](/images/device-dev/subsystems/figure/zh-cn_image_0000001181934155.png) - -整个验签流程,主要分为三部分:整包验签、授权文件验签,以及授权文件内容校验。 - -**整包验签** - -整包签名数据块是一个PKCS7格式的签名块(signed data),验签过程包括PKSC7签名验证、哈希比较、证书链验证以及证书链与设备预置根证书的匹配校验。 - -**授权文件验签** - -授权文件数据块是一个PKCS7格式的签名块(signed data),其中PKCS7签名块的内容信息\(contentinfo\)是授权文件的内容。验签过程包括:PKCS7签名验证、哈希比较、证书链验证以及签发授权文件证书的合法性校验。 - -**授权文件内容校验** - -验签模块将对授权文件内容进行合法性检查。如果授权文件是调试类型,则会比对本机UDID是否在授权文件授权调试的UDID列表中,如果本机UDID在授权文件授权调试的UDID列表中,则会进一步比较授权文件中的调试证书和整包签名使用的证书是否相同,如果相同,则验证通过。 - -## 接口说明 - -验签组件当前提供innerkits接口,仅供系统应用调用,相关接口及功能描述如下: - -**表 1** 轻量级系统验签组件API接口功能介绍 - - - - - - - - - - - - - - - - -

接口名

-

描述

-

int APPVERI_AppVerify(const char *filePath, VerifyResult *verifyRst)

-

主入口函数,输入文件路径,进行验签,并将从描述文件中获取的数据通过verifyRst返回给调用者

-

int APPVERI_SetDebugMode(bool mode)

-

设置测试模式,设置mode为true,则支持基于测试根密钥的证书链校验,设置mode为false,则关闭基于测试根密钥的证书链校验。

-

注:当前没有基于现有测试根密钥的证书,开发者可根据自身需要,替换测试根密钥并进行相关验证。

-

void APPVERI_FreeVerifyRst(VerifyResult *verifyRst)

-

释放verifyRst中申请的内存

-
- -**表 2** 标准系统验签组件API接口功能介绍 - - - - - - - - - - -

接口名

-

描述

-

nt HapVerify(const std::string& filePath, HapVerifyResult& hapVerifyResult)

-

校验应用完整性,识别应用来源。

-
- -## 开发步骤 - -### 生成OpenHarmony签名应用 - -参考文档:https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/quick-start/configuring-openharmony-app-signature.md - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/13.\345\256\211\345\205\250/03.\345\272\224\347\224\250\346\235\203\351\231\220\347\256\241\347\220\206\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/13.\345\256\211\345\205\250/03.\345\272\224\347\224\250\346\235\203\351\231\220\347\256\241\347\220\206\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index a15882ebb52ddb73f8383b0836829b60593b8436..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/13.\345\256\211\345\205\250/03.\345\272\224\347\224\250\346\235\203\351\231\220\347\256\241\347\220\206\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,241 +0,0 @@ ---- -title: 应用权限管理开发指导 -permalink: /pages/01050d03 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 应用权限管理开发指导 - -- [运作机制](#section193961322175011) -- [场景介绍](#section18502174174019) -- [接口说明](#section1633115419401) -- [开发步骤](#section022611498210) - -## 运作机制 - -由于OpenHarmony允许安装三方应用,所以需要对三方应用的敏感权限调用进行管控,具体实现是应用在开发阶段就需要在profile.json中指明此应用在运行过程中可能会调用哪些敏感权限,这些权限包括静态权限和动态权限,静态权限表示只需要在安装阶段注册就可以,而动态权限一般表示获取用户的敏感信息,所以需要在运行时让用户确认才可以调用,授权方式包括系统设置应用手动授权等。除了运行时对应用调用敏感权限进行管控外,还需要利用应用签名管控手段确保应用安装包已经被设备厂商进行了确认。 - -**表 1** OpenHarmony权限列表 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

OpenHarmony权限

-

授权方式

-

权限说明

-

ohos.permission.LISTEN_BUNDLE_CHANGE

-

system_grant(静态权限)

-

允许该应用获取应用变化消息。

-

ohos.permission.GET_BUNDLE_INFO

-

system_grant(静态权限)

-

允许该应用获取应用信息。

-

ohos.permission.INSTALL_BUNDLE

-

system_grant(静态权限)

-

允许该应用安装应用。

-

ohos.permission.CAMERA

-

user_grant(动态权限)

-

此应用可随时使用相机拍摄照片和录制视频。

-

ohos.permission.MODIFY_AUDIO_SETTINGS

-

system_grant(静态权限)

-

允许该应用修改全局音频设置,例如音量和用于输出的扬声器。

-

ohos.permission.READ_MEDIA

-

user_grant(动态权限)

-

允许该应用读取您的视频收藏。

-

ohos.permission.MICROPHONE

-

user_grant(动态权限)

-

此应用可随时使用麦克风进行录音。

-

ohos.permission.WRITE_MEDIA

-

user_grant(动态权限)

-

允许该应用写入您的音乐收藏。

-

ohos.permission.DISTRIBUTED_DATASYNC

-

user_grant(动态权限)

-

管控分布式数据传输能力。

-

ohos.permission.DISTRIBUTED_VIRTUALDEVICE

-

user_grant(动态权限)

-

允许应用使用分布式虚拟能力

-
- ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->静态权限:应用安装时由系统授予的权限,对应于权限敏感级别的system\_grant ->动态权限:应用在运行过程中需要用户授权的权限,对应于权限敏感级别的user\_grant - -## 场景介绍 - -应用权限是软件用来访问系统资源和使用系统能力的一种通行方式。在涉及用户隐私相关功能和数据的场景,例如:访问个人设备的硬件特性,如摄像头、麦克风,以及读写媒体文件等,OpenHarmony通过应用权限管理组件来保护这些数据以及能力。 - -在系统应用开发过程中,如果应用要使用敏感权限,开发者可以调用应用权限管理组件接口检查待访问权限是否被授权,如果未授权,操作不允许。 - -## 接口说明 - -应用权限管理提供的API接口,当前仅供系统应用和系统服务调用,具体API接口如下。 - -**表 2** 应用权限管理API接口功能介绍 - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

接口名

-

描述

-

int CheckPermission(int uid, const char *permissionName)

-

检查指定UID的应用进程是否具有访问系统服务API的权限

-

int CheckSelfPermission(const char *permissionName)

-

检查调用者是否具有访问系统服务API的权限

-

int QueryPermission(const char *identifier, PermissionSaved **permissions, int *permNum)

-

查询应用申请的所有权限,并检查权限是否被授予

-

int GrantPermission(const char *identifier, const char *permName)

-

将指定权限授予应用程序

-

int RevokePermission(const char *identifier, const char *permName)

-

收回应用程序的指定权限

-

int GrantRuntimePermission(int uid, const char *permissionName)

-

应用运行时动态授予指定权限

-

int RevokeRuntimePermission(int uid, const char *permissionName)

-

应用运行时动态撤销指定权限

-
- -## 开发步骤 - -本部分以包管理器的应用权限开发为例进行讲解。开发过程中,首先需要明确涉及的敏感权限,并在config.json中声明该权限,在安装应用程序时,包管理器会调用应用权限管理组件的接口检查该权限是否被授予,若授予,安装流程正常进行,否则安装失败。 - -1. 在开发过程中,包管理器明确需要安装应用的权限(ohos.permission.INSTALL\_BUNDLE),并在config.json中声明该权限; - - ``` - { - ... - "module": { - "package": "com.huawei.kitframework", - "deviceType": [ - "phone", "tv","tablet", "pc","car","smartWatch","sportsWatch","smartCamera", "smartVision" - ], - "reqPermissions": [{ - // 声明需要的权限:安装应用程序的权限名 - "name": "ohos.permission.INSTALL_BUNDLE", - "reason": "install bundle", - "usedScene": { - "ability": [ - "KitFramework" - ], - "when": "always" - } - }, - { - "name": "ohos.permission.LISTEN_BUNDLE_CHANGE", - "reason": "install bundle", - "usedScene": { - "ability": [ - "KitFramework" - ], - "when": "always" - } - }, - { - "name": "ohos.permission.GET_BUNDLE_INFO", - "reason": "install bundle", - "usedScene": { - "ability": [ - "KitFramework" - ], - "when": "always" - } - } - ], - ... - } - ``` - -2. 当包管理器开发应用安装功能接口时,会调用权限管理相关接口检查自身是否具有安装应用程序的权限,例如:以安装应用的权限名"ohos.permission.INSTALL\_BUNDLE"作为入参,调用CheckPermission接口检查包管理器是否具有安装应用的权限,如果有权限,安装流程继续执行,否则返回安装失败; - - ``` - constexpr static char PERMISSION_INSTALL_BUNDLE[] = "ohos.permission.INSTALL_BUNDLE"; - - bool Install(const char *hapPath, const InstallParam *installParam, InstallerCallback installerCallback) - { - if ((hapPath == nullptr) || (installerCallback == nullptr) || (installParam == nullptr)) { - HILOG_ERROR(HILOG_MODULE_APP, "BundleManager install failed due to nullptr parameters"); - return false; - } - // 检查ohos.permission.INSTALL_BUNDLE权限是否被授予 - if (CheckPermission(0, static_cast(PERMISSION_INSTALL_BUNDLE)) != GRANTED) { - HILOG_ERROR(HILOG_MODULE_APP, "BundleManager install failed due to permission denied"); - return false; // 返回安装失败 - } - // 安装流程 - ... - } - ``` - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/13.\345\256\211\345\205\250/04.IPC\351\200\232\344\277\241\351\211\264\346\235\203\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/13.\345\256\211\345\205\250/04.IPC\351\200\232\344\277\241\351\211\264\346\235\203\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index 6dcd7bad5e093d057f63cebce70948c8c1a45438..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/13.\345\256\211\345\205\250/04.IPC\351\200\232\344\277\241\351\211\264\346\235\203\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,152 +0,0 @@ ---- -title: IPC通信鉴权开发指导 -permalink: /pages/01050d04 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# IPC通信鉴权开发指导 - -- [场景介绍](#section18502174174019) -- [接口说明](#section1633115419401) -- [开发步骤](#section022611498210) -- [常见问题](#section15729104510271) - -## 场景介绍 - -系统服务通过IPC跨进程方式开放的接口,需要对接口调用者进行鉴权操作。在Samgr中注册的系统服务,可以通过进程间通信的方式暴露接口给其他进程访问,同时需要配置相应的访问策略,当其他进程访问这些接口时,将会触发IPC通信鉴权机制校验访问进程是否拥有权限访问该接口,若无权限,则访问会被拒绝。 - -当开发一个系统服务时,如果需要对外开放某些接口,开发者可以通过IPC通信鉴权组件配置这些接口的访问策略。当其他服务通过IPC方式访问这些接口时,会触发Samgr服务调用IPC通信鉴权组件的接口检查调用者服务是否有权限调用该接口。 - -## 接口说明 - -IPC通信鉴权提供的API,仅供Samgr调用,开发者在开发服务时需要配置对应的访问策略,Samgr会调用如下接口获取和检查调用者是否具有正确的访问权限,提供的API列表如下。 - -**表 1** IPC通信鉴权API接口功能介绍 - - - - - - - - - - - - - -

接口名

-

描述

-

int GetCommunicationStrategy(RegParams params, PolicyTrans **policies, unsigned int *policyNum)

-

服务注册过程中查询调用接口对应的访问策略,仅供Samgr调用

-

int IsCommunicationAllowed(AuthParams params)

-

检查访问主体进程是否有权限调用受访客体进程的接口,仅供Samgr调用

-
- -## 开发步骤 - -本部分以BMS服务通过IPC通信方式对外开放接口为例,讲解如何通过IPC通信鉴权组件配置对应接口的访问策略。这里BMS在Samgr中注册的service为bundlems,为开放的接口注册的Feature为BmsFeature。 - -1. OpenHarmony侧在源码路径下的头文件base/security/permission/services/permission\_lite/ipc\_auth/include/policy\_preset.h中配置相应的访问策略,产品侧独有的在vendor/hisilicon/产品名称/hals/security/permission\_lite/ipc\_auth/include/policy\_preset\_product.h中配置相应的访问策略,配置策略后将头文件中的宏POLICY\_PRODUCT 配置为1;访问策略主要有三种类型: - - (1)type为RANGE类型:允许某个特定范围UID的进程访问,需要指定uidMin和uidMax; - - (2)type为FIXED类型:允许指定的几个UID的进程访问,需要指定fixedUid,最多配置8个; - - (3)type为BUNDLENAME类型:只允许特定的应用访问,需要指定bundleName(包名); - - ``` - FeaturePolicy bmsFeature[] = { - { - "BmsFeature", - { - { - .type=FIXED, // 允许指定UID的进程访问的方式 - .fixedUid={2, 3, 8} - }, - { - .type=RANGE, // 允许特定范围内的UID的进程访问的方式 - .uidMin=100, - .uidMax=__INT_MAX__, - }, - } - }, - { - "BmsInnerFeature", - { - { - .type=FIXED, // 允许指定UID的进程访问的方式 - .fixedUid={2, 3, 8} - }, - { - .type=RANGE, - .uidMin=100, - .uidMax=999, - }, - } - }, - }; - ``` - -2. 将步骤1中定义的Feature的策略加配到全局策略中,需要配置feature数量; - - ``` - static PolicySetting g_presetPolicies[] = { - {"permissionms", pmsFeature, 1}, - {"abilityms", amsFeature, 2}, - {"bundlems", bmsFeature, 2}, // 步骤1定义的BMS的feature,数量为2 - {"dtbschedsrv", dmsFeature, 1}, - {"samgr", samgrFeature, 1}, - {"appspawn", appspawnFeature, 1}, - {"WMS", wmsFeature, 1}, - {"bundle_daemon", bdsFeature, 1}, - }; - ``` - -3. 将步骤1中定义的BmsFeature注册到Samgr; - - ``` - const char BMS_SERVICE[] = "bundlems"; - const char BMS_FEATURE[] = "BmsFeature"; - static void Init() - { - SamgrLite *sm = SAMGR_GetInstance(); - if (sm == nullptr) { - return; - } - // 注册服务到Samgr - sm->RegisterFeature(BMS_SERVICE, reinterpret_cast(BundleMsFeature::GetInstance())); - sm->RegisterFeatureApi(BMS_SERVICE, BMS_FEATURE, - GetBmsFeatureApi(reinterpret_cast(BundleMsFeature::GetInstance()))); - HILOG_DEBUG(HILOG_MODULE_APP, "BundleMS feature start success"); - } - APP_FEATURE_INIT(Init); - ``` - - -完成以上开发步骤后,开发者在Samgr注册服务时,Samgr会调用IPC通信鉴权组件的GetCommunicationStrategy接口获取服务的访问策略;当其他服务或应用通过IPC方式访问这些服务时,Samgr会调用IPC通信鉴权组件的IsCommunicationAllowed接口检查调用者服务的权限,如果满足访问策略,则可以访问开发者接口,否则拒绝访问。 - -## 常见问题 - -- 开发新服务后,在Samgr注册失败问题 - - **现象描述** - - 开发完新服务后,在启动时出现服务在Samgr注册失败问题。 - - **可能原因** - - 服务注册过程中,Samgr需要从IPC通信鉴权模块获取该服务的访问策略,但是未在该模块配置该服务的UID。 - - **解决办法** - - 在base/security/permission/services/permission\_lite/ipc\_auth/src/ipc\_auth\_impl.c中配置有效的服务的UID。 - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/14.\345\220\257\345\212\250\346\201\242\345\244\215/01.\345\220\257\345\212\250\346\201\242\345\244\215\345\255\220\347\263\273\347\273\237\346\246\202\350\277\260.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/14.\345\220\257\345\212\250\346\201\242\345\244\215/01.\345\220\257\345\212\250\346\201\242\345\244\215\345\255\220\347\263\273\347\273\237\346\246\202\350\277\260.md" deleted file mode 100644 index cfc017cb143038e269ea086487aeee6ced0419a4..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/14.\345\220\257\345\212\250\346\201\242\345\244\215/01.\345\220\257\345\212\250\346\201\242\345\244\215\345\255\220\347\263\273\347\273\237\346\246\202\350\277\260.md" +++ /dev/null @@ -1,102 +0,0 @@ ---- -title: 启动恢复子系统概述 -permalink: /pages/01050e01 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 启动恢复子系统概述 - -- [启动恢复子系统上下文](#section167378304212) -- [约束与限制](#section2029921310472) - -## 启动恢复子系统上下文 - -下图是启动子系统上下文结构图: - -![](/images/device-dev/subsystems/figure/启动子系统上下文.png) - -系统上电加载内核后,按照以下流程完成系统各个服务和应用的启动: - -1. 内核加载init进程,一般在bootloader启动内核时通过设置内核的cmdline来指定init的位置。 -2. init进程启动后,会挂载tmpfs,procfs,创建基本的dev设备节点,提供最基本的根文件系统。 -3. init也会启动ueventd监听内核热插拔设备事件,为这些设备创建dev设备节点;包括block设备各个分区设备都是通过此事件创建。 -4. init进程挂载block设备各个分区(system,vendor)后,开始扫描各个系统服务的init启动脚本,并拉起各个SA服务。 -5. samgr是各个SA的服务注册中心,每个SA启动时,都需要向samgr注册,每个SA会分配一个ID,应用可以通过该ID访问SA。 -6. foundation是一个特殊的SA服务进程,提供了用户程序管理框架及基础服务;由该进程负责应用的生命周期管理。 -7. 由于应用都需要加载JS的运行环境,涉及大量准备工作,因此appspawn作为应用的孵化器,在接收到foundation里的应用启动请求时,可以直接孵化出应用进程,减少应用启动时间。 - -启动子系统内部涉及以下组件: - -- init启动引导组件 - - init启动引导组件对应的进程为init进程,是内核完成初始化后启动的第一个用户态进程。init进程启动之后,读取init.cfg配置文件,根据解析结果,执行相应命令(见[第2章表2](/pages/01050e02#table122681439144112)描述)并依次启动各关键系统服务进程,在启动系统服务进程的同时设置其对应权限。 - -- ueventd启动引导组件 - - ueventd负责监听内核设备驱动插拔的netlink事件,根据事件类型动态管理相应设备的dev节点。 - -- appspawn应用孵化组件 - - 负责接收**用户程序框架**的命令孵化应用进程,设置新进程的权限,并调用应用程序框架的入口函数。 - -- bootstrap服务启动组件 - - 提供了各服务和功能的启动入口标识。在SAMGR启动时,会调用boostrap标识的入口函数,并启动系统服务。 - -- syspara系统属性组件 - - 系统属性组件,根据OpenHarmony产品兼容性规范提供获取设备信息的接口,如:产品名、品牌名、厂家名等,同时提供设置/读取系统属性的接口。 - - -## 约束与限制 - -启动恢复子系统源代码目录和适配平台: - -**表 1** 启动恢复子系统源代码目录和适配平台 - - - - - - - - - - - - - - - - - - - -

名称

-

适配平台

-

base/startup/appspawn_lite

-

小型系统设备(参考内存≥1MB),如Hi3516DV300 、Hi3518EV300

-

base/startup/bootstrap_lite

-

轻量系统设备(参考内存≥128KB),如Hi3861V100

-

base/startup/init_lite

-

小型系统设备(参考内存≥1MB),如Hi3516DV300、Hi3518EV300

-

base/startup/syspara_lite

-
  • 轻量系统设备(参考内存≥128KB),如Hi3861V100
  • 小型系统设备(参考内存≥1MB),如Hi3516DV300、Hi3518EV300
-
- -- init启动引导组件: - - 每个系统服务启动时都需要编写各自的启动脚本文件init.cfg,定义各自的服务名、可执行文件路径、权限和其他信息。 - - 每个系统服务各自安装其启动脚本到/system/etc/init目录下,init进程统一扫码执行。 - -- 新芯片平台移植时,平台相关的初始化配置需要增加平台相关的初始化配置文件/vendor/etc/init/init.\{hardware\}.cfg;该文件完成平台相关的初始化设置,如安装ko驱动,设置平台相关的/proc节点信息。 - - 配置文件init.cfg仅支持json格式。 - -- bootstrap服务启动组件:需要在链接脚本中配置zInit代码段。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/14.\345\220\257\345\212\250\346\201\242\345\244\215/02.init\345\220\257\345\212\250\345\274\225\345\257\274\347\273\204\344\273\266.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/14.\345\220\257\345\212\250\346\201\242\345\244\215/02.init\345\220\257\345\212\250\345\274\225\345\257\274\347\273\204\344\273\266.md" deleted file mode 100644 index dcdd918355d60cc1f6a4d27e3da33e01db7d5729..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/14.\345\220\257\345\212\250\346\201\242\345\244\215/02.init\345\220\257\345\212\250\345\274\225\345\257\274\347\273\204\344\273\266.md" +++ /dev/null @@ -1,275 +0,0 @@ ---- -title: init启动引导组件 -permalink: /pages/01050e02 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# init启动引导组件 - -- [init启动引导的配置文件](#section56901555917) -- [开发指导](#section15371931131117) -- [开发实例](#section173413113565) - -init启动引导组件负责在系统启动阶段启动关键服务进程。 若用户需要新增随开机自启动的系统服务,可将新增服务加入配置文件init.cfg中。 - -## init启动引导的配置文件 - -init启动引导组件配置文件包含了所有需要由init进程启动的系统关键服务的服务名、可执行文件路径、权限和其他信息,该文件位于代码仓库“vendor/huawei/camera/init\_configs/“目录,烧写单板后可在“/etc/“目录下找到,文件名称为init.cfg,采用json格式,文件大小目前限制在100KB以内。 - -init进程启动后读取/etc/init.cfg,然后解析其json格式内容,并根据解析结果依次加载系统服务。 - -## 开发指导 - -1. 配置jobs数组。 - - init启动引导组件将系统启动分为三个阶段: - - - “pre-init”阶段:启动系统服务之前需要先执行的操作,例如挂载文件系统、创建文件夹、修改权限等。 - - “init”阶段:系统服务启动阶段。 - - “post-init”阶段:系统服务启动完后还需要执行的操作。 - - 上述每个阶段用一个job表示,一个job对应一个命令集合,init通过依次执行每个job中的命令来完成系统初始化。job执行顺序:先执行“pre-init”,再执行“init”,最后执行“post-init”。 - - ``` - "jobs" : [{ - "name" : "pre-init", - "cmds" : [ - "mkdir /testdir", - "chmod 0700 /testdir", - "chown 99 99 /testdir", - "mkdir /testdir2", - "mount vfat /dev/mmcblk0p0 /testdir2 noexec nosuid" // mount命令,格式为:mount 文件系统类型 source target flags data - ] - }, { - "name" : "init", - "cmds" : [ - "start service1", - "start service2" - ] - }, { - "name" : "post-init", - "cmds" : [] - } - ], - ``` - - **表 1** 执行job介绍 - - - - - - - - - - - - - - - - -

job名

-

说明

-

pre-init

-

最先执行的job,如果开发者的进程在启动之前需要首先执行一些操作(例如创建文件夹),可以把操作放到pre-init中先执行。

-

init

-

中间执行的job,例如服务启动。

-

post-init

-

最后被执行的job,如果开发者的进程在启动完成之后需要有一些处理(如驱动初始化后再挂载设备),可以把这类操作放到该job执行。

-
- - 单个job最多支持30条命令(当前仅支持start/mkdir/chmod/chown/mount/loadcfg),命令名称和后面的参数(参数长度≤128字节)之间有且只能有一个空格。 - - **表 2** 命令集说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

命令

-

命令格式和示例

-

说明

-

mkdir

-

mkdir 目标文件夹

-

如:mkdir /storage/myDirectory

-

创建文件夹命令,mkdir和目标文件夹之间有且只能有一个空格。

-

chmod

-

chmod 权限 目标

-

如:chmod 0600 /storage/myFile.txt

-

chmod 0750 /storage/myDir

-

修改权限命令,chmod权限目标之间间隔有且仅有一个空格,权限必须为0xxx格式。

-

chown

-

chown uid gid 目标

-

如:chown 900 800 /storage/myDir

-

chown 100 100 /storage/myFile.txt

-

修改属组命令,chown uid gid目标之间间隔有且仅有一个空格。

-

mount

-

mount fileSystemType src dst flags data

-

如:mount vfat /dev/mmcblk0 /sdc rw,umask=000

-

mount jffs2 /dev/mtdblock3 /storage nosuid

-

挂载命令,各参数之间有且仅有一个空格。flags当前仅支持nodev、noexec、nosuid、rdonly,data为可选字段。

-

start

-

start serviceName

-

如:start foundation

-

start shell

-

启动服务命令,start后面跟着service名称,该service名称必须能够在services数组中找到。

-

loadcfg

-

loadcfg filePath

-

如:loadcfg /patch/fstab.cfg

-

加载其他cfg文件命令。后面跟着的目标文件大小不得超过50KB,且目前仅支持加载/patch/fstab.cfg,其他文件路径和文件名均不支持。/patch/fstab.cfg文件的每一行都是一条命令,命令类型和格式必须符合本表格描述,命令条数不得超过20条。

-
- -2. 配置services数组,service集合(数组形式),包含了init进程需要启动的所有系统服务(最多支持100个)。 - - ``` - "services" : [{ - "name" : "service1", - "path" : ["/bin/process1", "param1", "param2"], - "uid" : 1, - "gid" : 1, - "once" : 0, - "importance" : 1, - "caps" : [0, 1, 2, 5] - }, { - "name" : "service2", - "path" : "/bin/process2", - "uid" : 2, - "gid" : 2, - "once" : 1, - "importance" : 0, - "caps" : [ ] - } - ] - ``` - - **表 3** service字段说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

字段名

-

说明

-

name

-

当前服务的服务名,须确保非空且长度<=32字节。

-

path

-

当前服务的可执行文件全路径和参数,数组形式。须确保第一个数组元素为可执行文件路径、数组元素个数<=20、每个元素为字符串形式以及每个字符串长度<=64字节。

-

uid

-

当前服务进程的uid值。

-

gid

-

当前服务进程的gid值。

-

once

-

当前服务进程是否为一次性进程:

-

1:一次性进程,当该进程退出时,init不会重新启动该服务进程

-

0 : 常驻进程,当该进程退出时,init收到SIGCHLD信号并重新启动该服务进程;

-

注意,对于常驻进程,若在4分钟之内连续退出5次,第5次退出时init将不会再重新拉起该服务进程。

-

importance

-

当前服务进程是否为关键系统进程:

-

0:非关键系统进程,当该进程退出时,init不会将系统复位重启;

-

1:关键系统进程,当该进程退出时,init将系统复位重启。

-

caps

-

当前服务所需的capability值,根据安全子系统已支持的capability,评估所需的capability,遵循最小权限原则配置(当前最多可配置100个值)。

-
- - -## 开发实例 - -init启动引导程序,此处以要新增一个名为MySystemApp的系统服务为例进行说明,使用如下配置: - -``` -{ - "jobs" : [{ - "name" : "pre-init", - "cmds" : [ - "mkdir /storage/MyDir", // MySystemApp服务启动之前需要先创建文件夹,因此放在 “pre-init”中进行 - "chmod 0600 /storage/MyDir", // MySystemApp服务要求该文件加只有本用户和属组才可读写,因此需要修改权限 - "chown 10 10 /storage/MyDir" - ] -}, { - "name" : "init", - "cmds" : [ - "start MySystemApp" // 在“init”中启动该系统服务 - ] -}, { - "name" : "post-init", - "cmds" : [] // MySystemApp系统服务启动后无需进行其他操作,因此不用配置“post-init” - } -], - "services" : [{ - "name" : "MySystemApp", // 系统服务名称 - "path" : ["/bin/MySystemAppExe", "param1", "param2", "param3"], // MySystemApp系统服务的可执行文件路径为"/bin/MySystemAppExe",其启动需要传入三个参数,分别是"param1"、"param2"和"param3 - "uid" : 20, // MySystemApp系统服务的uid是20 - "gid" : 20, // MySystemApp系统服务的gid是20 - "once" : 0, // MySystemApp系统服务的非一次性进程,即如果MySystemApp系统服务因任何原因退出,init进程需要将其重新拉起 - "importance" : 0, // MySystemApp系统服务不是关键系统进程,即如果MySystemApp系统服务因任何原因退出,init进程无需重启单板 - "caps" : [] // MySystemApp系统服务不需要任何capability权限(即MySystemApp系统服务不涉及与capability相关的操作) - } - ] -} -``` - -完成配置后,编译出包烧写单板: - -1. 启动后使用task -a(liteos-a版本)或ps命令(linux版本)查看是否MySystemApp系统服务进程已启动。 -2. 使用kill命令将上述新增的MySystemApp进程杀死,观察该进程是否会被重新拉起(此处应该为重新拉起)。 -3. 使用kill命令将上述新增的MySystemApp进程杀死,观察是否会导致单板重启(此处应该为不重启)。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/14.\345\220\257\345\212\250\346\201\242\345\244\215/03.appspawn\345\272\224\347\224\250\345\255\265\345\214\226\347\273\204\344\273\266.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/14.\345\220\257\345\212\250\346\201\242\345\244\215/03.appspawn\345\272\224\347\224\250\345\255\265\345\214\226\347\273\204\344\273\266.md" deleted file mode 100644 index 3035162f575c010b43bf673ea6dcb49578b668ce..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/14.\345\220\257\345\212\250\346\201\242\345\244\215/03.appspawn\345\272\224\347\224\250\345\255\265\345\214\226\347\273\204\344\273\266.md" +++ /dev/null @@ -1,60 +0,0 @@ ---- -title: appspawn应用孵化组件 -permalink: /pages/01050e03 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# appspawn应用孵化组件 - -appspawn被init启动后,向IPC框架注册服务名称,之后等待接收进程间消息,根据消息解析结果启动应用服务并赋予其对应权限。 - -appspawn注册的服务名称为“appspawn”,可通过包含“base\\startup\\appspawn\_lite\\services\\include\\appspawn\_service.h“头文件,获取服务名称对应的宏APPSPAWN\_SERVICE\_NAME定义。在安全子系统限制规则下,目前仅Ability Manager Service有权限可以向appspawn发送的进程间消息。 - -appspawn接收的消息为json格式,如下所示: - -"\{\\"bundleName\\":\\"testvalid1\\",\\"identityID\\":\\"1234\\",\\"uID\\":1000,\\"gID\\":1000,\\"capability\\":\[0\]\}" - -**表 1** 字段说明 - - - - - - - - - - - - - - - - - - - - - - -

字段名

-

说明

-

bundleName

-

即将启动的应用服务进程名,长度≥7字节,≤127字节。

-

identityID

-

AMS为新进程生成的标识符,由appspawn透传给新进程,长度≥1字节,≤24字节。

-

uID

-

即将启动的应用服务进程的uID,必须为正值。

-

gID

-

即将启动的应用服务进程的gID,必须为正值。

-

capability

-

即将启动的应用服务进程所需的capability权限,数量≤10个。

-
- diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/14.\345\220\257\345\212\250\346\201\242\345\244\215/04.bootstrap\346\234\215\345\212\241\345\220\257\345\212\250\347\273\204\344\273\266.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/14.\345\220\257\345\212\250\346\201\242\345\244\215/04.bootstrap\346\234\215\345\212\241\345\220\257\345\212\250\347\273\204\344\273\266.md" deleted file mode 100644 index 4369a3b735987c45761d765b4a8878d835a37812..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/14.\345\220\257\345\212\250\346\201\242\345\244\215/04.bootstrap\346\234\215\345\212\241\345\220\257\345\212\250\347\273\204\344\273\266.md" +++ /dev/null @@ -1,92 +0,0 @@ ---- -title: bootstrap服务启动组件 -permalink: /pages/01050e04 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# bootstrap服务启动组件 - -- [接口说明](#section1633115419401) -- [开发实例](#section2055311316228) - -bootstrap服务启动组件实现了服务的自动初始化,即服务的初始化函数无需显式调用,而是将其使用宏定义的方式申明,就会在系统启动时自动被执行。实现原理是将服务启动的函数通过宏申明之后,放在预定义好的zInit代码段中,系统启动的时候调用OHOS\_SystemInit接口,遍历该代码段并调用其中的函数。因此,需要在链接脚本中添加zInit段,并且在main函数里调用OHOS\_SystemInit接口。 - -zInit段的添加可参考已有的Hi3861平台的链接脚本,文件路径为vendor/hisi/hi3861/hi3861/build/link/link.ld.S。 - -用于实现服务的自动初始化的宏定义接口请参见启动恢复子系统的[API接口文档](https://device.harmonyos.com/cn/docs/develop/apiref/init-0000001054598113)。 - -## 接口说明 - -bootstrap服务启动: - -**表 1** 主要的服务自动初始化宏 - - - - - - - - - - - - - - - - - - - -

接口名

-

描述

-

SYS_SERVICE_INIT(func)

-

标识核心系统服务的初始化启动入口。

-

SYS_FEATURE_INIT(func)

-

标识核心系统功能的初始化启动入口。

-

APP_SERVICE_INIT(func)

-

标识应用层服务的初始化启动入口。

-

APP_FEATURE_INIT(func)

-

标识应用层功能的初始化启动入口。

-
- -## 开发实例 - -服务自动初始化宏使用实例: - -``` -void SystemServiceInit(void) { - printf("Init System Service\n"); -} -SYS_SERVICE_INIT(SystemServiceInit); - -void SystemFeatureInit(void) { - printf("Init System Feature\n"); -} -SYS_FEATURE_INIT(SystemFeatureInit); - -void AppServiceInit(void) { - printf("Init App Service\n"); -} -APP_SERVICE_INIT(AppServiceInit); - -void AppFeatureInit(void) { - printf("Init App Feature\n"); -} -APP_FEATURE_INIT(AppFeatureInit); - -// 日志的打印顺序为: -// Init System Service -// Init System Feature -// Init App Service -// Init App Feature -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/14.\345\220\257\345\212\250\346\201\242\345\244\215/05.syspara\347\263\273\347\273\237\345\261\236\346\200\247\347\273\204\344\273\266.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/14.\345\220\257\345\212\250\346\201\242\345\244\215/05.syspara\347\263\273\347\273\237\345\261\236\346\200\247\347\273\204\344\273\266.md" deleted file mode 100644 index 75562c485bc61057783e8caf5b441cfccbb49b8a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/14.\345\220\257\345\212\250\346\201\242\345\244\215/05.syspara\347\263\273\347\273\237\345\261\236\346\200\247\347\273\204\344\273\266.md" +++ /dev/null @@ -1,572 +0,0 @@ ---- -title: syspara系统属性组件 -permalink: /pages/01050e05 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# syspara系统属性组件 - -- [系统参数简介](#section381564832813) -- [系统参数定义规则](#section431671411293) - - [系统参数值定义文件](#section885018321291) - - [系统参数DAC访问控制定义文件](#section1333155762915) - - [系统参数定义文件安装方法](#section43801513193014) - - [系统参数值定义文件的加载顺序](#section89971332173017) - -- [shell命令使用说明](#section2039119283111) -- [syspara系统接口说明](#section0137175692616) -- [开发实例](#section118404913233) - -## 系统参数简介 - -syspara系统为各系统服务提供简单易用的键值对访问接口,使得各个系统服务可以通过各自的系统参数来进行业务功能的配置。系统参数的访问和操作有以下几个基本原语 - -**图 1** 系统参数操作原语 -![](/images/device-dev/subsystems/figure/系统参数操作原语.png "系统参数操作原语") - -**表 1** 系统参数操作原语说明 - - - - - - - - - - - - - - - - - - - -

功能

-

说明

-

get

-

获取系统参数的值

-

set

-

设置系统参数的值

-

wait

-

同步等待系统参数的值变更

-

watch

-

异步观察系统参数的值变更

-
- -系统参数名称采用点分格式由多段组成,每一段由字母、数字、下划线组成,总长度不超过96字节;系统参数名称分为两类: - -**表 2** 系统参数名称 - - - - - - - - - - - - - - - - - - - -

类别

-

名称

-

示例

-

说明

-

参数名称

-

Parameter Name

-

const.product.name

-

完整的系统参数名称,末尾不是"."。

-

参数目录

-

Parameter Directory

-

const.product.

-

以"."结尾,标识相同前缀的所有系统参数集合。

-
- -系统参数一共分为三大类: - -**表 3** 系统参数分类 - - - - - - - - - - - - - - - - - - - - -

类别

-

前缀

-

说明

-

常量

-

const.

-

常量参数,一旦赋值后续不会再变更;值最大长度为4096字节(包括结束符)。

-

可写

-

其它

-

可写参数,重启后丢失,值最大长度96字节(包括结束符)。

-

可持久化

-

persist.

-

可写并可持久化保存参数,重启后不会丢失,值最大长度96字节(包括结束符)。

-
- -每个系统参数名称总体格式如下:\[**const**|**persist**\].**$sub\_system**.**$desc**。 - -$sub\_system为子系统或模块的名称。 - -$desc为子系统或模块下参数的描述字符,可以为点分格式进行分级描述。 - -## 系统参数定义规则 - -每个子系统定义各自模块的系统参数,包括系统参数名称、默认值以及系统参数的权限访问信息。 - -### 系统参数值定义文件 - -系统参数值定义文件后缀名为**".para"**,其格式示例如下: - -``` -# This is comment -const.product.name=OHOS-PRODUCT -const.os.version.api=26 -const.telephony.enable=false|true - -const.test.withblank=My Value -``` - -注意:系统参数值不支持注释及换行。 - -``` -# 不支持 -const.test.withcomment=MyValue # This should be ommitted -# 不支持 -const.test.multiline="This is a multiline parameter. -Line2 value. -Last line." -``` - -系统参数必须通过完整的系统参数命令来赋值,赋值方式分为三大类: - -**表 4** 系统参数赋值方式 - - - - - - - - - - - - - - - - - - - - -

类别

-

示例

-

说明

-

字符串

-

const.product.name=OHOS-PRODUCT

-

不支持多行字符串,不支持注释。

-

数字

-

const.os.version.api=26

-

数字不需要引号。

-

布尔

-

const.telephony.enable=false

-

布尔型的可以为0,1,false,true。

-
- -### 系统参数DAC访问控制定义文件 - -当前系统参数的访问权限控制通过自主访问控制(**Discretionary Access Control**)方式管理,访问权限定义文件后缀名为**".para.dac"**,示例如下: - -``` -const.product.="root:root:660" -``` - -如上所示,可以通过**参数路径**为相同前缀的所有系统参数定义一类访问权限信息;DAC信息通过":"分三段来描述,分别为参数的user,group以及UGO规则信息。 - -UGO规则信息每一位的定义如下: - -**图 2** UGO规则信息 -![](/images/device-dev/subsystems/figure/UGO规则信息.png "UGO规则信息") - -### 系统参数定义文件安装方法 - -.para和.para.dac文件都安装到/etc/param/目录下,GN脚本示例如下: - -``` -ohos_prebuilt_etc("ohos.para") { - source = "//base/startup/init_lite/services/etc/ohos.para" - part_name = "init" - module_install_dir = "etc/param" -} - -ohos_prebuilt_etc("ohos.para.dac") { - source = "//base/startup/init_lite/services/etc/ohos.para.dac" - part_name = "init" - module_install_dir = "etc/param" -} -``` - -### 系统参数值定义文件的加载顺序 - -系统参数值的加载顺序如下: - -**表 5** 系统参数加载顺序 - - - - - - - - - - - - - - - - - - - - - - - - -

类别

-

路径

-

说明

-

内核参数

-

/proc/cmdline

-

内核参数中ohospara.xxx=valXXX类型的参数都转换成ohos.boot.xxx=valXXX系统参数

-

OS固定值

-

/system/etc/param/ohos_const/*.para

-

OS固定系统参数值参数优先加载。

-

vendor参数值

-

/vendor/etc/param/*.para

-

厂商参数值定义文件次优先级加载,可以覆盖system参数值定义。

-

system参数值

-

/system/etc/param/*.para

-

最后加载system参数值定义文件,文件中的系统参数值如果已经存在,则忽略掉。

-
- -## shell命令使用说明 - -通过shell命令中可直接操作系统参数: - -**表 6** 系统参数shell命令说明 - - - - - - - - - - - - - - - - - - - -

功能

-

说明

-

param get [key]

-

获取指定key名称的系统参数值;如果不指定任何name,则返回所有系统参数值。

-

param set key value

-

设置指定key名称的参数值为value

-

param wait key value

-

同步等待指定key名称的系统参数值与value匹配。value可支持模糊匹配,如"*"表示任何值,"val*"表示只匹配前三个val字符。

-

param dump

-

显示系统参数的统计信息。

-
- -## syspara系统接口说明 - -**表 7** 系统属性接口说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

接口名

-

描述

-

int GetParameter(const char* key, const char* def, char* value, unsigned int len)

-

获取系统参数。

-

int SetParameter(const char* key, const char* value)

-

设置/更新系统参数。

-

const char* GetDeviceType(void)

-

返回当前设备类型。

-

const char* GetManufacture(void)

-

返回当前设备生产厂家信息。

-

const char* GetBrand(void)

-

返回当前设备品牌信息。

-

const char* GetMarketName(void)

-

返回当前设备传播名。

-

const char* GetProductSeries(void)

-

返回当前设备产品系列名。

-

const char* GetProductModel(void)

-

返回当前设备认证型号。

-

const char* GetSoftwareModel(void)

-

返回当前设备内部软件子型号。

-

const char* GetHardwareModel(void)

-

返回当前设备硬件版本号。

-

const char* GetHardwareProfile(void)

-

返回当前设备硬件profile。

-

const char* GetSerial(void)

-

返回当前设备序列号(SN号)。

-

const char* GetOSFullName(void)

-

返回操作系统名。

-

const char* GetDisplayVersion(void)

-

返回当前设备用户可见的软件版本号。

-

const char* GetBootloaderVersion(void)

-

返回当前设备Bootloader版本号。

-

const char* GetSecurityPatchTag(void)

-

返回安全补丁标签。

-

const char* GetAbiList(void)

-

返回当前设备支持的指令集(Abi)列表。

-

int GetSdkApiVersion(void)

-

返回与当前系统软件匹配的SDK API 版本号。

-

int GetFirstApiVersion(void)

-

返回系统软件首版本SDK API 版本号。

-

const char* GetIncrementalVersion(void)

-

返回差异版本号。

-

const char* GetVersionId(void)

-

返回版本id。

-

const char* GetBuildType(void)

-

返回构建类型。

-

const char* GetBuildUser(void)

-

返回构建账户用户名。

-

const char* GetBuildHost(void)

-

返回构建主机名。

-

const char* GetBuildTime(void)

-

返回构建时间。

-

const char* GetBuildRootHash(void)

-

返回当前版本hash。

-

const char* GetOsReleaseType(void)

-

返回系统发布类型

-

int GetDevUdid(char *udid, int size)

-

获取设备udid

-
- -## 开发实例 - -系统属性使用实例 - -``` -// set && get -char key1[] = "rw.sys.version"; -char value1[] = "10.1.0"; -int ret = SetParameter(key1, value1); -char valueGet1[128] = {0}; -ret = GetParameter(key1, "version=10.1.0", valueGet1, 128); - -// get sysparm -char* value1 = GetDeviceType(); -printf("Product type =%s\n", value1); -free(value1); -char* value2 = GetManufacture(); -printf("Manufacture =%s\n", value2); -free(value2); -char* value3 = GetBrand(); -printf("GetBrand =%s\n", value3); -free(value3); -char* value4 = GetMarketName(); -printf("MarketName =%s\n", value4); -free(value4); -char* value5 = GetProductSeries(); -printf("ProductSeries =%s\n", value5); -free(value5); -char* value6 = GetProductModel(); -printf("ProductModel =%s\n", value6); -free(value6); -char* value7 = GetSoftwareModel(); -printf("SoftwareModel =%s\n", value7); -free(value7); -char* value8 = GetHardwareModel(); -printf("HardwareModel =%s\n", value8); -free(value8); -char* value9 = GetHardwareProfile(); -printf("Software profile =%s\n", value9); -free(value9); -char* value10 = GetSerial(); -printf("Serial =%s\n", value10); -free(value10); -char* value11 = GetOSFullName(); -printf("OS name =%s\n", value11); -free(value11); -char* value12 = GetDisplayVersion(); -printf("Display version =%s\n", value12); -free(value12); -char* value13 = GetBootloaderVersion(); -printf("bootloader version =%s\n", value13); -free(value13); -char* value14 = GetSecurityPatchTag(); -printf("secure patch level =%s\n", value14); -free(value14); -char* value15 = GetAbiList(); -printf("abi list =%s\n", value15); -free(value15); -int value16 = GetFirstApiVersion(); -printf("first api level =%d\n", value16); -free(value16); -char* value17 = GetIncrementalVersion(); -printf("Incremental version = %s\n", value17); -free(value17); -char* value18 = GetVersionId(); -printf("formal id =%s\n", value18); -free(value18); -char* value19 = GetBuildType(); -printf("build type =%s\n", value19); -free(value19); -char* value20 = GetBuildUser(); -printf("build user =%s\n", value20); -free(value20); -char* value21 = GetBuildHost(); -printf("Build host = %s\n", value21); -free(value21); -char* value22 = GetBuildTime(); -printf("build time =%s\n", value22); -free(value22); -char* value23 = GetBuildRootHash(); -printf("build root later..., %s\n", value23); -free(value23); -char* value24 = GetOsReleaseType(); -printf("OS release type =%s\n", value24); -free(value24); -char* value25 = GetOsReleaseType(); -printf("OS release type =%s\n", value25); -free(value25); -char value26[65] = {0}; -GetDevUdid(value26, 65); -printf("device udid =%s\n", value26); -free(value26); -``` - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/14.\345\220\257\345\212\250\346\201\242\345\244\215/06.\345\270\270\350\247\201\351\227\256\351\242\230.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/14.\345\220\257\345\212\250\346\201\242\345\244\215/06.\345\270\270\350\247\201\351\227\256\351\242\230.md" deleted file mode 100644 index c17d4946d751fcbfe9c1074dd70fcaa7cae4ca48..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/14.\345\220\257\345\212\250\346\201\242\345\244\215/06.\345\270\270\350\247\201\351\227\256\351\242\230.md" +++ /dev/null @@ -1,70 +0,0 @@ ---- -title: 常见问题 -permalink: /pages/01050e06 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 常见问题 - -- [系统启动过程中打印“parse failed!”错误后停止启动](#section2041345718513) -- [系统启动过程未结束就自动重启,如此反复持续](#section57381816168) -- [参数正确的情况下调用SetParameter/GetParameter返回失败](#section129991227141512) - -## 系统启动过程中打印“parse failed!”错误后停止启动 - -**现象描述** - -系统启动过程中,打印“\[Init\] InitReadCfg, parse failed! please check file /etc/init.cfg format.”错误,启动过程停止,如下图所示: - -**图 1** 运行报错图 -![](/images/device-dev/subsystems/figure/运行报错图.png "运行报错图") - -**可能原因** - -修改init.cfg文件时,漏掉或多加了逗号或括号等,导致init.cfg文件的json格式被破坏。 - -**解决办法** - -仔细检查init.cfg文件,确保其格式符合json格式要求。 - -## 系统启动过程未结束就自动重启,如此反复持续 - -**现象描述** - -镜像烧写完成后系统启动,启动过程未完成即自动重新启动,如此反复持续。 - -**可能原因** - -被init启动的服务都有一个叫做“importance”的属性(详见[第2章表3](/pages/01050e02#table14737791471)描述)。 - -- 当该属性为0时,表示若当前服务进程退出,init不需要重启单板。 -- 当该属性为1时,表示若当前服务进程退出,init需要重启单板。 - -因此出现上述现象的可能原因:有“importance”属性为1的服务在每次启动的过程中都会退出(可能是进程崩溃或出错自动退出),导致init进程自动重启单板。 - -**解决办法** - -1. 需要通过日志确认崩溃或报错退出的服务,并解决其崩溃/报错的问题,然后重新烧写镜像即可。 -2. 也可以将崩溃/报错退出的服务的“importance”属性改为0,然后重新烧写镜像,这样即使其退出,init也不会重启单板。 - -## 参数正确的情况下调用SetParameter/GetParameter返回失败 - -**现象描述** - -在各参数正确的情况下调用SetParameter/GetParameter返回失败。 - -**可能原因** - -程序对SetParameter/GetParameter这两个接口做了权限校验,在各参数正确的情况下调用SetParameter/GetParameter返回操作失败,很有可能是调用者的uid大于1000,没有调用权限。 - -**解决办法** - -无需处理 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/14.\345\220\257\345\212\250\346\201\242\345\244\215/07.\345\217\202\350\200\203.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/14.\345\220\257\345\212\250\346\201\242\345\244\215/07.\345\217\202\350\200\203.md" deleted file mode 100644 index 9be96305bf8dad49a534cfadc791681ba097aa21..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/14.\345\220\257\345\212\250\346\201\242\345\244\215/07.\345\217\202\350\200\203.md" +++ /dev/null @@ -1,53 +0,0 @@ ---- -title: 参考 -permalink: /pages/01050e07 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 参考 - -- [包结构说明](#section3523121414020) - -## 包结构说明 - -包结构见下表所示。 - -**表 1** 包结构说明 - - - - - - - - - - - - - - - - - - - -

名称

-

对应功能描述

-

/bin/init

-

init启动引导程序对应的可执行文件

-

/bin/appspawn

-

appspawn应用孵化程序对应的可执行文件

-

/etc/init.cfg

-

init启动引导程序的配置文件

-

/usr/lib/libsysparam.so

-

syspara系统属性组件的输出文件

-
- diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/15.DFX/04.HiSysEvent\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/15.DFX/04.HiSysEvent\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index fdc92e0b04ec90c364b9d752b5aecb9bc28c8bf7..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/15.DFX/04.HiSysEvent\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,24 +0,0 @@ ---- -title: HiSysEvent开发指导 -permalink: /pages/01050f04 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# HiSysEvent开发指导 - -- **[HiSysEvent打点配置指导](/pages/extra/ac6bb3/)** - -- **[HiSysEvent打点指导](/pages/0105100601)** - -- **[HiSysEvent订阅指导](/pages/0105100602)** - -- **[HiSysEvent查询指导](/pages/0105100603)** - -- **[HiSysEvent工具使用指导](/pages/0105100604)** \ No newline at end of file diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/16.DFX/01.DFX\346\246\202\350\277\260.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/16.DFX/01.DFX\346\246\202\350\277\260.md" deleted file mode 100644 index a96a007fd23268e5ea97008d8a5a37c7f6e1ec44..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/16.DFX/01.DFX\346\246\202\350\277\260.md" +++ /dev/null @@ -1,49 +0,0 @@ ---- -title: DFX概述 -permalink: /pages/01051001 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# DFX概述 - -- [基本概念](#section5635178134811) - -在OpenHarmony中,DFX\([Design for X](https://en.wikipedia.org/wiki/Design_for_X)\)是为了提升质量属性的软件设计,目前包含的内容主要有:DFR(Design for Reliability,可靠性)和DFT(Design for Testability,可测试性)特性。 - -提供以下功能: - -- HiLog流水日志,轻量系统类设备(参考内存≥128KB)、小型系统类设备(参考内存≥1MB)、标准系统类设备(参考内存≥128MB)适用。 - -- HiTrace分布式跟踪,标准系统类设备(参考内存≥128MB)适用。 -- HiCollie卡死故障检测,标准系统类设备(参考内存≥128MB)适用。 -- HiSysEvent系统事件埋点,标准系统类设备(参考内存≥128MB)适用。 - -## 基本概念 - -**流水日志:** - -流水日志是系统运行过程中产生的一些日志信息,用于开发人员了解系统或应用运行过程、状态。 - -**分布式跟踪:** - -在一个分布式系统中,一次业务的发起往往会涉及多个软件模块,通过进程内、进程间、设备间的通信接口进行控制和数据传递,为了便于开发人员对这类复杂流程的理解和问题跟踪定界,DFX提供了一个分布式跟踪框架。 - -**线程卡死故障:** - -线程在运行过程中,如果进入死循环,或者陷入内核态(Uninterruptable Sleep、Traced、Zombie等状态,或者其他同步等待状态),将无法响应正常的业务请求,且无法自己实现故障的感知和恢复。检测和定位这类故障需要通过一个简单的watchdog机制,在易于发生卡死的流程中插入检测点,在发生卡死故障的时候,进行故障恢复和日志采集。 - -**埋点:** - -是在程序关键处理流程中加入一些代码,采集程序运行过程中信息的一种技术,用于支持分析产品的使用情况。 - -**系统事件:** - -是OpenHarmony系统某种状态产生的一种标识,通过定义各种事件用于分析系统的状态变化情况。 - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/16.DFX/02.HiLog\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/16.DFX/02.HiLog\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index 3a4e9eacb8a5f27a9f5a5cc94b98e25b4855fc66..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/16.DFX/02.HiLog\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,121 +0,0 @@ ---- -title: HiLog开发指导 -permalink: /pages/01051002 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# HiLog开发指导 - -- [概述](#概述) -- [接口说明](#接口说明) -- [开发实例](#开发实例) - - [C使用示例](#c使用示例) - - [C++使用示例](#c-使用示例) - -## 概述 - -HiLog是OpenHarmony日志系统,提供给系统框架、服务、以及应用打印日志,记录用户操作、系统运行状态等。 - -本章节内容对标准系统类设备(参考内存≥128MB)适用。 - - -## 接口说明 - -**表1** C++、C的函数接口 - -| **C++** | | **C** | -| -------- | -------- | -------- | -| **类** | **方法** | **方法/宏** | -| HiLog | int Debug(const HiLogLabel &label, const char \*fmt, ...) | HILOG_DEBUG(type, ...) | -| | int Info(const HiLogLabel &label, const char \*fmt, ...) | HILOG_INFO(type, ...) | -| | int Warn(const HiLogLabel &label, const char \*fmt, ...) | HILOG_WARN(type, ...) | -| | int Error(const HiLogLabel &label, const char \*fmt, ...) | HILOG_ERROR(type, ...) | -| | int Fatal(const HiLogLabel &label, const char \*fmt, ...) | HILOG_FATAL(type, ...) | -| | NA | int HiLogPrint(LogType type, LogLevel level, unsigned int domain, const char \*tag, const char \*fmt, ...) | -| | boolean IsLoggable(unsigned int domain, const char \*tag, LogLevel level) | bool HiLogIsLoggable(unsigned int domain, const char \*tag, LogLevel level) | -| HiLogLabel | struct HiLogLabel | LOG_DOMAIN
LOG_TAG | - -**表3** C++接口说明函数参数和功能 - -| **类** | **方法** | **描述** | -| -------- | -------- | -------- | -| HiLog | int Debug(const HiLogLabel &label, const char \*fmt, ...) | 功能:输出 debug 级别日志。
输入参数:
- label:用于标识输出日志的类型、业务领域、TAG。
- format:常量格式字符串,包含参数类型、隐私标识。未加隐私标识的缺省为隐私参数。
- fmt:格式化变参描述字符串。
输出参数:无
返回值:大于等于0,成功;小于0,失败。 | -| | int Info(const HiLogLabel &label, const char \*fmt, ...) | 功能:输出 info 级别日志。
参数说明同 Debug 接口。 | -| | int Warn(const HiLogLabel &label, const char \*fmt, ...) | 功能:输出 warn 级别日志。
参数说明同 Debug 接口。 | -| | int Error(const HiLogLabel &label, const char \*fmt, ...) | 功能:输出 error 级别日志。
参数说明同 Debug 接口。 | -| | int Fatal(const HiLogLabel &label, const char \*fmt, ...) | 功能:输出 fatal 级别日志。
参数说明同 Debug 接口。 | -| | boolean IsLoggable(unsigned int domain, const char \*tag, LogLevel level) | 功能:检查指定业务领域、TAG、级别的日志是否可以打印。
输入参数:
- domain:指定日志业务领域。
- tag: 指定日志TAG。
- level: 指定日志level。
输出参数:无
返回值:如果指定domain、tag、level日志可以打印则返回true;否则返回false。 | -| HiLogLabel | struct HiLogLabel | 功能:初始化日志标签参数。
成员参数:
- domain:指定日志业务领域。
- tag: 指定日志TAG。
- level: 指定日志level。 | - - -## 开发实例 - - -### C使用示例 - -1. 在.c源文件中,包含hilog头文件: - ``` - #include "hilog/log.h" - ``` - - 定义domain、tag: - - ``` - #undef LOG_DOMAIN - #undef LOG_TAG - #define LOG_DOMAIN 0 // 标识业务领域,范围0x0~0xFFFFF - #define LOG_TAG "MY_TAG" - ``` - - 打印日志: - - ``` - HILOG_INFO(LOG_CORE, "Failed to visit %{private}s, reason:%{public}d.", url, errno); - ``` - -2. 编译设置,在BUILD.gn里增加子系统SDK依赖: - ``` - external_deps = [ "hiviewdfx_hilog_native:libhilog" ] - ``` - - -### C++使用示例 - -1. 在.h类定义头文件中,包含hilog头文件: - ``` - #include "hilog/log.h" - ``` - - 如果类头文件中需要日志打印,在头文件中类定义起始处 定义 LABEL: - - ``` - class MyClass { - static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "MY_TAG"}; - ...... - } - ``` - - 如果类头文件中没有日志打印,在类实现文件中 定义 LABEL: - - ``` - using namespace OHOS::HiviewDFX; - static constexpr HiLogLabel LABEL = {LOG_CORE, 0, "MY_TAG"}; - ``` - - 打印日志: - - ``` - HiLog::Info(LABEL, "Failed to visit %{private}s, reason:%{public}d.", url, errno); - ``` - -2. 编译设置,在BUILD.gn里增加子系统SDK依赖: - ``` - external_deps = [ "hiviewdfx:libhilog" ] - ``` diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/16.DFX/03.HiLog_Lite\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/16.DFX/03.HiLog_Lite\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index 2bc434824d82605c305b7afed60620ff8aa1ec72..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/16.DFX/03.HiLog_Lite\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,121 +0,0 @@ ---- -title: HiLog_Lite开发指导 -permalink: /pages/01051003 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# HiLog\_Lite开发指导 - -- [概述](#section775017517390) -- [接口说明](#section114412157402) -- [开发实例](#section1482812550419) - -## 概述 - -HiLog\_Lite是针对轻量系统类设备(参考内存≥128KB)、小型系统类设备(参考内存≥1MB)的hilog框架,实现了日志的打印、输出和流控功能。 - -## 接口说明 - -C语言接口: - -``` -HILOG_DEBUG(mod, fmt, ...) -HILOG_INFO/HILOG_WARN/HILOG_ERROR/HILOG_FATAL -``` - -**表 1** 接口参数说明 - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

是否必填

-

参数类型

-

参数说明

-

mod

-

-

uint8

-

模块/服务的ID。

-

统一规划分配,最大支持64个,其中第三方APP统一使用HILOG_MODULE_APP作为模块ID。

-

fmt

-

-

char *

-

格式化输出字符串。

-
  1. 最大支持6个可变参数,不支持%s。
  2. 格式化后的单条日志最大长度128字节,超过将无法打印。
-

可变参

-

-

int32

-

仅支持数字类型,最大支持6个变参。

-
- -## 开发实例 - -以下引用samgr\_lite模块使用hilog\_lite框架作为实例。 - -1. 添加模块ID,在“base/hiviewdfx/hilog\_lite/interfaces/native/kits/hilog\_lite/hiview\_log.h“的类型定义结构体中添加HILOG\_MODULE\_SAMGR定义。 - - ``` - typedef enum { - ... - HILOG_MODULE_SAMGR, - ... - } HiLogModuleType; - ``` - -2. 注册模块,在“base/hiviewdfx/hilog\_lite/frameworks/mini/hiview\_log.c“的HiLogInit函数中添加注册代码。 - - ``` - HiLogRegisterModule(HILOG_MODULE_SAMGR, "SAMGR"); - ``` - -3. 在GN文件中添加头文件依赖,文件路径为:“foundation/distributedschedule/samgr\_lite/samgr/BUILD.gn“ - - ``` - include_dirs = [ - "//base/hiviewdfx/hilog_lite/interfaces/native/kits/hilog_lite", - ] - ``` - -4. 源文件“foundation/distributedschedule/samgr\_lite/samgr/source/message.c“中引用头文件并调用接口。 - - ``` - #include - uint32 *SAMGR_SendSharedRequest(const Identity *identity, const Request *request, uint32 *token, Handler handler) - { - ... - if (err != EC_SUCCESS) { - HILOG_ERROR(HILOG_MODULE_SAMGR, "SharedSend [%p] failed(%d)!", identity->queueId, err); - (void)FreeReference(&exchange); - } - ... - } - ``` - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/16.DFX/04.HiTrace\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/16.DFX/04.HiTrace\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index 05f31fca4c959976d324239dc334cf380ad1f2d7..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/16.DFX/04.HiTrace\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,551 +0,0 @@ ---- -title: HiTrace开发指导 -permalink: /pages/01051004 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# HiTrace开发指导 - -- [概述](#section3986195420436) -- [应用场景](#section134561822574) - - [业务使用示例](#section63861653124417) - -- [接口说明](#section1517945334617) - - [接口形式对比](#section932504474) - - [接口功能参数](#section2514638125) - -- [通信调用处理](#section11257133933) -- [开发实例](#section14310412491) - - [C++接口实例](#section114916381509) - - [C接口实例](#section108292107514) - - -## 概述 - -HiTrace主要是对于跨设备/跨进程/跨线程的业务流程,通过相同的traceid在整个业务流程中传递,将流程处理过程中的调用关系、各种输出信息关联和展现出来,帮助使用者分析、定位问题和系统调优。 - -## 应用场景 - -HiTrace在产品中应用场景如下,包括: - -- 端侧业务流程信息(日志、事件等)关联、上报 -- 云侧对上报信息的关联展示和分析,辅助问题定位 -- IDE对业务流程详细信息、耗时分布进行调试,辅助系统调优 - - **图 1** HiTrace应用场景 - ![](/images/device-dev/subsystems/figure/HiTrace应用场景.png "HiTrace应用场景") - - -### 业务使用示例 - -**图 2** 业务调用流程图(跨设备、跨进程同步调用) -![](/images/device-dev/subsystems/figure/业务调用流程图(跨设备-跨进程同步调用).png "业务调用流程图(跨设备-跨进程同步调用)") - -1. 调试时展示业务流程中的调用关系,进行关键路径分析、功能依赖分析,确定各调用点耗时、调用频率,提前发现性能瓶颈点。 - - **图 3** 业务调用流程序列图 - ![](/images/device-dev/subsystems/figure/业务调用流程序列图.png "业务调用流程序列图") - - **图 4** 业务调用流程性能耗时分布 - ![](/images/device-dev/subsystems/figure/业务调用流程性能耗时分布.png "业务调用流程性能耗时分布") - -2. 在日志和事件等信息中自动附加traceid信息,便于开发人员综合分析和快速实现问题定界定位。 - -## 接口说明 - -HiTrace提供C++、C接口。上层业务主要使用HiTrace跟踪启动、结束接口。 - -HiTrace实现在C层,主要原理是在一次业务调用流程中,利用通信传递traceid,在业务处理前将traceid设置到当前线程的TLS\(Thread Local Storage\)中,业务处理结束清除当前线程的TLS;这样的话,在业务处理中可以从当前线程的上下文TLS取到traceid,自动附加到日志、事件信息中。 - -### 接口形式对比 - -**表 1** C++、C的函数接口 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  

C++

-

C

-

-

函数

-

函数

-

HiTrace

-

HiTraceId Begin(const std::string& name, int flags)

-

HiTraceIdStruct HiTraceBegin(const char* name, int flags)

-
  

void End(const HiTraceId& id)

-

void HiTraceEnd(const HiTraceIdStruct* pId)

-
  

HiTraceId GetId();

-

HiTraceIdStruct HiTraceGetId()

-
  

void SetId(const HiTraceId& id)

-

void HiTraceSetId(const HiTraceIdStruct* pId)

-
  

void ClearId()

-

void HiTraceClearId()

-
  

HiTraceId CreateSpan()

-

HiTraceIdStruct HiTraceCreateSpan()

-
  

void Tracepoint(HiTraceTracepointType type, const HiTraceId& id, const char* fmt, ...)

-

void HiTraceTracepoint(HiTraceTracepointType type, const HiTraceIdStruct* pId, const char* fmt, ...)

-
  

void Tracepoint(HiTraceCommunicationMode mode, HiTraceTracepointType type, const HiTraceId& id, const char* fmt, ...)

-

void HiTraceTracepointEx(HiTraceCommunicationMode mode, HiTraceTracepointType type, const HiTraceIdStruct* pId, const char* fmt, ...)

-

HiTraceId

-

HiTraceId();

-

void HiTraceInitId(HiTraceIdStruct* pId)

-
  

HiTraceId(const uint8_t* pIdArray, int len)

-

HiTraceIdStruct HiTraceBytesToId(const uint8_t* pIdArray, int len)

-
  

bool IsValid()

-

int HiTraceIsValid(const HiTraceIdStruct* pId)

-
  

bool IsFlagEnabled(HiTraceFlag flag)

-

int HiTraceIsFlagEnabled(const HiTraceIdStruct* pId, HiTraceFlag flag)

-
  

void EnableFlag(HiTraceFlag flag)

-

void HiTraceEnableFlag(HiTraceIdStruct* pId, HiTraceFlag flag)

-
  

int GetFlags()

-

int HiTraceGetFlags(const HiTraceIdStruct* pId)

-
  

void SetFlags(int flags)

-

void HiTraceSetFlags(HiTraceIdStruct* pId, int flags)

-
  

uint64_t GetChainId()

-

uint64_t HiTraceGetChainId(const HiTraceIdStruct* pId)

-
  

void SetChainId(uint64_t chainId)

-

void HiTraceSetChainId(HiTraceIdStruct* pId, uint64_t chainId)

-
  

uint64_t GetSpanId()

-

uint64_t HiTraceGetSpanId(const HiTraceIdStruct* pId)

-
  

void SetSpanId(uint64_t spanId)

-

void HiTraceSetSpanId(HiTraceIdStruct* pId, uint64_t spanId)

-
  

uint64_t GetParentSpanId()

-

uint64_t HiTraceGetParentSpanId(const HiTraceIdStruct* pId)

-
  

void SetParentSpanId(uint64_t parentSpanId)

-

void HiTraceSetParentSpanId(HiTraceIdStruct* pId, uint64_t parentSpanId)

-
  

int ToBytes(uint8_t* pIdArray, int len)

-

int HiTraceIdToBytes(const HiTraceIdStruct* pId, uint8_t* pIdArray, int len)

-
- -### 接口功能参数 - -**表 2** C++接口说明函数参数和功能 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

-

方法

-

描述

-

HiTrace

-

HiTraceId Begin(const std::string& name, int flags)

-

功能:启动HiTrace跟踪、生成HiTraceId对象并设置到当前线程TLS中。

-

输入参数:

-
  • name:业务流程名称。
  • flags:跟踪指示位,可以组合使用,具体含义为:
    • HITRACE_FLAG_INCLUDE_ASYNC:同时跟踪同步调用和异步调用,缺省只跟踪同步调用。
    • HITRACE_FLAG_DONOT_CREATE_SPAN:不创建子分支,缺省创建子分支。
    • HITRACE_FLAG_TP_INFO:输出tracepoint信息,缺省不输出。
    • HITRACE_FLAG_NO_BE_INFO:不输出起始、结束信息,缺省输出。
    • HITRACE_FLAG_DONOT_ENABLE_LOG:不与日志关联输出,缺省关联。
    • HITRACE_FLAG_FAULT_TRIGGER:故障触发的跟踪,缺省为正常启动的。
    • HITRACE_FLAG_D2D_TP_INFO:输出设备间tracepoint信息,缺省不输出。
    • HITRCE_FLAG_DEFAULT: 缺省标志。
    -
  • 输出参数:无
  • 返回值:启动跟踪超过返回有效HiTraceId对象,否则返回无效对象。
-

注意:嵌套启动跟踪时,内层启动调用返回无效对象。

-
  

void End(const HiTraceId& id)

-

功能:根据Begin返回的HiTraceId停止HiTrace跟踪;清除当前线程TLS中HiTraceId内容。

-

输入参数:

-
  • id:HiTraceId对象。
-

输出参数:无。

-

返回值:无。

-
  

HiTraceId GetId();

-

功能:从当前线程TLS中获取HiTraceId对象。

-

输入参数:无。

-

输出参数:无。

-

返回值:当前线程上下文的HiTraceId对象。

-
  

void SetId(const HiTraceId& id)

-

功能:设置HiTraceId对象内容到当前线程TLS中。

-

输入参数:

-
  • id:HiTraceId对象。
-

输出参数:无。

-

返回值:无。

-
  

void ClearId()

-

功能:清除当前线程TLS中的HiTraceId对象。

-

输入参数:无。

-

输出参数:无。

-

返回值:无。

-
  

HiTraceId CreateSpan()

-

接口功能:获取当前HiTraceId对象中的分支ID。

-

输入参数:无。

-

输出参数:无。

-

返回值:当前分支ID。

-
  

void Tracepoint(HiTraceTracepointType type, const HiTraceId& id, const char* fmt, ...)

-

功能:根据埋点信息类型输出HiTrace埋点信息,包括时间戳、子分支HiTraceId对象信息。

-

输入参数:

-
  • type:埋点信息类型,具体为
    • HITRACE_TP_CS:Client Send,同步/异步通信客户端发送信息。
    • HITRACE_TP_SR:Server Receive, 同步/异步通信服务端接收信息。
    • HITRACE_TP_SS:Server Send,同步通信服务端发送响应信息。
    • HITRACE_TP_CR:Client Receive,同步通信客户端接收响应信息。
    • HITRACE_TP_GENERAL:普通输出信息。
    -
  • id:当前子分支id。
  • fmt:格式化变参描述字符串。
  • args:变参。
-

输出参数:无。

-

返回值:无。

-
  

void Tracepoint(HiTraceCommunicationMode mode, HiTraceTracepointType type, const HiTraceId& id, const char* fmt, ...)

-

功能:根据通信模式、埋点信息类型输出HiTrace埋点信息,包括时间戳、子分支HiTraceId对象信息。

-

输入参数:

-
  • mode:通信模式,具体为
    • HITRACE_CM_DEFAULT:未指定通信模式。
    • HITRACE_CM_THREAD:线程间通信。
    • HITRACE_CM_PROCESS:进程间通信。
    • HITRACE_CM_DEVICE:设备间通信。
    -
  • type:埋点信息类型,具体为
    • HITRACE_TP_CS:Client Send,同步/异步通信客户端发送信息。
    • HITRACE_TP_SR:Server Receive, 同步/异步通信服务端接收信息。
    • HITRACE_TP_SS:Server Send,同步通信服务端发送响应信息。
    • HITRACE_TP_CR:Client Receive,同步通信客户端接收响应信息。
    • HITRACE_TP_GENERAL:普通输出信息。
    -
  • id:当前子分支id。
  • fmt:格式化变参描述字符串。
  • args:变参。
-

输出参数:无。

-

返回值:无。

-

HiTraceId

-

HiTraceId();

-

功能:缺省构造函数,生成无效HiTraceId对象。

-

输入参数:无。

-

输出参数:无。

-

返回值:无。

-
  

HiTraceId(const uint8_t* pIdArray, int len)

-

功能:构造函数,根据字节数组创建跟踪HiTraceId对象。

-
输入参数:
  • pIdArray:字节数组指针。
  • len:字节数组长度。
-
-

输出参数:无。

-

返回值:无。

-
  

bool IsValid()

-

功能:HiTraceId对象是否有效。

-

输入参数:无。

-

输出参数:无。

-

返回值:true 有效;false 无效。

-
  

bool IsFlagEnabled(HiTraceFlag flag)

-

功能:HiTraceId对象的某标志是否置位。

-

输入参数:

-
  • flag:跟踪指示位,具体含义见Begin函数中的定义。
-

输出参数:无。

-

返回值:true 该标志置位;false 该标志未置位。

-
  

void EnableFlag(HiTraceFlag flag)短短

-

功能:设置某跟踪标志位到HiTraceId对象中。

-

输入参数:

-
  • flag:跟踪指示位,具体含义见Begin函数中的定义。
-

输出参数:无。

-

返回值:无。

-
  

int GetFlags()

-

功能:获取HiTraceId对象中设置的标志位。

-

输入参数:无。

-

输出参数:无。

-

返回值:跟踪指示位组合,具体含义见Begin函数中的定义。

-
  

void SetFlags(int flags)

-

功能:设置跟踪标志位到HiTraceId对象中。

-

输入参数:

-
  • flags:跟踪指示位组合,具体含义见Begin函数中的定义。
-

输出参数:无。

-

返回值:无。

-
  

uint64_t GetChainId()

-

功能:获取跟踪链ID。

-

输入参数:无。

-

输出参数:无。

-

返回值:跟踪链ID。

-
  

void SetChainId(uint64_t chainId)

-

功能:设置跟踪链ID到HiTraceId对象中。

-

输入参数:

-
  • chainId:跟踪链ID。
-

输出参数:无。

-

返回值:无。

-
  

uint64_t GetSpanId()

-

接口功能:获取当前HiTraceId对象中的分支ID。

-

输入参数:无。

-

输出参数:无。

-

返回值:当前分支ID。

-
  

void SetSpanId(uint64_t spanId)

-

功能:设置分支ID到HiTraceId对象中。

-

输入参数:

-
  • spanId:分支ID。
-

输出参数:无。

-

返回值:无。

-
  

uint64_t GetParentSpanId()

-

功能:获取当前HiTraceId对象中的父分支ID。

-

输入参数:无。

-

输出参数:无。

-

返回值:父分支ID。

-
  

void SetParentSpanId(uint64_t parentSpanId)

-

功能:设置父分支ID到HiTraceId对象中。

-

输入参数:

-
  • parentSpanId:父分支ID。
-

输出参数:无。

-

返回值:无。

-
  

int ToBytes(uint8_t* pIdArray, int len)

-

功能:将HiTraceId对象转换为字节数组,便于缓存或者通信传递。

-

输入参数:

-
  • pIdArray:字节数组指针,数组长度至少为HITRACE_ID_LEN。
  • len: 字节数组长度
-

输出参数:

-
  • pIdArray:字节数组指针,对象有效时存储转换后的对象数据。
-

返回值:0 转换失败; >0 有效对象转换数组长度。

-
- -## 通信调用处理 - -业务使用时跨设备/跨进程/跨线程的调用是通过通信机制实现的,HiTrace需要通信机制传递traceid。 - -OpenHarmony系统内置部分通信机制(如ZIDL)已经支持传递traceid。 - -下面描述了同步通信调用传递traceid的处理过程,异步通信调用处理类似。 - -对于不支持的扩展通信机制可以参照该方式实现。 - -**图 5** 同步通信处理 -![](/images/device-dev/subsystems/figure/同步通信处理.png "同步通信处理") - -处理流程: - -1. client侧业务模块调用begin\(\)接口启动调用链跟踪。 -2. client侧业务模块发起同步调用transact,到client侧通信组件。 -3. client侧通信组件: - 1. 从当前线程TLS中获取traceid。 - 2. 生成子调用分支(child traceid)。 - 3. 将child traceid写入同步调用通信数据(transaction data)中。 - 4. 进行CS埋点(Client Send)。 - 5. 将通信数据发送到server侧通信组件。 - -4. server侧通信组件收到通信数据: - 1. 从数据消息包中取出traceid。 - 2. 将traceid设置到当前线程TLS中。 - 3. 进行SR埋点(Server Receive)。 - 4. 然后进行同步调用回调(onTransact)到server侧业务模块。 - -5. server侧业务模块进行服务处理,处理完毕发送处理结果(transact reply)到通信组件。 -6. server侧通信组件: - 1. 进行SS埋点(Server Send)。 - 2. 将响应数据发送到client侧通信组件。 - 3. 清除当前线程TLS中的traceid信息。 - -7. client侧通信组件收到响应数据: - 1. 进行CR埋点(Client Receive)。 - 2. 发送同步调用响应(transact reply)到client侧业务模块。 - -8. client侧业务模块进行同步调用响应处理。 -9. client侧业务模块在流程结束时调用end\(\)接口停止调用链跟踪。 - -## 开发实例 - -### C++接口实例 - -1. 源代码开发 - - 在类定义头文件或者类实现源文件中,包含hitrace头文件: - - ``` - #include "hitrace/trace.h" - ``` - - 在业务类实现源文件中使用(启动/结束跟踪): - - ``` - using namespace OHOS::HiviewDFX; - HiTraceId traceId = HiTrace::Begin("MyServiceFlow", HITRACE_FLAG_DEFAULT); - ...... - HiTrace::End(traceId); - ``` - -2. 编译设置,在BUILD.gn里增加子系统SDK依赖: - - ``` - external_deps = [ "hiviewdfx:libhitrace" ] - ``` - - -### C接口实例 - -1. 源代码开发 - - 在源文件中,包含hitrace头文件: - - ``` - #include "hitrace/trace.h" - ``` - - 在业务类实现源文件中使用(启动/结束跟踪): - - ``` - HiTraceIdStruct traceId = HiTraceBegin("MyServiceFlow", HITRACE_FLAG_DEFAULT); - ...... - HiTraceEnd(traceId); - ``` - -2. 编译设置,在BUILD.gn里增加子系统SDK依赖: - - ``` - external_deps = [ "hiviewdfx:libhitrace" ] - ``` - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/16.DFX/05.HiCollie\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/16.DFX/05.HiCollie\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index b9d79e25370d3b078abc5e93cc88f81419bc18f2..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/16.DFX/05.HiCollie\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,206 +0,0 @@ ---- -title: HiCollie开发指导 -permalink: /pages/01051005 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# HiCollie开发指导 - -- [概述](#section3432134085116) -- [接口说明](#section139261151145116) -- [效果](#section1589120102458) -- [开发实例](#section13905646534) - - [C++接口开发实例](#section9797199145316) - - [线程卡死监控](#section1734221332) - - [超时监控](#section2186947140) - - -## 概述 - -HiCollie提供了软件看门狗功能。针对系统服务死锁、应用主线程阻塞,用户业务流程超时等故障,HiCollie提供了一套统一的用于故障检测和故障日志生成的框架,提供软件超时故障日志,辅助定位软件超时问题。 - -## 接口说明 - -**表 1** C++接口功能描述表 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

所属类

-

接口定义

-

描述

-

XCollieChecker类接口

-

virtual void CheckBlock()

-

接口功能:卡死检测回调函数。

-

输入参数:无。

-

输出参数:无。

-

返回值:无。

-

XCollieChecker类接口

-

virtual void CheckThreadBlock()

-

接口功能:线程卡死检测回调函数。

-

输入参数:无。

-

输出参数:无。

-

返回值:无。

-

XCollie类接口

-

void RegisterXCollieChecker(const sptr<XCollieChecker> &checker, unsigned int type)

-

接口功能:线程卡死检测回调函数注册。

-

输入参数:

-
  • checker:XCollieChecker实例指针。
  • type:卡死检测类型,取值设置为XCOLLIE_THREAD。
-

输出参数:无。

-

返回值:无。

-

XCollie类接口

-

int SetTimer(const std::string &name, unsigned int timeout, std::function<void (void *)> func, void *arg, unsigned int flag)

-

接口功能:添加定时器。

-

输入参数:

-
  • name:定时器名称。
  • timeout:超时时间,单位为秒。
  • func:超时回调函数。
  • arg:超时回调函数参数指针。
  • flag:定时器操作类型。

    XCOLLIE_FLAG_DEFAULT // 其他三个选项功能之和

    -

    XCOLLIE_FLAG_NOOP // 仅调用超时回调函数

    -

    XCOLLIE_FLAG_LOG // 生成超时故障日志

    -

    XCOLLIE_FLAG_RECOVERY // 进程退出

    -
-

输出参数:无。

-

返回值:成功返回定时器标识,失败返回-1。

-

XCollie类接口

-

bool UpdateTimer(int id, unsigned int timeout)

-

接口功能:更新定时器。

-

输入参数:

-
  • id:定时器标识。
  • timeout:超时时间,单位为秒。
-

输出参数:无。

-

返回值:成功返回true,失败返回false。

-

XCollie类接口

-

void CancelTimer(int id)

-

接口功能:取消定时器。

-

输入参数:定时器标识。

-

输出参数:无。

-

返回值:无。

-
- -## 效果 - -日志打印: - -``` -timeout: TimeoutTimer start at 1611040305 to check 1s ago - -----------StacktraceCatcher CurrentTime:2021-01-19 15:11:45 Unexecuted(-1)(LogType:Stacktrace Pid:27689 Process:XCollieTimeoutModuleTest)---------- - - ------ pid 27689 at 2021-01-19 15:11:45 ----- -Cmd line: ./XCollieTimeoutModuleTest -ABI: 'arm64' - -"XCollieTimeoutM" sysTid=27689 - #01 pc 00000000000174cc /data/test/XCollieTimeoutModuleTest -``` - -## 开发实例 - -### C++接口开发实例 - -### 线程卡死监控 - -线程卡死监控功能需要开发者实现两个卡死检测回调函数,XCollieChecker类的CheckBlock和CheckThreadBlock接口函数。实现了该回调函数之后,开发者还需要通过XCollie类的RegisterXCollieChecker函数,将该回调函数的类实例成功注册。卡死监控线程会定时执行全部已成功注册的回调函数,检查线程逻辑完成标志位,判定已经成功注册的线程逻辑是否被卡死。 - -1. 源代码开发 - - 包含头文件: - - ``` - #include "xcollie.h" - ``` - - 在业务代码中使用: - - ``` - void MyXCollieChecker::CheckLock() - { - /* time consuming job */ - } - - void MyXCollieChecker::CheckThreadBlock() - { - /* time consuming job */ - } - - sptr checker = new MyXCollieChecker("MyXCollieChecker"); - XCollie::GetInstance().RegisterXCollieChecker(checker, - (XCOLLIE_LOCK | XCOLLIE_THREAD)); - ...... - ``` - -2. 编译设置,在BUILD.gn里增加子系统SDK依赖: - - ``` - external_deps = [ "hiviewdfx:libxcollie" ] - ``` - - -### 超时监控 - -单个进程通过SetTimer接口函数添加定时器最多可以设置128个,超过上限则添加定时器操作会失败。 - -1. 源代码开发 - - 包含头文件: - - ``` - #include "xcollie.h" - ``` - - 在业务代码中使用(添加/更新/取消): - - ``` - std::function callback = [](void *args) - { - /* dump helpful information */ - }; - - int id = XCollie::GetInstance().SetTimer("MyXCollieTimer", 10, callback ,nullptr, XCOLLIE_FLAG_LOG); - /* time consuming job */ - XCollie::GetInstance().UpdateTimer(id, 5); - /* time consuming job */ - XCollie::GetInstance().CancelTimer(id); - ...... - ``` - -2. 编译设置,在BUILD.gn里增加子系统SDK依赖: - - ``` - external_deps = [ "hiviewdfx:libxcollie" ] - ``` - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/16.DFX/06.HiSysEvent\345\274\200\345\217\221\346\214\207\345\257\274/01.HiSysEvent\346\211\223\347\202\271\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/16.DFX/06.HiSysEvent\345\274\200\345\217\221\346\214\207\345\257\274/01.HiSysEvent\346\211\223\347\202\271\346\214\207\345\257\274.md" deleted file mode 100644 index 60c6adf07728357d3563e9e1d1e0d785a4330e71..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/16.DFX/06.HiSysEvent\345\274\200\345\217\221\346\214\207\345\257\274/01.HiSysEvent\346\211\223\347\202\271\346\214\207\345\257\274.md" +++ /dev/null @@ -1,309 +0,0 @@ ---- -title: HiSysEvent打点指导 -permalink: /pages/0105100601 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# HiSysEvent打点指导 - -- [概述](#section77571101789) - - [功能简介](#section123133332175224) - - [约束与限制](#section123181432175224) -- [开发指导](#section314416685113) - - [接口说明](#section13480315886) - - [开发实例](#section112771171317) - -## 概述 - -### 功能简介 - -HiSysEvent提供OpenHarmony打点接口,通过在关键路径打点记录系统在运行过程中的重要信息,辅助开发者定位问题,此外还支持开发者将数据上传到云进行大数据质量度量。 - -### 约束与限制 - -**HiSysEvent事件打点条件约束:** - -- 在进行HiSysEvent事件打点之前,需要先完成HiSysEvent打点配置,具体配置方法请参考[《HiSysEvent打点配置指导》](/pages/extra/ac6bb3/)。 - -## 开发指导 - -### 接口说明 - -C++打点接口如下: - -HiSysEvent类,具体的API详见接口文档 。 - -**表 1** HiSysEvent接口介绍 - - - - - - - - - - -

接口名

-

描述

-

template<typename... Types> static int Write(const std::string &domain, const std::string &eventName, EventType type, Types... keyValues)

-

接口功能:记录系统事件。

-

输入参数:

-
  • domain:事件的相关领域,需要使用预置领域请参考Domain,可自定义领域。自定义领域长度在16个字符以内,有效的字符是0-9、A-Z,以字母开头。
  • eventName:事件名,长度在32个字符以内,有效的字符是0-9、A-Z、_,以字母开头,不能以_结尾。
  • type:事件类型,参考EventType。
  • keyValues:事件参数键值对,支持基本的数据类型、std::string,以及std::vector<基本类型>、std:vector<std::string>。参数名长度在48个字符以内,有效的字符是0-9、A-Z、_,以字母开头,不能以_结尾。参数名的个数在32个以内。
-

返回值:成功返回0,错误返回小于0的值。

-
- -**表 2** HiSysEvent::Domain接口介绍 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

成员

-

描述

-

static const std::string AAFWK

-

元能力子系统

-

static const std::string APPEXECFWK

-

用户程序框架子系统

-

static const std::string ACCOUNT

-

账号子系统

-

static const std::string ACE

-

ACE子系统

-

static const std::string AI

-

AI业务子系统

-

static const std::string BARRIER_FREE

-

无障碍软件服务子系统

-

static const std::string BIOMETRICS

-

生物特征识别服务子系统

-

static const std::string CCRUNTIME

-

C/C++运行环境子系统

-

static const std::string COMMUNICATION

-

公共通信子系统

-

static const std::string DEVELOPTOOLS

-

研发工具链子系统

-

static const std::string DISTRIBUTED_DATAMGR

-

分布式数据管理子系统

-

static const std::string DISTRIBUTED_SCHEDULE

-

分布式任务调度子系统

-

static const std::string GLOBAL

-

全球化子系统

-

static const std::string GRAPHIC

-

图形子系统

-

static const std::string HIVIEWDFX

-

DFX子系统

-

static const std::string IAWARE

-

本地资源调度管控子系统

-

static const std::string INTELLI_ACCESSORIES

-

智能配件业务子系统

-

static const std::string INTELLI_TV

-

智能电视业务子系统

-

static const std::string IVI_HARDWARE

-

车机专有硬件服务子系统

-

static const std::string LOCATION

-

位置服务子系统

-

static const std::string MSDP

-

综合传感处理平台子系统

-

static const std::string MULTI_MEDIA

-

媒体子系统

-

static const std::string MULTI_MODAL_INPUT

-

多模输入子系统

-

static const std::string NOTIFICATION

-

事件通知子系统

-

static const std::string POWERMGR

-

电源服务子系统

-

static const std::string ROUTER

-

路由器业务子系统

-

static const std::string SECURITY

-

安全子系统

-

static const std::string SENSORS

-

泛Sensor服务子系统

-

static const std::string SOURCE_CODE_TRANSFORMER

-

应用移植子系统

-

static const std::string STARTUP

-

启动恢复子系统

-

static const std::string TELEPHONY

-

电话服务子系统

-

static const std::string UPDATE

-

升级服务子系统

-

static const std::string USB

-

USB服务子系统

-

static const std::string WEARABLE_HARDWARE

-

穿戴专有硬件服务子系统

-

static const std::string WEARABLE

-

穿戴业务子系统

-

static const std::string OTHERS

-

其它

-
- -**表 3** HiSysEvent::EventType接口介绍 - - - - - - - - - - - - - - - - - - - -

接口名

-

描述

-

FAULT

-

故障类型事件

-

STATISTIC

-

统计类型事件

-

SECURITY

-

安全类型事件

-

BEHAVIOR

-

系统行为事件

-
- -### 开发实例 - -C++接口实例 - -1. 源代码开发 - - 在类定义头文件或者类实现源文件中,包含HiSysEvent头文件: - - ``` - #include "hisysevent.h" - ``` - - 假设在业务关注应用启动时间start\_app,在业务类实现相关源文件中使用(调用接口打点): - - ``` - HiSysEvent::Write(HiSysEvent::Domain::AAFWK, "start_app", HiSysEvent::EventType::FAULT, "app_name", "com.demo"); - ``` - -2. 编译设置,在BUILD.gn里增加子系统SDK依赖: - - ``` - external_deps = [ "hisysevent_native:libhisysevent" ] - ``` diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/16.DFX/06.HiSysEvent\345\274\200\345\217\221\346\214\207\345\257\274/02.HiSysEvent\350\256\242\351\230\205\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/16.DFX/06.HiSysEvent\345\274\200\345\217\221\346\214\207\345\257\274/02.HiSysEvent\350\256\242\351\230\205\346\214\207\345\257\274.md" deleted file mode 100644 index c4b1d044bfaca489747ea60d4fb601ba8e8d0d2a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/16.DFX/06.HiSysEvent\345\274\200\345\217\221\346\214\207\345\257\274/02.HiSysEvent\350\256\242\351\230\205\346\214\207\345\257\274.md" +++ /dev/null @@ -1,210 +0,0 @@ ---- -title: HiSysEvent订阅指导 -permalink: /pages/0105100602 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# HiSysEvent订阅指导 - -- [概述](#section315316685112) - - [功能简介](#section123181433335224) - - [约束与限制](#section123181433375224) -- [开发指导](#section315316685113) - - [接口说明](#section0342191810519) - - [开发实例](#section123181432175110) - -## 概述 - -### 功能简介 - -HiSysEvent提供了跨进程订阅机制,开发者可以通过注册订阅接口实时获取关注的事件,例如电池模块侦听功耗相关的事件,用于分析耗电情况。 - -### 约束与限制 - -**HiSysEvent事件订阅条件约束:** - -- 在订阅HiSysEvent事件之前,需要先完成HiSysEvent打点配置,具体配置方法请参考[《HiSysEvent打点配置指导》](/pages/extra/ac6bb3/)。 - -## 开发指导 - -### 接口说明 - -**表 1** HiSysEvent订阅接口 - - - - - - - - - - - - - -

接口名称

-

描述

-

int HiSysEventManager::AddEventListener(std::shared_ptr<HiSysEventSubscribeCallBackBase> listener, std::vector<ListenerRule>& rules)

-

接口功能:
  注册订阅HiSysEvent系统事件侦听对象,可设置规则订阅某些事件。

-

输入参数:

-
  • listener:订阅回调对象。
  • rules:事件订阅规则。
-

返回值:

-
  • 0:订阅成功,重复订阅。
  • 1:订阅成功,初次订阅。
  • 其他返回值:订阅失败。
-

void HiSysEventManager::RemoveListener(std::shared_ptr<HiSysEventSubscribeCallBackBase> listener)

-

接口功能:
  移除订阅hisysevent系统事件侦听对象。

-

输入参数:

-
  • listener:订阅回调对象。
-

返回值:
  无。

-
- -**表 2** ListenerRule订阅规则对象 - - - - - - - - - - - - - - - - -

接口名称

-

描述

-

ListenerRule(const std::string& tag, RuleType ruleType = RuleType::WHOLE_WORD)

-

接口功能:
  订阅规则构造函数,创建事件标签订阅规则对象。

-

输入参数:

-
    -
  • tag:订阅规则的HisysEvent事件标签,字符串类型,最大长度16个字符(含),有效字符包含大小写字母及数字。
  • -
  • ruleType:订阅规则的规则类型,RuleType枚举类型(参考表3)。
-

ListenerRule(const std::string& domain, const std::string& eventName, RuleType ruleType = RuleType::WHOLE_WORD)

-

接口功能:
  订阅规则构造函数,创建事件领域与事件名称订阅规则对象。

-

输入参数:

-
    -
  • domain:订阅规则的HisysEvent事件领域,字符串类型,最大长度16个字符(含),有效字符包含大写字母、数字及下划线。
  • -
  • eventName:订阅规则的HisysEvent事件名称,字符串类型,最大长度32个字符(含),有效字符包含大写字母、数字及下划线。
  • -
  • ruleType:订阅规则的规则类型,RuleType枚举类型(参考表3)。
-

ListenerRule(const std::string& domain, const std::string& eventName, const std::string& tag, RuleType ruleType = RuleType::WHOLE_WORD)

-

接口功能:
  订阅规则构造函数,创建事件领域、事件名称,事件标签订阅规则对象。

-

输入参数:

-
    -
  • tag:订阅规则的HisysEvent事件标签,字符串类型,最大长度16个字符(含),有效字符包含大小写字母及数字。
  • -
  • domain:订阅规则的HisysEvent事件领域,字符串类型,最大长度16个字符(含),有效字符包含大写字母、数字及下划线。
  • -
  • eventName:订阅规则的HisysEvent事件名称,字符串类型,最大长度32个字符(含),有效字符包含大写字母、数字及下划线。
  • -
  • ruleType:订阅规则的规则类型,RuleType枚举类型(参考表3)。
-
- -**表 3** RuleType类型 - -| 枚举值 | 描述 | -| ------------ | ------------- | -| WHOLE_WORD | 全词匹配类型 | -| PREFIX | 前缀匹配类型 | -| REGULAR | 正则匹配类型 | - -**表 4** HiSysEventSubscribeCallBackBase订阅对象 - - - - - - - - - - - -

接口名称

-

描述

-

void HiSysEventSubscribeCallBackBase::OnHandle(const std::string& domain, const std::string& eventName, const int eventType, const std::string& eventDetail)

-

接口功能:
  订阅事件的回调接口。

-

输入参数:

-
  • domain:事件所属领域。
  • eventName:事件的名称。
  • eventType:事件类型。
  • eventDetail:包含事件相关信息的字符串,以json的形式体现。
-

返回值:
  无。

-
- -### 开发实例 - -订阅HiSysEvent事件C++接口实例 - -1. 源代码开发 - - 自定义订阅回调实现类头文件DemoListener.h: - - ``` - #ifndef DEMO_LISTENER_H - #define DEMO_LISTENER_H - - #include "hisysevent_subscribe_callback_native.h" - - #include - - class DemoListener : public OHOS::HiviewDFX::HiSysEventSubscribeCallBackNative { - public: - explicit DemoListener() : HiSysEventSubscribeCallBackNative() {} - void OnHandle(const std::string& domain, const std::string& eventName, const int eventType, - const std::string& eventDetail); - virtual ~DemoListener() {} - void OnServiceDied(); - }; - - #endif DEMO_LISTENER_H - ``` - - 增加DemoListener.cpp文件,在DemoListener类中根据实际需求自定义订阅回调接口的实现逻辑: - - ``` - #include "demo_listener.h" - - #include - - void DemoListener::OnHandle(const std::string& domain, const std::string& eventName, - const int eventType, const std::string& eventDetail) - { - std::cout << eventDetail << std::endl; - } - - void DemoListener::OnServiceDied() - { - std::cout << std::string("service disconnect, exit") << std::endl; - exit(0); - } - ``` - - 通过HiSysEventManager类提供的AddEventListener接口注册回调对象,完成对HiSysEvent的订阅: - - ``` - auto demoListener = std::make_shared(); - // 事件标签规则订阅,规则类型为默认的全词匹配类型 - ListenerRule tagRule("dfx"); - // 事件标签规则订阅,规则类型为正则匹配类型 - ListenerRule regRule("dfx.*", RuleType::REGULAR); - // 事件领域及事件名称规则订阅,规则类型为前缀匹配类型 - ListenerRule domainNameRule("HIVIEWDFX", "APP_USAGE", RuleType::PREFIX); - std::vector sysRules; - sysRules.push_back(tagRule); - sysRules.push_back(regRule); - sysRules.push_back(domainNameRule); - HiSysEventManager::AddEventListener(demoListener, sysRules); - ``` - -2. 编译配置 - - 在BUILD.gn编译文件中,需要添加依赖hisysevent\_native组件的libhisyseventmanager库: - - ``` - external_deps = [ "hisysevent_native:libhisyseventmanager", ] - ``` diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/16.DFX/06.HiSysEvent\345\274\200\345\217\221\346\214\207\345\257\274/03.HiSysEvent\346\237\245\350\257\242\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/16.DFX/06.HiSysEvent\345\274\200\345\217\221\346\214\207\345\257\274/03.HiSysEvent\346\237\245\350\257\242\346\214\207\345\257\274.md" deleted file mode 100644 index 38a1a0ea0b82314ec8952038875533ffcf740893..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/16.DFX/06.HiSysEvent\345\274\200\345\217\221\346\214\207\345\257\274/03.HiSysEvent\346\237\245\350\257\242\346\214\207\345\257\274.md" +++ /dev/null @@ -1,191 +0,0 @@ ---- -title: HiSysEvent查询指导 -permalink: /pages/0105100603 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# HiSysEvent查询指导 - -- [概述](#section279684125212) -- [开发指导](#section315316761113) - - [接口说明](#section03869128521) - - [开发实例](#section14286111855212) - -## 概述 - -HiSysEvent提供了查询接口,支持开发者设置条件查询HiSysEvent事件,例如功耗部件可以通过该接口获取所需的系统事件进行业务分析。 - -## 开发指导 - -### 接口说明 - -**表 1** HiSysEvent查询接口 - - - - - - - - - - -

接口名

-

描述

-

bool HiSysEventManager::QueryHiSysEvent(struct QueryArg& queryArg, std::vector<struct QueryRule>& queryRules, std::shared_ptr<HiSysEventQueryCallBackBase> queryCallBack)

-

接口功能:支持设置查询时间段,事件领域,事件名称等,查询满足条件的HiSysEvent事件。

-

输入参数:

-
  • queryArg:查询参数。
  • queryRules:事件过滤规则。
  • queryCallBack:查询接口回调对象。
-

返回值:

-
  • true:查询成功。
  • false:查询失败。
-
- -**表 2** QueryArg查询参数对象 - - - - - - - - - - - - - - - - -

属性名称

-

描述

-

long long beginTime

-

事件开始时间。

-

long long endTime

-

事件结束事件。

-

int maxEvents

-

返回最大的查询条数。

-
- -**表 3** QueryRule查询规则对象 - - - - - - - - - - - - - - - - -

属性名称

-

描述

-

uint32_t ruleType

-

规则类型,目前默认是0。

-

std::string domain;

-
  • domain:事件所属领域,如果传入的是空字符串,则默认事件领域字段匹配成功。
-

std::vector<std::string> eventList

-
  • eventList:事件名称的列表,如果传入的是空字符串,则默认事件名称字段匹配成功。
-
- -**表 4** HiSysEventQueryCallBackBase查询回调对象 - - - - - - - - - - - - - -

接口名称

-

描述

-

void HiSysEventQueryCallBackBase::OnQuery(const ::std::vector<std::string>& sysEvent, const ::std::vector<int64_t>& seq)

-

接口功能:订阅事件查询中的回调。

-

输入参数:

-
  • sysEvent:返回事件集合。
  • seq:事件序列集合。
-

返回值:无。

-

void HiSysEventQueryCallBackBase::OnComplete(int32_t reason, int32_t total)

-

接口功能:订阅事件查询完成的回调。

-

输入参数:

-
  • reason:查询结束返回原因,目前默认是0。
  • total:本次查询总共返回的事件总数量。
-

返回值:无。

-
- -### 开发实例 - -C++接口实例。 - -1. 源代码开发: - - - 引入对应的头文件: - - hisysevent\_manager.h - - - 实现对应的查询回调接口: - - void HiSysEventQueryCallBackBase::OnQuery\(const ::std::vector& sysEvent, const ::std::vector& seq\) - - void HiSysEventQueryCallBackBase::OnComplete\(int32\_t reason, int32\_t total\) - - - 在相应的业务逻辑里面调用查询接口: - - HiSysEventManager::QueryHiSysEvent\(struct QueryArg& queryArg, std::vector& queryRules, std::shared\_ptr queryCallBack\) - - - ``` - // 以下是查询所有系统事件的应用例子 - #include "hisysevent_manager.h" - #include - - namespace OHOS { - namespace HiviewDFX { - // 实现查询回调的接口 - void HiSysEventToolQuery::OnQuery(const ::std::vector& sysEvent, - const ::std::vector& seq) - { - for_each(sysEvent.cbegin(), sysEvent.cend(), [](const std::string &tmp) { - std::cout << tmp << std::endl; - }); - } - - void HiSysEventToolQuery::OnComplete(int32_t reason, int32_t total) - { - return; - } - } // namespace HiviewDFX - } // namespace OHOS - - // 调用查询接口获取HiSysEvent事件 - auto queryCallBack = std::make_shared(); - struct QueryArg args(clientCmdArg.beginTime, clientCmdArg.endTime, clientCmdArg.maxEvents); - std::vector mRules; - HiSysEventManager::QueryHiSysEvent(args, mRules, queryCallBack); - ``` - -2. 编译设置: - - 在BUILD.gn编译文件中,需要添加依赖hisysevent\_native部件的libhisyseventmanager库。 - - ``` - external_deps = [ "hisysevent_native:libhisyseventmanager", ] - ``` - - diff --git "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/16.DFX/06.HiSysEvent\345\274\200\345\217\221\346\214\207\345\257\274/04.HiSysEvent\345\267\245\345\205\267\344\275\277\347\224\250\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/16.DFX/06.HiSysEvent\345\274\200\345\217\221\346\214\207\345\257\274/04.HiSysEvent\345\267\245\345\205\267\344\275\277\347\224\250\346\214\207\345\257\274.md" deleted file mode 100644 index 22441540a3ff7b73effaed1aeac487282197389c..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/05.\345\255\220\347\263\273\347\273\237\345\274\200\345\217\221/16.DFX/06.HiSysEvent\345\274\200\345\217\221\346\214\207\345\257\274/04.HiSysEvent\345\267\245\345\205\267\344\275\277\347\224\250\346\214\207\345\257\274.md" +++ /dev/null @@ -1,115 +0,0 @@ ---- -title: HiSysEvent工具使用指导 -permalink: /pages/0105100604 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# HiSysEvent工具使用指导 - -- [概述](#section1886702718521) -- [实时订阅HiSysEvent事件相关命令](#section1210623418527) -- [查询历史HiSysEvent事件相关命令](#section1210623418539) - -## 概述 - -目前在系统的/system/bin目录下预置了hisysevent工具,开发者可以通过此工具实时订阅HiSysEvent事件及查询历史HiSysEvent事件。 - -## 实时订阅HiSysEvent事件相关命令 - -- 实时订阅HiSysEvent事件的基础命令: - - ``` - hisysevent -r - ``` - - 选项说明: - - | 选项名称 | 功能说明 | - | -------- | --------- | - | -r  | 以缺省设置实时订阅HiSysEvent事件,在此种订阅方式下有任何实时HiSysEvent事件产生,都会在控制台上打印此HiSysEvent事件 | - -- 打开调试模式: - - ``` - hisysevent -r -d - ``` - - 选项说明: - - | 选项名称 | 功能说明 | - | -------- | --------- | - | -d | 在调试模式下实时订阅HiSysEvent事件 | - -- 通过事件标签方式实时订阅HiSysEvent事件: - - ``` - hisysevnet -r -t [-c [WHOLE_WORD|PREFIX|REGULAR]] - ``` - - 选项说明: - - | 选项名称 | 功能说明 | - | -------- | --------- | - | -t  | 设置实时订阅的HiSysEvent事件标签,用来过滤订阅的HiSysEvent事件 | - | -c  | 设置实时订阅的HiSysEvent事件标签匹配规则,有“WHOLE_WORD”、“PREFIX”、“REGULAR”三种匹配规则| - -- 通过事件领域及事件名称的方式实时订阅HiSysEvent事件: - - ``` - hisysevent -r -o -n [-c [WHOLE_WORD|PREFIX|REGULAR]] - ``` - - | 选项名称 | 功能说明 | - | -------- | --------- | - | -o | 设置实时订阅的HiSysEvent事件领域,用来过滤订阅的HiSysEvent事件 | - | -n | 设置实时订阅的HiSysEvent事件名称,用来过滤订阅的HiSysEvent事件| - | -c | 设置实时订阅的HiSysEvent事件领域及事件名称的匹配规则,有“WHOLE_WORD”、“PREFIX”、“REGULAR”三种匹配规则| - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >当同时通过-t、-o及-n指定了相关订阅规则参数设置,则判断设置的事件标签是否为空,若不为空,则使用事件标签规则进行订阅,否则使用事件领域及事件名称订阅规则进行订阅。 - -## 查询历史HiSysEvent事件相关命令 - -- 查询历史HiSysEvent事件的基础命令: - - ``` - hisysevent -l - ``` - - 选项说明: - - | 选项名称 | 功能说明 | - | -------- | --------- | - | -l | 以缺省设置查询历史HiSysEvent事件,此次查询会返回最近不多于1000条的HiSysEvent事件 | - -- 通过设置开始/结束时间,过滤查询历史HiSysEvent事件的结果的命令: - - ``` - hisysevent -l -s -e - ``` - - 选项说明: - - | 选项名称 | 功能说明 | - | -------- | --------- | - | -s | 设置查询历史HiSysEvent事件的开始时间,此次查询只会返回不早于该时间点的HiSysEvent事件 | - | -e | 设置查询历史HiSysEvent事件的结束时间,此次查询只会返回不晚于该时间点的HiSysEvent事件 | - -- 通过设置最大数量值,限制查询历史HiSysEvent事件的数量: - - ``` - hisysevent -l -m - ``` - - 选项说明: - - | 选项名称 | 功能说明 | - | -------- | --------- | - | -m | 设置查询历史HiSysEvent事件的数量,有效值范围[0,1000],此次查询返回的HiSysEvent事件数目不会多于此值。 | diff --git "a/website/docs/01.OpenHarmony/06.\344\270\223\351\242\230/01.HPMbundle/01.HPMBundle\345\274\200\345\217\221\350\247\204\350\214\203.md" "b/website/docs/01.OpenHarmony/06.\344\270\223\351\242\230/01.HPMbundle/01.HPMBundle\345\274\200\345\217\221\350\247\204\350\214\203.md" deleted file mode 100644 index 53561a6d4c484ae16aca285ef6e9639c7cd87ff3..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/06.\344\270\223\351\242\230/01.HPMbundle/01.HPMBundle\345\274\200\345\217\221\350\247\204\350\214\203.md" +++ /dev/null @@ -1,562 +0,0 @@ ---- -title: HPMBundle开发规范 -permalink: /pages/01060101 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 开发规范 - -- [概述](#section16820114352316) - - [定义](#section123361236249) - - [Bundle划分原则](#section1918162512419) - - [Bundle依赖](#section1687484311240) - -- [Bundle构成](#section18351162611254) - - [代码文件](#section1575645102513) - - [说明文件](#section15300198132611) - - [元数据描述文件](#section10956525102613) - -- [Bundle管理](#section32061634104110) - - [依赖关系](#section37361058192610) - - [hpm操作命令参考](#section72383420271) - -- [Bundle版本](#section162921336288) - - [版本号命名规范](#section176561816172819) - - [版本发布](#section8683417284) - -- [发行版](#section243845052819) -- [环境变量说明](#section19567181517299) - -## 概述 - -本文档将介绍Bundle的基本概念以及如何按照规范定义Bundle。 - -### 定义 - -OpenHarmony软件以bundle作为基本单元,从系统角度看,凡是运行在OpenHarmony上的软件都可以定义为Bundle;一般来讲,根据Bundle的应用范围,可以分为: - -- 板级Bundle:如board、arch、mcu这些与设备硬件相关的Bundle。 -- 系统Bundle:一组独立功能的集合,如内核、文件系统、框架等。 -- 应用Bundle:直接面向用户提供服务的应用\(如wifi\_iot,ip\_camera\)。 - -从形式上看,Bundle是为复用而生,一切可以复用的模块都可以定义为Bundle,可以分为: - -- 源代码 -- 二进制 -- 代码片段 -- 发行版 - -### Bundle划分原则 - -原则上应尽可能划分为细颗粒度的Bundle,以满足最大限度的复用。主要考虑以下几点: - -- 独立性:Bundle的功能应该相对独立,支持独立编译,可以单独对外提供接口和服务; -- 耦合性:如果Bundle必须依赖其他的Bundle,才能对外提供服务,应考虑和被依赖的Bundle合并为一个Bundle。 -- 相关性:如果一组Bundle共同完成一项功能,且没有被其他Bundle依赖,未来也没有被依赖的可能,则可以考虑合并为一个Bundle。 - -### Bundle依赖 - -Bundle的依赖关系分为两种:必选依赖和可选依赖。 - -- 必选依赖:是指BundleA在完成某个功能时,必须引入BundleB,调用B的接口或服务配合才能完成。称B为A的必选依赖。 -- 可选依赖:是在BundleA在完成某个功能时,可以引入BundleC,也可以引入BundleD。C和D可以相互替换,称C和D为A的可选依赖。 - -## Bundle构成 - -一个Bundle包一般包含如下内容: - -- Bundle包的代码或库(src目录下的代码文件) -- ohos\_bundles文件夹(存放依赖的Bundle,安装Bundle时自动生成,无需提交到代码库) -- Bundle包的说明文件\(README.md\) -- Bundle包元数据声明文件\(bundle.json\) -- 开源许可文件\(LICENSE\) - - ``` - my-bundle - |_ohos_bundles - |_src - |_bundle.json - |_README.md - |_LICENSE - ``` - - -### 代码文件 - -Bundle的代码文件和普通的代码目录没有差异。但要注意的是,Bundle中对外暴露的接口(头文件),会被其他Bundle所引用,需要单独在bundle.json的dirs中声明。 - -### 说明文件 - -README.md,为markdown格式的描述关于Bundle自述说明文件。([语法参考](https://www.markdownguide.org/getting-started/)\) - -为了帮助他人在hpm上找到该Bundle,并更方便的使用它,在Bundle的根目录中包含一个README文件。 - -README文件可能包括如何安装,配置和使用Bundle包中的实例代码说明,以及可能会对用户有所帮助的任何其他信息。 - -每个Bundle的自述文件将显示在hpm系统的Bundle详情页面的描述中。 - -### 元数据描述文件 - -bundle.json文件是对当前Bundle的元数据描述,每个Bundle中必须包含一个bundle.json文件。 - -``` -{ - "name": "@myorg/demo-bundle", - "version": "1.0.0", - "license": "MIT", - "description": "bundle description", - "keywords": ["hos"], - "tags": ["applications", "drivers"], - "author": {"name":"","email":"","url":""}, - "contributors":[{"name":"","email":"","url":""},{"name":"","email":"","url":""}], - "homepage": "http://www.foo.bar.com", - "repository": "https://git@gitee.com:foo/bar.git", - "publishAs": "code-segment", - "segment":{ - "destPath":"/the/dest/path" - }, - "dirs": { - "src": ["src/**/*.c"], - "headers": ["headers/**/*.h"], - "bin": ["bin/**/*.o"] - }, - "scripts": { - "build": "make" - }, - "envs": {}, - "ohos": { - "os": "2.0.0", - "board": "hi3516", - "kernel": "liteos-a" - }, - "rom": "10240", - "ram": "1024", - "dependencies": { - "@myorg/net":"1.0.0" - } -} -``` - -bundle.json文件具有如下功能: - -- name:定义Bundle的名称,放到组织下, 以@开头,/分割,如:@myorg/mybundle - -- version:定义Bundle版本号,如1.0.0,需满足semver的标准。 - -- description:一句话对Bundle进行简要的描述。 -- dependencies:定义Bundle的依赖Bundle。 - -- envs: 定义Bundle编译时所需要的参数,包括全局参数以及依赖所需的参数。 - -- scripts:定义在当前Bundle下能够执行的命令(如编译,构建,测试,烧录等)。 - -- publishAs:定义Bundle的发布类型(source:源码,binary:二进制,distribution:发行版,code-segment:代码片段)。 - -- segment: 仅针对code-segment类型的Bundle,定义Bundle的目标路径(即安装后,Bundle包中包含的文件复制到的目标路径) -- dirs:定义发布时打包的目录结构(如头文件)。 - -- ram&rom:统计相关信息:预计占用ROM和RAM信息。 -- ohos:描述OpenHarmony系统版本、开发板及内核的匹配关系(多个请用英文逗号的“,”分割)。 -- 定义其他扩展信息:作者,主页,代码仓库,许可协议,标签,关键字。 -- 对于发行版类型,还有个base,可以定义继承自的发行版。 - -## Bundle管理 - -### 依赖关系 - -生成基础bundle.json以后,需要继续添加Bundle依赖来实现更复杂的功能。此时需要知道所依赖Bundle的名称和版本号,并且把它们定义在bundle.json里面的dependencies字段中。 - -``` -{ - "name": "my-bundle", - "version": "1.0.0", - "dependencies": { - "net": "1.0.0" - } -} -``` - -上述示例中,my-bundleBundle依赖于net 1.0.0Bundle。在全局安装了 hpm CLI 工具之后,执行如下命令可以从远端仓库获取到依赖: - -``` -hpm install -``` - -依赖获取以后,会保存到当前Bundle根目录下到ohos\_bundles文件夹中。Bundle以及依赖之间会形成一个依赖关系的树状结构。全局安装了 hpm CLI 工具之后,在Bundle根目录下执行如下命令: - -``` -username@server MINGW64 /f/showcase/demo/demo -$ hpm list -+--demo@1.0.0 -| +--@huawei/media@1.0.2 -| +--@demo/sport_hi3518ev300_liteos_a@1.0.0 -| | +--@demo/app@4.0.1 -| | | +--@demo/build@4.0.1 -| | | +--@demo/arm_harmonyeabi_gcc@4.0.0 -| | +--@demo/liteos_a@4.0.0 -| | | +--@demo/third_party_fatfs@4.0.0 -| | | +--@demo/arm_harmonyeabi_gcc@4.0.0 -| | +--@demo/init@4.0.0 -| | +--@demo/dist_tools@4.0.0 -``` - -还可以使用可视化的形式,来查看当前Bundle的依赖关系,执行如下命令: - -``` -hpm ui -``` - -会在本地启动一个web服务(默认会打开浏览器并进入项目页),点击侧边栏的项目依赖图标,打开页面,可以看到项目的依赖Bundle列表,点击右侧按钮切换到树状视图,就可以看到依赖关系的图形化展示\(如下图\)。 - -**图 1** Bundle包依赖关系图 - - -![](/images/device-dev/bundles/figure/zh-cn_image_0000001188040429.png) - -### hpm操作命令参考 - -Bundle的全生命周期管理,可以通过hpm命令工具进行操作,hpm的操作命令如下(详细帮助可以执行 hpm -h学习): - -**表 1** hpm操作命令 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

命令类别

-

命令行

-

含义说明

-

版本查询

-

hpm -V 或 hpm --version

-

查看hpm-cli 版本号。

-

帮助查询

-

hpm -h 或 hpm --version

-

查看命令列表及帮助。

-

hpm -h

-

查看命令帮助。

-

创建

-

-

hpm init bundle

-

创建Bundle工程。

-

hpm init -t template

-

根据模板创建脚手架工程。

-

安装

-

-

hpm install 或hpm i

-

安装bundle.json中依赖的Bundle。

-

hpm install bundle@version

-

安装指定Bundle版本。

-

卸载

-

-

hpm uninstall bundle

-

删除depedencies依赖的Bundle。

-

hpm remove 或hpm rm bundlename

-

删除depedencies依赖的Bundle。

-

查看

-

-

hpm list 或者 hpm ls

-

显示当前Bundle/发行版所有的Bundle树。

-

hpm dependencies

-

生成当前Bundle/发行版依赖关系数据(在hpm ui也集成了该命令的调用,可以图形化的展示)

-

搜索

-

hpm search name

-

搜索Bundle,--json,可以以json格式输出 -type 可以设置搜索Bundle的类型,包括bundle,distribution,code-segment三种。

-

设置hpm配置项

-

hpm config set key value

-

设置配置值,如服务器地址,网络代理。

-

hpm config delete key

-

删除配置。

-

更新

-

-

hpm update

-

更新当前Bundle依赖的Bundle的版本。

-

hpm check-update

-

检查依赖的Bundle版本是否有更新。

-

编译

-

-

hpm build

-

编译Bundle/发行版。

-

hpm dist

-

针对发行版(distribution),发行版编译构建(依赖bundle.json的scripts中的dist脚本)。

-

打包

-

hpm pack

-

本地Bundle打包依赖。

-

烧录

-

hpm run flash

-

烧录固件(依赖bundle.json的scripts中的flash脚本)。

-

发布

-

hpm publish

-

发布Bundle,发布的Bundle在仓库中必须唯一,且版本唯一(需要账号登录)。

-

执行扩展命令

-

hpm run

-

执行bundle.json文件中定义的scripts脚本命令,支持多个命令可用 && 连接。

-

解压包

-

hpm extract

-

解压文件. 支持格式'zip','tar','tgz' 和'.tar.gz'

-

启动图形化界面

-

hpm ui

-

本地启动HPM UI,可通过-p参数指定端口,Windows平台下会启动默认的浏览器打开

-

多语言切换

-

hpm lang

-

切换中英文操作界面(同时支持命令行和UI)

-

转换为hpm包格式

-

hpm x2h

-

将一个maven格式或npm格式包转换成hpm的包格式,并发布到HPM

-

代码段还原或清理

-

hpm code clean|restore

-

针对依赖的代码段(code-segment)Bundle,执行清理或还原操作(即根据segment.destPath执行拷贝/删除操作)

-

生成秘钥

-

hpm gen-keys

-

生成公钥/私钥对,将公钥配置到HPM服务端,可以实现hpm-cli 免密登录,发布Bundle。

-

生成第三方开源说明

-

hpm gen-notice

-

根据每个Bundle的说明,生成一份合并后的第三方开源说明的合并文件。

-
- -## Bundle版本 - -### 版本号命名规范 - -名称需要为全小写字母,中间可以使用中划线或者下划线分隔。比如 "bundle", "my\_bundle"。 - -版本号的格式为 "主版本号.次版本号.修订号" 或 "主版本号.次版本号.修订号-先行版本号",比如 "1.0.0", "1.0.0-beta",详细规格可以参考 [https://semver.org](https://semver.org/)。 - -### 版本发布 - -为了使Bundle能被其他开发者使用,Bundle需要上传到远端仓库。Bundle上传使用如下命令: - -``` -hpm publish -``` - -命令执行以后,系统会对的整个依赖关系进行检查,下载缺失依赖Bundle。依赖检查完成后,如果发布类型为binary,系统会对整个Bundle进行编译,生成二进制文件,然后打包上传。如果使其他上传类型,则直接根据定义的打包规则进行打包,然后上传。 - -注意:发布Bundle需要用户账号登录,需要先拥有hpm的系统账号后,并注册组织,申请组织认证通过后,才拥有发布的权限。 - -## 发行版 - -发行版通常是将一系列Bundle组合起来,成为编译可以运行的OpenHarmony解决方案镜像,里面包含了多个依赖的Bundle,以及脚本,用于描述如何完整编译、链接这些Bundle。 - -发行版本身通常不需要包含功能实现代码,仅包含bundle.json描述(设置publishAs为distribution)和一些编译脚本组成。 - -因为发行版编译的过程需要系统提供环境变量,所以发行版使用scripts脚本中内置的dist命令: - -``` -{ - "publishAs":"distribution", - "scripts": { - "dist": "script compile command" - } -} -``` - -编译执行使用如下命令: - -``` -hpm dist -``` - -重新定义一个发行版所具有的功能是一个复杂的过程,所以系统允许对发行版进行继承,从而在现有功能的基础上进行定制。继承发行版需要在bundle.json中定义base字段。 - -``` -{ - "base": { - "name": "dist_wifi_iot", - "version": "1.0.0" - } -} -``` - -上述定义表明当前Bundle继承自发行版Bundledist-wifi-iot 1.0.0。 - -发行版由很多的依赖Bundle组成,通过bundle.json中的dependencies段来描述,有些依赖是必须的,有些依赖则是根据可以需求增加或删除的。bundle.json中名称前带有?的依赖表示可选依赖,继承它的发行版,可以移除掉该可选Bundle,再增加别的Bundle进行替换。 - -``` -{ - "dependencies": { - "?my_bundle": "1.0.0" - } -} -``` - -上述声明表示my\_bundle依赖可以被移除。如果想要移除my\_bundle,在上层依赖方需要使用excludes关键字来进行定义 - -``` -{ - "excludes": [ "my_bundle" ] -} -``` - -依赖被移除后,就不会参入Bundle的构建过程。只有标记为可选的依赖才能够被移除,强行移除未被标记的依赖会出现错误提示。 - -## 环境变量说明 - -Bundle在编译的过程中需要依赖系统提供的环境变量来自定义输出,链接所需二进制文件等等。这里提出的环境变量均指根据需求把所需变量注入脚本执行的上下文中。所以在脚本中可以直接获取到变量的值。下面介绍当前系统存在的几种环境变量。 - -全局变量由bundle.json中的envs属性来定义。整个Bundle中的依赖都可以获取到全局变量定义的值。 - -``` -{ - "envs": { - "compileEnv": "arm" - } -} -``` - -不同Bundle在引入依赖的过程中可以传入不同的参数,从而使依赖的编译可以满足当前Bundle的需求。依赖中定义的参数可以在对应依赖脚本执行的上下文中获取到。 - -``` -{ - "dependencies": { - "my-bundle": { - "version": "1.0.0", - "mode": "debug" - } - } -} -``` - -Bundle在链接二进制文件的时候,需要知道二进制文件在依赖中的路径,所以依赖的路径会作为环境变量传入编译Bundle中。 - -传入的环境变量的格式为DEP\_BundleName,BundleName为依赖的名称,例如 DEP\_first\_bundle。 - -依赖中可以定义标签,对引入的依赖进行分组。在脚本中可以根据标签,获得这一组依赖的路径。定义的标签以\#开头,具体定义的方式为: - -``` -{ - "dependencies": { - "#tool": { - "first-bundle": "1.0.0", - "second-bundle": "1.0.0" - }, - "#drivers": { - "xx-bundle": "1.0.0", - "yy-bundle": "1.0.0" - } - } -} -``` - -系统中存在两个固定环境变量: - -- DEP\_OHOS\_BUNDLES:表示ohos\_bundles文件夹所在的路径。 -- DEP\_BUNDLE\_BASE:表示最外层Bundle的路径。 - diff --git "a/website/docs/01.OpenHarmony/06.\344\270\223\351\242\230/01.HPMbundle/02.\345\274\200\345\217\221\346\214\207\345\215\227/01.HPMBundle\346\246\202\350\277\260.md" "b/website/docs/01.OpenHarmony/06.\344\270\223\351\242\230/01.HPMbundle/02.\345\274\200\345\217\221\346\214\207\345\215\227/01.HPMBundle\346\246\202\350\277\260.md" deleted file mode 100644 index f3eb3c63d71eee429107aad915092e2aa51a66c1..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/06.\344\270\223\351\242\230/01.HPMbundle/02.\345\274\200\345\217\221\346\214\207\345\215\227/01.HPMBundle\346\246\202\350\277\260.md" +++ /dev/null @@ -1,54 +0,0 @@ ---- -title: HPMBundle概述 -permalink: /pages/0106010201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 概述 - -- [Bundle](#section196713235514) -- [Distribution](#section155387501033) - -本章节将介绍OpenHarmony中的Bundle相关概念以及如何定义Bundle,并以一个示例说明如何使用hpm命令行工具完成Bundle的创建、开发、编译、发布、安装使用的全过程。 - -## Bundle - -Bundle是OpenHarmony中一个用来表示分发单元的术语,等同于包,一个Bundle中通常包含以下内容: - -- 被分发的二进制文件(二进制类型) -- 被分发的源代码文件(源代码/代码片段类型) -- 编译脚本(发行版类型需要) -- 自身的说明文件 - - bundle.json:元数据声明(名称,版本,依赖等) - - LICENSE:许可协议文本 - - README.md:自述文件 - - CHANGELOG.md:变更日志(可选) - - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->Bundle的类型可以分为二进制,源代码,代码片段,模板,插件,发行版等。一个Bundle可以依赖其他的Bundles,依赖关系为有向无环图 - -一个Bundle被发布到HPM服务器(https://hpm.harmonyos.com)后,另外一些开发者就可以通过hpm包管理器下载安装使用 。 - -一个Bundle在命名空间内拥有唯一的名称(命名格式为:@scope/name),可以进行独立的版本演进。 - -## Distribution - -Distribution是OpenHarmony的发行版,是一个完整的操作系统版本,集合了各种Bundle(驱动,内核,框架,应用等),也通过Bundle在HPM平台分发。 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->发行版的元数据中仅描述了依赖的Bundles以及如何编译该发行版的编译脚本,并不包含发行版的二进制镜像。下载发行版后,需要在本地将依赖的Bundles下载下来,安装编译后才能得到可用于烧录的系统镜像文件。 ->发行版可以继承,即在一个既有的发行版的基础上,通过增加/删除Bundle形成新的发行版,以实现发行版的定制。 - -**图 1** 组Bundle和Distribution的关系 - - -![](/images/device-dev/bundles/figure/组件和发行版的构成-英文.png) - diff --git "a/website/docs/01.OpenHarmony/06.\344\270\223\351\242\230/01.HPMbundle/02.\345\274\200\345\217\221\346\214\207\345\215\227/02.\345\256\211\350\243\205hpm\345\221\275\344\273\244\350\241\214\345\267\245\345\205\267.md" "b/website/docs/01.OpenHarmony/06.\344\270\223\351\242\230/01.HPMbundle/02.\345\274\200\345\217\221\346\214\207\345\215\227/02.\345\256\211\350\243\205hpm\345\221\275\344\273\244\350\241\214\345\267\245\345\205\267.md" deleted file mode 100644 index dad21f6b26eb8ed634569c6ae0b666a470e7231c..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/06.\344\270\223\351\242\230/01.HPMbundle/02.\345\274\200\345\217\221\346\214\207\345\215\227/02.\345\256\211\350\243\205hpm\345\221\275\344\273\244\350\241\214\345\267\245\345\205\267.md" +++ /dev/null @@ -1,86 +0,0 @@ ---- -title: 安装hpm命令行工具 -permalink: /pages/0106010202 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 安装hpm命令行工具 - -- [安装](#section14480912380) -- [配置hpm(可选)](#section138983413013) -- [下载OpenHarmony代码](#section669905815300) - -要进行Bundle的开发,需要安装包管理器hpm(HarmonyOS Package Manager),这是一个基于Node.js开发的跨平台的命令行工具,所以要运行hpm,需要先安装Node.js,然后可以npm 来安装hpm。 - -## 安装 - -1. 安装Node.js。 - - 从官网下载并在本地安装Node.js. - - 推荐安装 [Node.js](https://nodejs.org/) 12.x \(包含 npm 6.14.4\)或更高版本 \(推荐 12.13.0+\)。 - -2. 通过Node.js自带的npm安装hpm-cli命令行工具。执行以下命令: - - ``` - npm install -g @ohos/hpm-cli - ``` - -3. 安装完成后执行如下命令,显示hpm版本,即安装成功。 - - ``` - hpm -V 或 hpm --version - ``` - -4. (可选)如果需要升级hpm版本,请执行如下命令: - - ``` - npm update -g @ohos/hpm-cli - ``` - - -## 配置hpm(可选) - -安装完hpm-cli命令行工具后,如果需要更改配置信息(如代理,shell),执行以下命令可以查看hpm配置: - -``` -hpm config -``` - -上述命令执行后将会显示hpm的默认配置,您可以根据自己需要对默认配置进行修改,以下是hpm的常用配置: - -``` -registry = https://hpm.harmonyos.com -### login Settings -# loginUser = invitation_code - -#### Path Settings -shellPath = C:\WINDOWS\System32\cmd.exe -# shellPath = C:\Program Files\Git\bin\sh.exe -# globalRepo = C:\Users\username\.hpm\global - -#### Network Settings -# no_proxy = *.server.com -# http_proxy = http://user:pwd@proxy_server:port -# https_proxy = http://user:pwd@proxy_server:port -# strictSsl = true - -#### Other Settings -# privateSupport = true|false -# ignoreBundles = @ohos/llvm,@ohos/gn, -# OSPlatform = Auto|linux|darwin|win32 -``` - -hpm-cli的命令介绍可以参考:[hpm操作命令](/pages/0106010201) - -## 下载OpenHarmony代码 - -参考[《源码获取》](/pages/extra/51fbe5/)。 - diff --git "a/website/docs/01.OpenHarmony/06.\344\270\223\351\242\230/01.HPMbundle/02.\345\274\200\345\217\221\346\214\207\345\215\227/03.\345\274\200\345\217\221Bundle.md" "b/website/docs/01.OpenHarmony/06.\344\270\223\351\242\230/01.HPMbundle/02.\345\274\200\345\217\221\346\214\207\345\215\227/03.\345\274\200\345\217\221Bundle.md" deleted file mode 100644 index fa315a28477aa9d0bf5424a5a5c51429af1328e8..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/06.\344\270\223\351\242\230/01.HPMbundle/02.\345\274\200\345\217\221\346\214\207\345\215\227/03.\345\274\200\345\217\221Bundle.md" +++ /dev/null @@ -1,375 +0,0 @@ ---- -title: 开发Bundle -permalink: /pages/0106010203 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 开发Bundle - -- [创建Bundle](#section717481119145) -- [将现有工程定义为Bundle](#section102861955201410) -- [发布Bundle到HPM平台](#section1318574233211) -- [引用Bundle](#section57959284315) -- [全局安装Bundle](#section647375516313) -- [编译Bundle](#section7972161715325) -- [定义编译脚本](#section10274147111610) -- [执行编译](#section879301916172) -- [定义发行版](#section127388393326) -- [定义脚本](#section11503171219190) -- [编译发行版](#section4694125521912) -- [烧录](#section2061514431039) - -创建OpenHarmonyBundle有如下几种方式: - -- 从头创建一个全新的Bundle。 -- 将一个现有的源码项目定义为Bundle。 - -## 创建Bundle - -通常情况下,[HPM网站](https://hpm.harmonyOS.com)上能找到您开发常用的Bundle,如果现有的Bundle不能完全满足开发,这时可以自己动手开发一个Bundle。 - -如果您愿意,可以将Bundle发布到HPM的仓库中供其他用户使用。 - -假设要在D:/source目录下新建一个全新的Bundle:my-bundle,可以使用hpm init 创建该Bundle的脚手架代码,例如,进入D:/source目录,执行如下命令: - -``` -hpm init -t default -d demo mybundle -``` - -将使用'default' 模板 在当前目录下的demo路径下,创建一个名为mybundle的Bundle: - -``` -demo -├── headers # 头文件(样例) -│ └── main.h -└── src # 源代码(样例) -│ └─ main.c -├── bundle.json # 元数据声明文件 -└── LICENSE # 许可协议文本 -└── Makefile # 编译描述文件(样例) -└── README.md # Bundle的自述文件 - -``` - -接下来根据您的业务需要,实现Bundle内部的功能代码,以及编译脚本,完成代码开发后,通过git将代码(包括bundle.json文件)提交到组件代码托管仓库中(如gitee)。 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->``` ->hpm init -t {templatename} -d {dir} {name} ->``` ->- -t \{templatename\} :指的是模板名称。 ->- -d \{dir\}:是要创建的Bundle所存放的路径。 ->- name:为要创建的Bundle名称。 - -hpm 除了提供了少量默认模板之外,其他模板均存储在服务器端,可以使用命令hpm search -t template 从服务器端搜索模板。 - -![](/images/device-dev/bundles/figure/zh-cn_image_0000001141641532.png) - -## 将现有工程定义为Bundle - -如果您已经有了代码工程,需要分发的HPM平台,只需要在当前工程目录下(例如mybundle2),执行如下命令,会引导您输入组件名称和版本等信息。 - -``` -hpm init -``` - -1. 输入名称后回车(如mybundle2)。 -2. 接下来依次输入版本、描述等信息后,会在当前目录下会生成一个bundle.json文件。 -3. 也可以打开bundle.json文件。 - - ``` - $ hpm init - Your bundle will be created in directory ~\demo\mybundle2 - ? bundle name mybundel2 - ? version 1.0.0 - ... - Initialization finished. - ``` - - -1. 打开bundle.json文件修改其他信息(如作者,代码仓库,代码目录,命令脚本,依赖组件等),如下(仅示意): - - ``` - { - "name": "mybundle2", - "version": "1.0.0", - "publishAs": "code-segment", - "dirs":{ - ".":["README.md"], - "src":["test.c"], - "header":["header/test.h" ], - "src/common":["src/common/foobar.txt"] - }, - "scripts": { - "build": "make -${args}" - }, - "dependencies": { - "@ohos/cjson": "^1.0.0", - "@ohos/foobar": "^1.2.0" - } - } - ``` - - -## 发布Bundle到HPM平台 - -要在发布Bundle到HPM,你需要先具备账号,并创建组织,创建组织的条件及详细步骤请参考hpm网站上的帮助说明。 - -完成账号申请和组织创建(或者加入一个现有的组织)后,您需要根据个人的邀请码(在HPM网站的个人中心页查看),在本机生成公钥,并在HPM网站的个人中心配置。 - -``` -hpm config set loginUser {your-invitation-code} -hpm gen-keys -``` - -生成的文件将会存放在 \~\\Users\\yourname\\.hpm\\key 下,将公钥文件\(publicKey\_your-accout.pem\)中内容拷贝到 HPM 个人中心的 SSH 公钥中。 - -完成上述操作后,你就具备了在您的组织内发布Bundle的权限了。 - -在bundle所在目录,执行命令hpm publish,将会完成组件的打包发布操作。 - -``` -hpm publish -``` - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->- 为避免Bundle名称冲突,发布的Bundle的名称需限定在组织范围内,即命名为@org\_name/bundle\_name的格式。 ->- 你的账号也必须是org\_name内的成员,才可以发布或更新组织内的Bundle。 ->- 发布的组件,需要通过安全及内容审核,才能正式生效。 - -## 引用Bundle - -通常开发一个项目,需要引用其他的组件以加快特定功能的开发,可以采用安装依赖的方式。 - -首先去HPM网站,根据关键字去搜索满足您的需求的组件,找到合适的组件后,将其引入到您的工程。 - -在您的bundle工程中(工程目录中必须包含bundle.json文件)执行如下命令: - -``` -$ hpm install @scope/the_bundle -``` - -引用的bundle将会被安装到你的工程所在的目录的 ohos\_bundle下 - -``` -project -├── ohos_bundle -│ └── scope -│ └─ the_bundle # <---引用的组件将会出现在这 -└── src -│ └─ main.c -├── bundle.json # 元数据声明文件 -└── LICENSE -└── Makefile -└── README.md -``` - -打开bundle.json文件,可以看到bundle已经被引入到您的工程的依赖中。 - -``` -{ -"dependencies": { - "@scope/the_bundle": "^1.0.0" - } -} -``` - -您也可以一次性在此文件中编辑多个Bundle的依赖 - -``` -{ -"dependencies": { - "@scope/the_bundle1": "^1.0.0", - "@scope/the_bundle2": "^2.0.0", - "@scope/the_bundle3": "^3.0.0", - "@scope/the_bundle4": "^1.1.0" - } -} -``` - -再执行hpm install命令,将会一次性将所有未安装的Bundle一次性全部下载并安装完成。 - -## 全局安装Bundle - -如果引用的Bundle是多个项目共用的组件(如编译工具链),你可以全局安装 - -在您的bundle工程中(工程目录中必须包含bundle.json文件)执行如下命令: - -``` -$ hpm install -g @scope/the_tool -``` - -引用的bundle将会被安装到你在hpm config中设置的globalRepo所指定的目录下: - -``` -~\.hpm\global -│ └── scope -│ └─ the_tool # <---引用的组件将会出现在这 -``` - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->- 在项目安装的Bundle,在执行hpm编译命令时可以通过引用环境变量 DEP\_SCOPE\_bundle\_name,例如: ->通过 hpm i @opensource/gn 安装后,可以编辑bundle.json中的编译脚本,如下: ->``` ->"scripts": { -> "build": "${DEP_OPENSOURCE_gn}/gn --version" -> }, ->``` ->然后就可以通过执行hpm build将调用gn的功能。 ->- 在全局安装的Bundle,可以通过设置系统环境变量,直接调用,或者hpm config set key value的方式,通过 $\{key\}/tool\_name 的方式 引用,例如: ->``` ->hpm i -g @ohos/opensource/gn ->hpm config BUILD_SYS_GN ~/.hpm/global/ohos_bundles/opensource/gn ->``` ->可以编辑bundle.json中的编译脚本,如下: ->``` ->"scripts": { -> "build": "${BUILD_SYS_GN}/gn --version" -> }, ->``` ->然后就可以通过执行hpm build将调用gn的功能。 - -## 编译Bundle - -完成代码开发后,如果Bundle的代码是可以独立编译的,可以配置编译工具和脚本以完成二进制的生成。 - -hpm具备命令集成的能力,您可以选择任意的适合项目所采用的语言编译工具(如make,gcc,gn等等)。只需在当前项目的bundle.json文件中定义scripts脚本中的build命令,就可以通过执行hpm build执行编译。 - -## 定义编译脚本 - -以编译一个app目录下helloworld可执行文件为例: - -``` -app -├── BUILD.gn -├── include -│ └── helloworld.h -└── src - └── helloworld.c -``` - -在helloworld.c同级目录下新建一个BUILD.gn - -``` -touch BUILD.gn -vim BUILD.gn -``` - -以下是BUILD.gn的样例,仅供参考 - -``` -executable("hello_world") { - sources = [ - "src/helloworld.c" - ] - - include_dirs = [ - "include" - ] -} -``` - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->- “executable”是gn内置模板,可以用“gn help executable ”查看使用方法。 ->- “sources ”是源码路径,“include\_dirs ”是头文件路径。 - -## 执行编译 - -在当前文件夹下,执行编译命令: - -``` -hpm build -``` - -在完成一系列的编译动作后,显示build succeed。检查编译的输出结果: - -![](/images/device-dev/bundles/figure/zh-cn_image_0000001188041297.png) - -## 定义发行版 - -发行版的元数据文件中定义了其依赖的Bundles,以及如何编译、链接这些bundles,生成镜像文件。 - -示例如下(以下示例的编译命令dist,采用hb编译框架描述) - -## 定义脚本 - -bundle.json中定义如下(示例) - -``` -{ -"name": "@your/dist_name", -"version": "2.2.0", -"publishAs": "distribution", -"description": "describe it", -"scripts": { -"config_hb": "hb set -root $DEP_BUNDLE_BASE", -"dist": "PATH=/root/.local/bin:${DEP_OHOS_gn}:${DEP_OHOS_ninja}/ninja:${DEP_OHOS_llvm}/llvm/bin:${DEP_OHOS_hc_gen}/hc-gen:${PATH} && ./scripts/dist.sh" -}, -"envs": { -"debug": false -}, -"dirs": { -"scripts": "scripts/*" -}, -"dependencies": { -"@ohos/build_lite": "2.2.0", -"@ohos/gn": "1.1.1", -"@ohos/llvm": "1.1.1", -"@ohos/hc_gen": "1.1.0", -"@ohos/ninja": "1.1.0", -...... -}, -"ohos": { -"os": "2.2-Beta", -"board": "hi3516", -"kernel": "liteos-a" -}, -"keywords": [ "hispark", "hi3516" ], -"repository": "https://gitee.com/openharmony/your-project", -"license": "Apache V2" -} -``` - -## 编译发行版 - -在当前发行版根目录下,执行如下命令。 - -``` -hpm dist -``` - -hpm-cli工具会自动执行编译,生成镜像文件,如: - -``` -out -|-xxdist.img -|-xx.file -``` - -## 烧录 - -发行版的编译结果可以烧录到设备中运行,例如使用hiburn工具进行烧录。在发行版的bundle.json文件配置烧录参数。 - -``` -"scripts": { - "flash": "{$DEP_HIBURN}/hiburn" -}, -``` - -设置烧录命令行工具的所在路径,配置烧录相关的参数(参考烧录工具的说明进行配置)。 - -``` -hpm config set DEP_HIBURN {hiburn_path} -hpm run flash -``` - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->上述仅描述如何定义bundle.json的样例,烧录工具取决于实际开发板所需的工具。 - diff --git "a/website/docs/01.OpenHarmony/06.\344\270\223\351\242\230/01.HPMbundle/03.\345\274\200\345\217\221\347\244\272\344\276\213/01.HPM\344\273\213\347\273\215.md" "b/website/docs/01.OpenHarmony/06.\344\270\223\351\242\230/01.HPMbundle/03.\345\274\200\345\217\221\347\244\272\344\276\213/01.HPM\344\273\213\347\273\215.md" deleted file mode 100644 index 332d4bb45f0aebff26b2a137af4e82e4f953e182..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/06.\344\270\223\351\242\230/01.HPMbundle/03.\345\274\200\345\217\221\347\244\272\344\276\213/01.HPM\344\273\213\347\273\215.md" +++ /dev/null @@ -1,17 +0,0 @@ ---- -title: HPM介绍 -permalink: /pages/0106010301 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# HPM介绍 - -HPM全称HarmonyOS Package Manager,是OpenHarmonyBundle的管理和分发工具。HPM主要是面向OpenHarmony开发者,用于获取/定制OpenHarmony源码,执行安装依赖、编译、打包、升级等操作的工具集。本文档将向开发者介绍如何使用HPM工具进行OpenHarmonyBundle的安装、编译、打包等操作。 - diff --git "a/website/docs/01.OpenHarmony/06.\344\270\223\351\242\230/01.HPMbundle/03.\345\274\200\345\217\221\347\244\272\344\276\213/02.\347\274\226\350\257\221\347\216\257\345\242\203\345\207\206\345\244\207.md" "b/website/docs/01.OpenHarmony/06.\344\270\223\351\242\230/01.HPMbundle/03.\345\274\200\345\217\221\347\244\272\344\276\213/02.\347\274\226\350\257\221\347\216\257\345\242\203\345\207\206\345\244\207.md" deleted file mode 100644 index e4678e2bca36b65b8865ce5e9abce44956612b24..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/06.\344\270\223\351\242\230/01.HPMbundle/03.\345\274\200\345\217\221\347\244\272\344\276\213/02.\347\274\226\350\257\221\347\216\257\345\242\203\345\207\206\345\244\207.md" +++ /dev/null @@ -1,148 +0,0 @@ ---- -title: 编译环境准备 -permalink: /pages/0106010302 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 编译环境准备 - -- [linux服务器](#section20979554791) -- [安装Node.js](#section9954105413153) -- [安装HPM命令行工具](#section15937194904819) -- [安装python环境](#section1621819180417) -- [安装文件打包工具](#section77617165913) -- [安装SCons](#section873135716233) - -![](/images/device-dev/bundles/figure/3516dv300.png) - -## linux服务器 - -准备一台装有Ubuntu 16.04 及以上 64 位系统的linux服务器(当前未完全支持window环境下的编译)。 - -将linux shell改为bash: - -``` -ls -l $(which sh) -# 如果指向的不是bash,则按以下方式修改: -# 方法一:执行以下命令,然后选择no -dpkg-reconfigure dash -# 方法二:先删除sh,再重新创建软连接 -rm -f /bin/sh -ln -s bash /bin/sh -``` - -## 安装Node.js - -推荐安装 Node.js 12.x (包含 npm 6.14.4)或更高版本(推荐 12.13.0+): - -``` -sudo apt-get install nodejs -sudo apt-get install npm -``` - -查看版本: - -``` -node --version # 查看nodejs版本 -npm --version # 查看npm版本 -``` - -## 安装HPM命令行工具 - -通过 Node.js 自带的 npm(使用默认的源 https://registry.npmjs.org/ )安装 hpm-cli 命令行工具: - -``` -npm install -g @ohos/hpm-cli -``` - -安装完hpm-cli命令行工具后,执行以下命令可以查看hpm配置: - -``` -hpm config -``` - -上述命令执行后将会显示hpm的默认配置,您可以根据实际情况对默认配置进行修改,以下是hpm的常用配置: - -``` -registry = https://hpm.harmonyos.com # hpm注册中心地址,下载组件必须 -strictSsl = true # 通过https连接时,是否需要校验证书 -http_proxy = http://your-proxy-server:port # 配置HTTP代理 -https_proxy = http://your-proxy-server:port # 配置HTTPS代理 -``` - -hpm-cli的命令介绍可以参考:[hpm操作命令](/pages/01060101) - -## 安装python环境 - -需使用python3.7以上版本,采用以下命令进行安装: - -``` -sudo apt-get install python3.8 -sudo apt-get install python3-pip -sudo pip3 install setuptools -sudo pip3 install kconfiglib # 建议安装kconfiglib 13.2.0+版本 -``` - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->上述方式适用Hi3518和Hi3516两种平台,针对Hi3861平台采用以下方式安装python环境: ->``` ->sudo apt-get install python3.8 ->sudo apt-get install python3-pip ->sudo pip3 install setuptools ->sudo pip3 install kconfiglib # 建议安装kconfiglib 13.2.0+版本 ->sudo pip3 install pycryptodome ->sudo pip3 install six --upgrade --ignore-installed six ->sudo pip3 install ecdsa ->``` - -如果当前系统中既存在python2又存在python3,参考以下方法将默认python修改为python3: - -``` -ll `which python` -rm /usr/bin/python -ln -s python3.8 /usr/bin/python -``` - -## 安装文件打包工具 - -采用以下命令进行安装: - -``` -which mkfs.vfat # 如果没找到,执行以下命令安装 -sudo apt-get install dosfstools -which mcopy # 如果没找到,执行以下命令安装 -sudo apt-get install mtools -``` - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->Hi3518和Hi3516两种平台需要安装打包工具,Hi3861平台不需要。 - -## 安装SCons - -1. 打开Linux编译服务器终端。 -2. 运行如下命令,安装SCons安装包。 - - ``` - python3 -m pip install scons - ``` - -3. 运行如下命令,查看是否安装成功。如果安装成功,查询结果下图所示。 - - ``` - scons -v - ``` - - **图 1** SCons安装成功界面,版本要求3.0.4以上 - ![](/images/device-dev/bundles/figure/SCons安装成功界面-版本要求3-0-4以上-27.png "SCons安装成功界面-版本要求3-0-4以上-27") - - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->Hi3861平台需要安装SCons,Hi3518和Hi3516两种平台不需要。 - diff --git "a/website/docs/01.OpenHarmony/06.\344\270\223\351\242\230/01.HPMbundle/03.\345\274\200\345\217\221\347\244\272\344\276\213/03.\346\223\215\344\275\234\345\256\236\344\276\213.md" "b/website/docs/01.OpenHarmony/06.\344\270\223\351\242\230/01.HPMbundle/03.\345\274\200\345\217\221\347\244\272\344\276\213/03.\346\223\215\344\275\234\345\256\236\344\276\213.md" deleted file mode 100644 index 74156a1342169ab7033c590efa46a9a0c52127ff..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/06.\344\270\223\351\242\230/01.HPMbundle/03.\345\274\200\345\217\221\347\244\272\344\276\213/03.\346\223\215\344\275\234\345\256\236\344\276\213.md" +++ /dev/null @@ -1,67 +0,0 @@ ---- -title: 操作实例 -permalink: /pages/0106010303 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 操作实例 - -环境准备好后,接下来本文以Hi3861平台为例,演示如何利用hpm进行发行版的安装、编译。 - -1. 执行以下命令,创建目录,并根据模板dist创建一个默认工程(目录名可自行设置): - - ``` - mkdir test3861 - cd test3861 - hpm init -t dist myproduct - ``` - - 创建成功则显示: - - ``` - Initialization finished. - ``` - -2. 安装hispark\_pegasus发行版。 - - ``` - hpm install @ohos/hispark_pegasus - ``` - - 安装成功则显示: - - ``` - Installed. - ``` - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >Hi3516平台采用下述命令: - >``` - >hpm install @ohos/hispark_taurus - >``` - >Hi3518平台采用下述命令: - >``` - >hpm install @ohos/hispark_aries - >``` - -3. 编译打包 - - ``` - hpm dist - ``` - - 编译成功会显示: - - ``` - {{name}}: distribution building completed. - ``` - -4. 上述所有命令执行成功后,在 ./out 目录下会生成编译结果,开发者可以将编译结果烧录到对应的开发板上进行测试。 - diff --git "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/01.WLAN\350\277\236\346\216\245\347\261\273\344\272\247\345\223\201/01.LED\345\244\226\350\256\276\346\216\247\345\210\266.md" "b/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/01.WLAN\350\277\236\346\216\245\347\261\273\344\272\247\345\223\201/01.LED\345\244\226\350\256\276\346\216\247\345\210\266.md" deleted file mode 100644 index d9601e730e7ee85994f015f6be491c1e1c1ec8a7..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/01.WLAN\350\277\236\346\216\245\347\261\273\344\272\247\345\223\201/01.LED\345\244\226\350\256\276\346\216\247\345\210\266.md" +++ /dev/null @@ -1,123 +0,0 @@ ---- -title: LED外设控制 -permalink: /pages/0107010101 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# LED外设控制 - -- [概述](#section14639174516337) -- [开发](#section13857170163412) -- [验证](#section1949121910344) - -## 概述 - -OpenHarmony WLAN模组基于Hi3861平台提供了丰富的外设操作能力,包含I2C、I2S、ADC、UART、SPI、SDIO、GPIO、PWM、FLASH等。本文介绍如何通过调用OpenHarmony的NDK接口,实现对GPIO控制,达到LED闪烁的效果。其他的IOT外设控制,开发者可根据API指导文档完成,此处不逐一介绍。 - -## 开发 - -1. 请先完成[《Hi3861快速入门》](/pages/01020101)。 - - LED控制参考示例存放于applications/sample/wifi-iot/app/iothardware/led\_example.c文件中。 - -2. 实现IOT外设控制,首先需要通过查阅原理图明确接线关系。经过查阅,hispark pegasus的LED与芯片的9号管脚相连。 - - ``` - #define LED_TEST_GPIO 9 - ``` - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >开发板原理图,请开发者联系Hi3861购买渠道客服获取。 - -3. 使用GPIO前,需要完成GPIO管脚初始化,明确管脚用途,并创建任务,使LED周期性亮灭,达到闪烁的效果。 - - ``` - static void LedExampleEntry(void) - { - osThreadAttr_t attr; - - /* 管脚初始化 */ - IoTGpioInit(LED_TEST_GPIO); - /* 配置9号管脚为输出方向 */ - IoTGpioSetDir(LED_TEST_GPIO, IOT_GPIO_DIR_OUT); - - attr.name = "LedTask"; - attr.attr_bits = 0U; - attr.cb_mem = NULL; - attr.cb_size = 0U; - attr.stack_mem = NULL; - attr.stack_size = LED_TASK_STACK_SIZE; - attr.priority = LED_TASK_PRIO; - - /* 启动任务 */ - if (osThreadNew((osThreadFunc_t)LedTask, NULL, &attr) == NULL) { - printf("[LedExample] Failed to create LedTask!\n"); - } - } - ``` - -4. 在循环任务中通过周期性亮灭形式实现LED闪烁。 - - ``` - static void *LedTask(const char *arg) - { - (void)arg; - while (1) { - switch (g_ledState) { - case LED_ON: - IoTGpioSetOutputVal(LED_TEST_GPIO, 1); - usleep(LED_INTERVAL_TIME_US); - break; - case LED_OFF: - IoTGpioSetOutputVal(LED_TEST_GPIO, 0); - usleep(LED_INTERVAL_TIME_US); - break; - case LED_SPARK: - IoTGpioSetOutputVal(LED_TEST_GPIO, 0); - usleep(LED_INTERVAL_TIME_US); - IoTGpioSetOutputVal(LED_TEST_GPIO, 1); - usleep(LED_INTERVAL_TIME_US); - break; - default: - usleep(LED_INTERVAL_TIME_US); - break; - } - } - return NULL; - } - ``` - -5. 在代码最下方,使用OpenHarmony启动恢复模块接口SYS\_RUN\(\)启动业务。(SYS\_RUN定义在ohos\_init.h文件中) - - ``` - SYS_RUN(LedExampleEntry); - ``` - -6. 修改applications/sample/wifi-iot/app/BUILD.gn文件,使led\_example.c参与编译。 - - ``` - import("//build/lite/config/component/lite_component.gni") - lite_component("app") { - features = [ - "iothardware:led_example" - ] - } - ``` - - -## 验证 - -编译过程请参考《[Hi3861快速入门-源码编译](/pages/010201030103)》,烧录过程请参考《[Hi3861快速入门-镜像烧录](/pages/010201030104)》。 - -完成以上两步后,按下RST键复位模组,可发现LED在周期性闪烁,与预期相符,验证完毕。 - -**图 1** LED闪烁图 -![](/images/device-dev/guide/figures/LED闪烁图.gif "LED闪烁图") - diff --git "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/01.WLAN\350\277\236\346\216\245\347\261\273\344\272\247\345\223\201/02.\351\233\206\346\210\220\344\270\211\346\226\271SDK.md" "b/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/01.WLAN\350\277\236\346\216\245\347\261\273\344\272\247\345\223\201/02.\351\233\206\346\210\220\344\270\211\346\226\271SDK.md" deleted file mode 100644 index e4de72c875d7702403737a0d5b82d78212a5a61b..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/01.WLAN\350\277\236\346\216\245\347\261\273\344\272\247\345\223\201/02.\351\233\206\346\210\220\344\270\211\346\226\271SDK.md" +++ /dev/null @@ -1,338 +0,0 @@ ---- -title: 集成三方SDK -permalink: /pages/0107010102 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 集成三方SDK - -- [规划目录结构](#section1736472718351) -- [构建业务libs](#section442815485351) -- [编写适配代码](#section3984721113613) -- [代码编写](#section830417531286) -- [脚本编写](#section13500201173710) -- [编写业务代码](#section8754114803918) -- [运行](#section7737749184012) -- [结束](#section153301392411) - -OpenHarmony致力于打造一套更加开放完善的IoT生态系统,为此OpenHarmony规划了一组目录,用于将各厂商的SDK集成到OpenHarmony中。本文档基于Hi3861开发板,向平台开发者介绍将SDK集成到OpenHarmony的方法。 - -## 规划目录结构 - -三方SDK通常由静态库和适配代码构成。SDK的业务逻辑通过硬件模组工具链编译得到静态库libs,每款模组都有其对应的libs。SDK的南向API与OpenHarmony 的API存在使用差异,该差异可通过adapter适配代码屏蔽,不同模组可共用一套adapter。 - -基于以上特征,在OpenHarmony目录结构中,可以对三方SDK目录做如下划分。 - -- 适配代码adapter,放置到domains/iot/link/ 目录下,与模组解耦。 -- 业务库libs,放置到device/hisilicon/hispark\_pegasus/sdk\_liteos/3rd\_sdk/ 目录下,与模组绑定。 - -平台开发者在适配前,务必先依次完成以下步骤,下面以demolink SDK举例,进行介绍。 - -1. 创建厂商目录,domains/iot/link/demolink/、device/hisilicon/hispark\_pegasus/sdk\_liteos/3rd\_sdk/demolink/ ,用于厂商隔离。 -2. 创建domains/iot/link/demolink/BUILD.gn ,用于构建适配代码。 -3. 创建device/hisilicon/hispark\_pegasus/sdk\_liteos/3rd\_sdk/demolink/libs/ 目录,用于存放业务库libs。 - -``` -. -├── domains -│ └── iot -│ └── link -│ ├── demolink -│ │ └── BUILD.gn -│ ├── libbuild -│ │ └── BUILD.gn -│ └── BUILD.gn -└── device - └── hisilicon - └── hispark_pegasus - └── sdk_liteos - └── 3rd_sdk - └── demolink - └── libs -``` - -## 构建业务libs - -平台SDK业务一般以静态库的形式提供,平台厂商在获取到OpenHarmony代码后,需要根据对应的硬件模组vendor,编译业务libs,并将编译结果放置在device/hisilicon/hispark\_pegasus/sdk\_liteos/3rd\_sdk/demolink/libs/ 目录下。下面介绍业务libs的构建方法。 - -OpenHarmony已规划用于编译业务libs的目录domains/iot/link/libbuild/ ,该目录中包含domains/iot/link/libbuild/BUILD.gn和domains/iot/link/BUILD.gn文件,目录结构如下。 - -``` -. -└── domains - └── iot - └── link - ├── demolink - │ └── BUILD.gn - ├── libbuild - │ └── BUILD.gn - └── BUILD.gn -``` - -平台开发者在构建libs前,务必先完成如下步骤。 - -1. 在domains/iot/link/libbuild/ 目录下放置业务源码文件,包括.c和.h文件。 - - ``` - . - └── domains - └── iot - └── link - ├── demolink - │ ├── demosdk_adapter.c - │ ├── demosdk_adapter.h - │ └── BUILD.gn - ├── libbuild - │ ├── demosdk.c - │ ├── demosdk.h - │ └── BUILD.gn - └── BUILD.gn - ``` - -2. 适配domains/iot/link/libbuild/BUILD.gn,在编译完成后还原该文件。 - - 在BUILD.gn中,sources为需要参与构建的源文件,include\_dirs为依赖的头文件路径,构建的目标结果是生成静态库libdemosdk.a。 - - ``` - static_library("demosdk") { - sources = [ - "demosdk.c" - ] - include_dirs = [ - "//domains/iot/link/libbuild", - "//domains/iot/link/demolink" - ] - } - ``` - -3. 适配domains/iot/link/BUILD.gn,在编译完成后还原该文件。 - - 此BUILD.gn文件用于指定构建条目,需要在features中填入所有需参与编译的静态库条目,使domains/iot/link/libbuild/BUILD.gn参与到构建中来。 - - ``` - import("//build/lite/config/subsystem/lite_subsystem.gni") - import("//build/lite/config/component/lite_component.gni") - lite_subsystem("iot") { - subsystem_components = [ - ":link" - ] - } - lite_component("link") { - features = [ - "libbuild:demosdk" - ] - } - ``` - - -完成以上3点后,需在代码根目录下执行命令“hb build -T //domains/iot/link:iot”,等待执行完成,检查out/hispark\_pegasus/wifiiot\_hispark\_pegasus/libs/目录下是否生成了目标库文件。 - -![](/images/device-dev/guide/figures/device-wlan-sdk-files.png) - -将库文件拷贝到device/hisilicon/hispark\_pegasus/sdk\_liteos/3rd\_sdk/demolink/libs/ 目录下,并将domains/iot/link/libbuild/ 目录中的.c和.h文件清除。 - -## 编写适配代码 - -## 代码编写 - -平台SDK中使用的API通常与OpenHarmony API存在差异,无法直接使用,需要一层适配代码adapter进行中间转换。本节以domains/iot/link/demolink/demosdk\_adapter.c中的任务创建接口DemoSdkCreateTask举例,向开发者演示如何在OpenHarmony上编写适配代码。 - -1. 查看待适配接口DemoSdkCreateTask的描述、参数、返回值。 - - ``` - struct TaskPara { - char *name; - void *(*func)(char* arg); - void *arg; - unsigned char prio; - unsigned int size; - }; - - /* - * IoT OS 创建线程接口 - * 返回值: 返回0 成功, 其他 失败 - */ - int DemoSdkCreateTask(unsigned int *handle, const struct TaskPara *para); - ``` - -2. 查看OpenHarmony API接口文档,选取一个功能类似的接口,并比对参数及用法上的差异。例如本文选取osThreadNew ,通过和DemoSdkCreateTask接口比对,可以发现两接口依赖的参数基本一致,只是参数所归属的结构体不同。 - - ``` - typedef struct { - const char *name; ///< name of the thread - uint32_t attr_bits; ///< attribute bits - void *cb_mem; ///< memory for control block - uint32_t cb_size; ///< size of provided memory for control block - void *stack_mem; ///< memory for stack - uint32_t stack_size; ///< size of stack - osPriority_t priority; ///< initial thread priority (default: osPriorityNormal) - TZ_ModuleId_t tz_module; ///< TrustZone module identifier - uint32_t reserved; ///< reserved (must be 0) - } osThreadAttr_t; - - /// Create a thread and add it to Active Threads. - /// \param[in] func thread function. - /// \param[in] argument pointer that is passed to the thread function as start argument. - /// \param[in] attr thread attributes; NULL: default values. - /// \return thread ID for reference by other functions or NULL in case of error. - osThreadId_t osThreadNew (osThreadFunc_t func, void *argument, const osThreadAttr_t *attr); - ``` - -3. 完成代码差异转换。 - - ``` - int DemoSdkCreateTask(unsigned int *handle, const struct TaskPara *para) - { - osThreadAttr_t attr = {0}; - osThreadId_t threadId; - if (handle == 0 || para == 0) { - return DEMOSDK_ERR; - } - if (para->func == 0) { - return DEMOSDK_ERR; - } - if (para->name == 0) { - return DEMOSDK_ERR; - } - attr.name = para->name; - attr.priority = para->prio; - attr.stack_size = para->size; - threadId = osThreadNew((osThreadFunc_t)para->func, para->arg, &attr); - if (threadId == 0) { - printf("osThreadNew fail\n"); - return DEMOSDK_ERR; - } - *(unsigned int *)handle = (unsigned int)threadId; - return DEMOSDK_OK; - } - ``` - - -## 脚本编写 - -开发者在完成代码适配后,还需要在adapter同级目录下新建BUILD.gn文件。该文件可在整包构建时,将适配代码编译成静态库,并链接到bin包中去。在domains/iot/link/demolink/BUILD.gn中,sources中为需要参与构建的源文件,include\_dirs中为依赖的头文件路径,构建目标结果是生产静态库libdemolinkadapter.a。 - -``` -import("//build/lite/config/component/lite_component.gni") -static_library("demolinkadapter") { - sources = [ - "demosdk_adapter.c" - ] - include_dirs = [ - "//kernel/liteos-m/kal/cmsis", - "//domains/iot/link/demolink" - ] -} -``` - -修改domains/iot/link/BUILD.gn文件,使domain/iot/hilink/BUILD.gn参与到构建系统中。 - -``` -import("//build/lite/config/subsystem/lite_subsystem.gni") -import("//build/lite/config/component/lite_component.gni") -lite_subsystem("iot") { - subsystem_components = [ - ":link" - ] -} -lite_component("link") { - features = [ - "demolink:demolinkadapter" - ] -} -``` - -## 编写业务代码 - -业务libs库和适配代码准备就绪后,还需要编写业务入口函数,调起三方SDK的业务入口。 - -下面以demolink举例,介绍如何在applications/sample/wifi-iot/app/路径下编写代码,调起demosdk的入口函数。 - -1. 目录创建 - - 开发者编写业务时,务必先在applications/sample/wifi-iot/app/ 路径下新建一个目录(或一套目录结构),用于存放业务源码文件。 - - 例如:在app下新增业务目录demolink,并在其中创建业务入口代码helloworld.c和编译构建文件BUILD.gn,如下。 - - ``` - . - └── applications - └── sample - └── wifi-iot - └── app - │── demolink - │ │── helloworld.c - │ └── BUILD.gn - └── BUILD.gn - ``` - -2. 编写业务代码。 - - 在helloworld.c文件中编写业务入口函数DemoSdkMain,并调起demolink的业务DemoSdkEntry,最后通过SYS\_RUN\(\)调用入口函数完成业务启动。 - - ``` - #include "hos_init.h" - #include "demosdk.h" - - void DemoSdkMain(void) - { - DemoSdkEntry(); - } - - SYS_RUN(DemoSdkMain); - ``` - -3. 编写构建脚本 - - 新增applications/sample/wifi-iot/app/demolink/BUILD.gn文件,指定源码和头文件路径,编译输出静态库文件libexample\_demolink.a。 - - ``` - static_library("example_demolink") { - sources = [ - "helloworld.c" - ] - include_dirs = [ - "//utils/native/lite/include", - "//domains/iot/link/libbuild" - ] - } - ``` - - 修改applications/sample/wifi-iot/app/BUILD.gn,使demolink参与编译。 - - ``` - import("//build/lite/config/component/lite_component.gni") - lite_component("app") { - features = [ - "demolink:example_demolink" - ] - } - ``` - - -## 运行 - -在代码根目录下,执行命令“hb build”编译输出版本包。最后启动运行,运行结果如图所示,与demolink预期相符。 - -``` -ready to OS start -sdk ver:Hi3861V100R001C00SPC024 2020-08-05 16:30:00 -formatting spiffs... -FileSystem mount ok. -wifi init success! -it is demosdk entry. -it is demo biz: hello world. -it is demo biz: hello world. -``` - -## 结束 - -至此,三方SDK集成已介绍完毕。 - diff --git "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/02.\346\227\240\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/01.\346\221\204\345\203\217\345\244\264\346\216\247\345\210\266/01.\346\246\202\350\277\260.md" "b/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/02.\346\227\240\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/01.\346\221\204\345\203\217\345\244\264\346\216\247\345\210\266/01.\346\246\202\350\277\260.md" deleted file mode 100644 index 3ce7b15a1575d2f7542f6a191e589b4ba6b6e32f..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/02.\346\227\240\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/01.\346\221\204\345\203\217\345\244\264\346\216\247\345\210\266/01.\346\246\202\350\277\260.md" +++ /dev/null @@ -1,23 +0,0 @@ ---- -title: 概述 -permalink: /pages/010701020101 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 概述 - -本文档将介绍如何基于IoT Camera开发板,利用开发套件中自带的摄像头,完成拍照、录像功能。 - -开发者可通过执行示例应用,对开发板的外设控制有了更深入了解后,可使用开发板完成摄像头等设备。 - -若开发者想先查看示例效果,请进入[应用实例](/pages/010701020103)。如需自定义应用行为,可参考下节“示例开发”对示例代码进行修改。 - -相机开发基本概念可参考:[相机开发概述](/pages/0105060101)。 - diff --git "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/02.\346\227\240\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/01.\346\221\204\345\203\217\345\244\264\346\216\247\345\210\266/02.\347\244\272\344\276\213\345\274\200\345\217\221/01.\346\213\215\347\205\247\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/02.\346\227\240\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/01.\346\221\204\345\203\217\345\244\264\346\216\247\345\210\266/02.\347\244\272\344\276\213\345\274\200\345\217\221/01.\346\213\215\347\205\247\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index 67d0a1babc4c7a1dab53d1aadefb4648e0e216b6..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/02.\346\227\240\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/01.\346\221\204\345\203\217\345\244\264\346\216\247\345\210\266/02.\347\244\272\344\276\213\345\274\200\345\217\221/01.\346\213\215\347\205\247\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,409 +0,0 @@ ---- -title: 拍照开发指导 -permalink: /pages/01070102010201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 拍照开发指导 - -- [使用场景](#zh-cn_topic_0000001052170554_section1963312376119) -- [接口说明](#zh-cn_topic_0000001052170554_section56549532016) -- [约束与限制](#zh-cn_topic_0000001052170554_section1165911177314) -- [开发步骤](#zh-cn_topic_0000001052170554_section138543918214) - -## 使用场景 - -使用Camera产生图片帧(拍照)。 - -## 接口说明 - -**表 1** API列表 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

类名

-

接口名

-

描述

-

CameraKit

-

int32_t GetCameraIds(std::list<string> cameraList)

-

获取cameraId列表

-

CameraKit

-

CameraAbility& GetCameraAbility(string cameraId)

-

获取指定camera的能力

-

CameraKit

-

void RegisterCameraDeviceCallback(CameraDeviceCallback* callback, EventHandler* handler)

-

注册camera设备状态回调

-

CameraKit

-

void UnregisterCameraDeviceCallback(CameraDeviceCallback* callback)

-

去注册camera设备状态回调

-

CameraKit

-

void CreateCamera(string cameraId, CameraStateCallback* callback, EventHandler* handler)

-

创建camera实例

-

Camera

-

string GetCameraId()

-

获取cameraID

-

Camera

-

CameraConfig& GetCameraConfig()

-

获取camera配置信息

-

Camera

-

FrameConfig& GetFrameConfig(int32_t type)

-

获取捕获帧类型

-

Camera

-

void Configure(CameraConfig& config)

-

配置camera

-

Camera

-

void Release()

-

释放camera

-

Camera

-

int TriggerLoopingCapture(FrameConfig& frameConfig)

-

开始循环帧捕获

-

Camera

-

void StopLoopingCapture()

-

停止循环帧捕获

-

Camera

-

int32_t TriggerSingleCapture(FrameConfig& frameConfig)

-

抓图

-

CameraConfig

-

void SetFrameStateCallback(FrameStateCallback* callback, EventHandler* handler);

-

设置帧状态回调

-

CameraConfig

-

static CameraConfig* CreateCameraConfig()

-

创建camera配置信息实例

-

CameraAbility

-

std::list<Size> GetSupportedSizes(int format)

-

根据类型获取支持输出图像尺寸大小

-

CameraAbility

-

std::list<T> GetParameterRange(uint32_t key)

-

获取支持的参数范围

-

CameraDevice

-

CameraDeviceCallback()

-

camera设备回调类构造函数

-

CameraDevice

-

void OnCameraStatus​(std::string cameraId, int32_t status)

-

camera设备状态变化时的回调

-

CameraStateCallback

-

CameraStateCallback​()

-

camera状态回调类构造函数

-

CameraStateCallback

-

void OnConfigured​(Camera& camera)

-

camera配置成功回调

-

CameraStateCallback

-

void OnConfigureFailed​(Camera& camera,int32_t errorCode)

-

camera配置失败回调

-

CameraStateCallback

-

void OnCreated​(Camera& camera)

-

camera创建成功回调

-

CameraStateCallback

-

void OnCreateFailed​(std::string cameraId,int32_t errorCode)

-

camera创建失败回调

-

CameraStateCallback

-

void OnReleased​(Camera& camera)

-

camera释放回调

-

FrameStateCallback

-

FrameStateCallback​()

-

帧状态回调类构造函数

-

FrameStateCallback

-

void OnFrameFinished(Camera& camera, FrameConfig& frameConfig, FrameResult& frameResult)

-

拍照帧完成回调

-

FrameStateCallback

-

void OnFrameError​(Camera& camera, FrameConfig& frameConfig, int32_t errorCode, FrameResult& frameResult)

-

拍照帧异常回调

-

FrameConfig

-

int32_t GetFrameConfigType()

-

获取帧配置类型

-

FrameConfig

-

std::list<OHOS::Surface> GetSurfaces()

-

获取帧配置的surface

-

FrameConfig

-

void AddSurface(OHOS::AGP::UISurface& surface);

-

添加surface

-

FrameConfig

-

void RemoveSurface(OHOS::AGP::UISurface& surface);

-

删除surface

-
- -## 约束与限制 - -无。 - -## 开发步骤 - -1. 实现设备状态回调的派生类,用户在设备状态发生变更(如新插入相机设备/相机掉线)时,自定义操作。 - - ``` - class SampleCameraDeviceCallback : public CameraDeviceCallback { - void OnCameraStatus(std::string cameraId, int32_t status) override - { - //do something when camera is available/unavailable - } - }; - ``` - -2. 实现帧事件回调的派生类,这里在拿到帧数据以后将其转存为文件。 - - ``` - static void SampleSaveCapture(const char *p, uint32_t size) - { - cout << "Start saving picture" << endl; - struct timeval tv; - gettimeofday(&tv, NULL); - struct tm *ltm = localtime(&tv.tv_sec); - if (ltm != nullptr) { - ostringstream ss("Capture_"); - ss << "Capture" << ltm->tm_hour << "-" << ltm->tm_min << "-" << ltm->tm_sec << ".jpg"; - - ofstream pic("/sdcard/" + ss.str(), ofstream::out | ofstream::trunc); - cout << "write " << size << " bytes" << endl; - pic.write(p, size); - cout << "Saving picture end" << endl; - } - } - - class TestFrameStateCallback : public FrameStateCallback { - void OnFrameFinished(Camera &camera, FrameConfig &fc, FrameResult &result) override - { - cout << "Receive frame complete inform." << endl; - if (fc.GetFrameConfigType() == FRAME_CONFIG_CAPTURE) { - cout << "Capture frame received." << endl; - list surfaceList = fc.GetSurfaces(); - for (Surface *surface : surfaceList) { - SurfaceBuffer *buffer = surface->AcquireBuffer(); - if (buffer != nullptr) { - char *virtAddr = static_cast(buffer->GetVirAddr()); - if (virtAddr != nullptr) { - SampleSaveCapture(virtAddr, buffer->GetSize()); - } - surface->ReleaseBuffer(buffer); - } - delete surface; - } - delete &fc; - } - } - }; - ``` - -3. 实现相机状态回调的派生类,自定义相机状态发生变化(配置成功/失败,创建成功/失败\)时的操作。 - - ``` - class SampleCameraStateMng : public CameraStateCallback { - public: - SampleCameraStateMng() = delete; - SampleCameraStateMng(EventHandler &eventHdlr) : eventHdlr_(eventHdlr) {} - ~SampleCameraStateMng() - { - if (recordFd_ != -1) { - close(recordFd_); - } - } - void OnCreated(Camera &c) override - { - cout << "Sample recv OnCreate camera." << endl; - auto config = CameraConfig::CreateCameraConfig(); - config->SetFrameStateCallback(&fsCb_, &eventHdlr_); - c.Configure(*config); - cam_ = &c; - } - void OnCreateFailed(const std::string cameraId, int32_t errorCode) override {} - void OnReleased(Camera &c) override {} - }; - ``` - -4. 创建CameraKit,用于创建和获取camera信息。 - - ``` - CameraKit *camKit = CameraKit::GetInstance(); - list camList = camKit->GetCameraIds(); - string camId; - for (auto &cam : camList) { - cout << "camera name:" << cam << endl; - const CameraAbility *ability = camKit->GetCameraAbility(cam); - /* find camera which fits user's ability */ - list sizeList = ability->GetSupportedSizes(0); - if (find(sizeList.begin(), sizeList.end(), CAM_PIC_1080P) != sizeList.end()) { - camId = cam; - break; - } - } - ``` - -5. 创建Camera实例。 - - ``` - EventHandler eventHdlr; // Create a thread to handle callback events - SampleCameraStateMng CamStateMng(eventHdlr); - - camKit->CreateCamera(camId, CamStateMng, eventHdlr); - ``` - -6. 根据[步骤1](#zh-cn_topic_0000001052170554_li378084192111)、[步骤2](#zh-cn_topic_0000001052170554_li8716104682913)、[步骤3](#zh-cn_topic_0000001052170554_li6671035102514)中的回调设计,同步等待 OnCreated 回调拿到 cam\_ 之后,进行相关操作。 - - ``` - void OnCreated(Camera &c) override - { - cout << "Sample recv OnCreate camera." << endl; - auto config = CameraConfig::CreateCameraConfig(); - config->SetFrameStateCallback(&fsCb_, &eventHdlr_); - c.Configure(*config); - cam_ = &c; - } - - void Capture() - { - if (cam_ == nullptr) { - cout << "Camera is not ready." << endl; - return; - } - FrameConfig *fc = new FrameConfig(FRAME_CONFIG_CAPTURE); - Surface *surface = Surface::CreateSurface(); - if (surface == nullptr) { - delete fc; - return; - } - surface->SetWidthAndHeight(1920, 1080); /* 1920:width,1080:height */ - fc->AddSurface(*surface); - cam_->TriggerSingleCapture(*fc); - } - ``` - - diff --git "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/02.\346\227\240\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/01.\346\221\204\345\203\217\345\244\264\346\216\247\345\210\266/02.\347\244\272\344\276\213\345\274\200\345\217\221/02.\345\275\225\345\203\217\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/02.\346\227\240\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/01.\346\221\204\345\203\217\345\244\264\346\216\247\345\210\266/02.\347\244\272\344\276\213\345\274\200\345\217\221/02.\345\275\225\345\203\217\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index 192084f861394f277359b9775cf27a30d7ad8dbe..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/02.\346\227\240\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/01.\346\221\204\345\203\217\345\244\264\346\216\247\345\210\266/02.\347\244\272\344\276\213\345\274\200\345\217\221/02.\345\275\225\345\203\217\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,56 +0,0 @@ ---- -title: 录像开发指导 -permalink: /pages/01070102010202 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 录像开发指导 - -- [使用场景](#zh-cn_topic_0000001051451869_section186634310418) -- [接口说明](#zh-cn_topic_0000001051451869_section125479541744) -- [约束与限制](#zh-cn_topic_0000001051451869_section1165911177314) -- [开发步骤](#zh-cn_topic_0000001051451869_section1196016315516) - -## 使用场景 - -使用camera采集视频码流。 - -## 接口说明 - -参考“拍照开发指导”的“接口说明”。 - -## 约束与限制 - -无。 - -## 开发步骤 - -1. 参考“拍照开发指导”中步骤1、步骤2、步骤3、步骤4。 -2. 获取录像FrameConfig。 - - ``` - /* 从recorder获取surface */ - Surface *surface = recorder_->GetSurface(0); - surface->SetWidthAndHeight(1920, 1080); - surface->SetQueueSize(3); - surface->SetSize(1024 * 1024); - /* 将surface配置到帧配置中 */ - FrameConfig *fc = new FrameConfig(FRAME_CONFIG_RECORD); - fc->AddSurface(*surface); - ``` - -3. 开启和停止录像。 - - ``` - stateCallback->camera_->TriggerLoopingCapture(*fc); // 开始录像 - stateCallback->camera_->StopLoopingCapture(); // 结束录像 - ``` - - diff --git "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/02.\346\227\240\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/01.\346\221\204\345\203\217\345\244\264\346\216\247\345\210\266/03.\345\272\224\347\224\250\345\256\236\344\276\213.md" "b/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/02.\346\227\240\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/01.\346\221\204\345\203\217\345\244\264\346\216\247\345\210\266/03.\345\272\224\347\224\250\345\256\236\344\276\213.md" deleted file mode 100644 index 21bfbcd871c4b352342b94225c923accb40a06c8..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/02.\346\227\240\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/01.\346\221\204\345\203\217\345\244\264\346\216\247\345\210\266/03.\345\272\224\347\224\250\345\256\236\344\276\213.md" +++ /dev/null @@ -1,58 +0,0 @@ ---- -title: 应用实例 -permalink: /pages/010701020103 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 应用实例 - -- 开发板介绍、编译烧录、运行镜像等操作请参考[Hi3518快速入门](/pages/01020101),编译结果包含示例,结果文件为out/ipcamera\_hi3518ev300/dev\_tools/bin/camera\_sample,可将文件通过读卡器复制至TF卡中,或者修改camera\_sample的编译脚本将结果文件复制至rootfs.img中。 - - 修改applications/sample/camera/media/BUILD.gn中的output\_dir。 - - - 修改前:output\_dir = "$root\_out\_dir/dev\_tools" - - 修改后:output\_dir = "$root\_out\_dir/" - - 重新执行源码仓编译并烧写入单板后,可在单板bin目录下找到camera\_sample文件。 - -- 相机示例代码为applications/sample/camera/media/camera\_sample.cpp。 - - >![](/images/device-dev/public_sys-resources/icon-notice.gif) **须知:** - >实例运行拍照和录像功能需要插入TF卡\(最大容量支持128GB\),系统启动后时自动将TF卡挂载至/sdcard目录,如果在启动后插入则需要手动挂载。查看拍照和录像内容可将TF卡中内容复制到电脑中进行查看,预览功能无需TF卡。 - - -1. 通过cd命令进入可执行程序的末端路径,启动camera\_sample,执行命令如下图。 - - **图 1** 启动示例 - ![](/images/device-dev/guide/figures/启动示例.png "启动示例") - - 运行后的控制命令如串口打印所示,按s键停止当前操作(包括录像和预览),按q键退出示例程序。 - -2. 按1进行拍照,拍照的文件格式为jpg,存储在/sdcard,文件名Capture\* - - **图 2** 输入拍照指令后串口打印日志 - ![](/images/device-dev/guide/figures/输入拍照指令后串口打印日志.png "输入拍照指令后串口打印日志") - - 若想查看保存文件,可在退出程序后进入文件系统查看,退出后重新进入请回到步骤1。 - - **图 3** 查看文件图 - ![](/images/device-dev/guide/figures/查看文件图.png "查看文件图") - -3. 按2进行录像,录像的文件格式为mp4,存储在/sdcard,文件名Record\*,按s键停止 - - **图 4** 输入录像指令后串口打印日志 - ![](/images/device-dev/guide/figures/输入录像指令后串口打印日志.png "输入录像指令后串口打印日志") - -4. 按q键退出 - - **图 5** 输出退出指令后串口打印日志 - ![](/images/device-dev/guide/figures/输出退出指令后串口打印日志.png "输出退出指令后串口打印日志") - - diff --git "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\270\246\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/01.\345\261\217\345\271\225\345\222\214\346\221\204\345\203\217\345\244\264\346\216\247\345\210\266/01.\346\246\202\350\277\260.md" "b/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\270\246\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/01.\345\261\217\345\271\225\345\222\214\346\221\204\345\203\217\345\244\264\346\216\247\345\210\266/01.\346\246\202\350\277\260.md" deleted file mode 100644 index d3ca2027bf51490c40367f47df5a834eae343a29..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\270\246\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/01.\345\261\217\345\271\225\345\222\214\346\221\204\345\203\217\345\244\264\346\216\247\345\210\266/01.\346\246\202\350\277\260.md" +++ /dev/null @@ -1,23 +0,0 @@ ---- -title: 概述 -permalink: /pages/010701030101 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 概述 - -本文档将介绍如何基于IoT Camera开发板(Hi3516DV300),利用其摄像头和屏幕,完成拍照、录像和视频预览功能。 - -通过本文档,开发者能够对OpenHarmony的摄像控制有更深入的了解,可参照本例尝试完成“智能猫眼”、“智能后视镜”、“智能带屏音箱”等设备的开发。 - -若开发者想先查看示例效果,请进入[应用实例](/pages/010701030103)。如需自定义应用行为,可参考下节“示例开发”对示例代码进行修改。 - -相机应用开发的基本概念请参考:[相机开发概述](/pages/0105060101)。 - diff --git "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\270\246\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/01.\345\261\217\345\271\225\345\222\214\346\221\204\345\203\217\345\244\264\346\216\247\345\210\266/02.\347\244\272\344\276\213\345\274\200\345\217\221/01.\346\213\215\347\205\247\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\270\246\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/01.\345\261\217\345\271\225\345\222\214\346\221\204\345\203\217\345\244\264\346\216\247\345\210\266/02.\347\244\272\344\276\213\345\274\200\345\217\221/01.\346\213\215\347\205\247\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index 75c2e969aa970aa3bb18b9c2d830959d444ba93e..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\270\246\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/01.\345\261\217\345\271\225\345\222\214\346\221\204\345\203\217\345\244\264\346\216\247\345\210\266/02.\347\244\272\344\276\213\345\274\200\345\217\221/01.\346\213\215\347\205\247\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,409 +0,0 @@ ---- -title: 拍照开发指导 -permalink: /pages/01070103010201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 拍照开发指导 - -- [使用场景](#zh-cn_topic_0000001052170554_section1963312376119) -- [接口说明](#zh-cn_topic_0000001052170554_section56549532016) -- [约束与限制](#zh-cn_topic_0000001052170554_section1165911177314) -- [开发步骤](#zh-cn_topic_0000001052170554_section138543918214) - -## 使用场景 - -使用Camera产生图片帧(拍照)。 - -## 接口说明 - -**表 1** API列表 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

类名

-

接口名

-

描述

-

CameraKit

-

int32_t GetCameraIds(std::list<string> cameraList)

-

获取cameraId列表

-

CameraKit

-

CameraAbility& GetCameraAbility(string cameraId)

-

获取指定camera的能力

-

CameraKit

-

void RegisterCameraDeviceCallback(CameraDeviceCallback* callback, EventHandler* handler)

-

注册camera设备状态回调

-

CameraKit

-

void UnregisterCameraDeviceCallback(CameraDeviceCallback* callback)

-

去注册camera设备状态回调

-

CameraKit

-

void CreateCamera(string cameraId, CameraStateCallback* callback, EventHandler* handler)

-

创建camera实例

-

Camera

-

string GetCameraId()

-

获取cameraID

-

Camera

-

CameraConfig& GetCameraConfig()

-

获取camera配置信息

-

Camera

-

FrameConfig& GetFrameConfig(int32_t type)

-

获取捕获帧类型

-

Camera

-

void Configure(CameraConfig& config)

-

配置camera

-

Camera

-

void Release()

-

释放camera

-

Camera

-

int TriggerLoopingCapture(FrameConfig& frameConfig)

-

开始循环帧捕获

-

Camera

-

void StopLoopingCapture()

-

停止循环帧捕获

-

Camera

-

int32_t TriggerSingleCapture(FrameConfig& frameConfig)

-

抓图

-

CameraConfig

-

void SetFrameStateCallback(FrameStateCallback* callback, EventHandler* handler);

-

设置帧状态回调

-

CameraConfig

-

static CameraConfig* CreateCameraConfig()

-

创建camera配置信息实例

-

CameraAbility

-

std::list<Size> GetSupportedSizes(int format)

-

根据类型获取支持输出图像尺寸大小

-

CameraAbility

-

std::list<T> GetParameterRange(uint32_t key)

-

获取支持的参数范围

-

CameraDevice

-

CameraDeviceCallback()

-

camera设备回调类构造函数

-

CameraDevice

-

void OnCameraStatus​(std::string cameraId, int32_t status)

-

camera设备状态变化时的回调

-

CameraStateCallback

-

CameraStateCallback​()

-

camera状态回调类构造函数

-

CameraStateCallback

-

void OnConfigured​(Camera& camera)

-

camera配置成功回调

-

CameraStateCallback

-

void OnConfigureFailed​(Camera& camera,int32_t errorCode)

-

camera配置失败回调

-

CameraStateCallback

-

void OnCreated​(Camera& camera)

-

camera创建成功回调

-

CameraStateCallback

-

void OnCreateFailed​(std::string cameraId,int32_t errorCode)

-

camera创建失败回调

-

CameraStateCallback

-

void OnReleased​(Camera& camera)

-

camera释放回调

-

FrameStateCallback

-

FrameStateCallback​()

-

帧状态回调类构造函数

-

FrameStateCallback

-

void OnFrameFinished(Camera& camera, FrameConfig& frameConfig, FrameResult& frameResult)

-

拍照帧完成回调

-

FrameStateCallback

-

void OnFrameError​(Camera& camera, FrameConfig& frameConfig, int32_t errorCode, FrameResult& frameResult)

-

拍照帧异常回调

-

FrameConfig

-

int32_t GetFrameConfigType()

-

获取帧配置类型

-

FrameConfig

-

std::list<OHOS::Surface> GetSurfaces()

-

获取帧配置的surface

-

FrameConfig

-

void AddSurface(OHOS::AGP::UISurface& surface);

-

添加surface

-

FrameConfig

-

void RemoveSurface(OHOS::AGP::UISurface& surface);

-

删除surface

-
- -## 约束与限制 - -无。 - -## 开发步骤 - -1. 实现设备状态回调的派生类,用户在设备状态发生变更(如新插入相机设备/相机掉线)时,自定义操作。 - - ``` - class SampleCameraDeviceCallback : public CameraDeviceCallback { - void OnCameraStatus(std::string cameraId, int32_t status) override - { - //do something when camera is available/unavailable - } - }; - ``` - -2. 实现帧事件回调的派生类,这里在拿到帧数据以后将其转存为文件。 - - ``` - static void SampleSaveCapture(const char *p, uint32_t size) - { - cout << "Start saving picture" << endl; - struct timeval tv; - gettimeofday(&tv, NULL); - struct tm *ltm = localtime(&tv.tv_sec); - if (ltm != nullptr) { - ostringstream ss("Capture_"); - ss << "Capture" << ltm->tm_hour << "-" << ltm->tm_min << "-" << ltm->tm_sec << ".jpg"; - - ofstream pic("/sdcard/" + ss.str(), ofstream::out | ofstream::trunc); - cout << "write " << size << " bytes" << endl; - pic.write(p, size); - cout << "Saving picture end" << endl; - } - } - - class TestFrameStateCallback : public FrameStateCallback { - void OnFrameFinished(Camera &camera, FrameConfig &fc, FrameResult &result) override - { - cout << "Receive frame complete inform." << endl; - if (fc.GetFrameConfigType() == FRAME_CONFIG_CAPTURE) { - cout << "Capture frame received." << endl; - list surfaceList = fc.GetSurfaces(); - for (Surface *surface : surfaceList) { - SurfaceBuffer *buffer = surface->AcquireBuffer(); - if (buffer != nullptr) { - char *virtAddr = static_cast(buffer->GetVirAddr()); - if (virtAddr != nullptr) { - SampleSaveCapture(virtAddr, buffer->GetSize()); - } - surface->ReleaseBuffer(buffer); - } - delete surface; - } - delete &fc; - } - } - }; - ``` - -3. 实现相机状态回调的派生类,自定义相机状态发生变化(配置成功/失败,创建成功/失败\)时的操作。 - - ``` - class SampleCameraStateMng : public CameraStateCallback { - public: - SampleCameraStateMng() = delete; - SampleCameraStateMng(EventHandler &eventHdlr) : eventHdlr_(eventHdlr) {} - ~SampleCameraStateMng() - { - if (recordFd_ != -1) { - close(recordFd_); - } - } - void OnCreated(Camera &c) override - { - cout << "Sample recv OnCreate camera." << endl; - auto config = CameraConfig::CreateCameraConfig(); - config->SetFrameStateCallback(&fsCb_, &eventHdlr_); - c.Configure(*config); - cam_ = &c; - } - void OnCreateFailed(const std::string cameraId, int32_t errorCode) override {} - void OnReleased(Camera &c) override {} - }; - ``` - -4. 创建CameraKit,用于创建和获取camera信息。 - - ``` - CameraKit *camKit = CameraKit::GetInstance(); - list camList = camKit->GetCameraIds(); - string camId; - for (auto &cam : camList) { - cout << "camera name:" << cam << endl; - const CameraAbility *ability = camKit->GetCameraAbility(cam); - /* find camera which fits user's ability */ - list sizeList = ability->GetSupportedSizes(0); - if (find(sizeList.begin(), sizeList.end(), CAM_PIC_1080P) != sizeList.end()) { - camId = cam; - break; - } - } - ``` - -5. 创建Camera实例。 - - ``` - EventHandler eventHdlr; // Create a thread to handle callback events - SampleCameraStateMng CamStateMng(eventHdlr); - - camKit->CreateCamera(camId, CamStateMng, eventHdlr); - ``` - -6. 根据[步骤1](#zh-cn_topic_0000001052170554_li378084192111)、[步骤2](#zh-cn_topic_0000001052170554_li8716104682913)、[步骤3](#zh-cn_topic_0000001052170554_li6671035102514)中的回调设计,同步等待 OnCreated 回调拿到 cam\_ 之后,进行相关操作。 - - ``` - void OnCreated(Camera &c) override - { - cout << "Sample recv OnCreate camera." << endl; - auto config = CameraConfig::CreateCameraConfig(); - config->SetFrameStateCallback(&fsCb_, &eventHdlr_); - c.Configure(*config); - cam_ = &c; - } - - void Capture() - { - if (cam_ == nullptr) { - cout << "Camera is not ready." << endl; - return; - } - FrameConfig *fc = new FrameConfig(FRAME_CONFIG_CAPTURE); - Surface *surface = Surface::CreateSurface(); - if (surface == nullptr) { - delete fc; - return; - } - surface->SetWidthAndHeight(1920, 1080); /* 1920:width,1080:height */ - fc->AddSurface(*surface); - cam_->TriggerSingleCapture(*fc); - } - ``` - - diff --git "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\270\246\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/01.\345\261\217\345\271\225\345\222\214\346\221\204\345\203\217\345\244\264\346\216\247\345\210\266/02.\347\244\272\344\276\213\345\274\200\345\217\221/02.\345\275\225\345\203\217\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\270\246\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/01.\345\261\217\345\271\225\345\222\214\346\221\204\345\203\217\345\244\264\346\216\247\345\210\266/02.\347\244\272\344\276\213\345\274\200\345\217\221/02.\345\275\225\345\203\217\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index ab9e18b48bfc99b7716bce32d1481baf51f59d53..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\270\246\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/01.\345\261\217\345\271\225\345\222\214\346\221\204\345\203\217\345\244\264\346\216\247\345\210\266/02.\347\244\272\344\276\213\345\274\200\345\217\221/02.\345\275\225\345\203\217\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,56 +0,0 @@ ---- -title: 录像开发指导 -permalink: /pages/01070103010202 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 录像开发指导 - -- [使用场景](#zh-cn_topic_0000001051451869_section186634310418) -- [接口说明](#zh-cn_topic_0000001051451869_section125479541744) -- [约束与限制](#zh-cn_topic_0000001051451869_section1165911177314) -- [开发步骤](#zh-cn_topic_0000001051451869_section1196016315516) - -## 使用场景 - -使用camera采集视频码流。 - -## 接口说明 - -参考“拍照开发指导”的“接口说明”。 - -## 约束与限制 - -无。 - -## 开发步骤 - -1. 参考“拍照开发指导”中步骤1、步骤2、步骤3、步骤4。 -2. 获取录像FrameConfig。 - - ``` - /* 从recorder获取surface */ - Surface *surface = recorder_->GetSurface(0); - surface->SetWidthAndHeight(1920, 1080); - surface->SetQueueSize(3); - surface->SetSize(1024 * 1024); - /* 将surface配置到帧配置中 */ - FrameConfig *fc = new FrameConfig(FRAME_CONFIG_RECORD); - fc->AddSurface(*surface); - ``` - -3. 开启和停止录像。 - - ``` - stateCallback->camera_->TriggerLoopingCapture(*fc); // 开始录像 - stateCallback->camera_->StopLoopingCapture(); // 结束录像 - ``` - - diff --git "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\270\246\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/01.\345\261\217\345\271\225\345\222\214\346\221\204\345\203\217\345\244\264\346\216\247\345\210\266/02.\347\244\272\344\276\213\345\274\200\345\217\221/03.\351\242\204\350\247\210\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\270\246\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/01.\345\261\217\345\271\225\345\222\214\346\221\204\345\203\217\345\244\264\346\216\247\345\210\266/02.\347\244\272\344\276\213\345\274\200\345\217\221/03.\351\242\204\350\247\210\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index 828766a7ea555635d1eecbdf12befa1a5edbffcd..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\270\246\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/01.\345\261\217\345\271\225\345\222\214\346\221\204\345\203\217\345\244\264\346\216\247\345\210\266/02.\347\244\272\344\276\213\345\274\200\345\217\221/03.\351\242\204\350\247\210\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,56 +0,0 @@ ---- -title: 预览开发指导 -permalink: /pages/01070103010203 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:25 ---- -# 预览开发指导 - -- [使用场景](#zh-cn_topic_0000001051930577_section186634310418) -- [接口说明](#zh-cn_topic_0000001051930577_section125479541744) -- [约束与限制](#zh-cn_topic_0000001051930577_section1165911177314) -- [开发步骤](#zh-cn_topic_0000001051930577_section34171333656) - -## 使用场景 - -使用camera产生视频流并播放。 - -## 接口说明 - -参考“拍照开发指导”的“接口说明”。 - -## 约束与限制 - -无。 - -## 开发步骤 - -1. 参考“拍照开发指导”中步骤1、步骤2、步骤3、步骤4。 -2. 设置预览显示的区域。 - - ``` - Surface *surface = Surface::CreateSurface(); - /* 设置显示区域 */ - surface->SetUserData("region_position_x", "480"); // 矩形左上角横坐标 - surface->SetUserData("region_position_y", "270"); // 矩形左上角纵坐标 - surface->SetUserData("region_width", "960"); // 宽 - surface->SetUserData("region_height", "540"); // 高 - - fc->AddSurface(*surface); - ``` - -3. 开始和结束预览。 - - ``` - stateCallback->camera_->TriggerLoopingCapture(*fc); // start previewing - stateCallback->camera_->StopLoopingCapture(); // stop previewing - ``` - - diff --git "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\270\246\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/01.\345\261\217\345\271\225\345\222\214\346\221\204\345\203\217\345\244\264\346\216\247\345\210\266/03.\345\272\224\347\224\250\345\256\236\344\276\213.md" "b/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\270\246\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/01.\345\261\217\345\271\225\345\222\214\346\221\204\345\203\217\345\244\264\346\216\247\345\210\266/03.\345\272\224\347\224\250\345\256\236\344\276\213.md" deleted file mode 100644 index 60e8fb1f3e92a7f68cdefbcdab77de981dd4dee5..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\270\246\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/01.\345\261\217\345\271\225\345\222\214\346\221\204\345\203\217\345\244\264\346\216\247\345\210\266/03.\345\272\224\347\224\250\345\256\236\344\276\213.md" +++ /dev/null @@ -1,76 +0,0 @@ ---- -title: 应用实例 -permalink: /pages/010701030103 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:26 ---- -# 应用实例 - -本示例将运行源码中的camera示例代码,通过本示例可以实现使用开发板进行拍照、录像及预览等功能。 - -- 本示例源码路径为“applications/sample/camera/media/camera\_sample.cpp”。 -- 在运行本示例前需先完成编译烧录、运行镜像等步骤,相关操作请参考[Hi3516快速入门](/pages/01020101)。 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >开发板启动后默认会加载launcher应用,应用的图形界面默认显示在媒体图层上方,会影响camera\_sample的演示结果,因此需要在编译或是打包时去掉launcher应用。 - >**修改方法**:将“build/lite/components/applications.json”中camera\_sample\_app组件的targets中"//applications/sample/camera/launcher:launcher\_hap"整行注释或删除。 - -- 本示例编译结果路径为“out/hi3516dv300/ipcamera\_hi3516dv300\_liteos/dev\_tools/bin”,为让文件能在单板中执行,可将示例文件通过读卡器复制至TF卡中,或者修改camera\_sample的编译脚本将结果文件复制至rootfs.img中。 - - 修改源码路径“applications/sample/camera/media/BUILD.gn”中第一处的output\_dir。 - - - 修改前:output\_dir = "$root\_out\_dir/dev\_ools" - - 修改后:output\_dir = "$root\_out\_dir/" - - 重新执行源码仓编译并烧写入单板后,可在单板bin目录下找到camera\_sample文件。 - - >![](/images/device-dev/public_sys-resources/icon-notice.gif) **须知:** - >实例运行拍照和录像功能需要插入TF卡\(最大容量支持128GB\),系统启动后自动将TF卡挂载至/sdcard目录,如果在启动后插入则需要手动挂载。查看拍照和录像内容可将TF卡中内容复制到电脑中进行查看,预览功能无需TF卡。 - -- 接下来可通过以下步骤运行示例: - -1. 通过cd命令进入可执行程序的末端路径,启动camera\_sample,执行命令如下图。 - - **图 1** 启动示例 - ![](/images/device-dev/guide/figures/启动示例.png "启动示例") - - 运行后的控制命令如串口打印所示,按s键停止当前操作(包括录像和预览),按q键退出示例程序。 - -2. 按1进行拍照,拍照的文件格式为jpg,存储在/sdcard,文件名Capture\* - - **图 2** 输入拍照指令后串口打印日志 - ![](/images/device-dev/guide/figures/输入拍照指令后串口打印日志.png "输入拍照指令后串口打印日志") - - 若想查看保存文件,可在退出程序后进入文件系统查看,退出后重新进入请回到步骤1。 - - **图 3** 查看文件图 - ![](/images/device-dev/guide/figures/查看文件图.png "查看文件图") - -3. 按2进行录像,录像的文件格式为mp4,存储在/sdcard,文件名Record\*,按s键停止 - - **图 4** 输入录像指令后串口打印日志 - ![](/images/device-dev/guide/figures/输入录像指令后串口打印日志.png "输入录像指令后串口打印日志") - -4. 按3进行预览,预览图像直接送至显示屏,按s键停止。 - - **图 5** 输入预览指令后串口打印日志 - ![](/images/device-dev/guide/figures/输入预览指令后串口打印日志.png "输入预览指令后串口打印日志") - - 预览效果如下 - - **图 6** 预览效果 - ![](/images/device-dev/guide/figures/预览效果.jpg "预览效果") - -5. 按q键退出 - - **图 7** 输出退出指令后串口打印日志 - ![](/images/device-dev/guide/figures/输出退出指令后串口打印日志.png "输出退出指令后串口打印日志") - - diff --git "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\270\246\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/02.\350\247\206\350\247\211\345\272\224\347\224\250\345\274\200\345\217\221/01.\346\246\202\350\277\260.md" "b/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\270\246\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/02.\350\247\206\350\247\211\345\272\224\347\224\250\345\274\200\345\217\221/01.\346\246\202\350\277\260.md" deleted file mode 100644 index 706263e8ef45672f51ed4bc56da84e83c9264e57..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\270\246\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/02.\350\247\206\350\247\211\345\272\224\347\224\250\345\274\200\345\217\221/01.\346\246\202\350\277\260.md" +++ /dev/null @@ -1,26 +0,0 @@ ---- -title: 概述 -permalink: /pages/010701030201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:26 ---- -# 概述 - -- [效果展示](#section3997224182313) - -本文将介绍如何快速搭建基于OpenHarmony系统的行车记录仪(Hi3516DV300开发板)应用开发环境,并基于一个简易的APP示例逐步展示应用的创建、开发、调试和安装等流程。接下来本文以空气质量监测(AirQuality)App为例进行说明。 - -## 效果展示 - -空气质量监测App是一款展示城市空气质量信息的应用,有两个页面组成:首页和详情页,在DevEco Studio模拟器中的显示效果如下图所示: - -**图 1** 空气质量监测 App显示效果图 -![](/images/device-dev/guide/figures/空气质量监测-App显示效果图.gif "空气质量监测-App显示效果图") - diff --git "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\270\246\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/02.\350\247\206\350\247\211\345\272\224\347\224\250\345\274\200\345\217\221/02.\345\274\200\345\217\221\345\207\206\345\244\207.md" "b/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\270\246\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/02.\350\247\206\350\247\211\345\272\224\347\224\250\345\274\200\345\217\221/02.\345\274\200\345\217\221\345\207\206\345\244\207.md" deleted file mode 100644 index 59940ffc1213d5e19d09d3d0f867fb935cb223b6..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\270\246\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/02.\350\247\206\350\247\211\345\272\224\347\224\250\345\274\200\345\217\221/02.\345\274\200\345\217\221\345\207\206\345\244\207.md" +++ /dev/null @@ -1,40 +0,0 @@ ---- -title: 开发准备 -permalink: /pages/010701030202 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:26 ---- -# 开发准备 - -- [准备开发环境](#section1912530122716) -- [创建项目](#section1456035192720) - -## 准备开发环境 - -首先需要下载和配置DevEco Studio,具体操作请参考[《DevEco Studio使用指南》](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/software_install-0000001053582415)。 - -## 创建项目 - -1. 通过如下两种方式,打开工程创建向导界面。 - - 如果当前未打开任何工程,可以在DevEco Studio的欢迎页,选择**Create HarmonyOS Project**开始创建一个新工程。 - - 如果已经打开了工程,可以在菜单栏选择**File \> New \> New Project**来创建一个新工程。 - -2. 选择“Smart Vision”下的“Empty Feature Ability”模板。 - - ![](/images/device-dev/guide/figures/empty-feature-ability.png) - -3. 点击**Next**,进入到工程配置阶段,需要根据向导配置工程的基本信息。 - - **Project Name**:工程的名称,可以自定义。 - - **Package Name**:软件包名称,默认情况下,应用ID也会使用该名称,应用发布时,应用ID需要唯一。 - - **Save Location**:工程文件本地存储路径,存储路径中不能包含中文字符和空格。 - - **Compatible API Version**:兼容的SDK版本。 - -4. 点击**Finish**,工具会自动生成示例代码和相关资源,等待工程创建完成。 - diff --git "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\270\246\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/02.\350\247\206\350\247\211\345\272\224\347\224\250\345\274\200\345\217\221/03.\346\267\273\345\212\240\351\241\265\351\235\242.md" "b/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\270\246\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/02.\350\247\206\350\247\211\345\272\224\347\224\250\345\274\200\345\217\221/03.\346\267\273\345\212\240\351\241\265\351\235\242.md" deleted file mode 100644 index ddb354acbeb423bf32585bda92cfd8fbaffde3e5..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\270\246\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/02.\350\247\206\350\247\211\345\272\224\347\224\250\345\274\200\345\217\221/03.\346\267\273\345\212\240\351\241\265\351\235\242.md" +++ /dev/null @@ -1,47 +0,0 @@ ---- -title: 添加页面 -permalink: /pages/010701030203 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:26 ---- -# 添加页面 - -- [创建首页面](#section16935511143715) -- [创建详情页](#section122131729173819) - -## 创建首页面 - -空气质量监测App包含两个界面(Page),工程创建完成后会生成一个名为index的Page,可以作为首页。工程目录如下图所示: - -**图 1** 工程目录 -![](/images/device-dev/guide/figures/工程目录.png "工程目录") - -## 创建详情页 - -新增一个Page,作为详情页,具体步骤如下: - -1. pages目录右键 ,弹出的菜单中选择New、JS Page。 - - **图 2** 添加页面 - ![](/images/device-dev/guide/figures/添加页面.png "添加页面") - -2. 输入Page名称。 - - **图 3** 输入页面名称 - ![](/images/device-dev/guide/figures/输入页面名称.png "输入页面名称") - -3. 确认创建结果。 - - 详情页创建完成后应用工程目录如下图所示,每个Page包括三个文件:布局文件hml、样式文件css、业务逻辑代码js。 - - **图 4** 完整工程目录 - ![](/images/device-dev/guide/figures/完整工程目录.png "完整工程目录") - - diff --git "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\270\246\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/02.\350\247\206\350\247\211\345\272\224\347\224\250\345\274\200\345\217\221/04.\345\274\200\345\217\221\351\246\226\351\241\265.md" "b/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\270\246\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/02.\350\247\206\350\247\211\345\272\224\347\224\250\345\274\200\345\217\221/04.\345\274\200\345\217\221\351\246\226\351\241\265.md" deleted file mode 100644 index ad9e51f7e9d5416a85ad2eab7c164cdb249a909b..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\270\246\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/02.\350\247\206\350\247\211\345\272\224\347\224\250\345\274\200\345\217\221/04.\345\274\200\345\217\221\351\246\226\351\241\265.md" +++ /dev/null @@ -1,592 +0,0 @@ ---- -title: 开发首页 -permalink: /pages/010701030204 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:26 ---- -# 开发首页 - -应用首页主要展示城市的空气质量概况。首页总共有两屏(可以根据需求设置多屏),每屏显示一个城市的空气质量信息:主要包括AQI指数、城市名称、污染物指数、更新时间和信息来源等数据。 - -从第一章节中的[显示效果图](/pages/010701030201)分析可知,首页由三部分组成: - -- 标题栏:位于页面正上方,位置固定,包括应用退出按钮和页面标题。 -- 信息栏:主要展示城市的空气信息指标等内容;该页面根据用户需求可设置多屏,且能循环滑动。 -- 页面位置指示器:主要功能是标识当前页面,位置固定在页面底部的中间。 - -综上,我们可搭建一个纵向三行排列的弹性页面布局来实现首页的功能。 - -1. 在hml文件中添加一个根节点div,注意每个hml文件中有且只能有一个根节点,代码如下: - - ``` -
-
- ``` - - class="container"表示组件使用的样式,container是index.css文件中的一个样式类,代码如下: - - ``` - .container { - flex-direction: column; - height: 480px; - width: 960px; - } - ``` - - 在这个样式类中,我们分别设置了根组件div的高度和宽度(注意在应用的开发过程中,除部分组件(text)外必须显式指定组件的高度和宽度,否则可能无法显示)、并将flex-direction属性设置为column,该属性表示div的子组件是垂直方向从上到下排列;这样就可以实现本节开头所说的纵向三行排列的弹性页面布局。 - -2. 实现标题栏:标题栏包括一个退出按钮和一个标题,两个控件是横向排列;首先添加一个div,并设置flex-direction的属性为row,表示子组件是水平方向从左往右排列;然后依次添加一个image和text组件,代码如下: - - ``` -
-
- - - 空气质量 - -
-
- ``` - - 设置组件的高度、边距、颜色等属性。 - - ``` - .header { - width: 960px; - height: 72px; - } - .back { - width: 36px; - height: 36px; - margin-left: 39px; - margin-top: 23px; - } - .title { - width: 296px; - height: 40px; - margin-top: 20px; - margin-left: 21px; - color: #e6e6e6; - } - ``` - - onclick="exitApp" 设置了div组件的click事件,当在标题栏上触发点击事件时,就会执行函数exitApp,该函数位于index.js文件中,代码如下: - - ``` - exitApp() { - console.log('start exit'); - app.terminate(); - console.log('end exit'); - } - ``` - - app.terminate\(\)函数实现了程序退出功能;在使用该函数前,需要引入app模块,在js文件的最上方写如下代码: - - ``` - import app from '@system.app' - ``` - - 代码编写完成后,在模拟器中运行项目,显示效果如下图所示: - - **图 1** 标题栏效果 - ![](/images/device-dev/guide/figures/标题栏效果.png "标题栏效果") - -3. 实现城市空气质量信息的多屏左右滑动,需要使用“swiper”组件。 - - 在根节点中添加一个子节点swiper,代码片段如下: - - ``` -
-
- - - 空气质量 - -
- - -
- ``` - - - class="swiper"设置了组件的高度和宽度,代码如下: - - ``` - .swiper { - height: 385px; - width: 960px; - } - ``` - - - index="\{\{swiperPage\}\}" duration="500" onchange="swiperChange" 这些代码用来设置组件的属性和事件。其中,duration="500" 表示设置swiper的页面滑动的动画时长为500ms。 - - index="\{\{swiperPage\}\}"设置了swiper子组件索引值,\{\{swiperPage\}\}这种写法表示index的值是和js代码中的swiperPage变量动态绑定的,index的值会随着swiperPage变动而改变。 - - onchange="swiperChange" 设置了swiper组件的change事件和函数swiperChange绑定,对应的js代码如下: - - ``` - //引入router模块,用户页面跳转 - import router from'@system.router' - import app from '@system.app' - - export default { - //定义参数 - data: { - //默认是第一页 - swiperPage: 0 - }, - onInit () { - }, - exitApp(){ - console.log('start exit'); - app.terminate(); - console.log('end exit'); - }, - //swiper滑动回调事件,保存当前swiper的index值,每次滑动都会将index值保存在swiperPage变量中 - swiperChange (e) { - this.swiperPage = e.index; - } - } - ``` - -4. 设置一个城市的空气质量信息为一屏,在一屏内,要展示多种信息,分别使用不同的控件进行展示。 - - 在swiper中添加两个子组件stack(绝对布局),每个stack组件内分别添加text、image、progress等组件来显示对应的信息 ,页面结构如下: - - ``` - - - - ------空气质量 - ------城市名称 - -----进度条 - -------云朵图片 - --------AQI数值 - AQI------AQI -
--------空气指标详细信息 -
-
--------更新时间和网站等信息 -
-
- - - - - - - - -
-
-
- ``` - - 代码编写完成后,模拟器运行效果如下: - - **图 2** 标题栏和信息栏效果 - ![](/images/device-dev/guide/figures/标题栏和信息栏效果.png "标题栏和信息栏效果") - -5. 添加页面位置指示器:由于当前swiper不支持设置indicator,需要开发者自己来实现该效果。在根节点中添加一个子组件div,并设置相应样式;然后在该div中添加两个子组件div,设置两个div的border-radius,并在swiper滑动事件中动态改变对应div的背景色来实现该效果。 - - ``` -
-
-
-
- ``` - - **图 3** 页面位置指示器效果图 - ![](/images/device-dev/guide/figures/页面位置指示器效果图.png "页面位置指示器效果图") - -6. 所有组件设置样式、动画效果和数据动态绑定,完整代码如下所示: - - - **index.hml文件** - - ``` -
-
- - - 空气质量 - -
- - - {{airData[0].airQuality}} - - {{airData[0].location}} - - - - {{airData[0].detailData}} - - - AQI - -
-
- - CO - - - 100 - -
-
- - NO2 - - - 90 - -
-
- - PM10 - - - 120 - -
-
- - PM2.5 - - - 40 - -
-
- - SO2 - - - 150 - -
- -
- -
- - {{airData[1].airQuality}} - - {{airData[1].location}} - - - - {{airData[1].detailData}} - - - AQI - -
-
- - CO - - - 10 - -
-
- - NO2 - - - 50 - -
-
- - PM10 - - - 60 - -
-
- - PM2.5 - - - 40 - -
-
- - SO2 - - - 150 - -
- -
- -
-
-
-
-
-
-
- ``` - - - **index.css文件** - - css文件中定义了许多class,每个class用于定义组件的位置、大小、字体、颜色、背景色等信息。同时,每一个子组件都叠加在父组件中,父组件的样式会影响子组件的呈现。 - - ``` - .aqi-value { - text-align: center; - font-size: 65px; - color: #f0ffff; - width: 156px; - height: 92px; - top: 134px; - left: 210px; - } - .aqi { - text-align: center; - color: #a2c4a2; - width: 156px; - height: 45px; - top: 90px; - left: 210px; - } - .airquality { - top: 222px; - text-align: center; - width: 156px; - height: 45px; - left: 210px; - } - .image { - top: 285px; - left: 274px; - width: 32px; - height: 32px; - } - .location-text { - text-align: center; - color: #ffffff; - width: 200px; - height: 52px; - font-size: 40px; - left: 380px; - top: 16px; - } - .container { - flex-direction: column; - height: 480px; - width: 960px; - } - .circle-progress { - center-x: 128px; - center-y: 128px; - radius: 128px; - startAngle: 198; - totalAngle: 320; - strokeWidth: 24px; - width: 256px; - height: 256px; - left: 160px; - top: 58px; - } - .detail { - width: 256px; - height: 265px; - left: 544px; - top: 58px; - flex-direction: column; - } - .text-wrapper { - width: 256px; - height: 35px; - margin-top: 6px; - } - .gas-name { - width: 128px; - height: 35px; - text-align: left; - } - .gas-value { - width: 128px; - height: 35px; - text-align: right; - } - .btn { - width: 180px; - height: 50px; - margin-top: 6px; - margin-left: 38px; - background-color: #1a1a1a; - color: #1085CE; - } - .footer { - top: 326px; - width: 960px; - height: 28px; - } - .header { - width: 960px; - height: 72px; - } - .back { - width: 36px; - height: 36px; - margin-left: 39px; - margin-top: 23px; - } - .title { - width: 296px; - height: 40px; - margin-top: 20px; - margin-left: 21px; - color: #e6e6e6; - } - .swiper { - height: 385px; - width: 960px; - } - .images { - width: 60px; - height: 15px; - margin-left: 450px; - } - .update-time { - width: 480px; - height: 28px; - font-size: 20px; - color: #A9A9A9; - text-align: right; - } - .info-source { - width: 450px; - height: 28px; - font-size: 20px; - color: #A9A9A9; - text-align: left; - margin-left: 24px; - } - .circle-div { - width: 12px; - height: 12px; - border-radius: 6px; - } - ``` - - - **index.js:** - - js文件主要用于实现App应用的逻辑交互。在本页面js文件中,需要实现如下功能:根据数值动态改变文字、进度条颜色、页面跳转。 - - ``` - //导入router和app模块 - import router from '@system.router' - import app from '@system.app' - - export default { - data: { - //页面绑定数据 - textColor1: '#00ff00', - textColor2: '#00ff00', - bgColor1: '#669966', - bgColor2: '#669966', - swiperPage: 0, - percent1: 40, - percent2: 90, - iconUncheckedColor: '#262626', - iconcheckedColor: '#ffffff', - iconcheckedBR: '6px', - src1: 'common/cloud_green.png', - src2: 'common/cloud_green.png', - airData: [{ - location: '东莞', - airQuality: '良', - detailData: 40 - }, { - location: '深圳', - airQuality: '差', - detailData: 90 - }] - }, - onInit () { - //根据数值的不同,设置不同的字体、背景颜色和图片 - if(this.airData[0].detailData > 100){ - this.src1 = 'common/cloud_red.png'; - this.textColor1 = '#ff0000'; - this.bgColor1 = '#9d7462'; - } else if(50 < this.airData[0].detailData && this.airData[0].detailData <= 100){ - this.src1 = 'common/cloud_yellow.png'; - this.textColor1 = '#ecf19a'; - this.bgColor1 = '#9d9d62'; - } - if(this.airData[1].detailData > 100){ - this.src2 = 'common/cloud_red.png'; - this.textColor2 = '#ff0000'; - this.bgColor2 = '#9d7462'; - } else if(50 < this.airData[1].detailData && this.airData[1].detailData <= 100){ - this.src2 = 'common/cloud_yellow.png'; - this.textColor2 = '#ecf19a'; - this.bgColor2 = '#9d9d62'; - } - if(this.selectedCityIndex){ - this.swiperPage = this.selectedCityIndex; - if(this.swiperPage == 0){ - this.iconcheckedColor = '#ffffff'; - this.iconUncheckedColor = '#262626'; - }else{ - this.iconcheckedColor = '#262626'; - this.iconUncheckedColor = '#ffffff'; - } - } - }, - //跳转到详情页面 - openDetail () { - router.replace({ - uri: 'pages/detail/detail', - params: {selectedCityIndex:this.swiperPage} - }); - }, - //退出应用 - exitApp(){ - console.log('start exit'); - app.terminate(); - console.log('end exit'); - }, - //页面滑动事件,滑动时改变最新的标识 - swiperChange (e) { - this.swiperPage = e.index; - if(e.index == 0){ - this.iconcheckedColor = '#ffffff'; - this.iconUncheckedColor = '#262626'; - }else{ - this.iconcheckedColor = '#262626'; - this.iconUncheckedColor = '#ffffff'; - } - } - } - ``` - - diff --git "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\270\246\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/02.\350\247\206\350\247\211\345\272\224\347\224\250\345\274\200\345\217\221/05.\345\274\200\345\217\221\350\257\246\346\203\205\351\241\265.md" "b/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\270\246\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/02.\350\247\206\350\247\211\345\272\224\347\224\250\345\274\200\345\217\221/05.\345\274\200\345\217\221\350\257\246\346\203\205\351\241\265.md" deleted file mode 100644 index a283e50d13563308aeda53f5dffc7e8ce9de14bc..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\270\246\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/02.\350\247\206\350\247\211\345\272\224\347\224\250\345\274\200\345\217\221/05.\345\274\200\345\217\221\350\257\246\346\203\205\351\241\265.md" +++ /dev/null @@ -1,409 +0,0 @@ ---- -title: 开发详情页 -permalink: /pages/010701030205 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:26 ---- -# 开发详情页 - -- [detail.hml](#section275215487291) -- [detail.css](#section2589154215301) -- [detail.js](#section163410883117) - -详情页以图表的形式展示一周内空气质量指标值。本页面由两部分组成:标题栏和图表栏;在图表栏,考虑显示效果,我们使用多个div替代chart组件来实现图表功能。 - -首先,添加一个根节点div,并设置flex-direction属性为column,使两栏纵向排列,代码结构如下: - -``` -
-
- - - 历史记录 - -
- - -
-``` - -其中onclick="backMain"为返回主页事件,detail.js中的代码实现如下: - -``` -import router from '@system.router' - -export default { - backMain() { - router.replace({ - //页面地址 - uri: 'pages/index/index', - params: { - //返回主页时带的参数 - selectedCityIndex: this.selectedCityIndex - } - }); - } -} -``` - -其次,在list中添加div组件来实现图表效果。 - -详情页完整代码如下: - -## detail.hml - -``` -
-
- - - 历史记录 - -
- - - {{location}} - - - -
-
- - CO - -
-
-
-
-
-
-
-
-
-
-
- - MON - - - TUE - - - WED - - - THU - - - FRI - - - SAT - - - SUN - -
-
-
- - SO2 - -
-
-
-
-
-
-
-
-
-
-
- - MON - - - TUE - - - WED - - - THU - - - FRI - - - SAT - - - SUN - -
-
-
-
- -
-
- - PM10 - -
-
-
-
-
-
-
-
-
-
-
- - MON - - - TUE - - - WED - - - THU - - - FRI - - - SAT - - - SUN - -
-
-
- - PM2.5 - -
-
-
-
-
-
-
-
-
-
-
- - MON - - - TUE - - - WED - - - THU - - - FRI - - - SAT - - - SUN - -
-
-
-
- -
-
- - NO2 - -
-
-
-
-
-
-
-
-
-
-
- - MON - - - TUE - - - WED - - - THU - - - FRI - - - SAT - - - SUN - -
-
-
-
-
-
-``` - -## detail.css - -``` -.location { - text-align: center; - color: #ffffff; - width: 960px; - height: 52px; - font-size: 40px; -} -.container { - height: 480px; - width: 960px; - flex-direction: column; -} - -.header { - width: 960px; - height: 72px; -} - -.back { - width: 36px; - height: 36px; - margin-left: 39px; - margin-top: 23px; -} - -.title { - width: 296px; - height: 40px; - margin-top: 20px; - margin-left: 21px; - color: #e6e6e6; -} - -.chart-list { - width: 960px; - height: 408px; -} - -.list-item-title { - width: 960px; - height: 52px; -} - -.list-item-chart { - width: 960px; - height: 280px; -} - -.chart-wrapper { - width: 308px; - height: 256px; - flex-direction: column; -} - -.gas-name { - width: 308px; - height: 35px; - text-align: left; -} - -.chart { - width: 308px; - height: 155px; - margin-top: 10px; - justify-content: flex-start; - align-items: flex-end; -} - -.chart-item { - width: 24px; - margin-left: 18px; - border-radius: 3px; -} - -.white-line { - width: 308px; - height: 2px; - background-color: #ffffff; - margin-top: 22px; -} - -.week { - width: 308px; - height: 17px; - margin-top: 6px; - border-color: #ffffff; - border-radius: 2px; - margin-top: 6px; -} - -.day { - width: 26px; - height: 17px; - font-size: 10px; - margin-left: 16px; - text-align: center; -} -``` - -## detail.js - -``` -import router from '@system.router' - -export default { - data: { - location: '' - }, - onInit() { - if (this.selectedCityIndex === 0) { - this.location = '东莞'; - } else { - this.location = '深圳'; - } - }, - backMain() { - router.replace({ - uri: 'pages/index/index', - params: { - selectedCityIndex: this.selectedCityIndex - } - }); - } -} -``` - diff --git "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\270\246\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/02.\350\247\206\350\247\211\345\272\224\347\224\250\345\274\200\345\217\221/06.\350\260\203\350\257\225\346\211\223\345\214\205.md" "b/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\270\246\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/02.\350\247\206\350\247\211\345\272\224\347\224\250\345\274\200\345\217\221/06.\350\260\203\350\257\225\346\211\223\345\214\205.md" deleted file mode 100644 index c5bdf4885d2baa745cbeb6917245588deaf24bd6..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\270\246\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/02.\350\247\206\350\247\211\345\272\224\347\224\250\345\274\200\345\217\221/06.\350\260\203\350\257\225\346\211\223\345\214\205.md" +++ /dev/null @@ -1,17 +0,0 @@ ---- -title: 调试打包 -permalink: /pages/010701030206 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:26 ---- -# 调试打包 - -代码编写完成后,可以进行调试和打包;应用调试及打包方法可以参考[《DevEco Studio使用指南》](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/tools_overview-0000001053582387)的[应用调测](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404)和[编译构建](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/build_overview-0000001055075201)章节。IPCamera应用暂时不支持签名模式,所以需要将应用发布为未签名的应用安装包。 - diff --git "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\270\246\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/02.\350\247\206\350\247\211\345\272\224\347\224\250\345\274\200\345\217\221/07.\347\234\237\346\234\272\350\277\220\350\241\214.md" "b/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\270\246\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/02.\350\247\206\350\247\211\345\272\224\347\224\250\345\274\200\345\217\221/07.\347\234\237\346\234\272\350\277\220\350\241\214.md" deleted file mode 100644 index 7fe00483676ac491752ee27824411f6116592e96..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\270\246\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/02.\350\247\206\350\247\211\345\272\224\347\224\250\345\274\200\345\217\221/07.\347\234\237\346\234\272\350\277\220\350\241\214.md" +++ /dev/null @@ -1,42 +0,0 @@ ---- -title: 真机运行 -permalink: /pages/010701030207 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:26 ---- -# 真机运行 - -应用编译打包后即可安装到开发板。安装应用前需要先完成[DevEco Device Tool的安装配置](https://device.harmonyos.com/cn/docs/ide/user-guides/service_introduction-0000001050166905),然后将OpenHarmony烧录到开发板并运行。编译烧录、运行镜像的基本操作请参考快速入门手册:[Hi3516快速入门](/pages/01020101)。完成镜像运行,系统正常启动后,执行如下步骤安装或卸载三方应用。 - -1. 将IDE编译的未签名应用安装包和安装工具(镜像文件生成目录中的dev\_tools)放在sdcard中,将sdcard插入开发板卡槽。 -2. 应用安装默认要校验签名,需要执行以下命令,关闭签名校验。 - - ``` - ./sdcard/dev_tools/bin/bm set -s disable - ``` - -3. 执行以下命令,安装应用。 - - ``` - ./sdcard/dev_tools/bin/bm install -p /sdcard/airquality.hap - ``` - - 其中dev\_tools目录中是安装工具,airquality.hap为应用安装包,此处替换为实际工程的安装包名称。 - -4. 应用安装完成后,可点击桌面应用图标启动应用,进行操作。 - - **图 1** 桌面 - ![](/images/device-dev/guide/figures/桌面.png "桌面") - -5. 卸载应用(可选)。 - - 长按桌面应用图标,在弹出的菜单中点击“卸载”按钮即可卸载应用。 - - diff --git "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\270\246\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/02.\350\247\206\350\247\211\345\272\224\347\224\250\345\274\200\345\217\221/08.\345\270\270\350\247\201\351\227\256\351\242\230.md" "b/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\270\246\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/02.\350\247\206\350\247\211\345\272\224\347\224\250\345\274\200\345\217\221/08.\345\270\270\350\247\201\351\227\256\351\242\230.md" deleted file mode 100644 index 6bbe9aa1c837044dc44e8b282a40bc2a7089ff89..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/01.\350\275\273\351\207\217\345\222\214\345\260\217\345\236\213\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\270\246\345\261\217\346\221\204\345\203\217\345\244\264\347\261\273\344\272\247\345\223\201/02.\350\247\206\350\247\211\345\272\224\347\224\250\345\274\200\345\217\221/08.\345\270\270\350\247\201\351\227\256\351\242\230.md" +++ /dev/null @@ -1,161 +0,0 @@ ---- -title: 常见问题 -permalink: /pages/010701030208 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:26 ---- -# 常见问题 - -- [视觉应用常见问题](#section147421736145813) - - [是否存在一个全局变量,所有的页面都可以访问?](#section294382614018) - - [如何获取dom中的元素](#section1423713435019) - - [如何在页面间传值?](#section119822143117) - - [list如何滚动到某个item?](#section188663819111) - - [text支持多行吗?](#section205741157418) - - [为什么控件不显示?](#section1345810151025) - - [如何实现页面滑动?](#section1724052813218) - - [Left、Top为什么不生效?](#section34659571520) - - [动态绑定为什么不生效?](#section1758881511313) - - [如何实现相对定位和绝对定位?](#section1378730235) - - [如何控制控件的显示与隐藏?](#section1243424718312) - - [使用Margin时,有什么注意事项?](#section7923357414) - - [使用事件订阅时,有什么注意事项?](#section91641925548) - - [使用动态绑定时,有什么注意事项?](#section1292412431744) - - [swiper loop属性如何生效?](#section1136434952) - - [使用数组时,有什么注意事项?](#section1979819133510) - - -## 视觉应用常见问题 - -### 是否存在一个全局变量,所有的页面都可以访问? - -当前框架中不存在所有Page都可以访问的全局变量。 - -### 如何获取dom中的元素 - -通过ref属性获取dom中的元素,详细示例如下图所示;获取的元素只能使用它的方法,不能改变属性。 - -``` - -
- - -
- -/* index.js */ -export default { - data: { - images:[ - {src:"common/frame1.png"}, - {src:"common/frame2.png"}, - {src:"common/frame3.png"} - ] - }, - handleClick(){ - //通过$refs属性获取对应的组件,在hml中,组件的ref属性要设置为animator - const animator = this.$refs.animator; - const state = animator.getState(); - if(state == "paused"){ - animator.resume(); - }else if(state == "stopped"){ - animator.start(); - }else{ - animator.pause(); - } - } -} -``` - -### 如何在页面间传值? - -通过router.replace方法中的params参数来传递,参考代码如下: - -第一个页面传递数据: - -``` -router.replace({ - uri:'pages/detail/detail', //要跳转的页面uri - params:{transferData:this.data} //传递的数据,数据个数和名称开发者自己定义, -}); -``` - -第二个界面接受数据: - -``` -onInit(){ - const data = this.transferData; //在onInit函数中接受传递的数据 -} -``` - -### list如何滚动到某个item? - -通过list的scrollTo方法滚动到指定的item,参数是目标item的index。Index参数可以通过scrollend事件获取或者开发者指定。 - -### text支持多行吗? - -text支持多行。通过回车键换行或者是不设置text的高度属性,由控件自动根据内容换行。 - -### 为什么控件不显示? - -**现象描述** - -开发者在hml文件中添加的控件无法显示 - -**可能原因** - -- 未设置width和height值; -- 样式设置错误。 - -**处理步骤** - -\(1\)检查是否设置width和height值,组件必须显式设置width和height值; - -\(2\)检查组件的样式设置是否正确。 - -### 如何实现页面滑动? - -实现页面滑动目前有三种方式:scroll(根组件大小超过屏幕的大小即自动实现scroll效果)、list、swiper。开发者可以参考开发文档查看三者的区别,并加以使用。 - -### Left、Top为什么不生效? - -除根节点外,Left、Top配合Stack组件使用才有效果。 - -### 动态绑定为什么不生效? - -在进行绑定时,必须先将要绑定的对象或者对象的属性进行定义,不能先绑定后定义 - -### 如何实现相对定位和绝对定位? - -使用div、stack(top left属性)来实现相对和绝对定位。 - -### 如何控制控件的显示与隐藏? - -通过display、show和if来控制控件的显示与隐藏。区别在于:if为false时,组件会从VDOM中移除,而show仅是渲染时不可见,组件依然存在于VDOM中。 - -### 使用Margin时,有什么注意事项? - -Stack组件不支持其子组件设置margin属性。 - -### 使用事件订阅时,有什么注意事项? - -在应用运行期间只存在一个page,所以router.replace跳转是先销毁前一个页面,然后在新创建一个界面。因此,如果涉及到事件订阅的页面,每次页面创建时要进行事件订阅,跳转离开界面前取消事件订阅。 - -### 使用动态绑定时,有什么注意事项? - -过多的动态绑定会消耗较多的内存,若非业务需要,尽量不要使用太多的动态绑定。 - -### swiper loop属性如何生效? - -去掉第一个组件或者去掉最后一个组件,剩余的长度大于swiper长度,loop生效。 - -### 使用数组时,有什么注意事项? - -数组元素不宜过多,尽量避免对大数组进行频繁操作。 - diff --git "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\350\256\276\345\244\207/01.\346\227\266\351\222\237\345\272\224\347\224\250\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\350\256\276\345\244\207/01.\346\227\266\351\222\237\345\272\224\347\224\250\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index a75b706c54f075d0763f9852d9dcf13dc90a6fa2..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\350\256\276\345\244\207/01.\346\227\266\351\222\237\345\272\224\347\224\250\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,337 +0,0 @@ ---- -title: 时钟应用开发指导 -permalink: /pages/01070201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:26 ---- -# 时钟应用开发指导 - -- [概述](#section11522349121115) -- [开发准备](#section6592121861218) -- [开发步骤](#section19901741111312) -- [签名打包](#section10601181101516) -- [真机运行](#section092721731511) -- [常见问题](#section1122413460153) - - [hdc\_std连接不到设备](#section1922725151614) - - [hdc\_std运行不了](#section15657547131615) - - -## 概述 - -本文将介绍如何快速搭建基于OpenHarmony标准系统(Hi3516DV300开发板)的应用开发环境,并基于一个时钟APP示例逐步展示应用的创建、开发、调试和安装等流程。示例代码可以通过[本链接](https://gitee.com/openharmony/app_samples/tree/master/common/Clock)获取。 - -时钟App是一款显示实时时间的应用,显示效果如下图所示: - -**图 1** 时钟应用显示效果图 -![](/images/device-dev/guide/figures/时钟应用显示效果图.png "时钟应用显示效果图") - -## 开发准备 - -首先需要下载和配置DevEco Studio,具体操作请参考[DevEco Studio 使用指南](/pages/extra/d114c8/)。 - -## 开发步骤 - -应用的功能是通过表盘和数字显示实时时间。 - -从[显示效果图](#fig176772511186)分析可知,页面由两个部分组成: - -- 表盘栏:主要展示一个动态的钟表,且钟表指针能准确转动。 -- 数字时间栏:主要以数字形式显示当前时间。 - -综上,我们可搭建一个纵向两行排列的弹性页面布局来实现界面的功能。具体开发步骤如下: - -1. 在hml文件中添加一个根节点div,注意每个hml文件中有且只能有一个根节点,代码如下: - - ``` -
-
- ``` - - class="container"表示组件使用的样式,container是index.css文件中的一个样式类,代码如下: - - ``` - .container { - flex-direction: column; - justify-content: center; - align-items: center; - width: 100%; - height: 100%; - } - ``` - - 在这个样式类中,我们分别设置了根组件div的高度和宽度(注意在应用的开发过程中,除部分组件(text)外必须显式指定组件的高度和宽度,否则可能无法显示)、并将flex-direction属性设置为column,该属性表示div的子组件是垂直方向从上到下排列;这样就可以实现本节开头所说的纵向两行排列的弹性页面布局。 - -2. 实现时钟转动,需要使用“stack”组件。“stack”组件的功能是堆叠容器,子组件按照顺序依次入栈,后一个子组件覆盖前一个子组件。 - - 在根组件下添加一个stack容器,代码片段如下: - - ``` -
- - - - - - -
- ``` - - style="transform : rotate\(\{\{ second \* 6 \}\}deg\) 这类代码用来设置组件的旋转事件。其中transform是设置动画平移/旋转/缩放的属性,rotate是旋转动画属性,支持设置x轴和y轴两个维度的选中参数。 - - 在css文件中设置"stack"组件样式的高度、宽度、位置等属性,代码如下: - - ``` - .stack { - flex-direction: column; - justify-content: center; - align-items: center; - width: 100%; - height: 50%; - } - ``` - - 在css文件中设置"clock-bg"组件样式的高度、宽度等属性,代码如下: - - ``` - .clock-bg { - width: 80%; - height: 80%; - object-fit: scale-down; - } - ``` - - 在css文件中设置"clock-hand"组件为时针、分针和秒针的高度、宽度等属性,代码如下: - - ``` - .clock-hand { - width: 25%; - height: 65%; - object-fit: contain; - } - ``` - - index.js中会有一个定时器实时刷新时分秒变量,从而触发时间界面自动更新。对应的js代码如下: - - ``` - export default { - timer: undefined, - //定义参数 - data: { - hour: 0, //定义小时 - minute: 0, //定义分钟 - second: 0 //定义秒 - }, - onInit () { - this.updateTime(); - this.timer = setInterval(this.updateTime, 1000)//设置1s的定时器 - }, - updateTime: function () { - var nowTime = new Date() - this.hour = nowTime.getHours() - this.minute = nowTime.getMinutes() - this.second = nowTime.getSeconds() - if (this.hour < 10) { - this.hour = '0' + this.hour - } - if (this.minute < 10) { - this.minute = '0' + this.minute - } - if (this.second < 10) { - this.second = '0' + this.second - } - }, - } - ``` - -3. 显示数字时间,在钟表下面以数字形式显示当前时间。在根布局内末尾加上text组件,页面结构如下: - - ``` - {{ hour }}:{{ minute }}:{{ second }} - ``` - - class="digit-clock"设置了组件的高度和宽度以及字体大小,其代码如下: - - ``` - .digit-clock { - font-size: 58px; - width: 100%; - margin-top: 0px; - text-align: center; - } - ``` - -4. 所有组件设置样式、动画效果和数据动态绑定,完整代码如下所示: - - **index.hml文件** - - ``` -
- - - - - - - {{ hour }}:{{ minute }}:{{ second }} -
- ``` - - - **index.css文件** - - ``` - .container { - flex-direction: column; - justify-content: center; - align-items: center; - width: 100%; - height: 100%; - } - - .stack { - flex-direction: column; - justify-content: center; - align-items: center; - width: 100%; - height: 50%; - } - - .digit-clock { - font-size: 58px; - width: 100%; - margin-top: 0px; - text-align: center; - } - - .clock-bg { - width: 80%; - height: 80%; - object-fit: scale-down; - } - - .clock-hand { - width: 25%; - height: 65%; - object-fit: contain; - } - ``` - - - **index.js:** - - js文件主要用于实现App应用的逻辑交互。在本页面js文件中,需要实现如下功能:定时获取系统时间。 - - ``` - export default { - timer: undefined, - data: { - hour: 0, - minute: 0, - second: 0 - }, - onInit() { - this.updateTime() - this.timer = setInterval(this.updateTime, 1000) - }, - updateTime: function () { - var nowTime = new Date() - this.hour = nowTime.getHours() - this.minute = nowTime.getMinutes() - this.second = nowTime.getSeconds() - if (this.hour < 10) { - this.hour = '0' + this.hour - } - if (this.minute < 10) { - this.minute = '0' + this.minute - } - if (this.second < 10) { - this.second = '0' + this.second - } - }, - onDestroy() { - clearInterval(this.timer); - } - } - ``` - - - -## 签名打包 - -代码编写完成后,在真机设备上运行应用,需要先对应用进行签名,然后再进行打包,具体操作请参考[签名打包指导](/pages/01080905)。 - -## 真机运行 - -应用签名打包后即可安装到开发板。安装应用前需要先完成[DevEco Device Tool的安装配置](https://device.harmonyos.com/cn/docs/ide/user-guides/service_introduction-0000001050166905),然后将OpenHarmony系统烧录到开发板并运行。编译烧录、运行镜像的基本操作请参考快速入门手册:[标准系统Hi3516快速入门](/pages/01020201)。完成镜像运行,系统正常启动后,执行如下步骤安装或卸载应用。 - -1. 从开发者工具代码仓路径中获取hdc客户端。 - - ``` - developtools/hdc_standard/prebuilt/windows/hdc_std.exe - ``` - - 修改名称为hdc.exe,并将工具路径加入系统环境path变量中。 - -2. 启动cmd命令窗口,执行以下命令,推送hap应用包到设备目录下并安装。 - - ``` - hdc install clock.hap - ``` - -3. 启动应用。执行以下命令,其中ohos.samples.clock为应用包名,MainAbility为应用启动的Ability。 - - ``` - hdc shell aa start -d 123 -a ohos.samples.clock.MainAbility -b ohos.samples.clock - ``` - -4. 卸载应用(可选)。执行以下命令,其中ohos.samples.clock为应用包名。 - - ``` - hdc shell bm uninstall -n ohos.samples.clock - ``` - - -## 常见问题 - -### hdc\_std连接不到设备 - -- **现象描述** - - 执行 "hdc\_std list targets"命令后结果为:\[Empty\] - -- **可能原因和解决方法** - 1. 设备没有被识别: - - 在设备管理器中查看是否有hdc设备,在通用串行总线设备中会有“HDC Device”信息。如果没有,hdc无法连接。此时需要插拔设备,或者烧写最新的镜像。 - - 2. hdc\_std工作异常: - - 可以执行"hdc kill"或者"hdc start -r"杀掉hdc服务或者重启hdc服务,然后再执行hdc list targets查看是否已经可以获取设备信息。 - - 3. hdc\_std与设备不匹配: - - 如果设备烧写的是最新镜像,hdc\_std也需要使用最新版本。由于hdc\_std会持续更新,请从开源仓developtools\_hdc\_standard中获取,具体位置在该开源仓的prebuilt目录。 - - - -### hdc\_std运行不了 - -- **现象描述** - - 点击hdc\_std.exe文件无法运行。 - -- **可能原因和解决方法** - - hdc\_std.exe不需要安装,直接放到磁盘上就能使用,也可以添加到环境变量中。通过打开cmd执行hdc\_std命令直接使用。 - - diff --git "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\350\256\276\345\244\207/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221\347\244\272\344\276\213.md" "b/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\350\256\276\345\244\207/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221\347\244\272\344\276\213.md" deleted file mode 100644 index c71af36eff23cdf2e97cba8b6ba7d31902cacc2d..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\350\256\276\345\244\207/02.\345\271\263\345\217\260\351\251\261\345\212\250\345\274\200\345\217\221\347\244\272\344\276\213.md" +++ /dev/null @@ -1,458 +0,0 @@ ---- -title: 平台驱动开发示例 -permalink: /pages/01070202 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:26 ---- -# 平台驱动开发示例 - -- [概述](#section194201316174215) -- [环境准备](#section6926133918422) -- [开发](#section65801539470) - - [文件说明](#section0708184454414) - - [实例化驱动入口](#section85325864412) - - [设置相关参数](#section8155172019453) - - [添加控制器](#section1335374114452) - -- [编译及烧录](#section164824754712) - -## 概述 - -本文档将以I2C驱动为例,介绍如何基于HDF驱动框架完成平台驱动开发。 - ->![](/images/device-dev/public_sys-resources/icon-caution.gif) **注意:** ->本例仅作为平台驱动开发示例参考,开发者不可直接用于商用集成。 - -HDF驱动框架为常用外围设备提供了标准的驱动框架,驱动开发者只需将驱动适配至HDF驱动框架,即可通过HDF驱动框架提供的接口操作外围设备。 - -本文以I2C为例。其时序流程如[图1](#fig9596628607)所示。 - -**图 1** I2C时序流程图 -![](/images/device-dev/guide/figures/I2C时序流程图.png "I2C时序流程图") - -## 环境准备 - -环境准备具体操作请参考[标准系统基础环境搭建](/pages/01020201)。 - ->![](/images/device-dev/public_sys-resources/icon-notice.gif) **须知:** ->本示例针对OpenHarmony轻量系统、小型系统、标准系统都适用,本文以标准系统为例。其他系统的开发者可参考对应系统的指导文档进行环境搭建。 - -## 开发 - -### 文件说明 - -本例中涉及的文件及路径如下表: - -**表 1** 文件说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

说明

-

文件路径

-

操作

-

示例文件

-

/drivers/adapter/khdf/linux/platform/i2c/i2c_sample.c

-

新增文件

-

设备服务文件

-

/drivers/adapter/khdf/linux/hcs/device_info/device_info.hcs

-

-

追加内容

-

-

配置参数文件

-

/drivers/adapter/khdf/linux/hcs/platform/i2c_config.hcs

-

编译文件

-

/drivers/adapter/khdf/linux/platform/i2c/Makefile

-

依赖头文件

-

/drivers/framework/include/core/hdf_device_desc.h

-

作为头文件引用

-

-

核心层头文件

-

/drivers/framework/support/platform/include/i2c_core.h

-

HCS配置入口文件

-

/drivers/adapter/khdf/linux/hcs/hdf.hcs

-

HCS配置文件总入口

-
- ->![](/images/device-dev/public_sys-resources/icon-caution.gif) **注意:** ->本例程涉及的文件路径均作为演示,驱动开发者应根据实际情况确定具体的源文件存放位置。 - -### 实例化驱动入口 - -实例化一个HdfDriverEntry 对象作为驱动入口。驱动入口必须为HdfDriverEntry(在hdf\_device\_desc.h中定义)类型的全局变量,且moduleName要和device\_info.hcs中保持一致。在加载驱动时HDF框架会先调用Bind函数,再调用Init函数加载该驱动,当Init调用异常时,HDF框架会调用Release释放驱动资源并退出。 - -I2C驱动中没有实现Bind方法,因为I2C控制器由manager管理,而在manager中已经实现了Bind方法,因此I2C驱动中无需再绑定服务。 - -实例化驱动入口的示例代码如下: - -``` -/* 定义驱动入口的对象,必须为HdfDriverEntry(在hdf_device_desc.h中定义)类型的全局变量 */ -struct HdfDriverEntry g_sampleI2cDriverEntry = { - .moduleVersion = 1, - .Init = SampleI2cInit, - .Release = SampleI2cRelease, - .moduleName = "demo_i2c_driver", -}; -/* 调用HDF_INIT将驱动入口注册到HDF框架中 */ -HDF_INIT(g_sampleI2cDriverEntry); -``` - -### 设置相关参数 - -通过配置device\_info.hcs,并从HCS获取并解析设备的配置参数以确保驱动能够正确加载。 - -1. 添加设备服务节点(必选)。 - - 编辑device\_info.hcs,在device\_i2c :: device下添加驱动设备服务节点,示例如下: - - ``` - root { - device_info { - match_attr = "hdf_manager"; - device_i2c :: device { // i2c设备节点 - device2 :: deviceNode { // i2c驱动的DeviceNode节点 - policy = 0; // policy字段是驱动服务发布的策略 - priority = 55; // 驱动启动优先级 - permission = 0644; // 驱动创建设备节点权限 - moduleName = "demo_i2c_driver"; // 驱动名称,该字段的值必须和驱动入口结构的moduleName值一致 - serviceName = "DEMO_I2C_DRIVER"; // 驱动对外发布服务的名称,必须唯一 - deviceMatchAttr = "demo_i2c_config"; // 驱动私有数据匹配的关键字,必须和驱动私有数据配置表中的 - // match_attr值相等 - } - } - } - } - - ``` - - >![](/images/device-dev/public_sys-resources/icon-notice.gif) **须知:** - >配置文件中的priority(取值范围为整数0到200)是用来表示host和驱动的优先级,不同的host内的驱动,host的priority值越小,驱动加载优先级越高;同一个host内驱动的priority值越小,加载优先级越高,驱动的priority值相同则不保证加载顺序。 - -2. 添加配置参数(可选)。 - - 有时驱动可能会需要私有配置信息,以确保寄存器的配置可以满足不同产品的需求。如需要私有配置信息,则可以添加一个驱动的配置文件,用来存放一些驱动的默认配置信息,HDF框架在加载驱动的时候,会将对应的配置信息获取并保存在HdfDeviceObject 中的property里面,通过Bind和Init(参考[驱动开发](/pages/0105020102))传递给驱动。驱动开发者可新建配置文件,并在板级驱动hdf.hcs中引用新建的配置文件,本例中直接在原有的配置文件i2c\_config.hcs内添加配置参数。 - - 本例中编辑i2c\_config.hcs,添加配置参数: - - ``` - root { - platform { - i2c_config_demo { - match_attr = "demo_i2c_config"; // 该字段的值必须和device_info.hcs中的deviceMatchAttr值一致 - - template i2c_controller { // 参数模板 - bus = 0; - reg_pbase = 0x120b0000; - reg_size = 0xd1; - } - - controller_demo_0 :: i2c_controller { // 两个I2C示例控制器 - bus = 8; - } - controller_demo_1 :: i2c_controller { - bus = 9; - } - } - } - } - ``` - - match\_attr字段必须与device\_info.hcs中的deviceMatch\_Attr保持一致,在此文件中配置驱动需要的参数,通过match\_attr可匹配至对应的驱动,该驱动即可在Bind或Init中调用DeviceResourceGetIfaceInstance\(\)函数获取这些配置参数。 - - 若配置文件为新文件,则需要在板级配置入口文件hdf.hcs中引用该配置文件,例如: - - ``` - #include "device_info/device_info.hcs" - #include "i2c/i2c_config.hcs" - ``` - - 由于本例中在原有的i2c\_config.hcs内添加配置参数,没有新建配置文件,因此无需再将i2c\_config.hcs添加至板级配置入口文件中。 - -3. 驱动从HCS获取配置参数。 - - 在本例中,驱动需要通过HCS获取寄存器物理基地址、寄存器大小、总线号等参数,从而对控制器进行正确配置。 - - ``` - /* 从HCS获取配置参数 */ - static int32_t SampleI2cReadDrs(struct SampleI2cCntlr *sampleCntlr, const struct DeviceResourceNode *node) - { - int32_t ret; - struct DeviceResourceIface *drsOps = NULL; - - drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); - if (drsOps == NULL || drsOps->GetUint32 == NULL) { // 确保GetUint32方法可用 - HDF_LOGE("%s: invalid drs ops fail!", __func__); - return HDF_FAILURE; - } - - ret = drsOps->GetUint32(node, "reg_pbase", &sampleCntlr->regBasePhy, 0); // 从HCS读取物理基地址reg_pbase - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: read regBase fail!", __func__); - return ret; - } - - ret = drsOps->GetUint16(node, "reg_size", &sampleCntlr->regSize, 0); // 从HCS读取寄存器大小reg_size - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: read regsize fail!", __func__); - return ret; - } - - ret = drsOps->GetUint16(node, "bus", (uint16_t *)&sampleCntlr->bus, 0); // 从HCS读取总线号bus - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: read bus fail!", __func__); - return ret; - } - - return HDF_SUCCESS; - } - ``` - - -### 添加控制器 - -初始化控制器硬件,并调用核心层接口完成向核心层添加、删除设备,以及钩子函数的实现等。 - -1. 定义结构体,实现钩子函数并赋值至函数指针。 - - I2cMethod结构体在i2c\_core.h中定义,其中通过函数指针的方式定义了I2C需要实现的方法,transfer方法为用于传输的钩子函数,在驱动中需要做具体实现并对函数指针赋值。 - - 示例代码如下: - - ``` - /* 自定义设备结构体,继承父类I2cCntlr */ - struct SampleI2cCntlr { - struct I2cCntlr cntlr; - OsalSpinlock spin; - volatile unsigned char *regBase; - uint16_t regSize; - int16_t bus; - uint32_t regBasePhy; - }; - - /* 消息结构体,继承父类I2cMsg */ - struct SampleTransferData { - struct I2cMsg *msgs; - int16_t index; - int16_t count; - }; - /* 钩子函数实现 */ - static int32_t SampleI2cTransfer(struct I2cCntlr *cntlr, struct I2cMsg *msgs, int16_t count) - { - int32_t ret = HDF_SUCCESS; - struct SampleI2cCntlr *sampleCntlr = NULL; - struct SampleTransferData td; - - if (cntlr == NULL || cntlr->priv == NULL) { - HDF_LOGE("SampleI2cTransfer: cntlr lor sampleCntlr is null!"); - return HDF_ERR_INVALID_OBJECT; - } - sampleCntlr = (struct SampleI2cCntlr *)cntlr; - - if (msgs == NULL || count <= 0) { - HDF_LOGE("SampleI2cTransfer: err parms! count:%d", count); - return HDF_ERR_INVALID_PARAM; - } - td.msgs = msgs; - td.count = count; - td.index = 0; - - HDF_LOGE("Successfully transmitted!"); // 表示此处传输成功 - - td.index = count; // 经过处理,最后实际发送msg个数等于count,返回已发送个数,此句代替已省略的处理过程 - return (td.index > 0) ? td.index : ret; - } - /* 钩子函数赋值 */ - static struct I2cMethod g_method = { - .transfer = SampleI2cTransfer, - }; - ``` - -2. 编写驱动初始化函数。 - - 本例中使用SampleI2cInit作为驱动初始化函数的函数名(函数名称可由驱动开发者确定),该函数需要在驱动入口结构体中赋值给Init,以供HDF驱动框架调用从而达到初始化驱动的目的。该函数中需要对从HCS获取的配置参数进行解析,并按照这些参数创建控制器。示例如下: - - ``` - /* 解析参数,申请内存并创建控制器 */ - static int32_t SampleI2cParseAndInit(struct HdfDeviceObject *device, const struct DeviceResourceNode *node) - { - int32_t ret; - struct SampleI2cCntlr *sampleCntlr = NULL; - (void)device; - - sampleCntlr = (struct SampleI2cCntlr *)OsalMemCalloc(sizeof(*sampleCntlr)); - if (sampleCntlr == NULL) { - HDF_LOGE("%s: malloc sampleCntlr fail!", __func__); - return HDF_ERR_MALLOC_FAIL; - } - - ret = SampleI2cReadDrs(sampleCntlr, node); // 从HCS获取配置参数 - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: read drs fail! ret:%d", __func__, ret); - goto __ERR__; - } - - sampleCntlr->regBase = OsalIoRemap(sampleCntlr->regBasePhy, sampleCntlr->regSize); - if (sampleCntlr->regBase == NULL) { - HDF_LOGE("%s: ioremap regBase fail!", __func__); - ret = HDF_ERR_IO; - goto __ERR__; - } - - HDF_LOGE("The controller has been initialized!"); // 表示此处省略的控制器初始化操作已经成功 - - sampleCntlr->cntlr.priv = (void *)node; - sampleCntlr->cntlr.busId = sampleCntlr->bus; - sampleCntlr->cntlr.ops = &g_method; - (void)OsalSpinInit(&sampleCntlr->spin); // 初始化自旋锁 - ret = I2cCntlrAdd(&sampleCntlr->cntlr); // 向核心层添加控制器 - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: add i2c controller fail:%d!", __func__, ret); - goto __ERR__; - } - - return HDF_SUCCESS; - __ERR__: // 错误处理 - if (sampleCntlr != NULL) { - if (sampleCntlr->regBase != NULL) { - OsalIoUnmap((void *)sampleCntlr->regBase); // 取消地址映射 - sampleCntlr->regBase = NULL; - } - OsalMemFree(sampleCntlr); // 释放内存 - sampleCntlr = NULL; - } - return ret; - } - /* 驱动入口初始化函数 */ - static int32_t SampleI2cInit(struct HdfDeviceObject *device) - { - int32_t ret; - const struct DeviceResourceNode *childNode = NULL; - - HDF_LOGE("%s: Enter", __func__); - if (device == NULL || device->property == NULL) { - HDF_LOGE("%s: device or property is NULL", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - ret = HDF_SUCCESS; - DEV_RES_NODE_FOR_EACH_CHILD_NODE(device->property, childNode) { - ret = SampleI2cParseAndInit(device, childNode); // 调用解析参数和创建控制器的函数 - if (ret != HDF_SUCCESS) { - break; - } - } - return ret; - } - ``` - -3. 编写驱动释放函数。 - - 本例中使用SampleI2cRelease作为驱动释放函数的函数名(函数名称可由驱动开发者确定),该函数需要在驱动入口结构体中赋值给Release,当HDF框架调用Init函数初始化驱动失败时,将调用Release释放驱动资源。该函数中需包含释放内存和删除控制器等操作。示例如下: - - ``` - /* 删除控制器函数 */ - static void SampleI2cRemoveByNode(const struct DeviceResourceNode *node) - { - int32_t ret; - int16_t bus; - struct I2cCntlr *cntlr = NULL; - struct SampleI2cCntlr *sampleCntlr = NULL; - struct DeviceResourceIface *drsOps = NULL; - - drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); - if (drsOps == NULL || drsOps->GetUint32 == NULL) { - HDF_LOGE("%s: invalid drs ops fail!", __func__); - return; - } - - ret = drsOps->GetUint16(node, "bus", (uint16_t *)&bus, 0); // 从HCS获取I2C总线号 - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: read bus fail!", __func__); - return; - } - - cntlr = I2cCntlrGet(bus); - if (cntlr != NULL && cntlr->priv == node) { // 根据I2C总线号删除控制器 - I2cCntlrPut(cntlr); - I2cCntlrRemove(cntlr); - sampleCntlr = (struct SampleI2cCntlr *)cntlr; - OsalIoUnmap((void *)sampleCntlr->regBase); - OsalMemFree(sampleCntlr); - } - return; - } - /* 释放资源 */ - static void SampleI2cRelease(struct HdfDeviceObject *device) - { - const struct DeviceResourceNode *childNode = NULL; - - HDF_LOGI("%s: enter", __func__); - - if (device == NULL || device->property == NULL) { - HDF_LOGE("%s: device or property is NULL", __func__); - return; - } - - DEV_RES_NODE_FOR_EACH_CHILD_NODE(device->property, childNode) { - SampleI2cRemoveByNode(childNode); // 调用删除控制器函数 - } - } - ``` - - -## 编译及烧录 - -1. 编辑Makefile,添加源文件: - - ``` - include drivers/hdf/khdf/platform/platform.mk - - obj-y += $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/i2c_core.o \ - $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/i2c_if.o \ - ./i2c_adapter.o \ - ./i2c_sample.o - ``` - - "./i2c\_sample.o"为本示例中在Makefile中追加的内容。 - -2. 编译及烧录。 - - 具体操作请参考[标准系统快速入门编译及烧录章节](/pages/extra/6dca5d/)。 - - diff --git "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\244\226\350\256\276\351\251\261\345\212\250\345\274\200\345\217\221\347\244\272\344\276\213.md" "b/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\244\226\350\256\276\351\251\261\345\212\250\345\274\200\345\217\221\347\244\272\344\276\213.md" deleted file mode 100644 index 46642e9c7c1008d414eae7a9dd43fa5d130af5e1..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/07.\350\256\276\345\244\207\345\274\200\345\217\221\347\244\272\344\276\213/02.\346\240\207\345\207\206\347\263\273\347\273\237\350\256\276\345\244\207/03.\345\244\226\350\256\276\351\251\261\345\212\250\345\274\200\345\217\221\347\244\272\344\276\213.md" +++ /dev/null @@ -1,496 +0,0 @@ ---- -title: 外设驱动开发示例 -permalink: /pages/01070203 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:26 ---- -# 外设驱动开发示例 - -- [概述](#section86753818426) - - [硬件资源简介](#section123071189431) - - [Input模型简介](#section53684425430) - -- [环境搭建](#section661075474418) -- [TouchScreen器件驱动开发](#section15233162984520) - - [配置设备描述信息](#section16761205604515) - - [配置Touchscreen器件信息](#section156331030144617) - - [适配器件私有驱动](#section17127331595) - -- [编译及烧录](#section16465031164711) -- [调试验证](#section62577313482) -- [Input模型工作流程解析](#section1578569154917) - - [私有配置信息解析](#section1310113815495) - - [管理驱动层初始化及注册驱动至HDF框架](#section614512119500) - - [公共驱动层初始化及注册驱动至HDF框架](#section16194201755019) - - [器件驱动层初始化及注册驱动至HDF框架](#section1090743312505) - - [具体调用逻辑串联函数](#section81801147529) - - -## 概述 - -本文档将介绍如何基于Hi3516DV300开发板完成基于HDF\_Input模型的触摸屏器件驱动开发,从而使开发者快速入门,进行基于OpenHarmony的外设驱动开发。 - -### 硬件资源简介 - -Hi3516DV300开发板套件所提供的触摸屏器件IC为GT911,该器件采用标准I2C与主机通信,通过6pin软排线与主板连接。6pin分布以及实物连接图如下图所示: - -![](/images/device-dev/guide/figures/6-pin-distribution-and-physical-connection.png) - -### Input模型简介 - -Input驱动模型核心部分由设备管理层、公共驱动层、器件驱动层组成。其中: - -- 设备管理层:主要为各类输入设备驱动提供input设备的注册、注销接口,同时统一管理input设备列表; -- 公共驱动层:负责对板级硬件进行初始化、硬件中断处理、向manager注册input设备等; -- 器件驱动层:通过适配平台驱动预留的差异化接口,实现器件驱动开发量最小化; - -此外,Input模型预先实现了数据通道以及设备配置信息解析等函数。 - -关于Input模型的详细介绍请参考《[Touchscreen开发概述](/pages/0105020402#section175431838101617)》。 - -## 环境搭建 - -环境准备具体操作请参考[标准系统基础环境搭建](/pages/01020201)。 - ->![](/images/device-dev/public_sys-resources/icon-notice.gif) **须知:** ->本示例针对OpenHarmony轻量系统、小型系统、标准系统都适用,本文以标准系统为例。其他系统的开发者可参考对应系统的指导文档进行环境搭建。 - -## TouchScreen器件驱动开发 - -基于Input模型适配一款触摸屏IC需要完成的具体工作见下。 - -### 配置设备描述信息 - -驱动注册到HDF框架所需要的设备驱动描述信息,如驱动是否加载以及加载次序等。 - -配置文件路径:./drivers/adapter/khdf/linux/hcs/device\_info/device\_info.hcs - -device\_info.hcs中的信息主要提供给HDF框架使用,包含了Input模型各层驱动注册到HDF框架所必需的信息,开发者无特殊场景需求无需改动。各驱动层私有配置信息通过“deviceMatchAttr”字段与input\_config.hcs中的“match\_attr”相关内容进行匹配。 - -配置文件中与input模块相关的内容如下所示,相关字段的详细含义可以参考《[驱动配置](/pages/0105020102)》: - -``` -input :: host { - hostName = "input_host"; - priority = 100; - device_input_manager :: device { // Input管理层设备描述信息 - device0 :: deviceNode { - policy = 2; // 向内核用户态均发布服务 - priority = 100; // input管理层驱动优先级默认为100 - preload = 0; // 加载该驱动 - permission = 0660; // 驱动创建设备节点权限 - moduleName = "HDF_INPUT_MANAGER"; // 与驱动入口的moduleName匹配 - serviceName = "hdf_input_host"; // HDF框架生成的节点名 - deviceMatchAttr = ""; // manager目前不需要私有配置,因此为空 - } - } - - device_hdf_touch :: device { // Input公共驱动层设备描述信息 - device0 :: deviceNode { - policy = 2; // 向内核用户态均发布服务 - priority = 120; // input公共驱动优先级默认为120 - preload = 0; // 加载该驱动 - permission = 0660; // 驱动创建设备节点权限 - moduleName = "HDF_TOUCH"; // 与驱动入口的moduleName匹配 - serviceName = "hdf_input_event1"; // HDF框架生成的节点名 - deviceMatchAttr = "touch_device1"; // 与私有配置信息中的“match_attr”字段保持一致 - } - } - - device_touch_chip :: device { // Input器件驱动层信息 - device0 :: deviceNode { - policy = 0; // 向内核用户态均不发布服务 - priority = 130; // input器件驱动优先级默认为130 - preload = 0; // 加载该驱动 - permission = 0660; // 驱动创建设备节点权限 - moduleName = "HDF_TOUCH_GT911"; // 与驱动入口的moduleName匹配 - serviceName = "hdf_touch_gt911_service";// HDF框架生成的节点名 - deviceMatchAttr = "zsj_gt911_5p5"; //与私有配置信息中的“match_attr”字段保持一致 - } - } - } -``` - -该配置文件中需要重点关注的字段有: - -“priority”决定驱动加载顺序; - -“preload”决定驱动是否加载; - -“moduleName ”需要与驱动注册入口处的“moduleName ”字段保持一致; - -“serviceName ”HDF框架依据该字段创建节点名; - -“deviceMatchAttr ”需要与私有配置信息中的“match\_attr”字段保持一致。 - -通过配置设备描述信息,使得HDF框架通过moduleName与注册至驱动入口的代码相匹配,保证了驱动的正常加载,通过priority字段保证了各驱动的加载顺序。 - -### 配置Touchscreen器件信息 - -器件私有信息包括上下电时序等,平台硬件信息包括器件连接主板的GPIO端口信息等。 - -配置文件路径:./drivers/adapter/khdf/linux/hcs/input/input\_config.hcs - -input\_config.hcs中的信息由驱动代码进行读取解析,主要由公共驱动层的私有配置信息及器件驱动层的私有配置信息组成。文件中的配置包含板级硬件信息及器件私有配置信息,实际业务开发时,可根据具体需求增删及修改对应内容。 - -``` -root { - input_config { - touchConfig { - touch0 { // 第一款触摸屏 - boardConfig { // 板级硬件信息 - match_attr = "touch_device1"; // 与设备描述配置信息中公共驱动层私有配置信息的“match_attr”字段保持一致 - inputAttr { - /* 0:touch 1:key 2:keyboard 3:mouse 4:button 5:crown 6:encoder */ - inputType = 0; // input类型为touch - solutionX = 480; // 分辨率X信息 - solutionY = 960; // 分辨率Y信息 - devName = "main_touch"; // 设备名称 - } - busConfig { - /* 0:i2c 1:spi */ - busType = 0; // GT911采用I2C通信 - busNum = 6; // 与主机芯片第6路I2C通信 - clkGpio = 86; // 主机芯片SCL管脚 - dataGpio = 87; // 主机芯片SDA管脚 - i2cClkIomux = [0x114f0048, 0x403]; // SCL管脚配置信息 - i2cDataIomux = [0x114f004c, 0x403]; // SDA管脚配置信息 - } - pinConfig { - rstGpio = 3; // 复位管脚连接主机芯片的3号管脚 - intGpio = 4; // 中断管脚连接主机芯片的4号管脚 - rstRegCfg = [0x112f0094, 0x400]; // 复位管脚配置信息 - intRegCfg = [0x112f0098, 0x400]; // 中断管脚配置信息 - } - powerConfig { - /* 0:unused 1:ldo 2:gpio 3:pmic */ - vccType = 2; // GPIO供电 - vccNum = 20; // gpio20 - vccValue = 1800; // 电压幅值为1800mV - vciType = 1; // LDO供电 - vciNum = 12; // ldo12 - vciValue = 3300; // 电压幅值为3300mV - } - - featureConfig { - capacitanceTest = 0; // 容值测试 - gestureMode = 0; // 手势模式 - gloverMode = 0; // 手套模式 - coverMode = 0; // 皮套模式 - chargerMode = 0; // 充电模式 - knuckleMode = 0; // 指关节模式 - } - } - chipConfig { // 器件私有信息配置 - template touchChip { // 模板 - match_attr = ""; - chipName = "gt911"; // 触摸屏IC型号 - vendorName = "zsj"; // 供应商 - chipInfo = "AAAA11222"; // 1~4字符代表产品名,5~6字符代表IC型号,7~9字符代表模型型号 - busType = 0; // 0代表I2C,1代表SPI - deviceAddr = 0x5D; // 器件IC通信地址 - irqFlag = 2; // 1代表上升沿触发,2代表下降沿触发,4代表高电平触发,8代表低电平触发 - maxSpeed = 400; // 最大通信速率为400Hz - chipVersion = 0; // 触摸屏IC版本号 - powerSequence { - /* 上电时序的配置含义说明: - [类型, 状态, 方向 , 延时] - 0代表空,1代表vcc电源(1.8V),2代表VCI电源(3.3V),3代表复位管脚,4代表中断管脚 - 0代表下电或拉低,1代表上电或拉高,2代表无操作 - 0代表输入方向,1代表输出方向,2代表无操作 - 代表延时多少毫秒, 例如20代表延时20ms - */ - powerOnSeq = [4, 0, 1, 0, // 中断管脚配置为输出,且进行拉低 - 3, 0, 1, 10, // 复位管脚配置为输出,且进行拉低,延时10ms - 3, 1, 2, 60, // 复位管脚无操作,且进行拉高,延时60ms - 4, 2, 0, 0]; // 中断管脚配置为输入 - suspendSeq = [3, 0, 2, 10]; // 复位管脚无操作,且进行拉低,延时10ms - resumeSeq = [3, 1, 2, 10]; // 复位管脚无操作,且进行拉高,延时10ms - powerOffSeq = [3, 0, 2, 10, // 复位管脚无操作,且进行拉低,延时10ms - 1, 0, 2, 20]; // 电源正极管脚无操作,且进行拉低,延时20ms - } - } - - chip0 :: touchChip { - match_attr = "zsj_gt911_5p5"; // 与设备描述配置信息中器件私有配置信息的“match_attr”字段保持一致 - chipInfo = "ZIDN45100"; // 产品名+模组编号+芯片编号的组合信息 用于给用户态区分当前器件 - chipVersion = 0; // IC型号的版本 - } - } - } - } - } -} -``` - -示例中“touchConfig”包含了“touch0”,"touch0"包含了“boardConfig”与“chipConfig”;“boardConfig”字段包含了Hi3516DV300板级硬件信息,“chipConfig”包含了触摸屏器件的私有信息,如果需要替换触摸屏器件,重新配置“chipConfig”对应的字段信息即可。同时产品可以配置多款触摸屏,示例中用“touch0”代表了套件中默认的触摸屏的硬件接口以及器件的配置信息,如产品需要配置副屏,可在与“touch0”并列的位置配置“touch1”的信息。 - -### 适配器件私有驱动 - -Input模型对Input设备开发流程进行了抽象,开发者只需要适配器件驱动层,无需改动管理驱动层以及公共驱动层。 - -Input模型由三层驱动组成,开发者适配一款全新触摸屏驱动只需要适配器件驱动层即可,重点实现差异化接口,本小节以代码示例的形式展示开发者需要重点完成的工作。 - -1. 触摸屏器件差异化接口适配 - - 示例代码路径:./drivers/framework/model/input/driver/touchscreen/touch\_gt911.c - - ``` - static struct TouchChipOps g_gt911ChipOps = { // 器件IC接口 - .Init = ChipInit, // 初始化 - .Detect = ChipDetect, // 器件检测 - .Resume = ChipResume, // 唤醒 - .Suspend = ChipSuspend, // 休眠 - .DataHandle = ChipDataHandle, // 器件数据读取 - .UpdateFirmware = UpdateFirmware, // 固件升级 - }; - - /* 不同触摸屏厂家使用的IC不一样,对应的寄存器操作也不一样,因此器件驱动层代码重点适配差异化接口部分,如下示例代码展示了GT911的数据解析*/ - - static int32_t ChipDataHandle(ChipDevice *device) - { - ... - /* GT911获取坐标之前需先读取状态寄存器 */ - reg[0] = (GT_BUF_STATE_ADDR >> ONE_BYTE_OFFSET) & ONE_BYTE_MASK; - reg[1] = GT_BUF_STATE_ADDR & ONE_BYTE_MASK; - ret = InputI2cRead(i2cClient, reg, GT_ADDR_LEN, &touchStatus, 1); - if (ret < 0 || touchStatus == GT_EVENT_INVALID) { - return HDF_FAILURE; - } - ... - /* 根据状态寄存器的值读取数据寄存器数据 */ - reg[0] = (GT_X_LOW_BYTE_BASE >> ONE_BYTE_OFFSET) & ONE_BYTE_MASK; - reg[1] = GT_X_LOW_BYTE_BASE & ONE_BYTE_MASK; - pointNum = touchStatus & GT_FINGER_NUM_MASK; - if (pointNum == 0 || pointNum > MAX_SUPPORT_POINT) { - HDF_LOGE("%s: pointNum is invalid, %u", __func__, pointNum); - (void)ChipCleanBuffer(i2cClient); - OsalMutexUnlock(&device->driver->mutex); - return HDF_FAILURE; - } - frame->realPointNum = pointNum; - frame->definedEvent = TOUCH_DOWN; - (void)InputI2cRead(i2cClient, reg, GT_ADDR_LEN, buf, GT_POINT_SIZE * pointNum); - /* 对获取的数据进行解析 */ - ParsePointData(device, frame, buf, pointNum); - ... - } - static void ParsePointData(ChipDevice *device, FrameData *frame, uint8_t *buf, uint8_t pointNum) - { - ... - /* 每个坐标值由两个字节组成,对获取的单字节数据进行拼接得到最终的坐标值 */ - for (i = 0; i < pointNum; i++) { - frame->fingers[i].trackId = buf[GT_POINT_SIZE * i + GT_TRACK_ID]; - frame->fingers[i].y = (buf[GT_POINT_SIZE * i + GT_X_LOW] & ONE_BYTE_MASK) | - ((buf[GT_POINT_SIZE * i + GT_X_HIGH] & ONE_BYTE_MASK) << ONE_BYTE_OFFSET); - frame->fingers[i].x = (buf[GT_POINT_SIZE * i + GT_Y_LOW] & ONE_BYTE_MASK) | - ((buf[GT_POINT_SIZE * i + GT_Y_HIGH] & ONE_BYTE_MASK) << ONE_BYTE_OFFSET); - /* 对解析出来的坐标值进行打印 */ - HDF_LOGD("%s: x = %d, y = %d", __func__, frame->fingers[i].x, frame->fingers[i].y); - } - } - ``` - -2. 器件层驱动初始化及注册驱动至HDF框架 - - 示例代码路径:./drivers/framework/model/input/driver/touchscreen/touch\_gt911.c - - ``` - static int32_t HdfGoodixChipInit(struct HdfDeviceObject *device) - { - ... - /* 器件配置结构体内存申请、配置信息解析及挂载 */ - chipCfg = ChipConfigInstance(device); - ... - /* 器件实例化 */ - chipDev = ChipDeviceInstance(); - ... - /* 器件信息挂载及器件私有操作挂载 */ - chipDev->chipCfg = chipCfg; - chipDev->ops = &g_gt911ChipOps; - ... - /* 注册器件驱动至平台驱动 */ - RegisterChipDevice(chipDev); - ... - } - struct HdfDriverEntry g_touchGoodixChipEntry = { - .moduleVersion = 1, - .moduleName = "HDF_TOUCH_GT911", // 该moduleName与device_info.hcs文件中器件驱动层的moduleName信息相匹配 - .Init = HdfGoodixChipInit, // 器件驱动初始化函数 - }; - HDF_INIT(g_touchGoodixChipEntry); // 注册器件驱动至HDF框架 - ``` - - 器件私有驱动层主要实现了各器件厂商差异较大的部分,如器件休眠唤醒、数据解析以及固件升级等。 - - 至此,基于HDF框架及Input模型的触摸屏驱动适配完成。 - - -## 编译及烧录 - -1. 编辑Makefile文件,添加本示例中的内容: - - 文件路径:./drivers/adapter/khdf/linux/model/input/Makefile - - 添加内容如下: - - ``` - obj-$(CONFIG_DRIVERS_HDF_TP_5P5_GT911) += \ - $(INPUT_ROOT_DIR)/touchscreen/touch_gt911.o - ``` - - 其中touch\_gt911.o为本示例中追加的内容。 - -2. 具体编译及烧录操作请参考[标准系统快速入门编译及烧录章节](/pages/01020201)。 - -## 调试验证 - -如下所示为开机启动日志部分截取 - -``` -[I/HDF_INPUT_DRV] HdfInputManagerInit: enter // 管理驱动层初始化 -[I/HDF_INPUT_DRV] HdfInputManagerInit: exit succ // 初始化成功 -[I/osal_cdev] add cdev hdf_input_host success -[I/HDF_LOG_TAG] HdfTouchDriverProbe: enter // 公共驱动层初始化 -[I/HDF_LOG_TAG] HdfTouchDriverProbe: main_touch exit succ // 初始化成功 -[I/osal_cdev] add cdev hdf_input_event1 success -[I/HDF_INPUT_DRV] HdfGoodixChipInit: enter // 器件驱动层初始化 -[I/HDF_INPUT_DRV] ChipDetect: IC FW version is 0x1060 -[I/HDF_INPUT_DRV] Product_ID: 911_1060, x_sol = 960, y_sol = 480 -[I/HDF_LOG_TAG] ChipDriverInit: chipDetect succ, ret = 0 -[I/HDF_LOG_TAG] InputDeviceInstance: inputDev->devName = main_touch -[I/HDF_INPUT_DRV] HdfGoodixChipInit: exit succ, chipName = gt911 // 初始化成功 -``` - -## Input模型工作流程解析 - -为了让开发者更清晰的了解Input模型工作流程,本节将对input模型加载的关键流程代码进行说明。 - ->![](/images/device-dev/public_sys-resources/icon-notice.gif) **须知:** ->本章节为Input模型工作流程说明,开发者无需进行开发。 - -### 私有配置信息解析 - -示例代码路径:./drivers/framework/model/input/driver/input\_config\_parser.c - -根据OSAL提供的配置解析函数,可以将hcs文件中各字段含义进行解析,具体请参考input\_config\_parser.c中各函数的实现。如果提供的模板不能满足需求,在hcs文件中添加相应信息后,需要根据添加的字段开发相应的解析函数。 - -``` -static int32_t ParseAttr(struct DeviceResourceIface *parser, const struct DeviceResourceNode *attrNode, BoardAttrCfg *attr) -{ - int32_t ret; - ret = parser->GetUint8(attrNode, "inputType", &attr->devType, 0); // 获取inputType字段信息,保存在BoardAttrCfg结构体中 - CHECK_PARSER_RET(ret, "GetUint8"); - ... - return HDF_SUCCESS; -} -``` - -### 管理驱动层初始化及注册驱动至HDF框架 - -示例代码路径:./drivers/framework/model/input/driver/hdf\_input\_device\_manager.c - -``` -static int32_t HdfInputManagerInit(struct HdfDeviceObject *device) -{ - /* 分配内存给manager,manager中将存放所有input设备 */ - g_inputManager = InputManagerInstance(); - ... -} -struct HdfDriverEntry g_hdfInputEntry = { - .moduleVersion = 1, - .moduleName = "HDF_INPUT_MANAGER", - .Bind = HdfInputManagerBind, - .Init = HdfInputManagerInit, - .Release = HdfInputManagerRelease, -}; - -HDF_INIT(g_hdfInputEntry); //驱动注册入口 -``` - -### 公共驱动层初始化及注册驱动至HDF框架 - -示例代码路径:./drivers/framework/model/input/driver/hdf\_touch.c - -``` -static int32_t HdfTouchDriverProbe(struct HdfDeviceObject *device) -{ - ... - /* 板级信息结构体内存申请及hcs配置信息解析 */ - boardCfg = BoardConfigInstance(device); - ... - /* 公共驱动结构体内存申请 */ - touchDriver = TouchDriverInstance(); - ... - /* 依据解析出的板级信息进行公共资源初始化,如IIC初始化 */ - ret = TouchDriverInit(touchDriver, boardCfg); - if (ret == HDF_SUCCESS) { - ... - /* 添加驱动至公共驱动层驱动管理链表,当设备与驱动进行绑定时使用该链表进行查询 */ - AddTouchDriver(touchDriver); - ... - } - ... -} -struct HdfDriverEntry g_hdfTouchEntry = { - .moduleVersion = 1, - .moduleName = "HDF_TOUCH", - .Bind = HdfTouchDriverBind, - .Init = HdfTouchDriverProbe, - .Release = HdfTouchDriverRelease, -}; - -HDF_INIT(g_hdfTouchEntry); //驱动注册入口 -``` - -### 器件驱动层初始化及注册驱动至HDF框架 - -具体请参考[适配器件私有驱动](#section17127331595)器件层驱动初始化及注册驱动至HDF框架部分。 - -### 具体调用逻辑串联函数 - -Input模型管理层驱动init函数初始化了设备管理链表,公共驱动层初始化函数完成了相关结构体的内存申请。器件驱动相关信息通过RegisterChipDevice函数对公共驱动层相关结构体进行信息填充,同时完成了相关硬件信息的初始化(如中断注册等),绑定设备与驱动组成inputDev通过RegisterInputDevice函数向驱动管理层进行注册,在RegisterInputDevice函数中主要实现了将inputDev向设备管理链表的添加等功能。如下所示为两个函数的实现部分: - -``` -//函数具体实现代码位置 :./drivers/framework/model/input/driver/hdf_touch.c -int32_t RegisterChipDevice(ChipDevice *chipDev) -{ - ... - /* 绑定设备与驱动,从而通过InputDeviceInstance函数创建inputDev */ - DeviceBindDriver(chipDev); - ... - /* 主要包含器件中断注册及中断处理函数,中断处理函数中有数据上报用户态的数据通道 */ - ChipDriverInit(chipDev); - ... - /* 申请内存实例化InputDev */ - inputDev = InputDeviceInstance(chipDev); - ... - /* 将InputDev设备注册至input驱动管理层 */ - RegisterInputDevice(inputDev); - ... -} - -//函数具体实现代码位置 :./drivers/framework/model/input/driver/hdf_input_device_manager.c -int32_t RegisterInputDevice(InputDevice *inputDev) -{ - ... - /* 申请ID,该ID对于不同input设备唯一 */ - ret = AllocDeviceID(inputDev); - ... - /* 该函数包含了对hid类设备的特殊处理,对于触摸屏驱动,该函数无实质操作; */ - CreateDeviceNode(inputDev); - /* 内核态数据传送至用户态需使用IOService能力,需要申请buffer */ - AllocPackageBuffer(inputDev); - /* 将input设备添加进设备全局管理链表 */ - AddInputDevice(inputDev); - ... -} -``` - diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/01.\345\272\224\347\224\250\345\274\200\345\217\221\345\277\253\351\200\237\345\205\245\351\227\250/01.\345\274\200\345\217\221\345\207\206\345\244\207.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/01.\345\272\224\347\224\250\345\274\200\345\217\221\345\277\253\351\200\237\345\205\245\351\227\250/01.\345\274\200\345\217\221\345\207\206\345\244\207.md" deleted file mode 100644 index c12e4e91c31898564d4b9fd93f7b2c38a5cf5f45..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/01.\345\272\224\347\224\250\345\274\200\345\217\221\345\277\253\351\200\237\345\205\245\351\227\250/01.\345\274\200\345\217\221\345\207\206\345\244\207.md" +++ /dev/null @@ -1,48 +0,0 @@ ---- -title: 开发准备 -permalink: /pages/01080101 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:26 ---- -# 开发准备 - -## 任务说明 - -本文档适用于OpenHarmony应用开发的初学者。通过构建一个简单的具有页面跳转功能的应用(如下图[预览器](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/previewer-0000001054328973#ZH-CN_TOPIC_0000001056725592__section16523172216252)运行效果所示),熟悉OpenHarmony应用开发流程。 - -为确保运行效果,本文以使用**DevEco Studio 3.0 Beta2**版本为例,点击[此处](https://developer.harmonyos.com/cn/develop/deveco-studio#download_beta)获取下载链接。 - -![zh-cn_image_0000001089359413](/images/application-dev/quick-start/figures/zh-cn_image_0000001089359413.png) - -**表1** 方舟开发框架的对比 - -| 比较项 | 基于JS扩展的类Web开发范式 | 基于TS扩展的声明式开发范式 | -| -------- | -------- | -------- | -| 语言生态 | JS | eTS | -| 接口方式 | 类Web范式 | 声明式 | -| 执行方式 | 框架层处理,基于数据驱动的UI自动变更 | 框架层处理,基于数据驱动的UI自动变更 | -| 相对优势 | 轻量化,开发更简便 | 极简开发,内存占用更少、运行性能更高 | - -接下来,分别使用JS语言、eTS语言实现上述两个页面跳转的功能。 - - -## 开发准备 - -1. 开始前请参考[配置OpenHarmony SDK](/pages/01080903),完成**DevEco Studio**的安装和开发环境配置。 - -2. 开发环境配置完成后,请参考[创建OpenHarmony工程](/pages/0108090401)创建工程。 - - 使用JS语言开发,模板选择Empty Ability,Language选择JS。 - - - 使用eTS语言开发,模板选择Empty Ability,Language选择eTS。 - -3. 工程创建完成后,使用[预览器](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/previewer-0000001054328973#ZH-CN_TOPIC_0000001056725592__section16523172216252)运行该工程。 - -完成上述操作后,请参考[使用JS语言开发](/pages/01080102)、[使用eTS语言开发](/pages/01080103)继续下一步的学习。 - diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/01.\345\272\224\347\224\250\345\274\200\345\217\221\345\277\253\351\200\237\345\205\245\351\227\250/02.\344\275\277\347\224\250JS\350\257\255\350\250\200\345\274\200\345\217\221.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/01.\345\272\224\347\224\250\345\274\200\345\217\221\345\277\253\351\200\237\345\205\245\351\227\250/02.\344\275\277\347\224\250JS\350\257\255\350\250\200\345\274\200\345\217\221.md" deleted file mode 100644 index 3bb2c2c7e094780ce3ebd62f1557e92d7b953c01..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/01.\345\272\224\347\224\250\345\274\200\345\217\221\345\277\253\351\200\237\345\205\245\351\227\250/02.\344\275\277\347\224\250JS\350\257\255\350\250\200\345\274\200\345\217\221.md" +++ /dev/null @@ -1,118 +0,0 @@ ---- -title: 使用JS语言开发 -permalink: /pages/01080102 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:26 ---- -# 使用JS语言开发(传统代码方式) - -为确保运行效果,本文以使用**DevEco Studio 3.0 Beta2**版本为例,点击[此处](https://developer.harmonyos.com/cn/develop/deveco-studio#download_beta)获取下载链接。 - -## 编写第一个页面 - -1. 第一个页面内有一个文本和一个按钮,通过text和button组件来实现。 - 在"Project"窗口,选择entry > src > main > js > default > pages > index,打开index.hml文件,添加一个文本和一个按钮,示例代码如下: - ``` - -
- - - Hello World - - - -
- ``` - -2. 打开index.css文件,设置文本和按钮的样式,示例代码如下: - ``` - /* index.css */ - .container { - flex-direction: column; /* 设置容器内的项目纵向排列 */ - justify-content: center; /* 设置项目位于容器主轴的中心 */ - align-items: center; /* 项目在交叉轴居中 */ - width:100%; - height:100%; - } - /* 对class="text"的组件设置样式 */ - .text{ - font-size: 42px; - } - /* 对class="button"的组件设置样式 */ - .button { - width: 240px; - height: 60px; - background-color: #007dff; - font-size: 30px; - text-color: white; - margin-top: 20px; - } - ``` - -3. 使用[预览器](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/previewer-0000001054328973#ZH-CN_TOPIC_0000001056725592__section16523172216252)运行项目,效果如下图所示: - - ![zh-cn_image_0000001167690688](/images/application-dev/quick-start/figures/zh-cn_image_0000001167690688.png) - - -## 创建另一个页面 - -1. 在"Project"窗口,打开entry > src > main > js > default,右键点击pages文件夹,选择NewJS Page,命名为details,单击回车键。 - 创建完成后,可以看到pages文件夹下的文件目录结构如下: - - ![zh-cn_image_0000001167850660](/images/application-dev/quick-start/figures/zh-cn_image_0000001167850660.png) - -2. 打开details.hml文件,添加一个文本,示例代码如下: - ``` - -
- - Hi there - -
- ``` - -3. 打开details.css文件,设置文本的样式,示例代码如下: - ``` - /* details.css */ - .container { - flex-direction: column; - justify-content: center; - align-items: center; - width:100%; - height:100%; - } - .text { - font-size: 42px; - text-align: center; - } - ``` - - -## 实现页面跳转 - -1. 打开第一个页面的index.js文件,导入router模块,页面路由router根据页面的uri来找到目标页面,从而实现跳转。示例代码如下: - ``` - // index.js - import router from '@system.router'; - - export default { - launch() { - router.push ({ - uri:'pages/details/details', // 指定要跳转的页面 - }) - } - } - ``` - -2. 再次使用[预览器](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/previewer-0000001054328973#ZH-CN_TOPIC_0000001056725592__section16523172216252)运行项目,效果如下图所示: - - ![zh-cn_image_0000001213130527](/images/application-dev/quick-start/figures/zh-cn_image_0000001213130527.png) - -恭喜你,至此已成功完成OpenHarmony快速入门-使用JS语言开发。 diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/01.\345\272\224\347\224\250\345\274\200\345\217\221\345\277\253\351\200\237\345\205\245\351\227\250/03.\344\275\277\347\224\250eTS\350\257\255\350\250\200\345\274\200\345\217\221.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/01.\345\272\224\347\224\250\345\274\200\345\217\221\345\277\253\351\200\237\345\205\245\351\227\250/03.\344\275\277\347\224\250eTS\350\257\255\350\250\200\345\274\200\345\217\221.md" deleted file mode 100644 index 47f34d34fa09cc4786a2ec9ca62c3e43ba72504e..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/01.\345\272\224\347\224\250\345\274\200\345\217\221\345\277\253\351\200\237\345\205\245\351\227\250/03.\344\275\277\347\224\250eTS\350\257\255\350\250\200\345\274\200\345\217\221.md" +++ /dev/null @@ -1,131 +0,0 @@ ---- -title: 使用eTS语言开发 -permalink: /pages/01080103 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:26 ---- -# 使用eTS语言开发 - -> ![icon-note.gif](/images/application-dev/quick-start/public_sys-resources/icon-note.gif) **说明:** -> 请使用DevEco Studio V3.0.0.601 Beta1及更高版本。本文以使用**DevEco Studio 3.0 Beta2**版本为例,点击[此处](https://developer.harmonyos.com/cn/develop/deveco-studio#download_beta)获取下载链接。 - - -## 创建eTS工程 - -1. 打开DevEco Studio,创建一个新工程,选择模板,如Empty Ability: - - ![zh-cn_image_0000001238733799](/images/application-dev/quick-start/figures/zh-cn_image_0000001238733799.png) - -2. 进入配置工程界面,Project Type选择Application,Language选择eTS,其他参数根据实际需要设置即可。 - - ![zh-cn_image_0000001238853759](/images/application-dev/quick-start/figures/zh-cn_image_0000001238853759.png) - - -## 编写第一个页面 - -1. 工程创建完成后,在"Project"窗口,点击entry > src > main > ets > default > pages,打开index.ets文件。 - - ![zh-cn_image_0000001213883165](/images/application-dev/quick-start/figures/zh-cn_image_0000001213883165.png) - -2. 第一个页面由Flex容器组件、Text组件和Button组件构成。在index.ets中编写并设置页面组件的属性和样式,示例代码如下所示: - ``` - @Entry - @Component - struct Index { - build() { - //Flex容器组件 - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - //Text组件 - Text('Hello World') - .fontSize(60) - .fontWeight(500) - //Button组件 - Button('Next') - .fontSize(40) - .fontWeight(500) - .width(280) - .height(60) - } - //容器整体宽高 - .width('100%') - .height('100%') - } - } - ``` - -3. 使用[预览器](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/previewer-0000001054328973#ZH-CN_TOPIC_0000001056725592__section16523172216252)运行项目,效果如下图所示: - - ![zh-cn_image_0000001168898456](/images/application-dev/quick-start/figures/zh-cn_image_0000001168898456.png) - - -## 创建第二个页面 - -1. 在"Project"窗口,打开entry > src > main > ets > default,右键点击pages文件夹,选择NeweTS Page,命名为details,单击回车键。创建完成后,可以看到pages文件夹下的文件目录结构如下: - - ![zh-cn_image_0000001214043107](/images/application-dev/quick-start/figures/zh-cn_image_0000001214043107.png) - -2. 第二个页面由Flex容器组件、Text组件构成。在details.ets中编写并设置页面组件的属性和样式,示例代码如下所示: - ``` - @Entry - @Component - struct Details { - build() { - //Flex容器组件 - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - //Text组件 - Text('Hi there') - .fontSize(60) - .fontWeight(500) - } - //容器整体宽高 - .width('100%') - .height('100%') - } - } - ``` - - -## 实现页面跳转 - -1. 打开第一个页面的index.ets文件,导入router模块,页面路由router根据页面的uri来找到目标页面,从而实现跳转。示例代码如下: - ``` - //导入router模块 - import router from '@system.router'; - @Entry - @Component - struct Index { - build() { - //Flex容器组件 - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - //Text组件 - Text('Hello World') - .fontSize(60) - .fontWeight(500) - //Button组件 - Button('Next') - .fontSize(40) - .fontWeight(500) - .width(280) - .height(60) - //点击Button实现页面跳转 - .onClick(() => { router.push({ uri: 'pages/details' }) }) - } - //容器整体宽高 - .width('100%') - .height('100%') - } - } - ``` - -2. 再次使用[预览器](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/previewer-0000001054328973#ZH-CN_TOPIC_0000001056725592__section16523172216252)运行项目,效果如下图所示: - - ![zh-cn_image_0000001169221404](/images/application-dev/quick-start/figures/zh-cn_image_0000001169221404.png) - -恭喜你,至此已成功完成OpenHarmony快速入门-使用eTS语言开发。 diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/01.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\346\246\202\350\277\260.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/01.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\346\246\202\350\277\260.md" deleted file mode 100644 index 3fa79b340fdb391504ac6a8281f509b0aaa53157..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/01.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\346\246\202\350\277\260.md" +++ /dev/null @@ -1,70 +0,0 @@ ---- -title: 方舟开发框架概述 -permalink: /pages/01080201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:26 ---- -# 方舟开发框架概述 - -## 框架介绍 - -方舟开发框架,是OpenHarmony的一套UI开发框架,提供开发者进行应用UI开发时所必须的能力。 - - -## 基本概念 - -- **组件**:组件是界面搭建与显示的最小单位。开发者通过多种组件的组合,构建出满足自身应用诉求的完整界面。 - -- **页面**:page页面是方舟开发框架最小的调度分割单位。开发者可以将应用设计为多个功能页面,每个页面进行单独的文件管理,并通过路由API实现页面的调度管理,以实现应用内功能的解耦。 - - -## 主要能力 - -- **多种组件**:方舟开发框架不仅提供了多种基础组件,如文本显示、图片显示、按键交互等,也提供了支持视频播放能力的媒体组件。并且针对不同类型设备进行了组件设计,提供了组件在不同平台上的样式适配能力,此种组件称为“多态组件”。 - -- **布局计算**:UI界面设计离不开布局的参与。方舟开发框架提供了多种布局方式,不仅保留了经典的弹性布局能力,也提供了列表、宫格、栅格布局和适应多分辨率场景开发的原子布局能力。 - -- **动画能力**:方舟开发框架对于UI界面的美化,除了组件内置动画效果外,也提供了属性动画、转场动画和自定义动画能力。 - -- **UI交互**:方舟开发框架提供了多种交互能力,满足应用在不同平台通过不同输入设备均可正常进行UI交互响应,默认适配了触摸手势、遥控器、鼠标等输入操作,同时也提供事件通知能力。 - -- **绘制**:方舟开发框架提供了多种绘制能力,以满足开发者绘制自定义形状的需求,支持图形绘制、颜色填充、文本绘制、图片绘制等。 - -- **平台API通道**:方舟开发框架提供了API扩展机制,平台能力通过此种机制进行封装,提供风格统一的JS接口。 - - -## 选择方案 - -方舟开发框架针对不同目的和技术背景的开发者提供了两种开发范式,分别是基于JS扩展的类Web开发范式(简称“类Web开发范式”)和基于TS扩展的声明式开发范式(简称“声明式开发范式”)。下面我们对这两种开发范式进行对比与描述。 - - -### 类Web开发范式 - -类Web开发范式,采用经典的HML、CSS、JavaScript三段式开发方式。使用HML标签文件进行布局搭建,使用CSS文件进行样式描述,使用JavaScript文件进行逻辑处理。UI组件与数据之间通过单向数据绑定的方式建立关联,当数据发生变化时,UI界面自动触发更新。此种开发方式,更接近Web前端开发者的使用习惯,快速将已有的Web应用改造成方舟开发框架应用。主要适用于界面较为简单的中小型应用开发。 - - -### 声明式开发范式 - -声明式开发范式,采用TS语言并进行声明式UI语法扩展,从组件、动效和状态管理三个维度提供了UI绘制能力。UI开发更接近自然语义的编程方式,让开发者直观地描述UI界面,不必关心框架如何实现UI绘制和渲染,实现极简高效开发。同时,选用有类型标注的TS语言,引入编译期的类型校验,更适用大型的应用开发。 - - -### 两种开发范式对比 - -| **开发范式名称** | **语言生态** | **UI更新方式** | **适用场景** | **适用人群** | -| -------- | -------- | -------- | -------- | -------- | -| 类Web开发范式 | JS语言 | 数据驱动更新 | 界面较为简单的类小程序应用和卡片 | Web前端开发人员 | -| 声明式开发范式 | 扩展的TS语言(eTS) | 数据驱动更新 | 复杂度较大、团队合作度较高的程序 | 移动系统应用开发人员、系统应用开发人员 | - - -### 框架结构 - -![zh-cn_image_0000001183709904](/images/application-dev/ui/figures/zh-cn_image_0000001183709904.png) - -从上图可以看出,类Web开发范式与声明式开发范式的UI后端引擎和语言运行时是共用的,其中,UI后端引擎实现了方舟开发框架的六种基本能力。声明式开发范式无需JS Framework进行页面DOM管理,渲染更新链路更为精简,占用内存更少,因此更推荐开发者选用声明式开发范式来搭建应用UI界面。 diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\346\246\202\350\277\260.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\346\246\202\350\277\260.md" deleted file mode 100644 index 600628399652d4543e3068b59351da3d7620402a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\346\246\202\350\277\260.md" +++ /dev/null @@ -1,43 +0,0 @@ ---- -title: 概述 -permalink: /pages/0108020201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:26 ---- -# 概述 - -基于JS扩展的类Web开发范式的方舟开发框架是OpenHarmony UI开发框架,提供基础类、容器类、画布类等UI组件和标准CSS动画能力,支持类Web范式编程。 - - -## 基础能力 - -- **类Web范式编程** - 采用类HTML和CSS Web编程语言作为页面布局和页面样式的开发语言,页面业务逻辑则支持ECMAScript规范的JavaScript语言。方舟开发框架提供的类Web编程范式,可以让开发者避免编写UI状态切换的代码,视图配置信息更加直观。 - - -## 整体架构 - -使用基于JS扩展的类Web开发范式的方舟开发框架,包括应用层(Application)、前端框架层(Framework)、引擎层(Engine)和平台适配层(Porting Layer)。 - - - -![zh-cn_image_0000001117452952](/images/application-dev/ui/figures/zh-cn_image_0000001117452952.png) - -- **Application** - 应用层表示开发者开发的FA应用,这里的FA应用特指JS FA应用。 - -- **Framework** - 前端框架层主要完成前端页面解析,以及提供MVVM(Model-View-ViewModel)开发模式、页面路由机制和自定义组件等能力。 - -- **Engine** - 引擎层主要提供动画解析、DOM(Document Object Model)树构建、布局计算、渲染命令构建与绘制、事件管理等能力。 - -- **Porting Layer** - 适配层主要完成对平台层进行抽象,提供抽象接口,可以对接到系统平台。比如:事件对接、渲染管线对接和系统生命周期对接等。 diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/01.\346\226\207\344\273\266\347\273\204\347\273\207.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/01.\346\226\207\344\273\266\347\273\204\347\273\207.md" deleted file mode 100644 index 93863101b4e90c3d91ba38f491fe37baa163964a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/01.\346\226\207\344\273\266\347\273\204\347\273\207.md" +++ /dev/null @@ -1,98 +0,0 @@ ---- -title: 文件组织 -permalink: /pages/010802020201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:26 ---- -# 文件组织 - -## 目录结构 - -JS FA应用的JS模块(entry/src/main/js/module)的典型开发目录结构如下: - -**图1** 目录结构 - -![zh-cn_image_0000001127284926](/images/application-dev/ui/figures/zh-cn_image_0000001127284926.png) - -**图2** 多实例资源共享目录结构 -![zh-cn_image_0000001173164777](/images/application-dev/ui/figures/zh-cn_image_0000001173164777.png) - -目录结构中文件分类如下: - -- .hml结尾的HML模板文件,这个文件用来描述当前页面的文件布局结构。 - -- .css结尾的CSS样式文件,这个文件用于描述页面样式。 - -- .js结尾的JS文件,这个文件用于处理页面和用户的交互。 - -各个文件夹的作用: - -- app.js文件用于全局JavaScript逻辑和应用生命周期管理,详见[app.js](/pages/010802020203)说明。 - -- pages目录用于存放所有组件页面。 - -- common目录用于存放公共资源文件,比如:媒体资源,自定义组件和JS文件。 - -- resources目录用于存放资源配置文件,比如:多分辨率加载等配置文件,详见[资源限定与访问](/pages/010802020206)章节。 - -- share目录用于配置多个实例共享的资源内容,比如:share中的图片和JSON文件可被default1和default2实例共享。 - -> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** -> - i18n和resources是开发保留文件夹,不可重命名。 -> -> -> - 如果share目录中的资源和实例(default)中的资源文件同名且目录一致时,实例中资源的优先级高于share中资源的优先级。 -> -> -> - share目录当前不支持i18n。 -> -> - 在使用DevEco Studio进行应用开发时,目录结构中的可选文件夹需要开发者根据实际情况自行创建。 - - -## 文件访问规则 - -应用资源可通过绝对路径或相对路径的方式进行访问,本开发框架中绝对路径以"/"开头,相对路径以"./"或"../"。具体访问规则如下: - -- 引用代码文件,推荐使用相对路径,比如:../common/utils.js。 - -- 引用资源文件,推荐使用绝对路径。比如:/common/xxx.png。 - -- 公共代码文件和资源文件推荐放在common下,通过以上两条规则进行访问。 - -- CSS样式文件中通过url()函数创建<url>数据类型,如:url(/common/xxx.png)。 - -> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** -> 当代码文件A需要引用代码文件B时: -> -> - 如果代码文件A和文件B位于同一目录,则代码文件B引用资源文件时可使用相对路径,也可使用绝对路径。 -> -> - 如果代码文件A和文件B位于不同目录,则代码文件B引用资源文件时必须使用绝对路径。因为Webpack打包时,代码文件B的目录会发生变化。 -> -> -> - 在js文件中通过数据绑定的方式指定资源文件路径时,必须使用绝对路径。 - - -## 媒体文件格式 - -**表1** 支持的图片格式 - -| 格式 | 支持的文件类型 | -| -------- | -------- | -| BMP | .bmp | -| GIF | .gif | -| JPEG | .jpg | -| PNG | .png | -| WebP | .webp | - -**表2** 支持的视频格式 - -| 格式 | 支持的文件类型 | -| -------- | -------- | -| H.264 AVC
Baseline Profile (BP) | .3gp
.mp4 | diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/02.js\346\240\207\347\255\276\351\205\215\347\275\256.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/02.js\346\240\207\347\255\276\351\205\215\347\275\256.md" deleted file mode 100644 index 2358a01c80cdb342c9c9ef6ef1b1af091374e631..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/02.js\346\240\207\347\255\276\351\205\215\347\275\256.md" +++ /dev/null @@ -1,117 +0,0 @@ ---- -title: js标签配置 -permalink: /pages/010802020202 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:26 ---- -# js标签配置 - -js标签中包含了实例名称、页面路由和窗口样式信息。 - - -| 标签 | 类型 | 默认值 | 必填 | 描述 | -| -------- | -------- | -------- | -------- | -------- | -| name | string | default | 是 | 标识JS实例的名字。 | -| pages | Array | - | 是 | 路由信息,详见“**[pages](#pages)**”。 | -| window | Object | - | 否 | 窗口信息,详见“**[window](#window)**”。 | - - -> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** -> name、pages和window等标签配置需在配置文件(config.json)中的“js”标签中完成设置。 - - -## pages - -定义每个页面的路由信息,每个页面由页面路径和页面名组成,页面的文件名就是页面名。比如: - -``` -{ - ... - "pages": [ - "pages/index/index", - "pages/detail/detail" - ] - ... -} -``` - -> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** -> -> - pages列表中第一个页面是应用的首页,即entry入口。 -> -> -> - 页面文件名不能使用组件名称,比如:text.hml、button.hml等。 - -## window - -window用于定义与显示窗口相关的配置。对于屏幕适配问题,有2种配置方法: - -- 指定designWidth(屏幕逻辑宽度),所有与大小相关的样式(例如width、font-size)均以designWidth和实际屏幕宽度的比例进行缩放,例如在designWidth为720时,如果设置width为100px时,在实际宽度为1440物理像素的屏幕上,width实际渲染像素为200物理像素。 - -- 设置autoDesignWidth为true,此时designWidth字段将会被忽略,渲染组件和布局时按屏幕密度进行缩放。屏幕逻辑宽度由设备宽度和屏幕密度自动计算得出,在不同设备上可能不同,请使用相对布局来适配多种设备。例如:在466\*466分辨率,320dpi的设备上,屏幕密度为2(以160dpi为基准),1px等于渲染出的2物理像素。 - - > ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** - > 1. 组件样式中<length>类型的默认值,按屏幕密度进行计算和绘制,如:在屏幕密度为2(以160dpi为基准)的设备上,默认<length>为1px时,设备上实际渲染出2物理像素。 - > - > 2. autoDesignWidth、designWidth的设置不影响默认值计算方式和绘制结果。 - -| 属性 | 类型 | 必填 | 缺省值 | 描述 | -| -------- | -------- | -------- | -------- | -------- | -| designWidth | number | 否 | 720
| 页面显示设计时的参考值,实际显示效果基于设备宽度与参考值之间的比例进行缩放。 | -| autoDesignWidth | boolean | 否 | false | 页面设计基准宽度是否自动计算,当设为true时,designWidth将会被忽略,设计基准宽度由设备宽度与屏幕密度计算得出。 | - -示例如下: -``` -{ - ... - "window": { - "designWidth": 720, - "autoDesignWidth": false - } - ... -} -``` - - -## 示例 - -``` -{ - "app": { - "bundleName": "com.example.player", - "version": { - "code": 1, - "name": "1.0" - }, - "vendor": "example" - } - "module": { - ... - "js": [ - { - "name": "default", - "pages": [ - "pages/index/index", - "pages/detail/detail" - ], - "window": { - "designWidth": 720, - "autoDesignWidth": false - } - } - ], - "abilities": [ - { - ... - } - ] - } -} -``` diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/03.app.js.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/03.app.js.md" deleted file mode 100644 index 21e4a5e269869ca086f1ece337941ad735908b49..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/03.app.js.md" +++ /dev/null @@ -1,57 +0,0 @@ ---- -title: app.js -permalink: /pages/010802020203 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false ---- -# app.js - -## 应用生命周期 - -每个应用可以在app.js自定义应用级[生命周期](/pages/010802020205)的实现逻辑,以下示例仅在生命周期函数中打印对应日志: -``` -// app.js -export default { - onCreate() { - console.info('Application onCreate'); - }, - - onDestroy() { - console.info('Application onDestroy'); - }, -} -``` - -## 应用对象6+ - -| 属性 | 类型 | 描述 | -| -------- | -------- | -------- | -| getApp | Function | 提供getApp()全局方法,可以在自定义js文件中获取app.js中暴露的对象。 | - -示例如下: - -``` -// app.js -export default { - data: { - test: "by getAPP" - }, - onCreate() { - console.info('AceApplication onCreate'); - }, - onDestroy() { - console.info('AceApplication onDestroy'); - }, -}; -``` - -``` -// test.js 自定义逻辑代码 -export var appData = getApp().data; -``` diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/04.\350\257\255\346\263\225/01.HML\350\257\255\346\263\225\345\217\202\350\200\203.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/04.\350\257\255\346\263\225/01.HML\350\257\255\346\263\225\345\217\202\350\200\203.md" deleted file mode 100644 index 6c031d9158351f3168936c67db1cae3cb6b496ff..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/04.\350\257\255\346\263\225/01.HML\350\257\255\346\263\225\345\217\202\350\200\203.md" +++ /dev/null @@ -1,400 +0,0 @@ ---- -title: HML语法参考 -permalink: /pages/01080202020401 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:26 ---- -# HML语法参考 - -HML(OpenHarmony Markup Language)是一套类HTML的标记语言,通过组件,事件构建出页面的内容。页面具备数据绑定、事件绑定、列表渲染、条件渲染和逻辑控制等高级能力。 - - -## 页面结构 - -``` - -
- Image Show -
- -
-
-``` - - -## 数据绑定 - -``` - -
- {{content[1]}} -
-``` - -``` -// xxx.js -export default { - data: { - content: ['Hello World!', 'Welcome to my world!'] - }, - changeText: function() { - this.content.splice(1, 1, this.content[0]); - } -} -``` - -> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** -> - 针对数组内的数据修改,请使用splice方法生效数据绑定变更。 -> -> - hml文件中的js表达式不支持ES6语法。 - - -## 普通事件绑定 - -事件通过'on'或者'\@'绑定在组件上,当组件触发事件时会执行JS文件中对应的事件处理函数。 - -事件支持的写法有: - -- "funcName":funcName为事件回调函数名(在JS文件中定义相应的函数实现)。 - -- "funcName(a,b)":函数参数例如a,b可以是常量,或者是在JS文件中的data中定义的变量(前面不用写this.)。 - -- 示例 - ``` - -
- {{count}} -
- - - - - - -
-
- ``` - - ``` - // xxx.js - export default { - data: { - count: 0 - }, - increase() { - this.count++; - }, - decrease() { - this.count--; - }, - multiply(multiplier) { - this.count = multiplier * this.count; - } - }; - ``` - - ``` - /* xxx.css */ - .container { - display: flex; - flex-direction: column; - justify-content: center; - align-items: center; - left: 0px; - top: 0px; - width: 454px; - height: 454px; - } - .title { - font-size: 30px; - text-align: center; - width: 200px; - height: 100px; - } - .box { - width: 454px; - height: 200px; - justify-content: center; - align-items: center; - flex-wrap: wrap; - } - .btn { - width: 200px; - border-radius: 0; - margin-top: 10px; - margin-left: 10px; - } - ``` - - -## 冒泡事件绑定5+ - -冒泡事件绑定包括: - -- 绑定冒泡事件:on:{event}.bubble。on:{event}等价于on:{event}.bubble。 - -- 绑定并阻止冒泡事件向上冒泡:grab:{event}.bubble。grab:{event}等价于grab:{event}.bubble。 - > ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** - > 详细冒泡事件说明参见[通用事件](/pages/010c0201010103)章节。 - -- 示例 - ``` - -
- ; -
-
- -
-
- -
-
- -
-
-
- ``` - - ``` - // xxx.js - export default { - clickfunc: function(e) { - console.log(e); - }, - touchstartfuc: function(e) { - console.log(e); - }, - } - ``` - -> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** -> 采用旧写法(onclick)的事件绑定在最小API版本6以下时采用不冒泡处理,在最小API版本为6及6以上时采用冒泡处理。 - -## 捕获事件绑定5+ - -Touch触摸类事件支持捕获,捕获阶段位于冒泡阶段之前,捕获事件先到达父组件然后达到子组件。 - -捕获事件绑定包括: - -- 绑定捕获事件:on:{event}.capture。 - -- 绑定并阻止事件向下传递:grab:{event}.capture。 - -- 示例 - ``` - -
- -
- -
-
-``` - - ``` - // xxx.js - export default { - touchstartfuc: function(e) { - console.log(e); - }, - } - ``` - - -## 列表渲染 - -``` - -
- - -
- {{$idx}}.{{$item.name}} -
- -
- {{$idx}}.{{value.name}} -
- -
- {{index}}.{{value.name}} -
-
-``` - -``` -// xxx.js -export default { - data: { - array: [ - {id: 1, name: 'jack', age: 18}, - {id: 2, name: 'tony', age: 18}, - ], - }, - changeText: function() { - if (this.array[1].name === "tony"){ - this.array.splice(1, 1, {id:2, name: 'Isabella', age: 18}); - } else { - this.array.splice(2, 1, {id:3, name: 'Bary', age: 18}); - } - }, -} -``` - -tid属性主要用来加速for循环的重渲染,旨在列表中的数据有变更时,提高重新渲染的效率。tid属性是用来指定数组中每个元素的唯一标识,如果未指定,数组中每个元素的索引为该元素的唯一id。例如上述tid="id"表示数组中的每个元素的id属性为该元素的唯一标识。for循环支持的写法如下: - -- for="array":其中array为数组对象,array的元素变量默认为$item。 - -- for="v in array":其中v为自定义的元素变量,元素索引默认为$idx。 - -- for="(i, v) in array":其中元素索引为i,元素变量为v,遍历数组对象array。 - -> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** -> - 数组中的每个元素必须存在tid指定的数据属性,否则运行时可能会导致异常。 -> -> - 数组中被tid指定的属性要保证唯一性,如果不是则会造成性能损耗。比如,示例中只有id和name可以作为tid字段,因为它们属于唯一字段。 -> -> - tid不支持表达式。 - - -## 条件渲染 - -条件渲染分为2种:if/elif/else和show。两种写法的区别在于:第一种写法里if为false时,组件不会在vdom中构建,也不会渲染,而第二种写法里show为false时虽然也不渲染,但会在vdom中构建;另外,当使用if/elif/else写法时,节点必须是兄弟节点,否则编译无法通过。实例如下: - -``` - -
- - - Hello-TV - Hello-Wearable - Hello-World -
-``` - -``` -/* xxx.css */ -.container{ - flex-direction: column; - align-items: center; -} -.btn{ - width: 280px; - font-size: 26px; - margin: 10px 0; -} -``` - -``` -// xxx.js -export default { - data: { - visible: false, - display: true, - }, - toggleShow: function() { - this.visible = !this.visible; - }, - toggleDisplay: function() { - this.display = !this.display; - } -} -``` - -优化渲染优化:show方法。当show为true时,节点正常渲染;当为false时,仅仅设置display样式为none。 - -``` - -
- - Hello World -
-``` - -``` -/* xxx.css */ -.container{ - flex-direction: column; - align-items: center; -} -.btn{ - width: 280px; - font-size: 26px; - margin: 10px 0; -} -``` - -``` -// xxx.js -export default { - data: { - visible: false, - }, - toggle: function() { - this.visible = !this.visible; - }, -} -``` - -> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** -> 禁止在同一个元素上同时设置for和if属性。 - -## 逻辑控制块 - -<block>控制块使得循环渲染和条件渲染变得更加灵活;block在构建时不会被当作真实的节点编译。注意block标签只支持for和if属性。 - -``` - - - - - {{$item.name}} - - - - {{$item.color}} - - - - -``` - -``` -// xxx.js -export default { - data: { - glasses: [ - {name:'sunglasses', kinds:[{name:'XXX',color:'XXX'},{name:'XXX',color:'XXX'}]}, - {name:'nearsightedness mirror', kinds:[{name:'XXX',color:'XXX'}]}, - ], - }, -} -``` - -## 模板引用 - -HML可以通过element引用模板文件,详细介绍可参考[自定义组件](/pages/010c02010201)章节。 - -``` - -
- Name: {{name}} - Age: {{age}} -
-``` - -``` - - -
- -
-``` diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/04.\350\257\255\346\263\225/02.CSS\350\257\255\346\263\225\345\217\202\350\200\203.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/04.\350\257\255\346\263\225/02.CSS\350\257\255\346\263\225\345\217\202\350\200\203.md" deleted file mode 100644 index e6efd0a95162169641e93afac812cd8216c897dd..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/04.\350\257\255\346\263\225/02.CSS\350\257\255\346\263\225\345\217\202\350\200\203.md" +++ /dev/null @@ -1,221 +0,0 @@ ---- -title: CSS语法参考 -permalink: /pages/01080202020402 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:26 ---- -# CSS语法参考 - -CSS是描述HML页面结构的样式语言。所有组件均存在系统默认样式,也可在页面CSS样式文件中对组件、页面自定义不同的样式。 - -## 尺寸单位 - -1. 逻辑像素px(文档中以<length>表示): - 1. 默认屏幕具有的逻辑宽度为720px(配置见[配置文件](/pages/010802020202)中的window小节),实际显示时会将页面布局缩放至屏幕实际宽度,如100px在实际宽度为1440物理像素的屏幕上,实际渲染为200物理像素(从720px向1440物理像素,所有尺寸放大2倍)。 - 2. 额外配置autoDesignWidth为true时(配置见[配置文件](/pages/010802020202)中的window小节),逻辑像素px将按照屏幕密度进行缩放,如100px在屏幕密度为3的设备上,实际渲染为300物理像素。应用需要适配多种设备时,建议采用此方法。 - -2. 百分比(文档中以<percentage>表示):表示该组件占父组件尺寸的百分比,如组件的width设置为50%,代表其宽度为父组件的50%。 - - -## 样式导入 - -为了模块化管理和代码复用,CSS样式文件支持 \@import 语句,导入css文件。 - - -## 声明样式 - -每个页面目录下存在一个与布局hml文件同名的css文件,用来描述该hml页面中组件的样式,决定组件应该如何显示。 - -1. 内部样式,支持使用style、class属性来控制组件的样式。例如: - ``` - -
- Hello World -
- ``` - - ``` - /* index.css */ - .container { - justify-content: center; - } - ``` - -2. 文件导入,合并外部样式文件。例如,在common目录中定义样式文件style.css,并在index.css文件首行中进行导入: - ``` - /* style.css */ - .title { - font-size: 50px; - } - ``` - - ``` - /* index.css */ - @import '../../common/style.css'; - .container { - justify-content: center; - } - ``` - - -## 选择器 - -css选择器用于选择需要添加样式的元素,支持的选择器如下表所示: - -| 选择器 | 样例 | 样例描述 | -| -------- | -------- | -------- | -| .class | .container | 用于选择class="container"的组件。 | -| \#id | \#titleId | 用于选择id="titleId"的组件。 | -| tag | text | 用于选择text组件。 | -| , | .title, .content | 用于选择class="title"和class="content"的组件。 | -| \#id .class tag | \#containerId .content text | 非严格父子关系的后代选择器,选择具有id="containerId"作为祖先元素,class="content"作为次级祖先元素的所有text组件。如需使用严格的父子关系,可以使用“>”代替空格,如:\#containerId>.content。 | - -示例: - -``` - -
- 标题 -
- 内容 -
-
-``` - -``` -/* 页面样式xxx.css */ -/\* 对所有div组件设置样式 \*/ -div { - flex-direction: column; -} -/* 对class="title"的组件设置样式 */ -.title { - font-size: 30px; -} -/* 对id="contentId"的组件设置样式 */ -#contentId { - font-size: 20px; -} -/* 对所有class="title"以及class="content"的组件都设置padding为5px */ -.title, .content { - padding: 5px; -} -/\* 对class="container"的组件下的所有text设置样式 \*/ -.container text { - color: \#007dff; -} -/\* 对class="container"的组件下的直接后代text设置样式 \*/ -.container > text { - color: \#fa2a2d; -} -``` - -以上样式运行效果如下: - -![zh-cn_image_0000001127125270](/images/application-dev/ui/figures/zh-cn_image_0000001127125270.png) - -其中“.container text”将“标题”和“内容”设置为蓝色,而“.container > text”直接后代选择器将“标题”设置为红色。2者优先级相同,但直接后代选择器声明顺序靠后,将前者样式覆盖(优先级计算见[选择器优先级](#选择器优先级))。 - -## 选择器优先级 - -选择器的优先级计算规则与w3c规则保持一致(只支持:内联样式,id,class,tag,后代和直接后代),其中内联样式为在元素style属性中声明的样式。 - -当多条选择器声明匹配到同一元素时,各类选择器优先级由高到低顺序为:内联样式 > id > class > tag。 - - -## 伪类 - -css伪类是选择器中的关键字,用于指定要选择元素的特殊状态。例如,:disabled状态可以用来设置元素的disabled属性变为true时的样式。 - -除了单个伪类之外,还支持伪类的组合,例如,:focus:checked状态可以用来设置元素的focus属性和checked属性同时为true时的样式。支持的单个伪类如下表所示,按照优先级降序排列: - -| 名称 | 支持组件 | 描述 | -| -------- | -------- | -------- | -| :disabled | 支持disabled属性的组件 | 表示disabled属性变为true时的元素(不支持动画样式的设置)。 | -| :active | 支持click事件的组件
| 表示被用户激活的元素,如:被用户按下的按钮、被激活的tab-bar页签(不支持动画样式的设置)。 | -| :waiting | button | 表示waiting属性为true的元素(不支持动画样式的设置)。 | -| :checked | input[type="checkbox"、type="radio"]、 switch | 表示checked属性为true的元素(不支持动画样式的设置)。 | - -伪类示例如下,设置按钮的:active伪类可以控制被用户按下时的样式: - -``` - -
- -
-``` - -``` -/* index.css */ -.button:active { - background-color: #888888;/*按钮被激活时,背景颜色变为#888888 */ -} -``` - -> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** -> 针对弹窗类组件及其子元素不支持伪类效果,包括popup、dialog、menu、option、picker - - -## 样式预编译 - -预编译提供了利用特有语法生成css的程序,可以提供变量、运算等功能,令开发者更便捷地定义组件样式,目前支持less、sass和scss的预编译。使用样式预编译时,需要将原css文件后缀改为less、sass或scss,如index.css改为index.less、index.sass或index.scss。 - -- 当前文件使用样式预编译,例如将原index.css改为index.less: - ``` - /* index.less */ - /* 定义变量 */ - @colorBackground: #000000; - .container { - background-color: @colorBackground; /* 使用当前less文件中定义的变量 */ - } - ``` - -- 引用预编译文件,例如common中存在style.scss文件,将原index.css改为index.scss,并引入style.scss: - ``` - /* style.scss */ - /* 定义变量 */ - $colorBackground: #000000; - ``` - - 在index.scss中引用: - - ``` - /* index.scss */ - /* 引入外部scss文件 */ - @import '../../common/style.scss'; - .container { - background-color: $colorBackground; /* 使用style.scss中定义的变量 */ - } - ``` - - > ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** - > 引用的预编译文件建议放在common目录进行管理。 - -## CSS样式继承6+ - -css样式继承提供了子节点继承父节点样式的能力,继承下来的样式在多选择器样式匹配的场景下,优先级排最低,当前支持以下样式的继承: - -- font-family - -- font-weight - -- font-size - -- font-style - -- text-align - -- line-height - -- letter-spacing - -- color - -- visibility diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/04.\350\257\255\346\263\225/03.JS\350\257\255\346\263\225\345\217\202\350\200\203.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/04.\350\257\255\346\263\225/03.JS\350\257\255\346\263\225\345\217\202\350\200\203.md" deleted file mode 100644 index a40b9cec81a8503d6f29a054a8d9a7193aea9e98..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/04.\350\257\255\346\263\225/03.JS\350\257\255\346\263\225\345\217\202\350\200\203.md" +++ /dev/null @@ -1,307 +0,0 @@ ---- -title: JS语法参考 -permalink: /pages/01080202020403 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:26 ---- -# JS语法参考 - -JS文件用来定义HML页面的业务逻辑,支持ECMA规范的JavaScript语言。基于JavaScript语言的动态化能力,可以使应用更加富有表现力,具备更加灵活的设计能力。下面讲述JS文件的编译和运行的支持情况。 - - -## 语法 - -支持ES6语法。 - -- 模块声明 - 使用import方法引入功能模块: - - ``` - import router from '@system.router'; - ``` - -- 代码引用 - 使用import方法导入js代码: - - ``` - import utils from '../../common/utils.js'; - ``` - - -## 对象 - -- 应用对象 - | 属性 | 类型 | 描述 | - | -------- | -------- | -------- | - | $def | Object | 使用this.$app.$def获取在app.js中暴露的对象。
> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:**
> 应用对象不支持数据绑定,需主动触发UI更新。 | - - 示例代码 - - ``` - // app.js - export default { - onCreate() { - console.info('Application onCreate'); - }, - onDestroy() { - console.info('Application onDestroy'); - }, - globalData: { - appData: 'appData', - appVersion: '2.0', - }, - globalMethod() { - console.info('This is a global method!'); - this.globalData.appVersion = '3.0'; - } - }; - ``` - - ``` - // index.js页面逻辑代码 - export default { - data: { - appData: 'localData', - appVersion:'1.0', - }, - onInit() { - this.appData = this.$app.$def.globalData.appData; - this.appVersion = this.$app.$def.globalData.appVersion; - }, - invokeGlobalMethod() { - this.$app.$def.globalMethod(); - }, - getAppVersion() { - this.appVersion = this.$app.$def.globalData.appVersion; - } - } - ``` - -- 页面对象 - | 属性 | 类型 | 描述 | - | -------- | -------- | -------- | - | data | Object/Function | 页面的数据模型,类型是对象或者函数,如果类型是函数,返回值必须是对象。属性名不能以$或_开头,不要使用保留字for, if, show, tid。
data与private和public不能重合使用。 | - | $refs | Object | 持有注册过ref 属性的DOM元素或子组件实例的对象。示例见[获取DOM元素](#获取dom元素)。 | - | private | Object | 页面的数据模型,private下的数据属性只能由当前页面修改。 | - | public | Object | 页面的数据模型,public下的数据属性的行为与data保持一致。 | - | props | Array/Object | props用于组件之间的通信,可以通过<tag xxxx='value'>方式传递给组件;props名称必须用小写,不能以$或_开头,不要使用保留字for, if, show, tid。目前props的数据类型不支持Function。示例见[自定义组件](/pages/010c02010203)。 | - | computed | Object | 用于在读取或设置进行预先处理,计算属性的结果会被缓存。计算属性名不能以$或_开头,不要使用保留字。示例见[自定义组件](/pages/010c02010203)。 | - -## 方法 - -- 数据方法 - | 方法 | 参数 | 描述 | - | -------- | -------- | -------- | - | $set | key: string, value: any | 添加新的数据属性或者修改已有数据属性。
用法:
this.$set('key',value):添加数据属性。 | - | $delete | key: string | 删除数据属性。
用法:
this.$delete('key'):删除数据属性。 | - - 示例代码 - - ``` - // index.js - export default { - data: { - keyMap: { - OS: 'OpenHarmony', - Version: '2.0', - }, - }, - getAppVersion() { - this.$set('keyMap.Version', '3.0'); - console.info("keyMap.Version = " + this.keyMap.Version); // keyMap.Version = 3.0 - - this.$delete('keyMap'); - console.info("keyMap.Version = " + this.keyMap); // log print: keyMap.Version = undefined - } - } - ``` - -- 公共方法 - | 方法 | 参数 | 描述 | - | -------- | -------- | -------- | - | $element | id: string | 获得指定id的组件对象,如果无指定id,则返回根组件对象。示例见[获取DOM元素](#获取dom元素)。
用法:
<div id='xxx'></div>
- this.$element('xxx'):获得id为xxx的组件对象。
- this.$element():获得根组件对象。 | - | $rootElement | 无 | 获取根组件对象。
用法:this.$rootElement().scrollTo({ duration: 500, position: 300 }), 页面在500ms内滚动300px。 | - | $root | 无 | 获得顶级ViewModel实例。[获取ViewModel](#获取viewmodel)示例。 | - | $parent | 无 | 获得父级ViewModel实例。[获取ViewModel](#获取viewmodel)示例。 | - | $child | id: string | 获得指定id的子级自定义组件的ViewModel实例。[获取ViewModel](#获取viewmodel)示例。
用法:
this.$child('xxx') :获取id为xxx的子级自定义组件的ViewModel实例。 | - -- 事件方法 - | 方法 | 参数 | 描述 | - | -------- | -------- | -------- | - | $watch | data: string, callback: string \| Function | 观察data中的属性变化,如果属性值改变,触发绑定的事件。示例见[自定义组件](/pages/010c02010203)。
用法:
this.$watch('key', callback) | - -- 页面方法 - | 方法 | 参数 | 描述 | - | -------- | -------- | -------- | - | scrollTo6+ | scrollPageParam: ScrollPageParam | 将页面滚动到目标位置,可以通过ID选择器指定或者滚动距离指定。 | - - **表1** ScrollPageParam6+ - - | 名称 | 类型 | 默认值 | 描述 | - | -------- | -------- | -------- | -------- | - | position | number | - | 指定滚动位置。 | - | id | string | - | 指定需要滚动到的元素id。 | - | duration | number | 300 | 指定滚动时长,单位为毫秒。 | - | timingFunction | string | ease | 指定滚动动画曲线,可选值参考
[动画样式animation-timing-function](/pages/010c0201010105)。 | - | complete | () => void | - | 指定滚动完成后需要执行的回调函数。 | - - 示例: - - ``` - this.$rootElement().scrollTo({position: 0}) - this.$rootElement().scrollTo({id: 'id', duration: 200, timingFunction: 'ease-in', complete: ()=>void}) - ``` - - -## 获取DOM元素 - -1. 通过$refs获取DOM元素 - ``` - -
- -
- ``` - - ``` - // index.js - export default { - data: { - images: [ - { src: '/common/frame1.png' }, - { src: '/common/frame2.png' }, - { src: '/common/frame3.png' }, - ], - }, - handleClick() { - const animator = this.$refs.animator; // 获取ref属性为animator的DOM元素 - const state = animator.getState(); - if (state === 'paused') { - animator.resume(); - } else if (state === 'stopped') { - animator.start(); - } else { - animator.pause(); - } - }, - }; - ``` - -2. 通过$element获取DOM元素 - ``` - -
- -
- ``` - - ``` - // index.js - export default { - data: { - images: [ - { src: '/common/frame1.png' }, - { src: '/common/frame2.png' }, - { src: '/common/frame3.png' }, - ], - }, - handleClick() { - const animator = this.$element('animator'); // 获取id属性为animator的DOM元素 - const state = animator.getState(); - if (state === 'paused') { - animator.resume(); - } else if (state === 'stopped') { - animator.start(); - } else { - animator.pause(); - } - }, - }; - ``` - -## 获取ViewModel - -根节点所在页面: - -``` - - -
-
- {{text}} - -
-
-``` - -``` -// root.js -export default { - data: { - text: 'I am root!', - }, -} -``` - -自定义parent组件: - -``` - - -
- parent component click - hello parent component! - -
-``` - -``` -// parent.js -export default { - data: { - show: false, - text: 'I am parent component!', - }, - parentClicked () { - this.show = !this.show; - console.info('parent component get parent text'); - console.info(`${this.$parent().text}`); - console.info("parent component get child function"); - console.info(`${this.$child('selfDefineChild').childClicked()}`); - }, -} -``` - -自定义child组件: - -``` - -
- child component clicked - hello child component -
-``` - -``` -// child.js -export default { - data: { - show: false, - text: 'I am child component!', - }, - childClicked () { - this.show = !this.show; - console.info('child component get parent text'); - console.info('${this.$parent().text}'); - console.info('child component get root text'); - console.info('${this.$root().text}'); - }, -} -``` diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/05.\347\224\237\345\221\275\345\221\250\346\234\237.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/05.\347\224\237\345\221\275\345\221\250\346\234\237.md" deleted file mode 100644 index 29aef8dd1ea7f254b6e59d39576515569c6db43b..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/05.\347\224\237\345\221\275\345\221\250\346\234\237.md" +++ /dev/null @@ -1,59 +0,0 @@ ---- -title: 生命周期 -permalink: /pages/010802020205 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:26 ---- -# 生命周期 - -## 应用生命周期 - -在app.js中可以定义如下应用生命周期函数: - -| 属性 | 类型 | 描述 | 触发时机 | -| -------- | -------- | -------- | -------- | -| onCreate | () => void | 应用创建 | 当应用创建时调用。 | -| onShow6+ | () => void | 应用处于前台 | 当应用处于前台时触发。 | -| onHide6+ | () => void | 应用处于后台 | 当应用处于后台时触发。 | -| onDestroy | () => void | 应用销毁 | 当应用退出时触发。 | - - -## 页面生命周期 - -在页面JS文件中可以定义如下页面生命周期函数: - -| 属性 | 类型 | 描述 | 触发时机 | -| -------- | -------- | -------- | -------- | -| onInit | () => void | 页面初始化 | 页面数据初始化完成时触发,只触发一次。 | -| onReady | () => void | 页面创建完成 | 页面创建完成时触发,只触发一次。 | -| onShow | () => void | 页面显示 | 页面显示时触发。 | -| onHide | () => void | 页面消失 | 页面消失时触发。 | -| onDestroy | () => void | 页面销毁 | 页面销毁时触发。 | -| onBackPress | () => boolean | 返回按钮动作 | 当用户点击返回按钮时触发。
- 返回true表示页面自己处理返回逻辑。
- 返回false表示使用默认的返回逻辑。
- 不返回值会作为false处理。 | -| onActive()5+ | () => void | 页面激活 | 页面激活时触发。 | -| onInactive()5+ | () => void | 页面暂停 | 页面暂停时触发。 | -| onNewRequest()5+ | () => void | FA重新请求 | FA已经启动时收到新的请求后触发。 | - -页面A的生命周期接口的调用顺序 -- 打开页面A:onInit() -> onReady() -> onShow() - -- 在页面A打开页面B:onHide() - -- 从页面B返回页面A:onShow() - -- 退出页面A:onBackPress() -> onHide() -> onDestroy() - -- 页面隐藏到后台运行:onInactive() -> onHide() - -- 页面从后台运行恢复到前台:onShow() -> onActive() - -![zh-cn_image_0000001147417424](/images/application-dev/ui/figures/zh-cn_image_0000001147417424.png) - - diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/06.\350\265\204\346\272\220\351\231\220\345\256\232\344\270\216\350\256\277\351\227\256.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/06.\350\265\204\346\272\220\351\231\220\345\256\232\344\270\216\350\256\277\351\227\256.md" deleted file mode 100644 index 0a535766691cffaba4c1189b379f0916c2e9a8f7..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/06.\350\265\204\346\272\220\351\231\220\345\256\232\344\270\216\350\256\277\351\227\256.md" +++ /dev/null @@ -1,105 +0,0 @@ ---- -title: 资源限定与访问 -permalink: /pages/010802020206 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:26 ---- -# 资源限定与访问 - - -## 资源限定词 - -资源限定词可以由一个或多个表征应用场景或设备特征的限定词组合而成,包括屏幕密度等维度,限定词之间通过中划线(-)连接。开发者在**resources**目录下创建限定词文件时,需要掌握限定词文件的命名要求以及与限定词文件与设备状态的匹配规则。 - - -## 资源限定词的命名要求 - -- 限定词的组合顺序:屏幕密度。开发者可以根据应用的使用场景和设备特征,选择其中的一类或几类限定词组成目录名称,顺序不可颠倒。 - -- 限定词的连接方式:限定词之间均采用中划线(-)连接。例如:res-dark-ldpi.json 。 - -- 限定词的取值范围:每类限定词的取值必须符合下表的条件,否则,将无法匹配目录中的资源文件,限定词大小写敏感。 - -- 限定词前缀:**resources**资源文件的资源限定词有前缀res,例如res-ldpi.json。 - -- 默认资源限定文件:**resources**资源文件的默认资源限定文件为res-defaults.json。 - -- 资源限定文件中不支持使用枚举格式的颜色来设置资源。 - - -**表1** 资源限定词 - -| 类型 | 含义与取值说明 | -| -------- | -------- | -| 屏幕密度 | 表示设备的屏幕密度(单位为dpi),取值如下:
- ldpi:表示低密度屏幕(~120dpi)(0.75基准密度)
- mdpi:表示中密度屏幕(~160dpi)(基准密度)
- hdpi:表示高密度屏幕(~240dpi)(1.5基准密度)
- xhdpi:表示加高密度屏幕(~320dpi)(2.0基准密度)
- xxhdpi:表示超超高密度屏幕(~480dpi)(3.0基准密度)
- xxxhdpi:表示超超超高密度屏幕(~640dpi)(4.0基准密度) | - - -## 限定词与设备状态的匹配规则 - -- 在为设备匹配对应的资源文件时,限定词目录匹配的优先级从高到低依次为:MCC和MNC> 横竖屏 > 深色模式 > 设备类型 > 屏幕密度。在资源限定词目录均未匹配的情况下,则匹配默认资源限定文件。 - -- 如果限定词目录中包含资源限定词,则对应限定词的取值必须与当前的设备状态完全一致,该目录才能够参与设备的资源匹配。例如:资源限定文件res-hdpi.json与当前设备密度xhdpi无法匹配。 - - -## 引用JS模块内resources资源 - -在应用开发的hml和js文件中使用$r的语法,可以对JS模块内的resources目录下的json资源进行格式化,获取相应的资源内容。 - -| 属性 | 类型 | 描述 | -| -------- | -------- | -------- | -| $r | (key: string) => string | 获取资源限定下具体的资源内容。例如:this.$r('strings.hello')。
参数说明:
- key:定义在资源限定文件中的键值,如strings.hello。
| - -**res-defaults.json示例:**
- -``` -{ - strings: { - hello: 'hello world' - } -} -``` - -## 示例 - -resources/res-dark.json: - -``` -{ - "image": { - "clockFace": "common/dark_face.png" - }, - "colors": { - "background": "#000000" - } -} -``` - -resources/res-defaults.json: - -``` -{ - "image": { - "clockFace": "common/face.png" - }, - "colors": { - "background": "#ffffff" - } -} -``` - -``` - -
- -
-``` - -> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** -> 资源限定文件中不支持颜色枚举格式。 diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/07.\345\244\232\350\257\255\350\250\200\346\224\257\346\214\201.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/07.\345\244\232\350\257\255\350\250\200\346\224\257\346\214\201.md" deleted file mode 100644 index c2bb2369d03048c5b70d4ec1ca1ba537082023fd..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/07.\345\244\232\350\257\255\350\250\200\346\224\257\346\214\201.md" +++ /dev/null @@ -1,198 +0,0 @@ ---- -title: 多语言支持 -permalink: /pages/010802020207 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:26 ---- -# 多语言支持 - -基于开发框架的应用会覆盖多个国家和地区,开发框架支持多语言能力后,可以让应用开发者无需开发多个不同语言的版本,就可以同时支持多种语言的切换,为项目维护带来便利。 - - -开发者仅需要通过[定义资源文件](#定义资源文件)和[引用资源](#引用资源)两个步骤,就可以使用开发框架的多语言能力;如果需要在应用中获取当前系统语言,请参考[获取语言](#获取语言)。 - - -## 定义资源文件 - -资源文件用于存放应用在多种语言场景下的资源内容,开发框架使用JSON文件保存资源定义。在[文件组织](/pages/010802020201)中指定的i18n文件夹内放置语言资源文件,其中语言资源文件的命名是由语言、文字、国家或地区的限定词通过中划线连接组成,其中文字和国家或地区可以省略,如zh-Hant-HK(中国香港地区使用的繁体中文)、zh-CN(中国使用的简体中文)、zh(中文)。命名规则如下: - -``` -language[-script-region].json -``` - -限定词的取值需符合下表要求。 - -**表1** 限定词取值要求 - -| 限定词类型 | 含义与取值说明 | -| -------- | -------- | -| 语言 | 表示设备使用的语言类型,由2~3个小写字母组成。例如:zh表示中文,en表示英语,mai表示迈蒂利语。
详细取值范围,请查阅**ISO 639**(ISO制定的语言编码标准)。 | -| 文字 | 表示设备使用的文字类型,由1个大写字母(首字母)和3个小写字母组成。例如:Hans表示简体中文,Hant表示繁体中文。
详细取值范围,请查阅**ISO 15924**(ISO制定的文字编码标准)。 | -| 国家或地区 | 表示用户所在的国家或地区,由2~3个大写字母或者3个数字组成。例如:CN表示中国,GB表示英国。
详细取值范围,请查阅**ISO 3166-1**(ISO制定的国家和地区编码标准)。 | - -当开发框架无法在应用中找到系统语言的资源文件时,默认使用en-US.json中的资源内容。 - -资源文件内容格式如下: - -en-US.json -``` -{ - "strings": { - "hello": "Hello world!", - "object": "Object parameter substitution-{name}", - "array": "Array type parameter substitution-{0}", - "symbol": "@#$%^&*()_+-={}[]\\|:;\"'<>,./?" - }, - - "files": { - "image": "image/en_picture.PNG" - } -} -``` - - -由于不同语言针对单复数有不同的匹配规则,在资源文件中使用“zero”“one”“two”“few”“many”“other”定义不同单复数场景下的词条内容。例如中文不区分单复数,仅存在“other”场景;英文存在“one”、“other”场景;阿拉伯语存在上述6种场景。 - - -以en-US.json和ar-AE.json为例,资源文件内容格式如下: - - -en-US.json - -``` -{ - "strings": { - "people": { - "one": "one person", - "other": "{count} people" - } - } -} -``` - - -ar-AE.json - -``` -{ - "strings": { - "people": { - "zero": "لا أحد", - "one": "وحده", - "two": "اثنان", - "few": "ستة اشخاص", - "many": "خمسون شخص", - "other": "مائة شخص" - } - } -} -``` - - -## 引用资源 - -在应用开发的页面中使用多语言的语法,包含简单格式化和单复数格式化两种,都可以在hml或js中使用。 - -- 简单格式化方法 - 在应用中使用$t方法引用资源,$t既可以在hml中使用,也可以在js中使用。系统将根据当前语言环境和指定的资源路径(通过$t的path参数设置),显示对应语言的资源文件中的内容。 - - **表2** 简单格式化 - - | 属性 | 类型 | 参数 | 必填 | 描述 | - | -------- | -------- | -------- | -------- | -------- | - | $t | Function | 请见**表 $t参数说明** | 是 | 根据系统语言完成简单的替换:this.$t('strings.hello') | - - **表3** $t参数说明 - - | 参数 | 类型 | 必填 | 描述 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 资源路径 | - | params | Array\|Object | 否 | 运行时用来替换占位符的实际内容,占位符分为两种:
- 具名占位符,例如{name}。实际内容必须用Object类型指定,例如:$t('strings.object', **{ name: 'Hello world' }**)。
- 数字占位符,例如{0}。实际内容必须用Array类型指定,例如:$t('strings.array', **['Hello world']**)。 | - -- 简单格式化示例代码 - ``` - -
- - {{ $t('strings.hello') }} - - {{ $t('strings.object', { name: 'Hello world' }) }} - - {{ $t('strings.array', ['Hello world']) }} - - {{ hello }} - - {{ replaceObject }} - - {{ replaceArray }} - - - - - -
- ``` - - ``` - // xxx.js - // 下面为在js文件中的使用方法。 - export default { - data: { - hello: '', - replaceObject: '', - replaceArray: '', - replaceSrc: '', - }, - onInit() { - this.hello = this.$t('strings.hello'); - this.replaceObject = this.$t('strings.object', { name: 'Hello world' }); - this.replaceArray = this.$t('strings.array', ['Hello world']); - this.replaceSrc = this.$t('files.image'); - }, - } - ``` - -- 单复数格式化方法 - **表4** 单复数格式化 - - | 属性 | 类型 | 参数 | 必填 | 描述 | - | -------- | -------- | -------- | -------- | -------- | - | $tc | Function | 请见**表 $tc参数说明** | 是 | 根据系统语言完成单复数替换:this.$tc('strings.people')
> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:**
> 定义资源的内容通过json格式的key为“zero”、“one”、“two”、“few”、“many”和“other”区分。 | - - **表5** $tc参数说明 - - | 参数 | 类型 | 必填 | 描述 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 资源路径 | - | count | number | 是 | 要表达的值 | - -- 单复数格式化示例代码 - ``` - -
- - {{ $tc('strings.people', 0) }} - - {{ $tc('strings.people', 1) }} - - {{ $tc('strings.people', 2) }} - - {{ $tc('strings.people', 6) }} - - {{ $tc('strings.people', 50) }} - - {{ $tc('strings.people', 100) }} -
- ``` - - -## 获取语言 - -获取语言功能请参考[应用配置](/pages/010c010b05)。 diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/03.\346\236\204\345\273\272\347\224\250\346\210\267\347\225\214\351\235\242/01.\347\273\204\344\273\266\344\273\213\347\273\215.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/03.\346\236\204\345\273\272\347\224\250\346\210\267\347\225\214\351\235\242/01.\347\273\204\344\273\266\344\273\213\347\273\215.md" deleted file mode 100644 index d7bba9b1e084e66a545a0058fc0c9b06e892c4e5..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/03.\346\236\204\345\273\272\347\224\250\346\210\267\347\225\214\351\235\242/01.\347\273\204\344\273\266\344\273\213\347\273\215.md" +++ /dev/null @@ -1,33 +0,0 @@ ---- -title: 组件介绍 -permalink: /pages/010802020301 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:26 ---- -# 组件介绍 - -组件(Component)是构建页面的核心,每个组件通过对数据和方法的简单封装,实现独立的可视、可交互功能单元。组件之间相互独立,随取随用,也可以在需求相同的地方重复使用。关于组件的详细参考文档请参见[组件](/pages/010c0201010101)。 - - -开发者还可以通过组件间合理的搭配定义满足业务需求的新组件,减少开发量,自定义组件的开发方法请参见[自定义组件](/pages/0108020206)。 - - -## 组件分类 - -根据组件的功能,可以分为以下六大类: - -| 组件类型 | 主要组件 | -| -------- | -------- | -| 容器组件 | badge、dialog、div、form、list、list-item、list-item-group、panel、popup、refresh、stack、stepper、stepper-item、swiper、tabs、tab-bar、tab-content | -| 基础组件 | button、chart、divider、image、image-animator、input、label、marquee、menu、option、picker、picker-view、piece、progress、qrcode、rating、richtext、search、select、slider、span、switch、text、textarea、toolbar、toolbar-item、toggle | -| 媒体组件 | video | -| 画布组件 | canvas | -| 栅格组件 | grid-container、grid-row、grid-col | -| svg组件 | svg、rect、circle、ellipse、path、line、polyline、polygon、text、tspan、textPath、animate、animateMotion、animateTransform | diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/03.\346\236\204\345\273\272\347\224\250\346\210\267\347\225\214\351\235\242/02.\346\236\204\345\273\272\345\270\203\345\261\200/01.\345\270\203\345\261\200\350\257\264\346\230\216.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/03.\346\236\204\345\273\272\347\224\250\346\210\267\347\225\214\351\235\242/02.\346\236\204\345\273\272\345\270\203\345\261\200/01.\345\270\203\345\261\200\350\257\264\346\230\216.md" deleted file mode 100644 index 06199c6084b716ff05fe1437caede2925c88c364..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/03.\346\236\204\345\273\272\347\224\250\346\210\267\347\225\214\351\235\242/02.\346\236\204\345\273\272\345\270\203\345\261\200/01.\345\270\203\345\261\200\350\257\264\346\230\216.md" +++ /dev/null @@ -1,46 +0,0 @@ ---- -title: 布局说明 -permalink: /pages/01080202030201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:26 ---- -# 布局说明 - - - -设备的基准宽度为720px(px为逻辑像素,非物理像素),实际显示效果会根据实际屏幕宽度进行缩放。 - - -其换算关系如下: - - -组件的width设为100px时,在宽度为720物理像素的屏幕上,实际显示为100物理像素;在宽度为1440物理像素的屏幕上,实际显示为200物理像素。 - -一个页面的基本元素包含标题区域、文本区域、图片区域等,每个基本元素内还可以包含多个子元素,开发者根据需求还可以添加按钮、开关、进度条等组件。在构建页面布局时,需要对每个基本元素思考以下几个问题: - - -- 该元素的尺寸和排列位置 - -- 是否有重叠的元素 - -- 是否需要设置对齐、内间距或者边界 - -- 是否包含子元素及其排列位置 - -- 是否需要容器组件及其类型 - - -将页面中的元素分解之后再对每个基本元素按顺序实现,可以减少多层嵌套造成的视觉混乱和逻辑混乱,提高代码的可读性,方便对页面做后续的调整。以下图为例进行分解: -**图1** 页面布局分解 -![zh-cn_image_0000001070558189](/images/application-dev/ui/figures/zh-cn_image_0000001070558189.png) - -**图2** 留言区布局分解 - -![zh-cn_image_0000001063442797](/images/application-dev/ui/figures/zh-cn_image_0000001063442797.png) diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/03.\346\236\204\345\273\272\347\224\250\346\210\267\347\225\214\351\235\242/02.\346\236\204\345\273\272\345\270\203\345\261\200/02.\346\267\273\345\212\240\346\240\207\351\242\230\350\241\214\345\222\214\346\226\207\346\234\254\345\214\272\345\237\237.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/03.\346\236\204\345\273\272\347\224\250\346\210\267\347\225\214\351\235\242/02.\346\236\204\345\273\272\345\270\203\345\261\200/02.\346\267\273\345\212\240\346\240\207\351\242\230\350\241\214\345\222\214\346\226\207\346\234\254\345\214\272\345\237\237.md" deleted file mode 100644 index c95785effcb316c5527c54efc4d6a525666d3774..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/03.\346\236\204\345\273\272\347\224\250\346\210\267\347\225\214\351\235\242/02.\346\236\204\345\273\272\345\270\203\345\261\200/02.\346\267\273\345\212\240\346\240\207\351\242\230\350\241\214\345\222\214\346\226\207\346\234\254\345\214\272\345\237\237.md" +++ /dev/null @@ -1,59 +0,0 @@ ---- -title: 添加标题行和文本区域 -permalink: /pages/01080202030202 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:26 ---- -# 添加标题行和文本区域 - -实现标题和文本区域最常用的是基础组件text。text组件用于展示文本,可以设置不同的属性和样式,文本内容需要写在标签内容区,完整属性和样式信息请参考[text](/pages/010c0201010317)。在页面中插入标题和文本区域的示例如下: - - -``` - -
- {{headTitle}} - {{paragraphFirst}} - {{paragraphSecond}} -
-``` - - -``` -/* xxx.css */ -.container { - flex-direction: column; - margin-top: 20px; - margin-left: 30px; -} -.title-text { - color: #1a1a1a; - font-size: 50px; - margin-top: 40px; - margin-bottom: 20px; -} -.paragraph-text { - color: #000000; - font-size: 35px; - line-height: 60px; -} -``` - - -``` -// xxx.js -export default { - data: { - headTitle: 'Capture the Beauty in This Moment', - paragraphFirst: 'Capture the beauty of light during the transition and fusion of ice and water. At the instant of movement and stillness, softness and rigidity, force and beauty, condensing moving moments.', - paragraphSecond: 'Reflecting the purity of nature, the innovative design upgrades your visual entertainment and ergonomic comfort. Effortlessly capture what you see and let it speak for what you feel.', - }, -} -``` diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/03.\346\236\204\345\273\272\347\224\250\346\210\267\347\225\214\351\235\242/02.\346\236\204\345\273\272\345\270\203\345\261\200/03.\346\267\273\345\212\240\345\233\276\347\211\207\345\214\272\345\237\237.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/03.\346\236\204\345\273\272\347\224\250\346\210\267\347\225\214\351\235\242/02.\346\236\204\345\273\272\345\270\203\345\261\200/03.\346\267\273\345\212\240\345\233\276\347\211\207\345\214\272\345\237\237.md" deleted file mode 100644 index 317c8e76fecd9b06f958249c61f0acab4c9d0600..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/03.\346\236\204\345\273\272\347\224\250\346\210\267\347\225\214\351\235\242/02.\346\236\204\345\273\272\345\270\203\345\261\200/03.\346\267\273\345\212\240\345\233\276\347\211\207\345\214\272\345\237\237.md" +++ /dev/null @@ -1,46 +0,0 @@ ---- -title: 添加图片区域 -permalink: /pages/01080202030203 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:26 ---- -# 添加图片区域 - -添加图片区域通常用[image](/pages/010c0201010304)组件来实现,使用的方法和text组件类似。 - - - -图片资源建议放在jsdefaultcommon目录下,common目录需自行创建,详细的目录结构见[目录结构](/pages/010802020201#目录结构)。代码示例如下: - - -``` - - -``` - - -``` -/* xxx.css */ -.img { - margin-top: 30px; - margin-bottom: 30px; - height: 385px; -} -``` - - -``` -// xxx.js -export default { - data: { - middleImage: '/common/ice.png', - }, -} -``` diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/03.\346\236\204\345\273\272\347\224\250\346\210\267\347\225\214\351\235\242/02.\346\236\204\345\273\272\345\270\203\345\261\200/04.\346\267\273\345\212\240\347\225\231\350\250\200\345\214\272\345\237\237.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/03.\346\236\204\345\273\272\347\224\250\346\210\267\347\225\214\351\235\242/02.\346\236\204\345\273\272\345\270\203\345\261\200/04.\346\267\273\345\212\240\347\225\231\350\250\200\345\214\272\345\237\237.md" deleted file mode 100644 index 9ba3961969486350151a5ca67e344af7d7c32ab2..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/03.\346\236\204\345\273\272\347\224\250\346\210\267\347\225\214\351\235\242/02.\346\236\204\345\273\272\345\270\203\345\261\200/04.\346\267\273\345\212\240\347\225\231\350\250\200\345\214\272\345\237\237.md" +++ /dev/null @@ -1,94 +0,0 @@ ---- -title: 添加留言区域 -permalink: /pages/01080202030204 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:26 ---- -# 添加留言区域 - -留言框的功能为:用户输入留言后点击完成,留言区域即显示留言内容;用户点击右侧的删除按钮可删除当前留言内容并重新输入。 - - -留言区域由div、text、input关联click事件实现。开发者可以使用input组件实现输入留言的部分,使用text组件实现留言完成部分,使用commentText的状态标记此时显示的组件(通过if属性控制)。在包含文本完成和删除的text组件中关联click事件,更新commentText状态和inputValue的内容。具体的实现示例如下: - - -``` - -
- Comment -
- - Done -
-
- {{inputValue}} - Delete -
-
-``` - - -``` -/* xxx.css */ -.container { - margin-top: 24px; - background-color: #ffffff; -} -.comment-title { - font-size: 40px; - color: #1a1a1a; - font-weight: bold; - margin-top: 40px; - margin-bottom: 10px; -} -.comment { - width: 550px; - height: 100px; - background-color: lightgrey; -} -.comment-key { - width: 150px; - height: 100px; - margin-left: 20px; - font-size: 32px; - color: #1a1a1a; - font-weight: bold; -} -.comment-key:focus { - color: #007dff; -} -.comment-text { - width: 550px; - height: 100px; - text-align: left; - line-height: 35px; - font-size: 30px; - color: #000000; - border-bottom-color: #bcbcbc; - border-bottom-width: 0.5px; -} -``` - - -``` -// xxx.js -export default { - data: { - inputValue: '', - commentText: false, - }, - update() { - this.commentText = !this.commentText; - }, - updateValue(e) { - this.inputValue = e.text; - }, -} -``` diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/03.\346\236\204\345\273\272\347\224\250\346\210\267\347\225\214\351\235\242/02.\346\236\204\345\273\272\345\270\203\345\261\200/05.\346\267\273\345\212\240\345\256\271\345\231\250.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/03.\346\236\204\345\273\272\347\224\250\346\210\267\347\225\214\351\235\242/02.\346\236\204\345\273\272\345\270\203\345\261\200/05.\346\267\273\345\212\240\345\256\271\345\231\250.md" deleted file mode 100644 index 2776540605fa124c7440575d0c869c836a3813c0..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/03.\346\236\204\345\273\272\347\224\250\346\210\267\347\225\214\351\235\242/02.\346\236\204\345\273\272\345\270\203\345\261\200/05.\346\267\273\345\212\240\345\256\271\345\231\250.md" +++ /dev/null @@ -1,83 +0,0 @@ ---- -title: 添加容器 -permalink: /pages/01080202030205 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:26 ---- -# 添加容器 - -要将页面的基本元素组装在一起,需要使用容器组件。在页面布局中常用到三种容器组件,分别是div、list和tabs。在页面结构相对简单时,可以直接用div作为容器,因为div作为单纯的布局容器,可以支持多种子组件,使用起来更为方便。 - - -## List组件 - -当页面结构较为复杂时,如果使用div循环渲染,容易出现卡顿,因此推荐使用list组件代替div组件实现长列表布局,从而实现更加流畅的列表滚动体验。需要注意的是,list仅支持list-item作为子组件,具体的使用示例如下: - -``` - - - - {{$item.value}} - - -``` - -``` -/* xxx.css */ -.desc-text { - width: 683.3px; - font-size: 35.4px; -} -``` - -``` -// xxx.js -export default { - data: { - textList: [{value: 'JS FA'}], - }, -} -``` - -为避免示例代码过长,以上示例的list中只包含一个list-item,list-item中只有一个text组件。在实际应用中可以在list中加入多个list-item,同时list-item下可以包含多个其他子组件。 - - -## Tabs组件 - -当页面经常需要动态加载时,推荐使用tabs组件。tabs组件支持change事件,在页签切换后触发。tabs组件仅支持一个tab-bar和一个tab-content。具体的使用示例如下: - -``` - - - - Home - Index - Detail - - - - - - - -``` - -``` -// xxx.js -export default { - data: { - homeImage: '/common/home.png', - indexImage: '/common/index.png', - detailImage: '/common/detail.png', - }, -} -``` - -tab-content组件用来展示页签的内容区,高度默认充满tabs剩余空间。 diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/03.\346\236\204\345\273\272\347\224\250\346\210\267\347\225\214\351\235\242/03.\346\267\273\345\212\240\344\272\244\344\272\222.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/03.\346\236\204\345\273\272\347\224\250\346\210\267\347\225\214\351\235\242/03.\346\267\273\345\212\240\344\272\244\344\272\222.md" deleted file mode 100644 index db6e761d218dbe119a94e39d2196b7ccdd826417..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/03.\346\236\204\345\273\272\347\224\250\346\210\267\347\225\214\351\235\242/03.\346\267\273\345\212\240\344\272\244\344\272\222.md" +++ /dev/null @@ -1,93 +0,0 @@ ---- -title: 添加交互 -permalink: /pages/010802020303 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:26 ---- -# 添加交互 - -添加交互可以通过在组件上关联事件实现。本节将介绍如何用div、text、image组件关联click事件,构建一个如下图所示的点赞按钮。 -**图1** 点赞按钮效果 - -![zh-cn_image_0000001064068638](/images/application-dev/ui/figures/zh-cn_image_0000001064068638.gif) - - -点赞按钮通过一个div组件关联click事件实现。div组件包含一个image组件和一个text组件: - - -- image组件用于显示未点赞和点赞的效果。click事件函数会交替更新点赞和未点赞图片的路径。 - -- text组件用于显示点赞数,点赞数会在click事件的函数中同步更新。 - - -click事件作为一个函数定义在js文件中,可以更改isPressed的状态,从而更新显示的image组件。如果isPressed为真,则点赞数加1。该函数在hml文件中对应的div组件上生效,点赞按钮各子组件的样式设置在css文件当中。具体的实现示例如下: - - -``` - - -
- -
-``` - - -``` -/* xxx.css */ -.like { - width: 104px; - height: 54px; - border: 2px solid #bcbcbc; - justify-content: space-between; - align-items: center; - margin-left: 72px; - border-radius: 8px; -} -.like-img { - width: 33px; - height: 33px; - margin-left: 14px; -} -.like-num { - color: #bcbcbc; - font-size: 20px; - margin-right: 17px; -} -``` - - -``` -// xxx.js -export default { - data: { - likeImage: '/common/unLike.png', - isPressed: false, - total: 20, - }, - likeClick() { - var temp; - if (!this.isPressed) { - temp = this.total + 1; - this.likeImage = '/common/like.png'; - } else { - temp = this.total - 1; - this.likeImage = '/common/unLike.png'; - } - this.total = temp; - this.isPressed = !this.isPressed; - }, -} -``` - - -除此之外,还提供了很多表单组件,例如开关、标签、滑动选择器等,以便于开发者在页面布局时灵活使用和提高交互性,详见[容器组件](/pages/extra/c45b2f/)。 diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/03.\346\236\204\345\273\272\347\224\250\346\210\267\347\225\214\351\235\242/04.\345\212\250\347\224\273.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/03.\346\236\204\345\273\272\347\224\250\346\210\267\347\225\214\351\235\242/04.\345\212\250\347\224\273.md" deleted file mode 100644 index 82f7665c8c1070047778132495877a86feb1a313..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/03.\346\236\204\345\273\272\347\224\250\346\210\267\347\225\214\351\235\242/04.\345\212\250\347\224\273.md" +++ /dev/null @@ -1,173 +0,0 @@ ---- -title: 动画 -permalink: /pages/010802020304 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:26 ---- -# 动画 - -动画分为[静态动画](#静态动画)和[连续动画](#连续动画)。 - - -## 静态动画 - -静态动画的核心是transform样式,主要可以实现以下三种变换类型,一次样式设置只能实现一种类型变换。 - -- **translate**:沿水平或垂直方向将指定组件移动所需距离。 - -- **scale**:横向或纵向将指定组件缩小或放大到所需比例。 - -- **rotate**:将指定组件沿横轴或纵轴或中心点旋转指定的角度。 - -具体的使用示例如下,更多信息请参考[组件方法](/pages/010c0201010104)。 - -``` - -
- hello - hello - hello -
-``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - align-items: center; -} -.translate { - height: 150px; - width: 300px; - font-size: 50px; - background-color: #008000; - transform: translate(200px); -} -.rotate { - height: 150px; - width: 300px; - font-size: 50px; - background-color: #008000; - transform-origin: 200px 100px; - transform: rotateX(45deg); -} -.scale { - height: 150px; - width: 300px; - font-size: 50px; - background-color: #008000; - transform: scaleX(1.5); -} -``` - - -**图1** 静态动画效果图 -![zh-cn_image_0000001071134933](/images/application-dev/ui/figures/zh-cn_image_0000001071134933.png) - - -## 连续动画 - -静态动画只有开始状态和结束状态,没有中间状态,如果需要设置中间的过渡状态和转换效果,需要使用连续动画实现。 - -连续动画的核心是animation样式,它定义了动画的开始状态、结束状态以及时间和速度的变化曲线。通过animation样式可以实现的效果有: - -- **animation-name**:设置动画执行后应用到组件上的背景颜色、透明度、宽高和变换类型。 - -- **animation-delay**和**animation-duration**:分别设置动画执行后元素延迟和持续的时间。 - -- **animation-timing-function**:描述动画执行的速度曲线,使动画更加平滑。 - -- **animation-iteration-count**:定义动画播放的次数。 - -- **animation-fill-mode**:指定动画执行结束后是否恢复初始状态。 - -animation样式需要在css文件中先定义keyframe,在keyframe中设置动画的过渡效果,并通过一个样式类型在hml文件中调用。animation-name的使用示例如下: - -``` - -
- animation-name -
- color -
-
- opacity -
- -
-``` - -``` -/* xxx.css */ -.item-container { - margin-right: 60px; - margin-left: 60px; - flex-direction: column; -} -.header { - margin-bottom: 20px; -} -.item { - background-color: #f76160; -} -.txt { - text-align: center; - width: 200px; - height: 100px; -} -.button { - width: 200px; - font-size: 30px; - background-color: #09ba07; -} -.color { - animation-name: Color; - animation-duration: 8000ms; -} -.opacity { - animation-name: Opacity; - animation-duration: 8000ms; -} -@keyframes Color { - from { - background-color: #f76160; - } - to { - background-color: #09ba07; - } -} -@keyframes Opacity { - from { - opacity: 0.9; - } - to { - opacity: 0.1; - } -} -``` - -``` -// xxx.js -export default { - data: { - colorParam: '', - opacityParam: '', - }, - showAnimation: function () { - this.colorParam = ''; - this.opacityParam = ''; - this.colorParam = 'color'; - this.opacityParam = 'opacity'; - }, -} -``` - -**图2** 连续动画效果图 -![zh-cn_image_0000001063148757](/images/application-dev/ui/figures/zh-cn_image_0000001063148757.gif) diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/03.\346\236\204\345\273\272\347\224\250\346\210\267\347\225\214\351\235\242/05.\344\272\213\344\273\266.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/03.\346\236\204\345\273\272\347\224\250\346\210\267\347\225\214\351\235\242/05.\344\272\213\344\273\266.md" deleted file mode 100644 index a79c13964025907771aee465eeed70409b98ecab..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/03.\346\236\204\345\273\272\347\224\250\346\210\267\347\225\214\351\235\242/05.\344\272\213\344\273\266.md" +++ /dev/null @@ -1,119 +0,0 @@ ---- -title: 事件 -permalink: /pages/010802020305 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:26 ---- -# 事件 - -事件主要为手势事件。手势事件主要用于具有触摸屏的设备。 - - -## 手势事件 - -手势表示由单个或多个事件识别的语义动作(例如:点击、拖动和长按)。一个完整的手势也可能由多个事件组成,对应手势的生命周期。支持的事件有: - -**触摸** -- touchstart:手指触摸动作开始。 - -- touchmove:手指触摸后移动。 - -- touchcancel:手指触摸动作被打断,如来电提醒、弹窗。 - -- touchend:手指触摸动作结束。 - -**点击** - -click:用户快速轻敲屏幕。 - -**长按** - -longpress:用户在相同位置长时间保持与屏幕接触。 - -具体的使用示例如下: - -``` - -
-
- {{onClick}} -
-
- {{touchstart}} -
-
- {{touchmove}} -
-
- {{touchend}} -
-
- {{touchcancel}} -
-
- {{onLongPress}} -
-
-``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - justify-content: center; - align-items: center; -} -.text-container { - margin-top: 10px; - flex-direction: column; - width: 750px; - height: 50px; - background-color: #09ba07; -} -.text-style { - width: 100%; - line-height: 50px; - text-align: center; - font-size: 24px; - color: #ffffff; -} -``` - -``` -// xxx.js -export default { - data: { - touchstart: 'touchstart', - touchmove: 'touchmove', - touchend: 'touchend', - touchcancel: 'touchcancel', - onClick: 'onclick', - onLongPress: 'onlongpress', - }, - touchCancel: function (event) { - this.touchcancel = 'canceled'; - }, - touchEnd: function(event) { - this.touchend = 'ended'; - }, - touchMove: function(event) { - this.touchmove = 'moved'; - }, - touchStart: function(event) { - this.touchstart = 'touched'; - }, - longPress: function() { - this.onLongPress = 'longpressed'; - }, - click: function() { - this.onClick = 'clicked'; - }, -} -``` diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/03.\346\236\204\345\273\272\347\224\250\346\210\267\347\225\214\351\235\242/06.\351\241\265\351\235\242\350\267\257\347\224\261.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/03.\346\236\204\345\273\272\347\224\250\346\210\267\347\225\214\351\235\242/06.\351\241\265\351\235\242\350\267\257\347\224\261.md" deleted file mode 100644 index 79c85415eae50d31ea6197bba2751fd328d6a048..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/03.\346\236\204\345\273\272\347\224\250\346\210\267\347\225\214\351\235\242/06.\351\241\265\351\235\242\350\267\257\347\224\261.md" +++ /dev/null @@ -1,99 +0,0 @@ ---- -title: 页面路由 -permalink: /pages/010802020306 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:26 ---- -# 页面路由 - -很多应用由多个页面组成,比如用户可以从音乐列表页面点击歌曲,跳转到该歌曲的播放界面。开发者需要通过页面路由将这些页面串联起来,按需实现跳转。 - - -页面路由router根据页面的uri找到目标页面,从而实现跳转。以最基础的两个页面之间的跳转为例,具体实现步骤如下: - - -1. 在“Project“窗口,打开entry > src > mainjsdefault,右键点击pages文件夹,选择NewJS Page,创建一个详情页。 - -2. 调用router.push()路由到详情页。 - -3. 调用router.back()回到首页。 - - -## 构建页面布局 - -index和detail这两个页面均包含一个text组件和button组件:text组件用来指明当前页面,button组件用来实现两个页面之间的相互跳转。hml文件代码示例如下: - -``` - -
- This is the index page. - -
-``` - -``` - -
- This is the detail page. - -
-``` - - -## 构建页面样式 - -构建index和detail页面的页面样式,text组件和button组件居中显示,两个组件之间间距为50px。css代码如下(两个页面样式代码一致): - -``` -/* index.css */ -/* detail.css */ -.container { - flex-direction: column; - justify-content: center; - align-items: center; -} - -.title { - font-size: 50px; - margin-bottom: 50px; -} -``` - - -## 实现跳转 - -为了使button组件的launch方法生效,需要在页面的js文件中实现跳转逻辑。调用router.push()接口将uri指定的页面添加到路由栈中,即跳转到uri指定的页面。在调用router方法之前,需要导入router模块。代码示例如下: - -``` -// index.js -import router from '@system.router'; -export default { - launch() { - router.push ({ - uri: 'pages/detail/detail', - }); - }, -} -``` - -``` -// detail.js -import router from '@system.router'; -export default { - launch() { - router.back(); - }, -} -``` - -运行效果如下图所示: - -**图1** 页面路由效果 -![zh-cn_image_0000001070707559](/images/application-dev/ui/figures/zh-cn_image_0000001070707559.png) diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/04.\345\270\270\350\247\201\347\273\204\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274/01.Text.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/04.\345\270\270\350\247\201\347\273\204\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274/01.Text.md" deleted file mode 100644 index 909d685a2b54aa331d8e4b0a84ad35ac8b415fa3..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/04.\345\270\270\350\247\201\347\273\204\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274/01.Text.md" +++ /dev/null @@ -1,296 +0,0 @@ ---- -title: Text -permalink: /pages/010802020401 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:26 ---- -# Text - -Text是文本组件,用于呈现一段文本信息。具体用法请参考[Text API](/pages/010c0201010317)。 - - -## 创建Text组件 - -在pages/index目录下的hml文件中创建一个Text组件。 - -``` - -
- Hello World -
-``` - -``` -/* xxx.css */ -.container { - width: 100%; - height: 100%; - flex-direction: column; - align-items: center; - justify-content: center; - background-color: #F1F3F5; -} -``` - -![zh-cn_image_0000001211383427](/images/application-dev/ui/figures/zh-cn_image_0000001211383427.png) - - -## 设置Text组件样式和属性 - -- 添加文本样式 - - -设置color、font-size、allow-scale、word-spacing、text-valign属性分别为文本添加颜色、大小、缩放、文本之间的间距和文本在垂直方向的对齐方式。 - - -``` - -
- - This is a passage - - - This is a passage - -
-``` - - -``` -/* xxx.css */ -.container { - width: 100%; - height: 100%; - flex-direction: column; - align-items: center; - justify-content: center; - background-color: #F1F3F5; -} -``` - - -![zh-cn_image_0000001220778205](/images/application-dev/ui/figures/zh-cn_image_0000001220778205.png) - - -- 添加划线 - - -设置text-decoration和text-decoration-colo属性为文本添加划线和划线颜色,text-decoration枚举值请参考Text自有样式。 - - -``` - -
- - This is a passage - - - This is a passage - -
-``` - - -``` -/* xxx.css */ -.container { - width: 100%; - height: 100%; - flex-direction: column; - align-items: center; - justify-content: center; -} -text{ - font-size: 50px; -} -``` - - -![zh-cn_image_0000001220856725](/images/application-dev/ui/figures/zh-cn_image_0000001220856725.png) - - -- 隐藏文本内容 - - -当文本内容过多而显示不全时,添加text-overflow属性将隐藏内容以省略号的形式展现。 - - -``` - -
- - This is a passage - -
-``` - - -``` -/* xxx.css */ -.container { - width: 100%; - height: 100%; - flex-direction: column; - align-items: center; - background-color: #F1F3F5; - justify-content: center; -} -.text{ - width: 200px; - max-lines: 1; - text-overflow:ellipsis; -} -``` - - -> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** -> - text-overflow样式需要与max-lines样式配套使用,设置了最大行数的情况下生效。 -> -> - max-lines属性设置文本最多可以展示的行数。 - - -![zh-cn_image_0000001163656706](/images/application-dev/ui/figures/zh-cn_image_0000001163656706.png) - - -- 设置文本折行 - - -设置word-break属性对文本内容做断行处理,word-break枚举值请参考Text自有样式。 - - -``` - -
-
- - Welcome to the world - - - Welcome to the world - -
-
-``` - - -``` -/* xxx.css */ -.container { - background-color: #F1F3F5; - flex-direction: column; - align-items: center; - justify-content: center; -} -.content{ - width: 50%; - flex-direction: column; - align-items: center; - justify-content: center; -} -.text1{ - height: 200px; - border:1px solid #1a1919; - margin-bottom: 50px; - text-align: center; - word-break: break-word; - font-size: 40px; -} -.text2{ - height: 200px; - border:1px solid #0931e8; - text-align: center; - word-break: break-all; - font-size: 40px; -} -``` - - -![zh-cn_image_0000001209033195](/images/application-dev/ui/figures/zh-cn_image_0000001209033195.png) - - -- Text组件支持[Span](/pages/010c0201010315)子组件 - - -``` - -
- - This is a passage - - - This 1 is a 1 passage - -
-``` - - -![zh-cn_image_0000001163372568](/images/application-dev/ui/figures/zh-cn_image_0000001163372568.png) - - -> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** -> - 当使用Span子组件组成文本段落时,如果Span属性样式异常(例如:font-weight设置为1000),将导致文本段落显示异常。 -> -> - 在使用Span子组件时,注意Text组件内不能存在文本内容,如果存在文本内容也只会显示子组件Span里的内容。 - - -## 场景示例 - -Text组件通过数据绑定展示文本内容,Span组件通过设置show属性来实现文本内容的隐藏和显示。 - -``` - -
-
- - {{ content }} - - -
- - {{ content }} - - 1 - - Hide clip - -
-``` - -``` -/* xxx.css */ -.container { - align-items: center; - flex-direction: column; - justify-content: center; - background-color: #F1F3F5; -} -.title { - font-size: 26px; - text-align:center; - width: 200px; - height: 200px; -} -``` - -``` -// xxx.js -export default { - data: { - isShow:true, - content: 'Hello World' - }, - onInit(){ }, - test(e) { - this.isShow = e.checked - } -} -``` - -![zh-cn_image_0000001208636379](/images/application-dev/ui/figures/zh-cn_image_0000001208636379.gif) diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/04.\345\270\270\350\247\201\347\273\204\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274/02.Input.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/04.\345\270\270\350\247\201\347\273\204\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274/02.Input.md" deleted file mode 100644 index 0279dda01af8772a1b47086d0648d2a9e4649dff..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/04.\345\270\270\350\247\201\347\273\204\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274/02.Input.md" +++ /dev/null @@ -1,322 +0,0 @@ ---- -title: Input -permalink: /pages/010802020402 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:26 ---- -# Input - -Input是交互式组件,用于接收用户数据。其类型可设置为日期、多选框和按钮等。具体用法请参考[Input API](/pages/010c0201010306)。 - - -## 创建Input组件 - -在pages/index目录下的hml文件中创建一个Input组件。 - -``` - -
- Please enter the content -
-``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - justify-content: center; - align-items: center; - background-color: #F1F3F5; -} -``` - -![zh-cn_image_0000001165344988](/images/application-dev/ui/figures/zh-cn_image_0000001165344988.png) - - -## 设置Input类型 - -通过设置type属性来定义Input类型,如将Input设置为button、date等。 - -``` - -
-
- -
- this is a dialog -
-
- -
-
- -
-
- -
-
-``` - -``` -/* xxx.css */ -.container { - align-items: center; - flex-direction: column; - justify-content: center; - background-color: #F1F3F5 ; -} -.div-button { - flex-direction: column; - align-items: center; -} -.dialogClass{ - width:80%; - height: 200px; -} -.button { - margin-top: 30px; - width: 50%; -} -.content{ - width: 90%; - height: 150px; - align-items: center; - justify-content: center; -} -.flex { - width: 80%; - margin-bottom:40px; -} -``` - -``` -// xxx.js -export default { - btnclick(){ - this.$element('dialogId').show() - }, -} -``` - - -![zh-cn_image_0000001163375178](/images/application-dev/ui/figures/zh-cn_image_0000001163375178.gif) - - -> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** -> - 智能穿戴仅支Input类型设置为button、radio、checkbox。 -> -> - 仅当Input类型为checkbox和radio时,当前组件是否选中的属性checked才生效,默认值为false。 - - -## 事件绑定 - -向Input组件添加search和translate事件。 -``` - -
- - Enter text and then touch and hold what you've entered - - - -
-``` - -``` -/* xxx.css */ -.content { - width: 100%; - flex-direction: column; - align-items: center; - justify-content: center; - background-color: #F1F3F5; -} -.input { - margin-top: 50px; - width: 60%; - placeholder-color: gray; -} -text{ - width:100%; - font-size:25px; - text-align:center; -} -``` - -``` -// xxx.js -import prompt from '@system.prompt' -export default { - search(e){ - prompt.showToast({ - message: e.value, - duration: 3000, - }); - }, - translate(e){ - prompt.showToast({ - message: e.value, - duration: 3000, - }); - } -} -``` - -![zh-cn_image_0000001189088264](/images/application-dev/ui/figures/zh-cn_image_0000001189088264.gif) - - -## 设置输入提示 - -通过对Input组件添加showError方法来提示输入的错误原因。 - -``` - -
- - - -
-``` - -``` -/* xxx.css */ -.content { - width: 100%; - flex-direction: column; - align-items: center; - justify-content: center; - background-color: #F1F3F5; -} -.input { - width: 80%; - placeholder-color: gray; -} -.button { - width: 30%; - margin-top: 50px; -} -``` - -``` -// xxx.js -import prompt from '@system.prompt' - export default { - data:{ - value:'', - }, - change(e){ - this.value = e.value; - prompt.showToast({ - message: "value: " + this.value, - duration: 3000, - }); - }, - buttonClick(e){ - if(this.value.length > 6){ - this.$element("input").showError({ error: 'Up to 6 characters are allowed.' }); - }else if(this.value.length == 0){ - this.$element("input").showError({ error:this.value + 'This field cannot be left empty.' }); - }else{ - prompt.showToast({ - message: "success " - }); - } - }, - } -``` - -![zh-cn_image_0000001189248178](/images/application-dev/ui/figures/zh-cn_image_0000001189248178.gif) - -> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** -> - 该方法在Input类型为text、email、date、time、number和password时生效。 - - -## 场景示例 - - -根据场景选择不同类型的Input输入框,完成信息录入。 - - -``` - -
-
- -
-
- - -
-
- - -
-
- - -
-
- - -
-
- -
-
-``` - - -``` -/* xxx.css */ -.container { - flex-direction: column; - background-color: #F1F3F5; -} -.label-item { - align-items: center; - border-bottom-width: 1px;border-color: #dddddd; -} -.lab { - width: 400px;} -label { - padding: 30px; - font-size: 30px; - width: 320px; - font-family: serif; - color: #9370d8; - font-weight: bold; -} -.flex { - flex: 1; -} -.textareaPadding { - padding-left: 100px; -} -``` - - -``` -// xxx.js -import prompt from '@system.prompt'; -export default { - data: { - }, - onInit() { - }, - btnclick(e) { - prompt.showToast({ - message:'Saved successfully!' - }) - } -} -``` - - -![zh-cn_image_0000001188771358](/images/application-dev/ui/figures/zh-cn_image_0000001188771358.gif) diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/04.\345\270\270\350\247\201\347\273\204\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274/03.Button.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/04.\345\270\270\350\247\201\347\273\204\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274/03.Button.md" deleted file mode 100644 index 1009b8d4bad9700685dd8bcbb31c3df6d5af4d36..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/04.\345\270\270\350\247\201\347\273\204\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274/03.Button.md" +++ /dev/null @@ -1,294 +0,0 @@ ---- -title: Button -permalink: /pages/010802020403 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:26 ---- -# Button - -Button是按钮组件,其类型包括胶囊按钮、圆形按钮、文本按钮、弧形按钮、下载按钮。具体用法请参考[Button API](/pages/010c0201010301)。 - - -## 创建Button组件 - -在pages/index目录下的hml文件中创建一个Button组件。 - -``` - -
- -
-``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - justify-content: center; - align-items: center; - background-color: #F1F3F5; -} -``` - -![zh-cn_image_0000001211225091](/images/application-dev/ui/figures/zh-cn_image_0000001211225091.png) - - -## 设置Button类型 - -通过设置Button的type属性来选择按钮类型,如定义Button为圆形按钮、文本按钮等。 - - -``` - -
- - -
-``` - - -``` -/* xxx.css */ -.container { - background-color: #F1F3F5; - flex-direction: column; - align-items: center; - justify-content: center; -} -.circle { - font-size: 120px; - background-color: blue; - radius: 72px; -} -.text { - margin-top: 30px; - text-color: white; - font-size: 30px; - font-style: normal; - background-color: blue; - width: 50%; - height: 100px; -} -``` - - -![zh-cn_image_0000001208771093](/images/application-dev/ui/figures/zh-cn_image_0000001208771093.png) - - -> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** -> - 胶囊按钮(type=capsule)不支持border相关样式。 -> -> - 圆形按钮(type=circle)不支持文本相关样式。 -> -> - 文本按钮(type=text),自适应文本大小,不支持尺寸样式设置(radius,width,height),背景透明不支持background-color样式。 -> -> - Button组件使用的icon图标如果来自云端路径,需要添加网络访问权限 ohos.permission.INTERNET。 - - -如果需要添加ohos.permission.INTERNET权限,则在resources文件夹下的config.json文件里进行权限配置。 - - -``` - -"module": { - "reqPermissions": [{ - "name": "ohos.permission.INTERNET" - }], -} -``` - - -## 显示下载进度 - -为Button组件添加progress方法,来实时显示下载进度条的进度。 - -``` - -
- -
-``` - -``` -/* xxx.css */ -.container { - background-color: #F1F3F5; - flex-direction: column; - align-items: center; - justify-content: center; -} -.download { - width: 280px; - text-color: white; - background-color: #007dff; -} -``` - -``` -// xxx.js -import prompt from '@system.prompt'; -export default { - data: { - percent: 0, - downloadText: "Download", - isPaused: true, - intervalId : null, - }, - star(){ - this.intervalId = setInterval(()=>{ - if(this.percent <100){ - this.percent += 1; - this.downloadText = this.percent+ "%"; - } else{ - prompt.showToast({ - message: "Download succeeded." - }) - this.paused() - this.downloadText = "Download"; - this.percent = 0; - this.isPaused = true; - } - },100) - }, - paused(){ - clearInterval(this.intervalId); - this.intervalId = null; - }, - setProgress(e) { - if(this.isPaused){ - prompt.showToast({ - message: "Download started" - }) - this.star(); - this.isPaused = false; - }else{ - prompt.showToast({ - message: "Paused." - }) - this.paused(); - this.isPaused = true; - } - } -} -``` - -![zh-cn_image_0000001208393581](/images/application-dev/ui/figures/zh-cn_image_0000001208393581.gif) - -> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** -> - setProgress方法只支持button的类型为download。 - - -## 场景示例 - -在本场景中,开发者可根据输入的文本内容进行Button类型切换。 - - -``` - -
-
- -
-
-
- - -
-
-
-``` - - -``` -/* xxx.css */ -.container { - flex-direction: column; - align-items: center; - background-color: #F1F3F5; -} -.input-item { - margin-bottom: 80px; - flex-direction: column; -} -.doc-row { - justify-content: center; - margin-left: 30px; - margin-right: 30px; - justify-content: space-around; -} -.input-text { - height: 80px; - line-height: 80px; - padding-left: 30px; - padding-right: 30px; - margin-left: 30px; - margin-right: 30px; - margin-top:100px; - border: 3px solid; - border-color: #999999; - font-size: 30px; - background-color: #ffffff; - font-weight: 400; -} -.select-button { - width: 35%; - text-align: center; - height: 70px; - padding-top: 10px; - padding-bottom: 10px; - margin-top: 30px; - font-size: 30px; - color: #ffffff; -} -.color-3 { - background-color: #0598db;; -} -``` - - -``` -// xxx.js -export default { - data: { - myflex: '', - myholder: 'Enter text.', - myname: '', - mystyle1: "#ffffff", - mystyle2: "#ff0000", - mytype: 'text', - myvalue: '', - }, - onInit() { - }, - changetype3() { - this.myflex = ''; - this.myholder = 'Enter text.'; - this.myname = ''; - this.mystyle1 = "#ffffff"; - this.mystyle2 = "#FF0000"; - this.mytype = 'text'; - this.myvalue = ''; - }, - changetype4() { - this.myflex = ''; - this.myholder = 'Enter a date.'; - this.myname = ''; - this.mystyle1 = "#ffffff"; - this.mystyle2 = "#FF0000"; - this.mytype = 'date'; - this.myvalue = ''; - }, -} -``` - - -![zh-cn_image_0000001234129289](/images/application-dev/ui/figures/zh-cn_image_0000001234129289.gif) diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/04.\345\270\270\350\247\201\347\273\204\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274/04.List.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/04.\345\270\270\350\247\201\347\273\204\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274/04.List.md" deleted file mode 100644 index 39b47406a6551ba34db956571f797c4a56035025..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/04.\345\270\270\350\247\201\347\273\204\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274/04.List.md" +++ /dev/null @@ -1,316 +0,0 @@ ---- -title: List -permalink: /pages/010802020404 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# List - -List是用来显示列表的组件,包含一系列相同宽度的列表项,适合连续、多行地呈现同类数据。具体用法请参考[List API](/pages/010c0201010205)。 - - -## 创建List组件 - -在pages/index目录下的hml文件中创建一个List组件。 - -``` - -
- - - - - -
-``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - align-items: center; - background-color: #F1F3F5; -} -.listItem{ - height: 20%; - background-color:#d2e0e0; - margin-top: 20px; -} -``` - -![zh-cn_image_0000001211071477](/images/application-dev/ui/figures/zh-cn_image_0000001211071477.png) - -> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** -> - <list-item-group>是<list>的子组件,实现列表分组功能,不能再嵌套<list>,可以嵌套<list-item>。 -> -> - <list-item>是<list>的子组件,展示列表的具体项。 - - -## 添加滚动条 - -设置scrollbar属性为on即可在屏幕右侧生成滚动条,实现长列表或者屏幕滚动等效果。 - -``` - -
- - - - - - - - -
-``` - -``` -/* index.css */ -.container { - flex-direction: column; - background-color: #F1F3F5; -} -.listItem{ - height: 20%; - background-color:#d2e0e0; - margin-top: 20px; -} -.listCss{ - height: 100%; - scrollbar-color: #8e8b8b; - scrollbar-width: 50px; -} -``` - -![zh-cn_image_0000001163212980](/images/application-dev/ui/figures/zh-cn_image_0000001163212980.gif) - - -## 添加侧边索引栏 - -设置indexer属性为自定义索引时,索引栏会显示在列表右边界处,indexer属性设置为true,默认为字母索引表。 - -``` - -
- - - -
-``` - -``` -/* index.css */ -.container{ - flex-direction: column; - background-color: #F1F3F5; - } -.listCss{ - height: 100%; - flex-direction: column; - columns: 1 -} -``` - -![zh-cn_image_0000001166432552](/images/application-dev/ui/figures/zh-cn_image_0000001166432552.png) - -> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** -> - indexer属性生效需要flex-direction属性配合设置为column,且columns属性设置为1。 -> -> - indexer可以自定义索引表,自定义时"\#"必须要存在。 - - -## 实现列表折叠和展开 - -为List组件添加groupcollapse和groupexpand事件实现列表的折叠和展开。 - -``` - -
- - - -
- One---{{listgroup.value}} -
-
- -
- Primary---{{listgroup.value}} -
-
-
-
-
-``` - -``` -/* index.css */ -.doc-page { - flex-direction: column; - background-color: #F1F3F5; -} -list-item{ -margin-top:30px; -} -.top-list-item { - width:100%; - background-color:#D4F2E7; -} -.item-group-child { - justify-content: center; - align-items: center; - width:100%; -} -``` - -``` -// xxx.js -import prompt from '@system.prompt'; -export default { - data: { - direction: 'column', - list: [] - }, - onInit() { - this.list = [] - this.listAdd = [] - for (var i = 1; i <= 2; i++) { - var dataItem = { - value: 'GROUP' + i, - }; - this.list.push(dataItem); - } - }, - collapse(e) { - prompt.showToast({ - message: 'Close ' + e.groupid - }) - }, - expand(e) { - prompt.showToast({ - message: 'Open ' + e.groupid - }) - } -} -``` - -![zh-cn_image_0000001162911958](/images/application-dev/ui/figures/zh-cn_image_0000001162911958.gif) - -> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** -> - groupcollapse和groupexpand事件仅支持list-item-group组件使用。 - - -## 场景示例 - -在本场景中,开发者可以根据字母索引表查找对应联系人。 - - -``` - -
- - Contacts - - - -
-
- {{$item.name}} - 18888888888 -
-
-
- -
- Total: 10 -
-
-
-
-``` - - -``` -/* index.css */ -.doc-page { - flex-direction: column; - background-color: #F1F3F5; -} -.list { - width: 100%; - height: 100%; -} -.item { - height: 120px; - padding-left: 10%; - border-top: 1px solid #dcdcdc; -} -.name { - color: #000000; - font-size: 39px; -} -.phone { - color: black; - font-size: 25px; -} -.container { - flex-direction: row; - align-items: center; -} -.in-container { - flex-direction: column; - justify-content: space-around; -} -``` - - -``` -// xxx.js -export default { - data: { - namelist:[{ - name: 'Zoey', - section:'Z' - },{ - name: 'Quin', - section:'Q' - },{ - name:'Sam', - section:'S' - },{ - name:'Leo', - section:'L' - },{ - name:'Zach', - section:'Z' - },{ - name:'Wade', - section:'W' - },{ - name:'Zoe', - section:'Z' - },{ - name:'Warren', - section:'W' - },{ - name:'Kyle', - section:'K' - },{ - name:'Zaneta', - section:'Z' - }] - }, - onInit() { - } - } -``` - - -![zh-cn_image_0000001234287779](/images/application-dev/ui/figures/zh-cn_image_0000001234287779.gif) diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/04.\345\270\270\350\247\201\347\273\204\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274/05.Picker.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/04.\345\270\270\350\247\201\347\273\204\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274/05.Picker.md" deleted file mode 100644 index 55a353d987bd3ac6908b541aacd3ea8923b5d7d6..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/04.\345\270\270\350\247\201\347\273\204\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274/05.Picker.md" +++ /dev/null @@ -1,303 +0,0 @@ ---- -title: Picker -permalink: /pages/010802020405 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# Picker - -Picker是滑动选择器组件,类型支持普通选择器、日期选择器、时间选择器、时间日期选择器和多列文本选择器。具体用法请参考[Picker API](/pages/010c020101030b)。 - - -## 创建Picker组件 - -在pages/index目录下的hml文件中创建一个Picker组件。 - -``` - -
- picker -
-``` - -``` -/* index.css */ -.container { - flex-direction: column; - justify-content: center; - align-items: center; - background-color: #F1F3F5; -} -``` - -![zh-cn_image_0000001210951541](/images/application-dev/ui/figures/zh-cn_image_0000001210951541.gif) - - -## 设置Picker类型 - -通过设置Picker的type属性来选择滑动选择器类型,如定义Picker为日期选择器。 - -``` - -
- - -
-``` - -``` -/* index.css */ -.container { - flex-direction: column; - justify-content: center; - align-items: center; - background-color: #F1F3F5; -} -.pickertext{ - margin-bottom: 30px; -} -``` - -``` -// xxx.js -export default { - data: { - rangetext:['15', "20", "25"], - textvalue:'Select text', - datevalue:'Select date', - } -} -``` - -![zh-cn_image_0000001189098638](/images/application-dev/ui/figures/zh-cn_image_0000001189098638.gif) - -> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** -> - 普通选择器设置取值范围时,需要使用数据绑定的方式。 -> -> - 日期选择器的lunarswitch属性只支持手机和平板设备。 - - -## 设置时间展现格式 - -Picker的hours属性定义时间的展现格式,可选类型有12小时制和24小时制。 - -``` - -
- - -
-``` - -``` -/* index.css */ -.container { - flex-direction: column; - justify-content: center; - align-items: center; - background-color: #F1F3F5; -} -.pickertime { - margin-bottom:50px; - width: 300px; - height: 50px; -} -``` - -![zh-cn_image_0000001234327855](/images/application-dev/ui/figures/zh-cn_image_0000001234327855.gif) - -> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** -> - hours属性为12:按照12小时制显示,用上午和下午进行区分; -> -> - hours属性为24:按照24小时制显示。 - - -## 添加响应事件 - -对Picker添加change和cancel事件,来对选择的内容进行确定和取消。 - -``` - -
- -
-``` - -``` -/* index.css */ -.container { - flex-direction: column; - justify-content: center; - align-items: center; - background-color: #F1F3F5; -} -.pickermuitl { - margin-bottom:20px; - width: 600px; - height: 50px; - font-size: 25px; - letter-spacing:15px; -} -``` - -``` -// xxx.js -import prompt from '@system.prompt'; -export default { - data: { - multitext:[["a", "b", "c"], ["e", "f", "g"], ["h", "i"]], - multitextvalue:'Select multi-line text', - multitextselect:[0,0,0], - }, - multitextonchange(e) { - this.multitextvalue=e.newValue; - prompt.showToast({ message:"Multi-column text changed to:" + e.newValue }) - }, - multitextoncancel() { - prompt.showToast({ message:"multitextoncancel" }) - }, -} -``` - -![zh-cn_image_0000001234009343](/images/application-dev/ui/figures/zh-cn_image_0000001234009343.gif) - - -## 场景示例 - - -在本场景中,开发者可以自定义填写当前的健康情况来进行打卡。 - - -``` - -
- Health check-in -
- Office: - -
- -
- Office hours: - -
- -
- Having fever or cold symptoms - -
- -
- Close contact with someone with COVID-19 - -
-
- -
-
-``` - - -``` -/* index.css */ -.doc-page { - flex-direction: column; - background-color: #F1F3F5; -} -.title { - margin-top: 30px; - margin-bottom: 30px; - margin-left: 50px; - font-weight: bold; - color: #0000ff; - font-size: 38px; -} -.out-container { - flex-direction: column; - align-items: center; -} -.pick { - width: 80%; - height: 76px; - border: 1px solid #0000ff; - border-radius: 20px; - padding-left: 12px; -} -.txt { - width: 80%; - font-size: 18px; - text-align: left; - margin-bottom: 12px; - margin-left: 12px; -} -.dvd { - margin-top: 30px; - margin-bottom: 30px; - margin-left: 80px; - margin-right: 80px; - color: #6495ED; - stroke-width: 6px; -} -``` - - -``` -// xxx.js -import pmt from '@system.prompt' -export default { - data: { - yorn1:'No', - yorn2:'No', - pos:'Home', - yesno:['Yes', 'No'], - posarr:['Home', 'Company'], - datevalue:'Select time', - datetimeselect:'2012-5-6-11-25', - dateselect:'2021-9-17', - showbuild:true - }, - onInit() { - }, - isFever(e) { - this.yorn1 = e.newValue - }, - isTouch(e) { - this.yorn2 = e.newValue - }, - setPos(e) { - this.pos = e.newValue - if (e.newValue === 'Non-research center') { - this.showbuild = false - } else { - this.showbuild = true - } - }, - setbuild(e) { - this.build = e.newValue - }, - dateonchange(e) { - e.month=e.month+1; - this.datevalue = e.year + "-" + e.month + "-" + e.day; - pmt.showToast({ message:"date:"+e.year+"-"+e.month+"-"+e.day }) - }, - showtoast() { - pmt.showToast({ - message: 'Submitted.', - duration: 2000, - gravity: 'center' - }) - } -} -``` - - -![zh-cn_image_0000001234342189](/images/application-dev/ui/figures/zh-cn_image_0000001234342189.gif) diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/04.\345\270\270\350\247\201\347\273\204\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274/06.Dialog.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/04.\345\270\270\350\247\201\347\273\204\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274/06.Dialog.md" deleted file mode 100644 index f9bc5b47c81af4852613568d7ffe63e3e68c3ff0..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/04.\345\270\270\350\247\201\347\273\204\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274/06.Dialog.md" +++ /dev/null @@ -1,321 +0,0 @@ ---- -title: Dialog -permalink: /pages/010802020406 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# Dialog - -Dialog组件用于创建自定义弹窗,通常用来展示用户当前需要或用户必须关注的信息或操作。具体用法请参考[Dialog API](/pages/010c0201010202)。 - - -## 创建Dialog组件 - -在pages/index目录下的hml文件中创建一个Dialog组件,并添加Button组件来触发Dialog。Dialog组件仅支持width、height、margin、margin-[left|top|right|bottom]、margin-[start|end]样式。 -``` - -
-
- this is a dialog -
-
- -
-``` - -``` -/* xxx.css */ -.doc-page { - flex-direction: column; - align-items: center; - justify-content: center; - background-color: #F1F3F5; -} -.dialogClass{ - width: 80%; - height: 250px; - margin-start: 1%; -} -.content{ - width: 100%; - height: 250px; - justify-content: center; - background-color: #e8ebec; - border-radius: 20px; -} -text{ - width: 100%; - height: 100%; - text-align: center; -} -button{ - width: 70%; - height: 60px; -} -``` - -``` -/* xxx.js */ -export default { - //Touch to open the dialog box. - openDialog(){ - this.$element('dialogId').show() - }, -} -``` - -![zh-cn_image_0000001211246571](/images/application-dev/ui/figures/zh-cn_image_0000001211246571.gif) - - -## 设置弹窗响应 - -开发者点击页面上非Dialog的区域时,将触发cancel事件而关闭弹窗。同时也可以通过对Dialog添加show和close方法来显示和关闭弹窗。 - - -``` - -
- -
- dialog - -
-
- -
-``` - - -``` -/* xxx.css */ -.doc-page { - flex-direction: column; - align-items: center; - justify-content: center; - background-color: #F1F3F5; -} -.dialogClass{ - width: 80%; - height: 300px; - margin-start: 1%; -} -.dialogDiv{ - width: 100%; - flex-direction: column; - justify-content: center; - align-self: center; -} -text{ - height: 100px; - align-self: center; -} -button{ - align-self: center; - margin-top: 20px; - width: 60%; - height: 80px; -} -``` - - -``` -/* xxx.js */ -import prompt from '@system.prompt'; -export default { - openDialog(){ - this.$element('dialogId').show() - }, - confirmClick(e) { - this.$element('dialogId').close() - prompt.showToast({ - message: 'Confirmed.' - }) - }, -} -``` - - -![zh-cn_image_0000001163229150](/images/application-dev/ui/figures/zh-cn_image_0000001163229150.gif) - - -> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** -> - 仅支持单个子组件。 -> -> - Dialog属性、样式均不支持动态更新。 -> -> - Dialog组件不支持focusable、click-effect属性。 - - -## 场景示例 - - -在本场景中,开发者可以通过Dialog组件实现一个日程表。弹窗在打开状态下,利用[Textarea组件](/pages/010c0201010318)输入当前日程,点击确认按钮后获取当前时间并保存输入文本。最后以列表形式将各日程进行展示。 - - -``` - -
- - {{date}} events - -
- -
- - - -
- {{date}} event - {{$item.schedule}} -
-
-
- -
-
- {{date}} - New event -
- -
- - -
-
-
-
-``` - - -``` -/* xxx.css */ -.doc-page { - flex-direction: column; - background-color: #F1F3F5; -} -.btndiv { - width: 100%; - height: 200px; - flex-direction: column; - align-items: center; - justify-content: center; -} -.btn { - radius:60px; - font-size: 100px; - background-color: #1E90FF; -} -.schedulediv { - width: 100%; - height: 200px; - flex-direction: column; - justify-content: space-around; - padding-left: 55px; -} -.text1 { - color: #000000; - font-weight: bold; - font-size: 39px; -} -.text2 { - color: #a9a9a9; - font-size: 30px; -} -.dialogdiv { - flex-direction: column; - align-items: center; -} -.innertxt { - width: 320px; - height: 160px; - flex-direction: column; - align-items: center; - justify-content: space-around; -} -.text3 { - font-family: serif; - color: #1E90FF; - font-size: 38px; -} -.text4 { - color: #a9a9a9; - font-size: 33px; -} -.area { - width: 320px; - border-bottom: 1px solid #1E90FF; -} -.innerbtn { - width: 320px; - height: 120px; - justify-content: space-around; -} -.btntxt { - text-color: #1E90FF; -} -``` - - -``` -/* xxx.js */ -var info = null; -import prompt from '@system.prompt'; -import router from '@system.router'; -export default { - data: { - curYear:'', - curMonth:'', - curDay:'', - date:'', - schedule:'', - schedulelist:[] - }, - onInit() { - // Obtain the current date. - var date = new Date(); - this.curYear = date.getFullYear(); - this.curMonth = date.getMonth() + 1; - this.curDay = date.getDate(); - this.date = this.curYear + '-' + this.curMonth + '-' + this.curDay; - this.schedulelist = [] - }, - addschedule(e) { - this.$element('datedialog').show() - }, - canceldialog(e) { - prompt.showToast({ - message: 'Event setting canceled.' - }) - }, - getschedule(e) { - info = e.value - }, - cancelschedule(e) { - this.$element('datedialog').close() - prompt.showToast({ - message: 'Event setting canceled.' - }) - }, -// Touch OK to save the data. - setschedule(e) { - if (e.text === '') { - this.schedule = info - } else { - this.schedule = info - var addItem = {schedule: this.schedule,} - this.schedulelist.push(addItem) - } - this.$element('datedialog').close() - } -} -``` - - -![zh-cn_image_0000001234329527](/images/application-dev/ui/figures/zh-cn_image_0000001234329527.gif) diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/04.\345\270\270\350\247\201\347\273\204\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274/07.Form.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/04.\345\270\270\350\247\201\347\273\204\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274/07.Form.md" deleted file mode 100644 index 005f288ad1700e8e46ac2ca0b6c8e3f1cc2c5d4e..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/04.\345\270\270\350\247\201\347\273\204\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274/07.Form.md" +++ /dev/null @@ -1,204 +0,0 @@ ---- -title: Form -permalink: /pages/010802020407 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# Form - -Form是一个表单容器,支持容器内[Input](/pages/010c0201010306)组件内容的提交和重置。具体用法请参考[Form API](/pages/010c0201010204)。 - - -> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** -> 从 API Version 6 开始支持。 - - -## 创建Form组件 - -在pages/index目录下的hml文件中创建一个Form组件。 -``` - -
-
-
-
-``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - justify-content: center; - align-items: center; - background-color: #F1F3F5; -} -``` - -![zh-cn_image_0000001211069339](/images/application-dev/ui/figures/zh-cn_image_0000001211069339.png) - - -## 实现表单缩放 - -为Form组件添加click-effect属性,实现点击表单后的缩放效果,click-effect枚举值请参考[通用属性](/pages/010c0201010101)。 -``` - -
-
- -
-
-``` - - -## 设置Form样式 - - -通过为Form添加background-color和border属性,来设置表单的背景颜色和边框。 - - -``` -/* xxx.css */ -.container { - flex-direction: column; - align-items: center; - justify-content: center; - background-color: #F1F3F5; -} -.formClass{ - width: 80%; - padding: 10px; - border: 1px solid #c3d3e7; -} -``` - - -![zh-cn_image_0000001208771113](/images/application-dev/ui/figures/zh-cn_image_0000001208771113.gif) - - -## 添加响应事件 - -为Form组件添加submit和reset事件,来提交表单内容或重置表单选项。 -``` - -
-
-
-
- - - - -
-
- - -
-
-
-
-``` - -``` -/* xxx.js */ -import prompt from '@system.prompt'; -export default{ - onSubmit(result) { - prompt.showToast({ - message: result.value.radioGroup - }) - }, - onReset() { - prompt.showToast({ - message: 'Reset All' - }) - } -} -``` - - -![zh-cn_image_0000001234329539](/images/application-dev/ui/figures/zh-cn_image_0000001234329539.gif) - - -## 场景示例 - -在本场景中,开发者可以选择相应选项并提交或重置数据。 - -创建[Input](/pages/010c0201010306)组件,分别设置type属性为checkbox(多选框)和radio(单选框),再使用Form组件的onsubmit和onreset事件实现表单数据的提交与重置。 - -``` - -
-
- - Form - -
- Select 1 or more options -
- - - - -
- - Select 1 option -
- - - - -
- - Text box - -
- Submit - Reset -
-
-
-
-``` - -``` -/* index.css */ -.container { - flex-direction:column; - align-items:center; - background-color:#F1F3F5; -} -.txt { - font-size:33px; - font-weight:bold; - color:darkgray; -} -label{ - font-size: 20px; -} -``` - -``` -/* xxx.js */ -import prompt from '@system.prompt'; -export default { - formSubmit() { - prompt.showToast({ - message: 'Submited.' - }) - }, - formReset() { - prompt.showToast({ - message: 'Reset.' - }) - } -} -``` - -![zh-cn_image_0000001234289465](/images/application-dev/ui/figures/zh-cn_image_0000001234289465.gif) diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/04.\345\270\270\350\247\201\347\273\204\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274/08.Stepper.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/04.\345\270\270\350\247\201\347\273\204\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274/08.Stepper.md" deleted file mode 100644 index 503d571ff39379500ec78a1f8e74fc527dcac8cc..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/04.\345\270\270\350\247\201\347\273\204\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274/08.Stepper.md" +++ /dev/null @@ -1,399 +0,0 @@ ---- -title: Stepper -permalink: /pages/010802020408 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# Stepper - -当一个任务需要多个步骤时,可以使用stepper组件展示当前进展。具体用法请参考[Stepper API](/pages/010c020101020c)。 - - -> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** -> 从API Version 5 开始支持。 - - -## 创建Stepper组件 - -在pages/index目录下的hml文件中创建一个Stepper组件。 - -``` - -
- - Step 1 - - - Step 2 - - -
-``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - justify-content: center; - align-items: center; - background-color: #F1F3F5; -} -text{ - width: 100%; - height: 100%; - text-align: center; -} -``` - -![zh-cn_image_0000001234289455](/images/application-dev/ui/figures/zh-cn_image_0000001234289455.gif) - - -## 设置index属性 - -页面默认显示索引值为index的步骤。 - -``` - -
- - - stepper-item1 - - - stepper-item2 - - - stepper-item3 - - -
-``` - -``` -/* index.css */ -.container { - flex-direction: column; - background-color:#F1F3F5; -} -text{ - width: 100%; - height: 100%; - text-align: center; -} -``` - -![zh-cn_image_0000001234011019](/images/application-dev/ui/figures/zh-cn_image_0000001234011019.gif) - -通过设置label属性,自定义stepper-item的提示按钮。 - -``` - -
- - - stepper-item1 - - - stepper-item2 - - - stepper-item3 - - - stepper-item4 - - -
-``` - -``` -/* index.css */ -.container { - flex-direction: column; - background-color:#F1F3F5; -} -text{ - width: 100%; - height: 100%; - text-align: center; -} -``` - -``` -/* index.js */ -export default { - data: { - label_1:{ nextLabel: 'NEXT', status: 'normal' }, - label_2:{ - prevLabel: 'BACK', - nextLabel: 'NEXT', - status: 'normal' - }, - label_3:{ - prevLabel: 'BACK', - nextLabel: 'END', - status: 'disabled' - }, - }, -} -``` - -![zh-cn_image_0000001163531210](/images/application-dev/ui/figures/zh-cn_image_0000001163531210.gif) - - -## 设置样式 - -Stepper组件默认填充父容器,通过border和background-color设置边框、背景色。 -``` - -
-
- - - stepper-item1 - - -
-
-``` - -``` -/* index.css */ -.container { - flex-direction: column; - align-items: center; - justify-content: center; - background-color:#F1F3F5; -} -.stepperContent{ - width: 300px; - height: 300px; -} -.stepperClass{ - border:1px solid silver ; background-color: white; -} -text{ - width: 100%; - height: 100%; - text-align: center; -} -``` - -![zh-cn_image_0000001234130975](/images/application-dev/ui/figures/zh-cn_image_0000001234130975.png) - - -## 添加事件 - -Stepper分别添加finish,change,next,back,skip事件。 - -- 当change与next或back同时存在时,会先执行next或back事件再去执行change事件。 - -- 重新设置index属性值时要先清除index的值再重新设置,否则检测不到值的改变。 - -``` - -
-
- - - stepper-item1 - - - - stepper-item2 - - - - stepper-item3 - - -
-
-``` - -``` -/* xxx.css */ -.doc-page { - flex-direction: column; - align-items: center; - justify-content: center; -} -stepper-item{ - width: 100%; - flex-direction: column; - align-self: center; - justify-content: center; -} -text{ - margin-top: 45%; - justify-content: center; - align-self: center; - margin-bottom: 50px; -} -button{ - width: 80%; - height: 60px; - margin-top: 20px; -} -``` - -``` -/* index.js */ -import prompt from '@system.prompt'; -export default { - data: { - index:0, - }, - stepperSkip(){ - this.index = null; - this.index=2; - }, - skipClick(){ - this.$element('stepperId').setNextButtonStatus({status: 'skip', label: 'SKIP'}); - }, - stepperFinish(){ - prompt.showToast({ - message: 'All Finished' - }) - }, - stepperChange(e){ - console.log("stepperChange"+e.index) - prompt.showToast({ - message: 'Previous step: '+e.prevIndex+"-------Current step:"+e.index - }) - }, - stepperNext(e){ - console.log("stepperNext"+e.index) - prompt.showToast({ - message: 'Current step:'+e.index+"-------Next step:"+e.pendingIndex - }) - var index = {pendingIndex:e.pendingIndex } - return index; - }, - stepperBack(e){ - console.log("stepperBack"+e.index) - var index = {pendingIndex: e.pendingIndex } - return index; - } -} -``` - -![zh-cn_image_0000001189089950](/images/application-dev/ui/figures/zh-cn_image_0000001189089950.gif) - - -## 场景示例 - -在本场景中,开发者可以在界面上点击选择并实时显示选择结果,点击下一步按钮后可动态修改页面的字体颜色和字体大小。 - -用Stepper组件实现分步,再创建[Toggle](/pages/010c020101031b)组件实现选择显示功能,再使用[Select](/pages/010c0201010313)组件实现改变选中值动态修改字体颜色或大小。 - -``` -
- - -
- Select error types: - - {{error}} - -
- -
-
-
- -
- Toggle -
- - -
-
-
- text-color - -
-
- font-size - -
-
-
-
-
-
-``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - align-items: center; - justify-content: center; - background-color:#F1F3F5; -} -.dvd { - stroke-width: 8px; - color: orangered; - margin: 65px; -} -.tog{ - margin-right: 20px; - margin-top: 30px; -} -``` - -``` -/* index.js */ -import prompt from '@system.prompt'; -import router from '@system.router'; -let myset = new Set(); -export default { - data: { - error: '', - tcolor:'#FF4500', - color_list:['#FF4500','#5F9EA0','#0000FF'], - tsize: '12px', - size_list: ['12px', '30px', '8px', '50px'], - label1: { - prevLabel: 'The text on the left of the starting step is invalid.', - nextLabel: 'Toggle' - }, - label2: { - prevLabel: 'toggle', - nextLabel: 'END' - }, - togglelist1:['Program error', 'Software', 'System', 'Application'], - }, - multiTog(arg, e) { - this.error = ' ' - if (e.checked) { - myset.add(arg) - } else { - myset.delete(arg) - } - for (let item of myset) { - this.error += item + ' ' - } - }, - settcolor(e) { - this.tcolor = e.newValue - }, - settsize(e) { - this.tsize = e.newValue - } -} -``` - -![zh-cn_image_0000001189249862](/images/application-dev/ui/figures/zh-cn_image_0000001189249862.gif) diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/04.\345\270\270\350\247\201\347\273\204\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274/09.Tabs.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/04.\345\270\270\350\247\201\347\273\204\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274/09.Tabs.md" deleted file mode 100644 index 145eb575ea34ad9bf2d031df9ba5dd2bdc4b88bd..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/04.\345\270\270\350\247\201\347\273\204\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274/09.Tabs.md" +++ /dev/null @@ -1,318 +0,0 @@ ---- -title: Tabs -permalink: /pages/010802020409 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# Tabs - -Tabs是一种常见的界面导航结构。通过页签容器,用户可以快捷地访问应用的不同模块。具体用法请参考[Tabs API](/pages/010c020101020f)。 - - -## 创建Tabs - -在pages/index目录下的hml文件中创建一个Tabs组件。 - -``` - -
- - item1 - item2 - - -
- content1 -
-
- content2 -
-
-
-
-``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - justify-content: center; - align-items: center; - background-color: #F1F3F5; -} -.text{ - width: 100%; - height: 100%; - justify-content: center; - align-items: center; -} -``` - -![zh-cn_image_0000001165191390](/images/application-dev/ui/figures/zh-cn_image_0000001165191390.gif) - - -## 设置Tabs方向 - -Tabs默认展示索引为index的标签及内容。通过设置vertical属性使组件纵向展示。 - -``` - -
- - - item1 - item2 - - -
- -
-
- -
-
-
-
-``` - -![zh-cn_image_0000001208908643](/images/application-dev/ui/figures/zh-cn_image_0000001208908643.gif) - -设置mode属性使tab-bar的子组件均分,设置scrollable属性使tab-content不可进行左右滑动切换内容。 - -``` - -
- - - item1 - item2 - - -
- -
-
- -
-
-
-
-``` - -![zh-cn_image_0000001209028575](/images/application-dev/ui/figures/zh-cn_image_0000001209028575.gif) - - -## 设置样式 - -设置Tabs背景色及边框和tab-content布局。 -``` - -
- - - item1 - item2 - - -
- content1 -
-
- content2 -
-
-
-
-``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - justify-content: flex-start; - align-items: center; - background-color:#F1F3F5; -} -.tabs{ - margin-top: 20px; - border: 1px solid #2262ef; - width: 99%; - padding: 10px; -} -.tabBar{ - width: 100%; - border: 1px solid #78abec; -} -.tabContent{ - width: 100%; - margin-top: 10px; - height: 300px; - color: blue; - justify-content: center; align-items: center; -} -``` - -![zh-cn_image_0000001163388642](/images/application-dev/ui/figures/zh-cn_image_0000001163388642.gif) - - -## 显示页签索引 - -开发者可以为Tabs添加change事件,实现页签切换后显示当前页签索引的功能。 - -``` - -
- - - item1 - item2 - - -
- -
-
- -
-
-
-
-``` - -``` -/* index.js */ -import prompt from '@system.prompt'; -export default { - tabChange(e){ - prompt.showToast({ - message: "Tab index: " + e.index - }) - } -} -``` - -![zh-cn_image_0000001163228638](/images/application-dev/ui/figures/zh-cn_image_0000001163228638.gif) - - -> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** -> -> - tabs子组件仅支持一个[\](/pages/010c0201010210)和一个\[](/pages/010c0201010211)。 - - -## 场景示例 - -在本场景中,开发者可以点击标签切换内容,选中后标签文字颜色变红,并显示下划线。 - -用tabs、tab-bar和tab-content实现点击切换功能,再定义数组,设置属性。使用change事件改变数组内的属性值实现变色及下划线的显示。 - -``` - -
- - -
-
- -
-
- -
-
- -
-
-
- -
- {{$item.title}} -
-
-
-
-
-
-``` - -``` -/* xxx.css */ -.container{ -background-color:#F1F3F5; -} -.tab_bar { - width: 100%; -} -.tab_item { - flex-direction: column; - align-items: center; -} -.tab_item text { - font-size: 32px; -} -.item-container { - justify-content: center; - flex-direction: column; -} -.underline-show { - height: 2px; - width: 160px; - background-color: #FF4500; - margin-top: 7.5px; -} -.underline-hide { - height: 2px; - margin-top: 7.5px; - width: 160px; -} -``` - -``` -/* index.js */ -import prompt from '@system.prompt'; -export default { - data() { - return { - datas: { - color_normal: '#878787', - color_active: '#ff4500', - show: true, - list: [{ - i: 0, - color: '#ff4500', - show: true, - title: 'List1' - }, { - i: 1, - color: '#878787', - show: false, - title: 'List2' - }, { - i: 2, - color: '#878787', - show: false, - title: 'List3' - }] - } - } - }, - changeTabactive (e) { - for (let i = 0; i < this.datas.list.length; i++) { - let element = this.datas.list[i]; - element.show = false; - element.color = this.datas.color_normal; - if (i === e.index) { - element.show = true; - element.color = this.datas.color_active; - } - } - } -} -``` - -![zh-cn_image_0000001163228602](/images/application-dev/ui/figures/zh-cn_image_0000001163228602.gif) diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/04.\345\270\270\350\247\201\347\273\204\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274/10.Image.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/04.\345\270\270\350\247\201\347\273\204\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274/10.Image.md" deleted file mode 100644 index 915cf50e4c44a02cfe8afda809b33e44a8d7ba17..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/04.\345\270\270\350\247\201\347\273\204\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274/10.Image.md" +++ /dev/null @@ -1,281 +0,0 @@ ---- -title: Image -permalink: /pages/01080202040a -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# Image - -Image是图片组件,用来渲染展示图片。具体用法请参考[Image API](/pages/010c0201010304)。 - - -## 创建Image组件 - -在pages/index目录下的hml文件中创建一个Image组件。 -``` - -
- -
-``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - justify-content: center; - align-items: center; - background-color: #F1F3F5; -} -``` - -![zh-cn_image_0000001211227617](/images/application-dev/ui/figures/zh-cn_image_0000001211227617.png) - - -## 设置Image样式 - -通过设置width、height和object-fit属性定义图片的宽、高和缩放样式。 - - -``` - -
- -
-``` - - -``` -/* xxx.css */ -.container { - flex-direction: column; - align-items: center; - justify-content: center; -background-color:#F1F3F5; -} -image{ - width: 80%; height: 500px; - border: 5px solid saddlebrown; - border-radius: 20px; - object-fit: contain; - match-text-direction:true; - -} -``` - - -![zh-cn_image_0000001163532072](/images/application-dev/ui/figures/zh-cn_image_0000001163532072.png) - - -## 显示多张图 - -定义for循环展示多张图片,同时定义option选择图片的展示方式,选择方式请参考object-fit类型说明。 -``` - -
- - - -
- image{{$idx}} - content -
-
-
-
- -
-
-``` - -``` -/* xxx.css */ -.page-container { - flex-direction:column; - background-color:#F1F3F5; -} -.text-container { - width: 300px; - flex-direction: column; - justify-content: center; -} -.item-container { - flex-direction: row; - align-items: center; - justify-content:center; - margin-top:200px; -} -.testimage { - width: 175px; - height: 220px; - border: 5px solid #add8e6; - padding: 5px 5px 5px 5px; - margin: 5px 5px 5px 5px; -} -.testicon { - width: 50px; - height: 50px; - margin-left: 150px; - border-radius: 25px; - background-color: orange; -} -``` - -``` -/* index.js */ -export default { - data: { - url:['common/images/bg-tv.jpg','common/images/img2.jpg'], - list:[0,1], - fit:'cover', - fit_list:['cover','contain','fill','none','scale-down'] - }, - setfit(e) { - this.fit = e.newValue - } -} -``` - - -![zh-cn_image_0000001208787005](/images/application-dev/ui/figures/zh-cn_image_0000001208787005.gif) - - -## 加载图片 - -图片成功加载时触发complete事件,返回加载的图源尺寸。加载失败则触发error事件,打印图片加载失败。 - -``` - -
-
- -
-
- -
-
-``` - -``` -/* xxx.css */ -.container{ - flex-direction: column; - justify-content: center; - align-self: center; - background-color: #F1F3F5; -} -.container div{ - margin-left: 10%; - width: 80%; - height: 300px; - margin-bottom: 40px; -} -``` - -``` -/* index.js */ -import prompt from '@system.prompt'; -export default { - imageComplete(i,e){ - prompt.showToast({ - message: "Image "+i+"'s width"+ e.width+"----Image "+i+"'s height"+e.height, - duration: 3000, - }) - }, - imageError(i,e){ - setTimeout(()=>{ - prompt.showToast({ - message: "Failed to load image "+i+".", - duration: 3000, - }) - },3000) - } -} -``` - -![zh-cn_image_0000001188931396](/images/application-dev/ui/figures/zh-cn_image_0000001188931396.gif) - - -## 场景示例 - -在本场景中,开发者长按图片后将慢慢隐藏图片,当完全隐藏后再重新显示原始图片。定时器setInterval每隔一段时间改变图片透明度,实现慢慢隐藏的效果,当透明度为0时清除定时器,设置透明度为1。 -``` - -
-
-
- -
-
- Touch and hold the image -
-
-
-``` - -``` -/* xxx.css */ -.page-container { - flex-direction:column; - align-self: center; - justify-content: center; - background-color:#F1F3F5; - background-color: #F1F3F5; -} -.content{ - flex-direction:column; -} -.image-container { - width: 100%; - height: 300px; - align-items: center; - justify-content: center; -} -.text-container { - margin-top:50px; - width: 100%; - height: 60px; - flex-direction: row; - justify-content: space-between; -} -.testimage { - width: 100%; height: 400px; object-fit: scale-down; border-radius: 20px;} -``` - -``` -/* index.js */ -import prompt from '@system.prompt'; -export default { - data: { - testuri: 'common/images/bg-tv.jpg', - imageopacity:1, - timer: null - }, - changeopacity: function () { - prompt.showToast({ - message: 'Touch and hold the image.' - }) - var opval = this.imageopacity * 20 - clearInterval(this.timer); - this.timer = setInterval(()=>{ - opval--; - this.imageopacity = opval / 20 - if (opval===0) { - clearInterval(this.timer) - this.imageopacity = 1 - } - },100); - } -} -``` - -![zh-cn_image_0000001188771430](/images/application-dev/ui/figures/zh-cn_image_0000001188771430.gif) diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/05.\345\212\250\346\225\210\345\274\200\345\217\221\346\214\207\345\257\274/01.CSS\345\212\250\347\224\273/01.\345\261\236\346\200\247\346\240\267\345\274\217\345\212\250\347\224\273.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/05.\345\212\250\346\225\210\345\274\200\345\217\221\346\214\207\345\257\274/01.CSS\345\212\250\347\224\273/01.\345\261\236\346\200\247\346\240\267\345\274\217\345\212\250\347\224\273.md" deleted file mode 100644 index ebbe60f4ef8cb4e44bb2deb97b694ce8f367368a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/05.\345\212\250\346\225\210\345\274\200\345\217\221\346\214\207\345\257\274/01.CSS\345\212\250\347\224\273/01.\345\261\236\346\200\247\346\240\267\345\274\217\345\212\250\347\224\273.md" +++ /dev/null @@ -1,105 +0,0 @@ ---- -title: 属性样式动画 -permalink: /pages/01080202050101 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# 属性样式动画 - - - -在关键帧(Keyframes)中动态设置父组件的width和height,实现组件变大缩小。子组件设置scale属性使父子组件同时缩放,再设置opacity实现父子组件的显示与隐藏。 - - -``` - -
-
- fading away -
-
- getting bigger -
-
-``` - - -``` -/* xxx.css */ -.container { - background-color:#F1F3F5; - display: flex; - justify-content: center; - align-items: center; - flex-direction: column; -} -.fade{ - width: 30%; - height: 200px; - left: 35%; - top: 25%; - position: absolute; - animation: 2s change infinite friction; -} -.bigger{ - width: 20%; - height: 100px; - background-color: blue; - animation: 2s change1 infinite linear-out-slow-in; -} -text{ - width: 100%; - height: 100%; - text-align: center; - color: white; - font-size: 35px; - animation: 2s change2 infinite linear-out-slow-in; -} -/* 颜色变化 */ -@keyframes change{ - from { - background-color: #f76160; - opacity: 1; - } - to { - background-color: #09ba07; - opacity: 0; - } -} -/* 父组件大小变化 */ -@keyframes change1{ - 0% { - width: 20%; - height: 100px; - } - 100% { - width: 80%; - height: 200px; - } -} -/* 子组件文字缩放 */ -@keyframes change2{ - 0%{ - transform: scale(0); - } - 100% { - transform: scale(1.5); - } -} -``` - - -![zh-cn_image_0000001217168141](/images/application-dev/ui/figures/zh-cn_image_0000001217168141.gif) - - -> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** -> 1. animation取值不区分先后,duration (动画执行时间)/ delay (动画延迟执行时间)按照出现的先后顺序解析。 -> -> 2. 必须设置animation-duration样式,否则时长为0则不会有动画效果。当设置animation-fill-mode属性为forwards时,组件直接展示最后一帧的样式。 diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/05.\345\212\250\346\225\210\345\274\200\345\217\221\346\214\207\345\257\274/01.CSS\345\212\250\347\224\273/02.transform\346\240\267\345\274\217\345\212\250\347\224\273.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/05.\345\212\250\346\225\210\345\274\200\345\217\221\346\214\207\345\257\274/01.CSS\345\212\250\347\224\273/02.transform\346\240\267\345\274\217\345\212\250\347\224\273.md" deleted file mode 100644 index e41dea2a8b8647b83d85fd678779017c363a44e0..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/05.\345\212\250\346\225\210\345\274\200\345\217\221\346\214\207\345\257\274/01.CSS\345\212\250\347\224\273/02.transform\346\240\267\345\274\217\345\212\250\347\224\273.md" +++ /dev/null @@ -1,585 +0,0 @@ ---- -title: transform样式动画 -permalink: /pages/01080202050102 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# transform样式动画 - -设置transform属性对组件进行旋转、缩放、移动和倾斜。 - - -## 设置静态动画 - -创建一个正方形并旋转90°变成菱形,并用下方的长方形把菱形下半部分遮盖形成屋顶,设置长方形translate属性值为(150px,-150px)确定坐标位置形成门,再使用position属性使横纵线跟随父组件(正方形)移动到指定坐标位置,接着设置scale属性使父子组件一起变大形成窗户大小,最后使用skewX属性使组件倾斜后设置坐标translate(200px,-830px)得到烟囱。 - -``` - -
-
-
-
- -
-
-
-
-
-
-``` - -``` -/* xxx.css */ -.container { - background-color:#F1F3F5; - align-items: center; - flex-direction: column; -} -.top{ - z-index: -1; - position: absolute; - width: 428px; - height: 428px; - background-color: #860303; - transform: rotate(45deg); - margin-top: 230px; - margin-left: 266px; -} -.content{ - margin-top: 500px; - width: 600px; - height: 400px; - background-color: white; - border: 1px solid black; -} -.door{ - width: 100px; - height: 150px; - background-color: #1033d9; - transform: translate(150px,-150px); -} -.window{ - z-index: 1; - position: relative; - width: 100px; - height: 100px; - background-color: white; - border: 1px solid black; - transform: translate(-150px,-400px) scale(1.5); -} -/* 窗户的横轴 */ -.horizontal{ - position: absolute; - top: 50%; - width: 100px; - height: 5px; - background-color: black; -} -/* 窗户的纵轴 */ -.vertical{ - position: absolute; - left: 50%; - width: 5px; - height: 100px; - background-color: black; -} -.chimney{ - z-index: -2; - width: 40px; - height: 100px; - border-radius: 15px; - background-color: #9a7404; - transform: translate(200px,-830px) skewX(-5deg); -} -``` - -![zh-cn_image_0000001220634677](/images/application-dev/ui/figures/zh-cn_image_0000001220634677.png) - - -## 设置平移动画 - -小球下降动画,改变小球的Y轴坐标实现小球下落,在下一段是时间内减小Y轴坐标实现小球回弹,让每次回弹的高度逐次减小直至回弹高度为0,就模拟出了小球下降的动画。 - -``` - -
-
-
-
-``` - -``` -/* xxx.css */ -.container { - background-color:#F1F3F5; - display: flex; - justify-content: center; -} -.circle{ - width: 100px; - height: 100px; - border-radius: 50px; - background-color: red; - /* forwards停在动画的最后一帧 */ - animation: down 3s fast-out-linear-in forwards; -} -.flower{ - position: fixed; - width: 80%; - margin-left: 10%; - height: 5px; - background-color: black; - top: 1000px; -} -@keyframes down { - 0%{ - transform: translate(0px,0px); - } - /* 下落 */ - 15%{ - transform: translate(10px,900px); - } - /* 开始回弹 */ - 25%{ - transform: translate(20px,500px); - } - /* 下落 */ - 35%{ - transform: translate(30px,900px); - } - /* 回弹 */ - 45%{ - transform: translate(40px,700px); - } - 55%{ - transform: translate(50px,900px); - } - 65%{ - transform: translate(60px,800px); - } - 80%{ - transform: translate(70px,900px); - } - 90%{ - transform: translate(80px,850px); - } - /* 停止 */ - 100%{ - transform: translate(90px,900px); - } -} -``` - -![zh-cn_image_0000001174756438](/images/application-dev/ui/figures/zh-cn_image_0000001174756438.gif) - - -## 设置旋转动画 - -设置不同的原点位置(transform-origin)改变元素所围绕的旋转中心。rotate3d属性前三个参数值分别为X轴、Y轴、Z轴的旋转向量,第四个值为旋转角度,旋转向角度可为负值,负值则代表旋转方向为逆时针方向。 - -``` - -
-
-
-
-
-
- -
-
-
-
-
-
-
-
-``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - background-color:#F1F3F5; - display: flex; - align-items: center; - justify-content: center; -} -.rect{ - width: 100px; - height: 100px; - animation: rotate 3s infinite; - margin-left: 100px; -} -.rect1{ - background-color: #f76160; -} -.rect2{ - background-color: #60f76f; - /* 改变原点位置*/ - transform-origin: 10% 10px; -} -.rect3{ - background-color: #6081f7; - /* 改变原点位置*/ - transform-origin: right bottom; -} -@keyframes rotate { - from { - transform: rotate(0deg) - } - to { - transform: rotate(360deg); - } -} -/* 3d示例样式 */ -.rotate3d{ - margin-top: 150px; - flex-direction: column; - background-color:#F1F3F5; - display: flex; - align-items: center; - width: 80%; - height: 600px; - border-radius: 300px; - border: 1px solid #ec0808; -} -.content{ - padding-top: 150px; - display: flex; - align-items: center; - justify-content: center; -} -/* react4 react5 翻转形成眼睛 */ -.rect4{ - width: 100px; - height: 100px; - animation: rotate3d1 17ms infinite; - background: linear-gradient(#e6c4ec, #be15d9) -} -.rect5{ - width: 100px; - height: 100px; - animation: rotate3d1 17ms infinite; - margin-left: 100px; - background: linear-gradient(#e6c4ec, #be15d9) -} -.mouse{ - margin-top: 150px; - width: 200px; - height: 100px; - border-radius: 50px; - border: 1px solid #e70303; - animation: rotate3d2 17ms infinite; -} -/* 眼睛的动效 */ -@keyframes rotate3d1{ - 0% { - transform:rotate3d(0,0,0,0deg) - } - 50% { - transform:rotate3d(20,20,20,360deg); - } - 100% { - transform:rotate3d(0,0,0,0deg); - } -} -/* 嘴的动效 */ -@keyframes rotate3d2{ - 0% { - transform:rotate3d(0,0,0,0deg) - } - 33% { - transform:rotate3d(0,0,10,30deg); - } - 66% { - transform:rotate3d(0,0,10,-30deg); - } - 100% { - transform:rotate3d(0,0,0,0deg); - } -} -``` - -![zh-cn_image_0000001220316305](/images/application-dev/ui/figures/zh-cn_image_0000001220316305.gif) - -> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** -> transform-origin变换对象的原点位置,如果仅设置一个值,另一个值为50%,若设置两个值第一个值表示X轴的位置,第二个值表示Y轴的位置。 - - -## 设置缩放动画 - -设置scale样式属性实现涟漪动画,先使用定位确定元素的位置,确定坐标后创建多个组件实现重合效果,再设置opacity属性改变组件不透明度实现组件隐藏与显示,同时设置scale值使组件可以一边放大一边隐藏,最后设置两个组件不同的动画执行时间,实现扩散的效果。 - -设置sacle3d中X轴、Y轴、Z轴的缩放参数实现动画。 - -``` - -
-
- ripple -
-
-
- -
- spring -
-
-``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - background-color:#F1F3F5; - width: 100%; - position: relative; -} -.circle{ - margin-top: 400px; - margin-left: 40%; - width: 100px; - height: 100px; - border-radius: 50px; - background:linear-gradient(#dcaec1, #d3a8e3); - z-index: 1; position: absolute; -} -.ripple{ - margin-top: 400px; - margin-left: 40%; - position: absolute; z-index: 0; - width: 100px; - height: 100px; - border-radius: 50px; - background:linear-gradient(#dcaec1,#d3a8e3); - animation: ripple 5s infinite; -} -/* 设置不同的动画时间 */ -.ripple2{ - animation-duration: 2.5s; -} -@keyframes ripple{ - 0%{ - transform: scale(1); - opacity: 0.5; - } - 50%{ - transform: scale(3); - opacity: 0; - } - 100%{ - transform: scale(1); - opacity: 0.5; - } -} -text{ - color: white; - text-align: center; - height: 100%; - width: 100%; -} -.content { - margin-top: 700px; - margin-left: 33%; - width: 200px; - height: 100px; - animation:rubberBand 1s infinite; - /* 设置渐变色 */ - background:linear-gradient(#e276aa,#ec0d66); - position: absolute; -} -@keyframes rubberBand { - 0% { - transform: scale3d(1, 1, 1); - } - 30% { - transform: scale3d(1.25, 0.75, 1.1); - } - 40% { - transform: scale3d(0.75, 1.25, 1.2); - } - 50% { - transform: scale3d(1.15, 0.85, 1.3); - } - 65% { - transform: scale3d(.95, 1.05, 1.2); - } - 75% { - transform: scale3d(1.05, .95, 1.1); - } - 100%{ - transform: scale3d(1, 1, 1); - } -} -``` - -![zh-cn_image_0000001220396251](/images/application-dev/ui/figures/zh-cn_image_0000001220396251.gif) - -> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** -> 设置transform属性值后,子元素会跟着父元素一起改变,若只改变父元素其他属性值时(如:height,width),子元素不会改变。 - - -## 设置matrix属性 - -matrix是一个入参为六个值的矩阵,6个值分别代表:scaleX, skewY, skewX, scaleY, translateX, translateY。下面示例中设置 了matrix属性为matrix(1,0,0,1,0,200)使组件移动和倾斜。 - -``` - -
-
-
-``` - -``` -/* xxx.css */ -.container{ - background-color:#F1F3F5; - display: flex; - justify-content: center; -} -.rect{ - width: 100px; - height: 100px; - background-color: red; - animation: down 3s infinite forwards; -} -@keyframes down{ - 0%{ - transform: matrix(1,0,0,1,0,0); - } - 10%{ - transform: matrix(1,0,0,1,0,200); - } - 60%{ - transform: matrix(2,1.5,1.5,2,0,700); - } - 100%{ - transform: matrix(1,0,0,1,0,0); - } -} -``` - -![zh-cn_image_0000001174756580](/images/application-dev/ui/figures/zh-cn_image_0000001174756580.gif) - - -## 整合transform属性 - -transform可以设置多个值并且多个值可同时设置,下面案例中展示同时设置缩放(scale),平移(translate),旋转(rotate)属性时的动画效果。 - -``` - -
-
-
-
-
-
-
-``` - -``` -/* xxx.css */ -.container{ - flex-direction:column; - background-color:#F1F3F5; - padding:50px; -} -.rect1{ - width: 100px; - height: 100px; - background:linear-gradient(#e77070,#ee0202); - animation: change1 3s infinite forwards; -} -.rect2{ - margin-top: 50px; - width: 100px; - height: 100px; - background:linear-gradient(#95a6e8, #2739de); - animation: change2 3s infinite forwards; -} -.rect3{ - margin-top: 50px; - width: 100px; - height: 100px; - background:linear-gradient(#142ee2, #8cb1e5); - animation: change3 3s infinite; -} -.rect4{ - align-self: center; - margin-left: 50px; - margin-top: 200px; - width: 100px; - height: 100px; - background:linear-gradient(#e2a8df, #9c67d4,#8245d9,#e251c3); - animation: change4 3s infinite; -} -.rect5{ - margin-top: 300px; - width: 100px; - height: 100px; - background:linear-gradient(#e7ded7, #486ccd, #94b4d2); - animation: change5 3s infinite; -} -/* change1 change2 对比 */ -@keyframes change1{ - 0%{ - transform: translate(0,0); transform: rotate(0deg) - } - 100%{ - transform: translate(0,500px); - transform: rotate(360deg) - } -} -/* change2 change3 对比属性顺序不同的动画效果 */ -@keyframes change2{ - 0%{ - transform:translate(0,0) rotate(0deg) ; - } - 100%{ - transform: translate(300px,0) rotate(360deg); - } -} -@keyframes change3{ - 0%{ - transform:rotate(0deg) translate(0,0); - } - 100%{ - transform:rotate(360deg) translate(300px,0); - } -} -/* 属性值不对应的情况 */ -@keyframes change4{ - 0%{ - transform: scale(0.5); - } - 100%{ - transform:scale(2) rotate(45deg); - } -} -/* 多属性的写法 */ -@keyframes change5{ - 0%{ - transform:scale(0) translate(0,0) rotate(0); - } - 100%{ - transform: scale(1.5) rotate(360deg) translate(200px,0); - } -} -``` - -![zh-cn_image_0000001220554911](/images/application-dev/ui/figures/zh-cn_image_0000001220554911.gif) - -> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** -> 1. 当设置多个transform时,后续的transform值会把前面的覆盖掉。若想同时使用多个动画样式可用复合写法,例:transform: scale(1) rotate(0) translate(0,0)。 -> -> 2. transform进行复合写法时,变化样式内多个样式值顺序的不同会呈现不一样的动画效果。 -> -> 3. transform属性设置的样式值要一一对应,若前后不对应,则该动画不生效。若设置多个样式值则只会呈现出已对应值的动画效果。 diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/05.\345\212\250\346\225\210\345\274\200\345\217\221\346\214\207\345\257\274/01.CSS\345\212\250\347\224\273/03.background-position\346\240\267\345\274\217\345\212\250\347\224\273.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/05.\345\212\250\346\225\210\345\274\200\345\217\221\346\214\207\345\257\274/01.CSS\345\212\250\347\224\273/03.background-position\346\240\267\345\274\217\345\212\250\347\224\273.md" deleted file mode 100644 index fe5b83f495fc82d4d2427c3b7bbb6919394a4696..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/05.\345\212\250\346\225\210\345\274\200\345\217\221\346\214\207\345\257\274/01.CSS\345\212\250\347\224\273/03.background-position\346\240\267\345\274\217\345\212\250\347\224\273.md" +++ /dev/null @@ -1,99 +0,0 @@ ---- -title: background-position样式动画 -permalink: /pages/01080202050103 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# background-position样式动画 - - - -通过改变background-position属性(第一个值为X轴的位置,第二个值为Y轴的位置)移动背景图片位置,若背景图位置超出组件则超出部分的背景图不显示。 - - -``` - -
-
-
-
-``` - - -``` -/* xxx.css */ -.container { - background-color:#F1F3F5; - display: flex; - flex-direction: column; - justify-content: center; - align-items: center; - width: 100%; -} -.content{ - width: 400px; - height: 400px; - background-image: url('common/images/bg-tv.jpg'); - background-size: 100%; - background-repeat: no-repeat; - animation: change 3s infinite; - border: 1px solid black; -} -.content1{ - margin-top:50px; - width: 400px; - height: 400px; - background-image: url('common/images/bg-tv.jpg'); - background-size: 50%; - background-repeat: no-repeat; - animation: change1 5s infinite; - border: 1px solid black; -} -/* 背景图片移动出组件 */ -@keyframes change{ - 0%{ - background-position:0px top; - } - 25%{ - background-position:400px top; - } - 50%{ - background-position:0px top; - } - 75%{ - background-position:0px bottom; - } - 100%{ - background-position:0px top; - } -} -/* 背景图片在组件内移动 */ -@keyframes change1{ - 0%{ - background-position:left top; - } - 25%{ - background-position:50% 50%; - } - 50%{ - background-position:right bottom; - } - 100%{ - background-position:left top;; - } -} -``` - - -![zh-cn_image_0000001217008255](/images/application-dev/ui/figures/zh-cn_image_0000001217008255.gif) - - -> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** -> background-position仅支持背景图片的移动,不支持背景颜色(background-color)。 diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/05.\345\212\250\346\225\210\345\274\200\345\217\221\346\214\207\345\257\274/02.JS\345\212\250\347\224\273/01.\347\273\204\344\273\266\345\212\250\347\224\273.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/05.\345\212\250\346\225\210\345\274\200\345\217\221\346\214\207\345\257\274/02.JS\345\212\250\347\224\273/01.\347\273\204\344\273\266\345\212\250\347\224\273.md" deleted file mode 100644 index 009e30de4f22696c0fc2dc65113e14b4989ee225..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/05.\345\212\250\346\225\210\345\274\200\345\217\221\346\214\207\345\257\274/02.JS\345\212\250\347\224\273/01.\347\273\204\344\273\266\345\212\250\347\224\273.md" +++ /dev/null @@ -1,464 +0,0 @@ ---- -title: 组件动画 -permalink: /pages/01080202050201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# 组件动画 - -在组件上创建和运行动画的快捷方式。具体用法请参考[通用方法](/pages/010c0201010104)。 - - -## 获取动画对象 - -通过调用animate方法获得animation对象,animation对象支持动画属性、动画方法和动画事件。 - -``` - -
-
-
-``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - justify-content: center; - align-items: center; - width: 100%; -} -.box{ - width: 200px; - height: 200px; - background-color: #ff0000; - margin-top: 30px; -} -``` - -``` -/* xxx.js */ -export default { - data: { - animation: '', - }, - onInit() { - }, - onShow() { - var options = { - duration: 1500, - }; - var frames = [ - { - width:200,height:200, - }, - { - width:300,height:300, - } - ]; - this.animation = this.$element('content').animate(frames, options); //获取动画对象 - }, - Show() { - this.animation.play(); - } -} -``` - -![zh-cn_image_0000001175235138](/images/application-dev/ui/figures/zh-cn_image_0000001175235138.gif) - -> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** ->- 使用animate方法时必须传入Keyframes和Options参数。 ->- 多次调用animate方法时,采用replace策略,即最后一次调用时传入的参数生效。 - - -## 设置动画参数 - -在获取动画对象后,通过设置参数Keyframes设置动画在组件上的样式。 - -``` - -
-
-
-``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - justify-content: center; - align-items: center; - width: 100%; -} -.box{ - width: 200px; - height: 200px; - background-color: #ff0000; - margin-top: 30px; -} -``` - -``` -/* xxx.js */ -export default { - data: { - animation: '', - keyframes:{}, - options:{} - }, - onInit() { - this.options = { - duration: 4000, - }; - this.keyframes = [ { transform: { translate: '-120px -0px', scale: 1, rotate: 0 }, transformOrigin: '100px 100px', offset: 0.0, width: 200, height: 200 }, { transform: { translate: '120px 0px', scale: 1.5, rotate: 90 }, transformOrigin: '100px 100px', offset: 1.0, width: 300, height: 300 } ]; - }, - Show() { - this.animation = this.$element('content').animate(this.keyframes, this.options); - this.animation.play(); - } -} -``` - -![zh-cn_image_0000001174916742](/images/application-dev/ui/figures/zh-cn_image_0000001174916742.gif) - -> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** -> - translate、scale和rtotate的先后顺序会影响动画效果。 -> -> - transformOrigin只对scale和rtotate起作用。 - -在获取动画对象后,通过设置参数Options来设置动画的属性。 - -``` - -
-
-
-``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - justify-content: center; - align-items: center; - width: 100%; -} -.box{ - width: 200px; - height: 200px; - background-color: #ff0000; - margin-top: 30px; -} -``` - -``` -/* xxx.js */ -export default { - data: { - animation: '', - }, - onInit() { - }, - onShow() { - var options = { - duration: 1500, - easing: 'ease-in', - delay: 5, - iterations: 2, - direction: 'normal', - }; - var frames = [ - { - transform: { - translate: '-150px -0px' - } - }, - { - transform: { - translate: '150px 0px' - } - } - ]; - this.animation = this.$element('content').animate(frames, options); - }, - Show() { - this.animation.play(); - } -} -``` - -![zh-cn_image_0000001220396499](/images/application-dev/ui/figures/zh-cn_image_0000001220396499.gif) - -> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** -> direction:指定动画的播放模式。 -> -> normal: 动画正向循环播放。 -> -> reverse: 动画反向循环播放。 -> -> alternate:动画交替循环播放,奇数次正向播放,偶数次反向播放。 -> -> alternate-reverse:动画反向交替循环播放,奇数次反向播放,偶数次正向播放。 - - -## 添加事件和调用方法 - -animation对象支持动画事件和动画方法。可以通过添加开始和取消事件,调用播放、暂停、倒放和结束方法实现预期动画。 - -``` - -
-
-
-
- - -
-
- - -
-
-``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - align-items: center; - justify-content: center; -} -button{ - width: 200px; -} -.row{ - width: 65%; - height: 100px; - align-items: center; - justify-content: space-between; - margin-top: 40px; - position: fixed; - top: 65%; - left: 120px; -} -.row1{ - width: 65%; - height: 100px; - align-items: center; - justify-content: space-between; - margin-top: 30px; - position: fixed; - top: 75%; - left: 120px; -} -``` - -``` -/* xxx.js */ -import prompt from '@system.prompt'; -export default { - data: { - animation: '', - }, - onInit() { - }, - onShow() { - var options = { - duration: 1500, - easing:'ease-in', - elay:5, - direction:'normal', - iterations:2 - }; - var frames = [ - { - transform: { - translate: '-150px -0px' - }, - opacity: 0.1, - offset: 0.0, - width: 200, - height: 200, - }, - { - transform: { - translate: '150px 0px' - }, - opacity: 1.0, - offset: 1.0, - width: 300, - height: 300, - } - ]; - this.animation = this.$element('content').animate(frames, options); - this.animation.onstart = function(){ - prompt.showToast({ - message: "start" - }); - }; //添加开始事件 - this.animation.onrepeat = function(){ - prompt.showToast({ - message: " repeated" - }); - };//添加重播事件 - this.animation.oncancel = function(){ - prompt.showToast({ - message: "canceled" - }); - };//添加取消事件 - this.animation.onfinish = function(){ - prompt.showToast({ - message: "finish" - }); - };//添加完成事件 - }, - playAnimation() { - this.animation.play();//调用播放开始的方法 - }, - pauseAnimation() { - this.animation.pause();//调用播放暂停的方法 - }, - reverseAnimation() { - this.animation.reverse();//调用播放倒放的方法 - }, - cancelAnimation() { - this.animation.cancel();//调用播放取消的方法 - } -} -``` - -![zh-cn_image_0000001220635011](/images/application-dev/ui/figures/zh-cn_image_0000001220635011.gif) - -通过改变playStat的属性实现动画状态的改变。 - -``` - -
-
-
-
- -
-
- -
-
-``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - align-items: center; - justify-content: center; -} -button{ - width: 200px; -} -.row{ - width: 65%; - height: 100px; - align-items: center; - justify-content: space-between; - margin-top: 50px; - margin-left: 260px; - position: fixed; - top: 65%; -} -.row1{ - width: 65%; - height: 100px; - align-items: center; - justify-content: space-between; - margin-top: 50px; - margin-left: 260px; - position: fixed; - top: 75%; -} -``` - -``` -/* xxx.js */ -import prompt from '@system.prompt'; -export default { - data: { - animation: '', - state:'play', - state1:'play' - }, - onInit() { - }, - onShow() { - var options = { - duration: 1500, - easing:'ease-in', - elay:5, - direction:'normal', - iterations:2, - }; - var frames = [ - { - transform: { - translate: '-150px -0px' - }, - opacity: 0.1, - offset: 0.0, - width: 200, - height: 200, - }, - { - transform: { - translate: '150px 0px' - }, - opacity: 1.0, - offset: 1.0, - width: 300, - height: 300, - } - ]; - this.animation = this.$element('content').animate(frames, options); - this.animation.onstart = function(){ - prompt.showToast({ - message: "start" - }); - }; - this.animation.onrepeat = function(){ - prompt.showToast({ - message: " repeated" - }); - }; - this.animation.onfinish = function(){ - prompt.showToast({ - message: " finished" - }); - }; - }, - playStateClick(){ - if(this.animation.playState != 'running'){ - this.animation.playState = 'running';//设置playState为running,动画运行。 - this.state = 'pause' - }else{ - this.animation.playState = 'paused';//设置playState为paused,动画暂停。 - this.state = 'play' - } - }, - playStateClick1(){ - if(this.animation.playState != 'running'){ - this.animation.playState = 'running'; - this.state1 = 'finish' - }else{ - this.animation.playState = 'finished';//设置playState为finished,动画结束。 - this.state1 = 'play' - } - } -} -``` - -![zh-cn_image_0000001175075286](/images/application-dev/ui/figures/zh-cn_image_0000001175075286.gif) diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/05.\345\212\250\346\225\210\345\274\200\345\217\221\346\214\207\345\257\274/02.JS\345\212\250\347\224\273/02.\346\217\222\345\200\274\345\231\250\345\212\250\347\224\273/01.\345\212\250\347\224\273\345\212\250\346\225\210.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/05.\345\212\250\346\225\210\345\274\200\345\217\221\346\214\207\345\257\274/02.JS\345\212\250\347\224\273/02.\346\217\222\345\200\274\345\231\250\345\212\250\347\224\273/01.\345\212\250\347\224\273\345\212\250\346\225\210.md" deleted file mode 100644 index e0eb2b7a8b8d68c23a98f807f6a7ba1e266e0d43..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/05.\345\212\250\346\225\210\345\274\200\345\217\221\346\214\207\345\257\274/02.JS\345\212\250\347\224\273/02.\346\217\222\345\200\274\345\231\250\345\212\250\347\224\273/01.\345\212\250\347\224\273\345\212\250\346\225\210.md" +++ /dev/null @@ -1,254 +0,0 @@ ---- -title: 动画动效 -permalink: /pages/0108020205020201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# 动画动效 - - -通过设置插值器来实现动画效果。具体用法请参考[动画](/pages/010c010b08)。 - -> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** -> 从API Version 6 开始支持。 - - -## 创建动画对象 - -通过createAnimator创建一个动画对象,通过设置参数options来设置动画的属性。 - -``` - -
-
-
-
- -
-
-``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - align-items: center; - justify-content: center; -} -button{ - width: 200px; -} -.row{ - width: 65%; - height: 100px; - align-items: center; - justify-content: space-between; - margin-top: 50px; - margin-left: 260px; -} -``` - -``` -/* xxx.js */ -import animator from '@ohos.animator'; -export default { - data: { - translateVal: 0, - animation: null - }, - onInit() {}, - onShow(){ - var options = { - duration: 3000, - easing:"friction", - delay:"1000", - fill: 'forwards', - direction:'alternate', - iterations: 2, - begin: 0, - end: 180 - };//设置参数 - this.animation = animator.createAnimator(options)//创建动画 - }, - playAnimation() { - var _this = this; - this.animation.onframe = function(value) { - _this.translateVal= value - }; - this.animation.play(); - } -} -``` - -![zh-cn_image_0000001174756776](/images/application-dev/ui/figures/zh-cn_image_0000001174756776.gif) - -> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** -> - 使用createAnimator创建动画对象时必须传入options参数。 -> -> - begin插值起点,不设置时默认为0。 -> -> - end插值终点,不设置时默认为1。 - - -## 添加动画事件和调用接口 - -animator支持事件和接口,可以通过添加frame、cancel、repeat、finish事件和调用update、play、pause、cancel、reverse、finish接口自定义动画效果。animator支持的事件和接口具体见[动画中的createAnimator](/pages/010c010b08)。 - -``` - -
-
-
-
-
- - -
-
- - -
-
- - -
-
-``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - align-items: center; - justify-content: center; -} -button{ - width: 200px; -} -.row{ - width: 65%; - height: 100px; - align-items: center; - justify-content: space-between; - margin-top: 150px; - position: fixed; - top: 55%; - left: 120px; -} -.row1{ - width: 65%; - height: 100px; - align-items: center; - justify-content: space-between; - margin-top: 120px; - position: fixed; - top: 65%; - left: 120px; -} -.row2{ - width: 65%; - height: 100px; - align-items: center; - justify-content: space-between; - margin-top: 100px; - position: fixed; - top: 75%; - left: 120px; -} -``` - -``` -/* xxx.js */ -import animator from '@ohos.animator'; -import prompt from '@system.prompt'; -export default { - data: { - scaleVal:1, - DivWidth:200, - DivHeight:200, - translateVal:0, - animation: null - }, - onInit() { - var options = { - duration: 3000, - fill: 'forwards', - begin: 200, - end: 270 - }; - this.animation = animator.createAnimator(options); - }, - onShow() { - var _this= this; - //添加动画重放事件 - this.animation.onrepeat = function() { - prompt.showToast({ - message: 'repeat' - }); - var repeatoptions = { - duration: 2000, - iterations: 1, - direction: 'alternate', - begin: 180, - end: 240 - }; - _this.animation.update(repeatoptions); - _this.animation.play(); - }; - }, - playAnimation() { - var _this= this; - //添加动画逐帧插值回调事件 - this.animation.onframe = function(value) { - _this. scaleVal= value/150, - _this.DivWidth = value, - _this.DivHeight = value, - _this.translateVal = value-180 - }; - this.animation.play(); - }, - updateAnimation() { - var newoptions = { - duration: 5000, - iterations: 2, - begin: 120, - end: 180 - }; - this.animation.update(newoptions); - this.animation.play();//调用动画播放接口 - }, - pauseAnimation() { - this.animation.pause();//调用动画暂停接口 - }, - finishAnimation() { - var _this= this; - //添加动画完成事件 - this.animation.onfinish = function() { - prompt.showToast({ - message: 'finish' - }) - }; - this.animation.finish(); //调用动画完成接口 - }, - cancelAnimation() { - this.animation.cancel(); //调用动画取消接口 - }, - reverseAnimation() { - this.animation.reverse(); //调用动画倒放接口 - } -} -``` - -![zh-cn_image_0000001220635059](/images/application-dev/ui/figures/zh-cn_image_0000001220635059.gif) - -> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** -> 在调用update接口的过程中可以使用这个接口更新动画参数,入参与createAnimator一致。 diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/05.\345\212\250\346\225\210\345\274\200\345\217\221\346\214\207\345\257\274/02.JS\345\212\250\347\224\273/02.\346\217\222\345\200\274\345\231\250\345\212\250\347\224\273/02.\345\212\250\347\224\273\345\270\247.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/05.\345\212\250\346\225\210\345\274\200\345\217\221\346\214\207\345\257\274/02.JS\345\212\250\347\224\273/02.\346\217\222\345\200\274\345\231\250\345\212\250\347\224\273/02.\345\212\250\347\224\273\345\270\247.md" deleted file mode 100644 index 0234bc815ad2b23ee4e3656d613933f8b4498f43..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/05.\345\212\250\346\225\210\345\274\200\345\217\221\346\214\207\345\257\274/02.JS\345\212\250\347\224\273/02.\346\217\222\345\200\274\345\231\250\345\212\250\347\224\273/02.\345\212\250\347\224\273\345\270\247.md" +++ /dev/null @@ -1,201 +0,0 @@ ---- -title: 动画帧 -permalink: /pages/0108020205020202 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# 动画帧 - -## 请求动画帧 - -请求动画帧时通过requestAnimationFrame函数逐帧回调,在调用该函数时传入一个回调函数。 - -runframe在调用requestAnimationFrame时传入带有timestamp参数的回调函数step,将step中的timestamp赋予起始的startTime。当timestamp与startTime的差值小于规定的时间时将再次调用requestAnimationFrame,最终动画将会停止。 - -``` - -
- - -
- - - -
-
-
- -
-
-
-
-``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - justify-content: center; - align-items: center; - width: 100%; - height: 100%; -} -button{ - width: 300px; -} -``` - -``` -/* xxx.js */ -export default { - data: { - timer: null, - left: 0, - top: 0, - flag: true, - animation: null, - startTime: 0, - }, - onShow() { - var test = this.$element("mycanvas"); - var ctx = test.getContext("2d"); - ctx.beginPath(); - ctx.moveTo(0, 0); - ctx.lineTo(300, 300); - ctx.lineWidth = 5; - ctx.strokeStyle = "red"; - ctx.stroke(); - }, - runframe() { - this.left = 0; - this.top = 0; - this.flag = true; - this.animation = requestAnimationFrame(this.step); - }, - step(timestamp) { - if (this.flag) { - this.left += 5; - this.top += 5; - if (this.startTime == 0) { - this.startTime = timestamp; - } - var elapsed = timestamp - this.startTime; - if (elapsed < 500) { - console.log('callback step timestamp: ' + timestamp); - this.animation = requestAnimationFrame(this.step); - } - } else { - this.left -= 5; - this.top -= 5; - this.animation = requestAnimationFrame(this.step); - } - if (this.left == 250 || this.left == 0) { - this.flag = !this.flag - } - }, - onDestroy() { - cancelAnimationFrame(this.animation); - } -} -``` - -![zh-cn_image_0000001174756860](/images/application-dev/ui/figures/zh-cn_image_0000001174756860.gif) - -> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** -> requestAnimationFrame函数在调用回调函数时在第一个参数位置传入timestamp时间戳,表示requestAnimationFrame开始去执行回调函数的时刻。 - - -## 取消动画帧 - -通过cancelAnimationFrame函数取消逐帧回调,在调用cancelAnimationFrame函数时取消requestAnimationFrame函数的请求。 - -``` - -
- - -
- - - -
-
-
- -
-
-
-
-``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - justify-content: center; - align-items: center; - width: 100%; - height: 100%; -} -button{ - width: 300px; -} -``` - -``` -/* xxx.js */ -export default { - data: { - timer: null, - left: 0, - top: 0, - flag: true, - animation: null - }, - onShow() { - var test = this.$element("mycanvas"); - var ctx = test.getContext("2d"); - ctx.beginPath(); - ctx.moveTo(0, 0); - ctx.lineTo(300, 300); - ctx.lineWidth = 5; - ctx.strokeStyle = "red"; - ctx.stroke(); - }, - runframe() { - this.left = 0; - this.top = 0; - this.flag = true; - this.animation = requestAnimationFrame(this.step); - }, - step(timestamp) { - if (this.flag) { - this.left += 5; - this.top += 5; - this.animation = requestAnimationFrame(this.step); - } else { - this.left -= 5; - this.top -= 5; - this.animation = requestAnimationFrame(this.step); - } - if (this.left == 250 || this.left == 0) { - this.flag = !this.flag - } - }, - onDestroy() { - cancelAnimationFrame(this.animation); - } -} -``` - -![zh-cn_image_0000001220316655](/images/application-dev/ui/figures/zh-cn_image_0000001220316655.gif) - -> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** -> 在调用该函数时需传入一个具有标识id的参数。 diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/06.\350\207\252\345\256\232\344\271\211\347\273\204\344\273\266.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/06.\350\207\252\345\256\232\344\271\211\347\273\204\344\273\266.md" deleted file mode 100644 index caa9e8db20b8c005d2ca33fe60e738fd356200ac..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/02.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/06.\350\207\252\345\256\232\344\271\211\347\273\204\344\273\266.md" +++ /dev/null @@ -1,112 +0,0 @@ ---- -title: 自定义组件 -permalink: /pages/0108020206 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# 自定义组件 - -使用基于JS扩展的类Web开发范式的方舟开发框架支持自定义组件,用户可根据业务需求将已有的组件进行扩展,增加自定义的私有属性和事件,封装成新的组件,方便在工程中多次调用,提高页面布局代码的可读性。具体的封装方法示例如下: - - -- **构建自定义组件** - ``` - -
- {{title}} - 点击这里查看隐藏文本 - hello world -
- ``` - - ``` - /* comp.css */ - .item { - width: 700px; - flex-direction: column; - height: 300px; - align-items: center; - margin-top: 100px; - } - .text-style { - width: 100%; - text-align: center; - font-weight: 500; - font-family: Courier; - font-size: 36px; - } - .title-style { - font-weight: 500; - font-family: Courier; - font-size: 50px; - color: #483d8b; - } - ``` - - ``` - // comp.js - export default { - props: { - title: { - default: 'title', - }, - showObject: {}, - }, - data() { - return { - showObj: this.showObject, - }; - }, - childClicked () { - this.$emit('eventType1', {text: '收到子组件参数'}); - this.showObj = !this.showObj; - }, - } - ``` - -- **引入自定义组件** - ``` - - -
- 父组件:{{text}} - -
- ``` - - ``` - /* xxx.css */ - .container { - background-color: #f8f8ff; - flex: 1; - flex-direction: column; - align-content: center; - } - ``` - - ``` - // xxx.js - export default { - data: { - text: '开始', - isShow: false, - }, - textClicked (e) { - this.text = e.detail.text; - }, - } - ``` - - -本示例中父组件通过添加自定义属性向子组件传递了名称为title的参数,子组件在props中接收。同时子组件也通过事件绑定向上传递了参数text,接收时通过e.detail获取。要绑定子组件事件,父组件事件命名必须遵循事件绑定规则,详见[自定义组件开发规范](/pages/010c02010201)。自定义组件效果如下图所示: - - -**图1** 自定义组件的效果 -![zh-cn_image_0000001070693737](/images/application-dev/ui/figures/zh-cn_image_0000001070693737.png) diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\346\246\202\350\277\260.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\346\246\202\350\277\260.md" deleted file mode 100644 index 702d7f99d93fa13e32c43f26801405be19d97fb0..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\346\246\202\350\277\260.md" +++ /dev/null @@ -1,59 +0,0 @@ ---- -title: 概述 -permalink: /pages/0108020301 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# 概述 - -基于TS扩展的声明式开发范式的方舟开发框架是为OpenHarmony平台开发极简、高性能、跨设备应用设计研发的UI开发框架,支持开发者高效的构建跨设备应用UI界面。 - - -## 基础能力 - -使用基于TS扩展的声明式开发范式的方舟开发框架,采用更接近自然语义的编程方式,让开发者可以直观地描述UI界面,不必关心框架如何实现UI绘制和渲染,实现极简高效开发。从组件、动效和状态管理三个维度来提供UI能力,还提供了系统能力接口,实现系统能力的极简调用。 - - -- **开箱即用的组件** - 框架提供丰富的系统预置组件,可以通过链式调用的方式设置系统组件的渲染效果。开发者可以组合系统组件为自定义组件,通过这种方式将页面组件化为一个个独立的UI单元,实现页面不同单元的独立创建、开发和复用,使页面具有更强的工程性。 - - -- **丰富的动效接口** - 提供svg标准的绘制图形能力,同时开放了丰富的动效接口,开发者可以通过封装的物理模型或者调用动画能力接口来实现自定义动画轨迹。 - - -- **状态与数据管理** - 状态数据管理作为基于TS扩展的声明式开发范式的特色,通过功能不同的装饰器给开发者提供了清晰的页面更新渲染流程和管道。状态管理包括UI组件状态和应用程序状态,两者协作可以使开发者完整地构建整个应用的数据更新和UI渲染。 - - -- **系统能力接口** - 使用基于TS扩展的声明式开发范式的方舟开发框架,还封装了丰富的系统能力接口,开发者可以通过简单的接口调用,实现从UI设计到系统能力调用的极简开发。 - - -## 整体架构 - - - -![zh-cn_image_0000001169532276](/images/application-dev/ui/figures/zh-cn_image_0000001169532276.png) - -- **声明式UI前端** - 提供了UI开发范式的基础语言规范,并提供内置的UI组件、布局和动画,提供了多种状态管理机制,为应用开发者提供一系列接口支持。 - -- **语言运行时** - 选用方舟语言运行时,提供了针对UI范式语法的解析能力,提供了跨语言调用支持,提供了TS语言高性能运行环境。 - -- **声明式UI后端引擎** - 后端引擎提供了兼容不同开发范式的UI渲染管线,提供多种基础组件、布局计算、动效、交互事件,提供了状态管理和绘制能力。 - -- **渲染引擎** - 提供了高效的绘制能力,将渲染管线收集的渲染指令,绘制到屏幕能力。 - -- **平台适配层** - 提供了对系统平台的抽象接口,具备接入不同系统的能力,如系统渲染管线、生命周期调度等。 diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/01.\346\226\207\344\273\266\347\273\204\347\273\207/01.\347\233\256\345\275\225\347\273\223\346\236\204.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/01.\346\226\207\344\273\266\347\273\204\347\273\207/01.\347\233\256\345\275\225\347\273\223\346\236\204.md" deleted file mode 100644 index ab1dbc17a019b217df6dd873c980104c197acc45..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/01.\346\226\207\344\273\266\347\273\204\347\273\207/01.\347\233\256\345\275\225\347\273\223\346\236\204.md" +++ /dev/null @@ -1,42 +0,0 @@ ---- -title: 目录结构 -permalink: /pages/01080203020101 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# 目录结构 - - - -FA应用的eTS模块(entry/src/main)的典型开发目录结构如下: - - -![zh-cn_image_0000001182200571](/images/application-dev/ui/figures/zh-cn_image_0000001182200571.png) - - -**目录结构中文件分类如下:** - - -- .ets结尾的eTS(extended TypeScript)文件,这个文件用于描述UI布局、样式、事件交互和页面逻辑。 - - -**各个文件夹和文件的作用:** - - -- **app.ets**文件用于全局应用逻辑和应用生命周期管理。 - -- **pages**目录用于存放所有组件页面。 - -- **common**目录用于存放公共代码文件,比如:自定义组件和公共方法。 - - -> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** -> -> - 页面支持导入TypeScript和JavaScript文件。 diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/01.\346\226\207\344\273\266\347\273\204\347\273\207/02.\345\272\224\347\224\250\344\273\243\347\240\201\346\226\207\344\273\266\350\256\277\351\227\256\350\247\204\345\210\231.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/01.\346\226\207\344\273\266\347\273\204\347\273\207/02.\345\272\224\347\224\250\344\273\243\347\240\201\346\226\207\344\273\266\350\256\277\351\227\256\350\247\204\345\210\231.md" deleted file mode 100644 index cb06aff70f3af537fc80bfd081609c8e9a5158e4..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/01.\346\226\207\344\273\266\347\273\204\347\273\207/02.\345\272\224\347\224\250\344\273\243\347\240\201\346\226\207\344\273\266\350\256\277\351\227\256\350\247\204\345\210\231.md" +++ /dev/null @@ -1,83 +0,0 @@ ---- -title: 应用代码文件访问规则 -permalink: /pages/01080203020102 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# 应用代码文件访问规则 - -应用代码文件可通过如下方式访问: - - -- 使用相对路径引用代码文件,比如:上一级目录:../common/utils/utils.ets,当前目录:./common/utils/utils.ets。 - -- 使用当前模块根路径引用代码文件,比如:common/utils/utils.ets。 - -- 公共代码文件推荐放在**common**目录下。 - - -## 示例 - -``` -import { FoodData, FoodList } from "../common/utils/utils.ets"; - -@Entry -@Component -struct FoodCategoryList { - private foodItems: FoodData[] = [ - new FoodData("Tomato"), - new FoodData("Strawberry"), - new FoodData("Cucumber") - ] - build() { - Column() { - FoodList({ foodItems: this.foodItems }) - } - } -} -``` - -导入文件示例: - -``` -//common/utils/utils.ets - -export class FoodData { - name: string; - constructor(name: string) { - this.name = name; - } -} - -@Component -export struct FoodList { - private foodItems: FoodData[] - - build() { - Column() { - Flex({justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center}) { - Text('Food List') - .fontSize(20) - } - .width(200) - .height(56) - .backgroundColor('#FFf1f3f5') - List() { - ForEach(this.foodItems, item => { - ListItem() { - Text(item.name) - .fontSize(14) - } - }, item => item.toString()) - } - } - } -} -``` diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/02.js\346\240\207\347\255\276\351\205\215\347\275\256.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/02.js\346\240\207\347\255\276\351\205\215\347\275\256.md" deleted file mode 100644 index 74c27785dd92baa59a55dd920c43441b0fed7f9d..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/02.js\346\240\207\347\255\276\351\205\215\347\275\256.md" +++ /dev/null @@ -1,114 +0,0 @@ ---- -title: js标签配置 -permalink: /pages/010802030202 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# js标签配置 - -开发框架需要应用的config.json中配置相关的js标签,其中包含了实例名称、页面路由、视图窗口配置信息。 - - -| 标签 | 类型 | 默认值 | 必填 | 描述 | -| -------- | -------- | -------- | -------- | -------- | -| name | string | default | 是 | 标识ETS实例的名字。 | -| pages | Array | - | 是 | 页面路由信息,详见[pages](#pages)说明。 | -| window | Object | - | 否 | 视图窗口配置信息,详见[window](#window)说明。 | -| mode | Object | - | 否 | 配置Js Component运行类型与语法风格,详见[mode](#mode)说明。 | - - -## pages - -定义每个页面入口组件的路由信息,每个页面由页面路径和页面名组成,页面的文件名就是页面名。比如: - -``` -{ - "pages": [ - "pages/index", - "pages/detail" - ] -} -``` - -> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** -> - pages列表中第一个页面为应用的首页入口。 -> -> - 页面文件名不能使用组件名称,比如:Text.ets、Button.ets等。 -> -> - 每个页面文件中必须包含[页面入口组件](/pages/0108020303020302)(\@Entry装饰)。 - - -## window - -window用于配置相关视图显示窗口,支持配置如下属性: - -| 类型 | 默认值 | 说明 | -| -------- | -------- | -------- | -| designWidth | - | 配置视图显示的逻辑宽度,缺省默认720(智能穿戴默认454)。视图显示的逻辑宽度决定了lpx像素单位大小,如designWidth配置720时,在视图宽度为1440物理像素时,1lpx为2物理像素。详见[lpx像素单位](/pages/010802030204)说明。 | - -``` -{ - ... - "window": { - "designWidth": 720 - } - ... -} -``` - - -## mode - -mode用于配置JS Component的运行类型与语法风格,支持如下属性: - -| 类型 | 默认值 | 说明 | -| -------- | -------- | -------- | -| type | - | 配置该JS Component的运行类型,可选值为:
- pageAbility:以ability的方式运行该JS Component。
- form:以卡片的方式运行该JS Component。 | -| syntax | - | 配置该JS Component的语法风格,可选值为:
- hml:以hml/css/js风格进行编写。
- ets:以声明式语法风格进行编写。 | - -> ![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** -> 不支持同时配置type类型为form,syntax类型为ets。 - - -## 示例 - -config.json: - -``` -{ - "app": { - "bundleName": "com.example.player", - "version": { - "code": 1, - "name": "1.0" - }, - "vendor": "example" - }, - "module": { - "js": [{ - "name": "default", - "pages": [ - "pages/index", - "pages/detail" - ], - "window": { - "designWidth": 720 - }, - "mode": { - "type": "pageAbility", - "syntax": "ets" - }, - }], - "abilities": [{ - ... - }] - } -} -``` diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/03.\350\265\204\346\272\220\350\256\277\351\227\256/01.\345\252\222\344\275\223\350\265\204\346\272\220\347\261\273\345\236\213\350\257\264\346\230\216.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/03.\350\265\204\346\272\220\350\256\277\351\227\256/01.\345\252\222\344\275\223\350\265\204\346\272\220\347\261\273\345\236\213\350\257\264\346\230\216.md" deleted file mode 100644 index ea521b9254a2884a1148980c2a33c15cc9f1d270..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/03.\350\265\204\346\272\220\350\256\277\351\227\256/01.\345\252\222\344\275\223\350\265\204\346\272\220\347\261\273\345\236\213\350\257\264\346\230\216.md" +++ /dev/null @@ -1,26 +0,0 @@ ---- -title: 媒体资源类型说明 -permalink: /pages/01080203020301 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# 媒体资源类型说明 - - - -- 开发框架支持的图片资源类型说明 - | 格式 | 文件后缀名 | - | -------- | -------- | - | JPEG | .jpg | - | PNG | .png | - | GIF | .gif | - | SVG | .svg | - | WEBP | .webp | - | BMP | .bmp | diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/04.\345\203\217\347\264\240\345\215\225\344\275\215.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/04.\345\203\217\347\264\240\345\215\225\344\275\215.md" deleted file mode 100644 index f3a930775513392e9d159742e1516ac4a34f1d32..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/04.\345\203\217\347\264\240\345\215\225\344\275\215.md" +++ /dev/null @@ -1,86 +0,0 @@ ---- -title: 像素单位 -permalink: /pages/010802030204 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# 像素单位 - -为开发者提供4种像素单位,框架采用vp为基准数据单位。 - - -| 名称 | 描述 | -| -------- | -------- | -| px | 屏幕物理像素单位。 | -| vp | 屏幕密度相关像素,根据屏幕像素密度转换为屏幕物理像素。 | -| fp | 字体像素,与vp类似适用屏幕密度变化,随系统字体大小设置变化。 | -| lpx | 视窗逻辑像素单位,lpx单位为实际屏幕宽度与逻辑宽度(通过[designWidth](/pages/010802030202)配置)的比值。如配置designWidth为720时,在实际宽度为1440物理像素的屏幕上,1lpx为2px大小。 | - - -## 像素单位转换 - -提供其他单位与px单位互相转换的方法。 - -| 接口 | 描述 | -| -------- | -------- | -| vp2px(value : number) : number | 将vp单位的数值转换为以px为单位的数值。 | -| px2vp(value : number) : number | 将px单位的数值转换为以vp为单位的数值。 | -| fp2px(value : number) : number | 将fp单位的数值转换为以px为单位的数值。 | -| px2fp(value : number) : number | 将px单位的数值转换为以fp为单位的数值。 | -| lpx2px(value : number) : number | 将lpx单位的数值转换为以px为单位的数值。 | -| px2lpx(value : number) : number | 将px单位的数值转换为以lpx为单位的数值。 | - - -## 示例 - -``` -@Entry -@Component -struct Example { - build() { - Column() { - Flex({ wrap: FlexWrap.Wrap }) { - Column() { - Text("width(220)") - .width(220).height(40).backgroundColor(0xF9CF93) - .textAlign(TextAlign.Center).fontColor(Color.White).fontSize('12vp') - }.margin(5) - Column() { - Text("width('220px')") - .width('220px').height(40).backgroundColor(0xF9CF93) - .textAlign(TextAlign.Center).fontColor(Color.White) - }.margin(5) - Column() { - Text("width('220vp')") - .width('220vp').height(40).backgroundColor(0xF9CF93) - .textAlign(TextAlign.Center).fontColor(Color.White).fontSize('12vp') - }.margin(5) - Column() { - Text("width('220lpx') designWidth:720") - .width('220lpx').height(40).backgroundColor(0xF9CF93) - .textAlign(TextAlign.Center).fontColor(Color.White).fontSize('12vp') - }.margin(5) - Column() { - Text("width(vp2px(220) + 'px')") - .width(vp2px(220) + 'px').height(40).backgroundColor(0xF9CF93) - .textAlign(TextAlign.Center).fontColor(Color.White).fontSize('12vp') - }.margin(5) - Column() { - Text("fontSize('12fp')") - .width(220).height(40).backgroundColor(0xF9CF93) - .textAlign(TextAlign.Center).fontColor(Color.White).fontSize('12fp') - }.margin(5) - }.width('100%') - } - } -} -``` - -![zh-cn_image_0000001169582302](/images/application-dev/ui/figures/zh-cn_image_0000001169582302.gif) diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/05.\347\261\273\345\236\213\345\256\232\344\271\211.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/05.\347\261\273\345\236\213\345\256\232\344\271\211.md" deleted file mode 100644 index 036ff77e7312e0b3e7b3607edeea56c7eb096b4c..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\346\241\206\346\236\266\350\257\264\346\230\216/05.\347\261\273\345\236\213\345\256\232\344\271\211.md" +++ /dev/null @@ -1,151 +0,0 @@ ---- -title: 类型定义 -permalink: /pages/010802030205 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# 类型定义 - -## 长度类型 - -| 名称 | 类型定义 | 描述 | -| -------- | -------- | -------- | -| Length | string \| number | 用于描述尺寸单位,输入为number类型时,使用vp单位;输入为string类型时,需要显式指定像素单位,如'10px',也可设置百分比字符串,如'100%'。 | - - -## 角度类型 - -| 名称 | 类型定义 | 描述 | -| -------- | -------- | -------- | -| Angle | string \| number | 用于角度单位,输入为number类型时,使用deg单位;输入为string类型时需要显示指定角度单位,支持以下两种角度单位:
- deg:如'100deg'。
- rad:如'3.14rad'。 | - - -## 点类型 - -| 名称 | 类型定义 | 描述 | -| -------- | -------- | -------- | -| Point | [Length, Length] | 用于描述点坐标,第一个值为x轴坐标,第二个值为y坐标。 | - - -## 颜色类型 - -组件属性方法使用的颜色Color说明如下: - -| 名称 | 类型定义 | 描述 | -| -------- | -------- | -------- | -| Color | string \| number \| Color | 用于描述颜色信息,输入为string类型时,使用rgb或者rgba进行描述;输入为number类型是,使用HEX格式颜色;输入类型为Color枚举时,使用颜色枚举值。
- 'rgb(255, 255, 255)'。
- 'rgba(255, 255, 255, 1.0)'。
- HEX格式:0xrrggbb,0xaarrggbb,'\#FFFFFF'。
- 枚举格式:Color.Black,Color.White等。 | - - -当前支持的Color颜色枚举: - - -| 颜色名称 | 颜色值 | 颜色示意 | -| -------- | -------- | -------- | -| Black | 0x000000 | ![zh-cn_image_0000001111680230](/images/application-dev/ui/figures/zh-cn_image_0000001111680230.png) | -| Blue | 0x0000ff | ![zh-cn_image_0000001158240091](/images/application-dev/ui/figures/zh-cn_image_0000001158240091.png) | -| Brown | 0xa52a2a | ![zh-cn_image_0000001158360079](/images/application-dev/ui/figures/zh-cn_image_0000001158360079.png) | -| Gray | 0x808080 | ![zh-cn_image_0000001111840132](/images/application-dev/ui/figures/zh-cn_image_0000001111840132.png) | -| Green | 0x008000 | ![zh-cn_image_0000001111680236](/images/application-dev/ui/figures/zh-cn_image_0000001111680236.png) | -| Orange | 0xffa500 | ![zh-cn_image_0000001158240095](/images/application-dev/ui/figures/zh-cn_image_0000001158240095.png) | -| Pink | 0xffc0cb | ![zh-cn_image_0000001158360085](/images/application-dev/ui/figures/zh-cn_image_0000001158360085.png) | -| Red | 0xff0000 | ![zh-cn_image_0000001111840136](/images/application-dev/ui/figures/zh-cn_image_0000001111840136.png) | -| White | 0xffffff | ![zh-cn_image_0000001111680240](/images/application-dev/ui/figures/zh-cn_image_0000001111680240.png) | -| Yellow | 0xffff00 | ![zh-cn_image_0000001158240097](/images/application-dev/ui/figures/zh-cn_image_0000001158240097.png) | - - -## ColorStop类型 - -颜色断点类型,用于描述渐进色颜色断点。 - -| 名称 | 类型定义 | 描述 | -| -------- | -------- | -------- | -| ColorStop | [Color, number] | 描述渐进色颜色断点类型,第一个参数为颜色值,第二个参数为0~1之间的比例值。 | - - -## ResourceStr类型 - -| 名称 | 类型定义 | 描述 | -| -------- | -------- | -------- | -| ResourceStr | string \| Resource | 用于描述资源字符串的类型。 | - - -## ResourceColor类型 - -| 名称 | 类型定义 | 描述 | -| -------- | -------- | -------- | -| ResourceColor | Color \| number \| string \| Resource | 用于描述资源颜色类型。 | - - -## Font类型 - -| 名称 | 类型定义 | 描述 | -| -------- | -------- | -------- | -| Font | {
size?: Length;
weight?: FontWeight  \| number  \| string;
family?: string  \| Resource;
style?: FontStyle;
} | 设置文本样式:
  • size: 设置文本尺寸,Length为number类型时,使用fp单位。
  • weight: 设置文本的字体粗细,number类型取值[100, 900],取值间隔为100,默认为400,取值越大,字体越粗。
  • family: 设置文本的字体列表。使用多个字体,使用','进行分割,优先级按顺序生效。例如:'Arial, sans-serif'。
  • style: 设置文本的字体样式。
| - - -## 示例 - -``` -@Entry -@Component -struct dataTypeExample { - build() { - Column({ space: 5 }) { - Text('Length').fontColor(0xCCCCCC).fontSize(9).width('90%') - Text('90%').width('90%').height(40).backgroundColor(0xF9CF93) - .textAlign(TextAlign.Center).fontColor(Color.White) - Text('320').width(320).height(40).backgroundColor(0xF9CF93) - .textAlign(TextAlign.Center).fontColor(Color.White) - Text('1000px').width('1000px').height(40).backgroundColor(0xF9CF93) - .textAlign(TextAlign.Center).fontColor(Color.White) - - Text('Angle').fontColor(0xCCCCCC).fontSize(9).width('90%') - Text('45deg') - .width(40).height(40) - .rotate({ x: 0, y: 0, z: 1, angle: 45, centerX: '50%', centerY: '50%' }) - .fontColor(Color.White) - .backgroundColor(0xF9CF93).textAlign(TextAlign.Center) - - Text('45rad') - .width(40).height(40) - .rotate({ x: 0, y: 0, z: 1, angle: '45rad', centerX: '50%', centerY: '50%' }) - .fontColor(Color.White) - .backgroundColor(0xF9CF93).textAlign(TextAlign.Center).margin({ top: 30 }) - - Text('Point').fontColor(0xCCCCCC).fontSize(9).width('90%') - Line().width(300).height(40).startPoint([0, 20]).endPoint([300, 20]) - - Text('Color').fontColor('#CCCCCC').fontSize(9).width('90%') - Text('0xF9CF93') - .fontColor(Color.White).textAlign(TextAlign.Center) - .width('90%').height(40).backgroundColor(0xF9CF93) - - Text('#F9CF93') - .fontColor(Color.White).textAlign(TextAlign.Center) - .width('90%').height(40).backgroundColor('#F9CF93') - - Text('rgb(249, 207, 147)') - .fontColor(Color.White).textAlign(TextAlign.Center) - .width('90%').height(40).backgroundColor('rgb(249, 207, 147)') - - Text('rgba(249, 207, 147, 1.0)') - .fontColor(Color.White).textAlign(TextAlign.Center) - .width('90%').height(40).backgroundColor('rgba(249, 207, 147, 1.0)') - - Text('Color.Yellow') - .textAlign(TextAlign.Center) - .width('90%').height(40).backgroundColor(Color.Yellow) - } - .width('100%').margin({ top: 5 }) - } -} -``` - -![zh-cn_image_0000001214437889](/images/application-dev/ui/figures/zh-cn_image_0000001214437889.png) diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/01.\346\217\217\350\277\260\350\247\204\350\214\203\344\275\277\347\224\250\350\257\264\346\230\216.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/01.\346\217\217\350\277\260\350\247\204\350\214\203\344\275\277\347\224\250\350\257\264\346\230\216.md" deleted file mode 100644 index d110f714f29f06f2c646bee7b30f9916e5c06714..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/01.\346\217\217\350\277\260\350\247\204\350\214\203\344\275\277\347\224\250\350\257\264\346\230\216.md" +++ /dev/null @@ -1,25 +0,0 @@ ---- -title: 描述规范使用说明 -permalink: /pages/010802030301 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# 描述规范使用说明 - -本节定义了基于TS扩展的声明式开发范式的核心机制和功能。讲述了声明式UI描述、组件化机制、UI状态管理、渲染控制语法和语法糖。 - -本节为应用开发人员开发UI提供了参考规范。有关组件的详细信息,请参考[组件说明](/pages/extra/710f05/)。 - ->**说明:** -> ->- 所有示例都以TypeScript \(TS\)语言为例,请遵循相应语言的语法要求。 ->- 示例中的**Image**、**Button**、**Text**、**Divider**、**Row**和**Column**等组件是UI框架中预置的组件控件,仅用于解释UI描述规范。 ->- 通用属性方法和事件方法通常支持所有组件,而组件内的属性方法和事件方法仅对当前组件有效。 - diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/02.\351\200\232\347\224\250UI\346\217\217\350\277\260\350\247\204\350\214\203/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/02.\351\200\232\347\224\250UI\346\217\217\350\277\260\350\247\204\350\214\203/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" deleted file mode 100644 index a0142f3d965e6557af2f2c8a55281148dc75e0ce..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/02.\351\200\232\347\224\250UI\346\217\217\350\277\260\350\247\204\350\214\203/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" +++ /dev/null @@ -1,56 +0,0 @@ ---- -title: 基本概念 -permalink: /pages/01080203030201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# 基本概念 - -基于TS扩展的声明式开发范式提供了一系列基本组件,这些组件以声明方式进行组合和扩展来描述应用程序的UI界面,并且还提供了基本的数据绑定和事件处理机制,帮助开发者实现应用交互逻辑。 - -## HelloWorld基本示例 - -``` -// An example of displaying Hello World. After you click the button, Hello UI is displayed. -@Entry -@Component -struct Hello { - @State myText: string = 'World' - build() { - Column() { - Text('Hello') - .fontSize(30) - Text(this.myText) - .fontSize(32) - Divider() - Button() { - Text('Click me') - .fontColor(Color.Red) - }.onClick(() => { - this.myText = 'UI' - }) - .width(500) - .height(200) - } - } -} -``` - -## 基本概念描述 - -上述示例代码描述了简单页面的结构,并介绍了以下基本概念: - -- **装饰器:**方舟开发框架定义了一些具有特殊含义的装饰器,用于装饰类、结构、方法和变量。例如,上例中的**@Entry**、**@Component**和**@State**都是装饰器; -- **自定义组件:**可重用的UI单元,可以与其他组件组合,如**@Component**装饰的**struct Hello**; -- **UI描述:**声明性描述UI结构,例如**build\(\)**方法中的代码块; -- **内置组件:**框架中默认内置的基本组件和布局组件,开发者可以直接调用,如**Column**、**Text**、**Divider**、**Button**等; -- **属性方法:**用于配置组件属性,如**fontSize\(\)**、**width\(\)**、**height\(\)**、**color\(\)**等; -- **事件方法:**在事件方法的回调中添加组件响应逻辑。例如,为Button组件添加onClick方法,在onClick方法的回调中添加点击响应逻辑。 - diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/02.\351\200\232\347\224\250UI\346\217\217\350\277\260\350\247\204\350\214\203/02.\345\243\260\346\230\216\345\274\217UI\346\217\217\350\277\260\350\247\204\350\214\203/01.\346\227\240\346\236\204\351\200\240\345\217\202\346\225\260\351\205\215\347\275\256.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/02.\351\200\232\347\224\250UI\346\217\217\350\277\260\350\247\204\350\214\203/02.\345\243\260\346\230\216\345\274\217UI\346\217\217\350\277\260\350\247\204\350\214\203/01.\346\227\240\346\236\204\351\200\240\345\217\202\346\225\260\351\205\215\347\275\256.md" deleted file mode 100644 index 2832b842acdaf75e9b3002b578c03135a5578765..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/02.\351\200\232\347\224\250UI\346\217\217\350\277\260\350\247\204\350\214\203/02.\345\243\260\346\230\216\345\274\217UI\346\217\217\350\277\260\350\247\204\350\214\203/01.\346\227\240\346\236\204\351\200\240\345\217\202\346\225\260\351\205\215\347\275\256.md" +++ /dev/null @@ -1,25 +0,0 @@ ---- -title: 无构造参数配置 -permalink: /pages/0108020303020201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# 无构造参数配置 - -组件的接口定义不包含必选构造参数,组件后面的“**\(\)**”中不需要配置任何内容。例如,**Divider**组件不包含构造参数: - -``` -Column() { - Text('item 1') - Divider() // No parameter configuration of the divider component - Text('item 2') -} -``` - diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/02.\351\200\232\347\224\250UI\346\217\217\350\277\260\350\247\204\350\214\203/02.\345\243\260\346\230\216\345\274\217UI\346\217\217\350\277\260\350\247\204\350\214\203/02.\345\277\205\351\200\211\345\217\202\346\225\260\346\236\204\351\200\240\351\205\215\347\275\256.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/02.\351\200\232\347\224\250UI\346\217\217\350\277\260\350\247\204\350\214\203/02.\345\243\260\346\230\216\345\274\217UI\346\217\217\350\277\260\350\247\204\350\214\203/02.\345\277\205\351\200\211\345\217\202\346\225\260\346\236\204\351\200\240\351\205\215\347\275\256.md" deleted file mode 100644 index cdb3ff3ddc3be1ab221254383f0d47ab15cc41c9..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/02.\351\200\232\347\224\250UI\346\217\217\350\277\260\350\247\204\350\214\203/02.\345\243\260\346\230\216\345\274\217UI\346\217\217\350\277\260\350\247\204\350\214\203/02.\345\277\205\351\200\211\345\217\202\346\225\260\346\236\204\351\200\240\351\205\215\347\275\256.md" +++ /dev/null @@ -1,45 +0,0 @@ ---- -title: 必选参数构造配置 -permalink: /pages/0108020303020202 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# 必选参数构造配置 - -如果组件的接口定义中包含必选构造参数,则在组件后面的“**\(\)**”中必须配置参数,参数可以使用常量进行赋值。 - -例如: - -- **Image**组件的必选参数**src**: - - ``` - Image('http://xyz/a.jpg') - ``` - - -- **Text**组件的必选参数**content**: - - ``` - Text('123') - ``` - - -变量或表达式也可以用于参数赋值,其中表达式返回的结果类型必须满足参数类型要求。例如,传递变量或表达式来构造**Image**和**Text**组件的参数: - -``` -// imagePath, where imageUrl is a private data variable defined in the component. -Image(this.imagePath) -Image('http://' + this.imageUrl) -// count is a private data variable defined in the component. -// (``) and (${}) are the template character string features supported by the TS language and comply with the -// features of the corresponding language. This specification is not limited. -Text(`count: ${this.count}`) -``` - diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/02.\351\200\232\347\224\250UI\346\217\217\350\277\260\350\247\204\350\214\203/02.\345\243\260\346\230\216\345\274\217UI\346\217\217\350\277\260\350\247\204\350\214\203/03.\345\261\236\346\200\247\351\205\215\347\275\256.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/02.\351\200\232\347\224\250UI\346\217\217\350\277\260\350\247\204\350\214\203/02.\345\243\260\346\230\216\345\274\217UI\346\217\217\350\277\260\350\247\204\350\214\203/03.\345\261\236\346\200\247\351\205\215\347\275\256.md" deleted file mode 100644 index fced798ac9eae83581dbd6919465789473bef87b..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/02.\351\200\232\347\224\250UI\346\217\217\350\277\260\350\247\204\350\214\203/02.\345\243\260\346\230\216\345\274\217UI\346\217\217\350\277\260\350\247\204\350\214\203/03.\345\261\236\346\200\247\351\205\215\347\275\256.md" +++ /dev/null @@ -1,57 +0,0 @@ ---- -title: 属性配置 -permalink: /pages/0108020303020203 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# 属性配置 - -使用属性方法配置组件的属性,属性方法紧随组件,并用“**.**”运算符连接。 - -- 配置**Text**组件的字体大小属性: - - ``` - Text('123') - .fontSize(12) - ``` - - -- 使用“**.**”操作进行链式调用并同时配置组件的多个属性,如下所示: - - ``` - Image('a.jpg') - .alt('error.jpg') - .width(100) - .height(100) - ``` - - -- 除了直接传递常量参数外,还可以传递变量或表达式,如下所示: - - ``` - // Size, count, and offset are private variables defined in the component. - Text('hello') - .fontSize(this.size) - Image('a.jpg') - .width(this.count % 2 === 0 ? 100 : 200) - .height(this.offset + 100) - ``` - - -- 对于内置组件,框架还为其属性预定义了一些枚举类型,供开发人员调用,枚举值可以作为参数传递。枚举类型必须满足参数类型要求,有关特定属性的枚举类型定义的详细信息。可以按以下方式配置**Text**组件的颜色和字重属性: - - ``` - Text('hello') - .fontSize(20) - .fontColor(Color.Red) - .fontWeight(FontWeight.Bold) - ``` - - diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/02.\351\200\232\347\224\250UI\346\217\217\350\277\260\350\247\204\350\214\203/02.\345\243\260\346\230\216\345\274\217UI\346\217\217\350\277\260\350\247\204\350\214\203/04.\344\272\213\344\273\266\351\205\215\347\275\256.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/02.\351\200\232\347\224\250UI\346\217\217\350\277\260\350\247\204\350\214\203/02.\345\243\260\346\230\216\345\274\217UI\346\217\217\350\277\260\350\247\204\350\214\203/04.\344\272\213\344\273\266\351\205\215\347\275\256.md" deleted file mode 100644 index 926d28c1d7a0ab43a773b3f83d1ae461ebada0fc..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/02.\351\200\232\347\224\250UI\346\217\217\350\277\260\350\247\204\350\214\203/02.\345\243\260\346\230\216\345\274\217UI\346\217\217\350\277\260\350\247\204\350\214\203/04.\344\272\213\344\273\266\351\205\215\347\275\256.md" +++ /dev/null @@ -1,53 +0,0 @@ ---- -title: 事件配置 -permalink: /pages/0108020303020204 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# 事件配置 - -通过事件方法可以配置组件支持的事件。 - -- 使用lambda表达式配置组件的事件方法: - - ``` - // Counter is a private data variable defined in the component. - Button('add counter') - .onClick(() => { - this.counter += 2 - }) - ``` - - -- 使用匿名函数表达式配置组件的事件方法,要求使用**bind**,以确保函数体中的this引用包含的组件。 - - ``` - // Counter is a private data variable defined in the component. - Button('add counter') - .onClick(function () { - this.counter += 2 - }.bind(this)) - ``` - - -- 使用组件的成员函数配置组件的事件方法: - - ``` - myClickHandler(): void { - // do something - } - - ... - - Button('add counter') - .onClick(this.myClickHandler) - ``` - - diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/02.\351\200\232\347\224\250UI\346\217\217\350\277\260\350\247\204\350\214\203/02.\345\243\260\346\230\216\345\274\217UI\346\217\217\350\277\260\350\247\204\350\214\203/05.\345\255\220\347\273\204\344\273\266\351\205\215\347\275\256.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/02.\351\200\232\347\224\250UI\346\217\217\350\277\260\350\247\204\350\214\203/02.\345\243\260\346\230\216\345\274\217UI\346\217\217\350\277\260\350\247\204\350\214\203/05.\345\255\220\347\273\204\344\273\266\351\205\215\347\275\256.md" deleted file mode 100644 index ed04236c3fb8e606bf2ea8bdbe52fe06b7251142..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/02.\351\200\232\347\224\250UI\346\217\217\350\277\260\350\247\204\350\214\203/02.\345\243\260\346\230\216\345\274\217UI\346\217\217\350\277\260\350\247\204\350\214\203/05.\345\255\220\347\273\204\344\273\266\351\205\215\347\275\256.md" +++ /dev/null @@ -1,60 +0,0 @@ ---- -title: 子组件配置 -permalink: /pages/0108020303020205 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# 子组件配置 - -对于支持子组件配置的组件,例如容器组件,在“**\{ ... \}**”里为组件添加子组件的UI描述。**Column**、**Row**、**Stack**、**Button**、**Grid**和**List**组件都是容器组件。 - -以下是简单的**Column**示例: - -``` -Column() { - Text('Hello') - .fontSize(100) - Divider() - Text(this.myText) - .fontSize(100) - .fontColor(Color.Red) -} -``` - -可以嵌套多个子组件: - -``` -Column() { - Column() { - Button() { - Text('+ 1') - }.type(ButtonType.Capsule) - .onClick(() => console.log ('+1 clicked!')) - Image('1.jpg') - } - Divider() - Column() { - Button() { - Text('+ 2') - }.type(ButtonType.Capsule) - .onClick(() => console.log ('+2 clicked!')) - Image('2.jpg') - } - Divider() - Column() { - Button() { - Text('+ 3') - }.type(ButtonType.Capsule) - .onClick(() => console.log('+3 clicked!')) - Image('3.jpg') - } -}.alignItems(HorizontalAlign.Center) // center align components inside Column -``` - diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/02.\351\200\232\347\224\250UI\346\217\217\350\277\260\350\247\204\350\214\203/03.\347\273\204\344\273\266\345\214\226/01.Component.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/02.\351\200\232\347\224\250UI\346\217\217\350\277\260\350\247\204\350\214\203/03.\347\273\204\344\273\266\345\214\226/01.Component.md" deleted file mode 100644 index 6546a3ade62b10b0ab0db54b957cb0016b1fd691..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/02.\351\200\232\347\224\250UI\346\217\217\350\277\260\350\247\204\350\214\203/03.\347\273\204\344\273\266\345\214\226/01.Component.md" +++ /dev/null @@ -1,91 +0,0 @@ ---- -title: Component -permalink: /pages/0108020303020301 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# @Component - -**@Component**装饰的**struct**表示该结构体具有组件化能力,能够成为一个独立的组件,这种类型的组件也称为自定义组件,在**build**方法里描述UI结构。自定义组件具有以下特点: - -- **可组合:**允许开发人员组合使用内置组件、其他组件、公共属性和方法; -- **可重用:**自定义组件可以被其他组件重用,并作为不同的实例在不同的父组件或容器中使用; -- **生命周期:**生命周期的回调方法可以在组件中配置,用于业务逻辑处理; -- **数据驱动更新:**由状态变量的数据驱动,实现UI自动更新。 - -对组件化的深入描述,请参考[深入理解组件化](/pages/extra/ba7ead/)。 - ->![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** ->- 自定义组件必须定义build方法。 ->- 自定义组件禁止自定义构造函数。 - -## 示例 - -如下代码定义了**MyComponent**组件**:** - -``` -@Component -struct MyComponent { - build() { - Column() { - Text('my component') - .fontColor(Color.Red) - }.alignItems(HorizontalAlign.Center) // center align Text inside Column - } -} -``` - -**MyComponent**的**build**方法会在初始渲染时执行,此外,当组件中的状态发生变化时,**build**方法将再次执行。 - -以下代码使用了**MyComponent**组件: - -``` -@Component -struct ParentComponent { - build() { - Column() { - MyComponent() - Text('we use component') - .fontSize(20) - } - } -} -``` - -可以多次使用**MyComponent**,并在不同的组件中进行重用: - -``` -@Component -struct ParentComponent { - build() { - Row() { - Column() { - MyComponent() - Text('first column') - .fontSize(20) - } - Column() { - MyComponent() - Text('second column') - .fontSize(20) - } - } - } - - private aboutToAppear() { - console.log('ParentComponent: Just created, about to become rendered first time.') - } - - private aboutToDisappear() { - console.log('ParentComponent: About to be removed from the UI.') - } -} -``` - diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/02.\351\200\232\347\224\250UI\346\217\217\350\277\260\350\247\204\350\214\203/03.\347\273\204\344\273\266\345\214\226/02.Entry.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/02.\351\200\232\347\224\250UI\346\217\217\350\277\260\350\247\204\350\214\203/03.\347\273\204\344\273\266\345\214\226/02.Entry.md" deleted file mode 100644 index 5640267f8b5f7a74b07df6d4c9a352b0d06f82f1..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/02.\351\200\232\347\224\250UI\346\217\217\350\277\260\350\247\204\350\214\203/03.\347\273\204\344\273\266\345\214\226/02.Entry.md" +++ /dev/null @@ -1,48 +0,0 @@ ---- -title: Entry -permalink: /pages/0108020303020302 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# @Entry - -用**@Entry**装饰的自定义组件用作页面的默认入口组件,加载页面时,将首先创建并呈现**@Entry**装饰的自定义组件。 - ->![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** ->在单个源文件中,最多可以使用**@Entry**装饰一个自定义组件。 - -## 示例 - -**@Entry**的用法如下: - -``` -// Only MyComponent decorated by @Entry is rendered and displayed. "hello world" is displayed, but "goodbye" is not displayed. -@Entry -@Component -struct MyComponent { - build() { - Column() { - Text('hello world') - .fontColor(Color.Red) - } - } -} - -@Component -struct HideComponent { - build() { - Column() { - Text('goodbye') - .fontColor(Color.Blue) - } - } -} -``` - diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/02.\351\200\232\347\224\250UI\346\217\217\350\277\260\350\247\204\350\214\203/03.\347\273\204\344\273\266\345\214\226/03.Preview.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/02.\351\200\232\347\224\250UI\346\217\217\350\277\260\350\247\204\350\214\203/03.\347\273\204\344\273\266\345\214\226/03.Preview.md" deleted file mode 100644 index e7ae3970434f72ec3a06098de7c5ed771aac2238..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/02.\351\200\232\347\224\250UI\346\217\217\350\277\260\350\247\204\350\214\203/03.\347\273\204\344\273\266\345\214\226/03.Preview.md" +++ /dev/null @@ -1,73 +0,0 @@ ---- -title: Preview -permalink: /pages/0108020303020303 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# @Preview - -用**@Preview**装饰的自定义组件可以在DevEco Studio的预览器上进行预览,加载页面时,将创建并呈现**@Preview**装饰的自定义组件。 - ->![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** ->在单个源文件中,最多可以使用**@Preview**装饰一个自定义组件。 - -## 示例 - -**@Preview**的用法如下: - -``` -// Display only Hello Component1 on the PC preview. The content under MyComponent is displayed on the real device. -@Entry -@Component -struct MyComponent { - build() { - Column() { - Row() { - Text('Hello World!') - .fontSize("50lpx") - .fontWeight(FontWeight.Bold) - } - Row() { - Component1() - } - Row() { - Component2() - } - } - } -} -@Preview -@Component -struct Component1 { - build() { - Column() { - Row() { - Text('Hello Component1') - .fontSize("50lpx") - .fontWeight(FontWeight.Bold) - } - } - } -} - -@Component -struct Component2 { - build() { - Column() { - Row() { - Text('Hello Component2') - .fontSize("50lpx") - .fontWeight(FontWeight.Bold) - } - } - } -} -``` - diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/02.\351\200\232\347\224\250UI\346\217\217\350\277\260\350\247\204\350\214\203/03.\347\273\204\344\273\266\345\214\226/04.Builder.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/02.\351\200\232\347\224\250UI\346\217\217\350\277\260\350\247\204\350\214\203/03.\347\273\204\344\273\266\345\214\226/04.Builder.md" deleted file mode 100644 index 3855283878ddf11cb1cf01d3345c90fcf46019b8..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/02.\351\200\232\347\224\250UI\346\217\217\350\277\260\350\247\204\350\214\203/03.\347\273\204\344\273\266\345\214\226/04.Builder.md" +++ /dev/null @@ -1,55 +0,0 @@ ---- -title: Builder -permalink: /pages/0108020303020304 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# @Builder - -@Builder装饰的方法用于定义组件的声明式UI描述,在一个自定义组件内快速生成多个布局内容。@Builder装饰方法的功能和语法规范与[build函数](/pages/01080203030501)相同。 - -``` -@Entry -@Component -struct CompA { - size : number = 100; - - @Builder SquareText(label: string) { - Text(label) - .width(1 * this.size) - .height(1 * this.size) - } - - @Builder RowOfSquareTexts(label1: string, label2: string) { - Row() { - this.SquareText(label1) - this.SquareText(label2) - } - .width(2 * this.size) - .height(1 * this.size) - } - - build() { - Column() { - Row() { - this.SquareText("A") - this.SquareText("B") - // or as long as tsc is used - } - .width(2 * this.size) - .height(1 * this.size) - this.RowOfSquareTexts("C", "D") - } - .width(2 * this.size) - .height(2 * this.size) - } -} -``` - diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/02.\351\200\232\347\224\250UI\346\217\217\350\277\260\350\247\204\350\214\203/03.\347\273\204\344\273\266\345\214\226/05.Extend.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/02.\351\200\232\347\224\250UI\346\217\217\350\277\260\350\247\204\350\214\203/03.\347\273\204\344\273\266\345\214\226/05.Extend.md" deleted file mode 100644 index b1176f98fbb47ade40151a17be9633863d10a243..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/02.\351\200\232\347\224\250UI\346\217\217\350\277\260\350\247\204\350\214\203/03.\347\273\204\344\273\266\345\214\226/05.Extend.md" +++ /dev/null @@ -1,41 +0,0 @@ ---- -title: Extend -permalink: /pages/0108020303020305 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# @Extend - -**@Extend**装饰器将新的属性函数添加到内置组件上,如**Text**、**Column**、**Button**等。通过**@Extend**装饰器可以快速定义并复用组件的自定义样式。 - -``` -@Extend(Text) function fancy(fontSize: number) { - .fontColor(Color.Red) - .fontSize(fontSize) - .fontStyle(FontStyle.Italic) -} - -@Entry -@Component -struct FancyUse { - build() { - Row({ space: 10 }) { - Text("Fancy") - .fancy(16) - Text("Fancy") - .fancy(24) - } - } -} -``` - ->![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** ->@Extend装饰器不能用在自定义组件struct定义框内。 - diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/02.\351\200\232\347\224\250UI\346\217\217\350\277\260\350\247\204\350\214\203/03.\347\273\204\344\273\266\345\214\226/06.CustomDialog.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/02.\351\200\232\347\224\250UI\346\217\217\350\277\260\350\247\204\350\214\203/03.\347\273\204\344\273\266\345\214\226/06.CustomDialog.md" deleted file mode 100644 index 16fb082a7d22559b1043dd60bab26b3eff2a584a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/02.\351\200\232\347\224\250UI\346\217\217\350\277\260\350\247\204\350\214\203/03.\347\273\204\344\273\266\345\214\226/06.CustomDialog.md" +++ /dev/null @@ -1,62 +0,0 @@ ---- -title: CustomDialog -permalink: /pages/0108020303020306 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# @CustomDialog - -**@CustomDialog**装饰器用于装饰自定义弹窗。 - -``` -// custom-dialog-demo.ets -@CustomDialog -struct DialogExample { - controller: CustomDialogController; - action: () => void; - - build() { - Row() { - Button ("Close CustomDialog") - .onClick(() => { - this.controller.close(); - this.action(); - }) - }.padding(20) - } -} - -@Entry -@Component -struct CustomDialogUser { - dialogController : CustomDialogController = new CustomDialogController({ - builder: DialogExample({action: this.onAccept}), - cancel: this.existApp, - autoCancel: true - }); - - onAccept() { - console.log("onAccept"); - } - existApp() { - console.log("Cancel dialog!"); - } - - build() { - Column() { - Button("Click to open Dialog") - .onClick(() => { - this.dialogController.open() - }) - } - } -} -``` - diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/03.UI\347\212\266\346\200\201\347\256\241\347\220\206/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/03.UI\347\212\266\346\200\201\347\256\241\347\220\206/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" deleted file mode 100644 index bbc29c4e40aa39a48bb66c3277d06449f9b3e4ba..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/03.UI\347\212\266\346\200\201\347\256\241\347\220\206/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" +++ /dev/null @@ -1,33 +0,0 @@ ---- -title: 基本概念 -permalink: /pages/01080203030301 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# 基本概念 - -在声明式UI编程范式中,UI是应用程序状态的函数,开发人员通过修改当前应用程序状态来更新相应的UI界面。开发框架提供了多种应用程序状态管理的能力。 - -![](/images/application-dev/ui/figures/CoreSpec_/images/application-dev/ui/figures_state-mgmt-overview.png) - -## 状态变量装饰器 - -- **@State:**组件拥有的状态属性,当**@State**装饰的变量更改时,组件会重新渲染更新UI。 -- **@Link:**组件依赖于其父组件拥有的某些状态属性,当任何一个组件中的数据更新时,另一个组件的状态都会更新,父子组件重新渲染。 -- **@Prop:**原理类似**@Link**,但是子组件所做的更改不会同步到父组件上,属于单向传递。 - -## 应用程序状态数据 - -**AppStorage**是整个UI应用程序状态的中心“数据库”,UI框架会针对应用程序创建单例**AppStorage**对象,并提供相应的装饰器和接口供应用程序使用。 - -- **@StorageLink:@StorageLink\(name\)**的原理类似于**@Consume\(name\)**,不同的是,该给定名称的链接对象是从**AppStorage**中获得的,在**UI组件**和**AppStorage**之间建立双向绑定同步数据。 -- **@StorageProp:@StorageProp\(name\)**将UI组件属性与**AppStorage**进行单向同步,**AppStorage**中值的更改会更新组件中的属性,但UI组件无法更改**AppStorage**中的属性值。 -- **AppStorage**还提供用于业务逻辑实现的API,用于添加、读取、修改和删除应用程序的状态属性,此API所做的更改会导致修改的状态数据同步到UI组件上进行UI更新。 - diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/03.UI\347\212\266\346\200\201\347\256\241\347\220\206/02.\347\256\241\347\220\206\347\273\204\344\273\266\346\213\245\346\234\211\347\232\204\347\212\266\346\200\201/01.State.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/03.UI\347\212\266\346\200\201\347\256\241\347\220\206/02.\347\256\241\347\220\206\347\273\204\344\273\266\346\213\245\346\234\211\347\232\204\347\212\266\346\200\201/01.State.md" deleted file mode 100644 index a609582023403d26aaf99c3ef78a469cddb904e4..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/03.UI\347\212\266\346\200\201\347\256\241\347\220\206/02.\347\256\241\347\220\206\347\273\204\344\273\266\346\213\245\346\234\211\347\232\204\347\212\266\346\200\201/01.State.md" +++ /dev/null @@ -1,106 +0,0 @@ ---- -title: State -permalink: /pages/0108020303030201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# @State - -**@State**装饰的变量是组件内部的状态数据,当这些状态数据被修改时,将会调用所在组件的**build**方法进行UI刷新。 - -**@State**状态数据具有以下特征: - -- **支持多种类型:**允许**class**、**number**、**boolean**、**string**强类型的按值和按引用类型。允许这些强类型构成的数组,即**Array**、**Array**、**Array**、**Array。**不允许**object**和**any。** -- **支持多实例:**组件不同实例的内部状态数据独立。 -- **内部私有:**标记为**@State**的属性是私有变量,只能在组件内访问。 -- **需要本地初始化:**必须为所有**@State**变量分配初始值,将变量保持未初始化可能导致框架行为未定义。 -- **创建自定义组件时支持通过状态变量名设置初始值:**在创建组件实例时,可以通过变量名显式指定**@State**状态属性的初始值**。** - -## 简单类型的状态属性示例 - -``` -@Entry -@Component -struct MyComponent { - @State count: number = 0 - // MyComponent provides a method for modifying the @State status data member. - private toggleClick() { - this.count += 1 - } - - build() { - Column() { - Button() { - Text(`click times: ${this.count}`) - .fontSize(10) - }.onClick(this.toggleClick.bind(this)) - } - } -} -``` - -## 复杂类型的状态变量示例 - -``` -// Customize the status data class. -class Model { - value: string - constructor(value: string) { - this.value = value - } -} - -@Entry -@Component -struct EntryComponent { - build() { - Column() { - MyComponent({count: 1, increaseBy: 2}) // MyComponent1 in this document - MyComponent({title: {value: 'Hello, World 2'}, count: 7}) //MyComponent2 in this document - } - } -} - -@Component -struct MyComponent { - @State title: Model = {value: 'Hello World'} - @State count: number = 0 - private toggle: string = 'Hello World' - private increaseBy: number = 1 - - build() { - Column() { - Text(`${this.title.value}`).fontSize(30) - Button() { - Text(`Click to change title`).fontSize(20).fontColor(Color.White) - }.onClick(() => { - this.title.value = (this.toggle == this.title.value) ? 'Hello World' : 'Hello UI' - }) // Modify the internal state of MyComponent using the anonymous method. - - Button() { - Text(`Click to increase count=${this.count}`).fontSize(20).fontColor(Color.White) - }.onClick(() => { - this.count += this.increaseBy - }) // Modify the internal state of MyComponent using the anonymous method. - } - } -} -``` - -在上述示例中: - -- 用户定义的组件**MyComponent**定义了**@State**状态变量**count**和**title**。如果**count**或**title**的值发生变化,则执行**MyComponent**的**build**方法来重新渲染组件; -- **EntryComponent**中有多个**MyComponent**组件实例,第一个**MyComponent**内部状态的更改不会影响第二个**MyComponent**; -- 创建**MyComponent**实例时通过变量名给组件内的变量进行初始化,如: - - ``` - MyComponent({title: {value: 'Hello, World 2'}, count: 7}) - ``` - diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/03.UI\347\212\266\346\200\201\347\256\241\347\220\206/02.\347\256\241\347\220\206\347\273\204\344\273\266\346\213\245\346\234\211\347\232\204\347\212\266\346\200\201/02.Prop.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/03.UI\347\212\266\346\200\201\347\256\241\347\220\206/02.\347\256\241\347\220\206\347\273\204\344\273\266\346\213\245\346\234\211\347\232\204\347\212\266\346\200\201/02.Prop.md" deleted file mode 100644 index 4322c8144f6c9712dd14ad9ae510092e9ed99f14..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/03.UI\347\212\266\346\200\201\347\256\241\347\220\206/02.\347\256\241\347\220\206\347\273\204\344\273\266\346\213\245\346\234\211\347\232\204\347\212\266\346\200\201/02.Prop.md" +++ /dev/null @@ -1,81 +0,0 @@ ---- -title: Prop -permalink: /pages/0108020303030202 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# @Prop - -**@Prop与@State**有相同的语义,但初始化方式不同。**@Prop**装饰的变量必须使用其父组件提供的**@State**变量进行初始化,允许组件内部修改**@Prop**变量,但更改不会通知给父组件,即**@Prop**属于单向数据绑定。 - -**@Prop**状态数据具有以下特征: - -- **支持简单类型:**仅支持number、string、boolean简单类型; -- **私有:**仅在组件内访问; -- **支持多个实例:**一个组件中可以定义多个标有**@Prop**的属性; -- **创建自定义组件时将值传递给@Prop变量进行初始化:**在创建组件的新实例时,必须初始化所有@Prop变量,不支持在组件内部进行初始化。 - -## 示例 - -``` -@Entry -@Component -struct ParentComponent { - @State countDownStartValue: number = 10 // 10 Nuggets default start value in a Game - build() { - Column() { - Text(`Grant ${this.countDownStartValue} nuggets to play.`) - Button() { - Text('+1 - Nuggets in New Game') - }.onClick(() => { - this.countDownStartValue += 1 - }) - Button() { - Text('-1 - Nuggets in New Game') - }.onClick(() => { - this.countDownStartValue -= 1 - }) - - // when creatng ChildComponent, the initial value of its @Prop variable must be supplied - // in a named constructor parameter - // also regular costOfOneAttempt (non-Prop) variable is initialied - CountDownComponent({ count: this.countDownStartValue, costOfOneAttempt: 2}) - } - } -} - -@Component -struct CountDownComponent { - @Prop count: number - private costOfOneAttempt: number - - build() { - Column() { - if (this.count > 0) { - Text(`You have ${this.count} Nuggets left`) - } else { - Text('Game over!') - } - - Button() { - Text('Try again') - }.onClick(() => { - this.count -= this.costOfOneAttempt - }) - } - } -} -``` - -在上述示例中,当按“+1”或“-1”按钮时,父组件状态发生变化,重新执行**build**方法,此时将创建一个新的**CountDownComponent**组件。父组件的**countDownStartValue**状态属性被用于初始化子组件的**@Prop**变量,当按下子组件的“Try again”按钮时,其**@Prop**变量**count**将被更改,**CountDownComponent**重新渲染。但是**count**值的更改不会影响父组件的**countDownStartValue**值。 - ->![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** ->创建新组件实例时,必须初始化其所有**@Prop**变量。 - diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/03.UI\347\212\266\346\200\201\347\256\241\347\220\206/02.\347\256\241\347\220\206\347\273\204\344\273\266\346\213\245\346\234\211\347\232\204\347\212\266\346\200\201/03.Link.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/03.UI\347\212\266\346\200\201\347\256\241\347\220\206/02.\347\256\241\347\220\206\347\273\204\344\273\266\346\213\245\346\234\211\347\232\204\347\212\266\346\200\201/03.Link.md" deleted file mode 100644 index e16e4904ae1a12c6f58de6fd28ee440e6634f61c..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/03.UI\347\212\266\346\200\201\347\256\241\347\220\206/02.\347\256\241\347\220\206\347\273\204\344\273\266\346\213\245\346\234\211\347\232\204\347\212\266\346\200\201/03.Link.md" +++ /dev/null @@ -1,138 +0,0 @@ ---- -title: Link -permalink: /pages/0108020303030203 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# @Link - -**@Link**装饰的变量可以和父组件的**@State**变量建立双向数据绑定: - -- **支持多种类型:@Link**变量的值与**@State**变量的类型相同,即class、number、string、boolean或这些类型的数组; -- **私有:**仅在组件内访问; -- **单个数据源:**初始化**@Link**变量的父组件的变量必须是**@State**变量; -- **双向通信:**子组件对**@Link**变量的更改将同步修改父组件的**@State**变量; -- **创建自定义组件时需要将变量的引用传递给@Link变量:**在创建组件的新实例时,必须使用命名参数初始化所有**@Link**变量。**@Link**变量可以使用**@State**变量或**@Link**变量的引用进行初始化,**@State**变量可以通过'**$**'操作符创建引用。 - ->![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** ->**@Link**变量不能在组件内部进行初始化。 - -## 简单类型示例 - -``` -@Entry -@Component -struct Player { - @State isPlaying: boolean = false - build() { - Column() { - PlayButton({buttonPlaying: $isPlaying}) - Text(`Player is ${this.isPlaying? '':'not'} playing`) - } - } -} - -@Component -struct PlayButton { - @Link buttonPlaying: boolean - build() { - Column() { - Button() { - Image(this.buttonPlaying? 'play.png' : 'pause.png') - }.onClick(() => { - this.buttonPlaying = !this.buttonPlaying - }) - } - } -} -``` - -**@Link**语义是从'**$**'操作符引出,即**$isPlaying**是**this.isPlaying**内部状态的双向数据绑定。当您单击**PlayButton**时,PlayButton 的**Image**组件和**Text**组件将同时进行刷新。 - -## 复杂类型示例 - -``` -@Entry -@Component -struct Parent { - @State arr: number[] = [1, 2, 3] - build() { - Column() { - Child({items: $arr}) - ForEach(this.arr, - item => Text(`${item}`), - item => item.toString()) - } - } -} - -@Component -struct Child { - @Link items: number[] - build() { - Column() { - Button() { - Text('Button1: push') - }.onClick(() => { - this.items.push(100) - }) - Button() { - Text('Button2: replace whole item') - }.onClick(() => { - this.items = [100, 200, 300] - }) - } - } -} -``` - -在上面的示例中,点击**Button1**和**Button2**更改父组件中显示的文本项目列表。 - -## @Link和@State、@Prop结合使用示例 - -``` -@Entry -@Component -struct ParentView { - @State counter: number = 0 - build() { - Column() { - ChildA({counterVal: this.counter}) // pass by value - ChildB({counterRef: $counter}) // $ creates a Reference that can be bound to counterRef - } - } -} - -@Component -struct ChildA { - @Prop counterVal: number - build() { - Button() { - Text(`ChildA: (${this.counterVal}) + 1`) - }.onClick(() => {this.counterVal+= 1}) - } -} - -@Component -struct ChildB { - @Link counterRef: number - build() { - Button() { - Text(`ChildB: (${this.counterRef}) + 1`) - }.onClick(() => {this.counterRef+= 1}) - } -} -``` - -上述示例中,ParentView包含ChildA和ChildB两个子组件,ParentView的状态变量**counter**分别初始化ChildA和ChildB。 - -- ChildB使用**@Link**建立双向状态绑定。当**ChildB**修改**counterRef**状态变量值时,该更改将同步到**ParentView**和**ChildA**共享; -- ChildA使用**@Prop**建立从**ParentView**到自身的单向状态绑定。当**ChildA**修改状态时,**ChildA**将重新渲染,但该更改不会传达给**ParentView**和**ChildB。** - diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/03.UI\347\212\266\346\200\201\347\256\241\347\220\206/03.\347\256\241\347\220\206\345\272\224\347\224\250\347\250\213\345\272\217\347\232\204\347\212\266\346\200\201/01.\346\216\245\345\217\243/01.\345\272\224\347\224\250\347\250\213\345\272\217\347\232\204\346\225\260\346\215\256\345\255\230\345\202\250.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/03.UI\347\212\266\346\200\201\347\256\241\347\220\206/03.\347\256\241\347\220\206\345\272\224\347\224\250\347\250\213\345\272\217\347\232\204\347\212\266\346\200\201/01.\346\216\245\345\217\243/01.\345\272\224\347\224\250\347\250\213\345\272\217\347\232\204\346\225\260\346\215\256\345\255\230\345\202\250.md" deleted file mode 100644 index a6856e65d8b1457eb49f95e678c7e9916211ad83..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/03.UI\347\212\266\346\200\201\347\256\241\347\220\206/03.\347\256\241\347\220\206\345\272\224\347\224\250\347\250\213\345\272\217\347\232\204\347\212\266\346\200\201/01.\346\216\245\345\217\243/01.\345\272\224\347\224\250\347\250\213\345\272\217\347\232\204\346\225\260\346\215\256\345\255\230\345\202\250.md" +++ /dev/null @@ -1,211 +0,0 @@ ---- -title: 应用程序的数据存储 -permalink: /pages/010802030303030101 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# 应用程序的数据存储 - -**AppStorage**是应用程序中的单例对象,由UI框架在应用程序启动时创建,在应用程序退出退出时销毁,为应用程序范围内的可变状态属性提供中央存储。**AppStorage**包含整个应用程序中需要访问的所有状态属性,只要应用程序保持运行,**AppStorage**就会保存所有属性及属性值,属性值可以通过唯一的键值进行访问。 - -UI组件可以通过装饰器将应用程序状态数据与**AppStorage**进行同步,应用业务逻辑的实现也可以通过接口访问**AppStorage**。 - -**AppStorage**的选择状态属性可以与不同的数据源或数据接收器同步,这些数据源和接收器可以是设备上的本地或远程,并具有不同的功能,如数据持久性。这样的数据源和接收器可以独立于UI在业务逻辑中实现。 - -默认情况下,**AppStorage**中的属性是可变的,**AppStorage**还可使用不可变(只读)属性。 - -## AppStorage接口 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

方法

-

参数说明

-

返回值

-

定义

-

SetAndLink

-

key: string,

-

defaultValue: T

-

@Link

-

与Link接口类似,如果当前的key保存于AppStorage,则返回该key对应的value。如果该key未被创建,则创建一个对应default值的Link返回。

-

Set

-

key: string,

-

newValue: T

-

void

-

对已保存的key值,替换其value值。

-

Link

-

key: string

-

@Link

-

如果存在具有给定键的数据,则返回到此属性的双向数据绑定,该双向绑定意味着变量或者组件对数据的更改将同步到AppStorage,通过AppStorage对数据的修改将同步到变量或者组件。如果具有此键的属性不存在或属性为只读,则返回undefined

-

SetAndProp

-

propName: string,

-

defaultValue: S

-

@Prop

-

与Prop接口类似,如果当前的key保存于AppStorage,则返回该key对应的value。如果该key未被创建,则创建一个对应default值的Prop返回。

-

Prop

-

key: string

-

@Prop

-

如果存在具有给定键的属性,则返回此属性的单向数据绑定。该单向绑定意味着只能通过AppStorage将属性的更改同步到变量或者组件。该方法返回的变量为不可变变量,适用于可变和不可变的状态属性,如果具有此键的属性不存在则返回undefined

-
说明:

prop方法对应的属性值类型为简单类型。

-
-

SetOrCreate

-

key: string,

-

newValue: T

-

boolean

-

如果相同名字的属性存在:如果此属性可以被更改返回true,否则返回false。

-

如果相同名字的属性不存在:创建第一个赋值为defaultValue的属性,不支持null和undefined。

-

Get

-

key: string

-

T或undefined

-

通过此接口获取对应key值的value。

-

Has

-

propName: string

-

boolean

-

判断对应键值的属性是否存在

-

Keys

-

void

-

array<string>

-

返回包含所有键的字符串数组。

-

Delete

-

key: string

-

boolean

-

删除key指定的键值对,如果存在且删除成功返回true,不存在或删除失败返回false。

-

Clear

-

void

-

boolean

-

删除所有的属性,如果当前有状态变量依旧引用此属性,则返回false。

-

IsMutable

-

key: string

-

boolean

-

返回此属性是否存在并且是否可以改变。

-
- ->![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** ->当前接口当前仅可以处理基础类型数据,对于修改object中某一个值尚未支持。 - -## AppStorage与组件同步 - -在[管理组件拥有的状态](/pages/0108020303030201)中,已经定义了如何将组件的状态变量与父组件或祖先组件中的**@State**装饰的状态变量同步,主要包括**@Prop**、**@Link**、**@Consume**。 - -本章节将定义如何将组件变量与**AppStorage**同步,主要提供**@StorageLink**和**@StorageProp**装饰器。 - -### @StorageLink装饰器 - -组件通过使用**@StorageLink\(key\)**装饰的状态变量,与**AppStorage**建立双向数据绑定,**key**为**AppStorage**中的属性键值。当创建包含**@StorageLink**的状态变量的组件时,该状态变量的值将使用**AppStorage**中的值进行初始化。在UI组件中对**@StorageLink**的状态变量所做的更改将同步到**AppStorage**,并从**AppStorage**同步到任何其他绑定实例中,如**PersistentStorage**或其他绑定的UI组件。 - -### @StorageProp装饰器 - -组件通过使用**@StorageProp\(key\)**装饰的状态变量,将与**AppStorage**建立单向数据绑定,**key**标识AppStorage中的属性键值。当创建包含**@StoageProp**的状态变量的组件时,该状态变量的值将使用**AppStorage**中的值进行初始化。**AppStorage**中的属性值的更改会导致绑定的UI组件进行状态更新。 - -## 示例 - -``` -let varA = AppStorage.Link('varA') -let envLang = AppStorage.Prop('languageCode') - -@Entry -@Component -struct ComponentA { - @StorageLink('varA') varA: number = 2 - @StorageProp('languageCode') lang: string = 'en' - private label: string = 'count' - - private aboutToAppear() { - this.label = (this.lang === 'zh') ? '数' : 'Count' - } - - build() { - Row({ space: 20 }) { - - Button(`${this.label}: ${this.varA}`) - .onClick(() => { - AppStorage.Set('varA', AppStorage.Get('varA') + 1) - }) - Button(`lang: ${this.lang}`) - .onClick(() => { - if (this.lang === 'zh') { - AppStorage.Set('languageCode', 'en') - } else { - AppStorage.Set('languageCode', 'zh') - } - this.label = (this.lang === 'zh') ? '数' : 'Count' - }) - } - } -} -``` - -每次开发者单击Count按钮时,this.varA变量值都会增加,此变量与AppStorage中的varA同步。每次用户单击当前语言按钮时,修改AppStorage中的languageCode,此修改会同步给this.lang变量。 - diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/03.UI\347\212\266\346\200\201\347\256\241\347\220\206/03.\347\256\241\347\220\206\345\272\224\347\224\250\347\250\213\345\272\217\347\232\204\347\212\266\346\200\201/01.\346\216\245\345\217\243/02.\346\214\201\344\271\205\345\214\226\346\225\260\346\215\256\347\256\241\347\220\206.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/03.UI\347\212\266\346\200\201\347\256\241\347\220\206/03.\347\256\241\347\220\206\345\272\224\347\224\250\347\250\213\345\272\217\347\232\204\347\212\266\346\200\201/01.\346\216\245\345\217\243/02.\346\214\201\344\271\205\345\214\226\346\225\260\346\215\256\347\256\241\347\220\206.md" deleted file mode 100644 index 2a4867059420d6db72428e4b425825bdd76c9399..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/03.UI\347\212\266\346\200\201\347\256\241\347\220\206/03.\347\256\241\347\220\206\345\272\224\347\224\250\347\250\213\345\272\217\347\232\204\347\212\266\346\200\201/01.\346\216\245\345\217\243/02.\346\214\201\344\271\205\345\214\226\346\225\260\346\215\256\347\256\241\347\220\206.md" +++ /dev/null @@ -1,104 +0,0 @@ ---- -title: 持久化数据管理 -permalink: /pages/010802030303030102 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# 持久化数据管理 - -方舟开发框架通过**PersistentStorage**类提供了一些静态方法用来管理应用持久化数据,可以将特定标记的持久化数据链接到AppStorage中,并由AppStorage接口访问对应持久化数据,或者通过@StorageLink装饰器来访问对应key的变量。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

方法

-

参数说明

-

返回值

-

定义

-

PersistProp

-

key : string

-

defaultValue: T

-

void

-

关联命名的属性在AppStorage变为持久化数据,赋值覆盖顺序如下:

-
  • 首先,如果该属性存在于AppStorage,将Persistent中的数据复写为AppStorage中的属性值。
  • 其次,Persistent中有此命名的属性,使用Persistent中的属性值。
-
  • 最后,以上条件均不满足,则使用defaultValue,不支持null和undefined。
-

DeleteProp

-

key: string

-

void

-

取消双向数据绑定,该属性值将从持久存储中删除。

-

PersistProps

-

keys: {

-

key: string,

-

defaultValue: any

-

}[]

-

void

-

关联多个命名的属性绑定。

-

Keys

-

void

-

Array<string>

-

返回所有持久化属性的标记。

-
- ->![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** ->- PersistProp接口使用时,需要保证输入对应的key应当在Appstorage存在。 ->- DeleteProp接口使用时,只能对本次启动已经link过的数据生效。 - -``` -PersistentStorage.PersistProp("highScore", "0"); - -@Entry -@Component -struct PersistentComponent { - @StorageLink('highScore') highScore: string = '0' - @State currentScore: number = 0 - build() { - Column() { - if (this.currentScore === Number(this.highScore)) { - Text(`new highScore : ${this.highScore}`) - } - Button() { - Text(`goal!, currentScore : ${this.currentScore}`) - .fontSize(10) - }.onClick(() => { - this.currentScore++ - if (this.currentScore > Number(this.highScore)) { - this.highScore = this.currentScore.toString() - } - }) - } - } -} -``` - diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/03.UI\347\212\266\346\200\201\347\256\241\347\220\206/03.\347\256\241\347\220\206\345\272\224\347\224\250\347\250\213\345\272\217\347\232\204\347\212\266\346\200\201/01.\346\216\245\345\217\243/03.\347\216\257\345\242\203\345\217\230\351\207\217.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/03.UI\347\212\266\346\200\201\347\256\241\347\220\206/03.\347\256\241\347\220\206\345\272\224\347\224\250\347\250\213\345\272\217\347\232\204\347\212\266\346\200\201/01.\346\216\245\345\217\243/03.\347\216\257\345\242\203\345\217\230\351\207\217.md" deleted file mode 100644 index 2ced31271f5d74f4233b74e80323b59d14193c72..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/03.UI\347\212\266\346\200\201\347\256\241\347\220\206/03.\347\256\241\347\220\206\345\272\224\347\224\250\347\250\213\345\272\217\347\232\204\347\212\266\346\200\201/01.\346\216\245\345\217\243/03.\347\216\257\345\242\203\345\217\230\351\207\217.md" +++ /dev/null @@ -1,128 +0,0 @@ ---- -title: 环境变量 -permalink: /pages/010802030303030103 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# 环境变量 - -**Environment**是框架在应用程序启动时创建的单例对象,它为**AppStorage**提供了一系列应用程序需要的环境状态属性,这些属性描述了应用程序运行的设备环境。**Environment**及其属性是不可变的,所有属性值类型均为简单类型。如下示例展示了从**Environment**获取语音环境: - -``` -Environment.EnvProp("accessibilityEnabled", "default"); -var enable = AppStorageGet("accessibilityEnabled"); -``` - -**accessibilityEnabled**是**Environment**提供默认系统变量识别符。首先需要将对应系统属性绑定到**Appstorage**中,再通过AppStorage中的方法或者装饰器访问对应系统的属性数据。 - -## Environment接口 - - - - - - - - - - - - - - - - - - - - - - - - -

key

-

参数

-

返回值

-

说明

-

EnvProp

-

key: string,

-

defaultValue: any

-

boolean

-

关联此系统项到Appstorage中,建议在app启动时使用此接口。如果该属性在Appstorage已存在,返回false。请勿使用AppStorage中的变量,在调用此方法关联环境变量。

-

EnvProps

-

keys: {

-

key: string,

-

defaultValue: any

-

}[]

-

void

-

关联此系统项数组到Appstorage中。

-

Keys

-

Array<string>

-

number

-

返回关联的系统项。

-
- -## Environment内置的环境变量 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

key

-

类型

-

说明

-

accessibilityEnabled

-

boolean

-

无障碍屏幕朗读是否启用。

-

colorMode

-

ColorMode

-

深浅色模式,可选值为:

-
  • ColorMode.LIGHT:浅色模式;
  • ColorMode.DARK:深色模式。
-

fontScale

-

number

-

字体大小比例,取值范围为[0.85, 1.45]。

-

fontWeightScale

-

number

-

字体权重比例,取值范围为[0.6, 1.6]。

-

layoutDirection

-

LayoutDirection

-

布局方向类型,可选值为:

-
  • LayoutDirection.LTR:从左到右;
  • LayoutDirection.RTL:从右到左。
-

languageCode

-

string

-

设置当前系统的语言,小写字母,例如zh。

-
diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/03.UI\347\212\266\346\200\201\347\256\241\347\220\206/03.\347\256\241\347\220\206\345\272\224\347\224\250\347\250\213\345\272\217\347\232\204\347\212\266\346\200\201/02.AppStorage\344\270\216\347\273\204\344\273\266\345\220\214\346\255\245.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/03.UI\347\212\266\346\200\201\347\256\241\347\220\206/03.\347\256\241\347\220\206\345\272\224\347\224\250\347\250\213\345\272\217\347\232\204\347\212\266\346\200\201/02.AppStorage\344\270\216\347\273\204\344\273\266\345\220\214\346\255\245.md" deleted file mode 100644 index 230b5ae0eab58e1338d68c531d444b82652bdfe2..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/03.UI\347\212\266\346\200\201\347\256\241\347\220\206/03.\347\256\241\347\220\206\345\272\224\347\224\250\347\250\213\345\272\217\347\232\204\347\212\266\346\200\201/02.AppStorage\344\270\216\347\273\204\344\273\266\345\220\214\346\255\245.md" +++ /dev/null @@ -1,70 +0,0 @@ ---- -title: AppStorage与组件同步 -permalink: /pages/0108020303030302 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:27 ---- -# AppStorage与组件同步 - -在[管理组件拥有的状态](/pages/0108020303030201)中,我们已经定义了如何将组件的状态变量与父组件或祖先组件中的**@State**装饰的状态变量同步,主要包括**@Prop**、**@Link**、**@Consume**。 - - -本章节将定义如何将组件变量与**AppStorage**同步,主要提供**@StorageLink**和**@StorageProp**装饰器。 - - -## @StorageLink装饰器 - -组件通过使用**@StorageLink(key)**装饰的状态变量,将与**AppStorage**建立双向数据绑定,**key**为**AppStorage**中的属性键值。当创建包含**@StorageLink**的状态变量的组件时,该状态变量的值将使用**AppStorage**中的值进行初始化。在UI组件中对**@StorageLink**的状态变量所做的更改将同步到**AppStorage**,并从**AppStorage**同步到任何其他绑定实例中,如**PersistentStorage**或其他绑定的UI组件。 - - -## @StorageProp装饰器 - -组件通过使用**@StorageProp(key)**装饰的状态变量,将于**AppStorage**建立单向数据绑定,**key**标识AppStorage中的属性键值。当创建包含**@StoageProp**的状态变量的组件时,该状态变量的值将使用**AppStorage**中的值进行初始化。**AppStorage**中的属性值更改会导致绑定的UI组件进行状态更新。 - - -## 示例 - -``` -let varA = AppStorage.Link('varA') -let envLang = AppStorage.Prop('languageCode') - -@Entry -@Component -struct ComponentA { - @StorageLink('varA') varA: number = 2 - @StorageProp('languageCode') lang: string = 'en' - private label: string = 'count' - - private aboutToAppear() { - this.label = (this.lang === 'zh') ? '数' : 'Count' - } - - build() { - Row({ space: 20 }) { - - Button(`${this.label}: ${this.varA}`) - .onClick(() => { - AppStorage.Set('varA', AppStorage.Get('varA') + 1) - }) - Button(`lang: ${this.lang}`) - .onClick(() => { - if (this.lang === 'zh') { - AppStorage.Set('languageCode', 'en') - } else { - AppStorage.Set('languageCode', 'zh') - } - this.label = (this.lang === 'zh') ? '数' : 'Count' - }) - } - } -} -``` - -每次用户单击Count按钮时,this.varA变量值都会增加,此变量与AppStorage中的varA同步。每次用户单击当前语言按钮时,修改AppStorage中的languageCode,此修改会同步给this.lang变量。 diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/03.UI\347\212\266\346\200\201\347\256\241\347\220\206/04.\345\205\266\344\273\226\347\261\273\347\233\256\347\232\204\347\212\266\346\200\201\347\256\241\347\220\206/01.Observed\345\222\214ObjectLink\346\225\260\346\215\256\347\256\241\347\220\206.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/03.UI\347\212\266\346\200\201\347\256\241\347\220\206/04.\345\205\266\344\273\226\347\261\273\347\233\256\347\232\204\347\212\266\346\200\201\347\256\241\347\220\206/01.Observed\345\222\214ObjectLink\346\225\260\346\215\256\347\256\241\347\220\206.md" deleted file mode 100644 index efe450691fc04283cfec19ab877bf8f3768b8970..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/03.UI\347\212\266\346\200\201\347\256\241\347\220\206/04.\345\205\266\344\273\226\347\261\273\347\233\256\347\232\204\347\212\266\346\200\201\347\256\241\347\220\206/01.Observed\345\222\214ObjectLink\346\225\260\346\215\256\347\256\241\347\220\206.md" +++ /dev/null @@ -1,185 +0,0 @@ ---- -title: Observed和ObjectLink数据管理 -permalink: /pages/0108020303030401 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# Observed和ObjectLink数据管理 - - -本章将引入两个新的装饰符@Observed和@ObjectLink: - -- @Observed应用于类,表示该类中的数据变更被UI页面管理,例如:@Observed class ClassA \{\}。 -- @ObjectLink应用于被@Observed所装饰类的对象,例如:@ObjectLink a: ClassA。 - -## 引入动机 - -当开发者需要在子组件中针对父组件的一个变量(parent\_a)设置双向同步时,开发者可以在父组件中使用@State装饰变量(parsent\_a),并在子组件中使用@Link装饰相应的变量(child\_a)。这样的话,不仅可以实现父组件与单个子组件之间的数据同步,也可以实现父组件与多个子组件之间的数据同步。如下图所示,可以看到,父子组件针对ClassA类型的变量设置了双向同步,那么当子组件1中变量的属性c的值变化时,会通知父组件同步变化,而当父组件中属性c的值变化时,会通知所有子组件同步变化。 - -![](/images/application-dev/ui/figures/zh-cn_image_0000001251090821.png) - -然而,上述例子是针对某个数据对象进行的整体同步,而当开发者只想针对父组件中某个数据对象的部分信息进行同步时,使用@Link就不能满足要求。如果这些部分信息是一个类对象,就可以使用@ObjectLink配合@Observed来实现,如下图所示。 - -![](/images/application-dev/ui/figures/zh-cn_image_0000001206450834.png) - -## 设置要求 - -- @Observed 用于类,@ObjectLink 用于变量。 -- @ObjectLink装饰的变量类型必须为类(class type)。 - - 类要被@Observed装饰器所装饰。 - - 不支持简单类型参数,可以使用@Prop进行单向同步。 - -- @ObjectLink装饰的变量是不可变的(immutable)。 - - 属性的改动是被允许的,当改动发生时,如果同一个对象被多个@ObjectLink变量所引用,那么所有拥有这些变量的自定义组件都会被通知去重新渲染。 - -- @ObjectLink装饰的变量不可设置默认值。 - - 必须让父组件中有一个由@State、@Link、@StorageLink、@Provide或@Consume所装饰变量参与的TS表达式进行初始化。 - -- @ObjectLink装饰的变量是私有变量,只能在组件内访问。 - -## 示例 - -### 案例1 - -``` -@Observed -class ClassA { - public name : string; - public c: number; - constructor(c: number, name: string = 'OK') { - this.name = name; - this.c = c; - } -} - -class ClassB { - public a: ClassA; - constructor(a: ClassA) { - this.a = a; - } -} - -@Component -struct ViewA { - label : string = "ep1"; - @ObjectLink a : ClassA; - build() { - Column() { - Text(`ViewA [${this.label}]: a.c=${this.a.c}`) - .fontSize(20) - Button(`+1`) - .width(100) - .margin(2) - .onClick(() => { - this.a.c += 1; - }) - Button(`reset`) - .width(100) - .margin(2) - .onClick(() => { - this.a = new ClassA(0); // ERROR, this.a is immutable - }) - } - } -} - -@Entry -@Component -struct ViewB { - @State b : ClassB = new ClassB(new ClassA(10)); - build() { - Flex({direction: FlexDirection.Column, alignItems: ItemAlign.Center}) { - ViewA({label: "ViewA #1", a: this.b.a}) - ViewA({label: "ViewA #2", a: this.b.a}) - - Button(`ViewB: this.b.a.c += 1` ) - .width(320) - .margin(4) - .onClick(() => { - this.b.a.c += 1; - }) - Button(`ViewB: this.b.a = new ClassA(0)`) - .width(240) - .margin(4) - .onClick(() => { - this.b.a = new ClassA(0); - }) - Button(`ViewB: this.b = new ClassB(ClassA(0))`) - .width(240) - .margin(4) - .onClick(() => { - this.b = new ClassB(new ClassA(0)); - }) - } - } -} -``` - -### 案例2 - -``` -var nextID: number = 0; -@Observed -class ClassA { - public name : string; - public c: number; - public id : number; - constructor(c: number, name: string = 'OK') { - this.name = name; - this.c = c; - this.id = nextID++; - } -} - -@Component -struct ViewA { - label : string = "ViewA1"; - @ObjectLink a: ClassA; - build() { - Row() { - Button(`ViewA [${this.label}] this.a.c= ${this.a.c} +1`) - .onClick(() => { - this.a.c += 1; - }) - } - } -} - -@Entry -@Component -struct ViewB { - @State arrA : ClassA[] = [ new ClassA(0), new ClassA(0) ]; - build() { - Column() { - ForEach (this.arrA, (item) => { - ViewA({label: `#${item.id}`, a: item}) - }, - (item) => item.id.toString() - ) - ViewA({label: `ViewA this.arrA[first]`, a: this.arrA[0]}) - ViewA({label: `ViewA this.arrA[last]`, a: this.arrA[this.arrA.length-1]}) - - Button(`ViewB: reset array`) - .onClick(() => { - this.arrA = [ new ClassA(0), new ClassA(0) ]; - }) - Button(`ViewB: push`) - .onClick(() => { - this.arrA.push(new ClassA(0)) - }) - Button(`ViewB: shift`) - .onClick(() => { - this.arrA.shift() - }) - } - } -} -``` - diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/03.UI\347\212\266\346\200\201\347\256\241\347\220\206/04.\345\205\266\344\273\226\347\261\273\347\233\256\347\232\204\347\212\266\346\200\201\347\256\241\347\220\206/02.Consume\345\222\214Provide\346\225\260\346\215\256\347\256\241\347\220\206.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/03.UI\347\212\266\346\200\201\347\256\241\347\220\206/04.\345\205\266\344\273\226\347\261\273\347\233\256\347\232\204\347\212\266\346\200\201\347\256\241\347\220\206/02.Consume\345\222\214Provide\346\225\260\346\215\256\347\256\241\347\220\206.md" deleted file mode 100644 index 41bda27b356d6aa744b0005d0bf9133a4df56f7c..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/03.UI\347\212\266\346\200\201\347\256\241\347\220\206/04.\345\205\266\344\273\226\347\261\273\347\233\256\347\232\204\347\212\266\346\200\201\347\256\241\347\220\206/02.Consume\345\222\214Provide\346\225\260\346\215\256\347\256\241\347\220\206.md" +++ /dev/null @@ -1,118 +0,0 @@ ---- -title: Consume和Provide数据管理 -permalink: /pages/0108020303030402 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# @Consume和@Provide数据管理 - -Provide作为数据的提供方,可以更新其子孙节点的数据,并触发页面渲染。Consume在感知到Provide数据的更新后,会触发当前view的重新渲染。 - -**表 1** @Provide - - - - - - - - - - - - - - - - - - - -

名称

-

说明

-

装饰器参数

-

是一个string类型的常量,用于给装饰的变量起别名。如果规定别名,则提供对应别名的数据更新。如果没有,则使用变量名作为别名。推荐使用@Provide("alias")这种形式。

-

同步机制

-

@Provide的变量类似@state,可以修改对应变量进行页面重新渲染。也可以修改@Consume装饰的变量,反向修改@State变量。

-

初始值

-

必须制定初始值。

-

页面重渲染场景

-

触发页面渲染的修改:

-
  • 基础类型(boolean,string,number)的改变;
  • @Observed class类型变量及其属性的修改;
  • 添加,删除,更新数组中的元素。
-
- -**表 2** @Consume - - - - - - - - - - -

类型

-

说明

-

初始值

-

不可设置默认值。

-
- ->![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** ->使用@Provide 和@Consume时避免循环引用导致死循环。 - -其他属性说明与Provide一致。 - -``` -@Entry -@Component -struct CompA { - @Provide("reviewVote") reviewVotes : number = 0; - - build() { - Column() { - CompB() - Button() { - Text(`${this.reviewVotes}`) - .fontSize(30) - } - .onClick(() => { - this.reviewVotes += 1; - }) - } - } -} - -@Component -struct CompB { - build() { - Column() { - CompC() - } - } -} - -@Component -struct CompC { - @Consume("reviewVote") reviewVotes : number; - build() { - Column() { - Button() { - Text(`${this.reviewVotes}`) - .fontSize(30) - } - .onClick(() => { - this.reviewVotes += 1; - }) - } - } -} -``` - diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/03.UI\347\212\266\346\200\201\347\256\241\347\220\206/04.\345\205\266\344\273\226\347\261\273\347\233\256\347\232\204\347\212\266\346\200\201\347\256\241\347\220\206/03.Watch.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/03.UI\347\212\266\346\200\201\347\256\241\347\220\206/04.\345\205\266\344\273\226\347\261\273\347\233\256\347\232\204\347\212\266\346\200\201\347\256\241\347\220\206/03.Watch.md" deleted file mode 100644 index 57e1f396ef8700302220eb34d9fbd8b666aa869a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/03.UI\347\212\266\346\200\201\347\256\241\347\220\206/04.\345\205\266\344\273\226\347\261\273\347\233\256\347\232\204\347\212\266\346\200\201\347\256\241\347\220\206/03.Watch.md" +++ /dev/null @@ -1,55 +0,0 @@ ---- -title: Watch -permalink: /pages/0108020303030403 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# @Watch - -@Watch用于监听状态变量的变化,语法结构为: - -``` -@State @Watch("onChanged") count : number = 0 -``` - -如上给状态变量增加一个@Watch装饰器,通过@Watch注册一个回调方法onChanged, 当状态变量count被改变时, 触发onChanged回调。 - -装饰器@State, @Prop, @Link, @ObjectLink, @Provide, @Consume, @StorageProp以及 @StorageLink装饰的变量可以监听其变化。 - -``` -@Entry -@Component -struct CompA { - @State @Watch("onBasketUpdated") shopBasket : Array = [ 7, 12, 47, 3 ]; - @State totalPurchase : number = 0; - - updateTotal() : number { - let sum = 0; - this.shopBasket.forEach((i) => { sum += i; }); - // calculate new total shop basket value and apply discount if over 100RMB - this.totalPurchase = (sum < 100) ? sum : 0.9 * sum; - return this.totalPurchase; - } - - // @Watch cb - onBasketUpdated(propName: string) : void { - this.updateTotal(); - } - - build() { - Column() { - Button("add to basket").onClick(() => { this.shopBasket.push(Math.round(100 * Math.random())) }) - Text(`${this.totalPurchase}`) - .fontSize(30) - } - } -} -``` - diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/04.\346\270\262\346\237\223\346\216\247\345\210\266\350\257\255\346\263\225/01.\346\235\241\344\273\266\346\270\262\346\237\223.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/04.\346\270\262\346\237\223\346\216\247\345\210\266\350\257\255\346\263\225/01.\346\235\241\344\273\266\346\270\262\346\237\223.md" deleted file mode 100644 index b30cf2968742d0cc39f2845e06ef0dbe23873b13..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/04.\346\270\262\346\237\223\346\216\247\345\210\266\350\257\255\346\263\225/01.\346\235\241\344\273\266\346\270\262\346\237\223.md" +++ /dev/null @@ -1,51 +0,0 @@ ---- -title: 条件渲染 -permalink: /pages/01080203030401 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# 条件渲染 - -使用**if/else**进行条件渲染。 - ->![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** ->- if条件语句可以使用状态变量。 ->- 使用if可以使子组件的渲染依赖条件语句。 ->- 必须在容器组件内使用。 ->- 某些容器组件限制子组件的类型或数量。将if放置在这些组件内时,这些限制将应用于if和else语句内创建的组件。例如,Grid组件的子组件仅支持GridItem组件,在Grid组件内使用if时,则if条件语句内仅允许使用GridItem组件。 - -## 示例 - -使用if条件语句: - -``` -Column() { - if (this.count > 0) { - Text('count is positive') - } -} -``` - -使用if、else if、else条件语句: - -``` -Column() { - if (this.count < 0) { - Text('count is negative') - } else if (this.count % 2 === 0) { - Divider() - Text('even') - } else { - Divider() - Text('odd') - } -} -``` - diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/04.\346\270\262\346\237\223\346\216\247\345\210\266\350\257\255\346\263\225/02.\345\276\252\347\216\257\346\270\262\346\237\223.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/04.\346\270\262\346\237\223\346\216\247\345\210\266\350\257\255\346\263\225/02.\345\276\252\347\216\257\346\270\262\346\237\223.md" deleted file mode 100644 index 0f0678f57cdb35f33eefbbf9469212b68263fd69..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/04.\346\270\262\346\237\223\346\216\247\345\210\266\350\257\255\346\263\225/02.\345\276\252\347\216\257\346\270\262\346\237\223.md" +++ /dev/null @@ -1,188 +0,0 @@ ---- -title: 循环渲染 -permalink: /pages/01080203030402 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# 循环渲染 - -开发框架提供**循环渲染(**ForEach组件)来迭代数组,并为每个数组项创建相应的组件。**ForEach**定义如下: - -``` -ForEach( - arr: any[], // Array to be iterated - itemGenerator: (item: any, index?: number) => void, // child component generator - keyGenerator?: (item: any, index?: number) => string // (optional) Unique key generator, which is recommended. -) -``` - -## ForEach - -ForEach\(arr: any\[\],itemGenerator: \(item: any, index?: number\) =\> void, keyGenerator?: \(item: any, index?: number\) =\> string\):void - -**表 1** 参数说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

arr

-

any[]

-

-

-

-

必须是数组,允许空数组,空数组场景下不会创建子组件。同时允许设置返回值为数组类型的函数,例如arr.slice(1, 3),设置的函数不得改变包括数组本身在内的任何状态变量,如Array.spliceArray.sortArray.reverse这些改变原数组的函数。

-

itemGenerator

-

(item: any, index?: number) => void

-

-

-

-

生成子组件的lambda函数,为给定数组项生成一个或多个子组件,单个组件和子组件列表必须括在大括号“{....}”中。

-

keyGenerator

-

(item: any, index?: number) => string

-

-

-

-

匿名参数,用于给定数组项生成唯一且稳定的键值。当子项在数组中的位置更改时,子项的键值不得更改,当数组中的子项被新项替换时,被替换项的键值和新项的键值必须不同。键值生成器的功能是可选的,但是,为了使开发框架能够更好地识别数组更改,提高性能,建议提供。如将数组反向时,如果没有提供键值生成器,则ForEach中的所有节点都将重建

-
- ->![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** ->- 必须在容器组件内使用; ->- 生成的子组件允许在**ForEach**的父容器组件中,允许子组件生成器函数中包含**if/else**条件渲染,同时也允许**ForEach**包含在**if/else**条件渲染语句中; ->- 子项生成器函数的调用顺序不一定和数组中的数据项相同,在开发过程中不要假设子项生成器和键值生成器函数是否执行以及执行顺序。如下示例可能无法正常工作: -> ``` -> ForEach(anArray, item => {Text(`${++counter}. item.label`)}) -> ``` -> 正确的示例如下: -> ``` -> ForEach(anArray.map((item1, index1) => { return { i: index1 + 1, data: item1 }; }), -> item => Text(`${item.i}. item.data.label`), -> item => item.data.id.toString()) -> ``` - -## 示例 - -简单类型数组示例: - -``` -@Entry -@Component -struct MyComponent { - @State arr: number[] = [10, 20, 30] - build() { - Column() { - Button() { - Text('Reverse Array') - }.onClick(() => { - this.arr.reverse() - }) - - ForEach(this.arr, // Parameter 1: array to be iterated - (item: number) => { // Parameter 2: item generator - Text(`item value: ${item}`) - Divider() - }, - (item: number) => item.toString() // Parameter 3: unique key generator, which is optional but recommended. - ) - } - } -} -``` - -复杂类型数组示例: - -``` -class Month { - year: number - month: number - days: Array - - constructor(year, month, days) { - this.year = year; - this.month = month; - this.days = days; - } -} - -@Entry -@Component -struct Calendar1 { -// simulate with 6 months - @State calendar: Month[] = [ - new Month(2020, 1, [...Array(31).keys()]), - new Month(2020, 2, [...Array(28).keys()]), - new Month(2020, 3, [...Array(31).keys()]), - new Month(2020, 4, [...Array(30).keys()]), - new Month(2020, 5, [...Array(31).keys()]), - new Month(2020, 6, [...Array(30).keys()]), - ] - - build() { - Column() { - Button('next month') - .onClick(() => { - this.calendar.shift() - this.calendar.push({ - year: 2020, - month: 7, - days: [...Array(31) - .keys()] - }) - }) - ForEach(this.calendar, - (item: Month) => { - Text('month:' + item.month) - .fontSize(30) - .padding(20) - Grid() { - ForEach(item.days, - (day: number) => { - GridItem() { - Text((day + 1).toString()) - .fontSize(30) - } - }, - (day: number) => day.toString()) - } - .columnsTemplate('1fr 1fr 1fr 1fr 1fr 1fr 1fr') - .rowsGap(20) - }, - // field is used together with year and month as the unique ID of the month. - (item: Month) => (item.year * 12 + item.month).toString()) - } - } -} -``` - diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/04.\346\270\262\346\237\223\346\216\247\345\210\266\350\257\255\346\263\225/03.\346\225\260\346\215\256\346\207\222\345\212\240\350\275\275.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/04.\346\270\262\346\237\223\346\216\247\345\210\266\350\257\255\346\263\225/03.\346\225\260\346\215\256\346\207\222\345\212\240\350\275\275.md" deleted file mode 100644 index ae6b4ff451bfce57d8227ed6a231170f00bb7d57..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/04.\346\270\262\346\237\223\346\216\247\345\210\266\350\257\255\346\263\225/03.\346\225\260\346\215\256\346\207\222\345\212\240\350\275\275.md" +++ /dev/null @@ -1,280 +0,0 @@ ---- -title: 数据懒加载 -permalink: /pages/01080203030403 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# 数据懒加载 - -开发框架提供**数据懒加载**(LazyForEach组件)从提供的数据源中按需迭代数据,并在每次迭代过程中创建相应的组件。**LazyForEach**定义如下: - -``` -LazyForEach( - dataSource: IDataSource, // Data source to be iterated - itemGenerator: (item: any) => void, // child component generator - keyGenerator?: (item: any) => string // (optional) Unique key generator, which is recommended. -): void - -interface IDataSource { - totalCount(): number; // Get total count of data - getData(index: number): any; // Get single data by index - registerDataChangeListener(listener: DataChangeListener): void; // Register listener to listening data changes - unregisterDataChangeListener(listener: DataChangeListener): void; // Unregister listener -} - -interface DataChangeListener { - onDataReloaded(): void; // Called while data reloaded - onDataAdded(index: number): void; // Called while single data added - onDataMoved(from: number, to: number): void; // Called while single data moved - onDataDeleted(index: number): void; // Called while single data deleted - onDataChanged(index: number): void; // Called while single data changed -} -``` - -## 接口 - -### LazyForEach - -LazyForEach\(dataSource: IDataSource, itemGenerator: \(item: any\) =\> void, keyGenerator?: \(item: any\) =\> string\):void - -**表 1** 参数说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

dataSource

-

IDataSource

-

-

-

-

实现IDataSource接口的对象,需要开发者实现相关接口。

-

itemGenerator

-

(item: any) => void

-

-

-

-

生成子组件的lambda函数,为给定数组项生成一个或多个子组件,单个组件和子组件列表必须括在大括号“{....}”中。

-

keyGenerator

-

(item: any) => string

-

-

-

-

匿名函数,用于键值生成,为给定数组项生成唯一且稳定的键值。当子项在数组中的位置更改时,子项的键值不得更改,当数组中的子项被新项替换时,被替换项的键值和新项的键值必须不同。键值生成器的功能是可选的,但是,为了使开发框架能够更好地识别数组更改,提高性能,建议提供。如将数组反向时,如果没有提供键值生成器,则LazyForEach中的所有节点都将重建。

-
- -**表 2** IDataSource类型说明 - - - - - - - - - - - - - - - - - - - -

名称

-

描述

-

totalCount(): number

-

获取数据总数。

-

getData(index: number): any

-

获取索引对应的数据。

-

registerDataChangeListener(listener: DataChangeListener): void

-

注册改变数据的控制器。

-

unregisterDataChangeListener(listener: DataChangeListener): void

-

注销改变数据的控制器。

-
- -**表 3** DataChangeListener类型说明 - - - - - - - - - - - - - - - - - - - - - - -

名称

-

描述

-

onDataReloaded(): void

-

重新加载所有数据。

-

onDataAdded(index: number): void

-

通知组件index的位置有数据添加。

-

onDataMoved(from: number, to: number): void

-

通知组件数据从from的位置移到to的位置。

-

onDataDeleted(index: number): void

-

通知组件index的位置有数据删除。

-

onDataChanged(index: number): void

-

通知组件index的位置有数据变化。

-
- ->![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** ->- 数据懒加载必须在容器组件内使用,且仅有List、Grid以及Swiper组件支持数据的懒加载(即只加载可视部分以及其前后少量数据用于缓冲),其他组件仍然是一次加载所有的数据; ->- **LazyForEach**在每次迭代中,必须且只允许创建一个子组件; ->- 生成的子组件必须允许在**LazyForEach**的父容器组件中; ->- 允许**LazyForEach**包含在**if/else**条件渲染语句中,不允许**LazyForEach**中出现**if/else**条件渲染语句; ->- 为了高性能渲染,通过DataChangeListener对象的onDataChanged方法来更新UI时,仅itemGenerator中的UI描述的组件内使用了状态变量时,才会触发组件刷新; ->- 子项生成器函数的调用顺序不一定和数据源中的数据项相同,在开发过程中不要假设子项生成器和键值生成器函数是否执行以及执行顺序。如下示例可能无法正常工作: -> ``` -> LazyForEach(dataSource, item => {Text(`${++counter}. item.label`)}) -> ``` -> 正确的示例如下: -> ``` -> LazyForEach(dataSource, -> item => Text(`${item.i}. item.data.label`)), -> item => item.data.id.toString()) -> ``` - -## 示例 - -``` -// Basic implementation of IDataSource to handle data listener -class BasicDataSource implements IDataSource { - private listeners: DataChangeListener[] = [] - - public totalCount(): number { - return 0 - } - public getData(index: number): any { - return undefined - } - - registerDataChangeListener(listener: DataChangeListener): void { - if (this.listeners.indexOf(listener) < 0) { - console.info('add listener') - this.listeners.push(listener) - } - } - unregisterDataChangeListener(listener: DataChangeListener): void { - const pos = this.listeners.indexOf(listener); - if (pos >= 0) { - console.info('remove listener') - this.listeners.splice(pos, 1) - } - } - - notifyDataReload(): void { - this.listeners.forEach(listener => { - listener.onDataReloaded() - }) - } - notifyDataAdd(index: number): void { - this.listeners.forEach(listener => { - listener.onDataAdded(index) - }) - } - notifyDataChange(index: number): void { - this.listeners.forEach(listener => { - listener.onDataChanged(index) - }) - } - notifyDataDelete(index: number): void { - this.listeners.forEach(listener => { - listener.onDataDeleted(index) - }) - } - notifyDataMove(from: number, to: number): void { - this.listeners.forEach(listener => { - listener.onDataMoved(from, to) - }) - } -} - -class MyDataSource extends BasicDataSource { - private dataArray: string[] = ['/path/image0', '/path/image1', '/path/image2', '/path/image3'] - - public totalCount(): number { - return this.dataArray.length - } - public getData(index: number): any { - return this.dataArray[index] - } - - public addData(index: number, data: string): void { - this.dataArray.splice(index, 0, data) - this.notifyDataAdd(index) - } - public pushData(data: string): void { - this.dataArray.push(data) - this.notifyDataAdd(this.dataArray.length - 1) - } -} - -@Entry -@Component -struct MyComponent { - private data: MyDataSource = new MyDataSource() - build() { - List({space: 3}) { - LazyForEach(this.data, (item: string) => { - ListItem() { - Row() { - Image(item).width("30%").height(50) - Text(item).fontSize(20).margin({left:10}) - }.margin({left: 10, right: 10}) - } - .onClick(()=>{ - this.data.pushData('/path/image' + this.data.totalCount()) - }) - }, item => item) - } - } -} -``` - diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/05.\346\267\261\345\205\245\347\220\206\350\247\243\347\273\204\344\273\266\345\214\226/01.build\345\207\275\346\225\260.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/05.\346\267\261\345\205\245\347\220\206\350\247\243\347\273\204\344\273\266\345\214\226/01.build\345\207\275\346\225\260.md" deleted file mode 100644 index 27bbc749721b334fc6c57ca4b2d4e9e3c4bb1a1c..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/05.\346\267\261\345\205\245\347\220\206\350\247\243\347\273\204\344\273\266\345\214\226/01.build\345\207\275\346\225\260.md" +++ /dev/null @@ -1,26 +0,0 @@ ---- -title: build函数 -permalink: /pages/01080203030501 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# build函数 - -**build**函数满足**Builder**构造器接口定义,用于定义组件的声明式UI描述。必须遵循上述**Builder**接口约束,在**build**方法中以声明式方式进行组合自定义组件或系统内置组件,在组件的第一次创建和更新场景中都会调用**build**方法。 - -``` -interface Builder { - build: () => void -} -``` - ->![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** ->build方法仅支持组合组件,使用渲染控制语法。 - diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/05.\346\267\261\345\205\245\347\220\206\350\247\243\347\273\204\344\273\266\345\214\226/02.\350\207\252\345\256\232\344\271\211\347\273\204\344\273\266\345\210\235\345\247\213\345\214\226.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/05.\346\267\261\345\205\245\347\220\206\350\247\243\347\273\204\344\273\266\345\214\226/02.\350\207\252\345\256\232\344\271\211\347\273\204\344\273\266\345\210\235\345\247\213\345\214\226.md" deleted file mode 100644 index efd08b04a8e864a3c7defa83e1854348defae4c6..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/05.\346\267\261\345\205\245\347\220\206\350\247\243\347\273\204\344\273\266\345\214\226/02.\350\207\252\345\256\232\344\271\211\347\273\204\344\273\266\345\210\235\345\247\213\345\214\226.md" +++ /dev/null @@ -1,248 +0,0 @@ ---- -title: 自定义组件初始化 -permalink: /pages/01080203030502 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# 自定义组件成员变量初始化 - -组件的成员变量可以通过两种方式初始化: - -- 本地初始化,例如: - - ``` - @State counter: Counter = new Counter() - ``` - -- 在构造组件时通过构造参数初始化,例如: - - ``` - MyComponent(counter: $myCounter) - ``` - - -具体允许哪种方式取决于状态变量的装饰器: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

装饰器类型

-

本地初始化

-

通过构造函数参数初始化

-

@State

-

必须

-

可选

-

@Prop

-

禁止

-

必须

-

@Link

-

禁止

-

必须

-

@StorageLink

-

必须

-

禁止

-

@StorageProp

-

必须

-

禁止

-

@Provide

-

必须

-

可选

-

@Consume

-

禁止

-

禁止

-

@ObjectLink

-

禁止

-

必须

-

常规成员变量

-

推荐

-

可选

-
- -从上表中可以看出: - -- **@State**变量需要本地初始化,初始化的值可以被构造参数覆盖; -- **@Prop**和**@Link**变量必须且仅通过构造函数参数进行初始化。 - -通过构造函数方法初始化成员变量,需要遵循如下规则: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

从父组件中的变量(下)到子组件中的变量(右)

-

@State

-

@Link

-

@Prop

-

常规变量

-

@State

-

不允许

-

允许

-

允许

-

允许

-

@Link

-

不允许

-

允许

-

不推荐

-

允许

-

@Prop

-

不允许

-

不允许

-

允许

-

允许

-

@StorageLink

-

不允许

-

允许

-

不允许

-

允许

-

@StorageProp

-

不允许

-

不允许

-

不允许

-

允许

-

常规变量

-

允许

-

不允许

-

不允许

-

允许

-
- -从上表中可以看出: - -- 父组件的常规变量可以用于初始化子组件的**@State**变量,但不能用于初始化**@Link**或**@Prop**变量; -- 父组件的**@State**变量可以初始化子组件的**@Prop**、**@Link(通过$)**或常规变量,但不能初始化子组件的**@State**变量; -- 父组件的**@Link**变量可以初始化子组件的@Link或常规变量。但是初始化子组件的**@State**成员是语法错误,此外不建议初始化**@prop;** -- 父组件的**@Prop**变量可以初始化子组件的常规变量或**@Prop**变量,但不能初始化子组件的**@State**或**@Link**变量。 -- @StorageLink和@StorageProp不允许由父组件中传递到子组件。 -- 除了上述规则外,还需要遵循TS的强类型规则。 - -## 示例 - -``` -@Entry -@Component -struct Parent { - @State parentState: ClassA = new ClassA() - build() { - Row() { - CompA({aState: new ClassA, aLink: $parentState}) // valid - CompA({aLink: $parentState}) // valid - CompA() // invalid, @Link aLink remains uninitialized - CompA({aLink: new ClassA}) // invalid, @Link aLink must be a reference ($) to either @State or @Link variable - } - } -} - -@Component -struct CompA { - @State aState: boolean = false // must initialize locally - @Link aLink: ClassA // must not initialize locally - - build() { - Row() { - CompB({bLink: $aLink, // valid init a @Link with reference of another @Link, - bProp: this.aState}) // valid init a @Prop with value of a @State - CompB({aLink: $aState, // invalid: type missmatch expected ref to ClassA, provided reference to boolean - bProp: false}) // valid init a @Prop by constants value - } - } -} - -@Component -struct CompB { - @Link bLink: ClassA = new ClassA() // invalid, must not initialize locally - @Prop bProp: boolean = false // invalid must not initialize locally - - build() { - ... - } -} -``` - diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/05.\346\267\261\345\205\245\347\220\206\350\247\243\347\273\204\344\273\266\345\214\226/03.\350\207\252\345\256\232\344\271\211\347\273\204\344\273\266\347\224\237\345\221\275\345\221\250\346\234\237\345\233\236\350\260\203\345\207\275\346\225\260.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/05.\346\267\261\345\205\245\347\220\206\350\247\243\347\273\204\344\273\266\345\214\226/03.\350\207\252\345\256\232\344\271\211\347\273\204\344\273\266\347\224\237\345\221\275\345\221\250\346\234\237\345\233\236\350\260\203\345\207\275\346\225\260.md" deleted file mode 100644 index 179dfd782616ece38ef590399f82c740118910e7..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/05.\346\267\261\345\205\245\347\220\206\350\247\243\347\273\204\344\273\266\345\214\226/03.\350\207\252\345\256\232\344\271\211\347\273\204\344\273\266\347\224\237\345\221\275\345\221\250\346\234\237\345\233\236\350\260\203\345\207\275\346\225\260.md" +++ /dev/null @@ -1,91 +0,0 @@ ---- -title: 自定义组件生命周期回调函数 -permalink: /pages/01080203030503 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# 自定义组件生命周期回调函数 - -自定义组件的生命周期回调函数用于通知用户该自定义组件的生命周期,这些回调函数是私有的,在运行时由开发框架在特定的时间进行调用,不能从应用程序中手动调用这些回调函数。 - -## 生命周期回调函数定义 - - - - - - - - - - - - - - - - - - - - - - -

函数名

-

描述

-

aboutToAppear

-

函数在创建自定义组件的新实例后,在执行其build函数之前执行。允许在aboutToAppear函数中改变状态变量,更改将在后续执行build函数中生效。

-

aboutToDisappear

-

函数在自定义组件析构消耗之前执行。不允许在aboutToDisappear函数中改变状态变量,特别是@Link变量的修改可能会导致应用程序行为不稳定。

-

onPageShow

-

页面显示时触发一次,包括路由过程、应用进入前后台等场景,仅@Entry修饰的自定义组件生效。

-

onPageHide

-

页面消失时触发一次,包括路由过程、应用进入前后台等场景,仅@Entry修饰的自定义组件生效。

-

onBackPress

-

当用户点击返回按钮时触发,仅@Entry修饰的自定义组件生效。

-
  • 返回true表示页面自己处理返回逻辑, 不进行页面路由。
  • 返回false表示使用默认的返回逻辑。
  • 不返回值会作为false处理。
-
- -## 示例 - -``` -@Component -struct CountDownTimerComponent { - @State countDownFrom: number = 10 - private timerId: number = -1 - - private aboutToAppear(): void { - this.timerId = setInterval(() => { - if (this.countDownFrom <= 1) { - clearTimeout(this.timerId) - } - this.countDownFrom -= 1 - }, 1000) // decr counter by 1 every second - } - - private aboutToDisappear(): void { - if (this.timerId > 0) { - clearTimeout(this.timerId) - this.timerId = -1 - } - } - - build() { - Text(`${this.countDownFrom} sec left`) - } -} -``` - -上述示例表明,生命周期函数对于允许CountDownTimerComponent管理其计时器资源至关重要,类似的函数也包括异步从网络请求加载资源。 - ->![icon-note.gif](/images/application-dev/ui/public_sys-resources/icon-note.gif) **说明:** ->- 允许在生命周期函数中使用**Promise**和异步回调函数,比如网络资源获取,定时器设置等; ->- 不允许在生命周期函数中使用**async await**。 - diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/05.\346\267\261\345\205\245\347\220\206\350\247\243\347\273\204\344\273\266\345\214\226/04.\347\273\204\344\273\266\345\210\233\345\273\272\345\222\214\351\207\215\346\226\260\345\210\235\345\247\213\345\214\226\347\244\272\344\276\213.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/05.\346\267\261\345\205\245\347\220\206\350\247\243\347\273\204\344\273\266\345\214\226/04.\347\273\204\344\273\266\345\210\233\345\273\272\345\222\214\351\207\215\346\226\260\345\210\235\345\247\213\345\214\226\347\244\272\344\276\213.md" deleted file mode 100644 index b1db4cac05398cd4fd33e6250ded2b1b5d48d85b..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/05.\346\267\261\345\205\245\347\220\206\350\247\243\347\273\204\344\273\266\345\214\226/04.\347\273\204\344\273\266\345\210\233\345\273\272\345\222\214\351\207\215\346\226\260\345\210\235\345\247\213\345\214\226\347\244\272\344\276\213.md" +++ /dev/null @@ -1,102 +0,0 @@ ---- -title: 组件创建和重新初始化示例 -permalink: /pages/01080203030504 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# 组件创建和重新初始化示例 - -``` -@Entry -@Component -struct ParentComp { - @State isCountDown: boolean = true - build() { - Column() { - Text(this.isCountDown ? 'Count Down' : 'Stopwatch') - if (this.isCountDown) { - Image('countdown.png') - TimerComponent({counter: 10, changePerSec: -1, showInColor: Color.Red}) - } else { - Image('stopwatch.png') - TimerComponent({counter: 0, changePerSec: +1, showInColor: Color.Black }) - } - Button(this.isCountDown ? 'Swtich to Stopwatch' : 'Switch to Count Down') - .onClick(() => {this.isCountDown = !this.isCountDown}) - } - } -} - -// Manage and display a count down / stop watch timer -@Component -struct TimerComponent { - @State counter: number = 0 - private changePerSec: number = -1 - private showInColor: Color = Color.Black - private timerId : number = -1 - - build() { - Text(`${this.counter}sec`) - .fontColor(this.showInColor) - } - - aboutToAppear() { - this.timerId = setInterval(() => {this.counter += this.changePerSec}, 1000) - } - - aboutToDisappear() { - if (this.timerId > 0) { - clearTimeout(this.timerId) - this.timerId = -1 - } - } -} -``` - -## 初始创建和渲染 - -1. 创建父组件**ParentComp**; -2. 本地初始化**ParentComp**的状态变量**isCountDown**; -3. 执行**ParentComp**的**build**函数; -4. 创建**Column**内置组件; - 1. 创建**Text**内置组件,设置其文本展示内容,并将**Text**组件实例添加到**Column**中; - 2. 判断if条件,创建**true**分支上的组件; - 1. 创建**Image**内置组件,并设置其图片源地址; - 2. 使用给定的构造函数创建**TimerComponent**; - 1. 创建**TimerComponent**对象; - 2. 本地初始化成员变量初始值; - 3. 使用**TimerComponent**构造函数提供的参数更新成员变量的值; - 4. 执行**TimerComponent**的**aboutToAppear**函数; - 5. 执行**TimerComponent**的**build**函数,创建相应的UI描述结构; - - 3. 创建**Button**内置组件,设置相应的内容。 - - -## 状态更新 - -用户单击按钮时: - -1. **ParentComp**的**isCountDown**状态变量的值更改为false; -2. 执行**ParentComp**的**build**函数; -3. **Column**内置组件会被框架重用并执行重新初始化; -4. **Column**的子组件会重用内存中的对象,但会进行重新初始化; - 1. **Text**内置组件会被重用,但使用新的文本内容进行重新初始化; - 2. 判断if条件,使用false分支上的组件; - 1. 原来true分支上的组件不在使用,这些组件会进行销毁; - 1. 创建的**Image**内置组件实例进行销毁; - 2. **TimerComponent**组件实例进行销毁,**aboutToDisappear**函数被调用; - - 2. 创建false分支上的组件; - 1. 创建**Image**内置组件,并设置其图片源地址; - 2. 使用给定的构造函数重新创建**TimerComponent**; - 3. 新创建的**TimerComponent**进行初始化,并调用**aboutToAppear**函数和**build**函数。 - - 3. **Button**内置组件会被重用,但使用新的图片源地址。 - diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/06.\350\257\255\346\263\225\347\263\226/01.\350\243\205\351\245\260\345\231\250.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/06.\350\257\255\346\263\225\347\263\226/01.\350\243\205\351\245\260\345\231\250.md" deleted file mode 100644 index c36649c36f7f9a043716f024332c0752ac7865c1..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/06.\350\257\255\346\263\225\347\263\226/01.\350\243\205\351\245\260\345\231\250.md" +++ /dev/null @@ -1,61 +0,0 @@ ---- -title: 装饰器 -permalink: /pages/01080203030601 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# 装饰器 - -装饰器**@Decorator**,被装饰的元素可以是变量声明,类定义,结构体定义,方法定义等,赋予其特殊的含义。 - - -多个装饰器实现可以叠加到目标元素,书写在同一行上或者在多行上,推荐书写在多行上。 - - -如下**@Component**和**@State**的使用,被**@Component**装饰的元素具备了组件化的含义,使用**@State**装饰的变量具备了状态数据的含义: - - -``` -@Component -struct MyComponent { - @State count: number = 0 -} -``` - - -装饰器可以书写在同一行上: - - -``` -@Entry @Component struct MyComponent { -} -``` - - -但更推荐书写在多行上: - - -``` -@Entry -@Component -struct MyComponent { -} -``` - - -## 支持的装饰器列表 - -| 装饰器 | 装饰内容 | 说明 | -| -------- | -------- | -------- | -| @Component | struct | 结构体在装饰后具有基于组件的能力,需要实现**build**方法来更新UI。 | -| @Entry | struct | 组件被装饰后作为页面的入口,页面加载时将被渲染显示。 | -| @State | 基本数据类型,类,数组 | 修饰的状态数据被修改时会触发组件的**build**方法进行UI界面更新。 | -| @Prop | 基本数据类型 | 修改后的状态数据用于在父组件和子组件之间建立单向数据依赖关系。修改父组件关联数据时,更新当前组件的UI。 | -| @Link | 基本数据类型,类,数组 | 父子组件之间的双向数据绑定。父组件的内部状态数据作为数据源。任何一方所做的修改都会反映给另一方。 | diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/06.\350\257\255\346\263\225\347\263\226/02.\351\223\276\345\274\217\350\260\203\347\224\250.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/06.\350\257\255\346\263\225\347\263\226/02.\351\223\276\345\274\217\350\260\203\347\224\250.md" deleted file mode 100644 index 3b7dfc6b87a7eec7de3569b0c4c8e0c09ed7a333..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/06.\350\257\255\346\263\225\347\263\226/02.\351\223\276\345\274\217\350\260\203\347\224\250.md" +++ /dev/null @@ -1,28 +0,0 @@ ---- -title: 链式调用 -permalink: /pages/01080203030602 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# 链式调用 - - - -允许开发者以“.”链式调用的方式配置UI结构及其属性、事件等。 - - -``` -Column() { - Image('1.jpg') - .alt('error.jpg') - .width(100) - .height(100) -}.padding(10) -``` diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/06.\350\257\255\346\263\225\347\263\226/03.struct\345\257\271\350\261\241.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/06.\350\257\255\346\263\225\347\263\226/03.struct\345\257\271\350\261\241.md" deleted file mode 100644 index 67e2894d058707764c549a74697904617d1dc81d..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/06.\350\257\255\346\263\225\347\263\226/03.struct\345\257\271\350\261\241.md" +++ /dev/null @@ -1,29 +0,0 @@ ---- -title: struct对象 -permalink: /pages/01080203030603 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# struct对象 - - - -组件可以基于**struct**实现,组件不能有继承关系,**struct**可以比**class**更加快速的创建和销毁。 - - -``` -@Component -struct MyComponent { - @State data: string = '' - - build() { - } -} -``` diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/06.\350\257\255\346\263\225\347\263\226/04.\345\234\250\345\256\236\344\276\213\345\214\226\350\277\207\347\250\213\344\270\255\347\234\201\347\225\245new.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/06.\350\257\255\346\263\225\347\263\226/04.\345\234\250\345\256\236\344\276\213\345\214\226\350\277\207\347\250\213\344\270\255\347\234\201\347\225\245new.md" deleted file mode 100644 index 1542e9f0f2bcc48a5c220e115c0a9a2ab2cb6a8a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/06.\350\257\255\346\263\225\347\263\226/04.\345\234\250\345\256\236\344\276\213\345\214\226\350\277\207\347\250\213\344\270\255\347\234\201\347\225\245new.md" +++ /dev/null @@ -1,38 +0,0 @@ ---- -title: 在实例化过程中省略new -permalink: /pages/01080203030604 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# 在实例化过程中省略"new" - - - -对于**struct**的实例化,可以省略**new**。 - - -``` -// 定义 -@Component -struct MyComponent { - build() { - } -} - -// 使用 -Column() { - MyComponent() -} - -// 等价于 -new Column() { - new MyComponent() -} -``` diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/06.\350\257\255\346\263\225\347\263\226/05.\347\273\204\344\273\266\345\210\233\345\273\272\344\275\277\347\224\250\347\213\254\347\253\213\344\270\200\350\241\214.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/06.\350\257\255\346\263\225\347\263\226/05.\347\273\204\344\273\266\345\210\233\345\273\272\344\275\277\347\224\250\347\213\254\347\253\213\344\270\200\350\241\214.md" deleted file mode 100644 index 2d21960f9b1039571df7f9c73da2c89ecb5e40b8..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/06.\350\257\255\346\263\225\347\263\226/05.\347\273\204\344\273\266\345\210\233\345\273\272\344\275\277\347\224\250\347\213\254\347\253\213\344\270\200\350\241\214.md" +++ /dev/null @@ -1,74 +0,0 @@ ---- -title: 组件创建使用独立一行 -permalink: /pages/01080203030605 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# 组件创建使用独立一行 - - - -**每行代码末尾可以省略分号";"** - - -``` -Column() { - Image('icon.png') - Text('text') -} -``` - - -等同于: - - -``` -Column() { - Image('icon.png'); - Text('text'); -} -``` - - -**每行只允许创建一个组件。if, else, else if, ForEach语句单独一行。** - - -无效示例: - - -``` -Column() { - Image('icon.png') Text('text') // invalid, creation of two components in same line -} - -if (this.condi) {Image('icon.png')} // invalid, if and creation a components in same line -``` - - -**内置容器组件、if和ForEach项生成器函数必须在单个子项的情况下使用封闭括号"{}"。** - - -无效示例: - - -``` -if (this.condi) -Image('icon.png'), // invalid, missing {} -else - Text('text'); -``` - - -``` -ForEach(this.arr, - (item) => Image('icon.png'), // invalid, missing {} - (item) => item.id.toString() -} -``` diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/06.\350\257\255\346\263\225\347\263\226/06.\347\224\237\346\210\220\345\231\250\345\207\275\346\225\260\345\206\205\344\275\277\347\224\250TS\350\257\255\350\250\200\347\232\204\351\231\220\345\210\266.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/06.\350\257\255\346\263\225\347\263\226/06.\347\224\237\346\210\220\345\231\250\345\207\275\346\225\260\345\206\205\344\275\277\347\224\250TS\350\257\255\350\250\200\347\232\204\351\231\220\345\210\266.md" deleted file mode 100644 index 9074350b08e3b6d465fc558a7b08f9c9c4e7c020..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\243\260\346\230\216\345\274\217\350\257\255\346\263\225/06.\350\257\255\346\263\225\347\263\226/06.\347\224\237\346\210\220\345\231\250\345\207\275\346\225\260\345\206\205\344\275\277\347\224\250TS\350\257\255\350\250\200\347\232\204\351\231\220\345\210\266.md" +++ /dev/null @@ -1,47 +0,0 @@ ---- -title: 生成器函数内使用TS语言的限制 -permalink: /pages/01080203030606 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# 生成器函数内使用TS语言的限制 - - - -TS语言的使用在生成器函数中存在一定的限制: - - -- 表达式仅允许在字符串(${expression})、if条件、ForEach的参数和组件的参数中使用; - -- 这些表达式中的任何一个都不能导致任何应用程序状态变量(@State、@Link、@Prop)的改变,否则会导致未定义和潜在不稳定的框架行为; - -- 允许在生成器函数体的第一行使用console.log,以便开发人员更容易跟进组件重新渲染。对日志字符串文字中表达式仍遵循上述限制。 - -- 生成器函数内部不能有局部变量。 - - -上述限制都不适用于事件处理函数(例如**onClick**)的匿名函数实现,它们也不适用于UI组件描述外的其余部分。 - - -非法示例: - - -``` -build() { - let a: number = 1 // invalid: variable declaration not allowed - console.log(`a: ${a}`) // invalid: console.log only allowed in first line of build - Column() { - Text('Hello ${this.myName.toUpperCase()}') // ok. - ForEach(this.arr.reverse(), ..., ...) // invalid: Array.reverse modifies the @State array varible in place - } - buildSpecial() // invalid: no function calls - Text(this.calcTextValue()) // this function call is ok. -} -``` diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/04.\344\275\223\351\252\214\345\243\260\346\230\216\345\274\217UI/01.\345\210\233\345\273\272\345\243\260\346\230\216\345\274\217UI\345\267\245\347\250\213.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/04.\344\275\223\351\252\214\345\243\260\346\230\216\345\274\217UI/01.\345\210\233\345\273\272\345\243\260\346\230\216\345\274\217UI\345\267\245\347\250\213.md" deleted file mode 100644 index 307f4b20e2d193e9248c86a2694bd19bfe8d4afa..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/04.\344\275\223\351\252\214\345\243\260\346\230\216\345\274\217UI/01.\345\210\233\345\273\272\345\243\260\346\230\216\345\274\217UI\345\267\245\347\250\213.md" +++ /dev/null @@ -1,79 +0,0 @@ ---- -title: 创建声明式UI工程 -permalink: /pages/010802030401 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# 创建声明式UI工程 - - - -创建工程之前,首先需要安装DevEco Studio,[下载安装教程](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/tools_overview-0000001053582387)。 - - -1. 打开DevEco Studio,点击Create Project。如果已有一个工程,则点击File > New > New project。 - ![zh-cn_image_0000001168956332](/images/application-dev/ui/figures/zh-cn_image_0000001168956332.png) - -2. - 进入选择ability template界面,选择[Standard]Empty Ability。 - - ![zh-cn_image_0000001168059158](/images/application-dev/ui/figures/zh-cn_image_0000001168059158.png) - -3. - 安装OpenHarmony SDK。 - - ![zh-cn_image_0000001213462329](/images/application-dev/ui/figures/zh-cn_image_0000001213462329.png) - -4. 进入配置工程界面,将工程名字改为HealthyDiet,Project Type选择Application,Device Type选择Phone,Language选择eTS,选择兼容API Version 7。DevEco Studio会默认将工程保存在C盘,如果要更改工程保存位置,点击Save Location的文件夹图标,自行指定工程创建位置。配置完成后点击Finish。 - - - ![zh-cn_image_0000001167746622](/images/application-dev/ui/figures/zh-cn_image_0000001167746622.png) - -5. 工程创建完成后,打开app.ets。 - app.ets提供了应用生命周期的接口:onCreate和onDestroy,分别在应用创建之初和应用被销毁时调用。在app.ets里可以声明全局变量,并且声明的数据和方法是整个应用共享的。 - ``` - export default { - onCreate() { - console.info('Application onCreate') - }, - onDestroy() { - console.info('Application onDestroy') - }, - } - ``` - -6. 在工程导航栏里,打开index.ets。该页面展示了当前的UI描述,声明式UI框架会自动生成一个组件化的struct,这个struct遵循Builder接口声明,在build方法里面声明当前的布局和组件。 - ``` - @Entry - @Component - struct MyComponent { - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Text('Hello World') - .fontSize(50) - .fontWeight(FontWeight.Bold) - } - .width('100%') - .height('100%') - } - } - ``` - -7. 点击右侧的Previewer按钮,打开预览窗口。可以看到在手机设备类型的预览窗口中“Hello World”居中加粗显示。 - 如果没有Previewer按钮,点击settings > SDK Manager > OpenHarmony SDK> Tools 查看是否安装了Previewer。 - - ![zh-cn_image_0000001214595111](/images/application-dev/ui/figures/zh-cn_image_0000001214595111.png) - -8. 应用安装到手机上运行应用。将手机连接电脑,等IDE识别到物理设备后,点击Run 'entry'按钮。 - ![zh-cn_image_0000001148858818](/images/application-dev/ui/figures/zh-cn_image_0000001148858818.png) - - 在安装之前,需要配置应用签名,[配置应用签名教程](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/quick-start/configuring-openharmony-app-signature.md)。安装成功后,点击屏幕上的Run图标打开应用,可以看到居中加粗显示的“Hello World”。 - - ![zh-cn_image_0000001158896538](/images/application-dev/ui/figures/zh-cn_image_0000001158896538.png) diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/04.\344\275\223\351\252\214\345\243\260\346\230\216\345\274\217UI/02.\345\210\235\350\257\206Component.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/04.\344\275\223\351\252\214\345\243\260\346\230\216\345\274\217UI/02.\345\210\235\350\257\206Component.md" deleted file mode 100644 index 6687539bb9de6faac62286558d925ab3add4f14c..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/04.\344\275\223\351\252\214\345\243\260\346\230\216\345\274\217UI/02.\345\210\235\350\257\206Component.md" +++ /dev/null @@ -1,90 +0,0 @@ ---- -title: 初识Component -permalink: /pages/010802030402 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# 初识Component - -在自定义组件之前,需要先了解什么是[组件和装饰器](#组件和装饰器),并进行初始化组件。然后通过[修改组件属性和构造参数](#修改组件属性和构造参数),实现一个自定义组件。 - - -## 组件和装饰器 - -在声明式UI中,所有的页面都是由组件构成。组件的数据结构为struct,装饰器[@Component](/pages/0108020303020301)是组件化的标志。用@Component修饰的struct表示这个结构体有了组件化的能力。 - -自定义组件的声明方式为: - -``` -@Component -struct MyComponent {} -``` - -在IDE创建工程模板中,MyComponent就是一个可以居中显示文字的自定义组件。开发者可以在Component的build方法里描述自己的UI结构,但需要遵循Builder的接口约束。 - -``` -interface Builder { - build: () => void -} -``` - -[@Entry](/pages/0108020303020302)修饰的Component表示该Component是页面的总入口,也可以理解为页面的根节点。值得注意的是,一个页面有且仅能有一个@Entry,只有被@Entry修饰的组件或者其子组件,才会在页面上显示。 - -@Component和@Entry都是基础且十分重要的装饰器。简单地理解,装饰器就是某一种修饰,给被装饰的对象赋予某一种能力,比如@Entry就是页面入口的能力,@Component就是组件化能力。 - -在了解了组件和装饰器这两个重要概念后,接下来可以开始开发健康饮食应用。 - - -## 修改组件属性和构造参数 - -开发者创建系统组件时,会显示其默认样式。开发者可以通过更改组件的属性样式来改变组件的视图显示。 - -1. 修改Text组件的fontSize属性来更改组件的字体大小,将字体大小设置为26,fontWeight字体的粗细为500。fontWeight支持两种设置方式: - 1. number类型的取值范围为100到900,默认为400,取值越大,字体越粗。 - 2. fontWeight为内置枚举类型,取值支持Lighter、Normal、Bold、Bolder。 - - 属性方法要紧随组件,通过“.”运算符连接,也可以通过链式调用的方式配置组件的多个属性。 - - ``` - @Entry - @Component - struct MyComponent { - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Text('Hello World') - .fontSize(26) - .fontWeight(500) - } - .width('100%') - .height('100%') - } - } - ``` - - ![zh-cn_image_0000001168728272](/images/application-dev/ui/figures/zh-cn_image_0000001168728272.png) - -2. 修改Text组件的显示内容“Hello World”为“Tomato”,通过修改Text组件的构造参数来实现。 - ``` - @Entry - @Component - struct MyComponent { - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Text('Tomato') - .fontSize(26) - .fontWeight(500) - } - .width('100%') - .height('100%') - } - } - ``` - - ![zh-cn_image_0000001168888224](/images/application-dev/ui/figures/zh-cn_image_0000001168888224.png) diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/04.\344\275\223\351\252\214\345\243\260\346\230\216\345\274\217UI/03.\345\210\233\345\273\272\347\256\200\345\215\225\350\247\206\345\233\276.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/04.\344\275\223\351\252\214\345\243\260\346\230\216\345\274\217UI/03.\345\210\233\345\273\272\347\256\200\345\215\225\350\247\206\345\233\276.md" deleted file mode 100644 index facecb95769815d5bb0f70ec2258dac9f0b3be07..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/04.\344\275\223\351\252\214\345\243\260\346\230\216\345\274\217UI/03.\345\210\233\345\273\272\347\256\200\345\215\225\350\247\206\345\233\276.md" +++ /dev/null @@ -1,554 +0,0 @@ ---- -title: 创建简单视图 -permalink: /pages/010802030403 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# 创建简单视图 - -在这一小节中,我们将开始食物详情页的开发,学习如何通过容器组件Stack、Flex和基本组件Image、Text,构建用户自定义组件,完成图文并茂的食物介绍。 - - -## 构建Stack布局 - -1. 创建食物名称。 - 删掉工程模板的build方法的代码,创建Stack组件,将Text组件放进Stack组件的花括号中,使其成为Stack组件的子组件。Stack组件为堆叠组件,可以包含一个或多个子组件,其特点是后一个子组件覆盖前一个子组件。 - ``` - @Entry - @Component - struct MyComponent { - build() { - Stack() { - Text('Tomato') - .fontSize(26) - .fontWeight(500) - } - } - } - ``` - - ![zh-cn_image_0000001214128687](/images/application-dev/ui/figures/zh-cn_image_0000001214128687.png) - -2. 食物图片展示。 - 创建Image组件,指定Image组件的url,Image组件和Text组件都是必选构造参数组件。为了让Text组件在Image组件上方显示,所以要先声明Image组件。图片资源放在resources下的rawfile文件夹内,引用rawfile下资源时使用“$rawfile('filename')”的形式**,**filename为rawfile目录下的文件相对路径。当前$rawfile仅支持Image控件引用图片资源。 - ``` - @Entry - @Component - struct MyComponent { - build() { - Stack() { - Image($rawfile('Tomato.png')) - Text('Tomato') - .fontSize(26) - .fontWeight(500) - } - } - } - ``` - - ![zh-cn_image_0000001168410342](/images/application-dev/ui/figures/zh-cn_image_0000001168410342.png) - -3. 通过资源访问图片。 - 除指定图片路径外,也可以使用引用媒体资源符$r引用资源,需要遵循resources文件夹的资源限定词的规则。右键resources文件夹,点击New>Resource Directory,选择Resource Type为Media(图片资源),选择资源限定词为Device-Phone(目前开发设备为手机)。 - - ![zh-cn_image_0000001168570318](/images/application-dev/ui/figures/zh-cn_image_0000001168570318.png) - - 点击OK后,resources文件夹下生成phone.media文件夹。将Tomato.png放入该文件夹内。 - - ![zh-cn_image_0000001214330169](/images/application-dev/ui/figures/zh-cn_image_0000001214330169.png) - - 就可以通过“$r('app.type.name')”的形式引用应用资源,即$r('app.media.Tomato')。 - - ``` - @Entry - @Component - struct MyComponent { - build() { - Stack() { - Image($r('app.media.Tomato')) - .objectFit(ImageFit.Contain) - .height(357) - Text('Tomato') - .fontSize(26) - .fontWeight(500) - } - } - } - ``` - -4. 设置Image宽高,并且将image的objectFit属性设置为ImageFit.Contain,即保持图片长宽比的情况下,使得图片完整地显示在边界内。 - 如果Image填满了整个屏幕,原因如下: - 1. Image没有设置宽高。 - - 2. Image的objectFit默认属性是ImageFit.Cover,即在保持长宽比的情况下放大或缩小,使其填满整个显示边界。 - - ``` - @Entry - @Component - struct MyComponent { - build() { - Stack() { - Image($r('app.media.Tomato')) - .objectFit(ImageFit.Contain) - .height(357) - Text('Tomato') - .fontSize(26) - .fontWeight(500) - } - } - } - ``` - - ![zh-cn_image_0000001214210217](/images/application-dev/ui/figures/zh-cn_image_0000001214210217.png) - -5. 设置食物图片和名称布局。设置Stack的对齐方式为底部起始端对齐,Stack默认为居中对齐。设置Stack构造参数alignContent为Alignment.BottomStart。其中Alignment和FontWeight一样,都是框架提供的内置枚举类型。 - ``` - @Entry - @Component - struct MyComponent { - build() { - Stack({ alignContent: Alignment.BottomStart }) { - Image($r('app.media.Tomato')) - .objectFit(ImageFit.Contain) - .height(357) - Text('Tomato') - .fontSize(26) - .fontWeight(500) - } - } - } - ``` - - ![zh-cn_image_0000001168728872](/images/application-dev/ui/figures/zh-cn_image_0000001168728872.png) - -6. 通过设置Stack的背景颜色来改变食物图片的背景颜色,设置颜色有两种方式: - 1. 通过框架提供的Color内置枚举值来设置,比如backgroundColor(Color.Red),即设置背景颜色为红色。 - 2. string类型参数,支持的颜色格式有:rgb、rgba和HEX颜色码。比如backgroundColor('\#0000FF'),即设置背景颜色为蓝色,backgroundColor('rgb(255, 255, 255)'),即设置背景颜色为白色。 - - ``` - @Entry - @Component - struct MyComponent { - build() { - Stack({ alignContent: Alignment.BottomStart }) { - Image($r('app.media.Tomato')) - .objectFit(ImageFit.Contain) - .height(357) - Text('Tomato') - .fontSize(26) - .fontWeight(500) - } - .backgroundColor('#FFedf2f5') - } - } - ``` - - ![zh-cn_image_0000001168888822](/images/application-dev/ui/figures/zh-cn_image_0000001168888822.png) - -7. 调整Text组件的外边距margin,使其距离左侧和底部有一定的距离。margin是简写属性,可以统一指定四个边的外边距,也可以分别指定。具体设置方式如下: - 1. 参数为Length时,即统一指定四个边的外边距,比如margin(20),即上、右、下、左四个边的外边距都是20。 - 2. 参数为{top?: Length, right?: Length, bottom?: Length, left?:Length},即分别指定四个边的边距,比如margin({ left: 26, bottom: 17.4 }),即左边距为26,下边距为17.4。 - - ``` - @Entry - @Component - struct MyComponent { - build() { - Stack({ alignContent: Alignment.BottomStart }) { - Image($r('app.media.Tomato')) - .objectFit(ImageFit.Contain) - .height(357) - Text('Tomato') - .fontSize(26) - .fontWeight(500) - .margin({left: 26, bottom: 17.4}) - } - .backgroundColor('#FFedf2f5') - } - } - ``` - - ![zh-cn_image_0000001213968747](/images/application-dev/ui/figures/zh-cn_image_0000001213968747.png) - -8. 调整组件间的结构,语义化组件名称。创建页面入口组件为FoodDetail,在FoodDetail中创建Column,设置水平方向上居中对齐 alignItems(HorizontalAlign.Center)。MyComponent组件名改为FoodImageDisplay,为FoodDetail的子组件。 - Column是子组件竖直排列的容器组件,本质为线性布局,所以只能设置交叉轴方向的对齐。 - - ``` - @Component - struct FoodImageDisplay { - build() { - Stack({ alignContent: Alignment.BottomStart }) { - Image($r('app.media.Tomato')) - .objectFit(ImageFit.Contain) - Text('Tomato') - .fontSize(26) - .fontWeight(500) - .margin({ left: 26, bottom: 17.4 }) - } - .height(357) - .backgroundColor('#FFedf2f5') - } - } - - @Entry - @Component - struct FoodDetail { - build() { - Column() { - FoodImageDisplay() - } - .alignItems(HorizontalAlign.Center) - } - } - ``` - - -## 构建Flex布局 - -开发者可以使用Flex弹性布局来构建食物的食物成分表,弹性布局在本场景的优势在于可以免去多余的宽高计算,通过比例来设置不同单元格的大小,更加灵活。 - -1. 创建ContentTable组件,使其成为页面入口组件FoodDetail的子组件。 - ``` - @Component - struct FoodImageDisplay { - build() { - Stack({ alignContent: Alignment.BottomStart }) { - Image($r('app.media.Tomato')) - .objectFit(ImageFit.Contain) - .height(357) - Text('Tomato') - .fontSize(26) - .fontWeight(500) - .margin({ left: 26, bottom: 17.4 }) - } - .backgroundColor('#FFedf2f5') - } - } - - @Component - struct ContentTable { - build() {} - } - - @Entry - @Component - struct FoodDetail { - build() { - Column() { - FoodImageDisplay() - ContentTable() - } - .alignItems(HorizontalAlign.Center) - } - } - ``` - -2. 创建Flex组件展示Tomato两类成分。 - 一类是热量Calories,包含卡路里(Calories);一类是营养成分Nutrition,包含蛋白质(Protein)、脂肪(Fat)、碳水化合物(Carbohydrates)和维生素C(VitaminC)。 - - 先创建热量这一类。创建Flex组件,高度为280,上、右、左内边距为30,包含三个Text子组件分别代表类别名(Calories),含量名称(Calories)和含量数值(17kcal)。Flex组件默认为水平排列方式。 - - 已省略FoodImageDisplay代码,只针对ContentTable进行扩展。 - - ``` - @Component - struct ContentTable { - build() { - Flex() { - Text('Calories') - .fontSize(17.4) - .fontWeight(FontWeight.Bold) - Text('Calories') - .fontSize(17.4) - Text('17kcal') - .fontSize(17.4) - } - .height(280) - .padding({ top: 30, right: 30, left: 30 }) - } - } - - @Entry - @Component - struct FoodDetail { - build() { - Column() { - FoodImageDisplay() - ContentTable() - } - .alignItems(HorizontalAlign.Center) - } - } - ``` - - ![zh-cn_image_0000001169759552](/images/application-dev/ui/figures/zh-cn_image_0000001169759552.png) - -3. 调整布局,设置各部分占比。分类名占比(layoutWeight)为1,成分名和成分含量一共占比(layoutWeight)2。成分名和成分含量位于同一个Flex中,成分名占据所有剩余空间flexGrow(1)。 - ``` - @Component - struct FoodImageDisplay { - build() { - Stack({ alignContent: Alignment.BottomStart }) { - Image($m('Tomato.png')) - .objectFit(ImageFit.Contain) - .height(357) - Text('Tomato') - .fontSize(26) - .fontWeight(500) - .margin({ left: 26, bottom: 17.4 }) - } - .backgroundColor('#FFedf2f5') - } - } - - @Component - struct ContentTable { - build() { - Flex() { - Text('Calories') - .fontSize(17.4) - .fontWeight(FontWeight.Bold) - .layoutWeight(1) - Flex() { - Text('Calories') - .fontSize(17.4) - .flexGrow(1) - Text('17kcal') - .fontSize(17.4) - } - .layoutWeight(2) - } - .height(280) - .padding({ top: 30, right: 30, left: 30 }) - } - } - - @Entry - @Component - struct FoodDetail { - build() { - Column() { - FoodImageDisplay() - ContentTable() - } - .alignItems(HorizontalAlign.Center) - } - } - ``` - - ![zh-cn_image_0000001215079443](/images/application-dev/ui/figures/zh-cn_image_0000001215079443.png) - -4. 仿照热量分类创建营养成分分类。营养成分部分(Nutrition)包含:蛋白质(Protein)、脂肪(Fat)、碳水化合物(Carbohydrates)和维生素C(VitaminC)四个成分,后三个成分在表格中省略分类名,用空格代替。 - 设置外层Flex为竖直排列FlexDirection.Column, 在主轴方向(竖直方向)上等距排列FlexAlign.SpaceBetween,在交叉轴方向(水平轴方向)上首部对齐排列ItemAlign.Start。 - - ``` - @Component - struct ContentTable { - build() { - Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Start }) { - Flex() { - Text('Calories') - .fontSize(17.4) - .fontWeight(FontWeight.Bold) - .layoutWeight(1) - Flex() { - Text('Calories') - .fontSize(17.4) - .flexGrow(1) - Text('17kcal') - .fontSize(17.4) - } - .layoutWeight(2) - } - Flex() { - Text('Nutrition') - .fontSize(17.4) - .fontWeight(FontWeight.Bold) - .layoutWeight(1) - Flex() { - Text('Protein') - .fontSize(17.4) - .flexGrow(1) - Text('0.9g') - .fontSize(17.4) - } - .layoutWeight(2) - } - Flex() { - Text(' ') - .fontSize(17.4) - .fontWeight(FontWeight.Bold) - .layoutWeight(1) - Flex() { - Text('Fat') - .fontSize(17.4) - .flexGrow(1) - Text('0.2g') - .fontSize(17.4) - } - .layoutWeight(2) - } - Flex() { - Text(' ') - .fontSize(17.4) - .fontWeight(FontWeight.Bold) - .layoutWeight(1) - Flex() { - Text('Carbohydrates') - .fontSize(17.4) - .flexGrow(1) - Text('3.9g') - .fontSize(17.4) - } - .layoutWeight(2) - } - Flex() { - Text(' ') - .fontSize(17.4) - .fontWeight(FontWeight.Bold) - .layoutWeight(1) - Flex() { - Text('vitaminC') - .fontSize(17.4) - .flexGrow(1) - Text('17.8mg') - .fontSize(17.4) - } - .layoutWeight(2) - } - } - .height(280) - .padding({ top: 30, right: 30, left: 30 }) - } - } - - @Entry - @Component - struct FoodDetail { - build() { - Column() { - FoodImageDisplay() - ContentTable() - } - .alignItems(HorizontalAlign.Center) - } - } - ``` - -5. 使用自定义构造函数\@Builder简化代码。可以发现,每个成分表中的成分单元其实都是一样的UI结构。 - ![zh-cn_image_0000001169599582](/images/application-dev/ui/figures/zh-cn_image_0000001169599582.png) - - 当前对每个成分单元都进行了声明,造成了代码的重复和冗余。可以使用\@Builder来构建自定义方法,抽象出相同的UI结构声明。\@Builder修饰的方法和Component的build方法都是为了声明一些UI渲染结构,遵循一样的eTS语法。开发者可以定义一个或者多个\@Builder修饰的方法,但Component的build方法必须只有一个。 - - 在ContentTable内声明\@Builder修饰的IngredientItem方法,用于声明分类名、成分名称和成分含量UI描述。 - - ``` - @Component - struct ContentTable { - @Builder IngredientItem(title:string, colorValue: string, name: string, value: string) { - Flex() { - Text(title) - .fontSize(17.4) - .fontWeight(FontWeight.Bold) - .layoutWeight(1) - Flex({ alignItems: ItemAlign.Center }) { - Circle({width: 6, height: 6}) - .margin({right: 12}) - .fill(colorValue) - Text(name) - .fontSize(17.4) - .flexGrow(1) - Text(value) - .fontSize(17.4) - } - .layoutWeight(2) - } - } - } - ``` - - 在ContentTable的build方法内调用IngredientItem接口,需要用this去调用该Component作用域内的方法,以此来区分全局的方法调用。 - - ``` - @Component - struct ContentTable { - ...... - build() { - Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Start }) { - this.IngredientItem('Calories', 'Calories', '17kcal') - this.IngredientItem('Nutrition', 'Protein', '0.9g') - this.IngredientItem('', 'Fat', '0.2g') - this.IngredientItem('', 'Carbohydrates', '3.9g') - this.IngredientItem('', 'VitaminC', '17.8mg') - } - .height(280) - .padding({ top: 30, right: 30, left: 30 }) - } - } - ``` - - ContentTable组件整体代码如下。 - - ``` - @Component - struct ContentTable { - @Builder IngredientItem(title:string, name: string, value: string) { - Flex() { - Text(title) - .fontSize(17.4) - .fontWeight(FontWeight.Bold) - .layoutWeight(1) - Flex() { - Text(name) - .fontSize(17.4) - .flexGrow(1) - Text(value) - .fontSize(17.4) - } - .layoutWeight(2) - } - } - - build() { - Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Start }) { - this.IngredientItem('Calories', 'Calories', '17kcal') - this.IngredientItem('Nutrition', 'Protein', '0.9g') - this.IngredientItem('', 'Fat', '0.2g') - this.IngredientItem('', 'Carbohydrates', '3.9g') - this.IngredientItem('', 'VitaminC', '17.8mg') - } - .height(280) - .padding({ top: 30, right: 30, left: 30 }) - } - } - - @Entry - @Component - struct FoodDetail { - build() { - Column() { - FoodImageDisplay() - ContentTable() - } - .alignItems(HorizontalAlign.Center) - } - } - ``` - - ![zh-cn_image_0000001215199399](/images/application-dev/ui/figures/zh-cn_image_0000001215199399.png) - -通过学习Stack布局和Flex布局已完成食物的图文展示和营养成分表,构建出第一个普通视图的食物详情页。在下一个章节中,将开发食物分类列表页,并完成食物分类列表页面和食物详情页面的跳转和数据传递,现在我们就进入下一个章节的学习吧。 - -## 相关实例 - -针对创建简单视图,有以下示例工程可供参考: - -- [eTSBuildCommonView](https://gitee.com/openharmony/app_samples/tree/master/ETSUI/eTSBuildCommonView) - 本示例为构建了简单页面展示食物番茄的图片和营养信息,主要为了展示简单页面的Stack布局和Flex布局。 diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/05.\351\241\265\351\235\242\345\270\203\345\261\200\344\270\216\350\277\236\346\216\245/01.\346\236\204\345\273\272\351\243\237\347\211\251\346\225\260\346\215\256\346\250\241\345\236\213.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/05.\351\241\265\351\235\242\345\270\203\345\261\200\344\270\216\350\277\236\346\216\245/01.\346\236\204\345\273\272\351\243\237\347\211\251\346\225\260\346\215\256\346\250\241\345\236\213.md" deleted file mode 100644 index 7761bff7a3fae21cf553723ad027b5567ab08419..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/05.\351\241\265\351\235\242\345\270\203\345\261\200\344\270\216\350\277\236\346\216\245/01.\346\236\204\345\273\272\351\243\237\347\211\251\346\225\260\346\215\256\346\250\241\345\236\213.md" +++ /dev/null @@ -1,108 +0,0 @@ ---- -title: 构建食物数据模型 -permalink: /pages/010802030501 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# 构建食物数据模型 - -在创建视图中,我们逐一去表述食物的各个信息,如食物名称、卡路里、蛋白质、脂肪、碳水和维生素C。这样的编码形式在实际的开发中肯定是不切实际的,所以要创建食物数据模型来统一存储和管理数据。 - - -![zh-cn_image_0000001215433095](/images/application-dev/ui/figures/zh-cn_image_0000001215433095.png) - - -1. 新建model文件夹,在model目录下创建FoodData.ets。 - ![zh-cn_image_0000001195119619](/images/application-dev/ui/figures/zh-cn_image_0000001195119619.png) - -2. 定义食物数据的存储模型FoodData和枚举变量Category,FoodData类包含食物id、名称(name)、分类(category)、图片(image)、热量(calories)、蛋白质(protein)、脂肪(fat)、碳水(carbohydrates)和维生素C(vitaminC)属性。 - eTS语言是在ts语言的基础上的扩展,同样支持ts语法。 - - ``` - enum Category { - Fruit, - Vegetable, - Nut, - Seafood, - Dessert - } - - let NextId = 0; - class FoodData { - id: string; - name: string; - image: Resource; - category: Category; - calories: number; - protein: number; - fat: number; - carbohydrates: number; - vitaminC: number; - - constructor(name: string, image: Resource, category: Category, calories: number, protein: number, fat: number, carbohydrates: number, vitaminC: number) { - this.id = `${ NextId++ }`; - this.name = name; - this.image = image; - this.category = category; - this.calories = calories; - this.protein = protein; - this.fat = fat; - this.carbohydrates = carbohydrates; - this.vitaminC = vitaminC; - } - } - ``` - -3. 存入食物图片资源。在resources > phone > media目录下存入食物图片资源,图片名称为食物名称。 - ![zh-cn_image_0000001195117633](/images/application-dev/ui/figures/zh-cn_image_0000001195117633.png) - -4. 创建食物资源数据。在model文件夹下创建FoodDataModels.ets,在该页面中声明食物成分数组FoodComposition。 - 以12个食物数据为例,实际开发中,开发者可以自定义更多的数据资源,当食物资源很多时,建议使用数据懒加载LazyForEach。以下营养数据均来自网络。 - - ``` - const FoodComposition: any[] = [ - { 'name': 'Tomato', 'image': $r('app.media.Tomato'), 'category': Category.Vegetable, 'calories': 17, 'protein': 0.9, 'fat': 0.2, 'carbohydrates': 3.9, 'vitaminC': 17.8 }, - { 'name': 'Walnut', 'image': $r('app.media.Walnut'), 'category': Category.Nut, 'calories': 654 , 'protein': 15, 'fat': 65, 'carbohydrates': 14, 'vitaminC': 1.3 }, - { 'name': 'Cucumber', 'image': $r('app.media.Cucumber'), 'category': Category.Vegetable, 'calories': 30, 'protein': 3, 'fat': 0, 'carbohydrates': 1.9, 'vitaminC': 2.1 }, - { 'name': 'Blueberry', 'image': $r('app.media.Blueberry'), 'category': Category.Fruit, 'calories': 57, 'protein': 0.7, 'fat': 0.3, 'carbohydrates': 14, 'vitaminC': 9.7 }, - { 'name': 'Crab', 'image': $r('app.media.Crab'), 'category': Category.Seafood, 'calories': 97, 'protein': 19, 'fat': 1.5, 'carbohydrates': 0, 'vitaminC': 7.6 }, - { 'name': 'IceCream', 'image': $r('app.media.IceCream'), 'category': Category.Dessert, 'calories': 207, 'protein': 3.5, 'fat': 11, 'carbohydrates': 24, 'vitaminC': 0.6 }, - { 'name': 'Onion', 'image': $r('app.media.Onion'), 'category': Category.Vegetable, 'calories': 39, 'protein': 1.1, 'fat': 0.1, 'carbohydrates': 9, 'vitaminC': 7.4 }, - { 'name': 'Mushroom', 'image': $r('app.media.Mushroom'), 'category': Category.Vegetable, 'calories': 22, 'protein': 3.1, 'fat': 0.3, 'carbohydrates': 3.3, 'vitaminC': 2.1 }, - { 'name': 'Kiwi', 'image': $r('app.media.Kiwi'), 'category': Category.Fruit, 'calories': 60 , 'protein': 1.1, 'fat': 0.5, 'carbohydrates': 15, 'vitaminC': 20.5 }, - { 'name': 'Pitaya', 'image': $r('app.media.Pitaya'), 'category': Category.Fruit, 'calories': 60, 'protein': 1.2, 'fat': 0, 'carbohydrates': 10, 'vitaminC': 60.9 }, - { 'name': 'Avocado', 'image': $r('app.media.Avocado'), 'category': Category.Fruit, 'calories': 160, 'protein': 2, 'fat': 15, 'carbohydrates': 9, 'vitaminC': 10 }, - { 'name': 'Strawberry', 'image': $r('app.media.Strawberry'), 'category': Category.Fruit, 'calories': 32, 'protein': 0.7, 'fat': 0.3, 'carbohydrates': 8, 'vitaminC': 58.8 } - ] - ``` - -5. 创建initializeOnStartUp方法来初始化FoodData的数组。在FoodDataModels.ets中使用了定义在FoodData.ets的FoodData和Category,所以要将FoodData.ets的FoodData类export,在FoodDataModels.ets内import FoodData和Category。 - ``` - // FoodData.ets - export enum Category { - ...... - } - export class FoodData { - ...... - } - // FoodDataModels.ets - import { Category, FoodData } from './FoodData' - - export function initializeOnStartup(): Array { - let FoodDataArray: Array = [] - FoodComposition.forEach(item => { - FoodDataArray.push(new FoodData(item.name, item.image, item.category, item.calories, item.protein, item.fat, item.carbohydrates, item.vitaminC )); - }) - return FoodDataArray; - } - ``` - - -已完成好健康饮食应用的数据资源准备,接下来将通过加载这些数据来创建食物列表页面。 diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/05.\351\241\265\351\235\242\345\270\203\345\261\200\344\270\216\350\277\236\346\216\245/02.\346\236\204\345\273\272\351\243\237\347\211\251\345\210\227\350\241\250List\345\270\203\345\261\200.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/05.\351\241\265\351\235\242\345\270\203\345\261\200\344\270\216\350\277\236\346\216\245/02.\346\236\204\345\273\272\351\243\237\347\211\251\345\210\227\350\241\250List\345\270\203\345\261\200.md" deleted file mode 100644 index 989e721b5dc821b0b173cd0b6d446e6d310b6ae7..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/05.\351\241\265\351\235\242\345\270\203\345\261\200\344\270\216\350\277\236\346\216\245/02.\346\236\204\345\273\272\351\243\237\347\211\251\345\210\227\350\241\250List\345\270\203\345\261\200.md" +++ /dev/null @@ -1,265 +0,0 @@ ---- -title: 构建食物列表List布局 -permalink: /pages/010802030502 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# 构建食物列表List布局 - - - -使用List组件和ForEach循环渲染,构建食物列表布局。 - - -1. 在pages目录新建页面FoodCategoryList.ets,将index.ets改名为FoodDetail.ets,并将其添加到config.json文件下的pages标签,位于第一序位的页面为首页。 - ``` - "js": [ - { - "pages": [ - "pages/FoodCategoryList", - "pages/FoodDetail" - ], - ] - ``` - -2. 新建FoodList组件作为页面入口组件,FoodListItem为其子组件。List组件是列表组件,适用于重复同类数据的展示,其子组件为ListItem,适用于展示列表中的单元。 - ``` - @Component - struct FoodListItem { - build() {} - } - - @Entry - @Component - struct FoodList { - build() { - List() { - ListItem() { - FoodListItem() - } - } - } - } - ``` - -3. 引入FoodData类和initializeOnStartup方法。 - ``` - import { FoodData } from '../model/FoodData' - import { initializeOnStartup } from '../model/FoodDataModels' - ``` - -4. FoodList和FoodListItem组件数值传递。在FoodList组件内创建类型为FoodData[]成员变量foodItems,调用initializeOnStartup方法为其赋值。在FoodListItem组件内创建类型为FoodData的成员变量foodItem。将父组件foodItems数组的第一个元素的foodItems[0]作为参数传递给FoodListItem。 - ``` - import { FoodData } from '../model/FoodData' - import { initializeOnStartup } from '../model/FoodDataModels' - - @Component - struct FoodListItem { - private foodItem: FoodData - build() {} - } - - @Entry - @Component - struct FoodList { - private foodItems: FoodData[] = initializeOnStartup() - build() { - List() { - ListItem() { - FoodListItem({ foodItem: this.foodItems[0] }) - } - } - } - } - ``` - -5. 声明子组件FoodListItem 的UI布局。创建Flex组件,包含食物图片缩略图,食物名称,和食物对应的卡路里。 - ``` - import { FoodData } from '../model/FoodData' - import { initializeOnStartup } from '../model/FoodDataModels' - - @Component - struct FoodListItem { - private foodItem: FoodData - build() { - Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { - Image(this.foodItem.image) - .objectFit(ImageFit.Contain) - .height(40) - .width(40) - .backgroundColor('#FFf1f3f5') - .margin({ right: 16 }) - Text(this.foodItem.name) - .fontSize(14) - .flexGrow(1) - Text(this.foodItem.calories + ' kcal') - .fontSize(14) - } - .height(64) - .margin({ right: 24, left:32 }) - } - } - - @Entry - @Component - struct FoodList { - private foodItems: FoodData[] = initializeOnStartup() - build() { - List() { - ListItem() { - FoodListItem({ foodItem: this.foodItems[0] }) - } - } - } - } - ``` - - ![zh-cn_image_0000001204776353](/images/application-dev/ui/figures/zh-cn_image_0000001204776353.png) - -6. 创建两个FoodListItem。在List组件创建两个FoodListItem,分别给FoodListItem传递foodItems数组的第一个元素this.foodItems[0]和第二个元素foodItem: this.foodItems[1]。 - ``` - import { FoodData } from '../model/FoodData' - import { initializeOnStartup } from '../model/FoodDataModels' - - @Component - struct FoodListItem { - private foodItem: FoodData - build() { - Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { - Image(this.foodItem.image) - .objectFit(ImageFit.Contain) - .height(40) - .width(40) - .backgroundColor('#FFf1f3f5') - .margin({ right: 16 }) - Text(this.foodItem.name) - .fontSize(14) - .flexGrow(1) - Text(this.foodItem.calories + ' kcal') - .fontSize(14) - } - .height(64) - .margin({ right: 24, left:32 }) - } - } - - @Entry - @Component - struct FoodList { - private foodItems: FoodData[] = initializeOnStartup() - build() { - List() { - ListItem() { - FoodListItem({ foodItem: this.foodItems[0] }) - } - ListItem() { - FoodListItem({ foodItem: this.foodItems[1] }) - } - } - } - } - ``` - - ![zh-cn_image_0000001204537865](/images/application-dev/ui/figures/zh-cn_image_0000001204537865.png) - -7. 单独创建每一个FoodListItem肯定是不合理的。这就需要引入ForEach循环渲染,ForEach语法如下。 - ``` - ForEach( - arr: any[], // Array to be iterated - itemGenerator: (item: any) => void, // child component generator - keyGenerator?: (item: any) => string // (optional) Unique key generator, which is recommended. - ) - ``` - - ForEach组有三个参数,第一个参数是需要被遍历的数组,第二个参数为生成子组件的lambda函数,第三个参数是键值生成器。出于性能原因,即使第三个参数是可选的,强烈建议开发者提供。keyGenerator使开发框架能够更好地识别数组更改,而不必因为item的更改重建全部节点。 - - 遍历foodItems数组循环创建ListItem组件,foodItems中每一个item都作为参数传递给FoodListItem组件。 - - ``` - ForEach(this.foodItems, item => { - ListItem() { - FoodListItem({ foodItem: item }) - } - }, item => item.id.toString()) - ``` - - 整体的代码如下。 - - ``` - import { FoodData } from '../model/FoodData' - import { initializeOnStartup } from '../model/FoodDataModels' - - @Component - struct FoodListItem { - private foodItem: FoodData - build() { - Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { - Image(this.foodItem.image) - .objectFit(ImageFit.Contain) - .height(40) - .width(40) - .backgroundColor('#FFf1f3f5') - .margin({ right: 16 }) - Text(this.foodItem.name) - .fontSize(14) - .flexGrow(1) - Text(this.foodItem.calories + ' kcal') - .fontSize(14) - } - .height(64) - .margin({ right: 24, left:32 }) - } - } - - @Entry - @Component - struct FoodList { - private foodItems: FoodData[] = initializeOnStartup() - build() { - List() { - ForEach(this.foodItems, item => { - ListItem() { - FoodListItem({ foodItem: item }) - } - }, item => item.id.toString()) - } - } - } - ``` - -8. 添加FoodList标题。 - ``` - @Entry - @Component - struct FoodList { - private foodItems: FoodData[] = initializeOnStartup() - build() { - Column() { - Flex({justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center}) { - Text('Food List') - .fontSize(20) - .margin({ left:20 }) - } - .height('7%') - .backgroundColor('#FFf1f3f5') - List() { - ForEach(this.foodItems, item => { - ListItem() { - FoodListItem({ foodItem: item }) - } - }, item => item.id.toString()) - } - .height('93%') - } - } - } - ``` - - ![zh-cn_image_0000001169678922](/images/application-dev/ui/figures/zh-cn_image_0000001169678922.png) diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/05.\351\241\265\351\235\242\345\270\203\345\261\200\344\270\216\350\277\236\346\216\245/03.\346\236\204\345\273\272\351\243\237\347\211\251\345\210\206\347\261\273Grid\345\270\203\345\261\200.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/05.\351\241\265\351\235\242\345\270\203\345\261\200\344\270\216\350\277\236\346\216\245/03.\346\236\204\345\273\272\351\243\237\347\211\251\345\210\206\347\261\273Grid\345\270\203\345\261\200.md" deleted file mode 100644 index 8222dc84458784576bd6dc42c1588532005f0fcd..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/05.\351\241\265\351\235\242\345\270\203\345\261\200\344\270\216\350\277\236\346\216\245/03.\346\236\204\345\273\272\351\243\237\347\211\251\345\210\206\347\261\273Grid\345\270\203\345\261\200.md" +++ /dev/null @@ -1,374 +0,0 @@ ---- -title: 构建食物分类Grid布局 -permalink: /pages/010802030503 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# 构建食物分类Grid布局 - - - -健康饮食应用在主页提供给用户两种食物显示方式:列表显示和网格显示。开发者将实现通过页签切换不同食物分类的网格布局。 - - -1. 将Category枚举类型引入FoodCategoryList页面。 - ``` - import { Category, FoodData } from '../model/FoodData' - ``` - -2. 创建FoodCategoryList和FoodCategory组件,其中FoodCategoryList作为新的页面入口组件,在入口组件调用initializeOnStartup方法。 - ``` - @Component - struct FoodList { - private foodItems: FoodData[] - build() { - ...... - } - } - - @Component - struct FoodCategory { - private foodItems: FoodData[] - build() { - ...... - } - } - - @Entry - @Component - struct FoodCategoryList { - private foodItems: FoodData[] = initializeOnStartup() - build() { - ...... - } - } - ``` - -3. 在FoodCategoryList组件内创建showList成员变量,用于控制List布局和Grid布局的渲染切换。需要用到条件渲染语句if...else...。 - ``` - @Entry - @Component - struct FoodCategoryList { - private foodItems: FoodData[] = initializeOnStartup() - private showList: boolean = false - - build() { - Stack() { - if (this.showList) { - FoodList({ foodItems: this.foodItems }) - } else { - FoodCategory({ foodItems: this.foodItems }) - } - } - } - } - ``` - -4. 在页面右上角创建切换List/Grid布局的图标。设置Stack对齐方式为顶部尾部对齐TopEnd,创建Image组件,设置其点击事件,即showList取反。 - ``` - @Entry - @Component - struct FoodCategoryList { - private foodItems: FoodData[] = initializeOnStartup() - private showList: boolean = false - - build() { - Stack({ alignContent: Alignment.TopEnd }) { - if (this.showList) { - FoodList({ foodItems: this.foodItems }) - } else { - FoodCategory({ foodItems: this.foodItems }) - } - Image($r('app.media.Switch')) - .height(24) - .width(24) - .margin({ top: 15, right: 10 }) - .onClick(() => { - this.showList = !this.showList - }) - }.height('100%') - } - } - ``` - -5. 添加\@State装饰器。点击右上角的switch标签后,页面没有任何变化,这是因为showList不是有状态数据,它的改变不会触发页面的刷新。需要为其添加\@State装饰器,使其成为状态数据,它的改变会引起其所在组件的重新渲染。 - ``` - @Entry - @Component - struct FoodCategoryList { - private foodItems: FoodData[] = initializeOnStartup() - @State private showList: boolean = false - - build() { - Stack({ alignContent: Alignment.TopEnd }) { - if (this.showList) { - FoodList({ foodItems: this.foodItems }) - } else { - FoodCategory({ foodItems: this.foodItems }) - } - Image($r('app.media.Switch')) - .height(24) - .width(24) - .margin({ top: 15, right: 10 }) - .onClick(() => { - this.showList = !this.showList - }) - }.height('100%') - } - } - - ``` - - 点击切换图标,FoodList组件出现,再次点击,FoodList组件消失。 - - ![zh-cn_image_0000001170411978](/images/application-dev/ui/figures/zh-cn_image_0000001170411978.gif) - -6. 创建显示所有食物的页签(All)。在FoodCategory组件内创建Tabs组件和其子组件TabContent,设置tabBar为All。设置TabBars的宽度为280,布局模式为Scrollable,即超过总长度后可以滑动。Tabs是一种可以通过页签进行内容视图切换的容器组件,每个页签对应一个内容视图TabContent。 - ``` - @Component - struct FoodCategory { - private foodItems: FoodData[] - build() { - Stack() { - Tabs() { - TabContent() {}.tabBar('All') - } - .barWidth(280) - .barMode(BarMode.Scrollable) - } - } - } - ``` - - ![zh-cn_image_0000001204538065](/images/application-dev/ui/figures/zh-cn_image_0000001204538065.png) - -7. 创建FoodGrid组件,作为TabContent的子组件。 - ``` - @Component - struct FoodGrid { - private foodItems: FoodData[] - build() {} - } - - @Component - struct FoodCategory { - private foodItems: FoodData[] - build() { - Stack() { - Tabs() { - TabContent() { - FoodGrid({ foodItems: this.foodItems }) - }.tabBar('All') - } - .barWidth(280) - .barMode(BarMode.Scrollable) - } - } - } - ``` - -8. 实现2 \* 6的网格布局(一共12个食物数据资源)。创建Grid组件,设置列数columnsTemplate('1fr 1fr'),行数rowsTemplate('1fr 1fr 1fr 1fr 1fr 1fr'),行间距和列间距rowsGap和columnsGap为8。创建Scroll组件,使其可以滑动。 - ``` - @Component - struct FoodGrid { - private foodItems: FoodData[] - build() { - Scroll() { - Grid() { - ForEach(this.foodItems, (item: FoodData) => { - GridItem() {} - }, (item: FoodData) => item.id.toString()) - } - .rowsTemplate('1fr 1fr 1fr 1fr 1fr 1fr') - .columnsTemplate('1fr 1fr') - .columnsGap(8) - .rowsGap(8) - } - .scrollBar(BarState.Off) - .padding({left: 16, right: 16}) - } - } - ``` - -9. 创建FoodGridItem组件,展示食物图片、名称和卡路里,实现其UI布局,为GridItem的子组件。每个FoodGridItem高度为184,行间距为8,设置Grid总高度为(184 + 8) \* 6 - 8 = 1144。 - ``` - @Component - struct FoodGridItem { - private foodItem: FoodData - build() { - Column() { - Row() { - Image(this.foodItem.image) - .objectFit(ImageFit.Contain) - .height(152) - .width('100%') - }.backgroundColor('#FFf1f3f5') - Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { - Text(this.foodItem.name) - .fontSize(14) - .flexGrow(1) - .padding({ left: 8 }) - Text(this.foodItem.calories + 'kcal') - .fontSize(14) - .margin({ right: 6 }) - } - .height(32) - .width('100%') - .backgroundColor('#FFe5e5e5') - } - .height(184) - .width('100%') - } - } - - @Component - struct FoodGrid { - private foodItems: FoodData[] - build() { - Scroll() { - Grid() { - ForEach(this.foodItems, (item: FoodData) => { - GridItem() { - FoodGridItem({foodItem: item}) - } - }, (item: FoodData) => item.id.toString()) - } - .rowsTemplate('1fr 1fr 1fr 1fr 1fr 1fr') - .columnsTemplate('1fr 1fr') - .columnsGap(8) - .rowsGap(8) - .height(1144) - } - .scrollBar(BarState.Off) - .padding({ left: 16, right: 16 }) - } - } - ``` - - ![zh-cn_image_0000001170167520](/images/application-dev/ui/figures/zh-cn_image_0000001170167520.gif) - -10. 创建展示蔬菜(Category.Vegetable)、水果(Category.Fruit)、坚果(Category.Nut)、海鲜(Category.SeaFood)和甜品(Category.Dessert)分类的页签。 - ``` - @Component - struct FoodCategory { - private foodItems: FoodData[] - build() { - Stack() { - Tabs() { - TabContent() { - FoodGrid({ foodItems: this.foodItems }) - }.tabBar('All') - - TabContent() { - FoodGrid({ foodItems: this.foodItems.filter(item => (item.category === Category.Vegetable)) }) - }.tabBar('Vegetable') - - TabContent() { - FoodGrid({ foodItems: this.foodItems.filter(item => (item.category === Category.Fruit)) }) - }.tabBar('Fruit') - - TabContent() { - FoodGrid({ foodItems: this.foodItems.filter(item => (item.category === Category.Nut)) }) - }.tabBar('Nut') - - TabContent() { - FoodGrid({ foodItems: this.foodItems.filter(item => (item.category === Category.Seafood)) }) - }.tabBar('Seafood') - - TabContent() { - FoodGrid({ foodItems: this.foodItems.filter(item => (item.category === Category.Dessert)) }) - }.tabBar('Dessert') - } - .barWidth(280) - .barMode(BarMode.Scrollable) - } - } - } - ``` - -11. 设置不同食物分类的Grid的行数和高度。因为不同分类的食物数量不同,所以不能用'1fr 1fr 1fr 1fr 1fr 1fr '常量来统一设置成6行。 - 创建gridRowTemplate和HeightValue成员变量,通过成员变量设置Grid行数和高度。 - - ``` - @Component - struct FoodGrid { - private foodItems: FoodData[] - private gridRowTemplate : string = '' - private heightValue: number - build() { - Scroll() { - Grid() { - ForEach(this.foodItems, (item: FoodData) => { - GridItem() { - FoodGridItem({foodItem: item}) - } - }, (item: FoodData) => item.id.toString()) - } - .rowsTemplate(this.gridRowTemplate) - .columnsTemplate('1fr 1fr') - .columnsGap(8) - .rowsGap(8) - .height(this.heightValue) - } - .scrollBar(BarState.Off) - .padding({left: 16, right: 16}) - } - } - ``` - - 调用aboutToAppear接口计算行数(gridRowTemplate )和高度(heightValue)。 - - ``` - aboutToAppear() { - var rows = Math.round(this.foodItems.length / 2); - this.gridRowTemplate = '1fr '.repeat(rows); - this.heightValue = rows * 192 - 8; - } - ``` - - 自定义组件提供了两个生命周期的回调接口aboutToAppear和aboutToDisappear。aboutToAppear的执行时机在创建自定义组件后,执行自定义组件build方法之前。aboutToDisappear在自定义组件的去初始化的时机执行。 - - ![zh-cn_image_0000001215113569](/images/application-dev/ui/figures/zh-cn_image_0000001215113569.png) - - ``` - @Component - struct FoodGrid { - private foodItems: FoodData[] - private gridRowTemplate : string = '' - private heightValue: number - - aboutToAppear() { - var rows = Math.round(this.foodItems.length / 2); - this.gridRowTemplate = '1fr '.repeat(rows); - this.heightValue = rows * 192 - 8; - } - - build() { - Scroll() { - Grid() { - ForEach(this.foodItems, (item: FoodData) => { - GridItem() { - FoodGridItem({foodItem: item}) - } - }, (item: FoodData) => item.id.toString()) - } - .rowsTemplate(this.gridRowTemplate) - .columnsTemplate('1fr 1fr') - .columnsGap(8) - .rowsGap(8) - .height(this.heightValue) - } - .scrollBar(BarState.Off) - .padding({left: 16, right: 16}) - } - } - ``` - - ![zh-cn_image_0000001170008198](/images/application-dev/ui/figures/zh-cn_image_0000001170008198.gif) diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/05.\351\241\265\351\235\242\345\270\203\345\261\200\344\270\216\350\277\236\346\216\245/04.\351\241\265\351\235\242\350\267\263\350\275\254\344\270\216\346\225\260\346\215\256\344\274\240\351\200\222.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/05.\351\241\265\351\235\242\345\270\203\345\261\200\344\270\216\350\277\236\346\216\245/04.\351\241\265\351\235\242\350\267\263\350\275\254\344\270\216\346\225\260\346\215\256\344\274\240\351\200\222.md" deleted file mode 100644 index 614cc4cac1f92f762a391970b3f155bbb7da5315..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/02.\346\226\271\350\210\237\345\274\200\345\217\221\346\241\206\346\236\266\357\274\210ArkUI\357\274\211/03.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/05.\351\241\265\351\235\242\345\270\203\345\261\200\344\270\216\350\277\236\346\216\245/04.\351\241\265\351\235\242\350\267\263\350\275\254\344\270\216\346\225\260\346\215\256\344\274\240\351\200\222.md" +++ /dev/null @@ -1,284 +0,0 @@ ---- -title: 页面跳转与数据传递 -permalink: /pages/010802030504 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# 页面跳转与数据传递 - -本节将学习页面跳转和数据传递,实现: - - -1. 页面跳转:点击食物分类列表页面的食物条目后,跳转到食物详情页;点击食物详情页的返回按钮,返回到食物列表页。 - -2. 页面间数据传递:点击不同的食物条目后,FoodDetail接受前一个页面的数据,渲染对应的食物详情页。 - - -## 页面跳转 - -声明式UI范式提供了两种机制来实现页面间的跳转: - -1. 路由容器组件Navigator,包装了页面路由的能力,指定页面target后,使其包裹的子组件都具有路由能力。 - -2. 路由RouterAPI接口,通过在页面上引入router,可以调用router的各种接口,从而实现页面路由的各种操作。 - -下面我们就分别学习这两种跳转机制来实现食物分类列表页面和食物详情页的链接。 - -1. 点击FoodListItem后跳转到FoodDetail页面。在FoodListItem内创建Navigator组件,使其子组件都具有路由功能,目标页面target为'pages/FoodDetail'。 - ``` - @Component - struct FoodListItem { - private foodItem: FoodData - build() { - Navigator({ target: 'pages/FoodDetail' }) { - Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { - Image(this.foodItem.image) - .objectFit(ImageFit.Contain) - .height(40) - .width(40) - .backgroundColor('#FFf1f3f5') - .margin({ right: 16 }) - Text(this.foodItem.name) - .fontSize(14) - .flexGrow(1) - Text(this.foodItem.calories + ' kcal') - .fontSize(14) - } - .height(64) - } - .margin({ right: 24, left:32 }) - } - } - ``` - - ![zh-cn_image_0000001215318403](/images/application-dev/ui/figures/zh-cn_image_0000001215318403.gif) - -2. 点击FoodGridItem后跳转到FoodDetail页面。调用页面路由router模块的push接口,将FoodDetail页面推到路由栈中,实现页面跳转。使用router路由API接口,需要先引入router。 - ``` - import router from '@system.router' - - @Component - struct FoodGridItem { - private foodItem: FoodData - build() { - Column() { - ...... - } - .height(184) - .width('100%') - .onClick(() => { - router.push({ uri: 'pages/FoodDetail' }) - }) - } - } - ``` - - ![zh-cn_image_0000001169918548](/images/application-dev/ui/figures/zh-cn_image_0000001169918548.gif) - -3. 在FoodDetail页面增加回到食物列表页面的图标。在resources > phone > media文件夹下存入回退图标Back.png。新建自定义组件PageTitle,包含后退的图标和Food Detail的文本,调用路由的router.back()接口,弹出路由栈最上面的页面,即返回上一级页面。 - ``` - // FoodDetail.ets - import router from '@system.router' - - @Component - struct PageTitle { - build() { - Flex({ alignItems: ItemAlign.Start }) { - Image($r('app.media.Back')) - .width(21.8) - .height(19.6) - Text('Food Detail') - .fontSize(21.8) - .margin({left: 17.4}) - } - .height(61) - .backgroundColor('#FFedf2f5') - .padding({ top: 13, bottom: 15, left: 28.3 }) - .onClick(() => { - router.back() - }) - } - } - ``` - -4. 在FoodDetail组件内创建Stack组件,包含子组件FoodImageDisplay和PageTitle子组件,设置其对齐方式为左上对齐TopStart。 - ``` - @Entry - @Component - struct FoodDetail { - build() { - Column() { - Stack( { alignContent: Alignment.TopStart }) { - FoodImageDisplay() - PageTitle() - } - ContentTable() - } - .alignItems(HorizontalAlign.Center) - } - } - ``` - - ![zh-cn_image_0000001214998349](/images/application-dev/ui/figures/zh-cn_image_0000001214998349.png) - - -## 页面间数据传递 - -我们已经完成了FoodCategoryList页面和FoodDetail页面的跳转和回退,但是点击不同的FoodListItem/FoodGridItem,跳转的FoodDetail页面都是西红柿Tomato的详细介绍,这是因为没有构建起两个页面的数据传递,需要用到携带参数(parameter)路由。 - -1. 在FoodListItem组件的Navigator设置其params属性,params属性接受key-value的Object。 - ``` - // FoodList.ets - @Component - struct FoodListItem { - private foodItem: FoodData - build() { - Navigator({ target: 'pages/FoodDetail' }) { - ...... - } - .params({ foodData: this.foodItem }) - } - } - ``` - - FoodGridItem调用的routerAPI同样有携带参数跳转的能力,使用方法和Navigator类似。 - - ``` - router.push({ - uri: 'pages/FoodDetail', - params: { foodData: this.foodItem } - }) - ``` - -2. FoodDetail页面引入FoodData类,在FoodDetail组件内添加foodItem成员变量。 - ``` - // FoodDetail.ets - import { FoodData } from '../model/FoodData' - - @Entry - @Component - struct FoodDetail { - private foodItem: FoodData - build() { - ...... - } - } - ``` - -3. 获取foodData对应的value。调用router.getParams().foodData来获取到FoodCategoryList页面跳转来时携带的foodDate对应的数据。 - ``` - @Entry - @Component - struct FoodDetail { - private foodItem: FoodData = router.getParams().foodData - - build() { - ...... - } - } - ``` - -4. 重构FoodDetail页面的组件。在构建视图时,FoodDetail页面的食物信息都是直接声明的常量,现在要用传递来的FoodData数据来对其进行重新赋值。整体的FoodDetail.ets代码如下。 - ``` - @Component - struct PageTitle { - build() { - Flex({ alignItems: ItemAlign.Start }) { - Image($r('app.media.Back')) - .width(21.8) - .height(19.6) - Text('Food Detail') - .fontSize(21.8) - .margin({left: 17.4}) - } - .height(61) - .backgroundColor('#FFedf2f5') - .padding({ top: 13, bottom: 15, left: 28.3 }) - .onClick(() => { - router.back() - }) - } - } - - @Component - struct FoodImageDisplay { - private foodItem: FoodData - build() { - Stack({ alignContent: Alignment.BottomStart }) { - Image(this.foodItem.image) - .objectFit(ImageFit.Contain) - Text(this.foodItem.name) - .fontSize(26) - .fontWeight(500) - .margin({ left: 26, bottom: 17.4 }) - } - .height(357) - .backgroundColor('#FFedf2f5') - } - } - - @Component - struct ContentTable { - private foodItem: FoodData - - @Builder IngredientItem(title:string, name: string, value: string) { - Flex() { - Text(title) - .fontSize(17.4) - .fontWeight(FontWeight.Bold) - .layoutWeight(1) - Flex() { - Text(name) - .fontSize(17.4) - .flexGrow(1) - Text(value) - .fontSize(17.4) - } - .layoutWeight(2) - } - } - - build() { - Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Start }) { - this.IngredientItem('Calories', 'Calories', this.foodItem.calories + 'kcal') - this.IngredientItem('Nutrition', 'Protein', this.foodItem.protein + 'g') - this.IngredientItem('', 'Fat', this.foodItem.fat + 'g') - this.IngredientItem('', 'Carbohydrates', this.foodItem.carbohydrates + 'g') - this.IngredientItem('', 'VitaminC', this.foodItem.vitaminC + 'mg') - } - .height(280) - .padding({ top: 30, right: 30, left: 30 }) - } - } - - @Entry - @Component - struct FoodDetail { - private foodItem: FoodData = router.getParams().foodData - - build() { - Column() { - Stack( { alignContent: Alignment.TopStart }) { - FoodImageDisplay({ foodItem: this.foodItem }) - PageTitle() - } - ContentTable({ foodItem: this.foodItem }) - } - .alignItems(HorizontalAlign.Center) - } - } - ``` - -## 相关实例 - -针对页面布局与连接,有以下示例工程可供参考: - -- [eTSDefiningPageLayoutAndConnection](https://gitee.com/openharmony/app_samples/tree/master/ETSUI/eTSDefiningPageLayoutAndConnection) - 本示例构建了食物分类列表页面和食物详情页,向开发者展示了List布局、Grid布局以及页面路由的基本用法。 diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/03.\345\252\222\344\275\223/01.\351\237\263\351\242\221/01.\351\237\263\351\242\221\345\274\200\345\217\221\346\246\202\350\277\260.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/03.\345\252\222\344\275\223/01.\351\237\263\351\242\221/01.\351\237\263\351\242\221\345\274\200\345\217\221\346\246\202\350\277\260.md" deleted file mode 100644 index 19353c09d52735af47c6f71eb0d86e0016a8a93e..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/03.\345\252\222\344\275\223/01.\351\237\263\351\242\221/01.\351\237\263\351\242\221\345\274\200\345\217\221\346\246\202\350\277\260.md" +++ /dev/null @@ -1,36 +0,0 @@ ---- -title: 音频开发概述 -permalink: /pages/0108030101 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# 音频开发概述 - -- [基本概念](#基本概念) - -OpenHarmony音频模块支持音频业务的开发,提供音频相关的功能,主要包括音频播放、音量管理等。 - - -## 基本概念 - -- **采样**
- 采样是指将连续时域上的模拟信号按照一定的时间间隔采样,获取到离散时域上离散信号的过程。 - -- **采样率**
- 采样率为每秒从连续信号中提取并组成离散信号的采样次数,单位用赫兹(Hz)来表示。通常人耳能听到频率范围大约在20Hz~20kHz之间的声音。常用的音频采样频率有:8kHz、11.025kHz、22.05kHz、16kHz、37.8kHz、44.1kHz、48kHz、96kHz、192kHz等。 - -- **声道**
- 声道是指声音在录制或播放时在不同空间位置采集或回放的相互独立的音频信号,所以声道数也就是声音录制时的音源数量或回放时相应的扬声器数量。 - -- **音频帧**
- 音频数据是流式的,本身没有明确的一帧帧的概念,在实际的应用中,为了音频算法处理/传输的方便,一般约定俗成取2.5ms~60ms为单位的数据量为一帧音频。这个时间被称之为“采样时间”,其长度没有特别的标准,它是根据编解码器和具体应用的需求来决定的。 - -- **PCM**
- PCM(Pulse Code Modulation),即脉冲编码调制,是一种将模拟信号数字化的方法,是将时间连续、取值连续的模拟信号转换成时间离散、抽样值离散的数字信号的过程。 diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/03.\345\252\222\344\275\223/01.\351\237\263\351\242\221/02.\351\237\263\351\242\221\346\222\255\346\224\276\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/03.\345\252\222\344\275\223/01.\351\237\263\351\242\221/02.\351\237\263\351\242\221\346\222\255\346\224\276\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index 0f99eae7e7083e9244150ce0843fbfe2f30e2fa3..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/03.\345\252\222\344\275\223/01.\351\237\263\351\242\221/02.\351\237\263\351\242\221\346\222\255\346\224\276\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,192 +0,0 @@ ---- -title: 音频播放开发指导 -permalink: /pages/0108030102 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# 音频播放开发指导 - -## 场景介绍 - -音频播放的主要工作是将音频数据转码为可听见的音频模拟信号并通过输出设备进行播放,同时对播放任务进行管理。 - -**图1** 音频播放状态机 - -![zh-ch_image_20220117](/images/application-dev/media/figures/zh-ch_image_20220117.jpg) - -## 音频播放开发步骤 - -详细API含义可参考:[js-apis-media.md](/pages/010c010302) - -### 全流程场景 - -包含流程:创建实例,设置uri,播放音频,跳转播放位置,设置音量,暂停播放,获取轨道信息,停止播放,重置,释放资源等流程。 - -AudioPlayer支持的src媒体源输入类型可参考:[src属性说明](/pages/010c010302#audioplayer_属性) - -```js -function SetCallBack(audioPlayer) { - audioPlayer.on('dataLoad', () => { //设置'dataLoad'事件回调,src属性设置成功后,触发此回调 - console.info('audio set source success'); - //播放界面可切换至已准备好,可点击播放按钮进行播放状态 - }); - audioPlayer.on('play', () => { //设置'play'事件回调 - console.info('audio play success'); - //将播放按钮切换至可暂停状态 - }); - audioPlayer.on('pause', () => { //设置'pause'事件回调 - console.info('audio pause success'); - //将播放按钮切换至可播放状态 - }); - audioPlayer.on('stop', () => { //设置'stop'事件回调 - console.info('audio stop success'); - //播放停止,播放进度条归零,播放按钮切换至可播放状态 - }); - audioPlayer.on('reset', () => { //设置'reset'事件回调 - console.info('audio reset success'); - //需重新设置src属性后,可继续播放其他音频 - }); - audioPlayer.on('timeUpdate', (seekDoneTime) => {//设置'timeUpdate'事件回调 - if (typeof(seekDoneTime) == 'undefined') { - console.info('audio seek fail'); - return; - } - console.info('audio seek success, and seek time is ' + seekDoneTime); - //播放进度条更新到seek对应的位置 - }); - audioPlayer.on('volumeChange', () => { //设置'volumeChange'事件回调 - console.info('audio volumeChange success'); - //更新音量显示 - }); - audioPlayer.on('finish', () => { //设置'finish'事件回调,播放完成触发 - console.info('audio play finish'); - }); - audioPlayer.on('error', (error) => { //设置'error'事件回调 - console.info(`audio error called, errName is ${error.name}`); - console.info(`audio error called, errCode is ${error.code}`); - console.info(`audio error called, errMessage is ${error.message}`); - }); -} - -function printfDescription(obj) { - for (let item in obj) { - let property = obj[item]; - console.info('audio key is ' + item); - console.info('audio value is ' + property); - } -} - -//1、创建实例 -let audioPlayer = media.createAudioPlayer(); -SetCallBack(audioPlayer); //设置事件回调 -//2、用户选择音频,设置uri -audioPlayer.src = 'file:///data/data/ohos.xxx.xxx/files/test.mp3'; //设置src属性,并触发'dataLoad'事件回调 -//3、播放音频 -audioPlayer.play(); //需等待'dataLoad'事件回调完成后,才可调用play进行播放,触发'play'事件回调 -//4、跳转播放位置 -audioPlayer.seek(30000); //触发'timeUpdate'事件回调,seek到30000ms处播放 -//5、设置音量 -audioPlayer.setVolume(0.5); //触发'volumeChange'事件回调 -//6、暂停播放 -audioPlayer.pause(); //触发'pause'事件回调,暂停播放 -//7、获取轨道信息 -audioPlayer.getTrackDescription((error, arrlist) => { //通过回调方式获取音频轨道信息 - if (typeof (arrlist) != 'undefined') { - for (let i = 0; i < arrlist.length; i++) { - printfDescription(arrlist[i]); - } - } else { - console.log(`audio getTrackDescription fail, error:${error.message}`); - } -}); -//8、停止播放 -audioPlayer.stop(); //触发'stop'事件回调 -//9、重置播放资源 -audioPlayer.reset(); //触发'reset'事件回调后,重新设置src属性,可完成切歌 -//10、释放资源 -audioPlayer.release(); //audioPlayer资源被销毁 -audioPlayer = undefined; -``` - -### 正常播放场景 - -```js -function SetCallBack(audioPlayer) { - audioPlayer.on('dataLoad', () => { //设置'dataLoad'事件回调,src属性设置成功后,触发此回调 - console.info('audio set source success'); - audioPlayer.play(); //调用play方法开始播放,触发'play'事件回调 - }); - audioPlayer.on('play', () => { //设置'play'事件回调 - console.info('audio play success'); - }); - audioPlayer.on('finish', () => { //设置'finish'事件回调,播放完成触发 - console.info('audio play finish'); - audioPlayer.release(); //audioPlayer资源被销毁 - audioPlayer = undefined; - }); -} - -let audioPlayer = media.createAudioPlayer(); //创建一个音频播放实例 -SetCallBack(audioPlayer); //设置事件回调 -/* 用户选择音频,设置uri */ -audioPlayer.src = 'file:///data/data/ohos.xxx.xxx/files/test.mp3'; //设置src属性,并触发'dataLoad'事件回调 -``` - -### 切歌场景 - -```js -function SetCallBack(audioPlayer) { - audioPlayer.on('dataLoad', () => { //设置'dataLoad'事件回调,src属性设置成功后,触发此回调 - console.info('audio set source success'); - audioPlayer.play(); //调用play方法开始播放,触发'play'事件回调 - }); - audioPlayer.on('play', () => { //设置'play'事件回调 - console.info('audio play success'); - }); - audioPlayer.on('finish', () => { //设置'finish'事件回调,播放完成触发 - console.info('audio play finish'); - audioPlayer.release(); //audioPlayer资源被销毁 - audioPlayer = undefined; - }); -} - -let audioPlayer = media.createAudioPlayer(); //创建一个音频播放实例 -SetCallBack(audioPlayer); //设置事件回调 -/* 用户选择音频,设置uri */ -audioPlayer.src = 'file:///data/data/ohos.xxx.xxx/files/test.mp3'; //设置src属性,并触发'dataLoad'事件回调 -/* 播放一段时间后,下发切歌指令 */ -audioPlayer.reset(); -audioPlayer.src = 'file:///data/data/ohos.xxx.xxx/files/next.mp3'; -``` - -### 单曲循环场景 - -```js -function SetCallBack(audioPlayer) { - audioPlayer.on('dataLoad', () => { //设置'dataLoad'事件回调,src属性设置成功后,触发此回调 - console.info('audio set source success'); - audioPlayer.play(); //调用play方法开始播放,触发'play'事件回调 - }); - audioPlayer.on('play', () => { //设置'play'事件回调 - console.info('audio play success'); - }); - audioPlayer.on('finish', () => { //设置'finish'事件回调,播放完成触发 - console.info('audio play finish'); - audioPlayer.release(); //audioPlayer资源被销毁 - audioPlayer = undefined; - }); -} - -let audioPlayer = media.createAudioPlayer(); //创建一个音频播放实例 -SetCallBack(audioPlayer); //设置事件回调 -/* 用户选择音频,设置uri */ -audioPlayer.src = 'file:///data/data/ohos.xxx.xxx/files/test.mp3'; //设置src属性,并触发'dataLoad'事件回调 -audioPlayer.loop = true; //设置循环播放属性 -``` \ No newline at end of file diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/03.\345\252\222\344\275\223/01.\351\237\263\351\242\221/03.\351\237\263\351\242\221\347\256\241\347\220\206\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/03.\345\252\222\344\275\223/01.\351\237\263\351\242\221/03.\351\237\263\351\242\221\347\256\241\347\220\206\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index 3e2d9a702f4ecabe9a770fd38cd89ebc3f8f6ab2..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/03.\345\252\222\344\275\223/01.\351\237\263\351\242\221/03.\351\237\263\351\242\221\347\256\241\347\220\206\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,111 +0,0 @@ ---- -title: 音频管理开发指导 -permalink: /pages/0108030103 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# 音频管理开发指导 - -- [场景介绍](#场景介绍) -- [接口说明](#接口说明) -- [开发步骤](#开发步骤) - -## 场景介绍 - -音频管理的主要工作是音量调节与音量查询,以及输入/输出设备查询。 - - -## 接口说明 - -**表1** audio的相关接口 - -| 接口名 | 描述 | -| -------- | -------- | -| getAudioManager(): AudioManager | 获得音频管理器。 | -| AudioManager | 音频管理器。具体参考表 音频管理相关的interface AudioManager。 | -| AudioDeviceDescriptor | 描述音频设备。 | -| AudioVolumeType | 表示音频流类型的枚举。 | -| DeviceFlag | 表示可获取的设备种类的枚举。 | -| DeviceRole | 表示设备角色的枚举。 | -| DeviceType | 表示设备类型的枚举。 | - -**表2** 音频管理相关的interface **AudioManager** - -| 接口名 | 描述 | -| -------- | -------- | -| setVolume(audioType: AudioVolumeType,volume: number,callback: AsyncCallback<void>): void | 改变某个流的音量。 | -| setVolume(audioType: AudioVolumeType,volume: number): Promise<void> | 改变某个流的音量。 | -| getVolume(audioType: AudioVolumeType, callback: AsyncCallback<number>): void | 获得某个流的音量。 | -| getVolume(audioType: AudioVolumeType): Promise<number> | 获得某个流的音量。 | -| getMinVolume(audioType: AudioVolumeType, callback: AsyncCallback<number>): void | 获得某个流的最小音量。 | -| getMinVolume(audioType: AudioVolumeType): Promise<number> | 获得某个流的最小音量。 | -| getMaxVolume(audioType: AudioVolumeType, callback: AsyncCallback<number>): void | 获得某个流的最大音量。 | -| getMaxVolume(audioType: AudioVolumeType): Promise<number> | 获得某个流的最大音量。 | -| getDevices(deviceFlag: DeviceFlag, callback: AsyncCallback<AudioDeviceDescriptors>): void | 获得设备列表。 | -| getDevices(deviceFlag: DeviceFlag): Promise<AudioDeviceDescriptors> | 获得设备列表。 | - -**表3** 表示音频设备的interface **AudioDeviceDescriptor** - -| 属性 | 描述 | -| -------- | -------- | -| deviceRole: DeviceRole | 设备角色。 | -| deviceType: DeviceType | 设备类型。 | - -**表4** 表示音频流类型的枚举**AudioVolumeType** - -| 枚举值 | 描述 | -| -------- | -------- | -| MEDIA = 1 | 媒体声音。 | -| RINGTONE = 2 | 铃声。 | - -**表5** 表示可获取的设备种类的枚举**DeviceFlag** - -| 枚举值 | 描述 | -| -------- | -------- | -| OUTPUT_DEVICES_FLAG = 1 | 输出设备。 | -| INPUT_DEVICES_FLAG = 2 | 输入设备。 | -| ALL_DEVICES_FLAG = 3 | 所有设备。 | - -**表6** 表示设备角色的枚举**DeviceRole** - -| 枚举值 | 描述 | -| -------- | -------- | -| INPUT_DEVICE = 1 | 输入设备。 | -| OUTPUT_DEVICE = 2 | 输出设备。 | - -**表7** 表示设备类型的枚举**DeviceType** - -| 枚举值 | 描述 | -| -------- | -------- | -| INVALID = 0 | 无效。 | -| SPEAKER = 1 | 扬声器。 | -| WIRED_HEADSET = 2 | 有线耳机。 | -| BLUETOOTH_SCO = 3 | 蓝牙设备。 | -| BLUETOOTH_A2DP = 4 | 支持A2DP的蓝牙设备。 | -| MIC = 5 | 麦克风。 | - - -## 开发步骤 - -1. 获取音频控制器。 - ``` - const audioManager = audio.getAudioManager(); - ``` - -2. 改变媒体流的声音。 - ``` - audioManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => { - if (err) { - console.error(`failed to get volume ${err.message}`); - return; - } - console.log(`Media getVolume ${value}`); - }); - ``` diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/03.\345\252\222\344\275\223/01.\351\237\263\351\242\221/04.\351\237\263\351\242\221\345\275\225\345\210\266\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/03.\345\252\222\344\275\223/01.\351\237\263\351\242\221/04.\351\237\263\351\242\221\345\275\225\345\210\266\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index 7815e7fc5d715b3ee67cf9e96843f84db2fe3c24..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/03.\345\252\222\344\275\223/01.\351\237\263\351\242\221/04.\351\237\263\351\242\221\345\275\225\345\210\266\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,133 +0,0 @@ ---- -title: 音频录制开发指导 -permalink: /pages/0108030104 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# 音频录制开发指导 - -- [场景介绍](#场景介绍) -- [接口说明](#接口说明) - -## 场景介绍 - -音频录制的主要工作是将音频信号记录并保存下来,同时提供包括采样率、声道数、码率、编码格式、封装格式、文件路径等设置功能。 - - -## 接口说明 - -**表1** media - -| 接口名 | 描述 | -| -------- | -------- | -| media.createAudioRecorder() | 创建AudioRecorder实例。 | -| AudioRecorder | 提供音频录制相关功能。 | -| AudioRecorderConfig | 提供音频录制相关参数设置。 | - -**表2** 音频录制相关的interface **AudioRecorder** - -| 接口名 | 描述 | -| -------- | -------- | -| prepare(config: AudioRecorderConfig): void | 准备音频录制并设置参数。 | -| start(): void | 开始音频录制。 | -| pause(): void | 暂停音频录制。(暂不支持) | -| resume(): void | 恢复音频录制。(暂不支持) | -| stop(): void | 停止音频录制。 | -| release(): void | 释放音频录制资源。 | -| reset(): void | 重置音频录制。 | -| on('prepare', function callback) | 订阅音频录制准备事件。 | -| on('start', function callback) | 订阅音频录制开始事件。 | -| on('pause', function callback) | 订阅音频录制暂停事件。 | -| on('resume', function callback) | 订阅音频录制恢复事件。 | -| on('stop',function callback) | 订阅音频录制结束事件。 | -| on('release', function callback) | 订阅音频录制释放资源事件。 | -| on('reset', function callback) | 订阅音频录制重置事件。 | -| on('error', function callback) | 订阅音频录制错误事件。 | - -**表3** 音频录制的相关参数的interface **AudioRecorderConfig** - -| 接口名 | 描述 | -| -------- | -------- | -| audioEncoder?: AudioEncoder | 音频编码格式,默认值是AAC_LC。 | -| audioEncodeBitRate?: number | 音频编码的比特率,默认值为48000。 | -| audioSampleRate?: number | 音频编码的采样率,默认值为48000。 | -| numberOfChannels?:number | 音频的声道数,默认值为2。 | -| format?: AudioOutputFormat | 音频的输出格式,默认值是MPEG_4。 | -| uri: string | 音频的输出路径。(file://path 或者 file://fd) | - -**表4** AudioEncoder的相关参数的interface **AudioEncoder** - -| 接口名 | 描述 | -| -------- | -------- | -| AAC_LC = 3 | 表示AAC_LC编码格式。 | - -**表5** 音频输出格式的相关参数的interface **AudioOutputFormat** - -| 接口名 | 描述 | -| -------- | -------- | -| MPEG_4 = 2 | 表示MPEG_4编码格式。 | -| AAC_ADTS= 6 | 表示AAC_ADTS编码格式。 | - -1. 创建音频录制器。 - ``` - import media from '@ohos.multimedia.media'; - var recorder = media.createAudioRecorder(); - ``` - -2. 准备音频录制参数。 - ``` - let audioRecorderConfig = { - audioEncoder : AAC_LC , - audioEncodeBitRate : 22050, - audioSampleRate : 22050, - numberOfChannels : 2, - format : AAC_ADTS, - uri : 'file:///data/accounts/account_0/appdata/appdata/recorder/test.m4a', - } - recorder.prepare(audioRecorderConfig); - ``` - -3. 设置消息订阅事件。 - ``` - recorder.on('prepare', () => { - console.info('setCallback prepare() case callback is called'); - recorder.start(); - }); - recorder.on('start', () => { - console.info('setCallback start() case callback is called'); - setTimeout(function(){ - recorder.pause(); - }, 10000); // 开始录音10秒后,暂停录音。 - }); - recorder.on('pause', () => { - console.info('setCallback pause() case callback is called'); - setTimeout(function(){ - recorder.resume(); - }, 10000); // 暂停录音10秒后,恢复录音。 - }); - recorder.on('resume', () => { - console.info('setCallback resume() case callback is called'); - setTimeout(function(){ - recorder.stop(); - }, 10000); // 恢复录音10秒后,停止录音。 - }); - recorder.on('stop', () => { - console.info('setCallback stop() case callback is called'); - recorder.release(); - }); - recorder.on('release', () => { - console.info('setCallback release() case callback is called'); - }); - recorder.on('error', (err) => { - console.info(`case error called,errCode is ${err.code}`); - console.info(`case error called,errMessage is ${err.message}`); - recorder.reset(); - }); - ``` diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/04.\347\224\250\346\210\267\350\256\244\350\257\201/01.\347\224\250\346\210\267\350\256\244\350\257\201\345\274\200\345\217\221\346\246\202\350\277\260.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/04.\347\224\250\346\210\267\350\256\244\350\257\201/01.\347\224\250\346\210\267\350\256\244\350\257\201\345\274\200\345\217\221\346\246\202\350\277\260.md" deleted file mode 100644 index 114c6574e8597c8f6f42cec67b547e1a13823309..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/04.\347\224\250\346\210\267\350\256\244\350\257\201/01.\347\224\250\346\210\267\350\256\244\350\257\201\345\274\200\345\217\221\346\246\202\350\277\260.md" +++ /dev/null @@ -1,37 +0,0 @@ ---- -title: 用户认证开发概述 -permalink: /pages/01080401 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# 用户认证开发概述 - -提供用户认证能力,可应用于设备解锁、支付、应用登录等身份认证场景。 - -当前用户认证能力提供2D人脸识别、3D人脸识别两种人脸识别能力,设备具备哪种识别能力,取决于设备的硬件能力和技术实现。 - -3D人脸识别技术识别率、防伪能力都优于2D人脸识别技术,但具有3D人脸能力(比如3D结构光、3D TOF等)的设备才可以使用3D人脸识别技术。 - -## 基本概念 - -人脸识别:基于人的脸部特征信息进行身份识别的一种生物特征识别技术,用摄像机或摄像头采集含有人脸的图像或视频流,并自动在图像中检测和跟踪人脸,进而对检测到的人脸进行脸部识别,通常也叫做人像识别、面部识别、人脸认证。 - -## 运作机制 - -人脸识别会在摄像头和TEE(Trusted Execution Environment)之间建立安全通道,人脸图像信息通过安全通道传递到TEE中,由于人脸图像信息从REE(Rich Execution Environment)侧无法获取,从而避免了恶意软件从REE侧进行攻击。对人脸图像采集、特征提取、活体检测、特征比对等处理完全在TEE中,基于TrustZone进行安全隔离,外部的人脸框架只负责人脸的认证发起和处理认证结果等数据,不涉及人脸数据本身。 - -人脸特征数据通过TEE的安全存储区进行存储,采用高强度的密码算法对人脸特征数据进行加密和完整性保护,外部无法获取到加密人脸特征数据的密钥,保证用户的人脸特征数据不会泄露。本能力采集和存储的人脸特征数据不会在用户未授权的情况下被传出TEE,这意味着,用户未授权时,无论是系统应用还是三方应用都无法获得人脸特征数据,也无法将人脸特征数据传送或备份到任何外部存储介质。 - -## 约束与限制 - -- 当前版本提供的用户认证能力只包含人脸识别,且只支持本地认证,不提供认证界面。 -- 要求设备上具备摄像器件,且人脸图像像素大于100*100。 -- 要求设备上具有TEE安全环境,人脸特征信息高强度加密保存在TEE中。 -- 对于面部特征相似的人、面部特征不断发育的儿童,人脸特征匹配率有所不同。如果对此担忧,可考虑其他认证方式。 \ No newline at end of file diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/04.\347\224\250\346\210\267\350\256\244\350\257\201/02.\347\224\250\346\210\267\350\256\244\350\257\201\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/04.\347\224\250\346\210\267\350\256\244\350\257\201/02.\347\224\250\346\210\267\350\256\244\350\257\201\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index 19b07b67b26729cf583e2a35ecbec292271067fe..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/04.\347\224\250\346\210\267\350\256\244\350\257\201/02.\347\224\250\346\210\267\350\256\244\350\257\201\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,114 +0,0 @@ ---- -title: 用户认证开发指导 -permalink: /pages/01080402 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# 用户认证开发指导 - -## 场景介绍 - -当前用户认证支持2D人脸识别、3D人脸识别,可应用于设备解锁、应用登录、支付等身份认证场景。 - -## 接口说明 - -userIAM_userAuth模块提供了用户认证的相关方法,包括检测认证能力、认证和取消认证等,用户可以通过人脸等生物特征信息进行认证操作。具体接口说明可以查阅[API参考](/pages/010c010401)。 - -在执行认证前,需要检查设备是否支持该认证能力,具体指认证类型、安全级别和是否本地认证。如果不支持,需要考虑使用其他认证能力。 - -**表1** 用户认证开放能力列表 - -| 接口名 | 功能描述 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| getAuthenticator(): Authenticator | 获取Authenticator对象,用于执行用户身份认证。6+
获取Authenticator对象,用于检测设备身份认证能力、执行和取消用户身份认证,获取认证过程中的提示信息。7+ | -| checkAvailability(type: AuthType, level: SecureLevel): number | 根据指定的认证类型、安全等级,检测当前设备是否支持相应的认证能力。 | -| execute(type: AuthType, level: SecureLevel, callback: AsyncCallback\): void | 执行用户认证,使用callback方式作为异步方法。 | -| execute(type: AuthType, level: SecureLevel): Promise\ | 执行用户认证,使用Promise方式作为异步方法。 | -| cancel(): void | 取消当前的认证流程。 | -| on(type: "tip", callback: Callback\): void | 订阅指定类型的事件。 | -| off(type: "tip", callback?: Callback\): void | 取消订阅指定类型的事件。 | - -## 开发步骤 - -开发前请完成以下准备工作: - -1. 在应用配置权限文件中,增加ohos.permission.ACCESS_BIOMETRIC的权限声明。 -2. 在使用用户认证能力的代码文件中增加import userIAM_userAuth from '@ohos.userIAM.userAuth'。 - -开发过程: - -1. 获取Authenticator的单例对象,代码示例如下: - - ```js - let auth = userIAM_userAuth.getAuthenticator(); - ``` - -2. 检测设备是否具有指定级别的认证能力: - - 2D人脸识别支持低于S2级别的认证,3D人脸识别支持低于S3级别的认证。代码示例如下: - - ```js - let authenticator = userIAM_userAuth.getAuthenticator(); - let checkCode = authenticator.checkAvailability("FACE_ONLY", "S2"); - if (checkCode == userIAM_userAuth.CheckAvailabilityResult.SUPPORTED) { - console.info("check auth support success"); - } else { - console.error("check auth support fail, code = " + checkCode); - } - ``` - -3. (可选)订阅人脸tip信息,代码示例如下: - - ```js - let authenticator = userIAM_userAuth.getAuthenticator(); - let tipCallback = (tip)=>{ - console.info("receive tip: errorCode(" + tip.errorCode + ") code(" + tip.tipCode +") event(" + - tip.tipEvent + ") info(" + tip.tipInfo + ")"); - }; - authenticator.on("tip", tipCallback); - ``` - -4. 执行认证操作,代码示例如下: - - ```js - let authenticator = userIAM_userAuth.getAuthenticator(); - authenticator.execute("FACE_ONLY", "S2").then((code)=>{ - authenticator.off("tip", tipCallback); - console.info("auth success"); - }).catch((code)=>{ - authenticator.off("tip", tipCallback); - console.error("auth fail, code = " + code); - }); - ``` - -5. (仅执行订阅信息后需要)取消订阅人脸tip信息: - - ```js - let authenticator = userIAM_userAuth.getAuthenticator(); - let tipCallback = (tip)=>{ - console.info("receive tip: errorCode(" + tip.errorCode + ") code(" + tip.tipCode + ") event(" + - tip.tipEvent + ") info(" + tip.tipInfo + ")"); - }; - // 取消订阅指定回调 - authenticator.off("tip", tipCallback); - // 取消订阅所有回调authenticator.off("tip"); - ``` - -6. 认证过程中取消认证,代码示例如下: - - ```js - let authenticator = userIAM_userAuth.getAuthenticator(); - let cancelCode = authenticator.cancel(); - if (cancelCode == userIAM_userAuth.Result.SUCCESS) { - console.info("cancel auth success"); - } else { - console.error("cancel auth fail"); - } - ``` \ No newline at end of file diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/05.IPC\344\270\216RPC\351\200\232\344\277\241/01.IPC\344\270\216RPC\351\200\232\344\277\241\346\246\202\350\277\260.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/05.IPC\344\270\216RPC\351\200\232\344\277\241/01.IPC\344\270\216RPC\351\200\232\344\277\241\346\246\202\350\277\260.md" deleted file mode 100644 index 8422cbbbd1538f7db254dc5f0db5034c4967cfc7..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/05.IPC\344\270\216RPC\351\200\232\344\277\241/01.IPC\344\270\216RPC\351\200\232\344\277\241\346\246\202\350\277\260.md" +++ /dev/null @@ -1,33 +0,0 @@ ---- -title: IPC与RPC通信概述 -permalink: /pages/01080501 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# IPC与RPC通信概述 - -- [基本概念](#基本概念) -- [约束与限制](#约束与限制) -- [相关模块](#相关模块) - -## 基本概念 - -IPC(Inter-Process Communication)与RPC(Remote Procedure Call)机制用于实现跨进程通信,不同的是前者使用Binder驱动,用于设备内的跨进程通信,而后者使用软总线驱动,用于跨设备跨进程通信。IPC和RPC通常采用客户端-服务器(Client-Server)模型,服务请求方(Client)可获取提供服务提供方(Server)的代理 (Proxy),并通过此代理读写数据来实现进程间的数据通信。通常,Server会先注册系统能力(System Ability)到系统能力管理者(System Ability Manager,缩写SAMgr)中,SAMgr负责管理这些SA并向Client提供相关的接口。Client要和某个具体的SA通信,必须先从SAMgr中获取该SA的代理,然后使用代理和SA通信。下文使用Proxy表示服务请求方,Stub表示服务提供方。 - - -## 约束与限制 - -单个设备上跨进程通信时,传输的数据量最大约为1MB,过大的数据量请使用匿名共享内存。 -不支持把跨设备的Proxy对象传递回该Proxy对象所指向的Stub对象所在的设备。 - - -## 相关模块 - -分布式任务调度子系统 diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/05.IPC\344\270\216RPC\351\200\232\344\277\241/02.IPC\344\270\216RPC\351\200\232\344\277\241\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/05.IPC\344\270\216RPC\351\200\232\344\277\241/02.IPC\344\270\216RPC\351\200\232\344\277\241\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index aa5b2612ae0de14604290a160b4d24858579e76c..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/05.IPC\344\270\216RPC\351\200\232\344\277\241/02.IPC\344\270\216RPC\351\200\232\344\277\241\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,146 +0,0 @@ ---- -title: IPC与RPC通信开发指导 -permalink: /pages/01080502 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# IPC与RPC通信开发指导 - -- [场景介绍](#场景介绍) -- [接口说明](#接口说明) -- [开发步骤](#开发步骤) - -## 场景介绍 - -IPC/RPC的主要工作是让运行在不同进程的Proxy和Stub互相通信,包括Proxy和Stub运行在不同设备的情况。 - - -## 接口说明 - -**表1** Native侧IPC接口 - -| 类/接口 | 方法 | 功能说明 | -| -------- | -------- | -------- | -| IRemoteBroker | sptr<IRemoteObject> AsObject() | 返回通信对象。派生类需要实现,Stub端返回RemoteObject对象本身,Proxy端返回代理对象。 | -| IRemoteStub | virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) | 请求处理方法,派生类需要重写,处理Proxy的请求并返回结果。 | -| IRemoteProxy | | 业务Proxy类派生自IRemoteProxy类。 | - - -## 开发步骤 - -**Native侧开发步骤** - -1. 定义IPC接口ITestAbility - SA接口继承IPC基类接口IRemoteBroker,接口里定义描述符、业务函数和消息码,其中业务函数在Proxy端和Stub端都需要实现。 - - ``` - class ITestAbility : public IRemoteBroker { - public: - // DECLARE_INTERFACE_DESCRIPTOR是必须的,入参需使用std::u16string; - DECLARE_INTERFACE_DESCRIPTOR(u"test.ITestAbility"); - int TRANS_ID_PING_ABILITY = 1; // 定义消息码 - virtual int TestPingAbility(const std::u16string &dummy) = 0; // 定义业务函数 - }; - ``` - -2. 定义和实现服务端TestAbilityStub - 该类是和IPC框架相关的实现,需要继承 IRemoteStub<ITestAbility>。Stub端作为接收请求的一端,需重写OnRemoteRequest方法用于接收客户端调用。 - - ``` - class TestAbilityStub : public IRemoteStub { - public: - virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - int TestPingAbility(const std::u16string &dummy) override; - }; - - int TestServiceStub::OnRemoteRequest(uint32_t code, - MessageParcel &data, MessageParcel &reply, MessageOption &option) - { - switch (code) { - case TRANS_ID_PING_ABILITY: { - std::u16string dummy = data.ReadString16(); - int result = TestPingAbility(dummy); - reply.WriteInt32(result); - return 0; - } - default: - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } - } - ``` - -3. 定义服务端业务函数具体实现类TestAbility - ``` - class TestAbility : public TestAbilityStub { - public: - int TestPingAbility(const std::u16string &dummy); - } - - int TestAbility::TestPingAbility(const std::u16string &dummy) { - return 0; - } - ``` - -4. 定义和实现客户端 TestAbilityProxy - 该类是Proxy端实现,继承IRemoteProxy<ITestAbility>,调用SendRequest接口向Stub端发送请求,对外暴露服务端提供的能力。 - - ``` - class TestAbilityProxy : public IRemoteProxy { - public: - explicit TestAbilityProxy(const sptr &impl); - int TestPingService(const std::u16string &dummy) override; - private: - static inline BrokerDelegator delegator_; // 方便后续使用iface_cast宏 - } - - TestAbilityProxy::TestAbilityProxy(const sptr &impl) - : IRemoteProxy(impl) - { - } - - int TestAbilityProxy::TestPingService(const std::u16string &dummy){ - MessageOption option; - MessageParcel dataParcel, replyParcel; - dataParcel.WriteString16(dummy); - int error = Remote()->SendRequest(TRANS_ID_PING_ABILITY, dataParcel, replyParcel, option); - int result = (error == ERR_NONE) ? replyParcel.ReadInt32() : -1; - return result; - } - ``` - -5. SA 注册与启动 - SA 需要将自己的 TestAbilityStub实例通过 AddSystemAbility接口注册到 SystemAbilityManager,设备内与分布式的注册参数不同。 - - ``` - // 注册到本设备内 - auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - samgr->AddSystemAbility(said, new TestAbility()); - - // 在组网场景下,会被同步到其他设备上 - auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - ISystemAbilityManager::SAExtraProp saExtra; - saExtra.isDistributed = true; // 设置为分布式SA - int result = samgr->AddSystemAbility(said, new TestAbility(), saExtra); - ``` - -6. SA 获取与调用 - 通过SystemAbilityManager的GetSystemAbility方法可获取到对应SA的代理IRemoteObject,然后构造TestAbilityProxy即可。 - - ``` - // 获取本设备内注册的SA的proxy - sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - sptr remoteObject = samgr->GetSystemAbility(said); - sptr testAbility = iface_cast(remoteObject); // 使用iface_cast宏转换成具体类型 - - // 获取其他设备注册的SA的Proxy - sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - sptr remoteObject = samgr->GetSystemAbility(sdid, deviceId); // deviceId是指定设备的标识符 - sptr proxy(new TestAbilityProxy(remoteObject)); // 直接构造具体Proxy - ``` diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/05.IPC\344\270\216RPC\351\200\232\344\277\241/03.\350\277\234\347\253\257\347\212\266\346\200\201\350\256\242\351\230\205\345\274\200\345\217\221\345\256\236\344\276\213.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/05.IPC\344\270\216RPC\351\200\232\344\277\241/03.\350\277\234\347\253\257\347\212\266\346\200\201\350\256\242\351\230\205\345\274\200\345\217\221\345\256\236\344\276\213.md" deleted file mode 100644 index bc72b4b5f089ec6a7e1b8e1d5338a42ca9534a89..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/05.IPC\344\270\216RPC\351\200\232\344\277\241/03.\350\277\234\347\253\257\347\212\266\346\200\201\350\256\242\351\230\205\345\274\200\345\217\221\345\256\236\344\276\213.md" +++ /dev/null @@ -1,45 +0,0 @@ ---- -title: 远端状态订阅开发实例 -permalink: /pages/01080503 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# 远端状态订阅开发实例 - -IPC/RPC 提供对远端 Stub对象状态的订阅机制, 在远端 Stub对象死亡时,可触发死亡通知告诉本地 Proxy对象。这种状态通知订阅并不会自动附加在每个本地 Proxy对象上,需要调用特定接口完成,当不再需要订阅时也需要调用特定接口取消。使用这种订阅机制的用户,需要实现死亡通知接口DeathRecipient并实现onRemoteDied方法,清理资源,该方法会在 远端 Stub对象所在进程死亡,或所在设备离开组网时被回调。值得注意的是,调用这些接口有一定的顺序。首先,需要 Proxy订阅 Stub死亡通知,若在订阅期间Stub状态正常,则可在不再需要时取消订阅;若在订阅期间 Stub所在进程退出,或者所在设备退出组网,则会自动触发 Proxy自定义的后续操作。 - - - - -**Native侧接口** - - -依次为添加对远端Stub对象状态订阅的接口,取消订阅的接口,及感知到远端Stub对象死亡而进行本地操作的接口: - - -``` -bool AddDeathRecipient(const sptr &recipient); -bool RemoveDeathRecipient(const sptr &recipient); -void OnRemoteDied(const wptr &object); -``` - - -参考代码 - - -``` -class TestDeathRecipient : public IRemoteObject::DeathRecipient { -public: - virtual void OnRemoteDied(const wptr& remoteObject); -} -sptr deathRecipient (new TestDeathRecipient());// 构造一个死亡通知对象 -bool result = proxy->AddDeathRecipient(deathRecipient); // 注册死亡通知 -result = proxy->RemoveDeathRecipient(deathRecipient); // 移除死亡通知 -``` diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/06.\345\210\206\345\270\203\345\274\217\346\225\260\346\215\256\346\234\215\345\212\241/01.\345\210\206\345\270\203\345\274\217\346\225\260\346\215\256\346\234\215\345\212\241\346\246\202\350\277\260.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/06.\345\210\206\345\270\203\345\274\217\346\225\260\346\215\256\346\234\215\345\212\241/01.\345\210\206\345\270\203\345\274\217\346\225\260\346\215\256\346\234\215\345\212\241\346\246\202\350\277\260.md" deleted file mode 100644 index be9a42af42c832989b2575bd139d66ecbcf05168..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/06.\345\210\206\345\270\203\345\274\217\346\225\260\346\215\256\346\234\215\345\212\241/01.\345\210\206\345\270\203\345\274\217\346\225\260\346\215\256\346\234\215\345\212\241\346\246\202\350\277\260.md" +++ /dev/null @@ -1,105 +0,0 @@ ---- -title: 分布式数据服务概述 -permalink: /pages/01080601 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# 分布式数据服务概述 - -分布式数据服务(Distributed Data Service,DDS) 为应用程序提供不同设备间数据库的分布式协同能力。通过调用分布式数据接口,应用程序将数据保存到分布式数据库中。通过结合帐号、应用和数据库三元组,分布式数据服务对属于不同应用的数据进行隔离,保证不同应用之间的数据不能通过分布式数据服务互相访问。在通过可信认证的设备间,分布式数据服务支持应用数据相互同步,为用户提供在多种终端设备上最终一致的数据访问体验。 - - -## 基本概念 - -- **KV数据模型** - “KV数据模型”是“Key-Value数据模型”的简称,“Key-Value”即“键-值”;其数据以键值对的形式进行组织、索引和存储。 - - KV数据模型适合不涉及过多数据关系和业务关系的业务数据存储,比SQL数据库存储拥有更好的读写性能,同时因其在分布式场景中降低了解决数据库版本兼容问题的复杂度,和数据同步过程中冲突解决的复杂度而被广泛使用。分布式数据库也是基于KV数据模型,对外提供KV类型的访问接口。 - -- **分布式数据库事务性** - 分布式数据库事务支持本地事务(和传统数据库的事务概念一致)和同步事务。同步事务是指在设备之间同步数据时,以本地事务为单位进行同步,一次本地事务的修改要么都同步成功,要么都同步失败。 - -- **分布式数据库一致性** - 在分布式场景中一般会涉及多个设备,组网内设备之间看到的数据是否一致称为分布式数据库的一致性。分布式数据库一致性可以分为**强一致性**、**弱一致性**和**最终一致性**。 - - - **强一致性**:是指某一设备成功增、删、改数据后,组网内设备对该数据的读取操作都将得到更新后的值。 - - **弱一致性**:是指某一设备成功增、删、改数据后,组网内设备可能读取到本次更新数据,也可能读取不到,不能保证在多长时间后每个设备的数据一定是一致的。 - - **最终一致性**:是指某一设备成功增、删、改数据后,组网内设备可能读取不到本次更新数据,但在某个时间窗口之后组网内设备的数据能够达到一致状态。 - - 强一致性对分布式数据的管理要求非常高,在服务器的分布式场景可能会遇到。因为移动终端设备的不常在线、以及无中心的特性,分布式数据服务不支持强一致性,只支持最终一致性。 - -- **分布式数据库同步** - 底层通信组件完成设备发现和认证,会通知上层应用程序(包括分布式数据服务)设备上线。收到设备上线的消息后分布式数据服务可以在两个设备之间建立加密的数据传输通道,利用该通道在两个设备之间进行数据同步。 - - 分布式数据服务提供了两种同步方式:**手动同步**和**自动同步**。 - - - **手动同步**:由应用程序调用sync接口来触发,需要指定同步的设备列表和同步模式。同步模式分为PULL_ONLY(将远端数据拉到本端)、PUSH_ONLY(将本端数据推送到远端)和PUSH_PULL(将本端数据推送到远端同时也将远端数据拉取到本端)。内部接口支持按条件过滤同步,将符合条件的数据同步到远端。 - - **自动同步**:包括全量同步和按条件订阅同步。全量同步由分布式数据库自动将本端数据推送到远端,同时也将远端数据拉取到本端来完成数据同步,同步时机包括设备上线、应用程序更新数据等,应用不需要主动调用sync接口;内部接口支持按条件订阅同步,将远端符合订阅条件的数据自动同步到本端。 - -- **单版本分布式数据库** - 单版本是指数据在本地保存是以单个KV条目为单位的方式保存,对每个Key最多只保存一个条目项,当数据在本地被用户修改时,不管它是否已经被同步出去,均直接在这个条目上进行修改。同步也以此为基础,按照它在本地被写入或更改的顺序将当前最新一次修改逐条同步至远端设备。 - -- **设备协同分布式数据库** - 设备协同分布式数据库建立在单版本分布式数据库之上,对应用程序存入的KV数据中的Key前面拼接了本设备的DeviceID标识符,这样能保证每个设备产生的数据严格隔离,底层按照设备的维度管理这些数据,设备协同分布式数据库支持以设备的维度查询分布式数据,但是不支持修改远端设备同步过来的数据。 - -- **分布式数据库冲突解决策略** - 分布式数据库多设备提交冲突场景,在给提交冲突做合并的过程中,如果多个设备同时修改了同一数据,则称这种场景为数据冲突。数据冲突采用默认冲突解决策略(Last-write-wins),基于提交时间戳,取时间戳较大的提交数据,当前不支持定制冲突解决策略。 - -- **数据库Schema化管理与谓词查询** - 单版本数据库支持在创建和打开数据库时指定Schema,数据库根据Schema定义感知KV记录的Value格式,以实现对Value值结构的检查,并基于Value中的字段实现索引建立和谓词查询。 - -- **分布式数据库备份能力** - 提供分布式数据库备份能力,业务通过设置backup属性为true,可以触发分布式数据服务每日备份。当分布式数据库发生损坏,分布式数据服务会删除损坏数据库,并且从备份数据库中恢复上次备份的数据。如果不存在备份数据库,则创建一个新的数据库。同时支持加密数据库的备份能力。 - - -## 运作机制 - -分布式数据服务支撑OpenHarmony系统上应用程序数据库数据分布式管理,支持数据在相同帐号的多端设备之间相互同步,为用户在多端设备上提供一致的用户体验,分布式数据服务包含五部分: - -- **服务接口** - 分布式数据服务提供专门的数据库创建、数据访问、数据订阅等接口给应用程序调用,接口支持KV数据模型,支持常用的数据类型,同时确保接口的兼容性、易用性和可发布性。 - -- **服务组件** - 服务组件负责服务内元数据管理、权限管理、加密管理、备份和恢复管理以及多用户管理等、同时负责初始化底层分布式DB的存储组件、同步组件和通信适配层。 - -- **存储组件** - 存储组件负责数据的访问、数据的缩减、事务、快照、数据库加密,以及数据合并和冲突解决等特性。 - -- **同步组件** - 同步组件连结了存储组件与通信组件,其目标是保持在线设备间的数据库数据一致性,包括将本地产生的未同步数据同步给其他设备,接收来自其他设备发送过来的数据,并合并到本地设备中。 - -- **通信适配层** - 通信适配层负责调用底层公共通信层的接口完成通信管道的创建、连接,接收设备上下线消息,维护已连接和断开设备列表的元数据,同时将设备上下线信息发送给上层同步组件,同步组件维护连接的设备列表,同步数据时根据该列表,调用通信适配层的接口将数据封装并发送给连接的设备。 - -应用程序通过调用分布式数据服务接口实现分布式数据库创建、访问、订阅功能,服务接口通过操作服务组件提供的能力,将数据存储至存储组件,存储组件调用同步组件实现将数据同步,同步组件使用通信适配层将数据同步至远端设备,远端设备通过同步组件接收数据,并更新至本端存储组件,通过服务接口提供给应用程序使用。 - - -**图1** 数据分布式运作示意图 - - -![zh-cn_image_0000001183386164](/images/application-dev/database/figures/zh-cn_image_0000001183386164.png) - - -## 约束与限制 - -- 分布式数据服务的数据模型仅支持KV数据模型,不支持外键、触发器等关系型数据库中的功能。 - -- 分布式数据服务支持的KV数据模型规格: - - 设备协同数据库,针对每条记录,Key的长度≤896 Byte,Value的长度<4 MB。 - - 单版本数据库,针对每条记录,Key的长度≤1 KB,Value的度<4 MB。 - - 每个应用程序最多支持同时打开16个分布式数据库。 - -- 分布式数据库与本地数据库的使用场景不同,因此开发者应识别需要在设备间进行同步的数据,并将这些数据保存到分布式数据库中。 - -- 分布式数据服务当前不支持应用程序自定义冲突解决策略。 - -- 分布式数据服务针对每个应用程序当前的流控机制:KvStore的接口1秒最大访问1000次,1分钟最大访问10000次;KvManager的接口1秒最大访问50次,1分钟最大访问500次。 - -- 分布式数据库事件回调方法中不允许进行阻塞操作,例如修改UI组件。 diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/06.\345\210\206\345\270\203\345\274\217\346\225\260\346\215\256\346\234\215\345\212\241/02.\345\210\206\345\270\203\345\274\217\346\225\260\346\215\256\346\234\215\345\212\241\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/06.\345\210\206\345\270\203\345\274\217\346\225\260\346\215\256\346\234\215\345\212\241/02.\345\210\206\345\270\203\345\274\217\346\225\260\346\215\256\346\234\215\345\212\241\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index 9743b76d5d73067d8599b374006a4e93bf7c12c1..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/06.\345\210\206\345\270\203\345\274\217\346\225\260\346\215\256\346\234\215\345\212\241/02.\345\210\206\345\270\203\345\274\217\346\225\260\346\215\256\346\234\215\345\212\241\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,185 +0,0 @@ ---- -title: 分布式数据服务开发指导 -permalink: /pages/01080602 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# 分布式数据服务开发指导 - -## 场景介绍 - -分布式数据服务主要实现用户设备中应用程序数据内容的分布式同步。当设备1上的应用A在分布式数据库中增、删、改数据后,设备2上的应用A也可以获取到该数据库变化。可在分布式图库、信息、通讯录、文件管理器等场景中使用。 - - -## 接口说明 - -OpenHarmony系统中的分布式数据服务模块为开发者提供下面几种功能: - -**表1** 分布式数据服务关键API功能介绍 - -| 功能分类 | 接口名称 | 描述 | -| -------- | -------- | -------- | -| 分布式数据库创建。 | createKVManager(config: KVManagerConfig, callback: AsyncCallback<KVManager>): void
createKVManager(config: KVManagerConfig): Promise<KVManager> | 创建一个KVManager对象实例,用于管理数据库对象。 | -| getKVStore<T extends KVStore>(storeId: string, options: Options, callback: AsyncCallback<T>): void
getKVStore<T extends KVStore>(storeId: string, options: Options): Promise<T> | 指定Options和storeId,创建并获取KVStore数据库。 | -| 分布式数据增、删、改、查。 | put(key: string, value: Uint8Array \| string \| number \| boolean, callback: AsyncCallback<void>): void
put(key: string, value: Uint8Array \| string \| number \| boolean): Promise<void> | 插入和更新数据。 | -| delete(key: string, callback: AsyncCallback<void>): void
delete(key: string): Promise<void> | 删除数据。 | -| get(key: string, callback: AsyncCallback<Uint8Array \| string \| boolean \| number>): void
get(key: string): Promise<Uint8Array \| string \| boolean \| number> | 查询数据。 | -| 订阅分布式数据变化。 | on(event: 'dataChange', type: SubscribeType, observer: Callback<ChangeNotification>): void
on(event: 'syncComplete', syncCallback: Callback<Array<[string, number]>>): void | 订阅数据库中数据的变化。 | -| 分布式数据同步。 | sync(deviceIdList: string[], mode: SyncMode, allowedDelayMs?: number): void | 在手动模式下,触发数据库同步。 | - - -## 开发步骤 - -以单版本分布式数据库为例,说明开发步骤。 - -1. 导入模块。 - ``` - import distributedData from '@ohos.data.distributedData'; - ``` - -2. 根据配置构造分布式数据库管理类实例。 - 1. 根据应用上下文创建KvManagerConfig对象。 - 2. 创建分布式数据库管理器实例。 - - 以下为创建分布式数据库管理器的代码示例: - ``` - let kvManager; - try { - const kvManagerConfig = { - bundleName : 'com.example.datamanagertest', - userInfo : { - userId : '0', - userType : distributedData.UserType.SAME_USER_ID - } - } - distributedData.createKVManager(kvManagerConfig, function (err, manager) { - if (err) { - console.log("createKVManager err: " + JSON.stringify(err)); - return; - } - console.log("createKVManager success"); - kvManager = manager; - }); - } catch (e) { - console.log("An unexpected error occurred. Error:" + e); - } - ``` - -3. 获取/创建分布式数据库。 - 1. 声明需要创建的分布式数据库ID描述。 - 2. 创建分布式数据库,建议关闭自动同步功能(autoSync:false),需要同步时主动调用sync接口。 - - 以下为创建分布式数据库的代码示例: - ``` - let kvStore; - try { - const options = { - createIfMissing : true, - encrypt : false, - backup : false, - autoSync : false, - kvStoreType : distributedData.KVStoreType.SINGLE_VERSION, - securityLevel : distributedData.SecurityLevel.S2, - }; - kvManager.getKVStore('storeId', options, function (err, store) { - if (err) { - console.log("getKVStore err: " + JSON.stringify(err)); - return; - } - console.log("getKVStore success"); - kvStore = store; - }); - } catch (e) { - console.log("An unexpected error occurred. Error:" + e); - } - ``` - - > ![icon-note.gif](/images/application-dev/database/public_sys-resources/icon-note.gif) **说明:** - > 组网设备间同步数据的场景,建议在应用启动时打开分布式数据库,获取数据库的句柄。在该句柄(如上例中的kvStore)的生命周期内无需重复创建数据库,可直接使用句柄对数据库进行数据的插入等操作。 - -4. 订阅分布式数据变化。 - 以下为订阅单版本分布式数据库数据变化通知的代码示例: - ``` - kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_ALL, function (data) { - console.log("dataChange callback call data: " + JSON.stringify(data)); - }); - ``` - -5. 将数据写入分布式数据库。 - 1. 构造需要写入分布式数据库的Key(键)和Value(值)。 - 2. 将键值数据写入分布式数据库。 - - 以下为将字符串类型键值数据写入分布式数据库的代码示例: - - ``` - const KEY_TEST_STRING_ELEMENT = 'key_test_string'; - const VALUE_TEST_STRING_ELEMENT = 'value-test-string'; - try { - kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, function (err,data) { - if (err != undefined) { - console.log("put err: " + JSON.stringify(err)); - return; - } - console.log("put success"); - }); - }catch (e) { - console.log("An unexpected error occurred. Error:" + e); - } - ``` - -6. 查询分布式数据库数据。 - 1. 构造需要从单版本分布式数据库中查询的Key(键)。 - 2. 从单版本分布式数据库中获取数据。 - - 以下为从分布式数据库中查询字符串类型数据的代码示例: - ``` - const KEY_TEST_STRING_ELEMENT = 'key_test_string'; - const VALUE_TEST_STRING_ELEMENT = 'value-test-string'; - try { - kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, function (err,data) { - if (err != undefined) { - console.log("put err: " + JSON.stringify(err)); - return; - } - console.log("put success"); - kvStore.get(KEY_TEST_STRING_ELEMENT, function (err,data) { - console.log("get success data: " + data); - }); - }); - }catch (e) { - console.log("An unexpected error occurred. Error:" + e); - } - ``` - -7. 同步数据到其他设备。 - 1.选择同一组网环境下的设备以及同步模式,进行数据同步。 - - 以下为单版本分布式数据库进行数据同步的代码示例,其中deviceIds可由deviceManager调用getTrustedDeviceListSync()方法得到,1000表示最大延迟时间为1000ms: - ``` - import deviceManager from '@ohos.distributedHardware.deviceManager'; - - let devManager; - // create deviceManager - deviceManager.createDeviceManager("bundleName", (err, value) => { - if (!err) { - devManager = value; - } - }); - - // get deviceIds - let deviceIds = []; - if (devManager != null) { - var deviceList = devManager.getTrustedDeviceListSync(); - for (var i = 0; i < deviceList.length; i++) { - deviceIds[i] = deviceList[i].deviceId; - } - } - kvStore.sync(deviceIds, distributedData.SyncMode.PUSH_ONLY, 1000); - ``` diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/07.USB\346\234\215\345\212\241/01.USB\346\234\215\345\212\241\345\274\200\345\217\221\346\246\202\350\277\260.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/07.USB\346\234\215\345\212\241/01.USB\346\234\215\345\212\241\345\274\200\345\217\221\346\246\202\350\277\260.md" deleted file mode 100644 index 99ced3ca826aa456fbacce229217df6343c27cf8..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/07.USB\346\234\215\345\212\241/01.USB\346\234\215\345\212\241\345\274\200\345\217\221\346\246\202\350\277\260.md" +++ /dev/null @@ -1,33 +0,0 @@ ---- -title: USB服务开发概述 -permalink: /pages/01080701 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# USB服务开发概述 - -## 基本概念 - -OpenHarmony USB服务是应用访问底层的一种设备抽象概念。开发者根据提供的USB API,可以获取设备列表、控制设备访问权限、以及与连接的设备进行数据传输、控制命令传输等。 - - -## 运作机制 - -OpenHarmony USB服务系统包含USB API、USB Service、USB HAL。 - -**图2** USB服务运作机制 - -![zh-cn_image_0000001237821727](/images/application-dev/usb/figures/zh-cn_image_0000001237821727.png) - -- USB API:提供USB的基础API,主要包含查询USB设备列表、批量数据传输、控制命令传输、权限控制等。 - -- USB Service:主要实现HAL层数据的接收、解析、分发,前后台的策略管控以及对设备的管理等。 - -- USB HAL层:提供给用户态可直接调用的驱动能力接口。 diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/07.USB\346\234\215\345\212\241/02.USB\346\234\215\345\212\241\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/07.USB\346\234\215\345\212\241/02.USB\346\234\215\345\212\241\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index 98619da13bbc0d89758f14671e9d4dcd02b40628..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/07.USB\346\234\215\345\212\241/02.USB\346\234\215\345\212\241\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,168 +0,0 @@ ---- -title: USB服务开发指导 -permalink: /pages/01080702 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# USB服务开发指导 - - - -## 场景介绍 - -Host模式下,可以获取到已经连接的设备列表,并根据需要打开和关闭设备、控制设备权限、进行数据传输等。 - - -## 接口说明 - -OpenHarmony USB服务主要提供的功能有:查询USB设备列表、批量数据传输、控制命令传输、权限控制等。 - -USB类开放能力如下,具体请查阅API参考文档。 - -**表1** USB类的开放能力接口 - -| 接口名 | 描述 | -| -------- | -------- | -| hasRight(deviceName: string): boolean | 如果“使用者”(如各种App或系统)有权访问设备则返回true;无权访问设备则返回false。 | -| requestRight(deviceName: string): Promise<boolean> | 请求给定软件包的临时权限以访问设备。 | -| connectDevice(device: USBDevice): Readonly<USBDevicePipe> | 根据getDevices()返回的设备信息打开USB设备。 | -| getDevices(): Array<Readonly<USBDevice>> | 返回USB设备的列表。 | -| setConfiguration(pipe: USBDevicePipe, config: USBConfig): number | 设置设备的配置。 | -| setInterface(pipe: USBDevicePipe, iface: USBInterface): number | 设置设备的接口。 | -| claimInterface(pipe: USBDevicePipe, iface: USBInterface, force?: boolean): number | 获取接口。 | -| function bulkTransfer(pipe: USBDevicePipe, endpoint: USBEndpoint, buffer: Uint8Array, timeout?: number): Promise<number> | 批量传输。 | -| closePipe(pipe: USBDevicePipe): number | 关闭设备消息控制通道。 | -| releaseInterface(pipe: USBDevicePipe, iface: USBInterface): number | 释放接口。 | -| getFileDescriptor(pipe: USBDevicePipe): number | 获取文件描述符。 | -| getRawDescriptor(pipe: USBDevicePipe): Uint8Array | 获取原始的USB描述符。 | -| controlTransfer(pipe: USBDevicePipe, contrlparam: USBControlParams, timeout?: number): Promise<number> | 控制传输。 | - - -## 开发步骤 - -USB设备可作为Host设备连接Device设备进行数据传输。开发示例如下: - - -1. 获取设备列表。 - ``` - // 导入usb接口api包。 - import usb from '@ohos.usb'; - // 获取设备列表。 - var deviceList = usb.getDevices(); - /* - deviceList结构示例 - [ - { - name: "1-1", - serial: "", - manufacturerName: "", - productName: "", - version: "", - vendorId: 7531, - productId: 2, - clazz: 9, - subclass: 0, - protocol: 1, - devAddress: 1, - busNum: 1, - configs: [ - { - id: 1, - attributes: 224, - isRemoteWakeup: true, - isSelfPowered: true, - maxPower: 0, - name: "1-1", - interfaces: [ - { - id: 0, - protocol: 0, - clazz: 9, - subclass: 0, - alternateSetting: 0, - name: "1-1", - endpoints: [ - { - address: 129, - attributes: 3, - interval: 12, - maxPacketSize: 4, - direction: 128, - number: 1, - type: 3, - interfaceId: 0, - }, - ], - }, - ], - }, - ], - }, - ], - */ - ``` - -2. 获取设备操作权限。 - ``` - var deviceName = deviceList[0].name; - // 申请操作指定的device的操作权限。 - usb.requestRight(deviceName).then(hasRight => { - console.info("usb device request right result: " + hasRight); - }).catch(error => { - console.info("usb device request right failed : " + error); - }); - ``` - -3. 打开Device设备。 - ``` - // 打开设备,获取数据传输通道。 - var pipe = usb.connectDevice(deviceList[0]); - /* - 打开对应接口,在设备信息(deviceList)中选取对应的interface。 - interface为设备配置中的一个接口。 - */ - usb.claimInterface(pipe , interface, true); - ``` - -4. 数据传输。 - ``` - /* - 读取数据,在device信息中选取对应数据接收的endpoint来做数据传输 - (endpoint.direction == 0x80);dataUint8Array是要读取的数据,类型为Uint8Array。 - */ - - usb.bulkTransfer(pipe, inEndpoint, dataUint8Array, 15000).then(dataLength => { - if (dataLength >= 0) { - console.info("usb readData result Length : " + dataLength); - var resultStr = this.ab2str(dataUint8Array); // uint8数据转string。 - console.info("usb readData buffer : " + resultStr); - } else { - console.info("usb readData failed : " + dataLength); - } - }).catch(error => { - console.info("usb readData error : " + JSON.stringify(error)); - }); - // 发送数据,在device信息中选取对应数据发送的endpoint来做数据传输。(endpoint.direction == 0) - usb.bulkTransfer(pipe, endpoint, dataUint8Array, 15000).then(dataLength => { - if (dataLength >= 0) { - console.info("usb writeData result write length : " + dataLength); - } else { - console.info("writeData failed"); - } - }).catch(error => { - console.info("usb writeData error : " + JSON.stringify(error)); - }); - ``` - -5. 释放接口,关闭设备。 - ``` - usb.releaseInterface(pipe, interface); - usb.closePipe(pipe); - ``` diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/08.DFX/01.\345\272\224\347\224\250\344\272\213\344\273\266\346\211\223\347\202\271\346\246\202\350\277\260.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/08.DFX/01.\345\272\224\347\224\250\344\272\213\344\273\266\346\211\223\347\202\271\346\246\202\350\277\260.md" deleted file mode 100644 index 93eaab74b092e8024966e47985fb3d9838202884..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/08.DFX/01.\345\272\224\347\224\250\344\272\213\344\273\266\346\211\223\347\202\271\346\246\202\350\277\260.md" +++ /dev/null @@ -1,41 +0,0 @@ ---- -title: 应用事件打点概述 -permalink: /pages/01080801 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# 应用事件打点概述 - -HiAppEvent提供了应用事件打点接口,为应用提供事件打点的功能,用于帮助应用记录在运行过程中发生的故障信息、统计信息、安全信息、用户行为信息,以支撑开发者分析应用的运行情况。 - -## 基本概念 - -OpenHarmony系统HiAppEvent模块支持应用事件业务的开发,提供应用事件相关的功能,主要包括应用事件落盘、查询历史应用事件数据等功能。 - -- **打点** - - 记录由用户操作引起的变化,提供业务数据信息,以供开发、产品、运维分析。 - -## 事件校验结果码 - -| 错误码 | 原因 | 校验规则 | 处理结果 | -| ------ | --------------------------- | ------------------------------------------------------------ | ----------------------------------------------------- | -| 0 | 无 | 事件校验成功 | 事件正常打点。 | -| -1 | 无效的事件名称 | 非空且长度在48个字符以内(含)。
只由以下字符组成:0-9、a-z、_。
非数字以及下划线开头。 | 忽略该事件,不执行打点。 | -| -2 | 无效的事件基本参数类型 | 事件名称参数必须为string。
事件类型参数必须为number类型。
keyValues参数必须为object类型。 | 忽略该事件,不执行打点。 | -| -99 | 应用打点功能被关闭 | 应用打点功能被关闭。 | 忽略该事件,不执行打点。 | -| -100 | 未知错误 | 无。 | 忽略该事件,不执行打点。 | -| 1 | 无效的key参数名称 | 非空且长度在16个字符以内(含)。
只由以下字符组成:0-9、a-z、_。
非数字以及下划线开头。
非下划线结尾。 | 忽略该键值对参数后,继续执行打点。 | -| 2 | 无效的key参数类型 | Key参数必须为字符串类型。 | 忽略该键值对参数后,继续执行打点。 | -| 3 | 无效的value参数类型 | value参数只支持以下类型:
boolean、number、string、Array[基本类型]。
| 忽略该键值对参数后,继续执行打点。 | -| 4 | value参数值过长 | 参数值长度必须在8*1024个字符以内(含)。 | 忽略该键值对参数后,继续执行打点。 | -| 5 | key-value参数对数过多 | key-value参数对数必须在32对以内(含)。 | 忽略后面多余的键值对参数后,继续执行打点。 | -| 6 | List类型的value参数容量过大 | List类型的value参数容量必须在100个以内(含)。 | 对List进行截断(只保留前100个元素)后,继续执行打点。 | -| 7 | 无效的List类型value参数 | List的泛型类型只能为基本类型。
List内的参数必须为同一类型。 | 忽略该键值对参数后,继续执行打点。 | \ No newline at end of file diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/08.DFX/02.\345\272\224\347\224\250\344\272\213\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/08.DFX/02.\345\272\224\347\224\250\344\272\213\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index 1db3ab22f1b665aa3c53352404c7f9819197f88b..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/08.DFX/02.\345\272\224\347\224\250\344\272\213\344\273\266\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,130 +0,0 @@ ---- -title: 应用事件开发指导 -permalink: /pages/01080802 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# 应用事件开发指导 - -## 场景介绍 - -应用事件打点的主要工作是在应用运行过程中,帮助应用记录在运行过程中发生的各种信息。 - -## 接口说明 - -应用事件JS打点接口由hiAppEvent模块提供。 - -**打点接口功能介绍:** - -| 接口名 | 返回值 | 描述 | -| ------------------------------------------------------------ | -------------- | ---------------------------------------------------- | -| write(string eventName, EventType type, object keyValues, AsyncCallback\ callback): void | void | 应用事件异步打点方法,使用callback方式作为异步回调。 | -| write(string eventName, EventType type, object keyValues): Promise\ | Promise\ | 应用事件异步打点方法,使用promise方式作为异步回调。 | - -- 参数eventName:开发者自定义事件名称。事件名称在48个字符以内,有效的字符是0-9、a-z、下划线,只能以字母开头。 - -- 参数type:事件所属的类型,取值为枚举EventType,具体值如下表。 - - | 类型 | 描述 | - | --------- | -------------- | - | FAULT | 故障类型事件。 | - | STATISTIC | 统计类型事件。 | - | SECURITY | 安全类型事件。 | - | BEHAVIOR | 行为类型事件。 | - -- 参数keyValues:事件参数键值对,如果是变长参数类型,则依次输入事件的参数名与参数值。如果是Json对象类型,则Json对象的key是事件的参数名,value是事件的参数值。 - - 参数名只支持string类型,参数值只支持boolean、number、string、Array(数组参数值为基本类型)。 - - 事件的参数个数必须小于等于32。 - - 参数名在16个字符以内,有效的字符是0-9、a-z、下划线,只能以字母开头,不能以下划线结尾。 - - string类型参数值在8*1024个字符内。 - - Array类型参数值的元素个数必须在100个以内,超出时会进行截断处理。 -- 参数callback:回调函数,可以在回调函数中处理接口返回值。返回值为0表示事件参数校验成功,事件正常异步写入事件文件;大于0表示事件存在异常参数,事件在忽略异常参数后再异步写入事件文件;小于0表示事件校验失败,不执行事件异步打点操作。 - -当采用callback作为异步回调时,可以在callback中进行下一步处理。当采用Promise对象返回时,可以在Promise对象中类似地处理接口返回值。具体结果码说明见[事件校验结果码](/pages/01080801#事件校验结果码)。 - -**打点配置接口功能介绍:** - -| 接口名 | 返回值 | 描述 | -| ------------------------------ | ------- | ------------------------------------------------------------ | -| configure(ConfigOption config) | boolean | 应用事件打点配置方法,可以对打点功能进行自定义配置。返回true表示配置成功,false表示配置失败。 | - -- 参数config:应用事件打点配置项对象。应用打点配置选项ConfigOption如下表。 - - | 参数名 | 类型 | 必填 | 说明 | - | ---------- | ------- | ---- | ------------------------------------------------------------ | - | disable | boolean | 否 | 应用打点功能开关,例如配置值为true表示关闭打点功能。 | - | maxStorage | string | 否 | 打点落盘文件存放目录的配额大小,默认限额为“10M”,超出限额后会对存放目录进行清理。 | - - -**预定义事件名称常量接口Event:** -| 常量名 | 类型 | 描述 | -| ------------------------- | ------ | ------------------------ | -| USER_LOGIN | string | 用户登录事件名称。 | -| USER_LOGOUT | string | 用户登出事件名称。 | -| DISTRIBUTED_SERVICE_START | string | 分布式服务启动事件名称。 | - - -**预定义参数名称常量接口Param:** -| 常量名 | 类型 | 描述 | -| ------------------------------- | ------ | ------------------ | -| USER_ID | string | 用户自定义ID。 | -| DISTRIBUTED_SERVICE_NAME | string | 分布式服务名称。 | -| DISTRIBUTED_SERVICE_INSTANCE_ID | string | 分布式服务示例ID。 | - -## 开发步骤 - -在应用启动执行页面加载后,执行一个应用事件打点,用于记录应用的初始页面加载事件。 - -1. 新建一个JS应用工程,在“Project”窗口点击“entry > src > main > js > default > pages > index”,打开工程中的“index.js”文件,在页面执行加载后,执行一个应用事件打点,用于记录应用的初始页面加载事件,示例代码如下: - - ```js - import hiAppEvent from '@ohos.hiAppEvent' - - export default { - data: { - title: "" - }, - onInit() { - this.title = this.$t('strings.world'); - - // 1.callback方式 - hiAppEvent.write("start_event", hiAppEvent.EventType.BEHAVIOR, {"int_data":100, "str_data":"strValue"}, (err, value) => { - if (err) { - console.error(`failed to write event because ${err.code}`); - return; - } - console.log(`success to write event: ${value}`); - }); - - // 2.Promise方式 - hiAppEvent.write("start_event", hiAppEvent.EventType.BEHAVIOR, {"int_data":100, "str_data":"strValue"}) - .then((value) => { - console.log(`success to write event: ${value}`); - }).catch((err) => { - console.error(`failed to write event because ${err.code}`); - }); - }); - - // 3.配置应用打点开关 - hiAppEvent.configure({ - disable: true - }); - - // 4.配置事件文件目录限额(默认为10M) - hiAppEvent.configure({ - maxStorage: '100M' - }); - } - } - ``` - -2. 运行项目,点击应用界面上的运行按钮。 - - diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/09.DevEcoStudio\357\274\210OpenHarmony\357\274\211\344\275\277\347\224\250\346\214\207\345\215\227/01.\346\246\202\350\277\260.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/09.DevEcoStudio\357\274\210OpenHarmony\357\274\211\344\275\277\347\224\250\346\214\207\345\215\227/01.\346\246\202\350\277\260.md" deleted file mode 100644 index 936f8f67671201b16e8ae95d730e5e5a1d235abc..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/09.DevEcoStudio\357\274\210OpenHarmony\357\274\211\344\275\277\347\224\250\346\214\207\345\215\227/01.\346\246\202\350\277\260.md" +++ /dev/null @@ -1,57 +0,0 @@ ---- -title: 概述 -permalink: /pages/01080901 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# 概述 - - -## 总体说明 - -DevEco Studio是HarmonyOS的配套的开发IDE,因为HarmonyOS是基于OpenHarmony开发的,因此,使用DevEco Studio(配套HarmonyOS)也可以进行OpenHarmony的应用开发。 - -使用DevEco Studio开发OpenHarmony应用的流程与开发HarmonyOS的流程完全一样,本文档仅描述OpenHarmony应用开发与HarmonyOS应用开发的差异点。 - -- **搭建开发环境差异**:OpenHarmony应用开发环境需要先安装OpenHarmony SDK,具体可参考[配置OpenHarmony SDK](/pages/01080903)章节。 - -- **创建OpenHarmony工程**:OpenHarmony应用开发,可以通过工程向导创建一个新工程,或通过导入Sample工程的方式来创建一个新工程,具体可参考[使用工程向导创建新工程](/pages/0108090401)。 - -- **调试签名配置**:OpenHarmony应用运行在真机设备上,需要对应用进行签名,关于OpenHarmony应用的签名指导请参考[配置OpenHarmony应用签名信息](/pages/01080905)。 - -- **在真机设备上运行应用**:将OpenHarmony的hap包推送到真机设备上进行安装,具体可参考[安装运行OpenHarmony应用](/pages/01080906)。 - -关于DevEco Studio的详细操作指导,请访问[HUAWEI DevEco Studio使用指南](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/tools_overview-0000001053582387)。 - - -## 使用约束 - -- OpenHarmony只支持使用eTS、JS语言开发应用,不支持Java、C/C++语言。 - -- OpenHarmony开发环境DevEco Studio暂只支持Windows系统。 - -OpenHarmony与HarmonyOS的开发工具都是DevEco Studio,下表为OpenHarmony相比HarmonyOS不支持的功能说明: - -| 特性名称 | HarmonyOS版本 | OpenHarmony版本 | -| -------- | -------- | -------- | -| 服务卡片 | **√** | **X** | -| 自动化签名 | **√** | **X** | -| 远程模拟器 | **√** | **X** | -| 本地模拟器 | **√** | **X** | -| 使用DevEco Studio进行日志查看、调优 | **√** | **X** | -| 云测试 | **√** | **X** | -| 安全测试 | **√** | **X** | - - -## DevEco Studio演进路标 - -Huawei DevEco Studio分阶段支持OpenHarmony应用开发的演进路标如下: - -![zh-cn_image_0000001210018359](/images/application-dev/quick-start/figures/zh-cn_image_0000001210018359.png) diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/09.DevEcoStudio\357\274\210OpenHarmony\357\274\211\344\275\277\347\224\250\346\214\207\345\215\227/02.\347\211\210\346\234\254\345\217\230\346\233\264\350\257\264\346\230\216.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/09.DevEcoStudio\357\274\210OpenHarmony\357\274\211\344\275\277\347\224\250\346\214\207\345\215\227/02.\347\211\210\346\234\254\345\217\230\346\233\264\350\257\264\346\230\216.md" deleted file mode 100644 index 401c884389c7f12a800260c1cf189f40341435c6..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/09.DevEcoStudio\357\274\210OpenHarmony\357\274\211\344\275\277\347\224\250\346\214\207\345\215\227/02.\347\211\210\346\234\254\345\217\230\346\233\264\350\257\264\346\230\216.md" +++ /dev/null @@ -1,45 +0,0 @@ ---- -title: 版本变更说明 -permalink: /pages/01080902 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# 版本变更说明 - - -## V3.0 Beta2(2021-12-31) - - -### 版本兼容性 - -DevEco Studio 3.0 Beta2版本兼容性配套关系如下表所示。 - -| 组件 | 版本要求 | 说明 | -| -------- | -------- | -------- | -| Gradle | 7.3(最低版本要求7.2) | DevEco Studio已自带了Gradle7.3版本,开发者无需单独安装。 | -| JDK | 11.0.x | DevEco Studio已自带了JDK 11版本,开发者无需单独安装。 | -| OpenHarmony SDK | 3.1.0.0(API Version 8 Beta) | 兼容历史版本SDK。 | -| Toolchinas | 3.1.0.0 | 建议更新至最新版本。 | -| hap插件 | 3.0.5.2 | 建议更新至最新版本。 | -| decctest插件 | 1.2.7.2 | 建议更新至最新版本。 | - - -### 版本变更说明 - -| | -| -------- | -| **新增特性:**
- 新增DevEco Studio支持界面功能菜单的汉化版本,默认显示为英文,如需开启汉化版本,请打开DevEco Studio的**Settings**界面,在**Plugins > installed**中手动勾选“Chinese(Simplified)”插件,然后重新启动DevEco Studio即可生效。
- 新增支持OpenHarmony应用或服务的调试和运行,支持断点管理、变量查看、Step Into\Step Over\Step Out等单步调试功能。
**增强特性:**
- OpenHarmony SDK更新至3.1.0.0版本(API Version 8 Beta),配套的hap编译构建插件版本更新至3.0.5.2。
- 工程模板新增支持低代码开发的[Standard]Empty Ability模板。
- 支持eTS组件预览,要求compileSdkVersion为8或以上。
- eTS实时预览支持边修改属性边展示预览效果,无需保存修改才生效,要求compileSdkVersion为8或以上。 | - - -## V3.0 Beta1(2021-09-29) - -| | -| -------- | -| **新增特性:**
- 新增支持OpenHarmony SDK的管理,开发者可通过DevEco Studio的SDK Manager功能来下载和管理OpenHarmony SDK。
- 在编译构建HAP包时,新增支持对单个Module进行编译,对于多Module工程中只需要编译其中一个Module的场景,可以提升编译构建速度;同时还新增支持一键重构建HAP包,即在编译构建HAP前,会自动执行Clean Project操作。
**增强特性:**
- 编译构建插件更新至3.0.3.2版本。
- Json编辑器增强,资源索引错误支持快速修复,并支持快速查看资源的取值。
- 工程视图支持Ohos视图,默认视图为Project视图,开发者可手动切换。
- OpenHarmony工程支持ark方舟编译。
- OpenHarmony工程类型标识字段supportSystem "standard",由模块级build.gradle调整至工程级build.gradle。 | diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/09.DevEcoStudio\357\274\210OpenHarmony\357\274\211\344\275\277\347\224\250\346\214\207\345\215\227/03.\351\205\215\347\275\256OpenHarmonySDK.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/09.DevEcoStudio\357\274\210OpenHarmony\357\274\211\344\275\277\347\224\250\346\214\207\345\215\227/03.\351\205\215\347\275\256OpenHarmonySDK.md" deleted file mode 100644 index 708dd5d3a96f4b668e078e22f9140bc3b42bd03c..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/09.DevEcoStudio\357\274\210OpenHarmony\357\274\211\344\275\277\347\224\250\346\214\207\345\215\227/03.\351\205\215\347\275\256OpenHarmonySDK.md" +++ /dev/null @@ -1,178 +0,0 @@ ---- -title: 配置OpenHarmonySDK -permalink: /pages/01080903 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# 配置OpenHarmony SDK - - -在设置OpenHarmony应用开发环境时,需要开发者在DevEco Studio中配置对应的SDK信息。 - - -> ![icon-note.gif](/images/application-dev/quick-start/public_sys-resources/icon-note.gif) **说明:** -> 请注意,OpenHarmony SDK版本精简了部分工具链,因此不适用于HarmonyOS应用开发。 - - -## 前提条件 - -已下载并安装好DevEco Studio 3.0 Beta1及以上版本,点击[链接下载](https://developer.harmonyos.com/cn/develop/deveco-studio#download)。 - - -## 配置SDK信息 - -DevEco Studio通过SDK Manager统一管理SDK及工具链,OpenHarmony包含如下SDK包: - -| 类别 | 包名 | 说明 | -| -------- | -------- | -------- | -| SDK | JS | JS语言SDK包。 | -| eTS | eTS(Extended TypeScript) SDK包。 | -| SDK Tool | Toolchains | SDK工具链,OpenHarmony应用开发必备工具集,包括编译、打包、签名、数据库管理等工具的集合。 | -| Previewer | OpenHarmony应用预览器,可以在应用开发过程中查看界面UI布局效果。 | - -1. 运行已安装的DevEco Studio,首次使用,请选择**Do not import settings**,点击OK。 - -2. 进入配置向导页面,设置**npm registry**,DevEco Studio已预置对应的仓,直接点击**Start using DevEco Studio**进入下一步。 - > ![icon-note.gif](/images/application-dev/quick-start/public_sys-resources/icon-note.gif) **说明:** - > 如果配置向导界面出现的是设置**Set up HTTP Proxy**界面,说明网络受限,请根据[参考信息](#参考信息)配置DevEco Studio代理、NPM代理和Gradle代理后,再下载OpenHarmony SDK。 - - ![zh-cn_image_0000001163314102](/images/application-dev/quick-start/figures/zh-cn_image_0000001163314102.png) - -3. DevEco Studio向导指引开发者下载SDK,默认下载OpenHarmony SDK。SDK下载到user目录下,也可以指定对应的存储路径,SDK存储路径不支持中文字符,然后点击**Next**。 - ![zh-cn_image_0000001208394019](/images/application-dev/quick-start/figures/zh-cn_image_0000001208394019.png) - - > ![icon-note.gif](/images/application-dev/quick-start/public_sys-resources/icon-note.gif) **说明:** - > 如果不是首次安装DevEco Studio,可能无法查看进入该界面,可通过欢迎页的**Configure (或**![zh-cn_image_0000001208274069](/images/application-dev/quick-start/figures/zh-cn_image_0000001208274069.png)**图标)> Settings > SDK Manager > OpenHarmony SDK**界面,点击**OpenHarmony SDK Location**加载SDK。 - -4. 在弹出的SDK下载信息页面,点击**Next**,并在弹出的**License Agreement**窗口,点击**Accept**开始下载SDK。 - - ![zh-cn_image_0000001163472654](/images/application-dev/quick-start/figures/zh-cn_image_0000001163472654.png) - -5. 等待OpenHarmony SDK及工具下载完成,点击**Finish**,界面会进入到DevEco Studio欢迎页。 - ![zh-cn_image_0000001163632602](/images/application-dev/quick-start/figures/zh-cn_image_0000001163632602.png) - - -## 参考信息 - -DevEco Studio开发环境需要依赖于网络环境,需要连接上网络才能确保工具的正常使用。 - -一般来说,如果使用的是个人或家庭网络,是不需要设置代理信息的;只有部分企业网络受限的情况下,才需要设置代理信息。 - -如果是第一次打开DevEco Studio,配置向导界面出现设置**Set up HTTP Proxy**界面,说明网络受限,可以通过配置代理的方式来解决,需要配置DevEco Studio代理、NPM代理和Gradle代理。 - -![zh-cn_image_0000001166582138](/images/application-dev/quick-start/figures/zh-cn_image_0000001166582138.png) - - -### 配置DevEco Studio代理 - -1. 启动DevEco Studio,配置向导进入**Set up HTTP Proxy**界面,勾选**Manual proxy configuration**,设置DevEco Studio的HTTP Proxy。 - > ![icon-note.gif](/images/application-dev/quick-start/public_sys-resources/icon-note.gif) **说明:** - > 如果非首次设置向导进入HTTP Proxy,可以通过如下方式进入HTTP Proxy配置界面: - > - > - 在欢迎页点击**Configure(或**![zh-cn_image_0000001212142015](/images/application-dev/quick-start/figures/zh-cn_image_0000001212142015.png)**图标) > Settings > Appearance & Behavior > System Settings > HTTP Proxy**进入HTTP Proxy设置界面(Mac系统为**Configure > Preferences > Appearance & Behavior > System Settings > HTTP Proxy**)。 - > - > - 在打开了工程的情况下,可以点击**File > Settings > Appearance & Behavior > System Settings > HTTP Proxy**进入HTTP Proxy设置界面(Mac系统为**DevEco Studio > Preferences > Appearance & Behavior > System Settings > HTTP Proxy**) - - - **HTTP**配置项,设置代理服务器信息。**如果不清楚代理服务器信息,可以咨询你们的网络管理人员**。 - - **Host name**:代理服务器主机名或IP地址。 - - **Port number**:代理服务器对应的端口号。 - - **No proxy for**:不需要通过代理服务器访问的URL或者IP地址(地址之间用英文逗号分隔)。 - - **Proxy authentication**配置项,如果代理服务器需要通过认证鉴权才能访问,则需要设置。否则,请跳过该配置项。 - - **Login**:访问代理服务器的用户名。 - - **Password**:访问代理服务器的密码。 - - **Remember**:勾选,记住密码。 - - ![zh-cn_image_0000001212062065](/images/application-dev/quick-start/figures/zh-cn_image_0000001212062065.png) - -2. 配置完成后,点击**Check connection**,输入网络地址(如:https://developer.harmonyos.com),检查网络连通性。提示Connection successful表示代理设置成功。 - -3. 点击**Next: Configure npm**继续设置NPM代理信息,请参考[配置NPM代理](#配置npm代理)。 - - -### 配置NPM代理 - -通过DevEco Studio的设置向导设置NPM代理信息,代理信息将写入用户“users/用户名/”目录下的**.npmrc**文件。 -> ![icon-note.gif](/images/application-dev/quick-start/public_sys-resources/icon-note.gif) **说明:** -> 该向导只有第一次安装DevEco Studio才会出现。如果未出现该向导,可以直接在“users/用户名/”目录下的**.npmrc**文件中,添加代理配置信息。 - -- npm registry:设置npm仓的地址信息,建议勾选。 - -- HTTP proxy:代理服务器信息,默认会与DevEco Studio的HTTP proxy设置项保持一致。 - -- Enable Https Proxy:同步设置HTTPS Proxy配置信息,建议勾选。 - -![zh-cn_image_0000001164577336](/images/application-dev/quick-start/figures/zh-cn_image_0000001164577336.png) - -然后点击**Start using DevEco Studio**继续下一步操作。 - -如果代理服务器需要认证(需要用户名和密码),请先根据如下指导配置代理服务器的用户名和密码信息,然后再下载OpenHarmony SDK;否则,请跳过该操作,参考[配置SDK信息](#配置sdk信息)进行操作即可。 - -![zh-cn_image_0000001209817299](/images/application-dev/quick-start/figures/zh-cn_image_0000001209817299.png) - -1. 进入用户的users目录,打开**.npmrc**文件。 - -2. 修改npm代理信息,在proxy和https-proxy中,增加user和password字段,具体取值请以实际代理信息为准。示例如下所示: - ``` - proxy=http://user:password@proxy.server.com:80 - https-proxy=http://user:password@proxy.server.com:80 - ``` - - > ![icon-note.gif](/images/application-dev/quick-start/public_sys-resources/icon-note.gif) **说明:** - > 如果password中存在特殊字符,如\@、\#、\*等符号,可能导致配置不生效,建议将特殊字符替换为ASCII码,并在ASCII码前加百分号%。常用符号替换为ASCII码对照表如下: - > - > - !:%21 - > - > - \@:%40 - > - > - \#:%23 - > - > - ¥:%24 - > - > - &:%26 - > - > - \*:%2A - -3. 代理设置完成后,打开命令行工具,执行如下命令进行验证网络是否正常。 - ``` - npm info express - ``` - - 执行结果如下图所示,则说明代理设置成功。 - - ![zh-cn_image_0000001164417356](/images/application-dev/quick-start/figures/zh-cn_image_0000001164417356.png) - -4. 网络设置完成后,然后再[配置SDK信息](#配置sdk信息)。 - - -### 设置Gradle代理 - -1. 打开“此电脑”,在文件夹地址栏中输入**%userprofile%**(Mac系统请点击**前往 > 个人**),进入个人用户文件夹。 - ![zh-cn_image_0000001166740700](/images/application-dev/quick-start/figures/zh-cn_image_0000001166740700.png) - -2. 创建一个文件夹,命名为**.gradle**。如果已有.gradle文件夹,请跳过此操作。 - > ![icon-note.gif](/images/application-dev/quick-start/public_sys-resources/icon-note.gif) **说明:** - > macOS系统创建.gradle文件夹前,请将系统设置为“显示隐藏文件”。 - -3. 进入.gradle文件夹,新建一个文本文档,命名为**gradle**,并修改后缀为**.properties**。 - -4. 打开**gradle.properties**文件中,添加如下脚本,然后保存。 - 其中代理服务器、端口、用户名、密码和不使用代理的域名,请根据实际代理情况进行修改。其中不使用代理的nonProxyHosts的配置间隔符是 “|”。 - ``` - systemProp.http.proxyHost=proxy.server.com - systemProp.http.proxyPort=8080 - systemProp.http.nonProxyHosts=*.company.com|10.*|100.* - systemProp.http.proxyUser=userId - systemProp.http.proxyPassword=password - systemProp.https.proxyHost=proxy.server.com - systemProp.https.proxyPort=8080 - systemProp.https.nonProxyHosts=*.company.com|10.*|100.* - systemProp.https.proxyUser=userId - systemProp.https.proxyPassword=password - ``` diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/09.DevEcoStudio\357\274\210OpenHarmony\357\274\211\344\275\277\347\224\250\346\214\207\345\215\227/04.\345\210\233\345\273\272OpenHarmony\345\267\245\347\250\213/01.\344\275\277\347\224\250\345\267\245\347\250\213\345\220\221\345\257\274\345\210\233\345\273\272\346\226\260\345\267\245\347\250\213.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/09.DevEcoStudio\357\274\210OpenHarmony\357\274\211\344\275\277\347\224\250\346\214\207\345\215\227/04.\345\210\233\345\273\272OpenHarmony\345\267\245\347\250\213/01.\344\275\277\347\224\250\345\267\245\347\250\213\345\220\221\345\257\274\345\210\233\345\273\272\346\226\260\345\267\245\347\250\213.md" deleted file mode 100644 index 2814247043ecf9753764471c0ef71eb16b57fc31..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/09.DevEcoStudio\357\274\210OpenHarmony\357\274\211\344\275\277\347\224\250\346\214\207\345\215\227/04.\345\210\233\345\273\272OpenHarmony\345\267\245\347\250\213/01.\344\275\277\347\224\250\345\267\245\347\250\213\345\220\221\345\257\274\345\210\233\345\273\272\346\226\260\345\267\245\347\250\213.md" +++ /dev/null @@ -1,60 +0,0 @@ ---- -title: 使用工程向导创建新工程 -permalink: /pages/0108090401 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# 使用工程向导创建新工程 - -- [前提条件](#前提条件) -- [操作步骤](#操作步骤) - -通过工程向导创建一个OpenHarmony工程,该功能只有DevEco Studio 2.2 Beta1及以上版本支持。如果是DevEco Studio 2.1 Release版本,请根据[通过导入Sample方式创建新工程](/pages/0108090402)进行操作。 - - -## 前提条件 - -已安装OpenHarmony SDK,具体请参考[配置OpenHarmony SDK](/pages/01080903)。 - - -## 操作步骤 - -1. 通过如下两种方式,打开工程创建向导界面。 - - 如果当前未打开任何工程,可以在DevEco Studio的欢迎页,选择**Create Project**开始创建一个新工程。 - - 如果已经打开了工程,可以在菜单栏选择**File > New > New Project**来创建一个新工程。 - -2. 根据工程创建向导,选择“[Standard]Empty Ability”模板,点击**Next**。 - ![zh-cn_image_0000001162463400](/images/application-dev/quick-start/figures/zh-cn_image_0000001162463400.png) - -3. 点击**Next**,进入到工程配置阶段,需要根据向导配置工程的基本信息。 - - **Project name**:工程的名称,可以自定义。 - - **Project type**:工程的类型,标识该工程是一个[原子化服务](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/atomic-service-definition-0000001090840664)(Service)或传统方式的需要安装的应用(Application)。 - > ![icon-note.gif](/images/application-dev/quick-start/public_sys-resources/icon-note.gif) **说明:** - > 如果是创建的原子化服务,则: - > - > - 原子化服务调试、运行时,在设备桌面上没有应用图标,请使用DevEco Studio的调试和运行功能,来启动原子化服务。 - > - > - 原子化服务是免安装的,config.json中自动添加**installationFree**字段,取值为“true”。 - > - > - 如果entry模块的**installationFree**字段为true,则其相关的所有hap模块的**installationFree**字段都默认为true;如果entry模块的**installationFree**字段为false,则其相关的所有hap模块可以配置为true或false。 - > - > - 编译构建App时,每个hap包大小不能超过10MB。 - - **Bundle name**:软件包名称,默认情况下,应用ID也会使用该名称,应用发布时,应用ID需要唯一。如果“Project Type”选择了Atomic Service,则Bundle Name的后缀名必须是.hmservice。 - - **Save Location**:工程文件本地存储路径。 - - **Development mode**:选择开发模式,部分模板支持低代码开发,可选择Super Visual。 - - **Language**:支持的开发语言。 - - **Compatible API Version**:兼容的SDK最低版本。 - - > ![icon-note.gif](/images/application-dev/quick-start/public_sys-resources/icon-note.gif) **说明:** - > OpenHarmony工程如果配置了compileSdkVersion 7以上,对应模块默认使用方舟编译器进行编译,如果要修改编译方式为非方舟编译,在模块级build.gradle的**ohos**闭包中添加**arkEnable false**字段。 - - **Device Type**:该工程模板支持的设备类型。 - ![zh-cn_image_0000001196050928](/images/application-dev/quick-start/figures/zh-cn_image_0000001196050928.png) - -4. 点击**Finish**,工具会自动生成示例代码和相关资源,等待工程创建完成。 diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/09.DevEcoStudio\357\274\210OpenHarmony\357\274\211\344\275\277\347\224\250\346\214\207\345\215\227/04.\345\210\233\345\273\272OpenHarmony\345\267\245\347\250\213/02.\351\200\232\350\277\207\345\257\274\345\205\245Sample\346\226\271\345\274\217\345\210\233\345\273\272\346\226\260\345\267\245\347\250\213.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/09.DevEcoStudio\357\274\210OpenHarmony\357\274\211\344\275\277\347\224\250\346\214\207\345\215\227/04.\345\210\233\345\273\272OpenHarmony\345\267\245\347\250\213/02.\351\200\232\350\277\207\345\257\274\345\205\245Sample\346\226\271\345\274\217\345\210\233\345\273\272\346\226\260\345\267\245\347\250\213.md" deleted file mode 100644 index 359f873fd6be7b515d86af102ab7a950f0ba069a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/09.DevEcoStudio\357\274\210OpenHarmony\357\274\211\344\275\277\347\224\250\346\214\207\345\215\227/04.\345\210\233\345\273\272OpenHarmony\345\267\245\347\250\213/02.\351\200\232\350\277\207\345\257\274\345\205\245Sample\346\226\271\345\274\217\345\210\233\345\273\272\346\226\260\345\267\245\347\250\213.md" +++ /dev/null @@ -1,41 +0,0 @@ ---- -title: 通过导入Sample方式创建新工程 -permalink: /pages/0108090402 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:28 ---- -# 通过导入Sample方式创建新工程 - - - -> ![icon-note.gif](/images/application-dev/quick-start/public_sys-resources/icon-note.gif) **说明:** -> 该功能适用于通过DevEco Studio 2.1 Release及以上版本,创建OpenHarmony工程。 - - -OpenHarmony SDK配置完成后,便可以启动应用开发。针对OpenHarmony应用开发,**可以通过导入Sample工程的方式来创建一个新工程**。 - - -1. 在DevEco Studio的欢迎页,进入**Configure (或**![zh-cn_image_0000001118018452](/images/application-dev/quick-start/figures/zh-cn_image_0000001118018452.png)**图标) > Settings > Version Control > Git**界面,点击Test按钮检测是否安装Git工具。 - - 已安装,请根据**步骤2**开始导入Sample。 - ![zh-cn_image_0000001118018088](/images/application-dev/quick-start/figures/zh-cn_image_0000001118018088.png) - - 未安装,请点击**Download and Install**,DevEco Studio会自动下载并安装。安装完成后,请根据**步骤2**开始导入Sample。 - ![zh-cn_image_0000001164498191](/images/application-dev/quick-start/figures/zh-cn_image_0000001164498191.png) - -2. 在DevEco Studio的欢迎页,点击**Import Sample**按钮,导入Sample工程。 - ![zh-cn_image_0000001208006117](/images/application-dev/quick-start/figures/zh-cn_image_0000001208006117.png) - -3. 选择OpenHarmony Samples > common下的**JsHelloWorld**工程,然后点击**Next**。 - ![zh-cn_image_0000001152459178](/images/application-dev/quick-start/figures/zh-cn_image_0000001152459178.png) - -4. 设置**App Name**和**Project Location**,然后点击**Finish**,等待Sample工程导入完成。 - ![zh-cn_image_0000001207744539](/images/application-dev/quick-start/figures/zh-cn_image_0000001207744539.png) - -5. 等待工程同步完成,同步成功后,便可以进行OpenHarmony应用开发了。 - ![zh-cn_image_0000001163915523](/images/application-dev/quick-start/figures/zh-cn_image_0000001163915523.png) diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/09.DevEcoStudio\357\274\210OpenHarmony\357\274\211\344\275\277\347\224\250\346\214\207\345\215\227/05.\351\205\215\347\275\256OpenHarmony\345\272\224\347\224\250\347\255\276\345\220\215\344\277\241\346\201\257.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/09.DevEcoStudio\357\274\210OpenHarmony\357\274\211\344\275\277\347\224\250\346\214\207\345\215\227/05.\351\205\215\347\275\256OpenHarmony\345\272\224\347\224\250\347\255\276\345\220\215\344\277\241\346\201\257.md" deleted file mode 100644 index 685e4a3fef74e8ad144315ba7464153f01dfdbfc..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/09.DevEcoStudio\357\274\210OpenHarmony\357\274\211\344\275\277\347\224\250\346\214\207\345\215\227/05.\351\205\215\347\275\256OpenHarmony\345\272\224\347\224\250\347\255\276\345\220\215\344\277\241\346\201\257.md" +++ /dev/null @@ -1,203 +0,0 @@ ---- -title: 配置OpenHarmony应用签名信息 -permalink: /pages/01080905 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 配置OpenHarmony应用签名信息 - - -使用真机设备运行和调试OpenHarmony应用前,需要对应用进行签名才能正常运行。该指导用于OpenHarmony应用的签名配置。除此章节以外,DevEco Studio的其余操作指导无差别,具体请访问[HUAWEI DevEco Studio使用指南](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/tools_overview-0000001053582387)。配置应用签名信息的流程如下图所示。 - - -![zh-cn_image_0000001113808114](/images/application-dev/quick-start/figures/zh-cn_image_0000001113808114.png) - - -## 生成密钥和证书请求文件 - -OpenHarmony应用通过数字证书(.cer文件)和Profile文件(.p7b文件)来保证应用的完整性,需要通过DevEco Studio来生成密钥文件(.p12文件)和证书请求文件(.csr文件)。同时,也可以使用命令行工具的方式来生成密钥文件和证书请求文件。 - - -### 使用DevEco Studio生成 - -1. 在主菜单栏点击**Build > Generate Keyand CSR**。 - > ![icon-note.gif](/images/application-dev/quick-start/public_sys-resources/icon-note.gif) **说明:** - > 如果本地已有对应的密钥,无需新生成密钥,可以在**Generate Key**界面中点击下方的Skip跳过密钥生成过程,直接使用已有密钥生成证书请求文件。 - -2. 在**Key Store File**中,可以点击**Choose Existing**选择已有的密钥库文件(存储有密钥的.p12文件);如果没有密钥库文件,点击**New**进行创建。下面以新创建密钥库文件为例进行说明。 - ![zh-cn_image_0000001119560738](/images/application-dev/quick-start/figures/zh-cn_image_0000001119560738.png) - -3. 在**Create Key Store**窗口中,填写密钥库信息后,点击**OK**。 - - **Key Store File**:选择密钥库文件存储路径。 - - **Password**:设置密钥库密码,必须由大写字母、小写字母、数字和特殊符号中的两种以上字符的组合,长度至少为8位。请记住该密码,后续签名配置需要使用。 - - **Confirm Password**:再次输入密钥库密码。 - - ![zh-cn_image_0000001152674854](/images/application-dev/quick-start/figures/zh-cn_image_0000001152674854.png) - -4. 在**Generate Key**界面中,继续填写密钥信息后,点击**Next**。 - - **Alias**:密钥的别名信息,用于标识密钥名称。请记住该别名,后续签名配置需要使用。 - - **Password**:密钥对应的密码,与密钥库密码保持一致,无需手动输入。 - - **Validity**:证书有效期,建议设置为25年及以上,覆盖应用/服务的完整生命周期。 - - **Certificate**:输入证书基本信息,如组织、城市或地区、国家码等。 - - ![zh-cn_image_0000001117639668](/images/application-dev/quick-start/figures/zh-cn_image_0000001117639668.png) - -5. 在**Generate CSR**界面,选择密钥和设置CSR文件存储路径。 - ![zh-cn_image_0000001117479776](/images/application-dev/quick-start/figures/zh-cn_image_0000001117479776.png) - -6. 点击**OK**按钮,创建CSR文件成功,可以在存储路径下获取生成的密钥库文件(.p12)和证书请求文件(.csr)。 - ![zh-cn_image_0000001163839541](/images/application-dev/quick-start/figures/zh-cn_image_0000001163839541.png) - - -### 使用命令行工具生成 - -使用Open JDK携带的Keytool工具生成证书请求文件。 - -1. 使用管理员身份运行命令行工具。 - - ![zh-cn_image_0000001248045243](/images/application-dev/quick-start/figures/zh-cn_image_0000001248045243.png) - -2. 切换到keytool工具所在路径,实际路径请根据安装目录进行修改。 - ![zh-cn_image_0000001247125297](/images/application-dev/quick-start/figures/zh-cn_image_0000001247125297.png) - -3. 执行如下命令,生成公私钥文件。例如,生成的密钥库名称为ide_demo_app.p12,存储到D盘根目录下。 - ``` - keytool -genkeypair -alias "ide_demo_app" -keyalg EC -sigalg SHA256withECDSA -dname "C=CN,O=Organization,OU=Unit,CN=ide_demo_app" -keystore d:\\idedemokey.p12 -storetype pkcs12 -validity 9125 -storepass 123456Abc -keypass 123456Abc - ``` - - 生成公私钥文件的参数说明如下: - - > ![icon-note.gif](/images/application-dev/quick-start/public_sys-resources/icon-note.gif) **说明:** - > 请记录**下alias、storepass**和**keypass**的值,在后续[配置应用签名信息](#配置应用签名信息)操作会使用到。 - - - **alias**:密钥的别名信息,用于标识密钥名称。 - - **sigalg**:签名算法,固定为**SHA256withECDSA**。 - - **dname**:按照操作界面提示进行输入。 - - C:国家/地区代码,如CN。 - - O:组织名称,如Organization。 - - OU:组织单位名称,如Unit。 - - CN:名字与姓氏,建议与别名一致。 - - **validity**:证书有效期,建议设置为9125(25年)。 - - **storepass**:设置密钥库密码,必须由大写字母、小写字母、数字和特殊符号中的两种以上字符的组合,长度至少为8位。请记住该密码,后续签名配置需要使用。 - - **keypass**:设置密钥的密码,请与**storepass**保持一致。 - -4. 执行如下命令,执行后需要输入**storepass**密码,生成证书请求文件,后缀格式为.csr。 - ``` - keytool -certreq -alias "ide_demo_app" -keystore d:\\idedemokey.p12 -storetype pkcs12 -file d:\\idedemokey.csr - ``` - - 生成证书请求文件的参数说明如下: - - - **alias**:与3中输入的alias保持一致。 - - **file**:生成的证书请求文件名称,后缀为.csr。 - - -## 生成应用证书文件 - -使用[生成密钥和证书请求文件](#生成密钥和证书请求文件)中生成的证书请求文件,来生成应用签名所需的数字证书文件。生成方法如下: - -进入DevEco Studio安装目录的**Sdk\toolchains\lib**文件夹下(该SDK目录只能是OpenHarmony SDK,配置方法可参考[配置OpenHarmony SDK](/pages/01080903)),打开命令行工具,执行如下命令(如果keytool命令不能执行,请在系统环境变量中添加JDK的环境变量)。其中,只需要修改输入和输出即可快速生成证书文件,即修改**-infile**指定证书请求文件csr文件路径,**-outfile**指定输出证书文件名及路径。 - -``` -keytool -gencert -alias "OpenHarmony Application CA" -infile myApplication_ohos.csr -outfile myApplication_ohos.cer -keystore OpenHarmony.p12 -sigalg SHA384withECDSA -storepass 123456 -ext KeyUsage:"critical=digitalSignature" -validity 3650 -rfc -``` - -关于该命令的参数说明如下: - -- **alias**:用于签发证书的CA私钥别名,OpenHarmony社区CA私钥存于OpenHarmony.p12密钥库文件中,该参数不能修改。 - -- **infile**:证书请求(CSR)文件的路径。 - -- **outfile**:输出证书链文件名及路径。 - -- **keystore**:签发证书的CA密钥库路径,OpenHarmony密钥库文件名为OpenHarmony.p12,文件在OpenHarmony SDK中**Sdk\toolchains\lib**路径下,该参数不能修改。请注意,该OpenHarmony.p12文件并不是[生成密钥和证书请求文件](#生成密钥和证书请求文件)中生成的.p12文件。 - -- **sigalg**:证书签名算法,该参数不能修改。 - -- **storepass**:密钥库密码,密码为123456,该参数不能修改。 - -- **ext**:证书扩展项,该参数不能修改。 - -- **validity**:证书有效期,自定义天数。 - -- **rfc**:输出文件格式指定,该参数不能修改。 - - -## 生成应用Profile文件 - -Profile文件包含OpenHarmony应用的包名、数字证书信息、描述应用允许申请的证书权限列表,以及允许应用调试的设备列表(如果应用类型为Release类型,则设备列表为空)等内容,每个应用包中均必须包含一个Profile文件。 - -进入**Sdk\toolchains\lib**目录下,打开命令行工具,执行如下命令。 - -``` -java -jar provisionsigtool.jar sign --in UnsgnedReleasedProfileTemplate.json --out myApplication_ohos_Provision.p7b --keystore OpenHarmony.p12 --storepass 123456 --alias "OpenHarmony Application Profile Release" --sigAlg SHA256withECDSA --cert OpenHarmonyProfileRelease.pem --validity 365 --developer-id ohosdeveloper --bundle-name 包名 --permission 受限权限名(可选) --permission 受限权限名(可选) --distribution-certificate myApplication_ohos.cer -``` - -关于该命令的参数说明如下: - -- **provisionsigtool**:Profile文件生成工具,文件在OpenHarmony SDK的**Sdk\toolchains\lib**路径下。 - -- **in**:Profile模板文件所在路径,文件在OpenHarmony SDK中**Sdk\toolchains\lib**路径下,该参数不能修改。 - -- **out**:输出的Profile文件名和路径。 - -- **keystore**:签发证书的密钥库路径,OpenHarmony密钥库文件名为OpenHarmony.p12,文件在OpenHarmony SDK中**Sdk\toolchains\lib**路径下,该参数不能修改。 - -- **storepass**:密钥库密码,密码为123456,该参数不能修改。 - -- **alias**:用于签名Profile私钥别名,OpenHarmony社区CA私钥存于OpenHarmony.p12密钥库文件中,该参数不能修改。 - -- **sigalg**:证书签名算法,该参数不能修改。 - -- **cert**:签名Profile的证书文件路径,文件在OpenHarmony SDK中**Sdk\toolchains\lib**路径下,该参数不能修改。 - -- **validity**:证书有效期,自定义天数。 - -- **developer-id**:开发者标识符,自定义一个字符串。 - -- **bundle-name**:填写应用包名。 - -- **permission**:可选字段,如果不需要,则可以不用填写此字段;如果需要添加多个受限权限,则如示例所示重复输入。受限权限列表如下:ohos.permission.READ_CONTACTS、ohos.permission.WRITE_CONTACTS。 - -- **distribution-certificate**:[生成应用证书文件](#生成应用证书文件)中生成的证书文件。 - - -## 配置应用签名信息 - -在真机设备上调试前,需要使用到制作的私钥(.p12)文件、证书(.cer)文件和Profile(.p7b)文件对调试的模块进行签名。 - -打开**File > Project Structure**,点击**Project > Signing Configs > debug**窗口中,去除勾选“Automatically generate signing”,然后配置指定模块的调试签名信息。 -- **Store File**:选择密钥库文件,文件后缀为.p12,该文件为[生成密钥和证书请求文件](#生成密钥和证书请求文件)中生成的.p12文件。 - -- **Store Password**:输入密钥库密码,该密码为[生成密钥和证书请求文件](#生成密钥和证书请求文件)中填写的密钥库密码保持一致。 - -- **Key Alias**:输入密钥的别名信息,与[生成密钥和证书请求文件](#生成密钥和证书请求文件)中填写的别名保持一致。 - -- **Key Password**:输入密钥的密码,与**Store Password**保持一致。 - -- **Sign Alg**:签名算法,固定为SHA256withECDSA。 - -- **Profile File**:选择[生成应用Profile文件](#生成应用profile文件)中生成的Profile文件,文件后缀为.p7b。 - -- **Certpath File**:选择[生成应用证书文件](#生成应用证书文件)中生成的数字证书文件,文件后缀为.cer。 - -![zh-cn_image_0000001155643492](/images/application-dev/quick-start/figures/zh-cn_image_0000001155643492.png) - -设置完签名信息后,点击**OK**进行保存,然后可以在工程下的build.gradle中查看签名的配置信息。 - -![zh-cn_image_0000001202722349](/images/application-dev/quick-start/figures/zh-cn_image_0000001202722349.png) - -默认情况下,DevEco Studio编译hap包的类型为debug类型,如果需要编译release类型的hap包,请打开工程左下角的OhosBuild Variants,设置模块的编译构建类型为release。关于编译构建hap的详细说明请参考[HUAWEI DevEco Studio使用指南](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/build_hap-0000001053342418)。 - -![zh-cn_image_0000001115066116](/images/application-dev/quick-start/figures/zh-cn_image_0000001115066116.png) - -编译完成后,OpenHarmony应用的Hap包可以从工程的bulid目录下获取。 - -![zh-cn_image_0000001163918627](/images/application-dev/quick-start/figures/zh-cn_image_0000001163918627.png) diff --git "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/09.DevEcoStudio\357\274\210OpenHarmony\357\274\211\344\275\277\347\224\250\346\214\207\345\215\227/06.\345\256\211\350\243\205\350\277\220\350\241\214OpenHarmony\345\272\224\347\224\250.md" "b/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/09.DevEcoStudio\357\274\210OpenHarmony\357\274\211\344\275\277\347\224\250\346\214\207\345\215\227/06.\345\256\211\350\243\205\350\277\220\350\241\214OpenHarmony\345\272\224\347\224\250.md" deleted file mode 100644 index c60ffeddfa53b7f014156272f206ea5c364051e3..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/08.\345\272\224\347\224\250\345\274\200\345\217\221/09.DevEcoStudio\357\274\210OpenHarmony\357\274\211\344\275\277\347\224\250\346\214\207\345\215\227/06.\345\256\211\350\243\205\350\277\220\350\241\214OpenHarmony\345\272\224\347\224\250.md" +++ /dev/null @@ -1,45 +0,0 @@ ---- -title: 安装运行OpenHarmony应用 -permalink: /pages/01080906 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 安装运行OpenHarmony应用 - - - -安装OpenHarmony应用可以通过DevEco Studio安装,也可以通过使用hdc工具进行手动安装。 - - -- 通过DevEco Studio安装:将设备连接上DevEco Studio后,点击![zh-cn_image_0000001239855207](/images/application-dev/quick-start/figures/zh-cn_image_0000001239855207.png)按钮即可安装。 - -- 通过hdc工具安装:手动执行命令行完成应用的安装。 - hdc工具本身需要手动从开源仓中获取。然后使用工具将编译后的本地hap包发送至设备侧并完成安装。 - - 相关命令如下: - - - 安装命令 - **install [-r/-d/-g] _package_** - - 命令示例: - - ``` - hdc_std install E:\hwadmin.hap - ``` - - 日志抓取命令 - **hilog** - - 命令示例: - - ``` - hdc_std hilog - ``` - - 完整的hdc工具使用指导及命令格式请参见[hdc_std使用指导](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/subsystems/subsys-toolchain-hdc-guide.md)。 diff --git "a/website/docs/01.OpenHarmony/09.\350\260\203\346\265\213/01.\346\265\213\350\257\225\347\224\250\344\276\213\345\274\200\345\217\221.md" "b/website/docs/01.OpenHarmony/09.\350\260\203\346\265\213/01.\346\265\213\350\257\225\347\224\250\344\276\213\345\274\200\345\217\221.md" deleted file mode 100644 index eacbabfeeb82171e37d4a1b645c810b11637f141..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/09.\350\260\203\346\265\213/01.\346\265\213\350\257\225\347\224\250\344\276\213\345\274\200\345\217\221.md" +++ /dev/null @@ -1,881 +0,0 @@ ---- -title: 测试用例开发 -permalink: /pages/010901 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 测试子系统 -OpenHarmony为开发者提供了一套全面的自测试框架,开发者可根据测试需求开发相关测试用例,开发阶段提前发现缺陷,大幅提高代码质量。 - -本文从基础环境构建,用例开发,编译以及执行等方面介绍OpenHarmony测试框架如何运行和使用。 -## 基础环境构建 -测试框架依赖于python运行环境,在使用测试框架之前可参阅以下方式进行配置。 - - [环境配置](/pages/extra/9079c0/) - - [源码获取](/pages/extra/51fbe5/) - - -## 测试框架目录简介 -以下是测试框架的目录层级架构,在使用测试框架过程中可在相应目录查找对应组件。 -``` -test # 测试子系统 -├── developertest # 开发者测试组件 -│ ├── aw # 测试框架的静态库 -│ ├── config # 测试框架配置 -│ │ │ ... -│ │ └── user_config.xml # 用户使用配置 -│ ├── examples # 测试用例示例 -│ ├── src # 测试框架源码 -│ ├── third_party # 测试框架依赖第三方组件适配 -│ ├── reports # 测试结果报告 -│ ├── BUILD.gn # 测试框架编译入口 -│ ├── start.bat # 开发者测试入口(Windows) -│ └── start.sh # 开发者测试入口(Linux) -└── xdevice # 测试框架依赖组件 -``` -## 测试用例编写 -### 测试用例目录规划 -使用测试框架过程中,可根据以下层级关系规划测试用例目录。 -``` -subsystem # 子系统 -├── partA # 部件A -│ ├── moduleA # 模块A -│ │ ├── include -│ │ ├── src # 业务代码 -│ │ └── test # 测试目录 -│ │ ├── unittest # 单元测试 -│ │ │ ├── common # 公共用例 -│ │ │ │ ├── BUILD.gn # 测试用例编译配置 -│ │ │ │ └── testA_test.cpp # 单元测试用例源码 -│ │ │ ├── phone # 手机形态用例 -│ │ │ ├── ivi # 车机形态用例 -│ │ │ └── liteos-a # ipcamera使用liteos内核的用例 -│ │ ├── moduletest # 模块测试 -│ │ ... -│ │ -│ ├── moduleB # 模块B -│ ├── test -│ │ └── resource # 依赖资源 -│ │ ├── moduleA # 模块A -│ │ │ ├── ohos_test.xml # 资源配置文件 -│ │ ... └── 1.txt # 资源 -│ │ -│ ├── ohos_build # 编译入口配置 -│ ... -│ -... -``` -> **注意:** 测试用例根据不同设备形态差异分为通用用例和非通用用例,建议将通用用例存放在common目录下,非通用用例存放在相应设备形态目录下。 - -### 测试用例编写 -本测试框架支持多种语言用例编写,针对不同语言提供了不同的模板以供编写参考。 - -**C++参考示例** - -- 用例源文件命名规范 - - 测试用例源文件名称和测试套内容保持一致,文件命名采用全小写+下划线方式命名,以test结尾,具体格式为:[功能]_[子功能]_test,子功能支持向下细分。 -示例: - ``` - calculator_sub_test.cpp - ``` - -- 用例示例 - ``` - /* - * Copyright (c) 2021 XXXX 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 "calculator.h" - #include - - using namespace testing::ext; - - class CalculatorSubTest : public testing::Test { - public: - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - }; - - void CalculatorSubTest::SetUpTestCase(void) - { - // input testsuit setup step,setup invoked before all testcases - } - - void CalculatorSubTest::TearDownTestCase(void) - { - // input testsuit teardown step,teardown invoked after all testcases - } - - void CalculatorSubTest::SetUp(void) - { - // input testcase setup step,setup invoked before each testcases - } - - void CalculatorSubTest::TearDown(void) - { - // input testcase teardown step,teardown invoked after each testcases - } - - /** - * @tc.name: integer_sub_001 - * @tc.desc: Verify the sub function. - * @tc.type: FUNC - * @tc.require: Issue Number - */ - HWTEST_F(CalculatorSubTest, integer_sub_001, TestSize.Level1) - { - // step 1:调用函数获取结果 - int actual = Sub(4,0); - - // Step 2:使用断言比较预期与实际结果 - EXPECT_EQ(4, actual); - } - ``` - 详细内容介绍: - 1. 添加测试用例文件头注释信息 - ``` - /* - * Copyright (c) 2021 XXXX 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. - */ - ``` - 2. 引用测试框架头文件和命名空间 - ``` - #include - - using namespace testing::ext; - ``` - 3. 添加被测试类的头文件 - ``` - #include "calculator.h" - ``` - 4. 定义测试套(测试类) - ``` - class CalculatorSubTest : public testing::Test { - public: - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - }; - - void CalculatorSubTest::SetUpTestCase(void) - { - // input testsuit setup step,setup invoked before all testcases - } - - void CalculatorSubTest::TearDownTestCase(void) - { - // input testsuit teardown step,teardown invoked after all testcases - } - - void CalculatorSubTest::SetUp(void) - { - // input testcase setup step,setup invoked before each testcases - } - - void CalculatorSubTest::TearDown(void) - { - // input testcase teardown step,teardown invoked after each testcases - } - ``` - > **注意:** 在定义测试套时,测试套名称应与编译目标保持一致,采用大驼峰风格。 - - 5. 测试用例实现,包含用例注释和逻辑实现 - ``` - /** - * @tc.name: integer_sub_001 - * @tc.desc: Verify the sub function. - * @tc.type: FUNC - * @tc.require: Issue Number - */ - HWTEST_F(CalculatorSubTest, integer_sub_001, TestSize.Level1) - { - //step 1:调用函数获取结果 - int actual = Sub(4,0); - - //Step 2:使用断言比较预期与实际结果 - EXPECT_EQ(4, actual); - } - ``` - 在编写用例时,我们提供了三种用例模板供您选择。 - - | 类型 | 描述 | - | ------------| ------------| - | HWTEST(A,B,C)| 用例执行不依赖Setup&Teardown时,可选取| - | HWTEST_F(A,B,C)| 用例执行(不含参数)依赖于Setup&Teardown时,可选取| - | HWTEST_P(A,B,C)| 用例执行(含参数)依赖于Set&Teardown时,可选取| - - 其中,参数A,B,C的含义如下: - - 参数A为测试套名。 - - 参数B为测试用例名,其命名必须遵循[功能点]_[编号]的格式,编号为3位数字,从001开始。 - - 参数C为测试用例等级,具体分为门禁level0 以及非门禁level1-level4共五个等级,其中非门禁level1-level4等级的具体选取规则为:测试用例功能越重要,level等级越低。 - - **注意:** - - 测试用例的预期结果必须有对应的断言。 - - 测试用例必须填写用例等级。 - - 测试体建议按照模板分步实现。 - - 用例描述信息按照标准格式@tc.xxx value书写,注释信息必须包含用例名称,用例描述,用例类型,需求编号四项。其中用例测试类型@tc.type参数的选取,可参考下表。 - - | 测试类型名称|类型编码| - | ------------|------------| - |功能测试 |FUNC| - |性能测试 |PERF| - |可靠性测试 |RELI| - |安全测试 |SECU| - |模糊测试 |FUZZ| - - -**JavaScript参考示例** - -- 用例源文件命名规范 - - 测试用例原文件名称采用大驼峰风格,以TEST结尾,具体格式为:[功能][子功能]TEST,子功能支持向下细分。 -示例: - ``` - AppInfoTest.js - ``` - -- 用例示例 - ``` - /* - * Copyright (C) 2021 XXXX 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. - */ - import app from '@system.app' - - import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' - - describe("AppInfoTest", function () { - beforeAll(function() { - // input testsuit setup step,setup invoked before all testcases - console.info('beforeAll caled') - }) - - afterAll(function() { - // input testsuit teardown step,teardown invoked after all testcases - console.info('afterAll caled') - }) - - beforeEach(function() { - // input testcase setup step,setup invoked before each testcases - console.info('beforeEach caled') - }) - - afterEach(function() { - // input testcase teardown step,teardown invoked after each testcases - console.info('afterEach caled') - }) - - /* - * @tc.name:appInfoTest001 - * @tc.desc:verify app info is not null - * @tc.type: FUNC - * @tc.require: Issue Number - */ - it("appInfoTest001", 0, function () { - //step 1:调用函数获取结果 - var info = app.getInfo() - - //Step 2:使用断言比较预期与实际结果 - expect(info != null).assertEqual(true) - }) - }) - ``` - 详细内容介绍: - 1. 添加测试用例文件头注释信息 - ``` - /* - * Copyright (C) 2021 XXXX 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. - */ - ``` - 2. 导入被测api和jsunit测试库 - ``` - import app from '@system.app' - - import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' - ``` - 3. 定义测试套(测试类) - ``` - describe("AppInfoTest", function () { - beforeAll(function() { - // input testsuit setup step,setup invoked before all testcases - console.info('beforeAll caled') - }) - - afterAll(function() { - // input testsuit teardown step,teardown invoked after all testcases - console.info('afterAll caled') - }) - - beforeEach(function() { - // input testcase setup step,setup invoked before each testcases - console.info('beforeEach caled') - }) - - afterEach(function() { - // input testcase teardown step,teardown invoked after each testcases - console.info('afterEach caled') - }) - ``` - 4. 测试用例实现 - ``` - /* - * @tc.name:appInfoTest001 - * @tc.desc:verify app info is not null - * @tc.type: FUNC - * @tc.require: Issue Number - */ - it("appInfoTest001", 0, function () { - //step 1:调用函数获取结果 - var info = app.getInfo() - - //Step 2:使用断言比较预期与实际结果 - expect(info != null).assertEqual(true) - }) - ``` - -### 测试用例编译文件编写 -根据测试用例目录规划,当执行某一用例时,测试框架会根据编译文件逐层查找,最终找到所需用例进行编译。下面通过不同示例来讲解gn文件如何编写。 - -#### 测试用例编译配置文件 -针对不同语言,下面提供不同的编译模板以供参考。 - -- **C++用例编译配置示例** - ``` - # Copyright (c) 2021 XXXX Device Co., Ltd. - - import("//build/test.gni") - - module_output_path = "subsystem_examples/calculator" - - config("module_private_config") { - visibility = [ ":*" ] - - include_dirs = [ "../../../include" ] - } - - ohos_unittest("CalculatorSubTest") { - module_out_path = module_output_path - - sources = [ - "../../../include/calculator.h", - "../../../src/calculator.cpp", - ] - - sources += [ "calculator_sub_test.cpp" ] - - configs = [ ":module_private_config" ] - - deps = [ "//third_party/googletest:gtest_main" ] - } - - group("unittest") { - testonly = true - deps = [":CalculatorSubTest"] - } - ``` - 详细内容如下: - - 1. 添加文件头注释信息 - ``` - # Copyright (c) 2021 XXXX Device Co., Ltd. - ``` - 2. 导入编译模板文件 - ``` - import("//build/test.gni") - ``` - 3. 指定文件输出路径 - ``` - module_output_path = "subsystem_examples/calculator" - ``` - > **说明:** 此处输出路径为部件/模块名。 - - 4. 配置依赖包含目录 - - ``` - config("module_private_config") { - visibility = [ ":*" ] - - include_dirs = [ "../../../include" ] - } - ``` - > **说明:** 一般在此处对相关配置进行设置,在测试用例编译脚本中可直接引用。 - - 5. 指定测试用例编译目标输出的文件名称 - - ``` - ohos_unittest("CalculatorSubTest") { - } - ``` - 6. 编写具体的测试用例编译脚本(添加需要参与编译的源文件、配置和依赖) - ``` - ohos_unittest("CalculatorSubTest") { - module_out_path = module_output_path - sources = [ - "../../../include/calculator.h", - "../../../src/calculator.cpp", - "../../../test/calculator_sub_test.cpp" - ] - sources += [ "calculator_sub_test.cpp" ] - configs = [ ":module_private_config" ] - deps = [ "//third_party/googletest:gtest_main" ] - } - ``` - - > **说明:根据测试类型的不同,在具体编写过程中可选择不同的测试类型:** - > - ohos_unittest:单元测试 - > - ohos_moduletest:模块测试 - > - ohos_systemtest:系统测试 - > - ohos_performancetest:性能测试 - > - ohos_securitytest:安全测试 - > - ohos_reliabilitytest:可靠性测试 - > - ohos_distributedtest:分布式测试 - - 7. 对目标测试用例文件进行条件分组 - - ``` - group("unittest") { - testonly = true - deps = [":CalculatorSubTest"] - } - ``` - > **说明:** 进行条件分组的目的在于执行用例时可以选择性的执行某一种特定类型的用例。 - -- **JavaScript用例编译配置示例** - - ``` - # Copyright (C) 2021 XXXX Device Co., Ltd. - - import("//build/test.gni") - - module_output_path = "subsystem_examples/app_info" - - ohos_js_unittest("GetAppInfoJsTest") { - module_out_path = module_output_path - - hap_profile = "./config.json" - certificate_profile = "//test/developertest/signature/openharmony_sx.p7b" - } - - group("unittest") { - testonly = true - deps = [ ":GetAppInfoJsTest" ] - } - ``` - - 详细内容如下: - - 1. 添加文件头注释信息 - - ``` - # Copyright (C) 2021 XXXX Device Co., Ltd. - ``` - 2. 导入编译模板文件 - - ``` - import("//build/test.gni") - ``` - 3. 指定文件输出路径 - - ``` - module_output_path = "subsystem_examples/app_info" - ``` - > **说明:** 此处输出路径为部件/模块名。 - - 4. 指定测试用例编译目标输出的文件名称 - - ``` - ohos_js_unittest("GetAppInfoJsTest") { - } - ``` - > **说明:** - >- 使用模板ohos_js_unittest定义js测试套,注意与C++用例区分。 - >- js测试套编译输出文件为hap类型,hap名为此处定义的测试套名,测试套名称必须以JsTest结尾。 - - 5. 指定hap包配置文件config.json和签名文件,两个配置为必选项 - - ``` - ohos_js_unittest("GetAppInfoJsTest") { - module_out_path = module_output_path - - hap_profile = "./config.json" - certificate_profile = "//test/developertest/signature/openharmony_sx.p7b" - } - ``` - config.json为hap编译所需配置文件,需要开发者根据被测sdk版本配置“target”项,其余项可默认,具体如下所示: - - ``` - { - "app": { - "bundleName": "com.example.myapplication", - "vendor": "example", - "version": { - "code": 1, - "name": "1.0" - }, - "apiVersion": { - "compatible": 4, - "target": 5 // 根据被测sdk版本进行修改,此例为sdk5 - } - }, - "deviceConfig": {}, - "module": { - "package": "com.example.myapplication", - "name": ".MyApplication", - "deviceType": [ - "phone" - ], - "distro": { - "deliveryWithInstall": true, - "moduleName": "entry", - "moduleType": "entry" - }, - "abilities": [ - { - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ], - "name": "com.example.myapplication.MainAbility", - "icon": "$media:icon", - "description": "$string:mainability_description", - "label": "MyApplication", - "type": "page", - "launchType": "standard" - } - ], - "js": [ - { - "pages": [ - "pages/index/index" - ], - "name": "default", - "window": { - "designWidth": 720, - "autoDesignWidth": false - } - } - ] - } - } - ``` - 6. 对目标测试用例文件进行条件分组 - ``` - group("unittest") { - testonly = true - deps = [ ":GetAppInfoJsTest" ] - } - ``` - > **说明:** 进行条件分组的目的在于执行用例时可以选择性的执行某一种特定类型的用例。 - -#### 编译入口配置文件ohos.build - -当完成用例编译配置文件编写后,需要进一步编写部件编译配置文件,以关联到具体的测试用例。 -``` -"partA": { - "module_list": [ - - ], - "inner_list": [ - - ], - "system_kits": [ - - ], - "test_list": [ - "//system/subsystem/partA/calculator/test:unittest" //配置模块calculator下的test - ] - } -``` -> **说明:** test_list中配置的是对应模块的测试用例。 - -### 测试用例资源配置 -测试依赖资源主要包括测试用例在执行过程中需要的图片文件,视频文件、第三方库等对外的文件资源。 - -依赖资源文件配置步骤如下: -1. 在部件的test目录下创建resource目录,在resource目录下创建对应的模块,在模块目录中存放该模块所需要的资源文件。 - -2. 在resource目录下对应的模块目录中创建一个ohos_test.xml文件,文件内容格式如下: - ``` - - - - - - - - ``` -3. 在测试用例的编译配置文件中定义resource_config_file进行指引,用来指定对应的资源文件ohos_test.xml。 - ``` - ohos_unittest("CalculatorSubTest") { - resource_config_file = "//system/subsystem/partA/test/resource/calculator/ohos_test.xml" - } - ``` - >**说明:** - >- target_name: 测试套的名称,定义在测试目录的BUILD.gn中。preparer: 表示该测试套执行前执行的动作。 - >- src="res": 表示测试资源位于test目录下的resource目录下,src="out":表示位于out/release/$(部件)目录下。 - -## 测试用例执行 -在执行测试用例之前,针对用例使用设备的不同,需要对相应配置进行修改,修改完成即可执行测试用例。 - -### user_config.xml配置 -``` - - - - false - - false - - true - - - - - - - - - - - - - cmd - 115200 - 8 - 1 - 1 - - - - - - - - - - - - - - - - - - -``` ->**说明:** 在执行测试用例之前,若使用HDC连接设备,用例仅需配置设备IP和端口号即可,其余信息均默认不修改。 - -### Windows环境执行 -#### 测试用例编译 - -由于Windows环境下无法实现用例编译,因此执行用例前需要在Linux环境下进行用例编译,用例编译命令: -``` -./build.sh --product-name Hi3516DV300 --build-target make_test -``` ->说明: ->- product-name:指定编译产品名称,例如Hi3516DV300。 ->- build-target:指定所需要编译的用例,make_test表示指定全部用例,实际开发中可指定特定用例。 - -编译完成后,测试用例将自动保存在out/hi3516dv300/packages/phone/tests目录下。 - -#### 搭建执行环境 -1. 在Windows环境创建测试框架目录Test,并在此目录下创建testcase目录 - -2. 从Linux环境拷贝测试框架developertest和xdevice到创建的Test目录下,拷贝编译好的测试用例到testcase目录下 - >**说明:** 将测试框架及测试用例从Linux环境移植到Windows环境,以便后续执行。 - -3. 修改user_config.xml - ``` - - - false - - - - D:\Test\testcase\tests - - ``` - >**说明:** ``标签表示是否需要编译用例;``标签表示测试用例查找路径。 - -#### 执行用例 -1. 启动测试框架 - ``` - start.bat - ``` -2. 选择产品形态 - - 进入测试框架,系统会自动提示您选择产品形态,请根据实际的开发板进行选择。例如:Hi3516DV300。 - -3. 执行测试用例 - - 当选择完产品形态,可参考如下指令执行测试用例。 - ``` - run -t UT -ts CalculatorSubTest -tc interger_sub_00l - ``` - 执行命令参数说明: - ``` - -t [TESTTYPE]: 指定测试用例类型,有UT,MST,ST,PERF等。(必选参数) - -tp [TESTPART]: 指定部件,可独立使用。 - -tm [TESTMODULE]: 指定模块,不可独立使用,需结合-tp指定上级部件使用。 - -ts [TESTSUITE]: 指定测试套,可独立使用。 - -tc [TESTCASE]: 指定测试用例,不可独立使用,需结合-ts指定上级测试套使用。 - -h : 帮助命令。 - ``` -### Linux环境执行 -#### 远程端口映射 -为了在Linux远程服务器以及Linux虚拟机两种环境下执行测试用例,需要对端口进行远程映射,以实现与设备的数据通路连接。具体操作如下: -1. HDC Server指令: - ``` - hdc_std kill - hdc_std -m -s 0.0.0.0:8710 - ``` - >**说明:** IP和端口号为默认值。 - -2. HDC Client指令: - ``` - hdc_std -s xx.xx.xx.xx:8710 list targets - ``` - >**说明:** 此处IP填写设备侧IP地址。 - -#### 执行用例 -1. 启动测试框架 - ``` - ./start.sh - ``` -2. 选择产品形态 - - 进入测试框架,系统会自动提示您选择产品形态,请根据实际的开发板进行选择。例如:Hi3516DV300。 - -3. 执行测试用例 - - 测试框架在执行用例时会根据指令找到所需用例,自动实现用例编译,执行过程,完成自动化测试。 - ``` - run -t UT -ts CalculatorSubTest -tc interger_sub_00l - ``` - 执行命令参数说明: - ``` - -t [TESTTYPE]: 指定测试用例类型,有UT,MST,ST,PERF等。(必选参数) - -tp [TESTPART]: 指定部件,可独立使用。 - -tm [TESTMODULE]: 指定模块,不可独立使用,需结合-tp指定上级部件使用。 - -ts [TESTSUITE]: 指定测试套,可独立使用。 - -tc [TESTCASE]: 指定测试用例,不可独立使用,需结合-ts指定上级测试套使用。 - -h : 帮助命令。 - ``` - -## 测试报告日志 -当执行完测试指令,控制台会自动生成测试结果,若需要详细测试报告您可在相应的数据文档中进行查找。 - -### 测试结果 -测试结果输出根路径如下: -``` -test/developertest/reports/xxxx_xx_xx_xx_xx_xx -``` ->**说明:** 测试报告文件目录将自动生成。 - -该目录中包含以下几类结果: -| 类型 | 描述| -| ------------ | ------------ | -| result/ |测试用例格式化结果| -| log/plan_log_xxxx_xx_xx_xx_xx_xx.log | 测试用例日志 | -| summary_report.html | 测试报告汇总 | -| details_report.html | 测试报告详情 | - -### 测试框架日志 -``` -reports/platform_log_xxxx_xx_xx_xx_xx_xx.log -``` - -### 最新测试报告 -``` -reports/latest -``` - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git "a/website/docs/01.OpenHarmony/09.\350\260\203\346\265\213/02.\350\260\203\346\265\213\345\267\245\345\205\267/01.bytrace\344\275\277\347\224\250\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/09.\350\260\203\346\265\213/02.\350\260\203\346\265\213\345\267\245\345\205\267/01.bytrace\344\275\277\347\224\250\346\214\207\345\257\274.md" deleted file mode 100644 index 0c0108f21d2bc18a10cb7dab3a34fdc4abcc7c2e..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/09.\350\260\203\346\265\213/02.\350\260\203\346\265\213\345\267\245\345\205\267/01.bytrace\344\275\277\347\224\250\346\214\207\345\257\274.md" +++ /dev/null @@ -1,128 +0,0 @@ ---- -title: bytrace使用指导 -permalink: /pages/01090201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# bytrace使用指导 - -- [简介](#section11388623181619) -- [开发指导](#section1595564317164) -- [使用实例](#section667273201818) - -## 简介 - -bytrace是开发人员用于追踪进程轨迹、分析性能的一种工具,主要对内核ftrace进行了封装和扩展,来支持用户态的打点。通过该工具可以打开想要查看的用户态和内核label(通过下面命令行bytrace -l,查看支持的所有label),然后通过命令行进行抓取trace信息到指定文件中。 - -## 开发指导 - -bytrace当前支持以下命令: - -**表 1** 命令行列表 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Option

-

Description

-

-h,--help

-

查看option帮助

-

-b n,--buffer_size n

-

指定n(KB)内存大小用于存取trace日志,默认2048KB

-

-t n,--time n

-

用来指定trace运行的时间(单位:s),取决于需要分析过程的时间

-

--trace_clock clock

-

trace输出的时钟类型,一般设备支持boot、global、mono、uptime、perf等,默认为boot

-

--trace_begin

-

启动抓trace

-

--trace_dump

-

将数据输出到指定位置(默认控制台)

-

--trace_finish

-

停止抓trace,并将数据输出到指定位置(默认控制台)

-

-l,--list_categories

-

输出手机能支持的trace模块

-

--overwrite

-

当缓冲区满的时候,将丢弃最新的信息。(默认丢弃最老的日志)

-

-o filename,--output filename

-

指定输出的目标文件名称

-

-z

-

抓取trace后进行压缩

-
- -## 使用实例 - -以下是常用bytrace命令示例,供开发者参考: - -- 查询支持的label。 - -``` -bytrace -l -``` - -或者 - -``` -bytrace --list_categories -``` - -- 设置4M缓存,抓取10秒,抓取label为ability的trace信息。 - -``` -bytrace -b 4096 -t 10 --overwrite ability > /data/mytrace.ftrace -``` - -- 设置trace的输出时钟为mono。 - -``` -bytrace --trace_clock mono -b 4096 -t 10 --overwrite ability > /data/mytrace.ftrace -``` - -- 抓取trace后进行压缩。 - -``` -bytrace -z -b 4096 -t 10 --overwrite ability > /data/mytrace.ftrace -``` - diff --git "a/website/docs/01.OpenHarmony/09.\350\260\203\346\265\213/02.\350\260\203\346\265\213\345\267\245\345\205\267/02.hdc_std\344\275\277\347\224\250\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/09.\350\260\203\346\265\213/02.\350\260\203\346\265\213\345\267\245\345\205\267/02.hdc_std\344\275\277\347\224\250\346\214\207\345\257\274.md" deleted file mode 100644 index ccb0b4292db902da9d2f8fe2b4331ffa5db5bb75..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/09.\350\260\203\346\265\213/02.\350\260\203\346\265\213\345\267\245\345\205\267/02.hdc_std\344\275\277\347\224\250\346\214\207\345\257\274.md" +++ /dev/null @@ -1,705 +0,0 @@ ---- -title: hdc_std使用指导 -permalink: /pages/01090202 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# hdc\_std 使用指导 - -- [环境准备](#section05992022154916) -- [注意事项](#section19543134915210) -- [option相关的命令](#section618522925119) -- [查询设备列表的命令](#section174891132104218) -- [服务进程相关命令](#section680531510497) -- [网络相关的命令](#section71176123212) -- [文件相关的命令](#section173133523013) -- [应用相关的命令](#section2072647133819) -- [调试相关的命令](#section112861250195015) -- [常见问题](#section592920255582) - - [hdc\_std连接不到设备](#section74019384588) - - [hdc\_std运行不了](#section63291491267) - - -hdc\_std(OpenHarmony Device Connector)是OpenHarmony为开发人员提供的用于调试的命令行工具,通过该工具可以在Windows/Linux等系统上与开发机或者模拟器进行交互。 - -下文将介绍hdc\_std的环境准备和常用命令及使用举例。 - -## 环境准备 - -**hdc\_std 工具获取方式:** - -通过OpenHarmony sdk获取,hdc_std在sdk的toolchains目录下。 - -**使用举例:** - -下面以windows侧使用方式举例: - -获取windows的sdk,将hdc_std.exe放到磁盘某个位置即可使用。 - -## 注意事项 - -- 使用hdc\_std,如果出现异常,可以尝试通过hdc\_std kill命令杀掉hdc\_std服务,或者通过hdc\_std start -r命令重启服务进程进行解决。 -- 如果出现hdc\_std list targets获取不到设备信息,通过任务管理器查看是否有hdc.exe进程存在,如果进程存在,可以通过杀掉该进程进行解决。 - -## option相关的命令 - -option涉及以下命令: - -**-h/help -v/version** - -用于显示hdc相关的帮助、版本信息。 - -**表 1** 命令说明 - - - - - - - - - -

返回值

-

返回值说明

-

返回对应信息

-

帮助或者版本信息

-
- -使用方法: - -hdc\_std -h / hdc\_std help - -hdc\_std -v / hdc\_std version - -**-t key** - -用于连接指定设备标识为key的设备。 - -**表 2** 命令说明 - - - - - - - - - - - - - - - -

参数

-

参数说明

-

key

-

为tcp:port格式,或者USB序列号

-

返回值

-

返回值说明

-

①error: device '***' not found

-

②Nothing to do...

-

①设备不存在

-

②附加的命令不存在

-
- -使用方法: - -该option需要与具体的操作命令搭配使用,下面以shell命令举例: - -hdc\_std list targets (获取设备信息) - -hdc\_std -t _key_ shell (-t后面添加的_key_ 需要替换为上面查询的设备信息) - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->一台开发机可支持多个设备连接,每个设备有其唯一的设备标识,如果通过网络与设备连接,其标识为tcp:port格式,如果通过usb连接则标识为设备sn号。该命令需要跟随具体操作命令。 - -## 查询设备列表的命令 - -查询设备列表涉及以下命令: - -**list targets\[-v\]** - -显示所有已经连接的目标设备列表 - -**表 3** 命令说明 - - - - - - - - - - - - - - - -

参数

-

参数说明

-

-v

-

添加-v选项,则会打印设备详细信息

-

返回值

-

返回值说明

-

①返回设备信息

-

②[Empty]

-

①已经连接的设备列表信息

-

②没有查询到设备信息

-
- -使用方法: - -hdc\_std list targets - -hdc\_std list targets -v - -## 服务进程相关命令 - -服务进程涉及以下命令: - -**target mount** - -以读写模式挂载/system等分区。 - -**表 4** 命令说明 - - - - - - - - - - - - - - - -

参数

-

参数说明

-

-

-

返回值

-

返回值说明

-

①Mount finish

-

②返回具体信息

-

①成功情况下返回的信息

-

②失败情况下的具体信息

-
- -使用方法: - -hdc\_std target mount - -**smode \[off\]** - -授予后台服务进程root权限, 使用off参数取消授权。 - -使用方法: - -hdc\_std smode - -hdc\_std smode off - -**kill \[-r\]** - -终止服务进程。 - -**表 5** 命令说明 - - - - - - - - - - - - - - - -

参数

-

参数说明

-

-r

-

触发服务重启

-

返回值

-

返回值说明

-

①Kill server finish

-

②返回具体信息

-

①成功情况下返回的信息

-

②失败情况下的具体信息

-
- -使用方法: - -hdc\_std kill - -**start \[-r\]** - -启动服务进程。 - -**表 6** 命令说明 - - - - - - - - - - - - - - - -

参数

-

参数说明

-

-r

-

如果服务进程已经启动,-r选项会触发服务进程重新启动

-

返回值

-

返回值说明

-

-

-
- -使用方法: - -hdc\_std start - -## 网络相关的命令 - -网络部分涉及以下命令: - -**tconn host\[:port\]\[-remove\]** - -通过【ip地址:端口号】来指定连接的设备 - -**表 7** 命令说明 - - - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

host[:port]

-

为tcp:port格式

-

-remove

-

表示断开与指定设备的连接

-

返回值

-

返回值说明

-

①返回具体信息

-

②无

-

①失败情况下的具体信息

-

②成功情况下无返回值

-
- -使用方法(举例): - -hdc\_std tconn 192.168.0.100:8710 - -**tmode usb** - -执行后设备端对应daemon进程重启,并首先选用usb连接方式。 - -**表 8** 命令说明 - - - - - - - - - - - - - - - -

参数

-

参数说明

-

-

-

返回值

-

返回值说明

-

①返回具体信息

-

②无

-

①失败情况下的具体信息

-

②成功情况下无返回值

-
- -使用方法: - -hdc\_std tmode usb - -**tmode port port-number** - -执行后设备端对应daemon进程重启,并优先使用网络方式连接设备,如果连接设备再选择usb连接。 - -**表 9** 命令说明 - - - - - - - - - - - - - - - -

参数

-

参数说明

-

port-number

-

listen连接的网络端口

-

返回值

-

返回值说明

-

①返回具体信息

-

②无

-

①失败情况下的具体信息

-

②成功情况下无返回值

-
- -使用方法: - -hdc\_std tmode port 8710 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->执行完毕后,远端daemon将会退出并重启,默认启用TCP连接,如果不加上listen端口则listen随机端口。 - -## 文件相关的命令 - -文件部分涉及以下命令: - -**file send local remote** - -发送文件至远端设备。 - -**表 10** 命令说明 - - - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

local

-

本地待发送文件路径

-

remote

-

远程待接收文件路径

-

返回值

-

返回值说明

-

①返回具体信息

-

②返回传输结果

-

①失败情况下的具体信息

-

②成功传输的结果信息

-
- -使用方法(举例): - -hdc\_std file send E:\\a.txt /data/local/tmp/a.txt - -**file recv \[-a\] remote local** - -从远端设备接收文件至本地。 - -**表 11** 命令说明 - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

-a

-

文件保留时间戳模式

-

local

-

本地待接收文件路径

-

remote

-

远程待发送文件路径

-

返回值

-

返回值说明

-

①返回具体信息

-

②无

-

①失败情况下的具体信息

-

②成功情况下无返回值

-
- -使用方法(举例): - -hdc\_std file recv /data/local/tmp/a.txt ./a.txt - -## 应用相关的命令 - -应用部分涉及以下命令: - -**install \[-r/-d/-g\] _package_** - -安装OpenHarmony package。 - -**表 12** 命令说明 - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

package

-

OpenHarmony应用安装包

-

-r

-

替换已存在应用

-

-d

-

允许降级安装

-

-g

-

动态授权

-

返回值

-

返回值说明

-

①返回具体信息

-

②无

-

①失败情况下的具体信息

-

②成功情况下无返回值

-
- -使用方法(举例): - -hdc\_std install _hwadmin.hap_ - -**uninstall \[-k\] package** - -卸载OpenHarmony应用。 - -**表 13** 命令说明 - - - - - - - - - - - - - - - - - - -

参数

-

参数说明

-

package

-

OpenHarmony应用安装包

-

-k

-

保留/data/cache

-

返回值

-

返回值说明

-

①返回具体信息

-

②无

-

①失败情况下的具体信息

-

②成功情况下无返回值

-
- -使用方法(举例): - -hdc\_std uninstall _package_ - -## 调试相关的命令 - -调试涉及以下命令: - -**hilog** - -支持抓取log信息。 - -**表 14** 命令说明 - - - - - - - - - - - - - - - -

参数

-

参数说明

-

-

-

返回值

-

返回值说明

-

返回具体信息

-

抓取的日志信息

-
- -抓取hilog日志: - -hdc\_std hilog - -清理hilog缓存日志: - -hdc_std shell "hilog -r" - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->更多hilog操作命令请参考[hilog组件使用说明](https://gitee.com/openharmony/hiviewdfx_hilog/blob/master/README_zh.md#%E4%BD%BF%E7%94%A8%E8%AF%B4%E6%98%8E)。 - -**shell \[_command_\]** - -远程执行命令或进入交互命令环境。 - -**表 15** 命令说明 - - - - - - - - - - - - - - - -

参数

-

参数说明

-

command

-

需要执行的单次命令

-

返回值

-

返回值说明

-

返回具体信息

-

shell后面执行命令的结果信息

-
- -使用方法: - -hdc\_std shell - -## 常见问题 - -### hdc\_std连接不到设备 - -- **现象描述** - - 执行 "hdc\_std list targets"命令后结果为:\[Empty\] - -- **解决方法** - 1. 设备没有被识别: - - 在设备管理器中查看是否有hdc设备,在通用串行总线设备中会有“HDC Device”信息。如果没有,hdc无法连接。此时需要插拔设备,或者烧写最新的镜像。 - - 2. hdc\_std工作异常: - - 可以执行"hdc kill"或者"hdc start -r"杀掉hdc服务或者重启hdc服务,然后再执行hdc list targets查看是否已经可以获取设备信息。 - - 3. hdc\_std与设备不匹配: - - 如果设备烧写的是最新镜像,hdc\_std也需要使用最新版本。由于hdc\_std会持续更新,请从开源仓developtools\_hdc\_standard中获取,具体位置在该开源仓的prebuilt目录。 - - - -### hdc\_std运行不了 - -- **现象描述** - - 点击hdc\_std.exe文件无法运行。 - -- **解决方法** - - hdc\_std.exe不需要安装,直接放到磁盘上就能使用,也可以添加到环境变量中。通过打开cmd执行hdc\_std命令直接使用。 - - diff --git "a/website/docs/01.OpenHarmony/10.XTS\350\256\244\350\257\201/01.XTS\350\256\244\350\257\201\347\224\250\344\276\213\345\274\200\345\217\221\346\214\207\345\257\274.md" "b/website/docs/01.OpenHarmony/10.XTS\350\256\244\350\257\201/01.XTS\350\256\244\350\257\201\347\224\250\344\276\213\345\274\200\345\217\221\346\214\207\345\257\274.md" deleted file mode 100644 index 4e48fcb10a992d07b4991a873aa9201e4df6ef19..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/10.XTS\350\256\244\350\257\201/01.XTS\350\256\244\350\257\201\347\224\250\344\276\213\345\274\200\345\217\221\346\214\207\345\257\274.md" +++ /dev/null @@ -1,725 +0,0 @@ ---- -title: XTS认证用例开发指导 -permalink: /pages/010a01 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# XTS认证用例开发指导 - -- [简介](#section465982318513) -- [系统类型](#section125090457443) -- [目录](#section161941989596) -- [约束](#section119744591305) -- [使用说明](#section137768191623) -- [用例开发指导](#section3695134065513) - - [C语言用例开发编译指导(适用于轻量系统产品用例开发)](#section198193336544) - - [C语言用例执行指导(适用于轻量系统产品用例开发)](#section13820233175418) - - [C++语言用例开发编译指导(适用于小型系统、标准系统用例开发)](#section3822123311540) - - [C++语言用例执行指导(适用于小型系统、标准系统用例开发)](#section128222336544) - - [JS语言用例开发指导(适用于标准系统)](#section159801435165220) - - [JS语言用例编译打包指导(适用于标准系统)](#section445519106559) - -- [全量编译指导(适用于标准系统)](#section1519992743415) -- [全量用例执行指导(适用于小型系统、标准系统)](#section118149111426) - -## 简介 - -XTS子系统是OpenHarmony生态认证测试套件的集合,当前包括acts(application compatibility test suite)应用兼容性测试套件,后续会拓展dcts(device compatibility test suite)设备兼容性测试套件等。 - -XTS子系统当前包括acts与tools软件包: - -- acts,存放acts相关测试用例源码与配置文件,其目的是帮助终端设备厂商尽早发现软件与OpenHarmony的不兼容性,确保软件在整个开发过程中满足OpenHarmony的兼容性要求。 -- tools,存放acts相关测试用例开发框架。 - -## 系统类型 - -OpenHarmony支持如下几种系统类型: - -- 轻量系统(mini system) - - 面向MCU类处理器例如Arm Cortex-M、RISC-V 32位的设备,硬件资源极其有限,支持的设备最小内存为128KiB,可以提供多种轻量级网络协议,轻量级的图形框架,以及丰富的IOT总线读写部件等。可支撑的产品如智能家居领域的连接类模组、传感器设备、穿戴类设备等。 - -- 小型系统(small system) - - 面向应用处理器例如Arm Cortex-A的设备,支持的设备最小内存为1MiB,可以提供更高的安全能力、标准的图形框架、视频编解码的多媒体能力。可支撑的产品如智能家居领域的IP Camera、电子猫眼、路由器以及智慧出行域的行车记录仪等。 - -- 标准系统(standard system) - - 面向应用处理器例如Arm Cortex-A的设备,支持的设备最小内存为128MiB,可以提供增强的交互能力、3D GPU以及硬件合成能力、更多控件以及动效更丰富的图形能力、完整的应用框架。可支撑的产品如高端的冰箱显示屏。 - - -## 目录 - -``` -/test/xts -├── acts # 测试代码存放目录 -│ └── subsystem # 标准系统子系统测试用例源码存放目录 -│ └── subsystem_lite # 轻量系统、小型系统子系统测试用例源码存放目录 -│ └── BUILD.gn # 标准系统测试用例编译配置 -│ └── build_lite # 轻量系统、小型系统测试用例编译配置存放目录 -│ └── BUILD.gn # 轻量系统、小型系统测试用例编译配置 -└── tools # 测试工具代码存放目录 -``` - -## 约束 - -轻量系统用例开发语言是C,小型系统用例开发语言是C++。 - -## 使用说明 - -**表 1** 用例级别说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

级别名称

-

基本定义

-

测试范围

-

Level0

-

冒烟

-

验证关键功能点基本功能/最基本DFX属性在最常见输入下的表现,通过表示功能基本可运行。

-

Level1

-

基本

-

验证各功能点基本功能/基本DFX属性在常见输入下的表现,通过表示功能基本可测试。

-

Level2

-

重要

-

验证各功能点的基本功能/基本DFX属性在常规输入/常见异常情况下的表现,通过表示功能基本正常可用,可开展Beta。

-

Level3

-

一般

-

验证各功能点的全部功能/全部DFX属性在各种常规/非常规输入组合下,或各种正常/异常预置条件组合下的表现。

-

Level4

-

生僻

-

验证关键功能点在极端异常预置条件下、用户难以触及的异常输入组合下的表现。

-
- -**表 2** 用例粒度说明 - - - - - - - - - - - - - - - - - - - - -

用例规模

-

被测试对象

-

测试环境

-

LargeTest

-

业务功能/全场景特性/整机及场景级DFX

-

尽量使用贴近真实的环境设备

-

MediumTest

-

模块/子系统集成至设备后的功能/DFX

-

使用真实的单设备进行验证,可进行消息模拟,尽量不对函数进行MOCK

-

SmallTest

-

模块/类/函数

-

在开发者个人环境进行测试,尽量不依赖其他模块,存在大量的MOCK

-
- -**表 3** 测试类型说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

测试类型名称

-

测试类型定义

-

Function

-

验证被测对象提供给用户的业务功能实现正确性的测试项,这里的“用户”可以是终端用户或开发者,功能包括业务功能及平台功能

-

Performance

-

验证被测对象在特定预置条件/负载模型下的处理能力的测试项,“处理能力”一般以单位时间内可处理的业务量来衡量,如呼叫/秒,帧率/秒,事件处理量/秒等

-

Power

-

验证被测对象在特定预置条件/负载模型下在一定时间内能源消耗量的测试项

-

Reliability

-

验证被测对象在正常/异常输入情况下,或业务量压力和长时间连续运行压力情况下业务表现的测试项,含稳定性、压力、故障注入、Monkey测试项

-

Security

-

验证系统对恶意威胁的防护能力,威胁包括但不限于未授权访问、使用、泄露、破坏、修改、毁灭,以保障信息的机密性、完整性和可用性; 验证系统对用户隐私的保护能力,保障用户的隐私数据被收集、使用、保有、披露和处置符合法律规范,保障用户的隐私权; 验证对各类安全规范的遵从情况,如安全设计规范、安全红线、工信部安全认证规范等,保障安全相关法律法规的合规。

-

Global

-

验证被测对象在是否具有国际化数据支持和本地化能力的测试项,包括语言显示、输入/输出习惯、时间显示、区域特性如货币时间禁忌等等

-

Compatibility

-

当被测对象为应用时,包括被测对象对于自身数据的后向兼容性、对于系统的前后向兼容性、对于不同用户数据(如播放器之音频文件格式/智能短信之用户短信内容)的兼容性测试项; 当被测对象为系统时,包括被测系统对于系统自身数据的后向兼容性、以及对于生态中常用应用的兼容性测试项;当被测对象为软件时,包括被测系统对于相关的硬件的兼容性;

-

User

-

验证被测对象在真实用户场景下的用户体验感受的测试项,注意此种情况下没有客观的“正确”与“失败”,所有的结论及评价都应该来自于用户

-

Standard

-

验证被测对象对于行业及公司内标准/协议/规范的遵从情况的测试项,注意此处的“标准”不包含任何安全标准,针对安全标准的测试项划归为“安全测试”类型

-

Safety

-

验证被测对象的Safety属性,避免产品可能对人身安全、健康以及产品本身带来的危害。

-

Resilience

-

验证被测对象的韧性属性,确保系统受攻击时承受并保持在有定义的运行状态(包括降级)、恢复并适应攻击以保障Mission达成。

-
- -## 用例开发指导 - -根据测试系统选择测试框架和对应测试用例语言。 - -**表 4** 系统和测试框架、开发语言对应关系 - - - - - - - - - - - - - - - - - - - - -

系统

-

测试框架

-

语言

-

轻量系统

-

hctest

-

c

-

小型系统

-

hcpptest

-

c++

-

标准系统

-

HJSUnit、hcpptest

-

js、c++

-
- -### C语言用例开发编译指导(适用于轻量系统产品用例开发) - -**示例:轻量系统测试用例开发** - -当前使用的测试框架是hctest,hctest测试框架支持使用C语言编写测试用例,是在开源测试框架unity的基础上进行增强和适配。 - -1. 用例目录规范:测试用例存储到test/xts/acts仓中 - - ``` - ├── acts - │ └──subsystem_lite - │ │ └── module_hal - │ │ │ └── BUILD.gn - │ │ │ └── src - │ └──build_lite - │ │ └── BUILD.gn - ``` - -2. src目录下用例编写样例。 - - 1.引用测试框架 - - ``` - #include "hctest.h" - ``` - - 2. 使用宏定义LITE\_TEST\_SUIT定义子系统、模块、测试套件名称 - - ``` - /** - * @brief register a test suit named "IntTestSuite" - * @param test subsystem name - * @param example module name - * @param IntTestSuite test suit name - */ - LITE_TEST_SUIT(test, example, IntTestSuite); - ``` - - 3. 定义Setup与TearDown - - 命名方式:测试套件名称+Setup,测试套件名称+TearDown。 - - Setup与TearDown必须存在,可以为空函数。 - - 4. 使用宏定义LITE\_TEST\_CASE写测试用例 - - 包括三个参数:测试套件名称,测试用例名称,用例属性(测试类型、用例粒度、用例级别)。 - - ``` - LITE_TEST_CASE(IntTestSuite, TestCase001, Function | MediumTest | Level1) - { - //do something - }; - ``` - - 5. 使用宏定义 RUN\_TEST\_SUITE注册测试套件 - - ``` - RUN_TEST_SUITE(IntTestSuite); - ``` - -3. 测试模块的配置文件(BUILD.gn)样例: - - 在每个测试模块目录下新建BUILD.gn编译文件,用于指定编译后静态库的名称、依赖的头文件、依赖的库等;具体写法如下: - - ``` - import("//test/xts/tools/lite/build/suite_lite.gni") - hctest_suite("ActsDemoTest") { - suite_name = "acts" - sources = [ - "src/test_demo.c", - ] - include_dirs = [ ] - cflags = [ "-Wno-error" ] - } - ``` - -4. acts下BUILD.gn增加编译选项。 - - 需要将测试模块加入到acts目录下的编译脚本中,编译脚本路径:test/xts/acts/build\_lite/BUILD.gn。 - - ``` - lite_component("acts") { - ... - if(board_name == "liteos_m") { - features += [ - ... - "//xts/acts/subsystem_lite/module_hal:ActsDemoTest" - ] - } - } - ``` - -5. 测试套件编译命令。 - - 随版本编译,debug版本编译时会同步编译acts测试套件 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >acts测试套件编译中间件为静态库,最终链接到版本镜像中 。 - - -### C语言用例执行指导(适用于轻量系统产品用例开发) - -**示例:轻量系统测试用例执行** - -将版本镜像烧录进开发板。 - -**测试步骤** - -1. 使用串口工具登录开发板,并保存串口打印信息。 -2. 重启设备,查看串口日志。 - -**测试结果分析指导** - -基于串口打印日志进行分析; - -每个测试套件执行以Start to run test suite开始,以xx Tests xx Failures xx Ignored结束。 - -### C++语言用例开发编译指导(适用于小型系统、标准系统用例开发) - -**示例:小型系统测试用例开发**(标准参考具体样例目录:global/i18n\_standard) - -当前使用的测试框架是hcpptest,hcpptest测试框架是在开源的googletest测试框架的基础上进行的增强和适配。 - -1. 规范用例目录:测试用例存储到test/xts/acts仓中。 - - ``` - ├── acts - │ └──subsystem_lite - │ │ └── module_posix - │ │ │ └── BUILD.gn - │ │ │ └── src - │ └──build_lite - │ │ └── BUILD.gn - ``` - -2. 测试模块src下用例编写样例: - - 1. 引用测试框架: - - 需要引用gtest.h 如:\#include "gtest/gtest.h" - - ``` - #include "gtest/gtest.h" - ``` - - 2. 定义Setup与TearDown - - ``` - using namespace std; - using namespace testing::ext; - class TestSuite: public testing::Test { - protected: - // Preset action of the test suite, which is executed before the first test case - static void SetUpTestCase(void){ - } - // Test suite cleanup action, which is executed after the last test case - static void TearDownTestCase(void){ - } - // Preset action of the test case - virtual void SetUp() - { - } - // Cleanup action of the test case - virtual void TearDown() - { - } - }; - ``` - - 3. 使用宏定义HWTEST或HWTEST\_F写测试用例 - - 普通测试用例的定义:HWTEST(测试套名称, 测试用例名称, 用例标注)。 - - 包含SetUp和TearDown的测试用例的定义 :HWTEST\_F(测试套名称, 测试用例名称,用例标注)。 - - 宏定义包括三个参数:测试套件名称,测试用例名称,用例属性(测试类型、用例粒度、用例级别)。 - - ``` - HWTEST_F(TestSuite, TestCase_0001, Function | MediumTest | Level1) { - // do something - } - ``` - -3. 测试模块下用例配置文件(BUILD.gn)样例: - - 每个测试模块目录下新建BUILD.gn编译文件,用于指定编译后可执行文件的名称、依赖的头文件、依赖的库等;具体写法如下。每个测试模块将独立编译成.bin可执行文件, 该文件可直接push到单板上进行测试。 - - 举例: - - ``` - import("//test/xts/tools/lite/build/suite_lite.gni") - hcpptest_suite("ActsDemoTest") { - suite_name = "acts" - sources = [ - "src/TestDemo.cpp" - ] - - include_dirs = [ - "src", - ... - ] - deps = [ - ... - ] - cflags = [ "-Wno-error" ] - } - - ``` - -4. acts目录下增加编译选项(BUILD.gn)样例: - - 将测试模块加入到acts目录下的编译脚本中,编译脚本为:test/xts/acts/build\_lite/BUILD.gn。 - - ``` - lite_component("acts") { - ... - else if(board_name == "liteos_a") { - features += [ - ... - "//xts/acts/subsystem_lite/module_posix:ActsDemoTest" - ] - } - } - ``` - -5. 测试套件编译命令。 - - 随版本编译,debug版本编译时会同步编译acts测试套件 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >小型系统acts独立编译成可执行文件(bin格式), 在编译产物的suites\\acts目录下归档。 - - -### C++语言用例执行指导(适用于小型系统、标准系统用例开发) - -**示例:小型系统测试用例执行** - -目前的用例执行采用nfs共享的方式,mount到单板去执行。 - -**环境搭建** - -1. 使用有限网线或无线将开发板与PC进行连接。 -2. 开发板配置IP、子网掩码、网关,确保开发板与PC处于同一个网段。 -3. PC安装nfs服务器并完成注册,启动nfs服务。 -4. 开发板配置mount命令,确保开发板可以访问PC端的nfs共享文件。 - - 格式:mount \[nfs服务器IP\]:\[/nfs共享目录\] \[/开发板目录\] nfs - - 举例: - - ``` - mount 192.168.1.10:/nfs /nfs nfs - ``` - - -**用例执行** - -测试套件执行 ActsDemoTest.bin 触发用例执行,基于串口打印日志进行分析。 - -### JS语言用例开发指导(适用于标准系统) - -当前使用的测试框架是HJSUnit,用于支撑OpenHarmony application测试(特指基于JS应用框架使用 Javascript 语言开发的 APP)进行自动化测试。 - -**用例编写基础语法** - -测试用例为 js 语言,必须满足 JavaScript 语言编程规范: - -**表 5** - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

用例语法

-

描述

-

要求

-

beforeAll

-

测试套级别的预置条件,在所有测试用例开始前执行且仅执行一次,支持一个参数:预置动作函数

-

可选

-

afterAll

-

测试套级别的清理条件,在所有测试用例结束后执行且仅执行一次,支持一个参数:清理动作函数

-

可选

-

beforeEach

-

测试用例级别的预置条件,在每条测试用例开始前执行,执行次数与 it 定义的测试用例数一致,支持一个参数:预置动作函数

-

可选

-

afterEach

-

测试用例级别的清理条件,在每条测试用例结束后执行,执行次数与 it 定义的测试用例数一致,支持一个参数:清理动作函数

-

可选

-

describe

-

定义一个测试套,支持两个参数:测试套名称和测试套函数; describe 支持嵌套,每个 describe 内均可以定义 beforeAll 、beforeEach 、afterEach 和 afterAll

-

必选

-

it

-

定义一条测试用例,支持三个参数:用例名称,过滤参数和用例函数

-

备注:

-

过滤参数:过滤参数为一个 32 位的 Int 类型参数,0 位 置1表示不筛选、默认执行;0-10 位 置1表示测试用例类型;16-18 位 置1表示测试用例规模;24-28 位 置1表示测试层级

-

测试用例类型。置位0-10分别表示:FUNCTION 方法类测试、PERFORMANCE 性能类测试、POWER 功耗类测试、RELIABILITY 可靠性测试、SECURITY 安全合规测试、GLOBAL 整体性测试、COMPATIBILITY 兼容性测试、USER 用户测试、STANDARD 标准测试、SAFETY 安全特性测试,RESILIENCE 压力测试。

-

测试用例规模。置位16-18分别表示:SMALL 小型测试、MEDIUM 中型测试、LARGE 大型测试。

-

测试层级。置位24-28分别表示:LEVEL0-0 级测试、LEVEL1-1 级测试、LEVEL2-2 级测试、LEVEL3-3 级测试、LEVEL4-4 级测试。

-

必选

-
- -用例编写语法采用 jasmine 的标准语法,格式支持ES6格式。 - -1. 规范用例目录:测试用例存储到entry/src/main/js/test目录。 - - ``` - ├── BUILD.gn - │ └──entry - │ │ └──src - │ │ │ └──main - │ │ │ │ └──js - │ │ │ │ │ └──default - │ │ │ │ │ │ └──pages - │ │ │ │ │ │ │ └──index - │ │ │ │ │ │ │ │ └──index.js # 入口文件 - │ │ │ │ │ └──test # 测试代码存放目录 - │ │ │ └── resources # hap资源存放目录 - │ │ │ └── config.json # hap配置文件 - ``` - -2. index.js示例 - - ``` - // 拉起js测试框架,加载测试用例 - import {Core, ExpectExtend} from 'deccjsunit/index' - - export default { - data: { - title: "" - }, - onInit() { - this.title = this.$t('strings.world'); - }, - onShow() { - console.info('onShow finish') - const core = Core.getInstance() - const expectExtend = new ExpectExtend({ - 'id': 'extend' - }) - core.addService('expect', expectExtend) - core.init() - const configService = core.getDefaultService('config') - configService.setConfig(this) - require('../../../test/List.test') - core.execute() - }, - onReady() { - }, - } - ``` - -3. 单元测试用例示例 - - ``` - // Example1: 使用HJSUnit进行单元测试 - describe('appInfoTest', function () { - it('app_info_test_001', 0, function () { - var info = app.getInfo() - expect(info.versionName).assertEqual('1.0') - expect(info.versionCode).assertEqual('3') - }) - }) - ``` - - -### JS语言用例编译打包指导(适用于标准系统) - -hap包编译请参考[标准系统js应用开发指导](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/build_overview-0000001055075201)。 - -## 全量编译指导(适用于标准系统) - -1. 全量编译 - - **命令**: - - ``` - ./build.sh suite=acts system_size=standard - ``` - - **测试用例输出目录**:out/release/suites/acts/testcases - - **测试框架&用例整体输出目录**:out/release/suites/acts(编译用例时会同步编译测试套执行框架) - - -## 全量用例执行指导(适用于小型系统、标准系统) - -**搭建测试环境** - -Windows工作台下安装python3.7及以上版本,确保工作台和测试设备正常连接。 - -**测试执行目录**(对应编译生成的out/release/suites/acts目录) - -``` -├── testcase # 测试套文件存放目录 -│ └──xxx.hap # 测试套可执行hap文件 -│ └──xxx.json # 测试套对应执行配置文件 -├── tools # 测试框架工具目录 -├── run.bat # window平台测试套启动执行文件 -├── report # 测试报告生成目录 -``` - -**用例执行** - -1. 在Windows工作台上,找到从Linux服务器上拷贝下来的测试套件用例目录\(对应编译生成的out/release/suites/acts目录\),在Windows命令窗口进入对应目录,直接执行acts\\run.bat。 - -1. 界面启动后,输入用例执行指令。 - - - 全量执行 - - ``` - run acts - ``` - - ![](/images/device-dev/subsystems/figure/zh-cn_image_0000001119924146.gif) - - - 模块执行\(具体模块可以查看\\acts\\testcases\\\) - - ``` - run –l ActsSamgrTest - ``` - - ![](/images/device-dev/subsystems/figure/zh-cn_image_0000001166643927.jpg) - - 等待执行完成。 - - -1. 查看测试报告。 - - 进入acts\\reports\\,获取当前的执行记录,打开“summary\_report.html”可以获取到测试报告。 - - diff --git "a/website/docs/01.OpenHarmony/11.\345\267\245\345\205\267/01.Docker\347\274\226\350\257\221\347\216\257\345\242\203.md" "b/website/docs/01.OpenHarmony/11.\345\267\245\345\205\267/01.Docker\347\274\226\350\257\221\347\216\257\345\242\203.md" deleted file mode 100644 index 3395e1c20f2c3e29c22c63058c7c8f752b089ff6..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/11.\345\267\245\345\205\267/01.Docker\347\274\226\350\257\221\347\216\257\345\242\203.md" +++ /dev/null @@ -1,267 +0,0 @@ ---- -title: Docker编译环境 -permalink: /pages/010b01 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# Docker编译环境 - -- [Docker环境介绍](#section107932281315) -- [环境准备](#section7337134183512) -- [独立Docker环境](#section2858536103611) - - [搭建Docker环境-轻量系统类设备(参考内存≥128KB)和小型系统类设备(参考内存≥1MB)](#section319412277287) - - [编译源码-轻量系统类设备(参考内存≥128KB)和小型系统类设备(参考内存≥1MB)](#section631485163615) - - [搭建Docker环境-标准系统类设备(参考内存≥128MB)](#section13585262391) - - [编译源码-标准系统类设备(参考内存≥128MB)](#section193711513406) - -- [基于HPM的Docker环境](#section485713518337) - - [搭建Docker环境](#section3295842510) - - [获取及编译源码](#section69141039143518) - - -## Docker环境介绍 - -OpenHarmony为开发者提供了两种Docker环境,以帮助开发者快速完成复杂的开发环境准备工作。两种Docker环境及适用场景如下: - -- 独立Docker环境:适用于直接基于Ubuntu、Windows操作系统平台进行版本编译的场景。 -- 基于HPM的Docker环境:适用于使用HPM工具进行发行版编译的场景。 - -**表 1** Docker镜像介绍 - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Docker环境

-

系统类型

-

运行平台

-

Docker镜像仓库

-

标签

-

独立 Docker环境

-

轻量和小型系统

-

Ubuntu/Windows

-

swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker

-

0.0.6

-

标准系统

-

Ubuntu

-

swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker-standard

-

0.0.7

-

HPM Docker环境

-

轻量和小型系统

-

Ubuntu/Windows

-

swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker

-

0.0.3

-
- - - - - - -## 环境准备 - -在使用docker环境前需要先完成以下操作: - -1. 安装Docker,Docker安装请参考[官方指导](https://docs.docker.com/engine/install/)。 -2. 获取OpenHarmony源码,请参考[获取源码](/pages/extra/51fbe5/)。 - - >![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** - >HPM Docker环境无需单独获取源码。 - - -## 独立Docker环境 - -OpenHarmony的Docker镜像托管在[HuaweiCloud SWR](https://console.huaweicloud.com/swr/?region=cn-south-1#/app/warehouse/warehouseMangeDetail/goldensir/openharmony-docker/openharmony-docker?type=ownImage)上。开发者可以通过该镜像在很大程度上简化编译前的环境配置。下文将介绍具体使用步骤。 - -### 搭建Docker环境-轻量系统类设备(参考内存≥128KB)和小型系统类设备(参考内存≥1MB) - -1. 获取Docker镜像。 - - ``` - docker pull swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker:0.0.6 - ``` - -2. 进入OpenHarmony代码根目录执行如下命令,从而进入Docker构建环境。 - - ubuntu下执行: - - ``` - docker run -it -v $(pwd):/home/openharmony swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker:0.0.6 - ``` - - windows下执行(假设源码目录为D:\\OpenHarmony): - - ``` - docker run -it -v D:\OpenHarmony:/home/openharmony swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker:0.0.6 - ``` - - -### 编译源码-轻量系统类设备(参考内存≥128KB)和小型系统类设备(参考内存≥1MB) - -通过如下编译脚本启动轻量系统类设备(参考内存≥128KB)和小型系统类设备(参考内存≥1MB)的编译。下文以Hi3516平台为例说明具体编译步骤。 - -设置编译路径,选择当前路径。 - -``` -hb set - . -``` - -**图 1** 设置编译界面 -![](/images/device-dev/get-code/figure/设置编译界面.png "设置编译界面") - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->当前开发板平台和编译界面的对应关系如下: ->- Hi3861:wifiiot\_hispark\_pegasus@hisilicon ->- Hi3516:ipcamera\_hispark\_taurus@hisilicon ->- Hi3518:ipcamera\_hispark\_aries@hisilicon - -1. 选择ipcamera\_hispark\_taurus@hisilicon并回车。 -2. 执行编译。 - - ``` - hb build -f - ``` - -3. 查看编译结果。 - - 编译结果文件生成在out/hispark\_taurus/ipcamera\_hispark\_taurus目录下。 - - -### 搭建Docker环境-标准系统类设备(参考内存≥128MB) - -**方式一:从HuaweiCloud SWR上直接获取Docker镜像进行构建:** - -1. 获取Docker镜像。 - - ``` - docker pull swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker-standard:0.0.7 - ``` - -2. 进入OpenHarmony代码根目录执行如下命令,从而进入Docker构建环境。 - - ``` - docker run -it -v $(pwd):/home/openharmony swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker-standard:0.0.7 - ``` - - -### 编译源码-标准系统类设备(参考内存≥128MB) - -通过如下编译脚本启动标准系统类设备(参考内存≥128MB)的编译。 - -``` -./build.sh --product-name {product_name} --ccache -``` - -\{product\_name\}为当前版本支持的平台。比如:Hi3516DV300和rk3568等。 - -编译所生成的文件都归档在out/{device_name}/目录下,结果镜像输出在 out/{device_name}/packages/phone/images/ 目录下。 - - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->退出Docker执行exit命令即可。 - -## 基于HPM的Docker环境 - -docker\_dist是一个[HPM](https://hpm.harmonyos.com/)系统中的模板组件,能够帮助用户快速初始化HPM工程,利用docker镜像来快速编译OpenHarmony发行版,在很大程度上简化了编译前的环境配置。开发者在配置好Ubuntu和[hpm-cli](/pages/0106010202)开发环境后,可以通过以下步骤来使用我们提供的Docker环境。 - -### 搭建Docker环境 - -1. 初始化安装模板。在任意工作目录中执行以下命令。 - - ``` - hpm init -t @ohos/docker_dist - ``` - -2. 修改publishAs。 - - 因为获取到的是模板类型的包,要把包的类型改为需要的类型。 在当前目录下打开bundle.json文件,把"publishAs"字段的值由"template"改为"distribution"。 - - -### 获取及编译源码 - -执行编译。自动安装docker只能在Ubuntu环境下执行,如果其他环境,需要用户自行安装docker,然后拉取镜像,执行编译。 - -- **自动安装docker(Ubuntu环境)** - - 以下命令可以帮助用户自动安装docker, 拉取镜像,并且在容器中开始运行对应解决方案的拉取和编译。 - - **方式一:** - - 命令后接参数指定解决方案,格式如下: - - ``` - hpm run docker solution={product} - ``` - - \{product\}为需编译的解决方案,如:@ohos/hispark\_taurus、@ohos/hispark\_aries、@ohos/hispark\_pegasus。 - - **方式二:** - - 设置环境变量来选择解决方案,再执行编译命令。 - - 1. 选择解决方案。 - - ``` - export solution={product} - ``` - - \{product\}为需编译的解决方案,如:@ohos/hispark\_taurus、@ohos/hispark\_aries、@ohos/hispark\_pegasus。 - - 2. 获取源码及执行编译。 - - ``` - hpm run docker - ``` - - 以上两种方式以@ohos/hispark\_taurus为例,执行成功结果如下: - - ``` - ...... - ohos ipcamera_hispark_taurus build success! - @ohos/hispark_taurus: distribution building completed. - ``` - - -- **自行安装docker(非Ubuntu环境)** - - 自行安装docker相关操作如下: - - ``` - # 拉取镜像 - docker pull swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker:0.0.3# linux环境下的编译 - hpm run distWithDocker solution={product} - # windows下的编译,需要配置gitbash - hpm config set shellPath "gitbash路径" - hpm run distWithDocker solution={product} - ``` - diff --git "a/website/docs/01.OpenHarmony/11.\345\267\245\345\205\267/02.IDE\351\233\206\346\210\220\345\274\200\345\217\221\347\216\257\345\242\203.md" "b/website/docs/01.OpenHarmony/11.\345\267\245\345\205\267/02.IDE\351\233\206\346\210\220\345\274\200\345\217\221\347\216\257\345\242\203.md" deleted file mode 100644 index 34b7e11f920616ee09f2fc9377e2b454dd7f88ae..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/11.\345\267\245\345\205\267/02.IDE\351\233\206\346\210\220\345\274\200\345\217\221\347\216\257\345\242\203.md" +++ /dev/null @@ -1,30 +0,0 @@ ---- -title: IDE集成开发环境 -permalink: /pages/010b02 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# IDE - -- [获取设备开发工具(HUAWEI DevEco Device Tool)](#section2452141120244) -- [获取应用开发工具(HUAWEI DevEco Studio)](#section0904101019258) - -## 获取设备开发工具(HUAWEI DevEco Device Tool) - -HUAWEI DevEco Device Tool是OpenHarmony面向智能设备开发者提供的一站式集成开发环境,支持OpenHarmony的组件按需定制,支持代码编辑、编译、烧录、调试等功能,支持C/C++语言,以插件的形式部署在Visual Studio Code上。具体可参见[获取工具](https://device.harmonyos.com/cn/ide)和[工具使用指南](https://device.harmonyos.com/cn/docs/ide/user-guides/service_introduction-0000001050166905)**。** - -Huawei DevEco Device Tool支持 OpenHarmony设备开发的演进路标如下: - -![](/images/device-dev/get-code/figure/evolution-roadmap.png) - -## 获取应用开发工具(HUAWEI DevEco Studio) - -HUAWEI DevEco Studio(以下简称DevEco Studio)是面向华为终端全场景多设备的一站式集成开发环境(IDE),为开发者提供工程模板创建、开发、编译、调试、发布等E2E的OpenHarmony应用开发服务。通过使用DevEco Studio,开发者可以更高效的开发具备OpenHarmony分布式能力的应用,进而提升创新效率。具体可参见[获取工具](https://developer.harmonyos.com/cn/develop/deveco-studio)和[工具使用指南](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/tools_overview-0000001053582387)。 - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/01.Ability\346\241\206\346\236\266/01.FeatureAbility\346\250\241\345\235\227.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/01.Ability\346\241\206\346\236\266/01.FeatureAbility\346\250\241\345\235\227.md" deleted file mode 100644 index f83da1fa4318890e73795be4555754540b3224ba..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/01.Ability\346\241\206\346\236\266/01.FeatureAbility\346\250\241\345\235\227.md" +++ /dev/null @@ -1,692 +0,0 @@ ---- -title: FeatureAbility模块 -permalink: /pages/010c010101 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# FeatureAbility模块(JS端SDK接口) - -## 使用限制 - -FeatureAbility模块的接口只能在Page类型的Ability调用 - -## 导入模块 - -``` -import featureAbility from '@ohos.ability.featureAbility' -``` - -## featureAbility.startAbility - -startAbility(parameter: StartAbilityParameter, callback: AsyncCallback\): void - -启动新的ability(callback形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| --------- | --------------------- | ---- | ------------------- | -| parameter | [StartAbilityParameter](#startabilityparameter) | 是 | 表示被启动的Ability。 | -| callback | AsyncCallback\ | 是 | 被指定的回调方法。 | - -**示例:** - -```javascript -import featureAbility from '@ohos.ability.featureAbility' -featureAbility.startAbility( - { - want: - { - action: "", - entities: [""], - type: "", - flags: FLAG_AUTH_READ_URI_PERMISSION, - deviceId: "", - bundleName: "com.example.startability", - abilityName: "com.example.startability.MainAbility", - uri: "" - }, - }, - ); -) -``` - - - -## featureAbility.startAbility - -startAbility(parameter: StartAbilityParameter): Promise\ - -启动新的ability(Promise形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| --------- | ----------------------------------------------- | ---- | --------------------- | -| parameter | [StartAbilityParameter](#startabilityparameter) | 是 | 表示被启动的Ability。 | - -**示例:** - -```javascript -import featureAbility from '@ohos.ability.featureAbility' -featureAbility.startAbility( - { - want: - { - action: "action.system.home", - entities: ["entity.system.home"], - type: "MIMETYPE", - flags: FLAG_AUTH_READ_URI_PERMISSION, - deviceId: deviceId, - bundleName: "com.example.startability", - abilityName: "com.example.startability.MainAbility", - uri: "" - }, - } - ).then((void) => { - console.info("==========================>startAbility=======================>"); -}); -``` - -## featureAbility.acquireDataAbilityHelper - -acquireDataAbilityHelper(uri: string): DataAbilityHelper - -获取dataAbilityHelper。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| ---- | ------ | ---- | ------------------------ | -| uri | string | 是 | 指示要打开的文件的路径。 | - -**返回值:** - -| 类型 | 说明 | -| ----------------- | -------------------------------------------- | -| DataAbilityHelper | 用来协助其他Ability访问DataAbility的工具类。 | - -**示例:** - -```javascript -import featureAbility from '@ohos.ability.featureAbility' -featureAbility.acquireDataAbilityHelper( - "dataability:///com.exmaple.DataAbility" -) -``` - -## featureAbility.startAbilityForResult - -startAbilityForResult(parameter: StartAbilityParameter, callback: AsyncCallback\): void - -启动一个ability,并在该ability被销毁时返回执行结果(callback形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| --------- | ----------------------------------------------- | ---- | --------------------- | -| parameter | [StartAbilityParameter](#startabilityparameter) | 是 | 表示被启动的Ability。 | -| callback | AsyncCallback\<[AbilityResult](#abilityresult)> | 是 | 被指定的回调方法。 | - -**示例:** - -```javascript -import featureAbility from '@ohos.ability.featureability'; -featureAbility.startAbilityForResult( - { - want: - { - action: "action.system.home", - entities: ["entity.system.home"], - type: "MIMETYPE", - flags: FLAG_AUTH_READ_URI_PERMISSION, - deviceId: "", - bundleName: "com.example.featureabilitytest", - abilityName: "com.example.featureabilitytest.MainAbility", - uri:"" - }, - }, -) -``` - -## featureAbility.startAbilityForResult - -startAbilityForResult(parameter: StartAbilityParameter): Promise\ - -启动一个ability,并在该ability被销毁时返回执行结果(Promise形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| --------- | ----------------------------------------------- | ---- | ------------------- | -| parameter | [StartAbilityParameter](#startabilityparameter) | 是 | 表示被启动的Ability | - -**返回值:** -| 类型 | 说明 | -| ----------------------------------------- | -------------- | -| Promise\<[AbilityResult](#abilityresult)> | 返回执行结果。 | - -**示例:** - -```javascript -import featureAbility from '@ohos.ability.featureability'; -featureAbility.startAbilityForResult( - { - want: - { - action: "action.system.home", - entities: ["entity.system.home"], - type: "MIMETYPE", - flags: FLAG_AUTH_READ_URI_PERMISSION, - deviceId: "", - bundleName: "com.example.featureabilitytest", - abilityName: "com.example.featureabilitytest.MainAbility", - uri:"", - parameters: - { - mykey0: 1111, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "xxxxxxxxxxxxxxxxxxxxxx", - mykey4: [1, 15], - mykey5: [false, true, false], - mykey6: ["aaaaaa", "bbbbb", "ccccccccccc"], - mykey7: true, - }, - }, - requestCode: 2, - }, -).then((void) => { - console.info("==========================>startAbilityForResult=======================>"); -}); -``` - -## featureAbility.terminateSelfWithResult - -terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback\): void - -设置此Page Ability将返回给调用者的结果代码和数据并破坏此Page Ability(callback形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| --------- | ------------- | ---- | ------------------- | -| parameter | [AbilityResult](#abilityresult) | 是 | 表示被启动的Ability。 | -| callback | AsyncCallback\ | 是 | 被指定的回调方法。 | - -**示例:** - -```javascript -import featureAbility from '@ohos.ability.featureAbility' -featureAbility.terminateSelfWithResult( - { - resultCode: 1, - want: - { - action: "action.system.home", - entities: ["entity.system.home"], - type: "MIMETYPE", - flags: FLAG_AUTH_READ_URI_PERMISSION, - deviceId: "", - bundleName: "com.example.featureabilitytest", - abilityName: "com.example.featureabilitytest.MainAbility", - uri:"", - parameters: { - mykey0: 2222, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "ssssssssssssssssssssssssss", - mykey4: [1, 15], - mykey5: [false, true, false], - mykey6: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - mykey7: true, - } - }, - }, -); -``` - -## featureAbility.terminateSelfWithResult - -terminateSelfWithResult(parameter: AbilityResult): Promise\ - -设置此Page Ability将返回给调用者的结果代码和数据并破坏此Page Ability(Promise形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| --------- | ------------------------------- | ---- | ------------------- | -| parameter | [AbilityResult](#abilityresult) | 是 | 表示被启动的Ability | - -**返回值:** -| 类型 | 说明 | -| -------------- | ----------------------- | -| Promise\ | 以Promise形式返回结果。 | - -**示例:** - -```javascript -import featureAbility from '@ohos.ability.featureability'; -featureAbility.terminateSelfWithResult( - { - resultCode: 1, - want: - { - action: "action.system.home", - entities: ["entity.system.home"], - type: "MIMETYPE", - flags: FLAG_AUTH_READ_URI_PERMISSION, - deviceId: "", - bundleName: "com.example.featureabilitytest", - abilityName: "com.example.featureabilitytest.MainAbility", - uri:"", - parameters: { - mykey0: 2222, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "ssssssssssssssssssssssssss", - mykey4: [1, 15], - mykey5: [false, true, false], - mykey6: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - mykey7: true, - } - }, - } -).then((void) => { - console.info("==========================>terminateSelfWithResult=======================>"); -}); -``` - - - -## featureAbility.hasWindowFocus - -hasWindowFocus(callback: AsyncCallback\): void - -检查Ability的主窗口是否具有窗口焦点(callback形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| -------- | ----------------------- | ---- | ------------------------------------------------------------ | -| callback | AsyncCallback\ | 是 | 被指定的回调方法。
如果此Ability当前具有视窗焦点,则返回true;否则返回false。 | - -**示例:** - -```javascript -import featureAbility from '@ohos.ability.featureability'; -featureAbility.hasWindowFocus() -``` - - - -## featureAbility.hasWindowFocus - -hasWindowFocus(): Promise\ - -检查Ability的主窗口是否具有窗口焦点(Promise形式)。 - -**返回值:** - -| 类型 | 说明 | -| ----------------- | ---------------------------------------------------------- | -| Promise\ | 如果此Ability当前具有视窗焦点,则返回true;否则返回false。 | - -**示例:** - -```javascript -import featureAbility from '@ohos.ability.featureability'; -featureAbility.hasWindowFocus().then((void) => { - console.info("==========================>hasWindowFocus=======================>"); -}); -``` - - - -## featureAbility.getWant - -getWant(callback: AsyncCallback\): void - -获取从Ability发送的Want(callback形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| -------- | ----------------------------- | ---- | ------------------ | -| callback | AsyncCallback\<[Want](#want)> | 是 | 被指定的回调方法。 | - -**示例:** - -```javascript -import featureAbility from '@ohos.ability.featureability'; -featureAbility.getWant() -``` - - - -## featureAbility.getWant - -getWant(): Promise\ - -获取从Ability发送的Want(Promise形式)。 - -**返回值:** -| 类型 | 说明 | -| ----------------------- | ------------------------- | -| Promise\<[Want](#want)> | 以Promise的形式返回结果。 | - -**示例:** - -```javascript -import featureAbility from '@ohos.ability.featureability'; -featureAbility.getWant().then((void) => { - console.info("==========================>getWantCallBack=======================>"); -}); -``` - -## featureAbility.getContext - -getContext(): Context - -获取应用上下文。 - -**返回值:** -| 类型 | 说明 | -| ------- | -------------------- | -| Context | 返回应用程序上下文。 | - -**示例:** - -```javascript -import featureAbility from '@ohos.ability.featureability'; -var context = featureAbility.getContext() -context.getBundleName() -``` - - - -## featureAbility.terminateSelf - -terminateSelf(callback: AsyncCallback\): void - -设置Page Ability返回给被调用方的结果代码和数据,并销毁此Page Ability(callback形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| -------- | -------------------- | ---- | ---------------- | -| callback | AsyncCallback\ | 是 | 被指定的回调方法 | - -**示例:** - -```javascript -import featureAbility from '@ohos.ability.featureability'; -featureAbility.terminateSelf() -``` - - - -## featureAbility.terminateSelf - -terminateSelf(): Promise\ - -设置Page Ability返回给被调用方的结果代码和数据,并销毁此Page Ability(Promise形式)。 - -**返回值:** -| 类型 | 说明 | -| -------------- | ------------------------- | -| Promise\ | 以Promise的形式返回结果。 | - -**示例:** - -```javascript -import featureAbility from '@ohos.ability.featureability'; -featureAbility.terminateSelf().then((void) => { console.info("==========================>terminateSelfCallBack=======================>"); -}); -``` - -## featureAbility.connectAbility - -connectAbility(request: Want, options:ConnectOptions): number - -将当前ability连接到指定ServiceAbility(callback形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| ------- | -------------- | ---- | ---------------------------- | -| request | [Want](#want) | 是 | 表示被连接的ServiceAbility。 | -| options | ConnectOptions | 是 | 被指定的回调方法。 | - -**Want类型说明:** - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ------------ | -------- | -------- | ---- | ---------------------------------- | -| deviceId | 只读 | string | 否 | 表示被连接的ServiceAbility的设备id,缺省表示连接本地的ServiceAbility | -| bundleName | 只读 | string | 是 | 表示被连接的ServiceAbility的包名 | -| abilityName | 只读 | string | 是 | 表示被连接的ServiceAbility的类名 | - -**ConnectOptions类型说明:** - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ------------ | -------- | -------- | ---- | ---------------------------------- | -| onConnect | 只读 | function | 是 | 连接成功时的回调函数 | -| onDisconnect | 只读 | function | 是 | 连接失败时的回调函数 | -| onFailed | 只读 | function | 是 | ConnectAbility调用失败时的回调函数 | - -**返回值:** -| 类型 | 说明 | -| ------ | ------------------------ | -| number | 连接的ServiceAbilityID。 | - -**示例:** - -```javascript -import featureAbility from '@ohos.ability.featureAbility' -function onConnectCallback(element, remote){ - console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy)); -} -function onDisconnectCallback(element){ - console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId) -} -function onFailedCallback(code){ - console.log('featureAbilityTest ConnectAbility onFailed errCode : ' + code) -} -var connId = featureAbility.connectAbility( - { - deviceId: deviceId, - bundleName: "com.ix.ServiceAbility", - abilityName: "ServiceAbilityA", - }, - { - onConnect: onConnectCallback, - onDisconnect: onDisconnectCallback, - onFailed: onFailedCallback, - }, -); -``` - -## featureAbility.disconnectAbility - -disconnectAbility(connection: number, callback:AsyncCallback\): void - -断开与指定ServiceAbility的连接(callback形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| ---------- | ------------- | ---- | ------------------------------ | -| connection | number | 是 | 指定断开连接的ServiceAbilityID | -| callback | AsyncCallback\ | 是 | 被指定的回调方法 | - -**示例:** - -```javascript -import featureAbility from '@ohos.ability.featureAbility' -function onConnectCallback(element, remote){ - console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy)); -} -function onDisconnectCallback(element){ - console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId) -} -function onFailedCallback(code){ - console.log('featureAbilityTest ConnectAbility onFailed errCode : ' + code) -} -var connId = featureAbility.connectAbility( - { - bundleName: "com.ix.ServiceAbility", - abilityName: "ServiceAbilityA", - }, - { - onConnect: onConnectCallback, - onDisconnect: onDisconnectCallback, - onFailed: onFailedCallback, - }, -); -var result = featureAbility.disconnectAbility(connId, - (error,data) => { - console.log('featureAbilityTest DisConnectJsSameBundleName result errCode : ' + error.code + " data: " + data) - }, -); -``` - -## featureAbility.disconnectAbility - -disconnectAbility(connection: number): Promise\ - -断开与指定ServiceAbility的连接(Promise形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| ---------- | ------ | ---- | ------------------------------ | -| connection | number | 是 | 指定断开连接的ServiceAbilityID | - -**返回值:** -| 类型 | 说明 | -| -------------- | ----------------------- | -| Promise\ | 以Promise形式返回结果。 | - -**示例:** - -```javascript -import featureAbility from '@ohos.ability.featureAbility' -function onConnectCallback(element, remote){ - console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy)); -} -function onDisconnectCallback(element){ - console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId) -} -function onFailedCallback(code){ - console.log('featureAbilityTest ConnectAbility onFailed errCode : ' + code) -} -var connId = featureAbility.connectAbility( - { - bundleName: "com.ix.ServiceAbility", - abilityName: "ServiceAbilityA", - }, - { - onConnect: onConnectCallback, - onDisconnect: onDisconnectCallback, - onFailed: onFailedCallback, - }, -); -var result = await featureAbility.disconnectAbility(connId); -``` - -## featureAbility.continueAbility - -continueAbility(options: ContinueAbilityOptions, callback: AsyncCallback\): void - -迁移一个ability到目标设备,并返回执行结果(callback形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| -------- | ---------------------- | ---- | ------------------- | -| options | ContinueAbilityOptions | 是 | 表示被启动的Ability | -| callback | AsyncCallback\ | 是 | 被指定的回调方法 | - -**ContinueAbilityOptions类型说明:** - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ---------- | -------- | ------- | ---- | ------------------------------------------------------------ | -| deviceId | 只读 | string | 是 | 表示需要包含有关目标启动能力的信息。 | -| reversible | 只读 | boolean | 是 | 是否支持回迁的标志,目前不支持该功能,为保留字段,可填false。 | - -**示例:** - -```javascript -import featureAbility from '@ohos.ability.featureAbility' - -async StartContinueAbility(deviceId) { - let continueAbilityOptions = { - reversible: false, - deviceId: deviceId, - } - function ContinueAbilityCallback(err, data) { - console.info("[Demo] ContinueAbilityCallback, result err = " + JSON.stringify(err)); - console.info("[Demo] ContinueAbilityCallback, result data= " + JSON.stringify(data)); - } - await featureAbility.continueAbility(continueAbilityOptions, ContinueAbilityCallback); - console.info('[Demo] featureAbility.StartContinueAbility end'); -} -this.StartContinueAbility(remoteDeviceId); //remoteDeviceId is acquired from DeviceManager -``` - -## AbilityResult - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ---------- | -------- | --------------------- | ---- | ------------------------------------------------------------ | -| resultCode | 只读 | number | 是 | 指示销毁该能力后返回的结果代码。您可以定义结果代码来识别错误(暂不支持) | -| want | 只读 | [Want](#want) | 否 | 指示销毁该能力后返回的数据。您可以定义返回的数据。此参数可以为null。 | - -## StartAbilityParameter - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ------------------- | -------- | -------------------- | ---- | ------------------------------------------------------------ | -| want | 只读 | [Want](#want) | 是 | 表示需要包含有关目标启动能力的信息。 | -| abilityStartSetting | 只读 | {[key: string]: any} | 否 | 表示能力的特殊属性,当开发者启动能力时,该属性可以作为调用中的输入参数传递。 | - -## Want - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ----------- | -------- | -------------------- | ---- | ------------------------------------------------------------ | -| deviceId | 只读 | string | 否 | 表示运行指定Ability的设备ID。 | -| bundleName | 只读 | string | 否 | 表示包描述。如果在Want中同时指定了BundleName和AbilityName,则Want可以直接匹配到指定的Ability。 | -| abilityName | 只读 | string | 否 | 表示待启动的Ability名称。如果在Want中同时指定了BundleName和AbilityName,则Want可以直接匹配到指定的Ability。 | -| uri | 只读 | string | 否 | 表示Uri描述。如果在Want中指定了Uri,则Want将匹配指定的Uri信息,包括scheme, schemeSpecificPart, authority和path信息。 | -| type | 只读 | string | 否 | 表示MIME type类型描述,比如:"text/plain" 、 "image/*"等。 | -| flags | 只读 | number | 否 | 表示处理Want的方式。默认传数字,具体参考:[flags说明](#flags说明)。 | -| action | 只读 | string | 否 | 表示action选项描述。 | -| parameters | 只读 | {[key: string]: any} | 否 | 表示WantParams描述。 | -| entities | 只读 | Array\ | 否 | 表示entities相关描述。 | - -## flags说明 - -| 名称 | 参数 | 描述 | -| ------------------------------------ | ---------- | ------------------------------------------------------------ | -| FLAG_AUTH_READ_URI_PERMISSION | 0x00000001 | 指示对URI执行读取操作的授权 | -| FLAG_AUTH_WRITE_URI_PERMISSION | 0x00000002 | 指示对URI执行写入操作的授权 | -| FLAG_ABILITY_FORWARD_RESULT | 0x00000004 | 将结果返回给源能力 | -| FLAG_ABILITY_CONTINUATION | 0x00000008 | 确定是否可以将本地设备上的功能迁移到远程设备 | -| FLAG_NOT_OHOS_COMPONENT | 0x00000010 | 指定组件是否属于OHOS | -| FLAG_ABILITY_FORM_ENABLED | 0x00000020 | 指定是否启动某个能力 | -| FLAG_AUTH_PERSISTABLE_URI_PERMISSION | 0x00000040 | 指示URI上可能持久化的授权 | -| FLAG_AUTH_PREFIX_URI_PERMISSION | 0x00000080 | 指示对URI前缀进行授权的权限 | -| FLAG_ABILITYSLICE_MULTI_DEVICE | 0x00000100 | 支持分布式调度系统中的多设备启动 | -| FLAG_START_FOREGROUND_ABILITY | 0x00000200 | 指示无论主机应用程序是否已启动,都将启动使用服务模板的功能 | -| FLAG_ABILITY_CONTINUATION_REVERSIBLE | 0x00000400 | 表示迁移是可拉回的。 | -| FLAG_INSTALL_ON_DEMAND | 0x00000800 | 如果未安装指定的功能,请安装该功能 | -| FLAG_INSTALL_WITH_BACKGROUND_MODE | 0x80000000 | 如果未安装,使用后台模式安装该功能。 | -| FLAG_ABILITY_CLEAR_MISSION | 0x00008000 | 指示清除其他任务的操作。可以为传递给{@link ohos.app.Context#startAbility}的{@code Want}设置此标志,并且必须与{@link flag_ABILITY_NEW_MISSION}一起使用 | -| FLAG_ABILITY_NEW_MISSION | 0x10000000 | 指示在历史任务堆栈上创建任务的操作。 | -| FLAG_ABILITY_MISSION_TOP | 0x20000000 | 指示如果启动能力的现有实例已位于任务堆栈的顶部,则将重用该实例。否则,将创建一个新的能力实例。 | - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/01.Ability\346\241\206\346\236\266/02.ParticleAbility\346\250\241\345\235\227.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/01.Ability\346\241\206\346\236\266/02.ParticleAbility\346\250\241\345\235\227.md" deleted file mode 100644 index c6c10439c3083a424de2f2a72f4a93274dd674c6..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/01.Ability\346\241\206\346\236\266/02.ParticleAbility\346\250\241\345\235\227.md" +++ /dev/null @@ -1,553 +0,0 @@ ---- -title: ParticleAbility模块 -permalink: /pages/010c010102 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# particleAbility模块 - -## 使用限制 - -particleAbility模块用来对Data和Service类型的Ability进行操作。 - -## 导入模块 - -```js -import particleAbility from '@ohos.ability.particleAbility' -``` - -## particleAbility.startAbility - -startAbility(parameter: StartAbilityParameter, callback: AsyncCallback\: void - -使用此方法启动指定的particleAbility(callback形式)。 - -**参数:** - - -| 名称 | 类型 | 必填 | 描述 | -| --------- | ----------------------------------------------- | ---- | ----------------- | -| parameter | [StartAbilityParameter](#startabilityparameter) | 是 | 指示启动的ability | -| callback | AsyncCallback\ | 是 | 被指定的回调方法 | - -**示例:** - -```js -import particleAbility from '@ohos.ability.particleAbility' -particleAbility.startAbility( - { - want: - { - action: "action.system.home", - entities: ["entity.system.home"], - type: "MIMETYPE", - flags: FLAG_AUTH_READ_URI_PERMISSION; - deviceId: "", - bundleName: "com.example.Data", - abilityName: "com.example.Data.MainAbility", - uri:"" - }, - }, - (error, result) => { - console.log('particleAbility startAbility errCode:' + error + 'result:' + result) - }, -) -``` - - - -## particleAbility.startAbility - -startAbility(parameter: StartAbilityParameter): Promise\ -使用此方法启动指定的particleAbility(Promise形式)。 - -**参数:** - - -| 名称 | 类型 | 必填 | 描述 | -| --------- | ----------------------------------------------- | ---- | ----------------- | -| parameter | [StartAbilityParameter](#startabilityparameter) | 是 | 指示启动的ability | -**返回值:** -| 类型 | 说明 | -| -------------- | ------------------------- | -| Promise\ | 使用Promise形式返回结果。 | - -**示例:** - -```js -import particleAbility from '@ohos.ability.particleAbility' -particleAbility.startAbility( - { - want: - { - action: "action.system.home", - entities: ["entity.system.home"], - type: "MIMETYPE", - flags: FLAG_AUTH_READ_URI_PERMISSION; - deviceId: "", - bundleName: "com.example.Data", - abilityName: "com.example.Data.MainAbility", - uri:"" - }, - }, -).then((void) => { - console.info("particleAbility startAbility"); -}); -``` - - - -## particleAbility.terminateSelf - -terminateSelf(callback: AsyncCallback\): void - -终止particleAbility(callback形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| -------- | -------------------- | ---- | -------------------- | -| callback | AsyncCallback\ | 是 | 表示被指定的回调方法 | - -**示例:** - -```js -import particleAbility from '@ohos.ability.particleAbility' -particleAbility.terminateSelf( - (error, result) => { - console.log('particleAbility terminateSelf errCode:' + error + 'result:' + result) - } -) -``` - - - -## particleAbility.terminateSelf - -terminateSelf(): Promise\ - -终止particleAbility(Promise形式)。 - -**返回值:** -| 类型 | 说明 | -| -------------- | ------------------------- | -| Promise\ | 使用Promise形式返回结果。 | - -**示例:** - -```js -import particleAbility from '@ohos.ability.particleAbility' -particleAbility.terminateSelf().then((void) => { - console.info("particleAbility terminateSelf"); -}); -``` - - - -## particleAbility.acquireDataAbilityHelper - -acquireDataAbilityHelper(uri: string): DataAbilityHelper - -获取dataAbilityHelper。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| :--- | ------ | ---- | ------------------------ | -| uri | string | 是 | 指示要打开的文件的路径。 | - -**返回值:** - -| 类型 | 说明 | -| ----------------- | -------------------------------------------- | -| DataAbilityHelper | 用来协助其他Ability访问DataAbility的工具类。 | - -**示例:** - -```js -import particleAbility from '@ohos.ability.particleAbility' -var uri = ""; -particleAbility.acquireDataAbilityHelper(uri) -``` - -## particleAbility.connectAbility - -connectAbility(request: Want, options:ConnectOptions): number - -将当前ability连接到指定ServiceAbility(callback形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| ------- | -------------- | ---- | -------------------------- | -| request | [Want](#want) | 是 | 表示被连接的ServiceAbility | -| options | ConnectOptions | 是 | 被指定的回调方法 | - -**ConnectOptions类型说明:** - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ------------ | -------- | -------- | ---- | ---------------------------------- | -| onConnect | 只读 | function | 是 | 连接成功时的回调函数 | -| onDisconnect | 只读 | function | 是 | 断开连接时的回调函数 | -| onFailed | 只读 | function | 是 | ConnectAbility调用失败时的回调函数 | - -**返回值:** -| 类型 | 说明 | -| ------ | -------------------------- | -| number | 标识客户端与服务端的连接。 | - -**示例:** - -```javascript -import particleAbility from '@ohos.ability.particleAbility' -function onConnectCallback(element, remote){ - console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy)); -} -function onDisconnectCallback(element){ - console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId) -} -function onFailedCallback(code){ - console.log('particleAbilityTest ConnectAbility onFailed errCode : ' + code) -} -var connId = particleAbility.connectAbility( - { - bundleName: "com.ix.ServiceAbility", - abilityName: "com.ix.ServiceAbility.ServiceAbilityA", - }, - { - onConnect: onConnectCallback, - onDisconnect: onDisconnectCallback, - onFailed: onFailedCallback, - }, -); -``` - -## particleAbility.disconnectAbility - -disconnectAbility(connection: number, callback:AsyncCallback\): void - -断开与指定ServiceAbility的连接(callback形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| ---------- | ------------- | ---- | ------------------------------ | -| connection | number | 是 | 指定断开连接的ServiceAbilityID | -| callback | AsyncCallback\ | 是 | 被指定的回调方法 | - -**示例:** - -```javascript -import particleAbility from '@ohos.ability.particleAbility' -function onConnectCallback(element, remote){ - console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy)); -} -function onDisconnectCallback(element){ - console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId) -} -function onFailedCallback(code){ - console.log('particleAbilityTest ConnectAbility onFailed errCode : ' + code) -} -var connId = particleAbility.connectAbility( - { - bundleName: "com.ix.ServiceAbility", - abilityName: "com.ix.ServiceAbility.ServiceAbilityA", - }, - { - onConnect: onConnectCallback, - onDisconnect: onDisconnectCallback, - onFailed: onFailedCallback, - }, -); -var result = particleAbility.disconnectAbility(connId, - (error,data) => { - console.log('particleAbilityTest DisConnectAbility result errCode : ' + error.code + " data: " + data) - }, -); -``` - -## particleAbility.disconnectAbility - -disconnectAbility(connection: number): Promise\ - -断开与指定ServiceAbility的连接(Promise形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| ---------- | ------ | ---- | ------------------------------ | -| connection | number | 是 | 指定断开连接的ServiceAbilityID | - -**返回值:** -| 类型 | 说明 | -| -------------- | ------------------------- | -| Promise\ | 使用Promise形式返回结果。 | - -**示例:** - -```javascript -import particleAbility from '@ohos.ability.particleAbility' -function onConnectCallback(element, remote){ - console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy)); -} -function onDisconnectCallback(element){ - console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId) -} -function onFailedCallback(code){ - console.log('particleAbilityTest ConnectAbility onFailed errCode : ' + code) -} -var connId = particleAbility.connectAbility( - { - bundleName: "com.ix.ServiceAbility", - abilityName: "com.ix.ServiceAbility.ServiceAbilityA", - }, - { - onConnect: onConnectCallback, - onDisconnect: onDisconnectCallback, - onFailed: onFailedCallback, - }, -); -var result = particleAbility.disconnectAbility(connId).then((void) => { - console.info("particleAbilityTest disconnectAbility"); -}); -``` - -## StartAbilityParameter - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ------------------- | -------- | --------------------- | ---- | ------------------------------------------------------------ | -| want | 只读 | [Want](#want) | 是 | 表示需要包含有关目标启动能力的信息。 | -| abilityStartSetting | 只读 | {[key: string]: any} | 否 | 表示能力的特殊属性,当开发者启动能力时,该属性可以作为调用中的输入参数传递。 | - -## Want - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ----------- | -------- | -------------------- | ---- | ------------------------------------------------------------ | -| deviceId | 只读 | string | 否 | 表示运行指定Ability的设备ID。 | -| bundleName | 只读 | string | 否 | 表示包描述。如果在Want中同时指定了BundleName和AbilityName,则Want可以直接匹配到指定的Ability。 | -| abilityName | 只读 | string | 否 | 表示待启动的Ability名称。如果在Want中同时指定了BundleName和AbilityName,则Want可以直接匹配到指定的Ability。 | -| uri | 只读 | string | 否 | 表示Uri描述。如果在Want中指定了Uri,则Want将匹配指定的Uri信息,包括scheme, schemeSpecificPart, authority和path信息。 | -| type | 只读 | string | 否 | 表示MIME type类型描述,比如:"text/plain" 、 "image/*"等。 | -| flags | 只读 | number | 否 | 表示处理Want的方式。默认传数字,具体参考:[flags说明](#flags说明)。 | -| action | 只读 | string | 否 | 表示action选项描述。 | -| parameters | 只读 | {[key: string]: any} | 否 | 表示WantParams描述。 | -| entities | 只读 | Array\ | 否 | 表示entities相关描述。 | - -## flags说明 - -| 名称 | 参数 | 描述 | -| ------------------------------------ | ---------- | ------------------------------------------------------------ | -| FLAG_AUTH_READ_URI_PERMISSION | 0x00000001 | 指示对URI执行读取操作的授权 | -| FLAG_AUTH_WRITE_URI_PERMISSION | 0x00000002 | 指示对URI执行写入操作的授权 | -| FLAG_ABILITY_FORWARD_RESULT | 0x00000004 | 将结果返回给源能力 | -| FLAG_ABILITY_CONTINUATION | 0x00000008 | 确定是否可以将本地设备上的功能迁移到远程设备 | -| FLAG_NOT_OHOS_COMPONENT | 0x00000010 | 指定组件是否属于OHOS | -| FLAG_ABILITY_FORM_ENABLED | 0x00000020 | 指定是否启动某个能力 | -| FLAG_AUTH_PERSISTABLE_URI_PERMISSION | 0x00000040 | 指示URI上可能持久化的授权 | -| FLAG_AUTH_PREFIX_URI_PERMISSION | 0x00000080 | 将结果返回到源能力 | -| FLAG_ABILITYSLICE_MULTI_DEVICE | 0x00000100 | 支持分布式调度系统中的多设备启动 | -| FLAG_START_FOREGROUND_ABILITY | 0x00000200 | 指示无论主机应用程序是否已启动,都将启动使用服务模板的功能 | -| FLAG_ABILITY_CONTINUATION_REVERSIBLE | 0x00000400 | 表示迁移是可拉回的。 | -| FLAG_INSTALL_ON_DEMAND | 0x00000800 | 如果未安装指定的功能,请安装该功能 | -| FLAG_INSTALL_WITH_BACKGROUND_MODE | 0x80000000 | 如果未安装,使用后台模式安装该功能。 | -| FLAG_ABILITY_CLEAR_MISSION | 0x00008000 | 指示清除其他任务的操作。可以为传递给{@link ohos.app.Context#startAbility}的{@code Want}设置此标志,并且必须与{@link flag_ABILITY_NEW_MISSION}一起使用 | -| FLAG_ABILITY_NEW_MISSION | 0x10000000 | 指示在历史任务堆栈上创建任务的操作。 | -| FLAG_ABILITY_MISSION_TOP | 0x20000000 | 指示如果启动能力的现有实例已位于任务堆栈的顶部,则将重用该实例。否则,将创建一个新的能力实例。 | - -## AbilityStartSetting - -abilityStartSetting属性是一个定义为[key: string]: any的对象,key对应设定类型为:AbilityStartSetting枚举类型,value对应设定类型为:AbilityWindowConfiguration枚举类型。 - -使用时通过featureAbility.AbilityStartSetting获取,示例:featureAbility.AbilityStartSetting.BOUNDS_KEY。 - -| 名称 | 参数 | 描述 | -| --------------- | --------------- | -------------------------- | -| BOUNDS_KEY | "abilityBounds" | 窗口显示大小属性的名称。 | -| WINDOW_MODE_KEY | "windowMode" | 窗口显示模式属性的名称。 | -| DISPLAY_ID_KEY | "displayId" | 窗口显示设备ID属性的名称。 | - -## AbilityWindowConfiguration - -使用时通过featureAbility.AbilityWindowConfiguration获取,示例:featureAbility.AbilityWindowConfiguration.WINDOW_MODE_UNDEFINED。 - -| 名称 | 参数 | 描述 | -| --------------------------- | ---- | ---------- | -| WINDOW_MODE_UNDEFINED | 0 | 未定义。 | -| WINDOW_MODE_FULLSCREEN | 1 | 全屏。 | -| WINDOW_MODE_SPLIT_PRIMARY | 100 | 分屏主屏。 | -| WINDOW_MODE_SPLIT_SECONDARY | 101 | 分屏次屏。 | -| WINDOW_MODE_FLOATING | 102 | 悬浮窗。 | - - -## particleAbility.startBackgroundRunning - -startBackgroundRunning(id: number, request: NotificationRequest, callback: AsyncCallback<void>): void; - -向系统申请长时任务,使用callback形式返回结果。(此接口为api7接口,后续会被废弃,请使用新的api8接口) - -- **参数**: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | id | number | 是 | 长时任务通知id号 | - | request | NotificationRequest | 是 | 通知参数,用于显示通知栏的信息 | - | callback | AsyncCallback<void> | 是 | callback形式返回启动长时任务的结果 | - -- **示例**: -```js -import notification from '@ohos.notification'; -import particleAbility from '@ohos.ability.particleAbility'; -import wantAgent from '@ohos.wantAgent'; - -function callback(err, data) { - if (err) { - console.error("Operation failed Cause: " + err); - } else { - console.info("Operation succeeded"); - } -} - -let wantAgentInfo = { - wants: [ - { - bundleName: "com.example.myapplication", - abilityName: "com.example.myapplication.MainAbility" - } - ], - operationType: wantAgent.OperationType.START_ABILITY, - requestCode: 0, - wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESET_FLAG] -}; - -wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { - let basicContent = { - title: "title", - text: "text" - }; - let notificationContent = { - contentType: notification.ContentType.NOTIFICATION_CONTENT_TEXT, - normal: basicContent - }; - let request = { - content: notificatonContent, - wantAgent: wantAgentObj - }; - let id = 1; - particleAbility.startBackgroundRunning(id, request, callback); -}); - -``` - -## particleAbility.startBackgroundRunning - -startBackgroundRunning(id: number, request: NotificationRequest): Promise<void> - -向系统申请长时任务,使用promise形式返回结果。(此接口为api7接口,后续会被废弃,请使用新的api8接口) - -**参数**: -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| id | number | 是 | 长时任务通知id号 | -| request | NotificationRequest | 是 | 通知参数,用于显示通知栏的信息 | - -**返回值** -| 类型 | 说明 | -| -------------- | ------------------------- | -| Promise\ | 使用Promise形式返回结果。 | - -- **示例**: -```js -import notification from '@ohos.notification'; -import particleAbility from '@ohos.ability.particleAbility'; -import wantAgent from '@ohos.wantAgent'; - -let wantAgentInfo = { - wants: [ - { - bundleName: "com.example.myapplication", - abilityName: "com.example.myapplication.MainAbility" - } - ], - operationType: wantAgent.OperationType.START_ABILITY, - requestCode: 0, - wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESET_FLAG] -}; - -wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { - let basicContent = { - title: "title", - text: "text" - }; - let notificationContent = { - contentType: notification.ContentType.NOTIFICATION_CONTENT_TEXT, - normal: basicContent - }; - let request = { - content: notificatonContent, - wantAgent: wantAgentObj - }; - let id = 1; - particleAbility.startBackgroundRunning(id, request).then(() => { - console.info("Operation succeeded"); - }).catch((err) => { - console.error("Operation failed Cause: " + err); - }); -}); - -``` - -## particleAbility.cancelBackgroundRunning - -cancelBackgroundRunning(callback: AsyncCallback<void>): void; - -向系统申请取消长时任务,使用callback形式返回结果。(此接口为api7接口,后续会被废弃,请使用新的api8接口) - -- **参数**: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<void> | 是 | callback形式返回启动长时任务的结果 | - -- **示例**: -```js -import particleAbility from '@ohos.ability.particleAbility'; - -function callback(err, data) { - if (err) { - console.error("Operation failed Cause: " + err); - } else { - console.info("Operation succeeded"); - } -} - -particleAbility.cancelBackgroundRunning(callback); - -``` - -## particleAbility.cancelBackgroundRunning - -cancelBackgroundRunning(): Promise<void>; - -向系统申请取消长时任务,使用promise形式返回结果。(此接口为api7接口,后续会被废弃,请使用新的api8接口) - -**返回值** -| 类型 | 说明 | -| -------------- | ------------------------- | -| Promise\ | 使用Promise形式返回结果。 | - -- **示例**: -```js -import particleAbility from '@ohos.ability.particleAbility'; - -particleAbility.cancelBackgroundRunning().then(() => { - console.info("Operation succeeded"); -}).catch((err) => { - console.error("Operation failed Cause: " + err); -}); - -``` \ No newline at end of file diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/01.Ability\346\241\206\346\236\266/03.DataAbilityHelper\346\250\241\345\235\227.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/01.Ability\346\241\206\346\236\266/03.DataAbilityHelper\346\250\241\345\235\227.md" deleted file mode 100644 index 7ed7ef2433f591aecfe5f264c8fc2a8a4111dd3f..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/01.Ability\346\241\206\346\236\266/03.DataAbilityHelper\346\250\241\345\235\227.md" +++ /dev/null @@ -1,812 +0,0 @@ ---- -title: DataAbilityHelper模块 -permalink: /pages/010c010103 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# DataAbilityHelper模块(JS端SDK接口) - -## 导入模块 - -``` -import featureAbility from '@ohos.ability.featureAbility' -import ohos_data_ability from '@ohos.data.dataability' -import ohos_data_rdb from '@ohos.data.rdb' -``` - -## DataAbilityHelper - -### openFile - -openFile(uri: string, mode: string, callback: AsyncCallback\): void - -在指定的远程路径中打开文件(callback形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| -------- | ---------------------- | ---- | ---------------------------------- | -| uri | string | 是 | 指示要打开的文件的路径。 | -| mode | string | 是 | 指示文件打开模式‘rwt’。 | -| callback | AsyncCallback\ | 是 | 被指定的回调方法,返回文件描述符。 | - -**示例:** - -```javascript -import featureAbility from '@ohos.ability.featureAbility' -var DAHelper = featureAbility.acquireDataAbilityHelper( - "dataability:///com.example.DataAbility" -); -var mode = "rwt"; -DAHelper.openFile( - "dataability:///com.example.DataAbility", - mode, - (err) => { - console.info("==========================>Called=======================>"); -}); -``` - -### openFile - -openFile(uri: string, mode: string): Promise\ - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| ---- | ------ | ---- | ------------------------ | -| uri | string | 是 | 指示要打开的文件的路径。 | -| mode | string | 是 | 指示文件打开模式‘rwt’。 | - -**返回值:** -| 类型 | 说明 | -| ---------------- | ---------------- | -| Promise\ | 返回文件描述符。 | - -**示例:** - -```javascript -import featureAbility from '@ohos.ability.featureAbility' -var DAHelper = featureAbility.acquireDataAbilityHelper( - "dataability:///com.example.DataAbility" -); -var mode = "rwt"; -DAHelper.openFile( - "dataability:///com.example.DataAbility", - mode).then((void) => { - console.info("==========================>openFileCallback=======================>"); -}); -``` - -### on('dataChange') - -on(type: 'dataChange', uri: string, callback: AsyncCallback\): void - -注册观察者以观察给定uri指定的数据callback通知。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| -------- | -------------------- | ---- | ------------------------ | -| type | string | 是 | 数据更改。 | -| uri | string | 是 | 指示要操作的数据的路径。 | -| callback | AsyncCallback\ | 是 | 指示数据更改时的回调。 | - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -var helper = featureAbility.acquireDataAbilityHelper( - "dataability:///com.example.DataAbility" -); -function onChangeNotify() { - console.info("==========================>onChangeNotify=======================>"); -}; -helper.on( - "dataChange", - "dataability:///com.example.DataAbility", - onChangeNotify -) -``` - -### off('dataChange') - -off(type: 'dataChange', uri: string, callback?: AsyncCallback\): void - -注消观察者以停止观察给定uri指定的数据callback通知。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| -------- | -------------------- | ---- | ------------------------ | -| type | string | 是 | 数据更改。 | -| uri | string | 是 | 指示要操作的数据的路径。 | -| callback | AsyncCallback\ | 否 | 指示已注册的回调。 | - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -var helper = featureAbility.acquireDataAbilityHelper( - "dataability:///com.example.DataAbility" -); -function onChangeNotify() { - console.info("==========================>onChangeNotify=======================>"); -}; -helper.off( - "dataChange", - "dataability:///com.example.DataAbility", -) -helper.off( - "dataChange", - "dataability:///com.example.DataAbility", - onChangeNotify -) -``` - -### getType - -getType(uri: string, callback: AsyncCallback\): void - -获取给定URI指定数据的MIME类型(callback形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| -------- | ---------------------- | ---- | --------------------------------------------- | -| uri | string | 是 | 指示要操作的数据的路径。 | -| callback | AsyncCallback\ | 是 | 回调方法,返回与uri指定的数据匹配的MIME类型。 | - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -var DAHelper = featureAbility.acquireDataAbilityHelper( - "dataability:///com.example.DataAbility" -); -DAHelper.getType( - "dataability:///com.example.DataAbility", - (err, data) => { - console.info("==========================>Called=======================>"); -}); -``` - -### getType - -getType(uri: string): Promise\ - -获取给定URI指定数据的MIME类型(Promise形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| ---- | ------ | ---- | ------------------------ | -| uri | string | 是 | 指示要操作的数据的路径。 | - -**返回值:** -| 类型 | 说明 | -| ---------------- | ----------------------------------- | -| Promise\ | 返回与uri指定的数据匹配的MIME类型。 | - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -var DAHelper = featureAbility.acquireDataAbilityHelper( - "dataability:///com.example.DataAbility" -); -DAHelper.getType( - "dataability:///com.example.DataAbility" - ).then((data) => { - console.info("==========================>getTypeCallback=======================>"); -}); -``` - -### getFileTypes - -getFileTypes(uri: string, mimeTypeFilter: string, callback: AsyncCallback>): void - -获取支持的文件的MIME类型(callback形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| -------------- | ------------------------------ | ---- | ---------------------------------- | -| uri | string | 是 | 指示要获取的文件的路径。 | -| mimeTypeFilter | string | 是 | 指示要获取的文件的MIME类型。 | -| callback | AsyncCallback\> | 是 | 回调方法,返回匹配的MIME类型数组。 | - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -var DAHelper = featureAbility.acquireDataAbilityHelper( - "dataability:///com.example.DataAbility" -); -DAHelper.getFileTypes( - "dataability:///com.example.DataAbility", - "image/*", - (err, data) => { - console.info("==========================>Called=======================>"); -}); -``` - - - -### getFileTypes - -getFileTypes(uri: string, mimeTypeFilter: string): Promise\> - -获取支持的文件的MIME类型(Promise形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| -------------- | ------ | ---- | ---------------------------- | -| uri | string | 是 | 指示要获取的文件的路径。 | -| mimeTypeFilter | string | 是 | 指示要获取的文件的MIME类型。 | - -**返回值:** -| 类型 | 说明 | -| ------------------------ | ------------------------ | -| Promise\> | 返回匹配的MIME类型数组。 | - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -var DAHelper = featureAbility.acquireDataAbilityHelper( - "dataability:///com.example.DataAbility" -); -DAHelper.getFileTypes( - "dataability:///com.example.DataAbility", - "image/*" - ).then((data) => { - console.info("==========================>getFileTypesCallback=======================>"); -}); -``` - -### normalizeUri - -normalizeUri(uri: string, callback: AsyncCallback\): void - -将引用数据功能的给定uri转换为规范化uri(callback形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| -------- | ---------------------- | ---- | ------------------------------------------------------------ | -| uri | string | 是 | 指示要规范化的uri对象。 | -| callback | AsyncCallback\ | 是 | 回调方法。如果数据功能支持uri规范化或null,则返回规范化uri对象。 | - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -var DAHelper = featureAbility.acquireDataAbilityHelper( - "dataability:///com.example.DataAbility" -); -DAHelper.normalizeUri( - "dataability:///com.example.DataAbility", - (err, data) => { - console.info("==========================>Called=======================>"); -}); -``` - -### normalizeUri - -normalizeUri(uri: string): Promise\ - -将引用数据功能的给定uri转换为规范化uri(Promise形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| ---- | ------ | ---- | ----------------------- | -| uri | string | 是 | 指示要规范化的uri对象。 | - -**返回值:** -| 类型 | 说明 | -| ---------------- | ------------------------------------------------------ | -| Promise\ | 如果数据功能支持uri规范化或null,则返回规范化uri对象。 | - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -var DAHelper = featureAbility.acquireDataAbilityHelper( - "dataability:///com.example.DataAbility" -); -DAHelper.normalizeUri( - "dataability:///com.example.DataAbility", - ).then((data) => { - console.info("==========================>normalizeUriCallback=======================>"); -}); -``` - -### denormalizeUri - -denormalizeUri(uri: string, callback: AsyncCallback\): void - -将由normalizeUri(uri)生成的给定规范化uri转换为非规范化uri(callback形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| -------- | ---------------------- | ---- | --------------------------------------------------- | -| uri | string | 是 | 指示要规范化的uri对象。 | -| callback | AsyncCallback\ | 是 | 回调方法。如果反规范化成功,则返回反规范化uri对象。 | - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -var DAHelper = featureAbility.acquireDataAbilityHelper( - "dataability:///com.example.DataAbility" -); -DAHelper.denormalizeUri( - "dataability:///com.example.DataAbility",, - (err, data) => { - console.info("==========================>Called=======================>"); -}); -``` - - - -### denormalizeUri - -denormalizeUri(uri: string): Promise\ - -将由normalizeUri(uri)生成的给定规范化uri转换为非规范化uri(Promise形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| ---- | ------ | ---- | ----------------------- | -| uri | string | 是 | 指示要规范化的uri对象。 | - -**返回值:** -| 类型 | 说明 | -| ---------------- | ----------------------------------------- | -| Promise\ | 如果反规范化成功,则返回反规范化uri对象。 | - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -var DAHelper = featureAbility.acquireDataAbilityHelper( - "dataability:///com.example.DataAbility" -); -DAHelper.denormalizeUri( - "dataability:///com.example.DataAbility", - ).then((data) => { - console.info("==========================>denormalizeUriCallback=======================>"); -}); -``` - -### notifyChange - -notifyChange(uri: string, callback: AsyncCallback\): void - -通知已注册的观察者uri指定的数据资源的更改(callback形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| -------- | -------------------- | ---- | ------------------------ | -| uri | string | 是 | 指示要操作的数据的路径。 | -| callback | AsyncCallback\ | 是 | 回调方法。 | - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -var helper = featureAbility.acquireDataAbilityHelper( - "dataability:///com.example.DataAbility" -); -helper.notifyChange( - "dataability:///com.example.DataAbility",, - (err) => { - console.info("==========================>Called=======================>"); -}); -``` - -### notifyChange - -notifyChange(uri: string): Promise\ - -通知已注册的观察者uri指定的数据资源的更改(Promise形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| ---- | ------ | ---- | ------------------------ | -| uri | string | 是 | 指示要操作的数据的路径。 | - -**返回值:** -| 类型 | 说明 | -| -------------- | --------------------- | -| Promise\ | 返回值为Promise对象。 | - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -var DAHelper = featureAbility.acquireDataAbilityHelper( - "dataability:///com.example.DataAbility" -); -DAHelper.notifyChange( - "dataability:///com.example.DataAbility", - ).then((void) => { - console.info("==========================>notifyChangeCallback=======================>"); -}); -``` - -### insert - -insert(uri: string, valuesBucket: rdb.ValuesBucket, callback: AsyncCallback\): void - -将单个数据记录插入数据库(callback形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| ------------ | ---------------------- | ---- | ------------------------------------------------------ | -| uri | string | 是 | 指示要插入的数据的路径。 | -| valuesBucket | rdb.ValuesBucket | 是 | 指示要插入的数据记录。如果此参数为空,将插入一个空行。 | -| callback | AsyncCallback\ | 是 | 回调方法,返回插入数据记录的索引。 | - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -var DAHelper = featureAbility.acquireDataAbilityHelper( - "dataability:///com.example.DataAbility" -); -const valueBucket = { - "name": "rose", - "age": 22, - "salary": 200.5, - "blobType": u8, -} -DAHelper.insert( - "dataability:///com.example.DataAbility", - valueBucket, - (err, data) => { - console.info("==========================>Called=======================>"); -}); -``` - -### insert - -insert(uri: string, valuesBucket: rdb.ValuesBucket): Promise\ - -将单个数据记录插入数据库(Promise形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| ------------ | ---------------- | ---- | ------------------------------------------------------ | -| uri | string | 是 | 指示要插入的数据的路径。 | -| valuesBucket | rdb.ValuesBucket | 是 | 指示要插入的数据记录。如果此参数为空,将插入一个空行。 | - -**返回值:** -| 类型 | 说明 | -| ---------------- | ------------------------ | -| Promise\ | 返回插入数据记录的索引。 | - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -var DAHelper = featureAbility.acquireDataAbilityHelper( - "dataability:///com.example.DataAbility" -); -const valueBucket = { - "name": "rose1", - "age": 221, - "salary": 20.5, - "blobType": u8, -} -DAHelper.insert( - "dataability:///com.example.DataAbility", - valueBucket - ).then((data) => { - console.info("==========================>insertCallback=======================>"); -}); -``` - -### batchInsert - -batchInsert(uri: string, valuesBuckets: Array, callback: AsyncCallback\): void - -插入数据库(callback形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| ------------ | ----------------------- | ---- | -------------------------------- | -| uri | string | 是 | 指示要插入的数据的路径。 | -| valuesBucket | Array | 是 | 指示要插入的数据记录。 | -| callback | AsyncCallback\ | 是 | 回调方法。返回插入的数据记录数。 | - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -var DAHelper = featureAbility.acquireDataAbilityHelper( - "dataability:///com.example.DataAbility" -); -var cars = new Array({"name": "roe11", "age": 21, "salary": 20.5, "blobType": u8,}, - {"name": "roe12", "age": 21, "salary": 20.5, "blobType": u8,}, - {"name": "roe13", "age": 21, "salary": 20.5, "blobType": u8,}) -DAHelper.batchInsert( - "dataability:///com.example.DataAbility", - cars, - (err, data) => { - console.info("==========================>Called=======================>"); -}); -``` - -### batchInsert - -batchInsert(uri: string, valuesBuckets: Array): Promise\ - -将多个数据记录插入数据库(Promise形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| ------------ | ----------------------- | ---- | ------------------------ | -| uri | string | 是 | 指示要插入的数据的路径。 | -| valuesBucket | Array | 是 | 指示要插入的数据记录。 | - -**返回值:** -| 类型 | 说明 | -| ---------------- | ---------------------- | -| Promise\ | 返回插入的数据记录数。 | - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -var DAHelper = featureAbility.acquireDataAbilityHelper( - "dataability:///com.example.DataAbility" -); -var cars = new Array({"name": "roe11", "age": 21, "salary": 20.5, "blobType": u8,}, - {"name": "roe12", "age": 21, "salary": 20.5, "blobType": u8,}, - {"name": "roe13", "age": 21, "salary": 20.5, "blobType": u8,}) -DAHelper.batchInsert( - "dataability:///com.example.DataAbility", - cars - ).then((data) => { - console.info("==========================>batchInsertCallback=======================>"); -}); -``` - -### delete - -delete(uri: string, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback\): void - -从数据库中删除一个或多个数据记录(callback形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| ------------ | --------------------------------- | ---- | ------------------------------------------------ | -| uri | string | 是 | 指示要删除的数据的路径。 | -| valuesBucket | dataAbility.DataAbilityPredicates | 是 | 指示筛选条件。当此参数为null时,应定义处理逻辑。 | -| callback | AsyncCallback\ | 是 | 回调方法。返回已删除的数据记录数。 | - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -import ohos_data_ability from '@ohos.data.dataability' -var DAHelper = featureAbility.acquireDataAbilityHelper( - "dataability:///com.example.DataAbility" -); -let da = new ohos_data_ability.DataAbilityPredicates() -DAHelper.delete( - "dataability:///com.example.DataAbility", - da, - (err, data) => { - console.info("==========================>Called=======================>"); -}); -``` - -### delete - -delete(uri: string, predicates: dataAbility.DataAbilityPredicates): Promise\ - -从数据库中删除一个或多个数据记录(Promise形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| ------------ | --------------------------------- | ---- | ------------------------------------------------ | -| uri | string | 是 | 指示要删除的数据的路径。 | -| valuesBucket | dataAbility.DataAbilityPredicates | 是 | 指示筛选条件。当此参数为null时,应定义处理逻辑。 | - -**返回值:** -| 类型 | 说明 | -| ---------------- | ------------------------ | -| Promise\ | 返回已删除的数据记录数。 | - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -var DAHelper = featureAbility.acquireDataAbilityHelper( - "dataability:///com.example.DataAbility" -); -let da = new ohos_data_ability.DataAbilityPredicates() -DAHelper.delete( - "dataability:///com.example.DataAbility", - da - ).then((data) => { - console.info("==========================>deleteCallback=======================>"); -}); -``` - -### update - -update(uri: string, valuesBucket: rdb.ValuesBucket, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback\): void - -更新数据库中的数据记录(callback形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| ------------ | --------------------------------- | ---- | ------------------------------------------------ | -| uri | string | 是 | 指示要更新的数据的路径。 | -| valuesBucket | rdb.ValuesBucket | 是 | 指示要更新的数据。 | -| predicates | dataAbility.DataAbilityPredicates | 是 | 指示筛选条件。当此参数为null时,应定义处理逻辑。 | -| callback | AsyncCallback\ | 是 | 回调方法,返回更新的数据记录数。 | - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -import ohos_data_ability from '@ohos.data.dataability' -var DAHelper = featureAbility.acquireDataAbilityHelper( - "dataability:///com.example.DataAbility" -); -const va = { - "name": "roe1", - "age": 21, - "salary": 20.5, - "blobType": u8, -} -let da = new ohos_data_ability.DataAbilityPredicates() -DAHelper.update( - "dataability:///com.example.DataAbility", - va, - da, - (err, data) => { - console.info("==========================>Called=======================>"); -}); -``` - -### update - -update(uri: string, valuesBucket: rdb.ValuesBucket, predicates: dataAbility.DataAbilityPredicates): Promise\ - -更新数据库中的数据记录(Promise形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| ------------ | --------------------------------- | ---- | ------------------------------------------------ | -| uri | string | 是 | 指示要更新的数据的路径。 | -| valuesBucket | rdb.ValuesBucket | 是 | 指示要更新的数据。 | -| predicates | dataAbility.DataAbilityPredicates | 是 | 指示筛选条件。当此参数为null时,应定义处理逻辑。 | - -**返回值:** -| 类型 | 说明 | -| ---------------- | -------------------------------------------- | -| Promise\ | 返回值为Promise对象,Promise中包含应用信息。 | - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -import ohos_data_ability from '@ohos.data.dataability' -var DAHelper = featureAbility.acquireDataAbilityHelper( - "dataability:///com.example.DataAbility" -); -const va = { - "name": "roe1", - "age": 21, - "salary": 20.5, - "blobType": u8, -} -let da = new ohos_data_ability.DataAbilityPredicates() -DAHelper.update( - "dataability:///com.example.DataAbility", - va, - da - ).then((data) => { - console.info("==========================>updateCallback=======================>"); -}); -``` - -### query - -query(uri: string, columns: Array\, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback\): void - -查询数据库中的数据(callback形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| ---------- | --------------------------------- | ---- | ------------------------------------------------ | -| uri | string | 是 | 指示要查询的数据的路径。 | -| columns | rdb.ValuesBucket | 是 | 指示要查询的列。如果此参数为空,则查询所有列。 | -| predicates | dataAbility.DataAbilityPredicates | 是 | 指示筛选条件。当此参数为null时,应定义处理逻辑。 | -| callback | AsyncCallback\ | 是 | 回调方法,返回查询结果。 | - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -import ohos_data_ability from '@ohos.data.dataability' -var DAHelper = featureAbility.acquireDataAbilityHelper( - "dataability:///com.example.DataAbility" -); -var cars=new Array({"value1"}, {"value2"}, {"value3"}, {"value4"}); -let da = new ohos_data_ability.DataAbilityPredicates() -DAHelper.query( - "dataability:///com.example.DataAbility", - cars, - da, - (err, data) => { - console.info("==========================>Called=======================>"); -}); -``` - - - -### query - -query(uri: string, columns: Array\, predicates: dataAbility.DataAbilityPredicates): Promise\ - -查询数据库中的数据(Promise形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| ---------- | --------------------------------- | ---- | ------------------------------------------------ | -| uri | string | 是 | 指示要查询的数据的路径。 | -| columns | rdb.ValuesBucket | 是 | 指示要查询的列。如果此参数为空,则查询所有列。 | -| predicates | dataAbility.DataAbilityPredicates | 是 | 指示筛选条件。当此参数为null时,应定义处理逻辑。 | - -**返回值:** -| 类型 | 说明 | -| ------------------- | -------------- | -| Promise\ | 返回查询结果。 | - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -import ohos_data_ability from '@ohos.data.dataability' -var DAHelper = featureAbility.acquireDataAbilityHelper( - "dataability:///com.example.DataAbility" -); -var cars=new Array({"value1"}, {"value2"}, {"value3"}, {"value4"}); -let da = new ohos_data_ability.DataAbilityPredicates() -DAHelper.query( - "dataability:///com.example.DataAbility", - cars, - da - ).then((data) => { - console.info("==========================>queryCallback=======================>"); -}); -``` \ No newline at end of file diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/01.Ability\346\241\206\346\236\266/04.DataUriUtils\346\250\241\345\235\227.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/01.Ability\346\241\206\346\236\266/04.DataUriUtils\346\250\241\345\235\227.md" deleted file mode 100644 index e13d9821f35b7d008b1f5f859e47c6fd62bb413e..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/01.Ability\346\241\206\346\236\266/04.DataUriUtils\346\250\241\345\235\227.md" +++ /dev/null @@ -1,135 +0,0 @@ ---- -title: DataUriUtils模块 -permalink: /pages/010c010104 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# DataUriUtils模块 - -## 导入模块 - -```js -import dataUriUtils from '@ohos.ability.dataUriUtils'; -``` - -## dataUriUtils.getId - -getId(uri: string): number - -获取附加到给定uri的路径组件末尾的ID。 - -**参数:** - - -| 名称 | 类型 | 必填 | 描述 | -| ---- | ------ | ---- | --------------------------- | -| uri | string | 是 | 指示要从中获取ID的uri对象。 | - -**返回值:** -| 类型 | 说明 | -| ------ | ------------------------ | -| number | 附加到路径组件末尾的ID。 | - -**示例:** - -```js -import dataUriUtils from '@ohos.ability.datauriutils' -dataUriUtils.getIdSync("com.example.dataUriUtils/1221") -``` - - - -## dataUriUtils.attachId - -attachId(uri: string, id: number): string - -将给定ID附加到给定uri的路径组件的末尾。 - -**参数:** - - -| 名称 | 类型 | 必填 | 描述 | -| ---- | ------ | ---- | --------------------------- | -| uri | string | 是 | 指示要从中获取ID的uri对象。 | -| id | number | 是 | 指示要附加的ID。 | - -**返回值:** -| 类型 | 说明 | -| ------ | --------------------- | -| string | 附加给定ID的uri对象。 | - -**示例:** - -```js -import dataUriUtils from '@ohos.ability.datauriutils' -var idint = 1122; -dataUriUtils.attachId( - "com.example.dataUriUtils" - idint, -) -``` - - - -## dataUriUtils.deleteId - -deleteId(uri: string): string - -从给定uri的路径组件的末尾删除ID。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| ---- | ------ | ---- | --------------------------- | -| uri | string | 是 | 指示要从中删除ID的uri对象。 | - -**返回值:** -| 类型 | 说明 | -| ------ | ------------------- | -| string | ID已删除的uri对象。 | - -**示例:** - -```js -import dataUriUtils from '@ohos.ability.datauriutils' -dataUriUtils.deleteId("com.example.dataUriUtils/1221") -``` - - - -## dataUriUtils.updateId - -updateId(uri: string, id: number): string - -更新指定uri中的ID。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| ---- | ------ | ---- | ------------------- | -| uri | string | 是 | 指示要更新的uri对象 | -| id | number | 是 | 指示新ID | - -**返回值:** -| 类型 | 说明 | -| ------ | --------------- | -| string | 更新的uri对象。 | - -**示例:** - -```js -import dataUriUtils from '@ohos.ability.datauriutils' -var idint = 1122; -dataUriUtils.updateId( - "com.example.dataUriUtils" - idint, -) -``` - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/01.Ability\346\241\206\346\236\266/05.Bundle\346\250\241\345\235\227.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/01.Ability\346\241\206\346\236\266/05.Bundle\346\250\241\345\235\227.md" deleted file mode 100644 index f81c9d19ffe3868b5f433e7d9929a96aa8d5390d..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/01.Ability\346\241\206\346\236\266/05.Bundle\346\250\241\345\235\227.md" +++ /dev/null @@ -1,1298 +0,0 @@ ---- -title: Bundle模块 -permalink: /pages/010c010105 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# Bundle模块(JS端SDK接口) - -## 导入模块 - -``` -import bundle from '@ohos.bundle'; -``` - -## 系统能力 - -SystemCapability.BundleManager.BundleFramework - -## 权限列表 - -无 - -## bundle.getApplicationInfo - -getApplicationInfo(bundleName: string, bundleFlags: number, userId: number): Promise\ - -以异步方法根据给定的包名获取ApplicationInfo,使用Promise形式返回结果。 - -**需要权限:** - -ohos.permission.GET_BUNDLE_INFO_PRIVILEGED,ohos.permission.GET_BUNDLE_INFO - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| ----------- | ------ | ---- | ------------------------------------------------------------ | -| bundleName | string | 是 | 要查询的应用程序包名称。 | -| bundleFlags | number | 是 | 用于指定返回的应用信息对象中包含信息的标记。默认值:0,取值范围:大于等于0 | -| userId | number | 是 | 用户ID | - -**返回值:** - -| 类型 | 说明 | -| ----------- | -------- | -| Promise\ | Promise形式返回应用程序信息。 | - -**示例:** - -```js -bundle.getApplicationInfo('com.example.myapplicationInstall', 8, 0).then((data) => { - console.info("name: for begin"); - console.info("name:" + data.name); - console.info("bundleName:" + data.bundleName); - console.info("description:" + data.description); - console.info("descriptionId:" + data.descriptionId); - console.info("iconPath:" + data.iconPath); - console.info("iconId:" + data.iconId); - console.info("label:" + data.label); - console.info("labelId:" + data.labelId); - console.info("deviceId:" + data.deviceId); - console.info("signatureKey:" + data.signatureKey); - console.info("process:" + data.process); - console.info("isSystemApp:" + data.isSystemApp); - console.info("isLauncherApp:" + data.isLauncherApp); - console.info("supportedModes:" + data.supportedModes); - - console.info('getApplicationInfo permissions length [' + data.permissions.length + ']'); - for (var j = 0; j < data.permissions.length; j++) { - console.info("permissions[" + j + "]:" + data.permissions[j]); - } - console.info('getApplicationInfo moduleSourceDirs length [' + data.moduleSourceDirs.length + ']'); - for (var j = 0; j < data.moduleSourceDirs.length; j++) { - console.info("moduleSourceDirs[" + j + "]:" + data.moduleSourceDirs[j]); - } - console.info('getApplicationInfo moduleInfos length [' + data.moduleInfos.length + ']'); - for (var j = 0; j < data.moduleInfos.length; j++) { - console.info("moduleInfos[" + j + "]moduleName:" + data.moduleInfos[j].moduleName); - console.info("moduleInfos[" + j + "]moduleSourceDir:" + data.moduleInfos[j].moduleSourceDir); - } - console.info("entryDir:" + data.entryDir); - console.info("codePath:" + data.codePath); - console.info("dataDir:" + data.dataDir); - console.info("dataBaseDir:" + data.dataBaseDir); - console.info("cacheDir:" + data.cacheDir); -}) -``` - - - -## bundle.getApplicationInfo - -getApplicationInfo(bundleName: string, bundleFlags: number, userId: number, callback: AsyncCallback\): void - -以异步方法根据给定的包名获取ApplicationInfo,使用callback形式返回结果。 - -**需要权限:** - -ohos.permission.GET_BUNDLE_INFO_PRIVILEGED,ohos.permission.GET_BUNDLE_INFO - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| ----------- | ------------------------------- | ---- | ------------------------------------------------------------ | -| bundleName | string | 是 | 要查询的应用程序包名称。 | -| bundleFlags | number | 是 | 用于指定返回的应用信息对象中包含信息的标记。默认值:0,取值范围:大于等于0 | -| userId | number | 是 | 用户ID | -| callback | AsyncCallback\ | 是 | 程序启动作为入参的回调函数,返回应用程序信息。 | - -**示例:** - -```js -bundle.getApplicationInfo('com.example.myapplicationInstall', 8, 0, OnReceiveEvent); - -function OnReceiveEvent(err, data) { - console.info("name: for begin"); - console.info("name:" + data.name); - console.info("bundleName:" + data.bundleName); - console.info("description:" + data.description); - console.info("descriptionId:" + data.descriptionId); - console.info("iconPath:" + data.iconPath); - console.info("iconId:" + data.iconId); - console.info("label:" + data.label); - console.info("labelId:" + data.labelId); - console.info("deviceId:" + data.deviceId); - console.info("signatureKey:" + data.signatureKey); - console.info("process:" + data.process); - console.info("isSystemApp:" + data.isSystemApp); - console.info("isLauncherApp:" + data.isLauncherApp); - console.info("supportedModes:" + data.supportedModes); - - console.info('getApplicationInfo permissions length [' + data.permissions.length + ']'); - for (var j = 0; j < data.permissions.length; j++) { - console.info("permissions[" + j + "]:" + data.permissions[j]); - } - console.info('getApplicationInfo moduleSourceDirs length [' + data.moduleSourceDirs.length + ']'); - for (var j = 0; j < data.moduleSourceDirs.length; j++) { - console.info("moduleSourceDirs[" + j + "]:" + data.moduleSourceDirs[j]); - } - console.info('getApplicationInfo moduleInfos length [' + data.moduleInfos.length + ']'); - for (var j = 0; j < data.moduleInfos.length; j++) { - console.info("moduleInfos[" + j + "]moduleName:" + data.moduleInfos[j].moduleName); - console.info("moduleInfos[" + j + "]moduleSourceDir:" + data.moduleInfos[j].moduleSourceDir); - } - console.info("entryDir:" + data.entryDir); - console.info("codePath:" + data.codePath); - console.info("dataDir:" + data.dataDir); - console.info("dataBaseDir:" + data.dataBaseDir); - console.info("cacheDir:" + data.cacheDir); -} -``` - - - -## bundle.getAllBundleInfo - -getAllBundleInfo(bundleFlag: BundleFlag): Promise> - -以异步方法获取系统中所有可用的BundleInfo,使用Promise形式返回结果。 - -**需要权限:** - -ohos.permission.GET_BUNDLE_INFO_PRIVILEGED - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| ---------- | ---------- | ---- | ----------------------------------------------------------- | -| bundleFlag | BundleFlag | 是 | 0:返回默认BundleInfo
1:返回包含abilityInfo的BundleInfo | - -**返回值:** - -| 类型 | 说明 | -| --------------------------- | ----------------------------------- | -| Promise> | Promise形式返回所有可用的BundleInfo | - -**示例:** - -```js -bundle.getAllBundleInfo(0).then((data) => { - for (var i = 0; i < data.length; i++) { - console.info("index[" + i + "].name: for begin"); - console.info("index[" + i + "].name:" + data[i].name); - console.info("index[" + i + "].label:" + data[i].label); - console.info("index[" + i + "].description:" + data[i].description); - console.info("index[" + i + "].vendor:" + data[i].vendor); - console.info("index[" + i + "].versionCode:" + data[i].versionCode); - console.info("index[" + i + "].versionName:" + data[i].versionName); - console.info("index[" + i + "].jointUserId:" + data[i].jointUserId); - console.info("index[" + i + "].minSdkVersion:" + data[i].minSdkVersion); - console.info("index[" + i + "].maxSdkVersion:" + data[i].maxSdkVersion); - console.info("index[" + i + "].mainEntry:" + data[i].mainEntry); - console.info("index[" + i + "].cpuAbi:" + data[i].cpuAbi); - console.info("index[" + i + "].appId:" + data[i].appId); - console.info("index[" + i + "].compatibleVersion:" + data[i].compatibleVersion); - console.info("index[" + i + "].targetVersion:" + data[i].targetVersion); - console.info("index[" + i + "].releaseType:" + data[i].releaseType); - console.info("index[" + i + "].uid:" + data[i].uid); - console.info("index[" + i + "].gid:" + data[i].gid); - console.info("index[" + i + "].seInfo:" + data[i].seInfo); - console.info("index[" + i + "].entryModuleName:" + data[i].entryModuleName); - console.info("index[" + i + "].isKeepAlive:" + data[i].isKeepAlive); - console.info("index[" + i + "].isNativeApp:" + data[i].isNativeApp); - console.info("index[" + i + "].installTime:" + data[i].installTime); - console.info("index[" + i + "].updateTime:" + data[i].updateTime); - console.info("index[" + i + "].appInfo.name:" + data[i].applicationInfo.name); - console.info("index[" + i + "].appInfo.bundleName:" + data[i].applicationInfo.bundleName); - console.info('getAllBundleInfo reqPermissions length [' + data[i].reqPermissions.length + ']'); - for (var j = 0; j < data[i].reqPermissions.length; j++) { - console.info("index[" + i + "]reqPermissions[" + j + "]:" + data[i].reqPermissions[j]); - } - console.info('getAllBundleInfo defPermissions length [' + data[i].defPermissions.length + ']'); - for (var j = 0; j < data[i].defPermissions.length; j++) { - console.info("index[" + i + "]defPermissions[" + j + "]:" + data[i].defPermissions[j]); - } - - console.info('getAllBundleInfo hapModuleNames length [' + data[i].hapModuleNames.length + ']'); - for (var j = 0; j < data[i].hapModuleNames.length; j++) { - console.info("index[" + i + "]hapModuleNames[" + j + "]:" + data[i].hapModuleNames[j]); - } - console.info('getAllBundleInfo moduleNames length [' + data[i].moduleNames.length + ']'); - for (var j = 0; j < data[i].moduleNames.length; j++) { - console.info("index[" + i + "]moduleNames[" + j + "]:" + data[i].moduleNames[j]); - } - console.info('getAllBundleInfo modulePublicDirs length [' + data[i].modulePublicDirs.length + ']'); - for (var j = 0; j < data[i].modulePublicDirs.length; j++) { - console.info("index[" + i + "]modulePublicDirs[" + j + "]:" + data[i].modulePublicDirs[j]); - } - console.info('getAllBundleInfo moduleDirs length [' + data[i].moduleDirs.length + ']'); - for (var j = 0; j < data[i].moduleDirs.length; j++) { - console.info("index[" + i + "]moduleDirs[" + j + "]:" + data[i].moduleDirs[j]); - } - console.info('getAllBundleInfo moduleResPaths length [' + data[i].moduleResPaths.length + ']'); - for (var j = 0; j < data[i].moduleResPaths.length; j++) { - console.info("index[" + i + "]moduleResPaths[" + j + "]:" + data[i].moduleResPaths[j]); - } - console.info('getAllBundleInfo abilityInfo length [' + data[i].abilityInfos.length + ']'); - for (var j = 0; j < data[i].abilityInfos.length; j++) { - console.info("index[" + i + "]abilityInfos[" + j + "]name:" + data[i].abilityInfos[j].name); - console.info("index[" + i + "]abilityInfos[" + j + "]package:" + data[i].abilityInfos[j].package); - } - } -}) -``` - - - -## bundle.getAllBundleInfo - -getAllBundleInfo(bundleFlag: BundleFlag, callback: AsyncCallback>): void - -以异步方法获取系统中所有可用的BundleInfo,使用callback形式返回结果。 - -**需要权限:** - -ohos.permission.GET_BUNDLE_INFO_PRIVILEGED - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| ---------- | --------------------------------- | ---- | ------------------------------------------------------------ | -| bundleFlag | BundleFlag | 是 | 0:返回默认BundleInfo
1:返回包含abilityInfo的BundleInfo | -| callback | AsyncCallback> | 是 | 程序启动作为入参的回调函数,返回所有可用的BundleInfo。 | - -**示例:** - -```js -bundle.getAllBundleInfo(0, OnReceiveEvent); - -function OnReceiveEvent(err, data) { - console.info('xxx getAllBundleInfo data length [' + data.length + ']'); - for (var i = 0; i < data.length; i++) { - console.info("index[" + i + "].name: for begin"); - console.info("index[" + i + "].name:" + data[i].name); - console.info("index[" + i + "].label:" + data[i].label); - console.info("index[" + i + "].description:" + data[i].description); - console.info("index[" + i + "].vendor:" + data[i].vendor); - console.info("index[" + i + "].versionCode:" + data[i].versionCode); - console.info("index[" + i + "].versionName:" + data[i].versionName); - console.info("index[" + i + "].jointUserId:" + data[i].jointUserId); - console.info("index[" + i + "].minSdkVersion:" + data[i].minSdkVersion); - console.info("index[" + i + "].maxSdkVersion:" + data[i].maxSdkVersion); - console.info("index[" + i + "].mainEntry:" + data[i].mainEntry); - console.info("index[" + i + "].cpuAbi:" + data[i].cpuAbi); - console.info("index[" + i + "].appId:" + data[i].appId); - console.info("index[" + i + "].compatibleVersion:" + data[i].compatibleVersion); - console.info("index[" + i + "].targetVersion:" + data[i].targetVersion); - console.info("index[" + i + "].releaseType:" + data[i].releaseType); - console.info("index[" + i + "].uid:" + data[i].uid); - console.info("index[" + i + "].gid:" + data[i].gid); - console.info("index[" + i + "].seInfo:" + data[i].seInfo); - console.info("index[" + i + "].entryModuleName:" + data[i].entryModuleName); - console.info("index[" + i + "].isKeepAlive:" + data[i].isKeepAlive); - console.info("index[" + i + "].isNativeApp:" + data[i].isNativeApp); - console.info("index[" + i + "].installTime:" + data[i].installTime); - console.info("index[" + i + "].updateTime:" + data[i].updateTime); - console.info("index[" + i + "].appInfo.name:" + data[i].applicationInfo.name); - console.info("index[" + i + "].appInfo.bundleName:" + data[i].applicationInfo.bundleName); - console.info('getAllBundleInfo reqPermissions length [' + data[i].reqPermissions.length + ']'); - for (var j = 0; j < data[i].reqPermissions.length; j++) { - console.info("index[" + i + "]reqPermissions[" + j + "]:" + data[i].reqPermissions[j]); - } - console.info('getAllBundleInfo defPermissions length [' + data[i].defPermissions.length + ']'); - for (var j = 0; j < data[i].defPermissions.length; j++) { - console.info("index[" + i + "]defPermissions[" + j + "]:" + data[i].defPermissions[j]); - } - - console.info('getAllBundleInfo hapModuleNames length [' + data[i].hapModuleNames.length + ']'); - for (var j = 0; j < data[i].hapModuleNames.length; j++) { - console.info("index[" + i + "]hapModuleNames[" + j + "]:" + data[i].hapModuleNames[j]); - } - console.info('getAllBundleInfo moduleNames length [' + data[i].moduleNames.length + ']'); - for (var j = 0; j < data[i].moduleNames.length; j++) { - console.info("index[" + i + "]moduleNames[" + j + "]:" + data[i].moduleNames[j]); - } - console.info('getAllBundleInfo modulePublicDirs length [' + data[i].modulePublicDirs.length + ']'); - for (var j = 0; j < data[i].modulePublicDirs.length; j++) { - console.info("index[" + i + "]modulePublicDirs[" + j + "]:" + data[i].modulePublicDirs[j]); - } - console.info('getAllBundleInfo moduleDirs length [' + data[i].moduleDirs.length + ']'); - for (var j = 0; j < data[i].moduleDirs.length; j++) { - console.info("index[" + i + "]moduleDirs[" + j + "]:" + data[i].moduleDirs[j]); - } - console.info('getAllBundleInfo moduleResPaths length [' + data[i].moduleResPaths.length + ']'); - for (var j = 0; j < data[i].moduleResPaths.length; j++) { - console.info("index[" + i + "]moduleResPaths[" + j + "]:" + data[i].moduleResPaths[j]); - } - console.info('getAllBundleInfo abilityInfo length [' + data[i].abilityInfos.length + ']'); - for (var j = 0; j < data[i].abilityInfos.length; j++) { - console.info("index[" + i + "]abilityInfos[" + j + "]name:" + data[i].abilityInfos[j].name); - console.info("index[" + i + "]abilityInfos[" + j + "]package:" + data[i].abilityInfos[j].package); - } - } -} -``` - - - -## bundle.getBundleInfo - -getBundleInfo(bundleName: string, bundleFlags: number): Promise\ - -以异步方法根据给定的包名获取BundleInfo,使用Promise形式返回结果。 - -**需要权限:** - -ohos.permission.GET_BUNDLE_INFO_PRIVILEGED,ohos.permission.GET_BUNDLE_INFO - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| ----------- | ------ | ---- | ------------------------------------------------------------ | -| bundleName | string | 是 | 包名 | -| bundleFlags | number | 是 | 0:返回默认BundleInfo
1:返回包含abilityInfo的BundleInfo | - -**返回值:** - -| 类型 | 说明 | -| -------------------- | ------------------------------------------ | -| Promise\ | 返回值为Promise对象,Promise中包含包信息。 | - -**示例:** - -```js -bundle.getBundleInfo('com.example.myapplicationInstall', 1).then((data) => { - console.info("name:" + data.name); - console.info("label:" + data.label); - console.info("description:" + data.description); - console.info("vendor:" + data.vendor); - console.info("versionCode:" + data.versionCode); - console.info("versionName:" + data.versionName); - console.info("jointUserId:" + data.jointUserId); - console.info("minSdkVersion:" + data.minSdkVersion); - console.info("maxSdkVersion:" + data.maxSdkVersion); - console.info("mainEntry:" + data.mainEntry); - console.info("cpuAbi:" + data.cpuAbi); - console.info("appId:" + data.appId); - console.info("compatibleVersion:" + data.compatibleVersion); - console.info("targetVersion:" + data.targetVersion); - console.info("releaseType:" + data.releaseType); - console.info("uid:" + data.uid); - console.info("gid:" + data.gid); - console.info("seInfo:" + data.seInfo); - console.info("entryModuleName:" + data.entryModuleName); - console.info("isKeepAlive:" + data.isKeepAlive); - console.info("isNativeApp:" + data.isNativeApp); - console.info("installTime:" + data.installTime); - console.info("updateTime:" + data.updateTime); - console.info("appInfo.name:" + data.applicationInfo.name); - console.info("appInfo.bundleName:" + data.applicationInfo.bundleName); - console.info('getBundleInfo reqPermissions length [' + data.reqPermissions.length + ']'); - for (var j = 0; j < data.reqPermissions.length; j++) { - console.info("reqPermissions[" + j + "]:" + data.reqPermissions[j]); - } - console.info('getBundleInfo defPermissions length [' + data.defPermissions.length + ']'); - for (var j = 0; j < data.defPermissions.length; j++) { - console.info("defPermissions[" + j + "]:" + data.defPermissions[j]); - } - - console.info('getBundleInfo hapModuleNames length [' + data.hapModuleNames.length + ']'); - for (var j = 0; j < data.hapModuleNames.length; j++) { - console.info("hapModuleNames[" + j + "]:" + data.hapModuleNames[j]); - } - console.info('getBundleInfo moduleNames length [' + data.moduleNames.length + ']'); - for (var j = 0; j < data.moduleNames.length; j++) { - console.info("moduleNames[" + j + "]:" + data.moduleNames[j]); - } - console.info('getBundleInfo modulePublicDirs length [' + data.modulePublicDirs.length + ']'); - for (var j = 0; j < data.modulePublicDirs.length; j++) { - console.info("modulePublicDirs[" + j + "]:" + data.modulePublicDirs[j]); - } - console.info('getBundleInfo moduleDirs length [' + data.moduleDirs.length + ']'); - for (var j = 0; j < data.moduleDirs.length; j++) { - console.info("moduleDirs[" + j + "]:" + data.moduleDirs[j]); - } - console.info('getBundleInfo moduleResPaths length [' + data.moduleResPaths.length + ']'); - for (var j = 0; j < data.moduleResPaths.length; j++) { - console.info("moduleResPaths[" + j + "]:" + data.moduleResPaths[j]); - } - console.info('getBundleInfo abilityInfo length [' + data.abilityInfos.length + ']'); - for (var j = 0; j < data.abilityInfos.length; j++) { - console.info("abilityInfos[" + j + "]name:" + data.abilityInfos[j].name); - console.info("abilityInfos[" + j + "]package:" + data.abilityInfos[j].package); - } -}) -``` - - - -## bundle.getBundleInfo - -getBundleInfo(bundleName: string, bundleFlags: number, callback: AsyncCallback\): void - -以异步方法根据给定的包名获取BundleInfo,使用callback形式返回结果。 - -**需要权限:** - -ohos.permission.GET_BUNDLE_INFO_PRIVILEGED,ohos.permission.GET_BUNDLE_INFO - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| ----------- | -------------------------- | ---- | ------------------------------------------------------------ | -| bundleName | string | 是 | 包名 | -| bundleFlags | number | 是 | 0:返回默认BundleInfo
1:返回包含abilityInfo的BundleInfo | -| callback | AsyncCallback\ | 是 | 程序启动作为入参的回调函数,返回包信息。 | - -**示例:** - -```js -bundle.getBundleInfo('com.example.myapplicationInstall', 1, OnReceiveEvent); - -function OnReceiveEvent(err, data) { - console.info("name:" + data.name); - console.info("label:" + data.label); - console.info("description:" + data.description); - console.info("vendor:" + data.vendor); - console.info("versionCode:" + data.versionCode); - console.info("versionName:" + data.versionName); - console.info("jointUserId:" + data.jointUserId); - console.info("minSdkVersion:" + data.minSdkVersion); - console.info("maxSdkVersion:" + data.maxSdkVersion); - console.info("mainEntry:" + data.mainEntry); - console.info("cpuAbi:" + data.cpuAbi); - console.info("appId:" + data.appId); - console.info("compatibleVersion:" + data.compatibleVersion); - console.info("targetVersion:" + data.targetVersion); - console.info("releaseType:" + data.releaseType); - console.info("uid:" + data.uid); - console.info("gid:" + data.gid); - console.info("seInfo:" + data.seInfo); - console.info("entryModuleName:" + data.entryModuleName); - console.info("isKeepAlive:" + data.isKeepAlive); - console.info("isNativeApp:" + data.isNativeApp); - console.info("installTime:" + data.installTime); - console.info("updateTime:" + data.updateTime); - console.info("appInfo.name:" + data.applicationInfo.name); - console.info("appInfo.bundleName:" + data.applicationInfo.bundleName); - console.info('getBundleInfo reqPermissions length [' + data.reqPermissions.length + ']'); - for (var j = 0; j < data.reqPermissions.length; j++) { - console.info("reqPermissions[" + j + "]:" + data.reqPermissions[j]); - } - console.info('getBundleInfo defPermissions length [' + data.defPermissions.length + ']'); - for (var j = 0; j < data.defPermissions.length; j++) { - console.info("defPermissions[" + j + "]:" + data.defPermissions[j]); - } - - console.info('getBundleInfo hapModuleNames length [' + data.hapModuleNames.length + ']'); - for (var j = 0; j < data.hapModuleNames.length; j++) { - console.info("hapModuleNames[" + j + "]:" + data.hapModuleNames[j]); - } - console.info('getBundleInfo moduleNames length [' + data.moduleNames.length + ']'); - for (var j = 0; j < data.moduleNames.length; j++) { - console.info("moduleNames[" + j + "]:" + data.moduleNames[j]); - } - console.info('getBundleInfo modulePublicDirs length [' + data.modulePublicDirs.length + ']'); - for (var j = 0; j < data.modulePublicDirs.length; j++) { - console.info("modulePublicDirs[" + j + "]:" + data.modulePublicDirs[j]); - } - console.info('getBundleInfo moduleDirs length [' + data.moduleDirs.length + ']'); - for (var j = 0; j < data.moduleDirs.length; j++) { - console.info("moduleDirs[" + j + "]:" + data.moduleDirs[j]); - } - console.info('getBundleInfo moduleResPaths length [' + data.moduleResPaths.length + ']'); - for (var j = 0; j < data.moduleResPaths.length; j++) { - console.info("moduleResPaths[" + j + "]:" + data.moduleResPaths[j]); - } - console.info('getBundleInfo abilityInfo length [' + data.abilityInfos.length + ']'); - for (var j = 0; j < data.abilityInfos.length; j++) { - console.info("abilityInfos[" + j + "]name:" + data.abilityInfos[j].name); - console.info("abilityInfos[" + j + "]package:" + data.abilityInfos[j].package); - } -} -``` - - - -## bundle.getAllApplicationInfo - -getAllApplicationInfo(bundleFlags: number, userId: number): Promise> - -获取指定用户下所有已安装的应用信息,通过Promise获取返回值。 - -**需要权限:** - -ohos.permission.GET_BUNDLE_INFO_PRIVILEGED,ohos.permission.GET_BUNDLE_INFO - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| ----------- | ------ | ---- | ------------------------------------------------------ | -| bundleFlags | number | 是 | 0:返回默认应用信息<
8:返回包含权限信息的应用信息 | -| userId | number | 是 | 用户ID | - -**返回值:** - -| 类型 | 说明 | -| -------------------------------- | ------------------------------------------------ | -| Promise> | 返回值为Promise对象,Promise中包含应用信息列表。 | - -**示例:** - -```js -bundle.getAllApplicationInfo(8, 0).then((data) => { - console.info('xxx getAllApplicationInfo data length [' + data.length + ']'); - for (var i = 0; i < data.length; i++) { - console.info("index[" + i + "].name: for begin"); - console.info("index[" + i + "].name:" + data[i].name); - console.info("index[" + i + "].bundleName:" + data[i].bundleName); - console.info("index[" + i + "].description:" + data[i].description); - console.info("index[" + i + "].descriptionId:" + data[i].descriptionId); - console.info("index[" + i + "].iconPath:" + data[i].iconPath); - console.info("index[" + i + "].iconId:" + data[i].iconId); - console.info("index[" + i + "].label:" + data[i].label); - console.info("index[" + i + "].labelId:" + data[i].labelId); - console.info("index[" + i + "].deviceId:" + data[i].deviceId); - console.info("index[" + i + "].signatureKey:" + data[i].signatureKey); - console.info("index[" + i + "].process:" + data[i].process); - console.info("index[" + i + "].isSystemApp:" + data[i].isSystemApp); - console.info("index[" + i + "].isLauncherApp:" + data[i].isLauncherApp); - console.info("index[" + i + "].supportedModes:" + data[i].supportedModes); - - console.info('getAllApplicationInfo Async permissions length [' + data[i].permissions.length + ']'); - for (var j = 0; j < data[i].permissions.length; j++) { - console.info("index[" + i + "]permissions[" + j + "]:" + data[i].permissions[j]); - } - console.info('getAllApplicationInfo Async moduleSourceDirs length [' + data[i].moduleSourceDirs.length + ']'); - for (var j = 0; j < data[i].moduleSourceDirs.length; j++) { - console.info("index[" + i + "]moduleSourceDirs[" + j + "]:" + data[i].moduleSourceDirs[j]); - } - console.info('getAllApplicationInfo Async moduleInfos length [' + data[i].moduleInfos.length + ']'); - for (var j = 0; j < data[i].moduleInfos.length; j++) { - console.info("index[" + i + "]moduleInfos[" + j + "]moduleName:" + data[i].moduleInfos[j].moduleName); - console.info("index[" + i + "]moduleInfos[" + j + "]moduleSourceDir:" + data[i].moduleInfos[j].moduleSourceDir); - } - console.info("index[" + i + "].entryDir:" + data[i].entryDir); - console.info("index[" + i + "].codePath:" + data[i].codePath); - console.info("index[" + i + "].dataDir:" + data[i].dataDir); - console.info("index[" + i + "].dataBaseDir:" + data[i].dataBaseDir); - console.info("index[" + i + "].cacheDir:" + data[i].cacheDir); - } -}) -``` - - - -## bundle.getAllApplicationInfo - -getAllApplicationInfo(bundleFlags: number, userId: number, callback: AsyncCallback>): void - -获取指定用户下所有已安装的应用信息,通过回调函数获取返回值。 - -**需要权限:** - -ohos.permission.GET_BUNDLE_INFO_PRIVILEGED,ohos.permission.GET_BUNDLE_INFO - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| ----------- | -------------------------------------- | ---- | ------------------------------------------------------ | -| bundleFlags | number | 是 | 0:返回默认应用信息<
8:返回包含权限信息的应用信息 | -| userId | number | 是 | 用户ID | -| callback | AsyncCallback> | 是 | 程序启动作为入参的回调函数,返回应用信息列表。 | - -**示例:** - -```js -bundle.getAllApplicationInfo(8, 0, OnReceiveEvent); - -function OnReceiveEvent(err, data) { - console.info('xxx getAllApplicationInfo data length [' + data.length + ']'); - for (var i = 0; i < data.length; i++) { - console.info("index[" + i + "].name: for begin"); - console.info("index[" + i + "].name:" + data[i].name); - console.info("index[" + i + "].bundleName:" + data[i].bundleName); - console.info("index[" + i + "].description:" + data[i].description); - console.info("index[" + i + "].descriptionId:" + data[i].descriptionId); - console.info("index[" + i + "].iconPath:" + data[i].iconPath); - console.info("index[" + i + "].iconId:" + data[i].iconId); - console.info("index[" + i + "].label:" + data[i].label); - console.info("index[" + i + "].labelId:" + data[i].labelId); - console.info("index[" + i + "].deviceId:" + data[i].deviceId); - console.info("index[" + i + "].signatureKey:" + data[i].signatureKey); - console.info("index[" + i + "].process:" + data[i].process); - console.info("index[" + i + "].isSystemApp:" + data[i].isSystemApp); - console.info("index[" + i + "].isLauncherApp:" + data[i].isLauncherApp); - console.info("index[" + i + "].supportedModes:" + data[i].supportedModes); - - console.info('getAllApplicationInfo Async permissions length [' + data[i].permissions.length + ']'); - for (var j = 0; j < data[i].permissions.length; j++) { - console.info("index[" + i + "]permissions[" + j + "]:" + data[i].permissions[j]); - } - console.info('getAllApplicationInfo Async moduleSourceDirs length [' + data[i].moduleSourceDirs.length + ']'); - for (var j = 0; j < data[i].moduleSourceDirs.length; j++) { - console.info("index[" + i + "]moduleSourceDirs[" + j + "]:" + data[i].moduleSourceDirs[j]); - } - console.info('getAllApplicationInfo Async moduleInfos length [' + data[i].moduleInfos.length + ']'); - for (var j = 0; j < data[i].moduleInfos.length; j++) { - console.info("index[" + i + "]moduleInfos[" + j + "]moduleName:" + data[i].moduleInfos[j].moduleName); - console.info("index[" + i + "]moduleInfos[" + j + "]moduleSourceDir:" + data[i].moduleInfos[j].moduleSourceDir); - } - console.info("index[" + i + "].entryDir:" + data[i].entryDir); - console.info("index[" + i + "].codePath:" + data[i].codePath); - console.info("index[" + i + "].dataDir:" + data[i].dataDir); - console.info("index[" + i + "].dataBaseDir:" + data[i].dataBaseDir); - console.info("index[" + i + "].cacheDir:" + data[i].cacheDir); - } -} -``` - - - -## bundle.queryAbilityByWant - -queryAbilityByWant(want: Want, bundleFlags: number, userId?: number): Promise> - -以异步方法根据给定的意图获取Ability信息,使用Promise形式返回结果。 - -**需要权限:** - -ohos.permission.GET_BUNDLE_INFO_PRIVILEGED,ohos.permission.GET_BUNDLE_INFO - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| ----------- | ------ | ---- | ------------------------------------------------------------ | -| want | Want | 是 | 包含要查询的应用程序包名称的意图。 | -| bundleFlags | number | 是 | 0:返回默认AbilityInfo
2:返回包含权限信息的AbilityInfo
4:返回包含应用信息的AbilityInfo | -| userId | number | 否 | 用户ID。默认值:调用方所在用户,取值范围:大于等于0 | - -**返回值:** - -| 类型 | 说明 | -| ---------------------------- | ---------------------------- | -| Promise> | Promise形式返回Ability信息。 | - -**示例:** - -```js -bundle.queryAbilityByWant({ - want: { - action: "action.system.home", - entities: ["entity.system.home"], - elementName: { - deviceId: "0", - bundleName: "com.example.myapplicationInstall", - abilityName: "com.example.myapplication.MainAbility", - }, - } -}, 1, 0, -}).then((data) => { - console.info("name:" + data.name); - console.info("label:" + data.label); - console.info("description:" + data.description); - console.info("iconPath:" + data.iconPath); - console.info("visible:" + data.visible); - console.info("kind:" + data.kind); - console.info("uri:" + data.uri); - console.info("process:" + data.process); - console.info("package:" + data.package); - console.info("bundleName:" + data.bundleName); - console.info("moduleName:" + data.moduleName); - console.info("applicationName:" + data.applicationName); - console.info("deviceId:" + data.deviceId); - console.info("codePath:" + data.codePath); - console.info("resourcePath:" + data.resourcePath); - console.info("libPath:" + data.libPath); - - console.info('queryAbilityInfo permissions length [' + data.permissions.length + ']'); - for (var j = 0; j < data.permissions.length; j++) { - console.info("permissions[" + j + "]:" + data.permissions[j]); - } - console.info('queryAbilityInfo deviceTypes length [' + data.deviceTypes.length + ']'); - for (var j = 0; j < data.deviceTypes.length; j++) { - console.info("deviceTypes[" + j + "]:" + data.deviceTypes[j]); - } - console.info('queryAbilityInfo deviceCapabilities length [' + data.deviceCapabilities.length + ']'); - for (var j = 0; j < data.deviceCapabilities.length; j++) { - console.info("deviceCapabilities[" + j + "]:" + data.deviceCapabilities[j]); - } - console.info("appInfo.name:" + data.applicationInfo.name); - console.info("appInfo.bundleName:" + data.applicationInfo.bundleName); - // ability type: 0:UNKNOWN, 1:PAGE, 2:SERVICE, 3:DATA - console.info("type:" + data.type); - // orientation: 0:UNSPECIFIED, 1:LANDSCAPE, 2:PORTRAIT, 3:FOLLOWRECENT, - console.info("orientation:" + data.orientation); - // launchMode: 0:SINGLETON, 1:SINGLETOP, 2:STANDARD - console.info("launchMode:" + data.launchMode); - - // the enum of AbilityType - console.info("AbilityType:" + bundle.AbilityType.UNKNOWN); - console.info("AbilityType:" + bundle.AbilityType.PAGE); - console.info("AbilityType:" + bundle.AbilityType.SERVICE); - console.info("AbilityType:" + bundle.AbilityType.DATA); - if (data.type == bundle.AbilityType.PAGE) { - console.info("this AbilityType is PAGE"); - } - // the enum of DisplayOrientation - console.info("DisplayOrientation:" + bundle.DisplayOrientation.UNSPECIFIED); - console.info("DisplayOrientation:" + bundle.DisplayOrientation.LANDSCAPE); - console.info("DisplayOrientation:" + bundle.DisplayOrientation.PORTRAIT); - console.info("DisplayOrientation:" + bundle.DisplayOrientation.FOLLOWRECENT); - if (data.orientation == bundle.DisplayOrientation.UNSPECIFIED) { - console.info("this DisplayOrientation is UNSPECIFIED"); - } - // the enum of LaunchMode - console.info("LaunchMode:" + bundle.LaunchMode.SINGLETON); - console.info("LaunchMode:" + bundle.LaunchMode.SINGLETOP); - console.info("LaunchMode:" + bundle.LaunchMode.STANDARD); - if (data.launchMode == bundle.LaunchMode.STANDARD) { - console.info("this LaunchMode is STANDARD"); - } - -}) -``` - - - -## bundle.queryAbilityByWant - -queryAbilityByWant(want: Want, bundleFlags: number, userId: number, callback: AsyncCallback>): void - -以异步方法根据给定的意图获取Ability信息,使用callback形式返回结果。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| ----------- | ---------------------------------- | ---- | ------------------------------------------------------------ | -| want | Want | 是 | 指示包含要查询的应用程序包名称的意图。 | -| bundleFlags | number | 是 | 0:返回默认AbilityInfo
2:返回包含权限信息的AbilityInfo
4:返回包含应用信息的AbilityInfo | -| userId | number | 是 | 用户ID | -| callback | AsyncCallback> | 是 | 程序启动作为入参的回调函数,返回Ability信息。 | - -**示例:** - -```js -bundle.queryAbilityByWant( - { - want: { - action: "action.system.home", - entities: ["entity.system.home"], - elementName: { - deviceId: "0", - bundleName: "com.example.myapplicationInstall", - abilityName: "com.example.myapplication.MainAbility", - }, - } - }, 1, 0, - }, OnReceiveEvent); - -function OnReceiveEvent(err, data) { - console.info("name:" + data.name); - console.info("label:" + data.label); - console.info("description:" + data.description); - console.info("iconPath:" + data.iconPath); - console.info("visible:" + data.visible); - console.info("kind:" + data.kind); - console.info("uri:" + data.uri); - console.info("process:" + data.process); - console.info("package:" + data.package); - console.info("bundleName:" + data.bundleName); - console.info("moduleName:" + data.moduleName); - console.info("applicationName:" + data.applicationName); - console.info("deviceId:" + data.deviceId); - console.info("codePath:" + data.codePath); - console.info("resourcePath:" + data.resourcePath); - console.info("libPath:" + data.libPath); - - console.info('queryAbilityInfo permissions length [' + data.permissions.length + ']'); - for (var j = 0; j < data.permissions.length; j++) { - console.info("permissions[" + j + "]:" + data.permissions[j]); - } - console.info('queryAbilityInfo deviceTypes length [' + data.deviceTypes.length + ']'); - for (var j = 0; j < data.deviceTypes.length; j++) { - console.info("deviceTypes[" + j + "]:" + data.deviceTypes[j]); - } - console.info('queryAbilityInfo deviceCapabilities length [' + data.deviceCapabilities.length + ']'); - for (var j = 0; j < data.deviceCapabilities.length; j++) { - console.info("deviceCapabilities[" + j + "]:" + data.deviceCapabilities[j]); - } - console.info("appInfo.name:" + data.applicationInfo.name); - console.info("appInfo.bundleName:" + data.applicationInfo.bundleName); - // ability type: 0:UNKNOWN, 1:PAGE, 2:SERVICE, 3:DATA - console.info("type:" + data.type); - // orientation: 0:UNSPECIFIED, 1:LANDSCAPE, 2:PORTRAIT, 3:FOLLOWRECENT, - console.info("orientation:" + data.orientation); - // launchMode: 0:SINGLETON, 1:SINGLETOP, 2:STANDARD - console.info("launchMode:" + data.launchMode); - - // the enum of AbilityType - console.info("AbilityType:" + bundle.AbilityType.UNKNOWN); - console.info("AbilityType:" + bundle.AbilityType.PAGE); - console.info("AbilityType:" + bundle.AbilityType.SERVICE); - console.info("AbilityType:" + bundle.AbilityType.DATA); - if (data.type == bundle.AbilityType.PAGE) { - console.info("this AbilityType is PAGE"); - } - // the enum of DisplayOrientation - console.info("DisplayOrientation:" + bundle.DisplayOrientation.UNSPECIFIED); - console.info("DisplayOrientation:" + bundle.DisplayOrientation.LANDSCAPE); - console.info("DisplayOrientation:" + bundle.DisplayOrientation.PORTRAIT); - console.info("DisplayOrientation:" + bundle.DisplayOrientation.FOLLOWRECENT); - if (data.orientation == bundle.DisplayOrientation.UNSPECIFIED) { - console.info("this DisplayOrientation is UNSPECIFIED"); - } - // the enum of LaunchMode - console.info("LaunchMode:" + bundle.LaunchMode.SINGLETON); - console.info("LaunchMode:" + bundle.LaunchMode.SINGLETOP); - console.info("LaunchMode:" + bundle.LaunchMode.STANDARD); - if (data.launchMode == bundle.LaunchMode.STANDARD) { - console.info("this LaunchMode is STANDARD"); - } -} -``` - -## bundle.queryAbilityByWant - -queryAbilityByWant(want: Want, bundleFlags: number, callback: AsyncCallback>): void - -以异步方法根据给定的意图获取Ability信息,使用callback形式返回结果。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| ----------- | ---------------------------------- | ---- | ------------------------------------------------------------ | -| want | Want | 是 | 指示包含要查询的应用程序包名称的意图。 | -| bundleFlags | number | 是 | 0:返回默认AbilityInfo
2:返回包含权限信息的AbilityInfo
4:返回包含应用信息的AbilityInfo | -| callback | AsyncCallback> | 是 | 程序启动作为入参的回调函数,返回Ability信息。 | - -**示例:** - -```js -bundle.queryAbilityByWant( - { - want: { - action: "action.system.home", - entities: ["entity.system.home"], - elementName: { - deviceId: "0", - bundleName: "com.example.myapplicationInstall", - abilityName: "com.example.myapplication.MainAbility", - }, - } - }, 1, - }, OnReceiveEvent); - -function OnReceiveEvent(err, data) { - console.info("name:" + data.name); - console.info("label:" + data.label); - console.info("description:" + data.description); - console.info("iconPath:" + data.iconPath); - console.info("visible:" + data.visible); - console.info("kind:" + data.kind); - console.info("uri:" + data.uri); - console.info("process:" + data.process); - console.info("package:" + data.package); - console.info("bundleName:" + data.bundleName); - console.info("moduleName:" + data.moduleName); - console.info("applicationName:" + data.applicationName); - console.info("deviceId:" + data.deviceId); - console.info("codePath:" + data.codePath); - console.info("resourcePath:" + data.resourcePath); - console.info("libPath:" + data.libPath); - - console.info('queryAbilityInfo permissions length [' + data.permissions.length + ']'); - for (var j = 0; j < data.permissions.length; j++) { - console.info("permissions[" + j + "]:" + data.permissions[j]); - } - console.info('queryAbilityInfo deviceTypes length [' + data.deviceTypes.length + ']'); - for (var j = 0; j < data.deviceTypes.length; j++) { - console.info("deviceTypes[" + j + "]:" + data.deviceTypes[j]); - } - console.info('queryAbilityInfo deviceCapabilities length [' + data.deviceCapabilities.length + ']'); - for (var j = 0; j < data.deviceCapabilities.length; j++) { - console.info("deviceCapabilities[" + j + "]:" + data.deviceCapabilities[j]); - } - console.info("appInfo.name:" + data.applicationInfo.name); - console.info("appInfo.bundleName:" + data.applicationInfo.bundleName); - // ability type: 0:UNKNOWN, 1:PAGE, 2:SERVICE, 3:DATA - console.info("type:" + data.type); - // orientation: 0:UNSPECIFIED, 1:LANDSCAPE, 2:PORTRAIT, 3:FOLLOWRECENT, - console.info("orientation:" + data.orientation); - // launchMode: 0:SINGLETON, 1:SINGLETOP, 2:STANDARD - console.info("launchMode:" + data.launchMode); - - // the enum of AbilityType - console.info("AbilityType:" + bundle.AbilityType.UNKNOWN); - console.info("AbilityType:" + bundle.AbilityType.PAGE); - console.info("AbilityType:" + bundle.AbilityType.SERVICE); - console.info("AbilityType:" + bundle.AbilityType.DATA); - if (data.type == bundle.AbilityType.PAGE) { - console.info("this AbilityType is PAGE"); - } - // the enum of DisplayOrientation - console.info("DisplayOrientation:" + bundle.DisplayOrientation.UNSPECIFIED); - console.info("DisplayOrientation:" + bundle.DisplayOrientation.LANDSCAPE); - console.info("DisplayOrientation:" + bundle.DisplayOrientation.PORTRAIT); - console.info("DisplayOrientation:" + bundle.DisplayOrientation.FOLLOWRECENT); - if (data.orientation == bundle.DisplayOrientation.UNSPECIFIED) { - console.info("this DisplayOrientation is UNSPECIFIED"); - } - // the enum of LaunchMode - console.info("LaunchMode:" + bundle.LaunchMode.SINGLETON); - console.info("LaunchMode:" + bundle.LaunchMode.SINGLETOP); - console.info("LaunchMode:" + bundle.LaunchMode.STANDARD); - if (data.launchMode == bundle.LaunchMode.STANDARD) { - console.info("this LaunchMode is STANDARD"); - } -} -``` - -## bundle.getBundleArchiveInfo - -getBundleArchiveInfo(hapFilePath: string, bundleFlags: number): Promise\ - -以异步方法从给定的HAP中获取BundleInfo,使用Promise形式返回结果。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| ----------- | ------ | ---- | ------------------------------------------------------------ | -| hapFilePath | string | 是 | HAP文件路径 | -| bundleFlags | number | 是 | 0:返回默认BundleInfo
1:返回包含abilityInfo的BundleInfo | - -**返回值:** - -| 类型 | 说明 | -| -------------------- | ------------------------------------------ | -| Promise\ | 返回值为Promise对象,Promise中包含包信息。 | - -**示例:** - -```js -bundle.getBundleArchiveInfo('/data/test.hap', 1).then((data) => { - console.info("name:" + data.name); - console.info("label:" + data.label); - console.info("description:" + data.description); - console.info("vendor:" + data.vendor); - console.info("versionCode:" + data.versionCode); - console.info("versionName:" + data.versionName); - console.info("jointUserId:" + data.jointUserId); - console.info("minSdkVersion:" + data.minSdkVersion); - console.info("maxSdkVersion:" + data.maxSdkVersion); - console.info("mainEntry:" + data.mainEntry); - console.info("cpuAbi:" + data.cpuAbi); - console.info("appId:" + data.appId); - console.info("compatibleVersion:" + data.compatibleVersion); - console.info("targetVersion:" + data.targetVersion); - console.info("releaseType:" + data.releaseType); - console.info("uid:" + data.uid); - console.info("gid:" + data.gid); - console.info("seInfo:" + data.seInfo); - console.info("entryModuleName:" + data.entryModuleName); - console.info("isKeepAlive:" + data.isKeepAlive); - console.info("isNativeApp:" + data.isNativeApp); - console.info("installTime:" + data.installTime); - console.info("updateTime:" + data.updateTime); - console.info("appInfo.name:" + data.applicationInfo.name); - console.info("appInfo.bundleName:" + data.applicationInfo.bundleName); - console.info('getBundleArchiveInfo reqPermissions length [' + data.reqPermissions.length + ']'); - for (var j = 0; j < data.reqPermissions.length; j++) { - console.info("reqPermissions[" + j + "]:" + data.reqPermissions[j]); - } - console.info('getBundleArchiveInfo defPermissions length [' + data.defPermissions.length + ']'); - for (var j = 0; j < data.defPermissions.length; j++) { - console.info("defPermissions[" + j + "]:" + data.defPermissions[j]); - } - console.info('getBundleArchiveInfo hapModuleNames length [' + data.hapModuleNames.length + ']'); - for (var j = 0; j < data.hapModuleNames.length; j++) { - console.info("hapModuleNames[" + j + "]:" + data.hapModuleNames[j]); - } - console.info('getBundleArchiveInfo moduleNames length [' + data.moduleNames.length + ']'); - for (var j = 0; j < data.moduleNames.length; j++) { - console.info("moduleNames[" + j + "]:" + data.moduleNames[j]); - } - console.info('getBundleArchiveInfo modulePublicDirs length [' + data.modulePublicDirs.length + ']'); - for (var j = 0; j < data.modulePublicDirs.length; j++) { - console.info("modulePublicDirs[" + j + "]:" + data.modulePublicDirs[j]); - } - console.info('getBundleArchiveInfo moduleDirs length [' + data.moduleDirs.length + ']'); - for (var j = 0; j < data.moduleDirs.length; j++) { - console.info("moduleDirs[" + j + "]:" + data.moduleDirs[j]); - } - console.info('getBundleArchiveInfo moduleResPaths length [' + data.moduleResPaths.length + ']'); - for (var j = 0; j < data.moduleResPaths.length; j++) { - console.info("moduleResPaths[" + j + "]:" + data.moduleResPaths[j]); - } - console.info('getBundleArchiveInfo abilityInfo length [' + data.abilityInfos.length + ']'); - for (var j = 0; j < data.abilityInfos.length; j++) { - console.info("abilityInfos[" + j + "]name:" + data.abilityInfos[j].name); - console.info("abilityInfos[" + j + "]package:" + data.abilityInfos[j].package); - } -}) -``` - -## bundle.getBundleArchiveInfo - -getBundleArchiveInfo(hapFilePath: string, bundleFlags: number, callback: AsyncCallback\): void - -以异步方法从给定的HAP中获取BundleInfo,使用callback形式返回结果。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| ----------- | ------------------------- | ---- | ------------------------------------------------------------ | -| hapFilePath | string | 是 | HAP文件路径 | -| bundleFlags | number | 是 | 0:返回默认BundleInfo
1:返回包含abilityInfo的BundleInfo | -| callback | AsyncCallback | 是 | 程序启动作为入参的回调函数,返回包信息。 | - -**示例:** - -```js -bundle.getBundleArchiveInfo('/data/test.hap', 1, OnReceiveEvent); - -function OnReceiveEvent(err, data) { - console.info("name:" + data.name); - console.info("label:" + data.label); - console.info("description:" + data.description); - console.info("vendor:" + data.vendor); - console.info("versionCode:" + data.versionCode); - console.info("versionName:" + data.versionName); - console.info("jointUserId:" + data.jointUserId); - console.info("minSdkVersion:" + data.minSdkVersion); - console.info("maxSdkVersion:" + data.maxSdkVersion); - console.info("mainEntry:" + data.mainEntry); - console.info("cpuAbi:" + data.cpuAbi); - console.info("appId:" + data.appId); - console.info("compatibleVersion:" + data.compatibleVersion); - console.info("targetVersion:" + data.targetVersion); - console.info("releaseType:" + data.releaseType); - console.info("uid:" + data.uid); - console.info("gid:" + data.gid); - console.info("seInfo:" + data.seInfo); - console.info("entryModuleName:" + data.entryModuleName); - console.info("isKeepAlive:" + data.isKeepAlive); - console.info("isNativeApp:" + data.isNativeApp); - console.info("installTime:" + data.installTime); - console.info("updateTime:" + data.updateTime); - console.info("appInfo.name:" + data.applicationInfo.name); - console.info("appInfo.bundleName:" + data.applicationInfo.bundleName); - console.info('getBundleArchiveInfo reqPermissions length [' + data.reqPermissions.length + ']'); - for (var j = 0; j < data.reqPermissions.length; j++) { - console.info("reqPermissions[" + j + "]:" + data.reqPermissions[j]); - } - console.info('getBundleArchiveInfo defPermissions length [' + data.defPermissions.length + ']'); - for (var j = 0; j < data.defPermissions.length; j++) { - console.info("defPermissions[" + j + "]:" + data.defPermissions[j]); - } - console.info('getBundleArchiveInfo hapModuleNames length [' + data.hapModuleNames.length + ']'); - for (var j = 0; j < data.hapModuleNames.length; j++) { - console.info("hapModuleNames[" + j + "]:" + data.hapModuleNames[j]); - } - console.info('getBundleArchiveInfo moduleNames length [' + data.moduleNames.length + ']'); - for (var j = 0; j < data.moduleNames.length; j++) { - console.info("moduleNames[" + j + "]:" + data.moduleNames[j]); - } - console.info('getBundleArchiveInfo modulePublicDirs length [' + data.modulePublicDirs.length + ']'); - for (var j = 0; j < data.modulePublicDirs.length; j++) { - console.info("modulePublicDirs[" + j + "]:" + data.modulePublicDirs[j]); - } - console.info('getBundleArchiveInfo moduleDirs length [' + data.moduleDirs.length + ']'); - for (var j = 0; j < data.moduleDirs.length; j++) { - console.info("moduleDirs[" + j + "]:" + data.moduleDirs[j]); - } - console.info('getBundleArchiveInfo moduleResPaths length [' + data.moduleResPaths.length + ']'); - for (var j = 0; j < data.moduleResPaths.length; j++) { - console.info("moduleResPaths[" + j + "]:" + data.moduleResPaths[j]); - } - console.info('getBundleArchiveInfo abilityInfo length [' + data.abilityInfos.length + ']'); - for (var j = 0; j < data.abilityInfos.length; j++) { - console.info("abilityInfos[" + j + "]name:" + data.abilityInfos[j].name); - console.info("abilityInfos[" + j + "]package:" + data.abilityInfos[j].package); - } -} -``` - -## bundle.getBundleInstaller - -getBundleInstaller(): Promise - -以异步方法获取BundleInstaller,使用Promise形式返回结果。 - -**返回值:** - -| 类型 | 说明 | -| ------------------------ | --------------------------------------------------- | -| Promise | 返回值为Promise对象,Promise中包含BundleInstaller。 | - -**示例:** - -```js -bundle.getBundleInstaller().then((data) => { - data.install(['/data/test.hap'], { - param: { - userId: 0, - installFlag: 1, - isKeepData: false - } - }, OnReceiveinstallEvent); - - function OnReceiveinstallEvent(err, data) { - console.info("name: for begin"); - console.info("install result code:" + data.status); - console.info("install result msg:" + data.statusMessage); - } -}) -``` - -## bundle.getBundleInstaller - -getBundleInstaller(callback: AsyncCallback): void; - -以异步方法从给定的HAP中获取BundleInstaller,使用callback形式返回结果。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| -------- | ------------------------------ | ---- | ------------------------------------------------- | -| callback | AsyncCallback | 是 | 程序启动作为入参的回调函数,返回BundleInstaller。 | - -**示例:** - -```js -bundle.getBundleInstaller((err, data)=>{ - data.uninstall('com.example.myapplication', { - userId: 0, - installFlag: 1, - isKeepData: false - }, OnReceiveinstallEvent); - - function OnReceiveinstallEvent(err, data) { - console.info("name: for begin"); - console.info("uninstall result code:" + data.status); - console.info("uninstall result msg:" + data.statusMessage); - } -}) -``` - -## bundle.getAllShortcutInfo - -getAllShortcutInfo(bundleName: string): Promise> - -以异步方法获取指定bundle的Shortcut信息,使用Promise形式返回结果。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| ---------- | ------ | ---- | -------- | -| bundleName | string | 是 | bundle名 | - -**返回值:** -| 类型 | 说明 | -| ----------------------------- | ---------------------------------------------------- | -| Promise\> | 返回值为Promise对象,Promise中包含Shortcut信息列表。 | - -**示例:** - -```js -bundle.getAllShortcutInfo('com.example.third1').then((data) => { - console.log("getAllShortcutInfo data:" + data); -}); -``` - - - -## bundle.getAllShortcutInfo - -getAllShortcutInfo(bundleName: string, callback: AsyncCallback>): void - -以异步方法获取指定bundle的Shortcut信息,使用callback形式返回结果。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| ---------- | ------------------------------------ | ---- | -------------------------------------------------- | -| bundleName | string | 是 | bundle名 | -| callback | AsyncCallback<> | 是 | 程序启动作为入参的回调函数,返回Shortcut信息列表。 | - -**示例:** - -```js -bundle.getAllShortcutInfo('com.example.third1', OnReceiveEvent); - -function OnReceiveEvent(err, data) { - console.log("getAllShortcutInfo data:" + data); -} -``` - -## bundle.checkPermission - -checkPermission(bundleName: string, permission: string): Promise\ - -以异步方法校验指定bundle是否具有指定权限,使用Promise形式返回结果。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| ---------- | ------ | ---- | -------- | -| bundleName | string | 是 | bundle名 | -| permission | string | 是 | 权限名 | - -**返回值:** -| 类型 | 说明 | -| --------------------- | ------------------------------------------------------------ | -| Promise\ | 返回值为Promise对象,Promise中包含校验结果。
-1: 未授权
0: 已授权 | - -**示例:** - -```js -bundle.checkPermission('com.example.actsbmscheckpermissiontest', 'com.permission.CAMERA').then((data) => { - console.log("checkPermission data:" + data); -}); -``` - -## bundle.checkPermission - -checkPermission(bundleName: string, permission: string, callback: AsyncCallback\): void - -以异步方法校验指定bundle是否具有指定权限,使用callback形式返回结果。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| ---------- | --------------------------- | ---- | ------------------------------------------------------------ | -| bundleName | string | 是 | bundle名 | -| permission | string | 是 | 权限名 | -| callback | AsyncCallback\ | 是 | 程序启动作为入参的回调函数,返回校验结果。
-1: 未授权
0: 已授权 | - -**示例:** - -```js -bundle.checkPermission('com.example.actsbmscheckpermissiontest', 'com.permission.CAMERA', OnReceiveEvent); - -function OnReceiveEvent(err, data) { - console.log("checkPermission data:" + data); -} -``` - -## ElementName - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ----------- | -------- | ------ | ---- | ------------------------------------------------------------ | -| deviceId | 只读 | string | 否 | 表示运行指定Ability的设备ID。 | -| bundleName | 只读 | string | 是 | 表示包描述。如果在Want中同时指定了BundleName和AbilityName,则Want可以直接匹配到指定的Ability。 | -| abilityName | 只读 | string | 是 | 表示待启动的Ability名称。如果在Want中同时指定了BundleName和AbilityName,则Want可以直接匹配到指定的Ability。 | - -## InstallStatus - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ------------- | -------- | ---------------- | ---- | ------------------------------------------------------------ | -| status | 只读 | InstallErrorCode | 是 | 安装结果code
SUCCESS = 0
STATUS_INSTALL_FAILURE = 1
STATUS_INSTALL_FAILURE_ABORTED = 2,
STATUS_INSTALL_FAILURE_INVALID = 3
STATUS_INSTALL_FAILURE_CONFLICT = 4
STATUS_INSTALL_FAILURE_STORAGE = 5
STATUS_INSTALL_FAILURE_INCOMPATIBLE = 6
STATUS_INSTALL_FAILURE_DOWNLOAD_TIMEOUT = 0x0B
STATUS_INSTALL_FAILURE_DOWNLOAD_FAILED = 0x0C
STATUS_ABILITY_NOT_FOUND = 0x40
STATUS_BMS_SERVICE_ERROR = 0x41 | -| statusMessage | 只读 | string | 是 | 安装结果Message | diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/01.Ability\346\241\206\346\236\266/06.CommonEvent\346\250\241\345\235\227.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/01.Ability\346\241\206\346\236\266/06.CommonEvent\346\250\241\345\235\227.md" deleted file mode 100644 index 7632d3801fa93aee8fa9f592512f516ef14f72d0..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/01.Ability\346\241\206\346\236\266/06.CommonEvent\346\250\241\345\235\227.md" +++ /dev/null @@ -1,879 +0,0 @@ ---- -title: CommonEvent模块 -permalink: /pages/010c010106 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 公共事件模块 - -> **说明:** -> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - -## 权限列表 - -| 系统公共事件宏 | 系统公共事件名称 | 订阅者所需权限 | -| ------------ | ------------------ | ---------------------- | -| COMMON_EVENT_BOOT_COMPLETED | usual.event.BOOT_COMPLETED | ohos.permission.RECEIVER_STARTUP_COMPLETED | -| COMMON_EVENT_SHUTDOWN | usual.event.SHUTDOWN | 无 | -| COMMON_EVENT_BATTERY_CHANGED | usual.event.BATTERY_CHANGED | 无 | -| COMMON_EVENT_BATTERY_LOW | usual.event.BATTERY_LOW | 无 | -| COMMON_EVENT_BATTERY_OKAY | usual.event.BATTERY_OKAY | 无 | -| COMMON_EVENT_POWER_CONNECTED | usual.event.POWER_CONNECTED | 无 | -| COMMON_EVENT_POWER_DISCONNECTED | usual.event.POWER_DISCONNECTED | 无 | -| COMMON_EVENT_SCREEN_OFF | usual.event.SCREEN_OFF | 无 | -| COMMON_EVENT_SCREEN_ON | usual.event.SCREEN_ON | 无 | -| COMMON_EVENT_USER_PRESENT | usual.event.USER_PRESENT | 无 | -| COMMON_EVENT_TIME_TICK | usual.event.TIME_TICK | 无 | -| COMMON_EVENT_TIME_CHANGED | usual.event.TIME_CHANGED | 无 | -| COMMON_EVENT_DATE_CHANGED | usual.event.DATE_CHANGED | 无 | -| COMMON_EVENT_TIMEZONE_CHANGED | usual.event.TIMEZONE_CHANGED | 无 | -| COMMON_EVENT_CLOSE_SYSTEM_DIALOGS | usual.event.CLOSE_SYSTEM_DIALOGS | 无 | -| COMMON_EVENT_PACKAGE_ADDED | usual.event.PACKAGE_ADDED | 无 | -| COMMON_EVENT_PACKAGE_REPLACED | usual.event.PACKAGE_REPLACED | 无 | -| COMMON_EVENT_MY_PACKAGE_REPLACED | usual.event.MY_PACKAGE_REPLACED | 无 | -| COMMON_EVENT_PACKAGE_REMOVED | usual.event.PACKAGE_REMOVED | 无 | -| COMMON_EVENT_PACKAGE_FULLY_REMOVED | usual.event.PACKAGE_FULLY_REMOVED | 无 | -| COMMON_EVENT_PACKAGE_CHANGED | usual.event.PACKAGE_CHANGED | 无 | -| COMMON_EVENT_PACKAGE_RESTARTED | usual.event.PACKAGE_RESTARTED | 无 | -| COMMON_EVENT_PACKAGE_DATA_CLEARED | usual.event.PACKAGE_DATA_CLEARED | 无 | -| COMMON_EVENT_PACKAGES_SUSPENDED | usual.event.PACKAGES_SUSPENDED | 无 | -| COMMON_EVENT_PACKAGES_UNSUSPENDED | usual.event.PACKAGES_UNSUSPENDED | 无 | -| COMMON_EVENT_MY_PACKAGE_SUSPENDED | usual.event.MY_PACKAGE_SUSPENDED | 无 | -| COMMON_EVENT_MY_PACKAGE_UNSUSPENDED | usual.event.MY_PACKAGE_UNSUSPENDED | 无 | -| COMMON_EVENT_UID_REMOVED | usual.event.UID_REMOVED | 无 | -| COMMON_EVENT_PACKAGE_FIRST_LAUNCH | usual.event.PACKAGE_FIRST_LAUNCH | 无 | -| COMMON_EVENT_PACKAGE_NEEDS_VERIFICATION | usual.event.PACKAGE_NEEDS_VERIFICATION | 无 | -| COMMON_EVENT_PACKAGE_VERIFIED | usual.event.PACKAGE_VERIFIED | 无 | -| COMMON_EVENT_EXTERNAL_APPLICATIONS_AVAILABLE | usual.event.EXTERNAL_APPLICATIONS_AVAILABLE | 无 | -| COMMON_EVENT_EXTERNAL_APPLICATIONS_UNAVAILABLE | usual.event.EXTERNAL_APPLICATIONS_UNAVAILABLE | 无 | -| COMMON_EVENT_CONFIGURATION_CHANGED | usual.event.CONFIGURATION_CHANGED | 无 | -| COMMON_EVENT_LOCALE_CHANGED | usual.event.LOCALE_CHANGED | 无 | -| COMMON_EVENT_MANAGE_PACKAGE_STORAGE | usual.event.MANAGE_PACKAGE_STORAGE | 无 | -| COMMON_EVENT_DRIVE_MODE | common.event.DRIVE_MODE | 无 | -| COMMON_EVENT_HOME_MODE | common.event.HOME_MODE | 无 | -| COMMON_EVENT_OFFICE_MODE | common.event.OFFICE_MODE | 无 | -| COMMON_EVENT_USER_STARTED | usual.event.USER_STARTED | 无 | -| COMMON_EVENT_USER_BACKGROUND | usual.event.USER_BACKGROUND | 无 | -| COMMON_EVENT_USER_FOREGROUND | usual.event.USER_FOREGROUND | 无 | -| COMMON_EVENT_USER_SWITCHED | usual.event.USER_SWITCHED | ohos.permission.MANAGE_USERS | -| COMMON_EVENT_USER_UNLOCKED | usual.event.USER_UNLOCKED | 无 | -| COMMON_EVENT_USER_STOPPED | usual.event.USER_STOPPED | 无 | -| COMMON_EVENT_HWID_LOGIN | common.event.HWID_LOGIN | 无 | -| COMMON_EVENT_HWID_LOGOUT | common.event.HWID_LOGOUT | 无 | -| COMMON_EVENT_HWID_TOKEN_INVALID | common.event.HWID_TOKEN_INVALID | 无 | -| COMMON_EVENT_HWID_LOGOFF | common.event.HWID_LOGOFF | 无 | -| COMMON_EVENT_WIFI_POWER_STATE | usual.event.wifi.POWER_STATE | 无 | -| COMMON_EVENT_WIFI_SCAN_FINISHED | usual.event.wifi.SCAN_FINISHED | ohos.permission.LOCATION | -| COMMON_EVENT_WIFI_RSSI_VALUE | usual.event.wifi.RSSI_VALUE | ohos.permission.GET_WIFI_INFO | -| COMMON_EVENT_WIFI_CONN_STATE | usual.event.wifi.CONN_STATE | 无 | -| COMMON_EVENT_WIFI_HOTSPOT_STATE | usual.event.wifi.HOTSPOT_STATE | 无 | -| COMMON_EVENT_WIFI_AP_STA_JOIN | usual.event.wifi.WIFI_HS_STA_JOIN | ohos.permission.GET_WIFI_INFO | -| COMMON_EVENT_WIFI_AP_STA_LEAVE | usual.event.wifi.WIFI_HS_STA_LEAVE | ohos.permission.GET_WIFI_INFO | -| COMMON_EVENT_WIFI_P2P_CONN_STATE | usual.event.wifi.p2p.CONN_STATE_CHANGE | ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION | -| COMMON_EVENT_WIFI_P2P_STATE_CHANGED | usual.event.wifi.p2p.STATE_CHANGE | ohos.permission.GET_WIFI_INFO | -| COMMON_EVENT_WIFI_P2P_PEERS_STATE_CHANGED | usual.event.wifi.p2p.DEVICES_CHANGE | ohos.permission.GET_WIFI_INFO | -| COMMON_EVENT_WIFI_P2P_PEERS_DISCOVERY_STATE_CHANGED | usual.event.wifi.p2p.PEER_DISCOVERY_STATE_CHANGE | ohos.permission.GET_WIFI_INFO | -| COMMON_EVENT_WIFI_P2P_CURRENT_DEVICE_STATE_CHANGED | usual.event.wifi.p2p.CURRENT_DEVICE_CHANGE | ohos.permission.GET_WIFI_INFO | -| COMMON_EVENT_WIFI_P2P_GROUP_STATE_CHANGED | usual.event.wifi.p2p.GROUP_STATE_CHANGED | ohos.permission.GET_WIFI_INFO | -| COMMON_EVENT_BLUETOOTH_A2DPSOURCE_AVRCP_CONNECT_STATE_UPDATE | usual.event.bluetooth.a2dpsource.AVRCP_CONNECT_STATE_UPDATE | ohos.permission.USE_BLUETOOTH | -| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_SDP_RESULT | usual.event.bluetooth.remotedevice.SDP_RESULT | 无 | -| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIRING_CANCEL | usual.event.bluetooth.remotedevice.PAIRING_CANCEL | 无 | -| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CONNECT_REQ | usual.event.bluetooth.remotedevice.CONNECT_REQ | 无 | -| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CONNECT_REPLY | usual.event.bluetooth.remotedevice.CONNECT_REPLY | 无 | -| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CONNECT_CANCEL | usual.event.bluetooth.remotedevice.CONNECT_CANCEL | 无 | -| COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_CONNECT_STATE_UPDATE | usual.event.bluetooth.handsfreeunit.CONNECT_STATE_UPDATE | 无 | -| COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_AUDIO_STATE_UPDATE | usual.event.bluetooth.handsfreeunit.AUDIO_STATE_UPDATE | 无 | -| COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_AG_COMMON_EVENT | usual.event.bluetooth.handsfreeunit.AG_COMMON_EVENT | 无 | -| COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_AG_CALL_STATE_UPDATE | usual.event.bluetooth.handsfreeunit.AG_CALL_STATE_UPDATE | 无 | -| COMMON_EVENT_BLUETOOTH_HOST_REQ_DISCOVERABLE | usual.event.bluetooth.host.REQ_DISCOVERABLE | 无 | -| COMMON_EVENT_NFC_ACTION_ADAPTER_STATE_CHANGED | usual.event.nfc.action.ADAPTER_STATE_CHANGED | 无 | -| COMMON_EVENT_DISCHARGING | usual.event.DISCHARGING | 无 | -| COMMON_EVENT_CHARGING | usual.event.CHARGING | 无 | -| COMMON_EVENT_DEVICE_IDLE_MODE_CHANGED | usual.event.DEVICE_IDLE_MODE_CHANGED | 无 | -| COMMON_EVENT_POWER_SAVE_MODE_CHANGED | usual.event.POWER_SAVE_MODE_CHANGED | 无 | -| COMMON_EVENT_USER_ADDED | usual.event.USER_ADDED | ohos.permission.MANAGE_USERS | -| COMMON_EVENT_USER_REMOVED | usual.event.USER_REMOVED | ohos.permission.MANAGE_USERS | -| COMMON_EVENT_LOCATION_MODE_STATE_CHANGED | usual.event.location.MODE_STATE_CHANGED | 无 | -| COMMON_EVENT_IVI_SLEEP | common.event.IVI_SLEEP | 无 | -| COMMON_EVENT_IVI_PAUSE | common.event.IVI_PAUSE | 无 | -| COMMON_EVENT_IVI_STANDBY | common.event.IVI_STANDBY | 无 | -| COMMON_EVENT_IVI_LASTMODE_SAVE | common.event.IVI_LASTMODE_SAVE | 无 | -| COMMON_EVENT_IVI_VOLTAGE_ABNORMAL | common.event.IVI_VOLTAGE_ABNORMAL | 无 | -| COMMON_EVENT_IVI_HIGH_TEMPERATURE | common.event.IVI_HIGH_TEMPERATURE | 无 | -| COMMON_EVENT_IVI_EXTREME_TEMPERATURE | common.event.IVI_EXTREME_TEMPERATURE | 无 | -| COMMON_EVENT_IVI_TEMPERATURE_ABNORMAL | common.event.IVI_TEMPERATURE_ABNORMAL | 无 | -| COMMON_EVENT_IVI_VOLTAGE_RECOVERY | common.event.IVI_VOLTAGE_RECOVERY | 无 | -| COMMON_EVENT_IVI_TEMPERATURE_RECOVERY | common.event.IVI_TEMPERATURE_RECOVERY | 无 | -| COMMON_EVENT_IVI_ACTIVE | common.event.IVI_ACTIVE | 无 | -| COMMON_EVENT_USB_DEVICE_ATTACHED | usual.event.hardware.usb.action.USB_DEVICE_ATTACHED | 无 | -| COMMON_EVENT_USB_DEVICE_DETACHED | usual.event.hardware.usb.action.USB_DEVICE_DETACHED | 无 | -| COMMON_EVENT_USB_ACCESSORY_ATTACHED | usual.event.hardware.usb.action.USB_ACCESSORY_ATTACHED | 无 | -| COMMON_EVENT_USB_ACCESSORY_DETACHED | usual.event.hardware.usb.action.USB_ACCESSORY_DETACHED | 无 | -| COMMON_EVENT_DISK_REMOVED | usual.event.data.DISK_REMOVED | ohos.permission.WRITE_USER_STORAGE 或 ohos.permission.READ_USER_STORAGE | -| COMMON_EVENT_DISK_UNMOUNTED | usual.event.data.DISK_UNMOUNTED | ohos.permission.WRITE_USER_STORAGE 或 ohos.permission.READ_USER_STORAGE | -| COMMON_EVENT_DISK_MOUNTED | usual.event.data.DISK_MOUNTED | ohos.permission.WRITE_USER_STORAGE 或 ohos.permission.READ_USER_STORAGE | -| COMMON_EVENT_DISK_BAD_REMOVAL | usual.event.data.DISK_BAD_REMOVAL | ohos.permission.WRITE_USER_STORAGE 或 ohos.permission.READ_USER_STORAGE | -| COMMON_EVENT_DISK_EJECT | usual.event.data.DISK_EJECT | ohos.permission.WRITE_USER_STORAGE 或 ohos.permission.READ_USER_STORAGE | -| COMMON_EVENT_AIRPLANE_MODE_CHANGED | usual.event.AIRPLANE_MODE | 无 | - -## 导入模块 - -```js -import CommonEvent from '@ohos.commonevent'; -``` - -## 系统能力 - -```js -SystemCapability.Notification.CommonEvent -``` - -## CommonEvent.publish - -publish(event: string, callback: AsyncCallback\): void - -发布公共事件(callback形式)。 - -**参数:** - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------- | -------- | -------------------- | ---- | ---------------------- | -| event | 只读 | string | 是 | 表示要发送的公共事件。 | -| callback | 只读 | AsyncCallback\ | 是 | 表示被指定的回调方法。 | - -**示例:** - -```js -//发布公共事件回调 -function PublishCallBack(err) { - console.info("==========================>PublishCallBack=======================>"); - console.info("==========================>err:=======================>", err.code); -} -//发布公共事件 -CommonEvent.publish("publish_event", PublishCallBack); -``` - - - -## CommonEvent.publish - -publish(event: string, options: CommonEventPublishData, callback: AsyncCallback\): void - -发布公共事件指定发布信息(callback形式)。 - -**参数:** - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------- | -------- | ---------------------- | ---- | ---------------------- | -| event | 只读 | string | 是 | 表示要发布的公共事件。 | -| options | 只读 | [CommonEventPublishData](#commoneventpublishdata) | 是 | 表示发布公共事件的属性。 | -| callback | 只读 | AsyncCallback\ | 是 | 表示被指定的回调方法。 | - -**示例:** - - -```js -//公共事件相关信息 -var options = { - code: 0; //公共事件的初始代码 - data: "initial data";//公共事件的初始数据 - isOrdered: true; //有序公共事件 -} -//发布公共事件回调 -function PublishCallBack(err) { - console.info("==========================>PublishCallBack=======================>"); -} -//发布公共事件 -CommonEvent.publish("publish_event", options, PublishCallBack); -``` - - - -## CommonEvent.createSubscriber - -createSubscriber(subscribeInfo: CommonEventSubscribeInfo, callback: AsyncCallback\): void - -创建订阅者(callback形式)。 - -**参数:** - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ------------- | -------- | ------------------------------------------------------------ | ---- | -------------------------- | -| subscribeInfo | 只读 | [CommonEventSubscribeInfo](#commoneventsubscribeinfo) | 是 | 表示订阅信息。 | -| callback | 只读 | AsyncCallback\<[CommonEventSubscriber](#commoneventsubscriber)> | 是 | 表示创建订阅者的回调方法。 | - -**示例:** - - -```js -var subscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 -//订阅者信息 -var subscribeInfo = { - events: ["event"] -}; -//创建订阅者回调 -function CreateSubscriberCallBack(err, data) { - console.info("==========================>CreateSubscriberCallBack=======================>"); - subscriber = data; -} -//创建订阅者 -CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack); -``` - - - -## CommonEvent.createSubscriber - -createSubscriber(subscribeInfo: CommonEventSubscribeInfo): Promise\ - -创建订阅者(Promise形式)。 - -**参数:** - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ------------- | -------- | ----------------------------------------------------- | ---- | -------------- | -| subscribeInfo | 只读 | [CommonEventSubscribeInfo](#commoneventsubscribeinfo) | 是 | 表示订阅信息。 | - -**返回值:** -| 类型 | 说明 | -| --------------------------------------------------------- | ---------------- | -| Promise\<[CommonEventSubscriber](#commoneventsubscriber)> | 返回订阅者对象。 | - -**示例:** - -```js -var subscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 -//订阅者信息 -var subscribeInfo = { - events: ["event"] -}; -//创建订阅者 -CommonEvent.createSubscriber(subscribeInfo).then((data) => { - console.info("==========================>createSubscriberPromise=======================>"); - subscriber = data; -}); -``` - - - -## CommonEvent.subscribe - -subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback\): void - -订阅公共事件(callback形式)。 - -**参数:** - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ---------- | -------- | --------------------------------------------------- | ---- | -------------------------------- | -| subscriber | 只读 | [CommonEventSubscriber](#commoneventsubscriber) | 是 | 表示订阅者对象。 | -| callback | 只读 | AsyncCallback\<[CommonEventData](#commoneventdata)> | 是 | 表示接收公共事件数据的回调函数。 | - -**示例:** - -无序事件: - -```js -var subscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 -//订阅者信息 -var subscribeInfo = { - events: ["event"] -}; -//订阅公共事件回调 -function SubscribeCallBack(err, data) { - console.info("==========================>SubscribeCallBack=======================>"); -} -//创建订阅者回调 -function CreateSubscriberCallBack(err, data) { - console.info("==========================>CreateSubscriberCallBack=======================>"); - subscriber = data; - //订阅公共事件 - CommonEvent.subscribe(subscriber, SubscribeCallBack); -} -//创建订阅者 -CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack); -``` - - 有序事件: - -```js -var subscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 -//订阅者信息 -var subscribeInfo = { - events: ["event"] -}; - -//设置有序公共事件的结果代码回调 -function SetCodeCallBack(err) { - console.info("==========================>SetCodeCallBack=======================>"); -} -//设置有序公共事件的结果数据回调 -function SetDataCallBack(err) { - console.info("==========================>SetDataCallBack=======================>"); -} -//完成本次有序公共事件处理回调 -function FinishCommonEventCallBack(err) { - console.info("==========================>FinishCommonEventCallBack=======================>"); -} -//订阅公共事件回调 -function SubscribeCallBack(err, data) { - console.info("==========================>SubscribeCallBack=======================>"); - //设置有序公共事件的结果代码 - subscriber.setCode(0, SetCodeCallBack); - //设置有序公共事件的结果数据 - subscriber.setData("publish_data_changed", SetDataCallBack); - //完成本次有序公共事件处理 - subscriber.finishCommonEvent(FinishCommonEventCallBack) -} - -//创建订阅者回调 -function CreateSubscriberCallBack(err, data) { - console.info("==========================>CreateSubscriberCallBack=======================>"); - subscriber = data; - //订阅公共事件 - CommonEvent.subscribe(subscriber, SubscribeCallBack); -} - -//创建订阅者 -CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack); -``` - - - -## CommonEvent.unsubscribe - -unsubscribe(subscriber: CommonEventSubscriber, callback?: AsyncCallback\): void - -取消订阅公共事件(callback形式)。 - -**参数:** - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ---------- | -------- | --------------------- | ---- | ------------------------ | -| subscriber | 只读 | CommonEventSubscriber | 是 | 表示订阅者对象。 | -| callback | 只读 | AsyncCallback\ | 是 | 表示取消订阅的回调方法。 | - -**示例:** - -```js -var subscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 -//订阅者信息 -var subscribeInfo = { - events: ["event"] -}; -//订阅公共事件回调 -function SubscribeCallBack(err, data) { - console.info("==========================>SubscribeCallBack=======================>"); -} -//创建订阅者回调 -function CreateSubscriberCallBack(err, data) { - console.info("==========================>CreateSubscriberCallBack=======================>"); - subscriber = data; - //订阅公共事件 - CommonEvent.subscribe(subscriber, SubscribeCallBack); -} -//取消订阅公共事件回调 -function UnsubscribeCallBack(err) { - console.info("==========================>UnsubscribeCallBack=======================>"); -} -//创建订阅者 -CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack); -//取消订阅公共事件 -CommonEvent.unsubscribe(subscriber, UnsubscribeCallBack); -``` - -## CommonEventPublishData - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| --------------------- | -------- | -------------------- | ---- | ---------------------------- | -| bundleName | 只读 | string | 否 | 表示包名称 | -| code | 只读 | number | 否 | 表示公共事件的结果代码 | -| data | 只读 | string | 否 | 表示公共事件的自定义结果数据 | -| subscriberPermissions | 只读 | Array\ | 否 | 表示订阅者的权限 | -| isOrdered | 只读 | boolean | 否 | 表示是否是有序事件 | -| parameters | 只读 | {[key: string]: any} | 否 | 表示公共事件的附加信息 | - -## CommonEventSubscribeInfo - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ------------------- | -------- | -------------- | ---- | ------------------------------------------------------------ | -| events | 只读 | Array\ | 是 | 表示要发送的公共事件 | -| publisherPermission | 只读 | string | 否 | 表示发布者的权限 | -| publisherDeviceId | 只读 | string | 否 | 表示设备ID,该值必须是同一ohos网络上的现有设备ID | -| userId | 只读 | number | 否 | 表示用户ID。此参数是可选的,默认值当前用户的ID。如果指定了此参数,则该值必须是系统中现有的用户ID。 | -| priority | 只读 | number | 否 | 表示订阅者的优先级。值的范围是-100到1000 | - -## CommonEventData - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ---------- | -------- | -------------------- | ---- | ------------------------------------------------------ | -| event | 只读 | string | 是 | 表示当前接收的公共事件名称 | -| bundleName | 只读 | string | 否 | 表示包名称 | -| code | 只读 | number | 否 | 表示公共事件的结果代码,用于传递int类型的数据 | -| data | 只读 | string | 否 | 表示公共事件的自定义结果数据,用于传递string类型的数据 | -| parameters | 只读 | {[key: string]: any} | 否 | 表示公共事件的附加信息 | - -## CommonEventSubscriber - -### getCode - -getCode(callback: AsyncCallback\): void - -获取公共事件的结果代码(callback形式)。 - -**参数:** - -| 参数名 | 类型 | 必填 | 描述 | -| -------- | ---------------------- | ---- | ------------------ | -| callback | AsyncCallback\ | 是 | 公共事件的结果代码 | - -**示例:** - -```js -var subscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 -//设置有序公共事件的结果数据回调 -function getCodeCallback(err, data) { - console.info("==========================>getCodeCallback=======================>"); - console.info("==========================>err:=======================>", err.code); - console.info("==========================>code:=======================>", data); -} -subscriber.getCode(getCodeCallback); -``` - -### getCode - -getCode(): Promise\ - -获取公共事件的结果代码(Promise形式)。 - -**返回值:** - -| 类型 | 说明 | -| ---------------- | -------------------- | -| Promise\ | 公共事件的结果代码。 | - -**示例:** - -```js -var subscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 -subscriber.getCode().then((data) => { - console.info("==========================>getCodePromise=======================>"); - console.info("==========================>code:=======================>", data); -}); -``` - -### setCode - -setCode(code: number, callback: AsyncCallback\): void - -设置公共事件的结果代码(callback形式)。 - -**参数:** - -| 参数名 | 类型 | 必填 | 描述 | -| -------- | -------------------- | ---- | ---------------------- | -| code | number | 是 | 公共事件的结果代码。 | -| callback | AsyncCallback\ | 是 | 表示被指定的回调方法。 | - -**示例:** - -```js -var subscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 -//设置有序公共事件的结果数据回调 -function setCodeCallback(err) { - console.info("==========================>setCodeCallback=======================>"); - console.info("==========================>err:=======================>", err.code); -} -subscriber.setCode(1, setCodeCallback); -``` - -### setCode - -setCode(code: number): Promise\ - -设置公共事件的结果代码(Promise形式)。 - -**参数:** - -| 参数名 | 类型 | 必填 | 描述 | -| ------ | ------ | ---- | ------------------ | -| code | number | 是 | 公共事件的结果代码 | - -**示例:** - -```js -var subscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 -subscriber.setCode(1).then(() => { - console.info("==========================>setCodePromise=======================>"); -}); -``` - -### getData - -getData(callback: AsyncCallback\): void - -获取公共事件的结果数据(callback形式)。 - -**参数:** - -| 参数名 | 类型 | 必填 | 描述 | -| -------- | ---------------------- | ---- | -------------------- | -| callback | AsyncCallback\ | 是 | 公共事件的结果数据。 | - -**示例:** - -```js -var subscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 -//设置有序公共事件的结果数据回调 -function getDataCallback(err, data) { - console.info("==========================>getDataCallback=======================>"); - console.info("==========================>err:=======================>", err.code); - console.info("==========================>data:=======================>", data); -} -subscriber.getData(getDataCallback); -``` - -### getData - -getData(): Promise\ - -获取公共事件的结果数据(Promise形式)。 - -**返回值:** - -| 类型 | 说明 | -| ---------------- | ------------------ | -| Promise\ | 公共事件的结果数据 | - -**示例:** - -```js -var subscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 -subscriber.getData().then((data) => { - console.info("==========================>getDataPromise=======================>"); - console.info("==========================>data:=======================>", data); -}); -``` - -### setData - -setData(data: string, callback: AsyncCallback\): void - -设置公共事件的结果数据(callback形式)。 - -**参数:** - -| 参数名 | 类型 | 必填 | 描述 | -| -------- | -------------------- | ---- | -------------------- | -| data | string | 是 | 公共事件的结果数据 | -| callback | AsyncCallback\ | 是 | 表示被指定的回调方法 | - -**示例:** - -```js -var subscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 -//设置有序公共事件的结果数据回调 -function setDataCallback(err) { - console.info("==========================>setDataCallback=======================>"); - console.info("==========================>err:=======================>", err.code); -} -subscriber.setData("publish_data_changed", setDataCallback); -``` - -### setData - -setData(data: string): Promise\ - -设置公共事件的结果数据(Promise形式)。 - -**参数:** - -| 参数名 | 类型 | 必填 | 描述 | -| ------ | ------ | ---- | -------------------- | -| data | string | 是 | 公共事件的结果数据。 | - -**示例:** - -```js -var subscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 -subscriber.setData("publish_data_changed").then(() => { - console.info("==========================>setDataPromise=======================>"); -}); -``` - -### setCodeAndData - -setCodeAndData(code: number, data: string, callback:AsyncCallback\): void - -设置公共事件的结果代码和结果数据(callback形式)。 - -**参数:** - -| 参数名 | 类型 | 必填 | 描述 | -| -------- | -------------------- | ---- | ---------------------- | -| code | number | 是 | 公共事件的结果代码。 | -| data | string | 是 | 公共事件的结果数据。 | -| callback | AsyncCallback\ | 是 | 表示被指定的回调方法。 | - -**示例:** - -```js -var subscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 -//设置有序公共事件的结果数据回调 -function setCodeDataCallback(err) { - console.info("==========================>setCodeDataCallback=======================>"); - console.info("==========================>err:=======================>", err.code); -} -subscriber.setCodeAndData(1, "publish_data_changed", setCodeDataCallback); -``` - -### setCodeAndData - -setCodeAndData(code: number, data: string): Promise\ - -设置公共事件的结果代码和结果数据(Promise形式)。 - -**参数:** - -| 参数名 | 类型 | 必填 | 描述 | -| ------ | ------ | ---- | -------------------- | -| code | number | 是 | 公共事件的结果代码。 | -| data | string | 是 | 公共事件的结果数据。 | - -**示例:** - -```js -var subscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 -subscriber.setCodeAndData(1, "publish_data_changed").then(() => { - console.info("==========================>setCodeAndData=======================>"); -}); -``` - -### isOrderedCommonEvent - -isOrderedCommonEvent(callback: AsyncCallback\): void - -查询当前公共事件的是否为有序公共事件(callback形式)。 - -返回true代表是有序公共事件,false代表不是有序公共事件。 - -**参数:** - -| 参数名 | 类型 | 必填 | 描述 | -| -------- | ----------------------- | ---- | ---------------------------------- | -| callback | AsyncCallback\ | 是 | 当前公共事件的是否为有序公共事件。 | - -**示例:** - -```js -var subscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 -//设置有序公共事件的结果数据回调 -function isOrderedCallback(err, data) { - console.info("==========================>isOrderedCallback=======================>"); - console.info("==========================>err:=======================>", err.code); - console.info("==========================>isOrdered:=======================>", data); -} -subscriber.isOrderedCommonEvent(isOrderedCallback); -``` - -### isOrderedCommonEvent - -isOrderedCommonEvent(): Promise\ - -查询当前公共事件的是否为有序公共事件(Promise形式)。 - -返回true代表是有序公共事件,false代表不是有序公共事件。 - -**返回值:** - -| 类型 | 说明 | -| ----------------- | -------------------------------- | -| Promise\ | 当前公共事件的是否为有序公共事件 | - -**示例:** - -```js -var subscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 -subscriber.isOrderedCommonEvent().then((data) => { - console.info("==========================>isOrdered:=======================>", data); -}); -``` - -### abortCommonEvent - -abortCommonEvent(callback: AsyncCallback\): void - -取消当前的公共事件,仅对有序公共事件有效,取消后,公共事件不再向下一个订阅者传递(callback形式)。 - -**参数:** - -| 参数名 | 类型 | 必填 | 描述 | -| -------- | -------------------- | ---- | -------------------- | -| callback | AsyncCallback\ | 是 | 取消当前的公共事件。 | - -**示例:** - -```js -var subscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 -//设置有序公共事件的结果数据回调 -function abortCallback(err) { - console.info("==========================>abortCallback=======================>"); - console.info("==========================>err:=======================>", err.code); -} -subscriber.abortCommonEvent(abortCallback); -``` - -### abortCommonEvent - -abortCommonEvent(): Promise\ - -取消当前的公共事件,仅对有序公共事件有效,取消后,公共事件不再向下一个订阅者传递(Promise形式)。 - -**示例:** - -```js -var subscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 -subscriber.abortCommonEvent().then(() => { - console.info("==========================>abortCommonEvent:=======================>"); -}); -``` - -### clearAbortCommonEvent - -clearAbortCommonEvent(callback: AsyncCallback\): void - -清除当前公共事件的取消状态,仅对有序公共事件有效(callback形式)。 - -**参数:** - -| 参数名 | 类型 | 必填 | 描述 | -| -------- | -------------------- | ---- | -------------------- | -| callback | AsyncCallback\ | 是 | 表示被指定的回调方法 | - -**示例:** - -```js -var subscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 -//设置有序公共事件的结果数据回调 -function clearAbortCallback(err) { - console.info("==========================>clearAbortCallback=======================>"); - console.info("==========================>err:=======================>", err.code); -} -subscriber.clearAbortCommonEvent(clearAbortCallback); -``` - -### clearAbortCommonEvent - -clearAbortCommonEvent(): Promise\ - -清除当前公共事件的取消状态,仅对有序公共事件有效(Promise形式)。 - -**示例:** - -```js -var subscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 -subscriber.clearAbortCommonEvent().then(() => { - console.info("==========================>clearAbortCommonEvent:=======================>"); -}); -``` - -### getAbortCommonEvent - -getAbortCommonEvent(callback: AsyncCallback\): void - -获取当前有序公共事件是否取消的状态(callback形式)。 - -**参数:** - -| 参数名 | 类型 | 必填 | 描述 | -| -------- | ----------------------- | ---- | ---------------------------------- | -| callback | AsyncCallback\ | 是 | 表示当前有序公共事件是否取消的状态 | - -**示例:** - -```js -var subscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 -//设置有序公共事件的结果数据回调 -function getAbortCallback(err, data) { - console.info("==========================>getAbortCallback=======================>"); - console.info("==========================>err:=======================>", err.code); - console.info("==========================>abort:=======================>", data); -} -subscriber.getAbortCommonEvent(getAbortCallback); -``` - -### getAbortCommonEvent - -getAbortCommonEvent(): Promise\ - -获取当前有序公共事件是否取消的状态(Promise形式)。 - -**返回值:** - -| 类型 | 说明 | -| ----------------- | ---------------------------------- | -| Promise\ | 表示当前有序公共事件是否取消的状态 | - -**示例:** - -```js -var subscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 -subscriber.getAbortCommonEvent().then((data) => { - console.info("==========================>getAbortCommonEvent:=======================>"); - console.info("==========================>abort:=======================>", data); -}); -``` - -### getSubscribeInfo - -getSubscribeInfo(callback: AsyncCallback\): void - -获取订阅者的订阅信息(callback形式)。 - -**参数:** - -| 参数名 | 类型 | 必填 | 描述 | -| -------- | ------------------------------------------------------------ | ---- | ---------------------- | -| callback | AsyncCallback\<[CommonEventSubscribeInfo](#commoneventsubscribeinfo)> | 是 | 表示订阅者的订阅信息。 | - -**示例:** - -```js -var subscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 -//设置有序公共事件的结果数据回调 -function getSubscribeInfoCallback(err, data) { - console.info("==========================>getSubscribeInfoCallback=======================>"); - console.info("==========================>err:=======================>", err.code); - console.info("==========================>priority:=======================>", data.priority); -} -subscriber.getSubscribeInfo(getSubscribeInfoCallback); -``` - -### getSubscribeInfo - -getSubscribeInfo(): Promise\ - -获取订阅者的订阅信息(Promise形式)。 - -**返回值:** - -| 类型 | 说明 | -| ------------------------------------------------------------ | ---------------------- | -| Promise\<[CommonEventSubscribeInfo](#commoneventsubscribeinfo)> | 表示订阅者的订阅信息。 | - -**示例:** - -```js -var subscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 -subscriber.getSubscribeInfo().then((data) => { - console.info("==========================>getSubscribeInfo:=======================>"); - console.info("==========================>priority:=======================>", data.priority); -}); -``` \ No newline at end of file diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/01.Ability\346\241\206\346\236\266/07.Notification\346\250\241\345\235\227.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/01.Ability\346\241\206\346\236\266/07.Notification\346\250\241\345\235\227.md" deleted file mode 100644 index 9593fd704d5a38d3001c117a9f358571f79b6320..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/01.Ability\346\241\206\346\236\266/07.Notification\346\250\241\345\235\227.md" +++ /dev/null @@ -1,3202 +0,0 @@ ---- -title: Notification模块 -permalink: /pages/010c010107 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# Notification模块 - -## 导入模块 - -```js -import Notification from '@ohos.notification'; -``` - -## 系统能力 - -```js -SystemCapability.Notification.Notification -``` - -## Notification.publish(request: NotificationRequest, callback: AsyncCallback\) - -- 接口说明 - - 发布通知(callback形式) - -- publish参数描述 - - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------- | -------- | --------------------- | ---- | ------------------------------------------- | -| request | 只读 | NotificationRequest | 是 | 设置要发布通知内容的NotificationRequest对象 | -| callback | 只读 | AsyncCallback\ | 是 | 被指定的回调方法 | - -- NotificationRequest类型说明 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| --------------------- | -------- | --------------------------------------------- | ---- | -------------------------- | -| content | 读、写 | NotificationContent | 是 | 通知内容 | -| id | 读、写 | number | 否 | 通知ID | -| slotType | 读、写 | SlotType | 否 | 通道类型 | -| isOngoing | 读、写 | boolean | 否 | 是否进行时通知 | -| isUnremovable | 读、写 | boolean | 否 | 是否可移除 | -| deliveryTime | 读、写 | number | 否 | 通知发送时间 | -| tapDismissed | 读、写 | boolean | 否 | 通知是否自动清除 | -| autoDeletedTime | 读、写 | number | 否 | 自动清除的时间 | -| wantAgent | 读、写 | WantAgent | 否 | 点击跳转的WantAgent | -| extraInfo | 读、写 | {[key: string]: any} | 否 | 扩展参数 | -| color | 读、写 | number | 否 | 通知背景颜色 | -| colorEnabled | 读、写 | boolean | 否 | 通知背景颜色是否使能 | -| isAlertOnce | 读、写 | boolean | 否 | 设置是否仅有一次此通知警报 | -| isStopwatch | 读、写 | boolean | 否 | 是否显示已用时间 | -| isCountDown | 读、写 | boolean | 否 | 是否显示倒计时时间 | -| isFloatingIcon | 读、写 | boolean | 否 | 是否显示状态栏图标 | -| label | 读、写 | string | 否 | 通知标签 | -| badgeIconStyle | 读、写 | number | 否 | 通知角标类型 | -| showDeliveryTime | 读、写 | boolean | 否 | 是否显示分发时间 | -| actionButtons | 读、写 | Array\ | 否 | 通知按钮,最多两个按钮 | -| smallIcon | 读、写 | PixelMap | 否 | 通知小图标 | -| largeIcon | 读、写 | PixelMap | 否 | 通知大图标 | -| creatorBundleName | 只读 | string | 否 | 创建通知的包名 | -| creatorUid | 只读 | number | 否 | 创建通知的UID | -| creatorPid | 只读 | number | 否 | 创建通知的PID | -| hashCode | 只读 | string | 否 | 通知唯一标识 | -| classification | 读、写 | string | 否 | 通知分类 | -| groupName | 读、写 | string | 否 | 组通知名称 | -| template8+ | 读、写 | [NotificationTemplate](#notificationtemplate) | 否 | 通知模板 | - -NotificationContent类型说明 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ----------- | -------- | ---------------------------- | ---- | ------------------ | -| contentType | 读、写 | ContentType | 是 | 通知内容类型 | -| normal | 读、写 | NotificationBasicContent | 否 | 基本类型通知内容 | -| longText | 读、写 | NotificationLongTextContent | 否 | 长文本类型通知内容 | -| multiLine | 读、写 | NotificationMultiLineContent | 否 | 多行类型通知内容 | -| picture | 读、写 | NotificationPictureContent | 否 | 图片类型通知内容 | - -- ContentType类型说明 - -| 名称 | 读写属性 | 类型 | 描述 | -| --------------------------------- | -------- | ----------- | ---------------- | -| NOTIFICATION_CONTENT_BASIC_TEXT | 只读 | ContentType | 普通类型通知 | -| NOTIFICATION_CONTENT_LONG_TEXT | 只读 | ContentType | 长文本类型通知 | -| NOTIFICATION_CONTENT_PICTURE | 只读 | ContentType | 图片类型通知 | -| NOTIFICATION_CONTENT_CONVERSATION | 只读 | ContentType | 社交类型通知 | -| NOTIFICATION_CONTENT_MULTILINE | 只读 | ContentType | 多行文本类型通知 | - -- NotificationBasicContent类型说明 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------------- | -------- | ------ | ---- | -------------------------------- | -| title | 读、写 | string | 是 | 通知标题 | -| text | 读、写 | string | 是 | 通知内容 | -| additionalText | 读、写 | string | 是 | 通知次要内容,是对通知内容的补充 | - -- NotificationLongTextContent类型说明 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------------- | -------- | ------ | ---- | -------------------------------- | -| title | 读、写 | string | 是 | 通知标题 | -| text | 读、写 | string | 是 | 通知内容 | -| additionalText | 读、写 | string | 是 | 通知次要内容,是对通知内容的补充 | -| longText | 读、写 | string | 是 | 通知的长文本 | -| briefText | 读、写 | string | 是 | 通知概要内容,是对通知内容的总结 | -| expandedTitle | 读、写 | string | 是 | 通知展开时的标题 | - -- NotificationMultiLineContent类型说明 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------------- | -------- | --------------- | ---- | -------------------------------- | -| title | 读、写 | string | 是 | 通知标题 | -| text | 读、写 | string | 是 | 通知内容 | -| additionalText | 读、写 | string | 是 | 通知次要内容,是对通知内容的补充 | -| briefText | 读、写 | string | 是 | 通知概要内容,是对通知内容的总结 | -| longTitle | 读、写 | string | 是 | 通知展开时的标题 | -| lines | 读、写 | Array\ | 是 | 通知的多行文本 | - -- NotificationPictureContent类型说明 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------------- | -------- | -------------- | ---- | -------------------------------- | -| title | 读、写 | string | 是 | 通知标题 | -| text | 读、写 | string | 是 | 通知内容 | -| additionalText | 读、写 | string | 是 | 通知次要内容,是对通知内容的补充 | -| briefText | 读、写 | string | 是 | 通知概要内容,是对通知内容的总结 | -| expandedTitle | 读、写 | string | 是 | 通知展开时的标题 | -| picture | 读、写 | image.PixelMap | 是 | 通知的图片内容 | - -- SlotType类型说明 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------------------- | -------- | -------- | ---- | -------- | -| SOCIAL_COMMUNICATION | 只读 | SlotType | 否 | 社交类型 | -| SERVICE_INFORMATION | 只读 | SlotType | 否 | 服务类型 | -| CONTENT_INFORMATION | 只读 | SlotType | 否 | 内容类型 | -| OTHER_TYPES | 只读 | SlotType | 否 | 其他类型 | - -- NotificationActionButton类型说明 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| --------- | -------- | --------------------- | ---- | ------------------------- | -| title | 读、写 | string | 是 | 按钮标题 | -| wantAgent | 读、写 | wantAgent | 是 | 点击按钮时触发的WantAgent | -| extras | 读、写 | Array\ | 否 | 按钮扩展信息 | -| icon | 读、写 | image.PixelMap | 否 | 按钮图标 | -| userInput | 读、写 | NotificationUserInput | 否 | 用户输入对象实例 | - -- NotificationUserInput类型说明 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------- | -------- | ------ | ---- | ----------------------------- | -| inputKey | 读、写 | string | 是 | 用户输入时用于标识此输入的key | - - -- 返回值 - - void - -- 示例 - -```js -//publish回调 -function publishCallback(err) { - console.info("==========================>publishCallback=======================>"); -} -//通知Request对象 -var notificationRequest = { - id: 1, - content: { - contentType: notify.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, - normal: { - title: "test_title", - text: "test_text", - additionalText: "test_additionalText" - } - } -} -Notification.publish(notificationRequest, publishCallback) -``` - - - -## Notification.publish(request: NotificationRequest) - -- 接口说明 - - 发布通知(Promise形式) - -- 返回值 - - Promise\ - -- 示例 - -```js -//通知Request对象 -var notificationRequest = { - notificationId: 1, - content: { - contentType: notify.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, - normal: { - title: "test_title", - text: "test_text", - additionalText: "test_additionalText" - } - } -} -Notification.publish(notificationRequest).then((void) => { - console.info("==========================>publishCallback=======================>"); -}); - -``` - - - -## Notification.cancel(id: number, label: string, callback: AsyncCallback\) - -- 接口说明 - - 取消与指定id和label相匹配的已发布通知(callback形式) - -- cancel参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------- | -------- | --------------------- | ---- | -------------------- | -| id | 只读 | number | 是 | 通知ID | -| label | 只读 | string | 是 | 通知标签 | -| callback | 只读 | AsyncCallback\ | 是 | 表示被指定的回调方法 | - -- 返回值 - - void - -- 示例 - -```js -//cancel回调 -function cancelCallback(err) { - console.info("==========================>cancelCallback=======================>"); -} -Notification.cancel(0, "label", cancelCallback) -``` - - - -## Notification.cancel(id:number, label?:string) - -- 接口说明 - - 取消与指定id相匹配的已发布通知,label可以指定也可以不指定(Promise形式) - -- cancel参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ----- | -------- | ------ | ---- | -------- | -| id | 只读 | number | 是 | 通知ID | -| label | 只读 | string | 否 | 通知标签 | - -- 返回值 - - Promise\ - -- 示例 - -```js -Notification.cancel(0).then((void) => { - console.info("==========================>cancelCallback=======================>"); -}); -``` - - - -## Notification.cancel(id: number, callback: AsyncCallback\) - -- 接口说明 - - 取消与指定id相匹配的已发布通知(callback形式) - -- cancel参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------- | -------- | --------------------- | ---- | -------------------- | -| id | 只读 | number | 是 | 通知ID | -| callback | 只读 | AsyncCallback\ | 是 | 表示被指定的回调方法 | - -- 返回值 - - void - -- 示例 - -```js -//cancel回调 -function cancelCallback(err) { - console.info("==========================>cancelCallback=======================>"); -} -Notification.cancel(0, cancelCallback) -``` - - - -## Notification.cancelAll(callback: AsyncCallback\) - -- 接口说明 - - 取消所有已发布的通知(callback形式) - -- cancelAll参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------- | -------- | --------------------- | ---- | -------------------- | -| callback | 只读 | AsyncCallback\ | 是 | 表示被指定的回调方法 | - -- 返回值 - - void - -- 示例 - -```js -//cancel回调 -function cancelAllback(err) { - console.info("==========================>cancelAllback=======================>"); -} -Notification.cancelAll(cancelCallback) -``` - - - -## Notification.cancelAll() - -- 接口说明 - - 取消所有已发布的通知(Promise形式) - -- 参数描述 - - 无参数 - -- 返回值 - - Promise\ - -- 示例 - -```js -Notification.cancelAll().then((void) => { - console.info("==========================>cancelAllback=======================>"); -}); -``` - - - -## Notification.addSlot(slot: NotificationSlot, callback: AsyncCallback\) - -- 接口说明 - - 创建通知通道(callback形式) - -- addSlot参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------- | -------- | --------------------- | ---- | -------------------- | -| slot | 只读 | NotificationSlot | 是 | 要创建的通知通道对象 | -| callback | 只读 | AsyncCallback\ | 是 | 表示被指定的回调方法 | - -- NotificationSlot类型说明 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------------------- | -------- | --------------- | ---- | ------------------------------------------ | -| type | 读、写 | SlotType | 是 | 通道类型 | -| level | 读、写 | number | 否 | 通知级别,不设置则根据通知渠道类型有默认值 | -| desc | 读、写 | string | 否 | 通知渠道描述信息 | -| badgeFlag | 读、写 | boolean | 否 | 是否显示角标 | -| bypassDnd | 读、写 | boolean | 否 | 置是否在系统中绕过免打扰模式 | -| lockscreenVisibility | 读、写 | boolean | 否 | 在锁定屏幕上显示通知的模式 | -| vibrationEnabled | 读、写 | boolean | 否 | 是否可振动 | -| sound | 读、写 | string | 否 | 通知提示音 | -| lightEnabled | 读、写 | boolean | 否 | 是否闪灯 | -| lightColor | 读、写 | number | 否 | 通知灯颜色 | -| vibrationValues | 读、写 | Array\ | 否 | 通知振动样式 | - -* 返回值 - - void - -* 示例 - -```js -//addslot回调 -function addSlotCallBack(err) { - console.info("==========================>addSlotCallBack=======================>"); -} -//通知slot对象 -var notificationSlot = { - type: Notification.SlotType.SOCIAL_COMMUNICATION -} -Notification.addSlot(notificationSlot, addSlotCallBack) -``` - - - -## Notification.addSlot(slot: NotificationSlot) - -- 接口说明 - - 创建通知通道(Promise形式) - -- addSlot参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ---- | -------- | ---------------- | ---- | -------------------- | -| slot | 只读 | NotificationSlot | 是 | 要创建的通知通道对象 | - -- 返回值 - - Promise\ - -- 示例 - -```js -//通知slot对象 -var notificationSlot = { - type: Notification.SlotType.SOCIAL_COMMUNICATION -} -Notification.addSlot(notificationSlot).then((void) => { - console.info("==========================>addSlotCallback=======================>"); -}); -``` - - - -## Notification.addSlot(type: SlotType, callback: AsyncCallback\) - -- 接口说明 - - 创建通知通道(callback形式) - -- addSlot参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------- | -------- | --------------------- | ---- | ---------------------- | -| type | 只读 | SlotType | 是 | 要创建的通知通道的类型 | -| callback | 只读 | AsyncCallback\ | 是 | 表示被指定的回调方法 | - -- 返回值 - - void - -- 示例 - -```js -//addslot回调 -function addSlotCallBack(err) { - console.info("==========================>addSlotCallBack=======================>"); -} -Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION, addSlotCallBack) -``` - - - -## Notification.addSlot(type: SlotType) - -- 接口说明 - - 创建通知通道(Promise形式) - -- addSlot参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ---- | -------- | -------- | ---- | ---------------------- | -| type | 只读 | SlotType | 是 | 要创建的通知通道的类型 | - -- 返回值 - - Promise\ - -- 示例 - -```js -Notification.addSlot(Notification.SlotType.SOCIAL_COMMUNICATION).then((void) => { - console.info("==========================>addSlotCallback=======================>"); -}); -``` - - - -## Notification.addSlots(slots: Array\, callback: AsyncCallback\) - -- 接口说明 - - 创建多个通知通道(callback形式) - -- addSlots数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------- | -------- | ------------------------- | ---- | ------------------------ | -| slots | 只读 | Array\ | 是 | 要创建的通知通道对象数组 | -| callback | 只读 | AsyncCallback\ | 是 | 表示被指定的回调方法 | - -- 返回值 - - void - -- 示例 - -```js -//addSlots回调 -function addSlotsCallBack(err) { - console.info("==========================>addSlotsCallBack=======================>"); -} -//通知slot对象 -var notificationSlot = { - type: Notification.SlotType.SOCIAL_COMMUNICATION -} -//通知slot array 对象 -var notificationSlotArray = new Array(); -notificationSlotArray[0] = notificationSlot; - -Notification.addSlots(notificationSlotArray, addSlotsCallBack) -``` - - - -## Notification.addSlots(slots: Array\) - -- 接口说明 - - 创建多个通知通道(Promise形式) - -- addSlots数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ----- | -------- | ------------------------- | ---- | ------------------------ | -| slots | 只读 | Array\ | 是 | 要创建的通知通道对象数组 | - -- 返回值 - - Promise\ - -- 示例 - -```js -//通知slot对象 -var notificationSlot = { - type: Notification.SlotType.SOCIAL_COMMUNICATION -} -//通知slot array 对象 -var notificationSlotArray = new Array(); -notificationSlotArray[0] = notificationSlot; - -Notification.addSlots(notificationSlotArray).then((void) => { - console.info("==========================>addSlotCallback=======================>"); -}); -``` - - - -## Notification.getSlot(slotType: SlotType, callback: AsyncCallback\) - -- 接口说明 - - 获取一个通知通道(callback形式) - -- getSlot参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------- | -------- | --------------------------------- | ---- | ----------------------------------------------------------- | -| slotType | 只读 | slotType | 是 | 通知渠道类型,目前分为社交通信、服务提醒、内容咨询和其他类型 | -| callback | 只读 | AsyncCallback\ | 是 | 表示被指定的回调方法 | - -- 返回值 - - void - -- 示例 - -```js -//getSlot回调 -function getSlotCallback(err,data) { - console.info("==========================>getSlotCallback=======================>"); -} -var slotType = Notification.SlotType.SOCIAL_COMMUNICATION; -Notification.getSlot(slotType, getSlotCallback) -``` - - - -## Notification.getSlot(slotType) - -- 接口说明 - - 获取一个通知通道(Promise形式) - -- getSlot参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------- | -------- | -------- | ---- | ----------------------------------------------------------- | -| slotType | 只读 | slotType | 是 | 通知渠道类型,目前分为社交通信、服务提醒、内容咨询和其他类型 | - -- 返回值 - - Promise\ - -- 示例 - -```js -var slotType = Notification.SlotType.SOCIAL_COMMUNICATION; -Notification.getSlot(slotType).then((data) => { - console.info("==========================>getSlotCallback=======================>"); -}); -``` - - - -## Notification.getSlots(callback: AsyncCallback>) - -- 接口说明 - - 获取此应用程序的所有通知通道(callback形式) - -- getSlots参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------- | -------- | --------------------------------- | ---- | -------------------- | -| callback | 只读 | AsyncCallback\ | 是 | 表示被指定的回调方法 | - -- 返回值 - - void - -- 示例 - -```js -//getSlots回调 -function getSlotsCallback(err,data) { - console.info("==========================>getSlotsCallback=======================>"); -} -Notification.getSlots(getSlotsCallback) -``` - - - -## Notification.getSlots() - -- 接口说明 - - 获取此应用程序的所有通知通道(Promise形式) - -- getSlots参数描述 - - 无参数 - -- 返回值 - - Promise\\> - -- 示例 - -```js -Notification.getSlots().then((data) => { - console.info("==========================>getSlotsCallback=======================>"); -}); -``` - - - -## Notification.removeSlot(slotType: SlotType, callback: AsyncCallback\) - -- 接口说明 - - 根据通知通道类型删除创建的通知通道(callback形式) - -- removeSlot参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------- | -------- | --------------------- | ---- | ----------------------------------------------------------- | -| SlotType | 只读 | SlotType | 是 | 通知渠道类型,目前分为社交通信、服务提醒、内容咨询和其他类型 | -| callback | 只读 | AsyncCallback\ | 是 | 表示被指定的回调方法 | - -- 返回值 - - void - -- 示例 - -```js -//removeSlot回调 -function removeSlotCallback(err) { - console.info("==========================>removeSlotCallback=======================>"); -} -var slotType = Notification.SlotType.SOCIAL_COMMUNICATION; -Notification.removeSlot(slotType,removeSlotCallback) -``` - - - -## Notification.removeSlot(slotType: SlotType) - -- 接口说明 - - 根据通知通道类型删除创建的通知通道(Promise形式) - -- removeSlot参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------- | -------- | -------- | ---- | ----------------------------------------------------------- | -| SlotType | 只读 | SlotType | 是 | 通知渠道类型,目前分为社交通信、服务提醒、内容咨询和其他类型 | - -- 返回值 - - Promise\ - -- 示例 - -```js -var slotType = Notification.SlotType.SOCIAL_COMMUNICATION; -Notification.removeSlot(slotType).then((void) => { - console.info("==========================>removeSlotCallback=======================>"); -}); -``` - - - -## Notification.removeAllSlots(callback: AsyncCallback\) - -- 接口说明 - - 删除所有通知通道(callback形式) - -- removeAllSlots参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------- | -------- | --------------------- | ---- | -------------------- | -| callback | 只读 | AsyncCallback\ | 是 | 表示被指定的回调方法 | - -- 返回值 - - void - -- 示例 - -```js -function removeAllCallBack(err) { - console.info("================>removeAllCallBack=======================>"); -} -Notification.removeAllSlots(removeAllCallBack) -``` - - - -## Notification.removeAllSlots() - -- 接口说明 - - 删除所有通知通道(Promise形式) - -- removeAllSlots参数描述 - - 参数无 - -- 返回值 - - Promise\ - -- 示例 - -```js -Notification.removeAllSlots().then((void) => { - console.info("==========================>removeAllCallBack=======================>"); -}); -``` - - - -## Notification.subscribe(subscriber: NotificationSubscriber, info: NotificationSubscribeInfo, callback: AsyncCallback\) - -- 接口说明 - - 订阅通知并指定订阅信息(callback形式) - -- subscribe参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ---------- | -------- | ------------------------- | ---- | ---------------- | -| subscriber | 只读 | NotificationSubscriber | 是 | 通知订阅对象 | -| info | 只读 | NotificationSubscribeInfo | 是 | 订阅信息 | -| callback | 只读 | AsyncCallback\ | 是 | 订阅动作回调函数 | - -- NotificationSubscriber类型说明 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ------------------------------------------------------------ | -------- | -------- | ---- | -------------------------- | -| onConsume?:(data: SubscribeCallbackData) | 读、写 | function | 否 | 接收通知回调函数 | -| onCancel?:(data: SubscribeCallbackData) | 读、写 | function | 否 | 删除通知回调函数 | -| onUpdate?:(data: NotificationSortingMap) | 读、写 | function | 否 | 更新通知排序回调函数 | -| onConnect?:() | 读、写 | function | 否 | 注册订阅回调函数 | -| onDisconnect?:() | 读、写 | function | 否 | 取消订阅回调函数 | -| onDestroy?:() | 读、写 | function | 否 | 服务失联回调函数 | -| onDoNotDisturbDateChange?:(mode: notification.DoNotDisturbDate) | 读、写 | function | 否 | 免打扰时间选项变更回调函数 | - -- SubscribeCallbackData 类型说明 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| --------------- | -------- | ---------------------- | ---- | -------- | -| request | 只读 | NotificationRequest | 是 | 通知内容 | -| sortingMap | 只读 | NotificationSortingMap | 否 | 排序信息 | -| reason | 只读 | number | 否 | 删除原因 | -| sound | 只读 | string | 否 | 通知声音 | -| vibrationValues | 只读 | Array\ | 否 | 通知震动 | - -- NotificationSortingMap类型说明 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------------- | -------- | ------------------------------------ | ---- | ---------------- | -| sortings | 只读 | {[key: string]: NotificationSorting} | 是 | 通知排序信息数组 | -| sortedHashCode | 只读 | Array\ | 是 | 通知唯一标识数组 | - -- NotificationSorting 类型说明 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------- | -------- | ---------------- | ---- | ------------ | -| slot | 只读 | NotificationSlot | 是 | 通知通道内容 | -| hashCode | 只读 | string | 是 | 通知唯一标识 | -| ranking | 只读 | number | 是 | 通知排序序号 | - -- DoNotDisturbType类型说明 - - -| 名称 | 读写属性 | 类型 | 描述 | -| ------------ | -------- | --------------------- | ---------------------------------------- | -| TYPE_NONE | 只读 | enum DoNotDisturbType | 非通知勿扰类型 | -| TYPE_ONCE | 只读 | enum DoNotDisturbType | 以设置时间段(只看小时和分钟)一次执行勿扰 | -| TYPE_DAILY | 只读 | enum DoNotDisturbType | 以设置时间段(只看小时和分钟)每天执行勿扰 | -| TYPE_CLEARLY | 只读 | enum DoNotDisturbType | 以设置时间段(明确年月日时分)执行勿扰 | - -- DoNotDisturbDate类型说明 - -| 名称 | 读写属性 | 类型 | 描述 | -| ----- | -------- | ---------------- | ------------------------ | -| type | 读写 | DoNotDisturbType | 指定免打扰设置的时间类型 | -| begin | 读写 | Date | 指定免打扰设置的起点时间 | -| end | 读写 | Date | 指定免打扰设置的终点时间 | - -- NotificationSubscribeInfo类型说明 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ----------- | -------- | --------------- | ---- | ------------------------------- | -| bundleNames | 读、写 | Array\ | 否 | 指定订阅哪些包名的APP发来的通知 | -| userId | 读、写 | number | 否 | 指定订阅哪个用户下发来的通知 | - -- 返回值 - - void - -- 示例 - -```js -//subscribe回调 -function subscribeCallback(err) { - console.info("==========================>subscribeCallback=======================>"); -} -function onConsumeCallback(err, data) { - console.info("==========================>onConsumeCallback=======================>"); -} -var subscriber = { - onConsume: onConsumeCallback -} -var info = { - bundleNames: ["bundleName1","bundleName2"] -} -Notification.subscribe(subscriber, info, subscribeCallback); -``` - - - -## Notification.subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\) - -- 接口说明 - - 订阅通知并指定订阅信息(callback形式) - -- subscribe参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ---------- | -------- | ---------------------- | ---- | ---------------- | -| subscriber | 只读 | NotificationSubscriber | 是 | 通知订阅对象 | -| callback | 只读 | AsyncCallback\ | 是 | 订阅动作回调函数 | - -- 返回值 - - void - -- 示例 - -```js -function subscribeCallback(err) { - console.info("==========================>subscribeCallback=======================>"); -} -function onConsumeCallback(err, data) { - console.info("==========================>onConsumeCallback=======================>"); -} -var subscriber = { - onConsume: onConsumeCallback -} -Notification.subscribe(subscriber, subscribeCallback); -``` - - - -## Notification.subscribe(subscriber: NotificationSubscriber, info?: NotificationSubscribeInfo) - -- 接口说明 - - 订阅通知并指定订阅信息(Promise形式) - -- subscribe参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ---------- | -------- | ------------------------- | ---- | ------------ | -| subscriber | 只读 | NotificationSubscriber | 是 | 通知订阅对象 | -| info | 只读 | NotificationSubscribeInfo | 否 | 订阅信息 | - -- 返回值 - - Promise\ - -- 示例 - -```js -function onConsumeCallback(err, data) { - console.info("==========================>onConsumeCallback=======================>"); -} -var subscriber = { - onConsume: onConsumeCallback -}; -Notification.subscribe(subscriber).then((void) => { - console.info("==========================>subscribeCallback=======================>"); -}); -``` - - - -## Notification.unsubscribe(subscriber: NotificationSubscriber, callback: AsyncCallback\) - -- 接口说明 - - 取消订阅(callbcak形式) - -- unsubscribe参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ---------- | -------- | ---------------------- | ---- | -------------------- | -| subscriber | 只读 | NotificationSubscriber | 是 | 通知订阅对象 | -| callback | 只读 | AsyncCallback\ | 是 | 取消订阅动作回调函数 | - -- 返回值 - - void - -- 示例 - -```js -function unsubscribeCallback(err) { - console.info("==========================>unsubscribeCallback=======================>"); -} -function onConsumeCallback(err, data) { - console.info("==========================>onConsumeCallback=======================>"); -} -var subscriber = { - onConsume: onConsumeCallback -} -Notification.unsubscribe(subscriber, unsubscribeCallback); -``` - - - -## Notification.unsubscribe(subscriber: NotificationSubscriber) - -- 接口说明 - - 取消订阅(Promise形式) - -- unsubscribe参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ---------- | -------- | ---------------------- | ---- | ------------ | -| subscriber | 只读 | NotificationSubscriber | 是 | 通知订阅对象 | - -- 返回值 - - Promise\ - -- 示例 - -```js -function onConsumeCallback(err, data) { - console.info("==========================>onConsumeCallback=======================>"); -} -var subscriber = { - onConsume: onConsumeCallback -}; -Notification.unsubscribe(subscriber).then((void) => { - console.info("==========================>unsubscribeCallback=======================>"); -}); -``` - - - -## Notification.enableNotification(bundle: BundleOption, enable: boolean, callback: AsyncCallback\) - -- 接口说明 - - 设定指定包的通知使能状态(Callback形式) - -- enableNotification参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------- | -------- | --------------------- | ---- | -------------------- | -| bundle | 只读 | BundleOption | 是 | 指定包信息 | -| enable | 只读 | boolean | 是 | 使能状态 | -| callback | 只读 | AsyncCallback\ | 是 | 设定通知使能回调函数 | - -- BundleOption类型说明 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ------ | -------- | ------ | ---- | ------ | -| bundle | 读/写 | string | 是 | 包名 | -| uid | 读/写 | number | 否 | 用户id | -- 返回值 - - void - -- 示例 - -```js -function enableNotificationCallback(err) { - console.info("==========================>enableNotificationCallback=======================>"); -} -var bundle = { - bundle: "bundleName1"; -} -Notification.enableNotification(bundle, false, enableNotificationCallback); -``` - - - -## Notification.enableNotification(bundle: BundleOption, enable: boolean) - -- 接口说明 - - 设定指定包的通知使能状态(Promise形式) - -- enableNotification参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ------ | -------- | ------------ | ---- | ---------- | -| bundle | 只读 | BundleOption | 是 | 指定包信息 | -| enable | 只读 | boolean | 是 | 使能状态 | - -- 返回值 - - Promise\ - -- 示例 - -```js -var bundle = { - bundle: "bundleName1"; -} -Notification.enableNotification(bundle, false).then((void) => { - console.info("==========================>enableNotificationCallback=======================>"); -}); -``` - - - -## Notification.isNotificationEnabled(bundle: BundleOption, callback: AsyncCallback\) - -- 接口说明 - - 获取指定包的通知使能状态(Callback形式) - -- isNotificationEnabled参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------- | -------- | --------------------- | ---- | ------------------------ | -| bundle | 只读 | BundleOption | 是 | 指定包信息 | -| callback | 只读 | AsyncCallback\ | 是 | 获取通知使能状态回调函数 | - -- 返回值 - - void - -- 示例 - -```js -function isNotificationEnabledCallback(err, data) { - console.info("==========================>isNotificationEnabledCallback=======================>"); -} -var bundle = { - bundle: "bundleName1"; -} -Notification.isNotificationEnabled(bundle, isNotificationEnabledCallback); -``` - - - -## Notification.isNotificationEnabled(bundle: BundleOption) - -- 接口说明 - - 获取指定包的通知使能状态(Promise形式) - -- isNotificationEnabled参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ------ | -------- | ------------ | ---- | ---------- | -| bundle | 只读 | BundleOption | 是 | 指定包信息 | - -- 返回值 - - Promise\ - -- 示例 - -```js -var bundle = { - bundle: "bundleName1"; -} -Notification.isNotificationEnabled(bundle).then((data) => { - console.info("==========================>isNotificationEnabledCallback=======================>"); -}); -``` - - - -## Notification.isNotificationEnabled(callback: AsyncCallback\) - -- 接口说明 - - 获取通知使能状态(Callback形式) - -- isNotificationEnabled参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------- | -------- | --------------------- | ---- | ------------------------ | -| callback | 只读 | AsyncCallback\ | 是 | 获取通知使能状态回调函数 | - -- 返回值 - - void - -- 示例 - -```js -function isNotificationEnabledCallback(err, data) { - console.info("==========================>isNotificationEnabledCallback=======================>"); -} - -Notification.isNotificationEnabled(isNotificationEnabledCallback); -``` - - - -## Notification.isNotificationEnabled() - -- 接口说明 - - 获取通知使能状态(Promise形式) - -- isNotificationEnabled参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ------ | -------- | ------------ | ---- | ---------- | -| bundle | 只读 | BundleOption | 是 | 指定包信息 | - -- 返回值 - - Promise\ - -- 示例 - -```js -Notification.isNotificationEnabled().then((data) => { - console.info("==========================>isNotificationEnabledCallback=======================>"); -}); -``` - - - -## Notification.displayBadge(bundle: BundleOption, enable: boolean, callback: AsyncCallback\) - -- 接口说明 - - 设定指定包的角标使能状态(Callback形式) - -- displayBadge参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------- | -------- | --------------------- | ---- | -------------------- | -| bundle | 只读 | BundleOption | 是 | 指定包信息 | -| enable | 只读 | boolean | 是 | 使能状态 | -| callback | 只读 | AsyncCallback\ | 是 | 设定角标使能回调函数 | - -- 返回值 - - void - -- 示例 - -```js -function displayBadgeCallback(err) { - console.info("==========================>displayBadgeCallback=======================>"); -} -var bundle = { - bundle: "bundleName1"; -} -Notification.displayBadge(bundle, false, displayBadgeCallback); -``` - - - -## Notification.displayBadge(bundle: BundleOption, enable: boolean) - -- 接口说明 - - 设定指定包的角标使能状态(Promise形式) - -- displayBadge参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ------ | -------- | ------------ | ---- | ---------- | -| bundle | 只读 | BundleOption | 是 | 指定包信息 | -| enable | 只读 | boolean | 是 | 使能状态 | - -- 返回值 - - Promise\ - -- 示例 - -```js -var bundle = { - bundle: "bundleName1"; -} -Notification.displayBadge(bundle, false).then((void) => { - console.info("==========================>displayBadgeCallback=======================>"); -}); -``` - - - -## Notification.isBadgeDisplayed(bundle: BundleOption, callback: AsyncCallback\) - -- 接口说明 - - 获取指定包的角标使能状态(Callback形式) - -- isBadgeDisplayed参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------- | -------- | --------------------- | ---- | ------------------------ | -| bundle | 只读 | BundleOption | 是 | 指定包信息 | -| callback | 只读 | AsyncCallback\ | 是 | 获取角标使能状态回调函数 | - -- 返回值 - - void - -- 示例 - -```js -function isBadgeDisplayedCallback(err, data) { - console.info("==========================>isBadgeDisplayedCallback=======================>"); -} -var bundle = { - bundle: "bundleName1"; -} -Notification.isBadgeDisplayed(bundle, isBadgeDisplayedCallback); -``` - - - -## Notification.isBadgeDisplayed(bundle: BundleOption) - -- 接口说明 - - 获取指定包的角标使能状态(Promise形式) - -- isBadgeDisplayed参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ------ | -------- | ------------ | ---- | ---------- | -| bundle | 只读 | BundleOption | 是 | 指定包信息 | - -- 返回值 - - Promise\ - -- 示例 - -```js -var bundle = { - bundle: "bundleName1"; -} -Notification.isBadgeDisplayed(bundle).then((data) => { - console.info("==========================>isBadgeDisplayedCallback=======================>"); -}); -``` - - - -## Notification.setSlotByBundle(bundle: BundleOption, slot: NotificationSlot, callback: AsyncCallback\) - -- 接口说明 - - 设定指定包的通知通道状态(Callback形式) - -- setSlotByBundle参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------- | -------- | --------------------- | ---- | -------------------- | -| bundle | 只读 | BundleOption | 是 | 指定包信息 | -| slot | 只读 | NotificationSlot | 是 | 通知通道 | -| callback | 只读 | AsyncCallback\ | 是 | 设定通知通道回调函数 | - -- 返回值 - - void - -- 示例 - -```js -function setSlotByBundleCallback(err) { - console.info("==========================>setSlotByBundleCallback=======================>"); -} -var bundle = { - bundle: "bundleName1"; -} -var notificationSlot = { - type: Notification.SlotType.SOCIAL_COMMUNICATION -} -Notification.setSlotByBundle(bundle, notificationSlot, setSlotByBundleCallback); -``` - - - -## Notification.setSlotByBundle(bundle: BundleOption, slot: NotificationSlot) - -- 接口说明 - - 设定指定包的角标使能状态(Promise形式) - -- setSlotByBundle参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ------ | -------- | ------------ | ---- | ---------- | -| bundle | 只读 | BundleOption | 是 | 指定包信息 | -| enable | 只读 | boolean | 是 | 使能状态 | - -- 返回值 - - Promise\ - -- 示例 - -```js -var bundle = { - bundle: "bundleName1"; -} -var notificationSlot = { - type: Notification.SlotType.SOCIAL_COMMUNICATION -} -Notification.displayBadge(bundle, notificationSlot).then((void) => { - console.info("==========================>setSlotByBundleCallback=======================>"); -}); -``` - - - -## Notification.getSlotsByBundle(bundle: BundleOption, callback: AsyncCallback>) - -- 接口说明 - - 获取指定包的通知通道(Callback形式) - -- getSlotsByBundle参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------- | -------- | ---------------------------------------- | ---- | -------------------- | -| bundle | 只读 | BundleOption | 是 | 指定包信息 | -| callback | 只读 | AsyncCallback> | 是 | 获取通知通道回调函数 | - -- 返回值 - - void - -- 示例 - -```js -function getSlotsByBundleCallback(err, data) { - console.info("==========================>getSlotsByBundleCallback=======================>"); -} -var bundle = { - bundle: "bundleName1"; -} -Notification.getSlotsByBundle(bundle, getSlotsByBundleCallback); -``` - - - -## Notification.getSlotsByBundle(bundle: BundleOption) - -- 接口说明 - - 获取指定包的通知通道(Promise形式) - -- getSlotsByBundle参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ------ | -------- | ------------ | ---- | ---------- | -| bundle | 只读 | BundleOption | 是 | 指定包信息 | - -- 返回值 - - Promise> - -- 示例 - -```js -var bundle = { - bundle: "bundleName1"; -} -Notification.getSlotsByBundle(bundle).then((data) => { - console.info("==========================>getSlotsByBundleCallback=======================>"); -}); -``` - - - -## Notification.getSlotNumByBundle(bundle: BundleOption, callback: AsyncCallback\) - -- 接口说明 - - 获取指定包的通知通道数(Callback形式) - -- getSlotNumByBundle参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------- | -------- | ------------------------- | ---- | ---------------------- | -| bundle | 只读 | BundleOption | 是 | 指定包信息 | -| callback | 只读 | AsyncCallback\ | 是 | 获取通知通道数回调函数 | - -- 返回值 - - void - -- 示例 - -```js -function getSlotNumByBundle(err, data) { - console.info("==========================>getSlotNumByBundleCallback=======================>"); -} -var bundle = { - bundle: "bundleName1"; -} -Notification.getSlotNumByBundle(bundle, getSlotNumByBundleCallback); -``` - - - -## Notification.getSlotNumByBundle(bundle: BundleOption) - -- 接口说明 - - 获取指定包的通知通道数(Promise形式) - -- getSlotNumByBundle参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ------ | -------- | ------------ | ---- | ---------- | -| bundle | 只读 | BundleOption | 是 | 指定包信息 | - -- 返回值 - - Promise\ - -- 示例 - -```js -var bundle = { - bundle: "bundleName1"; -} -Notification.getSlotNumByBundle(bundle).then((data) => { - console.info("==========================>getSlotNumByBundleCallback=======================>"); -}); -``` - - - -## Notification.remove(bundle: BundleOption, notificationKey: NotificationKey, callback: AsyncCallback\) - -- 接口说明 - - 删除指定通知(Callback形式) - -- remove参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| --------------- | -------- | --------------------- | ---- | -------------------- | -| bundle | 只读 | BundleOption | 是 | 指定包信息 | -| notificationKey | 只读 | NotificationKey | 是 | 通知键值 | -| callback | 只读 | AsyncCallback\ | 是 | 删除指定通知回调函数 | - -- NotificationKey类型说明 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ----- | -------- | ------ | ---- | -------- | -| id | 读、写 | number | 是 | 通知ID | -| label | 读、写 | string | 否 | 通知标签 | - -- 返回值 - - void - -- 示例 - -```js -function removeCallback(err) { - console.info("==========================>removeCallback=======================>"); -} -var bundle = { - bundle: "bundleName1"; -} -var notificationKey = { - id: 0; - label: "label"; -} -Notification.remove(bundle, notificationKey, removeCallback); -``` - - - -## Notification.remove(bundle: BundleOption, notificationKey: NotificationKey) - -- 接口说明 - - 删除指定通知(Promise形式) - -- remove参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| --------------- | -------- | --------------- | ---- | ---------- | -| bundle | 只读 | BundleOption | 是 | 指定包信息 | -| notificationKey | 只读 | NotificationKey | 是 | 通知键值 | - -- 返回值 - - Promise\ - -- 示例 - -```js -var bundle = { - bundle: "bundleName1"; -} -var notificationKey = { - id: 0; - label: "label"; -} -Notification.remove(bundle, notificationKey).then((void) => { - console.info("==========================>removeCallback=======================>"); -}); -``` - - - -## Notification.remove(hashCode: string, callback: AsyncCallback\) - -- 接口说明 - - 删除指定通知(Callback形式) - -- remove参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------- | -------- | --------------------- | ---- | -------------------- | -| hashCode | 只读 | string | 是 | 通知唯一ID | -| callback | 只读 | AsyncCallback\ | 是 | 删除指定通知回调函数 | - -- 返回值 - - void - -- 示例 - -```js -function removeCallback(err) { - console.info("==========================>removeCallback=======================>"); -} - -Notification.remove(hashCode, removeCallback); -``` - - - -## Notification.remove(hashCode: string) - -- 接口说明 - - 删除指定通知(Promise形式) - -- remove参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------- | -------- | ---------- | ---- | ---------- | -| hashCode | 只读 | string | 是 | 通知唯一ID | - -- 返回值 - - Promise\ - -- 示例 - -```js -Notification.remove(hashCode).then((void) => { - console.info("==========================>removeCallback=======================>"); -}); -``` - - - -## Notification.removeAll(bundle: BundleOption, callback: AsyncCallback\) - -- 接口说明 - - 删除指定包的所有通知(Callback形式) - -- removeAll参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------- | -------- | --------------------- | ---- | ---------------------------- | -| bundle | 只读 | BundleOption | 是 | 指定包信息 | -| callback | 只读 | AsyncCallback\ | 是 | 删除指定包的所有通知回调函数 | - -- 返回值 - - void - -- 示例 - -```js -function removeAllCallback(err) { - console.info("==========================>removeAllCallback=======================>"); -} -var bundle = { - bundle: "bundleName1"; -} -Notification.removeAll(bundle, removeAllCallback); -``` - - - -## Notification.removeAll(callback: AsyncCallback\) - -- 接口说明 - - 删除所有通知(Callback形式) - -- removeAll参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------- | -------- | --------------------- | ---- | -------------------- | -| callback | 只读 | AsyncCallback\ | 是 | 删除所有通知回调函数 | - -- 返回值 - - void - -- 示例 - -```js -function removeAllCallback(err) { - console.info("==========================>removeAllCallback=======================>"); -} - -Notification.removeAll(removeAllCallback); -``` - - - -## Notification.removeAll(bundle?: BundleOption) - -- 接口说明 - - 删除所有通知(Promise形式) - -- removeAll参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ------ | -------- | ------------ | ---- | ---------- | -| bundle | 只读 | BundleOption | 否 | 指定包信息 | - -- 返回值 - - Promise\ - -- 示例 - -```js -Notification.removeAll().then((void) => { - console.info("==========================>removeAllCallback=======================>"); -}); -``` - - - -## Notification.getAllActiveNotifications(callback: AsyncCallback>) - -- 接口说明 - - 获取活动通知(Callback形式) - -- getAllActiveNotifications参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------- | -------- | ------------------------------------------- | ---- | -------------------- | -| callback | 只读 | AsyncCallback> | 是 | 获取活动通知回调函数 | - -- 返回值 - - void - -- 示例 - -```js -function getAllActiveNotificationsCallback(err, data) { - console.info("==========================>getAllActiveNotificationsCallback=======================>"); -} - -Notification.getAllActiveNotifications(getAllActiveNotificationsCallback); -``` - - - -## Notification.getAllActiveNotifications() - -- 接口说明 - - 获取活动通知(Promise形式) - -- getAllActiveNotifications参数描述 - - 无 - -- 返回值 - - Promise\\> - -- 示例 - -```js -Notification.getAllActiveNotifications().then((data) => { - console.info("==========================>getAllActiveNotificationsCallback=======================>"); -}); -``` - - - -## Notification.getActiveNotificationCount(callback: AsyncCallback\) - -- 接口说明 - - 获取当前应用的活动通知数(Callback形式) - -- getActiveNotificationCount参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------- | -------- | ---------------------- | ---- | ---------------------- | -| callback | 只读 | AsyncCallback\ | 是 | 获取活动通知数回调函数 | - -- 返回值 - - void - -- 示例 - -```js -function getActiveNotificationCountCallback(err, data) { - console.info("==========================>getActiveNotificationCountCallback=======================>"); -} - -Notification.getActiveNotificationCount(getActiveNotificationCountCallback); -``` - - - -## Notification.getActiveNotificationCount() - -- 接口说明 - - 获取当前应用的活动通知数(Promise形式) - -- getActiveNotificationCount参数描述 - - 无 - -- 返回值 - - 返回值为Promise\ - -- 示例 - -```js -Notification.getActiveNotificationCount().then((data) => { - console.info("==========================>getActiveNotificationCountCallback=======================>"); -}); -``` - - - -## Notification.getActiveNotifications(callback: AsyncCallback>) - -- 接口说明 - - 获取当前应用的活动通知(Callback形式) - -- getActiveNotifications参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------- | -------- | ------------------------------------------- | ---- | ------------------------------ | -| callback | 只读 | AsyncCallback> | 是 | 获取当前应用的活动通知回调函数 | - -- 返回值 - - void - -- 示例 - -```js -function getActiveNotificationsCallback(err, data) { - console.info("==========================>getActiveNotificationsCallback=======================>"); -} - -Notification.getActiveNotifications(getActiveNotificationsCallback); -``` - - - -## Notification.getActiveNotifications() - -- 接口说明 - - 获取当前应用的活动通知(Promise形式) - -- getActiveNotifications参数描述 - - 无 - -- 返回值 - - Promise\\> - -- 示例 - -```js -Notification.getActiveNotifications().then((data) => { - console.info("==========================>getActiveNotificationsCallback=======================>"); -}); -``` - - - -## Notification.cancelGroup(groupName: string, callback: AsyncCallback\) - -- 接口说明 - - 取消本应用指定组通知(Callback形式) - -- cancelGroup参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| --------- | -------- | --------------------- | ---- | ---------------------------- | -| groupName | 只读 | string | 是 | 指定通知组名称 | -| callback | 只读 | AsyncCallback\ | 是 | 取消本应用指定组通知回调函数 | - -- 返回值 - - void - -- 示例 - -```js -function cancelGroupCallback(err) { - console.info("==========================>cancelGroupCallback=======================>"); -} - -var groupName = "GroupName"; - -Notification.cancelGroup(groupName, cancelGroupCallback); -``` - - - -## Notification.cancelGroup(groupName: string) - -- 接口说明 - - 取消本应用指定组通知(Promise形式) - -- cancelGroup参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| --------- | -------- | ------ | ---- | -------------- | -| groupName | 只读 | string | 是 | 指定通知组名称 | - -- 返回值 - - Promise\ - -- 示例 - -```js -var groupName = "GroupName"; -Notification.cancelGroup(groupName).then(() => { - console.info("==========================>cancelGroupPromise=======================>"); -}); -``` - - - -## Notification.removeGroupByBundle(bundle: BundleOption, groupName: string, callback: AsyncCallback\) - -- 接口说明 - - 删除指定应用指定组通知(Callback形式) - -- removeGroupByBundle参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| --------- | -------- | --------------------- | ---- | ---------------------------- | -| bundle | 只读 | BundleOption | 是 | 指定包信息 | -| groupName | 只读 | string | 是 | 指定通知组名称 | -| callback | 只读 | AsyncCallback\ | 是 | 删除本应用指定组通知回调函数 | - -- 返回值 - - void - -- 示例 - -```js -function removeGroupByBundleCallback(err) { - console.info("==========================>removeGroupByBundleCallback=======================>"); -} - -var bundleOption = {bundle: "Bundle"}; -var groupName = "GroupName"; - -Notification.removeGroupByBundle(bundleOption, groupName, removeGroupByBundleCallback); -``` - - - -## Notification.removeGroupByBundle(bundle: BundleOption, groupName: string) - -- 接口说明 - - 删除指定应用指定组通知(Promise形式) - -- removeGroupByBundle参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| --------- | -------- | ------------ | ---- | -------------- | -| bundle | 只读 | BundleOption | 是 | 指定包信息 | -| groupName | 只读 | string | 是 | 指定通知组名称 | - -- 返回值 - - Promise\ - -- 示例 - -```js -var bundleOption = {bundle: "Bundle"}; -var groupName = "GroupName"; -Notification.removeGroupByBundle(bundleOption, groupName).then(() => { - console.info("==========================>removeGroupByBundlePromise=======================>"); -}); -``` - - - -## Notification.setDoNotDisturbDate(date: DoNotDisturbDate, callback: AsyncCallback\) - -- 接口说明 - - 设置免打扰时间(Callback形式) - -- setDoNotDisturbDate参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------- | -------- | --------------------- | ---- | ---------------------- | -| date | 只读 | DoNotDisturbDate | 是 | 免打扰时间选项 | -| callback | 只读 | AsyncCallback\ | 是 | 设置免打扰时间回调函数 | - -- 返回值 - - void - -- 示例 - -```js -function setDoNotDisturbDateCallback(err) { - console.info("==========================>setDoNotDisturbDateCallback=======================>"); -} - -var doNotDisturbDate = { - type: notification.DoNotDisturbType.TYPE_ONCE, - begin: new Date(), - end: new Date(2021, 11, 15, 18, 0) -} - -Notification.setDoNotDisturbDate(doNotDisturbDate, setDoNotDisturbDateCallback); -``` - - - -## Notification.setDoNotDisturbDate(date: DoNotDisturbDate) - -- 接口说明 - - 设置免打扰时间接口(Promise形式) - -- setDoNotDisturbDate参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ---- | -------- | ---------------- | ---- | -------------- | -| date | 只读 | DoNotDisturbDate | 是 | 免打扰时间选项 | - -- 返回值 - - Promise\ - -- 示例 - -```js -var doNotDisturbDate = { - type: notification.DoNotDisturbType.TYPE_ONCE, - begin: new Date(), - end: new Date(2021, 11, 15, 18, 0) -} -Notification.setDoNotDisturbDate(doNotDisturbDate).then(() => { - console.info("==========================>setDoNotDisturbDatePromise=======================>"); -}); -``` - - - -## Notification.getDoNotDisturbDate(callback: AsyncCallback\) - -- 接口说明 - - 查询免打扰时间接口(Callback形式) - -- getDoNotDisturbDate参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------- | -------- | --------------------------------- | ---- | ---------------------- | -| callback | 只读 | AsyncCallback\ | 是 | 查询免打扰时间回调函数 | - -- 返回值 - - void - -- 示例 - -```js -function getDoNotDisturbDateCallback(err,data) { - console.info("==========================>getDoNotDisturbDateCallback=======================>"); -} - -Notification.getDoNotDisturbDate(getDoNotDisturbDateCallback); -``` - - - -## Notification.getDoNotDisturbDate() - -- 接口说明 - - 查询免打扰时间接口(Promise形式) - -- getDoNotDisturbDate参数描述 - - 无 - -- 返回值 - - Promise\ - -- 示例 - -```js -Notification.getDoNotDisturbDate().then((data) => { - console.info("==========================>getDoNotDisturbDatePromise=======================>"); -}); -``` - - - -## Notification.supportDoNotDisturbMode(callback: AsyncCallback\) - -- 接口说明 - - 查询是否支持勿扰模式功能(Callback形式) - -- supportDoNotDisturbMode参数描述 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------- | -------- | ------------------------ | ---- | -------------------------------- | -| callback | 只读 | AsyncCallback\ | 是 | 查询是否支持勿扰模式功能回调函数 | - -- 返回值 - - void - -- 示例 - -```js -function supportDoNotDisturbModeCallback(err,data) { - console.info("==========================>supportDoNotDisturbModeCallback=======================>"); -} - -Notification.supportDoNotDisturbMode(supportDoNotDisturbModeCallback); -``` - - - -## Notification.supportDoNotDisturbMode() - -- 接口说明 - - 查询是否支持勿扰模式功能(Promise形式) - -- supportDoNotDisturbMode参数描述 - - 无 - -- 返回值 - - Promise\ - -- 示例 - -```js -Notification.supportDoNotDisturbMode().then((data) => { - console.info("==========================>supportDoNotDisturbModePromise=======================>"); -}); -``` - - - -## Notification.isSupportTemplate - -isSupportTemplate(templateName: string, callback: AsyncCallback\): void - -查询模板是否存在。 - -- 参数 - -| 参数名 | 类型 | 必填 | 说明 | -| ------------ | ------------------------ | ---- | -------------------------- | -| templateName | string | 是 | 模板名称 | -| callback | AsyncCallback\ | 是 | 查询模板是否存在的回调函数 | - -- 示例 - -```javascript -var templateName = 'process'; -function isSupportTemplateCallback(err, data) { - console.info("isSupportTemplateCallback"); -} - -Notification.isSupportTemplate(templateName, isSupportTemplateCallback); -``` - - - -## Notification.isSupportTemplate - -isSupportTemplate(templateName: string): Promise\ - -查询模板是否存在。 - -- 参数 - -| 参数名 | 类型 | 必填 | 说明 | -| ------------ | ------ | ---- | -------- | -| templateName | string | 是 | 模板名称 | - -- 返回值 - -| 类型 | 说明 | -| ------------------ | --------------- | -| Promise\ | Promise方式返回 | - -- 示例 - -```javascript -var templateName = 'process'; - -Notification.isSupportTemplate(templateName).then((data) => { - console.info("isSupportTemplateCallback"); -}); -``` - - - -## NotificationTemplate - -模板信息 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| ---- | ---------------------- | ---- | ---- | -------- | -| name | string | 是 | 是 | 模板名称 | -| data | {[key:string]: Object} | 是 | 是 | 模板数据 | - - - -## WantAgent接口 - -## 导入模块 - -```js -import WantAgent from '@ohos.wantAgent'; -``` - -## WantAgent.getWantAgent(info: WantAgentInfo, callback: AsyncCallback\) - -- 接口说明 - - 创建WantAgent(callback形式) - -- getWantAgent参数描述 - - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------- | -------- | -------------------------- | ---- | ----------------------- | -| info | 只读 | WantAgentInfo | 是 | WantAgent信息 | -| callback | 只读 | AsyncCallback\ | 是 | 创建WantAgent的回调方法 | - -- WantAgentInfo类型说明 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------------- | -------- | ------------------------------- | ---- | ---------------------- | -| wants | 读、写 | Array\ | 是 | 将被执行的动作列表 | -| operationType | 读、写 | wantAgent.OperationType | 是 | 动作类型 | -| requestCode | 读、写 | number | 是 | 使用者定义的一个私有值 | -| wantAgentFlags | 读、写 | Array | 否 | 动作执行属性 | -| extraInfo | 读、写 | {[key: string]: any} | 否 | 额外数据 | - -- - WantAgentFlags类型说明 - - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ------------------- | -------- | ---- | ---- | ------------------------------------------------------------ | -| ONE_TIME_FLAG | 只读 | enum | 否 | WantAgent仅能使用一次 | -| NO_BUILD_FLAG | 只读 | enum | 否 | 如果描述WantAgent对象不存在,则不创建它,直接返回null | -| CANCEL_PRESENT_FLAG | 只读 | enum | 否 | 在生成一个新的WantAgent对象前取消已存在的一个WantAgent对象 | -| UPDATE_PRESENT_FLAG | 只读 | enum | 否 | 使用新的WantAgent的额外数据替换已存在的WantAgent中的额外数据 | -| CONSTANT_FLAG | 只读 | enum | 否 | WantAgent是不可变的 | - -- OperationType类型说明 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ----------------- | -------- | ---- | ---- | ----------------------- | -| UNKNOWN_TYPE | 只读 | enum | 否 | 不识别的类型 | -| START_ABILITY | 只读 | enum | 否 | 开启一个有页面的Ability | -| START_ABILITIES | 只读 | enum | 否 | 开启多个有页面的Ability | -| START_SERVICE | 只读 | enum | 否 | 开启一个无页面的ability | -| SEND_COMMON_EVENT | 只读 | enum | 否 | 发送一个公共事件 | - -- 返回值 - - void - -- 示例 - -```js -import WantAgent from '@ohos.wantAgent'; -import { OperationType, WantAgentFlags } from '@ohos.wantagent'; - -//getWantAgent回调 -function getWantAgentCallback(err, data) { - console.info("==========================>getWantAgentCallback=======================>"); -} -//WantAgentInfo对象 -var wantAgentInfo = { - wants: [ - { - deviceId: "deviceId", - bundleName: "com.neu.setResultOnAbilityResultTest1", - abilityName: "com.example.test.MainAbility", - action: "action1", - entities: ["entity1"], - type: "MIMETYPE", - uri: "key={true,true,false}", - parameters: - { - mykey0: 2222, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "ssssssssssssssssssssssssss", - mykey4: [false, true, false], - mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - mykey6: true, - } - } - ], - operationType: OperationType.START_ABILITIES, - requestCode: 0, - wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] -} - -WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) -``` - - - -## WantAgent.getWantAgent(info: WantAgentInfo): Promise\ - -- 接口说明 - - 创建WantAgent(Promise形式) - -- getWantAgent参数描述 - - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ---- | -------- | ------------- | ---- | ------------- | -| info | 只读 | WantAgentInfo | 是 | WantAgent信息 | - -- 返回值 - - Promise\ - -- 示例 - -```js -import WantAgent from '@ohos.wantAgent'; -import { OperationType, WantAgentFlags } from '@ohos.wantagent'; - -//WantAgentInfo对象 -var wantAgentInfo = { - wants: [ - { - deviceId: "deviceId", - bundleName: "com.neu.setResultOnAbilityResultTest1", - abilityName: "com.example.test.MainAbility", - action: "action1", - entities: ["entity1"], - type: "MIMETYPE", - uri: "key={true,true,false}", - parameters: - { - mykey0: 2222, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "ssssssssssssssssssssssssss", - mykey4: [false, true, false], - mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - mykey6: true, - } - } - ], - operationType: OperationType.START_ABILITIES, - requestCode: 0, - wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] -} - -WantAgent.getWantAgent(wantAgentInfo).then((data) => { - console.info("==========================>getWantAgentCallback=======================>"); -}); -``` - - - -## WantAgent.getBundleName(agent: WantAgent, callback: AsyncCallback\) - -- 接口说明 - - 获取WantAgent实例的包名(callback形式) - -- getBundleName参数描述 - - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------- | -------- | ----------------------- | ---- | --------------------------------- | -| agent | 只读 | WantAgent | 是 | WantAgent对象 | -| callback | 只读 | AsyncCallback\ | 是 | 获取WantAgent实例的包名的回调方法 | - -- 返回值 - - void - -- 示例 - -```js -import WantAgent from '@ohos.wantAgent'; -import { OperationType, WantAgentFlags } from '@ohos.wantagent'; - -//wantAgent对象 -var wantAgent; - -//getWantAgent回调 -function getWantAgentCallback(err, data) { - console.info("==========================>getWantAgentCallback=======================>"); - if (err.code == 0) { - wantAgent = data; - } else { - console.info('----getWantAgent failed!----'); - } -} -//WantAgentInfo对象 -var wantAgentInfo = { - wants: [ - { - deviceId: "deviceId", - bundleName: "com.neu.setResultOnAbilityResultTest1", - abilityName: "com.example.test.MainAbility", - action: "action1", - entities: ["entity1"], - type: "MIMETYPE", - uri: "key={true,true,false}", - parameters: - { - mykey0: 2222, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "ssssssssssssssssssssssssss", - mykey4: [false, true, false], - mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - mykey6: true, - } - } - ], - operationType: OperationType.START_ABILITIES, - requestCode: 0, - wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] -} - -WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) - -//getBundleName回调 -function getBundleNameCallback(err, data) { - console.info("==========================>getBundleNameCallback=======================>"); -} -WantAgent.getBundleName(wantAgent, getBundleNameCallback) -``` - - - -## WantAgent.getBundleName(agent: WantAgent): Promise\ - -- 接口说明 - - 获取WantAgent实例的包名(Promise形式) - -- getBundleName参数描述 - - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ----- | -------- | --------- | ---- | ------------- | -| agent | 只读 | WantAgent | 是 | WantAgent对象 | - -- 返回值 - - Promise\ - -- 示例 - -```js -import WantAgent from '@ohos.wantAgent'; -import { OperationType, WantAgentFlags } from '@ohos.wantagent'; - -//wantAgent对象 -var wantAgent; - -//WantAgentInfo对象 -var wantAgentInfo = { - wants: [ - { - deviceId: "deviceId", - bundleName: "com.neu.setResultOnAbilityResultTest1", - abilityName: "com.example.test.MainAbility", - action: "action1", - entities: ["entity1"], - type: "MIMETYPE", - uri: "key={true,true,false}", - parameters: - { - mykey0: 2222, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "ssssssssssssssssssssssssss", - mykey4: [false, true, false], - mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - mykey6: true, - } - } - ], - operationType: OperationType.START_ABILITIES, - requestCode: 0, - wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] -} - -WantAgent.getWantAgent(wantAgentInfo).then((data) => { - console.info("==========================>getWantAgentCallback=======================>"); - wantAgent = data; -}); - -WantAgent.getBundleName(wantAgent).then((data) => { - console.info("==========================>getBundleNameCallback=======================>"); -}); -``` - - - -## WantAgent.getUid(agent: WantAgent, callback: AsyncCallback\) - -- 接口说明 - - 获取WantAgent实例的用户ID(callback形式) - -- getUid参数描述 - - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------- | -------- | ----------------------- | ---- | ----------------------------------- | -| agent | 只读 | WantAgent | 是 | WantAgent对象 | -| callback | 只读 | AsyncCallback\ | 是 | 获取WantAgent实例的用户ID的回调方法 | - -- 返回值 - - void - -- 示例 - -```js -import WantAgent from '@ohos.wantAgent'; -import { OperationType, WantAgentFlags } from '@ohos.wantagent'; - -//wantAgent对象 -var wantAgent; - -//getWantAgent回调 -function getWantAgentCallback(err, data) { - console.info("==========================>getWantAgentCallback=======================>"); - if (err.code == 0) { - wantAgent = data; - } else { - console.info('----getWantAgent failed!----'); - } -} -//WantAgentInfo对象 -var wantAgentInfo = { - wants: [ - { - deviceId: "deviceId", - bundleName: "com.neu.setResultOnAbilityResultTest1", - abilityName: "com.example.test.MainAbility", - action: "action1", - entities: ["entity1"], - type: "MIMETYPE", - uri: "key={true,true,false}", - parameters: - { - mykey0: 2222, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "ssssssssssssssssssssssssss", - mykey4: [false, true, false], - mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - mykey6: true, - } - } - ], - operationType: OperationType.START_ABILITIES, - requestCode: 0, - wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] -} - -WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) - -//getUid回调 -function getUidCallback(err, data) { - console.info("==========================>getUidCallback=======================>"); -} -WantAgent.getUid(wantAgent, getUidCallback) -``` - - - -## WantAgent.getUid(agent: WantAgent): Promise\ - -- 接口说明 - - 获取WantAgent实例的用户ID(Promise形式) - -- getUid参数描述 - - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ----- | -------- | --------- | ---- | ------------- | -| agent | 只读 | WantAgent | 是 | WantAgent对象 | - -- 返回值 - - Promise\ - -- 示例 - -```js -import WantAgent from '@ohos.wantAgent'; -import { OperationType, WantAgentFlags } from '@ohos.wantagent'; - -//wantAgent对象 -var wantAgent; - -//WantAgentInfo对象 -var wantAgentInfo = { - wants: [ - { - deviceId: "deviceId", - bundleName: "com.neu.setResultOnAbilityResultTest1", - abilityName: "com.example.test.MainAbility", - action: "action1", - entities: ["entity1"], - type: "MIMETYPE", - uri: "key={true,true,false}", - parameters: - { - mykey0: 2222, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "ssssssssssssssssssssssssss", - mykey4: [false, true, false], - mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - mykey6: true, - } - } - ], - operationType: OperationType.START_ABILITIES, - requestCode: 0, - wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] -} - -WantAgent.getWantAgent(wantAgentInfo).then((data) => { - console.info("==========================>getWantAgentCallback=======================>"); - wantAgent = data; -}); - -WantAgent.getUid(wantAgent).then((data) => { - console.info("==========================>getUidCallback=======================>"); -}); -``` - - - -## WantAgent.getWant(agent: WantAgent, callback: AsyncCallback\) - -- 接口说明 - - 获取WantAgent对象的want(callback形式) - -- getWant参数描述 - - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------- | -------- | --------------------- | ---- | ------------------------------- | -| agent | 只读 | WantAgent | 是 | WantAgent对象 | -| callback | 只读 | AsyncCallback\ | 是 | 获取WantAgent对象want的回调方法 | - -- 返回值 - - void - -- 示例 - -```js -import WantAgent from '@ohos.wantAgent'; -import { OperationType, WantAgentFlags } from '@ohos.wantagent'; - -//wantAgent对象 -var wantAgent; - -//getWantAgent回调 -function getWantAgentCallback(err, data) { - console.info("==========================>getWantAgentCallback=======================>"); - if (err.code == 0) { - wantAgent = data; - } else { - console.info('----getWantAgent failed!----'); - } -} -//WantAgentInfo对象 -var wantAgentInfo = { - wants: [ - { - deviceId: "deviceId", - bundleName: "com.neu.setResultOnAbilityResultTest1", - abilityName: "com.example.test.MainAbility", - action: "action1", - entities: ["entity1"], - type: "MIMETYPE", - uri: "key={true,true,false}", - parameters: - { - mykey0: 2222, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "ssssssssssssssssssssssssss", - mykey4: [false, true, false], - mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - mykey6: true, - } - } - ], - operationType: OperationType.START_ABILITIES, - requestCode: 0, - wantAgentFlags:[WantAgentWantAgentFlags.UPDATE_PRESENT_FLAG] -} - -WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) - -//getWant回调 -function getWantCallback(err, data) { - console.info("==========================>getWantCallback=======================>"); -} -WantAgent.getWant(wantAgent, getWantCallback) -``` - - - -## WantAgent.getWant(agent: WantAgent): Promise\ - -- 接口说明 - - 获取WantAgent对象的want(Promise形式) - -- getWant参数描述 - - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ----- | -------- | --------- | ---- | ------------- | -| agent | 只读 | WantAgent | 是 | WantAgent对象 | - -- 返回值 - - Promise\ - -- 示例 - -```js -import WantAgent from '@ohos.wantAgent'; -import { OperationType, WantAgentFlags } from '@ohos.wantagent'; - -//wantAgent对象 -var wantAgent; - -//WantAgentInfo对象 -var wantAgentInfo = { - wants: [ - { - deviceId: "deviceId", - bundleName: "com.neu.setResultOnAbilityResultTest1", - abilityName: "com.example.test.MainAbility", - action: "action1", - entities: ["entity1"], - type: "MIMETYPE", - uri: "key={true,true,false}", - parameters: - { - mykey0: 2222, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "ssssssssssssssssssssssssss", - mykey4: [false, true, false], - mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - mykey6: true, - } - } - ], - operationType: OperationType.START_ABILITIES, - requestCode: 0, - wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] -} - -WantAgent.getWantAgent(wantAgentInfo).then((data) => { - console.info("==========================>getWantAgentCallback=======================>"); - wantAgent = data; -}); - -WantAgent.getWant(wantAgent).then((data) => { - console.info("==========================>getWantCallback=======================>"); -}); -``` - - - -## WantAgent.cancel(agent: WantAgent, callback: AsyncCallback\) - -- 接口说明 - - 取消WantAgent实例(callback形式) - -- cancel参数描述 - - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------- | -------- | --------------------- | ---- | --------------------------- | -| agent | 只读 | WantAgent | 是 | WantAgent对象 | -| callback | 只读 | AsyncCallback\ | 是 | 取消WantAgent实例的回调方法 | - -- 返回值 - - void - -- 示例 - -```js -import WantAgent from '@ohos.wantAgent'; -import { OperationType, WantAgentFlags } from '@ohos.wantagent'; - -//wantAgent对象 -var wantAgent; - -//getWantAgent回调 -function getWantAgentCallback(err, data) { - console.info("==========================>getWantAgentCallback=======================>"); - if (err.code == 0) { - wantAgent = data; - } else { - console.info('----getWantAgent failed!----'); - } -} -//WantAgentInfo对象 -var wantAgentInfo = { - wants: [ - { - deviceId: "deviceId", - bundleName: "com.neu.setResultOnAbilityResultTest1", - abilityName: "com.example.test.MainAbility", - action: "action1", - entities: ["entity1"], - type: "MIMETYPE", - uri: "key={true,true,false}", - parameters: - { - mykey0: 2222, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "ssssssssssssssssssssssssss", - mykey4: [false, true, false], - mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - mykey6: true, - } - } - ], - operationType: OperationType.START_ABILITIES, - requestCode: 0, - wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] -} - -WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) - -//cancel回调 -function cancelCallback(err, data) { - console.info("==========================>cancelCallback=======================>"); -} -WantAgent.cancel(wantAgent, cancelCallback) -``` - - - -## WantAgent.cancel(agent: WantAgent): Promise\ - -- 接口说明 - - 取消WantAgent实例(Promise形式) - -- cancel参数描述 - - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ----- | -------- | --------- | ---- | ------------- | -| agent | 只读 | WantAgent | 是 | WantAgent对象 | - -- 返回值 - - Promise\ - -- 示例 - -```js -import WantAgent from '@ohos.wantAgent'; -import { OperationType, WantAgentFlags } from '@ohos.wantagent'; - -//wantAgent对象 -var wantAgent; - -//WantAgentInfo对象 -var wantAgentInfo = { - wants: [ - { - deviceId: "deviceId", - bundleName: "com.neu.setResultOnAbilityResultTest1", - abilityName: "com.example.test.MainAbility", - action: "action1", - entities: ["entity1"], - type: "MIMETYPE", - uri: "key={true,true,false}", - parameters: - { - mykey0: 2222, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "ssssssssssssssssssssssssss", - mykey4: [false, true, false], - mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - mykey6: true, - } - } - ], - operationType: OperationType.START_ABILITIES, - requestCode: 0, - wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] -} - -WantAgent.getWantAgent(wantAgentInfo).then((data) => { - console.info("==========================>getWantAgentCallback=======================>"); - wantAgent = data; -}); - -WantAgent.cancel(wantAgent).then((data) => { - console.info("==========================>cancelCallback=======================>"); -}); -``` - - - -## WantAgent.trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: Callback\) - -- 接口说明 - - 主动激发WantAgent实例(callback形式) - -- trigger参数描述 - - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ----------- | -------- | ----------------------------- | ---- | ------------------------------- | -| agent | 只读 | WantAgent | 是 | WantAgent对象 | -| triggerInfo | 只读 | TriggerInfo | 是 | TriggerInfo对象 | -| callback | 只读 | AsyncCallback\ | 是 | 主动激发WantAgent实例的回调方法 | - -- TriggerInfo类型说明 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ---------- | -------- | -------------------- | ---- | ----------- | -| code | 读、写 | number | 是 | result code | -| want | 读、写 | Want | 否 | Want | -| permission | 读、写 | string | 否 | 权限定义 | -| extraInfo | 读、写 | {[key: string]: any} | 否 | 额外数据 | - -- 返回值 - - void - -- 示例 - -```js -import WantAgent from '@ohos.wantAgent'; -import { OperationType, WantAgentFlags } from '@ohos.wantagent'; - -//wantAgent对象 -var wantAgent; - -//getWantAgent回调 -function getWantAgentCallback(err, data) { - console.info("==========================>getWantAgentCallback=======================>"); - if (err.code == 0) { - wantAgent = data; - } else { - console.info('----getWantAgent failed!----'); - } -} -//WantAgentInfo对象 -var wantAgentInfo = { - wants: [ - { - deviceId: "deviceId", - bundleName: "com.neu.setResultOnAbilityResultTest1", - abilityName: "com.example.test.MainAbility", - action: "action1", - entities: ["entity1"], - type: "MIMETYPE", - uri: "key={true,true,false}", - parameters: - { - mykey0: 2222, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "ssssssssssssssssssssssssss", - mykey4: [false, true, false], - mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - mykey6: true, - } - } - ], - operationType: OperationType.START_ABILITIES, - requestCode: 0, - wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] -} - -WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) - -//trigger回调 -function triggerCallback(err, data) { - console.info("==========================>triggerCallback=======================>"); -} - -var triggerInfo = { - code:0 -} -WantAgent.trigger(wantAgent, triggerInfo, triggerCallback) -``` - - - -## WantAgent.equal(agent: WantAgent, otherAgent: WantAgent, callback: AsyncCallback\) - -- 接口说明 - - 判断两个WantAgent实例是否相等(callback形式) - -- equal参数描述 - - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ---------- | -------- | ------------------------ | ---- | --------------------------------------- | -| agent | 只读 | WantAgent | 是 | WantAgent对象 | -| otherAgent | 只读 | WantAgent | 是 | WantAgent对象 | -| callback | 只读 | AsyncCallback\ | 是 | 判断两个WantAgent实例是否相等的回调方法 | - -- 返回值 - - void - -- 示例 - -```js -import WantAgent from '@ohos.wantAgent'; -import { OperationType, WantAgentFlags } from '@ohos.wantagent'; - -//wantAgent对象 -var wantAgent1; -var wantAgent2; - -//getWantAgent回调 -function getWantAgentCallback(err, data) { - console.info("==========================>getWantAgentCallback=======================>"); - if (err.code == 0) { - wantAgent1 = data; - wantAgent2 = data; - } else { - console.info('----getWantAgent failed!----'); - } -} -//WantAgentInfo对象 -var wantAgentInfo = { - wants: [ - { - deviceId: "deviceId", - bundleName: "com.neu.setResultOnAbilityResultTest1", - abilityName: "com.example.test.MainAbility", - action: "action1", - entities: ["entity1"], - type: "MIMETYPE", - uri: "key={true,true,false}", - parameters: - { - mykey0: 2222, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "ssssssssssssssssssssssssss", - mykey4: [false, true, false], - mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - mykey6: true, - } - } - ], - operationType: OperationType.START_ABILITIES, - requestCode: 0, - wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] -} - -WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) - -//equal回调 -function equalCallback(err, data) { - console.info("==========================>equalCallback=======================>"); -} -WantAgent.equal(wantAgent1, wantAgent2, equalCallback) -``` - - - -## WantAgent.equal(agent: WantAgent, otherAgent: WantAgent): Promise\ - -- 接口说明 - - 判断两个WantAgent实例是否相等(Promise形式) - -- equal参数描述 - - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ---------- | -------- | --------- | ---- | ------------- | -| agent | 只读 | WantAgent | 是 | WantAgent对象 | -| otherAgent | 只读 | WantAgent | 是 | WantAgent对象 | - -- 返回值 - - Promise\ - -- 示例 - -```js -import WantAgent from '@ohos.wantAgent'; -import { OperationType, WantAgentFlags } from '@ohos.wantagent'; - -//wantAgent对象 -var wantAgent1; -var wantAgent2; - -//WantAgentInfo对象 -var wantAgentInfo = { - wants: [ - { - deviceId: "deviceId", - bundleName: "com.neu.setResultOnAbilityResultTest1", - abilityName: "com.example.test.MainAbility", - action: "action1", - entities: ["entity1"], - type: "MIMETYPE", - uri: "key={true,true,false}", - parameters: - { - mykey0: 2222, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "ssssssssssssssssssssssssss", - mykey4: [false, true, false], - mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - mykey6: true, - } - } - ], - operationType: OperationType.START_ABILITIES, - requestCode: 0, - wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] -} - -WantAgent.getWantAgent(wantAgentInfo).then((data) => { - console.info("==========================>getWantAgentCallback=======================>"); - wantAgent1 = data; - wantAgent2 = data; -}); - -WantAgent.equal(wantAgent1, wantAgent2).then((data) => { - console.info("==========================>equalCallback=======================>"); -}); -``` - - - -#### - - - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/01.Ability\346\241\206\346\236\266/08.Context\346\250\241\345\235\227.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/01.Ability\346\241\206\346\236\266/08.Context\346\250\241\345\235\227.md" deleted file mode 100644 index e5b0d90df46df3d2afc5fef50cc31e7883cba134..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/01.Ability\346\241\206\346\236\266/08.Context\346\250\241\345\235\227.md" +++ /dev/null @@ -1,487 +0,0 @@ ---- -title: Context模块 -permalink: /pages/010c010108 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# Context模块 - -## 导入模块 - -```js -import featureAbility from '@ohos.ability.featureAbility' -import bundle from '@ohos.bundle' -``` - -Context对象是在featureAbility中创建实例,并通过featureAbility的getContext()接口返回,因此在使用Context时,必须导入@ohos.ability.featureAbility库。示例如下: - -```js -import featureAbility from '@ohos.ability.featureAbility' -var context = featureAbility.getContext(); -context.getOrCreateLocalDir() -``` - -## Context - -### getOrCreateLocalDir - -getOrCreateLocalDir(callback: AsyncCallback\): void - -获取应用程序的本地根目录(callback形式)。 - -如果是第一次调用,将创建目录。 - -**参数:** - - -| 名称 | 类型 | 必填 | 描述 | -| -------- | ---------------------- | ---- | -------------------------- | -| callback | AsyncCallback\ | 是 | 返回应用程序的本地根目录。 | - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -var context = featureAbility.getContext(); -context.getOrCreateLocalDir((err, data)=>{ - console.info("data=" + data); -}) -``` - - - -### getOrCreateLocalDir - -getOrCreateLocalDir(): Promise\ - -获取应用程序的本地根目录(Promise形式)。 - -如果是第一次调用,将创建目录。 - -**返回值:** - -| 类型 | 说明 | -| ---------------- | ---------------------- | -| Promise\ | 应用程序的本地根目录。 | - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -var context = featureAbility.getContext(); -context.getOrCreateLocalDir().then((void) => { - console.info("==========================>getOrCreateLocalDirCallback=======================>"); -}); -``` - - - -### verifyPermission - -verifyPermission(permission: string, options: PermissionOptions, callback: AsyncCallback\): void - -验证系统中运行的特定pid和uid是否允许指定的权限(callback形式)。 - -**参数:** - - -| 名称 | 类型 | 必填 | 描述 | -| ---------- | --------------------------------------- | ---- | ------------------------------------- | -| permission | string | 是 | 指定权限的名称。 | -| options | [PermissionOptions](#permissionoptions) | 是 | 权限选项。 | -| callback | AsyncCallback\ | 是 | 返回权限验证结果,0有权限,-1无权限。 | - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -import bundle from '@ohos.bundle' -var context = featureAbility.getContext(); -var datainfo = await bundle.getBundleInfo('com.context.test',1); -context.verifyPermission("com.example.permission",datainfo.uid) - -``` - - - -### verifyPermission - -verifyPermission(permission: string, callback: AsyncCallback\): void - -验证系统中运行的当前pid和uid是否具有指定的权限(callback形式)。 - -**参数:** - - -| 名称 | 类型 | 必填 | 描述 | -| ---------- | ---------------------- | ---- | ------------------------------------- | -| permission | string | 是 | 指定权限的名称。 | -| callback | AsyncCallback\ | 是 | 返回权限验证结果,0有权限,-1无权限。 | - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -var context = featureAbility.getContext(); -context.verifyPermission("com.example.permission") -``` - -### verifyPermission - -verifyPermission(permission: string, options?: PermissionOptions): Promise\ - -验证系统中运行的特定pid和uid是否具有指定的权限(Promise形式)。 - -**参数:** - - -| 名称 | 类型 | 必填 | 描述 | -| ---------- | --------------------------------------- | ---- | ---------------- | -| permission | string | 是 | 指定权限的名称。 | -| options | [PermissionOptions](#permissionoptions) | 否 | 权限选项。 | - -**返回值:** - -| 类型 | 说明 | -| ---------------- | ----------------------------------------------------------- | -| Promise\ | 如果pid和uid具有权限,则使用0进行异步回调;否则使用-1回调。 | - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -var context = featureAbility.getContext(); -var Permission = context.PermissionOptions(1,1); -context.getOrCreateLocalDir('com.context.permission',Permission).then((void) => { - console.info("==========================>verifyPermissionCallback=======================>"); -}); -``` - - - -### requestPermissionsFromUser - -requestPermissionsFromUser(permissions: Array\, requestCode: number, resultCallback: AsyncCallback<[PermissionRequestResult](#permissionrequestresult)>) - -从系统请求某些权限(callback形式)。 - -**参数:** - - -| 名称 | 类型 | 必填 | 描述 | -| -------------- | ------------------------------------------------------------ | ---- | ----------------------------------------------- | -| permissions | Array\ | 是 | 指示要请求的权限列表。此参数不能为null。 | -| requestCode | number | 是 | 指示要传递给PermissionRequestResult的请求代码。 | -| resultCallback | AsyncCallback<[PermissionRequestResult](#permissionrequestresult)> | 是 | 返回授权结果信息。 | -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -var context = featureAbility.getContext(); -context.getOrCreateLocalDir( - ["com.example.permission1", - "com.example.permission2", - "com.example.permission3", - "com.example.permission4", - "com.example.permission5"], - 1, -) -``` - - - -### getApplicationInfo - -getApplicationInfo(callback: AsyncCallback\) - -获取有关当前应用程序的信息(callback形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| -------- | ------------------------------- | ---- | ------------------------ | -| callback | AsyncCallback\ | 是 | 返回当前应用程序的信息。 | - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -var context = featureAbility.getContext(); -context.getApplicationInfo() -``` - - - -### getApplicationInfo - -getApplicationInfo(): Promise\ - -获取有关当前应用程序的信息(Promise形式)。 - -**返回值:** - -| 类型 | 说明 | -| ------------------------- | ------------------ | -| Promise\ | 当前应用程序的信息 | - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -var context = featureAbility.getContext(); -context.getApplicationInfo().then((void) => { - console.info("==========================>getApplicationInfoCallback=======================>"); -}); -``` - - - -### getBundleName - -getBundleName(callback: AsyncCallback\): void - -获取当前ability的捆绑包名称(callback形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| -------- | ---------------------- | ---- | ----------------------------- | -| callback | AsyncCallback\ | 是 | 返回当前ability的捆绑包名称。 | - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -var context = featureAbility.getContext(); -context.getBundleName() -``` - - - -### getBundleName - -getBundleName(): Promise\ - -获取当前ability的捆绑包名称(Promise形式)。 - -**返回值:** - -| 类型 | 说明 | -| ---------------- | ------------------------- | -| Promise\ | 当前ability的捆绑包名称。 | - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -var context = featureAbility.getContext(); -context.getBundleName().then((void) => { - console.info("==========================>getBundleNameCallback=======================>"); -}); -``` - - - -### getProcessInfo - -getProcessInfo(callback: AsyncCallback\) - -获取有关当前进程的信息,包括进程ID和名称(callback形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| -------- | --------------------------- | ---- | -------------------- | -| callback | AsyncCallback\ | 是 | 返回当前进程的信息。 | - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -var context = featureAbility.getContext(); -context.getProcessInfo() -``` - - - -### getProcessInfo - -getProcessInfo(): Promise\ - -获取有关当前进程的信息,包括进程id和名称(Promise形式)。 - -**返回值:** - -| 类型 | 说明 | -| --------------------- | -------------- | -| Promise\ | 当前进程的信息 | - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -var context = featureAbility.getContext(); -context.getProcessInfo().then((void) => { - console.info("==========================>getProcessInfoCallback=======================>"); -}); -``` - - - -### getElementName - -getElementName(callback: AsyncCallback\): void - -获取当前ability的ohos.bundle.ElementName对象(callback形式)。 - -此方法仅适用于页面功能。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| -------- | --------------------------- | ---- | ---------------------------------------------- | -| callback | AsyncCallback\ | 是 | 返回当前ability的ohos.bundle.ElementName对象。 | - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -var context = featureAbility.getContext(); -context.getElementName() -``` - - - -### getElementName - -getElementName(): Promise\ - -获取当前能力的ohos.bundle.ElementName对象(Promise形式)。 - -此方法仅适用于页面功能。 - -**返回值:** - -| 类型 | 说明 | -| --------------------- | ------------------------------------------ | -| Promise\ | 当前ability的ohos.bundle.ElementName对象。 | - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -var context = featureAbility.getContext(); -context.getElementName().then((void) => { - console.info("==========================>getElementNameCallback=======================>"); -}); -``` - -### getProcessName - -getProcessName(callback: AsyncCallback\): void - -获取当前进程的名称(callback形式)。 - -| 名称 | 类型 | 必填 | 描述 | -| -------- | ---------------------- | ---- | -------------------- | -| callback | AsyncCallback\ | 是 | 返回当前进程的名称。 | - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -var context = featureAbility.getContext(); -context.getProcessName() -``` - - - -### getProcessName - -getProcessName(): Promise\ - -获取当前进程的名称(Promise形式)。 - -**返回值:** - -| 类型 | 说明 | -| ---------------- | -------------------- | -| Promise\ | 返回当前进程的名称。 | - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -var context = featureAbility.getContext(); -context.getProcessName().then((void) => { - console.info("==========================>getProcessNameCallback=======================>"); -}); -``` - - - -### getCallingBundle - -getCallingBundle(callback: AsyncCallback\): void - -获取调用ability的包名称(callback形式)。 - -**参数:** - -| 名称 | 类型 | 必填 | 描述 | -| -------- | ---------------------- | ---- | ------------------------- | -| callback | AsyncCallback\ | 是 | 返回调用ability的包名称。 | - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -var context = featureAbility.getContext(); -context.getCallingBundle() -``` - - - -### getCallingBundle - -getCallingBundle(): Promise\ - -获取调用ability的包名称(Promise形式)。 - -**返回值:** - -| 类型 | 说明 | -| --------------- | ------------------------- | -| Promise\ | 调用ability的包名称 | - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -var context = featureAbility.getContext(); -context.getCallingBundle().then((void) => { - console.info("==========================>getCallingBundleCallback=======================>"); -}); -``` - -## PermissionOptions - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ---- | -------- | ------ | ---- | ------ | -| pid | 只读 | number | 否 | 进程id | -| uid | 只读 | number | 否 | 用户id | - -## PermissionRequestResult - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ----------- | -------- | -------------- | ---- | ------------------ | -| requestCode | 只读 | number | 是 | 用户传入的请求代码 | -| permissions | 只读 | Array\ | 是 | 用户传入的权限 | -| authResults | 只读 | Array\ | 是 | 求权限的结果 | diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/02.\350\265\204\346\272\220\347\256\241\347\220\206/01.\350\265\204\346\272\220\347\256\241\347\220\206.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/02.\350\265\204\346\272\220\347\256\241\347\220\206/01.\350\265\204\346\272\220\347\256\241\347\220\206.md" deleted file mode 100644 index d653ca8aa02be21aa096880f2032673de3dad38b..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/02.\350\265\204\346\272\220\347\256\241\347\220\206/01.\350\265\204\346\272\220\347\256\241\347\220\206.md" +++ /dev/null @@ -1,620 +0,0 @@ ---- -title: 资源管理 -permalink: /pages/010c010201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 资源管理 - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import resourceManager from '@ohos.resourceManager'; -``` - - -## 权限 - -无 - - -## resourceManager.getResourceManager - -getResourceManager(callback: AsyncCallback<ResourceManager>): void - -获取当前应用的资源管理对象,使用callback形式返回ResourceManager对象。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<[ResourceManager](#resourcemanager)> | 是 | callback方式返回ResourceManager对象 | - -- 示例: - ``` - resourceManager.getResourceManager((error, mgr) => { - if (error != null) { - console.log("error occurs" + error); - return; - } - mgr.getString(0x1000000, (error, value) => { - if (error != null) { - console.log(value); - } else { - console.log(value); - } - }); - }); - ``` - - -## resourceManager.getResourceManager - -getResourceManager(bundleName: string, callback: AsyncCallback<ResourceManager>): void - -获取指定应用的资源管理对象,使用callback形式返回ResourceManager对象。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | bundleName | string | 是 | 指定应用的Bundle名称 | - | callback | AsyncCallback<[ResourceManager](#resourcemanager)> | 是 | callback方式返回ResourceManager对象 | - -- 示例: - ``` - resourceManager.getResourceManager("com.example.myapplication", (error, mgr) => { - }); - ``` - - -## resourceManager.getResourceManager - -getResourceManager(): Promise<ResourceManager> - -获取当前应用的资源管理对象,使用Promise形式返回ResourceManager对象。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<[ResourceManager](#resourcemanager)> | Promise方式返回资源管理对象 | - -- 示例: - ``` - resourceManager.getResourceManager().then(mgr => { - mgr.getString(0x1000000, (error, value) => { - if (error != null) { - console.log(value); - } else { - console.log(value); - } - }); - }).catch(error => { - console.log(error); - }); - ``` - - -## resourceManager.getResourceManager - -getResourceManager(bundleName: string): Promise<ResourceManager> - -获取指定应用的资源管理对象,使用Promise形式返回ResourceManager对象。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | bundleName | string | 是 | 指定应用的Bundle名称 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<[ResourceManager](#resourcemanager)> | Promise方式返回的资源管理对象 | - -- 示例: - ``` - resourceManager.getResourceManager("com.example.myapplication").then(mgr => { - - }).catch(error => { - - }); - ``` - - -## Direction - -用于表示设备屏幕方向。 - -| 名称 | 默认值 | 说明 | -| -------- | -------- | -------- | -| DIRECTION_VERTICAL | 0 | 竖屏 | -| DIRECTION_HORIZONTAL | 1 | 横屏 | - - -## DeviceType - -用于表示当前设备类型。 - -| 名称 | 默认值 | 说明 | -| -------- | -------- | -------- | -| DEVICE_TYPE_PHONE | 0x00 | 手机 | -| DEVICE_TYPE_TABLET | 0x01 | 平板 | -| DEVICE_TYPE_CAR | 0x02 | 汽车 | -| DEVICE_TYPE_PC | 0x03 | 电脑 | -| DEVICE_TYPE_TV | 0x04 | 电视 | -| DEVICE_TYPE_WEARABLE | 0x06 | 穿戴 | - - -## ScreenDensity - -用于表示当前设备屏幕密度。 - -| 名称 | 默认值 | 说明 | -| -------- | -------- | -------- | -| SCREEN_SDPI | 120 | 小规模的屏幕密度 | -| SCREEN_MDPI | 160 | 中规模的屏幕密度 | -| SCREEN_LDPI | 240 | 大规模的屏幕密度 | -| SCREEN_XLDPI | 320 | 特大规模的屏幕密度 | -| SCREEN_XXLDPI | 480 | 超大规模的屏幕密度 | -| SCREEN_XXXLDPI | 640 | 超特大规模的屏幕密度 | - - -## Configuration - -表示当前设备的状态。 - - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| direction | [Direction](#direction) | 是 | 否 | 当前设备屏幕方向 | -| locale | string | 是 | 否 | 当前系统语言 | - - -## DeviceCapability - -表示设备支持的能力。 - - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| screenDensity | [ScreenDensity](#screendensity) | 是 | 否 | 当前设备屏幕密度 | -| deviceType | [DeviceType](#devicetype) | 是 | 否 | 当前设备类型 | - - -## ResourceManager - -提供访问应用资源的能力。 - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> - ResourceManager涉及到的方法,仅限基于TS扩展的声明式开发范式使用。 -> -> - 资源文件在工程的resources目录中定义,id可通过$r(资源地址).id的方式获取,例如$r('app.string.test').id。 - - -### getString - -getString(resId: number, callback: AsyncCallback<string>): void - -用户获取指定资源ID对应的字符串,使用callback形式返回字符串。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | resId | number | 是 | 资源ID值 | - | callback | AsyncCallback<string> | 是 | 异步回调,用于返回获取的字符串 | - -- 示例: - ``` - resourceManager.getResourceManager((error, mgr) => { - mgr.getString($r('app.string.test').id, (error, value) => { - if (error != null) { - console.log(value); - } else { - console.log(value); - } - }); - }); - ``` - - -### getString - -getString(resId: number): Promise<string> - -用户获取指定资源ID对应的字符串,使用Promise形式返回字符串。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | resId | number | 是 | 资源ID值 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<string> | 资源ID值对应的字符串 | - -- 示例: - ``` - resourceManager.getResourceManager((error, mgr) => { - mgr.getString($r('app.string.test').id).then(value => { - console.log(value); - }).catch(error => { - console.log("getstring promise " + error); - }); - }); - ``` - - -### getStringArray - -getStringArray(resId: number, callback: AsyncCallback<Array<string>>): void - -用户获取指定资源ID对应的字符串数组,使用callback形式返回字符串数组。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | resId | number | 是 | 资源ID值 | - | callback | AsyncCallback<Array<string>> | 是 | 异步回调,用于返回获取的字符串数组 | - -- 示例: - ``` - resourceManager.getResourceManager((error, mgr) => { - mgr.getStringArray($r('app.strarray.test').id, (error, value) => { - if (error != null) { - console.log(value); - } else { - console.log(value); - } - }); - }); - ``` - - -### getStringArray - -getStringArray(resId: number): Promise<Array<string>> - -用户获取指定资源ID对应的字符串数组,使用Promise形式返回字符串数组。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | resId | number | 是 | 资源ID值 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<Array<string>> | 资源ID值对应的字符串数组 | - -- 示例: - ``` - resourceManager.getResourceManager((error, mgr) => { - mgr.getStringArray($r('app.strarray.test').id).then(value => { - console.log(value); - }).catch(error => { - console.log("getstring promise " + error); - }); - }); - ``` - - -### getMedia - -getMedia(resId: number, callback: AsyncCallback<Uint8Array>): void - -用户获取指定资源ID对应的媒体文件内容,使用callback形式返回字节数组。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | resId | number | 是 | 资源ID值 | - | callback | AsyncCallback<Uint8Array> | 是 | 异步回调,用于返回获取的媒体文件内容 | - -- 示例: - ``` - resourceManager.getResourceManager((error, mgr) => { - mgr.getMedia($r('app.media.test').id, (error, value) => { - if (error != null) { - console.log(value); - } else { - console.log(value); - } - }); - }); - ``` - - -### getMedia - -getMedia(resId: number): Promise<Uint8Array> - -用户获取指定资源ID对应的媒体文件内容,使用Promise形式返回字节数组。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | resId | number | 是 | 资源ID值 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<Uint8Array> | 资源ID值对应的媒体文件内容 | - -- 示例: - ``` - resourceManager.getResourceManager((error, mgr) => { - mgr.getMedia($r('app.media.test').id).then(value => { - console.log(value); - }).catch(error => { - console.log("getstring promise " + error); - }); - }); - ``` - - -### getMediaBase64 - -getMediaBase64(resId: number, callback: AsyncCallback<string>): void - -用户获取指定资源ID对应的图片资源Base64编码,使用callback形式返回字符串。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | resId | number | 是 | 资源ID值 | - | callback | AsyncCallback<string> | 是 | 异步回调,用于返回获取的图片资源Base64编码 | - -- 示例: - ``` - resourceManager.getResourceManager((error, mgr) => { - mgr.getMediaBase64($r('app.media.test').id, (error, value) => { - if (error != null) { - console.log(value); - } else { - console.log(value); - } - }); - }); - ``` - - -### getMediaBase64 - -getMediaBase64(resId: number): Promise<string> - -用户获取指定资源ID对应的图片资源Base64编码,使用Promise形式返回字符串。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | resId | number | 是 | 资源ID值 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<string> | 资源ID值对应的图片资源Base64编码 | - -- 示例: - ``` - resourceManager.getResourceManager((error, mgr) => { - mgr.getMediaBase64($r('app.media.test').id).then(value => { - console.log(value); - }).catch(error => { - console.log("getstring promise " + error); - }); - }); - ``` - - -### getConfiguration - -getConfiguration(callback: AsyncCallback<Configuration>): void - -用户获取设备的Configuration,使用callback形式返回Configuration对象。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<[Configuration](#configuration)> | 是 | 异步回调,用于返回设备的Configuration | - -- 示例: - ``` - resourceManager.getResourceManager((error, mgr) => { - mgr.getConfiguration((error, value) => { - if (error != null) { - console.log(value); - } else { - console.log(value); - } - }); - }); - ``` - - -### getConfiguration - -getConfiguration(): Promise<Configuration> - -用户获取设备的Configuration,使用Promise形式返回Configuration对象。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<[Configuration](#configuration)> | 设备的Configuration | - -- 示例: - ``` - resourceManager.getResourceManager((error, mgr) => { - mgr.getConfiguration().then(value => { - console.log(value); - }).catch(error => { - console.log("getstring promise " + error); - }); - }); - ``` - - -### getDeviceCapability - -getDeviceCapability(callback: AsyncCallback<DeviceCapability>): void - -用户获取设备的DeviceCapability,使用callback形式返回DeviceCapability对象。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<[DeviceCapability](#devicecapability)> | 是 | 异步回调,用于返回设备的DeviceCapability | - -- 示例: - ``` - resourceManager.getResourceManager((error, mgr) => { - mgr.getDeviceCapability((error, value) => { - if (error != null) { - console.log(value); - } else { - console.log(value); - } - }); - }); - ``` - - -### getDeviceCapability - -getDeviceCapability(): Promise<DeviceCapability> - -用户获取设备的DeviceCapability,使用Promise形式返回DeviceCapability对象。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<[DeviceCapability](#devicecapability)> | 设备的DeviceCapability | - -- 示例: - ``` - resourceManager.getResourceManager((error, mgr) => { - mgr.getDeviceCapability().then(value => { - console.log(value); - }).catch(error => { - console.log("getstring promise " + error); - }); - }); - ``` - - -### getPluralString - -getPluralString(resId: number, num: number, callback: AsyncCallback<string>): void - -根据指定数量获取指定ID字符串表示的单复数字符串,使用callback形式返回字符串。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | resId | number | 是 | 资源ID值 | - | num | number | 是 | 数量值 | - | callback | AsyncCallback<string> | 是 | 异步回调,返回根据指定数量获取指定ID字符串表示的单复数字符串 | - -- 示例: - ``` - resourceManager.getResourceManager((error, mgr) => { - mgr.getPluralString($r("app.plural.test").id, 1, (error, value) => { - if (error != null) { - console.log(value); - } else { - console.log(value); - } - }); - }); - ``` - - -### getPluralString - -getPluralString(resId: number, num: number): Promise<string> - -根据指定数量获取对指定ID字符串表示的单复数字符串,使用Promise形式返回字符串。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | resId | number | 是 | 资源ID值 | - | num | number | 是 | 数量值 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<string> | 根据提供的数量获取对应ID字符串表示的单复数字符串 | - -- 示例: - ``` - resourceManager.getResourceManager((error, mgr) => { - mgr.getPluralString($r("app.plural.test").id, 1).then(value => { - console.log(value); - }).catch(error => { - console.log("getstring promise " + error); - }); - }); - ``` - -### getRawFile8+ - -getRawFile(path: string, callback: AsyncCallback<Uint8Array>): void - -用户获取指定路径对应的rawfile文件内容,使用callback形式返回字节数组。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | rawfile文件路径 | - | callback | AsyncCallback<Uint8Array> | 是 | 异步回调,用于返回获取的rawfile文件内容 | - -- 示例: - ``` - resourceManager.getResourceManager((error, mgr) => { - mgr.getRawFile("test.xml", (error, value) => { - if (error != null) { - console.log(value); - } else { - console.log(value); - } - }); - }); - ``` - -### getRawFile8+ - -getRawFile(path: string): Promise<Uint8Array> - -用户获取指定路径对应的rawfile文件内容,使用Promise形式返回字节数组。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | rawfile文件路径 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<Uint8Array> | rawfile文件内容 | - -- 示例: - ``` - resourceManager.getResourceManager((error, mgr) => { - mgr.getRawFile("test.xml").then(value => { - console.log(value); - }).catch(error => { - console.log("getrawfile promise " + error); - }); - }); - ``` diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/02.\350\265\204\346\272\220\347\256\241\347\220\206/02.\345\233\275\351\231\205\345\214\226\357\274\210I18n\357\274\211.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/02.\350\265\204\346\272\220\347\256\241\347\220\206/02.\345\233\275\351\231\205\345\214\226\357\274\210I18n\357\274\211.md" deleted file mode 100644 index 758b98571f5c6e5b5fe89d6fcfeb384d002817a2..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/02.\350\265\204\346\272\220\347\256\241\347\220\206/02.\345\233\275\351\231\205\345\214\226\357\274\210I18n\357\274\211.md" +++ /dev/null @@ -1,1166 +0,0 @@ ---- -title: 国际化(I18n) -permalink: /pages/010c010202 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 国际化-I18n - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> - 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 -> -> - I18N模块包含国际化能力增强接口(未在ECMA 402中定义)。 - - -## 导入模块 - -``` -import i18n from '@ohos.i18n'; -``` - - -## 权限 - -无 - - -## i18n.getDisplayLanguage - -getDisplayLanguage(language: string, locale: string, sentenceCase?: boolean): string - -获取指定语言的本地化显示文本。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | language | string | 是 | 指定语言。 | - | locale | string | 是 | 显示指定语言的区域ID。 | - | sentenceCase | boolean | 否 | 本地化显示文本是否要首字母大写。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string | 指定语言的本地化显示文本。 | - -- 示例: - ``` - i18n.getDisplayLanguage("zh", "en-GB", true); - i18n.getDisplayLanguage("zh", "en-GB"); - ``` - - -## i18n.getDisplayCountry - -getDisplayCountry(country: string, locale: string, sentenceCase?: boolean): string - -获取指定国家的本地化显示文本。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | country | string | 是 | 指定国家。 | - | locale | string | 是 | 显示指定国家的区域ID。 | - | sentenceCase | boolean | 否 | 本地化显示文本是否要首字母大写。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string | 指定国家的本地化显示文本。 | - -- 示例: - ``` - i18n.getDisplayCountry("zh-CN", "en-GB", true); - i18n.getDisplayCountry("zh-CN", "en-GB"); - ``` - - -## i18n.isRTL8+ - -isRTL(locale: string): boolean - -获取是否为从右至左显示语言。 - -- 参数: - | 参数名 | 类型 | 说明 | - | -------- | -------- | -------- | - | locale | string | 指定区域ID。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | true表示该locale从右至左显示语言;false表示该locale从左至右显示语言。 | - -- 示例: - ``` - i18n.isRTL("zh-CN");// 中文不是RTL语言,返回false - i18n.isRTL("ar-EG");// 阿语是RTL语言,返回true - ``` - - -## i18n.getSystemLanguage - -getSystemLanguage(): string - -获取系统语言。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string | 系统语言ID。 | - -- 示例: - ``` - i18n.getSystemLanguage(); - ``` - - -## i18n.getSystemRegion - -getSystemRegion(): string - -获取系统地区。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string | 系统地区ID。 | - -- 示例: - ``` - i18n.getSystemRegion(); - ``` - - -## i18n.getSystemLocale - -getSystemLocale(): string - -获取系统区域。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string | 系统区域ID。 | - -- 示例: - ``` - i18n.getSystemLocale(); - ``` - - -## i18n.getCalendar8+ - -getCalendar(locale: string, type? : string): Calendar - -获取日历对象。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | locale | string | 是 | 合法的locale值,例如zh-Hans-CN。 | - | type | string | 否 | 合法的日历类型,目前合法的类型有buddhist, chinese, coptic, ethiopic, hebrew, gregory, indian, islamic_civil, islamic_tbla, islamic_umalqura, japanese, persian。当type没有给出时,采用区域默认的日历类型。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [Calendar](#calendar8) | 日历对象。 | - -- 示例: - ``` - i18n.getCalendar("zh-Hans", "gregory"); - ``` - - -## Calendar8+ - - -### setTime8+ - -setTime(date: Date): void - -设置日历对象内部的时间日期。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | date | Date | 是 | 将要设置的日历对象的内部时间日期。 | - -- 示例: - ``` - var calendar = I18n.getCalendar("en-US", "gregory"); - var date = new Date(2021, 10, 7, 8, 0, 0, 0); - calendar.setTime(date); - ``` - - -### setTime8+ - -setTime(time: number): void - -设置日历对象内部的时间日期, time为从1970.1.1 00:00:00 GMT逝去的毫秒数。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | time | number | 是 | time为从1970.1.1 00:00:00 GMT逝去的毫秒数。 | - -- 示例: - ``` - var calendar = I18n.getCalendar("en-US", "gregory"); - calendar.setTime(10540800000); - ``` - - -### set8+ - -set(year: number, month: number, date:number, hour?: number, minute?: number, second?: number): void - -设置日历对象的年、月、日、时、分、秒。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | year | number | 是 | 设置的年。 | - | month | number | 是 | 设置的月。 | - | date | number | 是 | 设置的日。 | - | hour | number | 否 | 设置的小时。 | - | minute | number | 否 | 设置的分钟。 | - | second | number | 否 | 设置的秒。 | - -- 示例: - ``` - var calendar = i18n.getCalendar("zh-Hans"); - calendar.setTime(2021, 10, 1, 8, 0, 0); // set time to 2021.10.1 08:00:00 - ``` - - -### setTimeZone8+ - -setTimeZone(timezone: string): void - -设置日历对象的时区。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | timezone | string | 是 | 设置的时区id,如“Asia/Shanghai”。 | - -- 示例: - ``` - var calendar = i18n.getCalendar("zh-Hans"); - calendar.setTimeZone("Asia/Shanghai"); - ``` - - -### getTimeZone8+ - -getTimeZone(): string - -获取日历对象的时区。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string | 日历对象的时区id。 | - -- 示例: - ``` - var calendar = i18n.getCalendar("zh-Hans"); - calendar.setTimeZone("Asia/Shanghai"); - calendar.getTimeZone(); // Asia/Shanghai" - ``` - - -### getFirstDayOfWeek8+ - -getFirstDayOfWeek(): number - -获取日历对象的一周起始日。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 获取一周的起始日,1代表周日,7代表周六。 | - -- 示例: - ``` - var calendar = I18n.getCalendar("en-US", "gregory"); - calendar.getFirstDayOfWeek(); - ``` - - -### setFirstDayOfWeek8+ - -setFirstDayOfWeek(value: number): void - -设置每一周的起始日。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | number | 否 | 设置一周的起始日,1代表周日,7代表周六。 | - -- 示例: - ``` - var calendar = i18n.getCalendar("zh-Hans"); - calendar.setFirstDayOfWeek(0); - ``` - - -### getMinimalDaysInFirstWeek8+ - -getMinimalDaysInFirstWeek(): number - -获取一年中第一周的最小天数。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 一年中第一周的最小天数。 | - -- 示例: - ``` - var calendar = i18n.getCalendar("zh-Hans"); - calendar.getMinimalDaysInFirstWeek(); - ``` - - -### setMinimalDaysInFirstWeek8+ - -setMinimalDaysInFirstWeek(value: number): void - -设置一年中第一周的最小天数。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | number | 否 | 一年中第一周的最小天数。 | - -- 示例: - ``` - var calendar = i18n.getCalendar("zh-Hans"); - calendar.setMinimalDaysInFirstWeek(3); - ``` - - -### get8+ - -get(field: string): number - -获取日历对象中与field相关联的值。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | field | string | 是 | 通过field来获取日历对象相应的值。目前支持的field值有 era, year, month, week_of_year, week_of_month, date, day_of_year, day_of_week, day_of_week_in_month, hour, hour_of_day, minute, second, millisecond, zone_offset, dst_offset, year_woy, dow_local, extended_year, julian_day, milliseconds_in_day, is_leap_month。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 与field相关联的值,如当前Calendar对象的内部日期的年份为1990,get("year")返回1990。 | - -- 示例: - ``` - var calendar = i18n.getCalendar("zh-Hans"); - calendar.setTime(2021, 10, 1, 8, 0, 0); // set time to 2021.10.1 08:00:00 - calendar.get("hour_of_day"); // 8 - ``` - - -### getDisplayName8+ - -getDisplayName(locale: string): string - -获取日历对象在locale所指定的区域的名字。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | locale | string | 是 | locale指定获取哪个区域下该calendar的名字,如buddhist在en-US上显示的名称为“Buddhist Calendar”。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string | 日历在locale所指示的区域的名字。 | - -- 示例: - ``` - var calendar = i18n.getCalendar("en-US", "buddhist"); - calendar.getDisplayName("zh"); // 佛历 - ``` - - -### isWeekend8+ - -isWeekend(date?: Date): boolean - -判断给定的日期是否在日历中是周末。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | date | Date | 否 | 判断日期在日历中是否是周末。如果date没有给出,判断calendar当前日期是否为周末。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 当所判断的日期为周末时,返回 true,否则返回false。 | - -- 示例: - ``` - var calendar = i18n.getCalendar("zh-Hans"); - calendar.setTime(2021, 11, 11, 8, 0, 0); // set time to 2021.11.11 08:00:00 - calendar.isWeekend(); // false - var date = new Date(2011, 11, 6, 9, 0, 0); - calendar.isWeekend(date); // true - ``` - - -## PhoneNumberFormat8+ - - -### constructor8+ - -constructor(country: string, options?: PhoneNumberFormatOptions) - -创建电话号码格式化对象。 - -参数: -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| country | string | 是 | 表示电话号码所属国家或地区代码。 | -| options | [PhoneNumberFormatOptions](#phonenumberformatoptions8) | 否 | 电话号码格式化对象的相关选项。 | - -- 示例: - ``` - var phoneNumberFormat= new i18n.PhoneNumberFormat("CN", {"type": "E164"}); - ``` - - -### isValidNumber8+ - -isValidNumber(number: string): boolean - -判断传入的电话号码格式是否正确。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | number | string | 是 | 待判断的电话号码。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 返回true表示电话号码的格式正确,返回false表示电话号码的格式错误。 | - -- 示例: - ``` - var phonenumberfmt = new i18n.PhoneNumberFormat("CN"); - phonenumberfmt.isValidNumber("15812312312"); - ``` - - -### format8+ - -format(number: string): string - -对电话号码进行格式化。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | number | string | 是 | 待格式化的电话号码。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string | 格式化后的电话号码。 | - -- 示例: - ``` - var phonenumberfmt = new i18n.PhoneNumberFormat("CN"); - phonenumberfmt.format("15812312312"); - ``` - - -## PhoneNumberFormatOptions8+ - -表示电话号码格式化对象可设置的属性。 - - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| type | string | 是 | 是 | 表示对电话号码格式化的类型,取值范围:"E164", "INTERNATIONAL", "NATIONAL", "RFC3966"。 | - - -## UnitInfo8+ - -度量衡单位信息。 - - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| unit | string | 是 | 是 | 单位的名称,如:"meter", "inch", "cup"等。 | -| measureSystem | string | 是 | 是 | 单位的度量体系,取值包括:"SI", "US", "UK"。 | - - -## Util8+ - - -### unitConvert8+ - -unitConvert(fromUnit: UnitInfo, toUnit: UnitInfo, value: number, locale: string, style?: string): string - -将fromUnit的单位转换为toUnit的单位,并根据区域与风格进行格式化。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | fromUnit | [UnitInfo](#unitinfo8) | 是 | 要被转换的单位。 | - | toUnit | [UnitInfo](#unitinfo8) | 是 | 要转换为的单位。 | - | value | number | 是 | 要被转换的单位的数量值。 | - | locale | string | 是 | 格式化时使用的区域参数,如:zh-Hans-CN。 | - | style | string | 否 | 格式化使用的风格,取值包括:"long", "short", "medium"。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string | 按照toUnit的单位格式化后,得到的字符串。 | - -- 示例: - ``` - I18n.Util.unitConvert({unit: "cup", measureSystem: "US"}, {unit: "liter", measureSystem: "SI"}, 1000, "en-US", "long"); - ``` - - -## IndexUtil8+ - - -### getInstance8+ - -getInstance(): IndexUtil - -创建并返回IndexUtil对象。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | locale | string | 否 | 包含区域设置信息的字符串,包括语言以及可选的脚本和区域。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [IndexUtil](#indexutil8) | locale对应的IndexUtil对象。 | - -- 示例: - ``` - var indexUtil= i18n.IndexUtil.getInstance("zh-CN"); - ``` - - -### getIndexList8+ - -getIndexList(): Array<string> - -获取当前locale对应的索引列表。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Array<string> | 返回当前locale对应的索引列表。 | - -- 示例: - ``` - var indexUtil = i18n.getInstance("zh-CN"); - var indexList = indexUtil.getIndexList(); - ``` - - -### addLocale8+ - -addLocale(locale: string) - -将新的locale对应的索引加入当前索引列表。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | locale | string | 是 | 包含区域设置信息的字符串,包括语言以及可选的脚本和区域。 | - -- 示例: - ``` - var indexUtil = i18n.getInstance("zh-CN"); - indexUtil.addLocale("en-US"); - ``` - - -### getIndex8+ - -getIndex(text: string): string - -获取text对应的索引。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | text | string | 是 | 待计算索引值的输入文本。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string | 输入文本对应的索引值。 | - -- 示例: - ``` - var indexUtil= i18n.getInstance("zh-CN"); - indexUtil.getIndex("hi"); // 返回h - ``` - - -## Character8+ - - -### isDigit8+ - -isDigit(char: string): boolean - -判断字符串char是否是数字。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | char | string | 是 | 输入字符。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 返回true表示输入的字符是数字,返回false表示输入的字符不是数字。 | - -- 示例: - ``` - var isdigit = Character.isDigit("1"); // 返回true - ``` - - -### isSpaceChar8+ - -isSpaceChar(char: string): boolean - -判断字符串char是否是空格符。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | char | string | 是 | 输入字符。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 返回true表示输入的字符是空格符,返回false表示输入的字符不是空格符。 | - -- 示例: - ``` - var isspacechar = Character.isSpaceChar("a"); // 返回false - ``` - - -### isWhitespace8+ - -isWhitespace(char: string): boolean - -判断字符串char是否是空白符。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | char | string | 是 | 输入字符。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 返回true表示输入的字符是空白符,返回false表示输入的字符不是空白符。 | - -- 示例: - ``` - var iswhitespace = Character.isWhitespace("a"); // 返回false - ``` - - -### isRTL8+ - -isRTL(char: string): boolean - -判断字符串char是否是从右到左语言的字符。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | char | string | 是 | 输入字符。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 返回true表示输入的字符是从右到左语言的字符,返回false表示输入的字符不是从右到左语言的字符。 | - -- 示例: - ``` - var isrtl = Character.isRTL("a"); // 返回false - ``` - - -### isIdeograph8+ - -isIdeograph(char: string): boolean - -判断字符串char是否是表意文字。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | char | string | 是 | 输入字符。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 返回true表示输入的字符是表意文字,返回false表示输入的字符不是表意文字。 | - -- 示例: - ``` - var isideograph = Character.isIdeograph("a"); // 返回false - ``` - - -### isLetter8+ - -isLetter(char: string): boolean - -判断字符串char是否是字母。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | char | string | 是 | 输入字符。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 返回true表示输入的字符是字母,返回false表示输入的字符不是字母。 | - -- 示例: - ``` - var isletter = Character.isLetter("a"); // 返回true - ``` - - -### isLowerCase8+ - -isLowerCase(char: string): boolean - -判断字符串char是否是小写字母。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | char | string | 是 | 输入字符。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 返回true表示输入的字符是小写字母,返回false表示输入的字符不是小写字母。 | - -- 示例: - ``` - var islowercase = Character.isLowerCase("a"); // 返回true - ``` - - -### isUpperCase8+ - -isUpperCase(char: string): boolean - -判断字符串char是否是大写字母。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | char | string | 是 | 输入字符。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 返回true表示输入的字符是大写字母,返回false表示输入的字符不是大写字母。 | - -- 示例: - ``` - var isuppercase = Character.isUpperCase("a"); // 返回false - ``` - - -### getType8+ - -getType(char: string): string - -获取输入字符串的一般类别值。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | char | string | 是 | 输入字符。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string | 输入字符的一般类别值。 | - -- 示例: - ``` - var type = Character.getType("a"); - ``` - - -## i18n.getLineInstance8+ - -getLineInstance(locale: string): BreakIterator - -获取一个用于断句的[BreakIterator](#breakiterator8)对象。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | locale | string | 是 | 合法的locale值,例如zh-Hans-CN。生成的[BreakIterator](#breakiterator8)将按照locale所指定的区域的规则来进行断句。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [BreakIterator](#breakiterator8) | 用于进行断句的处理器。 | - -- 示例: - ``` - i18n.getLineInstance("en"); - ``` - - -## BreakIterator8+ - - -### setLineBreakText8+ - -setLineBreakText(text: string): void - -设置[BreakIterator](#breakiterator8)要处理的文本。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | text | string | 是 | 指定BreakIterator进行断句的文本。 | - -- 示例: - ``` - iterator = I18n.getLineInstance("en"); - iterator.setLineBreakText("Apple is my favorite fruit."); - ``` - - -### getLineBreakText8+ - -getLineBreakText(): string - -获取[BreakIterator](#breakiterator8)当前处理的文本。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string | BreakIterator对象正在处理的文本 | - -- 示例: - ``` - iterator = I18n.getLineInstance("en"); - iterator.setLineBreakText("Apple is my favorite fruit."); - iterator.getLineBreakText(); // Apple is my favorite fruit. - ``` - - -### current8+ - -current(): number - -获取[BreakIterator](#breakiterator8)对象在当前处理的文本中的位置。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | BreakIterator在当前所处理的文本中的位置。 | - -- 示例: - ``` - iterator = I18n.getLineInstance("en"); - iterator.setLineBreakText("Apple is my favorite fruit."); - breakIter.current(); // 0 - ``` - - -### first8+ - -first(): number - -将[BreakIterator](#breakiterator8)对象设置到第一个可断句的分割点。第一个分割点总是被处理的文本的起始位置。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 被处理文本的第一个分割点的偏移量。 | - -- 示例: - ``` - iterator = I18n.getLineInstance("en"); - iterator.setLineBreakText("Apple is my favorite fruit."); - breakIter.first(); // 0 - ``` - - -### last8+ - -last(): number - -将[BreakIterator](#breakiterator8)对象的位置设置到最后一个可断句的分割点。最后一个分割点总是被处理文本末尾的下一个位置。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 被处理的文本的最后一个分割点的偏移量 | - -- 示例: - ``` - iterator = I18n.getLineInstance("en"); - iterator.setLineBreakText("Apple is my favorite fruit."); - iterator.last(); // 27 - ``` - - -### next8+ - -next(index?: number): number - -如果index给出,并且index是一个正数将[BreakIterator](#breakiterator8)向后移动number个可断句的分割点,如果n是一个负数,向前移动相应个分割点。若index没有给出,则相当于index = 1。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | index | number | 否 | [BreakIterator](#breakiterator8)将要移动的分割点数,正数代表向后移动,负数代表向前移动。若index没有给出,则按照index=1处理。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 返回移动了index个分割点后,当前[BreakIterator](#breakiterator8)在文本中的位置。若移动index个分割点后超出了所处理的文本的长度范围,返回-1。 | - -- 示例: - ``` - iterator = I18n.getLineInstance("en"); - iterator.setLineBreakText("Apple is my favorite fruit."); - iterator.first(); // 0 - iterator.next(); // 6 - iterator.next(10); // -1 - ``` - - -### previous8+ - -previous(): number - -将[BreakIterator](#breakiterator8)移动到前一个分割点处。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 返回移动到前一个分割点后,当前[BreakIterator](#breakiterator8)在文本中的位置。若移动index个分割点后超出了所处理的文本的长度范围,返回-1。 | - -- 示例: - ``` - iterator = I18n.getLineInstance("en"); - iterator.setLineBreakText("Apple is my favorite fruit."); - iterator.first(); // 0 - iterator.next(3); // 12 - iterator.previous(); // 9 - ``` - - -### following8+ - -following(offset: number): number - -将[BreakIterator](#breakiterator8)设置到由offset指定的位置的后面一个分割点。返回移动后[BreakIterator](#breakiterator8)的位置。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | offset | number | 是 | 将[BreakIterator](#breakiterator8)对象的位置设置到由offset所指定的位置的下一个分割点。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 返回[BreakIterator](#breakiterator8)移动后的位置,如果由offset所指定的位置的下一个分割点超出了文本的范围则返回-1。 | - -- 示例: - ``` - iterator = I18n.getLineInstance("en"); - iterator.setLineBreakText("Apple is my favorite fruit."); - iterator.following(0); // 6 - iterator.following(100); // -1 - iterator.current(); // 27 - ``` - - -### isBoundary8+ - -isBoundary(offset: number): boolean - -如果offset所指定的文本位置是一个分割点,那么返回true,否则返回false。如果返回true, 将[BreakIterator](#breakiterator8)对象设置到offset所指定的位置, 否则相当于调用[following](#following8)(offset)。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | offset | number | 是 | 指定需要进行判断的位置 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 如果是一个分割点返回true, 否则返回false。 | - -- 示例: - ``` - iterator = I18n.getLineInstance("en"); - iterator.setLineBreakText("Apple is my favorite fruit."); - iterator.isBoundary(0); // true; - iterator.isBoundary(5); // false; - ``` - - -## i18n.is24HourClock - -is24HourClock(): boolean - -判断系统时间是否为24小时制。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 返回true,表示系统24小时开关开启;返回false,表示系统24小时开关关闭。 | - -- 示例: - ``` - var is24HourClock = i18n.is24HourClock(); - ``` - - -## i18n.set24HourClock - -set24HourClock(option: boolean): boolean - -修改系统时间的24小时制设置。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | option | boolean | 是 | option为true,表示开启系统24小时制开关;返回false,表示关闭系统24小时开关。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 返回true,表示修改成功;返回false,表示修改失败。 | - -- 示例: - ``` - // 将系统时间设置为24小时制 - var success = I18n.set24HourClock(true); - ``` - - -## i18n.addPreferredLanguage - -addPreferredLanguage(language: string, index?: number): boolean - -在系统偏好语言列表中的指定位置添加偏好语言。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | language | string | 是 | 待添加的偏好语言。 | - | index | number | 否 | 偏好语言的添加位置。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 返回true,表示添加成功;返回false,表示添加失败。 | - -- 示例: - ``` - // 将语言zh-CN添加到系统偏好语言列表中 - var language = 'zh-CN'; - var index = 0; - var success = i18n.addPreferredLanguage(language, index); - ``` - - -## i18n.removeDisplayLanguage - -removeDisplayLanguage(index: number): boolean - -删除系统偏好语言列表中指定位置的偏好语言。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | index | number | 是 | 待删除偏好语言在系统偏好语言列表中的位置。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 返回true,表示删除成功;返回false,表示删除失败。 | - -- 示例: - ``` - // 删除系统偏好语言列表中的第一个偏好语言 - var index = 0; - var success = i18n.removePreferredLanguage(index); - ``` - - -## i18n.getPreferredLanguageList - -getPreferredLanguageList(): Array - -获取系统偏好语言列表。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Array | 系统偏好语言列表。 | - -- 示例: - ``` - var preferredLanguageList = i18n.getPreferredLanguageList(); - ``` - - -## i18n.getFirstPreferredLanguage - -getFirstPreferredLanguage(): string - -获取与Hap资源最佳匹配的偏好语言。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string | Hap资源最佳匹配的偏好语言。 | - -- 示例: - ``` - var firstPreferredLanguage = i18n.getFirstPreferredLanguage(); - ``` \ No newline at end of file diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/02.\350\265\204\346\272\220\347\256\241\347\220\206/03.\345\233\275\351\231\205\345\214\226\357\274\210Intl\357\274\211.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/02.\350\265\204\346\272\220\347\256\241\347\220\206/03.\345\233\275\351\231\205\345\214\226\357\274\210Intl\357\274\211.md" deleted file mode 100644 index 49a60eb7711fdf6f8e7b1af12c06eee3ff58ceb3..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/02.\350\265\204\346\272\220\347\256\241\347\220\206/03.\345\233\275\351\231\205\345\214\226\357\274\210Intl\357\274\211.md" +++ /dev/null @@ -1,649 +0,0 @@ ---- -title: 国际化(Intl) -permalink: /pages/010c010203 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 国际化-Intl - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> - 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 -> -> - Intl模块包含国际化能力基础接口(在ECMA 402中定义)。 - - -## 导入模块 - -``` -import Intl from '@ohos.intl'; -``` - - -## 权限列表 - -无 - - -## Locale - - -### 属性 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| language | string | 是 | 否 | 与区域设置关联的语, 如:zh。 | -| script | string | 是 | 否 | 语言的书写方式,如:Hans。 | -| region | string | 是 | 否 | 与区域设置相关的地区,如:CN。 | -| baseName | string | 是 | 否 | Locale的基本核心信息(由语言脚本与地区组成),如:zh-Hans-CN。 | -| caseFirst | string | 是 | 否 | 区域的整理规则是否考虑大小写,取值包括:"upper", "lower", "false"。 | -| calendar | string | 是 | 否 | 区域的日历信息,取值包括:"buddhist", "chinese", "coptic","dangi", "ethioaa", "ethiopic", "gregory", "hebrew", "indian", "islamic", "islamic-umalqura", "islamic-tbla", "islamic-civil", "islamic-rgsa", "iso8601", "japanese", "persian", "roc", "islamicc"。 | -| collation | string | 是 | 否 | 区域的排序规则,取值包括:"big5han", "compat", "dict", "direct", "ducet", "eor", "gb2312", "phonebk", "phonetic", "pinyin", "reformed", "searchjl", "stroke", "trad", "unihan", "zhuyin"。 | -| hourCycle | string | 是 | 否 | 区域的时制信息,取值包括:"h12", "h23", "h11", "h24"。 | -| numberingSystem | string | 是 | 否 | 区域使用的数字系统,取值包括:"adlm", "ahom", "arab", "arabext", "bali", "beng", "bhks", "brah", "cakm", "cham", "deva", "diak", "fullwide", "gong", "gonm", "gujr", "guru", "hanidec", "hmng", "hmnp", "java", "kali", "khmr", "knda", "lana", "lanatham", "laoo", "latn", "lepc", "limb", "mathbold", "mathdbl", "mathmono", "mathsanb", "mathsans", "mlym", "modi", "mong", "mroo", "mtei", "mymr", "mymrshan", "mymrtlng", "newa", "nkoo", "olck", "orya", "osma", "rohg", "saur", "segment", "shrd", "sind", "sinh", "sora", "sund", "takr", "talu", "tamldec", "telu", "thai", "tibt", "tirh", "vaii", "wara", "wcho"。 | -| numeric | boolean | 是 | 否 | 是否对数字字符具有特殊的排序规则处理。 | - - -### constructor - -constructor(locale: string, options?: options) - -创建区域对象 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | locale | string | 是 | 包含区域设置信息的字符串,包括语言以及可选的脚本和区域。 | - | options | options | 否 | 用于创建区域对象的选项。 | - -- 示例: - ``` - var locale = new Intl.Locale("zh-CN"); - ``` - - -### toString - -toString(): string - -将区域信息转换为字符串 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string | 字符串形式的区域信息。 | - -- 示例: - ``` - var locale = new Intl.Locale("zh-CN"); - locale.toString(); - ``` - - -### maximize - -maximize(): Locale - -最大化区域信息,若缺少脚本与地区信息,则补齐。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [Locale](#locale) | 最大化后的区域对象。 | - -- 示例: - ``` - var locale = new Intl.Locale("zh-CN"); - locale.maximize(); - ``` - - -### minimize - -minimize(): Locale - -最小化区域信息,若包含脚本与地区信息,则去除。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [Locale](#locale) | 最小化后的区域对象。 | - -- 示例: - ``` - var locale = new Intl.Locale("zh-CN"); - locale.minimize(); - ``` - - -## DateTimeFormat - - -### constructor - -constructor(locale: string, options?: DateTimeOptions) - -创建时间日期格式化对象。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | locale | string | 是 | 包含区域设置信息的字符串,包括语言以及可选的脚本和区域。 | - | options | [DateTimeOptions](#datetimeoptions) | 否 | 用于创建时间日期格式化的选项。 | - -- 示例: - ``` - var datefmt= new Intl.DateTimeFormat("zh-CN", { dateStyle: 'full', timeStyle: 'medium' }); - ``` - - -### constructor - -constructor(locales: Array<string>, options?: DateTimeOptions) - -创建时间日期格式化对象。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | locales | Array<string> | 是 | 包含区域设置信息的字符串的数组。 | - | options | [DateTimeOptions](#datetimeoptions) | 否 | 用于创建时间日期格式化的选项。 | - -- 示例: - ``` - var datefmt= new Intl.DateTimeFormat(["ban", "zh"], { dateStyle: 'full', timeStyle: 'medium' }); - ``` - - -### format - -format(date: Date): string - -格式化时间日期字符串。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | date | Date | 是 | 时间日期对象。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string | 格式化后的时间日期字符串 | - -- 示例: - ``` - var date = new Date(2021, 11, 17, 3, 24, 0); - var datefmt = new Intl.DateTimeFormat("en-GB"); - datefmt.format(date); - ``` - - -### formatRange - -formatRange(fromDate: Date, toDate: Date): string - -格式化时间日期段字符串。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | startDate | Date | 是 | 起始的时间日期。 | - | endDate | Date | 是 | 结束的时间日期。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string | 格式化后的时间日期段字符串。 | - -- 示例: - ``` - var startDate = new Date(2021, 11, 17, 3, 24, 0); - var endDate = new Date(2021, 11, 18, 3, 24, 0); - var datefmt = new Intl.DateTimeFormat("en-GB"); - datefmt.formatRange(startDate, endDate); - ``` - - -### resolvedOptions - -resolvedOptions(): DateTimeOptions - -获取DateTimeFormat对象的格式化选项。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [DateTimeOptions](#datetimeoptions) | DateTimeFormat 对象的格式化选项。 | - -- 示例: - ``` - var datefmt = new Intl.DateTimeFormat("en-GB"); - datefmt.resolvedOptions(); - ``` - - -## DateTimeOptions - -表示时间日期格式化选项。 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| locale | string | 是 | 否 | 区域参数, 如:zh-Hans-CN。 | -| dateStyle | string | 是 | 是 | 日期显示格式,取值包括:"long", "short", "medium", "full"。 | -| timeStyle | string | 是 | 是 | 时间显示格式,取值包括:"long", "short", "medium", "full"。 | -| hourCycle | string | 是 | 是 | 时制格式,取值包括:"h11", "h12", "h23", "h24"。 | -| timeZone | string | 是 | 是 | 使用的时区(合法的IANA时区ID)。 | -| numberingSystem | string | 是 | 是 | 数字系统,取值包括:"adlm", "ahom", "arab", "arabext", "bali", "beng", "bhks", "brah", "cakm", "cham", "deva", "diak", "fullwide", "gong", "gonm", "gujr", "guru", "hanidec", "hmng", "hmnp", "java", "kali", "khmr", "knda", "lana", "lanatham", "laoo", "latn", "lepc", "limb", "mathbold", "mathdbl", "mathmono", "mathsanb", "mathsans", "mlym", "modi", "mong", "mroo", "mtei", "mymr", "mymrshan", "mymrtlng", "newa", "nkoo", "olck", "orya", "osma", "rohg", "saur", "segment", "shrd", "sind", "sinh", "sora", "sund", "takr", "talu", "tamldec", "telu", "thai", "tibt", "tirh", "vaii", "wara", "wcho"。 | -| hour12 | boolean | 是 | 是 | 是否使用12小时制。 | -| weekday | string | 是 | 是 | 工作日的显示格式,取值包括:"long", "short", "narrow"。 | -| era | string | 是 | 是 | 时代的显示格式,取值包括:"long", "short", "narrow"。 | -| year | string | 是 | 是 | 年份的显示格式,取值包括:"numeric", "2-digit"。 | -| month | string | 是 | 是 | 月份的显示格式,取值包括:"numeric", "2-digit", "long", "short", "narrow"。 | -| day | string | 是 | 是 | 日期的显示格式,取值包括:"numeric", "2-digit"。 | -| hour | string | 是 | 是 | 小时的显示格式,取值包括:"numeric", "2-digit"。 | -| minute | string | 是 | 是 | 分钟的显示格式,取值包括:"numeric", "2-digit"。 | -| second | string | 是 | 是 | 秒钟的显示格式,取值包括:"numeric", "2-digit"。 | -| timeZoneName | string | 是 | 是 | 时区名称的本地化表示。 | -| dayPeriod | string | 是 | 是 | 时段的显示格式,取值包括:"long", "short", "narrow"。 | -| localeMatcher | string | 是 | 是 | 要使用的区域匹配算法,取值包括:"lookup", "best fit"。 | -| formatMatcher | string | 是 | 是 | 要使用的格式匹配算法,取值包括:"basic", "best fit"。 | - - -## NumberFormat - - -### constructor - -constructor(locale: string, options?: NumberOptions) - -创建数字格式化对象。 - -参数: -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| locale | string | 是 | 包含区域设置信息的字符串,包括语言以及可选的脚本和区域。 | -| options | [NumberOptions](#numberoptions) | 否 | 用于创建数字格式化的选项。 | - -- 示例: - ``` - var numfmt = new Intl.NumberFormat("en-GB", {style:'decimal', notation:"scientific"}); - ``` - - -### constructor - -constructor(locales: Array<string>, options?: NumberOptions) - -创建数字格式化对象。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | locales | Array<string> | 是 | 包含区域设置信息的字符串的数组。 | - | options | [NumberOptions](#numberoptions) | 否 | 用于创建数字格式化的选项。 | - -- 示例: - ``` - var numfmt = new Intl.NumberFormat(["en-GB", "zh"], {style:'decimal', notation:"scientific"}); - ``` - - -### format - -format(number: number): string; - -格式化数字字符串。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | number | number | 是 | 数字对象 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string | 格式化后的数字字符串 | - - -- 示例: - ``` - var numfmt = new Intl.NumberFormat(["en-GB", "zh"], {style:'decimal', notation:"scientific"}); - numfmt.format(1223); - ``` - - -### resolvedOptions - -resolvedOptions(): NumberOptions - -获取NumberFormat 对象的格式化选项。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [NumberOptions](#numberoptions) | NumberFormat 对象的格式化选项。 | - - -- 示例: - ``` - var numfmt = new Intl.NumberFormat(["en-GB", "zh"], {style:'decimal', notation:"scientific"}); - numfmt.resolvedOptions(); - ``` - - -## NumberOptions - -表示设备支持的能力。 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| locale | string | 是 | 否 | 区域参数, 如:"zh-Hans-CN"。 | -| currency | string | 是 | 是 | 货币单位, 如:"EUR","CNY","USD"等。 | -| currencySign | string | 是 | 是 | 货币单位的符号显示,取值包括: "symbol","narrowSymbol","code","name" 。 | -| currencyDisplay | string | 是 | 是 | 货币的显示方式,取值包括:"symbol", "narrowSymbol", "code", "name"。 | -| unit | string | 是 | 是 | 单位名称,如:"meter","inch",“hectare”等。 | -| unitDisplay | string | 是 | 是 | 单位的显示格式,取值包括:"long", "short", "medium"。 | -| unitUsage | string | 是 | 是 | 单位的使用场景,取值包括:"default", "area-land-agricult", "area-land-commercl", "area-land-residntl", "length-person", "length-person-small", "length-rainfall", "length-road", "length-road-small", "length-snowfall", "length-vehicle", "length-visiblty", "length-visiblty-small", "length-person-informal", "length-person-small-informal", "length-road-informal", "speed-road-travel", "speed-wind", "temperature-person", "temperature-weather", "volume-vehicle-fuel"。 | -| signDisplay | string | 是 | 是 | 数字符号的显示格式,取值包括:"auto", "never", "always", "expectZero"。 | -| compactDisplay | string | 是 | 是 | 紧凑型的显示格式,取值包括:"long", "short"。 | -| notation | string | 是 | 是 | 数字的格式化规格,取值包括:"standard", "scientific", "engineering", "compact"。 | -| localeMatcher | string | 是 | 是 | 要使用的区域匹配算法,取值包括:"lookup", "best fit"。 | -| style | string | 是 | 是 | 数字的显示格式,取值包括:"decimal", "currency", "percent", "unit"。 | -| numberingSystem | string | 是 | 是 | 数字系统,取值包括:"adlm", "ahom", "arab", "arabext", "bali", "beng", "bhks", "brah", "cakm", "cham", "deva", "diak", "fullwide", "gong", "gonm", "gujr", "guru", "hanidec", "hmng", "hmnp", "java", "kali", "khmr", "knda", "lana", "lanatham", "laoo", "latn", "lepc", "limb", "mathbold", "mathdbl", "mathmono", "mathsanb", "mathsans", "mlym", "modi", "mong", "mroo", "mtei", "mymr", "mymrshan", "mymrtlng", "newa", "nkoo", "olck", "orya", "osma", "rohg", "saur", "segment", "shrd", "sind", "sinh", "sora", "sund", "takr", "talu", "tamldec", "telu", "thai", "tibt", "tirh", "vaii", "wara", "wcho"。 | -| useGrouping | boolean | 是 | 是 | 是否分组显示。 | -| miniumumIntegerDigits | number | 是 | 是 | 表示要使用的最小整数位数,取值范围:1~21。 | -| miniumumFractionDigits | number | 是 | 是 | 表示要使用的最小分数位数,取值范围:0~20。 | -| maxiumumFractionDigits | number | 是 | 是 | 表示要使用的最大分数位数,取值范围:1~21。 | -| miniumumSignificantDigits | number | 是 | 是 | 表示要使用的最低有效位数,取值范围:1~21。 | -| maxiumumSignificantDigits | number | 是 | 是 | 表示要使用的最大有效位数,取值范围:1~21。 | - - -## Collator8+ - - -### constructor8+ - -constructor() - -创建排序对象。 - -- 示例: - ``` - var collator = new Intl.Collator(); - ``` - - -### constructor8+ - -constructor(locale: string | Array<string>, options?: CollatorOptions) - -创建排序对象。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | locale | string\|Array<string> | 是 | 包含区域设置信息的字符串,包括语言以及可选的脚本和区域。 | - | options | [CollatorOptions](#collatoroptions) | 否 | 用于创建排序对象的选项。 | - -- 示例: - ``` - var collator = new Intl.Collator("zh-CN", {"localeMatcher": "lookup", "usage": "sort"}); - ``` - - -### compare8+ - -compare(first: string, second: string): number - -依据Collator的排序策略对两个字符串进行比较。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | first | string | 是 | 进行比较第一个字符串。 | - | second | string | 是 | 进行比较的第二个字符串。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 比较结果。当number为负数,表示first排序在second之前;当number为0,表示first与second排序相同;当number为正数,表示first排序在second之后。 | - -- 示例: - ``` - var collator = new Intl.Collator("zh-Hans"); - collator.compare("first", "second"); - ``` - - -### resolvedOptions8+ - -resolvedOptions(): CollatorOptions - -返回Collator对象的属性。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [CollatorOptions](#collatoroptions) | 返回的Collator对象的属性。 | - -- 示例: - ``` - var collator = new Intl.Collator("zh-Hans"); - var options = collator.resolvedOptions(); - ``` - - -## CollatorOptions8+ - -表示Collator可设置的属性。 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| localeMatcher | string | 是 | 是 | locale匹配算法,取值范围:"best fit", "lookup"。 | -| usage | string | 是 | 是 | 比较的用途,取值范围:"sort", "search"。 | -| sensitivity | string | 是 | 是 | 表示字符串中的哪些差异会导致非零结果值,取值范围:"base", "accent", "case", "variant"。 | -| ignorePunctuation | boolean | 是 | 是 | 表示是否忽略标点符号,取值范围:true, false。 | -| collation | string | 是 | 是 | 排序规则,取值范围:"big5han", "compat", "dict", "direct", "ducet", "eor", "gb2312", "phonebk", "phonetic", "pinyin", "reformed", "searchjl", "stroke", "trad", "unihan", "zhuyin"。 | -| numeric | boolean | 是 | 是 | 是否使用数字排序,取值范围:true, false。 | -| caseFirst | string | 是 | 是 | 表示大写、小写的排序顺序,取值范围:"upper", "lower", "false"。 | - - -## PluralRules8+ - - -### constructor8+ - -constructor() - -创建PluralRules对象。 - -- 示例: - ``` - var pluralRules = new Intl.PluralRules(); - ``` - - -### constructor8+ - -constructor(locale: string | Array<string>, options?: PluralRulesOptions) - -创建PluralRules对象。 - -参数: -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| locale | string\|Array<string> | 是 | 包含区域设置信息的字符串,包括语言以及可选的脚本和区域。 | -| options | [PluralRulesOptions](#pluralrulesoptions) | 否 | 用于创建单复数对象的选项。 | - -- 示例: - ``` - var pluralRules= new Intl.PluraRules("zh-CN", {"localeMatcher": "lookup", "type": "cardinal"}); - ``` - - -### select8+ - -select(n: number): string - -返回一个字符串表示该数字的单复数类别。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | n | number | 是 | 待获取单复数类别的数字。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string | 单复数类别,取值包括:"zero","one","two", "few", "many", "others"。 | - -- 示例: - ``` - var pluralRules = new Intl.PluralRules("zh-Hans"); - pluralRules.select(1); - ``` - - -## PluralRulesOptions8+ - -表示PluralRules对象可设置的属性。 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| localeMatcher | string | 是 | 是 | locale匹配算法,取值包括:"best fit", "lookup"。 | -| type | string | 是 | 是 | 排序的类型,取值包括:"cardinal", "ordinal"。 | -| minimumIntegerDigits | number | 是 | 是 | 表示要使用的最小整数位数,取值范围:1~21。 | -| minimumFractionDigits | number | 是 | 是 | 表示要使用的最小分数位数,取值范围:0~20。 | -| maximumFractionDigits | number | 是 | 是 | 表示要使用的最大分数位数,取值范围:1~21。 | -| minimumSignificantDigits | number | 是 | 是 | 表示要使用的最低有效位数,取值范围:1~21。 | -| maximumSignificantDigits | number | 是 | 是 | 表示要使用的最大有效位数,取值范围:1~21。 | - - -## RelativeTimeFormat8+ - - -### constructor8+ - -constructor() - -创建相对时间格式化对象。 - -- 示例: - ``` - var relativetimefmt = new Intl.RelativeTimeFormat(); - ``` - - -### constructor8+ - -constructor(locale: string | Array<string>, options?: RelativeTimeFormatInputOptions) - -创建相对时间格式化对象。 - -参数: -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| locale | string\|Array<string> | 是 | 包含区域设置信息的字符串,包括语言以及可选的脚本和区域。 | -| options | [RelativeTimeFormatInputOptions](#relativetimeformatinputoptions) | 否 | 用于创建相对时间格式化对象的选项。 | - -- 示例: - ``` - var relativeTimeFormat = new Intl.RelativeTimeFormat("zh-CN", {"localeMatcher": "lookup", "numeric": "always", "style": "long"}); - ``` - - -### format8+ - -format(value: numeric, unit: string): string - -依据locale和格式化选项,对value和unit进行格式化。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | numeric | 是 | 相对时间格式化的数值。 | - | unit | string | 是 | 相对时间格式化的单位,取值包括:"year", "quarter", "month", "week", "day", "hour", "minute", "second"。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string | 格式化后的相对时间。 | - -- 示例: - ``` - var relativetimefmt = new Intl.RelativeTimeFormat("zh-CN"); - relativetimefmt.format(3, "quarter") - ``` - - -### formatToParts8+ - -formatToParts(value: numeric, unit: string): Array<Object> - -返回一个对象数组,表示可用于自定义区域设置格式的相对时间格式。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | numeric | 是 | 相对时间格式化的数值。 | - | unit | string | 是 | 相对时间格式化的单位,取值包括:"year", "quarter", "month", "week", "day", "hour", "minute", "second"。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Array<Object> | 返回可用于自定义区域设置格式的相对时间格式的对象数组。 | - -- 示例: - ``` - var relativetimefmt = new Intl.RelativeTimeFormat("en", {"numeric": "auto"}); - var parts = relativetimefmt.format(10, "seconds"); - ``` - - -### resolvedOptions8+ - -resolvedOptions(): RelativeTimeFormatResolvedOptions - -获取RelativeTimeFormat对象的格式化选项。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [RelativeTimeFormatResolvedOptions](#relativetimeformatresolvedoptions) | RelativeTimeFormat 对象的格式化选项。 | - -- 示例: - ``` - var relativetimefmt= new Intl.RelativeTimeFormat("en-GB"); - relativetimefmt.resolvedOptions(); - ``` - - -## RelativeTimeFormatInputOptions8+ - -表示RelativeTimeFormat对象可设置的属性。 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| localeMatcher | string | 是 | 是 | locale匹配算法,取值包括:"best fit", "lookup"。 | -| numeric | string | 是 | 是 | 输出消息的格式,取值包括:"always", "auto"。 | -| style | string | 是 | 是 | 国际化消息的长度,取值包括:"long", "short", "narrow"。 | - - -## RelativeTimeFormatResolvedOptions8+ - -表示RelativeTimeFormat对象可设置的属性。 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| locale | string | 是 | 是 | 包含区域设置信息的字符串,包括语言以及可选的脚本和区域。 | -| numeric | string | 是 | 是 | 输出消息的格式,取值包括:"always", "auto"。 | -| style | string | 是 | 是 | 国际化消息的长度,取值包括:"long", "short", "narrow"。 | -| numberingSystem | string | 是 | 是 | 使用的数字系统。 | diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/03.\345\252\222\344\275\223/01.\351\237\263\351\242\221\347\256\241\347\220\206.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/03.\345\252\222\344\275\223/01.\351\237\263\351\242\221\347\256\241\347\220\206.md" deleted file mode 100644 index df86bdea7305801076a638a782bcb0ca513c55ea..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/03.\345\252\222\344\275\223/01.\351\237\263\351\242\221\347\256\241\347\220\206.md" +++ /dev/null @@ -1,973 +0,0 @@ ---- -title: 音频管理 -permalink: /pages/010c010301 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 音频管理 - -## 导入模块 - -``` -import audio from '@ohos.multimedia.audio'; -``` - - -## getAudioManager - -getAudioManager(): AudioManager - -获取音频管理器。 - -**返回值:** -| 类型 | 说明 | -| -------- | -------- | -| [AudioManager](#audiomanager) | 音频管理类。 | - -**示例:** -``` -var audioManager = audio.getAudioManager(); -``` - - -## AudioVolumeType - -枚举,音频流类型。 - -| 名称 | 默认值 | 描述 | -| -------- | -------- | -------- | -| RINGTONE | 2 | 表示铃声。 | -| MEDIA | 3 | 表示媒体。 | - - -## DeviceFlag - -枚举,可获取的设备种类。 - -| 名称 | 默认值 | 描述 | -| -------- | -------- | -------- | -| OUTPUT_DEVICES_FLAG | 1 | 表示输出设备种类。 | -| INPUT_DEVICES_FLAG | 2 | 表示输入设备种类。 | -| ALL_DEVICES_FLAG | 3 | 表示所有设备种类。 | - - -## DeviceRole - -枚举,设备角色。 - -| 名称 | 默认值 | 描述 | -| -------- | -------- | -------- | -| INPUT_DEVICE | 1 | 输入设备角色。 | -| OUTPUT_DEVICE | 2 | 输出设备角色。 | - - -## DeviceType - -枚举,设备类型。 - -| 名称 | 默认值 | 描述 | -| -------------- | ------ | ------------------------------------------------------- | -| INVALID | 0 | 无效设备。 | -| EARPIECE | 1 | 听筒。 | -| SPEAKER | 2 | 扬声器。 | -| WIRED_HEADSET | 3 | 有线耳机。 | -| BLUETOOTH_SCO | 7 | 蓝牙设备SCO连接(Synchronous Connection Oriented)。 | -| BLUETOOTH_A2DP | 8 | 蓝牙设备A2DP连接(Advanced Audio Distribution Profile)。 | -| MIC | 15 | 麦克风。 | - -## ActiveDeviceType7+ - -枚举,活跃设备类型。 - -| 名称 | 默认值 | 描述 | -| ------------- | ------ | -------------------------------------------------- | -| SPEAKER | 2 | 扬声器。 | -| BLUETOOTH_SCO | 7 | 蓝牙设备SCO连接(Synchronous Connection Oriented)。 | - -## AudioRingMode7+ - -枚举,铃声模式。 - -| 名称 | 默认值 | 描述 | -| -------- | -------- | -------- | -| RINGER_MODE_SILENT | 0 | 静音模式 | -| RINGER_MODE_VIBRATE | 1 | 震动模式 | -| RINGER_MODE_NORMAL | 2 | 响铃模式 | - - -## AudioManager - -管理音频音量和音频设备。 - -### setVolume - -setVolume(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback<void>): void - -设置指定流的音量,使用callback方式返回异步结果。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 | -| volume | number | 是 | 音量等级,可设置范围通过getMinVolume和getMaxVolume获取。 | -| callback | AsyncCallback<void> | 是 | 回调表示成功还是失败。 | - -**示例:** - -``` -var audioManager = audio.getAudioManager(); -audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err)=>{ - if (err) { - console.error('Failed to set the volume. ${err.message}'); - return; - } - console.log('Callback invoked to indicate a successful volume setting.'); -}) -``` - -### setVolume - -setVolume(volumeType: AudioVolumeType, volume: number): Promise<void> - -设置指定流的音量,使用promise方式返回异步结果。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 | -| volume | number | 是 | 音量等级,可设置范围通过getMinVolume和getMaxVolume获取。 | - -**返回值:** - -| 类型 | 说明 | -| -------- | -------- | -| Promise<void> | Promise回调表示成功还是失败。 | - -**示例:** - -``` -var audioManager = audio.getAudioManager(); -audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(()=> - console.log('Promise returned to indicate a successful volume setting.'); -) -``` - -### getVolume - -getVolume(volumeType: AudioVolumeType, callback: AsyncCallback<number>): void - -获取指定流的音量,使用callback方式返回异步结果。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 | -| callback | AsyncCallback<number> | 是 | 回调返回音量大小。 | - -**示例:** - -``` -var audioManager = audio.getAudioManager(); -audioManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => { - if (err) { - console.error('Failed to obtain the volume. ${err.message}'); - return; - } - console.log('Callback invoked to indicate that the volume is obtained.'); -}) -``` - -### getVolume - -getVolume(volumeType: AudioVolumeType): Promise<number> - -获取指定流的音量,使用promise方式返回异步结果。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 | - -**返回值:** - -| 类型 | 说明 | -| -------- | -------- | -| Promise<number> | Promise回调返回音量大小。 | - -**示例:** - -``` -var audioManager = audio.getAudioManager(); -audioManager.getVolume(audio.AudioVolumeType.MEDIA).then((value) => - console.log('Promise returned to indicate that the volume is obtained.' + value); -) -``` - -### getMinVolume - -getMinVolume(volumeType: AudioVolumeType, callback: AsyncCallback<number>): void - -获取指定流的最小音量,使用callback方式返回异步结果。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 | -| callback | AsyncCallback<number> | 是 | 回调返回最小音量。 | - -**示例:** - -``` -var audioManager = audio.getAudioManager(); -audioManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err, value) => { - if (err) { - console.error('Failed to obtain the minimum volume. ${err.message}'); - return; - } - console.log('Callback invoked to indicate that the minimum volume is obtained.' + value); -}) -``` - -### getMinVolume - -getMinVolume(volumeType: AudioVolumeType): Promise<number> - -获取指定流的最小音量,使用promise方式返回异步结果。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 | - -**返回值:** - -| 类型 | 说明 | -| -------- | -------- | -| Promise<number> | Promise回调返回最小音量。 | - -**示例:** - -``` -var audioManager = audio.getAudioManager(); -audioManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value) => - console.log('Promised returned to indicate that the minimum volume is obtained.' + value); -) -``` - -### getMaxVolume - -getMaxVolume(volumeType: AudioVolumeType, callback: AsyncCallback<number>): void - -获取指定流的最大音量,使用callback方式返回异步结果。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 | -| callback | AsyncCallback<number> | 是 | 回调返回最大音量大小。 | - -**示例:** - -``` -var audioManager = audio.getAudioManager(); -audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err, value) => { - if (err) { - console.error('Failed to obtain the maximum volume. ${err.message}'); - return; - } - console.log('Callback invoked to indicate that the maximum volume is obtained.' + value); -}) -``` - -### getMaxVolume - -getMaxVolume(volumeType: AudioVolumeType): Promise<number> - -获取指定流的最大音量,使用promise方式返回异步结果。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 | - -**返回值:** - -| 类型 | 说明 | -| -------- | -------- | -| Promise<number> | Promise回调返回最大音量大小。 | - -**示例:** - -``` -var audioManager = audio.getAudioManager(); -audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data)=> - console.log('Promised returned to indicate that the maximum volume is obtained.'); -) -``` - -### mute7+ - -mute(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback<void>): void - -设置指定音量流静音,使用callback方式返回异步结果。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 | -| mute | boolean | 是 | 静音状态,true为静音,false为非静音。 | -| callback | AsyncCallback<void> | 是 | 回调表示成功还是失败。 | - -**示例:** - -``` -var audioManager = audio.getAudioManager(); -audioManager.mute(audio.AudioVolumeType.MEDIA, true, (err) => { - if (err) { - console.error('Failed to mute the stream. ${err.message}'); - return; - } - console.log('Callback invoked to indicate that the stream is muted.'); -}) -``` - -### mute7+ - -mute(volumeType: AudioVolumeType, mute: boolean): Promise<void> - -设置指定音量流静音,使用promise方式返回异步结果。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 | -| mute | boolean | 是 | 静音状态,true为静音,false为非静音。 | - -**返回值:** - -| 类型 | 说明 | -| -------- | -------- | -| Promise<void> | Promise回调表示成功还是失败。 | - -**示例:** - - -``` -var audioManager = audio.getAudioManager(); -audioManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => - console.log('Promise returned to indicate that the stream is muted.'); -) -``` - - -### isMute7+ - -isMute(volumeType: AudioVolumeType, callback: AsyncCallback<boolean>): void - -获取指定音量流是否被静音,使用callback方式返回异步结果。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 | -| callback | AsyncCallback<boolean> | 是 | 回调返回流静音状态,true为静音,false为非静音。 | - -**示例:** - -``` -var audioManager = audio.getAudioManager(); -audioManager.isMute(audio.AudioVolumeType.MEDIA, (err, value) => { - if (err) { - console.error('Failed to obtain the mute status. ${err.message}'); - return; - } - console.log('Callback invoked to indicate that the mute status of the stream is obtained.' + value); -}) -``` - - -### isMute7+ - -isMute(volumeType: AudioVolumeType): Promise<boolean> - -获取指定音量流是否被静音,使用promise方式返回异步结果。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 | - -**返回值:** - -| 类型 | 说明 | -| -------- | -------- | -| Promise<boolean> | Promise回调返回流静音状态,true为静音,false为非静音。 | - -**示例:** - -``` -var audioManager = audio.getAudioManager(); -audioManager.isMute(audio.AudioVolumeType.MEDIA).then((value) => - console.log('Promise returned to indicate that the mute status of the stream is obtained.' + value); -) -``` - -### isActive7+ - -isActive(volumeType: AudioVolumeType, callback: AsyncCallback<boolean>): void - -获取指定音量流是否为活跃状态,使用callback方式返回异步结果。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 | -| callback | AsyncCallback<boolean> | 是 | 回调返回流的活跃状态,true为活跃,false为不活跃。 | - -**示例:** - -``` -var audioManager = audio.getAudioManager(); -audioManager.isActive(audio.AudioVolumeType.MEDIA, (err, value) => { - if (err) { - console.error('Failed to obtain the active status of the stream. ${err.message}'); - return; - } - console.log('Callback invoked to indicate that the active status of the stream is obtained.' + value); -}) -``` - -### isActive7+ - -isActive(volumeType: AudioVolumeType): Promise<boolean> - -获取指定音量流是否为活跃状态,使用promise方式返回异步结果。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 | - -**返回值:** - -| 类型 | 说明 | -| -------- | -------- | -| Promise<boolean> | Promise回调返回流的活跃状态,true为活跃,false为不活跃。 | - -**示例:** - -``` -var audioManager = audio.getAudioManager(); -audioManager.isActive(audio.AudioVolumeType.MEDIA).then((value) => - console.log('Promise returned to indicate that the active status of the stream is obtained.' + value); -) -``` - -### setRingerMode7+ - -setRingerMode(mode: AudioRingMode, callback: AsyncCallback<void>): void - -设置铃声模式,使用callback方式返回异步结果。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| mode | [AudioRingMode](#audioringmode) | 是 | 音频铃声模式。 | -| callback | AsyncCallback<void> | 是 | 回调返回设置成功或失败。 | - -**示例:** - -``` -var audioManager = audio.getAudioManager(); -audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err) => { - if (err) { - console.error('Failed to set the ringer mode.​ ${err.message}'); - return; - } - console.log('Callback invoked to indicate a successful setting of the ringer mode.'); -}) -``` - -### setRingerMode7+ - -setRingerMode(mode: AudioRingMode): Promise<void> - -设置铃声模式,使用promise方式返回异步结果。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| mode | [AudioRingMode](#audioringmode) | 是 | 音频铃声模式。 | - -**返回值:** - -| 类型 | 说明 | -| -------- | -------- | -| Promise<void> | Promise回调返回设置成功或失败。 | - -**示例:** - -``` -var audioManager = audio.getAudioManager(); -audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => - console.log('Promise returned to indicate a successful setting of the ringer mode.'); -) -``` - - -### getRingerMode7+ - -getRingerMode(callback: AsyncCallback<AudioRingMode>): void - -获取铃声模式,使用callback方式返回异步结果。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| callback | AsyncCallback<[AudioRingMode](#audioringmode)> | 是 | 回调返回系统的铃声模式。 | - -**示例:** - -``` -var audioManager = audio.getAudioManager(); -audioManager.getRingerMode((err, value) => { - if (err) { - console.error('Failed to obtain the ringer mode.​ ${err.message}'); - return; - } - console.log('Callback invoked to indicate that the ringer mode is obtained.' + value); -}) -``` - - -### getRingerMode7+ - -getRingerMode(): Promise<AudioRingMode> - -获取铃声模式,使用promise方式返回异步结果。 - -**返回值:** - -| 类型 | 说明 | -| -------- | -------- | -| Promise<[AudioRingMode](#audioringmode)> | Promise回调返回系统的铃声模式。 | - -**示例:** - -``` -var audioManager = audio.getAudioManager(); -audioManager.getRingerMode().then((value) => - console.log('Promise returned to indicate that the ringer mode is obtained.' + value); -) -``` - -### setAudioParameter7+ - -setAudioParameter(key: string, value: string, callback: AsyncCallback<void>): void - -音频参数设置,使用callback方式返回异步结果。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| key | string | 是 | 被设置的音频参数的键。 | -| value | string | 是 | 被设置的音频参数的值。 | -| callback | AsyncCallback<void> | 是 | 回调返回设置成功或失败。 | - -**示例:** - -``` -var audioManager = audio.getAudioManager(); -audioManager.setAudioParameter('PBits per sample', '8 bit', (err) => { - if (err) { - console.error('Failed to set the audio parameter. ${err.message}'); - return; - } - console.log('Callback invoked to indicate a successful setting of the audio parameter.'); -}) -``` - -### setAudioParameter7+ - -setAudioParameter(key: string, value: string): Promise<void> - -音频参数设置,使用promise方式返回异步结果。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| key | string | 是 | 被设置的音频参数的键。 | -| value | string | 是 | 被设置的音频参数的值。 | - -**返回值:** - -| 类型 | 说明 | -| -------- | -------- | -| Promise<void> | Promise回调返回设置成功或失败。 | - -**示例:** - -``` -var audioManager = audio.getAudioManager(); -audioManager.setAudioParameter('PBits per sample', '8 bit').then(() => - console.log('Promise returned to indicate a successful setting of the audio parameter.'); -) -``` - -### getAudioParameter7+ - -getAudioParameter(key: string, callback: AsyncCallback<string>): void - -获取指定音频参数值,使用callback方式返回异步结果。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| key | string | 是 | 待获取的音频参数的键。 | -| callback | AsyncCallback<string> | 是 | 回调返回获取的音频参数的值。 | - -**示例:** - -``` -var audioManager = audio.getAudioManager(); -audioManager.getAudioParameter('PBits per sample', (err, value) => { - if (err) { - console.error('Failed to obtain the value of the audio parameter. ${err.message}'); - return; - } - console.log('Callback invoked to indicate that the value of the audio parameter is obtained.' + value); -}) -``` - -### getAudioParameter7+ - -getAudioParameter(key: string): Promise<string> - -获取指定音频参数值,使用promise方式返回异步结果。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| key | string | 是 | 待获取的音频参数的键。 | - -**返回值:** - -| 类型 | 说明 | -| -------- | -------- | -| Promise<string> | Promise回调返回获取的音频参数的值。 | - -**示例:** - -``` -var audioManager = audio.getAudioManager(); -audioManager.getAudioParameter('PBits per sample').then((value) => - console.log('Promise returned to indicate that the value of the audio parameter is obtained.' + value); -) -``` - -### getDevices - -getDevices(deviceFlag: DeviceFlag, callback: AsyncCallback<AudioDeviceDescriptors>): void - -获取音频设备列表,使用callback方式返回异步结果。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| deviceFlag | [DeviceFlag](#deviceflag) | 是 | 设备类型的flag。 | -| callback | AsyncCallback<[AudioDeviceDescriptors](#audiodevicedescriptors)> | 是 | 回调,返回设备列表。 | - -**示例:** -``` -var audioManager = audio.getAudioManager(); -audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value)=>{ - if (err) { - console.error('Failed to obtain the device list. ${err.message}'); - return; - } - console.log('Callback invoked to indicate that the device list is obtained.'); -}) -``` - -### getDevices - -(deviceFlag: DeviceFlag): Promise<AudioDeviceDescriptors> - -获取音频设备列表,使用promise方式返回异步结果。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| deviceFlag | [DeviceFlag](#deviceflag) | 是 | 设备类型的flag。 | - -**返回值:** - -| 类型 | 说明 | -| -------- | -------- | -| Promise<[AudioDeviceDescriptors](#audiodevicedescriptors)> | Promise回调返回设备列表。 | - -**示例:** - -``` -var audioManager = audio.getAudioManager(); -audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data)=> - console.log('Promise returned to indicate that the device list is obtained.'); -) -``` - -### setDeviceActive7+ - -setDeviceActive(deviceType: DeviceType, active: boolean, callback: AsyncCallback<void>): void - -设置设备激活状态,使用callback方式返回异步结果。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| deviceType | [DeviceType](#devicetype) | 是 | 音频设备类型。 | -| active | boolean | 是 | 设备激活状态。 | -| callback | AsyncCallback<void> | 是 | 回调返回设置成功或失败。 | - -**示例:** - -``` -var audioManager = audio.getAudioManager(); -audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true, (err)=> { - if (err) { - console.error('Failed to set the active status of the device. ${err.message}'); - return; - } - console.log('Callback invoked to indicate that the device is set to the active status.'); -}) -``` - -### setDeviceActive7+ - -setDeviceActive(deviceType: DeviceType, active: boolean): Promise<void> - -设置设备激活状态,使用promise方式返回异步结果。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| deviceType | [DeviceType](#devicetype) | 是 | 音频设备类型。 | -| active | boolean | 是 | 设备激活状态。 | - -**返回值:** - -| 类型 | 说明 | -| -------- | -------- | -| Promise<void> | Promise回调返回设置成功或失败。 | - -**示例:** - - -``` -var audioManager = audio.getAudioManager(); -audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true).then(()=> - console.log('Promise returned to indicate that the device is set to the active status.'); -) -``` - -### isDeviceActive7+ - -isDeviceActive(deviceType: DeviceType, callback: AsyncCallback<boolean>): void - -获取指定设备的激活状态,使用callback方式返回异步结果。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| deviceType | [DeviceType](#devicetype) | 是 | 音频设备类型。 | -| callback | AsyncCallback<boolean> | 是 | 回调返回设备的激活状态。 | - -**示例:** - -``` -var audioManager = audio.getAudioManager(); -audioManager.isDeviceActive(audio.DeviceType.SPEAKER, (err, value) => { - if (err) { - console.error('Failed to obtain the active status of the device. ${err.message}'); - return; - } - console.log('Callback invoked to indicate that the active status of the device is obtained.'); -}) -``` - - -### isDeviceActive7+ - -isDeviceActive(deviceType: DeviceType): Promise<boolean> - -获取指定设备的激活状态,使用promise方式返回异步结果。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| deviceType | [DeviceType](#devicetype) | 是 | 音频设备类型。 | - -**返回值:** - -| Type | Description | -| -------- | -------- | -| Promise<boolean> | Promise回调返回设备的激活状态。 | - -**示例:** - -``` -var audioManager = audio.getAudioManager(); -audioManager.isDeviceActive(audio.DeviceType.SPEAKER).then((value) => - console.log('Promise returned to indicate that the active status of the device is obtained.' + value); -) -``` - -### setMicrophoneMute7+ - -setMicrophoneMute(mute: boolean, callback: AsyncCallback<void>): void - -设置麦克风静音状态,使用callback方式返回异步结果。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| mute | boolean | 是 | 待设置的静音状态,true为静音,false为非静音。 | -| callback | AsyncCallback<void> | 是 | 回调返回设置成功或失败。 | - -**示例:** - -``` -var audioManager = audio.getAudioManager(); -audioManager.setMicrophoneMute(true, (err) => { - if (err) { - console.error('Failed to mute the microphone. ${err.message}'); - return; - } - console.log('Callback invoked to indicate that the microphone is muted.'); -}) -``` - -### setMicrophoneMute7+ - -setMicrophoneMute(mute: boolean): Promise<void> - -设置麦克风静音状态,使用promise方式返回异步结果。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| mute | boolean | 是 | 待设置的静音状态,true为静音,false为非静音。 | - -**返回值:** - -| 类型 | 说明 | -| -------- | -------- | -| Promise<void> | Promise回调返回设置成功或失败。 | - -**示例:** - -``` -var audioManager = audio.getAudioManager(); -audioManager.setMicrophoneMute(true).then(() => - console.log('Promise returned to indicate that the microphone is muted.'); -) -``` - -### isMicrophoneMute7+ - -isMicrophoneMute(callback: AsyncCallback<boolean>): void - -获取麦克风静音状态,使用callback方式返回异步结果。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| callback | AsyncCallback<boolean> | 是 | 回调返回系统麦克风静音状态,true为静音,false为非静音。 | - -**示例:** - -``` -var audioManager = audio.getAudioManager(); -audioManager.isMicrophoneMute((err, value) => { - if (err) { - console.error('Failed to obtain the mute status of the microphone. ${err.message}'); - return; - } - console.log('Callback invoked to indicate that the mute status of the microphone is obtained.' + value); -}) -``` - -### isMicrophoneMute7+ - -isMicrophoneMute(): Promise<boolean> - -获取麦克风静音状态,使用promise方式返回异步结果。 - -**返回值:** - -| 类型 | 说明 | -| -------- | -------- | -| Promise<boolean> | Promise回调返回系统麦克风静音状态,true为静音,false为非静音。 | - -**示例:** - - -``` -var audioManager = audio.getAudioManager(); -audioManager.isMicrophoneMute().then((value) => - console.log('Promise returned to indicate that the mute status of the microphone is obtained.', + value); -) -``` - - -## AudioDeviceDescriptor - -描述音频设备。 - -| 名称 | 参数型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| deviceRole | [DeviceRole](#devicerole) | 是 | 否 | 设备角色。 | -| deviceType | [DeviceType](#devicetype) | 是 | 否 | 设备类型。 | - - -## AudioDeviceDescriptors - -| 名称 | 描述 | -| -------- | -------- | -| 设备属性数组 | AudioDeviceDescriptor的数组,只读。 | diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/03.\345\252\222\344\275\223/02.\345\252\222\344\275\223\346\234\215\345\212\241.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/03.\345\252\222\344\275\223/02.\345\252\222\344\275\223\346\234\215\345\212\241.md" deleted file mode 100644 index 7d94253c122ce133484b97a13ab750ce8a70dadc..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/03.\345\252\222\344\275\223/02.\345\252\222\344\275\223\346\234\215\345\212\241.md" +++ /dev/null @@ -1,725 +0,0 @@ ---- -title: 媒体服务 -permalink: /pages/010c010302 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 媒体服务 - -媒体子系统为开发者提供一套简单且易于理解的接口,使得开发者能够方便接入系统并使用系统的媒体资源。 - -媒体子系统包含了音视频相关媒体业务,提供以下常用功能: - -- 音频播放([AudioPlayer](#audioplayer)) -- 音频录制([AudioRecorder](#audiorecorder)) - -后续将提供以下功能:视频播放、视频录制、DataSource音视频播放、音视频编解码、容器封装解封装、媒体能力查询等功能。 - -## 导入模块 - -```js -import media from '@ohos.multimedia.media'; -``` - -## media.createAudioPlayer - -createAudioPlayer(): [AudioPlayer](#audioplayer) - -同步方式创建音频播放实例。 - -**返回值:** - -| 类型 | 说明 | -| --------------------------- | ------------------------------------------------------------ | -| [AudioPlayer](#audioplayer) | 返回AudioPlayer类实例,失败时返回null。可用于音频播放、暂停、停止等操作。 | - -**示例:** - -```js -var audioPlayer = media.createAudioPlayer(); -``` - -## media.createAudioPlayerAsync8+ - -createAudioPlayerAsync(callback: AsyncCallback\<[AudioPlayer](#audioplayer)>): void - -异步方式创建音频播放实例。通过注册回调函数获取返回值。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------------ | ---- | ------------------------------ | -| callback | AsyncCallback<[AudioPlayer](#audioplayer)> | 是 | 异步创建音频播放实例回调方法。 | - -**示例:** - -```js -media.createAudioPlayerAsync((error, audio) => { - if (typeof(audio) != 'undefined') { - audioPlayer = audio; - console.info('audio createAudioPlayerAsync success'); - } else { - console.info(`audio createAudioPlayerAsync fail, error:${error.message}`); - } -}); -``` - -## media.createAudioPlayerAsync8+ - -createAudioPlayerAsync: Promise<[AudioPlayer](#audioplayer)> - -异步方式创建音频播放实例。通过Promise获取返回值。 - -**返回值:** - -| 类型 | 说明 | -| ------------------------------------ | ----------------------------------- | -| Promise<[AudioPlayer](#audioplayer)> | 异步创建音频播放实例Promise返回值。 | - -**示例:** - -```js -function failureCallback(error) { - console.info(`audio failureCallback, error:${error.message}`); -} -function catchCallback(error) { - console.info(`audio catchCallback, error:${error.message}`); -} - -await media.createAudioPlayerAsync.then((audio) => { - if (typeof(audio) != 'undefined') { - audioPlayer = audio; - console.info('audio createAudioPlayerAsync success'); - } else { - console.info('audio createAudioPlayerAsync fail'); - } -}, failureCallback).catch(catchCallback); -``` - -## media.createAudioRecorder -createAudioRecorder(): AudioRecorder - -创建音频录制的实例来控制音频的录制。 - -**返回值:** - -| 类型 | 说明 | -| ------------------------------- | ----------------------------------------- | -| [AudioRecorder](#audiorecorder) | 返回AudioRecorder类实例,失败时返回null。 | - -**示例:** - -``` -var audiorecorder = media.createAudioRecorder(); -``` - -## MediaErrorCode8+ - -媒体服务错误类型枚举 - -| 名称 | 值 | 说明 | -| -------------------------- | ---- | -------------------------------------- | -| MSERR_OK | 0 | 表示操作成功。 | -| MSERR_NO_MEMORY | 1 | 表示申请内存失败,系统可能无可用内存。 | -| MSERR_OPERATION_NOT_PERMIT | 2 | 表示无权限执行此操作。 | -| MSERR_INVALID_VAL | 3 | 表示传入入参无效。 | -| MSERR_IO | 4 | 表示发生IO错误。 | -| MSERR_TIMEOUT | 5 | 表示操作超时。 | -| MSERR_UNKNOWN | 6 | 表示未知错误。 | -| MSERR_SERVICE_DIED | 7 | 表示服务端失效。 | -| MSERR_INVALID_STATE | 8 | 表示在当前状态下,不允许执行此操作。 | -| MSERR_UNSUPPORTED | 9 | 表示在当前版本下,不支持此操作。 | - -## MediaType8+ - -媒体类型枚举 - -| 名称 | 值 | 说明 | -| ------------------- | ---- | ------------------ | -| MEDIA_TYPE_AUD | 0 | 表示音频。 | -| MEDIA_TYPE_VID | 1 | 表示视频。 | -| MEDIA_TYPE_SUBTITLE | 2 | 表示字幕:开发中。 | - -## CodecMimeType8+ - -Codec MIME类型枚举 - -| 名称 | 值 | 说明 | -| ------------ | ----------------- | ------------------------ | -| AUDIO_MPEG | "audio/mpeg" | 表示音频/mpeg类型。 | -| AUDIO_AAC | "audio/mp4a-latm" | 表示音频/mp4a-latm类型。 | -| AUDIO_VORBIS | "audio/vorbis" | 表示音频/vorbis类型。 | -| AUDIO_FLAC | "audio/flac" | 表示音频/flac类型。 | - -## MediaDescriptionKey8+ - -媒体信息描述枚举 - -| 名称 | 值 | 说明 | -| ------------------------ | --------------- | ------------------------------------------------------------ | -| MD_KEY_TRACK_INDEX | "track_index" | 表示轨道序号,其对应键值类型为number。 | -| MD_KEY_TRACK_TYPE | "track_type" | 表示轨道类型,其对应键值类型为number,参考[MediaType](#mediatype8)。 | -| MD_KEY_CODEC_MIME | "codec_mime" | 表示codec_mime类型,其对应键值类型为string。 | -| MD_KEY_DURATION | "duration" | 表示媒体时长,其对应键值类型为number,单位为ms。 | -| MD_KEY_BITRATE | "bitrate" | 表示比特率,其对应键值类型为number,单位为bps。 | -| MD_KEY_WIDTH | "width" | 表示视频宽度,其对应键值类型为number,单位为像素。 | -| MD_KEY_HEIGHT | "height" | 表示视频高度,其对应键值类型为number,单位为像素。 | -| MD_KEY_FRAME_RATE | "frame_rate" | 表示视频帧率,其对应键值类型为number,单位为100fps。 | -| MD_KEY_AUD_CHANNEL_COUNT | "channel_count" | 表示声道数,其对应键值类型为number。 | -| MD_KEY_AUD_SAMPLE_RATE | "sample_rate" | 表示采样率,其对应键值类型为number,单位为HZ。 | - -## BufferingInfoType8+ - -缓存事件类型枚举 - -| 名称 | 值 | 说明 | -| ----------------- | ---- | -------------------------- | -| BUFFERING_START | 1 | 表示开始缓存。 | -| BUFFERING_END | 2 | 表示结束缓存。 | -| BUFFERING_PERCENT | 3 | 表示缓存百分比。 | -| CACHED_DURATION | 4 | 表示缓存时长,单位为毫秒。 | - -## AudioPlayer - -音频播放管理类,用于管理和播放音频媒体。在调用AudioPlayer的方法前,需要先通过[createAudioPlayer()](#media.createaudioplayer)或[createAudioPlayerAsync()](#media.createaudioplayerasync8)构建一个[AudioPlayer](#audioplayer)实例。 - -音频播放demo可参考:[音频播放开发指导](/pages/0108030102) - -### 属性 - -| 名称 | 类型 | 可读 | 可写 | 说明 | -| ----------- | ------------------------- | ---- | ---- | ------------------------------------------------------------ | -| src | string | 是 | 是 | 音频媒体URI,支持当前主流的音频格式(mp4、aac、mp3、ogg)。
**支持路径示例**:
1、本地绝对路径:file:///data/data/ohos.xxx.xxx/files/test.mp4
![zh-cn_image_0000001164217678](/images/application-dev/reference/apis/figures/zh-cn_image_0000001164217678.png)
2、http网络播放路径:开发中
3、hls网络播放路径:开发中
4、fd类型播放:开发中
**注意事项**:
媒体素材需至少赋予读权限后,才可正常播放 | -| loop | boolean | 是 | 是 | 音频循环播放属性,设置为'true'表示循环播放。 | -| currentTime | number | 是 | 否 | 音频的当前播放位置。 | -| duration | number | 是 | 否 | 音频时长。 | -| state | [AudioState](#audiostate) | 是 | 否 | 音频播放的状态。 | - -### play - -play(): void - -开始播放音频资源,需在[dataLoad](#on('play' | 'pause' | 'stop' | 'reset' | 'dataload' | 'finish' | 'volumechange'))事件成功触发后,才能调用play方法。 - -**示例:** - -```js -audioPlayer.on('play', () => { //设置'play'事件回调 - console.log('audio play success'); -}); -audioPlayer.play(); -``` - -### pause - -pause(): void - -暂停播放音频资源。 - -**示例:** - -```js -audioPlayer.on('pause', () => { //设置'pause'事件回调 - console.log('audio pause success'); -}); -audioPlayer.pause(); -``` - -### stop - -stop(): void - -停止播放音频资源。 - -**示例:** - -```js -audioPlayer.on('stop', () => { //设置'stop'事件回调 - console.log('audio stop success'); -}); -audioPlayer.stop(); -``` - -### reset7+ - -reset(): void - -切换播放音频资源。 - -**示例:** - -```js -audioPlayer.on('reset', () => { //设置'reset'事件回调 - console.log('audio reset success'); -}); -audioPlayer.reset(); -``` - -### seek - -seek(timeMs: number): void - -跳转到指定播放位置。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ------ | ---- | ------------------------------ | -| timeMs | number | 是 | 指定的跳转时间节点,单位毫秒。 | - -**示例:** - -```js -audioPlayer.on('timeUpdate', (seekDoneTime) => { //设置'timeUpdate'事件回调 - if (typeof (seekDoneTime) == 'undefined') { - console.info('audio seek fail'); - return; - } - console.log('audio seek success. seekDoneTime: ' + seekDoneTime); -}); -audioPlayer.seek(30000); //seek到30000ms的位置 -``` - -### setVolume - -setVolume(vol: number): void - -设置音量。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ------ | ---- | ------------------------------------------------------------ | -| vol | number | 是 | 指定的相对音量大小,取值范围为[0.00-1.00],1表示最大音量,即100%。 | - -**示例:** - -```js -audioPlayer.on('volumeChange', () => { //设置'volumeChange'事件回调 - console.log('audio volumeChange success'); -}); -audioPlayer.setVolume(1); //设置音量到100% -``` - -### release - -release(): void - -释放音频资源。 - -**示例:** - -```js -audioPlayer.release(); -audioPlayer = undefined; -``` - -### getTrackDescription8+ - -getTrackDescription(callback: AsyncCallback>): void - -通过回调方式获取音频轨道信息。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------------------------------ | ---- | -------------------------- | -| callback | AsyncCallback> | 是 | 获取音频轨道信息回调方法。 | - -**示例:** - -```js -function printfDescription(obj) { - for (let item in obj) { - let property = obj[item]; - console.info('audio key is ' + item); - console.info('audio value is ' + property); - } -} - -audioPlayer.getTrackDescription((error, arrlist) => { - if (typeof (arrlist) != 'undefined') { - for (let i = 0; i < arrlist.length; i++) { - printfDescription(arrlist[i]); - } - } else { - console.log(`audio getTrackDescription fail, error:${error.message}`); - } -}); -``` - -### getTrackDescription8+ - -getTrackDescription(): Promise> - -通过Promise方式获取音频轨道信息。 - -**返回值:** - -| 类型 | 说明 | -| ------------------------------------------------------ | ------------------------------- | -| Promise> | 获取音频轨道信息Promise返回值。 | - -**示例:** - -```js -function printfDescription(obj) { - for (let item in obj) { - let property = obj[item]; - console.info('audio key is ' + item); - console.info('audio value is ' + property); - } -} -function failureCallback(error) { - console.info(`audio failureCallback, error:${error.message}`); -} -function catchCallback(error) { - console.info(`audio catchCallback, error:${error.message}`); -} - -await audioPlayer.getTrackDescription.then((arrlist) => { - if (typeof (arrlist) != 'undefined') { - arrayDescription = arrlist; - } else { - console.log('audio getTrackDescription fail'); - } -}, failureCallback).catch(catchCallback); -for (let i = 0; i < arrayDescription.length; i++) { - printfDescription(arrayDescription[i]); -} -``` - -### on('bufferingUpdate')8+ - -on(type: 'bufferingUpdate', callback: (infoType: [BufferingInfoType](#bufferinginfotype8), value: number) => void): void - -开始订阅音频缓存更新事件。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | 是 | 音频缓存事件回调类型,支持的事件:'bufferingUpdate'。 | -| callback | (infoType: [BufferingInfoType](#bufferinginfotype8), value: number) => void | 是 | 音频缓存事件回调方法。
[BufferingInfoType](#bufferinginfotype8)为BUFFERING_PERCENT或CACHED_DURATION时,value值有效,否则固定为0。 | - -**示例:** - -```js -audioPlayer.on('bufferingUpdate', (infoType, value) => { - console.log('audio bufferingInfo type: ' + infoType); - console.log('audio bufferingInfo value: ' + value); -}); -``` - - ### on('play' | 'pause' | 'stop' | 'reset' | 'dataLoad' | 'finish' | 'volumeChange') - -on(type: 'play' | 'pause' | 'stop' | 'reset' | 'dataLoad' | 'finish' | 'volumeChange', callback: () => void): void - -开始订阅音频播放事件。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ---------- | ---- | ------------------------------------------------------------ | -| type | string | 是 | 播放事件回调类型,支持的事件包括:'play' \| 'pause' \| 'stop' \| 'reset' \| 'dataLoad' \| 'finish' \| 'volumeChange'。
- 'play':完成[play()](#play)调用,音频开始播放,触发该事件。
- 'pause':完成[pause()](#pause)调用,音频暂停播放,触发该事件。
- 'stop':完成[stop()](#stop)调用,音频停止播放,触发该事件。
- 'reset':完成[reset()](#reset7)调用,播放器重置,触发该事件。
- 'dataLoad':完成音频数据加载后触发该事件,即src属性设置完成后触发该事件。
- 'finish':完成音频播放后触发该事件。
- 'volumeChange':完成[setVolume()](#setvolume)调用,播放音量改变后触发该事件。 | -| callback | () => void | 是 | 播放事件回调方法。 | - -**示例:** - -```js -let audioPlayer = media.createAudioPlayer(); //创建一个音频播放实例 -audioPlayer.on('dataLoad', () => { //设置'dataLoad'事件回调,src属性设置成功后,触发此回调 - console.info('audio set source success'); - audioPlayer.play(); //开始播放,并触发'play'事件回调 -}); -audioPlayer.on('play', () => { //设置'play'事件回调 - console.info('audio play success'); - audioPlayer.seek(30000); //调用seek方法,并触发'timeUpdate'事件回调 -}); -audioPlayer.on('pause', () => { //设置'pause'事件回调 - console.info('audio pause success'); - audioPlayer.stop(); //停止播放,并触发'stop'事件回调 -}); -audioPlayer.on('reset', () => { //设置'reset'事件回调 - console.info('audio reset success'); - audioPlayer.release(); //释放播放实例资源 - audioPlayer = undefined; -}); -audioPlayer.on('timeUpdate', (seekDoneTime) => { //设置'timeUpdate'事件回调 - if (typeof(seekDoneTime) == "undefined") { - console.info('audio seek fail'); - return; - } - console.info('audio seek success, and seek time is ' + seekDoneTime); - audioPlayer.setVolume(0.5); //设置音量为50%,并触发'volumeChange'事件回调 -}); -audioPlayer.on('volumeChange', () => { //设置'volumeChange'事件回调 - console.info('audio volumeChange success'); - audioPlayer.pause(); //暂停播放,并触发'pause'事件回调 -}); -audioPlayer.on('finish', () => { //设置'finish'事件回调 - console.info('audio play finish'); - audioPlayer.stop(); //停止播放,并触发'stop'事件回调 -}); -audioPlayer.on('error', (error) => { //设置'error'事件回调 - console.info(`audio error called, errName is ${error.name}`); - console.info(`audio error called, errCode is ${error.code}`); - console.info(`audio error called, errMessage is ${error.message}`); -}); -audioPlayer.src = 'file:///data/data/ohos.xxx.xxx/files/test.mp4'; //设置src属性,并触发'dataLoad'事件回调 -``` - -### on('timeUpdate') - -on(type: 'timeUpdate', callback: Callback\): void - -开始订阅音频播放[seek()](#seek)时间更新事件。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ----------------- | ---- | ------------------------------------------------------------ | -| type | string | 是 | 播放事件回调类型,支持的事件包括:'timeUpdate'。
- 'timeUpdate':[seek()](#seek)调用完成,触发该事件。 | -| callback | Callback\ | 是 | 播放事件回调方法。回调方法入参为成功seek的时间。 | - -**示例:** - -```js -audioPlayer.on('timeUpdate', (seekDoneTime) => { //设置'timeUpdate'事件回调 - if (typeof (seekDoneTime) == 'undefined') { - console.info('audio seek fail'); - return; - } - console.log('audio seek success. seekDoneTime: ' + seekDoneTime); -}); -audioPlayer.seek(30000); //seek到30000ms的位置 -``` - -### on('error') - -on(type: 'error', callback: ErrorCallback): void - -开始订阅音频播放错误事件。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------- | ---- | ------------------------------------------------------------ | -| type | string | 是 | 播放错误事件回调类型,支持的事件包括:'error'。
- 'error':音频播放中发生错误,触发该事件。 | -| callback | ErrorCallback | 是 | 播放错误事件回调方法。 | - -**示例:** - -```js -audioPlayer.on('error', (error) => { //设置'error'事件回调 - console.info(`audio error called, errName is ${error.name}`); //打印错误类型名称 - console.info(`audio error called, errCode is ${error.code}`); //打印错误码 - console.info(`audio error called, errMessage is ${error.message}`);//打印错误类型详细描述 -}); -audioPlayer.setVolume(3); //设置volume为无效值,触发'error'事件 -``` - -## AudioState - -音频播放的状态机。可通过state属性获取当前状态。 - -| 名称 | 类型 | 描述 | -| ------------------ | ------ | -------------- | -| idle | string | 音频播放空闲。 | -| playing | string | 音频正在播放。 | -| paused | string | 音频暂停播放。 | -| stopped | string | 音频播放停止。 | -| error8+ | string | 错误状态。 | - -## MediaDescription8+ - -### [key : string] : any - -通过key-value方式获取媒体信息 - -| 名称 | 类型 | 说明 | -| ----- | ------ | ------------------------------------------------------------ | -| key | string | 通过key值获取对应的value。key值具体可见[MediaDescriptionKey](#mediadescriptionkey8)。 | -| value | any | 对应key值得value。其类型可为任意类型,具体key对应value的类型可参考[MediaDescriptionKey](#mediadescriptionkey8)的描述信息。 | - -**示例:** - -```js -function printfItemDescription(obj, key) { - let property = obj[key]; - console.info('audio key is ' + key); - console.info('audio value is ' + property); -} - -audioPlayer.getTrackDescription((error, arrlist) => { - if (typeof (arrlist) != 'undefined') { - for (let i = 0; i < arrlist.length; i++) { - printfItemDescription(arrlist[i], MD_KEY_TRACK_TYPE); //打印出每条轨道MD_KEY_TRACK_TYPE的值 - } - } else { - console.log(`audio getTrackDescription fail, error:${error.message}`); - } -}); -``` - -## AudioRecorder - -音频录制管理类,用于录制音频媒体。在调用AudioRecorder的方法前,需要先通过[createAudioRecorder()](#mediacreateaudiorecorder)构建一个AudioRecorder实例。 - -### prepare - -prepare(config: AudioRecorderConfig): void - -录音准备。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ------------------------------------------- | ---- | ------------------------------------------------------------ | -| config | [AudioRecorderConfig](#audiorecorderconfig) | 是 | 配置录音的相关参数,包括音频输出URI、编码格式、采样率、声道数等。 | - -**示例:** - -``` -var audiorecorder = media.createAudioRecorder(); -let audioRecorderConfig = { - audioEncoder : AAC_LC , - audioEncodeBitRate : 22050, - audioSampleRate : 22050, - numberOfChannels : 2, - format : AAC_ADTS, - uri : 'file:///data/accounts/account_0/appdata/appdata/recorder/test.m4a', -} -audiorecorder.prepare(audioRecorderConfig) -``` - - -### start - -start(): void - -开始录音。 - -**示例:** - -``` -var audiorecorder = media.createAudioRecorder(); -audiorecorder.start(); -``` - -### stop - -stop(): void - -停止录音。 - -**示例:** - -``` -var audiorecorder = media.createAudioRecorder(); -audiorecorder.stop(); -``` - -### release - -release(): void - -释放录音资源。 - -**示例:** - -``` -var audiorecorder = media.createAudioRecorder(); -audiorecorder.release(); -``` - -### reset - -reset(): void - -重置录音。 - -进行重置录音之前,需要先调用stop()停止录音。重置录音之后,需要调用prepare()设置录音配置项,才能再次进行录音。 - -**示例:** - -``` -var audiorecorder = media.createAudioRecorder(); -audiorecorder.reset(); -``` - -### on('prepare' | 'start' | 'stop' | 'release' | 'reset') - -on(type: 'prepare' | 'start' | 'stop' | 'release' | 'reset', callback: () => void): void - -开始订阅音频录制事件。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | ---- | ------------------------------------------------------------ | -| type | string | 是 | 录制事件回调类型,支持的事件包括:'prepare' \| 'start' \| 'stop' \| 'release' \| 'reset'。
- 'prepare' :音频录制准备完成后,触发该事件。
- 'start' :音频录制开始后,触发该事件。
- 'stop' :音频录制停止后,触发该事件。
- 'release' :音频录制相关资源释放后,触发该事件。
- 'reset':音频录制重置后,触发该事件。 | -| callback | function | 是 | 录制事件回调方法。 | - -**示例:** - -``` -var audiorecorder = media.createAudioRecorder(); -audiorecorder.on('prepare', () => { - console.log('Preparation succeeded.'); - audiorecorder.start(); -}); -``` - -### on('error') - -on(type: 'error', callback: ErrorCallback): void - -开始订阅音频录制错误事件。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------- | ---- | ------------------------------------------------------------ | -| type | string | 是 | 录制错误事件回调类型'error'。
- 'error':音频录制过程中发生错误,触发该事件。 | -| callback | ErrorCallback | 是 | 录制错误事件回调方法。 | - - -## AudioRecorderConfig - -表示音频的录音配置。 - -| 名称 | 参数类型 | 必填 | 说明 | -| ------------------ | --------------------------------------- | ---- | ------------------------------------------------------------ | -| audioEncoder | [AudioEncoder](#audioencoder) | 否 | 音频编码格式,默认设置为AAC_LC。 | -| audioEncodeBitRate | number | 否 | 音频编码比特率,默认值为48000。 | -| audioSampleRate | number | 否 | 音频采集采样率,默认值为48000。 | -| numberOfChannels | number | 否 | 音频采集声道数,默认值为2。 | -| format | [AudioOutputFormat](#audiooutputformat) | 否 | 音量输出封装格式,默认设置为MPEG_4。 | -| uri | string | 是 | 音频输出URI。支持:
1. 文件的绝对路径:file:///data/data/ohos.xxx.xxx/cache/test.mp4![zh-cn_image_0000001164217678](/images/application-dev/reference/apis/figures/zh-cn_image_0000001164217678.png)
2. 文件的fd路径:file://1 (fd number) | - - -## AudioEncoder - -表示音频编码格式的枚举。 - -| 名称 | 默认值 | 说明 | -| ------ | ------ | ------------------------------------------------------------ | -| AAC_LC | 3 | AAC-LC(Advanced Audio Coding Low Complexity)编码格式。 | - - -## AudioOutputFormat - -表示音频封装格式的枚举。 - -| 名称 | 默认值 | 说明 | -| -------- | ------ | ------------------------------------------------------------ | -| MPEG_4 | 2 | 封装为MPEG-4格式。 | -| AAC_ADTS | 6 | 封装为ADTS(Audio Data Transport Stream)格式,是AAC音频的传输流格式。 | \ No newline at end of file diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/04.\345\256\211\345\205\250/01.\347\224\250\346\210\267\350\256\244\350\257\201.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/04.\345\256\211\345\205\250/01.\347\224\250\346\210\267\350\256\244\350\257\201.md" deleted file mode 100644 index 7fcccdff8f91c0d79d5e657e2671ed1947ac00e3..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/04.\345\256\211\345\205\250/01.\347\224\250\346\210\267\350\256\244\350\257\201.md" +++ /dev/null @@ -1,357 +0,0 @@ ---- -title: 用户认证 -permalink: /pages/010c010401 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 用户认证 - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import userIAM_userAuth from '@ohos.userIAM.userAuth'; -``` - - -## 权限列表 - -ohos.permission.ACCESS_BIOMETRIC - - -## 完整示例 - -``` -import userIAM_userAuth from '@ohos.userIAM.userAuth'; - -export default { - startAuth() { - console.info("start auth"); - let tipCallback = (tip)=>{ - console.info("receive tip: errorCode(" + tip.errorCode + ") code(" + tip.tipCode + ") event(" + - tip.tipEvent + ") info(" + tip.tipInfo + ")"); - // 此处添加提示信息显示逻辑 - }; - let auth = userIAM_userAuth.getAuthenticator(); - auth.on("tip", tipCallback); - auth.execute("FACE_ONLY", "S2").then((code)=>{ - auth.off("tip", tipCallback); - console.info("auth success"); - // 此处添加认证成功逻辑 - }).catch((code)=>{ - auth.off("tip", tipCallback); - console.error("auth fail, code = " + code); - // 此处添加认证失败逻辑 - }); - }, - - checkAuthSupport() { - console.info("start check auth support"); - let auth = userIAM_userAuth.getAuthenticator(); - let checkCode = auth.checkAvailability("FACE_ONLY", "S2"); - if (checkCode == userIAM_userAuth.CheckAvailabilityResult.SUPPORTED) { - console.info("check auth support success"); - // 此处添加支持指定类型认证的逻辑 - } else { - console.error("check auth support fail, code = " + checkCode); - // 此处添加不支持指定类型认证的逻辑 - } - }, - - cancelAuth() { - console.info("start cancel auth"); - let auth = userIAM_userAuth.getAuthenticator(); - let cancelCode = auth.cancel(); - if (cancelCode == userIAM_userAuth.Result.SUCCESS) { - console.info("cancel auth success"); - } else { - console.error("cancel auth fail"); - } - } -} -``` - - -## userIAM_userAuth.getAuthenticator - -getAuthenticator(): Authenticator - -获取Authenticator对象,用于执行用户身份认证。6+ - -获取Authenticator对象,用于检测设备身份认证能力、执行和取消用户身份认证,获取认证过程中的提示信息。7+ - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [Authenticator](#authenticator) | 认证器对象。 | - -- 示例: - ``` - let authenticator = userIAM_userAuth.getAuthenticator(); - ``` - - -## Authenticator - -认证器对象。 - - -### execute - -execute(type: string, level: string, callback: AsyncCallback<number>): void - -执行用户认证,使用callback方式作为异步方法。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | string | 是 | 认证类型,当前只支持FACE_ONLY。
ALL为预留参数,当前版本暂不支持ALL类型的认证。 | - | level | string | 是 | 安全级别,对应认证的安全级别,有效值为S1(最低)、S2、S3、S4(最高)。
具备3D人脸识别能力的设备支持S3及以下安全级别的认证。
具备2D人脸识别能力的设备支持S2及以下安全级别的认证。 | - | callback | AsyncCallback<number> | 否 | 回调函数。 | - - callback返回值: - - | 类型 | 说明 | - | -------- | -------- | - | number | 表示认证结果,参见[AuthenticationResult](#authenticationresult)。 | - -- 示例: - ``` - authenticator.execute("FACE_ONLY", "S2", (code)=>{ - if (code == userIAM_userAuth.AuthenticationResult.SUCCESS) { - console.info("auth success"); - return; - } - console.error("auth fail, code = " + code); - }) - ``` - - -### execute - -execute(type:string, level:string): Promise<number> - -执行用户认证,使用promise方式作为异步方法。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | string | 是 | 认证类型,当前只支持FACE_ONLY。
ALL为预留参数,当前版本暂不支持ALL类型的认证。 | - | level | string | 是 | 安全级别,对应认证的安全级别,有效值为S1(最低)、S2、S3、S4(最高)。
具备3D人脸识别能力的设备支持S3及以下安全级别的认证。
具备2D人脸识别能力的设备支持S2及以下安全级别的认证。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<number> | 返回携带一个number的Promise。number 为认证结果,参见[AuthenticationResult](#authenticationresult)。 | - -- 示例 - ``` - let authenticator = userIAM_userAuth.getAuthenticator(); - authenticator.execute("FACE_ONLY", "S2").then((code)=>{ - authenticator.off("tip", tipCallback); - console.info("auth success"); - }).catch((code)=>{ - authenticator.off("tip", tipCallback); - console.error("auth fail, code = " + code); - }); - ``` - - -### cancel7+ - -cancel(): number - -取消当前的认证流程。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 返回取消当前认证的结果,参见[Result](#result7)。 | - -- 示例: - ``` - let authenticator = userIAM_userAuth.getAuthenticator(); - let cancelCode = authenticator.cancel(); - if (cancelCode == userIAM_userAuth.Result.SUCCESS) { - console.info("cancel auth success"); - } else { - console.error("cancel auth fail"); - } - ``` - - -### checkAvailability7+ - -checkAvailability(type: AuthType, level: SecureLevel): number - -根据指定的认证类型、安全等级,检测当前设备是否支持相应的认证能力。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | string | 是 | 认证类型,当前只支持FACE_ONLY。
ALL为预留参数,当前版本暂不支持ALL类型的认证。 | - | level | string | 是 | 安全级别,对应认证的安全级别,有效值为S1(最低)、S2、S3、S4(最高)。
具备3D人脸识别能力的设备支持S3及以下安全级别的认证。
具备2D人脸识别能力的设备支持S2及以下安全级别的认证。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 返回检测当前设备认证能力的结果,参见[CheckAvailabilityResult](#checkavailabilityresult7)。 | - -- 示例: - ``` - let authenticator = userIAM_userAuth.getAuthenticator(); - let checkCode = authenticator.checkAvailability("FACE_ONLY", "S2"); - if (checkCode == userIAM_userAuth.CheckAvailabilityResult.SUPPORTED) { - console.info("check auth support success"); - } else { - console.error("check auth support fail, code = " + checkCode); - } - ``` - - -### on7+ - -on(type: "tip", callback: Callback<Tip>) : void; - -订阅指定类型的事件。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | string | 是 | 事件类型,当前只支持"tip"。在认证服务发送提示信息给调用者时,会触发此事件。 | - | callback | Callback<Tip> | 是 | 事件发生时的回调,当前只支持以Tip为参数的回调函数。 | - -- 示例: - ``` - let authenticator = userIAM_userAuth.getAuthenticator(); - let tipCallback = (tip)=>{ - console.info("receive tip: errorCode(" + tip.errorCode + ") code(" + tip.tipCode +") event(" + - tip.tipEvent + ") info(" + tip.tipInfo + ")"); - }; - authenticator.on("tip", tipCallback); - ``` - - -### off7+ - -off(type: "tip", callback?: Callback<Tip>) : void; - -取消订阅指定类型的事件。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | string | 是 | 事件类型,当前只支持"tip"。 | - | callback | Callback<Tip> | 否 | 取消订阅的回调函数,当前只支持以Tip为参数的回调函数。如未指定此参数,同事件类型的所有回调都会被取消。 | - -- 示例: - ``` - let authenticator = userIAM_userAuth.getAuthenticator(); - let tipCallback = (tip)=>{ - console.info("receive tip: errorCode(" + tip.errorCode + ") code(" + tip.tipCode + ") event(" + - tip.tipEvent + ") info(" + tip.tipInfo + ")"); - }; - // 取消订阅指定回调 - authenticator.off("tip", tipCallback); - - // 取消订阅所有回调 - authenticator.off("tip"); - ``` - - -## AuthenticationResult - -表示认证结果的枚举。 - -| 名称 | 默认值 | 描述 | -| -------- | -------- | -------- | -| NO_SUPPORT | -1 | 设备不支持当前的认证方式。 | -| SUCCESS | 0 | 认证成功。 | -| COMPARE_FAILURE | 1 | 比对失败。 | -| CANCELED | 2 | 用户取消认证。 | -| TIMEOUT | 3 | 认证超时。 | -| CAMERA_FAIL | 4 | 开启相机失败。 | -| BUSY | 5 | 认证服务忙,请稍后重试。 | -| INVALID_PARAMETERS | 6 | 认证参数无效。 | -| LOCKED | 7 | 认证失败次数过多,已锁定。 | -| NOT_ENROLLED | 8 | 未录入认证凭据。 | -| GENERAL_ERROR | 100 | 其他错误。 | - - -## Tip7+ - -表示认证过程中提示信息的对象。 - -| 名称 | 参数类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| errorCode | number | 是 | 是否成功获取到提示信息,参考[Result](#result7)。 | -| tipEvent | number | 是 | 认证提示事件, 参考[TipEvent](#tipevent7)。当前只支持RESULT、ACQUIRE。 | -| tipCode | number | 是 | 认证提示的事件提示码。
- 当tipEvent为RESULT时,含义为认证结果,参考[AuthenticationResult](#authenticationresult)。
- 当tipEvent为ACQUIRE时,含义为提示信息,参考[TipCode](#tipcode7)。 | -| tipInfo | string | 是 | 认证提示的事件提示码的描述信息。 | - - -## Result7+ - -表示执行结果的枚举。 - -| 名称 | 默认值 | 描述 | -| -------- | -------- | -------- | -| SUCCESS | 0 | 执行成功。 | -| FAILED | 1 | 执行失败。 | - - -## CheckAvailabilityResult7+ - -表示检测设备认证能力结果的枚举。 - -| 名称 | 默认值 | 描述 | -| -------- | -------- | -------- | -| SUPPORTED | 0 | 设备支持指定的认证类型和认证安全等级。 | -| AUTH_TYPE_NOT_SUPPORT | 1 | 设备不支持指定的认证类型。 | -| SECURE_LEVEL_NOT_SUPPORT | 2 | 设备不支持指定的认证安全等级。 | -| DISTRIBUTED_AUTH_NOT_SUPPORT | 3 | 设备不支持分布式认证。 | -| NOT_ENROLLED | 4 | 设备中认证凭据未录入。 | -| PARAM_NUM_ERROR | 5 | 参数个数错误。 | - - -## TipEvent7+ - -表示认证过程中提示事件的枚举。 - -| 名称 | 默认值 | 描述 | -| -------- | -------- | -------- | -| RESULT | 1 | 录入或认证结果。 | -| CANCEL | 2 | 录入或认证取消。 | -| ACQUIRE | 3 | 录入或认证过程中提示。 | -| BUSY | 4 | 录入或认证功能被占用。 | -| OUT_OF_MEM | 5 | 内存不足。 | -| FACE_ID | 6 | 人脸认证凭据索引号。 | - - -## TipCode7+ - -表示认证过程中提示码的枚举。 - -| 名称 | 默认值 | 描述 | -| -------- | -------- | -------- | -| FACE_AUTH_TIP_TOO_BRIGHT | 1 | 光线太强,获取的图像太亮。 | -| FACE_AUTH_TIP_TOO_DARK | 2 | 光线太暗,获取的图像太暗。 | -| FACE_AUTH_TIP_TOO_CLOSE | 3 | 人脸距离设备过近。 | -| FACE_AUTH_TIP_TOO_FAR | 4 | 人脸距离设备过远。 | -| FACE_AUTH_TIP_TOO_HIGH | 5 | 设备太高,仅获取到的人脸上部。 | -| FACE_AUTH_TIP_TOO_LOW | 6 | 设备太低,仅获取到的人脸下部。 | -| FACE_AUTH_TIP_TOO_RIGHT | 7 | 设备太靠右,仅获取到的人脸右部。 | -| FACE_AUTH_TIP_TOO_LEFT | 8 | 设备太靠左,仅获取到的人脸左部。 | -| FACE_AUTH_TIP_TOO_MUCH_MOTION | 9 | 在图像采集过程中,用户人脸移动太快。 | -| FACE_AUTH_TIP_POOR_GAZE | 10 | 没有正视摄像头。 | -| FACE_AUTH_TIP_NOT_DETECTED | 11 | 没有检测到人脸信息。 | diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/05.\346\225\260\346\215\256\347\256\241\347\220\206/01.\350\275\273\351\207\217\347\272\247\345\255\230\345\202\250.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/05.\346\225\260\346\215\256\347\256\241\347\220\206/01.\350\275\273\351\207\217\347\272\247\345\255\230\345\202\250.md" deleted file mode 100644 index 88333f9eb30558cfedf5faaf9469a30469187f50..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/05.\346\225\260\346\215\256\347\256\241\347\220\206/01.\350\275\273\351\207\217\347\272\247\345\255\230\345\202\250.md" +++ /dev/null @@ -1,781 +0,0 @@ ---- -title: 轻量级存储 -permalink: /pages/010c010501 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 轻量级存储 - -轻量级存储为应用提供key-value键值型的文件数据处理能力,支持应用对数据进行轻量级存储及查询。数据存储形式为键值对,键的类型为字符串型,值的存储数据类型包括数字型、字符型、布尔型。 - - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import dataStorage from '@ohos.data.storage' -``` - - -## 权限 - -无 - - -## 属性 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| MAX_KEY_LENGTH | string | 是 | 否 | key的最大长度限制,大小为80字节。 | -| MAX_VALUE_LENGTH | string | 是 | 否 | string类型value的最大长度限制,大小为8192字节。 | - - -## dataStorage.getStorageSync - -getStorageSync(path: string): Storage - -读取指定文件,将数据加载到Storage实例,用于数据操作,此方法为同步方法。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 应用程序内部数据存储路径。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [Storage](#storage) | 获取到要操作的Storage实例,用于进行数据存储操作。 | - -- 示例: - ``` - import dataStorage from '@ohos.data.storage' - import featureAbility from '@ohos.ability.featureAbility' - - var context = featureAbility.getContext() - var path = await context.getFilesDir() - let storage = dataStorage.getStorageSync(path + '/mystore') - storage.putSync('startup', 'auto') - storage.flushSync() - ``` - - -## dataStorage.getStorage - -getStorage(path: string, callback: AsyncCallback<Storage>): void - -读取指定文件,将数据加载到Storage实例,用于数据操作,使用callback形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 应用程序内部数据存储路径。 | - | callback | AsyncCallback<[Storage](#storage)> | 是 | 回调函数。 | - -- 示例: - ``` - import dataStorage from '@ohos.data.storage' - import featureAbility from '@ohos.ability.featureAbility' - - var context = featureAbility.getContext() - var path = await context.getFilesDir() - dataStorage.getStorage(path + '/mystore', function (err, storage) { - if (err) { - console.info("Get the storage failed, path: " + path + '/mystore') - return; - } - storage.putSync('startup', 'auto') - storage.flushSync() - }) - ``` - - -## dataStorage.getStorage - -getStorage(path: string): Promise<Storage> - -读取指定文件,将数据加载到Storage实例,用于数据操作,使用Promise方式作为异步方法。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 应用程序内部数据存储路径。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<[Storage](#storage)> | Promise实例,用于异步获取结果。 | - -- 示例: - ``` - import dataStorage from '@ohos.data.storage' - import featureAbility from '@ohos.ability.featureAbility' - - var context = featureAbility.getContext() - var path = await context.getFilesDir() - let promise = dataStorage.getStorage(path + '/mystore') - promise.then((storage) => { - storage.putSync('startup', 'auto') - storage.flushSync() - }).catch((err) => { - console.info("Get the storage failed, path: " + path + '/mystore') - }) - ``` - - -## dataStorage.deleteStorageSync - -deleteStorageSync(path: string): void - -从内存中移除指定文件对应的Storage单实例,并删除指定文件及其备份文件、损坏文件。删除指定文件时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题,此方法为同步方法。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 应用程序内部数据存储路径。 | - -- 示例: - ``` - dataStorage.deleteStorageSync(path + '/mystore') - ``` - - -## dataStorage.deleteStorage - -deleteStorage(path: string, callback: AsyncCallback<void>) - -从内存中移除指定文件对应的Storage单实例,并删除指定文件及其备份文件、损坏文件。删除指定文件时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题,使用callback方式作为异步方法。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 应用程序内部数据存储路径。 | - | callback | AsyncCallback<void> | 是 | 回调函数。 | - -- 示例: - ``` - dataStorage.deleteStorage(path + '/mystore', function (err) { - if (err) { - console.info("Deleted failed with err: " + err) - return - } - console.info("Deleted successfully.") - }) - ``` - - -## dataStorage.deleteStorage - -deleteStorage(path: string): Promise<void> - -从内存中移除指定文件对应的Storage单实例,并删除指定文件及其备份文件、损坏文件。删除指定文件时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题,使用promise方式作为异步方法。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 应用程序内部数据存储路径。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | Promise实例,用于异步获取结果。 | - -- 示例: - ``` - let promise = dataStorage.deleteStorage(path + '/mystore') - promise.then(() => { - console.info("Deleted successfully.") - }).catch((err) => { - console.info("Deleted failed with err: " + err) - }) - ``` - - -## dataStorage.removeStorageFromCacheSync - -removeStorageFromCacheSync(path: string): void - -从内存中移除指定文件对应的Storage单实例。移除Storage单实例时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题。 - -此方法为同步方法。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 应用程序内部数据存储路径。 | - -- 示例: - ``` - dataStorage.removeStorageFromCacheSync(path + '/mystore') - ``` - - -## dataStorage.removeStorageFromCache - -removeStorageFromCache(path: string, callback: AsyncCallback<Storage>): void - -从内存中移除指定文件对应的Storage单实例。移除Storage单实例时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题。 - -此方法为异步方法。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 应用程序内部数据存储路径。 | - | callback | AsyncCallback<[Storage](#storage)> | 是 | 回调函数。 | - -- 示例: - ``` - dataStorage.removeStorageFromCache(path + '/mystore', function (err) { - if (err) { - console.info("Removed storage from cache failed with err: " + err) - return - } - console.info("Removed storage from cache successfully.") - }) - ``` - - -## dataStorage.removeStorageFromCache - -removeStorageFromCache(path: string): Promise<void> - -从内存中移除指定文件对应的Storage单实例。移除Storage单实例时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题。 - -此方法为异步方法。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 应用程序内部数据存储路径。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | Promise实例,用于异步获取结果。 | - -- 示例: - ``` - let promise = dataStorage.removeStorageFromCache(path + '/mystore') - promise.then(() => { - console.info("Removed storage from cache successfully.") - }).catch((err) => { - console.info("Removed storage from cache failed with err: " + err) - }) - ``` - - -## Storage - -提供获取和修改存储数据的接口。 - - -### getSync - -getSync(key: string, defValue: ValueType): ValueType - -获取键对应的值,如果值为null或者非默认值类型,返回默认数据。 - -此方法为同步方法。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | string | 是 | 要获取的存储key名称。它不能为空。 | - | defValue | ValueType | 是 | 给定key的存储不存在,则要返回的默认值。支持number、string、boolean。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | ValueType | 键对应的值,如果值为null或者非默认值类型,返回默认数据。 | - -- 示例: - ``` - let value = storage.getSync('startup', 'default') - console.info("The value of startup is " + value) - ``` - - -### get - -get(key: string, defValue: ValueType, callback: AsyncCallback<ValueType>): void - -获取键对应的值,如果值为null或者非默认值类型,返回默认数据。 - -此方法为异步方法。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | string | 是 | 要获取的存储key名称。它不能为空。 | - | defValue | ValueType | 是 | 默认返回值。支持number、string、boolean。 | - | callback | AsyncCallback<ValueType> | 是 | 回调函数。 | - -- 示例: - ``` - storage.get('startup', 'default', function(err, value) { - if (err) { - console.info("Get the value of startup failed with err: " + err) - return - } - console.info("The value of startup is " + value) - }) - ``` - - -### get - -get(key: string, defValue: ValueType): Promise<ValueType> - -获取键对应的值,如果值为null或者非默认值类型,返默认数据。 - -此方法为异步方法。 - -- **参数:** - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | string | 是 | 要获取的存储key名称。它不能为空。 | - | defValue | ValueType | 是 | 默认返回值。支持number、string、boolean。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<ValueType> | Promise实例,用于异步获取结果。 | - -- 示例: - ``` - let promise = storage.get('startup', 'default') - promise.then((value) => { - console.info("The value of startup is " + value) - }).catch((err) => { - console.info("Get the value of startup failed with err: " + err) - }) - ``` - - -### putSync - -putSync(key: string, value: ValueType): void - -首先获取指定文件对应的Storage实例,然后借助Storage API将数据写入Storage实例,通过flush或者flushSync将Storage实例持久化。 - -此方法为同步方法。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | string | 是 | 要修改的存储的key。它不能为空。 | - | value | ValueType | 是 | 存储的新值。支持number、string、boolean。 | - -- 示例: - ``` - storage.putSync('startup', 'auto') - ``` - - -### put - -put(key: string, value: ValueType, callback: AsyncCallback<void>): void - -首先获取指定文件对应的Storage实例,然后借助Storage API将数据写入Storage实例,通过flush或者flushSync将Storage实例持久化。 - -此方法为异步方法。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | string | 是 | 要修改的存储的key。它不能为空。 | - | value | ValueType | 是 | 存储的新值。支持number、string、boolean。 | - | callback | AsyncCallback<void> | 是 | 回调函数。 | - -- 示例: - ``` - storage.put('startup', 'auto', function (err) { - if (err) { - console.info("Put the value of startup failed with err: " + err) - return - } - console.info("Put the value of startup successfully.") - }) - ``` - - -### put - -put(key: string, value: ValueType): Promise<void> - -首先获取指定文件对应的Storage实例,然后借助Storage API将数据写入Storage实例,通过flush或者flushSync将Storage实例持久化。 - -此方法为异步方法。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | string | 是 | 要修改的存储的key。它不能为空。 | - | value | ValueType | 是 | 存储的新值。支持number、string、boolean。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | Promise实例,用于异步处理。 | - -- 示例: - ``` - let promise = storage.put('startup', 'auto') - promise.then(() => { - console.info("Put the value of startup successfully.") - }).catch((err) => { - console.info("Put the value of startup failed with err: " + err) - }) - ``` - - -### hasSync - -hasSync(key: string): boolean - -检查存储对象是否包含名为给定key的存储。 - -此方法为同步方法。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | string | 是 | 要获取的存储key名称。它不能为空。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | true 表示存在,false表示不存在。 | - -- 示例: - ``` - let isExist = storage.hasSync('startup') - if (isExist) { - console.info("The key of startup is contained.") - } - ``` - - -### has - -has(key: string, callback: AsyncCallback<boolean>): boolean - -检查存储对象是否包含名为给定key的存储。 - -此方法为异步方法。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | string | 是 | 要获取的存储key名称,不能为空。 | - | callback | AsyncCallback<boolean> | 是 | 回调函数。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | true表示存在,false表示不存在。 | - -- 示例: - ``` - storage.has('startup', function (err, isExist) { - if (err) { - console.info("Check the key of startup failed with err: " + err) - return - } - if (isExist) { - console.info("The key of startup is contained.") - } - }) - ``` - - -### has - -has(key: string): Promise<boolean> - -检查存储对象是否包含名为给定key的存储。 - -此方法为异步方法。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | string | 是 | 要获取的存储key名称。它不能为空。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<boolean> | Promise实例,用于异步处理。 | - -- 示例: - ``` - let promise = storage.has('startup') - promise.then((isExist) => { - if (isExist) { - console.info("The key of startup is contained.") - } - }).catch((err) => { - console.info("Check the key of startup failed with err: " + err) - }) - ``` - - -### deleteSync - -deleteSync(key: string): void - -从存储对象中删除名为给定key的存储。 - -此方法为同步方法。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | string | 是 | 要获取的存储key名称。它不能为空。 | - -- 示例: - ``` - storage.deleteSync('startup') - ``` - - -### delete - -delete(key: string, callback: AsyncCallback<void>): void - -从存储对象中删除名为给定key的存储。 - -此方法为异步方法。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | string | 是 | 要获取的存储key名称,不能为空。 | - | callback | AsyncCallback<void> | 是 | 回调函数。 | - -- 示例: - ``` - storage.delete('startup', function (err) { - if (err) { - console.info("Delete startup key failed with err: " + err) - return - } - console.info("Deleted startup key successfully.") - }) - ``` - - -### delete - -delete(key: string): Promise<void> - -从存储对象删除名为给定key的存储。 - -此方法为异步方法。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | string | 是 | 要获取的存储key名称。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | Promise实例,用于异步处理。 | - -- 示例: - ``` - let promise = storage.delete('startup') - promise.then(() => { - console.info("Deleted startup key successfully.") - }).catch((err) => { - console.info("Delete startup key failed with err: " + err) - }) - ``` - - -### flushSync - -flushSync(): void - -将当前storage对象中的修改保存到当前的storage,并同步存储到文件中。 - -此方法为同步方法。 - -- 示例: - ``` - storage.flushSync() - ``` - - -### flush - -flush(callback: AsyncCallback<void>): void - -将当前storage对象中的修改保存到当前的storage,并异步存储到文件中。 - -此方法为异步方法。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<void> | 是 | 回调函数。 | - -- 示例: - ``` - storage.flush(function (err) { - if (err) { - console.info("Flush to file failed with err: " + err) - return - } - console.info("Flushed to file successfully.") - }) - ``` - - -### flush - -flush(): Promise<void> - -将当前storage对象中的修改保存到当前的storage,并异步存储到文件中。 - -此方法为异步方法。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | Promise实例,用于异步处理。 | - -- 示例: - ``` - let promise = storage.flush() - promise.then(() => { - console.info("Flushed to file successfully.") - }).catch((err) => { - console.info("Flush to file failed with err: " + err) - }) - ``` - - -### clearSync - -clearSync(): void - -清除此存储对象中的所有存储。 - -此方法为同步方法。 - -- 示例: - ``` - storage.clearSync() - ``` - - -### clear - -clear(callback: AsyncCallback<void>): void - -清除此存储对象中的所有存储。 - -此方法为异步方法。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<void> | 是 | 回调函数。 | - -- 示例: - ``` - storage.clear(function (err) { - if (err) { - console.info("Clear to file failed with err: " + err) - return - } - console.info("Cleared to file successfully.") - }) - ``` - - -### clear - -clear(): Promise<void> - -清除此存储对象中的所有存储。 - -此方法为异步方法。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | Promise实例,用于异步处理。 | - -- 示例: - ``` - let promise = storage.clear() - promise.then(() => { - console.info("Cleared to file successfully.") - }).catch((err) => { - console.info("Clear to file failed with err: " + err) - }) - ``` - - -### on('change') - -on(type: 'change', callback: Callback<StorageObserver>): void - -订阅数据变更者类需要实现StorageObserver接口,订阅的key的值发生变更后,在执行flush/flushSync方法后,callback方法会被回调。 - -- 参数: - | 参数名 | 类型 | 说明 | - | -------- | -------- | -------- | - | type | string | 事件类型,固定值'change',表示数据变更。 | - | callback | Callback<[StorageObserver](#storageobserver)> | 回调对象实例。 | - -- 示例: - ``` - var observer = function (key) { - console.info("The key of " + key + " changed.") - } - storage.on('change', observer) - storage.putSync('startup', 'auto') - storage.flushSync() // observer will be called. - ``` - - -### off('change') - -off(type: 'change', callback: Callback<StorageObserver>): void - -当不再进行订阅数据变更时,使用此接口取消订阅。 - -- 参数: - | 参数名 | 类型 | 说明 | - | -------- | -------- | -------- | - | type | string | 事件类型,固定值'change',表示数据变更。 | - | callback | Callback<[StorageObserver](#storageobserver)> | 需要取消的回调对象实例。 | - -- 示例: - ``` - var observer = function (key) { - console.info("The key of " + key + " changed.") - } - storage.off('change', observer) - ``` - - -## StorageObserver - -| 名称 | 参数类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| key | string | 否 | 变更的数据内容。 | diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/05.\346\225\260\346\215\256\347\256\241\347\220\206/02.\345\210\206\345\270\203\345\274\217\346\225\260\346\215\256\347\256\241\347\220\206.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/05.\346\225\260\346\215\256\347\256\241\347\220\206/02.\345\210\206\345\270\203\345\274\217\346\225\260\346\215\256\347\256\241\347\220\206.md" deleted file mode 100644 index 0e0ce2c47158077982d19da23a0c17d62a33bf6f..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/05.\346\225\260\346\215\256\347\256\241\347\220\206/02.\345\210\206\345\270\203\345\274\217\346\225\260\346\215\256\347\256\241\347\220\206.md" +++ /dev/null @@ -1,8644 +0,0 @@ ---- -title: 分布式数据管理 -permalink: /pages/010c010502 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 分布式数据管理 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - -## 导入模块 - -``` -import distributedData from '@ohos.data.distributedData'; -``` - -## 权限 - -无 - -## distributedData.createKVManager - -createKVManager(config: KVManagerConfig, callback: AsyncCallback<KVManager>): void - -创建一个KVManager对象实例,用于管理数据库对象,并通过callback方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

config

-

KVManagerConfig

-

-

提供KVManager实例的配置信息,包括调用方的包名和用户信息。

-

callback

-

AsyncCallback<KVManager>

-

-

KVManager实例创建时调用的回调,返回KVManager对象实例。

-
- -- 示例: - - ``` - let kvManager; - try { - const kvManagerConfig = { - bundleName : 'com.example.datamanagertest', - userInfo : { - userId : '0', - userType : distributedData.UserType.SAME_USER_ID - } - } - distributedData.createKVManager(kvManagerConfig, function (err, manager) { - if (err) { - console.log("createKVManager err: " + JSON.stringify(err)); - return; - } - console.log("createKVManager success"); - kvManager = manager; - }); - } catch (e) { - console.log("An unexpected error occurred. Error:" + e); - } - ``` - - -## distributedData.createKVManager - -createKVManager(config: KVManagerConfig): Promise<KVManager> - -创建一个KVManager对象实例,用于管理数据库对象,并通过Promise方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

config

-

KVManagerConfig

-

-

提供KVManager实例的配置信息,包括调用方的包名和用户信息。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Promise<KVManager>

-

指定的Promise回调方法,返回创建的KVManager对象实例。

-
- -- 示例: - - ``` - let kvManager; - try { - const kvManagerConfig = { - bundleName : 'com.example.datamanagertest', - userInfo : { - userId : '0', - userType : distributedData.UserType.SAME_USER_ID - } - } - distributedData.createKVManager(kvManagerConfig).then((manager) => { - console.log("createKVManager success"); - kvManager = manager; - }).catch((err) => { - console.log("createKVManager err: " + JSON.stringify(err)); - }); - } catch (e) { - console.log("An unexpected error occurred. Error:" + e); - } - ``` - - -## KVManagerConfig - -提供KVManager实例的配置信息,包括调用方的包名和用户信息。 - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

必填

-

描述

-

userInfo

-

UserInfo

-

-

调用方的用户信息。

-

bundleName

-

string

-

-

调用方的包名。

-
- -## UserInfo - -用户信息。 - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

必填

-

描述

-

userId

-

string

-

-

指示要设置的用户ID。

-

userType

-

UserType

-

-

指示要设置的用户类型。

-
- -## UserType - -用户类型。 - - - - - - - - - - - - -

名称

-

默认值

-

说明

-

SAME_USER_ID

-

0

-

使用同一帐户登录不同设备的用户。

-
- -## KVManager - -数据管理实例,用于获取KVStore的相关信息。在调用KVManager的方法前,需要先通过createKVManager构建一个KVManager实例。 - -### getKVStore - -getKVStore(storeId: string, options: Options, callback: AsyncCallback<T>): void - -通过指定Options和storeId,创建并获取KVStore数据库,并通过callback方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

storeId

-

string

-

-

数据库唯一标识符,长度不大于MAX_STORE_ID_LENGTH

-

options

-

Options

-

-

创建KVStore实例的配置信息。

-

callback

-

AsyncCallback<T>,

-

<T extends KVStore>

-

-

创建KVStore实例的回调,返回KVStore对象实例。

-
- -- 示例: - - ``` - let kvStore; - let kvManager; - try { - const options = { - createIfMissing : true, - encrypt : false, - backup : false, - autoSync : true, - kvStoreType : distributedData.KVStoreType.SINGLE_VERSION, - securityLevel : distributedData.SecurityLevel.S2, - }; - kvManager.getKVStore('storeId', options, function (err, store) { - if (err) { - console.log("getKVStore err: " + JSON.stringify(err)); - return; - } - console.log("getKVStore success"); - kvStore = store; - }); - } catch (e) { - console.log("An unexpected error occurred. Error:" + e); - } - ``` - - -### getKVStore - -getKVStore<T extends KVStore>(storeId: string, options: Options): Promise<T> - -通过指定Options和storeId,创建并获取KVStore数据库,并通过Promise方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

storeId

-

string

-

-

数据库唯一标识符,长度不大于MAX_STORE_ID_LENGTH

-

options

-

Options

-

-

创建KVStore实例的配置信息。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Promise<T>

-

<T extends KVStore>

-

指定的Promise回调方法,返回创建的KVStore数据库实例。

-
- -- 示例: - - ``` - let kvStore; - let kvManager; - try { - const options = { - createIfMissing : true, - encrypt : false, - backup : false, - autoSync : true, - kvStoreType : distributedData.KVStoreType.SINGLE_VERSION, - securityLevel : distributedData.SecurityLevel.S2, - }; - kvManager.getKVStore('storeId', options).then((store) => { - console.log("getKVStore success"); - kvStore = store; - }).catch((err) => { - console.log("getKVStore err: " + JSON.stringify(err)); - }); - } catch (e) { - console.log("An unexpected error occurred. Error:" + e); - } - ``` - -### closeKVStore8+ ### - -closeKVStore(appId: string, storeId: string, kvStore: KVStore, callback: AsyncCallback<void>): void; - -通过storId的值关闭指定的kvStore数据库,并通过callback方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

appId

-

string

-

-

所调用数据库方的包名。

-

storeId

-

string

-

-

要关闭的数据库唯一标识符,长度不大于MAX_STORE_ID_LENGTH

-

kvStore

-

KVStore

-

-

要关闭的KvStore数据库。

-

callback

-

AsyncCallback<void>

-

-

回调函数,如果数据库关闭成功则返回true,否则返回false。

-
- -- 示例: - - ``` - let kvStore; - let kvManager; - const options = { - createIfMissing : true, - encrypt : false, - backup : false, - autoSync : true, - kvStoreType : distributedData.KVStoreType.SINGLE_VERSION, - schema : '', - securityLevel : distributedData.SecurityLevel.S2, - } - try { - kvManager.getKVStore('storeId', options, async function (err, store) { - console.log('getKVStore success'); - kvStore = store; - await kvManager.closeKVStore('appId', 'storeId', kvStore, function (err, data) { - console.log('closeKVStore success'); - }); - }); - } catch (e) { - console.log('closeKVStore e ' + e); - } - ``` - -### closeKVStore8+ ### - -closeKVStore(appId: string, storeId: string, kvStore: KVStore): Promise<void>; - -通过kvStore的值关闭指定的kvStore数据库,并通过Promise方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

appId

-

string

-

-

所调用数据库方的包名。

-

storeId

-

string

-

-

要关闭的数据库唯一标识符,长度不大于MAX_STORE_ID_LENGTH

-

kvStore

-

KVStore

-

-

要关闭的数据库。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Promise<void>

-

Promise实例,如果数据库关闭成功则返回true,否则返回false。

-
- -- 示例: - - ``` - let kvManager; - let kvStore; - const options = { - createIfMissing : true, - encrypt : false, - backup : false, - autoSync : true, - kvStoreType : distributedData.KVStoreType.SINGLE_VERSION, - schema : '', - securityLevel : distributedData.SecurityLevel.S2, - } - try { - kvManager.getKVStore('storeId', options).then(async (store) => { - console.log('getKVStore success'); - kvStore = store; - await kvManager.closeKVStore('appId', 'storeId', kvStore).then(() => { - console.log('closeKVStore success'); - }).catch((err) => { - console.log('closeKVStore err ' + JSON.stringify(err)); - }); - }).catch((err) => { - console.log('CloseKVStore getKVStore err ' + JSON.stringify(err)); - }); - } catch (e) { - console.log('closeKVStore e ' + e); - } - ``` - - -### deleteKVStore8+ ### - -deleteKVStore(appId: string, storeId: string, callback: AsyncCallback<void>): void; - -通过storeId的值删除指定的kvStore数据库,并通过callback方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

appId

-

string

-

-

所调用数据库方的包名。

-

storeId

-

string

-

-

要删除的数据库唯一标识符,长度不大于MAX_STORE_ID_LENGTH

-

callback

-

AsyncCallback<void>

-

-

回调函数,如果成功返回true,否则返回false。

-
- -- 示例: - - ``` - let kvManager; - let kvStore; - const options = { - createIfMissing : true, - encrypt : false, - backup : false, - autoSync : true, - kvStoreType : distributedData.KVStoreType.SINGLE_VERSION, - schema : '', - securityLevel : distributedData.SecurityLevel.S2, - } - try { - kvManager.getKVStore('store', options, async function (err, store) { - console.log('getKVStore success'); - kvStore = store; - await kvManager.deleteKVStore('appId', 'storeId', function (err, data) { - console.log('deleteKVStore success'); - }); - }); - } catch (e) { - console.log('DeleteKVStore e ' + e); - } - ``` - -### deleteKVStore8+ ### - -deleteKVStore(appId: string, storeId: string): Promise<void>; - -通过storeId的值删除指定的kvStore数据库,并通过Promise方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

appId

-

string

-

-

所调用数据库方的包名。

-

storeId

-

string

-

-

要删除数据库的唯一标识符,长度不大于MAX_STORE_ID_LENGTH

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Promise<void>

-

Promise实例,如果成功返回true,否则返回false。

-
- -- 示例: - - ``` - let kvManager; - let kvStore; - const options = { - createIfMissing : true, - encrypt : false, - backup : false, - autoSync : true, - kvStoreType : distributedData.KVStoreType.SINGLE_VERSION, - schema : '', - securityLevel : distributedData.SecurityLevel.S2, - } - try { - kvManager.getKVStore('storId', options).then(async (store) => { - console.log('getKVStore success'); - kvStore = store; - await kvManager.deleteKVStore('appId', 'storeId').then(() => { - console.log('deleteKVStore success'); - }).catch((err) => { - console.log('deleteKVStore err ' + JSON.stringify(err)); - }); - }).catch((err) => { - console.log('getKVStore err ' + JSON.stringify(err)); - }); - } catch (e) { - console.log('deleteKVStore e ' + e); - } - ``` - - -### getAllKVStoreId8+ ### - -getAllKVStoreId(appId: string, callback: AsyncCallback<string[]>): void; - -获取所有通过getKvStore方法创建的且没有调用deleteKvStore方法删除的KvStore数据库的storeId,并通过callback方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

appId

-

string

-

-

所调用数据库方的包名。

-

callback

-

AsyncCallback<void>

-

-

回调函数,返回所有创建的 KvStore 数据库的 storeId。

-
- -- 示例: - - ``` - let kvManager; - try { - kvManager.getAllKVStoreId('appId', function (err, data) { - console.log('GetAllKVStoreId success'); - console.log('GetAllKVStoreId size = ' + data.length); - }); - } catch (e) { - console.log('GetAllKVStoreId e ' + e); - } - ``` - - -### getAllKVStoreId8+ ### - -getAllKVStoreId(appId: string): Promise<string[]>; - -获取所有通过getKvStore方法创建的且没有调用deleteKvStore方法删除的KvStore数据库的storeId,并通过Promise方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

appId

-

string

-

-

所调用数据库方的包名。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Promise<string[]>

-

Promise实例,返回所有创建的 KvStore 数据库的 storeId。。

-
- -- 示例: - - ``` - let kvManager; - try { - console.log('GetAllKVStoreId'); - kvManager.getAllKVStoreId('apppId').then((data) => { - console.log('getAllKVStoreId success'); - console.log('size = ' + data.length); - }).catch((err) => { - console.log('getAllKVStoreId err ' + JSON.stringify(err)); - }); - } catch(e) { - console.log('getAllKVStoreId e ' + e); - } - ``` - - -### on8+ ### - -on(event: 'distributedDataServiceDie', deathCallback: Callback<void>): void; - -订阅服务状态变更通知,并通过callback方式返回,此方法为同步方法。 - -- 参数: - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

event

-

'distributedDataServiceDie'

-

-

服务状态改变时触发的事件名。

-

deathCallback

-

Callback<void>

-

-

回调函数,在设备状态改变时获取通知。

-
- -- 示例 - - ``` - let kvManager; - try { - - console.log('KVManagerOn'); - const deathCallback = function () { - console.log('death callback call'); - } - kvManager.on('distributedDataServiceDie', deathCallback); - } catch (e) { - console.log("An unexpected error occurred. Error:" + e); - } - ``` - - -### off8+ ### - -off(event: 'distributedDataServiceDie', deathCallback?: Callback<void>): void; - -取消订阅服务状态变更通知,并通过callback方式返回,此方法为同步方法。 - -- 参数: - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

event

-

'distributedDataServiceDie'

-

-

服务状态改变时触发的事件名。

-

deathCallback

-

Callback<void>

-

-

回调函数,取消设备状态改变时获取通知。

-
- -- 示例 - - ``` - let kvManager; - try { - console.log('KVManagerOff'); - const deathCallback = function () { - console.log('death callback call'); - } - kvManager.off('distributedDataServiceDie', deathCallback); - } catch (e) { - console.log("An unexpected error occurred. Error:" + e); - } - - ``` - -## Options - -用于提供创建数据库的配置信息。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

createIfMissing

-

boolean

-

-

当数据库文件不存在时是否创建数据库,默认创建。

-

encrypt

-

boolean

-

-

设置数据库文件是否加密,默认不加密。

-

backup

-

boolean

-

-

设置数据库文件是否备份,默认备份。

-

autoSync

-

boolean

-

-

设置数据库文件是否自动同步,默认不自动同步。

-

kvStoreType

-

KVStoreType

-

-

设置要创建的数据库类型,默认为多设备协同数据库。

-

securityLevel

-

SecurityLevel

-

-

设置数据库安全级别,默认不设置安全级别。

-
- -## KVStoreType - -用于指定创建的数据库的类型。 - - - - - - - - - - - - - - - - - - - - -

名称

-

默认值

-

说明

-

DEVICE_COLLABORATION

-

0

-

表示多设备协同数据库。

-

SINGLE_VERSION

-

1

-

表示单版本数据库。

-

MULTI_VERSION

-

2

-

表示多版本数据库。此类型当前不允许使用。

-
- -## SecurityLevel - -用于指定创建的数据库的安全级别。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

默认值

-

说明

-

NO_LEVEL

-

0

-

表示数据库不设置安全级别。

-

S0

-

1

-

表示数据库的安全级别为公共级别安全。

-

S1

-

2

-

表示数据库的安全级别为低级别安全,当数据泄露时会产生较低影响。

-

S2

-

3

-

表示数据库的安全级别为中级别安全,当数据泄露时会产生较大影响。

-

S3

-

5

-

表示数据库的安全级别为高级别安全,当数据泄露时会产生重大影响。

-

S4

-

6

-

表示数据库的安全级别为关键级别安全,当数据泄露时会产生严重影响。

-
- -## Constants - -KVStore常量。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

默认值

-

说明

-

MAX_KEY_LENGTH

-

1024

-

数据库中Key允许最大长度,单位字节。

-

MAX_VALUE_LENGTH

-

4194303

-

数据库中Value允许的最大长度,单位字节。

-

MAX_KEY_LENGTH_DEVICE

-

896

-

最大设备坐标密钥长度。

-

MAX_STORE_ID_LENGTH

-

128

-

数据库标识符允许的最大长度,单位字节。

-

MAX_QUERY_LENGTH

-

512000

-

最大查询长度。

-

MAX_BATCH_SIZE

-

128

-

最大批处理操作大小。

-
- -## Schema8+ ## - -表示数据库模式,可以在创建或打开数据库时创建 Schema 对象并将它们放入 Options 中。 - -### toJsonString8+ ### - -toJsonString():string; - -获取 json 格式的 schema 。 - -- 返回值: - - - - - - - - - - -

类型

-

说明

-

string

-

以 json 格式返回Schema。

-
- -- 示例 - - ``` - import ddm from '@ohos.data.distributedData'; - try { - let schema = new ddm.Schema(); - const str = schema.toJsonString(); - console.log("schema: " + str); - } catch (e) { - console.log("toJsonString " + e); - } - ``` - - -## FieldNode8+ ## - -表示 Schema 实例的节点,提供定义存储在数据库中的值的方法。 - -### appendChild8+ ### - -appendChild(child: FieldNode): boolean; - -向这个 FieldNode 添加一个子节点。 - -- 参数: - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

child

-

FieldNode

-

-

要附加的域节点。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

boolean

-

如果子节点成功添加到这个FieldNode,则返回 true;否则返回 false。

-
- -- 示例 - - ``` - import ddm from '@ohos.data.distributedData'; - try { - let node = new ddm.FieldNode("root"); - let child1 = new ddm.FieldNode("child1"); - let child2 = new ddm.FieldNode("child2"); - let child3 = new ddm.FieldNode("child3"); - node.appendChild(child1); - node.appendChild(child2); - node.appendChild(child3); - console.log("appendNode " + node.toJson()); - child1 = null; - child2 = null; - child3 = null; - node = null; - } catch (e) { - console.log("AppendChild " + e); - } - ``` - - -### toJson8+ ### - -toJson(): string; - -获取字段名称。 - -- 返回值: - - - - - - - - - - -

类型

-

说明

-

string

-

返回节点的字段名称。

-
- -- 示例 - - ``` - import ddm from '@ohos.data.distributedData'; - try { - let node = new ddm.FieldNode("root"); - let child = new ddm.FieldNode("child"); - node.appendChild(child); - console.log("appendNode " + node.toJson()); - } catch (e) { - console.log("ToJson " + e); - } - ``` - - -## KvStoreResultSet8+ ## - -提供获取KvStore数据库结果集的方法,提供查询和移动数据读取位置的方法,在调用KvStoreResultSet的方法前,需要先通过KvStore 构建一个KvStore 实例。 - -### getCount8+ ### - -getCount(): number; - -获取结果集中的行数。 - -- 返回值: - - - - - - - - - - -

类型

-

说明

-

number

-

返回行数。

-
- -- 示例 - - ``` - let kvStore; - try { - let resultSet; - kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('getResultSet success'); - resultSet = result; - }).catch((err) => { - console.log('getResultSet fail ' + err); - }); - const count = resultSet.getCount(); - console.log("GetCount " + count); - } catch (e) { - console.log("GetCount fail " + e); - } - ``` - - -### getPosition8+ ### - -getPosition(): number; - -获取结果集中当前的读取位置。 - -- 返回值: - - - - - - - - - - -

类型

-

说明

-

number

-

返回当前读取位置。

-
- -- 示例 - - ``` - let kvStore; - try { - let resultSet; - kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('getResultSet success'); - resultSet = result; - }).catch((err) => { - console.log('getResultSet fail ' + err); - }); - const positon = resultSet.getPosition(); - console.log("getPosition " + positon); - } catch (e) { - console.log("GetPosition fail " + e); - } - ``` - - -### moveToFirst8+ ### - -moveToFirst(): boolean; - -将读取位置移动到第一行。 - -- 返回值: - - - - - - - - - - -

类型

-

说明

-

boolean

-

如果操作成功则返回true,否则返回 false。

-
- -- 示例 - - ``` - let kvStore; - try { - let resultSet; - kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('getResultSet success'); - resultSet = result; - }).catch((err) => { - console.log('getResultSet fail ' + err); - }); - const moved = resultSet.moveToFirst(); - console.log("moveToFirst " + moved); - } catch (e) { - console.log("MoveToFirst fail " + e); - } - ``` - - -### moveToLast8+ ### - -moveToLast(): boolean; - -将读取位置移动到最后一行。 - -- 返回值: - - - - - - - - - - -

类型

-

说明

-

boolean

-

如果操作成功则返回true,否则返回 false。

-
- -- 示例 - - ``` - let kvStore; - try { - let resultSet; - kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('getResultSet success'); - resultSet = result; - }).catch((err) => { - console.log('getResultSet fail ' + err); - }); - const moved = resultSet.moveToLast(); - console.log("moveToLast " + moved); - } catch (e) { - console.log("moveToLast fail " + e); - } - ``` - - -### moveToNext8+ ### - -moveToNext(): boolean; - -将读取位置移动到下一行。 - -- 返回值: - - - - - - - - - - -

类型

-

说明

-

boolean

-

如果操作成功则返回true,否则返回 false。

-
- -- 示例 - - ``` - let kvStore; - try { - let resultSet; - kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('getResultSet success'); - resultSet = result; - }).catch((err) => { - console.log('getResultSet fail ' + err); - }); - const moved = resultSet.moveToNext(); - console.log("moveToNext " + moved); - } catch (e) { - console.log("moveToNext fail " + e); - } - ``` - - -### moveToPrevious8+ ### - -moveToPrevious(): boolean; - -将读取位置移动到上一行。 - -- 返回值: - - - - - - - - - - -

类型

-

说明

-

boolean

-

如果操作成功则返回true,否则返回 false。

-
- -- 示例 - - ``` - let kvStore; - try { - let resultSet; - kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('getResultSet success'); - resultSet = result; - }).catch((err) => { - console.log('getResultSet fail ' + err); - }); - const moved = resultSet.moveToPrevious(); - console.log("moveToPrevious " + moved); - } catch (e) { - console.log("moveToPrevious fail " + e); - } - ``` - - -### move8+ ### - -move(offset: number): boolean; - -将读取位置移动到当前位置的相对偏移量。 - -- 参数: - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

offset

-

number

-

-

表示与当前位置的相对偏移量,负偏移表示向后移动,正偏移表示向前移动。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

boolean

-

如果操作成功则返回true,否则返回 false。

-
- -- 示例 - - ``` - let kvStore; - try { - let resultSet; - kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('getResultSet success'); - resultSet = result; - }).catch((err) => { - console.log('getResultSet fail ' + err); - }); - const moved = resultSet.move(); - console.log("move " + moved); - } catch (e) { - console.log("move fail " + e); - } - ``` - - -### moveToPosition8+ ### - -moveToPosition(position: number): boolean; - -将读取位置从 0 移动到绝对位置。 - -- 参数: - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

position

-

number

-

-

表示绝对位置。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

boolean

-

如果操作成功则返回true,否则返回 false。

-
- -- 示例 - - ``` - let kvStore; - try { - let resultSet; - kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('getResultSet success'); - resultSet = result; - }).catch((err) => { - console.log('getResultSet fail ' + err); - }); - const moved = resultSet.moveToPosition(); - console.log("moveToPosition " + moved); - } catch (e) { - console.log("moveToPosition fail " + e); - } - ``` - - -### isFirst8+ ### - -isFirst(): boolean; - -检查读取位置是否为第一行。 - -- 返回值: - - - - - - - - - - -

类型

-

说明

-

boolean

-

如果读取位置是第一行,则返回 true;否则返回 false。

-
- -- 示例 - - ``` - let kvStore; - try { - let resultSet; - kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('getResultSet success'); - resultSet = result; - }).catch((err) => { - console.log('getResultSet fail ' + err); - }); - const moved = resultSet.isFirst(); - console.log("isFirst " + moved); - } catch (e) { - console.log("isFirst fail " + e); - } - ``` - - -### isLast8+ ### - -isLast(): boolean; - -检查读取位置是否为最后一行。 - -- 返回值: - - - - - - - - - - -

类型

-

说明

-

boolean

-

如果读取位置是最后一行,则返回 true;否则返回 false。

-
- -- 示例 - - ``` - let kvStore; - try { - let resultSet; - kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('getResultSet success'); - resultSet = result; - }).catch((err) => { - console.log('getResultSet fail ' + err); - }); - const moved = resultSet.isLast(); - console.log("isLast " + moved); - } catch (e) { - console.log("isLast fail " + e); - } - ``` - - -### isBeforeFirst8+ ### - -isBeforeFirst(): boolean; - -检查读取位置是否在第一行之前。 - -- 返回值: - - - - - - - - - - -

类型

-

说明

-

boolean

-

如果读取位置在第一行之前,则返回 true;否则返回 false。

-
- -- 示例 - - ``` - let kvStore; - try { - let resultSet; - kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('getResultSet success'); - resultSet = result; - }).catch((err) => { - console.log('getResultSet fail ' + err); - }); - const moved = resultSet.isBeforeFirst(); - console.log("isBeforeFirst " + moved); - } catch (e) { - console.log("isBeforeFirst fail " + e); - } - ``` - - -### isAfterLast8+ ### - -isAfterLast(): boolean; - -检查读取位置是否在最后一行之后。 - -- 返回值: - - - - - - - - - - -

类型

-

说明

-

boolean

-

如果读取位置在最后一行之后,则返回 true;否则返回 false。

-
- -- 示例 - - ``` - let kvStore; - try { - let resultSet; - kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('getResultSet success'); - resultSet = result; - }).catch((err) => { - console.log('getResultSet fail ' + err); - }); - const moved = resultSet.isAfterLast(); - console.log("isAfterLast " + moved); - } catch (e) { - console.log("isAfterLast fail " + e); - } - ``` - - -### getEntry8+ ### - -getEntry(): Entry; - -获取键值对 - -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Entry

-

返回键值对。

-
- -- 示例 - - ``` - let kvStore; - try { - let resultSet; - kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('getResultSet success'); - resultSet = result; - }).catch((err) => { - console.log('getResultSet fail ' + err); - }); - const moved = resultSet.moveToNext(); - const entry = resultSet.getEntry(); - console.log("getEntry " + JSON.stringify(entry)); - } catch (e) { - console.log("getEntry fail " + e); - } - ``` - - -## Query 8+ ## - -使用谓词表示数据库查询,提供创建Query实例、查询数据库中的数据和添加谓词的方法。 - -### reset8+ ### - -reset(): Query; - -公共查询重置。 - -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Query

-

返回重置的 Query 对象。

-
- -- 示例 - - ``` - try { - let query = new distributedData.Query(); - query.equalTo("key", "value"); - console.log("query is " + query.getSqlLike()); - query.reset(); - console.log("query is " + query.getSqlLike()); - query = null; - } catch (e) { - console.log("simply calls should be ok :" + e); - } - ``` - - -### equalTo8+ ### - -equalTo(field: string, value: number|string|boolean): Query; - -构造一个Query对象来查询具有指定字段的条目,其值等于指定的值。 - -- 参数: - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

fieId

-

string

-

-

表示指定字段,必须以$开头, 并且不能包含' ^ '。

-

value

-

number | string | boolean

-

-

表示指定的值。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Query

-

返回查询对象。

-
- -- 示例 - - ``` - try { - let query = new distributedData.Query(); - query.equalTo("field", "value"); - console.log("query is " + query.getSqlLike()); - query = null; - } catch (e) { - console.log("dumplicated calls should be ok :" + e); - } - ``` - - -### notEqualTo8+ ### - -notEqualTo(field: string, value: number|string|boolean): Query; - -构造一个Query对象以查询具有指定字段且值不等于指定值的条目。 - -- 参数: - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

fieId

-

string

-

-

表示指定字段,必须以$开头, 并且不能包含' ^ '。

-

value

-

number|string|boolean

-

-

表示指定的值。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Query

-

返回查询对象。

-
- -- 示例 - - ``` - try { - let query = new distributedData.Query(); - query.notEqualTo("field", "value"); - console.log("query is " + query.getSqlLike()); - query = null; - } catch (e) { - console.log("dumplicated calls should be ok :" + e); - } - ``` - - -### greaterThan8+ ### - -greaterThan(field: string, value: number|string|boolean): Query; - -构造一个Query对象以查询具有大于指定值的指定字段的条目。 - -- 参数: - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

fieId

-

string

-

-

表示指定字段,必须以$开头, 并且不能包含' ^ '。

-

value

-

number|string|boolean

-

-

表示指定的值。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Query

-

返回查询对象。

-
- -- 示例 - - ``` - try { - let query = new distributedData.Query(); - query.greaterThan("field", "value"); - console.log("query is " + query.getSqlLike()); - query = null; - } catch (e) { - console.log("dumplicated calls should be ok :" + e); - } - ``` - - -### lessThan8+ ### - -lessThan(field: string, value: number|string): Query; - -构造一个Query对象以查询具有小于指定值的指定字段的条目。 - -- 参数: - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

fieId

-

string

-

-

表示指定字段,必须以$开头, 并且不能包含' ^ '。

-

value

-

number|string

-

-

表示指定的值。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Query

-

返回查询对象。

-
- -- 示例 - - ``` - try { - let query = new distributedData.Query(); - query.lessThan("field", "value"); - console.log("query is " + query.getSqlLike()); - query = null; - } catch (e) { - console.log("dumplicated calls should be ok :" + e); - } - ``` - - -### greaterThanOrEqualTo8+ ### - -greaterThanOrEqualTo(field: string, value: number|string): Query; - -构造一个Query对象以查询具有指定字段且值大于或等于指定值的条目。 - -- 参数: - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

fieId

-

string

-

-

表示指定字段,必须以$开头, 并且不能包含' ^ '。

-

value

-

number|string

-

-

表示指定的值。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Query

-

返回查询对象。

-
- -- 示例 - - ``` - try { - let query = new distributedData.Query(); - query.greaterThanOrEqualTo("field", "value"); - console.log("query is " + query.getSqlLike()); - query = null; - } catch (e) { - console.log("dumplicated calls should be ok :" + e); - } - ``` - - -### lessThanOrEqualTo8+ ### - -lessThanOrEqualTo(field: string, value: number|string): Query; - -构造一个Query对象以查询具有指定字段且值小于或等于指定值的条目。 - -- 参数: - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

fieId

-

string

-

-

表示指定字段,必须以$开头, 并且不能包含' ^ '。

-

value

-

number|string

-

-

表示指定的值。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Query

-

返回查询对象。

-
- -- 示例 - - ``` - try { - let query = new distributedData.Query(); - query.lessThanOrEqualTo("field", "value"); - console.log("query is " + query.getSqlLike()); - query = null; - } catch (e) { - console.log("dumplicated calls should be ok :" + e); - } - ``` - - -### isNull8+ ### - -isNull(field: string): Query; - -构造一个Query对象以查询具有值为null的指定字段的条目。 - -- 参数: - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

fieId

-

string

-

-

表示指定字段,必须以$开头, 并且不能包含' ^ '。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Query

-

返回查询对象。

-
- -- 示例 - - ``` - try { - let query = new distributedData.Query(); - query.isNull("field"); - console.log("query is " + query.getSqlLike()); - query = null; - } catch (e) { - console.log("dumplicated calls should be ok :" + e); - } - ``` - - -### inNumber8+ ### - -inNumber(field: string, valueList: number[]): Query; - -构造一个Query对象以查询具有指定字段的条目,其值在指定的值列表中。 - -- 参数: - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

fieId

-

string

-

-

表示指定字段,必须以$开头, 并且不能包含' ^ '。

-

valueList

-

number[]

-

-

表示指定的值列表。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Query

-

返回查询对象。

-
- -- 示例 - - ``` - try { - let query = new distributedData.Query(); - query.inNumber("field", [0, 1]); - console.log("query is " + query.getSqlLike()); - query = null; - } catch (e) { - console.log("dumplicated calls should be ok :" + e); - } - ``` - - -### inString8+ ### - -inString(field: string, valueList: string[]): Query; - -构造一个Query对象以查询具有指定字段的条目,其值在指定的字符串值列表中。 - -- 参数: - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

fieId

-

string

-

-

表示指定字段,必须以$开头, 并且不能包含' ^ '。

-

valueList

-

string[]

-

-

表示指定的字符串值列表。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Query

-

返回查询对象。

-
- -- 示例 - - ``` - try { - let query = new distributedData.Query(); - query.inString("field", ['test1', 'test2']); - console.log("query is " + query.getSqlLike()); - query = null; - } catch (e) { - console.log("dumplicated calls should be ok :" + e); - } - ``` - - -### notInNumber8+ ### - -notInNumber(field: string, valueList: number[]): Query; - -构造一个Query对象以查询具有指定字段的条目,该字段的值不在指定的值列表中。 - -- 参数: - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

fieId

-

string

-

-

表示指定字段,必须以$开头, 并且不能包含' ^ '。

-

valueList

-

number[]

-

-

表示指定的值列表。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Query

-

返回查询对象。

-
- -- 示例 - - ``` - try { - let query = new distributedData.Query(); - query.notInNumber("field", [0, 1]); - console.log("query is " + query.getSqlLike()); - query = null; - } catch (e) { - console.log("dumplicated calls should be ok :" + e); - } - ``` - - -### notInString8+ ### - -notInString(field: string, valueList: string[]): Query; - -构造一个Query对象以查询具有指定字段且值不在指定字符串值列表中的条目。 - -- 参数: - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

fieId

-

string

-

-

表示指定字段,必须以$开头, 并且不能包含' ^ '。

-

valueList

-

string[]

-

-

表示指定的字符串值列表。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Query

-

返回查询对象。

-
- -- 示例 - - ``` - try { - let query = new distributedData.Query(); - query.notInString("field", ['test1', 'test2']); - console.log("query is " + query.getSqlLike()); - query = null; - } catch (e) { - console.log("dumplicated calls should be ok :" + e); - } - ``` - - -### like8+ ### - -like(field: string, value: string): Query; - -构造一个Query对象以查询具有与指定字符串值相似的指定字段的条目。 - -- 参数: - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

fieId

-

string

-

-

表示指定字段,必须以$开头, 并且不能包含' ^ '。

-

value

-

string

-

-

表示指定的字符串值。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Query

-

返回查询对象。

-
- -- 示例 - - ``` - try { - let query = new distributedData.Query(); - query.like("field", "value"); - console.log("query is " + query.getSqlLike()); - query = null; - } catch (e) { - console.log("dumplicated calls should be ok :" + e); - } - ``` - - -### unlike8+ ### - -unlike(field: string, value: string): Query; - -构造一个Query对象以查询具有与指定字符串值不相似的指定字段的条目。 - -- 参数: - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

fieId

-

string

-

-

表示指定字段,必须以$开头, 并且不能包含' ^ '。

-

value

-

string

-

-

表示指定的字符串值。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Query

-

返回查询对象。

-
- -- 示例 - - ``` - try { - let query = new distributedData.Query(); - query.unlike("field", "value"); - console.log("query is " + query.getSqlLike()); - query = null; - } catch (e) { - console.log("dumplicated calls should be ok :" + e); - } - ``` - - -### and8+ ### - -and(): Query; - -构造一个带有与条件的查询对象。 - -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Query

-

返回查询对象。

-
- -- 示例 - - ``` - try { - let query = new distributedData.Query(); - query.notEqualTo("field", "value1"); - query.and(); - query.notEqualTo("field", "value2"); - console.log("query is " + query.getSqlLike()); - query = null; - } catch (e) { - console.log("dumplicated calls should be ok :" + e); - } - ``` - - -### or8+ ### - -or(): Query; - -构造一个带有或条件的Query对象。 - -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Query

-

返回查询对象。

-
- -- 示例 - - ``` - try { - let query = new distributedData.Query(); - query.notEqualTo("field", "value1"); - query.or(); - query.notEqualTo("field", "value2"); - console.log("query is " + query.getSqlLike()); - query = null; - } catch (e) { - console.log("dumplicated calls should be ok :" + e); - } - ``` - - -### orderByAsc8+ ### - -orderByAsc(field: string): Query; - -构造一个Query对象,将查询结果按升序排序。 - -- 参数: - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

fieId

-

string

-

-

表示指定字段,必须以$开头, 并且不能包含' ^ '。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Query

-

返回查询对象。

-
- -- 示例 - - ``` - try { - let query = new distributedData.Query(); - query.notEqualTo("field", "value"); - query.orderByAsc("field"); - console.log("query is " + query.getSqlLike()); - query = null; - } catch (e) { - console.log("dumplicated calls should be ok :" + e); - } - ``` - - -### orderByDesc8+ ### - -orderByDesc(field: string): Query; - -构造一个Query对象,将查询结果按降序排序。 - -- 参数: - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

fieId

-

string

-

-

表示指定字段,必须以$开头, 并且不能包含' ^ '。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Query

-

返回查询对象。

-
- -- 示例 - - ``` - try { - let query = new distributedData.Query(); - query.notEqualTo("field", "value"); - query.orderByDesc("field"); - console.log("query is " + query.getSqlLike()); - query = null; - } catch (e) { - console.log("dumplicated calls should be ok :" + e); - } - ``` - - -### limit8+ ### - -limit(total: number, offset: number): Query; - -构造一个Query对象来指定结果的数量和开始位置。 - -- 参数: - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

total

-

number

-

-

表示指定的结果数。

-

offset

-

number

-

-

表示起始位置。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Query

-

返回查询对象。

-
- -- 示例 - - ``` - try { - let query = new distributedData.Query(); - query.notEqualTo("field", "value"); - query.limit("total", "offset"); - console.log("query is " + query.getSqlLike()); - query = null; - } catch (e) { - console.log("dumplicated calls should be ok :" + e); - } - ``` - - -### isNotNull8+ ### - -isNotNull(field: string): Query; - -使用不为空的指定字段创建查询条件。 - -- 参数: - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

fieId

-

string

-

-

表示指定字段。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Query

-

返回查询对象。

-
- -- 示例 - - ``` - try { - let query = new distributedData.Query(); - query.isNotNull("field"); - console.log("query is " + query.getSqlLike()); - query = null; - } catch (e) { - console.log("dumplicated calls should be ok :" + e); - } - ``` - - -### beginGroup8+ ### - -beginGroup(): Query; - -创建一个带有左括号的查询条件组。 - -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Query

-

返回查询对象。

-
- -- 示例 - - ``` - try { - let query = new distributedData.Query(); - query.beginGroup(); - query.isNotNull("field"); - query.endGroup(); - console.log("query is " + query.getSqlLike()); - query = null; - } catch (e) { - console.log("dumplicated calls should be ok :" + e); - } - ``` - - -### endGroup8+ ### - -endGroup(): Query; - -创建一个带有右括号的查询条件组。 - -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Query

-

返回查询对象。

-
- -- 示例 - - ``` - try { - let query = new distributedData.Query(); - query.beginGroup(); - query.isNotNull("field"); - query.endGroup(); - console.log("query is " + query.getSqlLike()); - query = null; - } catch (e) { - console.log("dumplicated calls should be ok :" + e); - } - ``` - - -### prefixKey8+ ### - -prefixKey(prefix: string): Query; - -创建具有指定键前缀的查询条件。 - -- 参数: - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

prefix

-

string

-

-

表示指定的键前缀。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Query

-

返回查询对象。

-
- -- 示例 - - ``` - try { - let query = new distributedData.Query(); - query.prefixKey("$.name"); - query.prefixKey("0"); - console.log("query is " + query.getSqlLike()); - query = null; - } catch (e) { - console.log("dumplicated calls should be ok :" + e); - } - ``` - - -### setSuggestIndex8+ ### - -setSuggestIndex(index: string): Query; - -设置一个指定的索引,将优先用于查询。 - -- 参数: - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

index

-

string

-

-

指示要设置的索引。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Query

-

返回查询对象。

-
- -- 示例 - - ``` - try { - let query = new distributedData.Query(); - query.setSuggestIndex("$.name"); - query.setSuggestIndex("0"); - console.log("query is " + query.getSqlLike()); - query = null; - } catch (e) { - console.log("dumplicated calls should be ok :" + e); - } - ``` - - -### deviceId8+ ### - -deviceId(deviceId:string):Query; - -添加设备ID作为key的前缀。 - -- 参数: - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

deviceId

-

string

-

-

指示查询的设备 ID。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Query

-

返回查询对象。

-
- -- 示例 - - ``` - try { - let query = new distributedData.Query(); - query.deviceId("deviceId"); - console.log("query is " + query.getSqlLike()); - } catch (e) { - console.log("should be ok on Method Chaining : " + e); - } - ``` - - -### getSqlLike8+ ### - -getSqlLike():string; - -获取指定Query对象的查询语句。 - -- 返回值: - - - - - - - - - - -

类型

-

说明

-

string

-

返回指定Query对象的查询语句。

-
- -- 示例 - - ``` - try { - let query = new distributedData.Query(); - let sql1 = query.getSqlLike(); - console.log("GetSqlLike sql=" + sql1); - } catch (e) { - console.log("dumplicated calls should be ok : " + e); - } - ``` - - -## KVStore - -KVStore数据库实例,提供增加数据、删除数据和订阅数据变更、订阅同步完成的方法。在调用KVStore的方法前,需要先通过getKVStore构建一个KVStore实例。 - -### put - -put(key: string, value: Uint8Array | string | number | boolean, callback: AsyncCallback<void>): void - -添加指定类型键值对到数据库,并通过callback方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

key

-

string

-

-

要添加数据的key,不能为空且长度不大于MAX_KEY_LENGTH

-

value

-

Uint8Array | string | number | boolean

-

-

要添加数据的value,支持Uint8Array、number 、 string 、boolean,

-

Uint8Array、string 的长度不大于MAX_VALUE_LENGTH

-

callback

-

AsyncCallback<void>

-

-

回调函数。

-
- -- 示例 - - ``` - let kvStore; - const KEY_TEST_STRING_ELEMENT = 'key_test_string'; - const VALUE_TEST_STRING_ELEMENT = 'value-test-string'; - try { - kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, function (err,data) { - if (err != undefined) { - console.log("put err: " + JSON.stringify(err)); - return; - } - console.log("put success"); - }); - }catch (e) { - console.log("An unexpected error occurred. Error:" + e); - } - ``` - - -### put - -put(key: string, value: Uint8Array | string | number | boolean): Promise<void> - -添加指定类型键值对到数据库,并通过Promise方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

key

-

string

-

-

要添加数据的key,不能为空且长度不大于MAX_KEY_LENGTH

-

value

-

Uint8Array | string | number | boolean

-

-

要添加数据的value,支持Uint8Array、number 、 string 、boolean,

-

Uint8Array、string 的长度不大于MAX_VALUE_LENGTH

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Promise<void>

-

Promise实例,用于异步处理。

-
- - -- 示例 - - ``` - let kvStore; - const KEY_TEST_STRING_ELEMENT = 'key_test_string'; - const VALUE_TEST_STRING_ELEMENT = 'value-test-string'; - try { - kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((data) => { - console.log("put success: " + JSON.stringify(data)); - }).catch((err) => { - console.log("put err: " + JSON.stringify(err)); - }); - }catch (e) { - console.log("An unexpected error occurred. Error:" + e); - } - ``` - - -### delete - -delete(key: string, callback: AsyncCallback<void>): void - -从数据库中删除指定键值的数据,并通过callback方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

key

-

string

-

-

要删除数据的key,不能为空且长度不大于MAX_KEY_LENGTH

-

callback

-

AsyncCallback<void>

-

-

回调函数。

-
- -- 示例 - - ``` - let kvStore; - const KEY_TEST_STRING_ELEMENT = 'key_test_string'; - const VALUE_TEST_STRING_ELEMENT = 'value-test-string'; - try { - kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, function (err,data) { - if (err != undefined) { - console.log("put err: " + JSON.stringify(err)); - return; - } - console.log("put success"); - kvStore.delete(KEY_TEST_STRING_ELEMENT, function (err,data) { - if (err != undefined) { - console.log("delete err: " + JSON.stringify(err)); - return; - } - console.log("delete success"); - }); - }); - }catch (e) { - console.log("An unexpected error occurred. Error:" + e); - } - ``` - - -### delete - -delete(key: string): Promise<void> - -从数据库中删除指定键值的数据,并通过Promise方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

key

-

string

-

-

要删除数据的key,不能为空且长度不大于MAX_KEY_LENGTH

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Promise<void>

-

Promise实例,用于异步处理。

-
- -- 示例 - - ``` - let kvStore; - const KEY_TEST_STRING_ELEMENT = 'key_test_string'; - const VALUE_TEST_STRING_ELEMENT = 'value-test-string'; - try { - kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((data) => { - console.log("put success: " + JSON.stringify(data)); - kvStore.delete(KEY_TEST_STRING_ELEMENT).then((data) => { - console.log("delete success"); - }).catch((err) => { - console.log("delete err: " + JSON.stringify(err)); - }); - }).catch((err) => { - console.log("put err: " + JSON.stringify(err)); - }); - }catch (e) { - console.log("An unexpected error occurred. Error:" + e); - } - ``` - - -### on - -on(event: 'dataChange', type: SubscribeType, observer: Callback<ChangeNotification>): void - -订阅指定类型的数据变更通知,此方法为同步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

event

-

'dataChange'

-

-

回调函数名称。

-

type

-

SubscribeType

-

-

表示订阅的类型。

-

observer

-

Callback<ChangeNotification>

-

-

回调函数。

-
- -- 示例 - - ``` - let kvStore; - kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_LOCAL, function (data) { - console.log("dataChange callback call data: " + JSON.stringify(data)); - }); - ``` - - -### on - -on(event: 'syncComplete', syncCallback: Callback - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

event

-

'syncComplete'

-

-

回调函数名称。

-

syncCallback

-

Callback<Array<[string, number]>

-

-

回调函数。

-
- -- 示例 - - ``` - let kvStore; - kvStore.on('syncComplete', function (data) { - console.log("syncComplete callback call data: " + data); - }); - ``` - -### off8+ ### - -off(event:'dataChange', observer?: Callback<ChangeNotification>): void; - -取消订阅数据变更通知,此方法为同步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

event

-

'datachange'

-

-

回调函数名称。

-

observer

-

Callback<ChangeNotification>

-

-

回调函数。

-
- -- 示例 - - ``` - let kvStore; - kvStore.on('dataChange', function (data) { - console.log("syncComplete callback call data: " + data); - }); - kvStore.off('dataChange', function (data) { - console.log("syncComplete callback call data: " + data); - }); - ``` - - -### putBatch8+ ### - -putBatch(entries: Entry[], callback: AsyncCallback<void>): void; - -批量插入键值对到KvStore数据库中,并通过callback方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

entries

-

Entry[]

-

-

表示要批量插入的键值对。

-

callback

-

Asyncallback<void>

-

-

回调函数。

-
- -- 示例 - - ``` - let kvStore; - try { - let entries = []; - for (var i = 0; i < 10; i++) { - var key = 'batch_test_string_key'; - var entry = { - key : key + i, - value : { - type : distributedData.ValueType.STRING, - value : 'batch_test_string_value' - } - } - entries.push(entry); - } - console.log('entries: ' + JSON.stringify(entries)); - kvStore.putBatch(entries, async function (err,data) { - console.log('putBatch success'); - await kvStore.getEntries('batch_test_string_key', function (err,entrys) { - console.log('getEntries success'); - console.log('entrys.length: ' + entrys.length); - console.log('entrys[0]: ' + JSON.stringify(entrys[0])); - }); - }); - }catch(e) { - console.log('PutBatch e ' + e); - } - - ``` - - -### putBatch8+ ### - -putBatch(entries: Entry[]): Promise<void>; - -批量插入键值对到KvStore数据库中,并通过Promise方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

entries

-

Entry[]

-

-

表示要批量插入的键值对。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Promise<void>

-

Promise实例,用于异步处理。

-
- -- 示例 - - ``` - let kvStore; - try { - let entries = []; - for (var i = 0; i < 10; i++) { - var key = 'batch_test_string_key'; - var entry = { - key : key + i, - value : { - type : distributedData.ValueType.STRING, - value : 'batch_test_string_value' - } - } - entries.push(entry); - } - console.log('entries: ' + JSON.stringify(entries)); - kvStore.putBatch(entries).then(async (err) => { - console.log('putBatch success'); - await kvStore.getEntries('batch_test_string_key').then((entrys) => { - console.log('getEntries success'); - console.log('PutBatch ' + JSON.stringify(entries)); - }).catch((err) => { - console.log('getEntries fail ' + JSON.stringify(err)); - }); - }).catch((err) => { - console.log('putBatch fail ' + JSON.stringify(err)); - }); - }catch(e) { - console.log('PutBatch e ' + e); - } - ``` - - -### deleteBatch8+ ### - -deleteBatch(keys: string[], callback: AsyncCallback<void>): void; - -批量删除KvStore数据库中的键值对,并通过callback方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

keys

-

string[]

-

-

表示要批量删除的键值对。

-

callback

-

Asyncallback<void>

-

-

回调函数。

-
- -- 示例 - - ``` - let kvStore; - try { - let entries = []; - let keys = []; - for (var i = 0; i < 5; i++) { - var key = 'batch_test_string_key'; - var entry = { - key : key + i, - value : { - type : distributedData.ValueType.STRING, - value : 'batch_test_string_value' - } - } - entries.push(entry); - keys.push(key + i); - } - console.log('entries: ' + JSON.stringify(entries)); - kvStore.putBatch(entries, async function (err,data) { - console.log('putBatch success'); - await kvStore.deleteBatch(keys, async function (err,data) { - console.log('deleteBatch success'); - }); - }); - }catch(e) { - console.log('DeleteBatch e ' + e); - } - ``` - - -### deleteBatch8+ ### - -deleteBatch(keys: string[]): Promise<void>; - -批量删除键值对到KvStore数据库中,并通过Promise方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

keys

-

string[]

-

-

表示要批量删除的键值对。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Promise<void>

-

Promise实例,用于异步处理。

-
- -- 示例 - - ``` - let kvStore; - try { - let entries = []; - let keys = []; - for (var i = 0; i < 5; i++) { - var key = 'batch_test_string_key'; - var entry = { - key : key + i, - value : { - type : distributedData.ValueType.STRING, - value : 'batch_test_string_value' - } - } - entries.push(entry); - keys.push(key + i); - } - console.log('entries: ' + JSON.stringify(entries)); - kvStore.putBatch(entries).then(async (err) => { - console.log('putBatch success'); - await kvStore.deleteBatch(keys).then((err) => { - console.log('deleteBatch success'); - }).catch((err) => { - console.log('deleteBatch fail ' + JSON.stringify(err)); - }); - }).catch((err) => { - console.log('putBatch fail ' + JSON.stringify(err)); - }); - }catch(e) { - console.log('DeleteBatch e ' + e); - } - ``` - - -### startTransaction8+ ### - -startTransaction(callback: AsyncCallback<void>): void; - -启动KvStore数据库中的事务,并通过callback方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

callback

-

AsyncCallback<void>

-

-

回调函数。

-
- -- 示例 - - ``` - let kvStore; - function putBatchString(len, prefix) { - let entries = []; - for (var i = 0; i < len; i++) { - var entry = { - key : prefix + i, - value : { - type : distributedData.ValueType.STRING, - value : 'batch_test_string_value' - } - } - entries.push(entry); - } - return entries; - } - try { - var count = 0; - kvStore.on('dataChange', 0, function (data) { - console.log('startTransaction 0' + data) - count++; - }); - kvStore.startTransaction(async function (err,data) { - console.log('startTransaction success'); - let entries = putBatchString(10, 'batch_test_string_key'); - console.log('entries: ' + JSON.stringify(entries)); - await kvStore.putBatch(entries, async function (err,data) { - console.log('putBatch success'); - }); - }); - }catch(e) { - console.log('startTransaction e ' + e); - } - ``` - - -### startTransaction8+ ### - -startTransaction(): Promise<void>; - -启动KvStore数据库中的事务,并通过Promise方式返回,此方法为异步方法。 - -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Promise<void>

-

Promise实例,用于异步处理。

-
- -- 示例 - - ``` - let kvStore; - try { - var count = 0; - kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_ALL, function (data) { - console.log('startTransaction ' + JSON.stringify(data)); - count++; - }); - kvStore.startTransaction().then(async (err) => { - console.log('startTransaction success'); - }).catch((err) => { - console.log('startTransaction fail ' + JSON.stringify(err)); - }); - }catch(e) { - console.log('startTransaction e ' + e); - } - ``` - - -### commit8+ ### - -commit(callback: AsyncCallback<void>): void; - -提交KvStore数据库中的事务,并通过callback方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

callback

-

AsyncCallback<void>

-

-

回调函数。

-
- -- 示例 - - ``` - let kvStore; - try { - kvStore.commit(function (err,data) { - if (err == undefined) { - console.log('commit success'); - } else { - console.log('commit fail'); - } - }); - }catch(e) { - console.log('Commit e ' + e); - } - ``` - - -### commit8+ ### - -commit(): Promise<void>; - -提交KvStore数据库中的事务,并通过Promise方式返回,此方法为异步方法。 - -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Promise<void>

-

Promise实例,用于异步处理。

-
- -- 示例 - - ``` - let kvStore; - try { - kvStore.commit().then(async (err) => { - console.log('commit success'); - }).catch((err) => { - console.log('commit fail ' + JSON.stringify(err)); - }); - }catch(e) { - console.log('Commit e ' + e); - } - ``` - - -### rollback8+ ### - -rollback(callback: AsyncCallback<void>): void; - -在KvStore数据库中回滚事务,并通过callback方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

callback

-

AsyncCallback<void>

-

-

回调函数。

-
- -- 示例 - - ``` - let kvStore; - try { - kvStore.rollback(function (err,data) { - if (err == undefined) { - console.log('commit success'); - } else { - console.log('commit fail'); - } - }); - }catch(e) { - console.log('Rollback e ' + e); - } - ``` - - -### rollback8+ ### - -rollback(): Promise<void>; - -在KvStore数据库中回滚事务,并通过Promise方式返回,此方法为异步方法。 - -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Promise<void>

-

Promise实例,用于异步处理。

-
- -- 示例 - - ``` - let kvStore; - try { - kvStore.rollback().then(async (err) => { - console.log('rollback success'); - }).catch((err) => { - console.log('rollback fail ' + JSON.stringify(err)); - }); - }catch(e) { - console.log('Rollback e ' + e); - } - ``` - - -### enableSync8+ ### - -enableSync(enabled: boolean, callback: AsyncCallback<void>): void; - -设定是否开启同步,并通过callback方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

enabled

-

boolean

-

-

指定是否开启同步,ture表示开启同步,false表示不启用同步。

-

callback

-

AsyncCallback<void>

-

-

回调函数。

-
- -- 示例 - - ``` - let kvStore; - try { - kvStore.enableSync(true, function (err,data) { - if (err == undefined) { - console.log('enableSync success'); - } else { - console.log('enableSync fail'); - } - }); - }catch(e) { - console.log('EnableSync e ' + e); - } - ``` - - -### enableSync8+ ### - -enableSync(enabled: boolean): Promise<void>; - -设定是否开启同步,并通过Promise方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

enabled

-

boolean

-

-

指定是否开启同步,ture表示开启同步,false表示不启用同步。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Promise<void>

-

Promise实例,用于异步处理。

-
- -- 示例 - - ``` - let kvStore; - try { - kvStore.enableSync(true).then((err) => { - console.log('enableSync success'); - }).catch((err) => { - console.log('enableSync fail ' + JSON.stringify(err)); - }); - }catch(e) { - console.log('EnableSync e ' + e); - } - ``` - - -### setSyncRange8+ ### - -setSyncRange(localLabels: string[], remoteSupportLabels: string[], callback: AsyncCallback<void>): void; - -设置同步范围标签,并通过callback方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

localLabels

-

string[]

-

-

表示本地设备的同步标签。

-

remoteSupportLabels

-

string[]

-

-

表示要同步数据的设备的同步标签。

-

callback

-

AsyncCallback<void>

-

-

回调函数。

-
- -- 示例 - - ``` - let kvStore; - try { - const localLabels = ['A', 'B']; - const remoteSupportLabels = ['C', 'D']; - kvStore.setSyncRange(localLabels, remoteSupportLabels, function (err,data) { - console.log('SetSyncRange put success'); - }); - }catch(e) { - console.log('SetSyncRange e ' + e); - } - ``` - - -### setSyncRange8+ ### - -setSyncRange(localLabels: string[], remoteSupportLabels: string[]): Promise<void>; - -设置同步范围标签,并通过Promise方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

localLabels

-

string[]

-

-

表示本地设备的同步标签。

-

remoteSupportLabels

-

string[]

-

-

表示要同步数据的设备的同步标签。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Promise<void>

-

Promise实例,用于异步处理。

-
- -- 示例 - - ``` - let kvStore; - try { - const localLabels = ['A', 'B']; - const remoteSupportLabels = ['C', 'D']; - kvStore.setSyncRange(localLabels, remoteSupportLabels).then((err) => { - console.log('setSyncRange success'); - }).catch((err) => { - console.log('delete fail ' + err); - }); - }catch(e) { - console.log('SetSyncRange e ' + e); - } - ``` - - -## SubscribeType - -描述订阅类型。 - - - - - - - - - - - - - - - - - - - - -

名称

-

默认值

-

说明

-

SUBSCRIBE_TYPE_LOCAL

-

0

-

表示订阅本地数据变更。

-

SUBSCRIBE_TYPE_REMOTE

-

1

-

表示订阅远端数据变更。

-

SUBSCRIBE_TYPE_ALL

-

2

-

表示订阅远端和本地数据变更。

-
- -## ChangeNotification - -数据变更时通知的对象,包括数据插入的数据、更新的数据、删除的数据和设备ID。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数类型

-

可读

-

可写

-

说明

-

insertEntries

-

Entry[]

-

-

-

数据添加记录。

-

updateEntries

-

Entry[]

-

-

-

数据更新记录。

-

deleteEntries

-

Entry[]

-

-

-

数据删除记录。

-

deviceId

-

string

-

-

-

设备ID,此处为设备UUID。

-
- -## Entry - -存储在数据库中的键值对。 - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数类型

-

可读

-

可写

-

说明

-

key

-

string

-

-

-

键值。

-

value

-

Value

-

-

-

值对象。

-
- -## Value - -存储在数据库中的对象。 - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数类型

-

可读

-

可写

-

说明

-

type

-

ValueType

-

-

-

值类型。

-

value

-

Uint8Array | string | number | boolean

-

-

-

值,Uint8Array、string 的长度不大于MAX_VALUE_LENGTH

-
- -## ValueType - -用于表示数据类型。 - -只能被内部应用使用。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

默认值

-

说明

-

STRING

-

0

-

表示值类型为字符串。

-

INTEGER

-

1

-

表示值类型为整数。

-

FLOAT

-

2

-

表示值类型为浮点数。

-

BYTE_ARRAY

-

3

-

表示值类型为字节数组。

-

BOOLEAN

-

4

-

表示值类型为布尔值。

-

DOUBLE

-

5

-

表示值类型为双浮点数。

-
- -## SingleKVStore - -单版本分布式数据库,继承自KVStore,提供查询数据和同步数据的方法。在调用 SingleKVStore 的方法前,需要先通过 getKVStore 构建一个 SingleKVStore 实例。 - -### get - -get(key: string, callback: AsyncCallback<Uint8Array | string | boolean | number>): void - -获取指定键的值,并通过callback方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

key

-

string

-

-

要查询数据的key,不能为空且长度不大于MAX_KEY_LENGTH

-

callback

-

AsyncCallback<Uint8Array | string | boolean | number>

-

-

回调函数,获取查询的值。

-
- -- 示例 - - ``` - let kvStore; - const KEY_TEST_STRING_ELEMENT = 'key_test_string'; - const VALUE_TEST_STRING_ELEMENT = 'value-test-string'; - try { - kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, function (err,data) { - if (err != undefined) { - console.log("put err: " + JSON.stringify(err)); - return; - } - console.log("put success"); - kvStore.get(KEY_TEST_STRING_ELEMENT, function (err,data) { - console.log("get success data: " + data); - }); - }); - }catch (e) { - console.log("An unexpected error occurred. Error:" + e); - } - ``` - - -### get - -get(key: string): Promise<Uint8Array | string | boolean | number> - -获取指定键的值,并通过Promise方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

key

-

string

-

-

要查询数据的key,不能为空且长度不大于MAX_KEY_LENGTH

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Promise<Uint8Array | string | boolean | number>

-

Promise实例,用于获取异步返回结果。

-
- - -- 示例 - - ``` - let kvStore; - const KEY_TEST_STRING_ELEMENT = 'key_test_string'; - const VALUE_TEST_STRING_ELEMENT = 'value-test-string'; - try { - kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((data) => { - console.log("put success: " + JSON.stringify(data)); - kvStore.get(KEY_TEST_STRING_ELEMENT).then((data) => { - console.log("get success data: " + data); - }).catch((err) => { - console.log("get err: " + JSON.stringify(err)); - }); - }).catch((err) => { - console.log("put err: " + JSON.stringify(err)); - }); - }catch (e) { - console.log("An unexpected error occurred. Error:" + e); - } - ``` - -### getEntries8+ ### - -getEntries(keyPrefix: string, callback: AsyncCallback<Entry[]>): void; - -获取匹配指定键前缀的所有键值对,并通过callback方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

keyPrefix

-

string

-

-

表示要匹配的键前缀。

-

callback

-

AsyncCallback<Entry[]>

-

-

回调函数,获取指定前缀的键值对列表。

-
- -- 示例 - - ``` - let kvStore; - try { - let entries = []; - for (var i = 0; i < 10; i++) { - var key = 'batch_test_number_key'; - var entry = { - key : key + i, - value : { - type : distributedData.ValueType.INTEGER, - value : 222 - } - } - entries.push(entry); - } - kvStore.putBatch(entries, async function (err,data) { - console.log('putBatch success'); - await kvStore.getEntries('batch_test_number_key', function (err,entrys) { - console.log('getEntries success'); - console.log('entrys.length: ' + entrys.length); - console.log('entrys[0]: ' + JSON.stringify(entrys[0])); - }); - }); - }catch(e) { - console.log('PutBatch e ' + e); - } - ``` - - -### getEntries8+ ### - -getEntries(keyPrefix: string): Promise<Entry[]>; - -获取匹配指定键前缀的所有键值对,并通过Promise方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

keyPrefix

-

string

-

-

表示要匹配的键前缀。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Promise<Entry[]>

-

Promise实例,用于获取异步返回结果。

-
- -- 示例 - - ``` - let kvStore; - try { - let entries = []; - for (var i = 0; i < 10; i++) { - var key = 'batch_test_string_key'; - var entry = { - key : key + i, - value : { - type : distributedData.ValueType.STRING, - value : 'batch_test_string_value' - } - } - entries.push(entry); - } - console.log('entries: ' + entries); - kvStore.putBatch(entries).then(async (err) => { - console.log('putBatch success'); - await kvStore.getEntries('batch_test_string_key').then((entrys) => { - console.log('getEntries success'); - console.log('entrys.length: ' + entrys.length); - console.log('entrys[0]: ' + JSON.stringify(entrys[0])); - console.log('entrys[0].value: ' + JSON.stringify(entrys[0].value)); - console.log('entrys[0].value.value: ' + entrys[0].value.value); - }).catch((err) => { - console.log('getEntries fail ' + JSON.stringify(err)); - }); - }).catch((err) => { - console.log('putBatch fail ' + JSON.stringify(err)); - }); - }catch(e) { - console.log('PutBatch e ' + e); - } - ``` - - -### getEntries8+ ### - -getEntries(query: Query, callback: AsyncCallback<Entry[]>): void; - -获取与指定 Query 对象匹配的键值对列表,并通过callback方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

query

-

Query

-

-

表示查询对象。

-

callback

-

AsyncCallback<Entry[]>

-

-

回调函数,获取指定前缀的键值对列表。

-
- -- 示例 - - ``` - let kvStore; - try { - var arr = new Uint8Array([21,31]); - let entries = []; - for (var i = 0; i < 10; i++) { - var key = 'batch_test_bool_key'; - var entry = { - key : key + i, - value : { - type : distributedData.ValueType.BYTE_ARRAY, - value : arr - } - } - entries.push(entry); - } - console.log('entries: ' + JSON.stringify(entries)); - kvStore.putBatch(entries, async function (err,data) { - console.log('putBatch success'); - const query = new distributedData.Query(); - query.prefixKey("batch_test"); - await kvStore.getEntries(query, function (err,entrys) { - console.log('getEntries success'); - console.log('entrys.length: ' + entrys.length); - console.log('entrys[0]: ' + JSON.stringify(entrys[0])); - }); - }); - console.log('GetEntries success'); - }catch(e) { - console.log('GetEntries e ' + e); - } - ``` - - -### getEntries8+ ### - -getEntries(query: Query): Promise<Entry[]>; - -获取匹配指定键前缀的所有键值对,并通过Promise方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

query

-

Query

-

-

表示查询对象。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Promise<Entry[]>

-

Promise实例,用于获取异步返回结果。

-
- -- 示例 - - ``` - try { - var arr = new Uint8Array([21,31]); - let entries = []; - for (var i = 0; i < 10; i++) { - var key = 'batch_test_bool_key'; - var entry = { - key : key + i, - value : { - type : distributedData.ValueType.BYTE_ARRAY, - value : arr - } - } - entries.push(entry); - } - console.log('entries: ' + JSON.stringify(entries)); - kvStore.putBatch(entries).then(async (err) => { - console.log('putBatch success'); - const query = new distributedData.Query(); - query.prefixKey("batch_test"); - await kvStore.getEntries(query).then((entrys) => { - console.log('getEntries success'); - }).catch((err) => { - console.log('getEntries fail ' + JSON.stringify(err)); - }); - }).catch((err) => { - console.log('GetEntries putBatch fail ' + JSON.stringify(err)) - }); - console.log('GetEntries success'); - }catch(e) { - console.log('GetEntries e ' + e); - } - ``` - - -### getResultSet8+ ### - -getResultSet(keyPrefix: string, callback: AsyncCallback<KvStoreResultSet>): void; - -从 KvStore 数据库中获取具有指定前缀的结果集,并通过callback方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

keyPrefix

-

string

-

-

表示要匹配的键前缀。

-

callback

-

AsyncCallback<KvStoreResultSet>

-

-

回调函数,获取具有指定前缀的结果集。

-
- -- 示例 - - ``` - let kvStore; - try { - let resultSet; - let entries = []; - for (var i = 0; i < 10; i++) { - var key = 'batch_test_string_key'; - var entry = { - key : key + i, - value : { - type : distributedData.ValueType.STRING, - value : 'batch_test_string_value' - } - } - entries.push(entry); - } - kvStore.putBatch(entries, async function (err, data) { - console.log('GetResultSet putBatch success'); - await kvStore.getResultSet('batch_test_string_key', async function (err, result) { - console.log('GetResultSet getResultSet success'); - resultSet = result; - kvStore.closeResultSet(resultSet, function (err, data) { - console.log('GetResultSet closeResultSet success'); - }) - }); - }); - }catch(e) { - console.log('GetResultSet e ' + e); - } - ``` - - -### getResultSet8+ ### - -getResultSet(keyPrefix: string): Promise<KvStoreResultSet>; - -从 KvStore 数据库中获取具有指定前缀的结果集,并通过Promise方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

keyPrefix

-

string

-

-

表示要匹配的键前缀。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Promise<KvStoreResultSet>

-

Promise实例,用于获取异步返回结果。

-
- -- 示例 - - ``` - let kvStore; - try { - let resultSet; - let entries = []; - for (var i = 0; i < 10; i++) { - var key = 'batch_test_string_key'; - var entry = { - key : key + i, - value : { - type : distributedData.ValueType.STRING, - value : 'batch_test_string_value' - } - } - entries.push(entry); - } - kvStore.putBatch(entries).then(async (err) => { - console.log('putBatch success'); - }).catch((err) => { - console.log('PutBatch putBatch fail ' + JSON.stringify(err)); - }); - kvStore.getResultSet('batch_test_string_key').then((result) => { - console.log('GetResult getResultSet success'); - resultSet = result; - }).catch((err) => { - console.log('getResultSet fail ' + JSON.stringify(err)); - }); - kvStore.closeResultSet(resultSet).then((err) => { - console.log('GetResult closeResultSet success'); - }).catch((err) => { - console.log('closeResultSet fail ' + JSON.stringify(err)); - }); - }catch(e) { - console.log('GetResult e ' + e); - } - ``` - - -### getResultSet8+ ### - -getResultSet(query: Query, callback: AsyncCallback<KvStoreResultSet>): void; - -获取与指定 Query 对象匹配的 KvStoreResultSet 对象,并通过callback方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

query

-

Query

-

-

表示查询对象。

-

callback

-

AsyncCallback<KvStoreResultSet>

-

-

回调函数,获取与指定 Query 对象匹配的 KvStoreResultSet 对象。

-
- -- 示例 - - ``` - let kvStore; - try { - let resultSet; - let entries = []; - for (var i = 0; i < 10; i++) { - var key = 'batch_test_string_key'; - var entry = { - key : key + i, - value : { - type : distributedData.ValueType.STRING, - value : 'batch_test_string_value' - } - } - entries.push(entry); - } - kvStore.putBatch(entries, async function (err, data) { - console.log('putBatch success'); - const query = new distributedData.Query(); - query.prefixKey("batch_test"); - await kvStore.getResultSet(query, async function (err, result) { - console.log('getResultSet success'); - resultSet = result; - }); - }); - } catch(e) { - console.log('GetResultSet e ' + e); - } - ``` - - -### getResultSet8+ ### - -getResultSet(query: Query): Promise<KvStoreResultSet>; - -获取与指定 Query 对象匹配的 KvStoreResultSet 对象,并通过Promise方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

query

-

Query

-

-

表示查询对象。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Promise<KvStoreResultSet>

-

Promise实例,用于获取异步返回结果。

-
- -- 示例 - - ``` - let kvStore; - try { - let resultSet; - let entries = []; - for (var i = 0; i < 10; i++) { - var key = 'batch_test_string_key'; - var entry = { - key : key + i, - value : { - type : distributedData.ValueType.STRING, - value : 'batch_test_string_value' - } - } - entries.push(entry); - } - kvStore.putBatch(entries).then(async (err) => { - console.log('putBatch success'); - }).catch((err) => { - console.log('putBatch fail ' + JSON.stringify(err)); - }); - const query = new distributedData.Query(); - query.prefixKey("batch_test"); - kvStore.getResultSet(query).then((result) => { - console.log(' getResultSet success'); - resultSet = result; - }).catch((err) => { - console.log('getResultSet fail ' + JSON.stringify(err)); - }); - }catch(e) { - console.log('GetResultSet e ' + e); - } - ``` - -### closeResultSet8+ ### - -closeResultSet(resultSet: KvStoreResultSet, callback: AsyncCallback<void>): void; - -关闭由 getResultSet 返回的 KvStoreResultSet 对象,并通过callback方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

resultSet

-

KvStoreResultSet

-

-

表示要关闭的 KvStoreResultSet 对象。

-

callback

-

AsyncCallback<void>

-

-

回调函数,获取由 getResultSet 返回的 KvStoreResultSet 对象。

-
- -- 示例 - - ``` - let kvStore; - try { - let resultSet = null; - kvStore.closeResultSet(resultSet, function (err, data) { - if (err == undefined) { - console.log('closeResultSet success'); - } else { - console.log('closeResultSet fail'); - } - }); - }catch(e) { - console.log('CloseResultSet e ' + e); - } - ``` - - -### closeResultSet8+ ### - -closeResultSet(resultSet: KvStoreResultSet): Promise<void>; - -关闭由 getResultSet 返回的 KvStoreResultSet 对象,并通过Promise方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

resultSet

-

KvStoreResultSet

-

-

表示要关闭的 KvStoreResultSet 对象。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Promise<void>

-

Promise实例,用于获取异步返回结果。

-
- -- 示例 - - ``` - let kvStore; - try { - let resultSet = null; - kvStore.closeResultSet(resultSet).then(() => { - console.log('closeResultSet success'); - }).catch((err) => { - console.log('closeResultSet fail ' + JSON.stringify(err)); - }); - }catch(e) { - console.log('CloseResultSet e ' + e); - } - ``` - - -### getResultSize8+ ### - -getResultSize(query: Query, callback: AsyncCallback<number>): void; - -获取与指定 Query 对象匹配的结果数,并通过callback方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

query

-

Query

-

-

表示查询对象。

-

callback

-

AsyncCallback<number>

-

-

回调函数,获取与指定 Query 对象匹配的结果数。

-
- -- 示例 - - ``` - let kvStore; - try { - let entries = []; - for (var i = 0; i < 10; i++) { - var key = 'batch_test_string_key'; - var entry = { - key : key + i, - value : { - type : distributedData.ValueType.STRING, - value : 'batch_test_string_value' - } - } - entries.push(entry); - } - kvStore.putBatch(entries, async function (err, data) { - console.log('putBatch success'); - const query = new distributedData.Query(); - query.prefixKey("batch_test"); - await kvStore.getResultSize(query, async function (err, resultSize) { - console.log('getResultSet success'); - }); - }); - } catch(e) { - console.log('GetResultSize e ' + e); - } - ``` - - -### getResultSize8+ ### - -getResultSize(query: Query): Promise<number>; - -获取与指定 Query 对象匹配的结果数,并通过Promise方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

query

-

Query

-

-

表示查询对象。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Promise<number>

-

Promise实例,用于获取异步返回结果。

-
- -- 示例 - - ``` - let kvStore; - try { - let entries = []; - for (var i = 0; i < 10; i++) { - var key = 'batch_test_string_key'; - var entry = { - key : key + i, - value : { - type : distributedData.ValueType.STRING, - value : 'batch_test_string_value' - } - } - entries.push(entry); - } - kvStore.putBatch(entries).then(async (err) => { - console.log('putBatch success'); - }).catch((err) => { - console.log('putBatch fail ' + JSON.stringify(err)); - }); - const query = new distributedData.Query(); - query.prefixKey("batch_test"); - kvStore.getResultSize(query).then((resultSize) => { - console.log('getResultSet success'); - }).catch((err) => { - console.log('getResultSet fail ' + JSON.stringify(err)); - }); - }catch(e) { - console.log('GetResultSize e ' + e); - } - ``` - - -### removeDeviceData8+ ### - -removeDeviceData(deviceId: string, callback: AsyncCallback<void>): void; - -删除指定设备的数据,并通过callback方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

deviceId

-

string

-

-

表示要删除设备的名称。

-

callback

-

AsyncCallback<void>

-

-

回调函数。

-
- -- 示例 - - ``` - let kvStore; - const KEY_TEST_STRING_ELEMENT = 'key_test_string_2'; - const VALUE_TEST_STRING_ELEMENT = 'value-string-002'; - try { - kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, async function (err,data) { - console.log('put success'); - const deviceid = 'no_exist_device_id'; - await kvStore.removeDeviceData(deviceid, async function (err,data) { - if (err == undefined) { - console.log('removeDeviceData success'); - } else { - console.log('removeDeviceData fail'); - await kvStore.get(KEY_TEST_STRING_ELEMENT, async function (err,data) { - console.log('RemoveDeviceData get success'); - }); - } - }); - }); - }catch(e) { - console.log('RemoveDeviceData e ' + e); - } - ``` - - -### removeDeviceData8+ ### - -removeDeviceData(deviceId: string): Promise<void>; - -删除指定设备的数据,并通过Promise方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

deviceId

-

string

-

-

表示要删除设备的名称。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Promise<void>

-

Promise实例,用于获取异步返回结果。

-
- -- 示例 - - ``` - let kvStore; - const KEY_TEST_STRING_ELEMENT = 'key_test_string_2'; - const VALUE_TEST_STRING_ELEMENT = 'value-string-001'; - try { - kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((err) => { - console.log('removeDeviceData put success'); - }).catch((err) => { - console.log('put fail ' + JSON.stringify(err)); - }); - const deviceid = 'no_exist_device_id'; - kvStore.removeDeviceData(deviceid).then((err) => { - console.log('removeDeviceData success'); - }).catch((err) => { - console.log('removeDeviceData fail ' + JSON.stringify(err)); - }); - kvStore.get(KEY_TEST_STRING_ELEMENT).then((data) => { - console.log('get success data:' + data); - }).catch((err) => { - console.log('RemoveDeviceData get fail ' + JSON.stringify(err)); - }); - }catch(e) { - console.log('RemoveDeviceData e ' + e); - } - ``` - - -### on8+ ### - -on(event: 'syncComplete', syncCallback: Callback - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

event

-

'syncComplete'

-

-

同步完成时触发的事件名。

-

syncCallback

-

Callback<Array<[string, number]>

-

-

用于向调用方发送同步结果的回调。

-
- -- 示例 - - ``` - let kvStore; - const KEY_TEST_FLOAT_ELEMENT = 'key_test_float'; - const VALUE_TEST_FLOAT_ELEMENT = 321.12; - try { - kvStore.on('syncComplete', function (data) { - console.log('syncComplete ' + data) - }); - kvStore.put(KEY_TEST_FLOAT_ELEMENT, VALUE_TEST_FLOAT_ELEMENT).then((data) => { - console.log('syncComplete put success'); - }).catch((error) => { - console.log('syncComplete put fail ' + error); - }); - }catch(e) { - console.log('syncComplete put e ' + e); - } - ``` - - -### off8+ ### - -off(event: 'syncComplete', syncCallback?: Callback - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

event

-

'syncComplete'

-

-

同步完成时触发的事件名。

-

syncCallback

-

Callback<Array<[string, number]>

-

-

用于向调用方发送同步结果的回调。

-
- -- 示例 - - ``` - let kvStore; - try { - const func = function (data) { - console.log('syncComplete ' + data) - }; - kvStore.on('syncComplete', func); - kvStore.off('syncComplete', func); - }catch(e) { - console.log('syncComplete e ' + e); - } - ``` - - -### sync - -sync(deviceIdList: string[], mode: SyncMode, allowedDelayMs?: number): void - -在手动模式下,触发数据库同步,此方法为同步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

deviceIdList

-

string[]

-

-

同一组网环境下,需要同步的设备的deviceId列表。

-

mode

-

SyncMode

-

-

同步类型。

-

allowedDelayMs

-

number

-

-

可选参数,允许延时时间,单位:ms(毫秒)。

-
- -- 示例: - - ``` - let kvStore; - kvStore.sync('deviceIds', distributedData.SyncMode.PULL_ONLY, 1000); - ``` - -### setSyncParam8+ ### - -setSyncParam(defaultAllowedDelayMs: number, callback: AsyncCallback<void>): void; - -设置允许数据库同步的默认延迟,并通过callback方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

defaultAllowedDelayMs

-

number

-

-

表示数据库同步允许的默认延迟,以毫秒为单位。

-

callback

-

AsyncCallback<void>

-

-

回调函数。

-
- -- 示例 - - ``` - let kvStore; - try { - const defaultAllowedDelayMs = 500; - kvStore.setSyncParam(defaultAllowedDelayMs, function (err,data) { - console.log('SetSyncParam put success'); - }); - }catch(e) { - console.log('testSingleKvStoreSetSyncParam e ' + e); - } - ``` - - -### setSyncParam8+ ### - -setSyncParam(defaultAllowedDelayMs: number): Promise<void>; - -设置允许数据库同步的默认延迟,并通过Promise方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

defaultAllowedDelayMs

-

number

-

-

表示数据库同步允许的默认延迟,以毫秒为单位。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Promise<void>

-

Promise实例,用于获取异步返回结果。

-
- -- 示例 - - ``` - let kvStore; - try { - const defaultAllowedDelayMs = 500; - kvStore.setSyncParam(defaultAllowedDelayMs).then((err) => { - console.log('SetSyncParam put success'); - }).catch((err) => { - console.log('SetSyncParam put fail ' + JSON.stringify(err)); - }); - }catch(e) { - console.log('SetSyncParam e ' + e); - } - ``` - - -### getSecurityLevel8+ ### - -getSecurityLevel(callback: AsyncCallback<SecurityLevel>): void; - -获取数据库的安全级别,并通过callback方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

callback

-

AsyncCallback<SecurityLevel>

-

-

回调函数。

-
- -- 示例 - - ``` - let kvStore; - try { - kvStore.getSecurityLevel(function (err,data) { - console.log('getSecurityLevel success'); - }); - }catch(e) { - console.log('GetSecurityLeve e ' + e); - } - ``` - - -### getSecurityLevel8+ ### - -getSecurityLevel(): Promise<SecurityLevel>; - -获取数据库的安全级别,并通过Promise方式返回,此方法为异步方法。 - -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Promise<SecurityLevel>

-

Promise实例,用于获取异步返回结果。

-
- -- 示例 - - ``` - let kvStore; - try { - kvStore.getSecurityLevel().then((data) => { - console.log(' getSecurityLevel success'); - }).catch((err) => { - console.log('getSecurityLevel fail ' + JSON.stringify(err)); - }); - }catch(e) { - console.log('GetSecurityLeve e ' + e); - } - ``` - - -## DeviceKVStore8+ ## - -在分布式系统中按设备管理分布式数据,继承自KvStore,提供查询数据和同步数据的方法。在调用DeviceKVStore的方法前,需要先通过getKVStore构建一个DeviceKVStore实例。 - -### get8+ ### - -get(deviceId: string, key: string, callback: AsyncCallback<boolean|string|number|Uint8Array>): void; - -获取与指定设备 ID 和 key 匹配的 String 值,并通过callback方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

deviceId

-

string

-

-

标识要查询其数据的设备。

-

key

-

string

-

-

表示要查询 key 值的键。

-

callback

-

AsyncCallback<boolean|string|number|Uint8Array>

-

-

回调函数,返回匹配给定条件的字符串值。

-
- -- 示例 - - ``` - let kvStore; - const KEY_TEST_STRING_ELEMENT = 'key_test_string_2'; - const VALUE_TEST_STRING_ELEMENT = 'value-string-002'; - try{ - kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, async function (err,data) { - console.log('put success'); - kvStore.get('localDeviceId', KEY_TEST_STRING_ELEMENT, function (err,data) { - console.log('get success'); - }); - }) - }catch(e) { - console.log('get e' + e); - } - ``` - - -### get8+ ### - -get(deviceId: string, key: string): Promise<boolean|string|number|Uint8Array>; - -获取与指定设备 ID 和 key 匹配的 String 值,并通过Promise方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

deviceId

-

string

-

-

标识要查询其数据的设备。

-

key

-

string

-

-

表示要查询的 key 值的键。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Promise<boolean|string|number|Uint8Array>

-

Promise实例,用于获取异步返回结果。

-
- -- 示例 - - ``` - let kvStore; - const KEY_TEST_STRING_ELEMENT = 'key_test_string_2'; - const VALUE_TEST_STRING_ELEMENT = 'value-string-002'; - try { - kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then(async (data) => { - console.log(' put success'); - kvStore.get('localDeviceId', KEY_TEST_STRING_ELEMENT).then((data) => { - console.log('get success'); - }).catch((err) => { - console.log('get fail ' + JSON.stringify(err)); - }); - }).catch((error) => { - console.log('put error' + error); - }); - } catch (e) { - console.log('Get e ' + e); - } - ``` - - -### getEntries8+ ### - -getEntries(deviceId: string, keyPrefix: string, callback: AsyncCallback<Entry[]>): void; - -获取与指定设备 ID 和 key 前缀匹配的所有键值对,并通过callback方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

deviceId

-

string

-

-

标识要查询其数据的设备。

-

keyPrefix

-

string

-

-

表示要匹配的键前缀。

-

callback

-

AsyncCallback<Entry[]>

-

-

回调函数,返回满足给定条件的所有键值对的列表。

-
- -- 示例 - - ``` - let kvStore; - try { - let entries = []; - for (var i = 0; i < 10; i++) { - var key = 'batch_test_string_key'; - var entry = { - key : key + i, - value : { - type : distributedData.ValueType.STRING, - value : 'batch_test_string_value' - } - } - entries.push(entry); - } - console.log('entries: ' + entries); - kvStore.putBatch(entries, async function (err,data) { - console.log('putBatch success'); - await kvStore.getEntries('localDeviceId', 'batch_test_string_key', function (err,entrys) { - console.log('getEntries success'); - console.log('entrys.length: ' + entrys.length); - console.log('entrys[0]: ' + JSON.stringify(entrys[0])); - }); - }); - }catch(e) { - console.log('PutBatch e ' + e); - } - ``` - - -### getEntries8+ ### - -getEntries(deviceId: string, keyPrefix: string): Promise<Entry[]>; - -获取与指定设备 ID 和 key 前缀匹配的所有键值对,并通过Promise方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

deviceId

-

string

-

-

标识要查询其数据的设备。

-

keyPrefix

-

string

-

-

表示要匹配的键前缀。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Promise<Entry[]>

-

Promise实例,用于获取异步返回结果。

-
- -- 示例 - - ``` - let kvStore; - try { - let entries = []; - for (var i = 0; i < 10; i++) { - var key = 'batch_test_string_key'; - var entry = { - key : key + i, - value : { - type : distributedData.ValueType.STRING, - value : 'batch_test_string_value' - } - } - entries.push(entry); - } - console.log('entries: ' + entries); - kvStore.putBatch(entries).then(async (err) => { - console.log('putBatch success'); - await kvStore.getEntries('localDeviceId', 'batch_test_string_key').then((entrys) => { - console.log('getEntries success'); - console.log('entrys.length: ' + entrys.length); - console.log('entrys[0]: ' + JSON.stringify(entrys[0])); - console.log('entrys[0].value: ' + JSON.stringify(entrys[0].value)); - console.log('entrys[0].value.value: ' + entrys[0].value.value); - }).catch((err) => { - console.log('getEntries fail ' + JSON.stringify(err)); - }); - }).catch((err) => { - console.log('putBatch fail ' + JSON.stringify(err)); - }); - }catch(e) { - console.log('PutBatch e ' + e); - } - ``` - - -### getEntries8+ ### - -getEntries(query: Query, callback: AsyncCallback<Entry[]>): void; - -获取与指定 Query 对象匹配的键值对列表,并通过callback方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

query

-

Query

-

-

表示查询对象。

-

callback

-

AsyncCallback<Entry[]>

-

-

回调函数,返回与指定 Query 对象匹配的键值对列表。

-
- -- 示例 - - ``` - let kvStore; - try { - var arr = new Uint8Array([21,31]); - let entries = []; - for (var i = 0; i < 10; i++) { - var key = 'batch_test_bool_key'; - var entry = { - key : key + i, - value : { - type : distributedData.ValueType.BYTE_ARRAY, - value : arr - } - } - entries.push(entry); - } - console.log('entries: ' + JSON.stringify(entries)); - kvStore.putBatch(entries, async function (err,data) { - console.log('putBatch success'); - expect(err == undefined).assertTrue(); - const query = new distributedData.Query(); - query.prefixKey("batch_test"); - query.deviceId('localDeviceId'); - await kvStore.getEntries(query, function (err,entrys) { - console.log('getEntries success'); - console.log('entrys.length: ' + entrys.length); - console.log('entrys[0]: ' + JSON.stringify(entrys[0])); - }); - }); - console.log('GetEntries success'); - }catch(e) { - console.log('GetEntries e ' + e); - } - ``` - - -### getEntries8+ ### - -getEntries(query: Query): Promise<Entry[]>; - -获取与指定 Query 对象匹配的键值对列表,并通过Promise方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

query

-

Query

-

-

表示查询对象。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Promise<Entry[]>

-

Promise实例,用于获取异步返回结果。

-
- -- 示例 - - ``` - let kvStore; - try { - var arr = new Uint8Array([21,31]); - let entries = []; - for (var i = 0; i < 10; i++) { - var key = 'batch_test_bool_key'; - var entry = { - key : key + i, - value : { - type : distributedData.ValueType.BYTE_ARRAY, - value : arr - } - } - entries.push(entry); - } - console.log('entries: ' + JSON.stringify(entries)); - kvStore.putBatch(entries).then(async (err) => { - console.log('putBatch success'); - const query = new distributedData.Query(); - query.prefixKey("batch_test"); - await kvStore.getEntries(query).then((entrys) => { - console.log('getEntries success'); - }).catch((err) => { - console.log('getEntries fail ' + JSON.stringify(err)); - }); - }).catch((err) => { - console.log('GetEntries putBatch fail ' + JSON.stringify(err)) - }); - console.log('GetEntries success'); - }catch(e) { - console.log('GetEntries e ' + e); - } - ``` - - -### getEntries8+ ### - -getEntries(deviceId: string, query: Query, callback: AsyncCallback<Entry[]>): void; - -获取与指定设备 ID 和 Query 对象匹配的键值对列表,并通过callback方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

deviceId

-

string

-

-

键值对所属的设备ID。

-

query

-

Query

-

-

表示查询对象。

-

callback

-

AsyncCallback<Entry[]>

-

-

回调函数,返回与指定 Query 对象匹配的键值对列表。

-
- -- 示例 - - ``` - let kvStore; - try { - var arr = new Uint8Array([21,31]); - let entries = []; - for (var i = 0; i < 10; i++) { - var key = 'batch_test_bool_key'; - var entry = { - key : key + i, - value : { - type : distributedData.ValueType.BYTE_ARRAY, - value : arr - } - } - entries.push(entry); - } - console.log('entries: ' + JSON.stringify(entries)); - kvStore.putBatch(entries, async function (err,data) { - console.log('putBatch success'); - expect(err == undefined).assertTrue(); - var query = new distributedData.Query(); - query.deviceId('localDeviceId'); - query.prefixKey("batch_test"); - await kvStore.getEntries('localDeviceId', query, function (err,entrys) { - console.log('getEntries success'); - console.log('entrys.length: ' + entrys.length); - console.log('entrys[0]: ' + JSON.stringify(entrys[0])); - }) - }); - console.log('GetEntries success'); - }catch(e) { - console.log('GetEntries e ' + e); - } - ``` - - -### getEntries8+ ### - -getEntries(deviceId: string, query: Query): Promise<Entry[]>; - -获取与指定设备 ID 和 Query 对象匹配的键值对列表,并通过Promise方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

deviceId

-

string

-

-

键值对所属的设备ID。

-

query

-

Query

-

-

表示查询对象。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Promise<Entry[]>

-

Promise实例,用于获取异步返回结果。

-
- -- 示例 - - ``` - let kvStore; - try { - var arr = new Uint8Array([21,31]); - let entries = []; - for (var i = 0; i < 10; i++) { - var key = 'batch_test_bool_key'; - var entry = { - key : key + i, - value : { - type : distributedData.ValueType.BYTE_ARRAY, - value : arr - } - } - entries.push(entry); - } - console.log('entries: ' + JSON.stringify(entries)); - kvStore.putBatch(entries).then(async (err) => { - console.log('putBatch success'); - var query = new distributedData.Query(); - query.deviceId('localDeviceId'); - query.prefixKey("batch_test"); - await kvStore.getEntries('localDeviceId', query).then((entrys) => { - console.log('getEntries success'); - }).catch((err) => { - console.log('getEntries fail ' + JSON.stringify(err)); - }); - }).catch((err) => { - console.log('putBatch fail ' + JSON.stringify(err)); - }); - console.log('GetEntries success'); - }catch(e) { - console.log('GetEntries e ' + e); - } - ``` - - -### getResultSet8+ ### - -getResultSet(deviceId: string, keyPrefix: string, callback: AsyncCallback<KvStoreResultSet>): void; - -获取与指定设备 ID 和 key 前缀匹配的 KvStoreResultSet 对象,并通过callback方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

deviceId

-

string

-

-

标识要查询其数据的设备。

-

keyPrefix

-

string

-

-

表示要匹配的键前缀。

-

callback

-

AsyncCallback<KvStoreResultSet>

-

-

回调函数,返回 KvStoreResultSet 对象。

-
- -- 示例 - - ``` - let kvStore; - try { - let resultSet; - kvStore.getResultSet('localDeviceId', 'batch_test_string_key', async function (err, result) { - console.log('getResultSet success'); - resultSet = result; - await kvStore.closeResultSet(resultSet, function (err, data) { - console.log('closeResultSet success'); - }) - }); - }catch(e) { - console.log('GetResultSet e ' + e); - } - ``` - - -### getResultSet8+ ### - -getResultSet(deviceId: string, keyPrefix: string): Promise<KvStoreResultSet>; - -获取与指定设备 ID 和 key 前缀匹配的 KvStoreResultSet 对象,并通过Promise方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

deviceId

-

string

-

-

标识要查询其数据的设备。

-

keyPrefix

-

string

-

-

表示要匹配的键前缀。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Promise<KvStoreResultSet>

-

Promise实例,用于获取异步返回结果。

-
- -- 示例 - - ``` - let kvStore; - try { - let resultSet; - kvStore.getResultSet('localDeviceId', 'batch_test_string_key').then((result) => { - console.log('getResultSet success'); - resultSet = result; - }).catch((err) => { - console.log('getResultSet fail ' + JSON.stringify(err)); - }); - kvStore.closeResultSet(resultSet).then((err) => { - console.log('closeResultSet success'); - }).catch((err) => { - console.log('closeResultSet fail ' + JSON.stringify(err)); - }); - }catch(e) { - console.log('GetResultSet e ' + e); - } - ``` - - -### getResultSet8+ ### - -getResultSet(query: Query, callback: AsyncCallback<KvStoreResultSet>): void; - -获取与指定 Query 对象匹配的 KvStoreResultSet 对象,并通过callback方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

query

-

Query

-

-

表示查询对象。

-

callback

-

AsyncCallback<KvStoreResultSet>

-

-

回调函数,返回与指定 Query 对象匹配的 KvStoreResultSet 对象。

-
- -- 示例 - - ``` - let kvStore; - try { - let resultSet; - let entries = []; - for (var i = 0; i < 10; i++) { - var key = 'batch_test_string_key'; - var entry = { - key : key + i, - value : { - type : distributedData.ValueType.STRING, - value : 'batch_test_string_value' - } - } - entries.push(entry); - } - kvStore.putBatch(entries, async function (err, data) { - console.log('putBatch success'); - const query = new distributedData.Query(); - query.prefixKey("batch_test"); - query.deviceId('localDeviceId'); - await kvStore.getResultSet(query, async function (err, result) { - console.log('getResultSet success'); - resultSet = result; - await kvStore.closeResultSet(resultSet, function (err, data) { - console.log('closeResultSet success'); - }) - }); - }); - } catch(e) { - console.log('GetResultSet e ' + e); - } - ``` - - -### getResultSet8+ ### - -getResultSet(query: Query): Promise<KvStoreResultSet>; - -获取与指定 Query 对象匹配的 KvStoreResultSet 对象,并通过Promise方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

query

-

Query

-

-

表示查询对象。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Promise<KvStoreResultSet>

-

Promise实例,用于获取异步返回结果。

-
- -- 示例 - - ``` - let kvStore; - try { - let resultSet; - let entries = []; - for (var i = 0; i < 10; i++) { - var key = 'batch_test_string_key'; - var entry = { - key : key + i, - value : { - type : distributedData.ValueType.STRING, - value : 'batch_test_string_value' - } - } - entries.push(entry); - } - kvStore.putBatch(entries).then(async (err) => { - console.log('putBatch success'); - }).catch((err) => { - console.log('putBatch fail ' + err); - }); - const query = new distributedData.Query(); - query.deviceId('localDeviceId'); - query.prefixKey("batch_test"); - console.log("GetResultSet " + query.getSqlLike()); - kvStore.getResultSet(query).then((result) => { - console.log('getResultSet success'); - resultSet = result; - }).catch((err) => { - console.log('getResultSet fail ' + JSON.stringify(err)); - }); - kvStore.closeResultSet(resultSet).then((err) => { - console.log('closeResultSet success'); - }).catch((err) => { - console.log('closeResultSet fail ' + JSON.stringify(err)); - }); - }catch(e) { - console.log('GetResultSet e ' + e); - } - ``` - - -### getResultSet8+ ### - -getResultSet(deviceId: string, query: Query, callback: AsyncCallback<KvStoreResultSet>): void; - -获取与指定设备ID和Query对象匹配的KvStoreResultSet对象,并通过callback方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

deviceId

-

string

-

-

KvStoreResultSet对象所属的设备ID。

-

query

-

Query

-

-

表示查询对象。

-

callback

-

AsyncCallback<KvStoreResultSet>

-

-

回调函数,返回与指定 Query 对象匹配的 KvStoreResultSet 对象。

-
- -- 示例 - - ``` - let kvStore; - try { - let resultSet; - let entries = []; - for (var i = 0; i < 10; i++) { - var key = 'batch_test_string_key'; - var entry = { - key : key + i, - value : { - type : distributedData.ValueType.STRING, - value : 'batch_test_string_value' - } - } - entries.push(entry); - } - kvStore.putBatch(entries, async function (err, data) { - console.log('putBatch success'); - const query = new distributedData.Query(); - query.prefixKey("batch_test"); - await kvStore.getResultSet('localDeviceId', query, async function (err, result) { - console.log('getResultSet success'); - resultSet = result; - await kvStore.closeResultSet(resultSet, function (err, data) { - console.log('closeResultSet success'); - }) - }); - }); - } catch(e) { - console.log('GetResultSet e ' + e); - } - ``` - - -### getResultSet8+ ### - -getResultSet(deviceId: string, query: Query): Promise<KvStoreResultSet>; - -获取与指定设备ID和Query对象匹配的KvStoreResultSet对象,并通过Promise方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

deviceId

-

string

-

-

KvStoreResultSet对象所属的设备ID。

-

query

-

Query

-

-

表示查询对象。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Promise<KvStoreResultSet>

-

Promise实例,用于获取异步返回结果。

-
- -- 示例 - - ``` - let kvStore; - try { - let resultSet; - let entries = []; - for (var i = 0; i < 10; i++) { - var key = 'batch_test_string_key'; - var entry = { - key : key + i, - value : { - type : distributedData.ValueType.STRING, - value : 'batch_test_string_value' - } - } - entries.push(entry); - } - kvStore.putBatch(entries).then(async (err) => { - console.log('GetResultSet putBatch success'); - }).catch((err) => { - console.log('PutBatch putBatch fail ' + JSON.stringify(err)); - }); - const query = new distributedData.Query(); - query.prefixKey("batch_test"); - kvStore.getResultSet('localDeviceId', query).then((result) => { - console.log('GetResultSet getResultSet success'); - resultSet = result; - }).catch((err) => { - console.log('GetResultSet getResultSet fail ' + JSON.stringify(err)); - }); - query.deviceId('localDeviceId'); - console.log("GetResultSet " + query.getSqlLike()); - kvStore.closeResultSet(resultSet).then((err) => { - console.log('GetResultSet closeResultSet success'); - }).catch((err) => { - console.log('GetResultSet closeResultSet fail ' + JSON.stringify(err)); - }); - - }catch(e) { - console.log('GetResultSet e ' + e); - } - ``` - - -### closeResultSet8+ ### - -closeResultSet(resultSet: KvStoreResultSet, callback: AsyncCallback<void>): void; - -关闭由 getResultSet 返回的 KvStoreResultSet 对象,并通过callback方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

resultSet

-

KvStoreResultSet

-

-

指示要关闭的 KvStoreResultSet 对象。

-

callback

-

AsyncCallback<void>

-

-

回调函数。

-
- -- 示例 - - ``` - let kvStore; - try { - console.log('CloseResultSet success'); - let resultSet = null; - kvStore.closeResultSet(resultSet, function (err, data) { - if (err == undefined) { - console.log('closeResultSet success'); - } else { - console.log('closeResultSet fail'); - } - }); - }catch(e) { - console.log('CloseResultSet e ' + e); - } - ``` - - -### closeResultSet8+ ### - -closeResultSet(resultSet: KvStoreResultSet): Promise<void>; - -关闭由 getResultSet 返回的 KvStoreResultSet 对象,并通过Promise方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

resultSet

-

KvStoreResultSet

-

-

指示要关闭的 KvStoreResultSet 对象。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Promise<void>

-

Promise实例,用于获取异步返回结果。

-
- -- 示例 - - ``` - let kvStore; - try { - console.log('CloseResultSet success'); - let resultSet = null; - kvStore.closeResultSet(resultSet).then(() => { - console.log('closeResultSet success'); - }).catch((err) => { - console.log('closeResultSet fail ' + JSON.stringify(err)); - }); - }catch(e) { - console.log('CloseResultSet e ' + e); - } - ``` - - -### getResultSize8+ ### - -getResultSize(query: Query, callback: AsyncCallback<number>): void; - -获取与指定 Query 对象匹配的结果数,并通过callback方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

query

-

Query

-

-

表示查询对象。

-

callback

-

AsyncCallback<number>

-

-

回调函数,返回与指定 Query 对象匹配的结果数。

-
- -- 示例 - - ``` - let kvStore; - try { - let entries = []; - for (var i = 0; i < 10; i++) { - var key = 'batch_test_string_key'; - var entry = { - key : key + i, - value : { - type : distributedData.ValueType.STRING, - value : 'batch_test_string_value' - } - } - entries.push(entry); - } - kvStore.putBatch(entries, async function (err, data) { - console.log('putBatch success'); - const query = new distributedData.Query(); - query.prefixKey("batch_test"); - query.deviceId('localDeviceId'); - await kvStore.getResultSize(query, async function (err, resultSize) { - console.log('getResultSet success'); - }); - }); - } catch(e) { - console.log('GetResultSize e ' + e); - } - ``` - - -### getResultSize8+ ### - -getResultSize(query: Query): Promise<number>; - -获取与指定 Query 对象匹配的结果数,并通过Promise方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

query

-

Query

-

-

表示查询对象。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Promise<number>

-

Promise实例,用于获取异步返回结果。

-
- -- 示例 - - ``` - let kvStore; - try { - let entries = []; - for (var i = 0; i < 10; i++) { - var key = 'batch_test_string_key'; - var entry = { - key : key + i, - value : { - type : distributedData.ValueType.STRING, - value : 'batch_test_string_value' - } - } - entries.push(entry); - } - kvStore.putBatch(entries).then(async (err) => { - console.log('putBatch success'); - }).catch((err) => { - console.log('putBatch fail ' + JSON.stringify(err)); - }); - const query = new distributedData.Query(); - query.prefixKey("batch_test"); - query.deviceId('localDeviceId'); - kvStore.getResultSize(query).then((resultSize) => { - console.log('getResultSet success'); - }).catch((err) => { - console.log('getResultSet fail ' + JSON.stringify(err)); - }); - }catch(e) { - console.log('GetResultSize e ' + e); - } - ``` - - -### getResultSize8+ ### - -getResultSize(deviceId: string, query: Query, callback: AsyncCallback<number>): void; - -获取与指定设备 ID 和 Query 对象匹配的结果数,并通过callback方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

deviceId

-

string

-

-

表示结果所属的设备ID。

-

query

-

Query

-

-

表示查询对象。

-

callback

-

AsyncCallback<number>

-

-

回调函数,返回与指定 Query 对象匹配的结果数。

-
- -- 示例 - - ``` - let kvStore; - try { - let entries = []; - for (var i = 0; i < 10; i++) { - var key = 'batch_test_string_key'; - var entry = { - key : key + i, - value : { - type : distributedData.ValueType.STRING, - value : 'batch_test_string_value' - } - } - entries.push(entry); - } - kvStore.putBatch(entries, async function (err, data) { - console.log('putBatch success'); - const query = new distributedData.Query(); - query.prefixKey("batch_test"); - await kvStore.getResultSize('localDeviceId', query, async function (err, resultSize) { - console.log('getResultSet success'); - }); - }); - } catch(e) { - console.log('GetResultSize e ' + e); - } - ``` - - -### getResultSize8+ ### - -getResultSize(deviceId: string, query: Query): Promise<number>; - -获取与指定设备 ID 和 Query 对象匹配的结果数,并通过Promise方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

deviceId

-

string

-

-

表示结果所属的设备ID。

-

query

-

Query

-

-

表示查询对象。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Promise<number>

-

Promise实例,用于获取异步返回结果。

-
- -- 示例 - - ``` - let kvStore; - try { - let entries = []; - for (var i = 0; i < 10; i++) { - var key = 'batch_test_string_key'; - var entry = { - key : key + i, - value : { - type : distributedData.ValueType.STRING, - value : 'batch_test_string_value' - } - } - entries.push(entry); - } - kvStore.putBatch(entries).then(async (err) => { - console.log('putBatch success'); - }).catch((err) => { - console.log('putBatch fail ' + JSON.stringify(err)); - }); - var query = new distributedData.Query(); - query.prefixKey("batch_test"); - kvStore.getResultSize('localDeviceId', query).then((resultSize) => { - console.log('getResultSet success'); - }).catch((err) => { - console.log('getResultSet fail ' + JSON.stringify(err)); - }); - }catch(e) { - console.log('GetResultSize e ' + e); - } - ``` - - -### removeDeviceData8+ ### - -removeDeviceData(deviceId: string, callback: AsyncCallback<void>): void; - -从当前数据库中删除指定设备的数据,并通过callback方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

deviceId

-

string

-

-

标识要删除其数据的设备。

-

callback

-

AsyncCallback<void>

-

-

回调函数。

-
- -- 示例 - - ``` - let kvStore; - const KEY_TEST_STRING_ELEMENT = 'key_test_string'; - const VALUE_TEST_STRING_ELEMENT = 'value-string-001'; - try { - kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT, async function (err,data) { - console.log('RemoveDeviceData put success'); - const deviceid = 'no_exist_device_id'; - await kvStore.removeDeviceData(deviceid, async function (err,data) { - if (err == undefined) { - console.log('removeDeviceData success'); - } else { - console.log('removeDeviceData fail'); - await kvStore.get('localDeviceId', KEY_TEST_STRING_ELEMENT, async function (err,data) { - console.log('RemoveDeviceData get success'); - }); - } - }); - }); - }catch(e) { - console.log('RemoveDeviceData e ' + e); - } - ``` - - -### removeDeviceData8+ ### - -removeDeviceData(deviceId: string): Promise<void>; - -从当前数据库中删除指定设备的数据,并通过Promise方式返回,此方法为异步方法。 - -- 参数: - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

deviceId

-

string

-

-

标识要删除其数据的设备。

-
- -- 返回值: - - - - - - - - - - -

类型

-

说明

-

Promise<void>

-

Promise实例,用于获取异步返回结果。

-
- -- 示例 - - ``` - let kvStore; - const KEY_TEST_STRING_ELEMENT = 'key_test_string'; - const VALUE_TEST_STRING_ELEMENT = 'value-string-001'; - try { - kvStore.put(KEY_TEST_STRING_ELEMENT, VALUE_TEST_STRING_ELEMENT).then((err) => { - console.log('RemoveDeviceData put success'); - }).catch((err) => { - console.log('RemoveDeviceData put fail ' + JSON.stringify(err)); - }); - const deviceid = 'no_exist_device_id'; - kvStore.removeDeviceData(deviceid).then((err) => { - console.log('removeDeviceData success'); - }).catch((err) => { - console.log('removeDeviceData fail ' + JSON.stringify(err)); - }); - kvStore.get('localDeviceId', KEY_TEST_STRING_ELEMENT).then((data) => { - console.log('RemoveDeviceData get success data:' + data); - }).catch((err) => { - console.log('RemoveDeviceData get fail ' + JSON.stringify(err)); - }); - }catch(e) { - console.log('RemoveDeviceData e ' + e); - } - ``` - - -### sync8+ ### - -sync(deviceIdList: string[], mode: SyncMode, allowedDelayMs?: number): void; - -在手动模式下,触发数据库同步,此方法为同步方法。 - -- 参数: - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

deviceIdList

-

string[]

-

-

需要同步DeviceKvStore数据库的设备ID列表。

-

mode

-

SyncMode

-

-

表示同步方式,PUSH、PULL或PUSH_PULL。

-

allowedDelayMs

-

- number

-

-

可选参数,允许延时时间,单位:ms(毫秒)。

-
- -- 示例 - - ``` - let kvStore; - const KEY_TEST_SYNC_ELEMENT = 'key_test_sync'; - const VALUE_TEST_SYNC_ELEMENT = 'value-string-001'; - try { - kvStore.on('syncComplete', function (data) { - console.log('Sync dataChange'); - }); - kvStore.put(KEY_TEST_SYNC_ELEMENT + 'testSync101', VALUE_TEST_SYNC_ELEMENT, function (err,data) { - console.log('Sync put success'); - const devices = ['deviceList']; - const mode = distributedData.SyncMode.PULL_ONLY; - kvStore.sync(devices, mode); - }); - }catch(e) { - console.log('Sync e' + e); - } - ``` - -### on8+ ### - -on(event: 'syncComplete', syncCallback: Callback - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

event

-

'syncComplete'

-

-

同步完成时触发的事件名。

-

syncCallback

-

Callback<Array<[string, number]>

-

-

用于向调用方发送同步结果的回调。

-
- -- 示例 - ``` - const KEY_TEST_FLOAT_ELEMENT = 'key_test_float'; - const VALUE_TEST_FLOAT_ELEMENT = 321.12; - try { - kvStore.on('syncComplete', function (data) { - console.log('syncComplete ' + data) - }); - kvStore.put(KEY_TEST_FLOAT_ELEMENT, VALUE_TEST_FLOAT_ELEMENT).then((data) => { - console.log('syncComplete put success'); - }).catch((error) => { - console.log('syncComplete put fail ' + error); - }); - }catch(e) { - console.log('syncComplete put e ' + e); - } - ``` - - -### off8+ ### - -off(event: 'syncComplete', syncCallback?: Callback - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

event

-

'syncComplete'

-

-

同步完成时触发的事件名。

-

syncCallback

-

Callback<Array<[string, number]>

-

-

用于向调用方发送同步结果的回调。

-
- -- 示例 - - ``` - let kvStore; - try { - const func = function (data) { - console.log('syncComplete ' + data) - }; - kvStore.on('syncComplete', func); - kvStore.off('syncComplete', func); - }catch(e) { - console.log('syncComplete e ' + e); - } - ``` - - -## SyncMode - -用于指定同步模式。 - - - - - - - - - - - - - - - - - - - - -

名称

-

默认值

-

说明

-

PULL_ONLY

-

0

-

表示只能从远端拉取数据到本端。

-

PUSH_ONLY

-

1

-

表示只能从本端推送数据到对端。

-

PUSH_PULL

-

2

-

表示从本端推送数据到远端,然后从远端拉取数据到本端。

-
\ No newline at end of file diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/05.\346\225\260\346\215\256\347\256\241\347\220\206/03.\345\205\263\347\263\273\345\236\213\346\225\260\346\215\256\345\272\223.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/05.\346\225\260\346\215\256\347\256\241\347\220\206/03.\345\205\263\347\263\273\345\236\213\346\225\260\346\215\256\345\272\223.md" deleted file mode 100644 index f4b1684ff20d2aa93fb33c57f774092e93728ce2..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/05.\346\225\260\346\215\256\347\256\241\347\220\206/03.\345\205\263\347\263\273\345\236\213\346\225\260\346\215\256\345\272\223.md" +++ /dev/null @@ -1,1227 +0,0 @@ ---- -title: 关系型数据库 -permalink: /pages/010c010503 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 关系型数据库 - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import data_rdb from '@ohos.data.rdb' -``` - - -## 权限 - -无 - - -## data_rdb.getRdbStore - -getRdbStore(context: Context, config: StoreConfig, version: number, callback: AsyncCallback<RdbStore>): void - -获得一个相关的RdbStore,操作关系型数据库,用户可以根据自己的需求配置RdbStore的参数,然后通过RdbStore调用相关接口可以执行相关的数据操作,结果以callback形式返回。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | context | Context | 是 | 应用程序或功能的上下文 | - | config | [StoreConfig](#storeconfig) | 是 | 与此RDB存储相关的数据库配置。 | - | version | number | 是 | 数据库版本。 | - | callback | AsyncCallback<[RdbStore](#rdbstore)> | 是 | 指定callback回调函数。返回一个RdbStore。 | - -- 示例: - ``` - import Ability from '@ohos.application.Ability' - import data_rdb from '@ohos.data.rdb' - export default class MainAbility extends Ability { - const STORE_CONFIG = { name: "RdbTest.db"} - const SQL_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)" - data_rdb.getRdbStore(this.context, STORE_CONFIG, 1, function (err, rdbStore) { - rdbStore.executeSql(SQL_CREATE_TABLE) - console.info(TAG + 'create table done.') - }) - } - ``` - -## data_rdb.getRdbStore - -getRdbStore(context: Context, config: StoreConfig, version: number): Promise<RdbStore> - -获得一个相关的RdbStore,操作关系型数据库,用户可以根据自己的需求配置RdbStore的参数,然后通过RdbStore调用相关接口可以执行相关的数据操作,结果以Promise形式返回。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | context | Context | 是 | 应用程序或功能的上下文 | - | config | [StoreConfig](#storeconfig) | 是 | 与此RDB存储相关的数据库配置。 | - | version | number | 是 | 数据库版本。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<[RdbStore](#rdbstore)> | 指定Promise回调函数。返回一个RdbStore。 | - -- 示例: - ``` - import Ability from '@ohos.application.Ability' - import data_rdb from '@ohos.data.rdb' - export default class MainAbility extends Ability { - const STORE_CONFIG = { name: "RdbTest.db" } - const SQL_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)" - let promise = data_rdb.getRdbStore(this.context, STORE_CONFIG, 1); - promise.then(async (rdbStore) => { - await rdbStore.executeSql(SQL_CREATE_TABLE, null) - }).catch((err) => { - expect(null).assertFail(); - }) - } - ``` - -## data_rdb.deleteRdbStore - -deleteRdbStore(context: Context, name: string, callback: AsyncCallback<void>): void - -删除数据库,结果以callback形式返回。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | context | Context | 是 | 应用程序或功能的上下文 | - | name | string | 是 | 数据库名称。 | - | callback | AsyncCallback<void> | 是 | 指定callback回调函数。如果数据库已删除,则为true;否则返回false。 | - -- 示例: - ``` - import Ability from '@ohos.application.Ability' - import data_rdb from '@ohos.data.rdb' - export default class MainAbility extends Ability { - data_rdb.deleteRdbStore(this.context, "RdbTest.db", function (err, rdbStore) { - console.info(TAG + 'delete store done.')}) - } - ``` - -## data_rdb.deleteRdbStore - -deleteRdbStore(context: Context, name: string): Promise<void> - -使用指定的数据库文件配置删除数据库,结果以Promise形式返回。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | context | Context | 是 | 应用程序或功能的上下文 | - | name | string | 是 | 数据库名称。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | 指定Promise回调函数。如果数据库已删除,则为true;否则返回false。 | - -- 示例: - ``` - import Ability from '@ohos.application.Ability' - import data_rdb from '@ohos.data.rdb' - export default class MainAbility extends Ability { - let promise = data_rdb.deleteRdbStore(this.context, "RdbTest.db") - promise.then(()=>{ - console.info(TAG + 'delete store done.') - }) - } - ``` - -## RdbPredicates - -表示关系型数据库(RDB)的谓词。该类确定RDB中条件表达式的值是true还是false。 - - -### constructor - -constructor(name: string) - - -构造函数。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | name | string | 是 | 数据库表名。 | - -- 示例: - ``` - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - ``` - - -### equalTo - -equalTo(field: string, value: ValueType): RdbPredicates - - -配置谓词以匹配数据字段为ValueType且值等于指定值的字段。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | field | string | 是 | 数据库表中的列名。 | - | value | [ValueType](#valuetype) | 是 | 指示要与谓词匹配的值。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | - -- 示例: - ``` - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.equalTo("NAME", "lisi") - ``` - - -### notEqualTo - -notEqualTo(field: string, value: ValueType): RdbPredicates - - -配置谓词以匹配数据字段为ValueType且值不等于指定值的字段。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | field | string | 是 | 数据库表中的列名。 | - | value | [ValueType](#valuetype) | 是 | 指示要与谓词匹配的值。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | - -- 示例: - ``` - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.notEqualTo("NAME", "lisi") - ``` - - -### beginWrap - -beginWrap(): RdbPredicates - - -向谓词添加左括号。 - - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [RdbPredicates](#rdbpredicates) | 返回带有左括号的Rdb谓词。 | - -- 示例: - ``` - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.equalTo("NAME", "lisi") - .beginWrap() - .equalTo("AGE", 18) - .or() - .equalTo("SALARY", 200.5) - .endWrap() - ``` - - -### endWrap - -endWrap(): RdbPredicates - - -向谓词添加右括号。 - - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [RdbPredicates](#rdbpredicates) | 返回带有右括号的Rdb谓词。 | - -- 示例: - ``` - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.equalTo("NAME", "lisi") - .beginWrap() - .equalTo("AGE", 18) - .or() - .equalTo("SALARY", 200.5) - .endWrap() - ``` - - -### or - -or(): RdbPredicates - - -将或条件添加到谓词中。 - - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [RdbPredicates](#rdbpredicates) | 返回带有或条件的Rdb谓词。 | - -- 示例: - ``` - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.equalTo("NAME", "Lisa") - .or() - .equalTo("NAME", "Rose") - ``` - - -### and - -and(): RdbPredicates - - -向谓词添加和条件。 - - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [RdbPredicates](#rdbpredicates) | 返回带有和条件的Rdb谓词。 | - -- 示例: - ``` - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.equalTo("NAME", "Lisa") - .and() - .equalTo("SALARY", 200.5) - ``` - - -### contains - -contains(field: string, value: string): RdbPredicat - - -配置谓词以匹配数据字段为String且value包含指定值的字段。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | field | string | 是 | 数据库表中的列名。 | - | value | string | 是 | 指示要与谓词匹配的值。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | - -- 示例: - ``` - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.contains("NAME", "os") - ``` - - -### beginsWith - -beginsWith(field: string, value: string): RdbPredicates - - -配置谓词以匹配数据字段为String且值以指定字符串开头的字段。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | field | string | 是 | 数据库表中的列名。 | - | value | string | 是 | 指示要与谓词匹配的值。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | - -- 示例: - ``` - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.beginsWith("NAME", "os") - ``` - - -### endsWith - -endsWith(field: string, value: string): RdbPredicates - - -配置谓词以匹配数据字段为String且值以指定字符串结尾的字段。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | field | string | 是 | 数据库表中的列名。 | - | value | string | 是 | 指示要与谓词匹配的值。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | - -- 示例: - ``` - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.endsWith("NAME", "se") - ``` - - -### isNull - -isNull(field: string): RdbPredicates - - -配置谓词以匹配值为null的字段。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | field | string | 是 | 数据库表中的列名。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | - -- 示例 - ``` - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.isNull("NAME") - ``` - - -### isNotNull - -isNotNull(field: string): RdbPredicates - - -配置谓词以匹配值不为null的指定字段。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | field | string | 是 | 数据库表中的列名。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | - -- 示例: - ``` - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.isNotNull("NAME") - ``` - - -### like - -like(field: string, value: string): RdbPredicates - - -配置谓词以匹配数据字段为String且值类似于指定字符串的字段。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | field | string | 是 | 数据库表中的列名。 | - | value | string | 是 | 指示要与谓词匹配的值。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | - -- 示例: - ``` - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.like("NAME", "%os%") - ``` - - -### glob - -glob(field: string, value: string): RdbPredicates - - -配置RdbPredicates匹配数据字段为String的指定字段。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | field | string | 是 | 数据库表中的列名。 | - | value | string | 是 | 指示要与谓词匹配的值。
支持通配符,*表示0个、1个或多个数字或字符,?表示1个数字或字符。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | - -- 示例: - ``` - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.glob("NAME", "?h*g") - ``` - - -### between - -between(field: string, low: ValueType, high: ValueType): RdbPredicates - - -将谓词配置为匹配数据字段为ValueType且value在给定范围内的指定字段。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | field | string | 是 | 数据库表中的列名。 | - | low | [ValueType](#valuetype) | 是 | 指示与谓词匹配的最小值。 | - | high | [ValueType](#valuetype) | 是 | 指示要与谓词匹配的最大值。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | - -- 示例: - ``` - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.between("AGE", 10, 50) - ``` - - -### notBetween - -notBetween(field: string, low: ValueType, high: ValueType): RdbPredicates - - -配置RdbPredicates以匹配数据字段为ValueType且value超出给定范围的指定字段。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | field | string | 是 | 数据库表中的列名。 | - | low | [ValueType](#valuetype) | 是 | 指示与谓词匹配的最小值。 | - | high | [ValueType](#valuetype) | 是 | 指示要与谓词匹配的最大值。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | - -- 示例: - ``` - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.notBetween("AGE", 10, 50) - ``` - - -### greaterThan - -greaterThan(field: string, value: ValueType): RdbPredicatesgr - - -配置谓词以匹配数据字段为ValueType且值大于指定值的字段。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | field | string | 是 | 数据库表中的列名。 | - | value | [ValueType](#valuetype) | 是 | 指示要与谓词匹配的值。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | - -- 示例: - ``` - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.greaterThan("AGE", 18) - ``` - - -### lessThan - -lessThan(field: string, value: ValueType): RdbPredicates - - -配置谓词以匹配数据字段为valueType且value小于指定值的字段。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | field | string | 是 | 数据库表中的列名。 | - | value | [ValueType](#valuetype) | 是 | 指示要与谓词匹配的值。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | - -- 示例: - ``` - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.lessThan("AGE", 20) - ``` - - -### greaterThanOrEqualTo - - -greaterThanOrEqualTo(field: string, value: ValueType): RdbPredicates - - -配置谓词以匹配数据字段为ValueType且value大于或等于指定值的字段。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | field | string | 是 | 数据库表中的列名。 | - | value | [ValueType](#valuetype) | 是 | 指示要与谓词匹配的值。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | - -- 示例: - ``` - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.greaterThanOrEqualTo("AGE", 18) - ``` - - -### lessThanOrEqualTo - - -lessThanOrEqualTo(field: string, value: ValueType): RdbPredicates - - -配置谓词以匹配数据字段为ValueType且value小于或等于指定值的字段。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | field | string | 是 | 数据库表中的列名。 | - | value | [ValueType](#valuetype) | 是 | 指示要与谓词匹配的值。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | - -- 示例: - ``` - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.lessThanOrEqualTo("AGE", 20) - ``` - - -### orderByAsc - - -orderByAsc(field: string): RdbPredicates - - -配置谓词以匹配其值按升序排序的列。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | field | string | 是 | 数据库表中的列名。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | - -- 示例: - ``` - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.orderByAsc("NAME") - ``` - - -### orderByDesc - - -orderByDesc(field: string): RdbPredicates - - -配置谓词以匹配其值按降序排序的列。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | field | string | 是 | 数据库表中的列名。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | - -- 示例: - ``` - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.orderByDesc("AGE") - ``` - - -### distinct - -distinct(): RdbPredicates - - -配置谓词以过滤重复记录并仅保留其中一个。 - - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [RdbPredicates](#rdbpredicates) | 返回可用于过滤重复记录的谓词。 | - -- 示例: - ``` - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.equalTo("NAME", "Rose").distinct("NAME") - let resultSet = await rdbStore.query(predicates, ["NAME"]) - ``` - - -### limitAs - -limitAs(value: number): RdbPredicates - - -设置最大数据记录数的谓词。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | number | 是 | 最大数据记录数。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [RdbPredicates](#rdbpredicates) | 返回可用于设置最大数据记录数的谓词。 | - -- 示例: - ``` - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.equalTo("NAME", "Rose").limitAs(3) - ``` - - -### offsetAs - -offsetAs(rowOffset: number): RdbPredicates - - -配置RdbPredicates以指定返回结果的起始位置。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | rowOffset | number | 是 | 返回结果的起始位置,取值为正整数。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [RdbPredicates](#rdbpredicates) | 返回具有指定返回结果起始位置的谓词。 | - -- 示例: - ``` - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.equalTo("NAME", "Rose").offsetAs(3) - ``` - - -### groupBy - -groupBy(fields: Array<string>): RdbPredicates - - -配置RdbPredicates按指定列分组查询结果。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | fields | Array<string> | 是 | 指定分组依赖的列名。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [RdbPredicates](#rdbpredicates) | 返回分组查询列的谓词。 | - -- 示例: - ``` - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.groupBy(["AGE", "NAME"]) - ``` - - -### indexedBy - -indexedBy(indexName: string): RdbPredicates - - -配置RdbPredicates以指定索引列。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | indexName | string | 是 | 索引列的名称。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [RdbPredicates](#rdbpredicates) | 返回具有指定索引列的RdbPredicates。 | - -- 示例: - ``` - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.indexedBy("SALARY_INDEX") - ``` - - -### in - -in(field: string, value: Array<ValueType>): RdbPredicates - - -配置RdbPredicates以匹配数据字段为ValueType数组且值在给定范围内的指定字段。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | field | string | 是 | 数据库表中的列名。 | - | value | Array<[ValueType](#valuetype)> | 是 | 以ValueType型数组形式指定的要匹配的值。 | - - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | - -- 示例: - ``` - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.in("AGE", [18, 20]) - ``` - - -### notIn - -notIn(field: string, value: Array<ValueType>): RdbPredicates - - -将RdbPredicates配置为匹配数据字段为ValueType且值超出给定范围的指定字段。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | field | string | 是 | 数据库表中的列名。 | - | value | Array<[ValueType](#valuetype)> | 是 | 以ValueType数组形式指定的要匹配的值。 | - - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | - -- 示例: - ``` - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.notIn("NAME", ["Lisa", "Rose"]) - ``` - - -## RdbStore - -提供管理关系数据库(RDB)方法的接口。 - - -### insert - -insert(name: string, values: ValuesBucket, callback: AsyncCallback<number>):void - -向目标表中插入一行数据,结果以callback形式返回。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | name | string | 是 | 指定的目标表名。 | - | values | [ValuesBucket](#valuesbucket) | 是 | 表示要插入到表中的数据行。 | - | callback | AsyncCallback<number> | 是 | 指定callback回调函数。如果操作成功,返回行ID;否则返回-1。 | - -- 示例: - ``` - const valueBucket = { - "NAME": "Lisa", - "AGE": 18, - "SALARY": 100.5, - "CODES": new Uint8Array([1, 2, 3, 4, 5]), - } - rdbStore.insert("EMPLOYEE", valueBucket, function (err, ret) { - expect(1).assertEqual(ret) - console.log(TAG + "insert first done: " + ret)}) - ``` - - -### insert - -insert(name: string, values: ValuesBucket):Promise<number> - -向目标表中插入一行数据,结果以Promise形式返回。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | name | string | 是 | 指定的目标表名。 | - | values | [ValuesBucket](#valuesbucket) | 是 | 表示要插入到表中的数据行。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<number> | 指定Promise回调函数。如果操作成功,返回行ID;否则返回-1。 | - -- 示例: - ``` - const valueBucket = { - "NAME": "Lisa", - "AGE": 18, - "SALARY": 100.5, - "CODES": new Uint8Array([1, 2, 3, 4, 5]), - } - let promise = rdbStore.insert("EMPLOYEE", valueBucket) - promise.then(async (ret) => { - await console.log(TAG + "insert first done: " + ret) - }).catch((err) => {}) - ``` - - -### update - -update(values: ValuesBucket, rdbPredicates: RdbPredicates, callback: AsyncCallback<number>):void - -根据RdbPredicates的指定实例对象更新数据库中的数据,结果以callback形式返回。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | values | [ValuesBucket](#valuesbucket) | 是 | value指示数据库中要更新的数据行。键值对与数据库表的列名相关联 | - | rdbPredicates | [RdbPredicates](#rdbpredicates) | 是 | 表示要插入到表中的数据行。 | - | callback | AsyncCallback<number> | 是 | 指定的callback回调方法。返回受影响的行数。 | - -- 示例: - ``` - const valueBucket = { - "NAME": "Rose", - "AGE": 22, - "SALARY": 200.5, - "CODES": new Uint8Array([1, 2, 3, 4, 5]), - } - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.equalTo("NAME", "Lisa") - rdbStore.update(valueBucket, predicates, function (err, ret) { - console.log(TAG + "updated row count: " + changedRows)}) - ``` - - -### update - -update(values: ValuesBucket, rdbPredicates: RdbPredicates):Promise<number> - -根据RdbPredicates的指定实例对象更新数据库中的数据,结果以Promise形式返回。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | values | [ValuesBucket](#valuesbucket) | 是 | value指示数据库中要更新的数据行。键值对与数据库表的列名相关联 | - | rdbPredicates | [RdbPredicates](#rdbpredicates) | 是 | 表示要插入到表中的数据行。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<number> | 指定的Promise回调方法。返回受影响的行数。 | - -- 示例: - ``` - const valueBucket = { - "NAME": "Rose", - "AGE": 22, - "SALARY": 200.5, - "CODES": new Uint8Array([1, 2, 3, 4, 5]), - } - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.equalTo("NAME", "Lisa") - let promise = rdbStore.update(valueBucket, predicates) - promise.then(async (ret) => { - await console.log(TAG + "updated row count: " + changedRows) - }).catch((err) => {}) - ``` - - -### delete - -delete(rdbPredicates: RdbPredicates, callback: AsyncCallback<number>):void - - -根据rdbPredicates的指定实例对象从数据库中删除数据,结果以callback形式返回。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | rdbPredicates | [RdbPredicates](#rdbpredicates) | 是 | RdbPredicates的实例对象指定的删除条件。 | - | callback | AsyncCallback<number> | 是 | 指定callback回调函数。返回受影响的行数。 | - -- 示例: - ``` - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.equalTo("NAME", "Lisa") - rdbStore.delete(predicates, function (err, rows) { - console.log(TAG + "delete rows: " + rows)}) - ``` - - -### delete - -delete(rdbPredicates: RdbPredicates):Promise<number> - -根据rdbPredicates的指定实例对象从数据库中删除数据,结果以Promise形式返回。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | rdbPredicates | [RdbPredicates](#rdbpredicates) | 是 | RdbPredicates的实例对象指定的删除条件。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<number> | 指定Promise回调函数。返回受影响的行数。 | - -- 示例: - ``` - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.equalTo("NAME", "Lisa") - let promise = rdbStore.delete(predicates) - promise.then((rows) => { - console.log(TAG + "delete rows: " + rows) - }).catch((err) => {}) - ``` - - -### query - -query(rdbPredicates: RdbPredicates, columns: Array<string>, callback: AsyncCallback<ResultSet>):void - -根据指定条件查询数据库中的数据,结果以callback形式返回。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | rdbPredicates | [RdbPredicates](#rdbpredicates) | 是 | 表示rdbPredicates的实例对象指定的查询条件。 | - | columns | Array<string> | 是 | 表示要查询的列。如果值为空,则查询应用于所有列。 | - | callback | AsyncCallback<[ResultSet](/pages/010c010504)> | 是 | 指定callback回调函数。如果操作成功,则返回ResultSet对象。 | - -- 示例: - ``` - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.equalTo("NAME", "Rose") - rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], function (err, resultSet) { - console.log(TAG + "resultSet column names:" + resultSet.columnNames) - console.log(TAG + "resultSet column count:" + resultSet.columnCount)}) - ``` - - -### query - -query(rdbPredicates: RdbPredicates, columns?: Array<string>):Promise<ResultSet> - -根据指定条件查询数据库中的数据,结果以Promise形式返回。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | rdbPredicates | [RdbPredicates](#rdbpredicates) | 是 | 表示rdbPredicates的实例对象指定的查询条件。 | - | columns | Array<string> | 否 | 表示要查询的列。如果值为空,则查询应用于所有列。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<[ResultSet](/pages/010c010504)> | 指定Promise回调函数。如果操作成功,则返回ResultSet对象。 | - -- 示例: - ``` - let predicates = new data_rdb.RdbPredicates("EMPLOYEE") - predicates.equalTo("NAME", "Rose") - let promise = rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]) - promise.then((resultSet) => { - console.log(TAG + "resultSet column names:" + resultSet.columnNames) - console.log(TAG + "resultSet column count:" + resultSet.columnCount)}) - ``` - - -### querySql8+ - -querySql(sql: string, bindArgs: Array<ValueType>, callback: AsyncCallback<ResultSet>):void - -根据指定SQL语句查询数据库中的数据,结果以callback形式返回。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | sql | string | 是 | 指定要执行的SQL语句。 | - | bindArgs | Array<[ValueType](#valuetype)> | 是 | SQL语句中参数的值。 | - | callback | AsyncCallback<[ResultSet](/pages/010c010504)> | 是 | 指定callback回调函数。如果操作成功,则返回ResultSet对象。 | - -- 示例: - ``` - rdbStore.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'], function (err, resultSet) { - console.log(TAG + "resultSet column names:" + resultSet.columnNames) - console.log(TAG + "resultSet column count:" + resultSet.columnCount)}) - ``` - - -### querySql8+ - -querySql(sql: string, bindArgs?: Array<ValueType>):Promise<ResultSet> - -根据指定SQL语句查询数据库中的数据,结果以Promise形式返回。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | sql | string | 是 | 指定要执行的SQL语句。 | - | bindArgs | Array<[ValueType](#valuetype)> | 否 | SQL语句中参数的值。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<[ResultSet](/pages/010c010504)> | 指定Promise回调函数。如果操作成功,则返回ResultSet对象。 | - -- 示例: - ``` - let promise = rdbStore.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo']) - promise.then((resultSet) => { - console.log(TAG + "resultSet column names:" + resultSet.columnNames) - console.log(TAG + "resultSet column count:" + resultSet.columnCount)}) - ``` - - -### executeSql - -executeSql(sql: string, bindArgs: Array<ValueType>, callback: AsyncCallback<void>):void - -执行包含指定参数但不返回值的SQL语句,结果以callbck形式返回。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | sql | string | 是 | 指定要执行的SQL语句。 | - | bindArgs | Array<[ValueType](#valuetype)> | 是 | SQL语句中参数的值。 | - | callback | AsyncCallback<void> | 是 | 指定callback回调函数。 | - -- 示例: - ``` - rdbStore.executeSql("DELETE FROM EMPLOYEE", null, function () { - console.info(TAG + 'delete done.')}) - ``` - - -### executeSql - -executeSql(sql: string, bindArgs?: Array<ValueType>):Promise<void> - -执行包含指定参数但不返回值的SQL语句,结果以Promise形式返回。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | sql | string | 是 | 指定要执行的SQL语句。 | - | bindArgs | Array<[ValueType](#valuetype)> | 否 | SQL语句中参数的值。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | 指定Promise回调函数。 | - -- 示例: - ``` - let promise = rdbStore.executeSql("DELETE FROM EMPLOYEE") - promise.then(() => { - console.info(TAG + 'delete done.')}) - ``` -## StoreConfig - -管理关系数据库配置。 - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| name | string | 是 | 数据库文件名。 | - - -## ValueType - -用于表示允许的数据字段类型。 - -| 名称 | 说明 | -| -------- | -------- | -| number | 表示值类型为数字。 | -| string | 表示值类型为字符。 | -| boolean | 表示值类型为布尔值。| - - -## ValuesBucket - -用于存储键值对。 - - -| 名称 | 参数类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| [key: string] | [ValueType](#valuetype)\| Uint8Array \| null | 是 | 用于存储键值对。 | diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/05.\346\225\260\346\215\256\347\256\241\347\220\206/04.\347\273\223\346\236\234\351\233\206.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/05.\346\225\260\346\215\256\347\256\241\347\220\206/04.\347\273\223\346\236\234\351\233\206.md" deleted file mode 100644 index 66500f1fd7060c1a7d213f8e7eb6b7a0f8fea14f..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/05.\346\225\260\346\215\256\347\256\241\347\220\206/04.\347\273\223\346\236\234\351\233\206.md" +++ /dev/null @@ -1,372 +0,0 @@ ---- -title: 结果集 -permalink: /pages/010c010504 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 结果集 - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 使用说明 - -需要通过[RdbStore.query()](/pages/010c010503#query)获取resultSet对象。 - -``` -import dataRdb from '@ohos.data.rdb'; -let predicates = new dataRdb.RdbPredicates("EMPLOYEE") -predicates.equalTo("AGE", 18) -let promise = rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]) -promise.then((resultSet) => { - await console.log(TAG + "resultSet columnNames:" + resultSet.columnNames); - await console.log(TAG + "resultSet columnCount:" + resultSet.columnCount);}) -``` - - -## 权限 - -无 - - -## ResultSet - -提供通过查询数据库生成的数据库结果集的访问方法。 - - -### 属性 - - -| 名称 | 参数类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| columnNames | Array<string> | 是 | 获取结果集中所有列的名称。 | -| columnCount | number | 是 | 获取结果集中的列数。 | -| rowCount | number | 是 | 获取结果集中的行数。 | -| rowIndex | number | 是 | 获取结果集当前行的索引。 | -| isAtFirstRow | boolean | 是 | 检查结果集是否位于第一行。 | -| isAtLastRow | boolean | 是 | 检查结果集是否位于最后一行。 | -| isEnded | boolean | 是 | 检查结果集是否位于最后一行之后。 | -| isStarted | boolean | 是 | 检查指针是否移动过。 | -| isClosed | boolean | 是 | 检查当前结果集是否关闭。 | - - -### getColumnIndex - -getColumnIndex(columnName: string): number - -根据指定的列名获取列索引。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | columnName | string | 是 | 表示结果集中指定列的名称。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 返回指定列的索引。 | - -- 示例: - ``` - resultSet.goToFirstRow() - const id = resultSet.getLong(resultSet.getColumnIndex("ID")) - const name = resultSet.getString(resultSet.getColumnIndex("NAME")) - const age = resultSet.getLong(resultSet.getColumnIndex("AGE")) - const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")) - ``` - - -### getColumnName - -getColumnName(columnIndex: number): string - -根据指定的列索引获取列名。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | columnIndex | number | 是 | 表示结果集中指定列的索引。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string | 返回指定列的名称。 | - -- 示例: - ``` - const id = resultSet.getColumnName(0) - const name = resultSet.getColumnName(1) - const age = resultSet.getColumnName(2) - ``` - - -### goTo - -goTo(offset:number): boolean - -向前或向后转至结果集的指定行,相对于其当前位置偏移。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | offset | number | 是 | 表示相对于当前位置的偏移量。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 如果成功移动结果集,则为true;否则返回false。 | - -- 示例: - ``` - let predicates = new dataRdb.RdbPredicates("EMPLOYEE") - let resultSet = await rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]) - resultSet.goTo(1) - resultSet.close() - resultSet = null - ``` - - -### goToRow - -goToRow(position: number): boolean - -转到结果集的指定行。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | position | number | 是 | 表示要移动到的指定位置。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 如果成功移动结果集,则为true;否则返回false。 | - -- 示例: - ``` - let predicates = new dataRdb.RdbPredicates("EMPLOYEE") - let resultSet = await rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]) - resultSet.goToRow(1) - resultSet.close() - resultSet = null - ``` - - -### goToFirstRow - -goToFirstRow(): boolean - - -转到结果集的第一行。 - - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 如果成功移动结果集,则为true;否则返回false。 | - -- 示例: - ``` - let predicates = new dataRdb.RdbPredicates("EMPLOYEE") - let resultSet = await rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]) - resultSet.goToFirstRow() - resultSet.close() - resultSet = null; - ``` - - -### goToLastRow - -goToLastRow(): boolean - -转到结果集的最后一行。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 如果成功移动结果集,则为true;否则返回false。 | - -- 示例: - ``` - let predicates = new dataRdb.RdbPredicates("EMPLOYEE") - let resultSet = await rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]) - resultSet.goToLastRow() - resultSet.close() - resultSet = null; - ``` - - -### goToNextRow - -goToNextRow(): boolean - -转到结果集的下一行。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 如果成功移动结果集,则为true;否则返回false。 | - -- 示例: - ``` - let predicates = new dataRdb.RdbPredicates("EMPLOYEE") - let resultSet = await rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]) - resultSet.goToNextRow() - resultSet.close() - resultSet = null; - ``` - - -### goToPreviousRow - -goToPreviousRow(): boolean - -转到结果集的上一行。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 如果成功移动结果集,则为true;否则返回false。 | - -- 示例: - ``` - let predicates = new dataRdb.RdbPredicates("EMPLOYEE") - let resultSet = await rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]) - resultSet.goToPreviousRow() - resultSet.close() - resultSet = null - ``` - - -### getBlob - -getBlob(columnIndex: number): Uint8Array - -以字节数组的形式获取当前行中指定列的值。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | columnIndex | number | 是 | 指定的列索引,从0开始。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Uint8Array | 以字节数组的形式返回指定列的值。 | - -- 示例: - ``` - const codes = resultSet.getBlob(resultSet.getColumnIndex("CODES")) - ``` - - -### getString - -getString(columnIndex: number): string - -以字符串形式获取当前行中指定列的值。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | columnIndex | number | 是 | 指定的列索引,从0开始。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string | 以字符串形式返回指定列的值。 | - -- 示例: - ``` - const name = resultSet.getString(resultSet.getColumnIndex("NAME")) - ``` - - -### getLong - -getLong(columnIndex: number): number - -以Long形式获取当前行中指定列的值。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | columnIndex | number | 是 | 指定的列索引,从0开始。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 以Long形式返回指定列的值。 | - -- 示例: - ``` - const age = resultSet.getLong(resultSet.getColumnIndex("AGE")) - ``` - - -### getDouble - -getDouble(columnIndex: number): number - -以double形式获取当前行中指定列的值。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | columnIndex | number | 是 | 指定的列索引,从0开始。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 以double形式返回指定列的值。 | - -- 示例: - ``` - const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")) - ``` - - -### isColumnNull - -isColumnNull(columnIndex: number): boolean - -检查当前行中指定列的值是否为null。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | columnIndex | number | 是 | 指定的列索引,从0开始。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 如果当前行中指定列的值为null,则返回true,否则返回false。 | - -- 示例: - ``` - const isColumnNull = resultSet.isColumnNull(resultSet.getColumnIndex("CODES")) - ``` - - -### close - -close(): void - -关闭结果集。 - - -- 示例: - ``` - let predicates = new dataRdb.RdbPredicates("EMPLOYEE") - let resultSet = await rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]) - resultSet.close() - resultSet = null - ``` diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/05.\346\225\260\346\215\256\347\256\241\347\220\206/05.DataAbility\350\260\223\350\257\215.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/05.\346\225\260\346\215\256\347\256\241\347\220\206/05.DataAbility\350\260\223\350\257\215.md" deleted file mode 100644 index 7fbbb3d20837c8036b654793557b6c2a7afd18cd..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/05.\346\225\260\346\215\256\347\256\241\347\220\206/05.DataAbility\350\260\223\350\257\215.md" +++ /dev/null @@ -1,800 +0,0 @@ ---- -title: DataAbility谓词 -permalink: /pages/010c010505 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# DataAbility 谓词 - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import dataAbility from '@ohos.data.dataAbility' -``` - - -## 权限 - -无 - - -## dataAbility.createRdbPredicates - - -createRdbPredicates(name: string, dataAbilityPredicates: DataAbilityPredicates): rdb.RdbPredicates - - -从DataAabilityPredicates对象创建RdbPredicates对象。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | name | string | 是 | 数据库表中表名。 | - | dataAbilityPredicates | [DataAbilityPredicates](#dataabilitypredicates) | 是 | dataAbility谓词。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | rdb.[RdbPredicates](/pages/010c010503#rdbpredicates) | 返回RdbPredicates对象。 | - -- 示例: - ``` - let dataAbilityPredicates = new dataAbility.DataAbilityPredicates() - dataAbilityPredicates.equalTo("NAME", "Rose").between("AGE", 16, 30) - let predicates = dataAbility.createRdbPredicates("EMPLOYEE", dataAbilityPredicates) - ``` - - -## DataAbilityPredicates - -提供用于实现不同查询方法的谓词。 - - -### equalTo - - -equalTo(field: string, value: ValueType): DataAbilityPredicates - - -配置谓词以匹配数据类型为ValueType且值等于指定值的字段。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | field | string | 是 | 数据库表中的列名。 | - | value | [ValueType](/pages/010c010503#valuetype) | 是 | 指示要与谓词匹配的值。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [DataAbilityPredicates](#dataabilitypredicates) | 返回与指定字段匹配的谓词。 | - -- 示例: - ``` - let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") - predicates.equalTo("NAME", "lisi") - ``` - - -### notEqualTo - - -notEqualTo(field: string, value: ValueType): DataAbilityPredicates - - -配置谓词以匹配数据类型为ValueType且值不等于指定值的字段。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | field | string | 是 | 数据库表中的列名。 | - | value | [ValueType](/pages/010c010503#valuetype) | 是 | 指示要与谓词匹配的值。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [DataAbilityPredicates](#dataabilitypredicates) | 返回与指定字段匹配的谓词。 | - -- 示例: - ``` - let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") - predicates.notEqualTo("NAME", "lisi") - ``` - - -### beginWrap - - -beginWrap(): DataAbilityPredicates - - -向谓词添加左括号。 - - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [DataAbilityPredicates](#dataabilitypredicates) | 返回带有左括号的DataAbility谓词。 | - -- 示例: - ``` - let predicates = new dataAbilitylity.DataAbilityPredicates("EMPLOYEE") - predicates.equalTo("NAME", "lisi") - .beginWrap() - .equalTo("AGE", 18) - .or() - .equalTo("SALARY", 200.5) - .endWrap() - ``` - - -### endWrap - - -endWrap(): DataAbilityPredicates - - -向谓词添加右括号。 - - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [DataAbilityPredicates](#dataabilitypredicates) | 返回带有右括号的DataAbility谓词。 | - -- 示例: - ``` - let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") - predicates.equalTo("NAME", "lisi") - .beginWrap() - .equalTo("AGE", 18) - .or() - .equalTo("SALARY", 200.5) - .endWrap() - ``` - - -### or - - -or(): DataAbilityPredicates - - -将或条件添加到谓词中。 - - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [DataAbilityPredicates](#dataabilitypredicates) | 返回带有或条件的DataAbility谓词。 | - -- 示例: - ``` - let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") - predicates.equalTo("NAME", "Lisa") - .or() - .equalTo("NAME", "Rose") - ``` - - -### and - - -and(): DataAbilityPredicates - - -向谓词添加和条件。 - - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [DataAbilityPredicates](#dataabilitypredicates) | 返回带有和条件的DataAbility谓词。 | - -- 示例: - ``` - let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") - predicates.equalTo("NAME", "Lisa") - .and() - .equalTo("SALARY", 200.5) - ``` - - -### contains - - -contains(field: string, value: string): DataAbilityPredicates - - -配置谓词以匹配数据类型为String且value包含指定值的字段。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | field | string | 是 | 数据库表中的列名。 | - | value | string | 是 | 指示要与谓词匹配的值。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [DataAbilityPredicates](#dataabilitypredicates) | 返回与指定字段匹配的谓词。 | - -- 示例: - ``` - let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") - predicates.contains("NAME", "os") - ``` - - -### beginsWith - - -beginsWith(field: string, value: string): DataAbilityPredicates - - -配置谓词以匹配数据类型为String且值以指定字符串开头的字段。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | field | string | 是 | 数据库表中的列名。 | - | value | string | 是 | 指示要与谓词匹配的值。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [DataAbilityPredicates](#dataabilitypredicates) | 返回与指定字段匹配的谓词。 | - -- 示例: - ``` - let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") - predicates.beginsWith("NAME", "os") - ``` - - -### endsWith - - -endsWith(field: string, value: string): DataAbilityPredicates - - -配置谓词以匹配数据类型为String且值以指定字符串结尾的字段。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | field | string | 是 | 数据库表中的列名。 | - | value | string | 是 | 指示要与谓词匹配的值。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [DataAbilityPredicates](#dataabilitypredicates) | 返回与指定字段匹配的谓词。 | - -- 示例: - ``` - let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") - predicates.endsWith("NAME", "se") - ``` - - -### isNull - - -isNull(field: string): DataAbilityPredicates - - -配置谓词以匹配值为null的字段。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | field | string | 是 | 数据库表中的列名。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [DataAbilityPredicates](#dataabilitypredicates) | 返回与指定字段匹配的谓词。 | - -- 示例: - ``` - let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") - predicates.isNull("NAME") - ``` - - -### isNotNull - - -isNotNull(field: string): DataAbilityPredicates - - -配置谓词以匹配值不为null的指定字段。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | field | string | 是 | 数据库表中的列名。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [DataAbilityPredicates](#dataabilitypredicates) | 返回与指定字段匹配的谓词。 | - -- 示例: - ``` - let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") - predicates.isNotNull("NAME") - ``` - - -### like - - -like(field: string, value: string): DataAbilityPredicates - - -配置谓词以匹配数据类型为string且值类似于指定字符串的字段。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | field | string | 是 | 数据库表中的列名。 | - | value | string | 是 | 指示要与谓词匹配的值。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [DataAbilityPredicates](#dataabilitypredicates) | 返回与指定字段匹配的谓词。 | - -- 示例: - ``` - let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") - predicates.like("NAME", "%os%") - ``` - - -### glob - - -glob(field: string, value: string): DataAbilityPredicates - - -配置谓词匹配数据类型为string的指定字段。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | field | string | 是 | 数据库表中的列名。 | - | value | string | 是 | 指示要与谓词匹配的值。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [DataAbilityPredicates](#dataabilitypredicates) | 返回与指定字段匹配的谓词。 | - -- 示例: - ``` - let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") - predicates.glob("NAME", "?h*g") - ``` - - -### between - - -between(field: string, low: ValueType, high: ValueType): DataAbilityPredicates - - -将谓词配置为匹配数据类型为ValueType且value在指定范围内的指定字段。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | field | string | 是 | 数据库表中的列名。 | - | low | [ValueType](/pages/010c010503#valuetype) | 是 | 指示与谓词匹配的最小值。 | - | high | [ValueType](/pages/010c010503#valuetype) | 是 | 指示与谓词匹配的最大值。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [DataAbilityPredicates](#dataabilitypredicates) | 返回与指定字段匹配的谓词。 | - -- 示例: - ``` - let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") - predicates.between("AGE", 10, 50) - ``` - - -### notBetween - - -notBetween(field: string, low: ValueType, high: ValueType): DataAbilityPredicates - - -配置谓词以匹配数据类型为ValueType且value超出给定范围的指定字段。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | field | string | 是 | 数据库表中的列名。 | - | low | [ValueType](/pages/010c010503#valuetype) | 是 | 指示与谓词匹配的最小值。 | - | high | [ValueType](/pages/010c010503#valuetype) | 是 | 指示与谓词匹配的最大值。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [DataAbilityPredicates](#dataabilitypredicates) | 返回与指定字段匹配的谓词。 | - -- 示例: - ``` - let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") - predicates.notBetween("AGE", 10, 50) - ``` - - -### greaterThan - - -greaterThan(field: string, value: ValueType): DataAbilityPredicates - - -配置谓词以匹配数据类型为ValueType且值大于指定值的字段。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | field | string | 是 | 数据库表中的列名。 | - | value | [ValueType](/pages/010c010503#valuetype) | 是 | 指示要与谓词匹配的值。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [DataAbilityPredicates](#dataabilitypredicates) | 返回与指定字段匹配的谓词。 | - -- 示例: - ``` - let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") - predicates.greaterThan("AGE", 18) - ``` - - -### lessThan - - -lessThan(field: string, value: ValueType): DataAbilityPredicates - - -配置谓词以匹配数据类型为valueType且value小于指定值的字段。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | field | string | 是 | 数据库表中的列名。 | - | value | [ValueType](/pages/010c010503#valuetype) | 是 | 指示要与谓词匹配的值。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [DataAbilityPredicates](#dataabilitypredicates) | 返回与指定字段匹配的谓词。 | - -- 示例: - ``` - let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") - predicates.lessThan("AGE", 20) - ``` - - -### greaterThanOrEqualTo - - -greaterThanOrEqualTo(field: string, value: ValueType): DataAbilityPredicates - - -配置谓词以匹配数据类型为ValueType且value大于或等于指定值的字段。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | field | string | 是 | 数据库表中的列名。 | - | value | [ValueType](/pages/010c010503#valuetype) | 是 | 指示要与谓词匹配的值。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [DataAbilityPredicates](#dataabilitypredicates) | 返回与指定字段匹配的谓词。 | - -- 示例: - ``` - let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") - predicates.greaterThanOrEqualTo("AGE", 18) - ``` - - -### lessThanOrEqualTo - - -lessThanOrEqualTo(field: string, value: ValueType): DataAbilityPredicates - - -配置谓词以匹配数据类型为ValueType且value小于或等于指定值的字段。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | field | string | 是 | 数据库表中的列名。 | - | value | [ValueType](/pages/010c010503#valuetype) | 是 | 指示要与谓词匹配的值。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [DataAbilityPredicates](#dataabilitypredicates) | 返回与指定字段匹配的谓词。 | - -- 示例: - ``` - let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") - predicates.lessThanOrEqualTo("AGE", 20) - ``` - - -### orderByAsc - - -orderByAsc(field: string): DataAbilityPredicates - - -配置谓词以匹配其值按升序排序的列。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | field | string | 是 | 数据库表中的列名。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [DataAbilityPredicates](#dataabilitypredicates) | 返回与指定字段匹配的谓词。 | - -- 示例: - ``` - let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") - predicates.orderByAsc("NAME") - ``` - - -### orderByDesc - - -orderByDesc(field: string): DataAbilityPredicates - - -配置谓词以匹配其值按降序排序的列。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | field | string | 是 | 数据库表中的列名。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [DataAbilityPredicates](#dataabilitypredicates) | 返回与指定字段匹配的谓词。 | - -- 示例: - ``` - let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") - predicates.orderByDesc("AGE") - ``` - - -### distinct - - -distinct(): DataAbilityPredicates - - -配置谓词以过滤重复记录并仅保留其中一个。 - - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [DataAbilityPredicates](#dataabilitypredicates) | 返回可用于过滤重复记录的谓词。 | - -- 示例: - ``` - let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") - predicates.equalTo("NAME", "Rose").distinct("NAME") - let resultSet = await rdbStore.query(predicates, ["NAME"]) - ``` - - -### limitAs - - -limitAs(value: number): DataAbilityPredicates - - -设置最大数据记录数的谓词。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | number | 是 | 最大数据记录数。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [DataAbilityPredicates](#dataabilitypredicates) | 返回可用于设置最大数据记录数的谓词。 | - -- 示例: - ``` - let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") - predicates.equalTo("NAME", "Rose").limitAs(3) - ``` - - -### offsetAs - - -offsetAs(rowOffset: number): DataAbilityPredicates - - -配置谓词以指定返回结果的起始位置。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | rowOffset | number | 是 | 返回结果的起始位置,取值为正整数。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [DataAbilityPredicates](#dataabilitypredicates) | 返回具有指定返回结果起始位置的谓词。 | - -- 示例: - ``` - let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") - predicates.equalTo("NAME", "Rose").offsetAs(3) - ``` - - -### groupBy - - -groupBy(fields: Array<string>): DataAbilityPredicates - - -配置谓词按指定列分组查询结果。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | fields | Array<string> | 是 | 指定分组依赖的列名。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [DataAbilityPredicates](#dataabilitypredicates) | 返回分组查询列的谓词。 | - -- 示例: - ``` - let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") - predicates.groupBy(["AGE", "NAME"]) - ``` - - -### indexedBy - - -indexedBy(indexName: string): DataAbilityPredicates - - -配置谓词以指定索引列。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | indexName | string | 是 | 索引列的名称。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [DataAbilityPredicates](#dataabilitypredicates) | 返回具有指定索引列的谓词。 | - -- 示例: - ``` - let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") - predicates.indexedBy("SALARY_INDEX") - ``` - - -### in - - -in(field: string, value: Array<ValueType>): DataAbilityPredicates - - -配置谓词以匹配数据类型为ValueType数组且值在给定范围内的指定字段。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | field | string | 是 | 数据库表中的列名。 | - | value | Array<[ValueType](/pages/010c010503#valuetype)> | 是 | 以ValueType型数组形式指定的要匹配的值。 | - - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [DataAbilityPredicates](#dataabilitypredicates) | 返回与指定字段匹配的谓词。 | - -- 示例: - ``` - let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") - predicates.in("AGE", [18, 20]) - ``` - - -### notIn - - -notIn(field: string, value: Array<ValueType>): DataAbilityPredicates - - -配置谓词以匹配数据类型为ValueType数组且值不在给定范围内的指定字段。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | field | string | 是 | 数据库表中的列名。 | - | value | Array<[ValueType](/pages/010c010503#valuetype)> | 是 | 以ValueType型数组形式指定的要匹配的值。 | - - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [DataAbilityPredicates](#dataabilitypredicates) | 返回与指定字段匹配的谓词。 | - -- 示例: - ``` - let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") - predicates.notIn("NAME", ["Lisa", "Rose"]) - ``` - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/05.\346\225\260\346\215\256\347\256\241\347\220\206/06.\350\256\276\347\275\256\346\225\260\346\215\256\351\241\271\345\220\215\347\247\260.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/05.\346\225\260\346\215\256\347\256\241\347\220\206/06.\350\256\276\347\275\256\346\225\260\346\215\256\351\241\271\345\220\215\347\247\260.md" deleted file mode 100644 index d02a00144db5b64a6742622f07e5dba88c5eb4c4..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/05.\346\225\260\346\215\256\347\256\241\347\220\206/06.\350\256\276\347\275\256\346\225\260\346\215\256\351\241\271\345\220\215\347\247\260.md" +++ /dev/null @@ -1,118 +0,0 @@ ---- -title: 设置数据项名称 -permalink: /pages/010c010506 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 设置数据项名称 - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - - -本模块提供设置数据项的访问功能相关接口的说明及示例。 - - -## 导入模块 - -``` -import settings from '@ohos.settings'; -``` - - -## 权限 - -无 - - -## settings.getUri - -getUri(name: string): string - -获取数据项的URI。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | name | string | 是 | 数据项的名称。数据项名称分为以下两种:
  • 数据库中已存在的数据项,包括:
    • 亮度:'settings.screen.brightness'
    • 时间格式:'settings.time.format'
  • 开发者自行添加的数据项。
| - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string | 数据项的URI。 | - -- 示例: - ``` - // 获取数据项的URI - let urivar = settings.getUri('settings.screen.brightness'); - ``` - - -## settings.getValue - -getValue(dataAbilityHelper: DataAbilityHelper, name: string, defValue: string): string - -获取数据项的值。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | dataAbilityHelper | [DataAbilityHelper](/pages/010c010103) | 是 | 数据管理辅助类。 | - | name | string | 是 | 数据项的名称。数据项名称分为以下两种:
  • 数据库中已存在的数据项,包括:
    • 亮度:'settings.screen.brightness'
    • 时间格式:'settings.time.format'
  • 开发者自行添加的数据项。
| - | defValue | string | 是 | 默认值。由开发者设置,当未从数据库中查询到该数据时,则返回该默认值。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string | 返回数据项的值。 | - -- 示例: - ``` - import featureAbility from '@ohos.featureAbility'; - - //获取数据项亮度的值(该数据项在数据库中已存在) - let brightness = 'settings.screen.brightness'; - let uri = settings.getUri(brightness); - let helper = featureAbility.acquireDataAbilityHelper(uri); - let value = settings.getValue(helper, brightness, '10'); - ``` - - -## settings.setValue - -setValue(dataAbilityHelper: DataAbilityHelper, name: string, value: string): boolean - -设置数据项的值。 -如果数据库中已经存在该数据项,则setValue方法将更新该数据项的值;如果数据库中尚未存在该数据项,则setValue方法将向数据库中插入该数据项。 - -使用此方法需获取ohos.permission.WRITE_SYSTEM_SETTING权限。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | dataAbilityHelper | [DataAbilityHelper](/pages/010c010103) | 是 | 数据管理辅助类。 | - | name | string | 是 | 数据项的名称。数据项名称分为以下两种:
  • 数据库中已存在的数据项,包括:
    • 亮度:'settings.screen.brightness'
    • 时间格式:'settings.time.format'
  • 开发者自行添加的数据项。
| - | value | string | 是 | 数据项的具体数值。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 返回设置数据项的值是否成功的结果。true表示设置成功,false则表示设置失败。 | - -- 示例: - ``` - import featureAbility from '@ohos.featureAbility'; - - //更新数据项亮度的值(该数据项在数据库中已存在,故setValue方法将更新该数据项的值) - let brightness = 'settings.screen.brightness'; - let uri = settings.getUri(brightness); - let helper = featureAbility.acquireDataAbilityHelper(uri); - let ret = settings.setValue(helper, brightness, '100'); - ``` diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/06.\346\226\207\344\273\266\347\256\241\347\220\206/01.\346\226\207\344\273\266\347\256\241\347\220\206.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/06.\346\226\207\344\273\266\347\256\241\347\220\206/01.\346\226\207\344\273\266\347\256\241\347\220\206.md" deleted file mode 100644 index 2d0012ce49c5c9868f3b309d98a0b6c59cb0a2e0..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/06.\346\226\207\344\273\266\347\256\241\347\220\206/01.\346\226\207\344\273\266\347\256\241\347\220\206.md" +++ /dev/null @@ -1,2717 +0,0 @@ ---- -title: 文件管理 -permalink: /pages/010c010601 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 文件管理 - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - -## 导入模块 - -``` -import fileio from '@ohos.fileio'; -``` - - -## 权限列表 - -无 - - -## 使用说明 - -使用该功能模块对文件/目录进行操作前,需要先获取其绝对路径,获取方式及其接口用法请参考:[Context模块的接口getOrCreateLocalDir](/pages/010c010108)。 - -“文件/目录绝对路径”=“应用目录路径”+“文件/目录名” - -通过上述接口获取到应用目录路径dir,文件名为“xxx.txt”,文件所在绝对路径为: - -``` -let path = dir + "/xxx.txt"; -``` - - -文件描述符fd: - - -``` -let fd = fileio.openSync(path); -``` - - -## fileio.stat - -stat(path: string): Promise<Stat> - -以异步方法获取文件信息,使用promise形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 待获取文件的绝对路径。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<[Stat](#stat)> | 表示文件的具体信息。 | - -- 示例: - ``` - let stat = await fileio.stat(path); - // example code in Stat - ``` - - -## fileio.stat - -stat(path:string, callback:AsyncCallback<Stat>): void - -以异步方法获取文件信息,使用callback形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 待获取文件的绝对路径。 | - | callback | AsyncCallback<[Stat](#stat)> | 是 | 异步获取文件的信息之后的回调。 | - -- 示例: - ``` - fileio.stat(path, function (err, stat) { - // example code in Stat - }); - ``` - - -## fileio.statSync - -statSync(path:string): Stat - -以同步方法获取文件的信息。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 待获取文件的绝对路径。 | - - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [Stat](#stat) | 表示文件的具体信息。 | - -- 示例: - ``` - let stat = fileio.statSync(path); - // example code in Stat - ``` - - -## fileio.opendir - -opendir(path: string): Promise<Dir> - -以异步方法打开文件目录,使用promise形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 待打开文件目录的绝对路径。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<[Dir](#dir)> | 返回Dir对象。 | - -- 示例: - ``` - let dir = fileio.opendir(path); - // example code in Dir - ``` - - -## fileio.opendir - -opendir(path: string, callback: AsyncCallback<Dir>): void - -以异步方法打开文件目录,使用callback形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 待打开文件目录的绝对路径。 | - | callback | AsyncCallback<[Dir](#dir)> | 是 | 异步打开文件目录之后的回调。 | - -- 示例: - ``` - fileio.opendir(path, function (err, dir) { - // example code in Dir struct - // use read/readSync/close - }); - ``` - - -## fileio.opendirSync - -opendirSync(path: string): Dir - -以同步方法打开文件目录。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 待打开文件目录的绝对路径。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [Dir](#dir) | 返回Dir对象。 | - -- 示例: - ``` - let dir = fileio.opendirSync(path); - // example code in Dir struct - // use read/readSync/close - ``` - - -## fileio.access - -access(path: string, mode?: number): Promise<void> - -以异步方法检查当前进程是否可访问某文件,使用promise形式返回结果。 - -- 参数:. - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 待访问文件的绝对路径。 | - | mode | number | 否 | 访问文件时的选项,可给定如下选项,以按位或的方式使用多个选项,默认给定0。
确认当前进程是否具有对应权限:
- 0:确认文件是否存在。
- 1:确认当前进程是否具有可执行权限。
- 2:确认当前进程是否具有写权限。
- 4:确认当前进程是否具有读权限。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | Promise实例,用于异步获取结果。本调用将返回空值。 | - -- 示例: - ``` - fileio.access(path) - .then(function(err) { - // 文件存在,do something - }).catch(function(e) { - //若不符合条件则进入 - }); - ``` - - -## fileio.access - -access(path: String, mode?: number, callback: AsyncCallback<void>): void - -以异步方法检查当前进程是否可访问某文件,使用callback形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 待访问文件的绝对路径。 | - | mode | number | 否 | 访问文件时的选项,可给定如下选项,以按位或的方式使用多个选项,默认给定0。
确认当前进程是否具有对应权限:
- 0:确认文件是否存在。
- 1:确认当前进程是否具有可执行权限。
- 2:确认当前进程是否具有写权限。
- 4:确认当前进程是否具有读权限。 | - | callback | AsyncCallback<void> | 是 | 异步检查当前进程是否可访问某文件之后的回调。 | - -- 示例: - ``` - fileio.access(path, function (err) { - }); - ``` - - -## fileio.accessSync - -accessSync(path: string, mode?: number): void - -以同步方法检查当前进程是否可访问某文件。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 待访问文件的绝对路径。 | - | mode | number | 否 | 访问文件时的选项,可给定如下选项,以按位或的方式使用多个选项,默认给定0。
确认当前进程是否具有对应权限:
- 0:确认文件是否存在。
- 1:确认当前进程是否具有可执行权限。
- 2:确认当前进程是否具有写权限。
- 4:确认当前进程是否具有读权限。 | - -- 示例: - ``` - try { - fileio.accessSync(path); - } catch(e) { - //不符合条件则进入 - } - ``` - - -## fileio.close7+ - -close(fd: number):Promise<void> - -以异步方法关闭文件,使用promise形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | fd | number | 是 | 待关闭文件的文件描述符。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | Promise实例,用于异步获取结果。本调用将返回空值。 | - -- 示例: - ``` - let fd = fileio.openSync(path); - await fileio.close(fd); - ``` - - -## fileio.close7+ - -close(fd: number, callback:AsyncCallback<void>): void - -以异步方法关闭文件,使用callback形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | fd | number | 是 | 待关闭文件的文件描述符。 | - | callback | AsyncCallback<void> | 是 | 异步关闭文件之后的回调。 | - -- 示例: - ``` - let fd = fileio.openSync(path); - await fileio.close(fd, function (err) { - }); - ``` - - -## fileio.closeSync - -closeSync(fd: number): void - -以同步方法关闭文件。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | fd | number | 是 | 待关闭文件的文件描述符。 | - -- 示例: - ``` - fileio.closeSync(fd); - ``` - - -## fileio.close7+ - -close(): Promise<void> - -以异步方法关闭文件流,使用promise形式返回结果。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | Promise实例,用于异步获取结果。本调用将返回空值。 | - -- 示例: - ``` - fileio.close(); - ``` - - -## fileio.close7+ - -close(callback: AsyncCallback<void>): void - -以异步方法关闭文件流,使用callback形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<void> | 是 | 异步关闭文件流之后的回调。 | - -- 示例: - ``` - await fileio.close(function(err){ - }); - ``` - - -## fileio.copyFile - -copyFile(src:string | number, dest:string | number, mode?:number):Promise<void> - -以异步方法复制文件,使用promise形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | src | string \| number | 是 | 待复制文件的路径或待复制文件的描述符。 | - | dest | string \| number | 是 | 目标文件路径或目标文件描述符。 | - | mode | number | 否 | mode提供覆盖文件的选项,当前仅支持0,且默认为0。
0:完全覆盖目标文件,未覆盖部分将被裁切掉。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | Promise实例,用于异步获取结果。本调用将返回空值。 | - -- 示例: - ``` - await fileio.copyFile(src, dest); - ``` - - -## fileio.copyFile - -copyFile(src:string | number, dest:string | number, mode?: number, callback: AsyncCallbak<void>): void - -以异步方法复制文件,使用callback形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | src | string \| number | 是 | 待复制文件的路径或待复制文件的描述符。 | - | dest | string \| number | 是 | 目标文件路径或目标文件描述符。 | - | mode | number | 否 | mode提供覆盖文件的选项,当前仅支持0,且默认为0。
0:完全覆盖目标文件,未覆盖部分将被裁切掉。 | - | callback | AsyncCallback<void> | 是 | 异步复制文件之后的回调。 | - -- 示例: - ``` - await fileio.copyFile(src, dest, function (err) { - }); - ``` - - -## fileio.copyFileSync - -fileio.copyFileSync(src:string | number, dest:string | number, mode?:number): void - -以同步方法复制文件。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | src | string \| number | 是 | 待复制文件的路径或待复制文件的描述符。 | - | dest | string \| number | 是 | 目标文件路径或目标文件描述符。 | - | mode | number | 否 | mode提供覆盖文件的选项,当前仅支持0,且默认为0。
0:完全覆盖目标文件,未覆盖部分将被裁切掉。 | - -- 示例: - ``` - fileio.copyFileSync(src, dest); - ``` - - -## fileio.mkdir - -mkdir(path:string, mode?: number): Promise<void> - -以异步方法创建目录,使用promise形式返回结果。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 待创建目录的绝对路径。 | - | mode | number | 否 | 创建目录的权限,可给定如下权限,以按位或的方式追加权限,默认给定0o775。
- 0o775:所有者具有读、写及可执行权限,其余用户具有读及可执行权限。
- 0o700:所有者具有读、写及可执行权限。
- 0o400:所有者具有读权限。
- 0o200:所有者具有写权限。
- 0o100:所有者具有可执行权限。
- 0o070:所有用户组具有读、写及可执行权限。
- 0o040:所有用户组具有读权限。
- 0o020:所有用户组具有写权限。
- 0o010:所有用户组具有可执行权限。
- 0o007:其余用户具有读、写及可执行权限。
- 0o004:其余用户具有读权限。
- 0o002:其余用户具有写权限。
- 0o001:其余用户具有可执行权限。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | Promise实例,用于异步获取结果。本调用将返回空值。 | - -- 示例: - ``` - await fileio.mkdir(path) - .then(function(err) { - // 目录创建成功,do something - }).catch(function (e){ - }); - ``` - - -## fileio.mkdir - -mkdir(path:string, mode?:number, callback:AsyncCallbak<void>): void - -以异步方法创建目录,使用callback形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 待创建目录的绝对路径。 | - | mode | number | 否 | 创建目录的权限,可给定如下权限,以按位或的方式追加权限,默认给定0o775。
- 0o775:所有者具有读、写及可执行权限,其余用户具有读及可执行权限。
- 0o700:所有者具有读、写及可执行权限。
- 0o400:所有者具有读权限。
- 0o200:所有者具有写权限。
- 0o100:所有者具有可执行权限。
- 0o070:所有用户组具有读、写及可执行权限。
- 0o040:所有用户组具有读权限。
- 0o020:所有用户组具有写权限。
- 0o010:所有用户组具有可执行权限。
- 0o007:其余用户具有读、写及可执行权限。
- 0o004:其余用户具有读权限。
- 0o002:其余用户具有写权限。
- 0o001:其余用户具有可执行权限。 | - | callback | AsyncCallback<void> | 是 | 异步创建目录操作完成之后的回调。 | - -- 示例: - ``` - await fileio.mkdir(path, function(err) { - if (!err) { - // do something - } - }); - ``` - - -## fileio.mkdirSync - -fileio.mkdirSync(path: string, mode?: number): void - -以同步方法创建目录。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 待创建目录的绝对路径。 | - | mode | number | 否 | 创建目录的权限,可给定如下权限,以按位或的方式追加权限,默认给定0o775。
- 0o775:所有者具有读、写及可执行权限,其余用户具有读及可执行权限。
- 0o700:所有者具有读、写及可执行权限。
- 0o400:所有者具有读权限。
- 0o200:所有者具有写权限。
- 0o100:所有者具有可执行权限。
- 0o070:所有用户组具有读、写及可执行权限。
- 0o040:所有用户组具有读权限。
- 0o020:所有用户组具有写权限。
- 0o010:所有用户组具有可执行权限。
- 0o007:其余用户具有读、写及可执行权限。
- 0o004:其余用户具有读权限。
- 0o002:其余用户具有写权限。
- 0o001:其余用户具有可执行权限。 | - -- 示例: - ``` - fileio.mkdirSync(path); - ``` - - -## fileio.open7+ - -open(path: string, flags?: number, mode?: number): Promise<number> - -以异步的方法打开文件,使用promise形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 待打开文件的绝对路径。 | - | flags | number | 否 | 打开文件的选项,必须指定如下选项中的一个,默认以只读方式打开:
- 0o0:只读打开。
- 0o1:只写打开。
- 0o2:读写打开。
同时,也可给定如下选项,以按位或的方式追加,默认不给定任何额外选项:
- 0o100:若文件不存在,则创建文件。使用该选项时必须指定第三个参数 mode。
- 0o200:如果追加了0o100选项,且文件已经存在,则出错。
- 0o1000:如果文件存在且以只写或读写的方式打开文件,则将其长度裁剪为零。
- 0o2000:以追加方式打开,后续写将追加到文件末尾。
- 0o4000:如果path指向FIFO、块特殊文件或字符特殊文件,则本次打开及后续 IO 进行非阻塞操作。
- 0o200000:如果path指向目录,则出错。
- 0o400000:如果path指向符号链接,则出错。
- 0o4010000:以同步IO的方式打开文件。 | - | mode | number | 否 | 若创建文件,则指定文件的权限,可给定如下权限,以按位或的方式追加权限,默认给定0o666。
- 0o666:所有者具有读、写权限,所有用户组具有读、写权限,其余用户具有读、写权限。
- 0o700:所有者具有读、写及可执行权限。
- 0o400:所有者具有读权限。
- 0o200:所有者具有写权限。
- 0o100:所有者具有可执行权限。
- 0o070:所有用户组具有读、写及可执行权限。
- 0o040:所有用户组具有读权限。
- 0o020:所有用户组具有写权限。
- 0o010:所有用户组具有可执行权限。
- 0o007:其余用户具有读、写及可执行权限。
- 0o004:其余用户具有读权限。
- 0o002:其余用户具有写权限。
- 0o001:其余用户具有可执行权限。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<number> | 打开文件的文件描述符。 | - -- 示例: - ``` - let fd = await fileio.open(path, 0o1, 0o0200); - ``` - - -## fileio.open7+ - -open(path: string, flags: number, mode: number, callback: AsyncCallback<number>): void - -以异步的方法打开文件,使用callback形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 待打开文件的绝对路径。 | - | flags | number | 是 | 打开文件的选项,必须指定如下选项中的一个,默认以只读方式打开:
- 0o0:只读打开。
- 0o1:只写打开。
- 0o2:读写打开。
同时,也可给定如下选项,以按位或的方式追加,默认不给定任何额外选项:
- 0o100:若文件不存在,则创建文件。使用该选项时必须指定第三个参数 mode。
- 0o200:如果追加了0o100选项,且文件已经存在,则出错。
- 0o1000:如果文件存在且以只写或读写的方式打开文件,则将其长度裁剪为零。
- 0o2000:以追加方式打开,后续写将追加到文件末尾。
- 0o4000:如果path指向FIFO、块特殊文件或字符特殊文件,则本次打开及后续 IO 进行非阻塞操作。
- 0o200000:如果path指向目录,则出错。
- 0o400000:如果path指向符号链接,则出错。
- 0o4010000:以同步IO的方式打开文件。 | - | mode | number | 是 | 若创建文件,则指定文件的权限,可给定如下权限,以按位或的方式追加权限,默认给定0o666。
- 0o666:所有者具有读、写权限,所有用户组具有读、写权限,其余用户具有读、写权限。
- 0o700:所有者具有读、写及可执行权限。
- 0o400:所有者具有读权限。
- 0o200:所有者具有写权限。
- 0o100:所有者具有可执行权限。
- 0o070:所有用户组具有读、写及可执行权限。
- 0o040:所有用户组具有读权限。
- 0o020:所有用户组具有写权限。
- 0o010:所有用户组具有可执行权限。
- 0o007:其余用户具有读、写及可执行权限。
- 0o004:其余用户具有读权限。
- 0o002:其余用户具有写权限。
- 0o001:其余用户具有可执行权限。 | - | callback | AsyncCallback <void> | 是 | 异步打开文件之后的回调。 | - -- 示例: - ``` - await fileio.open(path, 0, function(err, fd) { - }); - ``` - - -## fileio.openSync - -openSync(path:string, flags?:number, mode?:number): number - -以同步方法打开文件。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 待打开文件的绝对路径。 | - | flags | number | 否 | 打开文件的选项,必须指定如下选项中的一个,默认以只读方式打开:
- 0o0:只读打开。
- 0o1:只写打开。
- 0o2:读写打开。
同时,也可给定如下选项,以按位或的方式追加,默认不给定任何额外选项:
- 0o100:若文件不存在,则创建文件。使用该选项时必须指定第三个参数 mode。
- 0o200:如果追加了0o100选项,且文件已经存在,则出错。
- 0o1000:如果文件存在且以只写或读写的方式打开文件,则将其长度裁剪为零。
- 0o2000:以追加方式打开,后续写将追加到文件末尾。
- 0o4000:如果path指向FIFO、块特殊文件或字符特殊文件,则本次打开及后续 IO 进行非阻塞操作。
- 0o200000:如果path指向目录,则出错。
- 0o400000:如果path指向符号链接,则出错。
- 0o4010000:以同步IO的方式打开文件。 | - | mode | number | 否 | 若创建文件,则指定文件的权限,可给定如下权限,以按位或的方式追加权限,默认给定0o666。
- 0o666:所有者具有读、写权限,所有用户组具有读、写权限,其余用户具有读、写权限。
- 0o700:所有者具有读、写及可执行权限。
- 0o400:所有者具有读权限。
- 0o200:所有者具有写权限。
- 0o100:所有者具有可执行权限。
- 0o070:所有用户组具有读、写及可执行权限。
- 0o040:所有用户组具有读权限。
- 0o020:所有用户组具有写权限。
- 0o010:所有用户组具有可执行权限。
- 0o007:其余用户具有读、写及可执行权限。
- 0o004:其余用户具有读权限。
- 0o002:其余用户具有写权限。
- 0o001:其余用户具有可执行权限。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 打开文件的文件描述符。 | - -- 示例: - ``` - let fd = fileio.openSync(path); - ``` - - -## fileio.read - -read(fd: number, buffer: ArrayBuffer, options?: Object): Promise<Readout> - -以异步方法从文件读取数据,使用promise形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | fd | number | 是 | 待读取文件的文件描述符。 | - | buffer | ArrayBuffer | 是 | 用于保存读取到的文件数据的缓冲区。 | - | options | Object | 否 | 支持如下选项:
- offset,number类型,表示将数据读取到缓冲区的位置,即相对于缓冲区首地址的偏移。可选,默认为0。
- length,number类型,表示期望读取数据的长度。可选,默认缓冲区长度减去偏移长度。
- position,number类型,表示期望读取文件的位置。可选,默认从当前位置开始读。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<[Readout](#readout)> | 读取的结果。 | - -- 示例: - ``` - let fd = fileio.openSync(path, 0o2); - let buf = new ArrayBuffer(4096); - let res = await fileio.read(fd, buf); - ``` - - -## fileio.read - -read(fd: number, buffer: ArrayBuffer, options?: Object, callback: AsyncCallback<Readout>): void - -以异步方法从文件读取数据,使用callback形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | fd | number | 是 | 待读取文件的文件描述符。 | - | buffer | ArrayBuffer | 是 | 用于保存读取到的文件数据的缓冲区。 | - | options | Object | 否 | 支持如下选项:
- offset,number类型,表示将数据读取到缓冲区的位置,即相对于缓冲区首地址的偏移。可选,默认为0。
- length,number类型,表示期望读取数据的长度。可选,默认缓冲区长度减去偏移长度。
- position,number类型,表示期望读取文件的位置。可选,默认从当前位置开始读。 | - | callback | AsyncCallback<[Readout](#readout)> | 是 | 异步读取数据之后的回调。 | - -- 示例: - ``` - let fd = fileio.openSync(path, 0o2); - let buf = new ArrayBuffer(4096); - await fileio.read(fd, buf, function (err, readOut) { - if (!err) { - console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer))) - } - }); - ``` - - -## fileio.readSync - -readSync(fd: number, buffer: ArrayBuffer, options?: Object): number - -以同步方法从文件读取数据。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | fd | number | 是 | 待读取文件的文件描述符。 | - | buffer | ArrayBuffer | 是 | 用于保存读取到的文件数据的缓冲区。 | - | options | Object | 否 | 支持如下选项:
- offset,number类型,表示将数据读取到缓冲区的位置,即相对于缓冲区首地址的偏移。可选,默认为0。
- length,number类型,表示期望读取数据的长度。可选,默认缓冲区长度减去偏移长度。
- position,number类型,表示期望读取文件的位置。可选,默认从当前位置开始读。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 实际读取的长度。 | - -- 示例: - ``` - let fd = fileio.openSync(path, 0o2); - let buf = new ArrayBuffer(4096); - let num = fileio.readSync(fd, buf); - ``` - - -## fileio.rmdir7+ - -rmdir(path: string): Promise<void> - -以异步方法删除目录,使用promise形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 待删除目录的绝对路径。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | Promise实例,用于异步获取结果。本调用将返回空值。 | - -- 示例: - ``` - fileio.rmdir(path) - .then(function(err) { - // 删除目录成功,do something - }).catch(function(e){ - }); - ``` - - -## fileio.rmdir7+ - -rmdir(path: string, callback:AsyncCallback<void>): void - -以异步方法删除目录,使用callback形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 待删除目录的绝对路径。 | - | callback | AsyncCallback<void> | 是 | 异步删除目录之后的回调。 | - -- 示例: - ``` - fileio.rmdir(path, function(err){ - }); - ``` - - -## fileio.rmdirSync - -rmdirSync(path:string) - -以同步方法删除目录。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 待删除目录的绝对路径。 | - -- 示例: - ``` - fileio.rmdirSync(path); - ``` - - -## fileio.unlink - -unlink(path:string): Promise<void> - -以异步方法删除文件,使用promise形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 待删除文件的绝对路径。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | Promise实例,用于异步获取结果。本调用将返回空值。 | - -- 示例: - ``` - await fileio.unlink(path); - ``` - - -## fileio.unlink - -unlink(path:string, callback:AsyncCallback<void>): void - -以异步方法删除文件,使用callback形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 待删除文件的绝对路径。 | - | callback | AsyncCallback<void> | 是 | 异步删除文件之后的回调。 | - -- 示例: - ``` - await fileio.unlink(path, function(err) { - if (!err) { - // do something - } - }); - ``` - - -## fileio.unlinkSync - -unlinkSync(path: string): void - -以同步方法删除文件。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 待删除文件的绝对路径。 | - -- 示例: - ``` - fileio.unlinkSync(path); - ``` - - -## fileio.write - -write(fd: number, buffer: ArrayBuffer | string, options?: Object): Promise<number> - -以异步方法将数据写入文件,使用promise形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | fd | number | 是 | 待写入文件的文件描述符。 | - | buffer | ArrayBuffer \| string | 是 | 待写入文件的数据,可来自缓冲区或字符串。 | - | options | Object | 否 | 支持如下选项:
- offset,number类型,表示期望写入数据的位置相对于数据首地址的偏移。可选,默认为0。
- length,number类型,表示期望写入数据的长度。可选,默认缓冲区长度减去偏移长度。
- position,number类型,表示期望写入文件的位置。可选,默认从当前位置开始写。
- encoding,string类型,当数据是string类型时有效,表示数据的编码方式,默认 'utf-8'。仅支持 'utf-8'。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<number> | 实际写入的长度。 | - -- 示例: - ``` - let fd = fileio.openSync(fpath, 0o100 | 0o2, 0o666); - let num = await fileio.write(fd, "hello, world"); - ``` - - -## fileio.write - -write(fd:number, buffer:ArrayBuffer | string,options?:Object, callback:AsyncCallback<number>): void - -以异步方法将数据写入文件,使用callback形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | fd | number | 是 | 待写入文件的文件描述符。 | - | buffer | ArrayBuffer \| string | 是 | 待写入文件的数据,可来自缓冲区或字符串。 | - | options | Object | 否 | 支持如下选项:
- offset,number类型,表示期望写入数据的位置相对于数据首地址的偏移。可选,默认为0。
- length,number类型,表示期望写入数据的长度。可选,默认缓冲区长度减去偏移长度。
- position,number类型,表示期望写入文件的位置。可选,默认从当前位置开始写。
- encoding,string类型,当数据是string类型时有效,表示数据的编码方式,默认 'utf-8'。仅支持 'utf-8'。 | - | callback | AsyncCallback<number> | 是 | 异步将数据写入完成后执行的回调函数。 | - -- 示例: - ``` - let fd = fileio.openSync(path, 0o100 | 0o2, 0o666); - fileio.write(fd, "hello, world", function (err, bytesWritten) { - if (!err) { - console.log(bytesWritten) - } - }); - ``` - - -## fileio.writeSync - -writeSync(fd: number, buffer: ArrayBuffer | string, options?:Object): number - -以同步方法将数据写入文件。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | fd | number | 是 | 待写入文件的文件描述符。 | - | buffer | ArrayBuffer \| string | 是 | 待写入文件的数据,可来自缓冲区或字符串。 | - | options | Object | 否 | 支持如下选项:
- offset,number类型,表示期望写入数据的位置相对于数据首地址的偏移。可选,默认为0。
- length,number类型,表示期望写入数据的长度。可选,默认缓冲区长度减去偏移长度。
- position,number类型,表示期望写入文件的位置。可选,默认从当前位置开始写。
- encoding,string类型,当数据是string类型时有效,表示数据的编码方式,默认 'utf-8'。仅支持 'utf-8'。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 实际写入的长度。 | - -- 示例: - ``` - let fd = fileio.openSync(path, 0o100 | 0o2, 0o666); - let num = fileio.writeSync(fd, "hello, world"); - ``` - - -## fileio.hash - -hash(path: string, algorithm: string): Promise<string> - -以异步方法计算文件的哈希值,使用promise形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 待计算哈希值文件的绝对路径。 | - | algorithm | string | 是 | 哈希计算采用的算法。可选 "md5"、"sha1" 或 "sha256"。建议采用安全强度更高的 "sha256"。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<string> | 文件的哈希值。表示为十六进制数字串,所有字母均大写。 | - -- 示例: - ``` - let hashStr = await fileio.hash(path, "sha256"); - ``` - - -## fileio.hash - -hash(psth:string, algorithm:string, callback:AsyncCallback<string>): void - -以异步方法计算文件的哈希值,使用callback形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 待计算哈希值文件的绝对路径。 | - | algorithm | string | 是 | 哈希计算采用的算法。可选 "md5"、"sha1" 或 "sha256"。建议采用安全强度更高的 "sha256"。 | - | callback | AsyncCallback<string> | 是 | 异步计算文件哈希操之后的回调函数(其中给定文件哈希值表示为十六进制数字串,所有字母均大写)。 | - -- 示例: - ``` - fileio.hash(fpath, "sha256", function(err, hashStr) { - if (!err) { - console.log(hashStr) - } - }); - ``` - - -## fileio.chmod7+ - -chmod(path: string, mode: number):Promise<void> - -以异步方法基于文件路径改变文件权限,使用promise形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 待改变文件权限的绝对路径。 | - | mode | number | 是 | 改变文件权限,可给定如下权限,以按位或的方式追加权限。
- 0o700:所有者具有读、写及可执行权限。
- 0o400:所有者具有读权限。
- 0o200:所有者具有写权限。
- 0o100:所有者具有可执行权限。
- 0o070:所有用户组具有读、写及可执行权限。
- 0o040:所有用户组具有读权限。
- 0o020:所有用户组具有写权限。
- 0o010:所有用户组具有可执行权限。
- 0o007:其余用户具有读、写及可执行权限。
- 0o004:其余用户具有读权限。
- 0o002:其余用户具有写权限。
- 0o001:其余用户具有可执行权限。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | Promise实例,用于异步获取结果。本调用将返回空值。 | - -- 示例: - ``` - fileio.chmod(path, mode) - .then(function(err) { - // 改变文件权限成功,do something - }).catch(function(e){ - }); - ``` - - -## fileio.chmod7+ - -chmod(path: string, mode: number, callback: AsyncCallback<void>): void - -以异步方法基于文件路径改变文件权限,使用callback形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 待改变文件权限的绝对路径。 | - | mode | number | 是 | 改变文件权限,可给定如下权限,以按位或的方式追加权限。
- 0o700:所有者具有读、写及可执行权限。
- 0o400:所有者具有读权限。
- 0o200:所有者具有写权限。
- 0o100:所有者具有可执行权限。
- 0o070:所有用户组具有读、写及可执行权限。
- 0o040:所有用户组具有读权限。
- 0o020:所有用户组具有写权限。
- 0o010:所有用户组具有可执行权限。
- 0o007:其余用户具有读、写及可执行权限。
- 0o004:其余用户具有读权限。
- 0o002:其余用户具有写权限。
- 0o001:其余用户具有可执行权限。 | - | callback | AsyncCallback<void> | 是 | 异步改变文件权限之后的回调。 | - -- 示例: - ``` - fileio.chmod(path, mode, function (err) { - }); - ``` - - -## fileio.chmodSync7+ - -chmodSync(path: string, mode: number): void - -以同步方法基于文件路径改变文件权限。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 待改变文件权限的绝对路径。 | - | mode | number | 是 | 改变文件权限,可给定如下权限,以按位或的方式追加权限。
- 0o700:所有者具有读、写及可执行权限。
- 0o400:所有者具有读权限。
- 0o200:所有者具有写权限。
- 0o100:所有者具有可执行权限。
- 0o070:所有用户组具有读、写及可执行权限。
- 0o040:所有用户组具有读权限。
- 0o020:所有用户组具有写权限。
- 0o010:所有用户组具有可执行权限。
- 0o007:其余用户具有读、写及可执行权限。
- 0o004:其余用户具有读权限。
- 0o002:其余用户具有写权限。
- 0o001:其余用户具有可执行权限。 | - -- 示例: - ``` - fileio.chmodSync(fpath, mode); - ``` - - -## fileio.fstat7+ - -fstat(fd: number): Promise<Stat> - -以异步方法基于文件描述符获取文件状态信息,使用promise形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | fd | number | 是 | 待获取文件的文件描述符。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<[Stat](#stat)> | 表示文件的具体信息。 | - -- 示例: - ``` - let stat = await fileio.fstat(fd); - ``` - - -## fileio.fstat7+ - -fstat(fd: number, callback: AsyncCallback<Stat>): void - -以异步方法基于文件描述符获取文件状态信息,使用callback形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | fd | number | 是 | 待获取文件的文件描述符。 | - | callback | AsyncCallback<[Stat](#stat)> | 是 | 异步获取文件状态信息之后的回调。 | - -- 示例: - ``` - let fd = fileio.openSync(path); - fileio.fstat(fd, function (err) { - }); - ``` - - -## fileio.fstatSync7+ - -fstatSync(fd: number): Stat - -以同步方法基于文件描述符获取文件状态信息。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | fd | number | 是 | 待获取文件的文件描述符。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [Stat](#stat) | 表示文件的具体信息。 | - -- 示例: - ``` - let fd = fileio.openSync(path); - let stat = fileio.fstatSync(fd); - ``` - - -## fileio.ftruncate7+ - -ftruncate(fd: number, len: number): Promise<void> - -以异步方法基于文件描述符截断文件,使用promise形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | fd | number | 是 | 待截断文件的文件描述符。 | - | len | number | 是 | 文件截断后的长度,以字节为单位。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | Promise实例,用于异步获取结果。本调用将返回空值。 | - -- 示例: - ``` - let fd = fileio.openSync(path); - fileio.ftruncate(fd, 5) - .then(function(err) { - // 截断文件成功, do something - }).catch(function(e){ - }); - ``` - - -## fileio.ftruncate7+ - -ftruncate(fd: number, len: number, callback:AsyncCallback<void>): void - -以异步方法基于文件描述符截断文件,使用callback形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | fd | number | 是 | 待截断文件的文件描述符。 | - | len | number | 是 | 文件截断后的长度,以字节为单位。 | - | callback | AsyncCallback<void> | 是 | 异步截断文件的信息之后的回调。 | - -- 示例: - ``` - fileio.ftruncate(fd, len, function(err){ - }); - ``` - - -## fileio.ftruncateSync7+ - -ftruncateSync(fd: number, len?: number): void - -以同步方法基于文件描述符截断文件。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | fd | number | 是 | 待截断文件的文件描述符。 | - | len | number | 否 | 文件截断后的长度,以字节为单位。 | - -- 示例: - ``` - fileio.ftruncate(fd, len); - ``` - - -## fileio.truncate7+ - -truncate(path: string, len: number): Promise<void> - -以异步方法基于文件路径截断文件,使用promise形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 待截断文件的绝对路径。 | - | len | number | 是 | 文件截断后的长度,以字节为单位。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | Promise实例,用于异步获取结果。本调用将返回空值。 | - -- 示例: - ``` - fileio.truncate(path, len) - .then(function(err) { - // 截断文件成功,do something - }).catch(function(e){ - }); - ``` - - -## fileio.truncate7+ - -truncate(path: string, len: number, callback:AsyncCallback<void>): void - -以异步方法基于文件路径截断文件,使用callback形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 待截断文件的绝对路径。 | - | len | number | 是 | 文件截断后的长度,以字节为单位。 | - | callback | AsyncCallback<void> | 是 | 异步截断文件的信息之后的回调。 | - -- 示例: - ``` - fileio.truncate(path, len, function(err){ - }); - ``` - - -## fileio.truncateSync7+ - -truncateSync(fpath: string, len?: number): void - -以同步方法基于文件路径截断文件。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 待截断文件的绝对路径。 | - | len | number | 否 | 文件截断后的长度,以字节为单位。 | - -- 示例: - ``` - fileio.ftruncate(path, len); - ``` - - -## fileio.readText7+ - -readText(filePath: string, options?:Object): Promise<string> - -以异步方法基于文本方式读取文件(即直接读取文件的文本内容),使用promise形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | filePath | string | 是 | 待读取文件的绝对路径。 | - | options | Object | 否 | 支持如下选项:
- position,number类型,表示期望读取文件的位置。可选,默认从当前位置开始读取。
- length,number类型,表示期望读取数据的长度。可选,默认缓冲区长度减去偏移长度。
- encoding,string类型,当数据是 string 类型时有效,表示数据的编码方式,默认 'utf-8',仅支持 'utf-8'。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<string> | 返回读取文件的内容。 | - -- 示例: - ``` - fileio.readText(path) - .then(function(str) { - // 读取文件成功,do something - }).catch(function(e){ - }); - ``` - - -## fileio.readText7+ - -readText(filePath: string, options?:Object, callback:AsyncCallback<string>): void - -以异步方法基于文本方式读取文件(即直接读取文件的文本内容),使用callback形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | filePath | string | 是 | 待读取文件的绝对路径。 | - | options | Object | 否 | 支持如下选项:
- position,number类型,表示期望读取文件的位置。可选,默认从当前位置开始读取。
- length,number类型,表示期望读取数据的长度。可选,默认缓冲区长度减去偏移长度。
- encoding,string类型,当数据是 string 类型时有效,表示数据的编码方式,默认 'utf-8',仅支持 'utf-8'。 | - | callback | AsyncCallback<string> | 是 | 异步通过文本方式读取文件之后的回调。 | - -- 示例: - ``` - fileio.readText(path, function(err, str){ - }); - ``` - - -## fileio.readTextSync7+ - -readTextSync(filePath: string, options?:Object): string - -以同步方法基于文本方式读取文件(即直接读取文件的文本内容)。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | filePath | string | 是 | 待读取文件的绝对路径。 | - | options | Object | 否 | 支持如下选项:
- position,number类型,表示期望读取文件的位置。可选,默认从当前位置开始读取。
- length,number类型,表示期望读取数据的长度。可选,默认缓冲区长度减去偏移长度。
- encoding,string类型,当数据是 string 类型时有效,表示数据的编码方式,默认 'utf-8',仅支持 'utf-8'。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<string> | 返回读取文件的内容。 | - -- 示例: - ``` - let str = fileio.readTextSync(path, {position: pos, length: len}); - ``` - - -## fileio.lstat7+ - -lstat(path: string): Promise<Stat> - -以异步方法获取链接状态信息,使用promise形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 目标文件的绝对路径,指向链接状态。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<[Stat](#stat)> | 表示文件的具体信息。 | - -- 示例: - ``` - let stat = await fileio.lstat(path); - ``` - - -## fileio.lstat7+ - -lstat(path:string, callback:AsyncCallback<Stat>): void - -以异步方法获取链接状态信息,使用callback形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 目标文件的绝对路径,指向链接状态。 | - | callback | AsyncCallback<[Stat](#stat)> | 是 | 异步获取链接状态信息之后的回调。 | - -- 示例: - ``` - fileio.lstat(path, function (err, stat) { - )); - ``` - - -## fileio.lstatSync7+ - -lstatSync(path:string): Stat - -以同步方法获取链接状态信息。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 目标文件的绝对路径,指向链接状态。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [Stat](#stat) | 表示文件的具体信息。 | - -- 示例: - ``` - let stat = fileio.lstatSync(path); - ``` - - -## fileio.read7+ - -read(buffer: ArrayBuffer, options?: Object): Promise<Readout> - -以异步方法从文件读取数据,使用promise形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | buffer | ArrayBuffer | 是 | 用于保存读取到的文件数据的缓冲区。 | - | options | Object | 否 | 支持如下选项:
- offset,number类型,表示将数据读取到缓冲区的位置,即相对于缓冲区首地址的偏移。可选,默认为0。
- length,number类型,表示期望读取数据的长度。可选,默认缓冲区长度减去偏移长度。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<[Readout](#readout)> | 读取的结果。 | - -- 示例: - ``` - let readout = await fileio.read(new ArrayBuffer(4096)); - ``` - - -## fileio.read7+ - -read(buffer: ArrayBuffer, options?: Object, callback: AsyncCallback<Readout>): void - -异步方法从文件读取数据,使用callback形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | buffer | ArrayBuffer | 是 | 用于保存读取到的文件数据的缓冲区。 | - | options | Object | 否 | 支持如下选项:
- offset,number类型,表示将数据读取到缓冲区的位置,即相对于缓冲区首地址的偏移。可选,默认为0。
- length,number类型,表示期望读取数据的长度。可选,默认缓冲区长度减去偏移长度。 | - | callback | AsyncCallback<[Readout](#readout)> | 是 | 异步从文件读取数据之后的回调。 | - -- 示例 - ``` - let buf = new ArrayBuffer(4096); - fileio.read(buf, function (err, readOut) { - if (!err) { - console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer))) - } - }); - ``` - - -## fileio.rename7+ - -rename(oldPath: string, newPath: string): Promise<void> - -以异步方法重命名文件,使用promise形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | oldPath | string | 是 | 目标文件的当前绝对路径。 | - | Newpath | String | 是 | 目标文件的新绝对路径。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | Promise实例,用于异步获取结果。本调用将返回空值。 | - -- 示例: - ``` - fileio.rename(oldPath, Newpath) - .then(function(err) { - // 重命名文件成功,do something - }).catch(function(e){ - - }); - ``` - - -## fileio.rename7+ - -rename(oldPath: string, newPath: string, callback: AsyncCallback<void>): void - -以异步方法重命名文件,使用callback形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | oldpath | string | 是 | 目标文件的当前绝对路径。 | - | Newpath | String | 是 | 目标文件的新绝对路径。 | - | Callback | AsyncCallback<void> | 是 | 异步重命名文件之后的回调。 | - -- 示例: - ``` - fileio.rename(oldpath, Newpath, function(err){ - }); - ``` - - -## fileio.renameSync7+ - -renameSync(oldPath: string, newPath: string): void - -以同步方法重命名文件。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | oldPath | string | 是 | 目标文件的当前绝对路径。 | - | Newpath | String | 是 | 目标文件的新绝对路径。 | - -- 示例: - ``` - fileio.renameSync(oldpath, newpath); - ``` - - -## fileio.fsync7+ - -fsync(fd: number): Promise<void> - -以异步方法同步文件数据,使用promise形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | fd | number | 是 | 待同步文件的文件描述符。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | Promise实例,用于异步获取结果。本调用将返回空值。 | - -- 示例: - ``` - await fileio.fsync(fd); - ``` - - -## fileio.fsync7+ - -fsync(fd: number, callback: AsyncCallback<void>): void - -以异步方法同步文件数据,使用callback形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | fd | number | 是 | 待同步文件的文件描述符。 | - | Callback | AsyncCallback<void> | 是 | 异步将文件数据同步之后的回调。 | - -- 示例: - ``` - fileio.fsync(fd, function(err){ - }); - ``` - - -## fileio.fsyncSync7+ - -fsyncSync(fd: number): void - -以同步方法同步文件数据。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | fd | number | 是 | 待同步文件的文件描述符。 | - -- 示例: - ``` - fileio.fyncsSync(fd); - ``` - - -## fileio.fdatasync7+ - -fdatasync(fd: number): Promise<void> - -以异步方法实现文件内容数据同步,使用promise形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | fd | number | 是 | 待同步文件的文件描述符。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | Promise实例,用于异步获取结果,本调用将返回空值。 | - -- 示例: - ``` - fileio.fdatasync(fd) - .then(function(err) { - // 数据同步成功,do something - }).catch(function(e){ - }); - ``` - - -## fileio.fdatasync7+ - -fdatasync(fd: number, callback:AsyncCallback<void>): void - -以异步方法实现文件内容数据同步,使用callback形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | fd | number | 是 | 待同步文件的文件描述符。 | - | callback | AsyncCallback <void> | 是 | 异步将文件内容数据同步之后的回调。 | - -- 示例: - ``` - fileio.fdatasync (fd, function (err) { - }); - ``` - - -## fileio.fdatasyncSync7+ - -fdatasyncSync(fd: number): void - -以同步方法实现文件内容数据同步。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | fd | number | 是 | 待同步文件的文件描述符。 | - -- 示例: - ``` - let stat = fileio.fdatasyncSync(fd); - ``` - - -## fileio.symlink7+ - -symlink(target: string, srcPath: string): Promise<void> - -以异步方法基于文件路径创建符号链接,使用promise形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | target | string | 是 | 目标文件的绝对路径。 | - | srcPath | string | 是 | 符号链接文件的绝对路径。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | Promise实例,用于异步获取结果,本调用将返回空值。 | - -- 示例: - ``` - fileio.symlink(target, srcPath) - .then(function(err) { - // 创建符号链接成功,do something - }).catch(function(e){ - - }); - ``` - - -## fileio.symlink7+ - -symlink(target: string, srcPath: string, callback: AsyncCallback<void>): void - -以异步方法基于文件路径创建符号链接,使用callback形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | target | string | 是 | 目标文件的绝对路径。 | - | srcPath | string | 是 | 符号链接文件的绝对路径。 | - | callback | AsyncCallback<void> | 是 | 异步创建符号链接信息之后的回调。 | - -- 示例: - ``` - fileio.symlink(target, srcPath, function (err) { - }); - ``` - - -## fileio.symlinkSync7+ - -symlinkSync(target: string, srcPath: string): void - -以同步的方法基于文件路径创建符号链接。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | target | string | 是 | 目标文件的绝对路径。 | - | srcPath | string | 是 | 符号链接文件的绝对路径。 | - -- 示例: - ``` - fileio.symlinkSync(target, srcPath); - ``` - - -## fileio.chown7+ - -chown(path: string, uid: number, gid: number): Promise<void> - -以异步的方法基于文件路径改变文件所有者,使用promise形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 待改变文件的绝对路径。 | - | uid | number | 是 | 新的UID(UserID)。 | - | gid | number | 是 | 新的GID(GroupID)。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | Promise实例,用于异步获取结果,本调用将返回空值。 | - -- 示例: - ``` - let stat = fileio.statSync(path); - await fileio.chown(path, stat.uid, stat.gid)); - ``` - - -## fileio.chown7+ - -chown(path: string, uid: number, gid: number, callback: AsyncCallback<void>): void - -以异步的方法基于文件路径改变文件所有者,使用callback形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 待改变文件的绝对路径。 | - | uid | number | 是 | 新的UID。 | - | gid | number | 是 | 新的GID。 | - | callback | AsyncCallback<void> | 是 | 异步改变文件所有者之后的回调。 | - -- 示例: - ``` - let stat = fileio.statSync(fpath) - fileio.chown(path, stat.uid, stat.gid, function (err){ - }); - ``` - - -## fileio.chownSync7+ - -chownSync(path: string, uid: number, gid: number): void - -以同步的方法基于文件路径改变文件所有者。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 待改变文件的绝对路径。 | - | uid | number | 是 | 新的UID。 | - | gid | number | 是 | 新的GID。 | - -- 示例: - ``` - let stat = fileio.statSync(fpath) - fileio.chownSync(path, stat.uid, stat.gid); - ``` - - -## fileio.mkdtemp7+ - -mkdtemp(prefix: string): Promise<string> - -以异步的方法创建临时目录,使用promise形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | prefix | string | 是 | 用随机产生的字符串替换以“XXXXXX”结尾目录路径。 | - -- 返回值: - | 参数名 | 说明 | - | -------- | -------- | - | Promise<string> | 生成的唯一目录路径。 | - -- 示例: - ``` - let res = await fileio.mkdtempSync(path + "XXXX"); - ``` - - -## fileio.mkdtemp7+ - -mkdtemp(prefix: string, callback: AsyncCallback<string>): void - -以异步的方法创建临时目录,使用callback形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | prefix | string | 是 | 用随机产生的字符串替换以“XXXXXX”结尾目录路径。 | - | callback | AsyncCallback<string> | 是 | 异步创建临时目录之后的回调。 | - -- 示例: - ``` - fileio.mkdtemp(path + "XXXX", function (err, res) { - }); - ``` - - -## fileio.mkdtempSync7+ - -mkdtempSync(prefix: string): string - -以同步的方法创建临时目录。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | prefix | string | 是 | 用随机产生的字符串替换以“XXXXXX”结尾目录路径。 | - -- 返回值: - | 参数名 | 说明 | - | -------- | -------- | - | string | 产生的唯一目录路径。 | - -- 示例: - ``` - let res = fileio.mkdtempSync(path + "XXXX"); - ``` - - -## fileio.fchmod7+ - -fchmod(fd: number, mode: number): Promise<void> - -以异步方法基于文件描述符改变文件权限,使用promise形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | fd | number | 是 | 待改变文件的文件描述符。 | - | mode | number | 是 | 若创建文件,则指定文件的权限,可给定如下权限,以按位或的方式追加权限。
- 0o700:所有者具有读、写及可执行权限。
- 0o400:所有者具有读权限。
- 0o200:所有者具有写权限。
- 0o100:所有者具有可执行权限。
- 0o070:所有用户组具有读、写及可执行权限。
- 0o040:所有用户组具有读权限。
- 0o020:所有用户组具有写权限。
- 0o010:所有用户组具有可执行权限。
- 0o007:其余用户具有读、写及可执行权限。
- 0o004:其余用户具有读权限。
- 0o002:其余用户具有写权限。
- 0o001:其余用户具有可执行权限。 | - -- 返回值: - | 参数名 | 说明 | - | -------- | -------- | - | Promise<void> | Promise实例,用于异步获取结果,本调用将返回空值。 | - -- 示例: - ``` - fileio.fchmod(fd, mode) - .then(function(err) { - // 改变文件权限成功,do something - }).catch(function(e){ - - }); - ``` - - -## fileio.fchmod7+ - -fchmod(fd: number, mode: number, callback: AsyncCallback<void>): void - -以异步方法基于文件描述符改变文件权限,使用callback形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | fd | number | 是 | 待改变文件的文件描述符。 | - | mode | number | 是 | 若创建文件,则指定文件的权限,可给定如下权限,以按位或的方式追加权限。
- 0o700:所有者具有读、写及可执行权限。
- 0o400:所有者具有读权限。
- 0o200:所有者具有写权限。
- 0o100:所有者具有可执行权限。
- 0o070:所有用户组具有读、写及可执行权限。
- 0o040:所有用户组具有读权限。
- 0o020:所有用户组具有写权限。
- 0o010:所有用户组具有可执行权限。
- 0o007:其余用户具有读、写及可执行权限。
- 0o004:其余用户具有读权限。
- 0o002:其余用户具有写权限。
- 0o001:其余用户具有可执行权限。 | - | callback | AsyncCallback <void> | 是 | 异步改变文件权限之后的回调。 | - -- 示例: - ``` - fileio.fchmod(fd, mode, function (err) { - }); - ``` - - -## fileio.fchmodSync7+ - -fchmodSync(existingPath: string, newPath: string): void - -以同步方法基于文件描述符改变文件权限。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | fd | number | 是 | 待改变文件的文件描述符。 | - | mode | number | 是 | 若创建文件,则指定文件的权限,可给定如下权限,以按位或的方式追加权限。
- 0o700:所有者具有读、写及可执行权限。
- 0o400:所有者具有读权限。
- 0o200:所有者具有写权限。
- 0o100:所有者具有可执行权限。
- 0o070:所有用户组具有读、写及可执行权限。
- 0o040:所有用户组具有读权限。
- 0o020:所有用户组具有写权限。
- 0o010:所有用户组具有可执行权限。
- 0o007:其余用户具有读、写及可执行权限。
- 0o004:其余用户具有读权限。
- 0o002:其余用户具有写权限。
- 0o001:其余用户具有可执行权限。 | - -- 示例: - ``` - fileio.fchmodSync(fd, mode); - ``` - - -## fileio.createStream7+ - -createStream(path: string, mode: string): Promise<Stream> - -以异步方法基于文件路径打开文件流,使用promise形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 待打开文件的绝对路径。 | - | mode | string | 是 | - r:打开只读文件,该文件必须存在。
- r+:打开可读写的文件,该文件必须存在。
- w:打开只写文件,若文件存在则文件长度清0,即该文件内容会消失。若文件不存在则建立该文件。
- w+:打开可读写文件,若文件存在则文件长度清0,即该文件内容会消失。若文件不存在则建立该文件。
- a:以附加的方式打开只写文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾,即文件原先的内容会被保留。
- a+:以附加方式打开可读写的文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾后,即文件原先的内容会被保留。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<[Stream](#stream7)> | 返回文件流的结果。 | - -- 示例: - ``` - let ss = filrio.createStream(path, "r+"); - ``` - - -## fileio.createStream7+ - -createStream(path: string, mode: string, callback: AsyncCallback<Stream>): void - -以异步方法基于文件路径打开文件流,使用callback形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 待打开文件的绝对路径。 | - | mode | string | 是 | - r:打开只读文件,该文件必须存在。
- r+:打开可读写的文件,该文件必须存在。
- w:打开只写文件,若文件存在则文件长度清0,即该文件内容会消失。若文件不存在则建立该文件。
- w+:打开可读写文件,若文件存在则文件长度清0,即该文件内容会消失。若文件不存在则建立该文件。
- a:以附加的方式打开只写文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾,即文件原先的内容会被保留。
- a+:以附加方式打开可读写的文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾后,即文件原先的内容会被保留。 | - | callback | AsyncCallback<[Stream](#stream7)> | 是 | 异步打开文件流之后的回调。 | - -- 示例: - ``` - fileio.createStream(path, mode, function(err, stream){ - }); - ``` - - -## fileio.createStreamSync7+ - -createStreamSync(path: string, mode: string): Stream - -以同步方法基于文件路径打开文件流。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 待打开文件的绝对路径。 | - | mode | string | 是 | - r:打开只读文件,该文件必须存在。
- r+:打开可读写的文件,该文件必须存在。
- w:打开只写文件,若文件存在则文件长度清0,即该文件内容会消失。若文件不存在则建立该文件。
- w+:打开可读写文件,若文件存在则文件长度清0,即该文件内容会消失。若文件不存在则建立该文件。
- a:以附加的方式打开只写文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾,即文件原先的内容会被保留。
- a+:以附加方式打开可读写的文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾后,即文件原先的内容会被保留。 | - -- 返回值: - | 参数名 | 说明 | - | -------- | -------- | - | [Stream](#stream7) | 返回文件流的结果。 | - -- 示例: - ``` - let ss = fileio.createStreamSync(path, "r+"); - ``` - - -## fileio.fdopenStream7+ - -fdopenStream(fd: number, mode: string): Promise<Stream> - -以异步方法基于文件描述符打开文件流,使用promise形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | fd | number | 是 | 待打开文件的文件描述符。 | - | mode | string | 是 | - r:打开只读文件,该文件必须存在。
- r+:打开可读写的文件,该文件必须存在。
- w:打开只写文件,若文件存在则文件长度清0,即该文件内容会消失。若文件不存在则建立该文件。
- w+:打开可读写文件,若文件存在则文件长度清0,即该文件内容会消失。若文件不存在则建立该文件。
- a:以附加的方式打开只写文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾,即文件原先的内容会被保留。
- a+:以附加方式打开可读写的文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾后,即文件原先的内容会被保留。 | - -- 返回值: - | 参数名 | 说明 | - | -------- | -------- | - | Promise<[Stream](#stream7)> | 返回文件流的结果。 | - -- 示例: - ``` - let fp = await fileio.fdopenStream(fd, mode); - ``` - - -## fileio.fdopenStream7+ - -fdopenStream(fd: number, mode: string, callback: AsyncCallback<Stream>): void - -以异步方法基于文件描述符打开文件流,使用callback形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | fd | number | 是 | 待打开文件的文件描述符。 | - | mode | string | 是 | - r:打开只读文件,该文件必须存在。
- r+:打开可读写的文件,该文件必须存在。
- w:打开只写文件,若文件存在则文件长度清0,即该文件内容会消失。若文件不存在则建立该文件。
- w+:打开可读写文件,若文件存在则文件长度清0,即该文件内容会消失。若文件不存在则建立该文件。
- a:以附加的方式打开只写文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾,即文件原先的内容会被保留。
- a+:以附加方式打开可读写的文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾后,即文件原先的内容会被保留。 | - | callback | AsyncCallback <[Stream](#stream7)> | 是 | 异步打开文件流之后的回调。 | - -- 示例: - ``` - fileio.fdopenStream(fd, mode, function (err, fp) { - }); - ``` - - -## fileio.fdopenStreamSync7+ - -fdopenStreamSync(fd: number, mode: string): Stream - -以同步方法基于文件描述符打开文件流。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | fd | number | 是 | 待打开文件的文件描述符。 | - | mode | string | 是 | - r:打开只读文件,该文件必须存在。
- r+:打开可读写的文件,该文件必须存在。
- w:打开只写文件,若文件存在则文件长度清0,即该文件内容会消失。若文件不存在则建立该文件。
- w+:打开可读写文件,若文件存在则文件长度清0,即该文件内容会消失。若文件不存在则建立该文件。
- a:以附加的方式打开只写文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾,即文件原先的内容会被保留。
- a+:以附加方式打开可读写的文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾后,即文件原先的内容会被保留。 | - -- 返回值: - | 参数名 | 说明 | - | -------- | -------- | - | [Stream](#stream7) | 返回文件流的结果。 | - -- 示例: - ``` - let ss = fileio.fdopenStreamSync(fd, "r+"); - ``` - - -## fileio.fchown7+ - -fchown(fd: number, uid: number, gid: number): Promise<void> - -以异步方法基于文件描述符改变文件所有者,使用promise形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | fd | number | 是 | 待改变文件的文件描述符。 | - | uid | number | 是 | 文件所有者的UID。 | - | gid | number | 是 | 文件所有组的GID。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | Promise实例,用于异步获取结果。本调用将返回空值。 | - -- 示例: - ``` - let stat = fileio.statSync(path); - fileio.fchown(fd, stat.uid, stat.gid) - .then(function(err) { - // 改变文件所有者成功,do something - }).catch(function(e){ - - }); - ``` - - -## fileio.fchown7+ - -fchown(fd: number, uid: number, gid: number, callback: AsyncCallback<void>): void - -以异步方法基于文件描述符改变文件所有者,使用callback形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | fd | number | 是 | 待改变文件的文件描述符。 | - | uid | number | 是 | 文件所有者的UID。 | - | gid | number | 是 | 文件所有组的GID。 | - | callback | AsyncCallback<void> | 是 | 异步改变文件所有者之后的回调。 | - -- 示例: - ``` - let stat = fileio.statSync(fpath); - fileio.fchown(fd, stat.uid, stat.gid, function (err){ - }); - ``` - - -## fileio.fchownSync7+ - -fchownSync(fd: number, uid: number, gid: number): void - -以同步方法基于文件描述符改变文件所有者。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | fd | number | 是 | 待改变文件的文件描述符。 | - | uid | number | 是 | 文件所有者的UID。 | - | gid | number | 是 | 文件所有组的GID。 | - -- 示例: - ``` - let stat = fileio.statSync(fpath); - fileio.fchownSync(fd, stat.uid, stat.gid); - ``` - - -## fileio.lchown7+ - -lchown(path: string, uid: number, gid: number): Promise<void> - -以异步方法基于文件路径改变文件所有者,更改符号链接本身的所有者,而不是符号链接所指向的实际文件,使用promise形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 待打开文件的绝对路径。 | - | uid | number | 是 | 新的UID。 | - | gid | number | 是 | 新的GID。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | Promise实例,用于异步获取结果。本调用将返回空值。 | - -- 示例: - ``` - let stat = fileio.statSync(path); - fileio.lchown(path, stat.uid, stat.gid) - .then(function(err) { - // 改变文件所有者,do something - }).catch(function(e){ - - }); - ``` - - -## fileio.lchown7+ - -lchown(path: string, uid: number, gid: number, callback: AsyncCallback<void>): void - -以异步方法基于文件路径改变文件所有者,更改符号链接本身的所有者,而不是更改符号链接所指向的实际文件,使用callback形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 待打开文件的绝对路径。 | - | uid | number | 是 | 新的UID。 | - | gid | number | 是 | 新的GID。 | - | callback | AsyncCallback<void> | 是 | 异步改变文件所有者之后的回调。 | - -- 示例: - ``` - let stat = fileio.statSync(path); - fileio.lchown(path, stat.uid, stat.gid, function (err){ - }); - ``` - - -## fileio.lchownSync7+ - -lchownSync(path: string, uid: number, gid: number): void - -以同步方法基于文件路径改变文件所有者,更改符号链接本身的所有者,而不是更改符号链接所指向的实际文件。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 待打开文件的绝对路径。 | - | uid | number | 是 | 新的UID。 | - | gid | number | 是 | 新的GID。 | - -- 示例: - ``` - let stat = fileio.statSync(path); - fileio.lchownSync(path, stat.uid, stat.gid); - ``` - - -## fileio.createWatcher7+ - -createWatcher(filename: string, events: number, callback: AsyncCallback<number>): Watcher - -以异步方法监听文件或者目录的变化,使用callback形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | filename | string | 是 | 待监视文件的绝对路径。 | - | events | Number | 是 | - 1: 监听文件或者目录是否发生重命名。
- 2:监听文件或者目录内容的是否修改。
- 3:两者都有。 | - | callback | AsyncCallback<number > | 是 | 每发生变化一次,调用一次此函数。 | - -- 返回值: - | 参数名 | 说明 | - | -------- | -------- | - | [Watcher](#watcher7) | 文件变化监听的实例。 | - -- 示例: - ``` - let ob = await fileio.createWatcher(filename, events, function(event){ - }); - ``` - - -## Readout - -仅用于read方法,获取文件的读取结果。 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| bytesRead | number | 是 | 是 | 实际读取长度。 | -| offset | number | 是 | 是 | 读取数据相对于缓冲区首地址的偏移。 | -| buffer | ArrayBufer | 是 | 是 | 保存读取数据的缓冲区。 | - - -## Stat - -文件具体信息,在调用Stat的方法前,需要先通过[stat()](#fileiostat)方法(同步或异步)来构建一个Stat实例。 - - -### 属性 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| dev | number | 是 | 否 | 标识包含该文件的主设备号。 | -| ino | number | 是 | 否 | 标识该文件。通常同设备上的不同文件的INO不同。 | -| mode | number | 是 | 否 | 表示文件类型及权限,其首 4 位表示文件类型,后 12 位表示权限。各特征位的含义如下:
- 0o170000:可用于获取文件类型的掩码。
- 0o140000:文件是套接字。
- 0o120000:文件是符号链接。
- 0o100000:文件是一般文件。
- 0o060000:文件属于块设备。
- 0o040000:文件是目录。
- 0o020000:文件是字符设备。
- 0o010000:文件是具名管道,即FIFO。
- 0o0700:可用于获取用户权限的掩码。
- 0o0400:用户读,对于普通文件,所有者可读取文件;对于目录,所有者可读取目录项。
- 0o0200:用户写,对于普通文件,所有者可写入文件;对于目录,所有者可创建/删除目录项。
- 0o0100:用户执行,对于普通文件,所有者可执行文件;对于目录,所有者可在目录中搜索给定路径名。
- 0o0070:可用于获取用户组权限的掩码。
- 0o0040:用户组读,对于普通文件,所有用户组可读取文件;对于目录,所有用户组可读取目录项。
- 0o0020:用户组写,对于普通文件,所有用户组可写入文件;对于目录,所有用户组可创建/删除目录项。
- 0o0010:用户组执行,对于普通文件,所有用户组可执行文件;对于目录,所有用户组是否可在目录中搜索给定路径名。
- 0o0007:可用于获取其他用户权限的掩码。
- 0o0004:其他读,对于普通文件,其余用户可读取文件;对于目录,其他用户组可读取目录项。
- 0o0002:其他写,对于普通文件,其余用户可写入文件;对于目录,其他用户组可创建/删除目录项。
- 0o0001:其他执行,对于普通文件,其余用户可执行文件;对于目录,其他用户组可在目录中搜索给定路径名。 | -| nlink | number | 是 | 否 | 文件的硬链接数。 | -| uid | number | 是 | 否 | 文件所有者的ID。 | -| gid | number | 是 | 否 | 文件所有组的ID。 | -| rdev | number | 是 | 否 | 标识包含该文件的从设备号。 | -| size | number | 是 | 否 | 文件的大小,以字节为单位。仅对普通文件有效。 | -| blocks | number | 是 | 否 | 文件占用的块数,计算时块大小按512B计算。 | -| atime | number | 是 | 否 | 上次访问该文件的时间,表示距1970年1月1日0时0分0秒的秒数。 | -| mtime | number | 是 | 否 | 上次修改该文件的时间,表示距1970年1月1日0时0分0秒的秒数。 | -| ctime | number | 是 | 否 | 最近改变文件状态的时间,表示距1970年1月1日0时0分0秒的秒数。 | - - -### isBlockDevice - -isBlockDevice(): boolean - -用于判断当前目录项是否是块特殊文件。一个块特殊文件只能以块为粒度进行访问,且访问的时候带缓存。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 表示当前目录项是否是块特殊设备。 | - -- 示例: - ``` - let isBLockDevice = fileio.statSync(path).isBlockDevice(); - ``` - - -### isCharacterDevice - -isCharacterDevice(): boolean - -用于判断当前目录项是否是字符特殊文件。一个字符特殊设备可进行随机访问,且访问的时候不带缓存。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 表示当前目录项是否是字符特殊设备。 | - -- 示例: - ``` - let isCharacterDevice = fileio.statSync(path).isCharacterDevice(); - ``` - - -### isDirectory - -isDirectory(): boolean - -用于判断当前目录项是否是目录。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 表示当前目录项是否是目录。 | - -- 示例: - ``` - let isDirectory = fileio.statSync(path).isDirectory(); - ``` - - -### isFIFO - -isFIFO(): boolean - -用于判断当前目录项是否是命名管道(有时也称为FIFO)。命名管道通常用于进程间通信。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 表示当前目录项是否是 FIFO。 | - -- 示例: - ``` - let isFIFO = fileio.statSync(path).isFIFO(); - ``` - - -### isFile - -isFile(): boolean - -用于判断当前目录项是否是普通文件。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 表示当前目录项是否是普通文件。 | - -- 示例: - ``` - let isFile = fileio.statSync(fpath).isFile(); - ``` - - -### isSocket - -isSocket(): boolean - -用于判断当前目录项是否是套接字。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 表示当前目录项是否是套接字。 | - -- 示例: - ``` - let isSocket = fileio.statSync(path).isSocket(); - ``` - - -### isSymbolicLink - -isSymbolicLink(): boolean - -用于判断当前目录项是否是符号链接。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 表示当前目录项是否是符号链接。 | - -- 示例: - ``` - let isSymbolicLink = fileio.statSync(path).isSymbolicLink(); - ``` - - -## Watcher7+ - -Watcher是文件变化监听的实例,调用Watcher.stop()方法(同步或异步)来停止文件监听。 - - -### stop7+ - -stop(): void - -以异步方法关闭watcher监听,使用promise形式返回结果。 - -- 示例: - ``` - fileio.stop(); - ``` - - -### stop7+ - -stop(callback: AsyncCallback): void - -以异步方法关闭watcher监听,使用callback形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<void> | 是 | 以异步方法关闭watcher监听之后的回调。 | - -- 示例: - ``` - fileio.stop(function(err){ - }); - ``` - - -## Stream7+ - -文件流,在调用Stream的方法前,需要先通过createStream()方法(同步或异步)来构建一个Stream实例。 - - -### close7+ - -close(): Promise<void> - -异步关闭文件流,使用promise形式返回结果。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | 表示异步关闭文件流的结果。 | - -- 示例: - ``` - let ss= fileio.createStreamSync(path); - await ss.close(); - ``` - - -### close7+ - -close(callback: AsyncCallback<void>): void - -异步关闭文件流,使用callback形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<void> | 是 | 异步关闭文件流之后的回调。 | - -- 示例: - ``` - let ss= fileio.createStreamSync(path); - ss.close(function (err) { - }); - ``` - - -### closeSync7+ - -closeSync(): void - -同步关闭文件流。 - -- 示例: - ``` - let ss= fileio.createStreamSync(path); - ss.closeSync(); - ``` - - -### flush7+ - -flush(): Promise<void> - -异步刷新文件流,使用promise形式返回结果。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | 表示异步刷新文件流的结果。 | - -- 示例: - ``` - let ss= fileio.createStreamSync(path); - await ss.flush(); - ``` - - -### flush7+ - -flush(callback: AsyncCallback<void>): void - -异步刷新文件流,使用callback形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<void> | 是 | 异步刷新文件流后的回调函数。 | - -- 示例: - ``` - let ss= fileio.createStreamSync(path); - ss.flush(function (err) { - expect(fileio.unlinkSync(fpath)).assertNull(); - }); - ``` - - -### flushSync7+ - -flushSync(): void - -同步刷新文件流。 - -- 示例: - ``` - let ss= fileio.createStreamSync(path); - ss.flushSync(); - ``` - - -### write7+ - -write(buffer: ArrayBuffer | string, options?: Object): Promise<number> - -以异步方法将数据写入流文件,使用promise形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | buffer | ArrayBuffer \| string | 是 | 待写入文件的数据,可来自缓冲区或字符串。 | - | options | Object | 否 | 支持如下选项:
- offset,number类型,表示期望写入数据的位置相对于数据首地址的偏移。可选,默认为0。
- length,number类型,表示期望写入数据的长度。可选,默认缓冲区长度减去偏移长度。
- position,number类型,表示期望写入文件的位置。可选,默认从当前位置开始写。
- encoding,string类型,当数据是string类型时有效,表示数据的编码方式,默认 'utf-8'。仅支持 'utf-8'。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<number> | 实际写入的长度。 | - -- 示例: - ``` - let ss= fileio.createStreamSync(fpath, "r+"); - let num = await ss.write("hello, world",{offset: 1,length: 5,position: 5,encoding :'utf-8'}); - ``` - - -### write7+ - -write(buffer:ArrayBuffer | string,options?:Object, callback:AsyncCallback<number>): void - -以异步方法将数据写入流文件,使用callback形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | buffer | ArrayBuffer \| string | 是 | 待写入文件的数据,可来自缓冲区或字符串。 | - | options | Object | 否 | 支持如下选项:
- offset,number类型,表示期望写入数据的位置相对于数据首地址的偏移。可选,默认为0。
- length,number类型,表示期望写入数据的长度。可选,默认缓冲区长度减去偏移长度。
- position,number类型,表示期望写入文件的位置。可选,默认从当前位置开始写。
- encoding,string类型,当数据是string类型时有效,表示数据的编码方式,默认 'utf-8'。仅支持 'utf-8'。 | - | callback | AsyncCallback<number> | 是 | 异步写入完成后执行的回调函数。 | - -- 示例: - ``` - let ss= fileio.createStreamSync(fpath, "r+"); - ss.write("hello, world", {offset: 1, length: 5, position: 5, encoding :'utf-8'}, function (err, bytesWritten) { - if (!err) { - console.log(bytesWritten) - } - }); - ``` - - -### writeSync7+ - -writeSync(buffer: ArrayBuffer | string, options?:Object): number - -以同步方法将数据写入流文件。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | buffer | ArrayBuffer \| string | 是 | 待写入文件的数据,可来自缓冲区或字符串。 | - | options | Object | 否 | 支持如下选项:
- offset,number类型,表示期望写入数据的位置相对于数据首地址的偏移。可选,默认为0。
- length,number类型,表示期望写入数据的长度。可选,默认缓冲区长度减去偏移长度。
- position,number类型,表示期望写入文件的位置。可选,默认从当前位置开始写。
- encoding,string类型,当数据是string类型时有效,表示数据的编码方式,默认 'utf-8'。仅支持 'utf-8'。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 实际写入的长度。 | - -- 示例: - ``` - let ss= fileio.createStreamSync(fpath,"r+"); - let num = ss.writeSync("hello, world", {offset: 1, length: 5, position: 5, encoding :'utf-8'}); - ``` - - -### read7+ - -read(buffer: ArrayBuffer, options?: Object): Promise<Readout> - -以异步方法从流文件读取数据,使用promise形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | buffer | ArrayBuffer | 是 | 用于读取文件的缓冲区。 | - | options | Object | 否 | 支持如下选项:
- offset,number类型,表示将数据读取到缓冲区的位置,即相对于缓冲区首地址的偏移。可选,默认为0。
- length,number类型,表示期望读取数据的长度。可选,默认缓冲区长度减去偏移长度。
- position,number类型,表示期望读取文件的位置。可选,默认从当前位置开始读。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<[Readout](#readout)> | 读取的结果。 | - -- 示例: - ``` - let ss = fileio.createStreamSync(fpath, "r+"); - let readOut = await ss.read(new ArrayBuffer(4096), {offset: 1, length: 5, position: 5}); - ``` - - -### read7+ - -read(buffer: ArrayBuffer, options?: Object, callback: AsyncCallback<Readout>): void - -以异步方法从流文件读取数据,使用callback形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | buffer | ArrayBuffer | 是 | 用于读取文件的缓冲区。 | - | options | Object | 否 | 支持如下选项:
- offset,number类型,表示将数据读取到缓冲区的位置,即相对于缓冲区首地址的偏移。可选,默认为0。
- length,number类型,表示期望读取数据的长度。可选,默认缓冲区长度减去偏移长度。
- position,number类型,表示期望读取文件的位置。可选,默认从当前位置开始读。 | - | callback | AsyncCallback<[Readout](#readout)> | 是 | 异步从流文件读取数据之后的回调。 | - -- 示例: - ``` - let ss = fileio.createStreamSync(fpath, "r+"); - ss.read(new ArrayBuffer(4096),{offset: 1, length: 5, position: 5},function (err, readOut) { - if (!err) { - console.log(readOut) - } - }); - ``` - - -### readSync7+ - -readSync(buffer: ArrayBuffer, options?: Object): number - -以同步方法从流文件读取数据。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | buffer | ArrayBuffer | 是 | 用于读取文件的缓冲区。 | - | options | Object | 否 | 支持如下选项:
- offset,number类型,表示将数据读取到缓冲区的位置,即相对于缓冲区首地址的偏移。可选,默认为0。
- length,number类型,表示期望读取数据的长度。可选,默认缓冲区长度减去偏移长度。
- position,number类型,表示期望读取文件的位置。可选,默认从当前位置开始读。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 实际读取的长度。 | - -- 示例: - ``` - let ss = fileio.createStreamSync(fpath, "r+"); - let num = ss.readSync(new ArrayBuffer(4096), {offset: 1, length: 5, position: 5}); - ``` - - -## Dir - -管理目录,在调用Dir的方法前,需要先通过[opendir()](#fileioopendir)方法(同步或异步)来构建一个Dir实例。 - - -### read - -read(): Promise<Dirent> - -异步读取下一个目录项,使用promise形式返回结果。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<[Dirent](#dirent)> | 表示异步读取目录项的结果。 | - -- 示例: - ``` - let dir = fileio.opendirSync(dpath); - let dirent = await dir.read(); - ``` - - -### read - -read(callback: AsyncCallback<Dirent>): void - -异步读取下一个目录项,使用callback形式返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<[Dirent](#dirent)> | 是 | 异步读取下一个目录项之后的回调。 | - -- 示例: - ``` - let dir = fileio.opendirSync(dpath); - dir.read(function (err, dirent) { - if (!err) { - console.log(dirent.name) - } - }); - ``` - - -### readSync - -readSync(): Dirent - -同步读取下一个目录项。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [Dirent](#dirent) | 表示一个目录项。 | - -- 示例: - ``` - let dir = fileio.opendirSync(dpath); - let dirent = dir.readSync(); - ``` - - -### closeSync - -closeSync(): void - -用于关闭目录。目录被关闭后,Dir中持有的文件描述将被释放,后续将无法从Dir中读取目录项。 - -- 示例: - ``` - let dir = fileio.opendirSync(dpath); - dir.closeSync(); - ``` - - -## Dirent - -在调用Dirent的方法前,需要先通过[dir.read()](#read)方法(同步或异步)来构建一个Dirent实例。 - - -### 属性 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| name | string | 是 | 否 | 目录项的名称。 | - - -### isBlockDevice - -isBlockDevice(): boolean - -用于判断当前目录项是否是块特殊文件。一个块特殊文件只能以块为粒度进行访问,且访问的时候带缓存。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 表示当前目录项是否是块特殊设备。 | - -- 示例: - ``` - let dir = fileio.opendirSync(dpath); - let isBLockDevice = dir.readSync().isBlockDevice(); - ``` - - -### isCharacterDevice - -isCharacterDevice(): boolean - -用于判断当前目录项是否是字符特殊设备。一个字符特殊设备可进行随机访问,且访问的时候不带缓存。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 表示当前目录项是否是字符特殊设备。 | - -- 示例: - ``` - let dir = fileio.opendirSync(dpath); - let isCharacterDevice = dir.readSync().isCharacterDevice(); - ``` - - -### isDirectory - -isDirectory(): boolean - -用于判断当前目录项是否是目录。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 表示当前目录项是否是目录。 | - -- 示例: - ``` - let dir = fileio.opendirSync(dpath); - let isDirectory = dir.readSync().isDirectory(); - ``` - - -### isFIFO - -isFIFO(): boolean - -用于判断当前目录项是否是命名管道(有时也称为FIFO)。命名管道通常用于进程间通信。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 表示当前目录项是否是FIFO。 | - -- 示例: - ``` - let dir = fileio.opendirSync(dpath); - let isFIFO = dir.readSync().isFIFO(); - ``` - - -### isFile - -isFile(): boolean - -用于判断当前目录项是否是普通文件。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 表示当前目录项是否是普通文件。 | - -- 示例: - ``` - let dir = fileio.opendirSync(dpath); - let isFile = dir.readSync().isFile(); - ``` - - -### isSocket - -isSocket(): boolean - -用于判断当前目录项是否是套接字。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 表示当前目录项是否是套接字。 | - -- 示例: - ``` - let dir = fileio.opendirSync(dpath); - let isSocket = dir.readSync().isSocket(); - ``` - - -### isSymbolicLink - -isSymbolicLink(): boolean - -用于判断当前目录项是否是符号链接。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 表示当前目录项是否是符号链接。 | - -- 示例: - ``` - let dir = fileio.opendirSync(dpath); - let isSymbolicLink = dir.readSync().isSymbolicLink(); - ``` diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/06.\346\226\207\344\273\266\347\256\241\347\220\206/02.Statfs\347\256\241\347\220\206.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/06.\346\226\207\344\273\266\347\256\241\347\220\206/02.Statfs\347\256\241\347\220\206.md" deleted file mode 100644 index 718fd352574aff92428220a8074c35e0ea341b0b..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/06.\346\226\207\344\273\266\347\256\241\347\220\206/02.Statfs\347\256\241\347\220\206.md" +++ /dev/null @@ -1,130 +0,0 @@ ---- -title: Statfs管理 -permalink: /pages/010c010602 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# statfs - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - -## 导入模块 - -```js -import statfs from '@ohos.statfs' -``` - -## 使用说明 - -使用该功能模块对文件/目录进行操作前,需要先获取其绝对路径,获取方式及其接口用法请参考:[Context模块的接口getOrCreateLocalDir](/pages/010c010108)。 - -“文件/目录绝对路径”=“应用目录路径”+“文件/目录名” - -通过上述接口获取到应用目录路径dir,文件名为“xxx.txt”,文件所在绝对路径为: - -```js -let path = dir + "xxx.txt" -``` - -## 系统能力 - -SystemCapability.FileManagement.File.FileIO - -## statfs.getFreeBytes - -getFreeBytes(path:string):Promise<number> - -异步方法获取指定文件系统空闲字节数,以Promise形式返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | ------ | ------ | ---- | ---------------------------- | - | path | string | 是 | 需要查询的文件系统的文件路径 | - -- 返回值: - - | 类型 | 说明 | - | --------------------- | -------------- | - | Promise<number> | 返回空闲字节数 | - -- 示例: - - ```js - let num = await statfs.getFreeBytes(path); - ``` - -## statfs.getFreeBytes - -getFreeBytes(path:string, callback:AsyncCallback<number>): void - -异步方法获取指定文件系统空闲字节数,使用callback形式返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | --------------------------- | ---- | ---------------------------- | - | path | string | 是 | 需要查询的文件系统的文件路径 | - | callback | AsyncCallback<number> | 是 | 异步获取空闲字节数之后的回调 | - -- 示例: - - ```js - statfs.getFreeBytes(path, function(err, number){ - //do something - }); - ``` - -## statfs.getTotalBytes - -getTotalBytes.(path:string):Promise<number> - -异步方法获取指定文件系统总字节数,以Promise形式返回结果。 - -- 参数: - - | 参数 | 类型 | 必填 | 说明 | - | ---- | ------ | ---- | ---------------------------- | - | path | string | 是 | 需要查询的文件系统的文件路径 | - -- 返回值: - - | 类型 | 说明 | - | --------------------- | ------------ | - | Promise<number> | 返回总字节数 | - -- 示例: - - ```js - let num = await statfs.getTotalBytes(path); - ``` - -## statfs.getTotalBytes - -getTotalBytes(path:string, callback:AsyncCallback<number>): void - -异步方法获取指定文件系统总字节数,使用callback形式返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | --------------------------- | ---- | ---------------------------- | - | path | string | 是 | 需要查询的文件系统的文件路径 | - | callback | AsyncCallback<number> | 是 | 异步获取总字节数之后的回调 | - -- 示例: - - ```js - statfs.getTotalBytes(path, function(err, number){ - //do something - }); - ``` - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/06.\346\226\207\344\273\266\347\256\241\347\220\206/03.\347\233\256\345\275\225\347\216\257\345\242\203.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/06.\346\226\207\344\273\266\347\256\241\347\220\206/03.\347\233\256\345\275\225\347\216\257\345\242\203.md" deleted file mode 100644 index 2608805a3064b70d5b58840100bd2ac1c19d15f3..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/06.\346\226\207\344\273\266\347\256\241\347\220\206/03.\347\233\256\345\275\225\347\216\257\345\242\203.md" +++ /dev/null @@ -1,112 +0,0 @@ ---- -title: 目录环境 -permalink: /pages/010c010603 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 目录环境能力 - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - -## 导入模块 - -```js -import environment from '@ohos.environment'; -``` - -## 系统能力 - -SystemCapability.FileManagement.File.Environment - -## environment.getStorageDataDir - -getStorageDataDir():Promise<string> - -异步方法获取内存存储根目录,以promise形式返回结果。 - -- 返回值: - - | 类型 | 说明 | - | --------------------- | ---------------- | - | Promise<string> | 返回存存储根目录 | - -- 示例: - - ```js - environment.getStorageDataDir().then(function(path){ - // do something - }).catch(function(error){ - - }); - ``` - -## environment.getStorageDataDir - -getStorageDataDir(callback:AsyncCallback<string>):void - -异步方法获取内存存储根目录,以callback形式返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | --------------------------- | ---- | -------------------------------- | - | callback | AsyncCallback<string> | 是 | 异步获取内存存储根目录之后的回调 | - -- 示例: - - ```js - environment.getStorageDataDir(function(error, path){ - // do something - }); - ``` - -## environment.getUserDataDir - -getUserDataDir():Promise<string> - -异步方法获取公共文件根目录,以promise形式返回结果。 - -- 返回值: - - | 类型 | 说明 | - | --------------------- | ------------------ | - | Promise<string> | 返回公共文件根目录 | - -- 示例: - - ```js - environment.getUserDataDir().then(function(path){ - // do something - }).catch(function(error){ - - }); - ``` - -## environment.getUserDataDir - -getUserDataDir(callback:AsyncCallback<string>): void - -异步方法获取公共文件根目录,以callback形式返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | --------------------------- | ---- | -------------------------------- | - | callback | AsyncCallback<string> | 是 | 异步获取公共文件根目录之后的回调 | - -- 示例: - - ```js - environment.getUserDataDir(function(error, path){ - // do something - }); - ``` - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/07.\350\264\246\345\217\267\347\256\241\347\220\206/01.\345\210\206\345\270\203\345\274\217\345\270\220\345\217\267\347\256\241\347\220\206.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/07.\350\264\246\345\217\267\347\256\241\347\220\206/01.\345\210\206\345\270\203\345\274\217\345\270\220\345\217\267\347\256\241\347\220\206.md" deleted file mode 100644 index 32a3d92feffa4a9f9358e8beed83bb9e2db995bd..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/07.\350\264\246\345\217\267\347\256\241\347\220\206/01.\345\210\206\345\270\203\345\274\217\345\270\220\345\217\267\347\256\241\347\220\206.md" +++ /dev/null @@ -1,162 +0,0 @@ ---- -title: 分布式帐号管理 -permalink: /pages/010c010701 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 分布式帐号管理 - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import account_distributedAccount from '@ohos.account.distributedAccount'; -``` - - -## 系统能力 - -SystemCapability.Account.OsAccount - - -## account_distributedAccount.getDistributedAccountAbility - -getDistributedAccountAbility(): DistributedAccountAbility - -获取分布式帐号单实例对象。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [DistributedAccountAbility](#distributedaccountability) | 返回一个实例,实例提供查询和更新分布式帐号登录状态方法。 | - -- 示例: - ``` - const accountAbility = account_distributedAccount.getDistributedAccountAbility(); - ``` - -## DistributedAccountAbility - -提供查询和更新分布式帐号登录状态方法(需要先获取分布式帐号的单实例对象)。 - -### queryOsAccountDistributedInfo - -queryOsAccountDistributedInfo(callback: AsyncCallback<DistributedInfo>): void - -获取分布式帐号信息,使用callback回调异步返回结果。 - -需要权限:ohos.permission.MANAGE_LOCAL_ACCOUNTS,该权限仅供系统应用使用。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<[DistributedInfo](#distributedinfo)> | 是 | 获取分布式帐号信息的回调。 | - -- 示例: - ``` - const accountAbility = account_distributedAccount.getDistributedAccountAbility(); - accountAbility.queryOsAccountDistributedInfo((err, data) => { - console.log("queryOsAccountDistributedInfo err: " + JSON.stringify(err)); - console.log('Query account info name: ' + data.name); - console.log('Query account info id: ' + data.id); - }); - ``` - -### queryOsAccountDistributedInfo - -queryOsAccountDistributedInfo(): Promise<DistributedInfo> - -获取分布式帐号信息,使用Promise方式异步返回结果。 - -需要权限:ohos.permission.MANAGE_LOCAL_ACCOUNTS,该权限仅供系统应用使用。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<[DistributedInfo](#distributedinfo)> | Promise实例,用于获取异步返回结果。 | - -- 示例: - ``` - const accountAbility = account_distributedAccount.getDistributedAccountAbility(); - accountAbility.queryOsAccountDistributedInfo().then((data) => { - console.log('Query account info name: ' + data.name); - console.log('Query account info id: ' + data.id); - }).catch((err) => { - console.log("queryOsAccountDistributedInfoerr: " + JSON.stringify(err)); - }); - ``` - -### updateOsAccountDistributedInfo - -updateOsAccountDistributedInfo(accountInfo: DistributedInfo, callback: AsyncCallback<void>): void - -更新分布式帐号信息,使用callback回调异步返回结果。 - -需要权限:ohos.permission.MANAGE_LOCAL_ACCOUNTS,该权限仅供系统应用使用。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | accountInfo | [DistributedInfo](#distributedinfo) | 是 | 分布式帐号信息。 | - | callback | AsyncCallback<void> | 是 | 更新分布式帐号信息的回调。 | - -- 示例: - ``` - const accountAbility = account_distributedAccount.getDistributedAccountAbility(); - let accountInfo = {id: '12345', name: 'ZhangSan', event: 'Ohos.account.event.LOGIN'}; - accountAbility.updateOsAccountDistributedInfo(accountInfo, (err) => { - console.log("queryOsAccountDistributedInfo err: " + JSON.stringify(err)); - }); - ``` - -### updateOsAccountDistributedInfo - -updateOsAccountDistributedInfo(accountInfo: DistributedInfo): Promise<void> - -更新分布式帐号信息,使用Promise方式异步返回结果。 - -需要权限:ohos.permission.MANAGE_LOCAL_ACCOUNTS,该权限仅供系统应用使用。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | accountInfo | [DistributedInfo](#distributedinfo) | 是 | 分布式帐户信息。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | Promise实例,用于获取异步返回结果。 | - -- 示例: - ``` - const accountAbility = account_distributedAccount.getDistributedAccountAbility(); - let accountInfo = {id: '12345', name: 'ZhangSan', event: 'Ohos.account.event.LOGIN'}; - accountAbility.updateOsAccountDistributedInfo(accountInfo).then(() => { - console.log('updateOsAccountDistributedInfo Success'); - }).catch((err) => { - console.log("updateOsAccountDistributedInfo err: " + JSON.stringify(err)); - }); - ``` - - -## DistributedInfo - -提供操作系统帐户的分布式信息。 - - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| name | string | 是 | 分布式帐号名称,非空字符串。 | -| id | string | 是 | 分布式帐号UID,非空字符串。 | -| event | string | 是 | 分布式帐号登录状态,包括登录、登出、Token失效和注销,分别对应以下字符串:
- Ohos.account.event.LOGIN
- Ohos.account.event.LOGOUT
- Ohos.account.event.TOKEN_INVALID
- Ohos.account.event.LOGOFF | -| scalableData | object | 否 | 分布式帐号扩展信息,根据业务所需,以k-v形式传递定制化信息。
说明:该参数是预留的可选项,目前查询和更新的方法实现中未使用。 | diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/07.\350\264\246\345\217\267\347\256\241\347\220\206/02.\345\272\224\347\224\250\345\270\220\345\217\267\347\256\241\347\220\206.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/07.\350\264\246\345\217\267\347\256\241\347\220\206/02.\345\272\224\347\224\250\345\270\220\345\217\267\347\256\241\347\220\206.md" deleted file mode 100644 index 57815164049ac3f04b62eef91a9e5f4b6776996d..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/07.\350\264\246\345\217\267\347\256\241\347\220\206/02.\345\272\224\347\224\250\345\270\220\345\217\267\347\256\241\347\220\206.md" +++ /dev/null @@ -1,1669 +0,0 @@ ---- -title: 应用帐号管理 -permalink: /pages/010c010702 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 应用帐号管理 - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import account_appAccount from '@ohos.account.appAccount'; -``` - - -## 系统能力 - -SystemCapability.Account.AppAccount - - -## account_appAccount.createAppAccountManager - -createAppAccountManager(): AppAccountManager; - -应用帐号管理:获取应用帐号模块对象。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | AppAccountManager | 获取应用帐号模块的实例。 | - -- 示例: - ``` - var appAccountManager = account.createAppAccountManager(); - ``` - -## AppAccountManager - -管理应用帐号模块的实例。 - -### addAccount - -addAccount(name: string, callback: AsyncCallback<void>): void; - -将此应用的帐号名添加到帐号管理服务中,使用callback回调异步返回结果。 - -需要权限:无。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | ------------------- | ---- | ------------------------------------------ | - | name | string | 是 | 要添加的应用帐户的名称。 | - | callback | AsyncCallback<void> | 是 | 将此应用的帐号名添加到帐号管理服务的回调。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.addAccount("WangWu", (err) => { - console.log("addAccount err: " + JSON.stringify(err)); - }); - ``` - -### addAccount - -addAccount(name: string, extraInfo: string, callback: AsyncCallback<void>): void; - -将此应用程序的帐号名和额外信息添加到帐号管理服务中,使用callback回调异步返回结果。 - -需要权限:无。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | --------- | ------------------- | ---- | ------------------------------------------------------------ | - | name | string | 是 | 要添加的应用帐户的名称。 | - | extraInfo | string | 是 | 要添加的应用帐户的额外信息(例如token等),额外的信息不能是应用帐号的敏感信息。 | - | callback | AsyncCallback<void> | 是 | 将此应用程序的帐号名和额外信息添加到帐号管理服务中的回调。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.addAccount("LiSi", "token101", (err) => { - console.log("addAccount err: " + JSON.stringify(err)); - }); - ``` - - - -### addAccount - -addAccount(name: string, extraInfo?: string): Promise<void>; - -将此应用的帐号名或额外信息添加到帐号管理服务中,使用Promise方式异步返回结果。 - -需要权限:无。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | --------- | ------ | ---- | ------------------------------------------------------------ | - | name | string | 是 | 要添加的应用帐户的名称。 | - | extraInfo | string | 是 | 要添加的应用帐户的额外信息,额外的信息不能是应用帐号的敏感信息。 | - -- 返回值: - - | 类型 | 说明 | - | ------------- | ---------------------------------- | - | Promise<void> | romise实例,用于获取异步返回结果。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.addAccount("LiSi", "token101").then(()=> { - console.log('addAccount Success'); - }).catch((err) => { - console.log("addAccount err: " + JSON.stringify(err)); - }); - ``` - -### addAccountImplicitly8+ - -addAccountImplicitly(owner: string, authType: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void; - -根据指定的帐号所有者、鉴权类型和可选项,隐式地添加应用帐号,并使用callback回调异步返回结果。 - -需要权限:无。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | --------------------- | --- | -------------------------- | - | owner | string | 是 | 要添加的应用帐户的所有者包名。 | - | authType | string | 是 | 要添加的应用帐户的鉴权类型。 | - | options | {[key: string]: any} | 是 | 鉴权所需要的可选项。 | - | callback | AuthenticatorCallback | 是 | 认证器回调,用于返回鉴权结果。 | - -- 示例: - - ``` - import featureAbility from '@ohos.ability.featureAbility'; - - function onResultCallback(code, result) { - console.log("resultCode: " + code); - console.log("result: " + JSON.stringify(result)); - } - - function onRequestRedirectedCallback(request) { - let abilityStartSetting = {want: request}; - featureAbility.startAbility(abilityStartSetting, (err)=>{ - console.log("startAbility err: " + JSON.stringify(err)); - }); - } - - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.addAccountImplicitly("LiSi", "readAge", {}, { - onResult: onResultCallback, - onRequestRedirected: onRequestRedirectedCallback - }); - ``` - -### deleteAccount - -deleteAccount(name: string, callback: AsyncCallback<void>): void; - -从帐号管理服务中删除应用帐号,使用callback回调异步返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | ------------------- | ---- | ---------------------------------- | - | name | string | 是 | 要删除的应用帐户的名称。 | - | callback | AsyncCallback<void> | 是 | 帐号管理服务中删除应用帐号的回调。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.deleteAccount("ZhaoLiu", (err) => { - console.log("deleteAccount err: " + JSON.stringify(err)); - }); - ``` - -### deleteAccount - -deleteAccount(name: string): Promise<void>; - -从帐号管理服务中删除应用帐号,使用Promise方式异步返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | ------ | ------ | ---- | ------------------------ | - | name | string | 是 | 要删除的应用帐户的名称。 | - -- 返回值: - - | 类型 | 说明 | - | :------------ | :---------------------------------- | - | Promise<void> | Promise实例,用于获取异步返回结果。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.deleteAccount("ZhaoLiu").then(() => { - console.log('deleteAccount Success'); - }).catch((err) => { - console.log("deleteAccount err: " + JSON.stringify(err)); - }); - ``` - -### disableAppAccess - -disableAppAccess(name: string, bundleName: string, callback: AsyncCallback<void>): void; - -禁止指定第三方应用帐户的名称访问指定包名称的第三方应用,使用callback回调异步返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | ---------- | ------------------- | ---- | ------------------------------------------------------------ | - | name | string | 是 | 要禁用访问的第三方应用帐户的名称。 | - | bundleName | string | 是 | 第三方应用的包名。 | - | callback | AsyncCallback<void> | 是 | 禁止指定第三方应用帐户的名称访问指定包名称的第三方应用的回调。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.disableAppAccess("ZhangSan", "com.example.ohos.accountjsdemo", (err) => { - console.log("disableAppAccess err: " + JSON.stringify(err)); - }); - ``` - -### disableAppAccess - -disableAppAccess(name: string, bundleName: string): Promise<void>; - -禁止指定第三方应用帐户的名称访问指定包名称的第三方应用,使用Promise方式异步返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | ---------- | ------ | ---- | ---------------------------------- | - | name | string | 是 | 要禁用访问的第三方应用帐户的名称。 | - | bundleName | string | 是 | 第三方应用的包名。 | - -- 返回值: - - | 类型 | 说明 | - | :------------ | :---------------------------------- | - | Promise<void> | Promise实例,用于获取异步返回结果。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.disableAppAccess("ZhangSan", "com.example.ohos.accountjsdemo").then(() => { - console.log('disableAppAccess Success'); - }).catch((err) => { - console.log("disableAppAccess err: " + JSON.stringify(err)); - }); - ``` - -### enableAppAccess - -enableAppAccess(name: string, bundleName: string, callback: AsyncCallback<void>): void; - -允许指定第三方应用帐户的名称访问指定包名称的第三方应用,使用callback回调异步返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | ---------- | ------------------- | ---- | ------------------------------------------------------------ | - | name | string | 是 | 应用帐号名称。 | - | bundleName | string | 是 | 第三方应用的包名。 | - | callback | AsyncCallback<void> | 是 | 允许指定第三方应用帐户的名称访问指定包名称的第三方应用的回调。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.enableAppAccess("ZhangSan", "com.example.ohos.accountjsdemo", (err) => { - console.log("enableAppAccess: " + JSON.stringify(err)); - }); - ``` - -### enableAppAccess - -enableAppAccess(name: string, bundleName: string): Promise<void>; - -允许指定第三方应用帐户的名称访问指定包名称的第三方应用,使用Promise方式异步返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | ---------- | ------ | ---- | ------------------ | - | name | string | 是 | 应用帐号名称。 | - | bundleName | string | 是 | 第三方应用的包名。 | - -- 返回值: - - | 类型 | 说明 | - | :------------ | :---------------------------------- | - | Promise<void> | Promise实例,用于获取异步返回结果。 | - -- 示例: - - ``` - app_account_instance.enableAppAccess("ZhangSan", "com.example.ohos.accountjsdemo").then(() => { - console.log('enableAppAccess Success'); - }).catch((err) => { - console.log("enableAppAccess err: " + JSON.stringify(err)); - }); - ``` - -### checkAppAccountSyncEnable - -checkAppAccountSyncEnable(name: string, callback: AsyncCallback<boolean>): void; - -检查指定应用帐号是否允许应用数据同步,使用callback回调异步返回结果。 - -需要权限:ohos.permission.DISTRIBUTED_DATASYNC,系统应用可用。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | ---------------------- | ---- | -------------------------------------------- | - | name | string | 是 | 应用帐号名称。 | - | callback | AsyncCallback<boolean> | 是 | 检查指定应用帐号是否允许应用数据同步的回调。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.checkAppAccountSyncEnable("ZhangSan", (err, result) => { - console.log("checkAppAccountSyncEnable err: " + JSON.stringify(err)); - console.log('checkAppAccountSyncEnable result: ' + result); - }); - ``` - -### checkAppAccountSyncEnable - -checkAppAccountSyncEnable(name: string): Promise<boolean>; - -检查指定应用帐号是否允许应用数据同步,使用Promise方式异步返回结果。 - -需要权限:ohos.permission.DISTRIBUTED_DATASYNC,系统应用可用。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | ------ | ------ | ---- | -------------- | - | name | string | 是 | 应用帐号名称。 | - -- 返回值: - - | 类型 | 说明 | - | :--------------- | :---------------------------------- | - | Promise<boolean> | Promise实例,用于获取异步返回结果。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.checkAppAccountSyncEnable("ZhangSan").then((data) => { - console.log('checkAppAccountSyncEnable, result: ' + data); - }).catch((err) => { - console.log("checkAppAccountSyncEnable err: " + JSON.stringify(err)); - }); - ``` - -### setAccountCredential - -setAccountCredential(name: string, credentialType: string, credential: string,callback: AsyncCallback<void>): void; - -设置此应用程序帐号的凭据,使用callback回调异步返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | -------------- | ------------------- | ---- | ---------------------------- | - | name | string | 是 | 应用程序帐户的名称。 | - | credentialType | string | 是 | 要设置的凭据的类型。 | - | credential | string | 是 | 要设置的凭据。 | - | callback | AsyncCallback<void> | 是 | 设置此应用帐号的凭据的回调。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.setAccountCredential("ZhangSan", "credentialType001", "credential001", (err) => { - console.log("setAccountCredential err: " + JSON.stringify(err)); - }); - ``` - -### setAccountCredential - -setAccountCredential(name: string, credentialType: string, credential: string): Promise<void>; - -设置此应用程序帐号的凭据,使用Promise方式异步返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | -------------- | ------ | ---- | -------------------- | - | name | string | 是 | 应用帐户的名称。 | - | credentialType | string | 是 | 要设置的凭据的类型。 | - | credential | string | 是 | 要设置的凭据。 | - -- 返回值: - - | 类型 | 说明 | - | :------------ | :---------------------------------- | - | Promise<void> | Promise实例,用于获取异步返回结果。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.setAccountCredential("ZhangSan", "credentialType001", "credential001").then(() => { - console.log('setAccountCredential Success'); - }).catch((err) => { - console.log("setAccountCredential err: " + JSON.stringify(err)); - }); - ``` - -### setAccountExtraInfo - -setAccountExtraInfo(name: string, extraInfo: string, callback: AsyncCallback<void>): void; - -设置此应用程序帐号的额外信息,使用callback回调异步返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | --------- | ------------------- | ---- | -------------------------------- | - | name | string | 是 | 应用帐户的名称。 | - | extraInfo | string | 是 | 要设置的额外信息。 | - | callback | AsyncCallback<void> | 是 | 设置此应用帐号的额外信息的回调。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.setAccountExtraInfo("ZhangSan", "Tk002", (err) => { - console.log("setAccountExtraInfo err: " + JSON.stringify(err)); - }); - ``` - -### setAccountExtraInfo - -setAccountExtraInfo(name: string, extraInfo: string): Promise<void>; - -设置此应用程序帐号的额外信息,使用Promise方式异步返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | --------- | ------ | ---- | ------------------ | - | name | string | 是 | 应用帐户的名称。 | - | extraInfo | string | 是 | 要设置的额外信息。 | - -- 返回值: - - | 类型 | 说明 | - | :------------ | :---------------------------------- | - | Promise<void> | Promise实例,用于获取异步返回结果。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.setAccountExtraInfo("ZhangSan", "Tk002").then(() => { - console.log('setAccountExtraInfo Success'); - }).catch((err) => { - console.log("setAccountExtraInfo err: " + JSON.stringify(err)); - }); - ``` - -### setAppAccountSyncEnable - -setAppAccountSyncEnable(name: string, isEnable: boolean, callback: AsyncCallback<void>): void; - -设置指定的应用程序帐号是否允许应用程序数据同步,使用callback回调异步返回结果。 - -需要权限:ohos.permission.DISTRIBUTED_DATASYNC,系统应用可用。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | ------------------- | ---- | -------------------------------------------------- | - | name | string | 是 | 应用帐户的名称。 | - | isEnable | boolean | 是 | 是否允许应用数据同步。 | - | callback | AsyncCallback<void> | 是 | 设置指定的应用帐号是否允许应用程序数据同步的回调。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.setAppAccountSyncEnable("ZhangSan", true, (err) => { - console.log("setAppAccountSyncEnable err: " + JSON.stringify(err)); - }); - ``` - -### setAppAccountSyncEnable - -setAppAccountSyncEnable(name: string, isEnable: boolean): Promise<void>; - -设置指定的应用程序帐号是否允许应用程序数据同步,使用Promise方式异步返回结果。 - -需要权限:ohos.permission.DISTRIBUTED_DATASYNC,系统应用可用。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | ------- | ---- | ---------------------- | - | name | string | 是 | 应用帐户的名称。 | - | isEnable | boolean | 是 | 是否允许应用数据同步。 | - -- 返回值: - - | 类型 | 说明 | - | :------------ | :---------------------------------- | - | Promise<void> | Promise实例,用于获取异步返回结果。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager .setAppAccountSyncEnable("ZhangSan", true).then(() => { - console.log('setAppAccountSyncEnable Success'); - }).catch((err) => { - console.log("setAppAccountSyncEnable err: " + JSON.stringify(err)); - }); - ``` - -### setAssociatedData - -setAssociatedData(name: string, key: string, value: string, callback: AsyncCallback<void>): void; - -设置与此应用程序帐号关联的数据,使用callback回调异步返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | ------------------- | ---- | ---------------------------------- | - | name | string | 是 | 应用帐户的名称。 | - | key | string | 是 | 要设置的数据的键,密钥可以自定义。 | - | value | string | 是 | 要设置的数据的值。 | - | callback | AsyncCallback<void> | 是 | 设置与此应用帐号关联的数据的回调。 | - -- 示例: - - ``` - app_account_instance.setAssociatedData("ZhangSan", "k001", "v001", (err) => { - console.log("setAssociatedData err: " + JSON.stringify(err)); - }); - ``` - -### setAssociatedData - -setAssociatedData(name: string, key: string, value: string): Promise<void>; - -设置与此应用程序帐号关联的数据,使用Promise方式异步返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | ------ | ------ | ---- | ---------------------------------- | - | name | string | 是 | 应用帐户的名称。 | - | key | string | 是 | 要设置的数据的键,密钥可以自定义。 | - | value | string | 是 | 要设置的数据的值。 | - -- 返回值: - - | 类型 | 说明 | - | :------------ | :---------------------------------- | - | Promise<void> | Promise实例,用于获取异步返回结果。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.setAssociatedData("ZhangSan", "k001", "v001").then(() => { - console.log('setAssociatedData Success'); - }).catch((err) => { - console.log("setAssociatedData err: " + JSON.stringify(err)); - }); - ``` - -### getAccountCredential - -getAccountCredential(name: string, credentialType: string, callback: AsyncCallback<string>): void; - -获取此应用帐号的凭据,使用callback回调异步返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | -------------- | --------------------- | ---- | ---------------------------- | - | name | string | 是 | 应用帐号名称。 | - | credentialType | string | 是 | 要获取的凭据的类型。 | - | callback | AsyncCallback<string> | 是 | 获取此应用帐号的凭据的回调。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.getAccountCredential("ZhangSan", "credentialType001", (err, result) => { - console.log("getAccountCredential err: " + JSON.stringify(err)); - console.log('getAccountCredential result: ' + result); - }); - ``` - -### getAccountCredential - -getAccountCredential(name: string, credentialType: string): Promise<string>; - -获取此应用程序帐号的凭据,使用Promise方式异步返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | -------------- | ------ | ---- | -------------------- | - | name | string | 是 | 应用帐号名称。 | - | credentialType | string | 是 | 要获取的凭据的类型。 | - -- 返回值: - - | 类型 | 说明 | - | :-------------- | :---------------------------------- | - | Promise<string> | Promise实例,用于获取异步返回结果。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.getAccountCredential("ZhangSan", "credentialType001").then((data) => { - console.log('getAccountCredential, result: ' + data); - }).catch((err) => { - console.log("getAccountCredential err: " + JSON.stringify(err)); - }); - ``` - -### getAccountExtraInfo - -getAccountExtraInfo(name: string, callback: AsyncCallback<string>): void; - -获取此应用帐号的额外信息,使用callback回调异步返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | --------------------- | ---- | -------------------------------- | - | name | string | 是 | 应用帐号名称。 | - | callback | AsyncCallback<string> | 是 | 获取此应用帐号的额外信息的回调。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.getAccountExtraInfo("ZhangSan", (err, result) => { - console.log("getAccountExtraInfo err: " + JSON.stringify(err)); - console.log('getAccountExtraInfo result: ' + result); - }); - ``` - -### getAccountExtraInfo - -getAccountExtraInfo(name: string): Promise<string>; - -获取此应用程序帐号的额外信息,使用Promise方式异步返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | ------ | ------ | ---- | -------------- | - | name | string | 是 | 应用帐号名称。 | - -- 返回值: - - | 类型 | 说明 | - | :-------------- | :---------------------------------- | - | Promise<string> | Promise实例,用于获取异步返回结果。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.getAccountExtraInfo("ZhangSan").then((data) => { - console.log('getAccountExtraInfo, result: ' + data); - }).catch((err) => { - console.log("getAccountExtraInfo err: " + JSON.stringify(err)); - }); - ``` - -### getAssociatedData - -getAssociatedData(name: string, key: string, callback: AsyncCallback<string>): void; - -获取与此应用程序帐号关联的数据,使用callback回调异步返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | --------------------- | ---- | ---------------------------------- | - | name | string | 是 | 应用帐号名称。 | - | key | string | 是 | 要获取的数据的key。 | - | callback | AsyncCallback<string> | 是 | 获取与此应用帐号关联的数据的回调。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.getAssociatedData("ZhangSan", "k001", (err, result) => { - console.log("getAssociatedData err: " + JSON.stringify(err)); - console.log('getAssociatedData result: ' + result); - }); - ``` - -### getAssociatedData - -getAssociatedData(name: string, key: string): Promise<string>; - -获取与此应用程序帐号关联的数据,使用Promise方式异步返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | ------ | ------ | ---- | ------------------- | - | name | string | 是 | 应用帐号名称。 | - | key | string | 是 | 要获取的数据的key。 | - -- 返回值: - - | 类型 | 说明 | - | :-------------- | :---------------------------------- | - | Promise<string> | Promise实例,用于获取异步返回结果。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.getAssociatedData("ZhangSan", "k001").then((data) => { - console.log('getAssociatedData: ' + data); - }).catch((err) => { - console.log("getAssociatedData err: " + JSON.stringify(err)); - }); - ``` - -### getAllAccessibleAccounts - -getAllAccessibleAccounts(callback: AsyncCallback<Array<AppAccountInfo>>): void; - -获取全部应用已授权帐号信息。 - -需要权限:ohos.permission.GET_ACCOUNTS_PRIVILEGED,系统应用可用。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | ------------------------------------ | ---- | ---------------- | - | callback | AsyncCallback<Array<AppAccountInfo>> | 是 | 应用帐号信息列表 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.getAllAccessibleAccounts((err, data)=>{ - console.debug("getAllAccessibleAccounts err:" + JSON.stringify(err)); - console.debug("getAllAccessibleAccounts data:" + JSON.stringify(data)); - }); - ``` - -### getAllAccessibleAccounts - -getAllAccessibleAccounts(): Promise<Array<AppAccountInfo>>; - -获取全部应用已授权帐号信息。 - -需要权限:ohos.permission.GET_ACCOUNTS_PRIVILEGED,系统应用可用。 - -- 参数: - - | 类型 | 说明 | - | ------------------------------ | ----------------------------------- | - | Promise<Array<AppAccountInfo>> | Promise实例,用于获取异步返回结果。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.getAllAccessibleAccounts().then((data) => { - console.log('getAllAccessibleAccounts: ' + data); - }).catch((err) => { - console.log("getAllAccessibleAccounts err: " + JSON.stringify(err)); - }); - ``` - -### getAllAccounts - -getAllAccounts(owner: string, callback: AsyncCallback<Array<AppAccountInfo>>): void; - -获取指定应用全部帐号信息。 - -需要权限:ohos.permission.GET_ACCOUNTS_PRIVILEGED,系统应用可用。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | ------------------------------------ | ---- | ---------------- | - | owner | string | 是 | 应用包名称 | - | callback | AsyncCallback<Array<AppAccountInfo>> | 是 | 应用帐号信息列表 | - -- 示例: - - ``` - const appAccountManager = account.createAppAccountManager(); - const selfBundle = "com.example.actsgetallaaccounts"; - appAccountManager.getAllAccounts(selfBundle, (err, data)=>{ - console.debug("getAllAccounts err:" + JSON.stringify(err)); - console.debug("getAllAccounts data:" + JSON.stringify(data)); - }); - ``` - -### getAllAccounts - -getAllAccounts(owner: string): Promise<Array<AppAccountInfo>>; - -获取指定应用全部帐号信息。 - -需要权限:ohos.permission.GET_ACCOUNTS_PRIVILEGED,系统应用可用。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | ------ | ------ | ---- | ---------- | - | owner | string | 是 | 应用包名称 | - -- 参数: - - | 类型 | 说明 | - | ------------------------------ | ----------------------------------- | - | Promise<Array<AppAccountInfo>> | Promise实例,用于获取异步返回结果。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - const selfBundle = "com.example.actsgetallaaccounts"; - appAccountManager.getAllAccounts(selfBundle).then((data) => { - console.log('getAllAccounts: ' + data); - }).catch((err) => { - console.log("getAllAccounts err: " + JSON.stringify(err)); - }); - ``` - -### on('change') - -on(type: 'change', owners: Array<string>, callback: Callback<Array<AppAccountInfo>>): void; - -订阅指定帐号所有者的帐户变更事件,使用callback回调异步返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | ------------------------------- | ---- | ------------------------------------------------------------ | - | type | 'change' | 是 | 关于帐户更改事件,当帐户所有者更新帐户时,订阅者将收到通知。 | - | owners | Array<string> | 是 | 指示帐户的所有者。 | - | callback | Callback<Array<AppAccountInfo>> | 是 | 订阅指定帐号所有者的帐户变更事件的回调。 | - -- 示例: - - ``` - const appAccountManager = account.createAppAccountManager(); - function changeOnCallback(data){ - console.debug("receive change data:" + JSON.stringify(data)); - } - try{ - appAccountManager.on('change', ["com.example.actsaccounttest"], changeOnCallback); - } - catch(err){ - console.error("on accountOnOffDemo err:" + JSON.stringify(err)); - } - ``` - -### off('change') - -off(type: 'change', callback?: Callback<void>): void; - -取消订阅帐号事件,使用callback回调异步返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------------------- | ---- | ------------------------ | - | type | 'change' | 是 | 关于帐户更改事件。 | - | callback | Callback<void> | 否 | 取消订阅帐号事件的回调。 | - -- 示例: - - ``` - const appAccountManager = account.createAppAccountManager(); - function changeOnCallback(data){ - console.debug("receive change data:" + JSON.stringify(data)); - appAccountManager.off('change', function(){ - console.debug("off finish"); - }) - } - try{ - appAccountManager.on('change', ["com.example.actsaccounttest"], changeOnCallback); - } - catch(err){ - console.error("on accountOnOffDemo err:" + JSON.stringify(err)); - } - ``` - -### authenticate8+ - -authenticate(name: string, owner: string, authType: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void; - -鉴权应用帐户以获取OAuth令牌,使用callback回调异步返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | --------------------- | ---- | --------------------------- | - | name | string | 是 | 要鉴权的应用帐户的名称。 | - | owner | string | 是 | 要鉴权的应用帐户的所有者包名。 | - | authType | string | 是 | 鉴权类型。 | - | options | {[key: string]: any} | 是 | 鉴权所需的可选项。 | - | callback | AuthenticatorCallback | 是 | 认证器回调,用于返回鉴权结果。 | - -- 示例: - - ``` - import featureAbility from '@ohos.ability.featureAbility'; - - function onResultCallback(code, result) { - console.log("resultCode: " + code); - console.log("result: " + JSON.stringify(result)); - } - - function onRequestRedirectedCallback(request) { - let abilityStartSetting = {want: request}; - featureAbility.startAbility(abilityStartSetting, (err)=>{ - console.log("startAbility err: " + JSON.stringify(err)); - }); - } - - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.authenticate("LiSi", "com.example.ohos.accountjsdemo", "readAge", {}, { - onResult: onResultCallback, - onRequestRedirected: onRequestRedirectedCallback - }); - ``` - -### getOAuthToken8+ - -getOAuthToken(name: string, owner: string, authType: string, callback: AsyncCallback<string>): void; - -获取指定应用帐户和鉴权类型的OAuth令牌,使用callback回调异步返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | --------------------------- | ---- | -------------------- | - | name | string | 是 | 应用帐户的名称。 | - | owner | string | 是 | 应用帐户的所有者包名。 | - | authType | string | 是 | 鉴权类型。 | - | callback | AsyncCallback<string> | 是 | 查询结果的回调。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.getOAuthToken("LiSi", "com.example.ohos.accountjsdemo", "readAge", (err, data) => { - console.log('getOAuthToken err: ' + JSON.stringify(err)); - console.log('getOAuthToken token: ' + data); - }); - ``` - -### getOAuthToken8+ - -getOAuthToken(name: string, owner: string, authType: string): Promise<string>; - -获取指定应用帐户和鉴权类型的OAuth令牌,使用Promise方式异步返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | ------ | ---- | -------------------- | - | name | string | 是 | 应用帐户的名称。 | - | owner | string | 是 | 应用帐户的所有者包名。 | - | authType | string | 是 | 鉴权类型。 | - -- 参数: - - | 类型 | 说明 | - | --------------------- | -------------------------------- | - | Promise<string> | Promise实例,用于获取异步返回结果。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.getOAuthToken("LiSi", "com.example.ohos.accountjsdemo", "readAge").then((data) => { - console.log('getOAuthToken token: ' + data); - }).catch((err) => { - console.log("getOAuthToken err: " + JSON.stringify(err)); - }); - ``` - -### setOAuthToken8+ - -setOAuthToken(name: string, authType: string, token: string, callback: AsyncCallback<void>): void; - -设置指定应用帐户和鉴权类型的OAuth令牌,使用callback回调异步返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | ------------------------- | ---- | ------------- | - | name | string | 是 | 应用帐户的名称。 | - | authType | string | 是 | 鉴权类型。 | - | token | string | 是 | OAuth令牌。 | - | callback | AsyncCallback<void> | 是 | 设置结果的回调。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.setOAuthToken("LiSi", "readAge", "xxxx", (err) => { - console.log('setOAuthToken err: ' + JSON.stringify(err)); - }); - ``` - -### setOAuthToken8+ - -setOAuthToken(name: string, authType: string, token: string): Promise<void>; - -设置指定应用帐户和鉴权类型的OAuth令牌,使用Promise方式异步返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | ------ | ---- | ------------- | - | name | string | 是 | 应用帐户的名称。 | - | authType | string | 是 | 鉴权类型。 | - | token | string | 是 | OAuth令牌。 | - -- 参数: - - | 类型 | 说明 | - | ------------------- | -------------------------------- | - | Promise<void> | Promise实例,用于获取异步返回结果。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.setOAuthToken("LiSi", "readAge", "xxxx").then(() => { - console.log('setOAuthToken successfully'); - }).catch((err) => { - console.log('setOAuthToken err: ' + JSON.stringify(err)); - }); - ``` - -### deleteOAuthToken8+ - -deleteOAuthToken(name: string, owner: string, authType: string, token: string, callback: AsyncCallback<void>): void; - -删除指定应用帐户和鉴权类型的OAuth令牌,使用callback回调异步返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | ------------------------- | ---- | ------------------ | - | name | string | 是 | 应用帐户的名称。 | - | owner | string | 是 | 应用帐户的所有者包名。 | - | authType | string | 是 | 鉴权类型。 | - | token | string | 是 | 要删除的OAuth令牌。 | - | callback | AsyncCallback<void> | 是 | 删除结果的回调。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.deleteOAuthToken("LiSi", "com.example.ohos.accountjsdemo", "readAge", "xxxxx", (err) => { - console.log('deleteOAuthToken err: ' + JSON.stringify(err)); - }); - ``` - -### deleteOAuthToken8+ - -deleteOAuthToken(name: string, owner: string, authType: string, token: string): Promise<void>; - -删除指定应用帐户和鉴权类型的OAuth令牌,使用Promise方式异步返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | ------ | ---- | ------------------ | - | name | string | 是 | 应用帐户的名称。 | - | owner | string | 是 | 应用帐户的所有者包名。 | - | authType | string | 是 | 鉴权类型。 | - | token | string | 是 | 要删除的OAuth令牌。 | - -- 参数: - - | 类型 | 说明 | - | ------------------------------ | --------------------- | - | Promise<void> | Promise实例,用于获取异步返回结果。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.deleteOAuthToken("LiSi", "com.example.ohos.accountjsdemo", "readAge", "xxxxx").then(() => { - console.log('deleteOAuthToken successfully'); - }).catch((err) => { - console.log("deleteOAuthToken err: " + JSON.stringify(err)); - }); - ``` - -### setOAuthTokenVisibility8+ - -setOAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean, callback: AsyncCallback<void>): void; - -设置指定鉴权类型的OAuth令牌对特定应用的可见性,使用callback回调异步返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | ---------- | ------------------------- | ---- | ------------------- | - | name | string | 是 | 应用帐户的名称。 | - | authType | string | 是 | 鉴权类型。 | - | bundleName | string | 是 | 被设置可见性的应用包名。| - | isVisible | boolean | 是 | 是否可见。 | - | callback | AsyncCallback<void> | 是 | 设置结果的回调。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.setOAuthTokenVisibility("LiSi", "readAge", "com.example.ohos.accountjsdemo", true, (err) => { - console.log('setOAuthTokenVisibility err: ' + JSON.stringify(err)); - }); - ``` - -### setOAuthTokenVisibility8+ - -setOAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean): Promise<void>; - -设置指定鉴权类型的OAuth令牌对特定应用的可见性,使用Promise方式异步返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | ---------- | ------------------------- | ---- | ------------------- | - | name | string | 是 | 应用帐户的名称。 | - | authType | string | 是 | 鉴权类型。 | - | bundleName | string | 是 | 被设置可见性的应用包名。| - | isVisible | boolean | 是 | 是否可见。 | - -- 参数: - - | 类型 | 说明 | - | ------------------------------ | --------------------- | - | Promise<void> | Promise实例,用于获取异步返回结果。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.setOAuthTokenVisibility("LiSi", "readAge", "com.example.ohos.accountjsdemo", true).then(() => { - console.log('setOAuthTokenVisibility successfully'); - }).catch((err) => { - console.log('setOAuthTokenVisibility err: ' + JSON.stringify(err)); - }); - ``` - -### checkOAuthTokenVisibility8+ - -checkOAuthTokenVisibility(name: string, authType: string, bundleName: string, callback: AsyncCallback<boolean>): void; - -检查指定鉴权类型的OAuth令牌对特定应用的可见性,使用callback回调异步返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | ---------- | ---------------------------- | ---- | ---------------------- | - | name | string | 是 | 应用帐户的名称。 | - | authType | string | 是 | 鉴权类型。 | - | bundleName | string | 是 | 用于检查可见性的应用包名。 | - | callback | AsyncCallback<boolean> | 是 | 检查结果的回调。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.checkOAuthTokenVisibility("LiSi", "readAge", "com.example.ohos.accountjsdemo", true, (err, data) => { - console.log('checkOAuthTokenVisibility err: ' + JSON.stringify(err)); - console.log('checkOAuthTokenVisibility isVisible: ' + data); - }); - ``` - -### checkOAuthTokenVisibility8+ - -checkOAuthTokenVisibility(name: string, authType: string, bundleName: string): Promise<boolean>; - -检查指定鉴权类型的OAuth令牌对特定应用的可见性,使用Promise方式异步返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | ---------- | ------------------------- | ---- | ---------------------- | - | name | string | 是 | 应用帐户的名称。 | - | authType | string | 是 | 鉴权类型。 | - | bundleName | string | 是 | 用于检查可见性的应用包名。 | - -- 参数: - - | 类型 | 说明 | - | ------------------------------ | ------------------------ | - | Promise<boolean> | Promise实例,用于获取异步返回结果。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.checkOAuthTokenVisibility("LiSi", "readAge", "com.example.ohos.accountjsdemo", true).then((data) => { - console.log('checkOAuthTokenVisibility isVisible: ' + data); - }).catch((err) => { - console.log('checkOAuthTokenVisibility err: ' + JSON.stringify(err)); - }); - ``` - -### getAllOAuthTokens8+ - -getAllOAuthTokens(name: string, owner: string, callback: AsyncCallback<Array<OAuthTokenInfo>>): void; - -获取指定应用对调用方全部可见的OAuth令牌,使用callback回调异步返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | ------------------------------------------------ | ---- | ------------------- | - | name | string | 是 | 应用帐户的名称。 | - | owner | string | 是 | 应用帐户的所有者包名。 | - | callback | AsyncCallback<Array<OAuthTokenInfo>> | 是 | 查询结果的回调。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.getAllOAuthTokens("LiSi", "com.example.ohos.accountjsdemo", (err, data) => { - console.log("getAllOAuthTokens err: " + JSON.stringify(err)); - console.log('getAllOAuthTokens data: ' + JSON.stringify(data)); - }); - ``` - -### getAllOAuthTokens8+ - -getAllOAuthTokens(name: string, owner: string): Promise<Array<OAuthTokenInfo>>; - -获取指定应用帐户对调用方可见的全部OAuth令牌,使用Promise方式异步返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | ------ | ---- | ------------------- | - | name | string | 是 | 应用帐户的名称。 | - | owner | string | 是 | 应用帐户的所有者包名。 | - -- 参数: - - | 类型 | 说明 | - | ------------------------------ | ----------------------------------- | - | Promise<Array<OAuthTokenInfo>> | Promise实例,用于获取异步返回结果。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.getAllOAuthTokens("LiSi", "com.example.ohos.accountjsdemo").then((data) => { - console.log('getAllOAuthTokens data: ' + JSON.stringify(data)); - }).catch((err) => { - console.log("getAllOAuthTokens err: " + JSON.stringify(err)); - }); - ``` - -### getOAuthList8+ - -getOAuthList(name: string, authType: string, callback: AsyncCallback<Array<string>>): void; - -获取指定应用帐户和鉴权类型的OAuth令牌的授权列表,使用callback回调异步返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | ---------------------------------------- | ---- | ------------------ | - | name | string | 是 | 应用帐户的名称。 | - | owner | string | 是 | 应用帐户的所有者包名。 | - | callback | AsyncCallback<Array<string>> | 是 | 查询结果的回调。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.getOAuthList("com.example.ohos.accountjsdemo", "readAge", (err, data) => { - console.log('getOAuthList err: ' + JSON.stringify(err)); - console.log('getOAuthList data: ' + JSON.stringify(data)); - }); - ``` - -### getOAuthList8+ - -getOAuthList(name: string, authType: string): Promise<Array<string>>; - -获取指定应用帐户和鉴权类型的OAuth令牌的授权列表,使用Promise方式异步返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | ------ | ---- | ------------------- | - | name | string | 是 | 应用帐户的名称。 | - | owner | string | 是 | 应用帐户的所有者包名。 | - -- 参数: - - | 类型 | 说明 | - | ------------------------------ | ------------------------------------ | - | Promise<Array<string>> | Promise实例,用于获取异步返回结果。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.getOAuthList("com.example.ohos.accountjsdemo", "readAge").then((data) => { - console.log('getOAuthList data: ' + JSON.stringify(data)); - }).catch((err) => { - console.log("getOAuthList err: " + JSON.stringify(err)); - }); - ``` - -### getAuthenticatorCallback8+ - -getAuthenticatorCallback(sessionId: string, callback: AsyncCallback<AuthenticatorCallback>): void; - -获取鉴权会话的认证器回调,使用callback回调异步返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | --------- | ------------------------------------------ | ---- | -------------- | - | sessionId | string | 是 | 鉴权会话的标识。 | - | callback | AsyncCallback<AuthenticatorCallback> | 是 | 查询结果的回调。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - featureAbility.getWant((err, want) => { - var sessionId = want.parameters[Constants.KEY_SESSION_ID]; - appAccountManager.getAuthenticatorCallback(sessionId, (err, callback) => { - if (err.code != ResultCode.SUCCESS) { - console.log("getAuthenticatorCallback err: " + JSON.stringify(err)); - return; - } - var result = {Constants.KEY_NAME: "LiSi", Constants.KEY_OWNER: "com.example.ohos.accountjsdemo", - Constants.KEY_AUTH_TYPE: "readAge", Constants.KEY_TOKEN: "xxxxxx"}; - callback.OnResult(ResultCode.SUCCESS, result); - }); - }); - ``` - -### getAuthenticatorCallback8+ - -getAuthenticatorCallback(sessionId: string): Promise<AuthenticatorCallback>; - -获取鉴权会话的认证器回调,使用Promise方式异步返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | ---------- | ------ | ---- | -------------- | - | sessionId | string | 是 | 鉴权会话的标识。 | - -- 参数: - - | 类型 | 说明 | - | ------------------------------------ | -------------------------------- | - | Promise<AuthenticatorCallback> | Promise实例,用于获取异步返回结果。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - featureAbility.getWant().then((want) => { - var sessionId = want.parameters[Constants.KEY_SESSION_ID]; - appAccountManager.getAuthenticatorCallback(sessionId).then((callback) => { - var result = {Constants.KEY_NAME: "LiSi", Constants.KEY_OWNER: "com.example.ohos.accountjsdemo", - Constants.KEY_AUTH_TYPE: "readAge", Constants.KEY_TOKEN: "xxxxxx"}; - callback.OnResult(ResultCode.SUCCESS, result); - }).catch((err) => { - console.log("getAuthenticatorCallback err: " + JSON.stringify(err)); - }); - }).catch((err) => { - console.log("getWant err: " + JSON.stringify(err)); - }); - ``` - -### getAuthenticatorInfo8+ - -getAuthenticatorInfo(owner: string, callback: AsyncCallback<AuthenticatorInfo>): void; - -获取指定应用帐户的认证器信息,使用callback回调异步返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------------------------------------- | ---- | ------------------- | - | owner | string | 是 | 应用帐户的所有者包名。 | - | callback | AsyncCallback<AuthenticatorInfo> | 是 | 查询结果的回调。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.getAuthenticatorInfo("com.example.ohos.accountjsdemo", (err, data) => { - console.log("getAuthenticatorInfo err: " + JSON.stringify(err)); - console.log('getAuthenticatorInfo data: ' + JSON.stringify(data)); - }); - ``` - -### getAuthenticatorInfo8+ - -getAuthenticatorInfo(owner: string): Promise<AuthenticatorInfo>; - -获取指定应用帐户的认证器信息,使用Promise方式异步返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | ----- | ------ | ---- | -------------------- | - | owner | string | 是 | 应用帐户的所有者包名。 | - -- 参数: - - | 类型 | 说明 | - | ------------------------------ | ----------------------------------- | - | Promise<AuthenticatorInfo> | Promise实例,用于获取异步返回结果。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.getAuthenticatorInfo("com.example.ohos.accountjsdemo").then((data) => { - console.log('getAuthenticatorInfo: ' + JSON.stringify(data)); - }).catch((err) => { - console.log("getAuthenticatorInfo err: " + JSON.stringify(err)); - }); - ``` - -## AppAccountInfo - -表示应用帐号信息。 - -| 参数名 | 类型 | 必填 | 说明 | -| ----- | ------ | ---- | ---------------- | -| owner | string | 是 | 应用帐户的所有者包名。 | -| name | string | 是 | 应用帐户的名称。 | - -## OAuthTokenInfo8+ - -表示OAuth令牌信息。 - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------ | ---- | -------------- | -| authType | string | 是 | 令牌的鉴权类型。 | -| token | string | 是 | 令牌的取值。 | - -## AuthenticatorInfo8+ - -表示OAuth认证器信息。 - -| 参数名 | 类型 | 必填 | 说明 | -| ------- | ------ | ---- | ------------------ | -| owner | string | 是 | 认证器的所有者包名。 | -| iconId | string | 是 | 认证器的图标标识。 | -| labelId | string | 是 | 认证器的标签标识。 | - -## Constants8+ - -表示常量的枚举。 - -| 名称 | 默认值 | 描述 | -| ----------------------------- | ---------------------- | ----------------------- | -| ACTION_ADD_ACCOUNT_IMPLICITLY | "addAccountImplicitly" | 表示操作_隐式添加帐号。 | -| ACTION_AUTHENTICATE | "authenticate" | 表示操作_鉴权。 | -| KEY_NAME | "name" | 表示键名_应用帐户名称。 | -| KEY_OWNER | "owner" | 表示键名_应用帐户所有者。 | -| KEY_TOKEN | "token" | 表示键名_令牌。 | -| KEY_ACTION | "action" | 表示键名_操作。 | -| KEY_AUTH_TYPE | "authType" | 表示键名_鉴权类型。 | -| KEY_SESSION_ID | "sessionId" | 表示键名_会话标识。 | -| KEY_CALLER_PID | "callerPid" | 表示键名_调用方PID。 | -| KEY_CALLER_UID | "callerUid" | 表示键名_调用方UID。 | -| KEY_CALLER_BUNDLE_NAME | "callerBundleName" | 表示键名_调用方包名。 | - -## ResultCode8+ - -表示返回码的枚举。 - -| 名称 | 默认值 | 描述 | -| ----------------------------------- | ----- | ---------------------- | -| SUCCESS | 0 | 表示操作成功。 | -| ERROR_ACCOUNT_NOT_EXIST | 10001 | 表示应用帐户不存在。 | -| ERROR_APP_ACCOUNT_SERVICE_EXCEPTION | 10002 | 表示应用帐户服务异常。 | -| ERROR_INVALID_PASSWORD | 10003 | 表示密码无效。 | -| ERROR_INVALID_REQUEST | 10004 | 表示请求无效。 | -| ERROR_INVALID_RESPONSE | 10005 | 表示响应无效。 | -| ERROR_NETWORK_EXCEPTION | 10006 | 表示网络异常。 | -| ERROR_OAUTH_AUTHENTICATOR_NOT_EXIST | 10007 | 表示认证器不存在。 | -| ERROR_OAUTH_CANCELED | 10008 | 表示鉴权取消。 | -| ERROR_OAUTH_LIST_TOO_LARGE | 10009 | 表示开放授权列表过大。 | -| ERROR_OAUTH_SERVICE_BUSY | 10010 | 表示开放授权服务忙碌。 | -| ERROR_OAUTH_SERVICE_EXCEPTION | 10011 | 表示开放授权服务异常。 | -| ERROR_OAUTH_SESSION_NOT_EXIST | 10012 | 表示鉴权会话不存在。 | -| ERROR_OAUTH_TIMEOUT | 10013 | 表示鉴权超时。 | -| ERROR_OAUTH_TOKEN_NOT_EXIST | 10014 | 表示开放授权令牌不存在。 | -| ERROR_OAUTH_TOKEN_TOO_MANY | 10015 | 表示开放授权令牌过多。 | -| ERROR_OAUTH_UNSUPPORT_ACTION | 10016 | 表示不支持的鉴权操作。 | -| ERROR_OAUTH_UNSUPPORT_AUTH_TYPE | 10017 | 表示不支持的鉴权类型。 | -| ERROR_PERMISSION_DENIED | 10018 | 表示权限不足。 | - -## AuthenticatorCallback8+ - -OAuth认证器回调接口。 - -### onResult8+ - -onResult: (code: number, result: {[key: string]: any}) => void; - -通知鉴权结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | ------ | -------------------- | ---- | ----------- | - | code | number | 是 | 鉴权结果码。 | - | result | {[key: string]: any} | 是 | 鉴权结果。 | - -- 示例: - - ``` - const appAccountManager = account_appAccount.createAppAccountManager(); - var sessionId = "1234"; - appAccountManager.getAuthenticatorCallback(sessionId).then((callback) => { - var result = {Constants.KEY_NAME: "LiSi", Constants.KEY_OWNER: "com.example.ohos.accountjsdemo", - Constants.KEY_AUTH_TYPE: "readAge", Constants.KEY_TOKEN: "xxxxxx"}; - callback.OnResult(ResultCode.SUCCESS, result); - }).catch((err) => { - console.log("getAuthenticatorCallback err: " + JSON.stringify(err)); - }); - ``` - -### onRequestRedirected8+ - -onRequestRedirected: (request: Want) => void; - -通知鉴权请求被跳转。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | ------- | ---- | ---- | ------------------ | - | request | Want | 是 | 用于跳转的请求信息。 | - -- 示例: - - ``` - class MyAuthenticator extends account_appAccount.Authenticator { - addAccountImplicitly(authType, callerBundleName, options, callback) { - callback.onRequestRedirected({ - bundleName: "com.example.ohos.accountjsdemo", - abilityName: "com.example.ohos.accountjsdemo.LoginAbility", - }); - } - - authenticate(name, authType, callerBundleName, options, callback) { - var result = {Constants.KEY_NAME: name, Constants.KEY_AUTH_TYPE: authType, Constants.KEY_TOKEN: "xxxxxx"}; - callback.onResult(ResultCode.SUCCESS, result); - } - } - ``` - -## Authenticator8+ - -OAuth认证器基类。 - -### addAccountImplicitly8+ - -addAccountImplicitly(authType: string, callerBundleName: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void; - -根据指定的鉴权类型和可选项,隐式地添加应用帐户,并使用callback回调异步返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | ---------------- | --------------------- | --- | -------------------------- | - | authType | string | 是 | 应用帐户的鉴权类型。 | - | callerBundleName | string | 是 | 鉴权请求方的包名。 | - | options | {[key: string]: any} | 是 | 鉴权所需要的可选项。 | - | callback | AuthenticatorCallback | 是 | 认证器回调,用于返回鉴权结果。 | - -### authenticate8+ - -authenticate(name: string, authType: string, callerBundleName: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void; - -对应用帐户进行鉴权,获取OAuth令牌,并使用callback回调异步返回结果。 - -- 参数: - | 接口名 | 类型 | 必填 | 说明 | - | ---------------- | --------------------- | ---- | -------------------------- | - | name | string | 是 | 应用帐户的名称。 | - | authType | string | 是 | 应用帐户的鉴权类型。 | - | callerBundleName | string | 是 | 鉴权请求方的包名。 | - | options | {[key: string]: any} | 是 | 鉴权所需要的可选项。 | - | callback | AuthenticatorCallback | 是 | 认证器回调,用于返回鉴权结果。 | - -- 示例: - - ``` - class MyAuthenticator extends account_appAccount.Authenticator { - addAccountImplicitly(authType, callerBundleName, options, callback) { - callback.onRequestRedirected({ - bundleName: "com.example.ohos.accountjsdemo", - abilityName: "com.example.ohos.accountjsdemo.LoginAbility", - }); - } - - authenticate(name, authType, callerBundleName, options, callback) { - var result = {Constants.KEY_NAME: name, Constants.KEY_AUTH_TYPE: authType, Constants.KEY_TOKEN: "xxxxxx"}; - callback.onResult(ResultCode.SUCCESS, result); - } - } - - export default { - onConnect(want) { - return new MyAuthenticator(); - } - } - ``` diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/08.\347\224\265\350\257\235\346\234\215\345\212\241/01.\346\213\250\346\211\223\347\224\265\350\257\235.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/08.\347\224\265\350\257\235\346\234\215\345\212\241/01.\346\213\250\346\211\223\347\224\265\350\257\235.md" deleted file mode 100644 index 9824c6b4bd954fde77621ab0371b989b81222757..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/08.\347\224\265\350\257\235\346\234\215\345\212\241/01.\346\213\250\346\211\223\347\224\265\350\257\235.md" +++ /dev/null @@ -1,450 +0,0 @@ ---- -title: 拨打电话 -permalink: /pages/010c010801 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 拨打电话 - ->**说明:** -> ->本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import call from '@ohos.telephony.call'; -``` - -## call.dial - -dial\(phoneNumber: string, callback: AsyncCallback\): void - -拨打电话,使用callback方式作为异步方法。 - -需要权限:ohos.permission.PLACE\_CALL权限,该权限为系统权限。 - -- 参数 - - | 参数 | 类型 | 必填 | 说明 | - | ----------- | ---------------------------- | ---- | ------------------------------------------------- | - | phoneNumber | string | 是 | 电话号码。 | - | callback | AsyncCallback<boolean> | 是 | 回调函数:
- true:成功。
- false:失败。 | - -- 示例 - - ``` - call.dial("138xxxxxxxx", (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); - }); - ``` - - -## call.dial - -dial\(phoneNumber: string, options: DialOptions, callback: AsyncCallback\): void - -拨打电话,可设置通话参数,使用callback方式作为异步方法。 - -需要权限:ohos.permission.PLACE\_CALL权限,该权限为系统权限。 - -- 参数 - - | 参数 | 类型 | 必填 | 说明 | - | ----------- | ---------------------------- | ---- | ------------------------------------------------- | - | phoneNumber | string | 是 | 电话号码。 | - | options | DialOptions | 是 | 通话参数,参考[DialOptions](#DialOptions)。 | - | callback | AsyncCallback<boolean> | 是 | 回调函数:
- true:成功。
- false:失败。 | - - -- 示例 - - ``` - call.dial("138xxxxxxxx", { - extras: false - }, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); - }); - ``` - - -## call.dial - -dial\(phoneNumber: string, options?: DialOptions\): Promise - -拨打电话,可设置通话参数,使用promise方式作为异步方法。 - -需要权限:ohos.permission.PLACE\_CALL权限,该权限为系统权限。 - -- 参数 - - | 参数 | 类型 | 必填 | 说明 | - | ----------- | ----------- | ---- | ------------------------------------------- | - | phoneNumber | string | 是 | 电话号码。 | - | options | DialOptions | 是 | 通话参数,参考[DialOptions](#DialOptions)。 | - -- 返回值 - - | 类型 | 说明 | - | ---------------------- | --------------------------------- | - | Promise<boolean> | 以Promise形式返回拨打电话的结果。 | - -- 示例 - - ``` - let promise = call.dial("138xxxxxxxx", { - extras: false - }); - promise.then(data => { - console.log(`dial success, promise: data->${JSON.stringify(data)}`); - }).catch(err => { - console.error(`dial fail, promise: err->${JSON.stringify(err)}`); - }); - ``` - -## call.hasCall - -hasCall\(callback: AsyncCallback\): void - -判断是否存在通话,使用callback方式作为异步方法。 - -- 参数 - - | 参数 | 类型 | 必填 | 说明 | - | -------- | ---------------------------- | ---- | ------------------------------------------------------------ | - | callback | AsyncCallback<boolean> | 是 | 回调函数:
- true:当前存在通话。
- false:当前不存在通话。 | - -- 示例 - - ``` - call.hasCall((err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); - }); - ``` - - -## call.hasCall - -hasCall\(\): Promise - -判断是否存在通话,使用Promise方式作为异步方法。 - -- 返回值 - - | 类型 | 说明 | - | ---------------------- | --------------------------------------- | - | Promise<boolean> | 以Promise形式异步返回判断是否存在通话。 | - -- 示例 - - ``` - let promise = call.hasCall(); - promise.then(data => { - console.log(`hasCall success, promise: data->${JSON.stringify(data)}`); - }).catch(err => { - console.error(`hasCall fail, promise: err->${JSON.stringify(err)}`); - }); - ``` - - -## call.getCallState - -getCallState\(callback: AsyncCallback\): void - -获取通话状态,使用callback方式作为异步方法。 - -- 参数 - - | 参数 | 类型 | 必填 | 说明 | - | -------- | -------------------------------------------- | ---- | ------------------------------------ | - | callback | AsyncCallback<[CallState](#CallState)> | 是 | 回调函数:异步返回获取到的通话状态。 | - -- 示例 - - ``` - call.getCallState((err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); - }); - ``` - - -## call.getCallState - -getCallState\(\): Promise - -获取通话状态,使用Promise方式作为异步方法。 - -- 返回值 - - | 类型 | 说明 | - | -------------------------------------- | ----------------------------------------- | - | Promise<[CallState](#CallState)> | 以Promise形式异步返回获取通话状态的结果。 | - -- 示例 - - ``` - let promise = call.getCallState(); - promise.then(data => { - console.log(`getCallState success, promise: data->${JSON.stringify(data)}`); - }).catch(err => { - console.error(`getCallState fail, promise: err->${JSON.stringify(err)}`); - }); - ``` - -## call.isEmergencyPhoneNumber7+ - -isEmergencyPhoneNumber\(phoneNumber: string, callback: AsyncCallback\): void - -判断是否是紧急电话号码,使用callback方式作为异步方法。 - -- 参数 - - | 参数 | 类型 | 必填 | 说明 | - | ----------- | ---------------------------- | ---- | ------------------------------------------------------------ | - | phoneNumber | string | 是 | 电话号码。 | - | callback | AsyncCallback<boolean> | 是 | 回调函数,返回判断是否是紧急电话号码的结果:
- true:是紧急电话号码。
- false:不是紧急电话号码。 | - -- 示例 - - ``` - call.isEmergencyPhoneNumber("138xxxxxxxx", (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); - }); - ``` - - -## call.isEmergencyPhoneNumber7+ - -isEmergencyPhoneNumber\(phoneNumber: string, options: EmergencyNumberOptions, callback: AsyncCallback\): void - -判断是否是紧急电话号码,使用callback方式作为异步方法。 - -- 参数 - - | 参数 | 类型 | 必填 | 说明 | - | ----------- | ---------------------------- | ---- | ------------------------------------------------------------ | - | phoneNumber | string | 是 | 电话号码。 | - | options | EmergencyNumberOptions | 是 | 手机参数,参考[EmergencyNumberOptions](#EmergencyNumberOptions)。 | - | callback | AsyncCallback<boolean> | 是 | 回调函数,返回判断是否是紧急电话号码的结果:
- true:是紧急电话号码。
- false:不是紧急电话号码。 | - -- 示例 - - ``` - call.isEmergencyPhoneNumber("112", {slotId: 1}, (err, value) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); - }); - ``` - - -## call.isEmergencyPhoneNumber7+ - -isEmergencyPhoneNumber\(phoneNumber: string, options?: EmergencyNumberOptions\): Promise - -判断是否是紧急电话号码,使用promise方式作为异步方法。 - -- 参数 - - | 参数 | 类型 | 必填 | 说明 | - | ----------- | ---------------------- | ---- | ------------------------------------------------------------ | - | phoneNumber | string | 是 | 电话号码。 | - | options | EmergencyNumberOptions | 是 | 手机参数,参考[EmergencyNumberOptions](#EmergencyNumberOptions)。 | - -- 返回值 - - | 类型 | 说明 | - | ---------------------- | --------------------------------------------------- | - | Promise<boolean> | 以Promise形式异步返回判断是否是紧急电话号码的结果。 | - -- 示例 - - ``` - let promise = call.isEmergencyPhoneNumber("138xxxxxxxx", {slotId: 1}); - promise.then(data => { - console.log(`isEmergencyPhoneNumber success, promise: data->${JSON.stringify(data)}`); - }).catch(err => { - console.error(`isEmergencyPhoneNumber fail, promise: err->${JSON.stringify(err)}`); - }); - ``` - -## call.formatPhoneNumber7+ - -formatPhoneNumber\(phoneNumber: string, callback: AsyncCallback\): void - -格式化电话号码,使用callback方式作为异步方法。 - -- 参数 - - | 参数 | 类型 | 必填 | 说明 | - | ----------- | --------------------------- | ---- | ------------------------------------ | - | phoneNumber | string | 是 | 电话号码。 | - | callback | AsyncCallback<string> | 是 | 回调函数,返回格式化电话号码的结果。 | - -- 示例 - - ``` - call.formatPhoneNumber("138xxxxxxxx", (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); - }); - ``` - - -## call.formatPhoneNumber7+ - -formatPhoneNumber\(phoneNumber: string, options: NumberFormatOptions, callback: AsyncCallback\): void - -格式化电话号码,可设置格式化参数,使用callback方式作为异步方法。 - -- 参数 - - | 参数 | 类型 | 必填 | 说明 | - | ----------- | --------------------------- | ---- | ------------------------------------------------------------ | - | phoneNumber | string | 是 | 电话号码。 | - | options | NumberFormatOptions | 是 | 格式化参数,参考[NumberFormatOptions](#NumberFormatOptions)。 | - | callback | AsyncCallback<string> | 是 | 回调函数,返回格式化电话号码的结果。 | - -- 示例 - - ``` - call.formatPhoneNumber("138xxxxxxxx",{ - countryCode: "CN" - }, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); - }); - ``` - - -## call.formatPhoneNumber7+ - -formatPhoneNumber\(phoneNumber: string, options?: NumberFormatOptions\): Promise - -格式化电话号码,可设置格式化参数,使用promise方式作为异步方法。 - -- 参数 - - | 参数 | 类型 | 必填 | 说明 | - | ----------- | ------------------- | ---- | ------------------------------------------------------------ | - | phoneNumber | string | 是 | 电话号码。 | - | options | NumberFormatOptions | 是 | 格式化参数,参考[NumberFormatOptions](#NumberFormatOptions)。 | - -- 返回值 - - | 类型 | 说明 | - | --------------------- | ------------------------------------------- | - | Promise<string> | 以Promise形式异步返回格式化电话号码的结果。 | - -- 示例 - - ``` - let promise = call.formatPhoneNumber("138xxxxxxxx", { - countryCode: "CN" - }); - promise.then(data => { - console.log(`formatPhoneNumber success, promise: data->${JSON.stringify(data)}`); - }).catch(err => { - console.error(`formatPhoneNumber fail, promise: err->${JSON.stringify(err)}`); - }); - ``` - -## call.formatPhoneNumberToE1647+ - -formatPhoneNumberToE164\(phoneNumber: string, countryCode: string, callback: AsyncCallback\): void - -将电话号码格式化为E.164表示形式,使用callback方式作为异步方法。 - -需要格式化的电话号码需要与传入国家码相匹配,如中国手机号需要传入国家码CN,否则格式化后的手机号为null。 - -支持所有国家码。 - -- 参数 - - | 参数 | 类型 | 必填 | 说明 | - | ----------- | --------------------------- | ---- | ----------------------------------------------------- | - | phoneNumber | string | 是 | 电话号码。 | - | countryCode | string | 是 | 国家码,支持所有国家码,如:中国(CN)。 | - | callback | AsyncCallback<string> | 是 | 回调函数,返回将电话号码格式化为E.164表示形式的结果。 | - -- 示例 - - ``` - call.formatPhoneNumberToE164("138xxxxxxxx",{ - countryCode: "CN" - }, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); - }); - ``` - - -## call.formatPhoneNumberToE1647+ - -formatPhoneNumberToE164\(phoneNumber: string, countryCode: string\): Promise - -将电话号码格式化为E.164表示形式,使用promise方式作为异步方法。 - -需要格式化的手机号码需要与传入国家码相匹配,如中国手机号需要传入国家码CN,否则格式化后的手机号为null。 - -支持所有国家码。 - -- 参数 - - | 参数 | 类型 | 必填 | 说明 | - | ----------- | ------ | ---- | ---------------------------------------- | - | phoneNumber | string | 是 | 电话号码。 | - | countryCode | string | 是 | 国家码,支持所有国家码,如:中国(CN)。 | - -- 返回值 - - | 类型 | 说明 | - | --------------------- | ------------------------------------------------------------ | - | Promise<string> | 以Promise形式异步返回将电话号码格式化为E.164表示形式的结果。 | - -- 示例 - - ``` - let promise = call.formatPhoneNumberToE164("138xxxxxxxx", { - countryCode: "CN" - }); - promise.then(data => { - console.log(`formatPhoneNumberToE164 success, promise: data->${JSON.stringify(data)}`); - }).catch(err => { - console.error(`formatPhoneNumberToE164 fail, promise: err->${JSON.stringify(err)}`); - }); - ``` - -## DialOptions - -拨打电话的可选参数。 -| 参数 | 类型 | 必填 | 说明 | -| ------ | ------- | ---- | ------------------------------------------------------------ | -| extras | boolean | 否 | 根据extras的值判断是否为视频通话,默认为语音通话。
- true:视频通话。
- fasle:语音通话。 | - -## CallState - -通话状态码。 -| 变量 | 值 | 说明 | -| ------------------ | ---- | ------------------------------------------------------------ | -| CALL_STATE_UNKNOWN | -1 | 无效状态,当获取呼叫状态失败时返回。 | -| CALL_STATE_IDLE | 0 | 表示没有正在进行的呼叫。 | -| CALL_STATE_RINGING | 1 | 表示来电正在振铃或等待。 | -| CALL_STATE_OFFHOOK | 2 | 表示至少有一个呼叫处于拨号、通话中或呼叫保持状态,并且没有新的来电振铃或等待。 | - -## EmergencyNumberOptions7+ - -判断是否是紧急电话号码的可选参数。 -| 参数 | 类型 | 必填 | 说明 | -| ------ | ------ | ---- | ------------------------------------------ | -| slotId | number | 否 | 卡槽ID:
- 0:卡槽1。
- 1:卡槽2。 | - -## NumberFormatOptions7+ - -格式化号码的可选参数。 -| 参数 | 类型 | 必填 | 说明 | -| ----------- | ------ | ---- | ---------------------------------------------------------- | -| countryCode | string | 否 | 国家码,支持所有国家的国家码,如:中国(CN)。默认为:CN。 | \ No newline at end of file diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/08.\347\224\265\350\257\235\346\234\215\345\212\241/02.\347\237\255\344\277\241\346\234\215\345\212\241.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/08.\347\224\265\350\257\235\346\234\215\345\212\241/02.\347\237\255\344\277\241\346\234\215\345\212\241.md" deleted file mode 100644 index 12921856d7f028e1d829e9dd7fd3a1c3c52d73ae..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/08.\347\224\265\350\257\235\346\234\215\345\212\241/02.\347\237\255\344\277\241\346\234\215\345\212\241.md" +++ /dev/null @@ -1,365 +0,0 @@ ---- -title: 短信服务 -permalink: /pages/010c010802 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 短信服务 - ->**说明:** -> ->本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - -## 导入模块 - -``` -import sms from '@ohos.telephony.sms'; -``` - -## sms.createMessage - -createMessage\(pdu: Array, specification: string, callback: AsyncCallback\): void - -根据协议数据单元(PDU)和指定的短信协议创建短信实例,使用callback方式作为异步方法。 - -- 参数 - - | 参数名 | 类型 | 必填 | 说明 | - | ------------- | -------------------------------------------------- | ---- | ------------------------------------------------------------ | - | pdu | Array<number> | 是 | 协议数据单元,从收到的信息中获取。 | - | specification | string | 是 | 短信协议类型。
- 3gpp表示GSM/UMTS/LTE SMS
- 3gpp2表示CDMA SMS | - | callback | AsyncCallback<[ShortMessage](#ShortMessage)> | 是 | 回调函数。 | - -- 示例 - - ``` - const specification = '3gpp'; - // 以数组的形式显示协议数据单元(PDU),类型为number,例如[0x08, 0x91, ...] - const pdu = [0x08, 0x91]; - sms.createMessage(pdu, specification, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); - }); - ``` - - -## sms.createMessage - -createMessage\(pdu: Array, specification: string\): Promise - -根据协议数据单元(PDU)和指定的短信协议创建短信实例,使用Promise方式作为异步方法。 - -- 参数 - - | 参数名 | 类型 | 必填 | 说明 | - | ------------- | ------------------- | ---- | ------------------------------------------------------------ | - | pdu | Array<number> | 是 | 协议数据单元,从收到的信息中获取。 | - | specification | string | 是 | 短信协议类型。
- 3gpp表示GSM/UMTS/LTE SMS
- 3gpp2表示CDMA SMS | - -- 返回值 - - | 类型 | 说明 | - | -------------------------------------------- | --------------------------------- | - | Promise<[ShortMessage](#ShortMessage)> | 以Promise形式返回创建的短信实例。 | - -- 示例 - - ``` - const specification = '3gpp'; - // 以数组的形式显示协议数据单元(PDU),类型为number,例如[0x08, 0x91, ...] - const pdu = [0x08, 0x91]; - let promise = sms.createMessage(pdu, specification); - promise.then(data => { - console.log(`createMessage success, promise: data->${JSON.stringify(data)}`); - }).catch(err => { - console.error(`createMessage fail, promise: err->${JSON.stringify(err)}`); - }); - ``` - -## sms.sendMessage - -sendMessage(options: SendMessageOptions): void - -发送短信。 - -需要ohos.permission.SEND_MESSAGES权限。 - -- 参数 - - | 参数名 | 类型 | 必填 | 说明 | - | ------- | ----------------------------------------- | ---- | ------------------------------------------------------------ | - | options | [SendMessageOptions](#SendMessageOptions) | 是 | 发送短信的参数和回调,参考[SendMessageOptions](#SendMessageOptions)。 | - -- 示例 - - ``` - let sendCallback = function (err, data) { - console.log(`sendCallback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); - } - let deliveryCallback = function (err, data) { - console.log(`deliveryCallback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); - } - let slotId = 0; - let content = '短信内容'; - let destinationHost = '+861xxxxxxxxxx'; - let serviceCenter = '+861xxxxxxxxxx'; - let destinationPort = 1000; - let options = {slotId, content, destinationHost, serviceCenter, destinationPort, sendCallback, deliveryCallback}; - sms.sendMessage(options); - ``` - - -## sms.getDefaultSmsSlotId7+ - -getDefaultSmsSlotId\(callback: AsyncCallback\): void - -获取发送短信的默认SIM卡槽ID,使用callback方式作为异步方法。 - -- 参数 - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | --------------------------- | ---- | ---------------------------------------- | - | callback | AsyncCallback<number> | 是 | 回调函数。
- 0:卡槽1
- 1:卡槽2 | - -- 示例 - - ``` - sms.getDefaultSmsSlotId((err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); - }); - ``` - - -## sms.getDefaultSmsSlotId7+ - -getDefaultSmsSlotId\(\): Promise - -获取发送短信的默认SIM卡槽ID,使用Promise方式作为异步方法。 - -- 返回值 - - | 类型 | 说明 | - | --------------- | ------------------------------------------------------------ | - | Promise | 以Promise形式返回发送短信的默认SIM卡:
- 0:卡槽1
- 1:卡槽2 | - -- 示例 - - ``` - let promise = call.getDefaultSmsSlotId(); - promise.then(data => { - console.log(`getDefaultSmsSlotId success, promise: data->${JSON.stringify(data)}`); - }).catch(err => { - console.error(`getDefaultSmsSlotId fail, promise: err->${JSON.stringify(err)}`); - }); - ``` - - -## sms.setSmscAddr7+ - -setSmscAddr\(slotId: number, smscAddr: string, callback: AsyncCallback\): void - -设置短信服务中心(SMSC)地址,使用callback方式作为异步方法。 - -需要ohos.permission.SET\_TELEPHONY\_STATE权限,该权限为系统权限。 - -- 参数 - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | ------------------------- | ---- | ----------------------------------------- | - | slotId | number | 是 | SIM卡槽ID:
- 0:卡槽1
- 1:卡槽2 | - | smscAddr | string | 是 | 短信服务中心地址。 | - | callback | AsyncCallback<void> | 是 | 回调函数。 | - -- 示例 - - ``` - let slotId = 0; - let smscAddr = '+861xxxxxxxxxx'; - sms.setSmscAddr(slotId, smscAddr, (err,data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); - }); - ``` - - -## sms.setSmscAddr7+ - -setSmscAddr\(slotId: number, smscAddr: string\): Promise - -设置短信服务中心(SMSC)地址,使用Promise方式作为异步方法。 - -需要ohos.permission.SET\_TELEPHONY\_STATE权限,该权限为系统权限。 - -- 参数 - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | ------ | ---- | ----------------------------------------- | - | slotId | number | 是 | SIM卡槽ID:
- 0:卡槽1
- 1:卡槽2 | - | smscAddr | string | 是 | 短信服务中心地址。 | - -- 返回值 - - | 类型 | 说明 | - | ------------------- | ------------------------------- | - | Promise<void> | 以Promise形式异步返回设置结果。 | - -- 示例 - - ``` - let slotId = 0; - let smscAddr = '+861xxxxxxxxxx'; - let promise = sms.setSmscAddr(slotId, smscAddr); - promise.then(data => { - console.log(`setSmscAddr success, promise: data->${JSON.stringify(data)}`); - }).catch(err => { - console.error(`setSmscAddr fail, promise: err->${JSON.stringify(err)}`); - }); - ``` - - -## sms.getSmscAddr7+ - -getSmscAddr\(slotId: number, callback: AsyncCallback\): void - -获取短信服务中心(SMSC)地址,使用callback方式作为异步方法。 - -需要ohos.permission.GET\_TELEPHONY\_STATE权限,该权限为系统权限。 - -- 参数 - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | --------------------------- | ---- | ----------------------------------------- | - | slotId | number | 是 | SIM卡槽ID:
- 0:卡槽1
- 1:卡槽2 | - | callback | AsyncCallback<string> | 是 | 回调函数。 | - -- 示例 - - ``` - let slotId = 0; - sms.getSmscAddr(slotId, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); - }); - ``` - - -## sms.getSmscAddr7+ - -getSmscAddr\(slotId: number\): Promise - -获取短信服务中心(SMSC)地址,使用Promise方式作为异步方法。 - -需要ohos.permission.GET\_TELEPHONY\_STATE权限,该权限为系统权限。 - -- 参数 - - | 参数名 | 类型 | 必填 | 说明 | - | ------ | ------ | ---- | ----------------------------------------- | - | slotId | number | 是 | SIM卡槽ID:
- 0:卡槽1
- 1:卡槽2 | - -- 返回值 - - | 类型 | 说明 | - | --------------------- | --------------------------------------------- | - | Promise<string> | 以Promise形式返回获取短信服务中心地址的结果。 | - -- 示例 - - ``` - let slotId = 0; - let promise = sms.getSmscAddr(slotId); - promise.then(data => { - console.log(`getSmscAddr success, promise: data->${JSON.stringify(data)}`); - }).catch(err => { - console.error(`getSmscAddr fail, promise: err->${JSON.stringify(err)}`); - }); - ``` - - -## ShortMessage - -短信实例。 - -| 变量 | 类型 | 说明 | -| ------------------------ | --------------------------------------- | ------------------------------------------------------------ | -| emailAddress | string | 电子邮件地址。 | -| emailMessageBody | string | 电子邮件正文。 | -| hasReplyPath | boolean | 收到的短信是否包含“TP-Reply-Path”,默认为false。
“TP-Reply-Path”:移动电话根据发送SMS消息的短消息中心进行回复。 | -| isEmailMessage | boolean | 收到的短信是否为电子邮件。 | -| isReplaceMessage | boolean | 收到的短信是否为“替换短信”,默认为false。
“替换短信”有关详细信息,参见 “3GPP TS 23.040 9.2.3.9”。 | -| isSmsStatusReportMessage | boolean | 当前消息是否为“短信状态报告”,默认为false。
“短信状态报告”是一种特定格式的短信,被用来从Service Center到Mobile Station传送状态报告。 | -| messageClass | [ShortMessageClass](#ShortMessageClass) | 短信类型。 | -| pdu | Array<number> | SMS消息中的协议数据单元 (PDU)。 | -| protocolId | number | 发送短信时使用的协议标识。 | -| scAddress | string | 短消息服务中心(SMSC)地址。 | -| scTimestamp | number | SMSC时间戳。 | -| status | number | SMS-STATUS-REPORT消息中的短信状态指示短信服务中心(SMSC)发送的短信状态。 | -| userRawData | Array<number> | 除数据头外的用户数据。 | -| visibleMessageBody | string | 短信正文。 | -| visibleRawAddress | string | 发送者地址。 | - - -## ShortMessageClass - -短信类型。 - -| 变量 | 值 | 说明 | -| ---------------- | ---- | ---------------------------------------- | -| UNKNOWN | 0 | 未知类型。 | -| INSTANT_MESSAGE | 1 | 即时消息,收到后立即显示。 | -| OPTIONAL_MESSAGE | 2 | 存储在设备或SIM卡上的短信。 | -| SIM_MESSAGE | 3 | 包含SIM卡信息的短信,需要存储在SIM卡中。 | -| FORWARD_MESSAGE | 4 | 要转发到另一台设备的短信。 | - - -## SendMessageOptions - -发送短信的参数和回调。 - -根据SendMessageOptions中的可选参数content的值判断短信类型。 - -| 参数名 | 类型 | 必填 | 说明 | -| ---------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| slotId | number | 是 | 用于发送短信的SIM卡槽ID:
- 0:卡槽1
- 1:卡槽2 | -| destinationHost | string | 是 | 短信的发送地址。 | -| content | string \| Array<number> | 是 | 如果内容是字符串,则这是一条文本短信。如果内容是字节数组,则这是一条数据短信。 | -| serviceCenter | string | 否 | 短信中心地址。默认使用SIM卡中的短信中心地址。 | -| destinationPort | number | 否 | 如果发送数据消息,destinationPort 是必需的。否则是可选的。 | -| sendCallback | AsyncCallback<[ISendShortMessageCallback](#ISendShortMessageCallback)> | 否 | 短信发送结果回调,返回短信发送的结果,参考[ISendShortMessageCallback](#ISendShortMessageCallback)。 | -| deliveryCallback | AsyncCallback<[IDeliveryShortMessageCallback](#IDeliveryShortMessageCallback)> | 否 | 短信送达结果回调,返回短信递送报告,参考[IDeliveryShortMessageCallback](#IDeliveryShortMessageCallback)。 | - - -## ISendShortMessageCallback - -回调实例。返回短信发送结果、存储已发送短信的URI和是否为长短信的最后一部分。 - -| 参数名 | 类型 | 必填 | 说明 | -| ---------- | ------------------------------- | ---- | ------------------------------------------------------------ | -| isLastPart | boolean | 否 | 指定这是否是长短信的最后一部分。true表示这是长短信的最后一部分,false表示不是。默认为false。 | -| result | [SendSmsResult](#SendSmsResult) | 是 | 短信发送结果。 | -| url | string | 是 | 存储发送短信的URI。 | - - -## IDeliveryShortMessageCallback - -回调实例。返回短信送达报告。 - -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ------------------- | ---- | -------------- | -| pdu | Array<number> | 是 | 短信送达报告。 | - - -## SendSmsResult - -短信发送结果。 - -| 参数名 | 值 | 说明 | -| ------------------------------------ | ---- | ------------------------------------------------------ | -| SEND_SMS_SUCCESS | 0 | 发送短信成功。 | -| SEND_SMS_FAILURE_UNKNOWN | 1 | 发送短信失败,原因未知。 | -| SEND_SMS_FAILURE_RADIO_OFF | 2 | 发送短信失败,原因为调制解调器关机。 | -| SEND_SMS_FAILURE_SERVICE_UNAVAILABLE | 3 | 发送短信失败,原因为网络不可用、不支持发送或接收短信。 | \ No newline at end of file diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/08.\347\224\265\350\257\235\346\234\215\345\212\241/03.SIM\345\215\241\347\256\241\347\220\206.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/08.\347\224\265\350\257\235\346\234\215\345\212\241/03.SIM\345\215\241\347\256\241\347\220\206.md" deleted file mode 100644 index b9d24582143a19042662b762d48c66eab8384b27..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/08.\347\224\265\350\257\235\346\234\215\345\212\241/03.SIM\345\215\241\347\256\241\347\220\206.md" +++ /dev/null @@ -1,400 +0,0 @@ ---- -title: SIM卡管理 -permalink: /pages/010c010803 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# SIM卡管理 - ->**说明:** -> ->本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - -## 导入模块 - -``` -import sim from '@ohos.telephony.sim'; -``` - -## sim.getSimIccId - -getSimIccId\(slotId: number, callback: AsyncCallback\): void - -获取指定卡槽SIM卡的ICCID(Integrate Circuit Card Identity),使用callback方式作为异步方法。 - -需要ohos.permission.GET\_TELEPHONY\_STATE权限,该权限为系统权限。 - -- 参数 - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | --------------------------- | ---- | -------------------------------------- | - | slotId | number | 是 | 卡槽ID。
- 0:卡槽1
- 1:卡槽2 | - | callback | AsyncCallback<string> | 是 | 回调函数。 | - - -- 示例 - - ``` - sim.getSimIccId(0, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); - }); - ``` - - -## sim.getSimIccId - -getSimIccId\(slotId: number\): Promise - -获取指定卡槽SIM卡的ICCID(Integrate Circuit Card Identity),使用Promise方式作为异步方法。 - -需要ohos.permission.GET\_TELEPHONY\_STATE权限,该权限为系统权限。 - -- 参数 - - | 参数名 | 类型 | 必填 | 说明 | - | ------ | ------ | ---- | -------------------------------------- | - | slotId | number | 是 | 卡槽ID。
- 0:卡槽1
- 1:卡槽2 | - -- 返回值 - - | 类型 | 说明 | - | --------------------- | ---------------------------------- | - | Promise<string> | 以Promise形式返回指定卡槽的ICCID。 | - -- 示例 - - ``` - let promise = sim.getSimIccId(0); - promise.then(data => { - console.log(`getSimIccId success, promise: data->${JSON.stringify(data)}`); - }).catch(err => { - console.log(`getSimIccId fail, promise: err->${JSON.stringify(err)}`); - }); - ``` - -## sim.getDefaultVoiceSlotId7+ - -getDefaultVoiceSlotId\(callback: AsyncCallback\): void - -获取默认语音业务的卡槽ID,使用callback方式作为异步方法。 - -- 参数 - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | --------------------------- | ---- | ---------- | - | callback | AsyncCallback<number> | 是 | 回调函数。 | - -- 示例 - - ``` - sim.getDefaultVoiceSlotId((err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); - }); - ``` - - -## sim.getDefaultVoiceSlotId7+ - -getDefaultVoiceSlotId\(\): Promise - -获取默认语音业务的卡槽ID,使用Promise方式作为异步方法。 - -- 返回值 - - | 类型 | 说明 | - | ----------------- | --------------------------------------- | - | Promise\ | 以Promise形式返回默认语音业务的卡槽ID。 | - -- 示例 - - ``` - let promise = sim.getDefaultVoiceSlotId(); - promise.then(data => { - console.log(`getDefaultVoiceSlotId success, promise: data->${JSON.stringify(data)}`); - }).catch(err => { - console.log(`getDefaultVoiceSlotId fail, promise: err->${JSON.stringify(err)}`); - }); - ``` - -## sim.getISOCountryCodeForSim - -getISOCountryCodeForSim\(slotId: number, callback: AsyncCallback\): void - -获取指定卡槽SIM卡的ISO国家码,使用callback方式作为异步方法。 - -- 参数 - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | ----------------------- | ---- | ---------------------------------------- | - | slotId | number | 是 | 卡槽ID。
- 0:卡槽1
- 1:卡槽2 | - | callback | AsyncCallback\ | 是 | 回调函数。返回国家码,例如:CN(中国)。 | - -- 示例 - - ``` - sim.getISOCountryCodeForSim(0, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); - }); - ``` - - -## sim.getISOCountryCodeForSim - -getISOCountryCodeForSim\(slotId: number\): Promise - -获取指定卡槽SIM卡的ISO国家码,使用Promise方式作为异步方法。 - -- 参数 - - | 参数名 | 类型 | 必填 | 说明 | - | ------ | ------ | ---- | -------------------------------------- | - | slotId | number | 是 | 卡槽ID。
- 0:卡槽1
- 1:卡槽2 | - -- 返回值 - - | 类型 | 说明 | - | ----------------- | ------------------------------------------------------------ | - | Promise\ | 以Promise形式返回获取指定卡槽SIM卡的ISO国家码,例如:CN(中国)。 | - -- 示例 - - ``` - let promise = sim.getISOCountryCodeForSim(0); - promise.then(data => { - console.log(`getISOCountryCodeForSim success, promise: data->${JSON.stringify(data)}`); - }).catch(err => { - console.log(`getISOCountryCodeForSim fail, promise: err->${JSON.stringify(err)}`); - }); - ``` - - -## sim.getSimOperatorNumeric - -getSimOperatorNumeric\(slotId: number, callback: AsyncCallback\): void - -获取指定卡槽SIM卡的归属PLMN(Public Land Mobile Network)号,使用callback方式作为异步方法。 - -- 参数 - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | ----------------------- | ---- | -------------------------------------- | - | slotId | number | 是 | 卡槽ID。
- 0:卡槽1
- 1:卡槽2 | - | callback | AsyncCallback\ | 是 | 回调函数。 | - -- 示例 - - ``` - sim.getSimOperatorNumeric(0, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); - }); - ``` - - -## sim.getSimOperatorNumeric - -getSimOperatorNumeric\(slotId: number\): Promise - -获取指定卡槽SIM卡的归属PLMN(Public Land Mobile Network)号,使用Promise方式作为异步方法。 - -- 参数 - - | 参数名 | 类型 | 必填 | 说明 | - | ------ | ------ | ---- | -------------------------------------- | - | slotId | number | 是 | 卡槽ID。
- 0:卡槽1
- 1:卡槽2 | - -- 返回值 - - | 类型 | 说明 | - | ----------------- | ------------------------------------------------ | - | Promise\ | 以Promise形式返回获取指定卡槽SIM卡的归属PLMN号。 | - -- 示例 - - ``` - let promise = sim.getSimOperatorNumeric(0); - promise.then(data => { - console.log(`getSimOperatorNumeric success, promise: data->${JSON.stringify(data)}`); - }).catch(err => { - console.log(`getSimOperatorNumeric fail, promise: err->${JSON.stringify(err)}`); - }); - ``` - - -## sim.getSimSpn - -getSimSpn\(slotId: number, callback: AsyncCallback\): void - -获取指定卡槽SIM卡的服务提供商名称(Service Provider Name,SPN),使用callback方式作为异步方法。 - -- 参数 - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | ----------------------- | ---- | -------------------------------------- | - | slotId | number | 是 | 卡槽ID。
- 0:卡槽1
- 1:卡槽2 | - | callback | AsyncCallback\ | 是 | 回调函数。 | - -- 示例 - - ``` - sim.getSimSpn(0, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); - }); - ``` - - -## sim.getSimSpn - -getSimSpn\(slotId: number\): Promise - -获取指定卡槽SIM卡的服务提供商名称(Service Provider Name,SPN),使用Promise方式作为异步方法。 - -- 参数 - - | 参数名 | 类型 | 必填 | 说明 | - | ------ | ------ | ---- | -------------------------------------- | - | slotId | number | 是 | 卡槽ID。
- 0:卡槽1
- 1:卡槽2 | - -- 返回值 - - | 类型 | 说明 | - | ----------------- | ----------------------------------------- | - | Promise\ | 以Promise形式返回获取指定卡槽SIM卡的SPN。 | - -- 示例 - - ``` - let promise = sim.getSimSpn(0); - promise.then(data => { - console.log(`getSimSpn success, promise: data->${JSON.stringify(data)}`); - }).catch(err => { - console.log(`getSimSpn fail, promise: err->${JSON.stringify(err)}`); - }); - ``` - - -## sim.getSimState - -getSimState\(slotId: number, callback: AsyncCallback\): void - -获取指定卡槽的SIM卡状态,使用callback方式作为异步方法。 - -- 参数 - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------------------------------------- | ---- | -------------------------------------- | - | slotId | number | 是 | 卡槽ID。
- 0:卡槽1
- 1:卡槽2 | - | callback | AsyncCallback\<[SimState](#SimState)\> | 是 | 回调函数。参考[SimState](#SimState)。 | - -- 示例 - - ``` - sim.getSimState(0, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); - }); - ``` - - -## sim.getSimState - -getSimState\(slotId: number\): Promise - -获取指定卡槽的SIM卡状态,使用Promise方式作为异步方法。 - -- 参数 - - | 参数名 | 类型 | 必填 | 说明 | - | ------ | ------ | ---- | -------------------------------------- | - | slotId | number | 是 | 卡槽ID。
- 0:卡槽1
- 1:卡槽2 | - -- 返回值 - - | 类型 | 说明 | - | -------------------------------- | ------------------------------------------ | - | Promise\<[SimState](#SimState)\> | 以Promise形式返回获取指定卡槽的SIM卡状态。 | - -- 示例 - - ``` - let promise = sim.getSimState(0); - promise.then(data => { - console.log(`getSimState success, promise: data->${JSON.stringify(data)}`); - }).catch(err => { - console.log(`getSimState fail, promise: err->${JSON.stringify(err)}`); - }); - ``` - -## sim.getSimGid1 - -getSimGid1\(slotId: number, callback: AsyncCallback\): void - -获取指定卡槽SIM卡的GID1\(Group Identifier Level 1\),使用callback方式作为异步方法。 - -需要ohos.permission.GET\_TELEPHONY\_STATE权限,该权限为系统权限。 - -- 参数 - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | ----------------------- | ---- | -------------------------------------- | - | slotId | number | 是 | 卡槽ID。
- 0:卡槽1
- 1:卡槽2 | - | callback | AsyncCallback\ | 是 | 回调函数。 | - -- 示例 - - ``` - sim.getSimGid1(0, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); - }); - ``` - - -## sim.getSimGid1 - -getSimGid1\(slotId: number\): Promise - -获取指定卡槽SIM卡的GID1\(Group Identifier Level 1\),使用Promise方式作为异步方法。 - -需要ohos.permission.GET\_TELEPHONY\_STATE权限,该权限为系统权限。 - -- 参数 - - | 参数名 | 类型 | 必填 | 说明 | - | ------ | ------ | ---- | -------------------------------------- | - | slotId | number | 是 | 卡槽ID。
- 0:卡槽1
- 1:卡槽2 | - -- 返回值 - - | 类型 | 说明 | - | ----------------- | ------------------------------------------------------------ | - | Promise\ | 以Promise形式返回获取指定卡槽SIM卡的GID1(Group Identifier Level 1)。 | - -- 示例 - - ``` - let promise = sim.getSimGid1(0); - promise.then(data => { - console.log(`getSimGid1 success, promise: data->${JSON.stringify(data)}`); - }).catch(err => { - console.log(`getSimGid1 fail, promise: err->${JSON.stringify(err)}`); - }); - ``` - - -## SimState - -SIM卡状态。 - -| 变量 | 说明 | -| --------------------- | ---------------------------------------------------------- | -| SIM_STATE_UNKNOWN | SIM卡状态未知,即无法获取准确的状态。 | -| SIM_STATE_NOT_PRESENT | 表示SIM卡处于not present状态,即卡槽中没有插入SIM卡。 | -| SIM_STATE_LOCKED | 表示SIM卡处于locked状态,即SIM卡被PIN、PUK或网络锁锁定。 | -| SIM_STATE_NOT_READY | 表示SIM卡处于not ready状态,即SIM卡在位但无法正常工作。 | -| SIM_STATE_READY | 表示SIM卡处于ready状态,即SIM卡在位且工作正常。 | -| SIM_STATE_LOADED | 表示SIM卡处于loaded状态,即SIM卡在位且所有卡文件加载完毕。 | \ No newline at end of file diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/08.\347\224\265\350\257\235\346\234\215\345\212\241/04.\347\275\221\347\273\234\346\220\234\347\264\242.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/08.\347\224\265\350\257\235\346\234\215\345\212\241/04.\347\275\221\347\273\234\346\220\234\347\264\242.md" deleted file mode 100644 index fa8723fc5f949e853d58ffb6071f321926294dda..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/08.\347\224\265\350\257\235\346\234\215\345\212\241/04.\347\275\221\347\273\234\346\220\234\347\264\242.md" +++ /dev/null @@ -1,472 +0,0 @@ ---- -title: 网络搜索 -permalink: /pages/010c010804 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 网络搜索 - ->**说明:** -> ->本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import radio from '@ohos.telephony.radio' -``` - -## radio.getRadioTech - -getRadioTech\(slotId: number, callback: AsyncCallback<\{psRadioTech: RadioTechnology, csRadioTech: RadioTechnology\}\>\): void - -获取当前接入的CS域和PS域无线接入技术,使用callback方式作为异步方法。 - -需要ohos.permission.GET\_NETWORK\_INFO权限。 - -- 参数 - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | ------------------------------------------------------------ | ---- | -------------------------------------- | - | slotId | number | 是 | 卡槽ID。
- 0:卡槽1
- 1:卡槽2 | - | callback | AsyncCallback\<{psRadioTech: [RadioTechnology](#RadioTechnology), csRadioTech:[RadioTechnology](#RadioTechnology)}\> | 是 | 回调函数。 | - -- 示例 - - ``` - let slotId = 0; - radio.getRadioTech(slotId, (err, data) =>{ - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); - }); - ``` - - -## radio.getRadioTech - -getRadioTech\(slotId: number\): Promise<\{psRadioTech: RadioTechnology, csRadioTech: RadioTechnology\}\> - -获取当前接入的CS域和PS域无线接入技术,使用Promise方式作为异步方法。 - -需要ohos.permission.GET\_NETWORK\_INFO权限。 - -- 参数 - - | 参数名 | 类型 | 必填 | 说明 | - | ------ | ------ | ---- | -------------------------------------- | - | slotId | number | 是 | 卡槽ID。
- 0:卡槽1
- 1:卡槽2 | - -- 返回值 - - | 类型 | 说明 | - | ------------------------------------------------------------ | ----------------------------------------------- | - | Promise<{psRadioTech: [RadioTechnology](#RadioTechnology), csRadioTech: [RadioTechnology](#RadioTechnology)}> | 以Promise形式返回获取当前接入的CS域和PS域技术。 | - -- 示例 - - ``` - let slotId = 0; - let promise = radio.getRadioTech(slotId); - promise.then(data => { - console.log(`getRadioTech success, data->${JSON.stringify(data)}`); - }).catch(err => { - console.log(`getRadioTech fail, err->${JSON.stringify(err)}`); - }); - ``` - - -## radio.getNetworkState - -getNetworkState\(callback: AsyncCallback\): void - -获取网络状态,使用callback方式作为异步方法。 - -需要ohos.permission.GET\_NETWORK\_INFO权限。 - -- 参数 - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | ---------------------------------------------- | ---- | ---------- | - | callback | AsyncCallback\<[NetworkState](#NetworkState)\> | 是 | 回调函数。 | - -- 示例 - - ``` - radio.getNetworkState((err, data) =>{ - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); - }); - ``` - - -## radio.getNetworkState - -getNetworkState\(slotId: number, callback: AsyncCallback\): void - -获取网络状态,使用callback方式作为异步方法。 - -需要ohos.permission.GET\_NETWORK\_INFO权限。 - -- 参数 - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | ---------------------------------------------- | ---- | -------------------------------------- | - | slotId | number | 是 | 卡槽ID。
- 0:卡槽1
- 1:卡槽2 | - | callback | AsyncCallback\<[NetworkState](#NetworkState)\> | 是 | 回调函数。 | - -- 示例 - - ``` - let slotId = 0; - radio.getNetworkState(slotId, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); - }); - ``` - - -## radio.getNetworkState - -getNetworkState\(slotId?: number\): Promise - -获取网络状态,使用Promise方式作为异步方法。 - -需要ohos.permission.GET\_NETWORK\_INFO权限。 - -- 参数 - - | 参数名 | 类型 | 必填 | 说明 | - | ------ | ------ | ---- | -------------------------------------- | - | slotId | number | 否 | 卡槽ID。
- 0:卡槽1
- 1:卡槽2 | - -- 返回值 - - | 类型 | 说明 | - | ---------------------------------------- | --------------------------- | - | Promise\<[NetworkState](#NetworkState)\> | 以Promise形式返回网络状态。 | - -- 示例 - - ``` - let slotId = 0; - let promise = radio.getNetworkState(slotId); - promise.then(data => { - console.log(`getNetworkState success, promise: data->${JSON.stringify(data)}`); - }).catch(err => { - console.log(`getNetworkState fail, promise: err->${JSON.stringify(err)}`); - }); - ``` - - -## radio.getNetworkSelectionMode - -getNetworkSelectionMode\(slotId: number, callback: AsyncCallback\): void - -获取当前选网模式,使用callback方式作为异步方法。 - -- 参数 - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | ------------------------------------------------------------ | ---- | -------------------------------------- | - | slotId | number | 是 | 卡槽ID。
- 0:卡槽1
- 1:卡槽2 | - | callback | AsyncCallback\<[NetworkSelectionMode](#NetworkSelectionMode)\> | 是 | 回调函数。 | - -- 示例 - - ``` - let slotId = 0; - radio.getNetworkSelectionMode(slotId, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); - }); - ``` - - -## radio.getNetworkSelectionMode - -getNetworkSelectionMode\(slotId: number\): Promise - -获取当前选网模式,使用Promise方式作为异步方法。 - -- 参数 - - | 参数名 | 类型 | 必填 | 说明 | - | ------ | ------ | ---- | -------------------------------------- | - | slotId | number | 是 | 卡槽ID。
- 0:卡槽1
- 1:卡槽2 | - -- 返回值 - - | 类型 | 说明 | - | -------------------------------------------------------- | ------------------------------- | - | Promise\<[NetworkSelectionMode](#NetworkSelectionMode)\> | 以Promise形式返回当前选网模式。 | - -- 示例 - - ``` - let slotId = 0; - let promise = radio.getNetworkSelectionMode(slotId); - promise.then(data => { - console.log(`getNetworkSelectionMode success, promise: data->${JSON.stringify(data)}`); - }).catch(err => { - console.log(`getNetworkSelectionMode fail, promise: err->${JSON.stringify(err)}`); - }); - ``` - - -## radio.getISOCountryCodeForNetwork7+ - -getISOCountryCodeForNetwork\(slotId: number, callback: AsyncCallback\): void - -获取注册网络所在国家的ISO国家码,使用callback方式作为异步方法。 - -- 参数 - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | ----------------------- | ---- | ---------------------------------------- | - | slotId | number | 是 | 卡槽ID。
- 0:卡槽1
- 1:卡槽2 | - | callback | AsyncCallback\ | 是 | 回调函数。返回国家码,例如:CN(中国)。 | - -- 示例 - - ``` - let slotId = 0; - radio.getISOCountryCodeForNetwork(slotId, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); - }); - ``` - - -## radio.getISOCountryCodeForNetwork7+ - -getISOCountryCodeForNetwork\(slotId: number\): Promise - -获取注册网络所在国家的ISO国家码,使用Promise方式作为异步方法。 - -- 参数 - - | 参数名 | 类型 | 必填 | 说明 | - | ------ | ------ | ---- | -------------------------------------- | - | slotId | number | 是 | 卡槽ID。
- 0:卡槽1
- 1:卡槽2 | - -- 返回值 - - | 类型 | 说明 | - | ----------------- | ------------------------------------------------------------ | - | Promise\ | 以Promise形式返回注册网络所在国家的ISO国家码,例如CN(中国)。 | - -- 示例 - - ``` - let slotId = 0; - let promise = radio.getISOCountryCodeForNetwork(slotId); - promise.then(data => { - console.log(`getISOCountryCodeForNetwork success, promise: data->${JSON.stringify(data)}`); - }).catch(err => { - console.log(`getISOCountryCodeForNetwork fail, promise: err->${JSON.stringify(err)}`); - }); - ``` - - -## radio.getSignalInformation - -getSignalInformation\(slotId: number, callback: AsyncCallback\>\): void - -获取指定SIM卡槽对应的注册网络信号强度信息列表,使用callback方式作为异步方法。 - -- 参数 - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | - | slotId | number | 是 | 卡槽ID。
- 0:卡槽1
- 1:卡槽2 | - | callback | AsyncCallback\\> | 是 | 回调函数,返回[SignalInformation](#SignalInformation)对象的数组。 | - -- 示例 - - ``` - let slotId = 0; - radio.getSignalInformation(slotId, (err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); - }); - ``` - - -## radio.getSignalInformation - -getSignalInformation\(slotId: number\): Promise\> - -获取指定SIM卡槽对应的注册网络信号强度信息列表,使用Promise方式作为异步方法。 - -- 参数 - - | 参数名 | 类型 | 必填 | 说明 | - | ------ | ------ | ---- | -------------------------------------- | - | slotId | number | 是 | 卡槽ID。
- 0:卡槽1
- 1:卡槽2 | - -- 返回值 - - | 类型 | 说明 | - | ----------------------------------------------------------- | ------------------------------------------------------------ | - | Promise\\> | 以Promise形式返回网络信号强度[SignalInformation](#SignalInformation)对象的数组。 | - -- 示例 - - ``` - let slotId = 0; - let promise = radio.getSignalInformation(slotId); - promise.then(data => { - console.log(`getSignalInformation success, promise: data->${JSON.stringify(data)}`); - }).catch(err => { - console.error(`getSignalInformation fail, promise: err->${JSON.stringify(err)}`); - }); - ``` - - -## radio.isRadioOn7+ - -isRadioOn\(callback: AsyncCallback\): void - -判断Radio是否打开,使用callback方式作为异步方法。 - -需要ohos.permission.GET\_NETWORK\_INFO权限。 - -- 参数 - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | ------------------------ | ---- | ------------------------------------------------------- | - | callback | AsyncCallback\ | 是 | 回调函数。
- true:Radio打开
- false:Radio关闭 | - -- 示例 - - ``` - radio.isRadioOn((err, data) => { - console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); - }); - ``` - - -## radio.isRadioOn7+ - -isRadioOn\(\): Promise - -判断Radio是否打开,使用Promise方式作为异步方法。 - -需要ohos.permission.GET\_NETWORK\_INFO权限。 - -- 返回值 - - | 类型 | 说明 | - | ------------------ | ------------------------------------------------------------ | - | Promise\ | 以Promise形式返回判断Radio是否打开的结果。
- true:Radio打开
- false:Radio关闭 | - -- 示例 - - ``` - let promise = radio.isRadioOn(); - promise.then(data => { - console.log(`isRadioOn success, promise: data->${JSON.stringify(data)}`); - }).catch(err => { - console.error(`isRadioOn fail, promise: err->${JSON.stringify(err)}`); - }); - ``` - - -## RadioTechnology - -无线接入技术。 - -| 变量 | 值 | 说明 | -| ------------------------- | ---- | ------------------------------------------------------------ | -| RADIO_TECHNOLOGY_UNKNOWN | 0 | 未知无线接入技术(RAT)。 | -| RADIO_TECHNOLOGY_GSM | 1 | 无线接入技术GSM(Global System For Mobile Communication)。 | -| RADIO_TECHNOLOGY_1XRTT | 2 | 无线接入技术1XRTT(Single-Carrier Radio Transmission Technology)。 | -| RADIO_TECHNOLOGY_WCDMA | 3 | 无线接入技术WCDMA(Wideband Code Division Multiple Access)。 | -| RADIO_TECHNOLOGY_HSPA | 4 | 无线接入技术HSPA(High Speed Packet Access)。 | -| RADIO_TECHNOLOGY_HSPAP | 5 | 无线接入技术HSPAP(High Speed packet access (HSPA+) )。 | -| RADIO_TECHNOLOGY_TD_SCDMA | 6 | 无线接入技术TDSCDMA(TimeDivision-Synchronous Code Division Multiple Access)。 | -| RADIO_TECHNOLOGY_EVDO | 7 | 无线接入技术EVDO(Evolution、Data Only)。 | -| RADIO_TECHNOLOGY_EHRPD | 8 | 无线接入技术EHRPD(Evolved High Rate Package Data)。 | -| RADIO_TECHNOLOGY_LTE | 9 | 无线接入技术LTE(Long Term Evolution)。 | -| RADIO_TECHNOLOGY_LTE_CA | 10 | 无线接入技术LTE_CA(Long Term Evolution_Carrier Aggregation)。 | -| RADIO_TECHNOLOGY_IWLAN | 11 | 无线接入技术IWLAN(Industrial Wireless LAN)。 | -| RADIO_TECHNOLOGY_NR | 12 | 无线接入技术NR(New Radio)。 | - - -## SignalInformation - -网络信号强度信息对象。 - -| 属性名 | 类型 | 说明 | -| ----------- | --------------------------- | ------------------ | -| signalType | [NetworkType](#NetworkType) | 网络信号强度类型。 | -| signalLevel | number | 网络信号强度等级。 | - - -## NetworkType - -网络类型。 - -| 变量 | 值 | 说明 | -| -------------------- | ---- | ------------------------------------------------------------ | -| NETWORK_TYPE_UNKNOWN | 0 | 未知网络类型。 | -| NETWORK_TYPE_GSM | 1 | 网络类型为GSM(Global System For Mobile Communication)。 | -| NETWORK_TYPE_CDMA | 2 | 网络类型为CDMA(Code Division Multiple Access)。 | -| NETWORK_TYPE_WCDMA | 3 | 网络类型为WCDMA(Wideband Code Division Multiple Access)。 | -| NETWORK_TYPE_TDSCDMA | 4 | 网络类型为TDSCDMA(TimeDivision-Synchronous Code Division Multiple Access)。 | -| NETWORK_TYPE_LTE | 5 | 网络类型为LTE(Long Term Evolution)。 | -| NETWORK_TYPE_NR | 6 | 网络类型为5G NR(New Radio)。 | - -## NetworkState - -网络注册状态。 - -| 变量 | 类型 | 说明 | -| ----------------- | --------------------- | ------------------------------ | -| longOperatorName | string | 注册网络的长运营商名称。 | -| shortOperatorName | string | 注册网络的短运营商名称。 | -| plmnNumeric | string | 注册网络的PLMN码。 | -| isRoaming | boolean | 是否处于漫游状态。 | -| regState | [RegState](#RegState) | 设备的网络注册状态。 | -| nsaState | [NsaState](#NsaState) | 设备的NSA网络注册状态。 | -| isCaActive | boolean | CA的状态。 | -| isEmergency | boolean | 此设备是否只允许拨打紧急呼叫。 | - - -## RegState - -网络注册状态。 - -| 变量 | 值 | 说明 | -| ----------------------------- | ---- | -------------------------- | -| REG_STATE_NO_SERVICE | 0 | 设备不能使用任何服务。 | -| REG_STATE_IN_SERVICE | 1 | 设备可以正常使用业务。 | -| REG_STATE_EMERGENCY_CALL_ONLY | 2 | 设备只能使用紧急呼叫业务。 | -| REG_STATE_POWER_OFF | 3 | 蜂窝无线电已关闭。 | - - -## NsaState - -非独立组网状态。 - -| 变量 | 值 | 说明 | -| -------------------------- | ---- | ---------------------------------------------------------- | -| NSA_STATE_NOT_SUPPORT | 1 | 设备在不支持NSA的LTE小区下处于空闲状态或连接状态。 | -| NSA_STATE_NO_DETECT | 2 | 在支持NSA但不支持NR覆盖检测的LTE小区下,设备处于空闲状态。 | -| NSA_STATE_CONNECTED_DETECT | 3 | 设备在LTE小区下连接到LTE网络支持NSA和NR覆盖检测。 | -| NSA_STATE_IDLE_DETECT | 4 | 支持NSA和NR覆盖检测的LTE小区下设备处于空闲状态。 | -| NSA_STATE_DUAL_CONNECTED | 5 | 设备在支持NSA的LTE小区下连接到LTE + NR网络。 | -| NSA_STATE_SA_ATTACHED | 6 | 设备在5GC附着时在NG-RAN小区下空闲或连接到NG-RAN小区。 | - - -## NetworkSelectionMode - -选网模式。 - -| 变量 | 值 | 说明 | -| --------------------------- | ---- | -------------- | -| NETWORK_SELECTION_UNKNOWN | 0 | 未知选网模式。 | -| NETWORK_SELECTION_AUTOMATIC | 1 | 自动选网模式。 | -| NETWORK_SELECTION_MANUAL | 2 | 手动选网模式。 | \ No newline at end of file diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/09.\347\275\221\347\273\234\344\270\216\350\277\236\346\216\245/01.WLAN.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/09.\347\275\221\347\273\234\344\270\216\350\277\236\346\216\245/01.WLAN.md" deleted file mode 100644 index e184993fca7023804e9f634a1dfbf3c3370e428f..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/09.\347\275\221\347\273\234\344\270\216\350\277\236\346\216\245/01.WLAN.md" +++ /dev/null @@ -1,485 +0,0 @@ ---- -title: WLAN -permalink: /pages/010c010901 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# WLAN - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import wifi from '@ohos.wifi'; -``` - - -## wifi.isWifiActive - -isWifiActive(): boolean - -查询WLAN是否已激活。 - -- 返回值: - | **类型** | **说明** | - | -------- | -------- | - | boolean | true:已激活, false:未激活。 | - - -## wifi.scan - -scan(): boolean - -启动WLAN扫描。 - -- 返回值: - | **类型** | **说明** | - | -------- | -------- | - | boolean | true:扫描操作成功, false:扫描操作执行失败。 | - - -## wifi.getScanInfos - -getScanInfos(): Promise<Array<WifiScanInfo>> - -获取扫描结果,使用promise方式作为异步方法。 - -- 返回值: - | **类型** | **说明** | - | -------- | -------- | - | Promise< Array<[WifiScanInfo](#wifiscaninfo)> > | 返回扫描到的热点列表。 | - - -## wifi.getScanInfos - -getScanInfos(callback: AsyncCallback<Array<WifiScanInfo>>): void - -获取扫描结果,使用callback方式作为异步方法。 - -- 参数 - | **参数名** | **类型** | **必填** | **说明** | - | -------- | -------- | -------- | -------- | - | callback | AsyncCallback< Array<[WifiScanInfo](#wifiscaninfo)>> | 是 | 扫描到的热点列表结果回调函数。 | - -- 示例 - ``` - import wifi from '@ohos.wifi'; - - wifi.getScanInfos(result => { - var len = Object.keys(result).length; - console.log("wifi received scan info call back: " + len); - for (var i = 0; i < len; ++i) { - console.info("ssid: " + result[i].ssid); - console.info("bssid: " + result[i].bssid); - console.info("securityType: " + result[i].securityType); - console.info("rssi: " + result[i].rssi); - console.info("band: " + result[i].band); - console.info("frequency: " + result[i].frequency); - console.info("timestamp: " + result[i].timestamp); - } - }); - - wifi.getScanInfos().then(result => { - var len = Object.keys(result).length; - console.log("wifi received scan info promise: " + len); - for (var i = 0; i < len; ++i) { - console.info("ssid: " + result[i].ssid); - console.info("bssid: " + result[i].bssid); - console.info("securityType: " + result[i].securityType); - console.info("rssi: " + result[i].rssi); - console.info("band: " + result[i].band); - console.info("frequency: " + result[i].frequency); - console.info("timestamp: " + result[i].timestamp); - } - }); - ``` - - -## WifiScanInfo - -WLAN热点信息。 - -| **参数名** | **类型** | **读写属性** | **说明** | -| -------- | -------- | -------- | -------- | -| ssid | string | 只读 | 热点的SSID,编码格式为UTF-8。 | -| bssid | string | 只读 | 热点的BSSID。 | -| securityType | [WifiSecurityType](#wifisecuritytype) | 只读 | WLAN加密类型。 | -| rssi | number | 只读 | 热点的信号强度(dBm)。 | -| band | number | 只读 | WLAN接入点的频段。 | -| frequency | number | 只读 | WLAN接入点的频率。 | -| timestamp | number | 只读 | 时间戳。 | - - -## WifiSecurityType - -表示加密类型的枚举。 - -| **名称** | **默认值** | **说明** | -| -------- | -------- | -------- | -| WIFI_SEC_TYPE_INVALID | 0 | 无效加密类型。 | -| WIFI_SEC_TYPE_OPEN | 1 | 开放加密类型。 | -| WIFI_SEC_TYPE_WEP | 2 | Wired Equivalent Privacy (WEP)加密类型。 | -| WIFI_SEC_TYPE_PSK | 3 | Pre-shared key (PSK)加密类型。 | -| WIFI_SEC_TYPE_SAE | 4 | Simultaneous Authentication of Equals (SAE)加密类型。 | - - -## wifi.getSignalLevel - -getSignalLevel(rssi: number, band: number): number - -查询WLAN信号强度。 - -- 参数: - | **参数名** | **类型** | **必填** | **说明** | - | -------- | -------- | -------- | -------- | - | rssi | number | 是 | 热点的信号强度(dBm)。 | - | band | number | 是 | WLAN接入点的频段。 | - -- 返回值: - | **类型** | **说明** | - | -------- | -------- | - | number | 信号强度,取值范围为[0, 4]。 | - - -## wifi.getIpInfo7+ - -getIpInfo(): IpInfo - -获取IP信息。 - -- 返回值: - | **类型** | **说明** | - | -------- | -------- | - | [IpInfo](#ipinfo) | 返回IP信息。 | - - -## IpInfo - -IP信息。 - -| **参数名** | **类型** | **读写属性** | **说明** | -| -------- | -------- | -------- | -------- | -| ipAddress | number | 只读 | IP地址。 | -| gateway | number | 只读 | 网关。 | -| netmask | number | 只读 | 掩码。 | -| primaryDns | number | 只读 | 主DNS服务器IP地址。 | -| secondDns | number | 只读 | 备DNS服务器IP地址。 | -| serverIp | number | 只读 | DHCP服务端IP地址。 | -| leaseDuration | number | 只读 | IP地址租用时长。 | - - -## wifi.isConnected7+ - -isConnected(): boolean - -查询WLAN是否已连接。 - -- 返回值: - | **类型** | **说明** | - | -------- | -------- | - | boolean | true:已连接, false:未连接。 | - - -## wifi.getLinkedInfo7+ - -getLinkedInfo(): Promise<WifiLinkedInfo> - -获取WLAN连接信息,使用promise方式作为异步方法。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<[WifiLinkedInfo](#wifilinkedinfo)> | 返回WLAN连接的相关信息。 | - - -## wifi.getLinkedInfo7+ - -getLinkedInfo(callback: AsyncCallback<WifiLinkedInfo>): void - -获取WLAN连接信息,使用callback方式作为异步方法。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<[WifiLinkedInfo](#wifilinkedinfo)> | 是 | 获取WLAN连接信息结果回调函数。 | - -- 示例 - ``` - import wifi from '@ohos.wifi'; - - wifi.getLinkedInfo(data => { - console.info("get wifi linked info [callback]: " + JSON.stringify(data)); - }); - - wifi.getLinkedInfo().then(data => { - console.info("get wifi linked info [promise]: " + JSON.stringify(data)); - }).catch(error => { - console.info("linked info promise then error"); - }); - ``` - - -## WifiLinkedInfo - -提供WLAN连接的相关信息。 - -| 参数名 | 类型 | 读写属性 | 说明 | -| -------- | -------- | -------- | -------- | -| ssid | string | 只读 | 热点的SSID,编码格式为UTF-8。 | -| bssid | string | 只读 | 热点的BSSID。 | -| rssi | number | 只读 | 热点的信号强度(dBm)。 | -| band | number | 只读 | WLAN接入点的频段。 | -| linkSpeed | number | 只读 | WLAN接入点的速度。 | -| frequency | number | 只读 | WLAN接入点的频率。 | -| isHidden | boolean | 只读 | WLAN接入点是否是隐藏网络。 | -| isRestricted | boolean | 只读 | WLAN接入点是否限制数据量。 | -| macAddress | string | 只读 | 设备的MAC地址。 | -| ipAddress | number | 只读 | WLAN连接的IP地址。 | -| connState | ConnState | 只读 | WLAN连接状态。 | - - -## ConnState - -表示WLAN连接状态的枚举。 - -| 名称 | 默认值 | 说明 | -| -------- | -------- | -------- | -| SCANNING | 0 | 设备正在搜索可用的AP。 | -| CONNECTING | 1 | 正在建立WLAN连接。 | -| AUTHENTICATING | 2 | WLAN连接正在认证中。 | -| OBTAINING_IPADDR | 3 | 正在获取WLAN连接的IP地址。 | -| CONNECTED | 4 | WLAN连接已建立。 | -| DISCONNECTING | 5 | WLAN连接正在断开。 | -| DISCONNECTED | 6 | WLAN连接已断开。 | -| UNKNOWN | 7 | WLAN连接建立失败。 | - - -## wifi.getCountryCode7+ - -getCountryCode(): string - -获取国家码信息。 - -- 返回值: - | **类型** | **说明** | - | -------- | -------- | - | string | 国家码。 | - - -## wifi.isFeatureSupported7+ - -isFeatureSupported(featureId: number): boolean - -判断设备是否支持相关WLAN特性。 - -- 参数: - | **参数名** | **类型** | 必填 | **说明** | - | -------- | -------- | -------- | -------- | - | featureId | number | 是 | 特性ID值。 | - -- 返回值: - | **类型** | **说明** | - | -------- | -------- | - | boolean | true:支持, false:不支持。 | - -- 特性ID值枚举。 - | 枚举值 | 说明 | - | -------- | -------- | - | 0x0001 | 基础结构模式特性。 | - | 0x0002 | 5 GHz带宽特性。 | - | 0x0004 | GAS/ANQP特性。 | - | 0x0008 | Wifi-Direct特性。 | - | 0x0010 | Soft AP特性。 | - | 0x0040 | Wi-Fi AWare组网特性。 | - | 0x8000 | AP STA共存特性。 | - | 0x8000000 | WPA3-Personal SAE特性。 | - | 0x10000000 | WPA3-Enterprise Suite-B | - | 0x20000000 | 增强开放特性。 | - - -## wifi.on('wifiStateChange')7+ - -on(type: "wifiStateChange", callback: Callback<number>): void - -注册WLAN状态改变事件。 - -- 参数 - | **参数名** | **类型** | **必填** | **说明** | - | -------- | -------- | -------- | -------- | - | type | string | 是 | 固定填"wifiStateChange"字符串 | - | callback | Callback<number> | 是 | 状态改变回调函数。 | - -- 状态改变事件的枚举。 - | **枚举值** | **说明** | - | -------- | -------- | - | 0 | 未激活。 | - | 1 | 已激活。 | - | 2 | 激活中。 | - | 3 | 去激活中。 | - - -## wifi.off('wifiStateChange')7+ - -off(type: "wifiStateChange", callback?: Callback<number>): void - -取消注册WLAN状态改变事件。 - -- 参数 - | **参数名** | **类型** | **必填** | **说明** | - | -------- | -------- | -------- | -------- | - | type | string | 是 | 固定填"wifiStateChange"字符串 | - | callback | Callback<number> | 否 | 状态改变回调函数。如果callback不填,将去注册该事件关联的所有回调函数。 | - -- 示例 - ``` - import wifi from '@ohos.wifi'; - import { EventListener } from '@ohos.wifi'; - - var WIFI_POWER_STATE = "wifiStateChange"; - var listener = new EventListener(); - - var recvPowerNotifyFunc = result => { - console.info("power state receive event: " + result); - } - - // Register event - listener.on(WIFI_POWER_STATE, recvPowerNotifyFunc); - - // Unregister event - listener.off(WIFI_POWER_STATE, recvPowerNotifyFunc); - ``` - - -## wifi.on('wifiConnectionChange')7+ - -on(type: "wifiConnectionChange", callback: Callback<number>): void - -注册WLAN连接状态改变事件。 - -- 参数 - | **参数名** | **类型** | **必填** | **说明** | - | -------- | -------- | -------- | -------- | - | type | string | 是 | 固定填"wifiConnectionChange"字符串 | - | callback | Callback<number> | 是 | 状态改变回调函数。 | - -- 连接状态改变事件的枚举。 - | **枚举值** | **说明** | - | -------- | -------- | - | 0 | 已断开。 | - | 1 | 已连接。 | - - -## wifi.off('wifiConnectionChange')7+ - -off(type: "wifiConnectionChange", callback?: Callback<number>): void - -取消注册WLAN连接状态改变事件。 - -- 参数 - | **参数名** | **类型** | **必填** | **说明** | - | -------- | -------- | -------- | -------- | - | type | string | 是 | 固定填"wifiConnectionChange"字符串 | - | callback | Callback<number> | 否 | 连接状态改变回调函数。如果callback不填,将去注册该事件关联的所有回调函数。 | - - -## wifi.on('wifiScanStateChange')7+ - -on(type: "wifiScanStateChange", callback: Callback<number>): void - -注册扫描状态改变事件。 - -- 参数 - | **参数名** | **类型** | **必填** | **说明** | - | -------- | -------- | -------- | -------- | - | type | string | 是 | 固定填"wifiScanStateChange"字符串 | - | callback | Callback<number> | 是 | 状态改变回调函数。 | - -- 扫描状态改变事件的枚举。 - | **枚举值** | **说明** | - | -------- | -------- | - | 0 | 扫描失败。 | - | 1 | 扫描成功。 | - - -## wifi.off('wifiScanStateChange')7+ - -off(type: "wifiScanStateChange", callback?: Callback<number>): void - -取消注册扫描状态改变事件。 - -- 参数 - -| **参数名** | **类型** | **必填** | **说明** | -| -------- | -------- | -------- | -------- | -| type | string | 是 | 固定填"wifiScanStateChange"字符串 | -| callback | Callback<number> | 否 | 状态改变回调函数。如果callback不填,将去注册该事件关联的所有回调函数。 | - - -## wifi.on('wifiRssiChange')7+ - -on(type: "wifiRssiChange", callback: Callback<number>): void - -注册RSSI状态改变事件。 - -- 参数 - | **参数名** | **类型** | **必填** | **说明** | - | -------- | -------- | -------- | -------- | - | type | string | 是 | 固定填"wifiRssiChange"字符串 | - | callback | Callback<number> | 是 | 状态改变回调函数,返回以dBm为单位的RSSI值。 | - - -## wifi.off('wifiRssiChange')7+ - -off(type: "wifiRssiChange", callback?: Callback<number>): void - -取消注册RSSI状态改变事件。 - -- 参数 - | **参数名** | **类型** | **必填** | **说明** | - | -------- | -------- | -------- | -------- | - | type | string | 是 | 固定填"wifiRssiChange"字符串 | - | callback | Callback<number> | 否 | 状态改变回调函数。如果callback不填,将去注册该事件关联的所有回调函数。 | - - -## wifi.on('hotspotStateChange')7+ - -on(type: "hotspotStateChange", callback: Callback<number>): void - -注册热点状态改变事件。 - -- 参数 - | **参数名** | **类型** | **必填** | **说明** | - | -------- | -------- | -------- | -------- | - | type | string | 是 | 固定填"hotspotStateChange"字符串 | - | callback | Callback<number> | 是 | 状态改变回调函数。 | - -- 热点状态改变事件的枚举。 - | **枚举值** | **说明** | - | -------- | -------- | - | 0 | 未激活。 | - | 1 | 已激活。 | - | 2 | 激活中。 | - | 3 | 去激活中。 | - - -## wifi.off('hotspotStateChange')7+ - -off(type: "hotspotStateChange", callback?: Callback<number>): void - -取消注册热点状态改变事件。 - -- 参数 - | **参数名** | **类型** | **必填** | **说明** | - | -------- | -------- | -------- | -------- | - | type | string | 是 | 固定填"hotspotStateChange"字符串 | - | callback | Callback<number> | 否 | 状态改变回调函数。如果callback不填,将去注册该事件关联的所有回调函数。 | diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/10.\350\256\276\345\244\207\347\256\241\347\220\206/01.\344\274\240\346\204\237\345\231\250.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/10.\350\256\276\345\244\207\347\256\241\347\220\206/01.\344\274\240\346\204\237\345\231\250.md" deleted file mode 100644 index d351f092ae5efcf0463812b0e2cbc38ec9888ae7..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/10.\350\256\276\345\244\207\347\256\241\347\220\206/01.\344\274\240\346\204\237\345\231\250.md" +++ /dev/null @@ -1,1557 +0,0 @@ ---- -title: 传感器 -permalink: /pages/010c010a01 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 传感器 - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import sensor from '@ohos.sensor'; -``` - -## 系统能力 - -SystemCapability.Sensors.Sensor - -## 权限列表 - -计步器:ohos.permission.ACTIVITY_MOTION - -心率:ohos.permission.READ_HEALTH_DATA - -加速度:ohos.permission.ACCELEROMETER - -陀螺仪:ohos.permission.GYROSCOPE - - -## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER) - -on(type: sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: AsyncCallback<AccelerometerResponse>,options?: Options): void - - -监听加速度传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 要订阅的加速度传感器类型为SENSOR_TYPE_ID_ACCELEROMETER。 | - | callback | AsyncCallback<[AccelerometerResponse](#accelerometerresponse)> | 是 | 注册加速度传感器的回调函数,上报的数据类型为AccelerometerResponse。 | - | options | [Options](#options) | 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 | - -- 示例: - ``` - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - }, - {interval: 10000000} - ); - ``` - - -## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION) - -on(type:sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,callback:AsyncCallback<LinearAccelerometerResponse>, options?: Options): void - -监听线性加速度传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 要订阅的线性加速度传感器类型为SENSOR_TYPE_ID_LINEAR_ACCELERATION。 | - | callback | AsyncCallback<[LinearAccelerometerResponse](#linearaccelerometerresponse)> | 是 | 注册线性加速度传感器的回调函数,上报的数据类型为LinearAccelerometerResponse。 | - | options | [Options](#options) | 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 | - -- 示例: - ``` - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - }, - {interval: 10000000} - ); - ``` - - -## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED) - -on(type:sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,callback:AsyncCallback<AccelerometerUncalibratedResponse>, options?: Options): void - -监听未校准加速度计传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 要订阅的未校准加速度计传感器类型为SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED。 | - | callback | AsyncCallback<[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)> | 是 | 注册未校准加速度计传感器的回调函数,上报的数据类型为AccelerometerUncalibratedResponse。 | - | options | [Options](#options) | 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 | - -- 示例: - ``` - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - console.info('X-coordinate bias: ' + data.biasX); - console.info('Y-coordinate bias: ' + data.biasY); - console.info('Z-coordinate bias: ' + data.biasZ); - }, - {interval: 10000000} - ); - ``` - - -## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY) - -on(type: sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback: AsyncCallback<GravityResponse>,options?: Options): void - -监听重力传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 要订阅的重力传感器类型为SENSOR_TYPE_ID_GRAVITY。 | - | callback | AsyncCallback<[GravityResponse](#gravityresponse)> | 是 | 注册重力传感器的回调函数,上报的数据类型为GravityResponse。 | - | options | [Options](#options) | 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 | - -- 示例: - ``` - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - }, - {interval: 10000000} - ); - ``` - - -## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE) - -on(type: sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback: AsyncCallback<GyroscopeResponse>, options?: Options): void - -监听陀螺仪传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 要订阅的陀螺仪传感器类型为SENSOR_TYPE_ID_GYROSCOPE。 | - | callback | AsyncCallback<[GyroscopeResponse](#gyroscoperesponse)> | 是 | 注册陀螺仪传感器的回调函数,上报的数据类型为GyroscopeResponse。 | - | options | [Options](#options) | 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 | - -- 示例: - ``` - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - }, - {interval: 10000000} - ); - ``` - - -## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED) - -on(type:sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback:AsyncCallback<GyroscopeUncalibratedResponse>, options?: Options): void - -监听未校准陀螺仪传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 要订阅的未校准陀螺仪传感器类型为SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED。 | - | callback | AsyncCallback<[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)> | 是 | 注册未校准陀螺仪传感器的回调函数,上报的数据类型为GyroscopeUncalibratedResponse。 | - | options | [Options](#options) | 否 | 可选参数列表,设置上报频率。 | - -- 示例: - ``` - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - console.info('X-coordinate bias: ' + data.biasX); - console.info('Y-coordinate bias: ' + data.biasY); - console.info('Z-coordinate bias: ' + data.biasZ); - }, - {interval: 10000000} - ); - ``` - - -## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION) - -on(type: sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback: AsyncCallback<SignificantMotionResponse>, options?: Options): void - -监听大幅动作传感器数据变化。如果多次调用该接口,仅最后一次调用生效。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 要订阅的大幅动作传感器类型为SENSOR_TYPE_ID_SIGNIFICANT_MOTION。 | - | callback | AsyncCallback<[SignificantMotionResponse](#significantmotionresponse)> | 是 | 注册有效运动传感器的回调函数,上报的数据类型为SignificantMotionResponse。 | - | options | [Options](#options) | 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 | - -- 示例: - ``` - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('Scalar data: ' + data.scalar); - }, - {interval: 10000000} - ); - ``` - - -## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION) - -on(type: sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback: AsyncCallback<PedometerDetectResponse>, options?: Options): void - -监听计步检测传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 要订阅的计步检测传感器类型为SENSOR_TYPE_ID_PEDOMETER_DETECTION。 | - | callback | AsyncCallback<[PedometerDetectResponse](#pedometerdetectresponse)> | 是 | 注册计步检测传感器的回调函数,上报的数据类型为PedometerDetectResponse。 | - | options | [Options](#options) | 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 | - -- 示例: - ``` - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('Scalar data: ' + data.scalar); - }, - {interval: 10000000} - ); - ``` - - -## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER) - -on(type: sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, callback: AsyncCallback<PedometerResponse>, options?: Options): void - -监听计步传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 要订阅的计步传感器类型为SENSOR_TYPE_ID_PEDOMETER。 | - | callback | AsyncCallback<[PedometerResponse](#pedometerresponse)> | 是 | 注册计步传感器的回调函数,上报的数据类型为PedometerResponse。 | - | options | [Options](#options) | 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 | - -- 示例: - ``` - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('Steps: ' + data.steps); - }, - {interval: 10000000} - ); - ``` - - -## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE) - -on(type:sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback:AsyncCallback<AmbientTemperatureResponse>, options?: Options): void - -监听环境温度传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 要订阅的环境温度传感器类型为SENSOR_TYPE_ID_AMBIENT_TEMPERATURE。 | - | callback | AsyncCallback<[AmbientTemperatureResponse](#ambienttemperatureresponse)> | 是 | 注册环境温度传感器的回调函数,上报的数据类型为AmbientTemperatureResponse。 | - | options | [Options](#options) | 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 | - -- 示例: - ``` - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('Temperature: ' + data.temperature); - }, - {interval: 10000000} - ); - ``` - - -## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD) - -on(type: sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback: AsyncCallback<MagneticFieldResponse>,options?: Options): void - -监听磁场传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 要订阅的磁场传感器类型为SENSOR_TYPE_ID_MAGNETIC_FIELD。 | - | callback | AsyncCallback<[MagneticFieldResponse](#magneticfieldresponse)> | 是 | 注册磁场传感器的回调函数,上报的数据类型为MagneticFieldResponse。 | - | options | [Options](#options) | 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 | - -- 示例: - ``` - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - }, - {interval: 10000000} - ); - ``` - - -## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED) - -on(type:sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback:AsyncCallback<MagneticFieldUncalibratedResponse>, options: Options): void - -监听未校准磁场传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 要订阅的未校准磁场传感器类型为SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED。 | - | callback | AsyncCallback<[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)> | 是 | 注册未校准磁场传感器的回调函数,上报的数据类型为MagneticFieldUncalibratedResponse。 | - | options | [Options](#options) | 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 | - -- 示例: - ``` - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - console.info('X-coordinate bias: ' + data.biasX); - console.info('Y-coordinate bias: ' + data.biasY); - console.info('Z-coordinate bias: ' + data.biasZ); - }, - {interval: 10000000} - ); - ``` - - -## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY) - -on(type:sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: AsyncCallback<ProximityResponse>,options?: Options): void - -监听接近光传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 要订阅的接近光传感器类型为SENSOR_TYPE_ID_PROXIMITY。 | - | callback | AsyncCallback<[ProximityResponse](#proximityresponse)> | 是 | 注册接近光传感器的回调函数,上报的数据类型为ProximityResponse。 | - | options | [Options](#options) | 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 | - -- 示例: - ``` - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('Distance: ' + data.distance); - }, - {interval: 10000000} - ); - ``` - - -## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY) - -on(type: sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, callback: AsyncCallback<HumidityResponse>,options?: Options): void - -监听湿度传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 要订阅的湿度传感器类型为SENSOR_TYPE_ID_HUMIDITY。 | - | callback | AsyncCallback<[HumidityResponse](#humidityresponse)> | 是 | 注册湿度传感器的回调函数,上报的数据类型为HumidityResponse。 | - | options | [Options](#options) | 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 | - -- 示例: - ``` - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('Humidity: ' + data.humidity); - }, - {interval: 10000000} - ); - ``` - - -## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER) - -on(type:sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, callback: AsyncCallback<BarometerResponse>,options?: Options): void - -监听气压计传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 要订阅的气压计传感器类型为SENSOR_TYPE_ID_BAROMETER。 | - | callback | AsyncCallback<[BarometerResponse](#barometerresponse)> | 是 | 注册气压计传感器的回调函数,上报的数据类型为BarometerResponse。 | - | options | [Options](#options) | 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 | - -- 示例: - ``` - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('Atmospheric pressure: ' + data.pressure); - }, - {interval: 10000000} - ); - ``` - - -## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HALL) - -on(type: sensor.SensorType.SENSOR_TYPE_ID_HALL, callback: AsyncCallback<HallResponse>, options?: Options): void - -监听霍尔传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 要订阅的霍尔传感器类型为SENSOR_TYPE_ID_HALL。 | - | callback | AsyncCallback<[HallResponse](#hallresponse)> | 是 | 注册霍尔传感器的回调函数,上报的数据类型为 HallResponse。 | - | options | [Options](#options) | 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 | - -- 示例: - ``` - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HALL,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('Status: ' + data.status); - }, - {interval: 10000000} - ); - ``` - - -## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT) - -on(type:sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback: AsyncCallback<LightResponse>, options?: Options): void - -监听环境光传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 要订阅的环境光传感器类型为SENSOR_TYPE_ID_AMBIENT_LIGHT。 | - | callback | AsyncCallback<[LightResponse](#lightresponse)> | 是 | 注册环境光传感器的回调函数,上报的数据类型为LightResponse。 | - | options | [Options](#options) | 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 | - -- 示例: - ``` - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info(' Illumination: ' + data.intensity); - }, - {interval: 10000000} - ); - ``` - - -## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION) - -on(type: sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback: AsyncCallback<OrientationResponse>, options?: Options): void - -监听方向传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 要订阅的方向传感器类型为SENSOR_TYPE_ID_ORIENTATION | - | callback | AsyncCallback<[OrientationResponse](#orientationresponse)> | 是 | 注册方向传感器的回调函数,上报的数据类型为OrientationResponse。 | - | options | [Options](#options) | 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 | - -- 示例: - ``` - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - }, - {interval: 10000000} - ); - ``` - - -## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR) - -on(type:sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR,callback:AsyncCallback<RotationVectorResponse>,options?: Options): void - -监听旋转矢量传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 要订阅的旋转矢量传感器类型为SENSOR_TYPE_ID_ROTATION_VECTOR。 | - | callback | AsyncCallback<[RotationVectorResponse](#rotationvectorresponse)> | 是 | 注册旋转矢量传感器的回调函数,上报的数据类型为RotationVectorResponse。 | - | options | [Options](#options) | 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 | - -- 示例: - ``` - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - }, - {interval: 10000000} - ); - ``` - - -## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION) - -on(type: sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback: AsyncCallback<WearDetectionResponse>,options?: Options): void - -监听佩戴检测传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 要订阅的佩戴检测传感器类型为SENSOR_TYPE_ID_WEAR_DETECTION。 | - | callback | AsyncCallback<[WearDetectionResponse](#weardetectionresponse)> | 是 | 注册佩戴检测传感器的回调函数,上报的数据类型为WearDetectionResponse。 | - | options | [Options](#options) | 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 | - -- 示例: - ``` - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('Wear status: ' + data.value); - }, - {interval: 10000000} - ); - ``` - - -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER) - -once(type: sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: AsyncCallback<AccelerometerResponse>): void - -监听加速度传感器的数据变化一次。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 加速度传感器类型为SENSOR_TYPE_ID_ACCELEROMETER。 | - | callback | AsyncCallback<[AccelerometerResponse](#accelerometerresponse)> | 是 | 注册一次加速度传感器的回调函数,上报的数据类型为AccelerometerResponse。 | - -- 示例: - ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - } - ); - ``` - - -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION) - -once(type:sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,callback:AsyncCallback<LinearAccelerometerResponse>): void - -监听线性加速度传感器数据变化一次。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 线性加速度传感器类型为SENSOR_TYPE_ID_LINEAR_ACCELERATION。 | - | callback | AsyncCallback<[LinearAccelerometerResponse](#linearaccelerometerresponse)> | 是 | 注册一次线性加速度传感器的回调函数,上报的数据类型为LinearAccelerometerResponse。 | - -- 示例: - ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - } - ); - ``` - - -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED) - -once(type:sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,callback:AsyncCallback<AccelerometerUncalibratedResponse>): void - -监听未校准加速度传感器的数据变化一次。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 未校准加速度传感器类型为SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED。 | - | callback | AsyncCallback<[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)> | 是 | 注册一次未校准加速度传感器的回调函数,上报的数据类型为AccelerometerUncalibratedResponse。 | - -- 示例: - ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - console.info('X-coordinate bias: ' + data.biasX); - console.info('Y-coordinate bias: ' + data.biasY); - console.info('Z-coordinate bias: ' + data.biasZ); - } - ); - ``` - - -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY) - -once(type:sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback: AsyncCallback<GravityResponse>): void - -监听重力传感器的数据变化一次。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 重力传感器类型为SENSOR_TYPE_ID_GRAVITY。 | - | callback | AsyncCallback<[GravityResponse](#gravityresponse)> | 是 | 注册一次重力传感器的回调函数,上报的数据类型为GravityResponse。 | - -- 示例: - ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - } - ); - ``` - - -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE) - -once(type: sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback: AsyncCallback<GyroscopeResponse>): void - -监听陀螺仪传感器的数据变化一次。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 陀螺仪传感器类型为SENSOR_TYPE_ID_GYROSCOPE。 | - | callback | AsyncCallback<[GyroscopeResponse](#gyroscoperesponse)> | 是 | 注册一次陀螺仪传感器的回调函数,上报的数据类型为GyroscopeResponse。 | - -- 示例: - ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - } - ); - ``` - - -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED) - -once(type:sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback:AsyncCallback<GyroscopeUncalibratedResponse>): void - -监听未校准陀螺仪传感器的数据变化一次。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 未校准陀螺仪传感器类型为SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED。 | - | callback | AsyncCallback<[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)> | 是 | 注册一次未校准陀螺仪传感器的回调函数,上报的数据类型为GyroscopeUncalibratedResponse。 | - -- 示例: - ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - console.info('X-coordinate bias: ' + data.biasX); - console.info('Y-coordinate bias: ' + data.biasY); - console.info('Z-coordinate bias: ' + data.biasZ); - } - ); - ``` - - -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION) - -once(type: sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION,callback:AsyncCallback<SignificantMotionResponse>): void - -监听有效运动传感器的数据变化一次。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 有效运动传感器类型为SENSOR_TYPE_ID_SIGNIFICANT_MOTION。 | - | callback | AsyncCallback<[SignificantMotionResponse](#significantmotionresponse)> | 是 | 注册一次有效运动传感器的回调函数,上报的数据类型为SignificantMotionResponse。 | - -- 示例: - ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('Scalar data: ' + data.scalar); - } - ); - ``` - - -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION) - -once(type:sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION,callback:AsyncCallback<PedometerDetectResponse>): void - -监听计步检测传感器数据变化一次。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 计步检测传感器类型为SENSOR_TYPE_ID_PEDOMETER_DETECTION。 | - | callback | AsyncCallback<[PedometerDetectResponse](#pedometerdetectresponse)> | 是 | 注册一次计步检测传感器的回调函数,上报的数据类型为PedometerDetectResponse。 | - -- 示例: - ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('Scalar data: ' + data.scalar); - } - ); - ``` - - -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER) - -once(type: sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, callback: AsyncCallback<PedometerResponse>): void - -监听计步器传感器数据变化一次。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 计步传感器类型为SENSOR_TYPE_ID_PEDOMETER。 | - | callback | AsyncCallback<[PedometerResponse](#pedometerresponse)> | 是 | 注册一次计步传感器的回调函数,上报的数据类型为PedometerResponse。 | - -- 示例: - ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('Steps: ' + data.steps); - } - ); - ``` - - -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE) - -once(type:sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback:AsyncCallback<AmbientTemperatureResponse>): void - -监听环境温度传感器数据变化一次。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 环境温度传感器类型为SENSOR_TYPE_ID_AMBIENT_TEMPERATURE。 | - | callback | AsyncCallback<[AmbientTemperatureResponse](#ambienttemperatureresponse)> | 是 | 注册一次环境温度传感器的回调函数,上报的数据类型为AmbientTemperatureResponse。 | - -- 示例: - ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('Temperature: ' + data.temperature); - } - ); - ``` - - -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD) - -once(type: sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback: AsyncCallback<MagneticFieldResponse>): void - -监听磁场传感器数据变化一次。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 磁场传感器类型为SENSOR_TYPE_ID_MAGNETIC_FIELD。 | - | callback | AsyncCallback<[MagneticFieldResponse](#magneticfieldresponse)> | 是 | 注册一次磁场传感器的回调函数,上报的数据类型为MagneticFieldResponse。 | - -- 示例: - ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - } - ); - ``` - - -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED) - -once(type:sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback:AsyncCallback<MagneticFieldUncalibratedResponse>): void - -监听未校准磁场传感器数据变化一次。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 未校准磁场传感器类型为SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED。 | - | callback | AsyncCallback<[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)> | 是 | 注册一次未校准磁场传感器的回调函数,上报的数据类型为MagneticFieldUncalibratedResponse。 | - -- 示例: - ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - console.info('X-coordinate bias: ' + data.biasX); - console.info('Y-coordinate bias: ' + data.biasY); - console.info('Z-coordinate bias: ' + data.biasZ); - } - ); - ``` - - -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY) - -once(type: sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: AsyncCallback<ProximityResponse>): void - -监听接近光传感器数据变化一次。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 接近光传感器类型为SENSOR_TYPE_ID_PROXIMITY。 | - | callback | AsyncCallback<[ProximityResponse](#proximityresponse)> | 是 | 注册一次接近光传感器的回调函数,上报的数据类型为ProximityResponse。 | - -- 示例: - ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('Distance: ' + data.distance); - } - ); - ``` - - -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY) - -once(type: sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, callback: AsyncCallback<HumidityResponse>): void - -监听湿度传感器数据变化一次。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 湿度传感器类型为SENSOR_TYPE_ID_HUMIDITY。 | - | callback | AsyncCallback<[HumidityResponse](#humidityresponse)> | 是 | 注册一次湿度传感器的回调函数,上报的数据类型为HumidityResponse。 | - -- 示例: - ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('Humidity: ' + data.humidity); - } - ); - ``` - - -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER) - -once(type: sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, callback: AsyncCallback<BarometerResponse>): void - -监听气压计传感器数据变化一次。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 气压计传感器类型为SENSOR_TYPE_ID_BAROMETER。 | - | callback | AsyncCallback<[BarometerResponse](#barometerresponse)> | 是 | 注册一次气压计传感器的回调函数,上报的数据类型为BarometerResponse。 | - -- 示例: - ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('Atmospheric pressure: ' + data.pressure); - } - ); - ``` - - -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HALL) - -once(type: sensor.SensorType.SENSOR_TYPE_ID_HALL, callback: AsyncCallback<HallResponse>): void - -监听霍尔传感器数据变化一次。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 霍尔传感器类型为SENSOR_TYPE_ID_HALL。 | - | callback | AsyncCallback<[HallResponse](#hallresponse)> | 是 | 注册一次霍尔传感器的回调函数,上报的数据类型为HallResponse。 | - -- 示例: - ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HALL, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('Status: ' + data.status); - } - ); - ``` - - -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT) - -once(type: sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback: AsyncCallback<LightResponse>): void - -监听环境光传感器数据变化一次。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 环境光传感器类型为SENSOR_TYPE_ID_AMBIENT_LIGHT。 | - | callback | AsyncCallback<[LightResponse](#lightresponse)> | 是 | 注册一次环境光传感器的回调函数,上报的数据类型为LightResponse。 | - -- 示例: - ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info(' Illumination: ' + data.intensity); - } - ); - ``` - - -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION) - -once(type: sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback: AsyncCallback<OrientationResponse>): void - -监听方向传感器数据变化一次。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 方向传感器类型为SENSOR_TYPE_ID_ORIENTATION。 | - | callback | AsyncCallback<[OrientationResponse](#orientationresponse)> | 是 | 注册一次方向传感器的回调函数,上报的数据类型为OrientationResponse。 | - -- 示例: - ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - } - ); - ``` - - -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR) - -once(type: sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback: AsyncCallback<RotationVectorResponse>): void - -监听旋转矢量传感器数据变化一次。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 旋转矢量传感器类型为SENSOR_TYPE_ID_ROTATION_VECTOR。 | - | callback | AsyncCallback<[RotationVectorResponse](#rotationvectorresponse)> | 是 | 注册一次旋转矢量传感器的回调函数,上报的数据类型为RotationVectorResponse。 | - -- 示例: - ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - } - ); - ``` - - -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE) - -once(type: sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE, callback: AsyncCallback<HeartRateResponse>): void - -监听心率传感器数据变化一次。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 心率传感器类型为SENSOR_TYPE_ID_HEART_RATE。 | - | callback | AsyncCallback<[HeartRateResponse](#heartrateresponse)> | 是 | 注册一次心率传感器的回调函数,上报的数据类型为HeartRateResponse。 | - -- 示例: - ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info("Heart rate: " + data.heartRate); - } - ); - ``` - - -## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION) - -once(type: sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback: AsyncCallback<WearDetectionResponse>): void - -监听佩戴检测传感器数据变化一次。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 佩戴检测传感器类型为SENSOR_TYPE_ID_WEAR_DETECTION。 | - | callback | AsyncCallback<[WearDetectionResponse](#weardetectionresponse)> | 是 | 注册一次穿戴检测传感器的回调函数,上报的数据类型为WearDetectionResponse。 | - -- 示例: - ``` - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, function(error, data) { - if (error) { - console.error("Failed to register data, error code is" + error.code + ", message: " + error.message); - return; - } - console.info("Wear status: "+ data.value); - } - ); - ``` - - -## sensor.off - -off(type: SensorType, callback?: AsyncCallback<void>): void - -取消订阅传感器数据。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [SensorType](#sensortype) | 是 | 要取消订阅的传感器类型。 | - | callback | AsyncCallback<void> | 是 | 取消订阅的传感器的回调函数,表示接口调用是否成功。 | - -- 示例: - ``` - sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, function(error) { - if (error) { - console.error("Failed to unsubscribe from acceleration sensor data. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info("Succeeded in unsubscribing from acceleration sensor data."); - } - ); - - ``` - - -## sensor.getGeomagneticField - -getGeomagneticField(locationOptions: LocationOptions, timeMillis: number, callback: AsyncCallback<GeomagneticResponse>): void - -获取地球上特定位置的地磁场。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | locationOptions | [LocationOptions](#locationoptions) | 是 | 地理位置。 | - | timeMillis | number | 是 | 表示获取磁偏角的时间,单位为毫秒。 | - | callback | AsyncCallback<[GeomagneticResponse](#geomagneticresponse)> | 是 | 返回磁场信息。 | - -- 示例 - ``` - sensor.getGeomagneticField([80, 0, 0], {'timeMillis':1580486400000}, function(err, data) { - if (err) { - console.error('Operation failed. Error code: ' + err.code + '; message: ' + err.message); - return; - } - console.info('sensor_getGeomagneticField_promise x: ' + data.x + ',y: ' + data.y + ',z: ' + - data.z + ',geomagneticDip: ' + data.geomagneticDip + ',deflectionAngle: ' + data.deflectionAngle + - ',levelIntensity: ' + data.levelIntensity + ',totalIntensity: ' + data.totalIntensity); - }); - ``` - - -## sensor.getGeomagneticField - -getGeomagneticField(locationOptions: LocationOptions, timeMillis: number): Promise<GeomagneticResponse> - -获取地球上特定位置的地磁场。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | locationOptions | [LocationOptions](#locationoptions) | 是 | 地理位置。 | - | timeMillis | number | 是 | 表示获取磁偏角的时间,单位为毫秒。 | - -- 返回值 - | 类型 | 说明 | - | -------- | -------- | - | Promise<[GeomagneticResponse](#geomagneticresponse)> | 返回磁场信息。 | - -- 示例 - ``` - const promise = sensor.getGeomagneticField([80, 0, 0], {'timeMillis':1580486400000}); - promise.then((data) => { - console.info('sensor_getGeomagneticField_promise x: ' + data.x + ',y: ' + data.y + ',z: ' + - data.z + ',geomagneticDip: ' + data.geomagneticDip + ',deflectionAngle: ' + data.deflectionAngle + - ',levelIntensity: ' + data.levelIntensity + ',totalIntensity: ' + data.totalIntensity); - }).catch((reason) => { - console.info('Operation failed.'); - }) - ``` - - -## SensorType - -表示要订阅或取消订阅的传感器类型。 - - -| 名称 | 默认值 | 说明 | -| -------- | -------- | -------- | -| SENSOR_TYPE_ID_ACCELEROMETER | 1 | 加速度传感器。 | -| SENSOR_TYPE_ID_GYROSCOPE | 2 | 陀螺仪传感器。 | -| SENSOR_TYPE_ID_AMBIENT_LIGHT | 5 | 环境光传感器。 | -| SENSOR_TYPE_ID_MAGNETIC_FIELD | 6 | 磁场传感器。 | -| SENSOR_TYPE_ID_BAROMETER | 8 | 气压计传感器。 | -| SENSOR_TYPE_ID_HALL | 10 | 霍尔传感器。 | -| SENSOR_TYPE_ID_PROXIMITY | 12 | 接近光传感器。 | -| SENSOR_TYPE_ID_HUMIDITY | 13 | 湿度传感器。 | -| SENSOR_TYPE_ID_ORIENTATION | 256 | 方向传感器。 | -| SENSOR_TYPE_ID_GRAVITY | 257 | 重力传感器。 | -| SENSOR_TYPE_ID_LINEAR_ACCELERATION | 258 | 线性加速度传感器。 | -| SENSOR_TYPE_ID_ROTATION_VECTOR | 259 | 旋转矢量传感器。 | -| SENSOR_TYPE_ID_AMBIENT_TEMPERATURE | 260 | 环境温度传感器。 | -| SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED | 261 | 未校准磁场传感器。 | -| SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED | 263 | 未校准陀螺仪传感器。 | -| SENSOR_TYPE_ID_SIGNIFICANT_MOTION | 264 | 有效运动传感器。 | -| SENSOR_TYPE_ID_PEDOMETER_DETECTION | 265 | 计步检测传感器。 | -| SENSOR_TYPE_ID_PEDOMETER | 266 | 计步传感器。 | -| SENSOR_TYPE_ID_HEART_RATE | 278 | 心率传感器。 | -| SENSOR_TYPE_ID_WEAR_DETECTION | 280 | 佩戴检测传感器。 | -| SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED | 281 | 未校准加速度计传感器。 | - - -## Response - -传感器数据的时间戳。 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| timestamp | number | 是 | 是 | 传感器数据上报的时间戳。 | - - -## AccelerometerResponse - -加速度传感器数据,继承于[Response](#response)。 - - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| x | number | 是 | 是 | 施加在设备x轴的加速度,单位 : m/s2。 | -| y | number | 是 | 是 | 施加在设备y轴的加速度,单位 : m/s2。 | -| z | number | 是 | 是 | 施加在设备z轴的加速度,单位 : m/s2。 | - - -## LinearAccelerometerResponse - -线性加速度传感器数据,继承于[Response](#response)。 - - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| x | number | 是 | 是 | 施加在设备x轴的线性加速度,单位 : m/s2。 | -| y | number | 是 | 是 | 施加在设备y轴的线性加速度,单位 : m/s2。 | -| z | number | 是 | 是 | 施加在设备z轴的线性加速度,单位 : m/s2。 | - - -## AccelerometerUncalibratedResponse - -未校准加速度计传感器数据,继承于[Response](#response)。 - - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| x | number | 是 | 是 | 施加在设备x轴未校准的加速度,单位 : m/s2。 | -| y | number | 是 | 是 | 施加在设备y轴未校准的加速度,单位 : m/s2。 | -| z | number | 是 | 是 | 施加在设备z轴未校准的加速度,单位 : m/s2。 | -| biasX | number | 是 | 是 | 施加在设备x轴未校准的加速度偏量,单位 : m/s2。 | -| biasY | number | 是 | 是 | 施加在设备上y轴未校准的加速度偏量,单位 : m/s2。 | -| biasZ | number | 是 | 是 | 施加在设备z轴未校准的加速度偏量,单位 : m/s2。 | - - -## GravityResponse - -重力传感器数据,继承于[Response](#response)。 - - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| x | number | 是 | 是 | 施加在设备x轴的重力加速度,单位 : m/s2。 | -| y | number | 是 | 是 | 施加在设备y轴的重力加速度,单位 : m/s2。 | -| z | number | 是 | 是 | 施加在设备z轴的重力加速度,单位 : m/s2。 | - - -## OrientationResponse - -方向传感器数据,继承于[Response](#response)。 - - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| x | number | 是 | 是 | 设备围绕x轴的旋转角度,单位 : rad。 | -| y | number | 是 | 是 | 设备围绕y轴的旋转角度,单位 : rad。 | -| z | number | 是 | 是 | 设备围绕z轴的旋转角度,单位 : rad。 | - - -## RotationVectorResponse - -旋转矢量传感器数据,继承于[Response](#response)。 - - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| x | number | 是 | 是 | 旋转矢量x轴分量。 | -| y | number | 是 | 是 | 旋转矢量y轴分量。 | -| z | number | 是 | 是 | 旋转矢量z轴分量。 | - - -## GyroscopeResponse - -陀螺仪传感器数据,继承于[Response](#response)。 - - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| x | number | 是 | 是 | 设备x轴的旋转角速度,单位rad/s。 | -| y | number | 是 | 是 | 设备y轴的旋转角速度,单位rad/s。 | -| z | number | 是 | 是 | 设备z轴的旋转角速度,单位rad/s。 | - - -## GyroscopeUncalibratedResponse - -未校准陀螺仪传感器数据,继承于[Response](#response)。 - - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| x | number | 是 | 是 | 设备x轴未校准的旋转角速度,单位rad/s。 | -| y | number | 是 | 是 | 设备y轴未校准的旋转角速度,单位rad/s。 | -| z | number | 是 | 是 | 设备z轴未校准的旋转角速度,单位rad/s。 | -| biasX | number | 是 | 是 | 设备x轴未校准的旋转角速度偏量,单位rad/s。 | -| biasY | number | 是 | 是 | 设备y轴未校准的旋转角速度偏量,单位rad/s。 | -| biasZ | number | 是 | 是 | 设备z轴未校准的旋转角速度偏量,单位rad/s。 | - - -## SignificantMotionResponse - -有效运动传感器数据,继承于[Response](#response)。 - - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| scalar | number | 是 | 是 | 表示剧烈运动程度。测量三个物理轴(x、y 和 z)上,设备是否存在大幅度运动;如果取值为1则代表存在大幅度运动,取值为0则代表没有大幅度运动。 | - - -## ProximityResponse - -接近光传感器数据,继承于[Response](#response)。 - - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| distance | number | 是 | 是 | 可见物体与设备显示器的接近程度。0表示接近,1表示远离。 | - - -## LightResponse - -环境光传感器数据,继承于[Response](#response)。 - - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| intensity | number | 是 | 是 | 光强(单位:勒克斯)。 | - - -## HallResponse - -霍尔传感器数据,继承于[Response](#response)。 - - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| status | number | 是 | 是 | 显示霍尔状态。测量设备周围是否存在磁力吸引,0表示有,1表示没有。 | - - -## MagneticFieldResponse - -磁场传感器数据,继承于[Response](#response)。 - - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| x | number | 是 | 是 | x轴环境磁场强度,单位 : μT。 | -| y | number | 是 | 是 | y轴环境磁场强度,单位 : μT。 | -| z | number | 是 | 是 | z轴环境磁场强度,单位 : μT。。 | - - -## MagneticFieldUncalibratedResponse - -未校准磁场传感器数据,继承于[Response](#response)。 - - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| x | number | 是 | 是 | x轴未校准环境磁场强度,单位 : μT。 | -| y | number | 是 | 是 | y轴未校准环境磁场强度,单位 : μT。 | -| z | number | 是 | 是 | z轴未校准环境磁场强度,单位 : μT。 | -| biasX | number | 是 | 是 | x轴未校准环境磁场强度偏量,单位 : μT。 | -| biasY | number | 是 | 是 | y轴未校准环境磁场强度偏量,单位 : μT。 | -| biasZ | number | 是 | 是 | z轴未校准环境磁场强度偏量,单位 : μT。 | - - -## PedometerResponse - -计步传感器数据,继承于[Response](#response)。 - - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| steps | number | 是 | 是 | 用户的行走步数。 | - - -## HumidityResponse - -湿度传感器数据,继承于[Response](#response)。 - - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| humidity | number | 是 | 是 | 湿度值。测量环境的相对湿度,以百分比 (%) 表示。 | - - -## PedometerDetectResponse - -计步检测传感器数据,继承于[Response](#response)。 - - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| scalar | number | 是 | 是 | 计步器检测。检测用户的计步动作,如果取值为1则代表用户产生了计步行走的动作,取值为0则代表用户没有发生运动。 | - - -## AmbientTemperatureResponse - -温度传感器数据,继承于[Response](#response)。 - - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| temperature | number | 是 | 是 | 环境温度(单位:摄氏度)。 | - - -## BarometerResponse - -气压计传感器数据,继承于[Response](#response)。 - - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| pressure | number | 是 | 是 | 压力值(单位:帕斯卡)。 | - - -## HeartRateResponse - -心率传感器数据,继承于[Response](#response)。 - - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| heartRate | number | 是 | 是 | 心率值。测量用户的心率数值,单位:bpm。 | - - -## WearDetectionResponse - -佩戴检测传感器数据,继承于[Response](#response)。 - - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| value | number | 是 | 是 | 表示设备是否被穿戴(1表示已穿戴,0表示未穿戴)。 | - - -## Options - -设置传感器上报频率。 - -| 名称 | 参数类型 | 说明 | -| -------- | -------- | -------- | -| interval | number | 表示传感器的上报频率,默认值为200000000ns。 | - - -## GeomagneticResponse - -设置地磁响应对象,继承于[Response](#response)。 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| x | number | 是 | 是 | 地磁场的北分量。 | -| y | number | 是 | 是 | 地磁场的东分量。 | -| z | number | 是 | 是 | 地磁场的垂直分量。 | -| geomagneticDip | number | 是 | 是 | 地磁倾角,即地球磁场线与水平面的夹角。 | -| deflectionAngle | number | 是 | 是 | 地磁偏角,即地磁北方向与正北方向在水平面上的角度。 | -| levelIntensity | number | 是 | 是 | 地磁场的水平强度。 | -| totalIntensity | number | 是 | 是 | 地磁场的总强度。 | - - -## LocationOptions - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| latitude | number | 是 | 是 | 纬度。 | -| longitude | number | 是 | 是 | 经度。 | -| altitude | number | 是 | 是 | 海拔高度。 | diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/10.\350\256\276\345\244\207\347\256\241\347\220\206/02.\346\214\257\345\212\250.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/10.\350\256\276\345\244\207\347\256\241\347\220\206/02.\346\214\257\345\212\250.md" deleted file mode 100644 index 1e3922d5f57035f30d208cadd428b396999bb165..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/10.\350\256\276\345\244\207\347\256\241\347\220\206/02.\346\214\257\345\212\250.md" +++ /dev/null @@ -1,204 +0,0 @@ ---- -title: 振动 -permalink: /pages/010c010a02 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 振动 - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import vibrator from '@ohos.vibrator'; -``` - -## 系统能力 - -SystemCapability.Sensors.MiscDevice - -## 权限列表 - -ohos.permission.VIBRATE - - -## vibrator.vibrate - -vibrate(duration: number): Promise<void> - - -按照指定持续时间触发马达振动。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | duration | number | 是 | 指示马达振动的持续时间。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | 指示触发振动是否成功。 | - - -- 示例: - ``` - vibrator.vibrate(1000).then(()=>{ - console.log("Promise returned to indicate a successful vibration."); - }, (error)=>{ - console.log("error.code"+error.code+"error.message"+error.message); - }); - ``` - - -## vibrator.vibrate - -vibrate(duration: number, callback?: AsyncCallback<void>): void - -按照指定持续时间触发马达振动。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | duration | number | 是 | 指示马达振动的持续时间。 | - | callback | AsyncCallback<void> | 否 | 马达执行振动的回调函数,指示触发振动是否成功。 | - -- 示例**:** - ``` - vibrator.vibrate(1000,function(error){ - if(error){ - console.log("error.code"+error.code+"error.message"+error.message); - }else{ - console.log("Callback returned to indicate a successful vibration."); - } - }) - ``` - - -## vibrator.vibrate - -vibrate(effectId: EffectId): Promise<void> - -按照指定振动效果触发马达振动。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | effectId | [EffectId](#effectid) | 是 | 指示马达振动效果的字符串。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | 指示触发振动是否成功。 | - -- 示例: - ``` - vibrator.vibrate(vibrator.EffectId.EFFECT_CLOCK_TIMER).then(()=>{ - console.log("Promise returned to indicate a successful vibration."); - }, (error)=>{ - console.log("error.code"+error.code+"error.message"+error.message); - }); - ``` - - -## vibrator.vibrate - -vibrate(effectId: EffectId, callback?: AsyncCallback<void>): void - -按照指定振动效果触发马达振动。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | effectId | [EffectId](#effectid) | 是 | 指示马达振动效果的字符串。 | - | callback | AsyncCallback<void> | 否 | 马达执行振动的回调函数,指示触发振动是否成功。 | - -- 示例: - ``` - vibrator.vibrate(vibrator.EffectId.EFFECT_CLOCK_TIMER, function(error){ - if(error){ - console.log("error.code"+error.code+"error.message"+error.message); - }else{ - console.log("Callback returned to indicate a successful vibration."); - } - }) - ``` - - -## vibrator.stop - -stop(stopMode: VibratorStopMode): Promise<void> - -按照要停止指定的振动模式来停止马达的振动。如果要停止的振动模式与触发马达振动时的模式不相同,则调用本接口会失败。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | stopMode | [VibratorStopMode](#vibratorstopmode) | 是 | 指示马达要停止指定的振动模式。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | 指示停止振动是否成功。 | - -- 示例: - ``` - vibrator.stop(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_PRESET).then(()=>{ - console.log("Promise returned to indicate a successful vibration."); - }, (error)=>{ - console.log("error.code"+error.code+"error.message"+error.message); - }); - ``` - - -## vibrator.stop - -stop(stopMode: VibratorStopMode, callback?: AsyncCallback<void>): void; - -按照要停止指定的振动模式来停止马达的振动。如果要停止的振动模式与触发马达振动时的模式不相同,则调用本接口会失败。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | stopMode | [VibratorStopMode](#vibratorstopmode) | 是 | 指示马达要停止指定的振动模式。 | - | callback | AsyncCallback<void> | 否 | 马达停止振动的回调函数,指示停止振动是否成功。 | - -- 示例: - ``` - vibrator.stop(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_PRESET, function(error){ - if(error){ - console.log("error.code"+error.code+"error.message"+error.message); - }else{ - console.log("Callback returned to indicate successful."); - } - }) - ``` - - -## EffectId - -表示马达振动效果的字符串。 - -| 名称 | 默认值 | 说明 | -| -------- | -------- | -------- | -| EFFECT_CLOCK_TIMER | "haptic.clock.timer" | 调整定时器时振动器的振动效果。 | - - -## VibratorStopMode - -表示马达要停止指定的振动模式。 - -| 名称 | 默认值 | 说明 | -| -------- | -------- | -------- | -| VIBRATOR_STOP_MODE_TIME | "time" | 停止模式为duration模式的振动。即触发振动时参数类型为number,参数本身为指示振动持续时间的触发方式。 | -| VIBRATOR_STOP_MODE_PRESET | "preset" | 停止模式为预置EffectId的振动。即触发振动时参数类型为EffectId,参数本身为指示马达振动效果的字符串的触发方式。 | diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/10.\350\256\276\345\244\207\347\256\241\347\220\206/03.\345\261\217\345\271\225\344\272\256\345\272\246.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/10.\350\256\276\345\244\207\347\256\241\347\220\206/03.\345\261\217\345\271\225\344\272\256\345\272\246.md" deleted file mode 100644 index 8f12a25152c36e2e3032138210853a1dd1401616..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/10.\350\256\276\345\244\207\347\256\241\347\220\206/03.\345\261\217\345\271\225\344\272\256\345\272\246.md" +++ /dev/null @@ -1,45 +0,0 @@ ---- -title: 屏幕亮度 -permalink: /pages/010c010a03 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 屏幕亮度 - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import brightness from '@ohos.brightness'; -``` - -## 系统能力 - -SystemCapability.PowerManager.DisplayPowerManager - -## brightness.setValue - -setValue(value: number) - -设置系统的屏幕亮度。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | number | 是 | 亮度的值(0~255) | - -- 示例: - ``` - import brightness from '@ohos.brightness.d.ts'; - brightness.setValue(128); - ``` diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/10.\350\256\276\345\244\207\347\256\241\347\220\206/04.\347\224\265\351\207\217\344\277\241\346\201\257.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/10.\350\256\276\345\244\207\347\256\241\347\220\206/04.\347\224\265\351\207\217\344\277\241\346\201\257.md" deleted file mode 100644 index 53e416799e38a620af2746ad4e7cf15bef87dd3a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/10.\350\256\276\345\244\207\347\256\241\347\220\206/04.\347\224\265\351\207\217\344\277\241\346\201\257.md" +++ /dev/null @@ -1,90 +0,0 @@ ---- -title: 电量信息 -permalink: /pages/010c010a04 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 电量信息 - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import batteryInfo from '@ohos.batteryInfo'; -``` - -## 系统能力 - -SystemCapability.PowerManager.BatteryManager - -## 属性 - -描述电池信息。 - -| 名称 | 类型 | 可读 | 可写 | 描述 | -| -------- | -------- | -------- | -------- | -------- | -| batterySOC | number | 是 | 否 | 表示当前设备剩余电池容量。 | -| chargingStatus | [BatteryChargeState](#batterychargestate) | 是 | 否 | 表示当前设备电池的充电状态。 | -| healthStatus | [BatteryHealthState](#batteryhealthstate) | 是 | 否 | 表示当前设备电池的健康状态。 | -| pluggedType | [BatteryPluggedType](#batterypluggedtype) | 是 | 否 | 表示当前设备连接的充电器类型。 | -| voltage | number | 是 | 否 | 表示当前设备电池的电压。 | -| technology | string | 是 | 否 | 表示当前设备电池的技术型号。 | -| batteryTemperature | number | 是 | 否 | 表示当前设备电池的温度。 | -| isBatteryPresent7+ | boolean | 是 | 否 | 表示当前设备是否支持电池或者电池是否在位。 | - -- 示例: - ``` - import batteryInfo from '@ohos.batteryInfo'; - var batterySoc = batteryInfo.batterySOC; - ``` - - -## BatteryPluggedType - -表示连接的充电器类型的枚举。 - - -| 名称 | 默认值 | 描述 | -| -------- | -------- | -------- | -| NONE | 0 | 表示连接充电器类型未知。 | -| AC | 1 | 表示连接的充电器类型为交流充电器。 | -| USB | 2 | 表示连接的充电器类型为USB。 | -| WIRELESS | 3 | 表示连接的充电器类型为无线充电器。 | - - -## BatteryChargeState - -表示电池充电状态的枚举。 - - -| 名称 | 默认值 | 描述 | -| -------- | -------- | -------- | -| NONE | 0 | 表示电池充电状态未知。 | -| ENABLE | 1 | 表示电池充电状态为使能状态。 | -| DISABLE | 2 | 表示电池充电状态为停止状态。 | -| FULL | 3 | 表示电池充电状态为已充满状态。 | - - -## BatteryHealthState - -表示电池的健康状态的枚举。 - - -| 名称 | 默认值 | 描述 | -| -------- | -------- | -------- | -| UNKNOWN | 0 | 表示电池健康状态未知。 | -| GOOD | 1 | 表示电池健康状态为正常。 | -| OVERHEAT | 2 | 表示电池健康状态为过热。 | -| OVERVOLTAGE | 3 | 表示电池健康状态为过压。 | -| COLD | 4 | 表示电池健康状态为低温。 | -| DEAD | 5 | 表示电池健康状态为僵死状态。 | diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/10.\350\256\276\345\244\207\347\256\241\347\220\206/05.\347\263\273\347\273\237\347\224\265\346\272\220\347\256\241\347\220\206.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/10.\350\256\276\345\244\207\347\256\241\347\220\206/05.\347\263\273\347\273\237\347\224\265\346\272\220\347\256\241\347\220\206.md" deleted file mode 100644 index aa1347bd98939bf980852cd21a9e0ee09a07fd23..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/10.\350\256\276\345\244\207\347\256\241\347\220\206/05.\347\263\273\347\273\237\347\224\265\346\272\220\347\256\241\347\220\206.md" +++ /dev/null @@ -1,114 +0,0 @@ ---- -title: 系统电源管理 -permalink: /pages/010c010a05 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 系统电源管理 - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import power from '@ohos.power'; -``` - -## 系统能力 - -SystemCapability.PowerManager.PowerManager - - -## power.shutdownDevice - -shutdownDevice(reason: string): void - -系统关机。 - -需要权限:ohos.permission.SHUTDOWN - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | reason | string | 是 | 关机原因。 | - -- 示例: - ``` - power.shutdownDevice("shutdown_test"); - console.info('power_shutdown_device_test success') - ``` - - -## power.rebootDevice - -rebootDevice(reason: string): void - -重启设备。 - -需要权限:ohos.permission.REBOOT(重启权限)、ohos.permission.REBOOT_RECOVERY(重启并进入recovery模式的权限) - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | reason | string | 是 | 重启原因。 | - -- 示例: - ``` - power.rebootDevice("reboot_test"); - console.info('power_reboot_device_test success') - ``` - - -## power.isScreenOn - -isScreenOn(callback: AsyncCallback<boolean>): void - -检测当前设备的亮灭屏状态。 - -- 参数: - | 类型 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<boolean> | 是 | 指定的callback回调方法,用于获取返回值。
callback返回值:亮屏返回true,灭屏返回false。 | - -- 示例: - ``` - power.isScreenOn((error, screenOn) => { - if (typeof error === "undefined") { - console.info('screenOn status is ' + screenOn); - } else { - console.log('error: ' + error); - } - }) - ``` - - -## power.isScreenOn - -isScreenOn(): Promise<boolean> - -检测当前设备的亮灭屏状态。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<boolean> | Promise实例,用于异步获取返回值,亮屏返回true,灭屏返回false。 | - -- 示例: - ``` - power.isScreenOn() - .then(screenOn => { - console.info('screenOn status is ' + screenOn); - }) - .catch(error => { - console.log('error: ' + error); - }) - ``` diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/10.\350\256\276\345\244\207\347\256\241\347\220\206/06.Runninglock\351\224\201.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/10.\350\256\276\345\244\207\347\256\241\347\220\206/06.Runninglock\351\224\201.md" deleted file mode 100644 index feef405863365658f21b81441f4059f1b0b9ab5b..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/10.\350\256\276\345\244\207\347\256\241\347\220\206/06.Runninglock\351\224\201.md" +++ /dev/null @@ -1,225 +0,0 @@ ---- -title: Runninglock锁 -permalink: /pages/010c010a06 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# Runninglock锁 - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import runninglock from '@ohos.runningLock'; -``` - - -## 系统能力 - -SystemCapability.PowerManager.PowerManager - - -## RunningLockType - -RunningLock锁的类型。 - -| 名称 | 默认值 | 描述 | -| -------- | -------- | -------- | -| BACKGROUND | 1 | 阻止系统休眠的锁。 | -| PROXIMITY_SCREEN_CONTROL | 2 | 通过接近或者远离状态来控制亮灭屏的锁。 | - - -## isRunningLockTypeSupported - -isRunningLockTypeSupported(type: RunningLockType, callback: AsyncCallback<boolean>): void - -查询系统是否支持该类型的锁。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | RunningLockType | 是 | 需要查询的锁的类型。 | - | callback | AsyncCallback<boolean> | 是 | 指定的callback回调方法,用于获取返回值。
callback返回值:支持返回true,不支持返回false。 | - -- 示例: - ``` - runningLock.isRunningLockTypeSupported(runningLock.RunningLockType.BACKGROUND, (error, supported) => { - if (typeof error === "undefined") { - console.info('BACKGROUND support status is ' + supported); - } else { - console.log('error: ' + error); - } - }) - ``` - - -## isRunningLockTypeSupported - -isRunningLockTypeSupported(type: RunningLockType): Promise<boolean> - -查询系统是否支持该类型的锁。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | RunningLockType | 是 | 需要查询的锁的类型。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<boolean> | Promise实例,用于异步获取返回值,支持返回true,不支持返回false。 | - -- 示例: - ``` - runningLock.isRunningLockTypeSupported(runningLock.RunningLockType.PROXIMITY_SCREEN_CONTROL) - .then(supported => { - console.info('PROXIMITY_SCREEN_CONTROL support status is ' + supported); - }) - .catch(error => { - console.log('error: ' + error); - }); - ``` - - -## createRunningLock - -createRunningLock(name: string, type: RunningLockType, callback: AsyncCallback<RunningLock>): void - -创建RunningLock锁。 - -需要权限:ohos.permission.RUNNING_LOCK - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | name | string | 是 | 锁的名字。 | - | type | RunningLockType | 是 | 要创建的锁的类型。 | - | callback | AsyncCallback<[RunningLock](#runninglock)> | 是 | 指定的callback回调方法,用于获取返回的RunningLock锁对象。 | - -- 示例: - ``` - runningLock.createRunningLock("running_lock_test", runningLock.RunningLockType.BACKGROUND) - .then(runninglock => { - var used = runninglock.isUsed(); - console.info('runninglock is used: ' + used); - runninglock.lock(500); - used = runninglock.isUsed(); - console.info('after lock runninglock is used ' + used); - }) - .catch(error => { - console.log('create runningLock test error: ' + error); - }) - ``` - - -## createRunningLock - -createRunningLock(name: string, type: RunningLockType): Promise<RunningLock> - -创建Runninglock锁。 - -需要权限:ohos.permission.RUNNING_LOCK - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | name | string | 是 | 锁的名字。 | - | type | RunningLockType | 是 | 要创建的锁的类型。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<[RunningLock](#runninglock)> | Promise实例,用于异步获取返回的RunningLock锁对象。 | - -- 示例: - ``` - runningLock.createRunningLock("running_lock_test", runningLock.RunningLockType.BACKGROUND) - .then(runninglock => { - console.info('create runningLock success'); - }) - .catch(error => { - console.log('create runningLock test error: ' + error); - }) - ``` - - -## RunningLock - -阻止系统休眠的锁。 - - -### lock - -lock(timeout: number): void - -锁定和持有RunningLock - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | timeout | number | 否 | 锁定和持有RunningLock的时长。 | - -- 示例: - ``` - runningLock.createRunningLock("running_lock_test", runningLock.RunningLockType.BACKGROUND) - .then(runningLock => { - runningLock.lock(100) - console.info('create runningLock success') - }) - .catch(error => { - console.log('Lock runningLock test error: ' + error) - }); - ``` - - -### unlock - -unlock(): void - -释放Runninglock锁。 - -- 示例: - ``` - runningLock.createRunningLock("running_lock_test", runningLock.RunningLockType.BACKGROUND) - .then(runningLock => { - runningLock.unlock() - console.info('unLock runningLock success') - }) - .catch(error => { - console.log('unLock runningLock test error: ' + error) - }); - ``` - - -### isUsed - -isUsed(): boolean - -查询当前Runninglock是持有状态,还是释放状态。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 当前RunningLock是持有状态返回true,释放状态返回false。 | - -- 示例: - ``` - runningLock.createRunningLock("running_lock_test", runningLock.RunningLockType.BACKGROUND) - .then(runningLock => { - var used = runningLock.isUsed() - console.info('runningLock used status: ' + used) - }) - .catch(error => { - console.log('runningLock isUsed test error: ' + error) - }); - ``` diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/10.\350\256\276\345\244\207\347\256\241\347\220\206/07.\350\256\276\345\244\207\344\277\241\346\201\257.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/10.\350\256\276\345\244\207\347\256\241\347\220\206/07.\350\256\276\345\244\207\344\277\241\346\201\257.md" deleted file mode 100644 index a8641508db862980a8161fbd8d28140530e84e80..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/10.\350\256\276\345\244\207\347\256\241\347\220\206/07.\350\256\276\345\244\207\344\277\241\346\201\257.md" +++ /dev/null @@ -1,60 +0,0 @@ ---- -title: 设备信息 -permalink: /pages/010c010a07 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 设备信息 - -## 导入模块 - -``` -import deviceInfo from '@ohos.deviceInfo' -``` - - -## 权限列表 - -无 - - -## 属性 - -| 名称 | 参数类型 | 可读 | 可写 | 描述 | -| -------- | -------- | -------- | -------- | -------- | -| deviceType | string | 是 | 否 | 设备类型。 | -| manufacture | string | 是 | 否 | 设备厂家名称。 | -| brand | string | 是 | 否 | 设备品牌名称。 | -| marketName | string | 是 | 否 | 外部产品系列。 | -| productSeries | string | 是 | 否 | 产品系列。 | -| productModel | string | 是 | 否 | 认证型号。 | -| softwareModel | string | 是 | 否 | 内部软件子型号。 | -| hardwareModel | string | 是 | 否 | 硬件版本号。 | -| hardwareProfile | string | 是 | 否 | 硬件Profile。 | -| serial | string | 是 | 否 | 设备序列号。 | -| bootloaderVersion | string | 是 | 否 | Bootloader版本号。 | -| abiList | string | 是 | 否 | 应用二进制接口(Abi)列表。 | -| securityPatchTag | string | 是 | 否 | 安全补丁级别。 | -| displayVersion | string | 是 | 否 | 产品版本。 | -| incrementalVersion | string | 是 | 否 | 差异版本号。 | -| osReleaseType | string | 是 | 否 | 系统的发布类型,取值为:
- Canary:面向特定开发者发布的早期预览版本,不承诺API稳定性。
- Beta:面向开发者公开发布的Beta版本,不承诺API稳定性。
- Release:面向开发者公开发布的正式版本,承诺API稳定性。 | -| osFullName | string | 是 | 否 | 系统版本。 | -| majorVersion | number | 是 | 否 | Major版本号,随主版本更新增加。 | -| seniorVersion | number | 是 | 否 | Senior版本号,随局部架构、重大特性增加。 | -| featureVersion | number | 是 | 否 | Feature版本号,标识规划的新特性版本。 | -| buildVersion | number | 是 | 否 | Build版本号,标识编译构建的版本号。 | -| sdkApiVersion | number | 是 | 否 | 系统软件API版本。 | -| firstApiVersion | number | 是 | 否 | 首个版本系统软件API版本。 | -| versionId | string | 是 | 否 | 版本ID。 | -| buildType | string | 是 | 否 | 构建类型。 | -| buildUser | string | 是 | 否 | 构建用户。 | -| buildHost | string | 是 | 否 | 构建主机。 | -| buildTime | string | 是 | 否 | 构建时间。 | -| buildRootHash | string | 是 | 否 | 构建版本Hash。 | diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/10.\350\256\276\345\244\207\347\256\241\347\220\206/08.\347\263\273\347\273\237\345\261\236\346\200\247.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/10.\350\256\276\345\244\207\347\256\241\347\220\206/08.\347\263\273\347\273\237\345\261\236\346\200\247.md" deleted file mode 100644 index 918ecd2446024f5456babc03dd773c8ee055811e..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/10.\350\256\276\345\244\207\347\256\241\347\220\206/08.\347\263\273\347\273\237\345\261\236\346\200\247.md" +++ /dev/null @@ -1,240 +0,0 @@ ---- -title: 系统属性 -permalink: /pages/010c010a08 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 系统属性 - -## 导入模块 - -``` -import parameter from '@ohos.systemParameter' -``` - - -## 权限列表 - -无 - - -## parameter.getSync - -getSync(key: string, def?: string) - -获取系统属性Key对应的值。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| key | string | 是 | 待查询的系统属性Key。 | -| def | string | 否 | 默认值。 | - -**返回值:** - -| 类型 | 说明 | -| -------- | -------- | -| string | 系统属性值,若key不存在,返回默认值。若未指定默认值,返回空字符串。 | - -**示例:** - -``` -try { - var info = parameter.getSync("test.parameter.key"); - console.log(JSON.stringify(info)); -}catch(e){ - console.log("getSync unexpected error: " + e); -} -``` - - -## parameter.get - -get(key: string, callback: AsyncCallback<string>) - -获取系统属性Key对应的值。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| key | string | 是 | 待查询的系统属性Key。 | -| callback | AsyncCallback<string> | 是 | 回调函数。 | - -**示例:** - -``` -try { - parameter.get("test.parameter.key", function (err, data) { - if (err == undefined) { - console.log("get test.parameter.key value success:" + data) - } else { - console.log(" get test.parameter.key value err:" + err.code) - }}); -}catch(e){ - console.log("get unexpected error: " + e); -} -``` - - -## parameter.get - -get(key: string, def: string, callback: AsyncCallback<string>) - -获取系统属性Key对应的值。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| key | string | 是 | 待查询的系统属性Key。 | -| def | string | 是 | 默认值。 | -| callback | AsyncCallback<string> | 是 | 回调函数。 | - -**示例:** - -``` -try { - parameter.get("test.parameter.key", "default", function (err, data) { - if (err == undefined) { - console.log("get test.parameter.key value success:" + data) - } else { - console.log(" get test.parameter.key value err:" + err.code) - } - }); -}catch(e){ - console.log("get unexpected error:" + e) -} -``` - - -## parameter.get - -get(key: string, def?: string) - -获取系统属性Key对应的值。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| key | string | 是 | 待查询的系统属性Key。 | -| def | string | 否 | 默认值。 | - -**返回值:** - -| 类型 | 说明 | -| -------- | -------- | -| Promise<string> | Promise示例,用于异步获取结果。 | - -**示例:** - -``` -try { - var p = parameter.get("test.parameter.key"); - p.then(function (value) { - console.log("get test.parameter.key success: " + value); - }).catch(function (err) { - console.log("get test.parameter.key error: " + err.code); - }); -}catch(e){ - console.log("get unexpected error: " + e); -} -``` - - -## parameter.setSync - -setSync(key: string, value: string) - -设置系统属性Key对应的值。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| key | string | 是 | 待设置的系统属性Key。 | -| value | string | 是 | 待设置的系统属性值。 | - -**示例:** - -``` -try { - parameter.setSync("test.parameter.key", "default"); -}catch(e){ - console.log("set unexpected error: " + e); -} -``` - - -## parameter.set(key: string, value: string, callback: AsyncCallback<void>) - -set(key: string, value: string, callback: AsyncCallback<void>) - -设置系统属性Key对应的值。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| key | string | 是 | 待查询的系统属性Key。 | -| def | string | 是 | 默认值。 | -| callback | AsyncCallback<void> | 是 | 回调函数。 | - -**示例:** - -``` -try { - parameter.set("test.parameter.key", "testValue", function (err, data) { - if (err == undefined) { - console.log("set test.parameter.key value success :" + data) - } else { - console.log("set test.parameter.key value err:" + err.code) - }}); -}catch(e){ - console.log("set unexpected error: " + e); -} -``` - - -## parameter.set(key: string, def?: string) - -set(key: string, def?: string) - -设置系统属性Key对应的值。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| key | string | 是 | 待查询的系统属性Key。 | -| def | string | 否 | 默认值。 | - -**返回值:** - -| 类型 | 说明 | -| -------- | -------- | -| Promise<string> | Promise示例,用于异步获取结果。 | - -**示例:** - -``` -try { - var p = para.set("test.parameter.key", "testValue"); - p.then(function (value) { - console.log("set test.parameter.key success: " + value); - }).catch(function (err) { - console.log(" set test.parameter.key error: " + err.code); - }); -}catch(e){ - console.log("set unexpected error: " + e); -} -``` diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/10.\350\256\276\345\244\207\347\256\241\347\220\206/09.\350\256\276\345\244\207\347\256\241\347\220\206.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/10.\350\256\276\345\244\207\347\256\241\347\220\206/09.\350\256\276\345\244\207\347\256\241\347\220\206.md" deleted file mode 100644 index 5cea08f37541c7dca34f7f4efe656b3f5da7ca0a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/10.\350\256\276\345\244\207\347\256\241\347\220\206/09.\350\256\276\345\244\207\347\256\241\347\220\206.md" +++ /dev/null @@ -1,202 +0,0 @@ ---- -title: 设备管理 -permalink: /pages/010c010a09 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 设备管理 - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import deviceManager from '@ohos.distributedHardware.deviceManager'; -``` - - -## deviceManager.createDeviceManager - -createDeviceManager(bundleName: string, callback: AsyncCallback<DeviceManager>): void - -创建一个设备管理器实例。 -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | bundleName | string | 是 | 指示应用程序的包名。 | - | callback | AsyncCallback<[DeviceManager](#devicemanager)> | 是 | DeviceManager实例创建时调用的回调,返回设备管理器对象实例。 | - -- 示例: - ``` - deviceManager.createDeviceManager("ohos.samples.jshelloworld", (err, data) => { - if (err) { - console.info("createDeviceManager err:" + JSON.stringify(err)); - return; - } - console.info("createDeviceManager success"); - this.dmInstance = data; - }); - ``` - - -## DeviceStateChangeAction - -表示设备状态变化的枚举。 - -| 名称 | 默认值 | 说明 | -| -------- | -------- | -------- | -| ONLINE | 0 | 设备上线。 | -| READY | 1 | 设备就绪,设备信息同步已完成。 | -| OFFLINE | 2 | 设备下线。 | -| CHANGE | 3 | 设备信息更改。 | - - -## DeviceType - -表示设备类型的枚举类。 - -| 名称 | 默认值 | 说明 | -| -------- | -------- | -------- | -| SPEAKER | 0x0A | 智能音箱 | -| PHONE | 0x0E | 手机 | -| TABLET | 0x11 | 平板 | -| WEARABLE | 0x6D | 智能穿戴 | -| TV | 0x9C | 智慧屏 | - - -## DeviceInfo - -设备信息。 - -| 名称 | 类型 | 必填 | 描述 | -| -------- | -------- | -------- | -------- | -| deviceId | number | 是 | 设备的唯一标识。 | -| deviceName | string | 是 | 设备名称。 | -| deviceType | number | 是 | 设备类型。 | - - -## DeviceManager - -设备管理实例,用于获取可信设备和本地设备的相关信息。在调用DeviceManager的方法前,需要先通过createDeviceManager构建一个DeviceManager实例dmInstance。 - - -### release - -release(): void - -设备管理实例不再使用后,通过该方法释放DeviceManager实例。 - -- 示例: - ``` - dmInstance.release(); - ``` - - -### getTrustedDeviceListSync - -getTrustedDeviceListSync(): Array<DeviceInfo> - -同步获取所有可信设备列表。 - -- 返回值: - | 名称 | 说明 | - | -------- | -------- | - | Array<[DeviceInfo](#deviceinfo)> | 返回可信设备列表。 | - -- 示例: - ``` - var deviceInfoList = dmInstance.getTrustedDeviceListSync(); - ``` - - -### on('deviceStateChange') - -on(type: 'deviceStateChange', callback: Callback<{ action: DeviceStateChangeAction, device: DeviceInfo }>): void - -注册设备状态回调。 - -- 参数: - | 名称 | 参数类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | string | 是 | 注册设备状态回调,固定为deviceStateChange。 | - | callback | Callback<{ action: [DeviceStateChangeAction](#devicestatechangeaction), device: [DeviceInfo](#deviceinfo) }> | 是 | 指示要注册的设备状态回调,返回设备状态和设备信息。 | - -- 示例: - ``` - dmInstance.on('deviceStateChange', (data) => { - console.info("deviceStateChange on:" + JSON.stringify(data)); - } - ); - ``` - - -### off('deviceStateChange') - -off(type: 'deviceStateChange', callback?: Call back<{ action: DeviceStateChangeAction, device: DeviceInfo }>): void - -取消注册设备状态回调。 - -- 参数: - | 名称 | 参数类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | string | 是 | 根据应用程序的包名取消注册设备状态回调。 | - | callback | Callback<{ action: [DeviceStateChangeAction](#devicestatechangeaction), device: [DeviceInfo](#deviceinfo)  }> | 是 | 指示要取消注册的设备状态回调,返回设备状态和设备信息。 | - -- 示例: - ``` - dmInstance.off('deviceStateChange', (data) => { - console.info('deviceStateChange' + JSON.stringify(data)); - } - ); - ``` - - -### on('serviceDie') - -on(type: 'serviceDie', callback: () => void): void - -注册设备管理服务死亡监听。 - -- 参数: - | 名称 | 参数类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | string | 是 | 注册serviceDie回调,以便在devicemanager服务异常终止时通知应用程序。 | - | callback | () => void | 是 | 注册serviceDie的回调方法。 | - -- 示例: - ``` - dmInstance.on("serviceDie", () => { - console.info("serviceDie on"); - } - ); - ``` - - -### off('serviceDie') - -off(type: 'serviceDie', callback?: () => void): void - -取消注册设备管理服务死亡监听。 - -- 参数: - | 名称 | 参数类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | string | 是 | 取消注册serviceDie回调,以便在devicemanager服务异常终止时通知应用程序。 | - | callback | () => void | 否 | 取消注册serviceDie的回调方法。 | - -- 示例: - ``` - dmInstance.off("serviceDie", () => { - console.info("serviceDie off"); - } - ); - ``` diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/10.\350\256\276\345\244\207\347\256\241\347\220\206/10.\347\252\227\345\217\243.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/10.\350\256\276\345\244\207\347\256\241\347\220\206/10.\347\252\227\345\217\243.md" deleted file mode 100644 index 13dfdf5a475545feafb36cdf09f12994647054a9..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/10.\350\256\276\345\244\207\347\256\241\347\220\206/10.\347\252\227\345\217\243.md" +++ /dev/null @@ -1,975 +0,0 @@ ---- -title: 窗口 -permalink: /pages/010c010a0a -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 窗口 - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import window from '@ohos.window'; -``` - - -## 系统能力 -SystemCapability.WindowManager.WindowManager.Core - - - -## 权限列表 - -ohos.permission.SYSTEM_FLOAT_WINDOW - - -## SystemBarProperties - -状态栏导航栏的属性。 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| statusBarColor | string | 是 | 是 | 状态栏颜色,为16进制颜色,例如"\#00FF00"或"\#FF00FF00"。 | -| isStatusBarLightIcon7+ | boolean | 是 | 是 | 状态栏图标是否为高亮状态。 | -| navigationBarColor | string | 是 | 是 | 导航栏颜色,为16进制颜色,例如"\#00FF00"或"\#FF00FF00"。 | -| isNavigationBarLightIcon7+ | boolean | 是 | 是 | 导航栏图标是否为高亮状态。 | - - -## Rect7+ - -矩形。 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| left | number | 是 | 是 | 矩形区域的左边界。 | -| top | number | 是 | 是 | 矩形区域的上边界。 | -| width | number | 是 | 是 | 矩形区域的宽度。 | -| height | number | 是 | 是 | 矩形区域的高度。 | - - -## AvoidArea7+ - -表示窗口内容规避区域。 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| leftRect | [Rect](#rect) | 是 | 是 | 屏幕左侧的矩形区。 | -| topRect | [Rect](#rect) | 是 | 是 | 屏幕顶部的矩形区。 | -| rightRect | [Rect](#rect) | 是 | 是 | 屏幕右侧的矩形区。 | -| bottomRect | [Rect](#rect) | 是 | 是 | 屏幕底部的矩形区。 | - - -## Size7+ - -窗口大小。 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| width | number | 是 | 是 | 窗口宽度。 | -| height | number | 是 | 是 | 窗口高度。 | - - -## WindowProperties - -窗口属性。 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| windowRect7+ | [Rect](#rect) | 是 | 否 | 窗口尺寸。 | -| type7+ | [WindowType](#windowtype) | 是 | 否 | 窗口类型。 | -| brightness | number | 是 | 是 | 屏幕亮度,取值范围为0~1,1表示最大亮度值。 | -| isTransparent7+ | boolean | 是 | 是 | 窗口是否透明,默认为false。 | -| isFullScreen | boolean | 是 | 是 | 是否全屏,默认为false。 | -| isKeepScreenOn | boolean | 是 | 是 | 屏幕是否常亮,默认为false。 | -| dimBehindValue7+ | number | 是 | 是 | 靠后的窗口的暗度值,取值范围为0~1,1表示最暗。 | -| isLayoutFullScreen7+ | boolean | 是 | 是 | 窗口是否为沉浸式,默认为false。 | -| focusable7+ | boolean | 是 | 是 | 窗口是否可聚焦,默认为true。 | -| touchable7+ | boolean | 是 | 是 | 窗口是否可触摸,默认为true。 | -| isPrivacyMode7+ | boolean | 是 | 是 | 隐私模式,默认为false。 | -| isRoundCorner7+ | boolean | 是 | 是 | 窗口是否为圆角。 | - - -## SplitScreenBoundsInfo7+ - -分屏边界相关信息。 - -| 名称 | 类型 | 说明 | -| -------- | -------- | -------- | -| [splitMode](#splitmode) | number | 表示分屏模式。 | -| primaryBounds | [Rect](#rect) | 表示主要边界信息,返回Rect类实例。 | -| secondaryBounds | [Rect](#rect) | 表示次要边界信息,返回Rect类实例。 | - - -## window.getTopWindow - -getTopWindow(callback: AsyncCallback<Window>): void - -获取当前窗口,用于获取到window实例。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<[Window](#window)> | 是 | 回调返回当前窗口对象。 | - -- 示例 - ``` - window.getTopWindow((err, data) => { - if (err) { - console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err)); - return; - } - console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); - windowClass = data; - }); - ``` - - -## window.create7+ - -create(id: string, type: WindowType, callback: AsyncCallback<Window>): void - -创建子窗口。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | id | string | 是 | 窗口id。 | - | type | [WindowType](#windowtype) | 是 | 窗口类型。 | - | callback | AsyncCallback<[Window](#window)> | 是 | 回调返回当前窗口对象。 | - -- 示例 - - -``` - window.create("first", 1, (err, data) => { - windowClass = data; - if (err) { - console.error('Failed to create the subWindow. Cause: ' + JSON.stringify(err)); - return; - } - console.info('SubWindow created. Data: ' + JSON.stringify(data)) - windowClass.resetSize(500, 1000); - windowClass.setOutsideTouchable(true); - windowClass.loadContent("pages/index/index", (err, data) => { - }); -}) -``` - - -## window.find7+ - -find(id: string, callback: AsyncCallback<Window>): void - -查找子窗口。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | id | string | 是 | 窗口id。 | - | callback | AsyncCallback<[Window](#window)> | 是 | 回调返回当前窗口对象。 | - -- 示例 - ``` - window.find("first", (err, data) => { - if (err) { - console.error('Failed to find the subWindow. Cause: ' + JSON.stringify(err)); - return; - } - console.info('SubWindow found. Data: ' + JSON.stringify(data)) - windowClass = data; - }) - ``` - - -## window.getAbilityWindowMode7+ - -getAbilityWindowMode(callback: AsyncCallback<WindowMode>): void - -获取当前窗口模式。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<[WindowMode](#windowmode)> | 是 | 回调返回当前窗口模式。 | - -- 示例 - ``` - window.getAbilityWindowMode((err, data) => { - if (err) { - console.error('Failed to obtain the window mode. Cause:' + JSON.stringify(err)); - return; - } - console.info('Window mode obtained. Data:' + JSON.stringify(data)) - - }); - ``` - - -## window.getSplitScreenBounds7+ - -getSplitScreenBounds(splitRatio: SplitRatio, callback: AsyncCallback<SplitScreenBoundsInfo>): void - -获取分屏多窗口的位置和区域.。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | splitRatio | SplitRatio | 是 | 表示分屏比例,默认值为1:1,传值1表示1:2,传值2为2:1。 | - | callback | AsyncCallback<[SplitScreenBoundsInfo](#splitscreenboundsinfo)> | 是 | 回调返回一个SplitScreenBoundsInfo对象,表示分屏边界相关信息。 | - -- 示例 - ``` - var splitRatio = '1:1'; - window.getSplitScreenBounds(splitRatio, (err, data) => { - if (err) { - console.error('Failed to obtain the split-screen boundary information. Cause: ' + JSON.stringify(err)); - return; - } - console.info('Split-screen boundary information obtained. Data: ' + JSON.stringify(data)) - - }); - ``` - - -## window.isFloatingAbilityWindowVisible7+ - -isFloatingAbilityWindowVisible(callback:AsyncCallback<boolean>): void - -悬浮窗是否显示可见。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<boolean> | 是 | 回调返回一个boolean对象,表示悬浮窗是否可见。 | - -- 示例 - ``` - window.isFloatingAbilityWindowVisible( (err, data) => { - if (err) { - console.error('Failed to check whether the floating window is visible. Cause:' + JSON.stringify(err)); - return; - } - console.info('Succeeded in checking whether the floating window is visible. Data:' + JSON.stringify(data)) - - }); - ``` - - -## window.setSplitBarVisibility7+ - -setSplitBarVisibility(isVisibility: boolean, callback: AsyncCallback<void>): void - -设置分屏线是否可见。 - -- 参数 - | 参数名 | 类型 | 说明 | - | -------- | -------- | -------- | - | isVisibility | boolean | 表示分屏线是否是否显示,true为显示,false为显示。 | - | callback | AsyncCallback<void> | callback形式返回结果。 | - -- 示例 - ``` - var isVisibility = false; - window.setSplitBarVisibility(isVisibility , (err, data) => { - if (err) { - console.error('Failed to set the divider to be invisible. Cause:' + JSON.stringify(err)); - return; - } - console.info('Succeeded in setting the divider to be invisible. Data:' + JSON.stringify(data)) - }); - ``` - - -## WindowType7+ - -窗口类型。 - -| 名称 | 默认值 | 说明 | -| -------- | -------- | -------- | -| TYPE_APP | 0 | 表示应用窗口。 | -| TYPE_SYSTEM_ALERT | 1 | 表示系统弹窗。 | - - -## AvoidAreaType7+ - -窗口内容需要规避区域的类型。 - -| 名称 | 默认值 | 说明 | -| -------- | -------- | -------- | -| TYPE_SYSTEM | 0 | 表示系统默认。 | -| TYPE_CUTOUT | 1 | 表示刘海屏区域。 | - - -## WindowMode7+ - -窗口模式。 - -| 名称 | 默认值 | 说明 | -| -------- | -------- | -------- | -| UNDEFINED | 1 | 表示APP未定义窗口模式。 | -| FULLSCREEN | 2 | 表示APP全屏模式。 | -| PRIMARY | 3 | 表示APP分屏多窗口主要模式。 | -| SECONDARY | 4 | 表示APP分屏多窗口次要模式。 | -| FLOATING | 5 | 表示APP自由悬浮形式窗口模式。 | - - -## splitMode7+ - -分屏模式。 - -| 名称 | 默认值 | 说明 | -| -------- | -------- | -------- | -| VERTICAL | 0 | 表示垂直上下分屏模式 | -| HORIZONTAL | 1 | 表示水平左右分屏模式 | - - -## Window - -下列API示例中都需使用[getTopWindow()](#window-gettopwindow)先获取到Window实例,再通过此实例调用对应方法。 - - -### setBrightness - -setBrightness(brightness:number, callback: AsyncCallback<void>): void - -设置屏幕亮度值。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | brightness | number | 是 | 屏幕亮度值,值为0-1之间。1表示最亮。 | - | callback | AsyncCallback<void> | 是 | 回调函数。 | - -- 示例 - ``` - var brightness = 10; - windowClass.setBrightness(brightness, (err, data) => { - if (err) { - console.error('Failed to set the brightness. Cause: ' + JSON.stringify(err)); - return; - } - console.info('Succeeded in setting the brightness. Data: ' + JSON.stringify(data)); - }); - ``` - - -### setBackgroundColor - -setBackgroundColor(color: string, callback: AsyncCallback<void>): void - -设置窗口的背景色。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | color | string | 是 | 需要设置的背景色,为16进制颜色,例如"\#00FF00"或"\#FF00FF00"。 | - | callback | AsyncCallback<void> | 是 | 回调函数。 | - -- 示例 - ``` - var color = '#00ff33'; - windowClass.setBackgroundColor(color, (err, data) => { - if (err) { - console.error('Failed to set the background color. Cause: ' + JSON.stringify(err)); - return; - } - console.info('Succeeded in setting the background color. Data: ' + JSON.stringify(data)); - }); - ``` - -### setTransparent7+ - -setTransparent(isTransparent: boolean, callback: AsyncCallback<void>): void - -设置窗口是否透明。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | isTransparent | boolean | 是 | 窗口是否透明。 | - | callback | AsyncCallback<void> | 是 | 回调函数。 | - -- 示例 - ``` - var isTransparent = true; - windowClass.setTransparent(isTransparent, (err, data) => { - if (err) { - console.error('Failed to set the window to be transparent. Cause: ' + JSON.stringify(err)); - return; - } - console.info('Succeeded in setting the window to be transparent. Data: ' + JSON.stringify(data)) - }); - ``` - -### setFullScreen - -setFullScreen(isFullScreen: boolean, callback: AsyncCallback<void>): void - -设置是否为全屏状态。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | isFullScreen | boolean | 是 | 是否设为全屏状态。 | - | callback | AsyncCallback<void> | 是 | 回调函数。 | - -- 示例 - ``` - var isFullScreen = true; - windowClass.setFullScreen(isFullScreen, (err, data) => { - if (err) { - console.error('Failed to enable the full-screen mode. Cause: ' + JSON.stringify(err)); - return; - } - console.info('Succeeded in enabling the full-screen mode. Data: ' + JSON.stringify(data)); - }); - ``` - -### setKeepScreenOn - -setKeepScreenOn(isKeepScreenOn: boolean, callback: AsyncCallback<void>): void - -设置屏幕是否为常亮状态。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | isKeepScreenOn | boolean | 是 | 是否设置为屏幕常亮状态。 | - | callback | AsyncCallback<void> | 是 | 回调函数。 | - -- 示例 - ``` - var isKeepScreenOn = true; - windowClass.setKeepScreenOn(isKeepScreenOn, (err, data) => { - if (err) { - console.error('Failed to set the screen to be always on. Cause: ' + JSON.stringify(err)); - return; - } - console.info('Succeeded in setting the screen to be always on. Data: ' + JSON.stringify(data)); - }); - ``` - -### setWindowType7+ - -setWindowType(type: WindowType, callback: AsyncCallback<void>): void - -设置窗口类型。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [WindowType](#windowtype7) | 是 |窗口类型。 | - | callback | AsyncCallback<void> | 是 | 回调函数。 | - -- 示例 - ``` - var type = window.TYPE_APP; - windowClass.setWindowType(type, (err, data) => { - if (err) { - console.error('Failed to set the window type. Cause: ' + JSON.stringify(err)); - return; - } - console.info('Succeeded in setting the window type. Data: ' + JSON.stringify(data)) - }); - ``` - -### setDimBehind7+ - -setDimBehind(dimBehindValue: number, callback: AsyncCallback<void>): void - -窗口叠加时,设备有子窗口的情况下设置靠后的窗口的暗度值。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | dimBehindValue | number | 是 | 表示靠后的窗口的暗度值,取值范围为0-1,1表示最暗。 | - | callback | AsyncCallback<void> | 是 | 回调函数。 | - -- 示例 - ``` - windowClass.setDimBehind(0.5, (err, data) => { - if (err) { - console.error('Failed to set the dimness. Cause: ' + JSON.stringify(err)); - return; - } - console.info('Succeeded in setting the dimness. Data:' + JSON.stringify(data)); - }); - ``` - -### setLayoutFullScreen7+ - -setLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback<void>): void - -设置窗口的布局是否为全屏显示状态。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | isLayoutFullScreen | boolean | 是 | 窗口的布局是否为全屏显示状态。 | - | callback | AsyncCallback<void> | 是 | 回调函数。 | - -- 示例 - ``` - var isLayoutFullScreen= true; - windowClass.setLayoutFullScreen(isLayoutFullScreen, (err, data) => { - if (err) { - console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err)); - return; - } - console.info('Succeeded in setting the window layout to full-screen mode. Data:' + JSON.stringify(data)); - }); - ``` - -### setFocusable7+ - -setFocusable(isFocusable: boolean, callback: AsyncCallback<void>): void - -设置点击时是否支持切换焦点窗口。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | isFocusable | boolean | 是 | 点击时是否支持切换焦点窗口。 | - | callback | AsyncCallback<void> | 是 | 回调函数。 | - -- 示例 - ``` - var isFocusable= true; - windowClass.setFocusable(isFocusable, (err, data) => { - if (err) { - console.error('Failed to set the window to be focusable. Cause:' + JSON.stringify(err)); - return; - } - console.info('Succeeded in setting the window to be focusable. Data: ' + JSON.stringify(data)); - }); - ``` - -### setTouchable7+ - -setTouchable(isTouchable: boolean, callback: AsyncCallback<void>): void - -设置窗口是否为可触状态。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | isTouchable | boolean | 是 | 窗口是否为可触状态。 | - | callback | AsyncCallback<void> | 是 | 回调函数。 | - -- 示例 - ``` - var isTouchable = true; - windowClass.setTouchable(isTouchable, (err, data) => { - if (err) { - console.error('Failed to set the window to be touchable. Cause:' + JSON.stringify(err)); - return; - } - console.info('Succeeded in setting the window to be touchable. Data:' + JSON.stringify(data)); - - }); - ``` - -### setPrivacyMode7+ - -setPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback<void>): void - -设置窗口是否为隐私模式。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | isPrivacyMode | boolean | 是 | 窗口是否为隐私模式。 | - | callback | AsyncCallback<void> | 是 | 回调函数。 | - -- 示例 - ``` - var isPrivacyMode = true; - windowClass.setPrivacyMode(isPrivacyMode, (err, data) => { - if (err) { - console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(err)); - return; - } - console.info('Succeeded in setting the window to privacy mode. Data:' + JSON.stringify(data)); - - }); - ``` - -### setSystemBarEnable7+ - -setSystemBarEnable(names: Array, callback: AsyncCallback<void>): void - -设置导航栏、状态栏的可见模式。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | names | Array | 是 | 设置状态栏和导航栏是否显示。例如,需全部显示,该参数设置为["status", "navigation"]。 | - | callback | AsyncCallback<void> | 是 | 回调函数。 | - -- 示例 - ``` - var names = ["status", "navigation"]; - windowClass.setSystemBarEnable(names, (err, data) => { - if (err) { - console.error('Failed to set the system bar to be visible. Cause:' + JSON.stringify(err)); - return; - } - console.info('Succeeded in setting the system bar to be visible. Data: ' + JSON.stringify(data)); - }); - ``` - -### setSystemBarProperties - -setSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback<void>): void - -设置窗口内导航条状态栏的属性。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | SystemBarProperties | [SystemBarProperties](#systembarproperties) | 是 | 导航条状态栏的属性。 | - | callback | AsyncCallback<void> | 是 | 回调函数。 | - -- 示例 - ``` - var SystemBarProperties={ - statusBarColor: '#ff00ff', - navigationBarColor: '#00ff00', - //以下两个属性从API Version7开始支持 - isStatusBarLightIcon: true, - isNavigationBarLightIcon:false - }; - windowClass.setSystemBarProperties(SystemBarProperties, (err, data) => { - if (err) { - console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err)); - return; - } - console.info('Succeeded in setting the system bar properties. Data: ' + JSON.stringify(data)); - }); - ``` - -### getProperties - -getProperties(callback: AsyncCallback<WindowProperties>): void - -获取当前窗口的属性,异步返回WindowProperties。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<[WindowProperties](#windowproperties)> | 是 | 回调返回窗口属性。 | - -- 示例 - ``` - windowClass.getProperties((err, data) => { - if (err) { - console.error('Failed to obtain the window properties. Cause: ' + JSON.stringify(err)); - return; - } - console.info('Succeeded in obtaining the window properties. Data: ' + JSON.stringify(data)); - }); - ``` - -### getAvoidArea7+ - -getAvoidArea(type: AvoidAreaType, callback: AsyncCallback<AvoidArea>): void - -获取窗口内容规避的区域。如系统的系统栏区域 、凹口区域。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | [AvoidAreaType](#avoidareatype) | 是 | 表示规避区类型。type为TYPE_SYSTEM,表示系统默认区域。type为TYPE_CUTOUT,表示刘海屏区域。 | - | callback | AsyncCallback<[AvoidArea](#avoidarea)> | 是 | 回调返回窗口内容规避区域。 | - -- 示例 - ``` - var type = window.AvoidAreaType.TYPE_SYSTEM; - windowClass.getAvoidArea(type, (err, data) => { - if (err) { - console.error('Failed to obtain the area. Cause:' + JSON.stringify(err)); - return; - } - console.info('Succeeded in obtaining the area. Data:' + JSON.stringify(data)); - }); - ``` - -### moveTo7+ - -moveTo(x: number, y: number, callback: AsyncCallback<void>): void - -窗口位置移动。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | x | number | 是 | 窗口在x轴方向移动的值,值为正表示右移。 | - | y | number | 是 | 窗口在y轴方向移动的值,值为正表示下移。 | - | callback | AsyncCallback<void> | 是 | 回调函数。 | - -- 示例 - ``` - windowClass.moveTo(300, 300, (err, data)=>{ - if (err) { - console.error('Failed to move the window. Cause:' + JSON.stringify(err)); - return; - } - console.info('Window moved. Data:' + JSON.stringify(data)); - - }); - ``` - -### resetSize7+ - -resetSize(width: number, height: number, callback: AsyncCallback<void>): void - -改变当前窗口大小。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | width | number | 是 | 目标窗口的宽度。 | - | height | number | 是 | 目标窗口的高度。 | - | callback | AsyncCallback<void> | 是 | 回调函数。 | - -- 示例 - ``` - windowClass.resetSize(500, 1000, (err, data) => { - if (err) { - console.error('Failed to change the window size. Cause:' + JSON.stringify(err)); - return; - } - console.info('Window size changed. Data:' + JSON.stringify(data)); - }); - ``` - -### loadContent7+ - -loadContent(path: string, callback: AsyncCallback<void>): void - -子窗口加载具体页面内容。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | path | string | 是 | 设置加载页面的代码路径。 | - | callback | AsyncCallback<void> | 是 | 回调函数。 | - -- 示例 - ``` - windowClass.loadContent("pages/page2/page2", (err, data) => { - if (err) { - console.error('Failed to load the content. Cause:' + JSON.stringify(err)); - return; - } - console.info('Succeeded in loading the content. Data:' + JSON.stringify(data)); - }); - ``` - -### hide7+ - -hide (callback: AsyncCallback<void>): void - -隐藏子窗口。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<void> | 是 | 回调函数。 | - -- 示例 - ``` - windowClass.hide((err, data) => { - if (err) { - console.error('Failed to hide the subwindow. Cause: ' + JSON.stringify(err)); - return; - } - console.info('Subwindow hidden. Data:' + JSON.stringify(data)) - }) - ``` - -### show7+ - -show(callback: AsyncCallback<void>): void - -显示子窗口。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<void> | 是 | 回调函数。 | - -- 示例 - ``` - windowClass.show((err, data) => { - if (err) { - console.error('Failed to show the subwindow. Cause: ' + JSON.stringify(err)); - return; - } - console.info('Succeeded in showing the subwindow. Data: ' + JSON.stringify(data)) - }) - ``` - -### isShowing7+ - -isShowing(callback: AsyncCallback<boolean>): void - -判断子窗口是否已显示。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<boolean> | 是 | 回调函数返回是否显示子窗口结果。 | - -- 示例 - ``` - windowClass.isShowing((err, data) => { - if (err) { - console.error('Failed to check whether the subwindow is showing. Cause:' + JSON.stringify(err)); - return; - } - console.info('Succeeded in checking whether the subwindow is showing. Cause:' + JSON.stringify(data)) - }) - ``` - -### destroy7+ - -destroy(callback: AsyncCallback<void>): void - -销毁子窗口。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<void> | 是 | 回调函数。 | - -- 示例 - ``` - windowClass.destroy((err, data) => { - if (err) { - console.error('Failed to destroy the subwindow. Cause:' + JSON.stringify(err)); - return; - } - console.info('Succeeded in destroying the subwindow. Data:' + JSON.stringify(data)) - }) - ``` - -### setOutsideTouchable7+ - -setOutsideTouchable(touchable: boolean, callback: AsyncCallback<void>): void; - -设置是否允许可点击子窗口以外的区域。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | touchable | boolean | 是 | 设置是否可点击。 | - | callback | AsyncCallback<void> | 是 | 回调函数。 | - -- 示例 - ``` - windowClass.setOutsideTouchable(true, (err, data) => { - if (err) { - console.error('Failed to set the area to be touchable. Cause: ' + JSON.stringify(err)); - return; - } - console.info('Succeeded in setting the area to be touchable. Data: ' + JSON.stringify(data)) - }) - ``` - -### on('keyboardHeightChange') - -on(type: string, callback: AsyncCallback<number>): void - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 从 API Version 7 开始废弃。 - -开启监听键盘高度变化。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | string | 是 | 设置监听类型为监听键盘高度变化,应设置type为'keyboardHeightChange'。 | - | callback | AsyncCallback<number> | 是 | 回调返回监听到的键盘高度。 | - -- 示例 - ``` - var type= 'keyboardHeightChange'; - windowClass.on(type, (err, data) => { - if (err) { - console.error('Failed to enable the listener for keyboard height changes. Cause: ' + JSON.stringify(err)); - return; - } - console.info('Succeeded in enabling the listener for keyboard height changes. Data: ' + JSON.stringify(data)); - }); - ``` - -### off('keyboardHeightChange') - -off(type: string, callback?: AsyncCallback<number>): void - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 从 API Version 7 开始废弃。 - -关闭监听键盘高度变化。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | string | 是 | 设置监听类型为监听键盘高度变化,应设置type为'keyboardHeightChange'。 | - | callback | AsyncCallback<number> | 否 | 回调返回监听到的键盘高度。 | - -- 示例 - ``` - var type= 'keyboardHeightChange'; - windowClass.off(type); - ``` - -### on('keyboardHeightChange'|'windowSizeChange'7+|'systemAvoidAreaChange'7+) - -on(type: string, callback: Callback<AvoidArea | Size | number>): void - -开启监听。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | string | 是 | 设置监听类型。
- type为'keyboardHeightChange'时表示监听类型为键盘高度变化监听;
- type为'windowSizeChange'7+时表示监听类型为窗口尺寸变化监听;
- type为'systemAvoidAreaChange'7+时表示监听类型为系统窗口规避区变化监听。 | - | callback | Callback<[AvoidArea](#avoidarea) \| [Size](#size) \| number> | 是 | 回调返回监听到的信息。 | - -- 示例 - ``` - var type = 'windowSizeChange'; - windowClass.on(type, (data) => { - console.info('Succeeded in enabling the listener for window size changes. Data: ' + JSON.stringify(data)); - }); - ``` - -### off('keyboardHeightChange'|'windowSizeChange'7+|'systemAvoidAreaChange'7+) - -off(type: string, callback?: Callback<AvoidArea | Size | number>): void - -关闭监听。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | string | 是 | 设置监听类型。
- type为'keyboardHeightChange'时表示监听类型为键盘高度变化监听;
- type为'windowSizeChange'7+时表示监听类型为窗口尺寸变化监听;
- type为'systemAvoidAreaChange'7+时表示监听类型为系统窗口规避区变化监听。 | - | callback | Callback<[AvoidArea](#avoidarea) \| [Size](#size) \| number> | 否 | 回调返回监听到的信息。 | - -- 示例 - ``` - var type = 'windowSizeChange'; - windowClass.off(type); - ``` diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/10.\350\256\276\345\244\207\347\256\241\347\220\206/11.\346\230\276\347\244\272\350\256\276\345\244\207\345\261\236\346\200\247.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/10.\350\256\276\345\244\207\347\256\241\347\220\206/11.\346\230\276\347\244\272\350\256\276\345\244\207\345\261\236\346\200\247.md" deleted file mode 100644 index a3a2ad036cec0e512e69dcf8114f91227b42e379..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/10.\350\256\276\345\244\207\347\256\241\347\220\206/11.\346\230\276\347\244\272\350\256\276\345\244\207\345\261\236\346\200\247.md" +++ /dev/null @@ -1,154 +0,0 @@ ---- -title: 显示设备属性 -permalink: /pages/010c010a0b -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 显示设备属性 - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import display from '@ohos.display'; -``` - - -## 权限列表 - -无 - - -## DisplayState - -用于表示显示设备的状态。 - -| 名称 | 默认值 | 说明 | -| -------- | -------- | -------- | -| STATE_UNKNOWN | 0 | 表示显示设备状态未知。 | -| STATE_OFF | 1 | 表示显示设备状态为关闭。 | -| STATE_ON | 2 | 表示显示设备状态为开启。 | -| STATE_DOZE | 3 | 表示显示设备为低电耗模式。 | -| STATE_DOZE_SUSPEND | 4 | 表示显示设备为睡眠模式,CPU为挂起状态 。 | -| STATE_VR | 5 | 表示显示设备为VR模式。 | -| STATE_ON_SUSPEND | 6 | 表示显示设备为开启状态,CPU为挂起状态。 | - - -## Display - -描述display对象的属性。 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| id | number | 是 | 否 | 显示设备的id号。 | -| name | string | 是 | 否 | 显示设备的名称。 | -| alive | boolean | 是 | 否 | 显示设备是否启用。 | -| state | [DisplayState](#displaystate) | 是 | 否 | 显示设备的状态。 | -| refreshRate | number | 是 | 否 | 显示设备的刷新率。 | -| rotation | number | 是 | 否 | 显示设备的屏幕旋转角度。 | -| width | number | 是 | 否 | 显示设备的宽度,单位为像素。 | -| height | number | 是 | 否 | 显示设备的高度,单位为像素。 | -| densityDPI | number | 是 | 否 | 显示设备的屏幕密度,单位为DPI。 | -| densityPixels | number | 是 | 否 | 显示设备的屏幕密度,单位为像素。 | -| scaledDensity | number | 是 | 否 | 显示设备的显示字体的缩放因子。 | -| xDPI | number | 是 | 否 | x方向中每英寸屏幕的确切物理像素值。 | -| yDPI | number | 是 | 否 | y方向中每英寸屏幕的确切物理像素值。 | - - -## display.getDefaultDisplay - -getDefaultDisplay(callback: AsyncCallback<Display>): void; - -获取当前默认的display对象。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<[Display](#display)> | 是 | 回调返回显示设备的属性。 | - -- 示例 - ``` - var displayClass = null; - display.getDefaultDisplay((err, data) => { - if (err) { - console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(err)); - return; - } - console.info('Succeeded in obtaining the default display object. Data:' + JSON.stringify(data)); - displayClass = data; - }); - ``` - - -## display.getAllDisplay - -getAllDisplay(callback: AsyncCallback<Array<Display>>): void; - -获取当前所有的display对象。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<Array<[Display](#display)>> | 是 | 回调返回多个显示设备的属性。 | - -- 示例 - ``` - display.getAllDisplay((err, data) => { - if (err) { - console.error('Failed to obtain all the display objects. Code: ' + JSON.stringify(err)); - return; - } - console.info('Succeeded in obtaining all the display objects. Data: ' + JSON.stringify(data)) - }); - ``` - - -## display.on('add'|'remove'|'change') - -on(type: 'add'|'remove'|'change', callback: Callback<number>): void; - -开启监听。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | string | 是 | 设置监听类型。
- type为"add",表示监听增加显示设备。
- type为"remove",表示监听移除显示设备。
- type为"change",表示监听改变显示设备。 | - | callback | Callback<number> | 是 | 回调返回监听到的显示设备的id。 | - -- 示例 - ``` - var type = "add"; - var callback = (data) => { - console.info('Listening enabled. Data: ' + JSON.stringify(data)) - } - display.on(type, callback); - ``` - - -## display.off('add'|'remove'|'change') - -off(type: 'add'|'remove'|'change', callback?: Callback<number>): void; - -关闭监听。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | string | 是 | 设置监听类型。
- type为"add",表示监听增加显示设备。
- type为"remove",表示监听移除显示设备。
- type为"change",表示监听改变显示设备。 | - | callback | Callback<number> | 否 | 回调返回监听到的显示设备的id。 | - -- 示例 - ``` - var type = "remove"; - display.off(type); - ``` diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/10.\350\256\276\345\244\207\347\256\241\347\220\206/12.\345\215\207\347\272\247.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/10.\350\256\276\345\244\207\347\256\241\347\220\206/12.\345\215\207\347\272\247.md" deleted file mode 100644 index 60c5f239a63ef97057cfa0d347f46eda8089af2e..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/10.\350\256\276\345\244\207\347\256\241\347\220\206/12.\345\215\207\347\272\247.md" +++ /dev/null @@ -1,556 +0,0 @@ ---- -title: 升级 -permalink: /pages/010c010a0c -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 升级 - -升级范围:升级整个OpenHarmony系统,包括内置的资源、预置应用;第三方的应用不在升级的范围。 - -升级依赖:升级分为SD卡升级和在线升级两种。 - -- SD卡升级依赖升级包和SD卡安装。 -- 在线升级依赖手机厂商部署的用于管理升级包的服务器。服务器由手机厂商部署,IP由调用者传入,请求的request接口是固定的,由手机厂商开发。 - -## 导入模块 - -```js -import update from '@ohos.update' -``` - -## 权限列表 - -无 - -## 获取升级对象Updater - -### update.getUpdater - -getUpdater(upgradeFile: string, updateType?: UpdateTypes): Updater - -获取本地升级Updater。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ----------- | --------------------------- | ---- | -------- | -| upgradeFile | string | 是 | 升级文件 | -| updateType | [UpdateTypes](#updatetypes) | 是 | 升级类型 | - -**返回值:** - -| 类型 | 说明 | -| ------------------- | -------- | -| [Updater](#updater) | 升级对象 | - -**示例:** - -``` -try { - let updater = update.getUpdater('/data/updater/updater.zip', 'OTA'); -} catch(error) { - console.error(" Fail to get updater error: " + error); -} -``` - -### update.getUpdaterForOther - -getUpdaterForOther(upgradeFile: string, device: string, updateType?: UpdateTypes): Updater - -获取升级对象给待升级设备。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ----------- | --------------------------- | ---- | ---------- | -| upgradeFile | string | 是 | 升级文件 | -| device | string | 是 | 待升级设备 | -| updateType | [UpdateTypes](#updatetypes) | 是 | 升级类型 | - -**返回值:** - -| 类型 | 说明 | -| ------------------- | -------- | -| [Updater](#updater) | 升级对象 | - -**示例:** - -``` -try { - let updater = update.getUpdaterForOther('/data/updater/updater.zip', '1234567890', 'OTA'); -} catch(error) { - console.error(" Fail to get updater error: " + error); -} -``` - -### update.getUpdaterFromOther - -getUpdaterFromOther(upgradeFile: string, device: string, updateType?: UpdateTypes): Updater - -获取其它设备为本设备升级的Updater。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ----------- | --------------------------- | ---- | ---------- | -| upgradeFile | string | 是 | 升级文件 | -| device | string | 是 | 待升级设备 | -| updateType | [UpdateTypes](#updatetypes) | 是 | 升级类型 | - -**返回值:** - -| 类型 | 说明 | -| ------------------- | -------- | -| [Updater](#updater) | 升级对象 | - -**示例:** - -``` -try { - let updater = update.getUpdaterFromOther('/data/updater/updater.zip', '1234567890', 'OTA'); -} catch(error) { - console.error(" Fail to get updater error: " + error); -} -``` - -## Updater - -### getNewVersionInfo - -getNewVersionInfo(callback: AsyncCallback\): void - -获取新版本信息,使用callback方式作为异步方法。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------------------ | ---- | ------------------ | -| callback | AsyncCallback<[NewVersionInfo](#newversioninfo)> | 否 | 回调返回新版本信息 | - -**示例:** - -``` -update.getNewVersionInfo(info => { - console.log("getNewVersionInfo success " + info.status); - console.log(`info versionName = ` + info.result[0].versionName); - console.log(`info versionCode = ` + info.result[0].versionCode); - console.log(`info verifyInfo = ` + info.result[0].verifyInfo); -}); -``` - -### getNewVersionInfo - -getNewVersionInfo(): Promise\ - -获取新版本信息,使用promise方式作为异步方法。 - -**返回值:** - -| 类型 | 说明 | -| ------------------------------------------- | ------------------------- | -| Promise\<[NewVersionInfo](#newversioninfo)> | Promise,用于异步获取结果 | - -**示例:** - -``` -updater.getNewVersionInfo().then(value => { - console.log(`info versionName = ` + value.result[0].versionName); - console.log(`info versionCode = ` + value.result[0].versionCode); - console.log(`info verifyInfo = ` + value.result[0].verifyInfo); -}).catch(err => { - console.log("getNewVersionInfo promise error: " + err.code); -}); -``` - -### checkNewVersion - -checkNewVersion(callback: AsyncCallback\): void - -检查新版本,使用callback方式作为异步方法。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------------------- | ---- | ------------------ | -| callback | AsyncCallback\<[NewVersionInfo](#newversioninfo)> | 否 | 回调返回新版本信息 | - -**示例:** - -``` -update.checkNewVersion(info => { - console.log("checkNewVersion success " + info.status); - console.log(`info versionName = ` + info.result[0].versionName); - console.log(`info versionCode = ` + info.result[0].versionCode); - console.log(`info verifyInfo = ` + info.result[0].verifyInfo); -}); -``` - -### checkNewVersion - -checkNewVersion(): Promise\ - -检查新版本,使用promise方式作为异步方法。 - -**返回值:** - -| 类型 | 说明 | -| ------------------------------------------- | ------------------------- | -| Promise\<[NewVersionInfo](#newversioninfo)> | Promise函数返回新版本信息 | - -**示例:** - -``` -update.checkNewVersion().then(value => { - console.log(`info versionName = ` + value.result[0].versionName); - console.log(`info versionCode = ` + value.result[0].versionCode); - console.log(`info verifyInfo = ` + value.result[0].verifyInfo); -}).catch(err => { - console.log("checkNewVersion promise error: " + err.code); -}); -``` - -### verifyUpdatePackage - -verifyUpdatePackage(upgradeFile: string, certsFile: string): void - -升级前检查升级包是否有效。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ----------- | ------ | ---- | ------------------ | -| upgradeFile | string | 是 | 待校验的升级包路径 | -| certsFile | string | 是 | 证书路径 | - -**示例:** - -``` -update.on("verifyProgress", callback => { - console.info('on verifyProgress ' + callback.percent); -}); -update.verifyUpdatePackage("XXX", "XXX"); -``` - -### rebootAndCleanUserData - -rebootAndCleanUserData(): Promise\ - -重启设备并清除用户分区数据。 - -**返回值:** - -| 类型 | 说明 | -| ---------------- | ------------------------------- | -| Promise\ | Promise示例,用于异步获取结果。 | - -**示例:** - -``` -update.rebootAndCleanUserData().then(result => { - console.log("rebootAndCleanUserData " + result); -}).catch(err => { - console.info("rebootAndCleanUserData promise error: " + err.code); -}); -``` - -### rebootAndCleanUserData - -rebootAndCleanUserData(callback: AsyncCallback\): void - -重启设备并清除用户分区数据。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | ---- | ---------------------- | -| callback | Function | 是 | AsyncCallback\ | - -**示例:** - -``` -update.rebootAndCleanUserData(result => { - console.log("rebootAndCleanUserData ", result) -}); -``` - -### applyNewVersion - -applyNewVersion(): Promise\ - -重启设备后安装升级包。 - -**返回值:** - -| 类型 | 说明 | -| ---------------- | ------------------------------- | -| Promise\ | Promise示例,用于异步获取结果。 | - -**示例:** - -``` -update.applyNewVersion().then(result => { - console.log("appVewVersion ", result) -}).catch(err => { - console.info("applyNewVersion promise error: " + err.code); -}); -``` - -### applyNewVersion - -applyNewVersion(callback: AsyncCallback\): void - -重启设备后安装升级包。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | ---- | ---------------------- | -| callback | Function | 是 | AsyncCallback\ | - -**示例:** - -``` -update.applyNewVersion(result => { - console.log("applyNewVersion ", result) -}); -``` - -### download - -download(): void - -下载新版本,并监听下载进程。 - -**示例:** - -``` -updater.on("downloadProgress", progress => { - console.log("downloadProgress on" + progress); - console.log(`downloadProgress status: ` + progress.status); - console.log(`downloadProgress percent: ` + progress.percent); -}); -updater.download(); -``` - -### upgrade - -updater.upgrade():void - -启动升级。 - -**示例:** - -``` -updater.on("upgradeProgress", progress => { - console.log("upgradeProgress on" + progress); - console.log(`upgradeProgress status: ` + progress.status); - console.log(`upgradeProgress percent: ` + progress.percent); -}); -updater.upgrade(); -``` - -### setUpdatePolicy - -setUpdatePolicy(policy: UpdatePolicy, callback: AsyncCallback\): void - -设置升级策略,使用callback方式作为异步方法。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ----------------------------- | ---- | ------------ | -| policy | [UpdatePolicy](#updatepolicy) | 是 | 设置升级策略 | -| callback | AsyncCallback\ | 是 | 回调返回结果 | - -**示例:** - -``` -// 设置策略 -let policy = { - autoDownload: false, - autoDownloadNet: true, - mode: 2, - autoUpgradeInterval: [ 2, 3 ], - autoUpgradeCondition: 2 -} -update.setUpdatePolicy(policy, result => { - console.log("setUpdatePolicy ", result) -}); -``` - -### setUpdatePolicy - -setUpdatePolicy(policy: UpdatePolicy): Promise\ - -设置升级策略,使用promise方式作为异步方法。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ----------------------------- | ---- | ------------ | -| policy | [UpdatePolicy](#updatepolicy) | 是 | 设置升级策略 | - -**返回值:** - -| 类型 | 说明 | -| ---------------- | ----------------------- | -| Promise\ | Promise函数返回设置结果 | - -**示例:** - -``` -let policy = { - autoDownload: false, - autoDownloadNet: true, - mode: 2, - autoUpgradeInterval: [ 2, 3 ], - autoUpgradeCondition: 2 -} -update.setUpdatePolicy(policy).then(result => - console.log("setUpdatePolicy ", result) -).catch(err => { - console.log("setUpdatePolicy promise error: " + err.code); -}); -``` - -### getUpdatePolicy - -getUpdatePolicy(callback: AsyncCallback\): void - -获取升级策略信息,使用callback方式作为异步方法。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | --------------------------------------------- | ---- | -------------------- | -| callback | AsyncCallback\<[UpdatePolicy](#updatepolicy)> | 否 | 回调返回升级策略信息 | - -**示例:** - -``` -update.getUpdatePolicy(policy => { - console.log("getUpdatePolicy success"); - console.log(`policy autoDownload = ` + policy.autoDownload); - console.log(`policy autoDownloadNet = ` + policy.autoDownloadNet); - console.log(`policy mode = ` + policy.mode); -}); -``` - -### getUpdatePolicy - -getUpdatePolicy(): Promise\ - -获取升级策略,通过promise方式作为异步方法。 - -**返回值:** - -| 类型 | 说明 | -| --------------------------------------- | --------------------------- | -| Promise\<[UpdatePolicy](#updatepolicy)> | Promise函数返回升级策略信息 | - -**示例:** - -``` -update.getUpdatePolicy().then(value => { - console.log(`info autoDownload = ` + value.autoDownload); - console.log(`info autoDownloadNet = ` + value.autoDownloadNet); - console.log(`info mode = ` + value.mode); -}).catch(err => { - console.log("getUpdatePolicy promise error: " + err.code); -}); -``` - -## UpdateTypes - -升级类型。 - -| 参数名 | 说明 | -| ------ | -------- | -| OTA | OTA升级 | -| patch | 补丁升级 | - -## PackageTypes - -升级包类型。 - -| 参数名 | 默认值 | 说明 | -| -------------------- | ------ | -------------- | -| PACKAGE_TYPE_NORMAL | 1 | 通用升级包 | -| PACKAGE_TYPE_BASE | 2 | 基础升级包 | -| PACKAGE_TYPE_CUST | 3 | 定制升级包 | -| PACKAGE_TYPE_PRELOAD | 4 | 预装升级包 | -| PACKAGE_TYPE_COTA | 5 | 参数配置升级包 | -| PACKAGE_TYPE_VERSION | 6 | 版本升级包 | -| PACKAGE_TYPE_PATCH | 7 | 补丁包 | - -## InstallMode - -安装模式。 - -| 参数名 | 默认值 | 说明 | -| ------------------- | ------ | -------- | -| INSTALL_MODE_NORMAL | 0 | 正常升级 | -| INSTALL_MODE_NIGHT | 1 | 夜间升级 | -| INSTALL_MODE_AUTO | 2 | 自动升级 | - -## NewVersionStatus - -新版本检测状态。 - -| 参数名 | 默认值 | 说明 | -| ------------------- | ------ | ---------------- | -| VERSION_STATUS_ERR | -1 | 检测版本时出错 | -| VERSION_STATUS_NEW | 0 | 检测到新版本 | -| VERSION_STATUS_NONE | 1 | 没有检测到新版本 | -| VERSION_STATUS_BUSY | 2 | 检测版本时忙 | - -## UpdatePolicy - -升级策略。 - -| 名称 | 参数类型 | 必填 | 说明 | -| ------------------- | --------------------------- | ---- | -------------- | -| autoDownload | bool | 是 | 自动升级开关 | -| installMode | [InstallMode](#installmode) | 是 | 安装模式 | -| autoUpgradeInterval | Array\ | 是 | 自动升级时间段 | - -## NewVersionInfo - -新版本信息。 - -| 名称 | 参数类型 | 必填 | 说明 | -| --------------- | ------------------------------------------- | ---- | -------- | -| status | [NewVersionStatus](#newversionstatus) | 是 | 升级状态 | -| errMsg | string | 是 | 错误信息 | -| checkResults | Array<[CheckResult](#checkresult)> | 是 | 检测结果 | -| descriptionInfo | Array\<[DescriptionInfo](#descriptioninfo)> | 是 | 描述信息 | - -## CheckResult - -检测结果。 - -| 名称 | 参数类型 | 必填 | 说明 | -| ------------- | ----------------------------- | ---- | ------------ | -| versionName | string | 是 | 版本名称 | -| versionCode | number | 是 | 版本编码 | -| size | number | 是 | 版本大小 | -| verifyInfo | string | 是 | 版本校验信息 | -| packageType | [PackageTypes](#packagetypes) | 是 | 版本类型 | -| descriptionId | string | 是 | 版本描述信息 | - -## DescriptionInfo - -版本描述信息。 - -| 名称 | 参数类型 | 必填 | 说明 | -| ------------- | -------- | ---- | ----------------- | -| descriptionId | string | 是 | 版本versionId信息 | -| content | string | 是 | 版本changelog信息 | \ No newline at end of file diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/10.\350\256\276\345\244\207\347\256\241\347\220\206/13.USB\347\256\241\347\220\206.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/10.\350\256\276\345\244\207\347\256\241\347\220\206/13.USB\347\256\241\347\220\206.md" deleted file mode 100644 index 7187c4a8d3ded970a1609a11e5d1bc9653731105..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/10.\350\256\276\345\244\207\347\256\241\347\220\206/13.USB\347\256\241\347\220\206.md" +++ /dev/null @@ -1,541 +0,0 @@ ---- -title: USB管理 -permalink: /pages/010c010a0d -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# USB管理 - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import usb from "@ohos.usb"; -``` - - -## 权限 - -无 - - -## usb.getDevices - -usb.getDevices(): Array<Readonly<USBDevice>> - -获取USB设备列表。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Array<Readonly<[USBDevice](#usbdevice)>> | 设备信息列表。 | - -- 示例: - ``` - let devicesList = usb.getDevices(); - console.log(`devicesList = ${JSON.stringify(devicesList)}`); - //devicesList 返回的数据结构 - //此处提供一个简单的示例,如下 - [ - { - name: "1-1", - serial: "", - manufacturerName: "", - productName: "", - version: "", - vendorId: 7531, - productId: 2, - clazz: 9, - subclass: 0, - protocol: 1, - devAddress: 1, - busNum: 1, - configs: [ - { - id: 1, - attributes: 224, - isRemoteWakeup: true, - isSelfPowered: true, - maxPower: 0, - name: "1-1", - interfaces: [ - { - id: 0, - protocol: 0, - clazz: 9, - subclass: 0, - alternateSetting: 0, - name: "1-1", - endpoints: [ - { - address: 129, - attributes: 3, - interval: 12, - maxPacketSize: 4, - direction: 128, - number: 1, - type: 3, - interfaceId: 0, - }, - ], - }, - ], - }, - ], - }, - ] - ``` - - -## usb.connectDevice - -usb.connectDevice(device: USBDevice): Readonly<USBDevicePipe> - -打开USB设备。 - -需要调用[usb.getDevices](#usbgetdevices)获取设备信息以及device;再调用[usb.requestRight](#usbrequestright)获取设备请求权限。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | device | [USBDevice](#usbdevice) | 是 | USB设备信息。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Readonly<[USBDevicePipe](#usbdevicepipe)> | 指定的传输通道对象。 | - -- 示例: - ``` - let devicepipe= usb.connectDevice(device); - console.log(`devicepipe = ${JSON.stringify(devicepipe)}`); - ``` - - -## usb.hasRight - -usb.hasRight(deviceName: string): boolean - -判断是否有权访问该设备。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | deviceName | string | 是 | 设备名称。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | true表示有访问设备的权限,false表示没有访问设备的权限。 | - -- 示例: - ``` - let divicesName="1-1"; - let bool = usb.hasRight(divicesName); - console.log(bool); - ``` - - -## usb.requestRight - -usb.requestRight(deviceName: string): Promise<boolean> - -请求软件包的临时权限以访问设备。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | deviceName | string | 是 | 设备名称。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<boolean> | 获取到true则表示软件包的临时权限已访问成功, 获取到false则表示软件包的临时权限已访问失败。 | - -- 示例: - ``` - let divicesName="1-1"; - usb.requestRight(divicesName).then((ret) => { - console.log(`requestRight = ${JSON.stringify(ret)}`); - }); - ``` - - -## usb.claimInterface - -usb.claimInterface(pipe: USBDevicePipe, iface: USBInterface, force?: boolean): number - -注册通信接口。 - -需要调用[usb.getDevices](#usbgetdevices)获取设备信息以及interfaces;调用[usb.requestRight](#usbrequestright)获取设备请求权限;调用[usb.connectDevice](#usbconnectdevice)接口得到devicepipe作为参数。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | pipe | [USBDevicePipe](#usbdevicepipe) | 是 | 用于确定总线号和设备地址。 | - | iface | [USBInterface](#usbinterface) | 是 | 用于确定需要获取接口的索引。 | - | force | boolean | 否 | 可选参数,是否强制获取。默认值false ,表示不强制获取。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 注册通信接口成功返回0;注册通信接口失败返回其他错误码。 | - -- 示例: - ``` - let ret = usb.claimInterface(devicepipe, interfaces); - console.log(`claimInterface = ${ret}`); - ``` - - -## usb.releaseInterface - -usb.releaseInterface(pipe: USBDevicePipe, iface: USBInterface): number - -释放注册过的通信接口。 - -需要调用[usb.claimInterface](#usbclaiminterface)先获取接口,才能使用此方法释放接口。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | pipe | [USBDevicePipe](#usbdevicepipe) | 是 | 用于确定总线号和设备地址。 | - | iface | [USBInterface](#usbinterface) | 是 | 用于确定需要释放接口的索引。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 释放接口成功返回0;释放接口失败返回其他错误码。 | - -- 示例: - ``` - let ret = usb.releaseInterface(devicepipe, interfaces); - console.log(`releaseInterface = ${ret}`); - ``` - - -## usb.setConfiguration - -usb.setConfiguration(pipe: USBDevicePipe, config: USBConfig): number - -设置设备配置。 - -需要调用[usb.getDevices](#usbgetdevices)获取设备信息以及config;调用[usb.requestRight](#usbrequestright)获取设备请求权限;调用[usb.connectDevice](#usbconnectdevice)得到devicepipe作为参数。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | pipe | [USBDevicePipe](#usbdevicepipe) | 是 | 用于确定总线号和设备地址。 | - | config | [USBConfig](#usbconfig) | 是 | 用于确定需要设置的配置。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 设置设备配置成功返回0;设置设备配置失败返回其他错误码。 | - -- 示例: - ``` - let ret = usb.setConfiguration(devicepipe, config); - console.log(`setConfiguration = ${ret}`); - ``` - - -## usb.setInterface - -usb.setInterface(pipe: USBDevicePipe, iface: USBInterface): number - -设置设备接口。 - -需要调用[usb.getDevices](#usbgetdevices)获取设备列表以及interfaces;调用[usb.requestRight](#usbrequestright)获取设备请求权限;调用[usb.connectDevice](#usbconnectdevice)得到devicepipe作为参数。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | pipe | [USBDevicePipe](#usbdevicepipe) | 是 | 用于确定总线号和设备地址。 | - | iface | [USBInterface](#usbinterface) | 是 | 用于确定需要设置的接口。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 设置设备接口成功返回0;设置设备接口失败返回其他错误码。 | - -- 示例: - ``` - let ret = usb.setInterface(devicepipe, interfaces); - console.log(`setInterface = ${ret}`); - ``` - - -## usb.getRawDescriptor - -usb.getRawDescriptor(pipe: USBDevicePipe): Uint8Array - -获取原始的USB描述符。 - -需要调用[usb.getDevices](#usbgetdevices)获取设备列表;调用[usb.requestRight](#usbrequestright)获取设备请求权限;调用[usb.connectDevice](#usbconnectdevice)接口得到devicepipe作为参数。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | pipe | [USBDevicePipe](#usbdevicepipe) | 是 | 用于确定总线号和设备地址。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Uint8Array | 返回获取的原始数据。 | - -- 示例: - ``` - let ret = usb.getRawDescriptor(devicepipe); - ``` - - -## usb.getFileDescriptor - -usb.getFileDescriptor(pipe: USBDevicePipe): number - -获取文件描述符。 - -需要调用[usb.getDevices](#usbgetdevices)获取设备列表;调用[usb.requestRight](#usbrequestright)获取设备请求权限;调用[usb.connectDevice](#usbconnectdevice)接口得到devicepipe作为参数。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | pipe | [USBDevicePipe](#usbdevicepipe) | 是 | 用于确定总线号和设备地址。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 返回设备对应的文件描述符。 | - -- 示例: - ``` - let ret = usb.getFileDescriptor(devicepipe); - ``` - - -## usb.controlTransfer - -usb.controlTransfer(pipe: USBDevicePipe, contrlparam: USBControlParams, timeout?: number): Promise<number> - -控制传输。 - -需要调用[usb.getDevices](#usbgetdevices)获取设备列表;调用[usb.requestRight](#usbrequestright)获取设备请求权限;调用[usb.connectDevice](#usbconnectdevice)接口得到devicepipe作为参数。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | pipe | [USBDevicePipe](#usbdevicepipe) | 是 | 用于确定设备。 | - | contrlparam | [USBControlParams](#usbcontrolparams) | 是 | 控制传输参数。 | - | timeout | number | 否 | 超时时间,可选参数,默认为0不超时。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<number> | 获取传输或接收到的数据块大小, 获取到-1则表示异常。 | - -- 示例: - ``` - usb.controlTransfer(devicepipe, USBControlParams).then((ret) => { - console.log(`controlTransfer = ${JSON.stringify(ret)}`); - }) - ``` - - -## usb.bulkTransfer - -usb.bulkTransfer(pipe: USBDevicePipe, endpoint: USBEndpoint, buffer: Uint8Array, timeout?: number): Promise<number> - -批量传输。 - -需要调用[usb.getDevices](#usbgetdevices)获取设备信息列表以及endpoint;再调用[usb.requestRight](#usbrequestright)获取设备请求权限;然后调用[usb.connectDevice](#usbconnectdevice)接口得到返回数据devicepipe之后,再次获取接口[usb.claimInterface](#usbclaiminterface);再调用usb.bulkTransfer接口。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | pipe | [USBDevicePipe](#usbdevicepipe) | 是 | 用于确定设备。 | - | endpoint | [USBEndpoint](#usbendpoint) | 是 | 用于确定传输的端口。 | - | buffer | Uint8Array | 是 | 用于写入或读取的缓冲区。 | - | timeout | number | 否 | 超时时间,可选参数,默认为0不超时。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<number> | 获取传输或接收到的数据块大小, 获取到-1则表示异常。 | - -- 示例: - ``` - //usb.getDevices 接口返回数据集合,取其中一个设备对象,并获取权限 。 - //把获取到的设备对象作为参数传入usb.connectDevice;当usb.connectDevice接口成功返回之后; - //才可以调用第三个接口usb.claimInterface.当usb.claimInterface 调用成功以后,再调用该接口。 - usb.bulkTransfer(devicepipe, endpoint, buffer).then((ret) => { - console.log(`bulkTransfer = ${JSON.stringify(ret)}`); - }); - ``` - - -## usb.closePipe - -usb.closePipe(pipe: USBDevicePipe): number - -关闭设备消息控制通道。 - -需要调用[usb.getDevices](#usbgetdevices)获取设备列表;调用[usb.requestRight](#usbrequestright)获取设备请求权限;调用[usb.connectDevice](#usbconnectdevice)得到devicepipe作为参数。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | pipe | [USBDevicePipe](#usbdevicepipe) | 是 | 用于确定USB设备消息控制通道。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 关闭设备消息控制通道成功返回0;关闭设备消息控制通道失败返回其他错误码。 | - -- 示例: - ``` - let ret = usb.closePipe(devicepipe); - console.log(`closePipe = ${ret}`); - ``` - - -## USBEndpoint - -通过USB发送和接收数据的端口。通过[USBInterface](#usbinterface)获取。 - -| 名称 | 参数类型 | 说明 | -| -------- | -------- | -------- | -| address | number | 端点地址。 | -| attributes | number | 端点属性。 | -| interval | number | 端点间隔。 | -| maxPacketSize | number | 端点最大数据包大小。 | -| direction | [USBRequestDirection](#usbrequestdirection) | 端点的方向。 | -| number | number | 端点号。 | -| type | number | 端点类型。 | -| interfaceId | number | 端点所属的接口的唯一标识。 | - - -## USBInterface - -一个[USBConfig](#usbconfig)中可以含有多个USBInterface,每个USBInterface提供一个功能。 - -| 名称 | 参数类型 | 说明 | -| -------- | -------- | -------- | -| id | number | 接口的唯一标识。 | -| protocol | number | 接口的协议。 | -| clazz | number | 设备类型。 | -| subClass | number | 设备子类。 | -| alternateSetting | number | 在同一个接口中的多个描述符中进行切换设置。 | -| name | string | 接口名称。 | -| endpoints | Array<[USBEndpoint](#usbendpoint)> | 当前接口所包含的端点。 | - - -## USBConfig - -USB配置,一个[USBDevice](#usbdevice)中可以含有多个配置。 - -| 名称 | 参数类型 | 说明 | -| -------- | -------- | -------- | -| id | number | 配置的唯一标识。 | -| attributes | number | 配置的属性。 | -| maxPower | number | 最大功耗,以毫安为单位。 | -| name | string | 配置的名称,可以为空。 | -| isRemoteWakeup | boolean | 检查当前配置是否支持远程唤醒。 | -| isSelfPowered | boolean | 检查当前配置是否支持独立电源。 | -| interfaces | Array <[USBInterface](#usbinterface)> | 配置支持的接口属性。 | - - -## USBDevice - -USB设备信息。 - -| 名称 | 参数类型 | 说明 | -| -------- | -------- | -------- | -| busNum | number | 总线地址。 | -| devAddress | number | 设备地址。 | -| serial | string | 序列号。 | -| name | string | 设备名字。 | -| manufacturerName | string | 产商信息。 | -| productName | string | 产品信息。 | -| version | string | 版本。 | -| vendorId | number | 厂商ID。 | -| productId | number | 产品ID。 | -| clazz | number | 设备类。 | -| subClass | number | 设备子类。 | -| protocol | number | 设备协议码。 | -| configs | Array<[USBConfig](#usbconfig)> | 设备配置描述符信息。 | - - -## USBDevicePipe - -USB设备消息传输通道,用于确定设备。 - -| 名称 | 参数类型 | 说明 | -| -------- | -------- | -------- | -| busNum | number | 总线地址。 | -| devAddress | number | 设备地址。 | - - -## USBControlParams - -控制传输参数。 - -| 名称 | 参数类型 | 说明 | -| -------- | -------- | -------- | -| request | number | 请求类型。 | -| target | [USBRequestTargetType](#usbrequesttargettype) | 请求目标类型。 | -| reqType | [USBControlRequestType](#usbcontrolrequesttype) | 请求控制类型。 | -| value | number | 请求参数。 | -| index | number | 请求参数value对应的索引值。 | -| data | Uint8Array | 用于写入或读取的缓冲区。 | - - -## USBRequestTargetType - -请求目标类型。 - - -| 名称 | 默认值 | 说明 | -| -------- | -------- | -------- | -| USB_REQUEST_TARGET_DEVICE | 0 | 设备。 | -| USB_REQUEST_TARGET_INTERFACE | 1 | 接口。 | -| USB_REQUEST_TARGET_ENDPOINT | 2 | 端点。 | -| USB_REQUEST_TARGET_OTHER | 3 | 其他。 | - - -## USBControlRequestType - -控制请求类型。 - -| 名称 | 默认值 | 说明 | -| -------- | -------- | -------- | -| USB_REQUEST_TYPE_STANDARD | 0 | 标准。 | -| USB_REQUEST_TYPE_CLASS | 1 | 类。 | -| USB_REQUEST_TYPE_VENDOR | 2 | 厂商。 | - - -## USBRequestDirection - -请求方向。 - -| 名称 | 默认值 | 说明 | -| -------- | -------- | -------- | -| USB_REQUEST_TYPE_STANDARD | 0 | 写数据,主设备往从设备。 | -| USB_REQUEST_TYPE_CLASS | 0x80 | 读数据,从设备往主设备。 | - -| 名称 | 默认值 | 说明 | -| -------- | -------- | -------- | -| NONE | 0 | 无。 | -| ACM | 1 | 串口设备。 | -| ECM | 2 | 网口设备。 | -| HDC | 4 | HDC设备。 | diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/11.\345\237\272\346\234\254\345\212\237\350\203\275/01.\345\272\224\347\224\250\344\270\212\344\270\213\346\226\207.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/11.\345\237\272\346\234\254\345\212\237\350\203\275/01.\345\272\224\347\224\250\344\270\212\344\270\213\346\226\207.md" deleted file mode 100644 index 1e04ddd2eabdbba32dc13804188cb6db6ed68523..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/11.\345\237\272\346\234\254\345\212\237\350\203\275/01.\345\272\224\347\224\250\344\270\212\344\270\213\346\226\207.md" +++ /dev/null @@ -1,92 +0,0 @@ ---- -title: 应用上下文 -permalink: /pages/010c010b01 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 应用上下文 - - -## 导入模块 - -``` -import app from '@system.app'; -``` - -## 权限列表 - -无 - - -## app.getInfo - -getInfo(): <AppResponse> - -获取当前应用配置文件中声明的信息。 - -- 返回值 - **表1** AppResponse - - | | | | - | -------- | -------- | -------- | - | 参数名 | 类型 | 说明 | - | appID6+ | string | 表示应用的包名,用于标识应用的唯一性。 | - | appName | string | 表示应用的名称。 | - | versionName | string | 表示应用的版本名称。 | - | versionCode | number | 表示应用的版本号。 | - -- 示例 - ``` - export default { - getInfo(){ - var info = app.getInfo(); - console.log(JSON.stringify(info)); - } - } - ``` - - -## app.terminate - -terminate(): void - -退出当前Ability - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 从API Version 7 开始,推荐使用新接口['@ohos.ability.featureAbility'](/pages/010c010101)。 - -- 示例 - ``` - export default { - terminate(){ - app.terminate(); - }} - ``` - -## app.requestFullWindow - -requestFullWindow(duration: number): void - -请求应用以全窗口运行,FA在某些场景下(如半模态FA)会以非全窗口运行,调用该接口会从非全窗口切换为全窗口运行,如果已经以全窗口运行则该接口调用无效。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | duration | number | 否 | 请求全屏时,设定非全屏到全屏的过渡时间,单位为毫秒,默认时间与非全屏到全屏的距离成正比。 | - -- 示例 - ``` - export default { - requestFullWindow(){ - app.requestFullWindow({ - duration: 200}); - } - } - ``` diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/11.\345\237\272\346\234\254\345\212\237\350\203\275/02.\346\227\245\345\277\227\346\211\223\345\215\260.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/11.\345\237\272\346\234\254\345\212\237\350\203\275/02.\346\227\245\345\277\227\346\211\223\345\215\260.md" deleted file mode 100644 index 00d4fabc20606169066e9944b111fc149d6b85ad..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/11.\345\237\272\346\234\254\345\212\237\350\203\275/02.\346\227\245\345\277\227\346\211\223\345\215\260.md" +++ /dev/null @@ -1,101 +0,0 @@ ---- -title: 日志打印 -permalink: /pages/010c010b02 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 日志打印 - - -## 导入模块 - -无需导入。 - -## 权限列表 - -无 - - -## console.debug - -debug(message: string): void - -打印debug级别的日志信息。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | message | string | 是 | 表示要打印的文本信息。 | - - -## console.log - -log(message: string): void - -打印debug级别的日志信息。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | message | string | 是 | 表示要打印的文本信息。 | - - -## console.info - -info(message: string): void - -打印info级别的日志信息。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | message | string | 是 | 表示要打印的文本信息。 | - - -## console.warn - -warn(message: string): void - -打印warn级别的日志信息。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | message | string | 是 | 表示要打印的文本信息。 | - - -## console.error - -error(message: string): void - -打印error级别的日志信息。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | message | string | 是 | 表示要打印的文本信息。 | - - -## 示例 - -``` -export default { - clickConsole(){ - var versionCode = 1; - console.info('Hello World. The current version code is ' + versionCode); - console.log(`versionCode: ${versionCode}`); - // 以下写法从API Version 6开始支持console.log('versionCode:%d.', versionCode); - } -} -``` - -在DevEco Studio的底部,切换到“HiLog”窗口。选择当前的设备及进程,日志级别选择Info,搜索内容设置为“Hello World”。此时窗口仅显示符合条件的日志,效果如图所示: - -![zh-cn_image_0000001200913929](/images/application-dev/reference/apis/figures/zh-cn_image_0000001200913929.png) diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/11.\345\237\272\346\234\254\345\212\237\350\203\275/03.\351\241\265\351\235\242\350\267\257\347\224\261.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/11.\345\237\272\346\234\254\345\212\237\350\203\275/03.\351\241\265\351\235\242\350\267\257\347\224\261.md" deleted file mode 100644 index 7a28b30b3c3467cd33f318835c7dd609877ea8cd..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/11.\345\237\272\346\234\254\345\212\237\350\203\275/03.\351\241\265\351\235\242\350\267\257\347\224\261.md" +++ /dev/null @@ -1,304 +0,0 @@ ---- -title: 页面路由 -permalink: /pages/010c010b03 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 页面路由 - -> ![icon-notice.gif](/images/application-dev/reference/apis/public_sys-resources/icon-notice.gif) **须知:** -> 页面路由需要在页面渲染完成之后才能调用,在onInit和onReady生命周期中页面还处于渲染阶段,禁止调用页面路由方法。 - - -## 导入模块 - -``` -import router from '@system.router'; -``` - -## 权限列表 - -无 - -## router.push - -push(Object): void - -跳转到应用内的指定页面。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | uri | string | 是 | 表示目标页面的uri,可以用以下两种格式:
- 页面绝对路径,由配置文件中pages列表提供,例如:
  - pages/index/index
  - pages/detail/detail
- 特殊值,如果uri的值是"/",则跳转到首页。 | - | params | Object | 否 | 跳转时要同时传递到目标页面的数据,跳转到目标页面后,参数可以在页面中直接使用,如this.data1(data1为跳转时params参数中的key值)。如果目标页面中已有该字段,则其值会被传入的字段值覆盖。 | - -- 示例 - ``` - // 在当前页面中 - export default { - pushPage() { - router.push({ - uri: 'pages/routerpage2/routerpage2', - params: { - data1: 'message', - data2: { - data3: [123, 456, 789] - }, - }, - }); - } - } - ``` - - ``` - // 在routerpage2页面中 - export default { - data: { - data1: 'default', - data2: { - data3: [1, 2, 3] - } - }, - onInit() { - console.info('showData1:' + this.data1); - console.info('showData3:' + this.data2.data3); - } - } - ``` - - > ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** - > 页面路由栈支持的最大Page数量为32。 - - -## router.replace - -replace(Object): void - -用应用内的某个页面替换当前页面,并销毁被替换的页面。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | uri | string | 是 | 目标页面的uri,可以是以下的两种格式:
- 页面绝对路径,由配置文件中pages列表提供,例如:
  - pages/index/index
  - pages/detail/detail
- 特殊值,如果uri的值是"/",则跳转到首页。 | - | params | Object | 否 | 跳转时要同时传递到目标页面的数据,跳转到目标页面后,参数可以在页面中直接使用,如this.data1(data1为跳转时params参数中的key值)。如果目标页面中已有该字段,则其值会被传入的字段值覆盖。 | - -- 示例 - ``` - // 在当前页面中 - export default { - replacePage() { - router.replace({ - uri: 'pages/detail/detail', - params: { - data1: 'message', - }, - }); - } - } - ``` - - ``` - // 在detail页面中 - export default { - data: { - data1: 'default' - }, - onInit() { - console.info('showData1:' + this.data1) - } - } - ``` - -## router.back - -back(Object): void - -返回上一页面或指定的页面。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | uri | string | 否 | 返回到指定uri的界面,如果页面栈上没有uri页面,则不响应该情况。如果uri未设置,则返回上一页。 | - -- 示例 - ``` - // index页面 - export default { - indexPushPage() { - router.push({ - uri: 'pages/detail/detail', - }); - } - } - ``` - - ``` - // detail页面 - export default { - detailPushPage() { - router.push({ - uri: 'pages/mall/mall', - }); - } - } - ``` - - ``` - // mall页面通过back,将返回detail页面 - export default { - mallBackPage() { - router.back(); - } - } - ``` - - ``` - // detail页面通过back,将返回index页面 - export default { - defaultBack() { - router.back(); - } - } - ``` - - ``` - // 通过back,返回到detail页面 - export default { - backToDetail() { - router.back({uri:'pages/detail/detail'}); - } - } - ``` - - > ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** - > 示例中的uri字段是页面路由,由配置文件中的pages列表指定。 - -## router.clear - -clear(): void - -清空页面栈中的所有历史页面,仅保留当前页面作为栈顶页面。 - -- 示例 - ``` - export default { - clearPage() { - router.clear(); - } - } - ``` - -## router.getLength - -getLength(): string - -获取当前在页面栈内的页面数量。 - -- 返回值 - | 类型 | 说明 | - | -------- | -------- | - | string | 页面数量,页面栈支持最大数值是32。 | - -- 示例 - ``` - export default { - getLength() { - var size = router.getLength(); - console.log('pages stack size = ' + size); - } - } - ``` - -## router.getState - -getState(): <RouterState> - -获取当前页面的状态信息。 - -- 返回值 - **表1** RouterState - - | 参数名 | 类型 | 说明 | - | -------- | -------- | -------- | - | index | number | 表示当前页面在页面栈中的索引。
> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:**
> 从栈底到栈顶,index从1开始递增。 | - | name | string | 表示当前页面的名称,即对应文件名。 | - | path | string | 表示当前页面的路径。 | - -- 示例 - ``` - export default { - getState() { - var page = router.getState(); - console.log('current index = ' + page.index); - console.log('current name = ' + page.name); - console.log('current path = ' + page.path); - } - } - ``` - -## router.enableAlertBeforeBackPage6+ - -enableAlertBeforeBackPage(Object): void - -开启页面返回询问对话框。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | message | string | 是 | 询问对话框内容。 | - | success | () => void | 否 | 接口调用成功的回调函数。 | - | fail | () => void | 否 | 接口调用失败的回调函数。 | - | complete | () => void | 否 | 接口调用结束的回调函数。 | - -- 示例 - ``` - export default { - enableAlertBeforeBackPage() { - router.enableAlertBeforeBackPage({ - message: 'Message Info', - success: function() { - console.log('success'); - }, - fail: function() { - console.log('fail'); - }, - }); - } - } - ``` - -## router.disableAlertBeforeBackPage6+ - -disableAlertBeforeBackPage(Object): void - -禁用页面返回询问对话框。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | success | () => void | 否 | 接口调用成功的回调函数。 | - | fail | () => void | 否 | 接口调用失败的回调函数。 | - | complete | () => void | 否 | 接口调用结束的回调函数。 | - -- 示例 - ``` - export default { - disableAlertBeforeBackPage() { - router.disableAlertBeforeBackPage({ - success: function() { - console.log('success'); - }, - fail: function() { - console.log('fail'); - }, - }); - } - } - ``` diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/11.\345\237\272\346\234\254\345\212\237\350\203\275/04.\345\274\271\347\252\227.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/11.\345\237\272\346\234\254\345\212\237\350\203\275/04.\345\274\271\347\252\227.md" deleted file mode 100644 index f52c9668565d7df9296de5143d8ebc147c360e2c..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/11.\345\237\272\346\234\254\345\212\237\350\203\275/04.\345\274\271\347\252\227.md" +++ /dev/null @@ -1,146 +0,0 @@ ---- -title: 弹窗 -permalink: /pages/010c010b04 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 弹窗 - - -## 导入模块 - -``` -import prompt from '@system.prompt'; -``` - - -## 权限列表 - -无 - -## prompt.showToast - -showToast(Object): void - -显示文本弹窗。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | message | string | 是 | 显示的文本信息。 | - | duration | number | 否 | 默认值1500ms,建议区间:1500ms-10000ms。
> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:**
> 若小于1500ms则取默认值,最大取值为10000ms。 | - | $[bottom]^{5+}$ | <length> | 否 | 设置弹窗边框距离屏幕底部的位置。
> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:**
> 仅手机和平板设备支持。 | - -- 示例 - ``` - export default { - showToast() { - prompt.showToast({ - message: 'Message Info', - duration: 2000, - }); - } - } - ``` - - -## prompt.showDialog - -showDialog(): void - -在页面内显示对话框。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | title | string | 否 | 标题文本。 | - | message | string | 否 | 内容文本。 | - | buttons | Array | 否 | 对话框中按钮的数组,结构为:{text:'button', color: '\#666666'},支持1-3个按钮。其中第一个为positiveButton;第二个为negativeButton;第三个为neutralButton。 | - | success | Function | 否 | 接口调用成功的回调函数,返回值如success返回值所示。 | - | cancel | Function | 否 | 取消调用此接口的回调函数。 | - | complete | Function | 否 | 弹框退出时的回调函数。 | - - success返回值: - - | 参数名 | 类型 | 说明 | - | -------- | -------- | -------- | - | index | number | 选中按钮在buttons数组中的索引。 | - -- 示例 - ``` - export default { - showDialog() { - prompt.showDialog({ - title: 'Title Info', - message: 'Message Info', - buttons: [ - { - text: 'button', - color: '#666666', - }, - ], - success: function(data) { - console.log('dialog success callback,click button : ' + data.index); - }, - cancel: function() { - console.log('dialog cancel callback'); - }, - }); - } - } - ``` - -## prompt.showActionMenu6+ - -showActionMenu(Object): void - -显示操作菜单。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | title | string | 否 | 标题文本。 | - | buttons | Array | 是 | 对话框中按钮的数组,结构为:{text:'button', color: '\#666666'},支持1-6个按钮。大于6个按钮时弹窗不显示。 | - | success | (data: TapIndex) => void | 否 | 接口调用成功的回调函数。 | - | cancel | () => void | 否 | 接口调用失败的回调函数。 | - | complete | () => void | 否 | 接口调用结束的回调函数。 | - - **表1** TapIndex - - | 参数名 | 类型 | 说明 | - | -------- | -------- | -------- | - | tapIndex | number | 选中按钮在buttons数组中的索引,从0开始。 | - -- 示例 - ``` - export default { - showActionMenu() { - prompt.showActionMenu({ - title: 'Title Info', - buttons: [ - { - text: 'item1', - color: '#666666', - }, - { - text: 'item2', - color: '#000000', - }, - ], - success: function(data) { - console.log('dialog success callback,click button : ' + data.tapIndex); - }, - fail: function(data) { - console.log('dialog fail callback' + data.errMsg); - }, - }); - } - } - ``` diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/11.\345\237\272\346\234\254\345\212\237\350\203\275/05.\345\272\224\347\224\250\351\205\215\347\275\256.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/11.\345\237\272\346\234\254\345\212\237\350\203\275/05.\345\272\224\347\224\250\351\205\215\347\275\256.md" deleted file mode 100644 index 9de57f9f9bec33162d41db93d37cb3a4d117172d..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/11.\345\237\272\346\234\254\345\212\237\350\203\275/05.\345\272\224\347\224\250\351\205\215\347\275\256.md" +++ /dev/null @@ -1,57 +0,0 @@ ---- -title: 应用配置 -permalink: /pages/010c010b05 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 应用配置 - - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> - 从API Version 7 开始,该接口不再维护,推荐使用新接口['@ohos.i18n'](/pages/010c010202)和['@ohos.intl'](/pages/010c010203)。 -> - - -## 导入模块 - -``` -import configuration from '@system.configuration'; -``` - -## 权限列表 - -无 - - -## configuration.getLocale - -getLocale(): <LocaleResponse> - -获取应用当前的语言和地区。默认与系统的语言和地区同步。 - -- 返回值 - **表1** LocaleResponse - - | 参数名 | 类型 | 说明 | - | -------- | -------- | -------- | - | language | string | 语言。例如:zh。 | - | countryOrRegion | string | 国家或地区。例如:CN。 | - | dir | string | 文字布局方向。取值范围:
- ltr:从左到右;
- rtl:从右到左。 | - | $unicodeSetting^{5+}$ | string | 语言环境定义的Unicode语言环境键集,如果此语言环境没有特定键集,则返回空集。
例如:{"nu":"arab"},表示当前环境下的数字采用阿拉伯语的数字。 | - -- 示例 - ``` - export default { - getLocale() { - const localeInfo = configuration.getLocale(); - console.info(localeInfo.language); - } - } - ``` diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/11.\345\237\272\346\234\254\345\212\237\350\203\275/06.\345\256\232\346\227\266\345\231\250.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/11.\345\237\272\346\234\254\345\212\237\350\203\275/06.\345\256\232\346\227\266\345\231\250.md" deleted file mode 100644 index 0e6e2af1f328ea6b0c6662bc8c3f685d7b4800d4..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/11.\345\237\272\346\234\254\345\212\237\350\203\275/06.\345\256\232\346\227\266\345\231\250.md" +++ /dev/null @@ -1,132 +0,0 @@ ---- -title: 定时器 -permalink: /pages/010c010b06 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 定时器 - - -## 导入模块 - -无需导入。 - - -## 权限列表 - -无 - - -## setTimeout - -setTimeout(handler[,delay[,…args]]): number - -设置一个定时器,该定时器在定时器到期后执行一个函数。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | handler | Function | 是 | 定时器到期后执行函数。 | - | delay | number | 否 | 延迟的毫秒数,函数的调用会在该延迟之后发生。如果省略该参数,delay取默认值0,意味着“马上”执行,或尽快执行。 | - | ...args | Array<any> | 否 | 附加参数,一旦定时器到期,它们会作为参数传递给handler。 | - -- 返回值 - | 类型 | 说明 | - | -------- | -------- | - | number | timeout定时器的ID。 | - -- 示例 - ``` - export default { - setTimeOut() { - var timeoutID = setTimeout(function() { - console.log('delay 1s'); - }, 1000); - } - } - ``` - - -## clearTimeout - -clearTimeout(timeoutID: number): void - -取消了先前通过调用setTimeout()建立的定时器。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | timeoutID | number | 是 | 要取消定时器的ID, 是由setTimeout()返回的。 | - -- 示例 - ``` - export default { - clearTimeOut() { - var timeoutID = setTimeout(function() { - console.log('do after 1s delay.'); - }, 1000); - clearTimeout(timeoutID); - } - } - ``` - - -## setInterval - -setInterval(handler[, delay[, ...args]]): number - -重复调用一个函数,在每次调用之间具有固定的时间延迟。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | handler | Function | 是 | 要重复调用的函数。 | - | delay | number | 否 | 延迟的毫秒数(一秒等于1000毫秒),函数的调用会在该延迟之后发生。 | - | ...args | Array<any> | 否 | 附加参数,一旦定时器到期,他们会作为参数传递给handler。 | - -- 返回值 - | 类型 | 说明 | - | -------- | -------- | - | number | intervallID重复定时器的ID。 | - -- 示例 - ``` - export default { - setInterval() { - var intervalID = setInterval(function() { - console.log('do very 1s.'); - }, 1000); - } - } - ``` - - -## clearInterval - -clearInterval(intervalID: number): void - -可取消先前通过 setInterval() 设置的重复定时任务。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | intervalID | number | 是 | 要取消的重复定时器的ID,是由 setInterval() 返回的。 | - -- 示例 - ``` - export default { - clearInterval() { - var intervalID = setInterval(function() { - console.log('do very 1s.'); - }, 1000); - clearInterval(intervalID); - } - } - ``` diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/11.\345\237\272\346\234\254\345\212\237\350\203\275/07.\350\256\276\347\275\256\347\263\273\347\273\237\346\227\266\351\227\264.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/11.\345\237\272\346\234\254\345\212\237\350\203\275/07.\350\256\276\347\275\256\347\263\273\347\273\237\346\227\266\351\227\264.md" deleted file mode 100644 index 299d3aa65be7f7b34555c341c9cf9289e451e954..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/11.\345\237\272\346\234\254\345\212\237\350\203\275/07.\350\256\276\347\275\256\347\263\273\347\273\237\346\227\266\351\227\264.md" +++ /dev/null @@ -1,180 +0,0 @@ ---- -title: 设置系统时间 -permalink: /pages/010c010b07 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 设置系统时间 - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import systemTime from '@ohos.systemTime'; -``` - - -## systemTime.setTime - -setTime(time : number, callback : AsyncCallback<void>) : void - -设置系统时间,需要ohos.permission.SET_TIME权限。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | time | number | 是 | 目标时间戳(毫秒)。 | - | callback | AsyncCallback<void> | 是 | 回调函数,可以在回调函数中处理接口返回值。 | - -- 示例: - ``` - // time对应的时间为2021-01-20 02:36:25 - var time = 1611081385000; - systemTime.setTime(time, (error, data) => { - if (error) { - console.error(`failed to systemTime.setTime because ` + JSON.stringify(error)); - return; - } - console.log(`success to systemTime.setTime: ` + JSON.stringify(data)); - }); - ``` - - -## systemTime.setTime - -setTime(time : number) : Promise<void> - -设置系统时间,需要ohos.permission.SET_TIME权限。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | time | number | 是 | 目标时间戳(毫秒)。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | 返回的异步回调函数。 | - -- 示例: - ``` - // time对应的时间为2021-01-20 02:36:25 - var time = 1611081385000; - systemTime.setTime(time).then((data) => { - console.log(`success to systemTime.setTime: ` + JSON.stringify(data)); - }).catch((error) => { - console.error(`failed to systemTime.setTime because ` + JSON.stringify(error)); - }); - ``` - - -## systemTime.setDate - -setDate(date: Date, callback: AsyncCallback<void>): void - -设置系统日期,需要ohos.permission.SET_TIME权限。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | date | Date | 是 | 目标日期。 | - | callback | AsyncCallback<void> | 是 | 回调函数,可以在回调函数中处理接口返回值。 | - -- 示例: - ``` - var data = new Date("October 13, 2020 11:13:00"); - systemTime.setDate(data,(error, data) => { - if (error) { - console.error('SystemTimePlugin setDate failed because ' + JSON.stringify(error)); - return; - } - console.info('SystemTimePlugin setDate success data : ' + JSON.stringify(data)); - }); - ``` - - -## systemTime.setDate - -setDate(date: Date): Promise<void> - -设置系统日期,需要ohos.permission.SET_TIME权限。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | date | Date | 是 | 目标日期。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | 返回的异步回调函数。 | - -- 示例: - ``` - var data = new Date("October 13, 2020 11:13:00"); - systemTime.setDate(data).then((value) => { - console.log(`SystemTimePlugin success to systemTime.setDate: ` + JSON.stringify(value)); - }).catch((error) => { - console.error(`SystemTimePlugin failed to systemTime.setDate because: ` + JSON.stringify(error)); - }); - ``` - - -## systemTime.setTimezone - -setTimezone(timezone: string, callback: AsyncCallback<void>): void - -设置系统时区,需要ohos.permission.SET_TIME_ZONE权限。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | timezone | string | 是 | 系统时区。 | - | callback | AsyncCallback<void> | 是 | 回调函数,可以在回调函数中处理接口返回值。 | - -- 示例: - ``` - systemTime.setTimezone('Asia/Shanghai', (error, data) => { - if (error) { - console.error('SystemTimePlugin setTimezone failed because ' + JSON.stringify(error)); - return; - } - console.info('SystemTimePlugin setTimezone success data : ' + JSON.stringify(data)); - }); - ``` - - -## systemTime.setTimezone - -setTimezone(timezone: string): Promise<void> - -设置系统时区,需要ohos.permission.SET_TIME_ZONE权限。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | timezone | string | 是 | 系统时区。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | 返回的异步回调函数。 | - -- 示例: - ``` - systemTime.setTimezone('Asia/Shanghai').then((data) => { - console.log(`SystemTimePlugin success to systemTime.setTimezone: ` + JSON.stringify(data)); - }).catch((error) => { - console.error(`SystemTimePlugin failed to systemTime.setTimezone because: ` + JSON.stringify(error)); - }); - ``` diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/11.\345\237\272\346\234\254\345\212\237\350\203\275/08.\345\212\250\347\224\273.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/11.\345\237\272\346\234\254\345\212\237\350\203\275/08.\345\212\250\347\224\273.md" deleted file mode 100644 index 4caaf4d70348bffe2c69dab77c376b4e6b3fb59a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/11.\345\237\272\346\234\254\345\212\237\350\203\275/08.\345\212\250\347\224\273.md" +++ /dev/null @@ -1,252 +0,0 @@ ---- -title: 动画 -permalink: /pages/010c010b08 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 动画 - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -requestAnimationFrame:无需导入 - -cancelAnimationFrame:无需导入 - -createAnimator: - -``` -import animator from '@ohos.animator'; -``` - -## 权限列表 - -无 - - -## requestAnimationFrame - -requestAnimationFrame(handler[, [ ...args]]): number - -请求动画帧,逐帧回调JS函数。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | handler | Function | 是 | 表示要逐帧回调的函数。requestAnimationFrame函数回调handler函数时会在第一个参数位置传入timestamp时间戳。它表示requestAnimationFrame开始去执行回调函数的时刻。 | - | ...args | Array<any> | 否 | 附加参数,函数回调时,他们会作为参数传递给handler。 | - -- 返回值 - | 类型 | 说明 | - | -------- | -------- | - | number | requestID请求的ID。 | - -- 示例 - ``` - -
- -
- ``` - - ``` - /* xxx.css */ - .container { - flex-direction: column; - justify-content: center; - align-items: center; - width: 100%; - height: 100%; - } - .btn{ - width: 300px; - margin-top: 40px; - } - ``` - - ``` - /* xxx.js */ - export default { - data: { - requestId: 0, - startTime: 0, - }, - beginAnimation() { - cancelAnimationFrame(this.requestId); - this.requestId = requestAnimationFrame(this.runAnimation); - }, - runAnimation(timestamp) { - if (this.startTime == 0) { - this.startTime = timestamp; - } - var elapsed = timestamp - this.startTime; - if (elapsed < 500) { - console.log('callback handler timestamp: ' + timestamp); - this.requestId = requestAnimationFrame(this.runAnimation); - } - } - } - ``` - - -## cancelAnimationFrame - -cancelAnimationFrame(requestId: number): void - -取消动画帧,取消逐帧回调请求。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | requestId | number | 是 | 逐帧回调函数的标识id。 | - -- 示例 - ``` - -
- - -
- ``` - - ``` - /* xxx.css */ - .container { - flex-direction: column; - justify-content: center; - align-items: center; - width: 100%; - height: 100%; - } - .btn{ - width: 300px; - margin-top: 40px; - } - ``` - - ``` - /* xxx.js */ - export default { - data: { - requestId: 0, - startTime: 0, - }, - beginAnimation() { - cancelAnimationFrame(this.requestId); - this.requestId = requestAnimationFrame(this.runAnimation); - }, - runAnimation(timestamp) { - if (this.startTime == 0) { - this.startTime = timestamp; - } - var elapsed = timestamp - this.startTime; - if (elapsed < 500) { - console.log('callback handler timestamp: ' + timestamp); - this.requestId = requestAnimationFrame(this.runAnimation); - } - }, - stopAnimation() { - cancelAnimationFrame(this.requestId); - } - } - ``` - - -## createAnimator - -createAnimator(options[...]): void - -创建动画对象。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | options | Object | 是 | 表示待创建Animator对象的属性,详情见下表options说明。 | - -- options说明 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | duration | number | 否 | 动画播放的时长,单位毫秒,默认为0。 | - | easing | string | 否 | 动画插值曲线,默认为' ease '。 | - | delay | number | 否 | 动画延时播放时长,单位毫秒,默认为0,即不延时。 | - | fill | string | 否 | 动画启停模式,默认值none,详情见:[animation-fill-mode](/pages/010c0201010105) | - | direction | string | 否 | 动画播放模式,默认值normal,详情见:[animation-direction](/pages/010c0201010105) | - | iterations | number | 否 | 动画播放次数,默认值1,设置为0时不播放,设置为-1时无限次播放。 | - | begin | number | 否 | 动画插值起点,不设置时默认为0。 | - | end | number | 否 | 动画插值终点,不设置时默认为1。 | - -- animator支持的接口 - | 参数名 | 类型 | 说明 | - | -------- | -------- | -------- | - | update | options | 过程中可以使用这个接口更新动画参数,入参与createAnimator一致。 | - | play | - | 开始动画。 | - | finish | - | 结束动画。 | - | pause | - | 暂停动画。 | - | cancel | - | 取消动画。 | - | reverse | - | 倒播动画。 | - -- animator支持的事件: - | 参数名 | 类型 | 说明 | - | -------- | -------- | -------- | - | frame | number | 逐帧插值回调事件,入参为当前帧的插值 | - | cancel | - | 动画被强制取消 | - | finish | - | 动画播放完成 | - | repeat | - | 动画重新播放 | - -- 示例 - ``` - -
-
-
-
- ``` - - ``` - // js - export default { - data : { - divWidth: 200, - divHeight: 200, - animator: null - }, - onInit() { - var options = { - duration: 1500, - easing: 'friction', - fill: 'forwards', - iterations: 2, - begin: 200.0, - end: 400.0 - }; - this.animator = animator.createAnimator(options); - }, - Show() { - var options1 = { - duration: 2000, - easing: 'friction', - fill: 'forwards', - iterations: 1, - begin: 200.0, - end: 400.0 - }; - this.animator.update(options1); - var _this = this; - this.animator.onframe = function(value) { - _this.divWidth = value; - _this.divHeight = value; - }; - this.animator.play(); - } - } - ``` diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/11.\345\237\272\346\234\254\345\212\237\350\203\275/09.\345\272\224\347\224\250\346\211\223\347\202\271.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/11.\345\237\272\346\234\254\345\212\237\350\203\275/09.\345\272\224\347\224\250\346\211\223\347\202\271.md" deleted file mode 100644 index 528427ecb377181128096f4b242d7e092bc2d2f8..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/11.\345\237\272\346\234\254\345\212\237\350\203\275/09.\345\272\224\347\224\250\346\211\223\347\202\271.md" +++ /dev/null @@ -1,163 +0,0 @@ ---- -title: 应用打点 -permalink: /pages/010c010b09 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 应用打点 - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import hiAppEvent from '@ohos.hiAppEvent'; -``` - - -## 系统能力 - -SystemCapability.HiviewDFX.HiAppEvent - - -## hiAppEvent.write - -write(eventName: string, eventType: EventType, keyValues: object, callback: AsyncCallback<void>): void - -应用事件打点方法,将事件写入到当天的事件文件中,可接收类型为Json对象的事件参数,使用callback方式作为异步回调。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | eventName | string | 是 | 应用事件名称。 | - | eventType | [EventType](#eventtype) | 是 | 应用事件类型。 | - | keyValues | object | 是 | 应用事件的参数,key类型只能为string,value类型只能为string、number、boolean、Array(数组数据类型只能为string、number、boolean)。 | - | callback | AsyncCallback<void> | 否 | 回调函数,可以在回调函数中处理接口返回值。
- 返回值为0表示事件校验成功,事件正常异步写入事件文件;
- 大于0表示事件校验存在异常参数,在忽略异常参数后将事件异步写入事件文件;
- 小于0表示事件校验失败,不将事件写入事件文件。 | - -- 示例: - ``` - hiAppEvent.write("test_event", hiAppEvent.EventType.FAULT, {"int_data":100, "str_data":"strValue"}, (err, value) => { - if (err) { - // 事件写入异常:事件存在异常参数时忽略异常参数后继续写入,或者事件校验失败时不执行写入 - console.error(`failed to write event because ${err.code}`); - return; - } - - // 事件写入正常 - console.log(`success to write event: ${value}`); - }); - ``` - - -## hiAppEvent.write - -write(eventName: string, eventType: EventType, keyValues: object): Promise<void> - -应用事件打点方法,将事件写入到当天的事件文件中,可接收类型为Json对象的事件参数,使用promise方式作为异步回调。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | eventName | string | 是 | 应用事件名称。 | - | eventType | [EventType](#eventtype) | 是 | 应用事件类型。 | - | keyValues | object | 是 | 应用事件的参数,key类型只能为string,value类型只能为string、number、boolean、Array(数组数据类型只能为string、number、boolean)。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | Promise实例,可以在其then()、catch()方法中分别对事件写入成功、写入异常的情况进行回调处理。 | - -- 示例: - ``` - hiAppEvent.write("test_event", hiAppEvent.EventType.FAULT, {"int_data":100, "str_data":"strValue"}) - .then((value) => { - // 事件写入正常 - console.log(`success to write event: ${value}`); - }).catch((err) => { - // 事件写入异常:事件存在异常参数时忽略异常参数后继续写入,或者事件校验失败时不执行写入 - console.error(`failed to write event because ${err.code}`); - }); - ``` - - -## hiAppEvent.configure - -configure(config: ConfigOption): boolean - -应用事件打点配置方法,可用于配置打点开关、文件目录存储限额大小等功能。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | config | [ConfigOption](#configoption) | 是 | 应用事件打点配置项对象。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 配置结果,true 表示配置成功,false 表示配置失败。 | - -- 示例: - ``` - // 配置应用事件打点功能开关 - hiAppEvent.configure({ - disable: true - }); - - // 配置事件文件目录存储限额大小 - hiAppEvent.configure({ - maxStorage: '100M' - }); - ``` - - -## ConfigOption - -此接口提供了应用打点的配置选项。 - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| disable | boolean | 否 | 应用打点功能开关。配置值为true表示关闭打点功能,false表示不关闭打点功能。 | -| maxStorage | string | 否 | 打点数据本地存储文件所在目录的配额大小,默认限额为“10M”。所在目录大小超出限额后会对目录进行清理操作,会按从旧到新的顺序逐个删除打点数据文件,直到目录大小不超出限额时停止。 | - - -## EventType - -事件类型枚举。 - -| 名称 | 默认值 | 说明 | -| -------- | -------- | -------- | -| FAULT | 1 | 故障类型事件。 | -| STATISTIC | 2 | 统计类型事件。 | -| SECURITY | 3 | 安全类型事件。 | -| BEHAVIOR | 4 | 行为类型事件。 | - - -## Event - -此接口提供了所有预定义事件的事件名称常量。 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| USER_LOGIN | string | 是 | 否 | 用户登录事件。 | -| USER_LOGOUT | string | 是 | 否 | 用户登出事件。 | -| DISTRIBUTED_SERVICE_START | string | 是 | 否 | 分布式服务启动事件。 | - - -## Param - -此接口提供了所有预定义参数的参数名称常量。 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| USER_ID | string | 是 | 否 | 用户自定义ID。 | -| DISTRIBUTED_SERVICE_NAME | string | 是 | 否 | 分布式服务名称。 | -| DISTRIBUTED_SERVICE_INSTANCE_ID | string | 是 | 否 | 分布式服务实例ID。 | diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/11.\345\237\272\346\234\254\345\212\237\350\203\275/10.\346\200\247\350\203\275\346\211\223\347\202\271.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/11.\345\237\272\346\234\254\345\212\237\350\203\275/10.\346\200\247\350\203\275\346\211\223\347\202\271.md" deleted file mode 100644 index f876c63fb936da7e8f3906e6d5215a494aeade27..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/11.\345\237\272\346\234\254\345\212\237\350\203\275/10.\346\200\247\350\203\275\346\211\223\347\202\271.md" +++ /dev/null @@ -1,120 +0,0 @@ ---- -title: 性能打点 -permalink: /pages/010c010b0a -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:29 ---- -# 性能打点 - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import bytrace from '@ohos.bytrace'; -``` - - -## 权限 - -无 - - -## bytrace.startTrace - -startTrace(name: string, taskId: number, expectedTime?: number): void - -标记一个预追踪耗时任务的开始,expectedTime是可选参数,标识该任务的期望耗时。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | name | string | 是 | 要追踪的任务名称 | - | taskId | number | 是 | 任务id | - | expectedTime | number | 否 | 期望的耗时时间,单位:ms | - - > ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** - > 如果有多个相同name的任务需要追踪或者对同一个任务要追踪多次,并且这些会同时被执行,则每次调用startTrace的taskId必须不一致。如果具有相同name的任务是串行执行的,则taskId可以相同。在下面bytrace.finishTrace的示例中会举例说明。 - -- 示例: - ``` - bytrace.startTrace("myTestFunc", 1); - bytrace.startTrace("myTestFunc", 1, 5); //从startTrace到finishTrace流程的耗时期望为5ms - ``` - - -## bytrace.finishTrace - -finishTrace(name: string, taskId: number): void - -标记一个预追踪耗时任务的结束。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | name | string | 是 | 要追踪的任务名称 | - | taskId | number | 是 | 任务id | - - > ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** - > finishTrace的name和taskId必须与流程开始的startTrace对应参数值一致。 - -- 示例: - ``` - bytrace.finishTrace("myTestFunc", 1); - ``` - - ``` - //追踪并行执行的同名任务 - bytrace.startTrace("myTestFunc", 1); - //业务流程...... - bytrace.startTrace("myTestFunc", 2); //第二个追踪的任务开始,同时第一个追踪的同名任务还没结束,出现了并行执行,对应接口的taskId需要不同。 - //业务流程...... - bytrace.finishTrace("myTestFunc", 1); - //业务流程...... - bytrace.finishTrace("myTestFunc", 2); - ``` - - ``` - //追踪串行执行的同名任务 - bytrace.startTrace("myTestFunc", 1); - //业务流程...... - bytrace.finishTrace("myTestFunc", 1); //第一个追踪的任务结束 - //业务流程...... - bytrace.startTrace("myTestFunc", 1); //第二个追踪的同名任务开始,同名的待追踪任务串行执行。 - //业务流程...... - bytrace.finishTrace("myTestFunc", 1); - ``` - - -## bytrace.traceByValue - -traceByValue(name: string, value: number): void - -用来标记一个预追踪的数值变量,该变量的数值会不断变化。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | name | string | 是 | 要追踪的数值变量名称 | - | value | number | 是 | 变量的值 | - -- 示例: - ``` - let traceCount = 3; - bytrace.traceByValue("myTestCount", traceCount); - traceCount = 4; - bytrace.traceByValue("myTestCount", traceCount); - //业务流程...... - ``` diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/11.\345\237\272\346\234\254\345\212\237\350\203\275/11.\346\225\205\351\232\234\346\227\245\345\277\227\350\216\267\345\217\226.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/11.\345\237\272\346\234\254\345\212\237\350\203\275/11.\346\225\205\351\232\234\346\227\245\345\277\227\350\216\267\345\217\226.md" deleted file mode 100644 index d931bec6c9946d011b2d7a7a2c4cb938df061190..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/11.\345\237\272\346\234\254\345\212\237\350\203\275/11.\346\225\205\351\232\234\346\227\245\345\277\227\350\216\267\345\217\226.md" +++ /dev/null @@ -1,124 +0,0 @@ ---- -title: 故障日志获取 -permalink: /pages/010c010b0b -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# 故障日志获取 -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - -## 导入模块 - -``` -import faultLogger from '@ohos.faultLogger' -``` - -## 权限 - -无 - -## FaultType - -故障类型枚举 - -| 名称 | 默认值 | 说明 | -| -------- | -------- | -------- | -| NO_SPECIFIC | 0 | 不区分故障类型 | -| CPP_CRASH | 2 | C++程序故障类型 | -| JS_CRASH | 3 | JS程序故障类型 | -| APP_FREEZE | 4 | 应用程序卡死故障类型 | - -## FaultLogInfo - -故障信息数据结构,获取到的故障信息的数据结构 - -| 名称 | 参数类型 | 说明 | -| -------- | -------- | -------- | -| pid | number | 故障进程的进程id | -| uid | number | 故障进程的用户id | -| type | [FaultType](#faulttype) | 故障类型 | -| timestamp | number | 日志生成时的秒级时间戳 | -| reason | string | 发生故障的原因 | -| module | string | 发生故障的模块 | -| summary | string | 故障的概要 | -| fullLog | string | 故障日志全文 | - -## faultLogger.querySelfFaultLog - -querySelfFaultLog(faultType: FaultType, callback: AsyncCallback<Array<FaultLogInfo>>) : void - -获取当前进程故障信息,该方法通过回调方式获取故障信息数组,故障信息数组内最多上报10份故障信息。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | faultType | [FaultType](#faulttype) | 是 | 输入要查询的故障类型。 | - | callback | AsyncCallbackArray<Array<[FaultLogInfo](#faultloginfo)>> | 是 | 回调函数,在回调函数中获取故障信息数组。
- value拿到故障信息数组;value为undefined表示获取过程中出现异常,error返回错误提示字符串 - -- 示例: -``` -function queryFaultLogCallback(error, value) { - if (error) { - console.info('error is ' + error); - } else { - console.info("value length is " + value.length); - let len = value.length; - for (let i = 0; i < len; i++) { - console.info("log: " + i); - console.info("Log pid: " + value[i].pid); - console.info("Log uid: " + value[i].uid); - console.info("Log type: " + value[i].type); - console.info("Log ts: " + value[i].ts); - console.info("Log reason: " + value[i].reason); - console.info("Log module: " + value[i].module); - console.info("Log summary: " + value[i].summary); - console.info("Log text: " + value[i].fullLog); - } - } -} -faultLogger.querySelfFaultLog(faultlogger.FaultType.JS_CRASH, queryFaultLogCallback); -``` - -## faultLogger.querySelfFaultLog - -querySelfFaultLog(faultType: FaultType) : Promise<Array<FaultLogInfo>>; - -获取当前进程故障信息,该方法通过Promise方式返回故障信息数组,故障信息数组内最多上报10份故障信息。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | faultType | [FaultType](#faulttype) | 是 | 输入要查询的故障类型。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<Array<[FaultLogInfo](#faultloginfo)>> | Promise实例,可以在其then()方法中获取故障信息实例,也可以使用await。
- value拿到故障信息数组;value为undefined表示获取过程中出现异常 | - -- 示例: -``` -let value = await faultLogger.querySelfFaultLog(faultlogger.FaultType.JS_CRASH); -if (value) { - console.info("value length is " + value.length); - let len = value.length; - for (let i = 0; i < len; i++) { - console.info("log: " + i); - console.info("Log pid: " + value[i].pid); - console.info("Log uid: " + value[i].uid); - console.info("Log type: " + value[i].type); - console.info("Log ts: " + value[i].ts); - console.info("Log reason: " + value[i].reason); - console.info("Log module: " + value[i].module); - console.info("Log summary: " + value[i].summary); - console.info("Log text: " + value[i].fullLog); - } -} -``` \ No newline at end of file diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/12.\350\257\255\350\250\200\345\237\272\347\241\200\347\261\273\345\272\223/01.\350\216\267\345\217\226\350\277\233\347\250\213\347\233\270\345\205\263\347\232\204\344\277\241\346\201\257.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/12.\350\257\255\350\250\200\345\237\272\347\241\200\347\261\273\345\272\223/01.\350\216\267\345\217\226\350\277\233\347\250\213\347\233\270\345\205\263\347\232\204\344\277\241\346\201\257.md" deleted file mode 100644 index a5b4e2f1f58ec8abcee5da73d6c1c0895b7d5844..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/12.\350\257\255\350\250\200\345\237\272\347\241\200\347\261\273\345\272\223/01.\350\216\267\345\217\226\350\277\233\347\250\213\347\233\270\345\205\263\347\232\204\344\277\241\346\201\257.md" +++ /dev/null @@ -1,529 +0,0 @@ ---- -title: 获取进程相关的信息 -permalink: /pages/010c010c01 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# 获取进程相关的信息 - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import process from '@ohos.process'; -``` - - -## 属性 - -| 名称 | 类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| egid | number | 是 | 否 | 进程的有效组标识。 | -| euid | number | 是 | 否 | 进程的有效用户身份。 | -| gid | number | 是 | 否 | 进程的组标识。 | -| uid | number | 是 | 否 | 进程的用户标识。 | -| groups | number[] | 是 | 否 | 带有补充组id的数组。 | -| pid | number | 是 | 否 | 当前进程的pid。 | -| ppid | number | 是 | 否 | 当前进程的父进程的pid。 | -| tid8+ | number | 是 | 否 | 当前进程的tid。 | - - -## ChildProcess - -主进程可以获取子进程的标准输入输出,以及发送信号和关闭子进程。 - - -### 属性 - -| 名称 | 类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| pid | number | 是 | 否 | 子进程的pid。 | -| ppid | number | 是 | 否 | 子进程的父进程的pid。 | -| exitCode | number | 是 | 否 | 子进程的退出码。 | -| killed | boolean | 是 | 否 | 父进程给子进程发信号是否成功。 | - - -### wait - -wait(): Promise<number> - -等待子进程运行结束,返回promise对象,其值为子进程的退出码。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<number> | 异步返回子进程的退出码。 | - -- 示例: - ``` - var child = process.runCmd('ls'); - var result = child.wait(); - result.then(val=>{ - console.log("result = " + val); - }) - ``` - - -### getOutput - -getOutput(): Promise<Uint8Array> - -获取子进程的标准输出。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<Uint8Array> | 异步返回标准输出的字节流。 | - -- 示例: - ``` - var child = process.runCmd('ls'); - var result = child.wait(); - child.getOutput.then(val=>{ - console.log("child.getOutput = " + val); - }) - ``` - - -### getErrorOutput - -getErrorOutput(): Promise<Uint8Array> - -getErrorOutput函数用来获取子进程的标准错误输出。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<Uint8Array> | 异步返回标准错误输出的字节流。 | - -- 示例: - ``` - var child = process.runCmd('madir test.text'); - var result = child.wait(); - child.getErrorOutput.then(val=>{ - console.log("child.getErrorOutput= " + val); - }) - ``` - - -### close - -close(): void - -关闭正在运行的子进程。 - -- 示例: - ``` - var child = process.runCmd('sleep 5; ls'); - child.close(); - ``` - - -### kill - -kill(signal: number | string): void - -kill函数用来发送信号给子进程,结束指定进程。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | signal | number \| string | 是 | 数字或字符串。 | - -- 示例: - ``` - var child = process.runCmd('sleep 5; ls'); - child.kill(9); - ``` - - -## process.isIsolatedProcess8+ - -isIsolatedProcess(): boolean - -判断进程是否被隔离。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 返回判断结果,如果返回true表示进程被隔离。 | - -- 示例: - ``` - var result = process.isIsolatedProcess(); - ``` - - -## process.isAppUid8+ - -isAppUid(v:number): boolean - -判断uid是否属于应用程序。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | v | number | 是 | 应用程序的uid。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 返回判断结果,如果返回true表示为应用程序的uid。| - -- 示例: - ``` - var result = process.isAppUid(688); - ``` - - -## process.is64Bit8+ - -is64Bit(): boolean - -判断运行环境是否64位。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 返回判断结果,如果返回true表示为64位环境。 | - -- 示例: - ``` - var ressult = process.is64Bit(); - ``` - - -## process.getUidForName8+ - -getUidForName(v:string): number - -通过进程名获取进程uid。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | v | string | 是 | 进程名。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 返回进程uid。| - -- 示例: - ``` - var pres = process.getUidForName("tool") - ``` - - -## process.getThreadPriority8+ - -getThreadPriority(v:number): number - -根据指定的tid获取线程优先级。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | v | number | 是 | 指定的线程tid。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 返回线程的优先级。 | - -- 示例: - ``` - var tid = process.getTid(); - var pres = process.getThreadPriority(tid); - ``` - - -## process.getStartRealtime8+ - -getStartRealtime() :number - -获取从系统启动到进程启动所经过的实时时间(以毫秒为单位)。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 返回经过的实时时间。| - -- 示例: - ``` - var realtime = process.getStartRealtime(); - ``` - - -## process.getAvailableCores8+ - -getAvailableCores() :number[] - -获取多核设备上当前进程可用的CPU内核。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number[] | 返回可用内核数。 | - -- 示例: - ``` - var result = getAvailableCores(); - ``` - - -## process.getPastCputime8+ - -getPastCputime() :number - -获取进程启动到当前时间的CPU时间(以毫秒为单位)。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 返回经过的CPU时间。 | - -- 示例: - ``` - var result = process.getPastCputime() ; - ``` - - -## process.getSystemConfig8+ - -getSystemConfig(name:number): number - -获取系统配置信息。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | name | number | 是 | 指定系统配置参数名。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 返回系统配置信息。 | - -- 示例: - ``` - var _SC_ARG_MAX = 0 - var pres = process.getSystemConfig(_SC_ARG_MAX) - ``` - - -## process.getEnvironmentVar8+ - -getEnvironmentVar(name:string): string - -用该方法获取环境变量对应的值。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | name | string | 是 | 环境变量名。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string | 返回环境变量名对应的value。 | - -- 示例: - ``` - var pres = process.getEnvironmentVar("PATH") - ``` - - -## process.runCmd - -runCmd(command: string, options?: { timeout : number, killSignal :number | string, maxBuffer : number }) : ChildProcess - -通过runcmd可以fork一个新的进程来运行一段shell,并返回ChildProcess对象。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | command | string | 是 | shell命令。 | - | options | Object | 否 | 相关选项参数。 | - - **表1** options - - | 名称 | 参数类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | timeout | number | 否 | 子进程运行的ms数,当子进程运行时间超出此时间,则父进程发送killSignal信号给子进程。timeout默认为0。 | - | killSignal | number  \| string | 否 | 子进程运行时间超出timeout时,父进程发送killSignal 信号给子进程。killSignal 默认为'SIGTERM'。 | - | maxBuffer | number | 否 | 子进程标准输入输出的最大缓冲区大小,当超出此大小时则终止子进程。maxBuffer默认1024\*1024。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [ChildProcess](#childprocess) | 子进程对象。 | - -- 示例: - ``` - var child = process.runCmd('ls', { maxBuffer : 2 }); - var result = child.wait(); - child.getOutput.then(val=>{ - console.log("child.getOutput = " + val); - }) - ``` - - -## process.abort - -abort(): void - -该方法会导致进程立即退出并生成一个核心文件,谨慎使用。 - -- 示例: - ``` - process.abort(); - ``` - - -## process.on - -on(type: string, listener: EventListener): void - -用该方法来存储用户所触发的事件。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | string | 是 | 存储事件的type。 | - | listener | EventListener | 是 | 回调的事件。 | - - **表2** EventListener - - | 名称 | 说明 | - | -------- | -------- | - | EventListener = (evt: Object) => void | 用户存储的事件。 | - -- 示例: - ``` - process.on("data", (e)=>{ - console.log("data callback"); - }) - ``` - - -## process.off - -off(type: string): boolean - -用该方法来删除用户存储的事件。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | string | 是 | 删除事件的type。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 事件是否删除成功。 | - -- 示例: - ``` - process.on("data", (e)=>{ - console.log("data callback"); - }) - var result = process.off("data"); - ``` - - -## process.exit - -exit(code: number): void - -用该方法终止程序,谨慎使用。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | code | number | 是 | 进程的退出码。 | - -- 示例: - ``` - process.exit(0); - ``` - - -## process.cwd - -cwd(): string - -用该方法获取进程的工作目录。 - -- 示例: - ``` - var path = process.cwd(); - ``` - - -## process.chdir - -chdir(dir: string): void - -用该方法更改进程的当前工作目录。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | dir | string | 是 | 路径。 | - -- 示例: - ``` - process.chdir('/system'); - ``` - - -## process.uptime - -uptime(): number - -获取当前系统已运行的秒数。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 当前系统已运行的秒数。 | - -- 示例: - ``` - var time = process.uptime(); - ``` - - -## process.kill - -kill(pid: number,signal: number ): boolean - -用该方法发送signal到指定的进程,结束指定进程。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | pid | number | 是 | 进程的id。 | - | signal | number | 是 | 发送的信号。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 信号是否发送成功。 | - -- 示例: - ``` - var pres = process.pid - var result = that.kill(pres, 28) - ``` diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/12.\350\257\255\350\250\200\345\237\272\347\241\200\347\261\273\345\272\223/02.URL\345\255\227\347\254\246\344\270\262\350\247\243\346\236\220.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/12.\350\257\255\350\250\200\345\237\272\347\241\200\347\261\273\345\272\223/02.URL\345\255\227\347\254\246\344\270\262\350\247\243\346\236\220.md" deleted file mode 100644 index 02a7d92e09f276ba147668050baac25b98c571ed..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/12.\350\257\255\350\250\200\345\237\272\347\241\200\347\261\273\345\272\223/02.URL\345\255\227\347\254\246\344\270\262\350\247\243\346\236\220.md" +++ /dev/null @@ -1,429 +0,0 @@ ---- -title: URL字符串解析 -permalink: /pages/010c010c02 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# URL字符串解析 - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import Url from '@ohos.url' -``` - - -## URLSearchParams - - -### constructor - -constructor(init?: string[][] | Record<string, string> | string | URLSearchParams) - -URLSearchParams的构造函数。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | init | string[][] \| Record<string, string> \| string \| URLSearchParams | 否 | 入参对象。
- string[][]:字符串二维数组
- Record<string, string>:对象列表
- string:字符串
- URLSearchParams:对象 | - -- 示例: - ``` - var objectParams = new URLSearchParams([ ['user1', 'abc1'], ['query2', 'first2'], ['query3', 'second3'] ]); - var objectParams1 = new URLSearchParams({"fod" : 1 , "bard" : 2}); - var objectParams2 = new URLSearchParams('?fod=1&bard=2'); - var urlObject = new URL('https://developer.mozilla.org/?fod=1&bard=2'); - var params = new URLSearchParams(urlObject .search); - ``` - - -### append - -append(name: string, value: string): void - -将新的键值对插入到查询字符串。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | name | string | 是 | 需要插入搜索参数的键名。 | - | value | string | 是 | 需要插入搜索参数的值。 | - -- 示例: - ``` - let urlObject = new URL('https://developer.exampleUrl/?fod=1&bard=2'); - let paramsObject = new URLSearchParams(urlObject.search.slice(1)); - paramsObject.append('fod', 3); - ``` - - -### delete - -delete(name: string): void - -删除指定名称的键值对。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | name | string | 是 | 需要删除的键值名称。 | - -- 示例: - ``` - let urlObject = new URL('https://developer.exampleUrl/?fod=1&bard=2'); - let paramsobject = new URLSearchParams(urlObject.search.slice(1)); - paramsobject.delete('foo'); - ``` - - -### getAll - -getAll(name: string): string[] - -获取指定名称的所有键值对。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | name | string | 是 | 指定的键值名称。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string[] | 返回指定名称的所有键值对。 | - -- 示例: - ``` - let urlObject = new URL('https://developer.exampleUrl/?fod=1&bard=2'); - let paramsObject = new URLSearchParams(urlObject.search.slice(1)); - paramsObject.append('fod', 3); // Add a second value for the foo parameter. - console.log(params.getAll('fod')) // Output ["1","3"]. - ``` - - -### entries - -entries(): IterableIterator<[string, string]> - -返回一个ES6的迭代器,迭代器的每一项都是一个 JavaScript Array。Array的第一项是name,Array的第二项是value。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | IterableIterator<[string, string]> | 返回一个ES6的迭代器。 | - -- 示例: - ``` - var searchParamsObject = new URLSearchParams("keyName1=valueName1&keyName2=valueName2"); - for (var pair of searchParamsObject .entries()) { // Show keyName/valueName pairs - console.log(pair[0]+ ', '+ pair[1]); - } - ``` - - -### forEach - -forEach(callbackfn: (value: string, key: string, searchParams: Object) => void, thisArg?: Object): void - -通过回调函数来遍历URLSearchParams实例对象上的键值对。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callbackfn | function | 是 | 回调函数。 | - | thisArg | Object | 否 | callbackfn被调用时用作this值 | - - **表1** callbackfn的参数说明 - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | string | 是 | 当前遍历到的键值。 | - | key | string | 是 | 当前遍历到的键名。 | - | searchParams | Object | 是 | 当前调用forEach方法的实例对象。 | - -- 示例: - ``` - const myURLObject = new URL('https://developer.exampleUrl/?fod=1&bard=2'); - myURLObject.searchParams.forEach((value, name, searchParams) => { - console.log(name, value, myURLObject.searchParams === searchParams); - }); - ``` - - -### get - -get(name: string): string | null - -获取指定名称对应的第一个值。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | name | string | 是 | 指定键值对的名称。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string | 返回第一个值。 | - | null | 如果没找到,返回 null。 | - -- 示例: - ``` - var paramsOject = new URLSearchParams(document.location.search.substring(1)); - var name = paramsOject.get("name"); // is the string "Jonathan" - var age = parseInt(paramsOject.get("age"), 10); // is the number 18 - var address = paramsOject.get("address"); // null - ``` - - -### has - -has(name: string): boolean - -判断一个指定的键名对应的值是否存在。 -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | name | string | 是 | 要查找的参数的键名。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 是否存在相对应的key值,存在返回true,否则返回false。 | - -- 示例: - ``` - let urlObject = new URL('https://developer.exampleUrl/?fod=1&bard=2'); - let paramsObject = new URLSearchParams(urlObject.search.slice(1)); - paramsObject.has('bard') === true; - ``` - - -### set - -set(name: string, value: string): void - -将与name关联的URLSearchParams对象中的值设置为value。如果存在名称为name的键值对,请将第一个键值对的值设置为value并删除所有其他值。如果不是,则将键值对附加到查询字符串。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | name | string | 是 | 将要设置的参数的键值名。 | - | value | string | 是 | 所要设置的参数值。 | - -- 示例: - ``` - let urlObject = new URL('https://developer.exampleUrl/?fod=1&bard=2'); - let paramsObject = new URLSearchParams(urlObject.search.slice(1)); - paramsObject.set('baz', 3); // Add a third parameter. - ``` - - -### sort - -sort(): void - - -对包含在此对象中的所有键值对进行排序,并返回undefined。排序顺序是根据键的Unicode代码点。该方法使用稳定的排序算法 (即,将保留具有相等键的键值对之间的相对顺序)。 - - -- 示例: - ``` - var searchParamsObject = new URLSearchParams("c=3&a=9&b=4&d=2"); // Create a test URLSearchParams object - searchParamsObject.sort(); // Sort the key/value pairs - console.log(searchParamsObject.toString()); // Display the sorted query string // Output a=9&b=2&c=3&d=4 - ``` - - -### keys - -keys(): IterableIterator<string> - - -返回一个所有键值对的name的ES6迭代器。 - - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | IterableIterator<string> | 返回一个所有键值对的name的ES6迭代器。 | - - -- 示例: - ``` - var searchParamsObject = new URLSearchParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing - for (var key of searchParamsObject .keys()) { // Output key-value pairs - console.log(key); - } - ``` - - -### values - -values(): IterableIterator<string> - -返回一个所有键值对的value的ES6迭代器。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | IterableIterator<string> | 返回一个所有键值对的value的ES6迭代器。 | - -- 示例 - ``` - var searchParams = new URLSearchParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing - for (var value of searchParams.values()) { - console.log(value); - } - ``` - - -### [Symbol.iterator] - -[Symbol.iterator](): IterableIterator<[string, string]> - - -返回一个ES6的迭代器,迭代器的每一项都是一个 JavaScript Array。Array的第一项是name,Array的第二项是value。 - - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | IterableIterator<[string, string]> | 返回一个ES6的迭代器。 | - - -- 示例: - ``` - const paramsObject = new URLSearchParams('fod=bay&edg=bap'); - for (const [name, value] of paramsObject) { - console.log(name, value); - } - ``` - - -### tostring - -toString(): string - - -返回序列化为字符串的搜索参数,必要时对字符进行百分比编码。 - - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string | 返回序列化为字符串的搜索参数,必要时对字符进行百分比编码。 | - - -- 示例: - ``` - let url = new URL('https://developer.exampleUrl/?fod=1&bard=2'); - let params = new URLSearchParams(url.search.slice(1)); - params.append('fod', 3); - console.log(params.toString()); - ``` - - -## URL - - -### 属性 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| hash | string | 是 | 是 | 获取和设置URL的片段部分。 | -| host | string | 是 | 是 | 获取和设置URL的主机部分。 | -| hostname | string | 是 | 是 | 获取和设置URL的主机名部分,不带端口。 | -| href | string | 是 | 是 | 获取和设置序列化的URL。 | -| origin | string | 是 | 否 | 获取URL源的只读序列化。 | -| password | string | 是 | 是 | 获取和设置URL的密码部分。 | -| pathname | string | 是 | 是 | 获取和设置URL的路径部分。 | -| port | string | 是 | 是 | 获取和设置URL的端口部分。 | -| protocol | string | 是 | 是 | 获取和设置URL的协议部分。 | -| search | string | 是 | 是 | 获取和设置URL的序列化查询部分。 | -| searchParams | URLsearchParams | 是 | 否 | 获取URLSearchParams表示URL查询参数的对象。 | -| username | string | 是 | 是 | 获取和设置URL的用户名部分。 | - - -### constructor - -constructor(url: string, base?: string | URL) - - -URL的构造函数。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | url | string | 是 | 入参对象。 | - | base | string \| URL | 否 | 入参字符串或者对象。
- string:字符串
- URL:字符串或对象 | - - -- 示例: - ``` - var mm = 'http://username:password@host:8080'; - var a = new URL("/", mm); // Output 'http://username:password@host:8080/'; - var b = new URL(mm); // Output 'http://username:password@host:8080/'; - new URL('path/path1', b); // Output 'http://username:password@host:8080/path/path1'; - var c = new URL('/path/path1', b); // Output 'http://username:password@host:8080/path/path1'; - new URL('/path/path1', c); // Output 'http://username:password@host:8080/path/path1'; - new URL('/path/path1', a); // Output 'http://username:password@host:8080/path/path1'; - new URL('/path/path1', "https://www.exampleUrl/fr-FR/toto"); // Output https://www.exampleUrl/path/path1 - new URL('/path/path1', ''); // Raises a TypeError exception as '' is not a valid URL - new URL('/path/path1'); // Raises a TypeError exception as '/path/path1' is not a valid URL - new URL('http://www.shanxi.com', ); // Output http://www.shanxi.com/ - new URL('http://www.shanxi.com', b); // Output http://www.shanxi.com/ - ``` - - -### tostring - -toString(): string - -将解析过后的URL转化为字符串。 - - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string | 用于返回网址的字符串序列化。 | - - -- 示例: - ``` - const url = new URL('http://username:password@host:8080/directory/file?query=pppppp#qwer=da'); - url.toString() - ``` - - -### toJSON - -toJSON(): string - - -将解析过后的URL转化为JSON字符串。 - - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string | 用于返回网址的字符串序列化。 | - - -- 示例: - ``` - const url = new URL('http://username:password@host:8080/directory/file?query=pppppp#qwer=da'); - url.toJSON() - ``` diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/12.\350\257\255\350\250\200\345\237\272\347\241\200\347\261\273\345\272\223/03.URI\345\255\227\347\254\246\344\270\262\350\247\243\346\236\220.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/12.\350\257\255\350\250\200\345\237\272\347\241\200\347\261\273\345\272\223/03.URI\345\255\227\347\254\246\344\270\262\350\247\243\346\236\220.md" deleted file mode 100644 index 36c6fe03a766c59241647cb43b3a56af64f77bd0..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/12.\350\257\255\350\250\200\345\237\272\347\241\200\347\261\273\345\272\223/03.URI\345\255\227\347\254\246\344\270\262\350\247\243\346\236\220.md" +++ /dev/null @@ -1,140 +0,0 @@ ---- -title: URI字符串解析 -permalink: /pages/010c010c03 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# URI字符串解析 - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import uri from '@ohos.uri' -``` - -## URI - - -### 属性 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| scheme | string | 是 | 否 | 获取URI 的协议部分。 | -| userinfo | string | 是 | 否 | 获取 URI 的用户信息部分。 | -| host | string | 是 | 否 | 获取 URI 的主机名部分(不带端口)。 | -| port | string | 是 | 否 | 获取 URI 的端口部分。 | -| path | string | 是 | 否 | 获取 URI 的路径部分。 | -| query | string | 是 | 否 | 获取 URI 的查询部分。 | -| fragment | string | 是 | 否 | 获取 URI 的片段部分 | -| authority | string | 是 | 否 | 获取此URI的解码权限组件部分。 | -| ssp | string | 是 | 否 | 获取URI的解码方案特定部分。 | - - -### constructor - -constructor(uri: string) - -constructor是URI的构造函数。 - -- 参数: - | 参数名 | 类型 | 可读 | 可写 | 说明 | - | -------- | -------- | -------- | -------- | -------- | - | url | string | 是 | 是 | 入参对象。 | - -- 示例: - ``` - var mm = 'http://username:password@host:8080/directory/file?foo=1&bar=2#fragment'; - new uri.URI(mm); // Output 'http://username:password@host:8080/directory/file?foo=1&bar=2#fragment'; - ``` - ``` - new uri.URI('http://username:password@host:8080'); // Output 'http://username:password@host:8080'; - ``` - - -### toString - -toString(): string - -返回适用于URL中的查询字符串。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string | 返回网址的字符串序列化。 | - -- 示例: - ``` - const url = new uri.URL('http://username:password@host:8080/directory/file?query=pppppp#qwer=da'); - url.toString() - ``` - - -### equals - -equals(other: URI): boolean - -判断此URI是否与其他URI对象相等。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | other | [URI](#uri) | 是 | 需要比较的URI对象。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 返回true表示相等,否则返回false。 | - -- 示例: - ``` - const uriInstance = new uri.URI('http://username:password@host:8080/directory/file?query=pppppp#qwer=da'); - const uriInstance1 = new uri.URI('http://username:password@host:8080/directory/file?query=pppppp#qwer=da#fragment'); - uriInstance.equals(uriInstance1); - ``` - -### checkIsAbsolute - -checkIsAbsolute(): boolean - -判断此URI是否为绝对URI(是否定义了scheme组件)。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 返回true表示该URI是否为绝对URI。 | - -- 示例: - ``` - const uriInstance = new uri.URI('http://username:password@www.qwer.com:8080?query=pppppp'); - uriInstance.checkIsAbsolute(); - ``` - - -### normalize - -normalize(): URI - -规范化此URI的路径。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | URI | 返回一个path被规范化后的URI对象。 | - -- 示例: - ``` - const uriInstance = new uri.URI('http://username:password@www.qwer.com:8080/path/path1/../path2/./path3?query=pppppp'); - let uriInstance1 = uriInstance.normalize(); - uriInstance1.path; - ``` diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/12.\350\257\255\350\250\200\345\237\272\347\241\200\347\261\273\345\272\223/04.util\345\267\245\345\205\267\345\207\275\346\225\260.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/12.\350\257\255\350\250\200\345\237\272\347\241\200\347\261\273\345\272\223/04.util\345\267\245\345\205\267\345\207\275\346\225\260.md" deleted file mode 100644 index 103f6fa9de97747bd6d0deab8308c13f427e1d2f..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/12.\350\257\255\350\250\200\345\237\272\347\241\200\347\261\273\345\272\223/04.util\345\267\245\345\205\267\345\207\275\346\225\260.md" +++ /dev/null @@ -1,2336 +0,0 @@ ---- -title: util工具函数 -permalink: /pages/010c010c04 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# util工具函数 - - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -该模块主要提供常用的工具函数,实现字符串编解码(TextEncoder,TextDecoder)、有理数运算(RationalNumber)、缓冲区管理(LruBuffer)、范围判断(Scope)、Base64编解码(Base64)、内置对象类型检查(Types)等功能。 - - -## 导入模块 - -``` -import util from '@ohos.util'; -``` - - -## util.printf - -printf(format: string, ...args: Object[]): string - -通过式样化字符串对输入的内容按特定格式输出。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | format | string | 是 | 式样化字符串。 | - | ...args | Object[] | 否 | 待式样化数据。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string | 按特定格式式样化后的字符串。 | - -- 示例: - ``` - var res = util.printf("%s", "hello world!"); - console.log(res); - ``` - - -## util.getErrorString - -getErrorString(errno: number): string - -获取系统错误码对应的详细信息。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | errno | number | 是 | 系统发生错误产生的错误码。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string | 错误码对应的详细信息。 | - -- 示例: - ``` - var errnum = 10; // 10:a system error number - var result = util.getErrorString(errnum); - console.log("result = " + result); - ``` - - -## util.callbackWrapper - -callbackWrapper(original: Function): (err: Object, value: Object )=>void - -对异步函数进行回调化处理,回调中第一个参数将是拒绝原因(如果 Promise 已解决,则为 null),第二个参数将是已解决的值。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | original | Function | 是 | 异步函数。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Function | 返回一个第一个参数是拒绝原因(如果 Promise 已解决,则为 null),第二个参数是已解决的回调函数。 | - -- 示例: - ``` - async function promiseFn() { - return Promise.reject('value'); - } - var cb = util.callbackWrapper(promiseFn); - cb((err, ret) => { - expect(err).strictEqual('value'); - expect(ret).strictEqual(undefined); - }) - ``` - - -## util.promiseWrapper - -promiseWrapper(original: (err: Object, value: Object) => void): Object - -对异步函数处理并返回一个promise的版本。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | original | Function | 是 | 异步函数。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Function | 采用遵循常见的错误优先的回调风格的函数(也就是将 (err, value) => ... 回调作为最后一个参数),并返回一个返回 promise 的版本。 | - -- 示例: - ``` - function aysnFun(str1, str2, callback) { - if (typeof str1 === 'string' && typeof str2 === 'string') { - callback(null, str1 + str2); - } else { - callback('type err'); - } - } - let newPromiseObj = util.promiseWrapper(aysnFun)("Hello", 'World'); - newPromiseObj.then(res => { - expect(res).strictEqual('HelloWorld'); - }) - ``` - - -## TextDecoder - - -### 属性 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| encoding | string | 是 | 否 | 编码格式。
- 支持格式:utf-8、ibm866、iso-8859-2、iso-8859-3、iso-8859-4、iso-8859-5、iso-8859-6、iso-8859-7、iso-8859-8、iso-8859-8-i、iso-8859-10、iso-8859-13、iso-8859-14、iso-8859-15、koi8-r、koi8-u、macintosh、windows-874、windows-1250、windows-1251、windows-1252、windows-1253、windows-1254、windows-1255、windows-1256、windows-1257、windows-1258、x-mac-cyrilli、gbk、gb18030、big5、euc-jp、iso-2022-jp、shift_jis、euc-kr、utf-16be、utf-16le。 | -| fatal | boolean | 是 | 否 | 是否显示致命错误。 | -| ignoreBOM | boolean | 是 | 否 | 是否忽略BOM(byte order marker)标记,默认值为false ,表示解码结果包含BOM标记。 | - - -### constructor - -constructor(encoding?:string, options?:{ fatal?:boolean;ignoreBOM?:boolean }) - -TextDecoder的构造函数。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | encoding | string | 否 | 编码格式。 | - | options | Object | 否 | 编码相关选项参数,存在两个属性fatal和ignoreBOM。 | - - **表1** options - - | 名称 | 参数类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | fatal | boolean | 否 | 是否显示致命错误。 | - | ignoreBOM | boolean | 否 | 是否忽略BOM标记。 | - -- 示例: - ``` - var textDecoder = new util.TextDecoder("utf-8",{ignoreBOM:true}); - ``` - - -### decode - -decode(input: Unit8Array, options?:{stream?:false}):string - -通过输入参数解码后输出对应文本。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | input | Unit8Array | 是 | 符合格式需要解码的数组。 | - | options | Object | 否 | 解码相关选项参数。 | - - **表2** options - - | 名称 | 参数类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | stream | boolean | 否 | 在随后的decode()调用中是否跟随附加数据块。如果以块的形式处理数据,则设置为true;如果处理最后的数据块或数据未分块,则设置为false。默认为false。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string | 解码后的数据。 | - -- 示例: - ``` - var textDecoder = new util.TextDecoder("utf-8",{ignoreBOM:true}); - var result = new Uint8Array(6); - result[0] = 0xEF; - result[1] = 0xBB; - result[2] = 0xBF; - result[3] = 0x61; - result[4] = 0x62; - result[5] = 0x63; - console.log("input num:"); - for(var j= 0; j < 6; j++) { - console.log(result[j]); - } - var retStr = textDecoder.decode( result , {stream:false}); - console.log("retStr = " + retStr); - ``` - - -## TextEncoder - - -### 属性 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| encoding | string | 是 | 否 | 编码格式,默认值是utf-8。 | - - -### constructor - -constructor() - -TextEncoder的构造函数。 - -- 示例: - ``` - var textEncoder = new util.TextEncoder(); - ``` - - -### encode - -encode(input?:string):Uint8Array - -通过输入参数编码后输出对应文本。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | input | string | 是 | 需要编码的字符串。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Uint8Array | 返回编码后的文本。 | - -- 示例: - ``` - var textEncoder = new util.TextEncoder(); - var result = new Uint8Array(buffer); - result = textEncoder.encode("\uD800¥¥"); - ``` - - -### encodeInto - -encodeInto(input:string, dest:Uint8Array, ):{ read:number; written:number } - -放置生成的UTF-8编码文本。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | input | string | 是 | 需要编码的字符串。 | - | dest | Uint8Array | 是 | Uint8Array对象实例,用于将生成的UTF-8编码文本放入其中。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Uint8Array | 返回编码后的文本。 | - -- 示例: - ``` - var that = new util.TextEncoder(); - var buffer = new ArrayBuffer(4); - this.dest = new Uint8Array(buffer); - var result = that.encodeInto("abcd", this.dest); - ``` - -## RationalNumber8+ - - -### constructor8+ - -constructor(numerator:number,denominator:number) - -RationalNumber的构造函数。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | numerator | number | 是 | 分子,整数类型。 | - | denominator | number | 是 | 分母,整数类型。 | - -- 示例: - ``` - var rationalNumber = new util.RationalNumber(1,2); - ``` - - -### createRationalFromString8+ - -static createRationalFromString​(rationalString:string):RationalNumber​ - -基于给定的字符串创建一个RationalNumber对象。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | rationalString | string | 是 | 字符串格式。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | object | 返回有理数类的对象。 | - -- 示例: - ``` - var rationalNumber = new util.RationalNumber(1,2); - var rational = rationalNumer.creatRationalFromString("3/4"); - ``` - - -### compareTo8+ - -compareTo​(another:RationalNumber):number​ - -将当前的RationalNumber对象与给定的对象进行比较。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | another | RationalNumber | 是 | 其他的有理数对象。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 如果两个对象相等,则返回0;如果给定对象小于当前对象,则返回1;如果给定对象大于当前对象,则返回-1。 | - -- 示例: - ``` - var rationalNumber = new util.RationalNumber(1,2); - var rational = rationalNumer.creatRationalFromString("3/4"); - var result = rationalNumber.compareTo(rational); - ``` - - -### valueOf8+ - -valueOf():number - -以整数形式或者浮点数的形式获取当前RationalNumber对象的值。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 返回整数或者浮点数的值。 | - -- 示例: - ``` - var rationalNumber = new util.RationalNumber(1,2); - var result = rationalNumber.valueOf(); - ``` - - -### equals8+ - -equals​(obj:Object):boolean - -将当前的RationalNumber对象与给定的对象进行比较是否相等。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | object | Object | 是 | 其他类型对象。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 如果给定对象与当前对象相同,则返回true;否则返回false。 | - -- 示例: - ``` - var rationalNumber = new util.RationalNumber(1,2); - var rational = rationalNumer.creatRationalFromString("3/4"); - var result = rationalNumber.equals(rational); - ``` - - -### getCommonDivisor8+ - -static getCommonDivisor​(number1:number,number2:number):number - -获取两个指定整数的最大公约数。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | number1 | number | 是 | 整数类型。 | - | number2 | number | 是 | 整数类型。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 返回两个给定数字的最大公约数。 | - -- 示例: - ``` - var rationalNumber = new util.RationalNumber(1,2); - var result = rationalNumber.getCommonDivisor(4,6); - ``` - - -### getNumerator8+ - -getNumerator​():number - -获取当前RationalNumber对象的分子。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 返回RationalNumber对象的分子的值。 | - -- 示例: - ``` - var rationalNumber = new util.RationalNumber(1,2); - var result = rationalNumber.getNumerator(); - ``` - - -### getDenominator8+ - -getDenominator​():number - -获取当前RationalNumber对象的分母。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 返回RationalNumber对象的分母的值。 | - -- 示例: - ``` - var rationalNumber = new util.RationalNumber(1,2); - var result = rationalNumber.getDenominator(); - ``` - - -### isZero8+ - -isZero​():boolean - -检查当前RationalNumber对象是否为0。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 如果当前对象表示的值为0,则返回true;否则返回false。 | - -- 示例: - ``` - var rationalNumber = new util.RationalNumber(1,2); - var result = rationalNumber.isZero(); - ``` - - -### isNaN8+ - -isNaN​():boolean - -检查当前RationalNumber对象是否表示非数字(NaN)值。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 如果分母和分子都为0,则返回true;否则返回false。 | - -- 示例: - ``` - var rationalNumber = new util.RationalNumber(1,2); - var result = rationalNumber.isNaN(); - ``` - - -### isFinite8+ - -isFinite​():boolean - -检查当前RationalNumber对象是否表示一个有限值。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 如果分母不为0,则返回true;否则返回false。 | - -- 示例: - ``` - var rationalNumber = new util.RationalNumber(1,2); - var result = rationalNumber.isFinite(); - ``` - - -### toString8+ - -toString​():string - -获取当前RationalNumber对象的字符串表示形式。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string | 返回Numerator/Denominator格式的字符串,例如3/5,如果当前对象的分子和分母都为0,则返回NaN。 | - -- 示例: - ``` - var rationalNumber = new util.RationalNumber(1,2); - var result = rationalNumber.toString(); - ``` - -## LruBuffer8+ - - -### 属性 - -| 名称 | 类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| length | number | 是 | 否 | 当前缓冲区中值的总数。 | - -- 示例: - ``` - var pro = new util.LruBuffer(); - pro.put(2,10); - pro.put(1,8); - var result = pro.length; - ``` - - -### constructor8+ - -constructor(capacity?:number) - -默认构造函数用于创建一个新的LruBuffer实例,默认容量为64。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | capacity | number | 否 | 指示要为缓冲区自定义的容量。 | - -- 示例: - ``` - var lrubuffer= new util.LruBuffer(); - ``` - - -### updateCapacity8+ - -updateCapacity(newCapacity:number):void - -将缓冲区容量更新为指定容量,如果newCapacity小于或等于0,则抛出异常。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | newCapacity | number | 是 | 指示要为缓冲区自定义的容量。 | - -- 示例: - ``` - var pro = new util.LruBuffer(); - var result = pro.updateCapacity(100); - ``` - - -### toString8+ - -toString():string - -返回对象的字符串表示形式。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string | 返回对象的字符串表示形式。 | - -- 示例: - ``` - var pro = new util.LruBuffer(); - pro.put(2,10); - pro.get(2); - pro.remove(20); - var result = pro.toString(); - ``` - - -### getCapacity8+ - -getCapacity():number - -获取当前缓冲区的容量。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 返回当前缓冲区的容量。 | - -- 示例: - ``` - var pro = new util.LruBuffer(); - var result = pro.getCapacity(); - ``` - - -### clear8+ - -clear():void - -从当前缓冲区清除键值对。后续会调用afterRemoval()方法执行后续操作。 - -- 示例: - ``` - var pro = new util.LruBuffer(); - pro.put(2,10); - var result = pro.size(); - pro.clear(); - ``` - - -### getCreateCount8+ - -getCreateCount():number - -获取createDefault()返回值的次数。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 返回createDefault()返回值的次数。 | - -- 示例: - ``` - var pro = new util.LruBuffer(); - pro.put(1,8); - var result = pro.getCreateCount(); - ``` - - -### getMissCount8+ - -getMissCount():number - -获取查询值不匹配的次数。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 返回查询值不匹配的次数。 | - -- 示例: - ``` - var pro = new util.LruBuffer(); - pro.put(2,10); - pro.get(2); - var result = pro.getMissCount(); - ``` - - -### getRemovalCount8+ - -getRemovalCount():number - -获取从缓冲区中逐出值的次数。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 返回从缓冲区中驱逐的次数。 | - -- 示例: - ``` - var pro = new util.LruBuffer(); - pro.put(2,10); - pro.updateCapacity(2); - pro.put(50,22); - var result = pro.getRemovalCount(); - ``` - - -### getMatchCount8+ - -getMatchCount():number - -获取查询值匹配成功的次数。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 返回查询值匹配成功的次数。 | - -- 示例: - ``` - var pro = new util.LruBuffer(); - pro.put(2,10); - pro.get(2); - var result = pro.getMatchCount(); - ``` - - -### getPutCount8+ - -getPutCount():number - -获取将值添加到缓冲区的次数。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 返回将值添加到缓冲区的次数。 | - -- 示例: - ``` - var pro = new util.LruBuffer(); - pro.put(2,10); - var result = pro.getPutCount(); - ``` - - -### isEmpty8+ - -isEmpty():boolean - -检查当前缓冲区是否为空。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 如果当前缓冲区不包含任何值,则返回true。 | - -- 示例: - ``` - var pro = new util.LruBuffer(); - pro.put(2,10); - var result = pro.isEmpty(); - ``` - - -### get8+ - -get(key:K):V | undefined - -表示要查询的键。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | K | 是 | 要查询的键。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | V \| undefind | 如果指定的键存在于缓冲区中,则返回与键关联的值;否则返回undefined。 | - -- 示例: - ``` - var pro = new util.LruBuffer(); - pro.put(2,10); - var result = pro.get(2); - ``` - - -### put8+ - -put(key:K,value:V):V - -将键值对添加到缓冲区。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | K | 是 | 要添加的密钥。 | - | value | V | 是 | 指示与要添加的键关联的值。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | V | 返回与添加的键关联的值;如果要添加的键已经存在,则返回原始值,如果键或值为空,则抛出此异常。 | - -- 示例: - ``` - var pro = new util.LruBuffer(); - var result = pro.put(2,10); - ``` - - -### values8+ - -values():V[] - -获取当前缓冲区中所有值从最近访问到最近最少访问的顺序列表 。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | V [] | 按从最近访问到最近最少访问的顺序返回当前缓冲区中所有值的列表。 | - -- 示例: - ``` - var pro = new util.LruBuffer(); - pro.put(2,10); - pro.put(2,"anhu"); - pro.put("afaf","grfb"); - var result = pro.values(); - ``` - - -### keys8+ - -keys():K[] - -获取当前缓冲区中所有键从最近访问到最近最少访问的升序列表。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | K [] | 按升序返回当前缓冲区中所有键的列表,从最近访问到最近最少访问。 | - -- 示例: - ``` - var pro = new util.LruBuffer(); - pro.put(2,10); - var result = pro.keys(); - ``` - - -### remove8+ - -remove(key:K):V | undefined - -从当前缓冲区中删除指定的键及其关联的值。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | K | 是 | 要删除的密钥。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | V \| undefind | 返回一个包含已删除键值对的Optional对象;如果key不存在,则返回一个空的Optional对象,如果key为null,则抛出异常。 | - -- 示例: - ``` - var pro = new util.LruBuffer(); - pro.put(2,10); - var result = pro.remove(20); - ``` - - -### afterRemoval8+ - -afterRemoval(isEvict:boolean,key:K,value:V,newValue:V):void - -删除值后执行后续操作。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | isEvict | boolean | 否 | 因容量不足而调用该方法时,参数值为true,其他情况为false。 | - | key | K | 是 | 表示删除的键。 | - | value | V | 是 | 表示删除的值。 | - | newValue | V | 否 | 如果已调用put方法并且要添加的键已经存在,则参数值是关联的新值。其他情况下参数值为空。 | - -- 示例: - ``` - var arr = []; - class ChildLruBuffer extends util.LruBuffer - { - constructor() - { - super(); - } - static getInstance() - { - if(this.instance == null) - { - this.instance = new ChildLruBuffer(); - } - return this.instance; - } - afterRemoval(isEvict, key, value, newValue) - { - if (isEvict === false) - { - arr = [key, value, newValue]; - } - } - } - ChildLruBuffer.getInstance().afterRemoval(false,10,30,null); - ``` - - -### contains8+ - -contains(key:K):boolean - -检查当前缓冲区是否包含指定的键。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | K | 是 | 表示要检查的键。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 如果缓冲区包含指定的键,则返回 true。 | - -- 示例: - ``` - var pro = new util.LruBuffer(); - pro.put(2,10); - var result = pro.contains(20); - ``` - - -### createDefault8+ - -createDefault(key:K):V - -如果未计算特定键的值,则执行后续操作,参数表示丢失的键,返回与键关联的值。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | K | 是 | 表示丢失的键。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | V | 返回与键关联的值。 | - -- 示例: - ``` - var pro = new util.LruBuffer(); - var result = pro.createDefault(50); - ``` - - -### entries8+ - -entries():IterableIterator<[K,V]> - -允许迭代包含在这个对象中的所有键值对。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [K, V] | 返回一个可迭代数组。 | - -- 示例: - ``` - var pro = new util.LruBuffer(); - pro.put(2,10); - var result = pro.entries(); - ``` - - -### [Symbol.iterator]8+ - -[Symbol.iterator]\(): IterableIterator<[K, V]> - -返回一个键值对形式的二维数组。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [K, V] | 返回一个键值对形式的二维数组。 | - -- 示例: - ``` - var pro = new util.LruBuffer(); - pro.put(2,10); - var result = pro[symbol.iterator](); - ``` - - -## Scope8+ - - -### ScopeType8+ - -用于表示范围中的值的类型。该类型的值,类型可以为ScopeComparable或number。 - -ScopeComparable类型的值需要实现compareTo方法,确保传入的数据具有可比性。 -``` -interface ScopeComparable{ - compareTo(other:ScopeComparable):boolean; -} -type ScopeType = ScopeComparable | number; -``` - - -构造新类,实现compareTo方法。后续示例代码中,均通过Temperature,获取[ScopeType](#scopetype8)的实例化对象。 - - -示例: -``` -class Temperature{ - constructor(value){ - this._temp = value; - } - comapreTo(value){ - return this._temp >= value.getTemp(); - } - getTemp(){ - return this._temp; - } - toString(){ - return this._temp.toString(); - } -} -``` - - -### constructor8+ - -constructor(lowerObj:ScopeType,upperObje:ScopeType) - -用于创建指定下限和上限的作用域实例的构造函数,返回一个Scope对象。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | lowerObj | [ScopeType](#scopetype8) | 是 | 指定作用域实例的下限。 | - | upperObj | [ScopeType](#scopetype8) | 是 | 指定作用域实例的上限。 | - -- 示例: - ``` - var tempLower = new Temperature(30); - var tempUpper = new Temperature(40); - var range = new util.Scope(tempLower, tempUpper); - ``` - - -### toString8+ - -toString():string - -该字符串化方法返回一个包含当前范围的字符串表示形式。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string | 返回包含当前范围对象的字符串表示形式。 | - -- 示例: - ``` - var tempLower = new Temperature(30); - var tempUpper = new Temperature(40); - var range = new util.Scope(tempLower, tempUpper); - var result = range.toString(); - ``` - - -### intersect8+ - -intersect(range:Scope):Scope - -获取给定范围和当前范围的交集。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | range | [Scope](#scope8) | 是 | 传入一个给定范围。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [Scope](#scope8) | 返回给定范围和当前范围的交集。 | - -- 示例: - ``` - var tempLower = new Temperature(30); - var tempUpper = new Temperature(40); - var range = new util.Scope(tempLower, tempUpper); - var tempMiDF = new Temperature(35); - var tempMidS = new Temperature(39); - var rangeFir = new util.Scope(tempMiDF, tempMidS); - range.intersect(rangeFir ); - ``` - - -### intersect8+ - -intersect(lowerObj:ScopeType,upperObj:ScopeType):Scope - -获取当前范围与给定下限和上限范围的交集。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | lowerObj | [ScopeType](#scopetype8) | 是 | 给定范围的下限。 | - | upperObj | [ScopeType](#scopetype8) | 是 | 给定范围的上限。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [Scope](#scope8) | 返回当前范围与给定下限和上限范围的交集。 | - -- 示例: - ``` - var tempLower = new Temperature(30); - var tempUpper = new Temperature(40); - var tempMiDF = new Temperature(35); - var tempMidS = new Temperature(39); - var range = new util.Scope(tempLower, tempUpper); - var result = range.intersect(tempMiDF, tempMidS); - ``` - - -### getUpper8+ - -getUpper():ScopeType - -获取当前范围的上限。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [ScopeType](#scopetype8) | 返回当前范围的上限值。 | - -- 示例: - ``` - var tempLower = new Temperature(30); - var tempUpper = new Temperature(40); - var range = new util.Scope(tempLower, tempUpper); - var result = range.getUpper(); - ``` - - -### getLower8+ - -getLower():ScopeType - -获取当前范围的下限。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [ScopeType](#scopetype8) | 返回当前范围的下限值。 | - -- 示例: - ``` - var tempLower = new Temperature(30); - var tempUpper = new Temperature(40); - var range = new util.Scope(tempLower, tempUpper); - var result = range.getLower(); - ``` - - -### expand8+ - -expand(lowerObj:ScopeType,upperObj:ScopeType):Scope - -创建并返回包括当前范围和给定下限和上限的并集。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | lowerObj | [ScopeType](#scopetype8) | 是 | 给定范围的下限。 | - | upperObj | [ScopeType](#scopetype8) | 是 | 给定范围的上限。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [Scope](#scope8) | 返回当前范围和给定下限和上限的并集。 | - -- 示例: - ``` - var tempLower = new Temperature(30); - var tempUpper = new Temperature(40); - var tempMiDF = new Temperature(35); - var tempMidS = new Temperature(39); - var range = new util.Scope(tempLower, tempUpper); - var result = range.expand(tempMiDF, tempMidS); - ``` - - -### expand8+ - -expand(range:Scope):Scope - -创建并返回包括当前范围和给定范围的并集。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | range | [Scope](#scope8) | 是 | 传入一个给定范围。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [Scope](#scope8) | 返回包括当前范围和给定范围的并集。 | - -- 示例: - ``` - var tempLower = new Temperature(30); - var tempUpper = new Temperature(40); - var tempMiDF = new Temperature(35); - var tempMidS = new Temperature(39); - var range = new util.Scope(tempLower, tempUpper); - var rangeFir = new util.Scope(tempMiDF, tempMidS); - var result = range.expand(rangeFir); - ``` - - -### expand8+ - -expand(value:ScopeType):Scope - -创建并返回包括当前范围和给定值的并集。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | [ScopeType](#scopetype8) | 是 | 传入一个给定值。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [Scope](#scope8) | 返回包括当前范围和给定值的并集。 | - -- 示例: - ``` - var tempLower = new Temperature(30); - var tempUpper = new Temperature(40); - var tempMiDF = new Temperature(35); - var range = new util.Scope(tempLower, tempUpper); - var result = range.expand(tempMiDF); - ``` - - -### contains8+ - -contains(value:ScopeType):boolean - -检查给定value是否包含在当前范围内。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | [ScopeType](#scopetype8) | 是 | 传入一个给定值。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 如果给定值包含在当前范围内返回true,否则返回false。 | - -- 示例: - ``` - var tempLower = new Temperature(30); - var tempUpper = new Temperature(40); - var tempMiDF = new Temperature(35); - var range = new util.Scope(tempLower, tempUpper); - range.contains(tempMiDF); - ``` - - -### contains8+ - -contains(range:Scope):boolean - -检查给定range是否在当前范围内。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | range | [Scope](#scope8) | 是 | 传入一个给定范围。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 如果给定范围包含在当前范围内返回true,否则返回false。 | - -- 示例: - ``` - var tempLower = new Temperature(30); - var tempUpper = new Temperature(40); - var range = new util.Scope(tempLower, tempUpper); - var tempLess = new Temperature(20); - var tempMore = new Temperature(45); - var rangeSec = new util.Scope(tempLess, tempMore); - var result = range.contains(rangeSec); - ``` - - -### clamp8+ - -clamp(value:ScopeType):ScopeType - -将给定值限定到当前范围内。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | [ScopeType](#scopetype8) | 是 | 传入的给定值。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [ScopeType](#scopetype8) | 如果传入的value小于下限,则返回lowerObj;如果大于上限值则返回upperObj;如果在当前范围内,则返回value。 | - -- 示例: - ``` - var tempLower = new Temperature(30); - var tempUpper = new Temperature(40); - var tempMiDF = new Temperature(35); - var range = new util.Scope(tempLower, tempUpper); - var result = range.clamp(tempMiDF); - ``` - - -## Base648+ - - -### constructor8+ - -constructor() - -Base64的构造函数。 - -- 示例: - ``` - var base64 = new util.Base64(); - ``` - - -### encodeSync8+ - -encodeSync(src:Uint8Array):Uint8Array - -通过输入参数编码后输出对应文本。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | src | Uint8Array | 是 | 编码输入Uint8数组。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Uint8Array | 返回编码后新分配的Uint8数组。 | - -- 示例: - ``` - var that = new util.Base64(); - var array = new Uint8Array([115,49,51]); - var result = that.encodeSync(array); - ``` - - -### encodeToStringSync8+ - -encodeToStringSync(src:Uint8Array):string - -通过输入参数编码后输出对应文本。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | src | Uint8Array | 是 | 编码输入Uint8数组。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string | 返回编码后的字符串。 | - -- 示例: - ``` - var that = new util.Base64(); - var array = new Uint8Array([115,49,51]); - var result = that.encodeToStringSync(array); - ``` - - -### decodeSync8+ - -decodeSync(src:Uint8Array | string):Uint8Array - -通过输入参数解码后输出对应文本。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | src | Uint8Array \| string | 是 | 解码输入Uint8数组或者字符串。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Uint8Array | 返回解码后新分配的Uint8数组。 | - -- 示例: - ``` - var that = new util.Base64(); - var buff = 'czEz'; - var result = that.decodeSync(buff); - ``` - - -### encode8+ - -encode(src:Uint8Array):Promise<Uint8Array> - -通过输入参数异步编码后输出对应文本。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | src | Uint8Array | 是 | 异步编码输入Uint8数组。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<Uint8Array> | 返回异步编码后新分配的Uint8数组。 | - -- 示例: - ``` - var that = new util.Base64(); - var array = new Uint8Array([115,49,51]); - var rarray = new Uint8Array([99,122,69,122]); - that.encode(array).then(val=>{ - for (var i = 0; i < rarray.length; i++) { - expect(val[i]).assertEqual(rarray[i]) - } - }) - ``` - - -### encodeToString8+ - -encodeToString(src:Uint8Array):Promise<string> - -通过输入参数异步编码后输出对应文本。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | src | Uint8Array | 是 | 异步编码输入Uint8数组。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<string> | 返回异步编码后的字符串。 | - -- 示例: - ``` - var that = new util.Base64(); - var array = new Uint8Array([115,49,51]); - that.encodeToString(array).then(val=>{ - expect(val).assertEqual('czEz') - }) - ``` - - -### decode8+ - -decode(src:Uint8Array | string):Promise<Uint8Array> - -通过输入参数异步解码后输出对应文本。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | src | Uint8Array \| string | 是 | 异步解码输入Uint8数组或者字符串。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<Uint8Array> | 返回异步解码后新分配的Uint8数组。 | - -- 示例: - ``` - var that = new util.Base64(); - var array = new Uint8Array([99,122,69,122]); - var rarray = new Uint8Array([115,49,51]); - that.decode(array).then(val=>{ - for (var i = 0; i < rarray.length; i++) { - expect(val[i]).assertEqual(rarray[i]) - } - }) - ``` - - -## Types8+ - - -### constructor8+ - -constructor() - -Types的构造函数。 - -- 示例: - ``` - var type = new util.Types(); - ``` - - -### isAnyArrayBuffer8+ - -isAnyArrayBuffer(value: Object):boolean - -检查输入的value是否是ArrayBuffer类型。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | Object | 是 | 待检测对象。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 判断的结果,如果是ArrayBuffer类型为true,反之为false。 | - -- 示例: - ``` - var that = new util.Types(); - var result = that.isAnyArrayBuffer(new ArrayBuffer([])); - ``` - - -### isArrayBufferView8+ - -isArrayBufferView(value: Object):boolean - -检查输入的value是否是内置ArrayBufferView辅助类型。 - -ArrayBufferView辅助类型包括:Int8Array、Int16Array、Int32Array、Uint8Array、Uint8ClampedArray、Uint32Array、Float32Array、Float64Array、DataView。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | Object | 是 | 待检测对象。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 判断的结果,如果是内置包含的ArrayBufferView辅助类型为true,反之为false。 | - -- 示例: - ``` - var that = new util.Types(); - var result = that.isArrayBufferView(new Int8Array([])); - ``` - - -### isArgumentsObject8+ - -isArgumentsObject(value: Object):boolean - -检查输入的value是否是一个arguments对象类型。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | Object | 是 | 待检测对象。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 判断的结果,如果是内置包含的arguments类型为true,反之为false。 | - -- 示例: - ``` - var that = new util.Types(); - function foo() { - var result = that.isArgumentsObject(arguments); - } - var f = foo(); - ``` - - -### isArrayBuffer8+ - -isArrayBuffer(value: Object):boolean - -检查输入的value是否是ArrayBuffer类型。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | Object | 是 | 待检测对象。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 判断的结果,如果是内置包含的ArrayBuffer类型为true,反之为false。 | - -- 示例: - ``` - var that = new util.Types(); - var result = that.isArrayBuffer(new ArrayBuffer([])); - ``` - - -### isAsyncFunction8+ - -isAsyncFunction(value: Object):boolean - -检查输入的value是否是一个异步函数类型。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | Object | 是 | 待检测对象。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 判断的结果,如果是内置包含的异步函数类型为true,反之为false。 | - -- 示例: - ``` - var that = new util.Types(); - var result = that.isAsyncFunction(async function foo() {}); - ``` - - -### isBooleanObject8+ - -isBooleanObject(value: Object):boolean - -检查输入的value是否是一个Boolean对象类型。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | Object | 是 | 待检测对象。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 判断的结果,如果是内置包含的Boolean对象类型为true,反之为false。 | - -- 示例: - ``` - var that = new util.Types(); - var result = that.isBooleanObject(new Boolean(true)); - ``` - - -### isBoxedPrimitive8+ - -isBoxedPrimitive(value: Object):boolean - -检查输入的value是否是Boolean或Number或String或Symbol对象类型。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | Object | 是 | 待检测对象。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 判断的结果,如果是内置包含的Boolean或Number或String或Symbol对象类型为true,反之为false。 | - -- 示例: - ``` - var that = new util.Types(); - var result = that.isBoxedPrimitive(new Boolean(false)); - ``` - - -### isDataView8+ - -isDataView(value: Object):boolean - -检查输入的value是否是DataView类型。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | Object | 是 | 待检测对象。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 判断的结果,如果是内置包含的DataView对象类型为true,反之为false。 | - -- 示例: - ``` - var that = new util.Types(); - const ab = new ArrayBuffer(20); - var result = that.isDataView(new DataView(ab)); - ``` - - -### isDate8+ - -isDate(value: Object):boolean - -检查输入的value是否是Date类型。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | Object | 是 | 待检测对象。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 判断的结果,如果是内置包含的Date对象类型为true,反之为false。 | - -- 示例: - ``` - var that = new util.Types(); - var result = that.isDate(new Date()); - ``` - - -### isExternal8+ - -isExternal(value: Object):boolean - -检查输入的value是否是native External类型。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | Object | 是 | 待检测对象。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 判断的结果,如果是内置包含native External类型为true,反之为false。 | - -- 示例: - ``` - var that = new util.Types(); - const data = util.createExternalType(); - var result = that.isExternal(data); - ``` - - -### isFloat32Array8+ - -isFloat32Array(value: Object):boolean - -检查输入的value是否是Float32Array数组类型。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | Object | 是 | 待检测对象。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 判断的结果,如果是内置包含的Float32Array数组类型为true,反之为false。 | - -- 示例: - ``` - var that = new util.Types(); - var result = that.isFloat32Array(new Float32Array()); - ``` - - -### isFloat64Array8+ - -isFloat64Array(value: Object):boolean - -检查输入的value是否是Float64Array数组类型。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | Object | 是 | 待检测对象。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 判断的结果,如果是内置包含的Float64Array数组类型为true,反之为false。 | - -- 示例: - ``` - var that = new util.Types(); - var result = that.isFloat64Array(new Float64Array()); - ``` - - -### isGeneratorFunction8+ - -isGeneratorFunction(value: Object):boolean - -检查输入的value是否是generator函数类型。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | Object | 是 | 待检测对象。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 判断的结果,如果是内置包含的generator函数类型为true,反之为false。 | - -- 示例: - ``` - var that = new util.Types(); - var result = that.isGeneratorFunction(function* foo() {}); - ``` - - -### isGeneratorObject8+ - -isGeneratorObject(value: Object):boolean - -检查输入的value是否是generator对象类型。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | Object | 是 | 待检测对象。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 判断的结果,如果是内置包含的generator对象类型为true,反之为false。 | - -- 示例: - ``` - var that = new util.Types(); - function* foo() {} - const generator = foo(); - var result = that.isGeneratorObject(generator); - ``` - - -### isInt8Array8+ - -isInt8Array(value: Object):boolean - -检查输入的value是否是Int8Array数组类型。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | Object | 是 | 待检测对象。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 判断的结果,如果是内置包含的Int8Array数组类型为true,反之为false。 | - -- 示例: - ``` - var that = new util.Types(); - var result = that.isInt8Array(new Int8Array([])); - ``` - - -### isInt16Array8+ - -isInt16Array(value: Object):boolean - -检查输入的value是否是Int16Array数组类型。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | Object | 是 | 待检测对象。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 判断的结果,如果是内置包含的Int16Array数组类型为true,反之为false。 | - -- 示例: - ``` - var that = new util.Types(); - var result = that.isInt16Array(new Int16Array([])); - ``` - - -### isInt32Array8+ - -isInt32Array(value: Object):boolean - -检查输入的value是否是Int32Array数组类型。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | Object | 是 | 待检测对象。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 判断的结果,如果是内置包含的Int32Array数组类型为true,反之为false。 | - -- 示例: - ``` - var that = new util.Types(); - var result = that.isInt32Array(new Int32Array([])); - ``` - - -### isMap8+ - -isMap(value: Object):boolean - -检查输入的value是否是Map类型。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | Object | 是 | 待检测对象。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 判断的结果,如果是内置包含的Map类型为true,反之为false。 | - -- 示例: - ``` - var that = new util.Types(); - var result = that.isMap(new Map()); - ``` - - -### isMapIterator8+ - -isMapIterator(value: Object):boolean - -检查输入的value是否是Map的Iterator类型。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | Object | 是 | 待检测对象。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 判断的结果,如果是内置包含的Map的Iterator类型为true,反之为false。 | - -- 示例: - ``` - var that = new util.Types(); - const map = new Map(); - var result = that.isMapIterator(map.keys()); - ``` - - -### isNativeError8+ - -isNativeError(value: Object):boolean - -检查输入的value是否是Error类型。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | Object | 是 | 待检测对象。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 判断的结果,如果是内置包含的Error类型为true,反之为false。 | - -- 示例: - ``` - var that = new util.Types(); - var result = that.isNativeError(new TypeError()); - ``` - - -### isNumberObject8+ - -isNumberObject(value: Object):boolean - -检查输入的value是否是Number对象类型。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | Object | 是 | 待检测对象。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 判断的结果,如果是内置包含的Number对象类型为true,反之为false。 | - -- 示例: - ``` - var that = new util.Types(); - var result = that.isNumberObject(new Number(0)); - ``` - - -### isPromise8+ - -isPromise(value: Object):boolean - -检查输入的value是否是Promise类型。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | Object | 是 | 待检测对象。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 判断的结果,如果是内置包含的Promise类型为true,反之为false。 | - -- 示例: - ``` - var that = new util.Types(); - var result = that.isPromise(Promise.resolve(1)); - ``` - - -### isProxy8+ - -isProxy(value: Object):boolean - -检查输入的value是否是Proxy类型。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | Object | 是 | 待检测对象。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 判断的结果,如果是内置包含的Proxy类型为true,反之为false。 | - -- 示例: - ``` - var that = new util.Types(); - const target = {}; - const proxy = new Proxy(target, {}); - var result = that.isProxy(proxy); - ``` - - -### isRegExp8+ - -isRegExp(value: Object):boolean - -检查输入的value是否是RegExp类型。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | Object | 是 | 待检测对象。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 判断的结果,如果是内置包含的RegExp类型为true,反之为false。 | - -- 示例: - ``` - var that = new util.Types(); - var result = that.isRegExp(new RegExp('abc')); - ``` - - -### isSet8+ - -isSet(value: Object):boolean - -检查输入的value是否是Set类型。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | Object | 是 | 待检测对象。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 判断的结果,如果是内置包含的Set类型为true,反之为false。 | - -- 示例: - ``` - var that = new util.Types(); - var result = that.isSet(new Set()); - ``` - - -### isSetIterator8+ - -isSetIterator(value: Object):boolean - -检查输入的value是否是Set的Iterator类型。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | Object | 是 | 待检测对象。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 判断的结果,如果是内置包含的Set的Iterator类型为true,反之为false。 | - -- 示例: - ``` - var that = new util.Types(); - const set = new Set(); - var result = that.isSetIterator(set.keys()); - ``` - - -### isStringObject8+ - -isStringObject(value: Object):boolean - -检查输入的value是否是String对象类型。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | Object | 是 | 待检测对象。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 判断的结果,如果是内置包含的String对象类型为true,反之为false。 | - -- 示例: - ``` - var that = new util.Types(); - var result = that.isStringObject(new String('foo')); - ``` - - -### isSymbolObjec8+ - -isSymbolObjec(value: Object):boolean - -检查输入的value是否是Symbol对象类型。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | Object | 是 | 待检测对象。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 判断的结果,如果是内置包含的Symbol对象类型为true,反之为false。 | - -- 示例: - ``` - var that = new util.Types(); - const symbols = Symbol('foo'); - var result = that.isSymbolObject(Object(symbols)); - ``` - - -### isTypedArray8+ - -isTypedArray(value: Object):boolean - -检查输入的value是否是TypedArray类型的辅助类型。 - -TypedArray类型的辅助类型,包括Int8Array、Int16Array、Int32Array、Uint8Array、Uint8ClampedArray、Uint16Array、Uint32Array、Float32Array、Float64Array、DataView。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | Object | 是 | 待检测对象。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 判断的结果,如果是内置包含的TypedArray包含的类型为true,反之为false。 | - -- 示例: - ``` - var that = new util.Types(); - var result = that.isTypedArray(new Float64Array([])); - ``` - - -### isUint8Array8+ - -isUint8Array(value: Object):boolean - -检查输入的value是否是Uint8Array数组类型。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | Object | 是 | 待检测对象。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 判断的结果,如果是内置包含的Uint8Array数组类型为true,反之为false。 | - -- 示例: - ``` - var that = new util.Types(); - var result = that.isUint8Array(new Uint8Array([])); - ``` - - -### isUint8ClampedArray8+ - -isUint8ClampedArray(value: Object):boolean - -检查输入的value是否是Uint8ClampedArray数组类型。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | Object | 是 | 待检测对象。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 判断的结果,如果是内置包含的Uint8ClampedArray数组类型为true,反之为false。 | - -- 示例: - ``` - var that = new util.Types(); - var result = that.isUint8ClampedArray(new Uint8ClampedArray([])); - ``` - - -### isUint16Array8+ - -isUint16Array(value: Object):boolean - -检查输入的value是否是Uint16Array数组类型。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | Object | 是 | 待检测对象。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 判断的结果,如果是内置包含的Uint16Array数组类型为true,反之为false。 | - -- 示例: - ``` - var that = new util.Types(); - var result = that.isUint16Array(new Uint16Array([])); - ``` - - -### isUint32Array8+ - -isUint32Array(value: Object):boolean - -检查输入的value是否是Uint32Array数组类型。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | Object | 是 | 待检测对象。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 判断的结果,如果是内置包含的Uint32Array数组类型为true,反之为false。 | - -- 示例: - ``` - var that = new util.Types(); - var result = that.isUint32Array(new Uint32Array([])); - ``` - - -### isWeakMap8+ - -isWeakMap(value: Object):boolean - -检查输入的value是否是WeakMap类型。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | Object | 是 | 待检测对象。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 判断的结果,如果是内置包含的WeakMap类型为true,反之为false。 | - -- 示例: - ``` - var that = new util.Types(); - var result = that.isWeakMap(new WeakMap()); - ``` - - -### isWeakSet8+ - -isWeakSet(value: Object):boolean - -检查输入的value是否是WeakSet类型。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | Object | 是 | 待检测对象。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 判断的结果,如果是内置包含的WeakSet类型为true,反之为false。 | - -- 示例: - ``` - var that = new util.Types(); - var result = that.isWeakSet(new WeakSet()); - ``` diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/12.\350\257\255\350\250\200\345\237\272\347\241\200\347\261\273\345\272\223/05.xml\350\247\243\346\236\220\344\270\216\347\224\237\346\210\220.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/12.\350\257\255\350\250\200\345\237\272\347\241\200\347\261\273\345\272\223/05.xml\350\247\243\346\236\220\344\270\216\347\224\237\346\210\220.md" deleted file mode 100644 index ace2880f9b56ab632e7156dca93b9f0af9288e16..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/12.\350\257\255\350\250\200\345\237\272\347\241\200\347\261\273\345\272\223/05.xml\350\247\243\346\236\220\344\270\216\347\224\237\346\210\220.md" +++ /dev/null @@ -1,468 +0,0 @@ ---- -title: xml解析与生成 -permalink: /pages/010c010c05 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# xml解析与生成 - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import xml from '@ohos.xml'; -``` - - -## XmlSerializer - - -### constructor - -constructor(buffer: ArrayBuffer | DataView, encoding?: string) - -XmlSerializer的构造函数。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | buffer | ArrayBuffer \| DataView | 是 | 用于接收写入xml信息的ArrayBuffer或DataView内存。 | - | encoding | string | 否 | 编码格式。 | - -- 示例: - ``` - var arrayBuffer = new ArrayBuffer(1024); - var bufView = new DataView(arrayBuffer); - var thatSer = new xml.XmlSerializer(bufView); - ``` - - -### setAttributes - -setAttributes(name: string, value: string):void - -设置Attributes方法。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | name | string | 是 | 属性的key值。 | - | value | string | 是 | 属性的value值。 | - -- 示例: - ``` - var thatSer = new xml.XmlSerializer(bufView); - thatSer.setAttributes("importance", "high"); - ``` - - -### addEmptyElement - -addEmptyElement(name: string): void - -写入一个空元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | name | string | 是 | 该空元素的元素名。 | - -- 示例: - ``` - var thatSer = new xml.XmlSerializer(bufView); - thatSer.addEmptyElement("b"); // => - ``` - - -### setDeclaration - -setDeclaration(): void - -设置Declaration方法。 - -- 示例: - ``` - var thatSer = new xml.XmlSerializer(bufView); - thatSer.setDeclaration() // => ; - ``` - - -### startElement - -startElement(name: string): void - -根据给定名称写入元素开始标记。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | name | string | 是 | 当前元素的元素名。 | - -- 示例: - ``` - var arrayBuffer = new ArrayBuffer(1024); - var thatSer = new xml.XmlSerializer(arrayBuffer); - thatSer.startElement("notel"); - thatSer.endElement();// => ''; - ``` - - -### endElement - -endElement(): void - -写入元素结束标记。 - -- 示例: - ``` - var thatSer = new xml.XmlSerializer(bufView); - thatSer.setNamespace("h", "http://www.w3.org/TR/html4/"); - thatSer.startElement("table"); - thatSer.setAttributes("importance", "high"); - thatSer.setText("Happy"); - endElement(); // => Happy - ``` - - -### setNamespace - -setNamespace(prefix: string, namespace: string): void - -写入当前元素标记的命名空间。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | prefix | string | 是 | 当前元素及其子元素的前缀。 | - | namespace | string | 是 | 当前元素及其子元素的命名空间。 | - -- 示例: - ``` - var arrayBuffer = new ArrayBuffer(1024); - var thatSer = new xml.XmlSerializer(arrayBuffer); - thatSer.setDeclaration(); - thatSer.setNamespace("h", "http://www.w3.org/TR/html4/"); - thatSer.startElement("note"); - thatSer.endElement();// = >'\r\n'; - ``` - -### setComment - -setComment(text: string): void - -写入comment属性。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | text | string | 是 | 当前元素的注释内容。 | - -- 示例: - ``` - var arrayBuffer = new ArrayBuffer(1024); - var thatSer = new xml.XmlSerializer(arrayBuffer); - thatSer.startElement("note"); - thatSer.setComment("Hi!"); - thatSer.endElement(); // => '\r\n \r\n'; - ``` - - -### setCDATA - -setCDATA(text: string): void - -写入CDATA属性。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | text | string | 是 | CDATA属性的内容。 | - -- 示例: - ``` - var arrayBuffer = new ArrayBuffer(1028); - var thatSer = new xml.XmlSerializer(arrayBuffer); - thatSer.setCDATA('root SYSTEM') // => ''; - ``` - - -### setText - -setText(text: string): void - -设置Text方法。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | text | string | 是 | text属性的内容。 | - -- 示例: - ``` - var arrayBuffer = new ArrayBuffer(1024); - var thatSer = new xml.XmlSerializer(arrayBuffer); - thatSer.startElement("note"); - thatSer.setAttributes("importance", "high"); - thatSer.setText("Happy1"); - thatSer.endElement(); // => 'Happy1'; - ``` - - -### setDocType - -setDocType(text: string): void - -写入DocType属性。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | text | string | 是 | DocType属性的内容。 | - -- 示例: - ``` - var arrayBuffer = new ArrayBuffer(1024); - var thatSer = new xml.XmlSerializer(arrayBuffer); - thatSer.setDocType('root SYSTEM'); // => ''; - ``` - - -## XmlPullParser - - -### XmlPullParser - -constructor(buffer: ArrayBuffer | DataView, encoding?: string) - -创建并返回一个XmlPullParser对象,该XmlPullParser对象传参两个, 第一参数是ArrayBuffer或DataView类型的一段内存,第二个参数为文件格式(默认为UTF-8) - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | buffer | ArrayBuffer \| DataView | 是 | 含有xml文本信息的ArrayBuffer或者DataView。 | - | encoding | string | 否 | 编码格式(仅支持utf-8)。 | - -- 示例: - ``` - var strXml = - '' + - '' + - ' Happy' + - ' Work' + - ' Play' + - ''; - var arrayBuffer = new ArrayBuffer(strXml.length*2); - var bufView = new Uint8Array(arrayBuffer); - var strLen = strXml.length; - for (var i = 0; i < strLen; ++i) { - bufView[i] = strXml.charCodeAt(i);//设置arraybuffer方式 - } - var that = new xml.XmlPullParser(arrayBuffer); - ``` - - -### parse - -parse(option: ParseOptions): void - -该接口用于解析xml。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | option | [ParseOptions](#parseoptions) | 是 | 用户控制以及获取解析信息的选项。 | - -- 示例: - ``` - var strXml = - '' + - '' + - ' Happy' + - ' Work' + - ' Play' + - ''; - var arrayBuffer = new ArrayBuffer(strXml.length*2); - var bufView = new Uint8Array(arrayBuffer); - var strLen = strXml.length; - for (var i = 0; i < strLen; ++i) { - bufView[i] = strXml.charCodeAt(i); - } - var that = new xml.XmlPullParser(arrayBuffer); - var arrTag = {}; - arrTag[0] = '132'; - var i = 1; - function func(key, value){ - arrTag[i] = 'key:'+key+' value:'+ value.getDepth(); - i++; - return true; - } - var options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func} - that.parse(options); - ``` - - -## ParseOptions - -xml解析选项。 - -| 名称 | 参数类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| supportDoctype | boolean | 否 | 是否忽略Doctype , 默认false。 | -| ignoreNameSpace | boolean | 否 | 是否忽略NameSpace,默认false。 | -| tagValueCallbackFunction | (name: string, value: string)=> boolean | 否 | 获取tagValue回调函数。 | -| attributeValueCallbackFunction | (name: string, value: string)=> boolean | 否 | 获取attributeValue回调函数。 | -| tokenValueCallbackFunction | (eventType: [EventType](#eventtype), value: [ParseInfo](#parseinfo))=> boolean | 否 | 获取tokenValue回调函数。 | - - -## ParseInfo - -当前xml解析信息。 - - -### getColumnNumber - -getColumnNumber(): number - -获取当前列号,从1开始。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 返回当前列号。 | - - -### getDepth - -getDepth(): number - -获取元素的当前深度。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 返回元素的当前深度。 | - - -### getLineNumber - -getLineNumber(): number - -获取当前行号,从1开始。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 返回当前行号。 | - - -### getName - -getName(): string - -获取当前元素名称。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string | 返回当前元素名称。 | - - -### getNamespace - -getNamespace(): string - -获取当前元素的命名空间。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string | 返回当前元素的命名空间。 | - - -### getPrefix - -getPrefix(): string - -获取当前元素前缀。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string | 返回当前元素前缀。 | - - -### getText - -getText(): string - -获取当前事件的文本内容。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string | 返回当前事件的文本内容。 | - - -### isEmptyElementTag - -isEmptyElementTag(): boolean - -判断当前元素是否为空元素。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 返回true,当前元素为空元素。 | - - -### isWhitespace - -isWhitespace(): boolean - -判断当前文本事件是否仅包含空格字符。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 返回true,当前文本事件仅包含空格字符。 | - - -### getAttributeCount - -getAttributeCount(): number - -获取当前开始标记的属性数。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 当前开始标记的属性数。 | - - -## EventType - -事件枚举。 - -| 名称 | 枚举值 | 说明 | -| -------- | -------- | -------- | -| START_DOCUMENT | 0 | 启动文件事件。 | -| END_DOCUMENT | 1 | 结束文件事件。 | -| START_TAG | 2 | 启动标签事件。 | -| END_TAG | 3 | 结束标签事件。 | -| TEXT | 4 | 文本事件。 | -| CDSECT | 5 | CDATA事件。 | -| COMMENT | 6 | XML注释事件。 | -| DOCDECL | 7 | XML文档类型声明事件。 | -| INSTRUCTION | 8 | XML处理指令声明事件。 | -| ENTITY_REFERENCE | 9 | 实体引用事件。 | -| WHITESPACE | 10 | 空白事件。 | diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/12.\350\257\255\350\250\200\345\237\272\347\241\200\347\261\273\345\272\223/06.xml\350\275\254\346\215\242JavaScript.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/12.\350\257\255\350\250\200\345\237\272\347\241\200\347\261\273\345\272\223/06.xml\350\275\254\346\215\242JavaScript.md" deleted file mode 100644 index 33a2c771f52baaacd7b358d238e1bf9ef14acc5a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/12.\350\257\255\350\250\200\345\237\272\347\241\200\347\261\273\345\272\223/06.xml\350\275\254\346\215\242JavaScript.md" +++ /dev/null @@ -1,87 +0,0 @@ ---- -title: xml转换JavaScript -permalink: /pages/010c010c06 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# xml转换JavaScript - -> **说明:** -> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import convertxml from '@ohos.convertxml'; -``` - -## ConvertXML - - -### convert - -convert(xml: string, options?: ConvertOptions) : Object - -转化xml文本为JavaScript对象。 - - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | ------- | --------------------------------- | ---- | ------------------ | - | xml | string | 是 | 传入的xml文本。 | - | options | [ConvertOptions](#convertoptions) | 否 | 用户可进行的选项。 | - -- 返回值: - - | 类型 | 说明 | - | ------ | ---------------------------- | - | string | 处理后返回的JavaScript对象。 | - -- 示例: - - ``` - var xml = - '' + - '' + - ' Happy' + - ' Work' + - ' Play' + - ''; - var conv = new convertxml.ConvertXML(); - var result1 = conv.convert(xml, {trim: false, ignoreDeclaration: false}); - console.log(result1) - ``` - - -## ConvertOptions - -| 名称 | 参数类型 | 必填 | 说明 | -| ----------------- | -------- | ---- | ----------------------------------------------------------- | -| trim | boolean | 否 | 是否修剪位于文本前后的空白字符,默认false。 | -| ignoreDeclaration | boolean | 否 | 是否忽略xml写入声明指示,默认false。 | -| ignoreInstruction | boolean | 否 | 是否忽略xml的写入处理指令,默认false。 | -| ignoreAttributes | boolean | 否 | 是否跨多行打印属性并缩进属性,默认false。 | -| ignoreComment | boolean | 否 | 是否忽略元素的注释信息,默认false。 | -| ignoreCDATA | boolean | 否 | 是否忽略元素的CDATA信息,默认false。 | -| ignoreDoctype | boolean | 否 | 是否忽略元素的Doctype信息,默认false。 | -| ignoreText | boolean | 否 | 是否忽略元素的文本信息,默认false。 | -| declarationKey | string | 否 | 用于输出对象中declaration的属性键的名称,默认_declaration。 | -| instructionKey | string | 否 | 用于输出对象中instruction的属性键的名称,默认_instruction。 | -| attributesKey | string | 否 | 用于输出对象中attributes的属性键的名称,默认_attributes。 | -| textKey | string | 否 | 用于输出对象中text的属性键的名称,默认_text。 | -| cdataKey | string | 否 | 用于输出对象中cdata的属性键的名称,默认_cdata。 | -| doctypeKey | string | 否 | 用于输出对象中doctype的属性键的名称,默认_doctype。 | -| commentKey | string | 否 | 用于输出对象中comment的属性键的名称,默认_comment。 | -| parentKey | string | 否 | 用于输出对象中parent的属性键的名称,默认_parent。 | -| typeKey | string | 否 | 用于输出对象中type的属性键的名称,默认_type。 | -| nameKey | string | 否 | 用于输出对象中name的属性键的名称,默认_name。 | -| elementsKey | string | 否 | 用于输出对象中elements的属性键的名称,默认_elements。 | \ No newline at end of file diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/12.\350\257\255\350\250\200\345\237\272\347\241\200\347\261\273\345\272\223/07.\345\220\257\345\212\250\344\270\200\344\270\252worker.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/12.\350\257\255\350\250\200\345\237\272\347\241\200\347\261\273\345\272\223/07.\345\220\257\345\212\250\344\270\200\344\270\252worker.md" deleted file mode 100644 index 992fe1abe4bb958d4655c8c305dbd2a13254c53f..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/01.JSAPI\345\217\202\350\200\203/12.\350\257\255\350\250\200\345\237\272\347\241\200\347\261\273\345\272\223/07.\345\220\257\345\212\250\344\270\200\344\270\252worker.md" +++ /dev/null @@ -1,549 +0,0 @@ ---- -title: 启动一个worker -permalink: /pages/010c010c07 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# 启动一个worker - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import worker from '@ohos.worker'; -``` - - -## 属性 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| parentPort | [DedicatedWorkerGlobalScope](#dedicatedworkerglobalscope) | 是 | 是 | worker线程用于与宿主线程通信的对象 | - - -## WorkerOptions - -worker构造函数函数的选项信息,用于为worker添加其他信息。 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| type | "classic" | 是 | 是 | 按照指定方式执行脚本。 | -| name | string | 是 | 是 | worker的名称。 | - - -## Worker - -使用以下方法前,均需先构造worker实例,Worker类继承[EventTarget](#eventtarget)。 - - -### constructor - -constructor(scriptURL: string, options?: WorkerOptions) - -worker构造函数。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | scriptURL | string | 是 | worker执行脚本的url,路径规范:若DevEco新建工程在pages同级下没有workers目录,需要新建workers目录,将脚本文件放入workers目录。 | - | options | [WorkerOptions](#workeroptions) | 否 | worker构造的选项。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | worker | 执行Worker构造函数生成的Worker对象,失败则返回undefined。 | - -- 示例: - ``` - const workerInstance = new worker.Worker("workers/worker.js", {name:"first worker"}); - ``` - - -### postMessage - -postMessage(message: Object, options?: PostMessageOptions): void - -向worker线程发送消息,数据的传输采用结构化克隆算法。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | message | Object | 是 | 发送至worker的数据。 | - | options | [PostMessageOptions](#postmessageoptions) | 否 | 可转移对象是 ArrayBuffer 的实例对象。transferList数组中不可传入null。 | - -- 示例: - ``` - const workerInstance = new worker.Worker("workers/worker.js"); - workerInstance.postMessage("hello world"); - ``` - ``` - const workerInstance= new worker.Worker("workers/worker.js"); - var buffer = new ArrayBuffer(8); - workerInstance.postMessage(buffer, [buffer]); - ``` - - -### on - -on(type: string, listener: EventListener): void - -向worker添加一个事件监听。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | string | 是 | 监听事件的type。 | - | listener | [EventListener](#eventlistener) | 是 | 回调的事件。 | - -- 示例: - ``` - const workerInstance = new worker.Worker("workers/worker.js") - workerInstance.on("alert", (e)=>{ - console.log("alert listener callback"); - }) - ``` - - -### once - -once(type: string, listener: EventListener): void - -向worker添加一个事件监听,事件监听只执行一次便自动删除。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | string | 是 | 监听事件的type。 | - | listener | [EventListener](#eventlistener) | 是 | 回调的事件。 | - -- 示例: - ``` - const workerInstance = new worker.Worker("workers/worker.js"); - workerInstance.once("alert", (e)=>{ - console.log("alert listener callback"); - }) - ``` - - -### off - -off(type: string, listener?: EventListener): void - -删除worker的事件监听。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | string | 是 | 需要删除事件的type。 | - | listener | [EventListener](#eventlistener) | 否 | 需要删除的回调的事件。 | - -- 示例: - ``` - const workerInstance = new worker.Worker("workers/worker.js"); - workerInstance.off("alert"); - ``` - - -### terminate - -terminate(): void - -关闭worker线程,终止worker接收消息。 - -- 示例: - ``` - const workerInstance = new worker.Worker("workers/worker.js") - workerInstance.terminate() - ``` - - -### onexit - -onexit?: (code: number) => void - -Worker对象的onexit属性表示worker退出时被调用的事件处理程序,处理程序在宿主线程中执行。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | code | number | 否 | worker退出的code。 | - -- 示例: - ``` - const workerInstance = new worker.Worker("workers/worker.js") - workerInstance.onexit = function(e) { - console.log("onexit") - } - ``` - - -### onerror - -onerror?: (err: ErrorEvent) => void - -Worker对象的onerror属性表示worker在执行过程中发生异常被调用的事件处理程序,处理程序在宿主线程中执行。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | err | [ErrorEvent](#errorevent) | 否 | 异常数据。 | - -- 示例: - ``` - const workerInstance = new worker.Worker("workers/worker.js") - workerInstance.onerror = function(e) { - console.log("onerror") - } - ``` - - -### onmessage - -onmessage?: (event: MessageEvent) => void - -Worker对象的onmessage属性表示宿主线程接收到来自其创建的worker通过parentPort.postMessage接口发送的消息时被调用的事件处理程序,处理程序在宿主线程中执行。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | event | [MessageEvent](#messageevent) | 否 | 收到的worker消息数据。 | - -- 示例: - ``` - const workerInstance = new worker.Worker("workers/worker.js") - workerInstance.onmessage = function(e) { - console.log("onerror") - } - ``` - - -### onmessageerror - -onmessageerror?: (event: MessageEvent) => void - -Worker对象的onmessageerror属性表示当 Worker 对象接收到一条无法被序列化的消息时被调用的事件处理程序,处理程序在宿主线程中执行。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | event | [MessageEvent](#messageevent) | 否 | 异常数据。 | - -- 示例: - ``` - const workerInstance = new worker.Worker("workers/worker.js") - workerInstance.onmessageerror= function(e) { - console.log("onmessageerror") - } - ``` - - -## EventTarget - - -### addEventListener - -addEventListener(type: string, listener: EventListener): void - -向worker添加一个事件监听。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | string | 是 | 监听事件的type。 | - | listener | [EventListener](#eventlistener) | 是 | 回调的事件。 | - -- 示例: - ``` - const workerInstance = new worker.Worker("workers/worker.js") - workerInstance.addEventListener("alert", (e)=>{ - console.log("alert listener callback"); - }) - ``` - - -### removeEventListener - -removeEventListener(type: string, callback?: EventListener): void - -删除worker的事件监听。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | type | string | 是 | 需要删除事件的type。 | - | callback | [EventListener](#eventlistener) | 否 | 需要删除的回调的事件。 | - -- 示例: - ``` - const workerInstance = new worker.Worker("workers/worker.js") - workerInstance.removeEventListener("alert") - ``` - - -### dispatchEvent - -dispatchEvent(event: Event): boolean - -分发定义在worker的事件。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | event | [Event](#event) | 是 | 需要分发的事件。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 分发的结果,false表示分发失败。 | - -- 示例: - ``` - const workerInstance = new worker.Worker("workers/worker.js") - workerInstance.dispatchEvent({type:"alert"}) - ``` - - -### removeAllListener - -removeAllListener(): void - -删除worker的所有事件监听。 - -- 示例: - ``` - const workerInstance = new worker.Worker("workers/worker.js") - workerInstance.removeAllListener({type:"alert"}) - ``` - - -## DedicatedWorkerGlobalScope - -worker线程用于与宿主线程通信的类,通过postMessage接口发送消息给宿主线程、close接口关闭worker线程,DedicatedWorkerGlobalScope类继承[WorkerGlobalScope](#workerglobalscope)。 - - -### postMessage - -postMessage(message: Object, options?: PostMessageOptions): void - -worker向宿主线程发送消息。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | message | Object | 是 | 发送至worker的数据。 | - | options | [PostMessageOptions](#postmessageoptions) | 否 | 可转移对象是ArrayBuffer的实例对象。transferList数组中不可传入null。 | - -- 示例: - ``` - // main.js - import worker from '@ohos.worker'; - const workerInstance = new worker.Worker("workers/worker.js") - workerInstance.postMessage("hello world") - workerInstance.onmessage = function(e) { - console.log("receive data from worker.js") - } - ``` - ``` - // worker.js - import worker from '@ohos.worker'; - const parentPort = worker.parentPort; - parentPort.onmessage = function(e){ - parentPort.postMessage("receive data from main.js") - } - ``` - - -### close - -close(): void - -关闭worker线程,终止worker接收消息。 - -- 示例: - ``` - // main.js - import worker from '@ohos.worker'; - const workerInstance = new worker.Worker("workers/worker.js") - ``` - ``` - // worker.js - import worker from '@ohos.worker'; - const parentPort = worker.parentPort; - parentPort.onmessage = function(e) { - parentPort.close() - } - ``` - - -### onmessage - -onmessage?: (event: MessageEvent) => void - -DedicatedWorkerGlobalScope的onmessage属性表示worker线程收到来自其宿主线程通过worker.postMessage接口发送的消息时被调用的事件处理程序,处理程序在worker线程中执行。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | event | [MessageEvent](#messageevent) | 否 | 收到的worker消息数据。 | - -- 示例: - ``` - // main.js - import worker from '@ohos.worker'; - const workerInstance = new worker.Worker("workers/worker.js") - workerInstance.postMessage("hello world") - ``` - ``` - // worker.js - import worker from '@ohos.worker'; - const parentPort = worker.parentPort; - parentPort.onmessage = function(e) { - console.log("receive main.js message") - } - ``` - - -### onmessageerror - -onmessageerror?: (event: MessageEvent) => void - -DedicatedWorkerGlobalScope的onmessageerror属性表示当 Worker 对象接收到一条无法被反序列化的消息时被调用的事件处理程序,处理程序在worker线程中执行。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | event | [MessageEvent](#messageevent) | 否 | 异常数据。 | - -- 示例: - ``` - // main.js - import worker from '@ohos.worker'; - const workerInstance = new worker.Worker("workers/worker.js") - ``` - ``` - // worker.js - import worker from '@ohos.worker'; - const parentPort = worker.parentPort; - parentPort.onmessageerror= function(e) { - console.log("worker.js onmessageerror") - } - ``` - - -## PostMessageOptions - -明确数据传递过程中需要转移所有权对象的类,传递所有权的对象必须是ArrayBuffer。 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| transfer | Object[] | 是 | 是 | ArrayBuffer数组,用于传递所有权。 | - - -## Event - -事件类。 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| type | string | 是 | 否 | 指定事件的type。 | -| timeStamp | number | 是 | 否 | 事件创建时的时间戳(精度为毫秒)。 | - - -## EventListener - -事件监听类。 - - -### (evt: Event): void | Promise<void> - -执行的回调函数。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | evt | [Event](#event) | 是 | 回调的事件类。 | - -- 返回值 - | 类型 | 说明 | - | -------- | -------- | - | void \| Promise<void> | 无返回值或者以Promise形式返回。 | - -- 示例: - ``` - const workerInstance = new worker.Worker("workers/worker.js"); - workerInstance.addEventListener("alert", (e)=>{ - console.log("alert listener callback"); - }) - ``` - - -## ErrorEvent - -错误事件类,用于表示worker执行过程中出现异常的详细信息,ErrorEvent类继承[Event](#event)。 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| message | string | 是 | 否 | 异常发生的错误信息。 | -| filename | string | 是 | 否 | 出现异常所在的文件。 | -| lineno | number | 是 | 否 | 异常所在的行数。 | -| colno | number | 是 | 否 | 异常所在的列数。 | -| error | Object | 是 | 否 | 异常类型。 | - - -## MessageEvent - -消息类,持有worker线程间传递的数据。 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| data | T | 是 | 否 | 线程间传递的数据。 | - - -## WorkerGlobalScope - -worker线程自身的运行环境,WorkerGlobalScope类继承[EventTarget](#eventtarget)。 - - -### 属性 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| name | string | 是 | 否 | worker的名字,有new Worker时指定。 | -| self | [WorkerGlobalScope](#workerglobalscope) & typeof globalThis | 是 | 否 | WorkerGlobalScope本身。 | - - -### onerror - -onerror?: (ev: ErrorEvent) => void - -WorkerGlobalScope的onerror属性表示worker在执行过程中发生异常被调用的事件处理程序,处理程序在worker线程中执行。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | ev | [ErrorEvent](#errorevent) | 否 | 异常数据。 | - -- 示例: - ``` - // main.js - import worker from '@ohos.worker'; - const workerInstance = new worker.Worker("workers/worker.js") - ``` - ``` - // worker.js - import worker from '@ohos.worker'; - const parentPort = worker.parentPort - parentPort.onerror = function(e){ - console.log("worker.js onerror") - } - ``` diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/01.\351\200\232\347\224\250\345\261\236\346\200\247.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/01.\351\200\232\347\224\250\345\261\236\346\200\247.md" deleted file mode 100644 index a6f26a8f91df8d74fff19d6efdacd49cafe59203..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/01.\351\200\232\347\224\250\345\261\236\346\200\247.md" +++ /dev/null @@ -1,186 +0,0 @@ ---- -title: 通用属性 -permalink: /pages/010c0201010101 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# 通用属性 - -## 常规属性 - -常规属性指的是组件普遍支持的用来设置组件基本标识和外观显示特征的属性。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

id

-

string

-

-

-

-

组件的唯一标识。

-

style

-

string

-

-

-

-

组件的样式声明。

-

class

-

string

-

-

-

-

组件的样式类,用于引用样式表。

-

ref

-

string

-

-

-

-

用来指定指向子元素或子组件的引用信息,该引用将注册到父组件的$refs 属性对象上。

-

disabled

-

boolean

-

false

-

-

当前组件是否被禁用,在禁用场景下,组件将无法响应用户交互。

-

data

-

string

-

-

-

-

给当前组件设置data属性,进行相应的数据存储和读取。JS文件中:

-
  • 在事件回调中使用 e.target.attr.data 读取数据,e为事件回调函数入参。
  • 使用$element或者$refs获取DOM元素后,通过attr.data 进行访问。
-
说明:

从API Version 6 开始,建议使用data-*。

-
-

data-*6+

-

string

-

-

-

-

给当前组件设置data-*属性,进行相应的数据存储和读取。大小写不敏感,如data-A和data-a默认相同。JS文件中:

-
  • 在事件回调中使用 e.target.dataSet.a读取数据,e为事件回调函数入参。
  • 使用$element或者$refs获取DOM元素后,通过dataSet.a进行访问。
-

click-effect5+

-

string

-

-

-

-

通过这个属性可以设置组件的弹性点击效果,当前支持如下三种效果:

-
  • spring-small:建议小面积组件设置,缩放(90%)。
  • spring-medium:建议中面积组件设置,缩放(95%)。
  • spring-large:建议大面积组件设置,缩放(95%)。
-

dir6+

-

string

-

auto

-

-

设置元素布局模式,支持设置rtl、ltr和auto三种属性值:

-
  • rtl:使用从右往左布局模式。
  • ltr:使用从左往右布局模式。
  • auto:跟随系统语言环境。
-
- -## 渲染属性 - -组件普遍支持的用来设置组件是否渲染的属性。 - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

描述

-

for

-

Array

-

-

-

根据设置的数据列表,展开当前元素。

-

if

-

boolean

-

-

-

根据设置的boolean值,添加或移除当前元素。

-

show

-

boolean

-

-

-

根据设置的boolean值,显示或隐藏当前元素。

-
- ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->属性和样式不能混用,不能在属性字段中进行样式设置。 - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\346\240\267\345\274\217.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\346\240\267\345\274\217.md" deleted file mode 100644 index 8b289840b4327a3640d050bf01be5a7424dfb20d..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\346\240\267\345\274\217.md" +++ /dev/null @@ -1,629 +0,0 @@ ---- -title: 通用样式 -permalink: /pages/010c0201010102 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# 通用样式 - -组件普遍支持的可以在style或css中设置组件外观样式。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

描述

-

width

-

<length> | <percentage>

-

-

-

设置组件自身的宽度。

-

缺省时使用元素自身内容需要的宽度。

-

height

-

<length> | <percentage>

-

-

-

设置组件自身的高度。

-

缺省时使用元素自身内容需要的高度。

-

min-width5+

-

<length> | <percentage>6+

-

0

-

设置元素的最小宽度。

-

min-height5+

-

<length> | <percentage>6+

-

0

-

设置元素的最小高度。

-

max-width5+

-

<length> | <percentage>6+

-

-

-

设置元素的最大宽度。默认无限制。

-

max-height5+

-

<length> | <percentage>6+

-

-

-

设置元素的最大高度。默认无限制。

-

padding

-

<length> | <percentage>5+

-

0

-

使用简写属性设置所有的内边距属性。

-
该属性可以有1到4个值:
  • 指定一个值时,该值指定四个边的内边距。

    -
  • 指定两个值时,第一个值指定上下两边的内边距,第二个指定左右两边的内边距。

    -
  • 指定三个值时,第一个指定上边的内边距,第二个指定左右两边的内边距,第三个指定下边的内边距。

    -
  • 指定四个值时分别为上、右、下、左边的内边距(顺时针顺序)。

    -
-
-

padding-[left|top|right|bottom]

-

<length> | <percentage>5+

-

0

-

设置左、上、右、下内边距属性。

-

padding-[start|end]

-

<length> | <percentage>5+

-

0

-

设置起始和末端内边距属性。

-

margin

-

<length> | <percentage>5+

-

0

-

使用简写属性设置所有的外边距属性,该属性可以有1到4个值。

-
  • 只有一个值时,这个值会被指定给全部的四个边。

    -
  • 两个值时,第一个值被匹配给上和下,第二个值被匹配给左和右。

    -
  • 三个值时,第一个值被匹配给上, 第二个值被匹配给左和右,第三个值被匹配给下。

    -
  • 四个值时,会依次按上、右、下、左的顺序匹配 (即顺时针顺序)。

    -
-

margin-[left|top|right|bottom]

-

<length> | <percentage>5+

-

0

-

设置左、上、右、下外边距属性。

-

margin-[start|end]

-

<length> | <percentage>5+

-

0

-

设置起始和末端外边距属性。

-

border

-

-

-

0

-

使用简写属性设置所有的边框属性,包含边框的宽度,样式,颜色属性,顺序设置为border-width、border-style、border-color,不设置时,各属性值为默认值。

-

border-style

-

string

-

solid

-

使用简写属性设置所有边框的样式,可选值为:

-
  • dotted:显示为一系列圆点,圆点半径为border-width的一半。
  • dashed:显示为一系列短的方形虚线。
-
  • solid:显示为一条实线。
-

border-[left|top|right|bottom]-style

-

string

-

solid

-

分别设置左、上、右、下四个边框的样式,可选值为dotted、dashed、solid。

-

border-[left|top|right|bottom]

-

-

-

-

-

使用简写属性设置对应位置的边框属性,包含边框的宽度,样式,颜色属性,顺序设置为border-width、border-style、border-color,不设置的值为默认值。

-

border-width

-

<length>

-

0

-

使用简写属性设置元素的所有边框宽度,或者单独为各边边框设置宽度

-

border-[left|top|right|bottom]-width

-

<length>

-

0

-

分别设置左、上、右、下四个边框的宽度。

-

border-color

-

<color>

-

black

-

使用简写属性设置元素的所有边框颜色,或者单独为各边边框设置颜色

-

border-[left|top|right|bottom]-color

-

<color>

-

black

-

分别设置左、上、右、下四个边框的颜色。

-

border-radius

-

<length>

-

-

-

border-radius属性设置元素的外边框圆角半径。设置border-radius时不能单独设置某一个方向的border-[left|top|right|bottom]-width,border-[left|top|right|bottom]-color ,border-[left|top|right|bottom]-style,如果要设置color、width和style,需要将四个方向一起设置(border-width、border-color、border-style)。

-
说明:

顺序为左下、右下、左上和右上。

-
-

border-[top|bottom]-[left|right]-radius

-

<length>

-

-

-

分别设置左上,右上,右下和左下四个角的圆角半径。

-

background

-

<linear-gradient>

-

-

-

仅支持设置渐变样式,与background-color、background-image不兼容。

-

background-color

-

<color>

-

-

-

设置背景颜色。

-

background-image

-

string

-

-

-

设置背景图片。与background-color、background不兼容,支持本地图片资源地址。

-

示例:

-
  • background-image: url("/common/background.png")
    说明:

    不支持svg格式图片。

    -
    -
-

background-size

-
  • string
  • <length> <length>
  • <percentage> <percentage>
-

auto

-

设置背景图片的大小。

-
  • string可选值:
    • contain:把图片扩展至最大尺寸,以使其高度和宽度完全适用内容区域。
    • cover:把背景图片扩展至足够大,以使背景图片完全覆盖背景区域;背景图片的某些部分也许无法显示在背景定位区域中。
    • auto:保持原图的比例不变。
    -
  • length值参数方式:

    设置背景图片的高度和宽度。第一个值设置宽度,第二个值设置高度。如果只设置一个值,则第二个值会被设置为 "auto"。

    -
  • 百分比参数方式:

    以父元素的百分比来设置背景图片的宽度和高度。第一个值设置宽度,第二个值设置高度。如果只设置一个值,则第二个值会被设置为 "auto"。

    -
-

background-repeat

-

string

-

repeat

-

针对重复背景图片样式进行设置,背景图片默认在水平和垂直方向上重复。

-
  • repeat:在水平轴和竖直轴上同时重复绘制图片。
  • repeat-x:只在水平轴上重复绘制图片。
  • repeat-y:只在竖直轴上重复绘制图片。
  • no-repeat:不会重复绘制图片。
-

background-position

-
  • string string
  • <length> <length>
  • <percentage> <percentage>
-

0px 0px

-
  • 关键词方式:如果仅规定了一个关键词,那么第二个值为"center"。两个值分别定义水平方向位置和竖直方向位置。
    • left:水平方向上最左侧。
    • right:水平方向上最右侧。
    • top:竖直方向上最顶部。
    • bottom:竖直方向上最底部。
    • center:水平方向或竖直方向上中间位置。
    -
-
  • length值参数方式:第一个值是水平位置,第二个值是垂直位置。 左上角是 0 0。单位是像素 (0px 0px) 。如果仅规定了一个值,另外一个值将是50%。
  • 百分比参数方式:第一个值是水平位置,第二个值是垂直位置。左上角是 0% 0%。右下角是 100% 100%。如果仅规定了一个值,另外一个值为50%。
  • 可以混合使用<percentage>和<length>。
-

box-shadow5+

-

string

-

0

-

语法:box-shadow: h-shadow v-shadow blur spread color

-

通过这个样式可以设置当前组件的阴影样式,包括水平位置(必填)、垂直位置(必填)、模糊半径(可选,默认值为0)、阴影延展距离(可选,默认值为0)、阴影颜色(可选,默认值为黑色)。

-

示例:

-
  • box-shadow :10px 20px 5px 10px #888888
  • box-shadow :100px 100px 30px red
  • box-shadow :-100px -100px 0px 40px
-

filter5+

-

string

-

-

-

语法:filter: blur(px)

-

通过这个样式可以设置当前组件布局范围的内容模糊,参数用于指定模糊半径,如果没有设置值,则默认是0(不模糊),不支持百分比。

-

示例:

-
  • filter: blur(10px)
-

backdrop-filter5+

-

string

-

-

-

语法:backdrop-filter: blur(px)

-

通过这个样式可以设置当前组件布局范围的背景模糊,参数用于指定模糊半径,如果没有设置值,则默认是0(不模糊),不支持百分比。

-

示例:

-
  • backdrop-filter: blur(10px)
-

opacity

-

number

-

1

-

元素的透明度,取值范围为0到1,1表示为不透明,0表示为完全透明。

-

display

-

string

-

-

flex

-

确定一个元素所产生的框的类型,可选值为:

-
  • flex:弹性布局。
  • none:不渲染此元素。
-

visibility

-

string

-

-

visible

-

是否显示元素所产生的框。不可见的框会占用布局(将'display'属性设置为'none'来完全去除框),可选值为:

-
  • visible:元素正常显示。
  • hidden:隐藏元素,但是其他元素的布局不改变,相当于此元素变成透明。
-
说明:

visibility和display样式都设置时,仅display生效。

-
-

flex

-

number | string

-

-

-

规定当前组件如何适应父组件中的可用空间。

-

flex可以指定1个、2个5+或3个5+值。

-

单值语法:

-
  • 一个无单位数:用来设置组件的flex-grow。
  • 一个有效的宽度值5+:用来设置组件的flex-basis。
-

双值语法5+

-

第一个值必须是无单位数,用来设置组件的flex-grow。第二个值是以下之一:

-
  • 一个无单位数:用来设置组件的flex-shrink。
  • 一个有效的宽度值:用来设置组件的flex-basis。
-

三值语法5+

-

第一个值必须是无单位数,用来设置组件的flex-grow;第二个值必须是无单位数,用来设置组件的flex-shrink;第三个值必须是一个有效的宽度值,用来设置组件的flex-basis。

-
说明:

仅父容器为<div>、<list-item>、<tabs>、<refresh>、<stepper-item>5+时生效。

-
-

flex-grow

-

number

-

0

-

设置组件的拉伸样式,指定父组件容器主轴方向上剩余空间(容器本身大小减去所有flex子元素占用的大小)的分配权重。0为不伸展。

-
说明:

仅父容器为<div>、<list-item>、<tabs>、<refresh>、<stepper-item>5+时生效。

-
-

flex-shrink

-

number

-

1

-

设置组件的收缩样式,元素仅在默认宽度之和大于容器的时候才会发生收缩,0为不收缩。

-
说明:

仅父容器为<div>、<list-item>、<tabs>、<refresh>、<stepper-item>5+时生效。

-
-

flex-basis

-

<length>

-

-

-

-

设置组件在主轴方向上的初始大小。

-
说明:

仅父容器为<div>、<list-item>、<tabs>、<refresh>、<stepper-item>5+时生效。

-
-

align-self6+

-

string

-

-

-

设置自身在父元素交叉轴上的对齐方式,该样式会覆盖父元素的align-items样式,仅在父容器为div、list。可选值为:

-
  • stretch 弹性元素被在交叉轴方向被拉伸到与容器相同的高度或宽度。
  • flex-start 元素向交叉轴起点对齐。
  • flex-end 元素向交叉轴终点对齐。
  • center 元素在交叉轴居中。
  • baseline 元素在交叉轴基线对齐。
-

position

-

string

-

relative

-

设置元素的定位类型,不支持动态变更。

-
  • fixed:相对与整个界面进行定位。
  • absolute:相对于父元素进行定位。
  • relative:相对于其正常位置进行定位。
-
说明:

absolute属性仅在父容器为<div>、<stack>时生效。

-
-

[left|top|right|bottom]

-

<length> | <percentage>6+

-

-

-

left|top|right|bottom需要配合position样式使用,来确定元素的偏移位置。

-
  • left属性规定元素的左边缘。该属性定义了定位元素左外边距边界与其包含块左边界之间的偏移。
  • top属性规定元素的顶部边缘。该属性定义了一个定位元素的上外边距边界与其包含块上边界之间的偏移。
  • right属性规定元素的右边缘。该属性定义了定位元素右外边距边界与其包含块右边界之间的偏移。
  • bottom属性规定元素的底部边缘。该属性定义了一个定位元素的下外边距边界与其包含块下边界之间的偏移。
-

[start | end]6+

-

<length> | <percentage>

-

-

-

start | end需要配合position样式使用,来确定元素的偏移位置。

-
  • start属性规定元素的起始边缘。该属性定义了定位元素起始外边距边界与其包含块起始边界之间的偏移。
  • end属性规定元素的结尾边缘。该属性定义了一个定位元素的结尾边距边界与其包含块结尾边界之间的偏移。
-

z-index6+

-

number

-

-

-

表示对于同一父节点其子节点的渲染顺序。数值越大,渲染数据越靠后。

-
说明:

z-index不支持auto,并且opacity等其他样式不会影响z-index的渲染顺序。

-
-

image-fill6+

-

<color>

-

-

-

为svg图片填充颜色,支持组件范围(与设置图片资源的属性):button(icon属性)、piece(icon属性)、search(icon属性)、input(headericon属性)、textarea(headericon属性)、image(src属性)、toolbar-item(icon属性)。

-

svg图片文件内的fill属性颜色值在渲染时将被替换为image-fill所配的颜色值,且仅对svg图片内显示声明的fill属性生效。

-

clip-path6+

-

[ <geometry-box> || <basic-shape> ] | none

-

-

-

设置组件的裁剪区域。区域内的部分显示,区域外的不显示。

-

<geometry-box>:表示裁剪区域的作用范围,默认为border-box。可选值为:

-
  • margin-box:margin计算入长宽尺寸内。
  • border-box:border计算入长宽尺寸内。
  • padding-box:padding计算入长宽尺寸内。
  • content-box:margin/border/padding不计算入长宽尺寸内。
-

<basic-shape>:表示裁剪的形状。包含以下类型:

-
  • inset,格式为:inset( <percentage>{1,4} [ round <'border-radius'> ]? )。
  • circle,格式为:circle( [ <percentage> ]? [ at <percentage> <percentage> ]? )。
  • ellipse,格式为:ellipse( [ <percentage>{2} ]? [ at <percentage> <percentage> ]? )。
  • polygon,格式为:polygon( [ <percentage> <percentage> ]# )
  • path,格式为:path( <string> )。
-

mask-image6+

-
  • <linear-gradient>
  • string
-

-

-

设置渐变色遮罩或本地图片设置。

-

设置渐变色遮罩,示例:

-

linear-gradient(to left, black, white)

-

设置纯色遮罩,示例:

-

linear-gradient(to right, grey , grey)

-

设置本地svg图片为遮罩,示例:url(common/mask.svg)

-

mask-size6+

-
  • string
  • <length><length>
  • <percentage> <percentage>
-

auto

-

设置遮罩图片显示大小,仅当mask-image为图片资源时有效。

-

string可选值:

-
  • contain:把图像扩展至最大尺寸,以使其高度和宽度完全适用内容区域。
  • cover:把图像扩展至足够大,以使背景图像完全覆盖背景区域;背景图像的某些部分也许无法显示在背景定位区域中。
  • auto:保持原图的比例不变。
-

length值参数方式:设置图像的高度和宽度。第一个值设置宽度,第二个值设置高度。如果只设置一个值,则第二个值会被设置为 "auto"。

-

百分比参数方式:以原图宽高的百分比来设置图像的宽度和高度。第一个值设置宽度,第二个值设置高度。如果只设置一个值,则第二个值会被设置为 "auto"。

-

mask-position6+

-
  • string string
  • <length> <length>
  • <percentage> <percentage>
-

0px 0px

-

设置遮罩图片显示位置,仅当mask-image为图片资源时有效。关键词方式:如果仅规定了一个关键词,那么第二个值为"center"。两个值分别定义水平方向位置和竖直方向位置。

-

string可选值:

-
  • left:水平方向上最左侧。
  • right:水平方向上最右侧。
  • top:竖直方向上最顶部。
  • bottom:竖直方向上最底部。
  • center:水平方向或竖直方向上中间位置。
-

length值参数方式:第一个值是水平位置,第二个值是垂直位置。 左上角是 0 0。单位是像素 (0px 0px) 。如果仅规定了一个值,另外一个值将是50%。

-

百分比参数方式:第一个值是水平位置,第二个值是垂直位置。左上角是 0% 0%。右下角是 100% 100%。如果仅规定了一个值,另外一个值为50%。

-

可以混合使用<percentage>和<length>。

-

border-image-source7+

-

string

-

-

-

指定元素的边框图片。

-

示例:

-

border-image-source: url("/common/images/border.png")

-

border-image-slice7+

-

<length> | <percentage>

-

0

-

指定图片的边界内向偏移。

-

该属性可以有1到4个值:

-

指定一个值时,该值指定四个边的内偏移。

-

指定两个值时,第一个值指定上下两边的内偏移,第二个指定左右两边的内偏移。

-

指定三个值时,第一个指定上边的内偏移,第二个指定左右两边的内偏移,第三个指定下边的内偏移。

-

指定四个值时分别为上、右、下、左边的内偏移(顺时针顺序)。

-

border-image-width7+

-

<length> | <percentage>

-

0

-

指定图片边界的宽度。

-

指定一个值时,该值指定四个边的宽度。

-

指定两个值时,第一个值指定上下两边的宽度 ,第二个指定左右两边的宽度。

-

指定三个值时,第一个指定上边的宽度 ,第二个指定左右两边的宽度 ,第三个指定下边的宽度。

-

指定四个值时分别为上、右、下、左边的宽度 (顺时针顺序)。

-

border-image-outset7+

-

<length> | <percentage>

-

0

-

指定边框图像可超出边框的大小。

-

指定一个值时,边框图像在四个方向超出边框的距离。

-

指定两个值时,第一个值指定上下两边的边框图像超出边框的距离,第二个指定左右两边的 。

-

指定三个值时,第一个指定上边的边框图像超出边框的距离 ,第二个指定左右两边的边框图像超出边框的距离 ,第三个指定下边的边框图像超出边框的距离 。

-

指定四个值时分别为上、右、下、左边的边框图像超出边框的距离 (顺时针顺序)。

-

border-image-repeat7+

-

string

-

stretch

-

定义图片如何填充边框。

-

stretch: 拉伸图片以填充边框。

-

repeat:平铺图片以填充边框。

-

round:平铺图像。当不能整数次平铺时,根据情况放大或缩小图像。

-

border-image7+

-

string

-

-

-

简写属性,可以选择以下两种设置方式:

- -
  • 渐变色边框

    示例:

    -

    border-image: linear-gradient(red, yellow) 10px

    -
-
- ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->通用样式都不是必填项。 - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/03.\351\200\232\347\224\250\344\272\213\344\273\266.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/03.\351\200\232\347\224\250\344\272\213\344\273\266.md" deleted file mode 100644 index c95ac68eb187b99582c0c5d8de9e2f118f178873..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/03.\351\200\232\347\224\250\344\272\213\344\273\266.md" +++ /dev/null @@ -1,493 +0,0 @@ ---- -title: 通用事件 -permalink: /pages/010c0201010103 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# 通用事件 - -## 事件说明 - -- 事件绑定在组件上,当组件达到事件触发条件时,会执行JS中对应的事件回调函数,实现页面UI视图和页面JS逻辑层的交互; -- 事件回调函数中通过参数可以携带额外的信息,如组件上的数据对象dataset,事件特有的回调参数。 - -相对于私有事件,大部分组件都可以绑定如下事件。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数

-

描述

-

是否支持冒泡

-

touchstart

-

TouchEvent

-

手指刚触摸屏幕时触发该事件。

-

5+

-

touchmove

-

TouchEvent

-

手指触摸屏幕后移动时触发该事件。

-

5+

-

touchcancel

-

TouchEvent

-

手指触摸屏幕中动作被打断时触发该事件。

-

5+

-

touchend

-

TouchEvent

-

手指触摸结束离开屏幕时触发该事件。

-

5+

-

click

-

-

-

点击动作触发该事件。

-

6+

-

doubleclick7+

-
  

双击动作触发该事件

-

-

longpress

-

-

-

长按动作触发该事件。

-

-

swipe5+

-

SwipeEvent

-

组件上快速滑动后触发该事件。

-

-

attached6+

-

-

-

当前组件节点挂载在渲染树后触发。

-

-

detached6+

-

-

-

当前组件节点从渲染树中移除后触发。

-

-

pinchstart7+

-

PinchEvent

-

手指开始执行捏合操作时触发该事件。

-

-

pinchupdate7+

-

PinchEvent

-

手指执行捏合操作过程中触发该事件。

-

-

pinchend7+

-

PinchEvent

-

手指捏合操作结束离开屏幕时触发该事件。

-

-

pinchcancel7+

-

PinchEvent

-

手指捏合操作被打断时触发该事件。

-

-

dragstart7+

-

DragEvent

-

用户开始拖拽时触发该事件。

-

-

drag7+

-

DragEvent

-

拖拽过程中触发该事件。

-

-

dragend7+

-

DragEvent

-

用户拖拽完成后触发。

-

-

dragenter7+

-

DragEvent

-

进入释放目标时触发该事件。

-

-

dragover7+

-

DragEvent

-

在释放目标内拖动时触发。

-

-

dragleave7+

-

DragEvent

-

离开释放目标区域时触发。

-

-

drop7+

-

DragEvent

-

在可释放目标区域内释放时触发。

-

-
- ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->除上述事件外,其他事件均为非冒泡事件,如[input的change事件](/pages/010c0201010306#section1721512551218),详见各个组件。 - -**表 1** BaseEvent对象属性列表 - - - - - - - - - - - - - - - -

属性

-

类型

-

说明

-

type

-

string

-

当前事件的类型,比如click、longpress等。

-

timestamp

-

number

-

该事件触发时的时间戳。

-
- -**表 2** TouchEvent对象属性列表\(继承BaseEvent\) - - - - - - - - - - - - - - - - -

属性

-

类型

-

说明

-

touches

-

Array<TouchInfo>

-

触摸事件时的属性集合,包含屏幕触摸点的信息数组。

-

changedTouches

-

Array<TouchInfo>

-

触摸事件时的属性集合,包括产生变化的屏幕触摸点的信息数组。数据格式和touches一样。该属性表示有变化的触摸点,如从无变有,位置变化,从有变无。例如用户手指刚接触屏幕时,touches数组中有数据,但changedTouches无数据。

-
- -**表 3** TouchInfo - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

属性

-

类型

-

说明

-

globalX

-

number

-

距离屏幕左上角(不包括状态栏)横向距离。屏幕的左上角为原点。

-

globalY

-

number

-

距离屏幕左上角(不包括状态栏)纵向距离。屏幕的左上角为原点。

-

localX

-

number

-

距离被触摸组件左上角横向距离。组件的左上角为原点。

-

localY

-

number

-

距离被触摸组件左上角纵向距离。组件的左上角为原点。

-

size

-

number

-

触摸接触面积。

-

force6+

-

number

-

接触力信息。

-

identifier8+

-

number

-

接触点标识信息,表示接触表面与触摸点的唯一标识值,手指在屏幕表面上移动触发的每个事件中该值不变。

-
- -**表 4** SwipeEvent 基础事件对象属性列表(继承BaseEvent) - - - - - - - - - - - - - - - - -

属性

-

类型

-

说明

-

direction

-

string

-

滑动方向,可能值有:

-
  1. left:向左滑动;
  2. right:向右滑动;
  3. up:向上滑动;
  4. down:向下滑动。
-

distance6+

-

number

-

在滑动方向上的滑动距离。

-
- -**表 5** PinchEvent 对象属性列表7+ - - - - - - - - - - - - - - - - - - - - -

属性

-

类型

-

说明

-

scale

-

number

-

缩放比例

-

pinchCenterX

-

number

-

捏合中心点X轴坐标,单位px

-

pinchCenterY

-

number

-

捏合中心点Y轴坐标,单位px

-
- -**表 6** DragEvent对象属性列表\(继承BaseEvent\)7+ - - - - - - - - - - - - - - - - - - - - - - - - -

属性

-

类型

-

说明

-

type

-

string

-

事件名称。

-

globalX

-

number

-

距离屏幕左上角坐标原点横向距离。

-

globalY

-

number

-

距离屏幕左上角坐标原点纵向距离。

-

timestamp

-

number

-

时间戳。

-
- -## 事件对象 - -当组件触发事件后,事件回调函数默认会收到一个事件对象,通过该事件对象可以获取相应的信息。 - -**target对象:** - - - - - - - - - - - -

属性

-

类型

-

说明

-

dataSet6+

-

Object

-

组件上通过通用属性设置的data-*的自定义属性组成的集合。

-
- -**示例:** - -``` - -
-
-
-``` - -``` -// xxx.js -export default { - touchstartfunc(msg) { - console.info(`on touch start, point is: ${msg.touches[0].globalX}`); - console.info(`on touch start, data is: ${msg.target.dataSet.a}`); - } -} -``` - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/04.\351\200\232\347\224\250\346\226\271\346\263\225.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/04.\351\200\232\347\224\250\346\226\271\346\263\225.md" deleted file mode 100644 index 99635997829d857ee56e9a2015dfff77dbbe74b3..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/04.\351\200\232\347\224\250\346\226\271\346\263\225.md" +++ /dev/null @@ -1,692 +0,0 @@ ---- -title: 通用方法 -permalink: /pages/010c0201010104 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# 通用方法 - -当组件通过id属性标识后,可以使用该id获取组件对象并调用相关组件方法。 - -## animate - -animate\( keyframes: Keyframes, options: Options\):void - -- 参数 - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

描述

-

keyframes

-

keyframes

-

-

设置动画样式

-

options

-

Options

-

-

用于设置动画属性的对象列表。options请见Options说明

-
- - **表 1** keyframes - - - - - - - - - - - - -

属性

-

类型

-

说明

-

frames

-

Array<Style>

-

用于设置动画样式的对象列表。Style类型说明请见Style类型说明

-
- - **表 2** Style类型说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

默认值

-

说明

-

width

-

number

-

-

-

动画执行过程中设置到组件上的宽度值。

-

height

-

number

-

-

-

动画执行过程中设置到组件上的高度值。

-

backgroundColor

-

<color>

-

none

-

动画执行过程中设置到组件上的背景颜色。

-

opacity

-

number

-

1

-

设置到组件上的透明度(介于0到1之间)。

-

backgroundPosition

-

string

-

-

-

格式为"x y",单位为百分号或者px。

-

第一个值是水平位置,第二个值是垂直位置。

-

如果仅规定了一个值,另一个值为 50%。

-

transformOrigin

-

string

-

'center center'

-

变换对象的中心点。

-

第一个参数表示x轴的值,可以设置为left、center、right、长度值或百分比值。

-

第二个参数表示y轴的值,可以设置为top、center、bottom、长度值或百分比值。

-

transform

-

Transform

-

-

-

设置到变换对象上的类型。

-

offset

-

number

-

-

-
  • offset值(如果提供)必须在0.0到1.0(含)之间,并以升序排列。
  • 若只有两帧,可以不填offset。
  • 若超过两帧,offset必填。
-
- - **表 3** Options说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

默认值

-

说明

-

duration

-

number

-

0

-

指定当前动画的运行时长(单位毫秒)。

-

easing

-

string

-

linear

-

描述动画的时间曲线,支持类型见easing有效值说明

-

delay

-

number

-

0

-

设置动画执行的延迟时间(默认值表示无延迟)。

-

iterations

-

number | string

-

1

-

设置动画执行的次数。number表示固定次数,Infinity枚举表示无限次数播放。

-

direction6+

-

string

-

normal

-

指定动画的播放模式:

-

normal: 动画正向循环播放;

-

reverse: 动画反向循环播放;

-

alternate:动画交替循环播放,奇数次正向播放,偶数次反向播放;

-

alternate-reverse:动画反向交替循环播放,奇数次反向播放,偶数次正向播放。

-

fill

-

string

-

none

-

指定动画开始和结束的状态:

-

none:在动画执行之前和之后都不会应用任何样式到目标上。

-

forwards:在动画结束后,目标将保留动画结束时的状态(在最后一个关键帧中定义)。

-

backwards6+:动画将在animation-delay期间应用第一个关键帧中定义的值。当animation-direction为"normal"或"alternate"时应用from关键帧中的值,当animation-direction为"reverse"或"alternate-reverse"时应用to关键帧中的值。

-

both6+:动画将遵循forwards和backwards的规则,从而在两个方向上扩展动画属性。

-
- - **表 4** easing有效值说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

-

描述

-

linear

-

动画线性变化。

-

ease-in

-

动画速度先慢后快,cubic-bezier(0.42, 0.0, 1.0, 1.0)。

-

ease-out

-

动画速度先快后慢,cubic-bezier(0.0, 0.0, 0.58, 1.0)。

-

ease-in-out

-

动画先加速后减速,cubic-bezier(0.42, 0.0, 0.58, 1.0)。

-

friction

-

阻尼曲线,cubic-bezier(0.2, 0.0, 0.2, 1.0)。

-

extreme-deceleration

-

急缓曲线,cubic-bezier(0.0, 0.0, 0.0, 1.0)。

-

sharp

-

锐利曲线,cubic-bezier(0.33, 0.0, 0.67, 1.0)。

-

rhythm

-

节奏曲线,cubic-bezier(0.7, 0.0, 0.2, 1.0)。

-

smooth

-

平滑曲线,cubic-bezier(0.4, 0.0, 0.4, 1.0)。

-

cubic-bezier(x1, y1, x2, y2)

-

在三次贝塞尔函数中定义动画变化过程,入参的x和y值必须处于0-1之间。

-

steps(number, step-position)6+

-

Step曲线。

-

number必须设置,支持的类型为int。

-

step-position参数可选,支持设置start或end,默认值为end。

-
- -- 返回值 - - animation对象属性: - - - - - - - - - - - - - - - - - - - - - - - -

属性

-

类型

-

说明

-

finished

-

boolean

-

只读,用于表示当前动画是否已播放完成。

-

pending

-

boolean

-

只读,用于表示当前动画是否处于等待其他异步操作完成的等待状态(例如启动一个延时播放的动画)。

-

playState

-

string

-

可读可写,动画的执行状态:

-
  • idle:未执行状态,包括已结束或未开始。
  • running:动画正在运行。
  • paused:动画暂停。
  • finished:动画播放完成。
-

startTime

-

number

-

可读可写,动画播放开始的预定时间,用途类似于options参数中的delay。

-
- - animation对象方法: - - - - - - - - - - - - - - - - - - - - - - - - - - - -

方法

-

参数

-

说明

-

play

-

-

-

组件播放动画。

-

finish

-

-

-

组件完成动画。

-

pause

-

-

-

组件暂停动画。

-

cancel

-

-

-

组件取消动画。

-

reverse

-

-

-

组件倒播动画。

-
- - animation对象事件: - - - - - - - - - - - - - - - - - - -

事件

-

说明

-

start6+

-

动画开始事件。

-

cancel

-

动画被强制取消。

-

finish

-

动画播放完成。

-

repeat

-

动画重播事件。

-
- -- 示例 - - ``` - -
-
-
- - -
-
- ``` - - ``` - /* xxx.css */ - .container { - flex-direction: column; - justify-content: center; - align-items: center; - width: 100%; - } - .box{ - width: 200px; - height: 200px; - background-color: #ff0000; - margin-top: 30px; - } - .buttonBox{ - margin-top: 30px; - width: 250px; - justify-content: space-between; - } - button{ - background-color: #8e8b89; - color: white; - width: 100px; - height: 40px; - font-size: 24px; - } - ``` - - ``` - // xxx.js - import prompt from '@system.prompt'; - export default{ - data:{ - animation:'', - }, - onInit(){ - }, - onShow(){ - var options = { - duration: 1500, - easing: 'friction', - delay: 500, - fill: 'forwards', - iterations: 2, - direction: 'normal', - }; - var frames = [ - {transform: {translate: '-120px -0px'}, opacity: 0.1, offset: 0.0}, - {transform: {translate: '120px 0px'}, opacity: 1.0, offset: 1.0} - ]; - this.animation = this.$element('idName').animate(frames, options); - // handle finish event - this.animation.onfinish = function(){ - prompt.showToast({ - message: "The animation is finished." - }); - }; - // handle cancel event - this.animation.oncancel = function(){ - prompt.showToast({ - message: "The animation is canceled." - }); - }; - // handle repeat event - this.animation.onrepeat = function(){ - prompt.showToast({ - message: "The animation is repeated." - }); - }; - }, - start(){ - this.animation.play(); - }, - cancel(){ - this.animation.cancel(); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/AnimationAPI裁剪.gif) - - -## getBoundingClientRect - -getBoundingClientRect\(\): [ ](#table1650917111414) - -获取元素的大小及其相对于窗口的位置。 - -- 返回值 - - **表 5** Rect对象说明6+ - - - - - - - - - - - - - - - - - - - - - - - - -

属性

-

类型

-

描述

-

width

-

number

-

该元素的宽度。

-

height

-

number

-

该元素的高度。

-

left

-

number

-

该元素左边界距离窗口的偏移。

-

top

-

number

-

该元素上边界距离窗口的偏移。

-
- -- 示例 - - ``` - // xxx.js - var rect = this.$element('id').getBoundingClientRect(); - console.info(`current element position is ${rect.left}, ${rect.top}`); - ``` - - -## createIntersectionObserver - -createIntersectionObserver\(param?:ObserverParam\): Observer) - -监听元素在当前页面的可见范围。 - -- 参数 - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

描述

-

param

-

ObserverParam

-

-

-

获取observer的回调。

-
- - **表 6** ObserverParam对象说明6+ - - - - - - - - - - - - -

属性

-

类型

-

描述

-

ratios

-

Array<number>

-

组件超出或小于范围时触发observer的回调。

-
- -- 返回值 - - **表 7** Observer对象支持的方法6+ - - - - - - - - - - - - - - - - -

方法

-

参数

-

描述

-

observe

-

callback: function

-

开启observer的订阅方法。超出或小于阈值时触发callback。

-

unobserve

-

-

-

取消observer的订阅方法。

-
- -- 示例 - - ``` - // xxx.js - let observer = this.$element('broad').createIntersectionObserver({ - ratios: [0.2, 0.5], // number - }); - - observer.observe((isVisible, ratio)=> { - console.info('this element is ' + isVisible + 'ratio is ' + ratio) - }) - - observer.unobserve() - ``` - - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/05.\345\212\250\347\224\273\346\240\267\345\274\217.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/05.\345\212\250\347\224\273\346\240\267\345\274\217.md" deleted file mode 100644 index ab4ba783f2d85afec55030f92b289217669b4cc0..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/05.\345\212\250\347\224\273\346\240\267\345\274\217.md" +++ /dev/null @@ -1,543 +0,0 @@ ---- -title: 动画样式 -permalink: /pages/010c0201010105 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# 动画样式 - -组件支持动态的旋转、平移、缩放效果,可在style或css中设置。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

描述

-

transform-origin

-

string6+ | <percentage> | <length> string6+ | <percentage> | <length>

-

center center

-

变换对象的原点位置,支持px和百分比(相对于动画目标组件),如果仅设置一个值,另一个值为50%,第一个string的可选值为:left | center | right ,第二个string的可选值为:top | center | bottom。

-

示例:

-

transform-origin: 200px 30%。

-

transform-origin: 100px top。

-

transform-origin: center center。

-

transform

-

string

-

-

-

支持同时设置平移/旋转/缩放的属性。

-

详见表1

-

animation6+

-

string

-

0s ease 0s 1 normal none running none

-

格式:duration | timing-function | delay | iteration-count | direction | fill-mode | play-state | name,每个字段不区分先后,但是 duration / delay 按照出现的先后顺序解析。

-

animation-name

-

string

-

-

-

指定@keyframes,详见表2

-

animation-delay

-

<time>

-

0

-

定义动画播放的延迟时间。支持的单位为[s(秒)|ms(毫秒) ],默认单位为ms,格式为:1000ms或1s。

-

animation-duration

-

<time>

-

0

-

定义一个动画周期。支持的单位为[s(秒)|ms(毫秒) ],默认单位为ms,格式为:1000ms或1s。

-
说明:

animation-duration 样式必须设置,否则时长为 0,则不会播放动画。

-
-

animation-iteration-count

-

number | infinite

-

1

-

定义动画播放的次数,默认播放一次,可通过设置为infinite无限次播放。

-

animation-timing-function

-

string

-

ease

-

描述动画执行的速度曲线,用于使动画更为平滑。

-

可选项有:

-
  • linear:表示动画从头到尾的速度都是相同的。
  • ease:表示动画以低速开始,然后加快,在结束前变慢,cubic-bezier(0.25, 0.1, 0.25, 1.0)。
  • ease-in:表示动画以低速开始,cubic-bezier(0.42, 0.0, 1.0, 1.0)。
  • ease-out:表示动画以低速结束,cubic-bezier(0.0, 0.0, 0.58, 1.0)。
  • ease-in-out:表示动画以低速开始和结束,cubic-bezier(0.42, 0.0, 0.58, 1.0)。
  • friction:阻尼曲线,cubic-bezier(0.2, 0.0, 0.2, 1.0)。
  • extreme-deceleration:急缓曲线,cubic-bezier(0.0, 0.0, 0.0, 1.0)。
  • sharp:锐利曲线,cubic-bezier(0.33, 0.0, 0.67, 1.0)。
  • rhythm:节奏曲线,cubic-bezier(0.7, 0.0, 0.2, 1.0)。
  • smooth:平滑曲线,cubic-bezier(0.4, 0.0, 0.4, 1.0)。
  • cubic-bezier:在三次贝塞尔函数中定义动画变化过程,入参的x和y值必须处于0-1之间。
  • steps: 阶梯曲线6+。语法:steps(number[, end|start]);number必须设置,支持的类型为正整数。第二个参数可选,表示在每个间隔的起点或是终点发生阶跃变化,支持设置end或start,默认值为end。
-

animation-direction6+

-

string

-

normal

-

指定动画的播放模式:

-
  • normal: 动画正向循环播放。
  • reverse: 动画反向循环播放。
  • alternate:动画交替循环播放,奇数次正向播放,偶数次反向播放。
  • alternate-reverse:动画反向交替循环播放,奇数次反向播放,偶数次正向播放。
-

animation-fill-mode

-

string

-

none

-

指定动画开始和结束的状态:

-
  • none:在动画执行之前和之后都不会应用任何样式到目标上。
  • forwards:在动画结束后,目标将保留动画结束时的状态(在最后一个关键帧中定义)。
  • backwards6+:动画将在animation-delay期间应用第一个关键帧中定义的值。当animation-direction为"normal"或"alternate"时应用from关键帧中的值,当animation-direction为"reverse"或"alternate-reverse"时应用to关键帧中的值。
  • both6+:动画将遵循forwards和backwards的规则,从而在两个方向上扩展动画属性。
-

animation-play-state6+

-

string

-

running

-

指定动画的当前状态:

-
  • paused:动画状态为暂停。
  • running:动画状态为播放。
-

transition6+

-

string

-

all 0 ease 0

-

指定组件状态切换时的过渡效果,可以通过transition属性设置如下四个属性:

-
  • transition-property:规定设置过渡效果的 CSS 属性的名称,目前支持宽、高、背景色。
  • transition-duration:规定完成过渡效果需要的时间,单位秒。
  • transition-timing-function:规定过渡效果的时间曲线,支持样式动画提供的曲线。
  • transition-delay:规定过渡效果延时启动时间,单位秒。
-
- -**表 1** transform操作说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

描述

-

none6+

-

-

-

不进行任何转换。

-

matrix6+

-

<number>

-

入参为六个值的矩阵,6个值分别代表:scaleX, skewY, skewX, scaleY, translateX, translateY。

-

matrix3d6+

-

<number>

-

入参为十六个值的4X4矩阵。

-

translate

-

<length>| <percent>

-

平移动画属性,支持设置x轴和y轴两个维度的平移参数。

-

translate3d6+

-

<length>| <percent>

-

三个入参,分别代表X轴、Y轴、Z轴的平移距离。

-

translateX

-

<length>| <percent>

-

X轴方向平移动画属性。

-

translateY

-

<length>| <percent>

-

Y轴方向平移动画属性。

-

translateZ6+

-

<length>| <percent>

-

Z轴的平移距离。

-

scale

-

<number>

-

缩放动画属性,支持设置x轴和y轴两个维度的缩放参数。

-

scale3d6+

-

<number>

-

三个入参,分别代表X轴、Y轴、Z轴的缩放参数。

-

scaleX

-

<number>

-

X轴方向缩放动画属性。

-

scaleY

-

<number>

-

Y轴方向缩放动画属性。

-

scaleZ6+

-

<number>

-

Z轴的缩放参数。

-

rotate

-

<deg> | <rad> | <grad>6+ | <turn>6+

-

旋转动画属性,支持设置x轴和y轴两个维度的选中参数。

-

rotate3d6+

-

<deg> | <rad> | <grad> | <turn>

-

四个入参,前三个分别为X轴、Y轴、Z轴的旋转向量,第四个是旋转角度。

-

rotateX

-

<deg> | <rad> | <grad>6+ | <turn>6+

-

X轴方向旋转动画属性。

-

rotateY

-

<deg> | <rad> | <grad>6+ | <turn>6+

-

Y轴方向旋转动画属性。

-

rotateZ6+

-

<deg> | <rad> | <grad> | <turn>

-

Z轴方向的旋转角度。

-

skew6+

-

<deg> | <rad> | <grad> | <turn>

-

两个入参,分别为X轴和Y轴的2D倾斜角度。

-

skewX6+

-

<deg> | <rad> | <grad> | <turn>

-

X轴的2D倾斜角度。

-

skewY6+

-

<deg> | <rad> | <grad> | <turn>

-

Y轴的2D倾斜角度。

-

perspective6+

-

<number>

-

3D透视场景下镜头距离元素表面的距离。

-
- -**表 2** @keyframes属性说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

描述

-

background-color

-

<color>

-

-

-

动画执行后应用到组件上的背景颜色。

-

opacity

-

number

-

1

-

动画执行后应用到组件上的不透明度值,为介于0到1间的数值,默认为1。

-

width

-

<length>

-

-

-

动画执行后应用到组件上的宽度值。

-

height

-

<length>

-

-

-

动画执行后应用到组件上的高度值。

-

transform

-

string

-

-

-

定义应用在组件上的变换类型,见表1

-

background-position6+

-

string | <percentage> | <length> string | <percentage> | <length>

-

50% 50%

-

背景图位置。单位支持百分比和px,第一个值是水平位置,第二个值是垂直位置。如果仅设置一个值,另一个值为50%。第一个string的可选值为:left | center | right ,第二个string的可选值为:top | center | bottom。

-

示例:

-
  • background-position: 200px 30%
  • background-position: 100px top
  • background-position: center center
-
- -对于不支持起始值或终止值缺省的情况,可以通过from和to显示指定起始和结束。可以通过百分比指定动画运行的中间状态6+。示例: - -``` -
-
-
-
-``` - -``` -.container { - display: flex; - justify-content: center; - align-items: center; -} -.rect{ - width: 200px; - height: 200px; - background-color: #f76160; - animation: Go 3s infinite; -} -@keyframes Go -{ - from { - background-color: #f76160; - transform:translate(100px) rotate(0deg) scale(1.0); - } - /* 可以通过百分比指定动画运行的中间状态6+ */ - 50% { - background-color: #f76160; - transform:translate(100px) rotate(60deg) scale(1.3); - } - to { - background-color: #09ba07; - transform:translate(100px) rotate(180deg) scale(2.0); - } -} -``` - -![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173324797.gif) - -``` - -
-
- animation-play-state: {{playState}} -
-``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - justify-content: center; - align-items: center; -} -.simpleSize { - background-color: blue; - width: 100px; - height: 100px; -} -.simpleAnimation { - animation: simpleFrames 9s; -} -@keyframes simpleFrames { - from { transform: translateX(0px); } - to { transform: translateX(100px); } -} -``` - -``` -// xxx.js -export default { - data: { - title: "", - playState: "running" - }, - toggleState() { - if (this.playState === "running") { - this.playState = "paused"; - } else { - this.playState = "running"; - } - } -} -``` - -![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127285034.gif) - -``` - -
-``` - -``` -/* xxx.css */ -.img { - width: 294px; - height: 233px; - background-image: url('common/heartBeat.jpg'); - background-repeat: no-repeat; - background-position: 0% 0%; - background-size: 900%; - animation-name: heartBeating; - animation-duration: 1s; - animation-delay: 0s; - animation-fill-mode: forwards; - animation-iteration-count: -1; - animation-timing-function: steps(8, end); -} - -@keyframes heartBeating { - from { background-position: 0% 0%;} - to { background-position: 100% 0%;} -} -``` - -``` - -
-
-
-``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - justify-content: center; - align-items: center; -} -.content { /* 组件状态1 */ - height: 200px; - width: 200px; - background-color: red; - transition: all 5s ease 0s; -} -.content:active { /* 组件状态2 */ - height: 400px; - width: 400px; - background-color: blue; - transition: all 5s linear 0s; -} -``` - -![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001152833768.gif) - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->@keyframes的from/to不支持动态绑定。 ->steps函数的end和start含义如下图所示。 ->![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127125220.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/06.\346\270\220\345\217\230\346\240\267\345\274\217.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/06.\346\270\220\345\217\230\346\240\267\345\274\217.md" deleted file mode 100644 index 7ee0b30df623200f3164776da9c2d904b310c0ed..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/06.\346\270\220\345\217\230\346\240\267\345\274\217.md" +++ /dev/null @@ -1,133 +0,0 @@ ---- -title: 渐变样式 -permalink: /pages/010c0201010106 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# 渐变样式 - -组件普遍支持的在style或css中设置的 可以平稳过渡两个或多个指定的颜色。 - -开发框架支持线性渐变 \(linear-gradient\)和重复线性渐变 \(repeating-linear-gradient\)两种渐变效果。 - -## 线性渐变/重复线性渐变 - -使用渐变样式,需要定义过渡方向和过渡颜色。 - -### 过渡方向 - -通过direction或者angle指定过渡方向。 - -- direction:进行方向渐变。 -- angle:进行角度渐变。 - -``` -background: linear-gradient(direction/angle, color, color, ...); -background: repeating-linear-gradient(direction/angle, color, color, ...); -``` - -### 过渡颜色 - -支持以下四种方式:\#ff0000、\#ffff0000、rgb\(255, 0, 0\)、rgba\(255, 0, 0, 1\),需要指定至少两种颜色。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

direction

-

to <side-or-corner> <side-or-corner> = [left | right] || [top | bottom]

-

to bottom (由上到下渐变)

-

-

指定过渡方向,如:to left (从右向左渐变) ;或者

-

to bottom right (从左上角到右下角)。

-

angle

-

<deg>

-

180deg

-

-

指定过渡方向,以元素几何中心为坐标原点,水平方向为X轴,angle指定了渐变线与Y轴的夹角(顺时针方向)。

-

color

-

<color> [<length>|<percentage>]

-

-

-

-

定义使用渐变样式区域内颜色的渐变效果。

-
- -- 示例 - - 1. 默认渐变方向为从上向下渐变 - - ``` - #gradient { - height: 300px; - width: 600px; - /* 从顶部开始向底部由红色向绿色渐变 */ - background: linear-gradient(red, #00ff00); - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/111.png) - - 2. 45度夹角渐变 - - ``` - /* 45度夹角,从红色渐变到绿色 */ - background: linear-gradient(45deg, rgb(255,0,0),rgb(0, 255, 0)); - ``` - - ![](/images/application-dev/reference/arkui-js/figures/222.png) - - 3. 设置方向从左向右渐变 - - ``` - /* 从左向右渐变,在距离左边90px和距离左边360px (600*0.6) 之间270px宽度形成渐变 */ - background: linear-gradient(to right, rgb(255,0,0) 90px, rgb(0, 255, 0) 60%); - ``` - - ![](/images/application-dev/reference/arkui-js/figures/333.png) - - 4. 重复渐变 - - ``` - /* 从左向右重复渐变,重复渐变区域30px(60-30)透明度0.5 */ - background: repeating-linear-gradient(to right, rgba(255, 255, 0, 1) 30px,rgba(0, 0, 255, .5) 60px); - ``` - - ![](/images/application-dev/reference/arkui-js/figures/444.png) - - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/07.\350\275\254\345\234\272\346\240\267\345\274\217.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/07.\350\275\254\345\234\272\346\240\267\345\274\217.md" deleted file mode 100644 index b3fe0481a64cba600129d672a2307f330b780a8e..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/07.\350\275\254\345\234\272\346\240\267\345\274\217.md" +++ /dev/null @@ -1,355 +0,0 @@ ---- -title: 转场样式 -permalink: /pages/010c0201010107 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# 转场样式 - -## 共享元素转场 - -### 属性 - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

描述

-

shareid

-

string

-

-

进行共享元素转场时使用,若不配置,则转场样式不生效。共享元素转场当前支持的组件:list-item、image、text、button、label。

-
- -### 样式 - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

描述

-

shared-transition-effect

-

string

-

exchange

-

配置共享元素转场时的入场样式。

-
  • exchange(默认值):源页面元素移动到目的页元素位置,并进行适当缩放。
  • static:目的页元素位置不变,用户可配置透明度动画。当前仅跳转目标页配置的static效果生效。
-

shared-transition-name

-

string

-

-

-

转场时,目的页配置的样式优先生效。该样式用于配置共享元素的动画效果,一个由@keyframes定义的动画序列,支持transform和透明度动画。若共享元素效果与自定义的动画冲突,以自定义动画为准。

-

shared-transition-timing-function

-

string

-

friction

-

转场时,目的页配置的样式优先生效。该属性定义了共享元素转场时的差值曲线。若不配置,默认使用friction曲线。

-
- -### 注意事项 - -1. 若同时配置了共享元素转场和自定义页面转场样式,页面转场效果以自定义效果为准。 - -2. 共享元素的exchange效果类似下图。 - -**图 1** 共享元素转场默认效果 -![](/images/application-dev/reference/arkui-js/figures/共享元素转场默认效果.png "共享元素转场默认效果") - -3. 共享元素动画对元素的边框、背景色不生效。 - -4. 共享元素转场时,由于页面元素会被隐藏,故页面元素配置的动画样式/动画方法失效。 - -5. 动态修改shareid5+:组件A的shareid被组件B的shareid覆盖,则组件A的共享元素效果失效,即使组件B的shareid被修改,此时组件A的共享元素效果也不会恢复。 - -### 示例 - -PageA跳转到PageB,跳转的共享元素为image, shareid为“shareImage”。 - -``` - - -
- - -
- - Click on picture to Jump to ths details -
-
-
-
-``` - -``` -// xxx.js -import router from '@system.router'; -export default { - jump() { - router.push({ - uri: 'detailpage', - }); - }, -} -``` - -``` -/* xxx.css */ -.shared-transition-style { - shared-transition-effect: exchange; - shared-transition-name: shared-transition; -} -@keyframes shared-transition { - from { opacity: 0; } - to { opacity: 1; } -} -``` - -``` - - -
- -
-``` - -``` -// xxx.js -import router from '@system.router'; -export default { - jumpBack() { - router.back(); - }, -} -``` - -``` -/* xxx.css */ -.shared-transition-style { - shared-transition-effect: exchange; - shared-transition-name: shared-transition; -} -@keyframes shared-transition { - from { opacity: 0; } - to { opacity: 1; } -} -``` - -## 卡片转场样式 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->卡片转场无法和其他转场\(包括共享元素转场和自定义转场\)共同使用。 - -### 样式 - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

描述

-

transition-effect

-

string

-

-

-

用于配置当前页面中的某个组件在卡片转场过程中是否进行转场动效,当前支持如下配置:

-
  • unfold:配置这个属性的组件,如在卡片的上方,则向上移动一个卡片的高度,如在卡片的下方,则向下移动一个卡片的高度。
  • none:转场过程中没有动效。
-
- -### 示例 - -source\_page包含顶部内容以及卡片列表,点击卡片可以跳转到target\_page。 - -``` - - -
-
- MAIN TITLE -
- - - {{$item.title}} - - -
-``` - -``` -// xxx.js -import router from '@system.router' -export default { - data: { list: [] }, - onInit() { - for(var i = 0; i < 10; i++) { - var item = { uri: "pages/card_transition/target_page/index", - title: "this is title" + i, id: "item_" + i } - this.list.push(item); - } - }, - jumpPage(id, uri) { - var cardId = this.$element(id).ref; - router.push({ uri: uri, params : { ref : cardId } }); - } -} -``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - align-items: center; - background-color: #ABDAFF; -} -.item { - height: 80px; - background-color: #FAFAFA; - margin-top: 2px; -} -.outer { - width: 300px; - height: 100px; - align-items: flex-end; - transition-effect: unfold; -} -``` - -``` - - -
-
- this is detail -
-
-``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - align-items: center; - background-color: #EBFFD7; -} -.div { - height: 600px; - flex-direction: column; - align-items: center; - justify-content: center; -} -``` - -![](/images/application-dev/reference/arkui-js/figures/卡片转场.gif) - -## 页面转场样式 - -### 样式 - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

描述

-

transition-enter

-

string

-

-

-

与@keyframes配套使用,支持transform和透明度动画,详见表2

-

transition-exit

-

string

-

-

-

与@keyframes配套使用,支持transform和透明度动画,详见表2

-

transition-duration

-

string

-

跟随设备默认的页面转场时间

-

支持的单位为[s(秒)|ms(毫秒) ],默认单位为ms,未配置时使用系统默认值。

-

transition-timing-function

-

string

-

friction

-

描述转场动画执行的速度曲线,用于使转场更为平滑。详细参数见动画样式中“animation-timing-function”有效值说明。

-
- -### 注意事项 - -1. 配置自定义转场时,建议配置页面背景色为不透明颜色,否则在转场过程中可能会出现衔接不自然的现象。 -2. transition-enter和transition-exit可单独配置,没有配置时使用系统默认的参数。 -3. transition-enter/transition-exit说明如下: - 1. push场景下:进入页面栈的Page2.js应用transition-enter描述的动画配置;进入页面栈第二位置的Page1.js应用transition-exit描述的动画配置。 - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001193704354.png) - - 2. back场景下:退出页面栈的Page2.js应用transition-enter描述的动画配置,并进行倒播;从页面栈第二位置进入栈顶位置的Page1.js应用transition-exit描述的动画配置,并进行倒播。 - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001238184345.png) - - - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/08.\345\252\222\344\275\223\346\237\245\350\257\242.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/08.\345\252\222\344\275\223\346\237\245\350\257\242.md" deleted file mode 100644 index 0474259ceac4bc3f0e4699a7dd8700940e06e0a6..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/08.\345\252\222\344\275\223\346\237\245\350\257\242.md" +++ /dev/null @@ -1,312 +0,0 @@ ---- -title: 媒体查询 -permalink: /pages/010c0201010108 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# 媒体查询 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->- media属性值默认为设备的真实尺寸大小、物理像素和真实的屏幕分辨率。请勿与以720px为基准的项目配置宽度px混淆。 - -媒体查询(Media Query)在移动设备上应用十分广泛,开发者经常需要根据设备的大致类型或者特定的特征和设备参数(例如屏幕分辨率)来修改应用的样式。为此媒体查询提供了如下功能: - -1. 针对设备和应用的属性信息,可以设计出相匹配的布局样式。 -2. 当屏幕发生动态改变时(比如分屏、横竖屏切换),应用页面布局同步更新。 - -## CSS语法规则 - -使用@media来引入查询语句,具体规则如下: - -``` -@media [media-type] [and|not|only] [(media-feature)] { - CSS-Code; -} -``` - -例子: - -@media screen and \(round-screen: true\) \{ … \} // 当设备屏幕是圆形时条件成立 - -@media \(max-height: 800\) \{ … \} // 范围查询,CSS level 3 写法 - -@media \(height <= 800\) \{ … \} // 范围查询,CSS level 4 写法,与CSS level3写法等价 - -@media screen and \(device-type: tv\) or \(resolution < 2\) \{ … \} // 同时包含媒体类型和多个媒体特征的多条件复杂语句查询 - -## 页面中引用资源 - -通过@import方式引入媒体查询,具体使用方法如下: - -``` -@import url [media-type] [and|not|only] [(media-feature)]; -``` - -例如: - -``` -@import '../common/style.css' screen and (min-width: 600) and (max-width: 1200); -``` - -## 媒体类型 - - - - - - - - - -

类型

-

说明

-

screen

-

按屏幕相关参数进行媒体查询。

-
- -## 媒体逻辑操作 - -媒体逻辑操作符:and、or、not、only用于构成复杂媒体查询,也可以通过comma(,)将其组合起来,详细解释说明如下表。 - -**表 1** 媒体逻辑操作符 - - - - - - - - - - - - - - - - - - - - - -

类型

-

说明

-

and

-

将多个媒体特征(Media Feature)以“与”的方式连接成一个媒体查询,只有当所有媒体特征都为true,查询条件成立。另外,它还可以将媒体类型和媒体功能结合起来。

-

例如:screen and (device-type: wearable) and (max-height: 600) 表示当设备类型是智能穿戴同时应用的最大高度小于等于600个像素单位时成立。

-

not

-

取反媒体查询结果,媒体查询结果不成立时返回true,否则返回false。在媒体查询列表中应用not,则not仅取反应用它的媒体查询。

-

例如:not screen and (min-height: 50) and (max-height: 600) 表示当应用高度小于50个像素单位或者大于600个像素单位时成立。

-
说明:

使用not运算符时必须指定媒体类型。

-
-

only

-

当整个表达式都匹配时,才会应用选择的样式,可以应用在防止某些较早的版本的浏览器上产生歧义的场景。一些较早版本的浏览器对于同时包含了媒体类型和媒体特征的语句会产生歧义,比如:

-

screen and (min-height: 50)

-

老版本浏览器会将这句话理解成screen,从而导致仅仅匹配到媒体类型(screen),就应用了指定样式,使用only可以很好地规避这种情况。

-
说明:

使用only时必须指定媒体类型。

-
-

,(comma)

-

将多个媒体特征以“或”的方式连接成一个媒体查询,如果存在结果为true的媒体特征,则查询条件成立。其效果等同于or运算符。

-

例如:screen and (min-height: 1000), (round-screen:true) 表示当应用高度大于等于1000个像素单位或者设备屏幕是圆形时,条件成立。

-

or

-

将多个媒体特征以“或”的方式连接成一个媒体查询,如果存在结果为true的媒体特征,则查询条件成立。

-

例如:screen and (max-height: 1000) or (round-screen:true)表示当应用高度小于等于1000个像素单位或者设备屏幕是圆形时,条件成立。

-
- -在MediaQuery Level 4中引入了范围查询,使其能够使用max-,min-的同时,也支持了<=,\>=,<,\>操作符。 - -**表 2** 媒体逻辑范围操作符 - - - - - - - - - - - - - - - - - - -

类型

-

说明

-

<=

-

小于等于,例如:screen and (height <= 50)。

-

>=

-

大于等于,例如:screen and (height >= 600)。

-

<

-

小于,例如:screen and (height < 50)。

-

>

-

大于,例如:screen and (height > 600)。

-
- -## 媒体特征 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

类型

-

说明

-

height

-

应用页面显示区域的高度。

-

min-height

-

应用页面显示区域的最小高度。

-

max-height

-

应用页面显示区域的最大高度。

-

width

-

应用页面显示区域的宽度。

-

min-width

-

应用页面显示区域的最小宽度。

-

max-width

-

应用页面显示区域的最大宽度。

-

resolution

-

设备的分辨率,支持dpi,dppx和dpcm单位。其中:

-
  • dpi表示每英寸中物理像素个数,1dpi≈0.39dpcm;
  • dpcm表示每厘米上的物理像素个数,1dpcm ≈ 2.54dpi;
  • dppx表示每个px中的物理像素数(此单位按96px=1英寸为基准,与页面中的px单位计算方式不同),1dppx = 96dpi。
-

min-resolution

-

设备的最小分辨率。

-

max-resolution

-

设备的最大分辨率。

-

orientation

-

屏幕的方向。

-

可选值:

-
  • orientation: portrait(设备竖屏)
  • orientation: landscape(设备横屏)
-

aspect-ratio

-

应用页面显示区域的宽度与高度的比值。

-

例如:aspect-ratio:1/2

-

min-aspect-ratio

-

应用页面显示区域的宽度与高度的最小比值。

-

max-aspect-ratio

-

应用页面显示区域的宽度与高度的最大比值。

-

device-height

-

设备的高度。

-

min-device-height

-

设备的最小高度。

-

max-device-height

-

设备的最大高度。

-

device-width

-

设备的宽度。

-

min-device-width

-

设备的最小宽度。

-

max-device-width

-

设备的最大宽度。

-

round-screen

-

屏幕类型,圆形屏幕为true, 非圆形屏幕为 false。

-

dark-mode6+

-

系统为深色模式时为true,否则为false。

-
- -## 示例代码 - -- 通用媒体特征示例代码: - -``` - -
-
- Hello World -
-
-``` - -``` -/* xxx.css */ -.container { - width: 300px; - height: 600px; - background-color: #008000; -} -@media (device-type: tv) { - .container { - width: 500px; - height: 500px; - background-color: #fa8072; - } -} -@media (device-type: wearable) { - .container { - width: 300px; - height: 300px; - background-color: #008b8b; - } -} -``` - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/09.\350\207\252\345\256\232\344\271\211\345\255\227\344\275\223\346\240\267\345\274\217.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/09.\350\207\252\345\256\232\344\271\211\345\255\227\344\275\223\346\240\267\345\274\217.md" deleted file mode 100644 index 47aad6988720376da8da2480400710ea319b4865..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/09.\350\207\252\345\256\232\344\271\211\345\255\227\344\275\223\346\240\267\345\274\217.md" +++ /dev/null @@ -1,66 +0,0 @@ ---- -title: 自定义字体样式 -permalink: /pages/010c0201010109 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# 自定义字体样式 - -font-face用于定义字体样式。应用可以在style中定义font-face来指定相应的字体名和字体资源,然后在font-family样式中引用该字体。 - -自定义字体可以是从项目中的字体文件中加载的字体,字体格式支持ttf和otf。 - -## 定义font-face - -``` -@font-face { - font-family: HWfont; - src: url('/common/HWfont.ttf'); -} -``` - -**font-family:** - -自定义字体的名称。 - -**src:** - -自定义字体的来源,支持如下类别: - -- 项目中的字体文件:通过url指定项目中的字体文件路径\(只支持绝对路径,详见[资源和文件访问规则](/pages/010802020201)章节\)。 - -- 不支持设置多个src。 - -## 使用font-face - -可以在style中定义font-face,然后在font-family样式中指定该font-face的名称,从而应用font-face定义的字体。 - -**示例:** - -页面布局: - -``` -
- 测试自定义字体 -
-``` - -页面样式: - -``` -@font-face { - font-family: HWfont; - src: url("/common/HWfont.ttf"); -} -.demo-text { - font-family: HWfont; -} -``` - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/10.\345\216\237\345\255\220\345\270\203\345\261\200.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/10.\345\216\237\345\255\220\345\270\203\345\261\200.md" deleted file mode 100644 index 015b3bba40a513e6d43f9e9ba24e2c7f8e444061..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/10.\345\216\237\345\255\220\345\270\203\345\261\200.md" +++ /dev/null @@ -1,97 +0,0 @@ ---- -title: 原子布局 -permalink: /pages/010c020101010a -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# 原子布局 - -在屏幕形态和规格不同等情况下,布局效果需要实现自适应,因此系统提供了面向不同屏幕尺寸界面自适应适配的布局能力,称为原子布局。设计师可以考虑使用原子能力,定义元素在不同形态的尺寸界面上体现的自适应规则。开发者可以使用原子布局能力,快速实现让应用在多形态屏幕上有与设计效果相匹配的自适应效果。 - -## 隐藏能力 - -在非折行flex布局基础上,增加了显示优先级标记,可以调整组件内元素水平/垂直方向的显示优先级,根据当前组件容器的可用空间来显示内容。 - - - - - - - - - - - - - -

样式

-

类型

-

默认值

-

说明

-

display-index

-

number

-

0

-

适用于div等支持flex布局的容器组件中的子组件上,当容器组件在flex主轴上尺寸不足以显示全部内容时,按照display-index值从小到大的顺序进行隐藏,具有相同display-index值的组件同时隐藏,默认值为0,表示隐藏。

-
- -## 占比能力 - -在非折行的flex布局中,定义了占比能力的组件,保证指定元素始终在容器的某一个比例空间中进行布局。 - - - - - - - - - - - - - -

样式

-

类型

-

默认值

-

说明

-

flex-weight

-

number

-

-

-

指明当前元素在flex主轴方向上尺寸权值,当且仅当容器组件中所有节点均设置此属性时生效,当前元素尺寸为: 容器主轴尺寸 * 当前权值 / 所有子元素权值和。

-
- -## 固定比例 - -定义了组件固定比例调整尺寸的能力。 - - - - - - - - - - - - - -

样式

-

类型

-

默认值

-

说明

-

aspect-ratio

-

number

-

-

-

1. 接受任意大于0的浮点值,定义为该节点的宽度与高度比,设置该属性后,该元素尺寸宽高比按照此属性值进行调整。

-

2. 遵守最大值与最小值的限制。

-

3. 在flex布局中,主轴尺寸先进行调整,后根据该尺寸调整交叉轴。

-
- diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/01.badge.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/01.badge.md" deleted file mode 100644 index 69f59c209e3618a3e8b0751b05961bcac226b1d8..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/01.badge.md" +++ /dev/null @@ -1,246 +0,0 @@ ---- -title: badge -permalink: /pages/010c0201010201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# badge - -应用中如果有需用户关注的新事件提醒,可以采用新事件标记来标识。 - -## 权限列表 - -无 - -## 子组件 - -支持单个子组件。 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->仅支持单子组件节点,如果使用多子组件节点,默认使用第一个子组件节点。 - -## 属性 - -除支持[通用属性](/pages/010c0201010101)外,还支持如下属性: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

placement

-

string

-

rightTop

-

-

事件提醒的数字标记或者圆点标记的位置,可选值为:

-
  • right:位于组件右边框。
  • rightTop:位于组件边框右上角。
  • left:位于组件左边框。
-

count

-

number

-

0

-

-

设置提醒的消息数,默认为0。当设置相应的提醒消息数大于0时,消息提醒会变成数字标记类型,未设置消息数或者消息数不大于0时,消息提醒将采用圆点标记。

-
说明:

当数字设置为大于maxcount时,将使用maxcount显示。

-

count属性最大支持整数值为2147483647。

-
-

visible

-

boolean

-

false

-

-

是否显示消息提醒,当收到新信息提醒时可以设置该属性为true,显示相应的消息提醒,如果需要使用数字标记类型,同时需要设置相应的count属性。

-

maxcount

-

number

-

99

-

-

最大消息数限制,当收到新信息提醒大于该限制时,标识数字会进行省略,仅显示maxcount+。

-
说明:

maxcount属性最大支持整数值为2147483647。

-
-

config

-

BadgeConfig

-

-

-

-

设置新事件标记相关配置属性。

-

label6+

-

string

-

-

-

-

设置新事件提醒的文本值。

-
说明:

使用该属性时,count和maxcount属性不生效。

-
-
- -**表 1** BadgeConfig - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

badgeColor

-

<color>

-

#fa2a2d

-

-

新事件标记背景色。

-

textColor

-

<color>

-

#ffffff

-

-

数字标记的数字文本颜色。

-

textSize

-

<length>

-

10px

-

-

数字标记的数字文本大小。

-

badgeSize

-

<length>

-

6px

-

-

圆点标记的默认大小

-
- -## 样式 - -支持[通用样式](/pages/010c0201010102)。 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->badge组件的子组件大小不能超过badge组件本身的大小,否则子组件不会绘制。 - -## 事件 - -支持[通用事件](/pages/010c0201010103)。 - -## 方法 - -支持[通用方法](/pages/010c0201010104)。 - -## 示例 - -``` - -
- - example - - - example - -
-``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - width: 100%; - align-items: center; -} -.badge { - width: 50%; - margin-top: 100px; -} -.text1 { - background-color: #f9a01e; - font-size: 50px; -} -.text2 { - background-color: #46b1e3; - font-size: 50px; -} -``` - -``` -// xxx.js -export default { - data:{ - badgeconfig:{ - badgeColor:"#0a59f7", - textColor:"#ffffff", - } - } -} -``` - -![](/images/application-dev/reference/arkui-js/figures/捕获.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/02.dialog.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/02.dialog.md" deleted file mode 100644 index 7e1ab924721c01a9f76dbdeddc1c406ae61e1ff5..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/02.dialog.md" +++ /dev/null @@ -1,235 +0,0 @@ ---- -title: dialog -permalink: /pages/010c0201010202 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# dialog - -自定义弹窗容器。 - -## 权限列表 - -无 - -## 子组件 - -支持单个子组件。 - -## 属性 - -除支持[通用属性](/pages/010c0201010101)外,支持如下属性: - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

dragable7+

-

boolean

-

false

-

-

设置对话框是否支持拖拽。

-
- ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->- 弹窗类组件不支持focusable、click-effect属性。 - -## 样式 - -仅支持[通用样式](/pages/010c0201010102)中的width、height、margin、margin-\[left|top|right|bottom\]、margin-\[start|end\]样式。 - -## 事件 - -不支持[通用事件](/pages/010c0201010103),仅支持如下事件: - - - - - - - - - - - - - - - - - - - -

名称

-

参数

-

描述

-

cancel

-

-

-

用户点击非dialog区域触发取消弹窗时触发的事件。

-

show7+

-

-

-

对话框弹出时触发该事件。

-

close7+

-

-

-

对话框关闭时触发该事件。

-
- -## 方法 - -不支持[通用方法](/pages/010c0201010104),仅支持如下方法。 - - - - - - - - - - - - - - - -

名称

-

参数

-

描述

-

show

-

-

-

弹出对话框。

-

close

-

-

-

关闭对话框。

-
- ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->dialog属性、样式均不支持动态更新。 - -## 示例 - -``` - -
-
- -
- -
-
- Simple dialog -
-
- - -
-
-
-
-``` - -``` -/* xxx.css */ -.doc-page { - flex-direction: column; - justify-content: center; - align-items: center; -} -.btn-div { - width: 100%; - height: 200px; - flex-direction: column; - align-items: center; - justify-content: center; -} -.btn { - background-color: #F2F2F2; - text-color: #0D81F2; -} -.txt { - color: #000000; - font-weight: bold; - font-size: 39px; -} -.dialog-main { - width: 500px; -} -.dialog-div { - flex-direction: column; - align-items: center; -} -.inner-txt { - width: 400px; - height: 160px; - flex-direction: column; - align-items: center; - justify-content: space-around; -} -.inner-btn { - width: 400px; - height: 120px; - justify-content: space-around; - align-items: center; -} -.btn-txt { - background-color: #F2F2F2; - text-color: #0D81F2; -} -``` - -``` -// xxx.js -import prompt from '@system.prompt'; -export default { - showDialog(e) { - this.$element('simpledialog').show() - }, - cancelDialog(e) { - prompt.showToast({ - message: 'Dialog cancelled' - }) - }, - cancelSchedule(e) { - this.$element('simpledialog').close() - prompt.showToast({ - message: 'Successfully cancelled' - }) - }, - setSchedule(e) { - this.$element('simpledialog').close() - prompt.showToast({ - message: 'Successfully confirmed' - }) - }, - doubleclick(e){ - prompt.showToast({ - message: 'doubleclick' - }) - } -} -``` - -![](/images/application-dev/reference/arkui-js/figures/4.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/03.div.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/03.div.md" deleted file mode 100644 index 4a5ac2925ad6d4de7b6c18c902bde00bd0a8bb3b..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/03.div.md" +++ /dev/null @@ -1,715 +0,0 @@ ---- -title: div -permalink: /pages/010c0201010203 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# div - -基础容器,用作页面结构的根节点或将内容进行分组。 - -## 权限列表 - -无 - -## 子组件 - -支持。 - -## 属性 - -支持[通用属性](/pages/010c0201010101)。 - -## 样式 - -除支持[组件通用样式](/pages/010c0201010102)外,还支持如下样式: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

flex-direction

-

string

-

row

-

-

flex容器主轴方向。可选项有:

-
  • column:垂直方向从上到下。
  • row:水平方向从左到右。
-

flex-wrap

-

string

-

nowrap

-

-

flex容器是单行还是多行显示,该值暂不支持动态修改。可选项有:

-
  • nowrap:不换行,单行显示。
  • wrap:换行,多行显示。
-

justify-content

-

string

-

flex-start

-

-

flex容器当前行的主轴对齐格式。可选项有:

-
  • flex-start:项目位于容器的开头。
  • flex-end:项目位于容器的结尾。
  • center:项目位于容器的中心。
  • space-between:项目位于各行之间留有空白的容器内。
  • space-around:项目位于各行之前、之间、之后都留有空白的容器内。
  • space-evenly5+: 均匀排列每个元素,每个元素之间的间隔相等。
-

align-items

-

string

-

stretch

-

-

flex容器当前行的交叉轴对齐格式,可选值为:

-
  • stretch:弹性元素在交叉轴方向被拉伸到与容器相同的高度或宽度。
  • flex-start:元素向交叉轴起点对齐。
  • flex-end:元素向交叉轴终点对齐。
  • center:元素在交叉轴居中。
-

align-content

-

string

-

flex-start

-

-

交叉轴中有额外的空间时,多行内容对齐格式,可选值为:

-
  • flex-start:所有行从交叉轴起点开始填充。第一行的交叉轴起点边和容器的交叉轴起点边对齐。接下来的每一行紧跟前一行。
  • flex-end:所有行从交叉轴末尾开始填充。最后一行的交叉轴终点和容器的交叉轴终点对齐。同时所有后续行与前一个对齐。
  • center:所有行朝向容器的中心填充。每行互相紧挨,相对于容器居中对齐。容器的交叉轴起点边和第一行的距离相等于容器的交叉轴终点边和最后一行的距离。
  • space-between:所有行在容器中平均分布。相邻两行间距相等。容器的交叉轴起点边和终点边分别与第一行和最后一行的边对齐。
  • space-around:所有行在容器中平均分布,相邻两行间距相等。容器的交叉轴起点边和终点边分别与第一行和最后一行的距离是相邻两行间距的一半。
-

display

-

string

-

flex

-

-

确定该元素视图框的类型,该值暂不支持动态修改。可选值为:

-
  • flex:弹性布局
  • grid:网格布局
  • none:不渲染此元素
-

grid-template-[columns|rows]

-

string

-

1行1列

-

-

用于设置当前网格布局行和列的数量,不设置时默认1行1列,仅当display为grid时生效。

-

示例:如设置grid-template-columns为:

-
  • 50px 100px 60px:分三列,第一列50px,第二列100px,第三列60px;
  • 1fr 1fr 2fr:分三列,将父组件允许的宽分为4等份,第一列占1份,第二列占一份,第三列占2份;
  • 30% 20% 50%:分三列,将父组件允许的宽为基准,第一列占30%,第二列占20%,第三列占50%;
  • repeat(2,100px):分两列,第一列100px,第二列100px;
  • repeat(auto-fill,100px)5+:按照每列100px的大小和交叉轴大小计算最大正整数重复次数,按照该重复次数布满交叉轴;
  • auto 1fr 1fr:分三列,第一列自适应内部子组件所需宽度,剩余空间分为两等份,第二列占一份,第三列占一份。
-

grid-[columns|rows]-gap

-

<length>

-

0

-

-

用于设置行与行的间距或者列与列的间距,也可以支持通过grid-gap设置相同的行列间距,仅当display为grid时生效。

-

grid-row-[start|end]

-

number

-

-

-

-

用于设置当前元素在网格布局中的起止行号,仅当父组件display样式为grid时生效(仅div支持display样式设置为grid)。

-

grid-column-[start|end]

-

number

-

-

-

-

用于设置当前元素在网格布局中的起止列号,仅当父组件display样式为grid时生效(仅div支持display样式设置为grid)。

-

grid-auto-flow5+

-

string

-

-

-

-

使用框架自动布局算法进行网格的布局,可选值为:

-
  • row:逐行填充元素,如果行空间不够,则新增行;
  • column:逐列填充元素,如果列空间不够,则新增列。
-

overflow6+

-

string

-

visible

-

-

设置元素内容区超过元素本身大小时的表现形式。

-
  • visible:多个子元素内容超过元素大小时,显示在元素外面;
  • hidden:元素内容超过元素大小时,进行裁切显示;
  • scroll:元素内容超过元素大小时,进行滚动显示并展示滚动条(当前只支持纵向)。
-
说明:
  • overflow: scroll样式需要元素设置固定的大小。
-
-

align-items6+

-

string

-

-

-

-

设置容器中元素交叉轴上的对齐方式:

-
  • stretch:Flex容器内容在交叉轴方向被拉伸到与容器相同的高度或宽度;
  • flex-start:Flex布局容器内元素向交叉轴起点对齐;
  • flex-end:Flex布局容器内元素向交叉轴终点对齐;
  • center:Flex布局容器内元素在交叉轴居中对齐;
  • baseline:如Flex布局纵向排列,则该值与'flex-start'等效。横向布局时,内容元素存在文本时按照文本基线对齐,否则底部对齐。
-

scrollbar-color6+

-

<color>

-

-

-

-

设置滚动条的颜色。

-

scrollbar-width6+

-

<length>

-

-

-

-

设置滚动条的宽度。

-

overscroll-effect6+

-

string

-

-

-

-

设置滚动边缘效果,可选值为:

-
  • spring:弹性物理动效,滑动到边缘后可以根据初始速度或通过触摸事件继续滑动一段距离,松手后回弹;
  • fade:渐隐物理动效,滑动到边缘后展示一个波浪形的渐隐,根据速度和滑动距离的变化渐隐也会发送一定的变化;
  • none:滑动到边缘后无效果
-
- -## 事件 - -除支持[通用事件](/pages/010c0201010103)外,还支持如下事件: - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数

-

描述

-

reachstart6+

-

-

-

当页面滑动到最开始的点时触发的事件回调,当flex-direction: row时才会触发。

-

reachend6+

-

-

-

当页面滑动到最末尾的点时触发的事件回调,当flex-direction: row时才会触发。

-

reachtop6+

-

-

-

当页面滑动到最上部的点时触发的事件回调,当flex-direction: column时才会触发。

-

reachbottom6+

-

-

-

当页面滑动到最下部的点时触发的事件回调,当flex-direction: column时才会触发。

-
- -## 方法 - -除支持[通用方法](/pages/010c0201010104)外,还支持如下方法: - - - - - - - - - - - - - - - - - - -

名称

-

参数

-

返回值

-

描述

-

getScrollOffset6+

-

-

-

ScrollOffset

-

获取元素内容的滚动偏移。

-
说明:
  • 需要设置overflow样式为scroll。
-
-

scrollBy6+

-

ScrollParam

-

-

-

指定元素内容的滚动偏移。

-
说明:
  • 需要设置overflow样式为scroll。
-
-
- -**表 1** ScrollOffset6+ - - - - - - - - - - - - - - - - -

名称

-

类型

-

描述

-

x

-

number

-

在x轴方向的偏移,单位为px。

-

y

-

number

-

在y轴方向的偏移,单位为px。

-
- -**表 2** ScrollParam6+ - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

描述

-

dx

-

number

-

水平方向滑动的偏移量,单位px。

-

dy

-

number

-

垂直方向滑动的偏移量,单位px。

-

smooth

-

boolean

-

是否平滑处理。

-
- -## 示例 - -1. Flex样式 - - ``` - -
-
-
-
-
-
-
- ``` - - ``` - /* xxx.css */ - .container { - flex-direction: column; - justify-content: center; - align-items: center; - width: 454px; - height: 454px; - } - .flex-box { - justify-content: space-around; - align-items: center; - width: 400px; - height: 140px; - background-color: #ffffff; - } - .flex-item { - width: 120px; - height: 120px; - border-radius: 16px; - } - .color-primary { - background-color: #007dff; - } - .color-warning { - background-color: #ff7500; - } - .color-success { - background-color: #41ba41; - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127285076.png) - -2. Flex Wrap样式 - - ``` - -
-
-
-
-
-
-
- ``` - - ``` - /* xxx.css */ - .container { - flex-direction: column; - justify-content: center; - align-items: center; - width: 454px; - height: 454px; - } - .flex-box { - justify-content: space-around; - align-items: center; - flex-wrap: wrap; - width: 300px; - height: 250px; - background-color: #ffffff; - } - .flex-item { - width: 120px; - height: 120px; - border-radius: 16px; - } - .color-primary { - background-color: #007dff; - } - .color-warning { - background-color: #ff7500; - } - .color-success { - background-color: #41ba41; - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/22.png) - -3. Grid样式 - - ``` - -
-
-
-
-
-
- ``` - - ``` - /* xxx.css */ - .common { - width: 400px; - height: 400px; - background-color: #ffffff; - align-items: center; - justify-content: center; - margin: 24px; - } - .grid-parent { - display: grid; - grid-template-columns: 35% 35%; - grid-columns-gap: 24px; - grid-rows-gap: 24px; - grid-template-rows: 35% 35%; - } - .grid-child { - width: 100%; - height: 100%; - border-radius: 8px; - } - .grid-left-top { - grid-row-start: 0; - grid-column-start: 0; - grid-row-end: 0; - grid-column-end: 0; - background-color: #3f56ea; - } - .grid-left-bottom { - grid-row-start: 1; - grid-column-start: 0; - grid-row-end: 1; - grid-column-end: 0; - background-color: #00aaee; - } - .grid-right-top { - grid-row-start: 0; - grid-column-start: 1; - grid-row-end: 0; - grid-column-end: 1; - background-color: #00bfc9; - } - .grid-right-bottom { - grid-row-start: 1; - grid-column-start: 1; - grid-row-end: 1; - grid-column-end: 1; - background-color: #47cc47; - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/11.png) - -4. 拖拽7+ - - ``` - -
-
-
-
- ``` - - ``` - /* xxx.css */ - .container { - flex-direction: column; - } - .content{ - width: 200px; - height: 200px; - background-color: red; - } - ``` - - ``` - // xxx.js - import prompt from '@system.prompt'; - export default { - data:{ - left:0, - top:0, - }, - dragstart(e){ - prompt.showToast({ - message: 'Start to be dragged' - }) - }, - drag(e){ - this.left = e.globalX; - this.top = e.globalY; - }, - dragend(e){ - prompt.showToast({ - message: 'End Drag' - }) - }, - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/9.gif) - - ``` - -
-
-
-
-
- ``` - - ``` - /* xxx.css */ - .container { - flex-direction: column; - width: 100%; - position: relative; - max-width: 100%; - } - .content{ - width: 200px; - height: 200px; - background-color: red; - position: absolute; - } - ``` - - ``` - // xxx.js - import prompt from '@system.prompt'; - export default { - data:{ - left:0, - top:0, - }, - drag(e){ - this.left = e.globalX; - this.top = e.globalY; - }, - dragenter(e){ - prompt.showToast({ - message: 'enter' - }) - }, - dragover(e){ - prompt.showToast({ - message: 'over' - }) - }, - dragleave(e){ - prompt.showToast({ - message: 'leave' - }) - }, - drop(e){ - prompt.showToast({ - message: 'drop' - }) - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/6.gif) - -5. 手指捏合7+ - - ``` - -
-
-
-
- ``` - - ``` - /* xxx.css */ - .container { - flex-direction: column; - justify-content: center; - align-items: center; - width: 454px; - height: 454px;} - .content{ - width: 400px; - height: 400px; - background-color: aqua; - margin:30px - } - ``` - - ``` - // xxx.js - import prompt from '@system.prompt'; - export default { - pinchstart(e){ - prompt.showToast({ - message: 'pinchstart!!!' - }) - }, - pinchupdate(e){ - prompt.showToast({ - message: 'Two-finger pinch update' - }) - }, - pinchend(e){ - prompt.showToast({ - message: 'Finished with two fingers pinching' - }) - }, - pinchcancel(e){ - prompt.showToast({ - message: 'Finger pinching is interrupted' - }) - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/5.gif) - - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/04.form.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/04.form.md" deleted file mode 100644 index 30704415c961e8b3d2f3fd05e5bfe388e807ecb3..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/04.form.md" +++ /dev/null @@ -1,122 +0,0 @@ ---- -title: form -permalink: /pages/010c0201010204 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# form - -表单容器,支持容器内input元素的内容提交和重置。 - -## 权限列表 - -无 - -## 子组件 - -支持。 - -## 属性 - -支持[通用属性](/pages/010c0201010101)。 - -## 样式 - -支持[组件通用样式](/pages/010c0201010102)。 - -## 事件 - -处支持[通用事件](/pages/010c0201010103)外,还支持如下事件: - - - - - - - - - - - - - - - -

名称

-

参数

-

描述

-

submit

-

FormResult

-

点击提交按钮,进行表单提交时,触发该事件。

-

reset

-

-

-

点击重置按钮后,触发该事件。

-
- -**表 1** FormResult - - - - - - - - - - - - -

名称

-

类型

-

描述

-

value

-

Object

-

input元素的name和value的值。

-
- -## 方法 - -支持[通用方法](/pages/010c0201010104)。 - -## 示例 - -``` - -
-
- - - - -
- 输入文本 - -
- Submit - Reset -
-
-``` - -``` -// xxx.js -export default{ - onSubmit(result) { - console.log(result.value.radioGroup) // radio1 or radio2 - console.log(result.value.user) // text input value - }, - onReset() { - console.log('reset all value') - } -} -``` - -![](/images/application-dev/reference/arkui-js/figures/001.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/05.list.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/05.list.md" deleted file mode 100644 index 057ecd10781f74047c5e8fae74c6bb81b924f679..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/05.list.md" +++ /dev/null @@ -1,687 +0,0 @@ ---- -title: list -permalink: /pages/010c0201010205 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# list - -列表包含一系列相同宽度的列表项。适合连续、多行呈现同类数据,例如图片和文本。 - -## 权限列表 - -无 - -## 子组件 - -仅支持<[list-item-group](/pages/010c0201010207)\>和<[list-item](/pages/010c0201010206)\>。 - -## 属性 - -除支持[通用属性](/pages/010c0201010101)外,还支持如下属性: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

scrollpage

-

boolean

-

false

-

-

设置为true时,将 list 顶部页面中非 list 部分随 list 一起滑出可视区域,当list方向为row时,不支持此属性。

-

cachedcount

-

number

-

0

-

-

长列表延迟加载时list-item最少缓存数量。

-

可视区域外缓存的list-item数量少于该值时,会触发requestitem事件。

-

scrollbar

-

string

-

off

-

-

侧边滑动栏的显示模式(当前只支持纵向):

-
  • off:不显示。
  • auto:按需显示(触摸时显示,2s后消失)。
  • on:常驻显示。
-

scrolleffect

-

string

-

spring

-

-

滑动效果,目前支持如下滑动效果:

-
  • spring:弹性物理动效,滑动到边缘后可以根据初始速度或通过触摸事件继续滑动一段距离,松手后回弹。
  • fade:渐隐物理动效,滑动到边缘后展示一个波浪形的渐隐,根据速度和滑动距离的变化渐隐也会发送一定的变化。
  • no:滑动到边缘后无效果。
-

indexer

-

boolean | Array<string>

-

false

-

-

是否展示侧边栏快速字母索引栏。设置为true或者自定义索引时,索引栏会显示在列表右边界处。示例:

-

"indexer" : "true"表示使用默认字母索引表。

-

"indexer" : "false"表示无索引。

-

"indexer" : ['#',‘1’,'2',‘3’,'4',‘5’,'6',‘7’,'8']表示自定义索引表。自定义时"#"必须要存在。

-
说明:
  • indexer属性生效需要flex-direction属性配合设置为column,且columns属性设置为1。
  • 点击索引条进行列表项索引需要list-item子组件配合设置相应的section属性
-
-

indexercircle5+

-

boolean

-

-

-

-

是否为环形索引。

-

穿戴设备默认为true,其他为false。indexer为false时不生效。

-

indexermulti5+

-

boolean

-

false

-

-

是否开启索引条多语言功能。

-

indexer为false时不生效。

-

indexerbubble5+

-

boolean

-

true

-

-

是否开启索引切换的气泡提示。

-

indexer为false时不生效。

-

divider5+

-

boolean

-

false

-

-

item是否自带分隔线。

-

其样式参考样式列表的divider-color、divider-height、divider-length、divider-origin。

-

shapemode

-

string

-

default

-

-

侧边滑动栏的形状类型。

-
  • default:不指定,跟随主题;
  • rect:矩形;
  • round:圆形。
-

updateeffect

-

boolean

-

false

-

-

用于设置当list内部的item发生删除或新增时是否支持动效。

-
  • false:新增删除item时无过渡动效。
  • true:新增删除item时播放过程动效。
-

chainanimation5+

-

boolean

-

false

-

-

用于设置当前list是否启用链式联动动效,开启后列表滑动以及顶部和底部拖拽时会有链式联动的效果。链式联动效果:list内的list-item间隔一定距离,在基本的滑动交互行为下,主动对象驱动从动对象进行联动,驱动效果遵循弹簧物理动效。

-
  • false:不启用链式联动
  • true:启用链式联动
    说明:
    • 不支持动态修改。
    • 如同时配置了indexer,链式动效不生效。
    • 如配置了链式动效,list-item的sticky不生效。
    -
    -
-

initialindex

-

number

-

0

-

-

用于设置当前List初次加载时视口起始位置显示的item,默认为0,即显示第一个item,如设置的序号超过了最后一个item的序号,则设置不生效,当同时设置了initialoffset属性时,当前属性不生效。当indexer为true或者scrollpage为true时,不生效。

-

initialoffset

-

<length>

-

0

-

-

用于设置当前List初次加载时视口的起始偏移量,偏移量无法超过当前List可滑动的范围,如果超过会被截断为可滑动范围的极限值。当indexer为true或者scrollpage为true时,不生效。

-

selected5+

-

string

-

-

-

-

指定当前列表中被选中激活的项,可选值为list-item的section属性值。

-
- -## 样式 - -除支持[通用样式](/pages/010c0201010102)外,还支持如下样式: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

divider-color5+

-

<color>

-

transparent

-

-

item分隔线颜色,仅当list的divider属性为true时生效。

-

divider-height5+

-

<length>

-

1

-

-

item分隔线高度,仅当list的divider属性为true时生效。

-

divider-length5+

-

<length>

-

主轴宽度

-

-

item分隔线长度,不设置时最大长度为主轴宽度,具体长度取决于divider-origin,仅当list的divider属性为true时生效。

-

divider-origin5+

-

<length>

-

0

-

-

item分隔线相对于item主轴起点位置的偏移量,仅当list的divider属性为true时生效。

-

flex-direction

-

string

-

-

column

-

-

设置flex容器主轴的方向,指定flex项如何放置在flex容器中,可选值为:

-
  • column:主轴为纵向。
  • row:主轴为横向。
-

其他组件默认值为row,在list组件中默认值为column。

-

columns

-

number

-

1

-

-

list交叉轴方向的显示列数,默认为1列。

-
说明:

设置多列时,在list交叉轴上进行均分,每一列大小相同。

-
-

align-items

-

string

-

stretch

-

-

list每一列交叉轴上的对齐格式,可选值为:

-
  • stretch:弹性元素被在交叉轴方向被拉伸到与容器相同的高度或宽度。
  • flex-start:元素向交叉轴起点对齐。
  • flex-end:元素向交叉轴终点对齐。
  • center:元素在交叉轴居中。
    说明:

    align-items样式作用在每一列的子元素上,列与列之间采用均分方式布局。

    -
    -
-

item-extent

-

<length> | <percentage>

-

-

-

-

设置内部item为固定大小,设置为百分比格式时,指相对于list的视口主轴方向长度的百分比。

-

fade-color

-

<color>

-

grey

-

-

设置渐隐物理动效的颜色。当滑动效果设置为渐隐物理动效时生效。

-

scrollbar-color6+

-

<color>

-

-

-

-

设置滚动条的颜色。

-

scrollbar-width6+

-

<length>

-

-

-

-

设置滚动条的宽度。

-

scrollbar-offset6+

-

<length>

-

0

-

-

设置滚动条距离List默认位置的偏移量,只支持正数,默认位置在List右边缘,可以通过这个偏移量调整滚动条的水平位置,如果滚动条绘制在list外部,而list父组件有裁剪,会导致滚动条被裁剪。

-
- -## 事件 - -除支持[通用事件](/pages/010c0201010103)外,还支持如下事件: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数

-

描述

-

indexerchange5+

-

{ local: booleanValue }

-

多语言索引条切换事件,仅当indexer属性为true,indexermulti为true时生效。booleanValue可能值为true或者false:

-
  • true: 当前展示本地索引。
  • false: 当前展示字母索引。
-

scroll

-

{ scrollX: scrollXValue, scrollY: scrollYValue, scrollState: stateValue }

-

列表滑动的偏移量和状态回调。

-

stateValue: 0表示列表滑动已经停止。

-

stateValue: 1表示列表正在用户触摸状态下滑动。

-

stateValue: 2表示列表正在用户松手状态下滑动。

-

scrollbottom

-

-

-

当前列表已滑动到底部位置。

-

scrolltop

-

-

-

当前列表已滑动到顶部位置。

-

scrollend

-

-

-

列表滑动已经结束。

-

scrolltouchup

-

-

-

手指已经抬起且列表仍在惯性滑动。

-

requestitem

-

-

-

请求创建新的list-item。

-

长列表延迟加载时,可视区域外缓存的list-item数量少于cachedcount时,会触发该事件。

-

rotate7+

-

{ rotateValue: number }

-

返回表冠旋转角度增量值,仅智能穿戴支持。

-
- -## 方法 - -支持[通用方法](/pages/010c0201010104)外,还支持如下方法: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数

-

描述

-

scrollTo

-

{ index: number(指定位置) }

-

list滑动到指定index的item位置。

-

scrollBy

-

ScrollParam

-

触发list滑动一段距离。

-

智慧屏特有方法。

-

scrollTop

-

{ smooth: boolean }

-

smooth缺省为false,表示直接滚动到顶部。

-

smooth为true,表示平滑滚动到顶部。

-

scrollBottom

-

{ smooth: boolean }

-

smooth缺省为false,表示直接滚动到底部。

-

smooth为true,表示平滑滚动到底部。

-

scrollPage

-

{ reverse: boolean, smooth: boolean }

-

reverse缺省值为false,表示下一页,无完整页则滚动到底部。

-

reverse为true,表示上一页,无完整页则滚动到顶部。

-

smooth缺省值为false,表示直接滚动一页。

-

smooth为true,表示平滑滚动一页。

-

scrollArrow

-

{ reverse: boolean, smooth: boolean }

-

reverse缺省值为false,表示向底部方向滑动一段距离,无足够距离则滚动到底部。

-

reverse为true,表示向顶部方向滑动一段距离,无足够距离则滚动到顶部。

-

smooth缺省值为false,表示直接滚动。

-

smooth为true,表示平滑滚动。

-

collapseGroup

-

{ groupid: string }

-

收拢指定的group。

-

groupid:需要收拢的group的id。

-

当groupid未指定时收拢所有的group。

-

expandGroup

-

{ groupid: string }

-

展开指定的group。

-

groupid:需要展开的group的id。

-

当groupid未指定时展开所有的group。

-

currentOffset

-

-

-

返回当前滑动的偏移量。返回值类型是Object,返回值说明请见表2

-
- -**表 1** ScrollParam - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

是否必选

-

默认值

-

备注

-

dx

-

number

-

-

0

-

水平方向滑动的偏移量,单位为px。

-

dy

-

number

-

-

0

-

垂直方向滑动的偏移量,单位为px。

-

smooth

-

boolean

-

-

true

-

列表位置跳转时是否有滑动动画。

-
- -**表 2** currentOffset返回对象属性说明 - - - - - - - - - - - - - - - - -

名称

-

类型

-

备注

-

x

-

number

-

当前x轴滑动偏移量,单位为px。

-

y

-

number

-

当前y轴滑动偏移量,单位为px。

-
-## 示例 - -``` -!-- index.hml --> -
- - -
- {{$item.title}} - {{$item.date}} -
-
-
-``` - -``` -// index.js -export default { - data: { - todolist: [{ - title: '刷题', - date: '2021-12-31 10:00:00', - }, { - title: '看电影', - date: '2021-12-31 20:00:00', - }], - }, -} -``` - -``` -/* index.css */ -.container { - display: flex; - justify-content: center; - align-items: center; - width: 100%; - height: 100%; -} -.todo-wrapper { - width: 100%; - height: 300px; -} -.todo-item { - width: 100%; - height: 120px; - justify-content:center; -} -.todo-title { - width: 100%; - height: 80px; - text-align: center; -} -``` - -![](/images/application-dev/reference/arkui-js/figures/list.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/06.list-item.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/06.list-item.md" deleted file mode 100644 index efbc6f4ceb22c626e09316701ea4700764aa8213..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/06.list-item.md" +++ /dev/null @@ -1,164 +0,0 @@ ---- -title: list-item -permalink: /pages/010c0201010206 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# list-item - -<[list](/pages/010c0201010205)\>的子组件,用来展示列表具体item。由于父元素list组件的align-items默认样式为stretch,该组件宽度默认充满list组件。设置父元素list组件的align-items样式为非stretch来生效自定义宽度。 - -## 权限列表 - -无 - -## 子组件 - -支持单个子组件。 - -## 属性 - -除支持[通用属性](/pages/010c0201010101)外,还支持如下属性: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

type

-

string

-

default

-

-

list-item类型,默认值为default,同一list中可以包含多种type的list-item,相同type的list-item需要确保渲染后的视图布局也相同,如果type固定,则使用show属性代替if属性,确保视图布局不变。

-

primary

-

boolean

-

false

-

-

设置为true表示该item是group中的主item,即收拢时显示的item。如果有多个primary,以第一个为准。如果没有标记为primary的item,则以第一个item为主item。

-

section

-

string

-

-

-

-

当前item的匹配字符串,如不设置则为空。不支持动态修改。group内只有主item设置有效。

-

sticky

-

string

-

none

-

-

设置当前item是否为吸顶item以及其吸顶消失的效果,当前仅支持纵向list,group内部的item不可吸顶,设置该属性无效。

-
  • none:当前item不吸顶。
  • normal:当前item吸顶,消失效果滑动消失。
  • opacity:当前item吸顶,消失效果渐隐消失,仅在智能穿戴上支持。
-

clickeffect5+

-

boolean

-

true

-

-

设置当前item是否有点击动效。

-
  • false:item点击时无点击动效。
  • true:item点击时有点击动效。
-
- -## 样式 - -除支持[通用样式](/pages/010c0201010102)外,还支持如下样式: - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

column-span

-

<number>

-

1

-

-

当前的list-item需要在list中占据的列的数量,默认占一列,仅在list为多列时生效。

-
- -## 事件 - -除支持[通用事件](/pages/010c0201010103)外,还支持如下事件: - - - - - - - - - - - -

名称

-

参数

-

描述

-

sticky

-

{ state: boolean }

-

吸顶组件回调事件。

-

value: false表示当前item处于非吸顶状态;

-

value: true表示当前item处于吸顶状态;

-

说明:仅当item设置sticky属性时支持注册此事件。

-
- -## 方法 - -支持[通用方法](/pages/010c0201010104)。 - -## 示例 - -详见[List示例](/pages/010c0201010205#示例)。 - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/07.list-item-group.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/07.list-item-group.md" deleted file mode 100644 index 274aa497a279f3c29071b1b811e6696aa7b4db2f..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/07.list-item-group.md" +++ /dev/null @@ -1,260 +0,0 @@ ---- -title: list-item-group -permalink: /pages/010c0201010207 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# list-item-group - -<[list](/pages/010c0201010205)\>的子组件,用来展示分组,宽度默认充满list组件。 - -- 使用该组件时父元素list组件的样式columns必须为1,否则功能异常。 -- 由于父元素list组件的align-items默认样式为stretch,该组件宽度默认充满list组件。设置父元素list组件的align-items样式为非stretch来生效自定义宽度。 - -## 权限列表 - -无 - -## 子组件 - -仅支持<[list-item](/pages/010c0201010206)\>。 - -## 属性 - -除支持[通用属性](/pages/010c0201010101)外,还支持如下属性: - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

type

-

string

-

default

-

-

list-item-group类型,同一list支持多种type的list-item-group,相同type的list-item-group需要确保渲染后的视图布局也完全相同,当type固定时,使用show属性代替if属性,确保视图布局不变。

-
- ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->- 通用属性中的id用来标识一个group。list中相关的函数的入参以及事件的信息皆以此标识一个唯一的group。 - -## 样式 - -除支持[通用样式](/pages/010c0201010102)外,还支持如下样式: - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

flex-direction

-

string

-

row

-

-

flex容器主轴方向。可选项有:

-
  • column:垂直方向从上到下
  • row:水平方向从左到右
-

justify-content

-

string

-

flex-start

-

-

flex容器当前行的主轴对齐格式。可选项有:

-
  • flex-start:项目位于容器的开头。
  • flex-end:项目位于容器的结尾。
  • center:项目位于容器的中心。
  • space-between:项目位于各行之间留有空白的容器内。
  • space-around:项目位于各行之前、之间、之后都留有空白的容器内。
  • space-evenly5+: 均匀排列每个元素,每个元素之间的间隔相等。
-
- -## 事件 - -除支持[通用事件](/pages/010c0201010103)外,还支持如下事件: - - - - - - - - - - - - - - - - - - - -

名称

-

参数

-

描述

-

groupclick

-

{ groupid: string }

-

group点击事件。

-

groupid:被点击的group的id。

-

groupcollapse

-

{ groupid: string }

-

group收拢事件。

-

groupid:收拢的group的id。

-

当不输入参数或者groupid为空时收拢所有分组。

-

groupexpand

-

{ groupid: string }

-

group展开事件。

-

groupid:展开的group的id。

-

当不输入参数或者groupid为空时展开所有分组。

-
- -## 方法 - -支持[通用方法](/pages/010c0201010104)。 - -## 示例 - -``` - -
- - -
-
- - -
-
- - -
-
-
- - -
- One---{{listgroup.value}} -
-
- -
- Primary---{{listgroup.value}} -
-
-
-
-
-``` - -``` -/* xxx.css */ -.doc-page { - flex-direction: column; -} -.top-list-item { - width:100%; - background-color:#D4F2E7; -} -.item-div { - flex-direction:column; - align-items:center; - justify-content:space-around; - height:240px; -} -.item-child { - width:100%; - height:60px; - justify-content:space-around; - align-items:center; -} -.item-group-child { - justify-content: center; - align-items: center; - width:100%; -} -``` - -``` -// xxx.js -import prompt from '@system.prompt'; -export default { - data: { - direction: 'column', - list: [] - }, - onInit() { - this.list = [] - this.listAdd = [] - for (var i = 1; i <= 3; i++) { - var dataItem = { - value: 'GROUP' + i, - }; - this.list.push(dataItem); - } - }, - collapseOne(e) { - this.$element('mylist').collapseGroup({ - groupid: 'GROUP1' - }) - }, - expandOne(e) { - this.$element('mylist').expandGroup({ - groupid: 'GROUP1' - }) - }, - collapseAll(e) { - this.$element('mylist').collapseGroup() - }, - expandAll(e) { - this.$element('mylist').expandGroup() - }, - collapse(e) { - prompt.showToast({ - message: 'Close ' + e.groupid - }) - }, - expand(e) { - prompt.showToast({ - message: 'Open ' + e.groupid - }) - } -} -``` - -![](/images/application-dev/reference/arkui-js/figures/list6.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/08.panel.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/08.panel.md" deleted file mode 100644 index 11db3c4b5f06fa25dc36bcafd7180294c3a8efb0..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/08.panel.md" +++ /dev/null @@ -1,546 +0,0 @@ ---- -title: panel -permalink: /pages/010c0201010208 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# panel - -可滑动面板。提供一种轻量的内容展示的窗口,可方便的在不同尺寸中切换。属于弹出式组件。 - -## 子组件 - -支持 - -## 属性 - -除支持[通用属性](/pages/010c0201010101)外,还支持如下属性: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

type

-

string

-

foldable

-

-

设置可滑动面板类型,不可动态变更,可选值有:

-
  • minibar:提供minibar和类全屏展示切换效果。

    -
  • foldable:内容永久展示类,提供大(类全屏)、中(类半屏)、小三种尺寸展示切换效果。

    -
  • temporary:内容临时展示区,提供大(类全屏)、中(类半屏)两种尺寸展示切换效果。

    -
-

mode

-

string

-

full

-

-

设置初始状态,mode参数可选值为:

-
  1. mini:类型为minibar和foldable时,为最小状态;类型为temporary,则不生效。

    -
  2. half: 类型为foldable和temporary时,为类半屏状态;类型为minibar,则不生效。

    -
  3. full: 类全屏状态。

    -
-

dragbar

-

boolean

-

true

-

-

设置是否存在dragbar,true表示存在,false表示不存在。

-

fullheight

-

<length>

-

-

-

-

指定full状态下的高度,默认为屏幕尺寸 - 8px。

-

halfheight

-

<length>

-

-

-

-

指定half状态下的高度,默认为屏幕尺寸的一半。

-

miniheight

-

<length>

-

-

-

-

指定mini状态下的高度,默认为48px。

-
- ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->- 不支持渲染属性,包括for、if和show。 ->- 不支持focusable和disabled属性。 - -## 样式 - -仅支持如下样式: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

padding

-

<length>

-

0

-

-
该属性可以有1到4个值:
  • 指定一个值时,该值指定四个边的内边距。

    -
  • 指定两个值时,第一个值指定上下两边的内边距,第二个指定左右两边的内边距。

    -
  • 指定三个值时,第一个指定上边的内边距,第二个指定左右两边的内边距,第三个指定下边的内边距。

    -
  • 指定四个值时分别为上、右、下、左边的内边距(顺时针顺序)。

    -
-
-

padding-[left|top|right|bottom]

-

<length>

-

0

-

-

设置左、上、右、下内边距属性。

-

padding-[start|end]

-

<length>

-

0

-

-

设置起始和末端内边距属性。

-

margin

-

<length>

-

0

-

-

使用简写属性设置所有的外边距属性,该属性可以有1到4个值。

-
  • 只有一个值时,这个值会被指定给全部的四个边。

    -
  • 两个值时,第一个值被匹配给上和下,第二个值被匹配给左和右。

    -
  • 三个值时,第一个值被匹配给上, 第二个值被匹配给左和右,第三个值被匹配给下。

    -
  • 四个值时,会依次按上、右、下、左的顺序匹配 (即顺时针顺序)。

    -
-

margin-[left|top|right|bottom]

-

<length>

-

0

-

-

设置左、上、右、下外边距属性。

-

margin-[start|end]

-

<length>

-

0

-

-

设置起始和末端外边距属性。

-

border

-

-

-

0

-

-

使用简写属性设置所有的边框属性,包含边框的宽度,样式,颜色属性,顺序设置为border-width、border-style、border-color,不设置时,各属性值为默认值。

-

border-style

-

string

-

solid

-

-

使用简写属性设置所有边框的样式,可选值为:

-
  • dotted:显示为一系列圆点,圆点半径为border-width的一半。
  • dashed:显示为一系列短的方形虚线。
-
  • solid:显示为一条实线。
-

border-[left|top|right|bottom]-style

-

string

-

solid

-

-

分别设置左、上、右、下四个边框的样式,可选值为dotted、dashed、solid。

-

border-[left|top|right|bottom]

-

-

-

-

-

-

使用简写属性设置对应位置的边框属性,包含边框的宽度,样式,颜色属性,顺序设置为border-width、border-style、border-color,不设置的值为默认值。

-

border-width

-

<length>

-

0

-

-

使用简写属性设置元素的所有边框宽度,或者单独为各边边框设置宽度

-

border-[left|top|right|bottom]-width

-

<length>

-

0

-

-

分别设置左、上、右、下四个边框的宽度。

-

border-color

-

<color>

-

black

-

-

使用简写属性设置元素的所有边框颜色,或者单独为各边边框设置颜色

-

border-[left|top|right|bottom]-color

-

<color>

-

black

-

-

分别设置左、上、右、下四个边框的颜色。

-

border-radius

-

<length>

-

-

-

-

border-radius属性是设置元素的外边框圆角半径。设置border-radius时不能单独设置某一个方向的border-[left|top|right|bottom]-width,border-[left|top|right|bottom]-color ,如果要设置color和width,需要将四个方向一起设置(border-width、border-color)。

-

border-[top|bottom]-[left|right]-radius

-

<length>

-

-

-

-

分别设置左上,右上,右下和左下四个角的圆角半径。

-

background

-

<linear-gradient>

-

-

-

-

仅支持设置渐变样式,与background-color、background-image不兼容。

-

background-color

-

<color>

-

-

-

-

设置背景颜色。

-

background-image

-

string

-

-

-

-

设置背景图片。与background-color、background不兼容;支持本地图片资源地址。

-

background-size

-
  • string
  • <length> <length>
  • <percentage> <percentage>
-

auto

-

-

设置背景图片的大小。

-
  • string可选值:
    • contain:把图像扩展至最大尺寸,以使其高度和宽度完全适用内容区域。
    • cover:把背景图像扩展至足够大,以使背景图像完全覆盖背景区域;背景图像的某些部分也许无法显示在背景定位区域中。
    • auto:保持原图的比例不变。
    -
  • length值参数方式:

    设置背景图像的高度和宽度。第一个值设置宽度,第二个值设置高度。如果只设置一个值,则第二个值会被设置为 "auto"。

    -
  • 百分比参数方式:

    以父元素的百分比来设置背景图像的宽度和高度。第一个值设置宽度,第二个值设置高度。如果只设置一个值,则第二个值会被设置为 "auto"。

    -
-

background-repeat

-

string

-

repeat

-

-

针对重复背景图像样式进行设置,背景图像默认在水平和垂直方向上重复。

-
  • repeat:在水平轴和竖直轴上同时重复绘制图片。
  • repeat-x:只在水平轴上重复绘制图片。
  • repeat-y:只在竖直轴上重复绘制图片。
  • no-repeat:不会重复绘制图片。
-

background-position

-
  • string string
  • <length> <length>
  • <percentage> <percentage>
-

0px 0px

-

-
  • 关键词方式:如果仅规定了一个关键词,那么第二个值为"center"。两个值分别定义水平方向位置和竖直方向位置。
    • left:水平方向上最左侧。
    • right:水平方向上最右侧。
    • top:竖直方向上最顶部。
    • bottom:竖直方向上最底部。
    • center:水平方向或竖直方向上中间位置。
    -
-
  • length值参数方式:第一个值是水平位置,第二个值是垂直位置。 左上角是 0 0。单位是像素 (0px 0px) 。如果仅规定了一个值,另外一个值将是50%。
  • 百分比参数方式:第一个值是水平位置,第二个值是垂直位置。左上角是 0% 0%。右下角是 100% 100%。如果仅规定了一个值,另外一个值为50%。
  • 可以混合使用<percentage>和<length>
-

opacity

-

number

-

1

-

-

元素的透明度,取值范围为0到1,1表示为不透明,0表示为完全透明。

-
- -## 事件 - -仅支持如下事件: - - - - - - - - - - - -

名称

-

参数

-

描述

-

sizechange

-

{ size: { height: heightLength, width: widthLength }, mode: modeStr }

-

当可滑动面板发生状态变化时触发,mode参数可选值为:

-
  1. mini:类型为minibar和foldable时,处于最小状态;

    -
  2. half: 类型为foldable时,处于类半屏状态;

    -
  3. full: 类全屏状态。

    -
    说明:

    返回的height值为内容区高度值,当dragbar属性为true时,panel本身的高度值为dragbar高度加上内容区高度。

    -
    -
-
- -## 方法 - -仅支持如下方法: - - - - - - - - - - - - - - - -

名称

-

参数

-

描述

-

show

-

-

-

弹出panel可滑动面板。

-

close

-

-

-

关闭panel可滑动面板。

-
- -## 示例 - -``` - -
-
- -
- -
-
- Simple panel in {{modeFlag}} mode -
-
- -
-
-
-
-``` - -``` -/* xxx.css */ -.doc-page { - flex-direction: column; - justify-content: center; - align-items: center; -} -.btn-div { - width: 100%; - height: 200px; - flex-direction: column; - align-items: center; - justify-content: center; -} -.txt { - color: #000000; - font-weight: bold; - font-size: 39px; -} -.panel-div { - width: 100%; - flex-direction: column; - align-items: center; -} -.inner-txt { - width: 100%; - height: 160px; - flex-direction: column; - align-items: center; - justify-content: center; -} -.inner-btn { - width: 100%; - height: 120px; - justify-content: center; - align-items: center; -} -``` - -``` -// xxx.js -export default { - data: { - modeFlag: "half" - }, - showPanel() { - this.$element('simplepanel').show() - }, - closePanel() { - this.$element('simplepanel').close() - }, - changeMode(e) { - this.modeFlag = e.mode - } -} -``` - -![](/images/application-dev/reference/arkui-js/figures/panel6.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/09.popup.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/09.popup.md" deleted file mode 100644 index c8d3c8d41eea01abf91a3bcb2b817654743b6349..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/09.popup.md" +++ /dev/null @@ -1,249 +0,0 @@ ---- -title: popup -permalink: /pages/010c0201010209 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# popup - -气泡指示。在点击绑定的控件后会弹出相应的气泡提示来引导用户进行操作。 - -## 权限列表 - -无 - -## 子组件 - -支持单个子组件节点5+。 - -## 属性 - -除支持[通用属性](/pages/010c0201010101)外,还支持如下属性:↵ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

target

-

string

-

-

-

-

目标元素的id属性值,不支持动态切换。

-

placement

-

string

-

bottom

-

-

弹出窗口位置。可选值为:

-
  • left:位于目标元素左边;
  • right:位于目标元素右边;
  • top:位于目标元素上边;
  • bottom:位于目标元素下边;
  • topLeft:位于目标元素左上角;
  • topRight:位于目标元素右上角;
  • bottomLeft:位于目标元素左下角;
  • bottomRight:位于目标元素右下角。
-

keepalive5+

-

boolean

-

false

-

-

设置当前popup是否需要保留。设置为true时,点击屏幕区域或者页面切换气泡不会消失,需调用气泡组件的hide方法才可让气泡消失;设置为false时,点击屏幕区域或者页面切换气泡会自动消失。

-

clickable5+

-

boolean

-

true

-

-

popup是否使用点击弹窗,当设置为false时,只支持方法调用显示。

-

arrowoffset5+

-

<length>

-

0

-

-

popup箭头在弹窗处的偏移,默认居中,正值按照语言方向进行偏移,负值相反。

-
- ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->- 不支持focusable属性。 - -## 样式 - -除支持[通用样式](/pages/010c0201010102)外,还支持如下样式: - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

mask-color

-

<color>

-

-

-

-

遮罩层的颜色,默认值为全透明。

-
- ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->- 不支持position相关样式。 - -## 事件 - -除支持[通用事件](/pages/010c0201010103)外,还支持如下事件: - - - - - - - - - - - -

名称

-

参数

-

描述

-

visibilitychange

-

{ visibility: boolean }

-

当气泡弹出和消失时会触发该回调函数。

-
- -## 方法 - -仅支持如下方法: - - - - - - - - - - - - - - - -

名称

-

参数

-

描述

-

show5+

-

-

-

弹出气泡提示。

-

hide5+

-

-

-

取消气泡提示。

-
- ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->1. popup气泡弹窗属性、样式均不支持动态更新。 ->2. popup气泡弹窗的margin样式是相对于target元素进行生效的,如popup在target元素下方,此时只生效margin-top样式,popup在target元素左上方,此时只生效margin-bottom和margin-right样式。 ->3. popup的border四边样式需一致,若四边设置不一致且圆角为零,则按左、上、右、下的顺序取第一个被设置的样式,否则border不生效。 ->4. popup的target组件的click事件不生效。 - -## 示例 - -``` - -
- Click to show the pop-up - - - Text content of the pop-up - - -
-``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - align-items: center; - padding-top: 200px; -} -.popup { - mask-color: gray; -} -.text { - color: white; -} -.button { - width: 220px; - height: 70px; - margin-top: 50px; -} -``` - -``` -// xxx.js -import prompt from '@system.prompt' -export default { - visibilitychange(e) { - prompt.showToast({ - message: 'visibility change visibility: ' + e.visibility, - duration: 3000, - }); - }, - showpopup() { - this.$element("popup").show(); - }, - hidepopup() { - this.$element("popup").hide(); - }, -} -``` - -![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001178886129.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/10.refresh.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/10.refresh.md" deleted file mode 100644 index bd19fd40ac0315eb06efb921cfc55abd7012668d..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/10.refresh.md" +++ /dev/null @@ -1,274 +0,0 @@ ---- -title: refresh -permalink: /pages/010c020101020a -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# refresh - -下拉刷新容器。 - -## 权限列表 - -无 - -## 子组件 - -支持。 - -## 属性 - -除支持[通用属性](/pages/010c0201010101)外,还支持如下属性: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

offset

-

<length>

-

-

-

-

刷新组件静止时距离父组件顶部的距离。

-

refreshing

-

boolean

-

false

-

-

用于标识刷新组件当前是否正在刷新。

-

type

-

string

-

auto

-

-

设置组件刷新时的动效。两个可选值,不支持动态修改。

-
  • auto: 默认效果,列表界面拉到顶后,列表不移动,下拉后有转圈弹出。
  • pulldown: 列表界面拉到顶后,可以继续往下滑动一段距离触发刷新,刷新完成后有回弹效果(如果子组件含有list,防止下拉效果冲突,需将list的scrolleffect设置为no)。
-

lasttime

-

boolean

-

false

-

-

是否显示上次更新时间,字符串格式为:“上次更新时间:XXXX ”,XXXX 按照时间日期显示规范显示,不可动态修改(建议type为pulldown时使用,固定距离位于内容下拉区域底部,使用时注意offset属性设置,防止出现重叠)。

-

timeoffset6+

-

<length>

-

-

-

-

设置更新时间距离父组件顶部的距离。

-

friction

-

number

-

42

-

-

下拉摩擦系数,取值范围:0-100,数值越大refresh组件跟手性高,数值越小refresh跟手性低。

-
说明:

仅手机、平板和智能穿戴设备支持。

-
-
- -## 样式 - -除支持[通用样式](/pages/010c0201010102)外,还支持如下样式: - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

background-color

-

<color>

-

white

-

-

用于设置刷新组件的背景颜色。

-

progress-color

-

<color>

-

black

-

-

用于设置刷新组件的loading颜色。

-
- -## 事件 - -仅支持如下事件: - - - - - - - - - - - - - - - -

名称

-

参数

-

描述

-

refresh

-

{ refreshing: refreshingValue }

-

下拉刷新状态变化时触发。可能值:

-
  • false:当前处于下拉刷新过程中。
  • true:当前未处于下拉刷新过程中。
-

pulldown

-

{ state: string }

-

下拉开始和松手时触发。可能值:

-
  • start:表示开始下拉。
  • end:表示结束下拉。
-
- -## 方法 - -不支持[通用方法](/pages/010c0201010104)。 - -## 示例 - -``` - -
- - - -
- {{$item}} -
-
-
-
-
-``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - align-items: center; - width: 100%; - height: 100%; -} - -.list { - width: 100%; - height: 100%; -} - -.listitem { - width: 100%; - height: 150px; -} - -.content { - width: 100%; - height: 100%; - flex-direction: column; - align-items: center; - justify-content: center; -} - -.text { - font-size: 35px; - font-weight: bold; -} -``` - -``` -// xxx.js -import prompt from '@system.prompt'; -export default { - data: { - list:[], - fresh:false - }, - onInit() { - this.list = []; - for (var i = 0; i <= 3; i++) { - var item = '列表元素' + i; - this.list.push(item); - } - }, - refresh: function (e) { - prompt.showToast({ - message: '刷新中...' - }) - var that = this; - that.fresh = e.refreshing; - setTimeout(function () { - that.fresh = false; - var addItem = '更新元素'; - that.list.unshift(addItem); - prompt.showToast({ - message: '刷新完成!' - }) - }, 2000) - } -} -``` - -![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001150719520.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/11.stack.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/11.stack.md" deleted file mode 100644 index 9bb0a7e22227a7142e63f9d41f9c5aee409bca01..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/11.stack.md" +++ /dev/null @@ -1,85 +0,0 @@ ---- -title: stack -permalink: /pages/010c020101020b -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# stack - -堆叠容器,子组件按照顺序依次入栈,后一个子组件覆盖前一个子组件。 - -## 权限列表 - -无 - -## 子组件 - -支持。 - -## 属性 - -支持[通用属性](/pages/010c0201010101)。 - -## 样式 - -支持[通用样式](/pages/010c0201010102)。 - -## 事件 - -支持[通用事件](/pages/010c0201010103)。 - -## 方法 - -支持[通用方法](/pages/010c0201010104)。 - -## 示例 - -``` - - -
-
-
-
-``` - -``` -/* xxx.css */ -.stack-parent { - width: 400px; - height: 400px; - background-color: #ffffff; - border-width: 1px; - border-style: solid; -} -.back-child { - width: 300px; - height: 300px; - background-color: #3f56ea; -} -.front-child { - width: 100px; - height: 100px; - background-color: #00bfc9; -} -.positioned-child { - width: 100px; - height: 100px; - left: 50px; - top: 50px; - background-color: #47cc47; -} -.bd-radius { - border-radius: 16px; -} -``` - -![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127284958.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/12.stepper.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/12.stepper.md" deleted file mode 100644 index 7b680e72238657e7230b5f8bed9f900fc0e249a2..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/12.stepper.md" +++ /dev/null @@ -1,229 +0,0 @@ ---- -title: stepper -permalink: /pages/010c020101020c -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# stepper - -步骤导航器。当完成一个任务需要多个步骤时,可以使用步骤导航器展示当前进展。 - -## 权限列表 - -无 - -## 子组件 - -仅支持子组件。 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->步骤导航器内的步骤顺序按照子组件的顺序进行排序。 - -## 属性 - -除支持[通用属性](/pages/010c0201010101)外,还支持如下属性: - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

描述

-

index

-

number

-

-

-

设置步骤导航器步骤显示第几个stepper-item子组件。

-
- -## 样式 - -支持[通用样式](/pages/010c0201010102)。 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->stepper组件默认占满父容器大小,建议父组件使用应用窗口大小(或者父组件为根节点)来优化体验。 - -## 事件 - -除支持[通用事件](/pages/010c0201010103)外,还支持如下事件: - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数

-

描述

-

finish

-

-

当步骤导航器最后一个步骤完成时触发该事件。

-

skip

-

-

当通过setNextButtonStatus方法设置当前步骤导航器可跳过时,点击右侧跳过按钮触发该事件。

-

change

-

{ prevIndex:prevIndex, index: index}

-

当步骤导航器点击左边或者右边文本按钮进行步骤切换时触发该事件,prevIndex表示老步骤的序号,index表示新步骤的序号。

-

next

-

{ index:index, pendingIndex: pendingIndex }

-

当用户点击下一步按钮时触发该事件,index表示当前步骤序号,pendingIndex表示将于跳转的序号,该事件有返回值,返回值格式为:{ pendingIndex:pendingIndex },可以通过指定pendingIndex来修改下一个步骤使用哪个stepper-item子组件。

-

back

-

{ index:index, pendingIndex: pendingIndex }

-

当用户点击上一步按钮时触发该事件,index表示当前步骤序号,pendingIndex表示将于跳转的序号,该事件有返回值,返回值格式为Object:{ pendingIndex:pendingIndex },可以通过指定pendingIndex来修改上一个步骤使用哪个stepper-item子组件。

-
- -## 方法 - -除支持[通用方法](/pages/010c0201010104)外,支持如下方法: - - - - - - - - - - - -

名称

-

参数

-

描述

-

setNextButtonStatus

-

{ status: string, label: label }

-

设置当前步骤导航器下一步文本按钮的状态,参数中status类型为string,可选值为:

-
  1. normal:正常状态,下一步文本按钮正常显示,可点击进入下一个步骤;
  2. disabled:不可用状态,下一步文本按钮灰度显示,不可点击进入下一个步骤;
  3. waiting:等待状态,下一步文本按钮不显示,使用等待进度条,不可点击进入下一个步骤。
  4. skip:跳过状态,下一步文本按钮显示跳过按钮,点击时会跳过剩下步骤。
-
- -## 示例 - -``` - -
- - -
- First screen -
- -
- -
- Second screen -
- -
- -
- Third screen -
- -
-
-
-``` - -``` -/* xxx.css */ -.container { - margin-top: 20px; - flex-direction: column; - align-items: center; - height: 300px; -} -.stepperItem { - flex-direction: column; - align-items: center; -} -.stepperItemContent { - color: #0000ff; - font-size: 50px; - justify-content: center; -} -.button { - width: 60%; - margin-top: 30px; - justify-content: center; -} -``` - -``` -// xxx.js -export default { - data: { - label_1: - { - prevLabel: 'BACK', - nextLabel: 'NEXT', - status: 'normal' - }, - label_2: - { - prevLabel: 'BACK', - nextLabel: 'NEXT', - status: 'normal' - }, - label_3: - { - prevLabel: 'BACK', - nextLabel: 'NEXT', - status: 'normal' - }, - }, - setRightButton(e) { - this.$element('mystepper').setNextButtonStatus({status: 'skip', label: 'SKIP'}); - }, - nextclick(e) { - var index = { - pendingIndex: e.pendingIndex - } - return index; - }, - backclick(e) { - var index = { - pendingIndex: e.pendingIndex - } - return index; - }, -} -``` - -![](/images/application-dev/reference/arkui-js/figures/Video_2021-03-26_154549.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/13.stepper-item.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/13.stepper-item.md" deleted file mode 100644 index ec260f5e494d2fdf911c6caecde58fbf1fcdc02d..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/13.stepper-item.md" +++ /dev/null @@ -1,240 +0,0 @@ ---- -title: stepper-item -permalink: /pages/010c020101020d -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# stepper-item - -步骤导航器子组件,作为步骤导航器某一个步骤的内容展示组件。 - -## 权限列表 - -无 - -## 子组件 - -支持。 - -## 属性 - -除支持[通用属性](/pages/010c0201010101)外,还支持如下属性: - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

label

-

Label

-

-

-

-

自定义步骤导航器底部步骤提示文本按钮属性,不支持动态修改。如果没有定义该属性,步骤导航器在中文语言环境下,使用“返回”和“下一步”文本按钮,在非中文语言环境下,使用“BACK”和“NEXT”文本按钮。针对第一个步骤,没有回退文本按钮,针对最后一个步骤,下一步文本按钮文本使用“开始”(中文语言)或者“START”(非中文语言)。

-
- -**表 1** Label对象定义 - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

描述

-

prevLabel

-

string

-

-

-

步骤导航器底部回退文本按钮的描述文本。

-

nextLabel

-

string

-

-

-

步骤导航器底部下一步文本按钮的描述文本。

-

status

-

string

-

normal

-

步骤导航器当前步骤的初始状态,可选值为:

-
  • normal:正常状态,右侧文本按钮正常显示,可点击进入下一个步骤。
-
  • disabled:不可用状态,右侧文本按钮灰度显示,不可点击进入下一个步骤。
-
  • waiting:等待状态,右侧文本按钮不显示,使用等待进度条,不可点击进入下一个步骤。
-
- -## 样式 - -除支持[通用样式](/pages/010c0201010102)外,还支持如下样式: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

color

-

<color>

-

-

-

-

文本颜色。

-

font-size

-

<length>

-

-

-

-

文本大小。

-

allow-scale

-

boolean

-

true

-

-

文本尺寸是否跟随系统设置字体缩放尺寸进行放大缩小。

-

font-style

-

string

-

normal

-

-

文本字体样式,可选值为:

-
  • normal: 标准的字体样式;
  • italic: 斜体的字体样式。
-

font-weight

-

number|string

-

normal

-

-

文本字体粗细,number类型取值[100, 900]的整数(被100整除),默认为400,取值越大,字体越粗。string类型取值为:lighter、normal、bold、bolder。

-

text-decoration

-

string

-

none

-

-

文本修饰,可选值为:

-
  • underline: 文本下划线修饰。
  • line-through: 穿过文本的修饰线。
  • none: 标准文本。
-

font-family

-

string

-

sans-serif

-

-

字体列表,用逗号分隔,每个字体用字体名或者字体族名设置。列表中第一个系统中存在的或者通过自定义字体指定的字体,会被选中作为文本的字体。

-
- ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->- 不支持长宽样式,宽和父容器stepper一样,高是父容器stepper减去底部导航按钮的高度。 ->- 不支持posit样式。 - -## 事件 - -除支持[通用事件](/pages/010c0201010103)外,还支持如下事件: - - - - - - - - - - - - - - - -

名称

-

参数

-

描述

-

appear

-

-

-

当该步骤出现时触发。

-

disappear

-

-

-

当该步骤消失时触发。

-
- -## 方法 - -不支持[通用方法](/pages/010c0201010104)。 - -## 示例 - -详见[stepper示例](/pages/010c020101020c)。 - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/14.swiper.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/14.swiper.md" deleted file mode 100644 index f28cd44955d5e18bc8f9f799c32ed2b51848f213..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/14.swiper.md" +++ /dev/null @@ -1,414 +0,0 @@ ---- -title: swiper -permalink: /pages/010c020101020e -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# swiper - -滑动容器,提供切换子组件显示的能力。 - -## 权限列表 - -无 - -## 子组件 - -支持除之外的子组件。 - -## 属性 - -除支持[通用属性](/pages/010c0201010101)外,还支持如下属性: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

index

-

number

-

0

-

-

当前在容器中显示的子组件的索引值。

-

autoplay

-

boolean

-

false

-

-

子组件是否自动播放,自动播放状态下,导航点不可操作5+

-

interval

-

number

-

3000

-

-

使用自动播放时播放的时间间隔,单位为ms。

-

indicator

-

boolean

-

true

-

-

是否启用导航点指示器,默认true。

-

digital5+

-

boolean

-

false

-

-

是否启用数字导航点,默认为false。

-
说明:

必须设置indicator时才能生效数字导航点。

-
-

indicatordisabled5+

-

boolean

-

false

-

-

指示器是否禁止用户手势操作,设置为true时,指示器不会响应用户的点击拖拽。

-

loop

-

boolean

-

true

-

-

是否开启循环滑动。

-

duration

-

number

-

-

-

-

子组件切换的动画时长。

-

vertical

-

boolean

-

false

-

-

是否为纵向滑动,纵向滑动时采用纵向的指示器。

-

cachedsize7+

-

number

-

-1

-

-

swiper延迟加载时item最少缓存数量。-1表示全部缓存。

-

scrolleffect7+

-

string

-

spring

-

-

滑动效果。目前支持如下:

-
  • spring:弹性物理动效,滑动到边缘后可以根据初始速度或通过触摸事件继续滑动一段距离,松手后回弹。
  • fade:渐隐物理动效,滑动到边缘后展示一个波浪形的渐隐,根据速度和滑动距离的变化渐隐也会发送一定的变化
  • none:滑动到边缘后无效果。
    说明:

    该属性仅在loop属性为false时生效。

    -
    -
-
- -## 样式 - -除支持[通用样式](/pages/010c0201010102)外,还支持如下样式: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

indicator-color

-

<color>

-

-

-

-

导航点指示器的填充颜色。

-

indicator-selected-color

-

<color>

-

#ff007dff

-

-

导航点指示器选中的颜色。

-

indicator-size

-

<length>

-

4px

-

-

导航点指示器的直径大小。

-

indicator-top|left|right|bottom

-

<length> | <percentage>

-

-

-

-

导航点指示器在swiper中的相对位置。

-

next-margin7+

-

<length> | <percentage>

-

-

-

-

后边距,用于露出后一项的一小部分。

-

previous-margin7+

-

<length> | <percentage>

-

-

-

-

前边距,用于露出前一项的一小部分。

-
- -## 事件 - -除支持[通用事件](/pages/010c0201010103)外,还支持如下事件: - - - - - - - - - - - - - - - - - - - -

名称

-

参数

-

描述

-

change

-

{ index: currentIndex }

-

当前显示的组件索引变化时触发该事件。

-

rotation

-

{ value: rotationValue }

-

智能穿戴表冠旋转事件触发时的回调。

-

animationfinish7+

-

-

-

动画结束时触发该事件。

-
- -## 方法 - -除支持[通用方法](/pages/010c0201010104)外,还支持如下方法: - - - - - - - - - - - - - - - - - - - -

名称

-

参数

-

描述

-

swipeTo

-

{ index: number(指定位置) }

-

切换到index位置的子组件。

-

showNext

-

-

显示下一个子组件。

-

showPrevious

-

-

显示上一个子组件。

-
- -## 示例 - -``` - -
- -
- First screen -
-
- Second screen -
-
- Third screen -
-
- - - -
-``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - width: 100%; - height: 100%; - align-items: center; -} -.swiper { - flex-direction: column; - align-content: center; - align-items: center; - width: 70%; - height: 130px; - border: 1px solid #000000; - indicator-color: #cf2411; - indicator-size: 14px; - indicator-bottom: 20px; - indicator-right: 30px; - margin-top: 100px; - next-margin:20px; - previous-margin:20px; -} -.swiperContent1{ - height: 100%; - justify-content: center; - background-color: #007dff; -} -.swiperContent2{ - height: 100%; - justify-content: center; - background-color: #ff7500; -} -.swiperContent3{ - height: 100%; - justify-content: center; - background-color: #41ba41; -} -.button { - width: 70%; - margin: 10px; -} -.text { - font-size: 40px; -} -``` - -``` -// xxx.js -export default { - swipeTo() { - this.$element('swiper').swipeTo({index: 2}); - }, - showNext() { - this.$element('swiper').showNext(); - }, - showPrevious() { - this.$element('swiper').showPrevious(); - } -} -``` - -![](/images/application-dev/reference/arkui-js/figures/4-0.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/15.tabs.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/15.tabs.md" deleted file mode 100644 index ca762a64fdd46357740e47ede3294517fa024ccd..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/15.tabs.md" +++ /dev/null @@ -1,166 +0,0 @@ ---- -title: tabs -permalink: /pages/010c020101020f -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# tabs - -tab页签容器。 - -## 权限列表 - -无 - -## 子组件 - -仅支持最多一个<[tab-bar](/pages/010c0201010210)\>和最多一个<[tab-content](/pages/010c0201010211)\>。 - -## 属性 - -除支持[通用属性](/pages/010c0201010101)外,还支持如下属性: - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

index

-

number

-

0

-

-

当前处于激活态的tab索引。

-

vertical

-

boolean

-

false

-

-

是否为纵向的tab,默认为false,可选值为:

-
  • false:tabbar和tabcontent上下排列。
  • true:tabbar和tabcontent左右排列。
-
- -## 样式 - -支持[通用样式](/pages/010c0201010102)。 - -## 事件 - -除支持[通用事件](/pages/010c0201010103)外,还支持如下事件: - - - - - - - - - - - -

名称

-

参数

-

描述

-

change

-

{ index: indexValue }

-

tab页签切换后触发。

-
说明:

动态修改index值不会触发该回调。

-
-
- -## 示例 - -``` - -
- - - Home - Index - Detail - - -
- First screen -
-
- Second screen -
-
- Third screen -
-
-
-
-``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - justify-content: flex-start; - align-items: center; -} -.tabs { - width: 100%; -} -.tabcontent { - width: 100%; - height: 80%; - justify-content: center; -} -.item-content { - height: 100%; - justify-content: center; -} -.item-title { - font-size: 60px; -} -.tab-bar { - margin: 10px; - height: 60px; - border-color: #007dff; - border-width: 1px; -} -.tab-text { - width: 300px; - text-align: center; -} -``` - -``` -// xxx.js -export default { - change: function(e) { - console.log("Tab index: " + e.index); - }, -} -``` - -![](/images/application-dev/reference/arkui-js/figures/tab.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/16.tab-bar.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/16.tab-bar.md" deleted file mode 100644 index 0584814133529f18186c0d459131a5f33fae7901..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/16.tab-bar.md" +++ /dev/null @@ -1,72 +0,0 @@ ---- -title: tab-bar -permalink: /pages/010c0201010210 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# tab-bar - -<[tabs](/pages/010c020101020f)\>的子组件,用来展示tab的标签区,子组件排列方式为横向排列。 - -## 权限列表 - -无 - -## 子组件 - -支持。 - -## 属性 - -除支持[通用属性](/pages/010c0201010101)外,还支持如下属性: - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

mode

-

string

-

scrollable

-

-

设置组件宽度的可延展性。可选值为:

-
  • scrollable:子组件宽度为实际设置的宽度,当宽度之和(包括margin边距)大于tab-bar的宽度时,子组件可以横向滑动。
  • fixed:子组件宽度均分tab-bar的宽度。
-
- -## 样式 - -支持[通用样式](/pages/010c0201010102)。 - -## 事件 - -支持[通用事件](/pages/010c0201010103)。 - -## 方法 - -支持[通用方法](/pages/010c0201010104)。 - -## 示例 - -详见[tabs示例](/pages/010c020101020f#section14993155318710)。 - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/17.tab-content.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/17.tab-content.md" deleted file mode 100644 index 6f9700ccaeab90f32e105c197b856d999c72a48d..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\256\271\345\231\250\347\273\204\344\273\266/17.tab-content.md" +++ /dev/null @@ -1,67 +0,0 @@ ---- -title: tab-content -permalink: /pages/010c0201010211 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# tab-content - -<[tabs](/pages/010c020101020f)\>的子组件,用来展示tab的内容区,高度默认充满tabs剩余空间,子组件排列方式为横向排列,当作为容器组件的子元素时在主轴方向需要设置tab-content的确定长度,否则无法显示。 - -## 权限列表 - -无 - -## 子组件 - -支持。 - -## 属性 - -除支持[通用属性](/pages/010c0201010101)外,还支持如下属性: - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

scrollable

-

boolean

-

true

-

-

是否可以通过左右滑动进行页面切换。默认为true,设置为false后,页面的切换只能通过tab-bar的点击实现。

-
- -## 样式 - -支持[通用样式](/pages/010c0201010102)。 - -## 事件 - -支持[通用事件](/pages/010c0201010103)。 - -## 示例 - -详见[tabs示例](/pages/010c020101020f#section14993155318710)。 - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/01.button.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/01.button.md" deleted file mode 100644 index f879f0e6c2fc0e0cc7751c58b9b0ade869214b82..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/01.button.md" +++ /dev/null @@ -1,420 +0,0 @@ ---- -title: button -permalink: /pages/010c0201010301 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# button - -提供按钮组件,包括胶囊按钮、圆形按钮、文本按钮、弧形按钮、下载按钮。 - -## 子组件 - -不支持。 - -## 属性 - -除支持[通用属性](/pages/010c0201010101)外,还支持如下属性: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

type

-

string

-

-

-

-

不支持动态修改。如果该属性缺省,展示类胶囊型按钮,不同于胶囊类型,四边圆角可以通过border-radius分别指定,如果需要设置该属性,则可选值包括如下:

-
  • capsule:胶囊型按钮,带圆角按钮,有背景色和文本;
  • circle:圆形按钮,支持放置图标;
  • text:文本按钮,仅包含文本显示;
  • arc:弧形按钮,仅支持智能穿戴;
  • download:下载按钮,额外增加下载进度条功能,仅支持手机和智慧屏。
-

value

-

string

-

-

-

-

button的文本值。

-

icon

-

string

-

-

-

-

button的图标路径,图标格式为jpg,png和svg。

-

placement5+

-

string

-

end

-

-

仅在type属性为缺省时生效,设置图标位于文本的位置,可选值为:

-
  • start:图标位于文本起始处;
  • end:图标位于文本结束处;
  • top:图标位于文本上方;
  • bottom:图标位于文本下方。
-

waiting

-

boolean

-

false

-

-

waiting状态,waiting为true时展现等待中转圈效果,位于文本左侧。类型为download时不生效,不支持智能穿戴。

-
- -## 样式 - -### type设置为非arc - -除支持[通用样式](/pages/010c0201010102)外,还支持如下样式: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

text-color

-

<color>

-

#ff007dff

-

-

按钮的文本颜色。

-

font-size

-

<length>

-

16px

-

-

按钮的文本尺寸。

-

allow-scale

-

boolean

-

true

-

-

按钮的文本尺寸是否跟随系统设置字体缩放尺寸进行放大缩小。

-
说明:

如果在config描述文件中针对ability配置了fontSize的config-changes标签,则应用不会重启而直接生效。

-
-

font-style

-

string

-

normal

-

-

按钮的字体样式。

-

font-weight

-

number | string

-

normal

-

-

按钮的字体粗细。见text组件font-weight的样式属性

-

font-family

-

<string>

-

sans-serif

-

-

按钮的字体列表,用逗号分隔,每个字体用字体名或者字体族名设置。列表中第一个系统中存在的或者通过自定义字体指定的字体,会被选中作为文本的字体。

-

icon-width

-

<length>

-

-

-

-

设置圆形按钮内部图标的宽,默认填满整个圆形按钮。

-
说明:

icon使用svg图源时必须设置该样式。

-
-

icon-height

-

<length>

-

-

-

-

设置圆形按钮内部图标的高,默认填满整个圆形按钮。

-
说明:

icon使用svg图源时必须设置该样式。

-
-

radius

-

<length>

-

-

-

-

按钮圆角半径。在圆形按钮类型下该样式优先于通用样式的width和height样式。

-
- ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->- 胶囊按钮(type=capsule)时,不支持border相关样式; ->- 圆形按钮(type=circle)时,不支持文本相关样式; ->- 文本按钮(type=text)时,自适应文本大小,不支持尺寸设置(radius,width,height),背景透明不支持background-color样式。 - -### type设置为arc - -除支持[通用样式](/pages/010c0201010102)中background-color、opacity、display、visibility、position、\[left|top|right|bottom外,还支持如下样式: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

text-color

-

<color>

-

#de0000

-

-

弧形按钮的文本颜色。

-

font-size

-

<length>

-

37.5px

-

-

弧形按钮的文本尺寸。

-

allow-scale

-

boolean

-

true

-

-

弧形按钮的文本尺寸是否跟随系统设置字体缩放尺寸进行放大缩小。

-

font-style

-

string

-

normal

-

-

弧形按钮的字体样式。

-

font-weight

-

number | string

-

normal

-

-

弧形按钮的字体粗细。见text组件font-weight的样式属性

-

font-family

-

<string>

-

sans-serif

-

-

按钮的字体列表,用逗号分隔,每个字体用字体名或者字体族名设置。列表中第一个系统中存在的或者通过自定义字体指定的字体,会被选中作为文本的字体。

-
- -## 事件 - -支持[通用事件](/pages/010c0201010103)。 - -## 方法 - -支持[通用方法](/pages/010c0201010104)。 - -类型为download时,支持如下方法: - - - - - - - - - - - -

名称

-

参数

-

描述

-

setProgress

-

{ progress:percent }

-

设定下载按钮进度条进度,取值位于0-100区间内,当设置的值大于0时,下载按钮展现进度条。当设置的值大于等于100时,取消进度条显示。

-
说明:

浮在进度条上的文字通过value值进行变更。

-
-
- -## 示例 - -``` - -
- - - - - -
-``` - -``` -/* xxx.css */ -.div-button { - flex-direction: column; - align-items: center; -} -.first{ - background-color: #F2F2F2; - text-color: #0D81F2; -} -.button { - margin-top: 15px; -} -.last{ - background-color: #F2F2F2; - text-color: #969696; - margin-top: 15px; - width: 280px; - height:72px; -} -.button:waiting { - width: 280px; -} -.circle { - background-color: #007dff; - radius: 72px; - icon-width: 72px; - icon-height: 72px; -} -.text { - text-color: red; - font-size: 40px; - font-weight: 900; - font-family: sans-serif; - font-style: normal; -} -.download { - width: 280px; - text-color: white; - background-color: #007dff; -} -``` - -``` -// xxx.js -export default { - data: { - count: 5, - downloadText: "Download" - }, - progress(e) { - this.count+= 10; - this.downloadText = this.count+ "%"; - this.$element('download-btn').setProgress({ progress: this.count}); - if (this.count>= 100) { - this.downloadText = "Done"; - } - } -} -``` - -![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127125132.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/02.chart.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/02.chart.md" deleted file mode 100644 index 5298c97c537b7c572a30c59806d49c3784382d0d..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/02.chart.md" +++ /dev/null @@ -1,1163 +0,0 @@ ---- -title: chart -permalink: /pages/010c0201010302 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# chart - -图表组件,用于呈现线形图、柱状图、量规图界面。 - -## 权限列表 - -无 - -## 子组件 - -不支持。 - -## 属性 - -除支持[通用属性](/pages/010c0201010101)外,还支持如下属性: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

type

-

string

-

line

-

-

设置图表类型(不支持动态修改),可选项有:

-
  • bar:柱状图。
  • line:线形图。
  • gauge:量规图。
  • progress5+:进度类圆形图表。
  • loading5+:加载类圆形图表。
  • rainbow5+:占比类圆形图表。
-

options

-

ChartOptions

-

-

-

-

图表参数设置,柱状图和线形图必须设置参数设置,量规图不生效。可以设置x轴、y轴的最小值、最大值、刻度数、是否显示,线条宽度、是否平滑等。(不支持动态修改)

-

datasets

-

Array<ChartDataset>

-

-

-

-

数据集合,柱状图和线形图必须设置数据集合,量规图不生效。可以设置多条数据集及其背景色。

-

segments5+

-

DataSegment | Array<DataSegment>

-

-

-

-

进度类、加载类和占比类圆形图表使用的数据结构。

-

DataSegment针对进度类和加载类圆形图表使用,

-

Array<DataSegment>针对占比类图标使用,DataSegment最多9个。

-
说明:

仅手机和平板设备支持。

-
-

effects5+

-

boolean

-

true

-

-

是否开启占比类、进度类圆形图表特效。

-
说明:

仅手机和平板设备支持。

-
-

animationduration6+

-

number

-

3000

-

-

设置占比类圆形图表展开动画时长,单位为ms。

-
说明:

仅手机和平板设备支持。

-
-
- -**表 1** ChartOptions - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

xAxis

-

ChartAxis

-

-

-

-

x轴参数设置。可以设置x轴最小值、最大值、刻度数以及是否显示。

-

yAxis

-

ChartAxis

-

-

-

-

y轴参数设置。可以设置y轴最小值、最大值、刻度数以及是否显示。

-

series

-

ChartSeries

-

-

-

-

数据序列参数设置。可以设置1)线的样式,如线宽、是否平滑;2)设置线最前端位置白点的样式和大小。

-
说明:

仅线形图支持。

-
-
- -**表 2** ChartDataset - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

strokeColor

-

<color>

-

#ff6384

-

-

线条颜色。

-
说明:

仅线形图支持。

-
-

fillColor

-

<color>

-

#ff6384

-

-

填充颜色。线形图表示填充的渐变颜色。

-

data

-

Array<number> | Array<Point>5+

-

-

-

-

设置绘制线或柱中的点集。

-

gradient

-

boolean

-

false

-

-

设置是否显示填充渐变颜色。

-
说明:

仅线形图支持。

-
-
- -**表 3** ChartAxis - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

min

-

number

-

0

-

-

轴的最小值。

-
说明:

仅线形图支持负数。

-
-

max

-

number

-

100

-

-

轴的最大值。

-
说明:

仅线形图支持负数。

-
-

axisTick

-

number

-

10

-

-

轴显示的刻度数量。

-
说明:

仅支持1~20,且具体显示的效果与如下计算值有关(图的宽度所占的像素/(max-min))。

-

在柱状图中,每组数据显示的柱子数量与刻度数量一致,且柱子显示在刻度处。

-
-

display

-

boolean

-

false

-

-

是否显示轴。

-

color

-

<color>

-

#c0c0c0

-

-

轴颜色。

-
- -**表 4** ChartSeries - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

lineStyle

-

ChartLineStyle

-

-

-

-

线样式设置,如线宽、是否平滑。

-

headPoint

-

PointStyle

-

-

-

-

线最前端位置白点的样式和大小。

-

topPoint

-

PointStyle

-

-

-

-

最高点的样式和大小。

-

bottomPoint

-

PointStyle

-

-

-

-

最低点的样式和大小。

-

loop

-

ChartLoop

-

-

-

-

设置屏幕显示满时,是否需要重头开始绘制。

-
- -**表 5** ChartLineStyle - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

width

-

<length>

-

1px

-

-

线宽设置。

-

smooth

-

boolean

-

false

-

-

是否平滑。

-
- -**表 6** PointStyle - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

shape

-

string

-

circle

-

-

高亮点的形状。可选值为:

-
  • circle:圆形。
  • square:方形。
  • triangle:三角形。
-

size

-

<length>

-

5px

-

-

高亮点的大小。

-

strokeWidth

-

<length>

-

1px

-

-

边框宽度

-

strokeColor

-

<color>

-

#ff0000

-

-

边框颜色。

-

fillColor

-

<color>

-

#ff0000

-

-

填充颜色。

-
- -**表 7** ChartLoop - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

margin

-

<length>

-

1

-

-

擦除点的个数(最新绘制的点与最老的点之间的横向距离)。注意:轻量设备margin和topPoint/bottomPoint/headPoint同时使用时,有概率出现point正好位于擦除区域的情况,导致point不可见,因此不建议同时使用。

-

gradient

-

boolean

-

false

-

-

是否需要渐变擦除。

-
- -**表 8** Point5+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

value

-

number

-

0

-

-

表示绘制点的Y轴坐标。

-

pointStyle

-

PointStyle

-

-

-

-

表示当前数据点的绘制样式。

-

description

-

string

-

-

-

-

表示当前点的注释内容。

-

textLocation

-

string

-

-

-

-

可选值为top,bottom,none。分别表示注释的绘制位置位于点的上方,下方,以及不绘制。

-

textColor

-

<color>

-

#000000

-

-

表示注释文字的颜色。

-

lineDash

-

string

-

solid

-

-

表示绘制当前线段虚线的样式。“dashed, 5, 5”表示纯虚线,绘制5px的实线后留5px的空白。“solid”表示绘制实线。

-

lineColor

-

<color>

-

#000000

-

-

表示绘制当前线段的颜色。此颜色不设置会默认使用整体的strokeColor。

-
- -**表 9** DataSegment5+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

startColor

-

Color

-

-

-

-

起始位置的颜色,设置startColor必须设置endColor。不设置startColor时,会使用系统默认预置的颜色数组,具体颜色值见下表。

-

endColor

-

Color

-

-

-

-

终止位置的颜色,设置endColor必须设置startColor。

-

不设置startColor时,会使用系统默认预置的颜色数组。

-

value

-

number

-

0

-

-

占比数据的所占份额,最大100。

-

name

-

string

-

-

-

-

此类数据的名称。

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

数据组

-

浅色主题

-

深色主题

-

0

-

起始颜色:#f7ce00,结束颜色:#f99b11

-

起始颜色:#d1a738,结束颜色:#eb933d

-

1

-

起始颜色:#f76223,结束颜色:#f2400a

-

起始颜色:#e67d50,结束颜色:#d9542b

-

2

-

起始颜色:#f772ac,结束颜色:#e65392

-

起始颜色:#d5749e,结束颜色:#d6568d

-

3

-

起始颜色:#a575eb,结束颜色:#a12df7

-

起始颜色:#9973d1,结束颜色:#5552d9

-

4

-

起始颜色:#7b79f7,结束颜色:#4b48f7

-

起始颜色:#7977d9,结束颜色:#f99b11

-

5

-

起始颜色:#4b8af3,结束颜色:#007dff

-

起始颜色:#4c81d9,结束颜色:#217bd9

-

6

-

起始颜色:#73c1e6,结束颜色:#4fb4e3

-

起始颜色:#5ea6d1,结束颜色:#4895c2

-

7

-

起始颜色:#a5d61d,结束颜色:#69d14f

-

起始颜色:#91c23a,结束颜色:#70ba5d

-

8

-

起始颜色:#a2a2b0,结束颜色:#8e8e93

-

起始颜色:#8c8c99,结束颜色:#6b6b76

-
- -当类型为量规图时,还支持如下属性: - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

percent

-

number

-

0

-

-

当前值占整体的百分比,取值范围为0-100。

-
- -## 样式 - -除支持[通用样式](/pages/010c0201010102)外,还支持如下样式: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

stroke-width

-

<length>

-

32px(量规)

-

24px(占比类圆形图表)

-

-

量规、占比类圆形图表组件刻度条的宽度。

-

start-angle

-

<deg>

-

240(量规)

-

0(占比类圆形图表)

-

-

量规、占比类圆形图表组件刻度条起始角度,以时钟0点为基线。范围为0到360。

-

total-angle

-

<deg>

-

240(量规)

-

360(占比类圆形图表)

-

-

量规、占比类圆形图表组件刻度条总长度,范围为-360到360,负数标识起点到终点为逆时针。

-

center-x

-

<length>

-

-

-

-

量规组件刻度条中心位置,该样式优先于通用样式的position样式。该样式需要和center-y和radius一起配置才能生效。(仅量规图支持)

-

center-y

-

<length>

-

-

-

-

量规组件刻度条中心位置,该样式优先于通用样式的position样式。该样式需要和center-x和radius一起配置才能生效。(仅量规图支持)

-

radius

-

<length>

-

-

-

-

量规组件刻度条半径,该样式优先于通用样式的width和height样式。该样式需要和center-x和center-y一起配置才能生效。(仅量规图支持)

-

colors

-

Array

-

-

-

-

量规组件刻度条每一个区段的颜色。

-

如:colors: #ff0000, #00ff00。(仅量规图支持)

-

weights

-

Array

-

-

-

-

量规组件刻度条每一个区段的权重。

-

如:weights: 2, 2。(仅量规图支持)

-

font-family5+

-

Array

-

-

-

-

表示绘制注释的字体样式,支持自定义字体

-

font-size5+

-

<length>

-

-

-

-

表示绘制注释的字体的大小。

-
- -## 事件 - -支持[通用事件](/pages/010c0201010103)。 - -## 方法 - -除支持[通用方法](/pages/010c0201010104)外,还支持如下方法: - - - - - - - - - - - -

方法

-

参数

-

描述

-

append

-

{

-

serial: number, // 设置要更新的线形图数据下标

-

data: Array<number>, // 设置新增的数据

-

}

-

往已有的数据序列中动态添加数据,根据serial指定目标序列,serial为datasets数组的下标,从0开始。注意:不会更新datasets[index].data。仅线形图支持,按横坐标加1递增(与xAxis min/max设置相关)。

-
- -## 示例 - -1. 线形图 - - ``` - -
- - - - - -
- ``` - - ``` - /* xxx.css */ - .container { - flex-direction: column; - justify-content: center; - align-items: center; - } - .chart-region { - height: 400px; - width: 700px; - } - .chart-background { - object-fit: fill; - } - .chart-data { - width: 700px; - height: 600px; - } - button { - width: 100%; - height: 50px; - background-color: #F4F2F1; - text-color: #0C81F3; - } - ``` - - ``` - // xxx.js - export default { - data: { - lineData: [ - { - strokeColor: '#0081ff', - fillColor: '#cce5ff', - data: [763, 550, 551, 554, 731, 654, 525, 696, 595, 628, 791, 505, 613, 575, 475, 553, 491, 680, 657, 716], - gradient: true, - } - ], - lineOps: { - xAxis: { - min: 0, - max: 20, - display: false, - }, - yAxis: { - min: 0, - max: 1000, - display: false, - }, - series: { - lineStyle: { - width: "5px", - smooth: true, - }, - headPoint: { - shape: "circle", - size: 20, - strokeWidth: 5, - fillColor: '#ffffff', - strokeColor: '#007aff', - display: true, - }, - loop: { - margin: 2, - gradient: true, - } - } - }, - }, - addData() { - this.$refs.linechart.append({ - serial: 0, - data: [Math.floor(Math.random() * 400) + 400] - }) - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173324843.png) - -2. 柱状图 - - ``` - -
- - - - -
- ``` - - ``` - /* xxx.css */ - .container { - flex-direction: column; - justify-content: center; - align-items: center; - } - .data-region { - height: 400px; - width: 700px; - } - .data-background { - object-fit: fill; - } - .data-bar { - width: 700px; - height: 400px; - } - ``` - - ``` - // xxx.js - export default { - data: { - barData: [ - { - fillColor: '#f07826', - data: [763, 550, 551, 554, 731, 654, 525, 696, 595, 628], - }, - { - fillColor: '#cce5ff', - data: [535, 776, 615, 444, 694, 785, 677, 609, 562, 410], - }, - { - fillColor: '#ff88bb', - data: [673, 500, 574, 483, 702, 583, 437, 506, 693, 657], - }, - ], - barOps: { - xAxis: { - min: 0, - max: 20, - display: false, - axisTick: 10, - }, - yAxis: { - min: 0, - max: 1000, - display: false, - }, - }, - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/barchart.png) - -3. 量规图 - - ``` - -
-
- -
-
- ``` - - ``` - /* xxx.css */ - .container { - flex-direction: column; - justify-content: center; - align-items: center; - } - .gauge-region { - height: 400px; - width: 400px; - } - .data-gauge { - colors: #83f115, #fd3636, #3bf8ff; - weights: 4, 2, 1; - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/gauge.png) - - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/03.divider.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/03.divider.md" deleted file mode 100644 index 163ed2980129a198a6adf24cad44b2062a7433de..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/03.divider.md" +++ /dev/null @@ -1,257 +0,0 @@ ---- -title: divider -permalink: /pages/010c0201010303 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# divider - -提供分隔器组件,分隔不同内容块/内容元素。可用于列表或界面布局。 - -## 权限列表 - -无 - -## 子组件 - -不支持。 - -## 属性 - -除支持[通用属性](/pages/010c0201010101)外,还支持如下属性: - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

vertical

-

boolean

-

false

-

-

使用水平分割线还是垂直分割线,默认水平。

-
- ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->不支持focusable、disabled属性。 - -## 样式 - -仅支持如下样式: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

margin

-

<length>

-

0

-

-

使用简写属性设置所有的外边距属性,该属性可以有1到4个值。

-

margin-[left|top|right|bottom]

-

<length>

-

0

-

-

使用简写属性设置左、上、右、下外边距属性,类型length,单位px,默认值0。

-

color

-

<color>

-

#08000000

-

-

设置分割线颜色。

-

stroke-width

-

<length>

-

1

-

-

设置分割线宽度。

-

display

-

string

-

flex

-

-

确定分割线所产生的框的类型。值flex/none,默认值flex。

-

visibility

-

string

-

visible

-

-

是否显示分割线。不可见的框会占用布局。visible代表显示元素,hidden代表不显示元素。

-

line-cap

-

string

-

butt

-

-

设置分割线条的端点样式,默认为butt,可选值为:

-
  • butt:分割线两端为平行线;
  • round:分割线两端额外添加半圆;
  • square:分割线两端额外添加半方形;
-
说明:

round和square会额外增加一个线宽的分割线长度。

-
-

flex

-

number

-

-

-

-

规定了分割线如何适应父组件中的可用空间。它作为一个简写属性,用来设置组件的flex-grow。

-
说明:

仅父容器为<div>、<list-item>、<tabs>时生效。

-
-

flex-grow

-

number

-

0

-

-

设置分割线的伸展因子,指定父组件容器主轴方向上剩余空间(容器本身大小减去所有flex项加起来的大小)的分配系数。0为不伸展。

-
说明:

仅父容器为<div>、<list-item>、<tabs>时生效。

-
-

-

flex-shrink

-

number

-

1

-

-

设置分割线的收缩因子,flex元素仅在默认宽度之和大于容器的时候才会发生收缩,0为不收缩。

-
说明:

仅父容器为<div>、<list-item>、<tabs>时生效。

-
-

flex-basis

-

<length>

-

-

-

-

-

设置分割线在主轴方向上的初始大小。

-
说明:

仅父容器为<div>、<list-item>、<tabs>时生效。

-
-
- -## 事件 - -不支持。 - -## 方法 - -不支持。 - -## 示例 - -``` - -
-
- -
-
-``` - -``` -/* xxx.css */ -.container { - margin: 20px; - flex-direction:column; - width:100%; - height:100%; - align-items:center; -} -.content{ - width:80%; - height:40%; - border:1px solid #000000; - align-items: center; - justify-content: center; - flex-direction:column; -} -.divider { - margin: 10px; - color: #ff0000ff; - stroke-width: 3px; - line-cap: round; -} -``` - -![](/images/application-dev/reference/arkui-js/figures/1.jpg) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/04.image.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/04.image.md" deleted file mode 100644 index 6db6ff48b2fdc82afa0151d709bff7c33c241e73..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/04.image.md" +++ /dev/null @@ -1,254 +0,0 @@ ---- -title: image -permalink: /pages/010c0201010304 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# image - -图片组件,用来渲染展示图片。 - -## 子组件 - -不支持。 - -## 属性 - -除支持[通用属性](/pages/010c0201010101)外,还支持如下属性: - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

src

-

string

-

-

-

-

图片的路径,支持本地路径,图片格式包括png、jpg、bmp、svg和gif。

-

支持Base64字符串6+。格式为data:image/[png | jpeg | bmp | webp];base64, [base64 data], 其中[base64 data]为Base64字符串数据。

-

支持dataability://的路径前缀,用于访问通过data ability提供的图片路径6+

-

alt

-

string

-

-

-

-

占位图,当指定图片在加载中时显示。

-
- -## 样式 - -除支持[通用样式](/pages/010c0201010102)外,还支持如下属性: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

object-fit

-

string

-

cover

-

-

设置图片的缩放类型。可选值类型说明请见object-fit 类型说明。(不支持svg格式)

-

match-text-direction

-

boolean

-

false

-

-

图片是否跟随文字方向。(不支持svg格式)

-

fit-original-size

-

boolean

-

false

-

-

image组件在未设置宽高的情况下是否适应图源尺寸(该属性为true时object-fit属性不生效),svg类型图源不支持该属性。

-

object-position7+

-

string

-

0px 0px

-

-

设置图片在组件内展示的位置。

-

设置类型有两种:

-

1. 像素,单位px,示例 15px 15px 代表X轴或者Y轴移动的位置

-

2. 字符,可选值:

-
  • left 图片显示在组件左侧;
  • top 图片显示在组件顶部位置;
  • right 图片显示在组件右侧位置;
  • bottom图片显示在组件底部位置。
-
- -**表 1** object-fit 类型说明 - - - - - - - - - - - - - - - - - - - - - - -

类型

-

描述

-

cover

-

保持宽高比进行缩小或者放大,使得图片两边都大于或等于显示边界,居中显示。

-

contain

-

保持宽高比进行缩小或者放大,使得图片完全显示在显示边界内,居中显示。

-

fill

-

不保持宽高比进行放大缩小,使得图片填充满显示边界。

-

none

-

保持原有尺寸进行居中显示。

-

scale-down

-

保持宽高比居中显示,图片缩小或者保持不变。

-
- ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->使用svg图片资源时: ->- 建议设置image组件的长宽,否则在父组件的长或宽为无穷大的场景下,svg资源将不会绘制; ->- 如果svg描述中未指定相应的长宽,则svg将会填满image组件区域; ->- 如果svg描述中指定了相应的长宽,和image组件本身的长宽效果如下: ->1. 如果image组件本身的长宽小于svg中的长宽,svg会被裁切,仅显示左上角部分; ->2. 如果image组件本身的长宽大于svg中的长宽,svg会被放置在image组件的左上角,image组件其他部分显示空白。 - -## 事件 - -除支持[通用事件](/pages/010c0201010103)外,还支持如下事件: - - - - - - - - - - - - - - - -

名称

-

参数

-

描述

-

complete(Rich)

-

{ width:width, height:height }

-

图片成功加载时触发该回调,返回成功加载的图源尺寸。

-

error(Rich)

-

{ width:width, height:height }

-

图片加载出现异常时触发该回调,异常时长宽为零。

-
- -## 方法 - -支持[通用方法](/pages/010c0201010104)。 - -## 示例 - -``` - -
- - - -
-``` - -``` -/* xxx.css */ -.container { - justify-content: center; - align-items: center; - flex-direction: column; - - -} -.selects{ - margin-top: 20px; - width:300px; - border:1px solid #808080; - border-radius: 10px; -} -``` - -``` -// xxx.js -export default { - data: { - fit:"cover", - fits: ["cover", "contain", "fill", "none", "scale-down"], - }, - change_fit(e) { - this.fit = e.newValue; - }, -} -``` - -![](/images/application-dev/reference/arkui-js/figures/GIF.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/05.image-animator.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/05.image-animator.md" deleted file mode 100644 index 07ad1dcffc92aaec1f3bb9a02a4555448cd572a6..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/05.image-animator.md" +++ /dev/null @@ -1,428 +0,0 @@ ---- -title: image-animator -permalink: /pages/010c0201010305 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# image-animator - -图片帧动画播放器。 - -## 子组件 - -不支持。 - -## 属性 - -除支持[通用属性](/pages/010c0201010101)外,还支持如下属性: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

images

-

Array<ImageFrame>

-

-

-

-

设置图片帧信息集合。每一帧的帧信息包含图片路径、图片大小和图片位置信息。目前支持以下图片格式:png、jpg。ImageFrame的详细说明请见表1

-
说明:

使用时需要使用数据绑定的方式,如images = {{images}},js中声明相应变量:images: [{src: "/common/heart-rate01.png"}, {src: "/common/heart-rate02.png"}]。

-

js中声明相应变量:images: [{src: "/common/heart-rate01.png", duration: "100"}, {src: "/common/heart-rate02.png", duration: "200"}]。支持配置每一帧图片的时长,单位毫秒。6+

-
-

predecode6+

-

number

-

0

-

-

是否启用预解码,默认值为0,即不启用预解码,如该值设为2,则播放当前页时会提前加载后面两张图片至缓存以提升性能。

-

iteration

-

number | string

-

infinite

-

-

设置帧动画播放次数。number表示固定次数,infinite枚举表示无限次数播放。

-

reverse

-

boolean

-

false

-

-

设置播放顺序。false表示从第1张图片播放到最后1张图片; true表示从最后1张图片播放到第1张图片。

-

fixedsize

-

boolean

-

true

-

-

设置图片大小是否固定为组件大小。 true表示图片大小与组件大小一致,此时设置图片的width 、height 、top 和left属性是无效的。false表示每一张图片的 width 、height 、top和left属性都要单独设置。

-

duration

-

string

-

-

-

-

设置单次播放时长。单位支持[s(秒)|ms(毫秒)],默认单位为ms。 duration为0时,不播放图片。 值改变只会在下一次循环开始时生效,当images中设置了单独的duration后,该属性设置无效。

-

fillmode5+

-

string

-

forwards

-

-

指定帧动画执行结束后的状态。可选项有:

-
  • none:恢复初始状态。
  • forwards:保持帧动画结束时的状态(在最后一个关键帧中定义)。
-
- -**表 1** ImageFrame说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

src

-

<uri>

-

-

-

-

图片路径,图片格式为svg,png和jpg

-

width

-

<length>

-

0

-

-

图片宽度。

-

height

-

<length>

-

0

-

-

图片高度。

-

top

-

<length>

-

0

-

-

图片相对于组件左上角的纵向坐标。

-

left

-

<length>

-

0

-

-

图片相对于组件左上角的横向坐标。

-

duration6+

-

number

-

-

-

-

每一帧图片的播放时长,单位毫秒。

-
- -## 样式 - -支持[通用样式](/pages/010c0201010102)。 - -## 事件 - -除支持[通用事件](/pages/010c0201010103)外,还支持如下事件: - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数

-

描述

-

start

-

-

-

帧动画启动时触发。

-

pause

-

-

-

帧动画暂停时触发。

-

stop

-

-

-

帧动画结束时触发。

-

resume

-

-

-

帧动画恢复时触发。

-
- -## 方法 - -支持[通用方法](/pages/010c0201010104)外,还支持如下方法: - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数

-

描述

-

start

-

-

-

开始播放图片帧动画。再次调用,重新从第1帧开始播放。

-

pause

-

-

-

暂停播放图片帧动画。

-

stop

-

-

-

停止播放图片帧动画。

-

resume

-

-

-

继续播放图片帧。

-

getState

-

-

-

获取播放状态。可能值有:

-
  • playing:播放中
  • paused:已暂停
  • stopped:已停止。
-
- -## 示例 - -``` - -
- -
- - - - -
-
-``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - justify-content: center; - align-items: center; - left: 0px; - top: 0px; - width: 454px; - height: 454px; -} -.animator { - width: 70px; - height: 70px; -} -.btn-box { - width: 264px; - height: 120px; - flex-wrap: wrap; - justify-content: space-around; - align-items: center; -} -.btn { - border-radius: 8px; - width: 120px; - margin-top: 8px; -} -``` - -``` -//xxx.js -export default { - data: { - frames: [ - { - src: "/common/asserts/heart78.png", - }, - { - src: "/common/asserts/heart79.png", - }, - { - src: "/common/asserts/heart80.png", - }, - { - src: "/common/asserts/heart81.png", - }, - { - src: "/common/asserts/heart82.png", - }, - { - src: "/common/asserts/heart83.png", - }, - { - src: "/common/asserts/heart84.png", - }, - { - src: "/common/asserts/heart85.png", - }, - { - src: "/common/asserts/heart86.png", - }, - { - src: "/common/asserts/heart87.png", - }, - { - src: "/common/asserts/heart88.png", - }, - { - src: "/common/asserts/heart89.png", - }, - { - src: "/common/asserts/heart90.png", - }, - { - src: "/common/asserts/heart91.png", - }, - { - src: "/common/asserts/heart92.png", - }, - { - src: "/common/asserts/heart93.png", - }, - { - src: "/common/asserts/heart94.png", - }, - { - src: "/common/asserts/heart95.png", - }, - { - src: "/common/asserts/heart96.png", - }, - ], - }, - handleStart() { - this.$refs.animator.start(); - }, - handlePause() { - this.$refs.animator.pause(); - }, - handleResume() { - this.$refs.animator.resume(); - }, - handleStop() { - this.$refs.animator.stop(); - }, -}; -``` - -![](/images/application-dev/reference/arkui-js/figures/image-animator.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/06.input.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/06.input.md" deleted file mode 100644 index bce7efb8b7fdd15e930690e89441b092d524a337..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/06.input.md" +++ /dev/null @@ -1,619 +0,0 @@ ---- -title: input -permalink: /pages/010c0201010306 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# input - -交互式组件,包括单选框,多选框,按钮和单行文本输入框。 - -## 权限列表 - -无 - -## 子组件 - -不支持。 - -## 属性 - -除支持[通用属性](/pages/010c0201010101)外,还支持如下属性: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

type

-

string

-

text

-

-

input组件类型,可选值为text,email,date,time,number,password,button,checkbox,radio。

-

其中text,email,date,time,number,password这六种类型之间支持动态切换修改。

-

button,checkbox,radio不支持动态修改。可选值定义如下:

-
  • button:定义可点击的按钮;
  • checkbox:定义多选框;
  • radio:定义单选按钮,允许在多个拥有相同name值的选项中选中其中一个;
  • text:定义一个单行的文本字段
  • email:定义用于e-mail地址的字段;
  • date:定义 date 控件(包括年、月、日,不包括时间);
  • time:定义用于输入时间的控件(不带时区);
  • number:定义用于输入数字的字段;
  • password:定义密码字段(字段中的字符会被遮蔽)。
    说明:

    智能穿戴仅支持button、radio、checkbox类型。

    -
    -
-

checked

-

boolean

-

false

-

-

当前组件是否选中,仅type为checkbox和radio生效。

-

name

-

string

-

-

-

-

input组件的名称。

-

value

-

string

-

-

-

-

input组件的value值,当类型为radio时必填且相同name值的选项该值唯一。

-

placeholder

-

string

-

-

-

-

设置提示文本的内容,仅在type为text|email|date|time|number|password时生效。

-

maxlength

-

number

-

-

-

-

输入框可输入的最多字符数量,不填表示不限制输入框中字符数量。

-

enterkeytype

-

string

-

default

-

-

不支持动态修改。

-

设置软键盘Enter按钮的类型,可选值为:

-
  • default:默认
  • next:下一项
  • go:前往
  • done:完成
  • send:发送
  • search:搜索
-
说明:

除“next”外,点击后会自动收起软键盘。

-
-

headericon

-

string

-

-

-

-

在文本输入前的图标资源路径,该图标不支持点击事件(button,checkbox和radio不生效),图标格式为jpg,png和svg。

-

showcounter5+

-

boolean

-

false

-

-

文本输入框是否显示计数下标,需要配合maxlength一起使用。

-

menuoptions5+

-

Array<MenuOption>

-

-

-

-

设置文本选择弹框点击更多按钮之后显示的菜单项。

-

autofocus6+

-

boolean

-

false

-

-

是否自动获焦。

-
说明:

应用首页中设置不生效,可在onActive中延迟(100-500ms左右)调用focus方法实现输入框在首页中自动获焦。

-
-

selectedstart6+

-

number

-

-1

-

-

开始选择文本时初始选择位置。

-

selectedend6+

-

number

-

-1

-

-

开始选择文本时结尾选择位置。

-

softkeyboardenabled6+

-

boolean

-

true

-

-

编辑时是否弹出系统软键盘。

-

showpasswordicon6+

-

boolean

-

true

-

-

是否显示密码框末尾的图标(仅type为password时生效)。

-
- -**表 1** MenuOption5+ - - - - - - - - - - - - - - - - -

名称

-

类型

-

描述

-

icon

-

string

-

菜单选项中的图标路径。

-

content

-

string

-

菜单选项中的文本内容。

-
- -## 样式 - -除支持[通用样式](/pages/010c0201010102)外,还支持如下样式: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

color

-

<color>

-

#e6000000

-

-

单行输入框或者按钮的文本颜色。

-

font-size

-

<length>

-

16px

-

-

单行输入框或者按钮的文本尺寸。

-

allow-scale

-

boolean

-

true

-

-

单行输入框或者按钮的文本尺寸是否跟随系统设置字体缩放尺寸进行放大缩小。

-
说明:

如果在config描述文件中针对ability配置了fontSize的config-changes标签,则应用不会重启而直接生效。

-
-

placeholder-color

-

<color>

-

#99000000

-

-

单行输入框的提示文本的颜色,type为text|email|date|time|number|password时生效。

-

font-weight

-

number | string

-

normal

-

-

单行输入框或者按钮的字体粗细,见text组件font-weight的样式属性

-

caret-color6+

-

<color>

-

-

-

-

设置输入光标的颜色。

-
- -## 事件 - -除支持[通用事件](/pages/010c0201010103)外,还支持如下事件: - -- 当input类型为text、email、date、time、number、password时,支持如下事件: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数

-

描述

-

change

-

{ value:inputValue }

-

输入框输入内容发生变化时触发该事件,返回用户当前输入值。

-
说明:

改变value属性值不会触发该回调。

-
-

enterkeyclick

-

{ value:enterKey }

-

软键盘enter键点击后触发该事件,返回enter按钮的类型,enterKey类型为number,可选值为:

-
  • 2:设置enterkeytype属性为go时生效。
  • 3:设置enterkeytype属性为search时生效。
  • 4:设置enterkeytype属性为send时生效。
  • 5:设置enterkeytype属性为next时生效。
  • 6:不设置enterkeytype或者设置enterkeytype属性为default、done时生效。
-

translate5+

-

{ value: selectedText }

-

设置此事件后,进行文本选择操作后文本选择弹窗会出现翻译按钮,点击翻译按钮之后,触发该回调,返回选中的文本内容。

-

share5+

-

{ value: selectedText }

-

设置此事件后,进行文本选择操作后文本选择弹窗会出现分享按钮,点击分享按钮之后,触发该回调,返回选中的文本内容。

-

search5+

-

{ value: selectedText }

-

设置此事件后,进行文本选择操作后文本选择弹窗会出现搜索按钮,点击搜索按钮之后,触发该回调,返回选中的文本内容。

-

optionselect5+

-

{ index:optionIndex, value: selectedText }

-

文本选择弹窗中设置menuoptions属性后,用户在文本选择操作后,点击菜单项后触发该回调,返回点击的菜单项序号和选中的文本内容。

-

selectchange6+

-

{ start: number,end: number }

-

文本选择变化时触发事件。

-
- -- 当input类型为checkbox、radio时,支持如下事件: - - - - - - - - - - - -

名称

-

参数

-

描述

-

change

-

{ checked:true | false }

-

checkbox多选框或radio单选框的checked状态发生变化时触发该事件。

-
- - -## 方法 - -除支持[通用方法](/pages/010c0201010104)外,还支持如下方法: - - - - - - - - - - - - - - - - - - - -

名称

-

参数

-

描述

-

focus

-

{ focus: true|false },focus不传默认为true。

-

使组件获得或者失去焦点,type为text|email|date|time|number|password时,可弹出或收起输入法。

-

showError

-

{ error: string }

-

展示输入错误提示,type为text|email|date|time|number|password时生效。

-

delete6+

-

-

-

type为text|email|date|time|number|password时,根据当前光标位置删除文本内容,如果当前输入组件没有光标,默认删除最后一个字符并展示光标。

-
- -## 示例 - -1. type为text - - ``` - -
- - - -
- ``` - - ``` - /* xxx.css */ - .content { - width: 60%; - flex-direction: column; - align-items: center; - } - .input { - placeholder-color: gray; - } - .button { - background-color: gray; - margin-top: 20px; - } - ``` - - ``` - // xxx.js - import prompt from '@system.prompt' - export default { - change(e){ - prompt.showToast({ - message: "value: " + e.value, - duration: 3000, - }); - }, - enterkeyClick(e){ - prompt.showToast({ - message: "enterkey clicked", - duration: 3000, - }); - }, - buttonClick(e){ - this.$element("input").showError({ - error: 'error text' - }); - }, - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127284984.png) - -2. type为button - - ``` - -
- -
- ``` - - ``` - /* xxx.css */ - .div-button { - flex-direction: column; - align-items: center; - - - } - .button { - margin-top: 30px; - width: 280px; - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001198898293.png) - -3. type为checkbox - - ``` - -
- - -
- ``` - - ``` - /* xxx.css */ - .content{ - width: 100%; - height: 200px; - - - align-items: center; - justify-content: center; - } - ``` - - ``` - // xxx.js - import prompt from '@system.prompt' - export default { - checkboxOnChange(e) { - prompt.showToast({ - message:'checked: ' + e.checked, - duration: 3000, - }); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173324749.png) - -4. type为radio - - ``` - -
- - - -
- ``` - - ``` - /* xxx.css */ - .content{ - width: 100%; - height: 200px; - justify-content: center; - align-items: center; - } - ``` - - ``` - // xxx.js - import prompt from '@system.prompt' - export default { - onRadioChange(inputValue, e) { - if (inputValue === e.value) { - prompt.showToast({ - message: 'The chosen radio is ' + e.value, - duration: 3000, - }); - } - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173324751.png) - - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/07.label.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/07.label.md" deleted file mode 100644 index 8a24d16ba589a3530ede2a062758851f3aa26f24..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/07.label.md" +++ /dev/null @@ -1,311 +0,0 @@ ---- -title: label -permalink: /pages/010c0201010307 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# label - -为input、button、textarea组件定义相应的标注,点击该标注时会触发绑定组件的点击效果。 - -## 权限列表 - -无 - -## 子组件 - -不支持。 - -## 属性 - -除支持[通用属性](/pages/010c0201010101)外,还支持如下属性: - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

target

-

string

-

-

-

-

目标组件的属性id值。

-
- -## 样式 - -除支持[通用样式](/pages/010c0201010102)外,还支持如下样式: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

color

-

<color>

-

#e5000000

-

-

设置文本的颜色。

-

font-size

-

<length>

-

30px

-

-

设置文本的尺寸。

-

allow-scale

-

boolean

-

true

-

-

文本尺寸是否跟随系统设置字体缩放尺寸进行放大缩小。

-
说明:

如果需要支持动态生效,请参看config描述文件中config-changes标签。

-
-

letter-spacing

-

<length>

-

0px

-

-

设置文本的字符间距。

-

font-style

-

string

-

normal

-

-

设置文本的字体样式,可选值为:

-
  • normal:标准的字体样式;
  • italic:斜体的字体样式。
-

font-weight

-

number | string

-

normal

-

-

设置文本的字体粗细,number类型取值[100, 900],默认为400,取值越大,字体越粗。

-
说明:

number取值必须为100的整数倍。

-
-

string类型取值支持如下四个值:lighter、normal、bold、bolder。

-

text-decoration

-

string

-

none

-

-

设置文本的文本修饰,可选值为:

-
  • underline:文字下划线修饰;
  • line-through:穿过文本的修饰线n
  • none:标准文本。
-

text-align

-

string

-

start

-

-

设置文本的文本对齐方式,可选值为:

-
  • left:文本左对齐;
  • center:文本居中对齐;
  • right:文本右对齐;
  • start:根据文字书写相同的方向对齐;
  • end:根据文字书写相反的方向对齐。
-
说明:

如文本宽度未指定大小,文本的宽度和父容器的宽度大小相等的情况下,对齐效果可能会不明显。

-
-

line-height

-

<length>

-

0px

-

-

设置文本的文本行高,设置为0px时,不限制文本行高,自适应字体大小。

-

text-overflow

-

string

-

clip

-

-

在设置了最大行数的情况下生效,可选值为:

-
  • clip:将文本根据父容器大小进行裁剪显示;
  • ellipsis:根据父容器大小显示,显示不下的文本用省略号代替。需配合max-lines使用。
-

font-family

-

string

-

sans-serif

-

-

设置文本的字体列表,用逗号分隔,每个字体用字体名或者字体族名设置。列表中第一个系统中存在的或者通过自定义字体指定的字体,会被选中作为文本的字体。

-

max-lines

-

number

-

-

-

-

设置文本的最大行数。

-

min-font-size

-

<length>

-

-

-

-

文本最小字号,需要和文本最大字号同时设置,支持文本字号动态变化。设置最大最小字体样式后,font-size不生效。

-

max-font-size

-

<length>

-

-

-

-

文本最大字号,需要和文本最小字号同时设置,支持文本字号动态变化。设置最大最小字体样式后,font-size不生效。

-

font-size-step

-

<length>

-

1px

-

-

文本动态调整字号时的步长,需要设置最小,最大字号样式生效。

-

prefer-font-sizes

-

<array>

-

-

-

-

预设的字号集合,在动态尺寸调整时,优先使用预设字号集合中的字号匹配设置的最大行数,如果预设字号集合未设置,则使用最大最小和步长调整字号。针对仍然无法满足最大行数要求的情况,使用text-overflow设置项进行截断,设置预设尺寸集后,font-size、max-font-size、min-font-size和font-size-step不生效。

-

如:prefer-font-sizes: 12px,14px,16px

-
- -## 事件 - -不支持。 - -## 方法 - -不支持。 - -## 示例 - -``` - -
-
- - -
-
- - -
-
- - -
-
-``` - -``` -/*xxx.css */ -.container { - flex-direction: column; - align-items: center; -} -.row { - flex-direction: row; -} -.label { - width: 200px; - margin-top: 50px; -} -.input { - margin-left: 100px; - margin-top: 50px; -} -``` - -![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001152834002.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/08.marquee.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/08.marquee.md" deleted file mode 100644 index deceee2cfc8013f8f80977dab1eab159a8839261..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/08.marquee.md" +++ /dev/null @@ -1,292 +0,0 @@ ---- -title: marquee -permalink: /pages/010c0201010308 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# marquee - -跑马灯组件,用于展示一段单行滚动的文字。 - -## 权限列表 - -无 - -## 子组件 - -不支持。 - -## 属性 - -除支持[通用属性](/pages/010c0201010101)外,还支持如下属性: - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

scrollamount

-

number

-

6

-

-

跑马灯每次滚动时移动的最大长度。

-

loop

-

number

-

-1

-

-

跑马灯滚动的次数。如果未指定,则默认值为-1,当该值小于等于零时表示marquee将连续滚动。

-

direction

-

string

-

left

-

-

设置跑马灯的文字滚动方向,可选值为left和right。

-
- -## 样式 - -除支持[通用样式](/pages/010c0201010102)外,还支持如下样式: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

color

-

<color>

-

#e5000000

-

-

设置跑马灯中文字的文本颜色。

-

font-size

-

<length>

-

37.5

-

-

设置跑马灯中文字的文本尺寸。

-

allow-scale

-

boolean

-

true

-

-

设置跑马灯中文字的文本尺寸是否跟随系统设置字体缩放尺寸进行放大缩小。

-
说明:

如果在config描述文件中针对ability配置了fontSize的config-changes标签,则应用不会重启而直接生效。

-
-

font-weight

-

number | string

-

normal

-

-

设置跑马灯中文字的字体的粗细,见text组件font-weight的样式属性

-

font-family

-

string

-

sans-serif

-

-

设置跑马灯中文字的字体列表,用逗号分隔,每个字体用字体名或者字体族名设置。列表中第一个系统中存在的或者通过自定义字体指定的字体,会被选中作为文本的字体。

-
- -## 事件 - -除支持[通用事件](/pages/010c0201010103)外,还支持如下事件: - - - - - - - - - - - - - - - - - - - -

名称

-

参数

-

描述

-

bounce(Rich)

-

-

-

当文本滚动到末尾时触发该事件。

-

finish(Rich)

-

-

-

当完成滚动次数时触发该事件。需要在 loop 属性值大于 0 时触发。

-

start(Rich)

-

-

-

当文本滚动开始时触发该事件。

-
- -## 方法 - -除支持[通用方法](/pages/010c0201010104)外,还支持如下方法: - - - - - - - - - - - - - - - -

名称

-

参数

-

描述

-

start

-

-

-

开始滚动。

-

stop

-

-

-

停止滚动。

-
- -## 示例 - -``` - -
- {{marqueeCustomData}} -
- - -
-
-``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - justify-content: center; - align-items: center; - background-color: #ffffff; -} -.customMarquee { - width: 100%; - height: 80px; - padding: 10px; - margin: 20px; - border: 4px solid #ff8888; - border-radius: 20px; - font-size: 40px; - color: #ff8888; - font-weight: bolder; - font-family: serif; - background-color: #ffdddd; -} -.content { - flex-direction: row; -} -.controlButton { - flex-grow: 1; - background-color: #F2F2F2; - text-color: #0D81F2; -} -``` - -``` -// xxx.js -export default { - data: { - scrollAmount: 30, - loop: 3, - marqueeDir: 'left', - marqueeCustomData: 'Custom marquee', - }, - onMarqueeBounce: function() { - console.log("onMarqueeBounce"); - }, - onMarqueeStart: function() { - console.log("onMarqueeStart"); - }, - onMarqueeFinish: function() { - console.log("onMarqueeFinish"); - }, - onStartClick (evt) { - this.$element('customMarquee').start(); - }, - onStopClick (evt) { - this.$element('customMarquee').stop(); - } -} -``` - -![](/images/application-dev/reference/arkui-js/figures/sample1.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/09.menu.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/09.menu.md" deleted file mode 100644 index 2b697690fcd5ec20accb5fa73d43bfdc6fef1381..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/09.menu.md" +++ /dev/null @@ -1,273 +0,0 @@ ---- -title: menu -permalink: /pages/010c0201010309 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# menu - -提供菜单组件,作为临时性弹出窗口,用于展示用户可执行的操作。 - -## 权限列表 - -无 - -## 子组件 - -<[option](/pages/010c020101030a)\>子组件。 - -## 属性 - -除支持[通用属性](/pages/010c0201010101)外,还支持如下属性:↵ - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

target

-

string

-

-

-

-

目标元素选择器。当使用目标元素选择器后,点击目标元素会自动弹出menu菜单。弹出菜单位置优先为目标元素右下角,当右边可视空间不足时会适当左移,当下方空间不足时会适当上移。

-

type

-

string

-

click

-

-

目标元素触发弹窗的方式,可选值有:

-
  • click:点击弹窗。
  • longpress:长按弹窗。
-

title

-

string

-

-

-

-

菜单标题内容。

-
- ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->不支持focusable、disabled属性。 - -## 样式 - -仅支持如下样式: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

text-color

-

<color>

-

-

-

-

设置菜单的文本颜色。

-

font-size

-

<length>

-

30px

-

-

设置菜单的文本尺寸。

-

allow-scale

-

boolean

-

true

-

-

设置菜单的文本尺寸是否跟随系统设置字体缩放尺寸进行放大缩小。

-
说明:

如果在config描述文件中针对ability配置了fontSize的config-changes标签,则应用不会重启而直接生效。

-
-

letter-spacing

-

<length>

-

0

-

-

设置菜单的字符间距。

-

font-style

-

string

-

normal

-

-

设置菜单的字体样式。见text组件font-style的样式属性

-

font-weight

-

number | string

-

normal

-

-

设置菜单的字体粗细。见text组件font-weight的样式属性

-

font-family

-

string

-

sans-serif

-

-

设置菜单的字体列表,用逗号分隔,每个字体用字体名或者字体族名设置。列表中第一个系统中存在的或者通过自定义字体指定的字体,会被选中作为文本的字体。

-
- -## 事件 - -仅支持如下事件: - - - - - - - - - - - - - - - -

名称

-

参数

-

描述

-

selected

-

{ value:value }

-

菜单中某个值被点击选中时触发,返回的value值为option组件的value属性。

-

cancel

-

-

-

用户取消。

-
- -## 方法 - -仅支持如下方法。 - - - - - - - - - - - -

名称

-

参数

-

描述

-

show

-

{ x:x, y:y }

-

显示menu菜单。(x, y)指定菜单弹窗位置。其中x表示距离可见区域左边沿的 X 轴坐标,不包含任何滚动偏移,y表示距离可见区域上边沿的 Y 轴坐标,不包含任何滚动偏移以及状态栏。菜单优先显示在弹窗位置右下角,当右边可视空间不足时会适当左移,当下方空间不足时会适当上移。

-
- -## 示例 - -``` - -
- Show popup menu. - - - - - -
-``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - align-items: flex-start; - justify-content: center; -} -.title-text { - margin: 20px; -} -``` - -``` -// xxx.js -import prompt from '@system.prompt'; -export default { - onMenuSelected(e) { - prompt.showToast({ - message: e.value - }) - }, - onTextClick() { - this.$element("apiMenu").show({x:280,y:120}); - } -} -``` - -![](/images/application-dev/reference/arkui-js/figures/menu13.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/10.option.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/10.option.md" deleted file mode 100644 index 4dcbd97b46243d2efd5274533363b8e85f746cfa..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/10.option.md" +++ /dev/null @@ -1,180 +0,0 @@ ---- -title: option -permalink: /pages/010c020101030a -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# option - -当作为<[select](/pages/010c0201010313)\>的子组件时用来展示下拉选择的具体项目。 - -当作为<[menu](/pages/010c0201010309)\>的子组件时用来展示弹出菜单的具体项目。 - -## 权限列表 - -无 - -## 子组件 - -不支持。 - -## 属性 - -除支持[通用属性](/pages/010c0201010101)外,还支持如下属性:↵ - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

selected

-

boolean

-

-

-

-

选择项是否为下拉列表的默认项,仅在父组件是select时生效。

-

value

-

string

-

-

-

-

选择项的值,作为select、menu父组件的selected事件中的返回值。

-
说明:

option选项的UI展示值需要放在标签内,如<option value="10">十月</option>

-
-

icon

-

string

-

-

-

-

图标资源路径,该图标展示在选项文本前,图标格式为jpg,png和svg。

-
- -## 样式 - -支持如下样式。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

color

-

<color>

-

#e6000000

-

-

选择项的文本颜色。

-

font-size

-

<length>

-

16px

-

-

选择项的文本尺寸。

-

allow-scale

-

boolean

-

true

-

-

选择项的文本尺寸是否跟随系统设置字体缩放尺寸进行放大缩小。

-
说明:

如果在config描述文件中针对ability配置了fontSize的config-changes标签,则应用不会重启而直接生效。

-
-

font-weight

-

number | string

-

normal

-

-

选择项的字体粗细,见text组件font-weight的样式属性

-

text-decoration

-

string

-

none

-

-

选择项的文本修饰,见text组件text-decoration的样式属性

-

font-family

-

string

-

sans-serif

-

-

选择项的字体列表,用逗号分隔,每个字体用字体名或者字体族名设置。列表中第一个系统中存在的或者通过自定义字体指定的字体,会被选中作为文本的字体。

-
- -## 事件 - -不支持。 - -## 方法 - -不支持。 - -## 示例 - -详见[menu示例](/pages/010c0201010309#section54636714136)。 - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/11.picker.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/11.picker.md" deleted file mode 100644 index 0b76195ae9c9be1aab9df1c78c26292184286942..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/11.picker.md" +++ /dev/null @@ -1,846 +0,0 @@ ---- -title: picker -permalink: /pages/010c020101030b -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# picker - -滑动选择器组件,类型支持普通选择器、日期选择器、时间选择器、时间日期选择器和多列文本选择器。 - -## 权限列表 - -无 - -## 子组件 - -不支持。 - -## 属性 - -除支持[通用属性](/pages/010c0201010101)外,还支持如下属性:↵ - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

type

-

string

-

-

-

-

该属性值不支持动态修改。可选择项有:

-
  • text:文本选择器。
  • date:日期选择器。
  • time:时间选择器。
  • datetime:日期时间选择器。
  • multi-text:多列文本选择器。
-
- -### 普通选择器 - -滑动选择器类型设置为text时表示普通选择器。 - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

range

-

Array

-

-

-

-

设置普通选择器的取值范围,如["15", "20", "25"]。

-
说明:

使用时需要使用数据绑定的方式,如range = {{data}},js中声明相应变量:data:["15", "20", "25"]。

-
-

selected

-

string

-

0

-

-

设置普通选择器弹窗的默认取值,取值需要是 range 的索引值,该取值表示选择器弹窗界面的默认选择值。

-

value

-

string

-

-

-

-

设置普通选择器的值。

-
- -### 日期选择器 - -滑动选择器类型设置为date时表示日期选择器。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

start

-

<time>

-

1970-1-1

-

-

设置日期选择器的起始时间,格式为 YYYY-MM-DD。

-

end

-

<time>

-

2100-12-31

-

-

设置日期选择器的结束时间,格式为 YYYY-MM-DD。

-

selected

-

string

-

当前日期

-

-

设置日期选择器弹窗的默认取值,格式为 YYYY-MM-DD,该取值表示选择器弹窗界面的默认选择值。

-

value

-

string

-

-

-

-

设置日期选择器的值。

-

lunar5+

-

boolean

-

false

-

-

设置日期选择器弹窗界面是否为农历展示。

-

lunarswitch

-

boolean

-

false

-

-

设置日期选择器是否显示农历开关。当值为true时,显示农历开关,点击农历开关可切换公历和农历。当值为false时,不显示农历开关。

-
说明:

仅手机和平板设备支持。 当lunarswitch=true且lunar=true时,开关按钮处于被选中状态。

-
-
- -### 时间选择器 - -滑动选择器类型设置为time时表示时间选择器。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

containsecond

-

boolean

-

false

-

-

设置时间选择器是否包含秒。

-

selected

-

string

-

当前时间

-

-

设置时间选择器弹窗的默认取值,格式为 HH:mm;当包含秒时,格式为HH:mm:ss,

-

该取值表示选择器弹窗界面的默认选择值。

-

value

-

string

-

-

-

-

设置时间选择器的值。

-

hours

-

number

-

241-4

-

-5+

-

-

设置时间选择器采用的时间格式,可选值:

-
  • 12:按照12小时制显示,用上午和下午进行区分;
  • 24:按照24小时制显示。
    说明:

    默认值会依据系统当前所选地区和语言选择当地习惯的小时制(12小时制或24小时制)。5+

    -
    -
-
- -### 日期时间选择器 - -滑动选择器类型设置为datetime时表示日期时间选择器,日期的选择范围为本年的日月。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

selected

-

string

-

当前日期时间

-

-

设置日期时间选择器弹窗的默认取值,有两种可选格式。

-
  • 月日时分:MM-DD-HH-mm
  • 年月日时分:YYYY-MM-DD-HH-mm
-

不设置年时,默认使用当前年,该取值表示选择器弹窗界面的默认选择值。

-

value

-

string

-

-

-

-

设置日期时间选择器的值。

-

hours

-

number

-

241-4

-

-5+

-

-

设置日期时间选择器采用的时间格式,可选值:

-
  • 12:按照12小时制显示,用上午和下午进行区分;
  • 24:按照24小时制显示。
    说明:

    默认值会依据系统当前所选地区和语言选择当地习惯的小时制(12小时制或24小时制)。5+

    -
    -
-

lunar5+

-

boolean

-

false

-

-

设置日期时间选择器弹窗界面是否为农历展示。

-

lunarswitch

-

boolean

-

false

-

-

设置日期选择器是否显示农历开关。当值为true时,显示农历开关,点击农历开关可切换公历和农历。当值为false时,不显示农历开关。

-
说明:

仅手机和平板设备支持。 当lunarswitch=true且lunar=true时,开关按钮处于被选中状态。

-
-
- -### 多列文本选择器 - -滑动选择器类型设置为multi-text时表示多列文本选择器。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

columns

-

number

-

-

-

-

设置多列文本选择器的列数。

-

range

-

二维Array

-

-

-

-

设置多列文本选择器的选择项,其中range 为二维数组。长度表示多少列,数组的每项表示每列的数据,如 [["a","b"], ["c","d"]]。

-
说明:

使用时需要使用数据绑定的方式,如range = {{data}},js中声明相应变量:data:[["a","b"], ["c","d"]]。

-
-

selected

-

Array

-

[0,0,0,…]

-

-

设置多列文本选择器弹窗的默认值,每一列被选中项对应的索引构成的数组,该取值表示选择器弹窗界面的默认选择值。

-

value

-

Array

-

-

-

-

设置多列文本选择器的值,每一列被选中项对应的值构成的数组。

-
- -## 样式 - -除支持[通用样式](/pages/010c0201010102)外,还支持如下样式: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

text-color

-

<color>

-

-

-

-

选择器的文本颜色。

-

font-size

-

<length>

-

-

-

-

选择器的文本尺寸。

-

allow-scale

-

boolean

-

true

-

-

选择器的文本尺寸是否跟随系统设置字体缩放尺寸进行放大缩小。

-
说明:

如果在config描述文件中针对ability配置了fontSize的config-changes标签,则应用不会重启而直接生效。

-
-

letter-spacing

-

<length>

-

0

-

-

选择器的字符间距。见text组件的letter-spacing样式属性

-

text-decoration

-

string

-

-

-

-

选择器的文本修饰。见text组件的text-decoration样式属性

-

font-style

-

string

-

normal

-

-

选择器的字体样式。见text组件的font-style样式属性

-

font-weight

-

number | string

-

normal

-

-

选择器的字体粗细。见text组件的font-weight样式属性

-

font-family

-

string

-

sans-serif

-

-

选择器的字体列表,用逗号分隔,每个字体用字体名或者字体族名设置。列表中第一个系统中存在的或者通过自定义字体指定的字体,会被选中作为文本的字体。

-

line-height

-

<length>

-

0px

-

-

选择器的文本行高。

-

column-height5+

-

<length>

-

-

-

-

选择器的选择项列表高度。

-
说明:

仅手机和平板设备支持。

-
-
- -## 事件 - -除支持[通用事件](/pages/010c0201010103)外,还支持如下事件: - -### 普通选择器 - - - - - - - - - - - - - - - -

名称

-

参数

-

描述

-

change

-

{ newValue: newValue, newSelected: newSelected }

-

普通选择器选择值后点击弹窗中的确定按钮时触发该事件(newSelected为索引)。

-

cancel

-

-

-

用户点击弹窗中的取消按钮时触发该事件。

-
- -### 日期选择器 - - - - - - - - - - - - - - - -

名称

-

参数

-

描述

-

change

-

{ year: year, month: month, day: day }

-

日期选择器选择值后点击弹窗中的确认按钮时触发该事件。

-
说明:

month值范围为: 0(1月)~11(12月)。5+

-
-

cancel

-

-

-

用户点击弹窗中的取消按钮时触发该事件。

-
- -### 日期时间选择器 - - - - - - - - - - - - - - - -

名称

-

参数

-

描述

-

change

-

{ year: year, month: month, day: day, hour: hour, minute: minute}

-

日期时间选择器选择值后点击弹窗中的确认按钮时触发该事件。

-

cancel

-

-

-

用户点击弹窗中的取消按钮时触发该事件。

-
- -### 时间选择器 - - - - - - - - - - - - - - - -

名称

-

参数

-

描述

-

change

-

{ hour: hour, minute: minute, [second: second] }

-

时间选择器选择值后点击弹窗中的确认按钮时触发该事件,当使用时分秒时,还包含秒数据。

-

cancel

-

-

-

用户点击弹窗中的取消按钮时触发该事件。

-
- -### 多列文本选择器 - - - - - - - - - - - - - - - - - - - -

名称

-

参数

-

描述

-

change

-

{ newValue: [newValue1, newValue2, newValue3, …], newSelected:[newSelected1, newSelected2, newSelected3, …] }

-

多列文本选择器选择值后点击弹窗中的确认按钮时触发该事件,其中:

-
  • newValue:被选中项对应的值构成的数组。
  • newSelected:被选中项对应的索引构成的数组,两者的长度和range的长度一致。
-

columnchange

-

{ column: column, newValue: newValue, newSelected: newSelected }

-

多列文本选择器中某一列的值改变时触发该事件,其中:

-
  • column:第几列修改。
  • newValue:选中的值。
  • newSelected:选中值对应的索引。
-

cancel

-

-

-

用户点击弹窗中的取消按钮时触发该事件。

-
- -## 方法 - -除支持[通用方法](/pages/010c0201010104)外,支持如下方法: - - - - - - - - - - - -

名称

-

参数

-

描述

-

show

-

-

-

显示 picker。

-
- -## 示例 - -``` - -
- - - - - - - - - - -
-``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - justify-content: center; - align-items: center; -} - picker{ - width:60%; - height:80px; - border-radius:20px; - text-color:white; - font-size:15px; - background-color:#4747e3; - margin-left:20%; -} - select{ - background-color: #efecec; - height: 50px; - width: 60%; - margin-left: 20%; - margin-top: 300px; - margin-bottom: 50px; - font-size: 22px; -} -``` - -``` -// xxx.js -import router from '@system.router'; -import prompt from '@system.prompt'; -export default { - data: { - selectList:["text","data","time","datetime","multitext"], - rangetext:['15', "20", "25"], - multitext:[["a", "b", "c"], ["e", "f", "g"], ["h", "i"], ["k", "l", "m"]], - textvalue:'default textvalue', - datevalue:'default datevalue', - timevalue:'default timevalue', - datetimevalue:'default datetimevalue', - multitextvalue:'default multitextvalue', - containsecond:true, - multitextselect:[1,2,0], - datetimeselect:'2012-5-6-11-25', - timeselect:'11:22:30', - dateselect:'2021-3-2', - textselect:'2' - }, - selectChange(e){ - for(let i = 0;i - -嵌入页面的滑动选择器。 - -## 子组件 - -不支持。 - -## 属性 - -除支持[通用属性](/pages/010c0201010101)外,还支持如下属性: - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

type

-

string

-

text

-

-

设置滑动选择器的类型,该属性不支持动态修改,可选项有:

-
  • text:文本选择器。
  • time:时间选择器。
  • date:日期选择器。
  • datetime:日期时间选择器。
  • multi-text:多列文本选择器。
-
- -文本选择器:type=text - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

range

-

Array

-

-

-

-

设置文本选择器的取值范围。

-
说明:

使用时需要使用数据绑定的方式,如range = {{data}},js中声明相应变量:data:["15", "20", "25"]。

-
-

selected

-

string

-

0

-

-

设置文本选择器的默认选择值,该值需要为range的索引。

-

indicatorprefix

-

string

-

-

-

-

文本选择器选定值增加的前缀字段。

-

indicatorsuffix

-

string

-

-

-

-

文本选择器选定值增加的后缀字段。

-
- -时间选择器:type=time - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

containsecond

-

boolean

-

false

-

-

时间选择器是否包含秒。

-

selected

-

string

-

当前时间

-

-

设置时间选择器的默认取值,格式为 HH:mm;

-

当包含秒时,格式为HH:mm:ss。

-

hours

-

number

-

241-4

-

-5+

-

-

设置时间选择器采用的时间格式,可选值:

-
  • 12:按照12小时制显示,用上午和下午进行区分;
  • 24:按照24小时制显示。
    说明:

    默认值会依据系统当前所选地区和语言选择当地习惯的小时制(12小时制或24小时制)。5+

    -
    -
-
- -日期选择器:type=date - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

start

-

<time>

-

1970-1-1

-

-

设置日期选择器的起始时间,格式为 YYYY-MM-DD。

-

end

-

<time>

-

2100-12-31

-

-

设置日期选择器的结束时间,格式为 YYYY-MM-DD。

-

selected

-

string

-

当前日期

-

-

设置日期选择器的默认选择值,格式为 YYYY-MM-DD。

-

lunar5+

-

boolean

-

false

-

-

设置日期选择器弹窗界面是否为农历展示。

-

lunarswitch

-

boolean

-

false

-

-

设置日期选择器是否显示农历开关,显示农历开关时,可以在弹窗界面展现农历的开关由于公历和农历切换。在设置显示农历时,开关状态为开,当设置不显示农历时,开关状态为关。手机生效。

-
说明:

仅手机和平板设备支持。

-
-
- -日期时间选择器:type=datetime,日期的选择范围为本年的日月。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

selected

-

string

-

当前日期时间

-

-

设置日期时间选择器的默认取值,格式有两种,为月日时分MM-DD-HH-mm或者年月日时分YYYY-MM-DD-HH-mm,不设置年时,默认使用当前年,该取值表示选择器弹窗时弹窗界面的默认选择值。

-

hours

-

number

-

241-4

-

-5+

-

-

设置日期时间选择器采用的时间格式,可选值:

-
  • 12:按照12小时制显示,用上午和下午进行区分;
  • 24:按照24小时制显示。
    说明:

    默认值会依据系统当前所选地区和语言选择当地习惯的小时制(12小时制或24小时制)。5+

    -
    -
-

lunar5+

-

boolean

-

false

-

-

设置日期时间选择器弹窗界面是否为农历展示。

-

lunarswitch

-

boolean

-

false

-

-

设置日期时间选择器是否显示农历开关,显示农历开关时,可以在弹窗界面展现农历的开关由于公历和农历切换。在设置显示农历时,开关状态为开,当设置不显示农历时,开关状态为关。手机生效。

-
说明:

仅手机和平板设备支持。

-
-
- -多列文本选择器:type=multi-text - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

columns

-

number

-

-

-

-

设置多列文本选择器的列数。

-

range

-

二维Array

-

-

-

-

设置多列文本选择器的选择值,该值为二维数组。长度表示多少列,数组的每项表示每列的数据,如 [["a","b"], ["c","d"]]。

-
说明:

使用时需要使用数据绑定的方式,如range = {{data}},js中声明相应变量:data:[["a","b"], ["c","d"]]。

-
-

selected

-

Array

-

[0,0,0,…]

-

-

设置多列文本选择器的默认值,每一列被选中项对应的索引构成的数组,该取值表示选择器弹窗时弹窗界面的默认选择值。

-
- -## 样式 - -除支持[通用样式](/pages/010c0201010102)外,还支持如下样式: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

color

-

<color>

-

#ffffff

-

-

候选项字体颜色。

-

font-size

-

<length>

-

16px

-

-

候选项字体尺寸,类型length,单位px。

-

selected-color

-

<color>

-

#ff0a69f7

-

-

选中项字体颜色。

-

selected-font-size

-

<length>

-

20px

-

-

选中项字体尺寸,类型length,单位px。

-

disappear-color5+

-

<color>

-

#ffffff

-

-

渐变消失项的字体颜色。消失项是在一列中有五个选项场景下最上和最下的两个选项。

-
说明:

仅手机和平板设备支持。

-
-

disappear-font-size5+

-

<length>

-

14px

-

-

渐变消失项的字体尺寸。消失项是在一列中有五个选项场景下最上和最下的两个选项。

-
说明:

仅手机和平板设备支持。

-
-

font-family

-

string

-

sans-serif

-

-

选项字体类型。字体列表,用逗号分隔,每个字体用字体名或者字体族名设置。列表中第一个系统中存在的或者通过自定义字体指定的字体,会被选中作为文本的字体。

-
- -## 事件 - -仅支持如下事件: - -type=text: - - - - - - - - - - - -

名称

-

参数

-

描述

-

change

-

{ newValue: newValue, newSelected: newSelected }

-

文本选择器选定值后触发该事件。

-
- -type=time: - - - - - - - - - - - -

名称

-

参数

-

描述

-

change

-

{ hour: hour, minute: minute, [second:second] }

-

时间选择器选定值后触发该事件。

-

包含秒时,返回时分秒。

-
- -type=date: - - - - - - - - - - - -

名称

-

参数

-

描述

-

change

-

{ year:year, month:month, day:day }

-

日期选择器选择值后触发该事件。

-
- -type=datetime: - - - - - - - - - - - -

名称

-

参数

-

描述

-

change

-

{ year:year, month:month, day:day, hour:hour, minute:minute }

-

日期时间选择器选择值后触发该事件。

-
- -type=multi-text: - - - - - - - - - - - -

名称

-

参数

-

描述

-

columnchange

-

{ column:column, newValue:newValue, newSelected:newSelected }

-

多列文本选择器某一列的值改变时触发该事件,column:第几列修改,newValue:选中的值,newSelected:选中值对应的索引。

-
- -## 方法 - -不支持。 - -## 示例 - -``` - -
- - Selected:{{time}} - - -
-``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - justify-content: center; - align-items: center; - left: 0px; - top: 0px; - width: 454px; - height: 454px; -} -.title { - font-size: 30px; - text-align: center; -} -.time-picker { - width: 500px; - height: 400px; - margin-top: 20px; -} -``` - -``` -/* xxx.js */ -export default { - data: { - defaultTime: "", - time: "", - }, - onInit() { - this.defaultTime = this.now(); - }, - handleChange(data) { - this.time = this.concat(data.hour, data.minute); - }, - now() { - const date = new Date(); - const hours = date.getHours(); - const minutes = date.getMinutes(); - return this.concat(hours, minutes); - }, - - fill(value) { - return (value > 9 ? "" : "0") + value; - }, - - concat(hours, minutes) { - return `${this.fill(hours)}:${this.fill(minutes)}`; - }, -} -``` - -![](/images/application-dev/reference/arkui-js/figures/sssssss.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/13.piece.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/13.piece.md" deleted file mode 100644 index c1203b50b64ed18651239e23a822a006b570ac39..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/13.piece.md" +++ /dev/null @@ -1,141 +0,0 @@ ---- -title: piece -permalink: /pages/010c020101030d -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:30 ---- -# piece - -一种块状的入口,可包含图片和文本。常用于展示收件人,例如:邮件收件人或信息收件人。 - -## 子组件 - -无 - -## 属性 - -除支持[通用属性](/pages/010c0201010101)外,还支持如下属性: - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

content

-

string

-

-

-

-

操作块文本内容。

-

closable

-

boolean

-

false

-

-

设置当前操作块是否显示删除图标,当显示删除图标时,点击删除图标会触发close事件。

-

icon

-

string

-

-

-

-

操作块删除图标的url,支持本地。

-
- -## 样式 - -支持[通用样式](/pages/010c0201010102)。 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->文本和图片默认在整个piece组件中居中。 - -## 事件 - -除支持[通用事件](/pages/010c0201010103)外,还支持如下事件: - - - - - - - - - - - -

名称

-

参数

-

描述

-

close

-

-

-

当piece组件点击删除图标触发,此时可以通过渲染属性if删除该组件。

-
- -## 方法 - -支持[通用方法](/pages/010c0201010104)。 - -## 示例 - -``` - -
- - -
-``` - -``` -/* xxx.css */ -.container { - width: 100%; - height: 100%; - align-items: center; - justify-content: center; -} -``` - -``` -// xxx.js -export default { - data: { - first: true, - second: true - }, - closeSecond(e) { - this.second = false; - } -} -``` - -![](/images/application-dev/reference/arkui-js/figures/11-1.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/14.progress.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/14.progress.md" deleted file mode 100644 index 3063e2be595a1de54717b2f0e52805be922ab068..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/14.progress.md" +++ /dev/null @@ -1,517 +0,0 @@ ---- -title: progress -permalink: /pages/010c020101030e -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:31 ---- -# progress - -进度条,用于显示内容加载或操作处理进度。 - -## 权限列表 - -无 - -## 子组件 - -不支持。 - -## 属性 - -除支持[通用属性](/pages/010c0201010101)外,还支持如下属性: - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

type

-

string

-

horizontal

-

-

设置进度条的类型,该属性不支持动态修改,可选值为:

-
  • horizontal:线性进度条;
  • circular:loading样式进度条;
  • ring:圆环形进度条;
  • scale-ring:带刻度圆环形进度条
  • arc:弧形进度条。
  • eclipse5+:圆形进度条,展现类似月圆月缺的进度展示效果。
-
- -不同类型的进度条还支持不同的属性: - -- 类型为horizontal、ring、scale-ring时,支持如下属性: - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

percent

-

number

-

0

-

-

当前进度。取值范围为0-100。

-

secondarypercent

-

number

-

0

-

-

次级进度。取值范围为0-100。

-
- -- 类型为ring、scale-ring时,支持如下属性: - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

clockwise

-

boolean

-

true

-

-

圆环形进度条是否采用顺时针。

-
- -- 类型为arc、eclipse5+时,支持如下属性: - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

percent

-

number

-

0

-

-

当前进度。取值范围为0-100。

-
- - -## 样式 - -除支持[通用样式](/pages/010c0201010102)外,还支持如下样式: - -type=horizontal - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

color

-

<color>

-

#ff007dff

-

-

设置进度条的颜色。

-

stroke-width

-

<length>

-

4px

-

-

-

设置进度条的宽度。

-

background-color

-

<color>

-

-

-

-

设置进度条的背景色。

-

secondary-color

-

<color>

-

-

-

-

设置次级进度条的颜色。

-
- -type=circular - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

color

-

<color>

-

-

-

-

loading进度条上的圆点颜色。

-
- -type=ring, scale-ring - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

color

-

<color> | <linear-gradient>

-

-

-

-

环形进度条的颜色,ring类型支持线性渐变色设置。

-
说明:

线性渐变色仅支持两个颜色参数设置格式,如color = linear-gradient(#ff0000, #00ff00)。

-
-

background-color

-

<color>

-

-

-

-

环形进度条的背景色。

-

secondary-color

-

<color>

-

-

-

-

环形次级进度条的颜色。

-

stroke-width

-

<length>

-

10px

-

-

环形进度条的宽度。

-

scale-width

-

<length>

-

-

-

-

带刻度的环形进度条的刻度粗细,类型为scale-ring生效。

-

scale-number

-

number

-

120

-

-

带刻度的环形进度条的刻度数量,类型为scale-ring生效。

-
- -type=arc - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

color

-

<color>

-

-

-

-

-

弧形进度条的颜色。

-

background-color

-

<color>

-

-

-

-

-

弧形进度条的背景色。

-

stroke-width

-

<length>

-

4px

-

-

弧形进度条的宽度。

-
说明:

进度条宽度越大,进度条越靠近圆心,进度条始终在半径区域内。

-
-

start-angle

-

<deg>

-

240

-

-

弧形进度条起始角度,以时钟0点为基线,取值范围为0到360(顺时针)。

-

total-angle

-

<deg>

-

240

-

-

弧形进度条总长度,范围为-360到360,负数标识起点到终点为逆时针。

-

center-x

-

<length>

-

弧形进度条宽度的一半

-

-

弧形进度条中心位置,(坐标原点为组件左上角顶点)。该样式需要和center-y和radius一起使用。

-

center-y

-

<length>

-

弧形进度条高度的一半

-

-

弧形进度条中心位置,(坐标原点为组件左上角顶点)。该样式需要和center-x和radius一起使用。

-

radius

-

<length>

-

弧形进度条宽高最小值的一半

-

-

弧形进度条半径,该样式需要和center-x和center-y一起使用。

-
- -type=eclipse5+ - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

color

-

<color>

-

-

-

-

圆形进度条的颜色。

-

background-color

-

<color>

-

-

-

-

弧形进度条的背景色。

-
- -## 事件 - -支持[通用事件](/pages/010c0201010103)。 - -## 方法 - -支持[通用方法](/pages/010c0201010104)。 - -## 示例 - -``` - -
- - - - -
-``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - height: 100%; - width: 100%; - align-items: center; -} -.min-progress { - width: 300px; - height: 300px; -} -``` - -![](/images/application-dev/reference/arkui-js/figures/progress.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/15.qrcode.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/15.qrcode.md" deleted file mode 100644 index b4a46d1960d5900c7d395a17e8878a1f4bca93ab..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/15.qrcode.md" +++ /dev/null @@ -1,191 +0,0 @@ ---- -title: qrcode -permalink: /pages/010c020101030f -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:31 ---- -# qrcode - -生成并显示二维码。 - -## 权限列表 - -无 - -## 子组件 - -不支持。 - -## 属性 - -除支持[通用属性](/pages/010c0201010101)外,还支持如下属性: - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

value

-

string

-

-

-

-

用来生成二维码的内容。

-

type

-

string

-

rect

-

-

二维码类型。可能选项有:

-
  • rect:矩形二维码。
  • circle:圆形二维码。
-
- -## 样式 - -除支持[通用样式](/pages/010c0201010102)外,还支持如下样式: - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

color

-

<color>

-

#000000

-

-

二维码颜色。

-

background-color

-

<color>

-

#ffffff

-

-

二维码背景颜色。

-
- ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->- width和height不一致时,取二者较小值作为二维码的边长。且最终生成的二维码居中显示。 ->- width和height只设置一个时,取设置的值作为二维码的边长。都不设置时,使用200px作为默认边长。 - -## 事件 - -支持[通用事件](/pages/010c0201010103)。 - -## 方法 - -支持[通用方法](/pages/010c0201010104)。 - -## 示例 - -``` - -
- - Type - - Color - - Background Color - -
-``` - -``` -/* xxx.css */ -.container { - width: 100%; - height: 100%; - flex-direction: column; - justify-content: center; - align-items: center; -} -.txt { - margin: 30px; - color: orangered; -} -select{ - margin-top: 40px; - margin-bottom: 40px; -} -``` - -``` -/* index.js */ -export default { - data: { - qr_type: 'rect', - qr_size: '300px', - qr_col: '#87ceeb', - col_list: ['#87ceeb','#fa8072','#da70d6','#80ff00ff','#00ff00ff'], - qr_bcol: '#f0ffff', - bcol_list: ['#f0ffff','#ffffe0','#d8bfd8'] - }, - settype(e) { - if (e.checked) { - this.qr_type = 'rect' - } else { - this.qr_type = 'circle' - } - }, - setvalue(e) { - this.qr_value = e.newValue - }, - setcol(e) { - this.qr_col = e.newValue - }, - setbcol(e) { - this.qr_bcol = e.newValue - } -} -``` - -![](/images/application-dev/reference/arkui-js/figures/12.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/16.rating.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/16.rating.md" deleted file mode 100644 index b0a45d5fa86f10e4055ec68df912bfacb15145e5..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/16.rating.md" +++ /dev/null @@ -1,242 +0,0 @@ ---- -title: rating -permalink: /pages/010c0201010310 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:31 ---- -# rating - -评分条,表示用户使用感受的衡量标准条。 - -## 权限列表 - -无 - -## 子组件 - -不支持。 - -## 属性 - -除支持[通用属性](/pages/010c0201010101)外,还支持如下属性: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

numstars

-

number

-

5

-

-

设置评分条的星级总数。

-

rating

-

number

-

0

-

-

设置评分条当前评星数。

-

stepsize

-

number

-

0.5

-

-

设置评分条的评星步长。

-
说明:

仅手机和平板设备支持

-
-

indicator

-

boolean

-

false

-

-

设置评分条是否作为一个指示器,此时用户不可操作。

-
- -## 样式 - -除支持[通用样式](/pages/010c0201010102)外,还支持如下样式: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

star-background

-

string

-

-

-

-

设置单个星级未选中的背景图片,只支持本地路径图片,图片格式为png和jpg。

-

star-foreground

-

string

-

-

-

-

设置单个星级选中的前景图片,只支持本地路径图片,图片格式为png和jpg。

-

star-secondary

-

string

-

-

-

-

设置单个星级部分选中的次级背景图片,该图片会覆盖背景图片,只支持本地路径图片,图片格式为png和jpg。

-

width

-

<length>|<percentage>

-

120px

-

60px(不可操作)

-

-

默认值是在未设置自定义资源和评分星数时,使用5个星和默认资源下的宽度值。

-

height

-

<length>|<percentage>

-

24px

-

12px(不可操作)

-

-

默认值是在未设置自定义资源和评分星数时,使用5个星和默认资源下的高度值。

-

rtl-flip

-

boolean

-

true

-

-

在RTL文字方向下是否自动翻转图源。

-
- ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->star-background,star-secondary,star-foreground三个星级图源必须全部设置,否则默认的星级颜色为灰色,以此提示图源设置错误。 - -## 事件 - -除支持[通用事件](/pages/010c0201010103)外,还支持如下事件: - - - - - - - - - - - -

名称

-

参数

-

描述

-

change

-

{ rating: number }

-

评分条的评星发生改变时触发该回调。

-
- -## 方法 - -支持[通用方法](/pages/010c0201010104)。 - -## 示例 - -``` - -
- - -
-``` - -``` -/* xxx.css */ -.container { - display: flex; - justify-content: center; - align-items: center; -} -rating { - width: 200px; -} -``` - -``` -// xxx.js -import prompt from '@system.prompt'; -export default { - changeRating(e){ - prompt.showToast({ - message: e.rating - }); - } -} -``` - -![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001198670487.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/17.richtext.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/17.richtext.md" deleted file mode 100644 index 9fa758de2de09da42d3aac15b30036416caf8136..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/17.richtext.md" +++ /dev/null @@ -1,104 +0,0 @@ ---- -title: richtext -permalink: /pages/010c0201010311 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:31 ---- -# richtext - -富文本组件,用于展示富文本信息。 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->- 富文本内容需要写在元素标签内。 - -## 权限列表 - -无 - -## 属性 - -仅支持[通用属性](/pages/010c0201010101)中的id、style和class属性。 - -## 样式 - -仅支持[通用样式](/pages/010c0201010102)中的display和visibility样式。 - -## 事件 - -除支持[通用事件](/pages/010c0201010103)外,还支持如下事件: - - - - - - - - - - - - - - - -

名称

-

参数

-

描述

-

start

-

-

-

开始加载时触发。

-

complete

-

-

-

加载完成时触发。

-
- ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->- 不支持focus、blur、key事件。 ->- 不支持无障碍事件。 ->- 包含richtext的页面返回时richtext显示区域不会跟随页面的转场动效。 ->- richtext内容不建议超过一个屏幕高度,超出部分不会显示。 ->- 不支持设置宽度,默认撑开全屏。 - -## 方法 - -不支持。 - -## 示例 - -``` - -
- {{content}} -
-``` - -``` -// xxx.js -export default { - data: { - content: ` -
- -

h1

-

文本测试(h1测试)

-

h2

-

文本测试(h2测试)

-
- `, - }, - onLoadStart() { - console.error("start load rich text:" + JSON.stringify()) - }, - onLoadEnd() { - console.error("end load rich text:" + JSON.stringify()) - } -} -``` - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/18.search.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/18.search.md" deleted file mode 100644 index f8464d0b07e7b04a7ba8552dca945038fa93041f..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/18.search.md" +++ /dev/null @@ -1,305 +0,0 @@ ---- -title: search -permalink: /pages/010c0201010312 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:31 ---- -# search - -提供搜索框组件,用于提供用户搜索内容的输入区域。 - -## 子组件 - -不支持。 - -## 属性 - -除支持[通用属性](/pages/010c0201010101)外,还支持如下属性: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

icon

-

string

-

-

-

-

搜索图标,默认使用系统搜索图标,图标格式为svg,jpg和png。

-

hint

-

string

-

-

-

-

搜索提示文字。

-

value

-

string

-

-

-

-

搜索框搜索文本值。

-

searchbutton5+

-

string

-

-

-

-

搜索框末尾搜索按钮文本值。

-

menuoptions5+

-

Array<MenuOption>

-

-

-

-

设置文本选择弹框点击更多按钮之后显示的菜单项。

-
- -**表 1** MenuOption5+ - - - - - - - - - - - - - - - - -

名称

-

类型

-

描述

-

icon

-

string

-

菜单选项中的图标路径。

-

content

-

string

-

菜单选项中的文本内容。

-
- -## 样式 - -除支持[通用样式](/pages/010c0201010102)外,还支持如下样式: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

color

-

<color>

-

#e6000000

-

-

搜索框的文本颜色。

-

font-size

-

<length>

-

16px

-

-

搜索框的文本尺寸。

-

allow-scale

-

boolean

-

true

-

-

搜索框的文本尺寸是否跟随系统设置字体缩放尺寸进行放大缩小。

-
说明:

如果在config描述文件中针对ability配置了fontSize的config-changes标签,则应用不会重启而直接生效。

-
-

placeholder-color

-

<color>

-

#99000000

-

-

搜索框的提示文本颜色。

-

font-weight

-

number | string

-

normal

-

-

搜索框的字体粗细,见text组件font-weight的样式属性

-

font-family

-

string

-

sans-serif

-

-

搜索框的字体列表,用逗号分隔,每个字体用字体名或者字体族名设置。列表中第一个系统中存在的或者通过自定义字体指定的字体,会被选中作为文本的字体。

-

caret-color6+

-

<color>

-

-

-

-

设置输入光标的颜色。

-
- -## 事件 - -除支持[通用事件](/pages/010c0201010103)外,还支持如下事件: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数

-

描述

-

change

-

{ text:newText }

-

输入内容发生变化时触发。

-
说明:

改变value属性值不会触发该回调。

-
-

submit

-

{ text:submitText }

-

点击搜索图标、搜索按钮5+或者按下软键盘搜索按钮时触发。

-

translate5+

-

{ value: selectedText }

-

设置此事件后,进行文本选择操作后文本选择弹窗会出现翻译按钮,点击翻译按钮之后,触发该回调,返回选中的文本内容。

-

share5+

-

{ value: selectedText }

-

设置此事件后,进行文本选择操作后文本选择弹窗会出现分享按钮,点击分享按钮之后,触发该回调,返回选中的文本内容。

-

search5+

-

{ value: selectedText }

-

设置此事件后,进行文本选择操作后文本选择弹窗会出现搜索按钮,点击搜索按钮之后,触发该回调,返回选中的文本内容。

-

optionselect5+

-

{ index:optionIndex, value: selectedText }

-

文本选择弹窗中设置menuoptions属性后,用户在文本选择操作后,点击菜单项后触发该回调,返回点击的菜单项序号和选中的文本内容。

-
- -## 方法 - -支持[通用方法](/pages/010c0201010104)。 - -## 示例 - -``` - -
- - -
-``` - -``` -/* xxx.css */ -.container { - display: flex; - justify-content: center; - align-items: center; -} -``` - -![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001153427082.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/19.select.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/19.select.md" deleted file mode 100644 index 0275424e01e1855f7ceff646f9c67f093f6c1e51..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/19.select.md" +++ /dev/null @@ -1,118 +0,0 @@ ---- -title: select -permalink: /pages/010c0201010313 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:31 ---- -# select - -下拉选择按钮,可让用户在多个选项之间选择。 - -## 权限列表 - -无 - -## 子组件 - -支持<[option](/pages/010c020101030a)\>。 - -## 属性 - -支持[通用属性](/pages/010c0201010101)。 - -## 样式 - -除支持[通用样式](/pages/010c0201010102)外,还支持如下样式: - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

font-family

-

string

-

sans-serif

-

-

字体列表,用逗号分隔,每个字体用字体名或者字体族名设置。列表中第一个系统中存在的或者通过自定义字体指定的字体,会被选中作为文本的字体。

-
- -## 事件 - -除支持[通用事件](/pages/010c0201010103)外,还支持如下事件: - - - - - - - - - - - -

名称

-

参数

-

描述

-

change

-

{newValue: newValue}

-

下拉选择新值后触发该事件,newValue的值为子组件option的value属性值。

-
- ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->- select组件不支持click事件。 - -## 方法 - -支持[通用方法](/pages/010c0201010104)。 - -## 示例 - -``` - -
- -
-``` - -``` -/* xxx.css */ -.container { - display: flex; - justify-content: center; - align-items: center; -} -``` - -![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001152588538.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/20.slider.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/20.slider.md" deleted file mode 100644 index f15a0fac0cb82b5ae94f14432dd6ee9876017b7d..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/20.slider.md" +++ /dev/null @@ -1,293 +0,0 @@ ---- -title: slider -permalink: /pages/010c0201010314 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:31 ---- -# slider - -滑动条组件,用来快速调节设置值,如音量、亮度等。 - -## 子组件 - -不支持。 - -## 属性 - -除支持[通用属性](/pages/010c0201010101)外,还支持如下属性: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

min

-

number

-

0

-

-

滑动选择器的最小值。

-

max

-

number

-

100

-

-

滑动选择器的最大值。

-

step

-

number

-

1

-

-

每次滑动的步长。

-

value

-

number

-

0

-

-

滑动选择器的初始值。

-

mode5+

-

string

-

outset

-

-

滑动条样式:

-
  • outset:滑块在滑杆上;
  • inset:滑块在滑杆内。
    说明:

    仅手机和平板设备支持。

    -
    -
-

showsteps5+

-

boolean

-

false

-

-

是否显示步长标识;

-
说明:

仅手机和平板设备支持。

-
-

showtips5+

-

boolean

-

false

-

-

滑动时是否有气泡提示百分比;

-
说明:

仅手机和平板设备支持。

-
-
- -## 样式 - -除支持[通用样式](/pages/010c0201010102)外,还支持如下样式: - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

color

-

<color>

-

#19000000

-

-

滑动条的背景颜色。

-

selected-color

-

<color>

-

#ff007dff

-

-

滑动条的已选择颜色。

-

block-color

-

<color>

-

#ffffff

-

-

滑动条的滑块颜色。

-
说明:

仅手机、平板和智慧屏设备支持。

-
-
- -## 事件 - -除支持[通用事件](/pages/010c0201010103)外,还支持如下事件: - - - - - - - - - - - -

名称

-

参数

-

描述

-

change

-

ChangeEvent

-

选择值发生变化时触发该事件。

-
- -**表 1** ChangeEvent - - - - - - - - - - - - - - - - - - - - - - - - -

属性

-

类型

-

说明

-

progress(deprecated5+)

-

string

-

当前slider的进度值。

-

isEnd(deprecated5+)

-

string

-

当前slider是否拖拽结束,可选值为:

-
  • true:slider拖拽结束。
  • false:slider拖拽中。
-

value5+

-

number

-

当前slider的进度值。

-

mode5+

-

string

-

当前change事件的类型,可选值为:

-
  • start:slider的值开始改变。
  • move:slider的值跟随手指拖动中。
  • end:slider的值结束改变。
-
- -## 示例 - -``` - -
- slider start value is {{startValue}} - slider current value is {{currentValue}} - slider end value is {{endValue}} - -
-``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - justify-content: center; - align-items: center; - - -} -``` - -``` -// xxx.js -export default { - data: { - value: 0, - startValue: 0, - currentValue: 0, - endValue: 0, - }, - setvalue(e) { - if (e.mode == "start") { - this.value = e.value; - this.startValue = e.value; - } else if (e.mode == "move") { - this.value = e.value; - this.currentValue = e.value; - } else if (e.mode == "end") { - this.value = e.value; - this.endValue = e.value; - } - } -} -``` - -![](/images/application-dev/reference/arkui-js/figures/slider.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/21.span.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/21.span.md" deleted file mode 100644 index 124e14527a8177907e54f279779221257d8313bc..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/21.span.md" +++ /dev/null @@ -1,170 +0,0 @@ ---- -title: span -permalink: /pages/010c0201010315 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:31 ---- -# span - -作为<[text](/pages/010c0201010317)\>子组件提供文本修饰能力。 - -## 权限列表 - -无 - -## 子组件 - -支持子组件。 - -## 属性 - -支持[通用属性](/pages/010c0201010101)。 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->不支持focusable和disabled属性。 - -## 样式 - -仅支持如下样式: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

color

-

<color>

-

-

-

-

设置文本段落的文本颜色。

-

font-size

-

<length>

-

30px

-

-

设置文本段落的文本尺寸。

-

allow-scale

-

boolean

-

true

-

-

设置文本段落的文本尺寸是否跟随系统设置字体缩放尺寸进行放大缩小。

-
说明:

如果在config描述文件中针对ability配置了fontSize的config-changes标签,则应用不会重启而直接生效。

-
-

font-style

-

string

-

normal

-

-

设置文本段落的字体样式,见text组件font-style的样式属性

-

font-weight

-

number | string

-

normal

-

-

设置文本段落的字体粗细,见text组件font-weight的样式属性

-

text-decoration

-

string

-

none

-

-

设置文本段落的文本修饰,见text组件text-decoration样式属性

-

font-family

-

string

-

sans-serif

-

-

设置文本段落的字体列表,用逗号分隔,每个字体用字体名或者字体族名设置。列表中第一个系统中存在的或者通过自定义字体指定的字体,会被选中作为文本的字体。

-
- -## 事件 - -仅支持[通用事件](/pages/010c0201010103)中的click事件。 - -## 方法 - -不支持。 - -## 示例 - -``` - -
- - span - -
-``` - -``` -/* xxx.css */ -.container { - display: flex; - justify-content: center; - align-items: center; -} -.title { - font-size: 30px; - text-align: center; - width: 100%; - height: 100px; -} -.spanTxt{ - color: chartreuse; - font-size: 100px; -} -``` - -![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001152588626.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/22.switch.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/22.switch.md" deleted file mode 100644 index eba3e8d7889d9041a171abf603bf181fbb1c661a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/22.switch.md" +++ /dev/null @@ -1,271 +0,0 @@ ---- -title: switch -permalink: /pages/010c0201010316 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:31 ---- -# switch - -开关选择器,通过开关,开启或关闭某个功能。 - -## 权限列表 - -无 - -## 子组件 - -不支持。 - -## 属性 - -除支持[通用属性](/pages/010c0201010101)外,还支持如下属性: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

checked

-

boolean

-

false

-

-

是否选中。

-

showtext

-

boolean

-

false

-

-

是否显示文本。

-

texton

-

string

-

"On"

-

-

选中时显示的文本。

-

textoff

-

string

-

"Off"

-

-

未选中时显示的文本。

-
- -## 样式 - -除支持[通用样式](/pages/010c0201010102)外,还支持如下样式: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

texton-color(Rich)

-

<color>

-

#000000

-

-

选中时显示的文本颜色。

-

textoff-color(Rich)

-

<color>

-

#000000

-

-

未选中时显示的文本颜色。

-

text-padding(Rich)

-

number

-

0px

-

-

texton/textoff中最长文本两侧距离滑块边界的距离。

-

font-size(Rich)

-

<length>

-

-

-

-

文本尺寸,仅设置texton和textoff生效。

-

allow-scale(Rich)

-

boolean

-

true

-

-

文本尺寸是否跟随系统设置字体缩放尺寸进行放大缩小。

-
说明:

如果在config描述文件中针对ability配置了fontSize的config-changes标签,则应用不会重启而直接生效。

-
-

font-style(Rich)

-

string

-

normal

-

-

字体样式,仅设置texton和textoff生效。见text组件font-style的样式属性

-

font-weight(Rich)

-

number | string

-

normal

-

-

字体粗细,仅设置texton和textoff生效。见text组件的font-weight的样式属性

-

font-family(Rich)

-

string

-

sans-serif

-

-

字体列表,用逗号分隔,每个字体用字体名或者字体族名设置。列表中第一个系统中存在的或者通过自定义字体指定的字体,会被选中作为文本的字体。仅设置texton和textoff生效。

-
- -## 事件 - -除支持[通用事件](/pages/010c0201010103)外,还支持如下事件: - - - - - - - - - - - -

名称

-

参数

-

描述

-

change

-

{ checked: checkedValue }

-

选中状态改变时触发该事件。

-
- -## 方法 - -支持[通用方法](/pages/010c0201010104)。 - -## 示例 - -``` - -
- - -
-``` - -``` -/* xxx.css */ -.container { - display: flex; - justify-content: center; - align-items: center; -} -switch{ - texton-color:#002aff; - textoff-color:silver; - text-padding:20px; -} -``` - -``` -// xxx.js -import prompt from '@system.prompt'; -export default { - data: { - title: 'World' - }, - switchChange(e){ - console.log(e.checked); - if(e.checked){ - prompt.showToast({ - message: "打开开关" - }); - }else{ - prompt.showToast({ - message: "关闭开关" - }); - } - } -} -``` - -![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001152862510.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/23.text.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/23.text.md" deleted file mode 100644 index f011337c6150da00c11925068c526cf15ed1fa52..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/23.text.md" +++ /dev/null @@ -1,417 +0,0 @@ ---- -title: text -permalink: /pages/010c0201010317 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:31 ---- -# text - -文本,用于呈现一段信息。 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->- 文本的展示内容需要写在元素标签内。 - -## 权限列表 - -无 - -## 子组件 - -支持<[span](/pages/010c0201010315)\>。 - -## 属性 - -支持[通用属性](/pages/010c0201010101)。 - -## 样式 - -除支持[通用样式](/pages/010c0201010102)外,还支持如下样式: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

color

-

<color>

-

#e5000000

-

-

设置文本的颜色。

-

font-size

-

<length>

-

30px

-

-

设置文本的尺寸。

-

allow-scale

-

boolean

-

true

-

-

文本尺寸是否跟随系统设置字体缩放尺寸进行放大缩小。

-
说明:

如果需要支持动态生效,请参看config描述文件中config-changes标签。

-
-

letter-spacing

-

<length>

-

0px

-

-

设置文本的字符间距。

-

word-spacing7+

-

<length> | <percentage> | string

-

normal

-

-

设置文本之间的间距,string可选值为:

-

normal:默认的字间距。

-

font-style

-

string

-

normal

-

-

设置文本的字体样式,可选值为:

-
  • normal:标准的字体样式;
  • italic:斜体的字体样式。
-

font-weight

-

number | string

-

normal

-

-

设置文本的字体粗细,number类型取值[100, 900],默认为400,取值越大,字体越粗。

-
说明:

number取值必须为100的整数倍。

-
-

string类型取值支持如下四个值:lighter、normal、bold、bolder。

-

text-decoration

-

string

-

none

-

-

设置文本的文本修饰,可选值为:

-
  • underline:文字下划线修饰;
  • line-through:穿过文本的修饰线n
  • none:标准文本。
-

text-decoration-color7+

-

<color>

-

-

-

-

设置文本修饰线的颜色。

-

text-align

-

string

-

start

-

-

设置文本的文本对齐方式,可选值为:

-
  • left:文本左对齐;
  • center:文本居中对齐;
  • right:文本右对齐;
  • start:根据文字书写相同的方向对齐;
  • end:根据文字书写相反的方向对齐。
-
说明:

如文本宽度未指定大小,文本的宽度和父容器的宽度大小相等的情况下,对齐效果可能会不明显。

-
-

line-height

-

<length> | <percentage>7+ | string7+

-

0px1-6

-

normal7+

-

-

设置文本的文本行高,设置为0px时,不限制文本行高,自适应字体大小。string可选值为:

-

normal7+:默认的行高。

-

text-overflow

-

string

-

clip

-

-

在设置了最大行数的情况下生效,可选值为:

-
  • clip:将文本根据父容器大小进行裁剪显示;
  • ellipsis:根据父容器大小显示,显示不下的文本用省略号代替。需配合max-lines使用。
-

font-family

-

string

-

sans-serif

-

-

设置文本的字体列表,用逗号分隔,每个字体用字体名或者字体族名设置。列表中第一个系统中存在的或者通过自定义字体指定的字体,会被选中作为文本的字体。

-

max-lines

-

number | string7+

-

-

-

-

设置文本的最大行数,string类型可选值为:

-
  • auto7+:文本行数自适应容器高度。
-

min-font-size

-

<length>

-

-

-

-

文本最小字号,需要和文本最大字号同时设置,支持文本字号动态变化。设置最大最小字体样式后,font-size不生效。

-

max-font-size

-

<length>

-

-

-

-

文本最大字号,需要和文本最小字号同时设置,支持文本字号动态变化。设置最大最小字体样式后,font-size不生效。

-

font-size-step

-

<length>

-

1px

-

-

文本动态调整字号时的步长,需要设置最小,最大字号样式生效。

-

prefer-font-sizes

-

<array>

-

-

-

-

预设的字号集合,在动态尺寸调整时,优先使用预设字号集合中的字号匹配设置的最大行数,如果预设字号集合未设置,则使用最大最小和步长调整字号。针对仍然无法满足最大行数要求的情况,使用text-overflow设置项进行截断,设置预设尺寸集后,font-size、max-font-size、min-font-size和font-size-step不生效。

-

如:prefer-font-sizes: 12px,14px,16px

-

word-break6+

-

string

-

normal

-

-

设置文本折行模式,可选值为:

-
  • normal:默认换行规则,依据各自语言的规则,允许在字间发生换行。
  • break-all:对于非中文/日文/韩文的文本,可在任意字符间断行。
  • break-word:与break-all相同,不同的地方在于它要求一个没有断行破发点的词必须保持为一个整体单位。
-

text-indent7+

-

<length>

-

-

-

-

设置首行缩进量。

-

white-space7+

-

string

-

pre

-

-

设置处理元素中空白的模式,可选值为:

-
  • normal:所有空格、回车、制表符都合并成一个空格,文本自动换行;
  • nowrap:所有空格、回车、制表符都合并成一个空格,文本不换行;
  • pre:所有东西原样输出;
  • pre-wrap:所有东西原样输出,文本换行;
  • pre-line:所有空格、制表符合并成一个空格,回车不变,文本换行。
-

adapt-height7+

-

boolean

-

false

-

-

文本大小是否自适应容器高度。

-
说明:

设置字体大小自适应相关样式后生效。

-
-
- ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->- 字体动态缩放:预设尺寸集合和最小最大字号调节基于是否满足最大行数要求,预设尺寸集合会按照从左到右顺序查看是否满足最大行数要求,最小最大字号调节则基于从大到小顺序查看是否满足最大行数要求。 ->- 文本换行:文本可以通过转义字符\\r\\n进行换行。 ->- 文本标签内支持以下转义字符:\\a,\\b,\\f,\\n,\\r,\\t,\\v,\\',\\",\\0。 ->- 当使用子组件span组成文本段落时,如果span属性样式异常,将导致text段落无法显示。 ->- letter-spacing、text-align、line-height、text-overflow和max-lines样式作用于text及其子组件(span)组成的文本内容。 ->- text组件说明:不支持text内同时存在文本内容和span子组件。(如果同时存在,只显示span内的内容\) - -## 事件 - -支持[通用事件](/pages/010c0201010103)。 - -## 方法 - -支持[通用方法](/pages/010c0201010104)。 - -## 示例 - -``` - -
-
- - Hello {{ title }} - -
-
-``` - -``` -/* xxx.css */ -.container { - display: flex; - justify-content: center; - align-items: center; -} -.content{ - width: 400px; - height: 400px; - border: 20px; - border-image-source: url("/common/images/landscape.jpg"); - border-image-slice: 20px; - border-image-width: 30px; - border-image-outset: 10px; - border-image-repeat: round; -} -.title { - font-size: 80px; - text-align: center; - width: 400px; - height: 400px; -} -``` - -``` -// xxx.js -export default { - data: { - title: 'World' - } -} -``` - -![](/images/application-dev/reference/arkui-js/figures/3.png) - -``` - -
- - This is a passage - - - This is a passage - -
-``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - align-items: center; - background-color: #F1F3F5; - justify-content: center; -} -.text1{ - word-spacing: 10px; - adapt-height: true; -} -.text2{ - width: 200px; - max-lines: 1; - text-overflow: ellipsis; - text-valign: middle; - line-height: 40px; - text-decoration: underline; - text-decoration-color: red; - text-indent: 20px; - white-space: pre; -} -``` - -![](/images/application-dev/reference/arkui-js/figures/2.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/24.textarea.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/24.textarea.md" deleted file mode 100644 index e5646a42c334d3e693e99ccc7b60856373d51b02..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/24.textarea.md" +++ /dev/null @@ -1,386 +0,0 @@ ---- -title: textarea -permalink: /pages/010c0201010318 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:31 ---- -# textarea - -多行文本输入的文本框。 - -## 权限列表 - -无 - -## 子组件 - -不支持。 - -## 属性 - -除支持[通用属性](/pages/010c0201010101)外,还支持如下属性: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

placeholder

-

string

-

-

-

-

多行文本框的提示文本内容。

-

maxlength

-

number

-

-

-

-

多行文本框可输入的最多字符数量。

-

headericon

-

string

-

-

-

-

在文本输入前的图标展示,该图标不支持点击事件,图标格式为jpg,png和svg。

-

extend

-

boolean

-

false

-

-

文本框是否支持可扩展,设置可扩展属性后文本框高度可以跟随文字自适应。

-

value5+

-

string

-

-

-

-

多行文本框的内容。

-

showcounter5+

-

boolean

-

false

-

-

文本框是否需要开启计数下标功能,需要配合maxlength一起使用。

-

menuoptions5+

-

Array<MenuOption>

-

-

-

-

设置文本选择弹框点击更多按钮之后显示的菜单项。

-

autofocus6+

-

boolean

-

false

-

-

是否自动获焦。

-

selectedstart6+

-

number

-

-1

-

-

开始选择文本时初始选择位置。

-

selectedend6+

-

number

-

-1

-

-

开始选择文本时结尾选择位置。

-

softkeyboardenabled6+

-

boolean

-

true

-

-

编辑时是否弹出系统软键盘。

-
- -**表 1** MenuOption5+ - - - - - - - - - - - - - - - - -

名称

-

类型

-

描述

-

icon

-

string

-

菜单选项中的图标路径。

-

content

-

string

-

菜单选项中的文本内容。

-
- -## 样式 - -除支持[通用样式](/pages/010c0201010102)外,还支持如下样式: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

color

-

<color>

-

#e6000000

-

-

多行文本框的文本颜色。

-

font-size

-

<length>

-

16px

-

-

多行文本框的文本尺寸。

-

allow-scale

-

boolean

-

true

-

-

多行文本框的文本尺寸是否跟随系统设置字体缩放尺寸进行放大缩小。

-
说明:

如果在config描述文件中针对ability配置了fontSize的config-changes标签,则应用不会重启而直接生效。

-
-

placeholder-color

-

<color>

-

#99000000

-

-

多行文本框的提示文本颜色,type为text|email|date|time|number|password时生效。

-

font-weight

-

number | string

-

normal

-

-

多行文本框的字体粗细,见text组件font-weight的样式属性

-

font-family

-

string

-

sans-serif

-

-

多行文本框的字体列表,用逗号分隔,每个字体用字体名或者字体族名设置。列表中第一个系统中存在的或者通过自定义字体指定的字体,会被选中作为文本的字体。

-

caret-color6+

-

<color>

-

-

-

-

设置输入光标的颜色。

-
- -## 事件 - -除支持[通用事件](/pages/010c0201010103)外,还支持如下事件: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数

-

描述

-

change

-

{ text: newText, lines: textLines, height: textHeight }

-

输入内容发生变化时触发该事件,通过参数获取输入内容、行数和行高。

-
说明:

改变value属性值不会触发该回调。5+

-
-

translate5+

-

{ value: selectedText }

-

设置此事件后,进行文本选择操作后文本选择弹窗会出现翻译按钮,点击翻译按钮之后,触发该回调,返回选中的文本内容。

-

share5+

-

{ value: selectedText }

-

设置此事件后,进行文本选择操作后文本选择弹窗会出现分享按钮,点击分享按钮之后,触发该回调,返回选中的文本内容。

-

search5+

-

{ value: selectedText }

-

设置此事件后,进行文本选择操作后文本选择弹窗会出现搜索按钮,点击搜索按钮之后,触发该回调,返回选中的文本内容。

-

optionselect5+

-

{ index:optionIndex, value: selectedText }

-

文本选择弹窗中设置menuoptions属性后,用户在文本选择操作后,点击菜单项后触发该回调,返回点击的菜单项序号和选中的文本内容。

-

selectchange6+

-

{ start: number,end: number }

-

文本选择变化时触发事件。

-
- -## 方法 - -支持[通用方法](/pages/010c0201010104)。 - -## 示例 - -``` - - -``` - -``` -/* xxx.css */ -.textarea { - placeholder-color: gray; -} -``` - -``` -// xxx.js -import prompt from '@system.prompt'; -export default { -change(e){ - prompt.showToast({ - message: 'value: ' + e.text + ', lines: ' + e.lines + ', height: ' + e.height, - duration: 3000, - }); -} -} -``` - -![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127125124.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/25.toolbar.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/25.toolbar.md" deleted file mode 100644 index f062be63d8766940b32f312672b8387569d48330..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/25.toolbar.md" +++ /dev/null @@ -1,51 +0,0 @@ ---- -title: toolbar -permalink: /pages/010c0201010319 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:31 ---- -# toolbar - -工具栏。放在界面底部,用于展示针对当前界面的操作选项。 - -## 权限列表 - -无 - -## 子组件 - -支持子组件。 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->工具栏最多可以展示5个toolbar-item子组件,如果存在6个及以上toolbar-item子组件,则保留前面4个子组件,后续的子组件收纳到工具栏上的更多项中,通过点击更多项弹窗展示剩下的子组件,更多项展示的组件样式采用系统默认样式,toolbar-item上设置的自定义样式不生效。 - -## 属性 - -支持[通用属性](/pages/010c0201010101)。 - -## 样式 - -支持[通用样式](/pages/010c0201010102)。 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->不支持height样式,高度固定为56px。 - -## 事件 - -不支持。 - -## 方法 - -不支持。 - -## 示例 - -详见[toolbar-item示例](/pages/010c020101031a)。 - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/26.toolbar-item.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/26.toolbar-item.md" deleted file mode 100644 index 126b11eaf58d1070d4155433bd2c8bc2321b34ae..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/26.toolbar-item.md" +++ /dev/null @@ -1,296 +0,0 @@ ---- -title: toolbar-item -permalink: /pages/010c020101031a -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:31 ---- -# toolbar-item - -工具栏子组件。作为工具栏组件的子组件,用于展示工具栏上的一个操作选项。 - -## 子组件 - -无 - -## 属性 - -除支持[通用属性](/pages/010c0201010101)外,还支持如下属性: - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

value

-

string

-

-

-

-

该操作项文本内容。

-

icon

-

string

-

-

-

-

该操作项图标资源路径,该图标展示在选项文本上,支持本地路径,格式为png,jpg和svg。

-
- -## 样式 - -仅支持如下样式: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

color

-

<color>

-

#e6000000

-

-

文本颜色。

-

font-size

-

<length>

-

16px

-

-

文本大小。

-

allow-scale

-

boolean

-

true

-

-

文本尺寸是否跟随系统设置字体缩放尺寸进行放大缩小。

-

font-style

-

string

-

normal

-

-

文本字体样式,可选值为:

-
  1. normal: 标准的字体样式;
  2. italic: 斜体的字体样式。
-

font-weight

-

number|string

-

normal

-

-

文本字体粗细,number类型取值[100, 900]的整数(被100整除),默认为400,取值越大,字体越粗。string类型取值为:lighter、normal、bold、bolder。

-

text-decoration

-

string

-

none

-

-

文本修饰,可选值为:

-
  1. underline: 文本下划线修饰;
  2. line-through: 穿过文本的修饰线;
  3. none: 标准文本。
-

font-family

-

string

-

sans-serif

-

-

字体列表,用逗号分隔,每个字体用字体名或者字体族名设置。列表中第一个系统中存在的或者通过自定义字体指定的字体,会被选中作为文本的字体。

-

background

-

<linear-gradient>

-

-

-

-

仅支持设置渐变样式,与background-color、background-image不兼容。

-

background-color

-

<color>

-

-

-

-

设置背景颜色。

-

background-image

-

string

-

-

-

-

设置背景图片。与background-color、background不兼容;支持网络图片资源和本地图片资源地址。

-

background-size

-
  • string
  • <length> <length>
  • <percentage> <percentage>
-

auto

-

-

设置背景图片的大小。

-
  • string可选值:
    • contain:把图像扩展至最大尺寸,以使其高度和宽度完全适用内容区域。
    • cover:把背景图像扩展至足够大,以使背景图像完全覆盖背景区域;背景图像的某些部分也许无法显示在背景定位区域中。
    • auto:保持原图的比例不变。
    -
  • length值参数方式:

    设置背景图像的高度和宽度。第一个值设置宽度,第二个值设置高度。如果只设置一个值,则第二个值会被设置为 "auto"。

    -
  • 百分比参数方式:

    以父元素的百分比来设置背景图像的宽度和高度。第一个值设置宽度,第二个值设置高度。如果只设置一个值,则第二个值会被设置为 "auto"。

    -
-

background-repeat

-

string

-

repeat

-

-

针对重复背景图像样式进行设置,背景图像默认在水平和垂直方向上重复。

-
  • repeat:在水平轴和竖直轴上同时重复绘制图片。
  • repeat-x:只在水平轴上重复绘制图片。
  • repeat-y:只在竖直轴上重复绘制图片。
  • no-repeat:不会重复绘制图片。
-

background-position

-
  • string string
  • <length> <length>
  • <percentage> <percentage>
-

0px 0px

-

-
  • 关键词方式:如果仅规定了一个关键词,那么第二个值为"center"。两个值分别定义水平方向位置和竖直方向位置。
    • left:水平方向上最左侧。
    • right:水平方向上最右侧。
    • top:竖直方向上最顶部。
    • bottom:竖直方向上最底部。
    • center:水平方向或竖直方向上中间位置。
    -
-
  • length值参数方式:第一个值是水平位置,第二个值是垂直位置。 左上角是 0 0。单位是像素 (0px 0px) 。如果仅规定了一个值,另外一个值将是50%。
  • 百分比参数方式:第一个值是水平位置,第二个值是垂直位置。左上角是 0% 0%。右下角是 100% 100%。如果仅规定了一个值,另外一个值为50%。
  • 可以混合使用<percentage>和<length>。
-

opacity

-

number

-

1

-

-

元素的透明度,取值范围为0到1,1表示为不透明,0表示为完全透明。

-

display

-

string

-

-

flex

-

-

确定一个元素所产生的框的类型,可选值为:

-
  • flex:弹性布局。
  • none:不渲染此元素。
-

visibility

-

string

-

-

visible

-

-

是否显示元素所产生的框。不可见的框会占用布局(将'display'属性设置为'none'来完全去除框),可选值为:

-
  • visible:元素正常显示。
  • hidden:隐藏元素,但是其他元素的布局不改变,相当于此元素变成透明。
-
说明:

visibility和display样式都设置时,仅display生效。

-
-
- -## 事件 - -支持[通用事件](/pages/010c0201010103)。 - -## 方法 - -不支持。 - -## 示例 - -``` - - - - - - - - - -``` - -![](/images/application-dev/reference/arkui-js/figures/000000.jpg) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/27.toggle.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/27.toggle.md" deleted file mode 100644 index 7a25277b1ba27ece419826629b87912e2ccc18cf..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\237\272\347\241\200\347\273\204\344\273\266/27.toggle.md" +++ /dev/null @@ -1,239 +0,0 @@ ---- -title: toggle -permalink: /pages/010c020101031b -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:31 ---- -# toggle - -状态按钮用于从一组选项中进行选择,并可能在界面上实时显示选择后的结果。通常这一组选项都是由状态按钮构成。 - -## 权限列表 - -无 - -## 子组件 - -不支持。 - -## 属性 - -除支持[通用属性](/pages/010c0201010101)外,还支持如下属性: - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

value

-

string

-

-

-

-

状态按钮的文本值。

-

checked

-

boolean

-

false

-

-

状态按钮是否被选中。

-
- -## 样式 - -除支持[通用样式](/pages/010c0201010102)外,还支持如下样式: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

text-color

-

<color>

-

#E5000000

-

-

状态按钮的文本颜色。

-

font-size

-

<length>

-

16px

-

-

状态按钮的文本尺寸。

-

allow-scale

-

boolean

-

true

-

-

状态按钮的文本尺寸是否跟随系统设置字体缩放尺寸进行放大缩小。

-
说明:

如果在config描述文件中针对ability配置了fontSize的config-changes标签,则应用不会重启而直接生效。

-
-

font-style

-

string

-

normal

-

-

状态按钮的字体样式。

-

font-weight

-

number | string

-

normal

-

-

状态按钮的字体粗细。见text组件font-weight的样式属性

-

font-family

-

<string>

-

sans-serif

-

-

状态按钮的字体列表,用逗号分隔,每个字体用字体名或者字体族名设置。列表中第一个系统中存在的或者通过自定义字体指定的字体,会被选中作为文本的字体。

-
- -## 事件 - -除支持[通用事件](/pages/010c0201010103)外,还支持如下事件: - - - - - - - - - - - -

名称

-

参数

-

描述

-

change

-

{ checked:isChecked }

-

组件选中状态发生变化时触发。

-
- -## 方法 - -支持[通用方法](/pages/010c0201010104)。 - -## 示例 - -``` - -
- 1. Multiple choice example -
- {{$item}} -
- 2. Single choice example -
- -
-
-``` - -``` -/* xxx.css */ -.margin { - margin: 7px; -} -``` - -``` -// xxx.js -export default { - data: { - toggle_list: [ - { "id":"1001", "name":"Living room", "checked":true }, - { "id":"1002", "name":"Bedroom", "checked":false }, - { "id":"1003", "name":"Second bedroom", "checked":false }, - { "id":"1004", "name":"Kitchen", "checked":false }, - { "id":"1005", "name":"Study", "checked":false }, - { "id":"1006", "name":"Garden", "checked":false }, - { "id":"1007", "name":"Bathroom", "checked":false }, - { "id":"1008", "name":"Balcony", "checked":false }, - ], - toggles: ["Living room","Bedroom","Kitchen","Study"], - idx: "" - }, - allclick(arg) { - this.idx = arg - }, - allchange(e) { - if (e.checked === true) { - for (var i = 0; i < this.toggle_list.length; i++) { - if (this.toggle_list[i].id === this.idx) { - this.toggle_list[i].checked = true - } else { - this.toggle_list[i].checked = false - } - } - } - } -} -``` - -![](/images/application-dev/reference/arkui-js/figures/screenshot.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/04.\345\252\222\344\275\223\347\273\204\344\273\266/01.video.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/04.\345\252\222\344\275\223\347\273\204\344\273\266/01.video.md" deleted file mode 100644 index 681ec523c5a3f64b9964e55f5e8ac67cb85e367a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/04.\345\252\222\344\275\223\347\273\204\344\273\266/01.video.md" +++ /dev/null @@ -1,249 +0,0 @@ ---- -title: video -permalink: /pages/010c0201010401 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:31 ---- -# video - -视频播放组件。 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->- 需要在config.json配置 -> ``` -> "configChanges": ["orientation"] -> ``` - -## 权限列表 - -## 子组件 - -不支持。 - -## 属性 - -除支持[通用属性](/pages/010c0201010101)外,还支持如下样式: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

muted

-

boolean

-

false

-

-

视频是否静音播放。

-

src

-

string

-

-

-

-

播放视频内容的路径。

-

autoplay

-

boolean

-

false

-

-

视频是否自动播放。

-

controls

-

boolean

-

true

-

-

控制视频播放的控制栏是否显示,如果设置为false,则不显示控制栏。默认为true,由系统决定显示或隐藏控制栏。

-
- -## 样式 - -除支持[通用样式](/pages/010c0201010102)外,还支持如下样式: - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

object-fit

-

string

-

contain

-

-

视频源的缩放类型,如果poster设置了值,那么此配置还会影响视频海报的缩放类型,可选值参考表1

-
- -**表 1** object-fit 类型说明 - - - - - - - - - - -

类型

-

描述

-

fill

-

不保持宽高比进行放大缩小,使得图片填充满显示边界。

-
- -## 事件 - -除支持[通用事件](/pages/010c0201010103)外,还支持如下事件: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数

-

描述

-

prepared

-

{ duration: value }5+

-

视频准备完成时触发该事件,通过duration可以获取视频时长,单位为s。

-

start

-

-

-

播放时触发该事件。

-

pause

-

-

-

暂停时触发该事件。

-

finish

-

-

-

播放结束时触发该事件。

-

error

-

-

-

播放失败时触发该事件。

-

seeking

-

{ currenttime: value }

-

操作进度条过程时上报时间信息,单位为s。

-

seeked

-

{ currenttime: value }

-

操作进度条完成后,上报播放时间信息,单位为s。

-

timeupdate

-

{ currenttime: value }

-

播放进度变化时触发该事件,单位为s,更新时间间隔为250ms。

-
- -## 方法 - -除支持[通用方法](/pages/010c0201010104)外,还支持如下方法: - - - - - - - - - - - - - - - - - - - -

名称

-

参数

-

描述

-

start

-

-

-

请求播放视频。

-

pause

-

-

-

请求暂停播放视频。

-

setCurrentTime

-

{ currenttime: value }

-

指定视频播放的进度位置,单位为s。

-
- ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->在attached组件生命周期回调后,可以调用上述组件方法。 - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/01.canvas\347\273\204\344\273\266.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/01.canvas\347\273\204\344\273\266.md" deleted file mode 100644 index e4c03a96c283eea88e820d056f43a638a90d58eb..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/01.canvas\347\273\204\344\273\266.md" +++ /dev/null @@ -1,196 +0,0 @@ ---- -title: canvas组件 -permalink: /pages/010c0201010501 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:31 ---- -# canvas组件 - -提供画布组件。用于自定义绘制图形。 - -## 权限列表 - -无 - -## 子组件 - -不支持。 - -## 属性 - -支持[通用属性](/pages/010c0201010101)。 - -## 样式 - -支持[通用样式](/pages/010c0201010102)。 - -## 事件 - -支持[通用事件](/pages/010c0201010103)。 - -## 方法 - -除支持[通用方法](/pages/010c0201010104)外,还支持如下方法: - -### getContext - -getContext\(type: '2d', options?: ContextAttrOptions\): CanvasRendering2dContext - -获取canvas绘图上下文。不支持在onInit和onReady中进行调用。 - -- 参数 - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

描述

-

type

-

string

-

-

设置为'2d',返回值为2D绘制对象,该对象可用于在画布组件上绘制矩形、文本、图片等。

-

options6+

-

ContextAttrOptions

-

-

当前仅支持配置是否开启抗锯齿功能,默认为关闭。

-
- - **表 1** ContextAttrOptions - - - - - - - - - - - - -

参数名

-

类型

-

说明

-

antialias

-

boolean

-

是否开启抗锯齿功能,默认为false。

-
- -- 返回值 - - - - - - - - - -

类型

-

说明

-

CanvasRenderingContext2D

-

用于在画布组件上绘制矩形、文本、图片等

-
- - -### toDataURL6+ - -toDataURL\(type?: string, quality?: number\): string - -生成一个包含图片展示的URL。 - -- 参数 - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

描述

-

type

-

string

-

-

可选参数,用于指定图像格式,默认格式为image/png。

-

quality

-

number

-

-

在指定图片格式为image/jpeg或image/webp的情况下,可以从0到1的区间内选择图片的质量。如果超出取值范围,将会使用默认值0.92。

-
- -- 返回值 - - - - - - - - - -

类型

-

说明

-

string

-

图像的URL地址。

-
- - -## 示例 - -``` - -
- - -
-``` - -``` -// xxx.js -export default { - handleClick() { - const el = this.$refs.canvas1; - var dataURL = el.toDataURL(); - console.log(dataURL); - // "data:image/png;base64,xxxxxxxx..." - } -} -``` - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/02.CanvasRenderingContext2D\345\257\271\350\261\241.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/02.CanvasRenderingContext2D\345\257\271\350\261\241.md" deleted file mode 100644 index b958c22e9a2a0e921091b4df01b7402a6ce21ae9..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/02.CanvasRenderingContext2D\345\257\271\350\261\241.md" +++ /dev/null @@ -1,3232 +0,0 @@ ---- -title: CanvasRenderingContext2D对象 -permalink: /pages/010c0201010502 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:31 ---- -# CanvasRenderingContext2D对象 - -使用CanvasRenderingContext2D在canvas画布组件上进行绘制,绘制对象可以是矩形、文本、图片等。 - -- 示例 - - ``` - -
- - - -
- ``` - - ``` - // xxx.js - export default { - handleClick() { - const el = this.$refs.canvas1; - const ctx = el.getContext('2d'); - ctx.beginPath(); - ctx.arc(100, 75, 50, 0, 6.28); - ctx.stroke(); - }, - antialias() { - const el = this.$refs.canvas1; - const ctx = el.getContext('2d', { antialias: true }); - ctx.beginPath(); - ctx.arc(100, 75, 50, 0, 6.28); - ctx.stroke(); - } - } - ``` - - -- 示意图(关闭抗锯齿) - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214837333.png) - -- 示意图(开启抗锯齿) - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127125162.png) - - -## 属性 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

描述

-

fillStyle

-

<color> | CanvasGradient | CanvasPattern

-

-

-

指定绘制的填充色。

-
  • 类型为<color>时,表示设置填充区域的颜色。
  • 类型为CanvasGradient时,表示渐变对象,使用 createLinearGradient()方法创建。
  • 类型为CanvasPattern时,使用 createPattern()方法创建。
-

lineWidth

-

number

-

-

-

设置绘制线条的宽度。

-

strokeStyle

-

<color> | CanvasGradient | CanvasPattern

-

-

-

设置描边的颜色。

-
  • 类型为<color>时,表示设置描边使用的颜色。
  • 类型为CanvasGradient时,表示渐变对象,使用 createLinearGradient()方法创建。
  • 类型为CanvasPattern时,使用 createPattern()方法创建。
-

lineCap

-

string

-

butt

-

指定线端点的样式,可选值为:

-
  • butt:线端点以方形结束。
  • round:线端点以圆形结束。
  • square:线端点以方形结束,该样式下会增加一个长度和线段厚度相同,宽度是线段厚度一半的矩形。
-

lineJoin

-

string

-

miter

-

指定线段间相交的交点样式,可选值为:

-
  • round:在线段相连处绘制一个扇形,扇形的圆角半径是线段的宽度。
  • bevel:在线段相连处使用三角形为底填充, 每个部分矩形拐角独立。
  • miter:在相连部分的外边缘处进行延伸,使其相交于一点,形成一个菱形区域,该属性可以通过设置miterLimit属性展现效果。
-

miterLimit

-

number

-

10

-

设置斜接面限制值,该值指定了线条相交处内角和外角的距离。

-

font

-

string

-

"normal normal 14px sans-serif"

-

设置文本绘制中的字体样式。

-

语法:ctx.font="font-style font-weight font-size font-family"5+

-
  • font-style(可选),用于指定字体样式,支持如下几种样式:normal, italic。
  • font-weight(可选),用于指定字体的粗细,支持如下几种类型:normal, bold, bolder, lighter, 100, 200, 300, 400, 500, 600, 700, 800, 900。
  • font-size(可选),指定字号和行高,单位只支持px。
  • font-family(可选),指定字体系列,支持如下几种类型:sans-serif, serif, monospace。
-

textAlign

-

string

-

left

-

设置文本绘制中的文本对齐方式,可选值为:

-
  • left:文本左对齐。
  • right:文本右对齐。
  • center:文本居中对齐。
  • start:文本对齐界线开始的地方。
  • end:文本对齐界线结束的地方。
-
说明:

ltr布局模式下start和left一致,rtl布局模式下start和right一致·。

-
-

textBaseline

-

string

-

alphabetic

-

设置文本绘制中的水平对齐方式,可选值为:

-
  • alphabetic:文本基线是标准的字母基线。
  • top:文本基线在文本块的顶部。
  • hanging:文本基线是悬挂基线。
  • middle:文本基线在文本块的中间。
  • ideographic:文字基线是表意字基线;如果字符本身超出了alphabetic 基线,那么ideographic基线位置在字符本身的底部。
  • bottom:文本基线在文本块的底部。 与 ideographic 基线的区别在于 ideographic 基线不需要考虑下行字母。
-

globalAlpha

-

number

-

-

-

设置透明度,0.0为完全透明,1.0为完全不透明。

-

lineDashOffset

-

number

-

0.0

-

设置画布的虚线偏移量,精度为float。

-

globalCompositeOperation

-

string

-

source-over

-

设置合成操作的方式。类型字段可选值有source-over,source-atop,source-in,source-out,destination-over,destination-atop,destination-in,destination-out,lighter,copy,xor。具体请参考类型字段说明

-

shadowBlur

-

number

-

0.0

-

设置绘制阴影时的模糊级别,值越大越模糊,精度为float。

-

shadowColor

-

<color>

-

-

-

设置绘制阴影时的阴影颜色。

-

shadowOffsetX

-

number

-

-

-

设置绘制阴影时和原有对象的水平偏移值。

-

shadowOffsetY

-

number

-

-

-

设置绘制阴影时和原有对象的垂直偏移值。

-

imageSmoothingEnabled6+

-

boolean

-

true

-

用于设置绘制图片时是否进行图像平滑度调整,true为启用,false为不启用。

-
- -### fillStyle - -``` - -
- -
-``` - -``` -//xxx.js -export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.fillStyle = '#0000ff'; - ctx.fillRect(20, 20, 150, 100); - } -} -``` - -![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001166962736.png) - -### lineWidth - -``` - -
- -
-``` - -``` -//xxx.js -export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.lineWidth = 5; - ctx.strokeRect(25, 25, 85, 105); - } -} -``` - -![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001166484430.png) - -### strokeStyle - -``` - -
- -
-``` - -``` -//xxx.js -export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.lineWidth = 10; - ctx.strokeStyle = '#0000ff'; - ctx.strokeRect(25, 25, 155, 105); - } -} -``` - -![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001212124299.png) - -### lineCap - -``` - -
- -
-``` - -``` -//xxx.js -export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.lineWidth = 8; - ctx.beginPath(); - ctx.lineCap = 'round'; - ctx.moveTo(30, 50); - ctx.lineTo(220, 50); - ctx.stroke(); - } -} -``` - -![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214837127.png) - -### lineJoin - -``` - -
- -
-``` - -``` -//xxx.js -export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.beginPath(); - ctx.lineWidth = 8; - ctx.lineJoin = 'miter'; - ctx.moveTo(30, 30); - ctx.lineTo(120, 60); - ctx.lineTo(30, 110); - ctx.stroke(); - } -} -``` - -![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214717247.png) - -### miterLimit - -``` - -
- -
-``` - -``` -//xxx.js -export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.lineWidth =14; - ctx.lineJoin = 'miter'; - ctx.miterLimit = 3; - ctx.moveTo(30, 30); - ctx.lineTo(120, 60); - ctx.lineTo(30, 70); - ctx.stroke(); - } -} -``` - -![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001167001464.png) - -### font - -``` - -
- -
-``` - -``` -//xxx.js -export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.font = '30px sans-serif'; - ctx.fillText("Hello World", 20, 60); - } -} -``` - -![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001167046832.png) - -### textAlign - -``` - -
- -
-``` - -``` -//xxx.js -export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.strokeStyle = '#0000ff'; - ctx.moveTo(140, 10); - ctx.lineTo(140, 160); - ctx.stroke(); - - ctx.font = '18px sans-serif'; - - // Show the different textAlign values - ctx.textAlign = 'start'; - ctx.fillText('textAlign=start', 140, 60); - ctx.textAlign = 'end'; - ctx.fillText('textAlign=end', 140, 80); - ctx.textAlign = 'left'; - ctx.fillText('textAlign=left', 140, 100); - ctx.textAlign = 'center'; - ctx.fillText('textAlign=center',140, 120); - ctx.textAlign = 'right'; - ctx.fillText('textAlign=right',140, 140); - } -} -``` - -![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001167472798.png) - -### textBaseline - -``` - -
- -
-``` - -``` -//xxx.js -export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.strokeStyle = '#0000ff'; - ctx.moveTo(0, 120); - ctx.lineTo(400, 120); - ctx.stroke(); - - ctx.font = '20px sans-serif'; - - ctx.textBaseline = 'top'; - ctx.fillText('Top', 10, 120); - ctx.textBaseline = 'bottom'; - ctx.fillText('Bottom', 55, 120); - ctx.textBaseline = 'middle'; - ctx.fillText('Middle', 125, 120); - ctx.textBaseline = 'alphabetic'; - ctx.fillText('Alphabetic', 195, 120); - ctx.textBaseline = 'hanging'; - ctx.fillText('Hanging', 295, 120); - } -} -``` - -![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169315920.png) - -### globalAlpha - -``` - -
- -
-``` - -``` -//xxx.js -export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.fillStyle = 'rgb(255,0,0)'; - ctx.fillRect(0, 0, 50, 50); - ctx.globalAlpha = 0.4; - ctx.fillStyle = 'rgb(0,0,255)'; - ctx.fillRect(50, 50, 50, 50); - - } -} -``` - -![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001167953648.png) - -### lineDashOffset - -``` - -
- -
-``` - -``` -//xxx.js -export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.arc(100, 75, 50, 0, 6.28); - ctx.setLineDash([10,20]); - ctx.lineDashOffset = 10.0; - ctx.stroke(); - } -} -``` - -![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001167950468.png) - -### globalCompositeOperation - -- 类型字段说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

-

描述

-

source-over

-

在现有绘制内容上显示新绘制内容,属于默认值。

-

source-atop

-

在现有绘制内容顶部显示新绘制内容。

-

source-in

-

在现有绘制内容中显示新绘制内容。

-

source-out

-

在现有绘制内容之外显示新绘制内容。

-

destination-over

-

在新绘制内容上方显示现有绘制内容。

-

destination-atop

-

在新绘制内容顶部显示现有绘制内容。

-

destination-in

-

在新绘制内容中显示现有绘制内容。

-

destination-out

-

在新绘制内容外显示现有绘制内容。

-

lighter

-

显示新绘制内容和现有绘制内容。

-

copy

-

显示新绘制内容而忽略现有绘制内容。

-

xor

-

使用异或操作对新绘制内容与现有绘制内容进行融合。

-
- - -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.fillStyle = 'rgb(255,0,0)'; - ctx.fillRect(20, 20, 50, 50); - ctx.globalCompositeOperation = 'source-over'; - ctx.fillStyle = 'rgb(0,0,255)'; - ctx.fillRect(50, 50, 50, 50); - // Start drawing second example - ctx.fillStyle = 'rgb(255,0,0)'; - ctx.fillRect(120, 20, 50, 50); - ctx.globalCompositeOperation = 'destination-over'; - ctx.fillStyle = 'rgb(0,0,255)'; - ctx.fillRect(150, 50, 50, 50); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001213192781.png) - - 示例中,新绘制内容是蓝色矩形,现有绘制内容是红色矩形。 - - -### shadowBlur - -``` - -
- -
-``` - -``` -//xxx.js -export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.shadowBlur = 30; - ctx.shadowColor = 'rgb(0,0,0)'; - ctx.fillStyle = 'rgb(255,0,0)'; - ctx.fillRect(20, 20, 100, 80); - } -} -``` - -![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001168111514.png) - -### shadowColor - -``` - -
- -
-``` - -``` -//xxx.js -export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.shadowBlur = 30; - ctx.shadowColor = 'rgb(0,0,255)'; - ctx.fillStyle = 'rgb(255,0,0)'; - ctx.fillRect(30, 30, 100, 100); - } -} -``` - -![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001168111610.png) - -### shadowOffsetX - -``` - -
- -
-``` - -``` -//xxx.js -export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.shadowBlur = 10; - ctx.shadowOffsetX = 20; - ctx.shadowColor = 'rgb(0,0,0)'; - ctx.fillStyle = 'rgb(255,0,0)'; - ctx.fillRect(20, 20, 100, 80); - } -} -``` - -![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001167631876.png) - -### shadowOffsetY - -``` - -
- -
-``` - -``` -//xxx.js -export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.shadowBlur = 10; - ctx.shadowOffsetY = 20; - ctx.shadowColor = 'rgb(0,0,0)'; - ctx.fillStyle = 'rgb(255,0,0)'; - ctx.fillRect(30, 30, 100, 100); - } -} -``` - -![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001213193285.png) - -### imageSmoothingEnabled6+ - -``` - -
- -
-``` - -``` -//xxx.js -export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - var img = new Image(); - img.src = 'common/image/example.jpg'; - img.onload = function() { - ctx.imageSmoothingEnabled = false; - ctx.drawImage(img, 0, 0, 400, 200); - }; - } -} -``` - -![](/images/application-dev/reference/arkui-js/figures/smoothOff.png) - -## 方法 - -### fillRect - -fillRect\(x: number, y: number, width:number, height: number\): void - -填充一个矩形。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

描述

-

x

-

number

-

指定矩形左上角点的x坐标。

-

y

-

number

-

指定矩形左上角点的y坐标。

-

width

-

number

-

指定矩形的宽度。

-

height

-

number

-

指定矩形的高度。

-
- -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.fillRect(20, 20, 200, 150); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214811029.png) - - -### clearRect - -clearRect\(x: number, y: number, width:number, height: number\): void - -删除指定区域内的绘制内容。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

描述

-

x

-

number

-

指定矩形上的左上角x坐标。

-

y

-

number

-

指定矩形上的左上角y坐标。

-

width

-

number

-

指定矩形的宽度。

-

height

-

number

-

指定矩形的高度。

-
- -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.fillStyle = 'rgb(0,0,255)'; - ctx.fillRect(0, 0, 400, 200); - ctx.clearRect(20, 20, 150, 100); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214619417.png) - - -### strokeRect - -strokeRect\(x: number, y: number, width:number, height: number\): void - -绘制具有边框的矩形,矩形内部不填充。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

描述

-

x

-

number

-

指定矩形的左上角x坐标。

-

y

-

number

-

指定矩形的左上角y坐标。

-

width

-

number

-

指定矩形的宽度。

-

height

-

number

-

指定矩形的高度。

-
- -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.strokeRect(30, 30, 200, 150); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214822091.png) - - -### fillText - -fillText\(text: string, x: number, y: number\): void - -绘制填充类文本。 - -- 参数 - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

描述

-

text

-

string

-

需要绘制的文本内容。

-

x

-

number

-

需要绘制的文本的左下角x坐标。

-

y

-

number

-

需要绘制的文本的左下角y坐标。

-
- -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.font = '35px sans-serif'; - ctx.fillText("Hello World!", 10, 60); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214469787.png) - - -### strokeText - -strokeText\(text: string, x: number, y: number\): void - -绘制描边类文本。 - -- 参数 - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

描述

-

text

-

string

-

需要绘制的文本内容。

-

x

-

number

-

需要绘制的文本的左下角x坐标。

-

y

-

number

-

需要绘制的文本的左下角y坐标。

-
- -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.font = '25px sans-serif'; - ctx.strokeText("Hello World!", 10, 60); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214460669.png) - - -### measureText - -measureText\(text: string\): TextMetrics - -该方法返回一个文本测算的对象,通过该对象可以获取指定文本的宽度值。 - -- 参数 - - - - - - - - - - - -

参数

-

类型

-

描述

-

text

-

string

-

需要进行测量的文本。

-
- -- 返回值 - - - - - - - - - -

类型

-

说明

-

TextMetrics

-

包含指定字体的宽度,该宽度可以通过TextMetrics.width来获取。

-
- -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.font = '20px sans-serif'; - var txt = 'Hello World'; - ctx.fillText("width:" + ctx.measureText(txt).width, 20, 60); - ctx.fillText(txt, 20, 110); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169142476.png) - - -### stroke - -stroke\(\): void - -进行边框绘制操作。 - -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.moveTo(25, 25); - ctx.lineTo(25, 250); - ctx.lineWidth = '6'; - ctx.strokeStyle = 'rgb(0,0,255)'; - ctx.stroke(); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001236697937.png) - - -### beginPath - -beginPath\(\): void - -创建一个新的绘制路径。 - -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.beginPath(); - ctx.lineWidth = '6'; - ctx.strokeStyle = '#0000ff'; - ctx.moveTo(15, 80); - ctx.lineTo(280, 80); - ctx.stroke(); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214629745.png) - - -### moveTo - -moveTo\(x: number, y: number\): void - -路径从当前点移动到指定点。 - -- 参数 - - - - - - - - - - - - - - - -

参数

-

类型

-

描述

-

x

-

number

-

指定位置的x坐标。

-

y

-

number

-

指定位置的y坐标。

-
- -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.beginPath(); - ctx.moveTo(10, 10); - ctx.lineTo(280, 160); - ctx.stroke(); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169309948.png) - - -### lineTo - -lineTo\(x: number, y: number\): void - -从当前点到指定点进行路径连接。 - -- 参数 - - - - - - - - - - - - - - - -

参数

-

类型

-

描述

-

x

-

number

-

指定位置的x坐标。

-

y

-

number

-

指定位置的y坐标。

-
- -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.beginPath(); - ctx.moveTo(10, 10); - ctx.lineTo(280, 160); - ctx.stroke(); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169469914.png) - - -### closePath - -closePath\(\): void - -结束当前路径形成一个封闭路径。 - -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.beginPath(); - ctx.moveTo(30, 30); - ctx.lineTo(110, 30); - ctx.lineTo(70, 90); - ctx.closePath(); - ctx.stroke(); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169151508.png) - - -### createPattern - -createPattern\(image: Image, repetition: string\): Object - -通过指定图像和重复方式创建图片填充的模板。 - -- 参数 - - - - - - - - - - - - - - - -

参数

-

类型

-

描述

-

image

-

Image

-

图源对象,具体参考Image对象

-

repetition

-

string

-

设置图像重复的方式,取值为:'repeat'、'repeat-x'、 'repeat-y'、'no-repeat'。

-
- -- 返回值 - - - - - - - - - -

类型

-

说明

-

Object

-

指定图像填充的Pattern对象。

-
- -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - var img = new Image(); - img.src = 'common/images/example.jpg'; - var pat = ctx.createPattern(img, 'repeat'); - ctx.fillStyle = pat; - ctx.fillRect(0, 0, 20, 20); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169301188.png) - - -### bezierCurveTo - -bezierCurveTo\(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number\): void - -创建三次贝赛尔曲线的路径。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

描述

-

cp1x

-

number

-

第一个贝塞尔参数的x坐标值。

-

cp1y

-

number

-

第一个贝塞尔参数的y坐标值。

-

cp2x

-

number

-

第二个贝塞尔参数的x坐标值。

-

cp2y

-

number

-

第二个贝塞尔参数的y坐标值。

-

x

-

number

-

路径结束时的x坐标值。

-

y

-

number

-

路径结束时的y坐标值。

-
- -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.beginPath(); - ctx.moveTo(10, 10); - ctx.bezierCurveTo(20, 100, 200, 100, 200, 20); - ctx.stroke(); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214621177.png) - - -### quadraticCurveTo - -quadraticCurveTo\(cpx: number, cpy: number, x: number, y: number\): void - -创建二次贝赛尔曲线的路径。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

描述

-

cpx

-

number

-

贝塞尔参数的x坐标值。

-

cpy

-

number

-

贝塞尔参数的y坐标值。

-

x

-

number

-

路径结束时的x坐标值。

-

y

-

number

-

路径结束时的y坐标值。

-
- -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.beginPath(); - ctx.moveTo(20, 20); - ctx.quadraticCurveTo(100, 100, 200, 20); - ctx.stroke(); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169461910.png) - - -### arc - -arc\(x: number, y: number, radius: number, startAngle: number, endAngle: number, anticlockwise: boolean\): void - -绘制弧线路径。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

描述

-

x

-

number

-

弧线圆心的x坐标值。

-

y

-

number

-

弧线圆心的y坐标值。

-

radius

-

number

-

弧线的圆半径。

-

startAngle

-

number

-

弧线的起始弧度。

-

endAngle

-

number

-

弧线的终止弧度。

-

anticlockwise

-

boolean

-

是否逆时针绘制圆弧。

-
- -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.beginPath(); - ctx.arc(100, 75, 50, 0, 6.28); - ctx.stroke(); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169470288.png) - - -### arcTo - -arcTo\(x1: number, y1: number, x2: number, y2: number, radius: number\): void - -依据圆弧经过的点和圆弧半径创建圆弧路径。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

描述

-

x1

-

number

-

圆弧经过的第一个点的x坐标值。

-

y1

-

number

-

圆弧经过的第一个点的y坐标值。

-

x2

-

number

-

圆弧经过的第二个点的x坐标值。

-

y2

-

number

-

圆弧经过的第二个点的y坐标值。

-

radius

-

number

-

圆弧的圆半径值。

-
- -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.moveTo(100, 20); - ctx.arcTo(150, 20, 150, 70, 50); // Create an arc - ctx.stroke(); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169143586.png) - - -### ellipse6+ - -ellipse\(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, anticlockwise: number\): void - -在规定的矩形区域绘制一个椭圆。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

描述

-

x

-

number

-

椭圆圆心的x轴坐标。

-

y

-

number

-

椭圆圆心的y轴坐标。

-

radiusX

-

number

-

椭圆x轴的半径长度。

-

radiusY

-

number

-

椭圆y轴的半径长度。

-

rotation

-

number

-

椭圆的旋转角度,单位为弧度。

-

startAngle

-

number

-

椭圆绘制的起始点角度,以弧度表示。

-

endAngle

-

number

-

椭圆绘制的结束点角度,以弧度表示。

-

anticlockwise

-

number

-

是否以逆时针方向绘制椭圆,0为顺时针,1为逆时针。(可选参数,默认为0)

-
- -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.beginPath(); - ctx.ellipse(200, 200, 50, 100, Math.PI * 0.25, Math.PI * 0.5, Math.PI, 1); - ctx.stroke(); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/ellipse.png) - - -### rect - -rect\(x: number, y: number, width: number, height: number\): void - -创建矩形路径。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

描述

-

x

-

number

-

指定矩形的左上角x坐标值。

-

y

-

number

-

指定矩形的左上角y坐标值。

-

width

-

number

-

指定矩形的宽度。

-

height

-

number

-

指定矩形的高度。

-
- -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.rect(20, 20, 100, 100); // Create a 100*100 rectangle at (20, 20) - ctx.stroke(); // Draw it - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214630783.png) - - -### fill - -fill\(\): void - -对封闭路径进行填充。 - -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.rect(20, 20, 100, 100); // Create a 100*100 rectangle at (20, 20) - ctx.fill(); // Draw it in default setting - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214703717.png) - - -### clip - -clip\(\): void - -设置当前路径为剪切路径。 - -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.rect(0, 0, 200, 200); - ctx.stroke(); - ctx.clip(); - // Draw red rectangle after clip - ctx.fillStyle = "rgb(255,0,0)"; - ctx.fillRect(0, 0, 150, 150); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169303414.png) - - -### rotate - -rotate\(rotate: number\): void - -针对当前坐标轴进行顺时针旋转。 - -- 参数 - - - - - - - - - - - -

参数

-

类型

-

描述

-

rotate

-

number

-

设置顺时针旋转的弧度值,可以通过Math.PI / 180将角度转换为弧度值。

-
- -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.rotate(45 * Math.PI / 180); // Rotate the rectangle 45 degrees - ctx.fillRect(70, 20, 50, 50); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169463368.png) - - -### scale - -scale\(x: number, y: number\): void - -设置canvas画布的缩放变换属性,后续的绘制操作将按照缩放比例进行缩放。 - -- 参数 - - - - - - - - - - - - - - - -

参数

-

类型

-

描述

-

x

-

number

-

设置水平方向的缩放值。

-

y

-

number

-

设置垂直方向的缩放值。

-
- -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.strokeRect(10, 10, 25, 25); - ctx.scale(2, 2);// Scale to 200% - ctx.strokeRect(10, 10, 25, 25); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214463281.png) - - -### transform - -transform\(scaleX: number, skewX: number, skewY: number, scale: number, translateX: number, translateY: number\): void - -transform方法对应一个变换矩阵,想对一个图形进行变化的时候,只要设置此变换矩阵相应的参数,对图形的各个定点的坐标分别乘以这个矩阵,就能得到新的定点的坐标。矩阵变换效果可叠加。 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->变换后的坐标计算方式(x和y为变换前坐标,x'和y'为变换后坐标): ->- x' = scaleX \* x + skewY \* y + translateX ->- y' = skewX \* x + scaleY \* y + translateY - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

描述

-

scaleX

-

number

-

指定水平缩放值。

-

skewX

-

number

-

指定水平倾斜值。

-

skewY

-

number

-

指定垂直倾斜值。

-

scaleY

-

number

-

指定垂直缩放值。

-

translateX

-

number

-

指定水平移动值。

-

translateY

-

number

-

指定垂直移动值。

-
- -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.fillStyle = 'rgb(0,0,0)'; - ctx.fillRect(0, 0, 100, 100) - ctx.transform(1, 0.5, -0.5, 1, 10, 10); - ctx.fillStyle = 'rgb(255,0,0)'; - ctx.fillRect(0, 0, 100, 100); - ctx.transform(1, 0.5, -0.5, 1, 10, 10); - ctx.fillStyle = 'rgb(0,0,255)'; - ctx.fillRect(0, 0, 100, 100); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214623227.png) - - -### setTransform - -setTransform\(scaleX: number, skewX: number, skewY: number, scale: number, translateX: number, translateY: number\): void - -setTransfrom方法使用的参数和transform\(\)方法相同,但setTransform\(\)方法会重置现有的变换矩阵并创建新的变换矩阵。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

描述

-

scaleX

-

number

-

指定水平缩放值。

-

skewX

-

number

-

指定水平倾斜值。

-

skewY

-

number

-

指定垂直倾斜值。

-

scaleY

-

number

-

指定垂直缩放值。

-

translateX

-

number

-

指定水平移动值。

-

translateY

-

number

-

指定垂直移动值。

-
- -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.fillStyle = 'rgb(255,0,0)'; - ctx.fillRect(0, 0, 100, 100) - ctx.setTransform(1,0.5, -0.5, 1, 10, 10); - ctx.fillStyle = 'rgb(0,0,255)'; - ctx.fillRect(0, 0, 100, 100); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001168984880.png) - - -### translate - -translate\(x: number, y: number\): void - -移动当前坐标系的原点。 - -- 参数 - - - - - - - - - - - - - - - -

参数

-

类型

-

描述

-

x

-

number

-

设置水平平移量。

-

y

-

number

-

设置竖直平移量。

-
- -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.fillRect(10, 10, 50, 50); - ctx.translate(70, 70); - ctx.fillRect(10, 10, 50, 50); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169144864.png) - - -### createPath2D6+ - -createPath2D\(path: Path2D, cmds: string\): Path2D - -创建一个Path2D对象。 - -- 参数 - - - - - - - - - - - - - - - -

参数

-

类型

-

描述

-

path

-

Path2D

-

Path2D对象。

-

cmds

-

string

-

SVG的Path描述字符串。

-
- -- 返回值 - - [Path2D对象](/pages/010c0201010506) - -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - var path1 = ctx.createPath2D(); - path1.moveTo(100, 100); - path1.lineTo(200, 100); - path1.lineTo(100, 200); - path1.closePath(); - ctx.stroke(path1); - var path2 = ctx.createPath2D("M150 150 L50 250 L250 250 Z"); - ctx.stroke(path2); - var path3 = ctx.createPath2D(path2); - ctx.stroke(path3); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214824709.png) - - -### drawImage - -drawImage\(image: Image, sx: number, sy: number, sWidth: number, sHeight: number, dx: number, dy: number, dWidth: number, dHeight: number\):void - -进行图像绘制。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

描述

-

image

-

Image

-

图片资源,请参考Image对象

-

sx

-

number

-

裁切源图像时距离源图像左上角的x坐标值。

-

sy

-

number

-

裁切源图像时距离源图像左上角的y坐标值。

-

sWidth

-

number

-

裁切源图像时需要裁切的宽度。

-

sHeight

-

number

-

裁切源图像时需要裁切的高度。

-

dx

-

number

-

绘制区域左上角在x轴的位置。

-

dy

-

number

-

绘制区域左上角在y 轴的位置。

-

dWidth

-

number

-

绘制区域的宽度。

-

dHeight

-

number

-

绘制区域的高度。

-
- -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - var test = this.$element('drawImage'); - var ctx = test.getContext('2d'); - var img = new Image(); - img.src = 'common/image/test.jpg'; - ctx.drawImage(img, 50, 80, 80, 80); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214704759.png) - - -### restore - -restore\(\): void - -对保存的绘图上下文进行恢复。 - -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.restore(); - } - } - ``` - - -### save - -save\(\): void - -对当前的绘图上下文进行保存。 - -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.save(); - } - } - ``` - - -### createLinearGradient6+ - -createLinearGradient\(x0: number, y0: number, x1: number, y1: number\): Object - -创建一个线性渐变色,返回CanvasGradient对象,请参考[CanvasGradient对象](/pages/010c0201010504)。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

描述

-

x0

-

number

-

起点的x轴坐标。

-

y0

-

number

-

起点的y轴坐标。

-

x1

-

number

-

终点的x轴坐标。

-

y1

-

number

-

终点的y轴坐标。

-
- -- 返回值 - - - - - - - - - -

类型

-

说明

-

Object

-

返回创建的CanvasGradient对象。

-
- -- 示例 - - ``` - -
- - -
- ``` - - ``` - // xxx.js - export default { - handleClick() { - const el = this.$refs.canvas; - const ctx = el.getContext('2d'); - // Linear gradient: start(50,0) end(300,100) - var gradient = ctx.createLinearGradient(50,0, 300,100); - // Add three color stops - gradient.addColorStop(0.0, 'red'); - gradient.addColorStop(0.5, 'white'); - gradient.addColorStop(1.0, 'green'); - // Set the fill style and draw a rectangle - ctx.fillStyle = gradient; - ctx.fillRect(0, 0, 500, 500); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169303416.png) - - -### createRadialGradient6+ - -createRadialGradient\(x0: number, y0: number, r0: number, x1: number, y1: number, r1: number\): Object - -创建一个径向渐变色,返回CanvasGradient对象,请参考CanvasGradient - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

描述

-

x0

-

number

-

起始圆的x轴坐标。

-

y0

-

number

-

起始圆的y轴坐标。

-

r0

-

number

-

起始圆的半径。必须是非负且有限的。

-

x1

-

number

-

终点圆的x轴坐标。

-

y1

-

number

-

终点圆的y轴坐标。

-

r1

-

number

-

终点圆的半径。必须为非负且有限的。

-
- -- 返回值 - - - - - - - - - -

类型

-

说明

-

Object

-

返回创建的CanvasGradient对象。

-
- -- 示例 - - ``` - -
- - -
- ``` - - ``` - // xxx.js - export default { - handleClick() { - const el = this.$refs.canvas; - const ctx = el.getContext('2d'); - // Radial gradient: inner circle(200,200,r:50) outer circle(200,200,r:200) - var gradient = ctx.createRadialGradient(200,200,50, 200,200,200); - // Add three color stops - gradient.addColorStop(0.0, 'red'); - gradient.addColorStop(0.5, 'white'); - gradient.addColorStop(1.0, 'green'); - // Set the fill style and draw a rectangle - ctx.fillStyle = gradient; - ctx.fillRect(0, 0, 500, 500); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001169463370.png) - - -### createImageData - -createImageData\(width: number, height: number, imageData: Object\): Object - -创建新的ImageData 对象,请参考[ImageData对象](/pages/010c0201010505)。 - -- 参数 - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

描述

-

width

-

number

-

ImageData的宽度。

-

height

-

number

-

ImageData的高度。

-

imagedata

-

Object

-

复制现有的ImageData对象。

-
- -- 返回值 - - - - - - - - - -

类型

-

说明

-

Object

-

返回创建的ImageData对象。

-
- -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - imageData = ctx.createImageData(50, 100); // Create ImageData with 50px width and 100px height - newImageData = ctx.createImageData(imageData); // Create ImageData using the input imageData - } - } - ``` - - -### getImageData - -getImageData\(sx: number, sy: number, sw: number, sh: number\): Object - -以当前canvas指定区域内的像素创建ImageData对象。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

描述

-

sx

-

number

-

需要输出的区域的左上角x坐标。

-

sy

-

number

-

需要输出的区域的左上角y坐标。

-

sw

-

number

-

需要输出的区域的宽度。

-

sh

-

number

-

需要输出的区域的高度。

-
- -- 返回值 - - - - - - - - - -

类型

-

说明

-

Object

-

返回包含指定区域像素的ImageData对象。

-
- -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - var test = this.$element('getImageData') - var ctx = test.getContext('2d'); - var imageData = ctx.getImageData(0, 0, 280, 300); - } - } - ``` - - -### putImageData - -putImageData\(imageData: Object, dx: number, dy: number, dirtyX: number, dirtyY: number, dirtyWidth: number, dirtyHeight: number\): void - -使用ImageData数据填充新的矩形区域。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

描述

-

imagedata

-

Object

-

包含像素值的ImageData对象。

-

dx

-

number

-

填充区域在x轴方向的偏移量。

-

dy

-

number

-

填充区域在y轴方向的偏移量。

-

dirtyX

-

number

-

源图像数据矩形裁切范围左上角距离源图像左上角的x轴偏移量。

-

dirtyY

-

number

-

源图像数据矩形裁切范围左上角距离源图像左上角的y轴偏移量。

-

dirtyWidth

-

number

-

源图像数据矩形裁切范围的宽度。

-

dirtyHeight

-

number

-

源图像数据矩形裁切范围的高度。

-
- -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - var test = this.$element('getImageData') - var ctx = test.getContext('2d'); - var imgData = ctx.createImageData(100, 100); - for (var i = 0; i < imgData.data.length; i += 4) { - imgData.data[i + 0] = 255; - imgData.data[i + 1] = 0; - imgData.data[i + 2] = 0; - imgData.data[i + 3] = 255; - } - ctx.putImageData(imgData, 10, 10); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214463283.png) - - -### setLineDash - -setLineDash\(segments: Array\): void - -设置画布的虚线样式。 - -- 参数 - - - - - - - - - - - -

参数

-

类型

-

描述

-

segments

-

Array

-

作为数组用来描述线段如何交替和间距长度。

-
- -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.arc(100, 75, 50, 0, 6.28); - ctx.setLineDash([10,20]); - ctx.stroke(); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001214623229.png) - - -### getLineDash - -getLineDash\(\): Array - -获得当前画布的虚线样式。 - -- 返回值 - - - - - - - - - -

类型

-

说明

-

Array

-

返回数组,该数组用来描述线段如何交替和间距长度。

-
- -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - var info = ctx.getLineDash(); - } - } - ``` - - -### transferFromImageBitmap7+ - -transferFromImageBitmap\(bitmap: ImageBitmap\): void - -显示给定的ImageBitmap对象。 - -- 参数 - - - - - - - - - - - -

参数

-

类型

-

描述

-

bitmap

-

ImageBitmap

-

待显示的ImageBitmap对象。

-
- -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - var canvas = this.$refs.canvas.getContext('2d'); - var offscreen = new OffscreenCanvas(500,500); - var offscreenCanvasCtx = offscreen.getContext("2d"); - offscreenCanvasCtx.fillRect(0, 0, 200, 200); - - var bitmap = offscreen.transferToImageBitmap(); - canvas.transferFromImageBitmap(bitmap); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001168984882.png) - - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/03.Image\345\257\271\350\261\241.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/03.Image\345\257\271\350\261\241.md" deleted file mode 100644 index 05e61c2ac32a23073282cc649abf512708eb8fa4..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/03.Image\345\257\271\350\261\241.md" +++ /dev/null @@ -1,119 +0,0 @@ ---- -title: Image对象 -permalink: /pages/010c0201010503 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:31 ---- -# Image对象 - -图片对象。 - -## 属性 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

属性

-

类型

-

默认值

-

必填

-

描述

-

src

-

string

-

-

-

-

图片资源的路径。

-

width

-

<length>

-

0px

-

-

图片的宽度。

-

height

-

<length>

-

0px

-

-

图片的高度。

-

onload

-

Function

-

-

-

-

图片加载成功后触发该事件,无参数。

-

onerror

-

Function

-

-

-

-

图片加载失败后触发该事件,无参数。

-
- -## 示例 - -``` - -
- -
-``` - -``` -//xxx.js -export default { - onShow(){ - const el =this.$refs.canvas - var ctx = this.$element('drawImage').getContext('2d'); - var img = new Image(); - img.src = 'common/images/example.jpg'; - img.onload = function() { - console.log('Image load success'); - ctx.drawImage(img, 0, 0, 360, 250); - }; - img.onerror = function() { - console.log('Image load fail'); - }; - } -} -``` - -![](/images/application-dev/reference/arkui-js/figures/1-2.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/04.CanvasGradient\345\257\271\350\261\241.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/04.CanvasGradient\345\257\271\350\261\241.md" deleted file mode 100644 index 39653179030cdecbb11d70e1d65c5773784fb780..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/04.CanvasGradient\345\257\271\350\261\241.md" +++ /dev/null @@ -1,76 +0,0 @@ ---- -title: CanvasGradient对象 -permalink: /pages/010c0201010504 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:31 ---- -# CanvasGradient对象 - -渐变对象。 - -## addColorStop - -addColorStop\(offset: number, color: string\): void - -设置渐变断点值,包括偏移和颜色。 - -- 参数 - - - - - - - - - - - - - - - -

参数

-

类型

-

描述

-

offset

-

number

-

设置渐变点距离起点的位置占总体长度的比例,范围为0到1。

-

color

-

string

-

设置渐变的颜色。

-
- -- 示例 - - ``` - -
- - -
- ``` - - ``` - // xxx.js - export default { - handleClick() { - const el =this.$refs.canvas; - const ctx =el.getContext('2d'); - const gradient = ctx.createLinearGradient(0,0,100,0); - gradient.addColorStop(0,'#00ffff'); - gradient.addColorStop(1,'#ffff00'); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001152610806.png) - - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/05.ImageData\345\257\271\350\261\241.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/05.ImageData\345\257\271\350\261\241.md" deleted file mode 100644 index d5194a4b99669806408fbf3cf1fa638a7089b6d1..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/05.ImageData\345\257\271\350\261\241.md" +++ /dev/null @@ -1,77 +0,0 @@ ---- -title: ImageData对象 -permalink: /pages/010c0201010505 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:31 ---- -# ImageData对象 - -ImageData对象可以存储canvas渲染的像素数据。 - -## 属性 - - - - - - - - - - - - - - - - - - - -

属性

-

类型

-

描述

-

width

-

number

-

矩形区域实际像素宽度。

-

height

-

number

-

矩形区域实际像素高度。

-

data

-

<Uint8ClampedArray>

-

一维数组,保存了相应的颜色数据,数据值范围为0到255。

-
- -## 示例 - -``` - -
- -
-``` - -``` -//xxx.js -import prompt from '@system.prompt'; -export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.fillRect(0,0,200,200) - var imageData = ctx.createImageData(1,1) - prompt.showToast({ - message:imageData, - duration:5000 - }) - } -} -``` - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/06.Path2D\345\257\271\350\261\241.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/06.Path2D\345\257\271\350\261\241.md" deleted file mode 100644 index c47b010507204d4ac8bcea1cf93ca7e6cacb4272..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/06.Path2D\345\257\271\350\261\241.md" +++ /dev/null @@ -1,809 +0,0 @@ ---- -title: Path2D对象 -permalink: /pages/010c0201010506 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:31 ---- -# Path2D对象 - -路径对象,支持通过对象的接口进行路径的描述,并通过Canvas的stroke接口进行绘制。 - -## addPath - -addPath\(path: Object\): void - -将另一个路径添加到当前的路径对象中。 - -- 参数 - - - - - - - - - - - -

参数

-

类型

-

描述

-

path

-

Object

-

需要添加到当前路径的路径对象

-
- -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - var path1 = ctx.createPath2D("M250 150 L150 350 L350 350 Z"); - var path2 = ctx.createPath2D(); - path2.addPath(path1); - ctx.stroke(path2); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173164873.png) - - -## setTransform - -setTransform\(scaleX: number, skewX: number, skewY: number, scaleY: number, translateX: number, translateY: number\): void - -设置路径变换矩阵。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

描述

-

scaleX

-

number

-

x轴的缩放比例

-

skewX

-

number

-

x轴的倾斜角度

-

skewY

-

number

-

y轴的倾斜角度

-

scaleY

-

number

-

y轴的缩放比例

-

translateX

-

number

-

x轴的平移距离

-

translateY

-

number

-

y轴的平移距离

-
- -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - var path = ctx.createPath2D("M250 150 L150 350 L350 350 Z"); - path.setTransform(0.8, 0, 0, 0.4, 0, 0); - ctx.stroke(path); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127125208.png) - - -## closePath - -closePath\(\): void - -将路径的当前点移回到路径的起点,当前点到起点间画一条直线。如果形状已经闭合或只有一个点,则此功能不执行任何操作。 - -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - var path = ctx.createPath2D(); - path.moveTo(200, 100); - path.lineTo(300, 100); - path.lineTo(200, 200); - path.closePath(); - ctx.stroke(path); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127125202.png) - - -## moveTo - -moveTo\(x: number, y: number\): void - -将路径的当前坐标点移动到目标点,移动过程中不绘制线条。 - -- 参数 - - - - - - - - - - - - - - - -

参数

-

类型

-

描述

-

x

-

number

-

目标点X轴坐标

-

y

-

number

-

目标点Y轴坐标

-
- -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - var path = ctx.createPath2D(); - path.moveTo(50, 100); - path.lineTo(250, 100); - path.lineTo(150, 200); - path.closePath(); - ctx.stroke(path); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173164869.png) - - -## lineTo - -lineTo\(x: number, y: number\): void - -从当前点绘制一条直线到目标点。 - -- 参数 - - - - - - - - - - - - - - - -

参数

-

类型

-

描述

-

x

-

number

-

目标点X轴坐标

-

y

-

number

-

目标点Y轴坐标

-
- -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - var path = ctx.createPath2D(); - path.moveTo(100, 100); - path.lineTo(100, 200); - path.lineTo(200, 200); - path.lineTo(200, 100); - path.closePath(); - ctx.stroke(path); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127285024.png) - - -## bezierCurveTo - -bezierCurveTo\(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number\): void - -创建三次贝赛尔曲线的路径。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

描述

-

cp1x

-

number

-

第一个贝塞尔参数的x坐标值。

-

cp1y

-

number

-

第一个贝塞尔参数的y坐标值。

-

cp2x

-

number

-

第二个贝塞尔参数的x坐标值。

-

cp2y

-

number

-

第二个贝塞尔参数的y坐标值。

-

x

-

number

-

路径结束时的x坐标值。

-

y

-

number

-

路径结束时的y坐标值。

-
- -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - var path = ctx.createPath2D(); - path.moveTo(10, 10); - path.bezierCurveTo(20, 100, 200, 100, 200, 20); - ctx.stroke(path); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173324783.png) - - -## quadraticCurveTo - -quadraticCurveTo\(cpx: number, cpy: number, x: number, y: number\): void - -创建二次贝赛尔曲线的路径。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

描述

-

cpx

-

number

-

贝塞尔参数的x坐标值。

-

cpy

-

number

-

贝塞尔参数的y坐标值。

-

x

-

number

-

路径结束时的x坐标值。

-

y

-

number

-

路径结束时的y坐标值。

-
- -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - var path = ctx.createPath2D(); - path.moveTo(10, 10); - path.quadraticCurveTo(100, 100, 200, 20); - ctx.stroke(path); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173164871.png) - - -## arc - -arc\(x: number, y: number, radius: number, startAngle: number, endAngle: number, anticlockwise: number\): void - -绘制弧线路径。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

描述

-

x

-

number

-

弧线圆心的x坐标值。

-

y

-

number

-

弧线圆心的y坐标值。

-

radius

-

number

-

弧线的圆半径。

-

startAngle

-

number

-

弧线的起始弧度。

-

endAngle

-

number

-

弧线的终止弧度。

-

anticlockwise

-

boolean

-

是否逆时针绘制圆弧。

-
- -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - var path = ctx.createPath2D(); - path.arc(100, 75, 50, 0, 6.28); - ctx.stroke(path); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173164867.png) - - -## arcTo - -arcTo\(x1: number, y1: number, x2: number, y2: number, radius: number\): void - -依据圆弧经过的点和圆弧半径创建圆弧路径。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

描述

-

x1

-

number

-

圆弧经过的第一个点的x坐标值。

-

y1

-

number

-

圆弧经过的第一个点的y坐标值。

-

x2

-

number

-

圆弧经过的第二个点的x坐标值。

-

y2

-

number

-

圆弧经过的第二个点的y坐标值。

-

radius

-

number

-

圆弧的圆半径值。

-
- -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - var path = ctx.createPath2D(); - path.arcTo(150, 20, 150, 70, 50); - ctx.stroke(path); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127125204.png) - - -## ellipse - -ellipse\(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, anticlockwise: number\): void - -在规定的矩形区域绘制一个椭圆。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

描述

-

x

-

number

-

椭圆圆心的x轴坐标。

-

y

-

number

-

椭圆圆心的y轴坐标。

-

radiusX

-

number

-

椭圆x轴的半径长度。

-

radiusY

-

number

-

椭圆y轴的半径长度。

-

rotation

-

number

-

椭圆的旋转角度,单位为弧度。

-

startAngle

-

number

-

椭圆绘制的起始点角度,以弧度表示。

-

endAngle

-

number

-

椭圆绘制的结束点角度,以弧度表示。

-

anticlockwise

-

number

-

是否以逆时针方向绘制椭圆,0为顺时针,1为逆时针。(可选参数,默认为0)

-
- -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx =el.getContext('2d'); - var path = ctx.createPath2D(); - path.ellipse(200, 200, 50, 100, Math.PI * 0.25, Math.PI * 0.5, Math.PI, 1); - ctx.stroke(path); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173324787.png) - - -## rect - -rect\(x: number, y: number, width: number, height: number\): void - -创建矩形路径。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

描述

-

x

-

number

-

指定矩形的左上角x坐标值。

-

y

-

number

-

指定矩形的左上角y坐标值。

-

width

-

number

-

指定矩形的宽度。

-

height

-

number

-

指定矩形的高度。

-
- -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - var path = ctx.createPath2D(); - path.rect(20, 20, 100, 100); - ctx.stroke(path); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127125212.png) - - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/07.ImageBitmap\345\257\271\350\261\241.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/07.ImageBitmap\345\257\271\350\261\241.md" deleted file mode 100644 index 6b1554305b955cc69bd1de965407ea9fc640598e..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/07.ImageBitmap\345\257\271\350\261\241.md" +++ /dev/null @@ -1,47 +0,0 @@ ---- -title: ImageBitmap对象 -permalink: /pages/010c0201010507 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:31 ---- -# ImageBitmap对象 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -ImageBitmap对象由OffscreenCanvas对象的transferToImageBitmap\(\)方法生成,存储了offscreen canvas渲染的像素数据。 - -## 属性 - - - - - - - - - - - - - - - -

属性

-

类型

-

描述

-

width

-

number

-

ImageBitmap的像素宽度。

-

height

-

number

-

ImageBitmap的像素高度。

-
- diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/08.OffscreenCanvas\345\257\271\350\261\241.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/08.OffscreenCanvas\345\257\271\350\261\241.md" deleted file mode 100644 index 9ca9fe116b280363d58801198e3cf4477aea9b69..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/08.OffscreenCanvas\345\257\271\350\261\241.md" +++ /dev/null @@ -1,212 +0,0 @@ ---- -title: OffscreenCanvas对象 -permalink: /pages/010c0201010508 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:31 ---- -# OffscreenCanvas对象 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -可以离屏渲染的canvas对象。 - -## 属性 - - - - - - - - - - - - - - - -

属性

-

类型

-

描述

-

width

-

number

-

offscreen canvas对象的宽度。

-

height

-

number

-

offscreen canvas对象的高度。

-
- -## 方法 - -### getContext - -getContext\(type: string, options?: CanvasRenderingContext2DSettings\): OffscreenCanvasRenderingContext2D - -获取offscreen canvas绘图上下文,返回值为2D绘制对象。 - -- 参数 - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

描述

-

contextId

-

string

-

-

仅支持 '2d'。

-

options

-

CanvasRenderingContext2DSettings

-

-

用于在离屏画布上进行绘制矩形、文本、图片等

-
- -- 返回值 - - - - - - - - - -

类型

-

说明

-

OffscreenCanvasRenderingContext2D

-

2D绘制对象,用于在画布组件上绘制矩形、文本、图片等

-
- - -### toDataURL - -toDataURL\(type?: string, quality?:number\): - -生成一个包含图片展示的URL。 - -- 参数 - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

描述

-

type

-

string

-

-

可选参数,用于指定图像格式,默认格式为image/png。

-

quality

-

number

-

-

在指定图片格式为image/jpeg或image/webp的情况下,可以从0到1的区间内选择图片的质量。如果超出取值范围,将会使用默认值0.92。

-
- -- 返回值 - - - - - - - - - -

类型

-

说明

-

string

-

图像的URL地址。

-
- - -### transferToImageBitmap - -transferToImageBitmap\(\): ImageBitmap - -在离屏画布最近渲染的图像上创建一个ImageBitmap对象。 - -- 返回值 - - - - - - - - - -

类型

-

说明

-

ImageBitmap

-

存储离屏画布上渲染的像素数据。

-
- - -## 示例 - -``` - -
- -
-``` - -``` -//xxx.js -export default { - onShow() { - var canvas = this.$refs.canvasId.getContext('2d'); - var offscreen = new OffscreenCanvas(500,500); - var offscreenCanvasCtx = offscreen.getContext("2d"); - - // ... some drawing for the canvas using the offscreenCanvasCtx ... - - var dataURL = offscreen.toDataURL(); - console.log(dataURL); //data:image/png;base64,xxxxxx - - var bitmap = offscreen.transferToImageBitmap(); - canvas.transferFromImageBitmap(bitmap); - } -} -``` - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/09.OffscreenCanvasRenderingContext2D\345\257\271\350\261\241.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/09.OffscreenCanvasRenderingContext2D\345\257\271\350\261\241.md" deleted file mode 100644 index 59430439b16df4a6557308e986f5a0d7976988ec..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/09.OffscreenCanvasRenderingContext2D\345\257\271\350\261\241.md" +++ /dev/null @@ -1,346 +0,0 @@ ---- -title: OffscreenCanvasRenderingContext2D对象 -permalink: /pages/010c0201010509 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:31 ---- -# OffscreenCanvasRenderingContext2D对象 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -使用OffscreenCanvasRenderingContext2D在offscreen canvas上进行绘制,绘制对象可以是矩形、文本、图片等 - -## 属性 - -除支持与CanvasRenderingContext2D对象相同的属性外,还支持如下属性: - - - - - - - - - - - -

属性

-

类型

-

描述

-

filter

-

string

-

设置图像的滤镜。

-

支持的滤镜效果如下:

-
  • blur:给图像设置高斯模糊
  • brightness:给图片应用一种线性乘法,使其看起来更亮或更暗
  • contrast:调整图像的对比度
  • drop-shadow:给图像设置一个阴影效果
  • grayscale:将图像转换为灰度图像
  • hue-rotate:给图像应用色相旋转
  • invert:反转输入图像
  • opacity:转化图像的透明程度
  • saturate:转换图像饱和度
  • sepia:将图像转换为深褐色
-
- -- 示例 - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow(){ - var ctx = this.$refs.canvasId.getContext('2d'); - var offscreen = new OffscreenCanvas(360, 500); - var offCanvas2 = offscreen.getContext("2d"); - var img = new Image(); - img.src = 'common/images/flower.jpg'; - offCanvas2.drawImage(img, 0, 0, 100, 100); - offCanvas2.filter = 'blur(5px)'; - offCanvas2.drawImage(img, 100, 0, 100, 100); - - offCanvas2.filter = 'grayscale(50%)'; - offCanvas2.drawImage(img, 200, 0, 100, 100); - - offCanvas2.filter = 'hue-rotate(90deg)'; - offCanvas2.drawImage(img, 0, 100, 100, 100); - - offCanvas2.filter = 'invert(100%)'; - offCanvas2.drawImage(img, 100, 100, 100, 100); - - offCanvas2.filter = 'drop-shadow(8px 8px 10px green)'; - offCanvas2.drawImage(img, 200, 100, 100, 100); - - offCanvas2.filter = 'brightness(0.4)'; - offCanvas2.drawImage(img, 0, 200, 100, 100); - - offCanvas2.filter = 'opacity(25%)'; - offCanvas2.drawImage(img, 100, 200, 100, 100); - - offCanvas2.filter = 'saturate(30%)'; - offCanvas2.drawImage(img, 200, 200, 100, 100); - - offCanvas2.filter = 'sepia(60%)'; - offCanvas2.drawImage(img, 0, 300, 100, 100); - - offCanvas2.filter = 'contrast(200%)'; - offCanvas2.drawImage(img, 100, 300, 100, 100); - var bitmap = offscreen.transferToImageBitmap(); - ctx.transferFromImageBitmap(bitmap); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/c3.png) - - -## 方法 - -除支持与CanvasRenderingContext2D对象相同的方法外,还支持如下方法: - -### isPointInPath - -isPointInPath\(path?: Path2D, x: number, y: number\): boolean - -判断指定点是否在路径的区域内。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

描述

-

path

-

Path2D

-

-

可选对象,指定用来判断的路径。若没有设置,则使用当前路径。

-

x

-

number

-

-

待判断点的x轴坐标。

-

y

-

number

-

-

待判断点的y轴坐标。

-
- -- 返回值 - - - - - - - - - -

类型

-

说明

-

boolean

-

指定点是否在路径的区域内。

-
- -- 示例 - - ``` - -
- In path:{{textValue}} - -
- ``` - - ``` - // xxx.js - export default { - data: { - textValue: 0 - }, - onShow(){ - var canvas = this.$refs.canvas.getContext('2d'); - var offscreen = new OffscreenCanvas(500,500); - var offscreenCanvasCtx = offscreen.getContext("2d"); - - offscreenCanvasCtx.rect(10, 10, 100, 100); - offscreenCanvasCtx.fill(); - this.textValue = offscreenCanvasCtx.isPointInPath(30, 70); - - var bitmap = offscreen.transferToImageBitmap(); - canvas.transferFromImageBitmap(bitmap); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001224354967.png) - - -### isPointInStroke - -isPointInStroke\(path?: Path2D, x: number, y: number\): boolean - -判断指定点是否在路径的边缘线上。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

描述

-

path

-

Path2D

-

-

可选对象,指定用来判断的路径。若没有设置,则使用当前路径。

-

x

-

number

-

-

待判断点的x轴坐标。

-

y

-

number

-

-

待判断点的y轴坐标。

-
- -- 返回值 - - - - - - - - - -

类型

-

说明

-

boolean

-

指定点是否在路径的区域内。

-
- -- 示例 - - ``` - -
- In path:{{textValue}} - -
- ``` - - ``` - // xxx.js - export default { - data: { - textValue: 0 - }, - onShow(){ - var canvas = this.$refs.canvas.getContext('2d'); - var offscreen = new OffscreenCanvas(500,500); - var offscreenCanvasCtx = offscreen.getContext("2d"); - - offscreenCanvasCtx.rect(10, 10, 100, 100); - offscreenCanvasCtx.stroke(); - this.textValue = offscreenCanvasCtx.isPointInStroke(50, 10); - - var bitmap = offscreen.transferToImageBitmap(); - canvas.transferFromImageBitmap(bitmap); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001178875308.png) - - -### resetTransform - -resetTransform\(\): void - -- 示例 - - ``` - -
- In path:{{textValue}} - -
- ``` - - ``` - //xxx.js - export default { - data:{ - textValue:0 - }, - onShow(){ - var canvas = this.$refs.canvas.getContext('2d'); - var offscreen = new OffscreenCanvas(500,500); - var offscreenCanvasCtx = offscreen.getContext("2d"); - - offscreenCanvasCtx.transform(1, 0, 1.7, 1, 0, 0); - offscreenCanvasCtx.fillStyle = 'gray'; - offscreenCanvasCtx.fillRect(40, 40, 50, 20); - offscreenCanvasCtx.fillRect(40, 90, 50, 20); - - // Non-skewed rectangles - offscreenCanvasCtx.resetTransform(); - offscreenCanvasCtx.fillStyle = 'red'; - offscreenCanvasCtx.fillRect(40, 40, 50, 20); - offscreenCanvasCtx.fillRect(40, 90, 50, 20); - - var bitmap = offscreen.transferToImageBitmap(); - canvas.transferFromImageBitmap(bitmap); - } - } - ``` - - ![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001179035242.png) - - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/06.\346\240\205\346\240\274\347\273\204\344\273\266/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/06.\346\240\205\346\240\274\347\273\204\344\273\266/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" deleted file mode 100644 index 623f2d464c278c0ccbec9221517dbe74b9696b7a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/06.\346\240\205\346\240\274\347\273\204\344\273\266/01.\345\237\272\346\234\254\346\246\202\345\277\265.md" +++ /dev/null @@ -1,57 +0,0 @@ ---- -title: 基本概念 -permalink: /pages/010c0201010601 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:31 ---- -# 基本概念 - -提供栅格布局效果,通过栅格系统进行元素布局,主要提供栅格容器组件。 - -栅格系统作为一种辅助布局的定位工具,在平面设计和网站设计都起到了很好的作用,对移动设备对界面设计有较好的借鉴作用。总结栅格系统对于移动设备的优势主要有: - -1. 给布局提供一种可循的规律,解决多尺寸多设备的动态布局问题。 - -2. 给系统提供一种统一的定位标注,保证各模块各设备的布局一致性。 - -3. 给应用提供一种灵活的间距调整方法,满足特殊场景布局调整的可能性。 - - -## 栅格系统的概念 - -栅格系统有Margins、Gutters、Columns三个属性。 - -1. Margins: - - 是用来控制元素距离屏幕最边缘的距离关系,可以根据设备的不同尺寸,定义不同的Margin值作为断点系统中的统一规范。 - -2. Gutters: - - 是用来控制元素和元素之间的距离关系,可以根据设备的不同尺寸,定义不同的Gutters值作为断点系统中的统一规范。为了保证较好的视觉效果,Gutters通常的取值不会大于Margins的取值。 - -3. Columns: - - 是用来辅助布局的主要定位工具,不同的屏幕尺寸匹配不同的Columns数量来辅助布局定位。Columns的宽度在保证Margins和Gutters符合规范的情况下,根据实际设备的宽度和Columns数量自动计算每一个Columns的宽度。![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127125136.png) - - **栅格断点系统** - - 栅格系统定义了不同水平宽度设备对应Columns的数量关系,形成了一套断点规则定义。 - - 栅格系统以水平分辨率值作为断点依据,不同的设备根据自身当前水平宽度px值\(配置了autoDesignWidth为true\)在不同的断点范围内的情况,显示不同数量的栅格数。 - - xs: 0<水平分辨率<320时:2 Columns栅格; - - sm: 320<=水平分辨率<600时:4 Columns栅格; - - md: 600<=水平分辨率<840时:8 Columns栅格; - - lg: 840<=水平分辨率时:12 Columns栅格; - - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/06.\346\240\205\346\240\274\347\273\204\344\273\266/02.grid-container.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/06.\346\240\205\346\240\274\347\273\204\344\273\266/02.grid-container.md" deleted file mode 100644 index ac9cdc312205db85be0ff59b74282375720c5c19..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/06.\346\240\205\346\240\274\347\273\204\344\273\266/02.grid-container.md" +++ /dev/null @@ -1,288 +0,0 @@ ---- -title: grid-container -permalink: /pages/010c0201010602 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:31 ---- -# grid-container - -栅格布局容器根节点,使用grid-row与grid-col进行栅格布局。 - -## 权限列表 - -无 - -## 子组件 - -仅支持。 - -## 属性 - -除支持[通用属性](/pages/010c0201010101)外,还支持如下属性: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

columns

-

string | number

-

auto

-

-

设置当前布局总列数,使用string类型时仅支持auto,配置为auto时按照当前的sizetype决定总列数:

-
  • xs:2列
  • sm:4列
  • md:8列
  • lg:12列
-

sizetype

-

string

-

auto

-

-

设置当前栅格使用的响应尺寸类型,支持xs, sm, md, lg类型,使用auto时按照当前容器大小自动选择xs, sm, md, lg类型。

-

gutter

-

<length>

-

24px

-

-

设置Gutter宽度

-

gridtemplate6+

-

string

-

default

-

-

当设置了columns和sizetype属性为auto时,可以设置栅格容器的布局模板,通过布局模块设置不同响应尺寸下的Columns、Gutters和Margins,详见可选值说明

-
- -**表 1** gridtemplate可选值说明6+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  

模板值

-

可响应的栅格断点系统

-

Columns

-

Margins(px)

-

Gutters(px)

-

默认栅格

-

default

-

xs

-

2

-

12

-

12

-

sm

-

4

-

24

-

24

-

md

-

8

-

32

-

24

-

lg

-

12

-

48

-

24

-

宫格布局栅格

-

grid

-

sm(0<设备水平分辨率<600px)

-

4

-

24

-

12

-

md

-

8

-

32

-

12

-

lg

-

12

-

48

-

12

-
- ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->- 本章中px单位是在js标签中配置了autoDesignWidth为true。6+ - -## 样式 - -除支持[通用样式](/pages/010c0201010102)外,还支持如下样式: - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

justify-content

-

string

-

flex-start

-

-

flex容器当前行的主轴对齐格式。可选项有:

-
  • flex-start:项目位于容器的开头。
  • flex-end:项目位于容器的结尾。
  • center:项目位于容器的中心。
  • space-between:项目位于各行之间留有空白的容器内。
  • space-around:项目位于各行之前、之间、之后都留有空白的容器内。
-

align-items

-

string

-

stretch

-

-

flex容器当前行的交叉轴对齐格式,可选值为:

-
  • stretch:弹性元素被在交叉轴方向被拉伸到与容器相同的高度或宽度。
  • flex-start:元素向交叉轴起点对齐。
  • flex-end:元素向交叉轴终点对齐。
  • center:元素在交叉轴居中。
-

align-content

-

string

-

flex-start

-

-

交叉轴中有额外的空间时,多行内容对齐格式,可选值为:

-
  • flex-start:所有行从交叉轴起点开始填充。第一行的交叉轴起点边和容器的交叉轴起点边对齐。接下来的每一行紧跟前一行。
  • flex-end:所有行从交叉轴末尾开始填充。最后一行的交叉轴终点和容器的交叉轴终点对齐。同时所有后续行与前一个对齐。
  • center:所有行朝向容器的中心填充。每行互相紧挨,相对于容器居中对齐。容器的交叉轴起点边和第一行的距离相等于容器的交叉轴终点边和最后一行的距离。
  • space-between:所有行在容器中平均分布。相邻两行间距相等。容器的交叉轴起点边和终点边分别与第一行和最后一行的边对齐。
  • space-around:所有行在容器中平均分布,相邻两行间距相等。容器的交叉轴起点边和终点边分别与第一行和最后一行的距离是相邻两行间距的一半。
-
- -## 事件 - -支持[通用事件](/pages/010c0201010103)。 - -## 方法 - -除支持[通用方法](/pages/010c0201010104)外,还支持如下方法: - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数

-

描述

-

getColumns

-

-

-

返回栅格容器列数

-

getColumnWidth

-

-

-

返回栅格容器column宽度

-

getGutterWidth

-

-

-

返回栅格容器gutter宽度

-

getSizeType

-

-

-

返回当前容器响应尺寸类型(xs|sm|md|lg)

-
- -## 示例 - -详见[grid-col示例](/pages/010c0201010604#section2021865273710)。 - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/06.\346\240\205\346\240\274\347\273\204\344\273\266/03.grid-row.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/06.\346\240\205\346\240\274\347\273\204\344\273\266/03.grid-row.md" deleted file mode 100644 index e78bed4033333149c0209688eaf24567bc4dff37..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/06.\346\240\205\346\240\274\347\273\204\344\273\266/03.grid-row.md" +++ /dev/null @@ -1,111 +0,0 @@ ---- -title: grid-row -permalink: /pages/010c0201010603 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:31 ---- -# grid-row - -grid-row是栅格布局容器grid-container的子容器组件,使用flex横向布局,排列每个grid-col容器,justify-content与align-items默认为flex-start,支持折行显示。 - -## 权限列表 - -无 - -## 子组件 - -仅支持。 - -## 属性 - -支持[通用属性](/pages/010c0201010101)。 - -## 样式 - -除支持[通用样式](/pages/010c0201010102)外,还支持如下样式: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

flex-wrap

-

string

-

nowrap

-

-

flex容器是单行还是多行显示,该值暂不支持动态修改。可选项有:

-
  • nowrap:不换行,单行显示。
  • wrap:换行,多行显示。
-

justify-content

-

string

-

flex-start

-

-

flex容器当前行的主轴对齐格式。可选项有:

-
  • flex-start:项目位于容器的开头。
  • flex-end:项目位于容器的结尾。
  • center:项目位于容器的中心。
  • space-between:项目位于各行之间留有空白的容器内。
  • space-around:项目位于各行之前、之间、之后都留有空白的容器内。
-

align-items

-

string

-

flex-start

-

-

flex容器当前行的交叉轴对齐格式,可选值为:

-
  • stretch:弹性元素被在交叉轴方向被拉伸到与容器相同的高度或宽度。
  • flex-start:元素向交叉轴起点对齐。
  • flex-end:元素向交叉轴终点对齐。
  • center:元素在交叉轴居中。
-

align-content

-

string

-

flex-start

-

-

交叉轴中有额外的空间时,多行内容对齐格式,可选值为:

-
  • flex-start:所有行从交叉轴起点开始填充。第一行的交叉轴起点边和容器的交叉轴起点边对齐。接下来的每一行紧跟前一行。
  • flex-end:所有行从交叉轴末尾开始填充。最后一行的交叉轴终点和容器的交叉轴终点对齐。同时所有后续行与前一个对齐。
  • center:所有行朝向容器的中心填充。每行互相紧挨,相对于容器居中对齐。容器的交叉轴起点边和第一行的距离相等于容器的交叉轴终点边和最后一行的距离。
  • space-between:所有行在容器中平均分布。相邻两行间距相等。容器的交叉轴起点边和终点边分别与第一行和最后一行的边对齐。
  • space-around:所有行在容器中平均分布,相邻两行间距相等。容器的交叉轴起点边和终点边分别与第一行和最后一行的距离是相邻两行间距的一半。
-
- ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->不支持宽度相关样式。 - -## 事件 - -支持[通用事件](/pages/010c0201010103)。 - -## 方法 - -支持[通用方法](/pages/010c0201010104)。 - -## 示例 - -详见[grid-col示例](/pages/010c0201010604#section2021865273710)。 - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/06.\346\240\205\346\240\274\347\273\204\344\273\266/04.grid-col.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/06.\346\240\205\346\240\274\347\273\204\344\273\266/04.grid-col.md" deleted file mode 100644 index 11e288b0aa239283ad0f351b70af3692a2fd6728..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/06.\346\240\205\346\240\274\347\273\204\344\273\266/04.grid-col.md" +++ /dev/null @@ -1,317 +0,0 @@ ---- -title: grid-col -permalink: /pages/010c0201010604 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:31 ---- -# grid-col - -grid-col是栅格布局容器grid-row的子容器组件。 - -## 权限列表 - -无 - -## 子组件 - -支持。 - -## 属性 - -除支持[通用属性](/pages/010c0201010101)外,还支持如下属性: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

xs

-

number|object

-

-

-

-

在分辨率为xs模式下,设置该项占用列数与偏移列数,当值为number类型时,仅设置列数,也可通过object同时设置占用列数与偏移列数,如{"span": 1, "offset": 0}

-

sm

-

number|object

-

-

-

-

在分辨率为sm模式下,该项占用列数与偏移列数,当值为number类型时,仅设置列数,也可通过object同时设置占用列数与偏移列数,如{"span": 1, "offset": 0}

-

md

-

number|object

-

-

-

-

在分辨率为md模式下,该项占用列数与偏移列数,当值为number类型时,仅设置列数,也可通过object同时设置占用列数与偏移列数,如{"span": 1, "offset": 0}

-

lg

-

number|object

-

-

-

-

在分辨率为lg模式下,该项占用列数与偏移列数,当值为number类型时,仅设置列数,也可通过object同时设置占用列数与偏移列数,如{"span": 1, "offset": 0}

-

span

-

number

-

1

-

-

在未设置明确断点时,默认占用列数

-

offset

-

number

-

0

-

-

未设置具体分辨率模式下偏移时,当前元素延容器布局方向,默认偏移的列数

-
- -## 样式 - -除支持[通用样式](/pages/010c0201010102)外,还支持如下样式: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

flex-direction

-

string

-

row

-

-

flex容器主轴方向。可选项有:

-
  • column:垂直方向从上到下
  • row:水平方向从左到右
-

flex-wrap

-

string

-

nowrap

-

-

flex容器是单行还是多行显示,该值暂不支持动态修改。可选项有:

-
  • nowrap:不换行,单行显示。
  • wrap:换行,多行显示。
-

justify-content

-

string

-

flex-start

-

-

flex容器当前行的主轴对齐格式。可选项有:

-
  • flex-start:项目位于容器的开头。
  • flex-end:项目位于容器的结尾。
  • center:项目位于容器的中心。
  • space-between:项目位于各行之间留有空白的容器内。
  • space-around:项目位于各行之前、之间、之后都留有空白的容器内。
-

align-items

-

string

-

stretch

-

-

flex容器当前行的交叉轴对齐格式,可选值为:

-
  • stretch:弹性元素被在交叉轴方向被拉伸到与容器相同的高度或宽度。
  • flex-start:元素向交叉轴起点对齐。
  • flex-end:元素向交叉轴终点对齐。
  • center:元素在交叉轴居中。
-

align-content

-

string

-

flex-start

-

-

交叉轴中有额外的空间时,多行内容对齐格式,可选值为:

-
  • flex-start:所有行从交叉轴起点开始填充。第一行的交叉轴起点边和容器的交叉轴起点边对齐。接下来的每一行紧跟前一行。
  • flex-end:所有行从交叉轴末尾开始填充。最后一行的交叉轴终点和容器的交叉轴终点对齐。同时所有后续行与前一个对齐。
  • center:所有行朝向容器的中心填充。每行互相紧挨,相对于容器居中对齐。容器的交叉轴起点边和第一行的距离相等于容器的交叉轴终点边和最后一行的距离。
  • space-between:所有行在容器中平均分布。相邻两行间距相等。容器的交叉轴起点边和终点边分别与第一行和最后一行的边对齐。
  • space-around:所有行在容器中平均分布,相邻两行间距相等。容器的交叉轴起点边和终点边分别与第一行和最后一行的距离是相邻两行间距的一半。
-

display

-

string

-

flex

-

-

确定该元素视图框的类型,该值暂不支持动态修改。可选值为:

-
  • flex:弹性布局
  • grid:网格布局
  • none:不渲染此元素
-

grid-template-[columns|rows]

-

string

-

1行1列

-

-

用于设置当前网格布局行和列的数量,不设置时默认1行1列,仅当display为grid时生效。

-

示例:如设置grid-template-columns为:

-

(1) 50px 100px 60px:分三列,第一列50px,第二列100px,第三列60px;

-

(2) 1fr 1fr 2fr:分三列,将父组件允许的宽分为4等份,第一列占1份,第二列占一份,第三列占2份;

-

(3) 30% 20% 50%:分三列,将父组件允许的宽为基准,第一列占30%,第二列占20%,第三列占50%;

-

(4) repeat(2,100px):分两列,第一列100px,第二列100px;

-

(5) auto 1fr 1fr:分三列,第一列自适应内部子组件所需宽度,剩余空间分为两等份,第二列占一份,第三列占一份。

-

grid-[columns|rows]-gap

-

<length>

-

0

-

-

用于设置行与行的间距或者列与列的间距,也可以支持通过grid-gap设置相同的行列间距,仅当display为grid时生效。

-

grid-row-[start|end]

-

number

-

-

-

-

用于设置当前元素在网格布局中的起止行号,仅当父组件display样式为grid时生效(仅div支持display样式设置为grid)。

-

grid-column-[start|end]

-

number

-

-

-

-

用于设置当前元素在网格布局中的起止列号,仅当父组件display样式为grid时生效(仅div支持display样式设置为grid)。

-
- ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->不支持宽度相关样式。 - -## 事件 - -支持[通用事件](/pages/010c0201010103)。 - -## 方法 - -支持[通用方法](/pages/010c0201010104)。 - -## 示例 - -``` - -
- - - -
- Element text -
-
- -
- Element text -
-
-
-
-
-``` - -``` -/* index.css */ -.container { - flex-direction: column; - padding-top: 80px; -} -``` - -``` -// index.js -import prompt from '@system.prompt'; -export default { - getCol(e) { - this.$element('mygrid').getColumns(function (result) { - prompt.showToast({ - message: e.target.id + ' result = ' + result, - duration: 3000, - }); - }) - }, - getColWidth(e) { - this.$element('mygrid').getColumnWidth(function (result) { - prompt.showToast({ - message: e.target.id + ' result = ' + result, - duration: 3000, - }); - }) - } -} -``` - -![](/images/application-dev/reference/arkui-js/figures/grid.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/01.\351\200\232\347\224\250\345\261\236\346\200\247.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/01.\351\200\232\347\224\250\345\261\236\346\200\247.md" deleted file mode 100644 index 80a758bc0f02554516a4ab09bb7d013cde2d67cb..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/01.\351\200\232\347\224\250\345\261\236\346\200\247.md" +++ /dev/null @@ -1,188 +0,0 @@ ---- -title: 通用属性 -permalink: /pages/010c0201010701 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:31 ---- -# 通用属性 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

fill

-

<color>

-

black

-

-

使用简写属性设置元素的填充色。支持属性动画。

-

fill-opacity

-

number

-

1

-

-

填充色的透明度,取值范围为0到1,1表示为不透明,0表示为完全透明。支持属性动画。

-

fill-rule

-

nonzero | evenodd

-

nonzero

-

-

nonzero:非零规则; evenodd:奇偶规则

-

opacity

-

number

-

1

-

-

元素的透明度,取值范围为0到1,1表示为不透明,0表示为完全透明。支持属性动画。

-

stroke

-

<color>

-

-

-

-

设置形状轮廓的颜色。支持属性动画。

-

stroke-dasharray

-

<string>

-

-

-

-

指定短划线和缺口的长度。格式为[length length length length],短划线和缺口的长度中间空格隔开成对出现。

-

stroke-dashoffset

-

<length>

-

0

-

-

设置关联虚线数组渲染时的偏移量。支持属性动画

-

stroke-linejoin

-

[bevel | miter | round]

-

miter

-

-

进行描边时在路径的拐角处使用的形状。

-

bevel:使用斜角连接路径段;

-

miter:使用尖角连接路径段;

-

round:使用圆角连接路径段。

-

stroke-linecap

-

[butt | round | square]

-

butt

-

-

路径描边时在它们的结尾处使用的形状。

-

butt:不在路径两端扩展;

-

round:在路径的末端延伸半个圆,直径等于线度。

-

square:在路径的末端延伸半个圆,宽度等于线宽的一半,高度等于线宽。

-

stroke-miterlimit

-

number

-

4

-

-

设置将锐角绘制成斜角的极限值。支持属性动画

-

stroke-opacity

-

number

-

1

-

-

轮廓线条的透明度,取值范围为0到1,1表示为不透明,0表示为完全透明。支持属性动画

-

stroke-width

-

<length>

-

1px

-

-

设置轮廓线条的宽度。支持属性动画

-

transform

-

<string>

-

-

-

-

设置组件以及子组件的坐标变换参数。

-

支持以下格式:

-

translate(<x> [<y>]) :沿x[y]轴方向平移

-

scale(<x> [<y>]) :沿x[y]轴缩放

-

rotate(<a> [<x> <y>]) :以(x,y)点进行旋转a度角

-

skewX(<a>) :沿x轴倾斜a度角的变换

-

skewY(<a>) :沿y轴倾斜a度角的变换

-
- diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/02.svg.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/02.svg.md" deleted file mode 100644 index 80086e2268901daaba0c62043d9f4886f3b811d3..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/02.svg.md" +++ /dev/null @@ -1,135 +0,0 @@ ---- -title: svg -permalink: /pages/010c0201010702 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:31 ---- -# svg - -基础容器,主要作为svg的根节点使用,也可以在svg中嵌套使用。 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->- 该组件从API version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 ->- svg父组件或者svg组件需要定义宽高值,否则不进行绘制。 - -## 权限列表 - -无 - -## 子组件 - -支持svg、rect、circle、ellipse、path、line、polygon、polyline、text、animate、animateTransform。 - -## 属性 - -支持Svg组件[通用属性](/pages/010c0201010701)和以下属性,设置的通用属性会传递给子组件。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

id

-

string

-

-

-

-

组件的唯一标识。

-

width

-

<length>|<percentage>

-

-

-

-

设置组件的宽度

-

height

-

<length>|<percentage>

-

-

-

-

设置组件的高度

-

x

-

<length>|<percentage>

-

-

-

-

设置当前svg的x轴坐标,根svg节点无效

-

y

-

<length>|<percentage>

-
  

-

设置当前svg的y轴坐标,根svg节点无效

-

viewBox

-

string

-

-

-

-

设置当前svg的视口。支持的格式为<number number number number>,4个参数分别表示min-x, min-y, width and height,viewBox的宽高和svg的宽高不一致,会以中心对齐进行缩放。

-
- -## 示例 - -``` - -
- - - - - - - - - - - - -
-``` - -![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173164789.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/03.rect.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/03.rect.md" deleted file mode 100644 index d42327f00238c3ad0adc84cac16e064e97bfb414..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/03.rect.md" +++ /dev/null @@ -1,141 +0,0 @@ ---- -title: rect -permalink: /pages/010c0201010703 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:32 ---- -# rect - -用于绘制矩形、圆角矩形。 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 权限列表 - -无 - -## 子组件 - -支持animate、animateMotion、animateTransform。 - -## 属性 - -支持Svg组件[通用属性](/pages/010c0201010701)和以下属性。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

id

-

string

-

-

-

-

组件的唯一标识。

-

width

-

<length>|<percentage>

-

0

-

-

设置矩形的宽度。支持属性动画

-

height

-

<length>|<percentage>

-

0

-

-

设置矩形的高度。支持属性动画

-

x

-

<length>|<percentage>

-

0

-

-

设置矩形左上角x轴坐标。支持属性动画

-

y

-

<length>|<percentage>

-

0

-

-

设置矩形左上角y轴坐标。支持属性动画

-

rx

-

<length>|<percentage>

-

0

-

-

设置矩形圆角x方向半径。支持属性动画

-

ry

-

<length>|<percentage>

-

0

-

-

设置矩形圆角y方向半径。支持属性动画

-
- -## 示例 - -``` - -
- - - - - - - -
-``` - -![](/images/application-dev/reference/arkui-js/figures/0.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/04.circle.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/04.circle.md" deleted file mode 100644 index 139e6c551df12a2014bb1b94d0c97efdec343411..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/04.circle.md" +++ /dev/null @@ -1,105 +0,0 @@ ---- -title: circle -permalink: /pages/010c0201010704 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:32 ---- -# circle - -圆形形状。 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 权限列表 - -无 - -## 子组件 - -支持animate、animateMotion、animateTransform。 - -## 属性 - -支持Svg组件[通用属性](/pages/010c0201010701)和以下属性。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

id

-

string

-

-

-

-

组件的唯一标识。

-

cx

-

<length>|<percentage>

-

0

-

-

设置圆心的x轴坐标。支持属性动画

-

cy

-

<length>|<percentage>

-

0

-

-

设置圆心的y轴坐标。支持属性动画

-

r

-

<length>|<percentage>

-

0

-

-

设置圆的半径。支持属性动画

-
- -## 示例 - -``` - -
- - - - -
-``` - -![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173164853.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/05.ellipse.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/05.ellipse.md" deleted file mode 100644 index 0e829b257e5fb78e75405ef8da9f5adc3609498c..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/05.ellipse.md" +++ /dev/null @@ -1,116 +0,0 @@ ---- -title: ellipse -permalink: /pages/010c0201010705 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:32 ---- -# ellipse - -椭圆形状。 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 权限列表 - -无 - -## 子组件 - -支持animate、animateMotion、animateTransform。 - -## 属性 - -支持Svg组件[通用属性](/pages/010c0201010701)和以下属性。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

id

-

string

-

-

-

-

组件的唯一标识。

-

cx

-

<length>|<percentage>

-

0

-

-

设置椭圆的x轴坐标。支持属性动画

-

cy

-

<length>|<percentage>

-

0

-

-

设置椭圆的y轴坐标。支持属性动画

-

rx

-

<length>|<percentage>

-

0

-

-

设置椭圆x轴的半径。支持属性动画

-

ry

-

<length>|<percentage>

-

0

-

-

设置椭圆y轴的半径。支持属性动画

-
- -## 示例 - -``` - -
- - - - -
-``` - -![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173164793.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/06.path.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/06.path.md" deleted file mode 100644 index f9c5646f926c4bbc454efd3655eca15c076d698d..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/06.path.md" +++ /dev/null @@ -1,86 +0,0 @@ ---- -title: path -permalink: /pages/010c0201010706 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:32 ---- -# path - -绘制路径。 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 权限列表 - -无 - -## 子组件 - -支持animate、animateMotion、animateTransform。 - -## 属性 - -支持Svg组件[通用属性](/pages/010c0201010701)和以下属性,设置的通用属性会传递给子组件。 - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

id

-

string

-

-

-

-

组件的唯一标识。

-

d

-

string

-

-

-

-

设置路径的形状。包含一组字符指令,大写字母为绝对路径,小写字符为相对路径。

-

字母指令表示的意义如下:

-
  • M/m = moveto
  • L/l = lineto
  • H/h = horizontal lineto
  • V/v = vertical lineto
  • C/c = curveto
  • S/s = smooth curveto
  • Q/q = quadratic Belzier curve
  • T/t = smooth quadratic Belzier curveto
  • A/a = elliptical Arc
  • Z/z = closepath
-
- -## 示例 - -``` - -
- - - - -
-``` - -![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173164891.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/07.line.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/07.line.md" deleted file mode 100644 index 2ba4d312d74509761c351417b2b8d5683ba9569a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/07.line.md" +++ /dev/null @@ -1,120 +0,0 @@ ---- -title: line -permalink: /pages/010c0201010707 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:32 ---- -# line - -绘制线条。 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 权限列表 - -无 - -## 子组件 - -支持animate、animateMotion、animateTransform。 - -## 属性 - -支持所列的Svg组件通用属性和以下表格的属性。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

id

-

string

-

-

-

-

组件的唯一标识。

-

x1

-

<length>|<percentage>

-

-

-

-

设置线条起点的x轴坐标。支持属性动画

-

y1

-

<length>|<percentage>

-

-

-

-

设置线条起点的y轴坐标。支持属性动画

-

x2

-

<length>|<percentage>

-

-

-

-

设置线条终点的x轴坐标。支持属性动画

-

y2

-

<length>|<percentage>

-

-

-

-

设置线条终点的y轴坐标。支持属性动画

-
- -## 示例 - -``` - -
- - - - - - - - -
-``` - -![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001127284954.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/08.polyline.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/08.polyline.md" deleted file mode 100644 index 40363dfe1536ca2e5c4e548726e91eaa301a7aa2..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/08.polyline.md" +++ /dev/null @@ -1,85 +0,0 @@ ---- -title: polyline -permalink: /pages/010c0201010708 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:32 ---- -# polyline - -绘制折线。 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 权限列表 - -无 - -## 子组件 - -支持animate、animateMotion、animateTransform。 - -## 属性 - -支持所列的Svg组件通用属性和以下表格的属性。 - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

id

-

string

-

-

-

-

组件的唯一标识。

-

points

-

string

-

-

-

-

设置折线的多个坐标点

-

格式为[x1,y1 x2,y2 x3,y3]。

-

支持属性动画,如果属性动画里设置的动效变化值的坐标个数与原始points的格式不一样,则无效

-
- -## 示例 - -``` - -
- - - - -
-``` - -![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173164845.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/09.polygon.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/09.polygon.md" deleted file mode 100644 index b8955d13e509c3e1df0e8e456d20b9839023a587..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/09.polygon.md" +++ /dev/null @@ -1,85 +0,0 @@ ---- -title: polygon -permalink: /pages/010c0201010709 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:32 ---- -# polygon - -绘制多边形。 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 权限列表 - -无 - -## 子组件 - -支持animate、animateMotion、animateTransform。 - -## 属性 - -支持Svg组件[通用属性](/pages/010c0201010701)和以下属性。 - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

id

-

string

-

-

-

-

组件的唯一标识。

-

points

-

string

-

-

-

-

设置多边形的多个坐标点

-

格式为[x1,y1 x2,y2 x3,y3]。

-

支持属性动画,如果属性动画里设置的动效变化值的坐标个数与原始points的格式不一样,则无效

-
- -## 示例 - -``` - -
- - - - -
-``` - -![](/images/application-dev/reference/arkui-js/figures/zh-cn_image_0000001173324721.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/10.text.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/10.text.md" deleted file mode 100644 index d7faee04b7a14afa6d7e1a7d90bbcf4ffb89f52a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/10.text.md" +++ /dev/null @@ -1,289 +0,0 @@ ---- -title: text -permalink: /pages/010c020101070a -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:32 ---- -# text - -文本,用于呈现一段信息。 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->- 该组件从API version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 ->- 文本的展示内容需要写在元素标签内,可嵌套tspan子元素标签分段,可嵌套textPath子元素标签按指定路径绘制。 ->- 只支持被父元素标签svg嵌套。 ->- 只支持默认字体sans-serif。 - -## 权限列表 - -无 - -## 子组件 - -支持tspan、textpath、animate、animateTransform。 - -## 属性 - -支持以下表格中的属性。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

id

-

string

-

-

-

-

组件的唯一标识。

-

x

-

<length>|<percentage>

-

0

-

-

设置组件左上角x轴坐标

-

y

-

<length>|<percentage>

-

0

-

-

设置组件左上角y轴坐标

-

dx

-

<length>|<percentage>

-

0

-

-

设置文本x轴偏移

-

dy

-

<length>|<percentage>

-

0

-

-

设置文本y轴偏移

-

rotate

-

number

-

0

-

-

字体以左下角为圆心旋转角度,正数顺时针,负数逆时针

-

font-size

-

<length>

-

30px

-

-

设置文本的尺寸。

-

fill

-

<color>

-

black

-

-

字体填充颜色

-

fill-opacity

-

number

-

1.0

-

-

字体填充透明度

-

opacity

-

number

-

1

-

-

元素的透明度,取值范围为0到1,1表示为不透明,0表示为完全透明。支持属性动画。

-

stroke

-

<color>

-

black

-

-

绘制字体边框并指定颜色

-

stroke-width

-

number

-

1px

-

-

字体边框宽度

-

stroke-opacity

-

number

-

1.0

-

-

字体边框透明度

-
- -## 示例 - -``` -/* xxx.css */ -.container { - flex-direction: row; - justify-content: flex-start; - align-items: flex-start; - height: 1000px; - width: 1080px; -} -``` - -``` - -
- - test x|y - test x|y - test opacity - test dx|dy|fill|font-size - test fill-opacity - test 0123456789 - test 中文 - test rotate - test stroke - test stroke-opacity - -
-``` - -![](/images/application-dev/reference/arkui-js/figures/text-part1.png) - -属性动画示例 - -``` -/* xxx.css */ -.container { - flex-direction: row; - justify-content: flex-start; - align-items: flex-start; - height: 3000px; - width: 1080px; -} -``` - -``` - -
- - - - - - text attribute x|opacity|rotate - - -
-``` - -![](/images/application-dev/reference/arkui-js/figures/text-animate-part1.gif) - -``` - -
- - - text attribute font-size - - - - -
-``` - -![](/images/application-dev/reference/arkui-js/figures/text-animate-part2.gif) - -``` - -
- - - text attribute stroke - - - - text attribute stroke-width-opacity - - - - -
-``` - -![](/images/application-dev/reference/arkui-js/figures/text-animate-part3.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/11.tspan.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/11.tspan.md" deleted file mode 100644 index 0d1b8cdd0c2d62afafd41ab53f7c71216f8da023..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/11.tspan.md" +++ /dev/null @@ -1,317 +0,0 @@ ---- -title: tspan -permalink: /pages/010c020101070b -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:32 ---- -# tspan - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->- 该组件从API version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 ->- 文本的展示内容需要写在元素标签内,可嵌套子元素标签tspan分段。 ->- 文本分段,只支持被父元素标签svg嵌套。 - -## 权限列表 - -无 - -## 子组件 - -支持tspan。 - -支持以下表格中的属性。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

id

-

string

-

-

-

-

组件的唯一标识。

-

x

-

<length>|<percentage>

-

0

-

-

设置组件左上角x轴坐标

-

y

-

<length>|<percentage>

-

0

-

-

设置组件左上角y轴坐标。作为textpath子组件时失效。

-

dx

-

<length>|<percentage>

-

0

-

-

设置文本x轴偏移

-

dy

-

<length>|<percentage>

-

0

-

-

设置文本y轴偏移。作为textpath子组件时失效。

-

rotate

-

number

-

0

-

-

字体以左下角为圆心旋转角度,正数顺时针,负数逆时针

-

font-size

-

<length>

-

30px

-

-

设置文本的尺寸。

-

fill

-

<color>

-

black

-

-

字体填充颜色

-

opacity

-

number

-

1

-

-

元素的透明度,取值范围为0到1,1表示为不透明,0表示为完全透明。支持属性动画。

-

fill-opacity

-

number

-

1.0

-

-

字体填充透明度

-

stroke

-

<color>

-

black

-

-

绘制字体边框并指定颜色

-

stroke-width

-

number

-

1px

-

-

字体边框宽度

-

stroke-opacity

-

number

-

1.0

-

-

字体边框透明度

-
- -## 示例 - -``` -/* xxx.css */ -.container { - flex-direction: row; - justify-content: flex-start; - align-items: flex-start; - height: 1000px; - width: 1080px; -} -``` - -``` - -
- - - zero text. - first span. - second span. - third span. - - - first span. - second span. - third span. - forth span. - - -
-``` - -![](/images/application-dev/reference/arkui-js/figures/tspan-part1.png) - -属性动画示例 - -``` -/* xxx.css */ -.container { - flex-direction: row; - justify-content: flex-start; - align-items: flex-start; - height: 3000px; - width: 1080px; -} -``` - -``` - -
- - - - tspan attribute x|opacity|rotate - - - - - - - - - tspan attribute dx - - - - -
-``` - -![](/images/application-dev/reference/arkui-js/figures/tspan-animate-part1.gif) - -``` - -
- - - - tspan attribute fill|fill-opacity - - - - - -
-``` - -![](/images/application-dev/reference/arkui-js/figures/tspan-animate-part2.gif) - -``` - -
- - - - tspan attribute font-size - - - - -
-``` - -![](/images/application-dev/reference/arkui-js/figures/tspan-animate-part3.gif) - -``` - -
- - - - tspan attribute stroke - - - - - - tspan attribute stroke-width-opacity - - - - - -
-``` - -![](/images/application-dev/reference/arkui-js/figures/tspan-animate-part4.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/12.textPath.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/12.textPath.md" deleted file mode 100644 index ee180453be6cf0f130c54ba25b02a02b9bb9de15..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/12.textPath.md" +++ /dev/null @@ -1,404 +0,0 @@ ---- -title: textPath -permalink: /pages/010c020101070c -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:32 ---- -# textPath - -沿路径绘制文本。 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->- 该组件从API version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 ->- 按指定的路径绘制文本,可嵌套子标签tspan分段。 ->- 只支持被父元素标签text嵌套。 - -## 权限列表 - -无 - -## 子组件 - -tspan。 - -## 属性 - -支持以下表格中的属性。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

id

-

string

-

-

-

-

组件的唯一标识。

-

path

-

string

-

0

-

-

设置路径的形状。

-

字母指令表示的意义如下:

-
  • M = moveto
  • L = lineto
  • H = horizontal lineto
  • V = vertical lineto
  • C = curveto
  • S = smooth curveto
  • Q = quadratic Belzier curve
  • T = smooth quadratic Belzier curveto
  • A = elliptical Arc
  • Z = closepath
-

startOffset

-

<length>|<percentage>

-

0

-

-

设置文本沿path绘制的起始偏移。

-

font-size

-

<length>

-

30px

-

-

设置文本的尺寸。

-

fill

-

<color>

-

black

-

-

字体填充颜色

-

by

-

number

-

-

-

-

相对被指定动画的属性偏移值,from默认为原属性值。

-

opacity

-

number

-

1

-

-

元素的透明度,取值范围为0到1,1表示为不透明,0表示为完全透明。支持属性动画。

-

fill-opacity

-

number

-

1.0

-

-

字体填充透明度

-

stroke

-

<color>

-

black

-

-

绘制字体边框并指定颜色

-

stroke-width

-

number

-

1px

-

-

字体边框宽度

-

stroke-opacity

-

number

-

1.0

-

-

字体边框透明度

-
- -## 示例 - -textspan属性示例,textpath文本内容沿着属性path中的路径绘制文本,起点偏移20%的path长度。(绘制的元素曲线仅做参照) - -``` -/* xxx.css */ -.container { - flex-direction: row; - justify-content: flex-start; - align-items: flex-start; - height: 1200px; - width: 600px; -} -``` - -``` - -
- - - - - This is textpath test. - - - -
-``` - -![](/images/application-dev/reference/arkui-js/figures/textPath-part1.png) - -textpath与tspan组合示例与效果图 - -``` - -
- - - - - This is tspan onTextPath. - Let's play. - 12345678912354567891234567891234567891234567891234567890 - - - -
-``` - -![](/images/application-dev/reference/arkui-js/figures/textPath-part2.png) - -``` - -
- - - - - This is TextPath. - This is tspan onTextPath. - Let's play. - 12345678912354567891234567891234567891234567891234567890 - - - - -
-``` - -![](/images/application-dev/reference/arkui-js/figures/textPath-part3.png) - -``` - -
- - - - - - - This is TextPath. - This is first tspan. - This is second tspan. - 12345678912354567891234567891234567891234567891234567890 - - - -
-``` - -![](/images/application-dev/reference/arkui-js/figures/textPath-part4.png) - -startOffset属性动画,文本绘制时起点偏移从10%运动到40%,不绘制超出path长度范围的文本。 - -``` -/* xxx.css */ -.container { - flex-direction: row; - justify-content: flex-start; - align-items: flex-start; - height: 3000px; - width: 1080px; -} -``` - -``` - -
- - - - - This is tspan onTextPath. - Let's play. - 12345678912354567891234567891234567891234567891234567890 - - - - -
-``` - -![](/images/application-dev/reference/arkui-js/figures/textpath-animate1.gif) - -textpath与tspan组合属性动画与效果图 - -``` - -
- - - - - - This is TextPath. - - tspan attribute x|rotate - - - - tspan static. - - tspan attribute dx|opacity - - - - tspan move - - - -
-``` - -![](/images/application-dev/reference/arkui-js/figures/textpath-animate2.gif) - -\(1\) "tspan attribute x|rotate" 文本绘制起点偏移从50px运动到100px,顺时针旋转0度到360度。 - -\(2\) "tspan attribute dx|opacity" 在 "tspan static." 绘制结束后再开始绘制,向后偏移量从0%运动到30%,透明度从浅到深变化。 - -\(3\) "tspan move" 在上一段tspan绘制完成后,向后偏移5%的距离进行绘制,呈现跟随前一段tspan运动的效果。 - -textpath与tspan组合属性动画与效果图 - -``` - -
- - - - - - This is TextPath. - - tspan attribute fill|fill-opacity - - - - - tspan attribute font-size - - - - Single tspan - - -
-``` - -![](/images/application-dev/reference/arkui-js/figures/textpath-animate3.gif) - -\(1\) "This is TextPath." 在path上无偏移绘制第一段文本内容,大小30px,颜色"\#D2691E"。 - -\(2\) "tspan attribute fill|fill-opacity" 相对上一段文本结束后偏移20px,颜色从蓝到红,透明度从浅到深。 - -\(3\) "tspan attribute font-size" 绘制起点相对上一段结束后偏移20px,起点静止,字体大小从10px到50px,整体长度持续拉长。 - -\(4\) "Single tspan" 在上一段的尾部做水平绘制,呈现跟随上一段运动的效果。 - -textpath与tspan组合属性动画与效果图 - -``` - -
- - - - - - This is TextPath. - - tspan attribute stroke - - - - tspan attribute stroke-width-opacity - - - - - - -
-``` - -![](/images/application-dev/reference/arkui-js/figures/textpath-animate4.gif) - -\(1\) "tspan attribute stroke" 轮廓颜色从红色逐渐转变成绿色。 - -\(2\) "tspan attribute stroke-width-opacity" 轮廓宽度从细1px转变粗5px,透明度从浅到深。 - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/13.animate.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/13.animate.md" deleted file mode 100644 index 879144d45e0c5ef8454be2d57223a7ee03fcd234..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/13.animate.md" +++ /dev/null @@ -1,282 +0,0 @@ ---- -title: animate -permalink: /pages/010c020101070d -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:32 ---- -# animate - -设置svg组件的属性动画。 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 权限列表 - -无 - -## 子组件 - -不支持。 - -## 属性 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

id

-

string

-

-

-

-

组件的唯一标识。

-

attributeName

-

string

-

-

-

-

设置需要进行动效的属性名。

-

begin

-

<time>

-

0

-

-

设置动效的延迟时间。

-

支持输入ms(毫秒)、s(秒)、m(分),默认为s(秒),其他格式不支持

-

dur

-

<time>

-

0

-

-

设置动效持续时间,如果dur没设置,按照end-begin的结果作为持续时间,小于等于0时,动效不触发。

-

支持输入ms(毫秒)、s(秒)、m(分),默认为s(秒),其他格式不支持

-

end

-

<time>

-

0

-

-

设置动效多久时间后结束。支持输入ms(毫秒)、s(秒)、m(分),默认为s(秒),其他格式不支持

-

repeatCount

-

<number | indefinite>

-

1

-

-

设置动画播放的次数,默认无限次播放(indefinite),可通过设置为数值1仅播放一次。

-

fill

-

<freeze | remove>

-

remove

-

-

设置动画结束时的状态。

-

calcMode

-

<discrete | linear | paced | spline>

-

linear

-

-

设置动画的插值模式。

-

discrete:阶跃,from值直接跳转到to的值;

-

linear:线性;

-

paced:线性,设置此项后keyTimes和keyPoints值无效

-

spline:自定义贝塞尔曲线,spline点定义在keyTimes属性中,每个时间间隔控制点由keySplines定义

-

keyTimes

-

string

-

-

-

-

设置关键帧动画的开始时间,值为0~1之间的数值用分号隔开,比如0;0.3;0.8;1。keyTimes、keySplines、values组合设置关键帧动画。keyTimes和values的个数保持一致。keySplines个数为keyTimes个数减一

-

keySplines

-

string

-

-

-

-

与keyTimes相关联的一组贝塞尔控制点。定义每个关键帧的贝塞尔曲线,曲线之间用分号隔开。曲线内的两个控制掉格式为x1 y1 x2 y2。比如0.5 0 0.5 1; 0.5 0 0.5 1;0.5 0 0.5 1

-

by

-

number

-

-

-

-

在动画中对某一指定属性,添加相对偏移值,from默认为原属性值。

-

from

-

string

-

-

-

-

设置需要进行动画的属性的开始值。

-

如果已经设置了values属性,则from失效。

-

to

-

string

-

-

-

-

设置需要进行动画的属性的结束值。

-

如果已经设置了values属性,则to都失效。

-

values

-

string

-

-

-

-

设置一组动画的变化值。格式为value1;value2;value3。

-
- -## 示例 - -``` - -
- - - - - - -
-``` - -![](/images/application-dev/reference/arkui-js/figures/animate-1.gif) - -``` - -
- - - - - - -
-``` - -![](/images/application-dev/reference/arkui-js/figures/1-3.gif) - -``` - -
- - - - - -
-``` - -![](/images/application-dev/reference/arkui-js/figures/animate-3.gif) - -``` - -
- - - - - - - - - - - - - - - - - - - - - - - - -
-``` - -![](/images/application-dev/reference/arkui-js/figures/animate-4.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/14.animateMotion.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/14.animateMotion.md" deleted file mode 100644 index a0295426a6dbfffd996cffa4e2dcf1c1c9945621..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/14.animateMotion.md" +++ /dev/null @@ -1,106 +0,0 @@ ---- -title: animateMotion -permalink: /pages/010c020101070e -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:32 ---- -# animateMotion - -路径动效。 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 权限列表 - -无 - -## 子组件 - -不支持。 - -## 属性 - -支持animate属性\(values不生效\)和以下表格中的属性。 - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

keyPoints

-

string

-

-

-

-

一组关键帧的点位置,每帧的值为对象沿路径的距离比例。功能与animate属性中的values相同。

-

path

-

string

-

-

-

-

定义运动的路径,使用与path组件d属性相同的语法。

-

rotate

-

[auto | auto-reverse | <number>]

-

auto

-

-

-

设置动画对象的旋转方向

-
- -## 示例 - -``` - -
- - - - - - - - - - - - - - - - -
-``` - -![](/images/application-dev/reference/arkui-js/figures/2-4.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/15.animateTransform.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/15.animateTransform.md" deleted file mode 100644 index 2b12e81dfb987c378dbf1db905fbb1711f6a858d..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/07.svg\347\273\204\344\273\266/15.animateTransform.md" +++ /dev/null @@ -1,245 +0,0 @@ ---- -title: animateTransform -permalink: /pages/010c020101070f -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:32 ---- -# animateTransform - -transform动效,支持的组件范围: - -, , , , , , , - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 权限列表 - -无 - -## 子组件 - -不支持。 - -## 属性 - -支持animate属性和以下表格中的属性。 - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

必填

-

描述

-

type

-

[translate | scale | rotate | skewX | skewY]

-

-

-

-

设置transform动画的类型

-
- -## 示例 - -``` - -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - justify-content: flex-start; - align-items: flex-start; - background-color: #f8f8ff; -} - -.back_container { - flex-direction: row; - justify-content: flex-start; - align-items: flex-start; - height: 1000px; - width: 1080px; -} -``` - -![](/images/application-dev/reference/arkui-js/figures/animate-transform.gif) - -动画叠加 - -``` - -
-
- - - - - - - - - - - - - - - - - - -
-
-``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - justify-content: flex-start; - align-items: flex-start; - background-color: #f8f8ff; -} -.back_container { - flex-direction: row; - justify-content: flex-start; - align-items: flex-start; - height: 1000px; - width: 1080px; -} -``` - -![](/images/application-dev/reference/arkui-js/figures/animate-transform2.gif) - -涉及组件示例 - -``` - -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-``` - -``` -/* xxx.css */ -.container { - flex-direction: column; - justify-content: flex-start; - align-items: flex-start; - background-color: #f8f8ff; -} -.back_container { - flex-direction: row; - justify-content: flex-start; - align-items: flex-start; - height: 1000px; - width: 1080px; -} -``` - -![](/images/application-dev/reference/arkui-js/figures/animate-transform3.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\350\207\252\345\256\232\344\271\211\347\273\204\344\273\266/01.\345\237\272\346\234\254\347\224\250\346\263\225.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\350\207\252\345\256\232\344\271\211\347\273\204\344\273\266/01.\345\237\272\346\234\254\347\224\250\346\263\225.md" deleted file mode 100644 index 7da37cbe8a7eb991de568b476dd186cafb68c469..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\350\207\252\345\256\232\344\271\211\347\273\204\344\273\266/01.\345\237\272\346\234\254\347\224\250\346\263\225.md" +++ /dev/null @@ -1,77 +0,0 @@ ---- -title: 基本用法 -permalink: /pages/010c02010201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:32 ---- -# 基本用法 - -自定义组件是用户根据业务需求,将已有的组件组合,封装成的新组件,可以在工程中多次调用,从而提高代码的可读性。自定义组件通过element引入到宿主页面,使用方法如下: - -``` - -
- -
-``` - -结合if-else使用自定义组件的示例: - -``` - - -
- - -
-``` - -- name属性指自定义组件名称\(非必填\),组件名称对大小写不敏感,默认使用小写。src属性指自定义组件hml文件路径\(必填\),若没有设置name属性,则默认使用hml文件名作为组件名。 -- 事件绑定:自定义组件中绑定子组件事件使用\(on|@\)child1语法,子组件中通过this.$emit\('child1', \{ params: '传递参数' \}\)触发事件并进行传值,父组件执行bindParentVmMethod方法并接收子组件传递的参数。 - - >![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** - >子组件中使用驼峰命名法命名的事件,在父组件中绑定时需要使用短横线分隔命名形式,例如:@children-event表示绑定子组件的childrenEvent事件,如 @children-event="bindParentVmMethod"。 - - -**表 1** 对象 - - - - - - - - - - - - - - - - - - - -

属性

-

类型

-

描述

-

data

-

Object/Function

-

页面的数据模型,类型是对象或者函数,如果类型是函数,返回值必须是对象。属性名不能以$或_开头,不要使用保留字for, if, show, tid。

-

data与private和public不能重合使用。(Rich)

-

props

-

Array/Object

-

props用于组件之间的通信,可以通过<tag xxxx='value'>方式传递给组件;props名称必须用小写,不能以$或_开头,不要使用保留字for, if, show, tid。目前props的数据类型不支持Function。

-

computed

-

Object

-

计算属性,用于在读取或设置时,进行预先处理,其结果会被缓存。计算属性名不能以$或_开头,不要使用保留字。

-
- diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\350\207\252\345\256\232\344\271\211\347\273\204\344\273\266/02.\350\207\252\345\256\232\344\271\211\344\272\213\344\273\266.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\350\207\252\345\256\232\344\271\211\347\273\204\344\273\266/02.\350\207\252\345\256\232\344\271\211\344\272\213\344\273\266.md" deleted file mode 100644 index b6e1c4d34d05798d4c8fa040ca6540fddf3b4ed1..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\350\207\252\345\256\232\344\271\211\347\273\204\344\273\266/02.\350\207\252\345\256\232\344\271\211\344\272\213\344\273\266.md" +++ /dev/null @@ -1,81 +0,0 @@ ---- -title: 自定义事件 -permalink: /pages/010c02010202 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:32 ---- -# 自定义事件 - -子组件comp定义如下: - -``` - -
- 点击这里查看隐藏文本 - hello world -
-``` - -``` -/* comp.css */ -.item { - width: 700px; - flex-direction: column; - height: 300px; - align-items: center; - margin-top: 100px; -} -.text-style { - font-weight: 500; - font-family: Courier; - font-size: 40px; -} -``` - -``` -// comp.js -export default { - data: { - showObj: false, - }, - childClicked () { - this.$emit('eventType1'); - this.showObj = !this.showObj; - }, -} -``` - -引入子组件的示例如下: - -``` - - -
- -
-``` - -``` -/* xxx.css */ -.container { - background-color: #f8f8ff; - flex: 1; - flex-direction: column; - align-content: center; -} -``` - -``` -// xxx.js -export default { - textClicked () {}, -} -``` - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\350\207\252\345\256\232\344\271\211\347\273\204\344\273\266/03.Props.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\350\207\252\345\256\232\344\271\211\347\273\204\344\273\266/03.Props.md" deleted file mode 100644 index 8af5755aaae6aaa3fb137623805d1fd390cbd258..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\350\207\252\345\256\232\344\271\211\347\273\204\344\273\266/03.Props.md" +++ /dev/null @@ -1,146 +0,0 @@ ---- -title: Props -permalink: /pages/010c02010203 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:32 ---- -# Props - -自定义组件可以通过props声明属性,父组件通过设置属性向子组件传递参数,props支持类型包括:String,Number,Boolean,Array,Object,Function。camelCase \(驼峰命名法\) 的 prop 名,在外部父组件传递参数时需要使用 kebab-case \(短横线分隔命名\) 形式,即当属性compProp在父组件引用时需要转换为comp-prop。给自定义组件添加props,通过父组件向下传递参数的示例如下: - -``` - -
- {{compProp}} -
-``` - -``` -// comp.js -export default { - props: ['compProp'], -} -``` - -``` - - -
- -
-``` - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->自定义属性命名时禁止以on、@、on:、grab: 等保留关键字为开头。 - -## 添加默认值 - -子组件可以通过固定值default设置默认值,当父组件没有设置该属性时,将使用其默认值。此情况下props属性必须为对象形式,不能用数组形式,示例如下: - -``` - -
- {{title}} -
-``` - -``` -// comp.js -export default { - props: { - title: { - default: 'title', - }, - }, -} -``` - -本示例中加入了一个text组件显示标题,标题的内容是一个自定义属性,显示用户设置的标题内容,当用户没有设置时显示默认值title。在引用该组件时添加该属性的设置: - -``` - - -
- -
-``` - -## 数据单向性 - -父子组件之间数据的传递是单向的,只能从父组件传递给子组件,子组件不能直接修改父组件传递下来的值,可以将props传入的值用data接收后作为默认值,再对data的值进行修改。 - -``` -// comp.js -export default { - props: ['defaultCount'], - data() { - return { - count: this.defaultCount, - }; - }, - onClick() { - this.count = this.count + 1; - }, -} -``` - -## $watch 感知数据改变 - -如果需要观察组件中属性变化,可以通过$watch方法增加属性变化回调。使用方法如下: - -``` -// comp.js -export default { - props: ['title'], - onInit() { - this.$watch('title', 'onPropertyChange'); - }, - onPropertyChange(newV, oldV) { - console.info('title 属性变化 ' + newV + ' ' + oldV); - }, -} -``` - -## computed 计算属性 - -自定义组件中经常需要在读取或设置某个属性时进行预先处理,提高开发效率,此种情况就需要使用computed字段。computed字段中可通过设置属性的getter和setter方法在属性读写的时候进行触发,使用方式如下: - -``` -// comp.js -export default { - props: ['title'], - data() { - return { - objTitle: this.title, - time: 'Today', - }; - }, - computed: { - message() { - return this.time + ' ' + this.objTitle; - }, - notice: { - get() { - return this.time; - }, - set(newValue) { - this.time = newValue; - }, - }, - }, - onClick() { - console.info('get click event ' + this.message); - this.notice = 'Tomorrow'; - }, -} -``` - -这里声明的第一个计算属性message默认只有getter函数,message的值会取决于objTitle的值的变化。getter函数只能读取不能改变设值,当需要赋值给计算属性的时候可以提供一个setter函数,如示例中的notice。 - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\350\207\252\345\256\232\344\271\211\347\273\204\344\273\266/04.\344\272\213\344\273\266\345\217\202\346\225\260.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\350\207\252\345\256\232\344\271\211\347\273\204\344\273\266/04.\344\272\213\344\273\266\345\217\202\346\225\260.md" deleted file mode 100644 index d68b7705843d711616f907b4f79f81275f72a446..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\350\207\252\345\256\232\344\271\211\347\273\204\344\273\266/04.\344\272\213\344\273\266\345\217\202\346\225\260.md" +++ /dev/null @@ -1,57 +0,0 @@ ---- -title: 事件参数 -permalink: /pages/010c02010204 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:32 ---- -# 事件参数 - -子组件也可以通过绑定的事件向上传递参数,在自定义事件上添加传递参数的示例如下: - -``` - -
- 点击这里查看隐藏文本 - hello world -
-``` - -``` -// comp.js -export default { - childClicked () { - this.$emit('eventType1', {text: '收到子组件参数'}); - this.showObj = !this.showObj; - }, -} -``` - -子组件向上传递参数text,父组件接收时通过e.detail来获取参数: - -``` - -
- 父组件:{{text}} - -
-``` - -``` -// xxx.js -export default { - data: { - text: '开始', - }, - textClicked (e) { - this.text = e.detail.text; - }, -} -``` - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\350\207\252\345\256\232\344\271\211\347\273\204\344\273\266/05.slot\346\217\222\346\247\275.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\350\207\252\345\256\232\344\271\211\347\273\204\344\273\266/05.slot\346\217\222\346\247\275.md" deleted file mode 100644 index 38ab40a61186d7d7aa68c834adb339e9d532832e..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\350\207\252\345\256\232\344\271\211\347\273\204\344\273\266/05.slot\346\217\222\346\247\275.md" +++ /dev/null @@ -1,71 +0,0 @@ ---- -title: slot插槽 -permalink: /pages/010c02010205 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:32 ---- -# slot插槽 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 7 开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 默认插槽 - -自定义组件中通过slot标签来承载父组件中定义的内容,使用slot标签可以更加灵活的控制自定义组件的内容元素,使用方式如下: - -``` - -
- 下面使用父组件定义的内容 - -
-``` - -引用该自定义组件方式如下: - -``` - - -
- - 父组件中定义的内容 - -
-``` - -## 具名插槽 - -当自定义组件中需要使用多个插槽时,可通过对插槽命名的方式进行区分,当填充插槽内容时,通过声明插槽名称,将内容加到对应的插槽中。 - -``` - -
- 下面使用父组件定义的内容 - - -
-``` - -引用该自定义组件方式如下: - -``` - - -
- - 插入第二个插槽中 - 插入第一个插槽中 - -
-``` - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->name 和 slot 属性不支持绑定动态数据。 - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\350\207\252\345\256\232\344\271\211\347\273\204\344\273\266/06.\347\224\237\345\221\275\345\221\250\346\234\237\345\256\232\344\271\211.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\350\207\252\345\256\232\344\271\211\347\273\204\344\273\266/06.\347\224\237\345\221\275\345\221\250\346\234\237\345\256\232\344\271\211.md" deleted file mode 100644 index f99181e5cce40f2599cea5d3ed19d156a688a5a2..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/02.\350\207\252\345\256\232\344\271\211\347\273\204\344\273\266/06.\347\224\237\345\221\275\345\221\250\346\234\237\345\256\232\344\271\211.md" +++ /dev/null @@ -1,129 +0,0 @@ ---- -title: 生命周期定义 -permalink: /pages/010c02010206 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:32 ---- -# 生命周期定义 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 5 开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -我们为自定义组件提供了一系列生命周期回调方法,便于开发者管理自定义组件的内部逻辑。生命周期主要包括:onInit,onAttached,onDetached,onLayoutReady,onDestroy,onPageShow和onPageHide。下面我们依次介绍一下各个生命周期回调的时机。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

属性

-

类型

-

描述

-

触发时机

-

onInit

-

Function

-

初始化自定义组件

-

自定义组件初始化生命周期回调,当自定义组件创建时,触发该回调,主要用于自定义组件中必须使用的数据初始化,该回调只会触发一次调用。

-

onAttached

-

Function

-

自定义组件装载

-

自定义组件被创建后,加入到Page组件树时,触发该回调,该回调触发时,表示组件将被进行显示,该生命周期可用于初始化显示相关数据,通常用于加载图片资源、开始执行动画等场景。

-

onLayoutReady

-

Function

-

自定义组件布局完成

-

自定义组件插入Page组件树后,将会对自定义组件进行布局计算,调整其内容元素尺寸与位置,当布局计算结束后触发该回调。

-

onDetached

-

Function

-

自定义组件摘除

-

自定义组件摘除时,触发该回调,常用于停止动画或异步逻辑停止执行的场景。

-

onDestroy

-

Function

-

自定义组件销毁

-

自定义组件销毁时,触发该回调,常用于资源释放。

-

onPageShow

-

Function

-

自定义组件Page显示

-

自定义组件所在Page显示后,触发该回调。

-

onPageHide

-

Function

-

自定义组件Page隐藏

-

自定义组件所在Page隐藏后,触发该回调。

-
- -## 示例 - -``` - -
- {{value}} -
-``` - -``` -//comp.js -export default { - data: { - value: "组件创建" - }, - onInit() { - console.log("组件创建") - }, - onAttached() { - this.value = "组件挂载" - }, - onDetached() { - this.value = "" - }, - onPageShow() { - console.log("Page显示") - }, - onPageHide() { - console.log("Page隐藏") - } -} -``` - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/03.\351\231\204\345\275\225/01.\347\261\273\345\236\213\350\257\264\346\230\216.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/03.\351\231\204\345\275\225/01.\347\261\273\345\236\213\350\257\264\346\230\216.md" deleted file mode 100644 index 07048d28efcbebaf45d12621b69a6c081ae2a443..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/01.\345\237\272\344\272\216JS\346\211\251\345\261\225\347\232\204\347\261\273Web\345\274\200\345\217\221\350\214\203\345\274\217/03.\351\231\204\345\275\225/01.\347\261\273\345\236\213\350\257\264\346\230\216.md" +++ /dev/null @@ -1,1108 +0,0 @@ ---- -title: 类型说明 -permalink: /pages/010c02010301 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:32 ---- -# 类型说明 - -## 长度类型 - - - - - - - - - - - - - - - -

名称

-

类型定义

-

描述

-

length

-

string | number

-

用于描述尺寸单位,输入为number类型时,使用px单位;输入为string类型时,需要显式指定像素单位,当前支持的像素单位有:

-
  • px:逻辑尺寸单位。
  • fp6+:字体尺寸单位,会随系统字体大小设置发生变化,仅支持文本类组件设置相应的字体大小。
-

percentage

-

string

-

百分比尺寸单位,如“50%”。

-
- -## 颜色类型 - - - - - - - - - - - -

名称

-

类型定义

-

描述

-

color

-

string | 颜色枚举字符串

-

用于描述颜色信息。

-
字符串格式如下:
  • 'rgb(255, 255, 255)'
  • 'rgba(255, 255, 255, 1.0)'
  • HEX格式:'#rrggbb','#aarrggbb'
  • 枚举格式:'black','white'。
    说明:

    JS脚本中不支持颜色枚举格式。

    -
    -
-
-
- -**表 1** 当前支持的颜色枚举 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

枚举名称

-

对应颜色

-

颜色

-

aliceblue

-

#f0f8ff

-

-

antiquewhite

-

#faebd7

-

-

aqua

-

#00ffff

-

-

aquamarine

-

#7fffd4

-

-

azure

-

#f0ffff

-

-

beige

-

#f5f5dc

-

-

bisque

-

#ffe4c4

-

-

black

-

#000000

-

-

blanchedalmond

-

#ffebcd

-

-

blue

-

#0000ff

-

-

blueviolet

-

#8a2be2

-

-

brown

-

#a52a2a

-

-

burlywood

-

#deB887

-

-

cadetblue

-

#5f9ea0

-

-

chartreuse

-

#7fff00

-

-

chocolate

-

#d2691e

-

-

coral

-

#ff7f50

-

-

cornflowerblue

-

#6495ed

-

-

cornsilk

-

#fff8dc

-

-

crimson

-

#dc143c

-

-

cyan

-

#00ffff

-

-

darkblue

-

#00008b

-

-

darkcyan

-

#008b8b

-

-

darkgoldenrod

-

#b8860b

-

-

darkgray

-

#a9a9a9

-

-

darkgreen

-

#006400

-

-

darkgrey

-

#a9a9a9

-

-

darkkhaki

-

#bdb76b

-

-

darkmagenta

-

#8b008b

-

-

darkolivegreen

-

#556b2f

-

-

darkorange

-

#ff8c00

-

-

darkorchid

-

#9932cc

-

-

darkred

-

#8b0000

-

-

darksalmon

-

#e9967a

-

-

darkseagreen

-

#8fbc8f

-

-

darkslateblue

-

#483d8b

-

-

darkslategray

-

#2f4f4f

-

-

darkslategrey

-

#2f4f4f

-

-

darkturquoise

-

#00ced1

-

-

darkviolet

-

#9400d3

-

-

deeppink

-

#ff1493

-

-

deepskyblue

-

#00bfff

-

-

dimgray

-

#696969

-

-

dimgrey

-

#696969

-

-

dodgerblue

-

#1e90ff

-

-

firebrick

-

#b22222

-

-

floralwhite

-

#fffaf0

-

-

forestgreen

-

#228b22

-

-

fuchsia

-

#ff00ff

-

-

gainsboro

-

#dcdcdc

-

-

ghostwhite

-

#f8f8ff

-

-

gold

-

#ffd700

-

-

goldenrod

-

#daa520

-

-

gray

-

#808080

-

-

green

-

#008000

-

-

greenyellow

-

#adff2f

-

-

grey

-

#808080

-

-

honeydew

-

#f0fff0

-

-

hotpink

-

#ff69b4

-

-

indianred

-

#cd5c5c

-

-

indigo

-

#4b0082

-

-

ivory

-

#fffff0

-

-

khaki

-

#f0e68c

-

-

lavender

-

#e6e6fa

-

-

lavenderblush

-

#fff0f5

-

-

lawngreen

-

#7cfc00

-

-

lemonchiffon

-

#fffacd

-

-

lightblue

-

#add8e6

-

-

lightcoral

-

#f08080

-

-

lightcyan

-

#e0ffff

-

-

lightgoldenrodyellow

-

#fafad2

-

-

lightgray

-

#d3d3d3

-

-

lightgreen

-

#90ee90

-

-

lightpink

-

#ffb6c1

-

-

lightsalmon

-

#ffa07a

-

-

lightseagreen

-

#20b2aa

-

-

lightskyblue

-

#87cefa

-

-

lightslategray

-

#778899

-

-

lightslategrey

-

#778899

-

-

lightsteelblue

-

#b0c4de

-

-

lightyellow

-

#ffffe0

-

-

lime

-

#00ff00

-

-

limegreen

-

#32cd32

-

-

linen

-

#faf0e6

-

-

magenta

-

#ff00ff

-

-

maroon

-

#800000

-

-

mediumaquamarine

-

#66cdaa

-

-

mediumblue

-

#0000cd

-

-

mediumorchid

-

#ba55d3

-

-

mediumpurple

-

#9370db

-

-

mediumseagreen

-

#3cb371

-

-

mediumslateblue

-

#7b68ee

-

-

mediumspringgreen

-

#00fa9a

-

-

mediumturquoise

-

#48d1cc

-

-

mediumvioletred

-

#c71585

-

-

midnightblue

-

#191970

-

-

mintcream

-

#f5fffa

-

-

mistyrose

-

#ffe4e1

-

-

moccasin

-

#ffe4b5

-

-

navajowhite

-

#ffdead

-

-

navy

-

#000080

-

-

oldlace

-

#fdf5e6

-

-

olive

-

#808000

-

-

olivedrab

-

#6b8e23

-

-

orange

-

#ffa500

-

-

orangered

-

#ff4500

-

-

orchid

-

#da70d6

-

-

palegoldenrod

-

#eee8aa

-

-

palegreen

-

#98fb98

-

-

paleturquoise

-

#afeeee

-

-

palevioletred

-

#db7093

-

-

papayawhip

-

#ffefd5

-

-

peachpuff

-

#ffdab9

-

-

peru

-

#cd853f

-

-

pink

-

#ffc0cb

-

-

plum

-

#dda0dd

-

-

powderblue

-

#b0e0e6

-

-

purple

-

#800080

-

-

rebeccapurple

-

#663399

-

-

red

-

#ff0000

-

-

rosybrown

-

#bc8f8f

-

-

royalblue

-

#4169e1

-

-

saddlebrown

-

#8b4513

-

-

salmon

-

#fa8072

-

-

sandybrown

-

#f4a460

-

-

seagreen

-

#2e8b57

-

-

seashell

-

#fff5ee

-

-

sienna

-

#a0522d

-

-

silver

-

#c0c0c0

-

-

skyblue

-

#87ceeb

-

-

slateblue

-

#6a5acd

-

-

slategray

-

#708090

-

-

slategrey

-

#708090

-

-

snow

-

#fffafa

-

-

springgreen

-

#00ff7f

-

-

steelblue

-

#4682b4

-

-

tan

-

#d2b48c

-

-

teal

-

#008080

-

-

thistle

-

#d8Bfd8

-

-

tomato

-

#ff6347

-

-

turquoise

-

#40e0d0

-

-

violet

-

#ee82ee

-

-

wheat

-

#f5deb3

-

-

white

-

#ffffff

-

-

whitesmoke

-

#f5f5f5

-

-

yellow

-

#ffff00

-

-

yellowgreen

-

#9acd32

-

-
diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/01.\351\200\232\347\224\250\344\272\213\344\273\266/01.\347\202\271\345\207\273\344\272\213\344\273\266.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/01.\351\200\232\347\224\250\344\272\213\344\273\266/01.\347\202\271\345\207\273\344\272\213\344\273\266.md" deleted file mode 100644 index fdad9dc721a85a94c2783e1a29c2eac890dad7b7..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/01.\351\200\232\347\224\250\344\272\213\344\273\266/01.\347\202\271\345\207\273\344\272\213\344\273\266.md" +++ /dev/null @@ -1,211 +0,0 @@ ---- -title: 点击事件 -permalink: /pages/010c020201010101 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:32 ---- -# 点击事件 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 权限列表 - -无 - -## 事件 - - - - - - - - - - - -

名称

-

支持冒泡

-

功能描述

-

onClick(callback: (event?: ClickEvent) => void)

-

-

点击动作触发该方法调用,event参数见ClickEvent介绍。

-
- -- ClickEvent对象说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

属性名称

-

类型

-

描述

-

screenX

-

number

-

点击点相对于设备屏幕左边沿的X坐标。

-

screenY

-

number

-

点击点相对于设备屏幕上边沿的Y坐标。

-

x

-

number

-

点击点相对于被点击元素左边沿的X坐标。

-

y

-

number

-

点击点相对于被点击元素上边沿的Y坐标。

-

target8+

-

EventTarget

-

被点击元素对象。

-

timestamp

-

number

-

事件时间戳。

-
- -- EventTarget对象说明8+ - - - - - - - - - - - -

名称

-

参数类型

-

描述

-

area

-

Area

-

目标元素的区域信息。

-
- -- Area对象说明8+ - - - - - - - - - - - - - - - - - - - - - - - -

属性名称

-

类型

-

描述

-

width

-

Length

-

目标元素的宽度。

-

height

-

Length

-

目标元素的高度。

-

pos

-

Position

-

目标元素左上角相对父元素左上角的位置。

-

globalPos

-

Position

-

目标元素左上角相对页面左上角的位置。

-
- -- Position对象说明8+ - - - - - - - - - - - - - - - -

属性名称

-

参数类型

-

描述

-

x

-

Length

-

x轴坐标。

-

y

-

Length

-

y轴坐标。

-
- - -## 示例 - -``` -@Entry -@Component -struct ClickExample { - @State text: string = '' - - build() { - Column() { - Button('Click').backgroundColor(0x2788D9).width(100).height(40) - .onClick((event: ClickEvent) => { - console.info(this.text = 'Click Point:' + '\n screenX:' + event.screenX + '\n screenY:' + event.screenY - + '\n x :' + event.x + '\n y:' + event.y + '\ntarget:' + '\n component globalPos:(' - + event.target.area.globalPos.x + ',' + event.target.area.globalPos.y + ')\n width:' - + event.target.area.width + '\n height:' + event.target.area.height) - }) - Text(this.text).padding(15) - }.height(350).width('100%').padding(10) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355087.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/01.\351\200\232\347\224\250\344\272\213\344\273\266/02.\350\247\246\346\221\270\344\272\213\344\273\266.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/01.\351\200\232\347\224\250\344\272\213\344\273\266/02.\350\247\246\346\221\270\344\272\213\344\273\266.md" deleted file mode 100644 index 2171229cd11944cb085e48e5874391e2d8a5dd99..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/01.\351\200\232\347\224\250\344\272\213\344\273\266/02.\350\247\246\346\221\270\344\272\213\344\273\266.md" +++ /dev/null @@ -1,233 +0,0 @@ ---- -title: 触摸事件 -permalink: /pages/010c020201010102 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:32 ---- -# 触摸事件 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 权限列表 - -无 - -## 事件 - - - - - - - - - - - -

名称

-

是否冒泡

-

功能描述

-

onTouch(callback: (event?: TouchEvent) => void)

-

-

触摸动作触发该方法调用,event参数见TouchEvent介绍。

-
- -## TouchEvent对象说明 - -- 属性 - - - - - - - - - - - - - - - - - - - - - - - - - - - -

属性名称

-

类型

-

描述

-

type

-

TouchType

-

触摸事件的类型。

-

touches

-

Array<TouchObject>

-

全部手指信息。

-

changedTouches

-

Array<TouchObject>

-

当前发生变化的手指信息。

-

timestamp

-

number

-

事件时间戳。

-

target8+

-

EventTarget

-

被触摸元素对象。

-
- - -- 接口 - - - - - - - - - -

接口名称

-

功能描述

-

stopPropagation():void

-

阻塞事件冒泡。

-
- - -- TouchObject对象说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

属性名称

-

类型

-

描述

-

type

-

TouchType

-

触摸事件的类型。

-

id

-

number

-

手指唯一标识符。

-

screenX

-

number

-

触摸点相对于设备屏幕左边沿的X坐标。

-

screenY

-

number

-

触摸点相对于设备屏幕上边沿的Y坐标。

-

x

-

number

-

触摸点相对于被触摸元素左边沿的X坐标。

-

y

-

number

-

触摸点相对于被触摸元素上边沿的Y坐标。

-
- - -- TouchType枚举说明 - - - - - - - - - - - - - - - - - - -

名称

-

描述

-

Down

-

手指按下时触发。

-

Up

-

手指抬起时触发。

-

Move

-

手指按压态在屏幕上移动时触发。

-

Cancel

-

触摸事件取消时触发。

-
- - -## 示例 - -``` -@Entry -@Component -struct TouchExample { - @State text: string = '' - @State eventType: string = '' - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) { - Button('Touch').backgroundColor(0x2788D9).height(40).width(80) - .onTouch((event: TouchEvent) => { - if (event.type === TouchType.Down) { - this.eventType = 'Down' - } - if (event.type === TouchType.Up) { - this.eventType = 'Up' - } - if (event.type === TouchType.Move) { - this.eventType = 'Move' - } - console.info(this.text = 'TouchType:' + this.eventType + '\nDistance between touch point and touch element:\nx: ' - + event.touches[0].x + '\n' + 'y: ' + event.touches[0].y + '\ncomponent globalPos:(' - + event.target.area.globalPos.x + ',' + event.target.area.globalPos.y + ')\nwidth:' - + event.target.area.width + '\nheight:' + event.target.area.height) - }) - Text(this.text) - }.height(200).width(350).padding({ left: 35, right: 35, top: 35 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915178.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/01.\351\200\232\347\224\250\344\272\213\344\273\266/03.\346\214\202\350\275\275\345\215\270\350\275\275\344\272\213\344\273\266.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/01.\351\200\232\347\224\250\344\272\213\344\273\266/03.\346\214\202\350\275\275\345\215\270\350\275\275\344\272\213\344\273\266.md" deleted file mode 100644 index 849802f9570e9e11a8ce87ece0a69bebdda96b23..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/01.\351\200\232\347\224\250\344\272\213\344\273\266/03.\346\214\202\350\275\275\345\215\270\350\275\275\344\272\213\344\273\266.md" +++ /dev/null @@ -1,85 +0,0 @@ ---- -title: 挂载卸载事件 -permalink: /pages/010c020201010103 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:32 ---- -# 挂载卸载事件 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 权限列表 - -无 - -## 事件 - - - - - - - - - - - - - - - -

名称

-

支持冒泡

-

功能描述

-

onAppear(callback: () => void)

-

-

组件挂载显示时触发此回调。

-

onDisappear(callback: () => void)

-

-

组件卸载消失时触发此回调。

-
- -## 示例 - -``` -import prompt from '@system.prompt' - -@Entry -@Component -struct AppearExample { - @State isShow: boolean = true - private myText: string = 'Text for onAppear' - private changeAppear: string = 'Hide Text' - - build() { - Column() { - Button(this.changeAppear) - .onClick(() => { - this.isShow = !this.isShow - }).margin(3).backgroundColor(0x2788D9) - if (this.isShow) { - Text(this.myText) - .onAppear(() => { - this.changeAppear = 'Show Text' - prompt.showToast({ message: 'The text is shown', duration: 2000 }) - }) - .onDisAppear(() => { - this.changeAppear = 'Hide Text' - prompt.showToast({ message: 'The text is hidden', duration: 2000 }) - }) - } - }.padding(30).width('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/appear.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/01.\351\200\232\347\224\250\344\272\213\344\273\266/04.\346\214\211\351\224\256\344\272\213\344\273\266.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/01.\351\200\232\347\224\250\344\272\213\344\273\266/04.\346\214\211\351\224\256\344\272\213\344\273\266.md" deleted file mode 100644 index 6f2c9ad8a312d3aa3cd275e414953bcce6adf375..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/01.\351\200\232\347\224\250\344\272\213\344\273\266/04.\346\214\211\351\224\256\344\272\213\344\273\266.md" +++ /dev/null @@ -1,258 +0,0 @@ ---- -title: 按键事件 -permalink: /pages/010c020201010104 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:32 ---- -# 按键事件 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 权限列表 - -无 - -## 事件 - - - - - - - - - - - -

名称

-

支持冒泡

-

功能描述

-

onKeyEvent(event: (event?: KeyEvent) => void)

-

-

按键动作触发该方法调用,event参数见KeyEvent介绍。

-
- -## KeyEvent对象说明 - -- 属性 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

属性名称

-

类型

-

描述

-

type

-

KeyType

-

按键的类型。

-

keyCode

-

number

-

按键的键码。

-

keyText

-

string

-

按键的键值。

-

keySource

-

KeySource

-

触发当前按键的输入设备类型。

-

deviceId

-

number

-

触发当前按键的输入设备ID。

-

metaKey

-

number

-

按键发生时元键的状态,1表示按压态,0表示未按压态。

-

timestamp

-

number

-

按键发生时的时间戳。

-
- - -- 接口 - - - - - - - - - -

接口名称

-

功能描述

-

stopPropagation(): void

-

阻塞事件冒泡传递。

-
- -- KeyType枚举说明 - - - - - - - - - - - - -

名称

-

描述

-

Down

-

按键按下。

-

Up

-

按键松开。

-
- - -- KeySource枚举说明 - - - - - - - - - - - - -

名称

-

描述

-

Unknown

-

输入设备类型未知。

-

Keyboard

-

输入设备类型为键盘。

-
- -- 常用KeyCode说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

数值

-

行为

-

物理按键

-

19

-

-

向上方向键。

-

20

-

-

向下方向键。

-

21

-

-

向左方向键。

-

22

-

-

向右方向键。

-

23

-

确定

-

遥控器的确认键。

-

66

-

确定

-

键盘的回车键。

-

160

-

确定

-

键盘的小键盘回车键。

-
- - -## 示例 - -``` -@Entry -@Component -struct KeyEventExample { - @State text: string = '' - @State eventType: string = '' - - build() { - Column() { - Button('KeyEvent').backgroundColor(0x2788D9) - .onKeyEvent((event: KeyEvent) => { - if (event.type === KeyType.Down) { - this.eventType = 'Down' - } - if (event.type === KeyType.Up) { - this.eventType = 'Up' - } - console.info(this.text = 'KeyType:' + this.eventType + '\nkeyCode:' + event.keyCode + '\nkeyText:' + event.keyText) - }) - Text(this.text).padding(15) - }.height(300).width('100%').padding(35) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/KeyEvent.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/01.\351\200\232\347\224\250\344\272\213\344\273\266/05.\347\273\204\344\273\266\345\214\272\345\237\237\345\217\230\345\214\226\344\272\213\344\273\266.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/01.\351\200\232\347\224\250\344\272\213\344\273\266/05.\347\273\204\344\273\266\345\214\272\345\237\237\345\217\230\345\214\226\344\272\213\344\273\266.md" deleted file mode 100644 index 2eedbd5627767516b53b9707a15cb0af3ed1fce2..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/01.\351\200\232\347\224\250\344\272\213\344\273\266/05.\347\273\204\344\273\266\345\214\272\345\237\237\345\217\230\345\214\226\344\272\213\344\273\266.md" +++ /dev/null @@ -1,71 +0,0 @@ ---- -title: 组件区域变化事件 -permalink: /pages/010c020201010105 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:32 ---- -# 组件区域变化事件 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 权限列表 - -无 - -## 事件 - - - - - - - - - - - -

名称

-

支持冒泡

-

功能描述

-

onAreaChange(event: (oldValue: Area, newValue: Area) => void)

-

-

组件区域变化时触发该回调,Area类型说明见Area对象介绍。

-
- -## 示例 - -``` -@Entry -@Component -struct AreaExample { - @State value: string = 'Text' - @State size: string = '' - - build() { - Column() { - Text(this.value) - .backgroundColor(Color.Green).margin(30).fontSize(20) - .onClick(() => { - this.value = this.value + 'Text' - }) - .onAreaChange((oldValue: Area, newValue: Area) => { - console.info(`Ace: on area change, oldValue is ${JSON.stringify(oldValue)} value is ${JSON.stringify(newValue)}`) - this.size = JSON.stringify(newValue) - }) - Text('new area is: \n' + this.size).margin({ right: 30, left: 30 }) - } - .width('100%').height('100%').margin({ top: 30 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/GIF4.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/01.\345\260\272\345\257\270\350\256\276\347\275\256.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/01.\345\260\272\345\257\270\350\256\276\347\275\256.md" deleted file mode 100644 index 645427de05e0b200f6ac1e864370db44fd76e4f8..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/01.\345\260\272\345\257\270\350\256\276\347\275\256.md" +++ /dev/null @@ -1,166 +0,0 @@ ---- -title: 尺寸设置 -permalink: /pages/010c020201010201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:32 ---- -# 尺寸设置 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 权限列表 - -无 - -## 属性 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数说明

-

默认值

-

描述

-

width

-

Length

-

-

-

设置组件自身的宽度,缺省时使用元素自身内容需要的宽度。

-

height

-

Length

-

-

-

设置组件自身的高度,缺省时使用元素自身内容需要的高度。

-

size

-

{

-

width?: Length,

-

height?: Length

-

}

-

-

-

设置高宽尺寸。

-

padding

-

{

-

top?: Length,

-

right?: Length,

-

bottom?: Length,

-

left?: Length

-

} | Length

-

0

-

设置内边距属性。

-

参数为Length类型时,四个方向内边距同时生效。

-

margin

-

{

-

top?: Length,

-

right?: Length,

-

bottom?: Length,

-

left?: Length

-

}

-

| Length

-

0

-

设置外边距属性。

-

参数为Length类型时,四个方向外边距同时生效。

-

constraintSize

-

{

-

minWidth?: Length,

-

maxWidth?: Length,

-

minHeight?: Length,

-

maxHeight?: Lenght

-

}

-

{

-

minWidth: 0,

-

maxWidth: Infinity,

-

minHeight: 0,

-

maxHeight: Infinity

-

}

-

设置约束尺寸,组件布局时,进行尺寸范围限制。

-

layoutWeight

-

number

-

0

-

容器尺寸确定时,元素与兄弟节点主轴布局尺寸按照权重进行分配,忽略本身尺寸设置。

-
说明:

仅在Row/Column/Flex布局中生效。

-
-
- -## 示例 - -``` -@Entry -@Component -struct SizeExample { - build() { - Column({ space: 10 }) { - Text('margin and padding:').fontSize(12).fontColor(0xCCCCCC).width('90%') - // 宽度80 ,高度80 ,内外边距20 - Row() { - Row() { - Row().size({ width: '100%', height: '100%' }).backgroundColor(0xAFEEEE) - }.width(80).height(80).padding(20).margin(20).backgroundColor(0xFDF5E6) - }.backgroundColor(0xFFA500) - - Text('layoutWeight').fontSize(12).fontColor(0xCCCCCC).width('90%') - // 容器尺寸确定时,元素与兄弟节点主轴布局尺寸按照权重进行分配,忽略本身尺寸设置。 - Row() { - // 权重1 - Text('layoutWeight(1)') - .size({ width: '30%', height: 110 }).backgroundColor(0xFFEFD5).textAlign(TextAlign.Center) - .layoutWeight(1) - // 权重0 - Text('layoutWeight(2)') - .size({ width: '30%', height: 110 }).backgroundColor(0xF5DEB3).textAlign(TextAlign.Center) - .layoutWeight(2) - // 权重默认0 - Text('no layoutWeight') - .size({ width: '30%', height: 110 }).backgroundColor(0xD2B48C).textAlign(TextAlign.Center) - }.size({ width: '90%', height: 140 }).backgroundColor(0xAFEEEE) - }.width('100%').margin({ top: 5 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/size.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/02.\344\275\215\347\275\256\350\256\276\347\275\256.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/02.\344\275\215\347\275\256\350\256\276\347\275\256.md" deleted file mode 100644 index 32bcf29e0901ed5a8bef723336025cb4e3d05524..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/02.\344\275\215\347\275\256\350\256\276\347\275\256.md" +++ /dev/null @@ -1,212 +0,0 @@ ---- -title: 位置设置 -permalink: /pages/010c020201010202 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:32 ---- -# 位置设置 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 权限列表 - -无 - -## 属性 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

align

-

Alignment

-

Center

-

设置元素内容的对齐方式,只有当设置的width和height大小超过元素本身内容大小时生效。

-

direction

-

Direction

-

Auto

-

设置元素水平方向的布局,可选值参照Direction枚举说明。

-

position

-

{

-

x: Length,

-

y: Length

-

}

-

-

-

使用绝对定位,设置元素锚点相对于父容器顶部起点偏移位置。在布局容器中,设置该属性不影响父容器布局,仅在绘制时进行位置调整。

-

markAnchor

-

{

-

x: Length,

-

y: Length

-

}

-

{

-

x: 0,

-

y: 0

-

}

-

设置元素在位置定位时的锚点,以元素顶部起点作为基准点进行偏移。

-

offset

-

{

-

x: Length,

-

y: Length

-

}

-

{

-

x: 0,

-

y: 0

-

}

-

相对布局完成位置坐标偏移量,设置该属性,不影响父容器布局,仅在绘制时进行位置调整。

-
- -- Direction枚举说明 - - - - - - - - - - - - - - - -

名称

-

描述

-

Ltr

-

元素从左到右布局。

-

Rtl

-

元素从右到左布局。

-

Auto

-

使用系统默认布局方向。

-
- - -## 示例 - -``` -@Entry -@Component -struct PositionExample { - build() { - Column() { - Column({space: 10}) { - Text('align').fontSize(9).fontColor(0xCCCCCC).width('90%') - Text('top start') - .align(Alignment.TopStart) - .height(50) - .width('90%') - .fontSize(16) - .backgroundColor(0xFFE4C4) - - Text('direction').fontSize(9).fontColor(0xCCCCCC).width('90%') - Row() { - Text('1').height(50).width('25%').fontSize(16).backgroundColor(0xF5DEB3) - Text('2').height(50).width('25%').fontSize(16).backgroundColor(0xD2B48C) - Text('3').height(50).width('25%').fontSize(16).backgroundColor(0xF5DEB3) - Text('4').height(50).width('25%').fontSize(16).backgroundColor(0xD2B48C) - } - .width('90%') - .direction(Direction.Rtl) - } - } - .width('100%').margin({ top: 5 }).direction(Direction.Rtl) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/position.gif) - -``` -@Entry -@Component -struct PositionExample2 { - build() { - Column({ space: 20 }) { - Text('position').fontSize(12).fontColor(0xCCCCCC).width('90%') - Row({ space: 20 }) { - Text('1').size({ width: '45%', height: '50' }).backgroundColor(0xdeb887).border({ width: 1 }) .fontSize(16) - Text('2 position(25, 15)') - .size({ width: '60%', height: '30' }).backgroundColor(0xbbb2cb).border({ width: 1 }) - .fontSize(16).align(Alignment.Start) - .position({ x: 25, y: 15 }) - Text('3').size({ width: '45%', height: '50' }).backgroundColor(0xdeb887).border({ width: 1 }).fontSize(16) - Text('4 position(50%, 70%)') - .size({ width: '50%', height: '50' }).backgroundColor(0xbbb2cb).border({ width: 1 }).fontSize(16) - .position({ x: '50%', y: '70%' }) - }.width('90%').height(100).border({ width: 1, style: BorderStyle.Dashed }) - - Text('markAnchor').fontSize(12).fontColor(0xCCCCCC).width('90%') - Stack({ alignContent: Alignment.TopStart }) { - Row() - .size({ width: '100', height: '100' }) - .backgroundColor(0xdeb887) - Image($r('app.media.ic_health_heart')) - .size({ width: 25, height: 25 }) - .markAnchor({ x: 25, y: 25 }) - Image($r('app.media.ic_health_heart')) - .size({ width: 25, height: 25 }) - .markAnchor({ x: 25, y: 25 }) - .position({ x: '100%', y: '100%' }) - }.margin({ top: 25 }).border({ width: 1, style: BorderStyle.Dashed }) - - Text('offset').fontSize(12).fontColor(0xCCCCCC).width('90%') - Row() { - Text('1').size({ width: '15%', height: '50' }).backgroundColor(0xdeb887).border({ width: 1 }).fontSize(16) - Text('2\noffset(15, 15)') - .size({ width: 120, height: '50' }).backgroundColor(0xbbb2cb).border({ width: 1 }) - .fontSize(16).align(Alignment.Start) - .offset({ x: 15, y: 15 }) - Text('3').size({ width: '15%', height: '50' }).backgroundColor(0xdeb887).border({ width: 1 }).fontSize(16) - Text('4\noffset(-10%, 20%)') - .size({ width: 150, height: '50' }) .backgroundColor(0xbbb2cb).border({ width: 1 }).fontSize(16) - .offset({ x: '-10%', y: '20%' }) - }.width('90%').height(100).border({ width: 1, style: BorderStyle.Dashed }) - } - .width('100%').margin({ top: 25 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/position2.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/03.\345\270\203\345\261\200\347\272\246\346\235\237.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/03.\345\270\203\345\261\200\347\272\246\346\235\237.md" deleted file mode 100644 index 9ce7fb4a08dbbdfbf18dfac27569a883089b9f86..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/03.\345\270\203\345\261\200\347\272\246\346\235\237.md" +++ /dev/null @@ -1,166 +0,0 @@ ---- -title: 布局约束 -permalink: /pages/010c020201010203 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:32 ---- -# 布局约束 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 权限列表 - -无 - -## 属性 - - - - - - - - - - - - - - - - - - -

名称

-

参数说明

-

默认值

-

描述

-

aspectRatio

-

number

-

-

-

指定当前组件的宽高比。

-

displayPriority

-

number

-

-

-

设置当前组件在布局容器中显示的优先级,当父容器空间不足时,低优先级的组件会被隐藏。

-
说明:

仅在Row/Column/Flex(单行)容器组件中生效。

-
-
- -## 示例 - -``` -@Entry -@Component -struct AspectRatioExample { - private children : string[] = ['1', '2', '3', '4', '5', '6'] - - build() { - Column({space: 20}) { - Text('using container: row').fontSize(14).fontColor(0xCCCCCC).width('100%') - Row({space: 10}) { - ForEach(this.children, (item) => { - Text(item) - .backgroundColor(0xbbb2cb) - .fontSize(20) - .aspectRatio(1.5) - .height(60) - Text(item) - .backgroundColor(0xbbb2cb) - .fontSize(20) - .aspectRatio(1.5) - .width(60) - }, item=>item) - } - .size({width: "100%", height: 100}) - .backgroundColor(0xd2cab3) - .clip(true) - - Text('using container: grid').fontSize(14).fontColor(0xCCCCCC).width('100%') - Grid() { - ForEach(this.children, (item) => { - GridItem() { - Text(item) - .backgroundColor(0xbbb2cb) - .fontSize(40) - .aspectRatio(1.5) - } - }, item=>item) - } - .columnsTemplate('1fr 1fr 1fr') - .columnsGap(10) - .rowsGap(10) - .size({width: "100%", height: 165}) - .backgroundColor(0xd2cab3) - }.padding(10) - } -} -``` - -**图 1** 竖屏显示 -![](/images/application-dev/reference/arkui-ts/figures/竖屏显示.gif "竖屏显示") - -**图 2** 横屏显示 -![](/images/application-dev/reference/arkui-ts/figures/横屏显示.gif "横屏显示") - -``` -class ContainerInfo { - label : string = '' - size : string = '' -} - -class ChildInfo { - text : string = '' - priority : number = 0 -} - -@Entry -@Component -struct DisplayPriorityExample { - private container : ContainerInfo[] = [ - {label: 'Big container', size: '90%'}, - {label: 'Middle container', size: '50%'}, - {label: 'Small container', size: '30%'}] - private children : ChildInfo[] = [ - {text: '1\n(priority:2)', priority: 2}, - {text: '2\n(priority:1)', priority: 1}, - {text: '3\n(priority:3)', priority: 3}, - {text: '4\n(priority:1)', priority: 1}, - {text: '5\n(priority:2)', priority: 2}] - @State currentIndex : number = 0 - - build() { - Column({space: 10}) { - Button(this.container[this.currentIndex].label).backgroundColor(0x317aff) - .onClick((event: ClickEvent) => { - this.currentIndex = (this.currentIndex + 1) % this.container.length - }) - Flex({justifyContent: FlexAlign.SpaceBetween}) { - ForEach(this.children, (item)=>{ - Text(item.text) - .width(120) - .height(60) - .fontSize(24) - .textAlign(TextAlign.Center) - .backgroundColor(0xbbb2cb) - .displayPriority(item.priority) - }, item=>item.text) - } - .width(this.container[this.currentIndex].size) - .backgroundColor(0xd2cab3) - }.width("100%").margin({top:50}) - } -} - -``` - -![](/images/application-dev/reference/arkui-ts/figures/DisplayPriorityExample.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/04.Flex\345\270\203\345\261\200.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/04.Flex\345\270\203\345\261\200.md" deleted file mode 100644 index 9069921af46e30a87e25b77e31e8cec5ce24bd3d..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/04.Flex\345\270\203\345\261\200.md" +++ /dev/null @@ -1,138 +0,0 @@ ---- -title: Flex布局 -permalink: /pages/010c020201010204 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:32 ---- -# Flex布局 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->- 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 ->- 仅当父组件是Flex组件时生效。 - -## 权限列表 - -无 - -## 属性 - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数说明

-

默认值

-

描述

-

flexBasis

-

'auto' | Length

-

'auto'

-

此属性所在的组件在Flex容器中主轴方向上基准尺寸。

-

flexGrow

-

number

-

0

-

Flex容器的剩余空间分配给给此属性所在的组件的比例。

-

flexShrink

-

number

-

1

-

Flex容器压缩尺寸分配给此属性所在的组件的比例。

-

alignSelf

-

ItemAlign

-

Auto

-

覆盖Flex布局容器中alignItems默认配置。

-
- -## 示例 - -``` -@Entry -@Component -struct FlexExample { - build() { - Column({ space: 5 }) { - Text('flexBasis').fontSize(9).fontColor(0xCCCCCC).width('90%') - // 基于主轴基准尺寸 - // flexBasis()值可以是'auto'(默认值)元素本来的大小 ,如果是数字则类似于.width()/.height() ,基于主轴 - Flex() { - Text('flexBasis(100)') - .flexBasis('100').height(100).lineHeight(70) - .backgroundColor(0xF5DEB3).textAlign(TextAlign.Center) - Text('flexBasis("auto")') - .flexBasis('auto').width('60%').height(100).lineHeight(70) - .backgroundColor(0xD2B48C).textAlign(TextAlign.Center) - }.width('90%').height(120).padding(10).backgroundColor(0xAFEEEE) - - Text('flexGrow').fontSize(9).fontColor(0xCCCCCC).width('90%') - // 剩余空间所占比例 - // flexGrow()剩余空间分配给该元素的比例 - Flex() { - Text('flexGrow(2)') - .flexGrow(2).height(100).lineHeight(70) - .backgroundColor(0xF5DEB3).textAlign(TextAlign.Center) - Text('flexGrow(1)') - .flexGrow(1).height(100).lineHeight(70) - .backgroundColor(0xD2B48C).textAlign(TextAlign.Center) - }.width('90%').height(120).padding(10).backgroundColor(0xAFEEEE) - - Text('flexShrink').fontSize(9).fontColor(0xCCCCCC).width('90%') - // flexShrink()此属性所在的组件的比例 - // text1比例是0,其他都是默认值1,放不下时直接等比例缩放后两个,第一个不缩放 - Flex({ direction: FlexDirection.Row }) { - Text('flexShrink(0)') - .flexShrink(0).width('50%').height(100).lineHeight(70) - .backgroundColor(0xF5DEB3).textAlign(TextAlign.Center) - Text('no flexShrink') - .width('40%').height(100).lineHeight(70).backgroundColor(0xD2B48C).textAlign(TextAlign.Center) - Text('flexShrink(2)') - .flexShrink(2).width('40%').height(100) .lineHeight(70) - .backgroundColor(0xF5DEB3).textAlign(TextAlign.Center) - }.width('90%').height(120).padding(10).backgroundColor(0xAFEEEE) - - Text('alignSelf').fontSize(9).fontColor(0xCCCCCC).width('90%') - // alignSelf()覆盖Flex布局容器中alignItems默认配置 - Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center }) { - Text('no alignSelf,height:80').width('33%').height(80) - .backgroundColor(0xF5DEB3).textAlign(TextAlign.Center) - Text('alignSelf stretch') - .alignSelf(ItemAlign.Stretch).width('33%').height(80).lineHeight(70) - .backgroundColor(0xD2B48C).textAlign(TextAlign.Center) - Text('no alignSelf,height:100').width('34%').height(100) - .backgroundColor(0xF5DEB3).textAlign(TextAlign.Center) - }.width('90%').height(120).padding(10).backgroundColor(0xAFEEEE) - }.width('100%').margin({ top: 5 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/flex.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/05.\350\276\271\346\241\206\350\256\276\347\275\256.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/05.\350\276\271\346\241\206\350\256\276\347\275\256.md" deleted file mode 100644 index dacc18cf94c543938e2b3fb4973009750181945a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/05.\350\276\271\346\241\206\350\256\276\347\275\256.md" +++ /dev/null @@ -1,139 +0,0 @@ ---- -title: 边框设置 -permalink: /pages/010c020201010205 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:32 ---- -# 边框设置 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -设置组件边框样式。 - -## 权限列表 - -无 - -## 属性 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

border

-

{

-

width?: Length,

-

color?: Color,

-

radius?: Length,

-

style?: BorderStyle

-

}

-

-

-

统一边框样式设置接口。

-

borderStyle

-

BorderStyle

-

Solid

-

设置元素的边框样式。

-

borderWidth

-

Length

-

0

-

设置元素的边框宽度。

-

borderColor

-

Color

-

-

-

设置元素的边框颜色。

-

borderRadius

-

Length

-

0

-

设置元素的边框圆角半径。

-
- -- BorderStyle枚举说明 - - - - - - - - - - - - - - - -

名称

-

描述

-

Dotted

-

显示为一系列圆点,圆点半径为borderWidth的一半。

-

Dashed

-

显示为一系列短的方形虚线。

-

Solid

-

显示为一条实线。

-
- - -## 示例 - -``` -@Entry -@Component -struct BorderExample { - build() { - Flex({ justifyContent: FlexAlign.SpaceAround, alignItems: ItemAlign.Center }) { - // 线段 - Text('dashed') - .borderStyle(BorderStyle.Dashed).borderWidth(5).borderColor(0xAFEEEE).borderRadius(10) - .width(120).height(120).textAlign(TextAlign.Center).fontSize(16) - // 点线 - Text('dotted') - .border({ width: 5, color: 0x317AF7, radius: 10, style: BorderStyle.Dotted }) - .width(120).height(120).textAlign(TextAlign.Center).fontSize(16) - }.width('100%').height(150) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/border.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/06.\350\203\214\346\231\257\350\256\276\347\275\256.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/06.\350\203\214\346\231\257\350\256\276\347\275\256.md" deleted file mode 100644 index d12521717ef720d9469b5fe9c4a754401f868077..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/06.\350\203\214\346\231\257\350\256\276\347\275\256.md" +++ /dev/null @@ -1,181 +0,0 @@ ---- -title: 背景设置 -permalink: /pages/010c020201010206 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:32 ---- -# 背景设置 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -设置组件的背景色。 - -## 权限列表 - -无 - -## 属性 - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

backgroundColor

-

Color

-

-

-

设置组件的背景色。

-

backgroundImage

-

src: string,

-

repeat?: ImageRepeat

-

-

-

src参数:图片地址,支持网络图片资源和本地图片资源地址(不支持svg类型的图片)。

-

repeat参数:设置背景图片的重复样式,默认不重复。

-

backgroundImageSize

-

{

-

width?: Length,

-

height?: Length

-

} | ImageSize

-

Auto

-

设置背景图像的高度和宽度。当输入为{width: Length, height: Length}对象时,如果只设置一个属性,则第二个属性保持图片原始宽高比进行调整。默认保持原图的比例不变。

-

backgroundImagePosition

-

{

-

x?: Length,

-

y?: Length

-

} | Alignment

-

{

-

x: 0,

-

y: 0

-

}

-

设置背景图在组件中显示位置。

-
- -- ImageSize枚举说明 - - - - - - - - - - - - - - - -

类型

-

描述

-

Cover

-

默认值,保持宽高比进行缩小或者放大,使得图片两边都大于或等于显示边界。

-

Contain

-

保持宽高比进行缩小或者放大,使得图片完全显示在显示边界内。

-

Auto

-

保持原图的比例不变。

-
- - -## 示例 - -``` -@Entry -@Component -struct BackgroundExample { - build() { - Column({ space: 5 }) { - Text('background color').fontSize(9).width('90%').fontColor(0xCCCCCC) - Row().width('90%').height(50).backgroundColor(0xE5E5E5).border({ width: 1 }) - - Text('background image repeat along X').fontSize(9).width('90%').fontColor(0xCCCCCC) - Row() - .backgroundImage('/comment/bg.jpg', ImageRepeat.X) - .backgroundImageSize({ width: '250px', height: '140px' }) - .width('90%') - .height(70) - .border({ width: 1 }) - - Text('background image repeat along Y').fontSize(9).width('90%').fontColor(0xCCCCCC) - Row() - .backgroundImage('/comment/bg.jpg', ImageRepeat.Y) - .backgroundImageSize({ width: '500px', height: '120px' }) - .width('90%') - .height(100) - .border({ width: 1 }) - - Text('background image size').fontSize(9).width('90%').fontColor(0xCCCCCC) - Row() - .width('90%').height(150) - .backgroundImage('/comment/bg.jpg', ImageRepeat.NoRepeat) - .backgroundImageSize({ width: 1000, height: 500 }) - .border({ width: 1 }) - - Text('background fill the box(Cover)').fontSize(9).width('90%').fontColor(0xCCCCCC) - // 不保准图片完整的情况下占满盒子 - Row() - .width(200) - .height(50) - .backgroundImage('/comment/bg.jpg', ImageRepeat.NoRepeat) - .backgroundImageSize(ImageSize.Cover) - .border({ width: 1 }) - - Text('background fill the box(Contain)').fontSize(9).width('90%').fontColor(0xCCCCCC) - // 保准图片完整的情况下放到最大 - Row() - .width(200) - .height(50) - .backgroundImage('/comment/bg.jpg', ImageRepeat.NoRepeat) - .backgroundImageSize(ImageSize.Contain) - .border({ width: 1 }) - - Text('background image position').fontSize(9).width('90%').fontColor(0xCCCCCC) - Row() - .width(100) - .height(50) - .backgroundImage('/comment/bg.jpg', ImageRepeat.NoRepeat) - .backgroundImageSize({ width: 1000, height: 560 }) - .backgroundImagePosition({ x: -500, y: -300 }) - .border({ width: 1 }) - } - .width('100%').height('100%').padding({ top: 5 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/back.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/07.\351\200\217\346\230\216\345\272\246\350\256\276\347\275\256.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/07.\351\200\217\346\230\216\345\272\246\350\256\276\347\275\256.md" deleted file mode 100644 index 03ceb97d765ee2ec87faac7ecb0df7b4a1ed0c46..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/07.\351\200\217\346\230\216\345\272\246\350\256\276\347\275\256.md" +++ /dev/null @@ -1,71 +0,0 @@ ---- -title: 透明度设置 -permalink: /pages/010c020201010207 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:32 ---- -# 透明度设置 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -设置组件的透明度。 - -## 权限列表 - -无 - -## 属性 - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

opacity

-

number

-

1

-

元素的不透明度,取值范围为0到1,1表示为不透明,0表示为完全透明。

-
- -## 示例 - -``` -@Entry -@Component -struct OpacityExample { - build() { - Column({ space: 5 }) { - Text('opacity(1)').fontSize(9).width('90%').fontColor(0xCCCCCC) - Text().width('90%').height(50).opacity(1).backgroundColor(0xAFEEEE) - Text('opacity(0.7)').fontSize(9).width('90%').fontColor(0xCCCCCC) - Text().width('90%').height(50).opacity(0.7).backgroundColor(0xAFEEEE) - Text('opacity(0.4)').fontSize(9).width('90%').fontColor(0xCCCCCC) - Text().width('90%').height(50).opacity(0.4).backgroundColor(0xAFEEEE) - } - .width('100%') - .padding({ top: 5 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/opacity.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/08.\346\230\276\351\232\220\346\216\247\345\210\266.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/08.\346\230\276\351\232\220\346\216\247\345\210\266.md" deleted file mode 100644 index ede7ee28b08c23412be6b1ad2c55715a11ec9937..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/08.\346\230\276\351\232\220\346\216\247\345\210\266.md" +++ /dev/null @@ -1,100 +0,0 @@ ---- -title: 显隐控制 -permalink: /pages/010c020201010208 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:32 ---- -# 显隐控制 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 权限列表 - -无 - -## 属性 - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

visibility

-

Visibility

-

Visible

-

控制当前组件显示或隐藏。

-
- -- Visibility枚举说明 - - - - - - - - - - - - - - - -

名称

-

描述

-

Hidden

-

隐藏,但参与布局进行占位。

-

Visible

-

显示。

-

None

-

隐藏,但不参与布局,不进行占位。

-
- - -## 示例 - -``` -@Entry -@Component -struct VisibilityExample { - build() { - Column() { - Column() { - Text('Visible').fontSize(9).width('90%').fontColor(0xCCCCCC) - Row().visibility(Visibility.Visible).width('90%').height(80).backgroundColor(0xAFEEEE) - - Text('None').fontSize(9).width('90%').fontColor(0xCCCCCC) - // 隐藏不参与占位 - Row().visibility(Visibility.None).width('90%').height(80).backgroundColor(0xAFEEEE) - - Text('Hidden').fontSize(9).width('90%').fontColor(0xCCCCCC) - // 隐藏参与占位 - Row().visibility(Visibility.Hidden).width('90%').height(80).backgroundColor(0xAFEEEE) - }.width('90%').border({ width: 1 }) - }.width('100%').margin({ top: 5 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/visibility.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/09.\347\246\201\347\224\250\346\216\247\345\210\266.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/09.\347\246\201\347\224\250\346\216\247\345\210\266.md" deleted file mode 100644 index 9ef1bfe75fdf7be156a41870b6540a4cc7d33889..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/09.\347\246\201\347\224\250\346\216\247\345\210\266.md" +++ /dev/null @@ -1,66 +0,0 @@ ---- -title: 禁用控制 -permalink: /pages/010c020201010209 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:32 ---- -# 禁用控制 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 权限列表 - -无 - -## 属性 - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

enabled

-

boolean

-

true

-

值为true表示组件可用,可响应点击等操作;值为false时,不响应点击等操作。

-
- -## 示例 - -``` -@Entry -@Component -struct EnabledExample { - build() { - Flex({ justifyContent: FlexAlign.SpaceAround }) { - // 点击没有反应 - Button('disable').enabled(false).backgroundColor(0x317aff).opacity(0.4) - Button('enable').backgroundColor(0x317aff) - } - .width('100%') - .padding({ top: 5 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/enabled.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/10.\346\265\256\345\261\202.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/10.\346\265\256\345\261\202.md" deleted file mode 100644 index c39384f930c7f63009e0f6dc26731c68fb25e486..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/10.\346\265\256\345\261\202.md" +++ /dev/null @@ -1,77 +0,0 @@ ---- -title: 浮层 -permalink: /pages/010c02020101020a -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:32 ---- -# 浮层 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 权限列表 - -无 - -## 属性 - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

overlay

-

title: string,

-

options: {

-

align?: Alignment,

-

offset?: {x: number, y: number}

-

}

-

{

-

align: Alignment.Center,

-

offset: {0, 0}

-

}

-

在当前组件上,增加遮罩文本,布局与当前组件相同。

-
- -## 示例 - -``` -@Entry -@Component -struct OverlayExample { - build() { - Column() { - Column() { - Text('floating layer') - .fontSize(12).fontColor(0xCCCCCC).maxLines(1) - Column() { - Image($r('app.media.img')) - .width(240).height(240) - .overlay("Winter is a beautiful season, especially when it snows", { align: Alignment.Bottom, offset: { x: 0, y: -15 } }) - }.border({ color: Color.Black, width: 2 }) - }.width('100%') - }.padding({ top: 20 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/overlay.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/11.Z\345\272\217\346\216\247\345\210\266.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/11.Z\345\272\217\346\216\247\345\210\266.md" deleted file mode 100644 index 2a2911a64fcf6eecd70cab368b3fa8bdebb5ffa3..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/11.Z\345\272\217\346\216\247\345\210\266.md" +++ /dev/null @@ -1,73 +0,0 @@ ---- -title: Z序控制 -permalink: /pages/010c02020101020b -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:32 ---- -# Z序控制 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 权限列表 - -无 - -## 属性 - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

zIndex

-

number

-

0

-

同一容器中兄弟组件显示层级关系,z值越大,显示层级越高。

-
- -## 示例 - -``` -@Entry -@Component -struct ZIndexExample { - build() { - Column() { - Stack() { - // stack会重叠组件, 默认后定义的在最上面 - Text('first child, zIndex(2)') - .size({width: '40%', height: '30%'}).backgroundColor(0xbbb2cb) - .zIndex(2) - // 默认值0 - Text('second child, default zIndex(0)') - .size({width: '90%', height: '80%'}).backgroundColor(0xd2cab3).align(Alignment.TopStart) - Text('third child, zIndex(1)') - .size({width: '70%', height: '50%'}).backgroundColor(0xc1cbac).align(Alignment.TopStart) - .zIndex(1) - } - }.width('100%').height(200) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/zIndex.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/12.\345\233\276\345\275\242\345\217\230\346\215\242.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/12.\345\233\276\345\275\242\345\217\230\346\215\242.md" deleted file mode 100644 index 179ab434094742ad0c514b306bdf82287c5af1fc..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/12.\345\233\276\345\275\242\345\217\230\346\215\242.md" +++ /dev/null @@ -1,150 +0,0 @@ ---- -title: 图形变换 -permalink: /pages/010c02020101020c -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:32 ---- -# 图形变换 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 权限列表 - -无 - -## 属性 - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

rotate

-

{

-

x?: number,

-

y?: number,

-

z?: number,

-

angle?: Angle,

-

centerX?: Length,

-

centerY?: Length

-

}

-

{

-

x: 0,

-

y: 0,

-

z: 0,

-

angle: 0,

-

centerX: '50%',

-

centerY: '50%'

-

}

-

(x, y, z)指定一个矢量,表示旋转轴,正角度为顺时针转动,负角度为逆时针转动,默认值为0,同时可以通过centerX和centerY设置旋转的中心点。

-

translate

-

{

-

x?: Length,

-

y?: Length,

-

z? : Length

-

}

-

{

-

x: 0,

-

y: 0,

-

z: 0

-

}

-

可以分别设置X轴、Y轴、Z轴的平移距离,距离的正负控制平移的方向,默认值为0。

-

scale

-

{

-

x?: number,

-

y?: number,

-

z?: number,

-

centerX?: Length,

-

centerY?: Length

-

}

-

{

-

x: 1,

-

y: 1,

-

z: 1,

-

centerX:'50%',

-

centerY:'50%'

-

}

-

可以分别设置X轴、Y轴、Z轴的缩放比例,默认值为1,同时可以通过centerX和centerY设置缩放的中心点。

-

transform

-

matrix: Matrix4

-

-

-

设置当前组件的变换矩阵。

-
- -## 示例 - -``` -import Matrix4 from '@ohos.matrix4' - -@Entry -@Component -struct TransformExample { - build() { - Column() { - Text('rotate').width('90%').fontColor(0xCCCCCC).padding(15).fontSize(30) - Row() - .rotate({ - x: 1, - y: 1, - z: 1, - centerX: '50%', - centerY: '50%', - angle: 300 - }) // 组件以(1,1,1)为旋转轴,中心点顺时针旋转 300度 - .width(100).height(100).backgroundColor(0xAFEEEE) - - Text('translate').width('90%').fontColor(0xCCCCCC).padding(10).fontSize(30) - Row() - .translate({ x: 100, y: 5 }) // x轴平移100,y轴平移5 - .width(100).height(100).backgroundColor(0xAFEEEE).margin({bottom:10}) - - Text('scale').width('90%').fontColor(0xCCCCCC).padding(15).fontSize(30) - Row() - .scale({ x: 2, y: 0.5 }) // 高度缩小一倍,宽度放大一倍,z轴在2D下无效果 - .width(100).height(100).backgroundColor(0xAFEEEE) - - Text('Matrix4').width('90%').fontColor(0xCCCCCC).padding(15).fontSize(30) - Row() - .width(100).height(100).backgroundColor(0xAFEEEE) - .transform(Matrix4.identity().translate({ x: 100, y: 100, z: 30 })) - }.width('100%').margin({ top: 5 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/1111.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/13.\345\233\276\345\203\217\346\225\210\346\236\234.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/13.\345\233\276\345\203\217\346\225\210\346\236\234.md" deleted file mode 100644 index 9e1a0c7a26d18d25e6405057d2c365f2868ff6a9..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/13.\345\233\276\345\203\217\346\225\210\346\236\234.md" +++ /dev/null @@ -1,188 +0,0 @@ ---- -title: 图像效果 -permalink: /pages/010c02020101020d -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:32 ---- -# 图像效果 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 权限列表 - -无 - -## 属性 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

blur

-

number

-

-

-

为当前组件添加内容模糊效果,入参为模糊半径,模糊半径越大越模糊,为0时不模糊。

-

backdropBlur

-

number

-

-

-

为当前组件添加背景模糊效果,入参为模糊半径,模糊半径越大越模糊,为0时不模糊。

-

shadow

-

{

-

radius: number,

-

color?: Color,

-

offsetX?: number,

-

offsetY?: number

-

}

-

-

-

为当前组件添加阴影效果,入参为模糊半径(必填)、阴影的颜色(可选,默认为灰色)、X轴的偏移量(可选,默认为0),Y轴的偏移量(可选,默认为0),偏移量单位为px。

-

grayscale

-

number

-

0.0

-

为当前组件添加灰度效果。值定义为灰度转换的比例,入参1.0则完全转为灰度图像,入参则0.0图像无变化,入参在0.0和1.0之间时,效果呈线性变化。(百分比)

-

brightness

-

number

-

1.0

-

为当前组件添加高光效果,入参为高光比例,值为1时没有效果,小于1时亮度变暗,0为全黑;大于1时亮度增加,数值越大亮度越大。

-

saturate

-

number

-

1.0

-

为当前组件添加饱和度效果,饱和度为颜色中的含色成分和消色成分(灰)的比例,入参为1时,显示原图像,大于1时含色成分越大,饱和度越大;小于1时消色成分越大,饱和度越小。(百分比)

-

contrast

-

number

-

1.0

-

为当前组件添加对比度效果,入参为对比度的值,值为1时,显示原图;大于1时,值越大对比度越高,图像越清晰醒目;小于1时,值越小对比度越低;当对比度为0时,图像变为全灰。(百分比)

-

invert

-

number

-

0

-

反转输入的图像。入参为图像反转的比例。值为1时完全反转。值为0则图像无变化。(百分比)

-

colorBlend 8+

-

Color

-

-

-

为当前组件添加颜色叠加效果,入参为叠加的颜色。

-

sepia

-

number

-

0

-

将图像转换为深褐色。入参为图像反转的比例。值为1则完全是深褐色的,值为0图像无变化。 (百分比)

-

hueRotate

-

Angle

-

0deg

-

为当前组件添加色相旋转效果,入参为旋转的角度值。当入参为0deg时图像无变化(默认值是0deg),入参没有最大值,超过360deg的值相当于又绕一圈。

-
- -## 示例 - -``` -@Entry -@Component -struct ImageEffectsExample { - build() { - Column({space: 10}) { - // 对字体进行模糊 - Text('font blur').fontSize(15).fontColor(0xCCCCCC).width('90%') - Text('text').blur(3).width('90%').height(40) - .fontSize(16).backgroundColor(0xF9CF93).padding({ left: 5 }) - - // 对背景进行模糊 - Text('backdropBlur').fontSize(15).fontColor(0xCCCCCC).width('90%') - Text().width('90%').height(40).fontSize(16).backdropBlur(3) - .backgroundImage('/comment/bg.jpg') - .backgroundImageSize({ width: 1200, height: 160 }) - - Text('shadow').fontSize(15).fontColor(0xCCCCCC).width('90%') - Image($r('app.media.bg')).width('90%').height(40) - .shadow({ radius: 10, color: Color.Gray, offsetX: 5, offsetY: 5 }) - - Text('grayscale').fontSize(15).fontColor(0xCCCCCC).width('90%') - Image($r('app.media.bg')).width('90%').height(40).grayscale(0.6) - - Text('brightness').fontSize(15).fontColor(0xCCCCCC).width('90%') - Image($r('app.media.bg')).width('90%').height(40).brightness(2.0) - - Text('saturate').fontSize(15).fontColor(0xCCCCCC).width('90%') - Image($r('app.media.bg')).width('90%').height(40).saturate(2.0) - - Text('contrast').fontSize(15).fontColor(0xCCCCCC).width('90%') - Image($r('app.media.bg')).width('90%').height(40).contrast(2.0) - - Text('invert').fontSize(15).fontColor(0xCCCCCC).width('90%') - Image($r('app.media.bg')).width('90%').height(40).invert(1) - - Text('hueRotate').fontSize(15).fontColor(0xCCCCCC).width('90%') - Image($r('app.media.bg')).width('90%').height(40).hueRotate(90) - }.width('100%').margin({ top: 5 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/2222.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/14.\345\275\242\347\212\266\350\243\201\345\211\252.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/14.\345\275\242\347\212\266\350\243\201\345\211\252.md" deleted file mode 100644 index 53fecbb1ed0b6c3af061b5260a1bb4266f91934b..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/14.\345\275\242\347\212\266\350\243\201\345\211\252.md" +++ /dev/null @@ -1,94 +0,0 @@ ---- -title: 形状裁剪 -permalink: /pages/010c02020101020e -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:32 ---- -# 形状裁剪 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 权限列表 - -无 - -## 属性 - - - - - - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

clip

-

Shape | boolean

-

false

-

参数为Shape类型时,按指定的形状对当前组件进行裁剪;参数为boolean类型时,设置是否按照边缘轮廓进行裁剪。

-

mask

-

Shape

-

-

-

在当前组件上加上指定形状的遮罩。

-
- -## 示例 - -``` -@Entry -@Component -struct ClipAndMaskExample { - build() { - Column({ space: 5 }) { - Text('clip').fontSize(9).width('90%').fontColor(0xCCCCCC) - // 用一个280px直径的圆对图像进行裁剪 - Image('/comment/bg.jpg') - .clip(new Circle({ width: 80, height: 80 })) - .width('500px').height('280px') - - Row() { - Image('/comment/bg.jpg').width('500px').height('280px') - } - .clip(true) - .borderRadius(20) - - Text('mask').fontSize(9).width('90%').fontColor(0xCCCCCC) - // 给图像添加了一个500px*280px的遮罩 - Image('/comment/bg.jpg') - .mask(new Rect({ width: '500px', height: '280px' }).fill(Color.Gray)) - .width('500px').height('280px') - - // 给图像添加了一个280px*280px的圆遮罩 - Image('/comment/bg.jpg') - .mask(new Circle({ width: '280px', height: '280px' }).fill(Color.Gray)) - .width('500px').height('281px') - } - .width('100%') - .margin({ top: 5 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/clip.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/15.\346\226\207\346\234\254\346\240\267\345\274\217\350\256\276\347\275\256.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/15.\346\226\207\346\234\254\346\240\267\345\274\217\350\256\276\347\275\256.md" deleted file mode 100644 index 7bcebf4acf264215f78ec489208c1891e0ffe870..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/15.\346\226\207\346\234\254\346\240\267\345\274\217\350\256\276\347\275\256.md" +++ /dev/null @@ -1,196 +0,0 @@ ---- -title: 文本样式设置 -permalink: /pages/010c02020101020f -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:32 ---- -# 文本样式设置 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -针对包含文本元素的组件,设置文本样式。 - -## 权限列表 - -无 - -## 属性 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

fontColor

-

Color

-

-

-

设置文本颜色。

-

fontSize

-

Length

-

-

-

设置文本尺寸,Length为number类型时,使用fp单位。

-

fontStyle

-

FontStyle

-

Normal

-

设置文本的字体样式。

-

fontWeight

-

number | FontWeight

-

Normal

-

设置文本的字体粗细,number类型取值[100, 900],取值间隔为100,默认为400,取值越大,字体越粗。

-

提供常用枚举值,参考:FontWeight

-

fontFamily

-

string

-

-

-

设置文本的字体列表。使用多个字体,使用','进行分割,优先级按顺序生效。例如:'Arial, sans-serif'。

-
- -- FontStyle枚举说明 - - - - - - - - - - - - -

名称

-

描述

-

Normal

-

标准的字体样式。

-

Italic

-

斜体的字体样式。

-
- - -- FontWeight枚举说明 - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

描述

-

Lighter

-

字体较细。

-

Normal

-

字体粗细正常。

-

Regular

-

字体粗细正常。

-

Medium

-

字体粗细适中。

-

Bold

-

字体较粗。

-

Bolder

-

字体非常粗。

-
- - -## 示例 - -``` -@Entry -@Component -struct TextStyleExample { - build() { - Column({ space: 5 }) { - Text('default text') - - Text('text font color red') - .fontColor(Color.Red) - - Text('text font size 20') - .fontSize(20) - - Text('text font style Italic') - .fontStyle(FontStyle.Italic) - - Text('text fontWeight bold') - .fontWeight(700) - - Text('text fontFamily sans-serif') - .fontFamily('sans-serif') - - Text('red 20 Italic bold cursive text') - .fontColor(Color.Red) - .fontSize(20) - .fontStyle(FontStyle.Italic) - .fontWeight(700) - .fontFamily('cursive') - .textAlign(TextAlign.Center) - .width('90%') - - Text('Orange 18 Normal source-sans-pro text') - .fontColor(Color.Orange) - .fontSize(18) - .fontStyle(FontStyle.Normal) - .fontWeight(400) - .fontFamily('source-sans-pro,cursive,sans-serif') - }.width('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/textstyle.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/16.\346\240\205\346\240\274\350\256\276\347\275\256.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/16.\346\240\205\346\240\274\350\256\276\347\275\256.md" deleted file mode 100644 index ad9bdb86e079ff2d0e14b8de9cbf79cfc5da0eb9..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/16.\346\240\205\346\240\274\350\256\276\347\275\256.md" +++ /dev/null @@ -1,133 +0,0 @@ ---- -title: 栅格设置 -permalink: /pages/010c020201010210 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:33 ---- -# 栅格设置 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->- 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 ->- 栅格布局的列宽、列间距由距离最近的GridContainer父组件决定。使用栅格属性的组件树上至少需要有1个GridContainer容器组件。 - -## 权限列表 - -无 - -## 属性 - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

useSizeType

-

{

-

xs?: number | { span: number, offset: number },

-

sm?: number | { span: number, offset: number },

-

md?: number | { span: number, offset: number },

-

lg?: number | { span: number, offset: number }

-

}

-

-

-

设置在特定设备宽度类型下的占用列数和偏移列数,span: 占用列数; offset: 偏移列数。

-

当值为number类型时,仅设置列数, 当格式如{"span": 1, "offset": 0}时,指同时设置占用列数与偏移列数。

-
  • xs: 指设备宽度类型为SizeType.XS时的占用列数和偏移列数。
  • sm: 指设备宽度类型为SizeType.SM时的占用列数和偏移列数。
-
  • md: 指设备宽度类型为SizeType.MD时的占用列数和偏移列数。
  • lg: 指设备宽度类型为SizeType.LG时的占用列数和偏移列数。
-

gridSpan

-

number

-

1

-

默认占用列数,指useSizeType属性没有设置对应尺寸的列数(span)时,占用的栅格列数。

-
说明:

设置了栅格span属性,组件的宽度由栅格布局决定。

-
-

gridOffset

-

number

-

0

-

默认偏移列数,指useSizeType属性没有设置对应尺寸的偏移(offset)时, 当前组件沿着父组件Start方向,偏移的列数,也就是当前组件位于第n列。

-
说明:

1. 配置该属性后,当前组件在父组件水平方向的布局不再跟随父组件原有的布局方式,而是沿着父组件的Start方向偏移一定位移。

-

2. 偏移位移 = (列宽 + 间距)* 列数。

-

3. 设置了偏移(gridOffset)的组件之后的兄弟组件会根据该组件进行相对布局,类似相对布局。

-
-
- -## 示例 - -``` -@Entry -@Component -struct GridContainerExample1 { - build(){ - GridContainer() { - Row({}) { - Row() { - Text('Left').fontSize(25) - } - .useSizeType({ - xs: { span: 1, offset: 0 }, sm: { span: 1, offset: 0 }, - md: { span: 1, offset: 0 }, lg: { span: 2, offset: 0 } - }) - .height("100%") - .backgroundColor(0x66bbb2cb) - Row() { - Text('Center').fontSize(25) - } - .useSizeType({ - xs: { span: 1, offset: 0 }, sm: { span: 2, offset: 1 }, - md: { span: 5, offset: 1 }, lg: { span: 7, offset: 2 } - }) - .height("100%") - .backgroundColor(0x66b6c5d1) - Row() { - Text('Right').fontSize(25) - } - .useSizeType({ - xs: { span: 1, offset: 0 }, sm: { span: 1, offset: 3 }, - md: { span: 2, offset: 6 }, lg: { span: 3, offset: 9 } - }) - .height("100%") - .backgroundColor(0x66bbb2cb) - } - .height(200) - } - .backgroundColor(0xf1f3f5) - .margin({ top: 10 }) - } -} -``` - -**图 1** 设备宽度为SM -![](/images/application-dev/reference/arkui-ts/figures/设备宽度为SM.png "设备宽度为SM") - -**图 2** 设备宽度为MD -![](/images/application-dev/reference/arkui-ts/figures/设备宽度为MD.png "设备宽度为MD") - -**图 3** 设备宽度为LG -![](/images/application-dev/reference/arkui-ts/figures/设备宽度为LG.png "设备宽度为LG") - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/17.\351\242\234\350\211\262\346\270\220\345\217\230.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/17.\351\242\234\350\211\262\346\270\220\345\217\230.md" deleted file mode 100644 index ab5941d15d2020c3819a0efd6366fc6709b95c43..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/17.\351\242\234\350\211\262\346\270\220\345\217\230.md" +++ /dev/null @@ -1,197 +0,0 @@ ---- -title: 颜色渐变 -permalink: /pages/010c020201010211 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:33 ---- -# 颜色渐变 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 权限列表 - -无 - -## 属性 - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

linearGradient

-

{

-

angle?: Angle,

-

direction?:GradientDirection,

-

colors: Array<ColorStop>

-

repeating?: boolean

-

}

-

-

-

线性渐变。

-

angle: 线性渐变的角度。

-

direction: 线性渐变的方向。

-

colors: 为渐变的颜色描述。

-

repeating: 为渐变的颜色重复着色。

-

sweepGradient

-

{

-

center: Point,

-

start?: angle,

-

end?: angle,

-

colors: Array<ColorStop>

-

repeating?: boolean

-

}

-

-

-

角度渐变。

-

center:为角度渐变的中心点。

-

start:角度渐变的起点。

-

end:角度渐变的终点。

-

colors: 为渐变的颜色描述。

-

repeating: 为渐变的颜色重复着色。

-

radialGradient

-

{

-

center: Point,

-

radius: Length,

-

colors: Array<ColorStop>

-

repeating: boolean

-

}

-

-

-

径向渐变。

-

center:径向渐变的中心点。

-

radius:径向渐变的半径。

-

colors: 为渐变的颜色描述。

-

repeating: 为渐变的颜色重复着色。

-
- -- GradientDirection枚举说明 - - GradientDirection用于描述渐变方向。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

描述

-

Left

-

从右向左。

-

Top

-

从下向上。

-

Right

-

从左向右。

-

Bottom

-

从上向下。

-

LeftTop

-

左上。

-

LeftBottom

-

左下。

-

RightTop

-

右上。

-

RightBottom

-

右下。

-

None

-

无。

-
- - -## 示例 - -``` -@Entry -@Component -struct ColorGradientExample { - build() { - Column({ space: 5 }) { - Text('linearGradient').fontSize(12).width('90%').fontColor(0xCCCCCC) - Row() - .width('90%') - .height(50) - .linearGradient({ - angle: 90, - direction: GradientDirection.Left, - colors: [[0xAEE1E1, 0.0], [0xD3E0DC, 0.3], [0xFCD1D1, 1.0]] - }) - Text('sweepGradient').fontSize(12).width('90%').fontColor(0xCCCCCC) - Row() - .width(100) - .height(100) - .sweepGradient({ - center: [50, 50], - start: 0, - end: 359, - colors: [[0xAEE1E1, 0.0], [0xD3E0DC, 0.3], [0xFCD1D1, 1.0]] - }) - Text('radialGradient').fontSize(12).width('90%').fontColor(0xCCCCCC) - Row() - .width(100) - .height(100) - .radialGradient({ - center: [50, 50], - radius: 60, - colors:[[0xAEE1E1, 0.0], [0xD3E0DC, 0.3], [0xFCD1D1, 1.0]] - }) - } - .width('100%') - .padding({ top: 5 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/colorGradient.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/18.Popup\346\216\247\345\210\266.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/18.Popup\346\216\247\345\210\266.md" deleted file mode 100644 index 1c6441ff312ae6e1a9ef32c54e37d357d61957c8..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/18.Popup\346\216\247\345\210\266.md" +++ /dev/null @@ -1,357 +0,0 @@ ---- -title: Popup控制 -permalink: /pages/010c020201010212 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:33 ---- -# Popup控制 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 权限列表 - -无 - -## 属性 - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

bindPopup

-

show: boolean,

-

popup: PopupOption | CustomPopupOption

-

-

-

给组件绑定Popup,点击弹出弹窗。

-

show: 创建页面弹窗提示是否默认显示,默认值为false。

-

popup: 配置当前弹窗提示的参数。

-
- -- PopupOption类型接口说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

必填

-

默认值

-

描述

-

message

-

string

-

-

-

-

弹窗信息内容。

-

placementOnTop

-

boolean

-

-

false

-

是否在组件上方显示,默认值为false。

-

primaryButton

-

{

-

value: string,

-

action: () => void

-

}

-

-

-

-

第一个按钮。

-

value: 弹窗里主按钮的文本。

-

action: 点击主按钮的回调函数。

-

secondaryButton

-

{

-

value: string,

-

action: () => void

-

}

-

-

-

-

第二个按钮。

-

value: 弹窗里辅助按钮的文本。

-

action: 点击辅助按钮的回调函数。

-

onStateChange

-

(isVisible: boolean) => void

-

-

-

-

弹窗状态变化事件回调,参数isVisible为弹窗当前的显示状态。

-
- -- CustomPopupOption类型接口说明8+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

必填

-

默认值

-

描述

-

builder

-

() => any

-

-

-

-

提示气泡内容的构造器。

-

placement

-

Placement

-

-

Placement.Bottom

-

气泡组件优先显示的位置,当前位置显示不下时,会自动调整位置。

-

maskColor

-

Color

-

-

-

-

提示气泡遮障层的颜色。

-

popupColor

-

Color

-

-

-

-

提示气泡的颜色。

-

enableArrow

-

boolean

-

-

true

-

是否显示箭头,只有上、下方向的气泡会显示箭头。

-

autoCancel

-

boolean

-

-

true

-

页面有操作时,是否自动关闭气泡

-

onStateChange

-

(isVisible: boolean) => void

-

-

-

-

弹窗状态变化事件回调,参数为弹窗当前的显示状态。

-
- -- Placement枚举说明8+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

描述

-

Left

-

气泡提示位于组件左侧。

-

Right

-

气泡提示位于组件右侧。

-

Top

-

气泡提示位于组件上侧。

-

Bottom

-

气泡提示位于组件下侧。

-

TopLeft

-

气泡提示位于组件左上角。

-

TopRight

-

气泡提示位于组件右上角。

-

BottomLeft

-

气泡提示位于组件左下角。

-

BottomRight

-

气泡提示位于组件右下角。

-
- - -## 示例 - -``` -@Entry -@Component -struct PopupExample { - @State noHandlePopup: boolean = false - @State handlePopup: boolean = false - @State customPopup: boolean = false - - @Builder popupBuilder() { - Row({ space: 2 }) { - Image('/resource/ic_public_thumbsup.svg').width(24).height(24).margin({ left: -5 }) - Text('Custom Popup').fontSize(12) - }.width(100).height(50).backgroundColor(Color.White) - } - - build() { - Flex({ direction: FlexDirection.Column }) { - Button('no handle popup') - .onClick(() => { - this.noHandlePopup = !this.noHandlePopup - }) - .bindPopup(this.noHandlePopup, { - message: 'content1 content1', - placementOnTop: false, - onStateChange: (e) => { - console.info(e.isVisible.toString()) - if (!e.isVisible) { - this.noHandlePopup = false - } - } - }) - .position({ x: 100, y: 50 }) - - Button('with handle popup') - .onClick(() => { - this.handlePopup = !this.handlePopup - }) - .bindPopup(this.handlePopup, { - message: 'content2 content2', - placementOnTop: true, - primaryButton: { - value: 'ok', - action: () => { - this.handlePopup = !this.handlePopup - console.info('secondaryButton click') - } - }, - onStateChange: (e) => { - console.info(e.isVisible.toString()) - } - }) - .position({ x: 100, y: 200 }) - - Button('custom popup') - .onClick(() => { - this.customPopup = !this.customPopup - }) - .bindPopup(this.customPopup, { - builder: this.popupBuilder, - placement: Placement.Bottom, - maskColor: 0x33000000, - popupColor: Color.White, - enableArrow: true, - onStateChange: (e) => { - if (!e.isVisible) { - this.customPopup = false - } - } - }) - .position({ x: 100, y: 350 }) - }.width('100%').padding({ top: 5 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/popup.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/19.Menu\346\216\247\345\210\266.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/19.Menu\346\216\247\345\210\266.md" deleted file mode 100644 index 8905e276ae69ecb6e5d0a048966439d96de5916e..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/19.Menu\346\216\247\345\210\266.md" +++ /dev/null @@ -1,154 +0,0 @@ ---- -title: Menu控制 -permalink: /pages/010c020201010213 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:33 ---- -# Menu控制 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 权限列表 - -无 - -## 属性 - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

bindMenu

-

Array<MenuItem> | CustomBuilder8+

-

-

-

给组件绑定菜单,点击后弹出菜单。弹出菜单项支持文本和自定义两种功能。

-
- -- MenuItem - - - - - - - - - - - - - - - -

名称

-

类型

-

描述

-

value

-

string

-

菜单项文本。

-

action

-

() => void

-

点击菜单项的事件回调。

-
- - -## 示例 - -``` -@Entry -@Component -struct MenuExample { - build() { - Column() { - Text('click for Menu') - } - .width('100%') - .margin({ top: 5 }) - .bindMenu([ - { - value: 'Menu1', - action: () => { - console.info('handle Menu1 select') - } - }, - { - value: 'Menu2', - action: () => { - console.info('handle Menu2 select') - } - }, - ]) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/menu.gif) - -``` -import router from '@system.router'; - -@Entry -@Component -struct MenuExample { - @Builder MenuBuilder() { - Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { - Text('text1') - .fontSize(20) - .width(100) - .height(50) - .textAlign(TextAlign.Center) - - Divider().height(10) - - Text('text2') - .fontSize(20) - .width(100) - .height(50) - .textAlign(TextAlign.Center) - - Divider().height(10) - - Button('Next') - .fontSize(20) - .width(100) - .height(50) - .onClick(() => { - router.push({ uri: 'pages/details' }) - }) - - }.width(100) - } - - build() { - Column() { - Text('click for menu') - } - .width('100%') - .margin({ top: 5 }) - .bindMenu(this.MenuBuilder) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/GIF.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/20.\347\202\271\345\207\273\346\216\247\345\210\266.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/20.\347\202\271\345\207\273\346\216\247\345\210\266.md" deleted file mode 100644 index 6730a0765259ca9c889137afae10e5c6c9617583..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/20.\347\202\271\345\207\273\346\216\247\345\210\266.md" +++ /dev/null @@ -1,77 +0,0 @@ ---- -title: 点击控制 -permalink: /pages/010c020201010214 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:33 ---- -# 点击控制 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 权限列表 - -无 - -## 属性 - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

touchable

-

boolean

-

true

-

设置当前组件是否可以被触摸。

-
- -## 示例 - -``` -@Entry -@Component -struct TouchAbleExample { - @State text1: string = '' - @State text2: string = '' - - build() { - Stack() { - Rect() - .fill(Color.Gray).width(150).height(150) - .onClick(() => { - console.info(this.text1 = 'Rect Clicked') - }) - .overlay(this.text1, { align: Alignment.Bottom, offset: { x: 0, y: 20 } }) - Ellipse() - .fill(Color.Pink).width(150).height(80) - .touchable(false) // 点击Ellipse区域,不会打印 “Ellipse Clicked” - .onClick(() => { - console.info(this.text2 = 'Ellipse Clicked') - }) - .overlay(this.text2, { align: Alignment.Bottom, offset: { x: 0, y: 20 } }) - }.margin(100) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/GIF2.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/21.\350\247\246\346\221\270\347\203\255\345\214\272\350\256\276\347\275\256.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/21.\350\247\246\346\221\270\347\203\255\345\214\272\350\256\276\347\275\256.md" deleted file mode 100644 index 181c234ebfe463e34ac6a3c9bd720c775426c067..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/02.\351\200\232\347\224\250\345\261\236\346\200\247/21.\350\247\246\346\221\270\347\203\255\345\214\272\350\256\276\347\275\256.md" +++ /dev/null @@ -1,144 +0,0 @@ ---- -title: 触摸热区设置 -permalink: /pages/010c020201010215 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:33 ---- -# 触摸热区设置 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -适用于支持通用点击事件、通用触摸事件、通用手势处理的组件。 - -## 权限列表 - -无 - -## 属性 - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

responseRegion

-

Array<Rectangle> | Rectangle

-

{

-

x:0,

-

y:0,

-

width:'100%',

-

height:'100%'

-

}

-

设置一个或多个触摸热区,包括位置和大小。

-
说明:

百分比是相对于组件本身来度量的。

-

x和y可以设置正负值百分比。当x设置为'100%'时表示热区往右偏移组件本身宽度大小,当x设置为'-100%'时表示热区往左偏移组件本身宽度大小。当y设置为'100%'时表示热区往下偏移组件本身高度大小,当y设置为'-100%'时表示热区往上偏移组件本身高度大小。

-

width和height只能设置正值百分比。width:'100%'表示热区宽度设置为该组件本身的宽度。比如组件本身宽度是100vp,那么'100%'表示热区宽度也为100vp。height:'100%'表示热区高度设置为该组件本身的高度。

-
-
- -- Rectangle对象说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

必填

-

默认值

-

描述

-

x

-

Length

-

-

0vp

-

触摸点相对于组件本身左边沿的X坐标。

-

y

-

Length

-

-

0vp

-

触摸点相对于组件本身左边沿的Y坐标。

-

width

-

Length

-

-

100%

-

触摸热区范围的宽度。

-

height

-

Length

-

-

100%

-

触摸热区范围的高度。

-
- - >![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** - >当x和y都设置为正值时,表示组件的触摸热区的范围整体往组件本身右下角偏移,偏移的大小可通过数值来设置。 - - -## 示例 - -``` -@Entry -@Component -struct ResponseRegionExample { - build() { - Column() { - Toggle({ type: ToggleType.Checkbox, isOn: true }) - .selectedColor(0x39a2db) - .backgroundColor(0xAFEEEE) - .responseRegion({ x: 1.0, y: 1.0, width: 400, height: 400 }) - .onChange((isOn: boolean) => { - console.info('Component status:' + isOn) - }) - }.width('100%').margin({ top: 5 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/GIF1.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/03.\346\211\213\345\212\277\345\244\204\347\220\206/01.\347\273\221\345\256\232\346\211\213\345\212\277\346\226\271\346\263\225.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/03.\346\211\213\345\212\277\345\244\204\347\220\206/01.\347\273\221\345\256\232\346\211\213\345\212\277\346\226\271\346\263\225.md" deleted file mode 100644 index 8364b5b3c3b9c6b924846f619c0c712e70f47a9a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/03.\346\211\213\345\212\277\345\244\204\347\220\206/01.\347\273\221\345\256\232\346\211\213\345\212\277\346\226\271\346\263\225.md" +++ /dev/null @@ -1,229 +0,0 @@ ---- -title: 绑定手势方法 -permalink: /pages/010c020201010301 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:33 ---- -# 绑定手势方法 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 权限列表 - -无 - -## 绑定手势识别 - -通过如下属性给组件绑定手势识别,手势识别成功后可以通过事件回调通知组件。 - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

gesture

-

gesture: GestureType,

-

mask?: GestureMask

-

gesture: -,

-

mask: GestureMask.Normal

-

绑定手势识别。

-

gesture: 绑定的手势类型, mask: 事件响应设置。

-

priorityGesture

-

gesture: GestureType,

-

mask?: GestureMask

-

gesture: -,

-

mask: GestureMask.Normal

-

绑定优先识别手势。

-

gesture: 绑定的手势类型, mask: 事件响应设置。

-
说明:
  • 默认情况下,子组件优先于父组件识别手势,当父组件配置priorityGesture时,父组件优先于子组件进行识别。
-
-

parallelGesture

-

gesture: GestureType,

-

mask?: GestureMask

-

gesture: -,

-

mask: GestureMask.Normal

-

绑定可与子组件手势同时触发的手势。

-

gesture: 绑定的手势类型, mask: 事件响应设置。

-
说明:
  • 手势事件为非冒泡事件。父组件设置parallelGesture时,父子组件相同的手势事件都可以触发,实现类似冒泡效果。
-
-
- -- GestureMask枚举说明 - - - - - - - - - - - - -

名称

-

描述

-

Normal

-

不屏蔽子组件的手势,按照默认手势识别顺序进行识别。

-

IgnoreInternal

-

屏蔽子组件的手势,仅当前容器的手势进行识别。

-
说明:

子组件上系统内置的手势不会被屏蔽,如子组件为List组件时,内置的滑动手势仍然会触发。

-
-
- - -- 系统提供如下Gesture类型 - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

描述

-

TapGesture

-

点击手势,支持单次点击、多次点击识别。

-

LongPressGesture

-

长按手势。

-

PanGesture

-

平移手势。

-

PinchGesture

-

捏合手势。

-

RotationGesture

-

旋转手势。

-

GestureGroup

-

手势识别组,多种手势组合为复合手势,支持连续识别、并行识别和互斥识别。

-
- - -## 响应手势事件 - -组件通过gesture方法绑定手势对象,可以通过手势对象提供的事件相应响应手势操作。如通过TapGesture对象的onAction事件响应点击事件。具体事件定义见各个手势对象章节。 - -- TapGesture事件说明 - - - - - - - - - -

名称

-

功能描述

-

onAction((event?: GestureEvent) => void)

-

Tap手势识别成功回调。

-
- - -- GestureEvent对象说明 - - - - - - - - - - - - - - - - -

属性名称

-

属性类型

-

描述

-

timestamp

-

number

-

事件时间戳。

-

target8+

-

EventTarget

-

触发手势事件的元素对象。

-
- - -## 示例 - -``` -@Entry -@Component -struct GestureSettingsExample { - @State value: string = '' - - build() { - Column(){ - Column() { - Text('Click\n' + this.value) - .gesture( - TapGesture() - .onAction(() => { - this.value = 'gesture onAction' - })) - }.height(200).width(300).padding(60).border({ width: 1 }) - //设置为priorityGesture时,会优先识别该绑定手势忽略内部gesture手势 - .priorityGesture( - TapGesture() - .onAction((event: GestureEvent) => { - this.value = 'priorityGesture onAction' + '\ncomponent globalPos:(' - + event.target.area.globalPos.x + ',' + event.target.area.globalPos.y + ')\nwidth:' - + event.target.area.width + '\nheight:' + event.target.area.height - }), GestureMask.IgnoreInternal - ) - }.padding(60) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475107.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/03.\346\211\213\345\212\277\345\244\204\347\220\206/02.\345\237\272\347\241\200\346\211\213\345\212\277/01.TapGesture.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/03.\346\211\213\345\212\277\345\244\204\347\220\206/02.\345\237\272\347\241\200\346\211\213\345\212\277/01.TapGesture.md" deleted file mode 100644 index f07387f2b9a3def8db30737003f998b53ac65cc8..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/03.\346\211\213\345\212\277\345\244\204\347\220\206/02.\345\237\272\347\241\200\346\211\213\345\212\277/01.TapGesture.md" +++ /dev/null @@ -1,118 +0,0 @@ ---- -title: TapGesture -permalink: /pages/010c02020101030201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:33 ---- -# TapGesture - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 权限列表 - -无 - -## 接口 - -TapGesture\(options?: \{ count?: number, fingers?: number \}\) - -- 参数 - - - - - - - - - - - - - - - - - - - - - -

参数名称

-

参数类型

-

必填

-

默认值

-

参数描述

-

count

-

number

-

-

1

-

识别的连续点击次数。如果设置小于1,会被转化为默认值。

-
说明:

如配置多击,上一次抬起和下一次按下的超时时间为300毫秒(ms)。

-
-

fingers

-

number

-

-

1

-

触发点击的最少手指数,最小为1指, 最大为10指。

-
说明:

1. 当配置多指时,第一根手指按下后300毫秒(ms)内未有足够的手指数按下,手势识别失败。

-

2. 实际点击手指数超过配置值,手势识别失败。

-
-
- - -## 事件 - - - - - - - - - -

名称

-

功能描述

-

onAction((event?: TapGestureEvent) => void)

-

Tap手势识别成功回调。

-
- -- TapGestureEvent类型说明8+ - - 继承自[GestureEvent](/pages/010c020201010301#table290mcpsimp)类型。 - - -## 示例 - -``` -@Entry -@Component -struct TapGestureExample { - @State value: string = '' - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) { - Text('Click twice') - Text(this.value) - } - .height(200).width(300).padding(60).border({ width: 1 }).margin(30) - .gesture( - TapGesture({ count: 2 }) - .onAction(() => { - this.value = 'TapGesture onAction' - }) - ) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/TapGesture.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/03.\346\211\213\345\212\277\345\244\204\347\220\206/02.\345\237\272\347\241\200\346\211\213\345\212\277/02.LongPressGesture.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/03.\346\211\213\345\212\277\345\244\204\347\220\206/02.\345\237\272\347\241\200\346\211\213\345\212\277/02.LongPressGesture.md" deleted file mode 100644 index 84a6a1735676254b7d4da152a8a6d035074b927b..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/03.\346\211\213\345\212\277\345\244\204\347\220\206/02.\345\237\272\347\241\200\346\211\213\345\212\277/02.LongPressGesture.md" +++ /dev/null @@ -1,156 +0,0 @@ ---- -title: LongPressGesture -permalink: /pages/010c02020101030202 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:33 ---- -# LongPressGesture - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 权限列表 - -无 - -## 接口 - -LongPressGesture\(options?: \{ fingers?: number, repeat?: boolean, duration?: number \}\) - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名称

-

参数类型

-

必填

-

默认值

-

参数描述

-

fingers

-

number

-

-

1

-

触发长按的最少手指数,最小为1指, 最大取值为10指。

-

repeat

-

boolean

-

-

false

-

是否连续触发事件回调。

-

duration

-

number

-

-

500

-

最小触发长按的时间,单位为毫秒(ms)。

-
- - -## 事件 - - - - - - - - - - - - - - - -

名称

-

功能描述

-

onAction((event?: LongPressGestureEvent) => void)

-

LongPress手势识别成功回调。

-

onActionEnd((event?: LongPressGestureEvent) => void)

-

LongPress手势识别成功,手指抬起后触发回调。

-

onActionCancel(event: () => void)

-

LongPress手势识别成功,接收到触摸取消事件触发回调。

-
- -- LongPressGestureEvent类型说明8+ - - 继承自[GestureEvent](/pages/010c020201010301#table290mcpsimp)类型。 - - - - - - - - - - - -

属性名称

-

属性类型

-

描述

-

repeat

-

boolean

-

事件是否为重复触发事件。

-
- - -## 示例 - -``` -@Entry -@Component -struct LongPressGestureExample { - @State count: number = 0 - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) { - Text('LongPress onAction:' + this.count) - } - .height(200).width(300).padding(60).border({ width:1 }).margin(30) - .gesture( - LongPressGesture({ repeat: true }) - //长按动作存在会连续触发 - .onAction((event: LongPressGestureEvent) => { - if (event.repeat) { this.count++ } - }) - //长按动作一结束触发 - .onActionEnd(() => { - this.count = 0 - }) - ) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/LongPressGesture.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/03.\346\211\213\345\212\277\345\244\204\347\220\206/02.\345\237\272\347\241\200\346\211\213\345\212\277/03.PanGesture.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/03.\346\211\213\345\212\277\345\244\204\347\220\206/02.\345\237\272\347\241\200\346\211\213\345\212\277/03.PanGesture.md" deleted file mode 100644 index 42e78998d080b10cbf3e284977fb05f9373ead3f..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/03.\346\211\213\345\212\277\345\244\204\347\220\206/02.\345\237\272\347\241\200\346\211\213\345\212\277/03.PanGesture.md" +++ /dev/null @@ -1,261 +0,0 @@ ---- -title: PanGesture -permalink: /pages/010c02020101030203 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:33 ---- -# PanGesture - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 权限列表 - -无 - -## 接口 - -PanGesture\(options?: \{ fingers?: number, direction?: PanDirection, distance?: number \} | [PanGestureOption](#section14214195212149)\) - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名称

-

参数类型

-

必填

-

默认值

-

参数描述

-

fingers

-

number

-

-

1

-

触发滑动的最少手指数,最小为1指, 最大取值为10指。

-

direction

-

PanDirection

-

-

All

-

设置滑动方向,此枚举值支持逻辑与(&)和逻辑或(|)运算。

-

distance

-

number

-

-

5.0

-

最小滑动识别距离,单位为vp。

-
- -- PanDirection枚举说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

描述

-

All

-

所有方向可滑动。

-

Horizontal

-

水平方向可滑动。

-

Vertical

-

竖直方向可滑动。

-

Left

-

向左滑动。

-

Right

-

向右滑动。

-

Up

-

向上滑动。

-

Down

-

向下滑动。

-

None

-

任何方向都不可滑动。

-
- - -### PanGestureOption - -通过PanGestureOption对象接口可以动态修改滑动手势识别器的属性,从而避免通过状态变量修改属性(状态变量修改会导致UI刷新)。 - -PanGestureOption\(options?: \{ fingers?: number, direction?: PanDirection, distance?: number \}\) - -- 参数 - - 同[PanGesture](#li118312377710)参数说明。 - - -- 接口 - - - - - - - - - - - - - - - -

名称

-

功能描述

-

setDirection(value: PanDirection)

-

设置direction属性。

-

setDistance(value: number)

-

设置distance属性。

-

setFingers(value: number)

-

设置fingers属性。

-
- - -## 事件 - - - - - - - - - - - - - - - - - - -

名称

-

功能描述

-

onActionStart(callback: (event?: PanGestureEvent) => void)

-

Pan手势识别成功回调。

-

onActionUpdate(callback: (event?: PanGestureEvent) => void)

-

Pan手势移动过程中回调。

-

onActionEnd(callback: (event?: PanGestureEvent) => void)

-

Pan手势识别成功,手指抬起后触发回调。

-

onActionCancel(callback: () => void)

-

Pan手势识别成功,接收到触摸取消事件触发回调。

-
- -- PanGestureEvent类型说明8+ - - 继承自[GestureEvent](/pages/010c020201010301#table290mcpsimp)类型。 - - - - - - - - - - - - - - - -

属性名称

-

属性类型

-

描述

-

offsetX

-

number

-

手势事件偏移量,单位为vp。

-

offsetY

-

number

-

手势事件偏移量,单位为vp。

-
- - -## 示例 - -``` -@Entry -@Component -struct PanGestureExample { - @State offsetX: number = 0 - @State offsetY: number = 0 - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) { - Text('PanGesture offset:\nX: ' + this.offsetX + '\n' + 'Y: ' + this.offsetY) - } - .height(100).width(200).padding(20).border({ width: 1 }).margin(80) - .translate({ x: this.offsetX, y: this.offsetY, z: 5 }) - .gesture( - PanGesture({}) - .onActionStart((event: PanGestureEvent) => { - console.info('Pan start') - }) - .onActionUpdate((event: PanGestureEvent) => { - this.offsetX = event.offsetX - this.offsetY = event.offsetY - }) - .onActionEnd(() => { - console.info('Pan end') - }) - ) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/PanGesture.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/03.\346\211\213\345\212\277\345\244\204\347\220\206/02.\345\237\272\347\241\200\346\211\213\345\212\277/04.PinchGesture.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/03.\346\211\213\345\212\277\345\244\204\347\220\206/02.\345\237\272\347\241\200\346\211\213\345\212\277/04.PinchGesture.md" deleted file mode 100644 index 1b3da9d1d336419df05c267936680c84c3769254..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/03.\346\211\213\345\212\277\345\244\204\347\220\206/02.\345\237\272\347\241\200\346\211\213\345\212\277/04.PinchGesture.md" +++ /dev/null @@ -1,166 +0,0 @@ ---- -title: PinchGesture -permalink: /pages/010c02020101030204 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:33 ---- -# PinchGesture - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 权限列表 - -无 - -## 接口 - -PinchGesture\(options?: \{ fingers?: number, distance?: number \}\) - -- 参数 - - - - - - - - - - - - - - - - - - - - - -

参数名称

-

参数类型

-

必填

-

默认值

-

参数描述

-

fingers

-

number

-

-

2

-

触发捏合的最少手指数, 最小为2指,最大为5指。

-

distance

-

number

-

-

3.0

-

最小识别距离,单位为vp。

-
- - -## 事件 - - - - - - - - - - - - - - - - - - -

名称

-

功能描述

-

onActionStart((event?: PinchGestureEvent) => void)

-

Pinch手势识别成功回调。

-

onActionUpdate((event?: PinchGestureEvent) => void)

-

Pinch手势移动过程中回调。

-

onActionEnd((event?: PinchGestureEvent) => void)

-

Pinch手势识别成功,手指抬起后触发回调。

-

onActionCancel(event: () => void)

-

Pinch手势识别成功,接收到触摸取消事件触发回调。

-
- -- PinchGestureEvent类型说明8+ - - 继承自[GestureEvent](/pages/010c020201010301#table290mcpsimp)类型。 - - - - - - - - - - - - - - - - - - - -

属性名称

-

属性类型

-

描述

-

scale

-

number

-

缩放比例,用于PinchGesture手势触发场景。

-

pinchCenterX

-

number

-

捏合手势中心点X轴坐标,单位为px。

-

pinchCenterY

-

number

-

捏合手势中心点Y轴坐标,单位为px。

-
- - -## 示例 - -``` -@Entry -@Component -struct PinchGestureExample { - @State scale: number = 1 - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) { - Text('PinchGesture scale:' + this.scale) - } - .height(100).width(200).padding(20).border({ width: 1 }).margin(80) - .scale({ x: this.scale, y: this.scale, z: this.scale }) - .gesture( - PinchGesture() - .onActionStart((event: PinchGestureEvent) => { - console.info('Pinch start') - }) - .onActionUpdate((event: PinchGestureEvent) => { - this.scale = event.scale - }) - .onActionEnd(() => { - console.info('Pinch end') - }) - ) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/PinchGesture.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/03.\346\211\213\345\212\277\345\244\204\347\220\206/02.\345\237\272\347\241\200\346\211\213\345\212\277/05.RotationGesture.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/03.\346\211\213\345\212\277\345\244\204\347\220\206/02.\345\237\272\347\241\200\346\211\213\345\212\277/05.RotationGesture.md" deleted file mode 100644 index d3818c3a7f189599131d08f28e0b7c67b05a32be..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/03.\346\211\213\345\212\277\345\244\204\347\220\206/02.\345\237\272\347\241\200\346\211\213\345\212\277/05.RotationGesture.md" +++ /dev/null @@ -1,166 +0,0 @@ ---- -title: RotationGesture -permalink: /pages/010c02020101030205 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:33 ---- -# RotationGesture - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 权限列表 - -无 - -## 接口 - -RotationGesture\(options?: \{ fingers?: number, angle?: number \}\) - -- 参数 - - - - - - - - - - - - - - - - - - - - - -

参数名称

-

参数类型

-

必填

-

默认值

-

参数描述

-

fingers

-

number

-

-

2

-

触发旋转的最少手指数, 最小为2指,最大为5指。

-

angle

-

number

-

-

1.0

-

触发旋转手势的最小改变度数,单位为度数。

-
- - -## 事件 - - - - - - - - - - - - - - - - - - -

名称

-

功能描述

-

onActionStart((event?: RotationGestureEvent) => void)

-

Rotation手势识别成功回调。

-

onActionUpdate((event?: RotationGestureEvent) => void)

-

Rotation手势移动过程中回调。

-

onActionEnd((event?: RotationGestureEvent) => void)

-

Rotation手势识别成功,手指抬起后触发回调。

-

onActionCancel(event: () => void)

-

Rotation手势识别成功,接收到触摸取消事件触发回调。

-
- -- RotationGestureEvent类型说明8+ - - 继承自[GestureEvent](/pages/010c020201010301#table290mcpsimp)类型。 - - - - - - - - - - - - - - - - - - - -

属性名称

-

属性类型

-

描述

-

angle

-

number

-

旋转角度。

-

pinchCenterX

-

number

-

捏合手势中心点X轴坐标,单位为px。

-

pinchCenterY

-

number

-

捏合手势中心点Y轴坐标,单位为px。

-
- - -## 示例 - -``` -@Entry -@Component -struct RotationGestureExample { - @State angle: number = 0 - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) { - Text('RotationGesture angle:' + this.angle) - } - .height(100).width(200).padding(20).border({ width:1 }) - .margin(80).rotate({ x:1, y:2, z:3, angle: this.angle }) - .gesture( - RotationGesture() - .onActionStart((event: RotationGestureEvent) => { - console.log('Rotation start') - }) - .onActionUpdate((event: RotationGestureEvent) => { - this.angle = event.angle - }) - .onActionEnd(() => { - console.log('Rotation end') - }) - ) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/RotationGesture.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/03.\346\211\213\345\212\277\345\244\204\347\220\206/02.\345\237\272\347\241\200\346\211\213\345\212\277/06.SwipeGesture.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/03.\346\211\213\345\212\277\345\244\204\347\220\206/02.\345\237\272\347\241\200\346\211\213\345\212\277/06.SwipeGesture.md" deleted file mode 100644 index 60f01b1a0c675f2d20861f9456ae729987e9a955..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/03.\346\211\213\345\212\277\345\244\204\347\220\206/02.\345\237\272\347\241\200\346\211\213\345\212\277/06.SwipeGesture.md" +++ /dev/null @@ -1,180 +0,0 @@ ---- -title: SwipeGesture -permalink: /pages/010c02020101030206 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:33 ---- -# SwipeGesture - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 权限列表 - -无 - -## 接口 - -SwipeGesture\(value?: \{ fingers?: number; direction?: SwipeDirection; speed?: number \}\) - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名称

-

参数类型

-

必填

-

默认值

-

参数描述

-

fingers

-

number

-

-

1

-

触发滑动的最少手指数,默认为1,最小为1指,最大为10指。

-

direction

-

SwipeDirection

-

-

SwipeDirection.All

-

滑动方向。

-

speed

-

number

-

-

100

-

识别滑动的最小速度(100VP/秒)。

-
- -- SwipeDirection枚举说明 - - - - - - - - - - - - - - - -

名称

-

描述

-

All

-

所有方向。

-

Horizontal

-

水平方向。

-

Vertical

-

竖直方向。

-
- - -## 事件 - - - - - - - - - -

名称

-

功能描述

-

onAction(callback:(event?: SwipeGestureEvent) => void)

-

滑动手势识别成功回调。

-
- -- SwipeGestureEvent类型说明 - - 继承自[GestureEvent](/pages/010c020201010301#table290mcpsimp)类型。 - - - - - - - - - - - - - - - -

参数名

-

类型

-

说明

-

angle

-

number

-

滑动手势的角度。

-

speed

-

number

-

滑动手势的速度。

-
- - -## 示例 - -``` -@Entry -@Component -struct SwipeGestureExample { - @State rotateAngle : number = 0 - @State speed : number = 1 - - build() { - Column() { - Text("SwipGesture speed : " + this.speed) - Text("SwipGesture angle : " + this.rotateAngle) - } - .position({x: 80, y: 200}) - .border({width:2}) - .width(260).height(260) - .rotate({x: 0, y: 0, z: 1, angle: this.rotateAngle}) - .gesture( - SwipeGesture({fingers: 1, direction:SwipeDirection.Vertical}) - .onAction((event: SwipeGestureEvent) => { - this.speed = event.speed - this.rotateAngle = event.angle - }) - ) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/GIF-0.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/03.\346\211\213\345\212\277\345\244\204\347\220\206/03.\347\273\204\345\220\210\346\211\213\345\212\277.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/03.\346\211\213\345\212\277\345\244\204\347\220\206/03.\347\273\204\345\220\210\346\211\213\345\212\277.md" deleted file mode 100644 index 285640cb243c8ab8ac7cee07c5b7d53bc4f8ab3f..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/01.\351\200\232\347\224\250/03.\346\211\213\345\212\277\345\244\204\347\220\206/03.\347\273\204\345\220\210\346\211\213\345\212\277.md" +++ /dev/null @@ -1,159 +0,0 @@ ---- -title: 组合手势 -permalink: /pages/010c020201010303 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:33 ---- -# 组合手势 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 权限列表 - -无 - -## 接口 - -GestureGroup\(mode: GestureMode, ...gesture: GestureType\[\]\) - -- 参数 - - - - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

mode

-

GestureMode

-

-

-

-

设置组合手势识别模式。

-

gesture

-

TapGesture

-

| LongPressGesture

-

| PanGesture

-

| PinchGesture

-

| RotationGesture

-

-

-

-

可变长参数,1个或者多个基础手势类型,这些手势会被组合识别。

-
- -- GestureMode枚举说明 - - - - - - - - - - - - - - - -

名称

-

描述

-

Sequence

-

顺序识别,按照手势的注册顺序识别手势,直到所有手势识别成功。当有一个手势识别失败时,所有手势识别失败。

-

Parallel

-

并发识别,注册的手势同时识别,直到所有手势识别结束,手势识别互相不影响。

-

Exclusive

-

互斥识别,注册的手势同时识别,若有一个手势识别成功,则结束手势识别。

-
- - -## 事件 - - - - - - - - - -

名称

-

功能描述

-

onCancel(event: () => void)

-

顺序组合手势(GestureMode.Sequence)取消后触发回调。

-
- -## 示例 - -``` -@Entry -@Component -struct GestureGroupExample { - @State count: number = 0 - @State offsetX: number = 0 - @State offsetY: number = 0 - @State borderStyle: BorderStyle = BorderStyle.Solid - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) { - Text('sequence gesture\n' + 'LongPress onAction:' + this.count + '\nPanGesture offset:\nX: ' + this.offsetX + '\n' + 'Y: ' + this.offsetY) - }.translate({ x: this.offsetX, y: this.offsetY, z: 5 }) - .height(100).width(200).padding(10).margin(80).border({ width: 1, style: this.borderStyle }) - .gesture( - GestureGroup(GestureMode.Sequence, - LongPressGesture({ repeat: true }) - .onAction((event: GestureEvent) => { - if (event.repeat) {this.count++} - console.log('LongPress onAction') - }) - .onActionEnd(() => { - console.log('LongPress end') - }), - PanGesture({}) - .onActionStart(() => { - this.borderStyle = BorderStyle.Dashed - console.log('pan start') - }) - .onActionUpdate((event: GestureEvent) => { - this.offsetX = event.offsetX - this.offsetY = event.offsetY - console.log('pan update') - }) - ) - .onCancel(() => { - console.log('sequence gesture canceled') - }) - ) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/GestureGroup.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/01.Blank.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/01.Blank.md" deleted file mode 100644 index 7e206606d75e3184f0ad3cc7b98be974eb897f03..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/01.Blank.md" +++ /dev/null @@ -1,114 +0,0 @@ ---- -title: Blank -permalink: /pages/010c0202010201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:33 ---- -# Blank - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -空白填充组件,在容器主轴方向上,空白填充组件具有自动填充容器空余部分的能力。仅当父组件为Row/Column时生效。 - -## 权限列表 - -无 - -## 子组件 - -无 - -## 接口 - -Blank\(min?: Length\) - -- 参数 - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

min

-

Length

-

-

0

-

空白填充组件在容器主轴上的最小大小。

-
- - -## 属性 - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

color

-

Color

-

0x00000000

-

设置空白填充的填充颜色。

-
- ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->- 不支持通用属性方法。 - -## 示例 - -``` -@Entry -@Component -struct BlankExample { - build() { - Column() { - Row() { - Text('Bluetooth').fontSize(18) - Blank() - Toggle({ type: ToggleType.Switch }) - }.width('100%').backgroundColor(0xFFFFFF).borderRadius(15).padding({ left: 12 }) - }.backgroundColor(0xEFEFEF).padding(20) - } -} -``` - -竖屏状态 - -![](/images/application-dev/reference/arkui-ts/figures/Blank1.gif) - -横屏状态 - -![](/images/application-dev/reference/arkui-ts/figures/Blank2.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/02.Button.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/02.Button.md" deleted file mode 100644 index 7f02528423ff83b62b060d5f48d310db19074481..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/02.Button.md" +++ /dev/null @@ -1,234 +0,0 @@ ---- -title: Button -permalink: /pages/010c0202010202 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:33 ---- -# Button - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -提供按钮组件。 - -## 权限列表 - -无 - -## 子组件 - -可以包含子组件。 - -## 接口 - -- Button\(options?: \{type?: ButtonType, stateEffect?: boolean\}\) - - **表 1** options参数说明 - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

type

-

ButtonType

-

-

Capsule

-

描述按钮风格。

-

stateEffect

-

boolean

-

-

true

-

按钮按下时是否开启切换效果,当状态置为false时,点击效果关闭。

-
- - -- Button\(label?: string, options?: \{ type?: ButtonType, stateEffect?: boolean \}\) - - 使用文本内容创建相应的按钮组件,此时Button无法包含子组件。 - - **表 2** value参数说明 - - - - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

label

-

string

-

-

-

-

按钮文本内容。

-

options

-

Object

-

-

-

-

options参数说明

-
- - -## 属性 - - - - - - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

type

-

ButtonType

-

Capsule

-

设置Button样式。

-

stateEffect

-

boolean

-

true

-

状态切换时是否开启切换效果,当状态置为false时,点击效果关闭。

-
- -- ButtonType枚举说明 - - - - - - - - - - - - - - - -

名称

-

描述

-

Capsule

-

胶囊型按钮(圆角默认为高度的一半)。

-

Circle

-

圆形按钮。

-

Normal

-

普通按钮(默认不带圆角)。

-
- - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->- 按钮圆角通过[通用属性borderRadius设置](/pages/010c020201010205)(不支持通过border接口设置圆角)。 ->- 按钮文本通过[通用文本样式](/pages/010c02020101020f)进行设置。 - -## 示例 - -``` -@Entry -@Component -struct ButtonExample { - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.SpaceBetween }) { - Text('Common button').fontSize(9).fontColor(0xCCCCCC) - Flex({ alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) { - Button('Ok', { type: ButtonType.Normal, stateEffect: true }).borderRadius(8).backgroundColor(0x317aff).width(90) - Button({ type: ButtonType.Normal, stateEffect: true }) { - Row() { - Image($r('app.media.loading')).width(20).height(20).margin({ left: 12 }) - Text('loading').fontSize(12).fontColor(0xffffff).margin({ left: 5, right: 12 }) - }.alignItems(VerticalAlign.Center) - }.borderRadius(8).backgroundColor(0x317aff).width(90) - Button('Disable', { type: ButtonType.Normal, stateEffect: false }).opacity(0.5) - .borderRadius(8).backgroundColor(0x317aff).width(90) - } - - Text('Capsule button').fontSize(9).fontColor(0xCCCCCC) - Flex({ alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) { - Button('Ok', { type: ButtonType.Capsule, stateEffect: true }).backgroundColor(0x317aff).width(90) - Button({ type: ButtonType.Capsule, stateEffect: true }) { - Row() { - Image($r('app.media.loading')).width(20).height(20).margin({ left: 12 }) - Text('loading').fontSize(12).fontColor(0xffffff).margin({ left: 5, right: 12 }) - }.alignItems(VerticalAlign.Center).width(90) - }.backgroundColor(0x317aff) - .onClick((event: ClickEvent) => { - AlertDialog.show({ message: 'The login is successful' }) - }) - Button('Disable', { type: ButtonType.Capsule, stateEffect: false }).opacity(0.5) - .backgroundColor(0x317aff).width(90) - } - - Text('Circle button').fontSize(9).fontColor(0xCCCCCC) - Flex({ alignItems: ItemAlign.Center, wrap: FlexWrap.Wrap }) { - Button({ type: ButtonType.Circle, stateEffect: true }) { - Image($r('app.media.ic_public_app_filled')).width(20).height(20) - }.width(55).height(55).backgroundColor(0x317aff) - Button({ type: ButtonType.Circle, stateEffect: true }) { - Image($r('app.media.ic_public_delete_filled')).width(30).height(30) - }.width(55).height(55).margin({ left: 20 }).backgroundColor(0xF55A42) - } - }.height(400).padding({ left: 35, right: 35, top: 35 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/Button.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/03.DataPanel.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/03.DataPanel.md" deleted file mode 100644 index 9e202c23b9dd95b3340146862d70c8dbd606e95a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/03.DataPanel.md" +++ /dev/null @@ -1,125 +0,0 @@ ---- -title: DataPanel -permalink: /pages/010c0202010203 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:33 ---- -# DataPanel - -数据面板组件,用于将多个数据占比情况使用占比图进行展示。 - -## 权限列表 - -无 - -## 子组件 - -无 - -## 接口 - -DataPanel\(value:\{values: number\[\], max?: number, type?: DataPanelType\}\) - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

values

-

number[]

-

-

-

-

数据值列表,最大支持9个数据。

-

max

-

number

-

-

100

-

1.max大于0,表示数据的最大值。

-

2.max小于等于0,max等于value数组各项的和,按比例显示。

-

type8+

-

DataPanelType

-

-

DataPanelType.Circle

-

数据面板的类型。

-
- - -- DataPanelType枚举说明 - - - - - - - - - - - - -

名称

-

描述

-

Line

-

线型数据面板。

-

Circle

-

环形数据面板。

-
- - -## 示例 - -``` -@Entry -@Component -struct DataPanelExample { - public values1: number[] = [10, 10, 10, 10, 10, 10, 10, 10, 10] - - build() { - Column({ space: 5 }) { - Text('Circle').fontSize(9).fontColor(0xCCCCCC).margin({ top: 20, right: '80%' }) - DataPanel({ values: this.values1, max: 100, type: DataPanelType.Circle }).width(200).height(200) - - Text('Line').fontSize(9).fontColor(0xCCCCCC).margin({ bottom: 20, right: '80%' }) - DataPanel({ values: this.values1, max: 100, type: DataPanelType.Line }).width(300).height(10) - }.width('100%').margin({ top: 5 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/datapanel.jpg) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/04.Divider.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/04.Divider.md" deleted file mode 100644 index 9199b7f0806f3d54266f15435684c7042061b99b..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/04.Divider.md" +++ /dev/null @@ -1,120 +0,0 @@ ---- -title: Divider -permalink: /pages/010c0202010204 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:33 ---- -# Divider - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -提供分隔器组件,分隔不同内容块/内容元素。 - -## 权限列表 - -无 - -## 子组件 - -无 - -## 接口 - -Divider\(\) - -## 属性 - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

vertical

-

boolean

-

false

-

使用水平分割线还是垂直分割线,false: 水平分割线, true:垂直分割线。

-

color

-

Color

-

-

-

设置分割线颜色。

-

strokeWidth

-

Length

-

1

-

设置分割线宽度。

-

lineCap

-

LineCapStyle

-

Butt

-

设置分割线条的端点样式,默认为Butt。

-
- -## 事件 - -不支持通用事件。 - -## 示例 - -``` -@Entry -@Component -struct DividerExample { - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.SpaceBetween }) { - Text('Horizontal divider').fontSize(9).fontColor(0xCCCCCC) - Row().width('100%').height(40).backgroundColor(0xF1F3F5) - Divider() - Row().width('100%').height(40).backgroundColor(0xF1F3F5) - - Text('Vertical divider').fontSize(9).fontColor(0xCCCCCC) - Flex({ alignItems: ItemAlign.Center, wrap: FlexWrap.Wrap }) { - Text('bravery') - Divider().vertical(true).margin(20).height(15) - Text('effort') - Divider().vertical(true).margin(20).height(15) - Text('upward') - }.width(250) - - Text('Custom Styles').fontSize(9).fontColor(0xCCCCCC) - Row().width('100%').height(40).backgroundColor(0xF1F3F5) - Divider().vertical(false).strokeWidth(5).color(0x2788D9).lineCap(LineCapStyle.Round) - Row().width('100%').height(40).backgroundColor(0xF1F3F5) - }.width('100%').height(350).padding({ left: 35, right: 35, top: 35 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/divider.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/05.Gauge.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/05.Gauge.md" deleted file mode 100644 index 5d6f29305c1e809009eee3287ab5ec102c15810b..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/05.Gauge.md" +++ /dev/null @@ -1,163 +0,0 @@ ---- -title: Gauge -permalink: /pages/010c0202010205 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:33 ---- -# Gauge - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -数据量规图表组件,用于将数据展示为环形图表。 - -## 权限列表 - -无 - -## 子组件 - -无 - -## 接口 - -Gauge\(value:\{value: number, min?: number, max?: number\}\) - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

value

-

number

-

-

-

-

当前数据值。

-

min

-

number

-

-

0

-

当前数据段最小值。

-

max

-

number

-

-

100

-

当前数据段最大值。

-
- - -## 属性 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

value

-

number

-

0

-

设置当前数据图表的值。

-

startAngle

-

Angle

-

-150

-

设置起始角度位置,时钟0点为0度,顺时针方向为正角度。

-

endAngle

-

Angle

-

150

-

设置终止角度位置,时钟0点为0度,顺时针方向为正角度。

-

colors

-

Color | Array<ColorStop>

-

-

-

设置图表的颜色,支持纯色和分段渐变色设置。

-

strokeWidth

-

Length

-

-

-

设置环形图表的环形厚度。

-
- -## 示例 - -``` -@Entry -@Component -struct GaugeExample { - build() { - Column() { - Gauge({ value: 50, min: 0, max: 100 }) - .startAngle(210).endAngle(150) - .colors([[0x317AF7, 1], [0x5BA854, 1], [0xE08C3A, 1], [0x9C554B, 1], [0xD94838, 1]]) - .strokeWidth(20) - .width(200).height(200) - }.width('100%').margin({ top: 5 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/gauge.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/06.Image.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/06.Image.md" deleted file mode 100644 index c799163c7c8279e87d43bd399f315d49a49bf9ec..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/06.Image.md" +++ /dev/null @@ -1,466 +0,0 @@ ---- -title: Image -permalink: /pages/010c0202010206 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:33 ---- -# Image - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -图片组件,用来渲染展示图片。 - -## 权限列表 - -ohos.permission.INTERNET(使用网络图片) - -## 子组件 - -无 - -## 接口 - -Image\(value: \{uri: string | PixelMap\}\) - -- 参数 - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

uri

-

string

-

-

-

-

图片的uri,支持本地图片和网络路径。

-
- - -## 属性 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

alt

-

string

-

-

-

加载时显示的占位图。支持本地图片和网络路径。

-

objectFit

-

ImageFit

-

Cover

-

设置图片的缩放类型。

-

objectRepeat

-

ImageRepeat

-

NoRepeat

-

设置图片的重复样式。

-
说明:
  • SVG类型图源不支持该属性。
-
-

interpolation

-

ImageInterpolation

-

None

-

设置图片的插值效果,仅针对图片放大插值。

-
说明:
  • SVG类型图源不支持该属性。
  • PixelMap资源不支持该属性。
-
-

renderMode

-

ImageRenderMode

-

Original

-

设置图片渲染的模式。

-
说明:
  • SVG类型图源不支持该属性。
-
-

sourceSize

-

{

-

width: number,

-

height: number

-

}

-

-

-

设置图片解码尺寸,将原始图片解码成指定尺寸的图片,number类型单位为px。

-
说明:

PixelMap资源不支持该属性。

-
-

syncLoad8+

-

boolean

-

false

-

设置是否同步加载图片,默认是异步加载。同步加载时阻塞UI线程,不会显示占位图。

-
- -- ImageFit枚举说明 - - - - - - - - - - - - - - - - - - - - - -

名称

-

描述

-

Cover

-

保持宽高比进行缩小或者放大,使得图片两边都大于或等于显示边界。

-

Contain

-

保持宽高比进行缩小或者放大,使得图片完全显示在显示边界内。

-

Fill

-

不保持宽高比进行放大缩小,使得图片填充满显示边界。

-

None

-

保持原有尺寸显示。通常配合objectRepeat属性一起使用。

-

ScaleDown

-

保持宽高比显示,图片缩小或者保持不变。

-
- - -- ImageInterpolation枚举说明 - - - - - - - - - - - - - - - - - - -

名称

-

描述

-

None

-

不使用插值图片数据。

-

High

-

高度使用插值图片数据,可能会影响图片渲染的速度。

-

Medium

-

中度使用插值图片数据。

-

Low

-

低度使用插值图片数据。

-
- - -- ImageRenderMode枚举说明 - - - - - - - - - - - - -

名称

-

描述

-

Original

-

按照原图进行渲染,包括颜色。

-

Template

-

将图像渲染为模板图像,忽略图片的颜色信息。

-
- - -## 事件 - - - - - - - - - - - - - - - -

名称

-

功能描述

-

onComplete(callback: (event?: { width: number, height: number, componentWidth: number, componentHeight: number, loadingStatus: number }) => void)

-

图片成功加载时触发该回调,返回成功加载的图源尺寸。

-

onError(callback: (event?: { componentWidth: number, componentHeight: number }) => void)

-

图片加载出现异常时触发该回调。

-

onFinish(callback: () => void)

-

当加载的源文件为带动效的svg图片时,当svg动效播放完成时会触发这个回调,如果动效为无限循环动效,则不会触发这个回调。

-
- -## 示例 - -``` -// Image1 -@Entry -@Component -struct ImageExample1 { - private on: string = 'http://uxd.rnd.huawei.com/uxIcon/file/2021-08/d2d6e6c6-043f-471e-80e3-57199142201e.svg' - @State src: string = this.on - - build() { - Column() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start }) { - Text('default').fontSize(16).fontColor(0xcccccc).height(30) - Row({ space: 5 }) { - Image($r('app.media.ic_png')) - .width(110).height(110).border({ width: 1 }).borderStyle(BorderStyle.Dashed) - .overlay('png', { align: Alignment.Bottom, offset: { x: 0, y: 20 } }) - Image($r('app.media.ic_gif')) - .width(110).height(110).border({ width: 1 }).borderStyle(BorderStyle.Dashed) - .overlay('gif', { align: Alignment.Bottom, offset: { x: 0, y: 20 } }) - Image($r('app.media.ic_svg')) - .width(110).height(110).border({ width: 1 }).borderStyle(BorderStyle.Dashed) - .overlay('svg', { align: Alignment.Bottom, offset: { x: 0, y: 20 } }) - } - Row({ space: 5 }) { - Image($r('app.media.img_example')) - .width(110).height(110).border({ width: 1 }).borderStyle(BorderStyle.Dashed) - .overlay('jpg', { align: Alignment.Bottom, offset: { x: 0, y: 20 } }) - Image(this.src) - .width(110).height(110).border({ width: 1 }).borderStyle(BorderStyle.Dashed) - .overlay('network', { align: Alignment.Bottom, offset: { x: 0, y: 20 } }) - }.margin({ top: 25, bottom: 10 }) - } - - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start }) { - Text('objectFit').fontSize(16).fontColor(0xcccccc).height(30) - Row({ space: 5 }) { - Image($r('app.media.img_example')) - .border({ width: 1 }).borderStyle(BorderStyle.Dashed) - .objectFit(ImageFit.None).width(110).height(110) - .overlay('None', { align: Alignment.Bottom, offset: { x: 0, y: 20 } }) - Image($r('app.media.img_example')) - .border({ width: 1 }).borderStyle(BorderStyle.Dashed) - .objectFit(ImageFit.Fill).width(110).height(110) - .overlay('Fill', { align: Alignment.Bottom, offset: { x: 0, y: 20 } }) - Image($r('app.media.img_example')) - .border({ width: 1 }).borderStyle(BorderStyle.Dashed) - .objectFit(ImageFit.Cover).width(110).height(110) - .overlay('Cover', { align: Alignment.Bottom, offset: { x: 0, y: 20 } }) - } - Row({ space: 5 }) { - Image($r('app.media.img_example_w250')) - .border({ width: 1 }).borderStyle(BorderStyle.Dashed) - .objectFit(ImageFit.Contain).width(110).height(110) - .overlay('Contain', { align: Alignment.Bottom, offset: { x: 0, y: 20 } }) - Image($r('app.media.img_example_w250')) - .border({ width: 1 }).borderStyle(BorderStyle.Dashed) - .objectFit(ImageFit.ScaleDown).width(110).height(110) - .overlay('ScaleDown', { align: Alignment.Bottom, offset: { x: 0, y: 20 } }) - }.margin({ top: 25 }) - } - }.height(320).width(360).padding({ right: 10, top: 10 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/Image1.gif) - -``` -// Image2 -@Entry -@Component -struct ImageExample2 { - @State width: number = 100 - @State height: number = 100 - - build() { - Column({ space: 10 }) { - Text('renderMode').fontSize(12).fontColor(0xcccccc).width('96%').height(30) - Row({ space: 50 }) { - Image($r('app.media.img_example')) - .renderMode(ImageRenderMode.Original).width(100).height(100) - .border({ width: 1 }).borderStyle(BorderStyle.Dashed) - .overlay('Original', { align: Alignment.Bottom, offset: { x: 0, y: 20 } }) - Image($r('app.media.img_example')) - .renderMode(ImageRenderMode.Template).width(100).height(100) - .border({ width: 1 }).borderStyle(BorderStyle.Dashed) - .overlay('Template', { align: Alignment.Bottom, offset: { x: 0, y: 20 } }) - } - - Text('alt').fontSize(12).fontColor(0xcccccc).width('96%').height(30) - Image('') - .alt($r('app.media.Image_none')) - .width(100).height(100).border({ width: 1 }).borderStyle(BorderStyle.Dashed) - - Text('sourceSize').fontSize(12).fontColor(0xcccccc).width('96%') - Row({ space: 50 }) { - Image($r('app.media.img_example')) - .sourceSize({ - width: 150, - height: 150 - }) - .objectFit(ImageFit.ScaleDown).width('25%').aspectRatio(1) - .border({ width: 1 }).borderStyle(BorderStyle.Dashed) - .overlay('w:150 h:150', { align: Alignment.Bottom, offset: { x: 0, y: 20 } }) - Image($r('app.media.img_example')) - .sourceSize({ - width: 200, - height: 200 - }) - .objectFit(ImageFit.ScaleDown).width('25%').aspectRatio(1) - .border({ width: 1 }).borderStyle(BorderStyle.Dashed) - .overlay('w:200 h:200', { align: Alignment.Bottom, offset: { x: 0, y: 20 } }) - } - - Text('objectRepeat').fontSize(12).fontColor(0xcccccc).width('96%').height(30) - Row({ space: 5 }) { - Image($r('app.media.ic_health_heart')) - .width(120).height(125).border({ width: 1 }).borderStyle(BorderStyle.Dashed) - .objectRepeat(ImageRepeat.XY).objectFit(ImageFit.ScaleDown) - .overlay('ImageRepeat.XY', { align: Alignment.Bottom, offset: { x: 0, y: 20 } }) - Image($r('app.media.ic_health_heart')) - .width(110).height(125).border({ width: 1 }).borderStyle(BorderStyle.Dashed) - .objectRepeat(ImageRepeat.Y).objectFit(ImageFit.ScaleDown) - .overlay('ImageRepeat.Y', { align: Alignment.Bottom, offset: { x: 0, y: 20 } }) - Image($r('app.media.ic_health_heart')) - .width(110).height(125).border({ width: 1 }).borderStyle(BorderStyle.Dashed) - .objectRepeat(ImageRepeat.X).objectFit(ImageFit.ScaleDown) - .overlay('ImageRepeat.X', { align: Alignment.Bottom, offset: { x: 0, y: 20 } }) - } - }.height(150).width('100%').padding({ right: 10 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/Image2.png) - -``` -// Image3 -@Entry -@Component -struct ImageExample3 { - @State width: number = 0 - @State height: number = 0 - private on: Resource = $r('app.media.wifi_on') - private off: Resource = $r('app.media.wifi_off') - private on2off: Resource = $r('app.media.wifi_on2off') - private off2on: Resource = $r('app.media.wifi_off2on') - @State src: Resource = this.on - - build() { - Column() { - Row({ space: 20 }) { - Column() { - Image($r('app.media.img_example1')) - .alt($r('app.media.ic_public_picture')) - .sourceSize({ - width: 900, - height: 900 - }) - .objectFit(ImageFit.Cover) - .height(180).width(180) - .onComplete((msg: { width: number,height: number }) => { - this.width = msg.width - this.height = msg.height - }) - .onError(() => { - console.log('load image fail') - }) - .overlay('\nwidth: ' + String(this.width) + ' height: ' + String(this.height), { - align: Alignment.Bottom, - offset: { x: 0, y: 20 } - }) - } - - Image(this.src) - .width(120).height(120) - .onClick(() => { - if (this.src == this.on || this.src == this.off2on) { - this.src = this.on2off - } else { - this.src = this.off2on - } - }) - .onFinish(() => { - if (this.src == this.off2on) { - this.src = this.on - } else { - this.src = this.off - } - }) - } - }.width('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/Image3.gif) \ No newline at end of file diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/07.ImageAnimator.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/07.ImageAnimator.md" deleted file mode 100644 index 7f956d634069afa72d5705dc1dd173496445f784..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/07.ImageAnimator.md" +++ /dev/null @@ -1,344 +0,0 @@ ---- -title: ImageAnimator -permalink: /pages/010c0202010207 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:33 ---- -# ImageAnimator - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -提供帧动画组件来实现逐帧播放图片的能力,可以配置需要播放的图片列表,每张图片可以配置时长。 - -## 权限列表 - -无 - -## 子组件 - -无 - -## 接口 - -ImageAnimator\(\) - -## 属性 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名称

-

参数类型

-

默认值

-

必填

-

参数描述

-

images

-

Array<{

-

src:string,

-

width?:Length,

-

height?:Length,

-

top?:Length,

-

left?:Length,

-

duration?:number

-

}>

-

[]

-

-

设置图片帧信息集合。每一帧的帧信息包含图片路径、图片大小、图片位置和图片播放时长信息。详细说明如下:

-

src:图片路径,图片格式为svg,png和jpg。

-

width:图片宽度。

-

height:图片高度。

-

top:图片相对于组件左上角的纵向坐标。

-

left:图片相对于组件左上角的横向坐标。

-

duration:每一帧图片的播放时长,单位毫秒。

-

state

-

AnimationStatus

-

Initial

-

-

默认为初始状态,用于控制播放状态。

-

duration

-

number

-

1000

-

-

单位为毫秒,默认时长为1000ms;duration为0时,不播放图片;值的改变只会在下一次循环开始时生效;当images中设置了单独的duration后,该属性设置无效。

-

reverse

-

boolean

-

false

-

-

设置播放顺序。false表示从第1张图片播放到最后1张图片; true表示从最后1张图片播放到第1张图片。

-

fixedSize

-

boolean

-

true

-

-

设置图片大小是否固定为组件大小。 true表示图片大小与组件大小一致,此时设置图片的width 、height 、top 和left属性是无效的。false表示每一张图片的 width 、height 、top和left属性都要单独设置。

-

preDecode

-

number

-

0

-

-

是否启用预解码,默认值为0,即不启用预解码,如该值设为2,则播放当前页时会提前加载后面两张图片至缓存以提升性能。

-

fillMode

-

FillMode

-

Forwards

-

-

设置动画开始前和结束后的状态,可选值参见FillMode说明。

-

iterations

-

number

-

1

-

-

默认播放一次,设置为-1时表示无限次播放。

-
- -- AnimationStatus枚举说明 - - - - - - - - - - - - - - - - - - -

名称

-

描述

-

Initial

-

动画初始状态

-

Running

-

动画处于播放状态。

-

Paused

-

动画处于暂停状态。

-

Stopped

-

动画处于停止状态。

-
- - -- FillMode枚举值说明 - - - - - - - - - - - - - - - - - - -

名称

-

描述

-

None

-

播放完成后恢复初始状态。

-

Forwards

-

播放完成后保持动画结束时的状态。

-

Backwards

-

在animation-delay所指定的一段时间内,在动画显示之前,应用开始属性值。

-

Both

-

向前和向后填充模式都被应用。

-
- - -## 事件 - - - - - - - - - - - - - - - - - - - - - -

名称

-

功能描述

-

onStart() => void

-

状态回调,动画开始播放时触发。

-

onPause() => void

-

状态回调,动画暂停播放时触发。

-

onRepeat() => void

-

状态回调,动画重新播放时触发。

-

onCancel() => void

-

状态回调,动画取消播放时触发。

-

onFinish() => void

-

状态回调,动画播放完成时触发。

-
- -## 示例 - -``` -@Entry -@Component -struct ImageAnimatorExample { - @State state: AnimationStatus = AnimationStatus.Initial - @State reverse: boolean = false - @State iterations: number = 1 - - build() { - Column({ space:5 }) { - ImageAnimator() - .images([ - { - src: '/comment/bg1.jpg', - duration: 500, - width: 325, - height: 200, - top: 0, - left: 0 - }, - { - src: '/comment/bg2.jpg', - duration: 500, - width: 325, - height: 200, - top: 0, - left: 0 - }, - { - src: '/comment/bg3.jpg', - duration: 500, - width: 325, - height: 200, - top: 0, - left: 0 - }, - { - src: '/comment/bg4.jpg', - duration: 500, - width: 325, - height: 200, - top: 0, - left: 0 - } - ]) - .state(this.state).reverse(this.reverse).fixedSize(false).preDecode(2) - .fillMode(FillMode.None).iterations(this.iterations).width(325).height(210) - .margin({top:100}) - .onStart(() => { // 当帧动画开始播放后触发 - console.info('Start') - }) - .onPause(() => { - console.info('Pause') - }) - .onRepeat(() => { - console.info('Repeat') - }) - .onCancel(() => { - console.info('Cancel') - }) - .onFinish(() => { // 当帧动画播放完成后触发 - console.info('Finish') - }) - Row() { - Button('start').width(100).padding(5).onClick(() => { - this.state = AnimationStatus.Running - }) - Button('pause').width(100).padding(5).onClick(() => { - this.state = AnimationStatus.Paused - }) - Button('stop').width(100).padding(5).onClick(() => { - this.state = AnimationStatus.Stopped - }) - } - Row() { - Button('reverse').width(100).padding(5).onClick(() => { - this.reverse = !this.reverse - }) - Button('once').width(100).padding(5).onClick(() => { - this.iterations = 1 - }) - Button('iteration').width(100).padding(5).onClick(() => { - this.iterations = -1 - }) - } - }.width('100%').height('100%').backgroundColor(0xF1F3F5) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/ImageAnimator.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/08.Progress.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/08.Progress.md" deleted file mode 100644 index 7472d9cf32d06b05d086023a083629fbee187a25..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/08.Progress.md" +++ /dev/null @@ -1,156 +0,0 @@ ---- -title: Progress -permalink: /pages/010c0202010208 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:33 ---- -# Progress - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -进度条,用于显示内容加载或操作处理进度。 - -## 权限列表 - -无 - -## 子组件 - -无 - -## 接口说明 - -Progress\(value: \{value: number, total?: number, style?: ProgressStyle\}\) - -创建指定进度的进度条。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

value

-

number

-

-

-

-

指定当前进度值。

-

total

-

number

-

-

100

-

指定进度总长。

-

style

-

ProgressStyle

-

-

Linear

-

指定进度条样式。

-
- - -- ProgressStyle枚举说明 - - - - - - - - - - -

名称

-

描述

-

Linear

-

线性进度条样式。

-
- - -## 属性 - - - - - - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

value

-

number

-

-

-

设置当前进度值。

-

color

-

Color

-

-

-

设置进度条前景色。

-
- -## 示例 - -``` -@Entry -@Component -struct ProgressExample { - build() { - Column({ space: 5 }) { - Text('Linear Progress').fontSize(9).fontColor(0xCCCCCC).width('90%') - Progress({ value: 10, style: ProgressStyle.Linear }).width(200) - - Text('Linear Progress Color').fontSize(9).fontColor(0xCCCCCC).width('90%') - Progress({ value: 20, total: 150, style: ProgressStyle.Linear }).color(Color.Red).value(50).width(200) - }.width('100%').margin({ top: 5 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/progress.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/09.QRCode.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/09.QRCode.md" deleted file mode 100644 index 19419e857648b44aa65fe5576bfb14ffd891199f..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/09.QRCode.md" +++ /dev/null @@ -1,111 +0,0 @@ ---- -title: QRCode -permalink: /pages/010c0202010209 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:33 ---- -# QRCode - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -显示二维码信息。 - -## 权限列表 - -无 - -## 子组件 - -无 - -## 接口 - -QRCode\(value: string\) - -- 参数 - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

value

-

string

-

-

-

-

二维码内容字符串。

-
- - -## 属性 - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

color

-

Color

-

Black

-

设置二维码颜色。

-
- -## 事件 - -通用事件仅支持点击事件。 - -## 示例 - -``` -@Entry -@Component -struct QRCodeExample { - private value: string = 'hello world' - - build() { - Column({ space: 5 }) { - Text('normal').fontSize(9).width('90%').fontColor(0xCCCCCC) - QRCode(this.value).width(200).height(200) - - Text('color').fontSize(9).width('90%').fontColor(0xCCCCCC) - QRCode(this.value).color(0xF7CE00).width(200).height(200) - }.width('100%').margin({ top: 5 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/qrcode.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/10.Rating.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/10.Rating.md" deleted file mode 100644 index 10d05be4781ca3bfbb9add31b5a073496c924fd6..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/10.Rating.md" +++ /dev/null @@ -1,161 +0,0 @@ ---- -title: Rating -permalink: /pages/010c020201020a -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:33 ---- -# Rating - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -评分条组件。 - -## 权限列表 - -无 - -## 子组件 - -无 - -## 接口说明 - -Rating\(options?: \{ rating: number, indicator?: boolean \}\) - -- 参数 - - - - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

rating

-

number

-

-

0

-

设置并接收评分值。

-

indicator

-

boolean

-

-

false

-

仅作为指示器使用,不可操作。

-
- - -## 属性 - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

stars

-

number

-

5

-

设置评星总数。

-

stepSize

-

number

-

0.5

-

操作评级的步长。

-

starStyle

-

{

-

backgroundUri: string,

-

foregroundUri: string,

-

secondaryUri?: string

-

}

-

-

-

backgroundSrc:未选中的星级的图片链接,可由用户自定义或使用系统默认图片,仅支持本地。

-

foregroundSrc:选中的星级的图片路径,可由用户自定义或使用系统默认图片,仅支持本地。

-

secondarySrc:部分选中的星级的图片路径,可由用户自定义或使用系统默认图片,仅支持本地。

-
- -## 事件 - - - - - - - - - -

名称

-

功能描述

-

onChange(callback:(value: number) => void)

-

操作评分条的评星发生改变时触发该回调。

-
- -## 示例 - -``` -@Entry -@Component -struct RatingExample { - @State rating: number = 1 - @State indicator: boolean = false - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) { - Text('current score is ' + this.rating).fontSize(20) - Rating({ rating: this.rating, indicator: this.indicator }) - .stars(5) - .stepSize(0.5) - .onChange((value: number) => { - this.rating = value - }) - }.width(350).height(200).padding(35) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/Rating.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/11.Span.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/11.Span.md" deleted file mode 100644 index 2a365ccd9a36b3aba543a21d322d302fcbb94934..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/11.Span.md" +++ /dev/null @@ -1,149 +0,0 @@ ---- -title: Span -permalink: /pages/010c020201020b -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:33 ---- -# Span - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -文本段落,只能作为Text子组件,呈现一段文本信息。 - -## 权限列表 - -无 - -## 子组件 - -无 - -## 接口 - -Span\(content: string\) - -- 参数 - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

content

-

string

-

-

-

-

文本内容。

-
- - -## 属性 - -通用属性方法仅支持通用文本样式,不支持触摸热区设置。 - - - - - - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

decoration

-

{

-

type: TextDecorationType,

-

color?: Color

-

}

-

{

-

type: TextDecorationType.None

-

}

-

设置文本装饰线样式及其颜色。

-

textCase

-

TextCase

-

Normal

-

设置文本大小写。

-
- -## 事件 - -通用事件仅支持点击事件。 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->由于Span组件无尺寸信息,因此点击事件返回的ClickEvent对象的target属性无效。 - -## 示例 - -``` -@Entry -@Component -struct SpanExample { - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.SpaceBetween }) { - Text('Basic Usage').fontSize(9).fontColor(0xCCCCCC) - Text() { - Span('This is the Span component').fontSize(12).textCase(TextCase.Normal) - .decoration({ type: TextDecorationType.None, color: Color.Red }) - } - - Text('Text Decoration').fontSize(9).fontColor(0xCCCCCC) - Text() { - Span('I am Underline-span').decoration({ type: TextDecorationType.Underline, color: Color.Red }).fontSize(12) - } - Text() { - Span('I am LineThrough-span').decoration({ type: TextDecorationType.LineThrough, color: Color.Red }).fontSize(12) - } - Text() { - Span('I am Overline-span').decoration({ type: TextDecorationType.Overline, color: Color.Red }).fontSize(12) - } - - Text('Text Case').fontSize(9).fontColor(0xCCCCCC) - Text() { - Span('I am Lower-span').textCase(TextCase.LowerCase).fontSize(12) - .decoration({ type: TextDecorationType.None, color: Color.Red }) - } - Text() { - Span('I am Upper-span').textCase(TextCase.UpperCase).fontSize(12) - .decoration({ type: TextDecorationType.None, color: Color.Red }) - } - }.width('100%').height(250).padding({ left: 35, right: 35, top: 35 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/Span.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/12.Slider.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/12.Slider.md" deleted file mode 100644 index 3d0f47cd8167028f894cfd730e96e8b69fc315d6..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/12.Slider.md" +++ /dev/null @@ -1,357 +0,0 @@ ---- -title: Slider -permalink: /pages/010c020201020c -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:33 ---- -# Slider - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -滑动条组件,用来快速调节设置值,如音量、亮度等。 - -## 权限列表 - -无 - -## 子组件 - -无 - -## 接口 - -Slider\(value:\{value?: number, min?: number, max?: number, step?: number, style?: SliderStyle, direction?: Axis\}\) - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

value

-

number

-

-

0

-

当前进度值。

-

min

-

number

-

-

0

-

设置最小值。

-

max

-

number

-

-

100

-

设置最大值。

-

step

-

number

-

-

1

-

设置Slider滑动跳动值,当设置相应的step时,Slider为间歇滑动。

-

style

-

SliderStyle

-

-

SliderStyle.OutSet

-

设置Slider的滑块样式。

-

direction8+

-

Axis

-

-

Axis.Horizontal

-

设置滑动条滑动方向为水平或竖直方向。

-
- -- SliderStyle枚举说明 - - - - - - - - - - - - -

名称

-

描述

-

OutSet

-

滑块在滑轨上。

-

InSet

-

滑块在滑轨内。

-
- - -## 属性 - -不支持触摸热区设置。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

blockColor

-

Color

-

-

-

设置滑块的颜色。

-

trackColor

-

Color

-

-

-

设置滑轨的背景颜色。

-

selectedColor

-

Color

-

-

-

设置滑轨的已滑动颜色。

-

showSteps

-

boolean

-

false

-

设置当前是否显示步长刻度值。

-

showTips

-

boolean

-

false

-

设置滑动时是否显示气泡提示百分比。

-
- -## 事件 - -通用事件仅支持:OnAppear,OnDisAppear。 - - - - - - - - - -

名称

-

功能描述

-

onChange(callback: (value: number, mode: SliderChangeMode) => void)

-

Slider滑动时触发事件回调。

-

value:当前进度值。

-

mode:拖动状态。

-
- -- SliderChangeMode枚举说明 - - - - - - - - - - - - - - - -

名称

-

描述

-

Begin

-

用户开始拖动滑块。

-

Moving

-

用户拖动滑块中。

-

End

-

用户结束拖动滑块。

-
- - -## 示例 - -``` -@Entry -@Component -struct SliderExample { - @State outSetValue: number = 40 - @State inSetValue: number = 40 - @State outVerticalSetValue: number = 40 - @State inVerticalSetValue: number = 40 - - build() { - Column({ space: 5 }) { - Text('slider out set').fontSize(9).fontColor(0xCCCCCC).width('90%') - Row() { - Slider({ - value: this.outSetValue, - min: 0, - max: 100, - step: 1, - style: SliderStyle.OutSet - }) - .blockColor(Color.Blue) - .trackColor(Color.Gray) - .selectedColor(Color.Blue) - .showSteps(true) - .showTips(true) - .onChange((value: number, mode: SliderChangeMode) => { - this.outSetValue = value - console.info('value:' + value + 'mode:' + mode.toString()) - }) - Text(this.outSetValue.toFixed(0)).fontSize(16) - } - .padding({ top: 50 }) - .width('80%') - - Text('slider in set').fontSize(9).fontColor(0xCCCCCC).width('90%') - Row() { - Slider({ - value: this.inSetValue, - min: 0, - max: 100, - step: 1, - style: SliderStyle.InSet - }) - .blockColor(0xCCCCCC) - .trackColor(Color.Black) - .selectedColor(0xCCCCCC) - .showSteps(false) - .showTips(false) - .onChange((value: number, mode: SliderChangeMode) => { - this.inSetValue = value - console.info('value:' + value + 'mode:' + mode.toString()) - }) - Text(this.inSetValue.toFixed(0)).fontSize(16) - } - .width('80%') - - Row() { - Column() { - Text('slider out direction set').fontSize(9).fontColor(0xCCCCCC).width('50%') - Slider({ - value: this.outVerticalSetValue, - min: 0, - max: 100, - step: 1, - style: SliderStyle.OutSet, - direction: Axis.Vertical - }) - .blockColor(Color.Blue) - .trackColor(Color.Gray) - .selectedColor(Color.Blue) - .showSteps(true) - .showTips(true) - .onChange((value: number, mode: SliderChangeMode) => { - this.outVerticalSetValue = value - console.info('value:' + value + 'mode:' + mode.toString()) - }) - Text(this.outVerticalSetValue.toFixed(0)).fontSize(16) - }.width('50%').height(300) - - Column() { - Text('slider in direction set').fontSize(9).fontColor(0xCCCCCC).width('50%') - Slider({ - value: this.inVerticalSetValue, - min: 0, - max: 100, - step: 1, - style: SliderStyle.InSet, - direction: Axis.Vertical - }) - .blockColor(0xCCCCCC) - .trackColor(Color.Black) - .selectedColor(0xCCCCCC) - .showSteps(false) - .showTips(false) - .onChange((value: number, mode: SliderChangeMode) => { - this.inVerticalSetValue = value - console.info('value:' + value + 'mode:' + mode.toString()) - }) - Text(this.inVerticalSetValue.toFixed(0)).fontSize(16) - }.width('50%').height(300) - } - - }.width('100%').margin({ top: 5 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/slider.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/13.Text.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/13.Text.md" deleted file mode 100644 index fb99db700bc7c2bbeabf42053904d001699692c6..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/13.Text.md" +++ /dev/null @@ -1,343 +0,0 @@ ---- -title: Text -permalink: /pages/010c020201020d -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:33 ---- -# Text - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -文本,用于呈现一段信息。 - -## 权限列表 - -无 - -## 子组件 - -可以包含[Span](/pages/010c020201020b)子组件。 - -## 接口 - -Text\(content?: string\) - -- 参数 - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

content

-

string

-

-

''

-

文本内容,包含子组件Span时不生效,显示Span内容。

-
- - -## 属性 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

textAlign

-

TextAlign

-

Start

-

设置多行文本的文本对齐方式。

-

textOverflow

-

{overflow: TextOverflow}

-

{overflow: TextOverflow.Clip}

-

设置文本超长时的显示方式。

-

maxLines

-

number

-

Infinity

-

设置文本的最大行数。

-

lineHeight

-

Length

-

-

-

设置文本的文本行高,设置值不大于0时,不限制文本行高,自适应字体大小,Length为number类型时单位为fp。

-

decoration

-

{

-

type: TextDecorationType,

-

color?: Color

-

}

-

{

-

type: TextDecorationType.None,

-

color:Color.Black

-

}

-

设置文本装饰线样式及其颜色。

-

baselineOffset

-

Length

-

-

-

设置文本基线的偏移量。

-

textCase

-

TextCase

-

Normal

-

设置文本大小写。

-
- -- TextAlign枚举说明 - - - - - - - - - - - - - - - -

名称

-

描述

-

Center

-

文本居中对齐。

-

Start

-

根据文字书写相同的方向对齐。

-

End

-

根据文字书写相反的方向对齐。

-
- - -- TextOverflow枚举说明 - - - - - - - - - - - - - - - -

名称

-

描述

-

Clip

-

文本超长时进行裁剪显示。

-

Ellipsis

-

文本超长时显示不下的文本用省略号代替。

-

None

-

文本超长时不进行裁剪。

-
- - -- TextDecorationType枚举说明 - - - - - - - - - - - - - - - - - - -

名称

-

描述

-

Underline

-

文字下划线修饰。

-

LineThrough

-

穿过文本的修饰线。

-

Overline

-

文字上划线修饰。

-

None

-

不使用文本装饰线。

-
- - -- TextCase枚举说明 - - - - - - - - - - - - - - - -

名称

-

描述

-

Normal

-

保持文本原有大小写。

-

LowerCase

-

文本采用全小写。

-

UpperCase

-

文本采用全大写。

-
- - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->不支持Text内同时存在文本内容和Span子组件。(如果同时存在,只显示Span内的内容\)。 - -## 示例 - -``` -@Entry -@Component -struct TextExample1 { - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.SpaceBetween }) { - Text('lineHeight').fontSize(9).fontColor(0xCCCCCC) - Text('This is the text with the line height set This is the text with the line height set This is the text with the line height set.') - .lineHeight(25).fontSize(12).border({ width: 1 }).padding(10) - - Text('TextOverflow').fontSize(9).fontColor(0xCCCCCC) - Text('This is the setting of textOverflow to none text content This is the setting of textOverflow to none text content.') - .textOverflow({ overflow: TextOverflow.None }) - .fontSize(12).border({ width: 1 }).padding(10) - Text('This is the setting of textOverflow to Clip text content This is the setting of textOverflow to Clip text content.') - .textOverflow({ overflow: TextOverflow.Clip }) - .maxLines(1).fontSize(12).border({ width: 1 }).padding(10) - Text('This is set textOverflow to Ellipsis text content This is set textOverflow to Ellipsis text content.') - .textOverflow({ overflow: TextOverflow.Ellipsis }) - .maxLines(1).fontSize(12).border({ width: 1 }).padding(10) - - Text('decoration').fontSize(9).fontColor(0xCCCCCC) - Text('This is the text content with the decoration set to Underline and the color set to Red.') - .decoration({ type: TextDecorationType.Underline, color: Color.Red }) - .fontSize(12).border({ width: 1 }).padding(10) - Text('This is the text content with the decoration set to LineThrough and the color set to Red.') - .decoration({ type: TextDecorationType.LineThrough, color: Color.Red }) - .fontSize(12).border({ width: 1 }).padding(10) - Text('This is the text content with the decoration set to Overline and the color set to Red.') - .decoration({ type: TextDecorationType.Overline, color: Color.Red }) - .fontSize(12).border({ width: 1 }).padding(10) - }.height(600).width(350).padding({ left: 35, right: 35, top: 35 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/Text1.gif) - -``` -@Entry -@Component -struct TextExample2 { - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.SpaceBetween }) { - Text('textCase').fontSize(9).fontColor(0xCCCCCC) - Text('This is the text content with textCase set to Normal.') - .textCase(TextCase.Normal) - .fontSize(12).border({ width: 1 }).padding(10).width('100%') - Text('This is the text content with textCase set to LowerCase.') - .textCase(TextCase.LowerCase) - .fontSize(12).border({ width: 1 }).padding(10).width('100%') - Text('This is the text content with textCase set to UpperCase.') - .textCase(TextCase.UpperCase) - .fontSize(12).border({ width: 1 }).padding(10) - - Text('textAlign').fontSize(9).fontColor(0xCCCCCC) - Text('This is the text content with textAlign set to Center.') - .textAlign(TextAlign.Center) - .fontSize(12).border({ width: 1 }).padding(10).width('100%') - Text('This is the text content with textAlign set to Start.') - .textAlign(TextAlign.Start) - .fontSize(12).border({ width: 1 }).padding(10).width('100%') - Text('This is the text content with textAlign set to End.') - .textAlign(TextAlign.End) - .fontSize(12).border({ width: 1 }).padding(10).width('100%') - - Text('baselineOffset').fontSize(9).fontColor(0xCCCCCC) - Text('This is the text content with baselineOffset set to 10.') - .baselineOffset(10).fontSize(12).border({ width: 1 }).padding(10).width('100%') - Text('This is the text content with baselineOffset set to 30.') - .baselineOffset(30).fontSize(12).border({ width: 1 }).padding(10).width('100%') - Text('This is the text content with baselineOffset set to -10.') - .baselineOffset(-10).fontSize(12).border({ width: 1 }).padding(10).width('100%') - }.height(700).width(350).padding({ left: 35, right: 35, top: 35 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/Text2.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/14.TextArea.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/14.TextArea.md" deleted file mode 100644 index 1473fd22cc646b600172a4ec0673a2b59d6e4ad6..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/14.TextArea.md" +++ /dev/null @@ -1,196 +0,0 @@ ---- -title: TextArea -permalink: /pages/010c020201020e -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:33 ---- -# TextArea - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -提供多行文本输入组件。 - -## 权限列表 - -无 - -## 子组件 - -无 - -## 接口 - -TextArea\(value?: \{ placeholder?: string \}\) - -- 参数 - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

placeholder

-

string

-

-

-

-

无输入时的提示文本。

-
- - -## 属性 - -除支持[通用属性](/pages/extra/b89109/)外,还支持以下属性: - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

placeholderColor

-

Color

-

-

-

设置placeholder文本颜色。

-

placeholderFont

-

{

-

size?: number,

-

weight?:number | FontWeight,

-

family?: string,

-

style?: FontStyle

-

}

-

-

-

设置placeholder文本样式:

-
  • size: 设置文本尺寸,Length为number类型时,使用fp单位。
  • weight: 设置文本的字体粗细,number类型取值[100, 900],取值间隔为100,默认为400,取值越大,字体越粗。
  • family: 设置文本的字体列表。使用多个字体,使用','进行分割,优先级按顺序生效。例如:'Arial, sans-serif'。
  • style: 设置文本的字体样式。
-

textAlign

-

TextAlign

-

TextAlign.Start

-

设置文本水平对齐方式。

-

caretColor

-

Color

-

-

-

设置输入框光标颜色。

-
- -- TextAlign枚举说明 - - - - - - - - - - - - - - - -

名称

-

描述

-

Start

-

水平对齐首部。

-

Center

-

水平居中对齐。

-

End

-

水平对齐尾部。

-
- - -## 事件 - - - - - - - - - - -

名称

-

功能描述

-

onChange(callback: (value: string) => void)

-

输入发生变化时,触发回调。

-
- -## 示例 - -``` -@Entry -@Component -struct TextAreaExample { - @State text: string = '' - - build() { - Column() { - TextArea({ placeholder: 'input your word' }) - .placeholderColor("rgb(0,0,225)") - .placeholderFont({ size: 30, weight: 100, family: 'cursive', style: FontStyle.Italic }) - .textAlign(TextAlign.Center) - .caretColor(Color.Blue) - .height(50) - .fontSize(30) - .fontWeight(FontWeight.Bold) - .fontFamily("sans-serif") - .fontStyle(FontStyle.Normal) - .fontColor(Color.Red) - .onChange((value: string) => { - this.text = value - }) - Text(this.text).width('90%') - } - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/textarea1.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/15.TextInput.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/15.TextInput.md" deleted file mode 100644 index 1f4da6227f9cad273b8774417aa3eb7a6a63acd6..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/15.TextInput.md" +++ /dev/null @@ -1,276 +0,0 @@ ---- -title: TextInput -permalink: /pages/010c020201020f -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:33 ---- -# TextInput - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -提供单行文本输入组件。 - -## 权限列表 - -无 - -## 子组件 - -无 - -## 接口 - -TextInput\(value?: \{ placeholder?: string \}\) - -- 参数 - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

placeholder

-

string

-

-

-

-

无输入时的提示文本。

-
- - -## 属性 - -除支持[通用属性](/pages/extra/b89109/)外,还支持以下属性: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

type

-

InputType

-

InputType.Normal

-

设置输入框类型。

-

placeholderColor

-

Color

-

-

-

设置placeholder颜色。

-

placeholderFont

-

{

-

size?: Length,

-

weight?: number | FontWeight,

-

family?: string,

-

style?: FontStyle

-

}

-

-

-

设置placeholder文本样式:

-
  • size: 设置文本尺寸,Length为number类型时,使用fp单位。
  • weight: 设置文本的字体粗细,number类型取值[100, 900],取值间隔为100,默认为400,取值越大,字体越粗。
  • family: 设置文本的字体列表。使用多个字体,使用','进行分割,优先级按顺序生效。例如:'Arial, sans-serif'。
  • style: 设置文本的字体样式。
-

enterKeyType

-

EnterKeyType

-

EnterKeyType.Done

-

设置输入法回车键类型。

-

caretColor

-

Color

-

-

-

设置输入框光标颜色。

-

maxLength

-

number

-

-

-

设置文本的最大输入字符数。

-
- -- EnterKeyType枚举说明 - - - - - - - - - - - - - - - - - - - - - -

名称

-

描述

-

Go

-

显示Go文本。

-

Search

-

显示为搜索样式。

-

Send

-

显示为发送样式。

-

Next

-

显示为下一个样式。

-

Done

-

标准样式。

-
- - -- InputType枚举说明 - - - - - - - - - - - - - - - - - - -

名称

-

描述

-

Normal

-

基本输入模式。

-

Password

-

密码输入模式。

-

Email

-

e-mail地址输入模式。

-

Number

-

纯数字输入模式。

-
- - -## 事件 - - - - - - - - - - - - - - - -

名称

-

功能描述

-

onChange(value: string) => void

-

输入发生变化时,触发回调。

-

onSubmit(callback: (enterKey: EnterKeyType) => void)

-

回车键或者软键盘回车键触发该回调,参数为当前软键盘回车键类型。

-

onEditChanged(callback: (isEditing: boolean) => void)

-

输入状态变化时,触发回调。

-
- -## 示例 - -``` -@Entry -@Component -struct TextInputTest { - @State text: string = '' - @State text1: string = '' - @State text2: string = '' - build() { - Column() { - TextInput({ placeholder: 'input your word' }) - .type(InputType.Normal) - .placeholderColor(Color.Blue) - .placeholderFont({ size: 40, weight: FontWeight.Normal, family: "sans-serif", style: FontStyle.Normal }) - .enterKeyType(EnterKeyType.Next) - .caretColor(Color.Green) - .height(60) - .fontSize(30) - .fontWeight(FontWeight.Bold) - .fontFamily("cursive") - .fontStyle(FontStyle.Italic) - .fontColor(Color.Red) - .maxLength(20) - .onChange((value: string) => { - this.text = value - }) - .onSubmit((enterKey) => { - this.text1 = 'onSubmit' - }) - .onEditChanged((isEditing) => { - this.text2 = 'onEditChanged' - }) - Text(this.text) - Text(this.text1) - Text(this.text2) - } - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/textinput1.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/16.Toggle.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/16.Toggle.md" deleted file mode 100644 index 036219a9e992c335a7f2200ea39e5b9b9082c621..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/02.\345\237\272\347\241\200\347\273\204\344\273\266/16.Toggle.md" +++ /dev/null @@ -1,217 +0,0 @@ ---- -title: Toggle -permalink: /pages/010c0202010210 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:33 ---- -# Toggle - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 权限列表 - -无 - -## 子组件 - -无 - -## 接口 - -Toggle\(options: \{ type: ToggleType, isOn?: boolean \}\) - -- 参数 - - - - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

type

-

ToggleType

-

-

-

-

创建相应的开关状态组件。

-

isOn

-

boolean

-

-

false

-

设置开关状态组件初始化状态。

-
说明:

在创建组件时不设置isOn,组件复用时可保持选中状态;如设置isOn初始值,则需要在通过事件方法记录选中状态已达到组件复用时保持选中状态。

-
-
- - -- ToggleType枚举说明 - - - - - - - - - - - - - - - -

名称

-

描述

-

Checkbox

-

提供单选框样式,子组件设置文本不生效,如需文本设置,可将Text和当前组件放入布局组件中。

-

Button

-

提供状态按钮样式,如果有文本设置,则相应的文本内容会显示在按钮内部。

-

Switch

-

提供开关样式,子组件设置文本不生效,如需文本设置,可将Text和当前组件放入布局组件中。

-
- - -## 属性 - - - - - - - - - - - - - - - - - - -

名称

-

参数

-

默认值

-

参数描述

-

selectedColor

-

Color

-

-

-

设置组件打开状态的背景颜色。

-

switchPointColor

-

Color

-

-

-

设置Switch类型的圆形滑块颜色。

-
说明:

仅对type为ToggleType.Switch生效。

-
-
- -## 事件 - - - - - - - - - -

名称

-

功能描述

-

onChange(callback: (isOn: boolean) => void)

-

开关状态切换时触发该事件。

-
- -## 示例 - -``` -@Entry -@Component -struct ToggleExample { - build() { - Column({ space: 10 }) { - Text('type: Switch').fontSize(12).fontColor(0xcccccc).width('90%') - Flex({ justifyContent: FlexAlign.SpaceEvenly, alignItems: ItemAlign.Center }) { - Toggle({ type: ToggleType.Switch, isOn: false }) - .selectedColor(0xed6f21) - .switchPointColor(0xe5ffffff) - .onChange((isOn: boolean) => { - console.info('Component status:' + isOn) - }) - - Toggle({ type: ToggleType.Switch, isOn: true }) - .selectedColor(0x39a2db) - .switchPointColor(0xe5ffffff) - .onChange((isOn: boolean) => { - console.info('Component status:' + isOn) - }) - } - - Text('type: Checkbox').fontSize(12).fontColor(0xcccccc).width('90%') - Flex({ justifyContent: FlexAlign.SpaceEvenly, alignItems: ItemAlign.Center }) { - Toggle({ type: ToggleType.Checkbox, isOn: false }) - .size({ width: 28, height: 28 }) - .selectedColor(0xed6f21) - .onChange((isOn: boolean) => { - console.info('Component status:' + isOn) - }) - - Toggle({ type: ToggleType.Checkbox, isOn: true }) - .size({ width: 28, height: 28 }) - .selectedColor(0x39a2db) - .onChange((isOn: boolean) => { - console.info('Component status:' + isOn) - }) - } - - Text('type: Button').fontSize(12).fontColor(0xcccccc).width('90%') - Flex({ justifyContent: FlexAlign.SpaceEvenly, alignItems: ItemAlign.Center }) { - Toggle({ type: ToggleType.Button, isOn: false }) { - Text('status button').padding({ left: 12, right: 12 }) - } - .selectedColor(0xed6f21) - .onChange((isOn: boolean) => { - console.info('Component status:' + isOn) - }) - - Toggle({ type: ToggleType.Button, isOn: true }) { - Text('status button').padding({ left: 12, right: 12 }) - } - .selectedColor(0x39a2db) - .onChange((isOn: boolean) => { - console.info('Component status:' + isOn) - }) - } - }.width('100%').padding(24) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/toggle.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/01.AlphabetIndexer.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/01.AlphabetIndexer.md" deleted file mode 100644 index fdd813c37762d460a394342b16d3f5cfcaa9e400..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/01.AlphabetIndexer.md" +++ /dev/null @@ -1,272 +0,0 @@ ---- -title: AlphabetIndexer -permalink: /pages/010c0202010301 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:33 ---- -# AlphabetIndexer - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -字母索引条。 - -## 支持设备 - - - - - - - - - - - - - -

手机

-

平板

-

智慧屏

-

智能穿戴

-

支持

-

支持

-

不支持

-

不支持

-
- -## 权限列表 - -无 - -## 子组件 - -无 - -## 接口 - -AlphabetIndexer\(value: \{arrayValue : Array, selected : number\}\) - -- 参数 - - - - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

arrayValue

-

Array<string>

-

-

-

-

字母索引字符串数组。

-

selected

-

number

-

-

-

-

选中项编号。

-
- - -## 属性 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数类型

-

描述

-

selectedColor

-

Color

-

选中文本文字颜色。

-

popupColor

-

Color

-

弹出提示文本字体颜色。

-

selectedBackgroundColor

-

Color

-

选中文本背景颜色。

-

popupBackground

-

Color

-

弹窗索引背景色。

-

usingPopup

-

boolean

-

是否使用弹出索引提示。

-

selectedFont

-

{

-

size?: number,

-

weight?: FontWeight,

-

family?: string,

-

style?: FontStyle

-

}

-

选中文本文字样式。

-

popupFont

-

{

-

size?: number,

-

weight?: FontWeight,

-

family?: string,

-

style?: FontStyle

-

}

-

弹出提示文本字体样式。

-

font

-

{

-

size?: number,

-

weight?: FontWeight,

-

family?: string,

-

style?: FontStyle

-

}

-

字母索引条默认文本字体样式。

-

itemSize

-

Length

-

字母索引条字母区域大小,字母区域为正方形,设置正方形边长。

-

alignStyle

-

IndexerAlign

-

字母索引条对齐样式,支持左侧对齐样式与右侧对齐样式,影响弹窗弹出位置。

-
- -- IndexerAlign枚举说明 - - - - - - - - - - - - -

名称

-

描述

-

Left

-

弹框显示在索引条右侧。

-

Right

-

弹框显示在索引条左侧。

-
- - -## 事件 - - - - - - - - - - - - - - - -

名称

-

功能描述

-

onSelected(index: number) => void

-

字母索引条选中回调。

-

onRequestPopupData(callback: (index: number) => Array<string>)8+

-

选中字母索引后,请求索引提示窗口显示内容回调。

-

返回值:索引对应的字符串数组,此字符串数组在弹出窗口中竖排显示,字符串列表最多显示5个,超出部分可以滑动显示。

-

onPopupSelected(callback: (index: number) => void)8+

-

字母索引提示窗口选中回调。

-
- -## 示例 - -``` -@Entry -@Component -struct AlphabetIndexerComponent { - private value: string[] = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'] - - build() { - AlphabetIndexer({ arrayValue: this.value, selected: 0 }) - .selectedColor(0xffffff) // 选中颜色 - .popupColor(0xFFFAF0) // 弹出框颜色 - .selectedBackgroundColor(0xCCCCCC) // 选中背景颜色 - .popupBackground(0xD2B48C) // 弹出框背景颜色 - .usingPopup(true) // 是否显示弹出框 - .selectedFont({ size: 16, weight: FontWeight.Bolder }) // 选中的样式 - .popupFont({ size: 30, weight: FontWeight.Bolder }) // 弹出框的演示 - .itemSize(28) // 每一项的大小正方形 - .alignStyle(IndexerAlign.Left) // 左对齐 - .onSelected((index: number) => { - console.info(this.value[index] + '被选中了') // 选中的事件 - }) - .margin({ left: 50 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/alphabetindexer.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/02.Badge.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/02.Badge.md" deleted file mode 100644 index 92f0f23f9b5bf00c73a3b7d8ca80c393bfff98d8..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/02.Badge.md" +++ /dev/null @@ -1,286 +0,0 @@ ---- -title: Badge -permalink: /pages/010c0202010302 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:33 ---- -# Badge - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -新事件标记组件,在组件上提供事件信息展示能力。 - -## 权限列表 - -无 - -## 子组件 - -支持单个子组件。 - -## 接口 - -Badge\(value: \{count: number, position?: BadgePosition, maxCount?: number, style?: BadgeStyle\}\) - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

count

-

number

-

-

-

-

设置提醒消息数。

-

position

-

BadgePosition

-

-

RightTop

-

设置提示点显示位置。

-

maxCount

-

number

-

-

99

-

最大消息数,超过最大消息时仅显示maxCount+。

-

style

-

BadgeStyle

-

-

-

-

Badge组件可设置样式,支持设置文本颜色、尺寸、圆点颜色和尺寸。

-
- - -Badge\(value: \{value: string, position?: BadgePosition, style?: BadgeStyle\}\) - -根据字符串创建提醒组件。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

value

-

string

-

-

-

-

提示内容的文本字符串。

-

position

-

BadgePosition

-

-

RightTop

-

设置提示点显示位置。

-

style

-

BadgeStyle

-

-

-

-

Badge组件可设置样式,支持设置文本颜色、尺寸、圆点颜色和尺寸。

-
- - -- BadgeStyle对象说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

必填

-

默认值

-

描述

-

color

-

Color

-

-

White

-

文本颜色。

-

fontSize

-

number | string

-

-

10

-

文本大小。

-

badgeSize

-

number | string

-

-

-

-

badge的大小。

-

badgeColor

-

Color

-

-

Red

-

badge的颜色。

-
- - -- BadgePosition枚举说明 - - - - - - - - - - - - - - - -

名称

-

描述

-

Right

-

圆点显示在右侧纵向居中。

-

RightTop

-

圆点显示在右上角。

-

Left

-

圆点显示在左侧纵向居中。

-
- - -## 示例 - -``` -@Entry -@Component -struct BadgeExample { - @State counts: number = 1 - @State message: string = 'new' - - build() { - Flex({ justifyContent: FlexAlign.SpaceAround }) { - Badge({ - count: this.counts, - maxCount: 99, - style: { color: 0xFFFFFF, fontSize: 16, badgeSize: 20, badgeColor: Color.Red } - }) { - Button('message') - .onClick(() => { - this.counts++ - }) - .width(100).height(50).backgroundColor(0x317aff) - }.width(100).height(50) - - Badge({ - value: this.message, - style: { color: 0xFFFFFF, fontSize: 9, badgeSize: 20, badgeColor: Color.Blue } - }) { - Text('message') - .width(80).height(50).fontSize(16).lineHeight(37) - .borderRadius(10).textAlign(TextAlign.Center).backgroundColor(0xF3F4ED) - }.width(80).height(50) - - Badge({ - value: '', - position: 1, - style: { badgeSize: 6, badgeColor: Color.Red } - }) { - Text('message') - .width(90).height(50).fontSize(16).lineHeight(37) - .borderRadius(10).textAlign(TextAlign.Center).backgroundColor(0xF3F4ED) - }.width(90).height(50) - }.width('100%').margin({ top: 5 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/badge.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/03.Column.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/03.Column.md" deleted file mode 100644 index 4e0f7a180df403bd27a7ad2a253a9cb1baa0b453..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/03.Column.md" +++ /dev/null @@ -1,166 +0,0 @@ ---- -title: Column -permalink: /pages/010c0202010303 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:33 ---- -# Column - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -沿垂直方向布局的容器。 - -## 权限列表 - -无 - -## 子组件 - -可以包含子组件。 - -## 接口 - -Column\(value:\{space?: Length\}\) - -- 参数 - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

space

-

Length

-

-

0

-

纵向布局元素间距。

-
- - - -## 属性 - - - - - - - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

alignItems

-

HorizontalAlign

-

Center

-

设置子组件在水平方向上的对齐格式。

-

justifyContent8+

-

FlexAlign

-

Start

-

设置子组件在垂直方向上的对齐格式。

-
- -- HorizontalAlign枚举说明 - - - - - - - - - - - - - - - -

名称

-

描述

-

Start

-

按照语言方向起始端对齐。

-

Center

-

居中对齐,默认对齐方式。

-

End

-

按照语言方向末端对齐。

-
- - -## 示例 - -``` -@Entry -@Component -struct ColumnExample { - build() { - Text('space').fontSize(9).fontColor(0xCCCCCC).width('90%') - Column({ space: 5 }) { - Column().width('100%').height(30).backgroundColor(0xAFEEEE) - Column().width('100%').height(30).backgroundColor(0x00FFFF) - }.width('90%').height(100).border({ width: 1 }) - - Text('alignItems(Start)').fontSize(9).fontColor(0xCCCCCC).width('90%') - Column() { - Column().width('50%').height(30).backgroundColor(0xAFEEEE) - Column().width('50%').height(30).backgroundColor(0x00FFFF) - }.alignItems(HorizontalAlign.Start).width('90%').border({ width: 1 }) - - Text('alignItems(End)').fontSize(9).fontColor(0xCCCCCC).width('90%') - Column() { - Column().width('50%').height(30).backgroundColor(0xAFEEEE) - Column().width('50%').height(30).backgroundColor(0x00FFFF) - }.alignItems(HorizontalAlign.End).width('90%').border({ width: 1 }) - - Text('justifyContent(Center)').fontSize(9).fontColor(0xCCCCCC).width('90%') - Column() { - Column().width('30%').height(30).backgroundColor(0xAFEEEE) - Column().width('30%').height(30).backgroundColor(0x00FFFF) - }.height('15%').border({ width: 1 }).justifyContent(FlexAlign.Center) - - Text('justifyContent(End)').fontSize(9).fontColor(0xCCCCCC).width('90%') - Column() { - Column().width('30%').height(30).backgroundColor(0xAFEEEE) - Column().width('30%').height(30).backgroundColor(0x00FFFF) - }.height('15%').border({ width: 1 }).justifyContent(FlexAlign.End) - }.width('100%').padding({ top: 5 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/Column.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/04.ColumnSplit.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/04.ColumnSplit.md" deleted file mode 100644 index 844e8e633b5941f7e4986c24e6fe465628c4b9bf..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/04.ColumnSplit.md" +++ /dev/null @@ -1,80 +0,0 @@ ---- -title: ColumnSplit -permalink: /pages/010c0202010304 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:33 ---- -# ColumnSplit - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -将子组件纵向布局,并在每个子组件之间插入一根横向的分割线。 - -## 权限列表 - -无 - -## 子组件 - -可以包含子组件。 - -## 接口 - -ColumnSplit\(\) - -## 属性 - - - - - - - - - - - -

名称

-

参数类型

-

描述

-

resizeable

-

boolean

-

分割线是否可拖拽,默认为false。

-
- ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->与RowSplit相同,ColumnSplit的分割线最小能拖动到刚好包含子组件。 - -## 示例 - -``` -@Entry -@Component -struct ColumnSplitExample { - build() { - Column(){ - Text('The secant line can be dragged').fontSize(9).fontColor(0xCCCCCC).width('90%') - ColumnSplit() { - Text('1').width('100%').height(50).backgroundColor(0xF5DEB3).textAlign(TextAlign.Center) - Text('2').width('100%').height(50).backgroundColor(0xD2B48C).textAlign(TextAlign.Center) - Text('3').width('100%').height(50).backgroundColor(0xF5DEB3).textAlign(TextAlign.Center) - Text('4').width('100%').height(50).backgroundColor(0xD2B48C).textAlign(TextAlign.Center) - Text('5').width('100%').height(50).backgroundColor(0xF5DEB3).textAlign(TextAlign.Center) - } - .resizeable(true) - .width('90%').height('60%') - }.width('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/ColumnSplit.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/05.Counter.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/05.Counter.md" deleted file mode 100644 index 8e7848164bd6865c465707be5b3427003731d5dd..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/05.Counter.md" +++ /dev/null @@ -1,81 +0,0 @@ ---- -title: Counter -permalink: /pages/010c0202010305 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:33 ---- -# Counter - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -计数器组件,提供相应的增加或者减少的计数操作。 - -## 权限列表 - -无 - -## 子组件 - -可以包含子组件。 - -## 接口 - -Counter\(\) - -## 事件 - -不支持通用事件和手势, 仅支持如下事件: - - - - - - - - - - - - -

名称

-

功能描述

-

onInc(event: () => void)

-

监听数值增加事件。

-

onDec(event: () => void)

-

监听数值减少事件。

-
- -## 示例 - -``` -@Entry -@Component -struct CounterExample { - @State value: number = 0 - - build() { - Column() { - Counter() { - Text(this.value.toString()) - }.margin(100) - .onInc(() => { - this.value++ - }) - .onDec(() => { - this.value-- - }) - }.width("100%") - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/Counter.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/06.Flex.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/06.Flex.md" deleted file mode 100644 index a19994ad91407e0f7bcc9a68d372f05ac89c8c03..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/06.Flex.md" +++ /dev/null @@ -1,467 +0,0 @@ ---- -title: Flex -permalink: /pages/010c0202010306 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:34 ---- -# Flex - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -弹性布局组件。 - -## 权限列表 - -无 - -## 子组件 - -可以包含子组件。 - -## 接口 - -Flex\(options?: \{ direction?: FlexDirection, wrap?: FlexWrap, justifyContent?: FlexAlign, alignItems?: ItemAlign, alignContent?: FlexAlign \}\) - -标准Flex布局容器。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

direction

-

FlexDirection

-

-

Row

-

子组件在Flex容器上排列的方向,即主轴的方向。

-

wrap

-

FlexWrap

-

-

NoWrap

-

Flex容器是单行/列还是多行/列排列。

-

justifyContent

-

FlexAlign

-

-

Start

-

子组件在Flex容器主轴上的对齐格式。

-

alignItems

-

ItemAlign

-

-

Stretch

-

子组件在Flex容器交叉轴上的对齐格式。

-

alignContent

-

FlexAlign

-

-

Start

-

交叉轴中有额外的空间时,多行内容的对齐方式。仅在wrap为Wrap或WrapReverse下生效。

-
- -- FlexDirection枚举说明 - - - - - - - - - - - - - - - - - - -

名称

-

描述

-

Row

-

主轴与行方向一致作为布局模式。

-

RowReverse

-

与Row方向相反方向进行布局。

-

Column

-

主轴与列方向一致作为布局模式。

-

ColumnReverse

-

与Column相反方向进行布局。

-
- - -- FlexWrap枚举说明 - - - - - - - - - - - - - - - -

名称

-

描述

-

NoWrap

-

Flex容器的元素单行/列布局,子项允许超出容器。

-

Wrap

-

Flex容器的元素多行/列排布,子项允许超出容器。

-

WrapReverse

-

Flex容器的元素反向多行/列排布,子项允许超出容器。

-
- - -- FlexAlign枚举说明 - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

描述

-

Start

-

元素在主轴方向首端对齐, 第一个元素与行首对齐,同时后续的元素与前一个对齐。

-

Center

-

元素在主轴方向中心对齐,第一个元素与行首的距离与最后一个元素与行尾距离相同。

-

End

-

元素在主轴方向尾部对齐, 最后一个元素与行尾对齐,其他元素与后一个对齐。

-

SpaceBetween

-

Flex主轴方向均匀分配弹性元素,相邻元素之间距离相同。 第一个元素与行首对齐,最后一个元素与行尾对齐。

-

SpaceAround

-

Flex主轴方向均匀分配弹性元素,相邻元素之间距离相同。 第一个元素到行首的距离和最后一个元素到行尾的距离时相邻元素之间距离的一半。

-

SpaceEvenly

-

Flex主轴方向元素等间距布局, 相邻元素之间的间距、第一个元素与行首的间距、最后一个元素到行尾的间距都完全一样。

-
- - -## 示例 - -``` -// Example 01 -@Entry -@Component -struct FlexExample1 { - build() { - Column() { - Column({ space: 5 }) { - Text('direction:Row').fontSize(9).fontColor(0xCCCCCC).width('90%') - Flex({ direction: FlexDirection.Row }) { - Text('1').width('20%').height(50).backgroundColor(0xF5DEB3) - Text('2').width('20%').height(50).backgroundColor(0xD2B48C) - Text('3').width('20%').height(50).backgroundColor(0xF5DEB3) - Text('4').width('20%').height(50).backgroundColor(0xD2B48C) - } - .height(70) - .width('90%') - .padding(10) - .backgroundColor(0xAFEEEE) - - Text('direction:RowReverse').fontSize(9).fontColor(0xCCCCCC).width('90%') - Flex({ direction: FlexDirection.RowReverse }) { - Text('1').width('20%').height(50).backgroundColor(0xF5DEB3) - Text('2').width('20%').height(50).backgroundColor(0xD2B48C) - Text('3').width('20%').height(50).backgroundColor(0xF5DEB3) - Text('4').width('20%').height(50).backgroundColor(0xD2B48C) - } - .height(70) - .width('90%') - .padding(10) - .backgroundColor(0xAFEEEE) - - Text('direction:Column').fontSize(9).fontColor(0xCCCCCC).width('90%') - Flex({ direction: FlexDirection.Column }) { - Text('1').width('100%').height(40).backgroundColor(0xF5DEB3) - Text('2').width('100%').height(40).backgroundColor(0xD2B48C) - Text('3').width('100%').height(40).backgroundColor(0xF5DEB3) - Text('4').width('100%').height(40).backgroundColor(0xD2B48C) - } - .height(160) - .width('90%') - .padding(10) - .backgroundColor(0xAFEEEE) - - Text('direction:ColumnReverse').fontSize(9).fontColor(0xCCCCCC).width('90%') - Flex({ direction: FlexDirection.ColumnReverse }) { - Text('1').width('100%').height(40).backgroundColor(0xF5DEB3) - Text('2').width('100%').height(40).backgroundColor(0xD2B48C) - Text('3').width('100%').height(40).backgroundColor(0xF5DEB3) - Text('4').width('100%').height(40).backgroundColor(0xD2B48C) - } - .height(160) - .width('90%') - .padding(10) - .backgroundColor(0xAFEEEE) - }.width('100%').margin({ top: 5 }) - }.width('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/Flex01.gif) - -``` -// Example 02 -@Entry -@Component -struct FlexExample2 { - build() { - Column() { - Column({ space: 5 }) { - Text('Wrap').fontSize(9).fontColor(0xCCCCCC).width('90%') - Flex({ wrap: FlexWrap.Wrap }) { - Text('1').width('50%').height(50).backgroundColor(0xF5DEB3) - Text('2').width('50%').height(50).backgroundColor(0xD2B48C) - Text('3').width('50%').height(50).backgroundColor(0xD2B48C) - } - .width('90%') - .padding(10) - .backgroundColor(0xAFEEEE) - - Text('NoWrap').fontSize(9).fontColor(0xCCCCCC).width('90%') - Flex({ wrap: FlexWrap.NoWrap }) { - Text('1').width('50%').height(50).backgroundColor(0xF5DEB3) - Text('2').width('50%').height(50).backgroundColor(0xD2B48C) - Text('3').width('50%').height(50).backgroundColor(0xF5DEB3) - } - .width('90%') - .padding(10) - .backgroundColor(0xAFEEEE) - - Text('WrapReverse').fontSize(9).fontColor(0xCCCCCC).width('90%') - Flex({ wrap: FlexWrap.WrapReverse , direction:FlexDirection.Row }) { - Text('1').width('50%').height(50).backgroundColor(0xF5DEB3) - Text('2').width('50%').height(50).backgroundColor(0xD2B48C) - Text('3').width('50%').height(50).backgroundColor(0xD2B48C) - } - .width('90%') - .height(120) - .padding(10) - .backgroundColor(0xAFEEEE) - }.width('100%').margin({ top: 5 }) - }.width('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/flex02.png) - -``` -// Example 03 -@Component -struct JustifyContentFlex { - @Prop justifyContent : number - - build() { - Flex({ justifyContent: this.justifyContent }) { - Text('1').width('20%').height(50).backgroundColor(0xF5DEB3) - Text('2').width('20%').height(50).backgroundColor(0xD2B48C) - Text('3').width('20%').height(50).backgroundColor(0xF5DEB3) - } - .width('90%') - .padding(10) - .backgroundColor(0xAFEEEE) - } -} - -@Entry -@Component -struct FlexExample3 { - build() { - Column() { - Column({ space: 5 }) { - Text('justifyContent:Start').fontSize(9).fontColor(0xCCCCCC).width('90%') - JustifyContentFlex({ justifyContent: FlexAlign.Start }) - - Text('justifyContent:Center').fontSize(9).fontColor(0xCCCCCC).width('90%') - JustifyContentFlex({ justifyContent: FlexAlign.Center }) - - Text('justifyContent:End').fontSize(9).fontColor(0xCCCCCC).width('90%') - JustifyContentFlex({ justifyContent: FlexAlign.End }) - - Text('justifyContent:SpaceBetween').fontSize(9).fontColor(0xCCCCCC).width('90%') - JustifyContentFlex({ justifyContent: FlexAlign.SpaceBetween }) - - Text('justifyContent:SpaceAround').fontSize(9).fontColor(0xCCCCCC).width('90%') - JustifyContentFlex({ justifyContent: FlexAlign.SpaceAround }) - - Text('justifyContent:SpaceEvenly').fontSize(9).fontColor(0xCCCCCC).width('90%') - JustifyContentFlex({ justifyContent: FlexAlign.SpaceEvenly }) - }.width('100%').margin({ top: 5 }) - }.width('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/Flex03.gif) - -``` -// Example 04 -@Component -struct AlignItemsFlex { - @Prop alignItems : number - - build() { - Flex({ alignItems: this.alignItems }) { - Text('1').width('33%').height(30).backgroundColor(0xF5DEB3) - Text('2').width('33%').height(40).backgroundColor(0xD2B48C) - Text('3').width('33%').height(50).backgroundColor(0xF5DEB3) - } - .size({width: '90%', height: 80}) - .padding(10) - .backgroundColor(0xAFEEEE) - } -} - -@Entry -@Component -struct FlexExample4 { - build() { - Column() { - Column({ space: 5 }) { - Text('alignItems:Auto').fontSize(9).fontColor(0xCCCCCC).width('90%') - AlignItemsFlex({ alignItems: ItemAlign.Auto }) - - Text('alignItems:Start').fontSize(9).fontColor(0xCCCCCC).width('90%') - AlignItemsFlex({ alignItems: ItemAlign.Start }) - - Text('alignItems:Center').fontSize(9).fontColor(0xCCCCCC).width('90%') - AlignItemsFlex({ alignItems: ItemAlign.Center }) - - Text('alignItems:End').fontSize(9).fontColor(0xCCCCCC).width('90%') - AlignItemsFlex({ alignItems: ItemAlign.End }) - - Text('alignItems:Stretch').fontSize(9).fontColor(0xCCCCCC).width('90%') - AlignItemsFlex({ alignItems: ItemAlign.Stretch }) - - Text('alignItems:Baseline').fontSize(9).fontColor(0xCCCCCC).width('90%') - AlignItemsFlex({ alignItems: ItemAlign.Baseline }) - }.width('100%').margin({ top: 5 }) - }.width('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/Flex04.jpg) - -![](/images/application-dev/reference/arkui-ts/figures/Flex04-2.gif) - -``` -// Example 05 -@Component -struct AlignContentFlex { - @Prop alignContent: number - - build() { - Flex({ wrap: FlexWrap.Wrap, alignContent: this.alignContent }) { - Text('1').width('50%').height(20).backgroundColor(0xF5DEB3) - Text('2').width('50%').height(20).backgroundColor(0xD2B48C) - Text('3').width('50%').height(20).backgroundColor(0xD2B48C) - } - .size({ width: '90%', height: 90 }) - .padding(10) - .backgroundColor(0xAFEEEE) - } -} - -@Entry -@Component -struct FlexExample5 { - build() { - Column() { - Column({ space: 5 }) { - Text('alignContent:Start').fontSize(9).fontColor(0xCCCCCC).width('90%') - AlignContentFlex({ alignContent: FlexAlign.Start }) - - Text('alignContent:Center').fontSize(9).fontColor(0xCCCCCC).width('90%') - AlignContentFlex({ alignContent: FlexAlign.Center }) - - Text('alignContent:End').fontSize(9).fontColor(0xCCCCCC).width('90%') - AlignContentFlex({ alignContent: FlexAlign.End }) - - Text('alignContent:SpaceBetween').fontSize(9).fontColor(0xCCCCCC).width('90%') - AlignContentFlex({ alignContent: FlexAlign.SpaceBetween }) - - Text('alignContent:SpaceAround').fontSize(9).fontColor(0xCCCCCC).width('90%') - AlignContentFlex({ alignContent: FlexAlign.SpaceAround }) - - Text('alignContent:SpaceEvenly').fontSize(9).fontColor(0xCCCCCC).width('90%') - AlignContentFlex({ alignContent: FlexAlign.SpaceEvenly }) - }.width('100%').margin({ top: 5 }) - }.width('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/Flex05.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/07.GridContainer.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/07.GridContainer.md" deleted file mode 100644 index 1f238a692aca1c460de27044da41f3151189b0e5..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/07.GridContainer.md" +++ /dev/null @@ -1,211 +0,0 @@ ---- -title: GridContainer -permalink: /pages/010c0202010307 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:34 ---- -# GridContainer - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -纵向排布栅格布局容器,仅在栅格布局场景中使用。 - -## 权限列表 - -无 - -## 子组件 - -可以包含子组件。 - -## 接口 - -GridContainer\(options?: \{ columns?: number | 'auto', sizeType?: SizeType, gutter?: Length, margin?: Length\}\) - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

默认值

-

说明

-

columns

-

number

-

-

'auto'

-

设置当前布局总列数。

-

sizeType

-

SizeType

-

-

Auto

-

选用设备宽度类型。

-

gutter

-

Length

-

-

-

-

栅格布局列间距。

-

margin

-

Length

-

-

-

-

栅格布局两侧间距。

-
- -- SizeType枚举说明 - - - - - - - - - - - - - - - - - - - - - -

名称

-

描述

-

XS

-

最小宽度类型设备。

-

SM

-

小宽度类型设备。

-

MD

-

中等宽度类型设备。

-

LG

-

大宽度类型设备。

-

Auto

-

根据设备类型进行选择。

-
- - -## 属性 - -支持通用属性和Column组件的[属性方法](/pages/010c0202010303#section358284262918)。 - -## 事件 - -支持通用事件。 - -## 示例 - -``` -@Entry -@Component -struct GridContainerExample { - @State sizeType: SizeType = SizeType.XS - - build() { - Column({ space: 5 }) { - GridContainer({ columns: 12, sizeType: this.sizeType, gutter: 10, margin: 20 }) { - Row() { - Text('1') - .useSizeType({ - xs: { span: 6, offset: 0 }, - sm: { span: 2, offset: 0 }, - md: { span: 2, offset: 0 }, - lg: { span: 2, offset: 0 } - }) - .height(50).backgroundColor(0x4682B4).textAlign(TextAlign.Center) - Text('2') - .useSizeType({ - xs: { span: 2, offset: 6 }, - sm: { span: 6, offset: 2 }, - md: { span: 2, offset: 2 }, - lg: { span: 2, offset: 2 } - }) - .height(50).backgroundColor(0x00BFFF).textAlign(TextAlign.Center) - Text('3') - .useSizeType({ - xs: { span: 2, offset: 8 }, - sm: { span: 2, offset: 8 }, - md: { span: 6, offset: 4 }, - lg: { span: 2, offset: 4 } - }) - .height(50).backgroundColor(0x4682B4).textAlign(TextAlign.Center) - Text('4') - .useSizeType({ - xs: { span: 2, offset: 10 }, - sm: { span: 2, offset: 10 }, - md: { span: 2, offset: 10 }, - lg: { span: 6, offset: 6 } - }) - .height(50).backgroundColor(0x00BFFF).textAlign(TextAlign.Center) - } - }.width('90%') - - Text('Click Simulate to change the device width').fontSize(9).width('90%').fontColor(0xCCCCCC) - Row() { - Button('XS') - .onClick(() => { - this.sizeType = SizeType.XS - }).backgroundColor(0x317aff) - Button('SM') - .onClick(() => { - this.sizeType = SizeType.SM - }).backgroundColor(0x317aff) - Button('MD') - .onClick(() => { - this.sizeType = SizeType.MD - }).backgroundColor(0x317aff) - Button('LG') - .onClick(() => { - this.sizeType = SizeType.LG - }).backgroundColor(0x317aff) - } - }.width('100%').margin({ top: 5 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/grid.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/08.Grid.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/08.Grid.md" deleted file mode 100644 index 274c8cd17f572ea218f0674b23f78b601417a8a1..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/08.Grid.md" +++ /dev/null @@ -1,162 +0,0 @@ ---- -title: Grid -permalink: /pages/010c0202010308 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:34 ---- -# Grid - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -网格容器,二维布局,将容器划分成"行"和"列",产生单元格,然后指定"项目所在"的单元格,可以任意组合不同的网格,做出各种各样的布局。 - -## 权限列表 - -无 - -## 子组件 - -包含[GridItem](/pages/010c0202010309)子组件。 - -## 接口说明 - -Grid\(\) - -## 属性 - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

columnsTemplate

-

string

-

'1fr'

-

用于设置当前网格布局列的数量,不设置时默认1列 示例, '1fr 1fr 2fr' 分三列,将父组件允许的宽分为4等份,第一列占1份,第二列占一份,第三列占2份。

-

rowsTemplate

-

string

-

'1fr'

-

用于设置当前网格布局行的数量,不设置时默认1行 示例, '1fr 1fr 2fr'分三行,将父组件允许的高分为4等份,第一行占1份,第二行占一份,第三行占2份。

-

columnsGap

-

Length

-

0

-

用于设置列与列的间距。

-

rowsGap

-

Length

-

0

-

用于设置行与行的间距。

-
- -## 事件 - - - - - - - - - -

名称

-

功能描述

-

onScrollIndex(first: number) => void

-

当前列表显示的起始位置item发生变化时触发。

-
- -## 示例 - -``` -@Entry -@Component -struct GridExample { - @State Number: String[] = ['0', '1', '2', '3', '4'] - - build() { - Column({ space: 5 }) { - Grid() { - ForEach(this.Number, (day: string) => { - ForEach(this.Number, (day: string) => { - GridItem() { - Text(day) - .fontSize(16) - .backgroundColor(0xF9CF93) - .width('100%') - .height('100%') - .textAlign(TextAlign.Center) - } - }, day => day) - }, day => day) - } - .columnsTemplate('1fr 1fr 1fr 1fr 1fr') - .rowsTemplate('1fr 1fr 1fr 1fr 1fr') - .columnsGap(10) - .rowsGap(10) - .width('90%') - .backgroundColor(0xFAEEE0) - .height(300) - - Text('scroll').fontColor(0xCCCCCC).fontSize(9).width('90%') - Grid() { - ForEach(this.Number, (day: string) => { - ForEach(this.Number, (day: string) => { - GridItem() { - Text(day) - .fontSize(16) - .backgroundColor(0xF9CF93) - .width('100%') - .height(80) - .textAlign(TextAlign.Center) - } - }, day => day) - }, day => day) - } - .columnsTemplate('1fr 1fr 1fr 1fr 1fr') - .columnsGap(10) - .rowsGap(10) - .onScrollIndex((first: number) => { - console.info(first.toString()) - }) - .width('90%') - .backgroundColor(0xFAEEE0) - .height(300) - }.width('100%').margin({ top: 5 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/grid-3.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/09.GridItem.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/09.GridItem.md" deleted file mode 100644 index d0c707535e9ef2a5be23efd9b49484a2823fef98..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/09.GridItem.md" +++ /dev/null @@ -1,133 +0,0 @@ ---- -title: GridItem -permalink: /pages/010c0202010309 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:34 ---- -# GridItem - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -网格容器中单项内容容器。 - -## 权限列表 - -无 - -## 子组件 - -可以包含子组件。 - -## 接口 - -GridItem\(\) - -## 属性 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

rowStart

-

number

-

-

-

用于指定当前元素起始行号。

-

rowEnd

-

number

-

-

-

用于指定当前元素终点行号。

-

columnStart

-

number

-

-

-

用于指定当前元素起始列号。

-

columnEnd

-

number

-

-

-

用于指定当前元素终点列号。

-

forceRebuild

-

boolean

-

false

-

用于设置在触发组件build时是否重新创建此节点。

-
- -## 示例 - -``` -@Entry -@Component -struct GridItemExample { - @State numbers: string[] = Array.apply(null, Array(16)).map(function (item, i) { return i.toString() }) - - build() { - Column() { - Grid() { - GridItem() { - Text('4') - .fontSize(16).backgroundColor(0xFAEEE0) - .width('100%').height('100%').textAlign(TextAlign.Center) - }.rowStart(1).rowEnd(4) - - ForEach(this.numbers, (item) => { - GridItem() { - Text(item) - .fontSize(16).backgroundColor(0xF9CF93) - .width('100%').height('100%').textAlign(TextAlign.Center) - }.forceRebuild(false) - }, item => item) - - GridItem() { - Text('5') - .fontSize(16).backgroundColor(0xDBD0C0) - .width('100%').height('100%').textAlign(TextAlign.Center) - }.columnStart(1).columnEnd(5) - } - .columnsTemplate('1fr 1fr 1fr 1fr 1fr') - .rowsTemplate('1fr 1fr 1fr 1fr 1fr') - .width('90%').height(300) - }.width('100%').margin({ top: 5 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/griditem.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/10.List.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/10.List.md" deleted file mode 100644 index cd0855fc49760720f2a3090e7bf6acbf16e63e76..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/10.List.md" +++ /dev/null @@ -1,434 +0,0 @@ ---- -title: List -permalink: /pages/010c020201030a -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:34 ---- -# List - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -列表包含一系列相同宽度的列表项。适合连续、多行呈现同类数据,例如图片和文本。 - -## 权限列表 - -无 - -## 子组件 - -包含[ListItem](/pages/010c020201030b)子组件。 - -## 接口 - -List\(value:\{space?: number, initialIndex?: number\}\) - -- 参数 - - - - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

space

-

number

-

-

0

-

列表项间距。

-

initialIndex

-

number

-

-

0

-

设置当前List初次加载时视口起始位置显示的item,即显示第一个item,如设置的序号超过了最后一个item的序号,则设置不生效。

-
- - -## 属性 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

listDirection

-

Axis

-

Vertical

-

设置List组件排列方向参照Axis枚举说明。

-

divider

-

{

-

strokeWidth: Length,

-

color?:Color,

-

startMargin?: Length,

-

endMargin?: Length

-

}

-

-

-

用于设置ListItem分割线样式,默认无分割线。

-

strokeWidth: 分割线的线宽。

-

color: 分割线的颜色。

-

startMargin: 分割线距离列表侧边起始端的距离。

-

endMargin: 分割线距离列表侧边结束端的距离。

-

editMode

-

boolean

-

false

-

声明当前List组件是否处于可编辑模式。

-

edgeEffect

-

EdgeEffect

-

Spring

-

滑动效果,目前支持的滑动效果参见EdgeEffect的枚举说明。

-

chainAnimation

-

boolean

-

false

-

用于设置当前list是否启用链式联动动效,开启后列表滑动以及顶部和底部拖拽时会有链式联动的效果。链式联动效果:list内的list-item间隔一定距离,在基本的滑动交互行为下,主动对象驱动从动对象进行联动,驱动效果遵循弹簧物理动效。

-
  • false:不启用链式联动。
  • true:启用链式联动。
-
- -- EdgeEffect枚举说明 - - - - - - - - - - - - -

名称

-

描述

-

Spring

-

弹性物理动效,滑动到边缘后可以根据初始速度或通过触摸事件继续滑动一段距离,松手后回弹。

-

None

-

滑动到边缘后无效果。

-
- - -## 事件 - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

功能描述

-

onItemDelete(index: number) => boolean

-

列表项删除时触发。

-

onScrollIndex(firstIndex: number, lastIndex: number) => void

-

当前列表显示的起始位置和终止位置发生变化时触发。

-

onItemDragEnter(callback: (event: ItemDragInfo) => void)

-

绑定后,拖拽在可放置组件范围内移动时,触发回调。

-
  • itemIndex: 当前被拖拽的ListItem原本的索引。
  • insertIndex: 拖动当前ListItem插入List后的索引。
-
说明:

当监听了onDrop事件时,此事件才有效。

-
-

onItemDragMove(callback: (event: ItemDragInfo, itemIndex: number, insertIndex: number) => void)

-

-

绑定后,拖拽在可放置组件范围内移动时,触发回调。

-
  • itemIndex: 当前被拖拽的ListItem原本的索引。
  • insertIndex: 拖动当前ListItem插入List后的索引。
-
说明:

当监听了onDrop事件时,此事件才有效。

-
-

onItemDragLeave(callback: (event: ItemDragInfo, itemIndex: number) => void)

-

-

绑定后,拖拽离开组件范围内时,触发回调。

-
  • itemIndex: 当前被拖拽的ListItem原本的索引。
-
说明:

当监听了onDrop事件时,此事件才有效。

-
-

onItemDragStart(callback: (event: ItemDragInfo, itemIndex: number) => CustomBuilder)

-

-

绑定后,第一次拖拽ListItem时,触发回调。

-
  • itemIndex: 当前被拖拽的ListItem原本的索引。
  • 返回值:被拖拽ListItem的浮动UI布局。
-
说明:

当监听了onDrop事件时,此事件才有效。

-
-

onItemDrop(callback: (event: ItemDragInfo, itemIndex: number, insertIndex: number,isSuccess: boolean) => void)

-

-

绑定此事件的组件可作为拖拽释放目标,当在本组件范围内停止拖拽行为时,触发此回调。

-
  • itemIndex: 当前被拖拽的ListItem原本的索引。
  • insertIndex: 拖动当前ListItem插入List后的索引。
  • isSuccess: 拖拽释放时插入是否成功。
-
说明:

当监听了onDrop事件时,此事件才有效。

-
-
- ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->List使能可编辑模式需配合onItemDelete事件和ListItem的editable属性,即可编辑模式实现删除列表项功能,需满足以下条件: ->- editMode属性设置为true。 ->- 绑定onItemDelete事件,且事件回调返回true。 ->- ListItem的editable属性设置为true。 ->实现ListItem拖拽,需满足以下条件: ->- editMode属性设置为true。 ->- 绑定onItemDragStart事件,且事件回调中返回浮动UI布局。 - -- ItemDragInfo对象说明 - - - - - - - - - - - - - - - -

属性名称

-

属性类型

-

描述

-

x

-

number

-

拖拽点的横坐标。

-

y

-

number

-

拖拽点的纵坐标。

-
- - -## 示例 - -``` -@Entry -@Component -struct ListExample { - private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] - @State editFlag: boolean = false - - build() { - Stack({ alignContent: Alignment.TopStart }) { - Column() { - List({ space: 20, initialIndex: 0 }) { - ForEach(this.arr, (item) => { - ListItem() { - Text('' + item) - .width('100%').height(100).fontSize(16) - .textAlign(TextAlign.Center).borderRadius(10).backgroundColor(0xFFFFFF) - }.editable(true) - }, item => item) - } - .listDirection(Axis.Vertical) // 排列方向 - .divider({ strokeWidth: 2, color: 0xFFFFFF, startMargin: 20, endMargin: 20 }) // 每行之间的分界线 - .edgeEffect(EdgeEffect.None) // 滑动到边缘无效果 - .chainAnimation(false) // 联动特效关闭 - .onScrollIndex((firstIndex: number, lastIndex: number) => { - console.info('first' + firstIndex) - console.info('last' + lastIndex) - }) - .editMode(this.editFlag) - .onItemDelete((index: number) => { - console.info(this.arr[index] + 'Delete') - this.arr.splice(index, 1) - console.info(JSON.stringify(this.arr)) - this.editFlag = false - return true - }).width('90%') - }.width('100%') - - Button('edit list') - .onClick(() => { - this.editFlag = !this.editFlag - }).margin({ top: 5, left: 20 }) - }.width('100%').height('100%').backgroundColor(0xDCDCDC).padding({ top: 5 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/list.gif) - -``` -@Entry -@Component -struct DragListExample { - @State number1: string[] = ['0', '1', '2'] - @State number2: string[] = ['one', 'two', 'three'] - @State text: string = '' - @State bool1: boolean = false - @State bool2: boolean = false - - @Builder pixelMapBuilder() { - Text('-1') - .width('100%').height(100).fontSize(16) - .textAlign(TextAlign.Center).borderRadius(10).backgroundColor(0xFFFFFF) - } - - build() { - Column() { - List() { - ForEach(this.number1, (item) => { - ListItem() { - Text('' + item) - .width('100%').height(100).fontSize(16) - .textAlign(TextAlign.Center).borderRadius(10).backgroundColor(0xF666FF) - } - }, item => item) - } - .editMode(true) - .width('90%').divider({ strokeWidth: 2, color: 0xFFFFFF, startMargin: 20, endMargin: 20 }) - .onItemDelete((index: number) => { - console.info(this.Number1[index] + 'Delete') - this.Number1.splice(index, 1) - console.info(JSON.stringify(this.Number1)) - return true - }) - .onItemDragStart((event: ItemDragInfo, itemIndex: number) => { - this.bool1 = true - this.text = this.number1[itemIndex] - console.log("List1 onItemDragStart, itemIndex:" + itemIndex + ", ItemDragInfo:"+`${JSON.stringify(event)}`) - return this.pixelMapBuilder - }) - .onItemDragEnter((event: ItemDragInfo) => { - console.log("List1 onItemDragEnter") - }) - .onItemDragMove((event: ItemDragInfo, itemIndex: number, insertIndex: number) => { - console.log("List1 onItemDragMove, itemIndex:" + itemIndex + ", insertIndex:" + insertIndex) - }) - .onItemDragLeave((event: ItemDragInfo, itemIndex: number) => { - console.log("List1 onItemDragLeave, itemIndex:" + itemIndex) - }) - .onItemDrop((event: ItemDragInfo, itemIndex: number, insertIndex: number, isSuccess: boolean) => { - if (isSuccess) { - if (this.bool2) { - this.number2.splice(itemIndex, 1) - this.number1.splice(insertIndex, 0, this.text) - this.bool1 = false - this.bool2 = false - } else if (this.bool1) { - this.number1.splice(itemIndex, 1) - this.number1.splice(insertIndex, 0, this.text) - this.bool1 = false - this.bool2 = false - } - } - console.log("List1 onItemDrop, itemIndex:" + itemIndex + ", insertIndex:" + insertIndex + ", isSuccess:" + isSuccess) - }) - Divider().strokeWidth(5).color(0x2788D9).lineCap(LineCapStyle.Round).margin(20) - List() { - ForEach(this.Number2, (item) => { - ListItem() { - Text('' + item) - .width('100%').height(100).fontSize(16) - .textAlign(TextAlign.Center).borderRadius(10).backgroundColor(0xFFF888) - } - }, item => item) - } - .edgeEffect(EdgeEffect.None) - .width('90%') - .editMode(true) - .divider({ strokeWidth: 2, color: 0xFFFFFF, startMargin: 20, endMargin: 20 }) - .onItemDragStart((event: ItemDragInfo, itemIndex: number) => { - this.bool2 = true - this.text = this.number2[itemIndex] - console.log("List2 onItemDragStart, itemIndex:" + itemIndex) - return this.pixelMapBuilder - }) - .onItemDragEnter((event: ItemDragInfo) => { - console.log("List2 onItemDragEnter") - }) - .onItemDragMove((event: ItemDragInfo, itemIndex: number, insertIndex: number) => { - console.log("List2 onItemDragMove, itemIndex:" + itemIndex + ", insertIndex:" + insertIndex) - }) - .onItemDragLeave((event: ItemDragInfo, itemIndex: number) => { - console.log("List2 onItemDragLeave, itemIndex:" + itemIndex) - }) - .onItemDrop((event: ItemDragInfo, itemIndex: number, insertIndex: number, isSuccess: boolean) => { - if (isSuccess) { - if (this.bool1) { - this.number1.splice(itemIndex, 1) - this.number2.splice(insertIndex, 0, this.text) - this.bool1 = false - this.bool2 = false - } else if (this.bool2) { - this.number2.splice(itemIndex, 1) - this.number2.splice(insertIndex, 0, this.text) - this.bool1 = false - this.bool2 = false - } - } - console.log("List2 onItemDrop, itemIndex:" + itemIndex + ", insertIndex:" + insertIndex + ", isSuccess:" + isSuccess) - }) - }.width('100%').height('100%').backgroundColor(0xE600000).padding({ top: 25 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/GIF-4.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/11.ListItem.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/11.ListItem.md" deleted file mode 100644 index 395358a119f8b3232e1f23ef385fe0e0fde10d4b..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/11.ListItem.md" +++ /dev/null @@ -1,130 +0,0 @@ ---- -title: ListItem -permalink: /pages/010c020201030b -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:34 ---- -# ListItem - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -用来展示列表具体item,宽度默认充满List组件,必须配合List来使用。 - -## 权限列表 - -无 - -## 子组件 - -可以包含单个子组件。 - -## 接口 - -ListItem\(\) - -## 属性 - - - - - - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

sticky

-

Sticky

-

None

-

设置ListItem吸顶效果,参见Sticky枚举描述。

-

editable

-

boolean

-

false

-

声明当前ListItem元素是否可编辑,进入编辑模式后可删除。

-
- -- Sticky枚举说明 - - - - - - - - - - - - -

名称

-

描述

-

None

-

无吸顶效果。

-

Normal

-

当前item吸顶,滑动消失。

-
- - -## 示例 - -``` -@Entry -@Component -struct ListItemExample { - private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] - @State editFlag: boolean = false - - build() { - Column() { - List({ space: 20, initialIndex: 0 }) { - ListItem() { - Text('sticky:Normal , click me edit list') - .width('100%').height(40).fontSize(12).fontColor(0xFFFFFF) - .textAlign(TextAlign.Center).backgroundColor(0x696969) - .onClick(() => { - this.editFlag = !this.editFlag - }) - }.sticky(Sticky.Normal) - - ForEach(this.arr, (item) => { - ListItem() { - Text('' + item) - .width('100%').height(100).fontSize(16) - .textAlign(TextAlign.Center).borderRadius(10).backgroundColor(0xFFFFFF) - }.editable(this.editFlag) - }, item => item) - } - .editMode(true) - .onItemDelete((index: number) => { - console.info(this.arr[index - 1] + 'Delete') - this.arr.splice(index - 1,1) - this.editFlag = false - return true - }).width('90%') - }.width('100%').height('100%').backgroundColor(0xDCDCDC).padding({ top: 5 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/ListItem.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/12.Navigator.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/12.Navigator.md" deleted file mode 100644 index b73f082d8c987299b85166e5374817a214cc9eef..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/12.Navigator.md" +++ /dev/null @@ -1,201 +0,0 @@ ---- -title: Navigator -permalink: /pages/010c020201030c -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:34 ---- -# Navigator - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -路由容器组件,提供路由跳转能力。 - -## 权限列表 - -无 - -## 子组件 - -可以包含子组件。 - -## 接口 - -Navigator\(value?: \{target: string, type?: NavigationType\}\) - -创建路由组件。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

target

-

string

-

-

-

-

指定跳转目标页面的路径。

-

type

-

NavigationType

-

-

Push

-

指定路由方式。

-
- -- NavigationType枚举说明 - - - - - - - - - - - - - - - - -

名称

-

描述

-

Push

-

跳转到应用内的指定页面。

-

Replace

-

用应用内的某个页面替换当前页面,并销毁被替换的页面。

-

Back

-

返回上一页面或指定的页面。

-
- - -## 属性 - - - - - - - - - - - - - - - - - - -

名称

-

参数

-

默认值

-

描述

-

active

-

boolean

-

-

-

当前路由组件是否处于激活状态,处于激活状态时,会生效相应的路由操作。

-

params

-

Object

-

undefined

-

跳转时要同时传递到目标页面的数据,可在目标页面使用router.getParams()获得。

-
- -## 示例 - -``` -// Navigator Page -@Entry -@Component -struct NavigatorExample { - @State active: boolean = false - @State Text: string = 'news' - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.SpaceBetween }) { - Navigator({ target: 'pages/container/navigator/Detail', type: NavigationType.Push }) { - Text('Go to ' + this.Text + ' page').width('100%').textAlign(TextAlign.Center) - }.params({ text: this.Text }) - - Navigator() { - Text('Back to previous page').width('100%').textAlign(TextAlign.Center) - }.active(this.active) - .onClick(() => { - this.active = true - }) - }.height(150).width(350).padding(35) - } -} -``` - -``` -// Detail Page -import router from '@system.router' - -@Entry -@Component -struct DetailExample { - @State text: string = router.getParams().text - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.SpaceBetween }) { - Navigator({ target: 'pages/container/navigator/Back', type: NavigationType.Push }) { - Text('Go to back page').width('100%').height(20) - } - - Text('This is ' + this.text + ' page').width('100%').textAlign(TextAlign.Center) - } - .width('100%').height(200).padding({ left: 35, right: 35, top: 35 }) - } -} - -``` - -``` -// Back Page -@Entry -@Component -struct BackExample { - build() { - Column() { - Navigator({ target: 'pages/container/navigator/Navigator', type: NavigationType.Back }) { - Text('Return to Navigator Page').width('100%').textAlign(TextAlign.Center) - } - }.width('100%').height(200).padding({ left: 35, right: 35, top: 35 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/Navigator.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/13.Navigation.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/13.Navigation.md" deleted file mode 100644 index 03da6a2f8a53e758fa46b3c02fd0def5dd568da1..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/13.Navigation.md" +++ /dev/null @@ -1,427 +0,0 @@ ---- -title: Navigation -permalink: /pages/010c020201030d -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:34 ---- -# Navigation - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -Navigation组件一般作为Page页面的根容器,通过属性设置来展示页面的标题、工具栏、菜单。 - -## 权限列表 - -无 - -## 子组件 - -可以包含子组件。 - -## 接口 - -Navigation\(\) - -创建可以根据属性设置,自动展示导航栏、标题、工具栏的组件。 - -## 属性 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

title

-

string | CustomBuilder

-

-

-

页面标题。

-

subtitle

-

string

-

-

-

页面副标题。

-

menus

-

Array<NavigationMenuItem> | CustomBuilder

-

-

-

页面右上角菜单。

-

-

titleMode

-

NavigationTitleMode

-

NavigationTitleMode.Free

-

页面标题栏显示模式。

-

toolBar

-

{

-

items:[

-

Object

-

] }

-

| CustomBuilder

-

-

-

-

设置工具栏内容。

-

items: 工具栏所有项。

-

hideToolBar

-

boolean

-

false

-

设置隐藏/显示工具栏:

-

true: 隐藏工具栏。

-

false: 显示工具栏。

-

hideTitleBar

-

boolean

-

false

-

隐藏标题栏。

-

hideBackButton

-

boolean

-

false

-

隐藏返回键。

-
- -- NavigationMenuItem类型接口说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

必填

-

默认值

-

描述

-

value

-

string

-

-

-

-

菜单栏单个选项的显示文本。

-

icon

-

string

-

-

-

-

菜单栏单个选项的图标资源路径。

-

action

-

() => void

-

-

-

-

当前选项被选中的事件回调。

-
- - -- Object类型接口说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

必填

-

默认值

-

描述

-

value

-

string

-

-

-

-

工具栏单个选项的显示文本。

-

icon

-

string

-

-

-

-

工具栏单个选项的图标资源路径。

-

action

-

() => void

-

-

-

-

当前选项被选中的事件回调。

-
- -- NavigationTitleMode枚举说明 - - - - - - - - - - - - - - - -

名称

-

描述

-

Free

-

当内容为可滚动组件时,标题随着内容向上滚动而缩小(子标题的大小不变、淡出)。向下滚动内容到顶时则恢复原样。

-

Mini

-

固定为小标题模式(图标+主副标题)。

-

Full

-

固定为大标题模式(主副标题)。

-
- - >![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** - >目前可滚动组件只支持List。 - - -## 事件 - - - - - - - - - -

名称

-

功能描述

-

onTitleModeChanged(callback: (titleMode: NavigationTitleMode) => void)

-

当titleMode为NavigationTitleMode.Free时,随着可滚动组件的滑动标题栏模式发生变化时触发此回调。

-
- -## 示例 - -``` -/ Example 01 -@Entry -@Component -struct NavigationExample { - private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] - @State hideBar: boolean = true - - @Builder NavigationTitle() { - Column() { - Text('title') - .width(80) - .height(60) - .fontColor(Color.Blue) - .fontSize(30) - } - .onClick(() => { - console.log("title") - }) - } - - @Builder NavigationMenus() { - Row() { - Image('images/add.png') - .width(25) - .height(25) - Image('comment/more.png') - .width(25) - .height(25) - .margin({ left: 30 }) - }.width(100) - } - - build() { - Column() { - Navigation() { - Search({ value: '', placeholder: "" }).width('85%').margin(26) - List({ space: 5, initialIndex: 0 }) { - ForEach(this.arr, (item) => { - ListItem() { - Text('' + item) - .width('90%') - .height(80) - .backgroundColor('#3366CC') - .borderRadius(15) - .fontSize(16) - .textAlign(TextAlign.Center) - }.editable(true) - }, item => item) - } - .listDirection(Axis.Vertical) - .height(300) - .margin({ top: 10, left: 18 }) - .width('100%') - - Button(this.hideBar ? "tool bar" : "hide bar") - .onClick(() => { - this.hideBar = !this.hideBar - }) - .margin({ left: 135, top: 60 }) - } - .title(this.NavigationTitle) - .subTitle('subtitle') - .menus(this.NavigationMenus) - .titleMode(NavigationTitleMode.Free) - .hideTitleBar(false) - .hideBackButton(false) - .onTitleModeChanged((titleModel: NavigationTitleMode) => { - console.log('titleMode') - }) - .toolBar({ items: [ - { value: 'app', icon: 'images/grid.svg', action: () => { - console.log("app") - } }, - { value: 'add', icon: 'images/add.svg', action: () => { - console.log("add") - } }, - { value: 'collect', icon: 'images/collect.svg', action: () => { - console.log("collect") - } }] }) - .hideToolBar(this.hideBar) - } - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/66666.gif) - -``` -// Example 02 -@Entry -@Component -struct ToolbarBuilderExample { - @State currentIndex: number = 0 - @State Build: Array = [ - { - icon: $r('app.media.ic_public_add'), - icon_after: $r('app.media.ic_public_addcolor'), - text: 'add', - num: 0 - }, - { - icon: $r('app.media.ic_public_app'), - icon_after: $r('app.media.ic_public_appcolor'), - text: 'app', - num: 1 - }, - { - icon: $r('app.media.ic_public_collect'), - icon_after: $r('app.media.ic_public_collectcolor'), - text: 'collect', - num: 2 - } - ] - - @Builder NavigationToolbar() { - Row() { - ForEach(this.Build, item => { - Column() { - Image(this.currentIndex == item.num ? item.icon_after : item.icon) - .width(25) - .height(25) - Text(item.text) - .fontColor(this.currentIndex == item.num ? "#ff7500" : "#000000") - } - .onClick(() => { - this.currentIndex = item.num - }) - .margin({ left: 70 }) - }) - } - } - - build() { - Column() { - Navigation() { - Flex() { - } - } - .toolBar(this.NavigationToolbar) - } - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/duande.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/14.Panel.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/14.Panel.md" deleted file mode 100644 index cc64315bc87d96396e0d9ec733b395ba5efc9a97..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/14.Panel.md" +++ /dev/null @@ -1,236 +0,0 @@ ---- -title: Panel -permalink: /pages/010c020201030e -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:34 ---- -# Panel - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -可滑动面板。提供一种轻量的内容展示的窗口,可方便的在不同尺寸中切换,属于弹出式组件。 - -## 权限列表 - -无 - -## 子组件 - -可以包含子组件。 - -## 接口 - -Panel\(value:\{show:boolean\}\) - -- 参数 - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

show

-

boolean

-

-

-

-

控制Panel显示或隐藏。

-
- - -## 属性 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

type

-

PanelType

-

Foldable

-

设置可滑动面板的类型。

-

mode

-

PanelMode

-

-

-

设置可滑动面板的初始状态。

-

dragBar

-

boolean

-

true

-

设置是否存在dragbar,true表示存在,false表示不存在。

-

fullHeight

-

Length

-

-

-

指定PanelMode.Full状态下的高度。

-

halfHeight

-

Length

-

-

-

指定PanelMode.Half状态下的高度,默认为屏幕尺寸的一半。

-

miniHeight

-

Length

-

-

-

指定PanelMode.Mini状态下的高度。

-
- -- PanelType枚举说明 - - - - - - - - - - - - - - - -

名称

-

描述

-

Minibar

-

提供minibar和类全屏展示切换效果。

-

Foldable

-

内容永久展示类,提供大(类全屏)、中(类半屏)、小三种尺寸展示切换效果。

-

Temporary

-

内容临时展示区,提供大(类全屏)、中(类半屏)两种尺寸展示切换效果。

-
- - -- PanelMode枚举说明 - - - - - - - - - - - - - - - -

名称

-

描述

-

Mini

-

类型为minibar和foldable时,为最小状态;类型为temporary,则不生效。

-

Half

-

类型为foldable和temporary时,为类半屏状态;类型为minibar,则不生效。

-

Full

-

类全屏状态。

-
- - -## 事件 - - - - - - - - - -

名称

-

功能描述

-

onChange(callback: (width: number, height: number, mode: PanelMode) => void)

-

当可滑动面板发生状态变化时触发, 返回的height值为内容区高度值,当dragbar属性为true时,panel本身的高度值为dragbar高度加上内容区高度。

-
- -## 示例 - -``` -@Entry -@Component -struct PanelExample { - @State show: boolean = false - - build() { - Column() { - Text('2021-09-30 Today Calendar: 1.afternoon......Click for details') - .width('90%').height(50).borderRadius(10) - .backgroundColor(0xFFFFFF).padding({ left: 20 }) - .onClick(() => { - this.show = !this.show - }) - Panel(this.show) { // 展示日程 - Column() { - Text('Today Calendar') - Divider() - Text('1. afternoon 4:00 The project meeting') - } - } - .type(PanelType.Foldable).mode(PanelMode.Half) - .dragBar(true) // 默认开启 - .halfHeight(500) // 默认一半 - .onChange((value: any) => { - console.info(`width:${value.width},height:${value.height},mode:${value.mode}`) - }) - }.width('100%').height('100%').backgroundColor(0xDCDCDC).padding({ top: 5 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/Panel.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/15.Row.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/15.Row.md" deleted file mode 100644 index 75837755d61e410563e6b0a75dc19e2f21bfb706..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/15.Row.md" +++ /dev/null @@ -1,167 +0,0 @@ ---- -title: Row -permalink: /pages/010c020201030f -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:34 ---- -# Row - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -沿水平方向布局容器。 - -## 权限列表 - -无 - -## 子组件 - -可以包含子组件。 - -## 接口 - -Row\(value:\{space?: Length\}\) - -- 参数 - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

space

-

Length

-

-

0

-

横向布局元素间距。

-
- - -## 属性 - - - - - - - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

alignItems

-

VerticalAlign

-

Center

-

在垂直方向上子组件的对齐格式。

-

justifyContent8+

-

FlexAlign

-

Start

-

设置子组件在水平方向上的对齐格式。

-
- -- VerticalAlign枚举说明 - - - - - - - - - - - - - - - - -

名称

-

描述

-

Top

-

顶部对齐。

-

Center

-

居中对齐,默认对齐方式。

-

Bottom

-

底部对齐。

-
- - -## 示例 - -``` -@Entry -@Component -struct RowExample { - build() { - Column({ space: 5 }) { - Text('space').fontSize(9).fontColor(0xCCCCCC).width('90%') - Row({ space: 5 }) { - Row().width('30%').height(50).backgroundColor(0xAFEEEE) - Row().width('30%').height(50).backgroundColor(0x00FFFF) - }.width('90%').height(107).border({ width: 1 }) - - Text('alignItems(Top)').fontSize(9).fontColor(0xCCCCCC).width('90%') - Row() { - Row().width('30%').height(50).backgroundColor(0xAFEEEE) - Row().width('30%').height(50).backgroundColor(0x00FFFF) - }.alignItems(VerticalAlign.Top).height('15%').border({ width: 1 }) - - Text('alignItems(Center)').fontSize(9).fontColor(0xCCCCCC).width('90%') - Row() { - Row().width('30%').height(50).backgroundColor(0xAFEEEE) - Row().width('30%').height(50).backgroundColor(0x00FFFF) - }.alignItems(VerticalAlign.Center).height('15%').border({ width: 1 }) - - Text('justifyContent(End)').fontSize(9).fontColor(0xCCCCCC).width('90%') - Row() { - Row().width('30%').height(50).backgroundColor(0xAFEEEE) - Row().width('30%').height(50).backgroundColor(0x00FFFF) - }.width('90%').border({ width: 1 }).justifyContent(FlexAlign.End) - - Text('justifyContent(Center)').fontSize(9).fontColor(0xCCCCCC).width('90%') - Row() { - Row().width('30%').height(50).backgroundColor(0xAFEEEE) - Row().width('30%').height(50).backgroundColor(0x00FFFF) - }.width('90%').border({ width: 1 }).justifyContent(FlexAlign.Center) - }.width('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/Row.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/16.RowSplit.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/16.RowSplit.md" deleted file mode 100644 index f677f7ca3ae10a692fd641405390fb109e52f941..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/16.RowSplit.md" +++ /dev/null @@ -1,80 +0,0 @@ ---- -title: RowSplit -permalink: /pages/010c0202010310 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:34 ---- -# RowSplit - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -将子组件横向布局,并在每个子组件之间插入一根纵向的分割线。 - -## 权限列表 - -无 - -## 子组件 - -可以包含子组件 - -## 接口 - -RowSplit\(\) - -## 属性 - - - - - - - - - - - -

名称

-

参数类型

-

描述

-

resizeable

-

boolean

-

分割线是否可拖拽,默认为false。

-
- ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->RowSplit的分割线最小能拖动到刚好包含子组件。 - -## 示例 - -``` -@Entry -@Component -struct RowSplitExample { - build() { - Column() { - Text('The secant line can be dragged').fontSize(9).fontColor(0xCCCCCC).width('90%') - RowSplit() { - Text('1').width('10%').height(100).backgroundColor(0xF5DEB3).textAlign(TextAlign.Center) - Text('2').width('10%').height(100).backgroundColor(0xD2B48C).textAlign(TextAlign.Center) - Text('3').width('10%').height(100).backgroundColor(0xF5DEB3).textAlign(TextAlign.Center) - Text('4').width('10%').height(100).backgroundColor(0xD2B48C).textAlign(TextAlign.Center) - Text('5').width('10%').height(100).backgroundColor(0xF5DEB3).textAlign(TextAlign.Center) - } - .resizeable(true) // 可拖动 - .width('90%').height(100) - }.width('100%').margin({ top: 5 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/RowSplit.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/17.Scroll.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/17.Scroll.md" deleted file mode 100644 index 279f864e231db9748ad27958dfe690ffa32cadb1..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/17.Scroll.md" +++ /dev/null @@ -1,397 +0,0 @@ ---- -title: Scroll -permalink: /pages/010c0202010311 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:34 ---- -# Scroll - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -可滚动的容器组件,当子组件的布局尺寸超过父组件的视口时,内容可以滚动。 - -## 权限列表 - -无 - -## 子组件 - -支持单个子组件。 - -## 接口 - -Scroll\(scroller?: Scroller\) - -## 属性 - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

scrollable

-

ScrollDirection

-

Vertical

-

设置滚动方法。

-

scrollBar

-

BarState

-

Auto

-

设置滚动条状态。

-

scrollBarColor

-

Color

-

-

-

设置滚动条的颜色。

-

scrollBarWidth

-

Length

-

-

-

设置滚动条的宽度。

-
- -- ScrollDirection枚举说明 - - - - - - - - - - - - - - - -

名称

-

描述

-

Horizontal

-

仅支持水平方向滚动。

-

Vertical

-

仅支持竖直方向滚动。

-

None

-

不可滚动。

-
- - -## Scroller - -可滚动容器组件的控制器,可以将此组件绑定至容器组件,然后通过它控制容器组件的滚动,目前支持绑定到List和Scroll组件上。 - -### 创建对象 - -``` -scroller: Scroller = new Scroller() -``` - -### scroller.scrollTo - -scrollTo\(value: \{ xOffset: number | string, yOffset: number | string, animation?: \{ duration: number, curve: Curve \} \}\): void - -滑动到指定位置。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

xOffset

-

Length

-

-

-

-

水平滑动偏移。

-

yOffset

-

Length

-

-

-

-

竖直滑动偏移。

-

animation

-

{

-

duration: number,

-

curve: Curve | CubicBezier | SpringCurve

-

}

-

-

-

-

动画配置:

-
  • duration: 滚动时长设置。
  • curve: 滚动曲线设置。
-
- - -### scroller.scrollEdge - -scrollEdge\(value: Edge\): void - -滚动到容器边缘。 - -- 参数 - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

value

-

Edge

-

-

-

-

滚动到的边缘位置。

-
- - -### scroller.scrollPage - -scrollPage\(value: \{ next: boolean \}\): void - -滚动到下一页或者上一页。 - -- 参数 - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

next

-

boolean

-

-

-

-

是否向下翻页。true表示向下翻页,false表示向上翻页。

-
- - -### scroller.currentOffset - -scroller.currentOffset\(\): Object - -返回当前的滚动偏移量。 - -- 返回值 - - - - - - - - - -

类型

-

描述

-

{

-

xOffset: number,

-

yOffset: number

-

}

-

xOffset: 水平滑动偏移;

-

yOffset: 竖直滑动偏移。

-
- - -### scroller.scrollToIndex - -scroller.scrollToIndex\(value: number\): void - -滑动到指定Index。 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->仅支持list组件。 - -- 参数 - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

value

-

number

-

-

-

-

要滑动到的列表项在列表中的索引值。

-
- - -## 事件 - - - - - - - - - - - - - - - -

名称

-

功能描述

-

onScroll(xOffset: number, yOffset: number) => void

-

滚动事件回调, 返回滚动时水平、竖直方向偏移量。

-

onScrollEdge(side: Edge) => void

-

滚动到边缘事件回调。

-

onScrollEnd() => void

-

滚动停止事件回调。

-
- -## 示例 - -``` -@Entry -@Component -struct ScrollExample { - scroller: Scroller = new Scroller() - private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] - - build() { - Stack({ alignContent: Alignment.TopStart }) { - Scroll(this.scroller) { - Column() { - ForEach(this.arr, (item) => { - Text(item.toString()) - .width('90%').height(150).backgroundColor(0xFFFFFF) - .borderRadius(15).fontSize(16).textAlign(TextAlign.Center) - .margin({ top: 10 }) - }, item => item) - }.width('100%') - } - .scrollable(ScrollDirection.Vertical).scrollBar(BarState.On) - .scrollBarColor(Color.Gray).scrollBarWidth(30) - .onScroll((xOffset: number, yOffset: number) => { - console.info(xOffset + ' ' + yOffset) - }) - .onScrollEdge((side: Edge) => { - console.info('To the edge') - }) - .onScrollEnd(() => { - console.info('Scroll Stop') - }) - - Button('scroll 100') - .onClick(() => { // 点击后下滑100.0距离 - this.scroller.scrollTo({ xOffset: 0, yOffset: this.scroller.currentOffset().yOffset + 100 }) - }) - .margin({ top: 10, left: 20 }) - Button('back top') - .onClick(() => { // 点击后回到顶部 - this.scroller.scrollEdge(Edge.Top) - }) - .margin({ top: 60, left: 20 }) - Button('next page') - .onClick(() => { // 点击后下滑到底部 - this.scroller.scrollPage({ next: true }) - }) - .margin({ top: 110, left: 20 }) - }.width('100%').height('100%').backgroundColor(0xDCDCDC) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/scroll.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/18.ScrollBar.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/18.ScrollBar.md" deleted file mode 100644 index 917acc95819946fbd7fbc99e783a1e56f616028a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/18.ScrollBar.md" +++ /dev/null @@ -1,179 +0,0 @@ ---- -title: ScrollBar -permalink: /pages/010c0202010312 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:34 ---- -# ScrollBar - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -滚动条组件ScrollBar,用于配合可滚动组件使用,如List、Grid、Scroll。 - -## 权限列表 - -无 - -## 子组件 - -可以包含单个子组件。 - -## 接口 - -ScrollBar\(value: ScrollBarOption\) - -- ScrollBarOption的参数描述 - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

scroller

-

Scroller

-

-

-

-

可滚动组件的控制器。用于与可滚动组件进行绑定。

-

direction

-

ScrollBarDirection

-

-

ScrollBarDirection.Vertical

-

滚动条的方向,控制可滚动组件对应方向的滚动。

-

state

-

BarState

-

-

BarState.Auto

-

滚动条状态。

-
- - >![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** - >ScrollBar组件负责定义可滚动区域的行为样式,ScrollBar的子节点负责定义滚动条的行为样式。 - >滚动条组件与可滚动组件通过Scroller进行绑定,且只有当两者方向相同时,才能联动,ScrollBar与可滚动组件仅支持一对一绑定。 - -- ScrollBarDirection枚举说明 - - - - - - - - - - - - -

名称

-

描述

-

Vertical

-

纵向滚动条。

-

Horizontal

-

横向滚动条。

-
- -- BarState枚举说明 - - - - - - - - - - - - - - - -

名称

-

描述

-

On

-

常驻显示。

-

Off

-

不显示。

-

Auto

-

按需显示(触摸时显示,无操作2s后消失)。

-
- - -## 示例 - -``` -@Entry -@Component -struct ScrollBarExample { - private scroller: Scroller = new Scroller() - private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] - - build() { - Column() { - Stack({ alignContent: Alignment.End }) { - Scroll(this.scroller) { - Flex({ direction: FlexDirection.Column }) { - ForEach(this.arr, (item) => { - Row() { - Text(item.toString()) - .width('90%') - .height(100) - .backgroundColor('#3366CC') - .borderRadius(15) - .fontSize(16) - .textAlign(TextAlign.Center) - .margin({ top: 5 }) - } - }, item => item) - }.margin({ left: 52 }) - } - .scrollBar(BarState.Off) - .scrollable(ScrollDirection.Vertical) - ScrollBar({ scroller: this.scroller, direction: ScrollBarDirection.Vertical,state: BarState.Auto }) { - Text() - .width(30) - .height(100) - .borderRadius(10) - .backgroundColor('#C0C0C0') - }.width(30).backgroundColor('#ededed') - } - } - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/F.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/19.Stack.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/19.Stack.md" deleted file mode 100644 index bc41e605eb82c0d957b22c79675a9cfb39443fad..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/19.Stack.md" +++ /dev/null @@ -1,78 +0,0 @@ ---- -title: Stack -permalink: /pages/010c0202010313 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:34 ---- -# Stack - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -堆叠容器,子组件按照顺序依次入栈,后一个子组件覆盖前一个子组件。 - -## 权限列表 - -无 - -## 子组件 - -可以包含子组件。 - -## 接口 - -Stack\(value:\{alignContent?: Alignment\}\) - -- 参数 - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

alignContent

-

Alignment

-

-

Center

-

设置子组件在容器内的对齐方式。

-
- - -## 示例 - -``` -@Entry -@Component -struct StackExample { - build() { - Stack({ alignContent: Alignment.Bottom }) { - Text('First child, show in bottom').width('90%').height('100%').backgroundColor(0xd2cab3).align(Alignment.Top) - Text('Second child, show in top').width('70%').height('60%').backgroundColor(0xc1cbac).align(Alignment.Top) - }.width('100%').height(150).margin({ top: 5 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/stack.jpg) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/20.Swiper.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/20.Swiper.md" deleted file mode 100644 index 0e658d4cc0daa20e321423799d389bc99762552e..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/20.Swiper.md" +++ /dev/null @@ -1,283 +0,0 @@ ---- -title: Swiper -permalink: /pages/010c0202010314 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:34 ---- -# Swiper - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -滑动容器,提供切换子组件显示的能力。 - -## 权限列表 - -无 - -## 子组件 - -可以包含子组件。 - -## 接口 - -Swiper\(value:\{controller?: SwiperController\}\) - -- 参数 - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

controller

-

SwiperController

-

-

null

-

给组件绑定一个控制器,用来控制组件翻页。

-
- - -## 属性 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

index

-

number

-

0

-

设置当前在容器中显示的子组件的索引值。

-

autoPlay

-

boolean

-

false

-

子组件是否自动播放,自动播放状态下,导航点不可操作。

-

interval

-

number

-

3000

-

使用自动播放时播放的时间间隔,单位为毫秒。

-

indicator

-

boolean

-

true

-

是否启用导航点指示器。

-

loop

-

boolean

-

true

-

是否开启循环。

-

duration

-

number

-

400

-

子组件切换的动画时长,单位为毫秒。

-

vertical

-

boolean

-

false

-

是否为纵向滑动。

-

itemSpace

-

Length

-

0

-

设置子组件与子组件之间间隙。

-

cachedCount8+

-

number

-

1

-

设置预加载子组件个数。

-

disableSwipe8+

-

boolean

-

false

-

禁用组件滑动切换功能。

-
- -### SwiperController - -Swiper容器组件的控制器,可以将此对象绑定至Swiper组件,然后通过它控制翻页。 - - - - - - - - - - - - -

接口名称

-

功能描述

-

showNext():void;

-

翻至下一页。

-

showPrevious():void;

-

翻至上一页。

-
- -## 事件 - - - - - - - - - -

名称

-

功能描述

-

onChange( index: number) => void

-

当前显示的组件索引变化时触发该事件。

-
- -## 示例 - -``` -class MyDataSource implements IDataSource { - private list: number[] = [] - private listener: DataChangeListener - - constructor(list: number[]) { - this.list = list - } - - totalCount(): number { - return this.list.length - } - - getData(index: number): any { - return this.list[index] - } - - registerDataChangeListener(listener: DataChangeListener): void { - this.listener = listener - } - - unregisterDataChangeListener() { - } -} - -@Entry -@Component -struct SwiperExample { - private swiperController: SwiperController = new SwiperController() - private data: MyDataSource = new MyDataSource([]) - - private aboutToAppear(): void { - let list = [] - for (var i = 1; i <= 10; i++) { - list.push(i.toString()); - } - this.data = new MyDataSource(list) - } - - build() { - Column({ space: 5 }) { - Swiper(this.swiperController) { - LazyForEach(this.data, (item: string) => { - Text(item).width('90%').height(160).backgroundColor(0xAFEEEE).textAlign(TextAlign.Center).fontSize(20) - }, item => item) - } - .cachedCount(2) - .index(1) - .autoPlay(true) - .interval(4000) - .indicator(true) // 默认开启指示点 - .loop(false) // 默认开启循环播放 - .duration(1000) - .vertical(false) // 默认横向切换 - .itemSpace(0) - .onChange((index: number) => { - console.info(index.toString()) - }) - - Flex({ justifyContent: FlexAlign.SpaceAround }) { - Button('next') - .onClick(() => { - this.swiperController.showNext() - }) - Button('preview') - .onClick(() => { - this.swiperController.showPrevious() - }) - } - }.margin({ top: 5 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/swiper.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/21.Tabs.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/21.Tabs.md" deleted file mode 100644 index ad2d4eeee76762b11614bd76cc6b853d41657166..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/21.Tabs.md" +++ /dev/null @@ -1,294 +0,0 @@ ---- -title: Tabs -permalink: /pages/010c0202010315 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:34 ---- -# Tabs - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -一种可以通过页签进行内容视图切换的容器组件,每个页签对应一个内容视图。 - -## 支持设备 - - - - - - - - - - - - - -

手机

-

平板

-

智慧屏

-

智能穿戴

-

支持

-

支持

-

不支持

-

不支持

-
- -## 权限列表 - -无 - -## 子组件 - -包含子组件[TabContent](/pages/010c0202010316)。 - -## 接口说明 - -Tabs\(value: \{barPosition?: BarPosition, index?: number, controller?: [TabsController](#section104288910399)\}\) - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

barPosition

-

BarPosition

-

-

Start

-

指定页签位置来创建Tabs容器组件。

-

index

-

number

-

-

0

-

指定初次初始页签索引。

-

controller

-

TabsController

-

-
  

设置Tabs控制器。

-
- -- BarPosition枚举说明 - - - - - - - - - - - - -

名称

-

描述

-

Start

-

vertical属性方法设置为true时,页签位于容器左侧;vertical属性方法设置为false时,页签位于容器顶部。

-

End

-

vertical属性方法设置为true时,页签位于容器右侧;vertical属性方法设置为false时,页签位于容器底部。

-
- - -### TabsController - -Tabs组件的控制器,用于控制Tabs组件进行页签切换。 - - - - - - - - - -

接口名称

-

功能描述

-

changeIndex(value: number): void

-

控制Tabs切换到指定页签,index: 页签在Tabs里的索引值,索引值从0开始。

-
- -## 属性 - -不支持触摸热区设置。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

vertical

-

boolean

-

是否为纵向Tab,默认为false。

-

是否为纵向Tab,默认为false。

-

scrollable

-

boolean

-

是否可以通过左右滑动进行页面切换,默认为true。

-

是否可以通过左右滑动进行页面切换,默认为true。

-

barMode

-

BarMode

-

TabBar布局模式。

-

TabBar布局模式。

-

barWidth

-

number

-

TabBar的宽度值,不设置时使用系统主题中的默认值。

-

TabBar的宽度值,不设置时使用系统主题中的默认值。

-

barHeight

-

number

-

TabBar的高度值,不设置时使用系统主题中的默认值。

-

TabBar的高度值,不设置时使用系统主题中的默认值

-

animationDuration

-

number

-

200

-

TabContent滑动动画时长。

-
- -- BarMode枚举说明 - - - - - - - - - - - - -

名称

-

描述

-

Scrollable

-

TabBar使用实际布局宽度, 超过总长度后可滑动。

-

Fixed

-

所有TabBar平均分配宽度。

-
- - -## 事件 - - - - - - - - - -

名称

-

功能描述

-

onChange(callback: (index: number) => void)

-

Tab页签切换后触发的事件。

-
- -## 示例 - -``` -@Entry -@Component -struct TabsExample { - private controller: TabsController = new TabsController() - - build() { - Column() { - Tabs({ barPosition: BarPosition.Start, index: 1, controller: this.controller }) { - TabContent() { - Column().width('100%').height('100%').backgroundColor(Color.Pink) - }.tabBar('pink') - - TabContent() { - Column().width('100%').height('100%').backgroundColor(Color.Yellow) - }.tabBar('yellow') - - TabContent() { - Column().width('100%').height('100%').backgroundColor(Color.Blue) - }.tabBar('blue') - - TabContent() { - Column().width('100%').height('100%').backgroundColor(Color.Green) - }.tabBar('green') - } - .vertical(true).scrollable(true).barMode(BarMode.Fixed) - .barWidth(70).barHeight(150).animationDuration(400) - .onChange((index: number) => { - console.info(index.toString()) - }) - .width('90%').backgroundColor(0xF5F5F5) - }.width('100%').height(150).margin({ top: 5 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/Tabs.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/22.TabContent.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/22.TabContent.md" deleted file mode 100644 index 9170de5826e05a7cf91cd68d8625903b4e97cb9f..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/22.TabContent.md" +++ /dev/null @@ -1,192 +0,0 @@ ---- -title: TabContent -permalink: /pages/010c0202010316 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:34 ---- -# TabContent - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -仅在Tabs中使用,对应一个切换页签的内容视图。 - -## 权限列表 - -无 - -## 子组件 - -支持单个子组件。 - -## 接口 - -TabContent\(\) - -## 属性 - -不支持触摸热区设置。 - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

tabBar

-

string | {

-

icon?: string,

-

text?: string

-

}

-

| CustomBuilder8+

-

-

-

设置TabBar上显示内容。

-

CustomBuilder: 构造器,内部可以传入组件(API8版本以上适用)。

-
说明:

如果icon采用svg格式图源,则要求svg图源删除其自有宽高属性值。如采用带有自有宽高属性的svg图源,icon大小则是svg本身内置的宽高属性值大小。

-
-
- ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->- TabContent组件不支持设置通用宽度属性,其宽度默认撑满Tabs父组件。 ->- TabContent组件不支持设置通用高度属性,其高度由Tabs父组件高度与TabBar组件高度决定。 - -## 示例 - -``` -@Entry -@Component -struct TabContentExample { - @State fontColor: string = 'rgba(0, 0, 0, 0.4)' - @State selectedFontColor: string = 'rgba(10, 30, 255, 1)' - @State currentIndex: number = 0 - private controller: TabsController = new TabsController() - @Builder Tab1Builder() { - Column() { - Image(this.currentIndex === 0 ? '/resources/ic_public_contacts_filled_selected.png' : '/resources/ic_public_contacts_filled.png') - .width(24) - .height(24) - .opacity(this.currentIndex === 0 ? 1 : 0.4) - .objectFit(ImageFit.Contain) - Text("Tab1") - .fontColor(this.currentIndex === 0 ? this.selectedFontColor : this.fontColor) - .fontSize(10) - .margin({top: 2}) - } - } - - @Builder Tab2Builder() { - Column() { - Image(this.currentIndex === 1 ? '/resources/ic_public_contacts_filled_selected.png' : '/resources/ic_public_contacts_filled.png') - .width(24) - .height(24) - .opacity(this.currentIndex === 1 ? 1 : 0.4) - .objectFit(ImageFit.Contain) - Text("Tab2") - .fontColor(this.currentIndex === 1 ? this.selectedFontColor : this.fontColor) - .fontSize(10) - .margin({top: 2}) - } - } - - @Builder Tab3Builder() { - Column() { - Image(this.currentIndex === 3 ? '/resources/ic_public_contacts_filled_selected.png' : '/resources/ic_public_contacts_filled.png') - .width(24) - .height(24) - .opacity(this.currentIndex === 3 ? 1 : 0.4) - .objectFit(ImageFit.Contain) - Text("Tab3") - .fontColor(this.currentIndex === 3 ? this.selectedFontColor : this.fontColor) - .fontSize(10) - .margin({top: 2}) - } - } - - @Builder Tab4Builder() { - Column() { - Image(this.currentIndex === 4 ? '/resources/ic_public_contacts_filled_selected.png' : '/resources/ic_public_contacts_filled.png') - .width(24) - .height(24) - .opacity(this.currentIndex === 4 ? 1 : 0.4) - .objectFit(ImageFit.Contain) - Text("Tab4") - .fontColor(this.currentIndex === 4 ? this.selectedFontColor : this.fontColor) - .fontSize(10) - .margin({top: 2}) - } - } - - @Builder AddBuilder() { - Column() { - Image(this.currentIndex === 2 ? '/resources/ic_public_add_norm_filled_selected.png' : '/resources/ic_public_add_norm_filled.png') - .width(this.currentIndex === 2 ? 26 : 24) - .height(this.currentIndex === 2 ? 26 : 24) - .opacity(this.currentIndex === 2 ? 1 : 0.4) - .objectFit(ImageFit.Contain) - .animation({duration: 200}) - } - } - - build() { - Column() { - Tabs({ barPosition: BarPosition.End, index: 0, controller: this.controller }) { - TabContent() { - Flex({justifyContent: FlexAlign.Center})) { - Text('Tab1').fontSize(32) - } - }.tabBar(this.Tab1Builder) - - TabContent() { - Flex({justifyContent: FlexAlign.Center})) { - Text('Tab2').fontSize(32) - } - }.tabBar(this.Tab2Builder) - - TabContent() { - Flex({justifyContent: FlexAlign.Center})) { - Text('Add').fontSize(32) - } - }.tabBar(this.AddBuilder) - - TabContent() { - Flex({justifyContent: FlexAlign.Center})) { - Text('Tab3').fontSize(32) - } - }.tabBar(this.Tab3Builder) - - TabContent() { - Flex({justifyContent: FlexAlign.Center})) { - Text('Tab4').fontSize(32) - } - }.tabBar(this.Tab4Builder) - } - .vertical(false) - .barWidth(300).barHeight(56) - .onChange((index: number) => { - this.currentIndex = index - }) - .width('90%').backgroundColor('rgba(241, 243, 245, 0.95)') - }.width('100%').height(200).margin({ top: 5 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075122.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/23.Stepper.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/23.Stepper.md" deleted file mode 100644 index 13e55cea715bbbf4e4c6ebe640acb06cd00c353f..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/23.Stepper.md" +++ /dev/null @@ -1,174 +0,0 @@ ---- -title: Stepper -permalink: /pages/010c0202010317 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:34 ---- -# Stepper - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -步骤导航器。 - - -## 权限列表 - -无 - -## 子组件 - -仅能包含子组件[StepperItem](/pages/010c0202010318)。 - -## 接口 - -Stepper\(value?: \{ index?: number \}\) - -- 参数 - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

index

-

number

-

-

0

-

设置步骤导航器显示第几个StepperItem。

-
- - -## 属性 - -无 - -## 事件 - - - - - - - - - - - - - - - -

名称

-

描述

-

onFinish(callback: () => void)

-

步骤导航器最后一个StepperItem的nextLabel被点击时触发该回调 。

-

onSkip(callback: () => void)

-

当前显示的StepperItem状态为ItemState.Skip时,nextLabel被点击时触发该回调。

-

onChange(callback: (prevIndex?: number, index?: number) => void)

-

点击左边或者右边文本按钮进行步骤切换时触发该事件。

-
  • prevIndex:切换前的步骤页索引值。
  • index:切换后的步骤页(前一页或者下一页)索引值。
-
- -## 示例 - -``` -@Entry -@Component -struct StepperExample { - @State currentIndex: number = 0 - @State firstState: ItemState = ItemState.Normal - @State secondState: ItemState = ItemState.Normal - - build() { - Stepper({ - index: this.currentIndex - }) { - StepperItem() { - Text('Page One') - .fontSize(35) - .fontColor(Color.Blue) - .width(200) - .lineHeight(50) - .margin({top:250}) - } - .nextLabel('') - .position({x: '35%', y: 0}) - StepperItem() { - Text('Page Two') - .fontSize(35) - .fontColor(Color.Blue) - .width(200) - .lineHeight(50) - .margin({top:250}) - .onClick(()=>{ - this.firstState = this.firstState === ItemState.Skip ? ItemState.Normal : ItemState.Skip - }) - } - .nextLabel('Next') - .prevLabel('Previous') - .status(this.firstState) - .position({x: '35%', y: 0}) - StepperItem() { - Text('Page Three') - .fontSize(35) - .fontColor(Color.Blue) - .width(200) - .lineHeight(50) - .margin({top:250}) - .onClick(()=>{ - this.secondState = this.secondState === ItemState.Waiting ? ItemState.Normal : ItemState.Waiting - }) - } - .position({x: '35%', y: 0}) - .status(this.secondState) - StepperItem() { - Text('Page four') - .fontSize(35) - .fontColor(Color.Blue) - .width(200) - .lineHeight(50) - .margin({top:250}) - } - .position({x: '35%', y: 0}) - .nextLabel('Finish') - } - .onFinish(() => { - console.log('onFinish') - }) - .onSkip(() => { - console.log('onSkip') - }) - .onChange((prevIndex: number, index: number) => { - this.currentIndex = index - }) - .align(Alignment.Center) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/stepper.gif) - - - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/24.StepperItem.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/24.StepperItem.md" deleted file mode 100644 index 2b1380e4a1078e658381f88f098a2b0cf29e9bef..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/03.\345\256\271\345\231\250\347\273\204\344\273\266/24.StepperItem.md" +++ /dev/null @@ -1,111 +0,0 @@ ---- -title: StepperItem -permalink: /pages/010c0202010318 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:34 ---- -# StepperItem - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -步骤导航器元素。 - - -## 权限列表 - -无 - -## 子组件 - -支持单个子组件。 - -## 接口 - -StepperItem\(\) - -## 属性 - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

默认值

-

参数描述

-

prevLabel

-

string

-

-

-

当步骤导航器大于一页,除第一页默认值都为"返回"。

-

nextLabel

-

string

-

-

-

步骤导航器大于一页时,最后一页默认值为"开始",其余页默认值为"下一步"。

-

status

-

ItemState

-

ItemState.Normal

-

步骤导航器元素的状态。

-
- -- ItemState枚举说明 - - - - - - - - - - - - - - - - - - -

名称

-

描述

-

Normal

-

正常状态,右侧文本按钮正常显示,可点击进入下一个StepperItem。

-

Disabled

-

不可用状态,右侧文本按钮灰度显示,不可点击进入下一个StepperItem。

-

Waiting

-

等待状态,右侧文本按钮不显示,使用等待进度条,不可点击进入下一个StepperItem。

-

Skip

-

跳过状态,表示跳过当前步骤, 进入下一个StepperItem。

-
- - -## 示例 - -见[Stepper](/pages/010c0202010317)。 - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/04.\347\273\230\345\210\266\347\273\204\344\273\266/01.Circle.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/04.\347\273\230\345\210\266\347\273\204\344\273\266/01.Circle.md" deleted file mode 100644 index 59997dc07da40719d585e15c19f84e3f78196f55..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/04.\347\273\230\345\210\266\347\273\204\344\273\266/01.Circle.md" +++ /dev/null @@ -1,158 +0,0 @@ ---- -title: Circle -permalink: /pages/010c0202010401 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:34 ---- -# Circle - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -圆形绘制组件。 - -## 权限列表 - -无 - -## 子组件 - -无 - -## 接口 - -Circle\(options?: \{width: Length, height: Length\}\) - -- 参数 - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

options

-

Object

-

-

-

-

options参数说明

-
- -- options参数说明 - - - - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

width

-

Length

-

-

-

-

宽度。

-

height

-

Length

-

-

-

-

高度。

-
- - -## 属性 - - - - - - - - - - - - - - - - - - - - - -

参数名称

-

参数类型

-

默认值

-

必填

-

参数描述

-

width

-

Length

-

0

-

-

圆所在矩形的宽度。

-

height

-

Length

-

0

-

-

圆所在矩形的高度。

-
- -## 示例 - -``` -@Entry -@Component -struct CircleExample { - build() { - Flex({ justifyContent: FlexAlign.SpaceAround }) { - // 绘制一个直径为150的圆 - Circle({ width: 150, height: 150 }) - // 绘制一个直径为150的圆 - Circle().width(150).height(150) - }.width('100%').margin({ top: 5 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/circle.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/04.\347\273\230\345\210\266\347\273\204\344\273\266/02.Ellipse.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/04.\347\273\230\345\210\266\347\273\204\344\273\266/02.Ellipse.md" deleted file mode 100644 index f132fc47e2eb1039e0a51d3b619022fb782e26d1..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/04.\347\273\230\345\210\266\347\273\204\344\273\266/02.Ellipse.md" +++ /dev/null @@ -1,158 +0,0 @@ ---- -title: Ellipse -permalink: /pages/010c0202010402 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:34 ---- -# Ellipse - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -椭圆绘制组件。 - -## 权限列表 - -无 - -## 子组件 - -无 - -## 接口 - -ellipse\(options?: \{width: Lenght, height: Length\}\) - -- 参数 - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

options

-

Object

-

-

-

-

options参数说明

-
- -- options参数说明 - - - - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

width

-

Length

-

-

-

-

宽度。

-

height

-

Length

-

-

-

-

高度。

-
- - -## 属性 - - - - - - - - - - - - - - - - - - - - - -

参数名称

-

参数类型

-

默认值

-

必填

-

参数描述

-

width

-

Length

-

0

-

-

椭圆所在矩形的宽度。

-

height

-

Length

-

0

-

-

椭圆所在矩形的高度。

-
- -## 示例 - -``` -@Entry -@Component -struct EllipseExample { - build() { - Flex({ justifyContent: FlexAlign.SpaceAround }) { - // 在一个 150 * 70 的矩形框中绘制一个椭圆 - Ellipse({ width: 150, height: 80 }) - // 在一个 150 * 70 的矩形框中绘制一个椭圆 - Ellipse().width(150).height(80) - }.width('100%').margin({ top: 5 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/ellipse.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/04.\347\273\230\345\210\266\347\273\204\344\273\266/03.Line.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/04.\347\273\230\345\210\266\347\273\204\344\273\266/03.Line.md" deleted file mode 100644 index 49126324757c4d0f856772eb759a14e8ec42a97a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/04.\347\273\230\345\210\266\347\273\204\344\273\266/03.Line.md" +++ /dev/null @@ -1,178 +0,0 @@ ---- -title: Line -permalink: /pages/010c0202010403 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:34 ---- -# Line - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -直线绘制组件。 - -## 权限列表 - -无 - -## 子组件 - -无 - -## 接口 - -Line\(options?: \{width: Lenght, height: Length\}\) - -- 参数 - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

options

-

Object

-

-

-

-

options参数说明

-
- -- options参数说明 - - - - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

width

-

Length

-

-

-

-

宽度。

-

height

-

Length

-

-

-

-

高度。

-
- - -## 属性 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名称

-

参数类型

-

默认值

-

必填

-

参数描述

-

width

-

Length

-

0

-

-

直线所在矩形的宽度。

-

height

-

Length

-

0

-

-

直线所在矩形的高度。

-

startPoint

-

Point

-

[0, 0]

-

-

直线起点坐标(相对坐标)。

-

endPoint

-

Point

-

[0, 0]

-

-

直线终点坐标(相对坐标)。

-
- -## 示例 - -``` -@Entry -@Component -struct LineExample { - build() { - Column() { - Line({ width: 50, height: 100 }).startPoint([0, 0]).endPoint([50, 100]) - Line().width(200).height(200).startPoint([50, 50]).endPoint([150, 150]) - }.margin({ top: 5 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/line.jpg) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/04.\347\273\230\345\210\266\347\273\204\344\273\266/04.Polyline.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/04.\347\273\230\345\210\266\347\273\204\344\273\266/04.Polyline.md" deleted file mode 100644 index ed343466b1e76edbbf10c6bb93bfff8ee9807ee8..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/04.\347\273\230\345\210\266\347\273\204\344\273\266/04.Polyline.md" +++ /dev/null @@ -1,171 +0,0 @@ ---- -title: Polyline -permalink: /pages/010c0202010404 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:34 ---- -# Polyline - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -折线绘制组件。 - -## 权限列表 - -无 - -## 子组件 - -无 - -## 接口 - -Polyline\(options?: \{width: Lenght, height: Length\}\) - -- 参数 - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

options

-

Object

-

-

-

-

options参数说明

-
- -- options参数说明 - - - - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

width

-

Length

-

-

-

-

宽度。

-

height

-

Length

-

-

-

-

高度。

-
- - -## 属性 - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名称

-

参数类型

-

默认值

-

必填

-

参数描述

-

width

-

Length

-

0

-

-

折线所在矩形的宽度。

-

height

-

Length

-

0

-

-

折线所在矩形的高度。

-

points

-

Array<Point>

-

-

-

-

折线经过坐标点列表。

-
- -## 示例 - -``` -@Entry -@Component -struct PolylineExample { - build() { - Column({ space: 5 }) { - Flex({ justifyContent: FlexAlign.SpaceAround }) { - // 在 100 * 100 的矩形框中绘制一段折线,起点(0, 0),经过(20,60),到达终点(100, 100) - Polyline({ width: 100, height: 100 }).points([[0, 0], [20, 60], [100, 100]]) - // 在 100 * 100 的矩形框中绘制一段折线,起点(0, 0),经过(0,100),到达终点(100, 100) - Polyline().width(100).height(100).points([[0, 0], [0, 100], [100, 100]]) - }.width('100%') - }.margin({ top: 5 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/polyline.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/04.\347\273\230\345\210\266\347\273\204\344\273\266/05.Polygon.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/04.\347\273\230\345\210\266\347\273\204\344\273\266/05.Polygon.md" deleted file mode 100644 index cb00deba4ad53308a1519d33419b180344fb47bc..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/04.\347\273\230\345\210\266\347\273\204\344\273\266/05.Polygon.md" +++ /dev/null @@ -1,173 +0,0 @@ ---- -title: Polygon -permalink: /pages/010c0202010405 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:34 ---- -# Polygon - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -多边形绘制组件。 - -## 权限列表 - -无 - -## 子组件 - -无 - -## 接口 - -Polygon\(value:\{options?: \{width: Lenght, height: Length\}\}\) - -- 参数 - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

options

-

Object

-

-

-

-

options参数说明

-
- -- options参数说明 - - - - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

width

-

Length

-

-

-

-

宽度。

-

height

-

Length

-

-

-

-

高度。

-
- - -## 属性 - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名称

-

参数类型

-

默认值

-

必填

-

参数描述

-

width

-

Length

-

0

-

-

多边形所在矩形的宽度。

-

height

-

Length

-

0

-

-

多边形所在矩形的高度。

-

points

-

Array<Point>

-

-

-

-

多边形的顶点坐标列表。

-
- -## 示例 - -``` -@Entry -@Component -struct PolygonExample { - build() { - Column({ space: 5 }) { - Flex({ justifyContent: FlexAlign.SpaceAround }) { - // 在 100 * 100 的矩形框中绘制一个三角形,起点(0, 0),经过(50, 100),终点(100, 0) - Polygon({ width: 100, height: 100 }).points([[0, 0], [50, 100], [100, 0]]) - // 在 100 * 100 的矩形框中绘制一个四边形,起点(0, 0),经过(0, 100)和(100, 100),终点(100, 0) - Polygon().width(100).height(100).points([[0, 0], [0, 100], [100, 100], [100, 0]]) - // 在 100 * 100 的矩形框中绘制一个五边形,起点(50, 0),依次经过(0, 50)、(20, 100)和(80, 100),终点(100, 50) - Polygon().width(100).height(100).points([[50, 0], [0, 50], [20, 100], [80, 100], [100, 50]]) - }.width('100%') - }.margin({ top: 5 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/polygon.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/04.\347\273\230\345\210\266\347\273\204\344\273\266/06.Path.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/04.\347\273\230\345\210\266\347\273\204\344\273\266/06.Path.md" deleted file mode 100644 index b4ccf6cec5026d445acf0d6c1ca78644d5c520a7..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/04.\347\273\230\345\210\266\347\273\204\344\273\266/06.Path.md" +++ /dev/null @@ -1,128 +0,0 @@ ---- -title: Path -permalink: /pages/010c0202010406 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:34 ---- -# Path - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -路径绘制组件。 - -## 权限列表 - -无 - -## 子组件 - -无 - -## 属性 - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名称

-

参数类型

-

默认值

-

必填

-

参数描述

-

width

-

Length

-

0

-

-

路径所在矩形的宽度。

-

height

-

Length

-

0

-

-

路径所在矩形的高度。

-

commands

-

string

-

''

-

-

路径绘制的命令字符串。

-
- -支持的绘制命令如下: - -- M = moveto -- L = lineto -- H = horizontal lineto -- V = vertical lineto -- C = curveto -- S = smooth curveto -- Q = quadratic Belzier curve -- T = smooth quadratic Belzier curveto -- A = elliptical Arc -- Z = closepath - -如 commands\('M0 20 L50 50 L50 100 Z'\)定义了一条路径,开始于位置(0,20),到达位置(50,50)后再到(50,100),最后在(0,20)处关闭路径。 - -## 示例 - -``` -@Entry -@Component -struct PathExample { - build() { - Column({ space: 5 }) { - Text('Straight line').fontSize(9).fontColor(0xCCCCCC).width('90%') - Path().width(300).height(10).commands('M0 0 L900 0').stroke(Color.Black).strokeWidth(3) - - Text('Straight line graph').fontSize(9).fontColor(0xCCCCCC).width('90%') - Flex({ justifyContent: FlexAlign.SpaceAround }) { - // 先后执行MoveTo(150, 0), LineTo(300, 300), LineTo(0, 300), ClosePath() - Path().width(100).height(100).commands('M150 0 L300 300 L0 300 Z') - // 先后执行MoveTo(0, 0), HorizontalLineto(300), VerticalLineto(300), HorizontalLineto(0), ClosePath() - Path().width(100).height(100).commands('M0 0 H300 V300 H0 Z') - // 先后执行MoveTo(150, 0), LineTo(0, 150), LineTo(60, 300), LineTo(240, 300), LineTo(300, 150), ClosePath() - Path().width(100).height(100).commands('M150 0 L0 150 L60 300 L240 300 L300 150 Z') - }.width('100%') - - Text('Curve graphics').fontSize(9).fontColor(0xCCCCCC).width('90%') - Flex({ justifyContent: FlexAlign.SpaceAround }) { - // 先后执行MoveTo(0, 300),(150, 0)(300, 300)两点之间画曲线, ClosePath() - Path().width(100).height(100).commands("M0 300 S150 0 300 300 Z") - // 先后执行MoveTo(0, 150),(0, 150)(150, 0)(300, 150)三点之间依次画曲线, LineTo(150, 300),ClosePath() - Path().width(100).height(100).commands('M0 150 C0 150 150 0 300 150 L150 300 Z') - } - }.width('100%').margin({ top: 5 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/path.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/04.\347\273\230\345\210\266\347\273\204\344\273\266/07.Rect.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/04.\347\273\230\345\210\266\347\273\204\344\273\266/07.Rect.md" deleted file mode 100644 index d1cc246d231ddfeb6c6e76074352f09138c801cc..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/04.\347\273\230\345\210\266\347\273\204\344\273\266/07.Rect.md" +++ /dev/null @@ -1,231 +0,0 @@ ---- -title: Rect -permalink: /pages/010c0202010407 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:34 ---- -# Rect - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -矩形绘制组件。 - -## 权限列表 - -无 - -## 子组件 - -无 - -## 接口 - -Rect\(value:\{options?: \{width: Length,height: Length,radius?: Length | Array\} | \{width: Length,height: Length,radiusWidth?: Length,radiusHeight?: Length\}\}\) - -- 参数 - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

options

-

Object

-

-

-

-

options参数说明

-
- -- options参数说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

width

-

Length

-

-

-

-

宽度。

-

height

-

Length

-

-

-

-

高度。

-

radius

-

Length | Array<Length>

-

-

0

-

圆角半径,支持分别设置四个角的圆角度数。

-

radiusWidth

-

Length

-

-

0

-

圆角宽度。

-

radiusHeight

-

Length

-

-

0

-

圆角高度。

-
- - -## 属性 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名称

-

参数类型

-

默认值

-

必填

-

参数描述

-

width

-

Length

-

0

-

-

宽度。

-

height

-

Length

-

0

-

-

高度。

-

radiusWidth

-

Length

-

0

-

-

圆角的宽度,仅设置宽时宽高一致。

-

radiusHeight

-

Length

-

0

-

-

圆角的高度,仅设置高时宽高一致。

-

radius

-

Length | Array<Length>

-

0

-

-

圆角大小。

-
- -## 示例 - -``` -@Entry -@Component -struct RectExample { - build() { - Column({ space: 5 }) { - Text('normal').fontSize(9).fontColor(0xCCCCCC).width('90%') - // 绘制90% * 50矩形 - Rect({ width: '90%', height: 50 }) - // 绘制90% * 50矩形 - Rect().width('90%').height(50) - - Text('with rounded corners').fontSize(9).fontColor(0xCCCCCC).width('90%') - // 绘制90% * 50矩形, 圆角宽高20 - Rect({ width: '90%', height: 50 }).radiusHeight(20).radiusWidth(20) - // 绘制90% * 50矩形, 圆角宽高20 - Rect({ width: '90%', height: 50 }).radius(20) - }.width('100%').margin({ top: 5 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/rect.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/04.\347\273\230\345\210\266\347\273\204\344\273\266/08.Shape.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/04.\347\273\230\345\210\266\347\273\204\344\273\266/08.Shape.md" deleted file mode 100644 index f345f2773472af454e98dce28dfcaaa08332ae45..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/04.\347\273\230\345\210\266\347\273\204\344\273\266/08.Shape.md" +++ /dev/null @@ -1,301 +0,0 @@ ---- -title: Shape -permalink: /pages/010c0202010408 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:34 ---- -# Shape - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -绘制组件的父组件,父组件中会描述所有绘制组件均支持的通用属性。 - -1、绘制组件使用Shape作为父组件,实现类似SVG的效果。 - -2、绘制组件单独使用,用于在页面上绘制指定的图形。 - -## 权限列表 - -无 - -## 子组件 - -可以包含子组件。 - -## 接口 - -Shape\(value:\{target?: PixelMap\}\) - -- 参数 - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

target

-

PixelMap

-

-

null

-

绘制目标,可将图形绘制在指定的PixelMap对象中,若未设置,则在当前绘制目标中进行绘制。

-
- - -## 属性 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名称

-

参数类型

-

默认值

-

必填

-

参数描述

-

viewPort

-

{

-

x: Length,

-

y: Length,

-

width: Length,

-

height: Length

-

}

-

-

-

-

形状的视口。

-

fill

-

Color

-

Black

-

-

填充颜色。

-

stroke

-

Color

-

-

-

-

边框颜色。

-

strokeDashArray

-

Array<Length>

-

[]

-

-

设置边框的间隙。

-

strokeDashOffset

-

Length

-

0

-

-

边框绘制起点的偏移量。

-

strokeLineCap

-

LineCapStyle

-

Butt

-

-

路径端点绘制样式。

-

strokeLineJoin

-

LineJoinStyle

-

Miter

-

-

边框拐角绘制样式。

-

strokeMiterLimit

-

number

-

4

-

-

锐角绘制成斜角的极限值。

-

strokeOpacity

-

number

-

1

-

-

设置边框的不透明度。

-

strokeWidth

-

Length

-

1

-

-

设置边框的宽度。

-

antiAlias

-

boolean

-

true

-

-

是否开启抗锯齿。

-
- -- LineJoinStyle枚举说明 - - - - - - - - - - - - - - - -

名称

-

描述

-

Bevel

-

使用斜角连接路径段。

-

Miter

-

使用尖角连接路径段。

-

Round

-

使用圆角连接路径段。

-
- - -## 示例 - -``` -@Entry -@Component -struct ShapeExample { - build() { - Column({ space: 5 }) { - Text('basic').fontSize(30).fontColor(0xCCCCCC).width(320) - // 在Shape的(-2, -2)点绘制一个 300 * 50 带边框的矩形,颜色0x317Af7,边框颜色黑色,边框宽度4,边框间隙20,向左偏移10,尖端样式圆角,拐角样式圆角,抗锯齿(默认开启) - // 在Shape的(-2, 58)点绘制一个 300 * 50 带边框的椭圆,颜色0x317Af7,边框颜色黑色,边框宽度4,边框间隙20,向左偏移10,尖端样式圆角,拐角样式圆角,抗锯齿(默认开启) - // 在Shape的(-2, 118)点绘制一个 300 * 10 线段,颜色0x317Af7,边框颜色黑色,宽度4,间隙20,向左偏移10,尖端样式圆角,拐角样式圆角,抗锯齿(默认开启) - Shape() { - Rect().width(300).height(50) - Ellipse().width(300).height(50).offset({ x: 0, y: 60 }) - Path().width(300).height(10).commands('M0 0 L900 0').offset({ x: 0, y: 120 }) - } - .viewPort({ x: -2, y: -2, width: 304, height: 130 }) - .fill(0x317Af7).stroke(Color.Black).strokeWidth(4) - .strokeDashArray([20]).strokeDashOffset(10).strokeLineCap(LineCapStyle.Round) - .strokeLineJoin(LineJoinStyle.Round).antiAlias(true) - // 在Shape的(-1, -1)点绘制一个 300 * 50 带边框的矩形,颜色0x317Af7,边框颜色黑色,边框宽度2 - Shape() { - Rect().width(300).height(50) - }.viewPort({ x: -1, y: -1, width: 302, height: 52 }).fill(0x317Af7).stroke(Color.Black).strokeWidth(2) - - Text('border').fontSize(30).fontColor(0xCCCCCC).width(320).margin({top:30}) - // 在Shape的(0, -5)点绘制一个 300 * 10 直线,颜色0xEE8443,边框宽度10,边框间隙20 - Shape() { - Path().width(300).height(10).commands('M0 0 L900 0') - }.viewPort({ x: 0, y: -5, width: 300, height: 20 }).stroke(0xEE8443).strokeWidth(10).strokeDashArray([20]) - // 在Shape的(0, -5)点绘制一个 300 * 10 直线,颜色0xEE8443,边框宽度10,边框间隙20,向左偏移10 - Shape() { - Path().width(300).height(10).commands('M0 0 L900 0') - } - .viewPort({ x: 0, y: -5, width: 300, height: 20 }) - .stroke(0xEE8443).strokeWidth(10).strokeDashArray([20]).strokeDashOffset(10) - // 在Shape的(0, -5)点绘制一个 300 * 10 直线,颜色0xEE8443,边框宽度10,透明度0.5 - Shape() { - Path().width(300).height(10).commands('M0 0 L900 0') - }.viewPort({ x: 0, y: -5, width: 300, height: 20 }).stroke(0xEE8443).strokeWidth(10).strokeOpacity(0.5) - // 在Shape的(0, -5)点绘制一个 300 * 10 直线,颜色0xEE8443,边框宽度10,边框间隙20,向左偏移10,尖端样式圆角 - Shape() { - Path().width(300).height(10).commands('M0 0 L900 0') - } - .viewPort({ x: 0, y: -5, width: 300, height: 20 }) - .stroke(0xEE8443).strokeWidth(10).strokeDashArray([20]).strokeLineCap(LineCapStyle.Round) - // 在Shape的(-5, -5)点绘制一个 300 * 50 带边框的矩形,颜色0x317Af7,边框宽度10,边框颜色0xEE8443,拐角样式圆角 - Shape() { - Rect().width(300).height(100) - } - .viewPort({ x: -5, y: -5, width: 310, height: 120 }) - .fill(0x317Af7).stroke(0xEE8443).strokeWidth(10).strokeLineJoin(LineJoinStyle.Round) - Shape() { - Path().width(300).height(60).commands('M0 0 L400 0 L400 200 Z') - } - .viewPort({ x: -80, y: -5, width: 310, height: 100 }) - .fill(0x317Af7).stroke(0xEE8443).strokeWidth(10) - .strokeLineJoin(LineJoinStyle.Miter).strokeMiterLimit(5) - }.width('100%').margin({ top: 15 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/2-01.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/01.Canvas.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/01.Canvas.md" deleted file mode 100644 index 6bdb72feda3948306eeaaeddd18491d7df5dcfc8..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/01.Canvas.md" +++ /dev/null @@ -1,112 +0,0 @@ ---- -title: Canvas -permalink: /pages/010c0202010501 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:34 ---- -# Canvas - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -提供画布组件,用于自定义绘制图形。 - -## 权限列表 - -无 - -## 子组件 - -不支持。 - -## 接口 - -Canvas\(context: CanvasRenderingContext2D\) - -- 参数 - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

context

-

CanvasRenderingContext2D

-

-

-

-

CanvasRenderingContext2D对象。

-
- - -## 属性 - -支持[通用属性](/pages/010c020201010201)。 - -## 事件 - -除支持[通用事件](/pages/010c020201010101)外,还支持如下事件: - - - - - - - - - - - -

名称

-

参数

-

描述

-

onReady(callback: () => void)

-

-

画布组件的事件回调,可以在此时进行绘制。

-
- -## 示例 - -``` -@Entry -@Component -struct CanvasExample { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.fillRect(0,30,100,100) - }) - } - .width('100%') - .height('100%') - } -} -``` - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/02.CanvasRenderingContext2D\345\257\271\350\261\241.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/02.CanvasRenderingContext2D\345\257\271\350\261\241.md" deleted file mode 100644 index 29eefb57a704a91c192234ac0497313f184d58a9..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/02.CanvasRenderingContext2D\345\257\271\350\261\241.md" +++ /dev/null @@ -1,3797 +0,0 @@ ---- -title: CanvasRenderingContext2D对象 -permalink: /pages/010c0202010502 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:35 ---- -# CanvasRenderingContext2D对象 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -使用RenderingContext在Canvas组件上进行绘制,绘制对象可以是矩形、文本、图片等。 - -## 接口 - -CanvasRenderingContext2D\(setting: RenderingContextSetting\) - -- 参数 - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

setting

-

RenderingContextSettings

-

-

-

-

RenderingContextSettings

-
- - -### RenderingContextSettings - -RenderingContextSettings\(antialias?: bool, alpha?: bool\) - -用来配置CanvasRenderingContext2D对象的参数,包括是否开启抗锯齿和是否包含一个alpha通道。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

antialias

-

bool

-

-

false

-

表明canvas是否开启抗锯齿。

-

alpha

-

bool

-

-

false

-

表明canvas包含是否包含一个alpha通道。

-
- - -## 属性 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

描述

-

fillStyle

-

<color> | CanvasGradient | CanvasPattern

-

-

-

指定绘制的填充色。

-
  • 类型为<color>时,表示设置填充区域的颜色。
  • 类型为CanvasGradient时,表示渐变对象,使用createLinearGradient方法创建。
  • 类型为CanvasPattern时,使用createPattern方法创建。
-

lineWidth

-

number

-

-

-

设置绘制线条的宽度。

-

strokeStyle

-

<color> | CanvasGradient | CanvasPattern

-

-

-

设置描边的颜色。

-
  • 类型为<color>时,表示设置描边使用的颜色。
  • 类型为CanvasGradient时,表示渐变对象,使用createLinearGradient方法创建。
  • 类型为CanvasPattern时,使用createPattern方法创建。
-

lineCap

-

string

-

'butt'

-

指定线端点的样式,可选值为:

-
  • 'butt':线端点以方形结束。
  • 'round':线端点以圆形结束。
  • 'square':线端点以方形结束,该样式下会增加一个长度和线段厚度相同,宽度是线段厚度一半的矩形。
-

lineJoin

-

string

-

'miter'

-

指定线段间相交的交点样式,可选值为:

-
  • 'round':在线段相连处绘制一个扇形,扇形的圆角半径是线段的宽度。
  • 'bevel':在线段相连处使用三角形为底填充, 每个部分矩形拐角独立。
  • 'miter':在相连部分的外边缘处进行延伸,使其相交于一点,形成一个菱形区域,该属性可以通过设置miterLimit属性展现效果。
-

miterLimit

-

number

-

10

-

设置斜接面限制值,该值指定了线条相交处内角和外角的距离。

-

font

-

string

-

'normal normal 14px sans-serif'

-

设置文本绘制中的字体样式。

-

语法:ctx.font='font-size font-family'

-
  • font-size(可选),指定字号和行高,单位只支持px。
  • font-family(可选),指定字体系列。
-

语法:ctx.font='font-style font-weight font-size font-family'

-
  • font-style(可选),用于指定字体样式,支持如下几种样式:'normal',talic。
  • font-weight(可选),用于指定字体的粗细,支持如下几种类型:'normal', 'bold', 'bolder', 'lighter', 100, 200, 300, 400, 500, 600, 700, 800, 900。
  • font-size(可选),指定字号和行高,单位只支持px。
  • font-family(可选),指定字体系列,支持如下几种类型:'sans-serif', 'serif', 'monospace'。
-

textAlign

-

string

-

'left'

-

设置文本绘制中的文本对齐方式,可选值为:

-
  • 'left':文本左对齐。
  • 'right':文本右对齐。
  • 'center':文本居中对齐。
  • 'start':文本对齐界线开始的地方。
  • 'end':文本对齐界线结束的地方。
-
说明:

ltr布局模式下'start'和'left'一致,rtl布局模式下'start'和'right'一致·。

-
-

textBaseline

-

string

-

'alphabetic'

-

设置文本绘制中的水平对齐方式,可选值为:

-
  • 'alphabetic':文本基线是标准的字母基线。
  • 'top':文本基线在文本块的顶部。
  • 'hanging':文本基线是悬挂基线。
  • 'middle':文本基线在文本块的中间。
  • 'ideographic':文字基线是表意字基线;如果字符本身超出了alphabetic基线,那么ideograhpic基线位置在字符本身的底部。
  • 'bottom':文本基线在文本块的底部。 与ideographic基线的区别在于ideographic基线不需要考虑下行字母。
-

globalAlpha

-

number

-

-

-

设置透明度,0.0为完全透明,1.0为完全不透明。

-

lineDashOffset

-

number

-

0.0

-

设置画布的虚线偏移量,精度为float。

-

globalCompositeOperation

-

string

-

'source-over'

-

设置合成操作的方式。类型字段可选值有'source-over','source-atop','source-in','source-out','destination-over','destination-atop','destination-in','destination-out','lighter','copy','xor'。

-

shadowBlur

-

number

-

0.0

-

设置绘制阴影时的模糊级别,值越大越模糊,精度为float。

-

shadowColor

-

<color>

-

-

-

设置绘制阴影时的阴影颜色。

-

shadowOffsetX

-

number

-

-

-

设置绘制阴影时和原有对象的水平偏移值。

-

shadowOffsetY

-

number

-

-

-

设置绘制阴影时和原有对象的垂直偏移值。

-

imageSmoothingEnabled

-

boolean

-

true

-

用于设置绘制图片时是否进行图像平滑度调整,true为启用,false为不启用。

-

imageSmoothingQuality

-

string

-

'low'

-

用于设置图像平滑度,支持如下三种类型:'low', 'medium', 'high'。

-
- ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->类型格式为 'rgb\(255, 255, 255\)','rgba\(255, 255, 255, 1.0\)','\#FFFFFF'。 - -### fillStyle - -``` -@Entry -@Component -struct FillStyleExample { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.fillStyle = '#0000ff' - this.context.fillRect(20, 160, 150, 100) - }) - } - .width('100%') - .height('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193322850.png) - -### lineWidth - -``` -@Entry -@Component -struct LineWidthExample { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.lineWidth = 5 - this.context.strokeRect(25, 25, 85, 105) - }) - } - .width('100%') - .height('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238402745.png) - -### strokeStyle - -``` -@Entry -@Component -struct StrokeStyleExample { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.lineWidth = 10 - this.context.strokeStyle = '#0000ff' - this.context.strokeRect(25, 25, 155, 105) - }) - } - .width('100%') - .height('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238282783.png) - -### lineCap - -``` -@Entry -@Component -struct LineCapExample { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.lineWidth = 8 - this.context.beginPath() - this.context.lineCap = 'round' - this.context.moveTo(30, 50) - this.context.lineTo(220, 50) - this.context.stroke() - }) - } - .width('100%') - .height('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193642802.png) - -### lineJoin - -``` -@Entry -@Component -struct LineJoinExample { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.beginPath() - this.context.lineWidth = 8 - this.context.lineJoin = 'miter' - this.context.moveTo(30, 30) - this.context.lineTo(120, 60) - this.context.lineTo(30, 110) - this.context.stroke() - }) - } - .width('100%') - .height('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193802788.png) - -### miterLimit - -``` -@Entry -@Component -struct MiterLimit { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.lineWidth = 8 - this.context.lineJoin = 'miter' - this.context.miterLimit = 3 - this.context.moveTo(30, 30) - this.context.lineTo(60, 35) - this.context.lineTo(30, 37) - this.context.stroke() - }) - } - .width('100%') - .height('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238522733.png) - -### font - -``` -@Entry -@Component -struct Font { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.font = '30px sans-serif' - this.context.fillText("Hello World", 20, 60) - }) - } - .width('100%') - .height('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193482814.png) - -### textAlign - -``` -@Entry -@Component -struct TextAlign { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.strokeStyle = '#0000ff' - this.context.moveTo(140, 10) - this.context.lineTo(140, 160) - this.context.stroke() - - this.context.font = '18px sans-serif' - - this.context.textAlign = 'start' - this.context.fillText('textAlign=start', 140, 60) - this.context.textAlign = 'end' - this.context.fillText('textAlign=end', 140, 80) - this.context.textAlign = 'left' - this.context.fillText('textAlign=left', 140, 100) - this.context.textAlign = 'center' - this.context.fillText('textAlign=center',140, 120) - this.context.textAlign = 'right' - this.context.fillText('textAlign=right',140, 140) - }) - } - .width('100%') - .height('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238602771.png) - -### textBaseline - -``` -@Entry -@Component -struct TextBaseline { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.strokeStyle = '#0000ff' - this.context.moveTo(0, 120) - this.context.lineTo(400, 120) - this.context.stroke() - - this.context.font = '20px sans-serif' - - this.context.textBaseline = 'top' - this.context.fillText('Top', 10, 120) - this.context.textBaseline = 'bottom' - this.context.fillText('Bottom', 55, 120) - this.context.textBaseline = 'middle' - this.context.fillText('Middle', 125, 120) - this.context.textBaseline = 'alphabetic' - this.context.fillText('Alphabetic', 195, 120) - this.context.textBaseline = 'hanging' - this.context.fillText('Hanging', 295, 120) - }) - } - .width('100%') - .height('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193322872.png) - -### globalAlpha - -``` -@Entry -@Component -struct GlobalAlpha { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.fillStyle = 'rgb(255,0,0)' - this.context.fillRect(0, 0, 50, 50) - this.context.globalAlpha = 0.4 - this.context.fillStyle = 'rgb(0,0,255)' - this.context.fillRect(50, 50, 50, 50) - }) - } - .width('100%') - .height('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238402777.png) - -### lineDashOffset - -``` -@Entry -@Component -struct LineDashOffset { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.arc(100, 75, 50, 0, 6.28) - this.context.setLineDash([10,20]) - this.context.stroke(); - }) - } - .width('100%') - .height('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238282827.png) - -### globalCompositeOperation - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

描述

-

source-over

-

在现有绘制内容上显示新绘制内容,属于默认值。

-

source-atop

-

在现有绘制内容顶部显示新绘制内容。

-

source-in

-

在现有绘制内容中显示新绘制内容。

-

source-out

-

在现有绘制内容之外显示新绘制内容。

-

destination-over

-

在新绘制内容上方显示现有绘制内容。

-

destination-atop

-

在新绘制内容顶部显示现有绘制内容。

-

destination-in

-

在新绘制内容中显示现有绘制内容。

-

destination-out

-

在新绘制内容外显示现有绘制内容。

-

lighter

-

显示新绘制内容和现有绘制内容。

-

copy

-

显示新绘制内容而忽略现有绘制内容。

-

xor

-

使用异或操作对新绘制内容与现有绘制内容进行融合。

-
- -``` -@Entry -@Component -struct GlobalCompositeOperation { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.fillStyle = 'rgb(255,0,0)' - this.context.fillRect(20, 20, 50, 50) - this.context.globalCompositeOperation = 'source-over' - this.context.fillStyle = 'rgb(0,0,255)' - this.context.fillRect(50, 50, 50, 50) - this.context.fillStyle = 'rgb(255,0,0)' - this.context.fillRect(120, 20, 50, 50) - this.context.globalCompositeOperation = 'destination-over' - this.context.fillStyle = 'rgb(0,0,255)' - this.context.fillRect(150, 50, 50, 50) - }) - } - .width('100%') - .height('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193642848.png) - -### shadowBlur - -``` -@Entry -@Component -struct ShadowBlur { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true); - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings); - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.shadowBlur = 30 - this.context.shadowColor = 'rgb(0,0,0)' - this.context.fillStyle = 'rgb(255,0,0)' - this.context.fillRect(20, 20, 100, 80) - }) - } - .width('100%') - .height('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193802836.png) - -### shadowColor - -``` -@Entry -@Component -struct ShadowColor { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.shadowBlur = 30 - this.context.shadowColor = 'rgb(0,0,255)' - this.context.fillStyle = 'rgb(255,0,0)' - this.context.fillRect(30, 30, 100, 100) - }) - } - .width('100%') - .height('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238522783.png) - -### shadowOffsetX - -``` -@Entry -@Component -struct ShadowOffsetX { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.shadowBlur = 10 - this.context.shadowOffsetX = 20 - this.context.shadowColor = 'rgb(0,0,0)' - this.context.fillStyle = 'rgb(255,0,0)' - this.context.fillRect(20, 20, 100, 80) - }) - } - .width('100%') - .height('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193482866.png) - -### shadowOffsetY - -``` -@Entry -@Component -struct ShadowOffsetY { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.shadowBlur = 10 - this.context.shadowOffsetY = 20 - this.context.shadowColor = 'rgb(0,0,0)' - this.context.fillStyle = 'rgb(255,0,0)' - this.context.fillRect(30, 30, 100, 100) - }) - } - .width('100%') - .height('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238602821.png) - -### imageSmoothingEnabled - -``` -@Entry -@Component -struct ImageSmoothingEnabled { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private img:ImageBitmap = new ImageBitmap("common/images/icon.jpg") - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.imageSmoothingEnabled = false - this.context.drawImage( this.img,0,0,400,200) - }) - } - .width('100%') - .height('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193322910.png) - -## 方法 - -### fillRect - -fillRect\(x: number, y: number, w: number, h: number\): void - -填充一个矩形。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

说明

-

x

-

number

-

-

0

-

指定矩形左上角点的x坐标。

-

y

-

number

-

-

0

-

指定矩形左上角点的y坐标。

-

width

-

number

-

-

0

-

指定矩形的宽度。

-

height

-

number

-

-

0

-

指定矩形的高度。

-
- - -- 示例 - - ``` - @Entry - @Component - struct FillRect { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.fillRect(0,30,100,100) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193737314.png) - - -### strokeRect - -strokeRect\(x: number, y: number, w: number, h: number\): void - -绘制具有边框的矩形,矩形内部不填充。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

说明

-

x

-

number

-

-

0

-

指定矩形的左上角x坐标。

-

y

-

number

-

-

0

-

指定矩形的左上角y坐标。

-

width

-

number

-

-

0

-

指定矩形的宽度。

-

height

-

number

-

-

0

-

指定矩形的高度。

-
- - -- 示例 - - ``` - @Entry - @Component - struct StrokeRect { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.strokeRect(30, 30, 200, 150) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238457271.png) - - -### clearRect - -clearRect\(x: number, y: number, w: number, h: number\): void - -删除指定区域内的绘制内容。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

x

-

number

-

-

0

-

指定矩形上的左上角x坐标。

-

y

-

number

-

-

0

-

指定矩形上的左上角y坐标。

-

width

-

number

-

-

0

-

指定矩形的宽度。

-

height

-

number

-

-

0

-

指定矩形的高度。

-
- - -- 示例 - - ``` - @Entry - @Component - struct ClearRect { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.fillStyle = 'rgb(0,0,255)' - this.context.fillRect(0,0,500,500) - this.context.clearRect(20,20,150,100) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/11111.png) - - -### fillText - -fillText\(text: string, x: number, y: number\): void - -绘制填充类文本。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

说明

-

text

-

string

-

-

“”

-

需要绘制的文本内容。

-

x

-

number

-

-

0

-

需要绘制的文本的左下角x坐标。

-

y

-

number

-

-

0

-

需要绘制的文本的左下角y坐标。

-
- - -- 示例 - - ``` - @Entry - @Component - struct FillText { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.font = '30px sans-serif' - this.context.fillText("Hello World!", 20, 100) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238537297.png) - - -### strokeText - -strokeText\(text: string, x: number, y: number\): void - -绘制描边类文本。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

text

-

string

-

-

“”

-

需要绘制的文本内容。

-

x

-

number

-

-

0

-

需要绘制的文本的左下角x坐标。

-

y

-

number

-

-

0

-

需要绘制的文本的左下角y坐标。

-
- - -- 示例 - - ``` - @Entry - @Component - struct StrokeText { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.font = '55px sans-serif' - this.context.strokeText("Hello World!", 20, 60) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193756416.png) - - -### measureText - -measureText\(text: string\): TextMetrics - -该方法返回一个文本测算的对象,通过该对象可以获取指定文本的宽度值。 - -- 参数 - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

说明

-

text

-

string

-

-

""

-

需要进行测量的文本。

-
- - -- 返回值 - - - - - - - - - -

类型

-

说明

-

TextMetrics

-

文本的尺寸信息

-
- -- TextMetrics类型描述 - - - - - - - - - - - -

属性

-

类型

-

描述

-

width

-

number

-

字符串的宽度。

-
- - -- 示例 - - ``` - @Entry - @Component - struct MeasureText { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.font = '50px sans-serif' - this.context.fillText("Hello World!", 20, 100) - this.context.fillText("width:" + this.context.measureText("Hello World!").width, 20, 200) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238476361.png) - - -### stroke - -stroke\(path?: Path2D\): void - -进行边框绘制操作。 - -- 参数 - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

path

-

Path2D

-

-

null

-

需要绘制的Path2D。

-
- - -- 示例 - - ``` - @Entry - @Component - struct Stroke { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.moveTo(25, 25) - this.context.lineTo(25, 105) - this.context.strokeStyle = 'rgb(0,0,255)' - this.context.stroke() - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193436448.png) - - -### beginPath - -beginPath\(\): void - -创建一个新的绘制路径。 - -- 示例 - - ``` - @Entry - @Component - struct BeginPath { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.beginPath() - this.context.lineWidth = 6 - this.context.strokeStyle = '#0000ff' - this.context.moveTo(15, 80) - this.context.lineTo(280, 160) - this.context.stroke() - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238556395.png) - - -### moveTo - -moveTo\(x: number, y: number\): void - -路径从当前点移动到指定点。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

说明

-

x

-

number

-

-

0

-

指定位置的x坐标。

-

y

-

number

-

-

0

-

指定位置的y坐标。

-
- - -- 示例 - - ``` - @Entry - @Component - struct MoveTo { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.beginPath() - this.context.moveTo(10, 10) - this.context.lineTo(280, 160) - this.context.stroke() - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193481094.png) - - -### lineTo - -lineTo\(x: number, y: number\): void - -从当前点到指定点进行路径连接。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

x

-

number

-

-

0

-

指定位置的x坐标。

-

y

-

number

-

-

0

-

指定位置的y坐标。

-
- - -- 示例 - - ``` - @Entry - @Component - struct LineTo { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.beginPath() - this.context.moveTo(10, 10) - this.context.lineTo(280, 160) - this.context.stroke() - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238601051.png) - - -### closePath - -closePath\(\): void - -结束当前路径形成一个封闭路径。 - -- 示例 - - ``` - @Entry - @Component - struct ClosePath { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.beginPath() - this.context.moveTo(30, 30) - this.context.lineTo(110, 30) - this.context.lineTo(70, 90) - this.context.closePath() - this.context.stroke() - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193321136.png) - - -### createPattern - -createPattern\(image: ImageBitmap, repetition: string\): void - -通过指定图像和重复方式创建图片填充的模板。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

image

-

ImageBitmap

-

-

null

-

图源对象,具体参考 ImageBitmap对象。

-

repetition

-

string

-

-

“”

-

设置图像重复的方式,取值为:'repeat'、'repeat-x'、 'repeat-y'、'no-repeat'。

-
- -- 示例 - - ``` - @Entry - @Component - struct CreatePattern { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private img:ImageBitmap = new ImageBitmap("common/images/icon.jpg") - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - var pattern = this.context.createPattern(this.img, 'repeat') - this.context.fillStyle = pattern - this.context.fillRect(0, 0, 200, 200) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238401029.png) - - -### bezierCurveTo - -bezierCurveTo\(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number\): void - -创建三次贝赛尔曲线的路径。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

cp1x

-

number

-

-

0

-

第一个贝塞尔参数的x坐标值。

-

cp1y

-

number

-

-

0

-

第一个贝塞尔参数的y坐标值。

-

cp2x

-

number

-

-

0

-

第二个贝塞尔参数的x坐标值。

-

cp2y

-

number

-

-

0

-

第二个贝塞尔参数的y坐标值。

-

x

-

number

-

-

0

-

路径结束时的x坐标值。

-

y

-

number

-

-

0

-

路径结束时的y坐标值。

-
- - -- 示例 - - ``` - @Entry - @Component - struct BezierCurveTo { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.beginPath() - this.context.moveTo(10, 10) - this.context.bezierCurveTo(20, 100, 200, 100, 200, 20) - this.context.stroke() - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238281067.png) - - -### quadraticCurveTo - -quadraticCurveTo\(cpx: number, cpy: number, x: number, y: number\): void - -创建二次贝赛尔曲线的路径。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

cpx

-

number

-

-

0

-

贝塞尔参数的x坐标值。

-

cpy

-

number

-

-

0

-

贝塞尔参数的y坐标值。

-

x

-

number

-

-

0

-

路径结束时的x坐标值。

-

y

-

number

-

-

0

-

路径结束时的y坐标值。

-
- - -- 示例 - - ``` - @Entry - @Component - struct QuadraticCurveTo { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true); - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings); - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.beginPath(); - this.context.moveTo(20, 20); - this.context.quadraticCurveTo(100, 100, 200, 20); - this.context.stroke(); - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193641084.png) - - -### arc - -arc\(x: number, y: number, radius: number, startAngle: number, endAngle: number, anticlockwise?: boolean\): void - -绘制弧线路径。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

x

-

number

-

-

0

-

弧线圆心的x坐标值。

-

y

-

number

-

-

0

-

弧线圆心的y坐标值。

-

radius

-

number

-

-

0

-

弧线的圆半径。

-

startAngle

-

number

-

-

0

-

弧线的起始弧度。

-

endAngle

-

number

-

-

0

-

弧线的终止弧度。

-

anticlockwise

-

boolean

-

-

false

-

是否逆时针绘制圆弧。

-
- - -- 示例 - - ``` - @Entry - @Component - struct Arc { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.beginPath() - this.context.arc(100, 75, 50, 0, 6.28) - this.context.stroke() - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193801070.png) - - -### arcTo - -arcTo\(x1: number, y1: number, x2: number, y2: number, radius: number\): void - -依据圆弧经过的点和圆弧半径创建圆弧路径。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

x1

-

number

-

-

0

-

圆弧经过的第一个点的x坐标值。

-

y1

-

number

-

-

0

-

圆弧经过的第一个点的y坐标值。

-

x2

-

number

-

-

0

-

圆弧经过的第二个点的x坐标值。

-

y2

-

number

-

-

0

-

圆弧经过的第二个点的y坐标值。

-

radius

-

number

-

-

0

-

圆弧的圆半径值。

-
- - -- 示例 - - ``` - @Entry - @Component - struct ArcTo { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.moveTo(100, 20); - this.context.arcTo(150, 20, 150, 70, 50); - this.context.stroke(); - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238521019.png) - - -### ellipse - -ellipse\(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, anticlockwise?: boolean\): void - -在规定的矩形区域绘制一个椭圆。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

说明

-

x

-

number

-

-

0

-

椭圆圆心的x轴坐标。

-

y

-

number

-

-

0

-

椭圆圆心的y轴坐标。

-

radiusX

-

number

-

-

0

-

椭圆x轴的半径长度。

-

radiusY

-

number

-

-

0

-

椭圆y轴的半径长度。

-

rotation

-

number

-

-

0

-

椭圆的旋转角度,单位为弧度。

-

startAngle

-

number

-

-

0

-

椭圆绘制的起始点角度,以弧度表示。

-

endAngle

-

number

-

-

0

-

椭圆绘制的结束点角度,以弧度表示。

-

anticlockwise

-

number

-

-

0

-

是否以逆时针方向绘制椭圆,0为顺时针,1为逆时针。(可选参数,默认为0)

-
- - -- 示例 - - ``` - @Entry - @Component - struct Ellipse { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.beginPath() - this.context.ellipse(200, 200, 50, 100, Math.PI * 0.25, Math.PI * 0.5, Math.PI, true) - this.context.stroke() - }) - Button('back') - .onClick(() => { - router.back() - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193481096.png) - - -### rect - -rect\(x: number, y: number, width: number, height: number\): void - -创建矩形路径。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

x

-

number

-

-

0

-

指定矩形的左上角x坐标值。

-

y

-

number

-

-

0

-

指定矩形的左上角y坐标值。

-

width

-

number

-

-

0

-

指定矩形的宽度。

-

height

-

number

-

-

0

-

指定矩形的高度。

-
- - -- 示例 - - ``` - @Entry - @Component - struct Rect { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.rect(20, 20, 100, 100) // Create a 100*100 rectangle at (20, 20) - this.context.stroke() - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238601053.png) - - -### fill - -fill\(\): void - -对封闭路径进行填充。 - -- 示例 - - ``` - @Entry - @Component - struct Fill { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.rect(20, 20, 100, 100) // Create a 100*100 rectangle at (20, 20) - this.context.fill() - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193321138.png) - - -### clip - -clip\(\): void - -设置当前路径为剪切路径。 - -- 示例 - - ``` - @Entry - @Component - struct Clip { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.rect(0, 0, 200, 200) - this.context.stroke() - this.context.clip() - this.context.fillStyle = "rgb(255,0,0)" - this.context.fillRect(0, 0, 150, 150) - }) - Button('back') - .onClick(() => { - router.back() - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238401031.png) - - -### rotate - -rotate\(rotate: number\): void - -针对当前坐标轴进行顺时针旋转。 - -- 参数 - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

rotate

-

number

-

-

0

-

设置顺时针旋转的弧度值,可以通过Math.PI / 180将角度转换为弧度值。

-
- - -- 示例 - - ``` - @Entry - @Component - struct Rotate { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.rotate(45 * Math.PI / 180) // Rotate the rectangle 45 degrees - this.context.fillRect(70, 20, 50, 50) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238281069.png) - - -### scale - -scale\(x: number, y: number\): void - -设置canvas画布的缩放变换属性,后续的绘制操作将按照缩放比例进行缩放。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

x

-

number

-

-

0

-

设置水平方向的缩放值。

-

y

-

number

-

-

0

-

设置垂直方向的缩放值。

-
- - -- 示例 - - ``` - @Entry - @Component - struct Scale { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.strokeRect(10, 10, 25, 25) - this.context.scale(2, 2) // Scale to 200% - this.context.strokeRect(10, 10, 25, 25) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193641086.png) - - -### transform - -transform\(scaleX: number, skewX: number, skewY: number, scaleY: number, translateX: number, translateY: number\): void - -transform方法对应一个变换矩阵,想对一个图形进行变化的时候,只要设置此变换矩阵相应的参数,对图形的各个定点的坐标分别乘以这个矩阵,就能得到新的定点的坐标。矩阵变换效果可叠加。 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->变换后的坐标计算方式(x和y为变换前坐标,x'和y'为变换后坐标): ->- x' = scaleX \* x + skewY \* y + translateX ->- y' = skewX \* x + scaleY \* y + translateY - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

scaleX

-

number

-

-

0

-

指定水平缩放值。

-

skewX

-

number

-

-

0

-

指定水平倾斜值。

-

skewY

-

number

-

-

0

-

指定垂直倾斜值。

-

scaleY

-

number

-

-

0

-

指定垂直缩放值。

-

translateX

-

number

-

-

0

-

指定水平移动值。

-

translateY

-

number

-

-

0

-

指定垂直移动值。

-
- -- 示例 - - ``` - @Entry - @Component - struct Transform { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.fillStyle = 'rgb(0,0,0)' - this.context.fillRect(0, 0, 100, 100) - this.context.transform(1, 0.5, -0.5, 1, 10, 10) - this.context.fillStyle = 'rgb(255,0,0)' - this.context.fillRect(0, 0, 100, 100) - this.context.transform(1, 0.5, -0.5, 1, 10, 10) - this.context.fillStyle = 'rgb(0,0,255)' - this.context.fillRect(0, 0, 100, 100) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193801072.png) - - -### setTransform - -setTransform\(scaleX: number, skewX: number, skewY: number, scale: number, translateX: number, translateY: number\): void - -setTransfrom方法使用的参数和transform\(\)方法相同,但setTransform\(\)方法会重置现有的变换矩阵并创建新的变换矩阵。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

scaleX

-

number

-

-

0

-

指定水平缩放值。

-

skewX

-

number

-

-

0

-

指定水平倾斜值。

-

skewY

-

number

-

-

0

-

指定垂直倾斜值。

-

scaleY

-

number

-

-

0

-

指定垂直缩放值。

-

translateX

-

number

-

-

0

-

指定水平移动值。

-

translateY

-

number

-

-

0

-

指定垂直移动值。

-
- -- 示例 - - ``` - @Entry - @Component - struct SetTransform { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.fillStyle = 'rgb(255,0,0)' - this.context.fillRect(0, 0, 100, 100) - this.context.setTransform(1,0.5, -0.5, 1, 10, 10) - this.context.fillStyle = 'rgb(0,0,255)' - this.context.fillRect(0, 0, 100, 100) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238521021.png) - - -### translate - -translate\(x: number, y: number\): void - -移动当前坐标系的原点。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

x

-

number

-

-

0

-

设置水平平移量。

-

y

-

number

-

-

0

-

设置竖直平移量。

-
- -- 示例 - - ``` - @Entry - @Component - struct Translate { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.fillRect(10, 10, 50, 50) - this.context.translate(70, 70) - this.context.fillRect(10, 10, 50, 50) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193481098.png) - - -### drawImage - -drawImage\(image: ImageBitmap, dx: number, dy: number\): void - -drawImage\(image: ImageBitmap, dx: number, dy: number, dWidth: number, dHeight: number\): void - -drawImage\(image: ImageBitmap, sx: number, sy: number, sWidth: number, sHeight: number, dx: number, dy: number, dWidth: number, dHeight: number\):void - -进行图像绘制。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

image

-

ImageBitmap

-

-

null

-

图片资源,请参考ImageBitmap

-

sx

-

number

-

-

0

-

裁切源图像时距离源图像左上角的x坐标值。

-

sy

-

number

-

-

0

-

裁切源图像时距离源图像左上角的y坐标值。

-

sWidth

-

number

-

-

0

-

裁切源图像时需要裁切的宽度。

-

sHeight

-

number

-

-

0

-

裁切源图像时需要裁切的高度。

-

dx

-

number

-

-

0

-

绘制区域左上角在x轴的位置。

-

dy

-

number

-

-

0

-

绘制区域左上角在y 轴的位置。

-

dWidth

-

number

-

-

0

-

绘制区域的宽度。

-

dHeight

-

number

-

-

0

-

绘制区域的高度。

-
- - -- 示例 - - ``` - @Entry - @Component - struct ImageExample { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true); - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings); - private img:ImageBitmap = new ImageBitmap("common/images/example.jpg"); - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.drawImage( this.img,0,0,500,500,0,0,400,200); - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915154.png) - - -### createImageData - -createImageData\(width: number, height: number\): Object - -创建新的ImageData 对象,请参考[ImageData](/pages/010c0202010508)。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认

-

描述

-

width

-

number

-

-

0

-

ImageData的宽度。

-

height

-

number

-

-

0

-

ImageData的高度。

-
- - -### createImageData - -createImageData\(imageData: Object\): Object - -创建新的ImageData 对象,请参考[ImageData](/pages/010c0202010508)。 - -- 参数 - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认

-

描述

-

imagedata

-

Object

-

-

null

-

复制现有的ImageData对象。

-
- - -### getImageData - -getImageData\(sx: number, sy: number, sw: number, sh: number\): Object - -以当前canvas指定区域内的像素创建[ImageData](/pages/010c0202010508)对象。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

sx

-

number

-

-

0

-

需要输出的区域的左上角x坐标。

-

sy

-

number

-

-

0

-

需要输出的区域的左上角y坐标。

-

sw

-

number

-

-

0

-

需要输出的区域的宽度。

-

sh

-

number

-

-

0

-

需要输出的区域的高度。

-
- - -### putImageData - -putImageData\(imageData: Object, dx: number, dy: number, dirtyX?: number, dirtyY?: number, dirtyWidth?: number, dirtyHeight?: number\): void - -使用[ImageData](/pages/010c0202010508)数据填充新的矩形区域。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

imagedata

-

Object

-

-

null

-

包含像素值的ImageData对象。

-

dx

-

number

-

-

0

-

填充区域在x轴方向的偏移量。

-

dy

-

number

-

-

0

-

填充区域在y轴方向的偏移量。

-

dirtyX

-

number

-

-

0

-

源图像数据矩形裁切范围左上角距离源图像左上角的x轴偏移量。

-

dirtyY

-

number

-

-

0

-

源图像数据矩形裁切范围左上角距离源图像左上角的y轴偏移量。

-

dirtyWidth

-

number

-

-

imagedata的宽度

-

源图像数据矩形裁切范围的宽度。

-

dirtyHeight

-

number

-

-

imagedata的高度

-

源图像数据矩形裁切范围的高度。

-
- -- 示例 - - ``` - @Entry - @Component - struct PutImageData { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - var imageData = this.context.createImageData(100, 100) - for (var i = 0; i < imageData.data.length; i += 4) { - imageData.data[i + 0] = 255 - imageData.data[i + 1] = 0 - imageData.data[i + 2] = 255 - imageData.data[i + 3] = 255 - } - this.context.putImageData(imageData, 10, 10) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075134.png) - - -### restore - -restore\(\): void - -对保存的绘图上下文进行恢复。 - -- 示例 - - ``` - @Entry - @Component - struct Restore { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.controller.restore() - }) - } - .width('100%') - .height('100%') - } - } - ``` - - -### save - -save\(\): void - -对当前的绘图上下文进行保存。 - -- 示例 - - ``` - @Entry - @Component - struct Restore { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.save() - }) - } - .width('100%') - .height('100%') - } - } - ``` - - -### createLinearGradient - -createLinearGradient\(x0: number, y0: number, x1: number, y1: number\): void - -创建一个线性渐变色。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

x0

-

number

-

-

0

-

起点的x轴坐标。

-

y0

-

number

-

-

0

-

起点的y轴坐标。

-

x1

-

number

-

-

0

-

终点的x轴坐标。

-

y1

-

number

-

-

0

-

终点的y轴坐标。

-
- -- 示例 - - ``` - @Entry - @Component - struct CreateLinearGradient { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private gra:CanvasGradient = new CanvasGradient() - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - var grad = this.context.createLinearGradient(50,0, 300,100) - this.gra.addColorStop(0.0, 'red') - this.gra.addColorStop(0.5, 'white') - this.gra.addColorStop(1.0, 'green') - this.context.fillStyle = grad - this.context.fillRect(0, 0, 500, 500) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555149.png) - - -### createRadialGradient - -createRadialGradient\(x0: number, y0: number, r0: number, x1: number, y1: number, r1: number\): void - -创建一个径向渐变色。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

x0

-

number

-

-

0

-

起始圆的x轴坐标。

-

y0

-

number

-

-

0

-

起始圆的y轴坐标。

-

r0

-

number

-

-

0

-

起始圆的半径。必须是非负且有限的。

-

x1

-

number

-

-

0

-

终点圆的x轴坐标。

-

y1

-

number

-

-

0

-

终点圆的y轴坐标。

-

r1

-

number

-

-

0

-

终点圆的半径。必须为非负且有限的。

-
- -- 示例 - - ``` - @Entry - @Component - struct CreateRadialGradient { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private gra:CanvasGradient = new CanvasGradient() - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - var grad = this.context.createRadialGradient(200,200,50, 200,200,200) - this.gra.addColorStop(0.0, 'red') - this.gra.addColorStop(0.5, 'white') - this.gra.addColorStop(1.0, 'green') - this.context.fillStyle = grad - this.context.fillRect(0, 0, 500, 500) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755188.png) - - -## CanvasPattern - -一个Object对象, 通过[createPattern](#section1643216163371)方法创建。 - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/03.OffscreenCanvasRenderingConxt2D\345\257\271\350\261\241.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/03.OffscreenCanvasRenderingConxt2D\345\257\271\350\261\241.md" deleted file mode 100644 index 633f5e90859944965d675d3bc645e9393822ef30..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/03.OffscreenCanvasRenderingConxt2D\345\257\271\350\261\241.md" +++ /dev/null @@ -1,3885 +0,0 @@ ---- -title: OffscreenCanvasRenderingConxt2D对象 -permalink: /pages/010c0202010503 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:35 ---- -# OffscreenCanvasRenderingConxt2D对象 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从 API Version 8 开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -使用OffscreenCanvasRenderingContext2D在Canvas上进行离屏绘制,绘制对象可以是矩形、文本、图片等。离屏绘制是指将需要绘制的内容先绘制在缓存区,然后将其转换成图片,一次性绘制绘制到canvas上,加快了绘制速度。 - -## 接口 - -OffscreenCanvasRenderingContext2D\(width: number, height: number, setting: RenderingContextSettings\) - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

width

-

number

-

-

-

-

离屏画布的宽度

-

height

-

number

-

-

-

-

离屏画布的高度

-

setting

-

RenderingContextSettings

-

-

-

-

RenderingContextSettings接口描述。

-
- - -## 属性 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

类型

-

默认值

-

描述

-

fillStyle

-

<color> | CanvasGradient | CanvasPattern

-

-

-

指定绘制的填充色。

-
  • 类型为<color>时,表示设置填充区域的颜色。
  • 类型为CanvasGradient时,表示渐变对象,使用 createLinearGradient方法创建。
  • 类型为CanvasPattern时,使用createPattern方法创建。
-

lineWidth

-

number

-

-

-

设置绘制线条的宽度。

-

strokeStyle

-

<color> | CanvasGradient | CanvasPattern

-

-

-

设置描边的颜色。

-
  • 类型为<color>时,表示设置描边使用的颜色。
  • 类型为CanvasGradient时,表示渐变对象,使用createLinearGradient方法创建。
  • 类型为CanvasPattern时,使用createPattern方法创建。
-

lineCap

-

string

-

'butt'

-

指定线端点的样式,可选值为:

-
  • 'butt':线端点以方形结束。
  • 'round':线端点以圆形结束。
  • 'square':线端点以方形结束,该样式下会增加一个长度和线段厚度相同,宽度是线段厚度一半的矩形。
-

lineJoin

-

string

-

'miter'

-

指定线段间相交的交点样式,可选值为:

-
  • 'round':在线段相连处绘制一个扇形,扇形的圆角半径是线段的宽度。
  • 'bevel':在线段相连处使用三角形为底填充, 每个部分矩形拐角独立。
  • 'miter':在相连部分的外边缘处进行延伸,使其相交于一点,形成一个菱形区域,该属性可以通过设置miterLimit属性展现效果。
-

miterLimit

-

number

-

10

-

设置斜接面限制值,该值指定了线条相交处内角和外角的距离。

-

font

-

string

-

'normal normal 14px sans-serif'

-

设置文本绘制中的字体样式。

-

语法:ctx.font='font-size font-family'

-
  • font-size(可选),指定字号和行高,单位只支持px。
  • font-family(可选),指定字体系列。
-

语法:ctx.font='font-style font-weight font-size font-family'

-
  • font-style(可选),用于指定字体样式,支持如下几种样式:'normal', 'italic'。
  • font-weight(可选),用于指定字体的粗细,支持如下几种类型:'normal', 'bold', 'bolder', 'lighter', 100, 200, 300, 400, 500, 600, 700, 800, 900。
  • font-size(可选),指定字号和行高,单位只支持px。
  • font-family(可选),指定字体系列,支持如下几种类型:'sans-serif', 'serif', 'monospace'。
-

textAlign

-

string

-

'left'

-

设置文本绘制中的文本对齐方式,可选值为:

-
  • 'left':文本左对齐。
  • 'right':文本右对齐。
  • 'center':文本居中对齐。
  • 'start':文本对齐界线开始的地方。
  • 'end':文本对齐界线结束的地方。
-
说明:

ltr布局模式下start和left一致,rtl布局模式下start和right一致·。

-
-

textBaseline

-

string

-

'alphabetic'

-

设置文本绘制中的水平对齐方式,可选值为:

-
  • 'alphabetic':文本基线是标准的字母基线。
  • 'top':文本基线在文本块的顶部。
  • 'hanging':文本基线是悬挂基线。
  • 'middle':文本基线在文本块的中间。
  • 'ideographic':文字基线是表意字基线;如果字符本身超出了alphabetic基线,那么ideograhpic基线位置在字符本身的底部。
  • 'bottom':文本基线在文本块的底部。 与ideographic基线的区别在于ideographic 基线不需要考虑下行字母。
-

globalAlpha

-

number

-

-

-

设置透明度,0.0为完全透明,1.0为完全不透明。

-

lineDashOffset

-

number

-

0.0

-

设置画布的虚线偏移量,精度为float。

-

globalCompositeOperation

-

string

-

'source-over'

-

设置合成操作的方式。类型字段可选值有'source-over','source-atop','source-in','source-out','destination-over','destination-atop','destination-in','destination-out','lighter','copy','xor'。

-

shadowBlur

-

number

-

0.0

-

设置绘制阴影时的模糊级别,值越大越模糊,精度为float。

-

shadowColor

-

<color>

-

-

-

设置绘制阴影时的阴影颜色。

-

shadowOffsetX

-

number

-

-

-

设置绘制阴影时和原有对象的水平偏移值。

-

shadowOffsetY

-

number

-

-

-

设置绘制阴影时和原有对象的垂直偏移值。

-

imageSmoothingEnabled

-

boolean

-

true

-

用于设置绘制图片时是否进行图像平滑度调整,true为启用,false为不启用。

-

imageSmoothingQuality

-

string

-

'low'

-

用于设置图像平滑度,支持如下三种类型:'low', 'medium', 'high'。

-
- ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->类型格式为 'rgb\(255, 255, 255\)','rgba\(255, 255, 255, 1.0\)','\#FFFFFF'。 - -### fillStyle - -``` -@Entry -@Component -struct FillStyleExample { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.fillStyle = '#0000ff' - this.offContext.fillRect(20, 160, 150, 100) - var image = this.offContext.transferToImageBitmap(); - this.context.transferFromImageBitmap(image); - }) - } - .width('100%') - .height('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555173.png) - -### lineWidth - -``` -@Entry -@Component -struct LineWidthExample { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.lineWidth = 5 - this.offContext.strokeRect(25, 25, 85, 105) - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755194.png) - -### strokeStyle - -``` -@Entry -@Component -struct StrokeStyleExample { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.lineWidth = 10 - this.offContext.strokeStyle = '#0000ff' - this.offContext.strokeRect(25, 25, 155, 105) - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355135.png) - -### lineCap - -``` -@Entry -@Component -struct LineCapExample { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.lineWidth = 8 - this.offContext.beginPath() - this.offContext.lineCap = 'round' - this.offContext.moveTo(30, 50) - this.offContext.lineTo(220, 50) - this.offContext.stroke() - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595232.png) - -### lineJoin - -``` -@Entry -@Component -struct LineJoinExample { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.beginPath() - this.offContext.lineWidth = 8 - this.offContext.lineJoin = 'miter' - this.offContext.moveTo(30, 30) - this.offContext.lineTo(120, 60) - this.offContext.lineTo(30, 110) - this.offContext.stroke() - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715141.png) - -### miterLimit - -``` -@Entry -@Component -struct MiterLimit { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.lineWidth = 8 - this.offContext.lineJoin = 'miter' - this.offContext.miterLimit = 3 - this.offContext.moveTo(30, 30) - this.offContext.lineTo(60, 35) - this.offContext.lineTo(30, 37) - this.offContext.stroke() - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075178.png) - -### font - -``` -@Entry -@Component -struct Font { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.font = '30px sans-serif' - this.offContext.fillText("Hello World", 20, 60) - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075164.png) - -### textAlign - -``` -@Entry -@Component -struct TextAlign { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.strokeStyle = '#0000ff' - this.offContext.moveTo(140, 10) - this.offContext.lineTo(140, 160) - this.offContext.stroke() - - this.offContext.font = '18px sans-serif' - - this.offContext.textAlign = 'start' - this.offContext.fillText('textAlign=start', 140, 60) - this.offContext.textAlign = 'end' - this.offContext.fillText('textAlign=end', 140, 80) - this.offContext.textAlign = 'left' - this.offContext.fillText('textAlign=left', 140, 100) - this.offContext.textAlign = 'center' - this.offContext.fillText('textAlign=center',140, 120) - this.offContext.textAlign = 'right' - this.offContext.fillText('textAlign=right',140, 140) - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595234.png) - -### textBaseline - -``` -@Entry -@Component -struct TextBaseline { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.strokeStyle = '#0000ff' - this.offContext.moveTo(0, 120) - this.offContext.lineTo(400, 120) - this.offContext.stroke() - - this.offContext.font = '20px sans-serif' - - this.offContext.textBaseline = 'top' - this.offContext.fillText('Top', 10, 120) - this.offContext.textBaseline = 'bottom' - this.offContext.fillText('Bottom', 55, 120) - this.offContext.textBaseline = 'middle' - this.offContext.fillText('Middle', 125, 120) - this.offContext.textBaseline = 'alphabetic' - this.offContext.fillText('Alphabetic', 195, 120) - this.offContext.textBaseline = 'hanging' - this.offContext.fillText('Hanging', 295, 120) - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075180.png) - -### globalAlpha - -``` -@Entry -@Component -struct GlobalAlpha { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.fillStyle = 'rgb(255,0,0)' - this.offContext.fillRect(0, 0, 50, 50) - this.offContext.globalAlpha = 0.4 - this.offContext.fillStyle = 'rgb(0,0,255)' - this.offContext.fillRect(50, 50, 50, 50) - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715165.png) - -### lineDashOffset - -``` -@Entry -@Component -struct LineDashOffset { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.arc(100, 75, 50, 0, 6.28) - this.offContext.setLineDash([10,20]) - this.offContext.stroke(); - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555181.png) - -### globalCompositeOperation - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

描述

-

source-over

-

在现有绘制内容上显示新绘制内容,属于默认值。

-

source-atop

-

在现有绘制内容顶部显示新绘制内容。

-

source-in

-

在现有绘制内容中显示新绘制内容。

-

source-out

-

在现有绘制内容之外显示新绘制内容。

-

destination-over

-

在新绘制内容上方显示现有绘制内容。

-

destination-atop

-

在新绘制内容顶部显示现有绘制内容。

-

destination-in

-

在新绘制内容中显示现有绘制内容。

-

destination-out

-

在新绘制内容外显示现有绘制内容。

-

lighter

-

显示新绘制内容和现有绘制内容。

-

copy

-

显示新绘制内容而忽略现有绘制内容。

-

xor

-

使用异或操作对新绘制内容与现有绘制内容进行融合。

-
- -``` -@Entry -@Component -struct GlobalCompositeOperation { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.fillStyle = 'rgb(255,0,0)' - this.offContext.fillRect(20, 20, 50, 50) - this.offContext.globalCompositeOperation = 'source-over' - this.offContext.fillStyle = 'rgb(0,0,255)' - this.offContext.fillRect(50, 50, 50, 50) - this.offContext.fillStyle = 'rgb(255,0,0)' - this.offContext.fillRect(120, 20, 50, 50) - this.offContext.globalCompositeOperation = 'destination-over' - this.offContext.fillStyle = 'rgb(0,0,255)' - this.offContext.fillRect(150, 50, 50, 50) - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355137.png) - -### shadowBlur - -``` -@Entry -@Component -struct ShadowBlur { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.shadowBlur = 30 - this.offContext.shadowColor = 'rgb(0,0,0)' - this.offContext.fillStyle = 'rgb(255,0,0)' - this.offContext.fillRect(20, 20, 100, 80) - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755182.png) - -### shadowColor - -``` -@Entry -@Component -struct ShadowColor { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.shadowBlur = 30 - this.offContext.shadowColor = 'rgb(0,0,255)' - this.offContext.fillStyle = 'rgb(255,0,0)' - this.offContext.fillRect(30, 30, 100, 100) - var image = this.offContext.transferToImageBitmap -() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555155.png) - -### shadowOffsetX - -``` -@Entry -@Component -struct ShadowOffsetX { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.shadowBlur = 10 - this.offContext.shadowOffsetX = 20 - this.offContext.shadowColor = 'rgb(0,0,0)' - this.offContext.fillStyle = 'rgb(255,0,0)' - this.offContext.fillRect(20, 20, 100, 80) - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075168.png) - -### shadowOffsetY - -``` -@Entry -@Component -struct ShadowOffsetY { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.shadowBlur = 10 - this.offContext.shadowOffsetY = 20 - this.offContext.shadowColor = 'rgb(0,0,0)' - this.offContext.fillStyle = 'rgb(255,0,0)' - this.offContext.fillRect(30, 30, 100, 100) - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475139.png) - -### imageSmoothingEnabled - -``` -@Entry -@Component -struct ImageSmoothingEnabled { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private img:ImageBitmap = new ImageBitmap("common/images/icon.jpg") - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.imageSmoothingEnabled = false - this.offContext.drawImage( this.img,0,0,400,200) - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355121.png) - -## 方法 - -### fillRect - -fillRect\(x: number, y: number, w: number, h: number\): void - -填充一个矩形。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

说明

-

x

-

number

-

-

0

-

指定矩形左上角点的x坐标。

-

y

-

number

-

-

0

-

指定矩形左上角点的y坐标。

-

width

-

number

-

-

0

-

指定矩形的宽度。

-

height

-

number

-

-

0

-

指定矩形的高度。

-
- -- 示例 - - ``` - @Entry - @Component - struct FillRect { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.fillRect(0,30,100,100) - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475123.png) - - -### strokeRect - -strokeRect\(x: number, y: number, w: number, h: number\): void - -绘制具有边框的矩形,矩形内部不填充。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

说明

-

x

-

number

-

-

0

-

指定矩形的左上角x坐标。

-

y

-

number

-

-

0

-

指定矩形的左上角y坐标。

-

width

-

number

-

-

0

-

指定矩形的宽度。

-

height

-

number

-

-

0

-

指定矩形的高度。

-
- - -- 示例 - - ``` - @Entry - @Component - struct StrokeRect { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.strokeRect(30, 30, 200, 150) - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755180.png) - - -### clearRect - -clearRect\(x: number, y: number, w: number, h: number\): void - -删除指定区域内的绘制内容。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

x

-

number

-

-

0

-

指定矩形上的左上角x坐标。

-

y

-

number

-

-

0

-

指定矩形上的左上角y坐标。

-

width

-

number

-

-

0

-

指定矩形的宽度。

-

height

-

number

-

-

0

-

指定矩形的高度。

-
- - -- 示例 - - ``` - @Entry - @Component - struct ClearRect { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.fillStyle = 'rgb(0,0,255)' - this.offContext.fillRect(0,0,500,500) - this.offContext.clearRect(20,20,150,100) - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/11111-5.png) - - -### fillText - -fillText\(text: string, x: number, y: number\): void - -绘制填充类文本。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

说明

-

text

-

string

-

-

“”

-

需要绘制的文本内容。

-

x

-

number

-

-

0

-

需要绘制的文本的左下角x坐标。

-

y

-

number

-

-

0

-

需要绘制的文本的左下角y坐标。

-
- - -- 示例 - - ``` - @Entry - @Component - struct FillText { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.font = '30px sans-serif' - this.offContext.fillText("Hello World!", 20, 100) - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555165.png) - - -### strokeText - -strokeText\(text: string, x: number, y: number\): void - -绘制描边类文本。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

text

-

string

-

-

“”

-

需要绘制的文本内容。

-

x

-

number

-

-

0

-

需要绘制的文本的左下角x坐标。

-

y

-

number

-

-

0

-

需要绘制的文本的左下角y坐标。

-
- - -- 示例 - - ``` - @Entry - @Component - struct StrokeText { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.font = '55px sans-serif' - this.offContext.strokeText("Hello World!", 20, 60) - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715149.png) - - -### measureText - -measureText\(text: string\): TextMetrics - -该方法返回一个文本测算的对象,通过该对象可以获取指定文本的宽度值。 - -- 参数 - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

说明

-

text

-

string

-

-

""

-

需要进行测量的文本。

-
- -- 返回值 - - - - - - - - - -

类型

-

说明

-

TextMetrics

-

文本的尺寸信息

-
- -- TextMetrics类型描述 - - - - - - - - - - - -

属性

-

类型

-

描述

-

width

-

number

-

字符串的宽度。

-
- - -- 示例 - - ``` - @Entry - @Component - struct MeasureText { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.font = '50px sans-serif' - this.offContext.fillText("Hello World!", 20, 100) - this.offContext.fillText("width:" + this.context.measureText("Hello World!").width, 20, 200) - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075172.png) - - -### stroke - -stroke\(path?: Path2D\): void - -进行边框绘制操作。 - -- 参数 - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

path

-

Path2D

-

-

null

-

需要绘制的Path2D。

-
- - -- 示例 - - ``` - @Entry - @Component - struct Stroke { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenRenderingContext(600, 600, this.settings) - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.moveTo(25, 25) - this.offContext.lineTo(25, 105) - this.offContext.strokeStyle = 'rgb(0,0,255)' - this.offContext.stroke() - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595220.png) - - -### beginPath - -beginPath\(\): void - -创建一个新的绘制路径。 - -- 示例 - - ``` - @Entry - @Component - struct BeginPath { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.beginPath() - this.offContext.lineWidth = 6 - this.offContext.strokeStyle = '#0000ff' - this.offContext.moveTo(15, 80) - this.offContext.lineTo(280, 160) - this.offContext.stroke() - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555163.png) - - -### moveTo - -moveTo\(x: number, y: number\): void - -路径从当前点移动到指定点。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

说明

-

x

-

number

-

-

0

-

指定位置的x坐标。

-

y

-

number

-

-

0

-

指定位置的y坐标。

-
- - -- 示例 - - ``` - @Entry - @Component - struct MoveTo { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.beginPath() - this.offContext.moveTo(10, 10) - this.offContext.lineTo(280, 160) - this.offContext.stroke() - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595228.png) - - -### lineTo - -lineTo\(x: number, y: number\): void - -从当前点到指定点进行路径连接。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

x

-

number

-

-

0

-

指定位置的x坐标。

-

y

-

number

-

-

0

-

指定位置的y坐标。

-
- - -- 示例 - - ``` - @Entry - @Component - struct LineTo { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.beginPath() - this.offContext.moveTo(10, 10) - this.offContext.lineTo(280, 160) - this.offContext.stroke() - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715151.png) - - -### closePath - -closePath\(\): void - -结束当前路径形成一个封闭路径。 - -- 示例 - - ``` - @Entry - @Component - struct ClosePath { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.beginPath() - this.offContext.moveTo(30, 30) - this.offContext.lineTo(110, 30) - this.offContext.lineTo(70, 90) - this.offContext.closePath() - this.offContext.stroke() - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595224.png) - - -### createPattern - -createPattern\(image: ImageBitmap, repetition: string\): CanvasPattern - -通过指定图像和重复方式创建图片填充的模板。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

image

-

ImageBitmap

-

-

null

-

图源对象,具体参考 ImageBitmap对象。

-

repetition

-

string

-

-

“”

-

设置图像重复的方式,取值为:'repeat'、'repeat-x'、 'repeat-y'、'no-repeat'。

-
- -- 示例 - - ``` - @Entry - @Component - struct CreatePattern { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private img:ImageBitmap = new ImageBitmap("common/images/icon.jpg") - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - var pattern = this.offContext.createPattern(this.img, 'repeat') - this.offContext.fillStyle = pattern - this.offContext.fillRect(0, 0, 200, 200) - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475133.png) - - -### bezierCurveTo - -bezierCurveTo\(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number\): void - -创建三次贝赛尔曲线的路径。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

cp1x

-

number

-

-

0

-

第一个贝塞尔参数的x坐标值。

-

cp1y

-

number

-

-

0

-

第一个贝塞尔参数的y坐标值。

-

cp2x

-

number

-

-

0

-

第二个贝塞尔参数的x坐标值。

-

cp2y

-

number

-

-

0

-

第二个贝塞尔参数的y坐标值。

-

x

-

number

-

-

0

-

路径结束时的x坐标值。

-

y

-

number

-

-

0

-

路径结束时的y坐标值。

-
- - -- 示例 - - ``` - @Entry - @Component - struct BezierCurveTo { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.beginPath() - this.offContext.moveTo(10, 10) - this.offContext.bezierCurveTo(20, 100, 200, 100, 200, 20) - this.offContext.stroke() - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715153.png) - - -### quadraticCurveTo - -quadraticCurveTo\(cpx: number, cpy: number, x: number, y: number\): void - -创建二次贝赛尔曲线的路径。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

cpx

-

number

-

-

0

-

贝塞尔参数的x坐标值。

-

cpy

-

number

-

-

0

-

贝塞尔参数的y坐标值。

-

x

-

number

-

-

0

-

路径结束时的x坐标值。

-

y

-

number

-

-

0

-

路径结束时的y坐标值。

-
- - -- 示例 - - ``` - @Entry - @Component - struct QuadraticCurveTo { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.beginPath(); - this.offContext.moveTo(20, 20); - this.offContext.quadraticCurveTo(100, 100, 200, 20); - this.offContext.stroke(); - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915184.png) - - -### arc - -arc\(x: number, y: number, radius: number, startAngle: number, endAngle: number, anticlockwise?: boolean\): void - -绘制弧线路径。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

x

-

number

-

-

0

-

弧线圆心的x坐标值。

-

y

-

number

-

-

0

-

弧线圆心的y坐标值。

-

radius

-

number

-

-

0

-

弧线的圆半径。

-

startAngle

-

number

-

-

0

-

弧线的起始弧度。

-

endAngle

-

number

-

-

0

-

弧线的终止弧度。

-

anticlockwise

-

boolean

-

-

false

-

是否逆时针绘制圆弧。

-
- -- 示例 - - ``` - @Entry - @Component - struct Arc { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.beginPath() - this.offContext.arc(100, 75, 50, 0, 6.28) - this.offContext.stroke() - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595226.png) - - -### arcTo - -arcTo\(x1: number, y1: number, x2: number, y2: number, radius: number\): void - -依据圆弧经过的点和圆弧半径创建圆弧路径。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

x1

-

number

-

-

0

-

圆弧经过的第一个点的x坐标值。

-

y1

-

number

-

-

0

-

圆弧经过的第一个点的y坐标值。

-

x2

-

number

-

-

0

-

圆弧经过的第二个点的x坐标值。

-

y2

-

number

-

-

0

-

圆弧经过的第二个点的y坐标值。

-

radius

-

number

-

-

0

-

圆弧的圆半径值。

-
- - -- 示例 - - ``` - @Entry - @Component - struct ArcTo { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.moveTo(100, 20); - this.offContext.arcTo(150, 20, 150, 70, 50); - this.offContext.stroke(); - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555167.png) - - -### ellipse - -ellipse\(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, anticlockwise?: boolean\): void - -在规定的矩形区域绘制一个椭圆。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

说明

-

x

-

number

-

-

0

-

椭圆圆心的x轴坐标。

-

y

-

number

-

-

0

-

椭圆圆心的y轴坐标。

-

radiusX

-

number

-

-

0

-

椭圆x轴的半径长度。

-

radiusY

-

number

-

-

0

-

椭圆y轴的半径长度。

-

rotation

-

number

-

-

0

-

椭圆的旋转角度,单位为弧度。

-

startAngle

-

number

-

-

0

-

椭圆绘制的起始点角度,以弧度表示。

-

endAngle

-

number

-

-

0

-

椭圆绘制的结束点角度,以弧度表示。

-

anticlockwise

-

boolean

-

-

false

-

是否以逆时针方向绘制椭圆,0为顺时针,1为逆时针。(可选参数,默认为0)

-
- - -- 示例 - - ``` - @Entry - @Component - struct Ellipse { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.beginPath() - this.offContext.ellipse(200, 200, 50, 100, Math.PI * 0.25, Math.PI * 0.5, Math.PI, true) - this.offContext.stroke() - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355131.png) - - -### rect - -rect\(x: number, y: number, width: number, height: number\): void - -创建矩形路径。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

x

-

number

-

-

0

-

指定矩形的左上角x坐标值。

-

y

-

number

-

-

0

-

指定矩形的左上角y坐标值。

-

width

-

number

-

-

0

-

指定矩形的宽度。

-

height

-

number

-

-

0

-

指定矩形的高度。

-
- - -- 示例 - - ``` - @Entry - @Component - struct Rect { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.rect(20, 20, 100, 100) // Create a 100*100 rectangle at (20, 20) - this.offContext.stroke() - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715155.png) - - -### fill - -fill\(\): void - -对封闭路径进行填充。 - -- 示例 - - ``` - @Entry - @Component - struct Fill { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.rect(20, 20, 100, 100) // Create a 100*100 rectangle at (20, 20) - this.offContext.fill() - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075166.png) - - -### clip - -clip\(\): void - -设置当前路径为剪切路径。 - -- 示例 - - ``` - @Entry - @Component - struct Clip { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.rect(0, 0, 200, 200) - this.offContext.stroke() - this.offContext.clip() - this.offContext.fillStyle = "rgb(255,0,0)" - this.offContext.fillRect(0, 0, 150, 150) - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595238.png) - - -### rotate - -rotate\(rotate: number\): void - -针对当前坐标轴进行顺时针旋转。 - -- 参数 - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

rotate

-

number

-

-

0

-

设置顺时针旋转的弧度值,可以通过Math.PI / 180将角度转换为弧度值。

-
- - -- 示例 - - ``` - @Entry - @Component - struct Rotate { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.rotate(45 * Math.PI / 180) // Rotate the rectangle 45 degrees - this.offContext.fillRect(70, 20, 50, 50) - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237355133.png) - - -### scale - -scale\(x: number, y: number\): void - -设置canvas画布的缩放变换属性,后续的绘制操作将按照缩放比例进行缩放。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

x

-

number

-

-

0

-

设置水平方向的缩放值。

-

y

-

number

-

-

0

-

设置垂直方向的缩放值。

-
- - -- 示例 - - ``` - @Entry - @Component - struct Scale { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.strokeRect(10, 10, 25, 25) - this.offContext.scale(2, 2) // Scale to 200% - this.offContext.strokeRect(10, 10, 25, 25) - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755178.png) - - -### transform - -transform\(scaleX: number, skewX: number, skewY: number, scaleY: number, translateX: number, translateY: number\): void - -transform方法对应一个变换矩阵,想对一个图形进行变化的时候,只要设置此变换矩阵相应的参数,对图形的各个定点的坐标分别乘以这个矩阵,就能得到新的定点的坐标。矩阵变换效果可叠加。 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->变换后的坐标计算方式(x和y为变换前坐标,x'和y'为变换后坐标): ->- x' = scaleX \* x + skewY \* y + translateX ->- y' = skewX \* x + scaleY \* y + translateY - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

scaleX

-

number

-

-

0

-

指定水平缩放值。

-

skewX

-

number

-

-

0

-

指定水平倾斜值。

-

skewY

-

number

-

-

0

-

指定垂直倾斜值。

-

scaleY

-

number

-

-

0

-

指定垂直缩放值。

-

translateX

-

number

-

-

0

-

指定水平移动值。

-

translateY

-

number

-

-

0

-

指定垂直移动值。

-
- -- 示例 - - ``` - @Entry - @Component - struct Transform { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.fillStyle = 'rgb(0,0,0)' - this.offContext.fillRect(0, 0, 100, 100) - this.offContext.transform(1, 0.5, -0.5, 1, 10, 10) - this.offContext.fillStyle = 'rgb(255,0,0)' - this.offContext.fillRect(0, 0, 100, 100) - this.offContext.transform(1, 0.5, -0.5, 1, 10, 10) - this.offContext.fillStyle = 'rgb(0,0,255)' - this.offContext.fillRect(0, 0, 100, 100) - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595230.png) - - -### setTransform - -setTransform\(scaleX: number, skewX: number, skewY: number, scale: number, translateX: number, translateY: number\): void - -setTransfrom方法使用的参数和transform\(\)方法相同,但setTransform\(\)方法会重置现有的变换矩阵并创建新的变换矩阵。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

scaleX

-

number

-

-

0

-

指定水平缩放值。

-

skewX

-

number

-

-

0

-

指定水平倾斜值。

-

skewY

-

number

-

-

0

-

指定垂直倾斜值。

-

scaleY

-

number

-

-

0

-

指定垂直缩放值。

-

translateX

-

number

-

-

0

-

指定水平移动值。

-

translateY

-

number

-

-

0

-

指定垂直移动值。

-
- -- 示例 - - ``` - @Entry - @Component - struct SetTransform { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.fillStyle = 'rgb(255,0,0)' - this.offContext.fillRect(0, 0, 100, 100) - this.offContext.setTransform(1,0.5, -0.5, 1, 10, 10) - this.offContext.fillStyle = 'rgb(0,0,255)' - this.offContext.fillRect(0, 0, 100, 100) - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237715159.png) - - -### translate - -translate\(x: number, y: number\): void - -移动当前坐标系的原点。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

x

-

number

-

-

0

-

设置水平平移量。

-

y

-

number

-

-

0

-

设置竖直平移量。

-
- -- 示例 - - ``` - @Entry - @Component - struct Translate { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.fillRect(10, 10, 50, 50) - this.offContext.translate(70, 70) - this.offContext.fillRect(10, 10, 50, 50) - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475137.png) - - -### drawImage - -drawImage\(image: ImageBitmap, dx: number, dy: number\): void - -drawImage\(image: ImageBitmap, dx: number, dy: number, dWidth: number, dHeight: number\): void - -drawImage\(image: ImageBitmap, sx: number, sy: number, sWidth: number, sHeight: number, dx: number, dy: number, dWidth: number, dHeight: number\):void - -进行图像绘制。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

image

-

ImageBitmap

-

-

null

-

图片资源,请参考ImageBitmap

-

sx

-

number

-

-

0

-

裁切源图像时距离源图像左上角的x坐标值。

-

sy

-

number

-

-

0

-

裁切源图像时距离源图像左上角的y坐标值。

-

sWidth

-

number

-

-

0

-

裁切源图像时需要裁切的宽度。

-

sHeight

-

number

-

-

0

-

裁切源图像时需要裁切的高度。

-

dx

-

number

-

-

0

-

绘制区域左上角在x轴的位置。

-

dy

-

number

-

-

0

-

绘制区域左上角在y 轴的位置。

-

dWidth

-

number

-

-

0

-

绘制区域的宽度。

-

dHeight

-

number

-

-

0

-

绘制区域的高度。

-
- - -- 示例 - - ``` - @Entry - @Component - struct Index { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private img:ImageBitmap = new ImageBitmap("common/images/icon.jpg") - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() => { - this.offContext.drawImage( this.img,0,0,400,200) - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915180.png) - - -### createImageData - -createImageData\(width: number, height: number\): Object - -根据宽高创建ImageData对象,请参考[ImageData](/pages/010c0202010508)。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认

-

描述

-

width

-

number

-

-

0

-

ImageData的宽度。

-

height

-

number

-

-

0

-

ImageData的高度。

-
- - -### createImageData - -createImageData\(imageData: ImageData\): Object - -根据已创建的ImageData对象创建新的ImageData对象,请参考[ImageData](/pages/010c0202010508)。 - -- 参数 - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认

-

描述

-

imagedata

-

ImageData

-

-

null

-

被复制的ImageData对象。

-
- - -### getImageData - -getImageData\(sx: number, sy: number, sw: number, sh: number\): Object - -以当前canvas指定区域内的像素创建[ImageData](/pages/010c0202010508)对象。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

sx

-

number

-

-

0

-

需要输出的区域的左上角x坐标。

-

sy

-

number

-

-

0

-

需要输出的区域的左上角y坐标。

-

sw

-

number

-

-

0

-

需要输出的区域的宽度。

-

sh

-

number

-

-

0

-

需要输出的区域的高度。

-
- - -### putImageData - -putImageData\(imageData: Object, dx: number, dy: number, dirtyX?: number, dirtyY?: number, dirtyWidth?: number, dirtyHeight?: number\): void - -使用[ImageData](/pages/010c0202010508)数据填充新的矩形区域。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

imagedata

-

Object

-

-

null

-

包含像素值的ImageData对象。

-

dx

-

number

-

-

0

-

填充区域在x轴方向的偏移量。

-

dy

-

number

-

-

0

-

填充区域在y轴方向的偏移量。

-

dirtyX

-

number

-

-

0

-

源图像数据矩形裁切范围左上角距离源图像左上角的x轴偏移量。

-

dirtyY

-

number

-

-

0

-

源图像数据矩形裁切范围左上角距离源图像左上角的y轴偏移量。

-

dirtyWidth

-

number

-

-

imagedata的宽度

-

源图像数据矩形裁切范围的宽度。

-

dirtyHeight

-

number

-

-

imagedata的高度

-

源图像数据矩形裁切范围的高度。

-
- -- 示例 - - ``` - @Entry - @Component - struct PutImageData { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - var imageData = this.offContext.createImageData(100, 100) - for (var i = 0; i < imageData.data.length; i += 4) { - imageData.data[i + 0] = 255 - imageData.data[i + 1] = 0 - imageData.data[i + 2] = 255 - imageData.data[i + 3] = 255 - } - this.offContext.putImageData(imageData, 10, 10) - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075170.png) - - -### restore - -restore\(\): void - -对保存的绘图上下文进行恢复。 - -- 示例 - - ``` - @Entry - @Component - struct Restore { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.restore() - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - -### save - -save\(\): void - -对当前的绘图上下文进行保存。 - -- 示例 - - ``` - @Entry - @Component - struct Restore { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.offContext.save() - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - -### createLinearGradient - -createLinearGradient\(x0: number, y0: number, x1: number, y1: number\): void - -创建一个线性渐变色。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

x0

-

number

-

-

0

-

起点的x轴坐标。

-

y0

-

number

-

-

0

-

起点的y轴坐标。

-

x1

-

number

-

-

0

-

终点的x轴坐标。

-

y1

-

number

-

-

0

-

终点的y轴坐标。

-
- -- 示例 - - ``` - @Entry - @Component - struct CreateLinearGradient { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private gra:CanvasGradient = new CanvasGradient() - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - var grad = this.offContext.createLinearGradient(50,0, 300,100) - this.gra.addColorStop(0.0, 'red') - this.gra.addColorStop(0.5, 'white') - this.gra.addColorStop(1.0, 'green') - this.offContext.fillStyle = grad - this.offContext.fillRect(0, 0, 500, 500) - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915162.png) - - -### createRadialGradient - -createRadialGradient\(x0: number, y0: number, r0: number, x1: number, y1: number, r1: number\): void - -创建一个径向渐变色。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

x0

-

number

-

-

0

-

起始圆的x轴坐标。

-

y0

-

number

-

-

0

-

起始圆的y轴坐标。

-

r0

-

number

-

-

0

-

起始圆的半径。必须是非负且有限的。

-

x1

-

number

-

-

0

-

终点圆的x轴坐标。

-

y1

-

number

-

-

0

-

终点圆的y轴坐标。

-

r1

-

number

-

-

0

-

终点圆的半径。必须为非负且有限的。

-
- -- 示例 - - ``` - @Entry - @Component - struct CreateRadialGradient { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private gra:CanvasGradient = new CanvasGradient() - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - var grad = this.offContext.createRadialGradient(200,200,50, 200,200,200) - this.gra.addColorStop(0.0, 'red') - this.gra.addColorStop(0.5, 'white') - this.gra.addColorStop(1.0, 'green') - this.offContext.fillStyle = grad - this.offContext.fillRect(0, 0, 500, 500) - var image = this.offContext.transferToImageBitmap() - this.context.transferFromImageBitmap(image) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555179.png) - - -## CanvasPattern - -一个Object对象, 通过[createPattern](#section660873113512)方法创建。 - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/04.Lottie.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/04.Lottie.md" deleted file mode 100644 index 7ad93990db2851f66b19fdc53ee034e1026e7e77..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/04.Lottie.md" +++ /dev/null @@ -1,1331 +0,0 @@ ---- -title: Lottie -permalink: /pages/010c0202010504 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:35 ---- -# Lottie - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从 API Version 8 开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -Lottie为三方开源库,依赖Canvas与RenderingContext。 - -## 权限列表 - -无 - -## 导入模块 - -``` -import lottie from 'lottie-web' -``` - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->'lottie-web' 名字以实际生态发布后的命名为准。 - -## lottie.loadAnimation - -loadAnimation\( - -path: string, container: object, render: string, loop: boolean, autoplay: boolean, name: string \): AnimationItem - -加载动画,须提前声明Animator\('\_\_lottie\_ets'\)对象,并在Canvas完成布局后调用。可配合Canvas组件生命周期接口使用,比如onAppear\(\)与onPageShow\(\)。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

描述

-

path

-

string

-

-

hap包内动画资源文件路径,仅支持json格式。示例:path: "common/lottie/data.json"

-

container

-

object

-

-

canvas绘图上下文,声明范式需提前声明CanvasRenderingContext2D。

-

render

-

string

-

-

渲染类型,仅支持“canvas”。

-

loop

-

boolean | number

-

-

动画播放结束后,是否循环播放,默认值true。值类型为number,且大于等于1时为设置的重复播放的次数。

-

autoplay

-

boolean

-

-

是否自动播放动画,默认值true。

-

name

-

string

-

-

开发者自定义的动画名称,后续支持通过该名称引用控制动画,默认为空。

-

initialSegment

-

[number, number]

-

-

指定动画播放的起始帧号,指定动画播放的结束帧号。

-
- - -## lottie.destroy - -destroy\(name: string\): void - -销毁动画,页面退出时,必须调用。可配合Canvas组件生命周期接口使用,比如onDisappear\(\)与onPageHide\(\)。 - -- 参数 - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

描述

-

name

-

string

-

-

被指定的动画名,同loadAnimation接口参数name, 缺省时销毁所有动画。

-
- -- 示例 - - ``` - import lottie from 'lottie-web' - - @Entry - @Component - struct Index { - private controller: CanvasRenderingContext2D = new CanvasRenderingContext2D() - private animateName: string = "animate" - private animatePath: string = "common/lottie/data.json" - private animateItem: any = null - - private onPageHide(): void { - console.log('onPageHide') - lottie.destroy() - } - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.controller) - .width('30%') - .height('20%') - .backgroundColor('#0D9FFB') - .onAppear(() => { - console.log('canvas onAppear'); - this.animateItem = lottie.loadAnimation({ - container: this.controller, - renderer: 'canvas', - loop: true, - autoplay: true, - name: this.animateName, - path: this.animatePath, - }) - }) - - Animator('__lottie_ets') // declare Animator('__lottie_ets') when use lottie - Button('load animation') - .onClick(() => { - if (this.animateItem != null) { - this.animateItem.destroy() - this.animateItem = null - } - this.animateItem = lottie.loadAnimation({ - container: this.controller, - renderer: 'canvas', - loop: true, - autoplay: true, - name: this.animateName, - path: this.animatePath, - initialSegment: [10, 50], - }) - }) - - Button('destroy animation') - .onClick(() => { - lottie.destroy(this.animateName) - this.animateItem = null - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/lottie-ark-2-0-canvas-ui-animate.gif) - - -## lottie.play - -play\(name: string\): void - -播放指定动画。 - -- 参数 - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

描述

-

name

-

string

-

-

被指定的动画名, 同loadAnimation接口参数name,缺省时播放所有动画。

-
- -- 示例 - - ``` - lottie.play(this.animateName) - ``` - - -## lottie.pause - -pause\(name: string\): void - -暂停指定动画,下次调用lottie.play\(\)从当前帧开始。 - -- 参数 - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

描述

-

name

-

string

-

-

被指定的动画名,同loadAnimation接口入参name,缺省时暂停所有动画。

-
- -- 示例 - - ``` - lottie.pause(this.animateName) - ``` - - -## lottie.togglePause - -togglePause\(name: string\): void - -暂停或播放指定动画,等效于lottie.play\(\)与lottie.pause\(\)切换调用。 - -- 参数 - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

描述

-

name

-

string

-

-

被指定的动画名,同loadAnimation接口参数name,缺省时停止所有动画。

-
- -- 示例 - - ``` - lottie.togglePause(this.animateName) - ``` - - -## lottie.stop - -stop\(name: string\): void - -停止指定动画,下次调用lottie.play\(\)从第一帧开始。 - -- 参数 - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

描述

-

name

-

string

-

-

被指定的动画名,同loadAnimation接口参数name,缺省时停止所有动画。

-
- -- 示例 - - ``` - lottie.stop(this.animateName) - ``` - - -## lottie.setSpeed - -setSpeed\(speed: number, name: string\): void - -设置指定动画播放速度。 - -- 参数 - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

描述

-

speed

-

number

-

-

值为浮点类型, speed>0正向播放, speed<0反向播放, speed=0暂停播放, speed=1.0/-1.0正常速度播放。

-

name

-

string

-

-

被指定的动画,同loadAnimation接口参数name,缺省时停止所有动画。

-
- -- 示例 - - ``` - lottie.setSpeed(5, this.animateName) - ``` - - -## lottie.setDirection - -setDirection\(direction: AnimationDirection, name: string\): void - -设置指定动画播放顺序。 - -- 参数 - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

描述

-

direction

-

AnimationDirection

-

-

1为正向,-1为反向; 当设置为反向时,从当前播放进度开始回播直到首帧,loop值为true时可无限倒放;speed<0叠加时也是倒放。

-

AnimationDirection:1 | -1

-

name

-

string

-

-

被指定的动画名,同loadAnimation接口参数name,缺省时设置所有动画方向。

-
- - -- 示例 - - ``` - lottie.setDirection(-1, this.controlName) - ``` - - -## AnimationItem - -loadAnimation接口的返回对象,具有属性与接口。属性描述如下: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名称

-

参数类型

-

参数描述

-

name

-

string

-

动画名称。

-

isLoaded

-

boolean

-

动画是否已加载。

-

currentFrame

-

number

-

当前播放的帧号, 默认精度为>=0.0的浮点数, 调用setSubframe(false)后精度为去小数点后的正整数。

-

currentRawFrame

-

number

-

当前播放帧数, 精度为>=0.0的浮点数。

-

firstFrame

-

number

-

当前播放片段的第一帧帧号。

-

totalFrames

-

number

-

当前播放片段的总帧数。

-

frameRate

-

number

-

帧率 (frame/s)。

-

frameMult

-

number

-

帧率 (frame/ms)。

-

playSpeed

-

number

-

值为浮点类型, speed>0正向播放, speed<0反向播放, speed=0暂停播放, speed=1.0 | -1.0正常速度播放。

-

playDirection

-

number

-

播放方向, 1为正放, -1为倒放。

-

playCount

-

number

-

动画完成播放的次数。

-

isPaused

-

boolean

-

当前动画是否已暂停, 值为true动画已暂停。

-

autoplay

-

boolean

-

加载动画后是否自动播放, 若值为false需要再调用play()接口开始播放。

-

loop

-

boolean | number

-

类型为boolean时是否循环播放, 类型为number时播放次数。

-

renderer

-

any

-

动画渲染对象, 根据渲染类型而定。

-

animationID

-

string

-

动画ID。

-

timeCompleted

-

number

-

当前动画片段完成单次播放的帧数, 受AnimationSegment设置影响, 与totalFrames属性值相同。

-

segmentPos

-

number

-

当前动画片段序号, 值为>=0的正整数。

-

isSubframeEnabled

-

boolean

-

关联了currentFrame的精度是否为浮点数。

-

segments

-

AnimationSegment | AnimationSegment[]

-

当前动画的播放片段。

-
- -## AnimationItem.play - -play\(name?: string\): void - -播放动画。 - -- 参数 - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

描述

-

name

-

string

-

-

被指定的动画名,缺省默认为空。

-
- -- 示例 - - ``` - this.anim.play() - ``` - - -## AnimationItem.destroy - -destroy\(name?: string\): void - -销毁动画。 - -- 参数 - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

描述

-

name

-

string

-

-

被指定的动画名,缺省默认为空。

-
- -- 示例 - - ``` - this.anim.destroy() - ``` - - -## AnimationItem.pause - -pause\(name?: string\): void - -暂停动画,下次调用play接口从当前帧开始播放。 - -- 参数 - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

描述

-

name

-

string

-

-

被指定的动画名,缺省默认为空。

-
- -- 示例 - - ``` - this.anim.pause() - ``` - - -## AnimationItem.togglePause - -togglePause\(name?: string\): void - -暂停或播放动画,等效于play接口与pause接口之间轮换调用。 - -- 参数 - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

描述

-

name

-

string

-

-

被指定的动画名,缺省默认为空。

-
- -- 示例 - - ``` - this.anim.togglePause() - ``` - - -## AnimationItem.stop - -stop\(name?: string\): void - -停止动画,下次调用play接口从第一帧开始播放。 - -- 参数 - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

描述

-

name

-

string

-

-

被指定的动画名,缺省默认为空。

-
- -- 示例 - - ``` - this.anim.stop() - ``` - - -## AnimationItem.setSpeed - -setSpeed\(speed: number\): void - -设置动画播放速度。 - -- 参数 - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

描述

-

speed

-

number

-

-

值为浮点类型, speed>0正向播放, speed<0反向播放, speed=0暂停播放, speed=1.0 | -1.0正常速度播放。

-
- -- 示例 - - ``` - this.anim.setSpeed(5); - ``` - - -## AnimationItem.setDirection - -setDirection\(direction: AnimationDirection\): void - -设置动画播放顺序。 - -- 参数 - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

描述

-

direction

-

AnimationDirection

-

-

1为正向,-1为反向; 当设置为反向时,从当前播放进度开始回播直到首帧,loop值为true时可无限倒放;speed<0叠加时也是倒放。

-

AnimationDirection:1 | -1。

-
- - -- 示例 - - ``` - this.anim.setDirection(-1) - ``` - - -## AnimationItem.goToAndStop - -goToAndStop\(value: number, isFrame: boolean\): void - -设置动画停止在指定帧或时间进度。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

描述

-

value

-

number

-

-

帧号(值大于等于0)或时间进度(ms)。

-

isFrame

-

boolean

-

-

true: 按指定帧控制,false:按指定时间控制,缺省默认false。

-

name

-

string

-

-

被指定的动画名,缺省默认为空。

-
- - -- 示例 - - ``` - // 按帧号控制 - this.anim.goToAndStop(25, true) - // 按时间进度控制 - this.anim.goToAndStop(300, false, this.animateName) - ``` - - -## AnimationItem.goToAndPlay - -goToAndPlay\(value: number, isFrame: boolean\): void - -设置动画从指定帧或时间进度开始播放。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

描述

-

value

-

number

-

-

帧号(值大于等于0)或时间进度(ms)

-

isFrame

-

boolean

-

-

true:按指定帧控制, false:按指定时间控制,缺省默认false。

-

name

-

string

-

-

被指定的动画名,缺省默认为空。

-
- - -- 示例 - - ``` - // 按帧号控制 - this.anim.goToAndPlay(25, true) - // 按时间进度控制 - this.anim.goToAndPlay(300, false, this.animateName) - ``` - - -## AnimationItem.playSegments - -playSegments\(segments: AnimationSegment | AnimationSegment\[\], forceFlag: boolean\): void - -设置动画仅播放指定片段。 - -- 参数 - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

描述

-

segments

-

AnimationSegment = [number, number] | AnimationSegment[]

-

-

片段或片段列表;

-

如果片段列表全部播放完毕后,下轮循环播放仅播放最后一个片段

-

forceFlag

-

boolean

-

-

true:即时生效播放,false:延迟到下轮循环播放再生效

-
- - -- 示例 - - ``` - // 指定播放片段 - this.anim.playSegments([10, 20], false) - // 指定播放片段列表 - this.anim.playSegments([[0, 5], [20, 30]], true) - ``` - - -## AnimationItem.resetSegments - -resetSegments\(forceFlag: boolean\): void - -重置动画播放片段,播放全帧。 - -- 参数 - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

描述

-

forceFlag

-

boolean

-

-

true:即时生效播放,false:延迟到下轮循环播放再生效

-
- - -- 示例 - - ``` - this.anim.resetSegments(true) - ``` - - -## AnimationItem.resize - -resize\(\): void - -刷新动画布局。 - -- 示例 - - ``` - this.anim.resize() - ``` - - -## AnimationItem.setSubframe - -setSubframe\(useSubFrame: boolean\): void - -设置属性currentFrame的精度显示浮点数。 - -- 参数 - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

描述

-

useSubFrames

-

boolean

-

-

currentFrame属性默认显示浮点数,该接口参数将影响currentFrame属性的精度。

-

true:属性currentFrame显示浮点。

-

false:属性currentFrame去浮点数显示整数。

-
- - -- 示例 - - ``` - this.anim.setSubframe(false) - ``` - - -## AnimationItem.getDuration - -getDuration\(inFrames?: boolean\): void - -获取动画单次完整播放的时间\(与播放速度无关\)或帧数, 与Lottie.loadAnimation接口入参initialSegment有关。 - -- 参数 - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

描述

-

inFrames

-

boolean

-

-

true:获取帧数, false:获取时间(单位ms),缺省默认false。

-
- - -- 示例 - - ``` - this.anim.setSubframe(true) - ``` - - -## AnimationItem.addEventListener - -addEventListener\(name: AnimationEventName, callback: AnimationEventCallback\): \(\) =\> void - -添加侦听事件, 事件完成后会触发指定回调函数。返回可删除该侦听事件的函数对象。 - -- 参数 - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

描述

-

name

-

AnimationEventName

-

-

指定动画事件类型,Lottie内置动画事件类型AnimationEventName:

-

'enterFrame'、'loopComplete'、'complete'、'segmentStart'、'destroy'、'config_ready'、'data_ready'、'DOMLoaded'、'error'、'data_failed'、'loaded_images'

-

callback

-

AnimationEventCallback<T>

-

-

用户自定义回调函数

-
- - -- 示例 - - ``` - private callbackItem: any = function() { - console.log("grunt loopComplete") - } - let delFunction = this.animateItem.addEventListener('loopComplete', this.callbackItem) - - // 删除侦听 - delFunction() - ``` - - -## AnimationItem.removeEventListener - -removeEventListener\(name: AnimationEventName, callback?: AnimationEventCallback\): void - -删除侦听事件。 - -- 参数 - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

描述

-

name

-

AnimationEventName

-

-

指定动画事件类型,Lottie内置动画事件类型AnimationEventName:

-

'enterFrame'、'loopComplete'、'complete'、'segmentStart'、'destroy'、'config_ready'、'data_ready'、'DOMLoaded'、'error'、'data_failed'、'loaded_images'

-

callback

-

AnimationEventCallback<T>

-

-

用户自定义回调函数;缺省为空时, 删除此事件的所有回调函数。

-
- - -- 示例 - - ``` - this.animateItem.removeEventListener('loopComplete', this.callbackItem) - ``` - - -## AnimationItem.triggerEvent - -triggerEvent\(name: AnimationEventName, args: T\): void - -直接触发指定事件的所有已设置的回调函数。 - -- 参数 - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

描述

-

name

-

AnimationEventName

-

-

指定动画事件类型

-

-

args

-

any

-

-

用户自定义回调参数

-
- - -- 示例 - - ``` - private triggerCallBack: any = function(item) { - console.log("trigger loopComplete, name:" + item.name) - } - - this.animateItem.addEventListener('loopComplete', this.triggerCallBack) - this.animateItem.triggerEvent('loopComplete', this.animateItem) - this.animateItem.removeEventListener('loopComplete', this.triggerCallBack) - ``` - - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/05.Path2D\345\257\271\350\261\241.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/05.Path2D\345\257\271\350\261\241.md" deleted file mode 100644 index bd6f654fbb738666c82412829094f34047daae32..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/05.Path2D\345\257\271\350\261\241.md" +++ /dev/null @@ -1,963 +0,0 @@ ---- -title: Path2D对象 -permalink: /pages/010c0202010505 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:35 ---- -# Path2D对象 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从 API Version 8 开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -路径对象,支持通过对象的接口进行路径的描述,并通过Canvas的stroke接口进行绘制。 - -## addPath - -addPath\(path: Object\): void - -将另一个路径添加到当前的路径对象中。 - -- 参数 - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

path

-

Object

-

-

null

-

需要添加到当前路径的路径对象

-
- -- 示例 - - ``` - @Entry - @Component - struct AddPath { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - - private path2Da: Path2D = new Path2D("M250 150 L150 350 L350 350 Z") - private path2Db: Path2D = new Path2D() - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.path2Db.addPath(this.path2Da) - this.context.stroke(this.path2Db) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595216.png) - - -## closePath - -closePath\(\): void - -将路径的当前点移回到路径的起点,当前点到起点间画一条直线。如果形状已经闭合或只有一个点,则此功能不执行任何操作。 - -- 示例 - - ``` - @Entry - @Component - struct ClosePath { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private path2Db: Path2D = new Path2D() - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.path2Db.moveTo(200, 100) - this.path2Db.lineTo(300, 100) - this.path2Db.lineTo(200, 200) - this.path2Db.closePath() - this.context.stroke(this.path2Db) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/unnaming-(4).png) - - -## moveTo - -moveTo\(x: number, y: number\): void - -将路径的当前坐标点移动到目标点,移动过程中不绘制线条。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

x

-

number

-

-

0

-

目标点X轴坐标

-

y

-

number

-

-

0

-

目标点Y轴坐标

-
- -- 示例 - - ``` - @Entry - @Component - struct MoveTo { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private path2Db: Path2D = new Path2D() - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.path2Db.moveTo(50, 100) - this.path2Db.lineTo(250, 100) - this.path2Db.lineTo(150, 200) - this.path2Db.closePath() - this.context.stroke(this.path2Db) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237475113.png) - - -## lineTo - -lineTo\(x: number, y: number\): void - -从当前点绘制一条直线到目标点。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

x

-

number

-

-

0

-

目标点X轴坐标

-

y

-

number

-

-

0

-

目标点Y轴坐标

-
- -- 示例 - - ``` - @Entry - @Component - struct LineTo { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private path2Db: Path2D = new Path2D() - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.path2Db.moveTo(100, 100) - this.path2Db.lineTo(100, 200) - this.path2Db.lineTo(200, 200) - this.path2Db.lineTo(200, 100) - this.path2Db.closePath() - this.context.stroke(this.path2Db) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/unnaming-(3).png) - - -## bezierCurveTo - -bezierCurveTo\(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number\): void - -创建三次贝赛尔曲线的路径。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

cp1x

-

number

-

-

0

-

第一个贝塞尔参数的x坐标值。

-

cp1y

-

number

-

-

0

-

第一个贝塞尔参数的y坐标值。

-

cp2x

-

number

-

-

0

-

第二个贝塞尔参数的x坐标值。

-

cp2y

-

number

-

-

0

-

第二个贝塞尔参数的y坐标值。

-

x

-

number

-

-

0

-

路径结束时的x坐标值。

-

y

-

number

-

-

0

-

路径结束时的y坐标值。

-
- - -- 示例 - - ``` - @Entry - @Component - struct BezierCurveTo { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private path2Db: Path2D = new Path2D() - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.path2Db.moveTo(10, 10) - this.path2Db.bezierCurveTo(20, 100, 200, 100, 200, 20);this.context.stroke(this.path2Db) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915158.png) - - -## quadraticCurveTo - -quadraticCurveTo\(cpx: number, cpy: number, x: number ,y: number\): void - -创建二次贝赛尔曲线的路径。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

cpx

-

number

-

-

0

-

贝塞尔参数的x坐标值。

-

cpy

-

number

-

-

0

-

贝塞尔参数的y坐标值。

-

x

-

number

-

-

0

-

路径结束时的x坐标值。

-

y

-

number

-

-

0

-

路径结束时的y坐标值。

-
- -- 示例 - - ``` - @Entry - @Component - struct QuadraticCurveTo { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private path2Db: Path2D = new Path2D() - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.path2Db.moveTo(10, 10) - this.path2Db.quadraticCurveTo(100, 100, 200, 20) - this.context.stroke(this.path2Db) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001237555151.png) - - -## arc - -arc\(x: number, y: number, radius: number, startAngle: number, endAngle: number, anticlockwise?: number\): void - -绘制弧线路径。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

x

-

number

-

-

0

-

弧线圆心的x坐标值。

-

y

-

number

-

-

0

-

弧线圆心的y坐标值。

-

radius

-

number

-

-

0

-

弧线的圆半径。

-

startAngle

-

number

-

-

0

-

弧线的起始弧度。

-

endAngle

-

number

-

-

0

-

弧线的终止弧度。

-

anticlockwise

-

boolean

-

-

false

-

是否逆时针绘制圆弧。

-
- -- 示例 - - ``` - @Entry - @Component - struct Arc { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private path2Db: Path2D = new Path2D() - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.path2Db.arc(100, 75, 50, 0, 6.28);this.context.stroke(this.path2Db) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595214.png) - - -## arcTo - -arcTo\(x1: number, y1: number, x2: number, y2: number, radius: number\): void - -依据圆弧经过的点和圆弧半径创建圆弧路径。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

x1

-

number

-

-

0

-

圆弧经过的第一个点的x坐标值。

-

y1

-

number

-

-

0

-

圆弧经过的第一个点的y坐标值。

-

x2

-

number

-

-

0

-

圆弧经过的第二个点的x坐标值。

-

y2

-

number

-

-

0

-

圆弧经过的第二个点的y坐标值。

-

radius

-

number

-

-

0

-

圆弧的圆半径值。

-
- -- 示例 - - ``` - @Entry - @Component - struct ArcTo { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private path2Db: Path2D = new Path2D() - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.path2Db.arcTo(150, 20, 150, 70, 50) - this.context.stroke(this.path2Db) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755172.png) - - -## ellipse - -ellipse\(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, anticlockwise?: number\): void - -在规定的矩形区域绘制一个椭圆。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

x

-

number

-

-

0

-

椭圆圆心的x轴坐标。

-

y

-

number

-

-

0

-

椭圆圆心的y轴坐标。

-

radiusX

-

number

-

-

0

-

椭圆x轴的半径长度。

-

radiusY

-

number

-

-

0

-

椭圆y轴的半径长度。

-

rotation

-

number

-

-

0

-

椭圆的旋转角度,单位为弧度。

-

startAngle

-

number

-

-

0

-

椭圆绘制的起始点角度,以弧度表示。

-

endAngle

-

number

-

-

0

-

椭圆绘制的结束点角度,以弧度表示。

-

anticlockwise

-

number

-

-

0

-

是否以逆时针方向绘制椭圆,0为顺时针,1为逆时针。(可选参数,默认为0)

-
- -- 示例 - - ``` - @Entry - @Component - struct Ellipse { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private path2Db: Path2D = new Path2D() - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.path2Db.ellipse(200, 200, 50, 100, Math.PI * 0.25, Math.PI * 0.5, Math.PI, true) - this.context.stroke(this.path2Db) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001193075154.png) - - -## rect - -rect\(x: number, y: number, width: number, height: number\): void - -创建矩形路径。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

x

-

number

-

-

0

-

指定矩形的左上角x坐标值。

-

y

-

number

-

-

0

-

指定矩形的左上角y坐标值。

-

width

-

number

-

-

0

-

指定矩形的宽度。

-

height

-

number

-

-

0

-

指定矩形的高度。

-
- -- 示例 - - ``` - @Entry - @Component - struct Rect { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private path2Db: Path2D = new Path2D() - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.path2Db.rect(20, 20, 100, 100);this.context.stroke(this.path2Db) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192755174.png) - - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/06.CanvasGradient\345\257\271\350\261\241.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/06.CanvasGradient\345\257\271\350\261\241.md" deleted file mode 100644 index 7aa211a66266601e2b9e3d30eae855fed6cf3845..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/06.CanvasGradient\345\257\271\350\261\241.md" +++ /dev/null @@ -1,99 +0,0 @@ ---- -title: CanvasGradient对象 -permalink: /pages/010c0202010506 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:35 ---- -# CanvasGradient对象 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从 API Version 8 开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -渐变对象。 - -## addColorStop - -addColorStop\(offset: number, color: string\): void - -设置渐变断点值,包括偏移和颜色。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - -

参数

-

类型

-

必填

-

默认值

-

描述

-

offset

-

number

-

-

0

-

设置渐变点距离起点的位置占总体长度的比例,范围为0到1。

-

color

-

string

-

-

'ffffff'

-

设置渐变的颜色。

-
- -- 示例 - - ``` - @Entry - @Component - struct Page45 { - private settings: RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private gra:CanvasGradient = new CanvasGradient() - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - var grad = this.context.createLinearGradient(50,0, 300,100) - this.gra.addColorStop(0.0, 'red') - this.gra.addColorStop(0.5, 'white') - this.gra.addColorStop(1.0, 'green') - this.context.fillStyle = grad - this.context.fillRect(0, 0, 500, 500) - }) - } - .width('100%') - .height('100%') - } - } - ``` - - ![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192915130.png) - - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/07.ImageBitmap\345\257\271\350\261\241.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/07.ImageBitmap\345\257\271\350\261\241.md" deleted file mode 100644 index 07b07850dab7d87bae7ca2fd97d16a41f3088aa1..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/07.ImageBitmap\345\257\271\350\261\241.md" +++ /dev/null @@ -1,120 +0,0 @@ ---- -title: ImageBitmap对象 -permalink: /pages/010c0202010507 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:35 ---- -# ImageBitmap对象 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从 API Version 8 开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -图片对象。 - -## 接口 - -ImageBitmap\(src: string\) - -- 参数 - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

src

-

string

-

-

-

-

图片对象所在的路径。

-
- - -## 属性 - - - - - - - - - - - - - - - - - - - - - -

属性

-

类型

-

默认值

-

必填

-

描述

-

width

-

Length

-

0px

-

-

图片的宽度。

-

height

-

Length

-

0px

-

-

图片的高度。

-
- -示例 - -``` -@Entry -@Component -struct DrawImageExample { - private settings:RenderingContextSettings = new RenderingContextSettings(true,true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private img:ImageBitmap = new ImageBitmap("common/images/example.jpg") - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Canvas(this.context) - .width('100%') - .height('100%') - .backgroundColor('#ffff00') - .onReady(() =>{ - this.context.drawImage( this.img,0,0,400,200) - }) - } - .width('100%') - .height('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001192595194.png) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/08.ImageData\345\257\271\350\261\241.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/08.ImageData\345\257\271\350\261\241.md" deleted file mode 100644 index d692dfc77a02f324738916f3eb80687e7334b35c..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/01.\347\273\204\344\273\266/05.\347\224\273\345\270\203\347\273\204\344\273\266/08.ImageData\345\257\271\350\261\241.md" +++ /dev/null @@ -1,54 +0,0 @@ ---- -title: ImageData对象 -permalink: /pages/010c0202010508 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:35 ---- -# ImageData对象 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从 API Version 8 开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -CanvasImageData对象可以存储canvas渲染的像素数据。 - -## 属性 - - - - - - - - - - - - - - - - - - - -

属性

-

类型

-

描述

-

width

-

number

-

矩形区域实际像素宽度。

-

height

-

number

-

矩形区域实际像素高度。

-

data

-

<Uint8ClampedArray>

-

一维数组,保存了相应的颜色数据,数据值范围为0到255。

-
- diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\345\212\250\347\224\273/01.\345\261\236\346\200\247\345\212\250\347\224\273.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\345\212\250\347\224\273/01.\345\261\236\346\200\247\345\212\250\347\224\273.md" deleted file mode 100644 index 8bdca7b7ffa96a215e1ff9515a73c729642b0430..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\345\212\250\347\224\273/01.\345\261\236\346\200\247\345\212\250\347\224\273.md" +++ /dev/null @@ -1,194 +0,0 @@ ---- -title: 属性动画 -permalink: /pages/010c02020201 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:35 ---- -# 属性动画 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -组件的通用属性发生变化时,可以创建属性动画进行渐变,提升用户体验。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

duration

-

number

-

1000

-

单位为毫秒,默认动画时长为1000毫秒。

-

curve

-

Curve

-

Linear

-

默认曲线为线性,有效值参见Curve说明。

-

delay

-

number

-

0

-

单位为毫秒,默认不延时播放。

-

iterations

-

number

-

1

-

默认播放一次,设置为-1时表示无限次播放。

-

playMode

-

PlayMode

-

Normal

-

设置动画播放模式,默认播放完成后重头开始播放。

-
- -- Curve枚举说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

描述

-

Linear

-

表示动画从头到尾的速度都是相同的。

-

Ease

-

表示动画以低速开始,然后加快,在结束前变慢,CubicBezier(0.25, 0.1, 0.25, 1.0)。

-

EaseIn

-

表示动画以低速开始,CubicBezier(0.42, 0.0, 1.0, 1.0)。

-

EaseOut

-

表示动画以低速结束,CubicBezier(0.0, 0.0, 0.58, 1.0)。

-

EaseInOut

-

表示动画以低速开始和结束,CubicBezier(0.42, 0.0, 0.58, 1.0)。

-

FastOutSlowIn

-

标准曲线,cubic-bezier(0.4, 0.0, 0.2, 1.0)。

-

LinearOutSlowIn

-

减速曲线,cubic-bezier(0.0, 0.0, 0.2, 1.0)。

-

FastOutLinearIn

-

加速曲线,cubic-bezier(0.4, 0.0, 1.0, 1.0)。

-

ExtremeDeceleration

-

急缓曲线,cubic-bezier(0.0, 0.0, 0.0, 1.0)。

-

Sharp

-

锐利曲线,cubic-bezier(0.33, 0.0, 0.67, 1.0)。

-

Rhythm

-

节奏曲线,cubic-bezier(0.7, 0.0, 0.2, 1.0)。

-

Smooth

-

平滑曲线,cubic-bezier(0.4, 0.0, 0.4, 1.0)。

-

Friction

-

阻尼曲线,CubicBezier(0.2, 0.0, 0.2, 1.0)。

-
- - -## 示例 - -``` -@Entry -@Component -struct AttrAnimationExample { - @State widthSize: number = 200 - @State heightSize: number = 100 - @State flag: boolean = true - - build() { - Column() { - Button('click me') - .onClick((event: ClickEvent) => { - if (this.flag) { - this.widthSize = 100 - this.heightSize = 50 - } else { - this.widthSize = 200 - this.heightSize = 100 - } - this.flag = !this.flag - }) - .width(this.widthSize).height(this.heightSize).backgroundColor(0x317aff) - .animation({ - duration: 2000, // 动画时长 - curve: Curve.EaseOut, // 动画曲线 - delay: 500, // 动画延迟 - iterations: 1, // 播放次数 - playMode: PlayMode.Normal // 动画模式 - }) // 对Button组件的宽高属性进行动画配置 - }.width('100%').margin({ top: 5 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/AttrAnimation.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\345\212\250\347\224\273/02.\346\230\276\345\274\217\345\212\250\347\224\273.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\345\212\250\347\224\273/02.\346\230\276\345\274\217\345\212\250\347\224\273.md" deleted file mode 100644 index a71ca57d63a1dfb79dc97292ff203dbdff38f63e..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\345\212\250\347\224\273/02.\346\230\276\345\274\217\345\212\250\347\224\273.md" +++ /dev/null @@ -1,179 +0,0 @@ ---- -title: 显式动画 -permalink: /pages/010c02020202 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:35 ---- -# 显式动画 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - - - - - - - - - -

接口名称

-

功能描述

-

animateTo(value: AnimationOption, event: ()=> void) : void

-

提供全局animateTo显式动画接口来指定由于闭包代码导致的状态变化插入过渡动效。

-

event指定显示动效的闭包函数,在闭包函数中导致的状态变化系统会自动插入过渡动画。

-
- -## AnimationOption对象说明 - -- 属性 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

属性名称

-

属性类型

-

默认值

-

描述

-

duration

-

number

-

1000

-

动画持续时间,单位为毫秒。

-

tempo

-

number

-

1.0

-

动画的播放速度,值越大动画播放越快,值越小播放越慢,为0时无动画效果。

-

curve

-

Curve | Curves

-

Linear

-

动画曲线。

-

delay

-

number

-

0

-

单位为ms(毫秒),默认不延时播放。

-

iterations

-

number

-

1

-

默认播放一次,设置为-1时表示无限次播放。

-

playMode

-

PlayMode

-

Normal

-

设置动画播放模式,默认播放完成后重头开始播放。

-
- - -- 接口 - - - - - - - - - -

名称

-

功能描述

-

onFinish() => void

-

动效播放完成回调。

-
- - -## 示例 - -``` -@Entry -@Component -struct AnimateToExample { - @State widthSize: number = 200 - @State heightSize: number = 100 - private flag: boolean = true - - build() { - Column() { - Button('click me') - .width(this.widthSize) - .height(this.heightSize) - .backgroundColor(0x317aff) - .onClick((event: ClickEvent) => { - // 对Button组件的宽高属性进行动画配置 - if (this.flag) { - animateTo({ - duration: 1000, // 动画时长 - tempo: 0.5, // 播放速率 - curve: Curve.EaseInOut, // 动画曲线 - delay: 200, // 动画延迟 - iterations: 1, // 播放次数 - playMode: PlayMode.Normal, // 动画模式 - onFinish: () => { - console.info('play end') - } - }, () => { - this.widthSize = 100 - this.heightSize = 50 - }) - } else { - animateTo({ - duration: 200, // 动画时长 - curve: Curve.Ease, // 动画曲线 - delay: 200, // 动画延迟 - iterations: 1, // 播放次数 - playMode: PlayMode.Normal, // 动画模式 - onFinish: () => { - console.info('play end') - } - }, () => { - this.widthSize = 200 - this.heightSize = 100 - }) - } - this.flag = !this.flag - }) - }.width('100%').margin({ top: 5 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/AnimateTo.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\345\212\250\347\224\273/03.\350\275\254\345\234\272\345\212\250\347\224\273/01.\351\241\265\351\235\242\351\227\264\350\275\254\345\234\272.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\345\212\250\347\224\273/03.\350\275\254\345\234\272\345\212\250\347\224\273/01.\351\241\265\351\235\242\351\227\264\350\275\254\345\234\272.md" deleted file mode 100644 index 9ce8cc1e2730b2a13a4f4f4e4c467c75ac6520ff..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\345\212\250\347\224\273/03.\350\275\254\345\234\272\345\212\250\347\224\273/01.\351\241\265\351\235\242\351\227\264\350\275\254\345\234\272.md" +++ /dev/null @@ -1,394 +0,0 @@ ---- -title: 页面间转场 -permalink: /pages/010c0202020301 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:35 ---- -# 页面间转场 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -页面转场通过在全局pageTransition方法内配置页面入场组件和页面退场组件来自定义页面转场动效。 - - - - - - - - - - - - - - - -

名称

-

参数

-

参数描述

-

PageTransitionEnter

-

Object

-

页面入场组件,用于自定义当前页面的入场效果,详见动效参数说明

-

PageTransitionExit

-

Object

-

页面退场组件,用于自定义当前页面的退场效果,详见动效参数说明

-
- -- 动效参数说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名称

-

参数类型

-

默认值

-

必填

-

参数描述

-

type

-

RouteType

-

-

-

-

不配置时表明pop为push时效果的逆播。

-

duration

-

number

-

1000

-

-

动画时长,单位为毫秒。

-

curve

-

Curve | Curves

-

Linear

-

-

动画曲线,有效值参见Curve 说明。

-

delay

-

number

-

0

-

-

动画延迟时长,单位为毫秒,默认不延时播放。

-
- - -- RouteType枚举说明 - - - - - - - - - - - - -

名称

-

描述

-

Pop

-

PageA跳转到PageB时,PageA为Exit+Push,PageB为Enter+Push。

-

Push

-

PageB返回至PageA时,PageA为Enter+Pop,PageB为Exit+Pop。

-
- - -## 属性 - -PageTransitionEnter和PageTransitionExit组件支持的属性: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名称

-

参数类型

-

默认值

-

必填

-

参数描述

-

slide

-

SlideEffect

-

Right

-

-

设置转场的滑入效果,有效值参见SlideEffect说明。

-

translate

-

{

-

x? : number,

-

y? : number,

-

z? : number

-

}

-

-

-

-

设置页面转场时的平移效果,为入场时起点和退场时终点的值,和slide同时设置时默认生效slide。

-

scale

-

{

-

x? : number,

-

y? : number,

-

z? : number,

-

centerX? : number,

-

centerY? : number

-

}

-

-

-

-

设置页面转场时的缩放效果,为入场时起点和退场时终点的值。

-

opacity

-

number

-

1

-

-

设置入场的起点透明度值或者退场的终点透明度值。

-
- -- SlideEffect枚举说明 - - - - - - - - - - - - - - - - - - -

名称

-

描述

-

Left

-

设置到入场时表示从左边滑入,出场时表示滑出到左边。

-

Right

-

设置到入场时表示从右边滑入,出场时表示滑出到右边。

-

Top

-

设置到入场时表示从上边滑入,出场时表示滑出到上边。

-

Bottom

-

设置到入场时表示从下边滑入,出场时表示滑出到下边。

-
- - -## 事件 - -PageTransitionEnter和PageTransitionExit组件支持的事件: - - - - - - - - - - - - -

事件

-

功能描述

-

onEnter(type: RouteType, progress: number) => void

-

回调入参为当前入场动画的归一化进度[0 - 1]。

-

onExit(type: RouteType, progress: number) => void

-

回调入参为当前退场动画的归一化进度[0 - 1]。

-
- -## 示例 - -自定义方式1:配置了当前页面的入场动画为淡入,退场动画为缩小。 - -``` -// index.ets -@Entry -@Component -struct PageTransitionExample1 { - @State scale: number = 1 - @State opacity: number = 1 - @State active: boolean = false - build() { - Column() { - Navigator({ target: 'pages/page1', type: NavigationType.Push }) { - Image($r('app.media.bg1')).width("100%").height("100%") - } - .onClick(() => { - this.active = true - }) - }.scale({ x: this.scale }).opacity(this.opacity) - } -// 自定义方式1:完全自定义转场过程的效果 - pageTransition() { - PageTransitionEnter({ duration: 1200, curve: Curve.Linear }) - .onEnter((type: RouteType, progress: number) => { - this.scale = 1 - this.opacity = progress - }) // 进场过程中会逐帧触发onEnter回调,入参为动效的归一化进度(0% -- 100%) - PageTransitionExit({ duration: 1500, curve: Curve.Ease }) - .onExit((type: RouteType, progress: number) => { - this.scale = 1 - progress - this.opacity = 1 - }) // 退场过程中会逐帧触发onExit回调,入参为动效的归一化进度(0% -- 100%) - } -} -``` - -``` -// page1.ets -@Entry -@Component -struct AExample { - @State scale: number = 1 - @State opacity: number = 1 - @State active: boolean = false - build() { - Column() { - Navigator({ target: 'pages/index' ,type: NavigationType.Push}) { - Image($r('app.media.bg2')).width("100%").height("100%") - } - }.height("100%").width("100%").scale({ x: this.scale }).opacity(this.opacity) - } -// 自定义方式1:完全自定义转场过程的效果 - pageTransition() { - PageTransitionEnter({ duration: 1200, curve: Curve.Linear }) - .onEnter((type: RouteType, progress: number) => { - this.scale = 1 - this.opacity = progress - }) // 进场过程中会逐帧触发onEnter回调,入参为动效的归一化进度(0% -- 100%) - PageTransitionExit({ duration: 1500, curve: Curve.Ease }) - .onExit((type: RouteType, progress: number) => { - this.scale = 1 - progress - this.opacity = 1 - }) // 退场过程中会逐帧触发onExit回调,入参为动效的归一化进度(0% -- 100%) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/PageTransition1.gif) - -自定义方式2:配置了当前页面的入场动画为从左侧滑入,退场为缩小加透明度变化。 - -``` -// index.ets -@Entry -@Component -struct PageTransitionExample { - @State scale: number = 1 - @State opacity: number = 1 - @State active: boolean = false - - build() { - Column() { - Navigator({ target: 'pages/page1', type: NavigationType.Push }) { - Image($r('app.media.bg1')).width("100%").height("100%") - } - .onClick(() => { - this.active = true - }) - }.scale({ x: this.scale }).opacity(this.opacity) - } - -// 自定义方式2:使用系统提供的多种默认效果(平移、缩放、透明度等) - pageTransition() { - PageTransitionEnter({ duration: 1200 }) - .slide(SlideEffect.Left) - PageTransitionExit({ delay: 100 }) - .translate({ x: 100.0, y: 100.0 }) - .opacity(0) - } -} -``` - -``` -// page1.ets -@Entry -@Component -struct PageTransitionExample1 { - @State scale: number = 1 - @State opacity: number = 1 - @State active: boolean = false - - build() { - Column() { - Navigator({ target: 'pages/index', type: NavigationType.Push }) { - Image($r('app.media.bg2')).width ("100%").height("100%") - } - .onClick(() => { - this.active = true - }) - }.scale({ x: this.scale }).opacity(this.opacity) - } - -// 自定义方式2:使用系统提供的多种默认效果(平移、缩放、透明度等) - pageTransition() { - PageTransitionEnter({ duration: 1200 }) - .slide(SlideEffect.Left) - PageTransitionExit({ delay: 100 }) - .translate({ x: 100.0, y: 100.0 }) - .opacity(0) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/PageTransition2.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\345\212\250\347\224\273/03.\350\275\254\345\234\272\345\212\250\347\224\273/02.\347\273\204\344\273\266\345\206\205\350\275\254\345\234\272.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\345\212\250\347\224\273/03.\350\275\254\345\234\272\345\212\250\347\224\273/02.\347\273\204\344\273\266\345\206\205\350\275\254\345\234\272.md" deleted file mode 100644 index 1c963b8ca5446860df9462a82555b162a077b41a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\345\212\250\347\224\273/03.\350\275\254\345\234\272\345\212\250\347\224\273/02.\347\273\204\344\273\266\345\206\205\350\275\254\345\234\272.md" +++ /dev/null @@ -1,200 +0,0 @@ ---- -title: 组件内转场 -permalink: /pages/010c0202020302 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:35 ---- -# 组件内转场 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -组件转场主要通过transition属性进行配置转场参数,在组件插入和删除时进行过渡动效,主要用于容器组件子组件插入删除时提升用户体验(需要配合animateTo才能生效,动效时长、曲线、延时跟随animateTo中的配置)。 - -## 属性 - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

参数描述

-

transition

-

Object

-

-

-

所有参数均为可选参数,详细描述见transition入参说明

-
- -- transition入参说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名称

-

参数类型

-

默认值

-

必填

-

参数描述

-

type

-

TransitionType

-

All

-

-

默认包括组件新增和删除。

-
说明:

不指定Type时说明插入删除使用同一种效果。

-
-

opacity

-

number

-

1

-

-

设置组件转场时的透明度效果,为插入时起点和删除时终点的值。

-

translate

-

{

-

x? : number,

-

y? : number,

-

z? : number

-

}

-

-

-

-

设置组件转场时的平移效果,为插入时起点和删除时终点的值。

-

scale

-

{

-

x? : number,

-

y? : number,

-

z? : number,

-

centerX? : number,

-

centerY? : number

-

}

-

-

-

-

设置组件转场时的缩放效果,为插入时起点和删除时终点的值。

-

rotate

-

{

-

x?: number,

-

y?: number,

-

z?: number,

-

angle?: Angle,

-

centerX?: Length,

-

centerY?: Length

-

}

-

-

-

-

设置组件转场时的旋转效果,为插入时起点和删除时终点的值。

-
- - -- TransitionType枚举说明 - - - - - - - - - - - - - - - -

名称

-

描述

-

All

-

指定当前的Transition动效生效在组件的所有变化场景。

-

Insert

-

指定当前的Transition动效生效在组件的插入场景。

-

Delete

-

指定当前的Transition动效生效在组件的删除场景。

-
- - -## 示例 - -示例功能通过一个Button控制第二个Button的出现和消失,并通过transition配置第二个Button出现和消失的过场动画。 - -``` -@Entry -@Component -struct TransitionExample { - @State btn1: boolean = false - @State show: string = "show" - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center,}) { - Button(this.show).width(80).height(30).backgroundColor(0x317aff).margin({bottom:50}) - .onClick(() => { - animateTo({ duration: 1000 }, () => { - this.btn1 = !this.btn1 - if(this.btn1){ - this.show = "hide" - }else{ - this.show = "show" - } - }) - }) - if (this.btn1) { - // 插入和删除配置为不同的过渡效果 - Button() { - Image($r('app.media.bg1')).width("80%").height(300) - }.transition({ type: TransitionType.Insert, scale : {x:0,y:1.0} }) - .transition({ type: TransitionType.Delete, scale: { x: 1.0, y: 0.0 } }) - } - }.height(400).width("100%").padding({top:100}) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/Transition.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\345\212\250\347\224\273/03.\350\275\254\345\234\272\345\212\250\347\224\273/03.\345\205\261\344\272\253\345\205\203\347\264\240\350\275\254\345\234\272.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\345\212\250\347\224\273/03.\350\275\254\345\234\272\345\212\250\347\224\273/03.\345\205\261\344\272\253\345\205\203\347\264\240\350\275\254\345\234\272.md" deleted file mode 100644 index 08404252d6cbc4e9713be00bcb5909bcffbaeacc..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\345\212\250\347\224\273/03.\350\275\254\345\234\272\345\212\250\347\224\273/03.\345\205\261\344\272\253\345\205\203\347\264\240\350\275\254\345\234\272.md" +++ /dev/null @@ -1,143 +0,0 @@ ---- -title: 共享元素转场 -permalink: /pages/010c0202020303 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:35 ---- -# 共享元素转场 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -共享元素转场支持页面间的转场,如当前页面的图片转场至下一页面中。 - -## 属性 - - - - - - - - - - - - - -

名称

-

参数

-

默认值

-

参数描述

-

sharedTransition

-

id: string,

-

options?: Object

-

-

-

两个页面的组件配置为同一个id,则转场过程中会进行共享元素转场,配置为空字符串时不会有共享元素转场效果。

-
- -- options参数说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名称

-

参数类型

-

默认值

-

必填

-

参数描述

-

duration

-

number

-

1000

-

-

单位为毫秒,默认动画时长为1000毫秒。

-

curve

-

Curve | Curves

-

Linear

-

-

默认曲线为线性,有效值参见Curve说明。

-

delay

-

number

-

0

-

-

单位为毫秒,默认不延时播放。

-
- - -## 示例 - -示例功能为两个页面,共享元素转场页面图片点击后转场至页面B的图片。 - -``` -@Entry -@Component -struct SharedTransitionExample { - @State scale: number = 1 - @State opacity: number = 1 - @State active: boolean = false - - build() { - List() { - ListItem() { - Row() { - Navigator({ target: 'pages/common/Animation/transAnimation/PageB', type: NavigationType.Push }) { - Image($r('app.media.ic_health_heart')).width(50).height(50) - .sharedTransition('sharedImage1', { duration: 800, curve: Curve.Linear, delay: 100 }) - }.padding({ left: 10 }) - .onClick(() => { - this.active = true - }) - - Text('SharedTransition').width(80).height(80).textAlign(TextAlign.Center) - } - } - } - } -} -``` - -``` -// PageB -@Entry -@Component -struct BExample { - build() { - Stack() { - Image($r('app.media.ic_health_heart')).width(150).height(150).sharedTransition('sharedImage1') - }.width('100%').height(400) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/SharedTransition.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\345\212\250\347\224\273/04.\350\267\257\345\276\204\345\212\250\347\224\273.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\345\212\250\347\224\273/04.\350\267\257\345\276\204\345\212\250\347\224\273.md" deleted file mode 100644 index 818dd0d6e1ae7e766861fe67b14698946084c733..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\345\212\250\347\224\273/04.\350\267\257\345\276\204\345\212\250\347\224\273.md" +++ /dev/null @@ -1,84 +0,0 @@ ---- -title: 路径动画 -permalink: /pages/010c02020204 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:35 ---- -# 路径动画 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -设置组件进行位移动画时的运动路径。 - -## 属性 - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

motionPath

-

{

-

path: string,

-

from?: number,

-

to?: number,

-

rotatable?: boolean

-

}

-
说明:

path中支持通过start和end进行起点和终点的替代,如:

-

'Mstart.x start.y L50 50 Lend.x end.y Z'。

-
-

{

-

"",

-

0.0,

-

1.0,

-

false

-

}

-

设置组件的运动路径,入参说明如下:

-
  • path:位移动画的运动路径,使用svg路径字符串。
  • from:运动路径的起点,默认为0.0。
  • to:运动路径的终点,默认为1.0。
  • rotatable:是否跟随路径进行旋转。
-
- -## 示例 - -``` -@Entry -@Component -struct MotionPathExample { - @State offsetX: number = 0 - @State offsetY: number = 0 - @State toggle: boolean = true - - build() { - Column() { - Button('click me') - .motionPath({ path: 'Mstart.x start.y L300 200 L300 500 Lend.x end.y', from: 0.0, to: 1.0, rotatable: true }) - .onClick((event: ClickEvent) => { - animateTo({ duration: 4000, curve: Curve.Linear }, () => { - this.toggle = !this.toggle; - }) - }).backgroundColor(0x317aff) - }.width('100%').height('100%').alignItems(this.toggle ? HorizontalAlign.Start : HorizontalAlign.Center) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/motion.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\345\212\250\347\224\273/05.\347\237\251\351\230\265\345\217\230\346\215\242.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\345\212\250\347\224\273/05.\347\237\251\351\230\265\345\217\230\346\215\242.md" deleted file mode 100644 index 89c8744086f46968e582d7a6ba7c68763a0a513a..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\345\212\250\347\224\273/05.\347\237\251\351\230\265\345\217\230\346\215\242.md" +++ /dev/null @@ -1,847 +0,0 @@ ---- -title: 矩阵变换 -permalink: /pages/010c02020205 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:35 ---- -# 矩阵变换 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 导入模块 - -``` -import Matrix4 from '@ohos.matrix4' -``` - -## 权限列表 - -无 - -## matrix4.init - -init\(array: Array\): Object - -Matrix的构造函数,可以通过传入的参数创建一个四阶矩阵,矩阵为列优先。 - -- 参数 - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

默认值

-

说明

-

array

-

Array<number>

-

-

[1, 0, 0, 0,

-

0, 1, 0, 0,

-

0, 0, 1, 0,

-

0, 0, 0, 1]

-

参数为长度为16(4*4)的number数组, 详情见参数描述

-
- -- 返回值 - - - - - - - - - -

类型

-

说明

-

Object

-

根据入参创建的四阶矩阵对象。

-
- -- 参数描述 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

m00

-

number

-

-

x轴缩放值,单位矩阵默认为1。

-

m01

-

number

-

-

第2个值,xyz轴旋转会影响这个值。

-

m02

-

number

-

-

第3个值,xyz轴旋转会影响这个值。

-

m03

-

number

-

-

无实际意义。

-

m10

-

number

-

-

第5个值,xyz轴旋转会影响这个值。

-

m11

-

number

-

-

y轴缩放值,单位矩阵默认为1。

-

m12

-

number

-

-

第7个值,xyz轴旋转会影响这个值。

-

m13

-

number

-

-

无实际意义。

-

m20

-

number

-

-

第9个值,xyz轴旋转会影响这个值。

-

m21

-

number

-

-

第10个值,xyz轴旋转会影响这个值。

-

m22

-

number

-

-

z轴缩放值,单位矩阵默认为1。

-

m23

-

number

-

-

无实际意义。

-

m30

-

number

-

-

x轴平移值,单位px,单位矩阵默认为0。

-

m31

-

number

-

-

y轴平移值,单位px,单位矩阵默认为0。

-

m32

-

number

-

-

z轴平移值,单位px,单位矩阵默认为0。

-

m33

-

number

-

-

齐次坐标下生效,产生透视投影效果。

-
- -- 示例 - - ``` - // 创建一个四阶矩阵 - let matrix = Matrix4.init([1.0, 0.0, 0.0, 0.0, - 0.0, 1.0, 0.0, 0.0, - 0.0, 0.0, 1.0, 0.0, - 0.0, 0.0, 0.0, 1.0]) - ``` - - -## matrix4.identity - -identity\(\): Object - -Matrix的初始化函数,可以返回一个单位矩阵对象。 - -- 返回值 - - - - - - - - - -

类型

-

说明

-

Object

-

单位矩阵对象。

-
- -- 示例 - - ``` - // matrix1 和 matrix2 效果一致 - let matrix1 = Matrix4.init([1.0, 0.0, 0.0, 0.0, - 0.0, 1.0, 0.0, 0.0, - 0.0, 0.0, 1.0, 0.0, - 0.0, 0.0, 0.0, 1.0]) - let matrix2 = Matrix4.identity() - ``` - - -## matrix4.copy - -copy\(\): Object - -Matrix的拷贝函数,可以拷贝一份当前的矩阵对象。 - -- 返回值 - - - - - - - - - -

类型

-

说明

-

Object

-

当前矩阵的拷贝对象。

-
- -- 示例 - - ``` - @Entry - @Component - struct Test { - private matrix1 = Matrix4.identity().translate({x:100}) - private matrix2 = this.matrix1.copy().scale({x:2}) - build() { - Column() { - Image($r("app.media.bg1")) - .width("40%") - .height(100) - .transform(this.matrix1) - Image($r("app.media.bg2")) - .width("40%") - .height(100) - .margin({top:50}) - .transform(this.matrix2) - } - } - } - ``` - -![](/images/application-dev/reference/arkui-ts/figures/s1.png) - - -## Matrix4 - -### combine - -combine\(matrix: Matrix4\): Object - -Matrix的叠加函数,可以将两个矩阵的效果叠加起来生成一个新的矩阵对象。 - -- 参数 - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

默认值

-

说明

-

matrix

-

Matrix4

-

-

-

-

待叠加的矩阵对象。

-
- -- 返回值 - - - - - - - - - -

类型

-

说明

-

Object

-

矩阵叠加后的对象。

-
- -- 示例 - - ``` - @Entry - @Component - struct Test { - private matrix1 = Matrix4.identity().translate({x:200}).copy() - private matrix2 = Matrix4.identity().scale({x:2}).copy() - build() { - Column() { - // 先平移x轴100px,再缩放两倍x轴 - Image($r("app.media.bg1")).transform(this.matrix1.combine(this.matrix2)) - .width("40%") - .height(100) - .margin({top:50}) - } - } - } - ``` - -![](/images/application-dev/reference/arkui-ts/figures/q1.png) - - -### invert - -invert\(\): Object - -Matrix的逆函数,可以返回一个当前矩阵对象的逆矩阵,即效果正好相反。 - -- 返回值 - - - - - - - - - -

类型

-

说明

-

Object

-

当前矩阵的逆矩阵对象。

-
- -- 示例 - - ``` - // matrix1(宽放大2倍) 和 matrix2(宽缩小2倍) 效果相反 - let matrix1 = Matrix4.identity().scale({x:2}) - let matrix2 = matrix1.invert() - ``` - - -### translate - -translate\(\{x?: number, y?: number, z?: number\}\): Object - -Matrix的平移函数,可以为当前矩阵增加x轴/Y轴/Z轴平移效果。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

默认值

-

说明

-

x

-

number

-

-

0

-

x轴的平移距离,单位px。

-

y

-

number

-

-

0

-

y轴的平移距离,单位px。

-

z

-

number

-

-

0

-

z轴的平移距离,单位px。

-
- - -- 返回值 - - - - - - - - - -

类型

-

说明

-

Object

-

增加好平移效果后的矩阵对象。

-
- -- 示例 - - ``` - @Entry - @Component - struct Test { - private matrix1 = Matrix4.identity().translate({x:100, y:200, z:30}) - build() { - Column() { - Image($r("app.media.bg1")).transform(this.matrix1) - .width("40%") - .height(100) - } - } - } - ``` - -![](/images/application-dev/reference/arkui-ts/figures/s3.png) - - -### scale - -scale\(\{x?: number, y?: number, z?: number, centerX?: number, centerY?: number\}\): Object - -Matrix的缩放函数,可以为当前矩阵增加x轴/Y轴/Z轴缩放效果。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

默认值

-

说明

-

x

-

number

-

-

1

-

x轴的缩放倍数。

-

y

-

number

-

-

1

-

y轴的缩放倍数。

-

z

-

number

-

-

1

-

z轴的缩放倍数。

-

centerX

-

number

-

-

0

-

变换中心点x轴坐标。

-

centerY

-

number

-

-

0

-

变换中心点y轴坐标。

-
- - -- 返回值 - - - - - - - - - -

类型

-

说明

-

Object

-

增加好缩放效果后的矩阵对象。

-
- -- 示例 - - ``` - @Entry - @Component - struct Test { - private matrix1 = Matrix4.identity().scale({x:2, y:3, z:4, centerX:50, centerY:50}) - build() { - Column() { - Image($r("app.media.bg1")).transform(this.matrix1) - .width("40%") - .height(100) - } - } - } - ``` - -![](/images/application-dev/reference/arkui-ts/figures/s4-(1).png) - - -### rotate - -rotate\(\{x?: number, y?: number, z?: number, angle?: number, centerX?: Length, centerY?: Length\}\): Object - -Matrix的旋转函数,可以为当前矩阵增加x轴/Y轴/Z轴旋转效果。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

默认值

-

说明

-

x

-

number

-

-

1

-

旋转轴向量x坐标。

-

y

-

number

-

-

1

-

旋转轴向量y坐标。

-

z

-

number

-

-

1

-

旋转轴向量z坐标。

-

angle

-

number

-

-

0

-

旋转角度。

-

centerX

-

number

-

-

0

-

变换中心点x轴坐标。

-

centerY

-

number

-

-

0

-

变换中心点y轴坐标。

-
- - -- 返回值 - - - - - - - - - -

类型

-

说明

-

Object

-

增加好旋转效果后的矩阵对象。

-
- -- 示例 - - ``` - @Entry - @Component - struct Test { - private matrix1 = Matrix4.identity().rotate({x:1, y:1, z:2, angle:30}) - build() { - Column() { - Image($r("app.media.bg1")).transform(this.matrix1) - .width("40%") - .height(100) - }.width("100%").margin({top:50}) - } - } - ``` - -![](/images/application-dev/reference/arkui-ts/figures/1.png) - - -### transformPoint - -transformPoint\(point: Point\): Point - -Matrix的坐标点转换函数,可以将当前的变换效果作用到一个坐标点上。 - -- 参数 - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

默认值

-

说明

-

point

-

Point

-

-

-

-

需要转换的坐标点。

-
- - -- 返回值 - - - - - - - - - -

类型

-

说明

-

Point

-

返回矩阵变换后的Point对象。

-
- -- 示例 - - ``` - import prompt from '@system.prompt' - - @Entry - @Component - struct Test { - private matrix1 = Matrix4.identity().transformPoint([100, 10]) - build() { - Column() { - Button("get Point") - .onClick(() => { - prompt.showToast({message:JSON.stringify(this.matrix1),duration:2000}) - }).backgroundColor(0x2788D9) - }.width("100%").padding(50) - } - } - ``` - -![](/images/application-dev/reference/arkui-ts/figures/222.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\345\212\250\347\224\273/06.\346\217\222\345\200\274\350\256\241\347\256\227.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\345\212\250\347\224\273/06.\346\217\222\345\200\274\350\256\241\347\256\227.md" deleted file mode 100644 index 5d3b571349d8299f06b2a21dffdf264e8885cdc8..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/02.\345\212\250\347\224\273/06.\346\217\222\345\200\274\350\256\241\347\256\227.md" +++ /dev/null @@ -1,307 +0,0 @@ ---- -title: 插值计算 -permalink: /pages/010c02020206 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:35 ---- -# 插值计算 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 导入模块 - -``` -import curves from '@ohos.curves' -``` - -## 权限 - -无 - -## curves.init - -init\(curve?: Curve\): Object - -插值曲线的初始化函数,可以根据入参创建一个插值曲线对象。 - -- 参数 - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

默认值

-

说明

-

curve

-

Curve

-

-

Linear

-

曲线对象。

-
- -- 返回值 - - 曲线对象Object。 - - -## curves.steps - -steps\(count: number, end: boolean\): Object - -构造阶梯曲线对象。 - -- 参数: - - - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

默认值

-

说明

-

count

-

number

-

-

-

-

阶梯的数量,需要为正整数。

-

end

-

boolean

-

-

true

-

在每个间隔的起点或是终点发生阶跃变化 ,默认值为true,即在终点发生阶跃变化。

-
- -- 返回值 - - 曲线对象Object。 - - -## curves.cubicBezier - -cubicBezier\(x1: number, y1: number, x2: number, y2: number\): Object - -构造三阶贝塞尔曲线对象,曲线的值必须处于0-1之间。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

x1

-

number

-

-

确定贝塞尔曲线第一点横坐标。

-

y1

-

number

-

-

确定贝塞尔曲线第一点纵坐标。

-

x2

-

number

-

-

确定贝塞尔曲线第二点横坐标。

-

y2

-

number

-

-

确定贝塞尔曲线第二点纵坐标。

-
- -- 返回值 - - 曲线对象Object。 - - -## curves.spring - -spring\(velocity: number, mass: number, stiffness: number, damping: number\): Object - -构造弹簧曲线对象。 - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

velocity

-

number

-

-

初始速度。

-

mass

-

number

-

-

质量。

-

stiffness

-

number

-

-

刚度。

-

damping

-

number

-

-

阻尼。

-
- -- 返回值 - - 曲线对象Object。 - - -## 示例 - -``` -import Curves from '@ohos.curves' -let curve1 = Curves.init() // 创建一个默认线性插值曲线 -let curve2 = Curves.init(Curve.EaseIn) // 创建一个默认先慢后快插值曲线 -let curve3 = Curves.spring(100, 1, 228, 30) // 创建一个弹簧插值曲线 -let curve3 = Curves.cubicBezier(0.1, 0.0, 0.1, 1.0) // 创建一个三阶贝塞尔曲线 -``` - -曲线对象只能通过上面的接口创建。 - - - - - - - - - -

接口名称

-

功能描述

-

interpolate(time: number): number

-

插值曲线的插值计算函数,可以通过传入的归一化时间参数返回当前的插值。

-

time: 当前的归一化时间参数,有效值范围0到1。

-

返回归一化time时间点对应的曲线插值。

-
- -- 示例 - - ``` - import Curves from '@ohos.curves' - let curve = Curves.init(Curve.EaseIn) // 创建一个默认先慢后快插值曲线 - let value: number = curve.interpolate(0.5) // 计算得到时间到一半时的插值 - ``` - - -## 整体示例 - -``` -import Curves from '@ohos.curves' -@Entry -@Component -struct ImageComponent { - @State widthSize: number = 200 - @State heightSize: number = 200 - build() { - Column() { - Text() - .margin({top:100}) - .width(this.widthSize) - .height(this.heightSize) - .backgroundColor(Color.Red) - .onClick(()=> { - let curve = Curves.cubicBezier(0.25, 0.1, 0.25, 1.0); - this.widthSize = curve.interpolate(0.5) * this.widthSize; - this.heightSize = curve.interpolate(0.5) * this.heightSize; - }) - .animation({duration: 2000 , curve: Curves.spring(0.25, 0.1, 0.25, 1.0)}) - }.width("100%").height("100%") - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/5.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\205\250\345\261\200UI\346\226\271\346\263\225/01.\350\255\246\345\221\212\345\274\271\347\252\227.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\205\250\345\261\200UI\346\226\271\346\263\225/01.\350\255\246\345\221\212\345\274\271\347\252\227.md" deleted file mode 100644 index a22cfd68533952929816a093514783035bb6db25..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\205\250\345\261\200UI\346\226\271\346\263\225/01.\350\255\246\345\221\212\345\274\271\347\252\227.md" +++ /dev/null @@ -1,347 +0,0 @@ ---- -title: 警告弹窗 -permalink: /pages/010c02020301 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:35 ---- -# 警告弹窗 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -显示警告弹窗组件,可设置文本内容与响应回调。 - -## 属性 - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

参数描述

-

show

-

options: { paramObject1| paramObject2}

-

-

-

定义并显示AlertDialog组件。

-
- -- paramObject1参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

title

-

string | Resource

-

-

-

-

弹窗标题。

-

message

-

string | Resource

-

-

-

-

弹窗内容。

-

autoCancel

-

boolean

-

-

true

-

点击遮障层时,是否关闭弹窗。

-

confirm

-

{

-

value: string | Resource,

-

fontColor?: Color | number | string | Resource,

-

backgroundColor?: Color | number | string | Resource,

-

action: () => void

-

}

-

-

-

-

确认按钮的文本内容、文本色、按钮背景色和点击回调。

-

cancel

-

() => void

-

-

-

-

点击遮障层关闭dialog时的回调。

-

alignment

-

DialogAlignment

-

-

DialogAlignment.Default

-

弹窗在竖直方向上的对齐方式。

-

offset

-

{

-

dx: Length | Resource,

-

dy: Length | Resource

-

}

-

-

-

-

弹窗相对alignment所在位置的偏移量。

-

gridCount

-

number

-

-

-

-

弹窗容器宽度所占用栅格数。

-
- - -- paramObject2参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

title

-

string | Resource

-

-

-

-

弹窗标题。

-

message

-

string | Resource

-

-

-

-

弹窗内容。

-

autoCancel

-

boolean

-

-

true

-

点击遮障层时,是否关闭弹窗。

-

primaryButton

-

{

-

value: string | Resource,

-

fontColor?: Color | number | string | Resource,

-

backgroundColor?: Color | number | string | Resource,

-

action: () => void;

-

}

-

-

-

-

按钮的文本内容、文本色、按钮背景色和点击回调。

-

secondaryButton

-

-

{

-

value: string | Resource,

-

fontColor?: Color | number | string | Resource,

-

backgroundColor?: Color | number | string | Resource,

-

action: () => void;

-

}

-

-

-

-

按钮的文本内容、文本色、按钮背景色和点击回调。

-

cancel

-

() => void

-

-

-

-

点击遮障层关闭dialog时的回调。

-

alignment

-

DialogAlignment

-

-

DialogAlignment.Default

-

弹窗在竖直方向上的对齐方式。

-

offset

-

{

-

dx: Length | Resource,

-

dy: Length | Resource

-

}

-

-

-

-

弹窗相对alignment所在位置的偏移量。

-

gridCount

-

number

-

-

-

-

弹窗容器宽度所占用栅格数。

-
- - -## 示例 - -``` -@Entry -@Component -struct AlertDialogExample { - build() { - Column({ space: 5 }) { - Button('one button dialog') - .onClick(() => { - AlertDialog.show( - { - title: 'title', - message: 'text', - confirm: { - value: 'button', - action: () => { - console.info('Button-clicking callback') - } - }, - cancel: () => { - console.info('Closed callbacks') - } - } - ) - }) - .backgroundColor(0x317aff) - Button('two button dialog') - .onClick(() => { - AlertDialog.show( - { - title: 'title', - message: 'text', - primaryButton: { - value: 'cancel', - action: () => { - console.info('Callback when the first button is clicked') - } - }, - secondaryButton: { - value: 'ok', - action: () => { - console.info('Callback when the second button is clicked') - } - }, - cancel: () => { - console.info('Closed callbacks') - } - } - ) - }).backgroundColor(0x317aff) - }.width('100%').margin({ top: 5 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/AlertDialog.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\205\250\345\261\200UI\346\226\271\346\263\225/02.\350\207\252\345\256\232\344\271\211\345\274\271\347\252\227.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\205\250\345\261\200UI\346\226\271\346\263\225/02.\350\207\252\345\256\232\344\271\211\345\274\271\347\252\227.md" deleted file mode 100644 index 968d00d9bea5c9c138eb252964ca4f7eb916129c..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\205\250\345\261\200UI\346\226\271\346\263\225/02.\350\207\252\345\256\232\344\271\211\345\274\271\347\252\227.md" +++ /dev/null @@ -1,220 +0,0 @@ ---- -title: 自定义弹窗 -permalink: /pages/010c02020302 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:35 ---- -# 自定义弹窗 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -通过CustomDialogController类显示自定义弹窗。 - -## 接口 - -CustomDialogController\(value:\{builder: CustomDialog, cancel?: \(\) =\> void, autoCancel?: boolean\}\) - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

builder

-

-

-

-

自定义弹窗内容构造器。

-

cancel

-

() => void

-

-

-

-

点击遮障层退出时的回调。

-

autoCancel

-

boolean

-

-

true

-

是否允许点击遮障层退出。

-

alignment

-

DialogAlignment

-

-

DialogAlignment.Default

-

弹窗在竖直方向上的对齐方式。

-

offset

-

{

-

dx: Length | Resource,

-

dy: Length | Resource

-

}

-

-

-

-

弹窗相对alignment所在位置的偏移量。

-

customStyle

-

boolean

-

-

false

-

弹窗容器样式是否自定义。

-
- -- DialogAlignment枚举说明 - - - - - - - - - - - - - - - - - - -

名称

-

描述

-

Top

-

垂直顶部对齐。

-

Center

-

垂直居中对齐。

-

Bottom

-

垂直底部对齐。

-

Default

-

默认对齐。

-
- - -### CustomDialogController - -创建对象 - -``` -dialogController : CustomDialogController = new CustomDialogController(value:{builder: CustomDialog, cancel?: () => void, autoCancel?: boolean}) -``` - -open\(\) - -显示自定义弹窗内容,若已显示,则不生效。 - -close\(\) - -关闭显示的自定义弹窗,若已关闭,则不生效。 - -## 示例 - -``` -@CustomDialog -struct CustomDialogExample { - controller: CustomDialogController - cancel: () => void - confirm: () => void - - build() { - Column() { - Text('Software uninstall').width('70%').fontSize(20).margin({ top: 10, bottom: 10 }) - Image($r('app.media.icon')).width(80).height(80) - Text('Whether to uninstall a software?').fontSize(16).margin({ bottom: 10 }) - Flex({ justifyContent: FlexAlign.SpaceAround }) { - Button('cancel') - .onClick(() => { - this.controller.close() - this.cancel() - }).backgroundColor(0xffffff).fontColor(Color.Black) - Button('confirm') - .onClick(() => { - this.controller.close() - this.confirm() - }).backgroundColor(0xffffff).fontColor(Color.Red) - }.margin({ bottom: 10 }) - } - } -} - -@Entry -@Component -struct CustomDialogUser { - dialogController: CustomDialogController = new CustomDialogController({ - builder: CustomDialogExample({ cancel: this.onCancel, confirm: this.onAccept }), - cancel: this.existApp, - autoCancel: true - }) - - onCancel() { - console.info('Callback when the first button is clicked') - } - onAccept() { - console.info('Callback when the second button is clicked') - } - existApp() { - console.info('Click the callback in the blank area') - } - - build() { - Column() { - Button('click me') - .onClick(() => { - this.dialogController.open() - }).backgroundColor(0x317aff) - }.width('100%').margin({ top: 5 }) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/customdialog.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\205\250\345\261\200UI\346\226\271\346\263\225/03.\345\233\276\347\211\207\347\274\223\345\255\230.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\205\250\345\261\200UI\346\226\271\346\263\225/03.\345\233\276\347\211\207\347\274\223\345\255\230.md" deleted file mode 100644 index 4dbeb6c4ad56cca425ce56ce8ce5afafc907be9b..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\205\250\345\261\200UI\346\226\271\346\263\225/03.\345\233\276\347\211\207\347\274\223\345\255\230.md" +++ /dev/null @@ -1,171 +0,0 @@ ---- -title: 图片缓存 -permalink: /pages/010c02020303 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:35 ---- -# 图片缓存 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从 API Version 7 开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 导入模块 - -``` -import app from '@system.app' -``` - -## 权限 - -无 - -## app.setImageCacheCount - -setImageCacheCount\(value: number\): void - -设置内存中缓存解码后图片的数量上限,提升再次加载同源图片的加载速度。如果不设置则默认为0,不进行缓存。缓存采用内置的LRU策略,新图片加载后,如果超过缓存上限,会删除最久未再次加载的缓存。建议根据应用内存需求,设置合理缓存数量,数字过大可能导致内存使用过高。 - -- 参数 - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

value

-

number

-

-

内存中解码后图片的缓存数量。

-
- -- 示例 - - ``` - // app.ets - import app from '@system.app'; - export default { - onCreate() { - app.setImageCacheCount(100) // 设置解码后图片内存缓存上限为100张 - console.info('Application onCreate') - }, - onDestroy() { - console.info('Application onDestroy') - }, - } - ``` - - -## app.setImageRawDataCacheSize - -setImageRawDataCacheSize\(value: number\): void - -设置内存中缓存解码前图片数据的大小上限,单位为字节,提升再次加载同源图片的加载速度。如果不设置则默认为0,不进行缓存。缓存采用内置的LRU策略,新图片加载后,如果解码前数据超过缓存上限,会删除最久未再次加载的图片数据缓存。建议根据应用内存需求,设置合理缓存上限,过大可能导致应用内存使用过高。 - -- 参数 - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

value

-

number

-

-

内存中解码前图片数据的缓存大小,单位为字节。

-
- -- 示例 - - ``` - // app.ets - import app from '@system.app'; - - export default { - onCreate() { - app.setImageRawDataCacheSize(104,857,600) // 设置解码前图片数据内存缓存上限为100MB - console.info('Application onCreate') - }, - onDestroy() { - console.info('Application onDestroy') - }, - } - ``` - - -## app.setImageFileCacheSize - -setImageFileCacheSize\(value: number\): void - -设置图片文件缓存的大小上限,单位为字节,提升再次加载同源图片的加载速度,特别是对网络图源、缩略图会有较明显提升。如果不设置则默认为100MB。缓存采用内置的LRU策略,新图片加载后,如果超过文件缓存上限,会按照时间由远到近删除缓存图片文件直到缓存图片大小满足缓存上限。建议根据应用实际需求,设置合理文件缓存上限,数字过大可能导致磁盘空间占用过高。 - -- 参数 - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

value

-

number

-

-

图片文件的缓存大小,单位为字节。

-
- -- 示例 - - ``` - // app.ets - import app from '@system.app'; - - export default { - onCreate() { - app.setImageFileCacheSize(209,715,200) // 设置图片文件数据缓存上限为200MB - console.info('Application onCreate') - }, - onDestroy() { - console.info('Application onDestroy') - }, - } - ``` - - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\205\250\345\261\200UI\346\226\271\346\263\225/04.\345\252\222\344\275\223\346\237\245\350\257\242.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\205\250\345\261\200UI\346\226\271\346\263\225/04.\345\252\222\344\275\223\346\237\245\350\257\242.md" deleted file mode 100644 index 8b68ee8b2356b5c7e92580e1132ce0bf87b62090..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/03.\345\205\250\345\261\200UI\346\226\271\346\263\225/04.\345\252\222\344\275\223\346\237\245\350\257\242.md" +++ /dev/null @@ -1,304 +0,0 @@ ---- -title: 媒体查询 -permalink: /pages/010c02020304 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 媒体查询 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 导入模块 - -``` -import mediaquery from '@ohos.mediaquery' -``` - -## 权限 - -无 - -## mediaquery.matchMediaSync - -matchMediaSync\(condition: string\): MediaQueryListener - -设置媒体查询的查询条件,并返回对应的监听句柄。 - -- 参数 - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

condition

-

string

-

-
- -- 返回值 - - - - - - - - - -

类型

-

说明

-

MediaQueryListener

-

媒体事件监听句柄,用于注册和去注册监听回调。

-
- -- 示例 - - ``` - listener = mediaquery.matchMediaSync('(orientation: landscape)'); //监听横屏事件 - ``` - - -## MediaQueryListener - -媒体查询的句柄,并包含了申请句柄时的首次查询结果。 - -### 属性 - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数类型

-

可读

-

可写

-

说明

-

matches

-

boolean

-

-

-

是否符合匹配条件。

-

media

-

string

-

-

-

媒体事件的匹配条件。

-
- -### on - -on\(type: 'change', callback: Callback\): void - -通过句柄向对应的查询条件注册回调,当媒体属性发生变更时会触发该回调。 - -- 参数 - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

type

-

string

-

-

必须填写字符串'change'。

-

callback

-

Callback<MediaQueryResult>

-

-

向媒体查询注册的回调

-
- -- 示例 - - 详见[off示例](#li16426122219256)。 - - -### off - -off\(type: 'change', callback?: Callback\): void - -通过句柄向对应的查询条件去注册回调,当媒体属性发生变更时不在触发指定的回调。 - -- 参数 - - - - - - - - - - - - - - - - - - -

参数名

-

类型

-

必填

-

说明

-

type

-

boolean

-

-

必须填写字符串'change'。

-

callback

-

Callback<MediaQueryResult>

-

-

需要去注册的回调,如果参数缺省则去注册该句柄下所有的回调。

-
- -- 示例 - - ``` - listener = mediaquery.matchMediaSync('(orientation: landscape)'); //监听横屏事件 - onPortrait(mediaQueryResult) { - if (mediaQueryResult.matches) { - // do something here - } else { - // do something here - } - } - listener.on('change', onPortrait) // 注册回调 - listener.off('change', onPortrait) // 去注册回调 - ``` - - -## MediaQueryResult - -### 属性 - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数类型

-

可读

-

可写

-

说明

-

matches

-

boolean

-

-

-

是否符合匹配条件。

-

media

-

string

-

-

-

媒体事件的匹配条件。

-
- -### 示例 - -``` -import mediaquery from '@ohos.mediaquery' - -let portraitFunc = null - -@Entry -@Component -struct MediaQueryExample { - @State color: string = '#DB7093' - @State text: string = 'Portrait' - listener = mediaquery.matchMediaSync('(orientation: landscape)') - - onPortrait(mediaQueryResult) { - if (mediaQueryResult.matches) { - this.color = '#FFD700' - this.text = 'Landscape' - } else { - this.color = '#DB7093' - this.text = 'Portrait' - } - } - - aboutToAppear() { - portraitFunc = this.onPortrait.bind(this) //bind current js instance - this.listener.on('change', portraitFunc) - } - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Text(this.text).fontSize(24).fontColor(this.color) - } - .width('100%').height('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/MediaQuery.gif) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/04.\351\231\204\345\275\225/01.\346\226\207\346\241\243\344\270\255\346\266\211\345\217\212\345\210\260\347\232\204\345\206\205\347\275\256\346\236\232\344\270\276\345\200\274.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/04.\351\231\204\345\275\225/01.\346\226\207\346\241\243\344\270\255\346\266\211\345\217\212\345\210\260\347\232\204\345\206\205\347\275\256\346\236\232\344\270\276\345\200\274.md" deleted file mode 100644 index 048f4c6c0e15fb8324ee85ba0e490a8162c1bfa5..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/02.ArkUI\347\273\204\344\273\266\345\217\202\350\200\203/02.\345\237\272\344\272\216TS\346\211\251\345\261\225\347\232\204\345\243\260\346\230\216\345\274\217\345\274\200\345\217\221\350\214\203\345\274\217/04.\351\231\204\345\275\225/01.\346\226\207\346\241\243\344\270\255\346\266\211\345\217\212\345\210\260\347\232\204\345\206\205\347\275\256\346\236\232\344\270\276\345\200\274.md" +++ /dev/null @@ -1,304 +0,0 @@ ---- -title: 文档中涉及到的内置枚举值 -permalink: /pages/010c02020401 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 文档中涉及到的内置枚举值 - -## Alignment枚举说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

描述

-

TopStart

-

顶部起始端。

-

Top

-

顶部横向居中。

-

TopEnd

-

顶部尾端。

-

Start

-

起始端纵向居中。

-

Center

-

横向和纵向居中。

-

End

-

尾端纵向居中。

-

BottomStart

-

底部起始端。

-

Bottom

-

底部横向居中。

-

BottomEnd

-

底部尾端。

-
- -## Axis枚举说明 - - - - - - - - - - - - -

名称

-

描述

-

Vertical

-

方向为纵向。

-

Horizontal

-

方向为横向。

-
- -## ItemAlign枚举说明 - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

描述

-

Auto

-

使用Flex容器中默认配置。

-

Start

-

元素在Flex容器中,交叉轴方向首部对齐。

-

Center

-

元素在Flex容器中,交叉轴方向居中对齐。

-

End

-

元素在Flex容器中,交叉轴方向底部对齐。

-

Stretch

-

元素在Flex容器中,交叉轴方向拉伸填充,在未设置尺寸时,拉伸到容器尺寸。

-

Baseline

-

元素在Flex容器中,交叉轴方向文本基线对齐。

-
- -## LineCapStyle枚举说明 - - - - - - - - - - - - - - - -

名称

-

描述

-

Butt

-

分割线两端为平行线。

-

Round

-

分割线两端为半圆。

-

Square

-

分割线两端为平行线。

-
- -## PlayMode枚举值说明 - - - - - - - - - - - - - - - - - - -

名称

-

描述

-

Normal

-

动画按正常播放。

-

Reverse

-

动画反向播放。

-

Alternate

-

动画在奇数次(1、3、5...)正向播放,在偶数次(2、4、6...)反向播放。

-

AlternateReverse

-

动画在奇数次(1、3、5...)反向播放,在偶数次(2、4、6...)正向播放。

-
- -## ImageRepeat枚举说明 - - - - - - - - - - - - - - - - - - -

名称

-

描述

-

X

-

只在水平轴上重复绘制图片。

-

Y

-

只在竖直轴上重复绘制图片。

-

XY

-

在两个轴上重复绘制图片。

-

NoRepeat

-

不重复绘制图片。

-
- -## TextDecorationType枚举说明 - - - - - - - - - - - - - - - - - - -

名称

-

描述

-

Underline

-

文字下划线修饰。

-

LineThrough

-

穿过文本的修饰线。

-

Overline

-

文字上划线修饰。

-

None

-

不使用文本装饰线。

-
- -## TextCase枚举说明 - - - - - - - - - - - - - - - -

名称

-

描述

-

Normal

-

保持文本原有大小写。

-

LowerCase

-

文本采用全小写。

-

UpperCase

-

文本采用全大写。

-
- -## BarState枚举说明 - - - - - - - - - - - - - - - -

名称

-

描述

-

Off

-

不显示。

-

On

-

常驻显示。

-

Auto

-

按需显示(触摸时显示,2s后消失)。

-
- diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/03.\345\272\224\347\224\250\345\274\200\345\217\221\345\214\205\347\273\223\346\236\204\350\257\264\346\230\216.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/03.\345\272\224\347\224\250\345\274\200\345\217\221\345\214\205\347\273\223\346\236\204\350\257\264\346\230\216.md" deleted file mode 100644 index cb2ba79c6ea96170679b02effc1866773500a272..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/03.\345\272\224\347\224\250\345\274\200\345\217\221\345\214\205\347\273\223\346\236\204\350\257\264\346\230\216.md" +++ /dev/null @@ -1,93 +0,0 @@ ---- -title: 应用开发包结构说明 -permalink: /pages/010c03 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 包结构说明 - -在应用开发的工程中,需要在config.json配置文件中对应用的包结构进行声明。 - - -配置文件示例如下: - - -``` -{ - "app": { - "bundleName": "com.example.myapplication", - "vendor": "example", - "version": { - "code": 1, - "name": "1.0" - }, - "apiVersion": { - "compatible": 4, - "target": 5, - "releaseType": "Beta1" - } - }, - "deviceConfig": {}, - "module": { - "package": "com.example.myapplication.entrymodule", - "name": ".MyApplication", - "deviceType": [ - "phone" - ], - "distro": { - "deliveryWithInstall": true, - "moduleName": "entry", - "moduleType": "entry" - }, - "abilities": [ - { - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ], - "name": "com.example.myapplication.entrymodule.MainAbility", - "icon": "$media:icon", - "description": "$string:mainability_description", - "label": "$string:app_name", - "type": "page", - "launchType": "standard" - } - ], - "js": [ - { - "pages": [ - "pages/index/index" - ], - "name": "default", - "window": { - "designWidth": 720, - "autoDesignWidth": false - } - } - ] - } -} -``` - - -**包结构声明需要注意以下约束:** - - -- "package"字段命名要保证在相同bundleName的应用内唯一。 - -- "abilities"字段下只能声明一个ability。 - -- "abilities"字段中ability的"name"字段命名要保证在相同bundleName的应用内唯一。 diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/04.\345\270\270\350\247\201\351\227\256\351\242\230-\350\256\276\345\244\207\345\274\200\345\217\221/01.\345\270\270\350\247\201\351\227\256\351\242\230\346\246\202\350\277\260.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/04.\345\270\270\350\247\201\351\227\256\351\242\230-\350\256\276\345\244\207\345\274\200\345\217\221/01.\345\270\270\350\247\201\351\227\256\351\242\230\346\246\202\350\277\260.md" deleted file mode 100644 index 2d8b628a561ef5b16d98eeb182834f9c9291d3d6..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/04.\345\270\270\350\247\201\351\227\256\351\242\230-\350\256\276\345\244\207\345\274\200\345\217\221/01.\345\270\270\350\247\201\351\227\256\351\242\230\346\246\202\350\277\260.md" +++ /dev/null @@ -1,151 +0,0 @@ ---- -title: 常见问题概述 -permalink: /pages/010c0401 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 常见问题概述 - -- [环境搭建](#section93289248249) - - [轻量和小型系统](#section197234983111) - -- [编译构建子系统](#section18826114693810) - - [轻量和小型系统](#section693410399) - -- [烧录](#section6556741113712) - - [轻量和小型系统](#section1029933713812) - -- [内核](#section13741125564211) - - [基础内核](#section1723365191114) - - [文件系统](#section14523145918136) - - [芯片适配](#section141541939159) - - [三方组件](#section4988163321816) - - [编译链接](#section080219574225) - -- [移植](#section129331824154313) -- [启动恢复](#section83501764443) -- [系统服务](#section19567132114455) - - [公共基础库](#section3214181711465) - - [视觉应用常见问题](#section295651815466) - - [hdc](#section178081876506) - - -常见问题主要用于帮助开发者解决在开发过程中经常出现的一类问题问题。当前提供了如下常见问题供开发者进行查询。 - -## 环境搭建 - -### 轻量和小型系统 - -- [安装hb过程中出现乱码、段错误](/pages/010c0402#section36351051193919) -- [安装hb过程中,提示"cannot import 'sysconfig' from 'distutils'"](/pages/010c0402#section48221013144011) -- [安装hb过程中,提示"module 'platform' has no attribute 'linux\_distribution'"](/pages/010c0402#section8692735427) -- [安装hb过程中,提示"Could not find a version that satisfies the requirement ohos-build"](/pages/010c0402#section8692735427) -- [安装python3过程中,提示“configure: error: no acceptable C compiler found in $PATH”](/pages/010c0402#section870082884217) -- [安装python3过程中,提示“-bash: make: command not found”](/pages/010c0402#section198707170455) -- [安装python3过程中,提示“zlib not available”](/pages/010c0402#section85401445204518) -- [安装python3过程中,提示“No module named '\_ctypes'”](/pages/010c0402#section12202694460) -- [安装 kconfiglib时,遇到lsb\_release错误](/pages/010c0402#section5803174135115) -- [Linux编译服务器终端输入不识别的命令时提示“ImportError: No module named apt\_pkg”](/pages/010c0402#section510820516515) - -## 编译构建子系统 - -### 轻量和小型系统 - -- [编译构建过程中,提示“usr/sbin/ninja: invalid option -- w”](/pages/010c0403#section67961431372) -- [编译构建过程中,提示“/usr/bin/ld: cannot find -lncurses”](/pages/010c0403#section199631617371) -- [编译构建过程中,提示“line 77: mcopy: command not found”](/pages/010c0403#section937435175) -- [编译构建过程中,提示“riscv32-unknown-elf-gcc: error trying to exec 'cc1': execvp: No such file or directory”](/pages/010c0403#section1115535018713) -- [编译构建过程中,提示“No module named 'Crypto'”](/pages/010c0403#section17982573813) -- [编译构建过程中,提示“Could not find a version that satisfies the requirement six\>=1.9.0”](/pages/010c0403#section1917790845) -- [编译构建过程中,提示“Could not find a version that satisfies the requirement six\>=1.9.0”](/pages/010c0403#section1917790845)” -- [编译构建过程中,提示找不到“-lgcc”](/pages/010c0403#section141771701647) -- [编译构建过程中,提示找不到“python”](/pages/010c0403#section51781202415) -- [编译构建过程中,提示找不到“python3”](/pages/010c0403#section1917950148) - -## 烧录 - -### 轻量和小型系统 - -- [烧写选择串口后,提示“Error: Opening COMxx: Access denied”](/pages/010c0404#section18988185615914) - -- [烧写失败](/pages/010c0404#section1370982513317) -- [串口无回显](/pages/010c0404#section183421944953) -- [Windows电脑与单板网络连接失败](/pages/010c0404#section1215410450215) - -## 内核 - -### 基础内核 - -- [LiteOS-A和LiteOS-M内核对外API的差异](/pages/010c0405#section447571122918) -- [如何分析线程栈溢出](/pages/010c0405#section8623141711293) - -### 文件系统 - -- [Hi3516开源板以写的模式打开同一个文件失败(LiteOS-A)](/pages/010c0405#section517972255311) - -### 芯片适配 - -- [LiteOS内核已支持哪些硬件平台](/pages/010c0405#section868413518533) -- [LiteOS内核已支持哪几款芯片架构](/pages/010c0405#section1131661465417) - -### 三方组件 - -- [OpenHarmony已支持哪些三方组件](/pages/010c0405#section74138185411) -- [在OpenHarmony上使用OpenSSL,出现秘钥长度校验不正确](/pages/010c0405#section10564614135516) -- [setsockopt是否支持SO\_RCVBUF和SO\_SNDBUF选项](/pages/010c0405#section2093373215556) - -### 编译链接 - -- [Arm Linux开发的应用程序,如何在LiteOS-A上运行](/pages/010c0405#section1164175713557) -- [OpenHarmony在什么系统下编译,使用什么编译器](/pages/010c0405#section132287223567) -- [LiteOS-M上使用单独编译成静态库的三方组件,出现三方组件中的全局变量值不正确,或调用三方组件的函数后系统卡死](/pages/010c0405#section15189154225619) -- [LiteOS-A生成目标可执行文件,提示 use VFP register arguments,xxx.o does not](/pages/010c0405#section193571012578) -- [clock\_gettime接口获取的时间打印不对](/pages/010c0405#section8973152015717) - -## 移植 - -- [如何将用户的堆内存挂载进内核](/pages/010c0406#section21471536184914) - -## 启动恢复 - -- [系统启动过程中打印“parse failed!”错误后停止启动](/pages/010c0407#section835662214302) -- [系统启动过程未结束就自动重启,如此反复持续](/pages/010c0407#section3857921143117) -- [参数正确的情况下调用SetParameter/GetParameter返回失败](/pages/010c0407#section548818116328) - -## 系统服务 - -### 公共基础库 - -- [LiteOS-A内核\(Hi3516、Hi3518平台\)KV存储路径设置错误,导致KV存储运行失败](/pages/010c0408#section16520347131511) - -### 视觉应用常见问题 - -- [是否存在一个全局变量,所有的页面都可以访问?](/pages/010c0408#section187297991718) -- [如何获取dom中的元素](/pages/010c0408#section1833493719175) -- [如何在页面间传值?](/pages/010c0408#section184283812183) -- [list如何滚动到某个item?](/pages/010c0408#section11897734131811) -- [text支持多行吗?](/pages/010c0408#section5872656121814) -- [为什么控件不显示?](/pages/010c0408#section7397125317107) -- [如何实现页面滑动?](/pages/010c0408#section338794422010) -- [Left、Top为什么不生效?](/pages/010c0408#section2597193611217) -- [动态绑定为什么不生效?](/pages/010c0408#section6939050172115) -- [如何实现相对定位和绝对定位?](/pages/010c0408#section5547311192215) -- [如何控制控件的显示与隐藏?](/pages/010c0408#section16107113352213) -- [使用Margin时,有什么注意事项?](/pages/010c0408#section1524910142314) -- [使用事件订阅时,有什么注意事项?](/pages/010c0408#section1537132012231) -- [使用动态绑定时,有什么注意事项?](/pages/010c0408#section96561452236) -- [swiper loop属性如何生效?](/pages/010c0408#section690166112414) -- [使用数组时,有什么注意事项?](/pages/010c0408#section1554552822414) - -### hdc - -- [hdc\_std连接不到设备](/pages/010c0408#section1965012223257) -- [hdc\_std运行不了](/pages/010c0408#section1157575212515) - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/04.\345\270\270\350\247\201\351\227\256\351\242\230-\350\256\276\345\244\207\345\274\200\345\217\221/02.\347\216\257\345\242\203\346\220\255\345\273\272\345\270\270\350\247\201\351\227\256\351\242\230.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/04.\345\270\270\350\247\201\351\227\256\351\242\230-\350\256\276\345\244\207\345\274\200\345\217\221/02.\347\216\257\345\242\203\346\220\255\345\273\272\345\270\270\350\247\201\351\227\256\351\242\230.md" deleted file mode 100644 index 1819e1cde2714f6608732b57cfbfd546700fdaf0..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/04.\345\270\270\350\247\201\351\227\256\351\242\230-\350\256\276\345\244\207\345\274\200\345\217\221/02.\347\216\257\345\242\203\346\220\255\345\273\272\345\270\270\350\247\201\351\227\256\351\242\230.md" +++ /dev/null @@ -1,252 +0,0 @@ ---- -title: 环境搭建常见问题 -permalink: /pages/010c0402 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 环境搭建常见问题 - -- [轻量和小型系统](#section1742119306399) - - [安装hb过程中,出现乱码、段错误](#section36351051193919) - - [安装hb过程中,提示"cannot import 'sysconfig' from 'distutils'"](#section48221013144011) - - [安装hb过程中,提示"module 'platform' has no attribute 'linux\_distribution'"](#section10307193044111) - - [安装hb过程中,提示"Could not find a version that satisfies the requirement ohos-build"](#section8692735427) - - [安装python3过程中,提示“configure: error: no acceptable C compiler found in $PATH”](#section870082884217) - - [安装python3过程中,提示“-bash: make: command not found”](#section198707170455) - - [安装python3过程中,提示“zlib not available”](#section85401445204518) - - [安装python3过程中,提示“No module named '\_ctypes'”](#section12202694460) - - [安装 kconfiglib时,遇到lsb\_release错误](#section5803174135115) - - [Linux编译服务器终端输入不识别的命令时提示“ImportError: No module named apt\_pkg”](#section510820516515) - - -## 轻量和小型系统 - -### 安装hb过程中,出现乱码、段错误 - -- **现象描述** - - 执行“python3 -m pip install --user ohos-build”出现乱码、段错误(segmentation fault)。 - - -- **可能原因** - - pip版本过低。 - -- **解决办法** - - 执行如下命令升级pip。 - - ``` - python3 -m pip install -U pip - ``` - - -### 安装hb过程中,提示"cannot import 'sysconfig' from 'distutils'" - -- **现象描述** - - 执行“python3 -m pip install --user ohos-build”提示"cannot import 'sysconfig' from 'distutils'"。 - - -- **可能原因** - - 缺少distutils模块。 - -- **解决办法** - - 执行如下命令安装。 - - ``` - sudo apt-get install python3.8-distutils - ``` - - -### 安装hb过程中,提示"module 'platform' has no attribute 'linux\_distribution'" - -- **现象描述** - - 执行“python3 -m pip install --user ohos-build”提示"module 'platform' has no attribute 'linux\_distribution'"。 - - -- **可能原因** - - python3 pip安装兼容性问题。 - -- **解决办法** - - 执行如下命令重新安装pip。 - - ``` - sudo apt remove python3-pip - curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py - python get-pip.py - ``` - - -### 安装hb过程中,提示"Could not find a version that satisfies the requirement ohos-build" - -- **现象描述** - - 执行“python3 -m pip install --user ohos-build”提示"Could not find a version that satisfies the requirement ohos-build" - - -- **可能原因** - - 可能是网络环境较差导致的安装失败。 - -- **解决办法** - 1. 请检查网络连接是否正常。如果网络有问题,请修复网络问题后重新安装。 - 2. 若网络正常,请尝试指定临时pypi源的方式安装: - - ``` - python3 -m pip install -i https://pypi.tuna.tsinghua.edu.cn/simple ohos-build - ``` - - - -### 安装python3过程中,提示“configure: error: no acceptable C compiler found in $PATH” - -- **现象描述** - - 安装python3过程中出现以下错误: - - ``` - configure: error: no acceptable C compiler found in $PATH. See 'config.log' for more details - ``` - -- **可能原因** - - 环境中未安装“gcc”。 - -- **解决办法** - - 1、通过命令“apt-get install gcc”在线安装。 - - 2、完成后,重新安装python3。 - - -### 安装python3过程中,提示“-bash: make: command not found” - -- **现象描述** - - 安装python3过程中出现以下错误: - - ``` - -bash: make: command not found - ``` - -- **可能原因** - - 环境中未安装“make”。 - -- **解决办法** - - 1、通过命令“apt-get install make”在线安装。 - - 2、完成后,重新安装python3。 - - -### 安装python3过程中,提示“zlib not available” - -- **现象描述** - - 安装python3过程中出现以下错误: - - ``` - zipimport.ZipImportError: can't decompress data; zlib not available - ``` - -- **可能原因** - - 环境中未安装“zlib”。 - -- **解决办法** - - 方法1:通过命令“apt-get install zlib”在线安装。 - - 方法2:如果软件源中没有该软件,请从“www.zlib.net”下载版本代码,并离线安装。 - - ![](/images/device-dev/faqs/figures/download-zlib.png) - - 完成下载后,通过以下命令安装: - - ``` - # tar xvf zlib-1.2.11.tar.gz - # cd zlib-1.2.11 - # ./configure - # make && make install - ``` - - 完成后,重新安装python3。 - - -### 安装python3过程中,提示“No module named '\_ctypes'” - -- **现象描述** - - 安装python3过程中出现以下错误: - - ``` - ModuleNotFoundError:No module named ‘_ctypes’ - ``` - - -- **可能原因** - - 环境中未安装“libffi”和“libffi-devel”。 - - -- **解决办法** - - 1、通过命令“apt-get install libffi\* -y”,在线安装。 - - 2、完成后,重新安装python3。 - - -### 安装 kconfiglib时,遇到lsb\_release错误 - -- **现象描述** - - 安装kconfiglib过程中遇到如下错误打印: - - ``` - subprocess.CalledProcessError: Command '('lsb_release', '-a')' returned non-zero exit status 1. - ``` - -- **可能原因** - - lsb\_release模块基于的python版本与现有python版本不一致 - -- **解决办法** - - 执行"find / -name lsb\_release",找到lsb\_release位置并删除,如:"sudo rm -rf /usr/bin/lsb\_release" - - -### Linux编译服务器终端输入不识别的命令时提示“ImportError: No module named apt\_pkg” - -- **现象描述** - - Linux编译服务器终端输入不识别的命令时,提示"ImportError: No module named apt\_pkg" - - -- **可能原因** - - python3 apt安装兼容性问题。 - -- **解决办法** - - 执行如下命令重新安装python3-apt。 - - ``` - sudo apt-get remove python3-apt - sudo apt-get install python3-apt - ``` - - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/04.\345\270\270\350\247\201\351\227\256\351\242\230-\350\256\276\345\244\207\345\274\200\345\217\221/03.\347\274\226\350\257\221\346\236\204\345\273\272\345\255\220\347\263\273\347\273\237\345\270\270\350\247\201\351\227\256\351\242\230.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/04.\345\270\270\350\247\201\351\227\256\351\242\230-\350\256\276\345\244\207\345\274\200\345\217\221/03.\347\274\226\350\257\221\346\236\204\345\273\272\345\255\220\347\263\273\347\273\237\345\270\270\350\247\201\351\227\256\351\242\230.md" deleted file mode 100644 index 05377de52d1242728ccb464c56d8fd460cbb4f1b..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/04.\345\270\270\350\247\201\351\227\256\351\242\230-\350\256\276\345\244\207\345\274\200\345\217\221/03.\347\274\226\350\257\221\346\236\204\345\273\272\345\255\220\347\263\273\347\273\237\345\270\270\350\247\201\351\227\256\351\242\230.md" +++ /dev/null @@ -1,264 +0,0 @@ ---- -title: 编译构建子系统常见问题 -permalink: /pages/010c0403 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 编译构建子系统常见问题 - -- [轻量和小型系统](#section78686441462) - - [编译构建过程中,提示“usr/sbin/ninja: invalid option -- w”](#section67961431372) - - [编译构建过程中,提示“/usr/bin/ld: cannot find -lncurses”](#section199631617371) - - [编译构建过程中,提示“line 77: mcopy: command not found”](#section937435175) - - [编译构建过程中,提示“riscv32-unknown-elf-gcc: error trying to exec 'cc1': execvp: No such file or directory”](#section1115535018713) - - [编译构建过程中,提示“No module named 'Crypto'”](#section17982573813) - - [编译构建过程中,提示“xx.sh : xx unexpected operator”](#section53663205819) - - [编译构建过程中,提示“Could not find a version that satisfies the requirement six\>=1.9.0”](#section1917790845) - - [编译构建过程中,提示找不到“-lgcc”](#section141771701647) - - [编译构建过程中,提示找不到“python”](#section51781202415) - - [编译构建过程中,提示找不到“python3”](#section1917950148) - - -## 轻量和小型系统 - -### 编译构建过程中,提示“usr/sbin/ninja: invalid option -- w” - -- **现象描述:** - - 编译失败,提示“usr/sbin/ninja: invalid option -- w”。 - -- **可能原因:** - - 编译环境中ninja版本太低,不支持--w选项。 - -- **解决办法:** - - 卸载环境中ninja和gn,按照[获取工具](/pages/010b02)。 - - -### 编译构建过程中,提示“/usr/bin/ld: cannot find -lncurses” - -- **现象描述:** - - 编译失败,提示“/usr/bin/ld: cannot find -lncurses”。 - -- **可能原因:** - - 编译环境ncurses库缺失。 - -- **解决办法:** - - ``` - sudo apt-get install lib32ncurses5-dev - ``` - - -### 编译构建过程中,提示“line 77: mcopy: command not found” - -- **现象描述:** - - ​编译失败,提示“line 77: mcopy: command not found”。 - -- **可能原因:** - - 编译环境未安装mcopy。 - -- **解决办法:** - - ``` - ​sudo apt-get install dosfstools mtools - ``` - - -### 编译构建过程中,提示“riscv32-unknown-elf-gcc: error trying to exec 'cc1': execvp: No such file or directory” - -- **现象描述:** - - 编译失败,提示“riscv32-unknown-elf-gcc: error trying to exec 'cc1': execvp: No such file or directory”。 - -- ​**可能原因:** - - 当前用户对riscv编译器路径下的文件访问权限不够。 - -- ​**解决办法:** - - 查询gcc\_riscv32所在目录。 - - ``` - which riscv32-unknown-elf-gcc - ``` - - 使用chmod命令修改目录权限为755。 - - -### 编译构建过程中,提示“No module named 'Crypto'” - -- **现象描述:** - - 编译失败,提示“No module named 'Crypto'”。 - -- **可能原因:** - - python3未安装Crypto。 - -- **解决办法:** - 1. 查询Python版本号。 - - ``` - python3 --version - ``` - - 2. 需使用python3.7以上版本,然后安装pycryptodome。 - - ``` - sudo pip3 install pycryptodome - ``` - - - -### 编译构建过程中,提示“xx.sh : xx unexpected operator” - -- **现象描述:** - - 编译失败:“xx.sh \[: xx unexpected operator”。 - -- **可能原因:** - - 编译环境shell不是bash。 - -- **解决办法:** - - ``` - sudo rm -rf /bin/sh - sudo ln -s /bin/bash /bin/sh - ``` - - -### 编译构建过程中,提示“Could not find a version that satisfies the requirement six\>=1.9.0” - -- **现象描述** - - 编译构建过程中出现以下错误: - - ``` - Could not find a version that satisfies the requirement six>=1.9.0 - ``` - - -- **可能原因** - - 环境中未安装合适的“six”。 - - -- **解决办法** - - 方法1:通过命令“pip3 install six”,在线安装。 - - 方法2:离线安装 - - 通过网页[https://pypi.org/project/six/\#files](https://pypi.org/project/six/#files),下载安装包。 - - ![](/images/device-dev/faqs/figures/download-six.png) - - 将源码放置在Linux服务器中,并安装“pip3 install six-1.14.0-py2.py3-none-any.whl”。 - - 完成上述安装后,重新构建。 - - -### 编译构建过程中,提示找不到“-lgcc” - -- **现象描述** - - 编译构建过程中出现以下错误: - - ``` - riscv32-unknown-elf-ld: cannot find -lgcc - ``` - - -- **可能原因** - - 交叉编译器gcc\_riscv32的PATH添加错误,如下,在"bin"后多添加了一个“/”,应该删除。 - - ``` - ~/gcc_riscv32/bin/:/data/toolchain/ - ``` - - -- **解决办法** - - 重新修改gcc\_riscv32的PATH,将多余的“/”删除。 - - ``` - ~/gcc_riscv32/bin:/data/toolchain/ - ``` - - -### 编译构建过程中,提示找不到“python” - -- **现象描述** - - 编译构建过程中出现以下错误: - - ``` - -bash: /usr/bin/python: No such file or directory - ``` - - -- **可能原因**1 - - 没有装python。 - -- **解决办法** - - 请使用如下命令安装Python,下方以Python3.8为例。 - ``` - sudo apt-get install python3.8 - ``` - -- **可能原因2** - usr/bin目录下没有python软链接 - - ![](/images/device-dev/faqs/figures/reason-no-python-soft-link.png) - -- **解决办法** - - 请运行以下命令添加软链接: - - ``` - # cd /usr/bin/ - # which python3 - # ln -s /usr/local/bin/python3 python - # python --version - ``` - - 例: - - ![](/images/device-dev/faqs/figures/solution-add-soft-link.png) - - -### 编译构建过程中,提示找不到“python3” - -- **现象描述** - - 安装python3过程中出现以下错误: - ``` - configure: error: no acceptable C compiler found in $PATH. See 'config.log' for more details - ``` - -- **可能原因** - - 环境中未安装“gcc”。 - -- **解决办法** - - 1. 通过命令“apt-get install gcc”在线安装。 - 2. 完成后,重新安装python3。 - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/04.\345\270\270\350\247\201\351\227\256\351\242\230-\350\256\276\345\244\207\345\274\200\345\217\221/04.\347\203\247\345\275\225\345\270\270\350\247\201\351\227\256\351\242\230.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/04.\345\270\270\350\247\201\351\227\256\351\242\230-\350\256\276\345\244\207\345\274\200\345\217\221/04.\347\203\247\345\275\225\345\270\270\350\247\201\351\227\256\351\242\230.md" deleted file mode 100644 index da3739f503ba8ab1960fac6237ffc6705a1d8af6..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/04.\345\270\270\350\247\201\351\227\256\351\242\230-\350\256\276\345\244\207\345\274\200\345\217\221/04.\347\203\247\345\275\225\345\270\270\350\247\201\351\227\256\351\242\230.md" +++ /dev/null @@ -1,142 +0,0 @@ ---- -title: 烧录常见问题 -permalink: /pages/010c0404 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 烧录常见问题 - -- [轻量和小型系统](#section278314413530) - - [烧写选择串口后,提示“Error: Opening COMxx: Access denied”](#section18988185615914) - - [烧写失败](#section1370982513317) - - [串口无回显](#section183421944953) - - [Windows电脑与单板网络连接失败](#section1215410450215) - - -## 轻量和小型系统 - -### 烧写选择串口后,提示“Error: Opening COMxx: Access denied” - -- **现象描述** - - 点击烧写并选择串口后,出现“Error: Opening COMxx: Access denied”。 - - ![](/images/device-dev/faqs/figures/Failed-to-open-the-serial-port.png) - -- **可能原因** - - 串口已经被占用。 - -- 解决方法 - - 检查主机中可能占用该端口的工具,关闭即可。若是当前工具占用,可按以下步骤排查并关闭: - - 1. 排查终端窗口列表,检查是否被monitor或其他终端占用。 - - ![](/images/device-dev/faqs/figures/terminal-list.png) - - 2. 找到占用,点击垃圾桶图标,关闭占用。 - - -### 烧写失败 - -- **现象描述** - - 点击烧写并选择串口后,出现无法烧写的情况。 - -- **可能原因** - - 安装IDE插件DevEco后未重启。 - -- **解决方法** - - 重启IDE。 - - -### 串口无回显 - -- **现象描述** - - 串口显示已连接,重启单板后,回车无任何回显。 - -- **可能原因1** - - 串口连接错误。 - -- **解决办法** - - 修改串口号。 - - 请查看设备管理器,确认连接单板的串口与终端中连接串口是否一致,若不一致,请按镜像运行修改串口号。 - - -- **可能原因2** - - 单板U-boot被损坏。 - -- **解决办法** - - 烧写U-boot。 - - 若上述步骤依旧无法连接串口,可能由于单板U-boot损坏,按下述步骤烧写U-boot。 - - -1. 获取引导文件U-boot。 - - >![](/images/device-dev/public_sys-resources/icon-notice.gif) **须知:** - >单板的U-boot文件请在开源包中获取: - >Hi3516DV300:device\\hisilicon\\hispark\_taurus\\sdk\_liteos\\uboot\\out\\boot\\u-boot-hi3516dv300.bin - >Hi3518EV300:device\\hisilicon\\hispark\_aries\\sdk\_liteos\\uboot\\out\\boot\\u-boot-hi3518ev300.bin - -2. 根据USB烧写步骤烧写U-boot文件。 - - 按照[Hi3516系列USB烧写步骤](https://device.harmonyos.com/cn/docs/ide/user-guides/hi3516_upload-0000001052148681)/[Hi3518系列USB烧写步骤](https://device.harmonyos.com/cn/docs/ide/user-guides/hi3518_upload-0000001057313128)中描述的USB烧写方法,选择对应单板的U-boot文件进行烧写。 - -3. 烧写完成后,登录串口如下图所示。 - - **图 1** U-boot烧写完成串口显示图 - ![](/images/device-dev/faqs/figures/U-boot烧写完成串口显示图.png "U-boot烧写完成串口显示图") - - -### Windows电脑与单板网络连接失败 - -- **现象描述** - - 点击烧写并选择串口后,无法获取文件。 - - **图 2** 网络不通,Hi3516单板无法获取文件 - ![](/images/device-dev/faqs/figures/网络不通-Hi3516单板无法获取文件.png "网络不通-Hi3516单板无法获取文件") - -- **可能原因** - - 单板网络与Windows电脑不联通。 - - Windows电脑防火墙未允许Visual Studio Code联网。 - -- **解决方法** - -1. 检查网线是否连接。 -2. 点击Windows防火墙。 - - ![](/images/device-dev/faqs/figures/hi3516-network-and-firewall-setting.png) - -3. 点击“允许应用通过防火墙”。 - - ![](/images/device-dev/faqs/figures/hi3516-firewall-and-network-protection.png) - -4. 查找Visual Studio Code应用。 - - ![](/images/device-dev/faqs/figures/hi3516-selecting-the-visual-studio-code-application.png) - -5. 勾选Visual Studio Code的专用和公用网络的访问权限。 - - ![](/images/device-dev/faqs/figures/hi3516-allowing-the-visual-studio-code-application-to-access-the-network.png) - - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/04.\345\270\270\350\247\201\351\227\256\351\242\230-\350\256\276\345\244\207\345\274\200\345\217\221/05.\345\206\205\346\240\270\345\270\270\350\247\201\351\227\256\351\242\230.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/04.\345\270\270\350\247\201\351\227\256\351\242\230-\350\256\276\345\244\207\345\274\200\345\217\221/05.\345\206\205\346\240\270\345\270\270\350\247\201\351\227\256\351\242\230.md" deleted file mode 100644 index 1d4a2809ceb273195c8534cfb9d72e708d2717d4..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/04.\345\270\270\350\247\201\351\227\256\351\242\230-\350\256\276\345\244\207\345\274\200\345\217\221/05.\345\206\205\346\240\270\345\270\270\350\247\201\351\227\256\351\242\230.md" +++ /dev/null @@ -1,105 +0,0 @@ ---- -title: 内核常见问题 -permalink: /pages/010c0405 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 内核常见问题 - -- [基础内核](#section263912372168) - - [LiteOS-A和LiteOS-M内核对外API的差异](#section447571122918) - - [如何分析线程栈溢出](#section8623141711293) - -- [文件系统](#section098519592162) - - [Hi3516开源板以写的模式打开同一个文件失败(LiteOS-A)](#section517972255311) - - [LiteOS内核已支持哪些硬件平台](#section868413518533) - - [LiteOS内核已支持哪几款芯片架构](#section1131661465417) - -- [三方组件](#section971818231178) - - [OpenHarmony已支持哪些三方组件](#section74138185411) - - [在OpenHarmony上使用OpenSSL,出现秘钥长度校验不正确](#section10564614135516) - - [setsockopt是否支持SO\_RCVBUF和SO\_SNDBUF选项](#section2093373215556) - -- [编译链接](#section10955302179) - - [Arm Linux开发的应用程序,OpenHarmony如何在LiteOS-A上运行](#section1164175713557) - - [OpenHarmony在什么系统下编译,使用什么编译器](#section132287223567) - - [LiteOS-M上使用单独编译成静态库的三方组件,出现三方组件中的全局变量值不正确,或调用三方组件的函数后系统卡死](#section15189154225619) - - [LiteOS-A生成目标可执行文件时,提示 use VFP register arguments,xxx.o does not](#section193571012578) - - [clock\_gettime接口获取的时间打印不对](#section8973152015717) - - -## 基础内核 - -### LiteOS-A和LiteOS-M内核对外API的差异 - -基础内核API存在差异,但是LiteOS-A提供标准POSIX接口,LiteOS-M提供标准POSIX和CMSIS接口。如果要支持跨平台,三方适配建议使用POSIX等标准接口。 - -### 如何分析线程栈溢出 - -**问题现象** - -系统异常,提示CURRENT task xxx stack overflow! - -**解决措施** - -1. 创建xxx线程的时候成倍加大栈空间,多次尝试如果问题不复现,则说明任务栈不够,需要调整; -2. 如果成倍加大线程栈,问题依旧复现,则排查xxx线程中是否定义超大数组,或者流程是否存在递归调用; -3. 确认无前述问题,则需要排查是否存在踩内存的情况。 - -## 文件系统 - -### Hi3516开源板以写的模式打开同一个文件失败(LiteOS-A) - -Hi3516开源板使用FAT文件系统,不允许该操作。 - -### LiteOS内核已支持哪些硬件平台 - -开源版本LiteOS-A已支持Hi3516/Hi3518开发板;LiteOS-M已支持Hi3861开发板、STM32F103、野火挑战者STM32F429IGTb、Nucleo\_f767zi等,详细查看kernel/liteos\_m目录下的README\_zh.md文件。 - -### LiteOS内核已支持哪几款芯片架构 - -LiteOS-M已支持risc-v、Cortex-m3\\m4\\m7\\m33、arm9,待支持c-sky、xtensa;LiteOS-A已支持armv7-a,待支持armv8-a,请关注开源社区更新。 - -## 三方组件 - -### OpenHarmony已支持哪些三方组件 - -已提供mbedtls、lwip等开源组件和三方库,可以直接使用;另外提供标准的POSIX接口,可以自行适配。 - -### 在OpenHarmony上使用OpenSSL,出现秘钥长度校验不正确 - -OpenSSL编译选项中要注意架构类型(ARM,X86等)和系统位数(32、64位)是否选择正确。 - -### setsockopt是否支持SO\_RCVBUF和SO\_SNDBUF选项 - -不支持。 - -## 编译链接 - -### Arm Linux开发的应用程序,OpenHarmony如何在LiteOS-A上运行 - -需要用开源版本提供的交叉编译器重新编译应用程序,才可以运行。 - -### OpenHarmony在什么系统下编译,使用什么编译器 - -LiteOS-A在linux环境进行编译,使用LLVM编译器;LiteOS-M在Linux或Windows环境进行编译,使用IAR、Keil、GCC等编译工具。 - -### LiteOS-M上使用单独编译成静态库的三方组件,出现三方组件中的全局变量值不正确,或调用三方组件的函数后系统卡死 - -检查三方组件编译选项中是否有-fPIE -fpie -fPIC -fpic等地址无关编译选项,如果有,则去掉,重新编译成库使用。 - -### LiteOS-A生成目标可执行文件时,提示 use VFP register arguments,xxx.o does not - -请确认xxx.o编译时是否添加-mfloat-abi=xxx -mcpu=xxx -mfpu=xxx编译选项,若没有,则需要添加。 - -### clock\_gettime接口获取的时间打印不对 - -struct timespec结构中tv\_sec为time\_t,而time\_t为long long类型,打印控制符为%lld,请确认实际打印控制符是否正确。 - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/04.\345\270\270\350\247\201\351\227\256\351\242\230-\350\256\276\345\244\207\345\274\200\345\217\221/06.\347\247\273\346\244\215\345\270\270\350\247\201\351\227\256\351\242\230.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/04.\345\270\270\350\247\201\351\227\256\351\242\230-\350\256\276\345\244\207\345\274\200\345\217\221/06.\347\247\273\346\244\215\345\270\270\350\247\201\351\227\256\351\242\230.md" deleted file mode 100644 index fe08b2c6f3635716ebb8191dea73068738ecab40..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/04.\345\270\270\350\247\201\351\227\256\351\242\230-\350\256\276\345\244\207\345\274\200\345\217\221/06.\347\247\273\346\244\215\345\270\270\350\247\201\351\227\256\351\242\230.md" +++ /dev/null @@ -1,52 +0,0 @@ ---- -title: 移植常见问题 -permalink: /pages/010c0406 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 移植常见问题 - -- [如何将用户的堆内存挂载进内核](#section21471536184914) - -## 如何将用户的堆内存挂载进内核 - -- 内核堆内存配置的相关宏如下,用户可根据实际情况,在target\_config.h中配置: - -**表 1** 内核堆内存配置相关宏 - - - - - - - - - - - - - - - - -

宏名称

-

描述

-

LOSCFG_SYS_EXTERNAL_HEAP

-

这个宏决定系统是使用内核的内部堆内存还是用户的堆内存,默认为0(即使用内部的堆内存),大小为0x10000;如果用户需要基于外部的堆内存,那么可以将该宏设置为1。

-

LOSCFG_SYS_HEAP_ADDR

-

内核堆内存的起始地址。

-

LOSCFG_SYS_HEAP_SIZE

-

内核堆内存的大小,即LOSCFG_SYS_HEAP_ADDR指定的内存块大小。

-
- -- 注意事项: - -指定的堆内存范围务必保证没有其他模块使用,避免踩内存,破坏堆内存功能。 - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/04.\345\270\270\350\247\201\351\227\256\351\242\230-\350\256\276\345\244\207\345\274\200\345\217\221/07.\345\220\257\345\212\250\346\201\242\345\244\215\345\270\270\350\247\201\351\227\256\351\242\230.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/04.\345\270\270\350\247\201\351\227\256\351\242\230-\350\256\276\345\244\207\345\274\200\345\217\221/07.\345\220\257\345\212\250\346\201\242\345\244\215\345\270\270\350\247\201\351\227\256\351\242\230.md" deleted file mode 100644 index 634172ab8235c255792e421e515119871a034f11..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/04.\345\270\270\350\247\201\351\227\256\351\242\230-\350\256\276\345\244\207\345\274\200\345\217\221/07.\345\220\257\345\212\250\346\201\242\345\244\215\345\270\270\350\247\201\351\227\256\351\242\230.md" +++ /dev/null @@ -1,70 +0,0 @@ ---- -title: 启动恢复常见问题 -permalink: /pages/010c0407 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 启动恢复常见问题 - -- [系统启动过程中打印“parse failed!”错误后停止启动](#section835662214302) -- [系统启动过程未结束就自动重启,如此反复持续](#section3857921143117) -- [参数正确的情况下调用SetParameter/GetParameter返回失败](#section548818116328) - -## 系统启动过程中打印“parse failed!”错误后停止启动 - -**现象描述** - -系统启动过程中,打印“\[Init\] InitReadCfg, parse failed! please check file /etc/init.cfg format.”错误,启动过程停止,如下图所示: - -**图 1** 运行报错图 -![](/images/device-dev/faqs/figures/运行报错图.png "运行报错图") - -**可能原因** - -修改init.cfg文件时,漏掉或多加了逗号或括号等,导致init.cfg文件的json格式被破坏。 - -**解决办法** - -仔细检查init.cfg文件,确保其格式符合json格式要求。 - -## 系统启动过程未结束就自动重启,如此反复持续 - -**现象描述** - -镜像烧写完成后系统启动,启动过程未完成即自动重新启动,如此反复持续。 - -**可能原因** - -被init启动的服务都有一个叫做“importance”的属性(详见[第2章表3](/pages/01050e02)描述)。 - -- 当该属性为0时,表示若当前服务进程退出,init不需要重启单板。 -- 当该属性为1时,表示若当前服务进程退出,init需要重启单板。 - -因此出现上述现象的可能原因:有“importance”属性为1的服务在每次启动的过程中都会退出(可能是进程崩溃或出错自动退出),导致init进程自动重启单板。 - -**解决办法** - -1. 需要通过日志确认崩溃或报错退出的服务,并解决其崩溃/报错的问题,然后重新烧写镜像即可。 -2. 也可以将崩溃/报错退出的服务的“importance”属性改为0,然后重新烧写镜像,这样即使其退出,init也不会重启单板。 - -## 参数正确的情况下调用SetParameter/GetParameter返回失败 - -**现象描述** - -在各参数正确的情况下调用SetParameter/GetParameter返回失败。 - -**可能原因** - -程序对SetParameter/GetParameter这两个接口做了权限校验,在各参数正确的情况下调用SetParameter/GetParameter返回操作失败,很有可能是调用者的uid大于1000,没有调用权限。 - -**解决办法** - -无需处理 - diff --git "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/04.\345\270\270\350\247\201\351\227\256\351\242\230-\350\256\276\345\244\207\345\274\200\345\217\221/08.\347\263\273\347\273\237\345\272\224\347\224\250\345\270\270\350\247\201\351\227\256\351\242\230.md" "b/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/04.\345\270\270\350\247\201\351\227\256\351\242\230-\350\256\276\345\244\207\345\274\200\345\217\221/08.\347\263\273\347\273\237\345\272\224\347\224\250\345\270\270\350\247\201\351\227\256\351\242\230.md" deleted file mode 100644 index e19414f185bd5aa5c3eff05eaa9966caa65200e8..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/12.\345\217\202\350\200\203/04.\345\270\270\350\247\201\351\227\256\351\242\230-\350\256\276\345\244\207\345\274\200\345\217\221/08.\347\263\273\347\273\237\345\272\224\347\224\250\345\270\270\350\247\201\351\227\256\351\242\230.md" +++ /dev/null @@ -1,224 +0,0 @@ ---- -title: 系统应用常见问题 -permalink: /pages/010c0408 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 系统应用常见问题 - -- [公共基础库常见问题](#section639433461512) - - [1.LiteOS-A内核\(Hi3516、Hi3518平台\)KV存储路径设置错误,导致KV存储运行失败](#section16520347131511) - -- [视觉应用常见问题](#section787718474161) - - [是否存在一个全局变量,所有的页面都可以访问?](#section187297991718) - - [如何获取dom中的元素](#section1833493719175) - - [如何在页面间传值?](#section184283812183) - - [list如何滚动到某个item?](#section11897734131811) - - [text支持多行吗?](#section5872656121814) - - [为什么控件不显示?](#section7397125317107) - - [如何实现页面滑动?](#section338794422010) - - [Left、Top为什么不生效?](#section2597193611217) - - [动态绑定为什么不生效?](#section6939050172115) - - [如何实现相对定位和绝对定位?](#section5547311192215) - - [如何控制控件的显示与隐藏?](#section16107113352213) - - [使用Margin时,有什么注意事项?](#section1524910142314) - - [使用事件订阅时,有什么注意事项?](#section1537132012231) - - [使用动态绑定时,有什么注意事项?](#section96561452236) - - [swiper loop属性如何生效?](#section690166112414) - - [使用数组时,有什么注意事项?](#section1554552822414) - -- [hdc类问题](#section412357182518) - - [hdc\_std连接不到设备](#section1965012223257) - - [hdc\_std运行不了](#section1157575212515) - - -## 公共基础库常见问题 - -### 1.LiteOS-A内核\(Hi3516、Hi3518平台\)KV存储路径设置错误,导致KV存储运行失败 - -**现象描述** - -LiteOS-A内核\(Hi3516、Hi3518平台\)直接调用KV存储提供的接口,各参数正常的情况下,编译可执行程序运行失败。 - -**可能原因** - -直接运行编译出的可执行文件,没有将程序基于AbilityKit转换成应用,不能由BMS在应用安装时正确设置应用数据存储路径,导致KV存储运行失败。 - -**解决办法** - -显示调用KV存储的UtilsSetEnv接口,设置数据存储路径。 - -``` -UtilsSetEnv("/storage/com.huawei.kv"); -``` - -## 视觉应用常见问题 - -### 是否存在一个全局变量,所有的页面都可以访问? - -当前框架中不存在所有Page都可以访问的全局变量。 - -### 如何获取dom中的元素 - -如何获取dom中的元素? - -通过ref属性获取dom中的元素,详细示例如下图所示;获取的元素只能使用它的方法,不能改变属性。 - -``` - -
- - -
- -/* index.js */ -export default { - data: { - images:[ - {src:"common/frame1.png"}, - {src:"common/frame2.png"}, - {src:"common/frame3.png"} - ] - }, - handleClick(){ - //通过$refs属性获取对应的组件,在hml中,组件的ref属性要设置为animator - const animator = this.$refs.animator; - const state = animator.getState(); - if(state == "paused"){ - animator.resume(); - }else if(state == "stopped"){ - animator.start(); - }else{ - animator.pause(); - } - } -} -``` - -### 如何在页面间传值? - -通过router.replace方法中的params参数来传递,参考代码如下: - -第一个页面传递数据: - -``` -router.replace({ - uri:'pages/detail/detail', //要跳转的页面uri - params:{transferData:this.data} //传递的数据,数据个数和名称开发者自己定义, -}); -``` - -第二个界面接受数据: - -``` -onInit(){ - const data = this.transferData; //在onInit函数中接受传递的数据 -} -``` - -### list如何滚动到某个item? - -通过list的scrollTo方法滚动到指定的item,参数是目标item的index。Index参数可以通过scrollend事件获取或者开发者指定。 - -### text支持多行吗? - -text支持多行。通过回车键换行或者是不设置text的高度属性,由控件自动根据内容换行。 - -### 为什么控件不显示? - -**现象描述** - -开发者在hml文件中添加的控件无法显示 - -**可能原因** - -- 未设置width和height值; -- 样式设置错误。 - -**处理步骤** - -\(1\)检查是否设置width和height值,组件必须显式设置width和height值; - -\(2\)检查组件的样式设置是否正确。 - -### 如何实现页面滑动? - -实现页面滑动目前有三种方式:scroll(根组件大小超过屏幕的大小即自动实现scroll效果)、list、swiper。开发者可以参考开发文档查看三者的区别,并加以使用。 - -### Left、Top为什么不生效? - -除根节点外,Left、Top配合Stack组件使用才有效果。 - -### 动态绑定为什么不生效? - -在进行绑定时,必须先将要绑定的对象或者对象的属性进行定义,不能先绑定后定义 - -### 如何实现相对定位和绝对定位? - -使用div、stack(top left属性)来实现相对和绝对定位。 - -### 如何控制控件的显示与隐藏? - -通过display、show和if来控制控件的显示与隐藏。区别在于:if为false时,组件会从VDOM中移除,而show仅是渲染时不可见,组件依然存在于VDOM中。 - -### 使用Margin时,有什么注意事项? - -Stack组件不支持其子组件设置margin属性。 - -### 使用事件订阅时,有什么注意事项? - -在应用运行期间只存在一个page,所以router.replace跳转是先销毁前一个页面,然后在新创建一个界面。因此,如果涉及到事件订阅的页面,每次页面创建时要进行事件订阅,跳转离开界面前取消事件订阅。 - -### 使用动态绑定时,有什么注意事项? - -过多的动态绑定会消耗较多的内存,若非业务需要,尽量不要使用太多的动态绑定。 - -### swiper loop属性如何生效? - -去掉第一个组件或者去掉最后一个组件,剩余的长度大于swiper长度,loop生效。 - -### 使用数组时,有什么注意事项? - -数组元素不宜过多,尽量避免对大数组进行频繁操作。 - -## hdc类问题 - -### hdc\_std连接不到设备 - -- **现象描述** - - 执行 "hdc\_std list targets"命令后结果为:\[Empty\] - -- **解决方法** - 1. 设备没有被识别: - - 在设备管理器中查看是否有hdc设备,在通用串行总线设备中会有“HDC Device”信息。如果没有,hdc无法连接。此时需要插拔设备,或者烧写最新的镜像。 - - 2. hdc\_std工作异常: - - 可以执行"hdc kill"或者"hdc start -r"杀掉hdc服务或者重启hdc服务,然后再执行hdc list targets查看是否已经可以获取设备信息。 - - 3. hdc\_std与设备不匹配: - - 如果设备烧写的是最新镜像,hdc\_std也需要使用最新版本。由于hdc\_std会持续更新,请从开源仓developtools\_hdc\_standard中获取,具体位置在该开源仓的prebuilt目录。 - - - -### hdc\_std运行不了 - -- **现象描述** - - 点击hdc\_std.exe文件无法运行。 - -- **解决方法** - - hdc\_std.exe不需要安装,直接放到磁盘上就能使用,也可以添加到环境变量中。通过打开cmd执行hdc\_std命令直接使用。 - - diff --git "a/website/docs/01.OpenHarmony/13.\350\264\241\347\214\256/01.\345\217\202\344\270\216\350\264\241\347\214\256.md" "b/website/docs/01.OpenHarmony/13.\350\264\241\347\214\256/01.\345\217\202\344\270\216\350\264\241\347\214\256.md" deleted file mode 100644 index 74544938047009b80ce7462e61821869c37ccf18..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/13.\350\264\241\347\214\256/01.\345\217\202\344\270\216\350\264\241\347\214\256.md" +++ /dev/null @@ -1,49 +0,0 @@ ---- -title: 参与贡献 -permalink: /pages/010d01 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 参与贡献 - -## 贡献代码 - -### 开始之前 - -#### 签署开发者原创声明 - -您必须首先签署“开发者原创声明”,然后才能参与社区贡献。 - -点击[这里](https://dco.openharmony.io/sign/Z2l0ZWUlMkZvcGVuX2hhcm1vbnk=)签署,点击[这里](https://dco.openharmony.io/check-sign-status)查询签署状态。 - -#### 行为准则 - -OpenHarmony是一个开源社区。它完全依赖于社区提供友好的开发和协作环境,所以在参与社区贡献之前,请先阅读并遵守OpenHarmony社区的[行为守则](/pages/010d02)。 - -### 找到感兴趣的SIG - -如何参与SIG(Special Interest Group)特别兴趣小组,请参考[SIG治理章程](https://gitee.com/openharmony/community/tree/master/sig)。 - -### 开始贡献 - -如何贡献代码,请参考[贡献代码](/pages/010d03)。 - -## 自测试验证 - -如何根据测试需求开发相关测试用例,请参考[测试子系统](/pages/01010218)。 - -## 贡献文档 - -如何贡献文档,请参考[贡献文档](/pages/extra/7f2552/)。 - -## 社区沟通与交流 - -有关详细信息,请参考[社区沟通与交流](/pages/010d06)。 - diff --git "a/website/docs/01.OpenHarmony/13.\350\264\241\347\214\256/02.\350\241\214\344\270\272\345\207\206\345\210\231.md" "b/website/docs/01.OpenHarmony/13.\350\264\241\347\214\256/02.\350\241\214\344\270\272\345\207\206\345\210\231.md" deleted file mode 100644 index 8fbaf3a101aef9b3bc1094e69713e7698ec37f78..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/13.\350\264\241\347\214\256/02.\350\241\214\344\270\272\345\207\206\345\210\231.md" +++ /dev/null @@ -1,73 +0,0 @@ ---- -title: 行为准则 -permalink: /pages/010d02 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 行为准则 - -OpenHarmony社区遵守开源社区[《贡献者公约》](https://contributor-covenant.org/)V1.4中规定的行为守则,请参考[V1.4版本](https://www.contributor-covenant.org/zh-cn/version/1/4/code-of-conduct.html) - -如需举报侮辱、骚扰或其他不可接受的行为,您可以发送邮件至contact.openharmony@openatom.org,联系OpenHarmony技术委员会处理。 - -**贡献者们的承诺** - -为建设开放友好的环境,我们贡献者和维护者承诺:不论年龄、体型、身体健全与否、民族、性征、性别认同与表征、经验水平、教育程度、社会地位、国籍、相貌、种族、信仰、性取向,我们项目和社区的参与者皆免于骚扰。 - -**我们的准则** - -有助于创造积极环境的行为包括但不限于: - -- 措辞友好且包容 - -- 尊重不同的观点和经验 - -- 耐心接受有益批评 - -- 关注对社区最有利的事情 - -- 与社区其他成员友善相处 - - -参与者不应采取的行为包括但不限于: - -- 发布与性有关的言论或图像、不受欢迎地献殷勤 - -- 捣乱/煽动/造谣行为、侮辱/贬损的评论、人身及政治攻击 - -- 公开或私下骚扰 - -- 未经明确授权便发布他人的资料,如住址、电子邮箱等 - -- 其他有理由认定为违反职业操守的不当行为 - - -**我们的义务** - -项目维护者有义务诠释何谓“妥当行为”,并妥善公正地纠正已发生的不当行为。 - -项目维护者有权利和义务去删除、编辑、拒绝违背本行为标准的评论(comments)、提交(commits)、代码、wiki 编辑、问题(issues)等贡献;项目维护者可暂时或永久地封禁任何他们认为行为不当、威胁、冒犯、有害的参与者。 - -**适用范围** - -本行为标准适用于本项目。当有人代表本项目或本社区时,本标准亦适用于此人所处的公共平台。 - -代表本项目或本社区的情形包括但不限于:使用项目的官方电子邮件、通过官方媒体账号发布消息、作为指定代表参与在线或线下活动等。 - -代表本项目的行为可由项目维护者进一步定义及解释。 - -**贯彻落实** - -可以致信contact.openharmony@openatom.org,向项目团队举报滥用、骚扰及不当行为。 - -维护团队将审议并调查全部投诉,妥善地予以必要的回应。项目团队有义务保密举报者信息。具体执行方针或将另行发布。 - -未切实遵守或执行本行为标准的项目维护人员,经项目负责人或其他成员决议,可能被暂时或永久地剥夺参与本项目的资格。 - diff --git "a/website/docs/01.OpenHarmony/13.\350\264\241\347\214\256/03.\350\264\241\347\214\256\344\273\243\347\240\201.md" "b/website/docs/01.OpenHarmony/13.\350\264\241\347\214\256/03.\350\264\241\347\214\256\344\273\243\347\240\201.md" deleted file mode 100644 index 23ae610bb2a08bf6025a163c88379c1cade720c4..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/13.\350\264\241\347\214\256/03.\350\264\241\347\214\256\344\273\243\347\240\201.md" +++ /dev/null @@ -1,58 +0,0 @@ ---- -title: 贡献代码 -permalink: /pages/010d03 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 贡献代码 - -## 开始贡献 - -### 设计规范 - -[OpenHarmony架构设计原则](https://gitee.com/openharmony/community/blob/master/sig/sig-QA/%E6%9E%B6%E6%9E%84%E8%AE%BE%E8%AE%A1%E5%8E%9F%E5%88%99.md) - -[OpenHarmony API治理章程](/pages/extra/261918/) - -[OpenHarmony安全设计规范](/pages/extra/aec558/) - -[OpenHarmony编译规范](https://gitee.com/openharmony/community/blob/master/sig/sig-QA/%E7%BC%96%E8%AF%91%E8%A7%84%E8%8C%83.md) - -### 代码风格 - -请遵循OpenHarmony编程规范,进行代码开发、检视、测试,务必保持代码风格统一。 - -- [C++语言编程规范](/pages/extra/ca40b1/) -- [C语言编程规范](/pages/extra/ac1933/) -- [JavaScript语言编程规范](/pages/extra/ae0e51/) -- [Python语言编程规范](https://pep8.org/) -- [C&C++语言安全编程指南](/pages/extra/1f6576/) -- [Java语言安全编程指南](/pages/extra/d49c41/) -- [32/64位可移植编程规范](/pages/extra/a53c98/) -- [HDF驱动编程规范](/pages/extra/a7ae41/) -- [Log打印规范](/pages/extra/2d2a23/) - -### 开源软件引入 - -若要引入新的第三方开源软件到OpenHarmony项目中,请参考[第三方开源软件引入指导](/pages/extra/0491e3/) - -## 贡献工作流 - -有关详细信息,请参考[贡献流程](/pages/010d04)。 - -[代码门禁详细质量要求](https://gitee.com/openharmony/community/blob/master/sig/sig-QA/%E4%BB%A3%E7%A0%81%E9%97%A8%E7%A6%81%E8%A6%81%E6%B1%82.md)。 - -## 社区安全问题披露 - -- [安全问题处理和发布流程](https://gitee.com/openharmony/security/blob/master/zh/security-process/README.md) - -- [安全和披露说明](https://gitee.com/openharmony/security/blob/master/zh/security-process/security-disclosure.md) - - diff --git "a/website/docs/01.OpenHarmony/13.\350\264\241\347\214\256/04.\350\264\241\347\214\256\346\265\201\347\250\213.md" "b/website/docs/01.OpenHarmony/13.\350\264\241\347\214\256/04.\350\264\241\347\214\256\346\265\201\347\250\213.md" deleted file mode 100644 index 5d92c0c4d5c61c93a4c877e7be2736923ba6b0c2..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/13.\350\264\241\347\214\256/04.\350\264\241\347\214\256\346\265\201\347\250\213.md" +++ /dev/null @@ -1,260 +0,0 @@ ---- -title: 贡献流程 -permalink: /pages/010d04 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 贡献流程 - -## 环境准备 - -- 针对Git的安装、环境配置及使用方法,请参考码云帮助中心的Git知识大全:[https://gitee.com/help/categories/43](https://gitee.com/help/categories/43) -- 注册SSH公钥,请参考码云帮助中心的公钥管理:[https://gitee.com/help/articles/4191](https://gitee.com/help/articles/4191) -- 在开展Gitee的工作流之前,您需要先在OpenHarmony的代码托管平台上找到您感兴趣的Repository。 - -## 代码下载 - -### 从云上Fork代码分支 - -1. 找到并打开对应Repository的首页。 -2. 点击右上角的 Fork 按钮,按照指引,建立一个属于**个人**的云上Fork分支。 - -### 把Fork仓下载到本地 - -请按照以下的过程将Repository内的代码下载到您的在计算机上: - -1. **创建本地工作目录**: - - 您需要创建本地工作目录,以便于本地代码的查找和管理 - - ``` - mkdir ${your_working_dir} - ``` - -2. **复制远程仓库到本地** - 1. **切换到本地路径**\* - - ``` - mkdir -p ${your_working_dir} - cd ${your_working_dir} - ``` - - 2. **复制远程仓库到本地** - - 您可以在仓库页面内复制远程仓库的拷贝地址,得到$remote\_link: - - **图 1** 复制远程仓库 - ![](/images/contribute/figures/复制远程仓库.png "复制远程仓库") - - - 在本地电脑执行拷贝命令: - - ``` - git clone $remote_link - ``` - - - - -### 使用repo工具批量下载代码仓 - -1. 下载码云repo工具\(可以参考码云帮助中心:[https://gitee.com/help/articles/4316](https://gitee.com/help/articles/4316)\): - - ``` - curl https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 > /usr/local/bin/repo - chmod a+x /usr/local/bin/repo - pip install -i https://pypi.tuna.tsinghua.edu.cn/simple requests - ``` - -2. 下载\(注意没有repo branch参数\): - - ``` - repo init -u https://gitee.com/openharmony/manifest.git -b master - repo sync -c - ``` - - -## 代码提交 - -### 单仓提交\(git clone场景\) - -1. **拉分支** - - 更新您的本地分支 - - ``` - git remote add origin $remote_link - git fetch origin - git checkout master - git pull --rebase - ``` - - 基于远端master分支拉取本地调试分支 - - ``` - git branch myfeature origin/master - git checkout myfeature - ``` - - 然后在myfeature分支上编辑和修改代码。 - -2. **在本地工作目录提交变更** - - ``` - git add . - git commit -sm "xxxxxx" // 提交信息包含signoff邮箱 - ``` - - 您可能会在前次提交的基础上,继续编辑构建并测试更多内容,可以使用commit --amend继续添加提交。 - -3. **将变更推送到您的远端目录** - - 准备进行审查(或只是建立工作的异地备份)时,将分支推到您的fork仓库: - - ``` - git push -f origin myfeature - ``` - - -### 多仓提交\(repo init/sync场景\) - -1. 配置全局环境token码: - -``` -repo config --global repo.token {TOKEN} -``` - -token码在码云[个人设置→安全设置→私人令牌](https://gitee.com/profile/personal_access_tokens)中生成,例如 - -``` -repo config --global repo.token 211XXXXXXXXXXXXXXXXXXXXXXXX -``` - -2. 在码云上任意一个此次要修改的仓下创建issue\(类似于gerrit的changeID功能,用来关联多个耦合仓修改\),并记录下issue编号\(如下图中的issue编号是\#I1TVV4\)\(如果不涉及多个仓耦合修改,则此步骤不需要\): - -![](/images/contribute/figures/无标题1.png) - -3. 在本地代码工作区新建分支,修改代码,并提交: - -``` -repo start branchname --all -``` - -修改代码后在此次修改的多个仓里执行: - -``` -git add . -git commit -sm "xxxxxx" -``` - -或者通过repo工具批量add/commit,在代码工程根目录下执行: - -``` -repo forall -c 'git add .' -repo forall -c 'git commit -sm "xxxxxx"' -``` - -4. PUSH代码\(注意:不支持repo upload\): - -配置push代码时是否直接生成PR,选择False是不直接生成,需要手动去fork仓里生成PR,选择True是push到fork仓的同时生成PR: - -``` -repo config repo.pullrequest {True/False} -``` - -例如选择push代码的时候同时生成PR,则执行: - -``` -repo config repo.pullrequest True -``` - -push代码: - -``` -repo push --br={BRANCH} --d={DEST_BRANCH} --content={PR_CONTENT} -``` - -BRANCH为本地分支,DEST\_BRANCH为目的分支\(即主干分支\),一般是master,PR\_CONTENT为填写的PR描述,假设涉及多仓耦合提交,这里必须填写Issue编号,例如: - -``` -repo push --br="20200903" --d="master" --content="#I1TVV4" -``` - -在弹出的编辑页面将需要提交仓、分支、commit的注释符打开: - -![](/images/contribute/figures/无标题2.png) - -保存退出,repo会自动将本地分支推送到远端fork仓\(如果没有fork仓,系统会自动创建fork仓\)里,并自动生成PR: - -![](/images/contribute/figures/无标题3.png) - -同时自动将PR和Issue关联: - -![](/images/contribute/figures/无标题4.png) - -## 创建Pull Request(如已通过repo工具自动创建PR,则此步忽略) - -访问您在码云上的fork仓页面,点击创建Pull Request按钮选择myfeature分支生成PR。 - -详细操作请参考码云帮助中心的开发协作指导:[https://gitee.com/help/articles/4128](https://gitee.com/help/articles/4128) - ->![](/images/contribute/public_sys-resources/icon-notice.gif) **须知:** ->**多个代码仓存在编译依赖时如何同时发起构建:** ->OS\(操作系统\)开发时,经常会遇到多个代码仓的修改具有编译依赖关系,需要同时构建、同时合入。为此码云平台将Issue作为具有编译依赖的多个代码仓提交PR的关联标识。具体操作如下: ->1. 在此次提交的任意一个代码仓上创建Issue。 ->2. 将多个需要同时构建、同时合入的PR关联上述Issue,具体操作请参考码云帮助中心:[https://gitee.com/help/articles/4142](https://gitee.com/help/articles/4142)。 ->3. 触发构建\(详见触发构建的操作帮助\)后,构建中心会识别关联了同一Issue的PR,同时下载构建,并在代码审核通过后,同时进行合并入代码库。 - -## 门禁构建 - -### 创建Issue - -1. 找到并打开对应Repository的首页 -2. 选择左上角的Issues页签,点击右侧新建Issue按钮,按照指引建立一个专属的任务,用于相关联的代码(开发特性/修改bug)执行CI门禁。 - -### 将Issue与PR关联 - -创建PR或编辑已有的PR时,描述框输入\#+I+五位Issue ID,即可将Issue与PR关联。 - -**约束:** - -- 一个PR只允许关联一个Issue,关联多个Issue时无法触发CI。 -- 相关特性开发或bug修复涉及多个代码仓联合修改时,多个PR可关联同一个Issue。 -- Issue关联的PR中,不允许存在已被合入或关闭的PR,否则无法触发CI。 -- 若Issue已被合入或关闭的PR关联,则该Issue无法被重复使用,需重新创建Issue并进行OPEN的PR关联。 - -### 触发代码门禁 - -在PR中评论“start build“即可触发CI门禁。 - -多个PR关联同一个Issue时,在任一PR中评论“start build”均可触发该Issue的CI门禁。 - -门禁执行完成,会在该Issue关联的所有PR中自动评论门禁执行结果。 - -如果门禁通过,该Issue关联的所有PR均会自动标记“测试通过”。 - -详细参考[代码门禁质量要求](https://gitee.com/openharmony/community/blob/master/sig/sig-QA/%E4%BB%A3%E7%A0%81%E9%97%A8%E7%A6%81%E8%A6%81%E6%B1%82.md)。 - -## CI门户 - -OpenHarmony通过持续集成(CI,Continuous Integration)及时发现代码问题,确保代码质量可靠和功能稳定,包括: - -- 代码门禁:开发者向OpenHarmony提交代码合入申请后,会触发门禁检查,例如静态检查、代码编译、功能测试等,门禁通过后才能合入代码。 -- 每日构建:OpenHarmony的持续集成流水线每日自动执行,以便提前发现代码静态检查、编译、功能等方面的问题,及时修复问题,确保代码质量。 - -CI门户是为了便于开发者及时查看、分析每日构建和代码门禁的执行结果的一个可持续集成的门户。 - -示例:[CI门户入口](http://ci.openharmony.cn/) - -![CI门户](/images/contribute/figures/ci-portal.png) - -## 代码审查 - -请参考码云帮助中心:[https://gitee.com/help/articles/4304](https://gitee.com/help/articles/4304) - -**相关主题:[FAQ](/pages/010d07)** diff --git "a/website/docs/01.OpenHarmony/13.\350\264\241\347\214\256/05.\350\264\241\347\214\256\346\226\207\346\241\243/01.\345\206\231\344\275\234\350\247\204\350\214\203.md" "b/website/docs/01.OpenHarmony/13.\350\264\241\347\214\256/05.\350\264\241\347\214\256\346\226\207\346\241\243/01.\345\206\231\344\275\234\350\247\204\350\214\203.md" deleted file mode 100644 index 7829a211a88851ee0aa58867e49a60670d661e00..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/13.\350\264\241\347\214\256/05.\350\264\241\347\214\256\346\226\207\346\241\243/01.\345\206\231\344\275\234\350\247\204\350\214\203.md" +++ /dev/null @@ -1,165 +0,0 @@ ---- -title: 写作规范 -permalink: /pages/010d0501 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 写作规范 - -本文介绍OpenHarmony文档贡献的写作规范。 - -## 命名规范 - -如需提交新的文档,在Gitee上工程代码doc目录下创建新的.md文件,命名需遵循xxx-xxx.md格式,根据文档的内容来声明。 - -比如介绍写作规范的文档,可以命名为write-standard.md。 - -## 内容规范 - -以简洁、直观地表达所述内容为目的,介绍性文档言简意赅介绍原理、架构、设计思路等,操作类文档写明关键步骤,以便能对其他开发者起到帮助。可以优先使用中文,建议中英文都支持,OpenHarmony也将持续更新,保证中英文的同步。 - -**标题** - -建议标题层级不超过三级。 - -操作类文档标题尽量用动宾结构,执行的主体要描述清楚。(例如:申请权限) - -**正文** - -**操作类文档**以移植为例,文档结构可以参考如下: - -- 目的(简述操作目的,如移植到哪款型号的单板) - -- 软硬件环境准备 - -- 移植具体步骤 - -- 结果验证 - - 步骤写作要求: - - - 步骤里涉及的接口在前面开放能力介绍里有说明。 - - 如果操作可选,要明确可选条件 - - 每一个开发步骤,如果涉及接口调用,需要清晰给出使用的接口及其使用说明,或给出示例代码 - - -**介绍性文档**以开发指南某一功能为例,文档结构可以参考如下: - -- 概述(概念及原理介绍) - -- 功能(支持的接口列表) - -- 开发流程(如何使用及相应步骤) - -- 编程实例(提供具体代码示例) - -- 注意事项 - - -**图片** - -图片统一存放到文档同级目录下的pic文件夹中(英文文档对应pic-en),如: - -“OpenHarmony\_DOCUMENTS/docs/quick-start/write-standard.md“中使用的图片,统一放置到 - -“OpenHarmony\_DOCUMENTS/docs/quick-start/pic“目录下,文档中使用相对路径引用图片。 - ->![](/images/contribute/public_sys-resources/icon-caution.gif) **注意:** ->请使用原创图片,避免存在知识产权侵权风险。 - -- 图形清晰可辨识,图形信息完整,如流程图有“开始”和“结束”。 -- 图形逻辑清晰,图文配合使用,切忌图文分离。 -- 图片高度建议在640px左右、宽度不超过820px、图片一般为.png格式,大小不超过150K。 -- 中文用中文图,英文用英文图形。 -- 图片建议根据内容命名,只用数字序列不利于后续图片的继承。 - ->![](/images/contribute/public_sys-resources/icon-note.gif) **说明:** ->引用方式: ->!\[\]\(./pic/pic-standard.png\) - -如果是自制图片,配色请参考如下,格式不限png/jpg/gif...均可。 - -**图 1** 配色示例 -![](/images/contribute/figures/配色示例.png "配色示例") - -如果是截图请参考如下,如需突出图形中的关键信息,可增加红色框线或者文字备注说明。 - -线条宽度:0.75pt - -线条颜色:CE0E2D - -中文字体:微软雅黑 - -英文字体:首选Arial - -字体大小:10pt - -**图 2** 截图示例 -![](/images/contribute/figures/截图示例.png "截图示例") - -**表格** - -在md中可以按照如下形式插入表格。 - -Input - -``` -| Tables | Type | Note | -| ----------- |:-------------:| -----:| -| first | standard | None | -| second | outstanding | 5 | -| third | inside | with | -``` - -Output - -**表 1** 参数表 - - - - - - - - - - - - - - - - - - - - -

Tables

-

Type

-

Note

-

first

-

standard

-

None

-

second

-

outstanding

-

5

-

third

-

inside

-

with

-
- -**代码** - -代码示例说明了如何实现特定功能,开发人员使用代码示例来编写和调试代码。代码要求如下: - -- 代码的逻辑和语法正确 -- 如果有返回值,也一并描述 -- 保证代码中关键段用粗体突出显示,关键步骤要有注释说明 - diff --git "a/website/docs/01.OpenHarmony/13.\350\264\241\347\214\256/05.\350\264\241\347\214\256\346\226\207\346\241\243/02.\344\270\272\345\217\221\350\241\214\347\211\210\346\234\254\346\222\260\345\206\231\351\205\215\345\245\227\346\226\207\346\241\243.md" "b/website/docs/01.OpenHarmony/13.\350\264\241\347\214\256/05.\350\264\241\347\214\256\346\226\207\346\241\243/02.\344\270\272\345\217\221\350\241\214\347\211\210\346\234\254\346\222\260\345\206\231\351\205\215\345\245\227\346\226\207\346\241\243.md" deleted file mode 100644 index 98aed8b984372489a215e60227581c5058e1445d..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/13.\350\264\241\347\214\256/05.\350\264\241\347\214\256\346\226\207\346\241\243/02.\344\270\272\345\217\221\350\241\214\347\211\210\346\234\254\346\222\260\345\206\231\351\205\215\345\245\227\346\226\207\346\241\243.md" +++ /dev/null @@ -1,135 +0,0 @@ ---- -title: 为发行版本撰写配套文档 -permalink: /pages/010d0502 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 为发行版本撰写配套文档 - -为了帮助开发者更高效使用OpenHarmony社区的每个Release版本,社区会根据每个版本规划的需求特性提供配套文档(如指南、API参考、开发示例、Release Notes、API Changelog、FAQ等)。有的需求涉及新增功能特性和文档,有的需求的是对现有特性和文档内容更新。 - -## OpenHarmony社区文档开发流程 - -每个SIG团队在规划功能特性需求时,需要判断该需求是否涉及新增开发者文档、或变更现有开发者文档,分解需求给SIG Docs 团队,便于文档需求跟踪闭环。SIG Docs团队会根据相关需求,提供文档设计意见,并配合各业务SIG团队完成开发者文档的评审、翻译和发布。社区文档完整开发流程如下: - -![OpenHarmony社区文档开发流程](/images/contribute/figures/docs-sig.png) - -## 业务SIG团队成员或其他开发人员 - -通过每个业务SIG团队为发行版本撰写配套文档基础稿,欢迎社区开发人员参与相关功能特性文档开发。 - -### 分解文档需求 - -1. 在业务SIG需求Issue中给出【配套文档】的分解,如果涉及开发者文档新增、更新,需要关联SIG-Docs。 - -2. 在 [OpenHarmony社区版本发布计划](https://gitee.com/openharmony/release-management/blob/master/OpenHarmony-RoadMap.md)中查看对应版本的特性需求,此文档中给出了OpenHarmony的版本发布时间计划、各版本交付特性、特性状态,所属SIG。 - - 如果该特性需求涉及文档交付,需要在对应的Need Docs列补充判断,SIG_Docs,便于SIG Docs团队闭环跟踪文档交付。 - - -### 开发文档 - -如果你是某个业务SIG的成员,负责开发某一新特性,你需要与SIG Docs一起配合,确保在版本发布之前完成该新特性文档开发。否则,在最终的版本发布中未提供配套文档的特性可能被移除。 - -如果你需要文档组织方面的帮助,请在`#SIG-Docs` ZULIK频道中提问求助。 - -1. 参考[评审人沟通表](/pages/extra/401d0b/),联系SIG Docs资料作者,沟通文档设计建议。 -2. 获取[文档模板](template),了解文档写作规范。 -3. 尽可能为功能特性提供详细的文档及使用说明,完成功能特性初稿后,提交PR并在PR描述中提供对应的需求Issue链接。 - -### 提交PR评审 - -所有新增内容的PR评审,为确保技术描述准确性需要指定相应业务SIG的技术专家参与技术评审,同时指定SIG Docs的资料专家评审文档规范性内容,请参考[评审人沟通表](/pages/extra/401d0b/)在PR评论区@相关专家。也可以在`#SIG-Docs` ZULIK频道中反馈评审需求。 - -在评审周期内,所有评审意见闭环修改后,该PR通过审核可以合并入仓的必要条件: - -- 技术评审专家审核后给出`TechApprove`的评论。 -- 文档规范性评审专家审核后给出`DocsApprove`的评论。 - -### 提交测试 - -文档随版本转测试,测试过程中的文档问题,由SIG Test团队测试人员以Issue形式提交到Docs仓,对应文档作者闭环确认测试意见并完成文档修改。 - -### 提交翻译 - -#### Docs仓文档翻译 - -OpenHarmony社区为开发者提供中文、英文的官方文档,中文文档完成评审、测试定稿后,可提交翻译需求Issue,由SIG Docs团队的翻译专家完成英文文档。 - -翻译专家通过PR提交英文文档,并在PR描述中提供对应的中文需求Issue链接。为确保技术翻译描述准确性需要指定相应业务SIG的技术专家参与技术评审,可以是中文文档作者,请参考[评审人沟通表](/pages/extra/401d0b/)在PR评论区@相关专家。 - -在评审周期内,所有评审意见闭环修改后,该PR通过审核可以合并入仓的必要条件: - -- 技术评审专家审核后给出`TechApprove`的评论。 -- 英文文档规范性评审专家审核后给出`DocsApprove`的评论。 - -#### 非Docs仓文本类翻译 - -针对OpenHarmony核心业务SIG的非Docs仓翻译需求(如API注释等),可提交翻译需求Issue到Docs仓,SIG Docs团队的翻译专家完成英文文档交付。 - -提交翻译需求时,需确保: - -1. 相关中文文档为发布交付件质量标准。 -2. 提供中文文档PR或相关文档路径。 -3. 中文临时文件可提交至[SIG-Docs仓](https://gitee.com/openharmony/community/tree/master/sig/)。 - -## Docs SIG团队成员或文档贡献者 - -SIG Docs团队成员或文档贡献者或,配合各业务SIG团队,评审、优化相关文档输出,英文翻译,确保相关输出符合发布条件。 - -### 了解发行版本规划特性 - -想要了解对应发行版本规划的功能特性、发布计划,可以参加每双周周五例行组织的[SIG Release](https://gitee.com/openharmony/release-management/blob/master/README.md)例会。了解版本进度,需求交付进度,文档交付进度等。 - -同时可以在 [OpenHarmony社区版本发布计划](https://gitee.com/openharmony/release-management/blob/master/OpenHarmony-RoadMap.md)中查看对应版本的特性需求,选择标识有SIG_Docs的相关特性Issue,及关联的文档PR。 - -![版本特性清单](/images/contribute/figures/sig-task.png) - -### 评审PR中提交的中文文档 - -在评审对应特性文档时,建议从以下方面给出中肯的评审建议。 - -#### 语言描述规范 - -- 前后逻辑表达通顺,术语名词表述一致 -- 语言正式避免口语化 -- 避免使用侵犯第三方知识产权的风险词汇 - -#### 内容易理解 - -- 内容逻辑清晰,前后表达一致 -- 内容表达易读易理解,避免使用晦涩、生僻的词语 -- 步骤清晰,有效指导开发者完成相关任务开发 - -#### 图表规范 - -- 图片清晰、图文配合使用 -- 表格有表头、表标题,避免出现单行或单列表 -- 表格中无内容用“-"或者"NA",避免出现空白单元格 - -#### 网站风格 - -- 该PR变更涉及新增Markdown页面时,需确保: - - 该页面内容使用了正确的内容模板 - - 该Markdown文件名称定义符合规范 - - 该页面在整本手册Readme导航中正常显示 - -- 删除Markdown页面、变更Markdown页面名称,需确保: - - 该页面对社区其他内容链接未产生影响,建议本地运行链接检查 - - 整本手册Readme导航中更新目录 - -更多详细规范请参考OpenHarmony社区文档[写作规范](/pages/010d0501)。 - -### 翻译英文文档 - -社区的翻译需求Issue会由SIG Docs团队技术翻译专家完成翻译,也欢迎文档贡献者领取翻译需求任务,提交英文文档PR。 - - - diff --git "a/website/docs/01.OpenHarmony/13.\350\264\241\347\214\256/06.\347\244\276\345\214\272\346\262\237\351\200\232\344\270\216\344\272\244\346\265\201.md" "b/website/docs/01.OpenHarmony/13.\350\264\241\347\214\256/06.\347\244\276\345\214\272\346\262\237\351\200\232\344\270\216\344\272\244\346\265\201.md" deleted file mode 100644 index 9b2aa13f492f8c683e51e36dae2820f53091cdfb..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/13.\350\264\241\347\214\256/06.\347\244\276\345\214\272\346\262\237\351\200\232\344\270\216\344\272\244\346\265\201.md" +++ /dev/null @@ -1,90 +0,0 @@ ---- -title: 社区沟通与交流 -permalink: /pages/010d06 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 社区沟通与交流 - -如果您在使用OpenHarmony过程中遇到问题,请加入邮件群组参与讨论,这是参与OpenHarmony项目讨论的正确方式。 - -## 如何订阅邮件列表 - -如果您以前从未订阅过邮件列表,请参照下面的操作步骤。 - -1. 点击您想要订阅的邮件列表的名称。 -2. 浏览器将跳转到该邮件列表的订阅页面,那里将提供有关如何订阅的说明。 -3. 阅读订阅说明,您需要提供一个您希望用来订阅邮件列表的电子邮件地址。 -4. 输入您的电子邮件地址并点击订阅,您将收到一封电子邮件,要求您确认订阅。 -5. 回复您收到的电子邮件以确认您的订阅。 -6. 最后您将收到来自一封来自邮件列表的欢迎邮件。 - -**表 1** : 邮件列表 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

邮件地址

-

简介

-

功能描述

-

contact@openharmony.io

-

公用邮箱

-

OpenHarmony社区公共邮箱。开发者CLA协议签署可以发邮件到此邮箱。

-

dev@openharmony.io

-

开发邮件列表

-

OpenHarmony社区开发讨论邮件列表,任何社区开发相关话题都可以在邮件列表讨论。任何开发者可订阅

-

cicd@openharmony.io

-

CI邮件列表

-

OpenHarmony社区CICD构建邮件列表,任何开发者可订阅

-

pmc@openharmony.io

-

PMC邮件列表

-

PMC讨论邮件列表,PMC成员可订阅

-

scy@openharmony.io

-

安全问题邮箱

-

开发者可反馈OpenHarmony安全问题到此邮箱。

-

scy-priv@openharmony.io

-

安全组邮件列表

-

安全组成员安全问题处理讨论邮件列表,安全组成员可订阅

-
- -## 如何发送邮件到邮件列表 - -要将邮件发送到指定的邮件列表,请向上表中列出的邮件地址发送您的电子邮件。 - -这样所有在这个邮件列表中的社区成员都能收到您的电子邮件。 - diff --git "a/website/docs/01.OpenHarmony/13.\350\264\241\347\214\256/07.FAQ.md" "b/website/docs/01.OpenHarmony/13.\350\264\241\347\214\256/07.FAQ.md" deleted file mode 100644 index 6787a50b66fc5837d200fdf572142c5e2605cab1..0000000000000000000000000000000000000000 --- "a/website/docs/01.OpenHarmony/13.\350\264\241\347\214\256/07.FAQ.md" +++ /dev/null @@ -1,87 +0,0 @@ ---- -title: FAQ -permalink: /pages/010d07 -navbar: true -sidebar: true -prev: true -next: true -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# FAQ - - -## 多个代码仓存在编译依赖时如何同时发起构建 - -OS\(操作系统\)开发时,经常会遇到多个代码仓的修改具有编译依赖关系,需要同时构建、同时合入。为此码云平台将Issue作为具有编译依赖的多个代码仓提交PR的关联标识。具体操作如下: - -1. 在此次提交的任意一个代码仓上创建Issue。 - -2. 将多个需要同时构建、同时合入的PR关联上述Issue,具体操作请参考码云帮助中心:[https://gitee.com/help/articles/4142](https://gitee.com/help/articles/4142)。 - -3. 触发构建\(详见触发构建的操作帮助\)后,构建中心会识别关联了同一Issue的PR,同时下载构建,并在代码审核通过后,同时进行合并入代码库。 - -## `Signed-off-by`相关操作 - -### 如何在Commit中添加signoff记录 - -使用`git commit -s` 或 `git commit –signoff` 命令提交。 - -### 如何追加signoff到上一次commit? - -执行`git commit --amend --signoff`命令 。 - -关于commit更多选项,请参考:[https://](https://git-scm.com/docs/git-commit)[git-scm.com/docs/git-commit](https://git-scm.com/docs/git-commit) - -## DCO校验异常处理 - -开发者提交Pull Request后,评论`start build`会触发门禁校验: - -1. 该PR提交是否签署Developer Certificate of Origin(DCO) “开发者原创声明”。 -2. 该PR提交是否包含 Signed-off-by信息。 - -校验失败可能的原因有: - -1. 未签署“DCO协议”,例如提示: - - ``` - 当前检测到如下commit的用户未签署DCO协议: - - •345612 - - •213123 - ``` - - **解决办法**: - - 点击[这里](https://dco.openharmony.io/sign/Z2l0ZWUlMkZvcGVuX2hhcm1vbnk=)签署、查看签署状态。 - - 在PR的评论框输入`check dco`后,单击”评论”,系统将再次进行DCO校验。 - -2. Commits 中未包含 Signed-off-by信息,例如提示: - - ``` - 当前检测到如下commit未包含Signed-off-by信息: - - •123123 - - •345612 - ``` - - **解决办法**: - - 参考`Signed-off-by`相关操作,添加Signed-off-by信息。格式为:Signed-off-by: user.name 。 - - 在PR的评论框输入`check dco`后,单击”评论”,系统将再次进行DCO校验。 - -## 回退提交 - -请参考码云帮助中心:[https://gitee.com/help/articles/4195](https://gitee.com/help/articles/4195) - -## 处理冲突 - -请参考码云帮助中心:[https://gitee.com/help/articles/4194](https://gitee.com/help/articles/4194) - diff --git a/website/docs/_posts/SIG/sig.md b/website/docs/_posts/SIG/sig.md index 9ae804d8860b484f0456ec6443041999ad24061b..f2a5f4220c7e057029bc5922b6cc195d5bed601f 100644 --- a/website/docs/_posts/SIG/sig.md +++ b/website/docs/_posts/SIG/sig.md @@ -1,5 +1,5 @@ --- -title: SIG管理章程 +title: 找到兴趣组SIG permalink: /sig_management navbar: true sidebar: false @@ -15,38 +15,38 @@ date: 2021-10-11 17:08:58 ## 背景 1. SIG(Special Interest Group)是指特别兴趣小组,SIG在PMC项目管理委员会指导下,负责OpenHarmony社区特定子领域及创新项目的架构设计、开源开发及项目维护等工作。 - 2. 为了便于OpenHarmony开源社区工作开展和交流,默认将其划分为[23个初始的SIG小组](/SIG/sig_subsystem_list/)。 + 2. 为了便于OpenHarmony开源社区工作开展和交流,默认将其划分为[23个初始的SIG小组]。 3. 本目录用于存放OpenHamony社区所有 “特别兴趣小组”(Special Interest Group,以下简称 SIG)的运作信息。 ## SIG职责&运作方式 - 1. 领域的技术演进方向由SIG组承担,负责领域技术竞争力分析和关键技术识别及决策。 - 2. 负责领域内功能分解分配,模块间接口定义与维护管理。 + 1. 子领域的技术演进方向由SIG组承担,负责子领域技术竞争力分析和关键技术识别及决策。 + 2. 负责子领域内功能分解分配,模块间接口定义与维护管理。 3. 社区的工作实体是SIG组,从基础设施到OS部件,从测试系统到版本发布都是由不同SIG的来承担。 4. 一个良好的社区组织形式是持续运作的关键,仪式感很重要,SIG组需要通过周期例会来保持其有效的运作,并定期向PMC委员会汇报进展。 ## 申请新建SIG - 1. 开发者在社区中寻找2-3个以上有共同兴趣及目标的人,确定SIG Leader。参考[新建SIG Charter](https://gitee.com/openharmony/community/blob/master/sig/sig-template/sig_template_cn.md)模板,创建SIG Charter提案,提案包括如下要素: + 1. 开发者在社区中寻找2-3个以上有共同兴趣及目标的人,确定SIG Leader。参考新建SIG Charter模板,创建SIG Charter提案,提案包括如下要素: - 创建SIG的背景信息 - 创建SIG的业务范围 - 创建SIG的业务目标 - 2. SIG Leader以[SIG-Charter-Proposal-XXX]为邮件标题,需先订阅[dev@openharmony.io](https://lists.openatom.io/postorius/lists/dev.openharmony.io/),将申请材料以附件方式向dev@openharmony.io发送邮件,提交新建SIG申请。 - 3. PMC或对应领域SIG、Committer邮件回复同意后,然后向[PMC](https://shimo.im/sheets/N2A1MZgDZxfbBVAD/MODOC)申报议题,PMC会根据收到的议题统一安排SIG申请评审,PMC根据评审通过后,申请者按照评审意见完善后,向[Community](https://gitee.com/openharmony/community)仓创建新的SIG的Pull Request申请新建SIG。 - - **重要**:SIG中如需新建仓申请的,请向[架构SIG](https://shimo.im/sheets/CqJChdHgcXywT9Gt/MODOC)中申报新增部件的议题。 + 2. SIG Leader以[SIG-Charter-Proposal-XXX]为邮件标题,需先订阅[dev@openharmony.io],将申请材料以附件方式向dev@openharmony.io发送邮件,提交新建SIG申请。 + 3. PMC或对应子领域SIG、Committer邮件回复同意后,然后向[PMC]申报议题,PMC会根据收到的议题统一安排SIG申请评审,PMC根据评审通过后,申请者按照评审意见完善后,向[Community]仓创建新的SIG的Pull Request申请新建SIG。 + - **重要**:SIG中如需新建仓申请的,请向[架构SIG]中申报新增部件的议题。 ## 加入已有SIG 1. 开发者可通过SIG列表查看感兴趣的SIG,通过订阅邮件列表、参与SIG会议等形式,参与对应SIG项目的技术讨论、社区维护及开源开发。 ## 运营维护SIG -1. SIG Leader Fork OpenHamony/community分支,在SIG文件夹下,以新SIG名称新建文件夹,并参考[SIG模板](/sig/sig_template_cn),创建对应的SIG配置文件,提交PR合入申请。 -2. SIG孵化子项目,统一存放在[OpenHarmony SIG组织](https://gitee.com/openharmony-sig),待孵化成熟后,可合入OpenHarmony组织代码主库。 -3. SIG Leader及Committer负责对应SIG的运营及维护,会议纪要和资料统一参考sig-template目录下的[meetings](https://gitee.com/openharmony-sig/sig-content)和[docs](https://gitee.com/openharmony-sig/sig-content)模版进行归档。 +1. SIG Leader Fork OpenHamony/community分支,在SIG文件夹下,以新SIG名称新建文件夹,并参考[SIG模板],创建对应的SIG配置文件,提交PR合入申请。 +2. SIG孵化子项目,统一存放在OpenHarmony SIG组织,待孵化成熟后,可合入OpenHarmony组织代码主库。 +3. SIG Leader及Committer负责对应SIG的运营及维护,会议纪要和资料统一参考sig-template目录下的[meetings]和[docs]模版进行归档。 4. SIG Leader定期在PMC项目管理委员会汇报SIG孵化项目及SIG运营进展,PMC基于SIG运作情况给出指导建议。 ## SIG孵化项目毕业 1. SIG孵化项目成熟并满足项目毕业要求后,可申请合入OpenHarmony组织代码主库。 2. SIG Leader通过向dev@openharmony.io发送邮件,提交孵化项目毕业申请。 3. PMC项目管理委员会通过项目毕业申请后,社区接纳孵化项目合入OpenHarmony主干。 - 4. 孵化项目毕业评审请按照[要求自检](/sig/guidance_for_incubation_project_graduation_cn)。 + 4. 孵化项目毕业评审请按照[要求自检]。 ## SIG数据存放和管理方式 SIG信息记录统一归档在OpenHamony/community仓库的sig目录内: @@ -59,14 +59,14 @@ SIG信息记录统一归档在OpenHamony/community仓库的sig目录内: - sig 独立目录下的OWNER存放相应sig的maintainer。 3. 代码的管理 - - 代码在[sig-manifest仓](https://gitee.com/openharmony-sig/manifest)下统一管理。 + - 代码在[sig-manifest仓]下统一管理。 - 需要各leader维护本组内对应仓的 .xml 文件。 - 多个单位参与,可向leader提出建仓需求,由leader向社区提建仓pr。 4. 文档的管理 - - 各sig组的公共文档(包括会议纪要、会议材料等)需放入[sig-content](https://gitee.com/openharmony-sig/sig-content) 仓对应组的文件夹内。 + - 各sig组的公共文档(包括会议纪要、会议材料等)需放入[sig-content]仓对应组的文件夹内。 - 与各sig组子任务密切相关的技术文档可放到任务对应的代码仓内。 5. 任务进度 diff --git a/website/docs/_posts/SIG/sigs_subsystem_list.md b/website/docs/_posts/SIG/sigs_subsystem_list.md index 6e142903494d302e2d4d41242fcd903d7eb445b3..a4cb52abea2be8d8ce918a25e5ac33c2cd46c842 100644 --- a/website/docs/_posts/SIG/sigs_subsystem_list.md +++ b/website/docs/_posts/SIG/sigs_subsystem_list.md @@ -6,6 +6,10 @@ comment: false editLink: false permalink: /SIG/sig_subsystem_list date: 2021-07-15 00:27:25 +categories: + - 随笔 +tags: + - --- |NO|SIG Name|SIG Tag Name|SIG Leader|Level 1 Subsystem Name| | :----: | :----: | :----: | :----: | :----: | diff --git a/website/docs/_posts/application-dev/ability/common-event.md b/website/docs/_posts/application-dev/ability/common-event.md new file mode 100644 index 0000000000000000000000000000000000000000..c574b881e3716751af850315c6ca9e239c83447e --- /dev/null +++ b/website/docs/_posts/application-dev/ability/common-event.md @@ -0,0 +1,538 @@ +--- +title: common-event.md +permalink: /pages/extra/d9a3ee/ +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +date: 2021-12-30 18:17:33 +--- +# CommonEvent开发指南 + +#### 基本概念 + +OpenHarmony通过CES(Common Event Service,公共事件服务)为应用程序提供订阅、发布、退订公共事件的能力。 + +公共事件可分为系统公共事件和自定义公共事件。 + +- 系统公共事件:系统将收集到的事件信息,根据系统策略发送给订阅该事件的用户程序。 例如:系统关键服务发布的系统事件(例如:hap安装,更新,卸载等)。 + +- 自定义公共事件:应用自定义一些公共事件用来实现跨应用的事件通信能力。 + +每个应用都可以按需订阅公共事件,订阅成功且公共事件发布,系统会把其发送给应用。这些公共事件可能来自系统、其他应用和应用自身。 + + + +#### 接口列表 + +| API | 手机 | 平板 | 智慧屏 | 智能穿戴 | 轻量级智能穿戴 | +| ------------------------------------------------------------ | ---- | ---- | ------ | -------- | -------------- | +| CommonEvent.publish(event: string, callback: AsyncCallback) | 支持 | 支持 | 支持 | 支持 | 不支持 | +| CommonEvent.publish(event: string, options: CommonEventPublishData, callback: AsyncCallback) | 支持 | 支持 | 支持 | 支持 | 不支持 | +| CommonEvent.createSubscriber(subscribeInfo: CommonEventSubscribeInfo, callback: AsyncCallback) | 支持 | 支持 | 支持 | 支持 | 不支持 | +| CommonEvent.createSubscriber(subscribeInfo: CommonEventSubscribeInfo) | 支持 | 支持 | 支持 | 支持 | 不支持 | +| CommonEvent.subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback) | 支持 | 支持 | 支持 | 支持 | 不支持 | +| CommonEvent.unsubscribe(subscriber: CommonEventSubscriber, callback?: AsyncCallback) | 支持 | 支持 | 支持 | 支持 | 不支持 | + + + +#### 导入模块 + +```js +import CommonEvent from '@ohos.commonevent'; +``` + + + +#### 创建公共事件订阅者 + +根据开发者设定的公共事件订阅相关信息(比如准备订阅的公共事件集等)创建公共事件订阅者对象。 + +- CommonEventSubscribeInfo类型说明 + + CommonEventSubscribeInfo封装公共事件订阅相关信息,比如准备订阅的公共事件集、发布者必须具备的权限、发布者的设备ID、发布者的用户ID、优先级等。 + + | 名称 | 读写属性 | 类型 | 必填 | 描述 | + | ------------------- | -------- | ------------- | ---- | ------------------------------------------------------------ | + | events | 只读 | Array | 是 | 表示要订阅的公共事件集。 | + | publisherPermission | 只读 | string | 否 | 表示发布者的权限。 | + | publisherDeviceId | 只读 | int | 否 | 表示发布者的设备ID,该值必须是同一ohos网络上的现有设备ID。 | + | userId | 只读 | int | 否 | 表示发布者的用户ID。默认值当前用户的ID。如果指定了此参数,则该值必须是系统中现有的用户ID。 | + | priority | 只读 | int | 否 | 表示订阅者的优先级,范围为-100~1000,用于有序公共事件。 | + +- CommonEventSubscriber 类说明 + + CommonEventSubscriber封装公共事件订阅者及相关参数,主要接口如下。 + + | 名称 | 参数 | 返回值 | 描述 | + | --------------------- | --------------------------------------------------------- | --------------------------------- | ------------------------------------------------------------ | + | getCode | callback: AsyncCallback | void | 获取公共事件的结果代码(callback形式) | + | getCode | void | Promise | 获取公共事件的结果代码(Promise形式) | + | setCode | code: number, callback: AsyncCallback | void | 设置有序公共事件的结果代码(callback形式) | + | setCode | code: number | Promise | 设置有序公共事件的结果代码(Promise形式) | + | getData | callback: AsyncCallback | void | 获取公共事件的结果数据(callback形式) | + | getData | void | Promise | 获取公共事件的结果数据(Promise形式) | + | setData | data: string, callback: AsyncCallback | void | 设置有序公共事件的结果数据(callback形式) | + | setData | data: string | Promise | 设置有序公共事件的结果数据(Promise形式) | + | setCodeAndData | code: number, data: string, callback: AsyncCallback | void | 设置有序公共事件的结果代码和结果数据(callback形式) | + | setCodeAndData | code: number, data: string | Promise | 设置有序公共事件的结果代码和结果数据(Promise形式) | + | isOrderedCommonEvent | callback: AsyncCallback | void | 查询当前公共事件的是否为有序公共事件,返回true代表是有序公共事件,false代表不是有序公共事件(callback形式) | + | isOrderedCommonEvent | void | Promise | 查询当前公共事件的是否为有序公共事件,返回true代表是有序公共事件,false代表不是有序公共事件(Promise形式) | + | abortCommonEvent | callback: AsyncCallback | void | 取消当前的公共事件,仅对有序公共事件有效,取消后,公共事件不再向下一个订阅者传递(callback形式) | + | abortCommonEvent | void | Promise | 取消当前的公共事件,仅对有序公共事件有效,取消后,公共事件不再向下一个订阅者传递(Promise形式) | + | clearAbortCommonEvent | callback: AsyncCallback | void | 清除当前有序公共事件abort状态(callback形式) | + | clearAbortCommonEvent | void | Promise | 清除当前有序公共事件abort状态(Promise形式) | + | getAbortCommonEvent | callback: AsyncCallback | void | 获取当前有序公共事件是否取消的状态(callback形式) | + | getAbortCommonEvent | void | Promise | 获取当前有序公共事件是否取消的状态Promise形式) | + | getSubscribeInfo | callback: AsyncCallback | void | 获取订阅者的订阅信息(callback形式) | + | getSubscribeInfo | void | Promise | 获取订阅者的订阅信息(Promise形式) | + + + +- 创建订阅者接口(callback形式) + + CommonEvent.createSubscriber(subscribeInfo: CommonEventSubscribeInfo, callback: AsyncCallback) + + - 接口参数描述 + + + | 名称 | 读写属性 | 类型 | 必填 | 描述 | + | ------------- | -------- | ------------------------------------ | ---- | ------------------------ | + | subscribeInfo | 只读 | CommonEventSubscribeInfo | 是 | 表示公共事件订阅信息 | + | callback | 只读 | AsyncCallback | 是 | 表示创建订阅者的回调方法 | + + - 返回值 + + void + + - 示例代码 + + ```js + var subscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 + //订阅者信息 + var subscribeInfo = { + events: ["event"] + }; + //创建订阅者回调 + function CreateSubscriberCallBack(err, data) { + console.info("==========================>CreateSubscriberCallBack=======================>"); + subscriber = data; + } + //创建订阅者 + CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack); + ``` + +- 创建订阅者接口(Promise形式) + + CommonEvent.createSubscriber(subscribeInfo: CommonEventSubscribeInfo) + + - 接口参数描述 + + | 名称 | 读写属性 | 类型 | 必填 | 描述 | + | ------------- | -------- | ------------------------ | ---- | ------------ | + | subscribeInfo | 只读 | CommonEventSubscribeInfo | 是 | 表示订阅信息 | + + - 返回值 + + Promise + + - 示例代码 + + ```js + var subscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 + //订阅者信息 + var subscribeInfo = { + events: ["event"] + }; + //创建订阅者 + CommonEvent.createSubscriber(subscribeInfo).then((data) => { + ``` + + console.info("==========================>createSubscriberPromise=======================>"); + subscriber = data; + }); + ``` + + + +#### 订阅公共事件 + +订阅公共事件,并指定公共事件订阅者对象和接收公共事件的回调函数。 + +- CommonEventData类型说明 + + CommonEventData封装公共事件相关信息。用于在接收时处理数据。 + + | 名称 | 读写属性 | 类型 | 必填 | 描述 | + | ---------- | -------- | -------------------- | ---- | ------------------------------------------------------- | + | event | 只读 | string | 是 | 表示当前接收的公共事件名称 | + | bundleName | 只读 | string | 否 | 表示包名称 | + | code | 只读 | int | 否 | 表示公共事件的结果代码,用于传递int类型的数据 | + | data | 只读 | string | 否 | 表示公共事件的自定义结果数据,用于传递string 类型的数据 | + | parameters | 只读 | {[key: string]: any} | 否 | 表示公共事件的附加信息 | + +- 订阅公共事件接口(callback形式) + + CommonEvent.subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback) + + - 接口参数描述 + + | 名称 | 读写属性 | 类型 | 必填 | 描述 | + | ---------- | -------- | ------------------------------ | ---- | ------------------------------ | + | subscriber | 只读 | CommonEventSubscriber | 是 | 表示订阅者对象 | + | callback | 只读 | AsyncCallback | 是 | 表示接收公共事件数据的回调函数 | + + - 返回值 + + void + + - 示例代码 + + **无序事件:** + + ```js + var subscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 + //订阅者信息 + var subscribeInfo = { + events: ["event"] + }; + //订阅公共事件回调 + function SubscribeCallBack(err, data) { + console.info("==========================>SubscribeCallBack=======================>"); + } + //创建订阅者回调 + function CreateSubscriberCallBack(err, data) { + console.info("==========================>CreateSubscriberCallBack=======================>"); + subscriber = data; + //订阅公共事件 + CommonEvent.subscribe(subscriber, SubscribeCallBack); + } + //创建订阅者 + CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack); + ``` + + **有序事件:** + + ```js + var subscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 + //订阅者信息 + var subscribeInfo = { + events: ["event"] + }; + + //设置有序公共事件的结果代码回调 + function SetCodeCallBack(err) { + console.info("==========================>SetCodeCallBack=======================>"); + } + //设置有序公共事件的结果数据回调 + function SetDataCallBack(err) { + console.info("==========================>SetDataCallBack=======================>"); + } + //完成本次有序公共事件处理回调 + function FinishCommonEventCallBack(err) { + console.info("==========================>FinishCommonEventCallBack=======================>"); + } + //订阅公共事件回调 + function SubscribeCallBack(err, data) { + console.info("==========================>SubscribeCallBack=======================>"); + //设置有序公共事件的结果代码 + subscriber.setCode(0, SetCodeCallBack); + //设置有序公共事件的结果数据 + subscriber.setData("publish_data_changed", SetDataCallBack); + //完成本次有序公共事件处理 + subscriber.finishCommonEvent(FinishCommonEventCallBack) + } + + //创建订阅者回调 + function CreateSubscriberCallBack(err, data) { + console.info("==========================>CreateSubscriberCallBack=======================>"); + subscriber = data; + //订阅公共事件 + CommonEvent.subscribe(subscriber, SubscribeCallBack); + } + + //创建订阅者 + CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack); + ``` + + +​ + +#### 发布公共事件 + +发布指定事件名称的公共事件,并可携带事件相关数据、属性、限制等信息。 + +- CommonEventPublishData类型说明 + + CommonEventPublishData封装公共事件发布相关数据、属性及限制等信息,包括公共事件类型(有序或无序)、订阅者所需权限等。 + + | 名称 | 读写属性 | 类型 | 必填 | 描述 | + | --------------------- | -------- | -------------------- | ---- | ---------------------------- | + | bundleName | 只读 | string | 否 | 表示包名称 | + | code | 只读 | int | 否 | 表示公共事件的结果代码 | + | data | 只读 | string | 否 | 表示公共事件的自定义结果数据 | + | subscriberPermissions | 只读 | Array | 否 | 表示订阅者所需的权限 | + | isOrdered | 只读 | bool | 否 | 表示是否是有序事件 | + | parameters | 只读 | {[key: string]: any} | 否 | 表示公共事件的附加信息 | + +- 发布公共事件接口(callback形式) + + CommonEvent.publish(event: string, callback: AsyncCallback) + + - 接口参数描述 + + | 名称 | 读写属性 | 类型 | 必填 | 描述 | + | -------- | -------- | ------------------- | ---- | ------------------------ | + | event | 只读 | string | 是 | 表示要发送的公共事件名称 | + | callback | 只读 | AsyncCallback | 是 | 表示被指定的回调方法 | + + - 返回值 + + void + + - 示例代码 + + ```js + //发布公共事件回调 + function PublishCallBack(err) { + console.info("==========================>PublishCallBack=======================>"); + console.info("==========================>err:=======================>", err.code); + } + //发布公共事件 + CommonEvent.publish("publish_event", PublishCallBack); + ``` + +- 发布公共事件指定发布信息接口(callback形式) + + CommonEvent.publish(event: string, options: CommonEventPublishData, callback: AsyncCallback) + + - 接口参数描述 + + | 名称 | 读写属性 | 类型 | 必填 | 描述 | + | -------- | -------- | ---------------------- | ---- | ------------------------ | + | event | 只读 | string | 是 | 表示要发布的公共事件名称 | + | options | 只读 | CommonEventPublishData | 是 | 表示发布公共事件的属性 | + | callback | 只读 | AsyncCallback | 是 | 表示被指定的回调方法 | + + - 返回值 + + void + + - 示例代码 + + ```js + //公共事件相关信息 + var options = { + code: 0; //公共事件的初始代码 + data: "initial data"; //公共事件的初始数据 + isOrdered: true; //有序公共事件 + } + //发布公共事件回调 + function PublishCallBack(err) { + console.info("==========================>PublishCallBack=======================>"); + } + //发布公共事件 + CommonEvent.publish("publish_event", options, PublishCallBack); + ``` + + + + +#### 取消订阅公共事件 + +- 取消订阅公共事件接口(callback形式) + + CommonEvent.unsubscribe(subscriber: CommonEventSubscriber, callback?: AsyncCallback) + + - 接口参数描述 + + | 名称 | 读写属性 | 类型 | 必填 | 描述 | + | ---------- | -------- | --------------------- | ---- | ---------------------- | + | subscriber | 只读 | CommonEventSubscriber | 是 | 表示订阅者对象 | + | callback | 只读 | AsyncCallback | 是 | 表示取消订阅的回调方法 | + + - 返回值 + + void + + - 示例代码 + + ```js + var subscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 + //订阅者信息 + var subscribeInfo = { + events: ["event"] + }; + //订阅公共事件回调 + function SubscribeCallBack(err, data) { + console.info("==========================>SubscribeCallBack=======================>"); + } + //创建订阅者回调 + function CreateSubscriberCallBack(err, data) { + console.info("==========================>CreateSubscriberCallBack=======================>"); + subscriber = data; + //订阅公共事件 + CommonEvent.subscribe(subscriber, SubscribeCallBack); + } + //取消订阅公共事件回调 + function UnsubscribeCallBack(err) { + console.info("==========================>UnsubscribeCallBack=======================>"); + } + //创建订阅者 + CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack); + //取消订阅公共事件 + CommonEvent.unsubscribe(subscriber, UnsubscribeCallBack); + ``` + + + + +#### 系统公共事件列表 + +| 系统公共事件宏 | 系统公共事件名称 | 订阅者所需权限 | +| ------------------------------------------------------------ | ----------------------------------------------------------- | ------------------------------------------------------------ | +| COMMON_EVENT_BOOT_COMPLETED | usual.event.BOOT_COMPLETED | ohos.permission.RECEIVER_STARTUP_COMPLETED | +| COMMON_EVENT_LOCKED_BOOT_COMPLETED | usual.event.LOCKED_BOOT_COMPLETED | ohos.permission.RECEIVER_STARTUP_COMPLETED | +| COMMON_EVENT_SHUTDOWN | usual.event.SHUTDOWN | 无 | +| COMMON_EVENT_BATTERY_CHANGED | usual.event.BATTERY_CHANGED | 无 | +| COMMON_EVENT_BATTERY_LOW | usual.event.BATTERY_LOW | 无 | +| COMMON_EVENT_BATTERY_OKAY | usual.event.BATTERY_OKAY | 无 | +| COMMON_EVENT_POWER_CONNECTED | usual.event.POWER_CONNECTED | 无 | +| COMMON_EVENT_POWER_DISCONNECTED | usual.event.POWER_DISCONNECTED | 无 | +| COMMON_EVENT_SCREEN_OFF | usual.event.SCREEN_OFF | 无 | +| COMMON_EVENT_SCREEN_ON | usual.event.SCREEN_ON | 无 | +| COMMON_EVENT_USER_PRESENT | usual.event.USER_PRESENT | 无 | +| COMMON_EVENT_TIME_TICK | usual.event.TIME_TICK | 无 | +| COMMON_EVENT_TIME_CHANGED | usual.event.TIME_CHANGED | 无 | +| COMMON_EVENT_DATE_CHANGED | usual.event.DATE_CHANGED | 无 | +| COMMON_EVENT_TIMEZONE_CHANGED | usual.event.TIMEZONE_CHANGED | 无 | +| COMMON_EVENT_CLOSE_SYSTEM_DIALOGS | usual.event.CLOSE_SYSTEM_DIALOGS | 无 | +| COMMON_EVENT_PACKAGE_ADDED | usual.event.PACKAGE_ADDED | 无 | +| COMMON_EVENT_PACKAGE_REPLACED | usual.event.PACKAGE_REPLACED | 无 | +| COMMON_EVENT_MY_PACKAGE_REPLACED | usual.event.MY_PACKAGE_REPLACED | 无 | +| COMMON_EVENT_PACKAGE_REMOVED | usual.event.PACKAGE_REMOVED | 无 | +| COMMON_EVENT_PACKAGE_FULLY_REMOVED | usual.event.PACKAGE_FULLY_REMOVED | 无 | +| COMMON_EVENT_PACKAGE_CHANGED | usual.event.PACKAGE_CHANGED | 无 | +| COMMON_EVENT_PACKAGE_RESTARTED | usual.event.PACKAGE_RESTARTED | 无 | +| COMMON_EVENT_PACKAGE_DATA_CLEARED | usual.event.PACKAGE_DATA_CLEARED | 无 | +| COMMON_EVENT_PACKAGES_SUSPENDED | usual.event.PACKAGES_SUSPENDED | 无 | +| COMMON_EVENT_PACKAGES_UNSUSPENDED | usual.event.PACKAGES_UNSUSPENDED | 无 | +| COMMON_EVENT_MY_PACKAGE_SUSPENDED | usual.event.MY_PACKAGE_SUSPENDED | 无 | +| COMMON_EVENT_MY_PACKAGE_UNSUSPENDED | usual.event.MY_PACKAGE_UNSUSPENDED | 无 | +| COMMON_EVENT_UID_REMOVED | usual.event.UID_REMOVED | 无 | +| COMMON_EVENT_PACKAGE_FIRST_LAUNCH | usual.event.PACKAGE_FIRST_LAUNCH | 无 | +| COMMON_EVENT_PACKAGE_NEEDS_VERIFICATION | usual.event.PACKAGE_NEEDS_VERIFICATION | 无 | +| COMMON_EVENT_PACKAGE_VERIFIED | usual.event.PACKAGE_VERIFIED | 无 | +| COMMON_EVENT_EXTERNAL_APPLICATIONS_AVAILABLE | usual.event.EXTERNAL_APPLICATIONS_AVAILABLE | 无 | +| COMMON_EVENT_EXTERNAL_APPLICATIONS_UNAVAILABLE | usual.event.EXTERNAL_APPLICATIONS_UNAVAILABLE | 无 | +| COMMON_EVENT_CONFIGURATION_CHANGED | usual.event.CONFIGURATION_CHANGED | 无 | +| COMMON_EVENT_LOCALE_CHANGED | usual.event.LOCALE_CHANGED | 无 | +| COMMON_EVENT_MANAGE_PACKAGE_STORAGE | usual.event.MANAGE_PACKAGE_STORAGE | 无 | +| COMMON_EVENT_DRIVE_MODE | common.event.DRIVE_MODE | 无 | +| COMMON_EVENT_HOME_MODE | common.event.HOME_MODE | 无 | +| COMMON_EVENT_OFFICE_MODE | common.event.OFFICE_MODE | 无 | +| COMMON_EVENT_USER_STARTED | usual.event.USER_STARTED | 无 | +| COMMON_EVENT_USER_BACKGROUND | usual.event.USER_BACKGROUND | 无 | +| COMMON_EVENT_USER_FOREGROUND | usual.event.USER_FOREGROUND | 无 | +| COMMON_EVENT_USER_SWITCHED | usual.event.USER_SWITCHED | ohos.permission.MANAGE_USERS | +| COMMON_EVENT_USER_STARTING | usual.event.USER_STARTING | ohos.permission.INTERACT_ACROSS_USERS | +| COMMON_EVENT_USER_UNLOCKED | usual.event.USER_UNLOCKED | 无 | +| COMMON_EVENT_USER_STOPPING | usual.event.USER_STOPPING | ohos.permission.INTERACT_ACROSS_USERS | +| COMMON_EVENT_USER_STOPPED | usual.event.USER_STOPPED | 无 | +| COMMON_EVENT_HWID_LOGIN | common.event.HWID_LOGIN | 无 | +| COMMON_EVENT_HWID_LOGOUT | common.event.HWID_LOGOUT | 无 | +| COMMON_EVENT_HWID_TOKEN_INVALID | common.event.HWID_TOKEN_INVALID | 无 | +| COMMON_EVENT_HWID_LOGOFF | common.event.HWID_LOGOFF | 无 | +| COMMON_EVENT_WIFI_POWER_STATE | usual.event.wifi.POWER_STATE | 无 | +| COMMON_EVENT_WIFI_SCAN_FINISHED | usual.event.wifi.SCAN_FINISHED | ohos.permission.LOCATION | +| COMMON_EVENT_WIFI_RSSI_VALUE | usual.event.wifi.RSSI_VALUE | ohos.permission.GET_WIFI_INFO | +| COMMON_EVENT_WIFI_CONN_STATE | usual.event.wifi.CONN_STATE | 无 | +| COMMON_EVENT_WIFI_HOTSPOT_STATE | usual.event.wifi.HOTSPOT_STATE | 无 | +| COMMON_EVENT_WIFI_AP_STA_JOIN | usual.event.wifi.WIFI_HS_STA_JOIN | ohos.permission.GET_WIFI_INFO | +| COMMON_EVENT_WIFI_AP_STA_LEAVE | usual.event.wifi.WIFI_HS_STA_LEAVE | ohos.permission.GET_WIFI_INFO | +| COMMON_EVENT_WIFI_MPLINK_STATE_CHANGE | usual.event.wifi.mplink.STATE_CHANGE | ohos.permission.MPLINK_CHANGE_STATE | +| COMMON_EVENT_WIFI_P2P_CONN_STATE | usual.event.wifi.p2p.CONN_STATE_CHANGE | ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION | +| COMMON_EVENT_WIFI_P2P_STATE_CHANGED | usual.event.wifi.p2p.STATE_CHANGE | ohos.permission.GET_WIFI_INFO | +| COMMON_EVENT_WIFI_P2P_PEERS_STATE_CHANGED | usual.event.wifi.p2p.DEVICES_CHANGE | ohos.permission.GET_WIFI_INFO | +| COMMON_EVENT_WIFI_P2P_PEERS_DISCOVERY_STATE_CHANGED | usual.event.wifi.p2p.PEER_DISCOVERY_STATE_CHANGE | ohos.permission.GET_WIFI_INFO | +| COMMON_EVENT_WIFI_P2P_CURRENT_DEVICE_STATE_CHANGED | usual.event.wifi.p2p.CURRENT_DEVICE_CHANGE | ohos.permission.GET_WIFI_INFO | +| COMMON_EVENT_WIFI_P2P_GROUP_STATE_CHANGED | usual.event.wifi.p2p.GROUP_STATE_CHANGED | ohos.permission.GET_WIFI_INFO | +| COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_CONNECT_STATE_UPDATE | usual.event.bluetooth.handsfree.ag.CONNECT_STATE_UPDATE | ohos.permission.USE_BLUETOOTH | +| COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_CURRENT_DEVICE_UPDATE | usual.event.bluetooth.handsfree.ag.CURRENT_DEVICE_UPDATE | ohos.permission.USE_BLUETOOTH | +| COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_AUDIO_STATE_UPDATE | usual.event.bluetooth.handsfree.ag.AUDIO_STATE_UPDATE | ohos.permission.USE_BLUETOOTH | +| COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CONNECT_STATE_UPDATE | usual.event.bluetooth.a2dpsource.CONNECT_STATE_UPDATE | ohos.permission.USE_BLUETOOTH | +| COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CURRENT_DEVICE_UPDATE | usual.event.bluetooth.a2dpsource.CURRENT_DEVICE_UPDATE | ohos.permission.USE_BLUETOOTH | +| COMMON_EVENT_BLUETOOTH_A2DPSOURCE_PLAYING_STATE_UPDATE | usual.event.bluetooth.a2dpsource.PLAYING_STATE_UPDATE" | ohos.permission.USE_BLUETOOTH | +| COMMON_EVENT_BLUETOOTH_A2DPSOURCE_AVRCP_CONNECT_STATE_UPDATE | usual.event.bluetooth.a2dpsource.AVRCP_CONNECT_STATE_UPDATE | ohos.permission.USE_BLUETOOTH | +| COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CODEC_VALUE_UPDATE | usual.event.bluetooth.a2dpsource.CODEC_VALUE_UPDATE | ohos.permission.USE_BLUETOOTH | +| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_DISCOVERED | usual.event.bluetooth.remotedevice.DISCOVERED | ohos.permission.USE_BLUETOOTH and ohos.permission.LOCATION | +| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CLASS_VALUE_UPDATE | usual.event.bluetooth.remotedevice.CLASS_VALUE_UPDATE | ohos.permission.USE_BLUETOOTH | +| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_ACL_CONNECTED | usual.event.bluetooth.remotedevice.ACL_CONNECTED | ohos.permission.USE_BLUETOOTH | +| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_ACL_DISCONNECTED | usual.event.bluetooth.remotedevice.ACL_DISCONNECTED | ohos.permission.USE_BLUETOOTH | +| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_NAME_UPDATE | usual.event.bluetooth.remotedevice.NAME_UPDATE | ohos.permission.USE_BLUETOOTH | +| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIR_STATE | usual.event.bluetooth.remotedevice.PAIR_STATE | ohos.permission.USE_BLUETOOTH | +| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_BATTERY_VALUE_UPDATE | usual.event.bluetooth.remotedevice.BATTERY_VALUE_UPDATE | ohos.permission.USE_BLUETOOTH | +| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_SDP_RESULT | usual.event.bluetooth.remotedevice.SDP_RESULT | 无 | +| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_UUID_VALUE | usual.event.bluetooth.remotedevice.UUID_VALUE | ohos.permission.DISCOVER_BLUETOOTH | +| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIRING_REQ | usual.event.bluetooth.remotedevice.PAIRING_REQ | ohos.permission.DISCOVER_BLUETOOTH | +| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIRING_CANCEL | usual.event.bluetooth.remotedevice.PAIRING_CANCEL | 无 | +| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CONNECT_REQ | usual.event.bluetooth.remotedevice.CONNECT_REQ | 无 | +| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CONNECT_REPLY | usual.event.bluetooth.remotedevice.CONNECT_REPLY | 无 | +| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CONNECT_CANCEL | usual.event.bluetooth.remotedevice.CONNECT_CANCEL | 无 | +| COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_CONNECT_STATE_UPDATE | usual.event.bluetooth.handsfreeunit.CONNECT_STATE_UPDATE | 无 | +| COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_AUDIO_STATE_UPDATE | usual.event.bluetooth.handsfreeunit.AUDIO_STATE_UPDATE | 无 | +| COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_AG_COMMON_EVENT | usual.event.bluetooth.handsfreeunit.AG_COMMON_EVENT | 无 | +| COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_AG_CALL_STATE_UPDATE | usual.event.bluetooth.handsfreeunit.AG_CALL_STATE_UPDATE | 无 | +| COMMON_EVENT_BLUETOOTH_HOST_STATE_UPDATE | usual.event.bluetooth.host.STATE_UPDATE | 无 | +| COMMON_EVENT_BLUETOOTH_HOST_REQ_DISCOVERABLE | usual.event.bluetooth.host.REQ_DISCOVERABLE | 无 | +| COMMON_EVENT_BLUETOOTH_HOST_REQ_ENABLE | usual.event.bluetooth.host.REQ_ENABLE | ohos.permission.USE_BLUETOOTH | +| COMMON_EVENT_BLUETOOTH_HOST_REQ_DISABLE | usual.event.bluetooth.host.REQ_DISABLE | ohos.permission.USE_BLUETOOTH | +| COMMON_EVENT_BLUETOOTH_HOST_SCAN_MODE_UPDATE | usual.event.bluetooth.host.SCAN_MODE_UPDATE | ohos.permission.USE_BLUETOOTH | +| COMMON_EVENT_BLUETOOTH_HOST_DISCOVERY_STARTED | usual.event.bluetooth.host.DISCOVERY_STARTED | ohos.permission.USE_BLUETOOTH | +| COMMON_EVENT_BLUETOOTH_HOST_DISCOVERY_FINISHED | usual.event.bluetooth.host.DISCOVERY_FINISHED | ohos.permission.USE_BLUETOOTH | +| COMMON_EVENT_BLUETOOTH_HOST_NAME_UPDATE | usual.event.bluetooth.host.NAME_UPDATE | ohos.permission.USE_BLUETOOTH | +| COMMON_EVENT_BLUETOOTH_A2DPSINK_CONNECT_STATE_UPDATE | usual.event.bluetooth.a2dpsink.CONNECT_STATE_UPDATE | ohos.permission.USE_BLUETOOTH | +| COMMON_EVENT_BLUETOOTH_A2DPSINK_PLAYING_STATE_UPDATE | usual.event.bluetooth.a2dpsink.PLAYING_STATE_UPDATE | ohos.permission.USE_BLUETOOTH | +| COMMON_EVENT_BLUETOOTH_A2DPSINK_AUDIO_STATE_UPDATE | usual.event.bluetooth.a2dpsink.AUDIO_STATE_UPDATE | ohos.permission.USE_BLUETOOTH | +| COMMON_EVENT_NFC_ACTION_ADAPTER_STATE_CHANGED | usual.event.nfc.action.ADAPTER_STATE_CHANGED | 无 | +| COMMON_EVENT_NFC_ACTION_RF_FIELD_ON_DETECTED | usual.event.nfc.action.RF_FIELD_ON_DETECTED | ohos.permission.MANAGE_SECURE_SETTINGS | +| COMMON_EVENT_NFC_ACTION_RF_FIELD_OFF_DETECTED | usual.event.nfc.action.RF_FIELD_OFF_DETECTED | ohos.permission.MANAGE_SECURE_SETTINGS | +| COMMON_EVENT_DISCHARGING | usual.event.DISCHARGING | 无 | +| COMMON_EVENT_CHARGING | usual.event.CHARGING | 无 | +| COMMON_EVENT_DEVICE_IDLE_MODE_CHANGED | usual.event.DEVICE_IDLE_MODE_CHANGED | 无 | +| COMMON_EVENT_POWER_SAVE_MODE_CHANGED | usual.event.POWER_SAVE_MODE_CHANGED | 无 | +| COMMON_EVENT_USER_ADDED | usual.event.USER_ADDED | ohos.permission.MANAGE_USERS | +| COMMON_EVENT_USER_REMOVED | usual.event.USER_REMOVED | ohos.permission.MANAGE_USERS | +| COMMON_EVENT_ABILITY_ADDED | common.event.ABILITY_ADDED | ohos.permission.LISTEN_BUNDLE_CHANGE | +| COMMON_EVENT_ABILITY_REMOVED | common.event.ABILITY_REMOVED | ohos.permission.LISTEN_BUNDLE_CHANGE | +| COMMON_EVENT_ABILITY_UPDATED | common.event.ABILITY_UPDATED | ohos.permission.LISTEN_BUNDLE_CHANGE | +| COMMON_EVENT_LOCATION_MODE_STATE_CHANGED | usual.event.location.MODE_STATE_CHANGED | 无 | +| COMMON_EVENT_IVI_SLEEP | common.event.IVI_SLEEP | 无 | +| COMMON_EVENT_IVI_PAUSE | common.event.IVI_PAUSE | 无 | +| COMMON_EVENT_IVI_STANDBY | common.event.IVI_STANDBY | 无 | +| COMMON_EVENT_IVI_LASTMODE_SAVE | common.event.IVI_LASTMODE_SAVE | 无 | +| COMMON_EVENT_IVI_VOLTAGE_ABNORMAL | common.event.IVI_VOLTAGE_ABNORMAL | 无 | +| COMMON_EVENT_IVI_HIGH_TEMPERATURE | common.event.IVI_HIGH_TEMPERATURE | 无 | +| COMMON_EVENT_IVI_EXTREME_TEMPERATURE | common.event.IVI_EXTREME_TEMPERATURE | 无 | +| COMMON_EVENT_IVI_TEMPERATURE_ABNORMAL | common.event.IVI_TEMPERATURE_ABNORMAL | 无 | +| COMMON_EVENT_IVI_VOLTAGE_RECOVERY | common.event.IVI_VOLTAGE_RECOVERY | 无 | +| COMMON_EVENT_IVI_TEMPERATURE_RECOVERY | common.event.IVI_TEMPERATURE_RECOVERY | 无 | +| COMMON_EVENT_IVI_ACTIVE | common.event.IVI_ACTIVE | 无 | +| COMMON_EVENT_USB_DEVICE_ATTACHED | usual.event.hardware.usb.action.USB_DEVICE_ATTACHED | 无 | +| COMMON_EVENT_USB_DEVICE_DETACHED | usual.event.hardware.usb.action.USB_DEVICE_DETACHED | 无 | +| COMMON_EVENT_USB_ACCESSORY_ATTACHED | usual.event.hardware.usb.action.USB_ACCESSORY_ATTACHED | 无 | +| COMMON_EVENT_USB_ACCESSORY_DETACHED | usual.event.hardware.usb.action.USB_ACCESSORY_DETACHED | 无 | +| COMMON_EVENT_DISK_REMOVED | usual.event.data.DISK_REMOVED | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE | +| COMMON_EVENT_DISK_UNMOUNTED | usual.event.data.DISK_UNMOUNTED | ohos.permission.WRITE_USER_STORAGEor ohos.permission.READ_USER_STORAGE | +| COMMON_EVENT_DISK_MOUNTED | usual.event.data.DISK_MOUNTED | ohos.permission.WRITE_USER_STORAGEor ohos.permission.READ_USER_STORAGE | +| COMMON_EVENT_DISK_BAD_REMOVAL | usual.event.data.DISK_BAD_REMOVAL | ohos.permission.WRITE_USER_STORAGEor ohos.permission.READ_USER_STORAGE | +| COMMON_EVENT_DISK_UNMOUNTABLE | usual.event.data.DISK_UNMOUNTABLE | ohos.permission.WRITE_USER_STORAGEor ohos.permission.READ_USER_STORAGE | +| COMMON_EVENT_DISK_EJECT | usual.event.data.DISK_EJECT | ohos.permission.WRITE_USER_STORAGEor ohos.permission.READ_USER_STORAGE | +| COMMON_EVENT_VISIBLE_ACCOUNTS_UPDATED | usual.event.data.VISIBLE_ACCOUNTS_UPDATED | ohos.permission.GET_APP_ACCOUNTS | +| COMMON_EVENT_ACCOUNT_DELETED | usual.event.data.ACCOUNT_DELETED | ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS | +| COMMON_EVENT_FOUNDATION_READY | common.event.FOUNDATION_READY | ohos.permission.RECEIVER_STARTUP_COMPLETED | +| COMMON_EVENT_AIRPLANE_MODE_CHANGED | usual.event.AIRPLANE_MODE | 无 | diff --git a/website/docs/_posts/application-dev/quick-start/create-openharmony-project.md b/website/docs/_posts/application-dev/quick-start/create-openharmony-project.md new file mode 100644 index 0000000000000000000000000000000000000000..ab7e588a810fe59341cf8c72cbe0c1a386454de5 --- /dev/null +++ b/website/docs/_posts/application-dev/quick-start/create-openharmony-project.md @@ -0,0 +1,19 @@ +--- +title: create-openharmony-project.md +permalink: /pages/extra/ea2f5f/ +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +date: 2021-12-30 18:17:38 +--- +# 创建OpenHarmony工程 + + +- **[使用工程向导创建新工程](/pages/0007050300)** + +- **[通过导入Sample方式创建新工程](/pages/0007050301)** \ No newline at end of file diff --git a/website/docs/_posts/application-dev/quick-start/deveco-studio-user-guide-for-openharmony.md b/website/docs/_posts/application-dev/quick-start/deveco-studio-user-guide-for-openharmony.md new file mode 100644 index 0000000000000000000000000000000000000000..8276a74d4ef1f13031b6e82a72b8abb662b1bb98 --- /dev/null +++ b/website/docs/_posts/application-dev/quick-start/deveco-studio-user-guide-for-openharmony.md @@ -0,0 +1,27 @@ +--- +title: deveco-studio-user-guide-for-openharmony.md +permalink: /pages/extra/00c2e5/ +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +date: 2021-12-30 18:17:38 +--- +# DevEco Studio(OpenHarmony)使用指南 + + +- **[概述](/pages/00070500)** + +- **[版本变更说明](/pages/00070501)** + +- **[配置OpenHarmony SDK](/pages/00070502)** + +- **[创建OpenHarmony工程](/pages/extra/ea2f5f/)** + +- **[配置OpenHarmony应用签名信息](/pages/00070504)** + +- **[安装运行OpenHarmony应用](/pages/00070505)** \ No newline at end of file diff --git a/website/docs/_posts/contribute/OpenHarmony-Java-secure-coding-guide.md b/website/docs/_posts/contribute/OpenHarmony-Java-secure-coding-guide.md new file mode 100644 index 0000000000000000000000000000000000000000..f41238ed315f8853241f5cf0cb1fcc85309860d4 --- /dev/null +++ b/website/docs/_posts/contribute/OpenHarmony-Java-secure-coding-guide.md @@ -0,0 +1,2111 @@ +--- +title: OpenHarmony-Java-secure-coding-guide.md +permalink: /pages/extra/6cbd43/ +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +date: 2021-12-30 18:17:45 +--- +# OpenHarmony Java 安全编程指南 + +本文档基于Java 语言提供一些安全编程建议,用于指导开发实践。 + +# 数据类型 + +## 进行数值运算时,避免整数溢出 + +**【描述】** + +在进行数值运算过程中,确保运算结果在特定的整数类型的数据范围内,避免溢出,导致非预期的结果。 + +内置的整数运算符不会以任何方式来标识运算结果的上溢或下溢。常见的加、减、乘、除都可能会导致整数溢出。另外,Java数据类型的合法取值范围是不对称的(最小值的绝对值比最大值大1),所以对最小值取绝对值(`java.lang.Math.abs()`)时,也会导致溢出。 + +对于整数溢出问题,可以通过先决条件检测、使用Math类的安全方法、向上类型转换或者使用`BigInteger`等方法进行规避。 + +**【反例】** + +```java +public static int multNum(int num1, int num2) { + return num1 * num2; +} +``` + +上述示例中,当num1和num2的绝对值较大,两者的乘积大于`Integer.MAX_VALUE`或小于`Integer.MIN_VALUE`时,方法就无法返回正确的计算结果(产生溢出)。 + +**【正例】** + +```java +public static int multNum(int num1, int num2) { + return Math.multiplyExact(num1, num2); +} +``` + +上述示例中,当无法预判乘积结果是否会产生溢出时,使用了Java 8新增的`Math.multiplyExact()`方法,该方法在乘积运算不产生溢出时会返回运算结果,溢出时抛出`ArithmeticException`。 + +## 确保除法运算和模运算中的除数不为0 + +**【描述】** + +如果除法或模运算中的除数为零可能会导致程序终止或拒绝服务(DoS),因此需要在运算前保证除数不为0。 + +**【反例】** + +```java +long dividendNum = 0; +long divisorNum = 0; +long result1 = dividendNum / divisorNum; +long result2 = dividendNum % divisorNum; +``` + +上述示例中,没有对除数进行非零判断,会导致程序运行错误。 + +**【正例】** + +```java +long dividendNum = 0; +long divisorNum = 0; +if (divisorNum != 0) { + long result1 = dividendNum / divisorNum; + long result2 = dividendNum % divisorNum; +} +``` + +上述示例中,对除数进行非零判断,然后再进行除法或取余运算。 + +# 表达式 + +## 禁止直接使用可能为null的对象,防止出现空指针引用 + +**【描述】** + +访问一个为null的对象时,会导致空引用问题,代码中抛出`NullPointerException`。该类问题应该通过预检查的方式进行消解,而不是通过`try...catch`机制处理`NullPointerException`。 + +**【反例】** + +```java +String env = System.getenv(SOME_ENV); +if (env.length() > MAX_LENGTH) { + ... +} +``` + +上述示例中,`System.getenv()`返回值可能为null,代码中在使用变量`env`前未判空,会发生空指针引用。 + +**【正例】** + +```java +String env = System.getenv(SOME_ENV); +if (env != null && env.length() > MAX_LENGTH) { + ... +} +``` + +上述示例中,对`System.getenv()`返回值先判空再使用,消除了空指针引用问题。 + +# 并发与多线程 + +## 在异常条件下,保证释放已持有的锁 + +**【描述】** + +一个线程中没有正确释放持有的锁会导致其他线程无法获取该锁对象,导致阻塞。在发生异常时,需要确保程序正确释放当前持有的锁。在异常条件下,同步方法或者块同步中使用的对象内置锁会自动释放。但是大多数的Java锁对象并不是Closeable,无法使用try-with-resources功能自动释放,在这种情况下需要主动释放锁。 + +**【反例】**(可检查异常) + +```java +public final class Foo { + private final Lock lock = new ReentrantLock(); + + public void incorrectReleaseLock() { + try { + lock.lock(); + doSomething(); + lock.unlock(); + } catch (MyBizException ex) { + // 处理异常 + } + } + + private void doSomething() throws MyBizException { + ... + } +} +``` + +上述代码示例中,使用了`ReentrantLock`锁,当`doSomething()`方法抛出异常时,catch代码块中没有释放锁操作,导致锁没有释放。 + +**【正例】**(finally代码块) + +```java +public final class Foo { + private final Lock lock = new ReentrantLock(); + + public void correctReleaseLock() { + lock.lock(); + try { + doSomething(); + } catch (MyBizException ex) { + // 处理异常 + } finally { + lock.unlock(); + } + } + + private void doSomething() throws MyBizException { + ... + } +} +``` + +上述代码示例中,成功执行锁定操作后,将可能抛出异常的操作封装在try代码块中。锁在执行try代码块前获取,可保证在执行finally代码时正确持有锁。在finally代码块中调用`lock.unlock()`,可以保证不管是否发生异常都可以释放锁。 + +**【反例】**(未检查异常) + +```java +final class Foo { + private final Lock lock = new ReentrantLock(); + + public void incorrectReleaseLock(String value) { + lock.lock(); + ... + int index = Integer.parseInt(value); + ... + lock.unlock(); + } +} +``` + +上述代码示例中,当`incorrectReleaseLock()`方法传入的String不是数字时,后续的操作会抛出`NumberFormatException`,导致锁未被正确释放。 + +**【正例】**(finally代码块) + +```java +final class Foo { + private final Lock lock = new ReentrantLock(); + + public void correctReleaseLock(String value) { + lock.lock(); + try { + ... + int index = Integer.parseInt(value); + ... + } finally { + lock.unlock(); + } + } +} +``` + +上述代码示例中,成功执行锁定操作后,将可能抛出异常的操作封装在try代码块中。锁在执行try代码块前获取,可保证在执行finally代码时正确持有锁。在finally代码块中调用`lock.unlock()`,可以保证不管是否发生异常都可以释放锁。 + +## 禁止使用Thread.stop()来终止线程 + +**【描述】** + +线程在正常退出时,会维持类的不变性。某些线程API最初是用来帮助线程的暂停、恢复和终止,但随后因为设计上的缺陷而被废弃。例如,`Thread.stop()`方法会导致线程立即抛出一个`ThreadDeath`异常,这通常会停止线程。调用`Thread.stop()`会造成一个线程非正常释放它所获得的所有锁,可能会暴露这些锁保护的对象,使这些对象处于一个不一致的状态中。 + +**【反例】**(使用废弃的Thread.stop()) + +```java +public final class Foo implements Runnable { + private final Vector vector = new Vector(1000); + + public Vector getVector() { + return vector; + } + + @Override + public synchronized void run() { + Random number = new Random(123L); + int i = vector.capacity(); + while (i > 0) { + vector.add(number.nextInt(100)); + i--; + } + } + + public static void main(String[] args) throws InterruptedException { + Thread thread = new Thread(new Foo()); + thread.start(); + Thread.sleep(5000); + thread.stop(); + } +} +``` + +上述示例中,一个线程将伪随机数写入一个vector中,在经过指定时间后,线程被强迫终止。因为Vector是线程安全的,所以多个线程对共享实例进行的操作是不会让其处于一个不一致的状态。例如,`Vector.size()`方法总是能返回vector中的元素的正确数目。Vector实例是使用自身的隐式锁来保持同步。而`Thread.stop()`方法会导致线程停止在正在进行的操作并抛出`ThreadDeath`异常,所有获得的锁会被释放,如果线程是在加入一个新整数到vector时被停止的,就可能导致处于不一致状态的vector,如因为元素数目是在添加一个元素后增加的,可能会导致`Vector.size()`返回的是错误的元素数目。 + +**【正例】**(设置线程结束标志) + +```java +public final class Foo implements Runnable { + private final Vector vector = new Vector(1000); + + private boolean done = false; + + public Vector getVector() { + return vector; + } + + public void shutdown() { + done = true; + } + + @Override + public synchronized void run() { + Random number = new Random(123L); + int i = vector.capacity(); + while (!done && i > 0) { + vector.add(number.nextInt(100)); + i--; + } + } + + public static void main(String[] args) throws InterruptedException { + Foo foo = new Foo(); + Thread thread = new Thread(foo); + thread.start(); + Thread.sleep(5000); + foo.shutdown(); + } +} +``` + +上述示例中,使用一个标志来请求线程终止。`shutdown()`方法设置这个标志为true,线程的`run()`方法查询该标志为true时终止执行。 + +**【正例】**(可中断) + +```java +public final class Foo implements Runnable { + private final Vector vector = new Vector(1000); + + public Vector getVector() { + return vector; + } + + @Override + public synchronized void run() { + Random number = new Random(123L); + int i = vector.capacity(); + while (!Thread.interrupted() && i > 0) { + vector.add(number.nextInt(100)); + i--; + } + } + + public static void main(String[] args) throws InterruptedException { + Foo foo = new Foo(); + Thread thread = new Thread(foo); + thread.start(); + Thread.sleep(5000); + thread.interrupt(); + } +} +``` + +上述示例中,调用`Thread.interrupt()`方法来终止线程。调用`Thread.interrupt()`方法设置了一个内部的中断标志。线程可以通过`Thread.interrupted()`方法来检查该标志,该方法会在当前线程被中断时返回true,并会清除该中断标志。 + +## 线程池中的线程结束后必须清理自定义的ThreadLocal变量 + +**【描述】** + +线程池技术通过重复使用线程以减少线程创建开销。由于线程的复用,导致`ThreadLocal`变量的使用存在以下两类问题: + +- 脏数据问题:当前任务未正确初始化`ThreadLocal`变量,导致`ThreadLocal`变量是由该线程执行的其他任务设置的; +- 内存泄露问题:`ThreadLocal`变量未主动释放,导致内存无法被主动回收。 + +因此必须保证线程池中每个任务使用的`ThreadLocal`变量在任务结束后被主动清理。 + +**【正例】** + +```java +public class TestThreadLocal { + public static void main(String[] args) { + ThreadPoolExecutor pool = new ThreadPoolExecutor(1, 2, 100, + TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), + Executors.defaultThreadFactory(), new ThreadPoolExecutor.CallerRunsPolicy()); + for (int i = 0; i < 20; i++) { + pool.execute(new TestThreadLocalTask()); + } + } +} + +class TestThreadLocalTask implements Runnable { + private static ThreadLocal localValue = new ThreadLocal<>(); + + @Override + public void run() { + localValue.set(STATE1); + try { + ... + localValue.set(STATE3); + ... + } finally { + localValue.remove(); // 需要执行remove方法清理线程局部变量,避免内存泄露 + } + } +} +``` + +# 输入输出 + +## 在多用户系统中创建文件时指定合适的访问许可 + +**【描述】** + +多用户系统中的文件通常归属于一个特定的用户,文件的属主能够指定系统中哪些用户能够访问该文件的内容。这些文件系统使用权限和许可模型来保护文件访问。当一个文件被创建时,文件访问许可规定了哪些用户可以访问或者操作这个文件。如果创建文件时没有对文件的访问许可做足够的限制,攻击者可能在修改此文件的访问权限之前对其进行读取或者修改。因此,一定要在创建文件时就为其指定访问许可,以防止未授权的文件访问。 + +**【反例】** + +```java +Writer out = new FileWriter("file"); +``` + +`FileOutputStream`与`FileWriter`的构造方法无法让程序员显式的指定文件的访问权限。在这个示例中,所创建文件的访问许可取决于具体的实现机制,可能无法防止未授权的访问。 + +**【正例】** + +```java +Path file = new File("file").toPath(); + +// 抛出异常而不是覆写已存在的文件 +Set options = new HashSet(); +options.add(StandardOpenOption.CREATE_NEW); +options.add(StandardOpenOption.APPEND); + +// 文件权限应设置为只有属主才能读取/写入文件 +Set perms = PosixFilePermissions.fromString("rw-------"); +FileAttribute> attr = + PosixFilePermissions.asFileAttribute(perms); +try (SeekableByteChannel sbc = Files.newByteChannel(file, options, attr)) { + ... // 写数据 +} +``` + +**【例外】** + +如果文件是创建在一个安全目录中,而且该目录对于非受信用户是不可读的,那么允许以默认许可创建文件。例如,如果整个文件系统是可信的或者只有可信用户可以访问,就属于这种情况。 + +## 使用外部数据构造的文件路径前必须进行校验,校验前必须对文件路径进行规范化处理 + +**【描述】** + +文件路径来自外部数据时,必须对其合法性进行校验,否则可能会产生路径遍历(Path Traversal)漏洞。 + +文件路径有多种表现形式,如绝对路径、相对路径,路径中可能会含各种链接、快捷方式、影子文件等,这些都会对文件路径的校验产生影响,所以在文件路径校验前要对文件路径进行规范化处理,使用规范化的文件路径进行校验。对文件路径的规范化处理必须使用`getCanonicalPath()`,禁止使用`getAbsolutePath()`(该方法无法保证在所有的平台上对文件路径进行正确的规范化处理)。 + +**【反例】** + +```java +public void doSomething() { + File file = new File(HOME_PATH, fileName); + String path = file.getPath(); + + if (!validatePath(path)) { + throw new IllegalArgumentException("Path Traversal vulnerabilities may exist!"); + } + ... // 对文件进行读写等操作 +} + +private boolean validatePath(String path) { + if (path.startsWith(HOME_PATH)) { + return true; + } else { + return false; + } +} +``` + +上述代码中fileName来自外部输入,直接用fileName的值与固定路径进行拼接,作为实际访问文件的路径,在访问文件之前通过`validatePath`检查了拼接的路径是否在固定目录下,但是攻击者可以通过../这样的路径方式,访问HOME_PATH之外的任意文件。 + +**【正例】**(getCanonicalPath()) + +```java +public void doSomething() { + File file = new File(HOME_PATH, fileName); + try { + String canonicalPath = file.getCanonicalPath(); + if (!validatePath(canonicalPath)) { + throw new IllegalArgumentException("Path Traversal vulnerability!"); + } + ... // 对文件进行读写等操作 + } catch (IOException ex) { + throw new IllegalArgumentException("An exception occurred ...", ex); + } +} + +private boolean validatePath(String path) { + if (path.startsWith(HOME_PATH)) { + return true; + } else { + return false; + } +} +``` + +上述代码示例中,使用外部输入的fileName构造文件路径后,先对文件路径进行规范化,然后用规范化的文件路径进行校验,满足条件后执行文件读写操作。这样可以有效避免路径遍历之类的风险。 + +## 从ZipInputStream中解压文件必须进行安全检查 + +**【描述】** + +使用`java.util.zip.ZipInputStream`解压文件时,有两个问题需要注意: + +**1. 解压出的文件在解压目标目录之外** + +解压zip文件时要校验各解压文件的名字,如果文件名包含../会导致解压文件被释放到目标目录之外的目录。因此,任何被解压文件的目标路径不在预期目录之内时,要么拒绝将其解压出来,要么将其解压到一个安全的位置。 + +**2. 解压的文件消耗过多的系统资源** + +解压zip时,不仅要对解压之后的文件数量进行限制,还要对解压之后的文件大小进行限制。zip压缩算法可能有很大的压缩比,可以把超大文件压缩成很小的zip文件。zip文件解压时,如果不对解压后的文件的实际大小进行检查,则可能会使解压后的文件占用大量系统资源,导致zip炸弹(zip bomb)攻击。因此,Zip文件解压时,若解压之后的文件大小超过一定的限制,必须拒绝将其解压。具体大小限制由平台的处理性能来决定。 + +**【反例】** + +```java +public void unzip(String fileName, String dir) throws IOException { + try (FileInputStream fis = new FileInputStream(fileName); + ZipInputStream zis = new ZipInputStream(fis)) { + ZipEntry entry; + File tempFile; + byte[] buf = new byte[10240]; + int length; + + while ((entry = zis.getNextEntry()) != null) { + tempFile = new File(dir, entry.getName()); + if (entry.isDirectory()) { + tempFile.mkdirs(); + continue; + } + + try (FileOutputStream fos = new FileOutputStream(tempFile)) { + while ((length = zis.read(buf)) != -1) { + fos.write(buf, 0, length); + } + } + } + } +} +``` + +上述示例中,未对解压的文件名做验证,直接将文件名传递给`FileOutputStream`构造器。也未检查解压文件的资源消耗情况,允许程序运行到操作完成或者本地资源被耗尽。 + +**【正例】** + +```java +private static final long MAX_FILE_COUNT = 100L; +private static final long MAX_TOTAL_FILE_SIZE = 1024L * 1024L; + +... + +public void unzip(FileInputStream zipFileInputStream, String dir) throws IOException { + long fileCount = 0; + long totalFileSize = 0; + + try (ZipInputStream zis = new ZipInputStream(zipFileInputStream)) { + ZipEntry entry; + String entryName; + String entryFilePath; + File entryFile; + byte[] buf = new byte[10240]; + int length; + + while ((entry = zis.getNextEntry()) != null) { + entryName = entry.getName(); + entryFilePath = sanitizeFileName(entryName, dir); + entryFile = new File(entryFilePath); + + if (entry.isDirectory()) { + creatDir(entryFile); + continue; + } + + fileCount++; + if (fileCount > MAX_FILE_COUNT) { + throw new IOException("The ZIP package contains too many files."); + } + + try (FileOutputStream fos = new FileOutputStream(entryFile)) { + while ((length = zis.read(buf)) != -1) { + totalFileSize += length; + zipBombCheck(totalFileSize); + fos.write(buf, 0, length); + } + } + } + } +} + +private String sanitizeFileName(String fileName, String dir) throws IOException { + File file = new File(dir, fileName); + String canonicalPath = file.getCanonicalPath(); + if (canonicalPath.startsWith(dir)) { + return canonicalPath; + } + throw new IOException("Path Traversal vulnerability: ..."); +} + +private void creatDir(File dirPath) throws IOException { + boolean result = dirPath.mkdirs(); + if (!result) { + throw new IOException("Create dir failed, path is : " + dirPath.getPath()); + } + ... +} + +private void zipBombCheck(long totalFileSize) throws IOException { + if (totalFileSize > MAX_TOTAL_FILE_SIZEG) { + throw new IOException("Zip Bomb! The size of the file extracted from the ZIP package is too large."); + } +} +``` + +上述示例中,在解压每个文件之前对其文件名进行校验,如果校验失败,整个解压过程会被终止。实际上也可以忽略跳过这个文件,继续后面的解压过程,甚至可以将这个文件解压到某个安全位置。解压缩过程中,在while循环中边读边统计实际解压出的文件总大小,如果达到指定的阈值(MAX_TOTAL_FILE_SIZE),会抛出异常终止解压操作;同时,会统计解压出来的文件的数量,如果达到指定阈值(MAX_FILE_COUNT),会抛出异常终止解压操作。 + +说明:在统计解压文件的大小时,不应该使用`entry.getSize()`来统计文件大小,`entry.getSize()`是从zip文件中的固定字段中读取单个文件压缩前的大小,文件压缩前的大小可被恶意篡改。 + +## 对于从流中读取一个字符或字节的方法,使用int类型的返回值 + +**【描述】** + +Java中`InputStream.read()`和`Reader.read()`方法用于从流中读取一个字节(byte)或字符(char)。 + +`InputStream.read()`读取一个字节,返回值的范围为0x00-0xFF(补码),8位;`Reader.read()`读取一个字符,返回值的范围为0x0000-0xFFFF(补码),16位。 + +当读取到流的末尾时,以上方法均返回int类型的-1(补码表示为0xFFFFFFFF),32位。 + +因此,如果在未判断返回值是否是流末尾标志-1(补码表示为0xFFFFFFFF)前将返回值转为byte或char,会导致无法正确判断返回值是流中的内容还是结束标识。 + +**【反例】**(字节) + +```java +FileInputStream in = getReadableStream(); + +byte data; +while ((data = (byte) in.read()) != -1) { + // 使用data + ... +} +``` + +上述代码中,将`read()`方法返回的值直接转换为byte类型,并将转换后的结果与-1进行比较,进而判断是否达到流的末尾。如果`read()`返回值为0xFF,0xFF转为有符号byte即为byte类型-1,循环结束条件判断通过,结果就是错误的以为流结束了。 + +**【反例】**(字符) + +```java +InputStreamReader in = getReader(); + +char data; +while ((data = (char) in.read()) != -1) { + // 使用data + ... +} +``` + +上述代码中,将`read()`方法返回的值直接转换为char类型,并将转换后的结果与-1进行比较,进而判断是否达到流的末尾。当读取流结束后,返回值转为char类型后也不为-1,因此即使流读取结束,while循环仍无法正确终止。 +原因是流结束标志-1(补码表示为0xFFFFFFFF)被强转为char类型时,会被转为0xFFFF,再和-1进行比较时等式不成立,导致循环结束条件永假。 + +**【正例】**(字节) + +```java +FileInputStream in = getReadableStream(); + +byte data; +int result; +while ((result = in.read()) != -1) { + data = (byte) result; + // 使用data + ... +} +``` + +**【正例】**(字符) + +```java +InputStreamReader in = getReader(); + +char data; +int result; +while ((result = in.read()) != -1) { + data = (char) result; + // 使用data + ... +} +``` + +上述代码中,使用int类型的变量来保存`read()`的返回值,并使用该返回值判断是否读取到流的末尾,流未读完时,将读取的内容转换为char或者byte类型,这样就避免了判断流末尾不准确。 + +## 防止外部进程阻塞在输入输出流上 + +**【描述】** + +Java中有两种方式启动一个外部进程并与其交互: + +1. java.lang.Runtime的exec()方法 +2. java.lang.ProcessBuilder的start()方法 + +他们都返回一个java.lang.Process对象,该对象封装了这个外部进程。 + +每个Process对象,包含输入流、输出流及错误流各一个,应该恰当地处理这些流,避免外部进程阻塞在这些流上。 + +不正确的处理会产生异常、DoS,及其他安全问题。 + +1、处理外部进程的输入流(`Process.getOutputStream()`,**从调用者角度来说,外部进程的输入流是OutputStream**): +对于需要输入流的外部进程,如果不为其提供一个有效输入,则其会从一个空的输入流中读取输入,导致其一直阻塞。 + +2、处理外部进程的输出流(`Process.getInputStream()`)和错误流(`Process.getErrorStream()`): +对于有输出流和错误流的外部进程,如果调用者不处理并且清空对应流,则该外部进程的输出可能会耗尽该进程输出流与错误流的缓冲区,导致外部进程被调用者阻塞,并影响调用者与外部进程的正常交互。 +如果使用`java.lang.ProcessBuilder`来调用外部进程,那么外部进程错误流可以通过`redirectErrorStream()`方法重定向到其输出流,调用者可以通过处理并清空输出流来同时处理错误流。 + +**【反例】**(错误处理外部进程的返回结果) + +```java +public void execExtProcess() throws IOException { + Process proc = Runtime.getRuntime().exec("ProcessMaybeStillRunning"); + int exitVal = proc.exitValue(); +} +``` + +上述示例中,程序未等到ProcessMaybeStillRunning进程结束就调用`exitValue()`方法,很可能会导致`IllegalThreadStateException`异常。 + +**【反例】**(未处理外部进程的输出流、错误流) + +```java +public void execExtProcess() throws IOException, InterruptedException { + Process proc = Runtime.getRuntime().exec("ProcessMaybeStillRunning"); + int exitVal = proc.waitFor(); +} +``` + +此示例对比上一个示例,不会产生`IllegalThreadStateException`异常。但是由于没有处理ProcessMaybeStillRunning的输出流和错误流,可能会导致描述中列出的问题。 + +**【正例】** + +```java +public class ProcessExecutor { + public void callExtProcess() throws IOException, InterruptedException { + Process proc = Runtime.getRuntime().exec("ProcessHasOutput"); + + StreamConsumer errConsumer = new StreamConsumer(proc.getErrorStream()); + StreamConsumer outputConsumer = new StreamConsumer(proc.getInputStream()); + + errConsumer.start(); + outputConsumer.start(); + + int exitVal = proc.waitFor(); + + errConsumer.join(); + outputConsumer.join(); + } + + class StreamConsumer extends Thread { + InputStream is; + + StreamConsumer(InputStream is) { + this.is = is; + } + + @Override + public void run() { + try { + byte data; + int result; + while ((result = is.read()) != -1) { + data = (byte) result; + handleData(data); + } + } catch (IOException ex) { + // 处理异常 + } + } + + private void handleData(byte data) { + ... + } + } +} +``` + +上述示例产生两个线程来分别读取进程的输出流和错误流。因此,外部进程将不会无限期地阻塞在这些流之上。 + +**【例外】** + +对于外部进程不涉及使用输入流、输出流和错误流的场景,可以不对流进行专门处理。 + +## 临时文件使用完毕必须及时删除 + +**【描述】** + +程序中很多用到临时文件的地方,比如用于进程间的数据共享,缓存内存数据,动态构造的类文件,动态连接库文件等。临时文件可能创建于操作系统的共享临时文件目录。这类目录中的文件可能会被定期清理,例如,每天晚上或者重启时。然而,如果文件未被安全地创建或者用完后还是可访问的,具备本地文件系统访问权限的攻击者便可以利用共享目录中的文件进行恶意操作。删除已经不再需要的临时文件有助于对文件名和其他资源(如二级存储)进行回收利用。每一个程序在正常运行过程中都有责任确保已使用完毕的临时文件被删除。 + +**【反例】** + +```java +public boolean uploadFile(InputStream in) throws IOException { + File tempFile = File.createTempFile("tempname", ".tmp"); + try (FileOutputStream fop = new FileOutputStream(tempFile)) { + int readSize; + do { + readSize = in.read(buffer, 0, MAX_BUFF_SIZE); + if (readSize > 0) { + fop.write(buffer, 0, readSize); + } + } while (readSize >= 0); + ... // 对tempFile进行其他操作 + } +} +``` + +上述示例代码在运行结束时未将临时文件删除。 + +**【正例】** + +```java +public boolean uploadFile(InputStream in) throws IOException { + File tempFile = File.createTempFile("tempname", ".tmp"); + try (FileOutputStream fop = new FileOutputStream(tempFile)) { + int readSize; + do { + readSize = in.read(buffer, 0, MAX_BUFF_SIZE); + if (readSize > 0) { + fop.write(buffer, 0, readSize); + } + } while (readSize >= 0); + ... // 对tempFile进行其他操作 + } finally { + if (!tempFile.delete()) { + // 忽略 + } + } +} +``` + +以上例子,在临时文件使用完毕之后,finally语句里对其进行了彻底删除。 + +# 序列化 + +#### 禁止直接将外部数据进行反序列化 + +**【描述】** + +反序列化操作是将一个二进制流或字符串反序列化为一个Java对象。当反序列化操作的数据是外部数据时,恶意用户可利用反序列化操作构造指定的对象、执行恶意代码、向应用程序中注入有害数据等。不安全反序列化操作可能导致任意代码执行、特权提升、任意文件访问、拒绝服务等攻击。 + +实际应用中,通常采用三方件实现对json、xml、yaml格式的数据序列化和反序列化操作。常用的三方件包括:fastjson、jackson、XMLDecoder、XStream、SnakeYmal等。 + +**【反例】** + +```java +public class DeserializeExample implements Serializable { + private static final long serialVersionUID = -5809782578272943999L; + + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + private void readObject(java.io.ObjectInputStream ois) { + ois.defaultReadObject(); + System.out.println("Hack!"); + } +} + + // 使用外部数据执行反序列化操作 + ObjectInputStream ois2= new ObjectInputStream(fis); + PersionInfo myPerson = (PersionInfo) ois2.readObject(); +``` + +上面的示例中,当反序列化操作的对象是攻击者构造的DeserializeExample对象的序列化结果,当`PersionInfo myPerson = (PersionInfo) ois2.readObject()`该语句执行时会报错,但是DeserializeExample对象中的`readObject()`方法中的攻击代码已经被执行。 + +**【正例】**(使用白名单校验) + +```java +public final class SecureObjectInputStream extends ObjectInputStream { + public SecureObjectInputStream() throws SecurityException, IOException { + super(); + } + + public SecureObjectInputStream(InputStream in) throws IOException { + super(in); + } + + protected Class resolveClass(ObjectStreamClass desc) + throws IOException, ClassNotFoundException { + if (!desc.getName().equals("com.xxxx.PersionInfo")) { // 白名单校验 + throw new ClassNotFoundException(desc.getName() + " not find"); + } + return super.resolveClass(desc); + } +} +``` + +上述示例是对反序列化的类进行白名单检查。即在自定义ObjectInputStream中重载`resolveClass()`方法,对className进行白名单校验。如果反序列化的类不在白名单之中,直接抛出异常。 + +**【正例】**(使用安全管理器防护) + +如果产品已经使用Java的安全管理器,建议使用Java安全管理器机制进行防护。 + +(1) 设置enableSubclassImplementation + +``` +permission java.io.SerializablePermission "enableSubclassImplementation"; + +``` + +(2) 定义ObjectInputStream,重载resolveClass的方法 + +```java +public final class HWObjectInputStream extends ObjectInputStream { + public HWObjectInputStream() throws SecurityException, IOException { + super(); + } + + public HWObjectInputStream(InputStream in) throws IOException { + super(in); + } + + protected Class resolveClass(ObjectStreamClass desc) + throws IOException, ClassNotFoundException { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + sm.checkPermission(new SerializablePermission( + "com.xxxx." + desc.getName())); + } + return super.resolveClass(desc); + } +} +``` + +(3) 在policy文件里设置白名单 + +``` +permission java.io.SerializablePermission "com.xxxx.PersionInfo"; + +``` + +# 外部数据校验 + +## 外部数据使用前必须进行合法性校验 + +**描述】** + +外部数据的范围包括但不限于:网络、用户输入(包括命令行、界面)、命令行、文件(包括程序的配置文件) 、环境变量、进程间通信(包括管道、消息、共享内存、socket等、RPC)、跨信任域方法参数(对于API)等。 + +来自程序外部的数据通常被认为是不可信的,在使用这些数据前需要进行合法性校验,否则可能会导致不正确的计算结果、运行时异常、不一致的对象状态,甚至引起各种注入攻击,对系统造成严重影响。 + +**对外部数据的校验包括但不局限于:** + +- 校验API接口参数合法性; +- 校验数据长度; +- 校验数据范围; +- 校验数据类型和格式; +- 校验集合大小; +- 校验外部数据只包含可接受的字符(白名单校验),尤其需要注意一些特殊情况下的特殊字符。 + +对于外部数据的校验,要注意以下两点: + +- 如果需要,外部数据校验前要先进行标准化:例如“\uFE64”、“<”都可以表示“<”,在web应用中,如果外部输入不做标准化,可以通过“\uFE64”绕过对“<”限制。 +- 对外部数据的修改要在校验前完成,保证实际使用的数据与校验的数据一致。 + +出于性能和代码简洁性考虑,对于RESTful API,provider只校验请求信息,consumer只校验响应结果;对于一个调用链上的方法,最外层的对外public方法必须校验,内部public方法可不重复校验。 + +**常见校验框架:** + +接口:JSR 380(Bean Validation 2.0)、JSR 303(Bean Validation 1.0)JavaBean参数校验标准,核心接口javax.validation.Validator,定义了很多常用的校验注解。 +实现:hibernate-validator 、Spring: + +- hibernate-validator 是 JSR 380(Bean Validation 2.0)、JSR 303(Bean Validation 1.0)规范的实现,同时扩展了注解:@Email、@Length、@NotEmpty、@Range等。 +- Spring validtor 同样实现了JSR 380和JSR 303,并提供了MethodValidationPostProcessor类,用于对方法的校验。 + +产品可自主选择合适的校验框架,也可以自主开发实现外部数据校验。 + +**【反例】** + +```java +/** + * 更换公司信息 + * + * @param companies 新旧公司信息 + * @return 更换公司是否成功 + */ +@RequestMapping(value = "/updating", method = RequestMethod.POST) +public boolean updateCompany(@RequestBody Companies companies) { + return employeeService.updateCompany(companies.getSrcCompany(), + companies.getDestCompany()); +} +``` + +上面的错误代码,provider对外开放的`updateCompany()`接口未对请求体做校验,存在被恶意攻击的风险。 + +**【正例】** + +```java +/** + * 更换公司信息 + * + * @param companies 新旧公司信息 + * @return 更换公司是否成功 + */ +@RequestMapping(value = "/updating", method = RequestMethod.POST) +public boolean updateCompany(@RequestBody @Valid @NotNull Companies companies) { + return employeeService.updateCompany( + companies.getSrcCompany(), companies.getDestCompany()); +} + +@Setter +@Getter +public class Companies { + @Valid + @NotNull + private Company srcCompany; + + @Valid + @NotNull + private Company destCompany; +} + +@Setter +@Getter +@Accessors(chain = true) +public class Company { + @NotBlank + @Size(min = 10, max = 256) + private String name; + + @NotBlank + @Size(min = 10, max = 512) + private String address; + + @Valid + private SubCompany subCompany; +} +``` + +上述示例使用@Valid注解触发参数校验,校验逻辑为对象属性声明时通过注解指定的规则。对外接口内部调用的public方法`employeeService.updateCompany()`由于只有本模块使用,非对外接口,而且调用的地方已做参数校验,可以不做参数判断。 + +**【反例】** + +获取环境变量值后未校验,直接使用。 + +```java +public static String getFile(String filePath, String fileName) { + // 获取进程的classpath路径 + String path = System.getProperty(RUNTIME_BASE_DIR); + ... // 直接使用 +} +``` + +**【正例】** + +使用ClassLoader提供的`getResource()`和`getResourceAsStream()`从装载的类路径中取得资源。 + +```java +public static String getSavePath(String filePath, String fileName) { + return ClassLoader.getSystemResource(fileName).getPath(); +} +``` + +对环境变量的值先进行标准化处理,再执行校验,最后使用: + +```java +public static String getFile(String filePath, String fileName) { + // 获取进程的classpath路径 + String path = System.getProperty(RUNTIME_BASE_DIR); + + // 标准化 + // 校验,例如StringUtils.startsWith(path, "/opt/xxxx/release/"); + // 使用 +} +``` + +**【反例】** + +配置文件未校验,直接使用。 + +```java +@Configuration +@PropertySource("classpath:xxx.properties") +@Component +public class XxxConfig { + @Value("${appId}") + private String appId; + + @Value("${secret}") + private String citySecret; +} +``` + +**【正例】** + +Spring Boot框架可以使用注解@ConfigurationProperties和@Validated完成对配置文件的校验,如下所示: + +```java +@ConfigurationProperties(locations = "classpath: xxx.properties", prefix = "xxx") +@Validated +public class XxxConfig { + @Value("${appId}") + @Pattern(regexp = "[0-9_A-Z]{32}") + private String appId; + + @Value("${secret}") + @Pattern(regexp = "[0-9A-Z]{64,138}", message = "Authentication credential error!") + private String citySecret; + + // Setter和Getter方法 +} +``` + +ServiceComb框架,可以通过Java自带的validation-api,从Bean上下文取到配置文件对象后,显式调用检验。 + +## 禁止直接使用外部数据来拼接SQL语句 + +**【描述】** + +SQL注入是指使用外部数据构造的SQL语句所代表的数据库操作与预期不符,这样可能会导致信息泄露或者数据被篡改。SQL注入产生的根本原因是使用外部数据直接拼接SQL语句,防护措施主要有以下三类: + +- 使用参数化查询:最有效的防护手段,但对SQL语句中的表名、字段名等不适用; +- 对外部数据进行白名单校验:适用于拼接SQL语句中的表名、字段名; +- 对外部数据中的与SQL注入相关的特殊字符进行转义:适用于必须通过字符串拼接构造SQL语句的场景,转义仅对由引号限制的字段有效。 + +参数化查询是一种简单有效的防止SQL注入的查询方式,应该被优先考虑使用。另外,参数化查询还能提高数据库访问的性能,例如,SQL Server与Oracle数据库会为其缓存一个查询计划,以便在后续重复执行相同的查询语句时无需编译而直接使用。对于常用的ORM框架(如Hibernate、iBATIS等),同样支持参数化查询。 + +**【反例】**(Java代码动态构建SQL) + +```java +Statement stmt = null; +ResultSet rs = null; +try { + String userName = request.getParameter("name"); + String password = request.getParameter("password"); + ... + String sqlStr = "SELECT * FROM t_user_info WHERE name = '" + userName + + "' AND password = '" + password + "'"; + stmt = connection.createStatement(); + rs = stmt.executeQuery(sqlString); + ... // 结果集处理 +} catch (SQLException ex) { + // 处理异常 +} +``` + +上述示例中使用用户提交的用户名和密码构造SQL语句,验证用户名和密码信息是否匹配,通过字符串拼接的方式构造SQL语句,存在SQL注入。恶意用户在仅知道用户名时,通过`zhangsan' OR 'a' = 'a`和**任意密码**的方式就能完成上述代码中的查询。 + +**【正例】**(使用PreparedStatement进行参数化查询) + +```java +PreparedStatement stmt = null; +ResultSet rs = null; +try { + String userName = request.getParameter("name"); + String password = request.getParameter("password"); + ... // 确保userName和password的长度是合法的 + String sqlStr = "SELECT * FROM t_user_info WHERE name=? AND password =?"; + stmt = connection.prepareStatement(sqlStr); + stmt.setString(1, userName); + stmt.setString(2, password); + rs = stmt.executeQuery(); + ... // 结果集处理 +} catch (SQLException ex) { + // 处理异常 +} +``` + +参数化查询在SQL语句中使用占位符表示需在运行时确定的参数值,使得SQL查询的语义逻辑预先被定义,实际的查询参数值则在程序运行时再确定。参数化查询使得数据库能够区分SQL语句中语义逻辑和数据参数,以确保用户输入无法改变预期的SQL查询语义逻辑。如果攻击者输入userName为`zhangsan' OR 'a' = 'a`,该字符串仅会作为name字段的值来使用。 + +**【正例】**(对输入输入做转义) + +```java +public List queryBooks(List queryCondition) { + ... + try { + StringBuilder sb = new StringBuilder("select * from t_book where "); + Codec oe = new OracleCodec(); + if (queryCondition != null && !queryCondition.isEmpty()) { + for (Expression e : queryCondition) { + String exprString = e.getColumn() + e.getOperator(); + String safeValue = XXXEncoder.encodeForSQL(oe, e.getValue()); + sb.append(exprString).append("'").append(safeValue).append("' and "); + } + sb.append("1=1"); + Statement stat = connection.createStatement(); + ResultSet rs = stat.executeQuery(sb.toString()); + ... // 其他代码 + } + } + ... +} +``` + +虽然参数化查询是防止SQL注入最便捷有效的一种方式,但不是SQL语句中任何部分在执行前都能够被占位符所替代,因此,参数化查询无法应用于所有场景。当使用执行前不可被占位符替代的外部数据来动态构建SQL语句时,必须对外部数据进行校验。每种DBMS都有其特定的转义机制,通过这种机制来告诉数据库此输入应该被当作数据,而不应该是代码逻辑。因此,只要输入数据被适当转义,就不会发生SQL注入问题。 + +**注:**如果传入的是字段名或者表名,建议使用白名单的方式进行校验。 + +在存储过程中,通过拼接参数值来构建查询字符串,和在应用程序代码中拼接参数一样,同样是有SQL注入风险的。 + +**【反例】**(在存储过程中动态构建SQL) + +SQL Server存储过程: + +```sql +CREATE PROCEDURE sp_queryItem + @userName varchar(50), + @password varchar(50) +AS +BEGIN + DECLARE @sql nvarchar(500); + SET @sql = 'SELECT * FROM t_user_info + WHERE name= ''' + @userName + ''' + AND password= ''' + @password + ''''; + EXEC(@sql); +END +GO +``` + +在存储过程中,通过拼接参数值来构建查询字符串,和在应用程序代码中拼接参数一样,同样是有SQL注入风险的。 + +**【正例】**(在存储过程中进行参数化查询) + +SQL Server存储过程: + +```sql +CREATE PROCEDURE sp_queryItem + @userName varchar(50), + @password varchar(50) +AS +BEGIN + SELECT * FROM t_user_info + WHERE name = @userName + AND password = @password; +END +GO +``` + +存储过程使用参数化查询,而不包含不安全的动态SQL构建。数据库编译此存储过程时,会生成一个SELECT查询的执行计划,只允许原始的SQL语义被执行,任何参数值,即使是被注入的SQL语句也不会被执行。 + +## 禁止使用外部数据构造格式化字符串 + +**描述】** + +Java中的Format可以将对象按指定的格式转为某种格式的字符串,格式化字符串可以控制最终字符串的长度、内容、样式,当格式化字符串中指定的格式与格式对象不匹配时还可能会抛出异常。当攻击者可以直接控制格式化字符串时,可导致信息泄露、拒绝服务、系统功能异常等风险。 + +**【反例】** + +```java +public String formatInfo(String formatStr) { + String value = getData(); + return String.format(formatStr, value)); +} + +String formatStr = req.getParameter("format"); +String formattedValue = formatInfo(formatStr); +``` + +上面的示例代码中,直接使用外部指定的格式对字符串进行格式化,当外部指定的格式为非字符类型如%d,会导致格式化操作出现异常。 + +**【正例】** + +```java +public String formatInfo() { + String value = getData(); + return String.format("my format: %s", value)); +} +``` + +上述示例将用户输入排除在格式化字符串之外。 + +## 禁止向Runtime.exec()方法或java.lang.ProcessBuilder类传递外部数据 + +**【描述】** + +`Runtime.exec()`方法或`java.lang.ProcessBuilder`类被用来启动一个新的进程,在新进程中执行命令。命令执行通常会有两种方式: + +- 直接执行具体命令: 例如`Runtime.getRuntime().exec("ping 127.0.0.1")`; + +直接使用外部数据构造命令行,会存在以下风险: + +- 执行命令时,需要命令行解释器对命令字符串进行拆分,该方式可执行多条命令,存在命令注入风险; +- 直接执行具体的命令时,可以通过空格、双引号或以-/开头的字符串向命令行中注入参数,存在参数注入风险。 + +**外部数据用于构造非shell方式的命令行** + +**【反例】** + +```java +String cmd = "ping" + ip; +Runtime rt = Runtime.getRuntime(); +Process proc = rt.exec(cmd); +``` + +当ip的值为“ 127.0.0.1 -t”的时候,会向实际执行的命令中注入参数“-t”参数,导致ping进程持续执行。 + +针对命令注入或参数注入,具体的解决方案如下: + +1、**避免直接执行命令** + +对于Java的标准库或开源组件已经提供的功能,应使用标准库或开源组件的API,避免执行命令。 + +如果无法避免执行命令,则必须要对外部数据进行检查和过滤。 + +2、**对外部数据进行校验** + +**【正例】**(数据校验) + +```java +... +// str值来自用户输入 +if (!Pattern.matches("[0-9A-Za-z@]+", str)) { + // 处理错误 +} +... +``` + +外部数据用于拼接命令行时,可使用白名单方式对外部数据进行校验,保证外部数据中不含注入风险的特殊字符。 + +3、**对外部数据进行转义** + +**【正例】**(转义) + +```java +String encodeIp = XXXXEncoder.encodeForOS(new WindowsCodec(), ip); +String cmd = "cmd.exe /c ping " + encodeIp; +Runtime rt = Runtime.getRuntime(); +Process proc = rt.exec(cmd); +... +``` + +在执行命令行时,如果输入校验不能禁止有风险的特殊字符,需先外部输入进行转义处理,转义后的字段拼接命令行可有效防止命令注入的产生。 + +说明:正确的转义处理只是针对外部输入,而不是拼接后的完整命令行。转义方式只针对命令注入有效,对于参数注入无效。 + +## 禁止直接使用外部数据来拼接XML + +**【描述】** + +使用未经校验的数据来构造XML会导致XML注入漏洞。如果用户被允许输入结构化的XML片段,则用户可以在XML的数据域中注入XML标签来改写目标XML文档的结构和内容,XML解析器会对注入的标签进行识别和解释,引起注入问题。 + +**【反例】** + +```java +private void createXMLStream(BufferedOutputStream outStream, User user) + throws IOException { + String xmlString; + xmlString = "operator" + user.getUserId() + + "" + user.getDescription() + ""; + ... // 解析xml字符串 +} +``` + +恶意用户可能会使用下面的字符串作为用户ID: + +``` +"joeadministratorjoe" + +``` + +并使用如下正常的输入作为描述字段: + +``` +"I want to be an administrator" + +``` + +最终,整个XML字符串将变成如下形式: + +```xml + + operator + joe + administrator + joe + I want to be an administrator + +``` + +由于SAX解析器(org.xml.sax and javax.xml.parsers.SAXParser)在解释XML文档时会将第二个role域的值覆盖前一个role域的值,因此会导致此用户角色由操作员提升为了管理员。 + +**【反例】**(XML Schema或者DTD校验) + +```java +private void createXMLStream(BufferedOutputStream outStream, User user) + throws IOException { + String xmlString; + xmlString = "" + user.getUserId() + + "operator" + user.getDescription() + + ""; + + StreamSource xmlStream = new StreamSource(new StringReader(xmlString)); + + // 创建一个使用schema执行校验的SAX解析器 + SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + StreamSource ss = new StreamSource(new File("schema.xsd")); + try { + Schema schema = sf.newSchema(ss); + Validator validator = schema.newValidator(); + validator.validate(xmlStream); + } catch (SAXException ex) { + throw new IOException("Invalid userId", ex); + } + + // XML是有效的, 进行处理 + outStream.write(xmlString.getBytes(StandardCharsets.UTF_8)); + outStream.flush(); +} +``` + +如下是schema.xsd文件中的schema定义: + +```xml + + + + + + + + + + + +``` + +某个恶意用户可能会使用下面的字符串作为用户ID: + +``` +"joeAdministratorI want to be an administrator" + +``` + +最终,整个XML字符串将变成如下形式: + +```xml + + joe + Administrator + I want to be an administrator + +``` + +用户ID结尾处的``将会注释掉原本硬编码在XML字符串中的角色信息。虽然用户角色已经被攻击者篡改成管理员类型,但是整个XML字符串仍然可以通过schema的校验。XML schema或者DTD校验仅能确保XML的格式是有效的,而攻击者可以在不打破原有XML格式的情况下,对XML的内容进行篡改。 + +**【正例】**(白名单校验) + +```java +private void createXMLStream(BufferedOutputStream outStream, User user) + throws IOException { + // 仅当userID只包含字母、数字和下划线时写入XML字符串 + if (!Pattern.matches("[_a-bA-B0-9]+", user.getUserId())) { + // 处理错误 + } + if (!Pattern.matches("[_a-bA-B0-9]+", user.getDescription())) { + // 处理错误 + } + String xmlString = "" + user.getUserId() + + "operator" + + user.getDescription() + ""; + outStream.write(xmlString.getBytes(StandardCharsets.UTF_8)); + outStream.flush(); +} +``` + +这个方法使用白名单的方式对输入进行校验,要求输入的userId中只能包含字母、数字或者下划线。 + +**【正例】**(使用安全的XML库) + +```java +public static void buidlXML(FileWriter writer, User user) throws IOException { + Document userDoc = DocumentHelper.createDocument(); + Element userElem = userDoc.addElement("user"); + Element idElem = userElem.addElement("id"); + idElem.setText(user.getUserId()); + Element roleElem = userElem.addElement("role"); + roleElem.setText("operator"); + Element descrElem = userElem.addElement("description"); + descrElem.setText(user.getDescription()); + XMLWriter output = null; + try { + OutputFormat format = OutputFormat.createPrettyPrint(); + format.setEncoding("UTF-8"); + output = new XMLWriter(writer, format); + output.write(userDoc); + output.flush(); + } finally { + // 关闭流 + } +} +``` + +上述示例中使用Dom4j来构建XML,Dom4j是一个定义良好、开源的XML工具库。Dom4j会对文本数据域进行XML编码,从而使得XML的原始结构和格式免受破坏。 + +这个例子中,攻击者如果输入如下字符串作为用户ID: + +``` +"joeAdministratorI want to be an administrator" + +``` + +则最终会生成如下格式的XML: + +```xml + + joe</id><role>Administrator</role><!-- + operator + --><description>I want to be an administrator + +``` + +可以看到,“<”与“>”经过XML编码后分别被替换成了 “**\<”**与”**\>**”,导致攻击者未能将其角色类型从操作员提升到管理员。 + +**【正例】**(编码) + +```java +private void createXMLStream(BufferedOutputStream outStream, User user) + throws IOException { + ... + String encodeUserId = XXXXEncoder.encodeForXML(user.getUserId()); + String encodeDec = XXXXEncoder.encodeForXML(user.getDescription()); + + String xmlString = "" + encodeUserId + + "operator" + encodeDec + + ""; + outStream.write(xmlString.getBytes(StandardCharsets.UTF_8)); + outStream.flush(); +} +``` + +上述示例中,对外部数据在拼接XML字符串前进行了编码处理,然后再构造XML字符串,这样就不会导致XML字符串结构被篡改。 + +## 防止解析来自外部的XML导致的外部实体(XML External Entity)攻击 + +**【描述】** + +XML实体包括内部实体和外部实体。外部实体格式:``或者``。Java中引入外部实体的协议包括http、https、ftp、file、jar、netdoc、mailto等。XXE漏洞发生在应用程序解析来自外部的XML数据或文件时没有禁止外部实体的加载,造成任意文件读取、内网端口扫描、内网网站攻击、DoS攻击等危害。 + +1.利用外部实体的引用功能实现任意文件的读取: + +```xml + + ]> + + Joe + &file; + ... + +``` + +2.使用参数实体和避免XML解析语法错误,构造恶意的实体解析: + +XML文件:构造参数实体 % start;% goodies;% end;% dtd定义一个恶意的combine.dtd + +```xml + + + + "> + + %dtd; + ]> +&all; +``` + +恶意DTD:combine.dtd中定义实体&all; + +```xml + + +``` + +甚至可以这样构造恶意的combine.dtd,将结果发送到目标地址,最后会获得file:///etc/fstab文件。 + +```xml + +"> +%send; +``` + +**【反例】** + +该示例中对来自外部的XML文件进行解析,没有禁止解析DTDs或者禁止解析外部实体。 + +```java +private void parseXmlFile(String filePath) { + try { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document doc = db.parse(new File(filePath)); + ... // 解析xml文件中的内容 + } catch (ParserConfigurationException ex) { + // 处理异常 + } + ... +} +``` + +上述代码示例中解析XML文件时未进行安全防护,当解析的XML文件是攻击者恶意构造的,系统会受到XXE攻击。 + +**【正例】**(禁止解析DTDs) + +```java +private void parserXmlFileDisableDtds(String filePath) { + try { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + + dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + dbf.setFeature("http://xml.org/sax/features/external-general-entities", false); + dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document doc = db.parse(new File(filePath)); + ... // 解析xml文件中的内容 + } catch (ParserConfigurationException ex) { + // 处理异常 + } + ... +} +``` + +代码中设置禁止解析DTDs属性,该方式不仅可以防止XML的外部实体攻击也能防止XML内部实体攻击。 + +**【正例】**(禁止解析外部一般实体和外部参数实体) + +该代码示例能防止外部实体(XXE)攻击,不能防止XML内部实体攻击。 + +```java +private void parserXmlFileDisableExternalEntityes(String filePath) { + try { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", false); + dbf.setFeature("http://xml.org/sax/features/external-general-entities", false); + dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document doc = db.parse(new File(filePath)); + ... // 解析xml文件中的内容 + } catch (ParserConfigurationException ex) { + // 处理异常 + } + ... +} +``` + +**【正例】**(对外部实体进行白名单校验) + +这个示例方法定义一个CustomResolver类来实现接口`org.xml.sax.EntityResolver`。在这个类中实现自定义的处理外部实体机制。自定义实体解析方法中使用一个简单的白名单,在白名单范围内的返回对应的文件内容,否则返回一个空的实体解析内容。 + +```java +private static void parserXmlFileValidateEntities(String filePath) { + try { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + db.setEntityResolver(new ValidateEntityResolver()); + Document doc = db.parse(new File(filePath)); + ... // 解析xml文件中的内容 + } catch (ParserConfigurationException ex) { + // 处理异常 + } + ... +} + +class ValidateEntityResolver implements EntityResolver { + private static final String GOOD_ENTITY = "file:/Users/onlinestore/good.xml"; + + public InputSource resolveEntity(String publicId, String systemId) + throws SAXException, IOException { + if (publicId != null && publicId.equals(GOOD_ENTITY)) { + return new InputSource(publicId); + } else if (systemId != null && systemId.equals(GOOD_ENTITY)) { + return new InputSource(systemId); + } else { + return new InputSource(); + } + } +} +``` + +当系统中涉及的XML操作中必须使用外部实体时,必须对外部实体进行白名单校验。具体的校验方式如上述代码,自定义一个`ValidateEntityResolver`类(实现接口`org.xml.sax.EntityResolver`),在`resolveEntity`方法中对XML中引入的实体进行白名单校验,拒绝解析非白名单中的外部实体。 + +备注:XML解析器非常多,不能一一列举。当程序加载来自外部的XML数据时,通过设置对该解析器生效的属性或其他方法达到禁止解析外部实体的目的,通过构建上面示例中有攻击行为的XML内容,查看程序反应来判断设置的属性是否已经生效。 + +## 防止解析来自外部的XML导致的内部实体扩展(XML Entity Expansion)攻击 + +**【描述】** + +XML内部实体是实体的内容已经在Doctype中声明。内部实体格式:``。内部实体攻击比较常见的是XML Entity Expansion攻击,它主要试图通过消耗目标程序的服务器内存资源导致DoS攻击。外部实体攻击和内部实体扩展攻击有不同的防护措施(禁止DTDs解析可以防护外部实体和内部实体攻击)。 + +解析下面恶意的XML内部实体,会占用大量服务器内存资源,导致拒绝服务攻击。 + +```xml + + + + + + + + + + + ]> +&lol9; +``` + +内部实体扩展攻击**最好的防护措施是禁止DTDs的解析**。也可以对内部实体数量进行限制,以消减内部实体扩展攻击发生的可能性。在不需要使用内部实体时,应该禁止DTDs解析,需要使用内部实体时,严格限制内部实体的数量及XML内容的大小。 + +**【正例】**(禁止解析DTDs) + +```java +public void receiveXMLStream(InputStream inStream) + throws ParserConfigurationException, SAXException, IOException { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + dbf.setFeature("http://xml.org/sax/features/external-general-entities", false); + dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false); + DocumentBuilder db = dbf.newDocumentBuilder(); + db.parse(inStream); +} +``` + +**【正例】**(限制实体解析个数) + +Java中的JAXP解析器默认限制实体解析个数是64,000个,但通常不会需要解析这么多的实体个数,可以限制更小的实体解析个数。该代码示例中通过设置DOM解析器的属性限制解析实体个数。 + +```java +public void receiveXMLStream(InputStream inStream) + throws ParserConfigurationException, SAXException, IOException { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setAttribute("http://www.oracle.com/xml/jaxp/properties/entityExpansionLimit", + "200"); + DocumentBuilder db = dbf.newDocumentBuilder(); + db.parse(inStream); +} +``` + +备注:属性http://www.oracle.com/xml/jaxp/properties/entityExpansionLimit在JDK 7u45+、JDK 8版本中支持。JAXP中的SAX和StAX类型解析器不支持该属性。 + +**【正例】**(限制实体解析个数) + +该代码示例中通过设置系统属性限制解析实体个数。 + +```java +public void receiveXMLStream(InputStream inStream) + throws ParserConfigurationException, SAXException, IOException { + + // 使用系统属性限制 + System.setProperty("entityExpansionLimit", "200"); + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + db.parse(inStream); +} +``` + +备注:系统属性entityExpansionLimit在JDK 7u45+、JDK 8版本中支持。JAXP中的SAX和StAX类型解析器同样生效。 + +有些产品使用Xerces第三方jar包提供的DOM、SAX、StAX类型解析器,该jar包中可以通过设置`setFeature("http://javax.xml.XMLConstants/feature/secure-processing", true)`限制实体个数不能超过100,000个。 + +**【正例】**(限制解析实体个数) + +Xerces包中限制实体解析个数代码。 + +```java +private static void receiveXMLStream(InputStream inStream) + throws ParserConfigurationException, SAXException, IOException { + DocumentBuilderFactory factory = DocumentBuilderFactoryImpl.newInstance(); + factory.setFeature("http://javax.xml.XMLConstants/feature/secure-processing", true); + DocumentBuilder db = factory.newDocumentBuilder(); + org.w3c.dom.Document doc = db.parse(inStream); + doc.getChildNodes(); +} +``` + +备注:XML解析器非常多,不能一一列举。当程序加载来自外部的XML数据时,通过设置对该解析器生效的属性或其他方法达到禁止解析内部实体的目的,通过构建上面示例中有攻击行为的XML内容,查看程序反应来判断设置的属性是否已经生效。 + +## 禁止使用不安全的XSLT转换XML文件 + +**【描述】** + +XSLT是一种样式转换标记语言,可以将XML数据转换为另外的XML或其他格式,如HTML网页,纯文字。因为XSLT的功能十分强大,可以导致任意代码执行,当使用TransformerFactory转换XML格式数据的时候,需要添加安全策略禁止不安全的XSLT代码执行。 + +**【反例】** + +```java +public void XsltTrans(String src, String dst, String xslt) { + // 获取转换器工厂 + TransformerFactory tf = TransformerFactory.newInstance(); + try { + // 获取转换器对象实例 + Transformer transformer = tf.newTransformer(new StreamSource(xslt)); + + // 进行转换 + transformer.transform(new StreamSource(src), + new StreamResult(new FileOutputStream(dst))); + ... + } catch (TransformerException ex) { + // 处理异常 + } + ... +} +``` + +这里xslt没有做任何限制,直接调用,当执行类似如下XSLT代码的时候,会导致命令执行漏洞: + +```xml + + + + + + + +``` + +**【正例】** + +```java +public void xsltTrans(String src, String dst, String xslt) { + // 获取转换器工厂 + TransformerFactory tf = TransformerFactory.newInstance(); + try { + // 转换器工厂设置黑名单,禁用一些不安全的方法,类似XXE防护 + tf.setFeature("http://javax.xml.XMLConstants/feature/secure-processing", true); + + // 获取转换器对象实例 + Transformer transformer = tf.newTransformer(new StreamSource(xslt)); + + // 去掉 + transformer.setOutputProperty("omit-xml-declaration", "yes"); + + // 进行转换 + transformer.transform(new StreamSource(src), + new StreamResult(new FileOutputStream(dst))); + ... + } catch (TransformerException ex) { + // 处理异常 + } + ... +} +``` + +TransformerFactory可以添加安全策略防护,Java对xslt内置了黑名单,这里通过将[http://javax.xml.XMLConstants/feature/secure-processing属性设置为true开启防护,可以禁用一些不安全的方法。](http://javax.xml.xmlconstants/feature/secure-processing属性设置为true开启防护,可以禁用一些不安全的方法。) + +## 正则表达式应该尽量简单,防止ReDos攻击 + +**【描述】** + +ReDos攻击是正则编写不当导致的常见安全风险。Java中提供的正则匹配使用的是NFA引擎。NFA引擎的回溯机制,导致当字符串文本与正则表达式不匹配时,所花费的时间要比匹配时多。即要确定匹配失败,需要与所有可能的路径进行对比匹配,证明都不匹配时,才返回匹配失败。当使用简单的非分组正则表达式时,一般不会存在ReDos攻击。容易存在ReDos攻击的正则表达式主要有两类: + +1、 包含具有自我重复的重复性分组的正则,例如: +`^(\d+)+$` +`^(\d*)*$` +`^(\d+)*$` +`^(\d+|\s+)*$` + +2、 包含替换的重复性分组,例如: +`^(\d|\d|\d)+$` +`^(\d|\d?)+$` + +对于ReDos攻击的防护手段主要包括: + +- 进行正则匹配前,先对匹配的文本的长度进行校验; +- 在编写正则时,尽量不要使用过于复杂的正则,尽量少用分组,例如对于正则`^(([a-z])+\.)+[A-Z]([a-z])+$`(存在ReDos风险),可以将多余的分组删除:`^([a-z]+\.)+[A-Z][a-z]+$`,这样在不改变检查规则的前提下消除了ReDos风险; +- 避免动态构建正则,当使用外部数据构造正则时,要使用白名单进行严格校验。 + +**【反例】** + +```java +private static final Pattern REGEX_PATTER = Pattern.compile("a(b|c+)+d"); + +public static void main(String[] args) { + ... + Matcher matcher = REGEX_PATTER.matcher(args[0]); + if (matcher.matches()) { + ... + } else { + ... + } + ... +} +``` + +上述示例代码中,正则表达式`a(b|c+)+d`存在ReDos风险,当匹配的字符串格式为”accccccccccccccccx”时,随中间的字符”c”的增加,代码执行时间将成指数级增长。 + +**【正例】** + +```java +private static final Pattern REGEX_PATTER = Pattern.compile("a[bc]+d"); + +public static void main(String[] args) { + ... + Matcher matcher = REGEX_PATTER.matcher(args[0]); + if (matcher.matches()) { + ... + } else { + ... + } + ... +} +``` + +上述代码中,将正则表达式精简为`a[bc]+d`,可以在实现相同功能的前提下消除ReDos风险。 + +**【反例】** + +```java +String key = request.getParameter("keyword"); +... +String regex = "[a-zA-Z0-9_-]+@" + key + "\\.com"; +Pattern searchPattern = Pattern.compile(regex); +... +``` + +上面的代码示例中,使用外部指定的keyword构造正则,当外部输入中使用了重复性分组,可能会导致最终的正则存在ReDos风险。在实际开发代码过程中,应避免直接使用外部数据构造正则或直接使用外部数据作为正则使用。 + +## 禁止直接使用外部数据作为反射操作中的类名/方法名 + +**【描述】** + +反射操作中直接使用外部数据作为类名或方法名,会导致系统执行非预期的逻辑流程(Unsafe Reflection)。这可被恶意用户利用来绕过安全检查或执行任意代码。当反射操作需要使用外部数据时,必须对外部数据进行白名单校验,明确允许访问的类或方法列表;另外也可以通过让用户在指定范围内选择的方式进行防护。 + +**【反例】** + +```java +String className = request.getParameter("class"); +... +Class objClass = Class.forName(className); +BaseClass obj = (BaseClass) objClass.newInstance(); +obj.doSomething(); +``` + +上述代码示例中,直接使用外部指定的类名通过反射构造了一个对象,恶意用户可利用此处构造一个任意的`BaseClass`子类的对象,当恶意用户可控制`BaseClass`的某个子类时,则可在该子类的`doSomething()`方法中执行任意代码。另外恶意用户还可以利用此代码执行任意类的默认构造方法,即使在进行类型转换时抛出`ClassCastException`,恶意用户预期的构造方法中的代码也已经执行。 + +**【正例】** + +```java +String classIndex = request.getParameter("classIndex"); +String className = (String) reflectClassesMap.get(classIndex); +if (className != null) { + Class objClass = Class.forName(className); + BaseClass obj = (BaseClass) objClass.newInstance(); + obj.doSomething(); +} else { + throw new IllegalStateException("Invalid reflect class!"); +} +... +``` + +上述示例代码中,外部只能指定要反射的类的代号,当代号可映射为一个指定的类名时,执行反射操作,否则判断为非法参数。 + +# 日志 + +#### 禁止直接使用外部数据记录日志 + +**【描述】** + +直接将外部数据记录到日志中,可能存在以下风险: + +- 日志注入:恶意用户可利用回车、换行等字符注入一条完整的日志; +- 敏感信息泄露:当用户输入敏感信息时,直接记录到日志中可能会导致敏感信息泄露; +- 垃圾日志或日志覆盖:当用户输入的是很长的字符串,直接记录到日志中可能会导致产生大量垃圾日志;当日志被循环覆盖时,这样还可能会导致有效日志被恶意覆盖。 + +所以外部数据应尽量避免直接记录到日志中,如果必须要记录到日志中,要进行必要的校验及过滤处理,对于较长字符串可以截断。对于记录到日志中的数据含有敏感信息时,对于秘钥、口令类的敏感信息,将这些敏感信息替换为固定长度的*,对于其他类的敏感信息(如手机号、邮箱等),先进行匿名化处理。 + +**【反例】** + +```java +String jsonData = getRequestBodyData(request); +if (!validateRequestData(jsonData)) { + LOG.error("Request data validate fail! Request Data : " + jsonData); +} +``` + +上述代码中,当请求的json数据校验失败,会直接将json字符串记录到日志中,当json字符串中含有敏感信息,会导致敏感信息泄露的风险,当恶意用户向json字符串中通过回车换行符注入伪造的日志会造成日志注入问题,当json字符串比较长时,会导致日志冗余。 + +**【正例】** + +外部数据记录到日志中前,将其中的\r\n等导致换行的字符进行替换,消除注入风险。如下代码为其中一种实现方式: + +```java +public String replaceCRLF(String message) { + if (message == null) { + return ""; + } + return message.replace('\n', '_').replace('\r', '_'); +} +``` + +#### 禁止在日志中记录口令、密钥等敏感信息 + +**【描述】** + +在日志中不能记录口令、密钥等敏感信息,包括这些敏感信息的加密密文,防止产生敏感信息泄露风险。若因为特殊原因必须要记录日志,应用固定长度的星号(*)代替这些敏感信息。 + +**【反例】** + +```java +private static final Logger LOGGER = Logger.getLogger(TestCase1.class); +... +LOGGER.info("Login success, user is " + userName + ", password is " + + encrypt(pwd.getBytes(StandardCharsets.UTF_8))); +``` + +**【正例】** + +```java +private static final Logger LOGGER = Logger.getLogger(TestCase1.class); +... +LOGGER.info("Login success, user is " + userName + ", password is ********."); +``` + +# 性能和资源管理 + +#### 进行IO类操作时,必须在try-with-resource或finally里关闭资源 + +**【描述】** + +申请的资源不再使用时,需要及时释放。而在产生异常时,资源释放常被忽视。因此要求在IO、数据库操作等需要显式调用关闭方法如`close()`释放资源时,必须在try-catch-finally的finally中调用关闭方法。如果有多个IO对象需要`close()`,需要分别对每个对象的`close()`方法进行try-catch,防止一个IO对象关闭失败导致其他IO对象都未关闭,保证产生异常时释放已申请的资源。 + +Java 7有自动资源管理的特性try-with-resource,不需手动关闭。它优先于try-finally,这样得到的代码将更加简洁、清晰,产生的异常也更有价值。特别是对于多个资源或异常时,try-finally可能丢失掉前面的异常,而try-with-resource会保留第一个异常,并把后续的异常作为Suppressed exceptions,可通过`getSuppressed()`返回的数组来检验。 + +try-finally也常用于`lock()`和`unlock()`等场景。 + +**【正例】** + +```java +try (FileInputStream in = new FileInputStream(inputFileName); + FileOutputStream out = new FileOutputStream(outputFileName)) { + copy(in, out); +} +``` + +# 其他 + +#### 全场景下必须使用密码学意义上的安全随机数 + +**【描述】** + +不安全的随机数可能被部分或全部预测到,导致系统存在安全隐患,安全场景下使用的随机数必须是密码学意义上的安全随机数。密码学意义上的安全随机数分为两类: + +- 真随机数产生器产生的随机数; +- 以真随机数产生器产生的少量随机数作为种子的密码学安全的伪随机数产生器产生的大量随机数。 + +Java中的`SecureRandom`是一种密码学安全的伪随机数产生器,对于使用非真随机数产生器产生随机数时,要使用少量真随机数作为种子。 + +常见安全场景包括但不限于以下场景: + +- 用于密码算法用途,如生成IV、盐值、密钥等; +- 会话标识(sessionId)的生成; +- 挑战算法中的随机数生成; +- 验证码的随机数生成; + +**【反例】** + +```java +public byte[] generateSalt() { + byte[] salt = new byte[8]; + Random random = new Random(123456L); + random.nextBytes(salt); + return salt; +} +``` + +`Random`生成是不安全随机数,不能用做盐值。 + +**【反例】** + +```java +public byte[] generateSalt() { + byte[] salt = new byte[8]; + SecureRandom random = new SecureRandom(); + random.nextBytes(salt); + return salt; +} +``` + +#### 必须使用SSLSocket代替Socket来进行安全数据交互 + +**【描述】** + +当网络通信中涉及明文的敏感信息时,需要使用SSLSocket而不是Socket,Socket是明文通信,攻击者可以通过网络监听获取其中的敏感信息,通过中间人攻击对报文进行恶意篡改。SSLSocket是在Socket的基础上进行了一个层安全性保护,包括身份认证、数据加密和完整性保护。 + +**【反例】** + +```java +try { + Socket socket = new Socket(); + socket.connect(new InetSocketAddress(ip, port), 10000); + os = socket.getOutputStream(); + os.write(userInfo.getBytes(StandardCharsets.UTF_8)); + ... +} catch (IOException ex) { + // 处理异常 +} finally { + // 关闭流 +} +``` + +上述代码中使用socket来明文传输报文信息,报文中的敏感信息存在泄露及篡改的风险。 + +**【正例】** + +```java +try { + SSLSocketFactory sslSocketFactory = + (SSLSocketFactory) SSLSocketFactory.getDefault(); + SSLSocket sslSocket = (SSLSocket) sslSocketFactory.createSocket(ip, port); + os = sslSocket.getOutputStream(); + os.write(userInfo.getBytes(StandardCharsets.UTF_8)); + ... +} catch (IOException ex) { + // 处理异常 +} finally { + // 关闭流 +} +``` + +该正确代码示例中,SSLSocket来使用SSL/TLS安全协议保护传输的报文。 + +**【例外】** + +因为SSLSocket提供的报文安全传输机制,将造成巨大的性能开销。在以下情况下,普通的套接字就可以满足需求: + +- 套接字上传输的数据不敏感。 +- 数据虽然敏感,但是已经过恰当加密。 + +#### 禁止代码中包含公网地址 + +**【级别】** 要求 + +**【描述】** + +代码或脚本中包含用户不可见,不可知的公网地址,可能会引起客户质疑。 + +对产品发布的软件(包含软件包/补丁包)中包含的公网地址(包括公网IP地址、公网URL地址/域名、邮箱地址)要求如下: +1、禁止包含用户界面不可见、或产品资料未描述的未公开的公网地址。 +2、已公开的公网地址禁止写在代码或者脚本中,可以存储在配置文件或数据库中。 + +对于开源/第三方软件自带的公网地址必须至少满足上述第1条公开性要求。 + +**【例外】** + +对于标准协议中必须指定公网地址的场景可例外,如soap协议中函数的命名空间必须指定的一个组装的公网URL、http页面中包含w3.org网址、XML解析器中的Feature名等。 \ No newline at end of file diff --git a/website/docs/_posts/contribute/OpenHarmony-JavaScript-coding-style-guide.md b/website/docs/_posts/contribute/OpenHarmony-JavaScript-coding-style-guide.md new file mode 100644 index 0000000000000000000000000000000000000000..193a8487c93495bf46530e44c2dd5eff356d7874 --- /dev/null +++ b/website/docs/_posts/contribute/OpenHarmony-JavaScript-coding-style-guide.md @@ -0,0 +1,770 @@ +--- +title: OpenHarmony-JavaScript-coding-style-guide.md +permalink: /pages/extra/b5a613/ +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +date: 2021-12-30 18:17:45 +--- +# JavaScript语言通用编程规范 + +## 目的 +规则并不是完美的,通过禁止在特定情况下有用的特性,可能会对代码实现造成影响。但是我们制定规则的目的“为了大多数程序员可以得到更多的好处”, 如果在团队运作中认为某个规则无法遵循,希望可以共同改进该规则。 +参考该规范之前,希望您具有相应的JavaScript语言基础能力,而不是通过该文档来学习JavaScript语言。 + +## 总体原则 +代码需要在保证功能正确的前提下,满足**可读、可维护、安全、可靠、可测试、高效、可移植**的特征要求。 + +## 约定 + +**规则**:编程时必须遵守的约定 +**建议**:编程时必须加以考虑的约定 + +无论是“规则”还是“建议”,都必须理解该条目这么规定的原因,并努力遵守。 + +## 例外 + +在不违背总体原则,经过充分考虑,有充足的理由的前提下,可以适当违背规范中约定。 +例外破坏了代码的一致性,请尽量避免。“规则”的例外应该是极少的。 + +下列情况,应风格一致性原则优先: +**修改外部开源代码、第三方代码时,应该遵守开源代码、第三方代码已有规范,保持风格统一。** + +## 编程规范 + +### 命名规范 + +#### 规则1.1 须使用正确的英文拼写进行命名,禁止使用拼音拼写。 + +**反例:**`xingming`、`zhanghao` + +**正例:**`username`、`account` + +#### 规则1.2 命名尽量少用缩写,除非是常见词或者业务线的领域词汇。比如:`context`可以简写成`ctx`,`request`可简写成`req`,`response`可简写成`resp`。 + +**说明:** 完整的单词拼写可以避免不必要的阅读障碍。 + +**例外:** 循环语种中可以使用`i`、`j`循环条件变量名。 + +#### 规则1.3 类名、枚举名、命名空间名采用`UpperCamelCase`风格。 + +**正例:** + +```javascript +// 类名 +class User { + constructor(username) { + this.username = username; + } + + sayHi() { + console.log(`hi, ${this.username}`); + } +} + +// 枚举名 +const UserType = { + TEACHER: 0, + STUDENT: 1 +}; + +// 命名空间 +const Base64Utils = { + encrypt: function(text) { + // todo encrypt + }, + decrypt: function(text) { + // todo decrypt + } +}; +``` + +#### 规则1.4 变量名、方法名、参数名采用`lowerCamelCase`风格。 + +**正例:** + +```javascript +let msg = 'Hello world'; + +function sendMsg(msg) { + // todo send message +} + +function findUser(userID) { + // todo find user by user ID +} +``` + +#### 规则1.5 静态常量名、枚举值名采用全部大写,单词间使用下划线隔开。 + +**正例:** + +```javascript +const MAX_USER_SIZE = 10000; + +const UserType = { + TEACHER: 0, + STUDENT: 1 +}; +``` + +#### 建议1.6 避免使用否定的布尔变量名,布尔型的局部变量或方法须加上表达是非意义的前缀。 + +**反例:** + +```javascript +let isNoError = true; +let isNotFound = false; +function empty() {} +function next() {} +``` + +**正例:** + +```javascript +let isError = false; +let isFound = true; +function isEmpty() {} +function hasNext() {} +``` + +### 代码格式 + +#### 规则2.1 采用2个空格缩进,禁止使用`tab`字符 + +**说明:** 只允许使用空格(space)进行缩进,每次缩进为2个空格。不允许使用Tab 符进行缩进。 + +**正例:** + +```javascript +const dataSource = [ + { + id: 1, + title: 'Title 1', + content: 'Content 1' + }, + { + id: 2, + title: 'Title 2', + content: 'Content 2' + } +]; + +function render(container, dataSource) { + if (!container || !dataSource || !dataSource.length) { + return void 0; + } + + const fragment = document.createDocumentFragment(); + for (let data of dataSource) { + if (!data || !data.id || !data.title || !data.content) { + continue; + } + const element = document.createElement("div"); + const textNode = document.createTextNode(`${data.title}: ${data.content}`); + element.appendChild(textNode); + element.setAttribute("id", data.id); + fragment.appendChild(element); + } + container.appendChild(fragment); +} + +``` + +#### 规则2.2 行宽不超过`120`个字符 + +**说明:** 建议每行字符数不要超过 120 个。如果超过120个字符,请选择合理的方式进行换行。 + +**例外:** 如果一行注释包含了超过120 个字符的命令或URL,则可以保持一行,以方便复制、粘贴和通过grep查找; 预处理的 error 信息在一行便于阅读和理解,即使超过 120 个字符。 + +#### 规则3.3 大括号的使用须遵循约定: + +1. 如果大括号内为空,则允许简写成`{}`,且无需换行; +2. 左大括号前不换行,括号后换行; +3. 右大括号前换行,括号后还有`else`、`catch`等情况下不换行,其他情况都换行。 + +#### 规则3.4 条件语句和循环语句的实现必须使用大括号包裹,即使只有一条语句。 + +**反例:** + +```javascript +if (condition) + console.log('success'); + +for(let idx = 0; idx < 5; ++idx) + console.log(idx); +``` + +**正例:** + +```javascript +if (condition) { + console.log('success'); +} + +for(let idx = 0; idx < 5; ++idx) { + console.log(idx); +} +``` + +#### 规则2.5 条件语句和循环语句都不允许写在同一行。 + +**反例:** + +```javascript +if (condition) { /* todo something */ } else { /* todo other */ } + +let idx = 0; +while(idx < 10) console.log(idx); +``` + +**正例:** + +```javascript +if (condition) { + /* todo something */ +} else { + /* todo other */ +} + +let idx = 0; +while(idx < 10) { + console.log(idx); +} +``` + +#### 规则2.6 `switch`语句的`case`和`default` 须缩进一层。 + +**正例:** + +```javascript +switch(condition) { + case 0: + doSomething(); + break; + case 1: { // 可以带括号也可以不带 + doOtherthing(); + break; + } + default: + break; +} +``` + +#### 规则2.7 表达式换行须保持一致性,运算符放行末。 + +**说明:** 较长的表达式,不满足行宽要求时,需要在适当的位置进行换行。一般在较低优先级运算符或连接符后面阶段,运算符或连接符放行末。运算符、连接符放在行末,表示“未结束,后续还有”。 + +**正例:** + +```javascript +// 假设条件语句超出行宽 +if (userCount > MAX_USER_COUNT || + userCount < MIN_USER_COUNT) { + doSomething(); +} + +const sum = + number1 + + number2 + + number3 + + number4 + + number5 + + number6 + + number7 + + number8 + + number9; +``` + +#### 规则2.8 多个变量定义和赋值语句不允许写在一行。 + +**反例:** + +```javascript +let maxCount = 10, isCompleted = false; + +let pointX, pointY; +pointX = 10; pointY = 0; +``` + +**正例:** + +```javascript +let maxCount = 10; +let isCompleted = false; + +let pointX = 0; +let pointY = 0; +``` + +#### 规则2.9 空格应该突出关键字和重要信息,避免不必要的空格。 + +**说明:** 空格可以减低代码密度,增加代码的可读性。总体规则如下: + +1. `if`、`elseif`、`else`、`switch`、`while`、`for`等关键字之后加空格; +2. 小括号内部两侧不加空格; +3. 大括号内部两侧须加空格,但`{}`等简单场景例外; +4. 多重括号之间不加空格; +5. 一元操作符(`&`、`*`、`+`、`-`、`!`等)之后不加空格; +6. 二元操作符(`=`、`+`、`-`、`*`、`/`、`%`、`|`、`&`、`||`、`&&`、`<`、`>`、`<=`、`>=`、`==`、`!=`、`===`、`!==`等)左右两侧加空格; +7. 三元运算符(`?: `)的两侧添加空格; +8. 前置或后置的自增、自减(`++`、`--`)和变量之间不加空格; +9. 逗号(`,`)前面不加空格,后面加空格; +10. 单行注释`//`后加空格; +11. 行尾不加空格。 + +#### 规则2.10 表达式语句须以分号结尾。 + +**反例:** + +```javascript +let username = 'jack' +let birthday = '1997-09-01' + +console.log(`${username}'s birthday is ${birthday}`) +``` + +**正例:** + +```javascript +let username = 'jack'; +let birthday = '1997-09-01'; + +console.log(`${username}'s birthday is ${birthday}`); +``` + +#### 建议2.11 优先使用单引号包裹字符串。 + +**正例:** + +```javascript +let message = 'wolrd'; +console.log(message); +``` + +### 代码规范 + +#### 规则3.1 声明变量时须使用`var`、`let`或`const`关键字进行声明,避免变量暴露到全局作用域上。 + +**说明:** 不使用`var`、`let`或`const`关键字声明变量,会导致将变量暴露到全局作用域上,这样可能会覆盖全局作用域上的同名变量,进而引发GC无法有效回收内存的问题;另外,当变量中包含敏感信息时,暴露到全局作用域可能会导致信息泄露问题。另外,**尽量对所有的引用使用`const`,不要使用 `var`;如果你一定需要可变动的引用,使用 `let` 代替 `var`**。因为`const`和`let`的作用域更小,写代码更容易控制;const可确保无法对引用重新赋值,const引用的指针不可变,重新赋值会报错,避免了不小心的重新赋值给覆盖了。 + +**反例:** + +```javascript +function open() { + url = 'http://127.0.0.1:8080'; //url会暴露到全局作用域上 + //todo something +} +open(); +console.log(url); //url可以被访问到,输出内容:http://127.0.0.1:8080 +``` + +**正例:** + +```javascript +function open() { + let url = 'http://127.0.0.1:8080'; + // todo something +} +open(); +console.log(url); //报错:Uncaught ReferenceError: url is not defined +``` + +```javascript +function open() { + const url = 'http://127.0.0.1:8080'; + //todo something +} +open(); +console.log(url); //报错:Uncaught ReferenceError: url is not defined +``` + +#### 规则3.2 函数块内须使用函数表达式声明函数 + +**说明:** 虽然很多 JS 引擎都支持块内声明函数,但它不属于 ECMAScript规范,各个浏览器糟糕的实现相互不兼容,有些也与未来 ECMAScript草案相违背。另外,ECMAScript5不支持块作用域,对于所有的控制流都不是独立的作用域,其内部声明的变量或者函数都是在其父函数或者脚本的作用域中,导致块内函数或者变量的声明会存在覆盖现象。如果确实需要在块中定义函数,应该使用函数表达式来初始化。 + +**反例:** + +```javascript +function bar(name) { + if (name === "hotel") { + // 1、定义一个foo函数,其作用域不是if代码块,而是bar函数作用域。 + function foo() { + console.log("hotel foo A"); + } + } else { + // 2、再重复定义一次foo函数,覆盖上面if条件分支下的foo函数定义。 + function foo() { + console.log("hotel foo 2"); + } + } + foo && foo(); +} +bar("hotel"); // 输出结果总是显示"hotel foo 2" +``` + +**正例:** + +```javascript +function bar(name) { + var foo; + if (name == "hotel") { + foo = function () { + console.log("hotel foo 1"); + }; + } else { + foo = function () { + console.log("hotel foo 2"); + } + } + foo && foo(); +} +bar("hotel"); // 正确输出"hotel foo 1" +``` + +#### 规则3.3 禁止封装基本类型 + +**说明:** JavaScript中有五种基本数据类型:Undefined、Null、Boolean、Number和String。基本数据类型的值是不可更改的。JavaScript中使用基本数据类型对象只是值,不包含器封装对象的方法和属性,在不需要使用属性和方法的时候,不需要使用其封装类型。 + +**反例:** + +```javascript +var isShow = new Boolean(false); +if (isShow) { + alert('hi'); //被执行,界面弹出显示:hi +} +``` + +**正例:** + +```javascript +var isShow = false; +if (isShow) { + alert('hi'); +} +``` + +#### 规则3.4 禁止使用`with` + +**说明:** 使用 with让你的代码在语义上变得不清晰,因为with的对象,可能会与局部变量产生冲突,从而改变程序原本的用义。 + +**反例:** + +```javascript +var foo = { x: 5 }; +with(foo) { + var x = 3; + console.log(x); //输出:5 +} +``` + +#### 规则3.5 `this`仅可在对象构造函数、方法、闭包中使用 + +**说明:** 在JavaScript里面,this指针代表的是执行当前代码的对象的所有者。this具有特殊的语义: + ++ 全局对象(大多数情况下) ++ 调用者的作用域(使用eval时) ++ DOM 树中的节点(添加事件处理函数时) ++ 新创建的对象(使用一个构造器) ++ 其他对象(如果函数被 call() 或 apply()) + +```javascript +var User = function(username) { + this.username = username; +}; +var user = new User('John'); +console.log(user.username); // 输出:John + +var ClickCounter = { + value: 0, + click: function() { + ++this.value; + }, + getValue() { + return this.value; + } +}; +console.log(Counter.getValue()); //输出:0 +Counter.click(); +console.log(Counter.getValue()); //输出:1 +``` + +#### 规则3.6 禁止使用IE下的条件注释 + +**说明:** 在IE下使用`\@cc_on`语句或使用`\@if`或`\@set`语句可以激活条件编译。尽管可以通过注释来兼容IE以外的浏览器,但它妨碍自动化工具的执行,因为在运行时,它们会改变JavaScript 语法树。 + +**反例:** + +```javascript +var f = function () { + /*@cc_on @*/ + /*@if (@_jscript_version >= 4) + alert("JavaScript version 4 or better"); + @else @*/ + alert("Conditional compilation not supported by this scripting engine."); + /*@end @*/ +}; +``` + +#### 规则3.7 禁止修改内置对象的原型 + +**说明:** 内置对象作为一套公共接口,具有约定俗成的行为方式,修改其原型,可能破坏接口语义,或导致调试时的诡异现象。 + +**反例:** + +```javascript +Array.prototype.indexOf = function () { return -1 } +var arr = [1, 1, 1, 1, 1, 2, 1, 1, 1]; +console.log(aar.indexOf(2)); // 输出:-1 +``` + +#### 规则3.8 禁止直接使用`Object.prototype`的内置属性 + +**说明:** ECMAScript5.1新增了`Object.create`,它创建一个新对象,使用现有的对象来提供新创建的对象的proto。`Object.create(null)`是用于创建用作map的对象的常用模式。当该对象具有`Object.prototype`同名的属性时,可能会导致意外行为或漏洞。例如,web服务器解析来自客户端的JSON输入并且使用`hasOwnProperty`直接调用生成的对象是不安全的,因为恶意客户端可能会发送类似的JSON值`'{ "hasOwnProperty": 1 }'` 并导致服务器崩溃。 + +**反例:** + +```javascript +var hasBarProperty = foo.hasOwnProperty("bar"); +var isPrototypeOfBar = foo.isPrototypeOf(bar); +var barIsEnumerable = foo.propertyIsEnumerable("bar"); +``` + +**正例:** + +```javascript +var hasBarProperty = Object.prototype.hasOwnProperty.call(foo, "bar"); +var isPrototypeOfBar = Object.prototype.isPrototypeOf.call(foo, bar); +var barIsEnumerable = {}.propertyIsEnumerable.call(foo, "bar"); +``` + +#### 规则3.9 使用`Object.getPrototypeOf`函数而不要使用`_proto_` + +说明:ES5引入`Object.getPrototypeOf`函数作为获取对象原型的标准API,但在这之前大量的JavaScript引擎早就使用一个特殊的`proto`属性来达到相同的目的。然而,`proto`它本质上是一个内部属性,而不是一个正式的对外的API,目前浏览器必须部署这个属性,但其他运行环境不一定部署,因此,该属性并不是完全兼容的。例如,对于拥有null原型的对象,不同的环境处理的不一样。 + +```javascript +var empty = Object.create(null); +"_proto_" in empty; //有些环境返回false,有些环境返回true +``` + +所以无论从语义的角度,还是从兼容性的角度,都不要使用proto这个属性,而是使用`Object.getPrototypeOf()`来代替。无论在什么环境中,`Object.getPrototypeOf`函数都是有效的,而且也是提取对象原型更加标准、可移植的方法。 + +#### 规则3.10 不要使用函数构造器创建函数 + +说明:定义函数的方法包括3种:函数声明、Function构造函数和函数表达式。不管用哪种方法定义函数,它们都是Function对象的实例,并将继承Function对象所有默认或自定义的方法和属性。以函数构造器创建函数的方式类似于字符串`eval()`,可以接受任何字符串形式作为它的函数体,这就会有安全漏洞的风险。 + +**反例:** + +```javascript +var func = new Function('a', 'b', 'return a + b'); +var func2 = new Function('alert("Hello")'); +``` + +**正例:** + +```javascript +function func(a, b) { + return a + b; +} + +var func2 = function(a, b) { + return a + b; +} +``` + +#### 建议3.11 在使用原型`prototype`实现继承时,尽量使用现有稳定的库方法而非自行实现 + +**说明:** 多级原型结构是指JavaScript中的继承关系。当定义一个D类,且把B类作为其原型,那么就获得了一个多级原型结构。这些原型结构会变得很复杂。使用现有的稳定的库方法如`the Closure`库的`goog.inherits()`或其他类似的函数,可避免不必要的编码失误,将是更好的选择。 + +#### 建议3.12 定义类时,应在原型下定义方法,在构造方法内定义属性 + +**说明:** JavaScript中有多种方法可以给构造函数添加方法或成员,但是使用原型定义方法,可以降低内存占用,提高运行效率。 + +**反例:** + +```javascript +function Animals() { + this.walk = function() {}; // 这样会导致每个实例上都创建一个walk方法 +} +``` + +**正例:** + +```javascript +function Animals() {} + +Animals.prototype.walk = function() {}; +``` + +#### 建议3.13 使用闭包时,应避免构成循环引用,导致内存泄露 + +**说明:** JavaScript是一种垃圾收集式语言,其对象的内存是根据对象的创建分配给该对象的,并且会在没有对该对象的引用时由浏览器收回。JavaScript的垃圾收集机制本身并没有问题,但浏览器在为DOM对象分配和恢复内存的方式上有些出入。IE和Firefox均使用引用计数来为DOM对象处理内存。在引用计数系统中,每个所引用的对象都会保留一个计数,以获悉有多少对象正在引用它。如果计数为零,那么该对象就会被销毁,其占用的内存也会返回给堆。虽然这种解决方案总的来说还算有效,但是在循环引用方面却存在一些盲点。 当两个对象互相引用时,就构成了循环引用,其中对象的引用计数值都被赋为1。在纯垃圾收集系统中,循环引用问题不大:如果涉及的两个对象中有一个对象被任何其他对象引用,那么这两个对象都将被垃圾收集。而在引用计数系统中,这两个对象都不能被销毁,原因是引用计数永远不能为0。在同时使用了垃圾收集和引用计数的混合系统中,将会发生泄漏,因为系统不能正确识别循环引用。在这种情况下,DOM对象和JavaScript对象均不能被销毁。 循环引用很容易创建。在JavaScript最为方便的编程结构之一——闭包中,循环引用尤其突出。闭包会持有其外部作用域(包括局部变量、参数及方法)的引用,当闭包本身又被作用域成员(常见于DOM对象)持有时便构成循环引用,进一步导致内存泄露。 + +**反例:** + +```javascript +function setClickListener(element, a, b) { + element.onclick = function() { + // 在这里用到a和b + }; +}; +``` + +在上述代码中,即使没有使用element,闭包也保留了element、a和b的引用。由于element也保留了对闭包的引用,因此产生了循环引用,不能被GC回收。 + +**正例:** + +```javascript +function setClickListener(element, a, b) { + element.onclick = createHandler(a, b); +} + +function createHandler(a, b) { + // 通过添加另外一个函数来避免闭包本身,进而组织内存泄露 + return function() { + // 在这里用到a和b + } +} +``` + +#### 建议3.14 警惕JavaScript的浮点数 + +**说明:** JavaScript具有单一数字类型:`IEEE 754`双精度浮点数。拥有单一数字类型是JavaScript的最佳功能之一。多种数字类型可能是复杂性,混淆和错误的根源。但是,二进制浮点类型有一个最大的缺点是,它不能准确地表示小数部分,会导致让人意外的精度问题,见下面示例。 + +示例代码1: + +```javascript +console.log(0.1 + 0.2 === 0.3); // 输出:false。所以通常禁止直接使用==或===来比较浮点数。 +``` + +示例代码2: + +```javascript +var sum1 = (0.1 + 0.2) + 0.3; +console.log(sum1); // 输出:0.6000000000000001 + +var sum2 = 0.1 + (0.2 + 0.3); +console.log(sum2); // 输出:0.6。所以对于二进制浮点数,(a + b) + c 不能保证产生于a + (b + c)相同的结果。 +``` + +有效的解决方法有以下几种: + +1. 尽可能的采用整数值运算,因为整数在表示是不需要舍入; + +2. 使用JavaScript的原生方法`Number.prototype.toFixed(digits)`,`digist`参数表示小数点后数字的个数,不使用指数法,在必要时会进行四舍五入。使用该方法,在判断浮点数运算结果前对计算结果进行精度缩小。示例代码如下所示: + + ```javascript + parseFloat(0.1 + 0.2).toFixed(1); //0.3 + ``` + +3. ES6 新增了一个极小的常量`Number.EPSILON =.220446049250313e-16 `,约等于`0.00000000000000022204`。`Number.EPSILON`的出现是用来判断浮点数的计算误差,如果浮点数计算得到的误差不超过`Number.EPSILON`的值,就表示可以接受这样的误差。示例代码如下所示: + + ```javascript + function isNumberEquals(one, other) { + return Math.abs(one - other) < Number.EPSILON; + } + var one = 0.1 + 0.2; + var other = 0.3; + console.log(isNumberEquals(one, other)); // 输出:true + ``` + +4. 使用一些支持精确运算的类库方法,如`math.js` + + ```html + + + + + + + + + + + + ``` + +#### 建议3.15 不要使用可变参数的Array构造函数 + +**说明:** 通常不鼓励使用构造函数`new Array`的方法来构造新数组,因为当构造函数只有一个参数的时候,可能会导致意外情况,另外Array的全局定义也可能被重新修改,所以提倡使用数组文字表示法来创建数组,也就是`[]`表示法。 +**反例:** + +```javascript +const arr1 = new Array(x1, x2, x3); +const arr2 = new Array(x1, x2); +const arr3 = new Array(x1); +const arr4 = new Array(); +``` + +除了第三种情况之外,其他都可以正常工作,如果`x1`是个整数,那么`arr3`就是长度为`x1`,值都为`undefined`的数组。如果`x1`是其他任何数字,那么将抛出异常,如果它是其他任何东西,那么它将是单元数组。 + +**正例:** + +```javascript +const arr1 = [x1, x2, x3]; +const arr2 = [x1, x2]; +const arr3 = [x1]; +const arr4 = []; +``` + +这种写法,就会省去很多麻烦。 + +同理,对于对象,同样不要使用`new Object()`,而是使用`{}`来创建。 + +#### 规则3.16 构建字符串时,优先使用字符串模板而不是字符串链接。 + +**说明:** 模板字符串表达更简洁,更具可读性。 + +**反例:** + +```javascript +function sayHi(name) { + console.log('hi, ' + name); +} +``` + +**正例:** + +```javascript +function sayHi(name) { + console.log(`hi, ${name}`); +} +``` + +#### 规则3.17 数组遍历采用`for...of`,对象遍历采用`for...in`。 + +**反例:** + +```javascript +let numbers = [1, 2, 3, 4]; +let sum = 0; +for (let number in numbers) { + sum += number; +} +// sum === 00123; +``` + +**正例:** + +```javascript +let numbers = [1, 2, 3, 4]; +let sum = 0; +for (let number of numbers) { + sum += number; +} +// sum === 10 +``` + diff --git a/website/docs/_posts/contribute/OpenHarmony-Log-guide.md b/website/docs/_posts/contribute/OpenHarmony-Log-guide.md new file mode 100644 index 0000000000000000000000000000000000000000..c26c932452023fd719b1b60f3c14015ba9950dc6 --- /dev/null +++ b/website/docs/_posts/contribute/OpenHarmony-Log-guide.md @@ -0,0 +1,250 @@ +--- +title: OpenHarmony-Log-guide.md +permalink: /pages/extra/f12b16/ +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +date: 2021-12-30 18:17:45 +--- +# OpenHarmony日志打印规范 + +## 简介 +公共流水日志指通过系统日志打印接口(HiLog)统一输出到日志服务的日志。日志用来记录用户操作、系统运行状态等,是一个系统的重要组成部分,然而由于日志不是核心功能,所以日志质量常常不被开发人员所重视。 + +尽管日志记录是必要的,但它对性能有明显的负面影响,如果不保持合理的简洁性,则会很快失去其有用性。每个领域在打印日志的时候都应该尽可能的合理,不要将别人的日志冲掉,就像你希望别人不冲掉你的日志一样。 + +## 日志级别 + +- **【规则】根据实际情况正确的使用日志打印等级** + +**说明:** 日志级别要符合日志内容的实际级别,日志级别说明如下: + +FATAL:重大致命异常,表明程序或功能即将崩溃,故障无法恢复。 + +ERROR: 程序或功能发生了错误,该错误会影响功能的正常运行或用户的正常使用,可以恢复但恢复代价较高,如重置数据等。 + +WARN:发生了较为严重的非预期情况,但是对用户影响不大,程序可以自动恢复或通过简单的操作就可以恢复的问题。 + +INFO:用来记录业务关键流程节点,可以还原业务的主要运行过程;用来记录非正常情况信息,但这些情况都是可以预期的(如无网络信号、登录失败等)。这些日志都应该由该业务内处于支配地位的模块来记录,避免在多个被调用的模块或低级函数中重复记录。 + +DEBUG: 比INFO级别更详细的流程记录,通过该级别的日志可以更详细地分析业务流程和定位分析问题。DEBUG级别的日志在正式发布版本中默认不会被打印,只有在调试版本或打开调试开关的情况下才会打印。 + +## 日志内容 + +- **【规则】日志打印内容使用英文描述,单词拼写无误,符合语法规范,准确表述日志的含义** + +**说明:** 日志内容应该简明扼要地描述发生的事情,阅读日志的人可以通过日志直接知道表述的含义,尽量不要通过产生日志的代码才能知道;符合语法语义的日志打印也有利于后续日志分析工具对日志进行自动化解析。如: + +“1234” 除了开发人员自己没人知道什么意义; + +“Error happened” 哪里发生了什么错误,错误的原因值等都没有打印出来,不利于问题的定位分析。 + +- **【规则】日志中禁止打印隐私信息** + +**说明:** 硬件序列号、个人账号、密码、身份等隐私信息禁止在日志中打印。隐私信息的范围遵从国家和地区的政策要求。 + +- **【规则】日志中禁止打印其它与业务无关的信息** + +**说明:** 禁止打印如issue单号、需求单号、公司部门名称、开发人员自己的姓名、工号、名字缩写、当天的天气心情等任何与业务代码无关的信息。 + +- **【规则】日志中禁止打印重复信息** + +**说明:** 禁止在不同的地方打印的内容完全一样的日志,在问题定位时无法准确找到代码位置。 + +- **【规则】禁止在日志打印语句中调用业务接口函数** + +**说明:** 日志打印不应该对业务的正常流程产生任何影响,定位问题走读代码时通常会忽略日志代码对业务逻辑的影响。 + +- **【规则】禁止将开发调试过程中使用的日志打印提交到代码仓中** + +**说明:** 为了定位问题可能会在代码中的每一步增加一行日志打印,或将各种变量内容打印出来(可能含用户隐私), +这些代码在提交到代码仓之前必须删除。 + +- **【建议】日志打印长度不要过长,尽可能使日志记录显示在一行以内** + +**说明:** 一行的长度通常是指在100个字符左右,尽量不要打印超过160个字符以上的日志。 + +## 打印时机 + +- **【规则】高频代码的正常流程中禁止打印日志** + +**说明:** 如被高频调用的接口函数,大数据量处理的循环中,高频的软硬件中断处理中,协议数据流处理中,多媒体音视频流处理中,显示屏幕刷新处理中等等,这些地方基本都是只要系统不休眠就会一直运行的代码,这些代码正常处理禁止打印日志,但可在错误分支中打印日志。开发调试过程中在这里增加的日志在提交代码时必须清除掉或使用开关关闭。 + +- **【规则】可能重复发生的日志需要进行频率限制** + +**说明:** 当事实证明某些日志记录可能会发生多次时,最好实施一种频率限制机制,防止出现具有相同(或非常相似)信息的大量重复日志副本。 + +- **【规则】在基本不可能发生的点必须要打印日志** + +**说明:** 根据墨菲定律,只要有可能发生的是就一定会发生,一旦发生就是疑难杂症。 + +- **【建议】日志字符串应在日志打印时再生成** + +**说明:** 日志字符串越迟生成越好,最好是在日志打印那一刻才生成,这样当日志被关闭时也就不会生成这个字符串,从而最大程度地减少对系统的开销。 + +## 日志形式 + + +- **【规则】事件记录的日志使用who do what 主谓宾的形式打印** + +- **【规则】状态变化的日志打印使用state\_name:s1->s2, reason:msg的形式打印** + +- **【规则】参数值的日志打印使用name1=value1, name2=value2…的形式打印** + +- **【规则】代码运行成功的日志使用xxx successful的形式打印** + +- **【规则】代码运行失败的日志使用xxx failed, please xxx的形式打印,且需包含可能的解决方案** + + 如:"Connect to server failed, please check network configuration"。 + +## 常见模式日志打印要求 + +### 流程类日志 + + +- **【建议】日志中应当记录业务的关键流程节点日志,包括业务的开始点,关键条件分支节点,错误处理点,业务结束点等** + +### 数据库类日志 + +- **【建议】日志中应当记录对数据库的各种操作及其相关信息** + +**说明:** 数据库的常规操作包括: +增、删、改、查;操作的发起者、操作类型、操作成功还是失败也要在日志中记录;但操作及返回结果中的内容通常不应记录以防止泄露用户隐私;查询结果的数量可以打印。 + +- **【建议】对于性能敏感型业务的数据库操作日志中需记录操作消耗的时间** + +**说明:** 数据库操作涉及I/O读写, 对于性能敏感性业务,数据库操作通常会是性能的关键节点,记录时间可以作为性能调优的参考依据。 + +- **【建议】日志中应当记录数据库的JOB相关信息** + +**说明:** JOB的名称,执行内容,启动时间,结束时间,执行结果应当在日志中记录。 + +### 文件类日志 +- **【建议】日志中应当记录对文件的各种操作及其相关信息** + +**说明:** 文件的常规操作包括: 创建、打开、读取、写入、关闭、删除、获取属性,操作的发起者、操作类型、操作结果需要记录日志;但文件内容不可记录以防止泄露用户隐私或暴露系统安全漏洞,系统文件名可以打印,用户文件名不可以打印; 文件句柄值可以打印。 + +- **【建议】批量文件操作只打印一条日志而不是打印多条日志** + +**说明:** 如批量删除大量文件,不要每删除一个文件就打印一条日志,只要记录删除的文件数即可,如果文件所在目录是系统创建,还要打印目录名称。 + +### 关键对象/对象池日志 + +**说明:** 关键对象/对象池可能是一个类或者一个结构体,也可能是一个队列或堆栈的数据结构,也可能是一个简单的原始类型变量,它处于系统的关键地位,系统的调度控制、状态记录、信息流转等动作都依赖它。 + +- **【建议】日志中应当记录关键对象的操作过程,操作结果,状态变化** + +**说明:** 对象的操作包括:创建、加载、卸载、释放等,对关键对象的操作需记录操作主体,操作类型,操作结果;状态类的需记录状态变化的前后值。 + +### 线程日志 + +- **【建议】日志中需记录线程的各种操作及相关信息** + +**说明:** 线程的操作包括: 创建、启动、暂停、终止。日志中需记录操作线程的操作类型,操作结果、线程号,线程名称(重要线程一定要设置线程名)。 + +- **【建议】线程陷入死循环或死锁等错误时要记录日志** + +**说明:** 对于有等锁处理、异步处理、循环处理等逻辑的线程在线程发生死锁或死循环时要有检测机制,并在错误发生时打印日志。 + +- **【建议】消息处理型的线程需要打印消息处理相关的日志** + +**说明:** 包括消息名称、消息处理结果,消息处理时长;对于高频消息,只需要打印消息处理结果错误时的日志即可 + +### 并发控制日志 + +**说明:** 并发控制的对象可能是锁、临界区、信号量等。 + +- **【建议】日志中需记录并发控制对象的操作及其相关信息** + +**说明:** 并发控制的操作包括:创建、占用、释放、等待等。日志中需记录操作的类型,操作对象的名称、操作的结果、操作的位置等信息。 + +### 共享内存日志 + +**说明:** 共享内存是软件系统中常用的进程间通信方法,它常用于在模块间共享数据或传递数据。共享内存所存放的数据可以是配置数据、数据库数据等。 + +- **【建议】日志中需记录对共享内存的操作及相关信息** + +**说明:** 对共享内存的操作包括:创建、删除、数据设置、数据查询、销毁等。日志中需记录对共享内存操作的操作者,操作类型、操作结果。 + +### 接口交互日志 + + +接口包括系统的内外部接口,内部接口指系统内部子系统、子模块之间的接口。形式可能包括模块间消息发送、IPC接口、RPC接口等。 + +- **【建议】日志需记录接口交互相关的信息** + +**说明:** 接口交互相关的信息包括:接口的调用者、消息内容(不能涉及用户隐私)、处理结果、返回值(不能涉及用户隐私)。 + +### 状态机日志 + +- **【建议】日志需记录状态机的操作及状态转换信息** + +**说明:** 状态机的操作包括:创建、开始、状态转换、结束、销毁等。状态机通常受外部条件激励(如消息、资源等)变换状态,状态机的状态变化前后的状态名称、导致变化的外部激励条件等信息也应该被记录。 + +### 其它操作系统资源 +这里说的主要操作系统资源指Socket、定时器等不在前面小节已专门提及的资源(如文件、线程等) + +- **【建议】日志中需要记录socket连接建立的过程和结果、连接维持的情况、连接断开的情况及原因** + +- **【建议】日志中需要记录定时器启动、复位、销毁、超时处理过程** + +- **【建议】使用其它类似操作系统中提供的资源也应参照遵循类似上述的日志记录原则** + +## HiLog接口使用规范 + + +- **【规则】每个业务须有独立的Domain ID** + +**说明:** 系统各领域使用HiLog API打印日志须先到DFX申请标识业务的Domain ID。Domain ID用于度量和管控单个业务日志质量,支持开发人员调试使用Domain ID过滤出自身业务日志分析提高调试效率,不允许在不申请Domain ID情况下,直接使用其它领域的Domain ID。对测试代码,要求使用专门为测试配置的Domain ID 0xD000F00 打印日志。 + +系统Domain ID的范围为:**0xD000001\~0xD00FFFF** + +- **【建议】每个业务内部基于Domain ID分配机制在领域内按照层次、模块的粒度划分使用** + +**说明:** Domain ID为32位整数,以16机制形式表达,分配范围0xD0xxxyy。其中D0为domain域标识,xxx高12位为DFT分配值,yy低8位业务领域内部使用。要求Domain ID 内部分配能够定界到组织或模块,反应领域内具体组织或模块日志质量,同时DFX会基于 Domain ID对日志打印进行管控,防止因为单个模块日志打印多影响领域内其它模块的日志输出,如BT业务内按照层次模块进一步划分: + + + APP | BT-App1 BT-App2 + --------------------------------------- + Framework | BT-Service1 BT-Service2 + --------------------------------------- + HAL | BT-HAL + --------------------------------------- + Kernel | BT-Driver1 BT-Driver2 + +BT内的Domain ID可以进一步划分: +| Domain名称 | Domain ID | +|----|----| +| BT | 0xD000100 | +| BT-App1 | 0xD000101 | +| BT-App2 | 0xD000102 | +| BT-Service1 | 0xD000103 | +| BT-Service2 | 0xD000104 | +| BT-HAL | 0xD000105 | +| BT-Driver1 | 0xD000106 | +| BT-Driver2 | 0xD000107 | + +- **【规则】日志服务会对每个业务的日志量进行流量管控,修改默认的流量阈值需要经过评审** + +**说明:** 日志服务中会对每个领域的日志流量进行控制,在正式发布的版本上默认每个领域的日志流量阈值是**2048KB/秒**, 在调试版本上默认阈值是**10240KB/秒**, 如果需要修改默认阈值需经过DFX领域审查。 + +- **【规则】正确填写日志格式化隐私参数标识{public},{private}** + +**说明:** 隐私参数标识{public},{private}用来标识每个参数日志内容是否含隐私敏感信息。Hilog +API会自动对标识{public}参数内容以明文输出,对标识{private}参数内容以<private>过滤回显,禁止不分析日志打印内容随意设置隐私参数标识。如: + +源码: + + + HiLog.info(LABEL, "Device Name:%{public}s, IP:%{private}s.", DeviceName, ip); + + +日志输出: + + + 11-11 09:19:00.932 1513 1513 E 00500/Settings: MyPad001, IP: diff --git a/website/docs/_posts/contribute/OpenHarmony-c-coding-style-guide.md b/website/docs/_posts/contribute/OpenHarmony-c-coding-style-guide.md new file mode 100644 index 0000000000000000000000000000000000000000..c789d4d5e4f53c916e1dde97529be1280d897648 --- /dev/null +++ b/website/docs/_posts/contribute/OpenHarmony-c-coding-style-guide.md @@ -0,0 +1,2016 @@ +--- +title: OpenHarmony-c-coding-style-guide.md +permalink: /pages/extra/29cfe8/ +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +date: 2021-12-30 18:17:45 +--- +# C语言编程规范 + +## 目的 +规则并不是完美的,通过禁止在特定情况下有用的特性,可能会对代码实现造成影响。但是我们制定规则的目的“为了大多数程序员可以得到更多的好处”, 如果在团队运作中认为某个规则无法遵循,希望可以共同改进该规则。 +参考该规范之前,希望您具有相应的C语言基础能力,而不是通过该文档来学习C语言。 +1. 了解C语言的ISO标准; +2. 熟知C语言的基本语言特性; +3. 了解C语言的标准库; + +## 总体原则 +代码需要在保证功能正确的前提下,满足**可读、可维护、安全、可靠、可测试、高效、可移植**的特征要求。 + +## 约定 + +**规则**:编程时必须遵守的约定 +**建议**:编程时必须加以考虑的约定 + +无论是“规则”还是“建议”,都必须理解该条目这么规定的原因,并努力遵守。 + +## 例外 + +在不违背总体原则,经过充分考虑,有充足的理由的前提下,可以适当违背规范中约定。 +例外破坏了代码的一致性,请尽量避免。“规则”的例外应该是极少的。 + +下列情况,应风格一致性原则优先: +**修改外部开源代码、第三方代码时,应该遵守开源代码、第三方代码已有规范,保持风格统一。** + + +# 1 命名 + +命名包括文件、函数、变量、类型、宏等命名。 + +命名被认为是软件开发过程中最困难,也是最重要的事情。 +标识符的命名要清晰、明了,有明确含义,符合阅读习惯,容易理解。 + +统一的命名风格是一致性原则最直接的体现。 + + +## 总体风格 + +**驼峰风格(CamelCase)** +大小写字母混用,单词连在一起,不同单词间通过单词首字母大写来分开。 +按连接后的首字母是否大写,又分: **大驼峰(UpperCamelCase)**和**小驼峰(lowerCamelCase)** + +**内核风格(unix_like)** +内核风格又称蛇形风格。单词小写,用下划线分割。 +如:'test_result' + +### 规则1.1 标识符命名使用驼峰风格 + +| 类型 | 命名风格 | +|-|-| +| 函数,结构体类型,枚举类型,联合体类型 | 大驼峰 | +| 变量,函数参数,宏参数,结构体中字段,联合体中成员 | 小驼峰 | +| 宏,常量,枚举值,goto 标签 | 全大写,下划线分割 | + +注意: +上表中`常量`是指,全局作用域下,const 修饰的基本数据类型、枚举、字符串类型的变量,不包括数组、结构体和联合体。 +上表中`变量`是指除常量定义以外的其他变量,均使用小驼峰风格。 +对于更亲和Linux/Unix的代码,可以使用内核风格。 +已使用内核命名风格的代码,可以选择继续使用内核风格。 +不管什么样的命名风格,都应该保证同一函数或结构体、联合体内的命名风格是一致的。 + +### 建议1.1 作用域越大,命名应越精确 + +C 与 C++ 不同,没有名字空间,没有类,所以全局作用域下的标识符命名要考虑不要冲突。 +对于全局函数、全局变量、宏、类型名、枚举名的命名,应当精确描述并全局唯一。 + +例: +```c +int GetCount(void); // Bad: 描述不精确 +int GetActiveConnectCount(void); // Good +``` + +为了命名更精确,必要时可以增加模块前缀。 +模块前缀与命名主体之间,按驼峰方式连接。 +示例: +```c +int PrefixFuncName(void); // OK: 驼峰方式,形式上无前缀,内容上有前缀 + +enum XxxMyEnum { // OK. + ... +}; +``` + +## 文件命名 + +### 建议1.2 文件命名统一采用小写字符 + +文件名命名只允许使用小写字母、数字以及下划线(\_)。 +文件名应尽量简短、准确、无二义性。 +不大小写混用的原因是,不同系统对文件名大小写处理会不同(如 MicroSoft 的 DOS, Windows 系统不区分大小写,但是 Unix / Linux, Mac 系统则默认区分)。 + +好的命名举例: +`dhcp_user_log.c` + +坏的命名举例: +`dhcp_user-log.c`: 不推荐用'\-'分隔 +`dhcpuserlog.c`: 未分割单词,可读性差 + +## 函数命名 + +函数命名统一使用大驼峰风格。 + +### 建议1.3 函数的命名遵循阅读习惯 + +动作类函数名,可以使用动宾结构。如: +```c +AddTableEntry() // OK +DeleteUser() // OK +GetUserInfo() // OK +``` +判断型函数,可以用形容词,或加 is: +```c +DataReady() // OK +IsRunning() // OK +JobDone() // OK +``` +数据型函数: +```c +TotalCount() // OK +GetTotalCount() // OK +``` + +## 变量命名 + +变量命名使用小驼峰风格,包括全局变量,局部变量,函数声明或定义中的参数,带括号宏中的参数。 + +### 规则1.2 全局变量应增加 'g_' 前缀,函数内静态变量命名不需要加特殊前缀 + +全局变量应当尽量少使用,使用时应特别注意,所以加上前缀用于视觉上的突出,促使开发人员对这些变量的使用更加小心。 +全局静态变量命名与全局变量相同,函数内的静态变量命名与普通局部变量相同。 + +```c +int g_activeConnectCount; + +void Func(void) +{ + static int pktCount = 0; + ... +} +``` + +注意: +常量本质也是全局变量,但如果命名风格是全大写,下划线连接的格式,则不适用当前规则。 + +### 建议1.4 局部变量应该简短,且能够表达相关含义 + +函数局部变量的命名,在能够表达相关含义的前提下,应该简短。 + +如下: +```c +int Func(...) +{ + enum PowerBoardStatus powerBoardStatusOfSlot; // Not good: 局部变量有点长 + powerBoardStatusOfSlot = GetPowerBoardStatus(slot); + if (powerBoardStatusOfSlot == POWER_OFF) { + ... + } + ... +} +``` +更好的写法: +```c +int Func(...) +{ + enum PowerBoardStatus status; // Good: 结合上下文,status 已经能明确表达意思 + status = GetPowerBoardStatus(slot); + if (status == POWER_OFF) { + ... + } + ... +} +``` +类似的, tmp 可以用来称呼任意类型的临时变量。 +过短的变量命名应慎用,但有时候,单字符变量也是允许的,如用于循环语句中的计数器变量: +```c +int i; +... +for (i = 0; i < COUNTER_RANGE; i++) { + ... +} +``` +或一些简单的数学计算函数中的变量: +```c +int Mul(int a, int b) +{ + return a * b; +} +``` + +## 类型命名 + +类型命名采用大驼峰命名风格。 +类型包括结构体、联合体、枚举类型名。 + +例: +```c +struct MsgHead { + enum MsgType type; + int msgLen; + char *msgBuf; +}; + +union Packet { + struct SendPacket send; + struct RecvPacket recv; +}; + +enum BaseColor { + RED, // 注意,枚举类型是大驼峰,枚举值应使用宏风格 + GREEN, + BLUE +}; + +typedef int (*NodeCmpFunc)(struct Node *a, struct Node *b); +``` + +通过 typedef 对结构体、联合体、枚举起别名时,尽量使用匿名类型。 +若需要指针自嵌套,可以增加 'tag' 前缀或下划线后缀。 +```c +typedef struct { // Good: 无须自嵌套,使用匿名结构体 + int a; + int b; +} MyType; // 结构体别名用大驼峰风格 +``` +```c +typedef struct tagNode { // Good: 使用 tag 前缀。这里也可以使用 'Node_'代替也可以。 + struct tagNode *prev; + struct tagNode *next; +} Node; // 类型主体用大驼峰风格 +``` + +## 宏、常量、枚举命名 + +宏、枚举值采用全大写,下划线连接的格式。 +常量推荐采用全大写,下划线连接风格。作为全局变量,也可以保持与普通全局变量命名风格相同。 +这里常量如前文定义,是指基本数据类型、枚举、字符串类型的全局 const 变量。 + +函数式宏,命名风格,采用全大写,下划线连接风格。 +例外情况: +1、用宏实现泛型功能的函数。如:实现list,map等功能的宏。可以与函数的命名方式相同,使用大驼峰命名风格。 +2、函数接口发生变更为兼容老版本时,使用函数同宏进行替代。可以与函数的命名方式相同,使用大驼峰命名风格。 +3、日志打印宏。可以与函数的命名方式相同,使用大驼峰命名风格。 +注:使用大驼峰命名的函数式宏,需要在接口说明中标注为宏。 + +宏举例: +```c +#define PI 3.14 +#define MAX(a, b) (((a) < (b)) ? (b) : (a)) +``` +```c +#ifdef SOME_DEFINE +void Bar(int); +#define Foo(a) Bar(a) // 特殊场景,用大驼峰风格命名函数式宏 +#else +void Foo(int); +#endif +``` + +常量举例: +```c +const int VERSION = 200; // OK. + +const enum Color DEFAULT_COLOR = BLUE; // OK. + +const char PATH_SEP = '/'; // OK. + +const char * const GREETINGS = "Hello, World!"; // OK. +``` + +非常量举例: +```c +// 结构体类型,不符合常量定义 +const struct MyType g_myData = { ... }; // OK: 用小驼峰 + +// 数组类型,不符合常量定义 +const int g_xxxBaseValue[4] = { 1, 2, 4, 8 }; // OK: 用小驼峰 + +int Foo(...) +{ + // 局部作用域,不符合常量定义 + const int bufSize = 100; // OK: 用小驼峰 + ... +} +``` + +枚举举例: +```c +// 注意,枚举类型名用大驼峰,其下面的取值是全大写,下划线相连 +enum BaseColor { + RED, + GREEN, + BLUE +}; +``` + +### 建议1.5 避免函数式宏中的临时变量命名污染外部作用域 + +首先,**定义函数式宏前,应考虑能否定义为函数。如果可以则不要定义为函数式宏。** + +当函数式宏需要定义局部变量时,为了防止跟外部函数中的局部变量有命名冲突。 + +后置下双划线,是一种解决方案。 例: +```c +#define SWAP_INT(a, b) do { \ + int tmp__ = a; \ + a = b; \ + b = tmp__; \ +} while (0) +``` + +# 2 排版格式 + +## 行宽 + +### 规则2.1 行宽不超过 120 个字符 + +代码行宽不宜过长,否则不利于阅读。 +控制行宽长度可以间接的引导开发去缩短函数、变量的命名,减少嵌套的层数,提升代码可读性。 +要求每行字符数不要超过 **120** 个;除非超过 **120** 能显著增加可读性,并且不会隐藏信息。 +虽然现代显示器分辨率已经很高,但是行宽过长,反而提高了阅读理解的难度;跟本规范提倡的“清晰”、“简洁”原则相背。 + +如下场景不宜换行,可以例外: +- 换行会导致内容截断,无法被方便查找(grep)的字符串,如命令行或 URL 等等。包含这些内容的代码或注释,可以适当例外。 +- \#include / \#error 语句可以超出行宽要求,但是也需要尽量避免。 + +例: +```c +#ifndef XXX_YYY_ZZZ +#error Header aaaa/bbbb/cccc/abc.h must only be included after xxxx/yyyy/zzzz/xyz.h +#endif +``` +## 缩进 + +### 规则2.2 使用空格进行缩进,每次缩进4个空格 + +只允许使用空格(space)进行缩进,每次缩进为 **4** 个空格。不允许使用Tab键进行缩进。 +当前几乎所有的集成开发环境(IDE)和代码编辑器都支持配置将Tab键自动扩展为**4**空格输入,请配置你的代码编辑器支持使用空格进行缩进。 + +## 大括号 + +### 规则2.3 使用 K&R 缩进风格 + +**K&R风格** +换行时,函数左大括号另起一行放行首,并独占一行;其他左大括号跟随语句放行末。 +右大括号独占一行,除非后面跟着同一语句的剩余部分,如 do 语句中的 while,或者 if 语句的 else/else if,或者逗号、分号。 + +如: +```c +struct MyType { // Good: 跟随语句放行末,前置1空格 + ... +}; // Good: 右大括号后面紧跟分号 + +int Foo(int a) +{ // Good: 函数左大括号独占一行,放行首 + if (...) { + ... + } else { // Good: 右大括号与 else 语句在同一行 + ... + } // Good: 右大括号独占一行 +} +``` + +## 函数声明和定义 + +### 规则2.4 函数声明、定义的返回类型和函数名在同一行;函数参数列表换行时应合理对齐 + +在声明和定义函数的时候,函数的返回值类型应该和函数名在同一行。 + +函数参数列表换行时,应合理对齐。 +参数列表的左圆括号总是和函数名在同一行,不要单独一行;右圆括号总是跟随最后一个参数。 + +换行举例: +```c +ReturnType FunctionName(ArgType paramName1, ArgType paramName2) // Good:全在同一行 +{ + ... +} + +ReturnType VeryVeryVeryLongFunctionName(ArgType paramName1, // 行宽不满足所有参数,进行换行 + ArgType paramName2, // Good:和上一行参数对齐 + ArgType paramName3) +{ + ... +} + +ReturnType LongFunctionName(ArgType paramName1, ArgType paramName2, // 行宽限制,进行换行 + ArgType paramName3, ArgType paramName4, ArgType paramName5) // Good: 换行后 4 空格缩进 +{ + ... +} + +ReturnType ReallyReallyReallyReallyLongFunctionName( // 行宽不满足第1个参数,直接换行 + ArgType paramName1, ArgType paramName2, ArgType paramName3) // Good: 换行后 4 空格缩进 +{ + ... +} +``` + +## 函数调用 + +### 规则2.5 函数调用参数列表换行时保持参数进行合理对齐 + +函数调用时,函数参数列表如果换行,应该进行合理的参数对齐。 +左圆括号总是跟函数名,右圆括号总是跟最后一个参数。 + +换行举例: +```c +ReturnType result = FunctionName(paramName1, paramName2); // Good:函数参数放在一行 + +ReturnType result = FunctionName(paramName1, + paramName2, // Good:保持与上方参数对齐 + paramName3); + +ReturnType result = FunctionName(paramName1, paramName2, + paramName3, paramName4, paramName5); // Good:参数换行,4 空格缩进 + +ReturnType result = VeryVeryVeryLongFunctionName( // 行宽不满足第1个参数,直接换行 + paramName1, paramName2, paramName3); // 换行后,4 空格缩进 +``` + +如果函数调用的参数存在内在关联性,按照可理解性优先于格式排版要求,对参数进行合理分组换行。 +```c +// Good:每行的参数代表一组相关性较强的数据结构,放在一行便于理解 +int result = DealWithStructureLikeParams(left.x, left.y, // 表示一组相关参数 + right.x, right.y); // 表示另外一组相关参数 +``` + +## 条件语句 + +### 规则2.6 条件语句必须要使用大括号 + +我们要求条件语句都需要使用大括号,即便只有一条语句。 +理由: +- 代码逻辑直观,易读; +- 在已有条件语句代码上增加新代码时不容易出错; +- 对于在条件语句中使用函数式宏时,没有大括号保护容易出错(如果宏定义时遗漏了大括号)。 + +```c +if (objectIsNotExist) { // Good:单行条件语句也加大括号 + return CreateNewObject(); +} +``` + +### 规则2.7 禁止 if/else/else if 写在同一行 + +条件语句中,若有多个分支,应该写在不同行。 + +如下是正确的写法: +```c +if (someConditions) { + ... +} else { // Good: else 与 if 在不同行 + ... +} +``` + +下面是不符合规范的案例: +```c +if (someConditions) { ... } else { ... } // Bad: else 与 if 在同一行 +``` + +## 循环 + +### 规则2.8 循环语句必须使用大括号 + +和条件表达式类似,我们要求for/while循环语句必须加上大括号,即便循环体是空的,或循环语句只有一条。 +```c +for (int i = 0; i < someRange; i++) { // Good: 使用了大括号 + DoSomething(); +} +``` +```c +while (condition) { } // Good:循环体是空,使用大括号 +``` +```c +while (condition) { + continue; // Good:continue 表示空逻辑,使用大括号 +} +``` + +坏的例子: +```c +for (int i = 0; i < someRange; i++) + DoSomething(); // Bad: 应该加上括号 +``` +```c +while (condition); // Bad:使用分号容易让人误解是while语句中的一部分 +``` + +## switch语句 + +### 规则2.9 switch 语句的 case/default 要缩进一层 + +switch 语句的缩进风格如下: +```c +switch (var) { + case 0: // Good: 缩进 + DoSomething1(); // Good: 缩进 + break; + case 1: { // Good: 带大括号格式 + DoSomething2(); + break; + } + default: + break; +} +``` + +```c +switch (var) { +case 0: // Bad: case 未缩进 + DoSomething(); + break; +default: // Bad: default 未缩进 + break; +} +``` + +## 表达式 + +### 建议2.1 表达式换行要保持换行的一致性,操作符放行末 + +较长的表达式,不满足行宽要求的时候,需要在适当的地方换行。一般在较低优先级操作符或连接符后面截断,操作符或连接符放在行末。 +操作符、连接符放在行末,表示“未结束,后续还有”。 + +例: +```c +// 假设下面第一行已经不满足行宽要求 +if ((currentValue > MIN) && // Good:换行后,布尔操作符放在行末 + (currentValue < MAX)) { + DoSomething(); + ... +} + +int result = reallyReallyLongVariableName1 + // Good: 加号留在行末 + reallyReallyLongVariableName2; +``` + +表达式换行后,注意保持合理对齐,或者4空格缩进。参考下面例子 +```c +int sum = longVaribleName1 + longVaribleName2 + longVaribleName3 + + longVaribleName4 + longVaribleName5 + longVaribleName6; // OK: 4空格缩进 + +int sum = longVaribleName1 + longVaribleName2 + longVaribleName3 + + longVaribleName4 + longVaribleName5 + longVaribleName6; // OK: 保持对齐 +``` + +## 变量赋值 + +### 规则2.10 多个变量定义和赋值语句不允许写在一行 + +每行最好只有一个变量初始化的语句,更容易阅读和理解。 + +```c +int maxCount = 10; +bool isCompleted = false; +``` + +下面是不符合规范的示例: +```c +int maxCount = 10; bool isCompleted = false; // Bad:多个初始化放在了同一行 +int x, y = 0; // Bad:多个变量定义需要分行,每行一个 + +int pointX; +int pointY; +... +pointX = 1; pointY = 2; // Bad:多个变量赋值语句放同一行 +``` + +例外情况: +对于多个相关性强的变量定义,且无需初始化时,可以定义在一行,减少重复信息,以便代码更加紧凑。 +```c +int i, j; // Good:多变量定义,未初始化,可以写在一行 +for (i = 0; i < row; i++) { + for (j = 0; j < col; j++) { + ... + } +} +``` + +## 初始化 + +初始化包括结构体、联合体及数组的初始化 + +### 规则2.11 初始化换行时要有缩进,或进行合理对齐 + +结构体或数组初始化时,如果换行应保持4空格缩进。 +从可读性角度出发,选择换行点和对齐位置。 +```c +// Good: 满足行宽要求时不换行 +int arr[4] = { 1, 2, 3, 4 }; + +// Good: 行宽较长时,换行让可读性更好 +const int rank[] = { + 16, 16, 16, 16, 32, 32, 32, 32, + 64, 64, 64, 64, 32, 32, 32, 32 +}; +``` + +对于复杂结构数据的初始化,尽量清晰、紧凑。 +参考如下格式: +```c +int a[][4] = { + { 1, 2, 3, 4 }, { 2, 2, 3, 4 }, // OK. + { 3, 2, 3, 4 }, { 4, 2, 3, 4 } +}; + +int b[][8] = { + { 1, 2, 3, 4, 5, 6, 7, 8 }, // OK. + { 2, 2, 3, 4, 5, 6, 7, 8 } +}; +``` +```c +int c[][8] = { + { + 1, 2, 3, 4, 5, 6, 7, 8 // OK. + }, { + 2, 2, 3, 4, 5, 6, 7, 8 + } +}; +``` + +注意: +- 左大括号放行末时,对应的右大括号需另起一行 +- 左大括号被内容跟随时,对应的右大括号也应跟随内容 + +### 规则2.12 结构体和联合体在按成员初始化时,每个成员初始化单独一行 + +C99标准支持结构体和联合体按照成员进行初始化,标准中叫"指定初始化"(designated initializer)。 如果按照这种方式进行初始化,每个成员的初始化单独一行。 +```c +struct Date { + int year; + int month; + int day; +}; + +struct Date date = { // Good:使用指定初始化方式时,每行初始化一个 + .year = 2000, + .month = 1, + .day = 1 +}; +``` + +## 指针 + +### 建议2.2 指针类型"\*"跟随变量名或者类型,不要两边都留有空格或都没有空格 + +声明或定义指针变量或者返回指针类型函数时,"\*" 靠左靠右都可以,但是不要两边都有或者都没有空格。 +```c +int *p1; // OK. +int* p2; // OK. + +int*p3; // Bad: 两边都没空格 +int * p4; // Bad: 两边都有空格 +``` + +选择一种风格,并保持一致性。 + +选择"\*"跟随类型风格时,避免一行同时声明带指针的多个变量。 +```c +int* a, b; // Bad: 很容易将 b 误理解成指针 +``` + +选择"\*"跟随变量风格时,可能会存在无法紧跟的情况。 +无法跟随时就不跟随,不要破坏风格一致性。 +```c +char * const VERSION = "V100"; // OK. +int Foo(const char * restrict p); // OK. +``` +注意,任何时候 "\*" 不要紧跟 const 或 restrict 关键字。 + +## 编译预处理 + +### 规则2.13 编译预处理的"#"默认放在行首,嵌套编译预处理语句时,"#"可以进行缩进 + +编译预处理的"#"统一放在行首;即便编译预处理的代码是嵌入在函数体中的,"#"也应该放在行首。 +注意,开发过程尽量不要使用编译预处理宏。如果需使用,则应由专人进行统一管理。 + +## 空格和空行 + +### 规则2.14 水平空格应该突出关键字和重要信息,避免不必要的留白 + +水平空格应该突出关键字和重要信息,每行代码尾部不要加空格。 总体规则如下: +- if, switch, case, do, while, for 等关键字之后加空格; +- 小括号内部的两侧,不要加空格 +- 二元操作符(= + ‐ < > * / % | & ^ <= >= == !=)左右两侧加空格 +- 一元操作符(& * + ‐ ~ !)之后不要加空格 +- 三目操作符(? :)符号两侧均需要空格 +- 结构体中表示位域的冒号,两侧均需要空格 +- 前置和后置的自增、自减(++ --)和变量之间不加空格 +- 结构体成员操作符(. ->)前后不加空格 +- 大括号内部两侧有无空格,左右必须保持一致 +- 逗号、分号、冒号(不含三目操作符和表示位域的冒号)紧跟前面内容无空格,其后需要空格 +- 函数参数列表的小括号与函数名之间无空格 +- 类型强制转换的小括号与被转换对象之间无空格 +- 数组的中括号与数组名之间无空格 +- 涉及到换行时,行末的空格可以省去 + +对于大括号内部两侧的空格,**建议**如下: +- 一般的,大括号内部两侧建议加空格 +- 对于空的,或单个标识符,或单个字面常量,空格不是必须 +如:'{}', '{0}', '{NULL}', '{"hi"}' 等 +- 连续嵌套的多重括号之间,空格不是必须 +如:'{{0}}', '{{ 1, 2 }}' 等 +错误示例:'{ 0, {1}}',不属于连续嵌套场景,而且最外侧大括号左右不一致 + +常规情况: +```c +int i = 0; // Good:变量初始化时,= 前后应该有空格,分号前面不要留空格 +int buf[BUF_SIZE] = {0}; // Good:数组初始化时,大括号内空格可选 +int arr[] = { 10, 20 }; // Good: 正常大括号内部两侧建议加空格 +``` + +函数定义和函数调用: +```c +int result = Foo(arg1,arg2); + ^ // Bad: 逗号后面应该有空格 + +int result = Foo( arg1, arg2 ); + ^ ^ // Bad: 小括号内部两侧不应该有空格 +``` + +指针和取地址 +```c +x = *p; // Good:*操作符和指针p之间不加空格 +p = &x; // Good:&操作符和变量x之间不加空格 +x = r.y; // Good:通过.访问成员变量时不加空格 +x = r->y; // Good:通过->访问成员变量时不加空格 +``` + +操作符: +```c +x = 0; // Good:赋值操作的=前后都要加空格 +x = -5; // Good:负数的符号和数值之前不要加空格 +++x; // Good:前置和后置的++/--和变量之间不要加空格 +x--; + +if (x && !y) // Good:布尔操作符前后要加上空格,!操作和变量之间不要空格 +v = w * x + y / z; // Good:二元操作符前后要加空格 +v = w * (x + z); // Good:括号内的表达式前后不需要加空格 +``` + +循环和条件语句: +```c +if (condition) { // Good:if关键字和括号之间加空格,括号内条件语句前后不加空格 + ... +} else { // Good:else关键字和大括号之间加空格 + ... +} + +while (condition) {} // Good:while关键字和括号之间加空格,括号内条件语句前后不加空格 + +for (int i = 0; i < someRange; ++i) { // Good:for关键字和括号之间加空格,分号之后加空格 + ... +} + +switch (var) { // Good: switch 关键字后面有1空格 + case 0: // Good:case语句条件和冒号之间不加空格 + ... + break; + ... + default: + ... + break; +} +``` + +注意:当前的集成开发环境(IDE)和代码编辑器都可以设置删除行尾的空格,请正确配置你的编辑器。 + +### 建议2.3 合理安排空行,保持代码紧凑 + +减少不必要的空行,可以显示更多的代码,方便代码阅读。下面有一些建议遵守的规则: +- 根据上下内容的相关程度,合理安排空行; +- 函数内部、类型定义内部、宏内部、初始化表达式内部,不使用连续空行 +- 不使用连续 **3** 个空行,或更多 +- 大括号内的代码块首行之前和末行之后不要加空行。 + +```c +ret = DoSomething(); + +if (ret != OK) { // Bad: 返回值判断应该紧跟函数调用 + return -1; +} +``` +```c +int Foo(void) +{ + ... +} + + + +int Bar(void) // Bad:最多使用连续2个空行。 +{ + ... +} +``` +```c +int Foo(void) +{ + + DoSomething(); // Bad:大括号内部首尾,不需要空行 + ... + +} +``` + +# 3 注释 + +一般的,尽量通过清晰的架构逻辑,好的符号命名来提高代码可读性;需要的时候,才辅以注释说明。 +注释是为了帮助阅读者快速读懂代码,所以要从读者的角度出发,**按需注释**。 + +注释内容要简洁、明了、无二义性,信息全面且不冗余。 + +**注释跟代码一样重要。** +写注释时要换位思考,用注释去表达此时读者真正需要的信息。在代码的功能、意图层次上进行注释,即注释解释代码难以表达的意图,不要重复代码信息。 +修改代码时,也要保证其相关注释的一致性。只改代码,不改注释是一种不文明行为,破坏了代码与注释的一致性,让阅读者迷惑、费解,甚至误解。 + +使用**英文**进行注释。 + +必须要加注释说明场合如下(包含但不限于列举的场合): +1、模块对外提供的接口头文件必须对函数进行注释。 +2、定义全局变量必须加注释。 +3、核心算法必须加注释。 +4、超过50行的函数必须加注释。 + +## 注释风格 + +在 C 代码中,使用 `/*` `*/`和 `//` 都是可以的。 +按注释的目的和位置,注释可分为不同的类型,如文件头注释、函数头注释、代码注释等等; +同一类型的注释应该保持统一的风格。 + +注意:本文示例代码中,大量使用 '//' 后置注释只是为了更精确的描述问题,并不代表这种注释风格更好。 + +## 文件头注释 + +### 规则3.1 文件头注释必须包含版权许可 + +/* + * Copyright (c) 2020 XXX + * 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. + */ + +## 函数头注释 + +### 规则3.2 禁止空有格式的函数头注释 + +并不是所有的函数都需要函数头注释; +函数原型无法表达的信息,加函数头注释辅助说明; + +函数头注释统一放在函数声明或定义上方。 +选择使用如下风格之一: +**使用'//'写函数头** +```c +// 单行函数头 +int Func1(void); + +// 多行函数头 +// 第二行 +int Func2(void); +``` + +**使用'/\*' '\*/' 写函数头** +```c +/* 单行函数头 */ +int Func1(void); + +/* + * 单行或多行函数头 + * 第二行 + */ +int Func2(void); +``` + +函数尽量通过函数名自注释,**按需**写函数头注释。 +不要写无用、信息冗余的函数头;不要写空有格式的函数头。 + +函数头注释内容**可选**,但不限于:功能说明、返回值,性能约束、用法、内存约定、算法实现、可重入的要求等等。 +模块对外头文件中的函数接口声明,其函数头注释,应当将重要、有用的信息表达清楚。 + +例: +```c +/* + * 返回实际写入的字节数,-1表示写入失败 + * 注意,内存 buf 由调用者负责释放 + */ +int WriteString(char *buf, int len); +``` + +坏的例子: +```c +/* + * 函数名:WriteString + * 功能:写入字符串 + * 参数: + * 返回值: + */ +int WriteString(char *buf, int len); +``` +上面例子中的问题: +- 参数、返回值,空有格式没内容 +- 函数名信息冗余 +- 关键的 buf 由谁释放没有说清楚 + +## 代码注释 + +### 规则3.3 代码注释放于对应代码的上方或右边 +### 规则3.4 注释符与注释内容间要有1空格;右置注释与前面代码至少1空格 + +代码上方的注释,应该保持对应代码一样的缩进。 +选择并统一使用如下风格之一: +**使用'//'** +```c +// 这是单行注释 +DoSomething(); + +// 这是多行注释 +// 第二行 +DoSomething(); +``` +**使用'/\*' '\*/'** +```c +/* 这是单行注释 */ +DoSomething(); + +/* + * 这是单/多行注释 + * 第二行 + */ +DoSomething(); +``` + +代码右边的注释,与代码之间,至少留1空格,建议不超过4空格。 +通常使用扩展后的 TAB 键即可实现 1-4 空格的缩进。 + +选择并统一使用如下风格之一: +```c +int foo = 100; // 放右边的注释 +int bar = 200; /* 放右边的注释 */ +``` + +右置格式在适当的时候,上下对齐会更美观。 +对齐后的注释,离左边代码最近的那一行,保证1-4空格的间隔。 +例: +```c +#define A_CONST 100 /* 相关的同类注释,可以考虑上下对齐 */ +#define ANOTHER_CONST 200 /* 上下对齐时,与左侧代码保持间隔 */ +``` + +当右置的注释超过行宽时,请考虑将注释置于代码上方。 + +### 规则3.5 不用的代码段直接删除,不要注释掉 + +被注释掉的代码,无法被正常维护;当企图恢复使用这段代码时,极有可能引入易被忽略的缺陷。 +正确的做法是,不需要的代码直接删除掉。若再需要时,考虑移植或重写这段代码。 + +这里说的注释掉代码,包括用 /\* \*/ 和 //,还包括 #if 0, #ifdef NEVER_DEFINED 等等。 + +### 建议3.1 case语句块结束时如果不加break/return,需要有注释说明(fall-through) + +有时候需要对多个case标签做相同的事情,case语句在结束不加break或return,直接执行下一个case标签中的语句,这在C语法中称之为"fall-through"。 +这种情况下,需要在"fall-through"的地方加上注释,清晰明确的表达出这样做的意图;或者至少显式指明是 "fall-through"。 + +例,显式指明 fall-through: +```c +switch (var) { + case 0: + DoSomething(); + /* fall-through */ + case 1: + DoSomeOtherThing(); + ... + break; + default: + DoNothing(); + break; +} +``` + +如果 case 语句是空语句,则可以不用加注释特别说明: +```c +switch (var) { + case 0: + case 1: + DoSomething(); + break; + default: + DoNothing(); + break; +} +``` + +# 4 头文件 + +**对于C语言来说,头文件的设计体现了大部分的系统设计**。 +正确使用头文件可使代码在可读性、文件大小和编译构建性能上大为改观。 + +本章从编程规范的角度总结了一些方法,可用于帮助合理规划头文件。 + +## 头文件职责 + +头文件是模块或文件的对外接口。 +头文件中适合放置接口的声明,不允许放置实现(内联函数除外)。 +头文件应当职责单一。头文件过于复杂,依赖过于复杂还是导致编译时间过长的主要原因。 + +### 建议4.1 每一个.c文件都应该有相应的.h文件,用于声明需要对外公开的接口 + +通常情况下,每个.c文件都有一个相应的.h(并不一定同名),用于放置对外提供的函数声明、宏定义、类型定义等。 +如果一个.c文件不需要对外公布任何接口,则其就不应当存在。 + +例外:程序的入口(如main函数所在的文件),单元测试代码,动态库代码。 + +示例: +foo.h 内容 +```c +#ifndef FOO_H +#define FOO_H + +int Foo(void); // Good:头文件中声明对外接口 + +#endif +``` + +foo.c 内容 +```c +static void Bar(void); // Good: 对内函数的声明放在.c文件的头部,并声明为static限制其作用域 + +void Foo(void) +{ + Bar(); +} + +static void Bar(void) +{ + // Do something; +} +``` + +内部使用的函数声明,宏、枚举、结构体等定义不应放在头文件中。 + +有些产品中,习惯一个.c文件对应两个.h文件,一个用于存放对外公开的接口,一个用于存放内部需要用到的定义、声明等,以控制.c文件的代码行数。 +不提倡这种风格,产生这种风格的根源在于.c过大,应当首先考虑拆分.c文件。 +另外,一旦把私有定义、声明放到独立的头文件中,就无法从技术上避免别人包含。 + +本规则反过来并不一定成立。比如: +有些特别简单的头文件,如命令 ID 定义头文件,不需要有对应的.c存在。 +同一套接口协议下,有多个实例,由于接口相同且稳定,所以允许出现一个.h对应多个.c文件。 + +### 建议4.2 头文件的扩展名只使用.h,不使用非习惯用法的扩展名,如.inc + +有些产品中使用了 .inc 作为头文件扩展名,这不符合C语言的习惯用法。 +在使用 .inc 作为头文件扩展名的产品,习惯上用于标识此头文件为私有头文件。 +但是从产品的实际代码来看,这一条并没有被遵守,一个 .inc 文件被多个 .c 包含。 +本规范不提倡将私有定义单独放在头文件中,具体见[建议4.1](#a4-1)。 + +## 头文件依赖 + +头文件包含是一种依赖关系,头文件应向稳定的方向包含。 +一般来说,应当让不稳定的模块依赖稳定的模块,从而当不稳定的模块发生变化时,不会影响(编译)稳定的模块。 + +依赖的方向应该是:产品依赖于平台,平台依赖于标准库。 + +除了不稳定的模块依赖于稳定的模块外,更好的方式是每个模块都依赖于接口,这样任何一个模块的内部实现更改都不需要重新编译另外一个模块。 +在这里,假设接口本身是最稳定的。 + +### 规则4.1 禁止头文件循环依赖 + +头文件循环依赖,指 a.h 包含 b.h,b.h 包含 c.h,c.h 包含 a.h, 导致任何一个头文件修改,都导致所有包含了a.h/b.h/c.h的代码全部重新编译一遍。 +而如果是单向依赖,如a.h包含b.h,b.h包含c.h,而c.h不包含任何头文件,则修改a.h不会导致包含了b.h/c.h的源代码重新编译。 + +头文件循环依赖直接体现了架构设计上的不合理,可通过架构优化来避免。 + + +### 规则4.2 头文件必须编写#define保护,防止重复包含 + +为防止头文件被多重包含,所有头文件都应当使用 #define 作为包含保护;不要使用 #pragma once + +定义包含保护符时,应该遵守如下规则: +- 保护符使用唯一名称;统一使用子系统名_部件名_文件名的定义规则。 +- 不要在受保护部分的前后放置代码或者注释,文件头注释除外。 + +假定 util 子系统 timer 部件的 timer.h,其目录为 `timer/include/timer.h`。其保护符若使用 'TIME_H' 很容易不唯一,按规则定义如: +```c +#ifndef UTIL_TIMER_TIMER_H +#define UTIL_TIMER_TIMER_H + +... + +#endif // UTIL_TIMER_TIMER_H +``` + +### 规则4.3 禁止通过声明的方式引用外部函数接口、变量 + +只能通过包含头文件的方式使用其他模块或文件提供的接口。 +通过 extern 声明的方式使用外部函数接口、变量,容易在外部接口改变时可能导致声明和定义不一致。 +同时这种隐式依赖,容易导致架构腐化。 + +不符合规范的案例: +a.c 内容 +```c +extern int Foo(void); // Bad: 通过 extern 的方式引用外部函数 + +void Bar(void) +{ + int i = Foo(); // 这里使用了外部接口 Foo + ... +} +``` + +应该改为: +a.c 内容 +```c +#include "b.h" // Good: 通过包含头文件的方式使用其他.c提供的接口 + +void Bar(void) +{ + int i = Foo(); + ... +} +``` + +b.h 内容 +```c +int Foo(void); +``` + +b.c内容 +```c +int Foo(void) +{ + // Do something +} +``` + +例外,有些场景需要引用其内部函数,但并不想侵入代码时,可以 extern 声明方式引用。 +如: +针对某一内部函数进行单元测试时,可以通过 extern 声明来引用被测函数; +当需要对某一函数进行打桩、打补丁处理时,允许 extern 声明该函数。 + +### 规则4.4 禁止在 extern "C" 中包含头文件 + +在 extern "C" 中包含头文件,有可能会导致 extern "C" 嵌套,部分编译器对 extern "C" 嵌套层次有限制,嵌套层次太多会编译错误。 + +extern "C" 通常出现在 C,C++ 混合编程的情况下,在 extern "C" 中包含头文件,可能会导致被包含头文件的原有意图遭到破坏,比如链接规范被不正确地更改。 + +示例,存在a.h和b.h两个头文件: +a.h 内容 +```c +... +#ifdef __cplusplus +void Foo(int); +#define A(value) Foo(value) +#else +void A(int) +#endif +``` + +b.h 内容 +```c +... +#ifdef __cplusplus +extern "C" { +#endif + +#include "a.h" +void B(void); + +#ifdef __cplusplus +} +#endif +``` + +使用C++预处理器展开b.h,将会得到 +```c +extern "C" { + void Foo(int); + void B(void); +} +``` + +按照 a.h 作者的本意,函数 Foo 是一个 C++ 自由函数,其链接规范为 "C++"。 +但在 b.h 中,由于 `#include "a.h"` 被放到了 `extern "C"` 的内部,函数 Foo 的链接规范被不正确地更改了。 + +例外: +如果在 C++ 编译环境中,想引用纯C的头文件,这些C头文件并没有 `extern "C"` 修饰。非侵入式的做法是,在 `extern "C"` 中去包含C头文件。 + +# 5 函数 + +函数的作用:避免重复代码、增加可重用性;分层,降低复杂度、隐藏实现细节,使程序更加模块化,从而更有利于程序的阅读,维护。 + +函数应该简洁、短小。 +一个函数只完成一件事情。 + +## 函数设计 + +函数设计的精髓:编写整洁函数,同时把代码有效组织起来。代码简单直接、不隐藏设计者的意图、用干净利落的抽象和直截了当的控制语句将函数有机组织起来。 + +### 规则5.1 避免函数过长,函数不超过50行(非空非注释) + +函数应该可以一屏显示完 (50行以内),只做一件事情,而且把它做好。 + +过长的函数往往意味着函数功能不单一,过于复杂,或过分呈现细节,未进行进一步抽象。 + +例外: +考虑代码的聚合性与功能的全面性,某些函数可能会超过50行,但前提是不影响代码的可读性与简洁。 +这些例外的函数应该是极少的,例如特定算法处理。 + +即使一个长函数现在工作的非常好, 一旦有人对其修改, 有可能出现新的问题, 甚至导致难以发现的bug。 +建议将其拆分为更加简短并易于管理的若干函数,以便于他人阅读和修改代码。 + +### 规则5.2 避免函数的代码块嵌套过深,不要超过4层 + +函数的代码块嵌套深度指的是函数中的代码控制块(例如:if、for、while、switch等)之间互相包含的深度。 +每级嵌套都会增加阅读代码时的脑力消耗,因为需要在脑子里维护一个“栈”(比如,进入条件语句、进入循环等等)。 +应该做进一步的功能分解,从而避免使代码的阅读者一次记住太多的上下文。 + +使用`卫语句`可以有效的减少 if 相关的嵌套层次。例: +原代码嵌套层数是 3: +```c +int Foo(...) +{ + if (received) { + type = GetMsgType(msg); + if (type != UNKNOWN) { + return DealMsg(...); + } + } + return -1; +} +``` + +使用`卫语句`重构,嵌套层数变成 2: +```c +int Foo(...) +{ + if (!received) { // Good: 使用'卫语句' + return -1; + } + + type = GetMsgType(msg); + if (type == UNKNOWN) { + return -1; + } + + return DealMsg(..); +} +``` +例外: +考虑代码的聚合性与功能的全面性,某些函数嵌套可能会超过4层,但前提是不影响代码的可读性与简洁。 +这些例外的函数应该是极少的。 + +### 建议5.1 对函数的错误返回码要全面处理 + +一个函数(标准库中的函数/第三方库函数/用户定义的函数)能够提供一些指示错误发生的方法。 +这可以通过使用错误标记、特殊的返回数据或者其他手段,不管什么时候函数提供了这样的机制,调用程序应该在函数返回时立刻检查错误指示。 + +示例: +```c +char fileHead[128]; +ReadFileHead(fileName, fileHead, sizeof(fileHead)); // Bad: 未检查返回值 + +DealWithFileHead(fileHead, sizeof(fileHead)); // fileHead 可能无效 +``` + +正确写法: +```c +char fileHead[128]; +ret = ReadFileHead(fileName, fileHead, sizeof(fileHead)); +if (ret != OK) { // Good: 确保 fileHead 被有效写入 + return ERROR; +} + +DealWithFileHead(fileHead, sizeof(fileHead)); // 处理文件头 +``` + + +注意,当函数返回值被大量的显式(void)忽略掉时,应当考虑函数返回值的设计是否合理。 +如果所有调用者都不关注函数返回值时,请将函数设计成`void`型。 + +## 函数参数 + +### 建议5.2 设计函数时,优先使用返回值而不是输出参数 + +使用返回值而不是输出参数,可以提高可读性,并且通常提供相同或更好的性能。 + +函数名为 GetXxx、FindXxx、IsXxx、OnXxx或直接名词作函数名的函数,直接返回对应对象,可读性更好。 +例外: +1、多值返回时,可以设计为输出参数返回。 +2、涉及内存分配时,可以设计为输出参数返回。调用者将申请的内存做为出参传入,而函数内由不再分配内存。 + +### 建议5.3 设计函数的参数时,统一按输入、输出、出入的顺序定义参数。 + +函数参数的定义统一按输入参数、输出参数、出入参的顺序进行定义。 + +### 规则5.3 设计函数的资源时,涉及内存、锁、队列等资源分配的,需要同时提供释放函数。 + +本着资源从那儿申请,向那儿释放的原则。如果函数申请了内存、锁、队列等资源,则模块需要同时提供资源的函数。 + +### 建议5.4 使用强类型参数,避免使用void\* + +尽管不同的语言对待强类型和弱类型有自己的观点,但是一般认为c/c++是强类型语言,既然我们使用的语言是强类型的,就应该保持这样的风格。 +好处是尽量让编译器在编译阶段就检查出类型不匹配的问题。 + +使用强类型便于编译器帮我们发现错误,如下代码中注意函数 `FooListAddNode` 的使用: +```c +struct FooNode { + struct List link; + int foo; +}; + +struct BarNode { + struct List link; + int bar; +} + +void FooListAddNode(void *node) // Bad: 这里用 void * 类型传递参数 +{ + FooNode *foo = (FooNode *)node; + ListAppend(&g_fooList, &foo->link); +} + +void MakeTheList(...) +{ + FooNode *foo; + BarNode *bar; + ... + + FooListAddNode(bar); // Wrong: 这里本意是想传递参数 foo,但错传了 bar,却没有报错 +} + +``` + +上述问题有可能很隐晦,不易轻易暴露,从而破坏性更大。 +如果明确 `FooListAddNode` 的参数类型,而不是 `void *`,则在编译阶段就能发现上述问题。 +```c +void FooListAddNode(FooNode *foo) +{ + ListAppend(&g_fooList, &foo->link); +} +``` + +例外:某些通用泛型接口,需要传入不同类型指针的,可以用 `void *` 入参。 + +### 建议5.5 模块内部函数参数的合法性检查,由调用者负责 + +对于模块外部传入的参数,必须进行合法性检查,保护程序免遭非法输入数据的破坏。 +模块内部函数调用,缺省由调用者负责保证参数的合法性,如果都由被调用者来检查参数合法性,可能会出现同一个参数,被检查多次,产生冗余代码,很不简洁。 + +由调用者保证入参的合法性,这种契约式编程能让代码逻辑更简洁,可读性更好。 +示例: +```c +int SomeProc(...) +{ + int data; + + bool dataOK = GetData(&data); // 获取数据 + if (!dataOK) { // 检查上一步结果,其实也就保证了数据合法 + return -1; + } + + DealWithData(data); // 调用数据处理函数 + ... +} + +void DealWithData(int data) +{ + if (data < MIN || data > MAX) { // Bad: 调用者已经保证了数据合法性 + return; + } + + ... +} +``` + +### 建议5.5 函数的指针参数如果不是用于修改所指向的对象就应该声明为指向const的指针 + +const 指针参数,将限制函数通过该指针修改所指向对象,使代码更牢固、安全。 + +示例:C99标准 7.21.4.4 中strncmp 的例子,不变参数声明为const。 +```c +int strncmp(const char *s1, const char *s2, size_t n); // Good:不变参数声明为const +``` + +注意: +指针参数要不要加 const 取决于函数设计,而不是看函数实体内有没有发生“修改对象”的动作。 + +### 建议5.6 函数的参数个数不超过5个 + +函数的参数过多,会使得该函数易于受外部(其他部分的代码)变化的影响,从而影响维护工作。函数的参数过多同时也会增大测试的工作量。 + +函数的参数个数不要超过5个,如果超过可以考虑: +- 看能否拆分函数 +- 看能否将相关参数合在一起,定义结构体 + +## 内联函数 + +内联函数是**C99**引入的一种函数优化手段。函数内联能消除函数调用的开销;并得益于内联实现跟调用点代码的合并,编译器有更大的视角,从而完成更多的代码优化。内联函数跟函数式宏比较类似,两者的分析详见[建议6.1](#a6-1)。 + +### 建议5.7 内联函数不超过10行(非空非注释) + +将函数定义成内联一般希望提升性能,但是实际并不一定能提升性能。 +如果函数体短小,则函数内联可以有效的缩减目标代码的大小,并提升函数执行效率。 +反之,函数体比较大,内联展开会导致目标代码的膨胀,特别是当调用点很多时,膨胀得更厉害,反而会降低执行效率。 +内联函数规模建议控制在 **10** 行以内。 + +不要为了提高性能而滥用内联函数。不要过早优化。一般情况,当有实际测试数据证明内联性能更高时,再将函数定义为内联。 +对于类似 setter/getter 短小而且调用频繁的函数,可以定义为内联。 + +### 规则5.3 被多个源文件调用的内联函数要放在头文件中定义 + +内联函数是在编译时内联展开,因此要求内联函数定义必须在调用此函数的每个源文件内可见。 +如下所示代码,inline.h 只有`SomeInlineFunc`函数的声明而没有定义。other.c包含inline.h,调用`SomeInlineFunc`时无法内联。 + +inline.h +```c +inline int SomeInlineFunc(void); +``` + +inline.c +```c +inline int SomeInlineFunc(void) +{ + // 实现代码 +} +``` + +other.c +```c +#include "inline.h" +int OtherFunc(void) +{ + int ret = SomeInlineFunc(); +} +``` + +由于这个限制,多个源文件如果要调用同一个内联函数,需要将内联函数的定义放在头文件中。 +**gnu89** 在内联函数实现上跟**C99**标准有差异,兼容做法是将函数声明为 **static inline**。 + +# 6 宏 + +## 函数式宏(function-like macro) + +函数式宏是指形如函数的宏(示例代码如下所示),其包含若干条语句来实现某一特定功能。 +```c +#define ASSERT(x) do { \ + if (!(x)) { \ + printk(KERN_EMERG "assertion failed %s: %d: %s\n", \ + __FILE__, __LINE__, #x); \ + BUG(); \ + } \ +} while (0) +``` + +### 建议6.1 使用函数代替函数式宏 + +定义函数式宏前,应考虑能否用函数替代。对于可替代场景,建议用函数替代宏。 +函数式宏的缺点如下: + +- 函数式宏缺乏类型检查,不如函数调用检查严格。示例代码[见下](#macro_lack_of_type_check__example)。 +- 宏展开时宏参数不求值,可能会产生非预期结果,详见[规则6.1](#r6-1)和[规则6.3](#r6-3)。 +- 宏没有独立的作用域,跟控制流语句配合时,可能会产生如[规则6.2](#r6-2)描述的非预期结果。 +- 宏的技巧性太强(参见下面的规则),例如`#`的用法和无处不在的括号,影响可读性。 +- 在特定场景下必须用特定编译器对宏的扩展,如 `gcc` 的 `statement expression`,可移植性也不好。 +- 宏在预编译阶段展开后,在其后编译、链接和调试时都不可见;而且包含多行的宏会展开为一行。函数式宏难以调试、难以打断点,不利于定位问题。 +- 对于包含大量语句的宏,在每个调用点都要展开。如果调用点很多,会造成代码空间的膨胀。 + +函数式宏缺乏类型检查的示例代码: + +```c +#define MAX(a, b) (((a) < (b)) ? (b) : (a)) + +int Max(int a, int b) +{ + return (a < b) ? b : a; +} + +int TestMacro(void) +{ + unsigned int a = 1; + int b = -1; + + (void)printf("MACRO: max of a(%u) and b(%d) is %d\n", a, b, MAX(a, b)); + (void)printf("FUNC : max of a(%u) and b(%d) is %d\n", a, b, Max(a, b)); + return 0; +} +``` + +由于宏缺乏类型检查,`MAX`中的`a`和`b`的比较提升为无符号数的比较,结果是**a < b**。输出结果是: + +``` +MACRO: max of a(1) and b(-1) is -1 +FUNC : max of a(1) and b(-1) is 1 +``` + +函数没有宏的上述缺点。但是,函数相比宏,最大的劣势是执行效率不高(增加函数调用的开销和编译器优化的难度)。 +为此,C99标准引入了内联函数(gcc在标准之前就引入了内联函数)。 + +内联函数跟宏类似,也是在调用点展开。不同之处在于内联函数是在编译时展开。 +内联函数兼具函数和宏的优点: + +- 内联函数/函数执行严格的类型检查 +- 内联函数/函数的入参求值只会进行一次 +- 内联函数就地展开,没有函数调用的开销 +- 内联函数比函数优化得更好 + +对于性能敏感的代码,可以考虑用内联函数代替函数式宏。 +函数和内联函数不能完全替代函数式宏,函数式宏在某些场景更适合。 +比如,在日志记录场景下,使用带可变参和默认参数的函数式宏更方便: + +```c +int ErrLog(const char *file, unsigned long line, const char *fmt, ...); +#define ERR_LOG(fmt, ...) ErrLog(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +``` + + +### 规则6.1 定义宏时,宏参数要使用完备的括号 + +宏参数在宏展开时只是文本替换,在编译时再求值。文本替换后,宏包含的语句跟调用点代码合并。 +合并后的表达式因为操作符的优先级和结合律,可能会导致计算结果跟期望的不同,尤其是当宏参数在一个表达式中时。 + +如下所示,是一种错误的写法: +```c +#define SUM(a, b) a + b // Bad. +``` + +下面这样调用宏,执行结果跟预期不符: +`100 / SUM(2, 8)` 将扩展成 `(100 / 2) + 8`,预期结果则是`100 / (2 + 8)`。 +这个问题可以通过将整个表示式加上括号来解决,如下所示: +```c +#define SUM(a, b) (a + b) // Bad. +``` + +但是这种改法在下面这种场景又有问题: +`SUM(1 << 2, 8)`扩展成`1 << (2 + 8)`(因为`<<`优先级低于`+`),跟预期结果`(1 << 2) + 8`不符。 + +这个问题可以通过将每个宏参数都加上括号来解决,如下所示: +```c +#define SUM(a, b) (a) + (b) // Bad. +``` + +再看看第三种问题场景:`SUM(2, 8) * 10` 。扩展后的结果为 `(2) + ((8) * 10)`,跟预期结果`(2 + 8) * 10`不符。 + +综上所述,正确的写法如下: +```c +#define SUM(a, b) ((a) + (b)) // Good. +``` + +但是要避免滥用括号。如下所示,单独的数字或标识符加括号毫无意义。 +```c +#define SOME_CONST 100 // Good: 单独的数字无需括号 +#define ANOTHER_CONST (-1) // Good: 负数需要使用括号 + +#define THE_CONST SOME_CONST // Good: 单独的标识符无需括号 +``` + +下列情况需要注意: +- 宏参数参与 '#', '##' 操作时,不要加括号 +- 宏参数参与字符串拼接时,不要加括号 +- 宏参数作为独立部分,在赋值(包括+=, -=等)操作的某一边时,无需括号 +- 宏参数作为独立部分,在逗号表达式,函数或宏调用列表中,无需括号 + +举例: +```c +#define MAKE_STR(x) #x // x 不要加括号 + +#define HELLO_STR(obj) "Hello, " obj // obj 不要加括号 + +#define ADD_3(sum, a, b, c) (sum = (a) + (b) + (c)) // a, b, c 需要括号;而 sum 无需括号 + +#define FOO(a, b) Bar((a) + 1, b) // a 需要括号;而 b 无需括号 +``` + + +### 规则6.2 包含多条语句的函数式宏的实现语句必须放在 do-while(0) 中 + +宏本身没有代码块的概念。当宏在调用点展开后,宏内定义的表达式和变量融合到调用代码中,可能会出现变量名冲突和宏内语句被分割等问题。 +通过 do-while(0) 显式为宏加上边界,让宏有独立的作用域,并且跟分号能更好的结合而形成单条语句,从而规避此类问题。 + +如下所示的宏是错误的用法(为了说明问题,下面示例代码稍不符规范): + +```c +// Not Good. +#define FOO(x) \ + (void)printf("arg is %d\n", (x)); \ + DoSomething((x)); +``` + +当像下面示例代码这样调用宏,for循环只执行了宏的第一条语句,宏的后一条语句只在循环结束后执行一次。 + +```c +for (i = 1; i < 10; i++) + FOO(i); +``` + +用大括号将`FOO`定义的语句括起来可以解决上面的问题: + +```c +#define FOO(x) { \ + (void)printf("arg is %d\n", (x)); \ + DoSomething((x)); \ +} +``` + +由于大括号跟分号没有关联。大括号后紧跟的分号,是另外一个语句。 +如下示例代码,会出现'悬挂else' 编译报错: + +```c +if (condition) + FOO(10); +else + FOO(20); +``` + +正确的写法是用 do-while(0) 把执行体括起来,如下所示: + +```c +// Good. +#define FOO(x) do { \ + (void)printf("arg is %d\n", (x)); \ + DoSomething((x)); \ +} while (0) +``` + +例外: +- 包含 break, continue 语句的宏可以例外。使用此类宏务必特别小心。 +- 宏中包含不完整语句时,可以例外。比如用宏封装 for 循环的条件部分。 +- 非多条语句,或单个 if/for/while/switch 语句,可以例外。 + +### 规则6.3 不允许把带副作用的表达式作为参数传递给函数式宏 + +由于宏只是文本替换,对于内部多次使用同一个宏参数的函数式宏,将带副作用的表达式作为宏参数传入会导致非预期的结果。 +如下所示,宏`SQUARE`本身没有问题,但是使用时将带副作用的`a++`传入导致`a`的值在`SQUARE`执行后跟预期不符: + +```c +#define SQUARE(a) ((a) * (a)) + +int a = 5; +int b; +b = SQUARE(a++); // Bad: 实际 a 自增加了 2 次 +``` + +`SQUARE(a++)`展开后为`((a++) * (a++))`,变量`a`自增了两次,其值为`7`,而不是预期的`6`。 + +正确的写法如下所示: + +```c +b = SQUARE(a); +a++; // 结果:a = 6,只自增了一次。 +``` + +此外,如果参数包含函数调用,宏展开后,函数可能会被重复调用。 +如果函数执行结果相同,则存在浪费;如果函数多次调用结果不一样,执行结果可能不符合预期。 + + +### 建议6.2 函数式宏定义中慎用 return、goto、continue、break 等改变程序流程的语句 + +宏中使用 return、goto、continue、break 等改变流程的语句,虽然能简化代码,但同时也隐藏了真实流程,不易于理解,容易导致资源泄漏等问题。 + +首先,宏封装 return 容易导致过度封装和使用。 +如下代码,`status`的判断是主干流程的一部分,用宏封装起来后,变得不直观了,阅读时习惯性把`RETURN_IF`宏忽略掉了,从而导致对主干流程的理解有偏差。 + +```c +#define LOG_AND_RETURN_IF_FAIL(ret, fmt, ...) do { \ + if ((ret) != OK) { \ + (void)ErrLog(fmt, ##__VA_ARGS__); \ + return (ret); \ + } \ +} while (0) + +#define RETURN_IF(cond, ret) do { \ + if (cond) { \ + return (ret); \ + } \ +} while (0) + +ret = InitModuleA(a, b, &status); +LOG_AND_RETURN_IF_FAIL(ret, "Init module A failed!"); // OK. + +RETURN_IF(status != READY, ERR_NOT_READY); // Bad: 重要逻辑不明显 + +ret = InitModuleB(c); +LOG_AND_RETURN_IF_FAIL(ret, "Init module B failed!"); // OK. +``` + +其次,宏封装 return 也容易引发内存泄漏。再看一个例子: +```c +#define CHECK_PTR(ptr, ret) do { \ + if ((ptr) == NULL) { \ + return (ret); \ + } \ +} while (0) + +... + +mem1 = MemAlloc(...); +CHECK_PTR(mem1, ERR_CODE_XXX); + +mem2 = MemAlloc(...); +CHECK_PTR(mem2, ERR_CODE_XXX); // Wrong: 内存泄漏 +``` + +如果 `mem2` 申请内存失败了,`CHECK_PTR` 会直接返回,而没有释放 `mem1`。 +除此之外,`CHECK_PTR` 宏命名也不好,宏名只反映了检查动作,没有指明结果。只有看了宏实现才知道指针为空时返回失败。 + +综上所述: +不推荐宏定义中封装 return、goto、continue、break 等改变程序流程的语句; +对于返回值判断等异常处理场景可以例外。 + +注意: +**包含 return、goto、continue、break 等改变流程语句的宏命名,务必要体现对应关键字。** + + +### 建议6.3 函数式宏不超过10行(非空非注释) + +函数式宏本身的一大问题是比函数更难以调试和定位,特别是宏过长,调试和定位的难度更大。 +而且宏扩展会导致目标代码的膨胀。建议函数式宏不要超过10行。 + +# 7 变量 + +在C语言编码中,除了函数,最重要的就是变量。 +变量在使用时,应始终遵循“职责单一”原则。 +按作用域区分,变量可分为全局变量和局部变量。 + +## 全局变量 + +尽量不用或少用全局变量。 +在程序设计中,全局变量是在所有作用域都可访问的变量。通常,使用不必要的全局变量被认为是坏习惯。 + +使用全局变量的缺点: +- 破坏函数的独立性和可移植性,使函数对全局变量产生依赖,存在耦合; +- 降低函数的代码可读性和可维护性。当多个函数读写全局变量时,某一时刻其取值可能不是确定的,对于代码的阅读和维护不利; +- 在并发编程环境中,使用全局变量会破坏函数的可重入性,需要增加额外的同步保护处理才能确保数据安全。 + +如不可避免,对全局变量的读写应集中封装。 + +### 规则7.1 模块间,禁止使用全局变量作接口 + +全局变量是模块内部的具体实现,不推荐但允许跨文件使用,但禁止作为模块接口暴露出去。 +对全局变量的使用应该尽量集中,如果本模块的数据需要对外部模块开放,应提供对应函数接口。 + +## 局部变量 + +### 规则7.2 严禁使用未经初始化的变量 + +这里的变量,指的是局部动态变量,并且还包括内存堆上申请的内存块。 +因为他们的初始值都是不可预料的,所以禁止未经有效初始化就直接读取其值。 + +```c +void Foo(...) +{ + int data; + Bar(data); // Bad: 未初始化就使用 + ... +} +``` + +如果有不同分支,要确保所有分支都得到初始化后才能使用: +```c +void Foo(...) +{ + int data; + if (...) { + data = 100; + } + Bar(data); // Bad: 部分分支该值未初始化 + ... +} +``` + +未经初始化就使用,一般静态检查工具是可以检查出来的。 +如 PCLint 工具,针对上述两个例子分别会报错: +>Warning 530: Symbol 'data' (line ...) not initialized +>Warning 644: Variable 'data' (line ...) may not have been initialized + +### 规则7.3 禁止无效、冗余的变量初始化 + +如果没有确定的初始值,而仍然进行初始化,不仅不简洁,反而不安全,可能会引入更难发现的问题。 + +常见的冗余初始化: +```c +int cnt = 0; // Bad: 冗余初始化,将会被后面直接覆盖 +... +cnt = GetXxxCnt(); +... +``` + +对于后续有条件赋值的变量,可以在定义时初始化成默认值 +```c +char *buf = NULL; // Good: 这里用 NULL 代表默认值 +if (condition) { + buf = malloc(MEM_SIZE); +} +... +if (buf != NULL) { // 判断是否申请过内存 + free(buf); +} +``` + +针对大数组的冗余清零,更是会影响到性能。 +```c +char buf[VERY_BIG_SIZE] = {0}; +memset(buf, 0, sizeof(buf)); // Bad: 冗余清零 +``` + +无效初始化,隐藏更大问题的反例: +```c +void Foo(...) +{ + int data = 0; // Bad: 习惯性的进行初始化 + + UseData(data); // 使用数据,本应该写在获取数据后面 + data = GetData(...); // 获取数据 + ... +} +``` +上例代码,如果没有赋 0 初始化,静态检查工具可以帮助发现“未经初始化就直接使用”的问题。 +但因为无效初始化,“使用数据”与“获取数据”写颠倒的缺陷,不能被轻易发现。 + +因此,应该写简洁的代码,对变量或内存块进行正确、必要的初始化。 + +C99不再限制局部变量定义必须在语句之前,可以按需定义,即在靠近变量使用的地方定义变量。 +这种简洁的做法,不仅将变量作用域限制更小,而且更方便阅读和维护,还能解决定义变量时不知该怎么初始化的问题。 +如果编译环境支持,建议按需定义。 + +**例外:** +**遵从“安全规范”要求,指针变量、表示资源描述符的变量、BOOL变量不作要求。** + +### 规则7.4 不允许使用魔鬼数字 + +所谓魔鬼数字即看不懂、难以理解的数字。 +魔鬼数字并非一个非黑即白的概念,看不懂也有程度,需要结合代码上下文和业务相关知识来判断 + +例如数字 12,在不同的上下文中情况是不一样的: +`type = 12;` 就看不懂,但 `month = year * 12;` 就能看懂。 +数字 0 有时候也是魔鬼数字,比如 `status = 0;` 并不能表达是什么状态。 + +解决途径: +对于单点使用的数字,可以增加注释说明 +对于多处使用的数字,必须定义宏或const 变量,并通过符号命名自注释。 + +禁止出现下列情况: +没有通过符号来解释数字含义,如 `#define ZERO 0` +符号命名限制了其取值,如 `#define XX_TIMER_INTERVAL_300MS 300` + +# 8 编程实践 + +## 表达式 + +### 建议8.1 表达式的比较,应当遵循左侧倾向于变化、右侧倾向于不变的原则 + +当变量与常量比较时,如果常量放左边,如 `if (MAX == v)` 不符合阅读习惯,而 `if (MAX > v)` 更是难于理解。 +应当按人的正常阅读、表达习惯,将常量放右边。写成如下方式: +```c +if (v == MAX) ... +if (v < MAX) ... +``` + +也有特殊情况,如:`if (MIN < v && v < MAX)` 用来描述区间时,前半段是常量在左的。 + +不用担心将 '==' 误写成 '=',因为 `if (v = MAX)` 会有编译告警,其他静态检查工具也会报错。让工具去解决笔误问题,代码要符合可读性第一。 + +### 规则8.1 含有变量自增或自减运算的表达式中禁止再次引用该变量 + +含有变量自增或自减运算的表达式中,如果再引用该变量,其结果在C标准中未明确定义。各个编译器或者同一个编译器不同版本实现可能会不一致。 +为了更好的可移植性,不应该对标准未定义的运算次序做任何假设。 + +注意,运算次序的问题不能使用括号来解决,因为这不是优先级的问题。 + +示例: +```c +x = b[i] + i++; // Bad: b[i]运算跟 i++,先后顺序并不明确。 +``` +正确的写法是将自增或自减运算单独放一行: +```c +x = b[i] + i; +i++; // Good: 单独一行 +``` + +函数参数: +```c +Func(i++, i); // Bad: 传递第2个参数时,不确定自增运算有没有发生 +``` +正确的写法: +```c +i++; // Good: 单独一行 +x = Func(i, i); +``` + + +### 建议8.2 用括号明确表达式的操作顺序,避免过分依赖默认优先级 + +可以使用括号强调表达式操作顺序,防止因默认的优先级与设计思想不符而导致程序出错。 +然而过多的括号会分散代码使其降低了可读性,应适度使用。 + +当表达式包含不常用,优先级易混淆的操作符时,推荐使用括号,比如位操作符: +```c +c = (a & 0xFF) + b; /* 涉及位操作符,需要括号 */ +``` + +## 语句 + +### 规则8.2 switch语句要有default分支 + +大部分情况下,switch语句中要有default分支,保证在遗漏case标签处理时能够有一个缺省的处理行为。 + +特例: +如果switch条件变量是枚举类型,并且 case 分支覆盖了所有取值,则加上default分支处理有些多余。 +现代编译器都具备检查是否在switch语句中遗漏了某些枚举值的case分支的能力,会有相应的warning提示。 +```c +enum Color { + RED, + BLUE +}; + +// 因为switch条件变量是枚举值,这里可以不用加default处理分支 +switch (color) { + case RED: + DoRedThing(); + break; + case BLUE: + DoBlueThing(); + ... + break; +} +``` + +### 建议8.3 慎用 goto 语句 + +goto语句会破坏程序的结构性,所以除非确实需要,最好不使用goto语句。使用时,也只允许跳转到本函数goto语句之后的语句。 + +goto语句通常用来实现函数单点返回。 +同一个函数体内部存在大量相同的逻辑但又不方便封装成函数的情况下,譬如反复执行文件操作, +对文件操作失败以后的处理部分代码(譬如关闭文件句柄,释放动态申请的内存等等), +一般会放在该函数体的最后部分,在需要的地方就goto到那里,这样代码反而变得清晰简洁。 +实际也可以封装成函数或者封装成宏,但是这么做会让代码变得没那么直接明了。 + +示例: +```c +// Good: 使用 goto 实现单点返回 +int SomeInitFunc(void) +{ + void *p1; + void *p2 = NULL; + void *p3 = NULL; + + p1 = malloc(MEM_LEN); + if (p1 == NULL) { + goto EXIT; + } + + p2 = malloc(MEM_LEN); + if (p2 == NULL) { + goto EXIT; + } + + p3 = malloc(MEM_LEN); + if (p3 == NULL) { + goto EXIT; + } + + DoSomething(p1, p2, p3); + return 0; // OK. + +EXIT: + if (p3 != NULL) { + free(p3); + } + if (p2 != NULL) { + free(p2); + } + if (p1 != NULL) { + free(p1); + } + return -1; // Failed! +} +``` + +## 类型转换 + +### 建议8.4 尽量减少没有必要的数据类型默认转换与强制转换 + +当进行数据类型强制转换时,其数据的意义、转换后的取值等都有可能发生变化,而这些细节若考虑不周,就很有可能留下隐患。 + +如下赋值,多数编译器不产生告警,但值的含义还是稍有变化。 +```c +char ch; +unsigned short int exam; + +ch = -1; +exam = ch; // Bad: 编译器不产生告警,此时exam为0xFFFF。 +``` diff --git a/website/docs/_posts/contribute/OpenHarmony-c-cpp-secure-coding-guide.md b/website/docs/_posts/contribute/OpenHarmony-c-cpp-secure-coding-guide.md new file mode 100644 index 0000000000000000000000000000000000000000..7aa64d5e9b989797e0b1c8100fafd853b45a3774 --- /dev/null +++ b/website/docs/_posts/contribute/OpenHarmony-c-cpp-secure-coding-guide.md @@ -0,0 +1,3173 @@ +--- +title: OpenHarmony-c-cpp-secure-coding-guide.md +permalink: /pages/extra/191e89/ +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +date: 2021-12-30 18:17:45 +--- +# OpenHarmony C&C++ 安全编程指南 + +本文档基于C&C++ 语言提供一些安全编程建议,用于指导开发实践。 + +# 函数 + +## 对所有外部数据进行合法性校验 + +**【描述】** +外部数据的来源包括但不限于:网络、用户输入、命令行、文件(包括程序的配置文件)、环境变量、用户态数据(对于内核程序)、进程间通信(包括管道、消息、共享内存、socket、RPC等,特别需要注意的是设备内部不同单板间通讯也属于进程间通信)、API参数、全局变量。 + +来自程序外部的数据通常被认为是不可信的,在使用这些数据之前,需要进行合法性校验。 +如果不对这些外部数据进行校验,将可能导致不可预期的安全风险。 + +注意:不要使用断言检查外部输入数据,断言应该用于防止不正确的程序假设,而不能用在发布版本上检查程序运行过程中发生的错误。 + +对来自程序外部的数据要校验处理后才能使用。典型场景包括: + +**作为数组索引** +将不可信的数据作为数组索引,可能导致超出数组上限,从而造成非法内存访问。 +**作为内存偏移地址** +将不可信数据作为指针偏移访问内存,可能造成非法内存访问,并可以造成进一步的危害,如任意地址读/写。 +**作为内存分配的尺寸参数** +使用0长度分配内存可能造成非法内存访问;未限制分配内存大小会造成过度资源消耗。 +**作为循环条件** +将不可信数据作为循环限定条件,可能会引发缓冲区溢出、内存越界读/写、死循环等问题。 +**作为除数** +可能产生除零错误(被零除)。 +**作为命令行参数** +可能产生命令注入漏洞。 +**作为数据库查询语句的参数** +可能产生SQL注入漏洞。 +**作为输入/输出格式化字符串** +可能产生格式化字符串漏洞。 +**作为内存复制长度** +可能造成缓冲区溢出问题。 +**作为文件路径** +直接打开不可信路径,可能会导致目录遍历攻击,攻击者操作了无权操作的文件,使得系统被攻击者所控制。 + +输入校验包括但不局限于: + +- API接口参数合法性 +- 校验数据长度 +- 校验数据范围 +- 校验数据类型和格式 +- 校验输入只包含可接受的字符(“白名单”形式),尤其需要注意一些特殊情况下的特殊字符。 + +**外部数据校验原则** +**1.信任边界** +由于外部数据不可信,因此系统在运行过程中,如果数据传输与处理跨越不同的信任边界,为了防止攻击蔓延,必须对来自信任边界外的其他模块的数据进行合法性校验。 +(a)so(或者dll)之间 +so或dll作为独立的第三方模块,用于对外导出公共的api函数,供其他模块进行函数调用。so/dll无法确定上层调用者是否传递了合法参数,因此so/dll的公共函数需要检查调用者提供参数的合法性。so/dll应该设计成低耦合、高复用性,尽管有些软件的so/dll当前设计成只在本软件中使用,但仍然应该将不同的so/dll模块视为不同的信任边界。 +(b)进程与进程之间 +为防止通过高权限进程提权,进程与进程之间的IPC通信(包括单板之间的IPC通信、不同主机间的网络通信),应视为不同信任边界。 +(c)应用层进程与操作系统内核 +操作系统内核具有比应用层更高的权限,内核向应用层提供的接口,应该将来自应用层的数据作为不可信数据处理。 +(d)可信执行环境内外环境 +为防止攻击蔓延至可信执行环境,TEE、SGX等对外提供的接口,应该将来自外部的数据作为不可信数据处理。 + +**2.外部数据校验** +外部数据进入到本模块后,必须经过合法性校验才能使用。被校验后的合法数据,在本模块内,后续传递到内部其他子函数,不需要重复校验。 + +**【反例】** +函数Foo处理外部数据,由于buffer不一定是’\0’结尾, strlen 的返回值 nameLen 有可能超过 len,导致越界读取数据。 + +```cpp +void Foo(const unsigned char* buffer, size_t len) +{ + // buffer可能为空指针,不保证以'\0'结尾 + const char* s = reinterpret_cast(buffer); + size_t nameLen = strlen(s); + std::string name(s, nameLen); + Foo2(name); + ... +} +``` + +**【正例】** +对外部参数做合法性校验,本例中使用 strnlen 进行字符串长度计算,缓解读越界风险。 + +```cpp +void Foo(const unsigned char* buffer, size_t len) +{ + // 必须做参数合法性校验 + if (buffer == nullptr || len == 0 || len >= MAX_BUFFER_LEN) { + ... // 错误处理 + } + + const char* s = reinterpret_cast(buffer); + size_t nameLen = strnlen(s, len); // 使用strnlen缓解读越界风险 + if (nameLen == len) { + ... // 错误处理 + } + std::string name(s, nameLen); + ... + Foo2(name); + ... +} +``` + +```cpp +namespace ModuleA { +// Foo2 为模块内部函数,约定为由调用者保证参数的合法性 +static void Foo2(const std::string& name) +{ + ... + Bar(name.c_str()); // 调用MODULE_B中的函数 +} + +// Foo 为模块的外部接口,需要校验参数的合法性 +void Foo(const unsigned char* buffer, size_t len) +{ + // 检查空指针、参数合法范围等 + if (buffer == nullptr || len <= sizeof(int)) { + // 错误处理 + ... + } + + int nameLen = *(reinterpret_cast(buffer)); // 从报文中获取name字符串长度 + // nameLen 是不可信数据,必须检查合法性 + if (nameLen <= 0 || static_cast(nameLen) > len - sizeof(int)) { + // 错误处理 + ... + } + + std::string name(reinterpret_cast(buffer), nameLen); + Foo2(name); // 调用本模块内内部函数 + ... +} +} +``` + +以下是使用C语言编写的`MODULE_B`模块中的代码: + +```cpp +// Bar 为 MODULE_B 模块的公共函数, +// 其约定为,如果参数name不为nullptr,那么必须是一个具有’\0’结尾的合法字符串并且长度大于0 +void Bar(const char* name) +{ + // 必须做参数合法性校验 + if (name == nullptr || name[0] == '\0') { + // 错误处理 + ... + } + size_t nameLen = strlen(name); // 不需要使用strnlen + ... +} +``` + +对于模块A来说, buffer 是外部不可信输入,必须做严格的校验,从 buffer 解析出来的 name,在解析过程中进行了合法性校验,在模块A内部属于合法数据,作为参数传递给内部子函数时不需要再做合法性校验(如果要继续对 name 内容进行解析,那么仍然必须对 name 内容进行校验)。 +如果模块A中的 name 继续跨越信任面传递给其他模块(在本例中是直接调用模块B的公共函数,也可以是通过文件、管道、网络等方式),那么对于B模块来说, name 属于不可信数据,必须做合法性校验。 + +# 类 + +## 类的成员变量必须显式初始化 + +**【描述】** +如果没有对类成员变量显示初始化,会使对象处于一种不确定状态。如果类的成员变量具有默认构造函数,那么可以不需要显式初始化。 + +**【反例】** + +```cpp +class Message { +public: + void Process() + { + ... + } + +private: + uint32_t msgId; // 不符合:成员变量没有被初始化 + size_t msgLength; // 不符合:成员变量没有被初始化 + unsigned char* msgBuffer; // 不符合:成员变量没有被初始化 + std::string someIdentifier; // 默认构造函数仅会初始化该成员 +}; + +Message message; // message成员变量没有被完全初始化 +message.Process(); // 后续使用存在隐患 +``` + +**【正例】** +一种做法是在类成员变量声明时显示初始化。 + +```cpp +class Message { +public: + void Process() + { + ... + } + +private: + uint32_t msgId{0}; + size_t msgLength{0}; + unsigned char* msgBuffer{nullptr}; + std::string someIdentifier; // 具有默认构造函数,不需要显式初始化 +}; +``` + +另一种做法是使用构造函数初始化列表初始化。 + +```cpp +class Message { +public: + Message() : msgId(0), msgLength(0), msgBuffer(nullptr) {} + void Process() + { + ... + } + +private: + uint32_t msgId; + size_t msgLength; + unsigned char* msgBuffer; + std::string someIdentifier; // 具有默认构造函数,不需要显式初始化 +}; +``` + +## 明确需要实现哪些特殊成员函数 + +**【描述】** +**三之法则(Rule of three):** +若某个类需要用户定义的析构函数、用户定义的拷贝构造函或拷贝赋值操作符,则它基本三者全部都需要。 + +```cpp +class Foo { +public: + Foo(const char* buffer, size_t size) { Init(buffer, size); } + Foo(const Foo& other) { Init(other.buf, other.size); } + + Foo& operator=(const Foo& other) + { + Foo tmp(other); + Swap(tmp); + return *this; + } + + ~Foo() { delete[] buf; } + + void Swap(Foo& other) noexcept + { + using std::swap; + swap(buf, other.buf); + swap(size, other.size); + } + +private: + void Init(const char* buffer, size_t size) + { + this->buf = new char[size]; + memcpy(this->buf, buffer, size); + this->size = size; + } + + char* buf; + size_t size; +}; +``` + +如果类对某种资源进行管理,而资源句柄是非类类型的对象(裸指针、文件描述符等),则这些隐式定义的成员函数通常都不正确,其析构函数不做任何事,而拷贝构造函数/拷贝赋值操作符则进行“浅拷贝”。 + +通过可复制句柄来管理不可复制资源的类,可能必须将其拷贝赋值和拷贝构造函数声明为私有的并且不提供其定义,或将它们定义为delete的。 + +**五之法则(Rule of five):** +如果定义了析构函数、拷贝构造函数或拷贝赋值操作符,会阻止移动构造函数和移动赋值操作符的隐式定义,所以任何想要移动语义的类必须声明全部五个特殊成员函数。 + +```cpp +class Foo { +public: + Foo(const char* buffer, size_t size) { Init(buffer, size); } + Foo(const Foo& other) { Init(other.buf, other.size); } + + Foo& operator=(const Foo& other) + { + Foo tmp(other); + Swap(tmp); + return *this; + } + + Foo(Foo&& other) noexcept : buf(std::move(other.buf)), size(std::move(other.size)) + { + other.buf = nullptr; + other.size = 0; + } + + Foo& operator=(Foo&& other) noexcept + { + Foo tmp(std::move(other)); + Swap(tmp); + return *this; + } + + ~Foo() { delete[] buf; } + + void Swap(Foo& other) noexcept + { + using std::swap; + swap(buf, other.buf); + swap(size, other.size); + } + +private: + void Init(const char* buffer, size_t size) + { + this->buf = new char[size]; + memcpy(this->buf, buffer, size); + this->size = size; + } + + char* buf; + size_t size; +}; +``` + +但是如果不提供移动构造函数和移动赋值操作符通常不会发生错误,但会导致失去优化机会。 + +**零之法则(Rule of zero):** +如果类不需要专门处理资源的所有权,那么就不应该有自定义的析构函数、拷贝/移动构造函数或拷贝/移动赋值操作符。 + +```cpp +class Foo { +public: + Foo(const std::string& text) : text(text) {} + +private: + std::string text; +}; +``` + +只要声明了拷贝构造函数、拷贝赋值操作符或析构函数,编译器将不会隐式生成移动构造函数和移动赋值操作符,导致该类的移动操作都变成了代价更高的复制操作。 +只要声明了移动构造函数或移动赋值操作符,编译器会将隐式生成的拷贝构造函数或拷贝赋值操作符定义为delete的,导致改类只能被移动、不能被复制。 +因此,只要声明了其中的任何一个函数,就应当声明其他全部函数,避免出现非预期的结果。 + +类似地,如果基类需要定义public的虚析构函数,那么需要显示定义全部相关的特殊成员函数: + +```cpp +class Base { +public: + ... + Base(const Base&) = default; + Base& operator=(const Base&) = default; + Base(Base&&) = default; + Base& operator=(Base&&) = default; + virtual ~Base() = default; + ... +}; +``` + +但是,如果基类声明了拷贝构造/拷贝赋值操作符,可能会发生切片,所以经常会将基类中的拷贝构造/拷贝赋值操作符显式定义为delete, 并且同时将其他的特殊成员函数也显式定义为delete: + +```cpp +class Base { +public: + ... + Base(const Base&) = delete; + Base& operator=(const Base&) = delete; + Base(Base&&) = delete; + Base& operator=(Base&&) = delete; + virtual ~Base() = default; + ... +}; +``` + +## 基类中的拷贝构造函数、拷贝赋值操作符、移动构造函数、移动赋值操作符必须为非public函数或者为delete函数 + +**【描述】** +如果把一个派生类对象直接赋值给基类对象,会发生切片,只拷贝或者移动了基类部分,损害了多态行为。 + +**【反例】** +如下代码中,基类的拷贝构造函数和拷贝赋值操作符为default,如果派生类对象赋值给基类对象时会发生切片。 +可以将此例中的拷贝构造函数和拷贝赋值操作符声明为delete,编译器可检查出此类赋值行为。 + +```cpp +class Base { +public: + Base() = default; + Base(const Base&) = default; + Base& operator=(const Base&) = default; + ... + virtual void Fun() { std::cout << "Base" << std::endl; } +}; + +class Derived : public Base { + ... + void Fun() override { std::cout << "Derived" << std::endl; } +}; + +void Foo(const Base& base) +{ + Base other = base; // 不符合:发生切片 + other.Fun(); // 调用的是Base类的Fun函数 +} +Derived d; +Foo(d); +``` + +## 在移动构造函数和移动赋值操作符中必须将源对象的资源正确重置 + +**【描述】** +移动构造函数和移动赋值操作符将资源的所有权从一个对象移动到另外一个资源。一旦资源被移动,则应将源对象的资源正确重置。这样可以防止源对象在析构函数中释放了被移动的资源。 + +在被移动的对象中允许保留部分非资源相关数据,但必须保证被移动的对象处于可被正常析构的状态。 +因此,当一个对象被move以后,除非该对象处于明确指定的状态,否则不要依赖已move对象的值,否则可能产生非预期行为。 + +**【反例】** + +```cpp +class Foo { +public: + ... + Foo(Foo&& foo) noexcept : data(foo.data) + { + } + + Foo& operator=(Foo&& foo) + { + data = foo.data; + return *this; + } + + ~Foo() + { + delete[] data; + } + +private: + char* data = nullptr; +}; +``` + +上述Foo的移动构造函数和移动赋值操作符没有正确将源对象的资源重置,源对象析构的时候会将资源释放,导致新创建的对象中接管的资源成为无效资源。 + +**【正例】** + +```cpp +class Foo { +public: + ... + Foo(Foo&& foo) noexcept : data(foo.data) + { + foo.data = nullptr; + } + + Foo& operator=(Foo&& foo) + { + if (this == &foo) { + return *this; + } + delete[] data; + data = foo.data; + foo.data = nullptr; + return *this; + } + + ~Foo() + { + delete[] data; + } + +private: + char* data = nullptr; +}; +``` + +此外,不要依赖已经被move对象的值。 +某些标准库std::string的实现可能对短字节做优化,在实现移动语义时可能不会修改被移动字符串的内容,导致如下代码输出不一定是预期的b, 有可能输出为ab,存在兼容性问题。 + +```cpp +std::string str{"a"}; +std::string other = std::move(str); + +str.append(1, 'b'); +std::cout << str << std::endl; +``` + +## 通过基类指针释放派生类时,必须将基类中析构函数声明为虚函数 + +**【描述】** +只有基类析构函数是虚函数时,才能保证通过多态调用的时候调用到派生类的析构函数。 +如果没有将基类的析构函数声明为虚函数,当通过基类指针释放派生类时,只会调用基类的析构函数,不会调用派生类的析构函数,导致内存泄漏。 + +**【反例】** +没有将基类的析构函数声明为虚函数,导致了内存泄漏。 + +```cpp +class Base { +public: + Base() = default; + ~Base() { std::cout << "~Base" << std::endl; } + virtual std::string GetVersion() = 0; +}; +class Derived : public Base { +public: + Derived() + { + const size_t numberCount = 100; + numbers = new int[numberCount]; + } + + ~Derived() + { + delete[] numbers; + std::cout << "~Derived" << std::endl; + } + + std::string GetVersion() + { + return std::string("hello!"); + } + +private: + int* numbers; +}; +void Foo() +{ + Base* base = new Derived(); + delete base; // 调用的是 Base 的析构函数,造成资源泄漏 +} +``` + +## 对象赋值或初始化避免切片操作 + +**【描述】** + +将派生类对象按值赋值给基类对象时会发生切片,损害了多态行为。 + +如果确实需要将对象切片处理,建议定义一个显式操作完成这个功能,以避免理解错误,增加可维护性。 + +**【反例】** + +```cpp +class Base { + virtual void Fun(); +}; + +class Derived : public Base { + ... +}; +void Foo(const Base& base) +{ + Base other = base; // 不符合:发生切片 + other.Fun(); // 调用的是Base类的Fun函数 +} +Derived d; +Base b{d}; // 不符合:仅构造了Base部分 +b = d; // 不符合:仅赋值Base部分 + +Foo(d); +``` + +# 表达式与语句 + +## 确保对象在使用之前已被初始化 + +**【描述】** +本条款中的“初始化”指的是通过定义时显示初始化、默认构造初始化、赋值等方式使对象拥有期望的值。 +读取一个未初始化的值时,程序可能产生未定义行为,因此需要确保对象在使用之前已被初始化。 + +**【反例】** + +```cpp +void Bar(int data); +... +void Foo() +{ + int data; + Bar(data); // 不符合:未初始化就使用 + ... +} +``` + +如果有不同分支,要确保所有分支都得到初始化后才能使用。 + +```cpp +void Bar(int data); +... +void Foo(int condition) +{ + int data; + if (condition > 0) { + data = CUSTOMIZED_SIZE; + } + Bar(data); // 不符合:部分分支该值未初始化 + ... +} +``` + +**【正例】** + +```cpp +void Bar(int data); +... +void Foo() +{ + int data{0}; // 符合:显示初始化 + Bar(data); + ... +} +void InitData(int& data); +... +void Foo() +{ + int data; + InitData(data); // 符合:通过函数初始化 + ... +} +std::string data; // 符合:默认构造函数初始化 +... +``` + +## 避免使用reinterpret_cast + +**【描述】** +`reinterpret_cast`用于转换不相关类型。尝试用`reinterpret_cast`将一种类型强制转换另一种类型,这破坏了类型的安全性与可靠性,是一种不安全的转换。不同类型之间尽量避免转换。 + +## 避免使用const_cast + +**【描述】** +`const_cast`用于移除对象的`const`和`volatile`性质。 + +使用const_cast转换后的指针或者引用来修改const对象或volatile对象,程序会产生未定义行为。 + +**【反例】** + +```cpp +const int i = 1024; +int* p = const_cast(&i); +*p = 2048; // 未定义行为 +class Foo { +public: + void SetValue(int v) { value = v; } + +private: + int value{0}; +}; + +int main() +{ + const Foo foo; + Foo* p = const_cast(&foo); + p->SetValue(2); // 未定义行为 + return 0; +} +``` + +## 确保有符号整数运算不溢出 + +**【描述】** +在C++标准中,有符号整数溢出会使程序产生未定义行为。 +因此,不同的实现可以自由处理有符号整数溢出。例如:在将有符号整数类型定义为模数的实现中,编译器可以不检测整数溢出。 + +使用溢出后的数值可能导致程序缓冲区读写越界等风险。出于安全考虑,对外部数据中的有符号整数值在如下场景中使用时,需要确保运算不会导致溢出: + +- 指针运算的整数操作数(指针偏移值) +- 数组索引 +- 变长数组的长度(及长度运算表达式) +- 内存复制长度 +- 内存分配函数的参数 +- 循环判断条件 + +在精度低于int的整数类型上进行运算时,需要考虑整数提升。程序员还需要掌握整数转换规则,包括隐式转换规则,以便设计安全的算术运算。 + +**【反例】** +如下代码示例中,参与减法运算的整数是外部数据,在使用前未做校验,可能出现整数溢出,进而造成后续的内存复制操作出现缓冲区溢出。 + +```cpp +unsigned char* content = ... // 指向报文头的指针 +size_t contentSize = ... // 缓冲区的总长度 +int totalLen = ... // 报文总长度 +int skipLen = ... // 从消息中解析出来的需要忽略的数据长度 + +std::vector dest; + +// 用 totalLen - skipLen 计算剩余数据长度,可能出现整数溢出 +std::copy_n(&content[skipLen], totalLen - skipLen, std::back_inserter(dest)); +... +``` + +**【正例】** +如下代码示例中,重构为使用`size_t`类型的变量表示数据长度,并校验外部数据长度是否在合法范围内。 + +```cpp +unsigned char* content = ... //指向报文头的指针 +size_t contentSize = ... // 缓冲区的总长度 +size_t totalLen = ... // 报文总长度 +size_t skipLen = ... // 从消息中解析出来的需要忽略的数据长度 + +if (skipLen >= totalLen || totalLen > contentSize) { + ... // 错误处理 +} + +std::vector dest; +std::copy_n(&content[skipLen], totalLen - skipLen, std::back_inserter(dest)); +... +``` + +**【反例】** +如下代码示例中,对来自外部数据的数值范围做了校验,但是由于second是`int`类型,而校验条件中错误的使用了`std::numeric_limits::max()`进行限制,导致整数溢出。 + +```cpp +int second = ... // 来自外部数据 + + // 错误的使用了unsigned long的取值范围做上限校验 +if (second < 0 || second > (std::numeric_limits::max() / 1000)) { + return -1; +} +int millisecond = second * 1000; // 可能出现整数溢出 +... +``` + +**【正例】** +一种改进方案是将second的类型修改为`unsigned long`类型,这种方案适用于修改了变量类型更符合业务逻辑的场景。 + +```cpp +unsigned long second = ... // 将类型重构为 unsigned long 类型 + +if (second > (std::numeric_limits::max() / 1000)) { + return -1; +} +int millisecond = second * 1000; +... +``` + +另一种改进方案是将数值上限修改为`std::numeric_limits::max()`。 + +```cpp +int second = ... // 来自外部数据 + +if (second < 0 || second > (std::numeric_limits::max() / 1000)) { + return -1; +} +int millisecond = second * 1000; +``` + +**【影响】** +整数溢出可能导致程序缓冲区溢出以及执行任意代码。 + +## 确保无符号整数运算不回绕 + +**【描述】** +无符号整数的算术运算结果可能会发生整数回绕,使用回绕后的数值其可能导致程序缓冲区读写越界等风险。 +出于安全考虑,对外部数据中的无符号整数值在如下场景中使用时,需要确保运算不会导致回绕: + +- 指针偏移值(指针算术运算的整数操作数) +- 数组索引值 +- 内存拷贝的长度 +- 内存分配函数的参数 +- 循环判断条件 + +**【反例】** +如下代码示例中,校验下一个子报文的长度加上已处理报文的长度是否超过了整体报文的最大长度,在校验条件中的加法运算可能会出现整数回绕,造成绕过该校验的问题。 + +```cpp +size_t totalLen = ... // 报文的总长度 +size_t readLen = 0; // 记录已经处理报文的长度 +... +size_t pktLen = ParsePktLen(); // 从网络报文中解析出来的下一个子报文的长度 +if (readLen + pktLen > totalLen) { // 可能出现整数回绕 + ... // 错误处理 +} +... +readLen += pktLen; +... +``` + +**【正例】** +由于readLen变量记录的是已经处理报文的长度,必然会小于totalLen,因此将代码中的加法运算修改为减法运算,不会导致条件绕过。 + +```cpp +size_t totalLen = ... // 报文的总长度 +size_t readLen = 0; // 记录已经处理报文的长度 +... +size_t pktLen = ParsePktLen(); // 来自网络报文 +if (pktLen > totalLen - readLen) { + ... // 错误处理 +} +... +readLen += pktLen; +... +``` + +**【反例】** +如下代码示例中,校验len合法范围的运算可能会出现整数回绕,导致条件绕过。 + +```cpp +size_t len = ... // 来自用户态输入 + +if (SCTP_SIZE_MAX - len < sizeof(SctpAuthBytes)) { // 减法操作可能出现整数回绕 + ... // 错误处理 +} +... = kmalloc(sizeof(SctpAuthBytes) + len, gfp); // 可能出现整数回绕 +... +``` + +**【正例】** +如下代码示例中,调整减法运算的位置(需要确保在编译期间减法表达式的值不回绕),避免整数回绕问题。 + +```cpp +size_t len = ... // 来自用户态输入 + +if (len > SCTP_SIZE_MAX - sizeof(SctpAuthBytes)) { // 确保在编译期间减法表达式的值不翻转 + ... // 错误处理 +} +... = kmalloc(sizeof(SctpAuthBytes) + len, gfp); +... +``` + +**【例外】** +为正确执行程序,必要时无符号整数可能表现出模态(回绕)。建议将变量声明明确注释为支持模数行为,并且对该整数的每个操作也应明确注释为支持模数行为。 + +**【影响】** +整数回绕可能导致程序缓冲区溢出以及执行任意代码。 + +## 确保除法和余数运算不会导致除零错误(被零除) + +**【描述】** +整数的除法运算或取余运算的除数为0会导致程序产生未定义的行为。如果涉及到除法或者取余运算,必须确保除数不为0。 + +在二进制浮点数算数标准ISO/IEEE Std 754-1985中规定了浮点数被零除的行为及结果,但是仍然取决于程序所运行的软硬件环境是否遵循该标准。 +因此,在做浮点数被零除的运算前,应确保软硬件环境已遵循二进制浮点数算数标准,否则仍然存在未定义行为。 + +**【反例】** + +```c +size_t a = ReadSize(); // 来自外部数据 +size_t b = 1000 / a; // 不符合:a可能是0 +size_t c = 1000 % a; // 不符合:a可能是0 +... +``` + +**【正例】** +如下代码示例中,添加a是否为0的校验,防止除零错误。 + +```c +size_t a = ReadSize(); // 来自外部数据 +if (a == 0) { + ... // 错误处理 +} +size_t b = 1000 / a; // 符合:确保a不为0 +size_t c = 1000 % a; // 符合:确保a不为0 +... +``` + +**【影响】** +除零错误可能导致拒绝服务。 + +## 只能对无符号整数进行位运算 + +**【描述】** +对有符号整数进行位运算时可能产生未定义行为,本条款要求只能对无符号整数进行位运算,避免出现未定义行为。 +此外,对精度低于int类型的无符号整数进行位运算时,编译器会进行整数提升,再对提升后的整数进行位运算,因此要特别注意对于这类无符号整数的位运算,避免出现非预期的结果。 +本条款涉及的位操作符包括: + +- `~`(求反) +- `&`(与) +- `|`(或) +- `^`(异或) +- `>>`(右移位) +- `<<`(左移位) +- `&=` +- `^=` +- `|=` +- `>>=` +- `<<=` + +在C++20中有符号整数的移位操作具有良好的定义,可以对有符号整数进行移位运算。 + +**【反例】** +在C++20之前,如下代码中的右移操作`data >> 24`可以实现为算术(有符号)移位或逻辑(无符号)移位;在左移操作`value << data`中,如果value为负数或者左移后的结果超出其整数提升后类型的表示范围,会导致程序产生未定义行为。 + +```cpp +int32_t data = ReadByte(); +int32_t value = data >> 24; // 对有符号整数进行右移运算,其结果是实现定义的 + +... // 检查 data 的合法范围 + +int32_t mask = value << data; // 对有符号整数进行左移运算,程序可能产生未定义行为 +``` + +**【正例】** + +```cpp +uint32_t data = static_cast(ReadByte()); +uint32_t value = data >> 24; // 只对无符号整数进行位运算 + +... // 检查 data 的合法范围 + +uint32_t mask = value << data; +``` + +对于精度低于`int`的无符号整数进行位运算,由于整数提升,其结果可能是非预期的,应将操作结果立即转换为期望的类型, 避免因整数提升而导致非预期结果。 + +**【反例】** + +```cpp +uint8_t mask = 1; +uint8_t value = (~mask) >> 4; // 不符合:~运算的结果会包含高位数据,可能不符合预期 +``` + +**【正例】** + +```cpp +uint8_t mask = 1; +uint8_t value = (static_cast(~mask)) >> 4; // 符合:~运算后立即转换为期望的类型 +``` + +**【例外】** + +- 作为位标志使用的有符号整数常量或枚举值,可以作为 & 和 | 操作符的操作数。 + +```cpp +int fd = open(fileName, O_CREAT | O_EXCL, S_IRWXU | S_IRUSR); +``` + +- 一个在编译时就可以确定的有符号正整数,可以作为移位操作符的右操作数。 + +```cpp +constexpr int SHIFT_BITS = 3; +... +uint32_t id = ...; +uint32_t type = id >> SHIFT_BITS; +``` + +# 资源管理 + +## 外部数据作为数组索引或者内存操作长度时,需要校验其合法性 + +**【描述】** +外部数据作为数组索引对内存进行访问时,必须对数据的大小进行严格的校验,确保数组索引在有效范围内,否则会导致严重的错误。 +将数据复制到容量不足以容纳该数据的内存中会导致缓冲区溢出。为了防止此类错误,必须根据目标容量的大小限制被复制的数据大小,或者必须确保目标容量足够大以容纳要复制的数据。 + +**【反例】** +如下代码示例中,SetDevId()函数存在差一错误,当 index 等于 `DEV_NUM` 时,恰好越界写一个元素。 + +```cpp +struct Dev { + int id; + char name[MAX_NAME_LEN]; +}; + +static Dev devs[DEV_NUM]; + +int SetDevId(size_t index, int id) +{ + if (index > DEV_NUM) { // 存在差一错误 + ... // 错误处理 + } + + devs[index].id = id; + return 0; +} +``` + +**【正例】** +如下代码示例中,修改校验索引的条件,避免差一错误。 + +```cpp +struct Dev { + int id; + char name[MAX_NAME_LEN]; +}; + +static Dev devs[DEV_NUM]; + +int SetDevId(size_t index, int id) +{ + if (index >= DEV_NUM) { + ... // 错误处理 + } + devs[index].id = id; + return 0; +} +``` + +**【反例】** +外部输入的数据不一定会直接作为内存复制长度使用,还可能会间接参与内存复制操作。 +如下代码示例中,inputTable.count来自设备外部报文,虽然没有直接作为内存复制长度使用,而是作为for循环体的上限使用,间接参与了内存复制操作。由于没有校验其大小,可造成缓冲区溢出: + +```cpp +struct ValueTable { + size_t count; + int val[MAX_NUMBERS]; +}; + +void ValueTableDup(const ValueTable& inputTable) +{ + ValueTable outputTable = {0, {0}}; + ... + for (size_t i = 0; i < inputTable.count; i++) { + outputTable.val[i] = inputTable.val[i]; + } + ... +} +``` + +**【正例】** +如下代码示例中,对inputTable.count做了校验。 + +```cpp +struct ValueTable { + size_t count; + int val[MAX_NUMBERS]; +}; + +void ValueTableDup(const ValueTable& inputTable) +{ + ValueTable outputTable = {0, {0}}; + ... + // 根据业务场景,对来自外部报文的循环长度inputTable.count + // 与outputTable.val数组大小做校验,避免造成缓冲区溢出 + if (inputTable->count > + sizeof(outputTable.val) / sizeof(outputTable.val[0])) { + ... // 错误处理 + } + for (size_t i = 0; i < inputTable.count; i++) { + outputTable.val[i] = inputTable.val[i]; + } + ... +} +``` + +**【影响】** +如果复制数据的长度是外部可控的,则复制数据的过程中可能出现缓冲区溢出,在某些情况下可以造成任意代码执行漏洞。 + +## 内存申请前,必须对申请内存大小进行合法性校验 + +**【描述】** +当申请内存大小由程序外部输入时,内存申请前,要求对申请内存大小进行合法性校验,防止申请0长度内存,或者过多地、非法地申请内存。 +因为内存的资源是有限的,是可以被耗尽的。当申请内存的数值过大(可能一次就申请了非常大的超预期的内存;也可能循环中多次申请内存),很可能会造成非预期的资源耗尽。 +大小不正确的参数、不当的范围检查、整数溢出或者截断都可能造成实际分配的缓冲区不符合预期。如果申请内存受攻击者控制,还可能会发生缓冲区溢出等安全问题。 + +**【反例】** +如下代码示例中,将动态分配size大小的内存。但是未对size做合法性校验。 + +```c +// 这里的size在传入DoSomething()函数之前还未做过合法性校验 +int DoSomething(size_t size) +{ + ... + char* buffer = new char[size]; // 本函数内,size使用前未做校验 + ... + delete[] buffer; +} +``` + +**【正例】** +如下代码示例中,动态分配size大小的内存前,进行了符合程序需要的合法性校验。 + +```c +// 这里的size在传入DoSomething()函数之前还未做过合法性校验 +int DoSomething(size_t size) +{ + // 本函数内,对size做合法性校验,FOO_MAX_LEN被定义为符合程序设计预期的最大内存空间 + if (size == 0 || size > FOO_MAX_LEN) { + ... // 错误处理 + } + char* buffer = new char[size]; + ... + delete[] buffer; +} +``` + +**【影响】** +如果申请内存的大小是外部可控的,可能导致资源耗尽,造成拒绝服务。 + +## 在传递数组参数时,不应单独传递指针 + +**【描述】** +当函数参数类型为数组(不是数组的引用)或者指针时,若调用者传入数组,则在参数传递时数组会退化为指针,其数组长度信息会丢失,容易引发越界读写等问题。 +如果函数只接收固定长度的数组为参数,可以定义参数类型为数组引用或者`std::array`。 +如果函数接受的是不带长度的指针,那么应该把长度作为另外一个参数也传递进去。 + +**【反例】** + +```cpp +constexpr int MAX_LEN = 1024; +constexpr int SIZE = 10; + +void UseArr(int arr[]) +{ + for (int i = 0; i < MAX_LEN; i++) { + std::cout << arr[i] << std::endl; + } +} + +void Test() +{ + int arr[SIZE] = {0}; + UseArr(arr); +} +``` + +**【正例】** + +可以把指针和长度合起来做成一个类型,方便使用。例如:类似下面的简单封装: + +```cpp +template +class Slice { +public: + template + Slice(T (&arr)[N]) : data(arr), len(N) {} + + template + Slice(std::array arr) : data(arr.data()), len(N) {} + + Slice(T* arr, size_t n) : data(arr), len(n) {} + ... + +private: + T* data; + size_t len; +}; + +void UseArr(Slice arr) +{ + for (int i = 0; i < arr.size(); i++) { + std::cout << arr[i] << std::endl; + } +} + +constexpr int SIZE = 10; + +void Test() +{ + int arr[SIZE] = {0}; + Slice s{arr}; + UseArr(s); +} +``` + +如果项目允许的话,推荐使用成熟的库来做这个事情,例如C++20中的`std::span`类型。 + +在不使用这些工具类的情况下,可以把指针和长度作为两个参数传递。 + +```cpp +void UseArr(int arr[], size_t len) +{ + for (int i = 0; i < len; i++) { + std::cout << arr[i] << std::endl; + } +} + +constexpr int SIZE = 10; + +void Test() +{ + int arr[SIZE] = {0}; + UseArr(arr, sizeof(arr)); +} +``` + +## 当lambda会逃逸出函数外面时,禁止按引用捕获局部变量 + +**【描述】** +如果一个 lambda 不止在局部范围内使用,禁止按引用捕获局部变量,比如它被传递到了函数的外部,或者被传递给了其他线程的时候。lambda按引用捕获就是把局部对象的引用存储起来。如果 lambda 的生命周期会超过局部变量生命周期,则可能导致内存不安全。 + +**【反例】** + +```cpp +void Foo() +{ + int local = 0; + // 按引用捕获 local,当函数返回后,local 不再存在,因此 Process() 的行为未定义 + threadPool.QueueWork([&] { Process(local); }); +} +``` + +**【正例】** + +```cpp +void Foo() +{ + int local = 0; + // 按值捕获 local, 在Process() 调用过程中,local 总是有效的 + threadPool.QueueWork([local] { Process(local); }); +} +``` + +## 指向资源句柄或描述符的变量,在资源释放后立即赋予新值 + +**【描述】** +指向资源句柄或描述符的变量包括指针、文件描述符、socket描述符以及其他指向资源的变量。 +以指针为例,当指针成功申请了一段内存之后,在这段内存释放以后,如果其指针未立即设置为nullptr,也未分配一个新的对象,那这个指针就是一个悬空指针。 +如果再对悬空指针操作,可能会发生重复释放或访问已释放内存的问题,造成安全漏洞。 +消减该漏洞的有效方法是将释放后的指针立即设置为一个确定的新值,例如设置为nullptr。对于全局性的资源句柄或描述符,在资源释放后,应该马上设置新值,以避免使用其已释放的无效值;对于只在单个函数内使用的资源句柄或描述符,应确保资源释放后其无效值不被再次使用。 + +**【反例】** +如下代码示例中,根据消息类型处理消息,处理完后释放掉body指向的内存,但是释放后未将指针设置为nullptr。如果还有其他函数再次处理该消息结构体时,可能出现重复释放内存或访问已释放内存的问题。 + +```c +int Fun() +{ + SomeStruct *msg = nullptr; + + ... // 使用new分配msg、msg->body的内存空间并初始化msg + + if (msg->type == MESSAGE_A) { + ... + delete msg->body; // 不符合:释放内存后,未置空 + } + + ... + + // 将msg存入全局队列,后续可能使用已释放的body成员 + if (!InsertMsgToQueue(msg)) { + delete msg->body; // 可能再次释放了body的内存 + delete msg; + return -1; + } + return 0; +} +``` + +**【正例】** +如下代码示例中,立即对释放后的指针设置为nullptr,避免重复释放指针。 + +```c +int Fun() +{ + SomeStruct *msg = nullptr; + + ... // 使用new分配msg、msg->body的内存空间并初始化msg + + if (msg->type == MESSAGE_A) { + ... + delete msg->body; + msg->body = nullptr; + } + + ... + + // 将msg存入全局队列 + if (!InsertMsgToQueue(msg)) { + delete msg->body; // 马上离开作用域,不必赋值 nullptr + delete msg; // 马上离开作用域,不必赋值 nullptr + return -1; + } + return 0; +} +``` + +默认的内存释放函数针对空指针不执行任何动作。 + +**【反例】** +如下代码示例中文件描述符关闭后未赋新值。 + +```c +SOCKET s = INVALID_SOCKET; +int fd = -1; +... +closesocket(s); +... +close(fd); +... +``` + +**【正例】** +如下代码示例中,在资源释放后,对应的变量应该立即赋予新值。 + +```c +SOCKET s = INVALID_SOCKET; +int fd = -1; +... +closesocket(s); +s = INVALID_SOCKET; +... +close(fd); +fd = -1; +... +``` + +**【影响】** +再次使用已经释放的内存,或者再次释放已经释放的内存,或其他使用已释放资源的行为,可能导致拒绝服务或执行任意代码。 + +## new和delete配对使用,new[]和delete[]配对使用 + +**【描述】** +使用 new 操作符创造的对象,只能使用 delete 操作符来销毁。 +使用 new[] 创造的对象数组只能由 delete[] 操作符来销毁。 + +**【反例】** + +```cpp +class C { +public: + C(size_t len) : arr(new int[len]) {} + ~C() + { + delete arr; // 此处应该是 delete[] arr; + } + +private: + int* arr; +}; +``` + +**【正例】** + +```cpp +class C { +public: + C(size_t len) : arr(new int[len]) {} + ~C() { delete[] arr; } + +private: + int* arr; +}; +``` + +## 自定义new/delete操作符需要配对定义,且行为与被替换的操作符一致 + +**【描述】** +自定义操作符的时候,new 和 delete 要配对定义,new[] 和 delete[] 要配对定义。 +自定义 new/delete 操作符的行为要与被替换的 new/delete 的行为一致。 + +**【反例】** + +```cpp +// 如果自定义了 operator new,必须同时自定义对应的 operator delete +struct S { + static void* operator new(size_t sz) + { + ... // 自定义操作 + return ::operator new(sz); + } +}; +``` + +**【正例】** + +```cpp +struct S { + static void* operator new(size_t sz) + { + ... // 自定义操作 + return ::operator new(sz); + } + static void operator delete(void* ptr, size_t sz) + { + ... // 自定义操作 + ::operator delete(ptr); + } +}; +``` + +默认的 new 操作符在内存分配失败时,会抛出`std::bad_alloc`异常,而使用了`std::nothrow`参数的 new 操作符在内存分配失败时,会返回 nullptr。 +自定义的 new/delete 操作符要和内置的操作符行为保持一致。 + +**【反例】** + +```cpp +// 在内存管理模块头文件中声明的函数 +extern void* AllocMemory(size_t size); // 分配失败返回 nullptr +void* operator new(size_t size) +{ + return AllocMemory(size); +} +``` + +**【正例】** + +```cpp +// 在内存管理模块头文件中声明的函数 +extern void* AllocMemory(size_t size); // 分配失败返回 nullptr +void* operator new(size_t size) +{ + void* ret = AllocMemory(size); + if (ret != nullptr) { + return ret; + } + throw std::bad_alloc(); // 分配失败抛出异常 +} + +void* operator new(size_t size, const std::nothrow_t& tag) +{ + return AllocMemory(size); +} +``` + +# 错误处理 + +## 抛异常时,抛对象本身,而不是指向对象的指针 + +**【描述】** +C++中推荐的抛异常方式是抛对象本身,而不是指向对象的指针。 + +用throw语句抛出异常的时候,会构造一个临时对象,称为“异常对象(exception object)”。这个异常对象的生命周期在C++语言中很明确:异常对象在throw时被构造;在某个捕获它的catch语句以`throw`以外的方式结束(即没有重新抛出)时,或者指向这个异常的`std::exception_ptr`对象被析构时析构。 + +抛出指针,会使回收被抛出对象的责任不明确。捕获异常的地方是否有义务对该指针进行`delete`操作,取决于该对象是如何分配的(例如静态变量,或者用`new`分配),以及这个对象是否被共享了。但是指针类型本身并不能表明这个对象的生命周期以及所有权,也就无法判断是否应该`delete`。如果应该`delete`却没有做,会造成内存泄露;如果不该`delete`却做了,会造成重复释放。 + +**【反例】** + +不要抛指针。 + +```cpp +static SomeException exc1("reason 1"); + +try { + if (SomeFunction()) { + throw &exc1; // 不符合:这是静态对象的指针,不应该delete + } else { + throw new SomeException("reason 2"); // 不符合:这是动态分配的,应该delete + } +} catch (const SomeException* e) { + delete e; // 不符合:这里不能确定是否需要delete +} +``` + +**【正例】** + +永远抛异常对象本身。 + +```cpp +try { + if (SomeFunction()) { + throw SomeException("reason 1"); + } else { + throw SomeException("reason 2"); + } +} catch (const SomeException& e) { + ... // 符合:这里可以确定不需要delete +} +``` + +## 禁止从析构函数中抛出异常 + +**【描述】** + +析构函数默认自带`noexcept`属性,如果析构函数抛出异常,会直接导致`std::terminate`。自C++11起,允许析构函数被标记为`noexcept(false)`,但即便如此,如果析构函数在stack unwinding的过程中被调用(例如另一个异常抛出,导致栈上的局部变量被析构),结果也是`std::terminate`,而析构函数最大的作用就是在不论正常返回还是抛出异常的情况下都能清理局部变量。因此,让析构函数抛出异常一般都是不好的。 + +# 标准库 + +## 禁止从空指针创建std::string + +**【描述】** +将空指针传递给std::string构造函数,会解引用空指针,从而导致程序产生未定义行为。 + +**【反例】** + +```cpp +void Foo() +{ + const char* path = std::getenv("PATH"); + std::string str(path); // 错误:这里没有判断getenv的返回值是否为nullptr + std::cout << str << std::endl; +} +``` + +**【正例】** + +```cpp +void Foo() +{ + const char* path = std::getenv("PATH"); + if (path == nullptr) { + ... // 报告错误 + return; + } + std::string str(path); + ... + std::cout << str << std::endl; +} +void Foo() +{ + const char* path = std::getenv("PATH"); + std::string str(path == nullptr ? path : ""); + ... // 判断空字符串 + std::cout << str << std::endl; // 必要时判断空字符串 +} +``` + +## 不要保存std::string类型的c_str和data成员函数返回的指针 + +**【描述】** +为保证调用std::string对象的c_str()和data()成员函数返回的引用值结果的有效性,不应保存std::string类型的c_str()和data()的结果,而是在每次需要时直接调用(调用的开销会被编译器内联优化)。否则,当调用此std::string对象的修改方法修改对象后,或超出std::string对象作用域时,之前存储的指针将会失效。使用失效的指针将导致未定义行为。 + +**【反例】** + +```cpp +void Bar(const char* data) +{ + ... +} + +void Foo1() +{ + std::string name{"demo"}; + const char* text = name.c_str(); // 表达式结束以后,name的生命周期还在,指针有效 + + // 如果中间调用了std::string的非const成员函数,导致name被修改,例如operator[], begin()等, + // 可能会导致text的内容不可用,或者不是原来的字符串 + name = "test"; + name[1] = '2'; + ... + Bar(text); // 此处text已不再指向合法内存空间 +} + +void Foo2() +{ + std::string name{"demo"}; + std::string test{"test"}; + const char* text = (name + test).c_str(); // 表达式结束以后,+号产生的临时对象被销毁 + ... + Bar(text); // 此处text已不再指向合法内存空间 +} + +void Foo3(std::string& s) +{ + const char* data = s.data(); + ... + s.replace(0, 3, "***"); + ... + Bar(data); // 此处text已不再指向合法内存空间 +} +``` + +**【正例】** + +```cpp +void Foo1() +{ + std::string name{"demo"}; + + name = "test"; + name[1] = '2'; + ... + Bar(name.c_str()); +} + +void Foo2() +{ + std::string name{"demo"}; + std::string test{"test"}; + name += test; + ... + Bar(name.c_str()); +} + +void Foo3(std::string& s) +{ + ... + s.replace(0, 3, "***"); + ... + Bar(s.data()); +} +``` + +**【例外】** +在少数对性能要求非常高的代码中,为了适配已有的只接受`const char*`类型入参的函数,可以临时保存std::string对象的c_str()方法返回的指针。但是必须严格保证std::string对象的生命周期长于所保存指针的生命周期,并且保证在所保存指针的生命周期内,std::string对象不会被修改。 + +## 确保用于字符串操作的缓冲区有足够的空间容纳字符数据和结束符,并且字符串以null结束符结束 + +**【描述】** +C风格字符串是一个连续的字符序列,由字符序列中的第一个出现的null字符终止并包含该null字符。 + +复制或存储C风格字符串时,必须确保缓冲区有足够的空间容纳字符序列包括null结束符,并且字符串以null结束符结束,否则可能会导致缓冲区溢出问题: + +- 优先使用std::string表示字符串,std::string表示字符串操作更简便,更容易被正确的使用,避免由于C风格字符串使用不当而导致溢出、没有null结束符的问题。 +- 使用C/C++标准库提供的C风格字符串操作函数时,需要确保输入的字符串以null结束符结束、不能超出字符串缓冲区的范围读写字符串、确保进存储操作后的字符串以null结束符结束。 + +**【反例】** + +```cpp +char buf[BUFFER_SIZE]; +std::cin >> buf; +void Foo(std::istream& in) +{ + char buffer[BUFFER_SIZE]; + if (!in.read(buffer, sizeof(buffer))) { // 注意:in.read()不能保证'\0'结尾 + ... // 错误处理 + return; + } + + std::string str(buffer); // 不符合:字符串没有结尾的'\0' + ... +} +void Foo(std::istream& in) +{ + std::string s; + in >> s; // 不符合:没有限制待读取的长度,可能导致资源消耗或攻击 + ... +} +``` + +**【正例】** + +```cpp +char buf[BUFFER_SIZE] = {0}; +std::cin.width(sizeof(buf) - 1); // 注意需要缓冲区长度-1,以留出字符串末尾'\0'的空间 +std::cin >> buf; +void Foo(std::istream& in) +{ + char buffer[BUFFER_SIZE]; + + if (!in.read(buffer, sizeof(buffer)) { // 注意in.read()不能保证'\0'结尾 + ... // 错误处理 + return; + } + + std::string str(buffer, in.gcount()); // 让std::string构造函数,只读取指定长度的字符内容 + ... +} +void Foo(std::istream& in) +{ + std::string s; + in.width(MAX_NEED_SIZE); + in >> s; // 符合:已经限制读取的最大长度 + ... +} +``` + +**【影响】** +未对外部数据中的整数值进行限制可能导致拒绝服务,缓冲区溢出,信息泄露,或执行任意代码。 + +## 禁止使用std::string存储敏感信息 + +**【描述】** +std::string类是C++内部定义的字符串管理类,如果口令等敏感信息通过std::string进行操作,在程序运行过程中,敏感信息可能会散落到内存的各个地方,并且无法清除。 + +**【反例】** +如下代码中,Foo函数中获取密码,保存到std::string变量password中,随后传递给VerifyPassword函数,在这个过程中,password实际上在内存中出现了两份。 + +```cpp +bool VerifyPassword(std::string password) +{ + ... +} + +void Foo() +{ + std::string password = GetPassword(); + VerifyPassword(password); +} +``` + +**【影响】** +未及时清理敏感信息,可能导致信息泄露。 + +## 外部数据用于容器索引或迭代器时必须确保在有效范围内 + +**【描述】** +外部数据是不可信数据,当将外部数据用于容器或数组的索引时,应确保其值在容器或数组可被访问元素的有效范围内;当将外部数据用于迭代器偏移时,应确保偏移后的迭代器值在与迭代器关联容器(从容器对象c的begin()方法创建)的[begin(), end())之间(即大于等于c.begin(),小于等于c.end())。 + +对于具有at()方法的容器(如std::vector, std::set, std::map),对应索引越界或键值内容不存在时,方法将抛出异常;而其对应的operator[]出现索引越界时,将导致未定义行为;或者因键值内容不存在而构造对应键值的默认值不成功时,也将导致未定义行为。 + +**【反例】** + +```cpp +int main() +{ + // 得到一个来自外部输入的整数 (index) + int index; + if (!(std::cin >> index)) { + ... // 错误处理 + return -1; + } + + std::vector c{'A', 'B', 'C', 'D'}; + + // 不符合:没有正确校验index的范围,溢出读取:需要确保index在容器元素的位置范围 + std::cout << c[index] << std::endl; + + // 不符合:需要确保index在容器/数组元素的位置范围 + for (auto pos = std::cbegin(c) + index; pos < std::cend(c); ++pos) { + std::cout << *pos << std::endl; + } + return 0; +} +void Foo(size_t n) +{ + std::vector v{0, 1, 2, 3}; + + // n为外部的API传入的索引,可能导致越界访问 + for_each_n(v.cbegin(), n, [](int x) { std::cout << x; }); +} +``` + +**【正例】** + +```cpp +int main() +{ + // 得到一个来自外部输入的整数 (index) + int index; + if (!(std::cin >> index)) { + ... // 错误处理 + return -1; + } + + // 这里仅以std::vector来举例,std::cbegin(c)等代码也适用于std::string字符串、 + // 和C数组(但不适应于char*变量以及char*表示的静态字符串) + std::vector c{'A', 'B', 'C', 'D'}; + + try { + std::cout << c.at(index) << std::endl; // 符合:索引越界时,at函数将抛出异常 + } catch (const std::out_of_range& e) { + ... // 越界异常处理 + } + + // 后续代码必须使用检验合法的 index 进行容器元素索引或迭代器偏移 + // 正确校验index的范围:已确保index在容器元素的位置范围 + if (index < 0 || index >= c.size()) { + ... // 错误处理 + return -1; + } + + std::cout << c[index] << std::endl; // 符合:已检验index的范围 + + // 符合:已检验index + for (auto pos = std::cbegin(c) + index; pos < std::cend(c); ++pos) { + std::cout << *pos << std::endl; + } + return 0; +} +void Foo(size_t n) +{ + std::vector v{0, 1, 2, 3}; + + // 必须确保for_each_n的迭代范围[first, first + count)有效 + if (n > v.size()) { + ... // 错误处理 + return; + } + for_each_n(v.cbegin(), n, [](int x) { std::cout << x; }); +} +``` + +## 调用格式化输入/输出函数时,使用有效的格式字符串 + +**【描述】** +使用C风格的格式化输入/输出函数时,需要确保格式串是合法有效的,并且格式串与相应的实参类型是严格匹配的,否则会使程序产生非预期行为。 + +除C风格的格式化输入/输出函数以外,C++中类似的函数也需要确保使用有效的格式串,如C++20的std::format()函数。 + +对于自定义C风格的格式化函数,可以使用编译器支持的属性自动检查使用自定义格式化函数的正确性。 +例如:GCC支持自动检测类似printf, scanf, strftime, strfmon的自定义格式化函数,参考GCC手册的Common Function Attributes: + +```c +extern int CustomPrintf(void* obj, const char* format, ...) + __attribute__ ((format (printf, 2, 3))); +``` + +**【反例】** +如下代码示例中,格式化输入一个整数到macAddr变量中,但是macAddr为unsigned char类型,而%x对应的是int类型参数,函数执行完成后会发生写越界。 + +```c +unsigned char macAddr[6]; +... +// macStr中的数据格式为 e2:42:a4:52:1e:33 +int ret = sscanf(macStr, "%x:%x:%x:%x:%x:%x\n", + &macAddr[0], &macAddr[1], + &macAddr[2], &macAddr[3], + &macAddr[4], &macAddr[5]); +... +``` + +**【正例】** +如下代码中,使用%hhx确保格式串与相应的实参类型严格匹配。 + +```c +unsigned char macAddr[6]; +... +// macStr中的数据格式为 e2:42:a4:52:1e:33 +int ret = sscanf(macStr, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx\n", + &macAddr[0], &macAddr[1], + &macAddr[2], &macAddr[3], + &macAddr[4], &macAddr[5]); +... +``` + +注:在C++中不推荐使用sscanf, sprintf等C库函数,可以替换为:std::istringstream, std::ostringstream, std::stringstream等。 + +**【影响】** +错误的格式串可能造成内存破坏或者程序异常终止。 + +## 调用格式化输入/输出函数时,禁止format参数受外部数据控制 + +**【描述】** +调用格式化函数时,如果format参数由外部数据提供,或由外部数据拼接而来,会造成字符串格式化漏洞。 +以C标准库的格式化输出函数为例,当其format参数外部可控时,攻击者可以使用%n转换符向指定地址写入一个整数值、使用%x或%d转换符查看栈或寄存器内容、使用%s转换符造成进程崩溃等。 + +常见格式化函数有: + +- 格式化输出函数: sprintf, vsprintf, snprintf, vsnprintf等等 +- 格式化输入函数: sscanf, vsscanf, fscanf, vscanf等等 +- 格式化错误消息函数: err(), verr(), errx(), verrx(), warn(), vwarn(), warnx(), vwarnx(), error(), error_at_line() +- 格式化日志函数: syslog(), vsyslog() +- C++20提供的std::format() + +调用格式化函数时,应使用常量字符串作为格式串,禁止格式串外部可控: + +```cpp +Box v{MAX_COUNT}; +std::cout << std::format("{:#x}", v); +``` + +**【反例】** +如下代码示例中,使用Log()函数直接打印外部数据,可能出现格式化字符串漏洞。 + +```c +void Foo() +{ + std::string msg = GetMsg(); + ... + syslog(priority, msg.c_str()); // 不符合:存在格式化字符串漏洞 +} +``` + +**【正例】** +下面是推荐做法,使用%s转换符打印外部数据,避免格式化字符串漏洞。 + +```c +void Foo() +{ + std::string msg = GetMsg(); + ... + syslog(priority, "%s", msg.c_str()); // 符合:这里没有格式化字符串漏洞 +} +``` + +**【影响】** +如果格式串被外部可控,攻击者可以使进程崩溃、查看栈内容、查看内存内容或者在任意内存位置写入数据,进而以被攻击进程的权限执行任意代码。 + +## 禁止外部可控数据作为进程启动函数的参数或者作为dlopen/LoadLibrary等模块加载函数的参数 + +**【描述】** +本条款中进程启动函数包括system、popen、execl、execlp、execle、execv、execvp等。 +system()、popen()等函数会创建一个新的进程,如果外部可控数据作为这些函数的参数,会导致注入漏洞。 +使用execl()等函数执行新进程时,如果使用shell启动新进程,则同样存在命令注入风险。 +使用execlp()、execvp()、execvpe()函数依赖于系统的环境变量PATH来搜索程序路径,使用它们时应充分考虑外部环境变量的风险,或避免使用这些函数。 + +因此,总是优先考虑使用C标准函数实现需要的功能。如果确实需要使用这些函数,应使用白名单机制确保这些函数的参数不受任何外来数据的影响。 + +dlopen、LoadLibrary函数会加载外部模块,如果外部可控数据作为这些函数的参数,有可能会加载攻击者事先预制的模块。如果要使用这些函数,可以采用如下措施之一: + +- 使用白名单机制,确保这些函数的参数不受任何外来数据的影响。 +- 使用数字签名机制保护要加载的模块,充分保证其完整性。 +- 在设备本地加载的动态库通过权限与访问控制措施保证了本身安全性后,通过特定目录自动被程序加载。 +- 在设备本地的配置文件通过权限与访问控制措施保证了本身安全性后,自动加载配置文件中指定的动态库。 + +**【反例】** +如下代码从外部获取数据后直接作为LoadLibrary函数的参数,有可能导致程序被植入木马。 + +```c +char* msg = GetMsgFromRemote(); +LoadLibrary(msg); +``` + +如下代码示例中,使用 system() 函数执行 cmd 命令串来自外部,攻击者可以执行任意命令: + +```c +std::string cmd = GetCmdFromRemote(); +system(cmd.c_str()); +``` + +如下代码示例中,使用 system() 函数执行 cmd 命令串的一部分来自外部,攻击者可能输入 `some dir;reboot`字符串,创造成系统重启: + +```cpp +std::string name = GetDirNameFromRemote(); +std::string cmd{"ls " + name}; +system(cmd.c_str()); +``` + +使用exec系列函数来避免命令注入时,注意exec系列函数中的path、file参数禁止使用命令解析器(如/bin/sh)。 + +```c +int execl(const char* path, const char* arg, ...); +int execlp(const char* file, const char* arg, ...); +int execle(const char* path, const char* arg, ...); +int execv(const char* path, char* const argv[]); +int execvp(const char* file, char* const argv[]); +int execvpe(const char* file, char* const argv[], char* const envp[]); +``` + +例如,禁止如下使用方式: + +```c +std::string cmd = GetDirNameFromRemote(); +execl("/bin/sh", "sh", "-c", cmd.c_str(), nullptr); +``` + +可以使用库函数,或者可以通过编写少量的代码来避免使用system函数调用命令,如`mkdir()`函数可以实现`mkdir`命令的功能。 +如下代码中,应该避免使用`cat`命令实现文件内容复制的功能。 + +```c +int WriteDataToFile(const char* dstFile, const char* srcFile) +{ + ... // 入参的合法性校验 + std::ostringstream oss; + oss << "cat " << srcFile << " > " << dstFile; + + std::string cmd{oss.str()}; + system(cmd.c_str()); + ... +} +``` + +**【正例】** + +如下代码中,通过少量的代码来实现。如下代码实现了文件复制的功能,避免了对`cat`或`cp`命令的调用。需要注意的是,为简化描述,下面代码未考虑信号中断的影响。 + +```cpp +bool WriteDataToFile(const std::string& dstFilePath, const std::string& srcFilePath) +{ + const int bufferSize = 1024; + std::vector buffer (bufferSize + 1, 0); + + std::ifstream srcFile(srcFilePath, std::ios::binary); + std::ofstream dstFile(dstFilePath, std::ios::binary); + + if (!dstFile || !dstFile) { + ... // 错误处理 + return false; + } + + while (true) { + // 从srcFile读取内容分块 + srcFile.read(buffer.data(), bufferSize); + std::streamsize size = srcFile ? bufferSize : srcFile.gcount(); + + // 写入分块内容到dstFile + if (size > 0 && !dstFile.write(buffer.data(), size)) { + ... // 错误处理 + break; + } + + if (!srcFile) { + ... // 检查错误:当不是eof()时记录错误 + break; + } + } + // srcFile 和 dstFile 在退出作用域时会自动被关闭 + return true; +} +``` + +可以通过库函数简单实现的功能(如上例),需要避免调用命令处理器来执行外部命令。 +如果确实需要调用单个命令,应使用exec*函数来实现参数化调用,并对调用的命令实施白名单管理。同时应避免使用execlp、execvp、execvpe函数,因为这几个函数依赖外部的PATH环境变量。 +此时,外部输入的fileName仅作为some_tool命令的参数,没有命令注入的风险。 + +```cpp +pid_t pid; +char* const envp[] = {nullptr}; +... +std::string fileName = GetDirNameFromRemote(); +... +pid = fork(); +if (pid < 0) { + ... +} else if (pid == 0) { + // 使用some_tool对指定文件进行加工 + execle("/bin/some_tool", "some_tool", fileName.c_str(), nullptr, envp); + _Exit(-1); +} +... +int status; +waitpid(pid, &status, 0); +std::ofstream ofs(fileName, std::ios::in); +... +``` + +在必须使用system等命令解析器执行命令时,应对输入的命令字符串基于合理的白名单检查,避免命令注入。 + +```cpp +std::string cmd = GetCmdFromRemote(); + +// 使用白名单检查命令是否合法,仅允许"some_tool_a", "some_tool_b"命令,外部无法随意控制 +if (!IsValidCmd(cmd.c_str())) { + ... // 错误处理 +} +system(cmd.c_str()); +... +``` + +**【影响】** + +- 如果传递给system()、popen()或其他命令处理函数的命令字符串是外部可控的,则攻击者可能会以被攻击进程的权限执行系统上存在的任意命令。 +- 如果动态库文件是外部可控的,则攻击者可替换该库文件,在某些情况下可以造成任意代码执行漏洞。 + +# 其他C语言编程规范 + +## 禁止通过对数组类型的函数参数变量进行sizeof来获取数组大小 + +**【描述】** + +使用sizeof操作符求其操作数的大小(以字节为单位),其操作数可以是一个表达式或者加上括号的类型名称,例如:`sizeof(int)`或`sizeof(int *)`。 +参考C11标准6.5.3.4中的脚注103: + +> 当将sizeof应用于具有数组或函数类型的参数时,sizeof操作符将得出调整后的(指针)类型的大小。 + +函数参数列表中声明为数组的参数会被调整为相应类型的指针。例如:`void Func(int inArray[LEN])`函数参数列表中的inArray虽然被声明为数组,但是实际上会被调整为指向int类型的指针,即调整为`void Func(int *inArray)`。 +在这个函数内使用`sizeof(inArray)`等同于`sizeof(int *)`,得到的结果通常与预期不相符。例如:在IA-32架构上,`sizeof(inArray)` 的值是 4,并不是inArray数组的大小。 + +**【反例】** +如下代码示例中,函数ArrayInit的功能是初始化数组元素。该函数有一个声明为`int inArray[]`的参数,被调用时传递了一个长度为256的int类型数组data。 +ArrayInit函数实现中使用`sizeof(inArray) / sizeof(inArray[0])`方法来计算入参数组中元素的数量。 +但由于inArray是函数参数,所以具有指针类型,结果,`sizeof(inArray)`等同于`sizeof(int *)`。 +无论传递给ArrayInit函数的数组实际长度如何,表达式的`sizeof(inArray) / sizeof(inArray[0])`计算结果均为1,与预期不符。 + +```c +#define DATA_LEN 256 +void ArrayInit(int inArray[]) +{ + // 不符合:这里使用sizeof(inArray)计算数组大小 + for (size_t i = 0; i < sizeof(inArray) / sizeof(inArray[0]); i++) { + ... + } +} + +void FunctionData(void) +{ + int data[DATA_LEN]; + + ... + ArrayInit(data); // 调用ArrayInit函数初始化数组data数据 + ... +} +``` + +**【正例】** +如下代码示例中,修改函数定义,添加数组长度参数,并在调用处正确传入数组长度。 + +```c +#define DATA_LEN 256 +// 函数说明:入参len是入参inArray数组的长度 +void ArrayInit(int inArray[], size_t len) +{ + for (size_t i = 0; i < len; i++) { + ... + } +} + +void FunctionData(void) +{ + int data[DATA_LEN]; + + ArrayInit(data, sizeof(data) / sizeof(data[0])); + ... +} +``` + +**【反例】** +如下代码示例中,`sizeof(inArray)`不等于`ARRAY_MAX_LEN * sizeof(int)`,因为将sizeof操作符应用于声明为具有数组类型的参数时,即使参数声明指定了长度,也会被调整为指针,`sizeof(inArray)`等同于 `sizeof(int *)`: + +```c +#define ARRAY_MAX_LEN 256 + +void ArrayInit(int inArray[ARRAY_MAX_LEN]) +{ + // 不符合:sizeof(inArray),得到的长度是指针的大小,不是数组的长度,和预期不符。 + for (size_t i = 0; i < sizeof(inArray) / sizeof(inArray[0]); i++) { + ... + } +} + +int main(void) +{ + int masterArray[ARRAY_MAX_LEN]; + + ... + ArrayInit(masterArray); + + return 0; +} +``` + +**【正例】** +如下代码示例中,使用入参len表示指定数组的长度: + +```c +#define ARRAY_MAX_LEN 256 + +// 函数说明:入参len是入参数组的长度 +void ArrayInit(int inArray[], size_t len) +{ + for (size_t i = 0; i < len; i++) { + ... + } +} + +int main(void) +{ + int masterArray[ARRAY_MAX_LEN]; + + ArrayInit(masterArray, ARRAY_MAX_LEN); + ... + + return 0; +} +``` + +## 禁止通过对指针变量进行sizeof操作来获取数组大小 + +**描述】** +将指针当做数组进行sizeof操作时,会导致实际的执行结果与预期不符。例如:变量定义 `char *p = array`,其中array的定义为`char array[LEN]`,表达式`sizeof(p)`得到的结果与 `sizeof(char *)`相同,并非array的长度。 + +**【反例】** +如下代码示例中,buffer和path分别是指针和数组,程序员想对这2个内存进行清0操作,但由于程序员的疏忽,将内存大小误写成了`sizeof(buffer)`,与预期不符。 + +```c +char path[MAX_PATH]; +char *buffer = (char *)malloc(SIZE); +... + +... +memset(path, 0, sizeof(path)); + +// sizeof与预期不符,其结果为指针本身的大小而不是缓冲区大小 +memset(buffer, 0, sizeof(buffer)); +``` + +**【正例】** +如下代码示例中,将`sizeof(buffer)`修改为申请的缓冲区大小: + +```c +char path[MAX_PATH]; +char *buffer = (char *)malloc(SIZE); +... + +... +memset(path, 0, sizeof(path)); +memset(buffer, 0, SIZE); // 使用申请的缓冲区大小 +``` + +## 禁止直接使用外部数据拼接SQL命令 + +**【描述】** +SQL注入是指SQL查询被恶意更改成一个与程序预期完全不同的查询。执行更改后的查询可能会导致信息泄露或者数据被篡改。而SQL注入的根源就是使用外部数据来拼接SQL语句。C/C++语言中常见的使用外部数据拼接SQL语句的场景有(包括但不局限于): + +- 连接MySQL时调用mysql_query(),Execute()时的入参 +- 连接SQL Server时调用db-library驱动的dbsqlexec()的入参 +- 调用ODBC驱动的SQLprepare()连接数据库时的SQL语句的参数 +- C++程序调用OTL类库中的otl_stream(),otl_column_desc()时的入参 +- C++程序连接Oracle数据库时调用ExecuteWithResSQL()的入参 + +防止SQL注入的方法主要有以下几种: + +- 参数化查询(通常也叫作预处理语句):参数化查询是一种简单有效的防止SQL注入的查询方式,应该被优先考虑使用。支持的数据库有MySQL,Oracle(OCI)。 +- 参数化查询(通过ODBC驱动):支持ODBC驱动参数化查询的数据库有Oracle、SQLServer、PostgreSQL和GaussDB。 +- 对外部数据进行校验(对于每个引入的外部数据推荐“白名单”校验)。 +- 对外部数据中的SQL特殊字符进行转义。 + +**【反例】** +下列代码拼接用户输入,没有进行输入检查,存在SQL注入风险: + +```c +char name[NAME_MAX]; +char sqlStatements[SQL_CMD_MAX]; +int ret = GetUserInput(name, NAME_MAX); +... +ret = sprintf(sqlStatements, + "SELECT childinfo FROM children WHERE name= ‘%s’", + name); +... +ret = mysql_query(&myConnection, sqlStatements); +... +``` + +**【正例】** +使用预处理语句进行参数化查询可以防御SQL注入攻击: + +```c +char name[NAME_MAX]; +... +MYSQL_STMT *stmt = mysql_stmt_init(myConnection); +char *query = "SELECT childinfo FROM children WHERE name= ?"; +if (mysql_stmt_prepare(stmt, query, strlen(query))) { + ... +} +int ret = GetUserInput(name, NAME_MAX); +... +MYSQL_BIND params[1]; +(void)memset(params, 0, sizeof(params)); +... +params[0].bufferType = MYSQL_TYPE_STRING; +params[0].buffer = (char *)name; +params[0].bufferLength = strlen(name); +params[0].isNull = 0; + +bool isCompleted = mysql_stmt_bind_param(stmt, params); +... +ret = mysql_stmt_execute(stmt); +... +``` + +**【影响】** + +如果拼接SQL语句的字符串是外部可控的,则攻击者可以通过注入特定的字符串欺骗程序执行恶意的SQL命令,造成信息泄露、权限绕过、数据被篡改等问题。 + +## 内存中的敏感信息使用完毕后立即清0 + +**【描述】** +内存中的口令、密钥等敏感信息使用完毕后立即清0,避免被攻击者获取或者无意间泄露给低权限用户。这里所说的内存包括但不限于: + +- 动态分配的内存 +- 静态分配的内存 +- 自动分配(堆栈)内存 +- 内存缓存 +- 磁盘缓存 + +**【反例】** +通常内存在释放前不需要清除内存数据,因为这样在运行时会增加额外开销,所以在这段内存被释放之后,之前的数据还是会保留在其中。如果这段内存中的数据包含敏感信息,则可能会意外泄露敏感信息。为了防止敏感信息泄露,必须先清除内存中的敏感信息,然后再释放。 +在如下代码示例中,存储在所引用的动态内存中的敏感信息secret被复制到新动态分配的缓冲区newSecret,最终通过free()释放。因为释放前未清除这块内存数据,这块内存可能被重新分配到程序的另一部分,之前存储在newSecret中的敏感信息可能会无意中被泄露。 + +```c +char *secret = NULL; +/* + * 假设 secret 指向敏感信息,敏感信息的内容是长度小于SIZE_MAX个字符, + * 并且以null终止的字节字符串 + */ + +size_t size = strlen(secret); +char *newSecret = NULL; +newSecret = (char *)malloc(size + 1); +if (newSecret == NULL) { + ... // 错误处理 +} else { + errno_t ret = strcpy(newSecret, secret); + ... // 处理 ret + + ... // 处理 newSecret... + + free(newSecret); + newSecret = NULL; +} +... +``` + +**【正例】** +如下代码示例中,为了防止信息泄露,应先清除包含敏感信息的动态内存(用’\0’字符填充空间),然后再释放它。 + +```c +char *secret = NULL; +/* + * 假设 secret 指向敏感信息,敏感信息的内容是长度小于SIZE_MAX个字符, + * 并且以null终止的字节字符串 + */ +size_t size = strlen(secret); +char *newSecret = NULL; +newSecret = (char *)malloc(size + 1); +if (newSecret == NULL) { + ... // 错误处理 +} else { + errno_t ret = strcpy(newSecret, secret); + ... // 处理 ret + + ... // 处理 newSecret... + + (void)memset(newSecret, 0, size + 1); + free(newSecret); + newSecret = NULL; +} +... +``` + +**【正例】** +下面是另外一个涉及敏感信息清理的场景,在代码获取到密码后,将密码保存到password中,进行密码验证,使用完毕后,通过`memset()`函数对password清0。 + +```c +int Foo(void) +{ + char password[MAX_PWD_LEN]; + if (!GetPassword(password, sizeof(password))) { + ... + } + if (!VerifyPassword(password)) { + ... + } + ... + (void)memset(password, 0, sizeof(password)); + ... +} +``` + +要特别**注意**:对敏感信息清理的时候要同时防止因编译器优化而使清理代码无效。 + +例如,下列代码使用了可能被编译器优化掉的语句。 + +```c +int SecureLogin(void) +{ + char pwd[PWD_SIZE]; + if (RetrievePassword(pwd, sizeof(pwd))) { + ... // 口令检查及其他处理 + } + memset(pwd, 0, sizeof(pwd)); // 编译器优化有可能会使该语句失效 + ... +} +``` + +某些编译器在优化时候不会执行它认为不会改变程序执行结果的代码,因此memset()操作会被优化掉。 + +如果编译器支持#pragma指令,那么可以使用该指令指示编译器不作优化。 + +```c +void SecureLogin(void) +{ + char pwd[PWD_SIZE]; + if (RetrievePassword(pwd, sizeof(pwd))) { + ... // 口令检查及其他处理 + } + #pragma optimize("", off) + // 清除内存 + ... + #pragma optimize("", on) + ... +} +``` + +**【影响】** + +未及时清理敏感信息,可能导致信息泄露。 + +## 创建文件时必须显式指定合适的文件访问权限 + +**【描述】** +创建文件时,如果不显式指定合适访问权限,可能会让未经授权的用户访问该文件,造成信息泄露,文件数据被篡改,文件中被注入恶意代码等风险。 + +虽然文件的访问权限也依赖于文件系统,但是当前许多文件创建函数(例如POSIX open函数)都具有设置(或影响)文件访问权限的功能,所以当使用这些函数创建文件时,必须显式指定合适的文件访问权限,以防止意外访问。 + +**【反例】** +使用POSIX open()函数创建文件但未显示指定该文件的访问权限,可能会导致文件创建时具有过高的访问权限。这可能会导致漏洞(例如CVE-2006-1174)。 + +```c +void Foo(void) +{ + int fd = -1; + char *filename = NULL; + + ... // 初始化 filename + + fd = open(filename, O_CREAT | O_WRONLY); // 没有显式指定访问权限 + if (fd == -1) { + ... // 错误处理 + } + ... +} +``` + +**【正例】** +应该在open的第三个参数中显式指定新创建文件的访问权限。可以根据文件实际的应用情况设置何种访问权限。 + +```c +void Foo(void) +{ + int fd = -1; + char *filename = NULL; + + ... // 初始化 filename 和指定其访问权限 + + // 此处根据文件实际需要,显式指定其访问权限 + int fd = open(filename, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR); + if (fd == -1) { + ... // 错误处理 + } + ... +} +``` + +**【影响】** + +创建访问权限弱的文件,可能会导致对这些文件的非法访问。 + +## 使用文件路径前必须进行规范化并校验 + +**【描述】** +当文件路径来自外部数据时,必须对其做合法性校验,如果不校验,可能造成系统文件的被任意访问。但是禁止直接对其进行校验,正确做法是在校验之前必须对其进行路径规范化处理。这是因为同一个文件可以通过多种形式的路径来描述和引用,例如既可以是绝对路径,也可以是相对路径;而且路径名、目录名和文件名可能包含使校验变得困难和不准确的字符(如:“.”、“..”)。此外,文件还可以是符号链接,这进一步模糊了文件的实际位置或标识,增加了校验的难度和校验准确性。所以必须先将文件路径规范化,从而更容易校验其路径、目录或文件名,增加校验准确性。 + +因为规范化机制在不同的操作系统和文件系统之间可能有所不同,所以最好使用符合当前系统特性的规范化机制。 + +一个简单的案例说明如下: + +```c +当文件路径来自外部数据时,需要先将文件路径规范化,如果没有作规范化处理,攻击者就有机会通过恶意构造文件路径进行文件的越权访问。 +例如,攻击者可以构造“../../../etc/passwd”的方式进行任意文件访问。 +``` + +**【反例】** +在此错误的示例中,inputFilename包含一个源于受污染源的文件名,并且该文件名已打开以进行写入。在使用此文件名操作之前,应该对其进行验证,以确保它引用的是预期的有效文件。 +不幸的是,inputFilename引用的文件名可能包含特殊字符,例如目录字符,这使验证变得困难,甚至不可能。而且,inputFilename中可能包含可以指向任意文件路径的符号链接,即使该文件名通过了验证,也会导致该文件名是无效的。 +这种场景下,对文件名的直接验证即使被执行也是得不到预期的结果,对fopen()的调用可能会导致访问一个意外的文件。 + +```c +... + +if (!verify_file(inputFilename) { // 没有对inputFilename做规范化,直接做校验 + ... // 错误处理 +} + +if (fopen(inputFilename, "w") == NULL) { + ... // 错误处理 +} + +... +``` + +**【正例】** +规范化文件名是具有一定难度的,因为这需要了解底层文件系统。 +POSIX realpath()函数可以帮助将路径名转换为规范形式。参考信息技术标准-POSIX®,基本规范第7期[IEEE std 1003.1:2013]: + +- 该realpath()函数应从所指向的路径名派生一个filename的绝对路径名,两者指向同一文件,绝对路径其文件名不涉及“ .”,“ ..”或符号链接。 + 在规范化路径之后,还必须执行进一步的验证,例如确保两个连续的斜杠或特殊文件不会出现在文件名中。有关如何执行路径名解析的更多详细信息,请参见[IEEE Std 1003.1: 2013]第4.12节“路径名解析”。 + 使用realpath()函数有许多需要注意的地方。 + 在了解了以上原理之后,对上面的错误代码示例,我们采用如下解决方案: + +```c +char *realpathRes = NULL; + +... + +// 在校验之前,先对inputFilename做规范化处理 +realpathRes = realpath(inputFilename, NULL); +if (realpathRes == NULL) { + ... // 规范化的错误处理 +} + +// 规范化以后对路径进行校验 +if (!verify_file(realpathRes) { + ... // 校验的错误处理 +} + +// 使用 +if (fopen(realpathRes, "w") == NULL) { + ... // 实际操作的错误处理 +} + +... + +free(realpathRes); +realpathRes = NULL; +... +``` + +**【正例】** +根据我们的实际场景,我们还可以采用的第二套解决方案,说明如下: +如果`PATH_MAX`被定义为 limits.h 中的一个常量,那么使用非空的`resolved_path`调用realpath()也是安全的。 +在本例中realpath()函数期望`resolved_path`引用一个字符数组,该字符数组足够大,可以容纳规范化的路径。 +如果定义了PATH_MAX,则分配一个大小为`PATH_MAX`的缓冲区来保存realpath()的结果。正确代码示例如下: + +```c +char *realpathRes = NULL; +char *canonicalFilename = NULL; +size_t pathSize = 0; + +... + +pathSize = (size_t)PATH_MAX; + +if (VerifyPathSize(pathSize) == true) { + canonicalFilename = (char *)malloc(pathSize); + + if (canonicalFilename == NULL) { + ... // 错误处理 + } + + realpathRes = realpath(inputFilename, canonicalFilename); +} + +if (realpathRes == NULL) { + ... // 错误处理 +} + +if (VerifyFile(realpathRes) == false) { + ... // 错误处理 +} + +if (fopen(realpathRes, "w") == NULL ) { + ... // 错误处理 +} + +... + +free(canonicalFilename); +canonicalFilename = NULL; +... +``` + +**【反例】** +下面的代码场景是从外部获取到文件名称,拼接成文件路径后,直接对文件内容进行读取,导致攻击者可以读取到任意文件的内容: + +```c +char *filename = GetMsgFromRemote(); +... +int ret = sprintf(untrustPath, "/tmp/%s", filename); +... +char *text = ReadFileContent(untrustPath); +``` + +**【正例】** +正确的做法是,对路径进行规范化后,再判断路径是否是本程序所认为的合法的路径: + +```c +char *filename = GetMsgFromRemote(); +... +sprintf(untrustPath, "/tmp/%s", filename); +char path[PATH_MAX]; +if (realpath(untrustPath, path) == NULL) { + ... // 处理错误 +} +if (!IsValidPath(path)) { // 检查文件的位置是否正确 + ... // 处理错误 +} +char *text = ReadFileContent(path); +``` + +**【例外】** + +运行于控制台的命令行程序,通过控制台手工输入文件路径,可以作为本条款例外。 + +```c +int main(int argc, char **argv) +{ + int fd = -1; + + if (argc == 2) { + fd = open(argv[1], O_RDONLY); + ... + } + + ... + return 0; +} +``` + +**【影响】** + +未对不可信的文件路径进行规范化和校验,可能造成对任意文件的访问。 + +## 不要在共享目录中创建临时文件 + +**【描述】** +共享目录是指其它非特权用户可以访问的目录。程序的临时文件应当是程序自身独享的,任何将自身临时文件置于共享目录的做法,将导致其他共享用户获得该程序的额外信息,产生信息泄露。因此,不要在任何共享目录创建仅由程序自身使用的临时文件。 + +临时文件通常用于辅助保存不能驻留在内存中的数据或存储临时的数据,也可用作进程间通信的一种手段(通过文件系统传输数据)。例如,一个进程在共享目录中创建一个临时文件,该文件名可能使用了众所周知的名称或者一个临时的名称,然后就可以通过该文件在进程间共享信息。这种通过在共享目录中创建临时文件的方法实现进程间共享的做法很危险,因为共享目录中的这些文件很容易被攻击者劫持或操纵。这里有几种缓解策略: + +1. 使用其他低级IPC(进程间通信)机制,例如套接字或共享内存。 +2. 使用更高级别的IPC机制,例如远程过程调用。 +3. 使用仅能由程序本身访问的安全目录(多线程/进程下注意防止条件竞争)。 + +同时,下面列出了几项临时文件创建使用的方法,产品根据具体场景执行以下一项或者几项,同时产品也可以自定义合适的方法。 + +1. 文件必须具有合适的权限,只有符合权限的用户才能访问 +2. 创建的文件名是唯一的、或不可预测的 +3. 仅当文件不存在时才创建打开(原子创建打开) +4. 使用独占访问打开,避免竞争条件 +5. 在程序退出之前移除 + +同时也需要注意到,当某个目录被开放读/写权限给多个用户或者一组用户时,该共享目录潜在的安全风险远远大于访问该目录中临时文件这个功能的本身。 + +在共享目录中创建临时文件很容易受到威胁。例如,用于本地挂载的文件系统的代码在与远程挂载的文件系统一起共享使用时可能会受到攻击。安全的解决方案是不要在共享目录中创建临时文件。 + +**【反例】** +如下代码示例,程序在系统的共享目录/tmp下创建临时文件来保存临时数据,且文件名是硬编码的。 +由于文件名是硬编码的,因此是可预测的,攻击者只需用符号链接替换文件,然后链接所引用的目标文件就会被打开并写入新内容。 + +```c +void ProcData(const char *filename) +{ + FILE *fp = fopen(filename, "wb+"); + if (fp == NULL) { + ... // 错误处理 + } + + ... // 写文件 + + fclose(fp); +} + +int main(void) +{ + // 不符合:1.在系统共享目录中创建临时文件;2.临时文件名硬编码 + char *pFile = "/tmp/data"; + ... + + ProcData(pFile); + + ... + return 0; +} +``` + +**【正确案例】** + +```c +不应在该目录下创建仅由程序自身使用的临时文件。 +``` + +**【影响】** + +不安全的创建临时文件,可能导致文件非法访问,并造成本地系统上的权限提升。 + +## 不要在信号处理函数中访问共享对象 + +**【描述】** +如果在信号处理程序中访问和修改共享对象,可能会造成竞争条件,使数据处于不确定的状态。 +这条规则有两个不适用的场景(参考C11标准5.1.2.3第5段): + +- 读写不需要加锁的原子对象; +- 读写volatile sig_atomic_t类型的对象,因为具有volatile sig_atomic_t类型的对象即使在出现异步中断的时候也可以作为一个原子实体访问,是异步安全的。 + +**【反例】** +在这个信号处理过程中,程序打算将`g_msg`作为共享对象,当产生SIGINT信号时更新共享对象的内容,但是该`g_msg`变量类型不是`volatile sig_atomic_t`,所以不是异步安全的。 + +```c +#define MAX_MSG_SIZE 32 +static char g_msgBuf[MAX_MSG_SIZE] = {0}; +static char *g_msg = g_msgBuf; + +void SignalHandler(int signum) +{ + // 下面代码操作g_msg不合规,因为不是异步安全的 + (void)memset(g_msg,0, MAX_MSG_SIZE); + errno_t ret = strcpy(g_msg, "signal SIGINT received."); + ... // 处理 ret +} + +int main(void) +{ + errno_t ret = strcpy(g_msg, "No msg yet."); // 初始化消息内容 + ... // 处理 ret + + signal(SIGINT, SignalHandler); // 设置SIGINT信号对应的处理函数 + + ... // 程序主循环代码 + + return 0; +} +``` + +**【正例】** +如下代码示例中,在信号处理函数中仅将`volatile sig_atomic_t`类型作为共享对象使用。 + +```c +#define MAX_MSG_SIZE 32 +volatile sig_atomic_t g_sigFlag = 0; + +void SignalHandler(int signum) +{ + g_sigFlag = 1; // 符合 +} + +int main(void) +{ + signal(SIGINT, SignalHandler); + char msgBuf[MAX_MSG_SIZE]; + errno_t ret = strcpy(msgBuf, "No msg yet."); // 初始化消息内容 + ... // 处理 ret + + ... // 程序主循环代码 + + if (g_sigFlag == 1) { // 在退出主循环之后,根据g_sigFlag状态再刷新消息内容 + ret = strcpy(msgBuf, "signal SIGINT received."); + ... // 处理 ret + } + + return 0; +} +``` + +**【影响】** + +在信号处理程序中访问或修改共享对象,可能造成以不一致的状态访问数据。 + +## 禁用rand函数产生用于安全用途的伪随机数 + +**【描述】** +C语言标准库rand()函数生成的是伪随机数,所以不能保证其产生的随机数序列质量。根据C11标准,rand()函数产生的随机数范围是`[0, RAND_MAX(0x7FFF)]`,因为范围相对较短,所以这些数字可以被预测。 +所以禁止使用rand()函数产生的随机数用于安全用途,必须使用安全的随机数产生方式。 + +典型的安全用途场景包括(但不限于)以下几种: + +- 会话标识SessionID的生成; +- 挑战算法中的随机数生成; +- 验证码的随机数生成; +- 用于密码算法用途(例如用于生成IV、盐值、密钥等)的随机数生成。 + +**【反例】** +程序员期望生成一个唯一的不可被猜测的HTTP会话ID,但该ID是通过调用rand()函数产生的数字随机数,它的ID是可猜测的,并且随机性有限。 + +**【影响】** + +使用rand()函数可能造成可预测的随机数。 + +## 禁止在发布版本中输出对象或函数的地址 + +**【描述】** +禁止在发布版本中输出对象或函数的地址,如:将变量或函数的地址输出到客户端、日志、串口中。 + +当攻击者实施高级攻击时,通常需要先获取目标程序中的内存地址(如变量地址、函数地址等),再通过修改指定内存的内容,达到攻击目的。 +如果程序中主动输出对象或函数的地址,则为攻击者提供了便利条件,可以根据这些地址以及偏移量计算出其他对象或函数的地址,并实施攻击。 +另外,由于内存地址泄露,也会造成地址空间随机化的保护功能失效。 + +**【反例】** +如下代码中,使用%p格式将指针指向的地址记录到日志中。 + +```c +int Encode(unsigned char *in, size_t inSize, unsigned char *out, size_t maxSize) +{ + ... + Log("in=%p, in size=%zu, out=%p, max size=%zu\n", in, inSize, out, maxSize); + ... +} +``` + +备注:这里仅用%p打印指针作为示例,代码中将指针转换为整数再打印也存在同样的风险。 + +**【正例】** +如下代码中,删除打印地址的代码。 + +```c +int Encode(unsigned char *in, size_t inSize, unsigned char *out, size_t maxSize) +{ + ... + Log("in size=%zu, max size=%zu\n", inSize, maxSize); + ... +} +``` + +**【例外】** +当程序崩溃退出时,在记录崩溃的异常信息中可以输出内存地址等信息。 + +**【影响】** + +内存地址信息泄露,为攻击者实施攻击提供有利信息,可能造成地址空间随机化防护失效。 + +## 禁止代码中包含公网地址 + +**【描述】** + +代码或脚本中包含用户不可见,不可知的公网地址,可能会引起客户质疑。 + +对产品发布的软件(包含软件包/补丁包)中包含的公网地址(包括公网IP地址、公网URL地址/域名、邮箱地址)要求如下: +1、禁止包含用户界面不可见、或产品资料未描述的未公开的公网地址。 +2、已公开的公网地址禁止写在代码或者脚本中,可以存储在配置文件或数据库中。 + +对于开源/第三方软件自带的公网地址必须至少满足上述第1条公开性要求。 + +**【例外】** + +- 对于标准协议中必须指定公网地址的场景可例外,如soap协议中函数的命名空间必须指定的一个组装的公网URL、http页面中包含w3.org网址等。 + +# 内核安全编程 + +## 内核mmap接口实现中,确保对映射起始地址和大小进行合法性校验 + +**【描述】** + +**说明:**内核 mmap接口中,经常使用remap_pfn_range()函数将设备物理内存映射到用户进程空间。如果映射起始地址等参数由用户态控制并缺少合法性校验,将导致用户态可通过映射读写任意内核地址。如果攻击者精心构造传入参数,甚至可在内核中执行任意代码。 + +**【错误代码示例】** + +如下代码在使用remap_pfn_range()进行内存映射时,未对用户可控的映射起始地址和空间大小进行合法性校验,可导致内核崩溃或任意代码执行。 + +```c +static int incorrect_mmap(struct file *file, struct vm_area_struct *vma) +{ + unsigned long size; + size = vma->vm_end - vma->vm_start; + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); + //错误:未对映射起始地址、空间大小做合法性校验 + if (remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff, size, vma->vm_page_prot)) { + err_log("%s, remap_pfn_range fail", __func__); + return EFAULT; + } else { + vma->vm_flags &= ~VM_IO; + } + + return EOK; +} +``` + +**【正确代码示例】** + +增加对映射起始地址等参数的合法性校验。 + +```c +static int correct_mmap(struct file *file, struct vm_area_struct *vma) +{ + unsigned long size; + size = vma->vm_end - vma->vm_start; + //修改:添加校验函数,验证映射起始地址、空间大小是否合法 + if (!valid_mmap_phys_addr_range(vma->vm_pgoff, size)) { + return EINVAL; + } + + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); + if (remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff, size, vma->vm_page_prot)) { + err_log( "%s, remap_pfn_range fail ", __func__); + return EFAULT; + } else { + vma->vm_flags &= ~VM_IO; + } + + return EOK; +} +``` + +## 内核程序中必须使用内核专用函数读写用户态缓冲区 + +**【描述】** + +用户态与内核态之间进行数据交换时,如果在内核中不加任何校验(如校验地址范围、空指针)而直接引用用户态传入指针,当用户态传入非法指针时,可导致内核崩溃、任意地址读写等问题。因此,应当禁止使用memcpy()、sprintf()等危险函数,而是使用内核提供的专用函数:copy_from_user()、copy_to_user()、put_user()和get_user()来读写用户态缓冲区,这些函数内部添加了入参校验功能。 + +所有禁用函数列表为:memcpy()、bcopy()、memmove()、strcpy()、strncpy()、strcat()、strncat()、sprintf()、vsprintf()、snprintf()、vsnprintf()、sscanf()、vsscanf()。 + +**【错误代码示例】** + +内核态直接使用用户态传入的buf指针作为snprintf()的参数,当buf为NULL时,可导致内核崩溃。 + +```c +ssize_t incorrect_show(struct file *file, char__user *buf, size_t size, loff_t *data) +{ + // 错误:直接引用用户态传入指针,如果buf为NULL,则空指针异常导致内核崩溃 + return snprintf(buf, size, "%ld\n", debug_level); +} +``` + +**【正确代码示例】** + +使用copy_to_user()函数代替snprintf()。 + +```c +ssize_t correct_show(struct file *file, char __user *buf, size_t size, loff_t *data) +{ + int ret = 0; + char level_str[MAX_STR_LEN] = {0}; + snprintf(level_str, MAX_STR_LEN, "%ld \n", debug_level); + if(strlen(level_str) >= size) { + return EFAULT; + } + + // 修改:使用专用函数copy_to_user()将数据写入到用户态buf,并注意防止缓冲区溢出 + ret = copy_to_user(buf, level_str, strlen(level_str)+1); + return ret; +} +``` + +**【错误代码示例】** + +内核态直接使用用户态传入的指针user_buf作为数据源进行memcpy()操作,当user_buf为NULL时,可导致内核崩溃。 + +```c +size_t incorrect_write(struct file *file, const char __user *user_buf, size_t count, loff_t *ppos) +{ + ... + char buf [128] = {0}; + int buf_size = 0; + buf_size = min(count, (sizeof(buf)-1)); + // 错误:直接引用用户态传入指针,如果user_buf为NULL,则可导致内核崩溃 + (void)memcpy(buf, user_buf, buf_size); + ... +} +``` + +**【正确代码示例】** + +使用copy_from_user()函数代替memcpy()。 + +```c +ssize_t correct_write(struct file *file, const char __user *user_buf, size_t count, loff_t *ppos) +{ + ... + char buf[128] = {0}; + int buf_size = 0; + + buf_size = min(count, (sizeof(buf)-1)); + // 修改:使用专用函数copy_from_user()将数据写入到内核态buf,并注意防止缓冲区溢出 + if (copy_from_user(buf, user_buf, buf_size)) { + return EFAULT; + } + + ... +} +``` + +## 必须对copy_from_user()拷贝长度进行校验,防止缓冲区溢出 + +**说明:**内核态从用户态拷贝数据时通常使用copy_from_user()函数,如果未对拷贝长度做校验或者校验不当,会造成内核缓冲区溢出,导致内核panic或提权。 + +**【错误代码示例】** + +未校验拷贝长度。 + +```c +static long gser_ioctl(struct file *fp, unsigned cmd, unsigned long arg) +{ + char smd_write_buf[GSERIAL_BUF_LEN]; + switch (cmd) + { + case GSERIAL_SMD_WRITE: + if (copy_from_user(&smd_write_arg, argp, sizeof(smd_write_arg))) {...} + // 错误:拷贝长度参数smd_write_arg.size由用户输入,未校验 + copy_from_user(smd_write_buf, smd_write_arg.buf, smd_write_arg.size); + ... + } +} +``` + +**【正确代码示例】** + +添加长度校验。 + +```c +static long gser_ioctl(struct file *fp, unsigned cmd, unsigned long arg) +{ + char smd_write_buf[GSERIAL_BUF_LEN]; + switch (cmd) + { + case GSERIAL_SMD_WRITE: + if (copy_from_user(&smd_write_arg, argp, sizeof(smd_write_arg))){...} + // 修改:添加校验 + if (smd_write_arg.size >= GSERIAL_BUF_LEN) {......} + copy_from_user(smd_write_buf, smd_write_arg.buf, smd_write_arg.size); + ... + } +} +``` + +## 必须对copy_to_user()拷贝的数据进行初始化,防止信息泄漏 + +**【描述】** + +**说明:**内核态使用copy_to_user()向用户态拷贝数据时,当数据未完全初始化(如结构体成员未赋值、字节对齐引起的内存空洞等),会导致栈上指针等敏感信息泄漏。攻击者可利用绕过kaslr等安全机制。 + +**【错误代码示例】** + +未完全初始化数据结构成员。 + +```c +static long rmnet_ctrl_ioctl(struct file *fp, unsigned cmd, unsigned long arg) +{ + struct ep_info info; + switch (cmd) { + case FRMNET_CTRL_EP_LOOKUP: + info.ph_ep_info.ep_type = DATA_EP_TYPE_HSUSB; + info.ipa_ep_pair.cons_pipe_num = port->ipa_cons_idx; + info.ipa_ep_pair.prod_pipe_num = port->ipa_prod_idx; + // 错误: info结构体有4个成员,未全部赋值 + ret = copy_to_user((void __user *)arg, &info, sizeof(info)); + ... + } +} +``` + +**【正确代码示例】** + +全部进行初始化。 + +```c +static long rmnet_ctrl_ioctl(struct file *fp, unsigned cmd, unsigned long arg) +{ + struct ep_info info; + // 修改:使用memset初始化缓冲区,保证不存在因字节对齐或未赋值导致的内存空洞 + (void)memset(&info, '0', sizeof(ep_info)); + switch (cmd) { + case FRMNET_CTRL_EP_LOOKUP: + info.ph_ep_info.ep_type = DATA_EP_TYPE_HSUSB; + info.ipa_ep_pair.cons_pipe_num = port->ipa_cons_idx; + info.ipa_ep_pair.prod_pipe_num = port->ipa_prod_idx; + ret = copy_to_user((void __user *)arg, &info, sizeof(info)); + ... + } +} +``` + +## 禁止在异常处理中使用BUG_ON宏,避免造成内核panic + +**【描述】** + +BUG_ON宏会调用内核的panic()函数,打印错误信息并主动崩溃系统,在正常逻辑处理中(如ioctl接口的cmd参数不识别)不应当使系统崩溃,禁止在此类异常处理场景中使用BUG_ON宏,推荐使用WARN_ON宏。 + +**【错误代码示例】** + +正常流程中使用了BUG_ON宏 + +```c +/ * 判断Q6侧设置定时器是否繁忙,1-忙,0-不忙 */ +static unsigned int is_modem_set_timer_busy(special_timer *smem_ptr) +{ + int i = 0; + if (smem_ptr == NULL) { + printk(KERN_EMERG"%s:smem_ptr NULL!\n", __FUNCTION__); + // 错误:系统BUG_ON宏打印调用栈后调用panic(),导致内核拒绝服务,不应在正常流程中使用 + BUG_ON(1); + return 1; + } + + ... +} +``` + +**【正确代码示例】** + +去掉BUG_ON宏。 + +```c +/ * 判断Q6侧设置定时器是否繁忙,1-忙,0-不忙 */ +static unsigned int is_modem_set_timer_busy(special_timer *smem_ptr) +{ + int i = 0; + if (smem_ptr == NULL) { + printk(KERN_EMERG"%s:smem_ptr NULL!\n", __FUNCTION__); + // 修改:去掉BUG_ON调用,或使用WARN_ON + return 1; + } + + ... +} +``` + +## 在中断处理程序或持有自旋锁的进程上下文代码中,禁止使用会引起进程休眠的函数 + +**【描述】** + +系统以进程为调度单位,在中断上下文中,只有更高优先级的中断才能将其打断,系统在中断处理的时候不能进行进程调度。如果中断处理程序处于休眠状态,就会导致内核无法唤醒,从而使得内核处于瘫痪。 + +自旋锁在使用时,抢占是失效的。若自旋锁在锁住以后进入睡眠,由于不能进行处理器抢占,其它进程都将因为不能获得CPU(单核CPU)而停止运行,对外表现为系统将不作任何响应,出现挂死。 + +因此,在中断处理程序或持有自旋锁的进程上下文代码中,应该禁止使用可能会引起休眠(如vmalloc()、msleep()等)、阻塞(如copy_from_user(),copy_to_user()等)或者耗费大量时间(如printk()等)的函数。 + +## 合理使用内核栈,防止内核栈溢出 + +**【描述】** + +内核栈大小是固定的(一般32位系统为8K,64位系统为16K,因此资源非常宝贵。不合理的使用内核栈,可能会导致栈溢出,造成系统挂死。因此需要做到以下几点: + +- 在栈上申请内存空间不要超过内核栈大小; +- 注意函数的嵌套使用次数; +- 不要定义过多的变量。 + +**【错误代码示例】** + +以下代码中定义的变量过大,导致栈溢出。 + +```c +... +struct result +{ + char name[4]; + unsigned int a; + unsigned int b; + unsigned int c; + unsigned int d; +}; // 结构体result的大小为20字节 + +int foo() +{ + struct result temp[512]; + // 错误: temp数组含有512个元素,总大小为10K,远超内核栈大小 + (void)memset(temp, 0, sizeof(result) * 512); + ... // use temp do something + return 0; +} + +... +``` + +代码中数组temp有512个元素,总共10K大小,远超内核的8K,明显的栈溢出。 + +**【正确代码示例】** + +使用kmalloc()代替之。 + +```c +... +struct result +{ + char name[4]; + unsigned int a; + unsigned int b; + unsigned int c; + unsigned int d; +}; // 结构体result的大小为20字节 + +int foo() +{ + struct result *temp = NULL; + temp = (result *)kmalloc(sizeof(result) * 512, GFP_KERNEL); //修改:使用kmalloc()申请内存 + ... // check temp is not NULL + (void)memset(temp, 0, sizeof(result) * 512); + ... // use temp do something + ... // free temp + return 0; +} +... +``` + +## 临时关闭地址校验机制后,在操作完成后必须及时恢复 + +**【描述】** + +SMEP安全机制是指禁止内核执行用户空间的代码(PXN是ARM版本的SMEP)。系统调用(如open(),write()等)本来是提供给用户空间程序访问的。默认情况下,这些函数会对传入的参数地址进行校验,如果入参是非用户空间地址则报错。因此,要在内核程序中使用这些系统调用,就必须使参数地址校验功能失效。set_fs()/get_fs()就用来解决该问题。详细说明见如下代码: + +```c +... +mmegment_t old_fs; +printk("Hello, I'm the module that intends to write message to file.\n"); +if (file == NULL) { + file = filp_open(MY_FILE, O_RDWR | O_APPEND | O_CREAT, 0664); +} + +if (IS_ERR(file)) { + printk("Error occured while opening file %s, exiting ...\n", MY_FILE); + return 0; +} + +sprintf(buf, "%s", "The Message."); +old_fs = get_fs(); // get_fs()的作用是获取用户空间地址上限值 + // #define get_fs() (current->addr_limit +set_fs(KERNEL_DS); // set_fs的作用是将地址空间上限扩大到KERNEL_DS,这样内核代码可以调用系统函数 +file->f_op->write(file, (char *)buf, sizeof(buf), &file->f_pos); // 内核代码可以调用write()函数 +set_fs(old_fs); // 使用完后及时恢复原来用户空间地址限制值 +... +``` + +通过上述代码,可以了解到最为关键的就是操作完成后,要及时恢复地址校验功能。否则SMEP/PXN安全机制就会失效,使得许多漏洞的利用变得很容易。 + +**【错误代码示例】** + +在程序错误处理分支,未通过set_fs()恢复地址校验功能。 + +```c +... +oldfs = get_fs(); +set_fs(KERNEL_DS); +/* 在时间戳目录下面创建done文件 */ +fd = sys_open(path, O_CREAT | O_WRONLY, FILE_LIMIT); +if (fd < 0) { + BB_PRINT_ERR("sys_mkdir[%s] error, fd is[%d]\n", path, fd); + return; // 错误:在错误处理程序分支未恢复地址校验机制 +} + +sys_close(fd); +set_fs(oldfs); +... +``` + +**【正确代码示例】** + +在错误处理程序中恢复地址校验功能。 + +```c +... +oldfs = get_fs(); +set_fs(KERNEL_DS); + +/* 在时间戳目录下面创建done文件 */ +fd = sys_open(path, O_CREAT | O_WRONLY, FILE_LIMIT); +if (fd < 0) { + BB_PRINT_ERR("sys_mkdir[%s] error, fd is[%d] \n", path, fd); + set_fs(oldfs); // 修改:在错误处理程序分支中恢复地址校验机制 + return; +} + +sys_close(fd); +set_fs(oldfs); +... +``` + diff --git a/website/docs/_posts/contribute/OpenHarmony-cpp-coding-style-guide.md b/website/docs/_posts/contribute/OpenHarmony-cpp-coding-style-guide.md new file mode 100644 index 0000000000000000000000000000000000000000..7553a87320134b3f3ca3ea7a0c9bab26e762f16c --- /dev/null +++ b/website/docs/_posts/contribute/OpenHarmony-cpp-coding-style-guide.md @@ -0,0 +1,2913 @@ +--- +title: OpenHarmony-cpp-coding-style-guide.md +permalink: /pages/extra/8b4362/ +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +date: 2021-12-30 18:17:45 +--- +# C++语言编程规范 + +## 目的 +规则并不是完美的,通过禁止在特定情况下有用的特性,可能会对代码实现造成影响。但是我们制定规则的目的“为了大多数程序员可以得到更多的好处”, 如果在团队运作中认为某个规则无法遵循,希望可以共同改进该规则。 +参考该规范之前,希望您具有相应的C++语言基础能力,而不是通过该文档来学习C++语言。 +1. 了解C++语言的ISO标准; +2. 熟知C++语言的基本语言特性,包括C++ 03/11/14/17相关特性; +3. 了解C++语言的标准库; + +## 总体原则 +代码需要在保证功能正确的前提下,满足**可读、可维护、安全、可靠、可测试、高效、可移植**的特征要求。 + +## 重点关注 +1. 约定C++语言的编程风格,比如命名,排版等。 +2. C++语言的模块化设计,如何设计头文件,类,接口和函数。 +3. C++语言相关特性的优秀实践,比如常量,类型转换,资源管理,模板等。 +4. 现代C++语言的优秀实践,包括C++11/14/17中可以提高代码可维护性,提高代码可靠性的相关约定。 +5. 本规范优先适于用C++17版本。 + +## 约定 +**规则**:编程时必须遵守的约定(must) + +**建议**:编程时应该遵守的约定(should) + +本规范适用通用C++标准, 如果没有特定的标准版本,适用所有的版本(C++03/11/14/17)。 + +## 例外 +无论是'规则'还是'建议',都必须理解该条目这么规定的原因,并努力遵守。 +但是,有些规则和建议可能会有例外。 + +在不违背总体原则,经过充分考虑,有充足的理由的前提下,可以适当违背规范中约定。 +例外破坏了代码的一致性,请尽量避免。'规则'的例外应该是极少的。 + +下列情况,应风格一致性原则优先: +**修改外部开源代码、第三方代码时,应该遵守开源代码、第三方代码已有规范,保持风格统一。** + +# 2 命名 +## 通用命名 +__驼峰风格(CamelCase)__ +大小写字母混用,单词连在一起,不同单词间通过单词首字母大写来分开。 +按连接后的首字母是否大写,又分: 大驼峰(UpperCamelCase)和小驼峰(lowerCamelCase) + + +| 类型 | 命名风格 | +| ---------------------------------------- | --------- | +| 类类型,结构体类型,枚举类型,联合体类型等类型定义, 作用域名称 | 大驼峰 | +| 函数(包括全局函数,作用域函数,成员函数) | 大驼峰 | +| 全局变量(包括全局和命名空间域下的变量,类静态变量),局部变量,函数参数,类、结构体和联合体中的成员变量 | 小驼峰 | +| 宏,常量(const),枚举值,goto 标签 | 全大写,下划线分割 | + +注意: +上表中__常量__是指全局作用域、namespace域、类的静态成员域下,以 const或constexpr 修饰的基本数据类型、枚举、字符串类型的变量,不包括数组和其他类型变量。 +上表中__变量__是指除常量定义以外的其他变量,均使用小驼峰风格。 + +## 文件命名 +### 规则2.2.1 C++文件以.cpp结尾,头文件以.h结尾 +我们推荐使用.h作为头文件的后缀,这样头文件可以直接兼容C和C++。 +我们推荐使用.cpp作为实现文件的后缀,这样可以直接区分C++代码,而不是C代码。 + +目前业界还有一些其他的后缀的表示方法: + +- 头文件: .hh, .hpp, .hxx +- cpp文件:.cc, .cxx, .c + +如果当前项目组使用了某种特定的后缀,那么可以继续使用,但是请保持风格统一。 +但是对于本文档,我们默认使用.h和.cpp作为后缀。 + + +### 规则2.2.2 C++文件名和类名保持一致 +C++的头文件和cpp文件名和类名保持一致,使用下划线小写风格。 + +如果有一个类叫DatabaseConnection,那么对应的文件名: +- database_connection.h +- database_connection.cpp + +结构体,命名空间,枚举等定义的文件名类似。 + +## 函数命名 +函数命名统一使用大驼峰风格,一般采用动词或者动宾结构。 +```cpp +class List { +public: + void AddElement(const Element& element); + Element GetElement(const unsigned int index) const; + bool IsEmpty() const; +}; + +namespace Utils { + void DeleteUser(); +} +``` + +## 类型命名 + +类型命名采用大驼峰命名风格。 +所有类型命名——类、结构体、联合体、类型定义(typedef)、枚举——使用相同约定,例如: +```cpp +// classes, structs and unions +class UrlTable { ... +class UrlTableTester { ... +struct UrlTableProperties { ... +union Packet { ... + +// typedefs +typedef std::map PropertiesMap; + +// enums +enum UrlTableErrors { ... +``` + +对于命名空间的命名,建议使用大驼峰: +```cpp +// namespace +namespace OsUtils { + +namespace FileUtils { + +} + +} +``` + + +### 建议2.4.1 避免滥用 typedef或者#define 对基本类型起别名 +除有明确的必要性,否则不要用 typedef/#define 对基本数据类型进行重定义。 +优先使用``头文件中的基本类型: + +| 有符号类型 | 无符号类型 | 描述 | +| -------- | --------- | ---------------- | +| int8_t | uint8_t | 宽度恰为8的有/无符号整数类型 | +| int16_t | uint16_t | 宽度恰为16的有/无符号整数类型 | +| int32_t | uint32_t | 宽度恰为32的有/无符号整数类型 | +| int64_t | uint64_t | 宽度恰为64的有/无符号整数类型 | +| intptr_t | uintptr_t | 足以保存指针的有/无符号整数类型 | + + +## 变量命名 +通用变量命名采用小驼峰,包括全局变量,函数形参,局部变量,成员变量。 +```cpp +std::string tableName; // Good: 推荐此风格 +std::string tablename; // Bad: 禁止此风格 +std::string path; // Good: 只有一个单词时,小驼峰为全小写 +``` + +### 规则2.5.1 全局变量应增加 'g_' 前缀,静态变量命名不需要加特殊前缀 +全局变量是应当尽量少使用的,使用时应特别注意,所以加上前缀用于视觉上的突出,促使开发人员对这些变量的使用更加小心。 +- 全局静态变量命名与全局变量相同。 +- 函数内的静态变量命名与普通局部变量相同。 +- 类的静态成员变量和普通成员变量相同。 + +```cpp +int g_activeConnectCount; + +void Func() +{ + static int packetCount = 0; + ... +} +``` + +### 规则2.5.2 类的成员变量命名以小驼峰加后下划线组成 + +```cpp +class Foo { +private: + std::string fileName_; // 添加_后缀,类似于K&R命名风格 +}; +``` +对于struct/union的成员变量,仍采用小驼峰不加后缀的命名方式,与局部变量命名风格一致。 + +## 宏、常量、枚举命名 +宏、枚举值采用全大写,下划线连接的格式。 +全局作用域内,有名和匿名namespace内的 const 常量,类的静态成员常量,全大写,下划线连接;函数局部 const 常量和类的普通const成员变量,使用小驼峰命名风格。 + +```cpp +#define MAX(a, b) (((a) < (b)) ? (b) : (a)) // 仅对宏命名举例,并不推荐用宏实现此类功能 + +enum TintColor { // 注意,枚举类型名用大驼峰,其下面的取值是全大写,下划线相连 + RED, + DARK_RED, + GREEN, + LIGHT_GREEN +}; + +int Func(...) +{ + const unsigned int bufferSize = 100; // 函数局部常量 + char *p = new char[bufferSize]; + ... +} + +namespace Utils { + const unsigned int DEFAULT_FILE_SIZE_KB = 200; // 全局常量 +} + +``` + +# 3 格式 + +## 行宽 + +### 规则3.1.1 行宽不超过 120 个字符 +建议每行字符数不要超过 120 个。如果超过120个字符,请选择合理的方式进行换行。 + +例外: +- 如果一行注释包含了超过120 个字符的命令或URL,则可以保持一行,以方便复制、粘贴和通过grep查找; +- 包含长路径的 #include 语句可以超出120 个字符,但是也需要尽量避免; +- 编译预处理中的error信息可以超出一行。 +预处理的 error 信息在一行便于阅读和理解,即使超过 120 个字符。 +```cpp +#ifndef XXX_YYY_ZZZ +#error Header aaaa/bbbb/cccc/abc.h must only be included after xxxx/yyyy/zzzz/xyz.h, because xxxxxxxxxxxxxxxxxxxxxxxxxxxxx +#endif +``` + +## 缩进 + +### 规则3.2.1 使用空格进行缩进,每次缩进4个空格 +只允许使用空格(space)进行缩进,每次缩进为 4 个空格。不允许使用Tab符进行缩进。 +当前几乎所有的集成开发环境(IDE)都支持配置将Tab符自动扩展为4空格输入;请配置你的IDE支持使用空格进行缩进。 + +## 大括号 +### 规则3.3.1 使用 K&R 缩进风格 +__K&R风格__ +换行时,函数(不包括lambda表达式)左大括号另起一行放行首,并独占一行;其他左大括号跟随语句放行末。 +右大括号独占一行,除非后面跟着同一语句的剩余部分,如 do 语句中的 while,或者 if 语句的 else/else if,或者逗号、分号。 + +如: +```cpp +struct MyType { // 跟随语句放行末,前置1空格 + ... +}; + +int Foo(int a) +{ // 函数左大括号独占一行,放行首 + if (...) { + ... + } else { + ... + } +} +``` +推荐这种风格的理由: + +- 代码更紧凑; +- 相比另起一行,放行末使代码阅读节奏感上更连续; +- 符合后来语言的习惯,符合业界主流习惯; +- 现代集成开发环境(IDE)都具有代码缩进对齐显示的辅助功能,大括号放在行尾并不会对缩进和范围产生理解上的影响。 + + +对于空函数体,可以将大括号放在同一行: +```cpp +class MyClass { +public: + MyClass() : value_(0) {} + +private: + int value_; +}; +``` + +## 函数声明和定义 + +### 规则3.4.1 函数声明和定义的返回类型和函数名在同一行;函数参数列表超出行宽时要换行并合理对齐 +在声明和定义函数的时候,函数的返回值类型应该和函数名在同一行;如果行宽度允许,函数参数也应该放在一行;否则,函数参数应该换行,并进行合理对齐。 +参数列表的左圆括号总是和函数名在同一行,不要单独一行;右圆括号总是跟随最后一个参数。 + +换行举例: +```cpp +ReturnType FunctionName(ArgType paramName1, ArgType paramName2) // Good:全在同一行 +{ + ... +} + +ReturnType VeryVeryVeryLongFunctionName(ArgType paramName1, // 行宽不满足所有参数,进行换行 + ArgType paramName2, // Good:和上一行参数对齐 + ArgType paramName3) +{ + ... +} + +ReturnType LongFunctionName(ArgType paramName1, ArgType paramName2, // 行宽限制,进行换行 + ArgType paramName3, ArgType paramName4, ArgType paramName5) // Good: 换行后 4 空格缩进 +{ + ... +} + +ReturnType ReallyReallyReallyReallyLongFunctionName( // 行宽不满足第1个参数,直接换行 + ArgType paramName1, ArgType paramName2, ArgType paramName3) // Good: 换行后 4 空格缩进 +{ + ... +} +``` + +## 函数调用 +### 规则3.5.1 函数调用入参列表应放在一行,超出行宽换行时,保持参数进行合理对齐 +函数调用时,函数参数列表放在一行。参数列表如果超过行宽,需要换行并进行合理的参数对齐。 +左圆括号总是跟函数名,右圆括号总是跟最后一个参数。 + +换行举例: +```cpp +ReturnType result = FunctionName(paramName1, paramName2); // Good:函数参数放在一行 + +ReturnType result = FunctionName(paramName1, + paramName2, // Good:保持与上方参数对齐 + paramName3); + +ReturnType result = FunctionName(paramName1, paramName2, + paramName3, paramName4, paramName5); // Good:参数换行,4 空格缩进 + +ReturnType result = VeryVeryVeryLongFunctionName( // 行宽不满足第1个参数,直接换行 + paramName1, paramName2, paramName3); // 换行后,4 空格缩进 +``` + +如果函数调用的参数存在内在关联性,按照可理解性优先于格式排版要求,对参数进行合理分组换行。 +```cpp +// Good:每行的参数代表一组相关性较强的数据结构,放在一行便于理解 +int result = DealWithStructureLikeParams(left.x, left.y, // 表示一组相关参数 + right.x, right.y); // 表示另外一组相关参数 +``` + +## if语句 + +### 规则3.6.1 if语句必须要使用大括号 +我们要求if语句都需要使用大括号,即便只有一条语句。 + +理由: +- 代码逻辑直观,易读; +- 在已有条件语句代码上增加新代码时不容易出错; +- 对于在if语句中使用函数式宏时,有大括号保护不易出错(如果宏定义时遗漏了大括号)。 + +```cpp +if (objectIsNotExist) { // Good:单行条件语句也加大括号 + return CreateNewObject(); +} +``` +### 规则3.6.2 禁止 if/else/else if 写在同一行 +条件语句中,若有多个分支,应该写在不同行。 + +如下是正确的写法: + +```cpp +if (someConditions) { + DoSomething(); + ... +} else { // Good: else 与 if 在不同行 + ... +} +``` + +下面是不符合规范的案例: + +```cpp +if (someConditions) { ... } else { ... } // Bad: else 与 if 在同一行 +``` + +## 循环语句 +### 规则3.7.1 循环语句必须使用大括号 +和条件表达式类似,我们要求for/while循环语句必须加上大括号,即便循环体是空的,或循环语句只有一条。 +```cpp +for (int i = 0; i < someRange; i++) { // Good: 使用了大括号 + DoSomething(); +} +``` +```cpp +while (condition) { } // Good:循环体是空,使用大括号 +``` +```cpp +while (condition) { + continue; // Good:continue 表示空逻辑,使用大括号 +} +``` + +坏的例子: +```cpp +for (int i = 0; i < someRange; i++) + DoSomething(); // Bad: 应该加上括号 +``` +```cpp +while (condition); // Bad:使用分号容易让人误解是while语句中的一部分 +``` + +## switch语句 +### 规则3.8.1 switch 语句的 case/default 要缩进一层 +switch 语句的缩进风格如下: +```cpp +switch (var) { + case 0: // Good: 缩进 + DoSomething1(); // Good: 缩进 + break; + case 1: { // Good: 带大括号格式 + DoSomething2(); + break; + } + default: + break; +} +``` + +```cpp +switch (var) { +case 0: // Bad: case 未缩进 + DoSomething(); + break; +default: // Bad: default 未缩进 + break; +} +``` + +## 表达式 + +### 建议3.9.1 表达式换行要保持换行的一致性,运算符放行末 +较长的表达式,不满足行宽要求的时候,需要在适当的地方换行。一般在较低优先级运算符或连接符后面截断,运算符或连接符放在行末。 +运算符、连接符放在行末,表示“未结束,后续还有”。 +例: + +// 假设下面第一行已经不满足行宽要求 +```cpp +if ((currentValue > threshold) && // Good:换行后,逻辑操作符放在行尾 + someConditionsion) { + DoSomething(); + ... +} + +int result = reallyReallyLongVariableName1 + // Good + reallyReallyLongVariableName2; +``` +表达式换行后,注意保持合理对齐,或者4空格缩进。参考下面例子 + +```cpp +int sum = longVaribleName1 + longVaribleName2 + longVaribleName3 + + longVaribleName4 + longVaribleName5 + longVaribleName6; // Good: 4空格缩进 + +int sum = longVaribleName1 + longVaribleName2 + longVaribleName3 + + longVaribleName4 + longVaribleName5 + longVaribleName6; // Good: 保持对齐 +``` +## 变量赋值 + +### 规则3.10.1 多个变量定义和赋值语句不允许写在一行 +每行只有一个变量初始化的语句,更容易阅读和理解。 + +```cpp +int maxCount = 10; +bool isCompleted = false; +``` + +下面是不符合规范的示例: + +```cpp +int maxCount = 10; bool isCompleted = false; // Bad:多个变量初始化需要分开放在多行,每行一个变量初始化 +int x, y = 0; // Bad:多个变量定义需要分行,每行一个 + +int pointX; +int pointY; +... +pointX = 1; pointY = 2; // Bad:多个变量赋值语句放同一行 +``` +例外:for 循环头、if 初始化语句(C++17)、结构化绑定语句(C++17)中可以声明和初始化多个变量。这些语句中的多个变量声明有较强关联,如果强行分成多行会带来作用域不一致,声明和初始化割裂等问题。 + +## 初始化 +初始化包括结构体、联合体、及数组的初始化 + +### 规则3.11.1 初始化换行时要有缩进,并进行合理对齐 +结构体或数组初始化时,如果换行应保持4空格缩进。 +从可读性角度出发,选择换行点和对齐位置。 + +```cpp +const int rank[] = { + 16, 16, 16, 16, 32, 32, 32, 32, + 64, 64, 64, 64, 32, 32, 32, 32 +}; +``` + +## 指针与引用 +### 建议3.12.1 指针类型"`*`"跟随变量名或者类型,不要两边都留有或者都没有空格 +指针命名: `*`靠左靠右都可以,但是不要两边都有或者都没有空格。 +```cpp +int* p = nullptr; // Good +int *p = nullptr; // Good + +int*p = nullptr; // Bad +int * p = nullptr; // Bad +``` + +例外:当变量被 const 修饰时,"`*`" 无法跟随变量,此时也不要跟随类型。 +```cpp +const char * const VERSION = "V100"; +``` + +### 建议3.12.2 引用类型"`&`"跟随变量名或者类型,不要两边都留有或者都没有空格 +引用命名:`&`靠左靠右都可以,但是不要两边都有或者都没有空格。 +```cpp +int i = 8; + +int& p = i; // Good +int &p = i; // Good +int*& rp = pi; // Good,指针的引用,*& 一起跟随类型 +int *&rp = pi; // Good,指针的引用,*& 一起跟随变量名 +int* &rp = pi; // Good,指针的引用,* 跟随类型,& 跟随变量名 + +int & p = i; // Bad +int&p = i; // Bad +``` + +## 编译预处理 +### 规则3.13.1 编译预处理的"#"统一放在行首,嵌套编译预处理语句时,"#"可以进行缩进 +编译预处理的"#"统一放在行首,即使编译预处理的代码是嵌入在函数体中的,"#"也应该放在行首。 + +### 规则3.13.2 避免使用宏 +宏会忽略作用域,类型系统以及各种规则,容易引发问题。应尽量避免使用宏定义,如果必须使用宏,要保证证宏名的唯一性。 +在C++中,有许多方式来避免使用宏: +- 用const或enum定义易于理解的常量 +- 用namespace避免名字冲突 +- 用inline函数避免函数调用的开销 +- 用template函数来处理多种类型 +在文件头保护宏、条件编译、日志记录等必要场景中可以使用宏。 + +### 规则3.13.3 禁止使用宏来表示常量 +宏是简单的文本替换,在预处理阶段完成,运行报错时直接报相应的值;跟踪调试时也是显示值,而不是宏名; 宏没有类型检查,不宏全; 宏没有作用域。 + +### 规则3.13.4 禁止使用函数式宏 +宏义函数式宏前,应考虑能否用函数替代。对于可替代场景,建议用函数替代宏。 +函数式宏的缺点如下: +- 函数式宏缺乏类型检查,不如函数调用检查严格 +- 宏展开时宏参数不求值,可能会产生非预期结果 +- 宏没有独产的作用域 +- 宏的技巧性太强,例如#的用法和无处不在的括号,影响可读性 +- 在特定场景中必须用编译器对宏的扩展语法,如GCC的statement expression,影响可移植性 +- 宏在预编译阶段展开后,在期后编译、链接和调试时都不可见;而且包含多行的宏会展开为一行。函数式宏难以调试、难以打断点,不利于定位问题 +- 对于包含大量语句的宏,在每个调用点都要展开。如果调用点很多,会造成代码空间的膨胀 + +函数没有宏的上述缺点。但是,函数相比宏,最大的劣势是执行效率不高(增加函数调用的开销和编译器优化的难度)。 +为此,可以在必要时使用内联函数。内联函数跟宏类似,也是在调用点展开。不同之处在于内联函数是在编译时展开。 + +内联函数兼具函数和宏的优点: +- 内联函数执行严格的类型检查 +- 内联函数的参数求值只会进行一次 +- 内联函数就地展开,没有函数调用的开销 +- 内联函数比函数优化得更好 +对于性能要求高的产品代码,可以考虑用内联函数代替函数。 + +例外: +在日志记录场景中,需要通过函数式宏保持调用点的文件名(__FILE__)、行号(__LINE__)等信息。 + +## 空格和空行 +### 规则3.14.1 水平空格应该突出关键字和重要信息,避免不必要的留白 +水平空格应该突出关键字和重要信息,每行代码尾部不要加空格。总体规则如下: + +- if, switch, case, do, while, for等关键字之后加空格; +- 小括号内部的两侧,不要加空格; +- 大括号内部两侧有无空格,左右必须保持一致; +- 一元操作符(& * + ‐ ~ !)之后不要加空格; +- 二元操作符(= + ‐ < > * / % | & ^ <= >= == != )左右两侧加空格 +- 三目运算符(? :)符号两侧均需要空格 +- 前置和后置的自增、自减(++ --)和变量之间不加空格 +- 结构体成员操作符(. ->)前后不加空格 +- 逗号(,)前面不加空格,后面增加空格 +- 对于模板和类型转换(<>)和类型之间不要添加空格 +- 域操作符(::)前后不要添加空格 +- 冒号(:)前后根据情况来判断是否要添加空格 + +常规情况: +```cpp +void Foo(int b) { // Good:大括号前应该留空格 + +int i = 0; // Good:变量初始化时,=前后应该有空格,分号前面不要留空格 + +int buf[BUF_SIZE] = {0}; // Good:大括号内两侧都无空格 +``` + +函数定义和函数调用: +```cpp +int result = Foo(arg1,arg2); + ^ // Bad: 逗号后面需要增加空格 + +int result = Foo( arg1, arg2 ); + ^ ^ // Bad: 函数参数列表的左括号后面不应该有空格,右括号前面不应该有空格 +``` + +指针和取地址 +```cpp +x = *p; // Good:*操作符和指针p之间不加空格 +p = &x; // Good:&操作符和变量x之间不加空格 +x = r.y; // Good:通过.访问成员变量时不加空格 +x = r->y; // Good:通过->访问成员变量时不加空格 +``` + +操作符: +```cpp +x = 0; // Good:赋值操作的=前后都要加空格 +x = -5; // Good:负数的符号和数值之前不要加空格 +++x; // Good:前置和后置的++/--和变量之间不要加空格 +x--; + +if (x && !y) // Good:布尔操作符前后要加上空格,!操作和变量之间不要空格 +v = w * x + y / z; // Good:二元操作符前后要加空格 +v = w * (x + z); // Good:括号内的表达式前后不需要加空格 + +int a = (x < y) ? x : y; // Good: 三目运算符, ?和:前后需要添加空格 +``` + +循环和条件语句: +```cpp +if (condition) { // Good:if关键字和括号之间加空格,括号内条件语句前后不加空格 + ... +} else { // Good:else关键字和大括号之间加空格 + ... +} + +while (condition) {} // Good:while关键字和括号之间加空格,括号内条件语句前后不加空格 + +for (int i = 0; i < someRange; ++i) { // Good:for关键字和括号之间加空格,分号之后加空格 + ... +} + +switch (condition) { // Good: switch 关键字后面有1空格 + case 0: // Good:case语句条件和冒号之间不加空格 + ... + break; + ... + default: + ... + break; +} +``` + +模板和转换 +```cpp +// 尖括号(< and >) 不与空格紧邻, < 前没有空格, > 和 ( 之间也没有. +vector x; +y = static_cast(x); + +// 在类型与指针操作符之间留空格也可以, 但要保持一致. +vector x; +``` + +域操作符 +```cpp +std::cout; // Good: 命名空间访问,不要留空格 + +int MyClass::GetValue() const {} // Good: 对于成员函数定义,不要留空格 +``` + +冒号 +```cpp +// 添加空格的场景 + +// Good: 类的派生需要留有空格 +class Sub : public Base { + +}; + +// 构造函数初始化列表需要留有空格 +MyClass::MyClass(int var) : someVar_(var) +{ + DoSomething(); +} + +// 位域表示也留有空格 +struct XX { + char a : 4; + char b : 5; + char c : 4; +}; +``` + +```cpp +// 不添加空格的场景 + +// Good: 对于public:, private:这种类访问权限的冒号不用添加空格 +class MyClass { +public: + MyClass(int var); +private: + int someVar_; +}; + +// 对于switch-case的case和default后面的冒号不用添加空格 +switch (value) +{ + case 1: + DoSomething(); + break; + default: + break; +} +``` + +注意:当前的集成开发环境(IDE)可以设置删除行尾的空格,请正确配置。 + +### 建议3.14.1 合理安排空行,保持代码紧凑 + +减少不必要的空行,可以显示更多的代码,方便代码阅读。下面有一些建议遵守的规则: +- 根据上下内容的相关程度,合理安排空行; +- 函数内部、类型定义内部、宏内部、初始化表达式内部,不使用连续空行 +- 不使用连续 **3** 个空行,或更多 +- 大括号内的代码块行首之前和行尾之后不要加空行,但namespace的大括号内不作要求。 + +```cpp +int Foo() +{ + ... +} + + + +int Bar() // Bad:最多使用连续2个空行。 +{ + ... +} + + +if (...) { + // Bad:大括号内的代码块行首不要加入空行 + ... + // Bad:大括号内的代码块行尾不要加入空行 +} + +int Foo(...) +{ + // Bad:函数体内行首不要加空行 + ... +} +``` + +## 类 +### 规则3.15.1 类访问控制块的声明依次序是 public:, protected:, private:,缩进和 class 关键字对齐 +```cpp +class MyClass : public BaseClass { +public: // 注意没有缩进 + MyClass(); // 标准的4空格缩进 + explicit MyClass(int var); + ~MyClass() {} + + void SomeFunction(); + void SomeFunctionThatDoesNothing() + { + } + + void SetVar(int var) { someVar_ = var; } + int GetVar() const { return someVar_; } + +private: + bool SomeInternalFunction(); + + int someVar_; + int someOtherVar_; +}; +``` + +在各个部分中,建议将类似的声明放在一起, 并且建议以如下的顺序: 类型 (包括 typedef, using 和嵌套的结构体与类), 常量, 工厂函数, 构造函数, 赋值运算符, 析构函数, 其它成员函数, 数据成员。 + + +### 规则3.15.2 构造函数初始化列表放在同一行或按四格缩进并排多行 +```cpp +// 如果所有变量能放在同一行: +MyClass::MyClass(int var) : someVar_(var) +{ + DoSomething(); +} + +// 如果不能放在同一行, +// 必须置于冒号后, 并缩进4个空格 +MyClass::MyClass(int var) + : someVar_(var), someOtherVar_(var + 1) // Good: 逗号后面留有空格 +{ + DoSomething(); +} + +// 如果初始化列表需要置于多行, 需要逐行对齐 +MyClass::MyClass(int var) + : someVar_(var), // 缩进4个空格 + someOtherVar_(var + 1) +{ + DoSomething(); +} +``` + +# 4 注释 +一般的,尽量通过清晰的架构逻辑,好的符号命名来提高代码可读性;需要的时候,才辅以注释说明。 +注释是为了帮助阅读者快速读懂代码,所以要从读者的角度出发,**按需注释**。 + +注释内容要简洁、明了、无二义性,信息全面且不冗余。 + +**注释跟代码一样重要。** +写注释时要换位思考,用注释去表达此时读者真正需要的信息。在代码的功能、意图层次上进行注释,即注释解释代码难以表达的意图,不要重复代码信息。 +修改代码时,也要保证其相关注释的一致性。只改代码,不改注释是一种不文明行为,破坏了代码与注释的一致性,让阅读者迷惑、费解,甚至误解。 + +使用英文进行注释。 + +## 注释风格 + +在 C++ 代码中,使用 `/*` `*/`和 `//` 都是可以的。 +按注释的目的和位置,注释可分为不同的类型,如文件头注释、函数头注释、代码注释等等; +同一类型的注释应该保持统一的风格。 + +注意:本文示例代码中,大量使用 '//' 后置注释只是为了更精确的描述问题,并不代表这种注释风格更好。 + +## 文件头注释 +### 规则3.1 文件头注释必须包含版权许可 + +/* + * Copyright (c) 2020 XXX + * 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. + */ + +## 函数头注释 +### 规则4.3.1 公有(public)函数必须编写函数头注释 +公有函数属于类对外提供的接口,调用者需要了解函数的功能、参数的取值范围、返回的结果、注意事项等信息才能正常使用。 +特别是参数的取值范围、返回的结果、注意事项等都无法做到自注示,需要编写函数头注释辅助说明。 + +### 规则4.3.2 禁止空有格式的函数头注释 +并不是所有的函数都需要函数头注释; +函数签名无法表达的信息,加函数头注释辅助说明; + +函数头注释统一放在函数声明或定义上方,使用如下风格之一: +使用`//`写函数头 + +```cpp +// 单行函数头 +int Func1(void); + +// 多行函数头 +// 第二行 +int Func2(void); +``` + +使用`/* */`写函数头 +```cpp +/* 单行函数头 */ +int Func1(void); + +/* + * 另一种单行函数头 + */ +int Func2(void); + +/* + * 多行函数头 + * 第二行 + */ +int Func3(void); +``` +函数尽量通过函数名自注释,按需写函数头注释。 +不要写无用、信息冗余的函数头;不要写空有格式的函数头。 + +函数头注释内容可选,但不限于:功能说明、返回值,性能约束、用法、内存约定、算法实现、可重入的要求等等。 +模块对外头文件中的函数接口声明,其函数头注释,应当将重要、有用的信息表达清楚。 + +例: + +```cpp +/* + * 返回实际写入的字节数,-1表示写入失败 + * 注意,内存 buf 由调用者负责释放 + */ +int WriteString(const char *buf, int len); +``` + +坏的例子: +```cpp +/* + * 函数名:WriteString + * 功能:写入字符串 + * 参数: + * 返回值: + */ +int WriteString(const char *buf, int len); +``` +上面例子中的问题: + +- 参数、返回值,空有格式没内容 +- 函数名信息冗余 +- 关键的 buf 由谁释放没有说清楚 + +## 代码注释 +### 规则4.4.1 代码注释放于对应代码的上方或右边 +### 规则4.4.2 注释符与注释内容间要有1空格;右置注释与前面代码至少1空格 +代码上方的注释,应该保持对应代码一样的缩进。 +选择并统一使用如下风格之一: +使用`//` +```cpp + +// 这是单行注释 +DoSomething(); + +// 这是多行注释 +// 第二行 +DoSomething(); +``` + +使用`/*' '*/` +```cpp +/* 这是单行注释 */ +DoSomething(); + +/* + * 另一种方式的多行注释 + * 第二行 + */ +DoSomething(); +``` +代码右边的注释,与代码之间,至少留1空格,建议不超过4空格。 +通常使用扩展后的 TAB 键即可实现 1-4 空格的缩进。 + +选择并统一使用如下风格之一: + +```cpp +int foo = 100; // 放右边的注释 +int bar = 200; /* 放右边的注释 */ +``` +右置格式在适当的时候,上下对齐会更美观。 +对齐后的注释,离左边代码最近的那一行,保证1-4空格的间隔。 +例: + +```cpp +const int A_CONST = 100; /* 相关的同类注释,可以考虑上下对齐 */ +const int ANOTHER_CONST = 200; /* 上下对齐时,与左侧代码保持间隔 */ +``` +当右置的注释超过行宽时,请考虑将注释置于代码上方。 + +### 规则4.4.3 不用的代码段直接删除,不要注释掉 +被注释掉的代码,无法被正常维护;当企图恢复使用这段代码时,极有可能引入易被忽略的缺陷。 +正确的做法是,不需要的代码直接删除掉。若再需要时,考虑移植或重写这段代码。 + +这里说的注释掉代码,包括用 /* */ 和 //,还包括 #if 0, #ifdef NEVER_DEFINED 等等。 + +# 5 头文件 +## 头文件职责 +头文件是模块或文件的对外接口,头文件的设计体现了大部分的系统设计。 +头文件中适合放置接口的声明,不适合放置实现(内联函数除外)。对于cpp文件中内部才需要使用的函数、宏、枚举、结构定义等不要放在头文件中。 +头文件应当职责单一。头文件过于复杂,依赖过于复杂还是导致编译时间过长的主要原因。 + +### 建议5.1.1 每一个.cpp文件应有一个对应的.h文件,用于声明需要对外公开的类与接口 +通常情况下,每个.cpp文件都有一个相应的.h,用于放置对外提供的函数声明、宏定义、类型定义等。 +如果一个.cpp文件不需要对外公布任何接口,则其就不应当存在。 +例外:__程序的入口(如main函数所在的文件),单元测试代码,动态库代码。__ + +示例: +```cpp +// Foo.h + +#ifndef FOO_H +#define FOO_H + +class Foo { +public: + Foo(); + void Fun(); + +private: + int value_; +}; + +#endif +``` + +```cpp +// Foo.cpp +#include "Foo.h" + +namespace { // Good: 对内函数的声明放在.cpp文件的头部,并声明为匿名namespace或者static限制其作用域 + void Bar() + { + } +} + +... + +void Foo::Fun() +{ + Bar(); +} +``` + +## 头文件依赖 +### 规则5.2.1 禁止头文件循环依赖 +头文件循环依赖,指 a.h 包含 b.h,b.h 包含 c.h,c.h 包含 a.h, 导致任何一个头文件修改,都导致所有包含了a.h/b.h/c.h的代码全部重新编译一遍。 +而如果是单向依赖,如a.h包含b.h,b.h包含c.h,而c.h不包含任何头文件,则修改a.h不会导致包含了b.h/c.h的源代码重新编译。 + +头文件循环依赖直接体现了架构设计上的不合理,可通过优化架构去避免。 + + +### 规则5.2.2 头文件必须编写`#define`保护,防止重复包含 +为防止头文件被重复包含,所有头文件都应当使用 #define 保护;不要使用 #pragma once + +定义包含保护符时,应该遵守如下规则: +1)保护符使用唯一名称; +2)不要在受保护部分的前后放置代码或者注释,文件头注释除外。 + +示例:假定timer模块的timer.h,其目录为timer/include/timer.h,应按如下方式保护: + +```cpp +#ifndef TIMER_INCLUDE_TIMER_H +#define TIMER_INCLUDE_TIMER_H +... +#endif +``` + +### 规则5.2.3 禁止通过声明的方式引用外部函数接口、变量 +只能通过包含头文件的方式使用其他模块或文件提供的接口。 +通过 extern 声明的方式使用外部函数接口、变量,容易在外部接口改变时可能导致声明和定义不一致。 +同时这种隐式依赖,容易导致架构腐化。 + +不符合规范的案例: + +// a.cpp内容 +```cpp +extern int Fun(); // Bad: 通过extern的方式使用外部函数 + +void Bar() +{ + int i = Fun(); + ... +} +``` + +// b.cpp内容 +```cpp +int Fun() +{ + // Do something +} +``` +应该改为: + +// a.cpp内容 +```cpp +#include "b.h" // Good: 通过包含头文件的方式使用其他.cpp提供的接口 + +void Bar() +{ + int i = Fun(); + ... +} +``` + +// b.h内容 +```cpp +int Fun(); +``` + +// b.cpp内容 +```cpp +int Fun() +{ + // Do something +} +``` +例外,有些场景需要引用其内部函数,但并不想侵入代码时,可以 extern 声明方式引用。 +如: +针对某一内部函数进行单元测试时,可以通过 extern 声明来引用被测函数; +当需要对某一函数进行打桩、打补丁处理时,允许 extern 声明该函数。 + +### 规则5.2.4 禁止在extern "C"中包含头文件 +在 extern "C" 中包含头文件,有可能会导致 extern "C" 嵌套,部分编译器对 extern "C" 嵌套层次有限制,嵌套层次太多会编译错误。 + +在C,C++混合编程的情况下,在extern "C"中包含头文件,可能会导致被包含头文件的原有意图遭到破坏,比如链接规范被不正确地更改。 + +示例,存在a.h和b.h两个头文件: + +// a.h内容 +```cpp +... +#ifdef __cplusplus +void Foo(int); +#define A(value) Foo(value) +#else +void A(int) +#endif +``` +// b.h内容 +```cpp +... +#ifdef __cplusplus +extern "C" { +#endif + +#include "a.h" +void B(); + +#ifdef __cplusplus +} +#endif +``` + +使用C++预处理器展开b.h,将会得到 +```cpp +extern "C" { + void Foo(int); + void B(); +} +``` + +按照 a.h 作者的本意,函数 Foo 是一个 C++ 自由函数,其链接规范为 "C++"。 +但在 b.h 中,由于 `#include "a.h"` 被放到了 `extern "C"` 的内部,函数 Foo 的链接规范被不正确地更改了。 + +例外: +如果在 C++ 编译环境中,想引用纯C的头文件,这些C头文件并没有` extern "C"` 修饰。非侵入式的做法是,在 `extern "C"` 中去包含C头文件。 + +### 建议5.2.1尽量避免使用前置声明,而是通过`#include`来包含头文件 +前置声明(forward declaration)通常指类、模板的纯粹声明,没伴随着其定义。 + +- 优点: + 1. 前置声明能够节省编译时间,多余的 #include 会迫使编译器展开更多的文件,处理更多的输入。 + 2. 前置声明能够节省不必要的重新编译的时间。 #include 使代码因为头文件中无关的改动而被重新编译多次。 +- 缺点: + 1. 前置声明隐藏了依赖关系,头文件改动时,用户的代码会跳过必要的重新编译过程。 + 2. 前置声明可能会被库的后续更改所破坏。前置声明模板有时会妨碍头文件开发者变动其 API. 例如扩大形参类型,加个自带默认参数的模板形参等等。 + 3. 前置声明来自命名空间` std::` 的 symbol 时,其行为未定义(在C++11标准规范中明确说明)。 + 4. 前置声明了不少来自头文件的 symbol 时,就会比单单一行的 include 冗长。 + 5. 仅仅为了能前置声明而重构代码(比如用指针成员代替对象成员)会使代码变得更慢更复杂。 + 6. 很难判断什么时候该用前置声明,什么时候该用`#include`,某些场景下面前置声明和`#include`互换以后会导致意想不到的结果。 + +所以我们尽可能避免使用前置声明,而是使用#include头文件来保证依赖关系。 + +# 6 作用域 + +## 命名空间 + +### 建议6.1.1 对于cpp文件中不需要导出的变量,常量或者函数,请使用匿名namespace封装或者用static修饰 +在C++ 2003标准规范中,使用static修饰文件作用域的变量,函数等被标记为deprecated特性,所以更推荐使用匿名namespace。 + +主要原因如下: +1. static在C++中已经赋予了太多的含义,静态函数成员变量,静态成员函数,静态全局变量,静态函数局部变量,每一种都有特殊的处理。 +2. static只能保证变量,常量和函数的文件作用域,但是namespace还可以封装类型等。 +3. 统一namespace来处理C++的作用域,而不需要同时使用static和namespace来管理。 +4. static修饰的函数不能用来实例化模板,而匿名namespace可以。 + +但是不要在 .h 中使用中使用匿名namespace或者static。 + +```cpp +// Foo.cpp + +namespace { + const int MAX_COUNT = 20; + void InternalFun() {}; +} + +void Foo::Fun() +{ + int i = MAX_COUNT; + + InternalFun(); +} + +``` + +### 规则6.1.1 不要在头文件中或者#include之前使用using导入命名空间 +说明:使用using导入命名空间会影响后续代码,易造成符号冲突,所以不要在头文件以及源文件中的#include之前使用using导入命名空间。 +示例: + +```cpp +// 头文件a.h +namespace NamespaceA { + int Fun(int); +} +``` + +```cpp +// 头文件b.h +namespace NamespaceB { + int Fun(int); +} + +using namespace NamespaceB; + +void G() +{ + Fun(1); +} +``` + +```cpp +// 源代码a.cpp +#include "a.h" +using namespace NamespaceA; +#include "b.h" + +void main() +{ + G(); // using namespace NamespaceA在#include “b.h”之前,引发歧义:NamespaceA::Fun,NamespaceB::Fun调用不明确 +} +``` + +对于在头文件中使用using导入单个符号或定义别名,允许在模块自定义名字空间中使用,但禁止在全局名字空间中使用。 +```cpp +// foo.h + +#include +using fancy::string; // Bad,禁止向全局名字空间导入符号 + +namespace Foo { + using fancy::string; // Good,可以在模块自定义名字空间中导入符号 + using MyVector = fancy::vector; // Good,C++11可在自定义名字空间中定义别名 +} +``` + + +## 全局函数和静态成员函数 + +### 建议6.2.1 优先使用命名空间来管理全局函数,如果和某个class有直接关系的,可以使用静态成员函数 +说明:非成员函数放在名字空间内可避免污染全局作用域, 也不要用类+静态成员方法来简单管理全局函数。 如果某个全局函数和某个类有紧密联系, 那么可以作为类的静态成员函数。 + +如果你需要定义一些全局函数,给某个cpp文件使用,那么请使用匿名namespace来管理。 +```cpp +namespace MyNamespace { + int Add(int a, int b); +} + +class File { +public: + static File CreateTempFile(const std::string& fileName); +}; +``` + +## 全局常量和静态成员常量 + +### 建议6.3.1 优先使用命名空间来管理全局常量,如果和某个class有直接关系的,可以使用静态成员常量 +说明:全局常量放在命名空间内可避免污染全局作用域, 也不要用类+静态成员常量来简单管理全局常量。 如果某个全局常量和某个类有紧密联系, 那么可以作为类的静态成员常量。 + +如果你需要定义一些全局常量,只给某个cpp文件使用,那么请使用匿名namespace来管理。 +```cpp +namespace MyNamespace { + const int MAX_SIZE = 100; +} + +class File { +public: + static const std::string SEPARATOR; +}; +``` + +## 全局变量 + +### 建议6.4.1 尽量避免使用全局变量,考虑使用单例模式 +说明:全局变量是可以修改和读取的,那么这样会导致业务代码和这个全局变量产生数据耦合。 +```cpp +int g_counter = 0; + +// a.cpp +g_counter++; + +// b.cpp +g_counter++; + +// c.cpp +cout << g_counter << endl; +``` + +使用单实例模式 +```cpp +class Counter { +public: + static Counter& GetInstance() + { + static Counter counter; + return counter; + } // 单实例实现简单举例 + + void Increase() + { + value_++; + } + + void Print() const + { + std::cout << value_ << std::endl; + } + +private: + Counter() : value_(0) {} + +private: + int value_; +}; + +// a.cpp +Counter::GetInstance().Increase(); + +// b.cpp +Counter::GetInstance().Increase(); + +// c.cpp +Counter::GetInstance().Print(); +``` + +实现单例模式以后,实现了全局唯一一个实例,和全局变量同样的效果,并且单实例提供了更好的封装性。 + +例外:有的时候全局变量的作用域仅仅是模块内部,这样进程空间里面就会有多个全局变量实例,每个模块持有一份,这种场景下是无法使用单例模式解决的。 + +# 7 类 + +## 构造,拷贝构造,赋值和析构函数 +构造,拷贝,移动和析构函数提供了对象的生命周期管理方法: +- 构造函数(constructor): `X()` +- 拷贝构造函数(copy constructor):`X(const X&)` +- 拷贝赋值操作符(copy assignment):`operator=(const X&)` +- 移动构造函数(move constructor):`X(X&&)` *C++11以后提供* +- 移动赋值操作符(move assignment):`operator=(X&&)` *C++11以后提供* +- 析构函数(destructor):`~X()` + +### 规则7.1.1 类的成员变量必须显式初始化 +说明:如果类有成员变量,没有定义构造函数,又没有定义默认构造函数,编译器将自动生成一个构造函数,但编译器生成的构造函数并不会对成员变量进行初始化,对象状态处于一种不确定性。 + +例外: +- 如果类的成员变量具有默认构造函数,那么可以不需要显式初始化。 + +示例:如下代码没有构造函数,私有数据成员无法初始化: +```cpp +class Message { +public: + void ProcessOutMsg() + { + //… + } + +private: + unsigned int msgID_; + unsigned int msgLength_; + unsigned char* msgBuffer_; + std::string someIdentifier_; +}; + +Message message; // message成员变量没有初始化 +message.ProcessOutMsg(); // 后续使用存在隐患 + +// 因此,有必要定义默认构造函数,如下: +class Message { +public: + Message() : msgID_(0), msgLength_(0), msgBuffer_(nullptr) + { + } + + void ProcessOutMsg() + { + // … + } + +private: + unsigned int msgID_; + unsigned int msgLength_; + unsigned char* msgBuffer_; + std::string someIdentifier_; // 具有默认构造函数,不需要显式初始化 +}; +``` + +### 建议7.1.1 成员变量优先使用声明时初始化(C++11)和构造函数初始化列表初始化 +说明:C++11的声明时初始化可以一目了然的看出成员初始值,应当优先使用。如果成员初始化值和构造函数相关,或者不支持C++11,则应当优先使用构造函数初始化列表来初始化成员。相比起在构造函数体中对成员赋值,初始化列表的代码更简洁,执行性能更好,而且可以对const成员和引用成员初始化。 + +```cpp +class Message { +public: + Message() : msgLength_(0) // Good,优先使用初始化列表 + { + msgBuffer_ = nullptr; // Bad,不推荐在构造函数中赋值 + } + +private: + unsigned int msgID_{0}; // Good,C++11中使用 + unsigned int msgLength_; + unsigned char* msgBuffer_; +}; +``` + +### 规则7.1.2 为避免隐式转换,将单参数构造函数声明为explicit +说明:单参数构造函数如果没有用explicit声明,则会成为隐式转换函数。 +示例: + +```cpp +class Foo { +public: + explicit Foo(const string& name): name_(name) + { + } +private: + string name_; +}; + + +void ProcessFoo(const Foo& foo){} + +int main(void) +{ + std::string test = "test"; + ProcessFoo(test); // 编译不通过 + return 0; +} +``` + +上面的代码编译不通过,因为`ProcessFoo`需要的参数是Foo类型,传入的string类型不匹配。 + +如果将Foo构造函数的explicit关键字移除,那么调用`ProcessFoo`传入的string就会触发隐式转换,生成一个临时的Foo对象。往往这种隐式转换是让人迷惑的,并且容易隐藏Bug,得到了一个不期望的类型转换。所以对于单参数的构造函数是要求explicit声明。 + +### 规则7.1.3 如果不需要拷贝构造函数、赋值操作符 / 移动构造函数、赋值操作符,请明确禁止 +说明:如果用户不定义,编译器默认会生成拷贝构造函数和拷贝赋值操作符, 移动构造和移动赋值操作符(移动语义的函数C++11以后才有)。 +如果我们不要使用拷贝构造函数,或者赋值操作符,请明确拒绝: + +1. 将拷贝构造函数或者赋值操作符设置为private,并且不实现: +```cpp +class Foo { +private: + Foo(const Foo&); + Foo& operator=(const Foo&); +}; +``` +2. 使用C++11提供的delete, 请参见后面现代C++的相关章节。 + + +3. 推荐继承NoCopyable、NoMovable,禁止使用DISALLOW_COPY_AND_MOVE,DISALLOW_COPY,DISALLOW_MOVE等宏。 +```cpp +class Foo : public NoCopyable, public NoMovable { +}; +``` +NoCopyable和NoMovable的实现: +```cpp +class NoCopyable { +public: + NoCopyable() = default; + NoCopyable(const NoCopyable&) = delete; + NoCopyable& operator = (NoCopyable&) = delete; +}; + +class NoMovable { +public: + NoMovable() = default; + NoMovable(NoMovable&&) noexcept = delete; + NoMovable& operator = (NoMovable&&) noexcept = delete; +}; +``` + +### 规则7.1.4 拷贝构造和拷贝赋值操作符应该是成对出现或者禁止 +拷贝构造函数和拷贝赋值操作符都是具有拷贝语义的,应该同时出现或者禁止。 + +```cpp +// 同时出现 +class Foo { +public: + ... + Foo(const Foo&); + Foo& operator=(const Foo&); + ... +}; + +// 同时default, C++11支持 +class Foo { +public: + Foo(const Foo&) = default; + Foo& operator=(const Foo&) = default; +}; + +// 同时禁止, C++11可以使用delete +class Foo { +private: + Foo(const Foo&); + Foo& operator=(const Foo&); +}; +``` + +### 规则7.1.5 移动构造和移动赋值操作符应该是成对出现或者禁止 +在C++11中增加了move操作,如果需要某个类支持移动操作,那么需要实现移动构造和移动赋值操作符。 + +移动构造函数和移动赋值操作符都是具有移动语义的,应该同时出现或者禁止。 +```cpp +// 同时出现 +class Foo { +public: + ... + Foo(Foo&&); + Foo& operator=(Foo&&); + ... +}; + +// 同时default, C++11支持 +class Foo { +public: + Foo(Foo&&) = default; + Foo& operator=(Foo&&) = default; +}; + +// 同时禁止, 使用C++11的delete +class Foo { +public: + Foo(Foo&&) = delete; + Foo& operator=(Foo&&) = delete; +}; +``` + +### 规则7.1.6 禁止在构造函数和析构函数中调用虚函数 +说明:在构造函数和析构函数中调用当前对象的虚函数,会导致未实现多态的行为。 +在C++中,一个基类一次只构造一个完整的对象。 + +示例:类Base是基类,Sub是派生类 +```cpp +class Base { +public: + Base(); + virtual void Log() = 0; // 不同的派生类调用不同的日志文件 +}; + +Base::Base() // 基类构造函数 +{ + Log(); // 调用虚函数Log +} + +class Sub : public Base { +public: + virtual void Log(); +}; +``` + +当执行如下语句: +`Sub sub;` +会先执行Sub的构造函数,但首先调用Base的构造函数,由于Base的构造函数调用虚函数Log,此时Log还是基类的版本,只有基类构造完成后,才会完成派生类的构造,从而导致未实现多态的行为。 +同样的道理也适用于析构函数。 + +### 规则7.1.7 多态基类中的拷贝构造函数、拷贝赋值操作符、移动构造函数、移动赋值操作符必须为非public函数或者为delete函数 +如果报一个派生类对象直接赋值给基类对象,会发生切片,只拷贝或者移动了基类部分,损害了多态行为。 +【反例】 +如下代码中,基类没有定义拷贝构造函数或拷贝赋值操作符,编译器会自动生成这两个特殊成员函数, +如果派生类对象赋值给基类对象时就发生切片。可以将此例中的拷贝构造函数和拷贝赋值操作符声明为delete,编译器可检查出此类赋值行为。 +```cpp +class Base { +public: + Base() = default; + virtual ~Base() = default; + ... + virtual void Fun() { std::cout << "Base" << std::endl;} +}; + +class Derived : public Base { + ... + void Fun() override { std::cout << "Derived" << std::endl; } +}; + +void Foo(const Base &base) +{ + Base other = base; // 不符合:发生切片 + other.Fun(); // 调用的时Base类的Fun函数 +} +``` +```cpp +Derived d; +Foo(d); // 传入的是派生类对象 +``` +1. 将拷贝构造函数或者赋值操作符设置为private,并且不实现: + +## 继承 + +### 规则7.2.1 基类的析构函数应该声明为virtual,不准备被继承的类需要声明为final +说明:只有基类析构函数是virtual,通过多态调用的时候才能保证派生类的析构函数被调用。 + +示例:基类的析构函数没有声明为virtual导致了内存泄漏。 +```cpp +class Base { +public: + virtual std::string getVersion() = 0; + + ~Base() + { + std::cout << "~Base" << std::endl; + } +}; +``` + +```cpp +class Sub : public Base { +public: + Sub() : numbers_(nullptr) + { + } + + ~Sub() + { + delete[] numbers_; + std::cout << "~Sub" << std::endl; + } + + int Init() + { + const size_t numberCount = 100; + numbers_ = new (std::nothrow) int[numberCount]; + if (numbers_ == nullptr) { + return -1; + } + + ... + } + + std::string getVersion() + { + return std::string("hello!"); + } +private: + int* numbers_; +}; +``` + +```cpp +int main(int argc, char* args[]) +{ + Base* b = new Sub(); + + delete b; + return 0; +} +``` +由于基类Base的析构函数没有声明为virtual,当对象被销毁时,只会调用基类的析构函数,不会调用派生类Sub的析构函数,导致内存泄漏。 +例外: +NoCopyable、NoMovable这种没有任何行为,仅仅用来做标识符的类,可以不定义虚析构也不定义final。 + +### 规则7.2.2 禁止虚函数使用缺省参数值 +说明:在C++中,虚函数是动态绑定的,但函数的缺省参数却是在编译时就静态绑定的。这意味着你最终执行的函数是一个定义在派生类,但使用了基类中的缺省参数值的虚函数。为了避免虚函数重载时,因参数声明不一致给使用者带来的困惑和由此导致的问题,规定所有虚函数均不允许声明缺省参数值。 +示例:虚函数display缺省参数值text是由编译时刻决定的,而非运行时刻,没有达到多态的目的: +```cpp +class Base { +public: + virtual void Display(const std::string& text = "Base!") + { + std::cout << text << std::endl; + } + + virtual ~Base(){} +}; + +class Sub : public Base { +public: + virtual void Display(const std::string& text = "Sub!") + { + std::cout << text << std::endl; + } + + virtual ~Sub(){} +}; + +int main() +{ + Base* base = new Sub(); + Sub* sub = new Sub(); + + ... + + base->Display(); // 程序输出结果: Base! 而期望输出:Sub! + sub->Display(); // 程序输出结果: Sub! + + delete base; + delete sub; + return 0; +}; +``` + +### 规则7.2.3 禁止重新定义继承而来的非虚函数 +说明:因为非虚函数无法实现动态绑定,只有虚函数才能实现动态绑定:只要操作基类的指针,即可获得正确的结果。 + +示例: +```cpp +class Base { +public: + void Fun(); +}; + +class Sub : public Base { +public: + void Fun(); +}; + +Sub* sub = new Sub(); +Base* base = sub; + +sub->Fun(); // 调用子类的Fun +base->Fun(); // 调用父类的Fun +//... + +``` + +## 多重继承 +在实际开发过程中使用多重继承的场景是比较少的,因为多重继承使用过程中有下面的典型问题: +1. 菱形继承所带来的数据重复,以及名字二义性。因此,C++引入了virtual继承来解决这类问题; +2. 即便不是菱形继承,多个父类之间的名字也可能存在冲突,从而导致的二义性; +3. 如果子类需要扩展或改写多个父类的方法时,造成子类的职责不明,语义混乱; +4. 相对于委托,继承是一种白盒复用,即子类可以访问父类的protected成员, 这会导致更强的耦合。而多重继承,由于耦合了多个父类,相对于单根继承,这会产生更强的耦合关系。 + +多重继承具有下面的优点: +多重继承提供了一种更简单的组合来实现多种接口或者类的组装与复用。 + +所以,对于多重继承的只有下面几种情况下面才允许使用多重继承。 + +### 建议7.3.1 使用多重继承来实现接口分离与多角色组合 +如果某个类需要实现多重接口,可以通过多重继承把多个分离的接口组合起来,类似 scala 语言的 traits 混入。 + +```cpp +class Role1 {}; +class Role2 {}; +class Role3 {}; + +class Object1 : public Role1, public Role2 { + // ... +}; + +class Object2 : public Role2, public Role3 { + // ... +}; + +``` + +在C++标准库中也有类似的实现样例: +```cpp +class basic_istream {}; +class basic_ostream {}; + +class basic_iostream : public basic_istream, public basic_ostream { + +}; +``` + +## 重载 + +重载操作符要有充分理由,而且不要改变操作符原有语义,例如不要使用 ‘+’ 操作符来做减运算。 +操作符重载令代码更加直观,但也有一些不足: +- 混淆直觉,误以为该操作和内建类型一样是高性能的,忽略了性能降低的可能; +- 问题定位时不够直观,按函数名查找比按操作符显然更方便。 +- 重载操作符如果行为定义不直观(例如将‘+’ 操作符来做减运算),会让代码产生混淆。 +- 赋值操作符的重载引入的隐式转换会隐藏很深的bug。可以定义类似Equals()、CopyFrom()等函数来替代=,==操作符。 + + + +# 8 函数 +## 函数设计 +### 规则8.1.1 避免函数过长,函数不超过50行(非空非注释) +函数应该可以一屏显示完 (50行以内),只做一件事情,而且把它做好。 + +过长的函数往往意味着函数功能不单一,过于复杂,或过分呈现细节,未进行进一步抽象。 + +例外:某些实现算法的函数,由于算法的聚合性与功能的全面性,可能会超过50行。 + +即使一个长函数现在工作的非常好, 一旦有人对其修改, 有可能出现新的问题, 甚至导致难以发现的bug。 +建议将其拆分为更加简短并易于管理的若干函数,以便于他人阅读和修改代码。 + +## 内联函数 + +### 建议8.2.1 内联函数不超过10行(非空非注释) +**说明**:内联函数具有一般函数的特性,它与一般函数不同之处只在于函数调用的处理。一般函数进行调用时,要将程序执行权转到被调用函数中,然后再返回到调用它的函数中;而内联函数在调用时,是将调用表达式用内联函数体来替换。 + +内联函数只适合于只有 1~10 行的小函数。对一个含有许多语句的大函数,函数调用和返回的开销相对来说微不足道,也没有必要用内联函数实现,一般的编译器会放弃内联方式,而采用普通的方式调用函数。 + +如果内联函数包含复杂的控制结构,如循环、分支(switch)、try-catch 等语句,一般编译器将该函数视同普通函数。 +**虚函数、递归函数不能被用来做内联函数**。 + +## 函数参数 + +### 建议8.3.1 函数参数使用引用取代指针 + +**说明**:引用比指针更安全,因为它一定非空,且一定不会再指向其他目标;引用不需要检查非法的NULL指针。 + +如果是基于老平台开发的产品,则优先顺从原有平台的处理方式。 +选择 const 避免参数被修改,让代码阅读者清晰地知道该参数不被修改,可大大增强代码可读性。 + +例外:当传入参数为编译期长度未知的数组时,可以使用指针而不是引用。 + +### 建议8.3.2 使用强类型参数,避免使用void* +尽管不同的语言对待强类型和弱类型有自己的观点,但是一般认为c/c++是强类型语言,既然我们使用的语言是强类型的,就应该保持这样的风格。 +好处是尽量让编译器在编译阶段就检查出类型不匹配的问题。 + +使用强类型便于编译器帮我们发现错误,如下代码中注意函数 FooListAddNode 的使用: +```cpp +struct FooNode { + struct List link; + int foo; +}; + +struct BarNode { + struct List link; + int bar; +} + +void FooListAddNode(void *node) // Bad: 这里用 void * 类型传递参数 +{ + FooNode *foo = (FooNode *)node; + ListAppend(&g_FooList, &foo->link); +} + +void MakeTheList() +{ + FooNode *foo = nullptr; + BarNode *bar = nullptr; + ... + + FooListAddNode(bar); // Wrong: 这里本意是想传递参数 foo,但错传了 bar,却没有报错 +} +``` + +1. 可以使用模板函数来实现参数类型的变化。 +2. 可以使用基类指针来实现多态。 + +### 建议8.3.3 函数的参数个数不超过5个 +函数的参数过多,会使得该函数易于受外部变化的影响,从而影响维护工作。函数的参数过多同时也会增大测试的工作量。 + +如果超过可以考虑: +- 看能否拆分函数 +- 看能否将相关参数合在一起,定义结构体 + +# 9 C++其他特性 + +## 常量与初始化 + +不变的值更易于理解、跟踪和分析,所以应该尽可能地使用常量代替变量,定义值的时候,应该把const作为默认的选项。 + +### 规则9.1.1 不允许使用宏来表示常量 + +**说明**:宏是简单的文本替换,在预处理阶段时完成,运行报错时直接报相应的值;跟踪调试时也是显示值,而不是宏名;宏没有类型检查,不安全;宏没有作用域。 + +```cpp +#define MAX_MSISDN_LEN 20 // 不好 + +// C++请使用const常量 +const int MAX_MSISDN_LEN = 20; // 好 + +// 对于C++11以上版本,可以使用constexpr +constexpr int MAX_MSISDN_LEN = 20; +``` + +### 建议9.1.1 一组相关的整型常量应定义为枚举 + +**说明**:枚举比`#define`或`const int`更安全。编译器会检查参数值是否位于枚举取值范围内,避免错误发生。 + +```cpp +// 好的例子: +enum Week { + SUNDAY, + MONDAY, + TUESDAY, + WEDNESDAY, + THURSDAY, + FRIDAY, + SATURDAY +}; + +enum Color { + RED, + BLACK, + BLUE +}; + +void ColorizeCalendar(Week today, Color color); + +ColorizeCalendar(BLUE, SUNDAY); // 编译报错,参数类型错误 + +// 不好的例子: +const int SUNDAY = 0; +const int MONDAY = 1; + +const int BLACK = 0; +const int BLUE = 1; + +bool ColorizeCalendar(int today, int color); +ColorizeCalendar(BLUE, SUNDAY); // 不会报错 +``` + +当枚举值需要对应到具体数值时,须在声明时显式赋值。否则不需要显式赋值,以避免重复赋值,降低维护(增加、删除成员)工作量。 + +```cpp +// 好的例子:S协议里定义的设备ID值,用于标识设备类型 +enum DeviceType { + DEV_UNKNOWN = -1, + DEV_DSMP = 0, + DEV_ISMG = 1, + DEV_WAPPORTAL = 2 +}; +``` + +程序内部使用,仅用于分类的情况,不应该进行显式的赋值。 + +```cpp +// 好的例子:程序中用来标识会话状态的枚举定义 +enum SessionState { + INIT, + CLOSED, + WAITING_FOR_RESPONSE +}; +``` + +应当尽量避免枚举值重复,如必须重复也要用已定义的枚举来修饰 + +```cpp +enum RTCPType { + RTCP_SR = 200, + RTCP_MIN_TYPE = RTCP_SR, + RTCP_RR = 201, + RTCP_SDES = 202, + RTCP_BYE = 203, + RTCP_APP = 204, + RTCP_RTPFB = 205, + RTCP_PSFB = 206, + RTCP_XR = 207, + RTCP_RSI = 208, + RTCP_PUBPORTS = 209, + RTCP_MAX_TYPE = RTCP_PUBPORTS +}; +``` + +### 规则9.1.2 不允许使用魔鬼数字 +所谓魔鬼数字即看不懂、难以理解的数字。 + +魔鬼数字并非一个非黑即白的概念,看不懂也有程度,需要自行判断。 +例如数字 12,在不同的上下文中情况是不一样的: +type = 12; 就看不懂,但 `monthsCount = yearsCount * 12`; 就能看懂。 +数字 0 有时候也是魔鬼数字,比如 `status = 0`; 并不能表达是什么状态。 + +解决途径: +对于局部使用的数字,可以增加注释说明 +对于多处使用的数字,必须定义 const 常量,并通过符号命名自注释。 + +禁止出现下列情况: +没有通过符号来解释数字含义,如` const int ZERO = 0` +符号命名限制了其取值,如 `const int XX_TIMER_INTERVAL_300MS = 300`,直接使用`XX_TIMER_INTERVAL_MS`来表示该常量是定时器的时间间隔。 + +### 规则9.1.3 常量应该保证单一职责 + +**说明**:一个常量只用来表示一个特定功能,即一个常量不能有多种用途。 + +```cpp +// 好的例子:协议A和协议B,手机号(MSISDN)的长度都是20。 +const unsigned int A_MAX_MSISDN_LEN = 20; +const unsigned int B_MAX_MSISDN_LEN = 20; + +// 或者使用不同的名字空间: +namespace Namespace1 { + const unsigned int MAX_MSISDN_LEN = 20; +} + +namespace Namespace2 { + const unsigned int MAX_MSISDN_LEN = 20; +} +``` + +### 规则9.1.4 禁止用memcpy_s、memset_s初始化非POD对象 + +**说明**:`POD`全称是`Plain Old Data`,是C++ 98标准(ISO/IEC 14882, first edition, 1998-09-01)中引入的一个概念,`POD`类型主要包括`int`, `char`, `float`,`double`,`enumeration`,`void`,指针等原始类型以及聚合类型,不能使用封装和面向对象特性(如用户定义的构造/赋值/析构函数、基类、虚函数等)。 + +由于非POD类型比如非聚合类型的class对象,可能存在虚函数,内存布局不确定,跟编译器有关,滥用内存拷贝可能会导致严重的问题。 + +即使对聚合类型的class,使用直接的内存拷贝和比较,破坏了信息隐蔽和数据保护的作用,也不提倡`memcpy_s`、`memset_s`操作。 + +对于POD类型的详细说明请参见附录。 + +### 建议9.1.2 变量使用时才声明并初始化 + +**说明**:变量在使用前未赋初值,是常见的低级编程错误。使用前才声明变量并同时初始化,非常方便地避免了此类低级错误。 + +在函数开始位置声明所有变量,后面才使用变量,作用域覆盖整个函数实现,容易导致如下问题: +* 程序难以理解和维护:变量的定义与使用分离。 +* 变量难以合理初始化:在函数开始时,经常没有足够的信息进行变量初始化,往往用某个默认的空值(比如零)来初始化,这通常是一种浪费,如果变量在被赋于有效值以前使用,还会导致错误。 + +遵循变量作用域最小化原则与就近声明原则, 使得代码更容易阅读,方便了解变量的类型和初始值。特别是,应使用初始化的方式替代声明再赋值。 + +```cpp +// 不好的例子:声明与初始化分离 +string name; // 声明时未初始化:调用缺省构造函数 +name = "zhangsan"; // 再次调用赋值操作符函数;声明与定义在不同的地方,理解相对困难 + +// 好的例子:声明与初始化一体,理解相对容易 +string name("zhangsan"); // 调用构造函数 +``` + + +## 表达式 +### 规则9.2.1 含有变量自增或自减运算的表达式中禁止再次引用该变量 +含有变量自增或自减运算的表达式中,如果再引用该变量,其结果在C++标准中未明确定义。各个编译器或者同一个编译器不同版本实现可能会不一致。 +为了更好的可移植性,不应该对标准未定义的运算次序做任何假设。 + +注意,运算次序的问题不能使用括号来解决,因为这不是优先级的问题。 + +示例: +```cpp +x = b[i] + i++; // Bad: b[i]运算跟 i++,先后顺序并不明确。 +``` +正确的写法是将自增或自减运算单独放一行: +```cpp +x = b[i] + i; +i++; // Good: 单独一行 +``` + +函数参数 +```cpp +Func(i++, i); // Bad: 传递第2个参数时,不确定自增运算有没有发生 +``` + +正确的写法 +```cpp +i++; // Good: 单独一行 +x = Func(i, i); +``` + +### 规则9.2.2 switch语句要有default分支 +大部分情况下,switch语句中要有default分支,保证在遗漏case标签处理时能够有一个缺省的处理行为。 + +特例: +如果switch条件变量是枚举类型,并且 case 分支覆盖了所有取值,则加上default分支处理有些多余。 +现代编译器都具备检查是否在switch语句中遗漏了某些枚举值的case分支的能力,会有相应的warning提示。 + +```cpp +enum Color { + RED = 0, + BLUE +}; + +// 因为switch条件变量是枚举值,这里可以不用加default处理分支 +switch (color) { + case RED: + DoRedThing(); + break; + case BLUE: + DoBlueThing(); + ... + break; +} +``` + +### 建议9.2.1 表达式的比较,应当遵循左侧倾向于变化、右侧倾向于不变的原则 +当变量与常量比较时,如果常量放左边,如 if (MAX == v) 不符合阅读习惯,而 if (MAX > v) 更是难于理解。 +应当按人的正常阅读、表达习惯,将常量放右边。写成如下方式: +```cpp +if (value == MAX) { + +} + +if (value < MAX) { + +} +``` +也有特殊情况,如:`if (MIN < value && value < MAX)` 用来描述区间时,前半段是常量在左的。 + +不用担心将 '==' 误写成 '=',因为` if (value = MAX)` 会有编译告警,其他静态检查工具也会报错。让工具去解决笔误问题,代码要符合可读性第一。 + +### 建议9.2.2 使用括号明确操作符的优先级 +使用括号明确操作符的优先级,防止因默认的优先级与设计思想不符而导致程序出错;同时使得代码更为清晰可读,然而过多的括号会分散代码使其降低了可读性。下面是如何使用括号的建议。 + +- 二元及以上操作符, 如果涉及多种操作符,则应该使用括号 +```cpp +x = a + b + c; /* 操作符相同,可以不加括号 */ +x = Foo(a + b, c); /* 逗号两边的表达式,不需要括号 */ +x = 1 << (2 + 3); /* 操作符不同,需要括号 */ +x = a + (b / 5); /* 操作符不同,需要括号 */ +x = (a == b) ? a : (a – b); /* 操作符不同,需要括号 */ +``` + + +## 类型转换 + +避免使用类型分支来定制行为:类型分支来定制行为容易出错,是企图用C++编写C代码的明显标志。这是一种很不灵活的技术,要添加新类型时,如果忘记修改所有分支,编译器也不会告知。使用模板和虚函数,让类型自己而不是调用它们的代码来决定行为。 + +建议避免类型转换,我们在代码的类型设计上应该考虑到每种数据的数据类型是什么,而不是应该过度使用类型转换来解决问题。在设计某个基本类型的时候,请考虑: +- 是无符号还是有符号的 +- 是适合float还是double +- 是使用int8,int16,int32还是int64,确定整形的长度 + +但是我们无法禁止使用类型转换,因为C++语言是一门面向机器编程的语言,涉及到指针地址,并且我们会与各种第三方或者底层API交互,他们的类型设计不一定是合理的,在这个适配的过程中很容易出现类型转换。 + +例外:在调用某个函数的时候,如果我们不想处理函数结果,首先要考虑这个是否是你的最好的选择。如果确实不想处理函数的返回值,那么可以使用(void)转换来解决。 + +### 规则9.3.1 如果确定要使用类型转换,请使用由C++提供的类型转换,而不是C风格的类型转换 + +**说明**: + +C++提供的类型转换操作比C风格更有针对性,更易读,也更加安全,C++提供的转换有: +- 类型转换: +1. `dynamic_cast`:主要用于继承体系下行转换,`dynamic_cast`具有类型检查的功能,请做好基类和派生类的设计,避免使用dynamic_cast来进行转换。 +2. `static_cast`:和C风格转换相似可做值的强制转换,或上行转换(把派生类的指针或引用转换成基类的指针或引用)。该转换经常用于消除多重继承带来的类型歧义,是相对安全的。如果是纯粹的算数转换,那么请使用后面的大括号转换方式。 +3. `reinterpret_cast`:用于转换不相关的类型。`reinterpret_cast`强制编译器将某个类型对象的内存重新解释成另一种类型,这是一种不安全的转换,建议尽可能少用`reinterpret_cast`。 +4. `const_cast`:用于移除对象的`const`属性,使对象变得可修改,这样会破坏数据的不变性,建议尽可能少用。 + +- 算数转换: (C++11开始支持) + 对于那种算数转换,并且类型信息没有丢失的,比如float到double, int32到int64的转换,推荐使用大括号的初始方式。 +```cpp + double d{ someFloat }; + int64_t i{ someInt32 }; +``` + +### 建议9.3.1 避免使用`dynamic_cast` +1. `dynamic_cast`依赖于C++的RTTI, 让程序员在运行时识别C++类对象的类型。 +2. `dynamic_cast`的出现一般说明我们的基类和派生类设计出现了问题,派生类破坏了基类的契约,不得不通过`dynamic_cast`转换到子类进行特殊处理,这个时候更希望来改善类的设计,而不是通过`dynamic_cast`来解决问题。 + +### 建议9.3.2 避免使用`reinterpret_cast` + +**说明**:`reinterpret_cast`用于转换不相关类型。尝试用`reinterpret_cast`将一种类型强制转换另一种类型,这破坏了类型的安全性与可靠性,是一种不安全的转换。不同类型之间尽量避免转换。 + +### 建议9.3.3 避免使用`const_cast` + +**说明**:`const_cast`用于移除对象的`const`和`volatile`性质。 + +使用const_cast转换后的指针或者引用来修改const对象,行为是未定义的。 + +```cpp +// 不好的例子 +const int i = 1024; +int* p = const_cast(&i); +*p = 2048; // 未定义行为 +``` + +```cpp +// 不好的例子 +class Foo { +public: + Foo() : i(3) {} + + void Fun(int v) + { + i = v; + } + +private: + int i; +}; + +int main(void) +{ + const Foo f; + Foo* p = const_cast(&f); + p->Fun(8); // 未定义行为 +} + +``` + + +## 资源分配和释放 + +### 规则9.4.1 单个对象释放使用delete,数组对象释放使用delete [] +说明:单个对象删除使用delete, 数组对象删除使用delete [],原因: + +- 调用new所包含的动作:从系统中申请一块内存,并调用此类型的构造函数。 +- 调用new[n]所包含的动作:申请可容纳n个对象的内存,并且对每一个对象调用其构造函数。 +- 调用delete所包含的动作:先调用相应的析构函数,再将内存归还系统。 +- 调用delete[]所包含的动作:对每一个对象调用析构函数,再释放所有内存 + +如果new和delete的格式不匹配,结果是未知的。对于非class类型, new和delete不会调用构造与析构函数。 + +错误写法: +```cpp +const int MAX_ARRAY_SIZE = 100; +int* numberArray = new int[MAX_ARRAY_SIZE]; +... +delete numberArray; +numberArray = nullptr; +``` + +正确写法: +```cpp +const int MAX_ARRAY_SIZE = 100; +int* numberArray = new int[MAX_ARRAY_SIZE]; +... +delete[] numberArray; +numberArray = nullptr; +``` + +### 建议9.4.1 使用 RAII 特性来帮助追踪动态分配 + +说明:RAII是“资源获取就是初始化”的缩语(Resource Acquisition Is Initialization),是一种利用对象生命周期来控制程序资源(如内存、文件句柄、网络连接、互斥量等等)的简单技术。 + +RAII 的一般做法是这样的:在对象构造时获取资源,接着控制对资源的访问使之在对象的生命周期内始终保持有效,最后在对象析构的时候释放资源。这种做法有两大好处: +- 我们不需要显式地释放资源。 +- 对象所需的资源在其生命期内始终保持有效。这样,就不必检查资源有效性的问题,可以简化逻辑、提高效率。 + + +示例:使用RAII不需要显式地释放互斥资源。 + +```cpp +class LockGuard { +public: + LockGuard(const LockType& lockType): lock_(lockType) + { + lock_.Aquire(); + } + + ~LockGuard() + { + lock_.Relase(); + } + +private: + LockType lock_; +}; + + +bool Update() +{ + LockGuard lockGuard(mutex); + if (...) { + return false; + } else { + // 操作数据 + } + + return true; +} +``` + +## 标准库 + +STL标准模板库在不同产品使用程度不同,这里列出一些基本规则和建议,供各团队参考。 + +### 规则9.5.1 不要保存std::string的c_str()返回的指针 + +说明:在C++标准中并未规定string::c_str()指针持久有效,因此特定STL实现完全可以在调用string::c_str()时返回一个临时存储区并很快释放。所以为了保证程序的可移植性,不要保存string::c_str()的结果,而是在每次需要时直接调用。 + +示例: + +```cpp +void Fun1() +{ + std::string name = "demo"; + const char* text = name.c_str(); // 表达式结束以后,name的生命周期还在,指针有效 + + // 如果中间调用了string的非const成员函数,导致string被修改,比如operator[], begin()等 + // 可能会导致text的内容不可用,或者不是原来的字符串 + name = "test"; + name[1] = '2'; + + // 后续使用text指针,其字符串内容不再是"demo" +} + +void Fun2() +{ + std::string name = "demo"; + std::string test = "test"; + const char* text = (name + test).c_str(); // 表达式结束以后,+号产生的临时对象被销毁,指针无效 + + // 后续使用text指针,其已不再指向合法内存空间 +} +``` +例外:在少数对性能要求非常高的代码中,为了适配已有的只接受const char*类型入参的函数,可以临时保存string::c_str()返回的指针。但是必须严格保证string对象的生命周期长于所保存指针的生命周期,并且保证在所保存指针的生命周期内,string对象不会被修改。 + + +### 建议9.5.1 使用std::string代替char* + +说明:使用string代替`char*`有很多优势,比如: +1. 不用考虑结尾的’\0’; +2. 可以直接使用+, =, ==等运算符以及其它字符串操作函数; +3. 不需要考虑内存分配操作,避免了显式的new/delete,以及由此导致的错误; + +需要注意的是某些stl实现中string是基于写时复制策略的,这会带来2个问题,一是某些版本的写时复制策略没有实现线程安全,在多线程环境下会引起程序崩溃;二是当与动态链接库相互传递基于写时复制策略的string时,由于引用计数在动态链接库被卸载时无法减少可能导致悬挂指针。因此,慎重选择一个可靠的stl实现对于保证程序稳定是很重要的。 + +例外: +当调用系统或者其它第三方库的API时,针对已经定义好的接口,只能使用`char*`。但是在调用接口之前都可以使用string,在调用接口时使用string::c_str()获得字符指针。 +当在栈上分配字符数组当作缓冲区使用时,可以直接定义字符数组,不要使用string,也没有必要使用类似`vector`等容器。 + +### 规则9.5.2 禁止使用auto_ptr +说明:在stl库中的std::auto_ptr具有一个隐式的所有权转移行为,如下代码: +```cpp +auto_ptr p1(new T); +auto_ptr p2 = p1; +``` +当执行完第2行语句后,p1已经不再指向第1行中分配的对象,而是变为nullptr。正因为如此,auto_ptr不能被置于各种标准容器中。 +转移所有权的行为通常不是期望的结果。对于必须转移所有权的场景,也不应该使用隐式转移的方式。这往往需要程序员对使用auto_ptr的代码保持额外的谨慎,否则出现对空指针的访问。 +使用auto_ptr常见的有两种场景,一是作为智能指针传递到产生auto_ptr的函数外部,二是使用auto_ptr作为RAII管理类,在超出auto_ptr的生命周期时自动释放资源。 +对于第1种场景,可以使用std::shared_ptr来代替。 +对于第2种场景,可以使用C++11标准中的std::unique_ptr来代替。其中std::unique_ptr是std::auto_ptr的代替品,支持显式的所有权转移。 + +例外: +在C++11标准得到普遍使用之前,在一定需要对所有权进行转移的场景下,可以使用std::auto_ptr,但是建议对std::auto_ptr进行封装,并禁用封装类的拷贝构造函数和赋值运算符,以使该封装类无法用于标准容器。 + + +### 建议9.5.2 使用新的标准头文件 + +说明: +使用C++的标准头文件时,请使用``这样的,而不是``这种的。 + +## const的用法 +在声明的变量或参数前加上关键字 const 用于指明变量值不可被篡改 (如 `const int foo` ). 为类中的函数加上 const 限定符表明该函数不会修改类成员变量的状态 (如 `class Foo { int Bar(char c) const; };`)。 const 变量, 数据成员, 函数和参数为编译时类型检测增加了一层保障, 便于尽早发现错误。因此, 我们强烈建议在任何可能的情况下使用 const。 +有时候,使用C++11的constexpr来定义真正的常量可能更好。 + +### 规则9.6.1 对于指针和引用类型的形参,如果是不需要修改的,请使用const +不变的值更易于理解/跟踪和分析,把const作为默认选项,在编译时会对其进行检查,使代码更牢固/更安全。 +```cpp +class Foo; + +void PrintFoo(const Foo& foo); +``` + +### 规则9.6.2 对于不会修改成员变量的成员函数请使用const修饰 +尽可能将成员函数声明为 const。 访问函数应该总是 const。只要不修改数据成员的成员函数,都声明为const。 +对于虚函数,应当从设计意图上考虑继承链上的所有类是否需要在此虚函数中修改数据成员,而不是仅关注单个类的实现。 +```cpp +class Foo { +public: + + // ... + + int PrintValue() const // const修饰成员函数,不会修改成员变量 + { + std::cout << value_ << std::endl; + } + + int GetValue() const // const修饰成员函数,不会修改成员变量 + { + return value_; + } + +private: + int value_; +}; +``` + +### 建议9.6.1 初始化后不会再修改的成员变量定义为const + +```cpp +class Foo { +public: + Foo(int length) : dataLength_(length) {} +private: + const int dataLength_; +}; +``` + +## 异常 + +### 建议9.7.1 C++11中,如果函数不会抛出异常,声明为`noexcept` +**理由** +1. 如果函数不会抛出异常,声明为`noexcept`可以让编译器最大程度的优化函数,如减少执行路径,提高错误退出的效率。 +2. `vector`等STL容器,为了保证接口的健壮性,如果保存元素的`move运算符`没有声明为`noexcept`,则在容器扩张搬移元素时不会使用`move机制`,而使用`copy机制`,带来性能损失的风险。如果一个函数不能抛出异常,或者一个程序并没有截获某个函数所抛出的异常并进行处理,那么这个函数可以用新的`noexcept`关键字对其进行修饰,表示这个函数不会抛出异常或者抛出的异常不会被截获并处理。例如: + +```cpp +extern "C" double sqrt(double) noexcept; // 永远不会抛出异常 + +// 即使可能抛出异常,也可以使用 noexcept +// 这里不准备处理内存耗尽的异常,简单地将函数声明为noexcept +std::vector MyComputation(const std::vector& v) noexcept +{ + std::vector res = v; // 可能会抛出异常 + // do something + return res; +} +``` + +**示例** + +```cpp +RetType Function(Type params) noexcept; // 最大的优化 +RetType Function(Type params); // 更少的优化 + +// std::vector 的 move 操作需要声明 noexcept +class Foo1 { +public: + Foo1(Foo1&& other); // no noexcept +}; + +std::vector a1; +a1.push_back(Foo1()); +a1.push_back(Foo1()); // 触发容器扩张,搬移已有元素时调用copy constructor + +class Foo2 { +public: + Foo2(Foo2&& other) noexcept; +}; + +std::vector a2; +a2.push_back(Foo2()); +a2.push_back(Foo2()); // 触发容器扩张,搬移已有元素时调用move constructor +``` + +**注意** +默认构造函数、析构函数、`swap`函数,`move操作符`都不应该抛出异常。 + +## 模板与泛型编程 + +### 规则9.8.1 禁止在OpenHarmony项目中进行泛型编程 +泛型编程和面向对象编程的思想、理念以及技巧完全不同,OpenHarmony项目主流使用面向对象的思想。 + +C++提供了强大的泛型编程的机制,能够实现非常灵活简洁的类型安全的接口,实现类型不同但是行为相同的代码复用。 + +但是C++泛型编程存在以下缺点: + +1. 对泛型编程不很熟练的人,常常会将面向对象的逻辑写成模板、将不依赖模板参数的成员写在模板中等等导致逻辑混乱代码膨胀诸多问题。 +2. 模板编程所使用的技巧对于使用c++不是很熟练的人是比较晦涩难懂的。在复杂的地方使用模板的代码让人更不容易读懂,并且debug 和维护起来都很麻烦。 +3. 模板编程经常会导致编译出错的信息非常不友好: 在代码出错的时候, 即使这个接口非常的简单, 模板内部复杂的实现细节也会在出错信息显示. 导致这个编译出错信息看起来非常难以理解。 +4. 模板如果使用不当,会导致运行时代码过度膨胀。 +5. 模板代码难以修改和重构。模板的代码会在很多上下文里面扩展开来, 所以很难确认重构对所有的这些展开的代码有用。 + +所以,OpenHarmony大部分部件禁止模板编程,仅有 __少数部件__ 可以使用泛型编程,并且开发的模板要有详细的注释。 +例外: +1. stl适配层可以使用模板 + +## 宏 +在C++语言中,我们强烈建议尽可能少使用复杂的宏 +- 对于常量定义,请按照前面章节所述,使用const或者枚举; +- 对于宏函数,尽可能简单,并且遵循下面的原则,并且优先使用内联函数,模板函数等进行替换。 + +```cpp +// 不推荐使用宏函数 +#define SQUARE(a, b) ((a) * (b)) + +// 请使用模板函数,内联函数等来替换。 +template T Square(T a, T b) { return a * b; } +``` + +如果需要使用宏,请参考C语言规范的相关章节。 +**例外**:一些通用且成熟的应用,如:对 new, delete 的封装处理,可以保留对宏的使用。 + +# 10 现代C++特性 + +随着 ISO 在2011年发布 C++11 语言标准,以及2017年3月发布 C++17 ,现代C++(C++11/14/17等)增加了大量提高编程效率、代码质量的新语言特性和标准库。 +本章节描述了一些可以帮助团队更有效率的使用现代C++,规避语言陷阱的指导意见。 + +## 代码简洁性和安全性提升 +### 建议10.1.1 合理使用`auto` +**理由** + +* `auto`可以避免编写冗长、重复的类型名,也可以保证定义变量时初始化。 +* `auto`类型推导规则复杂,需要仔细理解。 +* 如果能够使代码更清晰,继续使用明确的类型,且只在局部变量使用`auto`。 + +**示例** + +```cpp +// 避免冗长的类型名 +std::map::iterator iter = m.find(val); +auto iter = m.find(val); + +// 避免重复类型名 +class Foo {...}; +Foo* p = new Foo; +auto p = new Foo; + +// 保证初始化 +int x; // 编译正确,没有初始化 +auto x; // 编译失败,必须初始化 +``` + +auto 的类型推导可能导致困惑: + +```cpp +auto a = 3; // int +const auto ca = a; // const int +const auto& ra = a; // const int& +auto aa = ca; // int, 忽略 const 和 reference +auto ila1 = { 10 }; // std::initializer_list +auto ila2{ 10 }; // std::initializer_list + +auto&& ura1 = x; // int& +auto&& ura2 = ca; // const int& +auto&& ura3 = 10; // int&& + +const int b[10]; +auto arr1 = b; // const int* +auto& arr2 = b; // const int(&)[10] +``` + +如果没有注意 `auto` 类型推导时忽略引用,可能引入难以发现的性能问题: + +```cpp +std::vector v; +auto s1 = v[0]; // auto 推导为 std::string,拷贝 v[0] +``` + +如果使用`auto`定义接口,如头文件中的常量,可能因为开发人员修改了值,而导致类型发生变化。 + +### 规则10.1.1 在重写虚函数时请使用`override`或`final`关键字 +**理由** +`override`和`final`关键字都能保证函数是虚函数,且重写了基类的虚函数。如果子类函数与基类函数原型不一致,则产生编译告警。`final`还保证虚函数不会再被子类重写。 + +使用`override`或`final`关键字后,如果修改了基类虚函数原型,但忘记修改子类重写的虚函数,在编译期就可以发现。也可以避免有多个子类时,重写虚函数的修改遗漏。 + +**示例** + +```cpp +class Base { +public: + virtual void Foo(); + virtual void Foo(int var); + void Bar(); +}; + +class Derived : public Base { +public: + void Foo() const override; // 编译失败: Derived::Foo 和 Base::Foo 原型不一致,不是重写 + void Foo() override; // 正确: Derived::Foo 重写 Base::Foo + void Foo(int var) final; // 正确: Derived::Foo(int) 重写 Base::Foo(int),且Derived的派生类不能再重写此函数 + void Bar() override; // 编译失败: Base::Bar 不是虚函数 +}; +``` + +**总结** +1. 基类首次定义虚函数,使用`virtual`关键字 +2. 子类重写基类虚函数(包括析构函数),使用`override`或`final`关键字(但不要两者一起使用),并且不使用`virtual`关键字 +3. 非虚函数,`virtual`、`override`和`final`都不使用 + +### 规则10.1.2 使用`delete`关键字删除函数 +**理由** +相比于将类成员函数声明为`private`但不实现,`delete`关键字更明确,且适用范围更广。 + +**示例** + +```cpp +class Foo { +private: + // 只看头文件不知道拷贝构造是否被删除 + Foo(const Foo&); +}; + +class Foo { +public: + // 明确删除拷贝赋值函数 + Foo& operator=(const Foo&) = delete; +}; +``` + +`delete`关键字还支持删除非成员函数 + +```cpp +template +void Process(T value); + +template<> +void Process(void) = delete; +``` + +### 规则10.1.3 使用`nullptr`,而不是`NULL`或`0` +**理由** +长期以来,C++没有一个代表空指针的关键字,这是一件很尴尬的事: + +```cpp +#define NULL ((void *)0) + +char* str = NULL; // 错误: void* 不能自动转换为 char* + +void(C::*pmf)() = &C::Func; +if (pmf == NULL) {} // 错误: void* 不能自动转换为指向成员函数的指针 +``` + +如果把`NULL`被定义为`0`或`0L`。可以解决上面的问题。 + +或者在需要空指针的地方直接使用`0`。但这引入另一个问题,代码不清晰,特别是使用`auto`自动推导: + +```cpp +auto result = Find(id); +if (result == 0) { // Find() 返回的是 指针 还是 整数? + // do something +} +``` + +`0`字面上是`int`类型(`0L`是`long`),所以`NULL`和`0`都不是指针类型。 +当重载指针和整数类型的函数时,传递`NULL`或`0`都调用到整数类型重载的函数: + +```cpp +void F(int); +void F(int*); + +F(0); // 调用 F(int),而非 F(int*) +F(NULL); // 调用 F(int),而非 F(int*) +``` + +另外,`sizeof(NULL) == sizeof(void*)`并不一定总是成立的,这也是一个潜在的风险。 + +总结: 直接使用`0`或`0L`,代码不清晰,且无法做到类型安全;使用`NULL`无法做到类型安全。这些都是潜在的风险。 + +`nullptr`的优势不仅仅是在字面上代表了空指针,使代码清晰,而且它不再是一个整数类型。 + +`nullptr`是`std::nullptr_t`类型,而`std::nullptr_t`可以隐式的转换为所有的原始指针类型,这使得`nullptr`可以表现成指向任意类型的空指针。 + +```cpp +void F(int); +void F(int*); +F(nullptr); // 调用 F(int*) + +auto result = Find(id); +if (result == nullptr) { // Find() 返回的是 指针 + // do something +} +``` + +### 规则10.1.4 使用`using`而非`typedef` +在`C++11`之前,可以通过`typedef`定义类型的别名。没人愿意多次重复`std::map>`这样的代码。 + +```cpp +typedef std::map> SomeType; +``` + +类型的别名实际是对类型的封装。而通过封装,可以让代码更清晰,同时在很大程度上避免类型变化带来的散弹式修改。 +在`C++11`之后,提供`using`,实现`声明别名(alias declarations)`: + +```cpp +using SomeType = std::map>; +``` + +对比两者的格式: + +```cpp +typedef Type Alias; // Type 在前,还是 Alias 在前 +using Alias = Type; // 符合'赋值'的用法,容易理解,不易出错 +``` + +如果觉得这点还不足以切换到`using`,我们接着看看`模板别名(alias template)`: + +```cpp +// 定义模板的别名,一行代码 +template +using MyAllocatorVector = std::vector>; + +MyAllocatorVector data; // 使用 using 定义的别名 + +template +class MyClass { +private: + MyAllocatorVector data_; // 模板类中使用 using 定义的别名 +}; +``` + +而`typedef`不支持带模板参数的别名,只能"曲线救国": + +```cpp +// 通过模板包装 typedef,需要实现一个模板类 +template +struct MyAllocatorVector { + typedef std::vector> type; +}; + +MyAllocatorVector::type data; // 使用 typedef 定义的别名,多写 ::type + +template +class MyClass { +private: + typename MyAllocatorVector::type data_; // 模板类中使用,除了 ::type,还需要加上 typename +}; +``` + +### 规则10.1.5 禁止使用std::move操作const对象 +从字面上看,`std::move`的意思是要移动一个对象。而const对象是不允许修改的,自然也无法移动。因此用`std::move`操作const对象会给代码阅读者带来困惑。 +在实际功能上,`std::move`会把对象转换成右值引用类型;对于const对象,会将其转换成const的右值引用。由于极少有类型会定义以const右值引用为参数的移动构造函数和移动赋值操作符,因此代码实际功能往往退化成了对象拷贝而不是对象移动,带来了性能上的损失。 + +**错误示例:** +```cpp +std::string g_string; +std::vector g_stringList; + +void func() +{ + const std::string myString = "String content"; + g_string = std::move(myString); // bad:并没有移动myString,而是进行了复制 + const std::string anotherString = "Another string content"; + g_stringList.push_back(std::move(anotherString)); // bad:并没有移动anotherString,而是进行了复制 +} +``` + +## 智能指针 +### 规则10.2.1 单例、类的成员等所有机不会被多方持有的优先使用原始指针源而不是智能指针 +**理由** +智能指针会自动释放对象资源避免资源泄露,但会带额外的资源开销。如:智能指针自动生成的类、构造和析构的开销、内存占用多等。 + +单例、类的成员等对象的所有权不会被多方持有的情况,仅在类析构中释放资源即可。不应该使用智能指针而增额外的开销。 + +**示例** + +```cpp +class Foo; +class Base { +public: + Base() {} + virtual ~Base() + { + delete foo_; + } +private: + Foo* foo_ = nullptr; +}; +``` + +**例外** +1. 返回创建的对象时,需要指针销毁函数的可以使用智能指针。 +```cpp +class User; +class Foo { +public: + std::unique_ptr CreateUniqueUser() // 可使用unique_ptr保证对象的创建和释放在同一runtime + { + sptr ipcUser = iface_cast(remoter); + return std::unique_ptr(::new User(ipcUser), [](User *user) { + user->Close(); + ::delete user; + }); + } + + std::shared_ptr CreateSharedUser() // 可使用shared_ptr保证对象的创建和释放在同一runtime中 + { + sptr ipcUser = iface_cast(remoter); + return std::shared_ptr(ipcUser.GetRefPtr(), [ipcUser](User *user) mutable { + ipcUser = nullptr; + }); + } +}; +``` +2. 返回创建的对象且对象需要被多方引用时,可以使用shared_ptr。 + +### 规则10.2.2 使用`std::make_unique`而不是`new`创建`unique_ptr` +**理由** +1. `make_unique`提供了更简洁的创建方式 +2. 保证了复杂表达式的异常安全 + +**示例** + +```cpp +// 不好:两次出现 MyClass,重复导致不一致风险 +std::unique_ptr ptr(new MyClass(0, 1)); +// 好:只出现一次 MyClass,不存在不一致的可能 +auto ptr = std::make_unique(0, 1); +``` + +重复出现类型可能导致非常严重的问题,且很难发现: + +```cpp +// 编译正确,但new和delete不配套 +std::unique_ptr ptr(new uint8_t[10]); +std::unique_ptr ptr(new uint8_t); +// 非异常安全: 编译器可能按如下顺序计算参数: +// 1. 分配 Foo 的内存, +// 2. 构造 Foo, +// 3. 调用 Bar, +// 4. 构造 unique_ptr. +// 如果 Bar 抛出异常, Foo 不会被销毁,产生内存泄露。 +F(unique_ptr(new Foo()), Bar()); + +// 异常安全: 调用函数不会被打断. +F(make_unique(), Bar()); +``` + +**例外** +`std::make_unique`不支持自定义`deleter`。 +在需要自定义`deleter`的场景,建议在自己的命名空间实现定制版本的`make_unique`。 +使用`new`创建自定义`deleter`的`unique_ptr`是最后的选择。 + +### 规则10.2.4 使用`std::make_shared`而不是`new`创建`shared_ptr` +**理由** +使用`std::make_shared`除了类似`std::make_unique`一致性等原因外,还有性能的因素。 +`std::shared_ptr`管理两个实体: +* 控制块(存储引用计数,`deleter`等) +* 管理对象 + +`std::make_shared`创建`std::shared_ptr`,会一次性在堆上分配足够容纳控制块和管理对象的内存。而使用`std::shared_ptr(new MyClass)`创建`std::shared_ptr`,除了`new MyClass`会触发一次堆分配外,`std::shard_ptr`的构造函数还会触发第二次堆分配,产生额外的开销。 + +**例外** +类似`std::make_unique`,`std::make_shared`不支持定制`deleter` + +## Lambda +### 建议10.3.1 当函数不能工作时选择使用`lambda`(捕获局部变量,或编写局部函数) +**理由** +函数无法捕获局部变量或在局部范围内声明;如果需要这些东西,尽可能选择`lambda`,而不是手写的`functor`。 +另一方面,`lambda`和`functor`不会重载;如果需要重载,则使用函数。 +如果`lambda`和函数都可以的场景,则优先使用函数;尽可能使用最简单的工具。 + +**示例** + +```cpp +// 编写一个只接受 int 或 string 的函数 +// -- 重载是自然的选择 +void F(int); +void F(const string&); + +// 需要捕获局部状态,或出现在语句或表达式范围 +// -- lambda 是自然的选择 +vector v = LotsOfWork(); +for (int taskNum = 0; taskNum < max; ++taskNum) { + pool.Run([=, &v] {...}); +} +pool.Join(); +``` + +### 规则10.3.1 非局部范围使用`lambdas`,避免使用按引用捕获 +**理由** +非局部范围使用`lambdas`包括返回值,存储在堆上,或者传递给其它线程。局部的指针和引用不应该在它们的范围外存在。`lambdas`按引用捕获就是把局部对象的引用存储起来。如果这会导致超过局部变量生命周期的引用存在,则不应该按引用捕获。 + +**示例** + +```cpp +// 不好 +void Foo() +{ + int local = 42; + // 按引用捕获 local. + // 当函数返回后,local 不再存在, + // 因此 Process() 的行为未定义! + threadPool.QueueWork([&]{ Process(local); }); +} + +// 好 +void Foo() +{ + int local = 42; + // 按值捕获 local。 + // 因为拷贝,Process() 调用过程中,local 总是有效的 + threadPool.QueueWork([=]{ Process(local); }); +} +``` + +### 建议10.3.2 如果捕获`this`,则显式捕获所有变量 +**理由** +在成员函数中的`[=]`看起来是按值捕获。但因为是隐式的按值获取了`this`指针,并能够操作所有成员变量,数据成员实际是按引用捕获的,一般情况下建议避免。如果的确需要这样做,明确写出对`this`的捕获。 + +**示例** + +```cpp +class MyClass { +public: + void Foo() + { + int i = 0; + + auto Lambda = [=]() { Use(i, data_); }; // 不好: 看起来像是拷贝/按值捕获,成员变量实际上是按引用捕获 + + data_ = 42; + Lambda(); // 调用 use(42); + data_ = 43; + Lambda(); // 调用 use(43); + + auto Lambda2 = [i, this]() { Use(i, data_); }; // 好,显式指定按值捕获,最明确,最少的混淆 + } + +private: + int data_ = 0; +}; +``` + +### 建议10.3.3 避免使用默认捕获模式 +**理由** +lambda表达式提供了两种默认捕获模式:按引用(&)和按值(=)。 +默认按引用捕获会隐式的捕获所有局部变量的引用,容易导致访问悬空引用。相比之下,显式的写出需要捕获的变量可以更容易的检查对象生命周期,减小犯错可能。 +默认按值捕获会隐式的捕获this指针,且难以看出lambda函数所依赖的变量是哪些。如果存在静态变量,还会让阅读者误以为lambda拷贝了一份静态变量。 +因此,通常应当明确写出lambda需要捕获的变量,而不是使用默认捕获模式。 + +**错误示例** +```cpp +auto func() +{ + int addend = 5; + static int baseValue = 3; + + return [=]() { // 实际上只复制了addend + ++baseValue; // 修改会影响静态变量的值 + return baseValue + addend; + }; +} +``` + +**正确示例** +```cpp +auto func() +{ + int addend = 5; + static int baseValue = 3; + + return [addend, baseValue = baseValue]() mutable { // 使用C++14的捕获初始化拷贝一份变量 + ++baseValue; // 修改自己的拷贝,不会影响静态变量的值 + return baseValue + addend; + }; +} +``` + +参考:《Effective Modern C++》:Item 31: Avoid default capture modes. + +## 接口 +### 建议10.4.1 不涉及所有权的场景,使用`T*`或`T&`作为参数,而不是智能指针 +**理由** +1. 只在需要明确所有权机制时,才通过智能指针转移或共享所有权. +2. 通过智能指针传递,限制了函数调用者必须使用智能指针(如调用者希望传递`this`)。 +3. 传递共享所有权的智能指针存在运行时的开销。 + +**示例** + +```cpp +// 接受任何 int* +void F(int*); + +// 只能接受希望转移所有权的 int +void G(unique_ptr); + +// 只能接受希望共享所有权的 int +void G(shared_ptr); + +// 不改变所有权,但需要特定所有权的调用者 +void H(const unique_ptr&); + +// 接受任何 int +void H(int&); + +// 不好 +void F(shared_ptr& w) +{ + // ... + Use(*w); // 只使用 w -- 完全不涉及生命周期管理 + // ... +}; +``` + diff --git a/website/docs/_posts/contribute/OpenHarmony-security-design-guide.md b/website/docs/_posts/contribute/OpenHarmony-security-design-guide.md new file mode 100644 index 0000000000000000000000000000000000000000..e505e543bfb71a5c9cbf7cbb2074952ba0524482 --- /dev/null +++ b/website/docs/_posts/contribute/OpenHarmony-security-design-guide.md @@ -0,0 +1,216 @@ +--- +title: OpenHarmony-security-design-guide.md +permalink: /pages/extra/d44702/ +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +date: 2021-12-30 18:17:45 +--- +# OpenHarmony安全设计规范 + +本文档主要参考业界标准和最佳实践,提供OpenHarmony安全设计规范,用于指导开发者进行设计。 + +## 1.访问通道控制 + +1-1 为了防止系统和资源被非法访问,除非标准协议约定,所有能对系统进行管理的接口,应具备接入认证机制并缺省启用。 + +**说明:**为减少系统攻击面,对于可对系统进行管理(包括配置、升级、调试等)的接口必须要启用认证机制,避免未授权的访问。 + +1-2 只保留运行维护所必须的对外通信连接,关闭不需要连接、端口。 + +**说明:**关闭不必要的通信端口,可大大降低安全威胁,是系统安全防护的基础手段。 + +## 2.应用安全 + +2-1 对于每一个需要授权访问的请求都需核实请求方的会话标识是否合法、请求方是否被授权执行此操作。 + +**说明:**避免越权访问。 + +2-2 认证处理过程在客户端实现是不可靠的,可被轻易绕过,因此对用户的最终认证处理过程必须放到服务端进行。 + +## 3.加密 + +3-1 应该使用经过验证的、安全的、公开的加密算法。 + +**说明:**算法的安全性不在于算法本身的机密性。 + +**示例:**推荐使用的密码算法: +1)分组密码算法:AES(密钥长度在128位及以上) +2)流密码算法:AES(密钥长度在128位及以上)(OFB或CTR模式) +3)非对称加密算法:RSA(推荐3072位) +4)哈希算法:SHA2(256位及以上) +5)密钥交换算法:DH(推荐3072位) +6)HMAC(基于哈希的消息验证码)算法:HMAC-SHA2 +不安全的密码算法举例如下:MD5/DES/3DES(加密传输协议TLS/SSH密码协议中避免使用3DES,非密码协议场景必须保证密钥K1≠K2≠K3)/HMAC-SHA2-256-96/HMAC-SHA1-96/HMAC-MD5/HMAC-MD5-96/SSH服务所有带CBC模式的算法/匿名算法套件/DH512/DH1024/SKIPJACK/RC2/RSA(1024位及以下)/MD2/MD4/blowfish/RC4。 +3-2 除标准协议外,避免使用差错控制编码(如奇偶校验、CRC)实现完整性校验。 + +3-3 密码算法中使用到的随机数必须是密码学意义上的安全随机数。 + +**说明:**使用了不安全的随机数,容易导致密码算法的强度降低甚至算法的失效。 + +**示例:**可使用以下的安全随机数生成接口: +1) OpenSSL的RAND_bytes或RAND_priv_bytes; +2) OpenSSL FIPS模块中实现的DRBG; +3) JDK的java.security.SecureRandom; +4)类Unix平台的/dev/random文件 + +3-4 默认使用安全的密码算法,关闭或者禁用不安全的密码算法。在选择密码算法库时,应使用通过认证的或业界开源公认的或经评估认可的密码算法库。 + +**说明:**随着密码技术的发展以及计算能力的提升,一些密码算法变得不再安全,使用不安全的密码算法,有可能为用户的数据带来风险。同时非专业人员实现的密码算法,在技术上未经业界分析验证,有可能存在未知的缺陷,因此应使用通过认证的或业界开源公认的或经评估认可的密码算法库。 + +**示例:**密码算法相关示例请参考3-1。 + +3-5 使用分组密码算法时,应优先选择GCM模式。 + +3-6 使用RSA算法进行加密操作时,应优先选择OAEP填充方式。 + +**说明:**学术界和业界针对RSA的PKCS1填充方式的攻击已经比较成熟,如果不使用OAEP填充替换PKCS1填充,攻击者解密密文的难度将大大降低。 + +3-7 使用非对称运算保护数据机密性时,避免使用私钥加密敏感数据。 + +**说明:**私钥加密无法保护数据的机密性。 + +3-8 使用非对称算法时,加密和签名要使用不同的密钥对。 + +3-9 在同时需要对数据进行对称加密和数字签名时,使用先签名后加密的方式。检查程序里的密码算法函数调用次序,避免对密文的hash值进行签名(即对密文的hash值进行私钥运算)。 + +**说明:**如果对密文签名(即对密文的hash值签名),一旦攻击者可以通过网络嗅探的方式获得密文(也就可以获取密文hash值),就可以任意篡改密文消息的签名。 + +3-10 使用DH算法进行密钥协商的双方在接收到对方发送过来的“公钥”时,应判断公钥是不是0,1,p-1,p这样的特殊值并要求重新发起密钥协商。 + +**说明:**如果使用DH算法进行密钥协商的双方在接收到的对方发送的“公钥是某些特殊值“,则协商出的密钥也一定是某些已知的值。在这种情况下,攻击者可以尝试最多5个可能的密钥就可以轻易的解密密文。 + +3-11 在SSL/TLS中协议中,如使用DH/ECDH算法进行密钥协商,出于前向安全考虑,选取包含DHE或ECDHE密钥交换算法的加密套件,避免选取仅包含DH/ECDH的加密套件。 + +3-12 密码协议中不要使用截短的消息认证码。 + +**说明:**密码协议中(如TLS、SSH、IKE等),使用消息认证码(MAC)验证消息的完整性,协议标准有时支持选取截短的消息认证码。此时,消息认证码安全性也因截短而降低,如针对多种密码协议(如TLS、SSH等)的SLOTH攻击就可以利用截短哈希值构造碰撞。 + +**示例:**截短消息认证码的配置举例:SSH协议中配置HMAC-MD5-96、HMAC-SHA1-96、HMAC-SHA2-256-96 +哈希算法的标准输出长度如下,低于标准长度可视为截短: +1)SHA1/HMAC-SHA1,标准输出长度160比特 +2)SHA224/HMAC-SHA224,标准输出长度224比特 +3)SHA256/HMAC-SHA256,标准输出长度256比特 +4)SHA384/HMAC-SHA384,标准输出长度384比特 +5)SHA512/HMAC-SHA512,标准输出长度512比特 +6)SHA-512/224/HMAC-SHA-512/224,标准输出长度224比特 +7)SHA512/256/HMAC-SHA-512/256,标准输出长度256比特 + +3-13 使用HMAC保护数据完整性时,不能使用hash(key||message)或hash(message||key)的计算结果作为MAC值。 + +**说明:**攻击者可以通过在原始明文后面追加任意信息的方式篡改明文,破坏数据的完整性。 + +3-14 同一笔业务中,若既需要加密运算也需要计算MAC时,加密操作和计算MAC操作不能使用同一个对称密钥。 + +**说明:**如果加密和MAC密钥相同,一旦密钥泄露,攻击者可以有针对性的篡改机密信息。 +3-15 加密时避免使用固定的IV(如:硬编码,或固定在配置文件中)。 + +**说明:**CBC模式的随机IV值可确保相同的明文、相同的密钥加密出的密文完全不同,如果IV无法确保每次加密都不同,对于CBC模式,攻击者可以轻易的进行密文替换攻击;CBC模式之外的其他分组密码运算模式(如:OFB、CRT等),攻击者可以非常容易的解密密文。 + +3-16 密码协议中避免选择匿名认证、无加密、弱身份认证、弱密钥交换、弱对称加密算法和弱消息认证算法的加密算法套件。 + +**说明:**容易造成安全上的薄弱环节从而降低系统的安全性。 + +**示例:**匿名认证举例:TLS_DH_anon_WITH_3DES_EDE_CBC_SHA、TLS_DH_anon_WITH_AES_256_CBC_SHA +弱身份认证举例:密钥长度小于2048比特的RSA/DSA密钥 + +3-17 推荐仅选择使用ECDHE作为密钥交换算法的加密套件。 + +3-18 用于数据加解密的密钥不能硬编码在代码中,应采用根密钥等加密保护,同时根密钥也需采用适当的安全机制进行保护(如仅对部分密钥组件进行硬编码)。 + +**说明:**硬编码密钥容易被逆向分析破解。 + +3-19 功能设计中建议支持工作密钥更新方法(密钥更新方式:手动更新、自动更新等),并规定工作密钥更新规则(在线更新、离线更新、更新时间等)。 + +**说明:**密钥使用时间越长,密钥被破解的风险也越大;密钥加密的数据量越多,攻击者能够获取到密文的数据机会也越大,而对被同一个密钥加密的多个密文进行密码学分析相对比较容易,导致密钥越容易被破解;如果密钥已经泄露,那么密钥被使用的时间越久,损失越大。 + +**示例:**当密钥需要更新时,根据密钥生成的规则,重新生成新密钥,同时使用旧密钥解密已加密的数据,并使用新生成的密钥重新加密,同时销毁旧密钥;对于加密数据量很大的场景,可以考虑保留旧密钥,用于解密旧密钥加密的数据,同时使用更新后的密钥加密新数据。 + +3-20 密钥材料及密钥组件在保存时须限定其权限(如权限600或400)。 + +3-21 对于内存中的密钥,释放前应对保存密钥的内存空间填充其他值。(如:全0)。 + +## 4.敏感数据保护 + +4-1 口令等认证凭据应该加密存储并提供访问控制。 + +4-2 认证凭据不需要还原的场景,应使用PBKDF2等不可逆的算法加密,对于性能敏感且安全性要求不高的场景可使用HMAC(认证凭据,盐值)(注:认证凭据、盐值位置可以互换)。 + +**示例:**1、认证凭据使用PBKDF2算法计算口令单向哈希时,迭代次数最低1000次。 +2、盐值Salt为密码学意义上的安全随机数,由系统随机生成,盐值salt至少16字节,并按用户区分。 +3、避免使用HASH(用户名||口令)、HMAC(用户名,口令)、HASH(口令 XOR salt)。 + +4-3 敏感数据如需通过非信任网络传输,应支持安全传输通道或者将数据加密后再传输的机制。 + +4-4 对敏感数据的访问,根据风险采取适当的安全机制(如认证、授权或加密等)。包含敏感数据的文件(例如,包含敏感数据的配置文件、日志文件、个人敏感数据文件、用户口令文件、密钥文件、证书文件、驱动文件、备份文件)和其目录的权限设置应只允许文件的属主或需要访问该文件/目录的用户拥有相应的权限。 + +4-5 日志、调试信息、错误提示等中应过滤或者屏蔽认证凭据。 + +## 5.系统管理和维护安全 + +5-1 对于系统自身操作维护类的接口的登录认证场景,应综合考虑实际业务场景及风险,采取下述一种或几种保护措施,实现口令防暴力破解机制: +1)锁定帐号; +2)锁定IP; +3)登录延迟; +4)验证码; + +5-2 对于系统自身操作维护类的口令,图形界面缺省不明文显示用户键入的所有口令。 + +5-3 口令输入框不能支持口令拷出。 + +5-4 应使用合适的安全协议,不安全协议应默认关闭。 + +**示例:**安全协议举例:SSHv2/TLS1.2/TLS1.3/IPSec/SFTP/SNMPv3等协议,及其业界最新安全版本。对于流密码算法,建议使用AES的OFB和CTR模式或chacha20流加密算法替换RC4算法。 +不安全协议举例:TFTP、FTP、Telnet、SSL2.0、SSL3.0、TLS1.0、TLS1.1、SNMP v1/v2和SSHv1.x。 + +5-5 基于权限最小化原则,系统新建账号默认不授予任何权限,或者默认只指派最小权限(如:只读权限)的角色。 + +**说明:**保证当授权机制出现问题或授权机制被绕过时非法用户获得的权限也是最少的。 + +## 6.隐私保护 + +6-1 收集或使用个人数据前以及将该个人数据发送给第三方之前,应明确提示用户,并获得用户的同意。 + +**说明:**增加透明性及用户控制能力,满足GDPR等法律法规要求。 + +6-2 正常业务需要的情况下,采集、处理、存储个人数据,应根据实际安全风险提供必要的安全保护机制(如认证、权限控制、日志记录等),以防止个人数据被泄漏、丢失、破坏。 + +6-3 在说明文档中对产品涉及用户隐私的功能进行描述:该功能处理用户个人数据的目的、范围、处理方式、时限。要求使用该功能时遵从当地适用的法律法规。 + +**说明:**增加透明性,满足GDPR等法律法规要求。 + +6-4 对于所涉及的个人数据,应支持在呈现界面上(如显示界面、文件存储/导出等)进行过滤或匿名化或假名化。 + +**说明:**降低个人隐私泄露的风险。 + +6-5 为避免位置追踪,除了有明确的需求之外,不能出于故障定位等维护目的进行用户精确位置信息定位。 + +**说明:**精确位置信息非常敏感,故障定位无需精确定位。 + +6-6 收集个人数据需基于使用目的所必需,满足最小化原则。用于问题定位的日志中记录个人数据遵循最小化原则。 + +**说明:**用于问题定位的日志如果出现个人数据,会引起用户的质疑。应避免打印个人数据,如果必须打印个人数据(如调试目的),必须对个人数据进行匿名化处理。 + +6-7 涉及个人数据处理的场景,需要提供相关机制,确保数据主体能够查询、更新以及删除所有数据主体的个人数据。 + +**说明:**确保数据主体的权利。 + +## 术语说明 + +| 序号 | 术语 | 定义 | +| :--: | :----------: | ------------------------------------------------------------ | +| 1 | 认证凭据 | 认证凭据指用于证明真实性的身份而声明的私有或公共数据。常用的认证凭据有口令、预共享密钥、私钥、snmp团体字、智能卡、动态令牌卡、指纹、虹膜等。 | +| 2 | 个人数据 | 与一个身份已被识别或者身份可被识别的自然人(“数据主体”)相关的任何信息;身份可识别的自然人是指其身份可以通过诸如姓名、身份证号、位置数据等识别码或者通过一个或多个与自然人的身体、生理、精神、经济、文化或者社会身份相关的特定因素来直接或者间接地被识别。个人数据包括:自然人的email地址、电话号码、生物特征(指纹)、位置数据、IP地址、医疗信息、宗教信仰、社保号、婚姻状态等。 | +| 3 | 敏感个人数据 | 敏感个人数据是个人数据的一个重要子集,指的是涉及数据主体的最私密领域的信息或者一旦泄露可能会给数据主体造成重大不利影响的数据。包括种族、政治观点、宗教和哲学信仰、工会成员资格、基因数据、生物信息、健康和性生活状况,还包括可与自然人身份相关联的银行卡号、身份证号、护照号、口令等。敏感个人数据的处理需要更多更严格的保护措施。 | +| 4 | 敏感数据 | 敏感数据的具体范围取决于具体的应用场景,建议根据风险进行分析和判断。典型的敏感数据包括认证凭据(如口令、私钥、动态令牌卡)、加密秘钥、敏感个人数据等 | +| 5 | 数据主体 | 提供个人数据供数据控制者和处理者处理的人。数据主体能够通过个人数据识别,可以通过如姓名等直接识别也可以通过其个人数据的组合而间接识别出。 | +| 6 | 匿名化 | 是对个人数据进行不可逆改变的过程,个人数据匿名化处理后将无法直接或间接地识别数据主体或者识别需要不合理的耗费大量的时间,费用和精力。 | +| 7 | 假名化 | 为了限制通过个人数据来识别数据主体,个人数据中包含的身份信息可以被假名替代。这种替代就是假名化,假名化的两个属性是:(1)和假名相关联的其他属性不足以识别出这些属性关联的数据主体;(2)除假名分配者外,隐私相关方(例如数据控制者)在有限的努力下无法根据假名逆推出数据主体。假名化以后的数据依然属于个人数据。假名化也称作化名。 | +| 8 | 精确位置信息 | 经纬度、如GPS可以限定在几十米之内。精确位置信息的标准是能识别对应到具体的自然人的程度。 | +| 9 | 标准协议 | 本文中提及的“标准协议”指国际标准协议(如ETSI、3GPP、ITU-T等标准组织定义的标准)、区域性标准(如欧盟制定的标准)、国家行业标准(如中国工信部制定的标准)、事实行业标准(如UPnP组织定义的行业标准)。 | + diff --git a/website/docs/_posts/contribute/docs-reviewers.md b/website/docs/_posts/contribute/docs-reviewers.md new file mode 100644 index 0000000000000000000000000000000000000000..f3a9270818a16e3437c7cb90b51dfdfbefea4c6f --- /dev/null +++ b/website/docs/_posts/contribute/docs-reviewers.md @@ -0,0 +1,48 @@ +--- +title: docs-reviewers.md +permalink: /pages/extra/fd9d91/ +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +date: 2021-12-30 18:17:45 +--- +# 开发者文档评审人 + +## 文档规范评审人 +### 设备开发相关文档评审人 + +| Feature | Docs Reviewers | +| ------------ | ------------------------------------------------------------ | +| 快速入门 | [@duangavin123](https://gitee.com/duangavin123) | +| 获取源码 | [@duangavin123](https://gitee.com/duangavin123) | +| 内核 | [@Austin23](https://gitee.com/Austin23) | +| 驱动 | [@Qianchenya](https://gitee.com/Qianchenya) | +| 设备开发指南 | [@Austin23](https://gitee.com/Austin23) | +| 移植适配 | [@Austin23](https://gitee.com/Austin23) | +| Bundle开发 | [@Qianchenya](https://gitee.com/Qianchenya) | +| 隐私与安全 | [@Qianchenya](https://gitee.com/Qianchenya) | +| 子系统 | [@Qianchenya](https://gitee.com/Qianchenya) | +| 导读 | [@zengyawen](https://gitee.com/zengyawen) | +| 术语 | [@bj9854](https://gitee.com/bj9854) | +| 社区公共文档 | [@neeen](https://gitee.com/neeen) [@yan-tingting666](https://gitee.com/yan-tingting666) | + +### 应用开发相关文档评审人 + +| Feature | Docs Reviewers | +| ------------ | ----------------------------------------- | +| JS参考规范 | [@zengyawen](https://gitee.com/zengyawen) | +| 媒体 | [@zengyawen](https://gitee.com/zengyawen) | +| 快速入门 | [@ge-yafang](https://gitee.com/ge-yafang) | +| UI | [@ge-yafang](https://gitee.com/ge-yafang) | +| 应用开发导读 | [@zengyawen](https://gitee.com/zengyawen) | +| 网络与连接 | [@RayShih](https://gitee.com/RayShih) | + +## 技术正确性评审人---待补充 + + + diff --git a/website/docs/_posts/contribute/template/faq-template.md b/website/docs/_posts/contribute/template/faq-template.md new file mode 100644 index 0000000000000000000000000000000000000000..f4fda96a23c017598c1ef343147809d9fde33c99 --- /dev/null +++ b/website/docs/_posts/contribute/template/faq-template.md @@ -0,0 +1,49 @@ +--- +title: faq-template.md +permalink: /pages/extra/03f82c/ +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +date: 2021-12-30 18:17:45 +--- +# FAQ:标题(简要描述问题关键信息) + +FAQ页面介绍开发过程中遇到的各类问题及解决方法,帮助更多开发者快速消除此类开发障碍。 + +## 简单类问题写作模板 + +简要描述在完成哪些操作时,遇到的问题现象,以及解决方法。 + +## 复杂类问题写作模板 + +**现象描述** + +- 使用的系统软件、硬件版本? +- 在完成哪些操作时,遇到了什么样的问题? + +- 可能显示什么错误消息? + +- 如果可能,请提供屏幕截图。 + + +**可能原因** + +分析哪些原因导致此问题,如果有多个原因,请使用项目列表一一列举。 + +1. XXX +2. XXX + +**处理步骤** + +- 如果有多个解决方案,请按照复杂性排序,并提供什么场景下选择哪种解决方案。 +- 如果可能,请提供屏幕截图,帮助理解步骤完成标准。 +- 代码如有打印输出,请提示打印输出内容_,帮助理解步骤完成标准_。 + +1. XXX +2. XXX + diff --git a/website/docs/_posts/contribute/template/tutorial-template.md b/website/docs/_posts/contribute/template/tutorial-template.md new file mode 100644 index 0000000000000000000000000000000000000000..d536b2a675489cecacf6be9a8bee9d271bdbf7b1 --- /dev/null +++ b/website/docs/_posts/contribute/template/tutorial-template.md @@ -0,0 +1,61 @@ +--- +title: tutorial-template.md +permalink: /pages/extra/7ba326/ +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +date: 2021-12-30 18:17:45 +--- +# 教程:标题(对应的任务名称) + +教程页面介绍如何完成一个复杂的任务开发、功能开发、APP开发。通常教程页面会将开发过程拆解为多个小节,每个小节由一系列步骤组成。同时,教程中一般需要提供代码示例并进行介绍,便于用户了解具体的功能实现。 + +对于教程中可能涉及到的基本概念,简单的概念可以直接介绍,更深度的概念和主题推荐查阅文档对应专题。 + +撰写教程页面时,在“others“目录下面创建新的MarkDown文件。 + +## 总览 + +_写作内容:介绍开发者学习本教程后将完成什么样的任务,实现什么样的功能和效果。__例如,可以是移植教程、实现一个功能开发教程等。_如果可实现多个目标,建议使用项目符号列表。 + +_如果可能,请提供图片或短视频展示实现效果。_ + +## 开发准备 + +- _完成该功能需要的软件、硬件、工具及对应版本信息。_ +- _需要获取的相关权限说明。_ + +## XXX(关键任务一) + +_将教程分解为几个顺序的关键任务或并列不同的场景任务。_ + +1. XXXX。 + + ``` + //代码示例 + ``` + +2. XXXX。 + +_所有的操作步骤,遵循如下写作要求:_ + +1. _步骤明确操作场景和目的,__步骤中执行的主体要描述清楚。_ +2. _步骤中如果涉及接口调用,需要清晰给出使用的接口及其使用说明,示例代码。_ +3. _涉及到工具界面的步骤,可以提供界面截图,帮助理解步骤完成标准。_ +4. _保证代码的逻辑和语法的正确性。_ +5. _代码中关键步骤要有注释说明。_ +6. 代码如有打印输出,请单独提示打印输出内容_,帮助理解步骤完成标准_。 + +## XXX(关键任务二) + +1. XXXX。 + +## 下一步 + +介绍本教程可能关联的后续开发任务,如果没有请删除此内容。 + diff --git "a/website/docs/_posts/contribute/\347\254\254\344\270\211\346\226\271\345\274\200\346\272\220\350\275\257\344\273\266\345\274\225\345\205\245\346\214\207\345\257\274.md" "b/website/docs/_posts/contribute/\347\254\254\344\270\211\346\226\271\345\274\200\346\272\220\350\275\257\344\273\266\345\274\225\345\205\245\346\214\207\345\257\274.md" new file mode 100644 index 0000000000000000000000000000000000000000..def5d22002fee1de5135ae21e9548cdc2615cbbf --- /dev/null +++ "b/website/docs/_posts/contribute/\347\254\254\344\270\211\346\226\271\345\274\200\346\272\220\350\275\257\344\273\266\345\274\225\345\205\245\346\214\207\345\257\274.md" @@ -0,0 +1,232 @@ +--- +title: 第三方开源软件引入指导.md +permalink: /pages/extra/2ef3d6/ +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +date: 2021-12-30 18:17:45 +--- +# 第三方开源软件引入指导 + +## 目的 + +OpenHarmony遵从 [Open Source Definition](https://opensource.org/docs/osd) ,满足这一定义的软件,被OpenHarmony社区认同为开源软件。 +提供易用、高质量的开源软件是OpenHarmony的重要目标,因第三方开源软件数量多,而社区开发人员同样数量多、分布广,为确保OpenHarmony项目的整体质量,特别拟定本指南,供社区贡献者参考。 + +## 范围 + +本指导适用于所有引入到OpenHarmony项目中的第三方开源软件。 + +## 本文的改进和修订说明 + +1. 本文档由OpenHarmony SIG-QA主导起草和维护。本文档的最新版本总可以在 [这里](https://gitee.com/openharmony/docs/blob/36955109ed21d73afe09fcb5a5bc7067ad6ce18b/zh-cn/contribute/%E7%AC%AC%E4%B8%89%E6%96%B9%E5%BC%80%E6%BA%90%E8%BD%AF%E4%BB%B6%E5%BC%95%E5%85%A5%E6%8C%87%E5%AF%BC.md) + 找到。 +2. 任何对于本文中涉及的规则的增加,修改,删除都必须被追踪,请进入该追踪系统 。 +3. 最终规则经过社区充分的讨论后,由PMC评审定稿。 + +## 软件引入与引入原则 + +### 什么是软件引入 + +一个软件的引入指的是为满足OpenHarmony中指定SIG的业务需求,申请将其引入到OpenHarmony项目中,具体的流程请参考的[SIG管理章程](https://gitee.com/openharmony/community/tree/master/sig) 进行具体的开源软件引入,并确保整个引入的过程都必须可被追踪。 + +### 软件引入的基本要求 + +为便于第三方开源软件的维护与演进,在引入第三方开源软件时请参考如下原则: + +1. 软件必须有明确的来源,引入到OpenHarmony的软件必须有清晰定义的上游社区。 +2. 必须有明确的引入理由,若需要引入的软件在OpenHarmony项目中已存在,请重用该版本,避免多版本共存增加维护的复杂性。 +3. 软件应该以源码方式引入,原则上二进制不应该被引入,应从源码构建。如果需要引入二进制,经由PMC评审后决定。 +4. 软件应该在OpenHarmony上可以被正确构建,若该软件有尚未被引入的依赖软件,或者软件的运行或者构建依赖一个不能引入OpenHarmony的组件,需由PMC评审后决定。 +5. 引入软件到OpenHarmony项目中必须将其放置到单独的代码仓或独立的目录,命名统一为third_party_软件名称,其中软件名称和其官网保持一致。 +6. 应当完整保留引入软件的官方代码仓目录结构、许可证及Copyright信息,不要修改第三方开源软件的原始许可证与Copyright信息。 +7. 不建议引入未发布正式版本(如只发布Beta版本)的开源软件。 +8. 不能引入有高危漏洞且无解决方案的版本。 +9. 若需针对引入的开源软件进行修改,请将修改的代码放在该开源软件仓中,并确保满足该开源软件的许可证要求,修改的文件应当保持其原始许可证条款,新增的文件也建议采用相同的许可证条款。 +10. 新引入的开源软件必须在其根目录提供README.OpenSource文件,在该文件中准确描述其软件名、许可证、许可文件位置、版本、对应版本的上游社区地址、软件的维护Owner、功能描述以及引入的原因。 +11. 引入新软件到OpenHarmony时必须有对应的SIG负责管理,原则上如果没有SIG-QA以及相应SIG的确认,PMC不批准相应软件的引入。当要批量引入多个软件时,可以求助PMC主持发起SIG间的临时评审会议,提升协调效率。 如因特殊原因不能满足上述要求但又需要引入,请请联系邮箱:law@openatom.org。 + +### 软件引入流程 + +#### 软件引入前检查 + +| 检查项 | 说明 | +| :----- | :----- | +| 归一化 | 1、检查该软件在OpenHarmony中是否已存在,原则上一款软件只在OpenHarmony中引入一次。 | +| 来源可靠 | 1、应该从开源软件官网获取或官网指定的代码托管地址获取。 | +| 社区活跃 | 1、软件来自知名社区或组织,社区或组织通过发布公告、修改软件仓库状态、将仓库放到特定目录下等方式告知停止维护的,不建议引入。
2、软件来自个人、小型社区或组织,两年内未发布版本(含正式版本与测试版本),无明确版本计划,社区提交了有效的Bug或PR,但是半年以上未响应的,不建议引入。
3、社区运营状态不明确,通过Issue 或者邮件等方式询问社区是否继续维护,半年以上未响应或者答复停止维护的,不建议引入。| +| 安全漏洞 | 1、检索业界已知公开的安全漏洞,如有高危漏洞需要有应对方案。| +| 规范化软件名称 | 1、 仓库命名统一为third_party_软件名称,其中软件名称和其官网保持一致。
2、 不允许以软件的子模块作为软件名。
3、 当软件存在多个语言的开发库时,可在其官方命名前追加python-等前缀予以规范化管理。 | +| 官网信息 | 1、在申请引入请求中准确描述该软件官方网址,如无正式官网则提供主流代码托管商上面对应的项目网址,不能使用maven、mvnrepository、springsource等托管库地址。
2、必须同时提供要引入版本的官方源代码包下载地址,以达到可溯源,如需要二进制包,请提供官方的二进制包下载地址。 | +| License检查 | 1、待引入软件是否有license。
2、入库的License是否和官网对应版本的License保持一致。
3、高风险license的开源软件谨慎引入,在引入前请充分评估并在申请时附上分析结论。 | + +#### 提交申请 + +如需要引入新的软件,请参考[SIG管理章程](https://gitee.com/openharmony/community/tree/master/sig) 进行具体的开源软件引入,并在申请材料中包含如下内容: + +1、自检表 + +| 检查项 | 填写指导 | 自检结果示例 | +| :----- | :----- | :----- | +| 软件名 | 描述该软件官方名称以及引入后的仓名,仓名统一为third_party_加上官方软件名称 | third_party_softwarename | +| 软件官网地址 | 描述该软件官方网站链接地址 | https://softwaresite | +| 软件版本号 | 描述该软件要引入的版本号,版本号为其社区正式发布的版本号,不要随意修改;未正式发布的版本不建议引入 | 1.0.0 | +| 软件版本发布日期 | 描述该软件要引入的版本的社区发布日期 | 2021.01.01 | +| 软件版本地址 | 描述该版本的官方下载链接地址,注意该地址必须为能定位到该具体版本发布包的下载URL | https://gitee.com/softwarecodesite/v1.0.0.zip | +| 软件许可证 | 描述该版本的官方许可证名称及许可证文件的相对路径,如果是多许可证要完整描述,并说明各许可证的关系,如是And还是Or,或者是不同目录对应不同许可证 | Apache-2.0 | +| 软件生命周期 | 描述该软件是否有LTS版本,多长时间发布一个版本,最近一年社区代码提交及Issue解决情况,是否有告知停止维护或演进 | 无LTS版本,6个月发布一个版本,近6个月有10次代码提交 | +| 软件安全漏洞 | 描述该软件存在的业界公开的安全漏洞列表,包括漏洞号、级别、漏洞链接地址、是否已有补丁或解决方案 | 无业界公开漏洞 | +| 业务场景 | 描述该软件被哪些仓使用,解决什么业务场景的问题 | 被XX仓静态链接使用,提升YYY能力 | +| 归一化 | 描述社区是否已有此软件或类似软件,业界类似软件有哪些,为什么要新引入该软件或该版本 | 本社区还未引入此软件,业界相似软件有B、C,只有本软件许可证友好,且该软件生态较好,X、Y等公司也在使用 | +| 许可证兼容性 | 1、描述使用该软件有哪些进程,各进程的许可证是什么,与要引入软件的许可证是否兼容。
2、使用OAT工具扫描要引入软件的源代码,申请时附上OAT工具生成的扫描报告(扫描问题应当清零)、LicenseFile.txt内容 | 1、此软件在用户态X进程中,静态链接使用,该进程的许可证为Apache-2.0,与该软件许可证一致,无兼容性问题;
2、OAT工具扫描生成的Result.txt, LicenseFile.txt内容
| +| 责任人 | 描述该软件引入到本社区后的SIG名称及维护责任人的Gitee用名及邮箱 | SIG XXX,Zhangsan,Zhangsan@xyz.com | + +说明: + +- OAT工具的使用方式请参考 https://gitee.com/openharmony-sig/tools_oat ,如对工具有改进建议请直接在社区提交ISSUE,也可Fork下来完善工具并提交PR。 +- OAT报告原则上应当是清零,格式如下: + +``` +Invalid File Type Total Count: 0 +License Not Compatible Total Count: 0 +License Header Invalid Total Count: 0 +Copyright Header Invalid Total Count: 0 +No License File Total Count: 0 +No Readme.OpenSource Total Count: 0 +No Readme Total Count: 0 +``` + +- LicenseFile.txt位于OAT工具运行目录的log目录下,此文件记录扫描目录下所有疑似许可证的文件,格式如下: + +``` +third_party_abcde/ LICENSEFILE LICENSE Apache-2.0 +third_party_abcde/doc/ LICENSEFILE LICENSE Apache-2.0 +``` + +2、OAT.xml文件 + +请参考 https://gitee.com/openharmony-sig/tools_oat/blob/master/README_zh.md ,完成OAT扫描问题确认及OAT.xml文件配置,申请中附上此文件内容(如果无任何需确认问题则无需配置)。 + +3、该仓的README.OpenSource文件内容,格式如下: + +``` +[ + { + "Name": "softwarename", + "License": "Apache-2.0", + "License File": "LICENSE", + "Version Number": "1.0.0", + "Owner": "Zhangsan@xyz.com", + "Upstream URL": "https://gitee.com/softwarecodesite/v1.0.0.zip", + "Description": "...." + }, + { + ... + }//如有多个许可证,请一一列举 +] +``` + +#### PMC评审 + +参考[SIG管理章程](https://gitee.com/openharmony/community/tree/master/sig),PMC会根据收到的PR统一安排SIG申请评审以及建仓。 + +### 第三方开源软件许可证要求 + +1. 第三方开源软件许可证类型必须是[OSI](https://opensource.org/osd-annotated) 明确定义的。 +2. 第三方开源软件许可证必须与使用该开源软件的代码仓许可证兼容。 +3. 如下类型许可证可以引入到OpenHarmony项目中: + +* Apache License 2.0 +* Mulan Permissive Software License, Version 2 +* BSD 2-clause +* BSD 3-clause +* DOM4J License +* PostgreSQL License +* Eclipse Distribution License 1.0 +* MIT +* ISC +* ICU +* University of Illinois/NCSA +* W3C Software License +* zlib/libpng +* Academic Free License 3.0 +* Python Software Foundation License +* Python Imaging Library Software License +* Boost Software License Version 1.0 +* WTF Public License +* UNICODE, INC. LICENSE AGREEMENT - DATA FILES AND SOFTWARE +* Zope Public License 2.0 + +4. 如下类型许可证不建议引入到OpenHarmony项目中: + +* GNU GPL 1, 2, 3 +* GNU Affero GPL 3 +* GNU LGPL 2, 2.1, 3 +* QPL +* Sleepycat License +* Server Side Public License (SSPL) version 1 +* Code Project Open License (CPOL) +* BSD-4-Clause/BSD-4-Clause (University of California-Specific) +* Facebook BSD+Patents license +* NPL 1.0/NPL 1.1 +* The Solipsistic Eclipse Public License +* The "Don't Be A Dick" Public License +* JSON License +* Binary Code License (BCL) +* Intel Simplified Software License +* JSR-275 License +* Microsoft Limited Public License +* Amazon Software License (ASL) +* Java SDK for Satori RTM license +* Redis Source Available License (RSAL) +* Booz Allen Public License +* Creative Commons Non-Commercial +* Sun Community Source License 3.0 +* Common Development and Distribution Licenses: CDDL 1.0 and CDDL 1.1 +* Common Public License: CPL 1.0 +* Eclipse Public License: EPL 1.0 +* IBM Public License: IPL 1.0 +* Mozilla Public Licenses: MPL 1.0, MPL 1.1, and MPL 2.0 +* Sun Public License: SPL 1.0 +* Open Software License 3.0 +* Erlang Public License +* UnRAR License +* SIL Open Font License +* Ubuntu Font License Version 1.0 +* IPA Font License Agreement v1.0 +* Ruby License +* Eclipse Public License 2.0: EPL 2.0 + +如要引入其它类型License或上述(4)所列License,请联系邮箱:law@openatom.org。 + +## 软件退出与退出原则 + +### 什么是软件退出 + +1. 一个软件的退出指的是一个软件(项目)申请从OpenHarmony项目中删除,依照本文件描述的规则讨论,最终在OpenHarmony中移除的过程。 +2. 该软件相关的SIG负责申报议题到PMC评审,管理软件退出。 + +### 软件退出原则 + +当满足以下两个条件时,OpenHarmony中软件的退出申请可以被立即执行,对应文件将从项目中直接删除。 + +1. 软件的License变化,或者其他法律法规影响了目前正在使用的版本,导致OpenHarmony因为法务风险,不能继续集成该软件。 +2. 存在恶意代码或严重安全隐患且OpenHarmony社区无能力修复的,要求软件被立即移除。 + +除以上描述两种场景外,其它场景OpenHarmony对软件的退出实行过程化管理: + +1. 随着技术演进与发展,软件因技术陈旧或架构落后,不能满足现有的应用场景被其他更优秀的软件所取代。 +2. OpenHarmony已经集成的版本过于老旧,且软件新版本License或其他法律法规限制导致OpenHarmony不能升级新版本。 +3. 软件来自知名社区或组织,社区或组织通过发布公告、修改软件仓库状态、将仓库放到特定目录下等方式告知停止维护的。 +4. 软件来自个人、小型社区或组织,两年内未发布版本(含正式版本与测试版本),无明确版本计划,社区提交了有效的Bug或PR,社区半年以上未响应的。 +5. 社区运营状态不明确,通过Issue或者邮件等方式询问社区是否继续维护,社区半年以上未响应或者答复停止维护的。 + +如果软件符合以上任何一条退出条件,PMC与相应SIG首先分析该软件在当前OpenHarmony社区中被依赖、被使用的情况。 + +1. 如果OpenHarmony中存在依赖关系,且短时间内不能解除,我们建议SIG新建分支代码仓,并主动进行社区维护动作。 +2. 如果OpenHarmony中不存在依赖关系,或者短时间内可以解除,则责任SIG将软件从OpenHarmony正式发行中移出,并在相应的Release Notes中说明移除的原因及影响。 \ No newline at end of file diff --git "a/website/docs/_posts/zh-cn/contribute/\350\264\241\347\214\256\346\226\207\346\241\243.md" "b/website/docs/_posts/contribute/\350\264\241\347\214\256\346\226\207\346\241\243.md" similarity index 92% rename from "website/docs/_posts/zh-cn/contribute/\350\264\241\347\214\256\346\226\207\346\241\243.md" rename to "website/docs/_posts/contribute/\350\264\241\347\214\256\346\226\207\346\241\243.md" index 9f48bc8ca49575d500080302f69d30aa6db4c720..e641f732a7814f9299e4a849c9cd920fb3114ba4 100644 --- "a/website/docs/_posts/zh-cn/contribute/\350\264\241\347\214\256\346\226\207\346\241\243.md" +++ "b/website/docs/_posts/contribute/\350\264\241\347\214\256\346\226\207\346\241\243.md" @@ -1,16 +1,16 @@ --- -title: 贡献文档 -permalink: /pages/extra/7f2552/ +title: 贡献文档.md +permalink: /pages/extra/678153/ navbar: true sidebar: false prev: false next: false -search: true -article: true +search: false +article: false comment: false editLink: false -date: 2022-02-14 21:31:38 ---- +date: 2021-12-30 18:17:45 +--- # 贡献文档 非常欢迎您贡献文档,我们鼓励开发者以各种方式参与文档反馈和贡献。您可以对现有文档进行评价、简单更改、反馈文档质量问题、贡献您的原创内容。 @@ -18,7 +18,7 @@ date: 2022-02-14 21:31:38 卓越贡献者将会在开发者社区文档贡献专栏表彰公示。 - [贡献方式](#section5723203852414) -- [写作规范](/pages/010d0501) +- [写作规范](/pages/000c0400) ## 内容版权 @@ -64,20 +64,20 @@ date: 2022-02-14 21:31:38 文档团队成员将评审并合并您的修改内容,感谢您对OpenHarmony文档的支持和帮助。 -更多内容可参考[贡献流程](/pages/010d04)。 +更多内容可参考[贡献流程](/pages/000c03)。 ### 为发行版本贡献文档 为了帮助开发者更高效使用OpenHarmony社区的每个Release版本,社区会根据每个版本规划的需求特性提供配套文档(如指南、API参考、开发示例、Release Notes、API Changelog、FAQ等)。有的需求涉及新增功能特性和文档,有的需求的是对现有特性和文档内容更新。 -欢迎开发者参与贡献,详细参考:[为发行版本贡献文档](/pages/010d0502) +欢迎开发者参与贡献,详细参考:[为发行版本贡献文档](/pages/000c0401) ### 贡献经验分享内容 鼓励开发者在学习、开发过程中,总结经验并创建技术内容帮助更多开发者快速上手。推荐输出各类How to教程、常见问题FAQ等。请参考如下写作模板: -- [How to教程](/pages/extra/978e66/) -- [FAQ](/pages/extra/7eb1bd/) +- [How to教程](/pages/extra/7ba326/) +- [FAQ](/pages/extra/03f82c/) 内容写作模板归档在Docs文档仓下contribute文件夹中。 diff --git a/website/docs/_posts/design/API-Review-Template.md b/website/docs/_posts/design/API-Review-Template.md new file mode 100644 index 0000000000000000000000000000000000000000..24df4653cdba6874ba96eaf381bd16d9bf2a50bd --- /dev/null +++ b/website/docs/_posts/design/API-Review-Template.md @@ -0,0 +1,150 @@ +--- +title: API-Review-Template.md +permalink: /pages/extra/5f7b0a/ +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +date: 2021-12-30 18:17:45 +--- +# OpenHarmony xxx子系统 xxx API评审申请 + +## 背景 + +* API类型:[Public API | Test API| HDI] +* API需求来源: +* API使用场景: +* API所属子系统: +* API预计发布版本: +* Contributor: +* 本次评审涉及的API数量: + +| 类型 | 数量 | 编程语言 | +|---|---|---| +| 新增 | | | +| 行为变更 | | +| 废弃 | | | +| 删除 | | | + +## API说明 + +### 必要性说明 + +> 现状与差距分析。API的使用场景和价值是什么? + +### 总体特性说明 + +> 相关API完成了哪些功能特性。 + +## 评审结论 + +### Committer评审结论 + +### 领域SIG评审结论 + +## 自查表 + +| 自查项 | 自查结果 | +|---|---| +| 是否已完成拼写检查? | | +| 是否遵循了编码规范? | | +| 词性使用是否正确(名词,形容词,副词)? | | +| 命名是否完整表述了API所做的全部逻辑?| | +|API的参数数量是否合理?(通常少于7个)| | +|是否合理使用了缩写?(缩写是大家周知的)| | +|void类型API是否真的考虑过调用者不需要返回值?| | +|是否考虑过继承体系是合适的?父类的每一个方法都适用于子类| | +|已定义的错误状态是否完备?| | +| 命名是否正确使用了对仗词:
add/remove, create/destroy, insert/delete, start/stop, begin/end,
send/receive, up/down, show/hide, open/close, source/target,
source/destination, increase/decrease, first/last, next/previous | | +|新增API与同模块既存API表述和语义层次是否一致?| | +| 同步API是否需要提供异步版本? | | +| 是否每一个public API都真的是开发者需要的?| | + +## API接口及说明 + +> 请填写代码的提交地址。 + +* 代码地址: + +## API权限设计 + +> 使用该接口是否需要申请相应的权限。 + +## API隐私保护设计 + +> 涉及用户隐私,需要考虑隐私保护。 + +## 开发者指南 + +> 可选。 + +## API代码示例 + +> 二选一即可。 + +* 代码地址: +* 代码片段: + +## API变更说明 + +> 新增接口不需要填写此章节。 + +### 行为变更 + +> API行为变更是指API的接口没有发生变化,仅仅是行为发生变化。 +> API行为变更需要在新的API版本上进行,不允许破坏旧版本API行为(除非是缺陷修复)。 + +#### 相关接口 + +#### 变更原因 + +### 废弃接口 + +> 废弃接口的API说明中,需要添加`@deprecated`注解进行(包括:JS/TS/C/C++接口)标记。 + +#### 相关接口 + +> 需描述从哪个版本开始标记为废弃。 + +#### 废弃原因 + +#### 替代接口 + +> 如果有则提供,如果无则说明原因。 + +### 删除接口 + +> 接口不允许直接删除,需要在标记废弃之后经过5个API版本才允许删除。 + +#### 相关接口 + +#### 删除原因 + +#### 替代接口 + +> 如果有则提供,如果无则说明原因。 + +## DFX + +### 兼容性 + +### 性能 + +### 功耗 + +### 可靠性 + +### 可测试性 + +> API必须同步交付API自动化测试用例,用例100%覆盖API接口。 + +## 评审结论 + +* 评审时间: +* 与会人: +* 评审结论:[通过|不通过] +* 评审会议纪要: \ No newline at end of file diff --git a/website/docs/_posts/design/OpenHarmony-API-governance.md b/website/docs/_posts/design/OpenHarmony-API-governance.md new file mode 100644 index 0000000000000000000000000000000000000000..a81b892a2df58b3b235f450ef7f74cc3119eb014 --- /dev/null +++ b/website/docs/_posts/design/OpenHarmony-API-governance.md @@ -0,0 +1,218 @@ +--- +title: OpenHarmony-API-governance.md +permalink: /pages/extra/c065b3/ +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +date: 2021-12-30 18:17:45 +--- +# OpenHarmony API治理章程 + +## 总览 + +为了引导OpenHarmony生态健康、有序发展和演进,本章程对OpenHarmony API的新增、变更、废弃、删除等生命周期与治理流程进行约束,同时定义了基本的API设计要求。 + +本章程由[API SIG](https://www.openharmony.cn/SIG/api/)制定,经[PMC](https://www.openharmony.cn/community/pmc/)批准发布;本对章程的修订必须经由API SIG评审后,由PMC批准发布。 + +## 概述 + +### 范围与定义 + +OpenHarmony软件栈中包含了多个角色,因此API也分作多种类型。 + + + +不同的API类型其兼容性要求也不一样,具体如下表所述: + +| 类型 | 提供者 | 使用者 | 兼容性要求 | 看护手段| +|---|---|---|---|---| +| Public API | 系统与框架 | 所有应用开发者 | 5个API版本| XTS| +| Test API | 测试框架 | 所有应用开发者| 3个API版本| 待构建 | +| System API | 系统与框架 |系统应用开发者 |不承诺| 待构建 | +| HDI | HDF| 系统服务 | 4个API版本| XTS | +| Driver API | HDF | 驱动开发者 | 不承诺 | 无 | +| Inner API | 系统部件 | 系统部件 | 不承诺 | 无 | + +各类型API说明如下: + +* Public API:OpenHarmony对所有应用开发者公开的API。 +* Test API:测试专用的API,供开发者使用。 +* System API:提供给系统特权应用使用的API,普通应用无法使用。 +* HDI:描述硬件能力的接口。 +* Driver API:提供给驱动开发者使用的接口。 +* Inner API:系统服务和框架实现彼此调用的API,仅供系统内部使用,不承诺兼容性。 + +### API与编程语言 + +OpenHarmony的目标是构建面向万物互联时代的新一代操作系统,其实现涵盖但不限于以下编程语言: + +* C/C++ +* JavaScript +* TypeScript + +本章程所描述的内容与编程语言无关。即:在不违反编程语言要求的情况下,API不分编程语言都要遵守章程的要求。 + +## API治理 + +### 角色与职责 + +|**涉及角色**|**API治理中的职责**| +| - | - | +|Contributor|API的设计和交付主体,负责API相关的代码与设计文档提交。| +|Committer|API相关的代码评审,涉及API提交预审。| +|领域SIG| 新增API相关的代码提交评审,领域SIG评审通过即可合入。
变更API相关的代码提交预审。| +|API SIG|变更API相关的代码提交评审。| +|PMC|API Version计划发布、API治理章程修订评审发布等。| + +### API评审流程 +API评审流程如下: + + + +主要过程说明: + +1. API评审申请、代码提交(Owner:Contributor),所有涉及API新增或变更需同步提交相应的API评审文档,详细说明API的需求来源、场景与使用方法、权限设计、隐私保护澄清等,详见后面的API评审申请要素。为避免后续的返工,Contributor可以在正式的API评审申请、代码提交之前,先通过邮件方式将API设计文档提交Committer、领域SIG、API SIG等相关人员预审。 +1. 代码评审(Owner:Committer),代码评审和API预审,涉及API提交Code Review通过后,还需要进一步领域SIG评审。如果单次提交同时涉及多个领域的API新增或变更,相应的API评审申请和代码需要同时提交给相关领域的Committer评审,只有所有对应领域的Committer都完成CodeReview后才能进入下一评审环节。 +1. API评审(Owner:领域SIG),新增API相关的代码提交评审,领域SIG评审通过即可代码合入;变更API相关的代码提交,领域SIG评审通过后,还需要进一步提交API SIG。如果单次提交同时涉及多个领域的API新增,相应的API评审申请和代码需要同时提交给相关领域的SIG评审,只需一个领域SIG评审通过即可代码合入。如果单次提交同时涉及多个领域的API变更,相应的API评审申请和代码需要同时提交给相关领域的SIG评审,只有所有对应领域的SIG都要评审通过才能进入下一评审环节。 +1. API变更评审(Owner:API SIG),变更API相关的代码提交评审,评审通过即可代码。 +1. 评审完成。 + +### API评审申请要素 + +如果涉及API新增或变更需同步提交相应的API评审文档。API评审文档使用[《OpenHarmony API 评审模板》](/pages/extra/5f7b0a/)描述。 + +针对新增API,需要包含如下要素: +1. 需求来源与使用场景(必须)。 +1. API现状与差距分析,说明API新增或变更的必要性(必须)。 +1. API原型设计与使用方法说明(必须);必要时,可以进一步包含相应的使用样例(可选)。 +1. API权限设计(必须)。 +1. API隐私保护方案与要求满足情况澄清(必须); +1. 提交代码的同时提交相应的API参考(必须);必要时,可同步提交相应的开发者指南文档(可选)。 +1. 兼容性/性能/功耗/可靠性/测试等相关情况说明(可选,如不满足本章程 “API设计要求”,则必须包含相关说明)。 + +针对变更API,需要额外包含如下要素: +1. 针对老接口的处理方式(废弃、隐藏或彻底删除)以及对使用老SDK开发应用的兼容措施(必须); +2. 变更影响、替代接口和相应的应用适配方案(必须)。 +3. 刷新ChangeLog(必须) 和 API-diff文档(涉及JS/Native API变更,必须)。 + +## API设计要求 + + +### 一致性要求 +1. 概念一致性:基于场景的业务模型抽象,形成OpenHarmony的连贯、一致、自恰的用户程序模型和业务概念。 +1. 术语一致性:相应的业务术语必须采用统一名词,不允许使用多个语意接近的名词表示同一个业务对象;同样地,为了避免产生混淆,也不允许针对不同的业务对象使用相同的名词或语言接近的名词。 +1. 操作一致性:相同的操作动作必须采用同一动词。 +1. 参数顺序一致性:相同参数/参数序列在多个API中的位置和顺序保持一致。 +1. 机制及算法一致性:通信机制、调用模式、认证机制、加密算法等保持一致。 +1. 帮助、Demo、模板风格一致性:排版、用法等保持一致。 + +### 易用性要求 +以“能力使用者”视角,而不是“能力提供者”视角设计API: +1. 可理解:API命名和功能特性必须容易理解。 +1. 易使用:提供简单易用的API,减少API之间不必要的耦合,避免多个无之间关联关系API之间调用顺序的依赖,尽可能使调用者优雅,尽量避免使用单一功能时必须同时组合调用多个包/模块或类中的多方法才能实现。 +1. 避免误导:提供使用者期望的能力,避免误导,减少误用。 +1. 提供必要的API文档。 + +### 命名要求 +1. 能清晰的表达意图:使用完整的描述性的单词。 +1. 避免造成误导:有误导的名字比表达不清的名字还要有危害性。 +1. 词义清晰明了,避免使用info,data,object等一般意义的词。 +1. 作用域越大,命名应越精确。 +1. 不用或少用缩写,业界通用术语遵从行业习惯允许使用缩写。 +1. 包名/模块名/命名空间前缀约定: + 1. JS API 统一模块名:@ohos.\*。 + 2. Native API 统一命名空间:namespace OHOS.\*。 + 3. 引用外部开源代码的,可以保留原包名/模块名/命名空间,也可以按照上述规则对包名统一进行替换。 +1. 包名/模块名/命名空间最短不少于2段,最长不超过4段;每一段建议使用一个单词,最长不超过2个单词。 +1. 类名、方法名/函数名、成员变量、变量名最多不超过4个单词。 + +### 权限控制要求 +1. 完备性原则:一切穿透应用沙箱的行为都需考虑使用权限来管控。 +1. 最优粒度原则:一个权限只保护一类对象;一个接口仅需申请一个权限即可访问。 +1. 清晰完整原则:权限定义中必须清晰说明保护对象、开放范围、敏感级别。 +1. 最小开放原则:一个权限仅对确有正当业务需求的应用开放,开放控制可通过权限来实现。 + +### 隐私保护要求 +1. API调用的返回仅包含必要的内容, 避免携带额外信息。 +1. API调用不允许获取、手机用户个人数据, 除非通过用户权限管控、由用户授权同意。 +1. API涉及跨应用调用时,如涉及个人数据向被调用者的披露,由调用方在隐私声明中说明披露的数据类型、数据接收者和数据使用目的。 +1. API涉及到用户敏感数据(如电话、通讯录、媒体等)访问时,需要使用system picker的机制,禁止API通过申请敏感权限方式访问。 +1. API开放禁止捆绑与所开放能力不相关的功能。 + +### 文档化要求 +1. API参考采用英文方式交付。 +1. 模块/包模块的API参考必须包括简要描述和详细描述。 +1. 类、方法、“Interface”、枚举或成员变量的API参考必须包括简要描述。 +1. 类、方法、“Interface”、枚举或成员变量的API参考可选包括详细描述。 +1. 方法、“Interface”的API参考必须包括所有入参的参数描述。 +1. 如果方法或“Interface”有返回值,则API参考必须包含返回值描述。 +1. 如果执行过程中可能抛出异常,则API参数必须包含相关的异常描述。 +1. 必须包含API的起始版本号(使用@since注释标记)。 +1. 可选包括本模块或类自己的版本号(使用@version注释标记)。 +1. 涉及API变更(不兼容),必须同步交付API-Diff和ChangeLog文档。 + +### 兼容性要求 +1. 按严格程度从高到低,API兼容要求包括:契约兼容 > 二进制兼容 > 源码兼容。 + 1. 源码兼容:指版本演进后,开发者已有的源代码可正常编译通过。 + 1. 二进制兼容:指版本演进后,开发者已有程序不用重新编译可正常链接、运行。 + 1. 契约兼容:也称语义兼容,指版本演进后,开发者原有程序行为不发生变化。 +1. OpenHarmony API后向兼容必须满足二进制兼容要求,例外情况需要通过API SIG评审并经过PMC批准。常见破坏二进制兼容的API变更包括: + 1. 任何API元素删除; + 1. 降低方法的可见性,例如protected修改为了private,或者public修改为protected。 + 1. 类类型发生变化,例如抽象类变更为非抽象类,或者接口类(“Interface”)变更为非接口类。 + 1. 方法原型发生变化,例如返回值类型修改,或入参顺序或入参类型发生变化。 + 1. 成员final/static等属性发生变化,例如非final成员变成final,或者非static的成员变成static。 +1. 禁止“原型相同、功能不兼容”的API修改,可受限使用“废弃old-api、新增new-api”的方式进行修改。 +1. 根据发布类型不同,API的生命周期和兼容性要求: + +![](/images/design/figures/API-Lifecycle.png) + + 1. Canary版本:早期发布的预览版本,不承诺API稳定。 + 1. 对上一Release发布版本保持API兼容。 + 1. 相同API Version的多个Canary版本之间无API兼容性要求。 + 1. Beta版本:公开发布的Beta测试版本,不承诺API稳定。 + 1. 对上一Release发布版本保持API兼容。 + 1. 对同一API Version的早期发布的Canary版本不兼容。 + 1. 相同API Version的多个Beta版本之间无API兼容性要求。 + 1. API Stable版本发布之后API即冻结,之后再发布的Beta版不允许任何形式的API新增或变更。 + 1. Release版本:正式发布版本。 + 通过Release版本对外发布的API,需要遵守对外部开发者的“契约承诺”,原则上不允许对已经Release发布的API进行不兼容修改,受限允许对已发布的API进行废弃。已经Release发布的API废弃基本要求包括: + 1. 废弃接口标记。 + 1. 提供可替代接口。 + 1. 废弃API至少保留5个API Version版本(对废弃5个API Version的API可以彻底删除,不再支持)。 + +### 性能要求 +1. 应及时响应,避免调用者等待;如果API调用执行时间过长应设计为异步方式。 +2. 应关注API调用时机、调用频次对RAM占用的影响。 +3. 应关注API调用时机、调用频次对功耗的影响。 +4. 对使用资源的API调用需要能及时释放资源,异常场景具备容错机制,保障资源及时释放。 + +### 功耗要求 + +1. 针对API调用时机、调用频次对功耗的影响做评估,有影响进行相关设计。 +2. 版本演进过程中,功耗不劣化。 + +### 可靠性要求 + +1. API不能因为外部输入(输入参数、系统状态、外部数据等)或者内部状态、数据异常而崩溃,应该返回确定的错误码或者抛出预定义的异常。 +2. API应明确调用是同步还是异步调用,若是同步调用,应明确超时上限或者允许调用者设置超时时间,避免调用卡死导致业务无响应。 +3. API务必支持多线程重入。 +4. 满足幂等性要求,相同业务含义的请求API调用一次或多次重试总能获得相同的效果(API调用依赖外部资源的变化除外)。针对可重入的API调用实现内部应尽量避免引入时变因素,如系统tick、静态变量、没有互斥保护的全局变量等;针对同一客户端的多次重复调用,可以使用contextID、clientToken、squenceNo等作为调用入参。 +5. API内部创建对象的生命周期要闭合,避免对象资源泄漏。 +6. API要明确客户端调用失败后,能够发起重试的最大次数。 + +### 测试要求 +1. 新增API必须同步交付API自动化测试用例,用例100%覆盖API接口。 +2. 用例场景单一,单条用例覆盖接口单个功能场景,简化单条用例代码逻辑。 +3. 用例执行高效,每条用例执行时间控制在毫秒级。 +4. 用例执行全自动化:接口用例需要达成100%自动化。 +5. 用例有效性:用户要求必须存在断言,且不能仅是检查是否抛出异常,需要有功能逻辑的断言。 + +### 编程语言要求 + +API根据其编程语言类型,需要遵守相应的OpenHarmony编程语言规范。 diff --git "a/website/docs/_posts/footer/OpenHarmony\345\225\206\346\240\207\344\275\277\347\224\250\346\214\207\345\215\227.md" "b/website/docs/_posts/footer/OpenHarmony\345\225\206\346\240\207\344\275\277\347\224\250\346\214\207\345\215\227.md" index c88b943172a8a0054585b19b86aaad8b1350de50..e95c7039234c949cb69bc274f677cb2ccc51036e 100644 --- "a/website/docs/_posts/footer/OpenHarmony\345\225\206\346\240\207\344\275\277\347\224\250\346\214\207\345\215\227.md" +++ "b/website/docs/_posts/footer/OpenHarmony\345\225\206\346\240\207\344\275\277\347\224\250\346\214\207\345\215\227.md" @@ -30,6 +30,7 @@ editLink: false * 商标使用目的(商业/非商业) * 拟使用方式 * 拟使用场景 + * 关于通过OpenHarmony兼容性测试认证的认证标识使用指引另行规定 # OpenHarmony商标使用规范 diff --git a/website/docs/_posts/zh-cn/release-notes/OpenHarmony-1-0.md b/website/docs/_posts/release-notes/OpenHarmony-1-0.md similarity index 98% rename from website/docs/_posts/zh-cn/release-notes/OpenHarmony-1-0.md rename to website/docs/_posts/release-notes/OpenHarmony-1-0.md index 4c5e494a3c4dfef7fc5716f25c44b530c1a48c0d..d99461dc316d39ad6c3409166239e02d840fd5a9 100644 --- a/website/docs/_posts/zh-cn/release-notes/OpenHarmony-1-0.md +++ b/website/docs/_posts/release-notes/OpenHarmony-1-0.md @@ -1,16 +1,16 @@ --- -title: OpenHarmony-1-0 -permalink: /pages/extra/d09857/ +title: OpenHarmony-1-0.md +permalink: /pages/extra/0a1ae8/ navbar: true sidebar: false prev: false next: false -search: true -article: true +search: false +article: false comment: false editLink: false -date: 2022-02-14 21:31:37 ---- +date: 2021-12-30 18:17:34 +--- # OpenHarmony 1.0(2020-09-10) - [版本概述](#section249611124916) diff --git a/website/docs/_posts/zh-cn/release-notes/OpenHarmony-1-1-0-LTS.md b/website/docs/_posts/release-notes/OpenHarmony-1-1-0-LTS.md similarity index 99% rename from website/docs/_posts/zh-cn/release-notes/OpenHarmony-1-1-0-LTS.md rename to website/docs/_posts/release-notes/OpenHarmony-1-1-0-LTS.md index 6aabc3cffef51e7c2fce9c5e4344b7fd8ebf0226..e3d0d099fd280146aa0ba9dd8cf814a7063888d9 100644 --- a/website/docs/_posts/zh-cn/release-notes/OpenHarmony-1-1-0-LTS.md +++ b/website/docs/_posts/release-notes/OpenHarmony-1-1-0-LTS.md @@ -1,16 +1,16 @@ --- -title: OpenHarmony-1-1-0-LTS -permalink: /pages/extra/cada0e/ +title: OpenHarmony-1-1-0-LTS.md +permalink: /pages/extra/5e1674/ navbar: true sidebar: false prev: false next: false -search: true -article: true +search: false +article: false comment: false editLink: false -date: 2022-02-14 21:31:37 ---- +date: 2021-12-30 18:17:34 +--- # OpenHarmony 1.1.0 LTS(2021-04-01) - [版本概述](#section1846294912228) diff --git a/website/docs/_posts/zh-cn/release-notes/OpenHarmony-1-1-1-LTS.md b/website/docs/_posts/release-notes/OpenHarmony-1-1-1-LTS.md similarity index 98% rename from website/docs/_posts/zh-cn/release-notes/OpenHarmony-1-1-1-LTS.md rename to website/docs/_posts/release-notes/OpenHarmony-1-1-1-LTS.md index 7712e4b7918cd2b5b840edbc131a6a772eabc096..34246d36ee10d4f6e6b9103437a60e98469bda98 100644 --- a/website/docs/_posts/zh-cn/release-notes/OpenHarmony-1-1-1-LTS.md +++ b/website/docs/_posts/release-notes/OpenHarmony-1-1-1-LTS.md @@ -1,153 +1,153 @@ --- -title: OpenHarmony-1-1-1-LTS -permalink: /pages/extra/f5599c/ +title: OpenHarmony-1-1-1-LTS.md +permalink: /pages/extra/a70d2c/ navbar: true sidebar: false prev: false next: false -search: true -article: true +search: false +article: false comment: false editLink: false -date: 2022-02-14 21:31:37 ---- -# OpenHarmony 1.1.1 LTS(2021-06-22) - -- [版本概述](#section1846294912228) -- [源码获取](#section84808293211) - - [通过镜像站点获取](#section8394142222113) - - [通过repo下载](#section7180193542317) - -- [更新说明](#section175225345334) - -## 版本概述 - -更新发布LTS(long-term support)长期支持版本OpenHarmony 1.1.1,本版本在1.1.0版本的基础上新增了部分功能和修复了部分缺陷。 - -## 源码获取 - -### 通过镜像站点获取 - -**表 1** 源码获取路径 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

版本源码

-

版本信息

-

下载站点

-

SHA256校验码

-

全量代码

-

1.1.1

-

站点

-

SHA256校验码

-

Hi3861解决方案(二进制)

-

1.1.1

-

站点

-

SHA256校验码

-

Hi3518解决方案(二进制)

-

1.1.1

-

站点

-

SHA256校验码

-

Hi3516解决方案(二进制)

-

1.1.1

-

站点

-

SHA256校验码

-

Release Notes

-

1.1.1

-

站点

-

-

-
- -### 通过repo下载 - -下载命令如下: - -repo init -u [https://gitee.com/openharmony/manifest.git](https://gitee.com/openharmony/manifest.git) -b refs/tags/OpenHarmony-v1.1.1-LTS --no-repo-verify - -## 更新说明 - -本版本完全继承了OpenHarmony 1.1.0的所有特性,并在OpenHarmony 1.1.0版本的基础上,对各模块进行了缺陷修复和性能优化,详情请参考下表。 - -**表 2** 版本更新说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

类别

-

更新内容

-

通信

-
  • 更新了部分STA相关功能的数据类以及新增了几个AP相关功能的innerkits接口
  • 新增了蓝牙相关功能的innerkits接口,包括BLE设备gatt相关的操作,以及BLE广播、扫描等功能
-

安全

-
  • 支持调用方仅使用绑定的能力,裁剪设备认证能力
  • 支持了huks裁剪设备认证
-

内核

-
  • 修复clang编译的系统镜像内核栈回溯功能失效
  • 解决调度中存在有符号数与无符号数比较
  • 修复setitimer中定时给进程发信号时未持有调度锁,导致踩内存等问题
  • lwip适配内核posix接口
  • 修复sigaction中sigsuspend的后执行信号顺序与预期不符,信号注册时未屏蔽用户传入信号屏蔽字段
-

驱动

-
  • liteos_m上的编译错误修复
  • 合入解决mmc crash的问题
-

AI

-
  • AI添加共享内存机制
  • AI添加linux内核适配
  • 同步算法禁用异步调用
  • 添加gitignore和Cmakelist
-

图形

-
  • 修复circle progress开启端点样式情况下,进度为0,圆形端点需要绘制问题
  • 修改旋转表冠灵敏度及方向相关问题
  • 增加 UIList 自动对齐动画时间设置功能
  • 修复当LineBreakMode为LINE_BRAK_ELLIPSIS时UILabel GetText宽度值错误
  • slider组件新增样式属性
  • UITimePicker增加设置循环接口
  • 修复定点数优化导致的NEON旋转缩放变换显示异常的BUG
  • 修复换行算法在字符串中有多个换行符时存在的换行错误
  • 修复表盘指针显示花屏问题
-

全球化

-
  • 添加日期时间模板Ed和MEd
-

ACE框架

-
  • 修复checkbox/radio点击事件异常
  • 修复list和if指令场景JS应用crash问题
  • slider样式归一处理
  • pickerview组件支持循环滑动
  • 修改align-item设置值为stretch情况下,子项居中显示的问题
-
- +date: 2021-12-30 18:17:34 +--- +# OpenHarmony 1.1.1 LTS(2021-06-22) + +- [版本概述](#section1846294912228) +- [源码获取](#section84808293211) + - [通过镜像站点获取](#section8394142222113) + - [通过repo下载](#section7180193542317) + +- [更新说明](#section175225345334) + +## 版本概述 + +更新发布LTS(long-term support)长期支持版本OpenHarmony 1.1.1,本版本在1.1.0版本的基础上新增了部分功能和修复了部分缺陷。 + +## 源码获取 + +### 通过镜像站点获取 + +**表 1** 源码获取路径 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

版本源码

+

版本信息

+

下载站点

+

SHA256校验码

+

全量代码

+

1.1.1

+

站点

+

SHA256校验码

+

Hi3861解决方案(二进制)

+

1.1.1

+

站点

+

SHA256校验码

+

Hi3518解决方案(二进制)

+

1.1.1

+

站点

+

SHA256校验码

+

Hi3516解决方案(二进制)

+

1.1.1

+

站点

+

SHA256校验码

+

Release Notes

+

1.1.1

+

站点

+

-

+
+ +### 通过repo下载 + +下载命令如下: + +repo init -u [https://gitee.com/openharmony/manifest.git](https://gitee.com/openharmony/manifest.git) -b refs/tags/OpenHarmony-v1.1.1-LTS --no-repo-verify + +## 更新说明 + +本版本完全继承了OpenHarmony 1.1.0的所有特性,并在OpenHarmony 1.1.0版本的基础上,对各模块进行了缺陷修复和性能优化,详情请参考下表。 + +**表 2** 版本更新说明 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

类别

+

更新内容

+

通信

+
  • 更新了部分STA相关功能的数据类以及新增了几个AP相关功能的innerkits接口
  • 新增了蓝牙相关功能的innerkits接口,包括BLE设备gatt相关的操作,以及BLE广播、扫描等功能
+

安全

+
  • 支持调用方仅使用绑定的能力,裁剪设备认证能力
  • 支持了huks裁剪设备认证
+

内核

+
  • 修复clang编译的系统镜像内核栈回溯功能失效
  • 解决调度中存在有符号数与无符号数比较
  • 修复setitimer中定时给进程发信号时未持有调度锁,导致踩内存等问题
  • lwip适配内核posix接口
  • 修复sigaction中sigsuspend的后执行信号顺序与预期不符,信号注册时未屏蔽用户传入信号屏蔽字段
+

驱动

+
  • liteos_m上的编译错误修复
  • 合入解决mmc crash的问题
+

AI

+
  • AI添加共享内存机制
  • AI添加linux内核适配
  • 同步算法禁用异步调用
  • 添加gitignore和Cmakelist
+

图形

+
  • 修复circle progress开启端点样式情况下,进度为0,圆形端点需要绘制问题
  • 修改旋转表冠灵敏度及方向相关问题
  • 增加 UIList 自动对齐动画时间设置功能
  • 修复当LineBreakMode为LINE_BRAK_ELLIPSIS时UILabel GetText宽度值错误
  • slider组件新增样式属性
  • UITimePicker增加设置循环接口
  • 修复定点数优化导致的NEON旋转缩放变换显示异常的BUG
  • 修复换行算法在字符串中有多个换行符时存在的换行错误
  • 修复表盘指针显示花屏问题
+

全球化

+
  • 添加日期时间模板Ed和MEd
+

ACE框架

+
  • 修复checkbox/radio点击事件异常
  • 修复list和if指令场景JS应用crash问题
  • slider样式归一处理
  • pickerview组件支持循环滑动
  • 修改align-item设置值为stretch情况下,子项居中显示的问题
+
+ diff --git a/website/docs/_posts/zh-cn/release-notes/OpenHarmony-v1.1.2-LTS.md b/website/docs/_posts/release-notes/OpenHarmony-v1.1.2-LTS.md similarity index 99% rename from website/docs/_posts/zh-cn/release-notes/OpenHarmony-v1.1.2-LTS.md rename to website/docs/_posts/release-notes/OpenHarmony-v1.1.2-LTS.md index 43d98f428ea21673c3fc012a05add57c59700bac..d08ff350fdab1156772a4f561878e0ee48c7ae09 100644 --- a/website/docs/_posts/zh-cn/release-notes/OpenHarmony-v1.1.2-LTS.md +++ b/website/docs/_posts/release-notes/OpenHarmony-v1.1.2-LTS.md @@ -1,12 +1,12 @@ --- -title: OpenHarmony-v1.1.2-LTS -permalink: /pages/extra/055b26/ +title: OpenHarmony-v1.1.2-LTS.md +permalink: /pages/extra/4f9c6b/ navbar: true sidebar: false prev: false next: false -search: true -article: true +search: false +article: false comment: false editLink: false --- diff --git a/website/docs/_posts/release-notes/Readme.md b/website/docs/_posts/release-notes/Readme.md new file mode 100644 index 0000000000000000000000000000000000000000..5e15fd577d01733dd6e53ef0e4a0c3a75a437977 --- /dev/null +++ b/website/docs/_posts/release-notes/Readme.md @@ -0,0 +1,28 @@ +--- +title: Readme.md +permalink: /pages/extra/34805f/ +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +date: 2021-12-30 18:17:34 +--- +# OpenHarmony Release Notes +## OpenHarmony 3.x Releases +[OpenHarmony v3.0 LTS (2021-09-30)](/pages/00000300) + +## OpenHarmony 2.x Releases + +- [OpenHarmony v2.2 beta2 (2021-08-04)](/pages/00000301) +- [OpenHarmony 2.0 Canary (2021-06-02)](/pages/00000302) +## OpenHarmony 1.x Releases +- [OpenHarmony v1.1.3 LTS (2021-09-30)](/pages/00000303) +- [OpenHarmony v1.1.2 LTS (2021-08-04)](/pages/extra/4f9c6b/) +- [OpenHarmony 1.1.1 LTS (2021-06-22)](/pages/extra/a70d2c/) +- [OpenHarmony 1.1.0 LTS (2021-04-01)](/pages/extra/5e1674/) +- [OpenHarmony 1.0 (2020-09-10)](/pages/extra/0a1ae8/) + diff --git a/website/docs/_posts/release-notes/api-change/v2.2-beta2/js-apidiff-v2.2-beta2.md b/website/docs/_posts/release-notes/api-change/v2.2-beta2/js-apidiff-v2.2-beta2.md new file mode 100644 index 0000000000000000000000000000000000000000..dd91ec12a18dd916e76f2aa275720e1d4f3c8a3a --- /dev/null +++ b/website/docs/_posts/release-notes/api-change/v2.2-beta2/js-apidiff-v2.2-beta2.md @@ -0,0 +1,247 @@ +--- +title: js-apidiff-v2.2-beta2.md +permalink: /pages/extra/b0ae7b/ +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +date: 2021-12-30 18:17:33 +--- +# JS API 差异报告 +OpenHarmony 2.2 Beta2相较于OpenHarmony 2.0 Canary版本的API变更如下: +## 标准系统接口变更 + +| 模块名称 | 接口名称 | 变更类型 | 变更说明 | +| -------- | -------- | -------- | -------- | + | 时间日期数字模块-Locale | constructor(locale: string, options?:options) | 新增 | - | + | 时间日期数字模块-Locale | toString(): string | 新增 | - | + | 时间日期数字模块-Locale | maximize(): Locale | 新增 | - | + | 时间日期数字模块-Locale | minimize(): Locale | 新增 | - | + | 时间日期数字模块-Locale | calendar | 新增 | - | + | 时间日期数字模块-Locale | caseFirst | 新增 | - | + | 时间日期数字模块-Locale | collation | 新增 | - | + | 时间日期数字模块-Locale | hourCycle | 新增 | - | + | 时间日期数字模块-Locale | numberingSystem | 新增 | - | + | 时间日期数字模块-Locale | numeric | 新增 | - | + | 时间日期数字模块-Locale | language | 新增 | - | + | 时间日期数字模块-Locale | script | 新增 | - | + | 时间日期数字模块-Locale | region | 新增 | - | + | 时间日期数字模块-Locale | baseName | 新增 | - | + | 时间日期数字模块-DateTimeFormat | constructor(locale: string, options?:options) | 新增 | - | + | 时间日期数字模块-DateTimeFormat | constructor(locale: string[], options?:options) | 新增 | - | + | 时间日期数字模块-DateTimeFormat | resolvedOptions(): DateTimeOptions | 新增 | - | + | 时间日期数字模块-DateTimeFormat | format(date: Date): string; | 新增 | - | + | 时间日期数字模块-DateTimeFormat | formatRange(fromDate: Date, toDate: Date): string; | 新增 | - | + | 时间日期数字模块-NumberFormat | constructor(locale: string, options?:options) | 新增 | - | + | 时间日期数字模块-NumberFormat | constructor(locale: string[], options?:options) | 新增 | - | + | 时间日期数字模块-NumberFormat | resolvedOptions(): NumberOptions | 新增 | - | + | 时间日期数字模块-NumberFormat | format(number: number): string; | 新增 | - | + | 时间日期数字模块-DateTimeOptions | locale | 新增 | - | + | 时间日期数字模块-DateTimeOptions | dateStyle | 新增 | - | + | 时间日期数字模块-DateTimeOptions | timeStyle | 新增 | - | + | 时间日期数字模块-DateTimeOptions | calendar | 新增 | - | + | 时间日期数字模块-DateTimeOptions | dayPeriod | 新增 | - | + | 时间日期数字模块-DateTimeOptions | numberingSystem | 新增 | - | + | 时间日期数字模块-DateTimeOptions | localeMatcher | 新增 | - | + | 时间日期数字模块-DateTimeOptions | timeZone | 新增 | - | + | 时间日期数字模块-DateTimeOptions | hour12 | 新增 | - | + | 时间日期数字模块-DateTimeOptions | hourCycle | 新增 | - | + | 时间日期数字模块-DateTimeOptions | formatMatcher | 新增 | - | + | 时间日期数字模块-DateTimeOptions | weekday | 新增 | - | + | 时间日期数字模块-DateTimeOptions | era | 新增 | - | + | 时间日期数字模块-DateTimeOptions | year | 新增 | - | + | 时间日期数字模块-DateTimeOptions | month | 新增 | - | + | 时间日期数字模块-DateTimeOptions | day | 新增 | - | + | 时间日期数字模块-DateTimeOptions | hour | 新增 | - | + | 时间日期数字模块-DateTimeOptions | minute | 新增 | - | + | 时间日期数字模块-DateTimeOptions | second | 新增 | - | + | 时间日期数字模块-DateTimeOptions | timeZoneName | 新增 | - | + | 时间日期数字模块-NumberOptions | locale | 新增 | - | + | 时间日期数字模块-NumberOptions | compactDisplay | 新增 | - | + | 时间日期数字模块-NumberOptions | currency | 新增 | - | + | 时间日期数字模块-NumberOptions | currencyDisplay | 新增 | - | + | 时间日期数字模块-NumberOptions | currencySign | 新增 | - | + | 时间日期数字模块-NumberOptions | localeMatcher | 新增 | - | + | 时间日期数字模块-NumberOptions | notation | 新增 | - | + | 时间日期数字模块-NumberOptions | numberingSystem | 新增 | - | + | 时间日期数字模块-NumberOptions | signDisplay | 新增 | - | + | 时间日期数字模块-NumberOptions | style | 新增 | - | + | 时间日期数字模块-NumberOptions | unit | 新增 | - | + | 时间日期数字模块-NumberOptions | unitDisplay | 新增 | - | + | 时间日期数字模块-NumberOptions | useGrouping | 新增 | - | + | 时间日期数字模块-NumberOptions | minimumIntegerDigits | 新增 | - | + | 时间日期数字模块-NumberOptions | minimumFractionDigits | 新增 | - | + | 时间日期数字模块-NumberOptions | maximumFractionDigits | 新增 | - | + | 时间日期数字模块-NumberOptions | minimumSignificantDigits | 新增 | - | + | 时间日期数字模块-NumberOptions | maximumSignificantDigits | 新增 | - | +|文件存储- system.file|mkdir|新增|-| +|文件存储- system.file|rmdir|新增|-| +|文件存储- system.file|get|新增|-| +|文件存储- system.file|list|新增|-| +|文件存储- system.file|copy|新增|-| +|文件存储- system.file|move|新增|-| +|文件存储- system.file|delete|新增|-| +|文件存储- system.file|access|新增|-| +|文件存储- system.file|writeText|新增|-| +|文件存储- system.file|writeArrayBuffer|新增|-| +|文件存储- system.file|readText|新增|-| +|文件存储- system.file|readArrayBuffer|新增|-| +|文件存储- fileio|Dir.readSync|新增|-| +|文件存储- fileio|Dir.closeSync|新增|-| +|文件存储- fileio|dirent.name|新增|-| +|文件存储- fileio|dirent.isBlockDevice()|新增|-| +|文件存储- fileio|dirent.isCharacterDevice()|新增|-| +|文件存储- fileio|dirent.isDirectory()|新增|-| +|文件存储- fileio|dirent.isFIFO()|新增|-| +|文件存储- fileio|dirent.isFile()|新增|-| +|文件存储- fileio|dirent.isSocket()|新增|-| +|文件存储- fileio|dirent.isSymbolicLink()|新增|-| +|文件存储- fileio|stat.dev|新增|-| +|文件存储- fileio|stat.ino|新增|-| +|文件存储- fileio|stat.mode|新增|-| +|文件存储- fileio|stat.nlink|新增|-| +|文件存储- fileio|stat.uid|新增|-| +|文件存储- fileio|stat.gid|新增|-| +|文件存储- fileio|stat.rdev|新增|-| +|文件存储- fileio|stat.size|新增|-| +|文件存储- fileio|stat.blocks|新增|-| +|文件存储- fileio|stat.atime|新增|-| +|文件存储- fileio|stat.mtime|新增|-| +|文件存储- fileio|stat.ctime|新增|-| +|文件存储- fileio|stat.isBlockDevice()|新增|-| +|文件存储- fileio|stat.isCharacterDevice()|新增|-| +|文件存储- fileio|stat.isDirectory()|新增|-| +|文件存储- fileio|stat.isFIFO()|新增|-| +|文件存储- fileio|stat.isFile()|新增|-| +|文件存储- fileio|stat.isSocket()|新增|-| +|文件存储- fileio|stat.isSymbolicLink()|新增|-| +|文件存储- fileio|Stream.flushSync()|新增|-| +|文件存储- fileio|Stream.writeSync()|新增|-| +|文件存储- fileio|Stream.readSync()|新增|-| +|文件存储- fileio|Stream.closeSync()|新增|-| +|文件存储- fileio|fileio.accessSync()|新增|-| +|文件存储- fileio|fileio.chmodSync()|新增|-| +|文件存储- fileio|fileio.chownSync()|新增|-| +|文件存储- fileio|fileio.closeSync()|新增|-| +|文件存储- fileio|fileio.copyFileSync()|新增|-| +|文件存储- fileio|fileio.createStreamSync()|新增|-| +|文件存储- fileio|fileio.fchmodSync()|新增|-| +|文件存储- fileio|fileio.fchownSync()|新增|-| +|文件存储- fileio|fileio.fdopenStreamSync()|新增|-| +|文件存储- fileio|fileio.fstatSync()|新增|-| +|文件存储- fileio|fileio.fsyncSync()|新增|-| +|文件存储- fileio|fileio.ftruncateSync()|新增|-| +|文件存储- fileio|fileio.mkdirSync()|新增|-| +|文件存储- fileio|fileio.openSync()|新增|-| +|文件存储- fileio|fileio.opendirSync()|新增|-| +|文件存储- fileio|fileio.readSync()|新增|-| +|文件存储- fileio|fileio.renameSync()|新增|-| +|文件存储- fileio|fileio.rmdirSync()|新增|-| +|文件存储- fileio|fileio.statSync()|新增|-| +|文件存储- fileio|fileio.truncateSync()|新增|-| +|文件存储- fileio|fileio.unlinkSync()|新增|-| +|文件存储- fileio|fileio.writeSync()|新增|-| +|设备管理-DeviceManager|DeviceInfo|新增|-| +|设备管理-DeviceManager|DeviceType|新增|-| +|设备管理-DeviceManager|DeviceStateChangeAction|新增|-| +|设备管理-DeviceManager|SubscribeInfo|新增|-| +|设备管理-DeviceManager|DiscoverMode|新增|-| +|设备管理-DeviceManager|ExchangeMedium|新增|-| +|设备管理-DeviceManager|ExchangeFreq|新增|-| +|设备管理-DeviceManager|SubscribeCap|新增|-| +|设备管理-DeviceManager|createDeviceManager(bundleName: string, callback: AsyncCallback): void|新增|-| +|设备管理-DeviceManager|release(): void|新增|-| +|设备管理-DeviceManager|getTrustedDeviceListSync(): Array|新增|-| +|设备管理-DeviceManager|startDeviceDiscovery(subscribeInfo: SubscribeInfo): void|新增|-| +|设备管理-DeviceManager|stopDeviceDiscovery(subscribeId: number): void|新增|-| +|设备管理-DeviceManager|authenticateDevice(deviceInfo: DeviceInfo): void|新增|-| +|设备管理-DeviceManager|on(type: 'deviceStateChange', callback: Callback<{ action: DeviceStateChangeAction, device: DeviceInfo }>): void|新增|-| +|设备管理-DeviceManager|off(type: 'deviceStateChange', callback?: Callback<{ action: DeviceStateChangeAction, device: DeviceInfo }>): void|新增|-| +|设备管理-DeviceManager|on(type: 'deviceFound', callback: Callback<{ subscribeId: number, device: DeviceInfo }>): void|新增|-| +|设备管理-DeviceManager|off(type: 'deviceFound', callback?: Callback<{ subscribeId: number, device: DeviceInfo }>): void|新增|-| +|设备管理-DeviceManager|on(type: 'discoverFail', callback: Callback<{ subscribeId: number, reason: number }>): void|新增|-| +|设备管理-DeviceManager|off(type: 'discoverFail', callback?: Callback<{ subscribeId: number, reason: number }>): void|新增|-| +|设备管理-DeviceManager|on(type: 'authResult', callback: Callback<{ deviceId: string, status: number, reason: number }>): void|新增|-| +|设备管理-DeviceManager|off(type: 'authResult', callback?: Callback<{ deviceId: string, status: number, reason: number }>): void|新增|-| +|设备管理-DeviceManager|on(type: 'serviceDie', callback: () => void): void|新增|-| +|设备管理-DeviceManager|off(type: 'serviceDie', callback?: () => void): void|新增|-| +|播放录制|createAudioPlayer(): AudioPlayer|新增|-| +|播放录制|AudioState|新增|-| +|播放录制|play(): void|新增|-| +|播放录制|pause(): void|新增|-| +|播放录制|stop(): void|新增|-| +|播放录制|seek(timeMs: number): void|新增|-| +|播放录制|setVolume(vol: number): void|新增|-| +|播放录制|reset(): void|新增|-| +|播放录制|release(): void|新增|-| +|播放录制|src: string|新增|-| +|播放录制|loop: boolean|新增|-| +|播放录制|readonly currentTime: number|新增|-| +|播放录制|readonly duration: number|新增|-| +|播放录制|readonly state: AudioState|新增|-| +|播放录制|on(type: 'play' / 'pause' / 'stop' / 'reset' / 'dataLoad' / 'finish' / 'volumeChange', callback: () => void): void|新增|-| +|播放录制|on(type: 'timeUpdate', callback: Callback): void|新增|-| +|播放录制|on(type: 'error', callback: ErrorCallback): void|新增|-| +|音频管理|getAudioManager(): AudioManager|新增|-| +|音频管理|AudioVolumeType|新增|-| +|音频管理|MEDIA|新增|-| +|音频管理|RINGTONE|新增|-| +|音频管理|DeviceFlag|新增|-| +|音频管理|OUTPUT_DEVICES_FLAG|新增|-| +|音频管理|INPUT_DEVICES_FLAG |新增|-| +|音频管理|ALL_DEVICES_FLAG |新增|-| +|音频管理|DeviceRole |新增|-| +|音频管理|INPUT_DEVICE |新增|-| +|音频管理|OUTPUT_DEVICE |新增|-| +|音频管理|DeviceType |新增|-| +|音频管理|INVALID |新增|-| +|音频管理|SPEAKER |新增|-| +|音频管理|WIRED_HEADSET |新增|-| +|音频管理|BLUETOOTH_SCO |新增|-| +|音频管理|BLUETOOTH_A2DP |新增|-| +|音频管理|MIC|新增|-| +|音频管理|AudioRingMode |新增|-| +|音频管理|RINGER_MODE_NORMAL |新增|-| +|音频管理|RINGER_MODE_SILENT|新增|-| +|音频管理|RINGER_MODE_VIBRATE |新增|-| +|音频管理|setVolume(audioType: AudioVolumeType, volume: number,callback: AsyncCallback): void|新增|-| +|音频管理|setVolume(audioType: AudioVolumeType, volume: number): Promise|新增|-| +|音频管理|getVolume(audioType: AudioVolumeType, callback: AsyncCallback): void|新增|-| +|音频管理|getVolume(audioType: AudioVolumeType): Promise|新增|-| +|音频管理|getMinVolume(audioType: AudioVolumeType, callback: AsyncCallback): void|新增|-| +|音频管理|getMinVolume(audioType: AudioVolumeType): Promise|新增|-| +|音频管理|getMaxVolume(audioType: AudioVolumeType, callback: AsyncCallback): void|新增|-| +|音频管理|getMaxVolume(audioType: AudioVolumeType): Promise|新增|-| +|音频管理|getDevices(deviceFlag: DeviceFlag, callback: AsyncCallback): void|新增|-| +|音频管理|getDevices(deviceFlag: DeviceFlag): Promise|新增|-| +|音频管理|getRingerMode(callback: AsyncCallback): void|新增|-| +|音频管理|getRingerMode(): Promise|新增|-| +|音频管理|setRingerMode(mode: AudioRingMode, callback: AsyncCallback): void|新增|-| +|音频管理|setRingerMode(mode: AudioRingMode): Promise|新增|-| +|音频管理|isMute(volumeType: AudioVolumeType, callback: AsyncCallback): void|新增|-| +|音频管理|isMute(volumeType: AudioVolumeType): Promise|新增|-| +|音频管理|isActive(volumeType: AudioVolumeType, callback: AsyncCallback): void|新增|-| +|音频管理|isActive(volumeType: AudioVolumeType): Promise|新增|-| +|音频管理|isMicrophoneMute(callback: AsyncCallback): void|新增|-| +|音频管理|isMicrophoneMute(): Promise|新增|-| +|音频管理|mute(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback) : void|新增|-| +|音频管理|mute(volumeType: AudioVolumeType, mute: boolean): Promise|新增|-| +|音频管理|setMicrophoneMute(mute: boolean, callback: AsyncCallback): void|新增|-| +|音频管理|setMicrophoneMute(mute: boolean): Promise|新增|-| +|音频管理|isDeviceActive(deviceType: DeviceType, callback: AsyncCallback): void|新增|-| +|音频管理|isDeviceActive(deviceType: DeviceType): Promise|新增|-| +|音频管理|setDeviceActive(deviceType: DeviceType, active: boolean, callback: AsyncCallback): void|新增|-| +|音频管理|setDeviceActive(deviceType: DeviceType, active: boolean): Promise|新增|-| +|音频管理|getAudioParameter(key: string, callback: AsyncCallback): void|新增|-| +|音频管理|getAudioParameter(key: string): Promise|新增|-| +|音频管理|setAudioParameter(key: string, value: string, callback: AsyncCallback): void|新增|-| +|音频管理|setAudioParameter(key: string, value: string): Promise|新增|-| +|音频管理|AudioDeviceDescriptor|新增|-| +|音频管理|readonly deviceRole: DeviceRole|新增|-| +|音频管理|readonly deviceType: DeviceType|新增|-| +|音频管理|AudioDeviceDescriptors |新增|-| + diff --git a/website/docs/_posts/release-notes/api-change/v2.2-beta2/native-apidiff-v2.2-beta2.md b/website/docs/_posts/release-notes/api-change/v2.2-beta2/native-apidiff-v2.2-beta2.md new file mode 100644 index 0000000000000000000000000000000000000000..ff37a682e5fbc2ea64f65231cb161cee8a1383c9 --- /dev/null +++ b/website/docs/_posts/release-notes/api-change/v2.2-beta2/native-apidiff-v2.2-beta2.md @@ -0,0 +1,32 @@ +--- +title: native-apidiff-v2.2-beta2.md +permalink: /pages/extra/0d34cb/ +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +date: 2021-12-30 18:17:33 +--- +# Native API 差异报告 +OpenHarmony 2.2 Beta2相较于OpenHarmony 2.0 Canary版本的API变更如下: +## 轻量级系统接口变更 + +| 模块名称 | 接口名称 | 变更类型 | 变更类型 | +| -------- | -------- | -------- | -------- | +| global_i18n_lite | static LocaleInfo LocaleInfo ::ForLanguageTag(const char *languageTag, I18nStatus &status); | 新增 | 新增接口 | +| global_i18n_lite | const char LocaleInfo ::*GetExtension(const char *key); | 新增 | 新增接口 | +| global_i18n_lite | WeekInfo::WeekInfo(const LocaleInfo &localeInfo, I18nStatus &status); | 新增 | 新增接口 | +| global_i18n_lite | uint8_t WeekInfo::GetFirstDayOfWeek(); | 新增 | 新增接口 | +| global_i18n_lite | uint8_t WeekInfo::GetMinimalDaysInFirstWeek(); | 新增 | 新增接口 | +| global_i18n_lite | uint8_t WeekInfo::GetFirstDayOfWeekend(); | 新增 | 新增接口 | +| global_i18n_lite | uint8_t WeekInfo::GetLastDayOfWeekend(); | 新增 | 新增接口 | +| global_i18n_lite | int PluralFormat::GetPluralRuleIndex(double number, I18nStatus status); | 新增 | 新增接口 | +| powermgr_powermgr_lite | const RunningLock *CreateRunningLock(const char *name, RunningLockType type, RunningLockFlag flag); | 新增 | 新增接口 | +| powermgr_powermgr_lite | void DestroyRunningLock(const RunningLock *lock); | 新增 | 新增接口 | +| powermgr_powermgr_lite | BOOL AcquireRunningLock(const RunningLock *lock); | 新增 | 新增接口 | +| powermgr_powermgr_lite | BOOL ReleaseRunningLock(const RunningLock *lock); | 新增 | 新增接口 | +| powermgr_powermgr_lite | BOOL IsRunningLockHolding(const RunningLock *lock); | 新增 | 新增接口 | \ No newline at end of file diff --git a/website/docs/_posts/release-notes/api-change/v3.0-LTS/js-apidiff-v3.0-lts.md b/website/docs/_posts/release-notes/api-change/v3.0-LTS/js-apidiff-v3.0-lts.md new file mode 100644 index 0000000000000000000000000000000000000000..87681d4d65cd033616f70739b912861994b02dd7 --- /dev/null +++ b/website/docs/_posts/release-notes/api-change/v3.0-LTS/js-apidiff-v3.0-lts.md @@ -0,0 +1,638 @@ +--- +title: js-apidiff-v3.0-lts.md +permalink: /pages/extra/624df1/ +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +date: 2021-12-30 18:17:33 +--- +# JS API 差异报告 +OpenHarmony 3.0 LTS相较于OpenHarmony 2.2 Beta2版本的API变更如下: +## 标准系统接口变更 + +| 模块名称 | 接口名称 | 变更类型 | 变更说明 | +| -------- | -------- | -------- | -------- | +|语言编译器运行时-worker|postMessage(obj):void|新增|宿主线程与worker通信,传递数据| +|语言编译器运行时-worker|postMessage(message: Object, options?: PostMessageOptions):void|新增|宿主线程与worker通信,转移arrayBuffer的数据控制权| +|语言编译器运行时-worker|terminate():void|新增|宿主线程主动停止worker| +|语言编译器运行时-worker|on(type: string, listener: EventListener): void|新增|向worker添加回调接口| +|语言编译器运行时-worker|once(type: string, listener: EventListener): void|新增|向worker添加回调接口,并且在回调一次会释放回调| +|语言编译器运行时-worker|off(type: string, listener?: EventListener): void|新增|删除worker已添加的回调接口| +|语言编译器运行时-worker|addEventListener(type: string, listener: EventListener): void|新增|向worker添加回调接口| +|语言编译器运行时-worker|removeEventListener(type: string, listener?: EventListener): void|新增|删除worker已添加的回调接口| +|语言编译器运行时-worker|removeAllListener(): void|新增|删除worker所有的回调接口| +|语言编译器运行时-worker|dispatchEvent(event: Event): boolean|新增|向worker发送指定事件,触发回调接口| +|语言编译器运行时-parentPort|postMessage(obj):void|新增|worker与宿主线程通信,传递数据| +|语言编译器运行时-parentPort|postMessage(message: Object, options?: PostMessageOptions):void|新增|worker与宿主线程通信,转移arrayBuffer的数据控制权| +|语言编译器运行时-parentPort|close(): void|新增|worker主动终止| +|语言编译器运行时-Util|printf(format: string, ...args: Object[]): string|新增|-| +|语言编译器运行时-Util|getErrorString(errno: number): string|新增|-| +|语言编译器运行时-Util|callbackWrapper(original: Function): (err: Object, value: Object) => void|新增|-| +|语言编译器运行时-Util|promiseWrapper(original: (err: Object, value: Object) => void): Object|新增|-| +|语言编译器运行时-Util|new TextDecoder([encoding[, options]])|新增|-| +|语言编译器运行时-Util|decode([input[, options]]):string|新增|-| +|语言编译器运行时-Util|new TextEncoder()|新增|-| +|语言编译器运行时-Util|encode(input?: string): Uint8Array;|新增|-| +|语言编译器运行时-Util|"encodeInto(input: string,dest: Uint8Array,): { read: number; written: number };"|新增|-| +|语言编译器运行时-Util|readonly encoding: string;|新增|-| +|语言编译器运行时-Util|readonly fatal: boolean;|新增|-| +|语言编译器运行时-Util|readonly ignoreBOM = false;|新增|-| +|语言编译器运行时-Util|readonly encoding = "utf-8";|新增|-| +|语言编译器运行时-URL|new URL(url: string, base?: string/URL)|新增|-| +|语言编译器运行时-URL|toString(): string;|新增|-| +|语言编译器运行时-URL|toJSON(): string;|新增|-| +|语言编译器运行时-URL|new URSearchParams()|新增|-| +|语言编译器运行时-URL|new URSearchParams(string)|新增|-| +|语言编译器运行时-URL|new URSearchParams(obj)|新增|-| +|语言编译器运行时-URL|new URSearchParams(iterable)|新增|-| +|语言编译器运行时-URL|append(name: string, value: string): void;|新增|-| +|语言编译器运行时-URL|delete(name: string): void;|新增|-| +|语言编译器运行时-URL|entries(): IterableIterator<[string, string]>;|新增|-| +|语言编译器运行时-URL|forEach(callbackfn: (value: string, key: string, parent: this) => void, thisArg?: any,): void;|新增|-| +|语言编译器运行时-URL|get(name: string): string / null;|新增|-| +|语言编译器运行时-URL|getAll(name: string): string[];|新增|-| +|语言编译器运行时-URL|has(name: string): boolean;|新增|-| +|语言编译器运行时-URL|keys(): IterableIterator;|新增|-| +|语言编译器运行时-URL|set(name: string, value: string): void;|新增|-| +|语言编译器运行时-URL|sort():void;|新增|-| +|语言编译器运行时-URL|toString():string|新增|-| +|语言编译器运行时-URL|values(): IterableIterator;|新增|-| +|语言编译器运行时-URL|URSearchParams[Symbol.iterator]()|新增|-| +|语言编译器运行时-URL|hash: string;|新增|-| +|语言编译器运行时-URL|host: string;|新增|-| +|语言编译器运行时-URL|hostname: string;|新增|-| +|语言编译器运行时-URL|href: string;|新增|-| +|语言编译器运行时-URL|readonly origin: string;|新增|-| +|语言编译器运行时-URL|password: string;|新增|-| +|语言编译器运行时-URL|pathname: string;|新增|-| +|语言编译器运行时-URL|port: string;|新增|-| +|语言编译器运行时-URL|protocol: string;|新增|-| +|语言编译器运行时-URL|search: string;|新增|-| +|语言编译器运行时-URL|readonly searchParams: URLSearchParams;|新增|-| +|语言编译器运行时-URL|username: string;|新增|-| +|语言编译器运行时-ChildProcess|readonly pid: number;|新增|-| +|语言编译器运行时-ChildProcess|readonly ppid: number;|新增|-| +|语言编译器运行时-ChildProcess|readonly exitCode: number;|新增|-| +|语言编译器运行时-ChildProcess|readonly killed: boolean;|新增|-| +|语言编译器运行时-ChildProcess|wait(): Promise;|新增|-| +|语言编译器运行时-ChildProcess|getOutput(): Promise;|新增|-| +|语言编译器运行时-ChildProcess|getErrorOutput(): Promise;|新增|-| +|语言编译器运行时-ChildProcess|close(): void;|新增|-| +|语言编译器运行时-ChildProcess|kill(signal: number): void;|新增|-| +|语言编译器运行时-process|runCmd(command: string,options?: { timeout : number, killSignal : number / string, maxBuffer : number }): ChildProcess;|新增|-| +|语言编译器运行时-process|getPid(): number;|新增|-| +|语言编译器运行时-process|getPpid(): number;|新增|-| +|语言编译器运行时-process|abort(): void;|新增|-| +|语言编译器运行时-process|on(type: string, listener: EventListener): void;|新增|-| +|语言编译器运行时-process|exit(code?:number): void;|新增|-| +|语言编译器运行时-process|cwd(): string;|新增|-| +|语言编译器运行时-process|chdir(dir: string): void;|新增|-| +|语言编译器运行时-process|getEgid(): number;|新增|-| +|语言编译器运行时-process|getEuid(): number;|新增|-| +|语言编译器运行时-process|getGid(): number|新增|-| +|语言编译器运行时-process|getUid(): number;|新增|-| +|语言编译器运行时-process|uptime(): number;|新增|-| +|语言编译器运行时-process|getGroups(): number[];|新增|-| +|语言编译器运行时-process|kill(signal?: number, pid?: number): boolean;|新增|-| +|升级服务子系统-Updater|checkNewVersion(): Promise;|新增| -| +|升级服务子系统-Updater|rebootAndCleanUserData(callback: AsyncCallback): void;|新增| -| +|升级服务子系统-Updater|rebootAndCleanCache(): Promise;|新增| -| +|升级服务子系统-Updater|function getUpdaterFromOther(device: string, updateType?: UpdateTypes): Updater;|新增| -| +|升级服务子系统-Updater|cancel(): void;|新增| -| +|升级服务子系统-Updater|upgrade(): void;|新增| -| +|升级服务子系统-Updater|off(eventType: 'downloadProgress', callback?: UpdateProgressCallback): void;|新增| -| +|升级服务子系统-Updater|getUpdatePolicy(callback: AsyncCallback): void;|新增| -| +|升级服务子系统-Updater|function getUpdaterForOther(device: string, updateType?: UpdateTypes): Updater;|新增| -| +|升级服务子系统-Updater|setUpdatePolicy(policy: UpdatePolicy, callback: AsyncCallback): void;|新增| -| +|升级服务子系统-Updater|getNewVersionInfo(): Promise;|新增| -| +|升级服务子系统-Updater|function getUpdater(updateType?: UpdateTypes): Updater;|新增| -| +|升级服务子系统-Updater|applyNewVersion(callback: AsyncCallback): void;|新增| -| +|升级服务子系统-Updater|rebootAndCleanUserData(): Promise;|新增| -| +|升级服务子系统-Updater|off(eventType: 'verifyProgress', callback?: UpdateProgressCallback): void;|新增| -| +|升级服务子系统-Updater|on(eventType: 'upgradeProgress', callback: UpdateProgressCallback): void;|新增| -| +|升级服务子系统-Updater|checkNewVersion(callback: AsyncCallback): void;|新增| -| +|升级服务子系统-Updater|on(eventType: 'downloadProgress', callback: UpdateProgressCallback): void;|新增| -| +|升级服务子系统-Updater|getUpdatePolicy(): Promise;|新增| -| +|升级服务子系统-Updater|download(): void;|新增| -| +|升级服务子系统-Updater|off(eventType: 'upgradeProgress', callback?: UpdateProgressCallback): void;|新增| -| +|升级服务子系统-Updater|getNewVersionInfo(callback: AsyncCallback): void;|新增| -| +|升级服务子系统-Updater|on(eventType: 'verifyProgress', callback: UpdateProgressCallback): void;|新增| -| +|升级服务子系统-Updater|verifyUpdatePackage(upgradeFile: string, certsFile: string): void;|新增| -| +|升级服务子系统-Updater|setUpdatePolicy(policy: UpdatePolicy): Promise;|新增| -| +|升级服务子系统-Updater|rebootAndCleanCache(callback: AsyncCallback): void;|新增| -| +|升级服务子系统-Updater|applyNewVersion(): Promise;|新增| -| +|全球化子系统-I18n|getSystemLanguages(): Array;|新增| -| +|全球化子系统-I18n|getSystemCountries(language: string): Array;|新增| -| +|全球化子系统-I18n|isSuggested(language: string, region?: string): boolean;|新增| -| +|全球化子系统-I18n|getSystemLanguage(): string;|新增| -| +|全球化子系统-I18n|setSystemLanguage(language: string);|新增| -| +|全球化子系统-I18n|getSystemRegion(): string;|新增| -| +|全球化子系统-I18n|setSystemRegion(region: string);|新增| -| +|全球化子系统-I18n|"getDisplayCountry(locale: string, displayLocale: string,sentenceCase?: boolean): string;"|新增| -| +|全球化子系统-I18n|getSystemLocale(): string;|新增| -| +|全球化子系统-I18n|setSystemLocale(locale: string);|新增| -| +|全球化子系统-I18n|"getDisplayLanguage(locale: string, displayLocale: string,sentenceCase?: boolean): string;"|新增| -| +|电话子系统-radio|getNetworkState(callback: AsyncCallback): void;getNetworkState(slotId: number, callback: AsyncCallback): void;getNetworkState(slotId?: number): Promise;|新增| -| +|电话子系统-sim|getSimAccountInfo(slotId: number, callback: AsyncCallback): void;getSimAccountInfo(slotId: number): Promise;|新增| -| +|电话子系统-sim|getDefaultVoiceSlotId(callback: AsyncCallback): void;getDefaultVoiceSlotId(): Promise;|新增| -| +|电话子系统-sim|getSimSpn(slotId: number, callback: AsyncCallback): void;getSimSpn(slotId: number): Promise;|新增| -| +|电话子系统-sim|getISOCountryCodeForSim(slotId: number, callback: AsyncCallback): void;getISOCountryCodeForSim(slotId: number): Promise;|新增| -| +|电话子系统-sim|getSimIccId(slotId: number, callback: AsyncCallback): void;getSimIccId(slotId: number): Promise;|新增| -| +|电话子系统-sim|getSimGid1(slotId: number, callback: AsyncCallback): void;getSimGid1(slotId: number): Promise;|新增| -| +|电话子系统-sim|getISOCountryCodeForSim(slotId: number, callback: AsyncCallback): void;getISOCountryCodeForSim(slotId: number): Promise;|新增| -| +|电话子系统-sim|getSimOperatorNumeric(slotId: number, callback: AsyncCallback): void;getSimOperatorNumeric(slotId: number): Promise;|新增| -| +|电话子系统-sim|getSimSpn(slotId: number, callback: AsyncCallback): void;getSimSpn(slotId: number): Promise;|新增| -| +|电话子系统-sim|getSimIccId(slotId: number, callback: AsyncCallback): void;getSimIccId(slotId: number): Promise;|新增| -| +|电话子系统-sim|getIMSI(slotId: number, callback: AsyncCallback): void;getIMSI(slotId: number): Promise;|新增| -| +|电话子系统-call|combineConference(callId: number, callback: AsyncCallback): void;combineConference(callId: number): Promise;|新增| -| +|电话子系统-call|startDTMF(callId: number, character: string, callback: AsyncCallback): void;startDTMF(callId: number, character: string): Promise;|新增| -| +|电话子系统-call|stopDTMF(callId: number, callback: AsyncCallback): void;stopDTMF(callId: number): Promise;|新增| -| +|电话子系统-sim|setDefaultVoiceSlotId(slotId: number, callback: AsyncCallback): void;setDefaultVoiceSlotId(slotId: number): Promise;|新增| -| +|电话子系统-sim|unlockPin(slotId: number, pin: string, callback: AsyncCallback): void;unlockPin(slotId: number, pin: string): Promise;|新增| -| +|电话子系统-sim|alterPin(slotId: number, newPin: string, oldPin: string, callback: AsyncCallback): void;alterPin(slotId: number, newPin: string, oldPin: string): Promise;|新增| -| +|电话子系统-sim|setLockState(slotId: number, pin: string, enable: number, callback: AsyncCallback): void;setLockState(slotId: number, pin: string, enable: number): Promise;|新增| -| +|电话子系统-sim|getSimState(slotId: number, callback: AsyncCallback): void;getSimState(slotId: number): Promise;|新增| -| +|电话子系统-sim|getSimState(slotId: number, callback: AsyncCallback): void;getSimState(slotId: number): Promise;|新增| -| +|电话子系统-sim|getSimState(slotId: number, callback: AsyncCallback): void;getSimState(slotId: number): Promise;|新增| -| +|电话子系统-sim|getSimState(slotId: number, callback: AsyncCallback): void;getSimState(slotId: number): Promise;|新增| -| +|电话子系统-call|isEmergencyPhoneNumber(phoneNumber: string, callback: AsyncCallback): void;isEmergencyPhoneNumber(phoneNumber: string, options: EmergencyNumberOptions, callback: AsyncCallback): void;isEmergencyPhoneNumber(phoneNumber: string, options?: EmergencyNumberOptions): Promise;|新增| -| +|电话子系统-sms|createMessage(pdu: Array, specification: string, callback: AsyncCallback): void;createMessage(pdu: Array, specification: string): Promise;|新增| -| +|电话子系统-call|hasCall(callback: AsyncCallback): void;hasCall(): Promise;|新增| -| +|电话子系统-sms|sendMessage(options: SendMessageOptions): void;|新增| -| +|电话子系统-call|dial(phoneNumber: string, callback: AsyncCallback): void;dial(phoneNumber: string, options: DialOptions, callback: AsyncCallback): void;dial(phoneNumber: string, options?: DialOptions): Promise;|新增| -| +|电话子系统-call|interface DialOptions {extras?: boolean; }|新增| -| +|电话子系统-sms|sendMessage(options: SendMessageOptions): void;|新增| -| +|电话子系统-sms|getDefaultSmsSlotId(callback: AsyncCallback): void;getDefaultSmsSlotId(): Promise;|新增| -| +|电话子系统-call|formatPhoneNumber(phoneNumber: string, callback: AsyncCallback): void;formatPhoneNumber(phoneNumber: string, options: NumberFormatOptions, callback: AsyncCallback): void;formatPhoneNumber(phoneNumber: string, options?: NumberFormatOptions): Promise;|新增| -| +|电话子系统-call|formatPhoneNumber(phoneNumber: string, callback: AsyncCallback): void;formatPhoneNumber(phoneNumber: string, options: NumberFormatOptions, callback: AsyncCallback): void;formatPhoneNumber(phoneNumber: string, options?: NumberFormatOptions): Promise;|新增| -| +|电话子系统-call|formatPhoneNumberToE164(phoneNumber: string, countryCode: string, callback: AsyncCallback): void;formatPhoneNumberToE164(phoneNumber: string, countryCode: string): Promise;|新增| -| +|电话子系统-sms|setDefaultSmsSlotId(slotId: number, callback: AsyncCallback): void;setDefaultSmsSlotId(slotId: number): Promise;|新增| -| +|电话子系统-call|getCallState(callback: AsyncCallback): void;getCallState(): Promise;|新增| -| +|电话子系统-sms|setSmscAddr(slotId: number, smscAddr: string, callback: AsyncCallback): void;setSmscAddr(slotId: number, smscAddr: string): Promise;|新增| -| +|电话子系统-sms|getSmscAddr(slotId: number, callback: AsyncCallback): void;getSmscAddr(slotId: number): Promise;|新增| -| +|电话子系统-sms|addSimMessage(options: SimMessageOptions, callback: AsyncCallback): void;addSimMessage(options: SimMessageOptions): Promise;|新增| -| +|电话子系统-sms|delSimMessage(slotId: number, msgIndex: number, callback: AsyncCallback): void;delSimMessage(slotId: number, msgIndex: number): Promise;|新增| -| +|电话子系统-radio|getISOCountryCodeForNetwork(slotId: number, callback: AsyncCallback): void;getISOCountryCodeForNetwork(slotId: number): Promise;|新增| -| +|电话子系统-sms|updateSimMessage(options: UpdateSimMessageOptions, callback: AsyncCallback): void;updateSimMessage(options: UpdateSimMessageOptions): Promise;|新增| -| +|电话子系统-radio|getISOCountryCodeForNetwork(slotId: number, callback: AsyncCallback): void;getISOCountryCodeForNetwork(slotId: number): Promise;|新增| -| +|电话子系统-sms|getAllSimMessages(slotId: number, callback: AsyncCallback>): void;getAllSimMessages(slotId: number): Promise>;|新增| -| +|电话子系统-call|isInEmergencyCall(callback: AsyncCallback): void;isInEmergencyCall(): Promise;|新增| -| +|电话子系统-sms|setCBConfig(options: CBConfigOptions, callback: AsyncCallback): void;setCBConfig(options: CBConfigOptions): Promise;|新增| -| +|电话子系统-call|answer(callId: number, callback: AsyncCallback): void;answer(callId: number): Promise;|新增| -| +|电话子系统-call|hangup(callId: number, callback: AsyncCallback): void;hangup(callId: number): Promise;|新增| -| +|电话子系统-call|reject(callId: number, callback: AsyncCallback): void;reject(callId: number, options: RejectMessageOptions, callback: AsyncCallback): void;reject(callId: number, options?: RejectMessageOptions): Promise;|新增| -| +|电话子系统-call|holdCall(callId: number, callback: AsyncCallback): void;holdCall(callId: number): Promise;|新增| -| +|电话子系统-call|unHoldCall(callId: number, callback: AsyncCallback): void;unHoldCall(callId: number): Promise;|新增| -| +|电话子系统-call|switchCall(callId: number, callback: AsyncCallback): void;switchCall(callId: number): Promise;|新增| -| +|电话子系统-radio|setNetworkSelectionMode(options: NetworkSelectionModeOptions, callback: AsyncCallback): void;setNetworkSelectionMode(options: NetworkSelectionModeOptions): Promise;|新增| -| +|电话子系统-radio|getNetworkSearchInformation(slotId: number, callback: AsyncCallback): void;getNetworkSearchInformation(slotId: number): Promise;|新增| -| +|电话子系统-radio|getNetworkSelectionMode(slotId: number, callback: AsyncCallback): void;getNetworkSelectionMode(slotId: number): Promise;|新增| -| +|电话子系统-radio|isRadioOn(callback: AsyncCallback): void;isRadioOn(): Promise;|新增| -| +|电话子系统-radio|turnOnRadio(callback: AsyncCallback): void;turnOnRadio(): Promise;|新增| -| +|电话子系统-radio|turnOffRadio(callback: AsyncCallback): void;turnOffRadio(): Promise;|新增| -| +|电话子系统-radio|getSignalInformation(slotId: number, callback: AsyncCallback>): void;getSignalInformation(slotId: number): Promise>;|新增| -| +|电话子系统-radio|getRadioTech(slotId: number, callback: AsyncCallback<{psRadioTech: RadioTechnology, csRadioTech: RadioTechnology}>): void;getRadioTech(slotId: number): Promise<{psRadioTech: RadioTechnology, csRadioTech: RadioTechnology}>;|新增| -| +|电话子系统-radio|getRadioTech(slotId: number, callback: AsyncCallback<{psRadioTech: RadioTechnology, csRadioTech: RadioTechnology}>): void;getRadioTech(slotId: number): Promise<{psRadioTech: RadioTechnology, csRadioTech: RadioTechnology}>;|新增| -| +|电话子系统-radio|getRadioTech(slotId: number, callback: AsyncCallback<{psRadioTech: RadioTechnology, csRadioTech: RadioTechnology}>): void;getRadioTech(slotId: number): Promise<{psRadioTech: RadioTechnology, csRadioTech: RadioTechnology}>;|新增| -| +|数据管理-distributeddata|put(key:string, value:Uint8Array / string / boolean / number, callback: AsyncCallback):void put(key:string, value:Uint8Array / string / boolean / number):Promise|新增| -| +|数据管理-distributeddata|delete(key: string, callback: AsyncCallback): void delete(key: string): Promise|新增| -| +|数据管理-distributeddata|on(event:'dataChange', subType: SubscribeType, observer: Callback): void|新增| -| +|数据管理-distributeddata|get(key:string, callback:AsyncCallback):void get(key:string):Promise|新增| -| +|数据管理-distributeddata|sync(deviceIdList:string[], mode:SyncMode, allowedDelayMs?:number):void|新增| -| +|数据管理-distributeddata|createKVManager(config: KVManagerConfig, callback: AsyncCallback): void;createKVManager(config: KVManagerConfig): Promise;|新增| -| +|数据管理-distributeddata|getKVStore(options: Options, storeId: string): Promise;getKVStore(options: Options, storeId: string, callback: AsyncCallback): void;|新增| -| +|数据管理-distributeddata|on(event:'syncComplete', syncCallback: Callback>):void|新增| -| +|数据管理-rdb|type ValueType = number / string / boolean;|新增| -| +|数据管理-rdb|type ValuesBucket = { [key: string]: ValueType / Uint8Array / null; }|新增| -| +|数据管理-rdb|name: string;|新增| -| +|数据管理-rdb|constructor(name: string)|新增| -| +|数据管理-rdb|equalTo(field: string, value: ValueType): RdbPredicates;|新增| -| +|数据管理-rdb|notEqualTo(field: string, value: ValueType): RdbPredicates;|新增| -| +|数据管理-rdb|beginWrap(): RdbPredicates;|新增| -| +|数据管理-rdb|endWrap(): RdbPredicates;|新增| -| +|数据管理-rdb|function getRdbStore(config: StoreConfig, version: number, callback: AsyncCallback): void;function getRdbStore(config: StoreConfig, version: number): Promise;|新增| -| +|数据管理-rdb|function deleteRdbStore(name: string, callback: AsyncCallback): void;function deleteRdbStore(name: string): Promise;|新增| -| +|数据管理-rdb|insert(name: string, values: ValuesBucket, callback: AsyncCallback): void;insert(name: string, values: ValuesBucket): Promise;|新增| -| +|数据管理-rdb|update(values: ValuesBucket, rdbPredicates: RdbPredicates, callback: AsyncCallback): void;update(values: ValuesBucket, rdbPredicates: RdbPredicates): Promise;|新增| -| +|数据管理-rdb|delete(rdbPredicates: RdbPredicates, callback: AsyncCallback): void;delete(rdbPredicates: RdbPredicates): Promise;|新增| -| +|数据管理-rdb|query(rdbPredicates: RdbPredicates, columns: Array, callback: AsyncCallback): void;query(rdbPredicates: RdbPredicates, columns: Array): Promise;|新增| -| +|数据管理-rdb|executeSql(sql: string, bindArgs: Array, callback: AsyncCallback): void;executeSql(sql: string, bindArgs: Array): Promise;|新增| -| +|数据管理-rdb|like(field: string, value: string): RdbPredicates;|新增| -| +|数据管理-rdb|glob(field: string, value: string): RdbPredicates;|新增| -| +|数据管理-rdb|between(field: string, low: ValueType, high: ValueType): RdbPredicates;|新增| -| +|数据管理-rdb|notBetween(field: string, low: ValueType, high: ValueType): RdbPredicates;|新增| -| +|数据管理-rdb|greaterThan(field: string, value: ValueType): RdbPredicates;|新增| -| +|数据管理-rdb|lessThan(field: string, value: ValueType): RdbPredicates;|新增| -| +|数据管理-rdb|greaterThanOrEqualTo(field: string, value: ValueType): RdbPredicates;|新增| -| +|数据管理-rdb|lessThanOrEqualTo(field: string, value: ValueType): RdbPredicates;|新增| -| +|数据管理-rdb|or(): RdbPredicates;|新增| -| +|数据管理-rdb|and(): RdbPredicates;|新增| -| +|数据管理-rdb|contains(field: string, value: string): RdbPredicates;|新增| -| +|数据管理-rdb|beginsWith(field: string, value: string): RdbPredicates;|新增| -| +|数据管理-rdb|endsWith(field: string, value: string): RdbPredicates;|新增| -| +|数据管理-rdb|isNull(field: string): RdbPredicates;|新增| -| +|数据管理-rdb|isNotNull(field: string): RdbPredicates;|新增| -| +|数据管理-rdb|isEnded: boolean;|新增| -| +|数据管理-rdb|isStarted: boolean;|新增| -| +|数据管理-rdb|isClosed: boolean;|新增| -| +|数据管理-rdb|getColumnIndex(columnName: string): number;|新增| -| +|数据管理-rdb|getColumnName(columnIndex: number): string;|新增| -| +|数据管理-rdb|goTo(offset: number): boolean;|新增| -| +|数据管理-rdb|goToRow(position: number): boolean;|新增| -| +|数据管理-rdb|goToFirstRow(): boolean;|新增| -| +|数据管理-rdb|goToLastRow(): boolean;|新增| -| +|数据管理-rdb|goToNextRow(): boolean;|新增| -| +|数据管理-rdb|goToPreviousRow(): boolean;|新增| -| +|数据管理-rdb|getBlob(columnIndex: number): Uint8Array;|新增| -| +|数据管理-rdb|getString(columnIndex: number): string;|新增| -| +|数据管理-rdb|getLong(columnIndex: number): number;|新增| -| +|数据管理-rdb|getDouble(columnIndex: number): number;|新增| -| +|数据管理-dataAbility|orderByDesc(field: string): DataAbilityPredicates;|新增| -| +|数据管理-dataAbility|distinct(): DataAbilityPredicates;|新增| -| +|数据管理-dataAbility|limitAs(value: number): DataAbilityPredicates;|新增| -| +|数据管理-dataAbility|offsetAs(rowOffset: number): DataAbilityPredicates;|新增| -| +|数据管理-dataAbility|groupBy(fields: Array): DataAbilityPredicates;|新增| -| +|数据管理-dataAbility|indexedBy(field: string): DataAbilityPredicates;|新增| -| +|数据管理-dataAbility|in(field: string, value: Array): DataAbilityPredicates;|新增| -| +|数据管理-dataAbility|notIn(field: string, value: Array): DataAbilityPredicates;|新增| -| +|数据管理-dataAbility|glob(field: string, value: string): DataAbilityPredicates;|新增| -| +|数据管理-dataAbility|between(field: string, low: ValueType, high: ValueType): DataAbilityPredicates;|新增| -| +|数据管理-dataAbility|notBetween(field: string, low: ValueType, high: ValueType): DataAbilityPredicates;|新增| -| +|数据管理-dataAbility|greaterThan(field: string, value: ValueType): DataAbilityPredicates;|新增| -| +|数据管理-dataAbility|lessThan(field: string, value: ValueType): DataAbilityPredicates;|新增| -| +|数据管理-dataAbility|greaterThanOrEqualTo(field: string, value: ValueType): DataAbilityPredicates;|新增| -| +|数据管理-dataAbility|lessThanOrEqualTo(field: string, value: ValueType): DataAbilityPredicates;|新增| -| +|数据管理-dataAbility|orderByAsc(field: string): DataAbilityPredicates;|新增| -| +|数据管理-rdb|isColumnNull(columnIndex: number): boolean;|新增| -| +|数据管理-rdb|close(): void;|新增| -| +|数据管理-dataAbility|function createRdbPredicates(name: string, dataAbilityPredicates: DataAbilityPredicates): rdb.RdbPredicates;|新增| -| +|数据管理-dataAbility|equalTo(field: string, value: ValueType): DataAbilityPredicates;|新增| -| +|数据管理-dataAbility|notEqualTo(field: string, value: ValueType): DataAbilityPredicates;|新增| -| +|数据管理-dataAbility|beginWrap():DataAbilityPredicates;|新增| -| +|数据管理-dataAbility|endWrap(): DataAbilityPredicates;|新增| -| +|数据管理-rdb|orderByAsc(field: string): RdbPredicates;|新增| -| +|数据管理-rdb|orderByDesc(field: string): RdbPredicates;|新增| -| +|数据管理-rdb|distinct(): RdbPredicates;|新增| -| +|数据管理-rdb|limitAs(value: number): RdbPredicates;|新增| -| +|数据管理-rdb|offsetAs(rowOffset: number): RdbPredicates;|新增| -| +|数据管理-rdb|groupBy(fields: Array): RdbPredicates;|新增| -| +|数据管理-rdb|indexedBy(field: string): RdbPredicates;|新增| -| +|数据管理-dataAbility|or(): DataAbilityPredicates;|新增| -| +|数据管理-dataAbility|and(): DataAbilityPredicates;|新增| -| +|数据管理-dataAbility|contains(field: string, value: string): DataAbilityPredicates;|新增| -| +|数据管理-dataAbility|beginsWith(field: string, value: string): DataAbilityPredicates;|新增| -| +|数据管理-dataAbility|endsWith(field: string, value: string): DataAbilityPredicates;|新增| -| +|数据管理-dataAbility|isNull(field: string): DataAbilityPredicates;|新增| -| +|数据管理-dataAbility|isNotNull(field: string): DataAbilityPredicates;|新增| -| +|数据管理-dataAbility|like(field: string, value: string): DataAbilityPredicates;|新增| -| +|数据管理-rdb|in(field: string, value: Array): RdbPredicates;|新增| -| +|数据管理-rdb|notIn(field: string, value: Array): RdbPredicates;|新增| -| +|数据管理-rdb|columnNames: Array;|新增| -| +|数据管理-rdb|columnCount: number;|新增| -| +|数据管理-rdb|rowCount: number;|新增| -| +|数据管理-rdb|rowIndex: number;|新增| -| +|数据管理-rdb|isAtFirstRow: boolean;|新增| -| +|数据管理-rdb|isAtLastRow: boolean;|新增| -| +|事件通知-notification|title: string;|新增| -| +|事件通知-notification|sound?: string;|新增| -| +|事件通知-notification|text: string;|新增| -| +|事件通知-notification|vibrationValues?: Array;|新增| -| +|事件通知-wantAgent|want?: Want;|新增| -| +|事件通知-notification|vibrationEnabled?: boolean;|新增| -| +|事件通知-notification|badgeFlag?: boolean;|新增| -| +|事件通知-notification|type: notification.SlotType;|新增| -| +|事件通知-wantAgent|code: number;|新增| -| +|事件通知-notification|contentType: ContentType;|新增| -| +|事件通知-notification|picture: image.PixelMap;|新增| -| +|事件通知-notification|briefText: string;|新增| -| +|事件通知-notification|briefText: string;|新增| -| +|事件通知-notification|briefText: string;|新增| -| +|事件通知-notification|bypassDnd?: boolean;|新增| -| +|事件通知-notification|additionalText?: string;|新增| -| +|事件通知-wantagent|function cancel(info: WantAgentInfo, callback: AsyncCallback): void;|新增| -| +|事件通知-wantAgent|enum OperationType|新增| -| +|事件通知-wantAgent|enum WantAgentFlags|新增| -| +|事件通知-wantAgent|permission?: string;|新增| -| +|事件通知-notification|picture?: NotificationPictureContent;|新增| -| +|事件通知-notification|normal?: NotificationBasicContent;|新增| -| +|事件通知-notification|expandedTitle: string;|新增| -| +|事件通知-notification|expandedTitle: string;|新增| -| +|事件通知-wantAgent|function trigger(info: WantAgentInfo, triggerInfo: TriggerInfo, callback: AsyncCallback): void;|新增| -| +|事件通知-wantAgent|extraInfo?: {[key: string]: any};|新增| -| +|事件通知-notification|multiLine?: NotificationMultiLineContent;|新增| -| +|事件通知-notification|level?: notification.SlotLevel;|新增| -| +|事件通知-notification|lightColor?: number;|新增| -| +|事件通知-notification|lightEnabled?: boolean;|新增| -| +|事件通知-notification|lines: Array;|新增| -| +|事件通知-notification|lockscreenVisibility?: number;|新增| -| +|事件通知-notification|longText: string;|新增| -| +|事件通知-wantAgent|function getBundleName(info: WantAgentInfo, callback: AsyncCallback): void;|新增| -| +|事件通知-notification|longText?: NotificationLongTextContent;|新增| -| +|事件通知-notification|longTitle: string;|新增| -| +|事件通知-wantAgent|function judgeEquality(info: WantAgentInfo, info2: WantAgentInfo, callback: AsyncCallback): void;|新增| -| +|事件通知-wantAgent|function getUid(info: WantAgentInfo, callback: AsyncCallback): void;|新增| -| +|事件通知-commonEvent|COMMON_EVENT_IVI_TEMPERATURE_ABNORMAL = common.event.IVI_TEMPERATURE_ABNORMAL,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_IVI_VOLTAGE_RECOVERY = common.event.IVI_VOLTAGE_RECOVERY,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_IVI_TEMPERATURE_RECOVERY = common.event.IVI_TEMPERATURE_RECOVERY,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_IVI_ACTIVE = common.event.IVI_ACTIVE,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_USB_DEVICE_ATTACHED = usual.event.hardware.usb.action.USB_DEVICE_ATTACHED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_USB_DEVICE_DETACHED = usual.event.hardware.usb.action.USB_DEVICE_DETACHED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_IVI_PAUSE = common.event.IVI_PAUSE,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_IVI_STANDBY = common.event.IVI_STANDBY,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_IVI_LASTMODE_SAVE = common.event.IVI_LASTMODE_SAVE,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_IVI_VOLTAGE_ABNORMAL = common.event.IVI_VOLTAGE_ABNORMAL,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_IVI_HIGH_TEMPERATURE = common.event.IVI_HIGH_TEMPERATURE,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_IVI_EXTREME_TEMPERATURE = common.event.IVI_EXTREME_TEMPERATURE,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_DISK_UNMOUNTABLE = usual.event.data.DISK_UNMOUNTABLE,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_DISK_EJECT = usual.event.data.DISK_EJECT,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_VISIBLE_ACCOUNTS_UPDATED = usual.event.data.VISIBLE_ACCOUNTS_UPDATED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_ACCOUNT_DELETED = usual.event.data.ACCOUNT_DELETED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_FOUNDATION_READY = common.event.FOUNDATION_READY,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_AIRPLANE_MODE_CHANGED = usual.event.AIRPLANE_MODE|新增| -| +|事件通知-commonEvent|COMMON_EVENT_USB_ACCESSORY_ATTACHED = usual.event.hardware.usb.action.USB_ACCESSORY_ATTACHED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_USB_ACCESSORY_DETACHED = usual.event.hardware.usb.action.USB_ACCESSORY_DETACHED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_DISK_REMOVED = usual.event.data.DISK_REMOVED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_DISK_UNMOUNTED = usual.event.data.DISK_UNMOUNTED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_DISK_MOUNTED = usual.event.data.DISK_MOUNTED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_DISK_BAD_REMOVAL = usual.event.data.DISK_BAD_REMOVAL,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_NFC_ACTION_RF_FIELD_OFF_DETECTED = usual.event.nfc.action.RF_FIELD_OFF_DETECTED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_DISCHARGING = usual.event.DISCHARGING,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_CHARGING = usual.event.CHARGING,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_DEVICE_IDLE_MODE_CHANGED = usual.event.DEVICE_IDLE_MODE_CHANGED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_POWER_SAVE_MODE_CHANGED = usual.event.POWER_SAVE_MODE_CHANGED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_USER_ADDED = usual.event.USER_ADDED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_USER_REMOVED = usual.event.USER_REMOVED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_ABILITY_ADDED = common.event.ABILITY_ADDED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_ABILITY_REMOVED = common.event.ABILITY_REMOVED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_ABILITY_UPDATED = common.event.ABILITY_UPDATED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_LOCATION_MODE_STATE_CHANGED = usual.event.location.MODE_STATE_CHANGED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_IVI_SLEEP = common.event.IVI_SLEEP,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_HOST_NAME_UPDATE = usual.event.bluetooth.host.NAME_UPDATE,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_A2DPSINK_CONNECT_STATE_UPDATE = usual.event.bluetooth.a2dpsink.CONNECT_STATE_UPDATE,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_A2DPSINK_PLAYING_STATE_UPDATE = usual.event.bluetooth.a2dpsink.PLAYING_STATE_UPDATE,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_A2DPSINK_AUDIO_STATE_UPDATE = usual.event.bluetooth.a2dpsink.AUDIO_STATE_UPDATE,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_NFC_ACTION_ADAPTER_STATE_CHANGED = usual.event.nfc.action.ADAPTER_STATE_CHANGED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_NFC_ACTION_RF_FIELD_ON_DETECTED = usual.event.nfc.action.RF_FIELD_ON_DETECTED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_HOST_REQ_ENABLE = usual.event.bluetooth.host.REQ_ENABLE,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_HOST_REQ_DISABLE = usual.event.bluetooth.host.REQ_DISABLE,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_HOST_SCAN_MODE_UPDATE = usual.event.bluetooth.host.SCAN_MODE_UPDATE,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_HOST_DISCOVERY_STARTED = usual.event.bluetooth.host.DISCOVERY_STARTED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_HOST_DISCOVERY_FINISHED = usual.event.bluetooth.host.DISCOVERY_FINISHED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_WIFI_P2P_CONN_STATE = usual.event.wifi.p2p.CONN_STATE_CHANGE,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_WIFI_P2P_STATE_CHANGED = usual.event.wifi.p2p.STATE_CHANGE,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_WIFI_P2P_PEERS_STATE_CHANGED = usual.event.wifi.p2p.DEVICES_CHANGE,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_WIFI_P2P_CURRENT_DEVICE_STATE_CHANGED = usual.event.wifi.p2p.CURRENT_DEVICE_CHANGE,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_WIFI_P2P_GROUP_STATE_CHANGED = usual.event.wifi.p2p.GROUP_STATE_CHANGED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_CONNECT_STATE_UPDATE = usual.event.bluetooth.handsfree.ag.CONNECT_STATE_UPDATE,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_CURRENT_DEVICE_UPDATE = usual.event.bluetooth.handsfree.ag.CURRENT_DEVICE_UPDATE,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_AUDIO_STATE_UPDATE = usual.event.bluetooth.handsfree.ag.AUDIO_STATE_UPDATE,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CONNECT_STATE_UPDATE = usual.event.bluetooth.a2dpsource.CONNECT_STATE_UPDATE,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CURRENT_DEVICE_UPDATE = usual.event.bluetooth.a2dpsource.CURRENT_DEVICE_UPDATE,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_WIFI_RSSI_VALUE = usual.event.wifi.RSSI_VALUE,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_WIFI_CONN_STATE = usual.event.wifi.CONN_STATE,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_WIFI_HOTSPOT_STATE = usual.event.wifi.HOTSPOT_STATE,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_WIFI_AP_STA_JOIN = usual.event.wifi.WIFI_HS_STA_JOIN,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_WIFI_AP_STA_LEAVE = usual.event.wifi.WIFI_HS_STA_LEAVE,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_WIFI_MPLINK_STATE_CHANGE = usual.event.wifi.mplink.STATE_CHANGE,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_HWID_LOGOUT = common.event.HWID_LOGOUT,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_HWID_TOKEN_INVALID = common.event.HWID_TOKEN_INVALID,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_HWID_LOGOFF = common.event.HWID_LOGOFF,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_WIFI_POWER_STATE = usual.event.wifi.POWER_STATE,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_WIFI_SCAN_FINISHED = usual.event.wifi.SCAN_FINISHED,|新增| -| +|事件通知-commonEvent|clearAbortCommonEvent(): Promise;|新增| -| +|事件通知-commonEvent|bundleName?: string;|新增| -| +|事件通知-commonEvent|code?: number;|新增| -| +|事件通知-commonEvent|data?: string;|新增| -| +|事件通知-commonEvent|subscriberPermissions?: Array;|新增| -| +|事件通知-commonEvent|isOrdered?: boolean;|新增| -| +|事件通知-commonEvent|isSticky?: boolean;|新增| -| +|事件通知-commonEvent|abortCommonEvent(callback: AsyncCallback): void;|新增| -| +|事件通知-commonEvent|abortCommonEvent(): Promise;|新增| -| +|事件通知-commonEvent|function createSubscriber(subscribeInfo: CommonEventSubscribeInfo): Promise;|新增| -| +|事件通知-commonEvent|function createSubscriber(subscribeInfo: CommonEventSubscribeInfo, callback: AsyncCallback): void;|新增| -| +|事件通知-commonEvent|function subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback): void;|新增| -| +|事件通知-commonEvent|function publish(event: string, options: CommonEventPublishData, callback: AsyncCallback): void;|新增| -| +|事件通知-commonEvent|isOrderedCommonEvent(callback: AsyncCallback): void;|新增| -| +|事件通知-commonEvent|isOrderedCommonEvent(): Promise;|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BOOT_COMPLETED = usual.event.BOOT_COMPLETED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_LOCKED_BOOT_COMPLETED = usual.event.LOCKED_BOOT_COMPLETED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_SHUTDOWN = usual.event.SHUTDOWN,|新增| -| +|事件通知-commonEvent|isStickyCommonEvent(): Promise;|新增| -| +|事件通知-commonEvent|getData(callback: AsyncCallback): void;|新增| -| +|事件通知-commonEvent|getData(): Promise;|新增| -| +|事件通知-commonEvent|getSubscribeInfo(callback: AsyncCallback): void;|新增| -| +|事件通知-commonEvent|getSubscribeInfo(): Promise;|新增| -| +|事件通知-commonEvent|function publish(event: string, callback: AsyncCallback): void;|新增| -| +|事件通知-commonEvent|event: string|新增| -| +|事件通知-commonEvent|bundleName?: string;|新增| -| +|事件通知-commonEvent|code?: number;|新增| -| +|事件通知-commonEvent|data?: string;|新增| -| +|事件通知-commonEvent|setCode(code: number, callback: AsyncCallback): void;|新增| -| +|事件通知-commonEvent|COMMON_EVENT_DRIVE_MODE = common.event.DRIVE_MODE,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_HOME_MODE = common.event.HOME_MODE,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_OFFICE_MODE = common.event.OFFICE_MODE,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_USER_STARTED = usual.event.USER_STARTED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_USER_BACKGROUND = usual.event.USER_BACKGROUND,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_USER_FOREGROUND = usual.event.USER_FOREGROUND,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_USER_SWITCHED = usual.event.USER_SWITCHED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_USER_STARTING = usual.event.USER_STARTING,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_USER_UNLOCKED = usual.event.USER_UNLOCKED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_USER_STOPPING = usual.event.USER_STOPPING,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_USER_STOPPED = usual.event.USER_STOPPED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_HWID_LOGIN = common.event.HWID_LOGIN,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_PACKAGE_VERIFIED = usual.event.PACKAGE_VERIFIED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_EXTERNAL_APPLICATIONS_AVAILABLE = usual.event.EXTERNAL_APPLICATIONS_AVAILABLE,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_EXTERNAL_APPLICATIONS_UNAVAILABLE = usual.event.EXTERNAL_APPLICATIONS_UNAVAILABLE,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_CONFIGURATION_CHANGED = usual.event.CONFIGURATION_CHANGED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_LOCALE_CHANGED = usual.event.LOCALE_CHANGED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_MANAGE_PACKAGE_STORAGE = usual.event.MANAGE_PACKAGE_STORAGE,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_PACKAGES_UNSUSPENDED = usual.event.PACKAGES_UNSUSPENDED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_MY_PACKAGE_SUSPENDED = usual.event.MY_PACKAGE_SUSPENDED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_MY_PACKAGE_UNSUSPENDED = usual.event.MY_PACKAGE_UNSUSPENDED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_UID_REMOVED = usual.event.UID_REMOVED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_PACKAGE_FIRST_LAUNCH = usual.event.PACKAGE_FIRST_LAUNCH,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_PACKAGE_NEEDS_VERIFICATION = usual.event.PACKAGE_NEEDS_VERIFICATION,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_SCREEN_OFF = usual.event.SCREEN_OFF,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_SCREEN_ON = usual.event.SCREEN_ON,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_USER_PRESENT = usual.event.USER_PRESENT,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_TIME_TICK = usual.event.TIME_TICK,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_TIME_CHANGED = usual.event.TIME_CHANGED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_DATE_CHANGED = usual.event.DATE_CHANGED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BATTERY_CHANGED = usual.event.BATTERY_CHANGED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BATTERY_LOW = usual.event.BATTERY_LOW,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BATTERY_OKAY = usual.event.BATTERY_OKAY,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_POWER_CONNECTED = usual.event.POWER_CONNECTED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_POWER_DISCONNECTED = usual.event.POWER_DISCONNECTED,|新增| -| +|事件通知-commonEvent|function unsubscribe(subscriber: CommonEventSubscriber, callback?: AsyncCallback): void;|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_ACL_CONNECTED = usual.event.bluetooth.remotedevice.ACL_CONNECTED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_ACL_DISCONNECTED = usual.event.bluetooth.remotedevice.ACL_DISCONNECTED,|新增| -| +|事件通知-commonEvent|getAbortCommonEvent(callback: AsyncCallback): void;|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_NAME_UPDATE = usual.event.bluetooth.remotedevice.NAME_UPDATE,|新增| -| +|事件通知-commonEvent|getAbortCommonEvent(): Promise;|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_CONNECT_STATE_UPDATE = usual.event.bluetooth.handsfreeunit.CONNECT_STATE_UPDATE,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIR_STATE = usual.event.bluetooth.remotedevice.PAIR_STATE,|新增| -| +|事件通知-commonEvent|getCode(callback: AsyncCallback): void;|新增| -| +|事件通知-commonEvent|setCode(code: number): Promise;|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_AUDIO_STATE_UPDATE = usual.event.bluetooth.handsfreeunit.AUDIO_STATE_UPDATE,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_BATTERY_VALUE_UPDATE = usual.event.bluetooth.remotedevice.BATTERY_VALUE_UPDATE,|新增| -| +|事件通知-commonEvent|getCode(): Promise;|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_AG_COMMON_EVENT = usual.event.bluetooth.handsfreeunit.AG_COMMON_EVENT,|新增| -| +|事件通知-commonEvent|setCodeAndData(code: number, data: string, callback: AsyncCallback): void;|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_SDP_RESULT = usual.event.bluetooth.remotedevice.SDP_RESULT,|新增| -| +|事件通知-commonEvent|isStickyCommonEvent(callback: AsyncCallback): void;|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_AG_CALL_STATE_UPDATE = usual.event.bluetooth.handsfreeunit.AG_CALL_STATE_UPDATE,|新增| -| +|事件通知-commonEvent|setCodeAndData(code: number, data: string): Promise;|新增| -| +|事件通知-commonEvent|events: Array;|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_HOST_STATE_UPDATE = usual.event.bluetooth.host.STATE_UPDATE,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_A2DPSOURCE_PLAYING_STATE_UPDATE = usual.event.bluetooth.a2dpsource.PLAYING_STATE_UPDATE,|新增| -| +|事件通知-commonEvent|setData(data: string, callback: AsyncCallback): void;|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_A2DPSOURCE_AVRCP_CONNECT_STATE_UPDATE = usual.event.bluetooth.a2dpsource.AVRCP_CONNECT_STATE_UPDATE,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_HOST_REQ_DISCOVERABLE = usual.event.bluetooth.host.REQ_DISCOVERABLE,|新增| -| +|事件通知-commonEvent|publisherPermission?: string;|新增| -| +|事件通知-commonEvent|setData(data: string): Promise;|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_UUID_VALUE = usual.event.bluetooth.remotedevice.UUID_VALUE,|新增| -| +|事件通知-commonEvent|publisherDeviceId?: string;|新增| -| +|事件通知-commonEvent|clearAbortCommonEvent(callback: AsyncCallback): void;|新增| -| +|事件通知-commonEvent|userId?: number;|新增| -| +|事件通知-commonEvent|COMMON_EVENT_TIMEZONE_CHANGED = usual.event.TIMEZONE_CHANGED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIRING_REQ = usual.event.bluetooth.remotedevice.PAIRING_REQ,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_DISCOVERED = usual.event.bluetooth.remotedevice.DISCOVERED,|新增| -| +|事件通知-commonEvent|priority?: number;|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BUNDLE_REMOVED = usual.event.BUNDLE_REMOVED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CLASS_VALUE_UPDATE = usual.event.bluetooth.remotedevice.CLASS_VALUE_UPDATE,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIRING_CANCEL = usual.event.bluetooth.remotedevice.PAIRING_CANCEL,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_CLOSE_SYSTEM_DIALOGS = usual.event.CLOSE_SYSTEM_DIALOGS,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_PACKAGE_ADDED = usual.event.PACKAGE_ADDED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CONNECT_REQ = usual.event.bluetooth.remotedevice.CONNECT_REQ,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_PACKAGE_FULLY_REMOVED = usual.event.PACKAGE_FULLY_REMOVED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_PACKAGE_REPLACED = usual.event.PACKAGE_REPLACED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CONNECT_REPLY = usual.event.bluetooth.remotedevice.CONNECT_REPLY,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_MY_PACKAGE_REPLACED = usual.event.MY_PACKAGE_REPLACED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_PACKAGE_CHANGED = usual.event.PACKAGE_CHANGED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CONNECT_CANCEL = usual.event.bluetooth.remotedevice.CONNECT_CANCEL,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_PACKAGE_REMOVED = usual.event.PACKAGE_REMOVED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_PACKAGE_RESTARTED = usual.event.PACKAGE_RESTARTED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_PACKAGE_DATA_CLEARED = usual.event.PACKAGE_DATA_CLEARED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_PACKAGES_SUSPENDED = usual.event.PACKAGES_SUSPENDED,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CODEC_VALUE_UPDATE = usual.event.bluetooth.a2dpsource.CODEC_VALUE_UPDATE,|新增| -| +|事件通知-commonEvent|COMMON_EVENT_WIFI_P2P_PEERS_DISCOVERY_STATE_CHANGED = usual.event.wifi.p2p.PEER_DISCOVERY_STATE_CHANGE,|新增| -| +|事件通知-notification|LEVEL_NONE = 0,|新增| -| +|事件通知-notification|LEVEL_MIN = 1,|新增| -| +|事件通知-notification|LEVEL_LOW = 2,|新增| -| +|事件通知-notification|LEVEL_DEFAULT = 3,|新增| -| +|事件通知-notification|label?: string;|新增| -| +|事件通知-notification|bundle: string;|新增| -| +|事件通知-notification|uid?: number;|新增| -| +|事件通知-notification|NOTIFICATION_CONTENT_MULTILINE,|新增| -| +|事件通知-notification|UNKNOWN_TYPE = 0,|新增| -| +|事件通知-notification|SOCIAL_COMMUNICATION = 1,|新增| -| +|事件通知-notification|LEVEL_HIGH = 4,|新增| -| +|事件通知-notification|NOTIFICATION_CONTENT_BASIC_TEXT,|新增| -| +|事件通知-notification|NOTIFICATION_CONTENT_LONG_TEXT,|新增| -| +|事件通知-notification|NOTIFICATION_CONTENT_PICTURE,|新增| -| +|事件通知-notification|isFloatingIcon?: boolean;|新增| -| +|事件通知-notification|label?: string;|新增| -| +|事件通知-notification|badgeIconStyle?: number;|新增| -| +|事件通知-notification|showDeliveryTime?: boolean;|新增| -| +|事件通知-notification|isAlertOnce?: boolean;|新增| -| +|事件通知-notification|function getActiveNotifications(callback: AsyncCallback>): void;|新增| -| +|事件通知-notification|isStopwatch?: boolean;|新增| -| +|事件通知-notification|isCountDown?: boolean;|新增| -| +|事件通知-notification|function getActiveNotifications(): Promise>;|新增| -| +|事件通知-notification|function getActiveNotificationCount(callback: AsyncCallback): void;|新增| -| +|事件通知-notification|readonly creatorUid?: number;|新增| -| +|事件通知-notification|function getActiveNotificationCount(): Promise;|新增| -| +|事件通知-notification|readonly creatorPid?: number;|新增| -| +|事件通知-notification|function cancel(id: number, label?: string): Promise;|新增| -| +|事件通知-notification|classification?: string;|新增| -| +|事件通知-notification|readonly hashCode?: string;|新增| -| +|事件通知-notification|function cancelAll(callback: AsyncCallback): void;|新增| -| +|事件通知-notification|actionButtons?: Array;|新增| -| +|事件通知-notification|function cancelAll(): Promise;|新增| -| +|事件通知-notification|smallIcon?: image.PixelMap;|新增| -| +|事件通知-notification|isUnremovable?: boolean;|新增| -| +|事件通知-notification|largeIcon?: image.PixelMap;|新增| -| +|事件通知-notification|deliveryTime?: number;|新增| -| +|事件通知-notification|readonly creatorBundleName?: string;|新增| -| +|事件通知-notification|tapDismissed?: boolean;|新增| -| +|事件通知-notification|function publish(request: NotificationRequest): Promise;|新增| -| +|事件通知-notification|autoDeletedTime?: number;|新增| -| +|事件通知-notification|function cancel(id: number, callback: AsyncCallback): void;|新增| -| +|事件通知-notification|content: NotificationContent;|新增| -| +|事件通知-notification|wantAgent?: WantAgentInfo;|新增| -| +|事件通知-notification|function cancel(id: number, label: string, callback: AsyncCallback): void;|新增| -| +|事件通知-notification|function getSlot(slotType: SlotType, callback: AsyncCallback): void;|新增| -| +|事件通知-notification|extraInfo?: {[key: string]: any};|新增| -| +|事件通知-notification|function getSlot(slotType: SlotType): Promise;|新增| -| +|事件通知-notification|SERVICE_INFORMATION = 2,|新增| -| +|事件通知-notification|color?: number;|新增| -| +|事件通知-notification|id?: number;|新增| -| +|事件通知-notification|function getSlots(callback: AsyncCallback>): void;|新增| -| +|事件通知-notification|CONTENT_INFORMATION = 3,|新增| -| +|事件通知-notification|slotType?: notification.SlotType;|新增| -| +|事件通知-notification|colorEnabled?: boolean;|新增| -| +|事件通知-notification|OTHER_TYPES = 0xFFFF,|新增| -| +|事件通知-notification|isOngoing?: boolean;|新增| -| +|事件通知-notification|function addSlot(type: SlotType, callback: AsyncCallback): void;|新增| -| +|事件通知-notification|id: number;|新增| -| +|事件通知-notification|function addSlot(type: SlotType): Promise;|新增| -| +|事件通知-notification|desc?: string;|新增| -| +|事件通知-notification|function publish(request: NotificationRequest, callback: AsyncCallback): void;|新增| -| +|事件通知-notification|function removeAllSlots(callback: AsyncCallback): void;|新增| -| +|事件通知-notification|function removeAllSlots(): Promise;|新增| -| +|事件通知-notification|function getSlots(): Promise>;|新增| -| +|事件通知-notification|function removeSlot(slotType: SlotType, callback: AsyncCallback): void;|新增| -| +|事件通知-notification|function removeSlot(slotType: SlotType): Promise;|新增| -| +|全球化-resourceManager|getString(resId: number, callback: AsyncCallback);getString(resId: number): Promise;|新增| -| +|全球化-resourceManager|getStringArray(resId: number, callback: AsyncCallback>);getStringArray(resId: number): Promise>;|新增| -| +|全球化-resourceManager|getConfiguration(callback: AsyncCallback);getConfiguration(): Promise;|新增| -| +|全球化-resourceManager|getDeviceCapability(callback: AsyncCallback);getDeviceCapability(): Promise;|新增| -| +|全球化-resourceManager|getMedia(resId: number, callback: AsyncCallback);getMedia(resId: number): Promise;getMediaBase64(resId: number, callback: AsyncCallback);getMediaBase64(resId: number): Promise;|新增| -| +|全球化-resourceManager|"getPluralString(resId: number, num: number, callback: AsyncCallback);getPluralString(resId: number, num: number): Promise;"|新增| -| +|全球化-resourceManager|DeviceCapability|新增| -| +|全球化-resourceManager|"getMediaBase64(resId: number, callback: AsyncCallback);getMediaBase64(resId: number): Promise;"|新增| -| +|全球化-resourceManager|"getResourceManager(callback: AsyncCallback);getResourceManager(bundleName: string, callback: AsyncCallback);getResourceManager(): Promise;getResourceManager(bundleName: string): Promise;"|新增| -| +|全球化-resourceManager|DeviceType|新增| -| +|全球化-resourceManager|Direction|新增| -| +|全球化-resourceManager|Configuration|新增| -| +|全球化-resourceManager|ScreenDensity|新增| -| +|全球化-resourceManager|deviceType|新增| -| +|全球化-resourceManager|locale|新增| -| +|全球化-resourceManager|direction|新增| -| +|全球化-resourceManager|screenDensity|新增| -| +|电源服务-batteryInfo|batteryInfo:const batterySOC: number;|新增| -| +|电源服务-batteryInfo|batteryInfo:const technology: string;|新增| -| +|电源服务-batteryInfo|batteryInfo:const isBatteryPresent: boolean;|新增| -| +|电源服务-batteryInfo|batteryInfo:const batteryTemperature: number;|新增| -| +|电源服务-batteryInfo|batteryInfo:const pluggedType: BatteryPluggedType;|新增| -| +|电源服务-batteryInfo|batteryInfo:const chargingStatus: BatteryChargeState;|新增| -| +|电源服务-batteryInfo|batteryInfo:const healthStatus: BatteryHealthState;|新增| -| +|电源服务-batteryInfo|batteryInfo:const voltage: number;|新增| -| +|电源服务-batteryInfo|BatteryChargeState:NONE|新增| -| +|电源服务-batteryInfo|BatteryChargeState:DISABLE|新增| -| +|电源服务-batteryInfo|BatteryChargeState:ENABLE,|新增| -| +|电源服务-batteryInfo|BatteryChargeState:FULL|新增| -| +|电源服务-batteryInfo|BatteryHealthState:COLD|新增| -| +|电源服务-batteryInfo|BatteryHealthState:OVERHEAT|新增| -| +|电源服务-batteryInfo|BatteryHealthState:OVERVOLTAGE|新增| -| +|电源服务-batteryInfo|BatteryHealthState:DEAD|新增| -| +|电源服务-batteryInfo|BatteryHealthState:UNKNOWN|新增| -| +|电源服务-batteryInfo|BatteryHealthState:GOOD|新增| -| +|电源服务-batteryInfo|BatteryPluggedType:WIRELESS|新增| -| +|电源服务-batteryInfo|BatteryPluggedType:NONE|新增| -| +|电源服务-batteryInfo|BatteryPluggedType:AC|新增| -| +|电源服务-batteryInfo|BatteryPluggedType:USB|新增| -| +|电源服务-runningLock|RunningLock:unlock()|新增| -| +|电源服务-runningLock|runningLock:isRunningLockTypeSupported(type: RunningLockType, callback: AsyncCallback): void;|新增| -| +|电源服务-runningLock|runningLock:createRunningLock(name: string, type: runningLockType): RunningLock|新增| -| +|电源服务-runningLock|RunningLock:lock(timeout: number)|新增| -| +|电源服务-runningLock|RunningLock:isUsed(): boolean|新增| -| +|电源服务-runninglock|RunningLockType:BACKGROUND|新增| -| +|电源服务-runninglock|RunningLockType:PROXIMITY_SCREEN_CONTROL|新增| -| +|电源服务-power|power:rebootDevice(reason ?: string)|新增| -| +|电源服务-power|power:isScreenOn(callback: AsyncCallback): void;|新增| -| diff --git a/website/docs/_posts/zh-cn/application-dev/Readme-CN.md b/website/docs/_posts/zh-cn/application-dev/Readme-CN.md deleted file mode 100644 index a1a390750637a461097bc4afc0861aff9cdb0f68..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/Readme-CN.md +++ /dev/null @@ -1,33 +0,0 @@ ---- -title: Readme-CN -permalink: /pages/extra/31858c/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 应用开发 - -- [应用开发导读](/pages/extra/e59705/) -- [DevEco Studio(OpenHarmony)使用指南](/pages/extra/d114c8/) -- [包结构说明](/pages/010c03) -- [快速入门](/pages/extra/330eee/) -- [Ability框架](/pages/extra/f24f79/) -- 方舟开发框架(ArkUI) - - [基于JS扩展的类Web开发范式](/pages/extra/cdf053/) - - [基于TS扩展的声明式开发范式](/pages/extra/da8c59/) -- [后台代理提醒](/pages/extra/dff9d1/) -- [后台任务管理](/pages/extra/cc57fa/) -- [媒体](/pages/extra/504ad4/) -- [安全](/pages/extra/85ba77/) -- [IPC与RPC通信](/pages/extra/c25112/) -- [数据管理](/pages/extra/ebcb6a/) -- [USB服务](/pages/extra/6eccf9/) -- [DFX](/pages/extra/0b29a3/) -- [开发参考](/pages/extra/23166e/) - diff --git a/website/docs/_posts/zh-cn/application-dev/ability/Readme-CN.md b/website/docs/_posts/zh-cn/application-dev/ability/Readme-CN.md deleted file mode 100644 index bca86db9b08b039869319252b5c4e0e5d318b7f0..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/ability/Readme-CN.md +++ /dev/null @@ -1,21 +0,0 @@ ---- -title: Readme-CN -permalink: /pages/extra/f24f79/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# Ability框架 - -* [PageAbility开发说明](/pages/extra/c12bc9/) -* [ServiceAbility开发说明](/pages/extra/9644e5/) -* [基于Native的Data Ability创建与访问](/pages/extra/094a0f/) -* [CommonEvent开发指南](/pages/extra/51cfde/) -* [Notification开发指南](/pages/extra/fb46d5/) - diff --git a/website/docs/_posts/zh-cn/application-dev/ability/common-event.md b/website/docs/_posts/zh-cn/application-dev/ability/common-event.md deleted file mode 100644 index 47d44ca4b65e89714b6cb12cba6cdc76a58e0bb3..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/ability/common-event.md +++ /dev/null @@ -1,538 +0,0 @@ ---- -title: common-event -permalink: /pages/extra/51cfde/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# CommonEvent开发指南 - -#### 基本概念 - -OpenHarmony通过CES(Common Event Service,公共事件服务)为应用程序提供订阅、发布、退订公共事件的能力。 - -公共事件可分为系统公共事件和自定义公共事件。 - -- 系统公共事件:系统将收集到的事件信息,根据系统策略发送给订阅该事件的用户程序。 例如:系统关键服务发布的系统事件(例如:hap安装,更新,卸载等)。 - -- 自定义公共事件:应用自定义一些公共事件用来实现跨应用的事件通信能力。 - -每个应用都可以按需订阅公共事件,订阅成功且公共事件发布,系统会把其发送给应用。这些公共事件可能来自系统、其他应用和应用自身。 - - - -#### 接口列表 - -| API | 手机 | 平板 | 智慧屏 | 智能穿戴 | 轻量级智能穿戴 | -| ------------------------------------------------------------ | ---- | ---- | ------ | -------- | -------------- | -| CommonEvent.publish(event: string, callback: AsyncCallback) | 支持 | 支持 | 支持 | 支持 | 不支持 | -| CommonEvent.publish(event: string, options: CommonEventPublishData, callback: AsyncCallback) | 支持 | 支持 | 支持 | 支持 | 不支持 | -| CommonEvent.createSubscriber(subscribeInfo: CommonEventSubscribeInfo, callback: AsyncCallback) | 支持 | 支持 | 支持 | 支持 | 不支持 | -| CommonEvent.createSubscriber(subscribeInfo: CommonEventSubscribeInfo) | 支持 | 支持 | 支持 | 支持 | 不支持 | -| CommonEvent.subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback) | 支持 | 支持 | 支持 | 支持 | 不支持 | -| CommonEvent.unsubscribe(subscriber: CommonEventSubscriber, callback?: AsyncCallback) | 支持 | 支持 | 支持 | 支持 | 不支持 | - - - -#### 导入模块 - -```js -import CommonEvent from '@ohos.commonevent'; -``` - - - -#### 创建公共事件订阅者 - -根据开发者设定的公共事件订阅相关信息(比如准备订阅的公共事件集等)创建公共事件订阅者对象。 - -- CommonEventSubscribeInfo类型说明 - - CommonEventSubscribeInfo封装公共事件订阅相关信息,比如准备订阅的公共事件集、发布者必须具备的权限、发布者的设备ID、发布者的用户ID、优先级等。 - - | 名称 | 读写属性 | 类型 | 必填 | 描述 | - | ------------------- | -------- | ------------- | ---- | ------------------------------------------------------------ | - | events | 只读 | Array | 是 | 表示要订阅的公共事件集。 | - | publisherPermission | 只读 | string | 否 | 表示发布者的权限。 | - | publisherDeviceId | 只读 | int | 否 | 表示发布者的设备ID,该值必须是同一ohos网络上的现有设备ID。 | - | userId | 只读 | int | 否 | 表示发布者的用户ID。默认值当前用户的ID。如果指定了此参数,则该值必须是系统中现有的用户ID。 | - | priority | 只读 | int | 否 | 表示订阅者的优先级,范围为-100~1000,用于有序公共事件。 | - -- CommonEventSubscriber 类说明 - - CommonEventSubscriber封装公共事件订阅者及相关参数,主要接口如下。 - - | 名称 | 参数 | 返回值 | 描述 | - | --------------------- | --------------------------------------------------------- | --------------------------------- | ------------------------------------------------------------ | - | getCode | callback: AsyncCallback | void | 获取公共事件的结果代码(callback形式) | - | getCode | void | Promise | 获取公共事件的结果代码(Promise形式) | - | setCode | code: number, callback: AsyncCallback | void | 设置有序公共事件的结果代码(callback形式) | - | setCode | code: number | Promise | 设置有序公共事件的结果代码(Promise形式) | - | getData | callback: AsyncCallback | void | 获取公共事件的结果数据(callback形式) | - | getData | void | Promise | 获取公共事件的结果数据(Promise形式) | - | setData | data: string, callback: AsyncCallback | void | 设置有序公共事件的结果数据(callback形式) | - | setData | data: string | Promise | 设置有序公共事件的结果数据(Promise形式) | - | setCodeAndData | code: number, data: string, callback: AsyncCallback | void | 设置有序公共事件的结果代码和结果数据(callback形式) | - | setCodeAndData | code: number, data: string | Promise | 设置有序公共事件的结果代码和结果数据(Promise形式) | - | isOrderedCommonEvent | callback: AsyncCallback | void | 查询当前公共事件的是否为有序公共事件,返回true代表是有序公共事件,false代表不是有序公共事件(callback形式) | - | isOrderedCommonEvent | void | Promise | 查询当前公共事件的是否为有序公共事件,返回true代表是有序公共事件,false代表不是有序公共事件(Promise形式) | - | abortCommonEvent | callback: AsyncCallback | void | 取消当前的公共事件,仅对有序公共事件有效,取消后,公共事件不再向下一个订阅者传递(callback形式) | - | abortCommonEvent | void | Promise | 取消当前的公共事件,仅对有序公共事件有效,取消后,公共事件不再向下一个订阅者传递(Promise形式) | - | clearAbortCommonEvent | callback: AsyncCallback | void | 清除当前有序公共事件abort状态(callback形式) | - | clearAbortCommonEvent | void | Promise | 清除当前有序公共事件abort状态(Promise形式) | - | getAbortCommonEvent | callback: AsyncCallback | void | 获取当前有序公共事件是否取消的状态(callback形式) | - | getAbortCommonEvent | void | Promise | 获取当前有序公共事件是否取消的状态Promise形式) | - | getSubscribeInfo | callback: AsyncCallback | void | 获取订阅者的订阅信息(callback形式) | - | getSubscribeInfo | void | Promise | 获取订阅者的订阅信息(Promise形式) | - - - -- 创建订阅者接口(callback形式) - - CommonEvent.createSubscriber(subscribeInfo: CommonEventSubscribeInfo, callback: AsyncCallback) - - - 接口参数描述 - - - | 名称 | 读写属性 | 类型 | 必填 | 描述 | - | ------------- | -------- | ------------------------------------ | ---- | ------------------------ | - | subscribeInfo | 只读 | CommonEventSubscribeInfo | 是 | 表示公共事件订阅信息 | - | callback | 只读 | AsyncCallback | 是 | 表示创建订阅者的回调方法 | - - - 返回值 - - void - - - 示例代码 - - ```js - var subscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 - //订阅者信息 - var subscribeInfo = { - events: ["event"] - }; - //创建订阅者回调 - function CreateSubscriberCallBack(err, data) { - console.info("==========================>CreateSubscriberCallBack=======================>"); - subscriber = data; - } - //创建订阅者 - CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack); - ``` - -- 创建订阅者接口(Promise形式) - - CommonEvent.createSubscriber(subscribeInfo: CommonEventSubscribeInfo) - - - 接口参数描述 - - | 名称 | 读写属性 | 类型 | 必填 | 描述 | - | ------------- | -------- | ------------------------ | ---- | ------------ | - | subscribeInfo | 只读 | CommonEventSubscribeInfo | 是 | 表示订阅信息 | - - - 返回值 - - Promise - - - 示例代码 - - ```js - var subscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 - //订阅者信息 - var subscribeInfo = { - events: ["event"] - }; - //创建订阅者 - CommonEvent.createSubscriber(subscribeInfo).then((data) => { - ``` - - console.info("==========================>createSubscriberPromise=======================>"); - subscriber = data; - }); - ``` - - - -#### 订阅公共事件 - -订阅公共事件,并指定公共事件订阅者对象和接收公共事件的回调函数。 - -- CommonEventData类型说明 - - CommonEventData封装公共事件相关信息。用于在接收时处理数据。 - - | 名称 | 读写属性 | 类型 | 必填 | 描述 | - | ---------- | -------- | -------------------- | ---- | ------------------------------------------------------- | - | event | 只读 | string | 是 | 表示当前接收的公共事件名称 | - | bundleName | 只读 | string | 否 | 表示包名称 | - | code | 只读 | int | 否 | 表示公共事件的结果代码,用于传递int类型的数据 | - | data | 只读 | string | 否 | 表示公共事件的自定义结果数据,用于传递string 类型的数据 | - | parameters | 只读 | {[key: string]: any} | 否 | 表示公共事件的附加信息 | - -- 订阅公共事件接口(callback形式) - - CommonEvent.subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback) - - - 接口参数描述 - - | 名称 | 读写属性 | 类型 | 必填 | 描述 | - | ---------- | -------- | ------------------------------ | ---- | ------------------------------ | - | subscriber | 只读 | CommonEventSubscriber | 是 | 表示订阅者对象 | - | callback | 只读 | AsyncCallback | 是 | 表示接收公共事件数据的回调函数 | - - - 返回值 - - void - - - 示例代码 - - **无序事件:** - - ```js - var subscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 - //订阅者信息 - var subscribeInfo = { - events: ["event"] - }; - //订阅公共事件回调 - function SubscribeCallBack(err, data) { - console.info("==========================>SubscribeCallBack=======================>"); - } - //创建订阅者回调 - function CreateSubscriberCallBack(err, data) { - console.info("==========================>CreateSubscriberCallBack=======================>"); - subscriber = data; - //订阅公共事件 - CommonEvent.subscribe(subscriber, SubscribeCallBack); - } - //创建订阅者 - CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack); - ``` - - **有序事件:** - - ```js - var subscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 - //订阅者信息 - var subscribeInfo = { - events: ["event"] - }; - - //设置有序公共事件的结果代码回调 - function SetCodeCallBack(err) { - console.info("==========================>SetCodeCallBack=======================>"); - } - //设置有序公共事件的结果数据回调 - function SetDataCallBack(err) { - console.info("==========================>SetDataCallBack=======================>"); - } - //完成本次有序公共事件处理回调 - function FinishCommonEventCallBack(err) { - console.info("==========================>FinishCommonEventCallBack=======================>"); - } - //订阅公共事件回调 - function SubscribeCallBack(err, data) { - console.info("==========================>SubscribeCallBack=======================>"); - //设置有序公共事件的结果代码 - subscriber.setCode(0, SetCodeCallBack); - //设置有序公共事件的结果数据 - subscriber.setData("publish_data_changed", SetDataCallBack); - //完成本次有序公共事件处理 - subscriber.finishCommonEvent(FinishCommonEventCallBack) - } - - //创建订阅者回调 - function CreateSubscriberCallBack(err, data) { - console.info("==========================>CreateSubscriberCallBack=======================>"); - subscriber = data; - //订阅公共事件 - CommonEvent.subscribe(subscriber, SubscribeCallBack); - } - - //创建订阅者 - CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack); - ``` - - -​ - -#### 发布公共事件 - -发布指定事件名称的公共事件,并可携带事件相关数据、属性、限制等信息。 - -- CommonEventPublishData类型说明 - - CommonEventPublishData封装公共事件发布相关数据、属性及限制等信息,包括公共事件类型(有序或无序)、订阅者所需权限等。 - - | 名称 | 读写属性 | 类型 | 必填 | 描述 | - | --------------------- | -------- | -------------------- | ---- | ---------------------------- | - | bundleName | 只读 | string | 否 | 表示包名称 | - | code | 只读 | int | 否 | 表示公共事件的结果代码 | - | data | 只读 | string | 否 | 表示公共事件的自定义结果数据 | - | subscriberPermissions | 只读 | Array | 否 | 表示订阅者所需的权限 | - | isOrdered | 只读 | bool | 否 | 表示是否是有序事件 | - | parameters | 只读 | {[key: string]: any} | 否 | 表示公共事件的附加信息 | - -- 发布公共事件接口(callback形式) - - CommonEvent.publish(event: string, callback: AsyncCallback) - - - 接口参数描述 - - | 名称 | 读写属性 | 类型 | 必填 | 描述 | - | -------- | -------- | ------------------- | ---- | ------------------------ | - | event | 只读 | string | 是 | 表示要发送的公共事件名称 | - | callback | 只读 | AsyncCallback | 是 | 表示被指定的回调方法 | - - - 返回值 - - void - - - 示例代码 - - ```js - //发布公共事件回调 - function PublishCallBack(err) { - console.info("==========================>PublishCallBack=======================>"); - console.info("==========================>err:=======================>", err.code); - } - //发布公共事件 - CommonEvent.publish("publish_event", PublishCallBack); - ``` - -- 发布公共事件指定发布信息接口(callback形式) - - CommonEvent.publish(event: string, options: CommonEventPublishData, callback: AsyncCallback) - - - 接口参数描述 - - | 名称 | 读写属性 | 类型 | 必填 | 描述 | - | -------- | -------- | ---------------------- | ---- | ------------------------ | - | event | 只读 | string | 是 | 表示要发布的公共事件名称 | - | options | 只读 | CommonEventPublishData | 是 | 表示发布公共事件的属性 | - | callback | 只读 | AsyncCallback | 是 | 表示被指定的回调方法 | - - - 返回值 - - void - - - 示例代码 - - ```js - //公共事件相关信息 - var options = { - code: 0; //公共事件的初始代码 - data: "initial data"; //公共事件的初始数据 - isOrdered: true; //有序公共事件 - } - //发布公共事件回调 - function PublishCallBack(err) { - console.info("==========================>PublishCallBack=======================>"); - } - //发布公共事件 - CommonEvent.publish("publish_event", options, PublishCallBack); - ``` - - - - -#### 取消订阅公共事件 - -- 取消订阅公共事件接口(callback形式) - - CommonEvent.unsubscribe(subscriber: CommonEventSubscriber, callback?: AsyncCallback) - - - 接口参数描述 - - | 名称 | 读写属性 | 类型 | 必填 | 描述 | - | ---------- | -------- | --------------------- | ---- | ---------------------- | - | subscriber | 只读 | CommonEventSubscriber | 是 | 表示订阅者对象 | - | callback | 只读 | AsyncCallback | 是 | 表示取消订阅的回调方法 | - - - 返回值 - - void - - - 示例代码 - - ```js - var subscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 - //订阅者信息 - var subscribeInfo = { - events: ["event"] - }; - //订阅公共事件回调 - function SubscribeCallBack(err, data) { - console.info("==========================>SubscribeCallBack=======================>"); - } - //创建订阅者回调 - function CreateSubscriberCallBack(err, data) { - console.info("==========================>CreateSubscriberCallBack=======================>"); - subscriber = data; - //订阅公共事件 - CommonEvent.subscribe(subscriber, SubscribeCallBack); - } - //取消订阅公共事件回调 - function UnsubscribeCallBack(err) { - console.info("==========================>UnsubscribeCallBack=======================>"); - } - //创建订阅者 - CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack); - //取消订阅公共事件 - CommonEvent.unsubscribe(subscriber, UnsubscribeCallBack); - ``` - - - - -#### 系统公共事件列表 - -| 系统公共事件宏 | 系统公共事件名称 | 订阅者所需权限 | -| ------------------------------------------------------------ | ----------------------------------------------------------- | ------------------------------------------------------------ | -| COMMON_EVENT_BOOT_COMPLETED | usual.event.BOOT_COMPLETED | ohos.permission.RECEIVER_STARTUP_COMPLETED | -| COMMON_EVENT_LOCKED_BOOT_COMPLETED | usual.event.LOCKED_BOOT_COMPLETED | ohos.permission.RECEIVER_STARTUP_COMPLETED | -| COMMON_EVENT_SHUTDOWN | usual.event.SHUTDOWN | 无 | -| COMMON_EVENT_BATTERY_CHANGED | usual.event.BATTERY_CHANGED | 无 | -| COMMON_EVENT_BATTERY_LOW | usual.event.BATTERY_LOW | 无 | -| COMMON_EVENT_BATTERY_OKAY | usual.event.BATTERY_OKAY | 无 | -| COMMON_EVENT_POWER_CONNECTED | usual.event.POWER_CONNECTED | 无 | -| COMMON_EVENT_POWER_DISCONNECTED | usual.event.POWER_DISCONNECTED | 无 | -| COMMON_EVENT_SCREEN_OFF | usual.event.SCREEN_OFF | 无 | -| COMMON_EVENT_SCREEN_ON | usual.event.SCREEN_ON | 无 | -| COMMON_EVENT_USER_PRESENT | usual.event.USER_PRESENT | 无 | -| COMMON_EVENT_TIME_TICK | usual.event.TIME_TICK | 无 | -| COMMON_EVENT_TIME_CHANGED | usual.event.TIME_CHANGED | 无 | -| COMMON_EVENT_DATE_CHANGED | usual.event.DATE_CHANGED | 无 | -| COMMON_EVENT_TIMEZONE_CHANGED | usual.event.TIMEZONE_CHANGED | 无 | -| COMMON_EVENT_CLOSE_SYSTEM_DIALOGS | usual.event.CLOSE_SYSTEM_DIALOGS | 无 | -| COMMON_EVENT_PACKAGE_ADDED | usual.event.PACKAGE_ADDED | 无 | -| COMMON_EVENT_PACKAGE_REPLACED | usual.event.PACKAGE_REPLACED | 无 | -| COMMON_EVENT_MY_PACKAGE_REPLACED | usual.event.MY_PACKAGE_REPLACED | 无 | -| COMMON_EVENT_PACKAGE_REMOVED | usual.event.PACKAGE_REMOVED | 无 | -| COMMON_EVENT_PACKAGE_FULLY_REMOVED | usual.event.PACKAGE_FULLY_REMOVED | 无 | -| COMMON_EVENT_PACKAGE_CHANGED | usual.event.PACKAGE_CHANGED | 无 | -| COMMON_EVENT_PACKAGE_RESTARTED | usual.event.PACKAGE_RESTARTED | 无 | -| COMMON_EVENT_PACKAGE_DATA_CLEARED | usual.event.PACKAGE_DATA_CLEARED | 无 | -| COMMON_EVENT_PACKAGES_SUSPENDED | usual.event.PACKAGES_SUSPENDED | 无 | -| COMMON_EVENT_PACKAGES_UNSUSPENDED | usual.event.PACKAGES_UNSUSPENDED | 无 | -| COMMON_EVENT_MY_PACKAGE_SUSPENDED | usual.event.MY_PACKAGE_SUSPENDED | 无 | -| COMMON_EVENT_MY_PACKAGE_UNSUSPENDED | usual.event.MY_PACKAGE_UNSUSPENDED | 无 | -| COMMON_EVENT_UID_REMOVED | usual.event.UID_REMOVED | 无 | -| COMMON_EVENT_PACKAGE_FIRST_LAUNCH | usual.event.PACKAGE_FIRST_LAUNCH | 无 | -| COMMON_EVENT_PACKAGE_NEEDS_VERIFICATION | usual.event.PACKAGE_NEEDS_VERIFICATION | 无 | -| COMMON_EVENT_PACKAGE_VERIFIED | usual.event.PACKAGE_VERIFIED | 无 | -| COMMON_EVENT_EXTERNAL_APPLICATIONS_AVAILABLE | usual.event.EXTERNAL_APPLICATIONS_AVAILABLE | 无 | -| COMMON_EVENT_EXTERNAL_APPLICATIONS_UNAVAILABLE | usual.event.EXTERNAL_APPLICATIONS_UNAVAILABLE | 无 | -| COMMON_EVENT_CONFIGURATION_CHANGED | usual.event.CONFIGURATION_CHANGED | 无 | -| COMMON_EVENT_LOCALE_CHANGED | usual.event.LOCALE_CHANGED | 无 | -| COMMON_EVENT_MANAGE_PACKAGE_STORAGE | usual.event.MANAGE_PACKAGE_STORAGE | 无 | -| COMMON_EVENT_DRIVE_MODE | common.event.DRIVE_MODE | 无 | -| COMMON_EVENT_HOME_MODE | common.event.HOME_MODE | 无 | -| COMMON_EVENT_OFFICE_MODE | common.event.OFFICE_MODE | 无 | -| COMMON_EVENT_USER_STARTED | usual.event.USER_STARTED | 无 | -| COMMON_EVENT_USER_BACKGROUND | usual.event.USER_BACKGROUND | 无 | -| COMMON_EVENT_USER_FOREGROUND | usual.event.USER_FOREGROUND | 无 | -| COMMON_EVENT_USER_SWITCHED | usual.event.USER_SWITCHED | ohos.permission.MANAGE_USERS | -| COMMON_EVENT_USER_STARTING | usual.event.USER_STARTING | ohos.permission.INTERACT_ACROSS_USERS | -| COMMON_EVENT_USER_UNLOCKED | usual.event.USER_UNLOCKED | 无 | -| COMMON_EVENT_USER_STOPPING | usual.event.USER_STOPPING | ohos.permission.INTERACT_ACROSS_USERS | -| COMMON_EVENT_USER_STOPPED | usual.event.USER_STOPPED | 无 | -| COMMON_EVENT_HWID_LOGIN | common.event.HWID_LOGIN | 无 | -| COMMON_EVENT_HWID_LOGOUT | common.event.HWID_LOGOUT | 无 | -| COMMON_EVENT_HWID_TOKEN_INVALID | common.event.HWID_TOKEN_INVALID | 无 | -| COMMON_EVENT_HWID_LOGOFF | common.event.HWID_LOGOFF | 无 | -| COMMON_EVENT_WIFI_POWER_STATE | usual.event.wifi.POWER_STATE | 无 | -| COMMON_EVENT_WIFI_SCAN_FINISHED | usual.event.wifi.SCAN_FINISHED | ohos.permission.LOCATION | -| COMMON_EVENT_WIFI_RSSI_VALUE | usual.event.wifi.RSSI_VALUE | ohos.permission.GET_WIFI_INFO | -| COMMON_EVENT_WIFI_CONN_STATE | usual.event.wifi.CONN_STATE | 无 | -| COMMON_EVENT_WIFI_HOTSPOT_STATE | usual.event.wifi.HOTSPOT_STATE | 无 | -| COMMON_EVENT_WIFI_AP_STA_JOIN | usual.event.wifi.WIFI_HS_STA_JOIN | ohos.permission.GET_WIFI_INFO | -| COMMON_EVENT_WIFI_AP_STA_LEAVE | usual.event.wifi.WIFI_HS_STA_LEAVE | ohos.permission.GET_WIFI_INFO | -| COMMON_EVENT_WIFI_MPLINK_STATE_CHANGE | usual.event.wifi.mplink.STATE_CHANGE | ohos.permission.MPLINK_CHANGE_STATE | -| COMMON_EVENT_WIFI_P2P_CONN_STATE | usual.event.wifi.p2p.CONN_STATE_CHANGE | ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION | -| COMMON_EVENT_WIFI_P2P_STATE_CHANGED | usual.event.wifi.p2p.STATE_CHANGE | ohos.permission.GET_WIFI_INFO | -| COMMON_EVENT_WIFI_P2P_PEERS_STATE_CHANGED | usual.event.wifi.p2p.DEVICES_CHANGE | ohos.permission.GET_WIFI_INFO | -| COMMON_EVENT_WIFI_P2P_PEERS_DISCOVERY_STATE_CHANGED | usual.event.wifi.p2p.PEER_DISCOVERY_STATE_CHANGE | ohos.permission.GET_WIFI_INFO | -| COMMON_EVENT_WIFI_P2P_CURRENT_DEVICE_STATE_CHANGED | usual.event.wifi.p2p.CURRENT_DEVICE_CHANGE | ohos.permission.GET_WIFI_INFO | -| COMMON_EVENT_WIFI_P2P_GROUP_STATE_CHANGED | usual.event.wifi.p2p.GROUP_STATE_CHANGED | ohos.permission.GET_WIFI_INFO | -| COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_CONNECT_STATE_UPDATE | usual.event.bluetooth.handsfree.ag.CONNECT_STATE_UPDATE | ohos.permission.USE_BLUETOOTH | -| COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_CURRENT_DEVICE_UPDATE | usual.event.bluetooth.handsfree.ag.CURRENT_DEVICE_UPDATE | ohos.permission.USE_BLUETOOTH | -| COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_AUDIO_STATE_UPDATE | usual.event.bluetooth.handsfree.ag.AUDIO_STATE_UPDATE | ohos.permission.USE_BLUETOOTH | -| COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CONNECT_STATE_UPDATE | usual.event.bluetooth.a2dpsource.CONNECT_STATE_UPDATE | ohos.permission.USE_BLUETOOTH | -| COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CURRENT_DEVICE_UPDATE | usual.event.bluetooth.a2dpsource.CURRENT_DEVICE_UPDATE | ohos.permission.USE_BLUETOOTH | -| COMMON_EVENT_BLUETOOTH_A2DPSOURCE_PLAYING_STATE_UPDATE | usual.event.bluetooth.a2dpsource.PLAYING_STATE_UPDATE" | ohos.permission.USE_BLUETOOTH | -| COMMON_EVENT_BLUETOOTH_A2DPSOURCE_AVRCP_CONNECT_STATE_UPDATE | usual.event.bluetooth.a2dpsource.AVRCP_CONNECT_STATE_UPDATE | ohos.permission.USE_BLUETOOTH | -| COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CODEC_VALUE_UPDATE | usual.event.bluetooth.a2dpsource.CODEC_VALUE_UPDATE | ohos.permission.USE_BLUETOOTH | -| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_DISCOVERED | usual.event.bluetooth.remotedevice.DISCOVERED | ohos.permission.USE_BLUETOOTH and ohos.permission.LOCATION | -| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CLASS_VALUE_UPDATE | usual.event.bluetooth.remotedevice.CLASS_VALUE_UPDATE | ohos.permission.USE_BLUETOOTH | -| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_ACL_CONNECTED | usual.event.bluetooth.remotedevice.ACL_CONNECTED | ohos.permission.USE_BLUETOOTH | -| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_ACL_DISCONNECTED | usual.event.bluetooth.remotedevice.ACL_DISCONNECTED | ohos.permission.USE_BLUETOOTH | -| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_NAME_UPDATE | usual.event.bluetooth.remotedevice.NAME_UPDATE | ohos.permission.USE_BLUETOOTH | -| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIR_STATE | usual.event.bluetooth.remotedevice.PAIR_STATE | ohos.permission.USE_BLUETOOTH | -| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_BATTERY_VALUE_UPDATE | usual.event.bluetooth.remotedevice.BATTERY_VALUE_UPDATE | ohos.permission.USE_BLUETOOTH | -| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_SDP_RESULT | usual.event.bluetooth.remotedevice.SDP_RESULT | 无 | -| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_UUID_VALUE | usual.event.bluetooth.remotedevice.UUID_VALUE | ohos.permission.DISCOVER_BLUETOOTH | -| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIRING_REQ | usual.event.bluetooth.remotedevice.PAIRING_REQ | ohos.permission.DISCOVER_BLUETOOTH | -| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIRING_CANCEL | usual.event.bluetooth.remotedevice.PAIRING_CANCEL | 无 | -| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CONNECT_REQ | usual.event.bluetooth.remotedevice.CONNECT_REQ | 无 | -| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CONNECT_REPLY | usual.event.bluetooth.remotedevice.CONNECT_REPLY | 无 | -| COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CONNECT_CANCEL | usual.event.bluetooth.remotedevice.CONNECT_CANCEL | 无 | -| COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_CONNECT_STATE_UPDATE | usual.event.bluetooth.handsfreeunit.CONNECT_STATE_UPDATE | 无 | -| COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_AUDIO_STATE_UPDATE | usual.event.bluetooth.handsfreeunit.AUDIO_STATE_UPDATE | 无 | -| COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_AG_COMMON_EVENT | usual.event.bluetooth.handsfreeunit.AG_COMMON_EVENT | 无 | -| COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_AG_CALL_STATE_UPDATE | usual.event.bluetooth.handsfreeunit.AG_CALL_STATE_UPDATE | 无 | -| COMMON_EVENT_BLUETOOTH_HOST_STATE_UPDATE | usual.event.bluetooth.host.STATE_UPDATE | 无 | -| COMMON_EVENT_BLUETOOTH_HOST_REQ_DISCOVERABLE | usual.event.bluetooth.host.REQ_DISCOVERABLE | 无 | -| COMMON_EVENT_BLUETOOTH_HOST_REQ_ENABLE | usual.event.bluetooth.host.REQ_ENABLE | ohos.permission.USE_BLUETOOTH | -| COMMON_EVENT_BLUETOOTH_HOST_REQ_DISABLE | usual.event.bluetooth.host.REQ_DISABLE | ohos.permission.USE_BLUETOOTH | -| COMMON_EVENT_BLUETOOTH_HOST_SCAN_MODE_UPDATE | usual.event.bluetooth.host.SCAN_MODE_UPDATE | ohos.permission.USE_BLUETOOTH | -| COMMON_EVENT_BLUETOOTH_HOST_DISCOVERY_STARTED | usual.event.bluetooth.host.DISCOVERY_STARTED | ohos.permission.USE_BLUETOOTH | -| COMMON_EVENT_BLUETOOTH_HOST_DISCOVERY_FINISHED | usual.event.bluetooth.host.DISCOVERY_FINISHED | ohos.permission.USE_BLUETOOTH | -| COMMON_EVENT_BLUETOOTH_HOST_NAME_UPDATE | usual.event.bluetooth.host.NAME_UPDATE | ohos.permission.USE_BLUETOOTH | -| COMMON_EVENT_BLUETOOTH_A2DPSINK_CONNECT_STATE_UPDATE | usual.event.bluetooth.a2dpsink.CONNECT_STATE_UPDATE | ohos.permission.USE_BLUETOOTH | -| COMMON_EVENT_BLUETOOTH_A2DPSINK_PLAYING_STATE_UPDATE | usual.event.bluetooth.a2dpsink.PLAYING_STATE_UPDATE | ohos.permission.USE_BLUETOOTH | -| COMMON_EVENT_BLUETOOTH_A2DPSINK_AUDIO_STATE_UPDATE | usual.event.bluetooth.a2dpsink.AUDIO_STATE_UPDATE | ohos.permission.USE_BLUETOOTH | -| COMMON_EVENT_NFC_ACTION_ADAPTER_STATE_CHANGED | usual.event.nfc.action.ADAPTER_STATE_CHANGED | 无 | -| COMMON_EVENT_NFC_ACTION_RF_FIELD_ON_DETECTED | usual.event.nfc.action.RF_FIELD_ON_DETECTED | ohos.permission.MANAGE_SECURE_SETTINGS | -| COMMON_EVENT_NFC_ACTION_RF_FIELD_OFF_DETECTED | usual.event.nfc.action.RF_FIELD_OFF_DETECTED | ohos.permission.MANAGE_SECURE_SETTINGS | -| COMMON_EVENT_DISCHARGING | usual.event.DISCHARGING | 无 | -| COMMON_EVENT_CHARGING | usual.event.CHARGING | 无 | -| COMMON_EVENT_DEVICE_IDLE_MODE_CHANGED | usual.event.DEVICE_IDLE_MODE_CHANGED | 无 | -| COMMON_EVENT_POWER_SAVE_MODE_CHANGED | usual.event.POWER_SAVE_MODE_CHANGED | 无 | -| COMMON_EVENT_USER_ADDED | usual.event.USER_ADDED | ohos.permission.MANAGE_USERS | -| COMMON_EVENT_USER_REMOVED | usual.event.USER_REMOVED | ohos.permission.MANAGE_USERS | -| COMMON_EVENT_ABILITY_ADDED | common.event.ABILITY_ADDED | ohos.permission.LISTEN_BUNDLE_CHANGE | -| COMMON_EVENT_ABILITY_REMOVED | common.event.ABILITY_REMOVED | ohos.permission.LISTEN_BUNDLE_CHANGE | -| COMMON_EVENT_ABILITY_UPDATED | common.event.ABILITY_UPDATED | ohos.permission.LISTEN_BUNDLE_CHANGE | -| COMMON_EVENT_LOCATION_MODE_STATE_CHANGED | usual.event.location.MODE_STATE_CHANGED | 无 | -| COMMON_EVENT_IVI_SLEEP | common.event.IVI_SLEEP | 无 | -| COMMON_EVENT_IVI_PAUSE | common.event.IVI_PAUSE | 无 | -| COMMON_EVENT_IVI_STANDBY | common.event.IVI_STANDBY | 无 | -| COMMON_EVENT_IVI_LASTMODE_SAVE | common.event.IVI_LASTMODE_SAVE | 无 | -| COMMON_EVENT_IVI_VOLTAGE_ABNORMAL | common.event.IVI_VOLTAGE_ABNORMAL | 无 | -| COMMON_EVENT_IVI_HIGH_TEMPERATURE | common.event.IVI_HIGH_TEMPERATURE | 无 | -| COMMON_EVENT_IVI_EXTREME_TEMPERATURE | common.event.IVI_EXTREME_TEMPERATURE | 无 | -| COMMON_EVENT_IVI_TEMPERATURE_ABNORMAL | common.event.IVI_TEMPERATURE_ABNORMAL | 无 | -| COMMON_EVENT_IVI_VOLTAGE_RECOVERY | common.event.IVI_VOLTAGE_RECOVERY | 无 | -| COMMON_EVENT_IVI_TEMPERATURE_RECOVERY | common.event.IVI_TEMPERATURE_RECOVERY | 无 | -| COMMON_EVENT_IVI_ACTIVE | common.event.IVI_ACTIVE | 无 | -| COMMON_EVENT_USB_DEVICE_ATTACHED | usual.event.hardware.usb.action.USB_DEVICE_ATTACHED | 无 | -| COMMON_EVENT_USB_DEVICE_DETACHED | usual.event.hardware.usb.action.USB_DEVICE_DETACHED | 无 | -| COMMON_EVENT_USB_ACCESSORY_ATTACHED | usual.event.hardware.usb.action.USB_ACCESSORY_ATTACHED | 无 | -| COMMON_EVENT_USB_ACCESSORY_DETACHED | usual.event.hardware.usb.action.USB_ACCESSORY_DETACHED | 无 | -| COMMON_EVENT_DISK_REMOVED | usual.event.data.DISK_REMOVED | ohos.permission.WRITE_USER_STORAGE or ohos.permission.READ_USER_STORAGE | -| COMMON_EVENT_DISK_UNMOUNTED | usual.event.data.DISK_UNMOUNTED | ohos.permission.WRITE_USER_STORAGEor ohos.permission.READ_USER_STORAGE | -| COMMON_EVENT_DISK_MOUNTED | usual.event.data.DISK_MOUNTED | ohos.permission.WRITE_USER_STORAGEor ohos.permission.READ_USER_STORAGE | -| COMMON_EVENT_DISK_BAD_REMOVAL | usual.event.data.DISK_BAD_REMOVAL | ohos.permission.WRITE_USER_STORAGEor ohos.permission.READ_USER_STORAGE | -| COMMON_EVENT_DISK_UNMOUNTABLE | usual.event.data.DISK_UNMOUNTABLE | ohos.permission.WRITE_USER_STORAGEor ohos.permission.READ_USER_STORAGE | -| COMMON_EVENT_DISK_EJECT | usual.event.data.DISK_EJECT | ohos.permission.WRITE_USER_STORAGEor ohos.permission.READ_USER_STORAGE | -| COMMON_EVENT_VISIBLE_ACCOUNTS_UPDATED | usual.event.data.VISIBLE_ACCOUNTS_UPDATED | ohos.permission.GET_APP_ACCOUNTS | -| COMMON_EVENT_ACCOUNT_DELETED | usual.event.data.ACCOUNT_DELETED | ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS | -| COMMON_EVENT_FOUNDATION_READY | common.event.FOUNDATION_READY | ohos.permission.RECEIVER_STARTUP_COMPLETED | -| COMMON_EVENT_AIRPLANE_MODE_CHANGED | usual.event.AIRPLANE_MODE | 无 | diff --git a/website/docs/_posts/zh-cn/application-dev/ability/data-ability-creating-accessing.md b/website/docs/_posts/zh-cn/application-dev/ability/data-ability-creating-accessing.md deleted file mode 100644 index 439623d21be88586849e30739efcdc9f6a1f9288..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/ability/data-ability-creating-accessing.md +++ /dev/null @@ -1,199 +0,0 @@ ---- -title: data-ability-creating-accessing -permalink: /pages/extra/094a0f/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 基于Native的Data Ability创建与访问 - -## Data Ability基本概念 -通过Ability派生出的DataAbility类(以下简称“Data”),有助于应用管理其自身和其他应用存储数据的访问,并提供与其他应用共享数据的方法。Data既可用于同设备不同应用的数据共享,也支持跨设备不同应用的数据共享。 - -## 创建Data -### 1. Data子系统实现 -1. 基于Native的Data子系统,需要继承Ability类,成为Ability的派生类来实现功能 -2. 需要实现父类中Insert,Query,Update,Delete接口的业务内容.保证能够满足数据库存储业务的基本需求.BatchInsert与ExecuteBatch接口已经在系统中实现遍历逻辑,依赖Insert,Query,Update,Delete接口逻辑,来实现数据的批量处理. -3. 使用REGISTER_AA宏将Data的类名注册到系统服务中 - - -### 2. 子系统配置 - -| Json重要字段 | 备注说明 | -| ------------- | ------------------------------------------------------------ | -| "name" | Ability名子,对应Ability派生的Data类名 | -| "type" | Ability类型,Data对应的Ability类型未"data" | -| "uri" | 通信使用的URI | -| "srcLanguage" | Data实现语言,c++实现的Data填写c++, js实现的Data填写js | -| "visible" | 对其他应用是否可见, 设置为true时, Data才能与其他应用进行通信传输数据 | - -**config.json配置样例** - -```json -"abilities":[{ - "name": ".DataAbility", - "icon": "$media:snowball", - "label": "Data Firs Ability", - "launchType": "standard", - "orientation": "unspecified", - "type": "data", - "uri": "dataability://com.ix.DataAbility", - "srcLanguage": "c++", - "visible": true -}] -``` - -## 访问Data -### 1 JS应用开发前准备 -基础依赖包: - 1. @ohos.ability.featureAbility - 2. @ohos.data.dataability - 3. @ohos.data.rdb -与Data子系统通信的Uri字符串 - -### 2 JS应用开发接口 -工具接口类对象创建 -```js -// 作为参数传递的Uri,与config中定义的Uri的区别是多了一个"/",是因为作为参数传递的uri中,在第二个与第三个"/"中间,存在一个DeviceID的参数 -var urivar = "dataability:///com.ix.DataAbility" -var DAHelper = featureAbility.acquireDataAbilityHelper( - urivar -); -``` -数据库相关的rdb数据构建 -```js -var valuesBucket = {"name": "gaolu"} -var da = new ohos_data_ability.DataAbilityPredicates() -var valArray =new Array("value1"); -var cars = new Array({"batchInsert1" : "value1",}); -``` -向指定的Data子系统插入数据,inster调用 -```js -// callbacke方式调用: -DAHelper.insert( - urivar, - valuesBucket, - (error, data) => { - expect(typeof(data)).assertEqual("number") - } -); -// promise方式调用: -var datainsert = await DAHelper.insert( - urivar, - valuesBucket -); -``` -删除Data子系统中指定的数据, delete调用 -```js -// callbacke方式调用: -DAHelper.delete( - urivar, - da, - (error, data) => { - expect(typeof(data)).assertEqual("number") - } -); -// promise方式调用: -var datadelete = await DAHelper.delete( - urivar, - da, -); -``` -更新指定Data子系统中的数据, update调用 -```js -// callbacke方式调用: -DAHelper.update( - urivar - valuesBucket, - da, - (error, data) => { - expect(typeof(data)).assertEqual("number") - } -); -// promise方式调用: -var dataupdate = await DAHelper.update( - urivar, - valuesBucket, - da, -); -``` -在指定的Data子系统中查找数据,query调用 -```js -// callbacke方式调用: -DAHelper.query( - urivar, - valArray, - da, - (error, data) => { - expect(typeof(data)).assertEqual("object") - } -); -// promise方式调用: -var dataquery = await DAHelper.query( - urivar, - valArray, - da -); -``` -向指定的数据子系统批量插入数据,batchInsert调用 -```js -// callbacke方式调用: -DAHelper.batchInsert( - urivar, - cars, - (error, data) => { - expect(typeof(data)).assertEqual("number") - } -); -// promise方式调用: -var databatchInsert = await DAHelper.batchInsert( - urivar, - cars -); -``` -向指定的Data子系统进行数据的批量处理,executeBatch调用 -```js -// callbacke方式调用: -DAHelper.executeBatch( - urivar, - [ - { - uri: urivar, - type: featureAbility.DataAbilityOperationType.TYPE_INSERT, - valuesBucket: {"executeBatch" : "value1",}, - predicates: da, - expectedCount:0, - PredicatesBackReferences: {}, - interrupted:true, - } - ], - (error, data) => { - expect(typeof(data)).assertEqual("object") - } -); -// promise方式调用: -var dataexecuteBatch = await DAHelper.executeBatch( - urivar, - [ - { - uri: urivar, - type: featureAbility.DataAbilityOperationType.TYPE_INSERT, - valuesBucket: - { - "executeBatch" : "value1", - }, - predicates: da, - expectedCount:0, - PredicatesBackReferences: {}, - interrupted:true, - } - ] -); -``` - diff --git a/website/docs/_posts/zh-cn/application-dev/ability/notification.md b/website/docs/_posts/zh-cn/application-dev/ability/notification.md deleted file mode 100644 index 9f09348a29b4658ef4dd2c0b8b3e8111978ed73d..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/ability/notification.md +++ /dev/null @@ -1,1602 +0,0 @@ ---- -title: notification -permalink: /pages/extra/fb46d5/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- - - -# Notification开发指南 - -#### 简介 - -OpenHarmony通过ANS(Advanced Notification Service,通知系统服务)对通知类型的消息进行管理,支持多种通知类型,包括文本,长文本,多文本,图片,社交,媒体等。所有系统服务以及应用都可以通过通知接口发送通知消息,用户可以通过SystemUI查看所有通知消息。 - -通知常见的使用场景: - -- 显示接收到短消息、即时消息等。 -- 显示应用的推送消息,如广告、版本更新等。 -- 显示当前正在进行的事件,如导航、下载等。 - - - -#### 接口列表 - -| API | 手机 | 平板 | 智慧屏 | 智能穿戴 | -| ------------------------------------------------------------ | ---- | ---- | ------ | -------- | -| Notification.publish(request: NotificationRequest, callback: AsyncCallback) | 支持 | 支持 | 支持 | 支持 | -| Notification.publish(request: NotificationRequest) | 支持 | 支持 | 支持 | 支持 | -| Notification.cancel(id: number, label: string, callback: AsyncCallback) | 支持 | 支持 | 支持 | 支持 | -| Notification.cancel(id:number, label?:string) | 支持 | 支持 | 支持 | 支持 | -| Notification.cancel(id: number, callback: AsyncCallback) | 支持 | 支持 | 支持 | 支持 | -| Notification.cancelAll(callback: AsyncCallback) | 支持 | 支持 | 支持 | 支持 | -| Notification.cancelAll() | 支持 | 支持 | 支持 | 支持 | -| Notification.addSlot(type: SlotType, callback: AsyncCallback) | 支持 | 支持 | 支持 | 支持 | -| Notification.addSlot(type: SlotType) | 支持 | 支持 | 支持 | 支持 | -| Notification.getSlot(slotType: SlotType, callback: AsyncCallback) | 支持 | 支持 | 支持 | 支持 | -| Notification.getSlot(slotType: SlotType) | 支持 | 支持 | 支持 | 支持 | -| Notification.getSlots(callback: AsyncCallback>) | 支持 | 支持 | 支持 | 支持 | -| Notification.getSlots() | 支持 | 支持 | 支持 | 支持 | -| Notification.removeSlot(slotType: SlotType, callback: AsyncCallback) | 支持 | 支持 | 支持 | 支持 | -| Notification.removeSlot(slotType: SlotType) | 支持 | 支持 | 支持 | 支持 | -| Notification.removeAllSlots(callback: AsyncCallback): void | 支持 | 支持 | 支持 | 支持 | -| Notification.removeAllSlots(): Promise | 支持 | 支持 | 支持 | 支持 | -| Notification.getActiveNotificationCount(callback: AsyncCallback) | 支持 | 支持 | 支持 | 支持 | -| Notification.getActiveNotificationCount() | 支持 | 支持 | 支持 | 支持 | -| Notification.getActiveNotifications(callback: AsyncCallback>) | 支持 | 支持 | 支持 | 支持 | -| Notification.getActiveNotifications() | 支持 | 支持 | 支持 | 支持 | -| WantAgent.getWantAgent(info: WantAgentInfo, callback: AsyncCallback) | 支持 | 支持 | 支持 | 支持 | -| WantAgent.getWantAgent(info: WantAgentInfo): Promise | 支持 | 支持 | 支持 | 支持 | -| WantAgent.getBundleName(agent: WantAgent, callback: AsyncCallback) | 支持 | 支持 | 支持 | 支持 | -| WantAgent.getBundleName(agent: WantAgent): Promise | 支持 | 支持 | 支持 | 支持 | -| WantAgent.getUid(agent: WantAgent, callback: AsyncCallback) | 支持 | 支持 | 支持 | 支持 | -| WantAgent.getUid(agent: WantAgent): Promise | 支持 | 支持 | 支持 | 支持 | -| WantAgent.cancel(agent: WantAgent, callback: AsyncCallback) | 支持 | 支持 | 支持 | 支持 | -| WantAgent.cancel(agent: WantAgent): Promise | 支持 | 支持 | 支持 | 支持 | -| WantAgent.trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: Callback) | 支持 | 支持 | 支持 | 支持 | -| WantAgent.equal(agent: WantAgent, otherAgent: WantAgent, callback: AsyncCallback) | 支持 | 支持 | 支持 | 支持 | -| WantAgent.equal(agent: WantAgent, otherAgent: WantAgent): Promise | 支持 | 支持 | 支持 | 支持 | - - - -#### Notification接口 - -##### 导入模块 - -```js -import Notification from '@ohos.notification'; -``` - - - -##### NotificationSlot类型说明 - -NotificationSlot可以对提示音、振动等进行设置。一个应用可以创建一个或多个NotificationSlot,在发布通知时,通过绑定不同的NotificationSlot,实现不同用途。 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------------------- | -------- | ------------- | ---- | ---------------------------- | -| type | 读、写 | SlotType | 是 | 通道类型 | -| level | 读、写 | SlotLevel | 否 | 通知级别 | -| desc | 读、写 | string | 否 | 通知渠道描述信息 | -| badgeFlag | 读、写 | boolean | 否 | 是否显示角标 | -| bypassDnd | 读、写 | boolean | 否 | 置是否在系统中绕过免打扰模式 | -| lockscreenVisibility | 读、写 | boolean | 否 | 在锁定屏幕上显示通知的模式 | -| vibrationEnabled | 读、写 | boolean | 否 | 是否可振动 | -| sound | 读、写 | string | 否 | 通知提示音 | -| lightEnabled | 读、写 | boolean | 否 | 是否闪灯 | -| lightColor | 读、写 | number | 否 | 通知灯颜色 | -| vibrationValues | 读、写 | Array | 否 | 通知振动样式 | - -- SlotType类型说明 - -| 名称 | 读写属性 | 类型 | 描述 | -| -------------------- | -------- | ---- | -------- | -| SOCIAL_COMMUNICATION | 只读 | enum | 社交类型 | -| SERVICE_INFORMATION | 只读 | enum | 服务类型 | -| CONTENT_INFORMATION | 只读 | enum | 内容类型 | -| OTHER_TYPES | 只读 | enum | 其他类型 | - -- SlotLevel类型说明 - -| 名称 | 读写属性 | 类型 | 描述 | -| ------------- | -------- | ---- | ------------------------------------------------------------ | -| LEVEL_NONE | 只读 | enum | 表示通知不发布 | -| LEVEL_MIN | 只读 | enum | 表示通知可以发布,但不在状态栏显示,不自动弹出,无提示音;该级别不适用于前台服务的场景 | -| LEVEL_LOW | 只读 | enum | 表示通知发布后在状态栏显示,不自动弹出,无提示音 | -| LEVEL_DEFAULT | 只读 | enum | 表示通知发布后在状态栏显示,不自动弹出,触发提示音 | -| LEVEL_HIGH | 只读 | enum | 表示通知发布后在状态栏显示,自动弹出,触发提示音 | - - - -##### NotificationRequest类型说明 - -NotificationRequest用于设置具体的通知对象,包括设置通知的属性,如:通知的分发时间、小图标、大图标、自动删除等参数,以及设置具体的通知类型,如普通文本、长文本等。 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ----------------- | -------- | ------------------------------- | ---- | -------------------------- | -| content | 读、写 | NotificationContent | 是 | 通知内容 | -| id | 读、写 | number | 否 | 通知ID | -| slotType | 读、写 | SlotType | 否 | 通道类型 | -| isOngoing | 读、写 | boolean | 否 | 是否进行时通知 | -| isUnremovable | 读、写 | boolean | 否 | 是否可移除 | -| deliveryTime | 读、写 | number | 否 | 通知发送时间 | -| tapDismissed | 读、写 | boolean | 否 | 通知是否自动清除 | -| autoDeletedTime | 读、写 | number | 否 | 自动清除的时间 | -| wantAgent | 读、写 | WantAgent | 否 | 点击跳转的WantAgent | -| extraInfo | 读、写 | {[key: string]: any} | 否 | 扩展参数 | -| color | 读、写 | number | 否 | 通知背景颜色 | -| colorEnabled | 读、写 | boolean | 否 | 通知背景颜色是否使能 | -| isAlertOnce | 读、写 | boolean | 否 | 设置是否仅有一次此通知警报 | -| isStopwatch | 读、写 | boolean | 否 | 是否显示已用时间 | -| isCountDown | 读、写 | boolean | 否 | 是否显示倒计时时间 | -| isFloatingIcon | 读、写 | boolean | 否 | 是否显示状态栏图标 | -| isFloatingIcon | 读、写 | boolean | 否 | 是否显示状态栏图标 | -| label | 读、写 | string | 否 | 通知标签 | -| badgeIconStyle | 读、写 | number | 否 | 通知角标类型 | -| showDeliveryTime | 读、写 | boolean | 否 | 是否显示分发时间 | -| actionButtons | 读、写 | Array | 否 | 通知按钮,最多两个按钮 | -| smallIcon | 读、写 | PixelMap | 否 | 通知小图标 | -| largeIcon | 读、写 | PixelMap | 否 | 通知大图标 | -| creatorBundleName | 只读 | string | 否 | 创建通知的包名 | -| creatorUid | 只读 | number | 否 | 创建通知的UID | -| creatorPid | 只读 | number | 否 | 创建通知的PID | -| hashCode | 只读 | string | 否 | 通知唯一标识 | - -- NotificationContent类型说明 - - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ----------- | -------- | ---------------------------- | ---- | -------------------- | -| contentType | 读、写 | ContentType | 是 | 通知内容类型 | -| normal | 读、写 | NotificationBasicContent | 否 | 普通类型通知内容 | -| longText | 读、写 | NotificationLongTextContent | 否 | 长文本类型通知内容 | -| multiLine | 读、写 | NotificationMultiLineContent | 否 | 多行文本类型通知内容 | -| picture | 读、写 | NotificationPictureContent | 否 | 图片类型通知内容 | - -- ContentType类型说明 - -| 名称 | 读写属性 | 类型 | 描述 | -| --------------------------------- | -------- | ---- | ---------------- | -| NOTIFICATION_CONTENT_BASIC_TEXT | 只读 | enum | 普通类型通知 | -| NOTIFICATION_CONTENT_LONG_TEXT | 只读 | enum | 长文本类型通知 | -| NOTIFICATION_CONTENT_PICTURE | 只读 | enum | 图片类型通知 | -| NOTIFICATION_CONTENT_CONVERSATION | 只读 | enum | 社交类型通知 | -| NOTIFICATION_CONTENT_MULTILINE | 只读 | enum | 多行文本类型通知 | - -- NotificationBasicContent类型说明 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------------- | -------- | ------ | ---- | -------------------------------- | -| title | 读、写 | string | 是 | 通知标题 | -| text | 读、写 | string | 是 | 通知内容 | -| additionalText | 读、写 | string | 是 | 通知次要内容,是对通知内容的补充 | - -- NotificationLongTextContent类型说明 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ------------- | -------- | ------ | ---- | ---------------------- | -| title | 读、写 | string | 是 | 通知标题 | -| text | 读、写 | string | 是 | 通知内容 | -| additionalText | 读、写 | string | 是 | 通知次要内容,是对通知内容的补充 | -| longText | 读、写 | string | 是 | 通知的长文本 | -| briefText | 读、写 | string | 是 | 通知概要内容,是对通知内容的总结 | -| expandedTitle | 读、写 | string | 是 | 通知展开时的标题 | - -- NotificationMultiLineContent类型说明 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| --------- | -------- | ------------- | ---- | ---------------------- | -| title | 读、写 | string | 是 | 通知标题 | -| text | 读、写 | string | 是 | 通知内容 | -| additionalText | 读、写 | string | 是 | 通知次要内容,是对通知内容的补充 | -| briefText | 读、写 | string | 是 | 通知概要内容,是对通知内容的总结 | -| longTitle | 读、写 | string | 是 | 通知展开时的标题 | -| lines | 读、写 | Array | 是 | 通知的多行文本 | - -- NotificationPictureContent类型说明 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------------- | -------- | -------------- | ---- | -------------------------------- | -| title | 读、写 | string | 是 | 通知标题 | -| text | 读、写 | string | 是 | 通知内容 | -| additionalText | 读、写 | string | 是 | 通知次要内容,是对通知内容的补充 | -| briefText | 读、写 | string | 是 | 通知概要内容,是对通知内容的总结 | -| expandedTitle | 读、写 | string | 是 | 通知展开时的标题 | -| picture | 读、写 | image.PixelMap | 是 | 通知的图片内容 | - -- NotificationActionButton类型说明 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| --------- | -------- | -------------- | ---- | ------------------------- | -| title | 读、写 | string | 是 | 按钮标题 | -| wantAgent | 读、写 | wantAgent | 是 | 点击按钮时触发的WantAgent | -| extras | 读、写 | Array | 否 | 按钮扩展信息 | -| icon | 读、写 | image.PixelMap | 否 | 按钮图标 | - - - -##### 创建通知通道 - -- 创建通知通道(callback形式) - - Notification.addSlot(type: SlotType, callback: AsyncCallback) - - - 参数描述 - - | 名称 | 读写属性 | 类型 | 必填 | 描述 | - | -------- | -------- | ------------------- | ---- | ---------------------- | - | type | 只读 | SlotType | 是 | 要创建的通知通道的类型 | - | callback | 只读 | AsyncCallback | 是 | 表示被指定的回调方法 | - - - 返回值 - - void - - - 示例代码 - - ```js - //addslot回调 - function addSlotCallBack(err) { - console.info("==========================>addSlotCallBack=======================>"); - } - Notification.addSlot(SOCIAL_COMMUNICATION, addSlotCallBack) - ``` - - - -- 创建通知通道(Promise形式) - - Notification.addSlot(type: SlotType) - - - 参数描述 - - | 名称 | 读写属性 | 类型 | 必填 | 描述 | - | ---- | -------- | -------- | ---- | ---------------------- | - | type | 只读 | SlotType | 是 | 要创建的通知通道的类型 | - - - 返回值 - - Promise<**void**> - - - 示例代码 - - ```js - Notification.addSlot(SOCIAL_COMMUNICATION).then((void) => { - console.info("==========================>addSlotCallback=======================>"); - }); - ``` - - - -##### 获取通知通道 - -- 获取一个通知通道(callback形式) - - Notification.getSlot(slotType: SlotType, callback: AsyncCallback) - - - 参数描述 - - | 名称 | 读写属性 | 类型 | 必填 | 描述 | - | -------- | -------- | ------------------------------- | ---- | ----------------------------------------------------------- | - | slotType | 只读 | slotType | 是 | 通知渠道类型,目前分为社交通信、服务提醒、内容咨询和其他类型 | - | callback | 只读 | AsyncCallback | 是 | 表示被指定的回调方法 | - - - 返回值 - - void - - - 示例代码 - - ```js - //getSlot回调 - function getSlotCallback(err,data) { - console.info("==========================>getSlotCallback=======================>"); - } - var slotType = SOCIAL_COMMUNICATION; - Notification.getSlot(slotType, getSlotCallback) - ``` - - - -- 获取一个通知通道(Promise形式) - - Notification.getSlot(slotType) - - - 参数描述 - - | 名称 | 读写属性 | 类型 | 必填 | 描述 | - | -------- | -------- | -------- | ---- | ----------------------------------------------------------- | - | slotType | 只读 | slotType | 是 | 通知渠道类型,目前分为社交通信、服务提醒、内容咨询和其他类型 | - - - 返回值 - - Promise - - - 示例代码 - - ```js - var slotType = SOCIAL_COMMUNICATION; - Notification.getSlot(slotType).then((data) => { - console.info("==========================>getSlotCallback=======================>"); - }); - ``` - - - -- 获取本应用程序的所有通知通道(callback形式) - - Notification.getSlots(callback: AsyncCallback>) - - - 参数描述 - - | 名称 | 读写属性 | 类型 | 必填 | 描述 | - | -------- | -------- | ------------------------------- | ---- | -------------------- | - | callback | 只读 | AsyncCallback | 是 | 表示被指定的回调方法 | - - - 返回值 - - void - - - 示例代码 - - ```js - //getSlots回调 - function getSlotsCallback(err,data) { - console.info("==========================>getSlotsCallback=======================>"); - } - Notification.getSlots(getSlotsCallback) - ``` - - - -- 获取此应用程序的所有通知通道(Promise形式) - - Notification.getSlots() - - - 参数描述 - - 无参数 - - - 返回值 - - Promise> - - - 示例代码 - - ```js - Notification.getSlots().then((data) => { - console.info("==========================>getSlotsCallback=======================>"); - }); - ``` - - - -##### 删除通知通道 - -- 根据通知通道类型删除通知通道(callback形式) - - Notification.removeSlot(slotType: SlotType, callback: AsyncCallback) - - - 参数描述 - - | 名称 | 读写属性 | 类型 | 必填 | 描述 | - | -------- | -------- | ------------------- | ---- | ----------------------------------------------------------- | - | SlotType | 只读 | SlotType | 是 | 通知渠道类型,目前分为社交通信、服务提醒、内容咨询和其他类型 | - | callback | 只读 | AsyncCallback | 是 | 表示被指定的回调方法 | - - - 返回值 - - void - - - 示例代码 - - ```js - //removeSlot回调 - function removeSlotCallback(err) { - console.info("==========================>removeSlotCallback=======================>"); - } - var slotType = SOCIAL_COMMUNICATION; - Notification.removeSlot(slotType, removeSlotCallback) - ``` - - - -- 根据通知通道类型删除通知通道(Promise形式) - - Notification.removeSlot(slotType: SlotType) - - - 参数描述 - - | 名称 | 读写属性 | 类型 | 必填 | 描述 | - | -------- | -------- | -------- | ---- | ----------------------------------------------------------- | - | SlotType | 只读 | SlotType | 是 | 通知渠道类型,目前分为社交通信、服务提醒、内容咨询和其他类型 | - - - 返回值 - - Promise<**void**> - - - 示例代码 - - ```js - var slotType = SOCIAL_COMMUNICATION; - Notification.removeSlot(slotType).then((void) => { - console.info("==========================>removeSlotCallback=======================>"); - }); - ``` - - - -- 删除所有通知通道(callback形式) - - Notification.removeAllSlots(callback: AsyncCallback) - - - 参数描述 - - | 名称 | 读写属性 | 类型 | 必填 | 描述 | - | -------- | -------- | ------------------- | ---- | -------------------- | - | callback | 只读 | AsyncCallback | 是 | 表示被指定的回调方法 | - - - 返回值 - - void - - - 示例代码 - - ```js - function removeAllSlotsCallBack(err) { - console.info("================>removeAllSlotsCallBack=======================>"); - } - Notification.removeAllSlots(removeAllCallBack) - ``` - - - -- 删除所有通知通道(Promise形式) - - Notification.removeAllSlots() - - - 参数描述 - - 无参数 - - - 返回值 - - Promise<**void**> - - - 示例代码 - - ```js - Notification.removeAllSlots().then((void) => { - console.info("==========================>removeAllSlotsCallBack=======================>"); - }); - ``` - - - -##### 发布通知 - -- 发布通知(callback形式) - - Notification.publish(request: NotificationRequest, callback: AsyncCallback) - - - 参数描述 - - | 名称 | 读写属性 | 类型 | 必填 | 描述 | - | -------- | -------- | ------------------- | ---- | ------------------------------------------- | - | request | 只读 | NotificationRequest | 是 | 设置要发布通知内容的NotificationRequest对象 | - | callback | 只读 | AsyncCallback | 是 | 被指定的回调方法 | - - - 返回值 - - void - - - 示例代码 - - ```js - //publish回调 - function publishCallback(err) { - console.info("==========================>publishCallback=======================>"); - } - //通知Request对象 - var request = { - id: 1, - content: { - contentType: notify.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, - normal: { - title: "test_title", - text: "test_text", - additionalText: "test_additionalText" - } - } - } - Notification.publish(request, publishCallback); - ``` - - - - -- 发布通知(Promise形式) - - Notification.publish(request: NotificationRequest) - - - 参数描述 - - | 名称 | 读写属性 | 类型 | 必填 | 描述 | - | ------- | -------- | ------------------- | ---- | ------------------------------------------- | - | request | 只读 | NotificationRequest | 是 | 设置要发布通知内容的NotificationRequest对象 | - - - 返回值 - - Promise<**void**> - - - 示例代码 - - ```js - //通知Request对象 - var notificationRequest = { - notificationId: 1, - content: { - contentType: notify.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, - normal: { - title: "test_title", - text: "test_text", - additionalText: "test_additionalText" - } - } - } - Notification.publish(notificationRequest).then((void) => { - ``` - - console.info("==========================>publishCallback=======================>"); - }); - ``` - - - -##### 取消通知 - -- 取消指定通知(callback形式) - - Notification.cancel(id: number, label: string, callback: AsyncCallback) - - - 参数描述 - - | 名称 | 读写属性 | 类型 | 必填 | 描述 | - | -------- | -------- | ------------------- | ---- | -------------------- | - | id | 只读 | number | 是 | 通知ID | - | lable | 只读 | string | 是 | 通知标签 | - | callback | 只读 | AsyncCallback | 是 | 表示被指定的回调方法 | - - - 返回值 - - void - - - 示例代码 - - ```js - //cancel回调 - function cancelCallback(err) { - console.info("==========================>cancelCallback=======================>"); - } - Notification.cancel(0, "label", cancelCallback) - ``` - - - -- 取消指定通知(Promise形式) - - Notification.cancel(id:number, label?:string) - - - 参数描述 - - | 名称 | 读写属性 | 类型 | 必填 | 描述 | - | ----- | -------- | ------ | ---- | -------- | - | id | 只读 | number | 是 | 通知ID | - | lable | 只读 | string | 是 | 通知标签 | - - - 返回值 - - Promise<**void**> - - - 示例代码 - - ```js - Notification.cancel(0).then((void) => { - console.info("==========================>cancelCallback=======================>"); - }); - ``` - - - -- 取消指定id通知(callback形式) - - Notification.cancel(id: number, callback: AsyncCallback) - - - 参数描述 - - | 名称 | 读写属性 | 类型 | 必填 | 描述 | - | -------- | -------- | ------------------- | ---- | -------------------- | - | id | 只读 | number | 是 | 通知ID | - | callback | 只读 | AsyncCallback | 是 | 表示被指定的回调方法 | - - - 返回值 - - void - - - 示例代码 - - ```js - //cancel回调 - function cancelCallback(err) { - console.info("==========================>cancelCallback=======================>"); - } - Notification.cancel(0, cancelCallback) - ``` - - - -- 取消所有已发布的通知(callback形式) - - Notification.cancelAll(callback: AsyncCallback) - - - 参数描述 - - | 名称 | 读写属性 | 类型 | 必填 | 描述 | - | -------- | -------- | ------------------- | ---- | -------------------- | - | callback | 只读 | AsyncCallback | 是 | 表示被指定的回调方法 | - - - 返回值 - - void - - - 示例代码 - - ```js - //cancel回调 - function cancelAllback(err) { - console.info("==========================>cancelAllback=======================>"); - } - Notification.cancelAll(cancelCallback) - ``` - - - -- 取消所有已发布的通知(Promise形式) - - Notification.cancelAll() - - - 参数描述 - - 无参数 - - - 返回值 - - Promise - - - 示例代码 - - ```js - Notification.cancelAll().then((void) => { - ``` - - console.info("==========================>cancelAllback=======================>"); - }); - ``` - - - -##### 获取当前应用活动通知 - -- 获取当前应用的活动通知数(Callback形式) - - Notification.getActiveNotificationCount(callback: AsyncCallback<**number**>) - - - 参数描述 - - | 名称 | 读写属性 | 类型 | 必填 | 描述 | - | -------- | -------- | ------------------------- | ---- | ---------------------- | - | callback | 只读 | AsyncCallback<**number**> | 是 | 获取活动通知数回调函数 | - - - 返回值 - - void - - - 示例代码 - - ```js - function getActiveNotificationCountCallback(err, data) { - console.info("==========================>getActiveNotificationCountCallback=======================>"); - } - Notification.getActiveNotificationCount(getActiveNotificationCountCallback); - ``` - - - -- 获取当前应用的活动通知数(Promise形式) - - Notification.getActiveNotificationCount() - - - 参数描述 - - 无 - - - 返回值 - - Promise<**number**> - - - 示例代码 - - ```js - Notification.getActiveNotificationCount().then((data) => { - console.info("==========================>getActiveNotificationCountCallback=======================>"); - }); - ``` - - - -- 获取当前应用的活动通知(Callback形式) - - Notification.getActiveNotifications(callback: AsyncCallback>) - - - 参数描述 - - | 名称 | 读写属性 | 类型 | 必填 | 描述 | - | -------- | -------- | ----------------------------------------- | ---- | ------------------------------ | - | callback | 只读 | AsyncCallback> | 是 | 获取当前应用的活动通知回调函数 | - - - 返回值 - - void - - - 示例代码 - - ```js - function getActiveNotificationsCallback(err, data) { - console.info("==========================>getActiveNotificationsCallback=======================>"); - } - Notification.getActiveNotifications(getActiveNotificationsCallback); - ``` - - - -- 获取当前应用的活动通知(Promise形式) - - Notification.getActiveNotifications() - - - 参数描述 - - 无 - - - 返回值 - - Promise> - - - 示例代码 - - ```js - Notification.getActiveNotifications().then((data) => { - console.info("==========================>getActiveNotificationsCallback=======================>"); - }); - ``` - - - -#### WantAgent接口 - -##### 导入模块 - -```js -import WantAgent from '@ohos.wantAgent'; -``` - - - -##### WantAgentInfo类型说明 - -WantAgentInfo类封装了获取一个WantAgent实例所需的数据。 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| -------------- | -------- | ------------------------------- | ---- | ---------------------- | -| wants | 读、写 | Array | 是 | 将被执行的动作列表 | -| operationType | 读、写 | wantAgent.OperationType | 是 | 动作类型 | -| requestCode | 读、写 | number | 是 | 使用者定义的一个私有值 | -| wantAgentFlags | 读、写 | Array | 否 | 动作执行属性 | -| extraInfo | 读、写 | {[key: string]: any} | 否 | 额外数据 | - -- OperationType类型说明 - -| 名称 | 读写属性 | 类型 | 描述 | -| ----------------- | -------- | ---- | ----------------------- | -| UNKNOWN_TYPE | 只读 | enum | 不识别的类型 | -| START_ABILITY | 只读 | enum | 开启一个有页面的Ability | -| START_ABILITIES | 只读 | enum | 开启多个有页面的Ability | -| START_SERVICE | 只读 | enum | 开启一个无页面的ability | -| SEND_COMMON_EVENT | 只读 | enum | 发送一个公共事件 | - -- WantAgentFlags类型说明 - - -| 名称 | 读写属性 | 类型 | 描述 | -| ------------------- | -------- | ---- | ------------------------------------------------------------ | -| ONE_TIME_FLAG | 只读 | enum | WantAgent仅能使用一次 | -| NO_BUILD_FLAG | 只读 | enum | 如果描述WantAgent对象不存在,则不创建它,直接返回null | -| CANCEL_PRESENT_FLAG | 只读 | enum | 在生成一个新的WantAgent对象前取消已存在的一个WantAgent对象 | -| UPDATE_PRESENT_FLAG | 只读 | enum | 使用新的WantAgent的额外数据替换已存在的WantAgent中的额外数据 | -| CONSTANT_FLAG | 只读 | enum | WantAgent是不可变的 | -| REPLACE_ELEMENT | 只读 | enum | 当前Want中的element属性可被WantAgent.trigger()中Want的element属性取代 | -| REPLACE_ACTION | 只读 | enum | 当前Want中的action属性可被WantAgent.trigger()中Want的action属性取代 | -| REPLACE_URI | 只读 | enum | 当前Want中的uri属性可被WantAgent.trigger()中Want的uri属性取代 | -| REPLACE_ENTITIES | 只读 | enum | 当前Want中的entities属性可被WantAgent.trigger()中Want的entities属性取代 | -| REPLACE_BUNDLE | 只读 | enum | 当前Want中的bundleName属性可被WantAgent.trigger()中Want的bundleName属性取代 | - - - -##### TriggerInfo类型说明 - -TriggerInfo类封装了主动激发一个WantAgent实例所需的数据。 - -| 名称 | 读写属性 | 类型 | 必填 | 描述 | -| ---------- | -------- | -------------------- | ---- | ----------- | -| code | 读、写 | number | 是 | result code | -| want | 读、写 | Want | 否 | Want | -| permission | 读、写 | string | 否 | 权限定义 | -| extraInfo | 读、写 | {[key: string]: any} | 否 | 额外数据 | - - - -##### 创建WantAgent - -- 创建WantAgent(callback形式) - - WantAgent.getWantAgent(info: WantAgentInfo, callback: AsyncCallback) - - - 参数描述 - - | 名称 | 读写属性 | 类型 | 必填 | 描述 | - | -------- | -------- | ------------------------ | ---- | ----------------------- | - | info | 只读 | WantAgentInfo | 是 | WantAgent信息 | - | callback | 只读 | AsyncCallback | 是 | 创建WantAgent的回调方法 | - - 返回值 - - void - - - 示例代码 - - ```js - import wantAgent from '@ohos.wantAgent'; - import { OperationType, Flags } from '@ohos.wantagent'; - //getWantAgent回调 - function getWantAgentCallback(err, data) { - console.info("==========================>getWantAgentCallback=======================>"); - } - //WantAgentInfo对象 - var wantAgentInfo = { - wants: [ - { - deviceId: "deviceId", - bundleName: "com.neu.setResultOnAbilityResultTest1", - abilityName: "com.example.test.MainAbility", - action: "action1", - entities: ["entity1"], - type: "MIMETYPE", - uri: "key={true,true,false}", - parameters: - { - mykey0: 2222, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "ssssssssssssssssssssssssss", - mykey4: [false, true, false], - mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - mykey6: true, - } - } - ], - operationType: OperationType.START_ABILITIES, - requestCode: 0, - wantAgentFlags:[Flags.UPDATE_PRESENT_FLAG] - } - wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) - ``` - - - -- 创建WantAgent(Promise形式) - - WantAgent.getWantAgent(info: WantAgentInfo): Promise - - - 参数描述 - - | 名称 | 读写属性 | 类型 | 必填 | 描述 | - | ---- | -------- | ------------- | ---- | ------------- | - | info | 只读 | WantAgentInfo | 是 | WantAgent信息 | - - 返回值 - - Promise - - - 示例代码 - - ```js - import wantAgent from '@ohos.wantAgent'; - import { OperationType, Flags } from '@ohos.wantagent'; - //WantAgentInfo对象 - var wantAgentInfo = { - wants: [ - { - deviceId: "deviceId", - bundleName: "com.neu.setResultOnAbilityResultTest1", - abilityName: "com.example.test.MainAbility", - action: "action1", - entities: ["entity1"], - type: "MIMETYPE", - uri: "key={true,true,false}", - parameters: - { - mykey0: 2222, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "ssssssssssssssssssssssssss", - mykey4: [false, true, false], - mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - mykey6: true, - } - } - ], - operationType: OperationType.START_ABILITIES, - requestCode: 0, - wantAgentFlags:[Flags.UPDATE_PRESENT_FLAG] - } - wantAgent.getWantAgent(wantAgentInfo).then((data) => { - ``` - - console.info("==========================>getWantAgentCallback=======================>"); - }); - ``` - - - -##### 获取WantAgent实例的包名 - -- 获取WantAgent实例的包名(callback形式) - - WantAgent.getBundleName(agent: WantAgent, callback: AsyncCallback) - - - 参数描述 - - | 名称 | 读写属性 | 类型 | 必填 | 描述 | - | -------- | -------- | --------------------- | ---- | ---------------------------------------- | - | agent | 只读 | WantAgent | 是 | WantAgent对象 | - | callback | 只读 | AsyncCallback | 是 | 获取WantAgent指定的bundle name的回调方法 | - - - 返回值 - - void - - - 示例代码 - - ```js - import wantAgent from '@ohos.wantAgent'; - import { OperationType, Flags } from '@ohos.wantagent'; - //wantAgent对象 - var WantAgent; - //getWantAgent回调 - function getWantAgentCallback(err, data) { - console.info("==========================>getWantAgentCallback=======================>"); - if (err.code == 0) { - WantAgent = data; - } else { - console.info('----getWantAgent failed!----'); - } - } - //WantAgentInfo对象 - var wantAgentInfo = { - wants: [ - { - deviceId: "deviceId", - bundleName: "com.neu.setResultOnAbilityResultTest1", - abilityName: "com.example.test.MainAbility", - action: "action1", - entities: ["entity1"], - type: "MIMETYPE", - uri: "key={true,true,false}", - parameters: - { - mykey0: 2222, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "ssssssssssssssssssssssssss", - mykey4: [false, true, false], - mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - mykey6: true, - } - } - ], - operationType: OperationType.START_ABILITIES, - requestCode: 0, - wantAgentFlags:[Flags.UPDATE_PRESENT_FLAG] - } - wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) - //getBundleName回调 - function getBundleNameCallback(err, data) { - console.info("==========================>getBundleNameCallback=======================>"); - } - wantAgent.getBundleName(WantAgent, getBundleNameCallback) - ``` - - - -- 获取WantAgent实例的包名(Promise形式) - - WantAgent.getBundleName(agent: WantAgent): Promise - - - 参数描述 - - | 名称 | 读写属性 | 类型 | 必填 | 描述 | - | ----- | -------- | --------- | ---- | ------------- | - | agent | 只读 | WantAgent | 是 | WantAgent对象 | - - 返回值 - - Promise - - - 示例代码 - - ```js - import wantAgent from '@ohos.wantAgent'; - import { OperationType, Flags } from '@ohos.wantagent'; - //wantAgent对象 - var WantAgent; - //WantAgentInfo对象 - var wantAgentInfo = { - wants: [ - { - deviceId: "deviceId", - bundleName: "com.neu.setResultOnAbilityResultTest1", - abilityName: "com.example.test.MainAbility", - action: "action1", - entities: ["entity1"], - type: "MIMETYPE", - uri: "key={true,true,false}", - parameters: - { - mykey0: 2222, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "ssssssssssssssssssssssssss", - mykey4: [false, true, false], - mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - mykey6: true, - } - } - ], - operationType: OperationType.START_ABILITIES, - requestCode: 0, - wantAgentFlags:[Flags.UPDATE_PRESENT_FLAG] - } - wantAgent.getWantAgent(wantAgentInfo).then((data) => { - console.info("==========================>getWantAgentCallback=======================>"); - WantAgent = data; - }); - wantAgent.getBundleName(WantAgent).then((data) => { - console.info("==========================>getBundleNameCallback=======================>"); - }); - ``` - - - - -##### 获取WantAgent实例的用户ID - -- 获取WantAgent实例的用户ID(callback形式) - - WantAgent.getUid(agent: WantAgent, callback: AsyncCallback) - - - 参数描述 - - | 名称 | 读写属性 | 类型 | 必填 | 描述 | - | -------- | -------- | --------------------- | ---- | ----------------------------------- | - | agent | 只读 | WantAgent | 是 | WantAgent对象 | - | callback | 只读 | AsyncCallback | 是 | 获取WantAgent实例的用户ID的回调方法 | - - 返回值 - - void - - - 示例代码 - - ```js - import wantAgent from '@ohos.wantAgent'; - import { OperationType, Flags } from '@ohos.wantagent'; - - //wantAgent对象 - var WantAgent; - - //getWantAgent回调 - function getWantAgentCallback(err, data) { - console.info("==========================>getWantAgentCallback=======================>"); - if (err.code == 0) { - WantAgent = data; - } else { - console.info('----getWantAgent failed!----'); - } - } - //WantAgentInfo对象 - var wantAgentInfo = { - wants: [ - { - deviceId: "deviceId", - bundleName: "com.neu.setResultOnAbilityResultTest1", - abilityName: "com.example.test.MainAbility", - action: "action1", - entities: ["entity1"], - type: "MIMETYPE", - uri: "key={true,true,false}", - parameters: - { - mykey0: 2222, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "ssssssssssssssssssssssssss", - mykey4: [false, true, false], - mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - mykey6: true, - } - } - ], - operationType: OperationType.START_ABILITIES, - requestCode: 0, - wantAgentFlags:[Flags.UPDATE_PRESENT_FLAG] - } - - wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) - - //getUid回调 - function getUidCallback(err, data) { - console.info("==========================>getUidCallback=======================>"); - } - wantAgent.getUid(WantAgent, getUidCallback) - ``` - - - -- 获取WantAgent实例的用户ID(Promise形式) - - WantAgent.getUid(agent: WantAgent): Promise - - - 参数描述 - - | 名称 | 读写属性 | 类型 | 必填 | 描述 | - | ----- | -------- | --------- | ---- | ------------- | - | agent | 只读 | WantAgent | 是 | WantAgent对象 | - - 返回值 - - Promise - - - 示例代码 - - ```js - import wantAgent from '@ohos.wantAgent'; - import { OperationType, Flags } from '@ohos.wantagent'; - - //wantAgent对象 - var WantAgent; - - //WantAgentInfo对象 - var wantAgentInfo = { - wants: [ - { - deviceId: "deviceId", - bundleName: "com.neu.setResultOnAbilityResultTest1", - abilityName: "com.example.test.MainAbility", - action: "action1", - entities: ["entity1"], - type: "MIMETYPE", - uri: "key={true,true,false}", - parameters: - { - mykey0: 2222, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "ssssssssssssssssssssssssss", - mykey4: [false, true, false], - mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - mykey6: true, - } - } - ], - operationType: OperationType.START_ABILITIES, - requestCode: 0, - wantAgentFlags:[Flags.UPDATE_PRESENT_FLAG] - } - - wantAgent.getWantAgent(wantAgentInfo).then((data) => { - console.info("==========================>getWantAgentCallback=======================>"); - WantAgent = data; - }); - - wantAgent.getUid(WantAgent).then((data) => { - console.info("==========================>getUidCallback=======================>"); - }); - ``` - - - -##### 取消WantAgent实例 - -- 取消WantAgent实例(callback形式) - - WantAgent.cancel(agent: WantAgent, callback: AsyncCallback) - - - 参数描述 - - | 名称 | 读写属性 | 类型 | 必填 | 描述 | - | -------- | -------- | ------------------- | ---- | --------------------------- | - | agent | 只读 | WantAgent | 是 | WantAgent对象 | - | callback | 只读 | AsyncCallback | 是 | 取消WantAgent实例的回调方法 | - - 返回值 - - void - - - 示例代码 - - ```js - import wantAgent from '@ohos.wantAgent'; - import { OperationType, Flags } from '@ohos.wantagent'; - - //wantAgent对象 - var WantAgent; - - //getWantAgent回调 - function getWantAgentCallback(err, data) { - console.info("==========================>getWantAgentCallback=======================>"); - if (err.code == 0) { - WantAgent = data; - } else { - console.info('----getWantAgent failed!----'); - } - } - //WantAgentInfo对象 - var wantAgentInfo = { - wants: [ - { - deviceId: "deviceId", - bundleName: "com.neu.setResultOnAbilityResultTest1", - abilityName: "com.example.test.MainAbility", - action: "action1", - entities: ["entity1"], - type: "MIMETYPE", - uri: "key={true,true,false}", - parameters: - { - mykey0: 2222, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "ssssssssssssssssssssssssss", - mykey4: [false, true, false], - mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - mykey6: true, - } - } - ], - operationType: OperationType.START_ABILITIES, - requestCode: 0, - wantAgentFlags:[Flags.UPDATE_PRESENT_FLAG] - } - - wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) - - //cancel回调 - function cancelCallback(err, data) { - console.info("==========================>cancelCallback=======================>"); - } - wantAgent.cancel(WantAgent, cancelCallback) - ``` - - - -- 取消WantAgent实例(Promise形式) - - WantAgent.cancel(agent: WantAgent): Promise - - - 参数描述 - - | 名称 | 读写属性 | 类型 | 必填 | 描述 | - | ----- | -------- | --------- | ---- | ------------- | - | agent | 只读 | WantAgent | 是 | WantAgent对象 | - - 返回值 - - Promise - - - 示例代码 - - ```js - import wantAgent from '@ohos.wantAgent'; - import { OperationType, Flags } from '@ohos.wantagent'; - - //wantAgent对象 - var WantAgent; - - //WantAgentInfo对象 - var wantAgentInfo = { - wants: [ - { - deviceId: "deviceId", - bundleName: "com.neu.setResultOnAbilityResultTest1", - abilityName: "com.example.test.MainAbility", - action: "action1", - entities: ["entity1"], - type: "MIMETYPE", - uri: "key={true,true,false}", - parameters: - { - mykey0: 2222, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "ssssssssssssssssssssssssss", - mykey4: [false, true, false], - mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - mykey6: true, - } - } - ], - operationType: OperationType.START_ABILITIES, - requestCode: 0, - wantAgentFlags:[Flags.UPDATE_PRESENT_FLAG] - } - - wantAgent.getWantAgent(wantAgentInfo).then((data) => { - console.info("==========================>getWantAgentCallback=======================>"); - WantAgent = data; - }); - - wantAgent.cancel(WantAgent).then((data) => { - console.info("==========================>cancelCallback=======================>"); - }); - ``` - - - - -##### 主动激发WantAgent实例 - -- 主动激发WantAgent实例(callback形式) - - WantAgent.trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: Callback) - - - 参数描述 - - | 名称 | 读写属性 | 类型 | 必填 | 描述 | - | ----------- | -------- | --------------------------- | ---- | ------------------------------- | - | agent | 只读 | WantAgent | 是 | WantAgent对象 | - | triggerInfo | 只读 | TriggerInfo | 是 | TriggerInfo对象 | - | callback | 只读 | AsyncCallback | 是 | 主动激发WantAgent实例的回调方法 | - - 返回值 - - void - - - 示例代码 - - ```js - import wantAgent from '@ohos.wantAgent'; - import { OperationType, Flags } from '@ohos.wantagent'; - - //wantAgent对象 - var WantAgent; - - //getWantAgent回调 - function getWantAgentCallback(err, data) { - console.info("==========================>getWantAgentCallback=======================>"); - if (err.code == 0) { - WantAgent = data; - } else { - console.info('----getWantAgent failed!----'); - } - } - //WantAgentInfo对象 - var wantAgentInfo = { - wants: [ - { - deviceId: "deviceId", - bundleName: "com.neu.setResultOnAbilityResultTest1", - abilityName: "com.example.test.MainAbility", - action: "action1", - entities: ["entity1"], - type: "MIMETYPE", - uri: "key={true,true,false}", - parameters: - { - mykey0: 2222, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "ssssssssssssssssssssssssss", - mykey4: [false, true, false], - mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - mykey6: true, - } - } - ], - operationType: OperationType.START_ABILITIES, - requestCode: 0, - wantAgentFlags:[Flags.UPDATE_PRESENT_FLAG] - } - - wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) - - //cancel回调 - function triggerCallback(err, data) { - console.info("==========================>triggerCallback=======================>"); - } - wantAgent.trigger(WantAgent, triggerCallback) - ``` - - - - -##### 判断两个WantAgent实例是否相等 - -- 判断两个WantAgent实例是否相等(callback形式) - - WantAgent.equal(agent: WantAgent, otherAgent: WantAgent, callback: AsyncCallback) - - - 参数描述 - - | 名称 | 读写属性 | 类型 | 必填 | 描述 | - | ---------- | -------- | ---------------------- | ---- | --------------------------------------- | - | agent | 只读 | WantAgent | 是 | WantAgent对象 | - | otherAgent | 只读 | WantAgent | 是 | WantAgent对象 | - | callback | 只读 | AsyncCallback | 是 | 判断两个WantAgent实例是否相等的回调方法 | - - 返回值 - - void - - - 示例代码 - - ```js - import wantAgent from '@ohos.wantAgent'; - import { OperationType, Flags } from '@ohos.wantagent'; - - //wantAgent对象 - var WantAgent1; - var WantAgent2; - - //getWantAgent回调 - function getWantAgentCallback(err, data) { - console.info("==========================>getWantAgentCallback=======================>"); - if (err.code == 0) { - WantAgent1 = data; - WantAgent2 = data; - } else { - console.info('----getWantAgent failed!----'); - } - } - //WantAgentInfo对象 - var wantAgentInfo = { - wants: [ - { - deviceId: "deviceId", - bundleName: "com.neu.setResultOnAbilityResultTest1", - abilityName: "com.example.test.MainAbility", - action: "action1", - entities: ["entity1"], - type: "MIMETYPE", - uri: "key={true,true,false}", - parameters: - { - mykey0: 2222, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "ssssssssssssssssssssssssss", - mykey4: [false, true, false], - mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - mykey6: true, - } - } - ], - operationType: OperationType.START_ABILITIES, - requestCode: 0, - wantAgentFlags:[Flags.UPDATE_PRESENT_FLAG] - } - - wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) - - //cancel回调 - function equalCallback(err, data) { - console.info("==========================>equalCallback=======================>"); - } - wantAgent.equal(WantAgent1, WantAgent1, equalCallback) - ``` - - - -- 判断两个WantAgent实例是否相等(Promise形式) - - WantAgent.equal(agent: WantAgent, otherAgent: WantAgent): Promise - - - 参数描述 - - | 名称 | 读写属性 | 类型 | 必填 | 描述 | - | ---------- | -------- | --------- | ---- | ------------- | - | agent | 只读 | WantAgent | 是 | WantAgent对象 | - | otherAgent | 只读 | WantAgent | 是 | WantAgent对象 | - - 返回值 - - Promise - - - 示例代码 - - ```js - import wantAgent from '@ohos.wantAgent'; - import { OperationType, Flags } from '@ohos.wantagent'; - - //wantAgent对象 - var WantAgent1; - var WantAgent2; - - //WantAgentInfo对象 - var wantAgentInfo = { - wants: [ - { - deviceId: "deviceId", - bundleName: "com.neu.setResultOnAbilityResultTest1", - abilityName: "com.example.test.MainAbility", - action: "action1", - entities: ["entity1"], - type: "MIMETYPE", - uri: "key={true,true,false}", - parameters: - { - mykey0: 2222, - mykey1: [1, 2, 3], - mykey2: "[1, 2, 3]", - mykey3: "ssssssssssssssssssssssssss", - mykey4: [false, true, false], - mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], - mykey6: true, - } - } - ], - operationType: OperationType.START_ABILITIES, - requestCode: 0, - wantAgentFlags:[Flags.UPDATE_PRESENT_FLAG] - } - - wantAgent.getWantAgent(wantAgentInfo).then((data) => { - console.info("==========================>getWantAgentCallback=======================>"); - WantAgent = data; - }); - - wantAgent.equal(WantAgent1, WantAgent2).then((data) => { - console.info("==========================>equalCallback=======================>"); - }); - ``` - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/website/docs/_posts/zh-cn/application-dev/ability/page-ability.md b/website/docs/_posts/zh-cn/application-dev/ability/page-ability.md deleted file mode 100644 index 4b54add07752ed61a5ecc76d30492ed58faf3c80..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/ability/page-ability.md +++ /dev/null @@ -1,140 +0,0 @@ ---- -title: page-ability -permalink: /pages/extra/c12bc9/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# PageAbility开发说明 - -## PageAbility介绍 - -Page模板(以下简称“Page”)是FA唯一支持的模板,用于提供与用户交互的能力。 - -## PageAbility的生命周期 - -**Ability生命周期介绍**(Ability Life Cycle)是Ability被调度到INACTIVE、ACTIVE、BACKGROUND等各个状态的统称(主要涉及PageAbility类型和ServiceAbility类型的Ability)。 - - - **PageAbility类型的Ability生命周期流转如下图所示** - -![PageAbility-Lifecycle](/images/application-dev/ability/figures/page-ability-lifecycle.png) - - -**Ability生命周期状态说明:** - - - **UNINITIALIZED**:未初始状态,为临时状态,Ability被创建后会由UNINITIALIZED状态进入INITIAL状态。 - - - **INITIAL**:初始化状态,也表示停止状态,表示当前Ability未运行,Ability被启动后由INITIAL态进入INACTIVE状态。 - - - **INACTIVE**:未激活状态,表示当前窗口已显示但是无焦点状态,由于Window暂未支持焦点的概念,当前状态与ACTIVE一致。 - - - **ACTIVE**:前台激活状态,表示当前窗口已显示,并获取焦点,Ability在退到后台之前先由ACTIVE状态进入INACTIVE状态。 - - - **BACKGROUND**: 后台状态,表示当前Ability退到后台,Ability在被销毁后由BACKGROUND状态进入INITIAL状态,或者重新被激活后由BACKGROUND状态进入ACTIVE状态。 - -**PageAbility类型Ability生命周期回调如下图所示:** - -![PageAbility-Lifecycel-Callbacks](/images/application-dev/ability/figures/page-ability-lifecycle-callbacks.png) - - - -## 启动本地PageAbility - - 导入模块 - -``` -import featureAbility from '@ohos.ability.featureAbility' -``` -``` - FeatureAbility.startAbility(parameter: StartAbilityParameter, callback: AsyncCallback) -``` - -* 接口说明 - - 启动新的ability(callback形式) - -* 示例 - -```javascript -import featureAbility from '@ohos.ability.featureAbility' -featureAbility.startAbility( - { - want: - { - action: "", - entities: [""], - type: "", - options: { - // indicates the grant to perform read operations on the URI - authReadUriPermission: true, - // indicates the grant to perform write operations on the URI - authWriteUriPermission: true, - // support forward intent result to origin ability - abilityForwardResult: true, - // used for marking the ability start-up is triggered by continuation - abilityContinuation: true, - // specifies whether a component does not belong to ohos - notOhosComponent: true, - // specifies whether an ability is started - abilityFormEnabled: true, - // indicates the grant for possible persisting on the URI. - authPersistableUriPermission: true, - // indicates the grant for possible persisting on the URI. - authPrefixUriPermission: true, - // support distributed scheduling system start up multiple devices - abilitySliceMultiDevice: true, - // indicates that an ability using the service template is started regardless of whether the - // host application has been started. - startForegroundAbility: true, - // install the specified ability if it's not installed. - installOnDemand: true, - // return result to origin ability slice - abilitySliceForwardResult: true, - // install the specified ability with background mode if it's not installed. - installWithBackgroundMode: true - }, - deviceId: "", - bundleName: "com.example.startability", - abilityName: "com.example.startability.MainAbility", - uri: "" - }, - }, - ); -) -``` -## 启动远程PageAbility - - 导入模块 - -``` -import featureAbility from '@ohos.ability.featureAbility' -``` - -``` -FeatureAbility.startAbility(parameter: StartAbilityParameter) -``` -* 接口说明 - - 启动远程的ability(promise形式) - 前提:通过deviceManager获取远程deviceid - -* 示例 - -```javascript - var promise = await ability.startAbility( - { - want: - { - deviceId: this.deviceId, - bundleName: "com.example.test", - abilityName: "com.example.test.MainAbility", - }, - } - ); -``` \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/ability/service-ability.md b/website/docs/_posts/zh-cn/application-dev/ability/service-ability.md deleted file mode 100644 index 658b321d98da2c0a22aac059c13f50e8f6c193e8..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/ability/service-ability.md +++ /dev/null @@ -1,279 +0,0 @@ ---- -title: service-ability -permalink: /pages/extra/9644e5/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# ServiceAbility开发说明 - -## 创建Service - -1. Service也是一种Ability,Ability为Service提供了以下生命周期方法,开发者可以重写这些方法,来添加其他Ability请求与Service Ability交互时的处理方法。 - - - onStart() - - 该方法在创建Service的时候调用,用于Service的初始化。在Service的整个生命周期只会调用一次,调用时传入的Want应为空。 - - - onCommand() - - 在Service创建完成之后调用,该方法在客户端每次启动该Service时都会调用,开发者可以在该方法中做一些调用统计、初始化类的操作。 - - - onConnect() - - 在Ability和Service连接时调用,该方法返回IRemoteObject对象,开发者可以在该回调函数中生成对应Service的IPC通信通道,以便Ability与Service交互。Ability可以多次连接同一个Service,系统会缓存该Service的IPC通信对象,只有第一个客户端连接Service时,系统才会调用Service的onConnect方法来生成IRemoteObject对象,而后系统会将同一个IRemoteObject对象传递至其他连接同一个Service的所有客户端,而无需再次调用onConnect方法。 - - - onDisconnect() - - 在Ability与绑定的Service断开连接时调用。 - - - onStop() - - 在Service销毁时调用。Service应通过实现此方法来清理任何资源,如关闭线程、注册的侦听器等。 - - 创建Service的代码示例如下: - - ```javascript - export default { - onStart(want) { - console.log('SerivceAbility onStart'); - }, - onCommand(want, restart, startId) { - console.log('SerivceAbility onCommand'); - }, - onConnect(want) { - console.log('SerivceAbility OnConnect'); - }, - onDisconnect() { - console.log('SerivceAbility OnDisConnect'); - }, - onStop() { - console.log('SerivceAbility onStop'); - }, - } - ``` - -2. 注册Service。 - - Service也需要在应用配置文件config.json中进行注册,注册类型type需要设置为service。 - - ```javascript - { - "module": { - "abilities": [ - { - "name": ".ServiceAbility", - "type": "service", - "visible": true - ... - } - ] - ... - } - ... - } - ``` - - - - -## 启动Service - -Ability为开发者提供了startAbility()方法来启动另外一个Ability。因为Service也是Ability的一种,开发者同样可以通过将Want传递给该方法来启动Service。 - -开发者可以通过构造包含BundleName与AbilityName的Want对象来设置目标Service信息。参数的含义如下: - -- BundleName:表示包名称。 -- AbilityName:表示待启动的Ability名称。 - -启动本地设备Service的代码示例如下: - -```javascript -import featureAbility from '@ohos.ability.featureability'; -var promise = await featureAbility.startAbility( - { - want: - { - bundleName: "com.jstest.serviceability", - abilityName: "com.jstest.serviceability.MainAbility", - }, - } -); -``` - -- 执行上述代码后,Ability将通过startAbility() 方法来启动Service。 - - 如果Service尚未运行,则系统会先调用onStart()来初始化Service,再回调Service的onCommand()方法来启动Service。 - - 如果Service正在运行,则系统会直接回调Service的onCommand()方法来启动Service。 - -- 停止Service - - Service一旦创建就会一直保持在后台运行,除非必须回收内存资源,否则系统不会停止或销毁Service。开发者可以在Service中通过terminateAbility()停止本Service或在其他Ability调用stopAbility()来停止Service。 - - - -## 连接本地Service - -如果Service需要与Page Ability或其他应用的Service Ability进行交互,则须创建用于连接的Connection。Service支持其他Ability通过connectAbility()方法与其进行连接。 - -在使用connectAbility()处理回调时,需要传入目标Service的Want与IAbilityConnection的实例。IAbilityConnection提供了以下方法供开发者实现:onConnect()是用来处理连接Service成功的回调,onDisconnect()是用来处理Service异常死亡的回调,onFailed()是用来处理连接Service失败的回调。 - -创建连接本地Service回调实例的代码示例如下: - -```javascript -var mRemote; -function onConnectCallback(element, remote){ - console.log('ConnectAbility onConnect Callback') - mRemote = remote; -} - -function onDisconnectCallback(element){ - console.log('ConnectAbility onDisconnect Callback') -} - -function onFailedCallback(code){ - console.log('ConnectAbility onFailed Callback') -} -``` - -连接本地Service的代码示例如下: - -```javascript -import featureAbility from '@ohos.ability.featureability'; -var connId = featureAbility.connectAbility( - { - bundleName: "com.jstest.serviceability", - abilityName: "com.jstest.serviceability.MainAbility", - }, - { - onConnect: onConnectCallback, - onDisconnect: onDisconnectCallback, - onFailed: onFailedCallback, - }, -); -``` - -同时,Service侧也需要在onConnect()时返回IRemoteObject,从而定义与Service进行通信的接口。onConnect()需要返回一个IRemoteObject对象,OpenHarmony提供了IRemoteObject的默认实现,用户可以通过继承rpc.RemoteObject来创建自定义的实现类。 - -Service侧把自身的实例返回给调用侧的代码示例如下: - -```javascript -import rpc from "@ohos.rpc"; - -var mMyStub; -export default { - onStart(want) { - class MyStub extends rpc.RemoteObject{ - constructor(des) { - if (typeof des === 'string') { - super(des); - } - return null; - } - onRemoteRequest(code, message, reply, option) { - } - } - mMyStub = new MyStub("ServiceAbility-test"); - }, - onCommand(want, restart, startId) { - console.log('SerivceAbility onCommand'); - }, - onConnect(want) { - console.log('SerivceAbility OnConnect'); - return mMyStub; - }, - onDisconnect() { - console.log('SerivceAbility OnDisConnect'); - }, - onStop() { - console.log('SerivceAbility onStop'); - }, -} -``` - -## 连接远程Service - -如果Service需要与Page Ability或其他应用的Service Ability进行跨设备交互,则须创建用于连接的Connection。Service支持其他Ability通过connectAbility()方法与其进行跨设备连接。 - -在使用connectAbility()处理回调时,需要传入目标Service的Want与IAbilityConnection的实例。IAbilityConnection提供了以下方法供开发者实现:onConnect()是用来处理连接Service成功的回调,onDisconnect()是用来处理Service异常死亡的回调,onFailed()是用来处理连接Service失败的回调。 - -创建连接远程Service回调实例的代码示例如下: - -```javascript -var mRemote; -function onConnectCallback(element, remote){ - console.log('ConnectRemoteAbility onConnect Callback') - mRemote = remote; -} - -function onDisconnectCallback(element){ - console.log('ConnectRemoteAbility onDisconnect Callback') -} - -function onFailedCallback(code){ - console.log('ConnectRemoteAbility onFailed Callback') -} -``` - -目标Service的Want需要包含远程deviceId,该远程deviceId可通过deviceManager获取。 - -连接远程Service的代码示例如下: - -```javascript -import featureAbility from '@ohos.ability.featureability'; -var connId = featureAbility.connectAbility( - { - deviceId: deviceId, - bundleName: "com.jstest.serviceability", - abilityName: "com.jstest.serviceability.MainAbility", - }, - { - onConnect: onConnectCallback, - onDisconnect: onDisconnectCallback, - onFailed: onFailedCallback, - }, -); -``` - -同时,Service侧也需要在onConnect()时返回IRemoteObject,从而定义与Service进行通信的接口。onConnect()需要返回一个IRemoteObject对象,OpenHarmony提供了IRemoteObject的默认实现,用户可以通过继承rpc.RemoteObject来创建自定义的实现类。 - -Service侧把自身的实例返回给调用侧的代码示例如下: - -```javascript -import rpc from "@ohos.rpc"; - -var mMyStub; -export default { - onStart(want) { - class MyStub extends rpc.RemoteObject{ - constructor(des) { - if (typeof des === 'string') { - super(des); - } - return null; - } - onRemoteRequest(code, message, reply, option) { - } - } - mMyStub = new MyStub("ServiceAbility-test"); - }, - onCommand(want, restart, startId) { - console.log('SerivceAbility onCommand'); - }, - onConnect(want) { - console.log('SerivceAbility OnConnect'); - return mMyStub; - }, - onDisconnect() { - console.log('SerivceAbility OnDisConnect'); - }, - onStop() { - console.log('SerivceAbility onStop'); - }, -} -``` \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/application-dev-guide.md b/website/docs/_posts/zh-cn/application-dev/application-dev-guide.md deleted file mode 100644 index 79fc6bb4f463ecfb4a0c48362607d31a92cc9a35..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/application-dev-guide.md +++ /dev/null @@ -1,23 +0,0 @@ ---- -title: application-dev-guide -permalink: /pages/extra/e59705/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 应用开发导读 - -应用开发文档用于指导开发者通过OpenHarmony提供的接口完成应用开发。当前应用开发文档提供了在标准系统上开发应用的JS接口。 - -在这部分中,开发者可以通过“[入门](/pages/extra/82bbc8/)”来了解应用开发的基本方法。完整的接口清单和参考使用指导可参见“[开发参考](/pages/extra/23166e/)”。 - -除此之外,为方便开发者对常用功能进行深入理解,还提供了[UI](/pages/extra/91bbde/)、[媒体](/pages/extra/504ad4/)、[网络与连接](/pages/extra/30f113/)三个模块的开发指南。 - -如果需要了解各子系统的原理和基本信息,可以参考“docs/zh-cn/readme”目录中各子系统readme的介绍。 - diff --git a/website/docs/_posts/zh-cn/application-dev/background-agent-scheduled-reminder/Readme-CN.md b/website/docs/_posts/zh-cn/application-dev/background-agent-scheduled-reminder/Readme-CN.md deleted file mode 100644 index 6b392b9025a662e2b48bdcedcf0dabd5c897cb08..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/background-agent-scheduled-reminder/Readme-CN.md +++ /dev/null @@ -1,17 +0,0 @@ ---- -title: Readme-CN -permalink: /pages/extra/dff9d1/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 后台代理提醒 - -- [概述](/pages/extra/97f505/) -- [开发指导](/pages/extra/4e65d6/) diff --git a/website/docs/_posts/zh-cn/application-dev/background-agent-scheduled-reminder/background-agent-scheduled-reminder-guide.md b/website/docs/_posts/zh-cn/application-dev/background-agent-scheduled-reminder/background-agent-scheduled-reminder-guide.md deleted file mode 100644 index cef6ae01c6e688dfc985f2e40dd32468f01dbafa..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/background-agent-scheduled-reminder/background-agent-scheduled-reminder-guide.md +++ /dev/null @@ -1,280 +0,0 @@ ---- -title: background-agent-scheduled-reminder-guide -permalink: /pages/extra/4e65d6/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 开发指导 - -## 场景介绍 - -后台代理提醒主要提供后台提醒发布接口,开发者在应用开发时,可以调用这些接口去创建定时提醒,包括倒计时、日历、闹钟三种提醒类型。使用后台代理提醒能力后,应用可以被冻结或退出,计时和弹出提醒的功能将被后台系统服务代理。 - - -## 接口说明 - -reminderAgent:封装了发布、取消提醒类通知的方法 - -**表1** reminderAgent主要接口 - -| 接口名 | 描述 | -| -------- | -------- | -| function publishReminder(reminderReq: ReminderRequest, callback: AsyncCallback<number>): void;
function publishReminder(reminderReq: ReminderRequest): Promise<number>; | 发布一个定时提醒类通知。
单个应用有效的提醒个数最多支持30个(不包括已经超时,即后续不会再提醒的提醒实例)
整个系统有效的提醒个数最多支持2000个(不包括已经超时,即后续不会再提醒的提醒实例) | -| function cancelReminder(reminderId: number, callback: AsyncCallback<void>): void;
function cancelReminder(reminderId: number): Promise<void>; | 取消一个指定的提醒类通知。(reminderId从publishReminder的返回值获取) | -| function getValidReminders(callback: AsyncCallback<Array<ReminderRequest>>): void;
function getValidReminders(): Promise<Array<ReminderRequest>>; | 获取当前应用设置的所有有效的提醒。 | -| function cancelAllReminders(callback: AsyncCallback<void>): void;
function cancelAllReminders(): Promise<void>; | 取消当前应用设置的所有提醒 | -| function addNotificationSlot(slot: NotificationSlot, callback: AsyncCallback<void>): void;
function addNotificationSlot(slot: NotificationSlot): Promise<void>; | 注册一个提醒类需要使用的NotificationSlot | -| function removeNotificationSlot(slotType: notification.SlotType, callback: AsyncCallback<void>): void;
function removeNotificationSlot(slotType: notification.SlotType): Promise<void>; | 删除指定类型的NotificationSlot | - -enum ActionButtonType: 在提醒弹出的通知界面上的按钮的类型。 - -**表2** ActionButtonType 枚举类型 - -| 枚举名 | 描述 | -| -------- | -------- | -| ACTION_BUTTON_TYPE_CLOSE | 指明是close按钮,点击后关闭当前提醒的铃声(如果正在响铃),关闭提醒的通知,取消延迟提醒。 | - -enum ReminderType: 提醒类型 - -**表3** ReminderType 提醒类型枚举 - -| 枚举名 | 描述 | -| -------- | -------- | -| REMINDER_TYPE_TIMER | 指明是倒计时类型 | -| REMINDER_TYPE_CALENDAR | 指明是日历类型 | -| REMINDER_TYPE_ALARM | 指明是闹钟类型 | - -interface ActionButton:在提醒弹出的通知界面上的按钮实例 - -**表4** ActionButton - -| 参数名 | 类型 | 必填 | 描述 | -| -------- | -------- | -------- | -------- | -| title | string | 是 | 按钮上显示的名称 | -| type | ActionButtonType | 是 | 按钮的类型 | - -interface WantAgent: 设置点击通知后需要跳转的目标ability信息 - -**表5** WantAgent - -| 参数名 | 类型 | 是否必选 | 描述 | -| -------- | -------- | -------- | -------- | -| pkgName | string | 是 | 目标包的名称 | -| abilityName | string | 是 | 目标ability的名称 | - -interface MaxScreenWantAgent: 设置提醒到达时跳转的目标包。如果设备正在使用中,则弹出一个通知框 - -**表6** MaxScreenWantAgent - -| 参数名 | 类型 | 必填 | 描述 | -| -------- | -------- | -------- | -------- | -| pkgName | string | 是 | 目标包的名称 | -| abilityName | string | 是 | 目标ability的名称 | - -interface ReminderRequest: 需要发布的提醒实例的信息 - -**表7** ReminderRequest - -| 参数名 | 类型 | 必填 | 描述 | -| -------- | -------- | -------- | -------- | -| reminderType | ReminderType | 是 | 提醒的类型 | -| actionButton | [ActionButton?,ActionButton?] | 否 | 弹出的提醒通知栏中显示的按钮 | -| wantAgent | WantAgent | 否 | 点击通知后需要跳转的目标ability信息 | -| maxScreenWantAgent | MaxScreenWantAgent | 否 | 提醒到达时跳转的目标包。如果设备正在使用中,则弹出一个通知框 | -| ringDuration | number | 否 | 响铃时长 | -| snoozeTimes | number | 否 | 延迟提醒次数 | -| timeInterval | number | 否 | 延迟提醒间隔 | -| title | string | 否 | 提醒的标题 | -| content | string | 否 | 提醒的内容 | -| expiredContent | string | 否 | 提醒“过期”时显示的扩展内容 | -| snoozeContent | string | 否 | 提醒“再响”时显示的扩展内容 | -| notificationId | number | 否 | 提醒使用的notificationRequest的id,参见NotificationRequest.setNotificationId(int id) | -| slotType | SlotType | 否 | 提醒使用的slot类型 | - -interface ReminderRequestCalendar extends ReminderRequest: 日历类提醒实例。 - -第一次指定的目标时间必须大于当前时间。 - -**表8** ReminderRequestCalendar - -| 参数名 | 类型 | 必填 | 描述 | -| -------- | -------- | -------- | -------- | -| dateTime | LocalDataTime | 是 | 设置目标时间 | -| repeatMonths | Array<number> | 否 | 设置重复提醒的月份 | -| repeatDays | Array<number> | 否 | 设置重复提醒的日期 | - -interface ReminderRequestAlarm extends ReminderRequest: 闹钟类提醒实例。 - -**表9** ReminderRequestAlarm - -| 参数名 | 类型 | 必填 | 描述 | -| -------- | -------- | -------- | -------- | -| hour | number | 是 | 设置目标时间(小时) | -| minute | number | 是 | 设置目标时间(分钟) | -| daysOfWeek | Array<number> | 否 | 设置每个星期哪一天重复提醒 | - -interface ReminderRequestTimer extends ReminderRequest:倒计时提醒实例 - -**表10** ReminderRequestTimer - -| 参数名 | 类型 | 必填 | 描述 | -| -------- | -------- | -------- | -------- | -| triggerTimeInSeconds | number | 是 | 设置倒计时秒数 | - -interface LocalDateTime:时间信息实例 - -**表11** LocalDateTime - -| 参数名 | 类型 | 必填 | 描述 | -| -------- | -------- | -------- | -------- | -| year | number | 是 | 年 | -| month | number | 是 | 月 | -| day | number | 是 | 日 | -| hour | number | 是 | 时 | -| minute | number | 是 | 分 | -| second | number | 否 | 秒 | - - -## 开发步骤 - -> ![icon-note.gif](/images/application-dev/background-agent-scheduled-reminder/public_sys-resources/icon-note.gif) **说明:** -> 应用需要配置权限:ohos.permission.PUBLISH_AGENT_REMINDER - -发布一个10秒倒计时提醒 - -1. 定义一个倒计时实例 - ``` - import reminderAgent from '@ohos.reminderAgent'; - import notification from '@ohos.notification';export default { - timer: { - reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER, - triggerTimeInSeconds: 10, - actionButton: [ - { - title: "close", - type: reminderAgent.ActionButtonType.ACTION_BUTTON_TYPE_CLOSE - } - ], - wantAgent: { - pkgName: "com.example.phone", - abilityName: "com.example.phone.MainAbility" - }, - maxScreenWantAgent: { - pkgName: "com.example.phone", - abilityName: "com.example.phone.MainAbility" - }, - title: "this is title", - content: "this is content", - expiredContent: "this reminder has expired", - notificationId: 100, - slotType: notification.SlotType.SOCIAL_COMMUNICATION - } - } - ``` - -2. 发布提醒 - ``` - startTimer() { - reminderAgent.publishReminder(this.timer, (err, reminderId) =>{ - this.printInfo(JSON.stringify(err)); - this.printInfo("reminderId:" + reminderId); - }); - } - ``` - - html页面: - ``` -
- -
- ``` - -日历实例定义: - -``` -calendar: { - reminderType: reminderAgent.ReminderType.REMINDER_TYPE_CALENDAR, - dateTime: { - year: 2050, - month: 7, - day: 30, - hour: 11, - minute: 14, - second: 30 - }, - repeatMonths: [0], - repeatDays: [0], - actionButton: [ - { - title: "close", - type: reminderAgent.ActionButtonType.ACTION_BUTTON_TYPE_CLOSE - }, - { - title: "snooze", - type: reminderAgent.ActionButtonType.ACTION_BUTTON_TYPE_SNOOZE - }, - ], - wantAgent: { - pkgName: "com.example.phone", - abilityName: "com.example.phone.MainAbility" - }, - maxScreenWantAgent: { - pkgName: "com.example.phone", - abilityName: "com.example.phone.MainAbility" - }, - ringDuration: 5, - snoozeTimes: 2, - timeInterval: 5, - title: "this is title", - content: "this is content", - expiredContent: "this reminder has expired", - snoozeContent: "remind later", - notificationId: 100, - slotType: notification.SlotType.SOCIAL_COMMUNICATION -} -``` - -闹钟实例定义: - -``` -alarm: { - reminderType: reminderAgent.ReminderType.REMINDER_TYPE_ALARM, - hour: 11, - minute: 14, - daysOfWeek: [0], - actionButton: [ - { - title: "close", - type: reminderAgent.ActionButtonType.ACTION_BUTTON_TYPE_CLOSE - }, - { - title: "snooze", - type: reminderAgent.ActionButtonType.ACTION_BUTTON_TYPE_SNOOZE - }, - ], - wantAgent: { - pkgName: "com.example.phone", - abilityName: "com.example.phone.MainAbility" - }, - maxScreenWantAgent: { - pkgName: "com.example.phone", - abilityName: "com.example.phone.MainAbility" - }, - ringDuration: 5, - snoozeTimes: 2, - timeInterval: 5, - title: "this is title", - content: "this is content", - expiredContent: "this reminder has expired", - snoozeContent: "remind later", - notificationId: 100, - slotType: notification.SlotType.SOCIAL_COMMUNICATION -} -``` diff --git a/website/docs/_posts/zh-cn/application-dev/background-agent-scheduled-reminder/background-agent-scheduled-reminder-overview.md b/website/docs/_posts/zh-cn/application-dev/background-agent-scheduled-reminder/background-agent-scheduled-reminder-overview.md deleted file mode 100644 index ce13ed300eaf0b51657a01e5cedc650820cf15bc..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/background-agent-scheduled-reminder/background-agent-scheduled-reminder-overview.md +++ /dev/null @@ -1,16 +0,0 @@ ---- -title: background-agent-scheduled-reminder-overview -permalink: /pages/extra/97f505/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 概述 - -开发者在应用开发时,可以调用后台代理提醒类ReminderRequest去创建定时提醒,包括倒计时、日历、闹钟三种提醒类型。使用后台代理提醒能力后,应用可以被冻结或退出,计时和弹出提醒的功能将被后台系统服务代理。 diff --git a/website/docs/_posts/zh-cn/application-dev/background-task-management/Readme-CN.md b/website/docs/_posts/zh-cn/application-dev/background-task-management/Readme-CN.md deleted file mode 100644 index 1ae77622617c3f6044190f5f949d2276bf418e90..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/background-task-management/Readme-CN.md +++ /dev/null @@ -1,18 +0,0 @@ ---- -title: Readme-CN -permalink: /pages/extra/cc57fa/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 后台任务管理 - -- 后台任务 - - [后台任务概述](/pages/extra/7b6fc5/) - - [后台任务开发指导](/pages/extra/7977c4/) \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/background-task-management/background-task-dev-guide.md b/website/docs/_posts/zh-cn/application-dev/background-task-management/background-task-dev-guide.md deleted file mode 100644 index 3963af83e22378e9597a62ee6b3fbd6c6fe23281..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/background-task-management/background-task-dev-guide.md +++ /dev/null @@ -1,264 +0,0 @@ ---- -title: background-task-dev-guide -permalink: /pages/extra/7977c4/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 后台任务开发指导 - -## 场景介绍 - -应用或业务模块处于后台(无可见界面)时,如果有需要继续执行或者后续执行的业务,可基于业务类型,申请短时任务延迟挂起(Suspend)或者长时任务避免进入挂起状态。 - - -## 接口说明 - -```js -import backgroundTaskManager from '@ohos.backgroundTaskManager'; -``` - -## 短时任务 - -**表1** backgroundTaskManager主要接口 - -| 接口名 | 描述 | -| -------- | -------- | -| function requestSuspendDelay(reason: string, callback: Callback<void>): **DelaySuspendInfo**; | 后台应用申请延迟挂起。
延迟挂起时间一般情况下默认值为180000,低电量(依据系统低电量广播)时默认值为60000。 | -| function getRemainingDelayTime(requestId: number, callback: AsyncCallback<number>): void;
function getRemainingDelayTime(requestId: number): Promise<number>; | 获取应用程序进入挂起状态前的剩余时间。(requestId从requestSuspendDelay的返回值获取)
提供两种异步方法,使用Callback形式其任务执行结果以参数形式提供给回调函数,Promise形式则返回一个Promise对象。 | -| function cancelSuspendDelay(requestId: number): void; | 取消延迟挂起。(requestId从requestSuspendDelay的返回值获取) | - -**表2** DelaySuspendInfo包含参数 - -| 参数名 | 类型 | 是否必选 | 描述 | -| -------- | -------- | -------- | -------- | -| requestId | number | 是 | 延迟挂起的请求ID。 | -| actualDelayTime | number | 是 | 应用的实际挂起延迟时间,以毫秒为单位。 | - - -## 开发步骤 - - -1. 申请延迟挂起 - - ```js - import backgroundTaskManager from '@ohos.backgroundTaskManager'; - - let myReason = 'test requestSuspendDelay'; - let delayInfo = backgroundTaskManager.requestSuspendDelay(myReason, () => { - console.info("Request suspension delay will time out."); - }); - - var id = delayInfo.requestId;console.info("requestId is: " + id); - ``` - - -2. 获取进入挂起前的剩余时间 - - ```js - backgroundTaskManager.getRemainingDelayTime(id).then( res => { - console.log('promise => Operation succeeded. Data: ' + JSON.stringify(res)); - }).catch( err => { - console.log('promise => Operation failed. Cause: ' + err.data); - }); - ``` - - -3. 取消延迟挂起 - - ```js - backgroundTaskManager.cancelSuspendDelay(id); - ``` - - -## 开发实例 - -```js -import backgroundTaskManager from '@ohos.backgroundTaskManager'; -let myReason = 'test requestSuspendDelay'; - -// 申请延迟挂起 -let delayInfo = backgroundTaskManager.requestSuspendDelay(myReason, () => { - console.info("Request suspension delay will time out."); -}); - -// 打印延迟挂起信息 -var id = delayInfo.requestId; -var time = delayInfo.actualDelayTime; -console.info("The requestId is: " + id); -console.info("The actualDelayTime is: " + time); - -// 获取应用程序进入挂起状态前的剩余时间 -backgroundTaskManager.getRemainingDelayTime(id).then( res => { - console.log('promise => Operation succeeded. Data: ' + JSON.stringify(res)); -}).catch( err => { - console.log('promise => Operation failed. Cause: ' + err.data); -}); - -// 取消延迟挂起 -backgroundTaskManager.cancelSuspendDelay(id); -``` - -## 长时任务 - -### 权限 - -ohos.permission.KEEP_BACKGROUND_RUNNING - -**表3** 长时任务主要接口 - -| 接口名 | 描述 | -| -------- | -------- | -| function startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: WantAgent, callback: AsyncCallback<void>): void;
function startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: WantAgent): Promise<void>; | 服务启动后,向系统申请长时任务,使服务一直保持后台运行 | -| function stopBackgroundRunning(context: Context, callback: AsyncCallback<void>): void;
function stopBackgroundRunning(context: Context): Promise<void>; | 停止后台长时任务的运行 | - - - - - -**表4** 后台模式类型 -| 参数名 | id值 | 描述 | -| -------- | -------- | -------- | -| DATA_TRANSFER | 1 | 数据传输 | -| AUDIO_PLAYBACK | 2 | 音频播放 | -| AUDIO_RECORDING | 3 | 录音 | -| LOCATION | 4 | 定位导航 | -| BLUETOOTH_INTERACTION | 5 | 蓝牙相关 | -| MULTI_DEVICE_CONNECTION | 6 | 多设备互联 | -| WIFI_INTERACTION | 7 | WLAN相关(系统保留) | -| VOIP | 8 | 音视频通话(系统保留) | -| TASK_KEEPING | 9 | 计算任务(仅供PC使用) | - - -## 开发步骤 - -1. 在config.json文件中配置长时任务权限 - - ```json - "module": { - "package": "com.example.myapplication", - ..., - "reqPermissions": [ - { - "name": "ohos.permission.KEEP_BACKGROUND_RUNNING" - } - ] - } - ``` - -2. 申请长时任务 - - ```js - import backgroundTaskManager from '@ohos.backgroundTaskManager'; - import featureAbility from '@ohos.ability.featureAbility'; - import wantAgent from '@ohos.wantAgent'; - - let wantAgentInfo = { - wants: [ - { - bundleName: "com.example.myapplication", - abilityName: "com.example.myapplication.MainAbility" - } - ], - operationType: wantAgent.OperationType.START_ABILITY, - requestCode: 0, - wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESET_FLAG] - }; - - // 通过wantAgent模块的getWantAgent方法获取WantAgent对象 - wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { - backgroundTaskManager.startBackgroundRunning(featureAbility.getContext(), - backgroundTaskManager.BackgroundMode.DATA_TRANSFER, wantAgentObj).then(() => { - console.info("Operation succeeded"); - }).catch((err) => { - console.error("Operation failed Cause: " + err); - }); - }); - ``` - -3. 停止长时任务 - - ```js - import backgroundTaskManager from '@ohos.backgroundTaskManager'; - import featureAbility from '@ohos.ability.featureAbility'; - - backgroundTaskManager.stopBackgroundRunning(featureAbility.getContext()).then(() => { - console.info("Operation succeeded"); - }).catch((err) => { - console.error("Operation failed Cause: " + err); - }); - - ``` - -## 开发实例 - -当服务启动后,在serviceAbility的onStart回调方法中,调用长时任务的申请接口,声明此服务需要在后台长时运行。在onStop回调方法里,调用长时任务取消接口,声明取消长时任务。 -在service.js文件中: - -```js -import backgroundTaskManager from '@ohos.backgroundTaskManager'; -import featureAbility from '@ohos.ability.featureAbility'; -import wantAgent from '@ohos.wantAgent'; - -function startBackgroundRunning() { - let wantAgentInfo = { - wants: [ - { - bundleName: "com.example.myapplication", - abilityName: "com.example.myapplication.MainAbility" - } - ], - operationType: wantAgent.OperationType.START_ABILITY, - requestCode: 0, - wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESET_FLAG] - }; - - // 通过wantAgent模块的getWantAgent方法获取WantAgent对象 - wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { - backgroundTaskManager.startBackgroundRunning(featureAbility.getContext(), - backgroundTaskManager.BackgroundMode.DATA_TRANSFER, wantAgentObj).then(() => { - console.info("Operation succeeded"); - }).catch((err) => { - console.error("Operation failed Cause: " + err); - }); - }); -} - -function stopBackgroundRunning() { - backgroundTaskManager.stopBackgroundRunning(featureAbility.getContext()).then(() => { - console.info("Operation succeeded"); - }).catch((err) => { - console.error("Operation failed Cause: " + err); - }); -} - -export default { - onStart(want) { - console.info('ServiceAbility onStart'); - startBackgroundRunning(); - }, - onStop() { - console.info('ServiceAbility onStop'); - stopBackgroundRunning(); - }, - onConnect(want) { - console.info('ServiceAbility onConnect'); - return {}; - }, - onReconnect(want) { - console.info('ServiceAbility onReconnect'); - }, - onDisconnect() { - console.info('ServiceAbility onDisconnect'); - }, - onCommand(want, restart, startId) { - console.info('ServiceAbility onCommand'); - } -}; -``` \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/background-task-management/background-task-overview.md b/website/docs/_posts/zh-cn/application-dev/background-task-management/background-task-overview.md deleted file mode 100644 index 7fc64c08bd4e50d9c5461048f4634b066b4b1f82..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/background-task-management/background-task-overview.md +++ /dev/null @@ -1,75 +0,0 @@ ---- -title: background-task-overview -permalink: /pages/extra/7b6fc5/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 后台任务概述 - -对于有用户交互的OS来说,资源优先分配给与用户交互的业务进程,换句话说,在支撑OS运行的进程以外,用户能感知到的业务进程优先级最高,所以后台任务管理的范围是用户感知不到的业务进程。 - - -## 后台任务类型 - -本文描述的后台任务特指应用或业务模块处于后台(无可见界面)时,有需要继续执行或者后续执行的业务。对这些应用不可见但要继续或者将要执行的业务动作,为避免后台任务管理对业务执行的影响,OpenHarmony将后台任务分为三种类型: - -1. 无后台业务:退后台后,无任务需要处理。 - -2. 短时任务:退后台后,如果有紧急不可推迟且短时间能完成的任务,如应用退后台要进行数据压缩,不可中断,则使用短时任务申请延迟进入挂起(Suspend)状态。 - -3. 长时任务:如果是用户发起的可感知业务需要长时间后台运行的,如后台播放音乐、导航、上传下载、设备连接、VoIP等,则使用长时任务避免进入挂起(Suspend)状态。 - - -## 短时任务 - -退到后台的应用有不可中断且短时间能完成的任务时,可以使用短时任务机制,该机制允许应用在后台短时间内完成任务,保障应用业务运行不受后台生命周期管理的影响。 - -> ![icon-note.gif](/images/application-dev/background-task-management/public_sys-resources/icon-note.gif) **说明:** -> 短时任务仅针对应用的临时任务提供资源使用生命周期保障,限制单次最大使用时长为3分钟,全天使用配额默认为10分钟(具体时长系统根据应用场景和系统状态智能调整)。 - - -### 短时任务使用约束 - -短时任务的使用需要遵从如下约束和规则: - -- **申请时机**:允许应用在前台时,或退后台在被挂起之前(应用退到后台默认有6~12秒的运行时长,具体时长由系统根据具体场景决定)申请延迟挂起,否则可能被挂起(Suspend),导致申请失败。 - -- **超时**:延迟挂起超时(Timeout),系统通过回调知会应用,应用需要取消对应的延迟挂起,或再次申请延迟挂起。超期不取消或不处理,该应用会被强制取消延迟挂起。 - -- **取消时机**:任务完成后申请方应用主动取消延时申请,不要等到超时后被系统取消,否则会影响该应用的后台允许运行时长配额。 - -- **配额机制**:为了防止应用滥用保活,或者申请后不取消,每个应用每天都会有一定配额(会根据用户的使用习惯动态调整),配额消耗完就不再允许申请短时任务,所以应用完成短时任务后立刻取消延时申请,避免消耗配额。(注,这个配额指的是申请的时长,系统默认应用在后台运行的时间不计算在内)。 - -## 长时任务 -长时任务给用户能够直观感受到的且需要一直在后台运行的业务提供后台运行生命周期的保障。比如:业务需要在后台播放声音、需要在后台持续导航定位等。此类用户可以直观感知到的后台业务行为,可以通过使用长时任务对应的后台模式保障业务在后台的运行,支撑应用完成在后台的业务。 - -### 后台模式分类 -OpenHarmony提供了九种后台模式,供需要在后台做长时任务的业务使用,具体的后台模式类型如下: - -**表1** 长时任务种类 - -| BackgroundMode | 说明 | 通知栏显示提示 | 备注 | -| -------- | -------- | -------- | -------- | -| dataTransfer | 通过网络/对端设备进行数据下载、备份、分享、传输等 | 正在运行数据传输任务 | | -| audioPlayback | 音频输出 | 正在运行音频播放任务 | | -| audioRecording | 音频输入 | 正在运行录音任务 | | -| location | 定位、导航 | 正在运行定位任务 | | -| bluetoothInteraction | 蓝牙传输 | 正在运行蓝牙相关任务 | | -| multiDeviceConnection | 分布式互联任务 | 正在运行分布式任务 | | -| wifiInteraction | WLAN传输 | 正在运行WLAN相关任务 | SystemApi,仅对System权限应用开放 | -| voip | 音视频电话、VOIP | 正在运行通话相关任务 | SystemApi,仅对System权限应用开放 | -| taskKeeping | 计算任务 | 正在运行计算任务 | PC特有,仅在PC申请生效 | - -### 长时任务使用约束 -- 如果用户选择可感知业务(如播音、导航、上传下载等),触发对应后台模式,在任务启动时,系统会强制弹出通知提醒用户。 -- 如果任务结束,应用应主动退出后台模式。若在后台运行期间,系统检测到应用并未使用对应后台模式的资源,则会被挂起(Suspend)。 -- 避免不合理地申请后台长时任务,长时任务类型要与应用的业务类型匹配。如表1所示。如果执行的任务和申请的类型不匹配,也会被系统检测到并被挂起(Suspend)。 -- 长时任务是为了真正在后台长时间执行某个任务,如果一个应用申请了长时任务,但在实际运行过程中,并未真正运行或执行此类任务时,也会被系统检测到并被挂起(Suspend)。 -- 每个Ability同一时刻只能申请运行一个长时任务。 \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/connectivity/Readme-CN.md b/website/docs/_posts/zh-cn/application-dev/connectivity/Readme-CN.md deleted file mode 100644 index 01e9e9b5506903cd5df7a786699a0c9639973398..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/connectivity/Readme-CN.md +++ /dev/null @@ -1,19 +0,0 @@ ---- -title: Readme-CN -permalink: /pages/extra/30f113/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 网络与连接 - -- IPC与RPC通信 - - [IPC与RPC通信概述](/pages/01080501) - - [IPC与RPC通信开发指导](/pages/01080502) - - [远端状态订阅开发实例](/pages/01080503) diff --git a/website/docs/_posts/zh-cn/application-dev/connectivity/ipc-rpc.md b/website/docs/_posts/zh-cn/application-dev/connectivity/ipc-rpc.md deleted file mode 100644 index dae3e7ade38a09d8fe4166cbbc18cf4208bd6619..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/connectivity/ipc-rpc.md +++ /dev/null @@ -1,21 +0,0 @@ ---- -title: ipc-rpc -permalink: /pages/extra/c25112/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# IPC与RPC通信 - - -- **[IPC与RPC通信概述](/pages/01080501)** - -- **[IPC与RPC通信开发指导](/pages/01080502)** - -- **[远端状态订阅开发实例](/pages/01080503)** \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/database/Readme-CN.md b/website/docs/_posts/zh-cn/application-dev/database/Readme-CN.md deleted file mode 100644 index 40af0f312f9386758cb90c1c43f0a99d91c0172f..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/database/Readme-CN.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -title: Readme-CN -permalink: /pages/extra/ebcb6a/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 数据管理 - -- 分布式数据服务 - - [分布式数据服务概述](/pages/01080601) - - [分布式数据服务开发指导](/pages/01080602) -- 关系型数据库 - - [关系型数据库概述](/pages/extra/75379e/) - - [分布式数据服务开发指导](/pages/extra/0f5746/) -- 轻量级数据存储 - - [轻量级数据存储概述](/pages/extra/6f0fa4/) - - [轻量级数据存储开发指导](/pages/extra/46af57/) diff --git a/website/docs/_posts/zh-cn/application-dev/database/database-preference-guidelines.md b/website/docs/_posts/zh-cn/application-dev/database/database-preference-guidelines.md deleted file mode 100644 index d787789eac65203d7d4231b3ddb9e52fe2f7f836..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/database/database-preference-guidelines.md +++ /dev/null @@ -1,174 +0,0 @@ ---- -title: database-preference-guidelines -permalink: /pages/extra/46af57/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 轻量级数据存储开发指导 - -## 场景介绍 - -轻量级数据存储功能通常用于保存应用的一些常用配置信息,并不适合需要存储大量数据和频繁改变数据的场景。应用的数据保存在文件中,这些文件可以持久化地存储在设备上。需要注意的是,应用访问的实例包含文件所有数据,这些数据会一直加载在设备的内存中,直到应用主动从内存中将其移除前,应用可以通过Storage的API进行数据操作。 - -## 接口说明 - -轻量级存储为应用提供key-value键值型的文件数据处理能力,支持应用对数据进行轻量级存储及查询。数据存储形式为键值对,键的类型为字符串型,值的存储数据类型包括数字型、字符型、布尔型。 - -**创建存储实例** - -读取指定文件,将数据加载到Storage实例,即可创建一个存储实例,用于数据操作。 - -**表1** 轻量级数据存储实例创建接口 - -| 包名 | 接口名 | 描述 | -| ----------------- | ------------------------------------------- | ------------------------------------------- | -| ohos.data.storage | getStorage(path: string): Promise\ | 获取文件对应的Storage单实例,用于数据操作。 | - -**存入数据** - -通过put系列方法,可以增加或修改Storage实例中的数据。 - -**表2** 轻量级数据存入接口 - -| 类名 | 接口名 | 描述 | -| ------- | -------------------------------------------------- | ----------------------------------------------- | -| Storage | put(key: string, value: ValueType): Promise\ | 支持值为number、string、boolean类型的数据存入。 | - -**读取数据** - -通过调用get系列方法,可以读取Storage中的数据。 - -**表3** 轻量级数据读取接口 - -| 类名 | 接口名 | 描述 | -| ------- | ---------------------------------------------------------- | ----------------------------------------------- | -| Storage | get(key: string, defValue: ValueType): Promise\ | 支持获取值为number、string、boolean类型的数据。 | - -**数据持久化** - -通过执行flush方法,应用可以将缓存的数据再次写回文本文件中进行持久化存储。 - -**表4** 轻量级数据持久化接口 - -| 类名 | 接口名 | 描述 | -| ------- | ----------------------- | --------------------------------------- | -| Storage | flush(): Promise\ | 将Storage实例通过异步线程回写入文件中。 | - -**订阅数据变化** - -订阅数据变化需要指定StorageObserver作为回调方法。订阅的key的值发生变更后,当执行flush方法时,StorageObserver被回调。 - -**表5** 轻量级数据变化订阅接口 - -| 类名 | 接口名 | 描述 | -| ------- | ------------------------------------------------------------ | -------------- | -| Storage | on(type: 'change', callback: Callback\): void | 订阅数据变化。 | -| Storage | off(type: 'change', callback: Callback\): void | 注销订阅。 | - -**删除数据文件** - -通过调用以下两种接口,可以删除数据实例或对应的文件。 - -**表6** 轻量级数据存储删除接口 - -| 包名 | 接口名 | 描述 | -| ----------------- | ---------------------------------------------------- | ------------------------------------------------------------ | -| ohos.data.storage | deleteStorage(path: string): Promise\ | 从缓存中移除已加载的Storage对象,同时从设备上删除对应的文件。 | -| ohos.data.storage | removeStorageFromCache(path: string): Promise\ | 仅从缓存中移除已加载的Storage对象,主要用于释放内存。 | - -## 开发步骤 - -1. 准备工作,导入@ohos.data.storage以及相关的模块到开发环境。 - - ``` - import dataStorage from '@ohos.data.storage' - import featureAbility from '@ohos.ability.featureAbility' // 用于获取文件存储路径 - ``` - -2. 获取Storage实例。 - - 读取指定文件,将数据加载到Storage实例,用于数据操作。 - ``` - var context = featureAbility.getContext() - var path = await context.getFilesDir() - let promise = dataStorage.getStorage(path + '/mystore') - ``` - -3. 存入数据。 - - 使用Storage put方法保存数据到缓存的实例中。 - - ``` - promise.then((storage) => { - let getPromise = storage.put('startup', 'auto') // 保存数据到缓存的storage示例中。 - getPromise.then(() => { - console.info("Put the value of startup successfully.") - }).catch((err) => { - console.info("Put the value of startup failed with err: " + err) - }) - }).catch((err) => { - console.info("Get the storage failed") - }) - ``` - -4. 读取数据。 - - 使用Storage get方法读取数据。 - - ``` - promise.then((storage) => { - let getPromise = storage.get('startup', 'default') - getPromise.then((value) => { - console.info("The value of startup is " + value) - }).catch((err) => { - console.info("Get the value of startup failed with err: " + err) - }) - }).catch((err) => { - console.info("Get the storage failed")}) - ``` - -5. 数据持久化。 - - 应用存入数据到Storage实例后,可以通过flush或者flushSync方法将Storage实例回写到文件中。 - - ``` - storage.flush(); - ``` - -6. 订阅数据变化。 - - 应用订阅数据变化需要指定StorageObserver作为回调方法。订阅的key的值发生变更后,当执行flush方法时,StorageObserver被触发回调。不再需要StorageObserver时请注销。 - - ``` - promise.then((storage) => { - var observer = function (key) { - console.info("The key of " + key + " changed.") - } - storage.on('change', observer) - storage.putSync('startup', 'auto') // 修改storage存储数据 - storage.flushSync() // 触发订阅者回调方法 - - storage.off('change', observer) // 注销数据变化订阅 - }).catch((err) => { - console.info("Get the storage failed") - }) - ``` - -7. 删除指定文件。 - - 使用deleteStorage方法从内存中移除指定文件对应的Storage单实例,并删除指定文件及其备份文件、损坏文件。删除指定文件时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题。删除后,数据及文件将不可恢复。 - - ``` - let promise = dataStorage.deleteStorage(path + '/mystore') - promise.then(() => { - console.info("Deleted successfully.") - }).catch((err) => { - console.info("Deleted failed with err: " + err)}) - ``` \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/database/database-preference-overview.md b/website/docs/_posts/zh-cn/application-dev/database/database-preference-overview.md deleted file mode 100644 index 83c343e924b778623ccf052c6162d60124bb4db4..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/database/database-preference-overview.md +++ /dev/null @@ -1,41 +0,0 @@ ---- -title: database-preference-overview -permalink: /pages/extra/6f0fa4/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 轻量级数据存储概述 - -轻量级数据存储适用于对Key-Value结构的数据进行存取和持久化操作。应用获取某个轻量级存储对象后,该存储对象中的数据将会被缓存在内存中,以便应用获得更快的数据存取速度。应用也可以将缓存的数据再次写回文本文件中进行持久化存储,由于文件读写将产生不可避免的系统资源开销,建议应用减少对持久化文件的读写频率。 - -## 基本概念 - -- **Key-Value数据结构** - - 一种键值结构数据类型。Key是不重复的关键字,Value是数据值。 - -- **非关系型数据库** - - 区别于关系数据库,不保证遵循ACID(Atomic、Consistency、Isolation及Durability)特性,不采用关系模型来组织数据,数据之间无关系。 - -## 运作机制 - -1. 应用通过指定Storage文件将其中的数据加载到Storage实例,系统会通过静态容器将该实例存储在内存中,同一应用或进程中每个文件仅存在一个Storage实例,直到应用主动从内存中移除该实例或者删除该Storage文件。 -2. 应用获取到Storage文件对应的实例后,可以从Storage实例中读取数据,或者将数据存入Storage实例中。通过调用flush或者flushSync方法可以将Storage实例中的数据回写到文件里。 - -**图1** 轻量级数据存储运作机制 - -![zh-cn_image_0000001199139454](/images/application-dev/database/figures/zh-cn_image_0000001199139454.png) - -## 约束与限制 - -- 因Storage实例会加载到内存中,建议存储的数据不超过一万条,并及时清理不再使用的实例,以便减少非内存开销。 -- 数据中的key为string类型,要求非空且字符长度不超过80个。 -- 当数据中的value为string类型时,允许为空,字符长度不超过8192个。 \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/database/database-relational-guidelines.md b/website/docs/_posts/zh-cn/application-dev/database/database-relational-guidelines.md deleted file mode 100644 index 89ac71ca2f98e96b100018fd3000409cd9ea9219..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/database/database-relational-guidelines.md +++ /dev/null @@ -1,213 +0,0 @@ ---- -title: database-relational-guidelines -permalink: /pages/extra/0f5746/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 关系型数据库开发指导 - -## 场景介绍 - -关系型数据库是在SQLite基础上实现的本地数据操作机制,提供给用户无需编写原生SQL语句就能进行数据增删改查的方法,同时也支持原生SQL语句操作。 - - -## 接口说明 - -**数据库的创建和删除** - -关系型数据库提供了数据库创建方式,以及对应的删除接口,涉及的API如下所示。 - -**表1** 数据库创建和删除API - -| 类名 | 接口名 | 描述 | -| -------- | -------- | -------- | -| dataRdb | getRdbStore(config: StoreConfig, version: number, callback: AsyncCallback<RdbStore>): void | 获得一个相关的RdbStore,操作关系型数据库,用户可以根据自己的需求配置RdbStore的参数,然后通过RdbStore调用相关接口可以执行相关的数据操作,结果以callback形式返回。
- config:与此RDB存储相关的数据库配置。
- version:数据库版本。
- callback:指定callback回调函数。返回一个RdbStore。 | -| dataRdb | getRdbStore(config: StoreConfig, version: number): Promise<RdbStore> | 获得一个相关的RdbStore,操作关系型数据库,用户可以根据自己的需求配置RdbStore的参数,然后通过RdbStore调用相关接口可以执行相关的数据操作,结果以Promise形式返回。
- config:与此RDB存储相关的数据库配置。
- version:数据库版本。 | -| dataRdb | deleteRdbStore(name: string, callback: AsyncCallback<void>): void | 删除数据库,结果以callback形式返回。
- name:数据库名称。
- callback:指定callback回调函数。如果数据库已删除,则为true;否则返回false。 | -| dataRdb | deleteRdbStore(name: string): Promise<void> | 使用指定的数据库文件配置删除数据库,结果以Promise形式返回。
- name:数据库名称。 | - -**数据库的增删改查** - -关系型数据库提供对本地数据增删改查操作的能力,相关API如下所示。 - -- **新增** - 关系型数据库提供了插入数据的接口,通过ValuesBucket输入要存储的数据,通过返回值判断是否插入成功,插入成功时返回最新插入数据所在的行号,失败时则返回-1。 - **表2** 数据库插入API - - | 类名 | 接口名 | 描述 | - | -------- | -------- | -------- | - | RdbStore | insert(name: string, values: ValuesBucket, callback: AsyncCallback<number>):void | 向目标表中插入一行数据,结果以callback形式返回。
- name:指定的目标表名。
- values:表示要插入到表中的数据行。
- callback:指定callback回调函数。如果操作成功,返回行ID;否则返回-1。 | - | RdbStore | insert(name: string, values: ValuesBucket): Promise<number> | 向目标表中插入一行数据,结果以Promise形式返回。
- name:指定的目标表名。
- values:表示要插入到表中的数据行。 | - -- **更新** - 调用更新接口,传入要更新的数据,并通过RdbPredicates指定更新条件。该接口的返回值表示更新操作影响的行数。如果更新失败,则返回0。 - - **表3** 数据库更新API - - | 类名 | 接口名 | 描述 | - | -------- | -------- | -------- | - | RdbStore | update(values: ValuesBucket, rdbPredicates: RdbPredicates, callback: AsyncCallback<number>):void | 根据RdbPredicates的指定实例对象更新数据库中的数据,结果以callback形式返回。
- values:以ValuesBucket存储的要更新的数据。
- rdbPredicates:表示RdbPredicates的实例对象指定的更新条件。
- callback:指定的callback回调方法。返回受影响的行数。 | - | RdbStore | update(values: ValuesBucket, rdbPredicates: RdbPredicates): Promise | 根据RdbPredicates的指定实例对象更新数据库中的数据,结果以Promise形式返回。
- values:以ValuesBucket存储的要更新的数据。
- rdbPredicates:表示RdbPredicates的实例对象指定的更新条件。 | - -- **删除** - 调用删除接口,通过RdbPredicates指定删除条件。该接口的返回值表示删除的数据行数,可根据此值判断是否删除成功。如果删除失败,则返回0。 - - **表4** 数据库删除API - - | 类名 | 接口名 | 描述 | - | -------- | -------- | -------- | - | RdbStore | delete(rdbPredicates: RdbPredicates, callback: AsyncCallback<number>):void | 根据rdbPredicates的指定实例对象从数据库中删除数据,结果以callback形式返回。
- rdbPredicates:RdbPredicates的实例对象指定的删除条件。
- callback:指定callback回调函数。返回受影响的行数。 | - | RdbStore | delete(rdbPredicates: RdbPredicates): Promise | 根据rdbPredicates的指定实例对象从数据库中删除数据,结果以Promise形式返回。
- rdbPredicates:RdbPredicates的实例对象指定的删除条件。 | - -- **查询** - 关系型数据库提供了两种查询数据的方式: - - - 直接调用查询接口。使用该接口,会将包含查询条件的谓词自动拼接成完整的SQL语句进行查询操作,无需用户传入原生的SQL语句。 - - 执行原生的SQL语句进行查询操作。 - - **表5** 数据库查询API - - | 类名 | 接口名 | 描述 | - | -------- | -------- | -------- | - | RdbStore | query(rdbPredicates: RdbPredicates, columns: Array, callback: AsyncCallback<ResultSet>): void | 根据指定条件查询数据库中的数据,结果以callback形式返回。
- rdbPredicates:表示RdbPredicates的实例对象指定的查询条件。
- columns:表示要查询的列。如果值为空,则查询应用于所有列。
- callback:指定callback回调函数。如果操作成功,则返回ResultSet对象。 | - | RdbStore | query(rdbPredicates: RdbPredicates, columns: Array): Promise<ResultSet> | 根据指定条件查询数据库中的数据,结果以Promise形式返回。
- rdbPredicates:表示RdbPredicates的实例对象指定的查询条件。
- columns:表示要查询的列。如果值为空,则查询应用于所有列。 | - | RdbStore | querySql(sql: string, bindArgs: Array<ValueType>, callback: AsyncCallback<ResultSet>):void | 根据指定SQL语句查询数据库中的数据,结果以callback形式返回。
- sql:指定要查询的SQL语句。
- bindArgs:SQL语句中参数的值。
- callback:指定callback回调函数。如果操作成功,则返回ResultSet对象。 | - | RdbStore | querySql(sql: string, bindArgs?: Array<ValueType>):Promise<ResultSet> | 根据指定SQL语句查询数据库中的数据,结果以Promise形式返回。
- sql:指定要查询的SQL语句。
- bindArgs:SQL语句中参数的值。 | - -**数据库谓词的使用** - -关系型数据库提供了用于设置数据库操作条件的谓词RdbPredicates,该类确定RDB中条件表达式的值是true还是false。 - -**表6** 数据库谓词API - -| 类名 | 接口名 | 描述 | -| -------- | -------- | -------- | -| RdbPredicates | equalTo(field: string, value: ValueType): RdbPredicates | 配置谓词以匹配数据字段为ValueType且值等于指定值的字段。
- field:数据库表中的列名。
- value:指示要与谓词匹配的值。
- RdbPredicates:返回与指定字段匹配的谓词。 | -| RdbPredicates | notEqualTo(field: string, value: ValueType): RdbPredicates | 配置谓词以匹配数据字段为ValueType且值不等于指定值的字段。
- field:数据库表中的列名。
- value:指示要与谓词匹配的值。
- RdbPredicates:返回与指定字段匹配的谓词。 | -| RdbPredicates | beginWrap(): RdbPredicates | 向谓词添加左括号。
- RdbPredicates:返回带有左括号的谓词。 | -| RdbPredicates | endWrap(): RdbPredicates | 向谓词添加右括号。
- RdbPredicates:返回带有右括号的谓词。 | -| RdbPredicates | or(): RdbPredicates | 将或条件添加到谓词中。
- RdbPredicates:返回带有或条件的谓词。 | -| RdbPredicates | and(): RdbPredicates | 向谓词添加和条件。
- RdbPredicates:返回带有和条件的谓词。 | -| RdbPredicates | contains(field: string, value: string): RdbPredicats | 配置谓词以匹配数据字段为String且value包含指定值的字段。
- field:数据库表中的列名。
- value:指示要与谓词匹配的值。
- RdbPredicates:返回带有包含条件的谓词。 | -| RdbPredicates | beginsWith(field: string, value: string): RdbPredicates | 配置谓词以匹配数据字段为String且值以指定字符串开头的字段。
- field:数据库表中的列名。
- value:指示要与谓词匹配的值。
- RdbPredicates:返回与指定字段匹配的谓词。 | -| RdbPredicates | endsWith(field: string, value: string): RdbPredicates | 配置谓词以匹配数据字段为String且值以指定字符串结尾的字段。
- field:数据库表中的列名。
- value:指示要与谓词匹配的值。
- RdbPredicates:返回与指定字段匹配的谓词。 | -| RdbPredicates | isNull(field: string): RdbPredicates | 配置谓词以匹配值为null的字段。
- field:数据库表中的列名。
- RdbPredicates:返回与指定字段匹配的谓词。 | -| RdbPredicates | isNotNull(field: string): RdbPredicates | 配置谓词以匹配值不为null的指定字段。
- field:数据库表中的列名。
- RdbPredicates:返回与指定字段匹配的谓词。 | -| RdbPredicates | like(field: string, value: string): RdbPredicates | 配置谓词以匹配数据字段为String且值类似于指定字符串的字段。
- field:数据库表中的列名。
- value:指示要与谓词匹配的值。
- RdbPredicates:返回与指定字段匹配的谓词。 | -| RdbPredicates | glob(field: string, value: string): RdbPredicates | 配置RdbPredicates匹配数据字段为String的指定字段。
- field:数据库表中的列名。
- value:指示要与谓词匹配的值。
- RdbPredicates:返回与指定字段匹配的谓词。 | -| RdbPredicates | between(field: string, low: ValueType, high: ValueType): RdbPredicates | 将谓词配置为匹配数据字段为ValueType且value在给定范围内的指定字段。
- field:数据库表中的列名。
- low:指示与谓词匹配的最小值。
- high:指示与谓词匹配的最大值。
- RdbPredicates:返回与指定字段匹配的谓词。 | -| RdbPredicates | notBetween(field: string, low: ValueType, high: ValueType): RdbPredicates | 配置RdbPredicates以匹配数据字段为ValueType且value超出给定范围的指定字段。
- field:数据库表中的列名。
- low:指示与谓词匹配的最小值。
- high:指示与谓词匹配的最大值。
- RdbPredicates:返回与指定字段匹配的谓词。 | -| RdbPredicates | greaterThan(field: string, value: ValueType): RdbPredicatesgr | 配置谓词以匹配数据字段为ValueType且值大于指定值的字段。
- field:数据库表中的列名。
- value:指示要与谓词匹配的值。
- RdbPredicates:返回与指定字段匹配的谓词。 | -| RdbPredicates | lessThan(field: string, value: ValueType): RdbPredicates | 配置谓词以匹配数据字段为valueType且value小于指定值的字段。
- field:数据库表中的列名。
- value:指示要与谓词匹配的值。
- RdbPredicates:返回与指定字段匹配的谓词。 | -| RdbPredicates | greaterThanOrEqualTo(field: string, value: ValueType): RdbPredicates | 配置谓词以匹配数据字段为ValueType且value大于或等于指定值的字段。
- field:数据库表中的列名。
- value:指示要与谓词匹配的值。
- RdbPredicates:返回与指定字段匹配的谓词。 | -| RdbPredicates | lessThanOrEqualTo(field: string, value: ValueType): RdbPredicates | 配置谓词以匹配数据字段为ValueType且value小于或等于指定值的字段。
- field:数据库表中的列名。
- value:指示要与谓词匹配的值。
- RdbPredicates:返回与指定字段匹配的谓词。 | -| RdbPredicates | orderByAsc(field: string): RdbPredicates | 配置谓词以匹配其值按升序排序的列。
- field:数据库表中的列名。
- RdbPredicates:返回与指定字段匹配的谓词。 | -| RdbPredicates | orderByDesc(field: string): RdbPredicates | 配置谓词以匹配其值按降序排序的列。
- field:数据库表中的列名。
- RdbPredicates:返回与指定字段匹配的谓词。 | -| RdbPredicates | distinct(): RdbPredicates | 配置谓词以过滤重复记录并仅保留其中一个。
- RdbPredicates:返回可用于过滤重复记录的谓词。 | -| RdbPredicates | limitAs(value: number): RdbPredicates | 设置最大数据记录数的谓词。
- value:最大数据记录数。
- RdbPredicates:返回可用于设置最大数据记录数的谓词。 | -| RdbPredicates | offsetAs(rowOffset: number): RdbPredicates | 配置RdbPredicates以指定返回结果的起始位置。
- rowOffset:返回结果的起始位置,取值为正整数。
- RdbPredicates:返回具有指定返回结果起始位置的谓词。 | -| RdbPredicates | groupBy(fields: Array<string>): RdbPredicates | 配置RdbPredicates按指定列分组查询结果。
- fields:指定分组依赖的列名。
- RdbPredicates:返回分组查询列的谓词。 | -| RdbPredicates | indexedBy(indexName: string): RdbPredicates | 配置RdbPredicates以指定索引列。
- indexName:索引列的名称。
- RdbPredicates:返回具有指定索引列的RdbPredicates。 | -| RdbPredicates | in(field: string, value: Array<ValueType>): RdbPredicates | 配置RdbPredicates以匹配数据字段为ValueType数组且值在给定范围内的指定字段。
- field:数据库表中的列名。
- value:以ValueType型数组形式指定的要匹配的值。
- RdbPredicates:返回与指定字段匹配的谓词。 | -| RdbPredicates | notIn(field: string, value: Array<ValueType>): RdbPredicates | 将RdbPredicates配置为匹配数据字段为ValueType且值超出给定范围的指定字段。
- field:数据库表中的列名。
- value:以ValueType型数组形式指定的要匹配的值。
- RdbPredicates:返回与指定字段匹配的谓词。 | - -**查询结果集的使用** - -关系型数据库提供了查询返回的结果集ResultSet,其指向查询结果中的一行数据,供用户对查询结果进行遍历和访问。ResultSet对外API如下所示。 - -> ![icon-notice.gif](/images/application-dev/database/public_sys-resources/icon-notice.gif) **须知:** -> **注:结果集使用完后,请一定要调用close方法显式关闭。** - -**表7** 结果集API - -| 类名 | 接口名 | 描述 | -| -------- | -------- | -------- | -| ResultSet | goTo(offset:number): boolean | 从结果集当前位置移动指定偏移量。 | -| ResultSet | goToRow(position: number): boolean | 将结果集移动到指定位置。 | -| ResultSet | goToNextRow(): boolean | 将结果集向后移动一行。 | -| ResultSet | goToPreviousRow(): boolean | 将结果集向前移动一行。 | -| ResultSet | getColumnIndex(columnName: string): number | 根据指定的列名获取列索引。 | -| ResultSet | getColumnName(columnIndex: number): string | 根据指定的列索引获取列名。 | -| ResultSet | goToFirstRow(): boolean | 判断结果集当前位置是否在第一行。 | -| ResultSet | goToLastRow(): boolean | 判断结果集当前位置是否在最后一行。 | -| ResultSet | getString(columnIndex: number): string | 获取当前行指定列的值,以String类型返回。 | -| ResultSet | getBlob(columnIndex: number): Uint8Array | 获取当前行指定列的值,以字节数组形式返回。 | -| ResultSet | getDouble(columnIndex: number): number | 获取当前行指定列的值,以double型返回。 | -| ResultSet | isColumnNull(columnIndex: number): boolean | 检查当前行中指定列的值是否为null。 | -| ResultSet | close(): void | 关闭结果集。 | - -**数据库更改秘钥** - -用户可以对当前数据库进行加密。 - -数据库的加密仅限于初始使用一个数据库时就进行加密,使用过程中进行秘钥的变更,但不支持取消秘钥。 - -数据库初始时为加密库,则一直为加密库;初始时为未加密库,则一直为未加密库。 - -**表8** 数据库更改秘钥 - -| 类名 | 接口名 | 描述 | -| -------- | -------- | -------- | -| RdbStore | changeEncryptKey(newEncryptKey:Uint8Array, callback: AsyncCallback<number>):void; | 数据库更改秘钥接口,通过callback 可以异步处理返回结果。返回结果0成功,非0失败。 | -| RdbStore | changeEncryptKey(newEncryptKey:Uint8Array): Promise<number>; | 数据库更改秘钥接口,通过await 可以同步处理返回结果。返回结果0成功,非0失败。 | - - -## 开发步骤 - -1. 创建数据库。 - 1. 配置数据库相关信息,包括数据库的名称、存储模式、是否为只读模式等。 - 2. 初始化数据库表结构和相关数据。 - 3. 创建数据库。 - - 示例代码如下: - - ``` - import dataRdb from '@ohos.data.rdb'; - - const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)"; - const STORE_CONFIG = {name: "rdbstore.db",} - - let rdbStore = await dataRdb.getRdbStore(STORE_CONFIG, 1); - await rdbStore.executeSql(CREATE_TABLE_TEST); - ``` - -2. 插入数据。 - 1. 构造要插入的数据,以ValuesBucket形式存储。 - 2. 调用关系型数据库提供的插入接口。 - - 示例代码如下: - - ``` - var u8 = new Uint8Array([1, 2, 3]) - const valueBucket = {"name": "Tom", "age": 18, "salary": 100.5, "blobType": u8,} - let insertPromise = rdbStore.insert("test", valueBucket) - ``` - -3. 查询数据。 - 1. 构造用于查询的谓词对象,设置查询条件。 - 2. 调用查询接口查询数据。 - 3. 调用结果集接口,返回查询结果。 - - 示例代码如下: - - ``` - let predicates = new dataRdb.RdbPredicates("test"); - predicates.equalTo("name", "Tom") - let resultSet = await rdbStore.query(predicates) - - resultSet.goToFirstRow() - const id = await resultSet.getLong(resultSet.getColumnIndex("id")) - const name = await resultSet.getString(resultSet.getColumnIndex("name")) - const age = await resultSet.getLong(resultSet.getColumnIndex("age")) - const salary = await resultSet.getDouble(resultSet.getColumnIndex("salary")) - const blobType = await resultSet.getBlob(resultSet.getColumnIndex("blobType")) - - resultSet.close() - ``` diff --git a/website/docs/_posts/zh-cn/application-dev/database/database-relational-overview.md b/website/docs/_posts/zh-cn/application-dev/database/database-relational-overview.md deleted file mode 100644 index eb0f57e955b17b9ad938d114c90270ddc7643506..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/database/database-relational-overview.md +++ /dev/null @@ -1,54 +0,0 @@ ---- -title: database-relational-overview -permalink: /pages/extra/75379e/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 关系型数据库概述 - -关系型数据库(Relational Database,RDB)是一种基于关系模型来管理数据的数据库。关系型数据库基于SQLite组件提供了一套完整的对本地数据库进行管理的机制,对外提供了一系列的增、删、改、查等接口,也可以直接运行用户输入的SQL语句来满足复杂的场景需要。 - -## 基本概念 - -- **关系型数据库** - - 基于关系模型来管理数据的数据库,以行和列的形式存储数据。 - -- **谓词** - - 数据库中用来代表数据实体的性质、特征或者数据实体之间关系的词项,主要用来定义数据库的操作条件。 - -- **结果集** - - 指用户查询之后的结果集合,可以对数据进行访问。结果集提供了灵活的数据访问方式,可以更方便的拿到用户想要的数据。 - -- **SQLite数据库** - - 一款遵守ACID的轻型开源关系型数据库管理系统。 - -## 运作机制 - -关系型数据库对外提供通用的操作接口,底层使用SQLite作为持久化存储引擎,支持SQLite具有的所有数据库特性,包括但不限于事务、索引、视图、触发器、外键、参数化查询和预编译SQL语句。 - -**图1** 关系型数据库运作机制 - -![how-rdb-works](/images/application-dev/database/figures/how-rdb-works.png) - -## 默认配置 - -- 如果不指定数据库的日志模式,那么系统默认日志方式是WAL(Write Ahead Log)模式。 -- 如果不指定数据库的落盘模式,那么系统默认落盘方式是FULL模式。 -- OpenHarmony数据库使用的共享内存默认大小是2MB。 - -## 约束与限制 - -- 数据库中连接池的最大数量是4个,用以管理用户的读操作。 - -- 为保证数据的准确性,数据库同一时间只能支持一个写操作。 \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/dfx/Readme-CN.md b/website/docs/_posts/zh-cn/application-dev/dfx/Readme-CN.md deleted file mode 100644 index b4aa586520e2514f70bee603b60458bf031c2b45..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/dfx/Readme-CN.md +++ /dev/null @@ -1,19 +0,0 @@ ---- -title: Readme-CN -permalink: /pages/extra/0b29a3/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# DFX - -- 应用事件打点 - - [应用事件打点概述](/pages/01080801) - - [应用事件打点开发指导](/pages/01080802) - diff --git a/website/docs/_posts/zh-cn/application-dev/media/Readme-CN.md b/website/docs/_posts/zh-cn/application-dev/media/Readme-CN.md deleted file mode 100644 index 7e627c18d4a1a31568d14402988be4fd4e35526e..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/media/Readme-CN.md +++ /dev/null @@ -1,21 +0,0 @@ ---- -title: Readme-CN -permalink: /pages/extra/504ad4/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 媒体 - -- 音频 - - [音频开发概述](/pages/0108030101) - - [音频播放开发指导](/pages/0108030102) - - [音频管理开发指导](/pages/0108030103) - - [音频录制开发指导](/pages/0108030104) - diff --git a/website/docs/_posts/zh-cn/application-dev/media/audio.md b/website/docs/_posts/zh-cn/application-dev/media/audio.md deleted file mode 100644 index 1868181ce1add3a41450524fbce7549d032e2ffb..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/media/audio.md +++ /dev/null @@ -1,23 +0,0 @@ ---- -title: audio -permalink: /pages/extra/6d22e7/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 音频 - - -- **[音频开发概述](/pages/0108030101)** - -- **[音频播放开发指导](/pages/0108030102)** - -- **[音频管理开发指导](/pages/0108030103)** - -- **[音频录制开发指导](/pages/0108030104)** \ No newline at end of file diff --git "a/website/docs/_posts/zh-cn/application-dev/quick-start/DevEco-Studio\357\274\210OpenHarmony\357\274\211\344\275\277\347\224\250\346\214\207\345\215\227.md" "b/website/docs/_posts/zh-cn/application-dev/quick-start/DevEco-Studio\357\274\210OpenHarmony\357\274\211\344\275\277\347\224\250\346\214\207\345\215\227.md" new file mode 100644 index 0000000000000000000000000000000000000000..49ea9c34fb289195d91f2539f28fd407f34047f6 --- /dev/null +++ "b/website/docs/_posts/zh-cn/application-dev/quick-start/DevEco-Studio\357\274\210OpenHarmony\357\274\211\344\275\277\347\224\250\346\214\207\345\215\227.md" @@ -0,0 +1,26 @@ +--- +title: DevEco-Studio(OpenHarmony)使用指南.md +permalink: /pages/extra/5aac88/ +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +date: 2021-12-30 12:57:45 +--- +# DevEco Studio(OpenHarmony)使用指南 + +- **[概述](/pages/00090000)** + +- **[配置OpenHarmony SDK](/pages/00090001)** + +- **[创建OpenHarmony工程](/pages/00090002)** + +- **[配置OpenHarmony应用签名信息](/pages/00090003)** + +- **[安装运行OpenHarmony应用](/pages/00090004)** + + diff --git a/website/docs/_posts/zh-cn/application-dev/quick-start/Readme-CN.md b/website/docs/_posts/zh-cn/application-dev/quick-start/Readme-CN.md deleted file mode 100644 index 0c4af0b55cd365fe1a8b96dbd3be72f7569276dc..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/quick-start/Readme-CN.md +++ /dev/null @@ -1,29 +0,0 @@ ---- -title: Readme-CN -permalink: /pages/extra/82bbc8/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 入门 - -- DevEco Studio(OpenHarmony)使用指南 - - [概述](/pages/01080901) - - [版本变更说明](/pages/01080902) - - [配置OpenHarmony SDK](/pages/01080903) - - 创建OpenHarmony工程 - - [使用工程向导创建新工程](/pages/0108090401) - - [通过导入Sample方式创建新工程](/pages/0108090402) - - [配置OpenHarmony应用签名信息](/pages/01080905) - - [安装运行OpenHarmony应用](/pages/01080906) -- [包结构说明](/pages/010c03) -- 快速入门 - - [开发准备](/pages/01080101) - - [使用JS语言开发](/pages/01080102) - - [使用eTS语言开发](/pages/01080103) diff --git a/website/docs/_posts/zh-cn/application-dev/quick-start/create-openharmony-project.md b/website/docs/_posts/zh-cn/application-dev/quick-start/create-openharmony-project.md deleted file mode 100644 index 443f7e4265e1cac36727c58c3cfc36af38ad4c27..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/quick-start/create-openharmony-project.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: create-openharmony-project -permalink: /pages/extra/4c1a6a/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 创建OpenHarmony工程 - - - -- **[使用工程向导创建新工程](/pages/0108090401)** - -- **[通过导入Sample方式创建新工程](/pages/0108090402)** \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/quick-start/deveco-studio-user-guide-for-openharmony.md b/website/docs/_posts/zh-cn/application-dev/quick-start/deveco-studio-user-guide-for-openharmony.md deleted file mode 100644 index f493df9151ad0d5a8db5d853001cfd2bd98d2f71..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/quick-start/deveco-studio-user-guide-for-openharmony.md +++ /dev/null @@ -1,28 +0,0 @@ ---- -title: deveco-studio-user-guide-for-openharmony -permalink: /pages/extra/d114c8/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# DevEco Studio(OpenHarmony)使用指南 - - - -- **[概述](/pages/01080901)** - -- **[版本变更说明](/pages/01080902)** - -- **[配置OpenHarmony SDK](/pages/01080903)** - -- **[创建OpenHarmony工程](/pages/extra/4c1a6a/)** - -- **[配置OpenHarmony应用签名信息](/pages/01080905)** - -- **[安装运行OpenHarmony应用](/pages/01080906)** \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/quick-start/start.md b/website/docs/_posts/zh-cn/application-dev/quick-start/start.md deleted file mode 100644 index ff9a9a64362dfdefaa6f37dac17f6e14da0670ed..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/quick-start/start.md +++ /dev/null @@ -1,21 +0,0 @@ ---- -title: start -permalink: /pages/extra/330eee/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 快速入门 - - -- **[开发准备](/pages/01080101)** - -- **[使用JS语言开发](/pages/01080102)** - -- **[使用eTS语言开发](/pages/01080103)** \ No newline at end of file diff --git "a/website/docs/_posts/zh-cn/application-dev/quick-start/\345\210\233\345\273\272\346\226\260\345\267\245\347\250\213.md" "b/website/docs/_posts/zh-cn/application-dev/quick-start/\345\210\233\345\273\272\346\226\260\345\267\245\347\250\213.md" new file mode 100644 index 0000000000000000000000000000000000000000..e3425932637d3bb0ceb9be502e29307cb1882f64 --- /dev/null +++ "b/website/docs/_posts/zh-cn/application-dev/quick-start/\345\210\233\345\273\272\346\226\260\345\267\245\347\250\213.md" @@ -0,0 +1,55 @@ +--- +title: 创建新工程.md +permalink: /pages/extra/d4221e/ +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +date: 2021-12-30 12:57:45 +--- +# 创建新工程 + +- [前提条件](#section13642104391619) +- [操作步骤](#section132671712101714) + +创建一个OpenHarmony工程,该功能只有DevEco Studio 2.2 Beta1及以上版本支持。如果是DevEco Studio 2.1 Release版本,请根据[导入OpenHarmony工程](/pages/extra/55a502/)进行操作。 + +## 前提条件 + +已安装OpenHarmony SDK,具体请参考[配置OpenHarmony SDK](/pages/00090001)。 + +## 操作步骤 + +1. 通过如下两种方式,打开工程创建向导界面。 + - 如果当前未打开任何工程,可以在DevEco Studio的欢迎页,选择**Create HarmonyOS Project**开始创建一个新工程。 + - 如果已经打开了工程,可以在菜单栏选择**File \> New \> New Project**来创建一个新工程。 + +2. 根据工程创建向导,选择“\[Standard\]Empty Ability\(JS\)”模板,点击**Next**。 + + ![](/images/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001177051523.png) + +3. 点击**Next**,进入到工程配置阶段,需要根据向导配置工程的基本信息。 + - **Project Name**:工程的名称,可以自定义。 + - **Project Type**:工程的类型,标识该工程是一个[原子化服务](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/atomic-service-definition-0000001090840664)(Service)或传统方式的需要安装的应用(Application)。 + + >![](/images/zh-cn/application-dev/quick-start/public_sys-resources/icon-note.gif) **说明:** + >如果是创建的原子化服务,则: + >- 原子化服务调试、运行时,在设备桌面上没有应用图标,请使用DevEco Studio的调试和运行功能,来启动原子化服务。 + >- 原子化服务是免安装的,config.json中自动添加**installationFree**字段,取值为“true”。 + >- 如果entry模块的**installationFree**字段为true,则其相关的所有hap模块的**installationFree**字段都默认为true;如果entry模块的**installationFree**字段为false,则其相关的所有hap模块可以配置为true或false。 + >- 编译构建App时,每个hap包大小不能超过10MB。 + + - **Package Name**:软件包名称,默认情况下,应用ID也会使用该名称,应用发布时,应用ID需要唯一。 + - **Save Location**:工程文件本地存储路径。 + - **Compatible API Version**:兼容的SDK最低版本。 + - **Device Type**:该工程模板支持的设备类型。 + + ![](/images/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001130932554.png) + + +4. 点击**Finish**,工具会自动生成示例代码和相关资源,等待工程创建完成。 + diff --git "a/website/docs/_posts/zh-cn/application-dev/quick-start/\345\257\274\345\205\245OpenHarmony\345\267\245\347\250\213.md" "b/website/docs/_posts/zh-cn/application-dev/quick-start/\345\257\274\345\205\245OpenHarmony\345\267\245\347\250\213.md" new file mode 100644 index 0000000000000000000000000000000000000000..fdeda3d391aecc7534caab76f3d3a0948853130f --- /dev/null +++ "b/website/docs/_posts/zh-cn/application-dev/quick-start/\345\257\274\345\205\245OpenHarmony\345\267\245\347\250\213.md" @@ -0,0 +1,59 @@ +--- +title: 导入OpenHarmony工程.md +permalink: /pages/extra/55a502/ +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +date: 2021-12-30 12:57:45 +--- +# 导入OpenHarmony工程 + +>![](/images/zh-cn/application-dev/quick-start/public_sys-resources/icon-note.gif) **说明:** +>该功能适用于通过DevEco Studio 2.1 Release及以上版本,创建OpenHarmony工程。 + +OpenHarmony SDK配置完成后,便可以启动应用开发。针对OpenHarmony应用开发,**只能通过导入Sample工程的方式来创建一个新工程**。 + +目前,支持OpenHarmony应用开发的Sample工程,请选择导入含有“**This sample is intended for novices at developing OpenHarmony applications.**”说明的Sample,例如选择common分类中的**JsHelloWorld**。 + +![](/images/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001165463605.png) + +1. 在DevEco Studio的欢迎页,进入**Configure (或**![](/images/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001118018452.png)**图标) \> Settings \> Version Control \> Git**界面,点击Test按钮检测是否安装Git工具。 + - 已安装,请根据[2](#li5947194711181)开始导入Sample。 + + ![](/images/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001118018088.png) + + - 未安装,请点击**Download and Install**,DevEco Studio会自动下载并安装。安装完成后,请根据[2](#li5947194711181)开始导入Sample。 + + ![](/images/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001164498191.png) + + +2. 在DevEco Studio的欢迎页,点击**Import HarmonyOS Sample**按钮,导入Sample工程。 + + ![](/images/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001163835551.png) + +3. 选择common下的**JsHelloWorld**工程,然后点击**Next**。 + + ![](/images/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001118201202.png) + +4. 设置**App Name**和**Project Location**,然后点击**Finish**,等待Sample工程导入完成。 + + ![](/images/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001163915521.png) + +5. Sample导入后,请打开工程下的build.gradle,修改hap插件的版本号为“2.4.4.3-RC”。 + + ![](/images/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001117475776.png) + +6. 修改完成后,点击右上角Gradle中的![](/images/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001163835553.png)按钮,重新同步工程。 + + ![](/images/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001117635680.png) + +7. 等待工程同步完成,同步成功后,便可以进行OpenHarmony应用开发了。 + + ![](/images/zh-cn/application-dev/quick-start/figures/zh-cn_image_0000001163915523.png) + + diff --git a/website/docs/_posts/zh-cn/application-dev/reference/Readme-CN.md b/website/docs/_posts/zh-cn/application-dev/reference/Readme-CN.md deleted file mode 100644 index a388881f8dac7cb6486c64c9be1d87e2fc38fdf8..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/Readme-CN.md +++ /dev/null @@ -1,21 +0,0 @@ ---- -title: Readme-CN -permalink: /pages/extra/23166e/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 开发参考 - -- [基于JS扩展的类Web开发范式](/pages/extra/74333b/) - -- [基于TS扩展的声明式开发范式](/pages/extra/07ffe5/) - -- [接口](/pages/extra/cdb335/) - diff --git a/website/docs/_posts/zh-cn/application-dev/reference/apis/Readme-CN.md b/website/docs/_posts/zh-cn/application-dev/reference/apis/Readme-CN.md deleted file mode 100644 index 457fddc86a994ec6edf398917afd5c6f3a2e087b..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/apis/Readme-CN.md +++ /dev/null @@ -1,107 +0,0 @@ ---- -title: Readme-CN -permalink: /pages/extra/cdb335/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 接口 - -- Ability框架 - - [FeatureAbility模块](/pages/010c010101) - - [ParticleAbility模块](/pages/010c010102) - - [DataAbilityHelper模块](/pages/010c010103) - - [DataUriUtils模块](/pages/010c010104) - - [Bundle模块](/pages/010c010105) - - [Context模块](/pages/010c010108) -- 事件与通知 - - [CommonEvent模块](/pages/010c010106) - - [Notification模块](/pages/010c010107) - - [后台代理提醒](/pages/extra/5d9419/) -- 资源管理 - - [资源管理](/pages/010c010201) - - [国际化-Intl](/pages/010c010203) - - [国际化-I18n](/pages/010c010202) -- 媒体 - - [音频管理](/pages/010c010301) - - [媒体服务](/pages/010c010302) -- 安全 - - [用户认证](/pages/010c010401) - - [访问控制](/pages/extra/5b7654/) -- 数据管理 - - [轻量级存储](/pages/010c010501) - - [分布式数据管理](/pages/010c010502) - - [关系型数据库](/pages/010c010503) - - [结果集](/pages/010c010504) - - [DataAbility 谓词](/pages/010c010505) - - [设置数据项名称](/pages/010c010506) -- 文件管理 - - [文件管理](/pages/010c010601) - - [Statfs](/pages/010c010602) - - [目录环境](/pages/010c010603) - - [公共文件访问与管理](/pages/extra/39495c/) -- 账号管理 - - [分布式帐号管理](/pages/010c010701) - - [应用帐号管理](/pages/010c010702) -- 电话服务 - - [拨打电话](/pages/010c010801) - - [短信服务](/pages/010c010802) - - [SIM卡管理](/pages/010c010803) - - [网络搜索](/pages/010c010804) -- 网络与连接 - - [WLAN](/pages/010c010901) -- 设备管理 - - [传感器](/pages/010c010a01) - - [振动](/pages/010c010a02) - - [屏幕亮度](/pages/010c010a03) - - [电量信息](/pages/010c010a04) - - [系统电源管理](/pages/010c010a05) - - [Runninglock锁](/pages/010c010a06) - - [设备信息](/pages/010c010a07) - - [系统属性](/pages/010c010a08) - - [设备管理](/pages/010c010a09) - - [窗口](/pages/010c010a0a) - - [显示设备属性](/pages/010c010a0b) - - [升级](/pages/010c010a0c) - - [USB管理](/pages/010c010a0d) -- 基本功能 - - [应用上下文](/pages/010c010b01) - - [日志打印](/pages/010c010b02) - - [页面路由](/pages/010c010b03) - - [弹窗](/pages/010c010b04) - - [应用配置](/pages/010c010b05) - - [定时器](/pages/010c010b06) - - [设置系统时间](/pages/010c010b07) - - [动画](/pages/010c010b08) - - [应用打点](/pages/010c010b09) - - [性能打点](/pages/010c010b0a) - - [故障日志获取](/pages/010c010b0b) -- 语言基础类库 - - [获取进程相关的信息](/pages/010c010c01) - - [URL字符串解析](/pages/010c010c02) - - [URI字符串解析](/pages/010c010c03) - - [util工具函数](/pages/010c010c04) - - [xml解析与生成](/pages/010c010c05) - - [xml转换JavaScript](/pages/010c010c06) - - [启动一个worker](/pages/010c010c07) - - [线性容器ArrayList](/pages/extra/164a05/) - - [线性容器Deque](/pages/extra/e33666/) - - [线性容器List](/pages/extra/fa1a5f/) - - [线性容器LinkedList](/pages/extra/faabf6/) - - [线性容器Queue](/pages/extra/357a69/) - - [线性容器Stack](/pages/extra/eafceb/) - - [线性容器Vector](/pages/extra/444403/) - - [非线性容器HashSet](/pages/extra/256434/) - - [非线性容器HashMap](/pages/extra/c53422/) - - [非线性容器PlainArray](/pages/extra/9c7f1a/) - - [非线性容器TreeMap](/pages/extra/f84378/) - - [非线性容器TreeSet](/pages/extra/2d9ad7/) - - [非线性容器LightWeightMap](/pages/extra/6cbba8/) - - [非线性容器LightWeightSet](/pages/extra/15f160/) - diff --git a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-ability-context.md b/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-ability-context.md deleted file mode 100644 index 5d9e7d132e7b0005e775c8c268c2cec945dc016e..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-ability-context.md +++ /dev/null @@ -1,230 +0,0 @@ ---- -title: js-apis-ability-context -permalink: /pages/extra/0b5f30/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# AbilityContext - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -Ability的上下文环境,继承自Context。 - - -## 属性 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| abilityInfo | AbilityInfo | 是 | 否 | Abilityinfo相关信息 | -| currentHapModuleInfo | HapModuleInfo | 是 | 否 | 当前hap包的信息 | - - -## startAbility - -startAbility(want: Want, callback: AsyncCallback<void>): void - -启动Ability。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | want | [Want](/pages/010c010101#Want类型说明) | 是 | 启动Ability的want信息。 | - | callback | AsyncCallback<void> | 是 | callback形式返回启动结果 | - -- 示例: - ``` - var want = { - "deviceId": "", - "bundleName": "com.extreme.test", - "abilityName": "com.extreme.test.MainAbility" - }; - this.context.startAbility(want, (error) => { - console.log("error.code = " + error.code) - }) - ``` - - -## startAbility - -startAbility(want: Want): Promise<void>; - -启动Ability。通过Promise返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | want | [Want](/pages/010c010101#Want类型说明) | 是 | 启动Ability的want信息。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | Promise形式返回启动结果。 | - -- 示例: - ``` - var want = { - "deviceId": "", - "bundleName": "com.extreme.test", - "abilityName": "com.extreme.test.MainAbility" - }; - this.context.startAbility(want) - .then((data) => { - console.log('Operation successful.') - }).catch((error) => { - console.log('Operation failed.'); - }) - ``` - - -## startAbilityForResult - -startAbilityForResult(want: Want, callback: AsyncCallback<AbilityResult>): void; - -启动Ability并在结束的时候返回执行结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | want |[Want](/pages/010c010101#Want类型说明) | 是 | 启动Ability的want信息。 | - | callback | Callback<[AbilityResult](/pages/010c010101#abilityresult)> | 是 | 执行结果回调函数。 | - - -- 示例: - ``` - this.context.startAbilityForResult( - {bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo2"}, - (error, result) => { - console.log("startAbilityForResult AsyncCallback is called, error.code = " + error.code) - console.log("startAbilityForResult AsyncCallback is called, result.resultCode = " + result.resultCode) - } - ); - ``` - - -## startAbilityForResult - -startAbilityForResult(want: Want): Promise<AbilityResult>; - -启动Ability并在结束的时候返回执行结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | want | [Want](/pages/010c010101#Want类型说明) | 是 | 启动Ability的want信息。 | - -- 返回值 - | 类型 | 说明 | - | -------- | -------- | - | Promise<[AbilityResult](/pages/010c010101#abilityresult)> | Promise形式返回执行结果。 | - -- 示例: - ``` - this.context.startAbilityForResult({bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo2"}).then((result) => { - console.log("startAbilityForResult Promise.resolve is called, result.resultCode = " + result.resultCode) - }, (error) => { - console.log("startAbilityForResult Promise.Reject is called, error.code = " + error.code) - }) - ``` - - -## terminateSelf - -terminateSelf(callback: AsyncCallback<void>): void; - -停止Ability自身。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<void> | 否 | 回调函数,返回接口调用是否成功的结果。 | - -- 示例: - ``` - this.context.terminateSelf((err) => { - console.log('terminateSelf result:' + JSON.stringfy(err); - } - ``` - - -## terminateSelf - -terminateSelf(): Promise<void>; - -停止Ability自身。通过Promise返回结果。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | 返回一个Promise,包含接口的结果。 | - -- 示例: - ``` - this.context.terminateSelf(want).then((data) => { - console.log('success:' + JSON.stringfy(data)); - )).catch((error) => { - console.log('failed:' + JSON.stringfy(error)); - }); - ``` - - -## terminateSelfWithResult - -terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback<void>): void; - -停止Ability,并返回给调用startAbilityForResult 接口调用方的相关信息。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | parameter | [AbilityResult](/pages/010c010101#abilityresult) | 是 | 返回给调用startAbilityForResult 接口调用方的相关信息。 | - | callback | Callback<void> | 否 | callback形式返回停止结果 | - -- 示例: - ``` - this.context.terminateSelfWithResult( - { - want: {bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo"}, - resultCode: 100 - }, (error) => { - console.log("terminateSelfWithResult is called = " + error.code) - } - ); - ``` - - -## terminateSelfWithResult - -terminateSelfWithResult(parameter: AbilityResult): Promise<void>; - -停止Ability,并返回给调用startAbilityForResult 接口相关信息。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | parameter | [AbilityResult](/pages/010c010101#abilityresult) | 是 | 返回给startAbilityForResult 调用方的信息。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | promise形式返回停止结果 | - -- 示例: - ``` - this.context.terminateSelfWithResult( - { - want: {bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo"}, - resultCode: 100 - }).then((result) => { - console.log("terminateSelfWithResult") - } - ) - ``` diff --git a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-arraylist.md b/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-arraylist.md deleted file mode 100644 index 6fcc8890c931b5f2e6d96732da57885ac19c658f..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-arraylist.md +++ /dev/null @@ -1,531 +0,0 @@ ---- -title: js-apis-arraylist -permalink: /pages/extra/164a05/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 线性容器ArrayList - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - -## 导入模块 - -``` -import ArrayList from '@ohos.util.ArrayList' -``` - -## 权限 - -无 - -## ArrayList - -### 属性 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| length | number | 是 | 否 | ArrayList的元素个数 | - - -### constructor - -constructor(); - -ArrayList的构造函数。 - -- 示例: - ``` - let arrayList = new ArrayList(); - ``` - - -### add - -add(element: T): boolean; - -在ArrayList尾部插入元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | element | T | 是 | 添加进去的元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 插入成功返回true,失败返回false | - -- 示例: - ``` - let arrayList = new ArrayList(); - arrayList.add("a"); - arrayList.add(1); - let b = [1, 2, 3]; - arrayList.add(b); - let c = {name: "lala", age: "13"}; - arrayList.add(false); - ``` - -### insert - -insert(element: T, index: number): void; - -在长度范围内任意位置插入指定元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | element | T | 是 | 被插入的元素 | - | index | number | 是 | 被插入的位置索引 | - -- 示例: - ``` - let arrayList = new ArrayList(); - arrayList.insert("A", 0); - arrayList.insert(0, 1); - arrayList.insert(true, 2); - ``` - -### has - -has(element: T): boolean; - -判断此ArrayList中是否含有该指定元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | element | T | 是 | 指定元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 是否包含指定元素 | - -- 示例: - ``` - let arrayList = new ArrayList(); - arrayList.has("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - arrayList.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - arrayList.has("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - ``` - -### getIndexOf - -getIndexOf(element: T): number; - -返回指定元素第一次出现时的下标值,查找失败返回-1。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | element | T | 是 | 指定元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 返回指定元素第一次出现时的下标值,查找失败返回-1 | - -- 示例: - ``` - let arrayList = new ArrayList(); - arrayList.add(2); - arrayList.add(4); - arrayList.add(5); - arrayList.add(2); - arrayList.add(1); - arrayList.add(2); - arrayList.add(4); - arrayList.getIndexOf(2); - ``` -### getLastIndexOf - -getLastIndexOf(element: T): number; - -返回指定元素最后一次出现时的下标值,查找失败返回-1。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | element | T | 是 | 指定元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 返回指定元素最后一次出现时的下标值,查找失败返回-1 | - -- 示例: - ``` - let arrayList = new ArrayList(); - arrayList.add(2); - arrayList.add(4); - arrayList.add(5); - arrayList.add(2); - arrayList.add(1); - arrayList.add(2); - arrayList.add(4); - arrayList.getLastIndexOf(2); - ``` -### removeByIndex - -removeByIndex(index: number): T; - -根据元素的下标值查找元素,返回元素后将其删除。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | index | number | 是 | 指定元素的下标值 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | T | 返回删除的元素 | - -- 示例: - ``` - let arrayList = new ArrayList(); - arrayList.add(2); - arrayList.add(4); - arrayList.add(5); - arrayList.add(2); - arrayList.add(4); - arrayList.removeByIndex(2); - ``` - -### remove - -remove(element: T): boolean; - -删除查找到的第一个指定的元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | element | T | 是 | 指定元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 删除成功返回true,失败返回false | - -- 示例: - ``` - let arrayList = new ArrayList(); - arrayList.add(2); - arrayList.add(4); - arrayList.add(5); - arrayList.add(4); - arrayList.remove(2); - ``` - -### removeByRange - -removeByRange(fromIndex: number, toIndex: number): void; - -从一段范围内删除元素,包括起始值但不包括终止值。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | fromIndex | number | 是 | 起始下标 | - | toIndex | number | 是 | 终止下标 | - -- 示例: - ``` - let arrayList = new ArrayList(); - arrayList.add(2); - arrayList.add(4); - arrayList.add(5); - arrayList.add(4); - arrayList.removeByRange(2, 4); - arrayList.removeByRange(4, 3); - arrayList.removeByRange(2, 6); - ``` -### replaceAllElements -replaceAllElements(callbackfn: (value: T, index?: number, arraylist?: ArrayList<T>) => T, -thisArg?: Object): void; - -用户操作ArrayList中的元素,用操作后的元素替换原元素并返回操作后的元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callbackfn | function | 是 | 回调函数 | - | thisArg | Object | 否 | callbackfn被调用时用作this值 | - -- callbackfn的参数说明 - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | T | 是 | 当前遍历到的元素 | - | index | number | 否 | 当前遍历到的下标值 | - | arraylist | ArrayList<T> | 否 | 当前调用replaceAllElements方法的实例对象 | - -- 示例: - ``` - let arrayList = new ArrayList(); - arrayList.add(2); - arrayList.add(4); - arrayList.add(5); - arrayList.add(4); - arrayList.replaceAllElements((value, index) => { - return value = 2 * value; - }); - arrayList.replaceAllElements((value, index) => { - return value = value - 2; - }); - ``` -### forEach -forEach(callbackfn: (value: T, index?: number, arraylist?: ArrayList<T>) => void, -thisArg?: Object): void; - -通过回调函数来遍历ArrayList实例对象上的元素以及元素对应的下标。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callbackfn | function | 是 | 回调函数。 | - | thisArg | Object | 否 | callbackfn被调用时用作this值 | - -- callbackfn的参数说明 - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | T | 是 | 当前遍历到的元素。 | - | index | number | 否 | 当前遍历到的下标值。 | - | arraylist | ArrayList<T> | 否 | 当前调用forEach方法的实例对象。 | - - -- 示例: - ``` - let arrayList = new ArrayList(); - arrayList.add(2); - arrayList.add(4); - arrayList.add(5); - arrayList.add(4); - arrayList.forEach((value, index) => { - console.log(value, index); - }); - ``` -### sort -sort(comparator?: (firstValue: T, secondValue: T) => number): void; - -对ArrayList中的元素进行一个排序操作 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | comparator | function | 否 | 回调函数 | - -- comparator的参数说明 - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | firstValue | T | 是 | 前一项元素 | - | secondValue | T | 是 | 后一项元素 | - - -- 示例: - ``` - let arrayList = new ArrayList(); - arrayList.add(2); - arrayList.add(4); - arrayList.add(5); - arrayList.add(4); - arrayList.sort(a, (b => a - b)); - arrayList.sort(a, (b => b - a)); - arrayList.sort(); - ``` -### subArrayList -subArrayList(fromIndex: number, toIndex: number): ArrayList<T>; - -根据下标截取ArrayList中的一段元素,并返回这一段ArrayList实例, 包括起始值但不包括终止值 -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | fromIndex | number | 是 | 起始下标 | - | toIndex | number | 是 | 终止下标 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | ArrayList<T> | 返回ArrayList对象实例 | - -- 示例: - ``` - let arrayList = new ArrayList(); - arrayList.add(2); - arrayList.add(4); - arrayList.add(5); - arrayList.add(4); - arrayList.subArrayList(2, 4); - arrayList.subArrayList(4, 3); - arrayList.subArrayList(2, 6); - ``` - -### clear -clear(): void; - -清除ArrayList中的所有元素,并把length置为0。 - -- 示例: - ``` - let arrayList = new ArrayList(); - arrayList.add(2); - arrayList.add(4); - arrayList.add(5); - arrayList.add(4); - arrayList.clear(); - ``` -### clone -clone(): ArrayList<T> ; - -克隆一个与ArrayList一模一样的实例,并返回克隆后的实例,修改克隆后的实例并不会影响原实例。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | ArrayList<T> | 返回ArrayList对象实例 | - -- 示例: - ``` - let arrayList = new ArrayList(); - arrayList.add(2); - arrayList.add(4); - arrayList.add(5); - arrayList.add(4); - arrayList.clone(); - ``` -### getCapacity -getCapacity(): number; - -获取当前实例的容量大小。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 返回arraylist的容量大小 | - -- 示例: - ``` - let arrayList = new ArrayList(); - arrayList.add(2); - arrayList.add(4); - arrayList.add(5); - arrayList.add(4); - arrayList.getCapacity(); - ``` -### convertToArray -convertToArray(): Array<T>; - -把当前ArrayList实例转换成数组,并返回转换后的数组。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Array<T> | 返回数组类型 | - -- 示例: - ``` - let arrayList = new ArrayList(); - arrayList.add(2); - arrayList.add(4); - arrayList.add(5); - arrayList.add(4); - arrayList.convertToArray(); - ``` -### isEmpty -isEmpty(): boolean; - -判断该ArrayList是否为空。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 为空返回true, 不为空返回false | - -- 示例: - ``` - let arrayList = new ArrayList(); - arrayList.add(2); - arrayList.add(4); - arrayList.add(5); - arrayList.add(4); - arrayList.isEmpty(); - ``` -### increaseCapacityTo -increaseCapacityTo(newCapacity: number): void; - -如果传入的新容量大于或等于ArrayList中的元素个数,将容量变更为新容量。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | newCapacity | number | 是 | 新容量 | - - -- 示例: - ``` - let arrayList = new ArrayList(); - arrayList.add(2); - arrayList.add(4); - arrayList.add(5); - arrayList.add(4); - arrayList.increaseCapacityTo(2); - arrayList.increaseCapacityTo(8); - ``` -### trimToCurrentLength -trimToCurrentLength(): void; - -把容量限制为当前的length大小。 - -- 示例: - ``` - let arrayList = new ArrayList(); - arrayList.add(2); - arrayList.add(4); - arrayList.add(5); - arrayList.add(4); - arrayList.trimToCurrentLength(2); - ``` -### [Symbol.iterator] - -[Symbol.iterator]\(): IterableIterator<T>; - -返回一个迭代器,迭代器的每一项都是一个 JavaScript 对象,并返回该对象。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | IterableIterator<T> | 返回一个迭代器 | - -- 示例: - ``` - let arrayList = new ArrayList(); - arrayList.add(2); - arrayList.add(4); - arrayList.add(5); - arrayList.add(4); - - // 使用方法一: - for (let item of arrayList) { - console.log(item); - } - - // 使用方法二: - let iter = arrayList[Symbol.iterator](); - let temp = iter.next().value; - while(temp != undefined) { - console.log(temp); - temp = iter.next().value; - } - ``` \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-backgroundTaskManager.md b/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-backgroundTaskManager.md deleted file mode 100644 index 536e55048163811558edbcea3f0bd28cada5437e..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-backgroundTaskManager.md +++ /dev/null @@ -1,307 +0,0 @@ ---- -title: js-apis-backgroundTaskManager -permalink: /pages/extra/7f5b50/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 后台任务管理 - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import backgroundTaskManager from '@ohos.backgroundTaskManager'; -``` - -## 系统能力 -SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask -SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask - -## 权限列表 - -长时任务需要申请如下权限: - -ohos.permission.KEEP_BACKGROUND_RUNNING - - -## backgroundTaskManager.requestSuspendDelay - -requestSuspendDelay(reason: string, callback: Callback<void>): DelaySuspendInfo - -后台应用申请延迟挂起。 - -延迟挂起时间一般情况下默认值为180000,低电量(依据系统低电量广播)时默认值为60000。 - -- **参数**: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | reason | string | 是 | 延迟挂起申请的原因。 | - | callback | Callback<void> | 是 | 延迟即将超时的回调函数,一般在超时前6秒通过此回调通知应用。 | - -- **返回值**: - | 类型 | 说明 | - | -------- | -------- | - | [DelaySuspendInfo](#delaysuspendinfo) | 返回延迟挂起信息。 | - -- **示例**: - ``` - let myReason = 'test requestSuspendDelay'; - let delayInfo = backgroundTaskManager.requestSuspendDelay(myReason, () => { - console.info("Request suspension delay will time out."); - }) - ``` - - -## backgroundTaskManager.getRemainingDelayTime - -getRemainingDelayTime(requestId: number, callback: AsyncCallback<number>): void - -获取应用程序进入挂起状态前的剩余时间,使用callback形式返回。 - -- **参数**: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | requestId | number | 是 | 延迟挂起的请求ID。 | - | callback | AsyncCallback<number> | 是 | 指定的callback回调方法。用于返回应用程序进入挂起状态之前的剩余时间,以毫秒为单位。 | - -- **示例**: - ``` - let id = 1; - backgroundTaskManager.getRemainingDelayTime(id, (err, res) => { - if(err.data === 0) { - console.log('promise => Operation succeeded. Data: ' + JSON.stringify(res)); - } else { - console.log('promise => Operation failed. Cause: ' + err.data); - } - }) - ``` - - -## backgroundTaskManager.getRemainingDelayTime - -getRemainingDelayTime(requestId: number): Promise<number> - -获取应用程序进入挂起状态前的剩余时间,使用Promise形式返回。 - -- **参数**: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | requestId | number | 是 | 延迟挂起的请求ID。 | - -- **返回值**: - | 类型 | 说明 | - | -------- | -------- | - | Promise<number> | 指定的Promise回调方法。返回应用程序进入挂起状态之前的剩余时间,以毫秒为单位。 | - -- **示例**: - ``` - let id = 1; - backgroundTaskManager.getRemainingDelayTime(id).then( res => { - console.log('promise => Operation succeeded. Data: ' + JSON.stringify(res)); - }).catch( err => { - console.log('promise => Operation failed. Cause: ' + err.data); - }) - ``` - - -## backgroundTaskManager.cancelSuspendDelay - -cancelSuspendDelay(requestId: number): void - -取消延迟挂起。 - -- **参数**: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | requestId | number | 是 | 延迟挂起的请求ID。 | - -- **示例**: - ``` - backgroundTaskManager.cancelSuspendDelay(id); - ``` - - -#### DelaySuspendInfo - -延迟挂起信息。 - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| requestId | number | 是 | 延迟挂起的请求ID。 | -| actualDelayTime | number | 是 | 应用的实际挂起延迟时间,以毫秒为单位。
一般情况下默认值为180000,低电量(依据系统低电量广播)时默认值为60000。 | - -## backgroundTaskManager.startBackgroundRunning - -[8] startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: WantAgent, callback: AsyncCallback<void>): void; - -向系统申请长时任务,使用callback形式返回结果。 - -- **参数**: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | context | Context | 是 | 应用运行的上下文 | - | bgMode | BackgroundMode | 是 | 向系统申请的后台模式 | - | wantAgent | WantAgent | 是 | 通知参数,用于指定长时任务通知点击跳转的界面。使用方式参考:[8] | - | callback | AsyncCallback<void> | 是 | callback形式返回启动长时任务的结果 | - -- **示例**: -```js -import backgroundTaskManager from '@ohos.backgroundTaskManager'; -import featureAbility from '@ohos.ability.featureAbility'; -import wantAgent from '@ohos.wantAgent'; - -function callback(err, data) { - if (err) { - console.error("Operation failed Cause: " + err); - } else { - console.info("Operation succeeded"); - } -} - -let wantAgentInfo = { - wants: [ - { - bundleName: "com.example.myapplication", - abilityName: "com.example.myapplication.MainAbility" - } - ], - operationType: wantAgent.OperationType.START_ABILITY, - requestCode: 0, - wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESET_FLAG] -}; - -wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { - backgroundTaskManager.startBackgroundRunning(featureAbility.getContext(), - backgroundTaskManager.BackgroundMode.DATA_TRANSFER, wantAgentObj, callback) -}); - -``` - -## backgroundTaskManager.startBackgroundRunning - -[8] startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: WantAgent): Promise<void> - -向系统申请长时任务,使用promise形式返回结果。 - -- **参数**: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | context | Context | 是 | 应用运行的上下文 | - | bgMode | BackgroundMode | 是 | 向系统申请的后台模式 | - | wantAgent | WantAgent | 是 | 通知参数,用于指定长时任务通知点击跳转的界面 | - -- **返回值** - | 类型 | 说明 | - | -------------- | ------------------------- | - | Promise\ | 使用Promise形式返回结果。 | - -- **示例**: -```js -import backgroundTaskManager from '@ohos.backgroundTaskManager'; -import featureAbility from '@ohos.ability.featureAbility'; -import wantAgent from '@ohos.wantAgent'; - -let wantAgentInfo = { - wants: [ - { - bundleName: "com.example.myapplication", - abilityName: "com.example.myapplication.MainAbility" - } - ], - operationType: wantAgent.OperationType.START_ABILITY, - requestCode: 0, - wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESET_FLAG] -}; - -wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { - backgroundTaskManager.startBackgroundRunning(featureAbility.getContext(), - backgroundTaskManager.BackgroundMode.DATA_TRANSFER, wantAgentObj).then(() => { - console.info("Operation succeeded"); - }).catch((err) => { - console.error("Operation failed Cause: " + err); - }); -}); - -``` - -## backgroundTaskManager.stopBackgroundRunning - -[8] stopBackgroundRunning(context: Context, callback: AsyncCallback<void>): void; - -向系统申请取消长时任务,使用callback形式返回结果。 - -- **参数**: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | context | Context | 是 | 应用运行的上下文 | - | callback | AsyncCallback<void> | 是 | callback形式返回启动长时任务的结果 | - -- **示例**: -```js -import backgroundTaskManager from '@ohos.backgroundTaskManager'; -import featureAbility from '@ohos.ability.featureAbility'; - -function callback(err, data) { - if (err) { - console.error("Operation failed Cause: " + err); - } else { - console.info("Operation succeeded"); - } -} - -backgroundTaskManager.stopBackgroundRunning(featureAbility.getContext(), callback); - -``` - -## backgroundTaskManager.stopBackgroundRunning - -[8] stopBackgroundRunning(context: Context): Promise<void>; - -向系统申请取消长时任务,使用promise形式返回结果。 - -- **参数**: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | context | Context | 是 | 应用运行的上下文 | - -- **返回值** - | 类型 | 说明 | - | -------------- | ------------------------- | - | Promise\ | 使用Promise形式返回结果。 | - -- **示例**: -```js -import backgroundTaskManager from '@ohos.backgroundTaskManager'; -import featureAbility from '@ohos.ability.featureAbility'; - -backgroundTaskManager.stopBackgroundRunning(featureAbility.getContext()).then(() => { - console.info("Operation succeeded"); -}).catch((err) => { - console.error("Operation failed Cause: " + err); -}); - -``` - -## [8] BackgroundMode - -| 参数名 | 参数 | 描述 | -| ----------------------- | -------- | -------- | -| DATA_TRANSFER | 1 | 数据传输 | -| AUDIO_PLAYBACK | 2 | 音频播放 | -| AUDIO_RECORDING | 3 | 录音 | -| LOCATION | 4 | 定位导航 | -| BLUETOOTH_INTERACTION | 5 | 蓝牙相关 | -| MULTI_DEVICE_CONNECTION | 6 | 多设备互联 | -| WIFI_INTERACTION | 7 | WLAN相关(系统保留) | -| VOIP | 8 | 音视频通话(系统保留) | -| TASK_KEEPING | 9 | 计算任务(仅供PC使用) | \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-deque.md b/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-deque.md deleted file mode 100644 index 004b2ebb6568eab41201578bb814453182e09932..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-deque.md +++ /dev/null @@ -1,264 +0,0 @@ ---- -title: js-apis-deque -permalink: /pages/extra/e33666/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 线性容器Deque - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import Deque from '@ohos.util.Deque' -``` - -## 权限 - -无 - -## Deque - -### 属性 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| length | number | 是 | 否 | Deque的元素个数 | - -### constructor - -constructor(); - -Deque的构造函数。 - -- 示例: - ``` - let deque = new Deque(); - ``` - -### insertFront - -insertFront(element: T): void; - -在deque头部插入元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | element | T | 是 | 添加进去的元素 | - -- 示例: - ``` - let deque = new Deque; - deque.insertFront("a"); - deque.insertFront(1); - let b = [1, 2, 3]; - deque.insertFront(b); - let c = {name : "lala", age : "13"}; - deque.insertFront(false); - ``` -### insertEnd - -insertEnd(element: T): void; - -在deque尾部插入元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | element | T | 是 | 添加进去的元素 | - -- 示例: - ``` - let deque = new Deque; - deque.insertEnd("a"); - deque.insertEnd(1); - let b = [1, 2, 3]; - deque.insertEnd(b); - let c = {name : "lala", age : "13"}; - deque.insertEnd(false); - ``` -### has - -has(element: T): boolean; - -判断此Deque中是否含有该指定元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | element | T | 是 | 指定的元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 是否包含指定元素 | - -- 示例: - ``` - let deque = new Deque(); - deque.has("Ahfbrgrbgnutfodgorrogorg"); - deque.insertFront("Ahfbrgrbgnutfodgorrogorg"); - deque.has("Ahfbrgrbgnutfodgorrogorg"); - ``` -### popFirst - -popFirst(): T; - -删除并返回双端队列的首元素。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | T | 返回删除的元素 | - -- 示例: - ``` - let deque = new Deque(); - deque.insertFront(2); - deque.insertFront(4); - deque.insertEnd(5); - deque.insertFront(2); - deque.insertFront(4); - deque.popFirst(); - ``` -### popLast - -popLast(): T; - -删除并返回双端队列的尾元素。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | T | 返回删除的元素 | - -- 示例: - ``` - let deque = new Deque(); - deque.insertFront(2); - deque.insertEnd(4); - deque.insertFront(5); - deque.insertFront(2); - deque.insertFront(4); - deque.popLast(); - ``` - -### forEach -forEach(callbackfn: (value: T, index?: number, deque?: Deque<T>) => void, -thisArg?: Object): void; - -通过回调函数来遍历Deque实例对象上的元素以及元素对应的下标。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callbackfn | function | 是 | 回调函数 | - | thisArg | Object | 否 | callbackfn被调用时用作this值 | - -- callbackfn的参数说明 - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | T | 是 | 当前遍历到的元素 | - | index | number | 否 | 当前遍历到的下标值 | - | deque | Deque<T> | 否 | 当前调用forEach方法的实例对象 | - -- 示例: - ``` - let deque = new Deque(); - deque.insertFront(2); - deque.insertEnd(4); - deque.insertFront(5); - deque.insertEnd(4); - deque.forEach((value, index) => { - console.log(value, index); - }); - ``` - -### getFirst - -getFirst(): T; -获取Deque实例中的头元素。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | T | 返回T型 | - - -- 示例: - ``` - let deque = new Deque(); - deque.insertEnd(2); - deque.insertEnd(4); - deque.insertFront(5); - deque.insertFront(4); - deque.getFirst(); - ``` -### getLast - -getLast(): T; -获取Deque实例中的尾元素。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | T | 返回T型 | - - -- 示例: - ``` - let deque = new Deque(); - deque.insertFront(2); - deque.insertFront(4); - deque.insertFront(5); - deque.insertFront(4); - deque.getLast(); - ``` - -### [Symbol.iterator] - -[Symbol.iterator]\(): IterableIterator<T>; - - -返回一个迭代器,迭代器的每一项都是一个 JavaScript 对象,并返回该对象。 - - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | IterableIterator<T> | 返回一个迭代器。 | - - -- 示例: - ``` - let deque = new Deque(); - deque.insertFront(2); - deque.insertFront(4); - deque.insertFront(5); - deque.insertFront(4); - - // 使用方法一: - for (let item of deque) { - console.log(item); - } - - // 使用方法二: - let iter = deque[Symbol.iterator](); - let temp = iter.next().value; - while(temp != undefined) { - console.log(temp); - temp = iter.next().value; - } - ``` \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-emitter.md b/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-emitter.md deleted file mode 100644 index 8f57d320d237fbdf7e01da9a7e88de27d621da34..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-emitter.md +++ /dev/null @@ -1,157 +0,0 @@ ---- -title: js-apis-emitter -permalink: /pages/extra/07b733/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# Emitter - -> 说明:本模块首批接口从API version 7开始支持。 - -## 导入模块 - -```javascript -import emitter from '@ohos.events.emitter' -``` - -## 系统能力 - -```javascript -SystemCapability.Notification.Emitter -``` - -## 权限列表 - -无 - -## EventPriority - -用于表示事件被投递的优先级。 - -| 名称 | 值 | 说明 | -| --------- | ---- | ------------------------------------------------- | -| IMMEDIATE | 0 | 表示事件被立即投递 | -| HIGH | 1 | 表示事件先于LOW优先级投递 | -| LOW | 2 | 表示事件优于IDLE优先级投递,事件的默认优先级是LOW | -| IDLE | 3 | 表示在没有其他事件的情况下,才投递该事件 | - -## emitter.on - -on(event: [InnerEvent](#InnerEvent), callback: Callback\<[EventData](#EventData)\>): void - -持续订阅某个事件以及接收事件的回调处理。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ----------------------------------- | ---- | ------------------------ | -| event | [InnerEvent](#InnerEvent) | 是 | 持续订阅的事件 | -| callback | Callback\<[EventData](#EventData)\> | 是 | 接收订阅事件时的回调处理 | - -**示例:** - -```javascript -var innerEvent = { - eventId : 1 -}; -var callback = (eventData) => { - console.info('callback'); -}; -emitter.on(innerEvent, callback); -``` - -## emitter.once - -once(event: [InnerEvent](#InnerEvent), callback: Callback\<[EventData](#EventData)\>): void - -单次订阅某个事件以及接收事件的回调处理,接收到回调处理后自动取消订阅。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ----------------------------------- | ---- | ------------------------ | -| event | [InnerEvent](#InnerEvent) | 是 | 单次订阅的事件 | -| callback | Callback\<[EventData](#EventData)\> | 是 | 接收订阅事件时的回调处理 | - -**示例:** - -```javascript -var innerEvent = { - eventId : 1 -}; -var callback = (eventData) => { - console.info('once callback'); -}; -emitter.once(innerEvent, callback); -``` - -## emitter.off - -off(eventId: number): void - -取消订阅某个事件。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------- | ------ | ---- | -------------- | -| eventId | number | 是 | 单次订阅的事件 | - -**示例:** - -```javascript -emitter.off(1); -``` - -## emitter.emit - -emit(event: InnerEvent, data?: EventData): void - -发送一个事件到事件队列。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ------------------------- | ---- | -------------- | -| event | [InnerEvent](#InnerEvent) | 是 | 发送的事件 | -| data | [EventData](#EventData) | 否 | 事件携带的数据 | - -**示例:** - -```javascript -var eventData = { - data: { - 1:"t", - 'content':"c", - "id":1, - }}; -var innerEvent = { - eventId : 1, - priority: emitter.EventPriority.HIGH -}; -emitter.emit(innerEvent, eventData); -``` - -## InnerEvent - -进程内的事件。 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | ------------------------------- | ---- | ---- | ---------------------------------- | -| eventId | number | 是 | 是 | 事件的ID,由开发者定义用来辨别事件 | -| priority | [EventPriority](#EventPriority) | 是 | 是 | 事件被投递的优先级 | - -## EventData - -发送事件时传递的数据。 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| ---- | ------------------ | ---- | ---- | -------------- | -| data | [key: string]: any | 是 | 是 | 事件携带的数据 | diff --git a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-extension-context.md b/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-extension-context.md deleted file mode 100644 index 16100a8542e0abd96fa8215a4c821a3c4a74d82f..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-extension-context.md +++ /dev/null @@ -1,27 +0,0 @@ ---- -title: js-apis-extension-context -permalink: /pages/extra/5b65a4/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# ExtensionContext - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -Extension的上下文环境,继承自Context。 - - -## 属性 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| currentHapModuleInfo | HapModuleInfo | 是 | 否 | 当前Hap包的信息。 | diff --git a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-filemanager.md b/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-filemanager.md deleted file mode 100644 index dfbf62f14814d06319e2837f57fb90d3e1ea06ed..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-filemanager.md +++ /dev/null @@ -1,261 +0,0 @@ ---- -title: js-apis-filemanager -permalink: /pages/extra/39495c/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 公共文件访问与管理 ->![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** ->本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 -## 导入模块 - -```js -import filemanager from 'ohos.filemanager' -``` - -## 系统能力 - -SystemCapability.FileManagement.FileManagerService - -## filemanager.getRoot - -getRoot(options? : {dev? : DevInfo}) : Promise<FileInfo[]> - -以异步方法获取第一层相册,目录信息。使用promise形式返回结果。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | --- | --- | --- | -- | - | dev | [DevInfo](#devinfo) | 否 | 设备名, 不填为默认值dev = {name: "local"}, 当前仅支持设备'local' | - -- 返回值 - - | 类型 | 说明 | - | --- | -- | - | Promise<[FileInfo](#fileinfo)[]> | 第一层目录相册信息 | - -- 示例 - -```js -filemanager.getRoot() -.then((fileInfo) => { - if(Array.isArray(fileInfo)) { - for (var i = 0; i < fileInfo.length; i++) { - console.log(JSON.Stringify(fileInfo)) - } - } -}) -.catch((err) => { - console.log(err) -}) -``` - -## filemanager.getRoot - -getRoot(options? : {dev? : DevInfo}, callback : AsyncCallback<FileInfo[]>) : void - -以异步方法获取第一层相册,目录信息。使用callback形式返回结果。 - -- 参数 - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | ------------------------- | ---- | ----------------------------- | - | dev | [DevInfo](#devinfo) | 否 | 设备名, 不填为默认值dev = {name: "local"}, 当前仅支持设备'local' | - | callback | AsyncCallback<[FileInfo](#fileinfo)[]> | 是 | 异步获取文件的信息之后的回调 | - -- 示例 - -```js -filemanager.getRoot((err, fileInfo) => { - if(Array.isArray(fileInfo)) { - for (var i = 0; i < fileInfo.length; i++) { - console.log(JSON.Stringify(fileInfo)) - } - } -}) -``` - -## filemanager.listFile - -listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : number, count? : number}) : Promise<FileInfo[]> - -以异步方法获取获取第二层相册,文件信息。使用promise形式返回结果。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | --- | --- | --- | -- | - | type | string | 是 | 待查询文件类型, 支持以下类型 "file", "image", "audio", "video" | - | path | string | 是 | 待查询目录uri | - | dev | [DevInfo](#devinfo) | 是 | 设备名, 不填为默认值dev = {name: "local"}, 当前仅支持设备'local' | - | offset | number | 否 | 待查询文件偏移 | - | count | number | 否 | 待查询文件个数 | - -- 返回值 - - | 类型 | 说明 | - | --- | -- | - | Promise<FileInfo[]> | 文件信息 | - -- 异常 - | 错误名称 | 错误类型 | 错误码 |说明 | - | --- | -- | --- | -- | - | 对应的目录、相册不存在 | No such file or directory | 2 | uri对应的目录、相册不存在 | - | 获取FMS服务失败 | No such process | 3 | 获取FMS服务失败 | - | path对应uri不是相册、目录 | Not a directory | 20 | path对应uri不是相册、目录 | - -```js -// 获取目录下所有文件 -// 通过listFile、getRoot获取的文件uri -let media_path = file.uri -filemanager.listFile(media_path, "file") -.then((fileInfo) => { - if(Array.isArray(fileInfo)) { - for (var i = 0; i < fileInfo.length; i++) { - console.log(JSON.Stringify(fileInfo)) - } - } -}) -.catch((err) => { - console.log(err) -}) -``` -## filemanager.listFile - -listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : number, count? : number}, callback : AsyncCallback<FileInfo[]>) : void - -以异步方法获取获取第二层相册,文件信息。使用callback形式返回结果。 - -- 参数 - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | ------------------------- | ---- | ------------------------------------------------------------ | - | type | string | 是 | 待查询文件类型, 支持以下类型 "file", "image", "audio", "video" | - | path | string | 是 | 待查询目录uri | - | dev | [DevInfo](#devinfo) | 否 | 设备名, 不填为默认值dev = {name: "local"}, 当前仅支持设备'local' | - | offset | number | 否 | 待查询文件偏移 | - | count | number | 否 | 待查询文件个数 | - | callback | AsyncCallback<[FileInfo](#fileinfo)[]> | 是 | 异步获取文件的信息之后的回调 | -- 异常 - - | 错误名称 | 错误类型 | 错误码 | 说明 | - | ------------------------- | ------------------------- | ------ | ------------------------- | - | 对应的目录、相册不存在 | No such file or directory | 2 | uri对应的目录、相册不存在 | - | 获取FMS服务失败 | No such process | 3 | 获取FMS服务失败 | - | path对应uri不是相册、目录 | Not a directory | 20 | path对应uri不是相册、目录 | - -```js -// 通过listFile、getRoot获取的文件uri -let media_path = file.uri -filemanager.listFile(media_path, "file", (err, fileInfo) => { - if(Array.isArray(fileInfo)) { - for (var i = 0; i < fileInfo.length; i++) { - console.log(JSON.Stringify(fileInfo)) - } - } -}) -``` - -## filemanager.createFile - -filemanager.createFile(path : string, filename : string, options? : {dev? : DevInfo}) : promise<string> - -以异步方法创建文件到指定路径,返回文件uri。使用promise形式返回结果。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | --- | --- | --- | -- | - | filename | string | 是 | 待创建的文件名 | - | path | string | 是 | 待保存目的相册uri | - | dev | [DevInfo](#devinfo) | 否 | 设备名, 不填为默认值dev = {name: "local"}, 当前仅支持设备'local' | - -- 返回值 - - | 类型 | 说明 | - | --- | -- | - | string | 文件uri | - -- 异常 - | 错误名称 | 错误类型 | 错误码 |说明 | - | --- | -- | --- | -- | - | 创建文件不允许 | Operation not permitted | 1 | 已有重名文件 | - | 对应的目录、相册不存在 | No such file or directory | 2 | uri对应的目录、相册不存在 | - | 获取FMS服务失败 | No such process | 3 | 获取FMS服务失败 | - | path对应uri不是相册、目录 | Not a directory | 20 | path对应uri不是相册、目录 | - -```js -// 创建文件,返回文件uri -let media_path = file.uri // 通过listFile、getRoot获取的文件uri -let name = "xxx.jpg" // 待保存文件的后缀 -filemanager.createFile(media_path, name) -.then((uri) => { -// 返回uri给应用 -}) -.catch((err) => { - console.log(err) -}) -``` - -## filemanager.createFile - -createFile(path : string, filename: string, options? : {dev? : DevInfo}, callback : AsyncCallback<string>) : void - -以异步方法创建文件到指定路径,返回文件uri。使用callback形式返回结果。 - -- 参数 - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | ------------------------- | ---- | ----------------------------- | - | filename | string | 是 | 待创建的文件名 | - | path | string | 是 | 待保存目的相册uri | - | dev | [DevInfo](#devinfo) | 否 | 设备名, 不填为默认值dev = {name: "local"}, 当前仅支持设备'local' | - | callback | AsyncCallback<[FileInfo](#fileinfo)[]> | 是 | 异步获取文件的信息之后的回调 | - -- 异常 - - | 错误名称 | 错误类型 | 错误码 | 说明 | - | ------------------------- | ------------------------- | ------ | ------------------------- | - | 创建文件不允许 | Operation not permitted | 1 | 已有重名文件 | - | 对应的目录、相册不存在 | No such file or directory | 2 | uri对应的目录、相册不存在 | - | 获取FMS服务失败 | No such process | 3 | 获取FMS服务失败 | - | path对应uri不是相册、目录 | Not a directory | 20 | path对应uri不是相册、目录 | - -```js -// 创建文件,返回文件uri -// 通过listFile、getRoot获取的文件uri -let media_path = file.uri -// 待保存文件的后缀 -let name = "xxx.jpg" -filemanager.createFile(media_path, name, (err, uri) => { -// 返回uri给应用 -}) -``` - -## FileInfo -文件信息类型,通过getRoot, listFile等接口返回的类型。 - -### 属性 - -| 参数名 | 类型 | 可读 | 可写 | 说明 | -| --- | -- | -- | -- | -- | -| name | string | 是 | 否 | 文件名称 | -| path | string | 是 | 否 | 文件Uri | -| type | string | 是 | 否 | 文件类型 | -| size | number | 是 | 否 | 文件大小 | -| addedTime | number | 是 | 否 | 媒体插入时间 | -| modifiedTime | number | 是 | 否 | 媒体修改时间 | - -## DevInfo -设备类型,配置接口访问的设备类型。 - -### 属性 - - | 参数名 | 类型 | 可读 | 可写 | 说明 | - | --- | -- | -- | -- | -- | - | name | string | 是 | 是 | 设备名称 | \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-formbindingdata.md b/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-formbindingdata.md deleted file mode 100644 index 789fd6447702133737a45bdd064d7e0983044bb2..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-formbindingdata.md +++ /dev/null @@ -1,64 +0,0 @@ ---- -title: js-apis-formbindingdata -permalink: /pages/extra/6d5675/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 卡片数据绑定类 - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - -## 导入模块 - -``` -import formBindingData from '@ohos.application.formBindingData'; -``` - -## 权限 - -无 - -## formBindingData.createFormBindingData - -createFormBindingData(obj?: Object | string): FormBindingData - -创建一个FormBindingData对象。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | ------ | -------------- | ---- | ------------------------------------------------------------ | - | obj | Object或string | 否 | js卡片要展示的数据。可以是包含若干键值对的Object或者 json 格式的字符串。 | - - - -- 返回值: - - | 类型 | 说明 | - | ----------------------------------- | --------------------------------------- | - | [FormBindingData](#formbindingdata) | 根据传入数据创建的FormBindingData对象。 | - - - -- 示例: - - ``` - let obj = {"temperature": "21°"}; - let formBindingDataObj = formBindingData.createFormBindingData(obj); - ``` - -## FormBindingData - -FormBindingData相关描述。 - -| 名称 | 类型 | 说明 | -| ---- | -------------- | ------------------------------------------------------------ | -| obj | Object或string | js卡片要展示的数据。可以是包含若干键值对的Object或者 json 格式的字符串。 | \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-formextension.md b/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-formextension.md deleted file mode 100644 index 827bac8abfc722784088da2cdc62ba54dac1baef..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-formextension.md +++ /dev/null @@ -1,184 +0,0 @@ ---- -title: js-apis-formextension -permalink: /pages/extra/bd7e64/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# FormExtension - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - -提供FormExtension卡片扩展相关接口。 - -## 导入模块 - -``` -import FormExtension from '@ohos.application.FormExtension'; -``` - -## 权限 - -无 - -## 属性 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| ------- | ------------------------------------------------------- | ---- | ---- | --------------------------------------------------- | -| context | [FormExtensionContext](/pages/extra/5cbbb2/) | 是 | 否 | FormExtension的上下文环境,继承自ExtensionContext。 | - -## onCreate - -onCreate(want: Want): formBindingData.FormBindingData - -卡片提供方接收创建卡片的通知接口。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | ------ | -------------------------------------- | ---- | ------------------------------------------------------------ | - | want | [Want](/pages/010c010101#want) | 是 | 当前Extension相关的Want类型信息,包括卡片ID、卡片名称、卡片样式等。这些卡片信息必须作为持久数据进行管理,以便后续更新和删除卡片。 | - -- 返回值: - - | 类型 | 说明 | - | ------------------------------------------------------------ | ----------------------------------------------------------- | - | [formBindingData.FormBindingData](/pages/extra/6d5675/#formbindingdata) | 一个formBindingData.FormBindingData对象,卡片要显示的数据。 | - -- 示例: - - ``` - onCreate(want) { - console.log('FormExtension onCreate, want:' + want.abilityName); - let dataObj1 = { - temperature:"11c", - "time":"11:00" - }; - let obj1 = formBindingData.createFormBindingData(dataObj1); - return obj1; - } - ``` - -## onCastToNormal - -onCastToNormal(formId: string): void - -卡片提供方接收临时卡片转常态卡片的通知接口。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | ------ | ------ | ---- | ------------------------ | - | formId | string | 是 | 请求转换为常态的卡片ID。 | - -- 示例: - - ``` - onCastToNormal(formId) { - console.log('FormExtension onCastToNormal, formId:' + formId); - } - ``` - -## onUpdate - -onUpdate(formId: string): void - -卡片提供方接收更新卡片的通知接口。获取最新数据后调用[FormExtensionContext](/pages/extra/5cbbb2/)的updateForm接口刷新卡片数据。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | ------ | ------ | ---- | ------------------ | - | formId | string | 是 | 请求更新的卡片ID。 | - -- 示例: - - ``` - onUpdate(formId) { - console.log('FormExtension onUpdate, formId:' + formId); - let obj2 = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"}); - this.context.updateForm(formId, obj2) - .then((data)=>{ - console.log('FormExtension context updateForm, data:' + data); - }).catch((error) => { - console.error('Operation updateForm failed. Cause: ' + error);}); - } - ``` - -## onVisibilityChange - -onVisibilityChange(newStatus: { [key: string]: number }): void - -卡片提供方接收修改可见性的通知接口。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | --------- | ------------------------- | ---- | ---------------------------- | - | newStatus | { [key: string]: number } | 是 | 请求修改的卡片ID和可见状态。 | - -- 示例: - - ``` - onVisibilityChange(newStatus) { - console.log('FormExtension onVisibilityChange, newStatus:' + newStatus); - let obj2 = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"}); - - for (let key in newStatus) { - console.log('FormExtension onVisibilityChange, key:' + key + ", value=" + newStatus[key]); - this.context.updateForm(key, obj2) - .then((data)=>{ - console.log('FormExtension context updateForm, data:' + data); - }).catch((error) => { - console.error('Operation updateForm failed. Cause: ' + error);}); - } - } - ``` - -## onEvent - -onEvent(formId: string, message: string): void - -卡片提供方接收处理卡片事件的通知接口。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | ------- | ------ | ---- | ---------------------- | - | formId | string | 是 | 请求触发事件的卡片ID。 | - | message | string | 是 | 事件消息。 | - -- 示例: - - ``` - onEvent(formId, message) { - console.log('FormExtension onEvent, formId:' + formId + ", message:" + message); - } - ``` - -## onDestroy - -onDestroy(formId: string): void - -卡片提供方接收销毁卡片的通知接口。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | ------ | ------ | ---- | ------------------ | - | formId | string | 是 | 请求销毁的卡片ID。 | - -- 示例: - - ``` - onDestroy(formId) { - console.log('FormExtension onDestroy, formId:' + formId); - } - ``` \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-formextensioncontext.md b/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-formextensioncontext.md deleted file mode 100644 index 28f50b0b52a289b3e9710033c168a68ee509d49b..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-formextensioncontext.md +++ /dev/null @@ -1,72 +0,0 @@ ---- -title: js-apis-formextensioncontext -permalink: /pages/extra/5cbbb2/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# FormExtensionContext - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - -FormExtension的上下文环境,提供FormExtension具有的能力和接口,继承自ExtensionContext。 - -## updateForm - -updateForm(formId: string, formBindingData: formBindingData.FormBindingData, callback: AsyncCallback\): void - -主动更新卡片。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | --------------- | ------------------------------------------------------------ | ---- | -------------------------------------- | - | formId | string | 是 | 请求更新的卡片ID。 | - | formBindingData | [formBindingData.FormBindingData](/pages/extra/6d5675/#formbindingdata) | 是 | 卡片新的数据。 | - | callback | AsyncCallback\ | 是 | 回调函数,返回接口调用是否成功的结果。 | - -- 示例: - - ``` - let obj2 = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"}); - this.context.updateForm(formId, obj2, (data)=>{ - console.log('FormExtension context updateForm, data:' + data); - }); - ``` - -## updateForm - -updateForm(formId: string, formBindingData: formBindingData.FormBindingData): Promise\ - -更新卡片。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | --------------- | ------------------------------------------------------------ | ---- | ------------------ | - | formId | string | 是 | 请求更新的卡片ID。 | - | formBindingData | [formBindingData.FormBindingData](/pages/extra/6d5675/#formbindingdata) | 是 | 卡片新的数据。 | - -- 返回值: - - | 类型 | 说明 | - | -------------- | --------------------------------- | - | Promise\ | 返回一个Promise,包含接口的结果。 | - -- 示例: - - ``` - let obj2 = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"}); - this.context.updateForm(formId, obj2) - .then((data)=>{ - console.log('FormExtension context updateForm, data:' + data); - }).catch((error) => { - console.error('Operation updateForm failed. Cause: ' + error);}); - ``` \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-hashmap.md b/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-hashmap.md deleted file mode 100644 index da2ed6ad7687c6b17e08c989a9627ae72cd09f26..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-hashmap.md +++ /dev/null @@ -1,393 +0,0 @@ ---- -title: js-apis-hashmap -permalink: /pages/extra/c53422/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 非线性容器HashMap - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import HashMap from '@ohos.util.HashMap' -``` - - -## 权限 - -无 - -## HashMap - - -### 属性 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| length | number | 是 | 否 | HashMap的元素个数 | - - -### constructor - -constructor(); - -HashMap的构造函数。 - -- 示例: - ``` - let hashMap = new HashMap(); - ``` - - -### isEmpty - -isEmpty(): boolean; - -判断该HashMap是否为空。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 为空返回true, 不为空返回false | - -- 示例: - ``` - const hashMap = new HashMap(); - hashMap.isEmpty(); - ``` - - -### hasKey - -hasKey(key: K): boolean; - -判断此HashMap中是否含有该指定key。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | K | 是 | 指定元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 是否包含指定元素 | - -- 示例: - ``` - let hashMap = new HashMap(); - hashMap.hasKey("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - hashMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - hashMap.hasKey("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - ``` - - -### hasValue - -hasValue(value: V): boolean; - -判断此HashMap中是否含有该指定value。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | V | 是 | 指定元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 是否包含指定元素 | - -- 示例: - ``` - let hashMap = new HashMap(); - hashMap.hasValue(123); - hashMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - hashMap.hasValue(123); - ``` - - -### get - -get(key: K): V; - -获取指定key所对应的value。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | K | 是 | 查找的指定key | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | V | 返回key映射的value值 | - -- 示例: - ``` - let hashMap = new HashMap(); - hashMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - hashMap.set("sdfs", 356); - hashMap.get("sdfs"); - ``` - - -### setAll - -setAll(map: HashMap): void; - -将一个HashMap中的所有元素组添加到另一个hashmap中。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | map | HashMap | 是 | 被添加元素的hashmap | - -- 示例: - ``` - let hashMap = new HashMap(); - hashMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - hashMap.set("sdfs", 356); - let newHashMap = new HashMap(); - hashMap.setAll(newHashMap); - ``` - - -### set - -set(key: K, value: V): Object; - -向HashMap中添加一组数据。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | K | 是 | 添加成员数据的键名 | - | value | V | 是 | 添加成员数据的值 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Object | 返回添加后的hashmap | - -- 示例: - ``` - let hashMap = new HashMap(); - hashMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - ``` - - -### remove - -remove(key: K): V; - -删除指定的元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | K | 是 | 依据key指定删除的元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | V | 返回删除元素的值 | - -- 示例: - ``` - let hashMap = new HashMap(); - hashMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - hashMap.set("sdfs", 356); - hashMap.remove("sdfs"); - ``` - - -### clear - -clear(): void; - -清除HashMap中的所有元素,并把length置为0。 - -- 示例: - ``` - let hashMap = new HashMap(); - hashMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - hashMap.set("sdfs", 356); - hashMap.clear(); - ``` - - -### keys - -keys(): IterableIterator<K>; - -返回包含此映射中包含的键的新迭代器对象。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | IterableIterator<K> | 返回一个迭代器 | - -- 示例: - ``` - let hashMap = new HashMap(); - hashMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - hashMap.set("sdfs", 356); - let iter = hashMap.keys(); - let temp = iter.next().value; - while(temp != undefined) { - console.log(temp); - temp = iter.next().value; - } - ``` - - -### values - -values(): IterableIterator<V>; - -返回包含此映射中包含的键的新迭代器对象。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | IterableIterator<V> | 返回一个迭代器 | - -- 示例: - ``` - let hashMap = new HashMap(); - hashMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - hashMap.set("sdfs", 356); - let iter = hashMap.values(); - let temp = iter.next().value; - while(temp != undefined) { - console.log(temp); - temp = iter.next().value; - } - ``` - - -### replace - -replace(key: K, value: V): boolean; - -对HashMap中一组数据进行更新(替换)。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | K | 是 | 依据key指定替换的元素 | - | value | V | 是 | 添加成员数据的值 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 是否成功对已有数据进行替换 | - -- 示例: - ``` - let hashMap = new HashMap(); - hashMap.set("sdfs", 123); - hashMap.replace("sdfs", 357); - ``` - - -### forEach - -forEach(callbackfn: (value: V, key?: K, hashMap?: HashMap) => void, thisArg?: Object): void; - -通过回调函数来遍历HashMap实例对象上的元素以及元素对应的下标。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callbackfn | function | 是 | 回调函数 | - | thisArg | Object | 否 | callbackfn被调用时用作this值 | - -- callbackfn的参数说明 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | V | 是 | 当前遍历到的元素键值对的值 | - | key | K | 是 | 当前遍历到的元素键值对的键 | - | hashMap | HashMap | 否 | 当前调用forEach方法的实例对象 | - -- 示例: - ``` - let hashMap = new HashMap(); - hashMap.set("sdfs", 123); - hashMap.set("dfsghsf", 357); - hashMap.forEach((value, key) => { - console.log(value, key); - }); - ``` - - -### entries - -entries(): IterableIterator<[K, V]>; - -返回包含此映射中包含的键的新迭代器对象。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | IterableIterator<[K, V]> | 返回一个迭代器 | - -- 示例: - ``` - let hashMap = new HashMap(); - hashMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - hashMap.set("sdfs", 356); - let iter = hashMap.entries(); - let temp = iter.next().value; - while(temp != undefined) { - console.log(temp[0]); - console.log(temp[1]); - temp = iter.next().value; - } - ``` - - -### [Symbol.iterator] - -[Symbol.iterator]\(): IterableIterator<[K, V]>; - -返回一个迭代器,迭代器的每一项都是一个 JavaScript 对象,并返回该对象。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | IterableIterator<[K, V]> | 返回一个迭代器 | - -- 示例: - ``` - let hashMap = new HashMap(); - hashMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - hashMap.set("sdfs", 356); - - // 使用方法一: - for (let item of hashMap) { - console.log("key: " + item[0]); - console.log("value: " + item[1]); - } - - // 使用方法二: - let iter = hashMap[Symbol.iterator](); - let temp = iter.next().value; - while(temp != undefined) { - console.log(temp[0]); - console.log(temp[1]); - temp = iter.next().value; - } - ``` \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-hashset.md b/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-hashset.md deleted file mode 100644 index c8c4025f392065dd7c688ff2adbe7f350d465688..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-hashset.md +++ /dev/null @@ -1,268 +0,0 @@ ---- -title: js-apis-hashset -permalink: /pages/extra/256434/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 非线性容器HashSet - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import HashSet from '@ohos.util.HashSet'; -``` - -## 权限 - -无 - -## HashSet - - -### 属性 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| length | number | 是 | 否 | HashSet的元素个数 | - - -### constructor - -constructor(); - -HashSet的构造函数。 - -- 示例: - ``` - let hashSet = new HashSet(); - ``` - - -### isEmpty - -isEmpty(): boolean; - -判断该HashSet是否为空。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 为空返回true, 不为空返回false | - -- 示例: - ``` - const hashSet = new HashSet(); - hashSet.isEmpty(); - ``` - - -### has - -has(value: T): boolean; - -判断此HashSet中是否含有该指定key。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | T | 是 | 指定元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 是否包含指定元素 | - -- 示例: - ``` - let hashSet = new HashSet(); - hashSet.has("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - hashSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - hashSet.has("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - ``` - - -### add - -add(value: T): boolean; - -向HashSet中添加数据。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | T | 是 | 添加成员数据 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 返回是否有成功增加元素 | - -- 示例: - ``` - let hashSet = new HashSet(); - hashSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - ``` - - -### remove - -remove(value: T): boolean; - -删除指定的元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | T | 是 | 指定删除的元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 返回是否成功删除指定元素 | - -- 示例: - ``` - let hashSet = new HashSet(); - hashSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - hashSet.add("sdfs"); - hashSet.remove("sdfs"); - ``` - - -### clear - -clear(): void; - -清除HashSet中的所有元素,并把length置为0。 - -- 示例: - ``` - let hashSet = new HashSet(); - hashSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - hashSet.add("sdfs"); - hashSet.clear(); - ``` - - -### values - -values(): IterableIterator<T>; - -返回包含此映射中包含的键的新迭代器对象。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | IterableIterator<T> | 返回一个迭代器 | - -- 示例: - ``` - let hashSet = new HashSet(); - hashSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - hashSet.add("sdfs"); - let iter = hashSet.values(); - let temp = iter.next().value; - while(temp != undefined) { - console.log(temp); - temp = iter.next().value; - } - ``` - - -### forEach - -forEach(callbackfn: (value: T, key?: T, hashSet?: HashSet<T>) => void, thisArg?: Object): void; - -通过回调函数来遍历实例对象上的元素以及元素对应的下标。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callbackfn | function | 是 | 回调函数 | - | thisArg | Object | 否 | callbackfn被调用时用作this值 | - -- callbackfn的参数说明 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | T | 是 | 当前遍历到的元素键值对的值 | - | key | T | 否 | 当前遍历到的元素键值对的值(和value相同) | - | hashSet | HashSet<T> | 否 | 当前调用forEach方法的实例对象 | - - -- 示例: - ``` - let hashSet = new HashSet(); - hashSet.add("sdfs"); - hashSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - hashSet.forEach((value, key) => { - console.log(value, key); - }); - ``` - - -### entries -entries(): IterableIterator<[T, T]>; - -返回包含此映射中包含的键的新迭代器对象。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | IterableIterator<[T, T]> | 返回一个迭代器 | - -- 示例: - ``` - let hashSet = new HashSet(); - hashSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - hashSet.add("sdfs"); - let iter = hashSet.entries(); - let temp = iter.next().value; - while(temp != undefined) { - console.log(temp[0]); - console.log(temp[1]); - temp = iter.next().value; - } - ``` - - -### [Symbol.iterator] - -[Symbol.iterator]\(): IterableIterator<T>; - -返回一个迭代器,迭代器的每一项都是一个 JavaScript 对象,并返回该对象。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | IterableIterator<T> | 返回一个迭代器 | - -- 示例: - ``` - let hashSet = new HashSet(); - hashSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - hashSet.add("sdfs"); - - // 使用方法一: - for (let item of hashSet) { - console.log("value: " + item); - } - - // 使用方法二: - let iter = hashSet[Symbol.iterator](); - let temp = iter.next().value; - while(temp != undefined) { - console.log(temp); - temp = iter.next().value; - } - ``` \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-lightweightmap.md b/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-lightweightmap.md deleted file mode 100644 index ebce65040e6ab0564e00b837c9498db601a44b98..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-lightweightmap.md +++ /dev/null @@ -1,564 +0,0 @@ ---- -title: js-apis-lightweightmap -permalink: /pages/extra/6cbba8/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 非线性容器LightWeightMap - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import LightWeightMap from '@ohos.util.LightWeightMap' -``` - - -## 权限 - -无 - -## LightWeightMap - - -### 属性 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| length | number | 是 | 否 | LightWeightMap的元素个数 | - - -### constructor - -constructor(); - -LightWeightMap的构造函数。 - -- 示例: - ``` - let lightWeightMap = new LightWeightMap(); - ``` - - -### isEmpty - -isEmpty(): boolean; - -判断该LightWeightMap是否为空。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 为空返回true, 不为空返回false | - -- 示例: - ``` - const lightWeightMap = new LightWeightMap(); - lightWeightMap.isEmpty(); - ``` - - -### hasAll - -hasAll(map: LightWeightMap): boolean; - -判断此LightWeightMap中是否含有该指定map中的所有元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | map | LightWeightMap | 是 | 比较对象 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 是否包含所有元素 | - -- 示例: - ``` - let lightWeightMap = new LightWeightMap(); - lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - lightWeightMap.set("sdfs", 356); - let map = new LightWeightMap(); - map.set("sdfs", 356); - let result = lightWeightMap.hasAll(map); - ``` - - -### hasKey - -hasKey(key: K): boolean; - -判断此LightWeightMap中是否含有该指定key。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | K | 是 | 指定元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 是否包含指定元素 | - -- 示例: - ``` - let lightWeightMap = new LightWeightMap(); - lightWeightMap.hasKey("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - lightWeightMap.hasKey("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - ``` - - -### hasValue - -hasValue(value: V): boolean; - -判断此LightWeightMap中是否含有该指定value。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | V | 是 | 指定元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 是否包含指定元素 | - -- 示例: - ``` - let lightWeightMap = new LightWeightMap(); - lightWeightMap.hasValue(123); - lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - lightWeightMap.hasValue(123); - ``` - - -### increaseCapacityTo - -increaseCapacityTo(minimumCapacity: number): void; - -将当前LightWeightMap扩容至可以容纳指定数量元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | minimumCapacity | number | 是 | 需要容纳数量 | - - -- 示例: - ``` - let lightWeightMap = new LightWeightMap(); - lightWeightMap.increaseCapacityTo(10); - ``` - - -### get - -get(key: K): V; - -获取指定key所对应的value。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | K | 是 | 查找的指定key | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | V | 返回key映射的value值 | - -- 示例: - ``` - let lightWeightMap = new LightWeightMap(); - lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - lightWeightMap.set("sdfs", 356); - lightWeightMap.get("sdfs"); - ``` - - -### getIndexOfKey - -getIndexOfKey(key: K): number; - -查找指定元素第一次出现的下标值,如果没有找到该元素返回-1。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | K | 是 | 被查找的元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 返回指定元素第一次出现时的下标值,查找失败返回-1 | - -- 示例: - ``` - let lightWeightMap = new LightWeightMap(); - lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - lightWeightMap.set("sdfs", 356); - lightWeightMap.getIndexOfKey("sdfs"); - ``` - - -### getIndexOfValue - -getIndexOfValue(value: V): number; - -查找指定元素第一次出现的下标值,如果没有找到该元素返回-1。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | V | 是 | 被查找的元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 返回指定元素第一次出现时的下标值,查找失败返回-1 | - -- 示例: - ``` - let lightWeightMap = new LightWeightMap(); - lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - lightWeightMap.set("sdfs", 356); - lightWeightMap.getIndexOfValue(123); - ``` - - -### getKeyAt - -getKeyAt(index: number): K; - -查找指定下标的元素键值对中key值,否则返回undefined。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | index | number | 是 | 所查找的下标 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | K | 返回该下标对应的元素键值对中key值 | - -- 示例: - ``` - let lightWeightMap = new LightWeightMap(); - lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - lightWeightMap.set("sdfs", 356); - lightWeightMap.getKeyAt(1); - ``` - - -### setAll - -setAll(map: LightWeightMap): void; - -将一个LightWeightMap中的所有元素组添加到另一个lightweightmap中。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | map | LightWeightMap | 是 | 被添加元素的lightweightmap | - -- 示例: - ``` - let lightWeightMap = new LightWeightMap(); - lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - lightWeightMap.set("sdfs", 356); - let map = new LightWeightMap(); - lightWeightMap.setAll(map); - ``` - - -### set -set(key: K, value: V): Object; - -向LightWeightMap中添加一组数据。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | K | 是 | 添加成员数据的键名 | - | value | V | 是 | 添加成员数据的值 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Object | 返回添加后的hashmap | - -- 示例: - ``` - let lightWeightMap = new LightWeightMap(); - lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - ``` - - -### remove - -remove(key: K): V; - -删除指定的元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | K | 是 | 依据key指定删除的元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | V | 返回删除元素的值 | - -- 示例: - ``` - let lightWeightMap = new LightWeightMap(); - lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - lightWeightMap.set("sdfs", 356); - lightWeightMap.remove("sdfs"); - ``` - - -### removeAt - -removeAt(index: number): boolean; - -删除指定下标的元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | index | number | 是 | 指定想要删除元素下标 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 确认是否成功删除元素 | - -- 示例: - ``` - let lightWeightMap = new LightWeightMap(); - lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - lightWeightMap.set("sdfs", 356); - lightWeightMap.removeAt(1); - ``` - - -### setValueAt - -setValueAt(index: number, newValue: V): boolean; - -向LightWeightMap中具体位置替换键值对中的值。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | index | number | 是 | 指定替换数据下标 | - | newValue | V | 是 | 替换键值对中的值 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 是否成功替换指定位置数据 | - -- 示例: - ``` - let lightWeightMap = new LightWeightMap(); - lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - lightWeightMap.set("sdfs", 356); - lightWeightMap.setValueAt(1, 3546); - ``` - - -### getValueAt - -getValueAt(index: number): V; - -获取LightWeightMap中具体位置键值对中的值。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | index | number | 是 | 指定查询数据下标 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | V | 返回指定位置中键值对的值 | - -- 示例: - ``` - let lightWeightMap = new LightWeightMap(); - lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - lightWeightMap.set("sdfs", 356); - lightWeightMap.getValueAt(1); - ``` - - -### clear - -clear(): void; - -清除LightWeightMap中的所有元素,并把length置为0。 - -- 示例: - ``` - let lightWeightMap = new LightWeightMap(); - lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - lightWeightMap.set("sdfs", 356); - lightWeightMap.clear(); - ``` - - -### keys - -keys(): IterableIterator<K>; - -返回包含此映射中包含的键的新迭代器对象。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | IterableIterator<K> | 返回一个迭代器 | - -- 示例: - ``` - let lightWeightMap = new LightWeightMap(); - lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - lightWeightMap.set("sdfs", 356); - let iter = lightWeightMap.keys(); - let temp = iter.next().value; - while(temp != undefined) { - console.log(temp); - temp = iter.next().value; - } - ``` - - -### values - -values(): IterableIterator<V>; - -返回包含此映射中包含的键的新迭代器对象。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | IterableIterator<V> | 返回一个迭代器 | - -- 示例: - ``` - let lightWeightMap = new LightWeightMap(); - lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - lightWeightMap.set("sdfs", 356); - let iter = lightWeightMap.values(); - let temp = iter.next().value; - while(temp != undefined) { - console.log(temp); - temp = iter.next().value; - } - ``` - - -### forEach - -forEach(callbackfn: (value: V, key?: K, lightWeightMap?: LightWeightMap) => void, thisArg?: Object): void; - -通过回调函数来遍历实例对象上的元素以及元素对应的下标。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callbackfn | function | 是 | 回调函数 | - | thisArg | Object | 否 | callbackfn被调用时用作this值 | - -- callbackfn的参数说明 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | V | 是 | 当前遍历到的元素键值对的值 | - | key | K | 是 | 当前遍历到的元素键值对的键 | - | lightWeightMap | LightWeightMap | 否 | 当前调用forEach方法的实例对象 | - -- 示例: - ``` - let lightWeightMap = new LightWeightMap(); - lightWeightMap.set("sdfs", 123); - lightWeightMap.set("dfsghsf", 357); - lightWeightMap.forEach((value, key) => { - console.log(value, key); - }); - ``` - - -### entries - -entries(): IterableIterator<[K, V]>; - -返回包含此映射中包含的键的新迭代器对象。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | IterableIterator<[K, V]> | 返回一个迭代器 | - -- 示例: - ``` - let lightWeightMap = new LightWeightMap(); - lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - lightWeightMap.set("sdfs", 356); - let iter = lightWeightMap.entries(); - let temp = iter.next().value; - while(temp != undefined) { - console.log(temp[0]); - console.log(temp[1]); - temp = iter.next().value; - } - ``` - - -### [Symbol.iterator] - -[Symbol.iterator]\(): IterableIterator<[K, V]>; - -返回一个迭代器,迭代器的每一项都是一个 JavaScript 对象,并返回该对象。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | IterableIterator<[K, V]> | 返回一个迭代器 | - -- 示例: - ``` - let lightWeightMap = new LightWeightMap(); - lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - lightWeightMap.set("sdfs", 356); - - // 使用方法一: - for (let item of lightWeightMap) { - console.log("key: " + item[0]); - console.log("value: " + item[1]); - } - - // 使用方法二: - let iter = lightWeightMap[Symbol.iterator](); - let temp = iter.next().value; - while(temp != undefined) { - console.log(temp[0]); - console.log(temp[1]); - temp = iter.next().value; - } - ``` \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-lightweightset.md b/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-lightweightset.md deleted file mode 100644 index 390fbedcf3c3c655998796785dc4e81dabadcde2..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-lightweightset.md +++ /dev/null @@ -1,476 +0,0 @@ ---- -title: js-apis-lightweightset -permalink: /pages/extra/15f160/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 非线性容器LightWeightSet - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import LightWeightSet from '@ohos.util.LightWeightSet' -``` - - -## 权限 - -无 - -## LightWeightSet - - -### 属性 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| length | number | 是 | 否 | LightWeightSet的元素个数 | - - -### constructor - -constructor(); - -LightWeightSet的构造函数。 - -- 示例: - ``` - let lightWeightSet = new LightWeightSet(); - ``` - - -### isEmpty - -isEmpty(): boolean; - -判断该容器是否为空。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 为空返回true, 不为空返回false | - -- 示例: - ``` - const lightWeightSet = new LightWeightSet(); - lightWeightSet.isEmpty(); - ``` - -### add - -add(value: T): boolean; - -向此容器中添加数据。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | T | 是 | 添加的成员数据 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 是否成功添加元素 | - -- 示例: - ``` - let lightWeightSet = new LightWeightSet(); - lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - ``` - - -### addAll - -addAll(set: LightWeightSet<T>): boolean; - -将另一个容器中的所有元素组添加到当前容器中。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | set | LightWeightSet<T> | 是 | 提供添加元素的lightweightmap | - -- 示例: - ``` - let lightWeightSet = new LightWeightSet(); - lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - lightWeightSet.add("sdfs"); - let set = new LightWeightSet(); - set.add("sfage"); - lightWeightSet.addAll(set); - ``` - - -### hasAll - -hasAll(set: LightWeightSet<T>): boolean; - -判断此容器中是否含有该指定set中的所有元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | set | LightWeightSet<T> | 是 | 比较对象 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 是否包含所有元素 | - -- 示例: - ``` - let lightWeightSet = new LightWeightSet(); - lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - lightWeightSet.add("sdfs"); - let set = new LightWeightSet(); - set.add("sdfs"); - let result = lightWeightSet.hasAll(set); - ``` - - -### has - -has(value: T): boolean; - -判断此容器中是否含有该指定value。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | T | 是 | 指定元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 是否包含指定元素 | - -- 示例: - ``` - let lightWeightSet = new LightWeightSet(); - lightWeightSet.has(123); - lightWeightSet.add(123); - lightWeightSet.has(123); - ``` - - -### equal - -equal(obj: Object): boolean; - -判断此容器中是否含有该指定obj同类型。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | obj | Object | 是 | 比较对象 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 是否构成类型相同 | - -- 示例: - ``` - let lightWeightSet = new LightWeightSet(); - lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - lightWeightSet.add("sdfs"); - let obj = {"Ahfbrgrbgnutfodgorrogorgrogofdfdf", "sdfs"}; - let result = lightWeightSet.equal(obj); - ``` - - -### ensureCapacityTo - -ensureCapacityTo(minimumCapacity: number): void; - -将当前容器扩容至可以容纳指定数量元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | minimumCapacity | number | 是 | 需要容纳数量 | - - -- 示例: - ``` - let lightWeightSet = new LightWeightSet(); - lightWeightSet.ensureCapacityTo(10); - ``` - - -### getIndexOf - -getIndexOf(key: T): number; - -获取指定key所对应的下标。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | T | 是 | 查找的指定key | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 在lightweightset中指定数据的下标 | - -- 示例: - ``` - let lightWeightSet = new LightWeightSet(); - lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - lightWeightSet.add("sdfs"); - lightWeightSet.getIndexOf("sdfs"); - ``` - - -### remove - -remove(key: T): T; - -删除指定的元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | T | 是 | 依据key指定删除的元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | T | 返回删除元素的值 | - -- 示例: - ``` - let lightWeightSet = new LightWeightSet(); - lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - lightWeightSet.add("sdfs"); - lightWeightSet.remove("sdfs"); - ``` - - -### removeAt - -removeAt(index: number): boolean; - -删除指定下标的元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | index | number | 是 | 指定想要删除元素下标 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 确认是否成功删除元素 | - -- 示例: - ``` - let lightWeightSet = new LightWeightSet(); - lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - lightWeightSet.add("sdfs"); - lightWeightSet.removeAt(1); - ``` - - -### getValueAt - -getValueAt(index: number): T; - -获取此容器中具体位置的元素 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | index | number | 是 | 指定查询数据下标 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | T | 返回指定位置中元素 | - -- 示例: - ``` - let lightWeightSet = new LightWeightSet(); - lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - lightWeightSet.add("sdfs"); - lightWeightSet.getValueAt(1); - ``` - - -### clear - -clear(): void; - -清除容器中的所有元素,并把length置为0。 - -- 示例: - ``` - let lightWeightSet = new LightWeightSet(); - lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - lightWeightSet.add("sdfs"); - lightWeightSet.clear(); - ``` - - -### toString - -toString(): String; - -获取包含容器中所有键和值的字符串。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | String | 返回一个字符串 | - -- 示例: - ``` - let lightWeightSet = new LightWeightSet(); - lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - lightWeightSet.add("sdfs"); - lightWeightSet.toString(); - ``` - - -### toArray - -toArray(): Array<T>; - -获取包含此容器中所有对象的数组。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Array<T> | 返回一个数组 | - -- 示例: - ``` - let lightWeightSet = new LightWeightSet(); - lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - lightWeightSet.add("sdfs"); - lightWeightSet.toString(); - ``` - - -### values - -values(): IterableIterator<T>; - -返回包含此映射中包含的键的新迭代器对象。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | IterableIterator<T> | 返回一个迭代器 | - -- 示例: - ``` - let lightWeightSet = new LightWeightSet(); - lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - lightWeightSet.add("sdfs"); - let iter = lightWeightSet.values(); - let index = 0; - while(index < lightWeightSet.length) { - console.log(JSON.stringify(iter.next().value)); - index++; - } - ``` - - -### forEach - -forEach(callbackfn: (value: T, key?: T, lightWeightSet?: LightWeightSet<T>) => void, thisArg?: Object): void; - -通过回调函数来遍历LightWeightSet实例对象上的元素以及元素对应的下标。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callbackfn | function | 是 | 回调函数 | - | thisArg | Object | 否 | callbackfn被调用时用作this值 | - -- callbackfn的参数说明 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | T | 是 | 当前遍历到的元素 | - | key | T | 否 | 当前遍历到的元素(和value相同) | - | lightWeightSet | LightWeightSet<T> | 否 | 当前调用forEach方法的实例对象 | - -- 示例: - ``` - let lightWeightSet = new LightWeightSet(); - lightWeightSet.add("sdfs"); - lightWeightSet.add("dfsghsf"); - lightWeightSet.forEach((value, key) => { - console.log(value, key); - }); - ``` - - -### entries - -entries(): IterableIterator<[T, T]>; - -返回包含此映射中包含的键的新迭代器对象。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | IterableIterator<[T, T]> | 返回一个迭代器 | - -- 示例: - ``` - let lightWeightSet = new LightWeightSet(); - lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - lightWeightSet.add("sdfs"); - let iter = lightWeightSet.entries(); - let index = 0; - while(index < lightWeightSet.length) { - console.log(JSON.stringify(iter.next().value)); - index++; - } - ``` - - -### [Symbol.iterator] - -[Symbol.iterator]\(): IterableIterator<T>; - -返回一个迭代器,迭代器的每一项都是一个 JavaScript 对象,并返回该对象。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | IterableIterator<T> | 返回一个迭代器 | - -- 示例: - ``` - let lightWeightSet = new LightWeightSet(); - lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - lightWeightSet.add("sdfs"); - - // 使用方法一: - for (let item of lightWeightSet) { - console.log("value: " + item); - } - - // 使用方法二: - let iter = lightWeightSet[Symbol.iterator](); - let temp = iter.next().value; - while(temp != undefined) { - console.log(temp); - temp = iter.next().value; - } - ``` \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-linkedlist.md b/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-linkedlist.md deleted file mode 100644 index ac8f2f0a32750a753b43f62762e3bcf41e39d685..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-linkedlist.md +++ /dev/null @@ -1,564 +0,0 @@ ---- -title: js-apis-linkedlist -permalink: /pages/extra/faabf6/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 线性容器LinkedList - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import LinkedList from '@ohos.util.LinkedList' -``` - - -## 权限 - -无 - - -## LinkedList - - -### 属性 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| length | number | 是 | 否 | LinkedList的元素个数 | - - -### constructor - -constructor(_head?: NodeObj<T>, _tail?: NodeObj<T>); - -LinkedList的构造函数。 - -- 参数: - | 参数名 | 类型 | 可读 | 可写 | 说明 | - | -------- | -------- | -------- | -------- | -------- | - | _head | NodeObj<T> | 是 | 否 | 入参对象,节点对象,含有element,和next指向,和prev指向 | - | _tail | NodeObj<T> | 是 | 否 | 入参对象,节点对象,含有element,和next指向,和prev指向 | - -- 示例: - ``` - let linkedList = new LinkedList(); - ``` - - -### add - -add(element: T): boolean; - -在LinkedList尾部插入元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | element | T | 是 | 添加进去的元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 插入成功返回true,失败返回false | - -- 示例: - ``` - let linkedList = new LinkedList(); - linkedList.add("a"); - linkedList.add(1); - let b = [1, 2, 3]; - linkedList.add(b); - let c = {name : "lala", age : "13"}; - linkedList.add(false); - ``` -### addFirst - -addFirst(element: T): void; - -在LinkedList头部插入元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | element | T | 是 | 添加进去的元素 | - -- 示例: - ``` - let linkedList = new LinkedList(); - linkedList.addFirst("a"); - linkedList.addFirst(1); - let b = [1, 2, 3]; - linkedList.addFirst(b); - let c = {name : "lala", age : "13"}; - linkedList.addFirst(false); - ``` - -### insert - -insert(element: T, index: number): void; - -在长度范围内任意插入指定元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | element | T | 是 | 被插入的元素 | - | index | number | 是 | 被插入的位置索引 | - -- 示例: - ``` - let linkedList = new LinkedList(); - linkedList.insert("A", 0); - linkedList.insert(0, 1); - linkedList.insert(true, 2); - ``` - -### has - -has(element: T): boolean; - -判断此LinkedList中是否含有该指定元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | element | T | 是 | 指定元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 是否包含指定元素 | - -- 示例: - ``` - let linkedList = new LinkedList(); - linkedList.has("Ahfbrgrbgnutfodgorrogorg"); - linkedList.add("Ahfbrgrbgnutfodgorrogorg"); - linkedList.has("Ahfbrgrbgnutfodgorrogorg"); - ``` - -### get - -get(index: number): T; - -根据下标获取LinkedList中的元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | index | number | 是 | 指定的下标值 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | T | 根据下标查找到的元素 | - -- 示例: - ``` - let linkedList = new LinkedList(); - linkedList.add(2); - linkedList.add(4); - linkedList.add(5); - linkedList.add(2); - linkedList.add(1); - linkedList.add(2); - linkedList.add(4); - linkedList.get(2); - ``` -### getLastIndexOf - -getLastIndexOf(element: T): number; - -返回指定元素最后一次出现时的下标值,查找失败返回-1。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | element | T | 是 | 指定元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 返回指定元素最后一次出现时的下标值,查找失败返回-1 | - -- 示例: - ``` - let linkedList = new LinkedList(); - linkedList.add(2); - linkedList.add(4); - linkedList.add(5); - linkedList.add(2); - linkedList.add(1); - linkedList.add(2); - linkedList.add(4); - linkedList.getLastIndexOf(2); - ``` - -### getIndexOf - -getIndexOf(element: T): number; - -返回指定元素第一次出现时的下标值,查找失败返回-1。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | element | T | 是 | 指定元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 返回指定元素第一次出现时的下标值,查找失败返回-1 | - -- 示例: - ``` - let linkedList = new LinkedList(); - linkedList.add(2); - linkedList.add(4); - linkedList.add(5); - linkedList.add(2); - linkedList.add(1); - linkedList.add(2); - linkedList.add(4); - linkedList.getIndexOf(2); - ``` -### removeByIndex - -removeByIndex(index: number): T; - -根据元素的下标值查找元素,返回元素后将其删除。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | index | number | 是 | 指定元素的下标值 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | T | 返回删除的元素 | - -- 示例: - ``` - let linkedList = new LinkedList(); - linkedList.add(2); - linkedList.add(4); - linkedList.add(5); - linkedList.add(2); - linkedList.add(4); - linkedList.removeByIndex(2); - ``` -### removeFirst - -removeFirst(): T; - -删除并返回LinkedList的第一个元素。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | T | 返回删除的元素 | - -- 示例: - ``` - let linkedList = new LinkedList(); - linkedList.add(2); - linkedList.add(4); - linkedList.add(5); - linkedList.add(2); - linkedList.add(4); - linkedList.removeFirst(); - ``` -### removeLast - -removeLst(): T; - -删除并返回LinkedList的最后一个元素。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | T | 返回删除的元素 | - -- 示例: - ``` - let linkedList = new LinkedList(); - linkedList.add(2); - linkedList.add(4); - linkedList.add(5); - linkedList.add(2); - linkedList.add(4); - linkedList.removeLast(); - ``` - -### remove - -remove(element: T): boolean; - -删除查找到的第一个指定的元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | element | T | 是 | 指定元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 删除成功返回true,失败返回false | - -- 示例: - ``` - let linkedList = new LinkedList(); - linkedList.add(2); - linkedList.add(4); - linkedList.add(5); - linkedList.add(4); - linkedList.remove(2); - ``` -### removeFirstFound - -removeFirstFound(element: T): boolean; - -删除第一次出现的指定元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | element | T | 是 | 指定元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 删除成功返回true,失败返回false | - -- 示例: - ``` - let linkedList = new LinkedList(); - linkedList.add(2); - linkedList.add(4); - linkedList.add(5); - linkedList.add(4); - linkedList.removeFirstFound(4); - ``` -### removeLastFound - -removeLastFound(element: T): boolean; - -删除最后一次出现的指定元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | element | T | 是 | 指定元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 删除成功返回true,失败返回false | - -- 示例: - ``` - let linkedList = new LinkedList(); - linkedList.add(2); - linkedList.add(4); - linkedList.add(5); - linkedList.add(4); - linkedList.removeLastFound(4); - ``` -### clone -clone(): LinkedList<T>; - -克隆一个与LinkedList一模一样的实例,并返回克隆后的实例,修改克隆后的实例并不会影响原实例。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | LinkedList<T> | 返回LinkedList对象实例 | - -- 示例: - ``` - let linkedList = new LinkedList(); - linkedList.add(2); - linkedList.add(4); - linkedList.add(5); - linkedList.add(4); - linkedList.clone(); - ``` -### forEach -forEach(callbackfn: (value: T, index?: number, linkedlist?: LinkedList<T>) => void, -thisArg?: Object): void; - -通过回调函数来遍历LinkedList实例对象上的元素以及元素对应的下标。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callbackfn | function | 是 | 回调函数 | - | thisArg | Object | 否 | callbackfn被调用时用作this值 | - -- callbackfn的参数说明 - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | T | 是 | 当前遍历到的元素 | - | index | number | 否 | 当前遍历到的下标值 | - | linkedlist | LinkedList<T> | 否 | 当前调用forEach方法的实例对象 | - -- 示例: - ``` - let linkedList = new LinkedList(); - linkedList.add(2); - linkedList.add(4); - linkedList.add(5); - linkedList.add(4); - linkedList.forEach((value, index) => { - console.log(value, index); - }); - ``` -### clear -clear(): void; - -清除LinkedList中的所有元素,并把length置为0。 - -- 示例: - ``` - let linkedList = new LinkedList(); - linkedList.add(2); - linkedList.add(4); - linkedList.add(5); - linkedList.add(4); - linkedList.clear(); - ``` -### set -set(index: number, element: T): T; -将此 LinkedList 中指定位置的元素替换为指定元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | index | number | 是 | 查找的下标值 | - | element | T | 是 | 用来替换的元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | T | 返回T类型 | - -- 示例: - ``` - let linkedList = new LinkedList(); - linkedList.add(2); - linkedList.add(4); - linkedList.add(5); - linkedList.add(4); - linkedList.set(2, "b"); - ``` -### convertToArray -convertToArray(): Array<T>; - -把当前LinkedList实例转换成数组,并返回转换后的数组。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Array<T> | 返回数组类型 | - -- 示例: - ``` - let linkedList = new LinkedList(); - linkedList.add(2); - linkedList.add(4); - linkedList.add(5); - linkedList.add(4); - linkedList.convertToArray(); - ``` - -### getFirst - -getFirst(): T; -获取LinkedList实例中的第一个元素。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | T | 返回T型 | - - -- 示例: - ``` - let linkedList = new LinkedList(); - linkedList.add(2); - linkedList.add(4); - linkedList.add(5); - linkedList.add(4); - linkedList.getFirst(); - ``` -### getLast - -getLast(): T; -获取LinkedList实例中的最后一个元素。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | T | 返回T型 | - - -- 示例: - ``` - let linkedList = new LinkedList(); - linkedList.add(2); - linkedList.add(4); - linkedList.add(5); - linkedList.add(4); - linkedList.getLast(); - ``` - -### [Symbol.iterator] - -[Symbol.iterator]\(): IterableIterator<T>; - - -返回一个迭代器,迭代器的每一项都是一个 JavaScript 对象,并返回该对象。 - - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | IterableIterator<T> | 返回一个迭代器。 | - - -- 示例: - ``` - let linkedList = new LinkedList(); - linkedList.add(2); - linkedList.add(4); - linkedList.add(5); - linkedList.add(4); - - // 使用方法一: - for (let item of linkedList) { - console.log(item); - } - - // 使用方法二: - let iter = linkedList[Symbol.iterator](); - let temp = iter.next().value; - while(temp != undefined) { - console.log(temp); - temp = iter.next().value; - } - ``` \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-list.md b/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-list.md deleted file mode 100644 index e0326420374dcd324a44e341aa659940fe520424..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-list.md +++ /dev/null @@ -1,574 +0,0 @@ ---- -title: js-apis-list -permalink: /pages/extra/fa1a5f/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 线性容器List - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import List from '@ohos.util.List' -``` - - -## 权限 - -无 - - -## List - - -### 属性 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| length | number | 是 | 否 | List的元素个数 | - - -### constructor - -constructor(_head?: NodeObj<T>); - -List的构造函数。 - -- 参数: - | 参数名 | 类型 | 可读 | 可写 | 说明 | - | -------- | -------- | -------- | -------- | -------- | - | _head | NodeObj<T> | 是 | 否 | 入参对象,节点对象,含有element,和next指向 | - -- 示例: - ``` - let list = new List(); - ``` - - -### add - -add(element: T): boolean; - -在List尾部插入元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | element | T | 是 | 添加进去的元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 插入成功返回true,失败返回false | - -- 示例: - ``` - let list = new List; - list.add("a"); - list.add(1); - let b = [1, 2, 3]; - list.add(b); - let c = {name : "lala", age : "13"}; - list.add(false); - ``` - -### insert - -insert(element: T, index: number): void; - -在长度范围内任意位置插入指定元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | element | T | 是 | 被插入的元素 | - | index | number | 是 | 被插入的位置索引 | - -- 示例: - ``` - let list = new List(); - list.insert("A", 0); - list.insert(0, 1); - list.insert(true, 2); - ``` - -### has - -has(element: T): boolean; - -判断此List中是否含有该指定元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | element | T | 是 | 指定元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 是否包含指定元素 | - -- 示例: - ``` - let list = new List(); - list.has("Ahfbrgrbgnutfodgorrogorg"); - list.add("Ahfbrgrbgnutfodgorrogorg"); - list.has("Ahfbrgrbgnutfodgorrogorg"); - ``` - -### get - -get(index: number): T; - -根据下标获取List中的元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | index | number | 是 | 要查找的下标 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | T | 根据下标查找到的元素 | - -- 示例: - ``` - let list = new List(); - list.add(2); - list.add(4); - list.add(5); - list.add(2); - list.add(1); - list.add(2); - list.add(4); - list.get(2); - ``` -### getLastIndexOf - -getLastIndexOf(element: T): number; - -查找指定元素最后一次出现的下标值,查找失败返回-1。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | element | T | 是 | 指定元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 查找指定元素最后一次出现的下标值,查找失败返回-1 | - -- 示例: - ``` - let list = new List(); - list.add(2); - list.add(4); - list.add(5); - list.add(2); - list.add(1); - list.add(2); - list.add(4); - list.getLastIndexOf(2); - ``` - -### getIndexOf - -getIndexOf(element: T): number; - -查找指定元素第一次出现的下标值,查找失败返回-1。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | element | T | 是 | 指定元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 返回第一次找到指定元素的下标,没有找到返回-1 | - -- 示例: - ``` - let list = new List(); - list.add(2); - list.add(4); - list.add(5); - list.add(2); - list.add(1); - list.add(2); - list.add(4); - list.getIndexOf(2); - ``` - -### equal - -equal(obj: Object): boolean; - -比较指定对象与此List是否相等。如果对象与此列表相同,返回true,否则返回false。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | obj | Object | 是 | 用来比较的对象 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 返回boolean类型 | - -- 示例: - ``` - let list = new List(); - list.add(2); - list.add(4); - list.add(5); - list.add(2); - let obj1 = new List(); - obj1.add(2); - obj1.add(4); - obj1.add(5); - list.equal(obj1); - let obj2 = {name : "lala", age : "13"}; - list.equal(obj2); - ``` -### removeByIndex - -removeByIndex(index: number): T; - -根据元素的下标值查找元素,返回元素后将其删除。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | index | number | 是 | 指定元素的下标值 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | T | 返回删除的元素 | - -- 示例: - ``` - let list = new List(); - list.add(2); - list.add(4); - list.add(5); - list.add(2); - list.add(4); - list.removeByIndex(2); - ``` - -### remove - -remove(element: T): boolean; - -删除查找到的第一个指定的元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | element | T | 是 | 指定元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 删除成功返回true,失败返回false | - -- 示例: - ``` - let list = new List(); - list.add(2); - list.add(4); - list.add(5); - list.add(4); - list.remove(2); - ``` - -### replaceAllElements -replaceAllElements(callbackfn: (value: T, index?: number, list?: List<T>) => T, -thisArg?: Object): void; - -用户操作List中的元素,用操作后的元素替换原元素并返回操作后的元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callbackfn | function | 是 | 回调函数 | - | thisArg | Object | 否 | callbackfn被调用时用作this值 | - -- callbackfn的参数说明 - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | T | 是 | 当前遍历到的元素 | - | index | number | 否 | 当前遍历到的下标值 | - | list | List<T> | 否 | 当前调用replaceAllElements方法的实例对象 | - -- 示例: - ``` - let list = new List(); - list.add(2); - list.add(4); - list.add(5); - list.add(4); - list.replaceAllElements((value, index) => { - return value = 2 * value; - }); - list.replaceAllElements((value, index) => { - return value = value - 2; - }); - ``` -### forEach -forEach(callbackfn: (value: T, index?: number, list?: List<T>) => void, -thisArg?: Object): void; - -通过回调函数来遍历List实例对象上的元素以及元素对应的下标。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callbackfn | function | 是 | 回调函数 | - | thisArg | Object | 否 | callbackfn被调用时用作this值 | - -- callbackfn的参数说明 - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | T | 是 | 当前遍历到的元素。 | - | index | number | 否 | 当前遍历到的下标值。 | - | list | List<T> | 否 | 当前调用forEach方法的实例对象 | - - -- 示例: - ``` - let list = new List(); - list.add(2); - list.add(4); - list.add(5); - list.add(4); - list.forEach((value, index) => { - console.log(value, index); - }); - - ``` -### sort -sort(comparator: (firstValue: T, secondValue: T) => number): void; - -对List中的元素进行一个排序操作。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | comparator | function | 是 | 回调函数。 | - -- comparator的参数说明 - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | firstValue | T | 是 | 前一项元素 | - | secondValue | T | 是 | 后一项元素 | - - -- 示例: - ``` - let list = new List(); - list.add(2); - list.add(4); - list.add(5); - list.add(4); - list.sort(a, (b => a - b)); - list.sort(a, (b => b - a)); - ``` -### getSubList -getSubList(fromIndex: number, toIndex: number): List<T>; - -根据下标截取List中的一段元素,并返回这一段List实例,包括起始值但不包括终止值。 -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | fromIndex | number | 是 | 起始下标 | - | toIndex | number | 是 | 终止下标 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | List<T> | 返回List对象实例 | - -- 示例: - ``` - let list = new List(); - list.add(2); - list.add(4); - list.add(5); - list.add(4); - list.subList(2, 4); - list.subList(4, 3); - list.subList(2, 6); - ``` - -### clear -clear(): void; - -清除List中的所有元素,并把length置为0。 - -- 示例: - ``` - let list = new List(); - list.add(2); - list.add(4); - list.add(5); - list.add(4); - list.clear(); - ``` -### set -set(index: number, element: T): T; -将此 List 中指定位置的元素替换为指定元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | index | number | 是 | 查找的下标值 | - | element | T | 是 | 用来替换的元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | T | 返回T类型 | - -- 示例: - ``` - let list = new List(); - list.add(2); - list.add(4); - list.add(5); - list.add(4); - list.set(2, "b"); - - ``` -### convertToArray -convertToArray(): Array<T>; - -把当前List实例转换成数组,并返回转换后的数组。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Array<T> | 返回数组类型 | - -- 示例: - ``` - let list = new List(); - list.add(2); - list.add(4); - list.add(5); - list.add(4); - list.convertToArray(); - ``` -### isEmpty -isEmpty(): boolean; - -判断该List是否为空。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 为空返回true, 不为空返回false | - -- 示例: - ``` - let list = new List(); - list.add(2); - list.add(4); - list.add(5); - list.add(4); - list.isEmpty(); - ``` -### getFirst - -getFirst(): T; -获取List实例中的第一个元素。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | T | 返回T型 | - - -- 示例: - ``` - let list = new Vector(); - list.add(2); - list.add(4); - list.add(5); - list.add(4); - list.getFirst(); - ``` -### getLast - -getLast(): T; -获取List实例中的最后一个元素。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | T | 返回T型 | - - -- 示例: - ``` - let list = new Vector(); - list.add(2); - list.add(4); - list.add(5); - list.add(4); - list.getLast(); - ``` - -### [Symbol.iterator] - -[Symbol.iterator]\(): IterableIterator<T>; - - -返回一个迭代器,迭代器的每一项都是一个 JavaScript 对象,并返回该对象。 - - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | IterableIterator<T> | 返回一个迭代器。 | - - -- 示例: - ``` - let list = new List(); - list.add(2); - list.add(4); - list.add(5); - list.add(4); - - // 使用方法一: - for (let item of list) { - console.log(item); - } - - // 使用方法二: - let iter = list[Symbol.iterator](); - let temp = iter.next().value; - while(temp != undefined) { - console.log(temp); - temp = iter.next().value; - } - ``` \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-plainarray.md b/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-plainarray.md deleted file mode 100644 index 56b4d2597cf322ddec2a1d2b22857d23c266f3ad..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-plainarray.md +++ /dev/null @@ -1,434 +0,0 @@ ---- -title: js-apis-plainarray -permalink: /pages/extra/9c7f1a/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 非线性容器PlainArray - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import PlainArray from '@ohos.util.PlainArray' -``` - - -## 权限 - -无 - -## PlainArray - - -### 属性 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| length | number | 是 | 否 | PlainArray的元素个数 | - - -### constructor - -constructor(); - -PlainArray的构造函数。 - -- 示例: - ``` - let plainArray = new PlainArray(); - ``` - - -### isEmpty - -isEmpty(): boolean; - -判断该容器是否为空。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 为空返回true, 不为空返回false | - -- 示例: - ``` - const plainArray = new PlainArray(); - plainArray.isEmpty(); - ``` - - -### has - -has(key: number): boolean; - -判断此容器中是否含有该指定key。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | number | 是 | 查询的元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 是否包含指定元素 | - -- 示例: - ``` - let plainArray = new PlainArray(); - plainArray.has(1); - plainArray.add(1, "sddfhf"); - plainArray.has(1); - ``` - - -### get - -get(key: number): T; - -获取指定key所对应的value。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | number | 是 | 查找的指定key | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | T | 返回key映射的value值 | - -- 示例: - ``` - let plainArray = new PlainArray(); - plainArray.add(1, "sddfhf"); - plainArray.add(2, "sffdfhf"); - plainArray.get(1); - ``` - - -### getIndexOfKey - -getIndexOfKey(key: number): number; - -查找指定元素第一次出现的下标值,如果没有找到该元素返回-1。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | number | 是 | 被查找的元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 返回指定元素第一次出现时的下标值,查找失败返回-1 | - -- 示例: - ``` - let plainArray = new PlainArray(); - plainArray.add(1, "sddfhf"); - plainArray.add(2, "sffdfhf"); - plainArray.getIndexOfKey("sdfs"); - ``` - - -### getIndexOfValue - -getIndexOfValue(value: T): number; - -查找指定元素第一次出现的下标值,如果没有找到该元素返回-1。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | T | 是 | 被查找的元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 返回指定元素第一次出现时的下标值,查找失败返回-1 | - -- 示例: - ``` - let plainArray = new PlainArray(); - plainArray.add(1, "sddfhf"); - plainArray.add(2, "sffdfhf"); - plainArray.getIndexOfValue("sddfhf"); - ``` - - -### getKeyAt - -getKeyAt(index: number): number; - -查找指定下标的元素键值对中key值,否则返回undefined。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | index | number | 是 | 所查找的下标 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 返回该下标对应的元素键值对中key值 | - -- 示例: - ``` - let plainArray = new PlainArray(); - plainArray.add(1, "sddfhf"); - plainArray.add(2, "sffdfhf"); - plainArray.getKeyAt(1); - ``` - - -### clone - -clone(): PlainArray<T>; - -克隆一个一模一样的实例,并返回克隆后的实例,修改克隆后的实例并不会影响原实例。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | PlainArray<T> | 返回新的对象实例 | - -- 示例: - ``` - let plainArray = new ArrayList(); - plainArray.add(1, "sddfhf"); - plainArray.add(2, "sffdfhf"); - let newPlainArray = plainArray.clone(); - ``` - - -### add - -add(key: number, value: T): boolean; - -向容器中添加一组数据。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | number | 是 | 添加成员数据的键名 | - | value | T | 是 | 添加成员数据的值 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 确认是否成功添加 | - -- 示例: - ``` - let plainArray = new PlainArray(); - plainArray.add(1, "sddfhf"); - ``` - - -### remove - -remove(key: number): T; - -删除指定的元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | number | 是 | 依据key指定删除的元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | T | 返回删除元素的值 | - -- 示例: - ``` - let plainArray = new PlainArray(); - plainArray.add(1, "sddfhf"); - plainArray.add(2, "sffdfhf"); - plainArray.remove(2); - ``` - - -### removeAt - -removeAt(index: number): boolean; - -删除指定下标的元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | index | number | 是 | 指定想要删除元素下标 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 确认是否成功删除元素 | - -- 示例: - ``` - let plainArray = new PlainArray(); - plainArray.add(1, "sddfhf"); - plainArray.add(2, "sffdfhf"); - plainArray.removeAt(1); - ``` - - -### removeRangeFrom - -removeRangeFrom(index: number, size: number): number; - -删除一定范围内的元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | index | number | 是 | 删除元素的起始下标 | - | size | number | 是 | 期望删除元素个数 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 实际删除元素个数 | - -- 示例: - ``` - let plainArray = new PlainArray(); - plainArray.add(1, "sddfhf"); - plainArray.add(2, "sffdfhf"); - plainArray.removeAt(1, 3); - ``` - - -### setValueAt - -setValueAt(index: number, newValue: T): void; - -向容器中具体位置替换键值对中的值。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | index | number | 是 | 指定替换数据下标 | - | newValue | T | 是 | 替换键值对中的值 | - - -- 示例: - ``` - let plainArray = new PlainArray(); - plainArray.add(1, "sddfhf"); - plainArray.add(2, "sffdfhf"); - plainArray.setValueAt(1, 3546); - ``` - - -### toString - -toString(): String; - -获取包含容器中所有键和值的字符串。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | String | 返回一个字符串 | - -- 示例: - ``` - let plainArray = new PlainArray(); - plainArray.add(1, "sddfhf"); - plainArray.add(2, "sffdfhf"); - plainArray.toString(); - ``` - - -### clear - -clear(): void; - -清除容器中的所有元素,并把length置为0。 - -- 示例: - ``` - let plainArray = new PlainArray(); - plainArray.add(1, "sddfhf"); - plainArray.add(2, "sffdfhf"); - plainArray.clear(); - ``` - - -### forEach - -forEach(callbackfn: (value: T, key?: number, plainArray?: PlainArray) => void, thisArg?: Object): void; - -通过回调函数来遍历实例对象上的元素以及元素对应的下标。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callbackfn | function | 是 | 回调函数 | - | thisArg | Object | 否 | callbackfn被调用时用作this值 | - -- callbackfn的参数说明 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | T | 是 | 当前遍历到的元素键值对的值 | - | key | number | 是 | 当前遍历到的元素键值对的键 | - | plainArray | PlainArray | 否 | 当前调用forEach方法的实例对象 | - -- 示例: - ``` - let plainArray = new PlainArray(); - plainArray.add(1, "sddfhf"); - plainArray.add(2, "sffdfhf"); - plainArray.forEach((value, key) => { - console.log(value, key); - }); - ``` - - -### [Symbol.iterator] - -[Symbol.iterator]\(): IterableIterator<[number, T]>; - -返回一个迭代器,迭代器的每一项都是一个 JavaScript对象,并返回该对象。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | IterableIterator<[number, T]> | 返回一个迭代器 | - -- 示例: - ``` - let plainArray = new PlainArray(); - plainArray.add(1, "sddfhf"); - plainArray.add(2, "sffdfhf"); - - // 使用方法一: - for (let item of plainArray) { - console.log("index: " + item[0]); - console.log("value: " + item[1]); - } - - // 使用方法二: - let iter = plainArray[Symbol.iterator](); - let temp = iter.next().value; - while(temp != undefined) { - console.log(temp[0]); - console.log(temp[1]); - temp = iter.next().value; - } - ``` \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-queue.md b/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-queue.md deleted file mode 100644 index 64fd8ee9028a08195ee003a377454213439277b4..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-queue.md +++ /dev/null @@ -1,193 +0,0 @@ ---- -title: js-apis-queue -permalink: /pages/extra/357a69/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 线性容器Queue - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import Queue from '@ohos.util.Queue' -``` - - -## 权限 - -无 - - -## Queue - - -### 属性 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| length | number | 是 | 否 | Queue的元素个数 | - - -### constructor - -constructor(); - -Queue的构造函数。 - - -- 示例: - ``` - let queue = new Queue(); - ``` - - -### add - -add(element: T): boolean; - -在队列尾部插入元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | element | T | 是 | 添加进去的元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 插入成功返回true,失败返回false | - -- 示例: - ``` - let queue = new Queue(); - queue.add("a"); - queue.add(1); - let b = [1, 2, 3]; - queue.add(b); - let c = {name : "lala", age : "13"}; - queue.add(false); - ``` - -### pop - -pop(): T - -删除头元素并返回该删除元素。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | T | 返回删除的元素 | - -- 示例: - ``` - let queue = new Queue(); - queue.add(2); - queue.add(4); - queue.add(5); - queue.add(2); - queue.add(4); - queue.pop(); - ``` - -### getFirst - -getFirst(): T; - -获取队列的头元素。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | T | 返回尾元素 | - -- 示例: - ``` - let queue = new Queue(); - queue.add(2); - queue.add(4); - queue.add(5); - queue.add(2); - queue.getFirst(); - ``` - -### forEach -forEach(callbackfn: (value: T, index?: number, queue?: Queue<T>) => void, -thisArg?: Object): void; - -通过回调函数来遍历Queue实例对象上的元素以及元素对应的下标。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callbackfn | function | 是 | 回调函数。 | - | thisArg | Object | 否 | callbackfn被调用时用作this值 | - -- callbackfn的参数说明 - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | T | 是 | 当前遍历到的元素 | - | index | number | 否 | 当前遍历到的下标值 | - | queue | Queue<T> | 否 | 当前调用forEach方法的实例对象 | - - -- 示例: - ``` - let queue = new Queue(); - queue.add(2); - queue.add(4); - queue.add(5); - queue.add(4); - queue.forEach((value, index) => { - console.log(value, index); - }); - - ``` - -### [Symbol.iterator] - -[Symbol.iterator]\(): IterableIterator<T>; - - -返回一个迭代器,迭代器的每一项都是一个 JavaScript 对象,并返回该对象。 - - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | IterableIterator<T> | 返回一个迭代器 | - - -- 示例: - ``` - let queue = new Queue(); - queue.add(2); - queue.add(4); - queue.add(5); - queue.add(4); - - // 使用方法一: - for (let item of queue) { - console.log(item); - } - - // 使用方法二: - let iter = queue[Symbol.iterator](); - let temp = iter.next().value; - while(temp != undefined) { - console.log(temp); - temp = iter.next().value; - } - ``` \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-reminderAgent.md b/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-reminderAgent.md deleted file mode 100644 index ebe5ec39a3b3629695b4107116c1b9ce9542eeec..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-reminderAgent.md +++ /dev/null @@ -1,512 +0,0 @@ ---- -title: js-apis-reminderAgent -permalink: /pages/extra/5d9419/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 后台代理提醒 - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import reminderAgent from'@ohos.reminderAgent'; -``` - - -## 系统能力 - -SystemCapability.Notification.ReminderAgent - - -## 权限 - -ohos.permission.PUBLISH_AGENT_REMINDER - - -## reminderAgent.publishReminder - -publishReminder(reminderReq: ReminderRequest, callback: AsyncCallback<number>): void - -发布一个后台代理提醒,使用callback方式实现异步调用。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | reminderReq | [ReminderRequest](#reminderrequest) | 是 | 需要发布的提醒实例。 | - | callback | AsyncCallback<number> | 是 | 异步回调,返回当前发布的提醒的reminderId。 | - -- 示例: - ``` - export default { data: {timer: { - reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER, - triggerTimeInSeconds: 3 - } - }, - startTimer() { - reminderAgent.publishReminder(timer, (err, reminderId) => { console.log("reminderId = " + reminderId); - }); - } - } - ``` - - -## reminderAgent.publishReminder - -publishReminder(reminderReq: ReminderRequest): Promise<number> - -发布一个后台代理提醒,使用Promise方式实现异步调用。 - -- 参数 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | reminderReq | [ReminderRequest](#reminderrequest) | 是 | 需要发布的提醒实例。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<number> | 返回提醒的reminderId。 | - -- 示例 - ``` - export default { data: {timer: { - reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER, - triggerTimeInSeconds: 3 - } - }, - startTimer() { - reminderAgent.publishReminder(this.timer).then((reminderId) => { - console.log("reminderId = " + reminderId); - }); - } - } - ``` - - -## reminderAgent.cancelReminder - -cancelReminder(reminderId: number, callback: AsyncCallback<void>): void - -取消指定id的提醒,使用callback方式实现异步调用。 - -- 参数 - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| reminderId | number | 是 | 目标reminder的id号。 | -| callback | AsyncCallback<void> | 是 | 异步回调。 | - -- 示例 - -``` -export default { - cancel() { reminderAgent.cancelReminder(1, (err, data) => { - console.log("do next"); - }); - } -} -``` - - -## reminderAgent.cancelReminder - -cancelReminder(reminderId: number): Promise<void> - -取消指定id的提醒,使用Promise方式实现异步调用。 - -- 参数 - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| reminderId | number | 是 | 目标reminder的id号。 | - -- 返回值 - -| 类型 | 说明 | -| -------- | -------- | -| Promise<void> | Promise类型异步回调。 | - -- 示例 - -``` -export default { - cancel() { - reminderAgent.cancelReminder(1).then(() => { - console.log("do next"); - }); - } -} -``` - - -## reminderAgent.getValidReminders - -getValidReminders(callback: AsyncCallback<Array<ReminderRequest>>): void - -获取当前应用已设置的所有有效(未过期)的提醒,使用callback方式实现异步调用。 - -- 参数 - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| callback | AsyncCallback<Array<[ReminderRequest](#reminderrequest)>> | 是 | 异步回调,返回当前应用已设置的所有有效(未过期)的提醒。 | - -- 示例 - -``` -reminderAgent.getValidReminders((err, reminders) => { - for (let i = 0; i < reminders.length; i++) { - console.log("getValidReminders = " + reminders[i]); - console.log("getValidReminders, reminderType = " + reminders[i].reminderType); - for (let j = 0; j < reminders[i].actionButton.length; j++) { - console.log("getValidReminders, actionButton.title = " + reminders[i].actionButton[j].title); - console.log("getValidReminders, actionButton.type = " + reminders[i].actionButton[j].type); - } - console.log("getValidReminders, wantAgent.pkgName = " + reminders[i].wantAgent.pkgName); - console.log("getValidReminders, wantAgent.abilityName = " + reminders[i].wantAgent.abilityName); - console.log("getValidReminders, maxScreenWantAgent.pkgName = " + reminders[i].maxScreenWantAgent.pkgName); - console.log("getValidReminders, maxScreenWantAgent.abilityName = " + reminders[i].maxScreenWantAgent.abilityName); - console.log("getValidReminders, ringDuration = " + reminders[i].ringDuration); - console.log("getValidReminders, snoozeTimes = " + reminders[i].snoozeTimes); - console.log("getValidReminders, timeInterval = " + reminders[i].timeInterval); - console.log("getValidReminders, title = " + reminders[i].title); - console.log("getValidReminders, content = " + reminders[i].content); - console.log("getValidReminders, expiredContent = " + reminders[i].expiredContent); - console.log("getValidReminders, snoozeContent = " + reminders[i].snoozeContent); - console.log("getValidReminders, notificationId = " + reminders[i].notificationId); - console.log("getValidReminders, slotType = " + reminders[i].slotType); - } -}) -``` - - -## reminderAgent.getValidReminders - -getValidReminders(): Promise<Array<ReminderRequest>> - -获取当前应用已设置的所有有效(未过期)的提醒,使用Promise方式实现异步调用。 - -- 返回值 - -| 类型 | 说明 | -| -------- | -------- | -| Promise<Array<[ReminderRequest](#reminderrequest)>> | 返回当前应用已设置的所有有效(未过期)的提醒。 | - -- 示例 - -``` -reminderAgent.getValidReminders().then((reminders) => { - for (let i = 0; i < reminders.length; i++) { - console.log("getValidReminders = " + reminders[i]); - console.log("getValidReminders, reminderType = " + reminders[i].reminderType); - for (let j = 0; j < reminders[i].actionButton.length; j++) { - console.log("getValidReminders, actionButton.title = " + reminders[i].actionButton[j].title); - console.log("getValidReminders, actionButton.type = " + reminders[i].actionButton[j].type); - } - console.log("getValidReminders, wantAgent.pkgName = " + reminders[i].wantAgent.pkgName); - console.log("getValidReminders, wantAgent.abilityName = " + reminders[i].wantAgent.abilityName); - console.log("getValidReminders, maxScreenWantAgent.pkgName = " + reminders[i].maxScreenWantAgent.pkgName); - console.log("getValidReminders, maxScreenWantAgent.abilityName = " + reminders[i].maxScreenWantAgent.abilityName); - console.log("getValidReminders, ringDuration = " + reminders[i].ringDuration); - console.log("getValidReminders, snoozeTimes = " + reminders[i].snoozeTimes); - console.log("getValidReminders, timeInterval = " + reminders[i].timeInterval); - console.log("getValidReminders, title = " + reminders[i].title); - console.log("getValidReminders, content = " + reminders[i].content); - console.log("getValidReminders, expiredContent = " + reminders[i].expiredContent); - console.log("getValidReminders, snoozeContent = " + reminders[i].snoozeContent); - console.log("getValidReminders, notificationId = " + reminders[i].notificationId); - console.log("getValidReminders, slotType = " + reminders[i].slotType); - } -}) -``` - - -## reminderAgent.cancelAllReminders - -cancelAllReminders(callback: AsyncCallback<void>): void - -取消当前应用所有的提醒,使用callback方式实现异步调用。 - -- 参数 - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| callback | AsyncCallback<void> | 是 | 异步回调。 | - -- 示例 - -``` -reminderAgent.cancelAllReminders((err, data) =>{ - console.log("do next")}) -``` - - -## reminderAgent.cancelAllReminders - -cancelAllReminders(): Promise<void> - -取消当前应用所有的提醒,使用Promise方式实现异步调用。 - -- 返回值 - -| 类型 | 说明 | -| -------- | -------- | -| Promise<void> | Promise类型异步回调。 | - -- 示例 - -``` -reminderAgent.cancelAllReminders().then(() => { - console.log("do next")}) -``` - - -## reminderAgent.addNotificationSlot - -addNotificationSlot(slot: NotificationSlot, callback: AsyncCallback<void>): void - -添加一个NotificationSlot,使用callback方式实现异步调用。 - -- 参数 - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| slot | [ERROR:Invalid link:zh-cn_topic_0000001158696346.xml#xref1954171018915,link:zh-cn_topic_0000001180018813.xml#section1382174172015](zh-cn_topic_0000001180018813.xml#section1382174172015) | 是 | notification slot实例。 | -| callback | AsyncCallback<void> | 是 | 异步回调。 | - -- 示例 - -``` -export default { data: { mySlot: { - type: 3, - sound: "/sdcard/music2.mp3" - } }, - addSlot() { - reminderAgent.addNotificationSlot(this.mySlot, (err, data) => { - console.log("do next"); - }); - } -} -``` - - -## reminderAgent.addNotificationSlot - -addNotificationSlot(slot: NotificationSlot): Promise<void> - -添加一个NotificationSlot,使用Promise方式实现异步调用。 - -- 参数 - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| slot | [ERROR:Invalid link:zh-cn_topic_0000001158696346.xml#xref2049924012917,link:zh-cn_topic_0000001180018813.xml#section1382174172015](zh-cn_topic_0000001180018813.xml#section1382174172015) | 是 | notification slot实例。 | - -- 返回值 - -| 类型 | 说明 | -| -------- | -------- | -| Promise<void> | Promise类型异步回调。 | - -- 示例 - -``` -export default { data: { mySlot: { - type: 3, - sound: "/sdcard/music2.mp3" - } }, - addSlot() { - reminderAgent.addNotificationSlot(this.mySlot).then(() => { - console.log("do next"); - }); - } -} -``` - - -## reminderAgent.removeNotificationSlot - -removeNotificationSlot(slotType: notification.SlotType, callback: AsyncCallback<void>): void - -删除目标NotificationSlot,使用callback方式实现异步调用。 - -- 参数 - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| slotType | [ERROR:Invalid link:zh-cn_topic_0000001158696346.xml#xref11228182975217,link:zh-cn_topic_0000001180018813.xml#section072355105110](zh-cn_topic_0000001180018813.xml#section072355105110) | 是 | 目标notification slot的类型。 | -| callback | AsyncCallback<void> | 是 | 异步回调。 | - -- 示例 - -``` -export default { - removeSlot() {reminderAgent.removeNotificationSlot(notification.SlotType.CONTENT_INFORMATION, (err, data) => { - console.log("do next"); -}); - } -} -``` - - -## reminderAgent.removeNotificationSlot - -removeNotificationSlot(slotType: notification.SlotType): Promise<void> - -删除目标NotificationSlot,使用Promise方式实现异步调用。 - -- 参数 - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| slotType | [ERROR:Invalid link:zh-cn_topic_0000001158696346.xml#xref1120863519109,link:zh-cn_topic_0000001180018813.xml#section072355105110](zh-cn_topic_0000001180018813.xml#section072355105110) | 是 | 目标notification slot的类型。 | - -- 返回值 - -| 类型 | 说明 | -| -------- | -------- | -| Promise<void> | Promise类型异步回调。 | - -- 示例 - -``` -export default { - removeSlot() { reminderAgent.removeNotificationSlot(notification.SlotType.CONTENT_INFORMATION).then(() => { - console.log("do next"); - }); - } -} -``` - - -## ActionButtonType - -按钮的类型。 - -| 名称 | 默认值 | 说明 | -| -------- | -------- | -------- | -| ACTION_BUTTON_TYPE_CLOSE | 0 | 表示关闭提醒的按钮。 | -| ACTION_BUTTON_TYPE_SNOOZE | 1 | 表示延迟提醒的按钮。 | - - -## ReminderType - -提醒的类型。 - -| 名称 | 默认值 | 说明 | -| -------- | -------- | -------- | -| REMINDER_TYPE_TIMER | 0 | 表示提醒类型:倒计时。 | -| REMINDER_TYPE_CALENDAR | 1 | 表示提醒类型:日历。 | -| REMINDER_TYPE_ALARM | 2 | 表示提醒类型:闹钟。 | - - -## ActionButton - -用于设置弹出的提醒通知信息上显示的按钮类型和标题。 - -| 名称 | 参数类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| title | string | 是 | 按钮显示的标题。 | -| type | [ActionButtonType](#actionbuttontype) | 是 | 按钮的类型。 | - - -## WantAgent - -点击提醒通知后跳转的目标ability信息。 - -| 名称 | 参数类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| pkgName | string | 是 | 指明点击提醒通知栏后跳转的目标hap包名。 | -| abilityName | string | 是 | 指明点击提醒通知栏后跳转的目标ability名称。 | - - -## MaxScreenWantAgent - -提醒到达时自动拉起的目标ability信息。 - -| 名称 | 参数类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| pkgName | string | 是 | 指明提醒到达时自动拉起的目标hap包名(如果设备在使用中,则只弹出通知横幅框)。 | -| abilityName | string | 是 | 指明提醒到达时自动拉起的目标ability名(如果设备在使用中,则只弹出通知横幅框)。 | - - -## ReminderRequest - -提醒实例对象,用于设置提醒类型、响铃时长等具体信息。 - -| 名称 | 参数类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| reminderType | ReminderType | 是 | 指明提醒类型。 | -| actionButton | [ActionButton?, ActionButton?] | 否 | 弹出的提醒通知栏中显示的按钮(参数可选,支持0/1/2个按钮)。 | -| wantAgent | WantAgent | 否 | 点击通知后需要跳转的目标ability信息。 | -| maxScreenWantAgent | MaxScreenWantAgent | 否 | 提醒到达时跳转的目标包。如果设备正在使用中,则弹出一个通知框。 | -| ringDuration | number | 否 | 指明响铃时长。 | -| snoozeTimes | number | 否 | 指明延迟提醒次数。 | -| timeInterval | number | 否 | 执行延迟提醒间隔。 | -| title | string | 否 | 指明提醒标题。 | -| content | string | 否 | 指明提醒内容。 | -| expiredContent | string | 否 | 指明提醒过期后需要显示的内容。 | -| snoozeContent | string | 否 | 指明延迟提醒时需要显示的内容。 | -| notificationId | number | 否 | 指明提醒使用的通知的id号,相同id号的提醒会覆盖。 | -| slotType | [ERROR:Invalid link:zh-cn_topic_0000001158696346.xml#xref39047351518,link:zh-cn_topic_0000001180018813.xml#section072355105110](zh-cn_topic_0000001180018813.xml#section072355105110) | 否 | 指明提醒的slot类型。 | - - -## ReminderRequestCalendar - -ReminderRequestCalendar extends ReminderRequest - -日历实例对象,用于设置提醒的时间。 - -| 名称 | 参数类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| dateTime | [LocalDateTime](#localdatetime) | 是 | 指明提醒的目标时间。 | -| repeatMonths | Array<number> | 否 | 指明重复提醒的月份。 | -| repeatDays | Array<number> | 否 | 指明重复提醒的日期。 | - - -## ReminderRequestAlarm - -ReminderRequestAlarm extends ReminderRequest - -闹钟实例对象,用于设置提醒的时间。 - -| 名称 | 参数类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| hour | number | 是 | 指明提醒的目标时刻。 | -| minute | number | 是 | 指明提醒的目标分钟。 | -| daysOfWeek | Array<number> | 否 | 指明每周哪几天需要重复提醒。 | - - -## ReminderRequestTimer - -ReminderRequestTimer extends ReminderRequest - -倒计时实例对象,用于设置提醒的时间。 - -| 名称 | 参数类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| triggerTimeInSeconds | number | 是 | 指明倒计时的秒数。 | - - -## LocalDateTime - -用于日历类提醒设置时指定时间信息。 - -| 名称 | 参数类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| year | number | 是 | 年 | -| month | number | 是 | 月 | -| day | number | 是 | 日 | -| hour | number | 是 | 时 | -| minute | number | 是 | 分 | -| second | number | 否 | 秒 | diff --git a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-security-accessToken.md b/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-security-accessToken.md deleted file mode 100644 index 0d1b9ad732707dbebdf39fe21ad36d32f1f4bcac..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-security-accessToken.md +++ /dev/null @@ -1,229 +0,0 @@ ---- -title: js-apis-security-accessToken -permalink: /pages/extra/5b7654/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 访问控制管理 - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - -## 导入模块 - -``` -import abilityAccessCtrl from '@ohos.abilityAccessCtrl' -``` - -## 系统能力 -SystemCapability.Security.AccessToken - -## abilityAccessCtrl.createAtManager - -createAtManager(): AtManager - -访问控制管理:获取访问控制模块对象。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | [AtManager](#atManager) | 获取访问控制模块的实例。 | - -- 示例: - ``` - var AtManager = abilityAccessCtrl.createAtManager(); - ``` - -## AtManager - -管理访问控制模块的实例。 - -### verifyAccessToken - -verifyAccessToken(tokenID: number, permissionName: string): Promise<GrantStatus> - -校验应用是否授予权限,使用Promise方式异步返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | ------------------- | ---- | ------------------------------------------ | - | tokenID | number | 是 | 要校验的目标应用的身份标识。 | - | permissionName | string | 是 | 需要校验的权限名称。 | - -- 返回值: - - | 类型 | 说明 | - | :------------ | :---------------------------------- | - | Promise<GrantStatus> | Promise实例,用于获取异步返回的授权状态结果。 | - -- 示例: - - ``` - const AtManager = abilityAccessCtrl.createAtManager(); - let tokenID = 0; - let promise = AtManager.verifyAccessToken(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS"); - promise.then(data => { - console.log(`promise: data->${JSON.stringify(data)}`); - }); - ``` - -### grantUserGrantedPermission - -grantUserGrantedPermission(tokenID: number, permissionName: string, permissionFlag: number): Promise<number> - -授予应用user grant权限,使用Promise方式异步返回结果。 - -需要权限:ohos.permission.GRANT_SENSITIVE_PERMISSIONS。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | --------- | ------------------- | ---- | ------------------------------------------------------------ | - | tokenID | number | 是 | 目标应用的身份标识。 | - | permissionName | string | 是 | 被授予的权限名称。 | - | permissionFlag | number | 是 | 授权选项,1表示下次仍需弹窗,2表示允许、禁止后不再提醒,3表示系统授权不允许更改。 | - -- 返回值: - - | 类型 | 说明 | - | :------------ | :---------------------------------- | - | Promise<number> | Promise实例,用于获取异步返回的授权操作结果。 | -- 示例: - - ``` - const AtManager = abilityAccessCtrl.createAtManager(); - let tokenID = 0; - let promise = AtManager.grantUserGrantedPermission(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS"); - promise.then(data => { - console.log(`promise: data->${JSON.stringify(data)}`); - }); - ``` - - - -### grantUserGrantedPermission - -grantUserGrantedPermission(tokenID: number, permissionName: string, permissionFlag: number, callback: AsyncCallback<number>): void - -授予应用user grant权限,使用callback回调异步返回结果。 - -需要权限:ohos.permission.GRANT_SENSITIVE_PERMISSIONS。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | --------- | ------------------- | ---- | ------------------------------------------------------------ | - | tokenID | number | 是 | 目标应用的身份标识。 | - | permissionName | string | 是 | 被授予的权限名称。 | - | permissionFlag | number | 是 | 授权选项,1表示下次仍需弹窗,2表示允许、禁止后不再提醒,3表示系统授权不允许更改。 | - | callback | AsyncCallback<number> | 是 | 检查授予应用user grant权限的操作结果同步的回调。 | - -- 示例: - - ``` - const AtManager = abilityAccessCtrl.createAtManager(); - let tokenID = 0; - let permissionFlag = 1; - AtManager.grantUserGrantedPermission(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS",permissionFlag, data => { - console.log(`callback: data->${JSON.stringify(data)}`); - }); - ``` - -### revokeUserGrantedPermission - -revokeUserGrantedPermission(tokenID: number, permissionName: string, permissionFlag: number): Promise<number> - -撤销应用user grant权限,使用Promise方式异步返回结果。 - -需要权限:ohos.permission.REVOKE_SENSITIVE_PERMISSIONS。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | --------- | ------------------- | ---- | ------------------------------------------------------------ | - | tokenID | number | 是 | 目标应用的身份标识。 | - | permissionName | string | 是 | 被撤销的权限名称。 | - | permissionFlag | number | 是 | 授权选项,1表示下次仍需弹窗,2表示允许、禁止后不再提醒,3表示系统授权不允许更改。 | - -- 返回值: - - | 类型 | 说明 | - | :------------ | :---------------------------------- | - | Promise<number> | Promise实例,用于获取异步返回的授权操作结果。 | - -- 示例: - - ``` - const AtManager = abilityAccessCtrl.createAtManager(); - let tokenID = 0; - let permissionFlag = 1; - let promise = AtManager.revokeUserGrantedPermission(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", permissionFlag); - promise.then(data => { - console.log(`promise: data->${JSON.stringify(data)}`); - }); - ``` - -### revokeUserGrantedPermission - -revokeUserGrantedPermission(tokenID: number, permissionName: string, permissionFlag: number, callback: AsyncCallback<number>): void - -撤销应用user grant权限,使用callback回调异步返回结果。 - -需要权限:ohos.permission.REVOKE_SENSITIVE_PERMISSIONS。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | --------- | ------------------- | ---- | ------------------------------------------------------------ | - | tokenID | number | 是 | 目标应用的身份标识。 | - | permissionName | string | 是 | 被撤销的权限名称。 | - | permissionFlag | number | 是 | 授权选项,1表示下次仍需弹窗,2表示允许、禁止后不再提醒,3表示系统授权不允许更改。 | - | callback | AsyncCallback<number> | 是 | 检查撤销应用user grant权限的操作结果同步的回调。 | - -- 示例: - - ``` - const AtManager = abilityAccessCtrl.createAtManager(); - let tokenID = 0; - AtManager.revokeUserGrantedPermission(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS",permissionFlag, data => { - console.log(`callback: data->${JSON.stringify(data)}`); - }); - ``` - -### getPermissionFlags - -getPermissionFlags(tokenID: number, permissionName: string): Promise<number> - -获取指定应用的指定权限的flag,使用Promise方式异步返回结果。 - -- 参数: - - | 参数名 | 类型 | 必填 | 说明 | - | --------- | ------------------- | ---- | ------------------------------------------------------------ | - | tokenID | number | 是 | 目标应用的身份标识。 | - | permissionName | string | 是 | 查询的权限名称。 | - -- 返回值: - - | 类型 | 说明 | - | :------------ | :---------------------------------- | - | Promise<number> | Promise实例,用于获取异步返回的查询结果。 | - -- 示例: - - ``` - const AtManager = abilityAccessCtrl.createAtManager(); - let tokenID = 0; - let promise = AtManager.getPermissionFlags(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS"); - promise.then(data => { - console.log(`promise: data->${JSON.stringify(data)}`); - }); - ``` \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-service-extension-context.md b/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-service-extension-context.md deleted file mode 100644 index 19e9accf30868eef6eb91547829fab0e68cb3f14..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-service-extension-context.md +++ /dev/null @@ -1,206 +0,0 @@ ---- -title: js-apis-service-extension-context -permalink: /pages/extra/01f71d/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# ServiceExtensionContext - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -ServiceExtension的上下文环境,提供ServiceExtension具有的能力和接口,继承自ExtensionContext。 - - -## startAbility - - -startAbility(want: Want, callback: AsyncCallback<void>): void; - - -启动Ability。 - - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | want | [Want](/pages/010c010101#Want类型说明) | 是 | Want类型参数,传入需要启动的ability的信息,如ability名称,包名等。 | - | callback | AsyncCallback<void> | 否 | 回调函数,返回接口调用是否成功的结果。 | - -- 示例: - ``` - let want = { - "bundleName": "com.example.myapp", - "abilityName": "com.example.myapp.MyAbility" - }; - this.context.startAbility(want, (err) => { - console.log('startAbility result:' + JSON.stringfy(err); - } - ``` - - -## startAbility - -startAbility(want: Want): Promise<void>; - -启动Ability。通过Promise返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | want | [Want](/pages/010c010101#Want类型说明) | 是 | Want类型参数,传入需要启动的ability的信息,如ability名称,包名等。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | 返回一个Promise,包含接口的结果。 | - -- 示例: - ``` - let want = { - "bundleName": "com.example.myapp", - "abilityName": "com.example.myapp.MyAbility" - }; - this.context.startAbility(want).then((data) => { - console.log('success:' + JSON.stringfy(data)); - )).catch((error) => { - console.log('failed:' + JSON.stringfy(error)); - }); - ``` - - -## terminateSelf - -terminateSelf(callback: AsyncCallback<void>): void; - -停止Ability自身。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<void> | 否 | 回调函数,返回接口调用是否成功的结果。 | - -- 示例: - ``` - this.context.terminateSelf((err) => { - console.log('terminateSelf result:' + JSON.stringfy(err); - } - ``` - - -## terminateSelf - -terminateSelf(): Promise<void>; - -停止自身。通过Promise返回结果。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | 返回一个Promise,包含接口的结果。 | - -- 示例: - ``` - this.context.terminateSelf(want).then((data) => { - console.log('success:' + JSON.stringfy(data)); - )).catch((error) => { - console.log('failed:' + JSON.stringfy(error)); - }); - ``` - - -## connectAbility - -connectAbility(want: Want, options: ConnectOptions): number; - -将一个Ability与服务类型的Ability绑定。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | want | [Want](/pages/010c010101#Want类型说明) | 是 | Want类型参数,传入需要启动的ability的信息,如ability名称,包名等。 | - | options | [ConnectOptions](#connectoptions) | 是 | ConnectOptions类型的回调函数,返回服务连接成功、断开或连接失败后的信息。 | - -- 返回值 - | 类型 | 说明 | - | -------- | -------- | - | number | 返回一个number,后续根据这个number去断开连接。 | - -- 示例: - ``` - let want = { - "bundleName": "com.example.myapp", - "abilityName": "com.example.myapp.MyAbility" - }; - let options = { - onConnect: function(elementName, proxy) {} - onDisConnect: function(elementName) {} - onFailed: function(code) {} - } - let connection = this.context.connectAbility(want,options); - ``` - - -## disconnectAbility - -disconnectAbility(connection: number, callback:AsyncCallback<void>): void; - -将一个Ability与绑定的服务类型的Ability解绑。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | connection | number | 是 | 在connectAbility中返回的number。 | - | callback | AsyncCallback<void> | 否 | 回调函数,返回接口调用是否成功的结果。 | - -- 示例: - ``` - this.context.disconnectAbility(connection, (err) => { // connection为connectAbility中的返回值 - console.log('terminateSelf result:' + JSON.stringfy(err); - } - ``` - - -## disconnectAbility - -disconnectAbility(connection: number): Promise<void>; - -将一个Ability与绑定的服务类型的Ability解绑。通过Promise返回结果。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | connection | number | 是 | 在connectAbility中返回的number。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Promise<void> | 返回一个Promise,包含接口的结果。 | - -- 示例: - ``` - this.context.disconnectAbility(connection).then((data) => { // connection为connectAbility中的返回值 - console.log('success:' + JSON.stringfy(data)); - )).catch((error) => { - console.log('failed:' + JSON.stringfy(error)); - }); - ``` - - -## ConnectOptions - -ConnectOptions数据结构。 - -| 名称 | 说明 | -| -------- | -------- | -| onConnect(elementName:ElementName, remote:IRemoteObject) | Ability成功连接一个服务类型Ability的回调接口。 | -| onDisconnect(elementName:ElementName) | 对端服务发生异常或者被杀死回调该接口。 | -| onFailed(code: number) | 连接失败时回调该接口。 | diff --git a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-service-extension.md b/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-service-extension.md deleted file mode 100644 index 47e6419b3b3e04ae42f6a88f8d331a373deb586e..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-service-extension.md +++ /dev/null @@ -1,146 +0,0 @@ ---- -title: js-apis-service-extension -permalink: /pages/extra/3f4de7/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# ServiceExtension - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -提供ServiceExtension服务扩展相关接口。 - - -## 导入模块 - -``` -import ServiceExtension from '@ohos.application.ServiceExtension'; -``` - - -## 权限 - -无 - - -## 属性 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| context | [ServiceExtensionContext](/pages/extra/01f71d/) | 是 | 否 | ServiceExtension的上下文环境,继承自ExtensionContext。 | - - -## onCreate - -onCreate(want: Want): void; - -Extension生命周期回调,在创建时回调,执行初始化业务逻辑操作。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | want | [Want](/pages/010c010101#Want类型说明) | 是 | 当前Extension相关的Want类型信息,包括ability名称、bundle名称等。 | - -- 示例: - ``` - onCreate(want) { - console.log('onCreate, want:' + want.abilityName); - } - ``` - - -## onDestroy - -onDestroy(): void; - -Extension生命周期回调,在销毁时回调,执行资源清理等操作。 - -- 示例: - ``` - onDestroy() { - console.log('onDestroy'); - destory(); - } - ``` - - -## onRequest - -onRequest(want: Want, startId: number): void; - -Extension生命周期回调,如果是startAbility拉起的服务,会在onCreate之后回调。每次拉起服务都会回调,startId会递增。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | want | [Want](/pages/010c010101#Want类型说明) | 是 | 当前Extension相关的Want类型信息,包括ability名称、bundle名称等。 | - | startId | number | 是 | 返回拉起次数。首次拉起初始值返回1,多次之后自动递增。 | - -- 示例: - ``` - onRequest(want: Want, startId: number) { - console.log('onRequest, want:' + want.abilityName); - } - ``` - - -## onConnect - -onConnect(want: Want): rpc.RemoteObject; - -Extension生命周期回调,如果是connectAbility拉起的服务,会在onCreate之后回调。返回一个RemoteObject对象,用于和客户端进行通信。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | want | [Want](/pages/010c010101#Want类型说明)| 是 | 当前Extension相关的Want类型信息,包括ability名称、bundle名称等。 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | rpc.RemoteObject | 一个RemoteObject对象,用于和客户端进行通信。 | - -- 示例: - ``` - import rpc from '@ohos.rpc' - class StubTest extends rpc.RemoteObject{ - constructor(des) { - super(des); - } - onRemoteRequest(code, data, reply, option) { - } - } - ... - onConnect(want) { - console.log('onConnect , want:' + want.abilityName); - return new StubTest("test"); - } - ``` - - -## onDisconnect - -onDisconnect(want: Want): void; - -Extension的生命周期,断开服务连接时回调。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | want |[Want](/pages/010c010101#Want类型说明)| 是 | 当前Extension相关的Want类型信息,包括ability名称、bundle名称等。 | - -- 示例: - ``` - onDisconnect(want) { - console.log('onDisconnect, want:' + want.abilityName); - } - ``` diff --git a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-stack.md b/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-stack.md deleted file mode 100644 index fe0e8e05ad5ddce2aef80c73bac39d5db993a474..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-stack.md +++ /dev/null @@ -1,235 +0,0 @@ ---- -title: js-apis-stack -permalink: /pages/extra/eafceb/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 线性容器Stack - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import Stack from '@ohos.util.Stack' -``` - - -## 权限 - -无 - - -## Stack - - -### 属性 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| length | number | 是 | 否 | Stack的元素个数 | - - -### constructor - -constructor(); - -Stack的构造函数。 - - -- 示例: - ``` - let stack = new Stack(); - ``` - - -### push - -push(item: T): T; - -在栈顶插入元素,并返回该元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | item | T | 是 | 添加进去的元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | T | 返回被添加进去的元素 | - -- 示例: - ``` - let stack = new Stack(); - stack.push("a"); - stack.push(1); - let b = [1, 2, 3]; - stack.push(b); - let c = {name : "lala", age : "13"}; - stack.push(false); - ``` - -### pop - -pop(): T; - -删除栈顶元素并返回该删除元素。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | T | 返回删除的元素 | - -- 示例: - ``` - let stack = new Stack(); - stack.push(2); - stack.push(4); - stack.push(5); - stack.push(2); - stack.push(4); - stack.pop(); - ``` - -### peek - -peek(): T; - -获取并返回栈顶元素。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | T | 返回栈顶元素 | - -- 示例: - ``` - let stack = new Stack(); - stack.push(2); - stack.push(4); - stack.push(5); - stack.push(2); - stack.peek(); - ``` -### locate - -locate(element: T): number; - -返回指定元素第一次出现时的下标值,查找失败返回-1。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | element | T | 是 | 指定元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 找到就返回下标值,查找失败返回-1 | -- 示例: - ``` - let stack = new Stack(); - stack.push(2); - stack.push(4); - stack.push(5); - stack.push(2); - stack.locate(2); - ``` - -### forEach -forEach(callbackfn: (value: T, index?: number, stack?: Stack<T>) => void, -thisArg?: Object): void; - -通过回调函数来遍历Stack实例对象上的元素以及元素对应的下标。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callbackfn | function | 是 | 回调函数 | - | thisArg | Object | 否 | callbackfn被调用时用作this值 | - -- callbackfn的参数说明 - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | T | 是 | 当前遍历到的元素。 | - | index | number | 否 | 当前遍历到的下标值。 | - | stack | Stack<T> | 否 | 当前调用forEach方法的实例对象。 | - - -- 示例: - ``` - let stack = new Stack(); - stack.push(2); - stack.push(4); - stack.push(5); - stack.push(4); - stack.forEach((value, index) => { - console.log(value, index); - }); - ``` -### isEmpty -isEmpty(): boolean; - -判断该栈是否为空。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 为空返回true, 不为空返回false | - -- 示例: - ``` - let stack = new Stack(); - stack.push(2); - stack.push(4); - stack.push(5); - stack.push(4); - stack.isEmpty(); - ``` - -### [Symbol.iterator] - -[Symbol.iterator]\(): IterableIterator<T>; - - -返回一个迭代器,迭代器的每一项都是一个 JavaScript 对象,并返回该对象。 - - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | IterableIterator<T> | 返回一个迭代器 | - - -- 示例: - ``` - let stack = new Stack(); - stack.push(2); - stack.push(4); - stack.push(5); - stack.push(4); - - // 使用方法一: - for (let item of stack) { - console.log(item); - } - - // 使用方法二: - let iter = stack[Symbol.iterator](); - let temp = iter.next().value; - while(temp != undefined) { - console.log(temp); - temp = iter.next().value; - } - ``` \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-treemap.md b/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-treemap.md deleted file mode 100644 index 33688e7eea95ae9cb068cb0bd62d8890c7546a10..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-treemap.md +++ /dev/null @@ -1,489 +0,0 @@ ---- -title: js-apis-treemap -permalink: /pages/extra/f84378/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 非线性容器TreeMap - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import TreeMap from '@ohos.util.TreeMap' -``` - - -## 权限 - -无 - -## TreeMap - - -### 属性 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| length | number | 是 | 否 | TreeMap的元素个数 | - - -### constructor - -constructor(comparator?:(firstValue: K, secondValue: K) => boolean); - -TreeMap的构造函数。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | comparator | function | 否 | 用户自定义的比较函数 | - -- 示例: - ``` - let treeMap = new TreeMap(); - ``` - - -### isEmpty - -isEmpty(): boolean; - -判断该容器是否为空。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 为空返回true, 不为空返回false | - -- 示例: - ``` - const treeMap = new TreeMap(); - treeMap.isEmpty(); - ``` - - -### hasKey - -hasKey(key: K): boolean; - -判断此容器中是否含有该指定key。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | K | 是 | 指定元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 是否包含指定元素 | - -- 示例: - ``` - let treeMap = new TreeMap(); - treeMap.hasKey("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - treeMap.hasKey("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - ``` - - -### hasValue - -hasValue(value: V): boolean; - -判断此容器中是否含有该指定value。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | V | 是 | 指定元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 是否包含指定元素 | - -- 示例: - ``` - let treeMap = new TreeMap(); - treeMap.hasValue(123); - treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - treeMap.hasValue(123); - ``` - - -### get - -get(key: K): V; - -获取指定key所对应的value。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | K | 是 | 查找的指定key | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | V | 返回key映射的value值 | - -- 示例: - ``` - let treeMap = new TreeMap(); - treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - treeMap.set("sdfs", 356); - treeMap.get("sdfs"); - ``` - - -### getFirstKey - -getFirstKey(): K; - -获取容器中排序第一的数据。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | K | 返回排序第一的数据 | - -- 示例: - ``` - let treeMap = new TreeMap(); - treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - treeMap.set("sdfs", 356); - let result = treeMap.getFirstKey(); - ``` - - -### getLastKey - -getLastKey(): K; - -获取容器中排序最后的数据。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | K | 返回排序最后的数据 | - -- 示例: - ``` - let treeMap = new TreeMap(); - treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - treeMap.set("sdfs", 356); - let result = treeMap.getLastKey(); - ``` - - -### setAll - -setAll(map: TreeMap): void; - -将一个treemap中的所有元素组添加到另一个treemap中。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | map | TreeMap | 是 | 被添加元素的treemap | - -- 示例: - ``` - let treeMap = new TreeMap(); - treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - treeMap.set("sdfs", 356); - let map = new TreeMap(); - treeMap.setAll(map); - ``` - - -### set -set(key: K, value: V): Object; - -向treemap中添加一组数据。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | K | 是 | 添加成员数据的键名 | - | value | V | 是 | 添加成员数据的值 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Object | 返回添加后的hashmap | - -- 示例: - ``` - let treeMap = new TreeMap(); - treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - ``` - - -### remove - -remove(key: K): V; - -删除指定的元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | K | 是 | 依据key指定删除的元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | V | 返回删除元素的值 | - -- 示例: - ``` - let treeMap = new TreeMap(); - treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - treeMap.set("sdfs", 356); - treeMap.remove("sdfs"); - ``` - - -### getLowerByKey - -getLowerByKey(key: K): K; - -获取容器中比传入key排序靠前一位的key。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | K | 是 | 对比的key值 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | K | 返回排序中key前一位的数据 | - -- 示例: - ``` - let treeMap = new TreeMap(); - treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - treeMap.set("sdfs", 356); - treeMap.set("zdfgsd", 356); - let result = treeMap.getLowerByKey("sdfs"); - ``` - - -### getHigherByKey - -getHigherByKey(key: K): K; - -获取容器中比传入key排序靠后一位的key。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | K | 是 | 对比的key值 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | K | 返回排序中key后一位的数据 | - -- 示例: - ``` - let treeMap = new TreeMap(); - treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - treeMap.set("sdfs", 356); - treeMap.set("zdfgsd", 356); - let result = treeMap.getHigherByKey("sdfs"); - ``` - - -### replace -replace(key: K, value: V): boolean; - -对TreeMap中一组数据进行更新(替换)。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | K | 是 | 依据key指定替换的元素 | - | value | V | 是 | 添加成员数据的值 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 是否成功对已有数据进行替换 | - -- 示例: - ``` - let treeMap = new TreeMap(); - treeMap.set("sdfs", 123); - treeMap.replace("sdfs", 357); - ``` - - -### clear - -clear(): void; - -清除TreeMap中的所有元素,并把length置为0。 - -- 示例: - ``` - let treeMap = new TreeMap(); - treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - treeMap.set("sdfs", 356); - treeMap.clear(); - ``` - - -### keys - -keys(): IterableIterator<K>; - -返回包含此映射中包含的键的新迭代器对象。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | IterableIterator<K> | 返回一个迭代器 | - -- 示例: - ``` - let treeMap = new TreeMap(); - treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - treeMap.set("sdfs", 356); - let iter = treeMap.keys(); - let temp = iter.next().value; - while(temp != undefined) { - console.log(temp); - temp = iter.next().value; - } - ``` - - -### values - -values(): IterableIterator<V>; - -返回包含此映射中包含的键的新迭代器对象。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | IterableIterator<V> | 返回一个迭代器 | - -- 示例: - ``` - let treeMap = new TreeMap(); - treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - treeMap.set("sdfs", 356); - let iter = treeMap.values(); - let temp = iter.next().value; - while(temp != undefined) { - console.log(temp); - temp = iter.next().value; - } - ``` - - -### forEach - -forEach(callbackfn: (value: V, key?: K, treeMap?: TreeMap) => void, thisArg?: Object): void; - -通过回调函数来遍历实例对象上的元素以及元素对应的下标。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callbackfn | function | 是 | 回调函数 | - | thisArg | Object | 否 | callbackfn被调用时用作this值 | - -- callbackfn的参数说明 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | V | 是 | 当前遍历到的元素键值对的值 | - | key | K | 是 | 当前遍历到的元素键值对的键 | - | treeMap | TreeMap | 否 | 当前调用forEach方法的实例对象 | - -- 示例: - ``` - let treeMap = new TreeMap(); - treeMap.set("sdfs", 123); - treeMap.set("dfsghsf", 357); - treeMap.forEach((value, key) => { - console.log(value, key); - }); - ``` - - -### entries - -entries(): IterableIterator<[K, V]>; - -返回包含此映射中包含的键的新迭代器对象。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | IterableIterator<[K, V]> | 返回一个迭代器 | - -- 示例: - ``` - let treeMap = new TreeMap(); - treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - treeMap.set("sdfs", 356); - let iter = treeMap.entries(); - let temp = iter.next().value; - while(temp != undefined) { - console.log(temp[0]); - console.log(temp[1]); - temp = iter.next().value; - } - ``` - - -### [Symbol.iterator] - -[Symbol.iterator]\(): IterableIterator<[K, V]>; - - -返回一个迭代器,迭代器的每一项都是一个 JavaScript 对象,并返回该对象。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | IterableIterator<[K, V]> | 返回一个迭代器 | - -- 示例: - ``` - let treeMap = new TreeMap(); - treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); - treeMap.set("sdfs", 356); - - // 使用方法一: - for (let item of treeMap) { - console.log("key: " + item[0]); - console.log("value: " + item[1]); - } - - // 使用方法二: - let iter = treeMap[Symbol.iterator](); - let temp = iter.next().value; - while(temp != undefined) { - console.log(temp[0]); - console.log(temp[1]); - temp = iter.next().value; - } - ``` \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-treeset.md b/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-treeset.md deleted file mode 100644 index 55371e9662662bcfa21e0a12ab2bd3306e5a2700..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-treeset.md +++ /dev/null @@ -1,406 +0,0 @@ ---- -title: js-apis-treeset -permalink: /pages/extra/2d9ad7/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 非线性容器TreeSet - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import TreeSet from '@ohos.util.TreeSet' -``` - - -## 权限 - -无 - -## TreeSet - - -### 属性 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| length | number | 是 | 否 | TreeSet的元素个数 | - - -### constructor - -constructor(comparator?:(firstValue: T, secondValue: T) => boolean); - -TreeSet的构造函数。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | comparator | function | 否 | 用户自定义的比较函数 | - -- 示例: - ``` - let treeSet = new TreeSet(); - ``` - - -### isEmpty - -isEmpty(): boolean; - -判断该容器是否为空。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 为空返回true, 不为空返回false | - -- 示例: - ``` - const treeSet = new TreeSet(); - treeSet.isEmpty(); - ``` - - -### has - -has(value: T): boolean; - -判断此容器中是否含有该指定value。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | T | 是 | 指定元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 是否包含指定元素 | - -- 示例: - ``` - let treeSet = new TreeSet(); - treeSet.has(123); - treeSet.add(123); - treeSet.has(123); - ``` - - -### getFirstValue - -getFirstValue(): T; - -获取容器中排序第一的数据。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | T | 返回排序第一的数据 | - -- 示例: - ``` - let treeSet = new TreeSet(); - treeSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - treeSet.add("sdfs"); - let result = treeSet.getFirstValue(); - ``` - - -### getLastValue - -getLastValue(): T; - -获取容器中排序最后的数据。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | T | 返回排序最后的数据 | - -- 示例: - ``` - let treeSet = new TreeSet(); - treeSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - treeSet.add("sdfs"); - let result = treeSet.getLastValue(); - ``` - - -### add -add(value: T): boolean; - -向TreeSet中添加一组数据。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | T | 是 | 添加的成员数据 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 是否成功添加新数据至容器 | - -- 示例: - ``` - let treeSet = new TreeSet(); - treeSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - ``` - - -### remove - -remove(key: T): boolean; - -删除指定的元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | T | 是 | 指定的元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 判断是否成功删除元素 | - -- 示例: - ``` - let treeSet = new TreeSet(); - treeSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - treeSet.add("sdfs"); - treeSet.remove("sdfs"); - ``` - - -### getLowerValue - -getLowerValue(key: T): T; - -获取容器中比传入元素排序靠前一位的元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | T | 是 | 对比的元素值 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | T | 返回排序中对比元素前一位的数据 | - -- 示例: - ``` - let treeSet = new TreeSet(); - treeSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - treeSet.add("sdfs"); - treeSet.add("zdfgsd"); - let result = treeSet.getLowerValue("sdfs"); - ``` - - -### getHigherValue - -getHigherValue(key: T): T; - -获取容器中比传入元素排序靠后一位的元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | key | T | 是 | 对比的元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | T | 返回排序中传入元素后一位的数据 | - -- 示例: - ``` - let treeSet = new TreeSet(); - treeSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - treeSet.add("sdfs"); - treeSet.add("zdfgsd"); - let result = treeSet.getHigherValue("sdfs"); - ``` - - -### popFirst - -popFirst(): T; - -删除容器中排序最前的数据。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | T | 返回删除的数据 | - -- 示例: - ``` - let treeSet = new TreeSet(); - treeSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - treeSet.add("sdfs"); - let result = treeSet.popFirst(); - ``` - - -### popLast - -popLast(): T; - -删除容器中排序最后的数据。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | T | 返回删除的数据 | - -- 示例: - ``` - let treeSet = new TreeSet(); - treeSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - treeSet.add("sdfs"); - let result = treeSet.popLast(); - ``` - - -### clear - -clear(): void; - -清除容器中的所有元素,并把length置为0。 - -- 示例: - ``` - let treeSet = new TreeSet(); - treeSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - treeSet.add("sdfs"); - treeSet.clear(); - ``` - - -### values - -values(): IterableIterator<T>; - -返回包含此映射中包含的键的新迭代器对象。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | IterableIterator<T> | 返回一个迭代器 | - -- 示例: - ``` - let treeSet = new TreeSet(); - treeSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - treeSet.add("sdfs"); - let iter = treeSet.values(); - let temp = iter.next().value; - while(temp != undefined) { - console.log(temp); - temp = iter.next().value; - } - ``` - - -### forEach - -forEach(callbackfn: (value: T, key?: T, treeSet?: TreeSet<T>) => void, thisArg?: Object): void; - -通过回调函数来遍历实例对象上的元素以及元素对应的下标。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callbackfn | function | 是 | 回调函数 | - | thisArg | Object | 否 | callbackfn被调用时用作this值 | - -- callbackfn的参数说明 - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | T | 是 | 当前遍历到的元素 | - | key | T | 否 | 当前遍历到的元素(和value相同). | - | treeSet | TreeSet<T> | 否 | 当前调用forEach方法的实例对象 | - -- 示例: - ``` - let treeSet = new TreeSet(); - treeSet.add("sdfs"); - treeSet.add("dfsghsf"); - treeSet.forEach((value, key) => { - console.log(value, key) - }); - ``` - - -### entries - -entries(): IterableIterator<[T, T]>; - -返回包含此映射中包含的键的新迭代器对象。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | IterableIterator<[T, T]> | 返回一个迭代器 | - -- 示例: - ``` - let treeSet = new TreeSet(); - treeSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - treeSet.add("sdfs"); - let iter = treeSet.entries(); - let temp = iter.next().value; - while(temp != undefined) { - console.log(temp[0]); - console.log(temp[1]); - temp = iter.next().value; - } - ``` - - -### [Symbol.iterator] - -[Symbol.iterator]\(): IterableIterator<T>; - - -返回一个迭代器,迭代器的每一项都是一个 JavaScript 对象,并返回该对象。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | IterableIterator<T> | 返回一个迭代器 | - -- 示例: - ``` - let treeSet = new TreeSet(); - treeSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - treeSet.add("sdfs"); - - // 使用方法一: - for (let item of treeSet) { - console.log("value: " + item); - } - - // 使用方法二: - let iter = treeSet[Symbol.iterator](); - let temp = iter.next().value; - while(temp != undefined) { - console.log(temp); - temp = iter.next().value; - } - ``` \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-vector.md b/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-vector.md deleted file mode 100644 index 429c32253d0706d7f83be9d1c778709f72b52ae9..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/apis/js-apis-vector.md +++ /dev/null @@ -1,697 +0,0 @@ ---- -title: js-apis-vector -permalink: /pages/extra/444403/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 线性容器Vector - -> ![icon-note.gif](/images/application-dev/reference/apis/public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - - -## 导入模块 - -``` -import Vector from '@ohos.util.Vector' -``` - - -## 权限 - -无 - - -## Vector - - -### 属性 - -| 名称 | 参数类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| length | number | 是 | 否 | Vector的元素个数 | - - -### constructor - -constructor(); - -Vector的构造函数。 - -- 示例: - ``` - let vector = new Vector(); - ``` - - -### add - -add(element: T): boolean; - -在Vector中尾部插入元素 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | element | T | 是 | 添加进去的元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 插入成功返回true,失败返回false | - -- 示例: - ``` - let vector = new Vector(); - vector.add("a"); - vector.add(1); - let b = [1, 2, 3]; - vector.add(b); - let c = {name : "lala", age : "13"}; - vector.add(false); - ``` - -### insert - -insert(element: T, index: number): void; - -在长度范围内任意插入指定元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | element | T | 是 | 被插入的元素 | - | index | number | 是 | 被插入的位置索引 | - -- 示例: - ``` - let vector = new Vector(); - vector.insert("A", 0); - vector.insert(0, 1); - vector.insert(true, 2); - ``` - -### has - -has(element: T): boolean; - -判断此Vector中是否含有该指定元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | element | T | 是 | 指定的元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 是否包含指定元素 | - -- 示例: - ``` - let vector = new Vector(); - vector.has("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - vector.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - vector.has("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); - ``` - -### getIndexOf - -getIndexOf(element: T): number; - -返回指定元素第一次出现时的下标值,查找失败返回-1。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | element | T | 是 | 指定的元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 返回指定元素第一次出现时的下标值,查找失败返回-1 | - -- 示例: - ``` - let vector = new Vector(); - vector.add(2); - vector.add(4); - vector.add(5); - vector.add(2); - vector.add(1); - vector.add(2); - vector.add(4); - vector.getIndexOf(2); - ``` -### getLastIndexOf - -getLastIndexOf(element: T): number; - -返回指定元素最后一次出现时的下标值,查找失败返回-1。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | element | T | 是 | 指定元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 返回指定元素最后一次出现时的下标值,查找失败返回-1 | - -- 示例: - ``` - let vector = new Vector(); - vector.add(2); - vector.add(4); - vector.add(5); - vector.add(2); - vector.add(1); - vector.add(2); - vector.add(4); - vector.getLastIndexOf(2); - ``` -### removeByIndex - -removeByIndex(index: number): T; - -根据元素的下标值查找元素,返回元素后将其删除。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | index | number | 是 | 指定元素的下标值 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | T | 返回删除的元素 | - -- 示例: - ``` - let vector = new Vector(); - vector.add(2); - vector.add(4); - vector.add(5); - vector.add(2); - vector.add(4); - vector.removeByIndex(2); - ``` - -### remove - -remove(element: T): boolean; - -删除查找到的第一个指定的元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | element | T | 是 | 指定元素 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 删除成功返回true,失败返回false | - -- 示例: - ``` - let vector = new Vector(); - vector.add(2); - vector.add(4); - vector.add(5); - vector.add(4); - vector.remove(2); - ``` -### removeByRange -removeByRange(fromIndex: number, toIndex: number): void; - -从一段范围内删除元素,包括起始值但不包括终止值。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | fromIndex | number | 是 | 起始下标 | - | toIndex | number | 是 | 终止下标 | - -- 示例: - ``` - let vector = new Vector(); - vector.add(2); - vector.add(4); - vector.add(5); - vector.add(4); - vector.removeByRange(2,4); - vector.removeByRange(4,3); - vector.removeByRange(2,6); - ``` - -### replaceAllElements -replaceAllElements(callbackfn: (value: T, index?: number, vector?: Vector<T>) => T, -thisArg?: Object): void; - -用户操作Vector中的元素,用操作后的元素替换原元素并返回操作后的元素。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callbackfn | function | 是 | 回调函数 | - | thisArg | Object | 否 | callbackfn被调用时用作this值 | - -- callbackfn的参数说明 - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | T | 是 | 当前遍历到的元素 | - | index | number | 否 | 当前遍历到的下标值 | - | vector | Vector<T> | 否 | 当前调用replaceAllElements方法的实例对象 | - -- 示例: - ``` - let vector = new Vector(); - vector.add(2); - vector.add(4); - vector.add(5); - vector.add(4); - vector.replaceAllElements((value, index) => { - return value = 2 * value; - }); - vector.replaceAllElements((value, index) => { - return value = value - 2; - }); - ``` -### forEach -forEach(callbackfn: (value: T, index?: number, vector?: Vector<T>) => void, -thisArg?: Object): void; - -通过回调函数来遍历Vector实例对象上的元素以及元素对应的下标。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | callbackfn | function | 是 | 回调函数。 | - | thisArg | Object | 否 | callbackfn被调用时用作this值 | - -- callbackfn的参数说明 - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | value | T | 是 | 当前遍历到的元素。 | - | index | number | 否 | 当前遍历到的下标值。 | - | vector | Vector<T> | 否 | 当前调用forEach方法的实例对象。 | - - -- 示例: - ``` - let vector = new Vector(); - vector.add(2); - vector.add(4); - vector.add(5); - vector.add(4); - vector.forEach((value, index) => { - console.log(value, index) - }); - - ``` -### sort -sort(comparator?: (firstValue: T, secondValue: T) => number): void; - -对Vector中的元素进行一个排序操作。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | comparator | function | 否 | 回调函数。 | - -- comparator的参数说明 - - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | firstValue | T | 是 | 前一项元素 | - | secondValue | T | 是 | 后一项元素 | - - -- 示例: - ``` - let vector = new Vector(); - vector.add(2); - vector.add(4); - vector.add(5); - vector.add(4); - vector.sort(a, (b => a - b)); - vector.sort(a, (b => b - a)); - vector.sort(); - ``` -### subVector -subVector(fromIndex: number, toIndex: number): Vector<T>; - -根据下标截取Vector中的一段元素,并返回这一段vector实例,包括起始值但不包括终止值。 -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | fromIndex | number | 是 | 起始下标 | - | toIndex | number | 是 | 终止下标 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Vector<T> | 返回Vector对象实例 | - -- 示例: - ``` - let vector = new Vector(); - vector.add(2); - vector.add(4); - vector.add(5); - vector.add(4); - vector.subVector(2,4); - vector.subVector(4,3); - vector.subVector(2,6); - - ``` - -### clear -clear(): void; - -清除Vector中的所有元素,并把length置为0。 - -- 示例: - ``` - let vector = new Vector(); - vector.add(2); - vector.add(4); - vector.add(5); - vector.add(4); - vector.clear(); - ``` -### clone -clone(): Vector<T>; - -克隆一个与Vector一模一样的实例,并返回克隆后的实例,修改克隆后的实例并不会影响原实例。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Vector<T> | 返回Vector对象实例 | - -- 示例: - ``` - let vector = new Vector(); - vector.add(2); - vector.add(4); - vector.add(5); - vector.add(4); - vector.clone(); - ``` -### getCapacity -getCapacity(): number; - -获取当前实例的容量大小。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 返回Vector的容量大小 | - -- 示例: - ``` - let vector = new Vector(); - vector.add(2); - vector.add(4); - vector.add(5); - vector.add(4); - vector.getCapacity(); - ``` -### convertToArray -convertToArray(): Array<T>; - -把当前Vector实例转换成数组,并返回转换后的数组。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | Array<T> | 返回数组类型 | - -- 示例: - ``` - let vector = new Vector(); - vector.add(2); - vector.add(4); - vector.add(5); - vector.add(4); - vector.convertToArray(); - ``` -### isEmpty -isEmpty(): boolean; - -判断该Vector是否为空。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | boolean | 为空返回true, 不为空返回false | - -- 示例: - ``` - let vector = new Vector(); - vector.add(2); - vector.add(4); - vector.add(5); - vector.add(4); - vector.isEmpty(); - ``` -### increaseCapacityTo -increaseCapacityTo(newCapacity: number): void; - -如果传入的新容量大于或等于Vector中的元素个数,将容量变更为新容量。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | newCapacity | number | 是 | 新容量 | - - -- 示例: - ``` - let vector = new Vector(); - vector.add(2); - vector.add(4); - vector.add(5); - vector.add(4); - vector.increaseCapacityTo(2); - vector.increaseCapacityTo(8); - ``` -### trimToCurrentLength -trimToCurrentLength(): void; - -把容量限制为当前的length大小。 - -- 示例: - ``` - let vector = new Vector(); - vector.add(2); - vector.add(4); - vector.add(5); - vector.add(4); - vector.trimToCurrentLength(2); - ``` -### toString - -toString(): string; -用","将Vector实例中的元素按顺序拼接成字符串。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | string | 返回字符串类型 | - - -- 示例: - ``` - let vector = new Vector(); - vector.add(2); - vector.add(4); - vector.add(5); - vector.add(4); - vector.toSting(); - ``` - -### copyToArray - -copyToArray(array: Array<T>): void; -将Vector实例中的元素按照下标复制进array。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | array | Array<T> | 是 | 数组 | - - -- 示例: - ``` - let vector = new Vector(); - vector.add(2); - vector.add(4); - vector.add(5); - vector.add(4); - let array = ["a", "b", "c", "d", "e", "f"]; - vector.copyToArray(array); - ``` -### getFirstElement - -getFirstElement(): T; -获取实例中的第一个元素。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | T | 返回T型 | - - -- 示例: - ``` - let vector = new Vector(); - vector.add(2); - vector.add(4); - vector.add(5); - vector.add(4); - vector.getFirstElement(); - ``` -### getLastElement - -getLastElement(): T; -获取Vector实例中的最后一个元素。 - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | T | 返回T型 | - - -- 示例: - ``` - let vector = new Vector(); - vector.add(2); - vector.add(4); - vector.add(5); - vector.add(4); - vector.getLastElement(); - ``` -### getLastIndexFrom - -getLastIndexFrom(element: T, index: number): number; - -从指定索引向后搜索, 返回该元素的下标索引,如果查找失败,则返回-1。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | element | T | 是 | 要查找的元素 | - | index | number | 是 | 从指定索引开始搜索 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 返回该元素的下标 | - - -- 示例: - ``` - let vector = new Vector(); - vector.add(2); - vector.add(4); - vector.add(5); - vector.add(4); - vector.add("a"); - vector.getLastIndexFrom(4,3); - ``` -### getIndexFrom - -getIndexFrom(element: T, index: number): number; - -从指定索引向前搜索, 返回该元素的下标索引,如果查找失败,则返回 -1 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | element | T | 是 | 要查找的元素 | - | index | number | 是 | 从指定索引开始搜索 | - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | number | 返回该元素的下标 | - - -- 示例: - ``` - let vector = new Vector(); - vector.add(2); - vector.add(4); - vector.add(5); - vector.add(4); - vector.add("a"); - vector.getIndexFrom(4, 3); - ``` -### setLength -setLength(newSize: number): void; -设置Vector实例的元素个数。 - -- 参数: - | 参数名 | 类型 | 必填 | 说明 | - | -------- | -------- | -------- | -------- | - | newSize | number | 是 | 设置的新长度 | - -- 示例: - ``` - let vector = new Vector(); - vector.add(2); - vector.add(4); - vector.add(5); - vector.add(4); - vector.setLength(8); - vector.setLength(2); - ``` - -### [Symbol.iterator] - -[Symbol.iterator]\(): IterableIterator<T>; - - -返回一个迭代器,迭代器的每一项都是一个 JavaScript 对象,并返回该对象。 - - -- 返回值: - | 类型 | 说明 | - | -------- | -------- | - | IterableIterator<T> | 返回一个迭代器。 | - - -- 示例: - ``` - let vector = new Vector(); - vector.add(2); - vector.add(4); - vector.add(5); - vector.add(4); - - // 使用方法一: - for (let item of vector) { - console.log(item); - } - - // 使用方法二: - let iter = vector[Symbol.iterator](); - let temp = iter.next().value; - while(temp != undefined) { - console.log(temp); - temp = iter.next().value; - } - ``` \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/reference/arkui-js/Readme-CN.md b/website/docs/_posts/zh-cn/application-dev/reference/arkui-js/Readme-CN.md deleted file mode 100644 index c44c572aa545dbe79ad5921b9c74f126a2b44684..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/arkui-js/Readme-CN.md +++ /dev/null @@ -1,124 +0,0 @@ ---- -title: Readme-CN -permalink: /pages/extra/74333b/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 基于JS扩展的类Web开发范式 - -- [组件](/pages/extra/075858/) - - [通用](/pages/extra/1ce3c8/) - - [通用属性](/pages/010c0201010101) - - [通用样式](/pages/010c0201010102) - - [通用事件](/pages/010c0201010103) - - [通用方法](/pages/010c0201010104) - - [动画样式](/pages/010c0201010105) - - [渐变样式](/pages/010c0201010106) - - [转场样式](/pages/010c0201010107) - - [媒体查询](/pages/010c0201010108) - - [自定义字体样式](/pages/010c0201010109) - - [原子布局](/pages/010c020101010a) - - - [容器组件](/pages/extra/c45b2f/) - - [badge](/pages/010c0201010201) - - [dialog](/pages/010c0201010202) - - [div](/pages/010c0201010203) - - [form](/pages/010c0201010204) - - [list](/pages/010c0201010205) - - [list-item](/pages/010c0201010206) - - [list-item-group](/pages/010c0201010207) - - [panel](/pages/010c0201010208) - - [popup](/pages/010c0201010209) - - [refresh](/pages/010c020101020a) - - [stack](/pages/010c020101020b) - - [stepper](/pages/010c020101020c) - - [stepper-item](/pages/010c020101020d) - - [swiper](/pages/010c020101020e) - - [tabs](/pages/010c020101020f) - - [tab-bar](/pages/010c0201010210) - - [tab-content](/pages/010c0201010211) - - - [基础组件](/pages/extra/d6389e/) - - [button](/pages/010c0201010301) - - [chart](/pages/010c0201010302) - - [divider](/pages/010c0201010303) - - [image](/pages/010c0201010304) - - [image-animator](/pages/010c0201010305) - - [input](/pages/010c0201010306) - - [label](/pages/010c0201010307) - - [marquee](/pages/010c0201010308) - - [menu](/pages/010c0201010309) - - [option](/pages/010c020101030a) - - [picker](/pages/010c020101030b) - - [picker-view](/pages/010c020101030c) - - [piece](/pages/010c020101030d) - - [progress](/pages/010c020101030e) - - [qrcode](/pages/010c020101030f) - - [rating](/pages/010c0201010310) - - [richtext](/pages/010c0201010311) - - [search](/pages/010c0201010312) - - [select](/pages/010c0201010313) - - [slider](/pages/010c0201010314) - - [span](/pages/010c0201010315) - - [switch](/pages/010c0201010316) - - [text](/pages/010c0201010317) - - [textarea](/pages/010c0201010318) - - [toolbar](/pages/010c0201010319) - - [toolbar-item](/pages/010c020101031a) - - [toggle](/pages/010c020101031b) - - - [媒体组件](/pages/extra/8f898c/) - - [video](/pages/010c0201010401) - - - [画布组件](/pages/extra/c2a5d2/) - - [canvas组件](/pages/010c0201010501) - - [CanvasRenderingContext2D对象](/pages/010c0201010502) - - [Image对象](/pages/010c0201010503) - - [CanvasGradient对象](/pages/010c0201010504) - - [ImageData对象](/pages/010c0201010505) - - [Path2D对象](/pages/010c0201010506) - - [ImageBitmap对象](/pages/010c0201010507) - - [OffscreenCanvas对象](/pages/010c0201010508) - - [OffscreenCanvasRenderingContext2D对象](/pages/010c0201010509) - - - [栅格组件](/pages/extra/6ab25a/) - - [基本概念](/pages/010c0201010601) - - [grid-container](/pages/010c0201010602) - - [grid-row](/pages/010c0201010603) - - [grid-col](/pages/010c0201010604) - - - [svg组件](/pages/extra/c15464/) - - [通用属性](/pages/010c0201010701) - - [svg](/pages/010c0201010702) - - [rect](/pages/010c0201010703) - - [circle](/pages/010c0201010704) - - [ellipse](/pages/010c0201010705) - - [path](/pages/010c0201010706) - - [line](/pages/010c0201010707) - - [polyline](/pages/010c0201010708) - - [polygon](/pages/010c0201010709) - - [text](/pages/010c020101070a) - - [tspan](/pages/010c020101070b) - - [textPath](/pages/010c020101070c) - - [animate](/pages/010c020101070d) - - [animateMotion](/pages/010c020101070e) - - [animateTransform](/pages/010c020101070f) - -- [自定义组件](/pages/extra/e86efb/) - - [基本用法](/pages/010c02010201) - - [自定义事件](/pages/010c02010202) - - [Props](/pages/010c02010203) - - [事件参数](/pages/010c02010204) - - [slot插槽](/pages/010c02010205) - - [生命周期定义](/pages/010c02010206) - -- [附录](/pages/extra/98f426/) - - [类型说明](/pages/010c02010301) - diff --git a/website/docs/_posts/zh-cn/application-dev/reference/arkui-js/js-appendix.md b/website/docs/_posts/zh-cn/application-dev/reference/arkui-js/js-appendix.md deleted file mode 100644 index 8e2172cea43febbfc4ea21970d7c790e61fd2e3d..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/arkui-js/js-appendix.md +++ /dev/null @@ -1,17 +0,0 @@ ---- -title: js-appendix -permalink: /pages/extra/98f426/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 附录 - -- **[类型说明](/pages/010c02010301)** - diff --git a/website/docs/_posts/zh-cn/application-dev/reference/arkui-js/js-components-basic.md b/website/docs/_posts/zh-cn/application-dev/reference/arkui-js/js-components-basic.md deleted file mode 100644 index 4397e24105e8810bf61d4da54a83868ffbcbc702..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/arkui-js/js-components-basic.md +++ /dev/null @@ -1,70 +0,0 @@ ---- -title: js-components-basic -permalink: /pages/extra/d6389e/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 基础组件 - -- **[button](/pages/010c0201010301)** - -- **[chart](/pages/010c0201010302)** - -- **[divider](/pages/010c0201010303)** - -- **[image](/pages/010c0201010304)** - -- **[image-animator](/pages/010c0201010305)** - -- **[input](/pages/010c0201010306)** - -- **[label](/pages/010c0201010307)** - -- **[marquee](/pages/010c0201010308)** - -- **[menu](/pages/010c0201010309)** - -- **[option](/pages/010c020101030a)** - -- **[picker](/pages/010c020101030b)** - -- **[picker-view](/pages/010c020101030c)** - -- **[piece](/pages/010c020101030d)** - -- **[progress](/pages/010c020101030e)** - -- **[qrcode](/pages/010c020101030f)** - -- **[rating](/pages/010c0201010310)** - -- **[richtext](/pages/010c0201010311)** - -- **[search](/pages/010c0201010312)** - -- **[select](/pages/010c0201010313)** - -- **[slider](/pages/010c0201010314)** - -- **[span](/pages/010c0201010315)** - -- **[switch](/pages/010c0201010316)** - -- **[text](/pages/010c0201010317)** - -- **[textarea](/pages/010c0201010318)** - -- **[toolbar](/pages/010c0201010319)** - -- **[toolbar-item](/pages/010c020101031a)** - -- **[toggle](/pages/010c020101031b)** - - diff --git a/website/docs/_posts/zh-cn/application-dev/reference/arkui-js/js-components-canvas.md b/website/docs/_posts/zh-cn/application-dev/reference/arkui-js/js-components-canvas.md deleted file mode 100644 index 60d74556ed4a4827e264e877c19b4facab4099bd..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/arkui-js/js-components-canvas.md +++ /dev/null @@ -1,34 +0,0 @@ ---- -title: js-components-canvas -permalink: /pages/extra/c2a5d2/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 画布组件 - -- **[canvas组件](/pages/010c0201010501)** - -- **[CanvasRenderingContext2D对象](/pages/010c0201010502)** - -- **[Image对象](/pages/010c0201010503)** - -- **[CanvasGradient对象](/pages/010c0201010504)** - -- **[ImageData对象](/pages/010c0201010505)** - -- **[Path2D对象](/pages/010c0201010506)** - -- **[ImageBitmap对象](/pages/010c0201010507)** - -- **[OffscreenCanvas对象](/pages/010c0201010508)** - -- **[OffscreenCanvasRenderingContext2D对象](/pages/010c0201010509)** - - diff --git a/website/docs/_posts/zh-cn/application-dev/reference/arkui-js/js-components-common.md b/website/docs/_posts/zh-cn/application-dev/reference/arkui-js/js-components-common.md deleted file mode 100644 index 7f102c6f1e1bb1395e6be648b416aba67bfef486..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/arkui-js/js-components-common.md +++ /dev/null @@ -1,36 +0,0 @@ ---- -title: js-components-common -permalink: /pages/extra/1ce3c8/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 通用 - -- **[通用属性](/pages/010c0201010101)** - -- **[通用样式](/pages/010c0201010102)** - -- **[通用事件](/pages/010c0201010103)** - -- **[通用方法](/pages/010c0201010104)** - -- **[动画样式](/pages/010c0201010105)** - -- **[渐变样式](/pages/010c0201010106)** - -- **[转场样式](/pages/010c0201010107)** - -- **[媒体查询](/pages/010c0201010108)** - -- **[自定义字体样式](/pages/010c0201010109)** - -- **[原子布局](/pages/010c020101010a)** - - diff --git a/website/docs/_posts/zh-cn/application-dev/reference/arkui-js/js-components-container.md b/website/docs/_posts/zh-cn/application-dev/reference/arkui-js/js-components-container.md deleted file mode 100644 index 10cb9b89da64045ae6b1b44c5c13f5368cfa1a09..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/arkui-js/js-components-container.md +++ /dev/null @@ -1,50 +0,0 @@ ---- -title: js-components-container -permalink: /pages/extra/c45b2f/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 容器组件 - -- **[badge](/pages/010c0201010201)** - -- **[dialog](/pages/010c0201010202)** - -- **[div](/pages/010c0201010203)** - -- **[form](/pages/010c0201010204)** - -- **[list](/pages/010c0201010205)** - -- **[list-item](/pages/010c0201010206)** - -- **[list-item-group](/pages/010c0201010207)** - -- **[panel](/pages/010c0201010208)** - -- **[popup](/pages/010c0201010209)** - -- **[refresh](/pages/010c020101020a)** - -- **[stack](/pages/010c020101020b)** - -- **[stepper](/pages/010c020101020c)** - -- **[stepper-item](/pages/010c020101020d)** - -- **[swiper](/pages/010c020101020e)** - -- **[tabs](/pages/010c020101020f)** - -- **[tab-bar](/pages/010c0201010210)** - -- **[tab-content](/pages/010c0201010211)** - - diff --git a/website/docs/_posts/zh-cn/application-dev/reference/arkui-js/js-components-custom.md b/website/docs/_posts/zh-cn/application-dev/reference/arkui-js/js-components-custom.md deleted file mode 100644 index 4218523d0d7fc5a0de3783ff7098e86acf66db9b..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/arkui-js/js-components-custom.md +++ /dev/null @@ -1,28 +0,0 @@ ---- -title: js-components-custom -permalink: /pages/extra/e86efb/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 自定义组件 - -- **[基本用法](/pages/010c02010201)** - -- **[自定义事件](/pages/010c02010202)** - -- **[Props](/pages/010c02010203)** - -- **[事件参数](/pages/010c02010204)** - -- **[slot插槽](/pages/010c02010205)** - -- **[生命周期定义](/pages/010c02010206)** - - diff --git a/website/docs/_posts/zh-cn/application-dev/reference/arkui-js/js-components-grid.md b/website/docs/_posts/zh-cn/application-dev/reference/arkui-js/js-components-grid.md deleted file mode 100644 index 01a461275305dca1df2bb4b2c59203e8ba471156..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/arkui-js/js-components-grid.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -title: js-components-grid -permalink: /pages/extra/6ab25a/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 栅格组件 - -- **[基本概念](/pages/010c0201010601)** - -- **[grid-container](/pages/010c0201010602)** - -- **[grid-row](/pages/010c0201010603)** - -- **[grid-col](/pages/010c0201010604)** - - diff --git a/website/docs/_posts/zh-cn/application-dev/reference/arkui-js/js-components-media.md b/website/docs/_posts/zh-cn/application-dev/reference/arkui-js/js-components-media.md deleted file mode 100644 index c4e1b9d499d65cd003c478ae8df3f9c07b0210ed..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/arkui-js/js-components-media.md +++ /dev/null @@ -1,18 +0,0 @@ ---- -title: js-components-media -permalink: /pages/extra/8f898c/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 媒体组件 - -- **[video](/pages/010c0201010401)** - - diff --git a/website/docs/_posts/zh-cn/application-dev/reference/arkui-js/js-components.md b/website/docs/_posts/zh-cn/application-dev/reference/arkui-js/js-components.md deleted file mode 100644 index f5aaf1e11b7864a934959256318cc18ab9ac9013..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/arkui-js/js-components.md +++ /dev/null @@ -1,30 +0,0 @@ ---- -title: js-components -permalink: /pages/extra/075858/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 组件 - -- **[通用](/pages/extra/1ce3c8/)** - -- **[容器组件](/pages/extra/c45b2f/)** - -- **[基础组件](/pages/extra/d6389e/)** - -- **[媒体组件](/pages/extra/8f898c/)** - -- **[画布组件](/pages/extra/c2a5d2/)** - -- **[栅格组件](/pages/extra/6ab25a/)** - -- **[svg组件](/pages/extra/c15464/)** - - diff --git a/website/docs/_posts/zh-cn/application-dev/reference/arkui-js/js-svg.md b/website/docs/_posts/zh-cn/application-dev/reference/arkui-js/js-svg.md deleted file mode 100644 index 72f3a469b81c0ede8ceffd0ff016325f10f0ab08..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/arkui-js/js-svg.md +++ /dev/null @@ -1,46 +0,0 @@ ---- -title: js-svg -permalink: /pages/extra/c15464/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# svg组件 - -- **[通用属性](/pages/010c0201010701)** - -- **[svg](/pages/010c0201010702)** - -- **[rect](/pages/010c0201010703)** - -- **[circle](/pages/010c0201010704)** - -- **[ellipse](/pages/010c0201010705)** - -- **[path](/pages/010c0201010706)** - -- **[line](/pages/010c0201010707)** - -- **[polyline](/pages/010c0201010708)** - -- **[polygon](/pages/010c0201010709)** - -- **[text](/pages/010c020101070a)** - -- **[tspan](/pages/010c020101070b)** - -- **[textPath](/pages/010c020101070c)** - -- **[animate](/pages/010c020101070d)** - -- **[animateMotion](/pages/010c020101070e)** - -- **[animateTransform](/pages/010c020101070f)** - - diff --git a/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/Readme-CN.md b/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/Readme-CN.md deleted file mode 100644 index 0cb124ae7da1fce22dca0d651a71c5ebef2d59cb..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/Readme-CN.md +++ /dev/null @@ -1,146 +0,0 @@ ---- -title: Readme-CN -permalink: /pages/extra/07ffe5/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 基于TS扩展的声明式开发范式 - -- [组件](/pages/extra/710f05/) - - [通用](/pages/extra/f7c41d/) - - [通用事件](/pages/extra/1ab473/) - - [点击事件](/pages/010c020201010101) - - [触摸事件](/pages/010c020201010102) - - [挂载卸载事件](/pages/010c020201010103) - - [按键事件](/pages/010c020201010104) - - [组件区域变化事件](/pages/010c020201010105) - - - [通用属性](/pages/extra/b89109/) - - [尺寸设置](/pages/010c020201010201) - - [位置设置](/pages/010c020201010202) - - [布局约束](/pages/010c020201010203) - - [Flex布局](/pages/010c020201010204) - - [边框设置](/pages/010c020201010205) - - [背景设置](/pages/010c020201010206) - - [透明度设置](/pages/010c020201010207) - - [显隐控制](/pages/010c020201010208) - - [禁用控制](/pages/010c020201010209) - - [浮层](/pages/010c02020101020a) - - [Z序控制](/pages/010c02020101020b) - - [图形变换](/pages/010c02020101020c) - - [图像效果](/pages/010c02020101020d) - - [形状裁剪](/pages/010c02020101020e) - - [文本样式设置](/pages/010c02020101020f) - - [栅格设置](/pages/010c020201010210) - - [颜色渐变](/pages/010c020201010211) - - [Popup控制](/pages/010c020201010212) - - [Menu控制](/pages/010c020201010213) - - [点击控制](/pages/010c020201010214) - - [触摸热区设置](/pages/010c020201010215) - - - [手势处理](/pages/extra/74ae35/) - - [绑定手势方法](/pages/010c020201010301) - - [基础手势](/pages/extra/51a545/) - - [TapGesture](/pages/010c02020101030201) - - [LongPressGesture](/pages/010c02020101030202) - - [PanGesture](/pages/010c02020101030203) - - [PinchGesture](/pages/010c02020101030204) - - [RotationGesture](/pages/010c02020101030205) - - [SwipeGesture](/pages/010c02020101030206) - - - [组合手势](/pages/010c020201010303) - - - [基础组件](/pages/extra/8c88be/) - - [Blank](/pages/010c0202010201) - - [Button](/pages/010c0202010202) - - [DataPanel](/pages/010c0202010203) - - [Divider](/pages/010c0202010204) - - [Gauge](/pages/010c0202010205) - - [Image](/pages/010c0202010206) - - [ImageAnimator](/pages/010c0202010207) - - [Marquee](/pages/extra/0ecb0c/) - - [Progress](/pages/010c0202010208) - - [QRCode](/pages/010c0202010209) - - [Rating](/pages/010c020201020a) - - [Span](/pages/010c020201020b) - - [Slider](/pages/010c020201020c) - - [Text](/pages/010c020201020d) - - [TextArea](/pages/010c020201020e) - - [TextInput](/pages/010c020201020f) - - [Toggle](/pages/010c0202010210) - - - [容器组件](/pages/extra/4dbed9/) - - [AlphabetIndexer](/pages/010c0202010301) - - [Badge](/pages/010c0202010302) - - [Column](/pages/010c0202010303) - - [ColumnSplit](/pages/010c0202010304) - - [Counter](/pages/010c0202010305) - - [Flex](/pages/010c0202010306) - - [GridContainer](/pages/010c0202010307) - - [Grid](/pages/010c0202010308) - - [GridItem](/pages/010c0202010309) - - [List](/pages/010c020201030a) - - [ListItem](/pages/010c020201030b) - - [Navigator](/pages/010c020201030c) - - [Navigation](/pages/010c020201030d) - - [Panel](/pages/010c020201030e) - - [Row](/pages/010c020201030f) - - [RowSplit](/pages/010c0202010310) - - [Scroll](/pages/010c0202010311) - - [ScrollBar](/pages/010c0202010312) - - [Stack](/pages/010c0202010313) - - [Swiper](/pages/010c0202010314) - - [Tabs](/pages/010c0202010315) - - [TabContent](/pages/010c0202010316) - - [Stepper](/pages/010c0202010317) - - [StepperItem](/pages/010c0202010318) - - - [绘制组件](/pages/extra/0ed70d/) - - [Circle](/pages/010c0202010401) - - [Ellipse](/pages/010c0202010402) - - [Line](/pages/010c0202010403) - - [Polyline](/pages/010c0202010404) - - [Polygon](/pages/010c0202010405) - - [Path](/pages/010c0202010406) - - [Rect](/pages/010c0202010407) - - [Shape](/pages/010c0202010408) - - - [画布组件](/pages/extra/f2014a/) - - [Canvas](/pages/010c0202010501) - - [CanvasRenderingContext2D对象](/pages/010c0202010502) - - [OffscreenCanvasRenderingConxt2D对象](/pages/010c0202010503) - - [Lottie](/pages/010c0202010504) - - [Path2D对象](/pages/010c0202010505) - - [CanvasGradient对象](/pages/010c0202010506) - - [ImageBitmap对象](/pages/010c0202010507) - - [ImageData对象](/pages/010c0202010508) - -- [动画](/pages/extra/e7546b/) - - [属性动画](/pages/010c02020201) - - [显式动画](/pages/010c02020202) - - [转场动画](/pages/extra/242c24/) - - [页面间转场](/pages/010c0202020301) - - [组件内转场](/pages/010c0202020302) - - [共享元素转场](/pages/010c0202020303) - - - [路径动画](/pages/010c02020204) - - [矩阵变换](/pages/010c02020205) - - [插值计算](/pages/010c02020206) - -- [全局UI方法](/pages/extra/f4845e/) - - [警告弹窗](/pages/010c02020301) - - [自定义弹窗](/pages/010c02020302) - - [图片缓存](/pages/010c02020303) - - [媒体查询](/pages/010c02020304) - - [列表选择弹窗](/pages/extra/90b637/) - -- [附录](/pages/extra/8689ec/) - - [文档中涉及到的内置枚举值](/pages/010c02020401) - diff --git a/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-animation.md b/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-animation.md deleted file mode 100644 index 175b2428ad15e3be8ca310c48d8aedbfd5eb8d7f..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-animation.md +++ /dev/null @@ -1,28 +0,0 @@ ---- -title: ts-animation -permalink: /pages/extra/e7546b/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 动画 - -- **[属性动画](/pages/010c02020201)** - -- **[显式动画](/pages/010c02020202)** - -- **[转场动画](/pages/extra/242c24/)** - -- **[路径动画](/pages/010c02020204)** - -- **[矩阵变换](/pages/010c02020205)** - -- **[插值计算](/pages/010c02020206)** - - diff --git a/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-appendix.md b/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-appendix.md deleted file mode 100644 index ed2910c35e1e518cb5b9e20033e03fa0156cac6d..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-appendix.md +++ /dev/null @@ -1,18 +0,0 @@ ---- -title: ts-appendix -permalink: /pages/extra/8689ec/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 附录 - -- **[文档中涉及到的内置枚举值](/pages/010c02020401)** - - diff --git a/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-marquee.md b/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-marquee.md deleted file mode 100644 index 8ff3d8849f0506522a3d11560e76c19cd3c9b1fe..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-marquee.md +++ /dev/null @@ -1,183 +0,0 @@ ---- -title: ts-basic-components-marquee -permalink: /pages/extra/0ecb0c/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# Marquee - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -跑马灯组件,用于滚动展示一段单行文本。 - -## 权限列表 - -无 - -## 子组件 - -无 - -## 接口 - -Marquee\(value: \{ start: boolean, step?: number, loop?: number, fromStart?: boolean, src: string \}\) - -- 参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

start

-

boolean

-

-

-

-

控制是否进入播放状态。

-

step

-

number

-

-

6

-

滚动动画文本滚动步长。

-

loop

-

number

-

-

-1

-

设置重复滚动的次数,小于等于零时无限循环。

-

fromStart

-

boolean

-

-

true

-

设置文本从头开始滚动或反向滚动。

-

src

-

string

-

-

-

-

需要滚动的文本。

-
- - -## 事件 - - - - - - - - - - - - - - - -

名称

-

功能描述

-

onStart(callback: () => void)

-

开始滚动时触发回调。

-

onBounce(callback: () => void)

-

滚动到底时触发回调。

-

onFinish(callback: () => void)

-

滚动完成时触发回调。

-
- -## 示例 - -``` -@Entry -@Component -struct MarqueeExample { - @State start: boolean = false - @State fromStart: boolean = true - @State step: number = 50 - @State loop: number = 3 - @State src: string = "Running Marquee starts rolling" - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Marquee({ - start: this.start, - step: this.step, - loop: this.loop, - fromStart: this.fromStart, - src: this.src - }) - .fontColor(Color.White) - .fontSize(50) - .allowScale(false) - .fontWeight(FontWeight.Bold) - .backgroundColor(Color.Black) - .margin({bottom:40}) - .onStart(() => { - console.log('Marquee animation complete onStart') - }) - .onBounce(() => { - console.log('Marquee animation complete onBounce') - }) - .onFinish(() => { - console.log('Marquee animation complete onFinish') - }) - Button('start') - .onClick(() => { - this.start = true - }) - .width(200) - .height(60) - .margin({bottom:20}) - } - .width('100%') - .height('100%') - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/GIF-1.gif) - diff --git a/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-select.md b/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-select.md deleted file mode 100644 index b800f90d49b7a1e5c361c526e564d601bd59224f..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-select.md +++ /dev/null @@ -1,223 +0,0 @@ ---- -title: ts-basic-components-select -permalink: /pages/extra/987129/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# Select - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -提供下拉选择菜单,可以让用户在多个选项之间选择。 - -## 权限列表 - -无 - -## 子组件 - -无 - -## 接口 - -Select(options: Array<SelectOption>) - -- `SelectOption`参数 - - - - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

value

-

ResourceStr

-

-

-

-

下拉选项内容。

-

icon

-

ResourceStr

-

-

-

-

下拉选项图片。

-
- - -## 属性 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

selected

-

number

-

-

-

设置下拉菜单初始选择项的索引,第一项的索引为0。

-

value

-

string

-

-

-

设置下拉按钮本身的文本显示。

-

font

-

Font

-

-

-

设置下拉按钮本身的文本样式:

-

fontColor

-

ResourceColor

-

-

-

设置下拉按钮本身的文本颜色。

-

selectedOptionBgColor

-

ResourceColor

-

-

-

设置下拉菜单选中项的背景色。

-

selectedOptionFont

-

Font

-

-

-

设置下拉菜单选中项的文本样式:

-

selectedOptionFontColor

-

ResourceColor

-

-

-

设置下拉菜单选中项的文本颜色。

-

optionBgColor

-

ResourceColor

-

-

-

设置下拉菜单项的背景色。

-

optionFont

-

Font

-

-

-

设置下拉菜单项的文本样式:

-

optionFontColor

-

ResourceColor

-

-

-

设置下拉菜单项的文本颜色。

-
- - -## 事件 - - - - - - - - - -

名称

-

功能描述

-

onSelected(callback: (index: number, value?:string) => void)

-

下拉菜单选中某一项的回调。

-

index:选中项的索引。

-

value:选中项的值。

-
- -## 示例 - -``` - -@Entry -@Component -struct SliderExample { - build() { - Column() { - Select([{value:'aaa',icon: "/common/1.png"}, - {value:'bbb',icon: "/common/2.png"}, - {value:'ccc',icon: "/common/3.png"}, - {value:'ddd',icon: "/common/4.png"}]) - .selected(2) - .value('TTT') - .font({size: 30, weight:400, family: 'serif', style: FontStyle.Normal }) - .selectedOptionFont({size: 40, weight: 500, family: 'serif', style: FontStyle.Normal }) - .optionFont({size: 30, weight: 400, family: 'serif', style: FontStyle.Normal }) - .onSelected((index:number)=>{ - console.info("Select:" + index) - }) - } - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/select.png) \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-textclock.md b/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-textclock.md deleted file mode 100644 index 62884d0557f79773b4bc3f3362723ed1f4b94394..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-textclock.md +++ /dev/null @@ -1,149 +0,0 @@ ---- -title: ts-basic-components-textclock -permalink: /pages/extra/7cf836/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# TextClock - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -TextClock主要用于显示系统时间,支持不同时区的时间显示,时间显示最高精度到秒级。 - -## 权限列表 - -无 - -## 子组件 - -无 - -## 接口 - -TextClock(options?: {hourswest?: number}) - -- 参数 - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

hourwest

-

number

-

-

系统时间所在的时区

-

设置时区信息,时区范围为[-14, 12],其中负值表示东时区,比如东八区为-8,浮点数也会进行相应的换算(30分钟/0.5时区);理论上时区范围是[-12,+12],但是一些国家横跨国际日界线,因此用-13(UTC+13)和-14(UTC+14)来保证整个国家或者区域处在相同的时间。

-
- - -## 属性 - - - - - - - - - - - - - - - - - - -

名称

-

参数类型

-

默认值

-

描述

-

format

-

string

-

'hhmmss'

-

设置显示时间格式,如“yyyy/mm/dd”、“yyyy-mm-dd”等。支持的时间格式化字符串:yyyy(年份),mm(英文月份简写),mmm(英文月份简写),mmmm(英文月份全称),dd(英文星期简写),ddd(英文星期简写),dddd(英文星期全称),HH(24小时制),hh(12小时制),MM/mm(分钟),SS/ss(秒)。

-

status

-

boolean

-

-

-

设置文本时钟的启动和停止。

    -
  • true表示文本时钟是启动状态。
  • false表示文本时钟是停止状态。
  • -

-
- - - -## 事件 - -支持以下通用事件:onClick,onTouch,onKeyEvent,onDeleteEvent,onAppear,onDisAppear - - - - - - - - - -

名称

-

功能描述

-

onDateChange(event: (value: number) => void)

-

提供时间变化回调,回调参数为Unix Time Stamp,即自1970年1月1日(UTC)起经过的毫秒数,该事件最小回调间隔为秒。

-
- - -## 示例 - -``` -@Entry -@Component -struct TextClockExmaple { - format: string = 'hhmmss' - @State accumulateTime: number = 0 - hourswest: number = -8 - @State isStart: boolean = true - - build() { - Column() { - Text('current milliseconds is' + this.accumulateTime) - TextClock({hourswest:this.hourswest}) - .format(this.format) - .onDateChange((value: number) => { - this.accumulateTime = value - }) - .status(this.isStart) - .fontSize(50) - Button("start/stop clock") - .onClick(()=>{ - this.isStart = !this.isStart - }) - } - .align(Alignment.Center) - } -} -``` - -![](/images/application-dev/reference/arkui-ts/figures/textclock.png) - diff --git a/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-web.md b/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-web.md deleted file mode 100644 index 8563c66d77841aa143b7df806377b8aee61565d2..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-web.md +++ /dev/null @@ -1,142 +0,0 @@ ---- -title: ts-basic-components-web -permalink: /pages/extra/816d35/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# Web - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->该组件从 API Version 8 开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -提供具有网页显示能力的 Web 组件。 - -## 权限列表 - -ohos.permission.INTERNET - -ohos.permission.READ_USER_STORAGE - -## 子组件 - -无 - -## 接口 - -- Web\(options: {src: string, controller?: WebController}\) - - 表1 options 参数说明 - - | 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | - | ---------- | ---------------------------------------- | ---- | ---- | ------- | - | src | string | 是 | - | 网页资源地址。 | - | controller | WebController | 否 | - | 控制器。 | - - -> ![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** -> -> - 一个页面只支持一个 Web 组件,全屏显示,页面中的其他组件会被 Web 组件遮挡; -> - 不支持转场动画; -> - 只支持加载 rawfile 目录下的 html 文件,不支持远程资源。 - -## 属性 - -| 名称 | 参数类型 | 默认值 | 描述 | -| ---------------- | ------- | ----- | ---------------------------------------- | -| javaScriptAccess | boolean | false | 是否允许执行 JavaScript 脚本,当设置为 false 时,不允许执行。 | -| fileAccess | boolean | false | 启用或禁用 Web 中可通过 file 方式访问应用中的本地文件,当设置为 false 时,禁用。 | - -> ![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** -> -> 不支持通用属性。 - -## 事件 - -不支持通用事件。 - -| 名称 | 功能描述 | -| ---------------------------------------- | ---------------------------------------- | -| onPageEnd(callback: (event?: { url: string }) => void) |

网页加载结束时触发该回调。
url:Web 引擎返回的 URL。

| - -## WebController - -Web 组件的控制器。 - -### 创建对象 - -``` -webController: WebController = new WebController() -``` - -### runJavaScript - -runJavaScript(script: string): void - -执行 JavaScript 脚本。 - -- 参数 - - | 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | - | ------ | ------ | ---- | ---- | -------------- | - | script | string | 是 | - | JavaScript 脚本。 | - -### loadUrl - -loadUrl(url: string): void - -加载 URL。 - -- 参数 - - | 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | - | ---- | ------ | ---- | ---- | ---------- | - | url | string | 是 | - | 需要加载的 URL。 | - - -## 示例 - -``` -// webComponent.ets -@Entry -@Component -struct WebComponent { - @State javaScriptAccess: boolean = true; - @State fileAccess: boolean = true; - controller: WebController = new WebController(); - build() { - Column() { - Web(src: $rawfile('index.html'), controller: this.controller) - .javaScriptAccess(javaScriptAccess) - .fileAccess(fileAccess) - .onPageEnd(e => { - // test() 在 index.html 中已定义 - this.controller.runJavaScript('test()'); - console.log("url: ", e.url); - }) - } - } -} - -// index.html - - - - - Hello world! - - - -``` - -![](/images/application-dev/reference/arkui-ts/figures/Web.png) \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-basic-components.md b/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-basic-components.md deleted file mode 100644 index 72eb49dd97dc6228c139e582e615f2f8eec3db4a..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-basic-components.md +++ /dev/null @@ -1,50 +0,0 @@ ---- -title: ts-basic-components -permalink: /pages/extra/8c88be/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 基础组件 - -- **[Blank](/pages/010c0202010201)** - -- **[Button](/pages/010c0202010202)** - -- **[DataPanel](/pages/010c0202010203)** - -- **[Divider](/pages/010c0202010204)** - -- **[Gauge](/pages/010c0202010205)** - -- **[Image](/pages/010c0202010206)** - -- **[ImageAnimator](/pages/010c0202010207)** - -- **[Marquee](/pages/extra/0ecb0c/)** - -- **[Progress](/pages/010c0202010208)** - -- **[QRCode](/pages/010c0202010209)** - -- **[Rating](/pages/010c020201020a)** - -- **[Span](/pages/010c020201020b)** - -- **[Slider](/pages/010c020201020c)** - -- **[Text](/pages/010c020201020d)** - -- **[TextArea](/pages/010c020201020e)** - -- **[TextInput](/pages/010c020201020f)** - -- **[Toggle](/pages/010c0202010210)** - - diff --git a/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures.md b/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures.md deleted file mode 100644 index 64aace27a4e25dfd00862a19bdc73c05e1586200..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures.md +++ /dev/null @@ -1,28 +0,0 @@ ---- -title: ts-basic-gestures -permalink: /pages/extra/51a545/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 基础手势 - -- **[TapGesture](/pages/010c02020101030201)** - -- **[LongPressGesture](/pages/010c02020101030202)** - -- **[PanGesture](/pages/010c02020101030203)** - -- **[PinchGesture](/pages/010c02020101030204)** - -- **[RotationGesture](/pages/010c02020101030205)** - -- **[SwipeGesture](/pages/010c02020101030206)** - - diff --git a/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-components-canvas.md b/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-components-canvas.md deleted file mode 100644 index e1ab1fdbbfe81e670b60c9bbebb37518c94f56ad..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-components-canvas.md +++ /dev/null @@ -1,32 +0,0 @@ ---- -title: ts-components-canvas -permalink: /pages/extra/f2014a/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 画布组件 - -- **[Canvas](/pages/010c0202010501)** - -- **[CanvasRenderingContext2D对象](/pages/010c0202010502)** - -- **[OffscreenCanvasRenderingConxt2D对象](/pages/010c0202010503)** - -- **[Lottie](/pages/010c0202010504)** - -- **[Path2D对象](/pages/010c0202010505)** - -- **[CanvasGradient对象](/pages/010c0202010506)** - -- **[ImageBitmap对象](/pages/010c0202010507)** - -- **[ImageData对象](/pages/010c0202010508)** - - diff --git a/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-components-container.md b/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-components-container.md deleted file mode 100644 index 17dcb303509f503a53d5e0dbc4f63ca293ef6b63..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-components-container.md +++ /dev/null @@ -1,64 +0,0 @@ ---- -title: ts-components-container -permalink: /pages/extra/4dbed9/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 容器组件 - -- **[AlphabetIndexer](/pages/010c0202010301)** - -- **[Badge](/pages/010c0202010302)** - -- **[Column](/pages/010c0202010303)** - -- **[ColumnSplit](/pages/010c0202010304)** - -- **[Counter](/pages/010c0202010305)** - -- **[Flex](/pages/010c0202010306)** - -- **[GridContainer](/pages/010c0202010307)** - -- **[Grid](/pages/010c0202010308)** - -- **[GridItem](/pages/010c0202010309)** - -- **[List](/pages/010c020201030a)** - -- **[ListItem](/pages/010c020201030b)** - -- **[Navigator](/pages/010c020201030c)** - -- **[Navigation](/pages/010c020201030d)** - -- **[Panel](/pages/010c020201030e)** - -- **[Row](/pages/010c020201030f)** - -- **[RowSplit](/pages/010c0202010310)** - -- **[Scroll](/pages/010c0202010311)** - -- **[ScrollBar](/pages/010c0202010312)** - -- **[Stack](/pages/010c0202010313)** - -- **[Swiper](/pages/010c0202010314)** - -- **[Tabs](/pages/010c0202010315)** - -- **[TabContent](/pages/010c0202010316)** - -- **[Stepper](/pages/010c0202010317)** - -- **[StepperItem](/pages/010c0202010318)** - - diff --git a/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-components.md b/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-components.md deleted file mode 100644 index 2e628f9e585bf17626020d8ce0ea235c882820a3..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-components.md +++ /dev/null @@ -1,26 +0,0 @@ ---- -title: ts-components -permalink: /pages/extra/710f05/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 组件 - -- **[通用](/pages/extra/f7c41d/)** - -- **[基础组件](/pages/extra/8c88be/)** - -- **[容器组件](/pages/extra/4dbed9/)** - -- **[绘制组件](/pages/extra/0ed70d/)** - -- **[画布组件](/pages/extra/f2014a/)** - - diff --git a/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components.md b/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components.md deleted file mode 100644 index 0bd8804ee8461fc122fa0c2cab8c8ee16f167470..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components.md +++ /dev/null @@ -1,32 +0,0 @@ ---- -title: ts-drawing-components -permalink: /pages/extra/0ed70d/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 绘制组件 - -- **[Circle](/pages/010c0202010401)** - -- **[Ellipse](/pages/010c0202010402)** - -- **[Line](/pages/010c0202010403)** - -- **[Polyline](/pages/010c0202010404)** - -- **[Polygon](/pages/010c0202010405)** - -- **[Path](/pages/010c0202010406)** - -- **[Rect](/pages/010c0202010407)** - -- **[Shape](/pages/010c0202010408)** - - diff --git a/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-gesture-processing.md b/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-gesture-processing.md deleted file mode 100644 index 4b02c7a4c7efb304941efcf5b704c4be08800a36..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-gesture-processing.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: ts-gesture-processing -permalink: /pages/extra/74ae35/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 手势处理 - -- **[绑定手势方法](/pages/010c020201010301)** - -- **[基础手势](/pages/extra/51a545/)** - -- **[组合手势](/pages/010c020201010303)** - - diff --git a/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-global-ui-methods.md b/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-global-ui-methods.md deleted file mode 100644 index 9c8115a7d53c99f9a628699dc0e1a2036ec90dcd..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-global-ui-methods.md +++ /dev/null @@ -1,26 +0,0 @@ ---- -title: ts-global-ui-methods -permalink: /pages/extra/f4845e/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 全局UI方法 - -- **[警告弹窗](/pages/010c02020301)** - -- **[自定义弹窗](/pages/010c02020302)** - -- **[图片缓存](/pages/010c02020303)** - -- **[媒体查询](/pages/010c02020304)** - -- **[列表选择弹窗](/pages/extra/90b637/)** - - diff --git a/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-methods-custom-actionsheet.md b/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-methods-custom-actionsheet.md deleted file mode 100644 index fdff662f02bdbacec3f4f36363e94e0afccdf39f..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-methods-custom-actionsheet.md +++ /dev/null @@ -1,247 +0,0 @@ ---- -title: ts-methods-custom-actionsheet -permalink: /pages/extra/90b637/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 列表选择弹窗 - ->![](/images/application-dev/public_sys-resources/icon-note.gif) **说明:** ->从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -列表弹窗。 - -## 权限列表 - -无 - -## ActionSheet.show - -show\(options: \{ [paramObject1](#table816913216616)\}\) - -定义列表弹窗并弹出。 - -- paramObject1参数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

title

-

string

-

-

无标题

-

弹窗标题。

-

message

-

string

-

-

-

-

弹窗内容。

-

autoCancel

-

boolean

-

-

true

-

点击遮障层时,是否关闭弹窗。

-

confirm

-

{

-

value: string,

-

action: () => void

-

}

-

-

-

-

确认按钮的文本内容和点击回调。

-

value:按钮文本内容。

-

action: 按钮选中时的回调。

-

cancel

-

() => void

-

-

-

-

点击遮障层关闭dialog时的回调。

-

alignment

-

DialogAlignment

-

-

DialogAlignment.Default

-

弹窗在竖直方向上的对齐方式。

-

offset

-

{

-

dx: Length,

-

dy: Length

-

}

-

-

{

-

dx: 0,

-

dy: 0

-

}

-

弹窗相对alignment所在位置的偏移量。

-

sheets

-

Array<SheetInfo>

-

-

-

-

设置选项内容,每个选择项支持设置图片、文本和选中的回调。

-
- -- SheetInfo接口说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数名

-

参数类型

-

必填

-

默认值

-

参数描述

-

title

-

string

-

-

-

-

sheet文本。

-

icon

-

string

-

-

-

sheet图标。

-

action

-

()=>void

-

-

-

-

sheet选中的回调。

-
- - -## 示例 - -``` -@Entry -@Component -struct ActionSheetExapmle { - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Button('Click to Show ActionSheet') - .onClick(() => { - ActionSheet.show({ - title: 'ActionSheet title', - message: 'message', - confirm: { - value: 'Confirm button', - action: () => { - console.log('Get Alert Dialog handled') - } - }, - sheets: [ - { - title: 'apples', - action: () => { - console.error('apples') - } - }, - { - title: 'bananas', - action: () => { - console.error('bananas') - } - }, - { - title: 'pears', - action: () => { - console.error('pears') - } - } - ] - }) - }) - }.width('100%') - .height('100%') - } -} -``` - - - diff --git a/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-transition-animation.md b/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-transition-animation.md deleted file mode 100644 index a982dc58097352a255552a99129383605d0bf5ec..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-transition-animation.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: ts-transition-animation -permalink: /pages/extra/242c24/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 转场动画 - -- **[页面间转场](/pages/010c0202020301)** - -- **[组件内转场](/pages/010c0202020302)** - -- **[共享元素转场](/pages/010c0202020303)** - - diff --git a/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes.md b/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes.md deleted file mode 100644 index 58f386494c18c2e382e76e29fe9a3b6d7b3e9744..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes.md +++ /dev/null @@ -1,58 +0,0 @@ ---- -title: ts-universal-attributes -permalink: /pages/extra/b89109/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 通用属性 - -- **[尺寸设置](/pages/010c020201010201)** - -- **[位置设置](/pages/010c020201010202)** - -- **[布局约束](/pages/010c020201010203)** - -- **[Flex布局](/pages/010c020201010204)** - -- **[边框设置](/pages/010c020201010205)** - -- **[背景设置](/pages/010c020201010206)** - -- **[透明度设置](/pages/010c020201010207)** - -- **[显隐控制](/pages/010c020201010208)** - -- **[禁用控制](/pages/010c020201010209)** - -- **[浮层](/pages/010c02020101020a)** - -- **[Z序控制](/pages/010c02020101020b)** - -- **[图形变换](/pages/010c02020101020c)** - -- **[图像效果](/pages/010c02020101020d)** - -- **[形状裁剪](/pages/010c02020101020e)** - -- **[文本样式设置](/pages/010c02020101020f)** - -- **[栅格设置](/pages/010c020201010210)** - -- **[颜色渐变](/pages/010c020201010211)** - -- **[Popup控制](/pages/010c020201010212)** - -- **[Menu控制](/pages/010c020201010213)** - -- **[点击控制](/pages/010c020201010214)** - -- **[触摸热区设置](/pages/010c020201010215)** - - diff --git a/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-universal-components.md b/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-universal-components.md deleted file mode 100644 index 2d36013499fe29aeecda3ee1b8ffdf3c478c1004..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-universal-components.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: ts-universal-components -permalink: /pages/extra/f7c41d/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 通用 - -- **[通用事件](/pages/extra/1ab473/)** - -- **[通用属性](/pages/extra/b89109/)** - -- **[手势处理](/pages/extra/74ae35/)** - - diff --git a/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-universal-events.md b/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-universal-events.md deleted file mode 100644 index 4a784bc7c1684a8f69e942988f76b6193ff1a1c3..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/reference/arkui-ts/ts-universal-events.md +++ /dev/null @@ -1,26 +0,0 @@ ---- -title: ts-universal-events -permalink: /pages/extra/1ab473/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 通用事件 - -- **[点击事件](/pages/010c020201010101)** - -- **[触摸事件](/pages/010c020201010102)** - -- **[挂载卸载事件](/pages/010c020201010103)** - -- **[按键事件](/pages/010c020201010104)** - -- **[组件区域变化事件](/pages/010c020201010105)** - - diff --git a/website/docs/_posts/zh-cn/application-dev/security/Readme-CN.md b/website/docs/_posts/zh-cn/application-dev/security/Readme-CN.md deleted file mode 100644 index a190472721f795fe03f2a9274728e6b1dc2d178a..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/security/Readme-CN.md +++ /dev/null @@ -1,18 +0,0 @@ ---- -title: Readme-CN -permalink: /pages/extra/85ba77/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 安全 - -- 用户认证 - - [用户认证开发概述](/pages/01080401) - - [用户认证开发指导](/pages/01080402) \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/ui/Readme-CN.md b/website/docs/_posts/zh-cn/application-dev/ui/Readme-CN.md deleted file mode 100644 index 5342a708c832b06ddb4a3949c875f8aacf8cdec6..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/ui/Readme-CN.md +++ /dev/null @@ -1,125 +0,0 @@ ---- -title: Readme-CN -permalink: /pages/extra/91bbde/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# UI - -- 方舟开发框架(ArkUI) - - [方舟开发框架概述](/pages/01080201) - - 基于JS扩展的类Web开发范式 - - [概述](/pages/0108020201) - - 框架说明 - - [文件组织](/pages/010802020201) - - [js标签配置](/pages/010802020202) - - [app.js](/pages/010802020203) - - 语法 - - [HML语法参考](/pages/01080202020401) - - [CSS语法参考](/pages/01080202020402) - - [JS语法参考](/pages/01080202020403) - - [生命周期](/pages/010802020205) - - [资源限定与访问](/pages/010802020206) - - [多语言支持](/pages/010802020207) - - 构建用户界面 - - [组件介绍](/pages/010802020301) - - 构建布局 - - [布局说明](/pages/01080202030201) - - [添加标题行和文本区域](/pages/01080202030202) - - [添加图片区域](/pages/01080202030203) - - [添加留言区域](/pages/01080202030204) - - [添加容器](/pages/01080202030205) - - [添加交互](/pages/010802020303) - - [动画](/pages/010802020304) - - [事件](/pages/010802020305) - - [页面路由](/pages/010802020306) - - 常见组件开发指导 - - [Text](/pages/010802020401) - - [Input](/pages/010802020402) - - [Button](/pages/010802020403) - - [List](/pages/010802020404) - - [Picker](/pages/010802020405) - - [Dialog](/pages/010802020406) - - [Form](/pages/010802020407) - - [Stepper](/pages/010802020408) - - [Tabs](/pages/010802020409) - - [Image](/pages/01080202040a) - - 动效开发指导 - - CSS动画 - - [属性样式动画](/pages/01080202050101) - - [transform样式动画](/pages/01080202050102) - - [background-position样式动画](/pages/01080202050103) - - JS动画 - - [组件动画](/pages/01080202050201) - - 插值器动画 - - [动画动效](/pages/0108020205020201) - - [动画帧](/pages/0108020205020202) - - [自定义组件](/pages/0108020206) - - 基于TS扩展的声明式开发范式 - - [概述](/pages/0108020301) - - 框架说明 - - 文件组织 - - [目录结构](/pages/01080203020101) - - [应用代码文件访问规则](/pages/01080203020102) - - [js标签配置](/pages/010802030202) - - 资源访问 - - [媒体资源类型说明](/pages/01080203020301) - - [像素单位](/pages/010802030204) - - [类型定义](/pages/010802030205) - - 声明式语法 - - [描述规范使用说明](/pages/010802030301) - - 通用UI描述规范 - - [基本概念](/pages/01080203030201) - - 声明式UI描述规范 - - [无构造参数配置](/pages/0108020303020201) - - [必选参数构造配置](/pages/0108020303020202) - - [属性配置](/pages/0108020303020203) - - [事件配置](/pages/0108020303020204) - - [子组件配置](/pages/0108020303020205) - - 组件化 - - [@Component](/pages/0108020303020301) - - [@Entry](/pages/0108020303020302) - - [@Preview](/pages/0108020303020303) - - [@Builder](/pages/0108020303020304) - - [@Extend](/pages/0108020303020305) - - [@CustomDialog](/pages/0108020303020306) - - UI状态管理 - - [基本概念](/pages/01080203030301) - - 管理组件拥有的状态 - - [@State](/pages/0108020303030201) - - [@Prop](/pages/0108020303030202) - - [@Link](/pages/0108020303030203) - - 管理应用程序的状态 - - [应用程序的数据存储](/pages/010802030303030101) - - [持久化数据管理](/pages/010802030303030102) - - [环境变量](/pages/010802030303030103) - - 其他类目的状态管理 - - [Observed和ObjectLink数据管理](/pages/0108020303030401) - - [@Consume和@Provide数据管理](/pages/0108020303030402) - - [@Watch](/pages/0108020303030403) - - 渲染控制语法 - - [条件渲染](/pages/01080203030401) - - [循环渲染](/pages/01080203030402) - - [数据懒加载](/pages/01080203030403) - - 深入理解组件化 - - [build函数](/pages/01080203030501) - - [自定义组件初始化](/pages/01080203030502) - - [自定义组件生命周期回调函数](/pages/01080203030503) - - [组件创建和重新初始化示例](/pages/01080203030504) - - [语法糖](/pages/extra/451991/) - - 体验声明式UI - - [创建声明式UI工程](/pages/010802030401) - - [初识Component](/pages/010802030402) - - [创建简单视图](/pages/010802030403) - - 页面布局与连接 - - [构建食物数据模型](/pages/010802030501) - - [构建食物列表List布局](/pages/010802030502) - - [构建食物分类Grid布局](/pages/010802030503) - - [页面跳转与数据传递](/pages/010802030504) diff --git a/website/docs/_posts/zh-cn/application-dev/ui/js-framework-syntax.md b/website/docs/_posts/zh-cn/application-dev/ui/js-framework-syntax.md deleted file mode 100644 index 4546e4cc9aa1122a9882b0b3678d619973f2de2d..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/ui/js-framework-syntax.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: js-framework-syntax -permalink: /pages/extra/54258f/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 语法 - - - -- **[HML语法参考](/pages/01080202020401)** - -- **[CSS语法参考](/pages/01080202020402)** - -- **[JS语法参考](/pages/01080202020403)** \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/ui/js-framework.md b/website/docs/_posts/zh-cn/application-dev/ui/js-framework.md deleted file mode 100644 index 2aaae4de6d03eca750a4e1bbdc7d765a9ba03f84..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/ui/js-framework.md +++ /dev/null @@ -1,30 +0,0 @@ ---- -title: js-framework -permalink: /pages/extra/8e5cfc/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 框架说明 - - - -- **[文件组织](/pages/010802020201)** - -- **[js标签配置](/pages/010802020202)** - -- **[app.js](/pages/010802020203)** - -- **[语法](/pages/extra/54258f/)** - -- **[生命周期](/pages/010802020205)** - -- **[资源限定与访问](/pages/010802020206)** - -- **[多语言支持](/pages/010802020207)** \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/ui/ts-a-deep-dive-into-component.md b/website/docs/_posts/zh-cn/application-dev/ui/ts-a-deep-dive-into-component.md deleted file mode 100644 index 92ce09e0192f25176fe78b9f3601c0f5ebea42bf..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/ui/ts-a-deep-dive-into-component.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -title: ts-a-deep-dive-into-component -permalink: /pages/extra/ba7ead/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 深入理解组件化 - -- **[build函数](/pages/01080203030501)** - -- **[自定义组件成员变量初始化](/pages/01080203030502)** - -- **[自定义组件生命周期回调函数](/pages/01080203030503)** - -- **[组件创建和重新初始化示例](/pages/01080203030504)** - - diff --git a/website/docs/_posts/zh-cn/application-dev/ui/ts-component-based.md b/website/docs/_posts/zh-cn/application-dev/ui/ts-component-based.md deleted file mode 100644 index b0936adc67a4e7eeb36ff8407236c8fc954e0d90..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/ui/ts-component-based.md +++ /dev/null @@ -1,28 +0,0 @@ ---- -title: ts-component-based -permalink: /pages/extra/b1da24/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 组件化 - -- **[@Component](/pages/0108020303020301)** - -- **[@Entry](/pages/0108020303020302)** - -- **[@Preview](/pages/0108020303020303)** - -- **[@Builder](/pages/0108020303020304)** - -- **[@Extend](/pages/0108020303020305)** - -- **[@CustomDialog](/pages/0108020303020306)** - - diff --git a/website/docs/_posts/zh-cn/application-dev/ui/ts-declarative-syntax.md b/website/docs/_posts/zh-cn/application-dev/ui/ts-declarative-syntax.md deleted file mode 100644 index 74088813dee5325f47c7dfb83484329c0dffe4e8..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/ui/ts-declarative-syntax.md +++ /dev/null @@ -1,28 +0,0 @@ ---- -title: ts-declarative-syntax -permalink: /pages/extra/19a335/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 声明式语法 - - - -- **[描述规范使用说明](/pages/010802030301)** - -- **[通用UI描述规范](/pages/extra/52abc2/)** - -- **[UI状态管理](/pages/extra/09017f/)** - -- **[渲染控制语法](/pages/extra/cc10c8/)** - -- **[深入理解组件化](/pages/extra/ba7ead/)** - -- **[语法糖](/pages/extra/451991/)** \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/ui/ts-declarative-ui-description-specifications.md b/website/docs/_posts/zh-cn/application-dev/ui/ts-declarative-ui-description-specifications.md deleted file mode 100644 index 1e1e0cff55d6a7c80d97fe5d5b1ec0424bef3bd4..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/ui/ts-declarative-ui-description-specifications.md +++ /dev/null @@ -1,26 +0,0 @@ ---- -title: ts-declarative-ui-description-specifications -permalink: /pages/extra/62d804/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 声明式UI描述规范 - -- **[无构造参数配置](/pages/0108020303020201)** - -- **[必选参数构造配置](/pages/0108020303020202)** - -- **[属性配置](/pages/0108020303020203)** - -- **[事件配置](/pages/0108020303020204)** - -- **[子组件配置](/pages/0108020303020205)** - - diff --git a/website/docs/_posts/zh-cn/application-dev/ui/ts-framework-file.md b/website/docs/_posts/zh-cn/application-dev/ui/ts-framework-file.md deleted file mode 100644 index 37ab807173f917eed92acfbbce1bea9c0c86a67f..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/ui/ts-framework-file.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: ts-framework-file -permalink: /pages/extra/dea262/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 文件组织 - - - -- **[目录结构](/pages/01080203020101)** - -- **[应用代码文件访问规则](/pages/01080203020102)** \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/ui/ts-framework.md b/website/docs/_posts/zh-cn/application-dev/ui/ts-framework.md deleted file mode 100644 index 41f61adf1055caf881272348df49b8f6b30de780..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/ui/ts-framework.md +++ /dev/null @@ -1,26 +0,0 @@ ---- -title: ts-framework -permalink: /pages/extra/638001/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 框架说明 - - - -- **[文件组织](/pages/extra/dea262/)** - -- **[js标签配置](/pages/010802030202)** - -- **[资源访问](/pages/extra/18f769/)** - -- **[像素单位](/pages/010802030204)** - -- **[类型定义](/pages/010802030205)** \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/ui/ts-general-ui-description-specifications.md b/website/docs/_posts/zh-cn/application-dev/ui/ts-general-ui-description-specifications.md deleted file mode 100644 index 23be9dd12d2e8e796db226f523565533bfec9ca6..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/ui/ts-general-ui-description-specifications.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: ts-general-ui-description-specifications -permalink: /pages/extra/52abc2/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 通用UI描述规范 - -- **[基本概念](/pages/01080203030201)** - -- **[声明式UI描述规范](/pages/extra/62d804/)** - -- **[组件化](/pages/extra/b1da24/)** - - diff --git a/website/docs/_posts/zh-cn/application-dev/ui/ts-managing-application-states-apis.md b/website/docs/_posts/zh-cn/application-dev/ui/ts-managing-application-states-apis.md deleted file mode 100644 index 58672e5548cc5ad93499439e5f97bb28c3463db3..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/ui/ts-managing-application-states-apis.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: ts-managing-application-states-apis -permalink: /pages/extra/9e57dd/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 接口 - - - -- **[应用程序的数据存储](/pages/010802030303030101)** - -- **[持久化数据管理](/pages/010802030303030102)** - -- **[环境变量](/pages/010802030303030103)** \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/ui/ts-managing-application-states.md b/website/docs/_posts/zh-cn/application-dev/ui/ts-managing-application-states.md deleted file mode 100644 index bc2203327aa682c9f12896f36de68d9906bcd0a6..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/ui/ts-managing-application-states.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: ts-managing-application-states -permalink: /pages/extra/e94097/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 管理应用程序的状态 - -- **[应用程序的数据存储](/pages/010802030303030101)** - -- **[持久化数据管理](/pages/010802030303030102)** - -- **[环境变量](/pages/010802030303030103)** - - diff --git a/website/docs/_posts/zh-cn/application-dev/ui/ts-managing-component-states.md b/website/docs/_posts/zh-cn/application-dev/ui/ts-managing-component-states.md deleted file mode 100644 index adfcbe8ff6b79f0e7b79f017fe32389dcec17f73..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/ui/ts-managing-component-states.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: ts-managing-component-states -permalink: /pages/extra/b7881d/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 管理组件拥有的状态 - -- **[@State](/pages/0108020303030201)** - -- **[@Prop](/pages/0108020303030202)** - -- **[@Link](/pages/0108020303030203)** - - diff --git a/website/docs/_posts/zh-cn/application-dev/ui/ts-managing-other-states.md b/website/docs/_posts/zh-cn/application-dev/ui/ts-managing-other-states.md deleted file mode 100644 index 7d0d0405bf8ae7441bfd7f0b64da1a7bb535db84..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/ui/ts-managing-other-states.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: ts-managing-other-states -permalink: /pages/extra/9470b7/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 其他类目的状态管理 - -- **[Observed和ObjectLink数据管理](/pages/0108020303030401)** - -- **[@Consume和@Provide数据管理](/pages/0108020303030402)** - -- **[@Watch](/pages/0108020303030403)** - - diff --git a/website/docs/_posts/zh-cn/application-dev/ui/ts-rending-control-syntax.md b/website/docs/_posts/zh-cn/application-dev/ui/ts-rending-control-syntax.md deleted file mode 100644 index 979e49ee7af90351dd73a6d65a04f31331b735a8..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/ui/ts-rending-control-syntax.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: ts-rending-control-syntax -permalink: /pages/extra/cc10c8/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 渲染控制语法 - -- **[条件渲染](/pages/01080203030401)** - -- **[循环渲染](/pages/01080203030402)** - -- **[数据懒加载](/pages/01080203030403)** - - diff --git a/website/docs/_posts/zh-cn/application-dev/ui/ts-resource-access.md b/website/docs/_posts/zh-cn/application-dev/ui/ts-resource-access.md deleted file mode 100644 index a5ad55d66f9f87f4afcfdefd2359335212cd422d..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/ui/ts-resource-access.md +++ /dev/null @@ -1,18 +0,0 @@ ---- -title: ts-resource-access -permalink: /pages/extra/18f769/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 资源访问 - - - -- **[媒体资源类型说明](/pages/01080203020301)** \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/ui/ts-syntactic-sugar.md b/website/docs/_posts/zh-cn/application-dev/ui/ts-syntactic-sugar.md deleted file mode 100644 index 89818784f3383dd854d6b02b1813fede8575180c..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/ui/ts-syntactic-sugar.md +++ /dev/null @@ -1,230 +0,0 @@ ---- -title: ts-syntactic-sugar -permalink: /pages/extra/451991/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 语法糖 - -## 装饰器 - -装饰器**@Decorator**不仅可以装饰类或结构体,还可以装饰类的属性。多个装饰器可以叠加到目标元素,定义在同一行上或者在多行上,推荐定义在多行上。 - -如下示例为**@Component**和**@State**的使用,被**@Component**装饰的元素具备了组件化的含义,使用**@State**装饰的变量具备了状态数据的含义。 - -``` -@Component -struct MyComponent { - @State count: number = 0 -} -``` - -装饰器定义在同一行上的描述如下: - -``` -@Entry @Component struct MyComponent { -} -``` - -但更推荐定义在多行上: - -``` -@Entry -@Component -struct MyComponent { -} -``` - -### 支持的装饰器列表 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

装饰器

-

装饰内容

-

说明

-

@Component

-

struct

-

结构体在装饰后具有基于组件的能力,需要实现build方法来更新UI。

-

@Entry

-

struct

-

组件被装饰后作为页面的入口,页面加载时将被渲染显示。

-

@Preview

-

struct

-

用@Preview装饰的自定义组件可以在DevEco Studio的预览器上进行预览,加载页面时,将创建并呈现@Preview装饰的自定义组件。

-

@Builder

-

方法

-

@Builder装饰的方法用于定义组件的声明式UI描述,在一个自定义组件内快速生成多个布局内容。

-

@Extend

-

方法

-

@Extend装饰器将新的属性函数添加到内置组件上,通过@Extend装饰器可以快速定义并复用组件的自定义样式。

-

@CustomDialog

-

struct

-

@CustomDialog装饰器用于装饰自定义弹窗。

-

@State

-

基本数据类型,类,数组

-

修饰的状态数据被修改时会触发组件的build方法进行UI界面更新。

-

@Prop

-

基本数据类型

-

修改后的状态数据用于在父组件和子组件之间建立单向数据依赖关系。修改父组件关联数据时,更新当前组件的UI。

-

@Link

-

基本数据类型,类,数组

-

父子组件之间的双向数据绑定,父组件的内部状态数据作为数据源,任何一方所做的修改都会反映给另一方。

-

@Observed

-

-

@Observed应用于类,表示该类中的数据变更被UI页面管理。

-

@ObjectLink

-

被@Observed所装饰类的对象

-

@ObjectLink应用于被@Observed所装饰类的对象。

-

@Consume

-

基本数据类型,类,数组

-

Provide作为数据的提供方,可以更新其子孙节点的数据,并触发页面渲染。

-

@Provide

-

基本数据类型,类,数组

-

Consume在感知到Provide数据的更新后,会触发当前view的重新渲染。

-

@Watch

-

被@State, @Prop, @Link, @ObjectLink, @Provide, @Consume, @StorageProp, @StorageLink中任意一个装饰的变量

-

@Watch用于监听状态变量的变化,应用可以注册回调方法。

-
- -## 链式调用 - -允许开发者以“.”链式调用的方式配置UI结构及其属性、事件等。 - -``` -Column() { - Image('1.jpg') - .alt('error.jpg') - .width(100) - .height(100) -}.padding(10) -``` - -## struct对象 - -组件可以基于**struct**实现,组件不能有继承关系,**struct**可以比**class**更加快速的创建和销毁。 - -``` -@Component -struct MyComponent { - @State data: string = '' - - build() { - } -} -``` - -## 在实例化过程中省略"new" - -对于**struct**的实例化,可以省略**new**。 - -``` -// 定义 -@Component -struct MyComponent { - build() { - } -} - -// 使用 -Column() { - MyComponent() -} - -// 等价于 -new Column() { - new MyComponent() -} -``` - -## 生成器函数内使用TS语言的限制 - -TS语言的使用在生成器函数中存在一定的限制: - -- 表达式仅允许在字符串\($\{expression\}\)、if条件、ForEach的参数和组件的参数中使用; -- 这些表达式中的任何一个都不能导致任何应用程序状态变量(@State、@Link、@Prop)的改变,否则会导致未定义和潜在不稳定的框架行为; -- 生成器函数内部不能有局部变量。 - -上述限制都不适用于事件处理函数(例如**onClick**)的匿名函数实现,它们也不适用于UI组件描述外的其余部分。 - -非法示例: - -``` -build() { - let a: number = 1 // invalid: variable declaration not allowed - Column() { - Text('Hello ${this.myName.toUpperCase()}') // ok. - ForEach(this.arr.reverse(), ..., ...) // invalid: Array.reverse modifies the @State array varible in place - } - buildSpecial() // invalid: no function calls - Text(this.calcTextValue()) // this function call is ok. -} -``` - diff --git a/website/docs/_posts/zh-cn/application-dev/ui/ts-ui-state-management.md b/website/docs/_posts/zh-cn/application-dev/ui/ts-ui-state-management.md deleted file mode 100644 index db09c1c5bfb8d8b972ddc56d4372fb7294f0d7ae..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/ui/ts-ui-state-management.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -title: ts-ui-state-management -permalink: /pages/extra/09017f/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# UI状态管理 - -- **[基本概念](/pages/01080203030301)** - -- **[管理组件拥有的状态](/pages/extra/b7881d/)** - -- **[管理应用程序的状态](/pages/extra/e94097/)** - -- **[其他类目的状态管理](/pages/extra/9470b7/)** - - diff --git a/website/docs/_posts/zh-cn/application-dev/ui/ui-arkui-js.md b/website/docs/_posts/zh-cn/application-dev/ui/ui-arkui-js.md deleted file mode 100644 index 078574740ca49e808132f86452167dc1c4e17b19..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/ui/ui-arkui-js.md +++ /dev/null @@ -1,28 +0,0 @@ ---- -title: ui-arkui-js -permalink: /pages/extra/cdf053/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 基于JS扩展的类Web开发范式 - - - -- **[概述](/pages/0108020201)** - -- **[框架说明](/pages/extra/8e5cfc/)** - -- **[构建用户界面](/pages/extra/7184fa/)** - -- **[常见组件开发指导](/pages/extra/073ddb/)** - -- **[动效开发指导](/pages/extra/bd6457/)** - -- **[自定义组件](/pages/0108020206)** \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/ui/ui-arkui-ts.md b/website/docs/_posts/zh-cn/application-dev/ui/ui-arkui-ts.md deleted file mode 100644 index 5d07134d3def32b499c7f31b63a4a140813ef587..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/ui/ui-arkui-ts.md +++ /dev/null @@ -1,26 +0,0 @@ ---- -title: ui-arkui-ts -permalink: /pages/extra/da8c59/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 基于TS扩展的声明式开发范式 - - - -- **[概述](/pages/0108020301)** - -- **[框架说明](/pages/extra/638001/)** - -- **[声明式语法](/pages/extra/19a335/)** - -- **[体验声明式UI](/pages/extra/110365/)** - -- **[页面布局与连接](/pages/extra/f9c0e8/)** \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/ui/ui-arkui.md b/website/docs/_posts/zh-cn/application-dev/ui/ui-arkui.md deleted file mode 100644 index d55c764e5859aab0f23f6e16c4b19cf4a0d5cf0c..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/ui/ui-arkui.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: ui-arkui -permalink: /pages/extra/fb9edc/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 方舟开发框架(ArkUI) - - - -- **[方舟开发框架概述](/pages/01080201)** - -- **[基于JS扩展的类Web开发范式](/pages/extra/cdf053/)** - -- **[基于TS扩展的声明式开发范式](/pages/extra/da8c59/)** \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/ui/ui-js-animate-css.md b/website/docs/_posts/zh-cn/application-dev/ui/ui-js-animate-css.md deleted file mode 100644 index 091ed9a2a4409d87449c485d82c084282203d5da..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/ui/ui-js-animate-css.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: ui-js-animate-css -permalink: /pages/extra/c2a5b4/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# CSS动画 - - - -- **[属性样式动画](/pages/01080202050101)** - -- **[transform样式动画](/pages/01080202050102)** - -- **[background-position样式动画](/pages/01080202050103)** \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/ui/ui-js-animate-interpolator.md b/website/docs/_posts/zh-cn/application-dev/ui/ui-js-animate-interpolator.md deleted file mode 100644 index 6f0ca8f756b4982381b871f69726b6b0c0576302..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/ui/ui-js-animate-interpolator.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: ui-js-animate-interpolator -permalink: /pages/extra/376c86/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 插值器动画 - - - -- **[动画动效](/pages/0108020205020201)** - -- **[动画帧](/pages/0108020205020202)** \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/ui/ui-js-animate-javascript.md b/website/docs/_posts/zh-cn/application-dev/ui/ui-js-animate-javascript.md deleted file mode 100644 index 69e1cdb833fb344202e330fb9919621569d0fa3d..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/ui/ui-js-animate-javascript.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: ui-js-animate-javascript -permalink: /pages/extra/31fe33/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# JS动画 - - - -- **[组件动画](/pages/01080202050201)** - -- **[插值器动画](/pages/extra/376c86/)** \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/ui/ui-js-animate.md b/website/docs/_posts/zh-cn/application-dev/ui/ui-js-animate.md deleted file mode 100644 index ba7674667f3ba852d2b8565ec1b55cdc43d8a332..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/ui/ui-js-animate.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: ui-js-animate -permalink: /pages/extra/bd6457/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 动效开发指导 - - - -- **[CSS动画](/pages/extra/c2a5b4/)** - -- **[JS动画](/pages/extra/31fe33/)** \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/ui/ui-js-building-ui-layout.md b/website/docs/_posts/zh-cn/application-dev/ui/ui-js-building-ui-layout.md deleted file mode 100644 index b39729a7f6704c359e377f80c4c0affebdb21750..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/ui/ui-js-building-ui-layout.md +++ /dev/null @@ -1,26 +0,0 @@ ---- -title: ui-js-building-ui-layout -permalink: /pages/extra/8c7f97/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 构建布局 - - - -- **[布局说明](/pages/01080202030201)** - -- **[添加标题行和文本区域](/pages/01080202030202)** - -- **[添加图片区域](/pages/01080202030203)** - -- **[添加留言区域](/pages/01080202030204)** - -- **[添加容器](/pages/01080202030205)** \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/ui/ui-js-building-ui.md b/website/docs/_posts/zh-cn/application-dev/ui/ui-js-building-ui.md deleted file mode 100644 index 46d7ee68af4d9835e1691686ed059c0b6701e341..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/ui/ui-js-building-ui.md +++ /dev/null @@ -1,28 +0,0 @@ ---- -title: ui-js-building-ui -permalink: /pages/extra/7184fa/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 构建用户界面 - - - -- **[组件介绍](/pages/010802020301)** - -- **[构建布局](/pages/extra/8c7f97/)** - -- **[添加交互](/pages/010802020303)** - -- **[动画](/pages/010802020304)** - -- **[事件](/pages/010802020305)** - -- **[页面路由](/pages/010802020306)** diff --git a/website/docs/_posts/zh-cn/application-dev/ui/ui-js-common-components.md b/website/docs/_posts/zh-cn/application-dev/ui/ui-js-common-components.md deleted file mode 100644 index f1cf77de7d1037433cd72a3655e1512ec598d184..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/ui/ui-js-common-components.md +++ /dev/null @@ -1,35 +0,0 @@ ---- -title: ui-js-common-components -permalink: /pages/extra/073ddb/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 常见组件开发指导 - - -- **[Text](/pages/010802020401)** - -- **[Input](/pages/010802020402)** - -- **[Button](/pages/010802020403)** - -- **[List](/pages/010802020404)** - -- **[Picker](/pages/010802020405)** - -- **[Dialog](/pages/010802020406)** - -- **[Form](/pages/010802020407)** - -- **[Stepper](/pages/010802020408)** - -- **[Tabs](/pages/010802020409)** - -- **[Image](/pages/01080202040a)** \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/ui/ui-ts-experiencing-declarative-ui.md b/website/docs/_posts/zh-cn/application-dev/ui/ui-ts-experiencing-declarative-ui.md deleted file mode 100644 index 447bd0b2d50202f1591276ba1a7cf9d868db8871..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/ui/ui-ts-experiencing-declarative-ui.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: ui-ts-experiencing-declarative-ui -permalink: /pages/extra/110365/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 体验声明式UI - - - -- **[创建声明式UI工程](/pages/010802030401)** - -- **[初识Component](/pages/010802030402)** - -- **[创建简单视图](/pages/010802030403)** \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/ui/ui-ts-page-layout-connections.md b/website/docs/_posts/zh-cn/application-dev/ui/ui-ts-page-layout-connections.md deleted file mode 100644 index 28a6075f26d871b5a3ff0b13c9630afe5b466707..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/ui/ui-ts-page-layout-connections.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -title: ui-ts-page-layout-connections -permalink: /pages/extra/f9c0e8/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# 页面布局与连接 - - - -- **[构建食物数据模型](/pages/010802030501)** - -- **[构建食物列表List布局](/pages/010802030502)** - -- **[构建食物分类Grid布局](/pages/010802030503)** - -- **[页面跳转与数据传递](/pages/010802030504)** \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/application-dev/usb/Readme-CN.md b/website/docs/_posts/zh-cn/application-dev/usb/Readme-CN.md deleted file mode 100644 index 5740d2464377051e9f6daae825ec80339c23ea74..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/application-dev/usb/Readme-CN.md +++ /dev/null @@ -1,17 +0,0 @@ ---- -title: Readme-CN -permalink: /pages/extra/6eccf9/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# USB服务 - -- [USB服务开发概述](/pages/01080701) -- [USB服务开发指导](/pages/01080702) diff --git a/website/docs/_posts/zh-cn/compatibility/readme.md b/website/docs/_posts/zh-cn/compatibility/readme.md deleted file mode 100644 index 2c9c3c7c92771abe8bb3f19f604b0ce51d4525a8..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/compatibility/readme.md +++ /dev/null @@ -1,14 +0,0 @@ ---- -title: readme -permalink: /pages/extra/ac9e5f/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -Todo diff --git a/website/docs/_posts/zh-cn/contribute/OpenHarmony-64bits-coding-guide.md b/website/docs/_posts/zh-cn/contribute/OpenHarmony-64bits-coding-guide.md deleted file mode 100644 index 0b09e327f95726da35fcc917c4e843fc19ba98e0..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/contribute/OpenHarmony-64bits-coding-guide.md +++ /dev/null @@ -1,603 +0,0 @@ ---- -title: OpenHarmony-64bits-coding-guide -permalink: /pages/extra/a53c98/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# OpenHarmony 32/64位可移植编程规范 - -## 前言 - -### 目的 - -OpenHarmony的目标是面向全场景、全连接、全智能时代,基于开源的方式,搭建一个智能终端设备操作系统的框架和平台,促进万物互联产业的繁荣发展。具有“硬件互助,资源共享”、“一次开发,多端部署”、“统一OS,弹性部署”的技术特性。 -OpenHarmony支持三种系统类型: - -1. 轻量系统(mini system),面向MCU类处理器(例如Arm Cortex-M、RISC-V 32位)的轻量设备,硬件资源极其有限,支持的设备最小内存为128KiB; -2. 小型系统(small system),面向应用处理器(例如Arm Cortex-A 64位)的设备,支持的设备最小内存为1MiB -3. 标准系统(standard system),面向应用处理器(例如Arm Cortex-A 64位)的设备,支持的设备最小内存为128MiB - -因此,OpenHarmony的代码运行在32位/64位的设备上。对系统代码的可移植性、32位/64位运行模式下的编码需要一定的规约。本文以此为初衷,结合OpenHarmony的特点,拟定了相关编程规约,用于指导代码移植和64位编码,提升代码的规范性及可移植能力,供研发人员参考。 - -### 适用范围 - -用户态和内核态的C、C++代码,不区分语言的标准。 - -### 32位/64位系统的类型差异 - -#### 数据类型差异 - -大部分的32位系统采用的是ILP32,即int、long和pointer是32位长度。大部分的64位系统采用的是LP64,即long、long long、pointer是64位长度。Windows系统采用的是LLP64,即long long和pointer是64位长度。各系统基本数据长度对比如下表所示: - -| **TYPE** | **ILP32** | **LP64** | **LLP64** | **LP32** | **ILP64** | -| --------- | --------- | -------- | --------- | -------- | --------- | -| char | 1 | 1 | 1 | 1 | 1 | -| short | 2 | 2 | 2 | 2 | 2 | -| int | 4 | 4 | 4 | 2 | 8 | -| long | **4** | **8** | **4** | 4 | 8 | -| long long | 8 | 8 | 8 | 8 | 8 | -| float | 4 | 4 | 4 | 4 | 4 | -| double | 8 | 8 | 8 | 8 | 8 | -| size_t | **4** | **8** | **8** | 4 | 8 | -| pointer | **4** | **8** | **8** | 4 | 8 | - -上表中只包含了部分基本类型,下表分别将ILP32和LP64的sizeof和print`进行对比,展示了更全面的常量和类型对应的差异: - -| Type | ILP32 sizeof | ILP32 print | LP64 sizeof | LP64 print | 备注 | -| ------------------ | ------------ | ----------- | ----------- | ---------- | ------ | -| bool | 1 | %u | 1 | %u | C++ | -| char | 1 | %d或%c | 1 | %d或%c | | -| unsigned char | 1 | %u | 1 | %u | | -| short | 2 | %d | 2 | %d | | -| unsigned short | 2 | %u | 2 | %u | | -| int | 4 | %d | 4 | %d | | -| unsigned int | 4 | %u | 4 | %u | | -| long | 4 | %ld | **8** | %ld | 有差异 | -| unsigned long | 4 | %lu | **8** | %lu | 有差异 | -| long int | 4 | %ld | **8** | %ld | 有差异 | -| unsigned long int | 4 | %lu | **8** | %lu | 有差异 | -| long long | 8 | %lld | 8 | %lld | | -| unsigned long long | 8 | %llu | 8 | %llu | | -| type * | 4 | %p | **8** | %p | 有差异 | -| pid_t | 4 | %d | 4 | %d | | -| socklen_t | 4 | %u | 4 | %u | | -| off_t | 4 | %zd | **8** | %zd | 有差异 | -| time_t | 4 | %zd | 8 | %zd | 有差异 | -| pthread_t | 4 | %zu | **8** | %zu | 有差异 | -| size_t | 4 | %zu | 8 | %zu | 有差异 | -| ssize_t | 4 | %zd | **8** | %zd | 有差异 | - -#### 数据结构对齐的差异 - -##### 包含指针数据结构对齐的变化 - -```c -typedef struct tagFoo { - void *p; - uint32_t i; -} Foo; -``` - -在32位系统上,指针长度为4,Foo 4字节对齐,sizeof(Foo) 等于8,在64位系统上,指针长度为8,Foo 8字节对齐,sizeof(Foo) 等于16。 - -##### 包含64位整形的数据结构对齐的变化 - -```c -typedef struct tagFoo { - uint64_t p; - uint32_t i; -} Foo; -``` - -虽然uint64_t是定长的,但由于对齐的存在,Foo的大小也是不同的。在32位系统上,Foo 4字节对齐,sizeof(Foo) 等于12,在64位系统上,Foo 8字节对齐,sizeof(Foo) 等于16。uint64_t替换为double,上述结论依然成立。 - -### 约定 - -**规则**:编程时必须遵守的约定(must) - -**建议**:编程时应该遵守的约定(should) - -## 编程指导 - -### 总则 - -#### 【规则】开发者贡献的代码应当遵循此规范,编写出可同时应用于32位和64位的代码 - -【说明】由于OpenHarmony会长期同时存在32位的运行环境和64位的运行环境,而为了代码的一致性,开发者在编码时需要充分考虑代码的可移植能力。 - -### 数据类型定义和格式化 - -#### 【规则】应当使用统一定义的数据类型定义变量,无特殊意义或要求应当避免自行定义基本数据类型 - -【说明】基于可移植性要求,在32位和64位条件下,可变长度的数据类型可能导致兼容性错误,为简单清晰,要求采用归一清晰的数据类型进行定义。基于当前的要求,定义下列基础数据类型: - -| 类型定义 | ILP32 | LP64 | PRINT | 使用场景及代替类型 | -| ---------------- | ----- | ----- | ------- | ------------------------------------------------------------ | -| void | - | - | - | void,无类型,仅用于占位和通用指针定义 | -| char | 1 | 1 | %c | 对于字符串、数组直接使用原生char | -| int8_t | 1 | 1 | %d | 对于1字节整型使用int8_t,uint8_t | -| uint8_t | 1 | 1 | %u | 对于1字节整型使用int8_t,uint8_t | -| int16_t | 2 | 2 | %d | 代替short | -| uint16_t | 2 | 2 | %u | 代替unsigned short | -| int32_t | 4 | 4 | %d | 代替int | -| uint32_t | 4 | 4 | %u | 代替unsigned int | -| int64_t | 8 | 8 | %PRId64 | 代替long long、宏实现代码兼容 | -| uint64_t | 8 | 8 | %PRIu64 | 代替unsigned long long、宏实现代码兼容 | -| float | 4 | 4 | %f | 单精度浮点数 | -| double | 8 | 8 | %lf | 双精度浮点数 | -| bool | 1 | 1 | %d | 布尔类型 | -| uintptr_t | **4** | **8** | %zu | 会根据32位和64位的不同定义为不同的长度,用于可能存储指针的场景 | -| type * | **4** | **8** | %p | type *,可变长度类型,与uintptr_t等价,存在类型转换时建议使用uintptr_t | -| nullptr_t | **4** | **8** | %p | 指针初始化 | -| pid_t | 4 | 4 | %d | Linux内置,固定长度 | -| socklen_t | 4 | 4 | %u | Linux内置,固定长度 | -| off_t/time_t | **4** | **8** | %zd | 可变长类型,有符号 | -| size_t/pthread_t | **4** | **8** | %zu | 可变长度类型,无符号,仅用于调用库函数的兼容性要求(比如底层API中使用了size_t) | - -上述类型定义在stddef.h(C)和cstdint(C++)标准库中,在采用#define重定义相关类型时,其源头应来自于上述类型。 - -非特殊情况,不要使用非标准类型。禁止定义通用基础类型,除非定义的类型有明确的特定含义。对于涉及到第三方接口及API调用中使用的基础数据类型,以相关专项规则为准。 - -【示例】非必要禁止自定义基础数据类型: - -```c -// 禁止使用下面代码来重定义 -typedef unsigned int UINT32;// 此定义禁止使用 - -// 已经有内置的uint32_t完全可代替上述定义,因此上述定义没有存在的必要。但如果定义的类型有明确的专用意义,则可以保留定义: -typedef uint32_t DB_TABLE_ID; // 此定义可以保留 -``` - -【示例】下面2个类型的长度与通常理解不一致,禁止使用: - -| 类型定义 | ILP32 | LP64 | PRINT | 使用场景及代替类型 | -| -------- | ------ | ----- | ----- | ---------------------- | -| float_t | **12** | **4** | - | 长度不合常理,禁止使用 | -| double_t | **12** | **8** | - | 长度不合常理,禁止使用 | - -#### 【建议】应当避免使用非统一定义的可变长类型定义变量,为适配平台、第三方代码接口等使用,需要特殊说明 - -【说明】原生的long、int、short、size_t等类型,在64位和32位下其长度不确定,在编码时容易疏忽而导致代码隐患。如果将此类型用于外部存储或通信,则很容易导致系统间的不兼容,因此无特殊需求原则上应当避免使用这些类型。 - -【例外】如果因为平台、第三方、库函数等原因,可以有限使用。使用这些类型定义时需要增加说明方便理解。 - -【示例】 - -```c -long var; -// 该定义在64位下为8bytes,在32位下为4bytes,存在歧义,建议修改为uint32_t或uint64_t。 -``` - -#### 【规则】避免使用uchar类型定义变量 - -【说明】uchar或unsigned char用来定义字符串是一种不规范用法。对当前代码中已经存在的使用,需要修改为char类型(确认是字符串)或uint8_t(确认是无符号整数)。 - -对于涉及到8bit编码的非ANSI字符序列,建议仍然使用char类型来定义。C++情况下,可使用wchar等宽字符类型定义。 - -#### 【规则】当需要采用整型变量来存储指针时,变量应该定义成uintptr_t以适应不同的位宽 - -【说明】uintptr_t类型用于用于存储指针长度的数据,其长度在32位和64位可自动适应。 - -【示例】 - -```c -uintptr_t sessionPtr; - -// 将指针存储为变量时,强转和左值都应定义为uintptr_t,以适配不同场景字长的变化 -sessionPtr = (uintptr_t) GetMemAddress(); -``` - -#### 【建议】函数入参或返回值定义的类型与变量类型发生不匹配时候,需要谨慎处理,以保证按照赋值和类型转换的规则进行转换后的结果正确 - -【说明】如果不可避免出现了类型不一致的情况,需要谨慎进行类型转换,确保转换后的结果满足实际应用需求。 - -【示例】 - -```c -long function (long l); -int main () { - int i = -2; - unsigned int k = 1U; - long n = function(i + k); -} -``` - -【注释】上面这段代码在 64 位系统上会失败,因为表达式 (i + k) 是一个无符号的 32 位表达式,在将其转换成 long 类型时,符号并没有得到扩展。入参的结果是不正确的。解决方案是将其中一个操作数强制转换成 64 位的类型。 - -#### 【规则】打印64位的整数请使用%PRId64,%PRIu64,%PRIx64等64位兼容宏进行格式化输出,不允许使用%d,%ld,%zd,%x,%lx等不兼容输出 - -【说明】如果待格式化的数据明确为64位类型(定义为uint64_t),其输出格式化应当采用下述方法: - -```c -#include -#include -#include - -int main() -{ - uint64_t a = 0x1234567fffffff; - printf("a = %"PRIx64"\n", a); - return 0; -} -``` - -上述输出代码,在32位和64位环境下均能够正常输出64位长度数字。如果采用其它格式处理,都存在兼容性问题,需要注意避免,如下表: - -| 格式化方法 | ILP32构建 | ILP32结果 | LP64构建 | LP64结果 | 结论 | -| ---------- | -------------- | --------- | -------------- | -------- | ---------- | -| %lx | 类型不匹配告警 | 错误 | 无告警 | 正确 | **不兼容** | -| %zx | 类型不匹配告警 | 错误 | 无告警 | 正确 | **不兼容** | -| %llx | 无告警 | 正确 | 类型不匹配告警 | 正确 | **不兼容** | -| %p | 类型不匹配告警 | 错误 | 类型不匹配告警 | 正确 | **不兼容** | -| %PRIx64 | 无告警 | 正确 | 无告警 | 正确 | 兼容 | - -【示例】类型不匹配告警信息示例: - -```bash -# 32位编译 -format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 2 has type ‘uint64_t {aka long long unsigned int}’ -format ‘%zx’ expects argument of type ‘size_t’, but argument 2 has type ‘uint64_t {aka long long unsigned int}’ -format ‘%p’ expects argument of type ‘void *’, but argument 2 has type ‘uint64_t {aka long long unsigned int}’ - -# 64位编译 -format ‘%llx’ expects argument of type ‘long long unsigned int’, but argument 2 has type ‘uint64_t {aka long unsigned int}’ -format ‘%p’ expects argument of type ‘void *’, but argument 2 has type ‘uint64_t {aka long unsigned int}’ -``` - -#### 【规则】打印输出可变类型数据,对齐时要考虑数据长度并预留足够空间 - -【说明】32位下指针及size_t长度最大只有8位(16进制)或10位(10进制),但在64位系统下,其最大宽度可达到20位,因此在打印输出时需要充分考虑其范围,避免打印因不对齐而影响用户体验。 - -#### 【规则】使用常量时,禁止采用L/UL作后缀,允许增加U后缀指定为unsigned int类型,允许增加LL/ULL后缀指定其长度为64位 - -【说明】无后缀的常量缺省为int类型;采用L/UL为后缀时,在32位和64位系统下,长度可能发生变化;确定需要64位时,采用LL/ULL为后缀定义以确保在32位和64位系统下均为64位长度。 - -| 常量定义 | ILP32 | LP64 | 使用场景 | -| -------------- | --------- | ----- | ------------------------------------------------------------ | -| 1 | 4 | 4 | 默认为int32_t类型,长度固定 | -| 1U | 4 | 4 | 默认为uint32_t类型,长度固定 | -| 1L | **4** | **8** | 后缀为L或UL,长度不同,应当避免使用 | -| 1UL | **4** | **8** | 后缀为L或UL,长度不同,应当避免使用 | -| 1LL | 8 | 8 | 默认为int64_t类型,长整形数据,直接使用LL,确定为64位,长度固定 | -| 1ULL | 8 | 8 | uint64_t类型,无符号长整形数据 | -| 0x7FFFFFFF | 4 | 4 | 不携带附加符号的数字,不超过int32_t的范围,默认为int32_t类型 | -| 0x7FFFFFFFL | **4** | **8** | 长度不同,避免使用 | -| 0x7FFFFFFFLL | 8 | 8 | 长度固定 | -| 0x80000000 | 4 | 4 | 小于uint32_t范围,类型为uint32_t类型 | -| 0x80000000L | **4** | **8** | 后缀为L,小于uint32_t范围,增加该参数没有意义,应当避免使用 | -| 0x80000000LL | 8 | 8 | 增加LL后缀,小于uint32_t范围,长度固定 | -| 0x8000000000 | **NA或8** | **8** | 无后缀,超过uint32_t的范围,编译器默认为LL或无效,64位下固定为uint64_t类型 | -| 0x8000000000L | **NA或8** | **8** | 后缀为L,对超过uint32_t的范围常数,增加该参数没有意义,应当避免使用 | -| 0x8000000000LL | 8 | 8 | 后缀为LL,uint64_t类型 | - -从上表中可看出,使用L或UL后缀的常量,其长度在32位和64位下发生变化,不利于代码的可移植性,因此禁止使用这个后缀。 - -【示例】 - -```c -// 下面定义中的UL是没有意义的,在32位系统会出错,在64位系统不需要 -#define YYY_START_ADDRESS(XXX_START_ADDR + 0x80000000UL) -``` - -#### 【规则】应当使用标准头文件中定义的宏常量,避免自行定义 - -【说明】C(stdint.h)和C++(cstdint.h)的标准头文件中均有定义最大值/最小值的宏常量,源文件中引用即可,避免自行定义。 - -【示例】 - -```c -#include -#include - -int main() -{ - std::printf("%zu\n", sizeof(std::int64_t)); - std::printf("%s\n", PRId64); - std::printf("%+" PRId64 "\n", INT64_MIN); - std::printf("%+" PRId64 "\n", INT64_MAX); - - std::int64_t n = 7; - std::printf("%+" PRId64 "\n", n); -} -``` - -#### 【规则】应当使用统一的定义表示常量的无效值,避免直接使用全F等表示方法以适应不同的长度 - -【说明】同一个数字常量值在64位系统和32位系统上,按照32位系统有无符号类型,理解的结果可能不一样;特别是32位系统上最高bit位为1的,在32位系统上按照有符号类型理解成一个负数,在64位系统上是一个正数。要求统一使用typedef.h中的统一定义,表示数据的无效值。 - -```c -// 使用typedef.h中的定义 -#define INVALID_INT8((int8_t)(-1)) -#define INVALID_UINT8((uint8_t)(-1)) -#define INVALID_INT16((int16_t)(-1)) -#define INVALID_UINT16((uint16_t)(-1)) -#define INVALID_INT32((int32_t)(-1)) -#define INVALID_UINT32((uint32_t)(-1)) -#define INVALID_INT64((int64_t)(-1)) -#define INVALID_UINT64((uint64_t)(-1)) -``` - -【示例】 - -```c -// 在32位系统上,n是一个负数 -long n = 0xFFFFFFFF; -// 在64位系统上,n是一个正数,实际值为0x00000000FFFFFFFF。 -long n = 0xFFFFFFFF; -``` - -#### 【建议】对不会超过32位空间大小的临时变量,建议采用uint32_t定义 - -【说明】定义的变量不需要特别关注其类型,可采用默认的uint32_t类型,以减少因类型不一致导致的大量强制类型转换。 - -### 结构体对齐与填充 - -#### 【规则】代码中禁止采用常量硬编码来指定变量长度、结构体长度,应当使用sizeof等内建类型来获取 - -【说明】sizeof可自动计算相关变量和结构的长度,避免硬编码错误;同时在编译时即完成了所属变量长度的计算,不会影响运行性能。 - -在64位系统下默认对齐方式是8字节对齐,使用sizeof()获取结构体长度来取代硬编码,以避免因结构对齐导致的长度计算错误。 - -联合在使用时,需要特别关注到其长度在64位和32位下的不同,避免在计算长度时出现错误。特别是按照最大长度进行计算和空间申请。 - -【示例】未采用sizeof计算结构长度,可能导致内存空间不足。 - -```c -int32_t *p; -p = (int32_t *)malloc(4 * ELEMENTS_NUMBER); -// 这行代码假定指针的长度为4字节,而这在LP64中是不正确的,此时是8字节。 - -//正确的方法应使用sizeof() -int32_t *p; -p = (int32_t *)malloc(sizeof(p) * ELEMENTS_NUMBER); -``` - -#### 【建议】特殊情况下,64位系统可以强制编译器指定对齐方式 - -【说明】在需要时,为保持代码兼容性,可采用指定对齐方式。使用伪指令#pragma pack (n),编译器将按照n 个字节对齐;使用伪指令#pragma pack (),取消自定义字节对齐方式。 - -【样例】 - -```c -#pragma pack(push) # 保存当前的对齐方式 -#pragma pack(1) # 设置对齐方式为1字节对齐 -struct test -{ - ...... -}; -#pragma pack(pop) # 恢复之前的对齐方式 -``` - -#### 【规则】涉及多机通信的消息结构体,需要对齐统一。基于兼容性考虑,可优先采用1字节对齐;禁止使用8字节对齐和64位数据类型以避免与32位系统通信错误 - -【说明】板间通信消息涉及到跨板操作,除非所有软件同步升级,否则将会导致通信失败。为兼容性考虑,对已经存在的协议和结构,保持1字节对齐,并转换为网络序。对新增的通信协议,为通信效率和处理性能考虑,可以有条件采用4字节对齐。 - -#### 【规则】对外提供的接口数据结构应当避免出现填充,至少要求采用4字节对齐 - -【说明】对功能特性对外提供的API头文件,如果其中涉及到结构体定义,应当避免结构体填充,建议能够在自然对齐情况下数据不出现空洞,至少需要保证4字节对齐。 - -#### 【建议】应当使用成员名称访问结构体成员,禁止使用偏移方式访问 - -【说明】数据结构成员的偏移在32位和64位对齐情况下,其偏移值不同,不能直接计算每个成员的大小之后作为偏移;在32位系统上没有自动填充的数据结构,到了64位上有可能出现自动填充。 - -【示例】 - -```c -Struct A -{ - uint32_t a; - uint32_t *p; - uint32_t b; -}; -``` - -成员b的偏移等于sizeof(a) + sizeof(p)在32位系统上成立,在64位系统上不成立。正确的做法应当是直接通过变量名称进行索引定位: - -```c -xxx.b = 123; -``` - -如果结构定义比较特殊,比如结构体只是消息的头部,后续还有其它字段,则可能需要重新定义此结构,使结构体内部不出现填充字段。 - -【示例】 - -```c -typedef struct { - uint32_t self; /* 其它对齐结构 */ - uint32_t brother; /* 其它对齐结构 */ - uint8_t processedFlag; /* 当前节点是否被处理过的标志 */ - uint8_t reserve[3]; /* 为了4字节对齐的保留字段 */ -} TreeNodeInfo; - -typedef struct { - TreeNodeInfo nodeInfo; /* 每一个node的树信息的数据结构 */ - void *userInfo; /* 每一个node的用户信息数据结构 */ -} TreeNode; -``` - -TreeNode结构体中有两个成员结构体,下面的代码中根据第二个成员来获取第一个成员的地址,采用第二个成员首地址减去sizeof(第一个成员)计算(inUserInfo指向结构体中的userInfo字段): - -```c -inTreeNodeInfo = (TreeNodeInfo *)((void *)(((char *)inUserInfo) - sizeof(TreeNodeInfo))); -``` - -结构体采用自然对齐,需要注意到子结构体TreeNodeInfo,在32位下其长度为12bytes,在64位下,**其长度也是12位**。结构体TreeNode在32位下成员结构体之间无填充,其长度为16bytes,但在64位下的结构体长度:sizeof(TreeNodeInfo)=12,sizeof(TreeNode)=24,即子结构体TreeNodeInfo后有4个字节的填充字段,因此在64位下通过上述方法获取前一个字段地址,就会漏算填充的4个字节,导致成员访问出错。 - -#### 【建议】结构体定义时,为节省存储空间,在保证可读性的前提下,尽可能实现8字节自然对齐,避免出现填充 - -【说明】如果结构体能够实现自然对齐,则不需要进行填充,可有效节省结构体的无效空间。在不影响可读性的前提下,建议将size_t和pointer等64位长度类型放在结构体两端定义。 - -【示例】 - -```c -// 下面的结构体,在自然对齐情况下,其长度为24bytes -struct Foo -{ - int32_t a; - uint64_t l; - int32_t x; -} - -// 经过适当调整,可优化到16bytes -struct Foo -{ - uint64_t l; - int32_t a; - int32_t x; -} -``` - -### 数据类型转换及运算 - -#### 【规则】应当避免不同类型的数据之间的隐式类型转换,如果必要,应当采用显式类型转换,避免在32位和64位系统结果不一致 - -【说明】谨慎处理不同长度和精度的操作数之间进行运算,避免因默认转换出现精度和符号的丢失。64位与32位混合编程情况下,需要关注隐式类型转换的几个重要点: - -1. 64位长度的变量给32长度变量赋值,低32位直接赋值,高32位被截断丢失;低32位再根据左值变量类型理解成有符号或者无符号 - -2. 反之,32位长度的变量给64长度变量赋值,根据源32位为有符号或者无符号进行符号扩展,目的64位数再根据变量类型理解成有符号或者无符号。 - -3. 有符号数与无符号数进行运算,如果不指定结果类型,系统默认按照无符号方式理解。 - -上述转换过程可能带来不符合原意的结果,因此需要谨慎对待,尽可能避免隐式的转换。 - -【示例】转换后结果看上去正确的示例 - -```c -int32_t t1 = -2; -int64_t t2 = 1; -int32_t t3 = t1 + t2; -printf("t3 = %d\n", t3); - -// 打印结果: t3 = -1 -``` - -t1是个32位数,t2是个64位数,在做运算之前,先把t1也扩展成64位的。加法完成之后结果是一个64位的int64_t类型,在内存中16进制存储值为:0xffffffffffffffff,在给32位int32_t类型赋值发生截断, 值为0xffffffff,再理解成有符号32位,值为-1。此结果虽然看上去正确,但发生了数据截断,可能并不符合作者的本意。 - -【示例】有符号向无符号转换 - -```c -int64_t t1 = -1; -uint32_t t2 = t1; -printf("t2=%u", t2); - -// 打印结果:t2=4294967295 -``` - -t1是个64位int64_t类型,用二进制表示为0xffffffffffffffff,如果赋值给一个32位int类型,高32位丢失,直接显示位低32位的值,二进制为0xffffffff,按照无符号方式理解,值为4294967295。 - -【示例】32位向64位无符号转换 - -```c -int32_t t1 = -1; -uint64_t t2 = t1; -printf("t2 = %lu\n", t2); - -// 打印结果:t2 = 18446744073709551615 -``` - -源32位是个有符号的负数,扩展时,应该带符号扩展,负数高位全部为f,扩展后值为0xffffffffffffffff。目的64位类型是个无符号的数,所以其值是一个很大的正数。 - -#### 【规则】当需要将指针作为基址,再按照字节计算偏移时,指针需要强制转换为uintptr_t或uint8_t *等单字节指针类型 - -【说明】如果转换为整型,采用uint32_t强转,会出现指针被截断的情况,因此需要转换为uintptr_t。也可转换为单字节宽度的指针类型,如uint8_t *、char *等,转为上述方式后,偏移均被理解为字节。void *类型实际也会按照1字节进行偏移,但为了类型明确化,建议使用前面更明确的类型代替。 - -【示例】 - -```c -// 错误 -void *pPkt = (void *)((uint32_t)MSG_GET_DATA_ADDR(msgAddr) + OFFSET); - -// 正确 -void *pPkt = (void *)((uintptr_t)MSG_GET_DATA_ADDR(msgAddr) + OFFSET);// C -void *pPkt = reinterpret_cast(reinterpret_cast(MSG_GET_DATA_ADDR(msgAddr)) + OFFSET); // C++ -``` - -#### 【规则】禁止指针与uint32_t之间相互赋值,包括函数参数传递 - -【说明】如果要定义的变量可能是不确定长度的指针,使用void *;如果要定义的变量既可以是指针,也可以是整形,使用uintptr_t。 - -【示例】指针与整型的转换 - -```c -int32_t i, *p, *q; -p = &i; -q = (int32_t *) (int32_t)&i; - -// 在A32架构下,p = q;但是在A64-LP64架构下,p != q -``` - -为了避免这种类型冲突问题,可以用uintptr_t来表示指针类型。 - -#### 【规则】禁止size_t与int32_t/uint32_t之间相互赋值,包括函数参数传递 - -【说明】可变长度类型禁止与32长度类型强转。 - -【示例】 - -```c -int32_t length = (int32_t)strlen(str); // 错误 -``` - -strlen返回size_t(它在LP64中是unsigned long),当赋值给一个int32_t时,截断是必然发生的。而通常,截断只会在str的长度大于2GB时才会发生,这种情况在程序中一般不会出现,容易忽略。 - -#### 【规则】在64位环境下使用大数组或大for循环索引时,索引类型应当与下标边界保持一致 - -【说明】如果系统中使用了超大数组或超大循环,在64位环境有可能超过32位的索引范围,则需要使用可变长度类型或64位类型来定义数组下标或循环变量,避免因变量范围不足而导致不能全量遍历。 - -【示例】 - -```c -int64_t count = BIG_NUMBER; -for (unsigned int index = 0; index != count; index++) - ... -``` - -在64位系统上,由于int64_t是64位类型,count是一个很大的数。unsigned int是32位类型 导致上面的循环永远不会终止。因此,index应该改成int64_t类型。 - -### 位域和字节序 - -#### 【规则】基于位域的变量定义需要充分考虑位域的基础类型及对齐问题,避免在不同的位宽下计算出错 - -【说明】位域的宽度需要结合对齐进行理解,结构体会变长;对位域的取值需要采用名称,避免采用直接计算。 - -#### 【规则】在64位系统上,考虑移位操作带来的长度差异,以及移位以后生成的值隐形扩展到64位的问题 - -【说明】位移运算时,需要检查是否可能导致溢出而回绕的情况,需要修改为32位类型避免结果不一致。 - -【示例】 - -```c -int64_t t = 1 << a; // 需考虑a的大小 -``` - -在32位系统上,a的最大值是32,在64位系统上,是64。如果a是一个32位变量,其结果还要考虑到64位扩展问题。 - -### 第三方库和差异化功能 - -#### 【规则】64位系统使用到的第三方类库,都必须是支持64位的 - -【说明】部分库函数、第三方开源代码本身对64位的支持不定完善,需要针对所有涉及的代码进行评估,确保其可运行在64位环境下。部分库函数在64位和32位采用不同的接口实现,因此需要确保使用正确的接口。 - -【示例】内存映射处理,在32位系统下可使用mmap,如果映射超过2GBytes,则需要使用mmap64;但64位系统下可统一使用mmap。 - -#### 【规则】涉及到底层汇编的功能,需要在64位和32位系统分别独立调测,避免功能不可用 - -【说明】切换到64位后,寄存器个数和位宽都有变化,涉及到汇编的相关调测功能都需要进行重新的调测,并需要同时关注32位和64位下的代码有效性。 - -【示例】调用栈的推栈功能,在32位和64位内嵌的汇编代码需要独立编写调测。 - -#### 【规则】补丁功能需要同时支持32位指令和64位指令差异 - -【说明】由于指令长度变更,补丁机制及功能需要适配修改。 - -#### 【规则】64位系统使用到的工具,都必须是支持64位的 - -【说明】如果不可避免出现了类型不一致的情况,需要谨慎进行类型转换,确保转换后的结果满足实际应用需求。 diff --git a/website/docs/_posts/zh-cn/contribute/OpenHarmony-Java-secure-coding-guide.md b/website/docs/_posts/zh-cn/contribute/OpenHarmony-Java-secure-coding-guide.md index 299c2bfe00851ebf50fcf2635029712dda3d5606..e7ab9ddbe2b94d50a0f216f123ddd74d3754e965 100644 --- a/website/docs/_posts/zh-cn/contribute/OpenHarmony-Java-secure-coding-guide.md +++ b/website/docs/_posts/zh-cn/contribute/OpenHarmony-Java-secure-coding-guide.md @@ -1,15 +1,15 @@ --- -title: OpenHarmony-Java-secure-coding-guide -permalink: /pages/extra/d49c41/ +title: OpenHarmony-Java-secure-coding-guide.md +permalink: /pages/extra/d38f7b/ navbar: true sidebar: false prev: false next: false -search: true -article: true +search: false +article: false comment: false editLink: false -date: 2022-02-14 21:31:38 +date: 2021-12-30 12:57:47 --- # OpenHarmony Java 安全编程指南 diff --git a/website/docs/_posts/zh-cn/contribute/OpenHarmony-JavaScript-coding-style-guide.md b/website/docs/_posts/zh-cn/contribute/OpenHarmony-JavaScript-coding-style-guide.md index 407d4c6fdb55f34a2461e7b9383013881b3b5eb8..8e6b2bcb1cf5a59e7ab6376eec5edc16bc1d5617 100644 --- a/website/docs/_posts/zh-cn/contribute/OpenHarmony-JavaScript-coding-style-guide.md +++ b/website/docs/_posts/zh-cn/contribute/OpenHarmony-JavaScript-coding-style-guide.md @@ -1,15 +1,15 @@ --- -title: OpenHarmony-JavaScript-coding-style-guide -permalink: /pages/extra/ae0e51/ +title: OpenHarmony-JavaScript-coding-style-guide.md +permalink: /pages/extra/38b13b/ navbar: true sidebar: false prev: false next: false -search: true -article: true +search: false +article: false comment: false editLink: false -date: 2022-02-14 21:31:38 +date: 2021-12-30 12:57:47 --- # JavaScript语言通用编程规范 @@ -367,8 +367,9 @@ console.log(url); //url可以被访问到,输出内容:http://127.0.0.1:8080 **正例:** ```javascript +// ES5.1使用var声明变量 function open() { - let url = 'http://127.0.0.1:8080'; + var url = 'http://127.0.0.1:8080'; // todo something } open(); @@ -376,6 +377,7 @@ console.log(url); //报错:Uncaught ReferenceError: url is not defined ``` ```javascript +// ES6中,优先推荐使用let和const关键字来声明变量 function open() { const url = 'http://127.0.0.1:8080'; //todo something diff --git a/website/docs/_posts/zh-cn/contribute/OpenHarmony-Log-guide.md b/website/docs/_posts/zh-cn/contribute/OpenHarmony-Log-guide.md deleted file mode 100644 index b9d22b4f87d23c8dd0db795538260b6ce48d564a..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/contribute/OpenHarmony-Log-guide.md +++ /dev/null @@ -1,249 +0,0 @@ ---- -title: OpenHarmony-Log-guide -permalink: /pages/extra/2d2a23/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# OpenHarmony日志打印规范 - -## 简介 -公共流水日志指通过系统日志打印接口(HiLog)统一输出到日志服务的日志。日志用来记录用户操作、系统运行状态等,是一个系统的重要组成部分,然而由于日志不是核心功能,所以日志质量常常不被开发人员所重视。 - -尽管日志记录是必要的,但它对性能有明显的负面影响,如果不保持合理的简洁性,则会很快失去其有用性。每个领域在打印日志的时候都应该尽可能的合理,不要将别人的日志冲掉,就像你希望别人不冲掉你的日志一样。 - -## 日志级别 - -- **【规则】根据实际情况正确的使用日志打印等级** - -**说明:** 日志级别要符合日志内容的实际级别,日志级别说明如下: - -FATAL:重大致命异常,表明程序或功能即将崩溃,故障无法恢复。 - -ERROR: 程序或功能发生了错误,该错误会影响功能的正常运行或用户的正常使用,可以恢复但恢复代价较高,如重置数据等。 - -WARN:发生了较为严重的非预期情况,但是对用户影响不大,程序可以自动恢复或通过简单的操作就可以恢复的问题。 - -INFO:用来记录业务关键流程节点,可以还原业务的主要运行过程;用来记录非正常情况信息,但这些情况都是可以预期的(如无网络信号、登录失败等)。这些日志都应该由该业务内处于支配地位的模块来记录,避免在多个被调用的模块或低级函数中重复记录。 - -DEBUG: 比INFO级别更详细的流程记录,通过该级别的日志可以更详细地分析业务流程和定位分析问题。DEBUG级别的日志在正式发布版本中默认不会被打印,只有在调试版本或打开调试开关的情况下才会打印。 - -## 日志内容 - -- **【规则】日志打印内容使用英文描述,单词拼写无误,符合语法规范,准确表述日志的含义** - -**说明:** 日志内容应该简明扼要地描述发生的事情,阅读日志的人可以通过日志直接知道表述的含义,尽量不要通过产生日志的代码才能知道;符合语法语义的日志打印也有利于后续日志分析工具对日志进行自动化解析。如: - -“1234” 除了开发人员自己没人知道什么意义; - -“Error happened” 哪里发生了什么错误,错误的原因值等都没有打印出来,不利于问题的定位分析。 - -- **【规则】日志中禁止打印隐私信息** - -**说明:** 硬件序列号、个人账号、密码、身份等隐私信息禁止在日志中打印。隐私信息的范围遵从国家和地区的政策要求。 - -- **【规则】日志中禁止打印其它与业务无关的信息** - -**说明:** 禁止打印如issue单号、需求单号、公司部门名称、开发人员自己的姓名、工号、名字缩写、当天的天气心情等任何与业务代码无关的信息。 - -- **【规则】日志中禁止打印重复信息** - -**说明:** 禁止在不同的地方打印的内容完全一样的日志,在问题定位时无法准确找到代码位置。 - -- **【规则】禁止在日志打印语句中调用业务接口函数** - -**说明:** 日志打印不应该对业务的正常流程产生任何影响,定位问题走读代码时通常会忽略日志代码对业务逻辑的影响。 - -- **【规则】禁止将开发调试过程中使用的日志打印提交到代码仓中** - -**说明:** 为了定位问题可能会在代码中的每一步增加一行日志打印,或将各种变量内容打印出来(可能含用户隐私), -这些代码在提交到代码仓之前必须删除。 - -- **【建议】日志打印长度不要过长,尽可能使日志记录显示在一行以内** - -**说明:** 一行的长度通常是指在100个字符左右,尽量不要打印超过160个字符以上的日志。 - -## 打印时机 - -- **【规则】高频代码的正常流程中禁止打印日志** - -**说明:** 如被高频调用的接口函数,大数据量处理的循环中,高频的软硬件中断处理中,协议数据流处理中,多媒体音视频流处理中,显示屏幕刷新处理中等等,这些地方基本都是只要系统不休眠就会一直运行的代码,这些代码正常处理禁止打印日志,但可在错误分支中打印日志。开发调试过程中在这里增加的日志在提交代码时必须清除掉或使用开关关闭。 - -- **【规则】可能重复发生的日志需要进行频率限制** - -**说明:** 当事实证明某些日志记录可能会发生多次时,最好实施一种频率限制机制,防止出现具有相同(或非常相似)信息的大量重复日志副本。 - -- **【规则】在基本不可能发生的点必须要打印日志** - -**说明:** 根据墨菲定律,只要有可能发生的是就一定会发生,一旦发生就是疑难杂症。 - -- **【建议】日志字符串应在日志打印时再生成** - -**说明:** 日志字符串越迟生成越好,最好是在日志打印那一刻才生成,这样当日志被关闭时也就不会生成这个字符串,从而最大程度地减少对系统的开销。 - -## 日志形式 - - -- **【规则】事件记录的日志使用who do what 主谓宾的形式打印** - -- **【规则】状态变化的日志打印使用state\_name:s1->s2, reason:msg的形式打印** - -- **【规则】参数值的日志打印使用name1=value1, name2=value2…的形式打印** - -- **【规则】代码运行成功的日志使用xxx successful的形式打印** - -- **【规则】代码运行失败的日志使用xxx failed, please xxx的形式打印,且需包含可能的解决方案** - - 如:"Connect to server failed, please check network configuration"。 - -## 常见模式日志打印要求 - -### 流程类日志 - - -- **【建议】日志中应当记录业务的关键流程节点日志,包括业务的开始点,关键条件分支节点,错误处理点,业务结束点等** - -### 数据库类日志 - -- **【建议】日志中应当记录对数据库的各种操作及其相关信息** - -**说明:** 数据库的常规操作包括: -增、删、改、查;操作的发起者、操作类型、操作成功还是失败也要在日志中记录;但操作及返回结果中的内容通常不应记录以防止泄露用户隐私;查询结果的数量可以打印。 - -- **【建议】对于性能敏感型业务的数据库操作日志中需记录操作消耗的时间** - -**说明:** 数据库操作涉及I/O读写, 对于性能敏感性业务,数据库操作通常会是性能的关键节点,记录时间可以作为性能调优的参考依据。 - -- **【建议】日志中应当记录数据库的JOB相关信息** - -**说明:** JOB的名称,执行内容,启动时间,结束时间,执行结果应当在日志中记录。 - -### 文件类日志 -- **【建议】日志中应当记录对文件的各种操作及其相关信息** - -**说明:** 文件的常规操作包括: 创建、打开、读取、写入、关闭、删除、获取属性,操作的发起者、操作类型、操作结果需要记录日志;但文件内容不可记录以防止泄露用户隐私或暴露系统安全漏洞,系统文件名可以打印,用户文件名不可以打印; 文件句柄值可以打印。 - -- **【建议】批量文件操作只打印一条日志而不是打印多条日志** - -**说明:** 如批量删除大量文件,不要每删除一个文件就打印一条日志,只要记录删除的文件数即可,如果文件所在目录是系统创建,还要打印目录名称。 - -### 关键对象/对象池日志 - -**说明:** 关键对象/对象池可能是一个类或者一个结构体,也可能是一个队列或堆栈的数据结构,也可能是一个简单的原始类型变量,它处于系统的关键地位,系统的调度控制、状态记录、信息流转等动作都依赖它。 - -- **【建议】日志中应当记录关键对象的操作过程,操作结果,状态变化** - -**说明:** 对象的操作包括:创建、加载、卸载、释放等,对关键对象的操作需记录操作主体,操作类型,操作结果;状态类的需记录状态变化的前后值。 - -### 线程日志 - -- **【建议】日志中需记录线程的各种操作及相关信息** - -**说明:** 线程的操作包括: 创建、启动、暂停、终止。日志中需记录操作线程的操作类型,操作结果、线程号,线程名称(重要线程一定要设置线程名)。 - -- **【建议】线程陷入死循环或死锁等错误时要记录日志** - -**说明:** 对于有等锁处理、异步处理、循环处理等逻辑的线程在线程发生死锁或死循环时要有检测机制,并在错误发生时打印日志。 - -- **【建议】消息处理型的线程需要打印消息处理相关的日志** - -**说明:** 包括消息名称、消息处理结果,消息处理时长;对于高频消息,只需要打印消息处理结果错误时的日志即可 - -### 并发控制日志 - -**说明:** 并发控制的对象可能是锁、临界区、信号量等。 - -- **【建议】日志中需记录并发控制对象的操作及其相关信息** - -**说明:** 并发控制的操作包括:创建、占用、释放、等待等。日志中需记录操作的类型,操作对象的名称、操作的结果、操作的位置等信息。 - -### 共享内存日志 - -**说明:** 共享内存是软件系统中常用的进程间通信方法,它常用于在模块间共享数据或传递数据。共享内存所存放的数据可以是配置数据、数据库数据等。 - -- **【建议】日志中需记录对共享内存的操作及相关信息** - -**说明:** 对共享内存的操作包括:创建、删除、数据设置、数据查询、销毁等。日志中需记录对共享内存操作的操作者,操作类型、操作结果。 - -### 接口交互日志 - - -接口包括系统的内外部接口,内部接口指系统内部子系统、子模块之间的接口。形式可能包括模块间消息发送、IPC接口、RPC接口等。 - -- **【建议】日志需记录接口交互相关的信息** - -**说明:** 接口交互相关的信息包括:接口的调用者、消息内容(不能涉及用户隐私)、处理结果、返回值(不能涉及用户隐私)。 - -### 状态机日志 - -- **【建议】日志需记录状态机的操作及状态转换信息** - -**说明:** 状态机的操作包括:创建、开始、状态转换、结束、销毁等。状态机通常受外部条件激励(如消息、资源等)变换状态,状态机的状态变化前后的状态名称、导致变化的外部激励条件等信息也应该被记录。 - -### 其它操作系统资源 -这里说的主要操作系统资源指Socket、定时器等不在前面小节已专门提及的资源(如文件、线程等) - -- **【建议】日志中需要记录socket连接建立的过程和结果、连接维持的情况、连接断开的情况及原因** - -- **【建议】日志中需要记录定时器启动、复位、销毁、超时处理过程** - -- **【建议】使用其它类似操作系统中提供的资源也应参照遵循类似上述的日志记录原则** - -## HiLog接口使用规范 - - -- **【规则】每个业务须有独立的Domain ID** - -**说明:** 系统各领域使用HiLog API打印日志须先到DFX申请标识业务的Domain ID。Domain ID用于度量和管控单个业务日志质量,支持开发人员调试使用Domain ID过滤出自身业务日志分析提高调试效率,不允许在不申请Domain ID情况下,直接使用其它领域的Domain ID。对测试代码,要求使用专门为测试配置的Domain ID 0xD000F00 打印日志。 - -系统Domain ID的范围为:**0xD000001\~0xD00FFFF** - -- **【建议】每个业务内部基于Domain ID分配机制在领域内按照层次、模块的粒度划分使用** - -**说明:** Domain ID为32位整数,以16机制形式表达,分配范围0xD0xxxyy。其中D0为domain域标识,xxx高12位为DFX分配值,yy低8位业务领域内部使用。要求Domain ID 内部分配能够定界到组织或模块,反应领域内具体组织或模块日志质量,同时DFX会基于 Domain ID对日志打印进行管控,防止因为单个模块日志打印多影响领域内其它模块的日志输出,如BT业务内按照层次模块进一步划分: - - - APP | BT-App1 BT-App2 - --------------------------------------- - Framework | BT-Service1 BT-Service2 - --------------------------------------- - HAL | BT-HAL - --------------------------------------- - Kernel | BT-Driver1 BT-Driver2 - -BT内的Domain ID可以进一步划分: -| Domain名称 | Domain ID | -|----|----| -| BT | 0xD000100 | -| BT-App1 | 0xD000101 | -| BT-App2 | 0xD000102 | -| BT-Service1 | 0xD000103 | -| BT-Service2 | 0xD000104 | -| BT-HAL | 0xD000105 | -| BT-Driver1 | 0xD000106 | -| BT-Driver2 | 0xD000107 | - -- **【规则】日志服务会对每个业务的日志量进行流量管控,修改默认的流量阈值需要经过评审** - -**说明:** 日志服务中会对每个领域的日志流量进行控制,在正式发布的版本上默认每个领域的日志流量阈值是**2048KB/秒**, 在调试版本上默认阈值是**10240KB/秒**, 如果需要修改默认阈值需经过DFX领域审查。 - -- **【规则】正确填写日志格式化隐私参数标识{public},{private}** - -**说明:** 隐私参数标识{public},{private}用来标识每个参数日志内容是否含隐私敏感信息。Hilog API会自动对标识{public}参数内容以明文输出,对标识{private}参数内容以<private>过滤回显,禁止不分析日志打印内容随意设置隐私参数标识。如: - -源码: - - - HiLog.info(LABEL, "Device Name:%{public}s, IP:%{private}s.", DeviceName, ip); - - -日志输出: - - - 11-11 09:19:00.932 1513 1513 E 00500/Settings: MyPad001, IP: diff --git a/website/docs/_posts/zh-cn/contribute/OpenHarmony-c-coding-style-guide.md b/website/docs/_posts/zh-cn/contribute/OpenHarmony-c-coding-style-guide.md index 218cbc607fb3185ca2abd2b6cc2c5da48974e2e9..1f9f3ff69d333a55bb7c014bdcf395a1a8dfa662 100644 --- a/website/docs/_posts/zh-cn/contribute/OpenHarmony-c-coding-style-guide.md +++ b/website/docs/_posts/zh-cn/contribute/OpenHarmony-c-coding-style-guide.md @@ -1,15 +1,15 @@ --- -title: OpenHarmony-c-coding-style-guide -permalink: /pages/extra/ac1933/ +title: OpenHarmony-c-coding-style-guide.md +permalink: /pages/extra/6f48b1/ navbar: true sidebar: false prev: false next: false -search: true -article: true +search: false +article: false comment: false editLink: false -date: 2022-02-14 21:31:38 +date: 2021-12-30 12:57:47 --- # C语言编程规范 @@ -55,9 +55,6 @@ date: 2022-02-14 21:31:38 大小写字母混用,单词连在一起,不同单词间通过单词首字母大写来分开。 按连接后的首字母是否大写,又分: **大驼峰(UpperCamelCase)**和**小驼峰(lowerCamelCase)** -**内核风格(unix_like)** -内核风格又称蛇形风格。单词小写,用下划线分割。 -如:'test_result' ### 规则1.1 标识符命名使用驼峰风格 @@ -69,10 +66,7 @@ date: 2022-02-14 21:31:38 注意: 上表中`常量`是指,全局作用域下,const 修饰的基本数据类型、枚举、字符串类型的变量,不包括数组、结构体和联合体。 -上表中`变量`是指除常量定义以外的其他变量,均使用小驼峰风格。 -对于更亲和Linux/Unix的代码,可以使用内核风格。 -已使用内核命名风格的代码,可以选择继续使用内核风格。 -不管什么样的命名风格,都应该保证同一函数或结构体、联合体内的命名风格是一致的。 +上表中`变量`是指除常量定义以外的其他变量,均使用小驼峰风格。 ### 建议1.1 作用域越大,命名应越精确 @@ -250,12 +244,8 @@ typedef struct tagNode { // Good: 使用 tag 前缀。这里也可以使用 ' 常量推荐采用全大写,下划线连接风格。作为全局变量,也可以保持与普通全局变量命名风格相同。 这里常量如前文定义,是指基本数据类型、枚举、字符串类型的全局 const 变量。 -函数式宏,命名风格,采用全大写,下划线连接风格。 -例外情况: -1、用宏实现泛型功能的函数。如:实现list,map等功能的宏。可以与函数的命名方式相同,使用大驼峰命名风格。 -2、函数接口发生变更为兼容老版本时,使用函数同宏进行替代。可以与函数的命名方式相同,使用大驼峰命名风格。 -3、日志打印宏。可以与函数的命名方式相同,使用大驼峰命名风格。 -注:使用大驼峰命名的函数式宏,需要在接口说明中标注为宏。 +函数式宏,如果功能上可以替代函数,也可以与函数的命名方式相同,使用大驼峰命名风格。 +这种做法会让宏与函数看起来一样,容易混淆,需要特别注意。 宏举例: ```c @@ -310,16 +300,16 @@ enum BaseColor { ### 建议1.5 避免函数式宏中的临时变量命名污染外部作用域 -首先,**定义函数式宏前,应考虑能否定义为函数。如果可以则不要定义为函数式宏。** +首先,**尽量少的使用函数式宏。** 当函数式宏需要定义局部变量时,为了防止跟外部函数中的局部变量有命名冲突。 -后置下双划线,是一种解决方案。 例: +后置下划线,是一种解决方案。 例: ```c #define SWAP_INT(a, b) do { \ - int tmp__ = a; \ + int tmp_ = a; \ a = b; \ - b = tmp__; \ + b = tmp_; \ } while (0) ``` @@ -327,11 +317,11 @@ enum BaseColor { ## 行宽 -### 规则2.1 行宽不超过 120 个字符 +### 建议2.1 行宽不超过 120 个字符 代码行宽不宜过长,否则不利于阅读。 控制行宽长度可以间接的引导开发去缩短函数、变量的命名,减少嵌套的层数,提升代码可读性。 -要求每行字符数不要超过 **120** 个;除非超过 **120** 能显著增加可读性,并且不会隐藏信息。 +强烈建议和要求每行字符数不要超过 **120** 个;除非超过 **120** 能显著增加可读性,并且不会隐藏信息。 虽然现代显示器分辨率已经很高,但是行宽过长,反而提高了阅读理解的难度;跟本规范提倡的“清晰”、“简洁”原则相背。 如下场景不宜换行,可以例外: @@ -346,14 +336,14 @@ enum BaseColor { ``` ## 缩进 -### 规则2.2 使用空格进行缩进,每次缩进4个空格 +### 规则2.1 使用空格进行缩进,每次缩进4个空格 只允许使用空格(space)进行缩进,每次缩进为 **4** 个空格。不允许使用Tab键进行缩进。 当前几乎所有的集成开发环境(IDE)和代码编辑器都支持配置将Tab键自动扩展为**4**空格输入,请配置你的代码编辑器支持使用空格进行缩进。 ## 大括号 -### 规则2.3 使用 K&R 缩进风格 +### 规则2.2 使用 K&R 缩进风格 **K&R风格** 换行时,函数左大括号另起一行放行首,并独占一行;其他左大括号跟随语句放行末。 @@ -377,7 +367,7 @@ int Foo(int a) ## 函数声明和定义 -### 规则2.4 函数声明、定义的返回类型和函数名在同一行;函数参数列表换行时应合理对齐 +### 规则2.3 函数声明、定义的返回类型和函数名在同一行;函数参数列表换行时应合理对齐 在声明和定义函数的时候,函数的返回值类型应该和函数名在同一行。 @@ -413,7 +403,7 @@ ReturnType ReallyReallyReallyReallyLongFunctionName( // 行宽不满 ## 函数调用 -### 规则2.5 函数调用参数列表换行时保持参数进行合理对齐 +### 规则2.4 函数调用参数列表换行时保持参数进行合理对齐 函数调用时,函数参数列表如果换行,应该进行合理的参数对齐。 左圆括号总是跟函数名,右圆括号总是跟最后一个参数。 @@ -442,7 +432,7 @@ int result = DealWithStructureLikeParams(left.x, left.y, // 表示一组相 ## 条件语句 -### 规则2.6 条件语句必须要使用大括号 +### 规则2.5 条件语句必须要使用大括号 我们要求条件语句都需要使用大括号,即便只有一条语句。 理由: @@ -456,7 +446,7 @@ if (objectIsNotExist) { // Good:单行条件语句也加大括号 } ``` -### 规则2.7 禁止 if/else/else if 写在同一行 +### 规则2.6 禁止 if/else/else if 写在同一行 条件语句中,若有多个分支,应该写在不同行。 @@ -476,7 +466,7 @@ if (someConditions) { ... } else { ... } // Bad: else 与 if 在同一行 ## 循环 -### 规则2.8 循环语句必须使用大括号 +### 规则2.7 循环语句必须使用大括号 和条件表达式类似,我们要求for/while循环语句必须加上大括号,即便循环体是空的,或循环语句只有一条。 ```c @@ -504,7 +494,7 @@ while (condition); // Bad:使用分号容易让人误解是while语句中 ## switch语句 -### 规则2.9 switch 语句的 case/default 要缩进一层 +### 规则2.8 switch 语句的 case/default 要缩进一层 switch 语句的缩进风格如下: ```c @@ -533,7 +523,7 @@ default: // Bad: default 未缩进 ## 表达式 -### 建议2.1 表达式换行要保持换行的一致性,操作符放行末 +### 建议2.2 表达式换行要保持换行的一致性,操作符放行末 较长的表达式,不满足行宽要求的时候,需要在适当的地方换行。一般在较低优先级操作符或连接符后面截断,操作符或连接符放在行末。 操作符、连接符放在行末,表示“未结束,后续还有”。 @@ -562,7 +552,7 @@ int sum = longVaribleName1 + longVaribleName2 + longVaribleName3 + ## 变量赋值 -### 规则2.10 多个变量定义和赋值语句不允许写在一行 +### 规则2.9 多个变量定义和赋值语句不允许写在一行 每行最好只有一个变量初始化的语句,更容易阅读和理解。 @@ -597,7 +587,7 @@ for (i = 0; i < row; i++) { 初始化包括结构体、联合体及数组的初始化 -### 规则2.11 初始化换行时要有缩进,或进行合理对齐 +### 规则2.10 初始化换行时要有缩进,或进行合理对齐 结构体或数组初始化时,如果换行应保持4空格缩进。 从可读性角度出发,选择换行点和对齐位置。 @@ -639,7 +629,7 @@ int c[][8] = { - 左大括号放行末时,对应的右大括号需另起一行 - 左大括号被内容跟随时,对应的右大括号也应跟随内容 -### 规则2.12 结构体和联合体在按成员初始化时,每个成员初始化单独一行 +### 规则2.11 结构体和联合体在按成员初始化时,每个成员初始化单独一行 C99标准支持结构体和联合体按照成员进行初始化,标准中叫"指定初始化"(designated initializer)。 如果按照这种方式进行初始化,每个成员的初始化单独一行。 ```c @@ -658,7 +648,7 @@ struct Date date = { // Good:使用指定初始化方式时,每行初始 ## 指针 -### 建议2.2 指针类型"\*"跟随变量名或者类型,不要两边都留有空格或都没有空格 +### 建议2.3 指针类型"\*"跟随变量名或者类型,不要两边都留有空格或都没有空格 声明或定义指针变量或者返回指针类型函数时,"\*" 靠左靠右都可以,但是不要两边都有或者都没有空格。 ```c @@ -686,14 +676,13 @@ int Foo(const char * restrict p); // OK. ## 编译预处理 -### 规则2.13 编译预处理的"#"默认放在行首,嵌套编译预处理语句时,"#"可以进行缩进 +### 规则2.12 编译预处理的"#"默认放在行首,嵌套编译预处理语句时,"#"可以进行缩进 -编译预处理的"#"统一放在行首;即便编译预处理的代码是嵌入在函数体中的,"#"也应该放在行首。 -注意,开发过程尽量不要使用编译预处理宏。如果需使用,则应由专人进行统一管理。 +编译预处理的"#"统一放在行首;即便编译预处理的代码是嵌入在函数体中的,"#"也应该放在行首。 ## 空格和空行 -### 规则2.14 水平空格应该突出关键字和重要信息,避免不必要的留白 +### 规则2.13 水平空格应该突出关键字和重要信息,避免不必要的留白 水平空格应该突出关键字和重要信息,每行代码尾部不要加空格。 总体规则如下: - if, switch, case, do, while, for 等关键字之后加空格; @@ -782,7 +771,7 @@ switch (var) { // Good: switch 关键字后面有1空格 注意:当前的集成开发环境(IDE)和代码编辑器都可以设置删除行尾的空格,请正确配置你的编辑器。 -### 建议2.3 合理安排空行,保持代码紧凑 +### 建议2.4 合理安排空行,保持代码紧凑 减少不必要的空行,可以显示更多的代码,方便代码阅读。下面有一些建议遵守的规则: - 根据上下内容的相关程度,合理安排空行; @@ -829,15 +818,9 @@ int Foo(void) **注释跟代码一样重要。** 写注释时要换位思考,用注释去表达此时读者真正需要的信息。在代码的功能、意图层次上进行注释,即注释解释代码难以表达的意图,不要重复代码信息。 -修改代码时,也要保证其相关注释的一致性。只改代码,不改注释是一种不文明行为,破坏了代码与注释的一致性,让阅读者迷惑、费解,甚至误解。 +修改代码时,也要保证其相关注释的一致性。只改代码,不改注释是一种不文明行为,破坏了代码与注释的一致性,让阅读者迷惑、费解,甚至误解。 -使用**英文**进行注释。 - -必须要加注释说明场合如下(包含但不限于列举的场合): -1、模块对外提供的接口头文件必须对函数进行注释。 -2、定义全局变量必须加注释。 -3、核心算法必须加注释。 -4、超过50行的函数必须加注释。 +使用英文进行注释。 ## 注释风格 @@ -1025,7 +1008,7 @@ switch (var) { ## 头文件职责 头文件是模块或文件的对外接口。 -头文件中适合放置接口的声明,不允许放置实现(内联函数除外)。 +头文件中适合放置接口的声明,不适合放置实现(内联函数除外)。 头文件应当职责单一。头文件过于复杂,依赖过于复杂还是导致编译时间过长的主要原因。 ### 建议4.1 每一个.c文件都应该有相应的.h文件,用于声明需要对外公开的接口 @@ -1101,17 +1084,17 @@ static void Bar(void) 为防止头文件被多重包含,所有头文件都应当使用 #define 作为包含保护;不要使用 #pragma once 定义包含保护符时,应该遵守如下规则: -- 保护符使用唯一名称;统一使用子系统名_部件名_文件名的定义规则。 +- 保护符使用唯一名称;建议考虑项目源代码树顶层以下的文件路径 - 不要在受保护部分的前后放置代码或者注释,文件头注释除外。 -假定 util 子系统 timer 部件的 timer.h,其目录为 `timer/include/timer.h`。其保护符若使用 'TIME_H' 很容易不唯一,按规则定义如: +假定 timer 模块的 timer.h,其目录为 `timer/include/timer.h`。其保护符若使用 'TIME_H' 很容易不唯一,所以使用项目源代码树的全路径,如: ```c -#ifndef UTIL_TIMER_TIMER_H -#define UTIL_TIMER_TIMER_H +#ifndef TIMER_INCLUDE_TIMER_H +#define TIMER_INCLUDE_TIMER_H ... -#endif // UTIL_TIMER_TIMER_H +#endif ``` ### 规则4.3 禁止通过声明的方式引用外部函数接口、变量 @@ -1308,20 +1291,9 @@ DealWithFileHead(fileHead, sizeof(fileHead)); // 处理文件头 使用返回值而不是输出参数,可以提高可读性,并且通常提供相同或更好的性能。 -函数名为 GetXxx、FindXxx、IsXxx、OnXxx或直接名词作函数名的函数,直接返回对应对象,可读性更好。 -例外: -1、多值返回时,可以设计为输出参数返回。 -2、涉及内存分配时,可以设计为输出参数返回。调用者将申请的内存做为出参传入,而函数内由不再分配内存。 - -### 建议5.3 设计函数的参数时,统一按输入、输出、出入的顺序定义参数。 +函数名为 GetXxx、FindXxx 或直接名词作函数名的函数,直接返回对应对象,可读性更好。 -函数参数的定义统一按输入参数、输出参数、出入参的顺序进行定义。 - -### 规则5.3 设计函数的资源时,涉及内存、锁、队列等资源分配的,需要同时提供释放函数。 - -本着资源从那儿申请,向那儿释放的原则。如果函数申请了内存、锁、队列等资源,则模块需要同时提供资源的函数。 - -### 建议5.4 使用强类型参数,避免使用void\* +### 建议5.3 使用强类型参数,避免使用void\* 尽管不同的语言对待强类型和弱类型有自己的观点,但是一般认为c/c++是强类型语言,既然我们使用的语言是强类型的,就应该保持这样的风格。 好处是尽量让编译器在编译阶段就检查出类型不匹配的问题。 @@ -1366,7 +1338,8 @@ void FooListAddNode(FooNode *foo) 例外:某些通用泛型接口,需要传入不同类型指针的,可以用 `void *` 入参。 -### 建议5.5 模块内部函数参数的合法性检查,由调用者负责 + +### 建议5.4 模块内部函数参数的合法性检查,由调用者负责 对于模块外部传入的参数,必须进行合法性检查,保护程序免遭非法输入数据的破坏。 模块内部函数调用,缺省由调用者负责保证参数的合法性,如果都由被调用者来检查参数合法性,可能会出现同一个参数,被检查多次,产生冗余代码,很不简洁。 diff --git a/website/docs/_posts/zh-cn/contribute/OpenHarmony-c-cpp-secure-coding-guide.md b/website/docs/_posts/zh-cn/contribute/OpenHarmony-c-cpp-secure-coding-guide.md index 9dcd957e5d794f6def3c50fd291cc359c60fa82c..313a9bee3dd6d791dff37d7d6ca905cac9e9bf25 100644 --- a/website/docs/_posts/zh-cn/contribute/OpenHarmony-c-cpp-secure-coding-guide.md +++ b/website/docs/_posts/zh-cn/contribute/OpenHarmony-c-cpp-secure-coding-guide.md @@ -1,15 +1,15 @@ --- -title: OpenHarmony-c-cpp-secure-coding-guide -permalink: /pages/extra/1f6576/ +title: OpenHarmony-c-cpp-secure-coding-guide.md +permalink: /pages/extra/e35557/ navbar: true sidebar: false prev: false next: false -search: true -article: true +search: false +article: false comment: false editLink: false -date: 2022-02-14 21:31:38 +date: 2021-12-30 12:57:47 --- # OpenHarmony C&C++ 安全编程指南 diff --git a/website/docs/_posts/zh-cn/contribute/OpenHarmony-cpp-coding-style-guide.md b/website/docs/_posts/zh-cn/contribute/OpenHarmony-cpp-coding-style-guide.md index ae9003325da3335b18ae0aadcea632f17c191791..667ebd122fd072c4a1bc1595a500d0995469224e 100644 --- a/website/docs/_posts/zh-cn/contribute/OpenHarmony-cpp-coding-style-guide.md +++ b/website/docs/_posts/zh-cn/contribute/OpenHarmony-cpp-coding-style-guide.md @@ -1,15 +1,15 @@ --- -title: OpenHarmony-cpp-coding-style-guide -permalink: /pages/extra/ca40b1/ +title: OpenHarmony-cpp-coding-style-guide.md +permalink: /pages/extra/350529/ navbar: true sidebar: false prev: false next: false -search: true -article: true +search: false +article: false comment: false editLink: false -date: 2022-02-14 21:31:38 +date: 2021-12-30 12:57:47 --- # C++语言编程规范 @@ -28,7 +28,7 @@ date: 2022-02-14 21:31:38 2. C++语言的模块化设计,如何设计头文件,类,接口和函数。 3. C++语言相关特性的优秀实践,比如常量,类型转换,资源管理,模板等。 4. 现代C++语言的优秀实践,包括C++11/14/17中可以提高代码可维护性,提高代码可靠性的相关约定。 -5. 本规范优先适于用C++17版本。 + ## 约定 **规则**:编程时必须遵守的约定(must) @@ -66,7 +66,7 @@ __驼峰风格(CamelCase)__ 上表中__变量__是指除常量定义以外的其他变量,均使用小驼峰风格。 ## 文件命名 -### 规则2.2.1 C++文件以.cpp结尾,头文件以.h结尾 +### 建议2.2.1 C++文件以.cpp结尾,头文件以.h结尾 我们推荐使用.h作为头文件的后缀,这样头文件可以直接兼容C和C++。 我们推荐使用.cpp作为实现文件的后缀,这样可以直接区分C++代码,而不是C代码。 @@ -79,7 +79,7 @@ __驼峰风格(CamelCase)__ 但是对于本文档,我们默认使用.h和.cpp作为后缀。 -### 规则2.2.2 C++文件名和类名保持一致 +### 建议2.2.2 C++文件名和类名保持一致 C++的头文件和cpp文件名和类名保持一致,使用下划线小写风格。 如果有一个类叫DatabaseConnection,那么对应的文件名: @@ -212,7 +212,7 @@ namespace Utils { ## 行宽 -### 规则3.1.1 行宽不超过 120 个字符 +### 建议3.1.1 行宽不超过 120 个字符 建议每行字符数不要超过 120 个。如果超过120个字符,请选择合理的方式进行换行。 例外: @@ -519,41 +519,6 @@ int&p = i; // Bad ### 规则3.13.1 编译预处理的"#"统一放在行首,嵌套编译预处理语句时,"#"可以进行缩进 编译预处理的"#"统一放在行首,即使编译预处理的代码是嵌入在函数体中的,"#"也应该放在行首。 -### 规则3.13.2 避免使用宏 -宏会忽略作用域,类型系统以及各种规则,容易引发问题。应尽量避免使用宏定义,如果必须使用宏,要保证证宏名的唯一性。 -在C++中,有许多方式来避免使用宏: -- 用const或enum定义易于理解的常量 -- 用namespace避免名字冲突 -- 用inline函数避免函数调用的开销 -- 用template函数来处理多种类型 -在文件头保护宏、条件编译、日志记录等必要场景中可以使用宏。 - -### 规则3.13.3 禁止使用宏来表示常量 -宏是简单的文本替换,在预处理阶段完成,运行报错时直接报相应的值;跟踪调试时也是显示值,而不是宏名; 宏没有类型检查,不宏全; 宏没有作用域。 - -### 规则3.13.4 禁止使用函数式宏 -宏义函数式宏前,应考虑能否用函数替代。对于可替代场景,建议用函数替代宏。 -函数式宏的缺点如下: -- 函数式宏缺乏类型检查,不如函数调用检查严格 -- 宏展开时宏参数不求值,可能会产生非预期结果 -- 宏没有独产的作用域 -- 宏的技巧性太强,例如#的用法和无处不在的括号,影响可读性 -- 在特定场景中必须用编译器对宏的扩展语法,如GCC的statement expression,影响可移植性 -- 宏在预编译阶段展开后,在期后编译、链接和调试时都不可见;而且包含多行的宏会展开为一行。函数式宏难以调试、难以打断点,不利于定位问题 -- 对于包含大量语句的宏,在每个调用点都要展开。如果调用点很多,会造成代码空间的膨胀 - -函数没有宏的上述缺点。但是,函数相比宏,最大的劣势是执行效率不高(增加函数调用的开销和编译器优化的难度)。 -为此,可以在必要时使用内联函数。内联函数跟宏类似,也是在调用点展开。不同之处在于内联函数是在编译时展开。 - -内联函数兼具函数和宏的优点: -- 内联函数执行严格的类型检查 -- 内联函数的参数求值只会进行一次 -- 内联函数就地展开,没有函数调用的开销 -- 内联函数比函数优化得更好 -对于性能要求高的产品代码,可以考虑用内联函数代替函数。 - -例外: -在日志记录场景中,需要通过函数式宏保持调用点的文件名(__FILE__)、行号(__LINE__)等信息。 ## 空格和空行 ### 规则3.14.1 水平空格应该突出关键字和重要信息,避免不必要的留白 @@ -600,10 +565,10 @@ x = r->y; // Good:通过->访问成员变量时不加空格 操作符: ```cpp -x = 0; // Good:赋值操作的=前后都要加空格 -x = -5; // Good:负数的符号和数值之前不要加空格 -++x; // Good:前置和后置的++/--和变量之间不要加空格 -x--; +x = 0; // Good:赋值操作的=前后都要加空格 +x = -5; // Good:负数的符号和数值之前不要加空格 +++x; // Good:前置和后置的++/--和变量之间不要加空格 +x--; if (x && !y) // Good:布尔操作符前后要加上空格,!操作和变量之间不要空格 v = w * x + y / z; // Good:二元操作符前后要加空格 @@ -828,11 +793,7 @@ MyClass::MyClass(int var) */ ## 函数头注释 -### 规则4.3.1 公有(public)函数必须编写函数头注释 -公有函数属于类对外提供的接口,调用者需要了解函数的功能、参数的取值范围、返回的结果、注意事项等信息才能正常使用。 -特别是参数的取值范围、返回的结果、注意事项等都无法做到自注示,需要编写函数头注释辅助说明。 - -### 规则4.3.2 禁止空有格式的函数头注释 +### 规则4.3.1 禁止空有格式的函数头注释 并不是所有的函数都需要函数头注释; 函数签名无法表达的信息,加函数头注释辅助说明; @@ -1427,30 +1388,7 @@ private: Foo& operator=(const Foo&); }; ``` -2. 使用C++11提供的delete, 请参见后面现代C++的相关章节。 - - -3. 推荐继承NoCopyable、NoMovable,禁止使用DISALLOW_COPY_AND_MOVE,DISALLOW_COPY,DISALLOW_MOVE等宏。 -```cpp -class Foo : public NoCopyable, public NoMovable { -}; -``` -NoCopyable和NoMovable的实现: -```cpp -class NoCopyable { -public: - NoCopyable() = default; - NoCopyable(const NoCopyable&) = delete; - NoCopyable& operator = (NoCopyable&) = delete; -}; - -class NoMovable { -public: - NoMovable() = default; - NoMovable(NoMovable&&) noexcept = delete; - NoMovable& operator = (NoMovable&&) noexcept = delete; -}; -``` +2. 使用C++11提供的delete, 请参见后面现代C++的相关章节。 ### 规则7.1.4 拷贝构造和拷贝赋值操作符应该是成对出现或者禁止 拷贝构造函数和拷贝赋值操作符都是具有拷贝语义的,应该同时出现或者禁止。 @@ -1537,40 +1475,10 @@ public: 会先执行Sub的构造函数,但首先调用Base的构造函数,由于Base的构造函数调用虚函数Log,此时Log还是基类的版本,只有基类构造完成后,才会完成派生类的构造,从而导致未实现多态的行为。 同样的道理也适用于析构函数。 -### 规则7.1.7 多态基类中的拷贝构造函数、拷贝赋值操作符、移动构造函数、移动赋值操作符必须为非public函数或者为delete函数 -如果报一个派生类对象直接赋值给基类对象,会发生切片,只拷贝或者移动了基类部分,损害了多态行为。 -【反例】 -如下代码中,基类没有定义拷贝构造函数或拷贝赋值操作符,编译器会自动生成这两个特殊成员函数, -如果派生类对象赋值给基类对象时就发生切片。可以将此例中的拷贝构造函数和拷贝赋值操作符声明为delete,编译器可检查出此类赋值行为。 -```cpp -class Base { -public: - Base() = default; - virtual ~Base() = default; - ... - virtual void Fun() { std::cout << "Base" << std::endl;} -}; - -class Derived : public Base { - ... - void Fun() override { std::cout << "Derived" << std::endl; } -}; - -void Foo(const Base &base) -{ - Base other = base; // 不符合:发生切片 - other.Fun(); // 调用的时Base类的Fun函数 -} -``` -```cpp -Derived d; -Foo(d); // 传入的是派生类对象 -``` -1. 将拷贝构造函数或者赋值操作符设置为private,并且不实现: ## 继承 -### 规则7.2.1 基类的析构函数应该声明为virtual,不准备被继承的类需要声明为final +### 规则7.2.1 基类的析构函数应该声明为virtual 说明:只有基类析构函数是virtual,通过多态调用的时候才能保证派生类的析构函数被调用。 示例:基类的析构函数没有声明为virtual导致了内存泄漏。 @@ -1629,8 +1537,7 @@ int main(int argc, char* args[]) } ``` 由于基类Base的析构函数没有声明为virtual,当对象被销毁时,只会调用基类的析构函数,不会调用派生类Sub的析构函数,导致内存泄漏。 -例外: -NoCopyable、NoMovable这种没有任何行为,仅仅用来做标识符的类,可以不定义虚析构也不定义final。 + ### 规则7.2.2 禁止虚函数使用缺省参数值 说明:在C++中,虚函数是动态绑定的,但函数的缺省参数却是在编译时就静态绑定的。这意味着你最终执行的函数是一个定义在派生类,但使用了基类中的缺省参数值的虚函数。为了避免虚函数重载时,因参数声明不一致给使用者带来的困惑和由此导致的问题,规定所有虚函数均不允许声明缺省参数值。 @@ -2383,24 +2290,19 @@ a2.push_back(Foo2()); // 触发容器扩张,搬移已有元素时调用move c **注意** 默认构造函数、析构函数、`swap`函数,`move操作符`都不应该抛出异常。 -## 模板与泛型编程 +## 模板 -### 规则9.8.1 禁止在OpenHarmony项目中进行泛型编程 -泛型编程和面向对象编程的思想、理念以及技巧完全不同,OpenHarmony项目主流使用面向对象的思想。 +模板能够实现非常灵活简洁的类型安全的接口,实现类型不同但是行为相同的代码复用。 -C++提供了强大的泛型编程的机制,能够实现非常灵活简洁的类型安全的接口,实现类型不同但是行为相同的代码复用。 +模板编程的缺点: -但是C++泛型编程存在以下缺点: +1. 模板编程所使用的技巧对于使用c++不是很熟练的人是比较晦涩难懂的。在复杂的地方使用模板的代码让人更不容易读懂,并且debug 和维护起来都很麻烦。 +2. 模板编程经常会导致编译出错的信息非常不友好: 在代码出错的时候, 即使这个接口非常的简单, 模板内部复杂的实现细节也会在出错信息显示. 导致这个编译出错信息看起来非常难以理解。 +3. 模板如果使用不当,会导致运行时代码过度膨胀。 +4. 模板代码难以修改和重构。模板的代码会在很多上下文里面扩展开来, 所以很难确认重构对所有的这些展开的代码有用。 -1. 对泛型编程不很熟练的人,常常会将面向对象的逻辑写成模板、将不依赖模板参数的成员写在模板中等等导致逻辑混乱代码膨胀诸多问题。 -2. 模板编程所使用的技巧对于使用c++不是很熟练的人是比较晦涩难懂的。在复杂的地方使用模板的代码让人更不容易读懂,并且debug 和维护起来都很麻烦。 -3. 模板编程经常会导致编译出错的信息非常不友好: 在代码出错的时候, 即使这个接口非常的简单, 模板内部复杂的实现细节也会在出错信息显示. 导致这个编译出错信息看起来非常难以理解。 -4. 模板如果使用不当,会导致运行时代码过度膨胀。 -5. 模板代码难以修改和重构。模板的代码会在很多上下文里面扩展开来, 所以很难确认重构对所有的这些展开的代码有用。 +所以, 建议__模板编程最好只用在少量的基础组件,基础数据结构上面__。并且使用模板编程的时候尽可能把__复杂度最小化__,尽量__不要让模板对外暴露__。最好只在实现里面使用模板, 然后给用户暴露的接口里面并不使用模板, 这样能提高你的接口的可读性。 并且你应该在这些使用模板的代码上写尽可能详细的注释。 -所以,OpenHarmony大部分部件禁止模板编程,仅有 __少数部件__ 可以使用泛型编程,并且开发的模板要有详细的注释。 -例外: -1. stl适配层可以使用模板 ## 宏 在C++语言中,我们强烈建议尽可能少使用复杂的宏 @@ -2664,55 +2566,34 @@ void func() ``` ## 智能指针 -### 规则10.2.1 单例、类的成员等所有机不会被多方持有的优先使用原始指针源而不是智能指针 +### 规则10.2.1 优先使用智能指针而不是原始指针管理资源 **理由** -智能指针会自动释放对象资源避免资源泄露,但会带额外的资源开销。如:智能指针自动生成的类、构造和析构的开销、内存占用多等。 - -单例、类的成员等对象的所有权不会被多方持有的情况,仅在类析构中释放资源即可。不应该使用智能指针而增额外的开销。 +避免资源泄露。 **示例** ```cpp -class Foo; -class Base { -public: - Base() {} - virtual ~Base() - { - delete foo_; +void Use(int i) +{ + auto p = new int {7}; // 不好: 通过 new 初始化局部指针 + auto q = std::make_unique(9); // 好: 保证释放内存 + if (i > 0) { + return; // 可能 return,导致内存泄露 } -private: - Foo* foo_ = nullptr; -}; + delete p; // 太晚了 +} ``` **例外** -1. 返回创建的对象时,需要指针销毁函数的可以使用智能指针。 -```cpp -class User; -class Foo { -public: - std::unique_ptr CreateUniqueUser() // 可使用unique_ptr保证对象的创建和释放在同一runtime - { - sptr ipcUser = iface_cast(remoter); - return std::unique_ptr(::new User(ipcUser), [](User *user) { - user->Close(); - ::delete user; - }); - } +在性能敏感、兼容性等场景可以使用原始指针。 - std::shared_ptr CreateSharedUser() // 可使用shared_ptr保证对象的创建和释放在同一runtime中 - { - sptr ipcUser = iface_cast(remoter); - return std::shared_ptr(ipcUser.GetRefPtr(), [ipcUser](User *user) mutable { - ipcUser = nullptr; - }); - } -}; -``` -2. 返回创建的对象且对象需要被多方引用时,可以使用shared_ptr。 +### 规则10.2.2 优先使用`unique_ptr`而不是`shared_ptr` +**理由** +1. `shared_ptr`引用计数的原子操作存在可测量的开销,大量使用`shared_ptr`影响性能。 +2. 共享所有权在某些情况(如循环依赖)可能导致对象永远得不到释放。 +3. 相比于谨慎设计所有权,共享所有权是一种诱人的替代方案,但它可能使系统变得混乱。 -### 规则10.2.2 使用`std::make_unique`而不是`new`创建`unique_ptr` +### 规则10.2.3 使用`std::make_unique`而不是`new`创建`unique_ptr` **理由** 1. `make_unique`提供了更简洁的创建方式 2. 保证了复杂表达式的异常安全 diff --git a/website/docs/_posts/zh-cn/contribute/OpenHarmony-hdf-coding-guide.md b/website/docs/_posts/zh-cn/contribute/OpenHarmony-hdf-coding-guide.md deleted file mode 100644 index 5bc21788c610076ed126d0f9c1141b7a27ea38dd..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/contribute/OpenHarmony-hdf-coding-guide.md +++ /dev/null @@ -1,648 +0,0 @@ ---- -title: OpenHarmony-hdf-coding-guide -permalink: /pages/extra/a7ae41/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# OpenHarmony HDF驱动编程规范 - -## 前言 - -### 目的 - -OpenHarmony的目标是面向全场景、全连接、全智能时代,基于开源的方式,搭建一个智能终端设备操作系统的框架和平台,促进万物互联产业的繁荣发展。具有“硬件互助,资源共享”、“一次开发,多端部署”、“统一OS,弹性部署”的技术特性。 - -HDF(Hardware Driver Foundation)驱动框架,为开发者提供驱动框架能力,包括驱动加载、驱动服务管理和驱动消息机制。旨在构建统一的驱动架构平台,为开发者提供更精准、更高效的开发环境,力求做到一次开发,多系统部署。 - -因此,对基于HDF实现的OpenHarmony驱动代码需要有一定的编程规约,以满足驱动代码的“一次开发,多端部署”技术特性。本文以此为初衷,结合OpenHarmony和HDF的特点,拟定了相关编程规约,用于指导驱动代码的开发编码,提升代码的规范性及可移植性,供开发者参考。 - -## 编程规范 - -### 总则 - -#### 【规则】OpenHarmony的驱动程序,应当使用HDF框架提供的能力实现 - -【说明】HDF驱动框架提供了驱动加载、驱动服务管理和驱动消息机制,同时还提供了操作系统抽象层(OSAL, Operating System Abstraction Layer)和平台抽象层(PAL, Platform Abstraction Layer)来保证驱动程序的跨系统跨平台部署的特性。除此之外,HDF提供了驱动模型的抽象、公共工具、外围器件框架等能力。开发者应该基于HDF提供的这些能力开发驱动,从而保证驱动程序可以在各种形态的OpenHarmony上进行部署。 - -#### 【规则】开发者应当遵循此规范要求,开发能够同时满足内核态和用户态的驱动 - -【说明】内核态驱动与用户态驱动天然存在着差异,两种形态适用的场景也不尽相同。开发者在业务设计和开发的时候应当遵循此规范,使用HDF提供的OSAL、PAL等特性来屏蔽形态的差异,来保证开发的驱动同时满足内核态和用户态。 - -#### 【建议】使用HDF框架时,编译脚本应当包含drivers/framework/include目录,而不是子模块目录 - -【说明】drivers/framework/include目录是HDF对外暴露的头文件根目录,此目录下面按照功能划分为核心框架、OSAL和PAL等多个子模块目录。在使用对应头文件时,建议编译脚本包含到drivers/framework/include目录,这样在代码中进行引用时,可以避免重复包含,也便于区分对应子模块,达到驱动范围内的统一。 - -【样例】 - -```gn -config("xxxx_private_config") { - include_dirs = [ - "//drivers/framework/include", - "//drivers/framework/include/core", # 不建议 - ] -} -``` - -```c -#include -#include // 不建议 -``` - -### HDF核心框架 - -#### 【规则】应当按照驱动入口对象HdfDriverEntry中的职责定义来实现Bind、Init和Release方法,避免职责不单一引入问题 - -【说明】HdfDriverEntry对象是HDF驱动的入口,其中的三个方法指针均有各自的职责,开发者需按照方法职责来实现对应函数。 - -```c -struct HdfDriverEntry g_sampleDriverEntry = { - .moduleVersion = 1, - .moduleName = "sample_driver", - .Bind = SampleDriverBind, // 职责:绑定驱动对外提供的服务接口到HDF - .Init = SampleDriverInit, // 职责:初始化驱动自身的业务 - .Release = SampleDriverRelease, // 职责:释放驱动资源,发生异常时也会调用 -}; - -HDF_INIT(g_sampleDriverEntry); -``` - -#### 【规则】驱动服务的结构定义,首个成员必须是IDeviceIoService类型 - -【说明】HDF框架内部实现约束,驱动定义的服务接口,首个成员必须是IDeviceIoService类型。 - -【样例】 - -```c -struct ISampleDriverService { - struct IDeviceIoService ioService; // 首个成员必须是IDeviceIoService类型 - int32_t (*FunctionA)(void); // 驱动的第一个服务接口 - int32_t (*FunctionB)(uint32_t inputCode); // 驱动的第二个服务接口,可以依次往下累加 -}; -``` - -【样例】 - -```c -struct ISampleDriverService { - struct IDeviceIoService ioService; // 首个成员必须是IDeviceIoService类型 - void *instance; // 也可以封装服务实例,在实例中提供服务接口 -}; -``` - -#### 【规则】在HdfDriverEntry的Bind方法中,必须完成全部驱动服务接口的绑定,禁止将服务接口未定义或定义为空 - -【说明】驱动定义的服务接口,均是对外暴露的,如果未定义或定义为空,可能会导致外部调用时产生异常,从而降低驱动的可靠性。 - -【样例】 - -```c -int32_t SampleDriverBind(struct HdfDeviceObject *deviceObject) -{ - static struct ISampleDriverService sampleDriver = { - .FunctionA = SampleDriverServiceA, - .FunctionB = NULL, // 禁止定义为空 - }; - // 将ioService与HDF创建的设备对象进行绑定 - deviceObject->service = &sampleDriver.ioService; - return HDF_SUCCESS; -} -``` - -#### 【建议】在HdfDriverEntry的Init方法中,应当调用HdfDeviceSetClass接口,对驱动的类型进行定义 - -【说明】驱动的类型可以用于归类当前设备的驱动程序,也可以用来查询当前设备的驱动能力。为了便于后续驱动的统一管理,建议通过HdfDeviceSetClass接口来设置当前驱动的类型。 - -【样例】 - -```c -int32_t SampleDriverInit(struct HdfDeviceObject *deviceObject) -{ - // 设置驱动的类型为DISPLAY - if (!HdfDeviceSetClass(deviceObject, DEVICE_CLASS_DISPLAY)) { - HDF_LOGE("HdfDeviceSetClass failed"); - return HDF_FAILURE; - } - return HDF_SUCCESS; -} -``` - -### HCS配置规范 - -HCS(HDF Configuration Source)是HDF驱动框架的配置描述源码,内容以Key-Value为主要形式。它实现了配置代码与驱动代码解耦,便于开发者进行配置管理。 - -驱动配置包含两部分,HDF框架定义的驱动设备描述和驱动的私有配置信息。 - -**设备描述信息** - -HDF框架加载驱动所需要的信息来源于HDF框架定义的驱动设备描述,因此基于HDF框架开发的驱动必须要在HDF框架定义的device_info.hcs配置文件中添加对应的设备描述。 - -#### 【规则】在进行驱动设备配置之前,应当明确驱动所属的硬件和部署形态,规划需要配置的目录和文件 - -【说明】在OpenHarmony源码的vendor目录下,按照芯片厂商、开发板、配置的目录进行规划,HDF驱动的配置位于hdf_config目录下。根据硬件规格,此hdf_config目录下存放内核态配置信息或者分别内核态和用户态的配置信息。开发者应当根据驱动所属的硬件和部署形态,确定在哪一个目录下进行配置。 - -【样例】 - -```bash -$openharmony_src_root/vendor/hisilicon/hispark_taurus/hdf_config # 内核态配置文件目录,无用户态 - -$openharmony_src_root/vendor/hisilicon/Hi3516DV300/hdf_config/khdf # 内核态配置文件目录 -$openharmony_src_root/vendor/hisilicon/Hi3516DV300/hdf_config/uhdf # 用户态配置文件目录 -$openharmony_src_root/vendor/hisilicon/Hi3516DV300/hdf_config/khdf/device_info/device_info.hcs # 内核态驱动设备描述配置文件 -$openharmony_src_root/vendor/hisilicon/Hi3516DV300/hdf_config/khdf/lcd/lcd_config.hcs # 内核态驱动私有配置文件 -``` - -#### 【规则】驱动设备在配置时,应当充分使用已有的配置信息,继承已有的配置模板 - -【说明】在HDF框架定义的device_info.hcs配置文件中,已经配置好了host、device和deviceNode的模板,开发者在配置驱动设备时,应该充分利用已有配置信息和HCS的继承特性,减少重复的配置工作量。 - -【样例】 - -``` -root { - device_info { - match_attr = "hdf_manager"; - template host { // host模板 - hostName = ""; - priority = 100; // host启动优先级(0-200),值越大优先级越低,建议默认配100,优先级相同则不保证host的加载顺序 - template device { // device模板 - template deviceNode { // deviceNode模板 - policy = 0; // policy字段是驱动服务发布的策略 - priority = 100; // 驱动启动优先级(0-200),值越大优先级越低,建议默认配100,优先级相同则不保证device的加载顺序 - preload = 0; // 驱动按需加载字段 - permission = 0664; // 驱动创建设备节点权限 - moduleName = ""; - serviceName = ""; - deviceMatchAttr = ""; - } - } - } - // 继承模板的节点如果使用模板中的默认值,则节点字段可以缺省 - sample_host :: host { // sample_host继承了host模板 - hostName = "host0"; // host名称,host节点是用来存放某一类驱动的容器 - device_sample :: device { // device_sample继承了device模板 - device0 :: deviceNode { // device0继承了deviceNode模板 - policy = 1; // 覆写了模板中的policy值 - moduleName = "sample_driver"; // 驱动名称,该字段的值必须和驱动入口结构的moduleName值一致 - serviceName = "sample_service"; // 驱动对外发布服务的名称,必须唯一 - deviceMatchAttr = "sample_config"; // 驱动私有数据匹配的关键字,必须和驱动私有数据配置表中的match_attr值相等 - } - } - } - } -} -``` - -#### 【规则】驱动模型的设计和归类应当满足业务需要和既定类型,禁止重复配置Host和Device - -【说明】HDF框架将一类设备驱动放在同一个Host里面,开发者也可以将Host中的驱动功能分层独立开发和部署,支持一个驱动多个Node,HDF驱动模型如下图所示: - -![HDF驱动模型.png](/images/device-dev/driver/figures/HDF驱动模型.png) - -开发者应当将同一类的设备放在同一个Host里面,在新增设备时,检查是否已经存在同类型的Host。如果已存在Host,则将Device配置在此Host中,禁止重复配置Host。一个驱动设备应该只属于一类驱动类型,因此也禁止将同一个Device配置在不同Host当中。 - -#### 【规则】驱动服务必须按照业务规则设置对外发布的策略,禁止设置不必要的发布策略 - -【说明】驱动服务是HDF驱动设备对外提供能力的对象,由HDF框架统一管理。HDF框架定义了驱动对外发布服务的策略,是由配置文件中的policy字段来控制,policy字段的取值范围以及含义如下: - -```c -typedef enum { - /* 驱动不提供服务 */ - SERVICE_POLICY_NONE = 0, - /* 驱动对内核态发布服务 */ - SERVICE_POLICY_PUBLIC = 1, - /* 驱动对内核态和用户态都发布服务 */ - SERVICE_POLICY_CAPACITY = 2, - /* 驱动服务不对外发布服务,但可以被订阅 */ - SERVICE_POLICY_FRIENDLY = 3, - /* 驱动私有服务不对外发布服务,也不能被订阅 */ - SERVICE_POLICY_PRIVATE = 4, - /* 错误的服务策略 */ - SERVICE_POLICY_INVALID -} ServicePolicy; -``` - -因此,驱动服务应该按照业务规则来设置发布策略,禁止设置不必要的发布策略,如内核态驱动设置用户态的发布策略。 - -【样例】 - -``` -root { - device_info { - sample_host { - sample_device { - device0 { - policy = 1; // 驱动对内核态发布服务 - ... - } - } - } - } -} -``` - -#### 【规则】驱动创建设备节点权限必须与驱动的发布规则互相匹配 - -【说明】在HDF框架定义的device_info.hcs配置文件中,permission为驱动创建的设备节点权限字段。该字段的取值使用Unix文件权限的八进制数字模式来表示,长度为4位,例如0644。permission字段仅在驱动服务对用户态发布服务时(即policy = 2)才会生效。 - -开发者应当保证驱动服务的发布策略与设备节点的权限互相匹配,否则可能会导致驱动服务无法访问或设备节点的权限被放大。 - -【样例】 - -``` -root { - device_info { - sample_host { - sample_device { - device0 { - policy = 2; // 驱动对内核态和用户态都发布服务 - permission = 0640; // 建议值 - ... - } - } - } - } -} -``` - -【反例】 - -``` -root { - device_info { - sample_host { - sample_device { - device0 { - policy = 2; // 驱动对内核态和用户态都发布服务 - permission = 0777; // 权限过大 - ... - } - } - } - } -} -``` - -【反例】 - -``` -root { - device_info { - sample_host { - sample_device { - device0 { - policy = 1; // 驱动对内核态发布服务,不会创建设备节点 - permission = 0640; // 冗余配置 - ... - } - } - } - } -} -``` - -#### 【规则】应当根据业务要求配置是否按需加载 - -【说明】在HDF框架定义的device_info.hcs配置文件中,preload为驱动按需加载字段,取值的范围见如下枚举: - -```c -typedef enum { - /* 系统启动时默认加载 */ - DEVICE_PRELOAD_ENABLE = 0, - /* 当系统支持快启时,则在快启完成后再加载;如果系统不支持快启,与DEVICE_PRELOAD_ENABLE含义相同 */ - DEVICE_PRELOAD_ENABLE_STEP2, - /* 系统启动时默认不加载,当使用时HDF框架会尝试动态加载 */ - DEVICE_PRELOAD_DISABLE, - /* 无效值 */ - DEVICE_PRELOAD_INVALID -} DevicePreload; -``` - -开发者应当根据驱动的业务要求,将preload字段配置为相应的值,从而HDF框架可以按照preload规则进行驱动的加载。 - -【样例】 - -``` -root { - device_info { - sample_host { - sample_device { - device0 { - preload = 2; // 使用时按需加载 - ... - } - } - } - } -} -``` - -#### 【建议】当preload字段配置为默认加载时,应当根据业务要求配置按序加载的优先级 - -【说明】在HDF框架定义的device_info.hcs配置文件中,priority字段(取值范围为整数0到200)是用来表示Host和驱动的优先级。不同的Host内的驱动,Host的priority值越小,驱动加载优先级越高;同一个Host内驱动的priority值越小,加载优先级越高。priority字段的默认值为100,当未配置或字段值相同时,HDF框架将不保证驱动的加载顺序。开发者应当根据业务场景的要求,配置priority字段,保证各个驱动的启动顺序。 - -【样例】 - -``` -root { - device_info { - sample_host0 { - priority = 100; - sample_device { - device0 { - preload = 0; // 默认加载 - priority = 100; // HDF保证在device1之前加载 - ... - } - device1 { - preload = 0; // 默认加载 - priority = 200; // HDF保证在device0之后加载 - ... - } - } - } - sample_host1 { - priority = 100; // 由于与sample_host0的优先级相同,HDF将不保证加载顺序 - ... - } - } -} -``` - -**驱动私有配置信息** - -如果驱动有私有配置,则可以添加一个驱动的配置文件,用来填写一些驱动的默认配置信息,HDF框架在加载驱动的时候,会将对应的配置信息获取并保存在HdfDeviceObject中的property里面,通过Bind和Init传递给驱动。 - -#### 【规则】驱动私有配置文件应当按照器件类型或者模块进行目录划分,并放置在相应的目录下 - -【说明】开发者应当对驱动的私有配置文件进行合理的目录规划,禁止将私有配置文件放置在配置的根目录下。 - -【样例】 - -```bash -$openharmony_src_root/vendor/hisilicon/Hi3516DV300/hdf_config/khdf/sample/sample_config.hcs # 正确,将私有配置文件放置在了sample目录下 - -$openharmony_src_root/vendor/hisilicon/Hi3516DV300/hdf_config/khdf/sample_config.hcs # 错误,将私有配置文件放置在了配置根目录下 -``` - -#### 【规则】应当将驱动私有配置文件包含到hdf_config配置目录下的hdf.hcs文件中 - -【说明】hdf.hcs文件是配置信息的汇总文件,在HDF编译和运行时,将会解析此文件中的内容,加载驱动的私有配置信息到驱动的设备节点中。开发者应当保证hdf.hcs文件中包含了驱动的私有配置文件,从而保证驱动能够正确初始化。 - -【样例】 - -```c -#include "device_info/device_info.hcs" -#include "sample/sample_config.hcs" // 包含驱动私有配置文件 - -root { - module = "hisilicon,hi35xx_chip"; -} -``` - -#### 【规则】驱动私有配置信息中的matchAttr字段值,必须与device_info.hcs中配置的deviceMatchAttr字段值一致 - -【说明】HDF框架会通过match_attr字段的值,来与驱动设备进行关联。如果配置错误,将导致私有配置信息无法获取。 - -【样例】 - -``` -root { - sample_config { - ... - match_attr = "sample_config"; // 该字段的值必须和device_info.hcs中的deviceMatchAttr值一致 - } -} -``` - -#### 【规则】驱动私有配置信息中的字段名,使用下划线命名法 - -【说明】由于C/C++语言编程指导的命名规则要求,驱动的私有配置信息中的字段名,应当使用下划线命名法。这样,在实现代码中对私有配置数据结构进行定义时,可以满足命名规则,也便于代码和配置文件的统一管理。 - -【样例】 - -``` -root { - sample_config { - sample_version = 1; // 使用下划线命名 - sample_bus = "I2C_0"; - match_attr = "sample_config"; - } -} -``` - -### HCS宏 - -驱动的私有配置信息会被加载到HdfDeviceObject中的property中,因此会占用一定的内存空间,这在轻量和小型系统中带来的缺点尤为明显。为了减少私有配置信息的内存占用,HDF框架提供了HCS宏,来解析驱动的私有配置信息。 - -#### 【规则】在内存敏感或跨系统类型的驱动场景下,应当使用HCS宏来解析驱动的私有配置信息 - -【说明】开发者应当明确驱动的使用场景,如果对内存敏感或者需要跨轻量、小型和标准系统使用,应当使用HCS宏来解析驱动的私有配置信息,从而保证驱动的性能和可移植性。 - -【样例】 - -```c -#include - -#define SAMPLE_CONFIG_NODE HCS_NODE(HCS_ROOT, sample_config) - -ASSERT_EQ(HCS_PROP(SAMPLE_CONFIG_NODE, sampleVersion), 1); -ASSERT_EQ(HCS_PROP(SAMPLE_CONFIG_NODE, sample_bus), "I2C_0"); -ASSERT_EQ(HCS_PROP(SAMPLE_CONFIG_NODE, match_attr), "sample_config"); -``` - -### HDF工具 - -#### 【规则】在使用HdfSbuf进行数据通信时,应当明确通信的场景,并根据相应场景确定创建的HdfSbuf类型 - -【说明】HdfSbuf是HDF进行数据传输时的数据结构,此结构根据通信的场景区分为不同的类型,定义在hdf_sbuf.h头文件的枚举中: - -```c -enum HdfSbufType { - SBUF_RAW = 0, /* SBUF used for communication between the user space and the kernel space */ - SBUF_IPC, /* SBUF used for inter-process communication (IPC) */ - SBUF_IPC_HW, /* Reserved for extension */ - SBUF_TYPE_MAX, /* Maximum value of the SBUF type */ -}; -``` - -开发者在进行数据通信时,应当明确是跨用户态和内核态通信场景,还是用户态的进程间通信,从而创建相应的HdfSbuf。 - -【样例】 - -```c -void SampleDispatchBetweenUserAndKernel() -{ - int32_t ret; - /* 跨用户态和内核态进行通信的场景 */ - struct HdfSBuf *data = HdfSBufTypedObtain(SBUF_RAW); - ... - ret = sample->dispatcher->Dispatch(&sample->object, CMD_SAMPLE_DISPATCH, data, NULL); - ... - HdfSBufRecycle(data); -} -``` - -【样例】 - -```c++ -void SampleDispatchIpc() -{ - /* 跨进程进行通信的场景 */ - struct HdfSBuf *data = HdfSBufTypedObtain(SBUF_IPC); - ... - int ret = sample->dispatcher->Dispatch(sample, CMD_SAMPLE_DISPATCH, data, nullptr); - ... - HdfSBufRecycle(data); -} -``` - -#### 【规则】在使用HDF的日志打印时,应当明确定义HDF_LOG_TAG日志打印的标签 - -【说明】HDF框架提供了一套日志打印工具hdf_log.h,开发者可以直接使用HDF的日志打印进行驱动运行日志的输出。HDF_LOG_TAG宏的作用是定义日志打印的标签,开发者必须在打印日志前进行定义。 - -【样例】 - -```c -#include - -#define HDF_LOG_TAG sample_driver // 定义日志的标签 - -int32_t SampleDriverInit(struct HdfDeviceObject *deviceObject) -{ - HDF_LOGI("sample driver is initialized"); // 使用HDF日志工具打印日志 - return HDF_SUCCESS; -} -``` - -#### 【规则】应当对HDF框架方法的返回值进行有效判断,并使用HDF提供的错误码 - -【说明】HDF框架提供的方法有明确的错误码返回值,开发者在使用时应当进行判断,而不是选择忽略。对应的返回值为hdf_base.h头文件中的错误码,开发者在使用HDF或实现自定义方法时,应当统一使用HDF提供的错误码。 - -【样例】 - -```c -int32_t SampleDriverInit(struct HdfDeviceObject *deviceObject) -{ - int32_t ret; - // 判断设备类型设置是否成功 - if (!HdfDeviceSetClass(deviceObject, DEVICE_CLASS_DISPLAY)) { - HDF_LOGE("HdfDeviceSetClass failed"); - return HDF_FAILURE; - } - ret = InitDiver(); - // 自定义方法使用HDF的错误码 - if (ret != HDF_SUCCESS) { - HDF_LOGE("init drvier is failed"); - return ret; - } - return HDF_SUCCESS; -} -``` - -### OSAL框架 - -HDF OSAL框架屏蔽了OpenHarmony各个系统类型之间的接口差异,对外提供统一的OS接口,包括内存管理、线程、互斥体、自旋锁、信号量、定时器、文件、中断、时间、原子、固件、I/O操作模块。 - -#### 【规则】跨轻量、小型和标准系统类型的驱动,必须通过OSAL框架来使用操作系统接口 - -【说明】OSAL屏蔽了OS接口之间的差异,开发者应当基于OSAL来操作OS的接口,保证驱动能够跨系统类型运行。 - -【样例】 - -```c -#include -#include - -struct DevHandle *SampleInit(void) -{ - struct DevHandle *handle = (struct DevHandle *)OsalMemCalloc(sizeof(struct DevHandle)); - if (handle == NULL) { - HDF_LOGE("OsalMemCalloc handle failed"); - return NULL; - } - return handle; -} -``` - -【样例】 - -```c -#include - -void SampleSleep(uint32_t timeMs) -{ - OsalMSleep(timeMs); -} -``` - -### PAL框架 - -HDF PAL框架对平台类驱动进行了抽象,并对外提供统一的操作接口,包括GPIO、I2C、SPI、UART、RTC、SDIO、EMMC、DSI、PWM、WATCHDOG等模块。 - -#### 【规则】跨轻量、小型和标准系统类型的驱动,必须通过PAL框架来使用平台驱动 - -【说明】PAL屏蔽了不同系统类型之间的平台驱动接口差异,开发者应当基于PAL来操作这些接口,保证驱动能够跨系统类型运行。 - -【样例】 - -```c -#include -#include -#include -#include - -static uint32_t g_irqCnt; - -/* GPIO中断服务样例函数 */ -static int32_t SampleGpioIrqHandler(uint16_t gpio, void *data) -{ - HDF_LOGE("%s: irq triggered, on gpio:%u, data=%p", __func__, gpio, data); - g_irqCnt++; // 如果中断服务函数触发执行,则将全局中断计数加1 - return GpioDisableIrq(gpio); -} - -/* GPIO样例函数 */ -static int32_t SampleGpioIrqEdge(void) -{ - int32_t ret; - uint16_t valRead; - uint16_t mode; - uint16_t gpio = 83; // 待测试的GPIO管脚号 - uint32_t timeout; - - /* 将管脚方向设置为输出 */ - ret = GpioSetDir(gpio, GPIO_DIR_OUT); - ... - /* 禁止该管脚中断 */ - ret = GpioDisableIrq(gpio); - ... - /* 为管脚设置中断服务函数,触发模式为上升沿和下降沿共同触发 */ - mode = OSAL_IRQF_TRIGGER_RISING | OSAL_IRQF_TRIGGER_FALLING; - ret = GpioSetIrq(gpio, mode, SampleGpioIrqHandler, NULL); - ... - /* 使能此管脚中断 */ - ret = GpioEnableIrq(gpio); - ... - g_irqCnt = 0; // 清除全局计数器 - timeout = 0; // 等待时间清零 - /* 等待此管脚中断服务函数触发,等待超时时间为1000毫秒 */ - while (g_irqCnt <= 0 && timeout < 1000) { - ret = GpioRead(gpio, &valRead); - ... - ret = GpioWrite(gpio, (valRead == GPIO_VAL_LOW) ? GPIO_VAL_HIGH : GPIO_VAL_LOW); - ... - OsalMDelay(200); // 等待中断触发 - timeout += 200; - } - ret = GpioUnSetIrq(gpio); - ... - return (g_irqCnt > 0) ? HDF_SUCCESS : HDF_FAILURE; -} -``` diff --git a/website/docs/_posts/zh-cn/contribute/OpenHarmony-security-design-guide.md b/website/docs/_posts/zh-cn/contribute/OpenHarmony-security-design-guide.md index 9755953d9079d4d66242aec8c3bd53535c5c27ea..4b6934f0a3545fe6372ad829d394c265cac25e36 100644 --- a/website/docs/_posts/zh-cn/contribute/OpenHarmony-security-design-guide.md +++ b/website/docs/_posts/zh-cn/contribute/OpenHarmony-security-design-guide.md @@ -1,15 +1,15 @@ --- -title: OpenHarmony-security-design-guide -permalink: /pages/extra/aec558/ +title: OpenHarmony-security-design-guide.md +permalink: /pages/extra/2cc67e/ navbar: true sidebar: false prev: false next: false -search: true -article: true +search: false +article: false comment: false editLink: false -date: 2022-02-14 21:31:38 +date: 2021-12-30 12:57:47 --- # OpenHarmony安全设计规范 diff --git a/website/docs/_posts/zh-cn/contribute/Readme-CN.md b/website/docs/_posts/zh-cn/contribute/Readme-CN.md deleted file mode 100644 index bfc6dea96947296d4c5a4fdbc6a52684e1a27890..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/contribute/Readme-CN.md +++ /dev/null @@ -1,25 +0,0 @@ ---- -title: Readme-CN -permalink: /pages/extra/22d122/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 贡献指南 - -- [参与贡献](/pages/010d01) -- [行为准则](/pages/010d02) -- [贡献代码](/pages/010d03) -- [贡献流程](/pages/010d04) -- [自测试验证](/pages/01010218) -- [贡献文档](/pages/extra/7f2552/) -- [写作规范](/pages/010d0501) -- [社区沟通与交流](/pages/010d06) -- [FAQ](/pages/010d07) - diff --git a/website/docs/_posts/zh-cn/contribute/docs-reviewers.md b/website/docs/_posts/zh-cn/contribute/docs-reviewers.md deleted file mode 100644 index c9d7fc6f15b6220bbebafda4ed62422e29761583..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/contribute/docs-reviewers.md +++ /dev/null @@ -1,48 +0,0 @@ ---- -title: docs-reviewers -permalink: /pages/extra/401d0b/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 开发者文档评审人 - -## 文档规范评审人 -### 设备开发相关文档评审人 - -| Feature | Docs Reviewers | -| ------------ | ------------------------------------------------------------ | -| 快速入门 | [@duangavin123](https://gitee.com/duangavin123) | -| 获取源码 | [@duangavin123](https://gitee.com/duangavin123) | -| 内核 | [@Austin23](https://gitee.com/Austin23) | -| 驱动 | [@Qianchenya](https://gitee.com/Qianchenya) | -| 设备开发指南 | [@Austin23](https://gitee.com/Austin23) | -| 移植适配 | [@Austin23](https://gitee.com/Austin23) | -| Bundle开发 | [@Qianchenya](https://gitee.com/Qianchenya) | -| 隐私与安全 | [@Qianchenya](https://gitee.com/Qianchenya) | -| 子系统 | [@Qianchenya](https://gitee.com/Qianchenya) | -| 导读 | [@zengyawen](https://gitee.com/zengyawen) | -| 术语 | [@bj9854](https://gitee.com/bj9854) | -| 社区公共文档 | [@neeen](https://gitee.com/neeen) [@yan-tingting666](https://gitee.com/yan-tingting666) | - -### 应用开发相关文档评审人 - -| Feature | Docs Reviewers | -| ------------ | ----------------------------------------- | -| JS参考规范 | [@zengyawen](https://gitee.com/zengyawen) | -| 媒体 | [@zengyawen](https://gitee.com/zengyawen) | -| 快速入门 | [@ge-yafang](https://gitee.com/ge-yafang) | -| UI | [@ge-yafang](https://gitee.com/ge-yafang) | -| 应用开发导读 | [@zengyawen](https://gitee.com/zengyawen) | -| 网络与连接 | [@RayShih](https://gitee.com/RayShih) | - -## 技术正确性评审人---待补充 - - - diff --git a/website/docs/_posts/zh-cn/contribute/faq-template.md b/website/docs/_posts/zh-cn/contribute/faq-template.md new file mode 100644 index 0000000000000000000000000000000000000000..dc51135ebd8629e92c6df04b6a6390e992094df5 --- /dev/null +++ b/website/docs/_posts/zh-cn/contribute/faq-template.md @@ -0,0 +1,49 @@ +--- +title: faq-template.md +permalink: /pages/extra/95f10b/ +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +date: 2021-12-30 12:57:47 +--- +# FAQ:标题(简要描述问题关键信息) + +FAQ页面介绍开发过程中遇到的各类问题及解决方法,帮助更多开发者快速消除此类开发障碍。 + +## 简单类问题写作模板 + +简要描述在完成哪些操作时,遇到的问题现象,以及解决方法。 + +## 复杂类问题写作模板 + +**现象描述** + +- 使用的系统软件、硬件版本? +- 在完成哪些操作时,遇到了什么样的问题? + +- 可能显示什么错误消息? + +- 如果可能,请提供屏幕截图。 + + +**可能原因** + +分析哪些原因导致此问题,如果有多个原因,请使用项目列表一一列举。 + +1. XXX +2. XXX + +**处理步骤** + +- 如果有多个解决方案,请按照复杂性排序,并提供什么场景下选择哪种解决方案。 +- 如果可能,请提供屏幕截图,帮助理解步骤完成标准。 +- 代码如有打印输出,请提示打印输出内容_,帮助理解步骤完成标准_。 + +1. XXX +2. XXX + diff --git a/website/docs/_posts/zh-cn/contribute/template/concept-overview-template.md b/website/docs/_posts/zh-cn/contribute/template/concept-overview-template.md deleted file mode 100644 index af862dab08999dd98356925ed909334503b01af4..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/contribute/template/concept-overview-template.md +++ /dev/null @@ -1,124 +0,0 @@ ---- -title: concept-overview-template -permalink: /pages/extra/55ebd1/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 概述 - -## 基本概念 - -*【 **写作要求】*** - -*必选,描述本开发任务相关的基本概念,帮助开发者更好的理解开发任务。* *写作要求见下,完成写作后,请逐项自检。* - -| 内容要求 | 是否满足 | -| -------- | -------- | -| 业界通用的概念不用赘述。 | | -| 注意使用业界通用术语来表达,不用开发者无法理解的内部语言。 | | - - -【写作样例】 - - -XX系统音频模块支持音频业务的开发,提供音频相关的功能,主要包括音频播放、音频采集、音量管理和短音播放等。 - - -在进行应用的开发前,开发者应了解以下基本概念: - - -- 采样 - 采样就是把模拟信号数字化的过程,所有的模拟信号都需要通过采样转换为可以用0101来表示的数字信号。 - -- 采样率 - 采样率为每秒从连续信号中提取并组成离散信号的采样次数,单位用赫兹(Hz)来表示。通常人耳能听到频率范围大约在20Hz~20kHz之间的声音。常用的音频采样频率有:8kHz、11.025kHz、22.05kHz、16kHz、37.8kHz、44.1kHz、48kHz、96kHz、192kHz等。 - -- 声道 - 声道是指声音在录制或播放时在不同空间位置采集或回放的相互独立的音频信号,所以声道数也就是声音录制时的音源数量或回放时相应的扬声器数量。 - -- 音频帧 - 音频数据是流式的,本身没有明确的一帧帧的概念,在实际的应用中,为了音频算法处理/传输的方便,一般约定俗成取2.5ms~60ms为单位的数据量为一帧音频。这个时间被称之为“采样时间”,其长度没有特别的标准,它是根据编解码器和具体应用的需求来决定的。 - - -## 运作机制 - -*【 **写作要求】*** - -*可选。如果机制比较简单,通过前面基本概念就可以说清楚,此章节可以不用提供,删除标题即可。* - -*描述实现原理介绍机制,如关键步骤相关接口调用时机和触发时机,帮助开发者了解该功能的基本运作原理,以便更好的理解开发任务和定位问题。* - -* 写作要求见下,完成写作后,请逐项自检。* - -| 内容要求 | 是否满足 | -| -------- | -------- | -| 仅描述开发任务相关的原理。 | | -| 尽量图文配合,一般使用时序图、流程图等形式。文字描述与图形描述匹配。 | | - -【写作样例-1】 - -- 信号量初始化,为配置的N个信号量申请内存(N值可以由用户自行配置,受内存限制),并把所有的信号量初始化成未使用,并加入到未使用链表中供系统使用。 - -- 信号量创建,从未使用的信号量链表中获取一个信号量资源,并设定初值。 - -- 信号量申请,若其计数器值大于0,则直接减1返回成功。否则任务阻塞,等待其它任务释放该信号量,等待的超时时间可设定。当任务被一个信号量阻塞时,将该任务挂到信号量等待任务队列的队尾。 - -- 信号量释放,若没有任务等待该信号量,则直接将计数器加1返回。否则唤醒该信号量等待任务队列上的第一个任务。 - -- 信号量删除,将正在使用的信号量置为未使用信号量,并挂回到未使用链表。 - -- 信号量允许多个任务在同一时刻访问同一资源,但会限制同一时刻访问此资源的最大任务数目。访问同一资源的任务数达到该资源的最大数量时,会阻塞其他试图获取该资源的任务,直到有任务释放该信号量。 - - -【写作样例-2】 - -**互斥锁运作原理** - -多任务环境下会存在多个任务访问同一公共资源的场景,而有些公共资源是非共享的,需要任务进行独占式处理。互斥锁怎样来避免这种冲突呢? - -用互斥锁处理非共享资源的同步访问时,如果有任务访问该资源,则互斥锁为加锁状态。此时其他任务如果想访问这个公共资源则会被阻塞,直到互斥锁被持有该锁的任务释放后,其他任务才能重新访问该公共资源,此时互斥锁再次上锁,如此确保同一时刻只有一个任务正在访问这个公共资源,保证了公共资源操作的完整性。 - - - -## 约束与限制 - -【写作要求】 - -*必选。* *描述本开发任务过程中* *的约束条件,以及此操作约束带来相应的负面影响,包括但不限于如下几方面:* - -- **功能限制**: - - 功能使用范围(明确不支持的场景)。 - - 规格限制。 - -* **操作限制**: - - * 已知问题的操作。 - * 潜在风险的操作(如引起性能降低)。 - * 引起性能降低的操作。 - -写作要求见下,完成写作后,请逐项自检。 - -| 内容要求 | 是否满足 | -| -------- | -------- | -| 明确功能限制或操作限制。 | | -| 约束对指导任务开发有影响或体验有感知,否则不用体现。 | | -| 容易出错的操作在步骤里描述,不在此体现。 | | - -**【写作样例】** - -**互斥锁的约束与限制:** - -- 两个任务不能对同一把互斥锁加锁。如果某任务对已被持有的互斥锁加锁,则该任务会被挂起,直到持有该锁的任务对互斥锁解锁,才能执行对这把互斥锁的加锁操作。 - -- 互斥锁不能在中断服务程序中使用。 - -- XXX作为实时操作系统需要保证任务调度的实时性,尽量避免任务的长时间阻塞,因此在获得互斥锁之后,应该尽快释放互斥锁。 - -- 持有互斥锁的过程中,不得再调用LOS_TaskPriSet等接口更改持有互斥锁任务的优先级。 diff --git a/website/docs/_posts/zh-cn/contribute/template/faq-template.md b/website/docs/_posts/zh-cn/contribute/template/faq-template.md deleted file mode 100644 index c1099f2f5982d12836657ab881a007c9ce2e8b98..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/contribute/template/faq-template.md +++ /dev/null @@ -1,49 +0,0 @@ ---- -title: faq-template -permalink: /pages/extra/7eb1bd/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# FAQ:标题(简要描述问题关键信息) - -FAQ页面介绍开发过程中遇到的各类问题及解决方法,帮助更多开发者快速消除此类开发障碍。 - -## 简单类问题写作模板 - -简要描述在完成哪些操作时,遇到的问题现象,以及解决方法。 - -## 复杂类问题写作模板 - -**现象描述** - -- 使用的系统软件、硬件版本? -- 在完成哪些操作时,遇到了什么样的问题? - -- 可能显示什么错误消息? - -- 如果可能,请提供屏幕截图。 - - -**可能原因** - -分析哪些原因导致此问题,如果有多个原因,请使用项目列表一一列举。 - -1. XXX -2. XXX - -**处理步骤** - -- 如果有多个解决方案,请按照复杂性排序,并提供什么场景下选择哪种解决方案。 -- 如果可能,请提供屏幕截图,帮助理解步骤完成标准。 -- 代码如有打印输出,请提示打印输出内容_,帮助理解步骤完成标准_。 - -1. XXX -2. XXX - diff --git a/website/docs/_posts/zh-cn/contribute/template/guide-template.md b/website/docs/_posts/zh-cn/contribute/template/guide-template.md deleted file mode 100644 index 5a6db4c5fd578c83ad657f6b583294b18514ada7..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/contribute/template/guide-template.md +++ /dev/null @@ -1,139 +0,0 @@ ---- -title: guide-template -permalink: /pages/extra/bdb58b/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 开发指导 - -** *【写作要求】*** - - -*必选。* *描述各个场景下,开发者如何完成开发任务。* *可根据多场景任务增加章节。写作要求见下,完成写作后,请逐项自检。* - - -| 内容要求 | 是否满足 | -| -------- | -------- | -| 如果有多个场景,请写起多个“开发指导”章节,如音频播放开发指导、音量管理开发指导、短音播放开发指导。 | | -| 标题尽量使用“动词+名词”的句式表述任务操作。 | | - - -## 场景介绍 - -** *【写作要求】*** - -*必选。* *描述在什么情景下解决什么问题,最终达到什么样的效果。*应用SCQA描述方法: - -- S:situation(情景),由大家都熟悉的的情景,事实引入。 - -- C:complication(冲突),但是实际情况往往和我们的要求有冲突。 - -- Q:question(疑问),怎么办? - -- A:answer(回答),我们的解决方案是 … - -*写作要求见下,完成写作后,请逐项自检。* - -| 内容要求 | 是否满足 | -| -------- | -------- | -| 背景原因、什么时候在哪、做了什么操作、最终解决什么问题或操作效果都明确。 | | - -**【写作样例】** - -音频播放的主要工作是将音频数据转码为可听见的音频模拟信号并通过输出设备进行播放,同时对播放任务进行管理。 - - -## 接口说明 - -** *【写作要求】*** - -*必选。* *描述本开发指导相关的接口有哪些,旨在要开发者在开发前有大体了解,提升开发效率。* *写作要求见下,完成写作后,请逐项自检。* - -| 内容要求 | 是否满足 | -| -------- | -------- | -| 不在本开发任务的接口无需提供。 | | -| 如果接口太多,超过10个,可以提供主要的接口 | | - -**【写作样例】** - -音频播放开放能力如下:AudioRenderer类,具体的API详见接口文档。 - -**表1** 音频播放API接口功能介绍 - -| 接口名 | 描述 | -| -------- | -------- | -| AudioRenderer(AudioRendererInfo audioRendererInfo, PlayMode pm) throws IllegalArgumentException | 构造函数,设置播放相关音频参数和播放模式,使用默认播放设备 | -| AudioRenderer(AudioRendererInfo audioRendererInfo, PlayMode pm, AudioDeviceDescriptor outputDevice) throws IllegalArgumentException | 构造函数,设置播放相关音频参数、播放模式和播放设备 | -| boolean play() | 播放音频流 | -| boolean write(byte[] data, int offset, int size) | 将音频数据以byte流写入音频接收器以进行播放 | - - -## 开发步骤 - -** *【写作要求】*** - - * 必选。描述* *开发的整体过程,便于开发者快速完成开发。* * 具体 写作要求见下,完成写作后,请逐项自检下。* -| 内容要求 | 是否满足 | -| -------- | -------- | -| **如何写好步骤** | | -| 步骤完整:提供必须的步骤,顺利指导完成操作,无缺失。 | | -| 脉络清楚:文档逻辑清晰、合理。文档前面的概述、准备、操作围绕一条线描述,不能章节断裂或前后矛盾的现象。 | | -| 任务句式:标题或句子尽量使用“动词+名词”的句式表述动作。 | | -| 预防提前:操作过程中的限制、易错的、有潜在风险的,要提前描述,使用DOCS平台的“插入> 说明 > 须知”描述。 | | -| 步骤清晰-1:无论步骤简单或复杂,都需要写步骤目的,即为什么做。 | | -| 步骤清晰-2:明确在什么环境下,使用什么工具,做什么操作,怎么做该操作。 | | -| 步骤具体:如果操作可选,要明确可选条件。 | | -| 在开发步骤执行完成后,及时明确操作正确的标准。 | | -| **如何写好代码段** | | -| 代码涉及开发者拷贝的命令,必须用可编辑的报文呈现,避免截图,使用代码片段包裹。 | | -| 代码中关键段用蓝色(RGB:0.0.255)突出显示,关键步骤要有注释说明。 | | -| 代码显示符合代码缩进要求。 | | -| 步骤涉及接口调用,清晰给出接口及其使用说明或示例代码,代码来源于具体实例。 | | - -**【写作样例】** - -1. 构造音频流参数的数据结构AudioStreamInfo,推荐使用AudioStreamInfo.Builder类来构造,模板如下,模板中设置的均为AudioStreamInfo.Builder类的默认值,根据音频流的具体规格来设置具体参数。 - ``` - AudioStreamInfo audioStreamInfo = new AudioStreamInfo.Builder().sampleRate( AudioStreamInfo.SAMPLE_RATE_UNSPECIFIED) .audioStreamFlag(AudioStreamInfo.AudioStreamFlag.AUDIO_STREAM_FLAG_NONE) .encodingFormat(AudioStreamInfo.EncodingFormat.ENCODING_INVALID) .channelMask(AudioStreamInfo.ChannelMask.CHANNEL_INVALID) .streamUsage(AudioStreamInfo.StreamUsage.STREAM_USAGE_UNKNOWN) .build(); - ``` - - 以真实的播放pcm流为例: - ``` - AudioStreamInfo audioStreamInfo = new AudioStreamInfo.Builder().sampleRate(44100)//44.1kHz .audioStreamFlag(AudioStreamInfo.AudioStreamFlag.AUDIO_STREAM_FLAG_MAY_DUCK)//混音 .encodingFormat(AudioStreamInfo.EncodingFormat.ENCODING_PCM_16BIT)//16-bit PCM .channelMask(AudioStreamInfo.ChannelMask.CHANNEL_OUT_STEREO)//双声道 .streamUsage(AudioStreamInfo.StreamUsage.STREAM_USAGE_MEDIA)//媒体类音频 .build(); - ``` - -2. 使用步骤1创建的音频流构建音频播放的参数结构AudioRendererInfo,推荐使用AudioRendererInfo.Builder类来构造,模板如下,模板中设置的均为AudioRendererInfo.Builder类的默认值,根据音频播放的具体规格来设置具体参数。 - ``` - AudioRendererInfo audioRendererInfo = new AudioRendererInfo.Builder().audioStreamInfo(audioStreamInfo) .audioStreamOutputFlag(AudioRendererInfo.AudioStreamOutputFlag.AUDIO_STREAM_OUTPUT_FLAG_NONE) .bufferSizeInBytes(0) .distributedDeviceId("") .isOffload(false) .sessionID(AudioRendererInfo.SESSION_ID_UNSPECIFIED) .build(); - ``` - - 以真实的播放pcm流为例: - ``` - AudioRendererInfo audioRendererInfo = new AudioRendererInfo.Builder().audioStreamInfo(audioStreamInfo) .audioStreamOutputFlag(AudioRendererInfo.AudioStreamOutputFlag.AUDIO_STREAM_OUTPUT_FLAG_DIRECT_PCM)//pcm格式的输出流 .bufferSizeInBytes(100) .distributedDeviceId("E54***5E8")//使用分布式设备E54***5E8播放 .isOffload(false)//false表示分段传输buffer并播放,true表示整个音频流一次性传输到HAL层播放 .build(); - ``` - -3. 根据要播放音频流指定PlayMode,不同的PlayMode在写数据时存在差异,详情见步骤7,其余播放流程是无区别的。并通过构造函数获取AudioRenderer类的实例化对象。 - .... - -4. 播放任务结束后,调用AudioRenderer实例化对象的release()释放资源。 - - -## 调测验证(可选) - -** *【写作要求】*** - -*可选。* *描述开发完成后,进行调测验证,确保最终操作成功。* *操作步骤要求同“开发指导”,其他具体写作要求见下,完成写作后,请逐项自检下。* - -| 内容要求 | 是否满足 | -| -------- | -------- | -| 仅进行最后的业务调测,每个小任务的操作结果,在开发步骤执行完成后,及时验证操作结果。 | | -| 明确开发成功标准。 | | - - diff --git a/website/docs/_posts/zh-cn/contribute/template/js-template.md b/website/docs/_posts/zh-cn/contribute/template/js-template.md deleted file mode 100644 index ff2ba854389730d1bf47b229f64f8254c7ba2ff2..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/contribute/template/js-template.md +++ /dev/null @@ -1,250 +0,0 @@ ---- -title: js-template -permalink: /pages/extra/887244/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# API接口说明模板 - -> *写作说明* -> -> 0.1 - 所有的写作说明,在完成写作后,都要删除。 -> -> 0.2 - 上传路径:docs/zh-cn/application-dev/reference/apis,图片放到对应的figures文件夹中。上传后可通过提issue的方式,触发翻译。 -> -> 0.3 - 一个d.ts文件对应一个js api接口文档。**文件名称:js-apis-模块名.md**。示例: -> -> ​ 媒体@ohos.multimedia.audio,文件命名为:js-apis-audio.md -> -> ​ 电话@ohos.telephony.sms,文件命名为:js-apis-sms.md -> -> 0.4 - 新增文件,需要修改对应的Readme,即docs/zh-cn/application-dev/reference/apis/Readme-CN.md。 -> -> 0.5 - **文档标题**:使用中文短语概括本模块功能。但如果部分概念使用英文更便于开发者理解,不必强求,比方说,Ability、SIM卡等概念可以直接使用。 -> -> 0.6 - 文档标题为一级标题;namespace下的属性字段、function、class、interface、enum、type为二级标题;class下的属性、function为三级标题。 -> -> 0.7 - **对已有模块的新增接口标记起始版本:使用\标签,标记对应的版本号。** -> -> ​ 示例:API 6已有的模块,在API 7新增了一个属性字段,则在属性后加标记,即newAttribute7+。 -> -> ​ 如果新增了一个方法,则在方法标题后增加标记,即 sim.getSimIccId7+,interface、class、枚举等同理。 -> -> 0.8 - **废弃内容**:不能直接在文档上删去,在废弃内容后面加上标标注deprecated,并使用“>”引用语法建议使用的替代方式,加上对应的链接。 -> -> ​ 示例:abandonmentMethod(deprecated) -> -> > 从API Version 7 开始废弃,建议使用[newMethod](#newMethod)替代。 -> -> 下面进入具体每个API的写作。 - -*** -> *写作说明* -> -> 1.1 - 使用markdown的引用语法“>”对接口的起始版本进行说明。 -> -> 1.2 - 一个模块只会有一个起始版本。 -> -> 1.3 - 采用标准句式:“本模块首批接口从API version x开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。”x需要修改为对应的版本号。 -> - -> **说明** -> -> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - -模块说明。此处对该模块提供的功能、使用场景和使用建议进行简要描述。 - -## 导入模块 -> *写作说明* -> -> 2.1 - 根据实际情况填写导入模块。采用代码段的样式,给出import语句。 -> -> 2.2 - 如果没有导入模块,将“导入模块”修改为“使用说明”。 -> -> ​ 使用说明案例: -> - -> ```js -> import ability_featureAbility from '@ohos.ability.featureAbility'; -> var context = ability_featureAbility.getContext(); -> ``` - -```js -import call from '@ohos.telephony.call'; -``` -## 系统能力 -> *写作说明* -> -> 3.1 - 必选。 -> -示例:SystemCapability.BundleManager.BundleFramework - -## 属性 - -> *写作说明* -> -> 4.1 - 可选,如果没有属性可删除此二级标题。 -> -> 4.2 - 类型如果为自定义类型,需要建立链接到对应的interface或enum中。 -> -> 4.3 - 对于可读属性:如果取值为有特殊含义的有限值,需要进行枚举。 -> -> 4.4 - 对于可写属性:如果仅支持固定字段,需要进行说明。 - -| 名称 | 类型 | 可读 | 可写 | 说明 | -| ---------------- | ----------------------------------------- | ---- | ---- | ------------------------------------------ | -| pluggedType | [BatteryPluggedType](#BatteryPluggedType) | 是 | 否 | 表示当前设备连接的充电器类型。 | -| isBatteryPresent | boolean | 是 | 否 | 表示当前设备是否支持电池或者电池是否在位。 | - -## 枚举 - -> *写作说明* -> -> 5.1 - 可选,如果没有可删除。如果有多个枚举,请分多个二级内容描述,并使用“##”自行新建二级标题。 -> -> 5.2 - 二级标题名为实际枚举名,比方说 BatteryHealthState 。 - -在此处给出该枚举类型的简要描述。如:表示连接的充电器类型的枚举。 - -| 名称 | 值 | 说明 | -| ---- | ---- | -------------------------- | -| NONE | 1 | 表示连接的充电器类型未知。 | - -## 方法 - -> *写作说明* -> -> 6.1 - 可选,如果没有可删除。如果有多个方法,请分多个二级内容描述,并使用“##”自行新建二级标题。 -> -> 6.2 - 二级标题名为方法名,采用导入类.方法名,如果是订阅方法,需要在方法名加上对应的订阅事件。 -> -> ​ 示例: sim.getSimIccId -> -> ​ 订阅方法:sim.on('exampleEvent') -> -> 6.3 - **方法具体调用形式**:和d.ts保持一致,需要包括参数类型、参数名、返回值类型。 -> -> ​ 示例:getNetworkState(slotId: number, callback: AsyncCallback\): void -> -> ​ 注意:尖括号<>可能会被识别为标签,导致界面显示失效,可增加一个\,以保证界面正常显示,如“\\<>”或使用转义字符\< \> 。 -> -> 6.4.1 - **方法描述**:对方法实现的功能进行描述,包括其使用的前提条件(*如:在xx方法调用后才能调用、需要确保网络已连接……*)、使用之后的影响(*如:调用该接口后再进行xx将不起效*)、权限限制等。 -> -> 6.4.2 - **异步方法描述**:存在大量异步方法,其返回方式需要在方法描述处进行说明。通过注册回调函数获取?还是通过Promise获取? -> -> 6.4.3 - **表格内换行**:markdown语法中,换行采用特殊标记\
- -在此处给出方法的具体调用形式:(如果是静态方法需说明) 方法名称(参数1名称:参数1类型,参数2名称:参数2类型,……):返回值类型 - -在此处给出方法描述。说明请参考6.4.1和6.4.2。 - -需要权限:ohos.permission.XXX(如不涉及可删除,如果是系统权限要说明) - -**参数:** (可选,如不涉及可删除) - -| 参数名 | 类型 | 必填 | 说明 | -| ------------ | --------------------------------------------- | ---- | ------------------------------------------------------------ | -| parameterOne | number \| string \| [CustomType](#CustomType) | 是 | 参数描述。给出取值范围、建议值。如果有固定格式,需要给出格式样例,尤其是URI。
自定义类型需要进行建链说明。 | -| callback | Callback\> | 否 | 参数描述。可选参数需要说明不填写该参数的后果。
如:不填该参数则取消该type对应的所有回调。 | - -**返回值**:(可选,如不涉及可删除) - -| 类型 | 说明 | -| ------------------------------------------ | -------------------------------------------- | -| string | 返回值描述。取到返回值之后,可以用来做什么。 | -| Promise\> | 返回值描述。通过Promise获取了什么。 | - -**示例:** - -```js -// 必选项。 -// 所有的示例代码需要进行自检。 -// 不能出现缺符号、变量前后不一致等低错。 -// 所有的使用到的变量要进行声明。 -// 不允许直接写参数名,必须是可使用、易替代的实际用例。 -// 如果非用户自定义填写,需通过注释进行说明。 -// 示例:var result = xxx.createExample(parameterOne); // parameterOne由扫描自动获取 -``` - -## Class/Interface - -> *写作说明* -> -> 7.1 - 可选,如果没有可删除。如果有多个,请分多个二级内容描述,并使用“##”自行新建二级标题。 -> -> 7.2 - 二级标题名为class、interface的名称。 -> -> 7.3 - 如果该API中,既有属性,又有方法,需要先进行属性的写作,并使用“###”三级标题。 -> -> ​ 如果该API中,只有属性,那么不需要新建三级标题,直接使用表格陈列属性,具体示例参考[CustomType](#CustomType)。 - -类描述/interface描述。如果有使用限制,需要在这个地方说明。比方说,是否有前提条件,是否需要通过什么方法先构造一个实例。 - -### 属性 - -> *写作说明* -> -> 除标题使用三级标题外,其余要求同[属性](#属性)。 - -### Class/Interface中的方法 - -> *写作说明* -> -> 7.4 - 标题名为方法名,使用三级标题,**没有前缀**。如果是订阅方法,需要在方法名加上对应的订阅事件。 -> -> ​ 示例: getSimIccId -> -> ​ 订阅方法:on('exampleEvent') -> -> 其余要求请参考[方法](#方法)中的说明。 - -在此处给出方法的具体调用形式。说明请参考6.3。 - -在此处给出方法描述。说明请参考6.4.1和6.4.2。 - -需要权限:ohos.permission.XXX(如不涉及可删除,如果是系统权限要说明) - -**参数:** (可选,如不涉及可删除) - -| 参数名 | 类型 | 必填 | 说明 | -| ------------ | --------------------------------------------- | ---- | ------------------------------------------------------------ | -| parameterOne | number \| string \| [CustomType](#CustomType) | 是 | 参数描述。给出取值范围、建议值。如果有固定格式,需要给出格式样例,尤其是URI。
自定义类型需要进行建链说明。 | -| callback | Callback\> | 否 | 参数描述。可选参数需要说明不填写该参数的后果。
如:不填该参数则取消该type对应的所有回调。 | - -**返回值**:(可选,如不涉及可删除) - -| 类型 | 说明 | -| ------------------------------------------ | -------------------------------------------- | -| string | 返回值描述。取到返回值之后,可以用来做什么。 | -| Promise\> | 返回值描述。通过Promise获取了什么。 | - -**示例:** - -```js -// 必选项。 -// 所有的示例代码需要进行自检。 -// 不能出现缺符号、变量前后不一致等低错。 -// 所有的使用到的变量要进行声明。 -// 不允许直接写参数名,必须是可使用、易替代的实际用例。 -// 如果非用户自定义填写,需通过注释进行说明。 -// 示例:var result = xxx.createExample(parameterOne); // parameterOne由扫描自动获取 -``` - -## CustomType - -仅有k-v键值对的自定义类型示例。 - -| 名称 | 类型 | 可读 |可写| 说明 | -| ------------ | ---- | ---- | ---- | ---- | -| parameterUrl | string | 是 | 是 |媒体输出URI。支持:
1. 协议类型为“internal”的相对路径,示例如下:
临时目录:internal://cache/test.mp4

2. 文件的绝对路径,示例如下:
file:///data/data/ohos.xxx.xxx/files/test.mp4| -| parameterOne | [CustomEnum](#枚举) | 是 | 是 |属性描述,要求与参数说明类似。| - - - diff --git a/website/docs/_posts/zh-cn/contribute/template/tutorial-template.md b/website/docs/_posts/zh-cn/contribute/template/tutorial-template.md deleted file mode 100644 index 9b3176e1fc829591d14bf71b959eb56702792c46..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/contribute/template/tutorial-template.md +++ /dev/null @@ -1,61 +0,0 @@ ---- -title: tutorial-template -permalink: /pages/extra/978e66/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 教程:标题(对应的任务名称) - -教程页面介绍如何完成一个复杂的任务开发、功能开发、APP开发。通常教程页面会将开发过程拆解为多个小节,每个小节由一系列步骤组成。同时,教程中一般需要提供代码示例并进行介绍,便于用户了解具体的功能实现。 - -对于教程中可能涉及到的基本概念,简单的概念可以直接介绍,更深度的概念和主题推荐查阅文档对应专题。 - -撰写教程页面时,在“others“目录下面创建新的MarkDown文件。 - -## 总览 - -_写作内容:介绍开发者学习本教程后将完成什么样的任务,实现什么样的功能和效果。__例如,可以是移植教程、实现一个功能开发教程等。_如果可实现多个目标,建议使用项目符号列表。 - -_如果可能,请提供图片或短视频展示实现效果。_ - -## 开发准备 - -- _完成该功能需要的软件、硬件、工具及对应版本信息。_ -- _需要获取的相关权限说明。_ - -## XXX(关键任务一) - -_将教程分解为几个顺序的关键任务或并列不同的场景任务。_ - -1. XXXX。 - - ``` - //代码示例 - ``` - -2. XXXX。 - -_所有的操作步骤,遵循如下写作要求:_ - -1. _步骤明确操作场景和目的,__步骤中执行的主体要描述清楚。_ -2. _步骤中如果涉及接口调用,需要清晰给出使用的接口及其使用说明,示例代码。_ -3. _涉及到工具界面的步骤,可以提供界面截图,帮助理解步骤完成标准。_ -4. _保证代码的逻辑和语法的正确性。_ -5. _代码中关键步骤要有注释说明。_ -6. 代码如有打印输出,请单独提示打印输出内容_,帮助理解步骤完成标准_。 - -## XXX(关键任务二) - -1. XXXX。 - -## 下一步 - -介绍本教程可能关联的后续开发任务,如果没有请删除此内容。 - diff --git a/website/docs/_posts/zh-cn/contribute/template/xxboard-template.md b/website/docs/_posts/zh-cn/contribute/template/xxboard-template.md deleted file mode 100644 index 7bc3e17d91e6056c0264435fbf2aa10809bd920c..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/contribute/template/xxboard-template.md +++ /dev/null @@ -1,95 +0,0 @@ ---- -title: xxboard-template -permalink: /pages/extra/f7c977/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# XXX开发板名称 -*本模板定位:OpenHarmony生态引入第三方开发板时,第三方开发板厂商需提供开发板介绍,便于开发者快速了解此开发板。* - -## 介绍 - -【写作说明】 - -*文字描述开发板的功能,面向场景,主要支持的特性能力。* - -*提供开发板外观图片。* - -*底板图片。* - -*功能框图及介绍。* - -**图片名称以开发板名称命名。* - -*参考文档:https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/quickstart-lite-introduction-hi3861.md* - -******** -## 开发板规格 - -*【写作说明】提供开发板模组规格清单,硬件规格列表。* - -## 约束和限制(可选) - -*【写作说明】如果开发板在某些功能、特性、规格等使用上,有一定的约束和建议,需要明确说明。* - -******** - - -## 关键特性 -*【写作说明】支持的OpenHarmony关键特性列表。* - -## 引脚定义 -*【写作说明】介绍单板的管脚定义等,描述单板I/O引脚,以及如何配置PIN、如何使用PIN连接外部组件。* - -## 搭建开发环境 - -### 系统要求 - -*【写作说明】描述开发板对OpenHarmony系统依赖、软、硬件环境系统依赖。* - -### 工具要求 - -*【写作说明】提供从哪里下载开发板编译调试工具链。* - -### 搭建过程 - -*【写作说明】Step by Step介绍环境搭建详细步骤。* - -## 编译调试 - -### 编译 - -*【写作说明】如何在此开发板上使用OpenHarmony,以及如何在此单板上刷新OpenHarmony二进制文件及设备。* - -### 烧录 - -*【写作说明】Step by Step介绍如何烧录参考步骤。* - -### 运行 - -*【写作说明】如何判断开发板正常点亮、运行、输出正常。* - - -### 调试 - -*【写作说明】如何调试开发板常见报错等。* - -## 首个示例 - -*【写作说明】基于此开发板给出一个快速上手的示例,运行效果,或者给出demo示例源码链接。* - -## 参考资源 - -*【写作说明】给出更多详细参考文档、sample示例、FAQ、官网等内容链接。* - -## 感谢(可选) - -*【写作说明】致谢做出突出贡献的三方开发者。* - diff --git a/website/docs/_posts/zh-cn/contribute/tutorial-title-task-name.md b/website/docs/_posts/zh-cn/contribute/tutorial-title-task-name.md new file mode 100644 index 0000000000000000000000000000000000000000..de498947bc90d6b59e0f7055d88f059ff0f0367c --- /dev/null +++ b/website/docs/_posts/zh-cn/contribute/tutorial-title-task-name.md @@ -0,0 +1,61 @@ +--- +title: tutorial-title-task-name.md +permalink: /pages/extra/54a97b/ +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +date: 2021-12-30 12:57:47 +--- +# 教程:标题(对应的任务名称) + +教程页面介绍如何完成一个复杂的任务开发、功能开发、APP开发。通常教程页面会将开发过程拆解为多个小节,每个小节由一系列步骤组成。同时,教程中一般需要提供代码示例并进行介绍,便于用户了解具体的功能实现。 + +对于教程中可能涉及到的基本概念,简单的概念可以直接介绍,更深度的概念和主题推荐查阅文档对应专题。 + +撰写教程页面时,在“others“目录下面创建新的MarkDown文件。 + +## 总览 + +_写作内容:介绍开发者学习本教程后将完成什么样的任务,实现什么样的功能和效果。__例如,可以是移植教程、实现一个功能开发教程等。_如果可实现多个目标,建议使用项目符号列表。 + +_如果可能,请提供图片或短视频展示实现效果。_ + +## 开发准备 + +- _完成该功能需要的软件、硬件、工具及对应版本信息。_ +- _需要获取的相关权限说明。_ + +## XXX(关键任务一) + +_将教程分解为几个顺序的关键任务或并列不同的场景任务。_ + +1. XXXX。 + + ``` + //代码示例 + ``` + +2. XXXX。 + +_所有的操作步骤,遵循如下写作要求:_ + +1. _步骤明确操作场景和目的,__步骤中执行的主体要描述清楚。_ +2. _步骤中如果涉及接口调用,需要清晰给出使用的接口及其使用说明,示例代码。_ +3. _涉及到工具界面的步骤,可以提供界面截图,帮助理解步骤完成标准。_ +4. _保证代码的逻辑和语法的正确性。_ +5. _代码中关键步骤要有注释说明。_ +6. 代码如有打印输出,请单独提示打印输出内容_,帮助理解步骤完成标准_。 + +## XXX(关键任务二) + +1. XXXX。 + +## 下一步 + +介绍本教程可能关联的后续开发任务,如果没有请删除此内容。 + diff --git "a/website/docs/_posts/zh-cn/contribute/\347\244\276\345\214\272\346\262\237\351\200\232\344\270\216\344\272\244\346\265\201.md" "b/website/docs/_posts/zh-cn/contribute/\347\244\276\345\214\272\346\262\237\351\200\232\344\270\216\344\272\244\346\265\201.md" new file mode 100644 index 0000000000000000000000000000000000000000..429dfde10ecf7f28244a8cff12d58fa605e6d6fd --- /dev/null +++ "b/website/docs/_posts/zh-cn/contribute/\347\244\276\345\214\272\346\262\237\351\200\232\344\270\216\344\272\244\346\265\201.md" @@ -0,0 +1,90 @@ +--- +title: 社区沟通与交流.md +permalink: /pages/extra/f67e87/ +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +date: 2021-12-30 12:57:47 +--- +# 社区沟通与交流 + +如果您在使用OpenHarmony过程中遇到问题,请加入邮件群组参与讨论,这是参与OpenHarmony项目讨论的正确方式。 + +## 如何订阅邮件列表 + +如果您以前从未订阅过邮件列表,请参照下面的操作步骤。 + +1. 点击您想要订阅的邮件列表的名称。 +2. 浏览器将跳转到该邮件列表的订阅页面,那里将提供有关如何订阅的说明。 +3. 阅读订阅说明,您需要提供一个您希望用来订阅邮件列表的电子邮件地址。 +4. 输入您的电子邮件地址并点击订阅,您将收到一封电子邮件,要求您确认订阅。 +5. 回复您收到的电子邮件以确认您的订阅。 +6. 最后您将收到来自一封来自邮件列表的欢迎邮件。 + +**表 1** : 邮件列表 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

邮件地址

+

简介

+

功能描述

+

contact@openharmony.io

+

公用邮箱

+

OpenHarmony社区公共邮箱。开发者CLA协议签署可以发邮件到此邮箱。

+

dev@openharmony.io

+

开发邮件列表

+

OpenHarmony社区开发讨论邮件列表,任何社区开发相关话题都可以在邮件列表讨论。任何开发者可订阅

+

cicd@openharmony.io

+

CI邮件列表

+

OpenHarmony社区CICD构建邮件列表,任何开发者可订阅

+

pmc@openharmony.io

+

PMC邮件列表

+

PMC讨论邮件列表,PMC成员可订阅

+

scy@openharmony.io

+

安全问题邮箱

+

开发者可反馈OpenHarmony安全问题到此邮箱。

+

scy-priv@openharmony.io

+

安全组邮件列表

+

安全组成员安全问题处理讨论邮件列表,安全组成员可订阅

+
+ +## 如何发送邮件到邮件列表 + +要将邮件发送到指定的邮件列表,请向上表中列出的邮件地址发送您的电子邮件。 + +这样所有在这个邮件列表中的社区成员都能收到您的电子邮件。 + diff --git "a/website/docs/_posts/zh-cn/contribute/\347\254\254\344\270\211\346\226\271\345\274\200\346\272\220\350\275\257\344\273\266\345\274\225\345\205\245\346\214\207\345\257\274.md" "b/website/docs/_posts/zh-cn/contribute/\347\254\254\344\270\211\346\226\271\345\274\200\346\272\220\350\275\257\344\273\266\345\274\225\345\205\245\346\214\207\345\257\274.md" index 82ab01811baaac200e521d42c3ee8c88a25019e0..3b3c73072be72ba420069257f207511d1f8d343e 100644 --- "a/website/docs/_posts/zh-cn/contribute/\347\254\254\344\270\211\346\226\271\345\274\200\346\272\220\350\275\257\344\273\266\345\274\225\345\205\245\346\214\207\345\257\274.md" +++ "b/website/docs/_posts/zh-cn/contribute/\347\254\254\344\270\211\346\226\271\345\274\200\346\272\220\350\275\257\344\273\266\345\274\225\345\205\245\346\214\207\345\257\274.md" @@ -1,15 +1,15 @@ --- -title: 第三方开源软件引入指导 -permalink: /pages/extra/0491e3/ +title: 第三方开源软件引入指导.md +permalink: /pages/extra/ba9721/ navbar: true sidebar: false prev: false next: false -search: true -article: true +search: false +article: false comment: false editLink: false -date: 2022-02-14 21:31:38 +date: 2021-12-30 12:57:47 --- # 第三方开源软件引入指导 diff --git "a/website/docs/_posts/zh-cn/contribute/\350\264\241\347\214\256\346\214\207\345\215\227.md" "b/website/docs/_posts/zh-cn/contribute/\350\264\241\347\214\256\346\214\207\345\215\227.md" deleted file mode 100644 index 6f9f6c88404086aaf768564cc2bcdce31fe975ab..0000000000000000000000000000000000000000 --- "a/website/docs/_posts/zh-cn/contribute/\350\264\241\347\214\256\346\214\207\345\215\227.md" +++ /dev/null @@ -1,32 +0,0 @@ ---- -title: 贡献指南 -permalink: /pages/extra/a26939/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 贡献指南 - -- **[参与贡献](/pages/010d01)** - -- **[行为准则](/pages/010d02)** - -- **[贡献代码](/pages/010d03)** - -- **[贡献流程](/pages/010d04)** - -- **[FAQ](/pages/010d07)** - -- **[贡献文档](/pages/extra/7f2552/)** - -- **[写作规范](/pages/010d0501)** - -- **[社区沟通与交流](/pages/010d06)** - - diff --git a/website/docs/_posts/zh-cn/design/API-Review-Template.md b/website/docs/_posts/zh-cn/design/API-Review-Template.md deleted file mode 100644 index e0438a1be0e12cd25849551aade36f61e4c15edd..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/design/API-Review-Template.md +++ /dev/null @@ -1,150 +0,0 @@ ---- -title: API-Review-Template -permalink: /pages/extra/986269/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:36 ---- -# OpenHarmony xxx子系统 xxx API评审申请 - -## 背景 - -* API类型:[Public API | Test API| HDI] -* API需求来源: -* API使用场景: -* API所属子系统: -* API预计发布版本: -* Contributor: -* 本次评审涉及的API数量: - -| 类型 | 数量 | 编程语言 | -|---|---|---| -| 新增 | | | -| 行为变更 | | -| 废弃 | | | -| 删除 | | | - -## API说明 - -### 必要性说明 - -> 现状与差距分析。API的使用场景和价值是什么? - -### 总体特性说明 - -> 相关API完成了哪些功能特性。 - -## 评审结论 - -### Committer评审结论 - -### 领域SIG评审结论 - -## 自查表 - -| 自查项 | 自查结果 | -|---|---| -| 是否已完成拼写检查? | | -| 是否遵循了编码规范? | | -| 词性使用是否正确(名词,形容词,副词)? | | -| 命名是否完整表述了API所做的全部逻辑?| | -|API的参数数量是否合理?(通常少于7个)| | -|是否合理使用了缩写?(缩写是大家周知的)| | -|void类型API是否真的考虑过调用者不需要返回值?| | -|是否考虑过继承体系是合适的?父类的每一个方法都适用于子类| | -|已定义的错误状态是否完备?| | -| 命名是否正确使用了对仗词:
add/remove, create/destroy, insert/delete, start/stop, begin/end,
send/receive, up/down, show/hide, open/close, source/target,
source/destination, increase/decrease, first/last, next/previous | | -|新增API与同模块既存API表述和语义层次是否一致?| | -| 同步API是否需要提供异步版本? | | -| 是否每一个public API都真的是开发者需要的?| | - -## API接口及说明 - -> 请填写代码的提交地址。 - -* 代码地址: - -## API权限设计 - -> 使用该接口是否需要申请相应的权限。 - -## API隐私保护设计 - -> 涉及用户隐私,需要考虑隐私保护。 - -## 开发者指南 - -> 可选。 - -## API代码示例 - -> 二选一即可。 - -* 代码地址: -* 代码片段: - -## API变更说明 - -> 新增接口不需要填写此章节。 - -### 行为变更 - -> API行为变更是指API的接口没有发生变化,仅仅是行为发生变化。 -> API行为变更需要在新的API版本上进行,不允许破坏旧版本API行为(除非是缺陷修复)。 - -#### 相关接口 - -#### 变更原因 - -### 废弃接口 - -> 废弃接口的API说明中,需要添加`@deprecated`注解进行(包括:JS/TS/C/C++接口)标记。 - -#### 相关接口 - -> 需描述从哪个版本开始标记为废弃。 - -#### 废弃原因 - -#### 替代接口 - -> 如果有则提供,如果无则说明原因。 - -### 删除接口 - -> 接口不允许直接删除,需要在标记废弃之后经过5个API版本才允许删除。 - -#### 相关接口 - -#### 删除原因 - -#### 替代接口 - -> 如果有则提供,如果无则说明原因。 - -## DFX - -### 兼容性 - -### 性能 - -### 功耗 - -### 可靠性 - -### 可测试性 - -> API必须同步交付API自动化测试用例,用例100%覆盖API接口。 - -## 评审结论 - -* 评审时间: -* 与会人: -* 评审结论:[通过|不通过] -* 评审会议纪要: \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/design/OpenHarmony-API-governance.md b/website/docs/_posts/zh-cn/design/OpenHarmony-API-governance.md index b4b965016bc403f6a66fd92741e6f2f98edfd822..a3b3c04ebe953245ff6e18169ecfb165ff1ca3bc 100644 --- a/website/docs/_posts/zh-cn/design/OpenHarmony-API-governance.md +++ b/website/docs/_posts/zh-cn/design/OpenHarmony-API-governance.md @@ -1,61 +1,43 @@ --- -title: OpenHarmony-API-governance -permalink: /pages/extra/261918/ +title: OpenHarmony-API-governance.md +permalink: /pages/extra/d012a7/ navbar: true sidebar: false prev: false next: false -search: true -article: true +search: false +article: false comment: false editLink: false -date: 2022-02-14 21:31:36 +date: 2021-12-30 12:57:47 --- # OpenHarmony API治理章程 -## 总览 - -为了引导OpenHarmony生态健康、有序发展和演进,本章程对OpenHarmony API的新增、变更、废弃、删除等生命周期与治理流程进行约束,同时定义了基本的API设计要求。 - -本章程由[API SIG](https://www.openharmony.cn/SIG/api/)制定,经[PMC](https://www.openharmony.cn/community/pmc/)批准发布;本对章程的修订必须经由API SIG评审后,由PMC批准发布。 - -## 概述 - -### 范围与定义 -OpenHarmony软件栈中包含了多个角色,因此API也分作多种类型。 - - -不同的API类型其兼容性要求也不一样,具体如下表所述: +## 总览 -| 类型 | 提供者 | 使用者 | 兼容性要求 | 看护手段| -|---|---|---|---|---| -| Public API | 系统与框架 | 所有应用开发者 | 5个API版本| XTS| -| Test API | 测试框架 | 所有应用开发者| 3个API版本| 待构建 | -| System API | 系统与框架 |系统应用开发者 |不承诺| 待构建 | -| HDI | HDF| 系统服务 | 4个API版本| XTS | -| Driver API | HDF | 驱动开发者 | 不承诺 | 无 | -| Inner API | 系统部件 | 系统部件 | 不承诺 | 无 | -各类型API说明如下: -* Public API:OpenHarmony对所有应用开发者公开的API。 -* Test API:测试专用的API,供开发者使用。 -* System API:提供给系统特权应用使用的API,普通应用无法使用。 -* HDI:描述硬件能力的接口。 -* Driver API:提供给驱动开发者使用的接口。 -* Inner API:系统服务和框架实现彼此调用的API,仅供系统内部使用,不承诺兼容性。 +为了引导OpenHarmony应用生态健康、有序发展演进,本章程对OpenHarmony API的新增、变更、废弃、删除等生命周期与治理流程进行约束,同时定义了基本的API设计要求。 -### API与编程语言 +本章程由API SIG制定,经PMC批准发布;本对章程的修订必须经由API SIG评审后,由PMC批准发布。 +## API范围与定义 +应用程序接口(API)位于应用层和框架层之间,是由操作系统预定义的、由框架层和系统应用提供给应用(包括系统应用和三方应用)开发使用的类、方法等用户程序编程接口;不包括OEM扩展接口。 -OpenHarmony的目标是构建面向万物互联时代的新一代操作系统,其实现涵盖但不限于以下编程语言: +![](/images/zh-cn/design/figures/API-Scope-And-Definition.png) -* C/C++ -* JavaScript -* TypeScript +OpenHarmony API按可授权使用方分类包括: +- Public API:公开发布,提供给三方应用开发使用的API。 +- System API:非公开发布,仅授权平台签名应用(signature)、预置特权应用(privileged)使用的API。 +- Test API:受限发布,仅适用于xTS或应用调试阶段可使用的API。 +

如无特别说明,本章程定义的条款同时适用于Public API、System API或Test API等三种OpenHarmony API。针对System API和Test API的额外要求或例外说明,通过特别说明方式加以补充说明。

-本章程所描述的内容与编程语言无关。即:在不违反编程语言要求的情况下,API不分编程语言都要遵守章程的要求。 +OpenHarmony API按编程语言分类包括: +- Java API:面向应用开放的Java编程语言接口。 +- JS API:面向应用开放的JavaScript编程语言接口。 +- Native API:面向应用开放的C/C++编程语言接口。 +

如无特别说明,本章程定义的条款同时适用于Java API、JS API和Native API等三种编程语言OpenHarmony API。

## API治理 @@ -65,26 +47,24 @@ OpenHarmony的目标是构建面向万物互联时代的新一代操作系统, | - | - | |Contributor|API的设计和交付主体,负责API相关的代码与设计文档提交。| |Committer|API相关的代码评审,涉及API提交预审。| -|领域SIG| 新增API相关的代码提交评审,领域SIG评审通过即可合入。
变更API相关的代码提交预审。| +|领域SIG|

新增API相关的代码提交评审,领域SIG评审通过即可合入。

变更API相关的代码提交预审。

| |API SIG|变更API相关的代码提交评审。| |PMC|API Version计划发布、API治理章程修订评审发布等。| ### API评审流程 API评审流程如下: - +![](/images/zh-cn/design/figures/API-Review-Process.png) 主要过程说明: - -1. API评审申请、代码提交(Owner:Contributor),所有涉及API新增或变更需同步提交相应的API评审文档,详细说明API的需求来源、场景与使用方法、权限设计、隐私保护澄清等,详见后面的API评审申请要素。为避免后续的返工,Contributor可以在正式的API评审申请、代码提交之前,先通过邮件方式将API设计文档提交Committer、领域SIG、API SIG等相关人员预审。 -1. 代码评审(Owner:Committer),代码评审和API预审,涉及API提交Code Review通过后,还需要进一步领域SIG评审。如果单次提交同时涉及多个领域的API新增或变更,相应的API评审申请和代码需要同时提交给相关领域的Committer评审,只有所有对应领域的Committer都完成CodeReview后才能进入下一评审环节。 +1. API评审申请、代码提交(Owner:Contributor),除代码提交外,如果涉及API新增或变更需同步提交相应的API设计文档,详细说明API的需求来源、场景与使用方法、权限设计、隐私保护澄清等,详见后面的API评审申请要素。为避免后续的返工,Contributor可以在正式的API评审申请、代码提交之前,先通过邮件方式将API设计文档提交Committer、领域SIG、API SIG等相关人员预审。 +1. 代码评审(Owner:Committer),代码评审和API预审,涉及API提交CodeReview通过后,还需要进一步领域SIG评审。如果单次提交同时涉及多个领域的API新增或变更,相应的API评审申请和代码需要同时提交给相关领域的Committer评审,只有所有对应领域的Committer都完成CodeReview后才能进入下一评审环节。 1. API评审(Owner:领域SIG),新增API相关的代码提交评审,领域SIG评审通过即可代码合入;变更API相关的代码提交,领域SIG评审通过后,还需要进一步提交API SIG。如果单次提交同时涉及多个领域的API新增,相应的API评审申请和代码需要同时提交给相关领域的SIG评审,只需一个领域SIG评审通过即可代码合入。如果单次提交同时涉及多个领域的API变更,相应的API评审申请和代码需要同时提交给相关领域的SIG评审,只有所有对应领域的SIG都要评审通过才能进入下一评审环节。 1. API变更评审(Owner:API SIG),变更API相关的代码提交评审,评审通过即可代码。 1. 评审完成。 ### API评审申请要素 - -如果涉及API新增或变更需同步提交相应的API评审文档。API评审文档使用[《OpenHarmony API 评审模板》](/pages/extra/986269/)描述。 +如果涉及API新增或变更需同步提交相应的API设计文档。 针对新增API,需要包含如下要素: 1. 需求来源与使用场景(必须)。 @@ -98,11 +78,9 @@ API评审流程如下: 针对变更API,需要额外包含如下要素: 1. 针对老接口的处理方式(废弃、隐藏或彻底删除)以及对使用老SDK开发应用的兼容措施(必须); 2. 变更影响、替代接口和相应的应用适配方案(必须)。 -3. 刷新ChangeLog(必须) 和 API-diff文档(涉及JS/Native API变更,必须)。 +3. 刷新ChangeLog(必须) 和 API-diff文档(涉及JS/Native API变更,必须;Java API的差异报告可工具化生成,不需要人工提交)。 ## API设计要求 - - ### 一致性要求 1. 概念一致性:基于场景的业务模型抽象,形成OpenHarmony的连贯、一致、自恰的用户程序模型和业务概念。 1. 术语一致性:相应的业务术语必须采用统一名词,不允许使用多个语意接近的名词表示同一个业务对象;同样地,为了避免产生混淆,也不允许针对不同的业务对象使用相同的名词或语言接近的名词。 @@ -125,9 +103,10 @@ API评审流程如下: 1. 作用域越大,命名应越精确。 1. 不用或少用缩写,业界通用术语遵从行业习惯允许使用缩写。 1. 包名/模块名/命名空间前缀约定: - 1. JS API 统一模块名:@ohos.\*。 - 2. Native API 统一命名空间:namespace OHOS.\*。 - 3. 引用外部开源代码的,可以保留原包名/模块名/命名空间,也可以按照上述规则对包名统一进行替换。 + 1. Java API 统一包名: package ohos.\*。 + 2. JS API 统一模块名:@ohos.\*。 + 3. Native API 统一命名空间:namespace OHOS.\*。 + 4. 引用外部开源代码的,可以保留原包名/模块名/命名空间,也可以按照上述规则对包名统一进行替换。 1. 包名/模块名/命名空间最短不少于2段,最长不超过4段;每一段建议使用一个单词,最长不超过2个单词。 1. 类名、方法名/函数名、成员变量、变量名最多不超过4个单词。 @@ -170,7 +149,7 @@ API评审流程如下: 1. 禁止“原型相同、功能不兼容”的API修改,可受限使用“废弃old-api、新增new-api”的方式进行修改。 1. 根据发布类型不同,API的生命周期和兼容性要求: -![](/images/design/figures/API-Lifecycle.png) +![](/images/zh-cn/design/figures/API-Lifecycle.png) 1. Canary版本:早期发布的预览版本,不承诺API稳定。 1. 对上一Release发布版本保持API兼容。 @@ -186,33 +165,14 @@ API评审流程如下: 1. 提供可替代接口。 1. 废弃API至少保留5个API Version版本(对废弃5个API Version的API可以彻底删除,不再支持)。 -### 性能要求 +### 性能/功耗/可靠性要求 1. 应及时响应,避免调用者等待;如果API调用执行时间过长应设计为异步方式。 -2. 应关注API调用时机、调用频次对RAM占用的影响。 -3. 应关注API调用时机、调用频次对功耗的影响。 -4. 对使用资源的API调用需要能及时释放资源,异常场景具备容错机制,保障资源及时释放。 - -### 功耗要求 - -1. 针对API调用时机、调用频次对功耗的影响做评估,有影响进行相关设计。 -2. 版本演进过程中,功耗不劣化。 - -### 可靠性要求 - -1. API不能因为外部输入(输入参数、系统状态、外部数据等)或者内部状态、数据异常而崩溃,应该返回确定的错误码或者抛出预定义的异常。 -2. API应明确调用是同步还是异步调用,若是同步调用,应明确超时上限或者允许调用者设置超时时间,避免调用卡死导致业务无响应。 -3. API务必支持多线程重入。 -4. 满足幂等性要求,相同业务含义的请求API调用一次或多次重试总能获得相同的效果(API调用依赖外部资源的变化除外)。针对可重入的API调用实现内部应尽量避免引入时变因素,如系统tick、静态变量、没有互斥保护的全局变量等;针对同一客户端的多次重复调用,可以使用contextID、clientToken、squenceNo等作为调用入参。 -5. API内部创建对象的生命周期要闭合,避免对象资源泄漏。 -6. API要明确客户端调用失败后,能够发起重试的最大次数。 +1. 应关注API调用时机、调用频次对RAM占用的影响。 +1. 应关注API调用时机、调用频次对功耗的影响。 +1. API内部创建对象的生命周期要闭合,避免对象资源泄漏。 +1. 满足幂等性要求,相同业务含义的请求API调用一次或多次重试总能获得相同的效果(API调用依赖外部资源的变化除外)。针对可重入的API调用实现内部应尽量避免引入时变因素,如系统tick、静态变量、没有互斥保护的全局变量等;针对同一客户端的多次重复调用,可以使用contextID、clientToken、squenceNo等作为调用入参。 ### 测试要求 1. 新增API必须同步交付API自动化测试用例,用例100%覆盖API接口。 -2. 用例场景单一,单条用例覆盖接口单个功能场景,简化单条用例代码逻辑。 -3. 用例执行高效,每条用例执行时间控制在毫秒级。 -4. 用例执行全自动化:接口用例需要达成100%自动化。 -5. 用例有效性:用户要求必须存在断言,且不能仅是检查是否抛出异常,需要有功能逻辑的断言。 - -### 编程语言要求 - -API根据其编程语言类型,需要遵守相应的OpenHarmony编程语言规范。 +1. 用例场景单一,单条用例覆盖接口单个功能场景,简化单条用例代码逻辑。 +1. 用例执行高效,每条用例执行时间控制在毫秒级。 \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/device-dev/Readme-CN.md b/website/docs/_posts/zh-cn/device-dev/Readme-CN.md deleted file mode 100644 index 29685b1c42f7d7cdeb2ffb8c15e912882a57823c..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/Readme-CN.md +++ /dev/null @@ -1,188 +0,0 @@ ---- -title: Readme-CN -permalink: /pages/extra/006ae2/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 导读 - -- [系统类型](#section767218232110) -- [文档导读](#section19810171681218) - -为了方便开发者正确获取内容,本导读基于OpenHarmony学习路径同时结合开发者具体业务对相关资料资源进行了分类。 - -## 系统类型 - -在正式学习OpenHarmony开发前,开发者需要先了解系统类型,方便后续根据自身业务匹配对应的系统及对应文档资源。 - -OpenHarmony是一款面向全场景的开源分布式操作系统,采用组件化设计,支持在128KiB到xGiB RAM资源的设备上运行系统组件,设备开发者可基于目标硬件能力自由选择系统组件进行集成。 - -为了保证在不同硬件上集成的易用性,OpenHarmony当前定义了三种基础系统类型,设备开发者通过选择基础系统类型完成必选组件集配置后,便可实现其最小系统的开发。这三种基础系统类型的参考定义如下: - -- 轻量系统(mini system) - - 面向MCU类处理器例如Arm Cortex-M、RISC-V 32位的设备,硬件资源极其有限,支持的设备最小内存为128KiB,可以提供多种轻量级网络协议,轻量级的图形框架,以及丰富的IOT总线读写部件等。可支撑的产品如智能家居领域的连接类模组、传感器设备、穿戴类设备等。 - -- 小型系统(small system) - - 面向应用处理器例如Arm Cortex-A的设备,支持的设备最小内存为1MiB,可以提供更高的安全能力、标准的图形框架、视频编解码的多媒体能力。可支撑的产品如智能家居领域的IP Camera、电子猫眼、路由器以及智慧出行域的行车记录仪等。 - -- 标准系统(standard system) - - 面向应用处理器例如Arm Cortex-A的设备,支持的设备最小内存为128MiB,可以提供增强的交互能力、3D GPU以及硬件合成能力、更多控件以及动效更丰富的图形能力、完整的应用框架。可支撑的产品如高端的冰箱显示屏。 - - -OpenHarmony也提供了一系列可选的系统组件,方便设备开发者按需配置,以支撑其特色功能的扩展或定制开发。系统将这些可选的系统组件组合为一系列描述为特性或功能的系统能力,以方便设备开发者理解和选择。 - -## 文档导读 - -- [轻量和小型系统开发指导](#table3762949121211) -- [标准系统开发指导](#table17667535516) - -**表 1** 轻量和小型系统开发指导(参考内存<128MB) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

学习路径

-

开发者业务

-

相关文档

-

了解OpenHarmony

-

整体认知OpenHarmony

-
-

获取开发资源

-

准备开发前相关资源

-
-

快速入门

-

快速熟悉OpenHarmony环境搭建、编译、烧录、调测、运行。

-

轻量和小型系统快速入门

-

基础能力使用

-

使用OpenHarmony提供的基础能力

-
-

进阶开发

-

结合系统能力开发智能设备

-
-

移植适配

-
  • 针对特定芯片做移植适配
  • 对三方库进行移植适配
-
-

贡献组件

-

OpenHarmony贡献功能组件

-
-

参考

-

开发参考

-
-
- -**表 2** 标准系统开发指导(参考内存≥128MB) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

学习路径

-

开发者业务

-

相关文档

-

了解OpenHarmony

-

整体认知OpenHarmony

-
-

获取开发资源

-

准备开发前相关资源

-
-

快速入门

-

快速熟悉OpenHarmony环境搭建、编译、烧录、调测、运行。

-

标准系统快速入门

-

基础能力使用

-

使用OpenHarmony提供的基础能力

-
-

进阶开发

-

结合系统能力开发智能设备

-
-

移植适配

-

对三方库进行移植适配

-
-

贡献组件

-

OpenHarmony贡献功能组件

-
-

参考

-

开发参考

-
-
- diff --git a/website/docs/_posts/zh-cn/device-dev/bundles/Readme-CN.md b/website/docs/_posts/zh-cn/device-dev/bundles/Readme-CN.md deleted file mode 100644 index d490b6a277fcd57053f2f2f5745d9eadabec9e88..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/bundles/Readme-CN.md +++ /dev/null @@ -1,25 +0,0 @@ ---- -title: Readme-CN -permalink: /pages/extra/fc1d8d/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# Bundle开发指南 - -- [开发规范](/pages/01060101) -- [开发指南](/pages/extra/460736/) - - [概述](/pages/0106010201) - - [安装hpm命令行工具](/pages/0106010202) - - [开发Bundle](/pages/0106010203) -- [开发示例](/pages/extra/5aa5a6/) - - [HPM介绍](/pages/0106010301) - - [编译环境准备](/pages/0106010302) - - [操作实例](/pages/0106010303) - diff --git a/website/docs/_posts/zh-cn/device-dev/bundles/bundles-demo.md b/website/docs/_posts/zh-cn/device-dev/bundles/bundles-demo.md deleted file mode 100644 index 6d577ad625ffc1c4c1ee2cccab73f07adcdd32d1..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/bundles/bundles-demo.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: bundles-demo -permalink: /pages/extra/5aa5a6/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 开发示例 - -- **[HPM介绍](/pages/0106010301)** - -- **[编译环境准备](/pages/0106010302)** - -- **[操作实例](/pages/0106010303)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/bundles/bundles-guide.md b/website/docs/_posts/zh-cn/device-dev/bundles/bundles-guide.md deleted file mode 100644 index 1fddf9d7146240948f8d7013bbdb66c68504e953..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/bundles/bundles-guide.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: bundles-guide -permalink: /pages/extra/460736/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 开发指南 - -- **[概述](/pages/0106010201)** - -- **[安装hpm命令行工具](/pages/0106010202)** - -- **[开发Bundle](/pages/0106010203)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/bundles/bundles.md b/website/docs/_posts/zh-cn/device-dev/bundles/bundles.md deleted file mode 100644 index 51e62701048e80dd47eed6541900f492cc832fee..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/bundles/bundles.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: bundles -permalink: /pages/extra/341505/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# HPM bundle - -- **[开发规范](/pages/01060101)** - -- **[开发指南](/pages/extra/460736/)** - -- **[开发示例](/pages/extra/5aa5a6/)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/driver/Readme-CN.md b/website/docs/_posts/zh-cn/device-dev/driver/Readme-CN.md deleted file mode 100644 index b2294b4a03b0760d5502d27aa213cbc7a109ebb5..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/driver/Readme-CN.md +++ /dev/null @@ -1,59 +0,0 @@ ---- -title: Readme-CN -permalink: /pages/extra/551a2e/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 驱动使用指南 - -- [HDF驱动框架](/pages/extra/cda5c5/) - - [HDF开发概述](/pages/0105020101) - - [驱动开发](/pages/0105020102) - - [驱动服务管理](/pages/0105020103) - - [驱动消息机制管理](/pages/0105020104) - - [配置管理](/pages/0105020105) - - [HDF开发实例](/pages/0105020106) -- [平台驱动开发](/pages/extra/6b1378/) - - [ADC](/pages/0105020201) - - [GPIO](/pages/0105020202) - - [HDMI](/pages/0105020203) - - [I2C](/pages/0105020204) - - [I3C](/pages/0105020205) - - [MIPI-CSI](/pages/0105020206) - - [MIPI-DSI](/pages/0105020207) - - [MMC](/pages/0105020208) - - [PWM](/pages/0105020209) - - [RTC](/pages/010502020a) - - [SDIO](/pages/010502020b) - - [SPI](/pages/010502020c) - - [UART](/pages/010502020d) - - [WatchDog](/pages/010502020e) -- [平台驱动使用](/pages/extra/6777d1/) - - [ADC](/pages/0105020301) - - [GPIO](/pages/0105020302) - - [HDMI](/pages/0105020303) - - [I2C](/pages/0105020304) - - [I3C](/pages/0105020305) - - [MIPI-CSI](/pages/0105020306) - - [MIPI-DSI](/pages/0105020307) - - [PWM](/pages/0105020308) - - [RTC](/pages/0105020309) - - [SDIO](/pages/010502030a) - - [SPI](/pages/010502030b) - - [UART](/pages/010502030c) - - [WATCHDOG](/pages/010502030d) -- [外设驱动使用](/pages/extra/665bcf/) - - [LCD](/pages/0105020401) - - [TOUCHSCREEN](/pages/0105020402) - - [SENSOR](/pages/0105020403) - - [WLAN](/pages/0105020404) - - [AUDIO](/pages/0105020405) - - [USB](/pages/0105020406) - - [CAMERA](/pages/0105020407) diff --git a/website/docs/_posts/zh-cn/device-dev/driver/driver-develop.md b/website/docs/_posts/zh-cn/device-dev/driver/driver-develop.md deleted file mode 100644 index 7bf7bfa7a4fee522dfc1ac633e41a622749c2299..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/driver/driver-develop.md +++ /dev/null @@ -1,42 +0,0 @@ ---- -title: driver-develop -permalink: /pages/extra/6b1378/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 平台驱动开发 - -- **[ADC](/pages/0105020201)** - -- **[GPIO](/pages/0105020202)** - -- **[HDMI](/pages/0105020203)** - -- **[I2C](/pages/0105020204)** - -- **[I3C](/pages/0105020205)** - -- **[MIPI-CSI](/pages/0105020206)** - -- **[MIPI-DSI](/pages/0105020207)** - -- **[MMC](/pages/0105020208)** - -- **[PWM](/pages/0105020209)** - -- **[RTC](/pages/010502020a)** - -- **[SDIO](/pages/010502020b)** - -- **[SPI](/pages/010502020c)** - -- **[UART](/pages/010502020d)** - -- **[WatchDog](/pages/010502020e)** diff --git a/website/docs/_posts/zh-cn/device-dev/driver/driver-hdf.md b/website/docs/_posts/zh-cn/device-dev/driver/driver-hdf.md deleted file mode 100644 index 5494c59349aa48607be0b309d73658ab99720dcd..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/driver/driver-hdf.md +++ /dev/null @@ -1,28 +0,0 @@ ---- -title: driver-hdf -permalink: /pages/extra/cda5c5/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# HDF驱动框架 - -- **[HDF开发概述](/pages/0105020101)** - -- **[驱动开发](/pages/0105020102)** - -- **[驱动服务管理](/pages/0105020103)** - -- **[驱动消息机制管理](/pages/0105020104)** - -- **[配置管理](/pages/0105020105)** - -- **[HDF开发实例](/pages/0105020106)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/driver/driver-peripherals-vibrator-des.md b/website/docs/_posts/zh-cn/device-dev/driver/driver-peripherals-vibrator-des.md deleted file mode 100644 index a60726ea8c70cc4237e73faab4bb1ff90805c777..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/driver/driver-peripherals-vibrator-des.md +++ /dev/null @@ -1,382 +0,0 @@ ---- -title: driver-peripherals-vibrator-des -permalink: /pages/extra/37e845/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# Vibrator -- [概述](##概述) - - [功能简介](###功能简介) - - [运作机制](###运作机制) -- [开发指导](##开发指导) - - [接口说明](###接口说明) - - [开发步骤](###开发步骤) - - [开发实例](###开发实例) - -## 概述 - -### 功能简介 - -为了快速开发传感器驱动,基于HDF(Hardware Driver Foundation)驱动框架开发了马达驱动模型。马达设备模型抽象,屏蔽设备驱动与系统交互的实现,为硬件服务层提供统一稳定的驱动接口能力,为驱动开发者提供开放的接口实现和抽象的配置接口能力。用于不同操作系统马达设备部件的部署指导和马达设备部件驱动的开发。马达驱动模型如[图1](马达驱动模型图)所示: - -**图 1** 马达驱动模型图 - - - -### 运作机制 - -通过介绍马达驱动模型的加载以及运行流程,对模型内部关键组件以及关联组件之间的关系进行了划分,整体加载流程如[图2](#马达驱动运行图)所示: - -**图2** 马达驱动运行图 - - - -马达驱动模型以标准系统Hi3516DV300产品为例,介绍整个驱动加载及运行流程: - -1. 从device info HCS 的Vibrator Host读取Vibrator管理配置信息。 -2. 解析Vibrator配置信息,并关联对应设备驱动。 -3. 从linear_vibrator_config HCS读取Vibrator数据配置信息。 -4. 解析Vibrator数据配置信息,并关联对应Haptic驱动。 -5. 客户端下发Vibrator Stub控制到服务端。 -6. 服务端调用Vibrator Stub控制。 -7. 启动马达抽象驱动接口。 -8. Haptic中起线程,解析效果模块。 -9. Haptic调用马达抽象驱动中的Start接口。 -10. 马达抽象驱动调用马达差异化驱动中的Start接口。 - -## 开发指导 - -### 接口说明 - -马达驱动模型支持静态HCS配置和动态参数两种振动效果配置能力。马达硬件服务调用StartOnce接口动态配置持续振动;调用Start接口启动静态配置的振动效果。马达驱动模型对HDI开放的API接口能力,参考[表1](马达驱动模型对外API接口能力介绍)。 - -**表 1** 马达驱动模型对外API接口能力介绍 - -| 接口名 | 功能描述 | -| -------------------------------------- | -------------------------------------------------------- | -| int32_t StartOnce(uint32_t duration) | 按照指定持续时间触发振动马达,duration为振动持续时长。 | -| int32_t Start(const char *effectType) | 按照指定预置效果启动马达,effectType表示预置的预置效果。 | -| int32_t Stop(enum VibratorMode mode) | 按照指定的振动模式停止马达振动。 | - -### 开发步骤 - -Vibrator驱动模型为上层马达硬件服务层提供稳定的马达控制能力接口,包括马达一次振动、马达效果配置震动、马达停止。基于HDF(Hardware Driver Foundation)驱动框架开发的马达驱动模型,实现跨操作系统迁移、器件差异配置等功能。马达具体的开发步骤如下: - -1. 基于HDF驱动框架,按照驱动Driver Entry程序,完成马达抽象驱动开发,主要由Bind、Init、Release、Dispatch函数接口实现,配置资源和HCS解析。 -2. 创建马达效果模型,解析马达效果HCS配置。 -3. 完成马达振动和停止接口开发,会根据振动效果的模式创建和销毁定时器。 -4. 马达驱动模型提供给开发者马达驱动差异化接口,开发者实现差异化接口。 - -### 开发实例 - -1. 马达驱动的初始化和去初始化 - - - 调用HDF_INIT将驱动入口注册到HDF框架中,在加载驱动时HDF框架会先调用Bind函数,再调用Init函数加载该驱动。当Init调用异常时,HDF框架会调用Release释放驱动资源并退出马达驱动模型,使用HCS作为配置描述源码。HCS配置字段详细介绍参考[配置管理](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/driver/driver-hdf-manage.md)。其中Driver Entry入口函数定义如下: - - ``` - /* 注册马达抽象驱动入口数据结构体对象 */ - struct HdfDriverEntry g_vibratorDriverEntry = { - .moduleVersion = 1, //马达模块版本号 - .moduleName = "HDF_VIBRATOR", //马达模块名,要与device_info.hcs文件里的马达moduleName字段值一样 - .Bind = BindVibratorDriver, //马达绑定函数 - .Init = InitVibratorDriver, //马达初始化函数 - .Release = ReleaseVibratorDriver, //马达资源释放函数 - }; - - HDF_INIT(g_vibratorDriverEntry); - ``` - - - 基于HDF驱动框架,按照驱动Driver Entry程序,完成马达抽象驱动开发,主要由Bind、Init、Release、Dispatch函数接口实现。 - - ``` - /* 马达驱动对外发布的能力 */ - static int32_t DispatchVibrator(struct HdfDeviceIoClient *client, - int32_t cmd, struct HdfSBuf *data, struct HdfSBuf *reply) - { - int32_t loop; - - for (loop = 0; loop < sizeof(g_vibratorCmdHandle) / sizeof(g_vibratorCmdHandle[0]); ++loop) { - if ((cmd == g_vibratorCmdHandle[loop].cmd) && (g_vibratorCmdHandle[loop].func != NULL)) { - return g_vibratorCmdHandle[loop].func(data, reply); - } - } - - return HDF_SUCCESS; - } - - /* 马达驱动对外提供的服务绑定到HDF框架 */ - int32_t BindVibratorDriver(struct HdfDeviceObject *device) - { - struct VibratorDriverData *drvData = NULL; - CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(device, HDF_FAILURE); - - drvData = (struct VibratorDriverData *)OsalMemCalloc(sizeof(*drvData)); - CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_MALLOC_FAIL); - - drvData->ioService.Dispatch = DispatchVibrator; - drvData->device = device; - device->service = &drvData->ioService; - g_vibratorDrvData = drvData; - - return HDF_SUCCESS; - } - - /* 马达驱动初始化入口函数*/ - int32_t InitVibratorDriver(struct HdfDeviceObject *device) - { - struct VibratorDriverData *drvData = NULL; - - drvData->mode = VIBRATOR_MODE_BUTT; - drvData->state = VIBRATOR_STATE_IDLE; - ...... - if (CreateVibratorHaptic(device) != HDF_SUCCESS) { - HDF_LOGE("%s: init workQueue fail!", __func__); - return HDF_FAILURE; - } - - return HDF_SUCCESS; - } - - /* 释放马达驱动初始化时分配的资源 */ - void ReleaseVibratorDriver(struct HdfDeviceObject *device) - { - struct VibratorDriverData *drvData = NULL; - ...... - (void)DestroyVibratorHaptic(); - (void)OsalMutexDestroy(&drvData->mutex); - (void)OsalMemFree(drvData); - g_vibratorDrvData = NULL; - } - ``` - - - 马达设备管理模块负责系统中马达器件接口发布,在系统启动过程中,HDF框架机制通过马达 Host里设备HCS配置信息,加载设备管理驱动。 - - ``` - /* 马达设备HCS配置 */ - vibrator :: host { - hostName = "vibrator_host"; - device_vibrator :: device { - device0 :: deviceNode { - policy = 2; //驱动服务发布的策略 - priority = 100; //驱动启动优先级(0-200),值越大优先级越低,建议配置100,优先级相同则不保证device的加载顺序 - preload = 0; //驱动按需加载字段,0表示加载,2表示不加载 - permission = 0664; //驱动创建设备节点权限 - moduleName = "HDF_VIBRATOR"; //驱动名称,该字段的值必须和驱动入口结构的moduleName值一致 - serviceName = "hdf_misc_vibrator"; //驱动对外发布服务的名称,必须唯一 - deviceMatchAttr = "hdf_vibrator_driver"; //驱动私有数据匹配的关键字,必须和驱动私有数据配置表中的match_attr值相等 - } - } - ``` - -2. 创建马达效果模型,解析马达效果HCS配置。 - - - 创建马达效果模型。 - - ``` - /* 创建马达效果模型,分配资源,解析马达HCS配置 */ - int32_t CreateVibratorHaptic(struct HdfDeviceObject *device) - { - struct VibratorHapticData *hapticData = NULL; - CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(device, HDF_FAILURE); - - hapticData = (struct VibratorHapticData *)OsalMemCalloc(sizeof(*hapticData)); - CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(hapticData, HDF_ERR_MALLOC_FAIL); - g_vibratorHapticData = hapticData; - hapticData->supportHaptic = false; - - if (OsalMutexInit(&hapticData->mutex) != HDF_SUCCESS) { - HDF_LOGE("%s: fail to init mutex", __func__); - goto EXIT; - } - - DListHeadInit(&hapticData->effectSeqHead); - - /* 解析马达效果HCS配置 */ - if (ParserVibratorHapticConfig(device->property) != HDF_SUCCESS) { - HDF_LOGE("%s: parser haptic config fail!", __func__); - goto EXIT; - } - - return HDF_SUCCESS; - EXIT: - OsalMemFree(hapticData); - return HDF_FAILURE; - } - ``` - - - 马达效果模型使用HCS作为配置描述源码,HCS配置字段详细介绍参考[配置管理](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/driver/driver-hdf-manage.md)。 - - ``` - /* 马达数据配置模板(vibrator_config.hcs) */ - root { - vibratorConfig { - boardConfig { - match_attr = "hdf_vibrator_driver"; //需要和马达设备配置match_attr字段保持一致 - vibratorAttr { - /* 0:转子 1:线性 */ - deviceType = 1; //设备类型 - supportPreset = 1; //支持的预设类型 - } - vibratorHapticConfig { - haptic_clock_timer { - effectName = "haptic.clock.timer"; - type = 1; // 0 内置模式, 1 时间序列 - seq = [600, 600, 200, 600]; // 时间序列 - } - haptic_default_effect { - effectName = "haptic.default.effect"; - type = 0; - seq = [0, 3, 800, 1]; - } - } - } - } - } - ``` - -3. 完成马达振动和停止接口开发,会根据振动效果的模式创建和销毁定时器。 - - 马达硬件服务调用StartOnce接口动态配置持续振动时间;调用StartEffect接口启动静态配置的振动效果,为驱动开发者提供抽象的配置接口能力。 - - ``` - /* 按照指定持续时间触发振动马达,duration为振动持续时长 */ - static int32_t StartOnce(struct HdfSBuf *data, struct HdfSBuf *reply) - { - uint32_t duration; - int32_t ret; - struct VibratorEffectCfg config; - struct VibratorDriverData *drvData = GetVibratorDrvData(); - (void)reply; - ...... - config.cfgMode = VIBRATOR_MODE_ONCE; - config.duration = duration; - config.effect = NULL; - /* 据振动效果的模式创建 */ - ret = StartHaptic(&config); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: start haptic fail!", __func__); - return ret; - } - - return HDF_SUCCESS; - } - - /* 按照预置效果启动马达,effectType表示预置的预置效果 */ - static int32_t StartEffect(struct HdfSBuf *data, struct HdfSBuf *reply) - { - int32_t ret; - const char *effect = NULL; - struct VibratorEffectCfg config; - struct VibratorDriverData *drvData = GetVibratorDrvData(); - (void)reply; - ...... - config.cfgMode = VIBRATOR_MODE_PRESET; - config.duration = 0; - config.effect = effect; - - ret = StartHaptic(&config); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: start haptic fail!", __func__); - return ret; - } - - return HDF_SUCCESS; - } - - /* 按照指定的振动模式停止马达振动 */ - static int32_t Stop(struct HdfSBuf *data, struct HdfSBuf *reply) - { - int32_t ret; - int32_t mode; - struct VibratorDriverData *drvData = GetVibratorDrvData(); - (void)reply; - ...... - /* 停止马达效果振动,销毁马达定时器 */ - ret = StopHaptic(); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: stop haptic fail!", __func__); - return ret; - } - - (void)OsalMutexLock(&drvData->mutex); - drvData->mode = VIBRATOR_MODE_BUTT; - (void)OsalMutexUnlock(&drvData->mutex); - - return HDF_SUCCESS; - } - ``` - -4. 马达驱动模型提供给开发者马达驱动差异化接口,开发者实现差异化接口。 - - - 此接口在差异化器件驱动初始化成功时,注册差异实现接口,方便实现器件差异的驱动接口。 - - ``` - /* 注册马达差异化实现接口 */ - int32_t RegisterVibrator(struct VibratorOps *ops) - { - struct VibratorDriverData *drvData = GetVibratorDrvData(); - - CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(ops, HDF_FAILURE); - CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(drvData, HDF_FAILURE); - - (void)OsalMutexLock(&drvData->mutex); - drvData->ops.Start = ops->Start; - drvData->ops.StartEffect = ops->StartEffect; - drvData->ops.Stop = ops->Stop; - (void)OsalMutexUnlock(&drvData->mutex); - - return HDF_SUCCESS; - } - ``` - - - 马达驱动模型提供给开发者马达驱动差异化接口,具体实现如下: - - ``` - /* 按照指定持续时间触发马达线性驱动 */ - static int32_t StartLinearVibrator() - { - int32_t ret; - struct VibratorLinearDriverData *drvData = GetLinearVibratorData(); - CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(drvData, HDF_FAILURE); - ...... - ret = GpioWrite(drvData->gpioNum, GPIO_VAL_LOW); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: pull gpio%d to %d level failed", __func__, drvData->gpioNum, GPIO_VAL_LOW); - return ret; - } - return HDF_SUCCESS; - } - - /* 按照预置振动效果启动马达线性驱动 */ - static int32_t StartEffectLinearVibrator(uint32_t effectType) - { - (void)effectType; - HDF_LOGE("%s: vibrator set build-in effect no support!", __func__); - return HDF_SUCCESS; - } - - /* 按照指定的振动模式停止马达线性驱动 */ - static int32_t StopLinearVibrator() - { - int32_t ret; - struct VibratorLinearDriverData *drvData = GetLinearVibratorData(); - CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(drvData, HDF_FAILURE); - ...... - ret = GpioWrite(drvData->gpioNum, GPIO_VAL_HIGH); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: pull gpio%d to %d level failed", __func__, drvData->gpioNum, GPIO_VAL_HIGH); - return ret; - } - return HDF_SUCCESS; - } - ``` - - - diff --git a/website/docs/_posts/zh-cn/device-dev/driver/driver-peripherals.md b/website/docs/_posts/zh-cn/device-dev/driver/driver-peripherals.md deleted file mode 100644 index 639218661015e47147eb97d77c20fb324347ba8a..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/driver/driver-peripherals.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -title: driver-peripherals -permalink: /pages/extra/665bcf/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 外设驱动使用 - -- **[LCD](/pages/0105020401)** - -- **[TOUCHSCREEN](/pages/0105020402)** - -- **[SENSOR](/pages/0105020403)** - -- **[WLAN](/pages/0105020404)** - -- **[AUDIO](/pages/0105020405)** \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/device-dev/driver/driver-platform.md b/website/docs/_posts/zh-cn/device-dev/driver/driver-platform.md deleted file mode 100644 index 4e111dc3bee24f80d0b40ffb643b713bf13f3312..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/driver/driver-platform.md +++ /dev/null @@ -1,40 +0,0 @@ ---- -title: driver-platform -permalink: /pages/extra/6777d1/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 平台驱动使用 - -- **[ADC](/pages/0105020301)** - -- **[GPIO](/pages/0105020302)** - -- **[HDMI](/pages/0105020303)** - -- **[I2C](/pages/0105020304)** - -- **[I3C](/pages/0105020305)** - -- **[MIPI-CSI](/pages/0105020306)** - -- **[MIPI-DSI](/pages/0105020307)** - -- **[PWM](/pages/0105020308)** - -- **[RTC](/pages/0105020309)** - -- **[SDIO](/pages/010502030a)** - -- **[SPI](/pages/010502030b)** - -- **[UART](/pages/010502030c)** - -- **[WATCHDOG](/pages/010502030d)** diff --git a/website/docs/_posts/zh-cn/device-dev/driver/driver.md b/website/docs/_posts/zh-cn/device-dev/driver/driver.md deleted file mode 100644 index dddb80d2430a59824b7f1e2f0112f53b1af12d93..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/driver/driver.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -title: driver -permalink: /pages/extra/ce6aec/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 驱动 - -- **[HDF驱动框架](/pages/extra/cda5c5/)** - -- **[平台驱动开发](/pages/extra/6b1378/)** - -- **[平台驱动使用](/pages/extra/6777d1/)** - -- **[外设驱动使用](/pages/extra/665bcf/)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/faqs/Readme-CN.md b/website/docs/_posts/zh-cn/device-dev/faqs/Readme-CN.md deleted file mode 100644 index 6c12ae660a163b0af5c922a5f347326db18cc364..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/faqs/Readme-CN.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -title: Readme-CN -permalink: /pages/extra/3a26c5/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# FAQs - -- [常见问题概述](/pages/010c0401) -- [环境搭建常见问题](/pages/010c0402) -- [编译构建子系统常见问题](/pages/010c0403) -- [烧录常见问题](/pages/010c0404) -- [内核常见问题](/pages/010c0405) -- [移植常见问题](/pages/010c0406) -- [启动恢复常见问题](/pages/010c0407) -- [系统应用常见问题](/pages/010c0408) - diff --git a/website/docs/_posts/zh-cn/device-dev/get-code/Readme-CN.md b/website/docs/_posts/zh-cn/device-dev/get-code/Readme-CN.md deleted file mode 100644 index 8271441e54dbb5a66c6d66dd5d82798cfbc5e631..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/get-code/Readme-CN.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: Readme-CN -permalink: /pages/extra/95ee54/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 获取源码 - -- [获取源码](/pages/extra/b5ebea/) - - [源码获取](/pages/extra/51fbe5/) - -- [获取工具](/pages/extra/cc782c/) - - [Docker编译环境](/pages/010b01) - - [IDE](/pages/010b02) - diff --git a/website/docs/_posts/zh-cn/device-dev/get-code/gettools-acquire.md b/website/docs/_posts/zh-cn/device-dev/get-code/gettools-acquire.md new file mode 100644 index 0000000000000000000000000000000000000000..37e3d79b61ca51ed20cb53ab3049dc9d10d6d0eb --- /dev/null +++ b/website/docs/_posts/zh-cn/device-dev/get-code/gettools-acquire.md @@ -0,0 +1,325 @@ +--- +title: gettools-acquire.md +permalink: /pages/extra/70d134/ +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +date: 2021-12-30 12:57:40 +--- +# Docker编译环境 + +- [Docker环境介绍](#section107932281315) +- [环境准备](#section7337134183512) +- [独立Docker环境](#section2858536103611) + - [搭建Docker环境-轻量系统类设备(参考内存≥128KB)和小型系统类设备(参考内存≥1MB)](#section319412277287) + - [编译源码-轻量系统类设备(参考内存≥128KB)和小型系统类设备(参考内存≥1MB)](#section631485163615) + - [搭建Docker环境-标准系统类设备(参考内存≥128MB)](#section13585262391) + - [编译源码-标准系统类设备(参考内存≥128MB)](#section193711513406) + +- [基于HPM的Docker环境](#section485713518337) + - [搭建Docker环境](#section3295842510) + - [获取及编译源码](#section69141039143518) + + +## Docker环境介绍 + +OpenHarmony为开发者提供了两种Docker环境,以帮助开发者快速完成复杂的开发环境准备工作。两种Docker环境及适用场景如下: + +- 独立Docker环境:适用于直接基于Ubuntu、Windows操作系统平台进行版本编译的场景。 +- 基于HPM的Docker环境:适用于使用HPM工具进行发行版编译的场景。 + +**表 1** Docker镜像介绍 + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Docker环境

+

系统类型

+

运行平台

+

Docker镜像仓库

+

标签

+

独立 Docker环境

+

轻量和小型系统

+

Ubuntu/Windows

+

swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker

+

0.0.5

+

标准系统

+

Ubuntu

+

swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker-standard

+

0.0.2

+

HPM Docker环境

+

轻量和小型系统

+

Ubuntu/Windows

+

swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker

+

0.0.3

+
+ +## 环境准备 + +在使用docker环境前需要先完成以下操作: + +1. 安装Docker,Docker安装请参考[官方指导](https://docs.docker.com/engine/install/)。 +2. 获取OpenHarmony源码,请参考[获取源码](/pages/extra/dade07/)。 + + >![](/images/zh-cn/device-dev/public_sys-resources/icon-note.gif) **说明:** + >HPM Docker环境无需单独获取源码。 + + +## 独立Docker环境 + +OpenHarmony的Docker镜像托管在[HuaweiCloud SWR](https://console.huaweicloud.com/swr/?region=cn-south-1#/app/warehouse/warehouseMangeDetail/goldensir/openharmony-docker/openharmony-docker?type=ownImage)上。开发者可以通过该镜像在很大程度上简化编译前的环境配置。下文将介绍具体使用步骤。 + +### 搭建Docker环境-轻量系统类设备(参考内存≥128KB)和小型系统类设备(参考内存≥1MB) + +**方式一:从HuaweiCloud SWR上直接获取Docker镜像进行构建:** + +1. 获取Docker镜像。 + + ``` + docker pull swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker:0.0.5 + ``` + +2. 进入OpenHarmony代码根目录执行如下命令,从而进入Docker构建环境。 + + ubuntu下执行: + + ``` + docker run -it -v $(pwd):/home/openharmony swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker:0.0.5 + ``` + + windows下执行(假设源码目录为D:\\OpenHarmony): + + ``` + docker run -it -v D:\OpenHarmony:/home/openharmony swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker:0.0.5 + ``` + + +**方式二:通过Dockerfile 构建本地Docker镜像进行构建** + +1. 获取Dockerfile脚本文件,用来构建本地Docker镜像。 + + ``` + git clone https://gitee.com/openharmony/docs.git + ``` + +2. 进入Dockerfile代码目录路径执行Docker镜像构建命令。 + + ``` + cd docs/docker + ./build.sh + ``` + +3. 进入OpenHarmony代码根目录执行如下命令,从而进入Docker构建环境。 + + ubuntu下执行: + + ``` + docker run -it -v $(pwd):/home/openharmony swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker:0.0.5 + ``` + + windows下执行(假设源码目录为D:\\OpenHarmony): + + ``` + docker run -it -v D:\OpenHarmony:/home/openharmony swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker:0.0.5 + ``` + + +### 编译源码-轻量系统类设备(参考内存≥128KB)和小型系统类设备(参考内存≥1MB) + +通过如下编译脚本启动轻量系统类设备(参考内存≥128KB)和小型系统类设备(参考内存≥1MB)的编译。下文以Hi3516平台为例说明具体编译步骤。 + +设置编译路径,选择当前路径。 + +``` +hb set + . +``` + +**图 1** 设置编译界面 + + +![](/images/zh-cn/device-dev/get-code/figure/zh-cn_image_0000001101413884.png) + +>![](/images/zh-cn/device-dev/public_sys-resources/icon-note.gif) **说明:** +>当前开发板平台和编译界面的对应关系如下: +>- Hi3861:wifiiot\_hispark\_pegasus@hisilicon +>- Hi3516:ipcamera\_hispark\_taurus@hisilicon +>- Hi3518:ipcamera\_hispark\_aries@hisilicon + +1. 选择ipcamera\_hispark\_taurus@hisilicon并回车。 +2. 执行编译。 + + ``` + hb build -f + ``` + +3. 查看编译结果。 + + 编译结果文件生成在out/hispark\_taurus/ipcamera\_hispark\_taurus目录下。 + + +### 搭建Docker环境-标准系统类设备(参考内存≥128MB) + +**方式一:从HuaweiCloud SWR上直接获取Docker镜像进行构建:** + +1. 获取Docker镜像。 + + ``` + docker pull swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker-standard:0.0.2 + ``` + +2. 进入OpenHarmony代码根目录执行如下命令,从而进入Docker构建环境。 + + ``` + docker run -it -v $(pwd):/home/openharmony swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker-standard:0.0.2 + ``` + + +**方式二:通过Dockerfile 构建本地Docker镜像进行构建** + +1. 获取Dockerfile脚本文件,用来构建本地Docker镜像。 + + ``` + git clone https://gitee.com/openharmony/docs.git + ``` + +2. 进入Dockerfile代码目录路径执行Docker镜像构建命令。 + + ``` + cd docs/docker/standard + ./build.sh + ``` + +3. 进入OpenHarmony代码根目录执行如下命令,从而进入Docker构建环境。 + + ``` + docker run -it -v $(pwd):/home/openharmony openharmony-docker-standard:0.0.2 + ``` + + +### 编译源码-标准系统类设备(参考内存≥128MB) + +1. 在源码的根目录执行预处理脚本。 + + ``` + ../scripts/prepare.sh + ``` + +2. 通过如下编译脚本启动标准系统类设备(参考内存≥128MB)的编译。 + + ``` + ./build.sh --product-name {product_name} + ``` + + \{product\_name\}为当前版本支持的平台。比如:Hi3516DV300等。 + + 编译所生成的文件都归档在out/ohos-arm-release/目录下,结果镜像输出在 out/ohos-arm-release/packages/phone/images/ 目录下。 + + +>![](/images/zh-cn/device-dev/public_sys-resources/icon-note.gif) **说明:** +>退出Docker执行exit命令即可。 + +## 基于HPM的Docker环境 + +docker\_dist是一个[HPM](https://hpm.harmonyos.com/)系统中的模板组件,能够帮助用户快速初始化HPM工程,利用docker镜像来快速编译OpenHarmony发行版,在很大程度上简化了编译前的环境配置。开发者在配置好Ubuntu和[hpm-cli](/pages/000802)开发环境后,可以通过以下步骤来使用我们提供的Docker环境。 + +### 搭建Docker环境 + +1. 初始化安装模板。在任意工作目录中执行以下命令。 + + ``` + hpm init -t @ohos/docker_dist + ``` + +2. 修改publishAs。 + + 因为获取到的是模板类型的包,要把包的类型改为需要的类型。 在当前目录下打开bundle.json文件,把"publishAs"字段的值由"template"改为"distribution"。 + + +### 获取及编译源码 + +执行编译。自动安装docker只能在Ubuntu环境下执行,如果其他环境,需要用户自行安装docker,然后拉取镜像,执行编译。 + +- **自动安装docker(Ubuntu环境)** + + 以下命令可以帮助用户自动安装docker, 拉取镜像,并且在容器中开始运行对应解决方案的拉取和编译。 + + **方式一:** + + 命令后接参数指定解决方案,格式如下: + + ``` + hpm run docker solution={product} + ``` + + \{product\}为需编译的解决方案,如:@ohos/hispark\_taurus、@ohos/hispark\_aries、@ohos/hispark\_pegasus。 + + **方式二:** + + 设置环境变量来选择解决方案,再执行编译命令。 + + 1. 选择解决方案。 + + ``` + export solution={product} + ``` + + \{product\}为需编译的解决方案,如:@ohos/hispark\_taurus、@ohos/hispark\_aries、@ohos/hispark\_pegasus。 + + 2. 获取源码及执行编译。 + + ``` + hpm run docker + ``` + + 以上两种方式以@ohos/hispark\_taurus为例,执行成功结果如下: + + ``` + ...... + ohos ipcamera_hispark_taurus build success! + @ohos/hispark_taurus: distribution building completed. + ``` + + +- **自行安装docker(非Ubuntu环境)** + + 自行安装docker相关操作如下: + + ``` + # 拉取镜像 + docker pull swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker:0.0.3# linux环境下的编译 + hpm run distWithDocker solution={product} + # windows下的编译,需要配置gitbash + hpm config set shellPath "gitbash路径" + hpm run distWithDocker solution={product} + ``` + + diff --git a/website/docs/_posts/zh-cn/device-dev/get-code/gettools-ide.md b/website/docs/_posts/zh-cn/device-dev/get-code/gettools-ide.md new file mode 100644 index 0000000000000000000000000000000000000000..aaf5dc79be21b791d7d0c042832aabca45326820 --- /dev/null +++ b/website/docs/_posts/zh-cn/device-dev/get-code/gettools-ide.md @@ -0,0 +1,30 @@ +--- +title: gettools-ide.md +permalink: /pages/extra/20bf1d/ +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +date: 2021-12-30 12:57:44 +--- +# IDE + +- [获取设备开发工具(HUAWEI DevEco Device Tool)](#section2452141120244) +- [获取应用开发工具(HUAWEI DevEco Studio)](#section0904101019258) + +## 获取设备开发工具(HUAWEI DevEco Device Tool) + +HUAWEI DevEco Device Tool是OpenHarmony面向智能设备开发者提供的一站式集成开发环境,支持OpenHarmony的组件按需定制,支持代码编辑、编译、烧录、调试等功能,支持C/C++语言,以插件的形式部署在Visual Studio Code上。具体可参见[获取工具](https://device.harmonyos.com/cn/ide)和[工具使用指南](https://device.harmonyos.com/cn/docs/ide/user-guides/service_introduction-0000001050166905)**。** + +Huawei DevEco Device Tool支持 OpenHarmony设备开发的演进路标如下: + +![](/images/zh-cn/device-dev/get-code/figure/3-28.png) + +## 获取应用开发工具(HUAWEI DevEco Studio) + +HUAWEI DevEco Studio(以下简称DevEco Studio)是面向华为终端全场景多设备的一站式集成开发环境(IDE),为开发者提供工程模板创建、开发、编译、调试、发布等E2E的OpenHarmony应用开发服务。通过使用DevEco Studio,开发者可以更高效的开发具备OpenHarmony分布式能力的应用,进而提升创新效率。具体可参见[获取工具](https://developer.harmonyos.com/cn/develop/deveco-studio)和[工具使用指南](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/tools_overview-0000001053582387)。 + diff --git a/website/docs/_posts/zh-cn/device-dev/get-code/gettools.md b/website/docs/_posts/zh-cn/device-dev/get-code/gettools.md deleted file mode 100644 index fe73d28ffade78fad44e0a75900a68b40890da65..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/get-code/gettools.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: gettools -permalink: /pages/extra/cc782c/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 获取工具 - -- **[Docker编译环境](/pages/010b01)** - -- **[IDE](/pages/010b02)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/get-code/sourcecode-acquire.md b/website/docs/_posts/zh-cn/device-dev/get-code/sourcecode-acquire.md index 9c12704beb7e9fe082bd7a00a9fe55fb29ead163..69f3641e2ea1e6d8e3cd76eff09bf348bc5d2d9f 100644 --- a/website/docs/_posts/zh-cn/device-dev/get-code/sourcecode-acquire.md +++ b/website/docs/_posts/zh-cn/device-dev/get-code/sourcecode-acquire.md @@ -1,50 +1,48 @@ --- -title: sourcecode-acquire -permalink: /pages/extra/51fbe5/ +title: sourcecode-acquire.md +permalink: /pages/extra/dade07/ navbar: true sidebar: false prev: false next: false -search: true -article: true +search: false +article: false comment: false editLink: false -date: 2022-02-14 21:31:38 +date: 2021-12-30 12:57:40 --- -# 获取源码 +# 源码获取 - [OpenHarmony介绍](#section6370143622110) -- [获取源码概述](#section12763342204) -- [获取方式1:从码云仓库获取](#section537312010229) +- [源码获取概述](#section12763342204) +- [获取方式1:从代码仓库获取](#section537312010229) - [适用场景](#section10881513459) - [前提条件](#section102871547153314) - [操作步骤](#section429012478331) -- [获取方式2:从DevEco Marketplace获取](#section463013147412) +- [获取方式2:从HPM获取](#section463013147412) - [适用场景](#section26661067443) - [前提条件](#section17544943123315) - [操作步骤](#section954619433333) - [获取方式3:从镜像站点获取](#section1186691118430) -- [获取方式4:从github镜像仓库获取\(每天UTC时间23点同步\)](#section23448418360) - [源码目录简介](#section1072115612811) ## OpenHarmony介绍 OpenHarmony是由开放原子开源基金会(OpenAtom Foundation)孵化及运营的开源项目,目标是面向全场景、全连接、全智能时代,搭建一个智能终端设备操作系统的框架和平台,促进万物互联产业的繁荣发展。 -开源代码仓库地址:[https://openharmony.gitee.com](https://openharmony.gitee.com)。 +开源代码仓库地址:[https://openharmony.gitee.com](https://openharmony.gitee.com) -## 获取源码概述 +## 源码获取概述 -本文档将介绍如何获取OpenHarmony源码并说明OpenHarmony的源码目录结构。OpenHarmony的代码以[组件](/pages/01060101)的形式开放,开发者可以通过如下其中一种方式获取: +本文档将介绍如何获取OpenHarmony源码并说明OpenHarmony的源码目录结构。OpenHarmony的代码以[组件](/pages/000800)的形式开放,开发者可以通过如下其中一种方式获取: -- **获取方式1**:从码云代码仓库获取。通过repo或git工具从代码仓库中下载,此方式可获取最新代码。 -- **获取方式2**:通过[DevEco Marketplace](https://repo.harmonyos.com/#/cn/home)网站获取。访问[DevEco Marketplace](https://repo.harmonyos.com/#/cn/home)网站,查找满足需求的开源发行版,直接下载(或者定制后下载),再通过hpm-cli命令工具将所需的组件及工具链下载、安装到本地。 +- **获取方式1**:从代码仓库获取。通过repo或git工具从代码仓库中下载,此方式可获取最新代码。 +- **获取方式2**:通过HPM包管理器获取。在[HPM](https://hpm.harmonyos.com)网站,查找满足需求的开源发行版,直接下载(或者定制后下载),再通过hpm-cli命令工具将所需的组件及工具链下载、安装到本地。 - **获取方式3**:从镜像站点下载归档后的发行版压缩文件。如果要获取旧版本的源码,也可通过此方式获取,此方式下载速度较快。 -- **获取方式4**:从github代码仓库获取。通过repo或git工具从代码仓库中下载,此方式可获取最新代码。 -## 获取方式1:从码云仓库获取 +## 获取方式1:从代码仓库获取 ### 适用场景 @@ -63,7 +61,7 @@ OpenHarmony是由开放原子开源基金会(OpenAtom Foundation)孵化及 1. 注册码云gitee账号。 2. 注册码云SSH公钥,请参考[码云帮助中心](https://gitee.com/help/articles/4191)。 -3. 安装[git客户端](https://git-scm.com/book/zh/v2/%E8%B5%B7%E6%AD%A5-%E5%AE%89%E8%A3%85-Git)和[git-lfs](https://gitee.com/vcs-all-in-one/git-lfs?_from=gitee_search#downloading)并配置用户信息。 +3. 安装[git客户端](http://git-scm.com/book/zh/v2/%E8%B5%B7%E6%AD%A5-%E5%AE%89%E8%A3%85-Git)和[git-lfs](https://gitee.com/vcs-all-in-one/git-lfs?_from=gitee_search#downloading)并配置用户信息。 ``` git config --global user.name "yourname" @@ -82,14 +80,14 @@ OpenHarmony是由开放原子开源基金会(OpenAtom Foundation)孵化及 ### 操作步骤 -**获取轻量/小型/标准系统源码** +**获取轻量/小型/标准系统(2.0 Canary)源码** ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->Master主干为开发分支,开发者可通过Master主干获取最新特性。发布版本代码相对比较稳定,开发者可基于发布版本代码进行商用功能开发。 +>![](/images/zh-cn/device-dev/public_sys-resources/icon-note.gif) **说明:** +>主干代码为开发分支,开发者可通过主干代码获取最新特性。release分支代码相对比较稳定,开发者可基于release分支代码进行商用功能开发。 - **OpenHarmony主干代码获取** - 方式一(推荐):通过repo + ssh下载(需注册公钥,请参考[码云帮助中心](https://gitee.com/help/articles/4191))。 + 方式一(推荐):通过repo + ssh 下载(需注册公钥,请参考[码云帮助中心](https://gitee.com/help/articles/4191))。 ``` repo init -u git@gitee.com:openharmony/manifest.git -b master --no-repo-verify @@ -97,7 +95,7 @@ OpenHarmony是由开放原子开源基金会(OpenAtom Foundation)孵化及 repo forall -c 'git lfs pull' ``` - 方式二:通过repo + https下载。 + 方式二:通过repo + https 下载。 ``` repo init -u https://gitee.com/openharmony/manifest.git -b master --no-repo-verify @@ -105,16 +103,27 @@ OpenHarmony是由开放原子开源基金会(OpenAtom Foundation)孵化及 repo forall -c 'git lfs pull' ``` -- **OpenHarmony发布版本代码获取** - OpenHarmony发布版本获取源码方式请参考[Release-Notes](/pages/010104)。 +- **OpenHarmony release 分支最新代码获取** + >![](/images/zh-cn/device-dev/public_sys-resources/icon-note.gif) **说明:** + >当前通过release分支只能获取轻量和小型系统源码。 -## 获取方式2:从DevEco Marketplace获取 + 通过repo下载。 + + ``` + repo init -u https://gitee.com/openharmony/manifest.git -b OpenHarmony_1.0.1_release --no-repo-verify + repo sync -c + repo forall -c 'git lfs pull' + ``` + +- OpenHarmony其他版本源码获取方式请参考版本[Release-Notes](https://gitee.com/openharmony/docs/blob/master/zh-cn/release-notes/Readme.md)。 + +## 获取方式2:从HPM获取 ### 适用场景 -对于刚接触OpenHarmony的新用户,希望能够参考一些示例解决方案从而进行快速开发。可以在[DevEco Marketplace](https://repo.harmonyos.com/#/cn/home)网站获取下载开源发行版,也可以在开源发行版的基础上定制(添加或删除组件)。然后通过包管理器命令行工具(hpm-cli)将需要的组件及相关的编译工具链全部下载、安装到本地。 +对于刚接触OpenHarmony的新用户,希望能够参考一些示例解决方案从而进行快速开发。可以在[HPM](https://hpm.harmonyos.com)网站获取下载开源发行版,也可以在开源发行版的基础上定制(添加或删除组件)。然后通过包管理器命令行工具(hpm-cli)将需要的组件及相关的编译工具链全部下载、安装到本地。 ### 前提条件 @@ -124,7 +133,7 @@ OpenHarmony是由开放原子开源基金会(OpenAtom Foundation)孵化及 官网下载并在本地安装Node.js. - [Node.js](https://nodejs.org/) 版本需不低于12.x \(包含npm 6.14.4\),推荐安装LTS版本。 + 推荐安装 [Node.js](https://nodejs.org/) 12.x \(包含 npm 6.14.4\)或更高版本 \(推荐 12.13.0+\)。 2. 通过Node.js自带的npm安装hpm命令行工具。 @@ -150,13 +159,15 @@ OpenHarmony是由开放原子开源基金会(OpenAtom Foundation)孵化及 ### 操作步骤 1. 查找发行版。 - 1. 访问[DevEco Marketplace](https://repo.harmonyos.com/#/cn/home),设定搜索的对象为“设备组件“,并在左侧边栏选择“开源发行版“,如下图所示。 + 1. 打开包管理页面[HPM](https://hpm.harmonyOS.com),设定搜索的对象为“发行版“,如下图所示。 2. 在搜索框输入关键字搜索,如“摄像头”。 3. 结果中显示与关键字匹配的发行版,可以进一步根据组件类别等过滤条件(如:适配的开发板,内核)精确筛选。 4. 查找合适的发行版,点击查看发行版的详情介绍。 - **图 1** 包管理 - ![](/images/device-dev/get-code/figure/包管理.png "包管理") + **图 1** 包管理 + + + ![](/images/zh-cn/device-dev/get-code/figure/zh-cn_image_0000001119915556.png) 2. 了解发行版详情。 @@ -164,8 +175,10 @@ OpenHarmony是由开放原子开源基金会(OpenAtom Foundation)孵化及 2. 点击「直接下载」,将发行版下载到本地。 3. 点击「定制组件」,将对发行版包含的组件进行定制(添加/删除)。 - **图 2** 发行版示例 - ![](/images/device-dev/get-code/figure/发行版示例.png "发行版示例") + **图 2** 发行版示例 + + + ![](/images/zh-cn/device-dev/get-code/figure/zh-cn_image_0000001119755646.png) 3. 定制组件。 1. 进入发行版的定制页面,如下图所示。 @@ -173,211 +186,169 @@ OpenHarmony是由开放原子开源基金会(OpenAtom Foundation)孵化及 3. 在右边填写您的项目基本信息,包括名称、版本、描述等信息。 4. 点击“下载“,系统会根据您的选择,生成相应的OpenHarmony代码结构文件\(如my\_cust\_dist.zip\),保存至本地文件。 - **图 3** 组件定制 - ![](/images/device-dev/get-code/figure/组件定制.png "组件定制") + **图 3** 组件定制 + -4. 安装组件。 - 1. 解压下载的压缩文件,用命令行工具CMD(Linux下的Shell终端)。 - 2. 在解压后的文件目录下执行hpm install指令,系统会自动下载并安装组件。安装窗口显示“Install sucessful”表示组件下载及安装成功。 - 3. 下载的组件将保存在工程目录下的ohos\_bundles文件夹中(部分组件安装后会将源码复制到指定目录下)。 + ![](/images/zh-cn/device-dev/get-code/figure/zh-cn_image_0000001166715379.png) + +4. 下载安装组件。 + 1. 解压下载的压缩文件,用命令行工具CMD(Linux下的Shell终端) + 2. 在解压后的文件目录下执行hpm install指令 + 3. 下载的组件存在工程目录下的ohos\_bundles文件夹中(部分组件安装后会将源码复制到指定目录下)。 ## 获取方式3:从镜像站点获取 为了获得更好的下载性能,您可以选择从以下站点的镜像库获取源码或者对应的解决方案。 -本部分只提供OpenHarmony Master最新版本和LTS最新版本的获取源码方式, 其他版本获取源码方式以及具体版本信息请参考[Release-Notes](/pages/010104)。 +>![](/images/zh-cn/device-dev/public_sys-resources/icon-note.gif) **说明:** +>- 本部分只提供OpenHarmony Master最新版本和LTS最新版本的源码获取方式, 其他版本源码获取方式以及具体版本信息请参考[Release-Notes](https://gitee.com/openharmony/docs/blob/master/zh-cn/release-notes/Readme.md) +>- 当前Master 1.0版本已经不再维护。 -**表 1** 获取源码路径 +**表 1** 源码获取路径 - - - - - - -

LTS版本源码

-

版本信息

-

下载站点

-

SHA256校验码

-

全量代码(标准、轻量和小型系统)

+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

LTS版本源码

3.0

+

版本信息

站点

+

下载站点

SHA256校验码

+

SHA256校验码

标准系统解决方案(二进制)

+

全量代码(轻量和小型系统)

3.0

+

1.1.1

站点

+

站点

SHA256校验码

+

SHA256 校验码

Hi3861解决方案(二进制)

+

Hi3861解决方案(二进制)

3.0

+

1.1.1

站点

+

站点

SHA256校验码

+

SHA256 校验码

Hi3518解决方案(二进制)

+

Hi3518解决方案(二进制)

3.0

+

1.1.1

站点

+

站点

SHA256校验码

+

SHA256 校验码

Hi3516解决方案-LiteOS(二进制)

+

Hi3516解决方案(二进制)

3.0

+

1.1.1

站点

+

站点

SHA256校验码

+

SHA256 校验码

Hi3516解决方案-Linux(二进制)

+

RELEASE-NOTES

3.0

+

1.1.1

站点

+

站点

SHA256校验码

+

-

RELEASE-NOTES

+

Master版本源码

3.0

+

版本信息

站点

+

下载站点

-

+

SHA256校验码

Master版本源码

+

全量代码(标准系统)

版本信息

+

2.0 Canary

下载站点

+

站点1站点2

SHA256校验码

+

SHA256校验码

全量代码Beta版本(标准、轻量和小型系统)

+

全量代码(轻量和小型系统)

3.1 Beta

+

1.0(不再维护)

站点

+

站点

SHA256校验码

+

SHA256 校验码

Hi3516标准系统解决方案(二进制)

+

Hi3861解决方案(二进制)

3.1 Beta

+

1.0(不再维护)

站点

+

站点

SHA256校验码

+

SHA256 校验码

RK3568标准系统解决方案(二进制)

+

Hi3518解决方案(二进制)

3.1 Beta

+

1.0(不再维护)

站点

+

站点

SHA256校验码

+

SHA256 校验码

Hi3861解决方案(二进制)

+

Hi3516解决方案(二进制)

3.1 Beta

+

1.0(不再维护)

站点

+

站点

SHA256校验码

+

SHA256 校验码

Hi3516解决方案-LiteOS(二进制)

+

RELEASE-NOTES

3.1 Beta

+

1.0(不再维护)

站点

+

站点

SHA256校验码

+

-

Hi3516解决方案-Linux(二进制)

+

编译工具链

3.1 Beta

+

版本信息

站点

+

下载站点

SHA256校验码

+

SHA256校验码

RELEASE-NOTES

+

编译工具链获取清单

3.1 Beta

+

-

站点

+

站点

-

-

编译工具链

-

版本信息

-

下载站点

-

SHA256校验码

-

编译工具链获取清单

-

-

-

站点

-

-

+

-

-## 获取方式4:从github镜像仓库获取\(每天UTC时间23点同步\) - -方式一(推荐):通过repo + ssh下载(需注册公钥,请参考[GitHub帮助中心](https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account))。 - -``` -repo init -u git@github.com:openharmony/manifest.git -b master --no-repo-verify -repo sync -c -repo forall -c 'git lfs pull' -``` - -方式二:通过repo + https下载。 - -``` -repo init -u https://github.com/openharmony/manifest.git -b master --no-repo-verify -repo sync -c -repo forall -c 'git lfs pull' -``` - ## 源码目录简介 -下表是OpenHarmony源码目录: +下表是OpenHarmony源码的目录及简单说明: **表 2** 源码目录 diff --git a/website/docs/_posts/zh-cn/device-dev/get-code/sourcecode.md b/website/docs/_posts/zh-cn/device-dev/get-code/sourcecode.md deleted file mode 100644 index 253763406e7ec063fe3152d8f494479f79cf3637..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/get-code/sourcecode.md +++ /dev/null @@ -1,18 +0,0 @@ ---- -title: sourcecode -permalink: /pages/extra/b5ebea/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 获取源码 - -- **[源码获取](/pages/extra/51fbe5/)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/glossary/Readme-CN.md b/website/docs/_posts/zh-cn/device-dev/glossary/Readme-CN.md deleted file mode 100644 index 61bce0816689a14ad7c737b03d2773513a5715b3..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/glossary/Readme-CN.md +++ /dev/null @@ -1,17 +0,0 @@ ---- -title: Readme-CN -permalink: /pages/extra/ab4291/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 术语 - -- [术语](/pages/010103) - diff --git a/website/docs/_posts/zh-cn/device-dev/guide/Readme-CN.md b/website/docs/_posts/zh-cn/device-dev/guide/Readme-CN.md deleted file mode 100644 index f74aa5a48b5b3a81162bfdd87f4801169b54832c..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/guide/Readme-CN.md +++ /dev/null @@ -1,47 +0,0 @@ ---- -title: Readme-CN -permalink: /pages/extra/b89d59/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 设备开发指南 - -- [轻量和小型系统设备](/pages/extra/4cd9dc/) - - [WLAN连接类产品](/pages/extra/a9f9b7/) - - [LED外设控制](/pages/0107010101) - - [集成三方SDK](/pages/0107010102) - - [无屏摄像头类产品](/pages/extra/3b686a/) - - [摄像头控制](/pages/extra/b2b869/) - - [概述](/pages/010701020101) - - [示例开发](/pages/extra/d23bd1/) - - [拍照开发指导](/pages/01070102010201) - - [录像开发指导](/pages/01070102010202) - - [应用实例](/pages/010701020103) - - [带屏摄像头类产品](/pages/extra/51c9a4/) - - [屏幕和摄像头控制](/pages/extra/ac3f29/) - - [概述](/pages/010701030101) - - [示例开发](/pages/extra/781d25/) - - [拍照开发指导](/pages/01070103010201) - - [录像开发指导](/pages/01070103010202) - - [预览开发指导](/pages/01070103010203) - - [应用实例](/pages/010701030103) - - [视觉应用开发](/pages/extra/d06f24/) - - [概述](/pages/010701030201) - - [开发准备](/pages/010701030202) - - [添加页面](/pages/010701030203) - - [开发首页](/pages/010701030204) - - [开发详情页](/pages/010701030205) - - [调试打包](/pages/010701030206) - - [真机运行](/pages/010701030207) - - [常见问题](/pages/010701030208) -- [标准系统设备](/pages/extra/c37a91/) - - [时钟应用开发指导](/pages/01070201) - - [平台驱动开发示例](/pages/01070202) - - [外设驱动开发示例](/pages/01070203) \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/device-dev/guide/device-camera-control-demo.md b/website/docs/_posts/zh-cn/device-dev/guide/device-camera-control-demo.md index 8b3ece83f563ac368590cbfd391ac4bbd7a2a62d..6df8bc1de50ead40989340eb77b9382397c5384f 100644 --- a/website/docs/_posts/zh-cn/device-dev/guide/device-camera-control-demo.md +++ b/website/docs/_posts/zh-cn/device-dev/guide/device-camera-control-demo.md @@ -1,22 +1,22 @@ --- -title: device-camera-control-demo -permalink: /pages/extra/781d25/ +title: device-camera-control-demo.md +permalink: /pages/extra/a41da1/ navbar: true sidebar: false prev: false next: false -search: true -article: true +search: false +article: false comment: false editLink: false -date: 2022-02-14 21:31:37 +date: 2021-12-30 12:57:41 --- # 示例开发 -- **[拍照开发指导](/pages/01070103010201)** +- **[拍照开发指导](/pages/000600020001)** -- **[录像开发指导](/pages/01070103010202)** +- **[录像开发指导](/pages/000600020002)** -- **[预览开发指导](/pages/01070103010203)** +- **[预览开发指导](/pages/000600020003)** diff --git a/website/docs/_posts/zh-cn/device-dev/guide/device-camera-control.md b/website/docs/_posts/zh-cn/device-dev/guide/device-camera-control.md index 2e1b3d796138214d5cb249f1a9c165bf51537552..993d64f64eadcb8a2a962eab851e271270f26536 100644 --- a/website/docs/_posts/zh-cn/device-dev/guide/device-camera-control.md +++ b/website/docs/_posts/zh-cn/device-dev/guide/device-camera-control.md @@ -1,22 +1,22 @@ --- -title: device-camera-control -permalink: /pages/extra/ac3f29/ +title: device-camera-control.md +permalink: /pages/extra/bec91a/ navbar: true sidebar: false prev: false next: false -search: true -article: true +search: false +article: false comment: false editLink: false -date: 2022-02-14 21:31:37 +date: 2021-12-30 12:57:41 --- # 屏幕和摄像头控制 -- **[概述](/pages/010701030101)** +- **[概述](/pages/000600020000)** -- **[示例开发](/pages/extra/781d25/)** +- **[示例开发](/pages/extra/a41da1/)** -- **[应用实例](/pages/010701030103)** +- **[应用实例](/pages/000600020004)** diff --git a/website/docs/_posts/zh-cn/device-dev/guide/device-camera-visual.md b/website/docs/_posts/zh-cn/device-dev/guide/device-camera-visual.md index 3630fcb18a62102ec0f784cacaed8e05786ecf22..eff7f24a693ea36f0bc658f991bd6b61a8c132e8 100644 --- a/website/docs/_posts/zh-cn/device-dev/guide/device-camera-visual.md +++ b/website/docs/_posts/zh-cn/device-dev/guide/device-camera-visual.md @@ -1,32 +1,32 @@ --- -title: device-camera-visual -permalink: /pages/extra/d06f24/ +title: device-camera-visual.md +permalink: /pages/extra/368cab/ navbar: true sidebar: false prev: false next: false -search: true -article: true +search: false +article: false comment: false editLink: false -date: 2022-02-14 21:31:37 +date: 2021-12-30 12:57:41 --- # 视觉应用开发 -- **[概述](/pages/010701030201)** +- **[概述](/pages/000600020100)** -- **[开发准备](/pages/010701030202)** +- **[开发准备](/pages/000600020101)** -- **[添加页面](/pages/010701030203)** +- **[添加页面](/pages/000600020102)** -- **[开发首页](/pages/010701030204)** +- **[开发首页](/pages/000600020103)** -- **[开发详情页](/pages/010701030205)** +- **[开发详情页](/pages/000600020104)** -- **[调试打包](/pages/010701030206)** +- **[调试打包](/pages/000600020105)** -- **[真机运行](/pages/010701030207)** +- **[真机运行](/pages/000600020106)** -- **[常见问题](/pages/010701030208)** +- **[常见问题](/pages/000600020107)** diff --git a/website/docs/_posts/zh-cn/device-dev/guide/device-camera.md b/website/docs/_posts/zh-cn/device-dev/guide/device-camera.md index 7e43fe449d5d5ab618000275000ff5e65af604bc..b5ecf87d5b13eb7938133f119e20ba09978a959e 100644 --- a/website/docs/_posts/zh-cn/device-dev/guide/device-camera.md +++ b/website/docs/_posts/zh-cn/device-dev/guide/device-camera.md @@ -1,20 +1,20 @@ --- -title: device-camera -permalink: /pages/extra/51c9a4/ +title: device-camera.md +permalink: /pages/extra/b9f1a5/ navbar: true sidebar: false prev: false next: false -search: true -article: true +search: false +article: false comment: false editLink: false -date: 2022-02-14 21:31:37 +date: 2021-12-30 12:57:41 --- # 带屏摄像头类产品 -- **[屏幕和摄像头控制](/pages/extra/ac3f29/)** +- **[屏幕和摄像头控制](/pages/extra/bec91a/)** -- **[视觉应用开发](/pages/extra/d06f24/)** +- **[视觉应用开发](/pages/extra/368cab/)** diff --git a/website/docs/_posts/zh-cn/device-dev/guide/device-iotcamera-control-demo.md b/website/docs/_posts/zh-cn/device-dev/guide/device-iotcamera-control-demo.md index 0a95240eef06e6692d913aa16fb924146275db1a..a91463d94ee97043571a7d4fbab0d0d3078b032d 100644 --- a/website/docs/_posts/zh-cn/device-dev/guide/device-iotcamera-control-demo.md +++ b/website/docs/_posts/zh-cn/device-dev/guide/device-iotcamera-control-demo.md @@ -1,20 +1,20 @@ --- -title: device-iotcamera-control-demo -permalink: /pages/extra/d23bd1/ +title: device-iotcamera-control-demo.md +permalink: /pages/extra/ba9467/ navbar: true sidebar: false prev: false next: false -search: true -article: true +search: false +article: false comment: false editLink: false -date: 2022-02-14 21:31:37 +date: 2021-12-30 12:57:41 --- # 示例开发 -- **[拍照开发指导](/pages/01070102010201)** +- **[拍照开发指导](/pages/0006000101)** -- **[录像开发指导](/pages/01070102010202)** +- **[录像开发指导](/pages/0006000102)** diff --git a/website/docs/_posts/zh-cn/device-dev/guide/device-iotcamera-control.md b/website/docs/_posts/zh-cn/device-dev/guide/device-iotcamera-control.md index dcc292869aae57008593b84a8af8b0989ee4c3f2..8fe996489f15f795f617c1f6fa61e8e4b4d32e92 100644 --- a/website/docs/_posts/zh-cn/device-dev/guide/device-iotcamera-control.md +++ b/website/docs/_posts/zh-cn/device-dev/guide/device-iotcamera-control.md @@ -1,22 +1,22 @@ --- -title: device-iotcamera-control -permalink: /pages/extra/b2b869/ +title: device-iotcamera-control.md +permalink: /pages/extra/229e49/ navbar: true sidebar: false prev: false next: false -search: true -article: true +search: false +article: false comment: false editLink: false -date: 2022-02-14 21:31:37 +date: 2021-12-30 12:57:41 --- # 摄像头控制 -- **[概述](/pages/010701020101)** +- **[概述](/pages/0006000100)** -- **[示例开发](/pages/extra/d23bd1/)** +- **[示例开发](/pages/extra/ba9467/)** -- **[应用实例](/pages/010701020103)** +- **[应用实例](/pages/0006000103)** diff --git a/website/docs/_posts/zh-cn/device-dev/guide/device-iotcamera.md b/website/docs/_posts/zh-cn/device-dev/guide/device-iotcamera.md index fd469c589f3e17c4efcd2a1347e0a06e68afd5ba..77a8aabeb04fb5f3e8a0dbda73a1889c5665ce95 100644 --- a/website/docs/_posts/zh-cn/device-dev/guide/device-iotcamera.md +++ b/website/docs/_posts/zh-cn/device-dev/guide/device-iotcamera.md @@ -1,18 +1,18 @@ --- -title: device-iotcamera -permalink: /pages/extra/3b686a/ +title: device-iotcamera.md +permalink: /pages/extra/d4b6cb/ navbar: true sidebar: false prev: false next: false -search: true -article: true +search: false +article: false comment: false editLink: false -date: 2022-02-14 21:31:37 +date: 2021-12-30 12:57:41 --- # 无屏摄像头类产品 -- **[摄像头控制](/pages/extra/b2b869/)** +- **[摄像头控制](/pages/extra/229e49/)** diff --git a/website/docs/_posts/zh-cn/device-dev/guide/device-lite.md b/website/docs/_posts/zh-cn/device-dev/guide/device-lite.md deleted file mode 100644 index 44730ce67e3c8eda2f02c178cf59ed1ec036a1db..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/guide/device-lite.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: device-lite -permalink: /pages/extra/4cd9dc/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 轻量和小型系统设备 - -- **[WLAN连接类产品](/pages/extra/a9f9b7/)** - -- **[无屏摄像头类产品](/pages/extra/3b686a/)** - -- **[带屏摄像头类产品](/pages/extra/51c9a4/)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/guide/device-standard.md b/website/docs/_posts/zh-cn/device-dev/guide/device-standard.md deleted file mode 100644 index ec3046db0632d051dd2691ac2fd8a07c13d555f6..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/guide/device-standard.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: device-standard -permalink: /pages/extra/c37a91/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 标准系统设备 - -- **[时钟应用开发指导](/pages/01070201)** - -- **[平台驱动开发示例](/pages/01070202)** - -- **[外设驱动开发示例](/pages/01070203)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/guide/device-wlan-led.md b/website/docs/_posts/zh-cn/device-dev/guide/device-wlan-led.md deleted file mode 100644 index 1a03f48029d8e99829b33fd40503feb9c956face..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/guide/device-wlan-led.md +++ /dev/null @@ -1,18 +0,0 @@ ---- -title: device-wlan-led -permalink: /pages/extra/5efc06/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# LED外设控制 - -- **[LED外设控制](/pages/0107010101)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/guide/device-wlan.md b/website/docs/_posts/zh-cn/device-dev/guide/device-wlan.md index caa1ed46609546f0fce141bd31671e2df55cc0b4..934c1f09214367cda324d83ad17185621dbc6ddf 100644 --- a/website/docs/_posts/zh-cn/device-dev/guide/device-wlan.md +++ b/website/docs/_posts/zh-cn/device-dev/guide/device-wlan.md @@ -1,21 +1,20 @@ --- -title: device-wlan -permalink: /pages/extra/a9f9b7/ +title: device-wlan.md +permalink: /pages/extra/d57142/ navbar: true sidebar: false prev: false next: false -search: true -article: true +search: false +article: false comment: false editLink: false -date: 2022-02-14 21:31:37 +date: 2021-12-30 12:57:41 --- # WLAN连接类产品 - -- **[LED外设控制](/pages/extra/5efc06/)** +- **[LED外设控制](/pages/0006000000)** -- **[集成三方SDK](/pages/0107010102)** +- **[集成三方SDK](/pages/0006000001)** diff --git a/website/docs/_posts/zh-cn/device-dev/guide/device.md b/website/docs/_posts/zh-cn/device-dev/guide/device.md deleted file mode 100644 index c4b726628ee83a7e15934ae0d1ba2b355dcd7f3a..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/guide/device.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: device -permalink: /pages/extra/90b91a/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 设备 - -- **[轻量和小型系统设备](/pages/extra/4cd9dc/)** - -- **[标准系统设备](/pages/extra/c37a91/)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/Readme-CN.md b/website/docs/_posts/zh-cn/device-dev/kernel/Readme-CN.md deleted file mode 100644 index 5e41694ce0a9eace93fa1a13b69a732de96babad..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/Readme-CN.md +++ /dev/null @@ -1,209 +0,0 @@ ---- -title: Readme-CN -permalink: /pages/extra/41f16d/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 内核使用指南 - -- [轻量系统内核](/pages/extra/65dc1e/) - - [内核概述](/pages/0105010101) - - [基础内核](/pages/extra/9163c3/) - - [中断管理](/pages/extra/2a9327/) - - [基本概念](/pages/01050101020101) - - [开发指导](/pages/01050101020102) - - [任务管理](/pages/extra/9ad148/) - - [基本概念](/pages/01050101020201) - - [开发指导](/pages/01050101020202) - - [内存管理](/pages/extra/d62ea8/) - - [基本概念](/pages/01050101020301) - - [静态内存](/pages/01050101020302) - - [动态内存](/pages/01050101020303) - - [内核通信机制](/pages/extra/bad8c5/) - - [事件](/pages/extra/e4f01d/) - - [基本概念](/pages/0105010102040101) - - [开发指导](/pages/0105010102040102) - - [互斥锁](/pages/extra/7b78a2/) - - [基本概念](/pages/0105010102040201) - - [开发指导](/pages/0105010102040202) - - [消息队列](/pages/extra/c06361/) - - [基本概念](/pages/0105010102040301) - - [开发指导](/pages/0105010102040302) - - [信号量](/pages/extra/9d3f31/) - - [基本概念](/pages/0105010102040401) - - [开发指导](/pages/0105010102040402) - - [时间管理](/pages/extra/726813/) - - [基本概念](/pages/01050101020501) - - [开发指导](/pages/01050101020502) - - [软件定时器](/pages/extra/079668/) - - [基本概念](/pages/01050101020601) - - [开发指导](/pages/01050101020602) - - [扩展组件](/pages/extra/c07c37/) - - [C++支持](/pages/010501010301) - - [CPU占用率](/pages/extra/3ca78d/) - - [基本概念](/pages/01050101030201) - - [开发指导](/pages/01050101030202) - - [基本概念](/pages/extra/e745ce/) - - [开发指导](/pages/extra/ee750d/) - - [文件系统](/pages/extra/2bbbd9/) - - [FAT](/pages/01050101030301) - - [LittleFS](/pages/extra/65cb03/) - - [基本概念](/pages/0105010103030201) - - [开发指导](/pages/0105010103030202) - - [内核调测](/pages/extra/149095/) - - [内存调测](/pages/extra/034b9c/) - - [内存信息统计](/pages/01050101040101) - - [内存泄漏检测](/pages/01050101040102) - - [踩内存检测](/pages/01050101040103) - - [异常调测](/pages/010501010402) - - [Trace调测](/pages/010501010403) - - [LMS调测](/pages/010501010404) - - [附录](/pages/extra/318f40/) - - [内核编码规范](/pages/010501010501) - - [基本数据结构](/pages/extra/96d541/) - - [双向链表](/pages/01050101050201) - - [标准库支持](/pages/extra/ab87f3/) - - [CMSIS支持](/pages/01050101050301) - - [POSIX支持](/pages/01050101050302) -- [小型系统内核](/pages/extra/80d97b/) - - [内核概述](/pages/0105010201) - - [内核启动](/pages/extra/f14e14/) - - [内核态启动](/pages/010501020201) - - [用户态启动](/pages/010501020202) - - [基础内核](/pages/extra/365208/) - - [中断及异常处理](/pages/010501020301) - - [进程管理](/pages/extra/97e28a/) - - [进程](/pages/01050102030201) - - [任务](/pages/01050102030202) - - [调度器](/pages/01050102030203) - - [内存管理](/pages/extra/e65a3e/) - - [堆内存管理](/pages/01050102030301) - - [物理内存管理](/pages/01050102030302) - - [虚拟内存管理](/pages/01050102030303) - - [虚实映射](/pages/01050102030304) - - [内核通信机制](/pages/extra/1d11d4/) - - [事件](/pages/01050102030401) - - [信号量](/pages/01050102030402) - - [互斥锁](/pages/01050102030403) - - [消息队列](/pages/01050102030404) - - [读写锁](/pages/01050102030405) - - [用户态快速互斥锁](/pages/01050102030406) - - [信号](/pages/01050102030407) - - [时间管理](/pages/010501020305) - - [软件定时器](/pages/010501020306) - - [原子操作](/pages/010501020307) - - [扩展组件](/pages/extra/21b9e6/) - - [系统调用](/pages/010501020401) - - [动态加载与链接](/pages/010501020402) - - [虚拟动态共享库](/pages/010501020403) - - [轻量级进程间通信](/pages/010501020404) - - [文件系统](/pages/extra/124a98/) - - [虚拟文件系统](/pages/01050102040501) - - [支持的文件系统](/pages/extra/436bd9/) - - [FAT](/pages/0105010204050201) - - [JFFS2](/pages/0105010204050202) - - [NFS](/pages/0105010204050203) - - [Ramfs](/pages/0105010204050204) - - [Procfs](/pages/0105010204050205) - - [适配新的文件系统](/pages/01050102040503) - - [调测与工具](/pages/extra/1d2f34/) - - [Shell](/pages/extra/36f10b/) - - [Shell介绍](/pages/01050102050101) - - [Shell命令开发指导](/pages/01050102050102) - - [Shell命令编程实例](/pages/01050102050103) - - [Shell命令使用详解](/pages/extra/9729b4/) - - [系统命令](/pages/extra/810976/) - - [cpup](/pages/010501020501040101) - - [date](/pages/010501020501040102) - - [dmesg](/pages/010501020501040103) - - [exec](/pages/010501020501040104) - - [free](/pages/010501020501040105) - - [help](/pages/010501020501040106) - - [hwi](/pages/010501020501040107) - - [kill](/pages/010501020501040108) - - [log](/pages/010501020501040109) - - [memcheck](/pages/01050102050104010a) - - [oom](/pages/01050102050104010b) - - [pmm](/pages/01050102050104010c) - - [reset](/pages/01050102050104010d) - - [sem](/pages/01050102050104010e) - - [stack](/pages/01050102050104010f) - - [su](/pages/010501020501040110) - - [swtmr](/pages/010501020501040111) - - [systeminfo](/pages/010501020501040112) - - [task](/pages/010501020501040113) - - [uname](/pages/010501020501040114) - - [vmm](/pages/010501020501040115) - - [watch](/pages/010501020501040116) - - [文件命令](/pages/extra/157078/) - - [cat](/pages/010501020501040201) - - [cd](/pages/010501020501040202) - - [chgrp](/pages/010501020501040203) - - [chmod](/pages/010501020501040204) - - [chown](/pages/010501020501040205) - - [cp](/pages/010501020501040206) - - [format](/pages/010501020501040207) - - [ls](/pages/010501020501040208) - - [lsfd](/pages/010501020501040209) - - [mkdir](/pages/01050102050104020a) - - [mount](/pages/01050102050104020b) - - [partinfo](/pages/01050102050104020c) - - [partition](/pages/01050102050104020d) - - [pwd](/pages/01050102050104020e) - - [rm](/pages/01050102050104020f) - - [rmdir](/pages/010501020501040210) - - [statfs](/pages/010501020501040211) - - [sync](/pages/010501020501040212) - - [touch](/pages/010501020501040213) - - [writeproc](/pages/010501020501040214) - - [umount](/pages/010501020501040215) - - [网络命令](/pages/extra/49032e/) - - [arp](/pages/010501020501040301) - - [dhclient](/pages/010501020501040302) - - [ifconfig](/pages/010501020501040303) - - [ipdebug](/pages/010501020501040304) - - [netstat](/pages/010501020501040305) - - [ntpdate](/pages/010501020501040306) - - [ping](/pages/010501020501040307) - - [ping6](/pages/010501020501040308) - - [telnet](/pages/010501020501040309) - - [tftp](/pages/01050102050104030a) - - [魔法键使用方法](/pages/01050102050105) - - [用户态异常信息说明](/pages/01050102050106) - - [Trace调测](/pages/010501020502) - - [Perf调测](/pages/010501020503) - - [LMS调测](/pages/010501020504) - - [进程调测](/pages/extra/2d504d/) - - [CPU占用率](/pages/01050102050501) - - [内存调测](/pages/extra/502e79/) - - [内存信息统计](/pages/01050102050601) - - [内存泄漏检测](/pages/01050102050602) - - [踩内存检测](/pages/01050102050603) - - [用户态内存调测](/pages/extra/579697/) - - [基本概念](/pages/01050102050701) - - [运行机制](/pages/01050102050702) - - [使用指导](/pages/extra/e21465/) - - [接口说明](/pages/0105010205070301) - - [使用说明](/pages/extra/1f40f7/) - - [接口调用方式](/pages/010501020507030201) - - [命令行参数方式](/pages/010501020507030202) - - [常见问题场景](/pages/01050102050704) - - [其他内核调测手段](/pages/extra/f49df5/) - - [临终遗言](/pages/01050102050801) - - [常见问题定位方法](/pages/01050102050802) - - [附录](/pages/extra/658691/) - - [基本数据结构](/pages/extra/1f9e6d/) - - [双向链表](/pages/01050102060101) - - [位操作](/pages/01050102060102) - - [标准库](/pages/010501020602) -- [标准系统内核](/pages/extra/d328cc/) - - [Linux内核概述](/pages/0105010301) - - [OpenHarmony开发板Patch使用指导](/pages/0105010302) - - [Linux内核编译与构建指导](/pages/0105010303) \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-basic-mini-time.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-basic-mini-time.md deleted file mode 100644 index 52b6962b1411743d3beea0f85d3decd63c227490..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-basic-mini-time.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: kernel-basic-mini-time -permalink: /pages/extra/726813/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 时间管理 - -- **[基本概念](/pages/01050101020501)** - -- **[开发指导](/pages/01050101020502)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-memory-inner.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-memory-inner.md deleted file mode 100644 index 8c67f5485da894ed6f028dd487887673ff37b743..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-memory-inner.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: kernel-memory-inner -permalink: /pages/extra/149095/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 内核调测 - -- **[内存调测](/pages/extra/034b9c/)** - -- **[异常调测](/pages/010501010402)** - -- **[Trace调测](/pages/010501010403)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-app.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-app.md deleted file mode 100644 index c6ee8306dbf71a4c0d40a4da9c5a73d2ad92deff..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-app.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: kernel-mini-app -permalink: /pages/extra/318f40/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 附录 - -- **[内核编码规范](/pages/010501010501)** - -- **[基本数据结构](/pages/extra/96d541/)** - -- **[标准库支持](/pages/extra/ab87f3/)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-appx-data-list.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-appx-data-list.md new file mode 100644 index 0000000000000000000000000000000000000000..e741b7d5dc4d193e4df7d2e1080f64f48e5061d0 --- /dev/null +++ b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-appx-data-list.md @@ -0,0 +1,204 @@ +--- +title: kernel-mini-appx-data-list.md +permalink: /pages/extra/37d8dd/ +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +date: 2021-12-30 12:57:42 +--- +# 双向链表 + +- [基本概念](#section1990715203418) +- [功能说明](#section848334511411) +- [开发流程](#section01781261552) +- [编程实例](#section67569495514) + - [实例描述](#section48761994551) + - [示例代码](#section1280202685519) + - [结果验证](#section5811249105512) + + +## 基本概念 + +双向链表是指含有往前和往后两个方向的链表,即每个结点中除存放下一个节点指针外,还增加一个指向前一个节点的指针。其头指针head是唯一确定的。 + +从双向链表中的任意一个结点开始,都可以很方便地访问它的前驱结点和后继结点,这种数据结构形式使得双向链表在查找时更加方便,特别是大量数据的遍历。由于双向链表具有对称性,能方便地完成各种插入、删除等操作,但需要注意前后方向的操作。 + +## 功能说明 + +双向链表模块为用户提供下面几种功能,接口详细信息可以查看API参考。 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

功能分类

+

接口名

+

描述

+

初始化链表

+

LOS_ListInit

+

将指定双向链表节点初始化为双向链表

+

LOS_DL_LIST_HEAD

+

定义一个双向链表节点并以该节点初始化为双向链表

+

增加节点

+

LOS_ListAdd

+

将指定节点插入到双向链表头端

+

LOS_ListTailInsert

+

将指定节点插入到双向链表尾端

+

删除节点

+

LOS_ListDelete

+

将指定节点从链表中删除

+

LOS_ListDelInit

+

将指定节点从链表中删除,并使用该节点初始化链表

+

判断双向链表是否为空

+

LOS_ListEmpty

+

判断链表是否为空

+

获取结构体信息

+

LOS_DL_LIST_ENTRY

+

获取包含链表的结构体地址,接口的第一个入参表示的是链表中的某个节点,第二个入参是要获取的结构体名称,第三个入参是链表在该结构体中的名称

+

LOS_OFF_SET_OF

+

获取指定结构体内的成员相对于结构体起始地址的偏移量

+

遍历双向链表

+

LOS_DL_LIST_FOR_EACH

+

遍历双向链表

+

LOS_DL_LIST_FOR_EACH_SAFE

+

遍历双向链表,并存储当前节点的后继节点用于安全校验

+

遍历包含双向链表的结构体

+

LOS_DL_LIST_FOR_EACH_ENTRY

+

遍历指定双向链表,获取包含该链表节点的结构体地址

+

LOS_DL_LIST_FOR_EACH_ENTRY_SAFE

+

遍历指定双向链表,获取包含该链表节点的结构体地址,并存储包含当前节点的后继节点的结构体地址

+
+ +## 开发流程 + +双向链表的典型开发流程: + +1. 调用LOS\_ListInit/LOS\_DL\_LIST\_HEAD初始双向链表。 +2. 调用LOS\_ListAdd向链表插入节点。 +3. 调用LOS\_ListTailInsert向链表尾部插入节点。 +4. 调用LOS\_ListDelete删除指定节点。 +5. 调用LOS\_ListEmpty判断链表是否为空。 +6. 调用LOS\_ListDelInit删除指定节点并以此节点初始化链表。 + +>![](/images/zh-cn/device-dev/public_sys-resources/icon-note.gif) **说明:** +>- 需要注意节点指针前后方向的操作。 +>- 链表操作接口,为底层接口,不对入参进行判空,需要使用者确保传参合法。 +>- 如果链表节点的内存是动态申请的,删除节点时,要注意释放内存。 + +## 编程实例 + +### 实例描述 + +本实例实现如下功能: + +1. 初始化双向链表。 +2. 增加节点。 +3. 删除节点。 +4. 测试操作是否成功。 + +### 示例代码 + +示例代码如下: + +``` +#include "stdio.h" +#include "los_list.h" + +static UINT32 ListSample(VOID) +{ + LOS_DL_LIST listHead = {NULL,NULL}; + LOS_DL_LIST listNode1 = {NULL,NULL}; + LOS_DL_LIST listNode2 = {NULL,NULL}; + + //首先初始化链表 + printf("Initial head\n"); + LOS_ListInit(&listHead); + + //添加节点1和节点2,并校验他们的相互关系 + LOS_ListAdd(&listHead, &listNode1); + if (listNode1.pstNext == &listHead && listNode1.pstPrev == &listHead) { + printf("Add listNode1 success\n"); + } + + LOS_ListTailInsert(&listHead, &listNode2); + if (listNode2.pstNext == &listHead && listNode2.pstPrev == &listNode1) { + printf("Tail insert listNode2 success\n"); + } + + //删除两个节点 + LOS_ListDelete(&listNode1); + LOS_ListDelete(&listNode2); + + //确认链表为空 + if (LOS_ListEmpty(&listHead)) { + printf("Delete success\n"); + } + + return LOS_OK; +} +``` + +### 结果验证 + +编译运行得到的结果为: + +``` +Initial head +Add listNode1 success +Tail insert listNode2 success +Delete success +``` + diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-appx-data.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-appx-data.md deleted file mode 100644 index be0da7776e10aebb6952affb6ce6e14551ef008a..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-appx-data.md +++ /dev/null @@ -1,18 +0,0 @@ ---- -title: kernel-mini-appx-data -permalink: /pages/extra/96d541/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 基本数据结构 - -- **[双向链表](/pages/01050101050201)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-appx-lib.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-appx-lib.md deleted file mode 100644 index b8e844317382b1eb87064940e6d3eedb0eb554a7..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-appx-lib.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: kernel-mini-appx-lib -permalink: /pages/extra/ab87f3/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 标准库支持 - -- **[CMSIS支持](/pages/01050101050301)** - -- **[POSIX支持](/pages/01050101050302)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-basic-interrupt.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-basic-interrupt.md deleted file mode 100644 index 737332df98b6b2257cb9785b727f84088d097c56..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-basic-interrupt.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: kernel-mini-basic-interrupt -permalink: /pages/extra/2a9327/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 中断管理 - -- **[基本概念](/pages/01050101020101)** - -- **[开发指导](/pages/01050101020102)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-basic-ipc-event.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-basic-ipc-event.md deleted file mode 100644 index bc2823e2edf0310eb244c040d37eaaa3352e8497..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-basic-ipc-event.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: kernel-mini-basic-ipc-event -permalink: /pages/extra/e4f01d/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 事件 - -- **[基本概念](/pages/0105010102040101)** - -- **[开发指导](/pages/0105010102040102)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-basic-ipc-mutex.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-basic-ipc-mutex.md deleted file mode 100644 index 779e543de52be249f40c98465b68342553377779..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-basic-ipc-mutex.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: kernel-mini-basic-ipc-mutex -permalink: /pages/extra/7b78a2/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 互斥锁 - -- **[基本概念](/pages/0105010102040201)** - -- **[开发指导](/pages/0105010102040202)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-basic-ipc-queue.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-basic-ipc-queue.md deleted file mode 100644 index 2ef60890777b83846a61bf99491bf1863c01a5e7..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-basic-ipc-queue.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: kernel-mini-basic-ipc-queue -permalink: /pages/extra/c06361/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 消息队列 - -- **[基本概念](/pages/0105010102040301)** - -- **[开发指导](/pages/0105010102040302)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-basic-ipc-sem.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-basic-ipc-sem.md deleted file mode 100644 index 97f28849caeb773299decb44c892d22f91f08b19..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-basic-ipc-sem.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: kernel-mini-basic-ipc-sem -permalink: /pages/extra/9d3f31/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 信号量 - -- **[基本概念](/pages/0105010102040401)** - -- **[开发指导](/pages/0105010102040402)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-basic-ipc.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-basic-ipc.md deleted file mode 100644 index 0fe8b2c2e8d9838bd17f198ca9af0aeb82ae006a..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-basic-ipc.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -title: kernel-mini-basic-ipc -permalink: /pages/extra/bad8c5/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 内核通信机制 - -- **[事件](/pages/extra/e4f01d/)** - -- **[互斥锁](/pages/extra/7b78a2/)** - -- **[消息队列](/pages/extra/c06361/)** - -- **[信号量](/pages/extra/9d3f31/)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-basic-memory.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-basic-memory.md deleted file mode 100644 index 73eb903870300d0b9888f32112d8b11ad2b3bfd1..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-basic-memory.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: kernel-mini-basic-memory -permalink: /pages/extra/d62ea8/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 内存管理 - -- **[基本概念](/pages/01050101020301)** - -- **[静态内存](/pages/01050101020302)** - -- **[动态内存](/pages/01050101020303)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-basic-soft.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-basic-soft.md deleted file mode 100644 index 2a2e33e84893bb928723339280ddcdcc94bd1bef..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-basic-soft.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: kernel-mini-basic-soft -permalink: /pages/extra/079668/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 软件定时器 - -- **[基本概念](/pages/01050101020601)** - -- **[开发指导](/pages/01050101020602)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-basic-task.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-basic-task.md deleted file mode 100644 index 8352385d2f45ae19404a3b7bad1d13381faf5423..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-basic-task.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: kernel-mini-basic-task -permalink: /pages/extra/9ad148/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 任务管理 - -- **[基本概念](/pages/01050101020201)** - -- **[开发指导](/pages/01050101020202)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-basic.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-basic.md deleted file mode 100644 index 20fc6467af53e801e3c8d2f062517515a2cef565..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-basic.md +++ /dev/null @@ -1,28 +0,0 @@ ---- -title: kernel-mini-basic -permalink: /pages/extra/9163c3/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 基础内核 - -- **[中断管理](/pages/extra/2a9327/)** - -- **[任务管理](/pages/extra/9ad148/)** - -- **[内存管理](/pages/extra/d62ea8/)** - -- **[内核通信机制](/pages/extra/bad8c5/)** - -- **[时间管理](/pages/extra/726813/)** - -- **[软件定时器](/pages/extra/079668/)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-extend-cpup.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-extend-cpup.md deleted file mode 100644 index 8c4aba34d319aef53e3e99480db2ff581cf2c368..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-extend-cpup.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: kernel-mini-extend-cpup -permalink: /pages/extra/3ca78d/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# CPU占用率 - -- **[基本概念](/pages/01050101030201)** - -- **[开发指导](/pages/01050101030202)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-extend-dynamic-loading-basic.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-extend-dynamic-loading-basic.md deleted file mode 100644 index b265f59106d0f76299af49bd85dcadde85c9458a..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-extend-dynamic-loading-basic.md +++ /dev/null @@ -1,104 +0,0 @@ ---- -title: kernel-mini-extend-dynamic-loading-basic -permalink: /pages/extra/e745ce/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 基本概念 - -- [运行机制](#section139861939219) - - [符号表导出](#section15414650102716) - - [ELF文件加载](#section5221181562810) - - [ELF文件链接](#section68441639182817) - -- [ELF支持规格](#section187315541916) - - [ELF支持类型](#section1701552268) - - [ELF共享库编译链接选项](#section17292133274) - - -在硬件资源有限的小设备中,需要通过算法的动态部署能力来解决无法同时部署多种算法的问题。以开发者易用为主要考虑因素,同时考虑到多平台的通用性,LiteOS-M选择业界标准的ELF方案,方便拓展算法生态。LiteOS-M提供类似于dlopen、dlsym等接口,APP通过动态加载模块提供的接口可以加载、卸载相应算法库。如图1所示,APP需要通过三方算法库所需接口获取对应信息输出,三方算法库又依赖内核提供的基本接口,如malloc等。APP加载所需接口,并对相关的未定义符号完成重定位后,APP即可调用该接口完成功能调用。目前动态加载组件只支持arm架构。此外,待加载的共享库需要验签或者限制来源,确保系统的安全性。 - -**图 1** LiteOS-M内核动态加载架构图 -![](/images/device-dev/kernel/figure/LiteOS-M内核动态加载架构图.png "LiteOS-M内核动态加载架构图") - -## 运行机制 - -### 符号表导出 - -共享库调用内核接口需要内核主动暴露动态库所需的接口,如图2所示,该机制将符号信息编译到指定段中,调用SYM\_EXPORT宏即可完成对指定符号的信息导出。符号信息通过结构体SymInfo描述,成员包括符号名和符号地址信息,宏SYM\_EXPORT通过\_\_attribute\_\_编译属性将符号信息导入.sym.\*段中。 - -``` -typedef struct { - CHAR *name; - UINTPTR addr; -} SymInfo; - -#define SYM_EXPORT(func) \ -const SymInfo sym_##func __attribute__((section(".sym."#func))) = { \ - .name = #func, \ - .addr = (UINTPTR)func \ -}; -``` - -**图 2** 导出的符号表信息 -![](/images/device-dev/kernel/figure/导出的符号表信息.png "导出的符号表信息") - -### ELF文件加载 - -加载过程中,根据ELF文件的句柄以及程序头表的段偏移可以得到需要加载到内存的LOAD段,一般有两个段,只读段及读写段,如下所示,可以用readelf -l查看ELF文件的LOAD段信息。如图3所示,根据相应的对齐属性申请物理内存,通过每个段的加载基址及偏移将代码段或数据段写入内存中。 - -``` -$ readelf -l lib.so - -Elf file type is DYN (Shared object file) -Entry point 0x5b4 -There are 4 program headers, starting at offset 52 - -Program Headers: - Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align - EXIDX 0x000760 0x00000760 0x00000760 0x00008 0x00008 R 0x4 - LOAD 0x000000 0x00000000 0x00000000 0x0076c 0x0076c R E 0x10000 - LOAD 0x00076c 0x0001076c 0x0001076c 0x0010c 0x00128 RW 0x10000 - DYNAMIC 0x000774 0x00010774 0x00010774 0x000c8 0x000c8 RW 0x4 - - Section to Segment mapping: - Segment Sections... - 00 .ARM.exidx - 01 .hash .dynsym .dynstr .rel.dyn .rel.plt .init .plt .text .fini .ARM.exidx .eh_frame - 02 .init_array .fini_array .dynamic .got .data .bss - 03 .dynamic -``` - -**图 3** ELF文件的加载过程 -![](/images/device-dev/kernel/figure/ELF文件的加载过程.png "ELF文件的加载过程") - -### ELF文件链接 - -如图4所示,通过ELF文件的.dynamic段获取重定位表,遍历表中每一个需要重定位的条目,再根据需要重定位的符号名在共享库和内核提供的导出符号表中查找相应符号并更新相应的重定位信息。 - -**图 4** ELF文件的链接过程 -![](/images/device-dev/kernel/figure/ELF文件的链接过程.png "ELF文件的链接过程") - -## ELF支持规格 - -### ELF支持类型 - -编译共享库时,添加-fPIC可以编译出位置无关代码(-fPIC为编译选项),此时共享库文件类型为ET\_DYN,其可以加载至任意有效的地址区间。 - -例:arm-none-eabi-gcc -fPIC –shared –o lib.so lib.c - -### ELF共享库编译链接选项 - -1. “-nostdlib”编译链接选项:不依赖编译器中lib库。 -2. “-nostartfiles”编译链接选项:不依赖编译器中启动相关的文件。 -3. “-fPIC”编译选项:可编译位置无关的共享库。 -4. “-z max-page-size=4”链接选项:二进制文件中可加载段的对齐字节数为4,可节约内存,可用于动态库。 -5. “-mcpu=”需要指定对应的cpu架构。 - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-extend-dynamic-loading-guide.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-extend-dynamic-loading-guide.md deleted file mode 100644 index a6ca010a17aaed2d2e86c9b9343c7f5a257057db..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-extend-dynamic-loading-guide.md +++ /dev/null @@ -1,200 +0,0 @@ ---- -title: kernel-mini-extend-dynamic-loading-guide -permalink: /pages/extra/ee750d/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 开发指导 - -- [接口说明](#section158501652121514) -- [开发流程](#section5241132917523) -- [编程实例](#section8708112313531) - -## 接口说明 - -**表 1** 功能列表 - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名

-

描述

-

动态加载功能接口

-

LOS_DynlinkInit

-

初始化动态链接器链表以及互斥锁

-

LOS_SoLoad

-

加载指定路径的共享库

-

LOS_FindSym

-

根据共享库句柄查找指定符号

-

LOS_SoUnload

-

卸载共享库句柄

-
- -## 开发流程 - -1. 利用arm-none-eabi-gcc交叉编译器编译共享库并制作FAT或LittleFS文件系统格式镜像烧写至flash中; -2. 在target\_config.h文件中定义宏LOSCFG\_DYNLINK为1使能动态加载模块; -3. 调用LOS\_SoLoad接口加载指定路径下的共享库; -4. 调用LOS\_FindSym接口查找指定符号,获取符号地址; -5. 调用LOS\_SoUnload卸载指定共享库句柄。 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->1. 利用交叉编译器编译共享库所需要的编译选项参考ELF支持规格一节。 ->2. 制作文件系统镜像之前需要对特定单板适配FAT或LittleFS文件系统。 ->3. 共享库不依赖编译器中的libc库,不支持c++。 ->4. 共享库只能依赖内核提供的接口,不能依赖其他共享库。 - -## 编程实例 - -实例以cortex-m4单板为例。 - -1. 共享库示例代码及编译 - - 示例代码主要测试全局符号间的调用功能以及对内核接口maloc、free、memset接口的调用功能。 - - ``` - #include - #include - - int g_param = 10; - - int callee(int a, int b) - { - char *addr = malloc(g_param); - if (addr == NULL) { - return 0; - } - - memset(addr, '1', g_param); - - free(addr); - return a + b + g_param; - } - - int caller(int a, int b) - { - return callee(a, b); - } - ``` - - ``` - $ arm-none-eabi-gcc -fPIC -shared -mcpu=cortex-m4 -nostdlib -nostartfiles -z max-page-size=4 -o test.so test.c - ``` - -2. 导出共享库中使用到的malloc、free、memset符号,下述代码单独编写成一个.c文件,参与OS编译即可。 - - ``` - #include "stdlib.h" - #include "string.h" - - SYM_EXPORT(malloc); - SYM_EXPORT(free); - SYM_EXPORT(memset); - ``` - -3. 确定内核的编译环境,在对应编译器的编译链接脚本中添加如下语句,保证符号表信息在编译链接的时候输出到指定的段。 - - 在IAR编译器.icf链接脚本中添加如下语句: - - ``` - keep {section .TABLE.START}; - keep {section .sym.*}; - keep {section .table.end}; - define block SYMBOL_TABLE with fixed order - { - section .TABLE.START, - section .sym.*, - section .table.end - }; - place in ROM_region {readonly, block SYMBOL_TABLE}; - ``` - - 在gcc编译器的.ld链接脚本中添加如下语句: - - ``` - __sym_table_start = .; - KEEP(*( SORT (.sym.*))); - __sym_table_end = .; - ``` - -4. 共享库加载链接、执行与卸载 - - 示例代码主要测试LOS\_SoLoad、LOS\_FindSym、LOS\_SoUnload接口的功能是否正常以及通过LOS\_FindSym查找到的符号的调用是否正常。 - - ``` - #include "los_dynlink.h" - - VOID DynlinkTest(VOID) - { - VOID *handle = NULL; - INT32 (*func)(INT32, INT32) = NULL; - CHAR *symbolName = "caller"; - CHAR *dsoName = "/lib/test.so"; - INT32 ret; - - handle = (VOID *)LOS_SoLoad(dsoName, NULL); - if (handle == NULL) { - printf("Failed to load so\n"); - return; - } - - func = (INT32 (*)(INT32, INT32))LOS_FindSym(handle, symbolName); - if (func == NULL) { - printf("Failed to find symbol\n"); - LOS_SoUnload(handle); - return; - } - - ret = func(1, 1); - if (ret != 12) { - printf("Failed to execute function\n"); - LOS_SoUnload(handle); - return; - } - - ret = LOS_SoUnload(handle); - if (ret != 0) { - printf("Failed to unload so\n"); - } - - - printf("Success!\n"); - } - ``` - -5. 结果验证 - - ``` - Success! - ``` - - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->用例中文件系统路径为/lib/test.so; ->可以创建一个任务,在任务中调用DynlinkTest接口进行测试; - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-extend-dynamic-loading.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-extend-dynamic-loading.md deleted file mode 100644 index 85bf4e2b723398ccc943adb97a26c418454e8f2e..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-extend-dynamic-loading.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: kernel-mini-extend-dynamic-loading -permalink: /pages/extra/a97ca7/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# - -- **[基本概念](/pages/extra/e745ce/)** - -- **[开发指导](/pages/extra/ee750d/)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-extend-file-lit.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-extend-file-lit.md deleted file mode 100644 index 87f799155a919190b00caf257e9cfe1f1563a022..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-extend-file-lit.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: kernel-mini-extend-file-lit -permalink: /pages/extra/65cb03/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# LittleFS - -- **[基本概念](/pages/0105010103030201)** - -- **[开发指导](/pages/0105010103030202)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-extend-file.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-extend-file.md deleted file mode 100644 index e3c12142f5edb7666a389f4665a8a7c30442186a..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-extend-file.md +++ /dev/null @@ -1,217 +0,0 @@ ---- -title: kernel-mini-extend-file -permalink: /pages/extra/2bbbd9/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 文件系统 - -当前支持的文件系统有FATFS与LittleFS,支持的功能如下表所示: - -**表 1** ****功能列表 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

功能分类

-

接口名

-

描述

-

FATFS

-

LITTELFS

-

文件操作

-

open

-

打开文件

-

支持

-

支持

-

close

-

关闭文件

-

支持

-

支持

-

read

-

读取文件内容

-

支持

-

支持

-

write

-

往文件写入内容

-

支持

-

支持

-

lseek

-

设置文件偏移位置

-

支持

-

支持

-

unlink

-

删除文件

-

支持

-

支持

-

rename

-

重命名文件

-

支持

-

支持

-

fstat

-

通过文件句柄获取文件信息

-

支持

-

支持

-

stat

-

通过文件路径名获取文件信息

-

支持

-

支持

-

fsync

-

文件内容刷入存储设备

-

支持

-

支持

-

目录操作

-

mkdir

-

创建目录

-

支持

-

支持

-

opendir

-

打开目录

-

支持

-

支持

-

readdir

-

读取目录项内容

-

支持

-

支持

-

closedir

-

关闭目录

-

支持

-

支持

-

rmdir

-

删除目录

-

支持

-

支持

-

分区操作

-

mount

-

分区挂载

-

支持

-

支持

-

umount

-

分区卸载

-

支持

-

支持

-

umount2

-

分区卸载,可通过MNT_FORCE参数进行强制卸载

-

支持

-

不支持

-

statfs

-

获取分区信息

-

支持

-

不支持

-
- -- **[FAT](/pages/01050101030301)** - -- **[LittleFS](/pages/extra/65cb03/)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-extend.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-extend.md deleted file mode 100644 index e23ff41c282b887d59a369060a30e04f70ac4e29..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-extend.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -title: kernel-mini-extend -permalink: /pages/extra/c07c37/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 扩展组件 - -- **[C++支持](/pages/010501010301)** - -- **[CPU占用率](/pages/extra/3ca78d/)** - -- **[动态加载](/pages/extra/a97ca7/)** - -- **[文件系统](/pages/extra/2bbbd9/)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-memory-debug.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-memory-debug.md deleted file mode 100644 index 2031c7dc62d79554f29a4858ad3d5c1d75aab33f..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini-memory-debug.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -title: kernel-mini-memory-debug -permalink: /pages/extra/034b9c/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 内存调测 - -内存调测方法旨在辅助定位动态内存相关问题,提供了基础的动态内存池信息统计手段,向用户呈现内存池水线、碎片率等信息;提供了内存泄漏检测手段,方便用户准确定位存在内存泄漏的代码行,也可以辅助分析系统各个模块内存的使用情况;提供了踩内存检测手段,可以辅助定位越界踩内存的场景。 - -- **[内存信息统计](/pages/01050101040101)** - -- **[内存泄漏检测](/pages/01050101040102)** - -- **[踩内存检测](/pages/01050101040103)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini.md deleted file mode 100644 index ffcc9ac3f8a38d93df8d012a9f7e58fcae1f0748..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-mini.md +++ /dev/null @@ -1,26 +0,0 @@ ---- -title: kernel-mini -permalink: /pages/extra/65dc1e/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 轻量系统内核 - -- **[内核概述](/pages/0105010101)** - -- **[基础内核](/pages/extra/9163c3/)** - -- **[扩展组件](/pages/extra/c07c37/)** - -- **[内核调测](/pages/extra/149095/)** - -- **[附录](/pages/extra/318f40/)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-apx-structure.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-apx-structure.md deleted file mode 100644 index 4ad1050d6e9d43d5bc1fa076d4e8820b2e5a779f..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-apx-structure.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: kernel-small-apx-structure -permalink: /pages/extra/1f9e6d/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 基本数据结构 - -- **[双向链表](/pages/01050102060101)** - -- **[位操作](/pages/01050102060102)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-apx.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-apx.md deleted file mode 100644 index 100405d6c6628d8e5f12a1406009be4c9148cf28..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-apx.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: kernel-small-apx -permalink: /pages/extra/658691/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 附录 - -- **[基本数据结构](/pages/extra/1f9e6d/)** - -- **[标准库](/pages/010501020602)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-basic-memory.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-basic-memory.md deleted file mode 100644 index e98b7f80a3d9df66b3528eeff4b959b6fe8e363f..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-basic-memory.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -title: kernel-small-basic-memory -permalink: /pages/extra/e65a3e/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 内存管理 - -- **[堆内存管理](/pages/01050102030301)** - -- **[物理内存管理](/pages/01050102030302)** - -- **[虚拟内存管理](/pages/01050102030303)** - -- **[虚实映射](/pages/01050102030304)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-basic-process.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-basic-process.md deleted file mode 100644 index 48e49aefa360925ad1b35efb665914aa0f95faba..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-basic-process.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: kernel-small-basic-process -permalink: /pages/extra/97e28a/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 进程管理 - -- **[进程](/pages/01050102030201)** - -- **[线程](/pages/01050102030202)** - -- **[调度器](/pages/01050102030203)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-basic-trans.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-basic-trans.md deleted file mode 100644 index 12f511728e2af8c1b9e632385200dd54cf71db82..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-basic-trans.md +++ /dev/null @@ -1,30 +0,0 @@ ---- -title: kernel-small-basic-trans -permalink: /pages/extra/1d11d4/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 内核通信机制 - -- **[事件](/pages/01050102030401)** - -- **[信号量](/pages/01050102030402)** - -- **[互斥锁](/pages/01050102030403)** - -- **[消息队列](/pages/01050102030404)** - -- **[读写锁](/pages/01050102030405)** - -- **[用户态快速互斥锁](/pages/01050102030406)** - -- **[信号](/pages/01050102030407)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-basics.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-basics.md deleted file mode 100644 index 8b9f3a9599bf800bedd043b5477eaad743fc04c0..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-basics.md +++ /dev/null @@ -1,30 +0,0 @@ ---- -title: kernel-small-basics -permalink: /pages/extra/365208/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 基础内核 - -- **[中断及异常处理](/pages/010501020301)** - -- **[进程管理](/pages/extra/97e28a/)** - -- **[内存管理](/pages/extra/e65a3e/)** - -- **[内核通信机制](/pages/extra/1d11d4/)** - -- **[时间管理](/pages/010501020305)** - -- **[软件定时器](/pages/010501020306)** - -- **[原子操作](/pages/010501020307)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-bundles-fs-support.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-bundles-fs-support.md deleted file mode 100644 index f577ba7dcc14bb13382ef3298ad85d51199a7f7b..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-bundles-fs-support.md +++ /dev/null @@ -1,26 +0,0 @@ ---- -title: kernel-small-bundles-fs-support -permalink: /pages/extra/436bd9/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 支持的文件系统 - -- **[FAT](/pages/0105010204050201)** - -- **[JFFS2](/pages/0105010204050202)** - -- **[NFS](/pages/0105010204050203)** - -- **[Ramfs](/pages/0105010204050204)** - -- **[Procfs](/pages/0105010204050205)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-bundles-fs.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-bundles-fs.md deleted file mode 100644 index 253894772c79babb744fe9e7aee45e4cad940421..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-bundles-fs.md +++ /dev/null @@ -1,29 +0,0 @@ ---- -title: kernel-small-bundles-fs -permalink: /pages/extra/124a98/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 文件系统 - -文件系统(File System,或者简称FS),是操作系统中输入输出的一种主要形式,主要负责和内外部的存储设备交互。 - -文件系统对上通过C库提供的POSIX标准的操作接口,具体可以参考C库的API文档说明。对下,通过内核态的VFS虚拟层,屏蔽了各个具体文件系统的差异。基本架构如下: - -**图 1** 文件系统的总体结构 -![](/images/device-dev/kernel/figure/文件系统的总体结构.png "文件系统的总体结构") - -- **[虚拟文件系统](/pages/01050102040501)** - -- **[支持的文件系统](/pages/extra/436bd9/)** - -- **[适配新的文件系统](/pages/01050102040503)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-bundles.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-bundles.md deleted file mode 100644 index 4183d5f06f449da9d9bf85481615385e09266723..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-bundles.md +++ /dev/null @@ -1,26 +0,0 @@ ---- -title: kernel-small-bundles -permalink: /pages/extra/21b9e6/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 扩展组件 - -- **[系统调用](/pages/010501020401)** - -- **[动态加载与链接](/pages/010501020402)** - -- **[虚拟动态共享库](/pages/010501020403)** - -- **[轻量级进程间通信](/pages/010501020404)** - -- **[文件系统](/pages/extra/124a98/)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-debug-memory.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-debug-memory.md deleted file mode 100644 index 57bc2816b03d86a156721ef32a530c581c488be6..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-debug-memory.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: kernel-small-debug-memory -permalink: /pages/extra/502e79/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 内存调测 - -- **[内存信息统计](/pages/01050102050601)** - -- **[内存泄漏检测](/pages/01050102050602)** - -- **[踩内存检测](/pages/01050102050603)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-debug-other.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-debug-other.md deleted file mode 100644 index fdf1df71d6886cd5da5aaa48308a93bd29d91b2b..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-debug-other.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: kernel-small-debug-other -permalink: /pages/extra/f49df5/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 其他内核调测手段 - -- **[临终遗言](/pages/01050102050801)** - -- **[常见问题定位方法](/pages/01050102050802)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-debug-process.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-debug-process.md deleted file mode 100644 index df2ea5f3cb8e24aa655575146fccbbc5d8c8d079..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-debug-process.md +++ /dev/null @@ -1,18 +0,0 @@ ---- -title: kernel-small-debug-process -permalink: /pages/extra/2d504d/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 进程调测 - -- **[CPU占用率](/pages/01050102050501)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-debug-shell-cmd.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-debug-shell-cmd.md deleted file mode 100644 index bcce5f32d7187058574a701c0e3604fd3b09ae2b..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-debug-shell-cmd.md +++ /dev/null @@ -1,64 +0,0 @@ ---- -title: kernel-small-debug-shell-cmd -permalink: /pages/extra/810976/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 系统命令 - -- **[cpup](/pages/010501020501040101)** - -- **[date](/pages/010501020501040102)** - -- **[dmesg](/pages/010501020501040103)** - -- **[du](/pages/010501020501040216)** - -- **[exec](/pages/010501020501040104)** - -- **[free](/pages/010501020501040105)** - -- **[help](/pages/010501020501040106)** - -- **[hwi](/pages/010501020501040107)** - -- **[kill](/pages/010501020501040108)** - -- **[log](/pages/010501020501040109)** - -- **[memcheck](/pages/01050102050104010a)** - -- **[oom](/pages/01050102050104010b)** - -- **[pmm](/pages/01050102050104010c)** - -- **[reboot](/pages/010501020501040117)** - -- **[reset](/pages/01050102050104010d)** - -- **[sem](/pages/01050102050104010e)** - -- **[stack](/pages/01050102050104010f)** - -- **[su](/pages/010501020501040110)** - -- **[swtmr](/pages/010501020501040111)** - -- **[systeminfo](/pages/010501020501040112)** - -- **[task](/pages/010501020501040113)** - -- **[top](/pages/010501020501040118)** - -- **[uname](/pages/010501020501040114)** - -- **[vmm](/pages/010501020501040115)** - -- **[watch](/pages/010501020501040116)** diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-debug-shell-details.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-debug-shell-details.md deleted file mode 100644 index f04856860a218d8f03479de202b0c3df7b246287..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-debug-shell-details.md +++ /dev/null @@ -1,26 +0,0 @@ ---- -title: kernel-small-debug-shell-details -permalink: /pages/extra/9729b4/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# Shell命令使用详解 - -本章节介绍了系统关键命令的功能、格式、参数范围、使用指南和使用实例。 - -不在本文档范围内的命令,详见[help](/pages/010501020501040106)命令的输出内容,也可以通过命令的“-h | --help”选项,查看该命令的使用帮助。 - -- **[系统命令](/pages/extra/810976/)** - -- **[文件命令](/pages/extra/157078/)** - -- **[网络命令](/pages/extra/49032e/)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-debug-shell-file.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-debug-shell-file.md deleted file mode 100644 index 07ec0d24973d0b71a3b3b40f2b146ad7660120e0..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-debug-shell-file.md +++ /dev/null @@ -1,58 +0,0 @@ ---- -title: kernel-small-debug-shell-file -permalink: /pages/extra/157078/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 文件命令 - -- **[cat](/pages/010501020501040201)** - -- **[cd](/pages/010501020501040202)** - -- **[chgrp](/pages/010501020501040203)** - -- **[chmod](/pages/010501020501040204)** - -- **[chown](/pages/010501020501040205)** - -- **[cp](/pages/010501020501040206)** - -- **[format](/pages/010501020501040207)** - -- **[ls](/pages/010501020501040208)** - -- **[lsfd](/pages/010501020501040209)** - -- **[mkdir](/pages/01050102050104020a)** - -- **[mount](/pages/01050102050104020b)** - -- **[mv](/pages/010501020501040217)** - -- **[partinfo](/pages/01050102050104020c)** - -- **[partition](/pages/01050102050104020d)** - -- **[pwd](/pages/01050102050104020e)** - -- **[rm](/pages/01050102050104020f)** - -- **[rmdir](/pages/010501020501040210)** - -- **[statfs](/pages/010501020501040211)** - -- **[sync](/pages/010501020501040212)** - -- **[touch](/pages/010501020501040213)** - -- **[writeproc](/pages/010501020501040214)** - -- **[umount](/pages/010501020501040215)** diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-debug-shell-net.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-debug-shell-net.md deleted file mode 100644 index 12a4121528e0fb7da80ae756dc3c3ae1d44bbb6b..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-debug-shell-net.md +++ /dev/null @@ -1,35 +0,0 @@ ---- -title: kernel-small-debug-shell-net -permalink: /pages/extra/49032e/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 网络命令 - -- **[arp](/pages/010501020501040301)** - -- **[dhclient](/pages/010501020501040302)** - -- **[ifconfig](/pages/010501020501040303)** - -- **[ipdebug](/pages/010501020501040304)** - -- **[netstat](/pages/010501020501040305)** - -- **[ntpdate](/pages/010501020501040306)** - -- **[ping](/pages/010501020501040307)** - -- **[ping6](/pages/010501020501040308)** - -- **[telnet](/pages/010501020501040309)** - -- **[tftp](/pages/01050102050104030a)** - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-debug-shell.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-debug-shell.md deleted file mode 100644 index fa2bd9995f11be216be6fe9941982bb4771c97ef..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-debug-shell.md +++ /dev/null @@ -1,28 +0,0 @@ ---- -title: kernel-small-debug-shell -permalink: /pages/extra/36f10b/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# Shell - -- **[Shell介绍](/pages/01050102050101)** - -- **[Shell命令开发指导](/pages/01050102050102)** - -- **[Shell命令编程实例](/pages/01050102050103)** - -- **[Shell命令使用详解](/pages/extra/9729b4/)** - -- **[魔法键使用方法](/pages/01050102050105)** - -- **[用户态异常信息说明](/pages/01050102050106)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-debug-user-guide-use.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-debug-user-guide-use.md deleted file mode 100644 index d4cb86275f2c7882fe00c0720735a296f7a3f7dc..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-debug-user-guide-use.md +++ /dev/null @@ -1,30 +0,0 @@ ---- -title: kernel-small-debug-user-guide-use -permalink: /pages/extra/1f40f7/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 使用说明 - -编译OpenHarmony工程时默认编译的是debug版本,即libc库已经集成内存调测相关的接口实现,用户可以根据具体需要决定是否使能内存调测功能。 - -堆内存调测功能提供两种方式供用户使用:接口调用及命令行参数。 - -- 接口调用:优点是可以较精确的检查某一段代码逻辑的堆内存相关信息,缺点是需要修改用户代码。 -- 命令行参数:优点是无需修改用户代码,缺点是无法精确的校验某一段逻辑的堆内存信息。 - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->内存调测功能使能后,进程退出时会默认进行一次堆内存泄漏和堆内存完整性检查。内存调测功能未使能时,堆内存统计、堆内存泄漏检查、堆内存完整性校验功能不会开启,调用相关调测接口无响应。 - -- **[接口调用方式](/pages/010501020507030201)** - -- **[命令行参数方式](/pages/010501020507030202)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-debug-user-guide.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-debug-user-guide.md deleted file mode 100644 index 7497bd4c2178fe8b60193ce06136dbd63c34959f..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-debug-user-guide.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: kernel-small-debug-user-guide -permalink: /pages/extra/e21465/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 使用指导 - -- **[接口说明](/pages/0105010205070301)** - -- **[使用说明](/pages/extra/1f40f7/)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-debug-user.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-debug-user.md deleted file mode 100644 index 7aba31bb0a0d19384701ecb901e431bf3ebb9310..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-debug-user.md +++ /dev/null @@ -1,30 +0,0 @@ ---- -title: kernel-small-debug-user -permalink: /pages/extra/579697/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 用户态内存调测 - -- **[基本概念](/pages/01050102050701)** - -- **[运行机制](/pages/01050102050702)** - -- **[使用指导](/pages/extra/e21465/)** - -- **[常见问题场景](/pages/01050102050704)** - -- **[Linux内核概述](/pages/0105010301)** - -- **[OpenHarmony开发板Patch使用指导](/pages/0105010302)** - -- **[Linux内核编译与构建指导](/pages/0105010303)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-debug.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-debug.md deleted file mode 100644 index 8507fefaa6311c402b44cb85740c9d9e078af549..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-debug.md +++ /dev/null @@ -1,26 +0,0 @@ ---- -title: kernel-small-debug -permalink: /pages/extra/1d2f34/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 调测与工具 - -- **[Shell](/pages/extra/36f10b/)** - -- **[Trace](/pages/010501020502)** - -- **[进程调测](/pages/extra/2d504d/)** - -- **[内存调测](/pages/extra/502e79/)** - -- **[其他内核调测手段](/pages/extra/f49df5/)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-start.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-start.md deleted file mode 100644 index 5342a9887ee3140b6d8eff73e472644e2f34b33c..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small-start.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: kernel-small-start -permalink: /pages/extra/f14e14/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 内核启动 - -- **[内核态启动](/pages/010501020201)** - -- **[用户态启动](/pages/010501020202)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small.md deleted file mode 100644 index ea7fa6b78c19a16f1774de1fed10ea247c6d0c39..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-small.md +++ /dev/null @@ -1,28 +0,0 @@ ---- -title: kernel-small -permalink: /pages/extra/80d97b/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 小型系统内核 - -- **[内核概述](/pages/0105010201)** - -- **[内核启动](/pages/extra/f14e14/)** - -- **[基础内核](/pages/extra/365208/)** - -- **[扩展组件](/pages/extra/21b9e6/)** - -- **[调测与工具](/pages/extra/1d2f34/)** - -- **[附录](/pages/extra/658691/)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-standard.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel-standard.md deleted file mode 100644 index b089eaa303006271e5fb65a55f6329bf6a4efeb6..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel-standard.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: kernel-standard -permalink: /pages/extra/d328cc/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 标准系统内核 - -- **[Linux内核概述](/pages/0105010301)** - -- **[OpenHarmony开发板Patch使用指导](/pages/0105010302)** - -- **[Linux内核编译与构建指导](/pages/0105010303)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/kernel/kernel.md b/website/docs/_posts/zh-cn/device-dev/kernel/kernel.md deleted file mode 100644 index 928e6c93c1bf6235197e3b84190504fb4193808a..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/kernel/kernel.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: kernel -permalink: /pages/extra/0c607a/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 内核 - -- **[轻量系统内核](/pages/extra/65dc1e/)** - -- **[小型系统内核](/pages/extra/80d97b/)** - -- **[标准系统内核](/pages/extra/d328cc/)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/porting/Readme-CN.md b/website/docs/_posts/zh-cn/device-dev/porting/Readme-CN.md deleted file mode 100644 index a0203bea582c94400b656704a55b42173ddb74fb..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/porting/Readme-CN.md +++ /dev/null @@ -1,77 +0,0 @@ ---- -title: Readme-CN -permalink: /pages/extra/6a00bc/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -## 概述 -目前OpenHarmony已经成立了SIG组[sig-devboard](https://gitee.com/openharmony/community/blob/master/sig/sig-devboard/sig_devboard_cn.md)。该SIG组以支持更多第三方开发板为目标,提供开发板移植的支撑。 - -在了解开发板移植前,需要先了解一下OpenHarmony对设备的分类。不同设备类型的移植方法会有较大差异。 - -| 设备类型 | 硬件要求 | 支持的内核 | -|---------|-------------|----------------| -| 轻量系统类设备 | 内存>128KB | LiteOS-M | -| 小型系统类设备 | 内存>1MB、有MMU | LiteOS-A、Linux | -| 标准系统类设备 | 内存>128MB | Linux | - -## 代码准备 - -目前OpenHarmony已经为各厂家创建了仓库并在openharmony-sig中进行孵化。参与孵化仓开发,需要使用如下方法初始化和下载代码。 - -```shell -repo init -u https://gitee.com/openharmony-sig/manifest.git -b master -m devboard.xml --no-repo-verify -``` - -其他下载步骤与主线相同。 - -## 芯片移植指导 - -- [轻量系统芯片移植指导](/pages/extra/bc2a1e/) - - [移植准备](/pages/extra/2bf51a/) - - [移植须知](/pages/0104010101) - - [编译构建适配流程](/pages/0104010102) - - [内核移植](/pages/extra/7a2f63/) - - [移植概述](/pages/0104010201) - - [内核基础适配](/pages/0104010202) - - [内核移植验证](/pages/0104010203) - - [板级系统移植](/pages/extra/9257d8/) - - [移植概述](/pages/0104010301) - - [板级驱动适配](/pages/0104010302) - - [HAL层实现](/pages/0104010303) - - [系统组件调用](/pages/0104010304) - - [lwIP组件适配](/pages/0104010305) - - [三方组件适配](/pages/0104010306) - - [XTS认证](/pages/0104010307) - - [常见问题](/pages/01040104) -- [小型系统芯片移植指导](/pages/extra/362558/) - - [移植准备](/pages/extra/f4e07b/) - - [移植须知](/pages/0104020101) - - [编译构建](/pages/0104020102) - - [移植内核](/pages/extra/2858ab/) - - [LiteOS-A内核](/pages/0104020201) - - [Linux内核](/pages/0104020202) - - [驱动移植](/pages/extra/f63f6f/) - - [移植概述](/pages/0104020301) - - [平台驱动移植](/pages/0104020302) - - [器件驱动移植](/pages/0104020303) -- [标准系统芯片移植指导](/pages/01040301) - - [标准系统移植指南](/pages/01040301) - - [一种快速移植OpenHarmony Linux内核的方法](/pages/01040302) - - - [概述](/pages/01040401) - - [CMake方式组织编译的库移植](/pages/01040402) - - [Makefile方式组织编译的库移植](/pages/01040403) - -## 芯片移植案例 - -- [轻量系统芯片移植案例](/pages/extra/890e18/) - - [带屏解决方案之恒玄芯片移植案例](/pages/01040501) - diff --git a/website/docs/_posts/zh-cn/device-dev/porting/porting-chip-board.md b/website/docs/_posts/zh-cn/device-dev/porting/porting-chip-board.md deleted file mode 100644 index a6ccefa01cc907fbfcc44e4a38e85ec3c3854e04..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/porting/porting-chip-board.md +++ /dev/null @@ -1,30 +0,0 @@ ---- -title: porting-chip-board -permalink: /pages/extra/9257d8/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 板级系统移植 - -- **[移植概述](/pages/0104010301)** - -- **[板级驱动适配](/pages/0104010302)** - -- **[HAL层实现](/pages/0104010303)** - -- **[系统组件调用](/pages/0104010304)** - -- **[lwip组件适配](/pages/0104010305)** - -- **[三方组件适配](/pages/0104010306)** - -- **[XTS认证](/pages/0104010307)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/porting/porting-chip-kernel.md b/website/docs/_posts/zh-cn/device-dev/porting/porting-chip-kernel.md deleted file mode 100644 index d93af79d508e6f5880a458f07108df1370d1b79e..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/porting/porting-chip-kernel.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: porting-chip-kernel -permalink: /pages/extra/7a2f63/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 内核移植 - -- **[移植概述](/pages/0104010201)** - -- **[内核基础适配](/pages/0104010202)** - -- **[内核移植验证](/pages/0104010203)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/porting/porting-chip-prepare.md b/website/docs/_posts/zh-cn/device-dev/porting/porting-chip-prepare.md deleted file mode 100644 index 31813e2f4a2281a751bf44ae28fb21c7e6580b41..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/porting/porting-chip-prepare.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: porting-chip-prepare -permalink: /pages/extra/2bf51a/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 移植准备 - -- **[移植须知](/pages/0104010101)** - -- **[编译构建适配流程](/pages/0104010102)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/porting/porting-minichip-cases.md b/website/docs/_posts/zh-cn/device-dev/porting/porting-minichip-cases.md deleted file mode 100644 index 1853c5e2c7a495e91559258d2026c7380f95991e..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/porting/porting-minichip-cases.md +++ /dev/null @@ -1,17 +0,0 @@ ---- -title: porting-minichip-cases -permalink: /pages/extra/890e18/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 轻量系统芯片移植案例 - -- **[轻量带屏解决方案之恒玄芯片移植案例](/pages/01040501)** - diff --git a/website/docs/_posts/zh-cn/device-dev/porting/porting-minichip.md b/website/docs/_posts/zh-cn/device-dev/porting/porting-minichip.md deleted file mode 100644 index c32898d6104ca0dcab7eb8d3fd7f2a4464673b20..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/porting/porting-minichip.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -title: porting-minichip -permalink: /pages/extra/bc2a1e/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 轻量系统芯片移植指导 - -- **[移植准备](/pages/extra/2bf51a/)** - -- **[内核移植](/pages/extra/7a2f63/)** - -- **[板级系统移植](/pages/extra/9257d8/)** - -- **[常见问题](/pages/01040104)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/porting/porting-smallchip-driver.md b/website/docs/_posts/zh-cn/device-dev/porting/porting-smallchip-driver.md deleted file mode 100644 index 3e1c8db85087b368c62c0ca5d0836d4f9eabc553..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/porting/porting-smallchip-driver.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: porting-smallchip-driver -permalink: /pages/extra/f63f6f/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 驱动移植 - -- **[移植概述](/pages/0104020301)** - -- **[平台驱动移植](/pages/0104020302)** - -- **[器件驱动移植](/pages/0104020303)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/porting/porting-smallchip-kernel.md b/website/docs/_posts/zh-cn/device-dev/porting/porting-smallchip-kernel.md deleted file mode 100644 index b1d20f36c9dc72566b9a3ce8b75ef87900c31fd3..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/porting/porting-smallchip-kernel.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: porting-smallchip-kernel -permalink: /pages/extra/2858ab/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 移植内核 - -- **[LiteOS-A内核](/pages/0104020201)** - -- **[Linux内核](/pages/0104020202)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/porting/porting-smallchip-prepare.md b/website/docs/_posts/zh-cn/device-dev/porting/porting-smallchip-prepare.md deleted file mode 100644 index 232244b58d5a5bf1d416baa9000449235d697a73..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/porting/porting-smallchip-prepare.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: porting-smallchip-prepare -permalink: /pages/extra/f4e07b/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 移植准备 - -- **[移植须知](/pages/0104020101)** - -- **[编译构建](/pages/0104020102)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/porting/porting-smallchip.md b/website/docs/_posts/zh-cn/device-dev/porting/porting-smallchip.md deleted file mode 100644 index 71b75ec3ac84c6e85a50e5eaaa7d73d82e1a365d..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/porting/porting-smallchip.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: porting-smallchip -permalink: /pages/extra/362558/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 小型系统芯片移植指导 - -- **[移植准备](/pages/extra/f4e07b/)** - -- **[移植内核](/pages/extra/2858ab/)** - -- **[驱动移植](/pages/extra/f63f6f/)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/porting/porting-thirdparty.md b/website/docs/_posts/zh-cn/device-dev/porting/porting-thirdparty.md deleted file mode 100644 index de02f920999452b58b4e5589056e544d34e013d2..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/porting/porting-thirdparty.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: porting-thirdparty -permalink: /pages/extra/e80fe1/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 轻量和小型系统三方库移植指导 - -- **[概述](/pages/01040401)** - -- **[CMake方式组织编译的库移植](/pages/01040402)** - -- **[Makefile方式组织编译的库移植](/pages/01040403)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/porting/porting.md b/website/docs/_posts/zh-cn/device-dev/porting/porting.md deleted file mode 100644 index e051f837bec624f0dcd17778e4fce805c324e04b..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/porting/porting.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -title: porting -permalink: /pages/extra/a8791f/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 移植 - -- **[三方库移植指导](/pages/extra/e80fe1/)** - -- **[轻量系统芯片移植指导](/pages/extra/bc2a1e/)** - -- **[小型系统芯片移植指导](/pages/extra/362558/)** - -- **[标准系统移植指导](/pages/01040301)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/quick-start/Readme-CN.md b/website/docs/_posts/zh-cn/device-dev/quick-start/Readme-CN.md deleted file mode 100644 index 8778c55267980b0242a79d78d93b039fc4eb755d..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/quick-start/Readme-CN.md +++ /dev/null @@ -1,77 +0,0 @@ ---- -title: Readme-CN -permalink: /pages/extra/eec566/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 快速入门 - -- [轻量和小型系统入门](/pages/extra/fdee28/) - - [轻量与小型系统入门概述](/pages/01020101) - - [搭建轻量与小型系统环境](/pages/extra/770961/) - - [搭建系统环境概述](/pages/0102010201) - - [开发环境准备](/pages/0102010202) - - [获取源码](/pages/0102010203) - - [使用安装包方式搭建编译环境](/pages/0102010204) - - [使用Docker方式搭建编译环境](/pages/0102010205) - - [常见问题](/pages/0102010206) - - - [运行“Hello World”](/pages/extra/e5f98d/) - - [Hi3861开发板](/pages/extra/d8f8db/) - - [安装开发板环境](/pages/010201030101) - - [新建应用程序](/pages/010201030102) - - [编译](/pages/010201030103) - - [烧录](/pages/010201030104) - - [调试验证](/pages/010201030105) - - [运行](/pages/010201030106) - - [常见问题](/pages/010201030107) - - - [Hi3516开发板](/pages/extra/f3d084/) - - [安装开发板环境](/pages/010201030201) - - [新建应用程序](/pages/010201030202) - - [编译](/pages/010201030203) - - [烧录](/pages/010201030204) - - [运行](/pages/010201030205) - - [常见问题](/pages/010201030206) - - - [Hi3518开发板](/pages/extra/7db1f4/) - - [安装开发板环境](/pages/010201030301) - - [新建应用程序](/pages/010201030302) - - [编译](/pages/010201030303) - - [烧录](/pages/010201030304) - - [运行](/pages/010201030305) - - [常见问题](/pages/010201030306) - - - [附录](/pages/extra/d372c4/) - - [Hi3861开发板介绍](/pages/0102010401) - - [Hi3516开发板介绍](/pages/0102010402) - - [Hi3518开发板介绍](/pages/0102010403) - -- [标准系统入门](/pages/extra/6dca5d/) - - [标准系统入门简介](/pages/01020201) - - [标准系统开发环境准备(仅Hi3516需要)](/pages/01020202) - - [获取源码](/pages/01020203) - - [运行“Hello World”](/pages/extra/743c79/) - - [Hi3516开发板](/pages/extra/d76ae0/) - - [创建应用程序](/pages/010202040101) - - [编译](/pages/010202040102) - - [烧录](/pages/010202040103) - - [运行](/pages/010202040104) - - - [RK3568开发板](/pages/extra/e45186/) - - [创建应用程序](/pages/010202040201) - - [编译](/pages/010202040202) - - [烧录](/pages/010202040203) - - [运行](/pages/010202040204) - - - [常见问题](/pages/01020205) - - [附录](/pages/extra/f03f91/) - - [Hi3516开发板介绍](/pages/0102020601) - - [RK3568开发板介绍](/pages/0102020602) \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/device-dev/quick-start/quickstart-lite-env-setup.md b/website/docs/_posts/zh-cn/device-dev/quick-start/quickstart-lite-env-setup.md index 72d1acb01d56f17af437886e87f81a6a15661c26..df131aabb1c82938b06cf36965dc8b19d07068c7 100644 --- a/website/docs/_posts/zh-cn/device-dev/quick-start/quickstart-lite-env-setup.md +++ b/website/docs/_posts/zh-cn/device-dev/quick-start/quickstart-lite-env-setup.md @@ -1,28 +1,24 @@ --- -title: quickstart-lite-env-setup -permalink: /pages/extra/770961/ +title: quickstart-lite-env-setup.md +permalink: /pages/extra/a5e1ee/ navbar: true sidebar: false prev: false next: false -search: true -article: true +search: false +article: false comment: false editLink: false -date: 2022-02-14 21:31:38 +date: 2021-12-30 12:57:44 --- -# 搭建轻量与小型系统环境 +# 搭建系统环境 -- **[搭建系统环境概述](/pages/0102010201)** +- **[概述](/pages/0001000200)** -- **[开发环境准备](/pages/0102010202)** +- **[Windows开发环境准备](/pages/0001000201)** -- **[获取源码](/pages/0102010203)** +- **[获取源码及Ubuntu编译环境准备](/pages/0001000202)** -- **[使用安装包方式搭建编译环境](/pages/0102010204)** - -- **[使用Docker方式搭建编译环境](/pages/0102010205)** - -- **[常见问题](/pages/0102010206)** +- **[常见问题](/pages/0001000203)** diff --git a/website/docs/_posts/zh-cn/device-dev/quick-start/quickstart-lite-introduction.md b/website/docs/_posts/zh-cn/device-dev/quick-start/quickstart-lite-introduction.md deleted file mode 100644 index e8e5248a996bc5bc026c07a9c3e84534a1318abe..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/quick-start/quickstart-lite-introduction.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: quickstart-lite-introduction -permalink: /pages/extra/d372c4/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 附录 - -- **[Hi3861开发板介绍](/pages/0102010401)** - -- **[Hi3516开发板介绍](/pages/0102010402)** - -- **[Hi3518开发板介绍](/pages/0102010403)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/quick-start/quickstart-lite-steps-hi3516.md b/website/docs/_posts/zh-cn/device-dev/quick-start/quickstart-lite-steps-hi3516.md deleted file mode 100644 index 6f4a9868c20b17aeae22c00f7070667b3ef39374..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/quick-start/quickstart-lite-steps-hi3516.md +++ /dev/null @@ -1,28 +0,0 @@ ---- -title: quickstart-lite-steps-hi3516 -permalink: /pages/extra/f3d084/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# Hi3516开发板 - -- **[安装开发板环境](/pages/010201030201)** - -- **[新建应用程序](/pages/010201030202)** - -- **[编译](/pages/010201030203)** - -- **[烧录](/pages/010201030204)** - -- **[运行](/pages/010201030205)** - -- **[常见问题](/pages/010201030206)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/quick-start/quickstart-lite-steps-hi3518.md b/website/docs/_posts/zh-cn/device-dev/quick-start/quickstart-lite-steps-hi3518.md deleted file mode 100644 index 8aeae4930c119de5d26c63d7de514e4682b57ab6..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/quick-start/quickstart-lite-steps-hi3518.md +++ /dev/null @@ -1,28 +0,0 @@ ---- -title: quickstart-lite-steps-hi3518 -permalink: /pages/extra/7db1f4/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# Hi3518开发板 - -- **[安装开发板环境](/pages/010201030301)** - -- **[新建应用程序](/pages/010201030302)** - -- **[编译](/pages/010201030303)** - -- **[烧录](/pages/010201030304)** - -- **[运行](/pages/010201030305)** - -- **[常见问题](/pages/010201030306)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/quick-start/quickstart-lite-steps-hi3861.md b/website/docs/_posts/zh-cn/device-dev/quick-start/quickstart-lite-steps-hi3861.md deleted file mode 100644 index fa44448f459465f8eae7edefd49145e40d1b653a..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/quick-start/quickstart-lite-steps-hi3861.md +++ /dev/null @@ -1,30 +0,0 @@ ---- -title: quickstart-lite-steps-hi3861 -permalink: /pages/extra/d8f8db/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# Hi3861开发板 - -- **[安装开发板环境](/pages/010201030101)** - -- **[新建应用程序](/pages/010201030102)** - -- **[编译](/pages/010201030103)** - -- **[烧录](/pages/010201030104)** - -- **[调试验证](/pages/010201030105)** - -- **[运行](/pages/010201030106)** - -- **[常见问题](/pages/010201030107)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/quick-start/quickstart-lite-steps.md b/website/docs/_posts/zh-cn/device-dev/quick-start/quickstart-lite-steps.md deleted file mode 100644 index 130c7db2086e1cd00b4dffe5426c87c795736a70..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/quick-start/quickstart-lite-steps.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: quickstart-lite-steps -permalink: /pages/extra/e5f98d/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# 运行“Hello World” - -- **[Hi3861开发板](/pages/extra/d8f8db/)** - -- **[Hi3516开发板](/pages/extra/f3d084/)** - -- **[Hi3518开发板](/pages/extra/7db1f4/)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/quick-start/quickstart-lite.md b/website/docs/_posts/zh-cn/device-dev/quick-start/quickstart-lite.md deleted file mode 100644 index bed597c6cf3572722028f8f9f0d22ff2102f96e3..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/quick-start/quickstart-lite.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -title: quickstart-lite -permalink: /pages/extra/fdee28/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 轻量和小型系统入门 - -- **[轻量与小型系统入门概述](/pages/01020101)** - -- **[搭建轻量与小型系统环境](/pages/extra/770961/)** - -- **[运行“Hello World”](/pages/extra/e5f98d/)** - -- **[附录](/pages/extra/d372c4/)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/quick-start/quickstart-standard-appendix.md b/website/docs/_posts/zh-cn/device-dev/quick-start/quickstart-standard-appendix.md deleted file mode 100644 index aae522df26e77a49f2196433623268f4a23ed1eb..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/quick-start/quickstart-standard-appendix.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: quickstart-standard-appendix -permalink: /pages/extra/f03f91/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 附录 - -- **[Hi3516开发板介绍](/pages/0102020601)** - -- **[RK3568开发板介绍](/pages/0102020602)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/quick-start/quickstart-standard-running-hi3516.md b/website/docs/_posts/zh-cn/device-dev/quick-start/quickstart-standard-running-hi3516.md deleted file mode 100644 index f5274e26f863af4e2db331a0809b6a183a0c534e..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/quick-start/quickstart-standard-running-hi3516.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -title: quickstart-standard-running-hi3516 -permalink: /pages/extra/d76ae0/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# Hi3516开发板 - -- **[创建应用程序](/pages/010202040101)** - -- **[源码编译](/pages/010202040102)** - -- **[镜像烧录](/pages/010202040103)** - -- **[镜像运行](/pages/010202040104)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/quick-start/quickstart-standard-running-rk3568.md b/website/docs/_posts/zh-cn/device-dev/quick-start/quickstart-standard-running-rk3568.md deleted file mode 100644 index d0c1245de155fc840c4261c7ae0f7c524765e139..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/quick-start/quickstart-standard-running-rk3568.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -title: quickstart-standard-running-rk3568 -permalink: /pages/extra/e45186/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# RK3568开发板 - -- **[创建应用程序](/pages/010202040201)** - -- **[源码编译](/pages/010202040202)** - -- **[镜像烧录](/pages/010202040203)** - -- **[镜像运行](/pages/010202040204)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/quick-start/quickstart-standard-running.md b/website/docs/_posts/zh-cn/device-dev/quick-start/quickstart-standard-running.md deleted file mode 100644 index a952abf67f6ee70a0e1c9fdf1702637aa1c19328..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/quick-start/quickstart-standard-running.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: quickstart-standard-running -permalink: /pages/extra/743c79/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 运行“Hello World” - -- **[Hi3516开发板](/pages/extra/d76ae0/)** - -- **[RK3568开发板](/pages/extra/e45186/)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/quick-start/quickstart-standard.md b/website/docs/_posts/zh-cn/device-dev/quick-start/quickstart-standard.md index fa78d8d220ae26785888d3881bfd30248250b7e6..38fcde58852b51f9141979d2c58cc4ac82b5875c 100644 --- a/website/docs/_posts/zh-cn/device-dev/quick-start/quickstart-standard.md +++ b/website/docs/_posts/zh-cn/device-dev/quick-start/quickstart-standard.md @@ -1,28 +1,30 @@ --- -title: quickstart-standard -permalink: /pages/extra/6dca5d/ +title: quickstart-standard.md +permalink: /pages/extra/4b9ca0/ navbar: true sidebar: false prev: false next: false -search: true -article: true +search: false +article: false comment: false editLink: false -date: 2022-02-14 21:31:38 +date: 2021-12-30 12:57:45 --- # 标准系统入门 -- **[标准系统入门简介](/pages/01020201)** +- **[入门介绍](/pages/00010100)** -- **[标准系统开发环境准备(仅Hi3516需要)](/pages/01020202)** +- **[搭建Windows开发环境](/pages/00010101)** -- **[获取源码](/pages/01020203)** +- **[搭建Ubuntu环境\(获取源码及编译,Docker方式\)](/pages/00010102)** -- **[运行“Hello World”](/pages/extra/743c79/)** +- **[搭建Ubuntu环境\(获取源码及编译,安装包方式\)](/pages/00010103)** -- **[常见问题](/pages/01020205)** +- **[镜像烧录](/pages/00010104)** -- **[附录](/pages/extra/f03f91/)** +- **[镜像运行](/pages/00010105)** + +- **[常见问题](/pages/00010106)** diff --git a/website/docs/_posts/zh-cn/device-dev/quick-start/quickstart.md b/website/docs/_posts/zh-cn/device-dev/quick-start/quickstart.md deleted file mode 100644 index ea7bd035780663b4cb01c7c93c06f29b149549f4..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/quick-start/quickstart.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: quickstart -permalink: /pages/extra/5703bf/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 快速入门 - -- **[轻量和小型系统入门](/pages/extra/fdee28/)** - -- **[标准系统入门](/pages/extra/6dca5d/)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/security/Readme-CN.md b/website/docs/_posts/zh-cn/device-dev/security/Readme-CN.md deleted file mode 100644 index 014498c34416fa5381960b98ddabfe8c5da09961..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/security/Readme-CN.md +++ /dev/null @@ -1,18 +0,0 @@ ---- -title: Readme-CN -permalink: /pages/extra/b51404/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 隐私与安全 - -- [隐私保护](/pages/01030101) -- [安全指南](/pages/01030102) - diff --git a/website/docs/_posts/zh-cn/device-dev/security/security.md b/website/docs/_posts/zh-cn/device-dev/security/security.md deleted file mode 100644 index 7ffa22941162cee9ab8864bda3b53c27de474ab4..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/security/security.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: security -permalink: /pages/extra/d0d683/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 隐私与安全 - -- **[隐私保护](/pages/01030101)** - -- **[安全指南](/pages/01030102)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/subsystems/Readme-CN.md b/website/docs/_posts/zh-cn/device-dev/subsystems/Readme-CN.md deleted file mode 100644 index ff8a9b3d56717fe7e5594cc945053fa4aded6479..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/subsystems/Readme-CN.md +++ /dev/null @@ -1,105 +0,0 @@ ---- -title: Readme-CN -permalink: /pages/extra/e6eae1/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 子系统开发指南 - -- [编译构建](/pages/extra/7014d3/) - - [轻量和小型系统编译构建指导](/pages/01050301) - - [标准系统编译构建指导](/pages/01050302) - - [构建系统编码规范和最佳实践指导](/pages/01050303) -- [分布式远程启动](/pages/010504) -- [图形图像](/pages/extra/7fcbf2/) - - [图形图像概述](/pages/01050501) - - [容器类组件开发指导](/pages/01050502) - - [布局容器类组件开发指导](/pages/01050503) - - [普通组件开发指导](/pages/01050504) - - [动画开发指导](/pages/01050505) -- [媒体](/pages/extra/c169e0/) - - [相机](/pages/extra/ad4327/) - - [相机开发概述](/pages/0105060101) - - [拍照开发指导](/pages/0105060102) - - [录像开发指导](/pages/0105060103) - - [预览开发指导](/pages/0105060104) - - [音视频](/pages/extra/f106bb/) - - [音视频开发概述](/pages/0105060201) - - [音视频播放开发指导](/pages/0105060202) - - [音视频录制开发指导](/pages/0105060203) -- [公共基础](/pages/extra/ce319f/) - - [公共基础库概述](/pages/01050701) - - [公共基础库开发指导](/pages/01050702) - - [公共基础库常见问题](/pages/01050703) -- [AI框架](/pages/extra/ac23c8/) - - [AI引擎框架开发指南](/pages/01050801) - - [搭建环境](/pages/01050802) - - [技术规范](/pages/extra/574388/) - - [代码管理规范](/pages/0105080301) - - [命名规范](/pages/0105080302) - - [接口开发规范](/pages/0105080303) - - [开发指导](/pages/extra/6e5a07/) - - [SDK开发过程](/pages/0105080401) - - [插件的开发过程](/pages/0105080402) - - [配置文件的开发过程](/pages/0105080403) - - [开发示例](/pages/extra/1bd7d2/) - - [唤醒词识别SDK的开发示例](/pages/0105080501) - - [唤醒词识别插件的开发示例](/pages/0105080502) - - [唤醒词识别配置文件的开发示例](/pages/0105080503) -- [数据管理](/pages/extra/c92e1f/) - - [关系型数据库](/pages/extra/4b14bb/) - - [关系型数据库概述](/pages/extra/11c33d/) - - [关系型数据库开发指导](/pages/extra/b716c7/) - - [轻量级数据存储](/pages/extra/829325/) - - [轻量级数据存储概述](/pages/extra/ee7dd9/) - - [轻量级数据存储开发指导](/pages/extra/69c638/) -- [Sensor服务](/pages/extra/fdd664/) - - [Sensor服务子系概述](/pages/01050901) - - [Sensor服务子系使用指导](/pages/01050902) - - [Sensor服务子系使用实例](/pages/01050903) -- [用户程序框架](/pages/extra/72b946/) - - [概述](/pages/01050a01) - - [搭建环境](/pages/01050a02) - - [开发指导](/pages/01050a03) - - [开发实例](/pages/01050a04) -- [OTA升级](/pages/01050b) -- [电话服务](/pages/extra/019068/) - - [电话服务概述](/pages/01050c01) - - [电话服务开发指导](/pages/01050c02) -- [安全](/pages/extra/2dd473/) - - [概述](/pages/01050d01) - - [应用验签开发指导](/pages/01050d02) - - [应用权限管理开发指导](/pages/01050d03) - - [IPC通信鉴权开发指导](/pages/01050d04) -- [启动恢复](/pages/extra/9238e4/) - - [启动恢复子系统概述](/pages/01050e01) - - [init启动引导组件](/pages/01050e02) - - [appspawn应用孵化组件](/pages/01050e03) - - [bootstrap服务启动组件](/pages/01050e04) - - [syspara系统属性组件](/pages/01050e05) - - [常见问题](/pages/01050e06) - - [参考](/pages/01050e07) -- [测试用例开发指导](/pages/010901) -- [DFX](/pages/extra/684ab8/) - - [DFX概述](/pages/01051001) - - [HiLog开发指导](/pages/01051002) - - [HiLog\_Lite开发指导](/pages/01051003) - - [HiTrace开发指导](/pages/01051004) - - [HiCollie开发指导](/pages/01051005) - - [HiSysEvent开发指导](/pages/01050f04) - - [HiSysEvent打点指导](/pages/0105100601) - - [HiSysEvent订阅指导](/pages/0105100602) - - [HiSysEvent查询指导](/pages/0105100603) - - [HiSysEvent工具使用指导](/pages/0105100604) -- [研发工具链](/pages/extra/5138cc/) - - [bytrace使用指导](/pages/01090201) - - [hdc\_std 使用指导](/pages/01090202) - - [hiperf 使用指南](/pages/extra/715dd9/) -- [XTS认证用例开发指导](/pages/010a01) diff --git a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-aiframework-demo.md b/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-aiframework-demo.md deleted file mode 100644 index 2264ef87f25d45cbf9d8a3f4918caffeeeb5792f..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-aiframework-demo.md +++ /dev/null @@ -1,26 +0,0 @@ ---- -title: subsys-aiframework-demo -permalink: /pages/extra/1bd7d2/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 开发示例 - -以开发唤醒词识别为例,开发者可在Hi3516DV300开发板上,基于AI引擎框架开发唤醒词识别的sdk以及唤醒词识别的plugin,通过编译命令编出新的版本镜像并将其烧入版本。同时,开发者开发唤醒词识别的应用,该应用能够接收外部音频,将listen到的音频传入SDK中的接口,若音频中带有关键词,唤醒词识别的应用会识别出相应的词语,并打印在命令行中。 - -本示例中唤醒词识别的场景中唤醒词是固定的,当开发者传入的音频包含”Hi,小问“,启动的应用就会打印"\[Hi, xiaowen\]",当不包含时,会打印'\[UNKNOWN\]"。 - -- **[唤醒词识别SDK的开发示例](/pages/0105080501)** - -- **[唤醒词识别插件的开发示例](/pages/0105080502)** - -- **[唤醒词识别配置文件的开发示例](/pages/0105080503)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-aiframework-devguide.md b/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-aiframework-devguide.md deleted file mode 100644 index b5d7576144d5e4ae90c5bc56785c6846d6658324..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-aiframework-devguide.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -title: subsys-aiframework-devguide -permalink: /pages/extra/6e5a07/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 开发指导 - -为实现AI 引擎框架的接入,开发者需开发上述[图1](/pages/01050801#fig143186187187)中的SDK模块和Plugin模块,通过调用sdk提供的接口,基于AI引擎框架实现调用plugin中算法的能力,从而实现AI能力的生命周期管理和按需部署功能。 - -- **[SDK开发过程](/pages/0105080401)** - -- **[插件的开发过程](/pages/0105080402)** - -- **[配置文件的开发过程](/pages/0105080403)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-aiframework-tech.md b/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-aiframework-tech.md deleted file mode 100644 index 26a50abb7a38f73ca9bbce3e731b1f2b1983e656..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-aiframework-tech.md +++ /dev/null @@ -1,28 +0,0 @@ ---- -title: subsys-aiframework-tech -permalink: /pages/extra/574388/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 技术规范 - -**用词约定:** - -**规则**:必须准守的约定 - -**建议**:需要加以考虑的约定 - -- **[代码管理规范](/pages/0105080301)** - -- **[命名规范](/pages/0105080302)** - -- **[接口开发规范](/pages/0105080303)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-aiframework.md b/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-aiframework.md deleted file mode 100644 index fb8b2f399f1c86a97ffb78c7f2f0f22b073fbbf8..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-aiframework.md +++ /dev/null @@ -1,26 +0,0 @@ ---- -title: subsys-aiframework -permalink: /pages/extra/ac23c8/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# AI框架 - -- **[AI引擎框架开发指南](/pages/01050801)** - -- **[搭建环境](/pages/01050802)** - -- **[技术规范](/pages/extra/574388/)** - -- **[开发指导](/pages/extra/6e5a07/)** - -- **[开发示例](/pages/extra/1bd7d2/)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-application-framework.md b/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-application-framework.md deleted file mode 100644 index 2bda3b983c689d860098f2127babc9149afe680b..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-application-framework.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -title: subsys-application-framework -permalink: /pages/extra/72b946/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 用户程序框架 - -- **[概述](/pages/01050a01)** - -- **[搭建环境](/pages/01050a02)** - -- **[开发指导](/pages/01050a03)** - -- **[开发实例](/pages/01050a04)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-boot.md b/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-boot.md deleted file mode 100644 index 72e33e5eb3929ca8c1dd51687feae5aa96529b73..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-boot.md +++ /dev/null @@ -1,30 +0,0 @@ ---- -title: subsys-boot -permalink: /pages/extra/9238e4/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 启动恢复 - -- **[启动恢复子系统概述](/pages/01050e01)** - -- **[init启动引导组件](/pages/01050e02)** - -- **[appspawn应用孵化组件](/pages/01050e03)** - -- **[bootstrap服务启动组件](/pages/01050e04)** - -- **[syspara系统属性组件](/pages/01050e05)** - -- **[常见问题](/pages/01050e06)** - -- **[参考](/pages/01050e07)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-build.md b/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-build.md deleted file mode 100644 index 9e34668eb7e1f6a31768be31fe0fd52c03c096f5..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-build.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: subsys-build -permalink: /pages/extra/7014d3/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 编译构建 - -- **[轻量和小型系统编译构建指导](/pages/01050301)** - -- **[标准系统编译构建指导](/pages/01050302)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-data-relational-database-guide.md b/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-data-relational-database-guide.md deleted file mode 100644 index 1b94706f7e3507298214734ad716fa22069dc2c5..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-data-relational-database-guide.md +++ /dev/null @@ -1,204 +0,0 @@ ---- -title: subsys-data-relational-database-guide -permalink: /pages/extra/b716c7/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 关系型数据库开发指导 - -## 场景介绍 - -关系型数据库是在SQLite基础上实现的本地数据操作机制,提供给用户无需编写原生SQL语句就能进行数据增删改查的方法,同时也支持原生SQL语句操作。 - -## 接口说明 -### 数据库的创建和删除 - -关系型数据库提供了数据库创建方式,以及对应的删除接口,涉及的API如下所示。 - -表1 数据库创建和删除API - -| 类名 | 接口名 | 描述 | -| ---- | ---- | ---- | -| RdbStoreConfig | RdbStoreConfig(const std::string &path,
StorageMode storageMode = StorageMode::MODE_DISK,
bool readOnly = false,
const std::vector &encryptKey = std::vector(),
const std::string &journalMode = "",
const std::string &syncMode = "",
const std::string &databaseFileType = "",
const std::string &databaseFileSecurityLevel = "") | 对数据库进行配置,包括设置数据库名、存储模式、日志模式、同步模式,是否为只读,及数据库加密。
  • path:数据库路径;
  • readOnly:是否只读;
  • storageMode:存储模式;
  • encryptKey:加密密钥;
  • journalMode:日志模式;
  • syncMode:同步模式;
  • databaseFileType:数据库类型;
  • databaseFileSecurityLevel:安全等级
| -| RdbOpenCallback | int OnCreate(RdbStore &rdbStore) | 数据库创建时被回调,开发者可以在该方法中初始化表结构,并添加一些应用使用到的初始化数据。 | -| RdbOpenCallback | int OnUpgrade(RdbStore &rdbStore, int currentVersion, int targetVersion) | 数据库升级时被回调。 | -| RdbOpenCallback | int OnDowngrade(RdbStore &rdbStore, int currentVersion, int targetVersion) | 数据库降级时被回调。 | -| RdbHelper | std::shared_ptr\ GetRdbStore(const RdbStoreConfig &config, int version, RdbOpenCallback &openCallback, int &errCode) | 根据配置创建或打开数据库。 | -| RdbHelper | int DeleteRdbStore(const std::string &path) | 删除指定的数据库。 | - -### 数据库的加密 - -关系型数据库提供数据库加密的能力,在创建数据库时若指定了密钥,则会创建为加密数据库。再次使用此数据库时,需要指定该密钥,才能正确打开数据库。 - -表2 数据库修改密钥API -| 类名 | 接口名 | 描述 | -| ---- | ---- | ---- | -| RdbStore | int ChangeEncryptKey(const std::vector &newKey) | 为数据库设置新的加密密钥。注:仅支持加密数据库更换加密密钥。 | - -### 数据库谓词的使用 - -关系型数据库提供了用于设置数据库操作条件的谓词AbsRdbPredicates,其中包括两个实现子类RdbPredicates和RawRdbPredicates: - -- RdbPredicates:开发者无需编写复杂的SQL语句,仅通过调用该类中条件相关的方法,如equalTo、notEqualTo、groupBy、orderByAsc、beginsWith等,就可自动完成SQL语句拼接,方便用户聚焦业务操作。 -- RawRdbPredicates:可满足复杂SQL语句的场景,支持开发者自己设置where条件子句和whereArgs参数。不支持equalTo等条件接口的使用。 - - 表7 数据库谓词API - | 类名 | 接口名 | 描述 | - | ---- | ---- | ---- | - | RdbPredicates | AbsPredicates *EqualTo(std::string field, std::string value) | 设置谓词条件,满足field字段与value值相等。 | - | RdbPredicates | AbsPredicates *NotEqualTo(std::string field, std::string value) | 设置谓词条件,满足field字段与value值不相等。 | - | RdbPredicates | AbsPredicates *BeginsWith(std::string field, std::string value) | 设置谓词条件,满足field字段以value值开头。 | - | RdbPredicates | AbsPredicates *Between(std::string field, std::string low, std::string high) | 设置谓词条件,满足field字段在最小值low和最大值high之间。 | - | RdbPredicates | AbsPredicates *OrderByAsc(std::string field) | 设置谓词条件,根据field字段升序排列。 | - | RdbPredicates | void SetWhereClause(std::string whereClause) | 设置where条件子句。 | - | RdbPredicates | void SetWhereArgs(std::vector\ whereArgs) | 设置whereArgs参数,该值表示where子句中占位符的值。 | - -### 数据表的增删改查 - -关系型数据库提供对本地数据增删改查操作的能力,相关API如下所示。 - -- 新增 - - 关系型数据库提供了插入数据的接口,通过ValuesBucket输入要存储的数据,通过返回值判断是否插入成功,插入成功时返回最新插入数据所在的行号,失败时则返回-1。 - - 表3 数据表插入API - - | 类名 | 接口名 | 描述 | - | ---- | ---- | ---- | - | RdbStore | int Insert(int64_t &outRowId, const std::string &table, const ValuesBucket &initialValues) | 向数据库插入数据。
  • table:待添加数据的表名。
  • initialValues:以ValuesBucket存储的待插入的数据。它提供一系列put方法,如PutString(const std::string &columnName, const std::string &value),PutDouble(const std::string &columnName, double value),用于向ValuesBucket中添加数据。
| - -- 删除 - - 调用删除接口,通过AbsRdbPredicates指定删除条件。该接口的返回值表示删除的数据行数,可根据此值判断是否删除成功。如果删除失败,则返回0。 - - 表5 数据表删除API - | 类名 | 接口名 | 描述 | - | ---- | ---- | ---- | - | RdbStore | int Delete(int &deletedRows, const AbsRdbPredicates &predicates) | 删除数据。
  • deletedRows:删除的记录条数。
  • predicates:Rdb谓词,指定了删除操作的表名和条件。AbsRdbPredicates的实现类有两个:RdbPredicates和RawRdbPredicates。
    • RdbPredicates:支持调用谓词提供的equalTo等接口,设置更新条件。
    • RawRdbPredicates:仅支持设置表名、where条件子句、whereArgs三个参数,不支持equalTo等接口调用。
| - -- 更新 - - 调用更新接口,传入要更新的数据,并通过AbsRdbPredicates指定更新条件。该接口的返回值表示更新操作影响的行数。如果更新失败,则返回0。 - - 表4 数据表更新API - | 类名 | 接口名 | 描述 | - | ---- | ---- | ---- | - | RdbStore | int Update(int &changedRows, const ValuesBucket &values, const AbsRdbPredicates &predicates) | 更新数据库表中符合谓词指定条件的数据。
  • changedRows:更新的记录条数。
  • values:以ValuesBucket存储的要更新的数据。
  • predicates:指定了更新操作的表名和条件。AbsRdbPredicates的实现类有两个:RdbPredicates和RawRdbPredicates。
    • RdbPredicates:支持调用谓词提供的equalTo等接口,设置更新条件。
    • RawRdbPredicates:仅支持设置表名、where条件子句、whereArgs三个参数,不支持equalTo等接口调用。
| - -- 查询 - - 关系型数据库提供了两种查询数据的方式: - - - 直接调用查询接口。使用该接口,会将包含查询条件的谓词自动拼接成完整的SQL语句进行查询操作,无需用户传入原生的SQL语句。 - - 执行原生的SQL语句进行查询操作。 - - 表6 数据表查询API - | 类名 | 接口名 | 描述 | - | ---- | ---- | ---- | - | RdbStore | std::unique_ptr Query(const AbsRdbPredicates &predicates, const std::vector\ columns) | 查询数据。
  • predicates:谓词,可以设置查询条件。AbsRdbPredicates的实现类有两个:RdbPredicates和RawRdbPredicates。
    • RdbPredicates:支持调用谓词提供的equalTo等接口,设置更新条件。
    • RawRdbPredicates:仅支持设置表名、where条件子句、whereArgs三个参数,不支持equalTo等接口调用。
  • columns:规定查询返回的列。
| - | RdbStore | std::unique_ptr QuerySql(const std::string &sql, const std::vector\ &selectionArgs = std::vector\()) | 执行原生的用于查询操作的SQL语句。
  • sql:原生用于查询的sql语句。
  • selectionArgs:sql语句中占位符参数的值,若select语句中没有使用占位符,该参数可以设置为null。
| - -### 查询结果集的使用 - -关系型数据库提供了查询返回的结果集ResultSet,其指向查询结果中的一行数据,供用户对查询结果进行遍历和访问。ResultSet对外API如下所示。 - - 表8 结果集API - | 类名 | 接口名 | 描述 | - | ---- | ---- | ---- | - | ResultSet | int GoTo(int offset) | 从结果集当前位置移动指定偏移量。 | - | ResultSet | int GoToRow(int position) | 将结果集移动到指定位置。 | - | ResultSet | int GoToNextRow() | 将结果集向后移动一行。 | - | ResultSet | int GoToPreviousRow() | 将结果集向前移动一行。 | - | ResultSet | int IsStarted(bool &result) | 判断结果集是否被移动过。 | - | ResultSet | int IsEnded(bool &result) | 判断结果集是否被移动到最后一行之后。 | - | ResultSet | int IsAtFirstRow(bool &result) | 判断结果集当前位置是否在第一行。 | - | ResultSet | int IsAtLastRow(bool &result) | 判断结果集当前位置是否在最后一行。 | - | ResultSet | int GetRowCount(int &count) | 获取当前结果集中的记录条数。 | - | ResultSet | int GetColumnCount(int &count) | 获取结果集中的列数。 | - | ResultSet | int GetString(int columnIndex, std::string &value) | 获取当前行指定列的值,以String类型返回。 | - | ResultSet | int GetBlob(int columnIndex, std::vector\ &blob) | 获取当前行指定列的值,以字节数组形式返回。 | - | ResultSet | int GetDouble(int columnIndex, double &value) | 获取当前行指定列的值,以double型返回。 | - -## 约束与限制 - -无。 - -## 开发步骤 - -1. 创建数据库。 - - a. 配置数据库相关信息,包括数据库的名称、存储模式、是否为只读模式等。 - - b. 初始化数据库表结构和相关数据。 - - c. 创建数据库。 - - 示例代码如下: - ``` - const std::string DATABASE_NAME = RDB_TEST_PATH + "RdbStoreTest.db"; - const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER, salary REAL, blobType BLOB)"; - - class OpenCallback : public RdbOpenCallback { - public: - int OnCreate(RdbStore &rdbStore) override; - int OnUpgrade(RdbStore &rdbStore, int oldVersion, int newVersion) override; - }; - - int OpenCallback::OnCreate(RdbStore &store) - { - return store.ExecuteSql(CREATE_TABLE_TEST); - } - - RdbStoreConfig config(DATABASE_NAME); - OpenCallback callback; - - std::shared_ptr store = RdbHelper::GetRdbStore(config, 1, callback, 0); - ``` - -2. 插入数据。 - - a. 构造要插入的数据,以ValuesBucket形式存储。 - - b. 调用关系型数据库提供的插入接口。 - - c. 创建数据库。 - - 示例代码如下: - ``` - ValuesBucket values; - - values.PutInt("id", 1); - values.PutString("name", std::string("Tom")); - values.PutInt("age", 18); - values.PutDouble("salary", 100.5); - values.PutBlob("blobType", std::vector{ 1, 2, 3 }); - store->Insert(id, "test", values); - ``` - -3. 查询数据。 - - a. 构造用于查询的谓词对象,设置查询条件。 - - b. 指定查询返回的数据列。 - - c. 调用查询接口查询数据。 - - d. 调用结果集接口,遍历返回结果。 - - 示例代码如下: - ``` - std::vector columns = {"id", "name", "age", "salary"}; - - RdbPredicates predicates("test"); - predicates.EqualTo("age", "25")->OrderByAsc("salary"); - std::unique_ptr resultSet = store->Query(predicates, columns) - resultSet.goToNextRow(); - ``` - diff --git a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-data-relational-database-overview.md b/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-data-relational-database-overview.md deleted file mode 100644 index 4d1326b3980944c431a0698ead1b77ce70209a1e..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-data-relational-database-overview.md +++ /dev/null @@ -1,52 +0,0 @@ ---- -title: subsys-data-relational-database-overview -permalink: /pages/extra/11c33d/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 关系型数据库概述 - -关系型数据库(Relational Database,RDB)是一种基于关系模型来管理数据的数据库。OpenHarmony关系型数据库基于SQLite组件提供了一套完整的对本地数据库进行管理的机制,对外提供了一系列的增、删、改、查等接口,也可以直接运行用户输入的SQL语句来满足复杂的场景需要。 - -## 基本概念 - -- 关系型数据库 - - 基于关系模型来管理数据的数据库,以行和列的形式存储数据。 - -- 谓词 - - 数据库中用来代表数据实体的性质、特征或者数据实体之间关系的词项,主要用来定义数据库的操作条件。 - -- 结果集 - - 指用户查询之后的结果集合,可以对数据进行访问。结果集提供了灵活的数据访问方式,可以更方便的拿到用户想要的数据。 - -- SQLite数据库 - - 一款遵守ACID的轻型开源关系型数据库管理系统。 - -## 运作机制 -OpenHarmony关系型数据库对外提供通用的操作接口(即Rdb Store接口),底层使用第三方开源组件SQLite作为持久化存储引擎,支持SQLite具有的所有数据库特性。 - -**图1** 关系型数据库运作机制 - -![](/images/device-dev/subsystems/figure/zh-cn_image_0000001115980740.png) - -## 默认配置 -- 如果不指定数据库的日志模式,那么系统默认日志方式是WAL(Write Ahead Log)模式。 -- 如果不指定数据库的落盘模式,那么系统默认落盘方式是FULL模式。 -- OpenHarmony数据库使用的共享内存默认大小是8MB,单次查询使用的共享内存默认大小是2MB。 - -## 约束与限制 -- 数据库中连接池的最大数量是4个,用以管理用户的读操作。 -- 为保证数据的准确性,数据库同一时间只能支持一个写操作。 - - diff --git a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-data-relational-database.md b/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-data-relational-database.md deleted file mode 100644 index 230dd6ea4e876c103a3610f4eaae921c9dd6c9da..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-data-relational-database.md +++ /dev/null @@ -1,18 +0,0 @@ ---- -title: subsys-data-relational-database -permalink: /pages/extra/4b14bb/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 关系型数据库 - -- **[关系型数据库概述](/pages/extra/11c33d/)** - -- **[关系型数据库开发指导](/pages/extra/b716c7/)** diff --git a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-data-storage-guide.md b/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-data-storage-guide.md deleted file mode 100644 index 1b796b1252c209460fd0b11d6415b66f65d7a029..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-data-storage-guide.md +++ /dev/null @@ -1,208 +0,0 @@ ---- -title: subsys-data-storage-guide -permalink: /pages/extra/69c638/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 轻量级数据存储开发指导 - -## 场景介绍 - -轻量级数据存储功能通常用于保存应用的一些常用配置信息,并不适合需要存储大量数据和频繁改变数据的场景。应用的数据保存在文件中,这些文件可以持久化地存储在设备上。需要注意的是,应用访问的实例包含文件所有数据,这些数据会一直加载在设备的内存中,直到应用主动从内存中将其移除前,应用可以通过Preferences的API进行数据操作。 - -## 接口说明 - -轻量级存储为应用提供key-value键值型的文件数据处理能力,支持应用对数据进行轻量级存储及查询。数据存储形式为键值对,键的类型为字符串型,值的存储数据类型包括字符串型、布尔型、整数型、长整型、浮点型、双精度类型和字符串数组。 - -**创建存储实例** - -读取指定文件,将数据加载到Preferences实例,即可创建一个存储实例,用于数据操作。 - -**表 1** 轻量级数据存储实例创建接口 - -| 类名 | 方法名 | 描述 | -| --- | ----- | ----| -| PreferencesHelper | static std::shared_ptr GetPreferences(const std::string &path, int &errCode); | path:应用程序内部数据存储路径。
errCode:错误码。
返回值:轻量级存储实例。 | - -**存入数据** - -通过Put系列方法,可以增加或修改Preferences实例中的数据。 - -**表 2** 轻量级偏好数据库存入接口 - -| 类名 | 方法名 | 描述 | -| --- | ----- | ----| -| Preferences | int PutInt(const std::string &key, int value); | key:将要存储的key名称,不能为空。
value:将要存储的value。
返回值:错误码。 | -| Preferences | int PutString(const std::string &key, const std::string &value); | key:将要存储的key名称,不能为空。
value:将要存储的value。
返回值:错误码。 | -| Preferences | int PutBool(const std::string &key, bool value); | key:将要存储的key名称,不能为空。
value:将要存储的value。
返回值:错误码。 | -| Preferences | int PutLong(const std::string &key, int64_t value); | key:将要存储的key名称,不能为空。
value:将要存储的value。
返回值:错误码。 | -| Preferences | int PutFloat(const std::string &key, float value); | key:将要存储的key名称,不能为空。
value:将要存储的value。
返回值:错误码。 | -| Preferences | int PutDouble(const std::string &key, double value); | key:将要存储的key名称,不能为空。
value:将要存储的value。
返回值:错误码。 | -| Preferences | int PutStringSet(const std::string &key, const std::set\ &value); | key:将要存储的key名称,不能为空。
value:将要存储的。
返回值:错误码。 | - -**读取数据** - -通过调用Get系列方法,可以读取Preferences中的数据。 - -**表 3** 轻量级数据读取接口 - -| 类名 | 方法名 | 描述 | -| --- | ----- | ----| -| Preferences | bool GetBool(const std::string &key, bool defValue); | key:要获取的存储key名称,不能为空。
defValue:若获取失败或value不存在返回此默认值。
返回值:value。 | -| Preferences | std::string GetString(const std::string &key, const std::string &defValue); | key:要获取的存储key名称,不能为空。
defValue:若获取失败或value不存在返回此默认值。
返回值:value。 | -| Preferences | bool GetBool(const std::string &key, bool defValue); | key:要获取的存储key名称,不能为空。
defValue:若获取失败或value不存在返回此默认值。
返回值:value。 | -| Preferences | float GetFloat(const std::string &key, float defValue); | key:要获取的存储key名称,不能为空。
defValue:若获取失败或value不存在返回此默认值。
返回值:value。 | -| Preferences | double GetDouble(const std::string &key, double defValue); | key:要获取的存储key名称,不能为空。
defValue:若获取失败或value不存在返回此默认值。
返回值:value。 | -| Preferences | int64_t GetLong(const std::string &key, int64_t defValue); | key:要获取的存储key名称,不能为空。
defValue:若获取失败或value不存在返回此默认值。
返回值:value。 | -| Preferences | std::set\ GetStringSet(const std::string &key, std::set\ &defValue); | key:要获取的存储key名称,不能为空。
defValue:若获取失败或value不存在返回此默认值。
返回值:value。 | - -**数据持久化** - -通过执行flush或者flushSync方法,应用可以将缓存的数据再次写回文本文件中进行持久化存储。 - -**表 5** 轻量级数据数据持久化接口 - -| 类名 | 方法名 | 描述 | -| --- | ----- | ----| -| Preferences | void Flush(); | 将Preferences实例通过异步线程回写入文件中。 | -| Preferences | int FlushSync(); | 将Preferences实例通过同步线程回写入文件中,并返回错误码。 | - -**订阅数据变化** - -订阅数据变化需要指定PreferencesObserver作为回调方法。订阅的key的值发生变更后,当执行flush方法时,PreferencesObserver被回调。 - -**表 5** 轻量级数据变化订阅接口 - -| 类名 | 方法名 | 描述 | -| --- | ----- | ----| -| Preferences | void RegisterObserver(std::shared_ptr preferencesObserver); | preferencesObserver:需要订阅的回调对象实例。 | -| Preferences | void UnRegisterObserver(std::shared_ptr preferencesObserver); | preferencesObserver:需要注销订阅的回调对象实例。 | - -**删除数据文件** - -通过调用以下两种接口,可以删除数据实例或对应的文件。 - -**表 6** 轻量级数据存储删除接口 - -| 类名 | 方法名 | 描述 | -| --- | ----- | ----| -| PreferencesHelper | int DeletePreferences(const std::string &path); | 将Preferences实例从内存中移除,同时删除其在设备上的持久化文件。path:应用程序内部数据存储路径。
返回值:错误码。 | -| PreferencesHelper | int RemovePreferencesFromCache(const std::string &path); | 仅将Preferences实例从内存中移除。path:应用程序内部数据存储路径。
返回值:错误码。 | - -## 开发步骤 - -1. 准备工作,引入preferences以及相关的头文件到开发环境。 - - ``` C++ - 头文件路径://distributeddatamgr_appdatamgr/interfaces/innerkits/native_preferences/include - ``` - -2. 获取Preferences实例。 - - 读取指定文件,将数据加载到Preferences实例,用于数据操作。 - - ``` C++ - int errCode = E_OK; - Preferences pref = PreferencesHelper::GetPreferences(PREF_TEST_PATH + "test.xml", errCode); // PREF_TEST_PATH须为应用沙箱路径。 - EXPECT_EQ(errCode, E_OK); - ``` - - -3. 存入数据。 - - 使用Preferences put方法保存数据到缓存的实例中。 - - ```C++ - pref->PutString("test", "remove"); - ``` - -4. 读取数据。 - - 使用Preferences get方法读取数据。 - - ``` C++ - std::string ret = pref->GetString("test", "defaultValue"); - EXPECT_EQ(ret, "remove"); - ``` - - -5. 数据持久化。 - - 应用存入数据到Preferences实例后,可以通过flush或者flushSync方法将Preferences实例回写到文件中。 - - ```C++ - int err = pref->FlushSync(); - EXPECT_EQ(ret, E_OK); - ``` - - -6. 订阅数据变化。 - - 应用订阅数据变化需要指定PreferencesObserver作为回调方法。订阅的key的值发生变更后,当执行flush或者flushSync方法时,PreferencesObserver被触发回调。不再需要PreferencesObserver时请注销。 - - 自定义类,实现PreferencesObserver接口: - ``` C++ - class PreferencesObserverCounter : public PreferencesObserver { - public: - virtual ~PreferencesObserverCounter(); - void OnChange(Preferences &preferences, const std::string &key) override; - - std::atomic_int notifyTimes; - static const std::vector NOTIFY_KEYS_VECTOR; - }; - - PreferencesObserverCounter::~PreferencesObserverCounter() {} - - void PreferencesObserverCounter::OnChange(Preferences &preferences, const std::string &key) - { - for (auto it = NOTIFY_KEYS_VECTOR.cbegin(); it != NOTIFY_KEYS_VECTOR.cend(); it++) { - if (key.compare(*it)) { - notifyTimes++; - break; - } - } - } - - const std::vector PreferencesObserverCounter::NOTIFY_KEYS_VECTOR = { PreferencesTest::KEY_TEST_INT_ELEMENT, - PreferencesTest::KEY_TEST_LONG_ELEMENT, PreferencesTest::KEY_TEST_FLOAT_ELEMENT, - PreferencesTest::KEY_TEST_BOOL_ELEMENT, PreferencesTest::KEY_TEST_STRING_ELEMENT }; - ``` - - 订阅数据变化,并触发执行回调方法: - ``` C++ - std::shared_ptr counter = - std::shared_ptr(new PreferencesObserverCounter()); - pref->RegisterObserver(counter); // 注册数据变化的回调。 - - pref->PutString(PreferencesTest::KEY_TEST_STRING_ELEMENT, "test"); - pref->Flush(); // 触发执行counter的onChanged回调方法。 - EXPECT_EQ(static_cast(counter.get())->notifyTimes, 1); - - /* same value */ - pref->PutInt(PreferencesTest::KEY_TEST_INT_ELEMENT, 2); - pref->PutString(PreferencesTest::KEY_TEST_STRING_ELEMENT, "test"); - pref->Flush(); - EXPECT_EQ(static_cast(counter.get())->notifyTimes, 2); - - pref->UnRegisterObserver(counter); // 注销注册数据变化的回调。 - ``` - - -7. 删除指定文件。 - - 从使用PreferencesHelper内存中移除指定文件对应的Preferences单实例,并删除指定文件及其备份文件、损坏文件。删除指定文件时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题。删除后,数据及文件将不可恢复。 - - ``` C++ - pref = nullptr; - int ret = PreferencesHelper::DeletePreferences("/data/test/test"); - EXPECT_EQ(ret, E_OK); - ``` - - diff --git a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-data-storage-overview.md b/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-data-storage-overview.md deleted file mode 100644 index f2694350dc692a31121c34cfa16d035a20d51729..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-data-storage-overview.md +++ /dev/null @@ -1,44 +0,0 @@ ---- -title: subsys-data-storage-overview -permalink: /pages/extra/ee7dd9/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 轻量级数据存储概述 - -轻量级数据存储适用于对Key-Value结构的数据进行存取和持久化操作。应用获取某个轻量级存储对象后,该存储对象中的数据将会被缓存在内存中,以便应用获得更快的数据存取速度。应用也可以将缓存的数据再次写回文本文件中进行持久化存储,由于文件读写将产生不可避免的系统资源开销,建议应用减少对持久化文件的读写频率。 - -## 基本概念 - -- **Key-Value数据结构** - - 一种键值结构数据类型。Key是不重复的关键字,Value是数据值。 - -- **非关系型数据库** - - 区别于关系数据库,不保证遵循ACID(Atomic、Consistency、Isolation及Durability)特性,不采用关系模型来组织数据,数据之间无关系。 - - -## 运作机制 - -1. 应用通过指定Preferences文件将其中的数据加载到Preferences实例,系统会通过静态容器将该实例存储在内存中,同一应用或进程中每个文件仅存在一个Preferences实例,直到应用主动从内存中移除该实例或者删除该Preferences文件。 -2. 应用获取到Preferences文件对应的实例后,可以从Preferences实例中读取数据,或者将数据存入Preferences实例中。通过调用flush或者flushSync方法可以将Preferences实例中的数据回写到文件里。 - -**图 1** 轻量级数据存储运作机制 - - -![](/images/device-dev/subsystems/figure/zh-cn_image_0000001192123772.png) - -## 约束与限制 - -- 因Preferences实例会加载到内存中,建议存储的数据不超过一万条,并及时清理不再使用的实例,以便减少非内存开销。 -- 数据中的key为string类型,要求非空且字符长度不超过80个。 -- 当数据中的value为string类型时,允许为空,字符长度不超过8192个。 - diff --git a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-data-storage.md b/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-data-storage.md deleted file mode 100644 index 5f855ed279d4fa3e6748517339f34b4a95f522ec..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-data-storage.md +++ /dev/null @@ -1,18 +0,0 @@ ---- -title: subsys-data-storage -permalink: /pages/extra/829325/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 轻量级数据存储 - -- **[轻量级数据存储概述](/pages/extra/ee7dd9/)** - -- **[轻量级数据存储开发指导](/pages/extra/69c638/)** diff --git a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-data.md b/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-data.md deleted file mode 100644 index ba977aad86be730011549e9b9370af434754f19e..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-data.md +++ /dev/null @@ -1,19 +0,0 @@ ---- -title: subsys-data -permalink: /pages/extra/c92e1f/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 数据管理 - -- **[关系型数据库](/pages/extra/4b14bb/)** -- **[轻量级数据存储](/pages/extra/829325/)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-dfx-hisysevent-write-config.md b/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-dfx-hisysevent-write-config.md deleted file mode 100644 index 076d3a11b609638d82f809df512017fada1a6f23..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-dfx-hisysevent-write-config.md +++ /dev/null @@ -1,331 +0,0 @@ ---- -title: subsys-dfx-hisysevent-write-config -permalink: /pages/extra/ac6bb3/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# HiSysEvent打点配置指导 - -- [概述](#section315316685115) - - [基本概念](#section123181432175143) - - [约束与限制](#section123181432175114) -- [编写yaml文件](#section123181432175113) - - [yaml文件编写规则](#section123181432175133) - - [yaml文件编写样例](#section123181432175123) -- [验证yaml文件](#section123181432175115) - - [配置yaml文件路径](#section123181432175135) - - [编译yaml文件](#section123181432175137) - - [打点及查询定义的事件](#section123181432175139) - -## 概述 - -组件若有HiSysEvent事件的打点需求,则需要先定义yaml文件并在bundle.js文件中[配置yaml文件的路径](#section123181432175135)。OpenHarmony编译框架在编译过程中则会通过python编译脚本解析校验bundle.js文件指定的所有yaml文件。在解析校验之后,编译框架会将这些yaml文件中配置的信息汇总转换成名为hisysevent.def的json文件。最后,将此json文件打包到系统指定路径下,用作HiSysEvent事件落盘的判断依据。 - -### 基本概念 - -在配置HiSysEvent打点之前,开发者应了解以下基本概念: - -- 事件领域 - 用于标识事件所属的领域,在yaml文件中以domain为键值指定,可参考yaml文件样例中的[domain](#section123181432175123)。 - -- 事件名称 - 用于指定事件领域包含的所有事件,可参考yaml文件样例中的[EVENT_NAMEA/EVENT_NAMEB](#section123181432175123)。 - -- 参数 - 用于定义某个事件名称包含的所有键值,可参考yaml文件样例中的[__BASE/NAME1/NAME2](#section123181432175123)。 - - -### 约束与限制 - -**定义事件领域、事件名称及参数的约束与限制:** - -- 每个yaml文件只能有一个事件领域,且不能与其他yaml文件中定义的事件领域重名。 - -- 每个事件领域可定义零个或多个事件名称,同一个事件领域内部的事件名称不能重名。 - -- 每个事件名称可定义多个参数,同一个事件名称内部的参数不能重名,每个事件名称**有且只有**一个名称为__BASE的参数,此参数字段组成如表1,他自定义参数,具体字段组成如表2。 - - **表 1** __BASE参数字段说明 - - - - - - - - - - - - - - - - - - - - - - - -

字段名称

-

描述

-
-

type

-
-

字段说明:
  必选字段,用来标识该事件名称的类型。

-

取值范围:

- -
    -
  • FAULT:错误类型。
  • -
  • STATISTIC:统计类型。
  • -
  • SECURITY:安全性。
  • -
  • BEHAVIOR:用户行为。
  • -
-
-

level

-
-

字段作用:
  必选字段,用来标识该事件名称的级别。

-

取值范围:

- -
    -
  • CRITICAL:严重。
  • -
  • MINOR:一般。
  • -
-
-

tag

-
-

字段作用:
  可选字段,用来标识该事件名称的标签。

-

定义规则:

- -
    -
  • 最多可同时定义5个标签,标签之间使用空格来分隔。
  • -
  • 单个标签最多包含16个字符,字符范围[a-zA-Z0-9]。
  • -
-
-

desc

-
-

字段作用:
  必选字段,用来对该事件名称进行描述。

-

定义规则:

- -
    -
  • 至少包含3个字符,最多包含128个字符,字符范围[a-zA-Z0-9 _]
  • -
-
- - **表 2** 自定义参数字段说明 - - - - - - - - - - - - - - - - - - - -

字段名称

-

描述

-
-

type

-
-

字段说明:
  必选字段,用来标识该参数的类型。

-

取值范围:

- -
    -
  • BOOL
  • -
  • INT8
  • -
  • UINT8
  • -
  • INT16
  • -
  • UINT16
  • -
  • INT32
  • -
  • UINT32
  • -
  • INT64
  • -
  • UINT64
  • -
  • FLOAT
  • -
  • DOUBLE
  • -
  • STRING
  • -
-
-

arrsize

-
-

字段作用:
  可选字段,用来标识数组类型参数的长度。

-

取值范围:
   1~100

- -
-

desc

-
-

字段作用:
  必选字段,用来对该参数进行描述。

-

定义规则:

- -
    -
  • 至少包含3个字符,最多包含128个字符,字符范围[a-zA-Z0-9 _]
  • -
-
- -## 编写yaml文件 - -### yaml文件编写规则 - -- 事件领域命名规则: - - 字母开头,且只能由大写字母/数字/下划线组成; - - 字符串长度取值范围为1~16。 -- 事件名称命名规则: - - 字母开头,且只能由大写字母/数字/下划线组成; - - 字符串长度取值范围1~32; - - 单个事件领域内部事件名称的不能超过4096个。 -- 参数命名规则: - - 字母开头,且只能由大写字母/数字/下划线组成; - - 字符串长度取值范围1~32; - - 单个事件名称内包含的参数的个数不能超过128个。 - -### yaml文件编写样例 - -- yaml文件样例指定的事件领域名称为MODULEA,该事件领域包含两个事件,名称分别是EVENT_NAMEA和EVENT_NAMEB。 -- EVENT_NAMEA被定义成错误类型的严重事件,该事件包含类型为字符串类型的NAME1参数、字符串类型的NAME2参数及无符号短整型类型的NAME3参数,可以通过事件领域MODULEA和事件名称EVENT_NAMEA对其进行[实时订阅](/pages/0105100602)。 -- EVENT_NAMEB被定义成统计类型的一般事件,EVENT_NAMEB包含类型为无符号短整型类型的NAME1参数及整型类型的NAME2参数。因为EVENT_NAMEB在__BASE参数中定义了名称为tag1和tag2的两个事件标签,所以不仅可以通过事件领域MODULEA和事件名称EVENT_NAMEB对其进行[实时订阅](/pages/0105100602),,所以还可以通过事件标签对该事件进行[实时订阅](/pages/0105100602)。 - - ``` - ########################################## - # the hisysevent definition for module a # - ########################################## - - domain: MODULEA - - EVENT_NAMEA: - __BASE: {type: FAULT, level: CRITICAL, desc: event name a} - NAME1: {type: STRING, desc: name1} - NAME2: {type: STRING, desc: name2} - NAME3: {type: UINT16, desc: name3} - - EVENT_NAMEB: - __BASE: {type: STATISTIC, level: MINOR, tag: tag1 tag2, desc: event name b} - NAME1: {type: UINT16, desc: name1} - NAME2: {type: INT32, desc: name2} - ``` - -## 验证yaml文件 - -### 配置yaml文件路径 - -在bundle.js文件中通过```hisysevent_config```属性完成yaml文件的路径指定: - -``` -{ - "name": "@ohos/moduel_a", - "description": "module a", - "version": "3.1", - "license": "Apache License 2.0", - "publishAs": "code-segment", - "segment": { - "destPath": "moduel_a_path" - }, - "dirs": {}, - "scripts": {}, - "component": { - "name": "hisysevent_native", - "subsystem": "hiviewdfx", - "adapted_system_type": [ - "standard" - ], - "rom": "", - "ram": "", - "hisysevent_config": [ - "//moduel_a_path/yaml_file1.yaml", - "//moduel_a_path/yaml_file2.yaml" - ], - "deps": { - "components": [ - "hilog_native", - "hitrace_native", - "ipc", - "safwk", - "samgr_standard", - "utils_base" - ], - "third_party": [] - }, - "build": { - } - } -} -``` - ->![](/images/device-dev/public_sys-resources/icon-note.gif) **说明:** ->yaml文件可根据实际需求置于组件工程的任意目录下,只要在bundle.js文件指定即可。 - -### 编译yaml文件 - -- 全量编译: - - - 全量编译整个系统,会将所有组件配置的yaml文件中的配置进行汇总,正常完成系统编译后,指定目录下就会生成hisysevent.def文件。 - - ``` - cd 工程根目录的绝对路径 - ./build --product-name - ``` - - - 全量编译生成的hisysevent.def文件可以通过以下命令获取: - - ``` - cd 工程根目录的绝对路径 - find out -name hisysevent.def -type f - ``` - -- 单文件编译: - - 也可以只编译单个组件的yaml文件,命令如下: - - ``` - cd 工程根目录的绝对路径 - ./build/ohos/hisysevent/gen_def_from_all_yaml.py --yaml-list --def-path - ``` - - **表 3** 单文件编译参数说明 - - - - - - - - - - - - - -

选项名称

-

描述

-
-

--yaml-list

-
-

指定需要编译的yaml文件路径列表,多个yaml文件路径之间用空格分隔。

-
-

--def-path

-
-

指定编译生成的hisysevent.def文件的生成路径。

-
- -### 打点及查询定义的事件 - -1. 通过[hdc_std工具](/pages/01090202)将hisysevent.def文件推送到至设备的//system/etc/hiview/目录下; - -2. 触发yaml文件自定义的HiSysEvent事件完成打点,通过[hisysevent -l](/pages/0105100604)命令查询历史HiSysEvent事件,确认触发的自定义HiSysEvent事件是否打点成功。 diff --git a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-dfx.md b/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-dfx.md deleted file mode 100644 index 7ad7e4cbfcb0fa9883835697afa5d6d87118fd40..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-dfx.md +++ /dev/null @@ -1,32 +0,0 @@ ---- -title: subsys-dfx -permalink: /pages/extra/684ab8/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# DFX - -- **[DFX概述](/pages/01051001)** - -- **[HiLog开发指导](/pages/01051002)** - -- **[HiLog\_Lite开发指导](/pages/01051003)** - -- **[HiSysEvent开发指导](/pages/01050f04)** - - - [HiSysEvent打点指导](/pages/0105100601) - - - [HiSysEvent订阅指导](/pages/0105100602) - - - [HiSysEvent查询指导](/pages/0105100603) - - - [HiSysEvent工具使用指导](/pages/0105100604) - - diff --git a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-graphics.md b/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-graphics.md deleted file mode 100644 index 009d4bd0e02b728aa538b4543ee639a54d21c825..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-graphics.md +++ /dev/null @@ -1,26 +0,0 @@ ---- -title: subsys-graphics -permalink: /pages/extra/7fcbf2/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 图形图像 - -- **[图形图像概述](/pages/01050501)** - -- **[容器类组件开发指导](/pages/01050502)** - -- **[布局容器类组件开发指导](/pages/01050503)** - -- **[普通组件开发指导](/pages/01050504)** - -- **[动画开发指导](/pages/01050505)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-multimedia-camera.md b/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-multimedia-camera.md deleted file mode 100644 index 6a667c015ad9209dae2a233781780645aa0bbf8b..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-multimedia-camera.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -title: subsys-multimedia-camera -permalink: /pages/extra/ad4327/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 相机 - -- **[相机开发概述](/pages/0105060101)** - -- **[拍照开发指导](/pages/0105060102)** - -- **[录像开发指导](/pages/0105060103)** - -- **[预览开发指导](/pages/0105060104)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-multimedia-video.md b/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-multimedia-video.md deleted file mode 100644 index f74e43d6851ba95e9c631211f2926444f8907ced..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-multimedia-video.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: subsys-multimedia-video -permalink: /pages/extra/f106bb/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 音视频 - -- **[音视频开发概述](/pages/0105060201)** - -- **[音视频播放开发指导](/pages/0105060202)** - -- **[音视频录制开发指导](/pages/0105060203)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-multimedia.md b/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-multimedia.md deleted file mode 100644 index ca6d094dfd4a01554b43cea46a770a554914339e..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-multimedia.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: subsys-multimedia -permalink: /pages/extra/c169e0/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 媒体 - -- **[相机](/pages/extra/ad4327/)** - -- **[音视频](/pages/extra/f106bb/)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-security.md b/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-security.md deleted file mode 100644 index 4dfca10f52449c66ca486f99678f9ec0e29c558b..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-security.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -title: subsys-security -permalink: /pages/extra/2dd473/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 安全 - -- **[概述](/pages/01050d01)** - -- **[应用验签开发指导](/pages/01050d02)** - -- **[应用权限管理开发指导](/pages/01050d03)** - -- **[IPC通信鉴权开发指导](/pages/01050d04)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-sensor.md b/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-sensor.md deleted file mode 100644 index 01d75b268a8aa77789048ca574fdad6d0c9b0d1c..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-sensor.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: subsys-sensor -permalink: /pages/extra/fdd664/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# Sensor服务 - -- **[Sensor服务子系概述](/pages/01050901)** - -- **[Sensor服务子系使用指导](/pages/01050902)** - -- **[Sensor服务子系使用实例](/pages/01050903)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-tel.md b/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-tel.md deleted file mode 100644 index 8d2a6a08997db33a4d3881cc055ee2b004eb4664..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-tel.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: subsys-tel -permalink: /pages/extra/019068/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 电话服务 - -- **[电话服务概述](/pages/01050c01)** - -- **[电话服务开发指导](/pages/01050c02)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-testguide-envbuild.md b/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-testguide-envbuild.md deleted file mode 100644 index 5b6ddd1c7d6a21a813cb33388c9a55372ee34bc7..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-testguide-envbuild.md +++ /dev/null @@ -1,96 +0,0 @@ ---- -title: subsys-testguide-envbuild -permalink: /pages/extra/9079c0/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- - - -# 环境配置 -## 测试框架基础环境依赖 - -|环境依赖|操作系统|Linux系统扩展组件|python|python插件|NFS Server|HDC| -|------------|------------|------------|------------|------------|------------|------------| -|版本型号|Ubuntu18.04及以上|libreadline-dev|3.7.5版本及以上|pyserial 3.3及以上、paramiko2.7.1及以上、setuptools40.8.0及以上、rsa4.0及以上|haneWIN NFS Server 1.2.50及以上或者 NFS v4及以上| 1.1.0版本及以上 | -|详细说明|代码编译环境|命令行读取插件|测试框架语言 |pyserial:支持python的串口通信;paramiko:支持python使用SSH协议;setuptools:支持python方便创建和分发python包;rsa:支持python rsa加密 |支持设备通过串口连接| 支持设备通过HDC连接 | - -## 安装流程 -1. 安装Linux扩展组件readline,安装命令如下: - ``` - sudo apt-get install libreadline-dev - ``` - 安装成功提示如下: - ``` - Reading package lists... Done - Building dependency tree - Reading state information... Done - libreadline-dev is already the newest version (7.0-3). - 0 upgraded, 0 newly installed, 0 to remove and 11 not upgraded. - ``` -2. 安装setuptools插件,安装命令如下: - ``` - pip3 install setuptools - ``` - 安装成功提示如下: - ``` - Requirement already satisfied: setuptools in d:\programs\python37\lib\site-packages (41.2.0) - ``` -3. 安装paramiko插件,安装命令如下: - ``` - pip3 install paramiko - ``` - 安装成功提示如下: - ``` - Installing collected packages: pycparser, cffi, pynacl, bcrypt, cryptography, paramiko - Successfully installed bcrypt-3.2.0 cffi-1.14.4 cryptography-3.3.1 paramiko-2.7.2 pycparser-2.20 pynacl-1.4.0 - ``` -4. 安装python的rsa插件,安装命令如下: - ``` - pip3 install rsa - ``` - 安装成功提示如下: - ``` - Installing collected packages: pyasn1, rsa - Successfully installed pyasn1-0.4.8 rsa-4.7 - ``` -5. 安装串口插件pyserial,安装命令如下: - ``` - pip3 install pyserial - ``` - 安装成功提示如下: - ``` - Requirement already satisfied: pyserial in d:\programs\python37\lib\site-packages\pyserial-3.4-py3.7.egg (3.4) - ``` -6. 如果设备仅支持串口输出测试结果,则需要安装NFS Server - - Windows环境下安装,例如安装haneWIN NFS Server1.2.50。 - - Linux环境下安装,安装命令如下: - ``` - sudo apt install nfs-kernel-server - ``` - 安装成功提示如下: - ``` - Reading package lists... Done - Building dependency tree - Reading state information... Done - nfs-kernel-server is already the newest version (1:1.3.4-2.1ubuntu5.3). - 0 upgraded, 0 newly installed, 0 to remove and 11 not upgraded. - ``` -7. 如果设备支持HDC连接,则需要安装HDC工具,安装流程请参考如下链接 - - https://gitee.com/openharmony/developtools_hdc_standard/blob/master/README_zh.md - -## 安装环境检查 - -| 检查项 |操作 |满足环境 | -| --- | --- | --- | -| 检查python安装成功 |命令行窗口执行命令:python --version |版本不小于3.7.5即可 | -| 检查python扩展插件安装成功 |打开test/developertest目录,执行start.bat或start.sh| 可进入提示符“>>>”界面即可 | -|检查NFS Server启动状态(被测设备仅支持串口时检测) |通过串口登录开发板,执行mount命令挂载NFS |可正常挂载文件目录即可 | -|检查HDC安装成功 |命令行窗口执行命令:hdc_std -v |版本不小于1.1.0即可 | diff --git a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-toolchain-hiperf.md b/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-toolchain-hiperf.md deleted file mode 100644 index b23b7eb548fc9c7695cee7912f75c12b80fb51f4..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-toolchain-hiperf.md +++ /dev/null @@ -1,282 +0,0 @@ ---- -title: subsys-toolchain-hiperf -permalink: /pages/extra/715dd9/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# hiperf 使用指南 - -- [list 命令](#list-命令) - - [参数说明](#参数说明) - - [使用示例](#使用示例) -- [stat 命令](#stat-命令) - - [参数说明](#参数说明) - - [使用示例](#使用示例) - - [字段说明](#字段说明) -- [record 命令](#record-命令) - - [参数说明](#参数说明) - - [使用示例](#使用示例) -- [report 命令](#report-命令) -- [使用示例](#使用示例) - -hiperf是为开发人员提供性能采样分析的工具,基于内核perf机制进行的用户态能力的扩展,可以对指定的程序或者整个系统进行性能采样。 - - -hiperf支持的命令有:list、stat、record、report等,可以通过hiperf -h进行查看。 - - -下面对hiperf的常用命令进行详细说明: - - -## list 命令 - - -### 参数说明 - -列出设备上支持的所有perf事件名称,事件名称用于 stat 和 record命令的 -e 和 -g 参数。 - -``` -Usage: hiperf list [event type] -``` - -| 参数 | 功能说明 | -| -------- | -------- | -| hw | 列出支持的 hardware 事件(PMU支持) | -| sw | 列出支持的 software 事件 | -| tp | 列出支持 tracepotint 事件 | -| cache | 列出支持的 cache 事件(PMU支持) | -| raw | 列出支持的原始PMU事件 | - - -### 使用示例 - -下面列出了设备支持的 HW 事件,并且会提示哪些事件此设备不支持。 - -``` -hiperf list hw -event not support hw-stalled-cycles-backend -event not support hw-stalled-cycles-frontend -event not support hw-ref-cpu-cycles - -Supported events for hardware: - hw-cpu-cycles - hw-instructions - hw-cache-references - hw-cache-misses - hw-branch-instructions - hw-branch-misses - hw-bus-cycles -``` - - -## stat 命令 - - -### 参数说明 - -监听指定目标程序,周期性打印性能计数器的值。 -``` -Usage: hiperf stat [options] - Collect performance counter information. -``` - - -| 参数 | 功能说明 | -| -------- | -------- | -| -a | 采集监听整个系统的所有线程和默认的性能计数器的值。 | -| -c | 指定cpu id,可以是0,1,2用逗号分隔。 | -| -d <_sec_> | 指定监听的时间,单位为秒。 | -| -i <_ms_> | 指定监听事件的间隔打印时间,单位毫秒。 | -| -e | 指定监听的事件,可以通过list命令查看支持的所有事件,其中event:u 或者 :k 表示限制事件为用户空间或者内核空间。 | -| -g | 指定需要在同一组监听的事件,同一组事件会被放入同一个PMU监听。 | -| --no-inherit | 不监听目标线程/进程启动的子线程。 | -| -p | 指定需要监听的进程pid。 | -| -t | 指定需要监听的线程tid。 | -| --verbose | 显示详细的报告内容,包括一些原始的时间数据等等。 | - - -### 使用示例 - -下面是通过 stat 监听整个系统3秒的示例: - -``` -hiperf stat -d 3 -a -this is root mode, perfEventParanoid assume as -1 -Start Profiling... -Timeout exit (total 3009 ms) - count name | comment | coverage - 132523 hw-branch-instructions | 15.750 M/sec | (100%) - 62554 hw-branch-misses | 47.202372% miss rate | (100%) - 6994768 hw-cpu-cycles | 0.832068 GHz | (100%) - 1237627 hw-instructions | 5.651758 cycles per instruction | (100%) - 248 sw-context-switches | 29.959 K/sec | (100%) - 0 sw-page-faults | 0.000 /sec | (100%) - 9402580 sw-task-clock | 0.002758 cpus used | (100%) -``` - - -### 字段说明 - -| 字段名 | 含义 | -| -------- | -------- | -| count | 表示事件发生的次数 | -| name | 事件的名称,在 list 命令中可以看到所有支持的命令,hw 和 sw 的前缀分别代表是hardware事件还是software事件。 | -| comment | 一些经过计算的方便用户阅读的值。例如 CPU 的相对主频,千位进制换算等等。 | -| coverage | 该事件在PMU中的 enable 百分比,受限于PMU数量,每次装载的PMU监听事件是有限的。 | - - -## record 命令 - - -### 参数说明 - -采样指定目标程序,并且将采样数据保存到指定的文件中(默认为perf.data) - -``` -Usage: hiperf record [options] - Collect performance sampling information. -``` - -| 参数 | 功能说明 | -| -------- | -------- | -| -a | 对整个系统的所有进程和线程进行采样。 | -| --exclude-hiperf | 不采样hiperf自身进程。 | -| -c | 指定采样的cpu id。 | -| --cpu-limit <_percent_> | 限定采样过程占用的CPU最大百分比。 | -| -d <sec> | 指定采样时长,单位秒。 | -| -f <freq> | 设置采样事件的触发频率,默认为4000。
说明:该频率越高cpu负载会越高,但是数据采样会越多。 | -| --period <_num_> | 设置采样事件触发周期,以次数为单位,即发生指定的次数后采样一次。 | -| -e | 指定监听的事件,可以通过list命令查看支持的所有事件,其中event:u 或者 :k 可以表示限制事件为用户空间或者内核空间。 | -| -g | 指定需要在同一组监听的事件,同一组事件会被放入同一个PMU监听。 | -| --no-inherit | 不监听目标线程或者进程启动的子线程。 | -| -p | 指定需要监听的进程。 | -| -t | 指定需要监听的线程。 | -| --offcpu | 监听cpu调度事件,它等价于 --period 1 -e sched:sched_switch 事件。 | -| -j <_branch_filter1_>[,_branch_filter2_]... | 监听分支预测事件。分支预测就是指令存在多个if else判定的情况下,cpu去预测下一步即将执行哪一条指令。 | -| -s / --call-stack <_fp \\| dwarf[,size]_> | 设置用户栈的回栈方式,支持fp和dwarf两种方式。dwarf 后面可以指定采样的用户堆栈大小,默认是 65528。 | -| --delay-unwind | 延迟回栈,等到采样结束再进行回栈。 | -| --disable-unwind | 不进行回栈,用户的寄存器和堆栈数据会保存在perf.data中,供离线回栈使用。 | -| --disable-callstack-expend | 默认会对回栈的调用栈信息进行合并扩展,此选项会关闭该功能。 | -| --clockid <_clock type_> | 设置采样数据的时钟源,支持monotonic、boottime、realtime等。 | -| --symbol-dir <_dir_> | 指定符号表路径,如果指定了回栈时会优先使用该路径下的符号表。 | -| -m <_mmap pages_> | 指定缓存的大小,默认值为1024,以页为单位。参数需要为2的幂,范围为 [2 - 1024]。
说明:该值越高,事件丢失率会越低,但是内存占用会增大。 | -| --app <_package name_> | 指定采样的目标应用的包名,默认超时等待时间为10秒。 | -| --data-limit <_SIZE[K\|M|G]_> | 指定采样结果的最大容量,支持K/M/G(B)为单位,默认无大小限制。 | -| -o <_output file name_> | 指定采样数据结果文件名,默认为/data/local/tmp/perf.data。 | -| -z | 启动压缩模式,在保存到文件的时候,会用gzip进行压缩。 | -| --verbose | 采样的时候显示更详细的日志信息。 | - - -### 使用示例 - -- 对全系统所有进程采样3秒,并且显示详细的日志信息 - ``` - hiperf record -d 3 -a --verbose - ``` - -- 指定使用fp方式进行回栈 - ``` - hiperf record -s fp -d 3 -a - ``` - -- 指定使用dwarf方式进行回栈 - ``` - hiperf record -s dwarf -d 3 -a - ``` - -- 指定采样offcpu事件 - ``` - hiperf record --offcpu -s dwarf -d 3 -a - ``` - -- 指定延迟回栈 - ``` - hiperf record -d 3 -s dwarf --delay-unwind -a - ``` - -- 禁止回栈,此时会保存堆栈数据到perf.data文件 - ``` - hiperf record -d 3 -s dwarf --disable-unwind -a - ``` - -- 指定追踪的包名,如果指定的包名对应的进程不存在则会延时等待10秒,超时后进程退出 - ``` - hiperf record -d 3 -s dwarf --app com.ohos.launch - ``` - -- 指定对采样结果数据进行压缩保存 - ``` - hiperf record -z -s dwarf -d 3 -a - ``` - - -## report 命令 - -此命令主要用于展示record中抓取的采样数据 - -``` -Usage: hiperf report [option] - Report sampling information from perf.data. -``` - -| 参数 | 功能说明 | -| -------- | -------- | -| --symbol-dir <_dir_> | 指定符号表路径。 | -| --limit-percent <_number_> | 指定展示结果的最低百分比(低于的不显示)。 | -| -s / --call-stack | 指定该选项后结果数据中会包含详细的调用栈信息。 | -| --call-stack-limit-percent <_number_> | 调用栈的百分比最小值(低于的不显示)。 | -| --proto | 将输入的 perf.data 文件转换为 proto 格式,默认文件名为 perf.proto。 | -| --json | 将输入的 perf.data 文件转换为 json 格式,默认文件名为 perf.json。 | -| --branch | 按分支预测的结果地址来展示报告,而不是调用栈的IP地址。 | -| --<_keys_> <_keyname1_>[,_keyname2_][,...] | 按给出的关键字来过滤展示报告,keys支持:comms、pids、tids等 例如 --comms hiperf,hilog 表示仅显示进程/线程名称为 hiperf或者hilog的记录条目。 | -| --sort <_key1_>[,_key2_][,...] | 按照给出的关键字来排序和显示,支持:pid、tid、comm等,可以指定多个关键字。 | -| -i <_filename_> | 指定输入的采样数据(默认为perf.data)。 | -| -o <_filename_> | 指定输出的报告文件名。 | - - -## 使用示例 - -- 输出采样数据的报告,默认读取perf.data文件 - ``` - hiperf report - ``` - - 输出结果举例: - - ``` - Heating count comm pid tid dso func - 5.68% 15073949 hiperf_example_ 1085 1091 /system/lib/ld-musl-arm.so.1 malloc - 2.57% 6834119 hiperf_example_ 1085 1091 [kernel.kallsyms] vector_swi - 2.27% 6013910 hiperf_example_ 1085 1087 /system/lib/ld-musl-arm.so.1 malloc - 2.19% 5805738 hiperf_example_ 1085 1091 /system/lib/ld-musl-arm.so.1 vfprintf - 2.09% 5543362 hiperf_example_ 1085 1091 [kernel.kallsyms] ktime_get_ts64 - report done - ``` - -- 输出采集数据的调用栈报告 - ``` - hiperf report -s - ``` - -- 指定符号表路径 - ``` - hiperf report -s --symbol-dir /data/local/tmp - ``` - -- 指定结果过滤的关键字,指定后会只显示包含该关键字的信息。比如过滤libutils.z.so则命令如下: - ``` - hiperf report --dsos libuitls.z.so - ``` - -- 指定按照特定的关键字进行排序展示,比如按照dso进行排序: - ``` - hiperf report --sort dso - ``` - diff --git a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-toolchain.md b/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-toolchain.md deleted file mode 100644 index 37f76b618851dad3f3ff4a08a1a279290d245679..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-toolchain.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: subsys-toolchain -permalink: /pages/extra/5138cc/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 研发工具链 - -- **[bytrace使用指导](/pages/01090201)** - -- **[hdc\_std 使用指导](/pages/01090202)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-usbservice-demo.md b/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-usbservice-demo.md deleted file mode 100644 index d1b8cec1bb7d4a361b3e0ae2ecbcec5443fe4e4e..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-usbservice-demo.md +++ /dev/null @@ -1,200 +0,0 @@ ---- -title: subsys-usbservice-demo -permalink: /pages/extra/9ce8da/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# USB服务子系使用实例 - - -``` -#include -#include -#include -#include -#include -#include -#include "if_system_ability_manager.h" -#include "ipc_skeleton.h" -#include "iremote_object.h" -#include "iservice_registry.h" -#include "iusb_srv.h" -#include "string_ex.h" -#include "system_ability_definition.h" -#include "usb_common.h" -#include "usb_device.h" -#include "usb_errors.h" -#include "usb_request.h" -#include "usb_server_proxy.h" -#include "usb_srv_client.h" - -const int32_t REQUESTYPE = ((1 << 7) | (0 << 5) | (0 & 0x1f)); -const int32_t REQUESTCMD = 6; -const int32_t VALUE = (2 << 8) + 0; -const int32_t TIMEOUT = 5000; -const int32_t ITFCLASS = 10; -const int32_t PRAMATYPE = 2; -const int32_t BUFFERLENGTH = 21; - -void GetType(OHOS::USB::USBEndpoint &tep, OHOS::USB::USBEndpoint &outEp, bool &outEpFlg) -{ - if ((tep.GetType() == PRAMATYPE)) { - if (tep.GetDirection() == 0) { - outEp = tep; - outEpFlg = true; - } - } -} - -bool SelectEndpoint(OHOS::USB::USBConfig config, - std::vector interfaces, - OHOS::USB::UsbInterface &interface, - OHOS::USB::USBEndpoint &outEp, - bool &outEpFlg) -{ - for (int32_t i = 0; i < config.GetInterfaceCount(); ++i) { - OHOS::USB::UsbInterface tif = interfaces[i]; - std::vector mEndpoints = tif.GetEndpoints(); - for (int32_t j = 0; j < tif.GetEndpointCount(); ++j) { - OHOS::USB::USBEndpoint tep = mEndpoints[j]; - if ((tif.GetClass() == ITFCLASS) && (tif.GetSubClass() == 0) && (tif.GetProtocol() == PRAMATYPE)) { - GetType(tep, outEp, outEpFlg); - } - } - if (outEpFlg) { - interface = interfaces[i]; - return true; - } - std::cout << std::endl; - } - return false; -} - -int OpenDeviceTest(OHOS::USB::UsbSrvClient &Instran, OHOS::USB::UsbDevice device, OHOS::USB::USBDevicePipe &pip) -{ - int ret = Instran.RequestRight(device.GetName()); - std::cout << "device RequestRight ret = " << ret << std::endl; - if (0 != ret) { - std::cout << "device RequestRight failed = " << ret << std::endl; - } - ret = Instran.OpenDevice(device, pip); - return ret; -} - -int CtrTransferTest(OHOS::USB::UsbSrvClient &Instran, OHOS::USB::USBDevicePipe &pip) -{ - std::cout << "usb_device_test : << Control Transfer >> " << std::endl; - std::vector vData; - const OHOS::USB::UsbCtrlTransfer tctrl = {REQUESTYPE, REQUESTCMD, VALUE, 0, TIMEOUT}; - int ret = Instran.ControlTransfer(pip, tctrl, vData); - if (ret != 0) { - std::cout << "control message read failed width ret = " << ret << std::endl; - } else { - } - std::cout << "control message read success" << std::endl; - - return ret; -} - -int ClaimTest(OHOS::USB::UsbSrvClient &Instran, - OHOS::USB::USBDevicePipe &pip, - OHOS::USB::UsbInterface &interface, - bool interfaceFlg) -{ - if (interfaceFlg) { - std::cout << "ClaimInterface InterfaceInfo:" << interface.ToString() << std::endl; - int ret = Instran.ClaimInterface(pip, interface, true); - if (ret != 0) { - std::cout << "ClaimInterface failed width ret = " << ret << std::endl; - } else { - std::cout << "ClaimInterface success" << std::endl; - } - } - return 0; -} - -int BulkTransferTest(OHOS::USB::UsbSrvClient &Instran, - OHOS::USB::USBDevicePipe &pip, - OHOS::USB::USBEndpoint &outEp, - bool interfaceFlg, - bool outEpFlg) -{ - if (interfaceFlg) { - std::cout << "usb_device_test : << Bulk transfer start >> " << std::endl; - if (outEpFlg) { - uint8_t buffer[50] = "hello world 123456789"; - std::vector vData(buffer, buffer + BUFFERLENGTH); - int ret = Instran.BulkTransfer(pip, outEp, vData, TIMEOUT); - if (ret != 0) { - std::cout << "Bulk transfer write failed width ret = " << ret << std::endl; - } else { - std::cout << "Bulk transfer write success" << std::endl; - } - return ret; - } - } - return 0; -} - -int main(int argc, char **argv) -{ - std::cout << "usb_device_test " << std::endl; - static OHOS::USB::UsbSrvClient &Instran = OHOS::USB::UsbSrvClient::GetInstance(); - // GetDevices - std::vector deviceList; - int32_t ret = Instran.GetDevices(deviceList); - if (ret != 0) { - return OHOS::USB::UEC_SERVICE_INVALID_VALUE; - } - if (deviceList.empty()) { - return OHOS::USB::UEC_SERVICE_INVALID_VALUE; - } - - OHOS::USB::UsbDevice device = deviceList[0]; - std::vector configs = device.GetConfigs(); - OHOS::USB::USBConfig config = configs[0]; - std::vector interfaces = config.GetInterfaces(); - OHOS::USB::UsbInterface interface; - OHOS::USB::USBEndpoint outEp; - bool interfaceFlg = false; - bool outEpFlg = false; - interfaceFlg = SelectEndpoint(config, interfaces, interface, outEp, outEpFlg); - - // OpenDevice - std::cout << "usb_device_test : << OpenDevice >> test begin -> " << std::endl; - OHOS::USB::USBDevicePipe pip; - ret = OpenDeviceTest(Instran, device, pip); - if (ret != 0) { - return OHOS::USB::UEC_SERVICE_INVALID_VALUE; - } - - // ControlTransfer - CtrTransferTest(Instran, pip); - - // ClaimInterface - ClaimTest(Instran, pip, interface, interfaceFlg); - - // BulkTransferWrite - BulkTransferTest(Instran, pip, outEp, interfaceFlg, outEpFlg); - - // CloseDevice - std::cout << "usb_device_test : << Close Device >> " << std::endl; - ret = Instran.Close(pip); - if (ret == 0) { - std::cout << "Close device failed width ret = " << ret << std::endl; - return OHOS::USB::UEC_SERVICE_INVALID_VALUE; - } else { - std::cout << "Close Device success" << std::endl; - } - return 0; -} -``` - - diff --git a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-usbservice-guide.md b/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-usbservice-guide.md deleted file mode 100644 index f47778d55c6f1edabc79cde2e80c71ca74023b49..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-usbservice-guide.md +++ /dev/null @@ -1,66 +0,0 @@ ---- -title: subsys-usbservice-guide -permalink: /pages/extra/d1dd5e/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# USB服务子系统使用指导 - -- [使用步骤](#section18816105182315) - -下面使用步骤以bulktransfer为例。 - -## 使用步骤 - -1. 获取usb service实例 - -``` -static OHOS::USB::UsbSrvClient &g_usbClient = OHOS::USB::UsbSrvClient::GetInstance(); -``` - -2. 获取usb设备列表 - -``` -std::vector deviceList; -int32_t ret = g_usbClient.GetDevices(deviceList); -``` - -3. 申请设备权限 - -``` -int32_t ret = g_usbClient.RequestRight(device.GetName()); -``` - -4. 打开设备 - -``` -USBDevicePipe pip; -int32_t et = g_usbClient.OpenDevice(device, pip); -``` - -5. 配置设备接口 - -``` -ret = g_usbClient.ClaimInterface(pip, interface, true); -interface为deviceList中device的interface。 -``` - -6. 数据传输 - -``` -srvClient.BulkTransfer(pipe, endpoint, vdata, timeout); -``` -pipe为打开设备后的数据传输通道,endpoint为device中数据传输的端点,vdata是需要传输或读取的二进制数据块,timeout为传输超时时长. - -7. 关闭设备 - -``` -ret = g_usbClient.Close(pip); -``` diff --git a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-usbservice-overview.md b/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-usbservice-overview.md deleted file mode 100644 index a11030e4ed750b31ccc2e01d960c002934193f36..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-usbservice-overview.md +++ /dev/null @@ -1,234 +0,0 @@ ---- -title: subsys-usbservice-overview -permalink: /pages/extra/67dcae/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# USB服务子系统概述 - -- [概述](#section175431838101617) -- [接口说明](#section83365421647) - - [Host部分](#section83365421658) - - [Device部分](#section83365421669) - - [Port部分](#section83365421670) - -## 概述 - - USB设备分为Host设备(主机设备)和Device设备(从设备)。用户可通过Port Service来根据实际业务把运行OpenHarmony的设备切换为Host设备或者Device设备。目前在Host模式下,支持获取USB设备列表,USB设备权限管理,控制传输、批量传输的同异步数据传输等,在Device模式下,支持HDC(调试)、ACM(串口)、ECM(网口)等功能的切换。 - -**图1** USB服务架构图 - -![](/images/device-dev/subsystems/figure/USB服务架构图.png) - -- USB FWK/API:基于USB Service服务,使用NAPI技术,向上提供JS接口。 -- USB Service:使用C++代码实现,包含Host、Device、Port三个模块。基于HDI的接口,主要实现USB设备的列表管理、Function 管理、Port管理、USB设备权限管理等功能。 -- USB HAL:使用C代码实现,基于Host SDK和Device SDK,封装了对USB设备的基本操作,向上提供C++接口,同时通过HDF框架接收内核上报的信息。 - -## 接口说明 - -- ### Host部分 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

头文件

-

接口名称

-

功能描述

-

usb_srv_client.h

-

-

-

int32_t OpenDevice(const UsbDevice &device, USBDevicePipe &pip);

-

打开USB设备,建立连接

-

int32_t HasRight(std::string deviceName);

-

判断是否有权访问设备

-

int32_t RequestRight(std::string deviceName);

-

请求给定软件包的临时权限以访问设备

-

int32_t GetDevices(std::vector &deviceList);

-

获取USB设备列表

-

int32_t ClaimInterface(USBDevicePipe &pip, const UsbInterface &interface, bool force);

-

打开接口,并申明独占接口,必须在数据传输前执行

-

int32_t ReleaseInterface(USBDevicePipe &pip, const UsbInterface &interface);

-

关闭接口,释放接口的占用,在停止数据传输后执行

-

int32_t BulkTransfer(USBDevicePipe &pip, const USBEndpoint &endpoint, std::vector &vdata, int32_t timeout);

-

在给定端点上执行批量数据传输, 返回读取或发送的数据长度,通过端点方向确定读取或发送数据

-

int32_t ControlTransfer(USBDevicePipe &pip, const UsbCtrlTransfer &ctrl, std::vector &vdata);

-

对此设备执行端点零的控制事务,传输方向由请求类型决定

-

int32_t SetConfiguration(USBDevicePipe &pip, const USBConfig &config);

-

设置设备当前使用的配置,通过配置值进行指定

-

int32_t SetInterface(USBDevicePipe &pipe, const UsbInterface &interface);

-

设置指定接口的备选设置,用于在具有相同ID但不同备用设置的两个接口之间进行选择

-

int32_t GetRawDescriptors(std::vector &vdata);

-

获取原始的USB描述符

-

int32_t GetFileDescriptor();

-

获取文件描述符

-

bool Close(const USBDevicePipe &pip);

-

关闭设备,释放与设备相关的所有系统资源

-

int32_t PipeRequestWait(USBDevicePipe &pip, int64_t timeout, UsbRequest &req);

-

获取异步传输结果

-

int32_t RequestInitialize(UsbRequest &request);

-

初始化异步数据传输request

-

int32_t RequestFree(UsbRequest &request);

-

释放异步数据传输request

-
-

int32_t RequestAbort(UsbRequest &request);

-

取消待处理的数据请求

-

int32_t RequestQueue(UsbRequest &request);

-

将指定的端点进行异步数据发送或者接收请求,数据传输方向由端点方向决定

-

int32_t BulkRequstDataSize(const UsbDev &dev, const UsbPipe &pipe, uint32_t &length);

-

异步批量读取数据,传输大量数据时使用

-

int32_t BulkReadData(const UsbDev &dev, const UsbPipe &pipe, std::vector &data);

-

与BulkReadData配合使用,获取读取结果

-

int32_t BulkWriteData(const UsbDev &dev, const UsbPipe &pipe, const std::vector &data);

-

异步批量写数据,传输大量数据时使用

-

int32_t BulkGetWriteCompleteLength(const UsbDev &dev, const UsbPipe &pipe, uint32_t &length);

-

与BulkWriteData配合使用,获取写入状态,由length描述

-
- -- ### Device部分 - - - - - - - - - - - - - - - - - - - - - -

头文件

-

接口名称

-

功能描述

-

usb_srv_client.h

-

-

-

int32_t GetCurrentFunctions(int32_t &funcs);

-

获取设备模式下的当前USB功能列表的数字组合掩码

-

int32_t SetCurrentFunctions(int32_t funcs);

-

在设备模式下设置当前的USB功能列表

-

int32_t UsbFunctionsFromString(std::string funcs);

-

将给定的功能列表描述字符串转换为功能列表的数字组合掩码

-

std::string UsbFunctionsToString(int32_t funcs);

-

将给定的功能列表的数字组合掩码转换为功能列表描述字符串

-
- -- ### Port部分 - - - - - - - - - - - - - - - - - - -

头文件

-

接口名称

-

功能描述

-

usb_srv_client.h

-

-

-

int32_t GetSupportedModes(int32_t portId, int32_t &supportedModes);

-

获取指定的端口支持的模式列表的组合掩码

-

int32_t SetPortRole(int32_t portId, int32_t powerRole, int32_t dataRole);

-

设置指定的端口支持的角色模式,包含充电角色、数据传输角色

-

int32_t GetPorts(std::vector &usbPorts);

-

获取物理USB端口描述信息列表

-
diff --git a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-usbservice.md b/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-usbservice.md deleted file mode 100644 index d883f41761479589a2ac74860f236abe0274ccb5..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-usbservice.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: subsys-usbservice -permalink: /pages/extra/832f73/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# USB - -- **[USB服务子系统概述](/pages/extra/67dcae/)** - -- **[USB服务子系统使用指导](/pages/extra/d1dd5e/)** - -- **[USB服务子系统使用实例](/pages/extra/9ce8da/)** \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-utils.md b/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-utils.md deleted file mode 100644 index 9233e0bd0dfc2e17fe6322d670671d510628eec1..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys-utils.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: subsys-utils -permalink: /pages/extra/ce319f/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 公共基础 - -- **[公共基础库概述](/pages/01050701)** - -- **[公共基础库开发指导](/pages/01050702)** - -- **[公共基础库常见问题](/pages/01050703)** - - diff --git a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys.md b/website/docs/_posts/zh-cn/device-dev/subsystems/subsys.md deleted file mode 100644 index f4023bab574c40c6e902213a1b31184aef39f927..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/device-dev/subsystems/subsys.md +++ /dev/null @@ -1,34 +0,0 @@ ---- -title: subsys -permalink: /pages/extra/1328dc/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 子系统 - -- **[编译构建](/pages/extra/7014d3/)** -- **[分布式远程启动](/pages/010504)** -- **[图形图像](/pages/extra/7fcbf2/)** -- **[媒体](/pages/extra/c169e0/)** -- **[数据管理](/pages/extra/c92e1f/)** -- **[公共基础](/pages/extra/ce319f/)** -- **[AI框架](/pages/extra/ac23c8/)** -- **[Sensor服务](/pages/extra/fdd664/)** -- **[用户程序框架](/pages/extra/72b946/)** -- **[OTA升级](/pages/01050b)** -- **[电话服务](/pages/extra/019068/)** -- **[安全](/pages/extra/2dd473/)** -- **[启动恢复](/pages/extra/9238e4/)** -- **[测试用例开发指导](/pages/010901)** -- **[DFX](/pages/extra/684ab8/)** -- **[研发工具链](/pages/extra/5138cc/)** -- **[XTS认证用例开发指导](/pages/010a01)** - - diff --git a/website/docs/_posts/zh-cn/readme.md b/website/docs/_posts/zh-cn/readme.md deleted file mode 100644 index c1fed0bdfebf25d87f81e27347c84647c8475175..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/readme.md +++ /dev/null @@ -1,103 +0,0 @@ ---- -title: readme -permalink: /pages/extra/9161db/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 导读 - -此工程存放OpenHarmony提供的快速入门、开发指南、API参考等开发者文档,欢迎参与OpenHarmony开发者文档开源项目,与我们一起完善开发者文档。 - -## **文档目录结构** - - -- 设备开发 - - 轻量和小型系统开发指导(参考内存<128MB) - - overview:[设备开发导读](/pages/extra/006ae2/) - - quick-start:[快速入门](/pages/extra/eec566/)(搭建环境、获取源码、编译、烧录等) - - Basic Capability:开发基础能力 - - Kernel:[轻量系统内核](/pages/extra/65dc1e/) - - Kernel:[小型系统内核](/pages/extra/80d97b/) - - Drivers:[驱动](/pages/extra/551a2e/) - - Subsystems:[子系统](/pages/extra/e6eae1/)(编译构建、图形图像、DFX、XTS等子系统) - - Security:[隐私与安全](/pages/extra/b51404/) - - - guide:开发示例 - - [WLAN连接类产品](/pages/extra/a9f9b7/)(LED外设控制、集成三方SDK) - - [无屏摄像头类产品](/pages/extra/b2b869/)(摄像头控制) - - [带屏摄像头类产品](/pages/extra/51c9a4/)(屏幕和摄像头控制、视觉应用开发) - - - porting:移植适配 - - [轻量和小型系统三方库移植指导](/pages/extra/e80fe1/) - - [轻量系统芯片移植指导](/pages/extra/bc2a1e/) - - [轻量系统芯片移植案例](/pages/extra/890e18/) - - [小型系统芯片移植指导](/pages/extra/362558/) - - - bundles:HPM Bundle开发 - - [HPM Bundle开发规范](/pages/01060101) - - [HPM Bundle开发指南](/pages/extra/460736/) - - [HPM Bundle开发示例](/pages/extra/5aa5a6/) - - - 标准系统开发指导(参考内存≥128MB) - - overview:[设备开发导读](/pages/extra/006ae2/) - - quick-start:[快速入门](/pages/extra/6dca5d/)(搭建环境、获取源码、编译、烧录等) - - Basic Capability:开发基础能力 - - Kernel:[标准系统内核](/pages/extra/d328cc/) - - Drivers:[驱动](/pages/extra/551a2e/) - - Subsystems:[子系统](/pages/extra/e6eae1/)(编译构建、图形图像、DFX、XTS等子系统) - - Security:[隐私与安全](/pages/extra/b51404/) - - - guide:开发示例 - - [时钟应用](/pages/01070201) - - [平台驱动](/pages/01070202) - - [外设驱动](/pages/01070203) - - - porting:移植适配 - - [标准系统芯片移植指导](/pages/01040301) - - [一种快速移植OpenHarmony Linux内核的方法](/pages/01040302) - - - bundles:HPM Bundle开发 - - [HPM Bundle开发规范](/pages/01060101) - - [HPM Bundle开发指南](/pages/extra/460736/) - - [HPM Bundle开发示例](/pages/extra/5aa5a6/) - - [常见问题](/pages/extra/3a26c5/) - - -- 应用开发 - - overview:[应用开发导读](/pages/extra/e59705/) - - quick-start:[入门](/pages/extra/82bbc8/) - - ability:[Ability框架](/pages/extra/f24f79/) - - ui:[UI](/pages/extra/91bbde/) - - media:[媒体](/pages/extra/504ad4/) - - security:[安全](/pages/extra/85ba77/) - - connectivity:[网络与连接](/pages/extra/30f113/) - - database:[分布式数据服务](/pages/extra/ebcb6a/) - - usb:[USB服务](/pages/extra/6eccf9/) - - dfx:[DFX](/pages/extra/0b29a3/) - - reference:[开发参考](/pages/extra/23166e/) -- 许可证及版权信息检查工具:[开源合规审查工具](https://gitee.com/openharmony-sig/tools_oat) -- glossary:[术语](/pages/010103) - -## **版本更新** - -参考[Release Notes](/pages/010104)。 - -## **第三方开源软件及许可说明** - -3rd-Party-License:[第三方开源软件及许可证说明](/pages/extra/ccbaa4/) - -## **贡献** - -非常欢迎您参与[贡献](/pages/010d01),我们鼓励开发者以各种方式参与文档反馈和贡献。 - -您可以对现有文档进行评价、简单更改、反馈文档质量问题、贡献您的原创内容,详细请参考[贡献文档](/pages/extra/7f2552/)。 - -卓越贡献者将会在开发者社区文档贡献专栏表彰公示。 - diff --git a/website/docs/_posts/zh-cn/release-notes/OpenHarmony-2-0-Canary.md b/website/docs/_posts/zh-cn/release-notes/OpenHarmony-2-0-Canary.md deleted file mode 100644 index 63848d9d27a9d26a738a4daf21775ca64fcb75b2..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/release-notes/OpenHarmony-2-0-Canary.md +++ /dev/null @@ -1,263 +0,0 @@ ---- -title: OpenHarmony-2-0-Canary -permalink: /pages/extra/e47050/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# OpenHarmony 2.0 Canary(2021-06-01) - -- [版本概述](#section1677664815431) -- [配套关系](#section13201781528) -- [源码获取](#源码获取) -- [更新说明](#section11256141314463) - -## 版本概述 - -当前版本在OpenHarmony 1.1.0的基础上,增加标准系统版本,具备的主要功能如下: - -- 新增22个子系统,支持全面的OS能力,支持内存大于128M的带屏设备开发等。 -- 提供系统三大应用:桌面、设置和SystemUI。 -- 提供全新的OpenHarmony应用框架能力、Ability Cross-platform Engine能力。 -- 提供JS应用开发能力。 -- 提供媒体框架,支持音视频功能开发。 -- 提供图形框架能力,支持窗口管理和合成,支持GPU能力。 - -## 配套关系 - -**表 1** 版本软件和工具配套关系 - - - - - - - - - - - - - - - - - - - - -

软件

-

版本

-

备注

-

OpenHarmony

-

2.0 Canary

-

NA

-

HUAWEI DevEco Studio(可选)

-

DevEco Studio 2.1 Release

-

OpenHarmony应用开发推荐使用。

-

HUAWEI DevEco Device Tool(可选)

-

Deveco DeviceTool 2.2 Beta1

-

OpenHarmony智能设备集成开发环境推荐使用。

-
- -## 源码获取 - - -### 通过repo下载 - - **方式一(推荐)** - -通过repo + ssh 下载(需注册公钥,请参考[码云帮助中心](https://gitee.com/help/articles/4191))。 - - ``` -repo init -u git@gitee.com:openharmony/manifest.git -b refs/tags/OpenHarmony-2.0-Canary --no-repo-verify -repo sync -c -repo forall -c 'git lfs pull' - ``` - - **方式二** - -通过repo + https 下载。 - -``` -repo init -u https://gitee.com/openharmony/manifest.git -b refs/tags/OpenHarmony-2.0-Canary --no-repo-verify -repo sync -c -repo forall -c 'git lfs pull' -``` - -### 通过镜像站点获取 - -**表2** 源码获取路径 - -| 版本源码 | 版本信息 | 下载站点 | SHA256校验码 | -| -------- | -------- | -------- | -------- | -| 全量代码 | 2.0 | [站点](https://repo.huaweicloud.com/harmonyos/os/2.0/code-2.0-canary_20210601.tar.gz) | [SHA256校验码](https://repo.huaweicloud.com/harmonyos/os/2.0/code-2.0-canary_20210601.tar.gz.sha256) | -| Release Notes | 2.0 | [站点](https://gitee.com/openharmony/docs/blob/master/zh-cn/release-notes/OpenHarmony-2-0-Canary.md) | - | - -## 更新说明 - -本版本完全继承了OpenHarmony 1.1.0的所有特性,并在OpenHarmony 1.1.0版本的基础上,新增标准系统版本形态,详情请参考下表 。 - -**表 3** 版本新增特性表 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

子系统名称

-

新增特性

-

内核

-

基于Linux Kernel LTS社区开源基线,回合CVE补丁,包含了OpenHarmony上层特性适配。

-

分布式文件

-

提供本地同步文件 JS 接口,包括文件读写、目录访问以及文件Stat。

-

图形图像

-
  • 新增窗口管理功能,包括创建、销毁和窗口栈管理等。
  • 新增合成器功能,包括CPU、GPU和TDE合成。
  • 新增bufferqueue功能,支持进程间传递。
  • 新增vsync管理功能。
-

驱动

-

新增用户态驱动框架。

-

电源管理服务

-

新增电源管理能力,包括关机服务、亮灭屏管理、亮度调节、电池状态查询、系统电源管理、休眠锁管理等功能。

-

多模输入子系统

-

新增支持单指触屏输入能力。

-

启动恢复子系统

-

系统属性管理新增JS API。

-

升级服务

-
  • 新增recovery系统升级服务能力。
  • 新增差分包升级能力。
  • 新增系统属性管理JS API。
-

帐号

-

提供分布式云帐号登录状态管理功能。

-

编译构建

-
  • 支持按照部件名或模块名编译指定目标。
  • 支持不同芯片平台接入,配置产品部件列表。
-

测试

-

新增开发者自测试能力,支持C++ API单元测试,API性能测试等。

-

数据管理

-

提供轻量级Key-Value操作,支持本地应用存储少量数据,数据存储在本地文件中,同时也加载在内存中的,所以访问速度更快,效率更高。

-

语言编译运行时

-

提供了JS、C/C++语言程序的编译、执行环境,提供支撑运行时的基础库,以及关联的API接口、编译器和配套工具。

-

分布式任务调度

-

提供系统服务的启动、注册、查询及管理能力。

-

JS UI框架

-
  • 提供40+UI基础组件和容器组件。
  • 提供标准CSS动画。
  • 支持原子化布局、栅格布局。
  • 提供类Web开发范式的UI编程框架。
  • JS API扩展机制。
-

媒体

-
  • 新增媒体播放和录制基本功能。
  • 新增相机管理和相机采集基本功能。
  • 新增音频音量和设备管理基本功能。
-

事件通知

-

新增发布、订阅、接收公共事件的基本功能。

-

杂散软件服务

-

新增设置时间的能力。

-

用户程序框架

-

新增包安装、卸载、运行及管理能力。

-

电话服务

-
  • 新增获得信号强度、获得驻网状态能力。
  • 新增获得SIM卡状态能力。
  • 新增拨打电话、拒接电话、挂断电话能力。
  • 新增发送短信、接收短信能力。
-

公共基础类库

-

提供了一些常用的C、C++开发增强API。

-

研发工具链

-
  • 新增设备连接调试器。
  • 新增性能跟踪能力。
  • 新增实时内存和trace调优工具,和端侧插件能力。
-

分布式软总线

-
  • 新增跨进程通信(IPC)和跨设备的远程过程调用(RPC)能力。
  • 新增支持设备发现、组网、传输能力的软总线服务。
  • 新增WiFi服务,可提供STA开关、扫描、连接等基本能力。
-

XTS

-

新增各业务特性公共API兼容性看护用例套件。

-

系统应用

-

桌面:

-
  • 新增全量应用图标展示、启动和卸载应用能力。
  • 新增桌面管理界面,可切换网格布局与列表布局。
  • 新增最近任务管理能力,可热启动和清理任务。
-

设置:

-
  • 新增设置应用,包括亮度设置,应用信息,时间设置和关于设备。
-

SystemUI:

-
  • 新增系统栏展示,包括时间、电量信息。
  • 新增系统导航展示。
-

DFX

-
  • 新增流水日志。
  • 新增应用故障收集和订阅。
  • 新增系统事件记录接口。
  • 新增应用事件记录接口及框架。
-

全球化子系统

-
  • 新增支持资源解析读取能力。
  • 新增支持时间日期格式化能力。
-

安全

-
  • 新增系统权限管理,包括系统权限声明,应用安装时申请或申明的权限解析,权限查询,权限授予。
  • 新增应用签名和验签能力。
  • 新增点对点设备连接时的互信认证能力和设备群组管理能力。
-
- diff --git a/website/docs/_posts/zh-cn/release-notes/OpenHarmony-v1-1-3-LTS.md b/website/docs/_posts/zh-cn/release-notes/OpenHarmony-v1-1-3-LTS.md deleted file mode 100644 index 1691139109da23e9d5091d73f6370f777d802fcd..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/release-notes/OpenHarmony-v1-1-3-LTS.md +++ /dev/null @@ -1,239 +0,0 @@ ---- -title: OpenHarmony-v1-1-3-LTS -permalink: /pages/extra/ce2b2b/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# OpenHarmony v1.1.3 LTS - -- [版本概述](#section1846294912228) -- [配套关系](#section395983762117) -- [源码获取](#section84808293211) - - [通过镜像站点获取](#section8394142222113) - -- [更新说明](#section175225345334) -- [已修复缺陷列表](#section11935243172612) - -## 版本概述 - -更新发布LTS(long-term support)长期支持版本OpenHarmony v1.1.3 LTS,本版本在OpenHarmony v1.1.2 LTS版本的基础上新增了一些特性和修复了部分缺陷。 - -## 配套关系 - -**表 1** 版本软件和工具配套关系 - - - - - - - - - - - - - - - - -

软件

-

版本

-

备注

-

OpenHarmony

-

1.1.3 LTS

-

NA

-

HUAWEI DevEco Device Tool(可选)

-

HUAWEI DevEco Device Tool 2.1 Release

-

OpenHarmony智能设备集成开发环境推荐使用。

-
- -## 源码获取 - -通过repo下载 - -方式一(推荐):通过repo + ssh 下载(需注册公钥,请参考[码云帮助中心](https://gitee.com/help/articles/4191))。 - -``` -repo init -u git@gitee.com:openharmony/manifest.git -b refs/tags/OpenHarmony-v1.1.3-LTS --no-repo-verify -repo sync -c -repo forall -c 'git lfs pull' -``` - -方式二:通过repo + https 下载。 - -``` -repo init -u https://gitee.com/openharmony/manifest.git -b refs/tags/OpenHarmony-v1.1.3-LTS --no-repo-verify -repo sync -c -repo forall -c 'git lfs pull' -``` - -### 通过镜像站点获取 - -**表 2** 源码获取路径 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

版本源码

-

版本信息

-

下载站点

-

SHA256校验码

-

全量代码

-

1.1.3

-

站点

-

SHA256校验码

-

Hi3861解决方案(二进制)

-

1.1.3

-

站点

-

SHA256校验码

-

Hi3518解决方案(二进制)

-

1.1.3

-

站点

-

SHA256校验码

-

Hi3516解决方案(二进制)

-

1.1.3

-

站点

-

SHA256校验码

-

Release Notes

-

1.1.3

-

站点

-

-

-
- -## 更新说明 - -本版本完全继承了OpenHarmony v1.1.2 LTS的所有特性,并在OpenHarmony v1.1.2 LTS版本的基础上,新增了轻量设备可以在windows环境下的编译版本的特性(请参考[windows开发环境准备](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/quickstart-lite-env-setup-windows.md))。 - -**表 3** 特性更新说明 - - - - - - - - - - - - - - -

子系统

-

新增特性

-

修改特性

-

删除特性

-

芯片平台

-

支持了轻量设备在windows环境下编译版本(pulls/60

-

N/A

-

N/A

-
- -## 已修复缺陷列表 - -在OpenHarmony v1.1.2 LTS版本的基础上,解决并修复的问题见下表。 - -**表 4** 已修复问题列表 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

ISSUE

-

问题描述

-

I43MZK

-

release1.0.1分支命名中出现空格字符,与外部接口标准不符

-

I44ZGK

-

组件ffmpeg 4.2.2存在未修复的漏洞

-

I41ZMV

-

HI3516刷机之后,在系统bin目录下存在module_ActsUiInterfaceTest1.bin测试文件

-

I3ZOIO

-

los_disk_deinit 资源释放失败

-

I43WLG

-

OsMountRootfs启动失败

-

I44ZXW

-

openharmony_1.0.1_release分支上的curl组件从7.69.1版本更新到7.78.0版本

-

I48FKQ

-

osEventFlagsGet传NULL时应该返回0

-

I48FL1

-

osThreadNew函数attr为NULL时,创建线程失败

-

I48FLX

-

shell命令中使用rm -r指令尝试删除dev下节点时会导致系统出错

-

I48FMK

-

小型系统的ActsProcessApiTest/UidGidTest/testGetgroup测试用例失败

-

I48FMT

-

nanosleep函数实现存在缺陷

-
- diff --git a/website/docs/_posts/zh-cn/release-notes/OpenHarmony-v2.2-beta2.md b/website/docs/_posts/zh-cn/release-notes/OpenHarmony-v2.2-beta2.md deleted file mode 100644 index a0343a1454a740eb1373a3516578b21217184e35..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/release-notes/OpenHarmony-v2.2-beta2.md +++ /dev/null @@ -1,400 +0,0 @@ ---- -title: OpenHarmony-v2.2-beta2 -permalink: /pages/extra/bb5e43/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# OpenHarmony v2.2 Beta2 - -- [版本概述](#section1677664815431) -- [配套关系](#section13201781528) -- [源码获取](#section1350215462116) -- [更新说明](#section11256141314463) -- [修复缺陷列表](#section3442123281619) - -## 版本概述 - -当前版本在OpenHarmony 2.0 Canary的基础上,针对轻量系统、小型系统和标准系统都有增加新的特性: - -标准系统新增特性功能如下: - -- 新增分布式远程拉起能力端到端的构建。 -- 新增系统基础应用的拖拽能力和新增若干Sample应用。 -- 新增媒体三大服务能力,提供更好的媒体系统功能。 - -轻量和小型系统新增特性功能如下: - -- 新增小型系统linux版本构建能力。 -- 新增轻量级内核能力增强,包括文件系统增强、内核调试工具增强支持、内核模块支持可配置、三方芯片适配支持、支持ARM9架构等。 -- 轻量级图形能力增强支持,包括支持多语言字体对齐、支持显示控件轮廓、支持点阵字体、供统一多后端框架支持多芯片平台等。 -- DFX能力增强支持,包括HiLog功能增强、HiEvent功能增强,提供轻量级系统信息dump工具、提供重启维侧框架等。 -- AI能力增强支持,包括新增linux内核适配支持、AI引擎支持基于共享内存的数据传输。 - -## 配套关系 - -**表 1** 版本软件和工具配套关系 - - - - - - - - - - - - - - - - - - - - -

软件

-

版本

-

备注

-

OpenHarmony

-

2.2 Beta2

-

NA

-

HUAWEI DevEco Studio(可选)

-

DevEco Studio 2.2 Beta1

-

OpenHarmony应用开发推荐使用。

-

HUAWEI DevEco Device Tool(可选)

-

Deveco DeviceTool 2.2 Beta1

-

OpenHarmony智能设备集成开发环境推荐使用。

-
- -## 源码获取 - -### 通过repo下载 - -**方式一(推荐)** - -通过repo + ssh 下载(需注册公钥,请参考[码云帮助中心](https://gitee.com/help/articles/4191))。 - -``` -repo init -u git@gitee.com:openharmony/manifest.git -b refs/tags/OpenHarmony-v2.2-Beta2 --no-repo-verify -repo sync -c -repo forall -c 'git lfs pull' -``` - -**方式二** - -通过repo + https 下载。 - -``` -repo init -u https://gitee.com/openharmony/manifest.git -b refs/tags/OpenHarmony-v2.2-Beta2 --no-repo-verify -repo sync -c -repo forall -c 'git lfs pull' -``` - -### 通过镜像站点下载 - -**表2** 源码获取路径 - -| 版本源码 | 版本信息 | 下载站点 | SHA256校验码 | -| -------- | -------- | -------- | -------- | -| 全量代码(标准、轻量和小型系统) | 2.2 | [站点](https://repo.huaweicloud.com/harmonyos/os/2.2-Beta2/code-v2.2-beta2_20210730.tar.gz) | [SHA256校验码](https://repo.huaweicloud.com/harmonyos/os/2.2-Beta2/code-v2.2-beta2_20210730.tar.gz.sha256) | -| 标准系统解决方案(二进制) | 2.2 | [站点](https://repo.huaweicloud.com/harmonyos/os/2.2-Beta2/standard-2.2-Beta2.tar.gz) | [SHA256校验码](https://repo.huaweicloud.com/harmonyos/os/2.2-Beta2/standard-2.2-Beta2.tar.gz.sha256) | -| Hi3861解决方案(二进制) | 2.2 | [站点](https://repo.huaweicloud.com/harmonyos/os/2.2-Beta2/hispark_pegasus-2.2-Beta2.tar.gz) | [SHA256校验码](https://repo.huaweicloud.com/harmonyos/os/2.2-Beta2/hispark_pegasus-2.2-Beta2.tar.gz.sha256) | -| Hi3518解决方案(二进制) | 2.2 | [站点](https://repo.huaweicloud.com/harmonyos/os/2.2-Beta2/hispark_aries-2.2-Beta2.tar.gz) | [SHA256校验码](https://repo.huaweicloud.com/harmonyos/os/2.2-Beta2/hispark_aries-2.2-Beta2.tar.gz.sha256) | -| Hi3516解决方案-LiteOS(二进制) | 2.2 | [站点](https://repo.huaweicloud.com/harmonyos/os/2.2-Beta2/hispark_taurus-2.2-Beta2.tar.gz) | [SHA256校验码](https://repo.huaweicloud.com/harmonyos/os/2.2-Beta2/hispark_taurus-2.2-Beta2.tar.gz.sha256) | -| Hi3516解决方案-Linux(二进制) | 2.2 | [站点](https://repo.huaweicloud.com/harmonyos/os/2.2-Beta2/hispark_taurus_linux-2.2-Beta2.tar.gz) | [SHA256校验码](https://repo.huaweicloud.com/harmonyos/os/2.2-Beta2/hispark_taurus_linux-2.2-Beta2.tar.gz.sha256) | -| Release Notes | 2.2 | [站点](https://gitee.com/openharmony/docs/blob/master/zh-cn/release-notes/OpenHarmony-v2.2-beta2.md) | - | - - -## 更新说明 - -本版本在继承了OpenHarmony 2.0 Canary的基础上有如下变更。 - -### 特性变更 - -**表 3** 版本新增特性表 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

子系统名称

-

标准系统

-

轻量、小型系统

-

分布式文件

-

提供本地system.file异步文件操作JS API,包括文件读写、目录访问、增删等接口。

-

NA

-

驱动

-

3QE85:新增Audio、Camera、USB、马达、ADC驱动模型。

-

LiteOS-M支持HDF框架。

-

电源管理服务

-

新增系统电源状态机、休眠运行锁、休眠唤醒功能。

-
  • 新增充放电状态查询接口、电量查询接口。
  • 提供低功耗模式支持,并提供低功耗模式统一API支持。
-

升级服务

-

新增恢复出厂功能。

-

NA

-

媒体

-
  • 新增音频服务,提供音频基础控制能力。
  • 新增相机服务,提供预览、拍照等基础功能力。
  • 新增媒体服务,提供音频、视频播放能力。
-

NA

-

JS UI框架

-

支持使用JS与C/C++混合开发JS API。

-

NA

-

事件通知

-

支持应用本地发送、取消多行文本通知能力。

-

NA

-

分布式软总线

-

新增软总线自组网功能,可信设备接入到局域网中(ETH\WiFi)后可自发现、无感知的接入到软总线。

-

NA

-

分布式数据管理

-
  • 新增分布式数据管理能力,支持分布式数据库在本地加密存储
  • 支持轻量级偏好数据库
-
  • 提供数据库内容的删除能力。
  • 提供统一的HAL文件系统操作函数实现。
  • 提供相关数据存储的原子操作能力。
  • 提供二进制Value的写入读取能力。
-

系统应用

-

桌面:

-
  • 桌面设置界面UX优化。
  • 新增桌面图标拖拽特性。
-

设置:

-
  • 新增Wlan设置功能。
-

SystemUI:

-
  • 新增卡信号图标显示功能。
-

图库:

-
  • 新增图片、视频资源的查看、移动、复制、删除、重命名等功能。
-

NA

-

全球化子系统

-
  • 完善时间日期格式化能力。
  • 支持时间段的格式化。
  • 新增数字格式化能力。
-
  • 新增构建自定义数据编译能力。
  • 新增构建星期、单复数、数字开关国际化能力。
  • 新增构建应用资源解析和加载机制。
  • 新增构建资源回溯机制。
-

Sample应用

-
  • 计算器中新增分布式功能,组网后支持拉起另一台组网设备上的计算器,两台设备可协同计算,计算数据实时同步。
  • 新增音频播放器应用,支持本地音频播放,组网后可将音乐播放接续至其他组网设备上。
-

NA

-

分布式设备管理

-

新增设备管理系统服务,提供分布式设备账号无关的认证组网能力。

-

NA

-

DFX

-

NA

-
  • 提供LiteOS内核系统信息dump工具。
  • 提供LiteOS内核死机重启维测框架。
  • 新增数字格式化能力。
  • HiLog功能增强。
  • HiEvent功能增强。
-

内核

-

NA

-
  • 支持轻量级Linux版本。
  • proc文件系统增强。
  • 新增mksh命令解析器。
  • 文件系统维测增强。
  • LiteOS-A內核模块支持可配置。
  • 支持LiteOS-A小系统三方芯片适配。
  • LiteOS-M支持三方组件Mbedtls编译。
  • LiteOS-M支持三方组件curl编译。
  • 支持轻量级shell框架和常用调测命令。
  • LiteOS-M支持ARM9架构。
  • 支持基于NOR Flash的littlefs文件系统。
  • LiteOS-M对外提供统一的文件系统操作接口。
  • 新增Namecache模块、Vnode管理、Lookup模块。
-

图形图像

-

NA

-
  • 支持A4\A8、LUT8、TSC图片格式作为输入。
  • 支持多语言字体对齐。
  • UIKit支持显示控件轮廓。
  • ScrollView/List支持通过弧形进度条展示滑动进度。
  • 支持开关按钮/复选框/单选按钮动效。
  • UIKit支持点阵字体产品化解耦。
  • UI框架提供统一多后端框架支持多芯片平台。
  • UIKit组件支持margin/padding。
  • 圆形/胶囊按钮支持缩放和白色蒙层动效。
-

编译构建

-

NA

-

支持开源软件的通用patch框架。

-

启动恢复

-

NA

-

支持恢复出厂设置支持多语言字体对齐。

-

分布式调度

-

NA

-

支持轻量设备启动富设备上的Ability。

-

AI

-

NA

-
  • AI子系统添加Linux内核适配,编译选项支持。
  • AI引擎支持基于共享内存的数据传输。
-
- -### API变更 - -API变更请参考: - -[JS API 差异报告](/pages/extra/3ce8d3/) - -[Native API 差异报告](/pages/extra/7ca9bb/) - -## 修复缺陷列表 - -**表 4** **解决的缺陷ISSUE列表** - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

ISSUE单号

-

问题描述

-

I3I31W

-

ActsNFSTest.bin会引起内核crash

-

I3D49E

-

uboot的路径不对

-

I3D71U

-

【驱动子系统】反复reset,启动到hmac_main_init SUCCESSULLY后,高概率出现系统挂死

-

I3DGZW

-

【应用程序框架子系统】HI3516开源板进入屏保后 ,点击触摸屏,出现蓝屏问题

-

I3DHIL

-

【系统问题】HI3518开源板剩余空间不足,导致ACTS用例大量失败

-

I3DU36

-

【应用程序框架子系统】ipcamera bm 查询命令失效

-

I3EALU

-

【媒体子系统】cameraActs 用例执行时,找不到相机配置文件,初始失败

-

I3EGUX

-

【可靠性问题】反复reset,出现一次KIdle进程crash,系统挂死无法启动

-

I3EH4E

-

【流水线问题】高概率出现:uname无响应,然后执行reset也无响应

-

I3EQJA

-

【文件系统】cat /proc/mounts功能不可用

-

I3EQRC

-

磁盘文件映射延迟测试:并发3个测试进程,系统crash

-

I3HVL0

-

3861编译失败,报错[OHOS ERROR] Fatal error: invalid -march= option:rv32imac

-

I3TS1Y

-

压力场景下文件相关Vnode资源耗尽

-

I3TXT8

-

孤儿进程无法回收,压力场景下TCB资源耗尽

-

I3UWXI

-

libwap.so 存在已知一般漏洞: CVE-2021-30004,CVSS:5.3;漏洞发布日期:2021-04-02,不符合产品发布要求,需要解决。

-

I3SWY2

-

高概率出现KProcess进程挂死,质量不达标

-

I3YJRO

-

liteos-a內核模块可配置编译失败

-

I3YNWM

-

文件系统维测增强功能在该版本有问题

-

I3VEOG

-

bin目录下没有mksh和toybox,导致已转测的toybox命令集无法测试

-
- diff --git a/website/docs/_posts/zh-cn/release-notes/OpenHarmony-v3.0-LTS.md b/website/docs/_posts/zh-cn/release-notes/OpenHarmony-v3.0-LTS.md deleted file mode 100644 index 4f9486068d052ebc6dc836f215997a07bbb9b891..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/release-notes/OpenHarmony-v3.0-LTS.md +++ /dev/null @@ -1,207 +0,0 @@ ---- -title: OpenHarmony-v3.0-LTS -permalink: /pages/extra/096eed/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# OpenHarmony 3.0 LTS - -- [版本概述](#版本概述) -- [配套关系](#配套关系) -- [源码获取](#源码获取) -- [更新说明](#更新说明) - - [特性变更](#特性变更) - - [API变更](#api变更) - - [芯片及开发板适配](#芯片及开发板适配) -- [修复缺陷列表](#修复缺陷列表) -- [遗留缺陷列表](#遗留缺陷列表) - -## 版本概述 - -当前版本在OpenHarmony 2.2 Beta2的基础上,针对标准系统、轻量系统和小型系统更新内容: - -标准系统新增特性功能: - -- 用户程序框架支持服务能力(ServiceAbility,DataAbility)和线程模型。 - -- 支持文件安全访问,即文件转成URI和解析URI打开文件的能力。 - -- 支持设备管理PIN码认证的基本能力。 - -- 支持关系型数据库、分布式数据管理基础能力。 - -- 支持方舟JS编译工具链和运行时,支持OpenHarmony JS UI框架应用开发和运行。 - -- 支持远程绑定ServiceAbility、FA跨设备迁移能力。 - -- 支持应用通知订阅与应用通知消息跳转能力。 - -- 支持输入法框架及支持输入基础英文字母、符号和数字。 - -- 相机应用支持预览、拍照和录像基础能力。 - -- 支持CS基础通话、GSM短信能力。 - -- 支持定时器能力,提供定时时区管理能力。 - -- 在标准设备间的分布式组网下,提供应用跨设备访问对端资源或能力时的权限校验功能。 - -轻量和小型系统新增特性功能: - -- 新增轻量级分布式能力增强,支持从轻量级系统启动标准系统上的Ability。 - -- 软总线能力增强支持,提供认证通道传输能力,用于设备绑定。 - -- 轻量级全球化能力增强支持,新增31种语言支持。 - -- 轻量系统上新增权限属性字段及其写入接口,上层应用可通过该字段实现相关业务。 - - -## 配套关系 - -**表1** 版本软件和工具配套关系 - -| 软件 | 版本 | 备注 | -| -------- | -------- | -------- | -| OpenHarmony | 3.0 LTS | NA | -| HUAWEI DevEco Studio(可选) | 3.0 Beta1 | OpenHarmony应用开发推荐使用。 | -| HUAWEI DevEco Device Tool(可选) | 2.2 Beta2 | OpenHarmony智能设备集成开发环境推荐使用。 | - - -## 源码获取 - - -### 通过repo获取 - -**方式** **一(推荐)** - -通过repo + ssh 下载(需注册公钥,请参考[码云帮助中心](https://gitee.com/help/articles/4191))。 - -``` -repo init -u git@gitee.com:openharmony/manifest.git -b refs/tags/OpenHarmony-v3.0-LTS --no-repo-verify -repo sync -c -repo forall -c 'git lfs pull' -``` - -**方式二** - -通过repo + https 下载。 - -``` -repo init -u https://gitee.com/openharmony/manifest.git -b refs/tags/OpenHarmony-v3.0-LTS --no-repo-verify -repo sync -c -repo forall -c 'git lfs pull' -``` - -### 从镜像站点获取 - -**表2** 获取源码路径 - -| **LTS版本源码** | **版本信息** | **下载站点** | **SHA256校验码** | -| -------- | -------- | -------- | -------- | -| 全量代码(标准、轻量和小型系统) | 3.0 | [站点](https://repo.huaweicloud.com/harmonyos/os/3.0/code-v3.0-LTS.tar.gz) | [SHA256校验码](https://repo.huaweicloud.com/harmonyos/os/3.0/code-v3.0-LTS.tar.gz.sha256) | -| 标准系统解决方案(二进制) | 3.0 | [站点](https://repo.huaweicloud.com/harmonyos/os/3.0/standard.tar.gz) | [SHA256校验码](https://repo.huaweicloud.com/harmonyos/os/3.0/standard.tar.gz.sha256) | -| Hi3861解决方案(二进制) | 3.0 | [站点](https://repo.huaweicloud.com/harmonyos/os/3.0/hispark_pegasus.tar.gz) | [SHA256校验码](https://repo.huaweicloud.com/harmonyos/os/3.0/hispark_pegasus.tar.gz.sha256) | -| Hi3518解决方案(二进制) | 3.0 | [站点](https://repo.huaweicloud.com/harmonyos/os/3.0/hispark_aries.tar.gz) | [SHA256校验码](https://repo.huaweicloud.com/harmonyos/os/3.0/hispark_aries.tar.gz.sha256) | -| Hi3516解决方案-LiteOS(二进制) | 3.0 | [站点](https://repo.huaweicloud.com/harmonyos/os/3.0/hispark_taurus.tar.gz) | [SHA256校验码](https://repo.huaweicloud.com/harmonyos/os/3.0/hispark_taurus.tar.gz.sha256) | -| Hi3516解决方案-Linux(二进制) | 3.0 | [站点](https://repo.huaweicloud.com/harmonyos/os/3.0/hispark_taurus_linux.tar.gz) | [SHA256校验码](https://repo.huaweicloud.com/harmonyos/os/3.0/hispark_taurus_linux.tar.gz.sha256) | -| Release Notes | 3.0 | [站点](https://gitee.com/openharmony/docs/blob/OpenHarmony-3.0-LTS/zh-cn/release-notes/OpenHarmony-v3.0-LTS.md) | - | - - -## 更新说明 - -本版本在OpenHarmony 2.2 Beta2的基础上有如下变更。 - - -### 特性变更 - -**表3** 版本新增特性表 - -| 子系统名称 | 标准系统 | 轻量、小型系统 | -| -------- | -------- | -------- | -| 分布式任务调度 | - 新增远程绑定ServiceAbility基本功能
- 新增FA跨设备迁移功能
- 新增组件visible属性权限校验功能 | 新增小型系统启动HarmonyOS Ability的功能 | -| 图形 | 对于带有GPU模块的芯片平台,支持使用GPU进行渲染合成,以提升图形性能,降低CPU负载 | NA | -| 分布式硬件 | - 支持基于分布式软总线认证通道的PIN码认证方案
- 支持PIN码认证授权提示弹窗
- 支持PIN码显示弹窗
- 支持PIN码输入弹窗 | NA | -| 事件通知 | - 支持应用通知订阅 & 取消订阅
- 支持应用侧发布&取消本地文本、图片通知
- 支持应用通知消息跳转能力
- 支持应用侧增加&删除slot
- 支持通知流控处理、死亡监听能力 | NA | -| 分布式软总线 | 软总线:
- 支持基于CoAP的主动发现和被动发现,支持通过BLE主动发现连接
- 支持基于WLAN网络的手动入网和自组网
- 支持基于WLAN网络,直通模式下的消息、字节、文件传输
IPC:
- 支持设备内基于linux内核binder协议的进程间通信能力
- 支持对象和序列化数据通信
RPC:
- 支持设备间基于分布式软总线的进程间通信能力
- 支持对象和序列化数据通信
- 接口与IPC保持一致 | 软总线:
- 支持基于CoAP的主动发现和被动发现
- 支持基于WLAN网络的手动入网和自组网
- 支持基于WLAN网络,直通模式下的消息、字节、文件传输
IPC:
- 支持设备内基于Linux/LiteOS内核binder协议的进程间通信
- 支持char/int/long基础数据接口的序列化通信 | -| 全球化 | 提供获取系统设置的语言、地区、区域信息,以及获取语言和地区的本地化名称的能力 | 轻量级全球化能力增强支持,新增31种语言支持 | -| 系统应用 | - 桌面:全新架构优化
- SystemUI:
  - 通知中心以及普通文本通知功能
  - 控制中心:WLAN、飞行模式开关、亮度调节、声音调节
  - 全新架构优化
- 设置:全新架构优化
- 相机:
  - 支持基础拍照、录像功能
  - 分布式协同:拉起对端相机并拍照 | NA | -| 语言编译运行时 | 新增方舟JS编译工具链和运行时,支持OpenHarmony JS UI框架应用开发和运行 | NA | -| 媒体 | - 相机组件中新增录像功能
- 新增音频录制功能接口 | 新增支持播放mp3格式文件 | -| JS UI框架 | - 支持迁移相关生命周期
- 支持系统服务弹窗
- 支持使用JS开发service类型和data类型的Ability | NA | -| 内核 | 新增支持OpenHarmony Common Linux Kernel 5.10 | 小型系统新增支持OpenHarmony Common Linux Kernel 5.10 | -| DFX | - 提供HiAppEvent应用事件打点的JS API
- 提供HiCollie卡死检测框架
- 提供HiTrace分布式调用链基础库 | NA | -| 驱动 | 新增I2S、陀螺仪、压力、霍尔驱动模型 | NA | -| 安全 | 在标准设备间的分布式组网下,提供应用跨设备访问对端资源或能力时的权限校验功能 | 轻量系统上新增权限属性字段及其写入接口,上层应用可通过该字段实现相关业务(如弹框授权场景下,用户拒绝授权后不再弹框) | -| 电话服务 | - 搜网功能模块:支持飞行模式设置、搜网模式设置(包括手动搜网和自动搜网)、LTE制式信号强度获取
- SIM功能模块:支持PIN/PUK解锁、卡文件信息获取、卡账户信息的存取、卡状态获取
- 蜂窝通话功能模块:支持通话前后台切换、来电静音、呼叫保持与恢复、三方通话、DTMF
- 短彩信功能模块:支持SIM卡短信的增删改查 | NA | -| 分布式文件 | - 支持f2fs、ext4文件系统不同参数设置的分区挂载能力
- 支持文件安全访问,即文件转成URI和解析URI打开文件的能力
- 支持系统应用访问公共目录的能力 | NA | -| 分布式数据管理 | - 支持关系型数据库JS基础能力(增删改查等)
- 支持分布式数据管理JS基础能力(增删改查等) | NA | -| 编译构建 | - 支持编译arm64形态产品
- 支持编译ohos-sdk | NA | -| 用户程序框架 | - 支持ServiceAbility JS开发能力
- 支持DataAbility JS开发能力
- HAP支持多Ability声明
- 本地Ability迁移到远程设备
- 应用任务栈保存与恢复
- JS 利用Zip库实现文件压缩和解压缩 | NA | -| 杂散软件服务 | 支持定时器能力,提供定时时区管理能力 | NA | - - -### API变更 - -API变更请参考:[JS API 差异报告](/pages/extra/b1cae4/) - - -### 芯片及开发板适配 - -芯片及开发板适配状态请参考[SIG-Devboard](https://gitee.com/openharmony/community/blob/master/sig/sig-devboard/sig_devboard_cn.md)信息。 - - -## 修复缺陷列表 - -**表4** 轻量和小型系统解决的缺陷ISSUE列表 - -| ISSUE单号 | 问题描述 | -| -------- | -------- | -| [I45AVP](https://gitee.com/openharmony/hiviewdfx_hilog/issues/I45AVP) | 执行hilog落盘之后hilog命令执行失败 | -| [I47EPA](https://gitee.com/openharmony/appexecfwk_appexecfwk_lite/issues/I47EPA?from=project-issue) | 入参为空或无效时,GetBundleSize接口返回错误 | -| [I434AD](https://gitee.com/openharmony/multimedia_camera_lite/issues/I434AD) | Hi3516DV300轻量级系统常驻内存超基线 | -| [I434P1](https://gitee.com/openharmony/multimedia_camera_lite/issues/I434P1) | Hi3518EV300轻量级系统常驻内存超基线 | -| [I46I6K](https://gitee.com/openharmony/multimedia_media_lite/issues/I46I6K?from=project-issue) | 多媒体子系统相关代码存在安全编码问题 | -| [I46E6S](https://gitee.com/openharmony/kernel_liteos_m/issues/I46E6S?from=project-issue) | 轻量级内核模块编译添加-Werror编译选项 | -| [I47ETO](https://gitee.com/openharmony/appexecfwk_appexecfwk_lite/issues/I47ETO?from=project-issue -) | 权限校验没有生效,使用测试 bin 直接调用无权限 hap,期望查询失败返回 0,结果查询成功 | -| [I48A2I](https://gitee.com/openharmony/drivers_peripheral/issues/I48A2I) | Hi3516DV300轻量级版本调用AllocMem接口测试,单板挂死 | -| [I42LCU](https://gitee.com/openharmony/kernel_liteos_m/issues/I42LCU) | 集成测试开发板移植指导中需增加线程不足的确认方法和配置线程个数的方法 | -| [I3IPD7](https://gitee.com/openharmony/kernel_liteos_m/issues/I3IPD7) | 不支持osThreadExit/join函数需要在头文件中说明 | -| [I3M12H](https://gitee.com/openharmony/kernel_liteos_a/issues/I3M12H) | 集成测试发送两个不同的信号,sigwait第二次等到的仍是第一个信号 | -| [I47X2Z](https://gitee.com/openharmony/kernel_liteos_a/issues/I47X2Z?from=project-issue) | 集成测试 在执行ActsIpcShmTest.bin脚本,出现大量未释放的共享内存 | -| [I4BL3S](https://gitee.com/openharmony/kernel_liteos_a/issues/I4BL3S) | 集成测试fs_posix模块nfs用例跑多次会出现不停打印申请内存失败问题 | -| [I490KZ](https://gitee.com/openharmony/kernel_liteos_a/issues/I490KZ) | FutexTest.testPthreadTimdOutRWlockWR用例执行失败 | -| [I44SFO](https://gitee.com/openharmony/third_party_toybox/issues/I44SFO) | 集成测试在某个目录下mv一个文件后,再在此目录下创建同名文件并二次mv该文件失败,提示此文件不存在 | - -**表5** 标准系统解决的缺陷ISSUE列表 - -| ISSUE单号 | 问题描述 | -| -------- | -------- | -| [I46A6H](https://gitee.com/openharmony/ace_ace_engine/issues/I46A6H) | XTS子系统压力测试过程中libace.z.so异常导致ohos.samples.flashlight出现cppcrash异常 | -| [I48HLN](https://gitee.com/openharmony/app_samples/issues/I48HLN) | Demo&应用子系统- [ JsCanvas] 清除的button功能未生效 | -| [I46HH7](https://gitee.com/openharmony/drivers_peripheral/issues/I46HH7) | 驱动子系统-标准系统单板WLAN测试用例失败 | -| [I4312A](https://gitee.com/openharmony/communication_dsoftbus/issues/I4312A) | 【2.2 Beta2】【软总线】已组网,断1端网络后,自组网失败(GetAllNodeDeviceInfo返回null) | -| [I43WIJ](https://gitee.com/openharmony/communication_dsoftbus/issues/I43WIJ) | 【2.2 Beta2】【软总线】已组网,一端切换网络再切回,过程中组网未下线(无上下线回调) | -| [I43KLC](https://gitee.com/openharmony/communication_dsoftbus/issues/I43KLC) | 【2.2 Beta2】【软总线】注册节点状态监听,设备上线,设备再离线,offline回调调用了2次 | -| [I47WTY](https://gitee.com/openharmony/communication_dsoftbus/issues/I47WTY) | 【3.0 beta1】【软总线-传输】session id范围校验不严谨(有效范围1-16,校验时判断的是>17) | - - -## 遗留缺陷列表 - -**表6** 遗留缺陷列表 - -| ISSUE | 问题描述 | 影响 | 计划解决日期 | -| -------- | -------- | -------- | -------- | -| [I48IM7](https://gitee.com/openharmony/hiviewdfx_hilog/issues/I48IM7) | 运行hilog压力测试,hilogd异常重启,且hilog命令一直无法使用 | 压力测试下,低概率出现日志输出异常,调测场景可正常使用。 | 10月30日 | -| [I48YPH](https://gitee.com/openharmony/security_deviceauth/issues/I48YPH) | 【软总线-组网】测试发现和组网性能(循环离网-发现-组网)110次组网失败3次 | 低概率3/110,失败后重新发起组网即可。 | 10月30日 | -| [I4BVVW](https://gitee.com/openharmony/communication_dsoftbus/issues/I4BVVW) | 【软总线-组网】标准系统与手机开关网络自组网成功率97%失败3次需分析失败原因 | 低概率出现组网失败。 | 10月30日 | -| [I4BXWY](https://gitee.com/openharmony/multimedia_media_standard/issues/I4BXWY) | Hi3516音频录制后播放有杂音 | 仅在使用此开发板时,影响录制音频的播放体验效果。 | 10月30日 | -| [I4BXY1](https://gitee.com/openharmony/multimedia_camera_standard/issues/I4BXY1) | 视频录制后前几秒没声音,播放声画不同步,在板子播放会卡顿,音源较远时,有杂音 | 仅在使用此开发板时,影响录制视频的播放体验效果。 | 10月30日 | -| [3ZJ1D](https://gitee.com/openharmony/kernel_liteos_a/issues/I3ZJ1D) | XTS权限用例压测用户态概率失败 | 仅在重复创建子进程的XTS压力测试场景,设置子进程uid失败,低概率问题。 | 10月30日 | diff --git a/website/docs/_posts/zh-cn/release-notes/OpenHarmony-v3.0.1-LTS.md b/website/docs/_posts/zh-cn/release-notes/OpenHarmony-v3.0.1-LTS.md deleted file mode 100644 index 67ef135da95550daafddfd119e8fb5082f496b81..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/release-notes/OpenHarmony-v3.0.1-LTS.md +++ /dev/null @@ -1,179 +0,0 @@ ---- -title: OpenHarmony-v3.0.1-LTS -permalink: /pages/extra/23d8e8/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false ---- -# OpenHarmony 3.0.1 LTS - -## 版本概述 - -此版本为OpenHarmony-3.0-LTS分支上的维护版本,基于OpenHarmony-v3.0-LTS版本修复一些缺陷及安全问题,通过集成验证后发布最新的稳定的tag版本。 - - -## 配套关系 - -**表1** 版本软件和工具配套关系 - -| 软件 | 版本 | 备注 | -| -------- | -------- | -------- | -| OpenHarmony | 3.0.1 LTS | NA | -| SDK | 3.0.0.0(API Version 7 release) | NA | -| HUAWEI DevEco Studio(可选) | 3.0 Beta1 | OpenHarmony应用开发推荐使用。 | -| HUAWEI DevEco Device Tool(可选) | 2.2 Beta2 | OpenHarmony智能设备集成开发环境推荐使用。 | - - -## 源码获取 - - -### 通过repo获取 - -**方式一(推荐)**:通过repo + ssh 下载(需注册公钥,请参考[码云帮助中心](https://gitee.com/help/articles/4191))。 - -``` -repo init -u git@gitee.com:openharmony/manifest.git -b refs/tags/OpenHarmony-v3.0.1-LTS --no-repo-verify -repo sync -c -repo forall -c 'git lfs pull' -``` - -**方式二**:通过repo + https 下载。 - -``` -repo init -u https://gitee.com/openharmony/manifest.git -b refs/tags/OpenHarmony-v3.0.1-LTS --no-repo-verify -repo sync -c -repo forall -c 'git lfs pull' -``` - - -### 从镜像站点获取 - -**表2** 获取源码路径 - -| **LTS版本源码** | **版本信息** | **下载站点** | **SHA256校验码** | -| -------- | -------- | -------- | -------- | -| 全量代码(标准、轻量和小型系统) | 3.0.1 | [站点](https://repo.huaweicloud.com/harmonyos/os/3.0.1/code-v3.0.1-LTS.tar.gz) | [SHA256校验码](https://repo.huaweicloud.com/harmonyos/os/3.0.1/code-v3.0.1-LTS.tar.gz.sha256) | -| 标准系统解决方案(二进制) | 3.0.1 | [站点](https://repo.huaweicloud.com/harmonyos/os/3.0.1/standard.tar.gz) | [SHA256校验码](https://repo.huaweicloud.com/harmonyos/os/3.0.1/standard.tar.gz.sha256) | -| Hi3861解决方案(二进制) | 3.0.1 | [站点](https://repo.huaweicloud.com/harmonyos/os/3.0.1/hispark_pegasus.tar.gz) | [SHA256校验码](https://repo.huaweicloud.com/harmonyos/os/3.0.1/hispark_pegasus.tar.gz.sha256) | -| Hi3518解决方案(二进制) | 3.0.1 | [站点](https://repo.huaweicloud.com/harmonyos/os/3.0.1/hispark_aries.tar.gz) | [SHA256校验码](https://repo.huaweicloud.com/harmonyos/os/3.0.1/hispark_aries.tar.gz.sha256) | -| Hi3516解决方案-LiteOS(二进制) | 3.0.1 | [站点](https://repo.huaweicloud.com/harmonyos/os/3.0.1/hispark_taurus.tar.gz) | [SHA256校验码](https://repo.huaweicloud.com/harmonyos/os/3.0.1/hispark_taurus.tar.gz.sha256) | -| Hi3516解决方案-Linux(二进制) | 3.0.1 | [站点](https://repo.huaweicloud.com/harmonyos/os/3.0.1/hispark_taurus_linux.tar.gz) | [SHA256校验码](https://repo.huaweicloud.com/harmonyos/os/3.0.1/hispark_taurus_linux.tar.gz.sha256) | - - - -## 更新说明 - -本版本在OpenHarmony v3.0 LTS的基础上有如下变更。 - - -### 特性变更 - -当前维护版本不涉及新需求及新特性的接纳与变更。 - - -### API变更 - -此版本不涉及API变更。 - - -### 芯片及开发板适配 - -芯片及开发板适配状态请参考[SIG-Devboard](https://gitee.com/openharmony/community/blob/master/sig/sig-devboard/sig_devboard_cn.md)信息。 - - -## 修复缺陷列表 - -**表3** 轻量和小型系统解决的缺陷ISSUE列表 - -| ISSUE单号 | 问题描述 | -| -------- | -------- | -| [I4BJFU](https://gitee.com/openharmony/kernel_liteos_a/issues/I4BJFU) | dyload_posix模块在removefile的时候出现错误 | -| [I42N33](https://gitee.com/openharmony/third_party_mksh/issues/I42N33) | 集成测试直接执行cat后无法退出,需要重启设备恢复 | -| [I4C8BO](https://gitee.com/openharmony/docs/issues/I4C8BO?from=project-issue) | 3516DV300/3518EV300 使用官网烧写配置媒体子系统(轻量小型)基本功能异常 | -| [I4BWKC](https://gitee.com/openharmony/drivers_framework/issues/I4BWKC) | 3516DV300单板camera驱动压测问题 | -| [I4BW0G](https://gitee.com/openharmony/drivers_framework/issues/I4BW0G) | 3516DV300单板ResetDriver接口失败 | -| [I4C7ZK](https://gitee.com/openharmony/multimedia_camera_lite/issues/I4C7ZK) | HI3516DV300 小型系统常驻内存超基线 | -| [I434P1](https://gitee.com/openharmony/multimedia_camera_lite/issues/I434P1) | HI3518EV300常驻内存超基线 | -| [I48IM7](https://gitee.com/openharmony/hiviewdfx_hilog/issues/I48IM7) | 运行hilog的压测,hilogd异常重启,且hilog命令一直无法使用 | -| [I4EGMD](https://gitee.com/openharmony/aafwk_aafwk_lite/issues/I4EGMD) | 修改want的序列化和反序列化方法 | -| [I4CED3](https://gitee.com/openharmony/account_os_account/issues/I4CED3) | 修复JS API接口返回只有一个内容的问题 | -| [I4BXZ1](https://gitee.com/openharmony/app_samples/issues/I4BXZ1) | 修复[ Picker] 组件点击无响应问题 | -| [I4CMMH](https://gitee.com/openharmony/ace_ace_engine/issues/I4CMMH) | 解决toggle显示异常问题 | -| [I4CE7D](https://gitee.com/openharmony/miscservices_inputmethod/issues/I4CE7D) | 优化编辑框响应时间 | -| [I4HI4C](https://gitee.com/openharmony/ai_engine/issues/I4HI4C) | 解决小型系统TDD 用例失败问题,调整用例比较时间范围 | -| [I4EUOW](https://gitee.com/openharmony/ai_engine/issues/I4EUOW) | 更改用例执行线程数 | -| [I4HTFS](https://gitee.com/openharmony/appexecfwk_appexecfwk_lite/issues/I4HTFS) | 轻量系统bms适配 | -| [I4C3BE](https://gitee.com/openharmony/communication_dsoftbus/issues/I4C3BE) | 修复了BLE被动发现频繁更新蓝牙广播,导致蓝牙资源消耗完自动关闭的问题 | -| [I4I7QL](https://gitee.com/openharmony/developtools_packing_tool/issues/I4I7QL) | 修复一个ability有2张卡片的时候打包报错问题 | -| [I4BW0G](https://gitee.com/openharmony/drivers_framework/issues/I4BW0G) | 解决WiFi ResetDriver概率性失败问题 | -| [I4GBB6](https://gitee.com/openharmony/device_qemu/issues/I4GBB6) | 修复risc-v qemu模拟器运行系统异常问题 | -| [I4CE7E](https://gitee.com/openharmony/kernel_liteos_a/issues/I4CE7E) | liteos-a内核drivers/mtd/multi_partition/用到了device/hisilicon下的驱动函数实现 | -| [I4JBEH](https://gitee.com/openharmony/drivers_framework/issues/I4JBEH) | 修复了反复使用HDF的DMA传输接口,发生内存泄漏的问题 | -| [I4IGQ0](https://gitee.com/openharmony/drivers_framework/issues/I4IGQ0) | 解决器件探测失败后导致资源释放问题 | -| [I4JPCG](https://gitee.com/openharmony/drivers_framework/issues/I4JPCG) | 解决pwm背光无法设置0的问题 | -| [I4ERM4](https://gitee.com/openharmony/drivers_peripheral/issues/I4ERM4) | 解决显示用例失败的问题 | -| [I4CMUY](https://gitee.com/openharmony/drivers_adapter_khdf_linux/issues/I4CMUY) | hdf_peripheral_wlan_test_performance.bin测试套执行失败 | -| [I4FIP2](https://gitee.com/openharmony/kernel_liteos_a/issues/I4FIP2) | a核ioctl支持SIOCGIFBRDADDR选项 | -| [I4GVF7](https://gitee.com/openharmony/kernel_liteos_a/issues/I4GVF7) | 修改blackbox生成的文件和文件夹权限 | -| [I4EV8U](https://gitee.com/openharmony/kernel_liteos_a/issues/I4EV8U) | liteos_a_io_unittest.bin\#IoTest模块失败3条用例:IO_TEST_PPOLL_001等 | -| [I4EV3X](https://gitee.com/openharmony/kernel_liteos_a/issues/I4EV3X) | liteos_a_sys_unittest.bin\#SysTest模块失败7条用例:ItTestSys018等 | -| [I4EVG0](https://gitee.com/openharmony/kernel_liteos_a/issues/I4EVG0) | liteos_a_misc_unittest.bin\#MiscTest模块失败1条用例ItTestMisc009 | -| [I4JYAX](https://gitee.com/openharmony/kernel_liteos_a/issues/I4JYAX) | jffs2适配层错误释放锁 | -| [I4FIQW](https://gitee.com/openharmony/kernel_liteos_m/issues/I4FIQW) | liteos_m核ioctl支持SIOCGIFBRDADDR选项 | -| [I4ELVA](https://gitee.com/openharmony/kernel_liteos_m/issues/I4ELVA) | 修复文件系统VFS层read接口未正确判空g_fs的问题 | -| [I4C6P2](https://gitee.com/openharmony/kernel_liteos_m/issues/I4C6P2) | LOS_QueueInfoGet函数统计等待读写任务有误 | -| [I4C5RW](https://gitee.com/openharmony/kernel_liteos_m/issues/I4C5RW) | 开启MPU保护任务栈时,遇到OS_TASK_STACK_PROTECT_SIZE宏未定义的错误 | -| [I4G4VK](https://gitee.com/openharmony/kernel_liteos_m/issues/I4G4VK) | 修改inet_addr等宏为函数,外层调用可不包含lwip头文件 | -| [I4FVGV](https://gitee.com/openharmony/kernel_liteos_m/issues/I4FVGV) | liteos_m核优化lwip默认配置 | -| [I4CE7D](https://gitee.com/openharmony/miscservices_inputmethod/issues/I4CE7D) | 删除延迟3秒拉起输入法 | -| [I4CFOO](https://gitee.com/openharmony/multimedia_media_lite/issues/I4CFOO) | linux多次录像后,不退出应用,重启最后一个录像文件大小为0 | -| [I4CLGW](https://gitee.com/openharmony/kernel_liteos_a/issues/I4CLGW) | pagecache优化 | -| [I4HKQ2](https://gitee.com/openharmony/vendor_hisilicon/issues/I4HKQ2) | 测试轻量系统liteOs 获取udid | -| [I4FVJN](https://gitee.com/openharmony/startup_syspara_lite/issues/I4FVJN) | 轻量系统编译依赖mbedtls,却没有加依赖,导致编译不过 | -| [I4CE7E](https://gitee.com/openharmony/kernel_liteos_a/issues/I4CE7E) | liteos-a内核drivers/mtd/multi_partition/用到了device/hisilicon下的驱动函数实现 | - -**表4** 标准系统解决的缺陷ISSUE列表 - -| ISSUE单号 | 问题描述 | -| -------- | -------- | -| [I4BX4J](https://gitee.com/openharmony/hiviewdfx_hicollie/issues/I4BX4J?from=project-issue) | 3516DV300单板调用hicollie接口失败 | -| [I4BX1X](https://gitee.com/openharmony/hiviewdfx_hitrace/issues/I4BX1X?from=project-issue) | 3516DV300单板调用hitrace接口失败 | -| [I4BVUL](https://gitee.com/openharmony/communication_wifi/issues/I4BVUL?from=project-issue) | 标准系统与手机切换AP场景发现组网成功率低(91%),不达98% | -| [I4BW6E](https://gitee.com/openharmony/security_deviceauth/issues/I4BW6E) | 标准系统与手机_手机侧循环开关网络_30次左右开始组网失败不再成功 | -| [I4BVVW](https://gitee.com/openharmony/communication_dsoftbus/issues/I4BVVW) | 标准系统与手机_L2开关网络自组网成功率97%_失败3次_需分析失败原因 | -| [I48YPH](https://gitee.com/openharmony/security_deviceauth/issues/I48YPH?from=project-issue) | 测试发现和组网性能(循环离网-发现-组网)_110次组网失败3次 | -| [I4492M](https://gitee.com/openharmony/communication_dsoftbus/issues/I4492M) | 组网10分钟自动下线规格,实际测试不准确,耗时多了30s左右 | -| [I44W7U](https://gitee.com/openharmony/graphic_standard/issues/I44W7U?from=project-issue) | SubWindow窗口大小不支持缩放,导致播放Video过程中会盖住进度条 | -| [I480Z1](https://gitee.com/openharmony/communication_dsoftbus/issues/I480Z1?from=project-issue) | Softbus_server在执行socketfuzz时,出现crash | -| [I4BGLS](https://gitee.com/openharmony/security_deviceauth/issues/I4BGLS?from=project-issue) | import_signed_auth_info_hilink导入的key用于HiChain连接时的身份标志,导入后加密存储在文件中,属于敏感数据,在返回后没有从堆中清除 | -| [I4A10Q](https://gitee.com/openharmony/startup_appspawn/issues/I4A10Q?from=project-issue) | 性能测试3516 3.0.0.6静态KPI劣化严重 | -| [I4BXYT](https://gitee.com/openharmony/developtools_hdc_standard/issues/I4BXYT) | hdc_std在设备重启之后,需要hdc_std kill才能重新发现设备 | -| [I4KUTY](https://gitee.com/openharmony/ace_engine_lite/issues/I4KUTY) | 删除无效的结果返回 | -| [I4DMFV](https://gitee.com/openharmony/ark_js_runtime/issues/I4DMFV) | 修复utf16到utf8的转换 | -| [I4HGVM](https://gitee.com/openharmony/communication_dsoftbus/issues/I4HGVM) | 增加标准系统对mbedtls的依赖 | -| [I4DLV2](https://gitee.com/openharmony/drivers_framework/issues/I4DLV2) | 修复HidInfo\*类型导致非法内存访问错误的问题 | -| [I4CIJJ](https://gitee.com/openharmony/third_party_flutter/issues/I4CIJJ) | ArkUI支持GPU渲染 | -| [I4G31Z](https://gitee.com/openharmony/third_party_freetype/issues/I4G31Z) | 字体引擎版本从2.10.1升级到2.10.4 | -| [I4H06M](https://gitee.com/openharmony/third_party_harfbuzz/issues/I4H06M) | OpenType 文本整形引擎版本从2.6.1升级到2.8.1 | -| [I4FS7V](https://gitee.com/openharmony/third_party_lwip/issues/I4FS7V) | 使用LWIP_NETCONN_FULLDUPLEX宏来管控conn->mbox_threads_waiting的初始化 | -| [I43KL7](https://gitee.com/openharmony/graphic_standard/issues/I43KL7) | 修改了合成器支持GPU合成 | - - -## 遗留缺陷列表 - -**表5** 遗留缺陷列表 - -| ISSUE | 问题描述 | 影响 | 计划解决日期 | -| -------- | -------- | -------- | -------- | -| [I4NMXQ](https://gitee.com/openharmony/xts_acts/issues/I4NMXQ?from=project-issue) | 标准系统XTS执行storagefileioperformancejstest和storagefilestabilityjstest测试套无法自动执行 | XTS测试套框架问题,分布式文件子系统自动化x-device无法执行测试套,可以手动执行,对功能无影响 | 2022/1/30 | -| [I4NU92](https://gitee.com/openharmony/communication_wifi/issues/I4NU92) | 轻量系统3516_Linux ActsLwipTest.bin测试套测试存在一条失败项 | 自动化测试用例调用内核读取time_out失败,对通信功能无影响 | 2022/1/15 | -| [I4NTKG](https://gitee.com/openharmony/xts_acts/issues/I4NTKG) | 执行XTS测试套WeekPluralNumberTest出现两条失败项 | 测试套用例问题,不影响实际功能 | 2022/1/15 | -| [I4OWWM](https://gitee.com/openharmony/xts_acts/issues/I4OWWM) | WeekPluralNumbertest模块对应json文件配置的有问题,执行用例时报"required device does not exist"导致UN | json文件配置问题,不影响功能 | 2022/1/15 | -| [I4MSVV](https://gitee.com/openharmony/xts_acts/issues/I4MSVV?from=project-issue) | 标准系统XTS测试执行测试ActsHiCollieCppTest模块HiCollieCppTest用例3条失败项 | 测试套名称变更导致存在文本校验功能的测试用例不通过,对功能无影响 | 2022/1/15 | -| [I4MSWM](https://gitee.com/openharmony/xts_acts/issues/I4MSWM?from=project-issue) | 标准系统XTS测试执行测试ActsFaultLoggerTest模块faultloggertest用例1条失败项 | 测试套名称变更导致存在文本校验功能的测试用例不通过,对功能无影响 | 2022/1/15 | -| [I4NODO](https://gitee.com/openharmony/device_manager/issues/I4NODO) | 标准系统3516分布式业务流转端到端测试失败,无法完成流转 | DM组件_重复创建群组失败,影响使用流转功能(按照isuue中提到的操作步骤)的业务,对其他应用无影响 | 2022/1/30 | diff --git a/website/docs/_posts/zh-cn/release-notes/OpenHarmony-v3.1-beta.md b/website/docs/_posts/zh-cn/release-notes/OpenHarmony-v3.1-beta.md deleted file mode 100644 index 9188e6efa56401c029e09f26d3c516bc51abae52..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/release-notes/OpenHarmony-v3.1-beta.md +++ /dev/null @@ -1,228 +0,0 @@ ---- -title: OpenHarmony-v3.1-beta -permalink: /pages/extra/d61a8a/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# OpenHarmony 3.1 Beta - -- [版本概述](#版本概述) -- [配套关系](#配套关系) -- [源码获取](#源码获取) - - [通过repo获取](#通过repo获取) - - [从镜像站点获取](#从镜像站点获取) -- [更新说明](#更新说明) - - [特性变更](#特性变更) - - [API变更](#api变更) - - [芯片及开发板适配](#芯片及开发板适配) - - [Samples & Codelabs](#samples-amp-codelabs) - - [新增Samples](#新增samples) - - [新增Codelabs](#新增codelabs) -- [修复缺陷列表](#修复缺陷列表) -- [遗留缺陷列表](#遗留缺陷列表) - - -## 版本概述 - -当前版本在OpenHarmony 3.0 LTS的基础上,更新支持了以下能力: - -- 标准系统OS基础能力增强:内核提升CMA利用率特性、图形新增支持RenderService渲染后端引擎、短距离通信支持STA(Station)和SoftAP基础特性、支持地磁场的算法接口、传感器驱动模型能力增强、支持应用帐号信息查询和订阅等、全球化特性支持、编译构建支持统一的构建模板、编译运行时提供Windows/MacOS/Linux的前端编译工具链、JS运行时支持预览器、新增支持JSON处理、Eventbus、Vcard、Protobuf、RxJS、LibphoneNumber等6个JS三方库、新增时间时区管理、DFX新增支持HiSysEvent部件提供查询和订阅接口。 - -- 标准系统分布式能力增强:包括新增支持分布式DeviceProfile特性、分布式数据管理支持跨设备同步和订阅、分布式软总线支持网络切换组网、分布式文件系统支持Statfs API能力等。 - -- 标准系统应用程序框架能力增强:新增ArkUI自定义绘制能力和Lottie动画能力、新增包管理探秘隐式查询和多hap包安装、事件通知支持权限管理、设置通知振动、通知声音设置和查询、通知免打扰、会话类通知等。 - -- 标准系统应用能力增强:输入法应用支持文本输入和横屏下布局显示、短信应用信息管理、联系人应用通话记录和拨号盘显示、设置应用更多设置项。 - -- 轻量系统能力增强:HiStreamer轻量级支持可定制的媒体管线框架、Linux版本init支持热插拔、OS轻内核&驱动启动优化、快速启动能力支持。 - - -## 配套关系 - -**表1** 版本软件和工具配套关系 - -| 软件 | 版本 | 备注 | -| -------- | -------- | -------- | -| OpenHarmony | 3.1 Beta | NA | -| SDK | Ohos_sdk 3.1 Beta  (API Version 8 Beta) | NA | -| HUAWEI DevEco Studio(可选) | 3.0 Beta2 | OpenHarmony应用开发推荐使用。 | -| HUAWEI DevEco Device Tool(可选) | 3.0 Beta2 | OpenHarmony智能设备集成开发环境推荐使用。 | - - -## 源码获取 - - -### 通过repo获取 - -**方式一(推荐)** - -通过repo + ssh 下载(需注册公钥,请参考[码云帮助中心](https://gitee.com/help/articles/4191))。 - -``` -repo init -u git@gitee.com:openharmony/manifest.git -b refs/tags/OpenHarmony-v3.1-Beta --no-repo-verify -repo sync -c -repo forall -c 'git lfs pull' -``` - -**方式二** - -通过repo + https 下载。 - -``` -repo init -u https://gitee.com/openharmony/manifest.git -b refs/tags/OpenHarmony-v3.1-Beta --no-repo-verify -repo sync -c -repo forall -c 'git lfs pull' -``` - -### 从镜像站点获取 - -**表2** 获取源码路径 - -| 版本源码 | **版本信息** | **下载站点** | **SHA256校验码** | -| -------------------------------- | ------------ | ------------ | ---------------- | -| 全量代码(标准、轻量和小型系统) | 3.1 Beta | [站点](https://repo.huaweicloud.com/harmonyos/os/3.1-Beta/code-v3.1-Beta.tar.gz) | [SHA256校验码](https://repo.huaweicloud.com/harmonyos/os/3.1-Beta/code-v3.1-Beta.tar.gz.sha256) | -| Hi3516标准系统解决方案(二进制) | 3.1 Beta | [站点](https://repo.huaweicloud.com/harmonyos/os/3.1-Beta/standard_hi3516.tar.gz) | [SHA256校验码](https://repo.huaweicloud.com/harmonyos/os/3.1-Beta/standard_hi3516.tar.gz.sha256) | -| RK3568标准系统解决方案(二进制) | 3.1 Beta | [站点](https://repo.huaweicloud.com/harmonyos/os/3.1-Beta/standard_rk3568.tar.gz) | [SHA256校验码](https://repo.huaweicloud.com/harmonyos/os/3.1-Beta/standard_rk3568.tar.gz.sha256) | -| Hi3861轻量系统解决方案(二进制) | 3.1 Beta | [站点](https://repo.huaweicloud.com/harmonyos/os/3.1-Beta/hispark_pegasus.tar.gz) | [SHA256校验码](https://repo.huaweicloud.com/harmonyos/os/3.1-Beta/hispark_pegasus.tar.gz.sha256) | -| Hi3516轻量系统解决方案-LiteOS(二进制) | 3.1 Beta | [站点](https://repo.huaweicloud.com/harmonyos/os/3.1-Beta/hispark_taurus.tar.gz) | [SHA256校验码](https://repo.huaweicloud.com/harmonyos/os/3.1-Beta/hispark_taurus.tar.gz.sha256) | -| Hi3516轻量系统解决方案-Linux(二进制) | 3.1 Beta | [站点](https://repo.huaweicloud.com/harmonyos/os/3.1-Beta/hispark_taurus_linux.tar.gz) | [SHA256校验码](https://repo.huaweicloud.com/harmonyos/os/3.1-Beta/hispark_taurus_linux.tar.gz.sha256) | -| 标准系统SDK包(Mac) | 3.1 Beta | [站点](https://repo.huaweicloud.com/harmonyos/os/3.1-Beta/ohos-sdk-mac.tar.gz) | [SHA256校验码](https://repo.huaweicloud.com/harmonyos/os/3.1-Beta/ohos-sdk-mac.tar.gz.sha256) | -| 标准系统SDK包(Windows\Linux) | 3.1 Beta | [站点](https://repo.huaweicloud.com/harmonyos/os/3.1-Beta/ohos-sdk.tar.gz) | [SHA256校验码](https://repo.huaweicloud.com/harmonyos/os/3.1-Beta/ohos-sdk.tar.gz.sha256) | -| 编译工具链获取清单 | - | [站点](https://repo.huaweicloud.com/harmonyos/os/2.0/tool_chain/) | | - - -## 更新说明 - -本版本在OpenHarmony 3.0 LTS的基础上有如下变更。 - - -### 特性变更 - -**表3** 版本新增特性表 - -| 子系统名称 | 标准系统 | 轻量、小型系统 | -| -------- | -------- | -------- | -| 包管理子系统 | - I4MBSE:提供桌面包管理客户端
- I4MBSF:支持缓存清除能力
- I4MBSG:支持安装包信息查询
- I4MBSD:支持多hap包安装
- I4MBSH:支持多hap安装的签名校验
- I4MBSC:支持Module和Ability的srcPath字段 | NA | -| 分布式任务调度子系统 | -I4MBRW:SAMGR新增服务进程内的System Ability名单管控
-I4MBRV:SAMGR新增系统服务状态列表维护
-I4MBRZ:SAMGR新增全量服务列表初始化
-I4MBRY:SAMGR新增系统服务进程状态列表维护
-I4MBRX:SAMGR新增加载指定系统服务 | NA | -| DeviceProfile子系统 | -I4NY23:本地设备Profile的插入、删除、查询
-I4NY1X:远程设备Profile的查询
-I4NY1T:订阅远程Profile变化的通知
-I4NY1W:跨设备同步Profile | NA | -| 帐号子系统 | -I4MBQW:支持应用帐号的新增和删除
-I4MBQV:应用帐号基础信息约束
-I4MBQU:支持应用帐号订阅及取消订阅
-I4MBQT:支持应用帐号功能设置与内容修改
-I4MBQS:支持应用帐号信息查询
-I4IT3U:支持应用帐号基础信息管理 | NA | -| 泛sensor服务子系统 | -I3NJ96:加速度传感器数据上报
-I3NJ8H:陀螺仪传感器数据上报
-I3NJ7J:环境光传感器数据上报
-I3NJ76:磁力计传感器数据上报
-I4MBRP:地磁场偏角和倾角
-I4MBRQ:地磁场水平强度、总强度 | NA | -| USB服务子系统 | I410OZ:
- 查询已连接的USB设备列表
- 获取USB设备临时访问权限
- 设置USB设备配置、接口
- 与USB设备进行数据传输 | NA | -| 语言编译器运行时子系统 | - I4MBUK:JavaScript/TypeScript默认运行时从quickjs替换为方舟运行时。
- I4MBUJ:方舟运行时内存回收功能增强,支持并发标记算法以及并发压缩算法,支持选择部分region进行压缩GC(Partial CompressionGC),优化GC pause time减少30%。 | NA | -| 全球化子系统 | - 支持国际化特性:单复数规则、字符串排序、电话号码处理、日历&本地历法、度量衡体系和格式化、区域表示和属性、时间段格式化、字母表检索、unicode字符属性、断词换行
- 支持系统资源、rawfile资源 | NA | -| 分布式软总线子系统 | -I4FZ29:软总线提供传输ExtAPI接口
-I4FZ25:软总线支持网络切换组网 | -I4FZ29:软总线提供传输ExtAPI接口
-I4FZ25:软总线支持网络切换组网 | -| 启动子系统 | NA | -I3XGJH:init基础环境构建
-I3XGKV:system parameter管理
-I3XGLN:init 脚本管理
-I3XGMQ:基础权限管理
-I3XGN8:bootimage构建和加载
-I3XGKV:uevent 管理
-I3XGNM:烧写模式支持 | -| 媒体子系统 | NA | -I4BX5Z:HiStreamer支持音频播放和控制
-I4BX8A:HiStreamer支持常见音频格式mp3/wav的播放
-I4BX9E:HiStreamer播放引擎框架需求
-I4DK89:HiStreamer插件框架需求
-I4DK8D:HiStreamer性能和DFX需求 | -| 图形子系统 | 全新设计OpenHarmony 图形栈:
新增UI框架渲染后端特性支持
新增ArkUI控件接入RenderService渲染后端 | NA | -| 内核子系统 | 内核(Linux 5.10)
-I4LUG4 CMA内存区域复用(目前仅支持Hi3516DV300,暂不支持RK平台)
-I4LX4G 支持anonymous vma命名(目前仅支持Hi3516DV300,暂不支持RK平台) | -I3ND6Y:【性能】OS内核&驱动启动优化 | -| 启动恢复子系统 | NA | -I3NTCT:Linux版本init支持热插拔 | -| 分布式数据对象管理子系统 | NA | -I4H3JJ:分布式对象支持小型系统设备 | -| 电话子系统 | NA | -I4JQ2N:提供Http JS API
-I4JQ3G:提供Http 2.0协议 | -| Misc软件服务子系统 | I4MBQE:
支持应用读取时间
支持应用读取时区
支持时间修改通知
支持时区修改通知
支持分钟变化通知 | NA | -| 编译构建子系统 | I4K7E3:支持使用统一的编译命令作为编译入口
- I4KCNB:支持使用统一的gn模板 | -I4MBQN:支持统一的编译入口、支持使用build.sh编译轻量、小型系统
-I4MBQP:支持统一的编译流程
-I4MBQR:支持统一的产品配置 | -| 文件存储子系统 | -I4MBS2:statfs获取设备总空间与剩余空间JS接口 | NA | -| 驱动子系统 | -I4L3KK:传感器器件驱动能力增强,支持传感器采样率动态配置,三轴方向静态可配置,环境光增益调节。
-I4L3LF:传感器驱动模型能力增强,支持传感器HDI跨进程服务获取和调用。
-I4MBTS:HDF-Input设备能力丰富,支持摇杆设备数据上报。
-I4MBTR:Display HDI接口针对标准系统的参考实现,针对DRM显示架构,提供针对标准系统的Display HDI默认参考实现,有助于厂商参考适配HDI。
-I4HPR7:提供hcs宏式解析机制,编译时使用hc-gen工具把驱动的配置参数解析为宏定义参数,驱动通过hcs宏格式的接口访问宏定义参数。
-I4KVJQ:支持linux/liteos内核系统级休眠唤醒。
-I4L3ZZF:支持同步/异步电源管理调用,提供同步/异步的管理HDF设备进入休眠或者被唤醒的机制。 | -I4L3KK:传感器器件驱动能力增强,支持传感器采样率动态配置,三轴方向静态可配置,环境光增益调节。
-HDF-Input设备能力丰富(linux系统),支持摇杆设备数据上报。
-I4HPR7:提供hcs宏式解析机制,编译时使用hc-gen工具把驱动的配置参数解析为宏定义参数,驱动通过hcs宏格式的接口访问宏定义参数。
-I4KVJQ:支持linux/liteos内核系统级休眠唤醒。
-I4L3ZZF:支持同步/异步电源管理调用,提供同步/异步的管理HDF设备进入休眠或者被唤醒的机制。 | -| ArkUI子系统 | - I4MBUY:事件中增加Target获取尺寸
- I4MBUZ:Swiper组件支持设置缓存cache
- I4MBV1:Image组件支持同步、异步渲染设置
- I4MBV3:样式设置特性增加组件多态样式设置
- I4MBV5:字母索引条组件增加提示菜单内容扩展
- I4MBV6:组件自定义特性增加自定义容器组件规格
- I4MBV7:滚动条样式自定义能力
- I4MBV8:Swiper组件新增切换禁用规格
- I4MBV9:Tabs组件新增TabBar内容自定义规格
- I4MBVA:Navigation组件新增标题栏设置规格
- I4MBVB:工具栏组件增加工具栏显隐控制规格
- I4MBVC:工具栏组件增加内容自定义能力规格
- I4MBVD:新增SysCap声明编译特性
- I4MBVE:新增JSSDK编译特性
- I4MBVF:新增Config.json编译特性
- I4MBVG:新增断点调试特性支持单实例调试
- I4MBVH:新增attach调试特性支持单实例调试
- I4MBVI:新增声明式范式编译特性支持编译和校验规格
- I4MBVJ:新增JS模块共享编译特性
- I4MBVK:新增HAR引用和编译特性
- I4MBVL:新增NPM引用和编译特性、
- I4MBVN:纵向显示滑动条组件特性
- I4MBVO:Popup组件增加内容自定义规格
- I4MBVP:Canvas绘制能力支持
- I4MBVQ:Canvas能力增强
- I4MBVR:触摸响应热区设置
- I4MBVS:Lottie动画支持
- I4MBVT:组件尺寸获取特性
- I4MBVU:Menu组件增加内容自定义规格
- I4MBVV:Swipe手势特性
- I4MBVW:UI预览支持Inspector能力
- I4MBVX:新增非路由文件预览特性
- I4MBVY:新增NAPI预览特性
- I4MBVZ:新增声明式范式预览特性。支持基础预览规格
- I4MBW2:新增声明式范式热加载特性,支持已有节点修改规格
- I4MBW3:新增声明式范式热加载特性,支持新增节点规格
- I4MBW4:新增声明式范式热加载特性,支持删除节点规格
- I4MBW5:新增组件预览特性,支持页面组件预览规格
通用属性新增点击控制 touchable:设置组件是否可以被触摸。
基础组件新增Marquee:跑马灯组件。
基础组件新增Gauge:数据量规图表组件。
基础组件新增TextArea:多行文本输入组件。
基础组件新增TextInput:单行文本输入组件。
基础组件新增Toggle:状态组件。
容器组件新增Stepper:步骤导航器组件。
容器组件新增StepperItem:步骤导航器导航项组件。
新增全局UI方法ActionSheet:列表选择弹窗。 | NA | -| DFX子系统 | -I4MBQH:支持HiSysEvent部件,提供查询、订阅接口
-I4MBQJ:提供工具查询或者订阅系统事件
-I4MBQL:支持Hiappevent部件的C接口 | NA | -| 应用子系统 | -I4MBU1:支持Settings数据管理API
-I4MBU3:支持时间设置
- I4MBU5:支持声音管理
-I4MBU6:支持Settings数据管理
-I4MBU7:支持Settings数据默认值管理
-I4MBU8:支持Settings多设备形态差异化构建
-I4MBU9:通知组件化 | NA | - - -### API变更 - -API变更请参考: - -_[JS API 差异报告](/pages/extra/38355d/)_ - -_[Native API差异报告](/pages/extra/abff2d/)_ - -_[Changelog](/pages/extra/15af11/)_ - - -### 芯片及开发板适配 - -芯片及开发板适配状态请参考[SIG-Devboard](https://gitee.com/openharmony/community/blob/master/sig/sig-devboard/sig_devboard_cn.md)信息。 - - -### Samples & Codelabs - - -#### 新增Samples - -**表4** Samples列表 - -| 名称 | 简介 | 开发语言 | -| -------- | -------- | -------- | -| [Ets公共事件](https://gitee.com/openharmony/app_samples/tree/master/ability/EtsCommonEvent) | 本示例展示了在eTS中如何使用CommonEvent的接口完成创建订阅者、订阅公共事件、发布公共事件、取消订阅的功能。 | eTS | -| [空气质量](https://gitee.com/openharmony/app_samples/tree/master/common/AirQuality) | 本示例使用JS实现了一个简单空气质量应用,使用折行显示能力显示空气质量信息,使用柱形图展示历史记录。 | JS | -| [分布式计算器](https://gitee.com/openharmony/app_samples/tree/master/common/DistributeCalc) | 本示例使用JS分布式能力实现了一个简单的计算器应用,可以进行简单的数值计算,支持远程拉起另一个计算器FA,两个FA进行协同计算。 | JS | -| [EtsNotification](https://gitee.com/openharmony/app_samples/tree/master/common/EtsNotification) | 本示例展示了在eTS中如何创建和删除Slot通道,如何发布和取消通知。 | eTS | -| [Ets资源管理](https://gitee.com/openharmony/app_samples/tree/master/common/EtsResourceManager) | 本示例展示了在eTS中如何调用资源管理的API接口实现字符串和图片资源信息的获取。 | eTS | -| [kikainput](https://gitee.com/openharmony/app_samples/tree/master/CompleteApps/KikaInput) | kikainput是一个轻量级的输入法应用,支持在运行OpenHarmony OS的智能终端上。 | JS | -| [eTS分布式数据管理](https://gitee.com/openharmony/app_samples/tree/master/data/eTSKvStore) | 本示例展示了在eTS中分布式数据管理的使用,包括KVManager对象实例的创建和KVStore数据流转的使用。 | eTS | -| [轻量级数据存储](https://gitee.com/openharmony/app_samples/tree/master/data/eTSLiteStorage) | 轻量级数据存储主要提供轻量级Key-Value操作,支持本地应用存储少量数据。本示例通过对购物车商品的添加和删除并保存退出的操作,使得再次打开应用时依然可以保留退出前的购物车信息,体现了轻量级存储在保存轻量级数据时的作用。 | eTS | -| [Ets进程信息](https://gitee.com/openharmony/app_samples/tree/master/ETSUI/EtsProcess) | 本示例展示了在eTS中如何获取进程信息和启动一个子进程运行一段shell,包括当前系统运行时间、获取进程当前工作目录、更改进程当前工作目录、发送signal到指定的进程、启动一个子进程、关闭子进程、退出当前系统的功能。 | eTS | -| [Ets运行锁](https://gitee.com/openharmony/app_samples/tree/master/ETSUI/eTSRunninglock) | 本示例展示了阻止系统休眠的运行锁功能,通过黑白色壁纸模拟息屏、亮屏状态,来展示系统的休眠状态,从而对运行锁的功能进行测试,使得该运行锁在打开后可以阻止系统休眠。 | eTS | -| [字符串编解码](https://gitee.com/openharmony/app_samples/tree/master/ETSUI/StringCodec) | 本示例对字符串进行了特定格式的输出,对错误码的内容进行了文本输出,对字符串的编码和解码做了演示结果。 | eTS | -| [Js音频播放和管理](https://gitee.com/openharmony/app_samples/tree/master/media/JsAudioPlayer) | 本示例展示了JS音频播放的使用方法,以及音频的音量大小设置。 | JS | -| [JsVideo](https://gitee.com/openharmony/app_samples/tree/master/media/JsVideo) | 本示例使用JS UI中的<video/>组件,实现视频播放。可以通过video自带的控制栏进行播放、暂停等操作。 | JS | -| [测试打点](https://gitee.com/openharmony/app_samples/tree/master/security/JsDotTest) | 本示例展示了测试打点功能,包括应用打点与性能打点两部分。 | JS | -| [JsWorker](https://gitee.com/openharmony/app_samples/tree/master/thread/JsWorker) | 本示例展示了在JS中如何启动一个worker线程,并实现worker线程和宿主线程的通信。 | JS | -| [画布组件](https://gitee.com/openharmony/app_samples/tree/master/UI/JsCanvas) | <canvas/>组件可以自定义绘制图形,本示例展示了<canvas\>组件的使用方法 | JS | -| [JS页面弹窗](https://gitee.com/openharmony/app_samples/tree/master/UI/JsDialog) | JS中支持用户自定义弹窗,<dialog/>组件作为容器组件,用户可以自定义弹窗的样式和布局。本示例完成了添加和删除联系人功能,在添加和删除时使用自定义弹窗来实现。 | JS | -| [JSList商品列表](https://gitee.com/openharmony/app_samples/tree/master/UI/JsList) | 本示例展示了list控件在商品分类列表中的应用,在listGroup里采用两个list-item分别展示了Group收缩和Group展开的两种列表形态,点击后会弹出相应的list列表。 | JS | -| [JSPanel](https://gitee.com/openharmony/app_samples/tree/master/UI/JsPanel) | JS提供一种轻量级的内容展示面板,此面板可滑动,可自定义触发方式、弹出高度等属性。本示例通过可滑动面板展示了商品详细信息与平台保障。 | JS | -| [JsSvg](https://gitee.com/openharmony/app_samples/tree/master/UI/JsSvg) | 本示例展示了JS中组件及其子组件的使用,包括 。 | JS | -| [JS自定义组件](https://gitee.com/openharmony/app_samples/tree/master/UI/JSUICustomComponent) | 自定义组件是用户根据业务需求,将已有的组件组合,封装成的新组件,可以在工程中多次调用,提高代码的可读性。本示例展示了JS中自定义组件的使用,包括基本用法、自定义事件、Props和事件参数。 | JS | - - -#### 新增Codelabs - -**表5** Codelabs列表 - -| 名称 | 简介 | 开发语言 | -| -------- | -------- | -------- | -| [分布式手写板(eTS)](https://gitee.com/openharmony/codelabs/tree/master/Distributed/DistributeDatabaseDrawEts) | 基于分布式能力,实现多设备同步书写互动。 | eTS | -| [分布式数据库](https://gitee.com/openharmony/codelabs/tree/master/Data/JsDistributedData) | 基于分布式数据接口,实现多种设备上一致的数据访问体验。 | JS | -| [关系型数据库](https://gitee.com/openharmony/codelabs/tree/master/Data/JSRelationshipData) | 基于关系型数据库和数据管理能力,实现数据库相关应用服务的快速开发。 | JS | -| [极简声明式UI范式(eTS)](https://gitee.com/openharmony/codelabs/tree/master/ETSUI/SimpleGalleryEts) | 基于OpenHarmony eTS UI,实现一个图库应用。 | eTS | -| [一次开发多端部署(eTS)](https://gitee.com/openharmony/codelabs/tree/master/ETSUI/MultiDeploymentEts) | 基于OpenHarmony eTS UI,实现一次布局,多端部署。 | eTS | -| [购物应用(eTS)](https://gitee.com/openharmony/codelabs/tree/master/ETSUI/ShoppingEts) | 基于OpenHarmony eTS UI丰富的组件实现购物商城应用。 | eTS | -| [Page内和Page间导航跳转](https://gitee.com/openharmony/codelabs/tree/master/Ability/PageAbility) | 入门教程,学习如何完成Page内和Page间的页面导航跳转。 | eTS | -| [转场动画的使用(eTS)](https://gitee.com/openharmony/codelabs/tree/master/ETSUI/TransitionAnimtaionEts) | 基于OpenHarmony eTS UI转场动画,实现了页面间转场、组件内转场以及共享元素转场。 | eTS | -| [基础组件Slider的使用(eTS)](https://gitee.com/openharmony/codelabs/tree/master/ETSUI/SliderApplicationEts) | 基于OpenHarmony eTS UI,使用slider组件,实现可调节风车大小和转速的动画效果。 | eTS | -| [流式布局(eTS)](https://gitee.com/openharmony/codelabs/tree/master/ETSUI/FlowLayoutEts) | 基于OpenHarmony eTS UI,实现流式布局效果。 | eTS | -| [弹窗(eTS)](https://gitee.com/openharmony/codelabs/tree/master/ETSUI/CustomDialogEts) | 基于OpenHarmony eTS UI,实现警告弹窗和自定义弹窗。 | eTS | - - -## 修复缺陷列表 - -**表6** 修复缺陷ISSUE列表 - -| ISSUE单号 | 问题描述 | -| -------- | -------- | -| [I48IM7](https://gitee.com/openharmony/hiviewdfx_hilog/issues/I48IM7) | 运行hilog压力测试,hilogd异常重启,且hilog命令一直无法使用。 | -| [I48YPH](https://gitee.com/openharmony/security_deviceauth/issues/I48YPH) | 【软总线-组网】测试发现和组网性能(循环离网-发现-组网)110次组网失败3次。 | -| [I4BVVW](https://gitee.com/openharmony/communication_dsoftbus/issues/I4BVVW) | 【软总线-组网】标准系统与手机开关网络自组网成功率97%失败3次需分析失败原因。 | -| [I4BXY1](https://gitee.com/openharmony/multimedia_camera_standard/issues/I4BXY1) | 视频录制后前几秒没声音,播放声画不同步,在板子播放会卡顿,音源较远时,有杂音。 | -| [3ZJ1D](https://gitee.com/openharmony/kernel_liteos_a/issues/I3ZJ1D) | XTS权限用例压测用户态概率失败。 | - - -## 遗留缺陷列表 - -**表7** 遗留缺陷列表 - -| ISSUE | 问题描述 | 影响 | 计划解决日期 | -| -------- | -------- | -------- | -------- | -| [I4NRS5](https://gitee.com/openharmony/kernel_linux_5.10/issues/I4NRS5) | 【内核子系统】存在cve漏洞 | Linux内核还未发布补丁,暂时挂起,待社区发布补丁后升级同步。 | 待社区发布补丁 | -| [I4MGJM](https://gitee.com/openharmony/drivers_peripheral/issues/I4MGJM) | 【hdf/camera】RK3568单板跑camera HDI用例失败 | 拍照和预览正常,可以正常录像,点击结束按钮,不能结束。 | 2021/12/31 | -| [I4OECR](https://gitee.com/openharmony/ark_js_runtime/issues/I4OECR) | XTS运行报ark异常栈(低概率问题) | XTS压力测试低概率偶现(48小时出现1次),仅Log中上报异常栈,对功能无影响。 | 2022/1/5 | -| [I4OBTW](https://gitee.com/openharmony/aafwk_standard/issues/I4OBTW) | 全量执行XTS用例,安装应用后出现批量aa start 失败,影响社区流水线稳定性测试 | XTS压力测试,短时间内批量安装100个应用包,低概率(2个/100个)出现应用无法启动。用户使用无影响。 | 2022/1/5 | -| [I4OLHF](https://gitee.com/openharmony/ark_js_runtime/issues/I4OLHF?from=project-issue) | 【Ark子系统】 由进程com.amsst.amsMissionSnapshotTest导致测试进程异常 | 低概率、偶现,高压力测试偶现问题。 | 2022/1/5 | -| [I4OLUK](https://gitee.com/openharmony/ark_js_runtime/issues/I4OLUK) | 【Ark子系统】 由进程com.ohos.systemui导致进程栈异常 | 低概率、偶现,高压力测试偶现问题。 | 2022/1/5 | diff --git a/website/docs/_posts/zh-cn/release-notes/api-change/v2.2-beta2/js-apidiff-v2.2-beta2.md b/website/docs/_posts/zh-cn/release-notes/api-change/v2.2-beta2/js-apidiff-v2.2-beta2.md deleted file mode 100644 index 52a1f58e2a270bb2085a090efd83751422144a2d..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/release-notes/api-change/v2.2-beta2/js-apidiff-v2.2-beta2.md +++ /dev/null @@ -1,247 +0,0 @@ ---- -title: js-apidiff-v2.2-beta2 -permalink: /pages/extra/3ce8d3/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# JS API 差异报告 -OpenHarmony 2.2 Beta2相较于OpenHarmony 2.0 Canary版本的API变更如下: -## 标准系统接口变更 - -| 模块名称 | 接口名称 | 变更类型 | 变更说明 | -| -------- | -------- | -------- | -------- | - | 时间日期数字模块-Locale | constructor(locale: string, options?:options) | 新增 | - | - | 时间日期数字模块-Locale | toString(): string | 新增 | - | - | 时间日期数字模块-Locale | maximize(): Locale | 新增 | - | - | 时间日期数字模块-Locale | minimize(): Locale | 新增 | - | - | 时间日期数字模块-Locale | calendar | 新增 | - | - | 时间日期数字模块-Locale | caseFirst | 新增 | - | - | 时间日期数字模块-Locale | collation | 新增 | - | - | 时间日期数字模块-Locale | hourCycle | 新增 | - | - | 时间日期数字模块-Locale | numberingSystem | 新增 | - | - | 时间日期数字模块-Locale | numeric | 新增 | - | - | 时间日期数字模块-Locale | language | 新增 | - | - | 时间日期数字模块-Locale | script | 新增 | - | - | 时间日期数字模块-Locale | region | 新增 | - | - | 时间日期数字模块-Locale | baseName | 新增 | - | - | 时间日期数字模块-DateTimeFormat | constructor(locale: string, options?:options) | 新增 | - | - | 时间日期数字模块-DateTimeFormat | constructor(locale: string[], options?:options) | 新增 | - | - | 时间日期数字模块-DateTimeFormat | resolvedOptions(): DateTimeOptions | 新增 | - | - | 时间日期数字模块-DateTimeFormat | format(date: Date): string; | 新增 | - | - | 时间日期数字模块-DateTimeFormat | formatRange(fromDate: Date, toDate: Date): string; | 新增 | - | - | 时间日期数字模块-NumberFormat | constructor(locale: string, options?:options) | 新增 | - | - | 时间日期数字模块-NumberFormat | constructor(locale: string[], options?:options) | 新增 | - | - | 时间日期数字模块-NumberFormat | resolvedOptions(): NumberOptions | 新增 | - | - | 时间日期数字模块-NumberFormat | format(number: number): string; | 新增 | - | - | 时间日期数字模块-DateTimeOptions | locale | 新增 | - | - | 时间日期数字模块-DateTimeOptions | dateStyle | 新增 | - | - | 时间日期数字模块-DateTimeOptions | timeStyle | 新增 | - | - | 时间日期数字模块-DateTimeOptions | calendar | 新增 | - | - | 时间日期数字模块-DateTimeOptions | dayPeriod | 新增 | - | - | 时间日期数字模块-DateTimeOptions | numberingSystem | 新增 | - | - | 时间日期数字模块-DateTimeOptions | localeMatcher | 新增 | - | - | 时间日期数字模块-DateTimeOptions | timeZone | 新增 | - | - | 时间日期数字模块-DateTimeOptions | hour12 | 新增 | - | - | 时间日期数字模块-DateTimeOptions | hourCycle | 新增 | - | - | 时间日期数字模块-DateTimeOptions | formatMatcher | 新增 | - | - | 时间日期数字模块-DateTimeOptions | weekday | 新增 | - | - | 时间日期数字模块-DateTimeOptions | era | 新增 | - | - | 时间日期数字模块-DateTimeOptions | year | 新增 | - | - | 时间日期数字模块-DateTimeOptions | month | 新增 | - | - | 时间日期数字模块-DateTimeOptions | day | 新增 | - | - | 时间日期数字模块-DateTimeOptions | hour | 新增 | - | - | 时间日期数字模块-DateTimeOptions | minute | 新增 | - | - | 时间日期数字模块-DateTimeOptions | second | 新增 | - | - | 时间日期数字模块-DateTimeOptions | timeZoneName | 新增 | - | - | 时间日期数字模块-NumberOptions | locale | 新增 | - | - | 时间日期数字模块-NumberOptions | compactDisplay | 新增 | - | - | 时间日期数字模块-NumberOptions | currency | 新增 | - | - | 时间日期数字模块-NumberOptions | currencyDisplay | 新增 | - | - | 时间日期数字模块-NumberOptions | currencySign | 新增 | - | - | 时间日期数字模块-NumberOptions | localeMatcher | 新增 | - | - | 时间日期数字模块-NumberOptions | notation | 新增 | - | - | 时间日期数字模块-NumberOptions | numberingSystem | 新增 | - | - | 时间日期数字模块-NumberOptions | signDisplay | 新增 | - | - | 时间日期数字模块-NumberOptions | style | 新增 | - | - | 时间日期数字模块-NumberOptions | unit | 新增 | - | - | 时间日期数字模块-NumberOptions | unitDisplay | 新增 | - | - | 时间日期数字模块-NumberOptions | useGrouping | 新增 | - | - | 时间日期数字模块-NumberOptions | minimumIntegerDigits | 新增 | - | - | 时间日期数字模块-NumberOptions | minimumFractionDigits | 新增 | - | - | 时间日期数字模块-NumberOptions | maximumFractionDigits | 新增 | - | - | 时间日期数字模块-NumberOptions | minimumSignificantDigits | 新增 | - | - | 时间日期数字模块-NumberOptions | maximumSignificantDigits | 新增 | - | -|文件存储- system.file|mkdir|新增|-| -|文件存储- system.file|rmdir|新增|-| -|文件存储- system.file|get|新增|-| -|文件存储- system.file|list|新增|-| -|文件存储- system.file|copy|新增|-| -|文件存储- system.file|move|新增|-| -|文件存储- system.file|delete|新增|-| -|文件存储- system.file|access|新增|-| -|文件存储- system.file|writeText|新增|-| -|文件存储- system.file|writeArrayBuffer|新增|-| -|文件存储- system.file|readText|新增|-| -|文件存储- system.file|readArrayBuffer|新增|-| -|文件存储- fileio|Dir.readSync|新增|-| -|文件存储- fileio|Dir.closeSync|新增|-| -|文件存储- fileio|dirent.name|新增|-| -|文件存储- fileio|dirent.isBlockDevice()|新增|-| -|文件存储- fileio|dirent.isCharacterDevice()|新增|-| -|文件存储- fileio|dirent.isDirectory()|新增|-| -|文件存储- fileio|dirent.isFIFO()|新增|-| -|文件存储- fileio|dirent.isFile()|新增|-| -|文件存储- fileio|dirent.isSocket()|新增|-| -|文件存储- fileio|dirent.isSymbolicLink()|新增|-| -|文件存储- fileio|stat.dev|新增|-| -|文件存储- fileio|stat.ino|新增|-| -|文件存储- fileio|stat.mode|新增|-| -|文件存储- fileio|stat.nlink|新增|-| -|文件存储- fileio|stat.uid|新增|-| -|文件存储- fileio|stat.gid|新增|-| -|文件存储- fileio|stat.rdev|新增|-| -|文件存储- fileio|stat.size|新增|-| -|文件存储- fileio|stat.blocks|新增|-| -|文件存储- fileio|stat.atime|新增|-| -|文件存储- fileio|stat.mtime|新增|-| -|文件存储- fileio|stat.ctime|新增|-| -|文件存储- fileio|stat.isBlockDevice()|新增|-| -|文件存储- fileio|stat.isCharacterDevice()|新增|-| -|文件存储- fileio|stat.isDirectory()|新增|-| -|文件存储- fileio|stat.isFIFO()|新增|-| -|文件存储- fileio|stat.isFile()|新增|-| -|文件存储- fileio|stat.isSocket()|新增|-| -|文件存储- fileio|stat.isSymbolicLink()|新增|-| -|文件存储- fileio|Stream.flushSync()|新增|-| -|文件存储- fileio|Stream.writeSync()|新增|-| -|文件存储- fileio|Stream.readSync()|新增|-| -|文件存储- fileio|Stream.closeSync()|新增|-| -|文件存储- fileio|fileio.accessSync()|新增|-| -|文件存储- fileio|fileio.chmodSync()|新增|-| -|文件存储- fileio|fileio.chownSync()|新增|-| -|文件存储- fileio|fileio.closeSync()|新增|-| -|文件存储- fileio|fileio.copyFileSync()|新增|-| -|文件存储- fileio|fileio.createStreamSync()|新增|-| -|文件存储- fileio|fileio.fchmodSync()|新增|-| -|文件存储- fileio|fileio.fchownSync()|新增|-| -|文件存储- fileio|fileio.fdopenStreamSync()|新增|-| -|文件存储- fileio|fileio.fstatSync()|新增|-| -|文件存储- fileio|fileio.fsyncSync()|新增|-| -|文件存储- fileio|fileio.ftruncateSync()|新增|-| -|文件存储- fileio|fileio.mkdirSync()|新增|-| -|文件存储- fileio|fileio.openSync()|新增|-| -|文件存储- fileio|fileio.opendirSync()|新增|-| -|文件存储- fileio|fileio.readSync()|新增|-| -|文件存储- fileio|fileio.renameSync()|新增|-| -|文件存储- fileio|fileio.rmdirSync()|新增|-| -|文件存储- fileio|fileio.statSync()|新增|-| -|文件存储- fileio|fileio.truncateSync()|新增|-| -|文件存储- fileio|fileio.unlinkSync()|新增|-| -|文件存储- fileio|fileio.writeSync()|新增|-| -|设备管理-DeviceManager|DeviceInfo|新增|-| -|设备管理-DeviceManager|DeviceType|新增|-| -|设备管理-DeviceManager|DeviceStateChangeAction|新增|-| -|设备管理-DeviceManager|SubscribeInfo|新增|-| -|设备管理-DeviceManager|DiscoverMode|新增|-| -|设备管理-DeviceManager|ExchangeMedium|新增|-| -|设备管理-DeviceManager|ExchangeFreq|新增|-| -|设备管理-DeviceManager|SubscribeCap|新增|-| -|设备管理-DeviceManager|createDeviceManager(bundleName: string, callback: AsyncCallback): void|新增|-| -|设备管理-DeviceManager|release(): void|新增|-| -|设备管理-DeviceManager|getTrustedDeviceListSync(): Array|新增|-| -|设备管理-DeviceManager|startDeviceDiscovery(subscribeInfo: SubscribeInfo): void|新增|-| -|设备管理-DeviceManager|stopDeviceDiscovery(subscribeId: number): void|新增|-| -|设备管理-DeviceManager|authenticateDevice(deviceInfo: DeviceInfo): void|新增|-| -|设备管理-DeviceManager|on(type: 'deviceStateChange', callback: Callback<{ action: DeviceStateChangeAction, device: DeviceInfo }>): void|新增|-| -|设备管理-DeviceManager|off(type: 'deviceStateChange', callback?: Callback<{ action: DeviceStateChangeAction, device: DeviceInfo }>): void|新增|-| -|设备管理-DeviceManager|on(type: 'deviceFound', callback: Callback<{ subscribeId: number, device: DeviceInfo }>): void|新增|-| -|设备管理-DeviceManager|off(type: 'deviceFound', callback?: Callback<{ subscribeId: number, device: DeviceInfo }>): void|新增|-| -|设备管理-DeviceManager|on(type: 'discoverFail', callback: Callback<{ subscribeId: number, reason: number }>): void|新增|-| -|设备管理-DeviceManager|off(type: 'discoverFail', callback?: Callback<{ subscribeId: number, reason: number }>): void|新增|-| -|设备管理-DeviceManager|on(type: 'authResult', callback: Callback<{ deviceId: string, status: number, reason: number }>): void|新增|-| -|设备管理-DeviceManager|off(type: 'authResult', callback?: Callback<{ deviceId: string, status: number, reason: number }>): void|新增|-| -|设备管理-DeviceManager|on(type: 'serviceDie', callback: () => void): void|新增|-| -|设备管理-DeviceManager|off(type: 'serviceDie', callback?: () => void): void|新增|-| -|播放录制|createAudioPlayer(): AudioPlayer|新增|-| -|播放录制|AudioState|新增|-| -|播放录制|play(): void|新增|-| -|播放录制|pause(): void|新增|-| -|播放录制|stop(): void|新增|-| -|播放录制|seek(timeMs: number): void|新增|-| -|播放录制|setVolume(vol: number): void|新增|-| -|播放录制|reset(): void|新增|-| -|播放录制|release(): void|新增|-| -|播放录制|src: string|新增|-| -|播放录制|loop: boolean|新增|-| -|播放录制|readonly currentTime: number|新增|-| -|播放录制|readonly duration: number|新增|-| -|播放录制|readonly state: AudioState|新增|-| -|播放录制|on(type: 'play' / 'pause' / 'stop' / 'reset' / 'dataLoad' / 'finish' / 'volumeChange', callback: () => void): void|新增|-| -|播放录制|on(type: 'timeUpdate', callback: Callback): void|新增|-| -|播放录制|on(type: 'error', callback: ErrorCallback): void|新增|-| -|音频管理|getAudioManager(): AudioManager|新增|-| -|音频管理|AudioVolumeType|新增|-| -|音频管理|MEDIA|新增|-| -|音频管理|RINGTONE|新增|-| -|音频管理|DeviceFlag|新增|-| -|音频管理|OUTPUT_DEVICES_FLAG|新增|-| -|音频管理|INPUT_DEVICES_FLAG |新增|-| -|音频管理|ALL_DEVICES_FLAG |新增|-| -|音频管理|DeviceRole |新增|-| -|音频管理|INPUT_DEVICE |新增|-| -|音频管理|OUTPUT_DEVICE |新增|-| -|音频管理|DeviceType |新增|-| -|音频管理|INVALID |新增|-| -|音频管理|SPEAKER |新增|-| -|音频管理|WIRED_HEADSET |新增|-| -|音频管理|BLUETOOTH_SCO |新增|-| -|音频管理|BLUETOOTH_A2DP |新增|-| -|音频管理|MIC|新增|-| -|音频管理|AudioRingMode |新增|-| -|音频管理|RINGER_MODE_NORMAL |新增|-| -|音频管理|RINGER_MODE_SILENT|新增|-| -|音频管理|RINGER_MODE_VIBRATE |新增|-| -|音频管理|setVolume(audioType: AudioVolumeType, volume: number,callback: AsyncCallback): void|新增|-| -|音频管理|setVolume(audioType: AudioVolumeType, volume: number): Promise|新增|-| -|音频管理|getVolume(audioType: AudioVolumeType, callback: AsyncCallback): void|新增|-| -|音频管理|getVolume(audioType: AudioVolumeType): Promise|新增|-| -|音频管理|getMinVolume(audioType: AudioVolumeType, callback: AsyncCallback): void|新增|-| -|音频管理|getMinVolume(audioType: AudioVolumeType): Promise|新增|-| -|音频管理|getMaxVolume(audioType: AudioVolumeType, callback: AsyncCallback): void|新增|-| -|音频管理|getMaxVolume(audioType: AudioVolumeType): Promise|新增|-| -|音频管理|getDevices(deviceFlag: DeviceFlag, callback: AsyncCallback): void|新增|-| -|音频管理|getDevices(deviceFlag: DeviceFlag): Promise|新增|-| -|音频管理|getRingerMode(callback: AsyncCallback): void|新增|-| -|音频管理|getRingerMode(): Promise|新增|-| -|音频管理|setRingerMode(mode: AudioRingMode, callback: AsyncCallback): void|新增|-| -|音频管理|setRingerMode(mode: AudioRingMode): Promise|新增|-| -|音频管理|isMute(volumeType: AudioVolumeType, callback: AsyncCallback): void|新增|-| -|音频管理|isMute(volumeType: AudioVolumeType): Promise|新增|-| -|音频管理|isActive(volumeType: AudioVolumeType, callback: AsyncCallback): void|新增|-| -|音频管理|isActive(volumeType: AudioVolumeType): Promise|新增|-| -|音频管理|isMicrophoneMute(callback: AsyncCallback): void|新增|-| -|音频管理|isMicrophoneMute(): Promise|新增|-| -|音频管理|mute(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback) : void|新增|-| -|音频管理|mute(volumeType: AudioVolumeType, mute: boolean): Promise|新增|-| -|音频管理|setMicrophoneMute(mute: boolean, callback: AsyncCallback): void|新增|-| -|音频管理|setMicrophoneMute(mute: boolean): Promise|新增|-| -|音频管理|isDeviceActive(deviceType: DeviceType, callback: AsyncCallback): void|新增|-| -|音频管理|isDeviceActive(deviceType: DeviceType): Promise|新增|-| -|音频管理|setDeviceActive(deviceType: DeviceType, active: boolean, callback: AsyncCallback): void|新增|-| -|音频管理|setDeviceActive(deviceType: DeviceType, active: boolean): Promise|新增|-| -|音频管理|getAudioParameter(key: string, callback: AsyncCallback): void|新增|-| -|音频管理|getAudioParameter(key: string): Promise|新增|-| -|音频管理|setAudioParameter(key: string, value: string, callback: AsyncCallback): void|新增|-| -|音频管理|setAudioParameter(key: string, value: string): Promise|新增|-| -|音频管理|AudioDeviceDescriptor|新增|-| -|音频管理|readonly deviceRole: DeviceRole|新增|-| -|音频管理|readonly deviceType: DeviceType|新增|-| -|音频管理|AudioDeviceDescriptors |新增|-| - diff --git a/website/docs/_posts/zh-cn/release-notes/api-change/v2.2-beta2/native-apidiff-v2.2-beta2.md b/website/docs/_posts/zh-cn/release-notes/api-change/v2.2-beta2/native-apidiff-v2.2-beta2.md deleted file mode 100644 index 824a63a250ae1ce34ecbc312311705ef812f96e1..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/release-notes/api-change/v2.2-beta2/native-apidiff-v2.2-beta2.md +++ /dev/null @@ -1,32 +0,0 @@ ---- -title: native-apidiff-v2.2-beta2 -permalink: /pages/extra/7ca9bb/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# Native API 差异报告 -OpenHarmony 2.2 Beta2相较于OpenHarmony 2.0 Canary版本的API变更如下: -## 轻量级系统接口变更 - -| 模块名称 | 接口名称 | 变更类型 | 变更类型 | -| -------- | -------- | -------- | -------- | -| global_i18n_lite | static LocaleInfo LocaleInfo ::ForLanguageTag(const char *languageTag, I18nStatus &status); | 新增 | 新增接口 | -| global_i18n_lite | const char LocaleInfo ::*GetExtension(const char *key); | 新增 | 新增接口 | -| global_i18n_lite | WeekInfo::WeekInfo(const LocaleInfo &localeInfo, I18nStatus &status); | 新增 | 新增接口 | -| global_i18n_lite | uint8_t WeekInfo::GetFirstDayOfWeek(); | 新增 | 新增接口 | -| global_i18n_lite | uint8_t WeekInfo::GetMinimalDaysInFirstWeek(); | 新增 | 新增接口 | -| global_i18n_lite | uint8_t WeekInfo::GetFirstDayOfWeekend(); | 新增 | 新增接口 | -| global_i18n_lite | uint8_t WeekInfo::GetLastDayOfWeekend(); | 新增 | 新增接口 | -| global_i18n_lite | int PluralFormat::GetPluralRuleIndex(double number, I18nStatus status); | 新增 | 新增接口 | -| powermgr_powermgr_lite | const RunningLock *CreateRunningLock(const char *name, RunningLockType type, RunningLockFlag flag); | 新增 | 新增接口 | -| powermgr_powermgr_lite | void DestroyRunningLock(const RunningLock *lock); | 新增 | 新增接口 | -| powermgr_powermgr_lite | BOOL AcquireRunningLock(const RunningLock *lock); | 新增 | 新增接口 | -| powermgr_powermgr_lite | BOOL ReleaseRunningLock(const RunningLock *lock); | 新增 | 新增接口 | -| powermgr_powermgr_lite | BOOL IsRunningLockHolding(const RunningLock *lock); | 新增 | 新增接口 | \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/release-notes/api-change/v3.0-LTS/js-apidiff-v3.0-lts.md b/website/docs/_posts/zh-cn/release-notes/api-change/v3.0-LTS/js-apidiff-v3.0-lts.md deleted file mode 100644 index 4c3681d943ec082f5ce7e464e390a77c7d91c796..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/release-notes/api-change/v3.0-LTS/js-apidiff-v3.0-lts.md +++ /dev/null @@ -1,638 +0,0 @@ ---- -title: js-apidiff-v3.0-lts -permalink: /pages/extra/b1cae4/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# JS API 差异报告 -OpenHarmony 3.0 LTS相较于OpenHarmony 2.2 Beta2版本的API变更如下: -## 标准系统接口变更 - -| 模块名称 | 接口名称 | 变更类型 | 变更说明 | -| -------- | -------- | -------- | -------- | -|语言编译器运行时-worker|postMessage(obj):void|新增|宿主线程与worker通信,传递数据| -|语言编译器运行时-worker|postMessage(message: Object, options?: PostMessageOptions):void|新增|宿主线程与worker通信,转移arrayBuffer的数据控制权| -|语言编译器运行时-worker|terminate():void|新增|宿主线程主动停止worker| -|语言编译器运行时-worker|on(type: string, listener: EventListener): void|新增|向worker添加回调接口| -|语言编译器运行时-worker|once(type: string, listener: EventListener): void|新增|向worker添加回调接口,并且在回调一次会释放回调| -|语言编译器运行时-worker|off(type: string, listener?: EventListener): void|新增|删除worker已添加的回调接口| -|语言编译器运行时-worker|addEventListener(type: string, listener: EventListener): void|新增|向worker添加回调接口| -|语言编译器运行时-worker|removeEventListener(type: string, listener?: EventListener): void|新增|删除worker已添加的回调接口| -|语言编译器运行时-worker|removeAllListener(): void|新增|删除worker所有的回调接口| -|语言编译器运行时-worker|dispatchEvent(event: Event): boolean|新增|向worker发送指定事件,触发回调接口| -|语言编译器运行时-parentPort|postMessage(obj):void|新增|worker与宿主线程通信,传递数据| -|语言编译器运行时-parentPort|postMessage(message: Object, options?: PostMessageOptions):void|新增|worker与宿主线程通信,转移arrayBuffer的数据控制权| -|语言编译器运行时-parentPort|close(): void|新增|worker主动终止| -|语言编译器运行时-Util|printf(format: string, ...args: Object[]): string|新增|-| -|语言编译器运行时-Util|getErrorString(errno: number): string|新增|-| -|语言编译器运行时-Util|callbackWrapper(original: Function): (err: Object, value: Object) => void|新增|-| -|语言编译器运行时-Util|promiseWrapper(original: (err: Object, value: Object) => void): Object|新增|-| -|语言编译器运行时-Util|new TextDecoder([encoding[, options]])|新增|-| -|语言编译器运行时-Util|decode([input[, options]]):string|新增|-| -|语言编译器运行时-Util|new TextEncoder()|新增|-| -|语言编译器运行时-Util|encode(input?: string): Uint8Array;|新增|-| -|语言编译器运行时-Util|"encodeInto(input: string,dest: Uint8Array,): { read: number; written: number };"|新增|-| -|语言编译器运行时-Util|readonly encoding: string;|新增|-| -|语言编译器运行时-Util|readonly fatal: boolean;|新增|-| -|语言编译器运行时-Util|readonly ignoreBOM = false;|新增|-| -|语言编译器运行时-Util|readonly encoding = "utf-8";|新增|-| -|语言编译器运行时-URL|new URL(url: string, base?: string/URL)|新增|-| -|语言编译器运行时-URL|toString(): string;|新增|-| -|语言编译器运行时-URL|toJSON(): string;|新增|-| -|语言编译器运行时-URL|new URSearchParams()|新增|-| -|语言编译器运行时-URL|new URSearchParams(string)|新增|-| -|语言编译器运行时-URL|new URSearchParams(obj)|新增|-| -|语言编译器运行时-URL|new URSearchParams(iterable)|新增|-| -|语言编译器运行时-URL|append(name: string, value: string): void;|新增|-| -|语言编译器运行时-URL|delete(name: string): void;|新增|-| -|语言编译器运行时-URL|entries(): IterableIterator<[string, string]>;|新增|-| -|语言编译器运行时-URL|forEach(callbackfn: (value: string, key: string, parent: this) => void, thisArg?: any,): void;|新增|-| -|语言编译器运行时-URL|get(name: string): string / null;|新增|-| -|语言编译器运行时-URL|getAll(name: string): string[];|新增|-| -|语言编译器运行时-URL|has(name: string): boolean;|新增|-| -|语言编译器运行时-URL|keys(): IterableIterator;|新增|-| -|语言编译器运行时-URL|set(name: string, value: string): void;|新增|-| -|语言编译器运行时-URL|sort():void;|新增|-| -|语言编译器运行时-URL|toString():string|新增|-| -|语言编译器运行时-URL|values(): IterableIterator;|新增|-| -|语言编译器运行时-URL|URSearchParams[Symbol.iterator]()|新增|-| -|语言编译器运行时-URL|hash: string;|新增|-| -|语言编译器运行时-URL|host: string;|新增|-| -|语言编译器运行时-URL|hostname: string;|新增|-| -|语言编译器运行时-URL|href: string;|新增|-| -|语言编译器运行时-URL|readonly origin: string;|新增|-| -|语言编译器运行时-URL|password: string;|新增|-| -|语言编译器运行时-URL|pathname: string;|新增|-| -|语言编译器运行时-URL|port: string;|新增|-| -|语言编译器运行时-URL|protocol: string;|新增|-| -|语言编译器运行时-URL|search: string;|新增|-| -|语言编译器运行时-URL|readonly searchParams: URLSearchParams;|新增|-| -|语言编译器运行时-URL|username: string;|新增|-| -|语言编译器运行时-ChildProcess|readonly pid: number;|新增|-| -|语言编译器运行时-ChildProcess|readonly ppid: number;|新增|-| -|语言编译器运行时-ChildProcess|readonly exitCode: number;|新增|-| -|语言编译器运行时-ChildProcess|readonly killed: boolean;|新增|-| -|语言编译器运行时-ChildProcess|wait(): Promise;|新增|-| -|语言编译器运行时-ChildProcess|getOutput(): Promise;|新增|-| -|语言编译器运行时-ChildProcess|getErrorOutput(): Promise;|新增|-| -|语言编译器运行时-ChildProcess|close(): void;|新增|-| -|语言编译器运行时-ChildProcess|kill(signal: number): void;|新增|-| -|语言编译器运行时-process|runCmd(command: string,options?: { timeout : number, killSignal : number / string, maxBuffer : number }): ChildProcess;|新增|-| -|语言编译器运行时-process|getPid(): number;|新增|-| -|语言编译器运行时-process|getPpid(): number;|新增|-| -|语言编译器运行时-process|abort(): void;|新增|-| -|语言编译器运行时-process|on(type: string, listener: EventListener): void;|新增|-| -|语言编译器运行时-process|exit(code?:number): void;|新增|-| -|语言编译器运行时-process|cwd(): string;|新增|-| -|语言编译器运行时-process|chdir(dir: string): void;|新增|-| -|语言编译器运行时-process|getEgid(): number;|新增|-| -|语言编译器运行时-process|getEuid(): number;|新增|-| -|语言编译器运行时-process|getGid(): number|新增|-| -|语言编译器运行时-process|getUid(): number;|新增|-| -|语言编译器运行时-process|uptime(): number;|新增|-| -|语言编译器运行时-process|getGroups(): number[];|新增|-| -|语言编译器运行时-process|kill(signal?: number, pid?: number): boolean;|新增|-| -|升级服务子系统-Updater|checkNewVersion(): Promise;|新增| -| -|升级服务子系统-Updater|rebootAndCleanUserData(callback: AsyncCallback): void;|新增| -| -|升级服务子系统-Updater|rebootAndCleanCache(): Promise;|新增| -| -|升级服务子系统-Updater|function getUpdaterFromOther(device: string, updateType?: UpdateTypes): Updater;|新增| -| -|升级服务子系统-Updater|cancel(): void;|新增| -| -|升级服务子系统-Updater|upgrade(): void;|新增| -| -|升级服务子系统-Updater|off(eventType: 'downloadProgress', callback?: UpdateProgressCallback): void;|新增| -| -|升级服务子系统-Updater|getUpdatePolicy(callback: AsyncCallback): void;|新增| -| -|升级服务子系统-Updater|function getUpdaterForOther(device: string, updateType?: UpdateTypes): Updater;|新增| -| -|升级服务子系统-Updater|setUpdatePolicy(policy: UpdatePolicy, callback: AsyncCallback): void;|新增| -| -|升级服务子系统-Updater|getNewVersionInfo(): Promise;|新增| -| -|升级服务子系统-Updater|function getUpdater(updateType?: UpdateTypes): Updater;|新增| -| -|升级服务子系统-Updater|applyNewVersion(callback: AsyncCallback): void;|新增| -| -|升级服务子系统-Updater|rebootAndCleanUserData(): Promise;|新增| -| -|升级服务子系统-Updater|off(eventType: 'verifyProgress', callback?: UpdateProgressCallback): void;|新增| -| -|升级服务子系统-Updater|on(eventType: 'upgradeProgress', callback: UpdateProgressCallback): void;|新增| -| -|升级服务子系统-Updater|checkNewVersion(callback: AsyncCallback): void;|新增| -| -|升级服务子系统-Updater|on(eventType: 'downloadProgress', callback: UpdateProgressCallback): void;|新增| -| -|升级服务子系统-Updater|getUpdatePolicy(): Promise;|新增| -| -|升级服务子系统-Updater|download(): void;|新增| -| -|升级服务子系统-Updater|off(eventType: 'upgradeProgress', callback?: UpdateProgressCallback): void;|新增| -| -|升级服务子系统-Updater|getNewVersionInfo(callback: AsyncCallback): void;|新增| -| -|升级服务子系统-Updater|on(eventType: 'verifyProgress', callback: UpdateProgressCallback): void;|新增| -| -|升级服务子系统-Updater|verifyUpdatePackage(upgradeFile: string, certsFile: string): void;|新增| -| -|升级服务子系统-Updater|setUpdatePolicy(policy: UpdatePolicy): Promise;|新增| -| -|升级服务子系统-Updater|rebootAndCleanCache(callback: AsyncCallback): void;|新增| -| -|升级服务子系统-Updater|applyNewVersion(): Promise;|新增| -| -|全球化子系统-I18n|getSystemLanguages(): Array;|新增| -| -|全球化子系统-I18n|getSystemCountries(language: string): Array;|新增| -| -|全球化子系统-I18n|isSuggested(language: string, region?: string): boolean;|新增| -| -|全球化子系统-I18n|getSystemLanguage(): string;|新增| -| -|全球化子系统-I18n|setSystemLanguage(language: string);|新增| -| -|全球化子系统-I18n|getSystemRegion(): string;|新增| -| -|全球化子系统-I18n|setSystemRegion(region: string);|新增| -| -|全球化子系统-I18n|"getDisplayCountry(locale: string, displayLocale: string,sentenceCase?: boolean): string;"|新增| -| -|全球化子系统-I18n|getSystemLocale(): string;|新增| -| -|全球化子系统-I18n|setSystemLocale(locale: string);|新增| -| -|全球化子系统-I18n|"getDisplayLanguage(locale: string, displayLocale: string,sentenceCase?: boolean): string;"|新增| -| -|电话子系统-radio|getNetworkState(callback: AsyncCallback): void;getNetworkState(slotId: number, callback: AsyncCallback): void;getNetworkState(slotId?: number): Promise;|新增| -| -|电话子系统-sim|getSimAccountInfo(slotId: number, callback: AsyncCallback): void;getSimAccountInfo(slotId: number): Promise;|新增| -| -|电话子系统-sim|getDefaultVoiceSlotId(callback: AsyncCallback): void;getDefaultVoiceSlotId(): Promise;|新增| -| -|电话子系统-sim|getSimSpn(slotId: number, callback: AsyncCallback): void;getSimSpn(slotId: number): Promise;|新增| -| -|电话子系统-sim|getISOCountryCodeForSim(slotId: number, callback: AsyncCallback): void;getISOCountryCodeForSim(slotId: number): Promise;|新增| -| -|电话子系统-sim|getSimIccId(slotId: number, callback: AsyncCallback): void;getSimIccId(slotId: number): Promise;|新增| -| -|电话子系统-sim|getSimGid1(slotId: number, callback: AsyncCallback): void;getSimGid1(slotId: number): Promise;|新增| -| -|电话子系统-sim|getISOCountryCodeForSim(slotId: number, callback: AsyncCallback): void;getISOCountryCodeForSim(slotId: number): Promise;|新增| -| -|电话子系统-sim|getSimOperatorNumeric(slotId: number, callback: AsyncCallback): void;getSimOperatorNumeric(slotId: number): Promise;|新增| -| -|电话子系统-sim|getSimSpn(slotId: number, callback: AsyncCallback): void;getSimSpn(slotId: number): Promise;|新增| -| -|电话子系统-sim|getSimIccId(slotId: number, callback: AsyncCallback): void;getSimIccId(slotId: number): Promise;|新增| -| -|电话子系统-sim|getIMSI(slotId: number, callback: AsyncCallback): void;getIMSI(slotId: number): Promise;|新增| -| -|电话子系统-call|combineConference(callId: number, callback: AsyncCallback): void;combineConference(callId: number): Promise;|新增| -| -|电话子系统-call|startDTMF(callId: number, character: string, callback: AsyncCallback): void;startDTMF(callId: number, character: string): Promise;|新增| -| -|电话子系统-call|stopDTMF(callId: number, callback: AsyncCallback): void;stopDTMF(callId: number): Promise;|新增| -| -|电话子系统-sim|setDefaultVoiceSlotId(slotId: number, callback: AsyncCallback): void;setDefaultVoiceSlotId(slotId: number): Promise;|新增| -| -|电话子系统-sim|unlockPin(slotId: number, pin: string, callback: AsyncCallback): void;unlockPin(slotId: number, pin: string): Promise;|新增| -| -|电话子系统-sim|alterPin(slotId: number, newPin: string, oldPin: string, callback: AsyncCallback): void;alterPin(slotId: number, newPin: string, oldPin: string): Promise;|新增| -| -|电话子系统-sim|setLockState(slotId: number, pin: string, enable: number, callback: AsyncCallback): void;setLockState(slotId: number, pin: string, enable: number): Promise;|新增| -| -|电话子系统-sim|getSimState(slotId: number, callback: AsyncCallback): void;getSimState(slotId: number): Promise;|新增| -| -|电话子系统-sim|getSimState(slotId: number, callback: AsyncCallback): void;getSimState(slotId: number): Promise;|新增| -| -|电话子系统-sim|getSimState(slotId: number, callback: AsyncCallback): void;getSimState(slotId: number): Promise;|新增| -| -|电话子系统-sim|getSimState(slotId: number, callback: AsyncCallback): void;getSimState(slotId: number): Promise;|新增| -| -|电话子系统-call|isEmergencyPhoneNumber(phoneNumber: string, callback: AsyncCallback): void;isEmergencyPhoneNumber(phoneNumber: string, options: EmergencyNumberOptions, callback: AsyncCallback): void;isEmergencyPhoneNumber(phoneNumber: string, options?: EmergencyNumberOptions): Promise;|新增| -| -|电话子系统-sms|createMessage(pdu: Array, specification: string, callback: AsyncCallback): void;createMessage(pdu: Array, specification: string): Promise;|新增| -| -|电话子系统-call|hasCall(callback: AsyncCallback): void;hasCall(): Promise;|新增| -| -|电话子系统-sms|sendMessage(options: SendMessageOptions): void;|新增| -| -|电话子系统-call|dial(phoneNumber: string, callback: AsyncCallback): void;dial(phoneNumber: string, options: DialOptions, callback: AsyncCallback): void;dial(phoneNumber: string, options?: DialOptions): Promise;|新增| -| -|电话子系统-call|interface DialOptions {extras?: boolean; }|新增| -| -|电话子系统-sms|sendMessage(options: SendMessageOptions): void;|新增| -| -|电话子系统-sms|getDefaultSmsSlotId(callback: AsyncCallback): void;getDefaultSmsSlotId(): Promise;|新增| -| -|电话子系统-call|formatPhoneNumber(phoneNumber: string, callback: AsyncCallback): void;formatPhoneNumber(phoneNumber: string, options: NumberFormatOptions, callback: AsyncCallback): void;formatPhoneNumber(phoneNumber: string, options?: NumberFormatOptions): Promise;|新增| -| -|电话子系统-call|formatPhoneNumber(phoneNumber: string, callback: AsyncCallback): void;formatPhoneNumber(phoneNumber: string, options: NumberFormatOptions, callback: AsyncCallback): void;formatPhoneNumber(phoneNumber: string, options?: NumberFormatOptions): Promise;|新增| -| -|电话子系统-call|formatPhoneNumberToE164(phoneNumber: string, countryCode: string, callback: AsyncCallback): void;formatPhoneNumberToE164(phoneNumber: string, countryCode: string): Promise;|新增| -| -|电话子系统-sms|setDefaultSmsSlotId(slotId: number, callback: AsyncCallback): void;setDefaultSmsSlotId(slotId: number): Promise;|新增| -| -|电话子系统-call|getCallState(callback: AsyncCallback): void;getCallState(): Promise;|新增| -| -|电话子系统-sms|setSmscAddr(slotId: number, smscAddr: string, callback: AsyncCallback): void;setSmscAddr(slotId: number, smscAddr: string): Promise;|新增| -| -|电话子系统-sms|getSmscAddr(slotId: number, callback: AsyncCallback): void;getSmscAddr(slotId: number): Promise;|新增| -| -|电话子系统-sms|addSimMessage(options: SimMessageOptions, callback: AsyncCallback): void;addSimMessage(options: SimMessageOptions): Promise;|新增| -| -|电话子系统-sms|delSimMessage(slotId: number, msgIndex: number, callback: AsyncCallback): void;delSimMessage(slotId: number, msgIndex: number): Promise;|新增| -| -|电话子系统-radio|getISOCountryCodeForNetwork(slotId: number, callback: AsyncCallback): void;getISOCountryCodeForNetwork(slotId: number): Promise;|新增| -| -|电话子系统-sms|updateSimMessage(options: UpdateSimMessageOptions, callback: AsyncCallback): void;updateSimMessage(options: UpdateSimMessageOptions): Promise;|新增| -| -|电话子系统-radio|getISOCountryCodeForNetwork(slotId: number, callback: AsyncCallback): void;getISOCountryCodeForNetwork(slotId: number): Promise;|新增| -| -|电话子系统-sms|getAllSimMessages(slotId: number, callback: AsyncCallback>): void;getAllSimMessages(slotId: number): Promise>;|新增| -| -|电话子系统-call|isInEmergencyCall(callback: AsyncCallback): void;isInEmergencyCall(): Promise;|新增| -| -|电话子系统-sms|setCBConfig(options: CBConfigOptions, callback: AsyncCallback): void;setCBConfig(options: CBConfigOptions): Promise;|新增| -| -|电话子系统-call|answer(callId: number, callback: AsyncCallback): void;answer(callId: number): Promise;|新增| -| -|电话子系统-call|hangup(callId: number, callback: AsyncCallback): void;hangup(callId: number): Promise;|新增| -| -|电话子系统-call|reject(callId: number, callback: AsyncCallback): void;reject(callId: number, options: RejectMessageOptions, callback: AsyncCallback): void;reject(callId: number, options?: RejectMessageOptions): Promise;|新增| -| -|电话子系统-call|holdCall(callId: number, callback: AsyncCallback): void;holdCall(callId: number): Promise;|新增| -| -|电话子系统-call|unHoldCall(callId: number, callback: AsyncCallback): void;unHoldCall(callId: number): Promise;|新增| -| -|电话子系统-call|switchCall(callId: number, callback: AsyncCallback): void;switchCall(callId: number): Promise;|新增| -| -|电话子系统-radio|setNetworkSelectionMode(options: NetworkSelectionModeOptions, callback: AsyncCallback): void;setNetworkSelectionMode(options: NetworkSelectionModeOptions): Promise;|新增| -| -|电话子系统-radio|getNetworkSearchInformation(slotId: number, callback: AsyncCallback): void;getNetworkSearchInformation(slotId: number): Promise;|新增| -| -|电话子系统-radio|getNetworkSelectionMode(slotId: number, callback: AsyncCallback): void;getNetworkSelectionMode(slotId: number): Promise;|新增| -| -|电话子系统-radio|isRadioOn(callback: AsyncCallback): void;isRadioOn(): Promise;|新增| -| -|电话子系统-radio|turnOnRadio(callback: AsyncCallback): void;turnOnRadio(): Promise;|新增| -| -|电话子系统-radio|turnOffRadio(callback: AsyncCallback): void;turnOffRadio(): Promise;|新增| -| -|电话子系统-radio|getSignalInformation(slotId: number, callback: AsyncCallback>): void;getSignalInformation(slotId: number): Promise>;|新增| -| -|电话子系统-radio|getRadioTech(slotId: number, callback: AsyncCallback<{psRadioTech: RadioTechnology, csRadioTech: RadioTechnology}>): void;getRadioTech(slotId: number): Promise<{psRadioTech: RadioTechnology, csRadioTech: RadioTechnology}>;|新增| -| -|电话子系统-radio|getRadioTech(slotId: number, callback: AsyncCallback<{psRadioTech: RadioTechnology, csRadioTech: RadioTechnology}>): void;getRadioTech(slotId: number): Promise<{psRadioTech: RadioTechnology, csRadioTech: RadioTechnology}>;|新增| -| -|电话子系统-radio|getRadioTech(slotId: number, callback: AsyncCallback<{psRadioTech: RadioTechnology, csRadioTech: RadioTechnology}>): void;getRadioTech(slotId: number): Promise<{psRadioTech: RadioTechnology, csRadioTech: RadioTechnology}>;|新增| -| -|数据管理-distributeddata|put(key:string, value:Uint8Array / string / boolean / number, callback: AsyncCallback):void put(key:string, value:Uint8Array / string / boolean / number):Promise|新增| -| -|数据管理-distributeddata|delete(key: string, callback: AsyncCallback): void delete(key: string): Promise|新增| -| -|数据管理-distributeddata|on(event:'dataChange', subType: SubscribeType, observer: Callback): void|新增| -| -|数据管理-distributeddata|get(key:string, callback:AsyncCallback):void get(key:string):Promise|新增| -| -|数据管理-distributeddata|sync(deviceIdList:string[], mode:SyncMode, allowedDelayMs?:number):void|新增| -| -|数据管理-distributeddata|createKVManager(config: KVManagerConfig, callback: AsyncCallback): void;createKVManager(config: KVManagerConfig): Promise;|新增| -| -|数据管理-distributeddata|getKVStore(options: Options, storeId: string): Promise;getKVStore(options: Options, storeId: string, callback: AsyncCallback): void;|新增| -| -|数据管理-distributeddata|on(event:'syncComplete', syncCallback: Callback>):void|新增| -| -|数据管理-rdb|type ValueType = number / string / boolean;|新增| -| -|数据管理-rdb|type ValuesBucket = { [key: string]: ValueType / Uint8Array / null; }|新增| -| -|数据管理-rdb|name: string;|新增| -| -|数据管理-rdb|constructor(name: string)|新增| -| -|数据管理-rdb|equalTo(field: string, value: ValueType): RdbPredicates;|新增| -| -|数据管理-rdb|notEqualTo(field: string, value: ValueType): RdbPredicates;|新增| -| -|数据管理-rdb|beginWrap(): RdbPredicates;|新增| -| -|数据管理-rdb|endWrap(): RdbPredicates;|新增| -| -|数据管理-rdb|function getRdbStore(config: StoreConfig, version: number, callback: AsyncCallback): void;function getRdbStore(config: StoreConfig, version: number): Promise;|新增| -| -|数据管理-rdb|function deleteRdbStore(name: string, callback: AsyncCallback): void;function deleteRdbStore(name: string): Promise;|新增| -| -|数据管理-rdb|insert(name: string, values: ValuesBucket, callback: AsyncCallback): void;insert(name: string, values: ValuesBucket): Promise;|新增| -| -|数据管理-rdb|update(values: ValuesBucket, rdbPredicates: RdbPredicates, callback: AsyncCallback): void;update(values: ValuesBucket, rdbPredicates: RdbPredicates): Promise;|新增| -| -|数据管理-rdb|delete(rdbPredicates: RdbPredicates, callback: AsyncCallback): void;delete(rdbPredicates: RdbPredicates): Promise;|新增| -| -|数据管理-rdb|query(rdbPredicates: RdbPredicates, columns: Array, callback: AsyncCallback): void;query(rdbPredicates: RdbPredicates, columns: Array): Promise;|新增| -| -|数据管理-rdb|executeSql(sql: string, bindArgs: Array, callback: AsyncCallback): void;executeSql(sql: string, bindArgs: Array): Promise;|新增| -| -|数据管理-rdb|like(field: string, value: string): RdbPredicates;|新增| -| -|数据管理-rdb|glob(field: string, value: string): RdbPredicates;|新增| -| -|数据管理-rdb|between(field: string, low: ValueType, high: ValueType): RdbPredicates;|新增| -| -|数据管理-rdb|notBetween(field: string, low: ValueType, high: ValueType): RdbPredicates;|新增| -| -|数据管理-rdb|greaterThan(field: string, value: ValueType): RdbPredicates;|新增| -| -|数据管理-rdb|lessThan(field: string, value: ValueType): RdbPredicates;|新增| -| -|数据管理-rdb|greaterThanOrEqualTo(field: string, value: ValueType): RdbPredicates;|新增| -| -|数据管理-rdb|lessThanOrEqualTo(field: string, value: ValueType): RdbPredicates;|新增| -| -|数据管理-rdb|or(): RdbPredicates;|新增| -| -|数据管理-rdb|and(): RdbPredicates;|新增| -| -|数据管理-rdb|contains(field: string, value: string): RdbPredicates;|新增| -| -|数据管理-rdb|beginsWith(field: string, value: string): RdbPredicates;|新增| -| -|数据管理-rdb|endsWith(field: string, value: string): RdbPredicates;|新增| -| -|数据管理-rdb|isNull(field: string): RdbPredicates;|新增| -| -|数据管理-rdb|isNotNull(field: string): RdbPredicates;|新增| -| -|数据管理-rdb|isEnded: boolean;|新增| -| -|数据管理-rdb|isStarted: boolean;|新增| -| -|数据管理-rdb|isClosed: boolean;|新增| -| -|数据管理-rdb|getColumnIndex(columnName: string): number;|新增| -| -|数据管理-rdb|getColumnName(columnIndex: number): string;|新增| -| -|数据管理-rdb|goTo(offset: number): boolean;|新增| -| -|数据管理-rdb|goToRow(position: number): boolean;|新增| -| -|数据管理-rdb|goToFirstRow(): boolean;|新增| -| -|数据管理-rdb|goToLastRow(): boolean;|新增| -| -|数据管理-rdb|goToNextRow(): boolean;|新增| -| -|数据管理-rdb|goToPreviousRow(): boolean;|新增| -| -|数据管理-rdb|getBlob(columnIndex: number): Uint8Array;|新增| -| -|数据管理-rdb|getString(columnIndex: number): string;|新增| -| -|数据管理-rdb|getLong(columnIndex: number): number;|新增| -| -|数据管理-rdb|getDouble(columnIndex: number): number;|新增| -| -|数据管理-dataAbility|orderByDesc(field: string): DataAbilityPredicates;|新增| -| -|数据管理-dataAbility|distinct(): DataAbilityPredicates;|新增| -| -|数据管理-dataAbility|limitAs(value: number): DataAbilityPredicates;|新增| -| -|数据管理-dataAbility|offsetAs(rowOffset: number): DataAbilityPredicates;|新增| -| -|数据管理-dataAbility|groupBy(fields: Array): DataAbilityPredicates;|新增| -| -|数据管理-dataAbility|indexedBy(field: string): DataAbilityPredicates;|新增| -| -|数据管理-dataAbility|in(field: string, value: Array): DataAbilityPredicates;|新增| -| -|数据管理-dataAbility|notIn(field: string, value: Array): DataAbilityPredicates;|新增| -| -|数据管理-dataAbility|glob(field: string, value: string): DataAbilityPredicates;|新增| -| -|数据管理-dataAbility|between(field: string, low: ValueType, high: ValueType): DataAbilityPredicates;|新增| -| -|数据管理-dataAbility|notBetween(field: string, low: ValueType, high: ValueType): DataAbilityPredicates;|新增| -| -|数据管理-dataAbility|greaterThan(field: string, value: ValueType): DataAbilityPredicates;|新增| -| -|数据管理-dataAbility|lessThan(field: string, value: ValueType): DataAbilityPredicates;|新增| -| -|数据管理-dataAbility|greaterThanOrEqualTo(field: string, value: ValueType): DataAbilityPredicates;|新增| -| -|数据管理-dataAbility|lessThanOrEqualTo(field: string, value: ValueType): DataAbilityPredicates;|新增| -| -|数据管理-dataAbility|orderByAsc(field: string): DataAbilityPredicates;|新增| -| -|数据管理-rdb|isColumnNull(columnIndex: number): boolean;|新增| -| -|数据管理-rdb|close(): void;|新增| -| -|数据管理-dataAbility|function createRdbPredicates(name: string, dataAbilityPredicates: DataAbilityPredicates): rdb.RdbPredicates;|新增| -| -|数据管理-dataAbility|equalTo(field: string, value: ValueType): DataAbilityPredicates;|新增| -| -|数据管理-dataAbility|notEqualTo(field: string, value: ValueType): DataAbilityPredicates;|新增| -| -|数据管理-dataAbility|beginWrap():DataAbilityPredicates;|新增| -| -|数据管理-dataAbility|endWrap(): DataAbilityPredicates;|新增| -| -|数据管理-rdb|orderByAsc(field: string): RdbPredicates;|新增| -| -|数据管理-rdb|orderByDesc(field: string): RdbPredicates;|新增| -| -|数据管理-rdb|distinct(): RdbPredicates;|新增| -| -|数据管理-rdb|limitAs(value: number): RdbPredicates;|新增| -| -|数据管理-rdb|offsetAs(rowOffset: number): RdbPredicates;|新增| -| -|数据管理-rdb|groupBy(fields: Array): RdbPredicates;|新增| -| -|数据管理-rdb|indexedBy(field: string): RdbPredicates;|新增| -| -|数据管理-dataAbility|or(): DataAbilityPredicates;|新增| -| -|数据管理-dataAbility|and(): DataAbilityPredicates;|新增| -| -|数据管理-dataAbility|contains(field: string, value: string): DataAbilityPredicates;|新增| -| -|数据管理-dataAbility|beginsWith(field: string, value: string): DataAbilityPredicates;|新增| -| -|数据管理-dataAbility|endsWith(field: string, value: string): DataAbilityPredicates;|新增| -| -|数据管理-dataAbility|isNull(field: string): DataAbilityPredicates;|新增| -| -|数据管理-dataAbility|isNotNull(field: string): DataAbilityPredicates;|新增| -| -|数据管理-dataAbility|like(field: string, value: string): DataAbilityPredicates;|新增| -| -|数据管理-rdb|in(field: string, value: Array): RdbPredicates;|新增| -| -|数据管理-rdb|notIn(field: string, value: Array): RdbPredicates;|新增| -| -|数据管理-rdb|columnNames: Array;|新增| -| -|数据管理-rdb|columnCount: number;|新增| -| -|数据管理-rdb|rowCount: number;|新增| -| -|数据管理-rdb|rowIndex: number;|新增| -| -|数据管理-rdb|isAtFirstRow: boolean;|新增| -| -|数据管理-rdb|isAtLastRow: boolean;|新增| -| -|事件通知-notification|title: string;|新增| -| -|事件通知-notification|sound?: string;|新增| -| -|事件通知-notification|text: string;|新增| -| -|事件通知-notification|vibrationValues?: Array;|新增| -| -|事件通知-wantAgent|want?: Want;|新增| -| -|事件通知-notification|vibrationEnabled?: boolean;|新增| -| -|事件通知-notification|badgeFlag?: boolean;|新增| -| -|事件通知-notification|type: notification.SlotType;|新增| -| -|事件通知-wantAgent|code: number;|新增| -| -|事件通知-notification|contentType: ContentType;|新增| -| -|事件通知-notification|picture: image.PixelMap;|新增| -| -|事件通知-notification|briefText: string;|新增| -| -|事件通知-notification|briefText: string;|新增| -| -|事件通知-notification|briefText: string;|新增| -| -|事件通知-notification|bypassDnd?: boolean;|新增| -| -|事件通知-notification|additionalText?: string;|新增| -| -|事件通知-wantagent|function cancel(info: WantAgentInfo, callback: AsyncCallback): void;|新增| -| -|事件通知-wantAgent|enum OperationType|新增| -| -|事件通知-wantAgent|enum WantAgentFlags|新增| -| -|事件通知-wantAgent|permission?: string;|新增| -| -|事件通知-notification|picture?: NotificationPictureContent;|新增| -| -|事件通知-notification|normal?: NotificationBasicContent;|新增| -| -|事件通知-notification|expandedTitle: string;|新增| -| -|事件通知-notification|expandedTitle: string;|新增| -| -|事件通知-wantAgent|function trigger(info: WantAgentInfo, triggerInfo: TriggerInfo, callback: AsyncCallback): void;|新增| -| -|事件通知-wantAgent|extraInfo?: {[key: string]: any};|新增| -| -|事件通知-notification|multiLine?: NotificationMultiLineContent;|新增| -| -|事件通知-notification|level?: notification.SlotLevel;|新增| -| -|事件通知-notification|lightColor?: number;|新增| -| -|事件通知-notification|lightEnabled?: boolean;|新增| -| -|事件通知-notification|lines: Array;|新增| -| -|事件通知-notification|lockscreenVisibility?: number;|新增| -| -|事件通知-notification|longText: string;|新增| -| -|事件通知-wantAgent|function getBundleName(info: WantAgentInfo, callback: AsyncCallback): void;|新增| -| -|事件通知-notification|longText?: NotificationLongTextContent;|新增| -| -|事件通知-notification|longTitle: string;|新增| -| -|事件通知-wantAgent|function judgeEquality(info: WantAgentInfo, info2: WantAgentInfo, callback: AsyncCallback): void;|新增| -| -|事件通知-wantAgent|function getUid(info: WantAgentInfo, callback: AsyncCallback): void;|新增| -| -|事件通知-commonEvent|COMMON_EVENT_IVI_TEMPERATURE_ABNORMAL = common.event.IVI_TEMPERATURE_ABNORMAL,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_IVI_VOLTAGE_RECOVERY = common.event.IVI_VOLTAGE_RECOVERY,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_IVI_TEMPERATURE_RECOVERY = common.event.IVI_TEMPERATURE_RECOVERY,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_IVI_ACTIVE = common.event.IVI_ACTIVE,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_USB_DEVICE_ATTACHED = usual.event.hardware.usb.action.USB_DEVICE_ATTACHED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_USB_DEVICE_DETACHED = usual.event.hardware.usb.action.USB_DEVICE_DETACHED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_IVI_PAUSE = common.event.IVI_PAUSE,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_IVI_STANDBY = common.event.IVI_STANDBY,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_IVI_LASTMODE_SAVE = common.event.IVI_LASTMODE_SAVE,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_IVI_VOLTAGE_ABNORMAL = common.event.IVI_VOLTAGE_ABNORMAL,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_IVI_HIGH_TEMPERATURE = common.event.IVI_HIGH_TEMPERATURE,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_IVI_EXTREME_TEMPERATURE = common.event.IVI_EXTREME_TEMPERATURE,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_DISK_UNMOUNTABLE = usual.event.data.DISK_UNMOUNTABLE,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_DISK_EJECT = usual.event.data.DISK_EJECT,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_VISIBLE_ACCOUNTS_UPDATED = usual.event.data.VISIBLE_ACCOUNTS_UPDATED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_ACCOUNT_DELETED = usual.event.data.ACCOUNT_DELETED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_FOUNDATION_READY = common.event.FOUNDATION_READY,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_AIRPLANE_MODE_CHANGED = usual.event.AIRPLANE_MODE|新增| -| -|事件通知-commonEvent|COMMON_EVENT_USB_ACCESSORY_ATTACHED = usual.event.hardware.usb.action.USB_ACCESSORY_ATTACHED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_USB_ACCESSORY_DETACHED = usual.event.hardware.usb.action.USB_ACCESSORY_DETACHED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_DISK_REMOVED = usual.event.data.DISK_REMOVED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_DISK_UNMOUNTED = usual.event.data.DISK_UNMOUNTED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_DISK_MOUNTED = usual.event.data.DISK_MOUNTED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_DISK_BAD_REMOVAL = usual.event.data.DISK_BAD_REMOVAL,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_NFC_ACTION_RF_FIELD_OFF_DETECTED = usual.event.nfc.action.RF_FIELD_OFF_DETECTED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_DISCHARGING = usual.event.DISCHARGING,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_CHARGING = usual.event.CHARGING,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_DEVICE_IDLE_MODE_CHANGED = usual.event.DEVICE_IDLE_MODE_CHANGED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_POWER_SAVE_MODE_CHANGED = usual.event.POWER_SAVE_MODE_CHANGED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_USER_ADDED = usual.event.USER_ADDED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_USER_REMOVED = usual.event.USER_REMOVED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_ABILITY_ADDED = common.event.ABILITY_ADDED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_ABILITY_REMOVED = common.event.ABILITY_REMOVED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_ABILITY_UPDATED = common.event.ABILITY_UPDATED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_LOCATION_MODE_STATE_CHANGED = usual.event.location.MODE_STATE_CHANGED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_IVI_SLEEP = common.event.IVI_SLEEP,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_HOST_NAME_UPDATE = usual.event.bluetooth.host.NAME_UPDATE,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_A2DPSINK_CONNECT_STATE_UPDATE = usual.event.bluetooth.a2dpsink.CONNECT_STATE_UPDATE,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_A2DPSINK_PLAYING_STATE_UPDATE = usual.event.bluetooth.a2dpsink.PLAYING_STATE_UPDATE,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_A2DPSINK_AUDIO_STATE_UPDATE = usual.event.bluetooth.a2dpsink.AUDIO_STATE_UPDATE,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_NFC_ACTION_ADAPTER_STATE_CHANGED = usual.event.nfc.action.ADAPTER_STATE_CHANGED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_NFC_ACTION_RF_FIELD_ON_DETECTED = usual.event.nfc.action.RF_FIELD_ON_DETECTED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_HOST_REQ_ENABLE = usual.event.bluetooth.host.REQ_ENABLE,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_HOST_REQ_DISABLE = usual.event.bluetooth.host.REQ_DISABLE,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_HOST_SCAN_MODE_UPDATE = usual.event.bluetooth.host.SCAN_MODE_UPDATE,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_HOST_DISCOVERY_STARTED = usual.event.bluetooth.host.DISCOVERY_STARTED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_HOST_DISCOVERY_FINISHED = usual.event.bluetooth.host.DISCOVERY_FINISHED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_WIFI_P2P_CONN_STATE = usual.event.wifi.p2p.CONN_STATE_CHANGE,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_WIFI_P2P_STATE_CHANGED = usual.event.wifi.p2p.STATE_CHANGE,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_WIFI_P2P_PEERS_STATE_CHANGED = usual.event.wifi.p2p.DEVICES_CHANGE,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_WIFI_P2P_CURRENT_DEVICE_STATE_CHANGED = usual.event.wifi.p2p.CURRENT_DEVICE_CHANGE,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_WIFI_P2P_GROUP_STATE_CHANGED = usual.event.wifi.p2p.GROUP_STATE_CHANGED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_CONNECT_STATE_UPDATE = usual.event.bluetooth.handsfree.ag.CONNECT_STATE_UPDATE,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_CURRENT_DEVICE_UPDATE = usual.event.bluetooth.handsfree.ag.CURRENT_DEVICE_UPDATE,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_AUDIO_STATE_UPDATE = usual.event.bluetooth.handsfree.ag.AUDIO_STATE_UPDATE,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CONNECT_STATE_UPDATE = usual.event.bluetooth.a2dpsource.CONNECT_STATE_UPDATE,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CURRENT_DEVICE_UPDATE = usual.event.bluetooth.a2dpsource.CURRENT_DEVICE_UPDATE,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_WIFI_RSSI_VALUE = usual.event.wifi.RSSI_VALUE,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_WIFI_CONN_STATE = usual.event.wifi.CONN_STATE,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_WIFI_HOTSPOT_STATE = usual.event.wifi.HOTSPOT_STATE,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_WIFI_AP_STA_JOIN = usual.event.wifi.WIFI_HS_STA_JOIN,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_WIFI_AP_STA_LEAVE = usual.event.wifi.WIFI_HS_STA_LEAVE,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_WIFI_MPLINK_STATE_CHANGE = usual.event.wifi.mplink.STATE_CHANGE,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_HWID_LOGOUT = common.event.HWID_LOGOUT,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_HWID_TOKEN_INVALID = common.event.HWID_TOKEN_INVALID,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_HWID_LOGOFF = common.event.HWID_LOGOFF,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_WIFI_POWER_STATE = usual.event.wifi.POWER_STATE,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_WIFI_SCAN_FINISHED = usual.event.wifi.SCAN_FINISHED,|新增| -| -|事件通知-commonEvent|clearAbortCommonEvent(): Promise;|新增| -| -|事件通知-commonEvent|bundleName?: string;|新增| -| -|事件通知-commonEvent|code?: number;|新增| -| -|事件通知-commonEvent|data?: string;|新增| -| -|事件通知-commonEvent|subscriberPermissions?: Array;|新增| -| -|事件通知-commonEvent|isOrdered?: boolean;|新增| -| -|事件通知-commonEvent|isSticky?: boolean;|新增| -| -|事件通知-commonEvent|abortCommonEvent(callback: AsyncCallback): void;|新增| -| -|事件通知-commonEvent|abortCommonEvent(): Promise;|新增| -| -|事件通知-commonEvent|function createSubscriber(subscribeInfo: CommonEventSubscribeInfo): Promise;|新增| -| -|事件通知-commonEvent|function createSubscriber(subscribeInfo: CommonEventSubscribeInfo, callback: AsyncCallback): void;|新增| -| -|事件通知-commonEvent|function subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback): void;|新增| -| -|事件通知-commonEvent|function publish(event: string, options: CommonEventPublishData, callback: AsyncCallback): void;|新增| -| -|事件通知-commonEvent|isOrderedCommonEvent(callback: AsyncCallback): void;|新增| -| -|事件通知-commonEvent|isOrderedCommonEvent(): Promise;|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BOOT_COMPLETED = usual.event.BOOT_COMPLETED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_LOCKED_BOOT_COMPLETED = usual.event.LOCKED_BOOT_COMPLETED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_SHUTDOWN = usual.event.SHUTDOWN,|新增| -| -|事件通知-commonEvent|isStickyCommonEvent(): Promise;|新增| -| -|事件通知-commonEvent|getData(callback: AsyncCallback): void;|新增| -| -|事件通知-commonEvent|getData(): Promise;|新增| -| -|事件通知-commonEvent|getSubscribeInfo(callback: AsyncCallback): void;|新增| -| -|事件通知-commonEvent|getSubscribeInfo(): Promise;|新增| -| -|事件通知-commonEvent|function publish(event: string, callback: AsyncCallback): void;|新增| -| -|事件通知-commonEvent|event: string|新增| -| -|事件通知-commonEvent|bundleName?: string;|新增| -| -|事件通知-commonEvent|code?: number;|新增| -| -|事件通知-commonEvent|data?: string;|新增| -| -|事件通知-commonEvent|setCode(code: number, callback: AsyncCallback): void;|新增| -| -|事件通知-commonEvent|COMMON_EVENT_DRIVE_MODE = common.event.DRIVE_MODE,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_HOME_MODE = common.event.HOME_MODE,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_OFFICE_MODE = common.event.OFFICE_MODE,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_USER_STARTED = usual.event.USER_STARTED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_USER_BACKGROUND = usual.event.USER_BACKGROUND,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_USER_FOREGROUND = usual.event.USER_FOREGROUND,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_USER_SWITCHED = usual.event.USER_SWITCHED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_USER_STARTING = usual.event.USER_STARTING,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_USER_UNLOCKED = usual.event.USER_UNLOCKED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_USER_STOPPING = usual.event.USER_STOPPING,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_USER_STOPPED = usual.event.USER_STOPPED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_HWID_LOGIN = common.event.HWID_LOGIN,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_PACKAGE_VERIFIED = usual.event.PACKAGE_VERIFIED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_EXTERNAL_APPLICATIONS_AVAILABLE = usual.event.EXTERNAL_APPLICATIONS_AVAILABLE,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_EXTERNAL_APPLICATIONS_UNAVAILABLE = usual.event.EXTERNAL_APPLICATIONS_UNAVAILABLE,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_CONFIGURATION_CHANGED = usual.event.CONFIGURATION_CHANGED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_LOCALE_CHANGED = usual.event.LOCALE_CHANGED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_MANAGE_PACKAGE_STORAGE = usual.event.MANAGE_PACKAGE_STORAGE,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_PACKAGES_UNSUSPENDED = usual.event.PACKAGES_UNSUSPENDED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_MY_PACKAGE_SUSPENDED = usual.event.MY_PACKAGE_SUSPENDED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_MY_PACKAGE_UNSUSPENDED = usual.event.MY_PACKAGE_UNSUSPENDED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_UID_REMOVED = usual.event.UID_REMOVED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_PACKAGE_FIRST_LAUNCH = usual.event.PACKAGE_FIRST_LAUNCH,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_PACKAGE_NEEDS_VERIFICATION = usual.event.PACKAGE_NEEDS_VERIFICATION,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_SCREEN_OFF = usual.event.SCREEN_OFF,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_SCREEN_ON = usual.event.SCREEN_ON,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_USER_PRESENT = usual.event.USER_PRESENT,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_TIME_TICK = usual.event.TIME_TICK,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_TIME_CHANGED = usual.event.TIME_CHANGED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_DATE_CHANGED = usual.event.DATE_CHANGED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BATTERY_CHANGED = usual.event.BATTERY_CHANGED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BATTERY_LOW = usual.event.BATTERY_LOW,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BATTERY_OKAY = usual.event.BATTERY_OKAY,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_POWER_CONNECTED = usual.event.POWER_CONNECTED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_POWER_DISCONNECTED = usual.event.POWER_DISCONNECTED,|新增| -| -|事件通知-commonEvent|function unsubscribe(subscriber: CommonEventSubscriber, callback?: AsyncCallback): void;|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_ACL_CONNECTED = usual.event.bluetooth.remotedevice.ACL_CONNECTED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_ACL_DISCONNECTED = usual.event.bluetooth.remotedevice.ACL_DISCONNECTED,|新增| -| -|事件通知-commonEvent|getAbortCommonEvent(callback: AsyncCallback): void;|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_NAME_UPDATE = usual.event.bluetooth.remotedevice.NAME_UPDATE,|新增| -| -|事件通知-commonEvent|getAbortCommonEvent(): Promise;|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_CONNECT_STATE_UPDATE = usual.event.bluetooth.handsfreeunit.CONNECT_STATE_UPDATE,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIR_STATE = usual.event.bluetooth.remotedevice.PAIR_STATE,|新增| -| -|事件通知-commonEvent|getCode(callback: AsyncCallback): void;|新增| -| -|事件通知-commonEvent|setCode(code: number): Promise;|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_AUDIO_STATE_UPDATE = usual.event.bluetooth.handsfreeunit.AUDIO_STATE_UPDATE,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_BATTERY_VALUE_UPDATE = usual.event.bluetooth.remotedevice.BATTERY_VALUE_UPDATE,|新增| -| -|事件通知-commonEvent|getCode(): Promise;|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_AG_COMMON_EVENT = usual.event.bluetooth.handsfreeunit.AG_COMMON_EVENT,|新增| -| -|事件通知-commonEvent|setCodeAndData(code: number, data: string, callback: AsyncCallback): void;|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_SDP_RESULT = usual.event.bluetooth.remotedevice.SDP_RESULT,|新增| -| -|事件通知-commonEvent|isStickyCommonEvent(callback: AsyncCallback): void;|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_AG_CALL_STATE_UPDATE = usual.event.bluetooth.handsfreeunit.AG_CALL_STATE_UPDATE,|新增| -| -|事件通知-commonEvent|setCodeAndData(code: number, data: string): Promise;|新增| -| -|事件通知-commonEvent|events: Array;|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_HOST_STATE_UPDATE = usual.event.bluetooth.host.STATE_UPDATE,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_A2DPSOURCE_PLAYING_STATE_UPDATE = usual.event.bluetooth.a2dpsource.PLAYING_STATE_UPDATE,|新增| -| -|事件通知-commonEvent|setData(data: string, callback: AsyncCallback): void;|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_A2DPSOURCE_AVRCP_CONNECT_STATE_UPDATE = usual.event.bluetooth.a2dpsource.AVRCP_CONNECT_STATE_UPDATE,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_HOST_REQ_DISCOVERABLE = usual.event.bluetooth.host.REQ_DISCOVERABLE,|新增| -| -|事件通知-commonEvent|publisherPermission?: string;|新增| -| -|事件通知-commonEvent|setData(data: string): Promise;|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_UUID_VALUE = usual.event.bluetooth.remotedevice.UUID_VALUE,|新增| -| -|事件通知-commonEvent|publisherDeviceId?: string;|新增| -| -|事件通知-commonEvent|clearAbortCommonEvent(callback: AsyncCallback): void;|新增| -| -|事件通知-commonEvent|userId?: number;|新增| -| -|事件通知-commonEvent|COMMON_EVENT_TIMEZONE_CHANGED = usual.event.TIMEZONE_CHANGED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIRING_REQ = usual.event.bluetooth.remotedevice.PAIRING_REQ,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_DISCOVERED = usual.event.bluetooth.remotedevice.DISCOVERED,|新增| -| -|事件通知-commonEvent|priority?: number;|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BUNDLE_REMOVED = usual.event.BUNDLE_REMOVED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CLASS_VALUE_UPDATE = usual.event.bluetooth.remotedevice.CLASS_VALUE_UPDATE,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIRING_CANCEL = usual.event.bluetooth.remotedevice.PAIRING_CANCEL,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_CLOSE_SYSTEM_DIALOGS = usual.event.CLOSE_SYSTEM_DIALOGS,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_PACKAGE_ADDED = usual.event.PACKAGE_ADDED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CONNECT_REQ = usual.event.bluetooth.remotedevice.CONNECT_REQ,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_PACKAGE_FULLY_REMOVED = usual.event.PACKAGE_FULLY_REMOVED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_PACKAGE_REPLACED = usual.event.PACKAGE_REPLACED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CONNECT_REPLY = usual.event.bluetooth.remotedevice.CONNECT_REPLY,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_MY_PACKAGE_REPLACED = usual.event.MY_PACKAGE_REPLACED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_PACKAGE_CHANGED = usual.event.PACKAGE_CHANGED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CONNECT_CANCEL = usual.event.bluetooth.remotedevice.CONNECT_CANCEL,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_PACKAGE_REMOVED = usual.event.PACKAGE_REMOVED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_PACKAGE_RESTARTED = usual.event.PACKAGE_RESTARTED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_PACKAGE_DATA_CLEARED = usual.event.PACKAGE_DATA_CLEARED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_PACKAGES_SUSPENDED = usual.event.PACKAGES_SUSPENDED,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CODEC_VALUE_UPDATE = usual.event.bluetooth.a2dpsource.CODEC_VALUE_UPDATE,|新增| -| -|事件通知-commonEvent|COMMON_EVENT_WIFI_P2P_PEERS_DISCOVERY_STATE_CHANGED = usual.event.wifi.p2p.PEER_DISCOVERY_STATE_CHANGE,|新增| -| -|事件通知-notification|LEVEL_NONE = 0,|新增| -| -|事件通知-notification|LEVEL_MIN = 1,|新增| -| -|事件通知-notification|LEVEL_LOW = 2,|新增| -| -|事件通知-notification|LEVEL_DEFAULT = 3,|新增| -| -|事件通知-notification|label?: string;|新增| -| -|事件通知-notification|bundle: string;|新增| -| -|事件通知-notification|uid?: number;|新增| -| -|事件通知-notification|NOTIFICATION_CONTENT_MULTILINE,|新增| -| -|事件通知-notification|UNKNOWN_TYPE = 0,|新增| -| -|事件通知-notification|SOCIAL_COMMUNICATION = 1,|新增| -| -|事件通知-notification|LEVEL_HIGH = 4,|新增| -| -|事件通知-notification|NOTIFICATION_CONTENT_BASIC_TEXT,|新增| -| -|事件通知-notification|NOTIFICATION_CONTENT_LONG_TEXT,|新增| -| -|事件通知-notification|NOTIFICATION_CONTENT_PICTURE,|新增| -| -|事件通知-notification|isFloatingIcon?: boolean;|新增| -| -|事件通知-notification|label?: string;|新增| -| -|事件通知-notification|badgeIconStyle?: number;|新增| -| -|事件通知-notification|showDeliveryTime?: boolean;|新增| -| -|事件通知-notification|isAlertOnce?: boolean;|新增| -| -|事件通知-notification|function getActiveNotifications(callback: AsyncCallback>): void;|新增| -| -|事件通知-notification|isStopwatch?: boolean;|新增| -| -|事件通知-notification|isCountDown?: boolean;|新增| -| -|事件通知-notification|function getActiveNotifications(): Promise>;|新增| -| -|事件通知-notification|function getActiveNotificationCount(callback: AsyncCallback): void;|新增| -| -|事件通知-notification|readonly creatorUid?: number;|新增| -| -|事件通知-notification|function getActiveNotificationCount(): Promise;|新增| -| -|事件通知-notification|readonly creatorPid?: number;|新增| -| -|事件通知-notification|function cancel(id: number, label?: string): Promise;|新增| -| -|事件通知-notification|classification?: string;|新增| -| -|事件通知-notification|readonly hashCode?: string;|新增| -| -|事件通知-notification|function cancelAll(callback: AsyncCallback): void;|新增| -| -|事件通知-notification|actionButtons?: Array;|新增| -| -|事件通知-notification|function cancelAll(): Promise;|新增| -| -|事件通知-notification|smallIcon?: image.PixelMap;|新增| -| -|事件通知-notification|isUnremovable?: boolean;|新增| -| -|事件通知-notification|largeIcon?: image.PixelMap;|新增| -| -|事件通知-notification|deliveryTime?: number;|新增| -| -|事件通知-notification|readonly creatorBundleName?: string;|新增| -| -|事件通知-notification|tapDismissed?: boolean;|新增| -| -|事件通知-notification|function publish(request: NotificationRequest): Promise;|新增| -| -|事件通知-notification|autoDeletedTime?: number;|新增| -| -|事件通知-notification|function cancel(id: number, callback: AsyncCallback): void;|新增| -| -|事件通知-notification|content: NotificationContent;|新增| -| -|事件通知-notification|wantAgent?: WantAgentInfo;|新增| -| -|事件通知-notification|function cancel(id: number, label: string, callback: AsyncCallback): void;|新增| -| -|事件通知-notification|function getSlot(slotType: SlotType, callback: AsyncCallback): void;|新增| -| -|事件通知-notification|extraInfo?: {[key: string]: any};|新增| -| -|事件通知-notification|function getSlot(slotType: SlotType): Promise;|新增| -| -|事件通知-notification|SERVICE_INFORMATION = 2,|新增| -| -|事件通知-notification|color?: number;|新增| -| -|事件通知-notification|id?: number;|新增| -| -|事件通知-notification|function getSlots(callback: AsyncCallback>): void;|新增| -| -|事件通知-notification|CONTENT_INFORMATION = 3,|新增| -| -|事件通知-notification|slotType?: notification.SlotType;|新增| -| -|事件通知-notification|colorEnabled?: boolean;|新增| -| -|事件通知-notification|OTHER_TYPES = 0xFFFF,|新增| -| -|事件通知-notification|isOngoing?: boolean;|新增| -| -|事件通知-notification|function addSlot(type: SlotType, callback: AsyncCallback): void;|新增| -| -|事件通知-notification|id: number;|新增| -| -|事件通知-notification|function addSlot(type: SlotType): Promise;|新增| -| -|事件通知-notification|desc?: string;|新增| -| -|事件通知-notification|function publish(request: NotificationRequest, callback: AsyncCallback): void;|新增| -| -|事件通知-notification|function removeAllSlots(callback: AsyncCallback): void;|新增| -| -|事件通知-notification|function removeAllSlots(): Promise;|新增| -| -|事件通知-notification|function getSlots(): Promise>;|新增| -| -|事件通知-notification|function removeSlot(slotType: SlotType, callback: AsyncCallback): void;|新增| -| -|事件通知-notification|function removeSlot(slotType: SlotType): Promise;|新增| -| -|全球化-resourceManager|getString(resId: number, callback: AsyncCallback);getString(resId: number): Promise;|新增| -| -|全球化-resourceManager|getStringArray(resId: number, callback: AsyncCallback>);getStringArray(resId: number): Promise>;|新增| -| -|全球化-resourceManager|getConfiguration(callback: AsyncCallback);getConfiguration(): Promise;|新增| -| -|全球化-resourceManager|getDeviceCapability(callback: AsyncCallback);getDeviceCapability(): Promise;|新增| -| -|全球化-resourceManager|getMedia(resId: number, callback: AsyncCallback);getMedia(resId: number): Promise;getMediaBase64(resId: number, callback: AsyncCallback);getMediaBase64(resId: number): Promise;|新增| -| -|全球化-resourceManager|"getPluralString(resId: number, num: number, callback: AsyncCallback);getPluralString(resId: number, num: number): Promise;"|新增| -| -|全球化-resourceManager|DeviceCapability|新增| -| -|全球化-resourceManager|"getMediaBase64(resId: number, callback: AsyncCallback);getMediaBase64(resId: number): Promise;"|新增| -| -|全球化-resourceManager|"getResourceManager(callback: AsyncCallback);getResourceManager(bundleName: string, callback: AsyncCallback);getResourceManager(): Promise;getResourceManager(bundleName: string): Promise;"|新增| -| -|全球化-resourceManager|DeviceType|新增| -| -|全球化-resourceManager|Direction|新增| -| -|全球化-resourceManager|Configuration|新增| -| -|全球化-resourceManager|ScreenDensity|新增| -| -|全球化-resourceManager|deviceType|新增| -| -|全球化-resourceManager|locale|新增| -| -|全球化-resourceManager|direction|新增| -| -|全球化-resourceManager|screenDensity|新增| -| -|电源服务-batteryInfo|batteryInfo:const batterySOC: number;|新增| -| -|电源服务-batteryInfo|batteryInfo:const technology: string;|新增| -| -|电源服务-batteryInfo|batteryInfo:const isBatteryPresent: boolean;|新增| -| -|电源服务-batteryInfo|batteryInfo:const batteryTemperature: number;|新增| -| -|电源服务-batteryInfo|batteryInfo:const pluggedType: BatteryPluggedType;|新增| -| -|电源服务-batteryInfo|batteryInfo:const chargingStatus: BatteryChargeState;|新增| -| -|电源服务-batteryInfo|batteryInfo:const healthStatus: BatteryHealthState;|新增| -| -|电源服务-batteryInfo|batteryInfo:const voltage: number;|新增| -| -|电源服务-batteryInfo|BatteryChargeState:NONE|新增| -| -|电源服务-batteryInfo|BatteryChargeState:DISABLE|新增| -| -|电源服务-batteryInfo|BatteryChargeState:ENABLE,|新增| -| -|电源服务-batteryInfo|BatteryChargeState:FULL|新增| -| -|电源服务-batteryInfo|BatteryHealthState:COLD|新增| -| -|电源服务-batteryInfo|BatteryHealthState:OVERHEAT|新增| -| -|电源服务-batteryInfo|BatteryHealthState:OVERVOLTAGE|新增| -| -|电源服务-batteryInfo|BatteryHealthState:DEAD|新增| -| -|电源服务-batteryInfo|BatteryHealthState:UNKNOWN|新增| -| -|电源服务-batteryInfo|BatteryHealthState:GOOD|新增| -| -|电源服务-batteryInfo|BatteryPluggedType:WIRELESS|新增| -| -|电源服务-batteryInfo|BatteryPluggedType:NONE|新增| -| -|电源服务-batteryInfo|BatteryPluggedType:AC|新增| -| -|电源服务-batteryInfo|BatteryPluggedType:USB|新增| -| -|电源服务-runningLock|RunningLock:unlock()|新增| -| -|电源服务-runningLock|runningLock:isRunningLockTypeSupported(type: RunningLockType, callback: AsyncCallback): void;|新增| -| -|电源服务-runningLock|runningLock:createRunningLock(name: string, type: runningLockType): RunningLock|新增| -| -|电源服务-runningLock|RunningLock:lock(timeout: number)|新增| -| -|电源服务-runningLock|RunningLock:isUsed(): boolean|新增| -| -|电源服务-runninglock|RunningLockType:BACKGROUND|新增| -| -|电源服务-runninglock|RunningLockType:PROXIMITY_SCREEN_CONTROL|新增| -| -|电源服务-power|power:rebootDevice(reason ?: string)|新增| -| -|电源服务-power|power:isScreenOn(callback: AsyncCallback): void;|新增| -| diff --git a/website/docs/_posts/zh-cn/release-notes/api-change/v3.1-LTS/js-apidiff-v3.1-LTS.md b/website/docs/_posts/zh-cn/release-notes/api-change/v3.1-LTS/js-apidiff-v3.1-LTS.md deleted file mode 100644 index a8f54db1a925502894e49738bc33d33ab6895dcc..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/release-notes/api-change/v3.1-LTS/js-apidiff-v3.1-LTS.md +++ /dev/null @@ -1,27 +0,0 @@ ---- -title: js-apidiff-v3.1-LTS -permalink: /pages/extra/d546b2/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# JS API Diff - -OpenHarmony 3.1 LTS版本相较于OpenHarmony 3.1 Beta版本的API变更如下: - -## 接口变更 - -| 模块名称 | 接口名称 | 变更类型 | 变更说明 | -| -------- | -------- | -------- | -------- | -| 分布式硬件子系统-DeviceManager | release(): void | 删除 | 为了降低安全风险,删除设备管理JS API | -| 分布式硬件子系统-DeviceManager | getTrustedDeviceListSync(): Array | 删除 | 为了降低安全风险,删除设备管理JS API | -| 分布式硬件子系统-DeviceManager | on(type: 'deviceStateChange', callback: Callback<{ action: DeviceStateChangeAction, device: DeviceInfo }>): void | 删除 | 为了降低安全风险,删除设备管理JS API | -| 分布式硬件子系统-DeviceManager | off(type: 'deviceStateChange', callback?: Call back<{ action: DeviceStateChangeAction, device: DeviceInfo }>): void | 删除 | 为了降低安全风险,删除设备管理JS API | -| 分布式硬件子系统-DeviceManager | on(type: 'serviceDie', callback: () => void): void | 删除 | 为了降低安全风险,删除设备管理JS API | -| 分布式硬件子系统-DeviceManager | off(type: 'serviceDie', callback?: () => void): void | 删除 | 为了降低安全风险,删除设备管理JS API | \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/release-notes/api-change/v3.1-beta/changelog-v3.1-beta.md b/website/docs/_posts/zh-cn/release-notes/api-change/v3.1-beta/changelog-v3.1-beta.md deleted file mode 100644 index 4f64f2310813aea2ef990d719405e3a52fbf5d1f..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/release-notes/api-change/v3.1-beta/changelog-v3.1-beta.md +++ /dev/null @@ -1,56 +0,0 @@ ---- -title: changelog-v3.1-beta -permalink: /pages/extra/15af11/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# ChangeLog -##### 关键的接口/组件变更 -## 进程间通信子系统 -#### cl.rpc.1 sendRequest返回值类型变更 - -##### 变更影响 - -js的RemoteProxy和RemoteObject的sendRequest变更为异步接口,返回Promise,兑现值是SendRequestResult的实例。原有应用需要适配。 - -##### 关键的接口/组件变更 - -``` -模块:ohos.rpc.IRemoteObject, ohos.rpc.RemoteProxy和ohos.rpc.RemoteObject -接口:sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): boolean - -变更后接口: -sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): Promise -``` - -**适配指导** - -``` -import rpc from "@ohos.rpc" - -let option = new rpc.MessageOption() -let data = rpc.MessageParcel.create() -let reply = rpc.MessageParcel.create() -proxy.sendRequest(1, data, reply, option) - .then(function(result) { - console.info("send request done") - if (result.errCode === 0) { - // read result from result.reply - } - }) - .catch(function(e) { - console.error("send request failed: " + e) - }) - .finally(() => { - data.reclaim() - reply.reclaim() - }) -``` - diff --git a/website/docs/_posts/zh-cn/release-notes/api-change/v3.1-beta/js-apidiff-v3.1-beta.md b/website/docs/_posts/zh-cn/release-notes/api-change/v3.1-beta/js-apidiff-v3.1-beta.md deleted file mode 100644 index 4da63fd547d68676c3ac606a041ad7f6c1cc9dc7..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/release-notes/api-change/v3.1-beta/js-apidiff-v3.1-beta.md +++ /dev/null @@ -1,440 +0,0 @@ ---- -title: js-apidiff-v3.1-beta -permalink: /pages/extra/38355d/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# JS API 差异报告 - -OpenHarmony 3.1 Beta相较于OpenHarmony 3.0 LTS版本的API变更如下: - -## 标准系统接口变更 - -| 模块名称 | 接口名称 | 变更类型 | 变更说明 | -| -------- | -------- | -------- | -------- | -| 系统应用-settings | getUri(name: string): string | 新增 | 新增获取设置数据URI | -| 系统应用-settings | getValue(dataAbilityHelper: DataAbilityHelper, name: string, defValue: string): string | 新增 | 新增获取设置数据库值 | -| 系统应用-settings | setValue(dataAbilityHelper: DataAbilityHelper, name: string, value: string): boolean | 新增 | 新增设置设置数据库值 | -| 杂散软件服务-systemTime | getCurrentTime(callback: AsyncCallback): void | 新增 | 获取自 Unix 纪元以来经过的毫秒数。 | -| 杂散软件服务-systemTime | getCurrentTime(): Promise | 新增 | 获取自 Unix 纪元以来经过的毫秒数。 | -| 杂散软件服务-systemTime | getCurrentTimeNs(callback: AsyncCallback): void | 新增 | 获取自 Unix 纪元以来经过的纳秒数。 | -| 杂散软件服务-systemTime | getCurrentTimeNs(): Promise | 新增 | 获取自 Unix 纪元以来经过的纳秒数。 | -| 杂散软件服务-systemTime | getRealActiveTime(callback: AsyncCallback): void | 新增 | 获取自系统启动以来经过的毫秒数,不包括深度睡眠时间。 | -| 杂散软件服务-systemTime | getRealActiveTime(): Promise | 新增 | 获取自系统启动以来经过的毫秒数,不包括深度睡眠时间。 | -| 杂散软件服务-systemTime | getRealActiveTimeNs(callback: AsyncCallback): void | 新增 | 获取自系统启动以来经过的纳秒数,不包括深度睡眠时间。 | -| 杂散软件服务-systemTime | getRealActiveTimeNs(): Promise | 新增 | 获取自系统启动以来经过的纳秒数,不包括深度睡眠时间。 | -| 杂散软件服务-systemTime | getRealTime(callback: AsyncCallback): void | 新增 | 获取自系统启动以来经过的毫秒数,包括深度睡眠时间。 | -| 杂散软件服务-systemTime | getRealTime(): Promise | 新增 | 获取自系统启动以来经过的毫秒数,包括深度睡眠时间。 | -| 杂散软件服务-systemTime | getRealTimeNs(callback: AsyncCallback): void | 新增 | 获取自系统启动以来经过的纳秒数,包括深度睡眠时间。 | -| 杂散软件服务-systemTime | getRealTimeNs(): Promise | 新增 | 获取自系统启动以来经过的纳秒数,包括深度睡眠时间。 | -| 杂散软件服务-systemTime | getDate(callback: AsyncCallback): void | 新增 | 获取当前时间。 | -| 杂散软件服务-systemTime | getDate(): Promise | 新增 | 获取当前时间。 | -| 杂散软件服务-systemTime | getTimeZone(callback: AsyncCallback): void | 新增 | 获取系统时区。 | -| 杂散软件服务-systemTime | getTimeZone(): Promise | 新增 | 获取系统时区。 | -| Ark UI框架-通用事件 | 组件区域变化事件 onAreaChange | 新增 | 新增组件区域(包括大小和位置)变化事件。 | -| Ark UI框架-通用属性 | 触摸热区设置 responseRegion | 新增 | 新增组件触摸热区设置。 | -| Ark UI框架-通用属性 | 点击控制 touchable | 新增 | 新增设置组件是否可以被触摸。 | -| Ark UI框架-通用属性 | 多态样式 stateStyle | 新增 | 新增设置组件按压态和禁用态的样式。 | -| Ark UI框架-通用手势 | SwipeGesture | 新增 | 新增滑动手势。 | -| Ark UI框架-基础组件 | Marquee | 新增 | 新增跑马灯组件。 | -| Ark UI框架-基础组件 | PluginComponent | 新增 | 新增插件组件。 | -| Ark UI框架-基础组件 | TextArea | 新增 | 新增输入区域组件。 | -| Ark UI框架-基础组件 | TextInput | 新增 | 新增输入框组件。 | -| Ark UI框架-基础组件 | Toggle | 新增 | 新增状态组件。 | -| Ark UI框架-容器组件 | ScrollBar | 新增 | 新增滚动条组件。 | -| Ark UI框架-容器组件 | Navigation | 新增 | 新增页面导航组件。 | -| Ark UI框架-容器组件 | Stepper | 新增 | 新增步骤导航器组件。 | -| Ark UI框架-容器组件 | StepperItem | 新增 | 新增步骤导航器导航项组件。 | -| Ark UI框架-画布组件 | Canvas | 新增 | 新增画布组件。 | -| Ark UI框架-画布组件 | Lottie | 新增 | 新增Lottie库的支持。 | -| Ark UI框架-全局UI方法 | ActionSheet | 新增 | 新增列表选择弹窗。 | -| USB服务-usb | getDevices(): Array> | 新增 | 新增获取USB设备列表的接口 | -| USB服务-usb | connectDevice(device: USBDevice): Readonly | 新增 | 新增根据**getDevices()**返回的设备信息打开USB设备的接口 | -| USB服务-usb | hasRight(deviceName: string): boolean | 新增 | 新增判断是否有权访问设备的接口 | -| USB服务-usb | requestRight(deviceName: string): Promise | 新增 | 新增请求给定软件包的临时权限以访问设备的接口 | -| USB服务-usb | claimInterface(pipe: USBDevicePipe, iface: USBInterface, force?: boolean): number | 新增 | 新增获取接口的接口 | -| USB服务-usb | releaseInterface(pipe: USBDevicePipe, iface: USBInterface): number | 新增 | 新增释放接口的接口 | -| USB服务-usb | setConfiguration(pipe: USBDevicePipe, config: USBConfig): number | 新增 | 新增设置设备配置的接口 | -| USB服务-usb | setInterface(pipe: USBDevicePipe, iface: USBInterface): number | 新增 | 新增设置设备接口的接口 | -| USB服务-usb | getRawDescriptor(pipe: USBDevicePipe): Uint8Array | 新增 | 新增获取原始的USB描述符的接口 | -| USB服务-usb | getFileDescriptor(pipe: USBDevicePipe): number | 新增 | 新增获取文件描述符的接口 | -| USB服务-usb | controlTransfer(pipe: USBDevicePipe, contrlparam: USBControlParams, timeout?: number): Promise | 新增 | 新增控制传输的接口 | -| USB服务-usb | bulkTransfer(pipe: USBDevicePipe, endpoint: USBEndpoint, buffer: Uint8Array, timeout?: number): Promise | 新增 | 新增批量传输的接口 | -| USB服务-usb | closePipe(pipe: USBDevicePipe): number | 新增 | 新增关闭USBDevicePipe的接口 | -| 用户程序框架-bundle | function cleanBundleCacheFiles(bundleName: string, callback: AsyncCallback): void;
function cleanBundleCacheFiles(bundleName: string): Promise; | 新增 | 新增清理应用缓存接口 | -| 用户程序框架-bundle | function setApplicationEnabled(bundleName: string, isEnable: boolean, callback: AsyncCallback): void;
function setApplicationEnabled(bundleName: string, isEnable: boolean): Promise; | 新增 | 新增设置应用使能接口 | -| 用户程序框架-bundle | function setAbilityEnabled(info: AbilityInfo, isEnable: boolean, callback: AsyncCallback): void;
function setAbilityEnabled(info: AbilityInfo, isEnable: boolean): Promise; | 新增 | 新增设置ability使能接口 | -| 用户程序框架-bundle.innerBundleManager | function getLauncherAbilityInfos(bundleName: string, userId: number, callback: AsyncCallback>) : void;
function getLauncherAbilityInfos(bundleName: string, userId: number) : Promise>; | 新增 | 新增通过包名获取应用LauncherAbility接口 | -| 用户程序框架-bundle.innerBundleManager | function on(type:"BundleStatusChange", bundleStatusCallback : BundleStatusCallback, callback: AsyncCallback) : void;
function on(type:"BundleStatusChange", bundleStatusCallback : BundleStatusCallback): Proimise; | 新增 | 新增注册监听包状态变化接口 | -| 用户程序框架-bundle.innerBundleManager | function off(type:"BundleStatusChange", callback: AsyncCallback) : void;
function off(type:"BundleStatusChange"): Proimise; | 新增 | 新增注销监听包状态变化接口 | -| 用户程序框架-bundle.innerBundleManager | function getAllLauncherAbilityInfos(userId: number, callback: AsyncCallback>) : void;
function getAllLauncherAbilityInfos(userId: number) : Promise>; | 新增 | 新增通过userId获取所有launcher上应用的ability接口 | -| 用户程序框架-bundle.innerBundleManager | function getShortcutInfos(bundleName :string, callback: AsyncCallback>) : void;
function getShortcutInfos(bundleName : string) : Promise>; | 新增 | 新增通过bundleName获取应用的shortcutInfo接口 | -| 分布式软总线-rpc.MessageParcel | writeNoException(): void | 新增 | - | -| 分布式软总线-rpc.MessageParcel | readException(): void | 新增 | - | -| 分布式软总线-rpc.MessageParcel | writeRemoteObjectArray(objectArray: IRemoteObject[]): boolean | 新增 | - | -| 分布式软总线-rpc.MessageParcel | readSequenceableArray(sequenceableArray Sequenceable[]): void | 新增 | - | -| 分布式软总线-rpc.MessageParcel | readRemoteObjectArray(objects: IRemoteObject[]): void | 新增 | - | -| 分布式软总线-rpc.MessageParcel | readRemoteObjectArray(): IRemoteObject[] | 新增 | - | -| 分布式软总线-rpc.MessageParcel | static closeFileDescriptor(fd: number): void | 新增 | - | -| 分布式软总线-rpc.MessageParcel | static dupFileDescriptor(fd: number) :number | 新增 | - | -| 分布式软总线-rpc.MessageParcel | containFileDescriptors(): boolean | 新增 | - | -| 分布式软总线-rpc.MessageParcel | writeFileDescriptor(fd: number): boolean | 新增 | - | -| 分布式软总线-rpc.MessageParcel | readFileDescriptor(): number | 新增 | - | -| 分布式软总线-rpc.MessageParcel | writeAshmem(ashmem: Ashmem): boolean | 新增 | - | -| 分布式软总线-rpc.MessageParcel | readAshmem(): Ashmem | 新增 | - | -| 分布式软总线-rpc.MessageParcel | getRawDataCapacity(): number | 新增 | - | -| 分布式软总线-rpc.MessageParcel | writeRawData(rawData: number[], size: number): boolean | 新增 | - | -| 分布式软总线-rpc.MessageParcel | readRawData(size: number): number[] | 新增 | - | -| 分布式软总线-rpc | interface SendRequestResult {
errCode: number;

code: number;

data: MessageParcel;

reply: MessageParcel;
} | 新增 | - | -| 分布式软总线-rpc.Ashmem | PROT_EXEC = 4 | 新增 | - | -| 分布式软总线-rpc.Ashmem | PROT_NONE = 0 | 新增 | - | -| 分布式软总线-rpc.Ashmem | PROT_READ = 1 | 新增 | - | -| 分布式软总线-rpc.Ashmem | PROT_WRITE = 2 | 新增 | - | -| 分布式软总线-rpc.Ashmem | static createAshmem(name: string, size: number): Ashmem | 新增 | - | -| 分布式软总线-rpc.Ashmem | static createAshmemFromExisting(ashmem: Ashmem): Ashmem | 新增 | - | -| 分布式软总线-rpc.Ashmem | closeAshmem(): void | 新增 | - | -| 分布式软总线-rpc.Ashmem | unmapAshmem(): void | 新增 | - | -| 分布式软总线-rpc.Ashmem | getAshmemSize(): number | 新增 | - | -| 分布式软总线-rpc.Ashmem | mapAshmem(mapType: number): boolean | 新增 | - | -| 分布式软总线-rpc.Ashmem | mapReadAndWriteAshmem(): boolean | 新增 | - | -| 分布式软总线-rpc.Ashmem | mapReadOnlyAshmem(): boolean | 新增 | - | -| 分布式软总线-rpc.Ashmem | setProtection(protectionType: number): boolean | 新增 | - | -| 分布式软总线-rpc.Ashmem | writeToAshmem(buf: number[], size: number, offset: number): boolean | 新增 | - | -| 分布式软总线-rpc.Ashmem | readFromAshmem(size: number, offset: number): number[] | 新增 | - | -| 分布式软总线-rpc.IRemoteObject | sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): boolean | 废弃 | 替换为异步接口,使用返回Promise或者回调的接口 | -| 分布式软总线-rpc.IRemoteObject | sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): Promise | 新增 | - | -| 分布式软总线-rpc.IRemoteObject | sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption, callback: AsyncCallback): void | 新增 | - | -| 分布式软总线-rpc.RemoteProxy | sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): boolean | 废弃 | 替换为异步接口,使用返回Promise或者回调的接口 | -| 分布式软总线-rpc.RemoteProxy | sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): Promise | 新增 | - | -| 分布式软总线-rpc.RemoteProxy | sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption, callback: AsyncCallback): void | 新增 | - | -| 分布式软总线-rpc.RemoteObject | sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): boolean | 废弃 | 替换为异步接口,使用返回Promise或者回调的接口 | -| 分布式软总线-rpc.RemoteObject | sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): Promise | 新增 | - | -| 分布式软总线-rpc.RemoteObject | sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption, callback: AsyncCallback): void | 新增 | - | -| 分布式软总线-rpc.IRemoteObject | PING_TRANSACTION | 删除 | API 7没有实现,不影响已有应用 | -| 分布式软总线-rpc.IRemoteObject | DUMP_TRANSACTION | 删除 | API 7没有实现,不影响已有应用 | -| 分布式软总线-rpc.IRemoteObject | INTERFACE_TRANSACTION | 删除 | API 7没有实现,不影响已有应用 | -| 分布式软总线-rpc.IRemoteObject | MIN_TRANSACTION_ID | 删除 | API 7没有实现,不影响已有应用 | -| 分布式软总线-rpc.IRemoteObject | MAX_TRANSACTION_ID | 删除 | API 7没有实现,不影响已有应用 | -| 分布式软总线-rpc.Sequenceable | hasFileDescriptor(): boolean | 删除 | API 7可序列化对象定义的方法,rpc框架不会调用,不影响已有应用 | -| 分布式软总线-rpc.MessageOption | constructor(syncFlags?: number, waitTime = TF_WAIT_TIME) | 新增 | - | -| 分布式软总线-rpc.MessageOption | getFlags(): number | 新增 | - | -| 分布式软总线-rpc.MessageOption | setFlags(flags: number): void | 新增 | - | -| 分布式软总线-rpc.MessageOption | getWaitTime(): number | 新增 | - | -| 分布式软总线-rpc.MessageOption | setWaitTime(waitTime: number): void | 新增 | - | -| 分布式软总线-rpc.MessageOption | MAX_WAIT_TIME = 3000 | 删除 | API 7没有实现,不影响已有应用 | -| 分布式软总线-rpc.RemoteObject | constructor(descriptor: string) | 新增 | - | -| 分布式软总线-rpc.RemoteObject | queryLocalInterface(descriptor: string): IRemoteBroker | 修改 | API 7有误,返回类型更正为IRemoteBroker,不影响已有应用 | -| 分布式软总线-rpc.Proxy | PING_TRANSACTION | 新增 | - | -| 分布式软总线-rpc.Proxy | DUMP_TRANSACTION | 新增 | - | -| 分布式软总线-rpc.Proxy | INTERFACE_TRANSACTION | 新增 | - | -| 分布式软总线-rpc.Proxy | MIN_TRANSACTION_ID = 0x1 | 新增 | - | -| 分布式软总线-rpc.Proxy | MAX_TRANSACTION_ID = 0x00FFFFFF | 新增 | - | -| 分布式软总线-rpc.Proxy | queryLocalInterface(interface: string): IRemoteBroker | 修改 | API 7有误,返回类型更正为IRemoteBroker,不影响已有应用 | -| 分布式软总线-wifi | function getLinkedInfo(): Promise;
function getLinkedInfo(callback: AsyncCallback): void;| 新增 | - | -| 分布式软总线-wifi | function isConnected(): boolean;| 新增 | - | -| 分布式软总线-wifi | function getSupportedFeatures(): number;| 新增 | - | -| 分布式软总线-wifi | function isFeatureSupported(featureId: number): boolean;| 新增 | - | -| 分布式软总线-wifi | function getDeviceMacAddress(): string[];| 新增 | - | -| 分布式软总线-wifi | function getIpInfo(): IpInfo;| 新增 | - | -| 分布式软总线-wifi | function getCountryCode(): string;| 新增 | - | -| 分布式软总线-wifi | function reassociate(): boolean;| 新增 | - | -| 分布式软总线-wifi | function reconnect(): boolean;| 新增 | - | -| 分布式软总线-wifi | function getDeviceConfigs(): Array;| 新增 | - | -| 分布式软总线-wifi | function updateNetwork(config: WifiDeviceConfig): number;| 新增 | - | -| 分布式软总线-wifi | function disableNetwork(netId: number): boolean;| 新增 | - | -| 分布式软总线-wifi | function removeAllNetwork(): boolean;| 新增 | - | -| 分布式软总线-wifi | function removeDevice(id: number): boolean;| 新增 | - | -| 分布式软总线-wifi | function enableHotspot(): boolean;| 新增 | - | -| 分布式软总线-wifi | function disableHotspot(): boolean;| 新增 | - | -| 分布式软总线-wifi | function isHotspotActive(): boolean;| 新增 | - | -| 分布式软总线-wifi | function setHotspotConfig(config: HotspotConfig): boolean;| 新增 | - | -| 分布式软总线-wifi | function getHotspotConfig(): HotspotConfig;| 新增 | - | -| 分布式软总线-wifi | function getStations(): Array;| 新增 | - | -| 分布式软总线-wifi | function on(type: "wifiStateChange", callback: Callback): void;| 新增 | - | -| 分布式软总线-wifi | function off(type: "wifiStateChange", callback?: Callback): void;| 新增 | - | -| 分布式软总线-wifi | function on(type: "wifiConnectionChange", callback: Callback): void;| 新增 | - | -| 分布式软总线-wifi | function off(type: "wifiConnectionChange", callback?: Callback): void;| 新增 | - | -| 分布式软总线-wifi | function on(type: "wifiScanStateChange", callback: Callback): void;| 新增 | - | -| 分布式软总线-wifi | function off(type: "wifiScanStateChange", callback?: Callback): void;| 新增 | - | -| 分布式软总线-wifi | function on(type: "wifiRssiChange", callback: Callback): void;| 新增 | - | -| 分布式软总线-wifi | function off(type: "wifiRssiChange", callback?: Callback): void;| 新增 | - | -| 分布式软总线-wifi | function on(type: "hotspotStateChange", callback: Callback): void;| 新增 | - | -| 分布式软总线-wifi | function off(type: "hotspotStateChange", callback?: Callback): void;| 新增 | - | -| 分布式软总线-wifi | function on(type: "hotspotStaJoin", callback: Callback): void;| 新增 | - | -| 分布式软总线-wifi | function off(type: "hotspotStaJoin", callback?: Callback): void;| 新增 | - | -| 分布式软总线-wifi | function on(type: "hotspotStaLeave", callback: Callback): void;| 新增 | - | -| 分布式软总线-wifi | function off(type: "hotspotStaLeave", callback?: Callback): void;| 新增 | - | -| 全球化-resourceManager | getRawFile(path: string, callback: AsyncCallback);
getRawFile(path: string): Promise;| 新增 | - | -| 全球化-Intl | RelativeTimeFormat.constructor(); | 新增 | 构造函数 | -| 全球化-Intl | RelativeTimeFormat.constructor(locale: string \| Array, options?: RelativeTimeFormatInputOptions); | 新增 | 构造函数 | -| 全球化-Intl | RelativeTimeFormat.format(value: number, unit: string): string; | 新增 | 相对时间格式化 | -| 全球化-Intl | RelativeTimeFormat.formatToParts(value: number, unit: string): Array; | 新增 | 相对时间格式化,结果分为多部份分别存储 | -| 全球化-Intl | RelativeTimeFormat.formatToParts(value: number, unit: string): Array; | 新增 | 相对时间格式化,结果分为多部份分别存储 | -| 全球化-Intl | PluralRules.constructor(); | 新增 | 构造函数 | -| 全球化-Intl | PluralRules.constructor(locale: string \| Array, options?: PluralRulesOptions); | 新增 | 构造函数 | -| 全球化-Intl | PluralRules.select(n: number): string; | 新增 | 计算一个数字的单复数类别 | -| 全球化-Intl | Collator.constructor(); | 新增 | 构造函数 | -| 全球化-Intl | Collator.constructor(locale: string \| Array, options?: CollatorOptions); | 新增 | 构造函数 | -| 全球化-Intl | Collator.compare(first: string, second: string): number; | 新增 | 比较两个字符串 | -| 全球化-Intl | Collator.resolvedOptions(): CollatorOptions; | 新增 | 获取排序对象相关属性 | -| 全球化-I18N | function unitConvert(fromUnit: UnitInfo, toUnit: UnitInfo, value: **number**, locale: **string**, style?: **string**): **string**; | 新增 | 新增转换单位接口 | -| 全球化-I18N | function **constructor**(country: **string**, options?: PhoneNumberFormatOptions);
function isValidNumber(**number**: **string**): boolean;
function format(**number**: **string**): **string**; | 新增 | 新增电话号码格式化接口 | -| 全球化-I18N | function setTime(date: Date);
function setTime(time: **number**);
function **set**(year: **number**, month: **number**, date:**number**, hour?: **number**, minute?: **number**, second?: **number**);
function setTimeZone(timezone: **string**);
function getTimeZone(): **string**;
function getFirstDayOfWeek(): **number**;
function setFirstDayOfWeek(value: **number**);
function getMinimalDaysInFirstWeek(): **number**;
function setMinimalDaysInFirstWeek(value: **number**);
function **get**(field: **string**): **number**;
function getDisplayName(locale: **string**): **string**;
function isWeekend(date?: Date): boolean;
function **export** **function** getCalendar(locale: **string**, **type**?: **string**): Calendar; | 新增 | 新增日历接口 | -| 全球化-I18N | **function** isRTL(locale: **string**): boolean; | 新增 | 判断区域语言是否是从右到左语言 | -| 全球化-I18N | **function** getLineInstance(locale: **string**): BreakIterator;
function current(): **number**;
function first(): **number**;
function last(): **number**;
function next(index?: **number**): **number**;
function previous(): **number**;
function setLineBreakText(text: **string**): **void**;
function following(offset: **number**): **number**;
function getLineBreakText(): **string**;
function isBoundary(offset: **number**): boolean; | 新增 | 新增断词换行接口 | -| 全球化-I18N | function getInstance(locale?:**string**): IndexUtil;
function getIndexList(): Array<**string**>; | 新增 | 新增获取字母表索引接口 | -| 全球化-I18N | function addLocale(locale: **string**);
function getIndex(text: **string**): **string**;
function isDigit(char: **string**): boolean;
function isSpaceChar(char: **string**): boolean;
function isWhitespace(char: **string**): boolean;
function isRTL(char: **string**): boolean;
function isIdeograph(char: **string**): boolean;
function isLetter(char: **string**): boolean;
function isLowerCase(char: **string**): boolean;
function isUpperCase(char: **string**): boolean;
function getType(char: **string**): **string**; | 新增 | 新增获取字符属性接口 | -| 事件通知-DoNotDisturbDate | type: notification.DoNotDisturbType | 新增 | 免打扰设置的时间类型 | -| 事件通知-DoNotDisturbDate | begin: Date | 新增 | 免打扰设置的起点时间 | -| 事件通知-DoNotDisturbDate | end: Date | 新增 | 免打扰设置的终点时间 | -| 事件通知-DoNotDisturbDate | export enum DoNotDisturbType {
TYPE_NONE = 0, // 非通知勿扰类型
TYPE_ONCE = 1, // 以设置时间段一次执行勿扰
TYPE_DAILY = 2, // 以设置时间段(只看小时和分钟)每天执行勿扰
TYPE_CLEARLY = 3, // 以设置时间段(明确年月日时分)执行勿扰
} | 新增 | 免打扰时间类型 | -| 事件通知-notification | function setDoNotDisturbDate(date DoNotDisturbDate, callback: AsyncCallback): void | 新增 | 设置免打扰时间接口 | -| 事件通知-notification | function setDoNotDisturbDate(date DoNotDisturbDate): Promise | 新增 | 设置免打扰时间接口 | -| 事件通知-notification | function getDoNotDisturbDate(callback: AsyncCallback): void | 新增 | 查询免打扰时间接口 | -| 事件通知-notification | function getDoNotDisturbDate(): Promise | 新增 | 查询免打扰时间接口 | -| 事件通知-notification | function supportDoNotDisturbMode(callback: AsyncCallback): void | 新增 | 是否支持勿扰模式功能 | -| 事件通知-notification | function supportDoNotDisturbMode(): Promise | 新增 | 是否支持勿扰模式功能 | -| 事件通知-notification | function cancelGroup(groupName: string, callback: AsyncCallback): void | 新增 | 取消本应用指定组通知 | -| 事件通知-notification | function cancelGroup(groupName: string): Promise | 新增 | 取消本应用指定组通知 | -| 事件通知-notification | function removeGroupByBundle(bundle: BundleOption, groupName: string, callback: AsyncCallback): void | 新增 | 删除指定应用指定组通知 | -| 事件通知-notification | function removeGroupByBundle(bundle: BundleOption, groupName: string): Promise | 新增 | 删除指定应用指定组通知 | -| 事件通知-NotificationSubscriber | onDoNotDisturbDateChange?:(mode: notification.DoNotDisturbDate) => void | 新增 | 免打扰设置信息变更后的通知给订阅者 | -| 事件通知-NotificationRequest | smallIcon?: image.PixelMap | 新增 | 小图标 | -| 事件通知-NotificationRequest | largeIcon?: image.PixelMap; | 新增 | 大图标 | -| 事件通知-NotificationRequest | groupName?: string; | 新增 | 通知分组名称 | -| 事件通知-NotificationUserInput | | 新增 | 用户输入对象 | -| 事件通知-NotificationUserInput | inputKey: string | 新增 | 用户输入时用于标识此输入的key | -| 事件通知-NotificationActionButton | userInput?: NotificationUserInput | 新增 | 用户输入对象实例 | -| 事件通知-emitter | function on(event: InnerEvent, callback: Callback): void | 新增 | 持续订阅某个事件以及接收事件的回调处理 | -| 事件通知-emitter | function once(event: InnerEvent, callback: Callback): void | 新增 | 单次订阅某个事件以及接收事件的回调处理,接收到回调处理后自动取消订阅 | -| 事件通知-emitter | function off(eventId: number): void | 新增 | 取消订阅某个事件 | -| 事件通知-emitter | function emit(event: InnerEvent, data?: EventData): void | 新增 | 发送一个事件到事件队列 | -| 分布式文件-statfs | function getFreeBytes(path: string, callback: AsyncCallback): void | 新增 | 以callback形式异步获取设备剩余空间,单位为字节 | -| 分布式文件-statfs | function getFreeBytes(path: string): Promise | 新增 | 以promise形式异步获取设备剩余空间,单位为字节 | -| 分布式文件-statfs | function getTotalBytes(path: string, callback: AsyncCallback): void | 新增 | 以callback形式异步获取设备总空间,单位为字节 | -| 分布式文件-statfs | function getTotalBytes(path: string): Promise | 新增 | 以promise形式异步获取设备总空间,单位为字节 | -| 分布式任务调度-featureAbility | function continueAbility(options: ContinueAbilityOptions, callback: AsyncCallback): void;
function continueAbility(options: ContinueAbilityOptions): Promise; | 新增 | - | -| 语言编译运行时-URI | constructor(uri: string); | 新增 | | -| 语言编译运行时-URI | toString(): string | 新增 | | -| 语言编译运行时-URI | equals(other: URI): boolean; | 新增 | | -| 语言编译运行时-URI | checkIsAbsolute(): boolean; | 新增 | | -| 语言编译运行时-URI | normalize(): URI; | 新增 | | -| 语言编译运行时-URI | scheme: string; | 新增 | | -| 语言编译运行时-URI | userinfo: string; | 新增 | | -| 语言编译运行时-URI | host: string; | 新增 | | -| 语言编译运行时-URI | port: string; | 新增 | | -| 语言编译运行时-URI | path: string; | 新增 | | -| 语言编译运行时-URI | query: string; | 新增 | | -| 语言编译运行时-URI | query: string; | 新增 | | -| 语言编译运行时-URI | authority: string; | 新增 | | -| 语言编译运行时-URI | ssp: string; | 新增 | | -| 语言编译运行时-RationalNumber | constructor(numerator: number, denominator: number); | 新增 | | -| 语言编译运行时-RationalNumber | static createRationalFromString(rationalString: string): RationalNumber; | 新增 | | -| 语言编译运行时-RationalNumber | compareTo(another :RationalNumber): number; | 新增 | | -| 语言编译运行时-RationalNumber | equals(obj: Object): boolean; | 新增 | | -| 语言编译运行时-RationalNumber | valueOf(): number; | 新增 | | -| 语言编译运行时-RationalNumber | static getCommonDivisor(number1: number, number2: number): number; | 新增 | | -| 语言编译运行时-RationalNumber | getDenominator(): number; | 新增 | | -| 语言编译运行时-RationalNumber | getNumerator(): number; | 新增 | | -| 语言编译运行时-RationalNumber | isFinite() : boolean; | 新增 | | -| 语言编译运行时-RationalNumber | isNaN(): boolean; | 新增 | | -| 语言编译运行时-RationalNumber | isZero(): boolean; | 新增 | | -| 语言编译运行时-RationalNumber | toString(): string; | 新增 | | -| 语言编译运行时-LruBuffer | constructor(capacity?:number); | 新增 | | -| 语言编译运行时-LruBuffer | updateCapacity(newCapacity: number):void | 新增 | | -| 语言编译运行时-LruBuffer | toString():string | 新增 | | -| 语言编译运行时-LruBuffer | length:number | 新增 | | -| 语言编译运行时-LruBuffer | getCapacity(): number; | 新增 | | -| 语言编译运行时-LruBuffer | clear(): void; | 新增 | | -| 语言编译运行时-LruBuffer | getCreateCount(): number; | 新增 | | -| 语言编译运行时-LruBuffer | getMissCount(): number; | 新增 | | -| 语言编译运行时-LruBuffer | getRemovalCount(): number; | 新增 | | -| 语言编译运行时-LruBuffer | getMatchCount(): number; | 新增 | | -| 语言编译运行时-LruBuffer | getPutCount(): number; | 新增 | | -| 语言编译运行时-LruBuffer | isEmpty(): boolean; | 新增 | | -| 语言编译运行时-LruBuffer | get(key: K): V \| undefined; | 新增 | | -| 语言编译运行时-LruBuffer | put(key: K, value: V): V; | 新增 | | -| 语言编译运行时-LruBuffer | values(): V[]; | 新增 | | -| 语言编译运行时-LruBuffer | keys(): K[]; | 新增 | | -| 语言编译运行时-LruBuffer | remove(key: K): V \| undefined; | 新增 | | -| 语言编译运行时-LruBuffer | afterRemoval(isEvict: boolean, key: K, value: V, newValue: V): void; | 新增 | | -| 语言编译运行时-LruBuffer | contains(key: K): boolean; | 新增 | | -| 语言编译运行时-LruBuffer | createDefault(key: K): V; | 新增 | | -| 语言编译运行时-LruBuffer | entries(): IterableIterator<[K, V]>; | 新增 | | -| 语言编译运行时-LruBuffer | [Symbol.iterator](): IterableIterator<[K, V]>; | 新增 | | -| 语言编译运行时-Scope | constructor(lowerObj: ScopeType, upperObj: ScopeType); | 新增 | | -| 语言编译运行时-Scope | toString(): string; | 新增 | | -| 语言编译运行时-Scope | intersect(range: Scope): Scope; | 新增 | | -| 语言编译运行时-Scope | intersect(lowerObj: ScopeType, upperObj: ScopeType): Scope; | 新增 | | -| 语言编译运行时-Scope | getUpper(): ScopeType; | 新增 | | -| 语言编译运行时-Scope | getLower(): ScopeType; | 新增 | | -| 语言编译运行时-Scope | expand(lowerObj: ScopeType, upperObj: ScopeType): Scope; | 新增 | | -| 语言编译运行时-Scope | expand(range: Scope): Scope; | 新增 | | -| 语言编译运行时-Scope | expand(value: ScopeType): Scope; | 新增 | | -| 语言编译运行时-Scope | contains(value: ScopeType): boolean; | 新增 | | -| 语言编译运行时-Scope | contains(range: Scope): boolean; | 新增 | | -| 语言编译运行时-Scope | clamp(value: ScopeType): ScopeType; | 新增 | | -| 语言编译运行时-Base64 | constructor(); | 新增 | | -| 语言编译运行时-Base64 | encodeSync(src: Uint8Array): Uint8Array; | 新增 | | -| 语言编译运行时-Base64 | encodeToStringSync(src: Uint8Array): string; | 新增 | | -| 语言编译运行时-Base64 | decodeSync(src: Uint8Array \| string): Uint8Array; | 新增 | | -| 语言编译运行时-Base64 | encode(src: Uint8Array): Promise; | 新增 | | -| 语言编译运行时-Base64 | encodeToString(src: Uint8Array): Promise; | 新增 | | -| 语言编译运行时-Base64 | decode(src: Uint8Array \| string): Promise; | 新增 | | -| 语言编译运行时-types | constructor(); | 新增 | | -| 语言编译运行时-types | isAnyArrayBuffer(value: Object): boolean; | 新增 | | -| 语言编译运行时-types | isArrayBufferView(value: Object): boolean; | 新增 | | -| 语言编译运行时-types | isArgumentsObject(value: Object): boolean; | 新增 | | -| 语言编译运行时-types | isArrayBuffer(value: Object): boolean; | 新增 | | -| 语言编译运行时-types | isAsyncFunction(value: Object): boolean; | 新增 | | -| 语言编译运行时-types | isBigInt64Array(value: Object): boolean; | 新增 | | -| 语言编译运行时-types | isBigUint64Array(value: Object): boolean; | 新增 | | -| 语言编译运行时-types | isBooleanObject(value: Object): boolean; | 新增 | | -| 语言编译运行时-types | isBoxedPrimitive(value: Object): boolean; | 新增 | | -| 语言编译运行时-types | isDataView(value: Object): boolean; | 新增 | | -| 语言编译运行时-types | isDate(value: Object): boolean; | 新增 | | -| 语言编译运行时-types | isExternal(value: Object): boolean; | 新增 | | -| 语言编译运行时-types | isFloat32Array(value: Object): boolean; | 新增 | | -| 语言编译运行时-types | isFloat64Array(value: Object): boolean; | 新增 | | -| 语言编译运行时-types | isGeneratorFunction(value: Object): boolean; | 新增 | | -| 语言编译运行时-types | isGeneratorObject(value: Object): boolean; | 新增 | | -| 语言编译运行时-types | isInt8Array(value: Object): boolean; | 新增 | | -| 语言编译运行时-types | isInt16Array(value: Object): boolean; | 新增 | | -| 语言编译运行时-types | isInt32Array(value: Object): boolean; | 新增 | | -| 语言编译运行时-types | isMap(value: Object): boolean; | 新增 | | -| 语言编译运行时-types | isMapIterator(value: Object): boolean; | 新增 | | -| 语言编译运行时-types | isModuleNamespaceObject(value: Object): boolean; | 新增 | | -| 语言编译运行时-types | isNativeError(value: Object): boolean; | 新增 | | -| 语言编译运行时-types | isNumberObject(value: Object): boolean; | 新增 | | -| 语言编译运行时-types | isPromise(value: Object): boolean; | 新增 | | -| 语言编译运行时-types | isProxy(value: Object): boolean; | 新增 | | -| 语言编译运行时-types | isRegExp(value: Object): boolean; | 新增 | | -| 语言编译运行时-types | isSet(value: Object): boolean; | 新增 | | -| 语言编译运行时-types | isSetIterator(value: Object): boolean; | 新增 | | -| 语言编译运行时-types | isSharedArrayBuffer(value: Object): boolean; | 新增 | | -| 语言编译运行时-types | isStringObject(value: Object): boolean; | 新增 | | -| 语言编译运行时-types | isSymbolObject(value: Object): boolean; | 新增 | | -| 语言编译运行时-types | isTypedArray(value: Object): boolean; | 新增 | | -| 语言编译运行时-types | isUint8Array(value: Object): boolean; | 新增 | | -| 语言编译运行时-types | isUint8ClampedArray(value: Object): boolean; | 新增 | | -| 语言编译运行时-types | isUint16Array(value: Object): boolean; | 新增 | | -| 语言编译运行时-types | isUint32Array(value: Object): boolean; | 新增 | | -| 语言编译运行时-types | isWeakMap(value: Object): boolean; | 新增 | | -| 语言编译运行时-types | isWeakSet(value: Object): boolean; | 新增 | | -| 语言编译运行时-process | const tid: number; | 新增 | | -| 语言编译运行时-process | function isIsolatedProcess(): boolean; | 新增 | | -| 语言编译运行时-process | function isAppUid(v: number): boolean; | 新增 | | -| 语言编译运行时-process | function is64Bit(): boolean; | 新增 | | -| 语言编译运行时-process | function getUidForName(v: string): number; | 新增 | | -| 语言编译运行时-process | function getThreadPriority(v: number): number; | 新增 | | -| 语言编译运行时-process | function getStartRealtime(): number; | 新增 | | -| 语言编译运行时-process | function getAvailableCores(): number[]; | 新增 | | -| 语言编译运行时-process | function getPastCpuTime(): number; | 新增 | | -| 语言编译运行时-process | function getSystemConfig(name: number): number; | 新增 | | -| 语言编译运行时-process | function getEnvironmentVar(name: string): string; | 新增 | | -| 语言编译运行时-ConvertOptions | trim: boolean; | 新增 | | -| 语言编译运行时-ConvertOptions | ignoreDeclaration?: boolean; | 新增 | | -| 语言编译运行时-ConvertOptions | ignoreInstruction?: boolean; | 新增 | | -| 语言编译运行时-ConvertOptions | ignoreAttributes?: boolean; | 新增 | | -| 语言编译运行时-ConvertOptions | ignoreComment?: boolean; | 新增 | | -| 语言编译运行时-ConvertOptions | ignoreCdata?: boolean; | 新增 | | -| 语言编译运行时-ConvertOptions | ignoreDoctype?: boolean; | 新增 | | -| 语言编译运行时-ConvertOptions | ignoreText?: boolean; | 新增 | | -| 语言编译运行时-ConvertOptions | declarationKey: string; | 新增 | | -| 语言编译运行时-ConvertOptions | instructionKey: string; | 新增 | | -| 语言编译运行时-ConvertOptions | attributesKey: string; | 新增 | | -| 语言编译运行时-ConvertOptions | textKey: string; | 新增 | | -| 语言编译运行时-ConvertOptions | cdataKey: string; | 新增 | | -| 语言编译运行时-ConvertOptions | doctypeKey: string; | 新增 | | -| 语言编译运行时-ConvertOptions | commentKey: string; | 新增 | | -| 语言编译运行时-ConvertOptions | parentKey: string; | 新增 | | -| 语言编译运行时-ConvertOptions | typeKey: string; | 新增 | | -| 语言编译运行时-ConvertOptions | nameKey: string; | 新增 | | -| 语言编译运行时-ConvertOptions | elementsKey: string; | 新增 | | -| 语言编译运行时-ConvertXML | convert(xml: string, options?: ConvertOptions) : Object; | 新增 | | -| 语言编译运行时-XmlSerializer | constructor(buffer: ArrayBuffer \| DataView, encoding?: string); | 新增 | | -| 语言编译运行时-XmlSerializer | setAttributes(name: string, value: string): void; | 新增 | | -| 语言编译运行时-XmlSerializer | addEmptyElement(name: string): void; | 新增 | | -| 语言编译运行时-XmlSerializer | setDeclaration(): void; | 新增 | | -| 语言编译运行时-XmlSerializer | startElement(name: string): void; | 新增 | | -| 语言编译运行时-XmlSerializer | endElement(): void; | 新增 | | -| 语言编译运行时-XmlSerializer | setNamespace(prefix: string, namespace: string): void; | 新增 | | -| 语言编译运行时-XmlSerializer | setCommnet(text: string): void; | 新增 | | -| 语言编译运行时-XmlSerializer | setCData(text: string): void; | 新增 | | -| 语言编译运行时-XmlSerializer | setText(text: string): void; | 新增 | | -| 语言编译运行时-XmlSerializer | setDocType(text: string): void; | 新增 | | -| 语言编译运行时-ParseOptions | supportDoctype?: boolean; | 新增 | | -| 语言编译运行时-ParseOptions | ignoreNameSpace?: boolean; | 新增 | | -| 语言编译运行时-ParseOptions | tagValueCallbackFunction?: (name: string, value: string) => boolean; | 新增 | | -| 语言编译运行时-ParseOptions | attributeValueCallbackFunction?: (name: string, value: string) => boolean; | 新增 | | -| 语言编译运行时-ParseOptions | tokenValueCallbackFunction?: (eventType: EventType, value: ParseInfo) => boolean; | 新增 | | -| 帐号-account.appAccount | createAppAccountManager | 新增 | 获取实例 | -| 帐号-account.appAccount | addAccount(name: string, callback: AsyncCallback): void;
addAccount(name: string, extraInfo: string, callback: AsyncCallback): void;
addAccount(name: string, extraInfo?: string): Promise; | 新增 | 添加应用帐户 | -| 帐号-account.appAccount | deleteAccount(name: string, callback: AsyncCallback): void;
deleteAccount(name: string): Promise; | 新增 | 删除应用帐户 | -| 帐号-account.appAccount | disableAppAccess(name: string, bundleName: string, callback: AsyncCallback): void;
disableAppAccess(name: string, bundleName: string): Promise; | 新增 | 使指定的package拒绝访问给定的应用帐号 | -| 帐号-account.appAccount | enableAppAccess(name: string, bundleName: string, callback: AsyncCallback): void;
enableAppAccess(name: string, bundleName: string): Promise; | 新增 | 使指定的package允许访问给定的应用帐号 | -| 帐号-account.appAccount | checkAppAccountSyncEnable(name: string, callback: AsyncCallback): void;
checkAppAccountSyncEnable(name: string): Promise; | 新增 | 检查指定的应用帐号是否允许应用程序同步数据 | -| 帐号-account.appAccount | setAccountCredential(name: string, credentialType: string, credential: string,
callback: AsyncCallback): void;
setAccountCredential(name: string, credentialType: string, credential: string): Promise; | 新增 | 设置指定应用程序帐号的认证凭据 | -| 帐号-account.appAccount | setAccountExtraInfo(name: string, extraInfo: string, callback: AsyncCallback): void;
setAccountExtraInfo(name: string, extraInfo: string): Promise; | 新增 | 设置指定应用帐号的附加信息 | -| 帐号-account.appAccount | setAppAccountSyncEnable(name: string, isEnable: boolean, callback: AsyncCallback): void;
setAppAccountSyncEnable(name: string, isEnable: boolean): Promise; | 新增 | 设置指定的应用程序帐号是否允许应用程序同步数据 | -| 帐号-account.appAccount | setAssociatedData(name: string, key: string, value: string, callback: AsyncCallback): void;
setAssociatedData(name: string, key: string, value: string): Promise; | 新增 | 设置应用帐号关联信息 | -| 帐号-account.appAccount | getAllAccessibleAccounts(callback: AsyncCallback>): void;
getAllAccessibleAccounts(): Promise>; | 新增 | 获取本应用帐号信息和已授权给本应用的第三方应用帐号的信息 | -| 帐号-account.appAccount | getAllAccounts(owner: string, callback: AsyncCallback>): void;
getAllAccounts(owner: string): Promise>; | 新增 | 获取执行应用下全部帐号信息 | -| 帐号-account.appAccount | getAccountCredential(name: string, credentialType: string, callback: AsyncCallback): void;
getAccountCredential(name: string, credentialType: string): Promise; | 新增 | 获取指定应用程序帐号的认证凭据 | -| 帐号-account.appAccount | getAccountExtraInfo(name: string, callback: AsyncCallback): void;
getAccountExtraInfo(name: string): Promise; | 新增 | 获取应用帐号附加信息 | -| 帐号-account.appAccount | getAssociatedData(name: string, key: string, callback: AsyncCallback): void;
getAssociatedData(name: string, key: string): Promise; | 新增 | 获取应用帐号关联信息 | -| 帐号-account.appAccount| on(type: 'change', owners: Array, callback: Callback>): void; | 新增 | 订阅指定应用帐号的更改事件 | -| 帐号-account.appAccount | off(type: 'change', callback?: Callback): void; | 新增 | 取消订阅应用帐号的更改事件 | -| 帐号-account.appAccount | interface AppAccountInfo | 新增 | 应用帐号信息 | -| 泛Sensor服务-sensor | on(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: AsyncCallback,options?: Options): void | 新增 | 监听加速度传感器的数据变化 | -| 泛Sensor服务-sensor | on(type:SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,callback:AsyncCallback, options?: Options): void | 新增 | 监听线性加速度传感器的数据变化 | -| 泛Sensor服务-sensor | on(type:SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,callback:AsyncCallback, options?: Options): void | 新增 | 监听未校准加速度计传感器的数据变化 | -| 泛Sensor服务-sensor | on(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback: AsyncCallback,options?: Options): void | 新增 | 监听重力传感器的数据变化 | -| 泛Sensor服务-sensor | on(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback: AsyncCallback, options?: Options): void | 新增 | 监听陀螺仪传感器的数据变化 | -| 泛Sensor服务-sensor | on(type:SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback:AsyncCallback, options?: Options): void | 新增 | 监听未校准陀螺仪传感器的数据变化 | -| 泛Sensor服务-sensor | on(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback: AsyncCallback, options?: Options): void | 新增 | 监听大幅动作传感器数据变化 | -| 泛Sensor服务-sensor | on(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback: AsyncCallback, options?: Options): void | 新增 | 监听计步检测传感器的数据变化 | -| 泛Sensor服务-sensor | on(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback: AsyncCallback, options?: Options): void | 新增 | 监听计步传感器的数据变化 | -| 泛Sensor服务-sensor | on(type:SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback:AsyncCallback, options?: Options): void | 新增 | 监听环境温度传感器的数据变化 | -| 泛Sensor服务-sensor | on(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback: AsyncCallback,options?: Options): void | 新增 | 监听磁场传感器的数据变化 | -| 泛Sensor服务-sensor | on(type:SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback:AsyncCallback, options: Options): void | 新增 | 监听未校准磁场传感器的数据变化 | -| 泛Sensor服务-sensor | on(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: AsyncCallback,options?: Options): void | 新增 | 监听接近光传感器的数据变化 | -| 泛Sensor服务-sensor | on(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback: AsyncCallback,options?: Options): void | 新增 | 监听湿度传感器的数据变化 | -| 泛Sensor服务-sensor | on(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback: AsyncCallback,options?: Options): void | 新增 | 监听气压计传感器的数据变化 | -| 泛Sensor服务-sensor | on(type: SensorType.SENSOR_TYPE_ID_HALL, callback: AsyncCallback, options?: Options): void | 新增 | 监听霍尔传感器的数据变化 | -| 泛Sensor服务-sensor | on(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback: AsyncCallback, options?: Options): void | 新增 | 监听环境光传感器的数据变化 | -| 泛Sensor服务-sensor | on(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback: AsyncCallback, options?: Options): void | 新增 | 监听方向传感器的数据变化 | -| 泛Sensor服务-sensor | on(type:SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR,callback:AsyncCallback,options?: Options): void | 新增 | 监听旋转矢量传感器的数据变化 | -| 泛Sensor服务-sensor | on(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback: AsyncCallback,options?: Options): void | 新增 | 监听佩戴检测传感器的数据变化 | -| 泛Sensor服务-sensor | once(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: AsyncCallback): void | 新增 | 监听加速度传感器的数据变化一次 | -| 泛Sensor服务-sensor | once(type:SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,callback:AsyncCallback): void | 新增 | 监听线性加速度传感器的数据变化一次 | -| 泛Sensor服务-sensor | once(type:SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,callback:AsyncCallback): void | 新增 | 监听未校准加速度计传感器的数据变化一次 | -| 泛Sensor服务-sensor | once(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback: AsyncCallback): void | 新增 | 监听重力传感器的数据变化一次 | -| 泛Sensor服务-sensor | once(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback: AsyncCallback): void | 新增 | 监听陀螺仪传感器的数据变化一次 | -| 泛Sensor服务-sensor | once(type:SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback:AsyncCallback, options?: Options): void | 新增 | 监听未校准陀螺仪传感器的数据变化一次 | -| 泛Sensor服务-sensor | once(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback: AsyncCallback): void | 新增 | 监听大幅动作传感器数据变化一次 | -| 泛Sensor服务-sensor | once(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback: AsyncCallback): void | 新增 | 监听计步检测传感器的数据变化一次 | -| 泛Sensor服务-sensor | once(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback: AsyncCallback): void | 新增 | 监听计步传感器的数据变化一次 | -| 泛Sensor服务-sensor | once(type:SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback:AsyncCallback): void | 新增 | 监听环境温度传感器的数据变化一次 | -| 泛Sensor服务-sensor | once(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback: AsyncCallback): void | 新增 | 监听磁场传感器的数据变化一次 | -| 泛Sensor服务-sensor | once(type:SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback:AsyncCallback): void | 新增 | 监听未校准磁场传感器的数据变化一次 | -| 泛Sensor服务-sensor | once(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: AsyncCallback): void | 新增 | 监听接近光传感器的数据变化一次 | -| 泛Sensor服务-sensor | once(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback: AsyncCallback): void | 新增 | 监听湿度传感器的数据变化一次 | -| 泛Sensor服务-sensor | once(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback: AsyncCallback): void | 新增 | 监听气压计传感器的数据变化一次 | -| 泛Sensor服务-sensor | once(type: SensorType.SENSOR_TYPE_ID_HALL, callback: AsyncCallback): void | 新增 | 监听霍尔传感器的数据变化一次 | -| 泛Sensor服务-sensor | once(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback: AsyncCallback): void | 新增 | 监听环境光传感器的数据变化一次 | -| 泛Sensor服务-sensor | once(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback: AsyncCallback): void | 新增 | 监听方向传感器的数据变化一次 | -| 泛Sensor服务-sensor | once(type:SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR,callback:AsyncCallback): void | 新增 | 监听旋转矢量传感器的数据变化一次 | -| 泛Sensor服务-sensor | once(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback: AsyncCallback): void | 新增 | 监听佩戴检测传感器的数据变化一次 | -| 泛Sensor服务-sensor | off(type: SensorType, callback?: AsyncCallback): void | 新增 | 取消订阅传感器数据 | -| 泛Sensor服务-sensor | getGeomagneticField(locationOptions: LocationOptions, timeMillis: number, callback: AsyncCallback): void
getGeomagneticField(locationOptions: LocationOptions, timeMillis: number): Promise | 新增 | 获取地球上特定位置的地磁场 | -| 泛Sensor服务-vibrator | vibrate(duration: number): Promise
vibrate(duration: number, callback?: AsyncCallback): void | 新增 | 按照指定持续时间触发马达振动 | -| 泛Sensor服务-vibrator | vibrate(effectId: EffectId): Promise
vibrate(effectId: EffectId, callback?: AsyncCallback): void | 新增 | 按照指定振动效果触发马达振动 | -| 泛Sensor服务-vibrator | stop(stopMode: VibratorStopMode): Promise
stop(stopMode: VibratorStopMode, callback?: AsyncCallback): void | 新增 | 停止马达振动 | diff --git a/website/docs/_posts/zh-cn/release-notes/api-change/v3.1-beta/native-apidiff-v3.1-beta.md b/website/docs/_posts/zh-cn/release-notes/api-change/v3.1-beta/native-apidiff-v3.1-beta.md deleted file mode 100644 index 3f05d2164fdef3da0075c106aa162bc8493b65da..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/release-notes/api-change/v3.1-beta/native-apidiff-v3.1-beta.md +++ /dev/null @@ -1,29 +0,0 @@ ---- -title: native-apidiff-v3.1-beta -permalink: /pages/extra/abff2d/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# Native API 差异报告 - -OpenHarmony 3.1 Beta相较于OpenHarmony 3.0 LTS版本的API变更如下: - -## 标准系统接口变更 - -| 模块名称 | 接口名称 | 变更类型 | 变更说明 | -| ------------------ | ------------------------------------------------------------ | -------- | ------------------------------------------------- | -| bundle | napi_value ClearBundleCache(napi_env env, napi_callback_info info) | 新增 | 新增清理应用缓存接口 | -| bundle | napi_value SetApplicationEnabled(napi_env env, napi_callback_info info) | 新增 | 新增设置应用使能接口 | -| bundle | napi_value SetAbilityEnabled(napi_env env, napi_callback_info info) | 新增 | 新增设置ability使能接口 | -| innerbundlemanager | napi_value JSGetLauncherAbilityInfos(napi_env env, napi_callback_info info) | 新增 | 新增通过包名获取应用LauncherAbility接口 | -| innerbundlemanager | napi_value JSLauncherServiceOn(napi_env env, napi_callback_info info) | 新增 | 新增注册监听包状态变化接口 | -| innerbundlemanager | napi_value JSLauncherServiceOff(napi_env env, napi_callback_info info) | 新增 | 新增注销监听包状态变化接口 | -| innerbundlemanager | napi_value JSGetAllLauncherAbilityInfos(napi_env env, napi_callback_info info) | 新增 | 新增通过userId获取所有launcher上应用的ability接口 | -| innerbundlemanager | napi_value JSGetShortcutInfos(napi_env env, napi_callback_info info) | 新增 | 新增通过bundleName获取应用的shortcutInfo接口 | \ No newline at end of file diff --git a/website/docs/_posts/zh-cn/resources/external-resources.md b/website/docs/_posts/zh-cn/resources/external-resources.md deleted file mode 100644 index e4ceb89f92e3a00be64bc0413e7ab56cc8def459..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/resources/external-resources.md +++ /dev/null @@ -1,30 +0,0 @@ ---- -title: external-resources -permalink: /pages/extra/cf93e1/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:37 ---- -# 社区资源推荐--持续更新中 - -本专刊旨在为您提供OpenHarmony学习资源、知识内容园地,帮助您快速学习。小编在这里汇聚了许多来自社区及开发者的精选资源,希望能把优质的内容分享给每一位热爱技术的你。 - -您可以通过行业大咖、资深开发者的分享与实践,高效学习相关知识。 -您也可以通过技术专家们的官方解读,了解相关设计理念、技术架构、关键能力,让您的产品拥有更好的体验。 -我们也将持续更新本专刊,为您提供最新资源。 - -当您学习某课程或功能时,功能可能会发生变化,请参考官方文档获取最新信息。 - -**备注**: - -此专刊内容来自于OpenHarmony/HarmonyOS合作社区、生态伙伴,汇聚广受开发者喜爱的网络课程等资源。 - -如需转载,请标注课程的来源、链接,课程讲师等基本信息。 -如涉及版权问题,请联系我们,经核实后会尽快予以处理。 - diff --git a/website/docs/_posts/zh-cn/website-directory.md b/website/docs/_posts/zh-cn/website-directory.md deleted file mode 100644 index 57a4ba5588add094261d855d00f9cf982b5c6ff1..0000000000000000000000000000000000000000 --- a/website/docs/_posts/zh-cn/website-directory.md +++ /dev/null @@ -1,1980 +0,0 @@ ---- -title: website-directory -permalink: /pages/extra/f4e2d1/ -navbar: true -sidebar: false -prev: false -next: false -search: true -article: true -comment: false -editLink: false -date: 2022-02-14 21:31:38 ---- -# OpenHarmony - -——>——> 了解OpenHarmony - - - -——>——>——> 了解OpenHarmony系统 - -——>——>——>——>[内核子系统](/pages/01010201) - -——>——>——>——>[驱动子系统](/pages/01010202) - -——>——>——>——>[方舟运行时子系统](/pages/01010203) - -——>——>——>——>[DFX子系统](/pages/01010204) - -——>——>——>——>[JS-UI框架子系统](/pages/01010205) - -——>——>——>——>[Misc软件服务子系统](/pages/01010206) - -——>——>——>——>[XTS子系统](/pages/01010207) - -——>——>——>——>[事件通知子系统](/pages/01010208) - -——>——>——>——>[元能力子系统](/pages/01010209) - -——>——>——>——>[全球化子系统](/pages/0101020a) - -——>——>——>——>[公共基础库](/pages/0101020b) - -——>——>——>——>[分布式任务调度子系统](/pages/0101020c) - -——>——>——>——>[分布式数据管理子系统](/pages/0101020d) - -——>——>——>——>[分布式文件子系统](/pages/0101020e) - -——>——>——>——>[分布式软总线子系统](/pages/0101020f) - -——>——>——>——>[升级子系统](/pages/01010210) - -——>——>——>——>[启动恢复子系统](/pages/01010211) - -——>——>——>——>[图形子系统](/pages/01010212) - -——>——>——>——>[多模输入子系统](/pages/01010213) - -——>——>——>——>[媒体子系统](/pages/01010214) - -——>——>——>——>[安全子系统](/pages/01010215) - -——>——>——>——>[帐号子系统](/pages/01010216) - -——>——>——>——>[泛Sensor子系统](/pages/01010217) - -——>——>——>——>[测试子系统](/pages/01010218) - -——>——>——>——>[用户程序框架子系统](/pages/01010219) - -——>——>——>——>[电源管理子系统](/pages/0101021a) - -——>——>——>——>[电话服务子系统](/pages/0101021b) - -——>——>——>——>[研发工具链子系统](/pages/0101021c) - -——>——>——>——>[系统应用](/pages/0101021d) - -——>——>——>——>[编译构建子系统](/pages/0101021e) - -——>——>——>——>[语言运行时子系统](/pages/0101021f) - -——>——>——>——>[AI业务子系统](/pages/01010220) - -——>——>——> [术语](/pages/010103) - -——>——>——> [版本说明](/pages/010104) - -——>——> 快速开始 - -——>——>——>[轻量和小型系统入门](/pages/extra/fdee28/) - -——>——>——>——>[轻量与小型系统入门概述](/pages/01020101) - -——>——>——>——>[搭建轻量与小型系统环境](/pages/extra/770961/) - -——>——>——>——>——>[搭建系统环境概述](/pages/0102010201) - -——>——>——>——>——>[开发环境准备](/pages/0102010202) - -——>——>——>——>——>[获取源码](/pages/0102010203) - -——>——>——>——>——>[使用安装包方式搭建编译环境](/pages/0102010204) - -——>——>——>——>——>[使用Docker方式搭建编译环境](/pages/0102010205) - -——>——>——>——>——>[常见问题](/pages/0102010206) - -——>——>——>——>[运行“Hello World”](/pages/extra/e5f98d/) - -——>——>——>——>——>[Hi3861开发板](/pages/extra/d8f8db/) - -——>——>——>——>——>——>[安装开发板环境](/pages/010201030101) - -——>——>——>——>——>——>[新建应用程序](/pages/010201030102) - -——>——>——>——>——>——>[编译](/pages/010201030103) - -——>——>——>——>——>——>[烧录](/pages/010201030104) - -——>——>——>——>——>——>[调试验证](/pages/010201030105) - -——>——>——>——>——>——>[运行](/pages/010201030106) - -——>——>——>——>——>——>[常见问题](/pages/010201030107) - -——>——>——>——>——>[Hi3516开发板](/pages/extra/f3d084/) - -——>——>——>——>——>——>[安装开发板环境](/pages/010201030201) - -——>——>——>——>——>——>[新建应用程序](/pages/010201030202) - -——>——>——>——>——>——>[编译](/pages/010201030203) - -——>——>——>——>——>——>[烧录](/pages/010201030204) - -——>——>——>——>——>——>[运行](/pages/010201030205) - -——>——>——>——>——>——>[常见问题](/pages/010201030206) - -——>——>——>——>——>[Hi3518开发板](/pages/extra/7db1f4/) - -——>——>——>——>——>——>[安装开发板环境](/pages/010201030301) - -——>——>——>——>——>——>[新建应用程序](/pages/010201030302) - -——>——>——>——>——>——>[编译](/pages/010201030303) - -——>——>——>——>——>——>[烧录](/pages/010201030304) - -——>——>——>——>——>——>[运行](/pages/010201030305) - -——>——>——>——>——>——>[常见问题](/pages/010201030306) - -——>——>——>——>[附录](/pages/extra/d372c4/) - -——>——>——>——>——>[Hi3861开发板介绍](/pages/0102010401) - -——>——>——>——>——>[Hi3516开发板介绍](/pages/0102010402) - -——>——>——>——>——>[Hi3518开发板介绍](/pages/0102010403) - -——>——>——>[标准系统入门](/pages/extra/6dca5d/) - -——>——>——>——>[标准系统入门简介](/pages/01020201) - -——>——>——>——>[标准系统开发环境准备(仅Hi3516需要)](/pages/01020202) - -——>——>——>——>[获取源码](/pages/01020203) - -——>——>——>——>[运行“Hello World”](/pages/extra/743c79/) - -——>——>——>——>——>[Hi3516开发板](/pages/extra/d76ae0/) - -——>——>——>——>——>——>[创建应用程序](/pages/010202040101) - -——>——>——>——>——>——>[编译](/pages/010202040102) - -——>——>——>——>——>——>[烧录](/pages/010202040103) - -——>——>——>——>——>——>[运行](/pages/010202040104) - -——>——>——>——>——>[RK3568开发板](/pages/extra/e45186/) - -——>——>——>——>——>——>[创建应用程序](/pages/010202040201) - -——>——>——>——>——>——>[编译](/pages/010202040202) - -——>——>——>——>——>——>[烧录](/pages/010202040203) - -——>——>——>——>——>——>[运行](/pages/010202040204) - -——>——>——>——>[常见问题](/pages/01020205) - -——>——>——>——>[附录](/pages/extra/f03f91/) - -——>——>——>——>——>[Hi3516开发板介绍](/pages/0102020601) - -——>——>——>——>——>[RK3568开发板介绍](/pages/0102020602) - -——>——> 兼容性与安全 - -——>——>——> [隐私与安全规范](/pages/extra/d0d683/) - -——>——>——>——> [隐私保护](/pages/01030101) - -——>——>——>——> [安全指南](/pages/01030102) - -——>——> 移植 - -——>——>——>[轻量系统芯片移植指导](/pages/extra/bc2a1e/) - -——>——>——>——>[移植准备](/pages/extra/2bf51a/) - -——>——>——>——>——>[移植须知](/pages/0104010101) - -——>——>——>——>——>[编译构建适配流程](/pages/0104010102) - -——>——>——>——>[内核移植](/pages/extra/7a2f63/) - -——>——>——>——>——>[移植概述](/pages/0104010201) - -——>——>——>——>——>[内核基础适配](/pages/0104010202) - -——>——>——>——>——>[内核移植验证](/pages/0104010203) - -——>——>——>——>[板级系统移植](/pages/extra/9257d8/) - -——>——>——>——>——>[移植概述](/pages/0104010301) - -——>——>——>——>——>[板级驱动适配](/pages/0104010302) - -——>——>——>——>——>[HAL层实现](/pages/0104010303) - -——>——>——>——>——>[系统组件调用](/pages/0104010304) - -——>——>——>——>——>[lwIP组件适配](/pages/0104010305) - -——>——>——>——>——>[三方组件适配](/pages/0104010306) - -——>——>——>——>——>[XTS认证](/pages/0104010307) - -——>——>——>——>[常见问题](/pages/01040104) - -——>——>——>[小型系统芯片移植指导](/pages/extra/362558/) - -——>——>——>——>[移植准备](/pages/extra/f4e07b/) - -——>——>——>——>——>[移植须知](/pages/0104020101) - -——>——>——>——>——>[编译构建](/pages/0104020102) - -——>——>——>——>[移植内核](/pages/extra/2858ab/) - -——>——>——>——>——>[LiteOS-A内核](/pages/0104020201) - -——>——>——>——>——>[Linux内核](/pages/0104020202) - -——>——>——>——>[驱动移植](/pages/extra/f63f6f/) - -——>——>——>——>——>[移植概述](/pages/0104020301) - -——>——>——>——>——>[平台驱动移植](/pages/0104020302) - -——>——>——>——>——>[器件驱动移植](/pages/0104020303) - -——>——>——>[标准系统芯片移植指导](/pages/01040301) - -——>——>——>——>[标准系统移植指南](/pages/01040301) - -——>——>——>——>[一种快速移植OpenHarmony Linux内核的方法](/pages/01040302) - -——>——>——>[轻量和小型系统三方库移植指导](/pages/extra/e80fe1/) - -——>——>——>——>[概述](/pages/01040401) - -——>——>——>——>[CMake方式组织编译的库移植](/pages/01040402) - -——>——>——>——>[Makefile方式组织编译的库移植](/pages/01040403) - -——>——>——>[轻量系统芯片移植案例](/pages/extra/890e18/) - -——>——>——>——>[带屏解决方案之恒玄芯片移植案例](/pages/01040501) - -——>——> 子系统开发 - -——>——>——> [内核](/pages/extra/0c607a/) - -——>——>——>——> [轻量系统内核](/pages/extra/65dc1e/) - -——>——>——>——>——> [内核概述](/pages/0105010101) - -——>——>——>——>——> [基础内核](/pages/extra/9163c3/) - -——>——>——>——>——>——> [中断管理](/pages/extra/2a9327/) - -——>——>——>——>——>——>——> [基本概念](/pages/01050101020101) - -——>——>——>——>——>——>——> [开发指导](/pages/01050101020102) - -——>——>——>——>——>——> [任务管理](/pages/extra/9ad148/) - -——>——>——>——>——>——>——> [基本概念](/pages/01050101020201) - -——>——>——>——>——>——>——> [开发指导](/pages/01050101020202) - -——>——>——>——>——>——> [内存管理](/pages/extra/d62ea8/) - -——>——>——>——>——>——>——> [基本概念](/pages/01050101020301) - -——>——>——>——>——>——>——> [静态内存](/pages/01050101020302) - -——>——>——>——>——>——>——> [动态内存](/pages/01050101020303) - -——>——>——>——>——>——> [内核通信机制](/pages/extra/bad8c5/) - -——>——>——>——>——>——>——> [事件](/pages/extra/e4f01d/) - -——>——>——>——>——>——>——>——> [基本概念](/pages/0105010102040101) - -——>——>——>——>——>——>——>——> [开发指导](/pages/0105010102040102) - -——>——>——>——>——>——>——> [互斥锁](/pages/extra/7b78a2/) - -——>——>——>——>——>——>——>——> [基本概念](/pages/0105010102040201) - -——>——>——>——>——>——>——>——> [开发指导](/pages/0105010102040202) - -——>——>——>——>——>——>——> [消息队列](/pages/extra/c06361/) - -——>——>——>——>——>——>——>——> [基本概念](/pages/0105010102040301) - -——>——>——>——>——>——>——>——> [开发指导](/pages/0105010102040302) - -——>——>——>——>——>——>——> [信号量](/pages/extra/9d3f31/) - -——>——>——>——>——>——>——>——> [基本概念](/pages/0105010102040401) - -——>——>——>——>——>——>——>——> [开发指导](/pages/0105010102040402) - -——>——>——>——>——>——> [时间管理](/pages/extra/726813/) - -——>——>——>——>——>——>——> [基本概念](/pages/01050101020501) - -——>——>——>——>——>——>——> [开发指导](/pages/01050101020502) - -——>——>——>——>——>——> [软件定时器](/pages/extra/079668/) - -——>——>——>——>——>——>——> [基本概念](/pages/01050101020601) - -——>——>——>——>——>——>——> [开发指导](/pages/01050101020602) - -——>——>——>——>——> [扩展组件](/pages/extra/c07c37/) - -——>——>——>——>——>——> [C++支持](/pages/010501010301) - -——>——>——>——>——>——> [CPU占用率](/pages/extra/3ca78d/) - -——>——>——>——>——>——>——> [基本概念](/pages/01050101030201) - -——>——>——>——>——>——>——> [开发指导](/pages/01050101030202) - -——>——>——>——>——>——> [文件系统](/pages/extra/2bbbd9/) - -——>——>——>——>——>——>——> [FAT](/pages/01050101030301) - -——>——>——>——>——>——>——> [LittleFS](/pages/extra/65cb03/) - -——>——>——>——>——>——>——>——> [基本概念](/pages/0105010103030201) - -——>——>——>——>——>——>——>——> [开发指导](/pages/0105010103030202) - -——>——>——>——>——> [内核调测](/pages/extra/149095/) - -——>——>——>——>——>——> [内存调测](/pages/extra/034b9c/) - -——>——>——>——>——>——>——> [内存信息统计](/pages/01050101040101) - -——>——>——>——>——>——>——> [内存泄漏检测](/pages/01050101040102) - -——>——>——>——>——>——>——> [踩内存检测](/pages/01050101040103) - -——>——>——>——>——>——> [异常调测](/pages/010501010402) - -——>——>——>——>——>——> [Trace调测](/pages/010501010403) - -——>——>——>——>——>——> [LMS调测](/pages/010501010404) - -——>——>——>——>——> [附录](/pages/extra/318f40/) - -——>——>——>——>——>——> [内核编码规范](/pages/010501010501) - -——>——>——>——>——>——> [基本数据结构](/pages/extra/96d541/) - -——>——>——>——>——>——>——> [双向链表](/pages/01050101050201) - -——>——>——>——>——>——> [标准库支持](/pages/extra/ab87f3/) - -——>——>——>——>——>——>——> [CMSIS支持](/pages/01050101050301) - -——>——>——>——>——>——>——> [POSIX支持](/pages/01050101050302) - -——>——>——>——> [小型系统内核](/pages/extra/80d97b/) - -——>——>——>——>——> [内核概述](/pages/0105010201) - -——>——>——>——>——> [内核启动](/pages/extra/f14e14/) - -——>——>——>——>——>——> [内核态启动](/pages/010501020201) - -——>——>——>——>——>——> [用户态启动](/pages/010501020202) - -——>——>——>——>——> [基础内核](/pages/extra/365208/) - -——>——>——>——>——>——> [中断及异常处理](/pages/010501020301) - -——>——>——>——>——>——> [进程管理](/pages/extra/97e28a/) - -——>——>——>——>——>——>——> [进程](/pages/01050102030201) - -——>——>——>——>——>——>——> [任务](/pages/01050102030202) - -——>——>——>——>——>——>——> [调度器](/pages/01050102030203) - -——>——>——>——>——>——> [内存管理](/pages/extra/e65a3e/) - -——>——>——>——>——>——>——> [堆内存管理](/pages/01050102030301) - -——>——>——>——>——>——>——> [物理内存管理](/pages/01050102030302) - -——>——>——>——>——>——>——> [虚拟内存管理](/pages/01050102030303) - -——>——>——>——>——>——>——> [虚实映射](/pages/01050102030304) - -——>——>——>——>——>——> [内核通信机制](/pages/extra/1d11d4/) - -——>——>——>——>——>——>——> [事件](/pages/01050102030401) - -——>——>——>——>——>——>——> [信号量](/pages/01050102030402) - -——>——>——>——>——>——>——> [互斥锁](/pages/01050102030403) - -——>——>——>——>——>——>——> [消息队列](/pages/01050102030404) - -——>——>——>——>——>——>——> [读写锁](/pages/01050102030405) - -——>——>——>——>——>——>——> [用户态快速互斥锁](/pages/01050102030406) - -——>——>——>——>——>——>——> [信号](/pages/01050102030407) - -——>——>——>——>——>——> [时间管理](/pages/010501020305) - -——>——>——>——>——>——> [软件定时器](/pages/010501020306) - -——>——>——>——>——>——> [原子操作](/pages/010501020307) - -——>——>——>——>——> [扩展组件](/pages/extra/21b9e6/) - -——>——>——>——>——>——> [系统调用](/pages/010501020401) - -——>——>——>——>——>——> [动态加载与链接](/pages/010501020402) - -——>——>——>——>——>——> [虚拟动态共享库](/pages/010501020403) - -——>——>——>——>——>——> [轻量级进程间通信](/pages/010501020404) - -——>——>——>——>——>——> [文件系统](/pages/extra/124a98/) - -——>——>——>——>——>——>——> [虚拟文件系统](/pages/01050102040501) - -——>——>——>——>——>——>——> [支持的文件系统](/pages/extra/436bd9/) - -——>——>——>——>——>——>——>——> [FAT](/pages/0105010204050201) - -——>——>——>——>——>——>——>——> [JFFS2](/pages/0105010204050202) - -——>——>——>——>——>——>——>——> [NFS](/pages/0105010204050203) - -——>——>——>——>——>——>——>——> [Ramfs](/pages/0105010204050204) - -——>——>——>——>——>——>——>——> [Procfs](/pages/0105010204050205) - -——>——>——>——>——>——>——> [适配新的文件系统](/pages/01050102040503) - -——>——>——>——>——> [调测与工具](/pages/extra/1d2f34/) - -——>——>——>——>——>——> [Shell](/pages/extra/36f10b/) - -——>——>——>——>——>——>——> [Shell介绍](/pages/01050102050101) - -——>——>——>——>——>——>——> [Shell命令开发指导](/pages/01050102050102) - -——>——>——>——>——>——>——> [Shell命令编程实例](/pages/01050102050103) - -——>——>——>——>——>——>——> [Shell命令使用详解](/pages/extra/9729b4/) - -——>——>——>——>——>——>——>——> [系统命令](/pages/extra/810976/) - -——>——>——>——>——>——>——>——>——> [cpup](/pages/010501020501040101) - -——>——>——>——>——>——>——>——>——> [date](/pages/010501020501040102) - -——>——>——>——>——>——>——>——>——> [dmesg](/pages/010501020501040103) - -——>——>——>——>——>——>——>——>——> [exec](/pages/010501020501040104) - -——>——>——>——>——>——>——>——>——> [free](/pages/010501020501040105) - -——>——>——>——>——>——>——>——>——> [help](/pages/010501020501040106) - -——>——>——>——>——>——>——>——>——> [hwi](/pages/010501020501040107) - -——>——>——>——>——>——>——>——>——> [kill](/pages/010501020501040108) - -——>——>——>——>——>——>——>——>——> [log](/pages/010501020501040109) - -——>——>——>——>——>——>——>——>——> [memcheck](/pages/01050102050104010a) - -——>——>——>——>——>——>——>——>——> [oom](/pages/01050102050104010b) - -——>——>——>——>——>——>——>——>——> [pmm](/pages/01050102050104010c) - -——>——>——>——>——>——>——>——>——> [reset](/pages/01050102050104010d) - -——>——>——>——>——>——>——>——>——> [sem](/pages/01050102050104010e) - -——>——>——>——>——>——>——>——>——> [stack](/pages/01050102050104010f) - -——>——>——>——>——>——>——>——>——> [su](/pages/010501020501040110) - -——>——>——>——>——>——>——>——>——> [swtmr](/pages/010501020501040111) - -——>——>——>——>——>——>——>——>——> [systeminfo](/pages/010501020501040112) - -——>——>——>——>——>——>——>——>——> [task](/pages/010501020501040113) - -——>——>——>——>——>——>——>——>——> [uname](/pages/010501020501040114) - -——>——>——>——>——>——>——>——>——> [vmm](/pages/010501020501040115) - -——>——>——>——>——>——>——>——>——> [watch](/pages/010501020501040116) - -——>——>——>——>——>——>——>——>——>[reboot](/pages/010501020501040117) - -——>——>——>——>——>——>——>——>——>[top](/pages/010501020501040118) - -——>——>——>——>——>——>——>——> [文件命令](/pages/extra/157078/) - -——>——>——>——>——>——>——>——>——> [cat](/pages/010501020501040201) - -——>——>——>——>——>——>——>——>——> [cd](/pages/010501020501040202) - -——>——>——>——>——>——>——>——>——> [chgrp](/pages/010501020501040203) - -——>——>——>——>——>——>——>——>——> [chmod](/pages/010501020501040204) - -——>——>——>——>——>——>——>——>——> [chown](/pages/010501020501040205) - -——>——>——>——>——>——>——>——>——> [cp](/pages/010501020501040206) - -——>——>——>——>——>——>——>——>——> [format](/pages/010501020501040207) - -——>——>——>——>——>——>——>——>——> [ls](/pages/010501020501040208) - -——>——>——>——>——>——>——>——>——> [lsfd](/pages/010501020501040209) - -——>——>——>——>——>——>——>——>——> [mkdir](/pages/01050102050104020a) - -——>——>——>——>——>——>——>——>——> [mount](/pages/01050102050104020b) - -——>——>——>——>——>——>——>——>——> [partinfo](/pages/01050102050104020c) - -——>——>——>——>——>——>——>——>——> [partition](/pages/01050102050104020d) - -——>——>——>——>——>——>——>——>——> [pwd](/pages/01050102050104020e) - -——>——>——>——>——>——>——>——>——> [rm](/pages/01050102050104020f) - -——>——>——>——>——>——>——>——>——> [rmdir](/pages/010501020501040210) - -——>——>——>——>——>——>——>——>——> [statfs](/pages/010501020501040211) - -——>——>——>——>——>——>——>——>——> [sync](/pages/010501020501040212) - -——>——>——>——>——>——>——>——>——> [touch](/pages/010501020501040213) - -——>——>——>——>——>——>——>——>——> [writeproc](/pages/010501020501040214) - -——>——>——>——>——>——>——>——>——> [umount](/pages/010501020501040215) - -——>——>——>——>——>——>——>——>——>[du](/pages/010501020501040216) - -——>——>——>——>——>——>——>——>——>[mv](/pages/010501020501040217) - -——>——>——>——>——>——>——>——> [网络命令](/pages/extra/49032e/) - -——>——>——>——>——>——>——>——>——> [arp](/pages/010501020501040301) - -——>——>——>——>——>——>——>——>——> [dhclient](/pages/010501020501040302) - -——>——>——>——>——>——>——>——>——> [ifconfig](/pages/010501020501040303) - -——>——>——>——>——>——>——>——>——> [ipdebug](/pages/010501020501040304) - -——>——>——>——>——>——>——>——>——> [netstat](/pages/010501020501040305) - -——>——>——>——>——>——>——>——>——> [ntpdate](/pages/010501020501040306) - -——>——>——>——>——>——>——>——>——> [ping](/pages/010501020501040307) - -——>——>——>——>——>——>——>——>——> [ping6](/pages/010501020501040308) - -——>——>——>——>——>——>——>——>——> [telnet](/pages/010501020501040309) - -——>——>——>——>——>——>——>——>——> [tftp](/pages/01050102050104030a) - -——>——>——>——>——>——>——> [魔法键使用方法](/pages/01050102050105) - -——>——>——>——>——>——>——> [用户态异常信息说明](/pages/01050102050106) - -——>——>——>——>——>——> [Trace](/pages/010501020502) - -——>——>——>——>——>——>[Perf调测](/pages/010501020503) - -——>——>——>——>——>——>[LMS调测](/pages/010501020504) - -——>——>——>——>——>——> [进程调测](/pages/extra/2d504d/) - -——>——>——>——>——>——>——> [CPU占用率](/pages/01050102050501) - -——>——>——>——>——>——> [内存调测](/pages/extra/502e79/) - -——>——>——>——>——>——>——> [内存信息统计](/pages/01050102050601) - -——>——>——>——>——>——>——> [内存泄漏检测](/pages/01050102050602) - -——>——>——>——>——>——>——> [踩内存检测](/pages/01050102050603) - -——>——>——>——>——>——>[用户态内存调测](/pages/extra/579697/) - -——>——>——>——>——>——>——>[基本概念](/pages/01050102050701) - -——>——>——>——>——>——>——>[运行机制](/pages/01050102050702) - -——>——>——>——>——>——>——>[使用指导](/pages/extra/e21465/) - -——>——>——>——>——>——>——>——>[接口说明](/pages/0105010205070301) - -——>——>——>——>——>——>——>——>[使用说明](/pages/extra/1f40f7/) - -——>——>——>——>——>——>——>——>——>[接口调用方式](/pages/010501020507030201) - -——>——>——>——>——>——>——>——>——>[命令行参数方式](/pages/010501020507030202) - -——>——>——>——>——>——>——>[常见问题场景](/pages/01050102050704) - -——>——>——>——>——>——> [其他内核调测手段](/pages/extra/f49df5/) - -——>——>——>——>——>——>——> [临终遗言](/pages/01050102050801) - -——>——>——>——>——>——>——> [常见问题定位方法](/pages/01050102050802) - -——>——>——>——>——> [附录](/pages/extra/658691/) - -——>——>——>——>——>——> [基本数据结构](/pages/extra/1f9e6d/) - -——>——>——>——>——>——>——> [双向链表](/pages/01050102060101) - -——>——>——>——>——>——>——> [位操作](/pages/01050102060102) - -——>——>——>——>——>——> [标准库](/pages/010501020602) - -——>——>——>——> [标准系统内核](/pages/extra/d328cc/) - -——>——>——>——>——> [Linux内核概述](/pages/0105010301) - -——>——>——>——>——> [OpenHarmony开发板Patch使用指导](/pages/0105010302) - -——>——>——>——>——> [Linux内核编译与构建指导](/pages/0105010303) - -——>——>——> [驱动](/pages/extra/ce6aec/) - -——>——>——>——>[HDF驱动框架](/pages/extra/cda5c5/) - -——>——>——>——>——>[HDF开发概述](/pages/0105020101) - -——>——>——>——>——>[驱动开发](/pages/0105020102) - -——>——>——>——>——>[驱动服务管理](/pages/0105020103) - -——>——>——>——>——>[驱动消息机制管理](/pages/0105020104) - -——>——>——>——>——>[配置管理](/pages/0105020105) - -——>——>——>——>——>[HDF开发实例](/pages/0105020106) - -——>——>——>——>[平台驱动开发](/pages/extra/6b1378/) - -——>——>——>——>——>[ADC](/pages/0105020201) - -——>——>——>——>——>[GPIO](/pages/0105020202) - -——>——>——>——>——>[HDMI](/pages/0105020203) - -——>——>——>——>——>[I2C](/pages/0105020204) - -——>——>——>——>——>[I3C](/pages/0105020205) - -——>——>——>——>——>[MIPI-CSI](/pages/0105020206) - -——>——>——>——>——>[MIPI-DSI](/pages/0105020207) - -——>——>——>——>——>[MMC](/pages/0105020208) - -——>——>——>——>——>[PWM](/pages/0105020209) - -——>——>——>——>——>[RTC](/pages/010502020a) - -——>——>——>——>——>[SDIO](/pages/010502020b) - -——>——>——>——>——>[SPI](/pages/010502020c) - -——>——>——>——>——>[UART](/pages/010502020d) - -——>——>——>——>——>[WatchDog](/pages/010502020e) - -——>——>——>——>[平台驱动使用](/pages/extra/6777d1/) - -——>——>——>——>——>[ADC](/pages/0105020301) - -——>——>——>——>——>[GPIO](/pages/0105020302) - -——>——>——>——>——>[HDMI](/pages/0105020303) - -——>——>——>——>——>[I2C](/pages/0105020304) - -——>——>——>——>——>[I3C](/pages/0105020305) - -——>——>——>——>——>[MIPI-CSI](/pages/0105020306) - -——>——>——>——>——>[MIPI-DSI](/pages/0105020307) - -——>——>——>——>——>[PWM](/pages/0105020308) - -——>——>——>——>——>[RTC](/pages/0105020309) - -——>——>——>——>——>[SDIO](/pages/010502030a) - -——>——>——>——>——>[SPI](/pages/010502030b) - -——>——>——>——>——>[UART](/pages/010502030c) - -——>——>——>——>——>[WATCHDOG](/pages/010502030d) - -——>——>——>——>[外设驱动使用](/pages/extra/665bcf/) - -——>——>——>——>——>[LCD](/pages/0105020401) - -——>——>——>——>——>[TOUCHSCREEN](/pages/0105020402) - -——>——>——>——>——>[SENSOR](/pages/0105020403) - -——>——>——>——>——>[WLAN](/pages/0105020404) - -——>——>——>——>——>[AUDIO](/pages/0105020405) - -——>——>——>——>——>[USB](/pages/0105020406) - -——>——>——>——>——>[CAMERA](/pages/0105020407) - -——>——>——> [编译构建](/pages/extra/7014d3/) - -——>——>——>——> [轻量和小型系统编译构建指导](/pages/01050301) - -——>——>——>——> [标准系统编译构建指导](/pages/01050302) - -——>——>——>——>[构建系统编码规范和最佳实践指导](/pages/01050303) - -——>——>——> [分布式远程启动](/pages/010504) - -——>——>——> [图形图像](/pages/extra/7fcbf2/) - -——>——>——>——> [图形图像概述](/pages/01050501) - -——>——>——>——> [容器类组件开发指导](/pages/01050502) - -——>——>——>——> [布局容器类组件开发指导](/pages/01050503) - -——>——>——>——> [普通组件开发指导](/pages/01050504) - -——>——>——>——> [动画开发指导](/pages/01050505) - -——>——>——> [媒体](/pages/extra/c169e0/) - -——>——>——>——> [相机](/pages/extra/ad4327/) - -——>——>——>——>——> [相机开发概述](/pages/0105060101) - -——>——>——>——>——> [拍照开发指导](/pages/0105060102) - -——>——>——>——>——> [录像开发指导](/pages/0105060103) - -——>——>——>——>——> [预览开发指导](/pages/0105060104) - -——>——>——>——> [音视频](/pages/extra/f106bb/) - -——>——>——>——>——> [音视频开发概述](/pages/0105060201) - -——>——>——>——>——> [音视频播放开发指导](/pages/0105060202) - -——>——>——>——>——> [音视频录制开发指导](/pages/0105060203) - -——>——>——> [公共基础](/pages/extra/ce319f/) - -——>——>——>——> [公共基础库概述](/pages/01050701) - -——>——>——>——> [公共基础库开发指导](/pages/01050702) - -——>——>——>——> [公共基础库常见问题](/pages/01050703) - -——>——>——> [AI框架](/pages/extra/ac23c8/) - -——>——>——>——> [概述](/pages/01050801) - -——>——>——>——> [搭建环境](/pages/01050802) - -——>——>——>——> [技术规范](/pages/extra/574388/) - -——>——>——>——>——> [代码管理规范](/pages/0105080301) - -——>——>——>——>——> [命名规范](/pages/0105080302) - -——>——>——>——>——> [接口开发规范](/pages/0105080303) - -——>——>——>——> [开发指导](/pages/extra/6e5a07/) - -——>——>——>——>——> [SDK开发过程](/pages/0105080401) - -——>——>——>——>——> [插件的开发过程](/pages/0105080402) - -——>——>——>——>——> [配置文件的开发过程](/pages/0105080403) - -——>——>——>——> [开发示例](/pages/extra/1bd7d2/) - -——>——>——>——>——> [唤醒词识别SDK的开发示例](/pages/0105080501) - -——>——>——>——>——> [唤醒词识别插件的开发示例](/pages/0105080502) - -——>——>——>——>——> [唤醒词识别配置文件的开发示例](/pages/0105080503) - -——>——>——> [Sensor服务](/pages/extra/fdd664/) - -——>——>——>——> [Sensor服务子系概述](/pages/01050901) - -——>——>——>——> [Sensor服务子系使用指导](/pages/01050902) - -——>——>——>——> [Sensor服务子系使用实例](/pages/01050903) - -——>——>——> [用户程序框架](/pages/extra/72b946/) - -——>——>——>——> [概述](/pages/01050a01) - -——>——>——>——> [搭建环境](/pages/01050a02) - -——>——>——>——> [开发指导](/pages/01050a03) - -——>——>——>——> [开发实例](/pages/01050a04) - -——>——>——> [OTA升级](/pages/01050b) - -——>——>——>[电话服务](/pages/extra/019068/) - -——>——>——>——>[电话服务概述](/pages/01050c01) - -——>——>——>——>[电话服务开发指导](/pages/01050c02) - -——>——>——> [安全](/pages/extra/2dd473/) - -——>——>——>——> [概述](/pages/01050d01) - -——>——>——>——> [应用验签开发指导](/pages/01050d02) - -——>——>——>——> [应用权限管理开发指导](/pages/01050d03) - -——>——>——>——> [IPC通信鉴权开发指导](/pages/01050d04) - -——>——>——> [启动恢复](/pages/extra/9238e4/) - -——>——>——>——> [启动恢复子系统概述](/pages/01050e01) - -——>——>——>——> [init启动引导组件](/pages/01050e02) - -——>——>——>——> [appspawn应用孵化组件](/pages/01050e03) - -——>——>——>——> [bootstrap服务启动组件](/pages/01050e04) - -——>——>——>——> [syspara系统属性组件](/pages/01050e05) - -——>——>——>——> [常见问题](/pages/01050e06) - -——>——>——>——> [参考](/pages/01050e07) - -——>——>——> [DFX](/pages/extra/684ab8/) - -——>——>——>——> [DFX概述](/pages/01051001) - -——>——>——>——> [HiLog开发指导](/pages/01051002) - -——>——>——>——> [HiLog\_Lite开发指导](/pages/01051003) - -——>——>——>——> [HiSysEvent开发指导](/pages/01050f04) - -——>——>——> [DFX](/pages/extra/684ab8/) - -——>——>——>——>[DFX概述](/pages/01051001) - -——>——>——>——>[HiLog开发指导](/pages/01051002) - -——>——>——>——>[HiLog\_Lite开发指导](/pages/01051003) - -——>——>——>——>[HiTrace开发指导](/pages/01051004) - -——>——>——>——>[HiCollie开发指导](/pages/01051005) - -——>——>——>——>[HiSysEvent开发指导](/pages/01050f04) - -——>——>——>——>——>[HiSysEvent打点指导](/pages/0105100601) - -——>——>——>——>——>[HiSysEvent订阅指导](/pages/0105100602) - -——>——>——>——>——>[HiSysEvent查询指导](/pages/0105100603) - -——>——>——>——>——>[HiSysEvent工具使用指导](/pages/0105100604) - -——>——> 专题 - -——>——>——> [HPM bundle](/pages/extra/341505/) - -——>——>——>——> [HPM Bundle开发规范](/pages/01060101) - -——>——>——>——> [开发指南](/pages/extra/460736/) - -——>——>——>——>——> [HPM Bundle概述](/pages/0106010201) - -——>——>——>——>——> [安装hpm命令行工具](/pages/0106010202) - -——>——>——>——>——> [开发Bundle](/pages/0106010203) - -——>——>——>——> [开发示例](/pages/extra/5aa5a6/) - -——>——>——>——>——> [HPM介绍](/pages/0106010301) - -——>——>——>——>——> [编译环境准备](/pages/0106010302) - -——>——>——>——>——> [操作实例](/pages/0106010303) - -——>——> 设备开发示例 - -——>——>——> [轻量和小型系统设备](/pages/extra/4cd9dc/) - -——>——>——>——> [WLAN连接类产品](/pages/extra/a9f9b7/) - -——>——>——>——>——> [LED外设控制](/pages/0107010101) - -——>——>——>——>——> [集成三方SDK](/pages/0107010102) - -——>——>——>——> [无屏摄像头类产品](/pages/extra/3b686a/) - -——>——>——>——>——> [摄像头控制](/pages/extra/b2b869/) - -——>——>——>——>——>——> [概述](/pages/010701020101) - -——>——>——>——>——>——> [示例开发](/pages/extra/d23bd1/) - -——>——>——>——>——>——>——> [拍照开发指导](/pages/01070102010201) - -——>——>——>——>——>——>——> [录像开发指导](/pages/01070102010202) - -——>——>——>——>——>——> [应用实例](/pages/010701020103) - -——>——>——>——> [带屏摄像头类产品](/pages/extra/51c9a4/) - -——>——>——>——>——> [屏幕和摄像头控制](/pages/extra/ac3f29/) - -——>——>——>——>——>——> [概述](/pages/010701030101) - -——>——>——>——>——>——> [示例开发](/pages/extra/781d25/) - -——>——>——>——>——>——>——> [拍照开发指导](/pages/01070103010201) - -——>——>——>——>——>——>——> [录像开发指导](/pages/01070103010202) - -——>——>——>——>——>——>——> [预览开发指导](/pages/01070103010203) - -——>——>——>——>——>——> [应用实例](/pages/010701030103) - -——>——>——>——>——> [视觉应用开发](/pages/extra/d06f24/) - -——>——>——>——>——>——> [概述](/pages/010701030201) - -——>——>——>——>——>——> [开发准备](/pages/010701030202) - -——>——>——>——>——>——> [添加页面](/pages/010701030203) - -——>——>——>——>——>——> [开发首页](/pages/010701030204) - -——>——>——>——>——>——> [开发详情页](/pages/010701030205) - -——>——>——>——>——>——> [调试打包](/pages/010701030206) - -——>——>——>——>——>——> [真机运行](/pages/010701030207) - -——>——>——>——>——>——> [常见问题](/pages/010701030208) - -——>——>——> [标准系统设备](/pages/extra/c37a91/) - -——>——>——>——> [时钟应用开发指导](/pages/01070201) - -——>——>——>——> [平台驱动开发示例](/pages/01070202) - -——>——>——>——> [外设驱动开发示例](/pages/01070203) - -——>——> 应用开发 - -——>——>——> [应用开发快速入门](application-dev/quick-start) - -——>——>——>——> [开发准备](/pages/01080101) - -——>——>——>——> [使用JS语言开发](/pages/01080102) - -——>——>——>——> [使用eTS语言开发](/pages/01080103) - -——>——>——> 方舟开发框架(ArkUI) - -——>——>——>——> [方舟开发框架概述](/pages/01080201) - -——>——>——>——> 基于JS扩展的类Web开发范式 - -——>——>——>——>——> [概述](/pages/0108020201) - -——>——>——>——>——> 框架说明 - -——>——>——>——>——>——> [文件组织](/pages/010802020201) - -——>——>——>——>——>——> [js标签配置](/pages/010802020202) - -——>——>——>——>——>——> [app.js](/pages/010802020203) - -——>——>——>——>——>——> 语法 - -——>——>——>——>——>——>——> [HML语法参考](/pages/01080202020401) - -——>——>——>——>——>——>——> [CSS语法参考](/pages/01080202020402) - -——>——>——>——>——>——>——> [JS语法参考](/pages/01080202020403) - -——>——>——>——>——>——> [生命周期](/pages/010802020205) - -——>——>——>——>——>——> [资源限定与访问](/pages/010802020206) - -——>——>——>——>——>——> [多语言支持](/pages/010802020207) - -——>——>——>——>——> 构建用户界面 - -——>——>——>——>——>——> [组件介绍](/pages/010802020301) - -——>——>——>——>——>——> 构建布局 - -——>——>——>——>——>——>——> [布局说明](/pages/01080202030201) - -——>——>——>——>——>——>——> [添加标题行和文本区域](/pages/01080202030202) - -——>——>——>——>——>——>——> [添加图片区域](/pages/01080202030203) - -——>——>——>——>——>——>——> [添加留言区域](/pages/01080202030204) - -——>——>——>——>——>——>——> [添加容器](/pages/01080202030205) - -——>——>——>——>——>——> [添加交互](/pages/010802020303) - -——>——>——>——>——>——> [动画](/pages/010802020304) - -——>——>——>——>——>——> [事件](/pages/010802020305) - -——>——>——>——>——>——> [页面路由](/pages/010802020306) - -——>——>——>——>——> 常见组件开发指导 - -——>——>——>——>——>——> [Text](/pages/010802020401) - -——>——>——>——>——>——> [Input](/pages/010802020402) - -——>——>——>——>——>——> [Button](/pages/010802020403) - -——>——>——>——>——>——> [List](/pages/010802020404) - -——>——>——>——>——>——> [Picker](/pages/010802020405) - -——>——>——>——>——>——> [Dialog](/pages/010802020406) - -——>——>——>——>——>——> [Form](/pages/010802020407) - -——>——>——>——>——>——> [Stepper](/pages/010802020408) - -——>——>——>——>——>——> [Tabs](/pages/010802020409) - -——>——>——>——>——>——> [Image](/pages/01080202040a) - -——>——>——>——>——> 动效开发指导 - -——>——>——>——>——>——> CSS动画 - -——>——>——>——>——>——>——> [属性样式动画](/pages/01080202050101) - -——>——>——>——>——>——>——> [transform样式动画](/pages/01080202050102) - -——>——>——>——>——>——>——> [background-position样式动画](/pages/01080202050103) - -——>——>——>——>——>——> JS动画 - -——>——>——>——>——>——>——> [组件动画](/pages/01080202050201) - -——>——>——>——>——>——>——> 插值器动画 - -——>——>——>——>——>——>——>——> [动画动效](/pages/0108020205020201) - -——>——>——>——>——>——>——>——> [动画帧](/pages/0108020205020202) - -——>——>——>——>——> [自定义组件](/pages/0108020206) - -——>——>——>——> 基于TS扩展的声明式开发范式 - -——>——>——>——>——> [概述](/pages/0108020301) - -——>——>——>——>——> 框架说明 - -——>——>——>——>——>——> 文件组织 - -——>——>——>——>——>——>——> [目录结构](/pages/01080203020101) - -——>——>——>——>——>——>——> [应用代码文件访问规则](/pages/01080203020102) - -——>——>——>——>——>——> [js标签配置](/pages/010802030202) - -——>——>——>——>——>——> 资源访问 - -——>——>——>——>——>——>——> [媒体资源类型说明](/pages/01080203020301) - -——>——>——>——>——>——> [像素单位](/pages/010802030204) - -——>——>——>——>——>——> [类型定义](/pages/010802030205) - -——>——>——>——>——> 声明式语法 - -——>——>——>——>——>——> [描述规范使用说明](/pages/010802030301) - -——>——>——>——>——>——> 通用UI描述规范 - -——>——>——>——>——>——>——> [基本概念](/pages/01080203030201) - -——>——>——>——>——>——>——> 声明式UI描述规范 - -——>——>——>——>——>——>——>——> [无构造参数配置](/pages/0108020303020201) - -——>——>——>——>——>——>——>——> [必选参数构造配置](/pages/0108020303020202) - -——>——>——>——>——>——>——>——> [属性配置](/pages/0108020303020203) - -——>——>——>——>——>——>——>——> [事件配置](/pages/0108020303020204) - -——>——>——>——>——>——>——>——> [子组件配置](/pages/0108020303020205) - -——>——>——>——>——>——>——> 组件化 - -——>——>——>——>——>——>——>——> [@Component](/pages/0108020303020301) - -——>——>——>——>——>——>——>——> [@Entry](/pages/0108020303020302) - -——>——>——>——>——>——>——>——> [@Preview](/pages/0108020303020303) - -——>——>——>——>——>——>——>——> [@Builder](/pages/0108020303020304) - -——>——>——>——>——>——>——>——> [@Extend](/pages/0108020303020305) - -——>——>——>——>——>——>——>——> [@CustomDialog](/pages/0108020303020306) - -——>——>——>——>——>——> UI状态管理 - -——>——>——>——>——>——>——> [基本概念](/pages/01080203030301) - -——>——>——>——>——>——>——> 管理组件拥有的状态 - -——>——>——>——>——>——>——>——> [@State](/pages/0108020303030201) - -——>——>——>——>——>——>——>——> [@Prop](/pages/0108020303030202) - -——>——>——>——>——>——>——>——> [@Link](/pages/0108020303030203) - -——>——>——>——>——>——>——> 管理应用程序的状态 - -——>——>——>——>——>——>——>——> 接口 - -——>——>——>——>——>——>——>——>——> [应用程序的数据存储](/pages/010802030303030101) - -——>——>——>——>——>——>——>——>——> [持久化数据管理](/pages/010802030303030102) - -——>——>——>——>——>——>——>——>——> [环境变量](/pages/010802030303030103) - -——>——>——>——>——>——>——>——> [AppStorage与组件同步](/pages/0108020303030302) - -——>——>——>——>——>——>——> 其他类目的状态管理 - -——>——>——>——>——>——>——>——> [Observed和ObjectLink数据管理](/pages/0108020303030401) - -——>——>——>——>——>——>——>——> [@Consume和@Provide数据管理](/pages/0108020303030402) - -——>——>——>——>——>——>——>——> [@Watch](/pages/0108020303030403) - -——>——>——>——>——>——> 渲染控制语法 - -——>——>——>——>——>——>——> [条件渲染](/pages/01080203030401) - -——>——>——>——>——>——>——> [循环渲染](/pages/01080203030402) - -——>——>——>——>——>——>——> [数据懒加载](/pages/01080203030403) - -——>——>——>——>——>——> 深入理解组件化 - -——>——>——>——>——>——>——> [build函数](/pages/01080203030501) - -——>——>——>——>——>——>——> [自定义组件初始化](/pages/01080203030502) - -——>——>——>——>——>——>——> [自定义组件生命周期回调函数](/pages/01080203030503) - -——>——>——>——>——>——>——> [组件创建和重新初始化示例](/pages/01080203030504) - -——>——>——>——>——>——> 语法糖 - -——>——>——>——>——>——>——> [装饰器](/pages/01080203030601) - -——>——>——>——>——>——>——> [链式调用](/pages/01080203030602) - -——>——>——>——>——>——>——> [struct对象](/pages/01080203030603) - -——>——>——>——>——>——>——> [在实例化过程中省略"new"](/pages/01080203030604) - -——>——>——>——>——>——>——> [组件创建使用独立一行](/pages/01080203030605) - -——>——>——>——>——>——>——> [生成器函数内使用TS语言的限制](/pages/01080203030606) - -——>——>——>——>——> 体验声明式UI - -——>——>——>——>——>——> [创建声明式UI工程](/pages/010802030401) - -——>——>——>——>——>——> [初识Component](/pages/010802030402) - -——>——>——>——>——>——> [创建简单视图](/pages/010802030403) - -——>——>——>——>——> 页面布局与连接 - -——>——>——>——>——>——> [构建食物数据模型](/pages/010802030501) - -——>——>——>——>——>——> [构建食物列表List布局](/pages/010802030502) - -——>——>——>——>——>——> [构建食物分类Grid布局](/pages/010802030503) - -——>——>——>——>——>——> [页面跳转与数据传递](/pages/010802030504) - -——>——>——> 媒体 - -——>——>——>——> 音频 - -——>——>——>——>——> [音频开发概述](/pages/0108030101) - -——>——>——>——>——> [音频播放开发指导](/pages/0108030102) - -——>——>——>——>——> [音频管理开发指导](/pages/0108030103) - -——>——>——>——>——> [音频录制开发指导](/pages/0108030104) - -——>——>——> 用户认证 - -——>——>——>——> [用户认证开发概述](/pages/01080401) - -——>——>——>——> [用户认证开发指导](/pages/01080402) - -——>——>——> IPC与RPC通信 - -——>——>——>——> [IPC与RPC通信概述](/pages/01080501) - -——>——>——>——> [IPC与RPC通信开发指导](/pages/01080502) - -——>——>——>——> [远端状态订阅开发实例](/pages/01080503) - -——>——>——> 分布式数据服务 - -——>——>——>——> [分布式数据服务概述](/pages/01080601) - -——>——>——>——> [分布式数据服务开发指导](/pages/01080602) - -——>——>——> USB服务 - -——>——>——>——> [USB服务开发概述](/pages/01080701) - -——>——>——>——> [USB服务开发指导](/pages/01080702) - -——>——>——> DFX - -——>——>——>——> [应用事件打点概述](/pages/01080801) - -——>——>——>——> [应用事件开发指导](/pages/01080802) - -——>——>——> [DevEco Studio(OpenHarmony)使用指南](/pages/extra/d114c8/) - -——>——>——>——> [概述](/pages/01080901) - -——>——>——>——> [版本变更说明](/pages/01080902) - -——>——>——>——> [配置OpenHarmony SDK](/pages/01080903) - -——>——>——>——> [创建OpenHarmony工程](/pages/extra/4c1a6a/) - -——>——>——>——>——> [使用工程向导创建新工程](/pages/0108090401) - -——>——>——>——>——> [通过导入Sample方式创建新工程](/pages/0108090402) - -——>——>——>——> [配置OpenHarmony应用签名信息](/pages/01080905) - -——>——>——>——> [安装运行OpenHarmony应用](/pages/01080906) - -——>——> 调测 - -——>——>——> [测试用例开发](/pages/010901) - -——>——>——> [调测工具](/pages/extra/5138cc/) - -——>——>——>——> [bytrace使用指导](/pages/01090201) - -——>——>——>——> [hdc\_std 使用指导](/pages/01090202) - -——>——> XTS认证 - -——>——>——> [XTS认证用例开发指导](/pages/010a01) - -——>——> 工具 - -——>——>——> [Docker编译环境](/pages/010b01) - -——>——>——> [IDE集成开发环境](/pages/010b02) - -——>——> 参考 - -——>——>——> [JS API参考](/pages/extra/cdb335/) - -——>——>——>——> Ability框架 - -——>——>——>——>——> [FeatureAbility模块](/pages/010c010101) - -——>——>——>——>——> [ParticleAbility模块](/pages/010c010102) - -——>——>——>——>——> [DataAbilityHelper模块](/pages/010c010103) - -——>——>——>——>——> [DataUriUtils模块](/pages/010c010104) - -——>——>——>——>——> [Bundle模块](/pages/010c010105) - -——>——>——>——>——> [CommonEvent模块](/pages/010c010106) - -——>——>——>——>——> [Notification模块](/pages/010c010107) - -——>——>——>——>——> [Context模块](/pages/010c010108) - -——>——>——>——> 资源管理 - -——>——>——>——>——> [资源管理](/pages/010c010201) - -——>——>——>——>——> [国际化(I18n)](/pages/010c010202) - -——>——>——>——>——> [国际化(Intl)](/pages/010c010203) - -——>——>——>——> 媒体 - -——>——>——>——>——> [音频管理](/pages/010c010301) - -——>——>——>——>——> [媒体服务](/pages/010c010302) - -——>——>——>——> 安全 - -——>——>——>——>——> [用户认证](/pages/010c010401) - -——>——>——>——> 数据管理 - -——>——>——>——>——> [轻量级存储](/pages/010c010501) - -——>——>——>——>——> [分布式数据管理](/pages/010c010502) - -——>——>——>——>——> [关系型数据库](/pages/010c010503) - -——>——>——>——>——> [结果集](/pages/010c010504) - -——>——>——>——>——> [DataAbility 谓词](/pages/010c010505) - -——>——>——>——>——> [设置数据项名称](/pages/010c010506) - -——>——>——>——> 文件管理 - -——>——>——>——>——> [文件管理](/pages/010c010601) - -——>——>——>——>——> [Statfs管理](/pages/010c010602) - -——>——>——>——>——> [目录环境](/pages/010c010603) - -——>——>——>——> 账号管理 - -——>——>——>——>——> [分布式帐号管理](/pages/010c010701) - -——>——>——>——>——>[应用帐号管理](/pages/010c010702) - -——>——>——>——> 电话服务 - -——>——>——>——>——> [拨打电话](/pages/010c010801) - -——>——>——>——>——> [短信服务](/pages/010c010802) - -——>——>——>——>——> [SIM卡管理](/pages/010c010803) - -——>——>——>——>——> [网络搜索](/pages/010c010804) - -——>——>——>——> 网络与连接 - -——>——>——>——>——> [WLAN](/pages/010c010901) - -——>——>——>——> 设备管理 - -——>——>——>——>——> [传感器](/pages/010c010a01) - -——>——>——>——>——> [振动](/pages/010c010a02) - -——>——>——>——>——> [屏幕亮度](/pages/010c010a03) - -——>——>——>——>——> [电量信息](/pages/010c010a04) - -——>——>——>——>——> [系统电源管理](/pages/010c010a05) - -——>——>——>——>——> [Runninglock锁](/pages/010c010a06) - -——>——>——>——>——> [设备信息](/pages/010c010a07) - -——>——>——>——>——> [系统属性](/pages/010c010a08) - -——>——>——>——>——> [设备管理](/pages/010c010a09) - -——>——>——>——>——> [窗口](/pages/010c010a0a) - -——>——>——>——>——> [显示设备属性](/pages/010c010a0b) - -——>——>——>——>——> [升级](/pages/010c010a0c) - -——>——>——>——>——> [USB管理](/pages/010c010a0d) - -——>——>——>——> 基本功能 - -——>——>——>——>——> [应用上下文](/pages/010c010b01) - -——>——>——>——>——> [日志打印](/pages/010c010b02) - -——>——>——>——>——> [页面路由](/pages/010c010b03) - -——>——>——>——>——> [弹窗](/pages/010c010b04) - -——>——>——>——>——> [应用配置](/pages/010c010b05) - -——>——>——>——>——> [定时器](/pages/010c010b06) - -——>——>——>——>——> [设置系统时间](/pages/010c010b07) - -——>——>——>——>——> [动画](/pages/010c010b08) - -——>——>——>——>——> [应用打点](/pages/010c010b09) - -——>——>——>——>——> [性能打点](/pages/010c010b0a) - -——>——>——>——>——> [故障日志获取](/pages/010c010b0b) - -——>——>——>——> 语言基础类库 - -——>——>——>——>——> [获取进程相关的信息](/pages/010c010c01) - -——>——>——>——>——> [URL字符串解析](/pages/010c010c02) - -——>——>——>——>——> [URI字符串解析](/pages/010c010c03) - -——>——>——>——>——> [util工具函数](/pages/010c010c04) - -——>——>——>——>——> [xml解析与生成](/pages/010c010c05) - -——>——>——>——>——> [xml转换JavaScript](/pages/010c010c06) - -——>——>——>——>——> [启动一个worker](/pages/010c010c07) - -——>——>——> ArkUI组件参考 - -——>——>——>——> [基于JS扩展的类Web开发范式](/pages/extra/74333b/) - -——>——>——>——>——> 组件 - -——>——>——>——>——>——> 通用 - -——>——>——>——>——>——>——> [通用属性](/pages/010c0201010101) - -——>——>——>——>——>——>——> [通用样式](/pages/010c0201010102) - -——>——>——>——>——>——>——> [通用事件](/pages/010c0201010103) - -——>——>——>——>——>——>——> [通用方法](/pages/010c0201010104) - -——>——>——>——>——>——>——> [动画样式](/pages/010c0201010105) - -——>——>——>——>——>——>——> [渐变样式](/pages/010c0201010106) - -——>——>——>——>——>——>——> [转场样式](/pages/010c0201010107) - -——>——>——>——>——>——>——> [媒体查询](/pages/010c0201010108) - -——>——>——>——>——>——>——> [自定义字体样式](/pages/010c0201010109) - -——>——>——>——>——>——>——> [原子布局](/pages/010c020101010a) - -——>——>——>——>——>——> 容器组件 - -——>——>——>——>——>——>——> [badge](/pages/010c0201010201) - -——>——>——>——>——>——>——> [dialog](/pages/010c0201010202) - -——>——>——>——>——>——>——> [div](/pages/010c0201010203) - -——>——>——>——>——>——>——> [form](/pages/010c0201010204) - -——>——>——>——>——>——>——> [list](/pages/010c0201010205) - -——>——>——>——>——>——>——> [list-item](/pages/010c0201010206) - -——>——>——>——>——>——>——> [list-item-group](/pages/010c0201010207) - -——>——>——>——>——>——>——> [panel](/pages/010c0201010208) - -——>——>——>——>——>——>——> [popup](/pages/010c0201010209) - -——>——>——>——>——>——>——> [refresh](/pages/010c020101020a) - -——>——>——>——>——>——>——> [stack](/pages/010c020101020b) - -——>——>——>——>——>——>——> [stepper](/pages/010c020101020c) - -——>——>——>——>——>——>——> [stepper-item](/pages/010c020101020d) - -——>——>——>——>——>——>——> [swiper](/pages/010c020101020e) - -——>——>——>——>——>——>——> [tabs](/pages/010c020101020f) - -——>——>——>——>——>——>——> [tab-bar](/pages/010c0201010210) - -——>——>——>——>——>——>——> [tab-content](/pages/010c0201010211) - -——>——>——>——>——>——> 基础组件 - -——>——>——>——>——>——>——> [button](/pages/010c0201010301) - -——>——>——>——>——>——>——> [chart](/pages/010c0201010302) - -——>——>——>——>——>——>——> [divider](/pages/010c0201010303) - -——>——>——>——>——>——>——> [image](/pages/010c0201010304) - -——>——>——>——>——>——>——> [image-animator](/pages/010c0201010305) - -——>——>——>——>——>——>——> [input](/pages/010c0201010306) - -——>——>——>——>——>——>——> [label](/pages/010c0201010307) - -——>——>——>——>——>——>——> [marquee](/pages/010c0201010308) - -——>——>——>——>——>——>——> [menu](/pages/010c0201010309) - -——>——>——>——>——>——>——> [option](/pages/010c020101030a) - -——>——>——>——>——>——>——> [picker](/pages/010c020101030b) - -——>——>——>——>——>——>——> [picker-view](/pages/010c020101030c) - -——>——>——>——>——>——>——> [piece](/pages/010c020101030d) - -——>——>——>——>——>——>——> [progress](/pages/010c020101030e) - -——>——>——>——>——>——>——> [qrcode](/pages/010c020101030f) - -——>——>——>——>——>——>——> [rating](/pages/010c0201010310) - -——>——>——>——>——>——>——> [richtext](/pages/010c0201010311) - -——>——>——>——>——>——>——> [search](/pages/010c0201010312) - -——>——>——>——>——>——>——> [select](/pages/010c0201010313) - -——>——>——>——>——>——>——> [slider](/pages/010c0201010314) - -——>——>——>——>——>——>——> [span](/pages/010c0201010315) - -——>——>——>——>——>——>——> [switch](/pages/010c0201010316) - -——>——>——>——>——>——>——> [text](/pages/010c0201010317) - -——>——>——>——>——>——>——> [textarea](/pages/010c0201010318) - -——>——>——>——>——>——>——> [toolbar](/pages/010c0201010319) - -——>——>——>——>——>——>——> [toolbar-item](/pages/010c020101031a) - -——>——>——>——>——>——>——> [toggle](/pages/010c020101031b) - -——>——>——>——>——>——> 媒体组件 - -——>——>——>——>——>——>——> [video](/pages/010c0201010401) - -——>——>——>——>——>——> 画布组件 - -——>——>——>——>——>——>——> [canvas组件](/pages/010c0201010501) - -——>——>——>——>——>——>——> [CanvasRenderingContext2D对象](/pages/010c0201010502) - -——>——>——>——>——>——>——> [Image对象](/pages/010c0201010503) - -——>——>——>——>——>——>——> [CanvasGradient对象](/pages/010c0201010504) - -——>——>——>——>——>——>——> [ImageData对象](/pages/010c0201010505) - -——>——>——>——>——>——>——> [Path2D对象](/pages/010c0201010506) - -——>——>——>——>——>——>——> [ImageBitmap对象](/pages/010c0201010507) - -——>——>——>——>——>——>——> [OffscreenCanvas对象](/pages/010c0201010508) - -——>——>——>——>——>——>——> [OffscreenCanvasRenderingContext2D对象](/pages/010c0201010509) - -——>——>——>——>——>——> 栅格组件 - -——>——>——>——>——>——>——> [基本概念](/pages/010c0201010601) - -——>——>——>——>——>——>——> [grid-container](/pages/010c0201010602) - -——>——>——>——>——>——>——> [grid-row](/pages/010c0201010603) - -——>——>——>——>——>——>——> [grid-col](/pages/010c0201010604) - -——>——>——>——>——>——> svg组件 - -——>——>——>——>——>——>——> [通用属性](/pages/010c0201010701) - -——>——>——>——>——>——>——> [svg](/pages/010c0201010702) - -——>——>——>——>——>——>——> [rect](/pages/010c0201010703) - -——>——>——>——>——>——>——> [circle](/pages/010c0201010704) - -——>——>——>——>——>——>——> [ellipse](/pages/010c0201010705) - -——>——>——>——>——>——>——> [path](/pages/010c0201010706) - -——>——>——>——>——>——>——> [line](/pages/010c0201010707) - -——>——>——>——>——>——>——> [polyline](/pages/010c0201010708) - -——>——>——>——>——>——>——> [polygon](/pages/010c0201010709) - -——>——>——>——>——>——>——> [text](/pages/010c020101070a) - -——>——>——>——>——>——>——> [tspan](/pages/010c020101070b) - -——>——>——>——>——>——>——> [textPath](/pages/010c020101070c) - -——>——>——>——>——>——>——> [animate](/pages/010c020101070d) - -——>——>——>——>——>——>——> [animateMotion](/pages/010c020101070e) - -——>——>——>——>——>——>——> [animateTransform](/pages/010c020101070f) - -——>——>——>——>——> 自定义组件 - -——>——>——>——>——>——> [基本用法](/pages/010c02010201) - -——>——>——>——>——>——> [自定义事件](/pages/010c02010202) - -——>——>——>——>——>——> [Props](/pages/010c02010203) - -——>——>——>——>——>——> [事件参数](/pages/010c02010204) - -——>——>——>——>——>——> [slot插槽](/pages/010c02010205) - -——>——>——>——>——>——> [生命周期定义](/pages/010c02010206) - -——>——>——>——>——> [附录](/pages/extra/98f426/) - -——>——>——>——>——>——> [类型说明](/pages/010c02010301) - -——>——>——>——> [基于TS扩展的声明式开发范式](/pages/extra/07ffe5/) - -——>——>——>——>——> 组件 - -——>——>——>——>——>——> 通用 - -——>——>——>——>——>——>——> [通用事件](/pages/extra/1ab473/) - -——>——>——>——>——>——>——>——> [点击事件](/pages/010c020201010101) - -——>——>——>——>——>——>——>——> [触摸事件](/pages/010c020201010102) - -——>——>——>——>——>——>——>——> [挂载卸载事件](/pages/010c020201010103) - -——>——>——>——>——>——>——>——> [按键事件](/pages/010c020201010104) - -——>——>——>——>——>——>——>——>[组件区域变化事件](/pages/010c020201010105) - -——>——>——>——>——>——>——> 通用属性 - -——>——>——>——>——>——>——>——> [尺寸设置](/pages/010c020201010201) - -——>——>——>——>——>——>——>——> [位置设置](/pages/010c020201010202) - -——>——>——>——>——>——>——>——> [布局约束](/pages/010c020201010203) - -——>——>——>——>——>——>——>——> [Flex布局](/pages/010c020201010204) - -——>——>——>——>——>——>——>——> [边框设置](/pages/010c020201010205) - -——>——>——>——>——>——>——>——> [背景设置](/pages/010c020201010206) - -——>——>——>——>——>——>——>——> [透明度设置](/pages/010c020201010207) - -——>——>——>——>——>——>——>——> [显隐控制](/pages/010c020201010208) - -——>——>——>——>——>——>——>——> [禁用控制](/pages/010c020201010209) - -——>——>——>——>——>——>——>——> [浮层](/pages/010c02020101020a) - -——>——>——>——>——>——>——>——> [Z序控制](/pages/010c02020101020b) - -——>——>——>——>——>——>——>——> [图形变换](/pages/010c02020101020c) - -——>——>——>——>——>——>——>——> [图像效果](/pages/010c02020101020d) - -——>——>——>——>——>——>——>——> [形状裁剪](/pages/010c02020101020e) - -——>——>——>——>——>——>——>——> [文本样式设置](/pages/010c02020101020f) - -——>——>——>——>——>——>——>——> [栅格设置](/pages/010c020201010210) - -——>——>——>——>——>——>——>——> [颜色渐变](/pages/010c020201010211) - -——>——>——>——>——>——>——>——> [Popup控制](/pages/010c020201010212) - -——>——>——>——>——>——>——>——> [Menu控制](/pages/010c020201010213) - -——>——>——>——>——>——>——>——>[点击控制](/pages/010c020201010214) - -——>——>——>——>——>——>——>——>[触摸热区设置](/pages/010c020201010215) - -——>——>——>——>——>——>——> 手势处理 - -——>——>——>——>——>——>——>——> [绑定手势方法](/pages/010c020201010301) - -——>——>——>——>——>——>——>——> 基础手势 - -——>——>——>——>——>——>——>——>——> [TapGesture](/pages/010c02020101030201) - -——>——>——>——>——>——>——>——>——> [LongPressGesture](/pages/010c02020101030202) - -——>——>——>——>——>——>——>——>——> [PanGesture](/pages/010c02020101030203) - -——>——>——>——>——>——>——>——>——> [PinchGesture](/pages/010c02020101030204) - -——>——>——>——>——>——>——>——>——> [RotationGesture](/pages/010c02020101030205) - -——>——>——>——>——>——>——>——>——> [SwipeGesture](/pages/010c02020101030206) - -——>——>——>——>——>——>——>——> [组合手势](/pages/010c020201010303) - -——>——>——>——>——>——> 基础组件 - -——>——>——>——>——>——>——> [Blank](/pages/010c0202010201) - -——>——>——>——>——>——>——> [Button](/pages/010c0202010202) - -——>——>——>——>——>——>——> [DataPanel](/pages/010c0202010203) - -——>——>——>——>——>——>——> [Divider](/pages/010c0202010204) - -——>——>——>——>——>——>——>[Gauge](/pages/010c0202010205) - -——>——>——>——>——>——>——> [Image](/pages/010c0202010206) - -——>——>——>——>——>——>——> [ImageAnimator](/pages/010c0202010207) - -——>——>——>——>——>——>——> [Progress](/pages/010c0202010208) - -——>——>——>——>——>——>——> [QRCode](/pages/010c0202010209) - -——>——>——>——>——>——>——> [Rating](/pages/010c020201020a) - -——>——>——>——>——>——>——> [Span](/pages/010c020201020b) - -——>——>——>——>——>——>——> [Slider](/pages/010c020201020c) - -——>——>——>——>——>——>——> [Text](/pages/010c020201020d) - -——>——>——>——>——>——>——> [TextArea](/pages/010c020201020e) - -——>——>——>——>——>——>——> [TextInput](/pages/010c020201020f) - -——>——>——>——>——>——>——> [Toggle](/pages/010c0202010210) - -——>——>——>——>——>——> 容器组件 - -——>——>——>——>——>——>——> [AlphabetIndexer](/pages/010c0202010301) - -——>——>——>——>——>——>——> [Badge](/pages/010c0202010302) - -——>——>——>——>——>——>——> [Column](/pages/010c0202010303) - -——>——>——>——>——>——>——> [ColumnSplit](/pages/010c0202010304) - -——>——>——>——>——>——>——> [Counter](/pages/010c0202010305) - -——>——>——>——>——>——>——> [Flex](/pages/010c0202010306) - -——>——>——>——>——>——>——> [GridContainer](/pages/010c0202010307) - -——>——>——>——>——>——>——> [Grid](/pages/010c0202010308) - -——>——>——>——>——>——>——> [GridItem](/pages/010c0202010309) - -——>——>——>——>——>——>——> [List](/pages/010c020201030a) - -——>——>——>——>——>——>——> [ListItem](/pages/010c020201030b) - -——>——>——>——>——>——>——> [Navigator](/pages/010c020201030c) - -——>——>——>——>——>——>——> [Navigation](/pages/010c020201030d) - -——>——>——>——>——>——>——> [Panel](/pages/010c020201030e) - -——>——>——>——>——>——>——> [Row](/pages/010c020201030f) - -——>——>——>——>——>——>——> [RowSplit](/pages/010c0202010310) - -——>——>——>——>——>——>——> [Scroll](/pages/010c0202010311) - -——>——>——>——>——>——>——> [ScrollBar](/pages/010c0202010312) - -——>——>——>——>——>——>——> [Stack](/pages/010c0202010313) - -——>——>——>——>——>——>——> [Swiper](/pages/010c0202010314) - -——>——>——>——>——>——>——> [Tabs](/pages/010c0202010315) - -——>——>——>——>——>——>——> [TabContent](/pages/010c0202010316) - -——>——>——>——>——>——>——> [Stepper](/pages/010c0202010317) - -——>——>——>——>——>——>——> [StepperItem](/pages/010c0202010318) - -——>——>——>——>——>——> 绘制组件 - -——>——>——>——>——>——>——> [Circle](/pages/010c0202010401) - -——>——>——>——>——>——>——> [Ellipse](/pages/010c0202010402) - -——>——>——>——>——>——>——> [Line](/pages/010c0202010403) - -——>——>——>——>——>——>——> [Polyline](/pages/010c0202010404) - -——>——>——>——>——>——>——> [Polygon](/pages/010c0202010405) - -——>——>——>——>——>——>——> [Path](/pages/010c0202010406) - -——>——>——>——>——>——>——> [Rect](/pages/010c0202010407) - -——>——>——>——>——>——>——> [Shape](/pages/010c0202010408)‘ - -——>——>——>——>——>——>画布组件 - -——>——>——>——>——>——>——>[Canvas](/pages/010c0202010501) - -——>——>——>——>——>——>——>[CanvasRenderingContext2D对象](/pages/010c0202010502) - -——>——>——>——>——>——>——>[OffscreenCanvasRenderingConxt2D对象](/pages/010c0202010503) - -——>——>——>——>——>——>——>[Lottie](/pages/010c0202010504) - -——>——>——>——>——>——>——>[Path2D对象](/pages/010c0202010505) - -——>——>——>——>——>——>——>[CanvasGradient对象](/pages/010c0202010506) - -——>——>——>——>——>——>——>[ImageBitmap对象](/pages/010c0202010507) - -——>——>——>——>——>——>——>[ImageData对象](/pages/010c0202010508) - -——>——>——>——>——> 动画 - -——>——>——>——>——>——> [属性动画](/pages/010c02020201) - -——>——>——>——>——>——> [显式动画](/pages/010c02020202) - -——>——>——>——>——>——> 转场动画 - -——>——>——>——>——>——>——> [页面间转场](/pages/010c0202020301) - -——>——>——>——>——>——>——> [组件内转场](/pages/010c0202020302) - -——>——>——>——>——>——>——> [共享元素转场](/pages/010c0202020303) - -——>——>——>——>——>——> [路径动画](/pages/010c02020204) - -——>——>——>——>——>——> [矩阵变换](/pages/010c02020205) - -——>——>——>——>——>——> [插值计算](/pages/010c02020206) - -——>——>——>——>——> 全局UI方法 - -——>——>——>——>——>——> [警告弹窗](/pages/010c02020301) - -——>——>——>——>——>——> [自定义弹窗](/pages/010c02020302) - -——>——>——>——>——>——> [图片缓存](/pages/010c02020303) - -——>——>——>——>——>——> [媒体查询](/pages/010c02020304) - -——>——>——>——>——> 附录 - -——>——>——>——>——>——> [文档中涉及到的内置枚举值](/pages/010c02020401) - -——>——>——>[应用开发包结构说明](/pages/010c03) - -——>——>——> 常见问题-设备开发 - -——>——>——>——>[常见问题概述](/pages/010c0401) - -——>——>——>——>[环境搭建常见问题](/pages/010c0402) - -——>——>——>——>[编译构建子系统常见问题](/pages/010c0403) - -——>——>——>——>[烧录常见问题](/pages/010c0404) - -——>——>——>——>[内核常见问题](/pages/010c0405) - -——>——>——>——>[移植常见问题](/pages/010c0406) - -——>——>——>——>[启动恢复常见问题](/pages/010c0407) - -——>——>——>——>[系统应用常见问题](/pages/010c0408) - -——>——> 贡献 - -——>——>——>[参与贡献](/pages/010d01) - -——>——>——> [行为准则](/pages/010d02) - -——>——>——>[贡献代码](/pages/010d03) - -——>——>——>[贡献流程](/pages/010d04) - -——>——>——> [贡献文档](/pages/extra/7f2552/) - -——>——>——>——>[写作规范](/pages/010d0501) - -——>——>——>——>[为发行版本撰写配套文档](/pages/010d0502) - -——>——>——>[社区沟通与交流](/pages/010d06) - -——>——>——>[FAQ](/pages/010d07) \ No newline at end of file diff --git "a/website/docs/_posts/\345\272\224\347\224\250\345\274\200\345\217\221\345\267\245\345\205\267\347\256\200\344\273\213.md" "b/website/docs/_posts/\345\272\224\347\224\250\345\274\200\345\217\221\345\267\245\345\205\267\347\256\200\344\273\213.md" index 37fa7aa8e58b1e48db08f9c8b7ae205765db8bde..12ae39c63c4baf62d30663589e81cb308c17c1b2 100644 --- "a/website/docs/_posts/\345\272\224\347\224\250\345\274\200\345\217\221\345\267\245\345\205\267\347\256\200\344\273\213.md" +++ "b/website/docs/_posts/\345\272\224\347\224\250\345\274\200\345\217\221\345\267\245\345\205\267\347\256\200\344\273\213.md" @@ -3,6 +3,10 @@ title: 应用开发工具简介 date: 2021-07-13 18:46:33 permalink: /pages/61af3c/ sidebar: auto +categories: + - 随笔 +tags: + - --- # 应用开发工具简介 diff --git "a/website/docs/_posts/\345\274\200\345\217\221\346\235\277.md" "b/website/docs/_posts/\345\274\200\345\217\221\346\235\277.md" index f899bbcc4817ed44d8bcc5a5a69f3d093aefcd4c..de520338c51756d70b738483682e2d08c1ae0f01 100644 --- "a/website/docs/_posts/\345\274\200\345\217\221\346\235\277.md" +++ "b/website/docs/_posts/\345\274\200\345\217\221\346\235\277.md" @@ -1,8 +1,12 @@ --- title: 开发板 date: 2021-07-13 18:46:33 -permalink: /pages/e0bb52/ +permalink: /pages/e0bb52/ sidebar: auto +categories: + - 随笔 +tags: + - --- # 支持设备类型 OpenHarmony支持如下几种设备类型: diff --git "a/website/docs/_posts/\347\244\276\345\214\272/committers.md" "b/website/docs/_posts/\347\244\276\345\214\272/committers.md" index 745c7e23859390ab9734a09be9af292a352c16a3..dd8f8676ea834415d358e93a84e38d6f8b1ab9d5 100644 --- "a/website/docs/_posts/\347\244\276\345\214\272/committers.md" +++ "b/website/docs/_posts/\347\244\276\345\214\272/committers.md" @@ -6,6 +6,10 @@ comment: false editLink: false permalink: /community/committers date: 2021-08-06 02:05:46 +categories: + - 随笔 +tags: + - --- |编号|gitee账号 |gitee关联邮箱| |:----: |:----: |:----: | diff --git "a/website/docs/_posts/\347\244\276\345\214\272/guidelines_role_grouth.md" "b/website/docs/_posts/\347\244\276\345\214\272/guidelines_role_grouth.md" index eb572d4d399cfa79c97841ef36e6e15942820384..3d8d3f3720214c2969370d48b9918a3fba720845 100644 --- "a/website/docs/_posts/\347\244\276\345\214\272/guidelines_role_grouth.md" +++ "b/website/docs/_posts/\347\244\276\345\214\272/guidelines_role_grouth.md" @@ -6,6 +6,10 @@ comment: false editLink: false permalink: /community/guidelines_role_grouth date: 2021-08-06 01:58:16 +categories: + - 随笔 +tags: + - --- # **OpenHarmony社区角色定义及晋升机制** diff --git "a/website/docs/_posts/\347\244\276\345\214\272/pmc.md" "b/website/docs/_posts/\347\244\276\345\214\272/pmc.md" index 14debea51bb1dbb125e617e50dd0a4d558fee287..c22b85531eb0455c31b656c2cc9d6f652d7390ad 100644 --- "a/website/docs/_posts/\347\244\276\345\214\272/pmc.md" +++ "b/website/docs/_posts/\347\244\276\345\214\272/pmc.md" @@ -15,26 +15,26 @@ date: 2021-07-24 17:25:05 2. 发布和处理社区需求,为开源社区提供技术架构指导和技术决策; 3. 组织社区安全工作,及时进行安全漏洞扫描、响应、处理等工作; 4. 处理社区Bug、issue、邮件列表,闭环周期满足开源社区的SLA要求; -5. 负责PMC、Committer成员的[选举和退出](/community/guidelines_role_grouth),制定PMC、Committer协作机制; +5. 负责PMC、Committer成员的[选举和退出],制定PMC、Committer协作机制; ## OpenHarmony PMC成员列表 | 姓名 | 账号 | 角色 | 领域 | | :----: | :----: | :----: | :----: | -| 李毅 | [@nicholas-li](https://gitee.com/nicholas-li) | PMC主席 | 总架构 | -| 董金光 |[@dongjinguang](https://gitee.com/dongjinguang) | PMC成员 | 系统架构 | -| 任革林 | [@im-off-this-week](https://gitee.com/im-off-this-week) | PMC成员 | 架构SIG | -| 万承臻 | [@wanchengzhen](https://gitee.com/wanchengzhen) | PMC成员 | 架构SIG | -| 付天福 | [@futianfu](https://gitee.com/futianfu) | PMC成员 | 安全架构 | -| 马占福 | [@fma66169](https://gitee.com/fma66169) | PMC成员 | 版本发布SIG | -| 邢文华 | [@xhuazi](https://gitee.com/xhuazi) | PMC成员 | QA-SIG | -| 肖 峰 | [@blue.xiaofeng](https://gitee.com/blue.xiaofeng) | PMC成员 | 系统架构 | -| 聂 欣 | [@nie-x](https://gitee.com/nie-x) | PMC成员 | 测试SIG | -| 王意明 | [@youthdragon](https://gitee.com/youthdragon) | PMC成员 | 基础设施SIG | +| 李毅 | @nicholas-li | PMC主席 | 总架构 | +| 董金光 |@dongjinguang| PMC成员 | 系统架构 | +| 任革林 | @im-off-this-week | PMC成员 | 架构SIG | +| 万承臻 | @wanchengzhen | PMC成员 | 架构SIG | +| 付天福 | @futianfu | PMC成员 | 安全架构 | +| 马占福 | @fma66169 | PMC成员 | 版本发布SIG | +| 邢文华 | @xhuazi | PMC成员 | QA-SIG | +| 肖 峰 | @blue.xiaofeng | PMC成员 | 系统架构 | +| 聂 欣 | @nie-x | PMC成员 | 测试SIG | +| 王意明 | @youthdragon | PMC成员 | 基础设施SIG | ## PMC会议链接 - 会议时间: 每双周周一 14:30-16:00 -- 议题申报: [OpenHarmony PMC Meeting Proposal](https://shimo.im/sheets/N2A1MZgDZxfbBVAD/MODOC) +- 议题申报: [OpenHarmony PMC Meeting Proposal] - 会议主题: 通过邮件通知 - 会议通知: 请[订阅](https://lists.openatom.io/postorius/lists/dev.openharmony.io)邮件列表 dev@openharmony.io 获取会议链接 diff --git "a/website/docs/_posts/\347\244\276\345\214\272/\345\225\206\346\240\207\344\275\277\347\224\250\346\214\207\345\215\227.md" "b/website/docs/_posts/\347\244\276\345\214\272/\345\225\206\346\240\207\344\275\277\347\224\250\346\214\207\345\215\227.md" index 15cc39450f86c81cf341df3f635e0d30109ee632..434c8c840e487010c3f9eddb4c41caf5c7ea0a1d 100644 --- "a/website/docs/_posts/\347\244\276\345\214\272/\345\225\206\346\240\207\344\275\277\347\224\250\346\214\207\345\215\227.md" +++ "b/website/docs/_posts/\347\244\276\345\214\272/\345\225\206\346\240\207\344\275\277\347\224\250\346\214\207\345\215\227.md" @@ -32,6 +32,7 @@ date: 2021-06-01 17:08:58 * 商标使用目的(商业/非商业) * 拟使用方式 * 拟使用场景 + * 关于通过OpenHarmony兼容性测试认证的认证标识使用指引另行规定 ## OpenHarmony商标使用规范 diff --git "a/website/docs/_posts/\347\244\276\345\214\272/\347\244\276\345\214\272\346\210\220\351\225\277\350\267\257\345\276\204.md" "b/website/docs/_posts/\347\244\276\345\214\272/\347\244\276\345\214\272\346\210\220\351\225\277\350\267\257\345\276\204.md" new file mode 100644 index 0000000000000000000000000000000000000000..9bff1ebd4ab9eb11dbcb59fab5bfce0a95e940a1 --- /dev/null +++ "b/website/docs/_posts/\347\244\276\345\214\272/\347\244\276\345\214\272\346\210\220\351\225\277\350\267\257\345\276\204.md" @@ -0,0 +1,53 @@ +--- +title: 社区成长路径 +permalink: /community/role +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +date: 2021-10-11 17:08:58 +--- +# **OpenHarmony社区角色定义及晋升机制** + +## 1. 角色定义 +| 角色 | 描述| +| :---: | --- | +| 用户 (Users) | 使用OpenHarmony项目的广大用户,以Issue形式向OpenHarmony 社区反馈问题和功能建议。以PR的形式向Gitee贡献代码。| +| 贡献者 (Contributors) | 有一定代码编程经验的开发者。Contributors以参与OpenHarmony 社区代码贡献、文档贡献、技术方案讨论及设计、解答用户问题、发表技术文章及视频课程、组织策划开源OpenHarmony 社区活动等形式参与OpenHarmony 社区。 | +| 提交者 (Committers) | Committer拥有SIG子领域的代码仓写权限。Committer 负责SIG领域软件模块设计与评审,负责代码审核及维护,处理OpenHarmony社区的issue、邮件列表问题,辅导Contributors快速理解SIG领域架构设计并提升代码开发技能。 | +| SIG 负责人(SIG Leader)| SIG Leader负责特定SIG的运营及维护。SIG Leader负责定义特定SIG的工作范围及业务目标,并负责对应SIG的运营及维护;吸纳并发展Committer参与对应SIG的项目孵化、文档完善及社区推广;定期在PMC项目管理委员会汇报SIG孵化项目及SIG运营进展,并基于PMC的指导建议完成相关改进。 | +| PMC 成员 (PMC) | 项目管理委员会(PMC)成员,拥有代码库写权限、OpenHarmony 新版本发布、Roadmap发布、新PMC/Committer等社区事务的投票权、以及新的 PMC 成员和 Committer 提名权。PMC负责OpenHarmony 社区的管理工作,包括开源OpenHarmony 社区版本规划、竞争力规划、特性开发代码维护、资料开发、补丁规划等;组织PMC委员的选举和退出,负责Committer的任命和退出;负责OpenHarmony 社区SIG的申请准入、SIG孵化项目指导、SIG毕业项目准入等SIG生命周期管理等。 | + +## 2. 晋升机制和流程 + +### 2.1 晋升机制简介: + +- 2.1.1 如何晋升Committer:优秀的OpenHarmony 社区贡献者,经现任PMC/Committer提名和投票后,可以成为OpenHarmony 社区Committer。 + +- 2.1.2 如何成为SIG Leader :任何开发者可以在社区中寻找2-3个有共同兴趣及目标的开发者,确定SIG Leader候选人,通过PMC项目管理委员会发送新建SIG的PR申请,经PMC项目管理委员会批准后,可以成为此新SIG的SIG Leader。 + +- 2.1.3 如何晋升PMC:优秀的OpenHarmony 社区Committer,经现任PMC成员提议和投票后,可以成为OpenHarmony 社区PMC。 + +### 2.2 晋升Committer投票流程: + +- 2.2.1 由现任PMC/Committer提名,以标题“[VOTE] New Committer xxx ”发送邮件至[dev@openharmony.io](mailto:dev@openharmony.io)。 + +- 2.2.2 所有PMC/Committer成员有权通过“+1”或“-1”形式表示支持或反对,PMC通过回复邮件发送投票结果,投票时间一般持续72个小时。 + +- 2.2.3 提名获得三票及以上赞成票,无反对票情况下投票通过。投反对票的PMC成员必须说明反对的具体问题(无问题描述的反对票无效),投票发起人可针对具体问题进行澄清或修复。 + +- 2.2.4 投票通过后,PMC主席在OpenHarmony社区公告新Committer。 + +### 2.3 晋升PMC投票流程: + +- 2.3.1 由现任PMC提名,以标题“[VOTE] New PMC xxx ”发送邮件至[dev@openharmony.io](mailto:dev@openharmony.io)。 + +- 2.3.2 所有PMC成员有权通过“+1”或“-1”形式表示支持或反对,PMC通过回复邮件发送投票结果。投票时间一般持续72个小时。 + +- 2.3.3 提名获得三票及以上赞成票,无反对票情况下投票通过。投反对票的PMC成员必须说明反对的具体问题(无问题描述的反对票无效),投票发起人可针对具体问题进行澄清或修复。 + +- 2.3.4 投票通过后,PMC主席在OpenHarmony社区公告新PMC。 diff --git "a/website/docs/_posts/\347\244\276\345\214\272/\347\244\276\345\214\272\346\262\237\351\200\232\344\270\216\344\272\244\346\265\201.md" "b/website/docs/_posts/\347\244\276\345\214\272/\347\244\276\345\214\272\346\262\237\351\200\232\344\270\216\344\272\244\346\265\201.md" index 8c74e0081ccef34eebd025692de522cac7273046..8c6a2226fb0090955a87b7ed25de91a67e57a644 100755 --- "a/website/docs/_posts/\347\244\276\345\214\272/\347\244\276\345\214\272\346\262\237\351\200\232\344\270\216\344\272\244\346\265\201.md" +++ "b/website/docs/_posts/\347\244\276\345\214\272/\347\244\276\345\214\272\346\262\237\351\200\232\344\270\216\344\272\244\346\265\201.md" @@ -10,6 +10,10 @@ article: true comment: false editLink: false date: 2021-10-20 17:37:43 +categories: + - 随笔 +tags: + - --- # 社区沟通与交流 diff --git "a/website/docs/_posts/\347\244\276\345\214\272/\350\241\214\344\270\272\345\207\206\345\210\231.md" "b/website/docs/_posts/\347\244\276\345\214\272/\350\241\214\344\270\272\345\207\206\345\210\231.md" deleted file mode 100644 index e572e6d8a1fd33ecf60d1bdee33f2acf8ef92dd0..0000000000000000000000000000000000000000 --- "a/website/docs/_posts/\347\244\276\345\214\272/\350\241\214\344\270\272\345\207\206\345\210\231.md" +++ /dev/null @@ -1,67 +0,0 @@ ---- -title: 行为准则 -permalink: /community/rules -sidebar: true -article: true -comment: false -editLink: false -date: 2021-07-10 12:30:11 ---- - -OpenHarmony社区遵守开源社区[《贡献者公约》](https://contributor-covenant.org/)V1.4中规定的行为守则,请参考[V1.4版本](https://www.contributor-covenant.org/zh-cn/version/1/4/code-of-conduct.html) - -如需举报侮辱、骚扰或其他不可接受的行为,您可以发送邮件至contact.openharmony@openatom.org,联系OpenHarmony技术委员会处理。 - -**贡献者们的承诺** - -为建设开放友好的环境,我们贡献者和维护者承诺:不论年龄、体型、身体健全与否、民族、性征、性别认同与表征、经验水平、教育程度、社会地位、国籍、相貌、种族、信仰、性取向,我们项目和社区的参与者皆免于骚扰。 - -**我们的准则** - -有助于创造积极环境的行为包括但不限于: - -- 措辞友好且包容 - -- 尊重不同的观点和经验 - -- 耐心接受有益批评 - -- 关注对社区最有利的事情 - -- 与社区其他成员友善相处 - - -参与者不应采取的行为包括但不限于: - -- 发布与性有关的言论或图像、不受欢迎地献殷勤 - -- 捣乱/煽动/造谣行为、侮辱/贬损的评论、人身及政治攻击 - -- 公开或私下骚扰 - -- 未经明确授权便发布他人的资料,如住址、电子邮箱等 - -- 其他有理由认定为违反职业操守的不当行为 - - -**我们的义务** - -项目维护者有义务诠释何谓“妥当行为”,并妥善公正地纠正已发生的不当行为。 - -项目维护者有权利和义务去删除、编辑、拒绝违背本行为标准的评论(comments)、提交(commits)、代码、wiki 编辑、问题(issues)等贡献;项目维护者可暂时或永久地封禁任何他们认为行为不当、威胁、冒犯、有害的参与者。 - -**适用范围** - -本行为标准适用于本项目。当有人代表本项目或本社区时,本标准亦适用于此人所处的公共平台。 - -代表本项目或本社区的情形包括但不限于:使用项目的官方电子邮件、通过官方媒体账号发布消息、作为指定代表参与在线或线下活动等。 - -代表本项目的行为可由项目维护者进一步定义及解释。 - -**贯彻落实** - -可以致信contact.openharmony@openatom.org,向项目团队举报滥用、骚扰及不当行为。 - -维护团队将审议并调查全部投诉,妥善地予以必要的回应。项目团队有义务保密举报者信息。具体执行方针或将另行发布。 - -未切实遵守或执行本行为标准的项目维护人员,经项目负责人或其他成员决议,可能被暂时或永久地剥夺参与本项目的资格。 \ No newline at end of file diff --git "a/website/docs/_posts/\347\244\276\345\214\272/\350\241\214\344\270\272\345\256\210\345\210\231.md" "b/website/docs/_posts/\347\244\276\345\214\272/\350\241\214\344\270\272\345\256\210\345\210\231.md" new file mode 100644 index 0000000000000000000000000000000000000000..d2c3b96a5bf730cc4e61eccb99242cf4f8c77d72 --- /dev/null +++ "b/website/docs/_posts/\347\244\276\345\214\272/\350\241\214\344\270\272\345\256\210\345\210\231.md" @@ -0,0 +1,71 @@ +--- +title: 行为守则 +permalink: /community/rules +sidebar: true +article: true +comment: false +editLink: false +date: 2021-07-10 12:30:11 +categories: + - 随笔 +tags: + - +--- + +OpenHarmony社区遵守开源社区[《参与者公约》](https://contributor-covenant.org/)V1.4中规定的行为守则,请参考[V1.4版本](https://www.contributor-covenant.org/zh-cn/version/1/4/code-of-conduct.html) + +如需举报侮辱、骚扰或其他不可接受的行为,您可以发送邮件至contact.openharmony@openatom.org,联系OpenHarmony技术委员会处理。 + +**贡献者们的承诺** + +为建设开放友好的环境,我们贡献者和维护者承诺:不论年龄、体型、身体健全与否、民族、性征、性别认同与表征、经验水平、教育程度、社会地位、国籍、相貌、种族、信仰、性取向,我们项目和社区的参与者皆免于骚扰。 + +**我们的准则** + +有助于创造积极环境的行为包括但不限于: + +- 措辞友好且包容 + +- 尊重不同的观点和经验 + +- 耐心接受有益批评 + +- 关注对社区最有利的事情 + +- 与社区其他成员友善相处 + + +参与者不应采取的行为包括但不限于: + +- 发布与性有关的言论或图像、不受欢迎地献殷勤 + +- 捣乱/煽动/造谣行为、侮辱/贬损的评论、人身及政治攻击 + +- 公开或私下骚扰 + +- 未经明确授权便发布他人的资料,如住址、电子邮箱等 + +- 其他有理由认定为违反职业操守的不当行为 + + +**我们的义务** + +项目维护者有义务诠释何谓“妥当行为”,并妥善公正地纠正已发生的不当行为。 + +项目维护者有权利和义务去删除、编辑、拒绝违背本行为标准的评论(comments)、提交(commits)、代码、wiki 编辑、问题(issues)等贡献;项目维护者可暂时或永久地封禁任何他们认为行为不当、威胁、冒犯、有害的参与者。 + +**适用范围** + +本行为标准适用于本项目。当有人代表本项目或本社区时,本标准亦适用于此人所处的公共平台。 + +代表本项目或本社区的情形包括但不限于:使用项目的官方电子邮件、通过官方媒体账号发布消息、作为指定代表参与在线或线下活动等。 + +代表本项目的行为可由项目维护者进一步定义及解释。 + +**贯彻落实** + +可以致信contact.openharmony@openatom.org,向项目团队举报滥用、骚扰及不当行为。 + +维护团队将审议并调查全部投诉,妥善地予以必要的回应。项目团队有义务保密举报者信息。具体执行方针或将另行发布。 + +未切实遵守或执行本行为标准的项目维护人员,经项目负责人或其他成员决议,可能被暂时或永久地剥夺参与本项目的资格。 \ No newline at end of file diff --git "a/website/docs/_posts/\347\244\276\345\214\272/\350\247\222\350\211\262\350\257\264\346\230\216.md" "b/website/docs/_posts/\347\244\276\345\214\272/\350\247\222\350\211\262\350\257\264\346\230\216.md" deleted file mode 100644 index 558382080979b2daaecdaae36faabc844aaadb42..0000000000000000000000000000000000000000 --- "a/website/docs/_posts/\347\244\276\345\214\272/\350\247\222\350\211\262\350\257\264\346\230\216.md" +++ /dev/null @@ -1,53 +0,0 @@ ---- -title: 角色说明 -permalink: /community/role -navbar: true -sidebar: false -prev: false -next: false -search: false -article: false -comment: false -editLink: false -date: 2021-10-11 17:08:58 ---- -# **OpenHarmony社区角色定义及晋升机制** - -## 1. 角色定义 -| 角色 | 描述| -| :---: | --- | -| 用户 (Users) | 使用OpenHarmony项目的广大用户,以Issue形式向OpenHarmony 社区反馈问题和功能建议。以PR的形式向Gitee贡献代码。| -| 贡献者 (Contributors) | 有一定代码编程经验的开发者。Contributors以参与OpenHarmony 社区代码贡献、文档贡献、技术方案讨论及设计、解答用户问题、发表技术文章及视频课程、组织策划开源OpenHarmony 社区活动等形式参与OpenHarmony 社区。 | -| 提交者 (Committers) | Committer拥有SIG子领域的代码仓写权限。Committer 负责SIG领域软件模块设计与评审,负责代码审核及维护,处理OpenHarmony社区的issue、邮件列表问题,辅导Contributors快速理解SIG领域架构设计并提升代码开发技能。 | -| SIG 负责人(SIG Leader)| SIG Leader负责特定SIG的运营及维护。SIG Leader负责定义特定SIG的工作范围及业务目标,并负责对应SIG的运营及维护;吸纳并发展Committer参与对应SIG的项目孵化、文档完善及社区推广;定期在PMC项目管理委员会汇报SIG孵化项目及SIG运营进展,并基于PMC的指导建议完成相关改进。 | -| PMC 成员 (PMC) | 项目管理委员会(PMC)成员,拥有代码库写权限、OpenHarmony 新版本发布、Roadmap发布、新PMC/Committer等社区事务的投票权、以及新的 PMC 成员和 Committer 提名权。PMC负责OpenHarmony 社区的管理工作,包括开源OpenHarmony 社区版本规划、竞争力规划、特性开发代码维护、资料开发、补丁规划等;组织PMC委员的选举和退出,负责Committer的任命和退出;负责OpenHarmony 社区SIG的申请准入、SIG孵化项目指导、SIG毕业项目准入等SIG生命周期管理等。 | - -## 2. 晋升机制和流程 - -### 2.1 晋升机制简介: - -- 2.1.1 如何晋升Committer:优秀的OpenHarmony 社区贡献者,经现任PMC/Committer提名和投票后,可以成为OpenHarmony 社区Committer。 - -- 2.1.2 如何成为SIG Leader :任何开发者可以在社区中寻找2-3个有共同兴趣及目标的开发者,确定SIG Leader候选人,通过PMC项目管理委员会发送新建SIG的PR申请,经PMC项目管理委员会批准后,可以成为此新SIG的SIG Leader。 - -- 2.1.3 如何晋升PMC:优秀的OpenHarmony 社区Committer,经现任PMC成员提议和投票后,可以成为OpenHarmony 社区PMC。 - -### 2.2 晋升Committer投票流程: - -- 2.2.1 由现任PMC/Committer提名,以标题“[VOTE] New Committer xxx ”发送邮件至[dev@openharmony.io](mailto:dev@openharmony.io)。 - -- 2.2.2 所有PMC/Committer成员有权通过“+1”或“-1”形式表示支持或反对,PMC通过回复邮件发送投票结果,投票时间一般持续72个小时。 - -- 2.2.3 提名获得三票及以上赞成票,无反对票情况下投票通过。投反对票的PMC成员必须说明反对的具体问题(无问题描述的反对票无效),投票发起人可针对具体问题进行澄清或修复。 - -- 2.2.4 投票通过后,PMC主席在OpenHarmony社区公告新Committer。 - -### 2.3 晋升PMC投票流程: - -- 2.3.1 由现任PMC提名,以标题“[VOTE] New PMC xxx ”发送邮件至[dev@openharmony.io](mailto:dev@openharmony.io)。 - -- 2.3.2 所有PMC成员有权通过“+1”或“-1”形式表示支持或反对,PMC通过回复邮件发送投票结果。投票时间一般持续72个小时。 - -- 2.3.3 提名获得三票及以上赞成票,无反对票情况下投票通过。投反对票的PMC成员必须说明反对的具体问题(无问题描述的反对票无效),投票发起人可针对具体问题进行澄清或修复。 - -- 2.3.4 投票通过后,PMC主席在OpenHarmony社区公告新PMC。 diff --git "a/website/docs/_posts/\347\244\276\345\214\272/\350\256\242\351\230\205\351\202\256\344\273\266\345\210\227\350\241\250.md" "b/website/docs/_posts/\347\244\276\345\214\272/\350\256\242\351\230\205\351\202\256\344\273\266\345\210\227\350\241\250.md" new file mode 100644 index 0000000000000000000000000000000000000000..2b32b1ea808ca3356e4bc93c947ef062c9293021 --- /dev/null +++ "b/website/docs/_posts/\347\244\276\345\214\272/\350\256\242\351\230\205\351\202\256\344\273\266\345\210\227\350\241\250.md" @@ -0,0 +1,49 @@ +--- +title: 订阅邮件列表 +permalink: /community/maillist +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +date: 2021-10-11 17:08:58 +--- +# 介绍 +Community仓库用于管理OpenHarmony社区治理、开发者贡献指南、签署开发者原创声明、社区交流等内容。 + +# 社区治理组织架构 + +OpenHarmony社区通过项目管理委员会( Project Management Committee)管理OpenHarmony社区。 + +# 开发者社区贡献指南 + +请阅读如何贡献获得帮助。 + +# 签署开发者原创声明 + +您必须首先签署“签署开发者原创声明”,然后才能参与社区贡献。 +点击这里签署、查看签署状态。 + +# 社区交流 + +OpenHarmony maillist 交流方式 + +|邮箱|简述|用途说明| +| ------------ | ------------ | ------------ | +|contact@openharmony.io| 公用邮箱| OpenHarmony社区公共邮箱。| +|dev@openharmony.io| 开发邮件列表| OpenHarmony社区开发讨论邮件列表,任何社区开发相关话题都可以在邮件列表讨论。任何开发者可订阅。| +|cicd@openharmony.io| CI邮件列表| OpenHarmomny CICD构建邮件列表,任何开发者可订阅。| +|pmc@openharmony.io| PMC邮件列表| PMC讨论邮件列表,PMC成员可订阅。| +|scy@openharmony.io| 安全问题邮箱| 开发者可反馈OpenHarmony安全问题到此邮箱。| +|scy-priv@openharmony.io| 安全组邮件列表| 安全组成员安全问题处理讨论邮件列表,安全组成员可订阅。| +|oh-legal@openatom.io| 法务工作小组邮件列表| 开发者可反馈OpenHarmony法律问题到此邮箱,法务工作小组成员可订阅。| + +# 项目LOGO + +### OpenHarmony logo的标准式样 +![OpenHarmony logo的标准式样](/images/logo/OH标准LOGO.svg) +### OpenHarmony 商标的标准式样 +![OpenHarmony 商标的标准式样](/images/logo/OH标准商标.svg) \ No newline at end of file diff --git "a/website/docs/_posts/\347\244\276\345\214\272/\350\264\241\347\214\256\346\214\207\345\215\227.md" "b/website/docs/_posts/\347\244\276\345\214\272/\350\264\241\347\214\256\346\214\207\345\215\227.md" deleted file mode 100644 index cc7e8effba02b44edab9af61217d7b70ef81ce04..0000000000000000000000000000000000000000 --- "a/website/docs/_posts/\347\244\276\345\214\272/\350\264\241\347\214\256\346\214\207\345\215\227.md" +++ /dev/null @@ -1,44 +0,0 @@ ---- -title: 贡献指南 -permalink: /community/contribution -navbar: true -sidebar: false -prev: false -next: false -search: false -article: false -comment: false -editLink: false -date: 2021-10-11 17:08:58 ---- -# 参与贡献 - -## 贡献代码 - -### 开始之前 - -#### 签署开发者原创声明 - -您必须首先签署“开发者原创声明”,然后才能参与社区贡献。 - -点击这里签署、查看签署状态。 - -#### 行为准则 - -OpenHarmony是一个开源社区。它完全依赖于社区提供友好的开发和协作环境,所以在参与社区贡献之前,请先阅读并遵守OpenHarmony社区的行为守则。 - -### 找到感兴趣的SIG - -如何参与SIG(Special Interest Group)特别兴趣小组,请访问SIG组列表并订阅邮件列表。 - -### 开始贡献 - -如何贡献代码,请参考贡献代码。 - -## 贡献文档 - -如何贡献文档,请参考贡献文档。 - -## 社区沟通与交流 - -有关详细信息,请参考社区沟通与交流。 diff --git "a/website/docs/_posts/\347\244\276\345\214\272/\350\264\241\347\214\256\346\224\273\347\225\245.md" "b/website/docs/_posts/\347\244\276\345\214\272/\350\264\241\347\214\256\346\224\273\347\225\245.md" new file mode 100644 index 0000000000000000000000000000000000000000..f93cf5b520e119f661acd6bd8b75d014da79f93b --- /dev/null +++ "b/website/docs/_posts/\347\244\276\345\214\272/\350\264\241\347\214\256\346\224\273\347\225\245.md" @@ -0,0 +1,44 @@ +--- +title: 贡献攻略 +permalink: /community/contribution +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +date: 2021-10-11 17:08:58 +--- +# 参与贡献 + +## 贡献代码 + +### 开始之前 + +#### 签署开发者原创声明 + +您必须首先签署“开发者原创声明”,然后才能参与社区贡献。 + +点击这里签署、查看签署状态。 + +#### 行为准则 + +OpenHarmony是一个开源社区。它完全依赖于社区提供友好的开发和协作环境,所以在参与社区贡献之前,请先阅读并遵守OpenHarmony社区的行为守则。 + +### 找到感兴趣的SIG + +如何参与SIG(Special Interest Group)特别兴趣小组,请访问SIG组列表并订阅邮件列表。 + +### 开始贡献 + +如何贡献代码,请参考贡献代码。 + +## 贡献文档 + +如何贡献文档,请参考贡献文档。 + +## 社区沟通与交流 + +有关详细信息,请参考社区沟通与交流。 diff --git "a/website/docs/_posts/\347\244\276\345\214\272/\351\202\256\344\273\266\345\210\227\350\241\250.md" "b/website/docs/_posts/\347\244\276\345\214\272/\351\202\256\344\273\266\345\210\227\350\241\250.md" deleted file mode 100644 index 05dca20f72e3a54d6442e32241e18c1556faf1cd..0000000000000000000000000000000000000000 --- "a/website/docs/_posts/\347\244\276\345\214\272/\351\202\256\344\273\266\345\210\227\350\241\250.md" +++ /dev/null @@ -1,48 +0,0 @@ ---- -title: 邮件列表 -permalink: /community/maillist -navbar: true -sidebar: false -prev: false -next: false -search: false -article: false -comment: false -editLink: false -date: 2021-10-11 17:08:58 ---- -# 介绍 -Community仓库用于管理OpenHarmony社区治理、开发者贡献指南、签署开发者原创声明、社区交流等内容。 - -# 社区治理组织架构 - -OpenHarmony社区通过项目管理委员会( Project Management Committee)管理OpenHarmony社区。 - -# 开发者社区贡献指南 - -请阅读如何贡献获得帮助。 - -# 签署开发者原创声明 - -您必须首先签署“签署开发者原创声明”,然后才能参与社区贡献。 -点击这里签署、查看签署状态。 - -# 社区交流 - -OpenHarmony maillist 交流方式 - -|邮箱|简述|用途说明| -| ------------ | ------------ | ------------ | -|contact@openharmony.io| 公用邮箱| OpenHarmony社区公共邮箱。| -|dev@openharmony.io| 开发邮件列表| OpenHarmony社区开发讨论邮件列表,任何社区开发相关话题都可以在邮件列表讨论。任何开发者可订阅。| -|cicd@openharmony.io| CI邮件列表| OpenHarmomny CICD构建邮件列表,任何开发者可订阅。| -|pmc@openharmony.io| PMC邮件列表| PMC讨论邮件列表,PMC成员可订阅。| -|scy@openharmony.io| 安全问题邮箱| 开发者可反馈OpenHarmony安全问题到此邮箱。| -|scy-priv@openharmony.io| 安全组邮件列表| 安全组成员安全问题处理讨论邮件列表,安全组成员可订阅。| - -# 项目LOGO - -### OpenHarmony logo的标准式样 -![OpenHarmony logo的标准式样](/images/logo/OH标准LOGO.svg) -### OpenHarmony 商标的标准式样 -![OpenHarmony 商标的标准式样](/images/logo/OH标准商标.svg) \ No newline at end of file diff --git "a/website/docs/_posts/\350\256\276\345\244\207\345\274\200\345\217\221\345\267\245\345\205\267\347\256\200\344\273\213.md" "b/website/docs/_posts/\350\256\276\345\244\207\345\274\200\345\217\221\345\267\245\345\205\267\347\256\200\344\273\213.md" index 4188e56b4dc2880ec4653f963d418085eb978bd7..2891753c913fa51801f52f1950f6257f0a47abcc 100644 --- "a/website/docs/_posts/\350\256\276\345\244\207\345\274\200\345\217\221\345\267\245\345\205\267\347\256\200\344\273\213.md" +++ "b/website/docs/_posts/\350\256\276\345\244\207\345\274\200\345\217\221\345\267\245\345\205\267\347\256\200\344\273\213.md" @@ -1,8 +1,12 @@ --- title: 设备开发工具简介 date: 2021-07-13 18:46:33 -permalink: /pages/a19342/ +permalink: /pages/a19342/ sidebar: auto +categories: + - 随笔 +tags: + - --- # 设备开发工具简介 diff --git a/website/docs/extras/README.md b/website/docs/extras/README.md new file mode 100644 index 0000000000000000000000000000000000000000..548a276968fbca31d3b79076e1e937e8032f00fd --- /dev/null +++ b/website/docs/extras/README.md @@ -0,0 +1,48 @@ +--- +title: "README" +prepermalink: /extras/04c6e90faac2675aa89e2176d2eec7d8/ +permalink: /extras/04c6e90faac2675aa89e2176d2eec7d8/ +relpath: "OpenHarmony-3.1-Release/README.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [README] +--- +# OpenHarmony Documentation + +Welcome to the OpenHarmony documentation repository. + +This repository stores device and application development documents provided by OpenHarmony. Your contribution to the OpenHarmony documentation will be highly appreciated. + +## Contents + +[Chinese Documentation](/extras/5dd8a580cc4641e8b30f1ce9a559460b/) + +[English Documentation](/extras/1aaaaefbdefb26bd296cec91a5594d66/) + +## OpenHarmony Document Version Branches + +### Latest Versions + + - master: the latest version. + + - OpenHarmony 3.1 Beta. [Learn more](/pages/en/overview/OpenHarmony%20Release%20Notes/OpenHarmony%203.x%20Releases/OpenHarmony%20v3.1%20Beta%20%282021-12-31%29) + + - OpenHarmony 3.0 LTS. [Learn more](/pages/en/overview/OpenHarmony%20Release%20Notes/OpenHarmony%203.x%20Releases/OpenHarmony%20v3.0%20LTS%20%282021-09-30%29) + + This version is upgraded to OpenHarmony 3.0.2 LTS. [Learn more](/extras/229818abf55130c590e32f4e82d91b32/) + + - OpenHarmony 2.2 Beta2. [Learn more](/pages/en/overview/OpenHarmony%20Release%20Notes/OpenHarmony%202.x%20Releases/OpenHarmony%20v2.2%20beta2%20%282021-08-04%29) + + - OpenHarmony 2.0 Canary. [Learn more](/pages/en/overview/OpenHarmony%20Release%20Notes/OpenHarmony%202.x%20Releases/OpenHarmony%202.0%20Canary%20%282021-06-01%29) + +### Historical Stable Versions + +OpenHarmony_v1.x_release: OpenHarmony v1.1.4 LTS. [Learn more](/pages/en/overview/OpenHarmony%20Release%20Notes/%20OpenHarmony%201.x%20Releases/OpenHarmony%20v1.1.4%20LTS%20%282022-02-11%29) + +[More versions](en/release-notes/) diff --git a/website/docs/extras/README_zh.md b/website/docs/extras/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..d6abbb2747305e09d8d61a8c8d78da04d68850e9 --- /dev/null +++ b/website/docs/extras/README_zh.md @@ -0,0 +1,61 @@ +--- +title: "README_zh" +prepermalink: /extras/1207b4b58cba7aff651fc4abf5d71e64/ +permalink: /extras/1207b4b58cba7aff651fc4abf5d71e64/ +relpath: "OpenHarmony-3.1-Release/README_zh.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [README_zh] +--- +# OpenHarmony文档 + +欢迎访问OpenHarmony文档仓库,参与OpenHarmony开发者文档开源项目,与我们一起完善开发者文档。 + +此仓库存放OpenHarmony网站提供的设备开发、应用开发对应的开发者文档。 + +## 文档目录结构 + +[访问官网](https://www.openharmony.cn/) + +[中文文档](/extras/5dd8a580cc4641e8b30f1ce9a559460b/) + +[English Documentation](/extras/1aaaaefbdefb26bd296cec91a5594d66/) + +## OpenHarmony文档版本分支说明 + +### 最新版本 + +master:最新开发版本。 + +发布OpenHarmony 3.1 Release版本,[了解版本详情](/pages/zh-cn/%E4%BA%86%E8%A7%A3OpenHarmony/%E7%89%88%E6%9C%AC%E8%AF%B4%E6%98%8E/OpenHarmony%203.x%20Releases/OpenHarmony%20v3.1%20Release%20%282022-03-30%29)。 + +发布OpenHarmony 3.0 LTS版本,[了解版本详情](/pages/zh-cn/%E4%BA%86%E8%A7%A3OpenHarmony/%E7%89%88%E6%9C%AC%E8%AF%B4%E6%98%8E/OpenHarmony%203.x%20Releases/OpenHarmony%20v3.0%20LTS%20%282021-09-30%29)。该版本已更新至OpenHarmony 3.0.2 LTS,[了解版本详情](/extras/bed3f292d4b661348db73627a92c876a/)。 + +发布 OpenHarmony v2.2 Beta2版本,[了解版本详情](/pages/zh-cn/%E4%BA%86%E8%A7%A3OpenHarmony/%E7%89%88%E6%9C%AC%E8%AF%B4%E6%98%8E/OpenHarmony%202.x%20Releases/OpenHarmony%20v2.2%20beta2%20%282021-08-04%29)。 + +发布OpenHarmony 2.0 Canary预览版本,[了解版本详情](/pages/zh-cn/%E4%BA%86%E8%A7%A3OpenHarmony/%E7%89%88%E6%9C%AC%E8%AF%B4%E6%98%8E/OpenHarmony%202.x%20Releases/OpenHarmony%202.0%20Canary%20%282021-06-01%29)。 + +### 历史稳定版本 + +OpenHarmony_v1.x_release:OpenHarmony 1.1.4 LTS稳定版本,[了解版本详情](/pages/zh-cn/%E4%BA%86%E8%A7%A3OpenHarmony/%E7%89%88%E6%9C%AC%E8%AF%B4%E6%98%8E/OpenHarmony%201.x%20Releases%20/OpenHarmony%20v1.1.4%20LTS%20%282022-02-11%29)。 + +[了解更多版本详情](zh-cn/release-notes/)。 + + +## 第三方开源软件及许可说明 + +3rd-Party-License:[第三方开源软件及许可证说明](/extras/9e2cfbe7c8813ed27e02907d561dbda8/) + +## 贡献 + +非常欢迎您参与[贡献](/pages/zh-cn/%E4%BA%86%E8%A7%A3OpenHarmony/%E8%B4%A1%E7%8C%AE/%E5%8F%82%E4%B8%8E%E8%B4%A1%E7%8C%AE),我们鼓励开发者以各种方式参与文档反馈和贡献。 + +您可以对现有文档进行评价、简单更改、反馈文档质量问题、贡献您的原创内容,详细请参考[贡献文档](/pages/zh-cn/%E4%BA%86%E8%A7%A3OpenHarmony/%E8%B4%A1%E7%8C%AE/%E8%B4%A1%E7%8C%AE%E6%96%87%E6%A1%A3)。 + +卓越贡献者将会在开发者社区文档贡献专栏表彰公示。 \ No newline at end of file diff --git a/website/docs/extras/docker/CHANGELOG.md b/website/docs/extras/docker/CHANGELOG.md new file mode 100644 index 0000000000000000000000000000000000000000..b9422c3e0ced9cc0ada9c8a0da935fdd47eebc34 --- /dev/null +++ b/website/docs/extras/docker/CHANGELOG.md @@ -0,0 +1,66 @@ +--- +title: "CHANGELOG" +prepermalink: /extras/4bb56fed77c13409a83f2b67050a4386/ +permalink: /extras/4bb56fed77c13409a83f2b67050a4386/ +relpath: "OpenHarmony-3.1-Release/docker/CHANGELOG.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [CHANGELOG] +--- +### 1.0.0 (2022/03/09) + +合并轻设备和富设备系统docker编译环境。 + + + +### 0.0.7 (2022/02/16) + +增加安装doxygen工具。 + + + +### 0.0.6 (2022/02/10) + +1、更新hb。 + +2、增加安装ruby。 + + + +### 0.0.5 (2021/06/21) + +1、更新llvm版本从10.0.1-53907更新到10.0.1-62608,支撑ipcamera_hispark_taurus_linux编译。 + +2、增加安装bison、flex、bc、u-boot-tools和gcc-arm-linux-gnueabi。 + + + +### 0.0.4 (2021/05/18) + +1、更新llvm版本从9.0.0-34042更新到10.0.1-53907。 + +2、增加安装vim、ssh和git工具。 + + + +### 0.0.3(2021/04/26) + +增加安装hb工具。 + + + +### 0.0.2(2020/12/23) + +增加安装工具tzdata、default-jre、default-jdk、nodejs、hmos_app_packing_tool、hapsigntoolv2和hpm-cli工具。 + + + + ### 0.0.1(2020/10/28) + +提供OpenHarmony 1.0版本docker编译环境,预装编译依赖工具。 \ No newline at end of file diff --git a/website/docs/extras/docker/CHANGELOG_en.md b/website/docs/extras/docker/CHANGELOG_en.md new file mode 100644 index 0000000000000000000000000000000000000000..bae1d81587c4fb45fab07a6b1979a837f2b1ae9a --- /dev/null +++ b/website/docs/extras/docker/CHANGELOG_en.md @@ -0,0 +1,66 @@ +--- +title: "CHANGELOG_en" +prepermalink: /extras/b68349408814a9f56559d2c2ad28a75e/ +permalink: /extras/b68349408814a9f56559d2c2ad28a75e/ +relpath: "OpenHarmony-3.1-Release/docker/CHANGELOG_en.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [CHANGELOG_en] +--- +### 1.0.0 (2022/03/09) + +Combine the docker build environment of Mini-System Devices (reference memory ≥ 128 KB), Small-System Devices (reference memory ≥ 1 MB) and Standard-System Devices (reference memory ≥ 128 MB). + + + +### 0.0.7 (2022/02/16) + +Added the installation of doxygen. + + + +### 0.0.6 (2022/02/10) + +1\. Updated hb. + +2\. Added the installation of ruby. + + + +### 0.0.5 (2021/06/21) + +1\. Updated LLVM from 10.0.1-53907 to 10.0.1-62608. Introduced support for ipcamera\_hispark\_taurus\_linux. + +2\. Added the installation of Bison, Flex, bc, u-boot-tools, and gcc-arm-linux-gnueabi. + + + +### 0.0.4 (2021/05/18) + +1\. Updated LLVM from 9.0.0-34042 to 10.0.1-53907. + +2\. Added the installation of the Vim, SSH, and Git tools. + + + +### 0.0.3 (2021/04/26) + +Added the installation of the hb tool. + + + +### 0.0.2 (2020/12/23) + +Added the installation of the tzdata, default-jre, default-jdk, Node.js, hmos\_app\_packing\_tool, hapsigntoolv2, and hpm-cli tools. + + + +### 0.0.1 (2020/10/28) + +Provided a Docker build environment for OpenHarmony 1.0 and pre-installed build dependency tools. \ No newline at end of file diff --git a/website/docs/extras/docker/README.md b/website/docs/extras/docker/README.md new file mode 100644 index 0000000000000000000000000000000000000000..fb10d91d8b3df84af912dc0f3f77ddb79df2c608 --- /dev/null +++ b/website/docs/extras/docker/README.md @@ -0,0 +1,45 @@ +--- +title: "README" +prepermalink: /extras/a489144702a723431811d56a3c44690a/ +permalink: /extras/a489144702a723431811d56a3c44690a/ +relpath: "OpenHarmony-3.1-Release/docker/README.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [README] +--- +# OpenHarmony Docker镜像 + +### Docker镜像简介 + +本文为OpenHarmony的Docker编译环境使用指导。 + +OpenHarmony的Docker镜像托管在**HuaweiCloud SWR**上,开发者可以通过该镜像在很大程度上简化编译前的环境配置。 目前容器化构建选项支持情况如下: + +| Docker镜像仓库 | 标签 | 说明 | +| :----------------------------------------------------------- | :------ | :------------------------------------ | +| `swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker` | `1.0.0` | 已经预安装OpenHarmony版本的编译环境。 | + +### 使用方式及步骤 + + 开发者在下载好源码后,可以通过以下步骤来使用我们提供的Docker环境。详情请参见[Docker编译环境](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/get-code/gettools-acquire.md)。 + +1. 获取Docker镜像 + ``` + docker pull swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker:1.0.0 + ``` +2. 进入OpenHarmony代码根目录执行如下命令,从而进入Docker构建环境 + ``` + docker run -it -v $(pwd):/home/openharmony swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker:1.0.0 + ``` +3. 通过如下命令启动不同平台的编译 + ``` + hb set #在显示的页面中通过键盘上下键选择需要编译的平台,通过回车确定选择。 + hb build -f #执行编译。 + ``` + diff --git a/website/docs/extras/docker/README_en.md b/website/docs/extras/docker/README_en.md new file mode 100644 index 0000000000000000000000000000000000000000..b1eb42fcfdc23e0bb69a31a49c41d6818fbb226c --- /dev/null +++ b/website/docs/extras/docker/README_en.md @@ -0,0 +1,44 @@ +--- +title: "README_en" +prepermalink: /extras/6b6aff5bee5760e495896a37c100ea1f/ +permalink: /extras/6b6aff5bee5760e495896a37c100ea1f/ +relpath: "OpenHarmony-3.1-Release/docker/README_en.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [README_en] +--- +# OpenHarmony Docker Image + +### Docker Image + +This document provides guidance on building the Docker image for mini- and small-system devices. + +The Docker image of OpenHarmony is hosted on [HUAWEI Cloud SWR](https://auth.huaweicloud.com/authui/login.html?service=https%3A%2F%2Fconsole.huaweicloud.com%2Fswr%2F%3Fregion%3Dcn-south-1%26cloud_route_state%3D%2Fapp%2Fwarehouse%2FwarehouseMangeDetail%2Fgoldensir%2Fopenharmony-docker%2Fopenharmony-docker%3Ftype%3DownImage&locale=en-us#/login). Using the Docker image will help simplify environment configurations needed for the building. The following table lists container-based options needed for building in the standalone Docker environment. + +| Docker Image Repository | Tag | Description | +| :----------------------------------------------------------- | :------ | :-------------------------------------------------------- | +| `swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker` | `1.0.0` | The OpenHarmony build environment has been pre-installed. | + +### Usage + + After downloading the OpenHarmony code, perform the steps below to access the Docker environment. + +1. Obtain the Docker image. + ``` + docker pull swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker:1.0.0 + ``` +2. Go to the root directory of OpenHarmony code and run the following command to access the Docker build environment: + ``` + docker run -it -v $(pwd):/home/openharmony swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker:1.0.0 + ``` +3. Run the following script to start building for different platforms. + ``` + hb set # Press the Up or Down key to select the platform to build on, then press Enter. + hb build -f # Start building. + ``` diff --git a/website/docs/extras/en/application-dev/Readme-EN.md b/website/docs/extras/en/application-dev/Readme-EN.md new file mode 100644 index 0000000000000000000000000000000000000000..50b695df044f59d484ffe30a8f42b512072c1616 --- /dev/null +++ b/website/docs/extras/en/application-dev/Readme-EN.md @@ -0,0 +1,50 @@ +--- +title: "Readme-EN" +prepermalink: /extras/080d621f5869be3d033ce95ad9bff820/ +permalink: /extras/080d621f5869be3d033ce95ad9bff820/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/Readme-EN.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [Readme-EN] +--- +# Application Development + +- [Application Development Overview](/pages/en/app/application/Application%20Development%20Overview) +- About OpenHarmony + - [OpenHarmony Project](/pages/en/overview/OpenHarmony%20Project) + - [Glossary](/pages/en/overview/Glossary) + - [OpenHarmony Release Notes](/extras/348bb39c5ace3e332174966f24395f95/) +- Getting Started + - [Getting Started with Application Development](/extras/9e490855207b24d31c829b990a496bab/) + - [Directory Structure](/pages/en/app/application/Quick%20Start/Directory%20Structure) +- Development + - [Ability Development](/extras/7cb04fd4d65bfcb5ebcf8e4bc1bec1dd/) + - [UI Development](https://www.openharmony.cn/404/ui/Readme-EN.md) + - Basic Feature Development + - [Window Manager](/extras/73e7d965c5d7739d265b13c187614337/) + - [WebGL](/extras/b897bddbf732ca9fb45499241b5674f0/) + - [Media](/extras/6c7e1611868af12071e07b3b820f6298/) + - [Security](/extras/f49961f963597b8b33da99dbbc96c4fe/) + - [Connectivity](/extras/85a1b375c4c8c3286b1779df1f3dc372/) + - [Data Management](/extras/47af09e797485ee7ceafaaca30832cb9/) + - [Agent-Powered Scheduled Reminders](/extras/5a2f3d1cdb48ca5c2d915aac05b9eaab/) + - [Background Task Management](/extras/66fccd11797c885a22b5e57596ea39d6/) + - [Device Management](/extras/8a93033dae14d5695c8c5b3445590ba1/) + - [Device Usage Statistics](/extras/4642c8e1164455f6e87ffa333f4f8899/) + - [DFX](/extras/49e0a2bd226574ea119b2e39cf905f95/) +- Tools + - [DevEco Studio (OpenHarmony) User Guide](/pages/en/app/application/Tools/DevEco%20Studio%20%28OpenHarmony%29%20User%20Guide) +- Hands-On Tutorials + - [Samples](https://gitee.com/openharmony/app_samples/blob/master/README.md) +- API References + - [Component Reference (JavaScript-based Web-like Development Paradigm)](/extras/820ae68c631508f7f90c13d0d52dc8a3/) + - [Component Reference (TypeScript-based Declarative Development Paradigm)](/extras/ec6a4691541e5a4e94fb6b9474387fce/) + - [APIs](/extras/4e29a99e4f2669ec0b511c39725300f7/) +- Contribution + - [How to Contribute](/pages/en/overview/Contribution/Documentation%20Contribution) diff --git a/website/docs/extras/en/application-dev/application-dev-website.md b/website/docs/extras/en/application-dev/application-dev-website.md new file mode 100644 index 0000000000000000000000000000000000000000..498f87f4eae79959687845432506c50af8719394 --- /dev/null +++ b/website/docs/extras/en/application-dev/application-dev-website.md @@ -0,0 +1,679 @@ +--- +title: "application-dev-website" +prepermalink: /extras/23cf6ee787d2b8afa0c0fe61d03e1d81/ +permalink: /extras/23cf6ee787d2b8afa0c0fe61d03e1d81/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/application-dev-website.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [application-dev-website] +--- +# Application Development + +- [Application Development Overview](/pages/en/app/application/Application%20Development%20Overview) +- Quick Start + - [Directory Structure](/pages/en/app/application/Quick%20Start/Directory%20Structure) + - [Resource File Categories](/pages/en/app/application/Quick%20Start/Resource%20File%20Categories) +- Development + - Ability Development + - FA Model + - [FA Model Overview](/pages/en/app/application/Development/Ability%20Development/FA%20Model/FA%20Model%20Overview) + - [Page Ability Development](/pages/en/app/application/Development/Ability%20Development/FA%20Model/Page%20Ability%20Development) + - [Service Ability Development](/pages/en/app/application/Development/Ability%20Development/FA%20Model/Service%20Ability%20Development) + - [Data Ability Development](/pages/en/app/application/Development/Ability%20Development/FA%20Model/Data%20Ability%20Development) + - [FA Widget Development](/pages/en/app/application/Development/Ability%20Development/FA%20Model/FA%20Widget%20Development) + + - Other + - [Ability Assistant Usage](/pages/en/app/application/Development/Ability%20Development/Other/Ability%20Assistant%20Usage) + - UI + - JavaScript-based Web-Like Development Paradigm + - [Overview](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Overview) + - Framework + - [File Organization](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Framework/File%20Organization) + - ["js" Tag](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Framework/%20js%20%20Tag) + - [app.js](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Framework/app.js) + - Syntax + - [HML](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Framework/Syntax/HML) + - [CSS](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Framework/Syntax/CSS) + - [JavaScript](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Framework/Syntax/JavaScript) + - [Lifecycle](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Framework/Lifecycle) + - [Resource Limitations and Access](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Framework/Resource%20Limitations%20and%20Access) + - [Multi-Language Capability](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Framework/Multi-Language%20Capability) + - Building the UI + - [Component Overview](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Building%20the%20UI/Component%20Overview) + - Building the Layout + - [Layout Description](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Building%20the%20UI/Building%20the%20Layout/Layout%20Description) + - [Adding Title and Paragraph Text](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Building%20the%20UI/Building%20the%20Layout/Adding%20Title%20and%20Paragraph%20Text) + - [Adding an Image](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Building%20the%20UI/Building%20the%20Layout/Adding%20an%20Image) + - [Adding a Comment](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Building%20the%20UI/Building%20the%20Layout/Adding%20a%20Comment) + - [Adding a Container](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Building%20the%20UI/Building%20the%20Layout/Adding%20a%20Container) + - [Adding Interactions](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Building%20the%20UI/Adding%20Interactions) + - [Developing Animations](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Building%20the%20UI/Developing%20Animations) + - [Defining Events](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Building%20the%20UI/Defining%20Events) + - [Defining Page Routes](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Building%20the%20UI/Defining%20Page%20Routes) + - Common Component Development Guidelines + - Container Components + - [List](/extras/0dfc6b0664f6e334a81bfd9ccf6f51c6/) + - [Dialog](/extras/f78fdc6f879924b1b1b9566e48913731/) + - [Form](/extras/2e5bc8e1ddc170355c59c569c9e7e99e/) + - [Stepper](/extras/9b90423f489453dd8e1312bc6904c1af/) + - [Tabs](/extras/6280763f9b6ef60950030fbcc8673fa9/) + - Basic Components + - [Text](/extras/99e5841e65138d840158f6db79f9a82d/) + - [Input](/extras/d9c1ad400ac43ce056c56ae004780b64/) + - [Button](/extras/c26625fb2ce7815fd08c2aab247111f4/) + - [Picker](/extras/951bb17387966bf77e6bebed8adf4274/) + - [Image](/extras/874a020d7013a89a35806e100dc7e5f3/) + - Animation Development Guidelines + - CSS Animation + - [Defining Attribute Style Animations](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Common%20Component%20Development%20Guidelines/Animation%20Development%20Guidelines/CSS%20Animation/Defining%20Attribute%20Style%20Animations) + - [Defining Animations with the transform Attribute](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Common%20Component%20Development%20Guidelines/Animation%20Development%20Guidelines/CSS%20Animation/Defining%20Animations%20with%20the%20transform%20Attribute) + - [Defining Animations with the background-position Attribute](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Common%20Component%20Development%20Guidelines/Animation%20Development%20Guidelines/CSS%20Animation/Defining%20Animations%20with%20the%20background-position%20Attribute) + - [Defining Animations for SVG Components](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Common%20Component%20Development%20Guidelines/Animation%20Development%20Guidelines/CSS%20Animation/Defining%20Animations%20for%20SVG%20Components) + - JS Animation + - [Component Animation](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Common%20Component%20Development%20Guidelines/Animation%20Development%20Guidelines/JS%20Animation/Component%20Animation) + - Interpolator Animation + - [Animation Effect](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Common%20Component%20Development%20Guidelines/Animation%20Development%20Guidelines/JS%20Animation/Interpolator%20Animation/Animation%20Effect) + - [Animation Frame](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Common%20Component%20Development%20Guidelines/Animation%20Development%20Guidelines/JS%20Animation/Interpolator%20Animation/Animation%20Frame) + - [Custom Components](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Custom%20Components) + - TypeScript-based Declarative Development Paradigm + - [Overview](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Overview) + - Framework Overview + - File Organization + - [Directory Structure](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Framework%20Overview/File%20Organization/Directory%20Structure) + - [Rules for Accessing Application Code Files](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Framework%20Overview/File%20Organization/Rules%20for%20Accessing%20Application%20Code%20Files) + - ["js" Tag](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Framework%20Overview/%20js%20%20Tag) + - Resource Access + - [Accessing Application Resources](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Framework%20Overview/Resource%20Access/Accessing%20Application%20Resources) + - [Accessing System Resources](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Framework%20Overview/Resource%20Access/Accessing%20System%20Resources) + - [Media Resource Types](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Framework%20Overview/Resource%20Access/Media%20Resource%20Types) + - [Pixel Units](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Framework%20Overview/Pixel%20Units) + - [Types](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Framework%20Overview/Types) + - Declarative Syntax + - [Overview](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/Overview) + - General UI Description Specifications + - [Basic Concepts](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/General%20UI%20Description%20Specifications/Basic%20Concepts) + - Declarative UI Description Specifications + - [Parameterless Configuration](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/General%20UI%20Description%20Specifications/Declarative%20UI%20Description%20Specifications/Parameterless%20Configuration) + - [Configuration with Mandatory Parameters](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/General%20UI%20Description%20Specifications/Declarative%20UI%20Description%20Specifications/Configuration%20with%20Mandatory%20Parameters) + - [Attribution Configuration](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/General%20UI%20Description%20Specifications/Declarative%20UI%20Description%20Specifications/Attribution%20Configuration) + - [Event Configuration](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/General%20UI%20Description%20Specifications/Declarative%20UI%20Description%20Specifications/Event%20Configuration) + - [Child Component Configuration](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/General%20UI%20Description%20Specifications/Declarative%20UI%20Description%20Specifications/Child%20Component%20Configuration) + - Componentization + - [@Component](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/General%20UI%20Description%20Specifications/Componentization/Component) + - [@Entry](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/General%20UI%20Description%20Specifications/Componentization/Entry) + - [@Preview](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/General%20UI%20Description%20Specifications/Componentization/Preview) + - [@Builder](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/General%20UI%20Description%20Specifications/Componentization/Builder) + - [@Extend](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/General%20UI%20Description%20Specifications/Componentization/Extend) + - [@CustomDialog](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/General%20UI%20Description%20Specifications/Componentization/CustomDialog) + - About UI State Management + - [Basic Concepts](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20UI%20State%20Management/Basic%20Concepts) + - Managing Component States + - [@State](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20UI%20State%20Management/Managing%20Component%20States/State) + - [@Prop](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20UI%20State%20Management/Managing%20Component%20States/Prop) + - [@Link](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20UI%20State%20Management/Managing%20Component%20States/Link) + - Managing Application States + - [AppStorage](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20UI%20State%20Management/Managing%20Application%20States/AppStorage) + - [PersistentStorage](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20UI%20State%20Management/Managing%20Application%20States/PersistentStorage) + - [Environment](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20UI%20State%20Management/Managing%20Application%20States/Environment) + - Managing Other States + - [@observed and @objectLink](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20UI%20State%20Management/Managing%20Other%20States/observed%20and%20objectLink) + - [@Consume and @Provide](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20UI%20State%20Management/Managing%20Other%20States/Consume%20and%20Provide) + - [@Watch](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20UI%20State%20Management/Managing%20Other%20States/Watch) + - About Rendering Control Syntax + - [if/else](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20Rendering%20Control%20Syntax/if%20else) + - [ForEach](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20Rendering%20Control%20Syntax/ForEach) + - [LazyForEach](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20Rendering%20Control%20Syntax/LazyForEach) + - About @Component + - [build Function](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20Component/build%20Function) + - [Custom Component Initialization](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20Component/Custom%20Component%20Initialization) + - [Custom Component Lifecycle Callbacks](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20Component/Custom%20Component%20Lifecycle%20Callbacks) + - [Example: Component Creation and Re-Initialization](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20Component/Example%20%20Component%20Creation%20and%20Re-Initialization) + - [Syntactic Sugar](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/Syntactic%20Sugar) + - Experiencing the Declarative UI + - [Creating a Declarative UI Project](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Experiencing%20the%20Declarative%20UI/Creating%20a%20Declarative%20UI%20Project) + - [Getting to Know Components](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Experiencing%20the%20Declarative%20UI/Getting%20to%20Know%20Components) + - [Creating a Simple Page](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Experiencing%20the%20Declarative%20UI/Creating%20a%20Simple%20Page) + - Defining Page Layout and Connection + - [Building a Food Data Model](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Defining%20Page%20Layout%20and%20Connection/Building%20a%20Food%20Data%20Model) + - [Building a Food Category List Layout](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Defining%20Page%20Layout%20and%20Connection/Building%20a%20Food%20Category%20List%20Layout) + - [Building a Food Category Grid Layout](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Defining%20Page%20Layout%20and%20Connection/Building%20a%20Food%20Category%20Grid%20Layout) + - [Implementing Page Redirection and Data Transmission](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Defining%20Page%20Layout%20and%20Connection/Implementing%20Page%20Redirection%20and%20Data%20Transmission) + - Basic Functions + - Window Manager + - Window + - [Window Overview](/pages/en/app/application/Development/Basic%20Functions/Window%20Manager/Window/Window%20Overview) + - [Window Development](/pages/en/app/application/Development/Basic%20Functions/Window%20Manager/Window/Window%20Development) + - Display + - [Display Overview](/pages/en/app/application/Development/Basic%20Functions/Window%20Manager/Display/Display%20Overview) + - [Display Development](/pages/en/app/application/Development/Basic%20Functions/Window%20Manager/Display/Display%20Development) + - Screenshot + - [Screenshot Overview](/pages/en/app/application/Development/Basic%20Functions/Window%20Manager/Screenshot/Screenshot%20Overview) + - [Screenshot Development](/pages/en/app/application/Development/Basic%20Functions/Window%20Manager/Screenshot/Screenshot%20Development) + - WebGL + - [WebGL Overview](/pages/en/app/application/Development/Basic%20Functions/WebGL/WebGL%20Overview) + - [WebGL Development](/pages/en/app/application/Development/Basic%20Functions/WebGL/WebGL%20Development) + - Media + - Audio + - [Audio Overview](/pages/en/app/application/Development/Basic%20Functions/Media/Audio/Audio%20Overview) + - [Audio Playback Development](/pages/en/app/application/Development/Basic%20Functions/Media/Audio/Audio%20Playback%20Development) + - [Audio Rendering Development](/pages/en/app/application/Development/Basic%20Functions/Media/Audio/Audio%20Rendering%20Development) + - [Audio Recording Development](/pages/en/app/application/Development/Basic%20Functions/Media/Audio/Audio%20Recording%20Development) + - [Audio Capture Development](/pages/en/app/application/Development/Basic%20Functions/Media/Audio/Audio%20Capture%20Development) + - Video + - [Video Playback Development](/pages/en/app/application/Development/Basic%20Functions/Media/Video/Video%20Playback%20Development) + - Image + - [Image Development](/pages/en/app/application/Development/Basic%20Functions/Media/Image/Image%20Development) + - Security + - User Authentication + - [User Authentication Overview](/pages/en/app/application/Development/Basic%20Functions/Security/User%20Authentication/User%20Authentication%20Overview) + - [User Authentication Development](/pages/en/app/application/Development/Basic%20Functions/Security/User%20Authentication/User%20Authentication%20Development) + - hapsigner + - [hapsigner Guide](/pages/en/app/application/Development/Basic%20Functions/Security/hapsigner/hapsigner%20Guide) + - Connectivity + - IPC & RPC + - [IPC & RPC Overview](/pages/en/app/application/Development/Basic%20Functions/Connectivity/IPC%20%26%20RPC/IPC%20%26%20RPC%20Overview) + - [IPC & RPC Development Guidelines](/pages/en/app/application/Development/Basic%20Functions/Connectivity/IPC%20%26%20RPC/IPC%20%26%20RPC%20Development%20Guidelines) + - [Subscribing to State Changes of a Remote Object](/pages/en/app/application/Development/Basic%20Functions/Connectivity/IPC%20%26%20RPC/Subscribing%20to%20State%20Changes%20of%20a%20Remote%20Object) + - Data Management + - Distributed Data Service + - [Distributed Data Service Overview](/pages/en/app/application/Development/Basic%20Functions/Data%20Management/Distributed%20Data%20Service/Distributed%20Data%20Service%20Overview) + - [Distributed Data Service Development](/pages/en/app/application/Development/Basic%20Functions/Data%20Management/Distributed%20Data%20Service/Distributed%20Data%20Service%20Development) + - Relational Database Overview + - [RDB Overview](/pages/en/app/application/Development/Basic%20Functions/Data%20Management/Relational%20Database%20Overview/RDB%20Overview) + - [RDB Development](/pages/en/app/application/Development/Basic%20Functions/Data%20Management/Relational%20Database%20Overview/RDB%20Development) + - Lightweight Data Store + - [Lightweight Data Store Overview](/pages/en/app/application/Development/Basic%20Functions/Data%20Management/Lightweight%20Data%20Store/Lightweight%20Data%20Store%20Overview) + - [Lightweight Data Store Development](/pages/en/app/application/Development/Basic%20Functions/Data%20Management/Lightweight%20Data%20Store/Lightweight%20Data%20Store%20Development) + - Agent-Powered Scheduled Reminders + - [Overview](/pages/en/app/application/Development/Basic%20Functions/Agent-Powered%20Scheduled%20Reminders/Overview) + - [Development Guidelines](/pages/en/app/application/Development/Basic%20Functions/Agent-Powered%20Scheduled%20Reminders/Development%20Guidelines) + - Background Task Management + - [Background Task Management Overview](/pages/en/app/application/Development/Basic%20Functions/Background%20Task%20Management/Background%20Task%20Management%20Overview) + - [Background Task Management Development](/pages/en/app/application/Development/Basic%20Functions/Background%20Task%20Management/Background%20Task%20Management%20Development) + - Device + - USB Service + - [USB Service Overview](/pages/en/app/application/Development/Basic%20Functions/Device/USB%20Service/USB%20Service%20Overview) + - [USB Service Development](/pages/en/app/application/Development/Basic%20Functions/Device/USB%20Service/USB%20Service%20Development) + - Location + - [Location Overview](/pages/en/app/application/Development/Basic%20Functions/Device/Location/Location%20Overview) + - [Obtaining Device Location Information](/pages/en/app/application/Development/Basic%20Functions/Device/Location/Obtaining%20Device%20Location%20Information) + - [Geocoding and Reverse Geocoding Capabilities](/pages/en/app/application/Development/Basic%20Functions/Device/Location/Geocoding%20and%20Reverse%20Geocoding%20Capabilities) + - Sensor + - [Sensor Overview](/pages/en/app/application/Development/Basic%20Functions/Device/Sensor/Sensor%20Overview) + - [Sensor Development](/pages/en/app/application/Development/Basic%20Functions/Device/Sensor/Sensor%20Development) + - Vibrator + - [Vibrator Overview](/pages/en/app/application/Development/Basic%20Functions/Device/Vibrator/Vibrator%20Overview) + - [Vibrator Development](/pages/en/app/application/Development/Basic%20Functions/Device/Vibrator/Vibrator%20Development) + - Device Usage Statistics + - [Device Usage Statistics Overview](/pages/en/app/application/Development/Basic%20Functions/Device%20Usage%20Statistics/Device%20Usage%20Statistics%20Overview) + - [Device Usage Statistics Development](/pages/en/app/application/Development/Basic%20Functions/Device%20Usage%20Statistics/Device%20Usage%20Statistics%20Development) + - DFX + - Application Event Logging + - [Overview of Application Event Logging](/pages/en/app/application/Development/Basic%20Functions/DFX/Application%20Event%20Logging/Overview%20of%20Application%20Event%20Logging) + - [Development Guidelines on Application Event Logging](/pages/en/app/application/Development/Basic%20Functions/DFX/Application%20Event%20Logging/Development%20Guidelines%20on%20Application%20Event%20Logging) + - Performance Tracing + - [Overview of Performance Tracing](/pages/en/app/application/Development/Basic%20Functions/DFX/Performance%20Tracing/Overview%20of%20Performance%20Tracing) + - [Development of Performance Tracing](/pages/en/app/application/Development/Basic%20Functions/DFX/Performance%20Tracing/Development%20of%20Performance%20Tracing) + - Distributed Call Chain Tracing + - [Overview of Distributed Call Chain Tracing](/pages/en/app/application/Development/Basic%20Functions/DFX/Distributed%20Call%20Chain%20Tracing/Overview%20of%20Distributed%20Call%20Chain%20Tracing) + - [Development of Distributed Call Chain Tracing](/pages/en/app/application/Development/Basic%20Functions/DFX/Distributed%20Call%20Chain%20Tracing/Development%20of%20Distributed%20Call%20Chain%20Tracing) + - Internationalization + - [Overview](/pages/en/app/application/Development/Basic%20Functions/Internationalization/Overview) + - [Internationalization Development (intl)](/pages/en/app/application/Development/Basic%20Functions/Internationalization/Internationalization%20Development%20%28intl%29) + - [Internationalization Development (i18n)](/pages/en/app/application/Development/Basic%20Functions/Internationalization/Internationalization%20Development%20%28i18n%29) +- Tools + - [DevEco Studio (OpenHarmony) User Guide](/pages/en/app/application/Tools/DevEco%20Studio%20%28OpenHarmony%29%20User%20Guide) +- Hands-On Tutorials + - [Samples](https://gitee.com/openharmony/app_samples/blob/master/README.md) +- API References + - Compent Reference (JavaScript-based Web-like Development Paradigm) + - Components + - Common + - [Universal Attributes](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Common/Universal%20Attributes) + - [Universal Styles](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Common/Universal%20Styles) + - [Universal Events](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Common/Universal%20Events) + - [Universal Methods](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Common/Universal%20Methods) + - [Animation Styles](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Common/Animation%20Styles) + - [Gradient Styles](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Common/Gradient%20Styles) + - [Transition Styles](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Common/Transition%20Styles) + - [Custom Font Styles](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Common/Custom%20Font%20Styles) + - [Atomic Layout](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Common/Atomic%20Layout) + - Container Components + - [badge](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/badge) + - [dialog](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/dialog) + - [div](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/div) + - [form](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/form) + - [list](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/list) + - [list-item](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/list-item) + - [list-item-group](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/list-item-group) + - [panel](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/panel) + - [popup](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/popup) + - [refresh](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/refresh) + - [stack](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/stack) + - [stepper](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/stepper) + - [stepper-item](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/stepper-item) + - [swiper](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/swiper) + - [tabs](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/tabs) + - [tab-bar](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/tab-bar) + - [tab-content](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/tab-content) + - Basic Components + - [button](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/button) + - [chart](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/chart) + - [divider](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/divider) + - [image](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/image) + - [image-animator](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/image-animator) + - [input](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/input) + - [label](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/label) + - [marquee](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/marquee) + - [menu](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/menu) + - [option](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/option) + - [picker](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/picker) + - [picker-view](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/picker-view) + - [piece](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/piece) + - [progress](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/progress) + - [qrcode](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/qrcode) + - [rating](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/rating) + - [richtext](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/richtext) + - [search](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/search) + - [select](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/select) + - [slider](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/slider) + - [span](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/span) + - [switch](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/switch) + - [text](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/text) + - [textarea](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/textarea) + - [toolbar](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/toolbar) + - [toolbar-item](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/toolbar-item) + - [toggle](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/toggle) + - [web](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/web) + - Media Components + - [video](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Media%20Components/video) + - Canvas Components + - [canvas](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Canvas%20Components/canvas) + - [CanvasRenderingContext2D](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Canvas%20Components/CanvasRenderingContext2D) + - [Image](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Canvas%20Components/Image) + - [CanvasGradient](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Canvas%20Components/CanvasGradient) + - [ImageData](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Canvas%20Components/ImageData) + - [Path2D](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Canvas%20Components/Path2D) + - [ImageBitmap](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Canvas%20Components/ImageBitmap) + - [OffscreenCanvas](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Canvas%20Components/OffscreenCanvas) + - [OffscreenCanvasRenderingContext2D](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Canvas%20Components/OffscreenCanvasRenderingContext2D) + - Grid + - [Basic Concepts](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Grid/Basic%20Concepts) + - [grid-container](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Grid/grid-container) + - [grid-row](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Grid/grid-row) + - [grid-col](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Grid/grid-col) + - SVG Components + - [Universal Attributes](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/Universal%20Attributes) + - [svg](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/svg) + - [rect](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/rect) + - [circle](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/circle) + - [ellipse](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/ellipse) + - [path](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/path) + - [line](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/line) + - [polyline](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/polyline) + - [polygon](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/polygon) + - [text](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/text) + - [tspan](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/tspan) + - [textPath](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/textPath) + - [animate](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/animate) + - [animateMotion](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/animateMotion) + - [animateTransform](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/animateTransform) + - Custom Components + - [Basic Usage](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Custom%20Components/Basic%20Usage) + - [Custom Events](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Custom%20Components/Custom%20Events) + - [props](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Custom%20Components/props) + - [Event Parameter](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Custom%20Components/Event%20Parameter) + - [slot](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Custom%20Components/slot) + - [Lifecycle Definition](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Custom%20Components/Lifecycle%20Definition) + - [Type Attributes](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Type%20Attributes) + - Compent Reference (TypeScript-based Declarative Development Paradigm) + - Components + - Universal Components + - Universal Events + - [Click Event](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Events/Click%20Event) + - [Touch](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Events/Touch) + - [Show/Hide Event](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Events/Show%20Hide%20Event) + - [Drag/Drop Event](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Events/Drag%20Drop%20Event) + - [Key Event](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Events/Key%20Event) + - [Focus Event](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Events/Focus%20Event) + - [Mouse Event](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Events/Mouse%20Event) + - [Component Area Change Event](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Events/Component%20Area%20Change%20Event) + - Universal Attributes + - [Size](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Size) + - [Location](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Location) + - [Layout Constraints](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Layout%20Constraints) + - [Flex Layout](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Flex%20Layout) + - [Border Configuration](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Border%20Configuration) + - [Background](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Background) + - [Opacity](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Opacity) + - [Visibility](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Visibility) + - [Enable/Disable](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Enable%20Disable) + - [Overlay](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Overlay) + - [Z-order Control](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Z-order%20Control) + - [Transformation](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Transformation) + - [Image Effect Configuration](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Image%20Effect%20Configuration) + - [Shape Clipping](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Shape%20Clipping) + - [Text Style](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Text%20Style) + - [Grid](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Grid) + - [Gradient Color](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Gradient%20Color) + - [Popup Control](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Popup%20Control) + - [Menu Control](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Menu%20Control) + - [Click Control](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Click%20Control) + - [Focus Control](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Focus%20Control) + - [Hover Effect](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Hover%20Effect) + - [Component ID](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Component%20ID) + - [Touch Target](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Touch%20Target) + - [Polymorphic Style](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Polymorphic%20Style) + - Gesture Processing + - [Gesture Binding Methods](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Gesture%20Processing/Gesture%20Binding%20Methods) + - Basic Gestures + - [TapGesture](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Gesture%20Processing/Basic%20Gestures/TapGesture) + - [LongPressGesture](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Gesture%20Processing/Basic%20Gestures/LongPressGesture) + - [PanGesture](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Gesture%20Processing/Basic%20Gestures/PanGesture) + - [PinchGesture](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Gesture%20Processing/Basic%20Gestures/PinchGesture) + - [RotationGesture](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Gesture%20Processing/Basic%20Gestures/RotationGesture) + - [SwipeGesture](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Gesture%20Processing/Basic%20Gestures/SwipeGesture) + - [Combined Gestures](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Gesture%20Processing/Combined%20Gestures) + - Basic Components + - [Blank](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Blank) + - [Button](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Button) + - [Checkbox](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Checkbox) + - [CheckboxGroup](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/CheckboxGroup) + - [DataPanel](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/DataPanel) + - [DatePicker](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/DatePicker) + - [Divider](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Divider) + - [Gauge](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Gauge) + - [Image](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Image) + - [ImageAnimator](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/ImageAnimator) + - [LoadingProgress](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/LoadingProgress) + - [Marquee](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Marquee) + - [Navigation](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Navigation) + - [PatternLock](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/PatternLock) + - [PluginComponent](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/PluginComponent) + - [Progress](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Progress) + - [QRCode](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/QRCode) + - [Radio](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Radio) + - [Rating](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Rating) + - [RichText](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/RichText) + - [ScrollBar](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/ScrollBar) + - [Search](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Search) + - [Select](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Select) + - [Slider](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Slider) + - [Span](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Span) + - [Stepper](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Stepper) + - [StepperItem](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/StepperItem) + - [Text](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Text) + - [TextArea](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/TextArea) + - [TextClock](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/TextClock) + - [TextInput](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/TextInput) + - [TextPicker](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/TextPicker) + - [TextTimer](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/TextTimer) + - [TimePicker](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/TimePicker) + - [Toggle](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Toggle) + - [Web](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Web) + - [Xcomponent](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Xcomponent) + - Container Components + - [AlphabetIndexer](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/AlphabetIndexer) + - [Badge](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/Badge) + - [Column](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/Column) + - [ColumnSplit](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/ColumnSplit) + - [Counter](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/Counter) + - [Flex](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/Flex) + - [GridContainer](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/GridContainer) + - [Grid](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/Grid) + - [GridItem](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/GridItem) + - [List](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/List) + - [ListItem](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/ListItem) + - [Navigator](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/Navigator) + - [Panel](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/Panel) + - [Refresh](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/Refresh) + - [Row](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/Row) + - [RowSplit](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/RowSplit) + - [Scroll](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/Scroll) + - [SideBarContainer](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/SideBarContainer) + - [Stack](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/Stack) + - [Swiper](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/Swiper) + - [Tabs](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/Tabs) + - [TabContent](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/TabContent) + - Media Components + - [Video](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Media%20Components/Video) + - Drawing Components + - [Circle](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Drawing%20Components/Circle) + - [Ellipse](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Drawing%20Components/Ellipse) + - [Line](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Drawing%20Components/Line) + - [Polyline](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Drawing%20Components/Polyline) + - [Polygon](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Drawing%20Components/Polygon) + - [Path](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Drawing%20Components/Path) + - [Rect](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Drawing%20Components/Rect) + - [Shape](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Drawing%20Components/Shape) + - Canvas Components + - [Canvas](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Canvas%20Components/Canvas) + - [CanvasRenderingContext2D](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Canvas%20Components/CanvasRenderingContext2D) + - [OffscreenCanvasRenderingConxt2D](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Canvas%20Components/OffscreenCanvasRenderingConxt2D) + - [Lottie](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Canvas%20Components/Lottie) + - [Path2D](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Canvas%20Components/Path2D) + - [CanvasGradient](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Canvas%20Components/CanvasGradient) + - [ImageBitmap](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Canvas%20Components/ImageBitmap) + - [ImageData](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Canvas%20Components/ImageData) + - Animation + - [Attribute Animation](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Animation/Attribute%20Animation) + - [Explicit Animation](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Animation/Explicit%20Animation) + - Transition Animation + - [Page Transition](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Animation/Transition%20Animation/Page%20Transition) + - [Component Transition](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Animation/Transition%20Animation/Component%20Transition) + - [Transition of Shared Elements](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Animation/Transition%20Animation/Transition%20of%20Shared%20Elements) + - [Motion Path Animation](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Animation/Motion%20Path%20Animation) + - [Matrix Transformation](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Animation/Matrix%20Transformation) + - [Interpolation Calculation](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Animation/Interpolation%20Calculation) + - Global UI Methods + - Dialog Box + - [Alert Dialog Box](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Global%20UI%20Methods/Dialog%20Box/Alert%20Dialog%20Box) + - [Action Sheet](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Global%20UI%20Methods/Dialog%20Box/Action%20Sheet) + - [Custom Dialog Box](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Global%20UI%20Methods/Dialog%20Box/Custom%20Dialog%20Box) + - [Date Picker Dialog Box](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Global%20UI%20Methods/Dialog%20Box/Date%20Picker%20Dialog%20Box) + - [Text Picker Dialog Box](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Global%20UI%20Methods/Dialog%20Box/Text%20Picker%20Dialog%20Box) + - [Menu](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Global%20UI%20Methods/Menu) + - [Built-in Enums](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Built-in%20Enums) + - APIs + - Ability Framework + + - [@ohos.ability.dataUriUtils](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ohos.ability.dataUriUtils) + - [@ohos.application.Ability](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ohos.application.Ability) + - [@ohos.application.AbilityConstant](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ohos.application.AbilityConstant) + - [@ohos.application.AbilityStage ](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ohos.application.AbilityStage%20) + - [@ohos.application.appManager](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ohos.application.appManager) + - [@ohos.application.Configuration](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ohos.application.Configuration) + - [@ohos.application.ConfigurationConstant](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ohos.application.ConfigurationConstant) + - [@ohos.ability.featureAbility](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ohos.ability.featureAbility) + - [@ohos.application.formBindingData](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ohos.application.formBindingData) + - [@ohos.application.FormExtension](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ohos.application.FormExtension) + - [@ohos.application.missionManager](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ohos.application.missionManager) + - [@ohos.application.formProvider](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ohos.application.formProvider) + - [@ohos.ability.particleAbility](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ohos.ability.particleAbility) + - [@ohos.application.ServiceExtensionAbility](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ohos.application.ServiceExtensionAbility) + - [@ohos.application.uriPermissionManager](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ohos.application.uriPermissionManager) + - [@ohos.wantAgent](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ohos.wantAgent) + - [dataAbilityHelper](/pages/en/app/application/API%20References/APIs/Ability%20Framework/dataAbilityHelper) + - [context](/pages/en/app/application/API%20References/APIs/Ability%20Framework/context) + - [AbilityContext](/pages/en/app/application/API%20References/APIs/Ability%20Framework/AbilityContext) + - [AbilityRunningInfo](/pages/en/app/application/API%20References/APIs/Ability%20Framework/AbilityRunningInfo) + - [AbilityStageContext](/pages/en/app/application/API%20References/APIs/Ability%20Framework/AbilityStageContext) + - [Context](/pages/en/app/application/API%20References/APIs/Ability%20Framework/Context) + - [ExtensionContext](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ExtensionContext) + - [ExtensionRunningInfo](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ExtensionRunningInfo) + - [FormExtensionContext](/pages/en/app/application/API%20References/APIs/Ability%20Framework/FormExtensionContext) + - [MissionSnapshot](/pages/en/app/application/API%20References/APIs/Ability%20Framework/MissionSnapshot) + - [PermissionRequestResult](/pages/en/app/application/API%20References/APIs/Ability%20Framework/PermissionRequestResult) + - [ProcessRunningInfo](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ProcessRunningInfo) + - [ServiceExtensionContext](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ServiceExtensionContext) + + - Common Event and Notification + + - [@ohos.commonEvent](/pages/en/app/application/API%20References/APIs/Common%20Event%20and%20Notification/ohos.commonEvent) + - [@ohos.events.emitter](/pages/en/app/application/API%20References/APIs/Common%20Event%20and%20Notification/ohos.events.emitter) + - [@ohos.notification](/pages/en/app/application/API%20References/APIs/Common%20Event%20and%20Notification/ohos.notification) + - [@ohos.reminderAgent](/pages/en/app/application/API%20References/APIs/Common%20Event%20and%20Notification/ohos.reminderAgent) + - [EventHub](/pages/en/app/application/API%20References/APIs/Common%20Event%20and%20Notification/EventHub) + + - Bundle Management + + - [@ohos.bundle](/pages/en/app/application/API%20References/APIs/Bundle%20Management/ohos.bundle) + - [@ohos.bundleState ](/pages/en/app/application/API%20References/APIs/Bundle%20Management/ohos.bundleState%20) + - [@ohos.zlib](/pages/en/app/application/API%20References/APIs/Bundle%20Management/ohos.zlib) + + - UI Page + + - [@ohos.animator](/pages/en/app/application/API%20References/APIs/UI%20Page/ohos.animator) + + - Graphics + + - [@ohos.display ](/pages/en/app/application/API%20References/APIs/Graphics/ohos.display%20) + - [@ohos.screenshot](/pages/en/app/application/API%20References/APIs/Graphics/ohos.screenshot) + - [@ohos.window](/pages/en/app/application/API%20References/APIs/Graphics/ohos.window) + - [webgl](/pages/en/app/application/API%20References/APIs/Graphics/webgl) + - [webgl2](/pages/en/app/application/API%20References/APIs/Graphics/webgl2) + + - Media + + - [@ohos.multimedia.audio](/pages/en/app/application/API%20References/APIs/Media/ohos.multimedia.audio) + - [@ohos.multimedia.image](/pages/en/app/application/API%20References/APIs/Media/ohos.multimedia.image) + - [@ohos.multimedia.media](/pages/en/app/application/API%20References/APIs/Media/ohos.multimedia.media) + - [@ohos.multimedia.medialibrary](/pages/en/app/application/API%20References/APIs/Media/ohos.multimedia.medialibrary) + + - Resource Management + - [@ohos.i18n](/pages/en/app/application/API%20References/APIs/Resource%20Management/ohos.i18n) + - [@ohos.intl](/pages/en/app/application/API%20References/APIs/Resource%20Management/ohos.intl) + - [@ohos.resourceManager](/pages/en/app/application/API%20References/APIs/Resource%20Management/ohos.resourceManager) + + - Resource Scheduling + + - [@ohos.backgroundTaskManager](/pages/en/app/application/API%20References/APIs/Resource%20Scheduling%20/ohos.backgroundTaskManager) + + - Custom Management + + - [@ohos.configPolicy](/pages/en/app/application/API%20References/APIs/Custom%20Management/ohos.configPolicy) + + - Security + + - [@ohos.abilityAccessCtrl](/pages/en/app/application/API%20References/APIs/Security/ohos.abilityAccessCtrl) + - [@ohos.userIAM.userAuth ](/pages/en/app/application/API%20References/APIs/Security/ohos.userIAM.userAuth%20) + + - Data Management + + - [@ohos.data.dataAbility ](/pages/en/app/application/API%20References/APIs/Data%20Management/ohos.data.dataAbility%20) + - [@ohos.data.distributedData](/pages/en/app/application/API%20References/APIs/Data%20Management/ohos.data.distributedData) + - [@ohos.data.distributedDataObject](/pages/en/app/application/API%20References/APIs/Data%20Management/ohos.data.distributedDataObject) + - [@ohos.data.rdb](/pages/en/app/application/API%20References/APIs/Data%20Management/ohos.data.rdb) + - [@ohos.settings](/pages/en/app/application/API%20References/APIs/Data%20Management/ohos.settings) + - [resultSet](/pages/en/app/application/API%20References/APIs/Data%20Management/resultSet) + + - File Management + + - [@ohos.environment](/pages/en/app/application/API%20References/APIs/File%20Management/ohos.environment) + - [@ohos.fileio](/pages/en/app/application/API%20References/APIs/File%20Management/ohos.fileio) + - [@ohos.fileManager](/pages/en/app/application/API%20References/APIs/File%20Management/ohos.fileManager) + - [@ohos.statfs](/pages/en/app/application/API%20References/APIs/File%20Management/ohos.statfs) + - [@ohos.storageStatistics](/pages/en/app/application/API%20References/APIs/File%20Management/ohos.storageStatistics) + + - Telephony Service + + - [@ohos.contact](/pages/en/app/application/API%20References/APIs/Telephony%20Service/ohos.contact) + - [@ohos.telephony.call](/pages/en/app/application/API%20References/APIs/Telephony%20Service/ohos.telephony.call) + - [@ohos.telephony.observer](/pages/en/app/application/API%20References/APIs/Telephony%20Service/ohos.telephony.observer) + - [@ohos.telephony.radio](/pages/en/app/application/API%20References/APIs/Telephony%20Service/ohos.telephony.radio) + - [@ohos.telephony.sim](/pages/en/app/application/API%20References/APIs/Telephony%20Service/ohos.telephony.sim) + - [@ohos.telephony.sms](/pages/en/app/application/API%20References/APIs/Telephony%20Service/ohos.telephony.sms) + - [@ohos.telephony.data](/pages/en/app/application/API%20References/APIs/Telephony%20Service/ohos.telephony.data) + + - Network Management + - [@ohos.net.connection](/pages/en/app/application/API%20References/APIs/Network%20Management/ohos.net.connection) + - [@ohos.net.http](/pages/en/app/application/API%20References/APIs/Network%20Management/ohos.net.http) + - [@ohos.request](/pages/en/app/application/API%20References/APIs/Network%20Management/ohos.request) + - [@ohos.net.socket](/pages/en/app/application/API%20References/APIs/Network%20Management/ohos.net.socket) + - [@ohos.net.webSocket](/pages/en/app/application/API%20References/APIs/Network%20Management/ohos.net.webSocket) + + - Connectivity + + - [@ohos.bluetooth](/pages/en/app/application/API%20References/APIs/Connectivity/ohos.bluetooth) + - [@ohos.rpc](/pages/en/app/application/API%20References/APIs/Connectivity/ohos.rpc) + - [@ohos.wifi](/pages/en/app/application/API%20References/APIs/Connectivity/ohos.wifi) + - [@ohos.wifiext](/pages/en/app/application/API%20References/APIs/Connectivity/ohos.wifiext) + + - Basic Features + + - [@ohos.accessibility](/pages/en/app/application/API%20References/APIs/Basic%20Features/ohos.accessibility) + - [@ohos.faultLogger](/pages/en/app/application/API%20References/APIs/Basic%20Features/ohos.faultLogger) + - [@ohos.hiAppEvent](/pages/en/app/application/API%20References/APIs/Basic%20Features/ohos.hiAppEvent) + - [@ohos.hichecker](/pages/en/app/application/API%20References/APIs/Basic%20Features/ohos.hichecker) + - [@ohos.hidebug](/pages/en/app/application/API%20References/APIs/Basic%20Features/ohos.hidebug) + - [@ohos.hilog](/pages/en/app/application/API%20References/APIs/Basic%20Features/ohos.hilog) + - [@ohos.hiTraceChain](/pages/en/app/application/API%20References/APIs/Basic%20Features/ohos.hiTraceChain) + - [@ohos.hiTraceMeter](/pages/en/app/application/API%20References/APIs/Basic%20Features/ohos.hiTraceMeter) + - [@ohos.pasteboard](/pages/en/app/application/API%20References/APIs/Basic%20Features/ohos.pasteboard) + - [@ohos.screenLock](/pages/en/app/application/API%20References/APIs/Basic%20Features/ohos.screenLock) + - [@ohos.systemTime](/pages/en/app/application/API%20References/APIs/Basic%20Features/ohos.systemTime) + - [@ohos.wallpaper](/pages/en/app/application/API%20References/APIs/Basic%20Features/ohos.wallpaper) + - [Timer](/pages/en/app/application/API%20References/APIs/Basic%20Features/Timer) + + - Device Management + + - [@ohos.batteryInfo ](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.batteryInfo%20) + - [@ohos.brightness](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.brightness) + - [@ohos.deviceInfo](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.deviceInfo) + - [@ohos.distributedHardware.deviceManager](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.distributedHardware.deviceManager) + - [@ohos.geolocation](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.geolocation) + - [@ohos.multimodalInput.inputConsumer](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.multimodalInput.inputConsumer) + - [@ohos.multimodalInput.inputDevice](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.multimodalInput.inputDevice) + - [@ohos.multimodalInput.inputMonitor](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.multimodalInput.inputMonitor) + - [@ohos.power](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.power) + - [@ohos.runningLock](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.runningLock) + - [@ohos.sensor](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.sensor) + - [@ohos.systemParameter](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.systemParameter) + - [@ohos.thermal](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.thermal) + - [@ohos.update](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.update) + - [@ohos.usb](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.usb) + - [@ohos.vibrator](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.vibrator) + + - Account Management + + - [@ohos.account.appAccount](/pages/en/app/application/API%20References/APIs/Account%20Management/ohos.account.appAccount) + - [@ohos.account.distributedAccount](/pages/en/app/application/API%20References/APIs/Account%20Management/ohos.account.distributedAccount) + - [@ohos.account.osAccount](/pages/en/app/application/API%20References/APIs/Account%20Management/ohos.account.osAccount) + + - Language Base Class Library + + - [@ohos.convertxml](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.convertxml) + - [@ohos.process](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.process) + - [@ohos.uri](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.uri) + - [@ohos.url](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.url) + - [@ohos.util](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util) + - [@ohos.util.ArrayList](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.ArrayList) + - [@ohos.util.Deque](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.Deque) + - [@ohos.util.HashMap](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.HashMap) + - [@ohos.util.HashSet](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.HashSet) + - [@ohos.util.LightWeightMap](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.LightWeightMap) + - [@ohos.util.LightWeightSet](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.LightWeightSet) + - [@ohos.util.LinkedList](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.LinkedList) + - [@ohos.util.List](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.List) + - [@ohos.util.PlainArray](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.PlainArray) + - [@ohos.util.Queue](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.Queue) + - [@ohos.util.Stack](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.Stack) + - [@ohos.util.TreeMap](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.TreeMap) + - [@ohos.util.TreeSet](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.TreeSet) + - [@ohos.util.Vector](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.Vector) + - [@ohos.worker](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.worker) + - [@ohos.xml](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.xml) + + - APIs No Longer Maintained + + - [@ohos.bytrace](/pages/en/app/application/API%20References/APIs/APIs%20No%20Longer%20Maintained/ohos.bytrace) + - [@ohos.data.storage](/pages/en/app/application/API%20References/APIs/APIs%20No%20Longer%20Maintained/ohos.data.storage) + - [@system.sensor](/pages/en/app/application/API%20References/APIs/APIs%20No%20Longer%20Maintained/system.sensor) + - [@system.vibrator](/pages/en/app/application/API%20References/APIs/APIs%20No%20Longer%20Maintained/system.vibrator) + - [console](/pages/en/app/application/API%20References/APIs/APIs%20No%20Longer%20Maintained/console) \ No newline at end of file diff --git a/website/docs/extras/en/application-dev/background-agent-scheduled-reminder/Readme-EN.md b/website/docs/extras/en/application-dev/background-agent-scheduled-reminder/Readme-EN.md new file mode 100644 index 0000000000000000000000000000000000000000..1309408ef36b7a628c11a8727c58ac87eda6bbc4 --- /dev/null +++ b/website/docs/extras/en/application-dev/background-agent-scheduled-reminder/Readme-EN.md @@ -0,0 +1,19 @@ +--- +title: "Readme-EN" +prepermalink: /extras/5a2f3d1cdb48ca5c2d915aac05b9eaab/ +permalink: /extras/5a2f3d1cdb48ca5c2d915aac05b9eaab/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/background-agent-scheduled-reminder/Readme-EN.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [Readme-EN] +--- +# Agent-Powered Scheduled Reminders + +- [Overview](/pages/en/app/application/Development/Basic%20Functions/Agent-Powered%20Scheduled%20Reminders/Overview) +- [Development Guidelines](/pages/en/app/application/Development/Basic%20Functions/Agent-Powered%20Scheduled%20Reminders/Development%20Guidelines) diff --git a/website/docs/extras/en/application-dev/background-task-management/Readme-EN.md b/website/docs/extras/en/application-dev/background-task-management/Readme-EN.md new file mode 100644 index 0000000000000000000000000000000000000000..1393af3b0772a97eba3d8338d4596daecf977320 --- /dev/null +++ b/website/docs/extras/en/application-dev/background-task-management/Readme-EN.md @@ -0,0 +1,19 @@ +--- +title: "Readme-EN" +prepermalink: /extras/66fccd11797c885a22b5e57596ea39d6/ +permalink: /extras/66fccd11797c885a22b5e57596ea39d6/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/background-task-management/Readme-EN.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [Readme-EN] +--- +# Background Task Management + +- [Background Task Management Overview](/pages/en/app/application/Development/Basic%20Functions/Background%20Task%20Management/Background%20Task%20Management%20Overview) +- [Background Task Management Development](/pages/en/app/application/Development/Basic%20Functions/Background%20Task%20Management/Background%20Task%20Management%20Development) \ No newline at end of file diff --git a/website/docs/extras/en/application-dev/connectivity/Readme-EN.md b/website/docs/extras/en/application-dev/connectivity/Readme-EN.md new file mode 100644 index 0000000000000000000000000000000000000000..00393191e5ea434e32860ca19cbff09a480c6422 --- /dev/null +++ b/website/docs/extras/en/application-dev/connectivity/Readme-EN.md @@ -0,0 +1,23 @@ +--- +title: "Readme-EN" +prepermalink: /extras/85a1b375c4c8c3286b1779df1f3dc372/ +permalink: /extras/85a1b375c4c8c3286b1779df1f3dc372/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/connectivity/Readme-EN.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [Readme-EN] +--- +# Connectivity + +- [IPC & RPC](https://www.openharmony.cn/404/ipc-rpc.md) + - [IPC & RPC Overview](/pages/en/app/application/Development/Basic%20Functions/Connectivity/IPC%20%26%20RPC/IPC%20%26%20RPC%20Overview) + - [IPC & RPC Development Guidelines](/pages/en/app/application/Development/Basic%20Functions/Connectivity/IPC%20%26%20RPC/IPC%20%26%20RPC%20Development%20Guidelines) + + - [Subscribing to State Changes of a Remote Object](/pages/en/app/application/Development/Basic%20Functions/Connectivity/IPC%20%26%20RPC/Subscribing%20to%20State%20Changes%20of%20a%20Remote%20Object) + diff --git a/website/docs/extras/en/application-dev/database/Readme-EN.md b/website/docs/extras/en/application-dev/database/Readme-EN.md new file mode 100644 index 0000000000000000000000000000000000000000..80d3cbf92911a8e0e870afaa3f58880de008ba8b --- /dev/null +++ b/website/docs/extras/en/application-dev/database/Readme-EN.md @@ -0,0 +1,29 @@ +--- +title: "Readme-EN" +prepermalink: /extras/47af09e797485ee7ceafaaca30832cb9/ +permalink: /extras/47af09e797485ee7ceafaaca30832cb9/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/database/Readme-EN.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [Readme-EN] +--- +# Data Management + +- Distributed Data Service + - [Distributed Data Service Overview](/pages/en/app/application/Development/Basic%20Functions/Data%20Management/Distributed%20Data%20Service/Distributed%20Data%20Service%20Overview) + - [Distributed Data Service Development](/pages/en/app/application/Development/Basic%20Functions/Data%20Management/Distributed%20Data%20Service/Distributed%20Data%20Service%20Development) +- Relational Database + - [RDB Overview](/pages/en/app/application/Development/Basic%20Functions/Data%20Management/Relational%20Database%20Overview/RDB%20Overview) + - [RDB Development](/pages/en/app/application/Development/Basic%20Functions/Data%20Management/Relational%20Database%20Overview/RDB%20Development) +- Lightweight Data Store + - [Lightweight Data Store Overview](/pages/en/app/application/Development/Basic%20Functions/Data%20Management/Lightweight%20Data%20Store/Lightweight%20Data%20Store%20Overview) + - [Lightweight Data Store Development](/pages/en/app/application/Development/Basic%20Functions/Data%20Management/Lightweight%20Data%20Store/Lightweight%20Data%20Store%20Development) +- Distributed Data Object + - [Distributed Data Object Overview](/extras/0345d22b0fc3b8fa3d28cd2646c7b2d9/) + - [Distributed Data Object Development](/extras/407bc4ee0ff4a48840178c9daedc4bd4/) diff --git a/website/docs/extras/en/application-dev/database/database-distributedobject-guidelines.md b/website/docs/extras/en/application-dev/database/database-distributedobject-guidelines.md new file mode 100644 index 0000000000000000000000000000000000000000..9bbd825b4b7e22f9e3f66c4a70b1f71cc70d97e1 --- /dev/null +++ b/website/docs/extras/en/application-dev/database/database-distributedobject-guidelines.md @@ -0,0 +1,189 @@ +--- +title: "database-distributedobject-guidelines" +prepermalink: /extras/407bc4ee0ff4a48840178c9daedc4bd4/ +permalink: /extras/407bc4ee0ff4a48840178c9daedc4bd4/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/database/database-distributedobject-guidelines.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [database-distributedobject-guidelines] +--- +# Distributed Data Object Development + +## When to Use + +The distributed data objects allow data across devices to be processed like local variables by shielding complex data interaction between devices. For the devices that form a Super Device, when data in the distributed data object of an application is added, deleted, or modified on a device, the data for the same application is also updated on the other devices. The devices can listen for the data changes and online and offline states of other devices. The distributed data objects support basic data types, such as number, string, and Boolean, as well as complex data types, such as array and nested basic types. + + +## Available APIs + +### Creating a Distributed Data Object Instance + +Call **createDistributedObject()** to create a distributed data object instance. You can specify the attributes of the instance in **source**. + + +**Table 1** API for creating a distributed data object instance +| Package| API| Description| +| -------- | -------- | -------- | +| ohos.data.distributedDataObject| createDistributedObject(source: object): DistributedObject | Creates a distributed data object instance for data operations.| + +### Generating a Session ID + +Call **genSessionId()** to generate a session ID randomly. The generated session ID can be used to set the session ID of a distributed data object. + +**Table 2** API for generating a session ID randomly +| Package| API| Description| +| -------- | -------- | -------- | +| ohos.data.distributedDataObject| genSessionId(): string | Generates a session ID, which can be used as the session ID of a distributed data object.| + +### Setting a SessionID for Distributed Data Objects + +Call setSessionId() to set the session ID for a distributed data object. The session ID is a unique identifier for one collaboration across devices. The distributed data objects to be synchronized must be associated with the same session ID. + +**Table 3** API for setting a session ID +| Class| API| Description| +| -------- | -------- | -------- | +| DistributedDataObject | setSessionId(sessionId?: string): boolean | Sets a session ID for distributed data objects.| + +### Observing Data Changes + +Call **on()** to subscribe to data changes of a distributed data object. When the data changes, a callback will be invoked to return the data changes. You can use **off()** to unsubscribe from the data changes. + +**Table 4** APIs for observing data changes of a distributed data object +| Class| API| Description| +| -------- | -------- | -------- | +| DistributedDataObject| on(type: 'change', callback: Callback<{ sessionId: string, fields: Array<string> }>): void | Subscribes to data changes.| +| DistributedDataObject| off(type: 'change', callback?: Callback<{ sessionId: string, fields: Array<string> }>): void | Unsubscribes from data changes.| + +### Observing Online or Offline Status + +Call **on()** to subscribe to status changes of a distributed data object. The status can be online or offline. When the status changes, a callback will be invoked to return the status. You can use **off()** to unsubscribe from the status changes. + +**Table 5** APIs for observing status changes of a distributed data object +| Class| API| Description| +| -------- | -------- | -------- | +| DistributedDataObject| on(type: 'status', callback: Callback<{ sessionId: string, networkId: string, status: 'online' \| 'offline' }>): void | Subscribes to the status changes of a distributed data object.| +| DistributedDataObject| off(type: 'status', callback?: Callback<{ sessionId: string, deviceId: string, status: 'online' \| 'offline' }>): void | Unsubscribes from status changes of a distributed data object.| + + + +## How to Develop + +The following example shows how to implement a distributed data object synchronization. + +1. Import the @ohos.data.distributedDataObject module to the development environment. + ```js + import distributedObject from '@ohos.data.distributedDataObject' + ``` + +2. Obtain a distributed data object instance. + + The sample code is as follows: + ```js + var local_object = distributedObject.createDistributedObject({name:undefined, age:undefined, isVis:true, + parent:undefined, list:undefined}); + ``` + + +3. Add the synchronization network. The data objects in the synchronization network include the local and remote objects. + + The sample code is as follows: + + ```js + // Local object + var local_object = distributedObject.createDistributedObject({name:"jack", age:18, isVis:true, + parent:{mother:"jack mom",father:"jack Dad"},[{mother:"jack mom"}, {father:"jack Dad"}]}; + local_object.setsessionId(sessionId); + + // Remote object + var remote_object = distributedObject.createDistributedObject({name:undefined, age:undefined, isVis:true, + parent:undefined, list:undefined}); + remote_object.setsessionId(sessionId); + // After obtaining that the device status goes online, the remote object synchronizes data. That is, name changes to jack and age to 18. + ``` + +4. Observe the data changes of the distributed data object. Subscribe to data changes of the remote end. When the data is the peer end changes, a callback will be called to return the data changes. + + The sample code is as follows: + + ```js + changeCallback : function (sessionId, changeData) { + console.info("change" + sessionId); + + if (changeData != null && changeData != undefined) { + changeData.forEach(element => { + console.info("changed !" + element + " " + local_object[element]); + }); + } + } + local_object.on("change", this.changeCallback); + ``` + +5. Modify object attributes. The object attributes support basic data types (such as number, Boolean, and string) and complex data types (array and nested basic types). + + The sample code is as follows: + ```js + local_object.name = "jack"; + local_object.age = 19; + local_object.isVis = false; + local_object.parent = {mother:"jack mom",father:"jack Dad"}; + local_object.list = [{mother:"jack mom"}, {father:"jack Dad"}]; + ``` + + > ![icon-note.gif](../../../../images/en/application-dev/public_sys-resources/ae89e6a5f31e3d03603c1d114c8400cf.gif) **NOTE**
+ > For the distributed data object of the complex type, only the root attribute can be modified. The subordinate attributes cannot be modified. Example: + ```js + // Supported modification. + local_object.parent = {mother:"mom", father:"dad"}; + // Modification not supported. + local_object.parent.mother = "mom"; + ``` + +6. Access the distributed data object. Obtain the distributed data object attribute, which is the latest data on the network. + + The sample code is as follows: + ```js + console.info("name " + local_object["name"]); + ``` +7. Unsubscribe from data changes. You can specify the callback to unsubscribe from. If you do not specify the callback, all data change callbacks of the distributed data object will be unsubscribed from. + + The sample code is as follows: + ```js + // Unsubscribe from changeCallback. + local_object.off("change", changeCallback); + // Unsubscribe from all data change callbacks. + local_object.off("change"); + ``` +8. Subscribe to the status (online/offline) changes of the distributed data object. A callback will be invoked to report the status change when the target distributed data object goes online or offline. + The sample code is as follows: + ```js + statusCallback : function (sessionId, networkid, status) { + this.response += "status changed " + sessionId + " " + status + " " + networkId; + } + + local_object.on("status", this.changeCallback); + ``` +9. Unsubscribe from the status changes of the distributed data object. You can specify the callback to unsubscribe from. If you do not specify the callback, all status change callbacks will be unsubscribe from. + + The sample code is as follows: + ```js + // Unsubscribe from changeCallback. + local_object.off("status", changeCallback); + // unsubscribe from all status change callbacks. + local_object.off("status"); + ``` +10. Remove the distributed data object from the synchronization network. After the distributed data object is removed from the network, the data changes on the local end will not be synchronized to the remote end. + + The sample code is as follows: + ```js + local_object.setSessionId(""); + ``` + + + + diff --git a/website/docs/extras/en/application-dev/database/database-distributedobject-overview.md b/website/docs/extras/en/application-dev/database/database-distributedobject-overview.md new file mode 100644 index 0000000000000000000000000000000000000000..20ed7483359e7d3f79e38edda2f8caac4bb1f20e --- /dev/null +++ b/website/docs/extras/en/application-dev/database/database-distributedobject-overview.md @@ -0,0 +1,60 @@ +--- +title: "database-distributedobject-overview" +prepermalink: /extras/0345d22b0fc3b8fa3d28cd2646c7b2d9/ +permalink: /extras/0345d22b0fc3b8fa3d28cd2646c7b2d9/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/database/database-distributedobject-overview.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [database-distributedobject-overview] +--- +# Distributed Data Object Overview + +The distributed data object management framework is an object-oriented in-memory data management framework. It provides application developers with basic data object management capabilities, such as creating, querying, deleting, modifying, and subscribing to in-memory objects. This management framework also provides distributed capabilities to implement data object collaboration for the same application between multiple devices that form a Super Device. + + +## Key Concepts + +- **Distributed in-memory database** + + The distributed in-memory database caches data in the memory, so that applications can quickly access data. This database, however, does not store data persistently. If the database is closed, the data is not retained. + + +- **Distributed data object** + + A distributed data object is an encapsulation of the JS object type. Each distributed data object instance creates a data table in the in-memory database. The in-memory databases created for different applications are isolated from each other. Reading or assigning values to distributed data objects is automatically mapped to the **put** or **get** operation of the corresponding database. + + The distributed data object can be in the following states in its lifecycle: + + - **Uninitialized**: The distributed data object is not instantiated or has been destroyed. + - **Local**: The data table is created, but the data cannot be synchronized. + - **Distributed**: The data table is created, there are at least two online with the same session ID, and data can be synchronized across devices. If the device is offline or the session ID is empty, the distributed data object changes to the local state. + + +## Working Principles + +The distributed data objects are encapsulated into JS objects in distributed in-memory databases, which allows the distributed data objects to be operated in the same way as local variables. The system automatically implements cross-device data synchronization. + +**Figure 1** Working mechanism + +![how-distributedobject-works](../../../../images/en/application-dev/database/figures/34914a27d2d550a865d1fd112a42d9f4.png) + + + + +## Constraints + +- Data synchronization can be implemented across devices only for the applications with the same bundleName. + +- Each distributed data object occupies 100 KB to 150 KB of memory. Therefore, you are advised not to create too many distributed data objects. + +- The maximum size of a distributed data object is 500 KB. + +- For the distributed data object of the complex type, only the root attribute can be modified. The subordinate attributes cannot be modified. + +- Only JS APIs are supported. diff --git a/website/docs/extras/en/application-dev/device-usage-statistics/Readme-EN.md b/website/docs/extras/en/application-dev/device-usage-statistics/Readme-EN.md new file mode 100644 index 0000000000000000000000000000000000000000..9554788751c5c974843ce340316acb0def97fc00 --- /dev/null +++ b/website/docs/extras/en/application-dev/device-usage-statistics/Readme-EN.md @@ -0,0 +1,19 @@ +--- +title: "Readme-EN" +prepermalink: /extras/4642c8e1164455f6e87ffa333f4f8899/ +permalink: /extras/4642c8e1164455f6e87ffa333f4f8899/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/device-usage-statistics/Readme-EN.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [Readme-EN] +--- +# Device Usage Statistics + +- [Device Usage Statistics Overview](/pages/en/app/application/Development/Basic%20Functions/Device%20Usage%20Statistics/Device%20Usage%20Statistics%20Overview) +- [Device Usage Statistics Development](/pages/en/app/application/Development/Basic%20Functions/Device%20Usage%20Statistics/Device%20Usage%20Statistics%20Development) diff --git a/website/docs/extras/en/application-dev/device/Readme-EN.md b/website/docs/extras/en/application-dev/device/Readme-EN.md new file mode 100644 index 0000000000000000000000000000000000000000..74a8304bfe9c584e4b6d9acc1791d92c07cfd55b --- /dev/null +++ b/website/docs/extras/en/application-dev/device/Readme-EN.md @@ -0,0 +1,30 @@ +--- +title: "Readme-EN" +prepermalink: /extras/8a93033dae14d5695c8c5b3445590ba1/ +permalink: /extras/8a93033dae14d5695c8c5b3445590ba1/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/device/Readme-EN.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [Readme-EN] +--- +# Device + +- USB Service + - [USB Service Overview](/pages/en/app/application/Development/Basic%20Functions/Device/USB%20Service/USB%20Service%20Overview) + - [USB Service Development](/pages/en/app/application/Development/Basic%20Functions/Device/USB%20Service/USB%20Service%20Development) +- Location + - [Location Overview](/pages/en/app/application/Development/Basic%20Functions/Device/Location/Location%20Overview) + - [Obtaining Device Location Information](/pages/en/app/application/Development/Basic%20Functions/Device/Location/Obtaining%20Device%20Location%20Information) + - [Geocoding and Reverse Geocoding Capabilities](/pages/en/app/application/Development/Basic%20Functions/Device/Location/Geocoding%20and%20Reverse%20Geocoding%20Capabilities) +- Sensor + - [Sensor Overview](/pages/en/app/application/Development/Basic%20Functions/Device/Sensor/Sensor%20Overview) + - [Sensor Development](/pages/en/app/application/Development/Basic%20Functions/Device/Sensor/Sensor%20Development) +- Vibrator + - [vibrator-Overview.md](/pages/en/app/application/Development/Basic%20Functions/Device/Vibrator/Vibrator%20Overview) + - [Vibrator Development](/pages/en/app/application/Development/Basic%20Functions/Device/Vibrator/Vibrator%20Development) \ No newline at end of file diff --git a/website/docs/extras/en/application-dev/dfx/Readme-EN.md b/website/docs/extras/en/application-dev/dfx/Readme-EN.md new file mode 100644 index 0000000000000000000000000000000000000000..059f9195e37044584a336c688bed8ea30d1a33bf --- /dev/null +++ b/website/docs/extras/en/application-dev/dfx/Readme-EN.md @@ -0,0 +1,26 @@ +--- +title: "Readme-EN" +prepermalink: /extras/49e0a2bd226574ea119b2e39cf905f95/ +permalink: /extras/49e0a2bd226574ea119b2e39cf905f95/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/dfx/Readme-EN.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [Readme-EN] +--- +# DFX + +- Application Event Logging + - [Overview of Application Event Logging](/pages/en/app/application/Development/Basic%20Functions/DFX/Application%20Event%20Logging/Overview%20of%20Application%20Event%20Logging) + - [Development of Application Event Logging](/pages/en/app/application/Development/Basic%20Functions/DFX/Application%20Event%20Logging/Development%20Guidelines%20on%20Application%20Event%20Logging) +- Performance Tracing + - [Overview of Performance Tracing](/pages/en/app/application/Development/Basic%20Functions/DFX/Performance%20Tracing/Overview%20of%20Performance%20Tracing) + - [Development of Performance Tracing](/pages/en/app/application/Development/Basic%20Functions/DFX/Performance%20Tracing/Development%20of%20Performance%20Tracing) +- Distributed Call Chain Tracing + - [Overview of Distributed Call Chain Tracing](/pages/en/app/application/Development/Basic%20Functions/DFX/Distributed%20Call%20Chain%20Tracing/Overview%20of%20Distributed%20Call%20Chain%20Tracing) + - [Development of Distributed Call Chain Tracing](/pages/en/app/application/Development/Basic%20Functions/DFX/Distributed%20Call%20Chain%20Tracing/Development%20of%20Distributed%20Call%20Chain%20Tracing) diff --git a/website/docs/extras/en/application-dev/media/Readme-EN.md b/website/docs/extras/en/application-dev/media/Readme-EN.md new file mode 100644 index 0000000000000000000000000000000000000000..ec6db9c91de46a9efcc7c3ac2b1188983105a2f8 --- /dev/null +++ b/website/docs/extras/en/application-dev/media/Readme-EN.md @@ -0,0 +1,38 @@ +--- +title: "Readme-EN" +prepermalink: /extras/6c7e1611868af12071e07b3b820f6298/ +permalink: /extras/6c7e1611868af12071e07b3b820f6298/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/media/Readme-EN.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [Readme-EN] +--- +# Media + +- Audio + + - [Audio Overview](/pages/en/app/application/Development/Basic%20Functions/Media/Audio/Audio%20Overview) + + - [Audio Playback Development](/pages/en/app/application/Development/Basic%20Functions/Media/Audio/Audio%20Playback%20Development) + + - [Audio Playback Development Using AudioRenderer](/pages/en/app/application/Development/Basic%20Functions/Media/Audio/Audio%20Rendering%20Development) + + - [Audio Recording Development](/pages/en/app/application/Development/Basic%20Functions/Media/Audio/Audio%20Recording%20Development) + + - [Audio Recorder Development Using AudioCapturer](audio-capturer) + +- Video + + - [Video Playback Development](/pages/en/app/application/Development/Basic%20Functions/Media/Video/Video%20Playback%20Development) + + - [Video Recording Development](/extras/db58f6a38036d82ef8265d54d1e9552d/) + +- Image + + - [Image Development](/pages/en/app/application/Development/Basic%20Functions/Media/Image/Image%20Development) diff --git a/website/docs/extras/en/application-dev/quick-start/Readme-EN.md b/website/docs/extras/en/application-dev/quick-start/Readme-EN.md new file mode 100644 index 0000000000000000000000000000000000000000..0116276dc624bde1d2e55bf85e3db6d5d1b8b5ca --- /dev/null +++ b/website/docs/extras/en/application-dev/quick-start/Readme-EN.md @@ -0,0 +1,27 @@ +--- +title: "Readme-EN" +prepermalink: /extras/9e490855207b24d31c829b990a496bab/ +permalink: /extras/9e490855207b24d31c829b990a496bab/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/quick-start/Readme-EN.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [Readme-EN] +--- +# Quick Start + +- Getting Started + - [Preparations](/extras/3a1d4de8fdc9c4d7cb37a295d95efde7/) + - [Getting Started with eTS](/extras/ac45d669f09135c4381a93473f855d34/) + - [Getting Started with JavaScript in the Traditional Coding Approach](/extras/f414f3e1d2414f77f7257ff693ef881a/) + - [Getting Started with JavaScript in the Low-Code Approach](/extras/e0979c0b69c3f170c1d1054e21b8ae60/) + +- Development Fundamentals + - [Directory Structure](/pages/en/app/application/Quick%20Start/Directory%20Structure) + - [Resource File](/pages/en/app/application/Quick%20Start/Resource%20File%20Categories) + diff --git a/website/docs/extras/en/application-dev/quick-start/start-overview.md b/website/docs/extras/en/application-dev/quick-start/start-overview.md new file mode 100644 index 0000000000000000000000000000000000000000..b12dbc88567eab375ccaeeffab79cdaabdf0b441 --- /dev/null +++ b/website/docs/extras/en/application-dev/quick-start/start-overview.md @@ -0,0 +1,61 @@ +--- +title: "start-overview" +prepermalink: /extras/3a1d4de8fdc9c4d7cb37a295d95efde7/ +permalink: /extras/3a1d4de8fdc9c4d7cb37a295d95efde7/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/quick-start/start-overview.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [start-overview] +--- +# Preparations + +This document is intended for novices at developing OpenHarmony applications. It will introduce you to the OpenHarmony project directory structure and application development process, by walking you through a stripped-down, real-world example – building two pages and implementing redirection between pages. The following figure shows how the pages look on the DevEco Studio Previewer. + + +![en-us_image_0000001261809595](../../../../images/en/application-dev/quick-start/figures/a75d798c1b5dcb52603f104db331d1bc.png) + + +Before you begin, there are some basic concepts that will help you better understand OpenHarmony: UI framework and ability. + + +## Basic Concepts + + +### UI Framework + +OpenHarmony provides a UI development framework, known as ArkUI. ArkUI provides capabilities you may need for application UI development, including a wide array of components, layout calculation, animation, UI interaction, and drawing capabilities. + +ArkUI comes with two development paradigms: JavaScript-based web-like development paradigm (web-like development paradigm for short) and TypeScript-based declarative development paradigm (declarative development paradigm for short). You can choose whichever development paradigm that aligns with your practice. + +| **Development Paradigm** | **Language** | **UI Update Mode** | **Applicable To** | **Intended Audience** | +| -------- | -------- | -------- | -------- | -------- | +| Web-like development paradigm | JavaScript | Data-driven | Applications and service widgets with simple UIs | Frontend web developers | +| Declarative development paradigm | Extended TypeScript (eTS) | Data-driven | Applications involving technological sophistication and teamwork | Mobile application and system application developers | + +For DevEco Studio V2.2 Beta1 and later versions, both the traditional coding mode and the low-code mode are supported when the JS language is used for development. On the OpenHarmony low-code development pages, you can design your app UI in an efficient, intuitive manner, with a wide array of UI editing features complying with JS Development Specifications. + + +### Ability + +An ability is an abstraction of a capability that an application can provide. The **Ability** class is an essential component to OpenHarmony applications. An application may provide various capabilities, and so it can have multiple abilities. These abilities can be deployed together or independently from each other. + +Abilities are classified into two types: [Feature Ability (FA)](https://www.openharmony.cn/404/https://www.openharmony.cn/404/../../glossary.md#f) and [Particle Ability (PA)](https://www.openharmony.cn/404/https://www.openharmony.cn/404/../../glossary.md#p). Each type has their respective templates for different capabilities. FAs support only the Page template (also called the [Page ability](/pages/en/app/application/Development/Ability%20Development/FA%20Model/Page%20Ability%20Development)), which is used to provide the capability of interacting with users. A Page ability consists of one or more pages. The figure below shows the relationship between a Page ability and pages. + +![en-us_image_0000001215206886](../../../../images/en/application-dev/quick-start/figures/720319826002597f5e9d4a6761824d42.png) + +This document provides a Page ability instance with two pages. For more information about ability development, see [Ability Development](/pages/en/app/application/Development/Ability%20Development/FA%20Model/FA%20Model%20Overview). + + +## Tool Preparation + +1. Install the latest version of [DevEco Studio](https://developer.harmonyos.com/cn/develop/deveco-studio#download_beta_openharmony). + +2. Install DevEco Studio and configure the development environment. For details, see [Configuring the OpenHarmony SDK](https://developer.harmonyos.com/en/docs/documentation/doc-guides/ohos-setting-up-environment-0000001263160443). + +When you are done, follow the instructions in [Getting Started with eTS](/extras/ac45d669f09135c4381a93473f855d34/),[Getting Started with JavaScript in the Traditional Coding Approach](/extras/f414f3e1d2414f77f7257ff693ef881a/), and [Getting Started with JavaScript in the Low-Code Approach](/extras/e0979c0b69c3f170c1d1054e21b8ae60/). diff --git a/website/docs/extras/en/application-dev/quick-start/start-with-ets.md b/website/docs/extras/en/application-dev/quick-start/start-with-ets.md new file mode 100644 index 0000000000000000000000000000000000000000..9a3f88be1de8617b865e8dcf8c2f413af1fcc60c --- /dev/null +++ b/website/docs/extras/en/application-dev/quick-start/start-with-ets.md @@ -0,0 +1,265 @@ +--- +title: "start-with-ets" +prepermalink: /extras/ac45d669f09135c4381a93473f855d34/ +permalink: /extras/ac45d669f09135c4381a93473f855d34/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/quick-start/start-with-ets.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [start-with-ets] +--- +# Getting Started with eTS + +> ![icon-note.gif](../../../../images/en/application-dev/quick-start/public_sys-resources/ae89e6a5f31e3d03603c1d114c8400cf.gif) **Note:** +> To use eTS, your DevEco Studio must be V3.0.0.601 Beta1 or later. +> +> For best possible results, use [DevEco Studio V3.0.0.900 Beta3](https://developer.harmonyos.com/cn/develop/deveco-studio#download_beta_openharmony) for your development. + + +## Creating an eTS Project + +1. Open DevEco Studio, choose **File** > **New** > **Create Project**, select **Empty Ability**, and click **Next**. + ![en-us_image_0000001223556342](../../../../images/en/application-dev/quick-start/figures/311e9c535941186459f4e51e4f69eb24.png) + +2. On the project configuration page, set **UI Syntax** to **eTS** and retain the default values for other parameters. + ![en-us_image_0000001223716826](../../../../images/en/application-dev/quick-start/figures/9801ec03d4c76a4d80b98e41552aad93.png) + +3. Click **Finish**. DevEco Studio will automatically generate the sample code and resources that match your project type. Wait until the project is created. + + +## eTS Project Files + +- **entry** : OpenHarmony project module, which can be built into an ability package (HAP). + - **src > main > ets** : a collection of eTS source code. + - **src > main > ets > MainAbility** : entry to your application/service. + - **src > main > ets > MainAbility > pages** : pages contained in **MainAbility**. + - **src > main > ets > MainAbility > app.ets** : ability lifecycle file. + - **src > main > resources** : a collection of resource files used by your application/service, such as graphics, multimedia, character strings, and layout files. + - **src > main > config.json** : module configuration file. This file describes the global configuration information of the application/service, the device-specific configuration information, and the configuration information of the HAP file. + - **build-profile.json5** : module information and build configuration options, including **buildOption target**. + - **hvigorfile.js** : module-level compilation and build task script. You can customize related tasks and code implementation. +- **build-profile.json5** : application-level configuration information, including the signature and product configuration. +- **hvigorfile.js** : application-level compilation and build task script. + + +## Building the First Page + +1. Use the **Text** component. + After the project synchronization is complete, choose **entry** > **src** > **main** > **ets** > **MainAbility** > **pages** in the **Project** window and open the **index.ets** file. You can see that the file contains a **<Text>** component. The sample code in the **index.ets** file is shown below: + + + ``` + @Entry + @Component + struct Index { + @State message: string = 'Hello World' + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + } + .height('100%') + } + } + ``` + +2. Add a **<Button>** component. + On the default page, add a **<Button>** component to accept user clicks and implement redirection to another page. The sample code in the **index.ets** file is shown below: + + + ``` + @Entry + @Component + struct Index { + @State message: string = 'Hello World' + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + // Add a button to accept user clicks. + Button() { + Text('Next') + .fontSize(30) + .fontWeight(FontWeight.Bold) + } + .type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('40%') + .height('5%') + } + .width('100%') + } + .height('100%') + } + } + ``` + +3. On the toolbar in the upper right corner of the editing window, click **Previewer** to open the Previewer. Below is how the first page looks on the Previewer. + + ![en-us_image_0000001216239356](../../../../images/en/application-dev/quick-start/figures/485afd9b15cefaf4571ae3b381fec302.png) + + +## Building the Second Page + +1. Create the second page. + In the **Project** window, choose **entry** > **src** > **main** > **ets** > **MainAbility**, right-click the **pages** folder, choose **New** > **Page**, name the page **second**, and click **Finish**. Below is the structure of the **pages** folder: + + ![en-us_image_0000001223397122](../../../../images/en/application-dev/quick-start/figures/9c5e4822748e9c52c6d4355988d6f6a0.png) + +2. Add **<Text>** and **<Button>** components. + Add **<Text>** and **<Button>** components and set their styles, as you do for the first page. The sample code in the **second.ets** file is shown below: + + + ``` + @Entry + @Component + struct Second { + @State message: string = 'Hi there' + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('Back') + .fontSize(25) + .fontWeight(FontWeight.Bold) + } + .type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('40%') + .height('5%') + } + .width('100%') + } + .height('100%') + } + } + ``` + + +## Implementing Page Redirection + +You can implement page redirection through the page router, which finds the target page based on the page URI. Import the **router** module and then perform the steps below: + +1. Implement redirection from the first page to the second page. + In the **index.ets** file of the first page, bind the **onClick** event to the **Next** button so that clicking the button redirects the user to the second page. The sample code in the **index.ets** file is shown below: + + + ``` + import router from '@system.router'; + + @Entry + @Component + struct Index { + @State message: string = 'Hello World' + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + // Add a button to accept user clicks. + Button() { + Text('Next') + .fontSize(30) + .fontWeight(FontWeight.Bold) + } + .type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('40%') + .height('5%') + // Bind the onClick event to the Next button so that clicking the button redirects the user to the second page. + .onClick(() => { + router.push({ uri: 'pages/second' }) + }) + } + .width('100%') + } + .height('100%') + } + } + ``` + +2. Implement redirection from the second page to the first page. + In the **second.ets** file of the second page, bind the **onClick** event to the **Back** button so that clicking the button redirects the user back to the first page. The sample code in the **second.ets** file is shown below: + + + ``` + import router from '@system.router'; + + @Entry + @Component + struct Second { + @State message: string = 'Hi there' + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('Back') + .fontSize(25) + .fontWeight(FontWeight.Bold) + } + .type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('40%') + .height('5%') + // Bind the onClick event to the Back button so that clicking the button redirects the user back to the first page. + .onClick(() => { + router.back() + }) + } + .width('100%') + } + .height('100%') + } + } + ``` + +3. Open the **index.ets** file and click ![en-us_image_0000001262219043](../../../../images/en/application-dev/quick-start/figures/2b7379eb458a1a67d8ae136cd3d96a45.png) in the Previewer to refresh the file. The figure below shows the effect. + ![en-us_image_0000001260684127](../../../../images/en/application-dev/quick-start/figures/eea78dd431eda4f815f9f49dca98a3e8.png) + + +## Running the Application on a Real Device + +1. Connect the development board running the OpenHarmony standard system to the computer. + +2. Choose **File** > **Project Structure** > **Project** > **Signing Configs**, select **Automatically generate signing**, wait until the automatic signing is complete, and click **OK**, as shown below. + ![en-us_image_0000001268077317](../../../../images/en/application-dev/quick-start/figures/31a7bae88e146b99bf1336d0e69147b9.png) + +3. On the toolbar in the upper right corner of the editing window, click ![en-us_image_0000001262206247](../../../../images/en/application-dev/quick-start/figures/75a06affc0324029386b204d5cc19ad6.png). The display effect is shown in the figure below. + ![en-us_image_0000001217526428](../../../../images/en/application-dev/quick-start/figures/eea78dd431eda4f815f9f49dca98a3e8.png) + +Congratulations! You have finished developing your OpenHarmony application in eTS. To learn more about OpenHarmony, see [OpenHarmony Overview](/pages/en/app/application/Application%20Development%20Overview) diff --git a/website/docs/extras/en/application-dev/quick-start/start-with-js-low-code.md b/website/docs/extras/en/application-dev/quick-start/start-with-js-low-code.md new file mode 100644 index 0000000000000000000000000000000000000000..367cc0b74a4c3f7b936cac76c5cbbbadae5b5eb7 --- /dev/null +++ b/website/docs/extras/en/application-dev/quick-start/start-with-js-low-code.md @@ -0,0 +1,171 @@ +--- +title: "start-with-js-low-code" +prepermalink: /extras/e0979c0b69c3f170c1d1054e21b8ae60/ +permalink: /extras/e0979c0b69c3f170c1d1054e21b8ae60/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/quick-start/start-with-js-low-code.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [start-with-js-low-code] +--- +# Getting Started with JavaScript in the Low-Code Approach + +> ![icon-note.gif](../../../../images/en/application-dev/quick-start/public_sys-resources/ae89e6a5f31e3d03603c1d114c8400cf.gif) **Note:** +> This feature will be available in DevEco Studio V2.2 Beta1 and later versions. +> +> For best possible results, use [DevEco Studio V3.0.0.900 Beta3](https://developer.harmonyos.com/cn/develop/deveco-studio#download_beta_openharmony) for your development. + + +On the OpenHarmony low-code development pages, you can design your app UI in an efficient, intuitive manner, with a wide array of UI editing features complying with JS Development Specifications. + + +You can develop applications or services in the low-code approach using either of the following methods: + + +- Create a project that supports low-code development. This method is used as an example in this topic. + +- In an existing project, create a Visual file for development. + + +## Creating a Project That Supports Low-Code Development + +> ![icon-note.gif](../../../../images/en/application-dev/quick-start/public_sys-resources/ae89e6a5f31e3d03603c1d114c8400cf.gif) **Note:** +> This feature is available in DevEco Studio 3.0 Beta2 and later versions and works with compileSdkVersion 7 or later. + +1. Open DevEco Studio, choose **File** > **New** > **Create Project**, select **Empty Ability**, and click **Next**. + ![en-us_image_0000001268198893](../../../../images/en/application-dev/quick-start/figures/311e9c535941186459f4e51e4f69eb24.png) +2. Go to the project configuration page, select **Enable Super Visual**, set **UI Syntax** to **JS**, and retain the default values for other parameters. + + ![en-us_image_0000001223717294](../../../../images/en/application-dev/quick-start/figures/9c5a9b01ba549f7624563f5e24639303.png) + +3. Click **Finish**. DevEco Studio will automatically generate the sample code and resources that match your project type. Wait until the project is created. + + +## Low-code Project Files + +After the project synchronization is complete, a low-code directory structure is automatically generated in the project, as shown below. + +![en-us_image_0000001223558810](../../../../images/en/application-dev/quick-start/figures/0d726b76e0670f19290028a1a0c0d3a2.png) + +- **entry > src > main > js > MainAbility > pages > index > index.js** : defines logical relationships, such as data and events, used on low-code pages. For details, see [JavaScript](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Framework/Syntax/JavaScript). If multiple low-code development pages are created, a page folder and the corresponding **.js** file will be created for each of these pages. + > ![icon-note.gif](../../../../images/en/application-dev/quick-start/public_sys-resources/ae89e6a5f31e3d03603c1d114c8400cf.gif) **Note:** + > To avoid build errors when using the low-code development page, make sure the directory where the corresponding **.js** file is located does not contain **.hml** or **.css** files. For example, in the preceding example, no **.hml** or **.css** file is allowed in **js** > **MainAbility** > **pages** > **index**. +- **entry > src > main > supervisual > MainAbility > pages > index > index.visual** : stores the data model of the low-code development page. You can double-click the file to open the low-code development page. If multiple low-code development pages are created, a page folder and the corresponding **.visual** file will be created for each of these pages. + + +## Building the First Page + +After the project synchronization is complete, the default first page contains the **Div** and **Text** (**Hello World**) components. To better understand low-code development, we'll delete these template components from the canvas and set the page from scratch. + +Add **Div**, **Text**, and **Button** components to the first page. + +1. Delete the existing template components from the canvas. + Open the index.visual file, right-click the existing template components on the canvas, and choose **Delete** from the shortcut menu to delete them. Below is an illustration of the operations. + + ![en-us_image_0000001216600980](../../../../images/en/application-dev/quick-start/figures/496fb5d85b5eac167f4f023b5978a508.gif) + +2. Add a **Div** component and set its styles and attributes. + Drag the **Div** component from the **UI Control** area to the canvas. In the **Attributes & Styles** area on the right, click ![en-us_image_0000001260226691](../../../../images/en/application-dev/quick-start/figures/404f5af11483c9ccb3ec3327bc065c1d.png)**General** and set **Height** to **100%** so that the component fills the entire screen. Click ![en-us_image_0000001215226858](../../../../images/en/application-dev/quick-start/figures/420239e1da19e85eb357111d4ac5828c.png)**Flex**, set **FlexDirection** to **column** so that the main axis of the component is vertical, and set both **JustifyContent** and **AlignItems** to **center** so that the child components of the **Div** component are centered along the main axis and cross axis. Below is an illustration of the operations. + + ![en-us_image_0000001216448880](../../../../images/en/application-dev/quick-start/figures/35d01686d0e6c6ae09b9e8044830dbc7.gif) + +3. Add a **Text** component. + Drag the **Text** component from the **UI Control** area to the center area of the **Div** component. In the **Attributes & Styles** area, click ![en-us_image_0000001215066868](../../../../images/en/application-dev/quick-start/figures/8f7280d2b2ff4c53976d4b29ddec7c5e.png)**Properties** and set **Content** of the **Text** component to **Hello World**. Click ![en-us_image_0000001215386842](../../../../images/en/application-dev/quick-start/figures/6d353ba2426a58d92ca6df2fdc70534c.png)**Feature**, and set **FontSize** to **60px** and **TextAlign** to **center**. Then, select the **Text** component on the canvas and drag its corners to fully display the text. Below is an illustration of the operations. + + ![en-us_image_0000001216446670](../../../../images/en/application-dev/quick-start/figures/4fbd61c1787c27a3fea0fac08ca9b9c3.gif) + +4. Add a **Button** component. + Drag the **Button** component from the **UI Control** area to a position under the **Text** component on the canvas. In the **Attributes & Styles** area on the right, click ![en-us_image_0000001260106745](../../../../images/en/application-dev/quick-start/figures/8f7280d2b2ff4c53976d4b29ddec7c5e.png)**Properties** and set **Value** of the **Button** component to **Next**. Click ![en-us_image_0000001259866741](../../../../images/en/application-dev/quick-start/figures/6d353ba2426a58d92ca6df2fdc70534c.png)**Feature** and set **FontSize** to **40px**. Then, select the **Button** component on the canvas and drag its corners to fully display the text. Below is an illustration of the operations. + + ![en-us_image_0000001260928361](../../../../images/en/application-dev/quick-start/figures/719100a9abe8d663d6d742b42dfa118f.gif) + +5. On the toolbar in the upper right corner of the editing window, click **Previewer** to open the Previewer. Below is how the first page looks on the Previewer. + ![en-us_image_0000001216288558](../../../../images/en/application-dev/quick-start/figures/caf6bc6f1e82645be1a827f82c91dadf.png) + + +## Building the Second Page + +1. Create the second page. + In the **Project** window, choose **entry** > **src** > **main** > **js** > **MainAbility**, right-click the **pages** folder, choose **New** > **Visual**, name the page **second**, and click **Finish**. Below is the structure of the **pages** folder: + + ![en-us_image_0000001223882030](../../../../images/en/application-dev/quick-start/figures/e9ad7e8f6055b7a12945a0124c594238.png) + +2. [Delete the existing template components from the canvas.](#delete_origin_content) + +3. [Add a Div component and set its styles and attributes.](#add_container) + +4. Add a **Text** component. + Drag the **Text** component from the **UI Control** area to the center area of the **Div** component. In the **Attributes & Styles** area, click ![en-us_image_0000001260227453](../../../../images/en/application-dev/quick-start/figures/8f7280d2b2ff4c53976d4b29ddec7c5e.png)**Properties** and set **Content** of the **Text** component to **Hi there**. Click ![en-us_image_0000001260107497](../../../../images/en/application-dev/quick-start/figures/6d353ba2426a58d92ca6df2fdc70534c.png)**Feature**, and set **FontSize** to **60px** and **TextAlign** to **center**. Then, select the **Text** component on the canvas and drag its corners to fully display the text. Below is an illustration of the operations. + + ![en-us_image_0000001216614132](../../../../images/en/application-dev/quick-start/figures/b972c108e5e7499b71b6e8744e628a92.gif) + +5. Add a **Button** component. + Drag the **Button** component from the **UI Control** area to a position under the **Text** component on the canvas. In the **Attributes & Styles** area on the right, click ![en-us_image_0000001215227618](../../../../images/en/application-dev/quick-start/figures/8f7280d2b2ff4c53976d4b29ddec7c5e.png)**Properties** and set **Value** of the **Button** component to **Back**. Click ![en-us_image_0000001259987441](../../../../images/en/application-dev/quick-start/figures/6d353ba2426a58d92ca6df2fdc70534c.png)**Feature** and set **FontSize** to **40px**. Then, select the **Button** component on the canvas and drag its corners to fully display the text. Below is an illustration of the operations. + + ![en-us_image_0000001261017331](../../../../images/en/application-dev/quick-start/figures/cc2fd8b1c0eb692d905f96d92a52f72b.gif) + + +## Implementing Page Redirection + +You can implement page redirection through the [page router](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Building%20the%20UI/Defining%20Page%20Routes), which finds the target page based on the page URI. Import the **router** module and then perform the steps below: + +1. Implement redirection from the first page to the second page. + In the files of the first page, bind the **onclick** method to the button so that clicking the button redirects the user to the second page. This operation needs to be completed in both .js and .visual files. + - In the **index.js** file: + + ``` + import router from '@system.router'; + + export default { + onclick() { + router.push({ + uri:'pages/second/second', // Specify the page to be redirected to. + }) + } + } + ``` + + - In the index.visual file, select the **Button** component on the canvas. In the **Attributes & Styles** area, click ![en-us_image_0000001215388136](../../../../images/en/application-dev/quick-start/figures/751ef1d1e3ce624f2575e10bbd07e3c6.png)**Events** and set **Click** to **onclick**. + + ![en-us_image_0000001223722586](../../../../images/en/application-dev/quick-start/figures/37367cc8edf735817a0408fd28996158.png) + +2. Implement redirection from the second page to the first page. + In the files of the second page, bind the **back** method to the **Back** button so that clicking the button redirects the user back to the first page. + + This operation needs to be completed in both .js and .visual files. + + - In the **second.js** file: + + ``` + import router from '@system.router'; + + export default { + back() { + router.back() + } + } + ``` + - In the second.visual file, select the **Button** component on the canvas. In the **Attributes & Styles** area, click ![en-us_image_0000001215388262](../../../../images/en/application-dev/quick-start/figures/751ef1d1e3ce624f2575e10bbd07e3c6.png)**Events** and set **Click** to **back**. + + ![en-us_image_0000001268082945](../../../../images/en/application-dev/quick-start/figures/a24c4f5f8f0c83e49a07a9f292c7f07a.png) + +3. Open the **index.visual** or **index.js** file and click ![en-us_image_0000001261979271](../../../../images/en/application-dev/quick-start/figures/2b7379eb458a1a67d8ae136cd3d96a45.png) in the Previewer to refresh the file. The figure below shows the effect. + ![en-us_image_0000001261142799](../../../../images/en/application-dev/quick-start/figures/a13a734bbec30ffbb81afc5cbb898f34.png) + + +## Running the Application on a Real Device + +1. Connect the development board running the OpenHarmony standard system to the computer. + +2. Choose **File** > **Project Structure** > **Project** > **Signing Configs**, select **Automatically generate signing**, wait until the automatic signing is complete, and click **OK**, as shown below. + ![en-us_image_0000001268283201](../../../../images/en/application-dev/quick-start/figures/31a7bae88e146b99bf1336d0e69147b9.png) + +3. On the toolbar in the upper right corner of the editing window, click ![en-us_image_0000001262207811](../../../../images/en/application-dev/quick-start/figures/75a06affc0324029386b204d5cc19ad6.png). The display effect is shown in the figure below. + ![en-us_image_0000001262127855](../../../../images/en/application-dev/quick-start/figures/a13a734bbec30ffbb81afc5cbb898f34.png) + +Congratulations! You have finished developing your OpenHarmony app in JavaScript in the low-code approach. To learn more about OpenHarmony, see [OpenHarmony Overview](/pages/en/app/application/Application%20Development%20Overview) diff --git a/website/docs/extras/en/application-dev/quick-start/start-with-js.md b/website/docs/extras/en/application-dev/quick-start/start-with-js.md new file mode 100644 index 0000000000000000000000000000000000000000..7970fc6df46242e1dae95903a81913d949e1305c --- /dev/null +++ b/website/docs/extras/en/application-dev/quick-start/start-with-js.md @@ -0,0 +1,220 @@ +--- +title: "start-with-js" +prepermalink: /extras/f414f3e1d2414f77f7257ff693ef881a/ +permalink: /extras/f414f3e1d2414f77f7257ff693ef881a/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/quick-start/start-with-js.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [start-with-js] +--- +# Getting Started with JavaScript in the Traditional Coding Approach + +> ![icon-note.gif](../../../../images/en/application-dev/quick-start/public_sys-resources/ae89e6a5f31e3d03603c1d114c8400cf.gif) **Note:** +> For best possible results, use [DevEco Studio V3.0.0.900 Beta3](https://developer.harmonyos.com/cn/develop/deveco-studio#download_beta_openharmony) for your development. + + +## Creating a JavaScript Project + +1. Open DevEco Studio, choose **File** > **New** > **Create Project**, select **Empty Ability**, and click **Next**. + ![en-us_image_0000001223558814](../../../../images/en/application-dev/quick-start/figures/311e9c535941186459f4e51e4f69eb24.png) + +2. On the project configuration page, set **UI Syntax** to **JS** and retain the default values for other parameters. + ![en-us_image_0000001223877162](../../../../images/en/application-dev/quick-start/figures/fa0a7904550418cca1fe22ffbfc9b56c.png) + +3. Click **Finish**. DevEco Studio will automatically generate the sample code and resources that match your project type. Wait until the project is created. + + +## JavaScript Project Files + +- **entry** : OpenHarmony project module, which can be built into an ability package (HAP). + - **src > main > js** : a collection of JS source code. + - **src > main > js > MainAbility** : entry to your application/service. + - **src > main > js > MainAbility > i18n** : resources in different languages, for example, UI strings and image paths. + - **src > main > js > MainAbility > pages** : pages contained in **MainAbility**. + - **src > main > js > MainAbility > app.js** : ability lifecycle file. + - **src > main > resources** : a collection of resource files used by your application/service, such as graphics, multimedia, character strings, and layout files. + - **src > main > config.json** : module configuration file. This file describes the global configuration information of the application/service, the device-specific configuration information, and the configuration information of the HAP file. + - **build-profile.json5** : module information and build configuration options, including **buildOption target**. + - **hvigorfile.js** : module-level compilation and build task script. You can customize related tasks and code implementation. +- **build-profile.json5** : application-level configuration information, including the signature and product configuration. +- **hvigorfile.js** : application-level compilation and build task script. + + +## Building the First Page + +1. Use the **Text** component. + After the project synchronization is complete, choose **entry** > **src** > **main** > **js** > **MainAbility** > **pages** > **index** in the **Project** window and open the **index.hml** file. You can see that the file contains a **<Text>** component. The sample code in the **index.hml** file is shown below: + + + ``` +
+ + Hello World + +
+ ``` + +2. Add a button and bind the **onclick** method to this button. + On the default page, add an **<input>** component of the button type to accept user clicks and implement redirection to another page. The sample code in the **index.hml** file is shown below: + + + ``` +
+ + Hello World + + + + +
+ ``` + +3. Set the page style in the **index.css** file. + From the **Project** window, choose **entry** > **src** > **main** > **js** > **MainAbility** > **pages** > **index**, open the **index.css** file, and set the page styles, such as the width, height, font size, and spacing. The sample code in the **index.css** file is shown below: + + + ``` + .container { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + left: 0px; + top: 0px; + width: 100%; + height: 100%; + } + + .title { + font-size: 100px; + font-weight: bold; + text-align: center; + width: 100%; + margin: 10px; + } + + .btn { + font-size: 60px; + font-weight: bold; + text-align: center; + width: 40%; + height: 5%; + margin-top: 20px; + } + ``` + +4. On the toolbar in the upper right corner of the editing window, click **Previewer** to open the Previewer. Below is how the first page looks on the Previewer. + + ![en-us_image_0000001216084724](../../../../images/en/application-dev/quick-start/figures/461c4654b5412a2190e4993fd6e0402c.png) + + +## Building the Second Page + +1. Create the second page. + In the **Project** window, choose **entry** > **src** > **main** > **js** > **MainAbility**, right-click the **pages** folder, choose **New** > **Page**, name the page **second**, and click **Finish**. Below is the structure of the **second** folder: + + ![en-us_image_0000001223877210](../../../../images/en/application-dev/quick-start/figures/c0a170291064d14d43153868d83011d2.png) + +2. Add **<Text>** and **<Button>** components. + Add **<Text>** and **<Button>** components and set their styles, as you do for the first page. The sample code in the **second.hml** file is shown below: + + + ``` +
+ + Hi there + + + + +
+ ``` + +3. Set the page style in the **second.css** file. The sample code in the **second.css** file is shown below: + + ``` + .container { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + left: 0px; + top: 0px; + width: 100%; + height: 100%; + } + + .title { + font-size: 100px; + font-weight: bold; + text-align: center; + width: 100%; + margin: 10px; + } + + .btn { + font-size: 60px; + font-weight: bold; + text-align: center; + width: 40%; + height: 5%; + margin-top: 20px; + } + ``` + + +## Implementing Page Redirection + +You can implement page redirection through the [page router](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Building%20the%20UI/Defining%20Page%20Routes), which finds the target page based on the page URI. Import the **router** module and then perform the steps below: + +1. Implement redirection from the first page to the second page. + In the **index.js** file of the first page, bind the **onclick** method to the button so that clicking the button redirects the user to the second page. The sample code in the **index.js** file is shown below: + + + ``` + import router from '@system.router'; + + export default { + onclick: function () { + router.push({ + uri: "pages/second/second" + }) + } + } + ``` + +2. Implement redirection from the second page to the first page. + In the **second.ets** file of the second page, bind the **back** method to the **Back** button so that clicking the button redirects the user back to the first page. The sample code in the **second.js** file is shown below: + + + ``` + import router from '@system.router'; + + export default { + back: function () { + router.back() + } + } + ``` + +3. Open any file in the **index** folder and click ![en-us_image_0000001262339067](../../../../images/en/application-dev/quick-start/figures/2b7379eb458a1a67d8ae136cd3d96a45.png) in the Previewer to refresh the file. The figure below shows the effect. + ![en-us_image_0000001216269940](../../../../images/en/application-dev/quick-start/figures/cb67652e1c2fab7d3e6801883607ff75.png) + + +## Running the Application on a Real Device + +1. Connect the development board running the OpenHarmony standard system to the computer. + +2. Choose **File** > **Project Structure** > **Project** > **Signing Configs**, select **Automatically generate signing**, wait until the automatic signing is complete, and click **OK**, as shown below. + ![en-us_image_0000001223557290](../../../../images/en/application-dev/quick-start/figures/31a7bae88e146b99bf1336d0e69147b9.png) + +3. On the toolbar in the upper right corner of the editing window, click ![en-us_image_0000001217047316](../../../../images/en/application-dev/quick-start/figures/75a06affc0324029386b204d5cc19ad6.png). The display effect is shown in the figure below. + ![en-us_image_0000001217527892](../../../../images/en/application-dev/quick-start/figures/cb67652e1c2fab7d3e6801883607ff75.png) + +Congratulations! You have finished developing your OpenHarmony application in JavaScript in the traditional coding approach. To learn more about OpenHarmony, see [OpenHarmony Overview](/pages/en/app/application/Application%20Development%20Overview) diff --git a/website/docs/extras/en/application-dev/reference/Readme-EN.md b/website/docs/extras/en/application-dev/reference/Readme-EN.md new file mode 100644 index 0000000000000000000000000000000000000000..b8c74d7f5f5968d55b8f452bffe1397601324ad0 --- /dev/null +++ b/website/docs/extras/en/application-dev/reference/Readme-EN.md @@ -0,0 +1,22 @@ +--- +title: "Readme-EN" +prepermalink: /extras/a2937dfaaa001286821ae286f1e8e453/ +permalink: /extras/a2937dfaaa001286821ae286f1e8e453/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/reference/Readme-EN.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [Readme-EN] +--- +# Development References + +- [JavaScript-based Web-like Development Paradigm](/extras/820ae68c631508f7f90c13d0d52dc8a3/) +- [TypeScript-based Declarative Development Paradigm](/extras/ec6a4691541e5a4e94fb6b9474387fce/) +- [APIs](/extras/4e29a99e4f2669ec0b511c39725300f7/) + + \ No newline at end of file diff --git a/website/docs/extras/en/application-dev/reference/apis/Readme-EN.md b/website/docs/extras/en/application-dev/reference/apis/Readme-EN.md new file mode 100644 index 0000000000000000000000000000000000000000..887f16ef13a7707aaf27292c8e5be6b4a7c8ff55 --- /dev/null +++ b/website/docs/extras/en/application-dev/reference/apis/Readme-EN.md @@ -0,0 +1,137 @@ +--- +title: "Readme-EN" +prepermalink: /extras/4e29a99e4f2669ec0b511c39725300f7/ +permalink: /extras/4e29a99e4f2669ec0b511c39725300f7/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/reference/apis/Readme-EN.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [Readme-EN] +--- +# APIs + +- Ability Framework + - [FeatureAbility Module](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ohos.ability.featureAbility) + - [ParticleAbility Module](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ohos.ability.particleAbility) + - [DataAbilityHelper Module](/pages/en/app/application/API%20References/APIs/Ability%20Framework/dataAbilityHelper) + - [DataUriUtils Module](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ohos.ability.dataUriUtils) + - [Bundle Module](/pages/en/app/application/API%20References/APIs/Bundle%20Management/ohos.bundle) + - [Context Module](/pages/en/app/application/API%20References/APIs/Ability%20Framework/context) +- Event Notification + - [CommonEvent Module](/pages/en/app/application/API%20References/APIs/Common%20Event%20and%20Notification/ohos.commonEvent) + - [Notification Module](/pages/en/app/application/API%20References/APIs/Common%20Event%20and%20Notification/ohos.notification) + - [Reminder Agent](/pages/en/app/application/API%20References/APIs/Common%20Event%20and%20Notification/ohos.reminderAgent) +- Resource Management + - [Resource Manager](/pages/en/app/application/API%20References/APIs/Resource%20Management/ohos.resourceManager) + - [Internationalization \(intl\) ](/pages/en/app/application/API%20References/APIs/Resource%20Management/ohos.intl) + - [Internationalization \(i18n\) ](/pages/en/app/application/API%20References/APIs/Resource%20Management/ohos.i18n) +- Media + - [Audio Management](/pages/en/app/application/API%20References/APIs/Media/ohos.multimedia.audio) + - [Media](/pages/en/app/application/API%20References/APIs/Media/ohos.multimedia.media) + - [Image Processing](/pages/en/app/application/API%20References/APIs/Media/ohos.multimedia.image) + - [Camera](https://www.openharmony.cn/404/js-apis-camera.md) +- Security + - [User Authentication](/pages/en/app/application/API%20References/APIs/Security/ohos.userIAM.userAuth%20) + - [Access Control](/pages/en/app/application/API%20References/APIs/Security/ohos.abilityAccessCtrl) +- Data Management + - [Lightweight Storage](/pages/en/app/application/API%20References/APIs/APIs%20No%20Longer%20Maintained/ohos.data.storage) + - [Distributed Data Management](/pages/en/app/application/API%20References/APIs/Data%20Management/ohos.data.distributedData) + - [Relational Database](/pages/en/app/application/API%20References/APIs/Data%20Management/ohos.data.rdb) + - [Result Set](/pages/en/app/application/API%20References/APIs/Data%20Management/resultSet) + - [DataAbilityPredicates](/pages/en/app/application/API%20References/APIs/Data%20Management/ohos.data.dataAbility%20) + - [Settings](/pages/en/app/application/API%20References/APIs/Data%20Management/ohos.settings) +- File Management + - [File Management](/pages/en/app/application/API%20References/APIs/File%20Management/ohos.fileio) + - [Statfs](/pages/en/app/application/API%20References/APIs/File%20Management/ohos.statfs) + - [Environment](/pages/en/app/application/API%20References/APIs/File%20Management/ohos.environment) + - [Public File Access and Management](/pages/en/app/application/API%20References/APIs/File%20Management/ohos.fileManager) + - [App Storage Statistics](/pages/en/app/application/API%20References/APIs/File%20Management/ohos.storageStatistics) +- Account Management + - [OS Account Management](/pages/en/app/application/API%20References/APIs/Account%20Management/ohos.account.osAccount) + - [Distributed Account Management](/pages/en/app/application/API%20References/APIs/Account%20Management/ohos.account.distributedAccount) + - [App Account Management](/pages/en/app/application/API%20References/APIs/Account%20Management/ohos.account.appAccount) +- Telephony Service + - [Call](/pages/en/app/application/API%20References/APIs/Telephony%20Service/ohos.telephony.call) + - [SMS](/pages/en/app/application/API%20References/APIs/Telephony%20Service/ohos.telephony.sms) + - [SIM Management](/pages/en/app/application/API%20References/APIs/Telephony%20Service/ohos.telephony.sim) + - [Radio](/pages/en/app/application/API%20References/APIs/Telephony%20Service/ohos.telephony.radio) + - [Observer](/pages/en/app/application/API%20References/APIs/Telephony%20Service/ohos.telephony.observer) + - [Cellular Data](/pages/en/app/application/API%20References/APIs/Telephony%20Service/ohos.telephony.data) +- Network Management + - [Network Connection Management](/pages/en/app/application/API%20References/APIs/Network%20Management/ohos.net.connection) + - [Socket Connection](/pages/en/app/application/API%20References/APIs/Network%20Management/ohos.net.socket) + - [WebSocket Connection](/pages/en/app/application/API%20References/APIs/Network%20Management/ohos.net.webSocket) + - [Data Request](/pages/en/app/application/API%20References/APIs/Network%20Management/ohos.net.http) +- Network and Connectivity + - [WLAN](/pages/en/app/application/API%20References/APIs/Connectivity/ohos.wifi) + - [Bluetooth](/pages/en/app/application/API%20References/APIs/Connectivity/ohos.bluetooth) + - [RPC](/pages/en/app/application/API%20References/APIs/Connectivity/ohos.rpc) + - [Upload and Download](/pages/en/app/application/API%20References/APIs/Network%20Management/ohos.request) +- Device Management + - [Sensor](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.sensor) + - [Vibrator](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.vibrator) + - [Brightness](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.brightness) + - [Battery Info](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.batteryInfo%20) + - [Power Management](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.power) + - [Thermal Management](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.thermal) + - [Running Lock](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.runningLock) + - [Device Info](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.deviceInfo) + - [systemParameter](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.systemParameter) + - [Device Management](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.distributedHardware.deviceManager) + - [Window](/pages/en/app/application/API%20References/APIs/Graphics/ohos.window) + - [Display](/pages/en/app/application/API%20References/APIs/Graphics/ohos.display%20) + - [Update](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.update) + - [USB](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.usb) + - [Location](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.geolocation) +- Basic Features + - [Application Context](https://www.openharmony.cn/404/js-apis-basic-features-app-context.md) + - [Console Logs](https://www.openharmony.cn/404/js-apis-basic-features-logs.md) + - [Page Routing](https://www.openharmony.cn/404/js-apis-basic-features-routes.md) + - [Timer](https://www.openharmony.cn/404/js-apis-basic-features-timer.md) + - [Screen Lock Management](/pages/en/app/application/API%20References/APIs/Basic%20Features/ohos.screenLock) + - [Setting the System Time](/pages/en/app/application/API%20References/APIs/Basic%20Features/ohos.systemTime) + - [Wallpaper](/pages/en/app/application/API%20References/APIs/Basic%20Features/ohos.wallpaper) + - [Pasteboard](/pages/en/app/application/API%20References/APIs/Basic%20Features/ohos.pasteboard) + - [Animation](https://www.openharmony.cn/404/js-apis-basic-features-animator.md) + - [WebGL](/pages/en/app/application/API%20References/APIs/Graphics/webgl) + - [WebGL2](/pages/en/app/application/API%20References/APIs/Graphics/webgl2) + - [Screenshot](/pages/en/app/application/API%20References/APIs/Graphics/ohos.screenshot) + - [Accessibility](/pages/en/app/application/API%20References/APIs/Basic%20Features/ohos.accessibility) +- DFX + - [HiAppEvent](/pages/en/app/application/API%20References/APIs/Basic%20Features/ohos.hiAppEvent) + - [Performance Tracing](/pages/en/app/application/API%20References/APIs/Basic%20Features/ohos.hiTraceMeter) + - [Fault Logger](/pages/en/app/application/API%20References/APIs/Basic%20Features/ohos.faultLogger) + - [Distributed Call Chain Tracing](/pages/en/app/application/API%20References/APIs/Basic%20Features/ohos.hiTraceChain) + - [HiLog](/pages/en/app/application/API%20References/APIs/Basic%20Features/ohos.hilog) + - [HiChecker](/pages/en/app/application/API%20References/APIs/Basic%20Features/ohos.hichecker) + - [HiDebug](/pages/en/app/application/API%20References/APIs/Basic%20Features/ohos.hidebug) +- Language Base Class Library + - [Obtaining Process Information](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.process) + - [URL String Parsing](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.url) + - [URI String Parsing](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.uri) + - [Util](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util) + - [XML Parsing and Generation](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.xml) + - [XML-to-JavaScript Conversion](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.convertxml) + - [Worker Startup](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.worker) + - [Linear Container ArrayList](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.ArrayList) + - [Linear Container Deque](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.Deque) + - [Linear Container List](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.List) + - [Linear Container LinkedList](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.LinkedList) + - [Linear Container Queue](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.Queue) + - [Linear Container Stack](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.Stack) + - [Linear Container Vector](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.Vector) + - [Nonlinear Container HashSet](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.HashSet) + - [Nonlinear Container HashMap](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.HashMap) + - [Nonlinear Container PlainArray](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.PlainArray) + - [Nonlinear Container TreeMap](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.TreeMap) + - [Nonlinear Container TreeSet](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.TreeSet) + - [Nonlinear Container LightWeightMap](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.LightWeightMap) + - [Nonlinear Container LightWeightSet](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.LightWeightSet) +- Custom Management + - [Configuration Policy](/pages/en/app/application/API%20References/APIs/Custom%20Management/ohos.configPolicy) + diff --git a/website/docs/extras/en/application-dev/reference/arkui-js/Readme-EN.md b/website/docs/extras/en/application-dev/reference/arkui-js/Readme-EN.md new file mode 100644 index 0000000000000000000000000000000000000000..0cac566f20d533cb62b6691028c7eea1f31e3ebb --- /dev/null +++ b/website/docs/extras/en/application-dev/reference/arkui-js/Readme-EN.md @@ -0,0 +1,125 @@ +--- +title: "Readme-EN" +prepermalink: /extras/820ae68c631508f7f90c13d0d52dc8a3/ +permalink: /extras/820ae68c631508f7f90c13d0d52dc8a3/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/reference/arkui-js/Readme-EN.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [Readme-EN] +--- +# JavaScript-based Web-like Development Paradigm + +- Components + - Common + - [Universal Attributes](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Common/Universal%20Attributes) + - [Universal Styles](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Common/Universal%20Styles) + - [Universal Events](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Common/Universal%20Events) + - [Universal Methods](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Common/Universal%20Methods) + - [Animation Styles](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Common/Animation%20Styles) + - [Gradient Styles](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Common/Gradient%20Styles) + - [Transition Styles](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Common/Transition%20Styles) + - [Media Query](/extras/d4fa4e2382d1545e8fa3cb1b546f393e/) + - [Custom Font Styles](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Common/Custom%20Font%20Styles) + - [Atomic Layout](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Common/Atomic%20Layout) + + - Container Component + - [badge](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/badge) + - [dialog](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/dialog) + - [div](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/div) + - [form](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/form) + - [list](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/list) + - [list-item](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/list-item) + - [list-item-group](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/list-item-group) + - [panel](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/panel) + - [popup](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/popup) + - [refresh](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/refresh) + - [stack](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/stack) + - [stepper](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/stepper) + - [stepper-item](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/stepper-item) + - [swiper](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/swiper) + - [tabs](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/tabs) + - [tab-bar](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/tab-bar) + - [tab-content](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/tab-content) + + - Basic Components + - [button](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/button) + - [chart](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/chart) + - [divider](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/divider) + - [image](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/image) + - [image-animator](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/image-animator) + - [input](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/input) + - [label](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/label) + - [marquee](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/marquee) + - [menu](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/menu) + - [option](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/option) + - [picker](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/picker) + - [picker-view](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/picker-view) + - [piece](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/piece) + - [progress](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/progress) + - [qrcode](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/qrcode) + - [rating](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/rating) + - [richtext](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/richtext) + - [search](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/search) + - [select](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/select) + - [slider](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/slider) + - [span](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/span) + - [switch](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/switch) + - [text](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/text) + - [textarea](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/textarea) + - [toolbar](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/toolbar) + - [toolbar-item](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/toolbar-item) + - [toggle](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/toggle) + - [web](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/web) + + - Media Components + - [video](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Media%20Components/video) + + - Canvas Components + - [canvas](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Canvas%20Components/canvas) + - [CanvasRenderingContext2D](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Canvas%20Components/CanvasRenderingContext2D) + - [Image](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Canvas%20Components/Image) + - [CanvasGradient](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Canvas%20Components/CanvasGradient) + - [ImageData](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Canvas%20Components/ImageData) + - [Path2D](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Canvas%20Components/Path2D) + - [ImageBitmap](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Canvas%20Components/ImageBitmap) + - [OffscreenCanvas](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Canvas%20Components/OffscreenCanvas) + - [OffscreenCanvasRenderingContext2D](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Canvas%20Components/OffscreenCanvasRenderingContext2D) + + - Grid + - [Basic Concepts](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Grid/Basic%20Concepts) + - [grid-container](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Grid/grid-container) + - [grid-row](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Grid/grid-row) + - [grid-col](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Grid/grid-col) + + - SVG Components + - [Universal Attributes](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/Universal%20Attributes) + - [svg](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/svg) + - [rect](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/rect) + - [circle](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/circle) + - [ellipse](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/ellipse) + - [path](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/path) + - [line](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/line) + - [polyline](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/polyline) + - [polygon](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/polygon) + - [text](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/text) + - [tspan](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/tspan) + - [textPath](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/textPath) + - [animate](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/animate) + - [animateMotion](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/animateMotion) + - [animateTransform](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/animateTransform) + +- Custom Components + - [Basic Usage](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Custom%20Components/Basic%20Usage) + - [Custom Events](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Custom%20Components/Custom%20Events) + - [props](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Custom%20Components/props) + - [Event Parameter](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Custom%20Components/Event%20Parameter) + - [slot](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Custom%20Components/slot) + - [Lifecycle Definition](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Custom%20Components/Lifecycle%20Definition) +- [Type Attributes](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Type%20Attributes) + diff --git a/website/docs/extras/en/application-dev/reference/arkui-js/js-components-common-mediaquery.md b/website/docs/extras/en/application-dev/reference/arkui-js/js-components-common-mediaquery.md new file mode 100644 index 0000000000000000000000000000000000000000..970eb9ec12af0672bfac3dc98969cea80c3c88d9 --- /dev/null +++ b/website/docs/extras/en/application-dev/reference/arkui-js/js-components-common-mediaquery.md @@ -0,0 +1,318 @@ +--- +title: "js-components-common-mediaquery" +prepermalink: /extras/d4fa4e2382d1545e8fa3cb1b546f393e/ +permalink: /extras/d4fa4e2382d1545e8fa3cb1b546f393e/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/reference/arkui-js/js-components-common-mediaquery.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [js-components-common-mediaquery] +--- +# Media Query + +>![](../../../../../images/en/application-dev/public_sys-resources/ae89e6a5f31e3d03603c1d114c8400cf.gif) **NOTE:** +>- The **media** attribute uses the actual size, physical pixel, and screen resolution of the device by default. Do not confuse them with the configuration based on basic screen width 720 px. + +Media query is widely used on mobile devices. You may need to frequently modify the application style based on the device type or specific features and device parameters \(such as the screen resolution\). To keep up with your requirements, the media query component provides the following features: + +1. Allows you to design different layouts matching the device and application attributes. +2. Synchronously updates the application page layouts when your screen changes dynamically \(for example, in the event of screen splitting or landscape/portrait orientation switching\). + +## CSS Syntax Rules + +Use @media to import query statements. The rules are as follows: + +``` +@media [media-type] [and|not|only] [(media-feature)] { + CSS-Code; +} +``` + +Examples: + +@media screen and \(round-screen: true\) \{ … \} // The condition is met when the device screen is round. + +@media \(max-height: 800\) \{ … \} // Range query. CSS level 3 is used. + +@media \(height <= 800\) \{ ... \} // Range query. CSS level 4 is used, and the statement is equivalent to that of CSS level 3. + +@media screen and \(device-type: tv\) or \(resolution < 2\) \{ ... \} // Multi-condition query that contains the media type and multiple media features. + +## Referencing Resources on a Page + +Use @import to import media query. The rule is as follows: + +``` +@import url [media-type] [and|not|only] [(media-feature)]; +``` + +Sample code: + +``` +@import '../common/style.css' screen and (min-width: 600) and (max-width: 1200); +``` + +## Media Type + + + + + + + + + + +

Type

+

Description

+

screen

+

Media query based on screen-related parameters

+
+ +## Media Logical Operation + +Media logical operators \(and, or, not, and only\) are used to implement complex media query. They can also be combined using comma \(,\). The following table describes the operators. + +**Table 1** Media logical operators + + + + + + + + + + + + + + + + + + + + + + +

Type

+

Description

+

and

+

The and operator is used to combine multiple media features into a media query, in a logical AND operation. The query is valid only when all media features are true. It can also combine media types and media functions.

+

For example, screen and (device-type: wearable) and (max-height: 600) indicates that the query is valid when the device is a wearable and the maximum height of the application is less than or equal to 600 pixels.

+

not

+

The not operator is used to perform a logical negation for a media query. true is returned if the query condition is not met. Otherwise, false is returned. In a media query list, logical negation is performed only for the media query using the not operator.

+

For example, not screen and (min-height: 50) and (max-height: 600) indicates that the query is valid when the height of the application is less than 50 pixels or greater than 600 pixels.

+
NOTE:

You must specify the media type when using the not operator.

+
+

only

+

The only operator applies the selected style only when the entire expression is matched. It can be used to prevent ambiguity while some browsers of earlier versions are processing the statements containing both media types and media features. For example:

+

screen and (min-height: 50)

+

The browsers of earlier versions would mislead this sentence into screen, causing the fact that the specified style is applied when only the media type is matched. In this case, the only operator can be used to avoid this problem.

+
NOTE:

You must specify the media type when using the only operator.

+
+

,(comma)

+

The comma operator is used to combine multiple media features into one media query, in a logical OR operation. The query is valid if a media feature is true. The effect of a comma operator is equivalent to that of the or operator.

+

For example, screen and (min-height: 1000), (round-screen: true) evaluates to true when the application height is greater than or equal to 1000 pixels or the device screen is rounded.

+

or

+

The or operator is used to combine multiple media features into one media query, in a logical OR operation. The query is valid if a media feature is true.

+

For example, screen and (max-height: 1000) or (round-screen: true) evaluates to true when the application height is less than or equal to 1000 pixels or the device screen is rounded.

+
+ +At MediaQuery Level 4, range query is imported so that you can use the operators including <=, \>=, <, and \> besides the max- and min-operators. + +**Table 2** Media logical range operators + + + + + + + + + + + + + + + + + + + +

Type

+

Description

+

<=

+

Less than or equal to, for example, screen and (50 <= height).

+

>=

+

Greater than or equal to, for example, screen and (600 >= height).

+

<

+

Less than, for example, screen and (50 < height).

+

>

+

Greater than, for example, screen and (600 > height).

+
+ +## Media Features + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Type

+

Description

+

height

+

Height of the display area on the application page.

+

min-height

+

Minimum height of the display area on the application page.

+

max-height

+

Maximum height of the display area on the application page.

+

width

+

Width of the display area on the application page.

+

min-width

+

Minimum width of the display area on the application page.

+

max-width

+

Maximum width of the display area on the application page.

+

resolution

+

Resolution of the device. The unit can be dpi, dppx, or dpcm.

+
  • dpi indicates the number of physical pixels per inch. 1 dpi ≈ 0.39 dpcm.
  • dpcm indicates the number of physical pixels per centimeter. 1 dpcm ≈ 2.54 dpi.
  • dppx indicates the number of physical pixels in each pixel. The unit is 96 px = 1 inch, which is different from the calculation method of the pixel unit on the page. 1 dppx = 96 dpi.
+

min-resolution

+

Minimum device resolution.

+

max-resolution

+

Maximum device resolution.

+

orientation

+

Screen orientation.

+

Options are as follows:

+
  • orientation: portrait: portrait screen orientation
  • orientation: landscape: landscape screen orientation
+

aspect-ratio

+

Ratio of the width to the height of the display area on the application page.

+

Example: aspect-ratio:1/2

+

min-aspect-ratio

+

Minimum ratio of the width to the height of the display area on the application page.

+

max-aspect-ratio

+

Maximum ratio of the width to the height of the display area on the application page.

+

device-height

+

Height of the device.

+

min-device-height

+

Minimum height of the device.

+

max-device-height

+

Maximum height of the device.

+

device-width

+

Width of the device.

+

min-device-width

+

Minimum width of the device.

+

max-device-width

+

Maximum width of the device.

+

round-screen

+

Screen type. The value true indicates a circular screen, and false indicates a non-circular screen.

+

dark-mode6+

+

Whether the device is in dark mode. The value is true if the device is in dark mode and false otherwise.

+
+ +## Sample Code + +- Sample code of the common media feature is as follows: + +``` + +
+
+ Hello World +
+
+``` + +``` +/* xxx.css */ +.container { + width: 300px; + height: 600px; + background-color: #008000; +} +@media (device-type: tv) { + .container { + width: 500px; + height: 500px; + background-color: #fa8072; + } +} +@media (device-type: wearable) { + .container { + width: 300px; + height: 300px; + background-color: #008b8b; + } +} +``` + diff --git a/website/docs/extras/en/application-dev/reference/arkui-ts/Readme-EN.md b/website/docs/extras/en/application-dev/reference/arkui-ts/Readme-EN.md new file mode 100644 index 0000000000000000000000000000000000000000..1dacce6b96766a6d14864da0b7b482553db06ebe --- /dev/null +++ b/website/docs/extras/en/application-dev/reference/arkui-ts/Readme-EN.md @@ -0,0 +1,166 @@ +--- +title: "Readme-EN" +prepermalink: /extras/ec6a4691541e5a4e94fb6b9474387fce/ +permalink: /extras/ec6a4691541e5a4e94fb6b9474387fce/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/reference/arkui-ts/Readme-EN.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [Readme-EN] +--- +# TypeScript-based Declarative Development Paradigm + +- Components + - Universal Components + - Universal Events + - [Click Event](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Events/Click%20Event) + - [Touch Event](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Events/Touch) + - [Show/Hide Event](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Events/Show%20Hide%20Event) + - [Drag/Drop Event](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Events/Drag%20Drop%20Event) + - [Key Event](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Events/Key%20Event) + - [Focus Event](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Events/Focus%20Event) + - [Mouse Event](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Events/Mouse%20Event) + - [Component Area Change Event](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Events/Component%20Area%20Change%20Event) + - Universal Attributes + - [Size](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Size) + - [Location](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Location) + - [Layout Constraints](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Layout%20Constraints) + - [Flex Layout](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Flex%20Layout) + - [Border](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Border%20Configuration) + - [Background](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Background) + - [Opacity](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Opacity) + - [Visibility](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Visibility) + - [Enable/Disable](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Enable%20Disable) + - [Overlay](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Overlay) + - [Z-order Control](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Z-order%20Control) + - [Transformation](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Transformation) + - [Image Effect Configuration](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Image%20Effect%20Configuration) + - [Shape Clipping](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Shape%20Clipping) + - [Text Style](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Text%20Style) + - [Grid](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Grid) + - [Gradient Color](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Gradient%20Color) + - [Popup Control](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Popup%20Control) + - [Menu Control](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Menu%20Control) + - [Click Control](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Click%20Control) + - [Focus Control](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Focus%20Control) + - [Hover Effect](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Hover%20Effect) + - [Component ID](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Component%20ID) + - [Touch Target](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Touch%20Target) + - [Polymorphic Style](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Polymorphic%20Style) + - Gesture Processing + - [Gesture Binding Methods](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Gesture%20Processing/Gesture%20Binding%20Methods) + - Basic Gestures + - [TapGesture](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Gesture%20Processing/Basic%20Gestures/TapGesture) + - [LongPressGesture](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Gesture%20Processing/Basic%20Gestures/LongPressGesture) + - [PanGesture](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Gesture%20Processing/Basic%20Gestures/PanGesture) + - [PinchGesture](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Gesture%20Processing/Basic%20Gestures/PinchGesture) + - [RotationGesture](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Gesture%20Processing/Basic%20Gestures/RotationGesture) + - [SwipeGesture](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Gesture%20Processing/Basic%20Gestures/SwipeGesture) + - [Combined Gestures](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Gesture%20Processing/Combined%20Gestures) + - Basic Components + - [Blank](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Blank) + - [Button](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Button) + - [Checkbox](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Checkbox) + - [CheckboxGroup](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/CheckboxGroup) + - [DataPanel](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/DataPanel) + - [DatePicker](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/DatePicker) + - [Divider](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Divider) + - [Gauge](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Gauge) + - [Image](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Image) + - [ImageAnimator](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/ImageAnimator) + - [LoadingProgress](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/LoadingProgress) + - [Marquee](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Marquee) + - [Navigation](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Navigation) + - [PatternLock](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/PatternLock) + - [PluginComponent](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/PluginComponent) + - [Progress](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Progress) + - [QRCode](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/QRCode) + - [Radio](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Radio) + - [Rating](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Rating) + - [RichText](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/RichText) + - [Stepper](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Stepper) + - [StepperItem](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/StepperItem) + - [ScrollBar](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/ScrollBar) + - [Search](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Search) + - [Select](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Select) + - [Slider](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Slider) + - [Span](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Span) + - [Text](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Text) + - [TextArea](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/TextArea) + - [TextClock](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/TextClock) + - [TextInput](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/TextInput) + - [TextPicker](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/TextPicker) + - [TextTimer](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/TextTimer) + - [TimePicker](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/TimePicker) + - [Toggle](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Toggle) + - [Web](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Web) + - [Xcomponent](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Xcomponent) + - Container Components + - [AlphabetIndexer](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/AlphabetIndexer) + - [Badge](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/Badge) + - [Column](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/Column) + - [ColumnSplit](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/ColumnSplit) + - [Counter](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/Counter) + - [Flex](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/Flex) + - [GridContainer](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/GridContainer) + - [Grid](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/Grid) + - [GridItem](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/GridItem) + - [List](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/List) + - [ListItem](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/ListItem) + - [Navigator](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/Navigator) + - + - [Panel](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/Panel) + - [Refresh](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/Refresh) + - [Row](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/Row) + - [RowSplit](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/RowSplit) + - [Scroll](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/Scroll) + - [SideBarContainer](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/SideBarContainer) + - [Stack](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/Stack) + - [Swiper](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/Swiper) + - [Tabs](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/Tabs) + - [TabContent](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/TabContent) + - Media Components + - [Video](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Media%20Components/Video) + - Drawing Components + - [Circle](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Drawing%20Components/Circle) + - [Ellipse](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Drawing%20Components/Ellipse) + - [Line](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Drawing%20Components/Line) + - [Polyline](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Drawing%20Components/Polyline) + - [Polygon](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Drawing%20Components/Polygon) + - [Path](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Drawing%20Components/Path) + - [Rect](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Drawing%20Components/Rect) + - [Shape](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Drawing%20Components/Shape) + - Canvas Components + - [Canvas](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Canvas%20Components/Canvas) + - [CanvasRenderingContext2D](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Canvas%20Components/CanvasRenderingContext2D) + - [OffscreenCanvasRenderingConxt2D](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Canvas%20Components/OffscreenCanvasRenderingConxt2D) + - [Lottie](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Canvas%20Components/Lottie) + - [Path2D](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Canvas%20Components/Path2D) + - [CanvasGradient](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Canvas%20Components/CanvasGradient) + - [ImageBitmap](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Canvas%20Components/ImageBitmap) + - [ImageData](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Canvas%20Components/ImageData) +- Animation + - [AnimatorProperty](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Animation/Attribute%20Animation) + - [Explicit Animation](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Animation/Explicit%20Animation) + - Transition Animation + - [Page Transition](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Animation/Transition%20Animation/Page%20Transition) + - [Component Transition](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Animation/Transition%20Animation/Component%20Transition) + - [Transition of Shared Elements](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Animation/Transition%20Animation/Transition%20of%20Shared%20Elements) + - [Motion Path Animation](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Animation/Motion%20Path%20Animation) + - [Matrix Transformation](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Animation/Matrix%20Transformation) + - [Interpolation Calculation](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Animation/Interpolation%20Calculation) +- Global UI Methods + - Pop-up Window + - [Alert Dialog Box](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Global%20UI%20Methods/Dialog%20Box/Alert%20Dialog%20Box) + - [Action Sheet](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Global%20UI%20Methods/Dialog%20Box/Action%20Sheet) + - [Custom Dialog Box](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Global%20UI%20Methods/Dialog%20Box/Custom%20Dialog%20Box) + - [Date Picker Dialog Box](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Global%20UI%20Methods/Dialog%20Box/Date%20Picker%20Dialog%20Box) + - [Time Picker Dialog Box](/extras/873fac6f13fde57b8e8ae12c20e9fbb9/) + - [Text Picker Dialog Box](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Global%20UI%20Methods/Dialog%20Box/Text%20Picker%20Dialog%20Box) + - [Menu](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Global%20UI%20Methods/Menu) +- [Built-in Enums](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Built-in%20Enums) diff --git a/website/docs/extras/en/application-dev/reference/arkui-ts/ts-methods-timepicker-dialog.md b/website/docs/extras/en/application-dev/reference/arkui-ts/ts-methods-timepicker-dialog.md new file mode 100644 index 0000000000000000000000000000000000000000..fafd8475d1dca3d925732e0f819bd1f31de9144c --- /dev/null +++ b/website/docs/extras/en/application-dev/reference/arkui-ts/ts-methods-timepicker-dialog.md @@ -0,0 +1,101 @@ +--- +title: "ts-methods-timepicker-dialog" +prepermalink: /extras/873fac6f13fde57b8e8ae12c20e9fbb9/ +permalink: /extras/873fac6f13fde57b8e8ae12c20e9fbb9/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/reference/arkui-ts/ts-methods-timepicker-dialog.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [ts-methods-timepicker-dialog] +--- +# Time Picker Dialog Box + +> ![icon-note.gif](../../../../../images/en/application-dev/reference/arkui-ts/public_sys-resources/ae89e6a5f31e3d03603c1d114c8400cf.gif) **NOTE** +> This component is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version. + +You can display a time picker in a dialog box to allow users to select a time from the given range, which is from 00:00 to 23:59 by default. + +## Required Permissions + +None + +## TimePickerDialog.show + +show(options?: TimePickerDialogOptions) + +Defines and displays a time picker dialog box. + +- options parameters + | Name| Type| Mandatory| Default Value| Description| + | -------- | -------- | -------- | -------- | -------- | + | selected | Date | No| Current system time| Time of the selected item.| + | useMilitaryTime | boolean | No| false | Whether to display time in 24-hour format.| + | onAccept | (value: [TimePickerResult](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/TimePicker#TimePickerResult)) => void | No| - | Triggered when the OK button in the dialog box is clicked.| + | onCancel | () => void | No| - | Triggered when the Cancel button in the dialog box is clicked.| + | onChange | (value: [TimePickerResult](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/TimePicker#TimePickerResult)) => void | No| - | Triggered when the selected item in the picker changes.| + +## Example + +### Time Picker Sample Code (24-Hour Clock) +``` +@Entry +@Component +struct TimePickerDialogExample01 { + @State isUseMilitaryTime: boolean = true + + build() { + Flex({direction: FlexDirection.Column, alignItems: ItemAlign.Center, + justifyContent: FlexAlign.Center }) { + Button("TimePickerDialog").onClick(() => { + TimePickerDialog.show({ + useMilitaryTime: this.isUseMilitaryTime, + onAccept: (value: TimePickerResult) => { + this.selectedDate.setHours(value.hour, value.minute, value.second) + console.info("TimePickerDialog:onAccept()" + JSON.stringify(value)) + }, + onCancel: () => { + console.info("TimePickerDialog:onCancel()") + }, + onChange: (value: TimePickerResult) => { + console.info("TimePickerDialog:onChange()" + JSON.stringify(value)) + } + }) + }) + } + } +} +``` +### Time Picker Sample Code (12-Hour Clock) +``` +@Entry +@Component +struct TimePickerDialogExample02 { + @State isUseMilitaryTime: boolean = false + + build() { + Flex({direction: FlexDirection.Column, alignItems: ItemAlign.Center, + justifyContent: FlexAlign.Center }) { + Button("TimePickerDialog").onClick(() => { + TimePickerDialog.show({ + useMilitaryTime: this.isUseMilitaryTime, + onAccept: (value: TimePickerResult) => { + this.selectedDate.setHours(value.hour, value.minute, value.second) + console.info("TimePickerDialog:onAccept()" + JSON.stringify(value)) + }, + onCancel: () => { + console.info("TimePickerDialog:onCancel()") + }, + onChange: (value: TimePickerResult) => { + console.info("TimePickerDialog:onChange()" + JSON.stringify(value)) + } + }) + }) + } + } +} +``` diff --git a/website/docs/extras/en/application-dev/reference/native-lib/third_party_libc/musl-peculiar-symbol.md b/website/docs/extras/en/application-dev/reference/native-lib/third_party_libc/musl-peculiar-symbol.md new file mode 100644 index 0000000000000000000000000000000000000000..5ad239f3fec74a8d9d295d27dfa4c44fbf06f7f2 --- /dev/null +++ b/website/docs/extras/en/application-dev/reference/native-lib/third_party_libc/musl-peculiar-symbol.md @@ -0,0 +1,324 @@ +--- +title: "musl-peculiar-symbol" +prepermalink: /extras/8e912c88e233267d1f6f9c92a790cda8/ +permalink: /extras/8e912c88e233267d1f6f9c92a790cda8/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/reference/native-lib/third_party_libc/musl-peculiar-symbol.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [musl-peculiar-symbol] +--- +**Native API Symbols Not Exported** + +|Type|Symbol|Remarks| +| --- | --- | --- | +|OBJECT|___environ| +|OBJECT|__daylight| +|OBJECT|__environ| +|OBJECT|__hook_enable_hook_flag| +|OBJECT|__libc_malloc_default_dispatch| +|OBJECT|__musl_libc_globals| +|OBJECT|__optpos| +|OBJECT|__optreset| +|OBJECT|__progname_full| +|OBJECT|__signgam| +|OBJECT|__timezone| +|OBJECT|__tzname| +|OBJECT|_dl_debug_addr| +|OBJECT|_environ| +|OBJECT|function_of_shared_lib| +|OBJECT|h_errno| +|OBJECT|ohos_malloc_hook_shared_liibrary| +|OBJECT|program_invocation_name| +|OBJECT|program_invocation_short_name| +|FUNC|__adjtime64| +|FUNC|__aio_suspend_time64| +|FUNC|__clock_gettime64| +|FUNC|__ctype_b_loc| +|FUNC|__ctype_tolower_loc| +|FUNC|__ctype_toupper_loc| +|FUNC|__dls2b| +|FUNC|__dls3| +|FUNC|__fgetwc_unlocked| +|FUNC|__flt_rounds| +|FUNC|__fputwc_unlocked| +|FUNC|__freadahead| +|FUNC|__freadptr| +|FUNC|__freadptrinc| +|FUNC|__freelocale| +|FUNC|__fstat_time64| +|FUNC|__ftime64| +|FUNC|__fxstat64| +|FUNC|__fxstatat64| +|FUNC|__getdelim| +|FUNC|__isalnum_l| +|FUNC|__isalpha_l| +|FUNC|__isblank_l| +|FUNC|__iscntrl_l| +|FUNC|__isdigit_l| +|FUNC|__isgraph_l| +|FUNC|__islower_l| +|FUNC|__isoc99_fscanf| +|FUNC|__isoc99_fwscanf| +|FUNC|__isoc99_scanf| +|FUNC|__isoc99_sscanf| +|FUNC|__isoc99_swscanf| +|FUNC|__isoc99_vfscanf| +|FUNC|__isoc99_vfwscanf| +|FUNC|__isoc99_vscanf| +|FUNC|__isoc99_vsscanf| +|FUNC|__isoc99_vswscanf| +|FUNC|__isoc99_vwscanf| +|FUNC|__isoc99_wscanf| +|FUNC|__isprint_l| +|FUNC|__ispunct_l| +|FUNC|__isspace_l| +|FUNC|__isupper_l| +|FUNC|__iswalnum_l| +|FUNC|__iswalpha_l| +|FUNC|__iswblank_l| +|FUNC|__iswcntrl_l| +|FUNC|__iswctype_l| +|FUNC|__iswdigit_l| +|FUNC|__iswgraph_l| +|FUNC|__iswlower_l| +|FUNC|__iswprint_l| +|FUNC|__iswpunct_l| +|FUNC|__iswspace_l| +|FUNC|__iswupper_l| +|FUNC|__iswxdigit_l| +|FUNC|__isxdigit_l| +|FUNC|__lgammal_r| +|FUNC|__libc_free| +|FUNC|__libc_malloc| +|FUNC|__libc_start_main| +|FUNC|__lstat_time64| +|FUNC|__lxstat64| +|FUNC|__mq_timedreceive_time64| +|FUNC|__mq_timedsend_time64| +|FUNC|__nanosleep_time64| +|FUNC|__newlocale| +|FUNC|__nl_langinfo| +|FUNC|__nl_langinfo_l| +|FUNC|__overflow| +|FUNC|__posix_getopt| +|FUNC|__pthread_cond_timedwait_time64| +|FUNC|__pthread_gettid_np| +|FUNC|__pthread_timedjoin_np_time64| +|FUNC|__res_state| +|FUNC|__setjmp| +|FUNC|__sigsetjmp| +|FUNC|__stat_time64| +|FUNC|__stime64| +|FUNC|__strcasecmp_l| +|FUNC|__strcoll_l| +|FUNC|__strerror_l| +|FUNC|__strncasecmp_l| +|FUNC|__strtod_l| +|FUNC|__strtof_l| +|FUNC|__strtoimax_internal| +|FUNC|__strtol_internal| +|FUNC|__strtold_l| +|FUNC|__strtoll_internal| +|FUNC|__strtoul_internal| +|FUNC|__strtoull_internal| +|FUNC|__strtoumax_internal| +|FUNC|__strxfrm_l| +|FUNC|__sysv_signal| +|FUNC|__tolower_l| +|FUNC|__toupper_l| +|FUNC|__towctrans_l| +|FUNC|__towlower_l| +|FUNC|__towupper_l| +|FUNC|__uflow| +|FUNC|__uselocale| +|FUNC|__utimensat_time64| +|FUNC|__wait3_time64| +|FUNC|__wcscoll_l| +|FUNC|__wcsftime_l| +|FUNC|__wcsxfrm_l| +|FUNC|__wctrans_l| +|FUNC|__wctype_l| +|FUNC|__xmknod| +|FUNC|__xmknodat| +|FUNC|__xpg_basename| +|FUNC|__xpg_strerror_r| +|FUNC|__xstat64| +|FUNC|_dl_debug_state| +|FUNC|_dlstart| +|FUNC|_fini| +|FUNC|_init| +|FUNC|_IO_feof_unlocked| +|FUNC|_IO_ferror_unlocked| +|FUNC|_IO_getc| +|FUNC|_IO_getc_unlocked| +|FUNC|_IO_putc| +|FUNC|_IO_putc_unlocked| +|FUNC|a64l| +|FUNC|addmntent| +|FUNC|adjtime| +|FUNC|aio_cancel| +|FUNC|aio_cancel64| +|FUNC|aio_error| +|FUNC|aio_error64| +|FUNC|aio_fsync| +|FUNC|aio_fsync64| +|FUNC|aio_read| +|FUNC|aio_read64| +|FUNC|aio_return| +|FUNC|aio_return64| +|FUNC|aio_suspend| +|FUNC|aio_suspend64| +|FUNC|aio_write| +|FUNC|aio_write64| +|FUNC|bcmp| +|FUNC|bind_textdomain_codeset| +|FUNC|bindtextdomain| +|FUNC|confstr| +|FUNC|copy_file_range| +|FUNC|crypt| +|FUNC|crypt_r| +|FUNC|cuserid| +|FUNC|dcgettext| +|FUNC|dcngettext| +|FUNC|dgettext| +|FUNC|dlinfo| +|FUNC|dngettext| +|FUNC|eaccess| +|FUNC|ecvt| +|FUNC|encrypt| +|FUNC|endspent| +|FUNC|endusershell| +|FUNC|endutxent| +|FUNC|ether_hostton| +|FUNC|ether_line| +|FUNC|ether_ntohost| +|FUNC|euidaccess| +|FUNC|exp10| +|FUNC|exp10f| +|FUNC|exp10l| +|FUNC|explicit_bzero| +|FUNC|fanotify_init| +|FUNC|fanotify_mark| +|FUNC|fcvt| +|FUNC|fgetgrent| +|FUNC|fgetpwent| +|FUNC|fgetspent| +|FUNC|fgetwc_unlocked| +|FUNC|fgetws_unlocked| +|FUNC|finish_install_ohos_malloc_hooks| +|FUNC|fmtmsg| +|FUNC|fopencookie| +|FUNC|fputwc_unlocked| +|FUNC|fputws_unlocked| +|FUNC|gcvt| +|FUNC|get_current_dir_name| +|FUNC|getdate| +|FUNC|getdents64| +|FUNC|gethostid| +|FUNC|getpass| +|FUNC|getservbyname_r| +|FUNC|getservbyport_r| +|FUNC|getspent| +|FUNC|getspnam| +|FUNC|getspnam_r| +|FUNC|gettext| +|FUNC|getusershell| +|FUNC|getutid| +|FUNC|getutline| +|FUNC|getutxent| +|FUNC|getutxid| +|FUNC|getutxline| +|FUNC|getw| +|FUNC|getwc_unlocked| +|FUNC|getwchar_unlocked| +|FUNC|glob64| +|FUNC|globfree64| +|FUNC|init_malloc_hook_shared_library| +|FUNC|isastream| +|FUNC|l64a| +|FUNC|lchmod| +|FUNC|lckpwdf| +|FUNC|lio_listio| +|FUNC|lio_listio64| +|FUNC|load_malloc_hook_shared_library| +|FUNC|log_print| +|FUNC|membarrier| +|FUNC|mq_close| +|FUNC|mq_getattr| +|FUNC|mq_notify| +|FUNC|mq_open| +|FUNC|mq_receive| +|FUNC|mq_send| +|FUNC|mq_setattr| +|FUNC|mq_timedreceive| +|FUNC|mq_timedsend| +|FUNC|mq_unlink| +|FUNC|name_to_handle_at| +|FUNC|ngettext| +|FUNC|ohos_malloc_hook_init_function| +|FUNC|open_by_handle_at| +|FUNC|pivot_root| +|FUNC|posix_close| +|FUNC|posix_spawn_file_actions_addchdir_np| +|FUNC|posix_spawn_file_actions_addfchdir_np| +|FUNC|pow10| +|FUNC|pow10f| +|FUNC|pow10l| +|FUNC|pthread_cancel| +|FUNC|pthread_getaffinity_np| +|FUNC|pthread_getattr_default_np| +|FUNC|pthread_getconcurrency| +|FUNC|pthread_mutex_consistent| +|FUNC|pthread_mutex_getprioceiling| +|FUNC|pthread_mutex_setprioceiling| +|FUNC|pthread_mutexattr_getrobust| +|FUNC|pthread_mutexattr_setrobust| +|FUNC|pthread_setaffinity_np| +|FUNC|pthread_setattr_default_np| +|FUNC|pthread_setcancelstate| +|FUNC|pthread_setcanceltype| +|FUNC|pthread_setconcurrency| +|FUNC|pthread_testcancel| +|FUNC|pthread_timedjoin_np| +|FUNC|pthread_tryjoin_np| +|FUNC|putgrent| +|FUNC|putpwent| +|FUNC|putspent| +|FUNC|pututxline| +|FUNC|putwc_unlocked| +|FUNC|putwchar_unlocked| +|FUNC|remap_file_pages| +|FUNC|rindex| +|FUNC|secure_getenv| +|FUNC|setkey| +|FUNC|setspent| +|FUNC|setusershell| +|FUNC|setutxent| +|FUNC|shm_open| +|FUNC|shm_unlink| +|FUNC|sigandset| +|FUNC|sigisemptyset| +|FUNC|sigorset| +|FUNC|sockatmark| +|FUNC|stime| +|FUNC|strfmon| +|FUNC|strfmon_l| +|FUNC|strverscmp| +|FUNC|textdomain| +|FUNC|ualarm| +|FUNC|ulckpwdf| +|FUNC|ulimit| +|FUNC|updwtmp| +|FUNC|updwtmpx| +|FUNC|utmpxname| +|FUNC|versionsort| +|FUNC|versionsort64| +|FUNC|vhangup| +|FUNC|wordexp| +|FUNC|wordfree| diff --git a/website/docs/extras/en/application-dev/reference/native-lib/third_party_libc/musl.md b/website/docs/extras/en/application-dev/reference/native-lib/third_party_libc/musl.md new file mode 100644 index 0000000000000000000000000000000000000000..b3015ef10bfa58c652b0ac7c80a8e7b284338777 --- /dev/null +++ b/website/docs/extras/en/application-dev/reference/native-lib/third_party_libc/musl.md @@ -0,0 +1,83 @@ +--- +title: "musl" +prepermalink: /extras/82741903008850b1d5d02f352afb6c46/ +permalink: /extras/82741903008850b1d5d02f352afb6c46/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/reference/native-lib/third_party_libc/musl.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [musl] +--- +# Standard Libraries Supported by Native APIs + + + +## Introduction + + + +**Table 1** Standard libraries supported by OpenHarmony + +| Library | Description | +| :-------- | :----------------------------------------------------------- | +| C standard library | C11 standard library implemented by [libc, libm, and libdl](https://en.cppreference.com/w/c/header). | +| C++ standard library ([libc++](https://libcxx.llvm.org/))| An implementation of the C++ standard library. | +| [OpenSL ES](https://www.khronos.org/registry/OpenSL-ES/)| An embedded cross-platform audio processing library.| +| [zlib](https://zlib.net/) | A general data compression library implemented in C/C++.| + +## C Standard Library + + + +C11 standard library implemented by [libc, libm, and libdl](https://en.cppreference.com/w/c/header). + +libc: provides thread-related functions and a majority of standard functions. + +libm: provides basic mathematical functions. + +libdl: provides functions related to dynamic linking, such as dlopen. + +**Version** + +1.2.0 + +**Capabilities** + +C standard library includes a set of header files in accordance with standard C and provides common functions, such as the functions related to input/output (I/O) and string control. + +**musl** + +[Native API Symbols Not Exported](/extras/8e912c88e233267d1f6f9c92a790cda8/) + +## C++ Standard Library + + + +[libc++](https://libcxx.llvm.org/) is an implementation of the C++ standard library. + +**Version** + +10.0.1 + +**Capabilities** + +The C++11 and C++14 standards are supported, and the C++17 and C++20 standards are on the way. + +## OpenSL ES + + + +[OpenSL ES](https://www.khronos.org/registry/OpenSL-ES/) is an embedded cross-platform audio processing library. + + + +## zlib + + + +[zlib](https://zlib.net/) is a general data compression library implemented in C/C++. diff --git a/website/docs/extras/en/application-dev/security/Readme-EN.md b/website/docs/extras/en/application-dev/security/Readme-EN.md new file mode 100644 index 0000000000000000000000000000000000000000..c8e0e76092c9ecd45f6b5127cacfd6e231ffd61a --- /dev/null +++ b/website/docs/extras/en/application-dev/security/Readme-EN.md @@ -0,0 +1,22 @@ +--- +title: "Readme-EN" +prepermalink: /extras/f49961f963597b8b33da99dbbc96c4fe/ +permalink: /extras/f49961f963597b8b33da99dbbc96c4fe/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/security/Readme-EN.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [Readme-EN] +--- +# Security + +- User Authentication + - [User Authentication Overview](/pages/en/app/application/Development/Basic%20Functions/Security/User%20Authentication/User%20Authentication%20Overview) + - [User Authentication Development](/pages/en/app/application/Development/Basic%20Functions/Security/User%20Authentication/User%20Authentication%20Development) +- hapsigner + - [hapsigner Guide](/pages/en/app/application/Development/Basic%20Functions/Security/hapsigner/hapsigner%20Guide) \ No newline at end of file diff --git a/website/docs/extras/en/application-dev/ui/Readme-CN.md b/website/docs/extras/en/application-dev/ui/Readme-CN.md new file mode 100644 index 0000000000000000000000000000000000000000..8c0a7a64b3e097641035b4b2b1dab814a6afeac0 --- /dev/null +++ b/website/docs/extras/en/application-dev/ui/Readme-CN.md @@ -0,0 +1,132 @@ +--- +title: "Readme-CN" +prepermalink: /extras/0bf107e24388d69289fa30a7f1f4fce2/ +permalink: /extras/0bf107e24388d69289fa30a7f1f4fce2/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/ui/Readme-CN.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [Readme-CN] +--- +# UI + +- [ArkUI Overview](/pages/en/app/application/Development/UI/ArkUI%20Overview) +- JavaScript-based Web-like Development Paradigm + - [Overview](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Overview) + - Framework + - [File Organization](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Framework/File%20Organization) + - ["js" Tag](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Framework/%20js%20%20Tag) + - [app.js](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Framework/app.js) + - Syntax + - [HML](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Framework/Syntax/HML) + - [CSS](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Framework/Syntax/CSS) + - [JavaScript](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Framework/Syntax/JavaScript) + - [Lifecycle](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Framework/Lifecycle) + - [Resource Limitations and Access](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Framework/Resource%20Limitations%20and%20Access) + - [Multi-Language Capability](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Framework/Multi-Language%20Capability) + - Building the UI + - [Component Overview](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Building%20the%20UI/Component%20Overview) + - Building the Layout + - [Layout Description](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Building%20the%20UI/Building%20the%20Layout/Layout%20Description) + - [Adding Title and Paragraph Text](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Building%20the%20UI/Building%20the%20Layout/Adding%20Title%20and%20Paragraph%20Text) + - [Adding an Image](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Building%20the%20UI/Building%20the%20Layout/Adding%20an%20Image) + - [Adding a Comment](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Building%20the%20UI/Building%20the%20Layout/Adding%20a%20Comment) + - [Adding a Container](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Building%20the%20UI/Building%20the%20Layout/Adding%20a%20Container) + - [Adding Interactions](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Building%20the%20UI/Adding%20Interactions) + - [Developing Animations](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Building%20the%20UI/Developing%20Animations) + - [Defining Events](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Building%20the%20UI/Defining%20Events) + - [Defining Page Routes](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Building%20the%20UI/Defining%20Page%20Routes) + - Common Component Development Guidelines + - [<text> Development](/extras/99e5841e65138d840158f6db79f9a82d/) + - [<input> Development](/extras/d9c1ad400ac43ce056c56ae004780b64/) + - [<button> Development](/extras/c26625fb2ce7815fd08c2aab247111f4/) + - [<list> Development](/extras/0dfc6b0664f6e334a81bfd9ccf6f51c6/) + - [<picker> Development](/extras/951bb17387966bf77e6bebed8adf4274/) + - [<dialog> Development](/extras/f78fdc6f879924b1b1b9566e48913731/) + - [<form> Development](/extras/2e5bc8e1ddc170355c59c569c9e7e99e/) + - [<stepper> Development](/extras/9b90423f489453dd8e1312bc6904c1af/) + - [<tabs> Development](/extras/6280763f9b6ef60950030fbcc8673fa9/) + - [<image> Development](/extras/874a020d7013a89a35806e100dc7e5f3/) + - Animation Development Guidelines + - CSS Animation + - [Defining Attribute Style Animations](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Common%20Component%20Development%20Guidelines/Animation%20Development%20Guidelines/CSS%20Animation/Defining%20Attribute%20Style%20Animations) + - [Defining Animations with the transform Attribute](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Common%20Component%20Development%20Guidelines/Animation%20Development%20Guidelines/CSS%20Animation/Defining%20Animations%20with%20the%20transform%20Attribute) + - [Defining Animations with the background-position Attribute](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Common%20Component%20Development%20Guidelines/Animation%20Development%20Guidelines/CSS%20Animation/Defining%20Animations%20with%20the%20background-position%20Attribute) + - [Defining Animations for SVG Components](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Common%20Component%20Development%20Guidelines/Animation%20Development%20Guidelines/CSS%20Animation/Defining%20Animations%20for%20SVG%20Components) + - JS Animation + - [Component Animation](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Common%20Component%20Development%20Guidelines/Animation%20Development%20Guidelines/JS%20Animation/Component%20Animation) + - Interpolator Animation + - [Animation Effect](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Common%20Component%20Development%20Guidelines/Animation%20Development%20Guidelines/JS%20Animation/Interpolator%20Animation/Animation%20Effect) + - [Animation Frame](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Common%20Component%20Development%20Guidelines/Animation%20Development%20Guidelines/JS%20Animation/Interpolator%20Animation/Animation%20Frame) + - [Custom Components](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Custom%20Components) +- TypeScript-based Declarative Development Paradigm + - [Overview](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Overview) + - Framework Overview + - File Organization + - [Directory Structure](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Framework%20Overview/File%20Organization/Directory%20Structure) + - [Rules for Accessing Application Code Files](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Framework%20Overview/File%20Organization/Rules%20for%20Accessing%20Application%20Code%20Files) + - ["js" Tag](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Framework%20Overview/%20js%20%20Tag) + - Resource Access + - [Accessing Application Resources](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Framework%20Overview/Resource%20Access/Accessing%20Application%20Resources) + - [Accessing System Resources](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Framework%20Overview/Resource%20Access/Accessing%20System%20Resources) + - [Media Resource Types](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Framework%20Overview/Resource%20Access/Media%20Resource%20Types) + - [Pixel Units](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Framework%20Overview/Pixel%20Units) + - [Types](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Framework%20Overview/Types) + - Declarative Syntax + - [Overview](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/Overview) + - General UI Description Specifications + - [Basic Concepts](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/General%20UI%20Description%20Specifications/Basic%20Concepts) + - Declarative UI Description Specifications + - [Configuration Without Parameters](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/General%20UI%20Description%20Specifications/Declarative%20UI%20Description%20Specifications/Parameterless%20Configuration) + - [Configuration with Mandatory Parameters](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/General%20UI%20Description%20Specifications/Declarative%20UI%20Description%20Specifications/Configuration%20with%20Mandatory%20Parameters) + - [Attribute Configuration](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/General%20UI%20Description%20Specifications/Declarative%20UI%20Description%20Specifications/Attribution%20Configuration) + - [Event Configuration](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/General%20UI%20Description%20Specifications/Declarative%20UI%20Description%20Specifications/Event%20Configuration) + - [Child Component Configuration](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/General%20UI%20Description%20Specifications/Declarative%20UI%20Description%20Specifications/Child%20Component%20Configuration) + - Componentization + - [@Component](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/General%20UI%20Description%20Specifications/Componentization/Component) + - [@Entry](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/General%20UI%20Description%20Specifications/Componentization/Entry) + - [@Preview](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/General%20UI%20Description%20Specifications/Componentization/Preview) + - [@Builder](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/General%20UI%20Description%20Specifications/Componentization/Builder) + - [@Extend](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/General%20UI%20Description%20Specifications/Componentization/Extend) + - [@CustomDialog](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/General%20UI%20Description%20Specifications/Componentization/CustomDialog) + - [@Styles](/extras/6cb159864bd245203e97dc09d07913f8/) + - About UI State Management + - [Basic Concepts](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20UI%20State%20Management/Basic%20Concepts) + - Managing Component States + - [@State](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20UI%20State%20Management/Managing%20Component%20States/State) + - [@Prop](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20UI%20State%20Management/Managing%20Component%20States/Prop) + - [@Link](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20UI%20State%20Management/Managing%20Component%20States/Link) + - Managing Application States + - [AppStorage](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20UI%20State%20Management/Managing%20Application%20States/AppStorage) + - [PersistentStorage](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20UI%20State%20Management/Managing%20Application%20States/PersistentStorage) + - [Environment](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20UI%20State%20Management/Managing%20Application%20States/Environment) + - Managing Other States + - [@Observed and @ObjectLink](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20UI%20State%20Management/Managing%20Other%20States/observed%20and%20objectLink) + - [@Consume and @Provide](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20UI%20State%20Management/Managing%20Other%20States/Consume%20and%20Provide) + - [@Watch](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20UI%20State%20Management/Managing%20Other%20States/Watch) + - About Rendering Control Syntax + - [if/else](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20Rendering%20Control%20Syntax/if%20else) + - [ForEach](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20Rendering%20Control%20Syntax/ForEach) + - [LazyForEach](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20Rendering%20Control%20Syntax/LazyForEach) + - About @Component + - [build Function](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20Component/build%20Function) + - [Initialization of Custom Components' Member Variables](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20Component/Custom%20Component%20Initialization) + - [Custom Component Lifecycle Callbacks](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20Component/Custom%20Component%20Lifecycle%20Callbacks) + - [Component Creation and Re-initialization](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20Component/Example%20%20Component%20Creation%20and%20Re-Initialization) + - [About Syntactic Sugar](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/Syntactic%20Sugar) + - Common Component Development Guidelines + - [<web> Development](/extras/2b20680728bf092271588027fd37cf44/) + - Experiencing the Declarative UI + - [Creating a Declarative UI Project](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Experiencing%20the%20Declarative%20UI/Creating%20a%20Declarative%20UI%20Project) + - [Getting to Know Components](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Experiencing%20the%20Declarative%20UI/Getting%20to%20Know%20Components) + - [Creating a Simple Page](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Experiencing%20the%20Declarative%20UI/Creating%20a%20Simple%20Page) + - Defining Page Layout and Connection + - [Building a Food Data Model](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Defining%20Page%20Layout%20and%20Connection/Building%20a%20Food%20Data%20Model) + - [Building a Food Category List Layout](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Defining%20Page%20Layout%20and%20Connection/Building%20a%20Food%20Category%20List%20Layout) + - [Building a Food Category Grid Layout](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Defining%20Page%20Layout%20and%20Connection/Building%20a%20Food%20Category%20Grid%20Layout) + - [Implementing Page Redirection and Data Transmission](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Defining%20Page%20Layout%20and%20Connection/Implementing%20Page%20Redirection%20and%20Data%20Transmission) diff --git a/website/docs/extras/en/application-dev/ui/ts-component-based-styles.md b/website/docs/extras/en/application-dev/ui/ts-component-based-styles.md new file mode 100644 index 0000000000000000000000000000000000000000..c5eb65c31dd5a89ce92a9fa191b605a0bcf40966 --- /dev/null +++ b/website/docs/extras/en/application-dev/ui/ts-component-based-styles.md @@ -0,0 +1,91 @@ +--- +title: "ts-component-based-styles" +prepermalink: /extras/6cb159864bd245203e97dc09d07913f8/ +permalink: /extras/6cb159864bd245203e97dc09d07913f8/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/ui/ts-component-based-styles.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [ts-component-based-styles] +--- +# @Styles + + +The @Styles decorator adds new attribute functions to basic components, such as <Text>, <Column>, and <Button>. Currently, @Styles supports only universal attributes. You can use the @Styles decorator to quickly define and reuse the custom styles of a component. + + +@Styles can be defined inside or outside a component. When it is defined outside a component, the keyword function must be included. + + + +``` +@Styles function globalFancy() { + .backgroundColor(Color.Red) +} + +@Entry +@Component +struct FancyUse { + @Styles componentFancy() { + .backgroundColor(Color.Blue) + } + build() { + Column({ space: 10 }) { + Text("Fancy") + .globalFancy() + .width(100) + .height(100) + .fontSize(30) + Text("Fancy") + .componentFancy() + .width(100) + .height(100) + .fontSize(30) + } + } +} +``` + + +@Styles can also be used inside the StateStyles attribute to assign state-specific attributes to components. + + +In StateStyles, styles defined outside the component can be directly called. However, the keyword this must be used to call styles defined in the component. + + + +``` +@Styles function globalFancy() { + .width(100) + .height(100) +} + +@Entry +@Component +struct FancyUse { + @Styles function componentFancy() { + .width(50) + .height(50) + } + build() { + Row({ space: 10 }) { + Button() { + Text("Fancy") + } + .stateStyles({ + normal: { + .width(80) + .height(80) + }, + disabled: this.componentFancy, + pressed: globalFancy + }) + } + } +} +``` diff --git a/website/docs/extras/en/application-dev/ui/ui-js-component-tabs.md b/website/docs/extras/en/application-dev/ui/ui-js-component-tabs.md new file mode 100644 index 0000000000000000000000000000000000000000..dfa1d7ec8bf5002b6eb22359a44aa1b3969e7c04 --- /dev/null +++ b/website/docs/extras/en/application-dev/ui/ui-js-component-tabs.md @@ -0,0 +1,332 @@ +--- +title: "ui-js-component-tabs" +prepermalink: /extras/6280763f9b6ef60950030fbcc8673fa9/ +permalink: /extras/6280763f9b6ef60950030fbcc8673fa9/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/ui/ui-js-component-tabs.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [ui-js-component-tabs] +--- +# <tabs> Development + + +The <tabs> component is a common UI component for navigation. It allows quick access to different functions of an app. For details, see [tabs](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/tabs). + + +## Creating Tabs + +Create a <tabs> component in the .hml file under pages/index. + + +``` + +
+ + + item1 + item2 + + +
+ content1 +
+
+ content2 +
+
+
+
+``` + + +``` +/* xxx.css */ +.container { + flex-direction: column; + justify-content: center; + align-items: center; + background-color: #F1F3F5; +} +.text{ + width: 100%; + height: 100%; + justify-content: center; + align-items: center; +} +``` + +![en-us_image_0000001223287676](../../../../images/en/application-dev/ui/figures/e969d0184df230713dfa48acb30b3358.gif) + + +## Setting the Tabs Orientation + +By default, the active tab of a <tabs> component is the one with the specified index. To show the <tabs> vertically, set the vertical attribute to true. + + +``` + +
+ + + item1 + item2 + + +
+ +
+
+ +
+
+
+
+``` + +![en-us_image_0000001222967756](../../../../images/en/application-dev/ui/figures/fa50206cdc924f553faa69fd777d949d.gif) + +Set the mode attribute to enable the child components of the to be evenly distributed. Set the scrollable attribute to disable scrolling of the . + + +``` + +
+ + + item1 + item2 + + +
+ +
+
+ +
+
+
+
+``` + +![en-us_image_0000001267647857](../../../../images/en/application-dev/ui/figures/bb31396c0748e4b465ee0d8ffbe6a424.gif) + + +## Setting the Style + + Set the background color, border, and tab-content layout of the <tabs> component. + +``` + +
+ + + item1 + item2 + + +
+ content1 +
+
+ content2 +
+
+
+
+``` + + +``` +/* xxx.css */ +.container { + flex-direction: column; + justify-content: flex-start; + align-items: center; + background-color:#F1F3F5; +} +.tabs{ + margin-top: 20px; + border: 1px solid #2262ef; + width: 99%; + padding: 10px; +} +.tabBar{ + width: 100%; + border: 1px solid #78abec; +} +.tabContent{ + width: 100%; + margin-top: 10px; + height: 300px; + color: blue; + justify-content: center; align-items: center; +} +``` + +![en-us_image_0000001267767857](../../../../images/en/application-dev/ui/figures/f1db010f3c619beb93953da23bc05351.gif) + + +## Displaying the Tab Index + +Add the change event for the <tabs> component to display the index of the current tab after tab switching. + + +``` + +
+ + + item1 + item2 + + +
+ +
+
+ +
+
+
+
+``` + + +``` +/* index.js */ +import prompt from '@system.prompt'; +export default { + tabChange(e){ + prompt.showToast({ + message: "Tab index: " + e.index + }) + } +} +``` + +![en-us_image_0000001222807772](../../../../images/en/application-dev/ui/figures/c8e0db39b24e7187c167a4a85de88ee0.gif) + + +> ![icon-note.gif](../../../../images/en/application-dev/ui/public_sys-resources/ae89e6a5f31e3d03603c1d114c8400cf.gif) **NOTE**: +> - A <tabs> can wrap at most one [](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/tab-bar) and at most one [](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/tab-content). + + +## Example Scenario + +In this example, you can switch between tabs and the active tab has the title text in red with an underline below. + +Use the <tabs>, , and components to implement tab switching. Then define the arrays and attributes. Add the change event to change the attribute values in the arrays so that the active tab has a different font color and an underline. + + +``` + +
+ + +
+
+ +
+
+ +
+
+ +
+
+
+ +
+ {{$item.title}} +
+
+
+
+
+
+``` + + +``` +/* xxx.css */ +.container{ +background-color:#F1F3F5; +} +.tab_bar { + width: 100%; +} +.tab_item { + flex-direction: column; + align-items: center; +} +.tab_item text { + font-size: 32px; +} +.item-container { + justify-content: center; + flex-direction: column; +} +.underline-show { + height: 2px; + width: 160px; + background-color: #FF4500; + margin-top: 7.5px; +} +.underline-hide { + height: 2px; + margin-top: 7.5px; + width: 160px; +} +``` + + +``` +/* index.js */ +import prompt from '@system.prompt'; +export default { + data() { + return { + datas: { + color_normal: '#878787', + color_active: '#ff4500', + show: true, + list: [{ + i: 0, + color: '#ff4500', + show: true, + title: 'List1' + }, { + i: 1, + color: '#878787', + show: false, + title: 'List2' + }, { + i: 2, + color: '#878787', + show: false, + title: 'List3' + }] + } + } + }, + changeTabactive (e) { + for (let i = 0; i < this.datas.list.length; i++) { + let element = this.datas.list[i]; + element.show = false; + element.color = this.datas.color_normal; + if (i === e.index) { + element.show = true; + element.color = this.datas.color_active; + } + } + } +} +``` + +![en-us_image_0000001267607885](../../../../images/en/application-dev/ui/figures/39c5997c21c05f31c556618e6d89e2c7.gif) diff --git a/website/docs/extras/en/application-dev/ui/ui-js-components-button.md b/website/docs/extras/en/application-dev/ui/ui-js-components-button.md new file mode 100644 index 0000000000000000000000000000000000000000..dae46e3ceedc280238ae39be5efc1443e295c1ee --- /dev/null +++ b/website/docs/extras/en/application-dev/ui/ui-js-components-button.md @@ -0,0 +1,297 @@ +--- +title: "ui-js-components-button" +prepermalink: /extras/c26625fb2ce7815fd08c2aab247111f4/ +permalink: /extras/c26625fb2ce7815fd08c2aab247111f4/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/ui/ui-js-components-button.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [ui-js-components-button] +--- +# <button> Development + + +The<button>component can be used to set a capsule, circle, text, arc, or download button. For details, see [button](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/button). + + +## Creating a <button> Component + +Create a <button> component in the .hml file under pages/index. + + +``` + +
+ +
+``` + + +``` +/* xxx.css */ +.container { + flex-direction: column; + justify-content: center; + align-items: center; + background-color: #F1F3F5; +} +``` + +![en-us_image_0000001267887821](../../../../images/en/application-dev/ui/figures/504d7fe4b033445918d36bd40a1f8990.png) + + +## Setting the Button Type + +Set the type attribute of the <input> component to button, date, or any of the supported values. + +``` + +
+ + +
+``` + +``` +/* xxx.css */ +.container { + background-color: #F1F3F5; + flex-direction: column; + align-items: center; + justify-content: center; +} +.circle { + font-size: 120px; + background-color: blue; + radius: 72px; +} +.text { + margin-top: 30px; + text-color: white; + font-size: 30px; + font-style: normal; + background-color: blue; + width: 50%; + height: 100px; +} +``` + + +![en-us_image_0000001222967744](../../../../images/en/application-dev/ui/figures/165765c259cbcabb30e6b10b32b75004.png) + + +> ![icon-note.gif](../../../../images/en/application-dev/ui/public_sys-resources/ae89e6a5f31e3d03603c1d114c8400cf.gif) **NOTE**: +> - For capsule buttons, border-related styles are not supported. +> +> - For circle buttons, text-related styles are not supported. +> +> - For text buttons, the text size is adaptive, and radius, width, and height cannot be set. The background-color style is not supported when the background is completely transparent. +> +> - If the icon used by the<button>component is from the cloud, you must declare the ohos.permission.INTERNET permission in the config.json file under the resources folder. + + +Sample code for declaring the ohos.permission.INTERNET permission in the config.json file under the resources folder: + +``` + +"module": { + "reqPermissions": [{ + "name": "ohos.permission.INTERNET" + }], +} +``` + + +## Showing the Download Progress + +Add the progress method to the<button>component to display the download progress in real time. + + +``` + +
+ +
+``` + + +``` +/* xxx.css */ +.container { + background-color: #F1F3F5; + flex-direction: column; + align-items: center; + justify-content: center; +} +.download { + width: 280px; + text-color: white; + background-color: #007dff; +} +``` + + +``` +// xxx.js +import prompt from '@system.prompt'; +export default { + data: { + percent: 0, + downloadText: "Download", + isPaused: true, + intervalId : null, + }, + star(){ + this.intervalId = setInterval(()=>{ + if(this.percent <100){ + this.percent += 1; + this.downloadText = this.percent+ "%"; + } else{ + prompt.showToast({ + message: "Download succeeded." + }) + this.paused() + this.downloadText = "Download"; + this.percent = 0; + this.isPaused = true; + } + },100) + }, + paused(){ + clearInterval(this.intervalId); + this.intervalId = null; + }, + setProgress(e) { + if(this.isPaused){ + prompt.showToast({ + message: "Download started" + }) + this.star(); + this.isPaused = false; + }else{ + prompt.showToast({ + message: "Paused." + }) + this.paused(); + this.isPaused = true; + } + } +} +``` + +![en-us_image_0000001223287652](../../../../images/en/application-dev/ui/figures/dbaac143afa3c4547110e7f24c0a22d3.gif) + +> ![icon-note.gif](../../../../images/en/application-dev/ui/public_sys-resources/ae89e6a5f31e3d03603c1d114c8400cf.gif) **NOTE**: +> +> The setProgress method supports only buttons of the download type. + + +## Example Scenario + +Switch between the button types for different types of text. + +``` + +
+
+ +
+
+
+ + +
+
+
+``` + +``` +/* xxx.css */ +.container { + flex-direction: column; + align-items: center; + background-color: #F1F3F5; +} +.input-item { + margin-bottom: 80px; + flex-direction: column; +} +.doc-row { + justify-content: center; + margin-left: 30px; + margin-right: 30px; + justify-content: space-around; +} +.input-text { + height: 80px; + line-height: 80px; + padding-left: 30px; + padding-right: 30px; + margin-left: 30px; + margin-right: 30px; + margin-top:100px; + border: 3px solid; + border-color: #999999; + font-size: 30px; + background-color: #ffffff; + font-weight: 400; +} +.select-button { + width: 35%; + text-align: center; + height: 70px; + padding-top: 10px; + padding-bottom: 10px; + margin-top: 30px; + font-size: 30px; + color: #ffffff; +} +.color-3 { + background-color: #0598db;; +} +``` + +``` +// xxx.js +export default { + data: { + myflex: '', + myholder: 'Enter text.', + myname: '', + mystyle1: "#ffffff", + mystyle2: "#ff0000", + mytype: 'text', + myvalue: '', + }, + onInit() { + }, + changetype3() { + this.myflex = ''; + this.myholder = 'Enter text.'; + this.myname = ''; + this.mystyle1 = "#ffffff"; + this.mystyle2 = "#FF0000"; + this.mytype = 'text'; + this.myvalue = ''; + }, + changetype4() { + this.myflex = ''; + this.myholder = 'Enter a date.'; + this.myname = ''; + this.mystyle1 = "#ffffff"; + this.mystyle2 = "#FF0000"; + this.mytype = 'date'; + this.myvalue = ''; + }, +} +``` + + +![en-us_image_0000001222967740](../../../../images/en/application-dev/ui/figures/09af76b567f4627d23cf7b7556a60f81.gif) diff --git a/website/docs/extras/en/application-dev/ui/ui-js-components-dialog.md b/website/docs/extras/en/application-dev/ui/ui-js-components-dialog.md new file mode 100644 index 0000000000000000000000000000000000000000..ee451317e273cd5d5e062e5ca43d4bba7d9a046e --- /dev/null +++ b/website/docs/extras/en/application-dev/ui/ui-js-components-dialog.md @@ -0,0 +1,321 @@ +--- +title: "ui-js-components-dialog" +prepermalink: /extras/f78fdc6f879924b1b1b9566e48913731/ +permalink: /extras/f78fdc6f879924b1b1b9566e48913731/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/ui/ui-js-components-dialog.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [ui-js-components-dialog] +--- +# <dialog> Development + + +The <dialog> component is custom pop-up container for showing critical information or calling for an action. For details, see [dialog](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/dialog). + + +## Creating a <dialog> Component + + Create a <dialog> component in the .hml file under pages/index and add <button> components to trigger the <dialog>. The <dialog> component supports only the width, height, margin, margin-[left|top|right|bottom], and margin-[start|end] styles. + +``` + +
+
+ this is a dialog +
+
+ +
+``` + + +``` +/* xxx.css */ +.doc-page { + flex-direction: column; + align-items: center; + justify-content: center; + background-color: #F1F3F5; +} +.dialogClass{ + width: 80%; + height: 250px; + margin-start: 1%; +} +.content{ + width: 100%; + height: 250px; + justify-content: center; + background-color: #e8ebec; + border-radius: 20px; +} +text{ + width: 100%; + height: 100%; + text-align: center; +} +button{ + width: 70%; + height: 60px; +} +``` + + +``` +/* xxx.js */ +export default { + //Touch to open the dialog box. + openDialog(){ + this.$element('dialogId').show() + }, +} +``` + +![en-us_image_0000001267767893](../../../../images/en/application-dev/ui/figures/50b747d68432c4acb763779d2fa2a127.gif) + + +## Setting Dialog Box Response + +Add a cancel event that is triggered when a user touches a non-dialog area to cancel the pop-up dialog box. Add the show and close methods to display and close the dialog box, respectively. + +``` + +
+ +
+ dialog + +
+
+ +
+``` + +``` +/* xxx.css */ +.doc-page { + flex-direction: column; + align-items: center; + justify-content: center; + background-color: #F1F3F5; +} +.dialogClass{ + width: 80%; + height: 300px; + margin-start: 1%; +} +.dialogDiv{ + width: 100%; + flex-direction: column; + justify-content: center; + align-self: center; +} +text{ + height: 100px; + align-self: center; +} +button{ + align-self: center; + margin-top: 20px; + width: 60%; + height: 80px; +} +``` + +``` +/* xxx.js */ +import prompt from '@system.prompt'; +export default { + openDialog(){ + this.$element('dialogId').show() + }, + confirmClick(e) { + this.$element('dialogId').close() + prompt.showToast({ + message: 'Confirmed.' + }) + }, +} +``` + + +![en-us_image_0000001223287720](../../../../images/en/application-dev/ui/figures/e41e14fee70b8d8e448ac1f25d9b7426.gif) + + +> ![icon-note.gif](../../../../images/en/application-dev/ui/public_sys-resources/ae89e6a5f31e3d03603c1d114c8400cf.gif) **NOTE**: +> - This component supports only one child component. +> +> - Attributes and styles of a <dialog> component cannot be dynamically updated. +> +> - The <dialog> component does not support the focusable and click-effect attributes. + + +## Example Scenario + + +Use the <dialog> component to implement a schedule. When the dialog box is open, use the [<textarea>](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/textarea) component to add an event and touch the OK button to obtain the current time and save the input text. The events in the calendar are displayed in a list. + +``` + +
+ + {{date}} events + +
+ +
+ + + +
+ {{date}} event + {{$item.schedule}} +
+
+
+ +
+
+ {{date}} + New event +
+ +
+ + +
+
+
+
+``` + +``` +/* xxx.css */ +.doc-page { + flex-direction: column; + background-color: #F1F3F5; +} +.btndiv { + width: 100%; + height: 200px; + flex-direction: column; + align-items: center; + justify-content: center; +} +.btn { + radius:60px; + font-size: 100px; + background-color: #1E90FF; +} +.schedulediv { + width: 100%; + height: 200px; + flex-direction: column; + justify-content: space-around; + padding-left: 55px; +} +.text1 { + color: #000000; + font-weight: bold; + font-size: 39px; +} +.text2 { + color: #a9a9a9; + font-size: 30px; +} +.dialogdiv { + flex-direction: column; + align-items: center; +} +.innertxt { + width: 320px; + height: 160px; + flex-direction: column; + align-items: center; + justify-content: space-around; +} +.text3 { + font-family: serif; + color: #1E90FF; + font-size: 38px; +} +.text4 { + color: #a9a9a9; + font-size: 33px; +} +.area { + width: 320px; + border-bottom: 1px solid #1E90FF; +} +.innerbtn { + width: 320px; + height: 120px; + justify-content: space-around; +} +.btntxt { + text-color: #1E90FF; +} +``` + +``` +/* xxx.js */ +var info = null; +import prompt from '@system.prompt'; +import router from '@system.router'; +export default { + data: { + curYear:'', + curMonth:'', + curDay:'', + date:'', + schedule:'', + schedulelist:[] + }, + onInit() { + // Obtain the current date. + var date = new Date(); + this.curYear = date.getFullYear(); + this.curMonth = date.getMonth() + 1; + this.curDay = date.getDate(); + this.date = this.curYear + '-' + this.curMonth + '-' + this.curDay; + this.schedulelist = [] + }, + addschedule(e) { + this.$element('datedialog').show() + }, + canceldialog(e) { + prompt.showToast({ + message: 'Event setting canceled.' + }) + }, + getschedule(e) { + info = e.value + }, + cancelschedule(e) { + this.$element('datedialog').close() + prompt.showToast({ + message: 'Event setting canceled.' + }) + }, +// Touch OK to save the data. + setschedule(e) { + if (e.text === '') { + this.schedule = info + } else { + this.schedule = info + var addItem = {schedule: this.schedule,} + this.schedulelist.push(addItem) + } + this.$element('datedialog').close() + } +} +``` + + +![en-us_image_0000001223127756](../../../../images/en/application-dev/ui/figures/b11151b171ba0ff1651a880f1cfa3c4f.gif) diff --git a/website/docs/extras/en/application-dev/ui/ui-js-components-form.md b/website/docs/extras/en/application-dev/ui/ui-js-components-form.md new file mode 100644 index 0000000000000000000000000000000000000000..4cb34f27ed4c29d8ebfab4b6aab7cf18f71507f3 --- /dev/null +++ b/website/docs/extras/en/application-dev/ui/ui-js-components-form.md @@ -0,0 +1,214 @@ +--- +title: "ui-js-components-form" +prepermalink: /extras/2e5bc8e1ddc170355c59c569c9e7e99e/ +permalink: /extras/2e5bc8e1ddc170355c59c569c9e7e99e/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/ui/ui-js-components-form.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [ui-js-components-form] +--- +# <form> Development + + +The <form> component allows the content in [<input>](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/input)components to be submitted and reset. For details, see [form](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/form). + + +> ![icon-note.gif](../../../../images/en/application-dev/ui/public_sys-resources/ae89e6a5f31e3d03603c1d114c8400cf.gif) **NOTE**: +> This component is supported since API version 6. + + +## Creating a <form> Component + + Create a <form> component in the .hml file under pages/index. + +``` + +
+
+
+
+``` + + +``` +/* xxx.css */ +.container { + flex-direction: column; + justify-content: center; + align-items: center; + background-color: #F1F3F5; +} +``` + +![en-us_image_0000001267887873](../../../../images/en/application-dev/ui/figures/a37ed11b2b9bf41bab731a4aa44643ec.png) + + +## Zooming In or Out on a Form + + To implement the zoom effect after a form is clicked, add the click-effect attribute to the <form> component. For values of click-effect, see [Universal Attributes](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Common/Universal%20Attributes). + +``` + +
+
+ +
+
+``` + + +## Setting the Form Style + + +Add the background-color and border attributes. + +``` +/* xxx.css */ +.container { + flex-direction: column; + align-items: center; + justify-content: center; + background-color: #F1F3F5; +} +.formClass{ + width: 80%; + padding: 10px; + border: 1px solid #c3d3e7; +} +``` + + +![en-us_image_0000001267607913](../../../../images/en/application-dev/ui/figures/749f9d642dfcad65ea6c001a574b5286.gif) + + +## Adding Response Events + + To submit or reset a form, add the submit and reset events. + +``` + +
+
+
+
+ + + + +
+
+ + +
+
+
+
+``` + + +``` +/* xxx.js */ +import prompt from '@system.prompt'; +export default{ + onSubmit(result) { + prompt.showToast({ + message: result.value.radioGroup + }) + }, + onReset() { + prompt.showToast({ + message: 'Reset All' + }) + } +} +``` + + +![en-us_image_0000001267767885](../../../../images/en/application-dev/ui/figures/c2b283c5fd1c9276a7a6d4a786736731.gif) + + +## Example Scenario + +Select an option and submit or reset the form data. + +Create [<input>](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/input) (en-us_topic_0000001173324647.xml) components, set their type attribute to checkbox and radio, and use the onsubmit and onreset events of the <form> component to submit and reset the form data. + + +``` + +
+
+ + Form + +
+ Select 1 or more options +
+ + + + +
+ + Select 1 option +
+ + + + +
+ + Text box + +
+ Submit + Reset +
+
+
+
+``` + + +``` +/* index.css */ +.container { + flex-direction:column; + align-items:center; + background-color:#F1F3F5; +} +.txt { + font-size:33px; + font-weight:bold; + color:darkgray; +} +label{ + font-size: 20px; +} +``` + + +``` +/* xxx.js */ +import prompt from '@system.prompt'; +export default { + formSubmit() { + prompt.showToast({ + message: 'Submitted.' + }) + }, + formReset() { + prompt.showToast({ + message: 'Reset.' + }) + } +} +``` + +![en-us_image_0000001222967788](../../../../images/en/application-dev/ui/figures/f423d2521389aa4777e6164cca2f8634.gif) diff --git a/website/docs/extras/en/application-dev/ui/ui-js-components-images.md b/website/docs/extras/en/application-dev/ui/ui-js-components-images.md new file mode 100644 index 0000000000000000000000000000000000000000..0648747ceb6891c566732ebdbf0b9ac7977be072 --- /dev/null +++ b/website/docs/extras/en/application-dev/ui/ui-js-components-images.md @@ -0,0 +1,215 @@ +--- +title: "ui-js-components-images" +prepermalink: /extras/874a020d7013a89a35806e100dc7e5f3/ +permalink: /extras/874a020d7013a89a35806e100dc7e5f3/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/ui/ui-js-components-images.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [ui-js-components-images] +--- +# <image> Development + + +The <image> component is used to render and display images. For details, see [image](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/image). + + +## Creating an <image> Component + + Create an <image> component in the .hml file under pages/index. + +``` + +
+ +
+``` + + +``` +/* xxx.css */ +.container { + flex-direction: column; + justify-content: center; + align-items: center; + background-color: #F1F3F5; +} +``` + +![en-us_image_0000001223127736](../../../../images/en/application-dev/ui/figures/5addb7181cbff0c63a0a217fc8bdb245.png) + + +## Setting the Image Style + +Set the width, height, and object-fit attributes to define the width, height, and scale type of an image. + +``` + +
+ +
+``` + +``` +/* xxx.css */ +.container { + flex-direction: column; + align-items: center; + justify-content: center; +background-color:#F1F3F5; +} +image{ + width: 80%; height: 500px; + border: 5px solid saddlebrown; + border-radius: 20px; + object-fit: contain; + match-text-direction:true; + +} +``` + + +![en-us_image_0000001222807796](../../../../images/en/application-dev/ui/figures/621465480d4f66854a4cc777bbee1b92.png) + + +## Loading Images + +When an image is successfully loaded, the complete event is triggered, and the loaded image is returned. If an exception occurs during image loading, the error event is triggered, and the image loading failure is printed. + + +``` + +
+
+ +
+
+ +
+
+``` + + +``` +/* xxx.css */ +.container{ + flex-direction: column; + justify-content: center; + align-self: center; + background-color: #F1F3F5; +} +.container div{ + margin-left: 10%; + width: 80%; + height: 300px; + margin-bottom: 40px; +} +``` + + +``` +/* index.js */ +import prompt from '@system.prompt'; +export default { + imageComplete(i,e){ + prompt.showToast({ + message: "Image "+i+"'s width"+ e.width+"----Image "+i+"'s height"+e.height, + duration: 3000, + }) + }, + imageError(i,e){ + setTimeout(()=>{ + prompt.showToast({ + message: "Failed to load image "+i+".", + duration: 3000, + }) + },3000) + } +} +``` + +![en-us_image_0000001267887865](../../../../images/en/application-dev/ui/figures/fcb6b68d2df33986c1cb6c50824c22e3.gif) + + +## Example Scenario + + In this example you touch and hold an image to gradually hide it. After the image is completely hidden, it will show in its original setting. Set a setInterval timer to change the image opacity at a specified interval so that it is hidden gradually. When the opacity changes to 0, the timer is cleared and the opacity is set to 1. + +``` + +
+
+
+ +
+
+ Touch and hold the image +
+
+
+``` + + +``` +/* xxx.css */ +.page-container { + flex-direction:column; + align-self: center; + justify-content: center; + background-color:#F1F3F5; + background-color: #F1F3F5; +} +.content{ + flex-direction:column; +} +.image-container { + width: 100%; + height: 300px; + align-items: center; + justify-content: center; +} +.text-container { + margin-top:50px; + width: 100%; + height: 60px; + flex-direction: row; + justify-content: space-between; +} +.testimage { + width: 100%; height: 400px; object-fit: scale-down; border-radius: 20px;} +``` + + +``` +/* index.js */ +import prompt from '@system.prompt'; +export default { + data: { + testuri: 'common/images/bg-tv.jpg', + imageopacity:1, + timer: null + }, + changeopacity: function () { + prompt.showToast({ + message: 'Touch and hold the image.' + }) + var opval = this.imageopacity * 20 + clearInterval(this.timer); + this.timer = setInterval(()=>{ + opval--; + this.imageopacity = opval / 20 + if (opval===0) { + clearInterval(this.timer) + this.imageopacity = 1 + } + },100); + } +} +``` + +![en-us_image_0000001267607905](../../../../images/en/application-dev/ui/figures/faf70833c5ebfc487a835addf28eff3a.gif) diff --git a/website/docs/extras/en/application-dev/ui/ui-js-components-input.md b/website/docs/extras/en/application-dev/ui/ui-js-components-input.md new file mode 100644 index 0000000000000000000000000000000000000000..a599dceec1bd2d32d3c9a403fb4b67efefbdad1c --- /dev/null +++ b/website/docs/extras/en/application-dev/ui/ui-js-components-input.md @@ -0,0 +1,339 @@ +--- +title: "ui-js-components-input" +prepermalink: /extras/d9c1ad400ac43ce056c56ae004780b64/ +permalink: /extras/d9c1ad400ac43ce056c56ae004780b64/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/ui/ui-js-components-input.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [ui-js-components-input] +--- +# Development + + +The component provides an interactive way to receive user input of various types, including date, checkbox, and button. For details, see [input](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/input). + + +## Creating an Component + +Create an component in the .hml file under pages/index. + + +``` + +
+ Please enter the content +
+``` + + +``` +/* xxx.css */ +.container { + flex-direction: column; + justify-content: center; + align-items: center; + background-color: #F1F3F5; +} +``` + +![en-us_image_0000001222807768](../../../../images/en/application-dev/ui/figures/f802f22ebded89bcc4d0ed6ec78177cd.png) + + +## Setting the Input Type + +Set the type attribute of the component to button, date, or any of the supported values. + + +``` + +
+
+ +
+ this is a dialog +
+
+ +
+
+ +
+
+ +
+
+``` + + +``` +/* xxx.css */ +.container { + align-items: center; + flex-direction: column; + justify-content: center; + background-color: #F1F3F5 ; +} +.div-button { + flex-direction: column; + align-items: center; +} +.dialogClass{ + width:80%; + height: 200px; +} +.button { + margin-top: 30px; + width: 50%; +} +.content{ + width: 90%; + height: 150px; + align-items: center; + justify-content: center; +} +.flex { + width: 80%; + margin-bottom:40px; +} +``` + + +``` +// xxx.js +export default { + btnclick(){ + this.$element('dialogId').show() + }, +} +``` + + +![en-us_image_0000001223287672](../../../../images/en/application-dev/ui/figures/470842de8e2c8a96ca6277b1f2852079.gif) + + +> ![icon-note.gif](../../../../images/en/application-dev/ui/public_sys-resources/ae89e6a5f31e3d03603c1d114c8400cf.gif) **NOTE**: +> - For wearables, the input type can only be button, radio, or checkbox. +> +> - The settings of checked take effect only when the input type is set to checkbox or radio. The default value of checked is false. + + +## Event Binding + + Add the search and translate events to the component. + +``` + +
+ + Enter text and then touch and hold what you've entered + + + +
+``` + + +``` +/* xxx.css */ +.content { + width: 100%; + flex-direction: column; + align-items: center; + justify-content: center; + background-color: #F1F3F5; +} +.input { + margin-top: 50px; + width: 60%; + placeholder-color: gray; +} +text{ + width:100%; + font-size:25px; + text-align:center; +} +``` + + +``` +// xxx.js +import prompt from '@system.prompt' +export default { + search(e){ + prompt.showToast({ + message: e.value, + duration: 3000, + }); + }, + translate(e){ + prompt.showToast({ + message: e.value, + duration: 3000, + }); + } +} +``` + +![en-us_image_0000001267647853](../../../../images/en/application-dev/ui/figures/2cb297fb9166beb9de9e4d20bfd498b1.gif) + + +## Setting the Input Error Message + +Add the showError method to the component to display an error message in the event of incorrect input. + + +``` + +
+ + + +
+``` + + +``` +/* xxx.css */ +.content { + width: 100%; + flex-direction: column; + align-items: center; + justify-content: center; + background-color: #F1F3F5; +} +.input { + width: 80%; + placeholder-color: gray; +} +.button { + width: 30%; + margin-top: 50px; +} +``` + + +``` +// xxx.js +import prompt from '@system.prompt' + export default { + data:{ + value:'', + }, + change(e){ + this.value = e.value; + prompt.showToast({ + message: "value: " + this.value, + duration: 3000, + }); + }, + buttonClick(e){ + if(this.value.length > 6){ + this.$element("input").showError({ error: 'Up to 6 characters are allowed.' }); + }else if(this.value.length == 0){ + this.$element("input").showError({ error:this.value + 'This field cannot be left empty.' }); + }else{ + prompt.showToast({ + message: "success " + }); + } + }, + } +``` + +![en-us_image_0000001223127708](../../../../images/en/application-dev/ui/figures/7942ddbbaf2bab110b4232c3b98f9676.gif) + +> ![icon-note.gif](../../../../images/en/application-dev/ui/public_sys-resources/ae89e6a5f31e3d03603c1d114c8400cf.gif) **NOTE**: +> - This method is available when the input type is set to text, email, date, time, number, or password. + + +## Example Scenario + + +Enter information by using the component of the type that suits your needs. + + + +``` + +
+
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+``` + + + +``` +/* xxx.css */ +.container { + flex-direction: column; + background-color: #F1F3F5; +} +.label-item { + align-items: center; + border-bottom-width: 1px;border-color: #dddddd; +} +.lab { + width: 400px;} +label { + padding: 30px; + font-size: 30px; + width: 320px; + font-family: serif; + color: #9370d8; + font-weight: bold; +} +.flex { + flex: 1; +} +.textareaPadding { + padding-left: 100px; +} +``` + + + +``` +// xxx.js +import prompt from '@system.prompt'; +export default { + data: { + }, + onInit() { + }, + btnclick(e) { + prompt.showToast({ + message:'Saved successfully!' + }) + } +} +``` + + +![en-us_image_0000001222807760](../../../../images/en/application-dev/ui/figures/68d7a509f7976ceee339a8c94194e53f.gif) diff --git a/website/docs/extras/en/application-dev/ui/ui-js-components-list.md b/website/docs/extras/en/application-dev/ui/ui-js-components-list.md new file mode 100644 index 0000000000000000000000000000000000000000..4dc77fa9ffa71f1435224b67bab6c804a620d770 --- /dev/null +++ b/website/docs/extras/en/application-dev/ui/ui-js-components-list.md @@ -0,0 +1,325 @@ +--- +title: "ui-js-components-list" +prepermalink: /extras/0dfc6b0664f6e334a81bfd9ccf6f51c6/ +permalink: /extras/0dfc6b0664f6e334a81bfd9ccf6f51c6/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/ui/ui-js-components-list.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [ui-js-components-list] +--- +# <list> Development + + +The <list> component provides a list container that presents a series of list items arranged in a column with the same width. Lists can be used for presenting the same type of data in a multiple and coherent row style. For details, see [list](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/list). + + +## Creating a <list> Component + +Create a <list> component in the .hml file under pages/index. + + +``` + +
+ + + + + +
+``` + + +``` +/* xxx.css */ +.container { + flex-direction: column; + align-items: center; + background-color: #F1F3F5; +} +.listItem{ + height: 20%; + background-color:#d2e0e0; + margin-top: 20px; +} +``` + +![en-us_image_0000001223287680](../../../../images/en/application-dev/ui/figures/b21a23154fda666b7ff478990484276b.png) + +> ![icon-note.gif](../../../../images/en/application-dev/ui/public_sys-resources/ae89e6a5f31e3d03603c1d114c8400cf.gif) **NOTE**: +> - <list-item-group> is a child component of the <list> component and is used to group items in a list. It can have a <list-item> nested inside, but not <list>. +> +> - <list-item> is a child component of the <list> component and is used to display items in a list. + + +## Adding a Scrollbar + +To display a scrollbar on the right side of the screen, set scrollbar to on. The side scrollbar can be used to scroll a long list or the screen up or down. + + +``` + +
+ + + + + + + + +
+``` + + +``` +/* index.css */ +.container { + flex-direction: column; + background-color: #F1F3F5; +} +.listItem{ + height: 20%; + background-color:#d2e0e0; + margin-top: 20px; +} +.listCss{ + height: 100%; + scrollbar-color: #8e8b8b; + scrollbar-width: 50px; +} +``` + +![en-us_image_0000001223287684](../../../../images/en/application-dev/ui/figures/015ec145ec44499d685fca9dc1258d0a.gif) + + +## Adding a Side Index Bar + +Set a custom indexer component to add an index bar at the right boundary of a list. By default, an alphabetical indexer is used. + + +``` + +
+ + + +
+``` + + +``` +/* index.css */ +.container{ + flex-direction: column; + background-color: #F1F3F5; + } +.listCss{ + height: 100%; + flex-direction: column; + columns: 1 +} +``` + +![en-us_image_0000001223127716](../../../../images/en/application-dev/ui/figures/668c0106ac6c054dc2fd8261ce34aa75.png) + +> ![icon-note.gif](../../../../images/en/application-dev/ui/public_sys-resources/ae89e6a5f31e3d03603c1d114c8400cf.gif) **NOTE**: +> - This indexer attribute is valid only when flex-direction is set to column and columns is set to 1. +> +> - You must include "\#" when using a customized indexer. + + +## Collapsing or Expanding a List + +To allow a <list> component to collapse and expand, add groupcollapse and groupexpand events. + + +``` + +
+ + + +
+ One---{{listgroup.value}} +
+
+ +
+ Primary---{{listgroup.value}} +
+
+
+
+
+``` + + +``` +/* index.css */ +.doc-page { + flex-direction: column; + background-color: #F1F3F5; +} +list-item{ +margin-top:30px; +} +.top-list-item { + width:100%; + background-color:#D4F2E7; +} +.item-group-child { + justify-content: center; + align-items: center; + width:100%; +} +``` + + +``` +// xxx.js +import prompt from '@system.prompt'; +export default { + data: { + direction: 'column', + list: [] + }, + onInit() { + this.list = [] + this.listAdd = [] + for (var i = 1; i <= 2; i++) { + var dataItem = { + value: 'GROUP' + i, + }; + this.list.push(dataItem); + } + }, + collapse(e) { + prompt.showToast({ + message: 'Close ' + e.groupid + }) + }, + expand(e) { + prompt.showToast({ + message: 'Open ' + e.groupid + }) + } +} +``` + +![en-us_image_0000001267887845](../../../../images/en/application-dev/ui/figures/099f4a5956912e7f277a0d0998601db9.gif) + +> ![icon-note.gif](../../../../images/en/application-dev/ui/public_sys-resources/ae89e6a5f31e3d03603c1d114c8400cf.gif) **NOTE**: +> - The groupcollapse and groupexpand events can be used only by the list-item-group component. + + +## Example Scenario + +Search for contacts by using an alphabetical indexer. + +``` + +
+ + Contacts + + + +
+
+ {{$item.name}} + 18888888888 +
+
+
+ +
+ Total: 10 +
+
+
+
+``` + +``` +/* index.css */ +.doc-page { + flex-direction: column; + background-color: #F1F3F5; +} +.list { + width: 100%; + height: 100%; +} +.item { + height: 120px; + padding-left: 10%; + border-top: 1px solid #dcdcdc; +} +.name { + color: #000000; + font-size: 39px; +} +.number { + color: black; + font-size: 25px; +} +.container { + flex-direction: row; + align-items: center; +} +.in-container { + flex-direction: column; + justify-content: space-around; +} +``` + +``` +// xxx.js +export default { + data: { + namelist:[{ + name: 'Zoey', + section:'Z' + },{ + name: 'Quin', + section:'Q' + },{ + name:'Sam', + section:'S' + },{ + name:'Leo', + section:'L' + },{ + name:'Zach', + section:'Z' + },{ + name:'Wade', + section:'W' + },{ + name:'Zoe', + section:'Z' + },{ + name:'Warren', + section:'W' + },{ + name:'Kyle', + section:'K' + },{ + name:'Zaneta', + section:'Z' + }] + }, + onInit() { + } + } +``` + + +![en-us_image_0000001267767861](../../../../images/en/application-dev/ui/figures/aae519839b5d5a3db9b5bf53ea70ddff.gif) diff --git a/website/docs/extras/en/application-dev/ui/ui-js-components-picker.md b/website/docs/extras/en/application-dev/ui/ui-js-components-picker.md new file mode 100644 index 0000000000000000000000000000000000000000..2c6a8703312863eb1136072007edbb192890e935 --- /dev/null +++ b/website/docs/extras/en/application-dev/ui/ui-js-components-picker.md @@ -0,0 +1,312 @@ +--- +title: "ui-js-components-picker" +prepermalink: /extras/951bb17387966bf77e6bebed8adf4274/ +permalink: /extras/951bb17387966bf77e6bebed8adf4274/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/ui/ui-js-components-picker.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [ui-js-components-picker] +--- +# <picker> Development + + +The <picker> component supports common, date, time, data and time, and multi-column text selectors. For details, see [picker](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/picker). + + +## Creating a <picker> Component + +Create a <picker> component in the .hml file under pages/index. + + +``` + +
+ picker +
+``` + + +``` +/* index.css */ +.container { + flex-direction: column; + justify-content: center; + align-items: center; + background-color: #F1F3F5; +} +``` + +![en-us_image_0000001223287716](../../../../images/en/application-dev/ui/figures/f1ea98a5f900b8117553129560c802d9.gif) + + +## Setting the Picker Type + +Set the type attribute of the <picker> component. For example, set it to date. + + +``` + +
+ + +
+``` + + +``` +/* index.css */ +.container { + flex-direction: column; + justify-content: center; + align-items: center; + background-color: #F1F3F5; +} +.pickertext{ + margin-bottom: 30px; +} +``` + + +``` +// xxx.js +export default { + data: { + rangetext:['15', "20", "25"], + textvalue:'Select text', + datevalue:'Select date', + } +} +``` + +![en-us_image_0000001267647893](../../../../images/en/application-dev/ui/figures/5b32f7ef64517dfd06e42eb276f6ae1a.gif) + +> ![icon-note.gif](../../../../images/en/application-dev/ui/public_sys-resources/ae89e6a5f31e3d03603c1d114c8400cf.gif) **NOTE**: +> +> When setting the value range of a common selector, you must use the data binding mode. + + +## Setting the Time Format + +Set the hours attribute to specify the time format used by the time selector. Available values include 12 and 24, indicating the 12-hour format and 24-hour format, respectively. + + +``` + +
+ + +
+``` + + +``` +/* index.css */ +.container { + flex-direction: column; + justify-content: center; + align-items: center; + background-color: #F1F3F5; +} +.pickertime { + margin-bottom:50px; + width: 300px; + height: 50px; +} +``` + +![en-us_image_0000001222807808](../../../../images/en/application-dev/ui/figures/aced10706a481ffcbbc6784bd2fd9f11.gif) + +> ![icon-note.gif](../../../../images/en/application-dev/ui/public_sys-resources/ae89e6a5f31e3d03603c1d114c8400cf.gif) **NOTE**: +> - When hours is set to 12, the time is displayed in 12-hour format and distinguished by a.m. and p.m. +> +> - When hours is set to 24, the time is displayed in 24-hour format. + + +## Adding Response Events + +To confirm and cancel selection, add change and cancel events. + + +``` + +
+ +
+``` + + +``` +/* index.css */ +.container { + flex-direction: column; + justify-content: center; + align-items: center; + background-color: #F1F3F5; +} +.pickermuitl { + margin-bottom:20px; + width: 600px; + height: 50px; + font-size: 25px; + letter-spacing:15px; +} +``` + + +``` +// xxx.js +import prompt from '@system.prompt'; +export default { + data: { + multitext:[["a", "b", "c"], ["e", "f", "g"], ["h", "i"]], + multitextvalue:'Select multi-line text', + multitextselect:[0,0,0], + }, + multitextonchange(e) { + this.multitextvalue=e.newValue; + prompt.showToast({ message:"Multi-column text changed to:" + e.newValue }) + }, + multitextoncancel() { + prompt.showToast({ message:"multitextoncancel" }) + }, +} +``` + +![en-us_image_0000001223127748](../../../../images/en/application-dev/ui/figures/dd503f79244575e8e92fcc617acc5e4b.gif) + + +## Example Scenario + + +Implement a health check-in application by using the <picker> component. + +``` + +
+ Health check-in +
+ Office: + +
+ +
+ Office hours: + +
+ +
+ Having fever or cold symptoms + +
+ +
+ Close contact with someone with COVID-19 + +
+
+ +
+
+``` + +``` +/* index.css */ +.doc-page { + flex-direction: column; + background-color: #F1F3F5; +} +.title { + margin-top: 30px; + margin-bottom: 30px; + margin-left: 50px; + font-weight: bold; + color: #0000ff; + font-size: 38px; +} +.out-container { + flex-direction: column; + align-items: center; +} +.pick { + width: 80%; + height: 76px; + border: 1px solid #0000ff; + border-radius: 20px; + padding-left: 12px; +} +.txt { + width: 80%; + font-size: 18px; + text-align: left; + margin-bottom: 12px; + margin-left: 12px; +} +.dvd { + margin-top: 30px; + margin-bottom: 30px; + margin-left: 80px; + margin-right: 80px; + color: #6495ED; + stroke-width: 6px; +} +``` + +``` +// xxx.js +import pmt from '@system.prompt' +export default { + data: { + yorn1:'No', + yorn2:'No', + pos:'Home', + yesno:['Yes', 'No'], + posarr:['Home', 'Company'], + datevalue:'Select time', + datetimeselect:'2012-5-6-11-25', + dateselect:'2021-9-17', + showbuild:true + }, + onInit() { + }, + isFever(e) { + this.yorn1 = e.newValue + }, + isTouch(e) { + this.yorn2 = e.newValue + }, + setPos(e) { + this.pos = e.newValue + if (e.newValue === 'Non-research center') { + this.showbuild = false + } else { + this.showbuild = true + } + }, + setbuild(e) { + this.build = e.newValue + }, + dateonchange(e) { + e.month=e.month+1; + this.datevalue = e.year + "-" + e.month + "-" + e.day; + pmt.showToast({ message:"date:"+e.year+"-"+e.month+"-"+e.day }) + }, + showtoast() { + pmt.showToast({ + message: 'Submitted.', + duration: 2000, + gravity: 'center' + }) + } +} +``` + + +![en-us_image_0000001267887877](../../../../images/en/application-dev/ui/figures/8d7b6ea01f0edcca244fe452dc032d2e.gif) diff --git a/website/docs/extras/en/application-dev/ui/ui-js-components-stepper.md b/website/docs/extras/en/application-dev/ui/ui-js-components-stepper.md new file mode 100644 index 0000000000000000000000000000000000000000..3ebde44035c163eb4d537575dffe38fc2321a046 --- /dev/null +++ b/website/docs/extras/en/application-dev/ui/ui-js-components-stepper.md @@ -0,0 +1,416 @@ +--- +title: "ui-js-components-stepper" +prepermalink: /extras/9b90423f489453dd8e1312bc6904c1af/ +permalink: /extras/9b90423f489453dd8e1312bc6904c1af/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/ui/ui-js-components-stepper.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [ui-js-components-stepper] +--- +# <stepper> Development + + +When multiple steps are required to complete a task, you can use the <stepper> component to navigate your users through the whole process. For details, see [stepper](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/stepper). + + +> ![icon-note.gif](../../../../images/en/application-dev/ui/public_sys-resources/ae89e6a5f31e3d03603c1d114c8400cf.gif) **NOTE**: +> This component is supported since API version 5. + + +## Creating a <stepper> Component + +Create a <stepper> component in the .hml file under pages/index. + + +``` + +
+ + Step 1 + + + Step 2 + + +
+``` + + +``` +/* xxx.css */ +.container { + flex-direction: column; + justify-content: center; + align-items: center; + background-color: #F1F3F5; +} +text{ + width: 100%; + height: 100%; + text-align: center; +} +``` + +![en-us_image_0000001223287656](../../../../images/en/application-dev/ui/figures/7b45a4fdbfa7896f7b87f553b05a5229.gif) + + +## Setting the Index + +Set index to the index value of the step that you want to display by default. + + +``` + +
+ + + stepper-item1 + + + stepper-item2 + + + stepper-item3 + + +
+``` + + +``` +/* index.css */ +.container { + flex-direction: column; + background-color:#F1F3F5; +} +text{ + width: 100%; + height: 100%; + text-align: center; +} +``` + +![en-us_image_0000001267767837](../../../../images/en/application-dev/ui/figures/3587a7ad8be18a4584f485d6c471dbc8.gif) + +Set the label attribute to customize the button text for the <stepper-item>. + + +``` + +
+ + + stepper-item1 + + + stepper-item2 + + + stepper-item3 + + + stepper-item4 + + +
+``` + + +``` +/* index.css */ +.container { + flex-direction: column; + background-color:#F1F3F5; +} +text{ + width: 100%; + height: 100%; + text-align: center; +} +``` + + +``` +/* index.js */ +export default { + data: { + label_1:{ nextLabel: 'NEXT', status: 'normal' }, + label_2:{ + prevLabel: 'BACK', + nextLabel: 'NEXT', + status: 'normal' + }, + label_3:{ + prevLabel: 'BACK', + nextLabel: 'END', + status: 'disabled' + }, + }, +} +``` + +![en-us_image_0000001267767841](../../../../images/en/application-dev/ui/figures/028e94c28c329d6016cbb42965a4fd64.gif) + + +## Setting the Style + + By default, the <stepper> component fills entire space of its container. The sample code below shows how to set the border and background color using the border and background-color attributes. + +``` + +
+
+ + + stepper-item1 + + +
+
+``` + + +``` +/* index.css */ +.container { + flex-direction: column; + align-items: center; + justify-content: center; + background-color:#F1F3F5; +} +.stepperContent{ + width: 300px; + height: 300px; +} +.stepperClass{ + border:1px solid silver ; background-color: white; +} +text{ + width: 100%; + height: 100%; + text-align: center; +} +``` + +![en-us_image_0000001223287668](../../../../images/en/application-dev/ui/figures/a93822881bc62dd8e8f204c2ac0dec19.png) + + +## Adding Events + +The <stepper> component supports the finish, change, next, back, and skip events. + +- When the change and next or back events exist at the same time, the next or back event is executed before the change event. + +- Before resetting the index attribute, you must remove the current value. Otherwise, the value change cannot be detected. + +``` + +
+
+ + + stepper-item1 + + + + stepper-item2 + + + + stepper-item3 + + +
+
+``` + + +``` +/* xxx.css */ +.doc-page { + flex-direction: column; + align-items: center; + justify-content: center; +} +stepper-item{ + width: 100%; + flex-direction: column; + align-self: center; + justify-content: center; +} +text{ + margin-top: 45%; + justify-content: center; + align-self: center; + margin-bottom: 50px; +} +button{ + width: 80%; + height: 60px; + margin-top: 20px; +} +``` + + +``` +/* index.js */ +import prompt from '@system.prompt'; +export default { + data: { + index:0, + }, + stepperSkip(){ + this.index = null; + this.index=2; + }, + skipClick(){ + this.$element('stepperId').setNextButtonStatus({status: 'skip', label: 'SKIP'}); + }, + stepperFinish(){ + prompt.showToast({ + message: 'All Finished' + }) + }, + stepperChange(e){ + console.log("stepperChange"+e.index) + prompt.showToast({ + message: 'Previous step: '+e.prevIndex+"-------Current step:"+e.index + }) + }, + stepperNext(e){ + console.log("stepperNext"+e.index) + prompt.showToast({ + message: 'Current step:'+e.index+"-------Next step:"+e.pendingIndex + }) + var index = {pendingIndex:e.pendingIndex } + return index; + }, + stepperBack(e){ + console.log("stepperBack"+e.index) + var index = {pendingIndex: e.pendingIndex } + return index; + } +} +``` + +![en-us_image_0000001267607869](../../../../images/en/application-dev/ui/figures/7a659d5a088a615e174b7d2f03ace7e8.gif) + + +## Example Scenario + +Select the options displayed on the page. Your selection will be shown in real time. Click the next button to dynamically change the font color and font size on the page. + +Use the <stepper> component to navigate through the steps. Create a [<toggle>](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/toggle) component to implement the functions of selection and displaying the selection result. Then use the [<select>](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/select) component to dynamically change the font color or size of the selected options. + + +``` +
+ + +
+ Select error types: + + {{error}} + +
+ +
+
+
+ +
+ Toggle +
+ + +
+
+
+ text-color + +
+
+ font-size + +
+
+
+
+
+
+``` + + +``` +/* xxx.css */ +.container { + flex-direction: column; + align-items: center; + justify-content: center; + background-color:#F1F3F5; +} +.dvd { + stroke-width: 8px; + color: orangered; + margin: 65px; +} +.tog{ + margin-right: 20px; + margin-top: 30px; +} +``` + + +``` +/* index.js */ +import prompt from '@system.prompt'; +import router from '@system.router'; +let myset = new Set(); +export default { + data: { + error: '', + tcolor:'#FF4500', + color_list:['#FF4500','#5F9EA0','#0000FF'], + tsize: '12px', + size_list: ['12px', '30px', '8px', '50px'], + label1: { + prevLabel: 'The text on the left of the starting step is invalid.', + nextLabel: 'Toggle' + }, + label2: { + prevLabel: 'toggle', + nextLabel: 'END' + }, + togglelist1:['Program error', 'Software', 'System', 'Application'], + }, + multiTog(arg, e) { + this.error = ' ' + if (e.checked) { + myset.add(arg) + } else { + myset.delete(arg) + } + for (let item of myset) { + this.error += item + ' ' + } + }, + settcolor(e) { + this.tcolor = e.newValue + }, + settsize(e) { + this.tsize = e.newValue + } +} +``` + +![en-us_image_0000001267887817](../../../../images/en/application-dev/ui/figures/ae9af5baff6e242fecf3457cb6641c77.gif) diff --git a/website/docs/extras/en/application-dev/ui/ui-js-components-text.md b/website/docs/extras/en/application-dev/ui/ui-js-components-text.md new file mode 100644 index 0000000000000000000000000000000000000000..c2367ea8a0a2787b8e5a11a9804cd70eaff340a9 --- /dev/null +++ b/website/docs/extras/en/application-dev/ui/ui-js-components-text.md @@ -0,0 +1,294 @@ +--- +title: "ui-js-components-text" +prepermalink: /extras/99e5841e65138d840158f6db79f9a82d/ +permalink: /extras/99e5841e65138d840158f6db79f9a82d/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/ui/ui-js-components-text.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [ui-js-components-text] +--- +# <text> Development + + +The <text> component is used to display a piece of textual information. For details, see [text](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/text). + + +## Creating a <text> Component + +Create a <text> component in the .hml file under pages/index. + + +``` + +
+ Hello World +
+``` + + +``` +/* xxx.css */ +.container { + width: 100%; + height: 100%; + flex-direction: column; + align-items: center; + justify-content: center; + background-color: #F1F3F5; +} +``` + +![en-us_image_0000001222807780](../../../../images/en/application-dev/ui/figures/d96a8c80e364d2b9533c6e5639b75677.png) + + +## Setting the Text Style and Attributes + +- Adding a text style + + + Set the color, font-size, allow-scale, word-spacing, and text-valign attributes to apply the color, size, zoom, spacing, and vertical alignment styles to the text. + + ``` + +
+ + This is a passage + + + This is a passage + +
+ ``` + + + + ``` + /* xxx.css */ + .container { + width: 100%; + height: 100%; + flex-direction: column; + align-items: center; + justify-content: center; + background-color: #F1F3F5; + } + ``` + + + ![en-us_image_0000001222967764](../../../../images/en/application-dev/ui/figures/6c7dac22795861a7291e2b9611485997.png) + +- Adding a text modifier + + + Set the text-decoration attribute to add a line to selected text. Set the text-decoration-color attribute to apply specific color to the added line. For values of text-decoration, see [Text Style](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/text). + + ``` + +
+ + This is a passage + + + This is a passage + +
+ ``` + + ``` + /* xxx.css */ + .container { + width: 100%; + height: 100%; + flex-direction: column; + align-items: center; + justify-content: center; + } + text{ + font-size: 50px; + } + ``` + + + ![en-us_image_0000001223287688](../../../../images/en/application-dev/ui/figures/b3fe43a7190e4cace00190634293bb1f.png) + +- Hiding text content + + + Set the text-overflow attribute to ellipsis so that overflowed text is displayed as an ellipsis. + + ``` + +
+ + This is a passage + +
+ ``` + + ``` + /* xxx.css */ + .container { + width: 100%; + height: 100%; + flex-direction: column; + align-items: center; + background-color: #F1F3F5; + justify-content: center; + } + .text{ + width: 200px; + max-lines: 1; + text-overflow:ellipsis; + } + ``` + + + > ![icon-note.gif](../../../../images/en/application-dev/ui/public_sys-resources/ae89e6a5f31e3d03603c1d114c8400cf.gif) **NOTE**: + > - text-overflow must be used together with max-lines. + > + > - max-lines indicates the maximum number of lines in the text. + + +![en-us_image_0000001267647865](../../../../images/en/application-dev/ui/figures/a0cd5b5ae5a56f278883477f2f1ffb95.png) + + +- Setting the text line breaking mode + + + Set the word-break attribute to specify how to break lines of text. For values of word-break, see [Text Styles](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/text). + + ``` + +
+
+ + Welcome to the world + + + Welcome to the world + +
+
+ ``` + + ``` + /* xxx.css */ + .container { + background-color: #F1F3F5; + flex-direction: column; + align-items: center; + justify-content: center; + } + .content{ + width: 50%; + flex-direction: column; + align-items: center; + justify-content: center; + } + .text1{ + height: 200px; + border:1px solid #1a1919; + margin-bottom: 50px; + text-align: center; + word-break: break-word; + font-size: 40px; + } + .text2{ + height: 200px; + border:1px solid #0931e8; + text-align: center; + word-break: break-all; + font-size: 40px; + } + ``` + + + ![en-us_image_0000001267767865](../../../../images/en/application-dev/ui/figures/215b029944306505dbd62e2c48e568f4.png) + +- Setting the [<span>](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/span)child component + +``` + +
+ + This is a passage + + + This 1 is a 1 passage + +
+``` + + +![en-us_image_0000001223127720](../../../../images/en/application-dev/ui/figures/f4b4c044c7570ba45ccc7554b482b5c2.png) + + +> ![icon-note.gif](../../../../images/en/application-dev/ui/public_sys-resources/ae89e6a5f31e3d03603c1d114c8400cf.gif) **NOTE**: +> - When the <span> child component is used to form a text paragraph, incorrect <span> attribute settings (for example, setting of font-weight to 1000) will result in abnormal display of the text paragraph. +> +> - When the <span> child component is being used, do not include any text you want to show in the <text> component, as such text will not be displayed if you do so. + + +## Example Scenario + +Use the <text> component to display text content through data binding. Use the <span> child component to hide or display text content by setting the show attribute. + + + ``` + +
+
+ + {{ content }} + + +
+ + {{ content }} + + 1 + + Hide clip + +
+ ``` + + +``` +/* xxx.css */ +.container { + align-items: center; + flex-direction: column; + justify-content: center; + background-color: #F1F3F5; +} +.title { + font-size: 26px; + text-align:center; + width: 200px; + height: 200px; +} +``` + + +``` +// xxx.js +export default { + data: { + isShow:true, + content: 'Hello World' + }, + onInit(){ }, + test(e) { + this.isShow = e.checked + } +} +``` + +![en-us_image_0000001267887849](../../../../images/en/application-dev/ui/figures/7ac607c2bf2d23d03328058d9df7c342.gif) diff --git a/website/docs/extras/en/application-dev/ui/ui-ts-components-web.md b/website/docs/extras/en/application-dev/ui/ui-ts-components-web.md new file mode 100644 index 0000000000000000000000000000000000000000..9e94ac107f836265ccb42686946ef64bbd168a8f --- /dev/null +++ b/website/docs/extras/en/application-dev/ui/ui-ts-components-web.md @@ -0,0 +1,210 @@ +--- +title: "ui-ts-components-web" +prepermalink: /extras/2b20680728bf092271588027fd37cf44/ +permalink: /extras/2b20680728bf092271588027fd37cf44/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/ui/ui-ts-components-web.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [ui-ts-components-web] +--- +# Web + +The \ component can be used to display web pages. For details, see [Web API](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Web). + +## Creating a Component + +Create a \ component in the .ets file under main/ets/MainAbility/pages. Then, in the created component, use src to specify the web page URI to be referenced, and bind a controller to the component to call the component APIs. + + ``` + // xxx.ets + @Entry + @Component + struct WebComponent { + controller: WebController = new WebController(); + build() { + Column() { + Web({ src: 'https://www.example.com', controller: this.controller }) + } + } + } + ``` + +## Setting Styles and Attributes + +When using the \ component, you need to specify the styles and attributes. The sample code is as follows. + +``` +// xxx.ets +@Entry +@Component +struct WebComponent { + fileAccess: boolean = true; + controller: WebController = new WebController(); + build() { + Column() { + Text('Hello world!') + .fontSize(20) + Web({ src: 'https://www.example.com', controller: this.controller }) + // Set the height and padding. + .height(500) + .padding(20) + // Set the file access permission and script execution permission. + .fileAccess(this.fileAccess) + .javaScriptAccess(true) + Text('End') + .fontSize(20) + } + } +} +``` +## Adding Events and Methods + +Add the onProgressChange event for the \ component, which is triggered when the loading progress changes and returns the progress value in its callback. Assign the progress value to the \ component to control the status of the component. When the progress reaches 100%, the \ component is hidden, and the web page loading is complete. + +``` +// xxx.ets +@Entry +@Component +struct WebComponent { + @State progress: number = 0; + @State hideProgress: boolean = true; + fileAccess: boolean = true; + controller: WebController = new WebController(); + build() { + Column() { + Text('Hello world!') + .fontSize(20) + Progress({value: this.progress, total: 100}) + .color('#0000ff') + .visibility(this.hideProgress ? Visibility.None : Visibility.Visible) + Web({ src: 'https://www.example.com', controller: this.controller }) + .fileAccess(this.fileAccess) + .javaScriptAccess(true) + .height(500) + .padding(20) + // Add an onProgressChange event. + .onProgressChange(e => { + this.progress = e.newProgress; + // When the progress reaches 100%, the progress bar disappears. + if (this.progress === 100) { + this.hideProgress = true; + } else { + this.hideProgress = false; + } + }) + Text('End') + .fontSize(20) + } + } +} +``` +Add the runJavaScript method to the onPageEnd event. The onPageEnd event is triggered when the web page finishes loading. In this case, the runJavaScript method can be used to execute JavaScript scripts in the HTML file. In the sample code below, when the web page finishes loading, the onPageEnd event is triggered to call the test method in the HTML file and print information on the console. + +``` +// xxx.ets +@Entry +@Component +struct WebComponent { + @State progress: number = 0; + @State hideProgress: boolean = true; + fileAccess: boolean = true; + // Define the controller for the \ component. + controller: WebController = new WebController(); + build() { + Column() { + Text('Hello world!') + .fontSize(20) + Progress({value: this.progress, total: 100}) + .color('#0000ff') + .visibility(this.hideProgress ? Visibility.None : Visibility.Visible) + // Initialize the \ component and bind it to the controller. + Web({ src: $rawfile('index.html'), controller: this.controller }) + .fileAccess(this.fileAccess) + .javaScriptAccess(true) + .height(500) + .padding(20) + .onProgressChange(e => { + this.progress = e.newProgress; + if (this.progress === 100) { + this.hideProgress = true; + } else { + this.hideProgress = false; + } + }) + .onPageEnd(e => { + // test() is defined in index.html. + this.controller.runJavaScript({ script: 'test()' }); + console.info('url: ', e.url); + }) + Text('End') + .fontSize(20) + } + } +} +``` + +Create an HTML file in main/resources/rawfile. + +``` + + + + + + Hello world! + + + +``` +## Scenario Example + +In this example, you'll implement a \ component where videos can be played dynamically. Embed a video resource into an HTML page, and then use the \ component controller to invoke the onActive and onInactive methods to activate and pause page rendering, respectively. When the page is hidden, the \ component stops rendering and the video playback pauses. When the page is displayed, the \ component is activated and the video playback resumes. + + ``` + // xxx.ets + @Entry + @Component + struct WebComponent { + controller: WebController = new WebController(); + build() { + Column() { + Web({ src: $rawfile('index.html'), controller: this.controller }) + .fileAccess(true) + } + } + + onPageHide() { + // Invoked when the page is hidden. + this.controller.onInactive(); + } + + onPageShow() { + // Invoked when the page is displayed. + this.controller.onActive(); + } + } + ``` + + ``` + + + + + + + + + ``` diff --git a/website/docs/extras/en/application-dev/webgl/Readme-EN.md b/website/docs/extras/en/application-dev/webgl/Readme-EN.md new file mode 100644 index 0000000000000000000000000000000000000000..37e6dee7a770e3efc0145e7f805b8608197d56a1 --- /dev/null +++ b/website/docs/extras/en/application-dev/webgl/Readme-EN.md @@ -0,0 +1,19 @@ +--- +title: "Readme-EN" +prepermalink: /extras/b897bddbf732ca9fb45499241b5674f0/ +permalink: /extras/b897bddbf732ca9fb45499241b5674f0/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/webgl/Readme-EN.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [Readme-EN] +--- +# WebGL + +- [WebGL Overview](/pages/en/app/application/Development/Basic%20Functions/WebGL/WebGL%20Overview) +- [WebGL Development](/pages/en/app/application/Development/Basic%20Functions/WebGL/WebGL%20Development) diff --git a/website/docs/extras/en/application-dev/website.md b/website/docs/extras/en/application-dev/website.md new file mode 100644 index 0000000000000000000000000000000000000000..9b1abd4437dc54ede42e03daf847390ca4c45c03 --- /dev/null +++ b/website/docs/extras/en/application-dev/website.md @@ -0,0 +1,680 @@ +--- +title: "website" +prepermalink: /extras/9201f401eed7ab8a3af4ffd5fa67a286/ +permalink: /extras/9201f401eed7ab8a3af4ffd5fa67a286/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/website.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [website] +--- +# Application Development + +- [Application Development Overview](/pages/en/app/application/Application%20Development%20Overview) +- Quick Start + - [Directory Structure](/pages/en/app/application/Quick%20Start/Directory%20Structure) + - [Resource File Categories](/pages/en/app/application/Quick%20Start/Resource%20File%20Categories) +- Development + - Ability Development + - FA Model + - [FA Model Overview](/pages/en/app/application/Development/Ability%20Development/FA%20Model/FA%20Model%20Overview) + - [Page Ability Development](/pages/en/app/application/Development/Ability%20Development/FA%20Model/Page%20Ability%20Development) + - [Service Ability Development](/pages/en/app/application/Development/Ability%20Development/FA%20Model/Service%20Ability%20Development) + - [Data Ability Development](/pages/en/app/application/Development/Ability%20Development/FA%20Model/Data%20Ability%20Development) + - [FA Widget Development](/pages/en/app/application/Development/Ability%20Development/FA%20Model/FA%20Widget%20Development) + + - Other + - [Ability Assistant Usage](/pages/en/app/application/Development/Ability%20Development/Other/Ability%20Assistant%20Usage) + - UI + - [ArkUI Overview](/pages/en/app/application/Development/UI/ArkUI%20Overview) + - JavaScript-based Web-Like Development Paradigm + - [Overview](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Overview) + - Framework + - [File Organization](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Framework/File%20Organization) + - ["js" Tag](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Framework/%20js%20%20Tag) + - [app.js](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Framework/app.js) + - Syntax + - [HML](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Framework/Syntax/HML) + - [CSS](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Framework/Syntax/CSS) + - [JavaScript](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Framework/Syntax/JavaScript) + - [Lifecycle](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Framework/Lifecycle) + - [Resource Limitations and Access](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Framework/Resource%20Limitations%20and%20Access) + - [Multi-Language Capability](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Framework/Multi-Language%20Capability) + - Building the UI + - [Component Overview](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Building%20the%20UI/Component%20Overview) + - Building the Layout + - [Layout Description](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Building%20the%20UI/Building%20the%20Layout/Layout%20Description) + - [Adding Title and Paragraph Text](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Building%20the%20UI/Building%20the%20Layout/Adding%20Title%20and%20Paragraph%20Text) + - [Adding an Image](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Building%20the%20UI/Building%20the%20Layout/Adding%20an%20Image) + - [Adding a Comment](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Building%20the%20UI/Building%20the%20Layout/Adding%20a%20Comment) + - [Adding a Container](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Building%20the%20UI/Building%20the%20Layout/Adding%20a%20Container) + - [Adding Interactions](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Building%20the%20UI/Adding%20Interactions) + - [Developing Animations](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Building%20the%20UI/Developing%20Animations) + - [Defining Events](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Building%20the%20UI/Defining%20Events) + - [Defining Page Routes](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Building%20the%20UI/Defining%20Page%20Routes) + - Common Component Development Guidelines + - Container Components + - [List](/extras/0dfc6b0664f6e334a81bfd9ccf6f51c6/) + - [Dialog](/extras/f78fdc6f879924b1b1b9566e48913731/) + - [Form](/extras/2e5bc8e1ddc170355c59c569c9e7e99e/) + - [Stepper](/extras/9b90423f489453dd8e1312bc6904c1af/) + - [Tabs](/extras/6280763f9b6ef60950030fbcc8673fa9/) + - Basic Components + - [Text](/extras/99e5841e65138d840158f6db79f9a82d/) + - [Input](/extras/d9c1ad400ac43ce056c56ae004780b64/) + - [Button](/extras/c26625fb2ce7815fd08c2aab247111f4/) + - [Picker](/extras/951bb17387966bf77e6bebed8adf4274/) + - [Image](/extras/874a020d7013a89a35806e100dc7e5f3/) + - Animation Development Guidelines + - CSS Animation + - [Defining Attribute Style Animations](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Common%20Component%20Development%20Guidelines/Animation%20Development%20Guidelines/CSS%20Animation/Defining%20Attribute%20Style%20Animations) + - [Defining Animations with the transform Attribute](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Common%20Component%20Development%20Guidelines/Animation%20Development%20Guidelines/CSS%20Animation/Defining%20Animations%20with%20the%20transform%20Attribute) + - [Defining Animations with the background-position Attribute](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Common%20Component%20Development%20Guidelines/Animation%20Development%20Guidelines/CSS%20Animation/Defining%20Animations%20with%20the%20background-position%20Attribute) + - [Defining Animations for SVG Components](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Common%20Component%20Development%20Guidelines/Animation%20Development%20Guidelines/CSS%20Animation/Defining%20Animations%20for%20SVG%20Components) + - JS Animation + - [Component Animation](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Common%20Component%20Development%20Guidelines/Animation%20Development%20Guidelines/JS%20Animation/Component%20Animation) + - Interpolator Animation + - [Animation Effect](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Common%20Component%20Development%20Guidelines/Animation%20Development%20Guidelines/JS%20Animation/Interpolator%20Animation/Animation%20Effect) + - [Animation Frame](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Common%20Component%20Development%20Guidelines/Animation%20Development%20Guidelines/JS%20Animation/Interpolator%20Animation/Animation%20Frame) + - [Custom Components](/pages/en/app/application/Development/UI/JavaScript-based%20Web-Like%20Development%20Paradigm/Custom%20Components) + - TypeScript-based Declarative Development Paradigm + - [Overview](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Overview) + - Framework Overview + - File Organization + - [Directory Structure](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Framework%20Overview/File%20Organization/Directory%20Structure) + - [Rules for Accessing Application Code Files](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Framework%20Overview/File%20Organization/Rules%20for%20Accessing%20Application%20Code%20Files) + - ["js" Tag](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Framework%20Overview/%20js%20%20Tag) + - Resource Access + - [Accessing Application Resources](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Framework%20Overview/Resource%20Access/Accessing%20Application%20Resources) + - [Accessing System Resources](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Framework%20Overview/Resource%20Access/Accessing%20System%20Resources) + - [Media Resource Types](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Framework%20Overview/Resource%20Access/Media%20Resource%20Types) + - [Pixel Units](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Framework%20Overview/Pixel%20Units) + - [Types](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Framework%20Overview/Types) + - Declarative Syntax + - [Overview](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/Overview) + - General UI Description Specifications + - [Basic Concepts](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/General%20UI%20Description%20Specifications/Basic%20Concepts) + - Declarative UI Description Specifications + - [Parameterless Configuration](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/General%20UI%20Description%20Specifications/Declarative%20UI%20Description%20Specifications/Parameterless%20Configuration) + - [Configuration with Mandatory Parameters](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/General%20UI%20Description%20Specifications/Declarative%20UI%20Description%20Specifications/Configuration%20with%20Mandatory%20Parameters) + - [Attribution Configuration](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/General%20UI%20Description%20Specifications/Declarative%20UI%20Description%20Specifications/Attribution%20Configuration) + - [Event Configuration](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/General%20UI%20Description%20Specifications/Declarative%20UI%20Description%20Specifications/Event%20Configuration) + - [Child Component Configuration](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/General%20UI%20Description%20Specifications/Declarative%20UI%20Description%20Specifications/Child%20Component%20Configuration) + - Componentization + - [@Component](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/General%20UI%20Description%20Specifications/Componentization/Component) + - [@Entry](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/General%20UI%20Description%20Specifications/Componentization/Entry) + - [@Preview](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/General%20UI%20Description%20Specifications/Componentization/Preview) + - [@Builder](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/General%20UI%20Description%20Specifications/Componentization/Builder) + - [@Extend](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/General%20UI%20Description%20Specifications/Componentization/Extend) + - [@CustomDialog](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/General%20UI%20Description%20Specifications/Componentization/CustomDialog) + - About UI State Management + - [Basic Concepts](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20UI%20State%20Management/Basic%20Concepts) + - Managing Component States + - [@State](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20UI%20State%20Management/Managing%20Component%20States/State) + - [@Prop](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20UI%20State%20Management/Managing%20Component%20States/Prop) + - [@Link](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20UI%20State%20Management/Managing%20Component%20States/Link) + - Managing Application States + - [AppStorage](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20UI%20State%20Management/Managing%20Application%20States/AppStorage) + - [PersistentStorage](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20UI%20State%20Management/Managing%20Application%20States/PersistentStorage) + - [Environment](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20UI%20State%20Management/Managing%20Application%20States/Environment) + - Managing Other States + - [@observed and @objectLink](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20UI%20State%20Management/Managing%20Other%20States/observed%20and%20objectLink) + - [@Consume and @Provide](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20UI%20State%20Management/Managing%20Other%20States/Consume%20and%20Provide) + - [@Watch](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20UI%20State%20Management/Managing%20Other%20States/Watch) + - About Rendering Control Syntax + - [if/else](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20Rendering%20Control%20Syntax/if%20else) + - [ForEach](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20Rendering%20Control%20Syntax/ForEach) + - [LazyForEach](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20Rendering%20Control%20Syntax/LazyForEach) + - About @Component + - [build Function](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20Component/build%20Function) + - [Custom Component Initialization](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20Component/Custom%20Component%20Initialization) + - [Custom Component Lifecycle Callbacks](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20Component/Custom%20Component%20Lifecycle%20Callbacks) + - [Example: Component Creation and Re-Initialization](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/About%20Component/Example%20%20Component%20Creation%20and%20Re-Initialization) + - [Syntactic Sugar](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Declarative%20Syntax/Syntactic%20Sugar) + - Experiencing the Declarative UI + - [Creating a Declarative UI Project](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Experiencing%20the%20Declarative%20UI/Creating%20a%20Declarative%20UI%20Project) + - [Getting to Know Components](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Experiencing%20the%20Declarative%20UI/Getting%20to%20Know%20Components) + - [Creating a Simple Page](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Experiencing%20the%20Declarative%20UI/Creating%20a%20Simple%20Page) + - Defining Page Layout and Connection + - [Building a Food Data Model](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Defining%20Page%20Layout%20and%20Connection/Building%20a%20Food%20Data%20Model) + - [Building a Food Category List Layout](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Defining%20Page%20Layout%20and%20Connection/Building%20a%20Food%20Category%20List%20Layout) + - [Building a Food Category Grid Layout](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Defining%20Page%20Layout%20and%20Connection/Building%20a%20Food%20Category%20Grid%20Layout) + - [Implementing Page Redirection and Data Transmission](/pages/en/app/application/Development/UI/TypeScript-based%20Declarative%20Development%20Paradigm/Defining%20Page%20Layout%20and%20Connection/Implementing%20Page%20Redirection%20and%20Data%20Transmission) + - Basic Functions + - Window Manager + - Window + - [Window Overview](/pages/en/app/application/Development/Basic%20Functions/Window%20Manager/Window/Window%20Overview) + - [Window Development](/pages/en/app/application/Development/Basic%20Functions/Window%20Manager/Window/Window%20Development) + - Display + - [Display Overview](/pages/en/app/application/Development/Basic%20Functions/Window%20Manager/Display/Display%20Overview) + - [Display Development](/pages/en/app/application/Development/Basic%20Functions/Window%20Manager/Display/Display%20Development) + - Screenshot + - [Screenshot Overview](/pages/en/app/application/Development/Basic%20Functions/Window%20Manager/Screenshot/Screenshot%20Overview) + - [Screenshot Development](/pages/en/app/application/Development/Basic%20Functions/Window%20Manager/Screenshot/Screenshot%20Development) + - WebGL + - [WebGL Overview](/pages/en/app/application/Development/Basic%20Functions/WebGL/WebGL%20Overview) + - [WebGL Development](/pages/en/app/application/Development/Basic%20Functions/WebGL/WebGL%20Development) + - Media + - Audio + - [Audio Overview](/pages/en/app/application/Development/Basic%20Functions/Media/Audio/Audio%20Overview) + - [Audio Playback Development](/pages/en/app/application/Development/Basic%20Functions/Media/Audio/Audio%20Playback%20Development) + - [Audio Rendering Development](/pages/en/app/application/Development/Basic%20Functions/Media/Audio/Audio%20Rendering%20Development) + - [Audio Recording Development](/pages/en/app/application/Development/Basic%20Functions/Media/Audio/Audio%20Recording%20Development) + - [Audio Capture Development](/pages/en/app/application/Development/Basic%20Functions/Media/Audio/Audio%20Capture%20Development) + - Video + - [Video Playback Development](/pages/en/app/application/Development/Basic%20Functions/Media/Video/Video%20Playback%20Development) + - Image + - [Image Development](/pages/en/app/application/Development/Basic%20Functions/Media/Image/Image%20Development) + - Security + - User Authentication + - [User Authentication Overview](/pages/en/app/application/Development/Basic%20Functions/Security/User%20Authentication/User%20Authentication%20Overview) + - [User Authentication Development](/pages/en/app/application/Development/Basic%20Functions/Security/User%20Authentication/User%20Authentication%20Development) + - hapsigner + - [hapsigner Guide](/pages/en/app/application/Development/Basic%20Functions/Security/hapsigner/hapsigner%20Guide) + - Connectivity + - IPC & RPC + - [IPC & RPC Overview](/pages/en/app/application/Development/Basic%20Functions/Connectivity/IPC%20%26%20RPC/IPC%20%26%20RPC%20Overview) + - [IPC & RPC Development Guidelines](/pages/en/app/application/Development/Basic%20Functions/Connectivity/IPC%20%26%20RPC/IPC%20%26%20RPC%20Development%20Guidelines) + - [Subscribing to State Changes of a Remote Object](/pages/en/app/application/Development/Basic%20Functions/Connectivity/IPC%20%26%20RPC/Subscribing%20to%20State%20Changes%20of%20a%20Remote%20Object) + - Data Management + - Distributed Data Service + - [Distributed Data Service Overview](/pages/en/app/application/Development/Basic%20Functions/Data%20Management/Distributed%20Data%20Service/Distributed%20Data%20Service%20Overview) + - [Distributed Data Service Development](/pages/en/app/application/Development/Basic%20Functions/Data%20Management/Distributed%20Data%20Service/Distributed%20Data%20Service%20Development) + - Relational Database Overview + - [RDB Overview](/pages/en/app/application/Development/Basic%20Functions/Data%20Management/Relational%20Database%20Overview/RDB%20Overview) + - [RDB Development](/pages/en/app/application/Development/Basic%20Functions/Data%20Management/Relational%20Database%20Overview/RDB%20Development) + - Lightweight Data Store + - [Lightweight Data Store Overview](/pages/en/app/application/Development/Basic%20Functions/Data%20Management/Lightweight%20Data%20Store/Lightweight%20Data%20Store%20Overview) + - [Lightweight Data Store Development](/pages/en/app/application/Development/Basic%20Functions/Data%20Management/Lightweight%20Data%20Store/Lightweight%20Data%20Store%20Development) + - Agent-Powered Scheduled Reminders + - [Overview](/pages/en/app/application/Development/Basic%20Functions/Agent-Powered%20Scheduled%20Reminders/Overview) + - [Development Guidelines](/pages/en/app/application/Development/Basic%20Functions/Agent-Powered%20Scheduled%20Reminders/Development%20Guidelines) + - Background Task Management + - [Background Task Management Overview](/pages/en/app/application/Development/Basic%20Functions/Background%20Task%20Management/Background%20Task%20Management%20Overview) + - [Background Task Management Development](/pages/en/app/application/Development/Basic%20Functions/Background%20Task%20Management/Background%20Task%20Management%20Development) + - Device + - USB Service + - [USB Service Overview](/pages/en/app/application/Development/Basic%20Functions/Device/USB%20Service/USB%20Service%20Overview) + - [USB Service Development](/pages/en/app/application/Development/Basic%20Functions/Device/USB%20Service/USB%20Service%20Development) + - Location + - [Location Overview](/pages/en/app/application/Development/Basic%20Functions/Device/Location/Location%20Overview) + - [Obtaining Device Location Information](/pages/en/app/application/Development/Basic%20Functions/Device/Location/Obtaining%20Device%20Location%20Information) + - [Geocoding and Reverse Geocoding Capabilities](/pages/en/app/application/Development/Basic%20Functions/Device/Location/Geocoding%20and%20Reverse%20Geocoding%20Capabilities) + - Sensor + - [Sensor Overview](/pages/en/app/application/Development/Basic%20Functions/Device/Sensor/Sensor%20Overview) + - [Sensor Development](/pages/en/app/application/Development/Basic%20Functions/Device/Sensor/Sensor%20Development) + - Vibrator + - [Vibrator Overview](/pages/en/app/application/Development/Basic%20Functions/Device/Vibrator/Vibrator%20Overview) + - [Vibrator Development](/pages/en/app/application/Development/Basic%20Functions/Device/Vibrator/Vibrator%20Development) + - Device Usage Statistics + - [Device Usage Statistics Overview](/pages/en/app/application/Development/Basic%20Functions/Device%20Usage%20Statistics/Device%20Usage%20Statistics%20Overview) + - [Device Usage Statistics Development](/pages/en/app/application/Development/Basic%20Functions/Device%20Usage%20Statistics/Device%20Usage%20Statistics%20Development) + - DFX + - Application Event Logging + - [Overview of Application Event Logging](/pages/en/app/application/Development/Basic%20Functions/DFX/Application%20Event%20Logging/Overview%20of%20Application%20Event%20Logging) + - [Development Guidelines on Application Event Logging](/pages/en/app/application/Development/Basic%20Functions/DFX/Application%20Event%20Logging/Development%20Guidelines%20on%20Application%20Event%20Logging) + - Performance Tracing + - [Overview of Performance Tracing](/pages/en/app/application/Development/Basic%20Functions/DFX/Performance%20Tracing/Overview%20of%20Performance%20Tracing) + - [Development of Performance Tracing](/pages/en/app/application/Development/Basic%20Functions/DFX/Performance%20Tracing/Development%20of%20Performance%20Tracing) + - Distributed Call Chain Tracing + - [Overview of Distributed Call Chain Tracing](/pages/en/app/application/Development/Basic%20Functions/DFX/Distributed%20Call%20Chain%20Tracing/Overview%20of%20Distributed%20Call%20Chain%20Tracing) + - [Development of Distributed Call Chain Tracing](/pages/en/app/application/Development/Basic%20Functions/DFX/Distributed%20Call%20Chain%20Tracing/Development%20of%20Distributed%20Call%20Chain%20Tracing) + - Internationalization + - [Overview](/pages/en/app/application/Development/Basic%20Functions/Internationalization/Overview) + - [Internationalization Development (intl)](/pages/en/app/application/Development/Basic%20Functions/Internationalization/Internationalization%20Development%20%28intl%29) + - [Internationalization Development (i18n)](/pages/en/app/application/Development/Basic%20Functions/Internationalization/Internationalization%20Development%20%28i18n%29) +- Tools + - [DevEco Studio (OpenHarmony) User Guide](/pages/en/app/application/Tools/DevEco%20Studio%20%28OpenHarmony%29%20User%20Guide) +- Hands-On Tutorials + - [Samples](https://gitee.com/openharmony/app_samples/blob/master/README.md) +- API References + - Compent Reference (JavaScript-based Web-like Development Paradigm) + - Components + - Common + - [Universal Attributes](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Common/Universal%20Attributes) + - [Universal Styles](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Common/Universal%20Styles) + - [Universal Events](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Common/Universal%20Events) + - [Universal Methods](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Common/Universal%20Methods) + - [Animation Styles](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Common/Animation%20Styles) + - [Gradient Styles](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Common/Gradient%20Styles) + - [Transition Styles](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Common/Transition%20Styles) + - [Custom Font Styles](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Common/Custom%20Font%20Styles) + - [Atomic Layout](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Common/Atomic%20Layout) + - Container Components + - [badge](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/badge) + - [dialog](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/dialog) + - [div](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/div) + - [form](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/form) + - [list](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/list) + - [list-item](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/list-item) + - [list-item-group](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/list-item-group) + - [panel](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/panel) + - [popup](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/popup) + - [refresh](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/refresh) + - [stack](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/stack) + - [stepper](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/stepper) + - [stepper-item](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/stepper-item) + - [swiper](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/swiper) + - [tabs](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/tabs) + - [tab-bar](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/tab-bar) + - [tab-content](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Container%20Components/tab-content) + - Basic Components + - [button](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/button) + - [chart](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/chart) + - [divider](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/divider) + - [image](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/image) + - [image-animator](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/image-animator) + - [input](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/input) + - [label](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/label) + - [marquee](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/marquee) + - [menu](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/menu) + - [option](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/option) + - [picker](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/picker) + - [picker-view](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/picker-view) + - [piece](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/piece) + - [progress](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/progress) + - [qrcode](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/qrcode) + - [rating](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/rating) + - [richtext](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/richtext) + - [search](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/search) + - [select](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/select) + - [slider](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/slider) + - [span](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/span) + - [switch](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/switch) + - [text](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/text) + - [textarea](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/textarea) + - [toolbar](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/toolbar) + - [toolbar-item](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/toolbar-item) + - [toggle](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/toggle) + - [web](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Basic%20Components/web) + - Media Components + - [video](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Media%20Components/video) + - Canvas Components + - [canvas](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Canvas%20Components/canvas) + - [CanvasRenderingContext2D](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Canvas%20Components/CanvasRenderingContext2D) + - [Image](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Canvas%20Components/Image) + - [CanvasGradient](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Canvas%20Components/CanvasGradient) + - [ImageData](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Canvas%20Components/ImageData) + - [Path2D](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Canvas%20Components/Path2D) + - [ImageBitmap](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Canvas%20Components/ImageBitmap) + - [OffscreenCanvas](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Canvas%20Components/OffscreenCanvas) + - [OffscreenCanvasRenderingContext2D](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Canvas%20Components/OffscreenCanvasRenderingContext2D) + - Grid + - [Basic Concepts](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Grid/Basic%20Concepts) + - [grid-container](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Grid/grid-container) + - [grid-row](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Grid/grid-row) + - [grid-col](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/Grid/grid-col) + - SVG Components + - [Universal Attributes](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/Universal%20Attributes) + - [svg](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/svg) + - [rect](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/rect) + - [circle](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/circle) + - [ellipse](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/ellipse) + - [path](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/path) + - [line](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/line) + - [polyline](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/polyline) + - [polygon](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/polygon) + - [text](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/text) + - [tspan](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/tspan) + - [textPath](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/textPath) + - [animate](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/animate) + - [animateMotion](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/animateMotion) + - [animateTransform](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Components/SVG%20Components/animateTransform) + - Custom Components + - [Basic Usage](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Custom%20Components/Basic%20Usage) + - [Custom Events](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Custom%20Components/Custom%20Events) + - [props](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Custom%20Components/props) + - [Event Parameter](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Custom%20Components/Event%20Parameter) + - [slot](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Custom%20Components/slot) + - [Lifecycle Definition](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Custom%20Components/Lifecycle%20Definition) + - [Type Attributes](/pages/en/app/application/API%20References/Compent%20Reference%20%28JavaScript-based%20Web-like%20Development%20Paradigm%29/Type%20Attributes) + - Compent Reference (TypeScript-based Declarative Development Paradigm) + - Components + - Universal Components + - Universal Events + - [Click Event](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Events/Click%20Event) + - [Touch](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Events/Touch) + - [Show/Hide Event](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Events/Show%20Hide%20Event) + - [Drag/Drop Event](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Events/Drag%20Drop%20Event) + - [Key Event](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Events/Key%20Event) + - [Focus Event](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Events/Focus%20Event) + - [Mouse Event](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Events/Mouse%20Event) + - [Component Area Change Event](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Events/Component%20Area%20Change%20Event) + - Universal Attributes + - [Size](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Size) + - [Location](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Location) + - [Layout Constraints](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Layout%20Constraints) + - [Flex Layout](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Flex%20Layout) + - [Border Configuration](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Border%20Configuration) + - [Background](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Background) + - [Opacity](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Opacity) + - [Visibility](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Visibility) + - [Enable/Disable](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Enable%20Disable) + - [Overlay](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Overlay) + - [Z-order Control](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Z-order%20Control) + - [Transformation](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Transformation) + - [Image Effect Configuration](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Image%20Effect%20Configuration) + - [Shape Clipping](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Shape%20Clipping) + - [Text Style](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Text%20Style) + - [Grid](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Grid) + - [Gradient Color](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Gradient%20Color) + - [Popup Control](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Popup%20Control) + - [Menu Control](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Menu%20Control) + - [Click Control](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Click%20Control) + - [Focus Control](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Focus%20Control) + - [Hover Effect](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Hover%20Effect) + - [Component ID](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Component%20ID) + - [Touch Target](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Touch%20Target) + - [Polymorphic Style](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Universal%20Attributes/Polymorphic%20Style) + - Gesture Processing + - [Gesture Binding Methods](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Gesture%20Processing/Gesture%20Binding%20Methods) + - Basic Gestures + - [TapGesture](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Gesture%20Processing/Basic%20Gestures/TapGesture) + - [LongPressGesture](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Gesture%20Processing/Basic%20Gestures/LongPressGesture) + - [PanGesture](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Gesture%20Processing/Basic%20Gestures/PanGesture) + - [PinchGesture](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Gesture%20Processing/Basic%20Gestures/PinchGesture) + - [RotationGesture](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Gesture%20Processing/Basic%20Gestures/RotationGesture) + - [SwipeGesture](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Gesture%20Processing/Basic%20Gestures/SwipeGesture) + - [Combined Gestures](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Universal%20Components/Gesture%20Processing/Combined%20Gestures) + - Basic Components + - [Blank](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Blank) + - [Button](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Button) + - [Checkbox](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Checkbox) + - [CheckboxGroup](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/CheckboxGroup) + - [DataPanel](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/DataPanel) + - [DatePicker](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/DatePicker) + - [Divider](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Divider) + - [Gauge](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Gauge) + - [Image](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Image) + - [ImageAnimator](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/ImageAnimator) + - [LoadingProgress](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/LoadingProgress) + - [Marquee](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Marquee) + - [Navigation](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Navigation) + - [PatternLock](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/PatternLock) + - [PluginComponent](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/PluginComponent) + - [Progress](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Progress) + - [QRCode](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/QRCode) + - [Radio](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Radio) + - [Rating](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Rating) + - [RichText](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/RichText) + - [ScrollBar](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/ScrollBar) + - [Search](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Search) + - [Select](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Select) + - [Slider](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Slider) + - [Span](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Span) + - [Stepper](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Stepper) + - [StepperItem](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/StepperItem) + - [Text](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Text) + - [TextArea](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/TextArea) + - [TextClock](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/TextClock) + - [TextInput](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/TextInput) + - [TextPicker](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/TextPicker) + - [TextTimer](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/TextTimer) + - [TimePicker](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/TimePicker) + - [Toggle](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Toggle) + - [Web](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Web) + - [Xcomponent](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Basic%20Components/Xcomponent) + - Container Components + - [AlphabetIndexer](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/AlphabetIndexer) + - [Badge](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/Badge) + - [Column](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/Column) + - [ColumnSplit](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/ColumnSplit) + - [Counter](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/Counter) + - [Flex](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/Flex) + - [GridContainer](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/GridContainer) + - [Grid](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/Grid) + - [GridItem](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/GridItem) + - [List](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/List) + - [ListItem](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/ListItem) + - [Navigator](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/Navigator) + - [Panel](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/Panel) + - [Refresh](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/Refresh) + - [Row](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/Row) + - [RowSplit](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/RowSplit) + - [Scroll](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/Scroll) + - [SideBarContainer](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/SideBarContainer) + - [Stack](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/Stack) + - [Swiper](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/Swiper) + - [Tabs](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/Tabs) + - [TabContent](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Container%20Components/TabContent) + - Media Components + - [Video](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Media%20Components/Video) + - Drawing Components + - [Circle](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Drawing%20Components/Circle) + - [Ellipse](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Drawing%20Components/Ellipse) + - [Line](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Drawing%20Components/Line) + - [Polyline](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Drawing%20Components/Polyline) + - [Polygon](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Drawing%20Components/Polygon) + - [Path](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Drawing%20Components/Path) + - [Rect](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Drawing%20Components/Rect) + - [Shape](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Drawing%20Components/Shape) + - Canvas Components + - [Canvas](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Canvas%20Components/Canvas) + - [CanvasRenderingContext2D](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Canvas%20Components/CanvasRenderingContext2D) + - [OffscreenCanvasRenderingConxt2D](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Canvas%20Components/OffscreenCanvasRenderingConxt2D) + - [Lottie](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Canvas%20Components/Lottie) + - [Path2D](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Canvas%20Components/Path2D) + - [CanvasGradient](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Canvas%20Components/CanvasGradient) + - [ImageBitmap](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Canvas%20Components/ImageBitmap) + - [ImageData](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Components/Canvas%20Components/ImageData) + - Animation + - [Attribute Animation](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Animation/Attribute%20Animation) + - [Explicit Animation](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Animation/Explicit%20Animation) + - Transition Animation + - [Page Transition](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Animation/Transition%20Animation/Page%20Transition) + - [Component Transition](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Animation/Transition%20Animation/Component%20Transition) + - [Transition of Shared Elements](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Animation/Transition%20Animation/Transition%20of%20Shared%20Elements) + - [Motion Path Animation](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Animation/Motion%20Path%20Animation) + - [Matrix Transformation](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Animation/Matrix%20Transformation) + - [Interpolation Calculation](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Animation/Interpolation%20Calculation) + - Global UI Methods + - Dialog Box + - [Alert Dialog Box](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Global%20UI%20Methods/Dialog%20Box/Alert%20Dialog%20Box) + - [Action Sheet](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Global%20UI%20Methods/Dialog%20Box/Action%20Sheet) + - [Custom Dialog Box](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Global%20UI%20Methods/Dialog%20Box/Custom%20Dialog%20Box) + - [Date Picker Dialog Box](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Global%20UI%20Methods/Dialog%20Box/Date%20Picker%20Dialog%20Box) + - [Text Picker Dialog Box](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Global%20UI%20Methods/Dialog%20Box/Text%20Picker%20Dialog%20Box) + - [Menu](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Global%20UI%20Methods/Menu) + - [Built-in Enums](/pages/en/app/application/API%20References/Compent%20Reference%20%28TypeScript-based%20Declarative%20Development%20Paradigm%29/Built-in%20Enums) + - APIs + - Ability Framework + + - [@ohos.ability.dataUriUtils](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ohos.ability.dataUriUtils) + - [@ohos.application.Ability](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ohos.application.Ability) + - [@ohos.application.AbilityConstant](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ohos.application.AbilityConstant) + - [@ohos.application.AbilityStage ](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ohos.application.AbilityStage%20) + - [@ohos.application.appManager](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ohos.application.appManager) + - [@ohos.application.Configuration](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ohos.application.Configuration) + - [@ohos.application.ConfigurationConstant](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ohos.application.ConfigurationConstant) + - [@ohos.ability.featureAbility](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ohos.ability.featureAbility) + - [@ohos.application.formBindingData](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ohos.application.formBindingData) + - [@ohos.application.FormExtension](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ohos.application.FormExtension) + - [@ohos.application.missionManager](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ohos.application.missionManager) + - [@ohos.application.formProvider](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ohos.application.formProvider) + - [@ohos.ability.particleAbility](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ohos.ability.particleAbility) + - [@ohos.application.ServiceExtensionAbility](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ohos.application.ServiceExtensionAbility) + - [@ohos.application.uriPermissionManager](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ohos.application.uriPermissionManager) + - [@ohos.wantAgent](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ohos.wantAgent) + - [dataAbilityHelper](/pages/en/app/application/API%20References/APIs/Ability%20Framework/dataAbilityHelper) + - [context](/pages/en/app/application/API%20References/APIs/Ability%20Framework/context) + - [AbilityContext](/pages/en/app/application/API%20References/APIs/Ability%20Framework/AbilityContext) + - [AbilityRunningInfo](/pages/en/app/application/API%20References/APIs/Ability%20Framework/AbilityRunningInfo) + - [AbilityStageContext](/pages/en/app/application/API%20References/APIs/Ability%20Framework/AbilityStageContext) + - [Context](/pages/en/app/application/API%20References/APIs/Ability%20Framework/Context) + - [ExtensionContext](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ExtensionContext) + - [ExtensionRunningInfo](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ExtensionRunningInfo) + - [FormExtensionContext](/pages/en/app/application/API%20References/APIs/Ability%20Framework/FormExtensionContext) + - [MissionSnapshot](/pages/en/app/application/API%20References/APIs/Ability%20Framework/MissionSnapshot) + - [PermissionRequestResult](/pages/en/app/application/API%20References/APIs/Ability%20Framework/PermissionRequestResult) + - [ProcessRunningInfo](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ProcessRunningInfo) + - [ServiceExtensionContext](/pages/en/app/application/API%20References/APIs/Ability%20Framework/ServiceExtensionContext) + + - Common Event and Notification + + - [@ohos.commonEvent](/pages/en/app/application/API%20References/APIs/Common%20Event%20and%20Notification/ohos.commonEvent) + - [@ohos.events.emitter](/pages/en/app/application/API%20References/APIs/Common%20Event%20and%20Notification/ohos.events.emitter) + - [@ohos.notification](/pages/en/app/application/API%20References/APIs/Common%20Event%20and%20Notification/ohos.notification) + - [@ohos.reminderAgent](/pages/en/app/application/API%20References/APIs/Common%20Event%20and%20Notification/ohos.reminderAgent) + - [EventHub](/pages/en/app/application/API%20References/APIs/Common%20Event%20and%20Notification/EventHub) + + - Bundle Management + + - [@ohos.bundle](/pages/en/app/application/API%20References/APIs/Bundle%20Management/ohos.bundle) + - [@ohos.bundleState ](/pages/en/app/application/API%20References/APIs/Bundle%20Management/ohos.bundleState%20) + - [@ohos.zlib](/pages/en/app/application/API%20References/APIs/Bundle%20Management/ohos.zlib) + + - UI Page + + - [@ohos.animator](/pages/en/app/application/API%20References/APIs/UI%20Page/ohos.animator) + + - Graphics + + - [@ohos.display ](/pages/en/app/application/API%20References/APIs/Graphics/ohos.display%20) + - [@ohos.screenshot](/pages/en/app/application/API%20References/APIs/Graphics/ohos.screenshot) + - [@ohos.window](/pages/en/app/application/API%20References/APIs/Graphics/ohos.window) + - [webgl](/pages/en/app/application/API%20References/APIs/Graphics/webgl) + - [webgl2](/pages/en/app/application/API%20References/APIs/Graphics/webgl2) + + - Media + + - [@ohos.multimedia.audio](/pages/en/app/application/API%20References/APIs/Media/ohos.multimedia.audio) + - [@ohos.multimedia.image](/pages/en/app/application/API%20References/APIs/Media/ohos.multimedia.image) + - [@ohos.multimedia.media](/pages/en/app/application/API%20References/APIs/Media/ohos.multimedia.media) + - [@ohos.multimedia.medialibrary](/pages/en/app/application/API%20References/APIs/Media/ohos.multimedia.medialibrary) + + - Resource Management + - [@ohos.i18n](/pages/en/app/application/API%20References/APIs/Resource%20Management/ohos.i18n) + - [@ohos.intl](/pages/en/app/application/API%20References/APIs/Resource%20Management/ohos.intl) + - [@ohos.resourceManager](/pages/en/app/application/API%20References/APIs/Resource%20Management/ohos.resourceManager) + + - Resource Scheduling + + - [@ohos.backgroundTaskManager](/pages/en/app/application/API%20References/APIs/Resource%20Scheduling%20/ohos.backgroundTaskManager) + + - Custom Management + + - [@ohos.configPolicy](/pages/en/app/application/API%20References/APIs/Custom%20Management/ohos.configPolicy) + + - Security + + - [@ohos.abilityAccessCtrl](/pages/en/app/application/API%20References/APIs/Security/ohos.abilityAccessCtrl) + - [@ohos.userIAM.userAuth ](/pages/en/app/application/API%20References/APIs/Security/ohos.userIAM.userAuth%20) + + - Data Management + + - [@ohos.data.dataAbility ](/pages/en/app/application/API%20References/APIs/Data%20Management/ohos.data.dataAbility%20) + - [@ohos.data.distributedData](/pages/en/app/application/API%20References/APIs/Data%20Management/ohos.data.distributedData) + - [@ohos.data.distributedDataObject](/pages/en/app/application/API%20References/APIs/Data%20Management/ohos.data.distributedDataObject) + - [@ohos.data.rdb](/pages/en/app/application/API%20References/APIs/Data%20Management/ohos.data.rdb) + - [@ohos.settings](/pages/en/app/application/API%20References/APIs/Data%20Management/ohos.settings) + - [resultSet](/pages/en/app/application/API%20References/APIs/Data%20Management/resultSet) + + - File Management + + - [@ohos.environment](/pages/en/app/application/API%20References/APIs/File%20Management/ohos.environment) + - [@ohos.fileio](/pages/en/app/application/API%20References/APIs/File%20Management/ohos.fileio) + - [@ohos.fileManager](/pages/en/app/application/API%20References/APIs/File%20Management/ohos.fileManager) + - [@ohos.statfs](/pages/en/app/application/API%20References/APIs/File%20Management/ohos.statfs) + - [@ohos.storageStatistics](/pages/en/app/application/API%20References/APIs/File%20Management/ohos.storageStatistics) + + - Telephony Service + + - [@ohos.contact](/pages/en/app/application/API%20References/APIs/Telephony%20Service/ohos.contact) + - [@ohos.telephony.call](/pages/en/app/application/API%20References/APIs/Telephony%20Service/ohos.telephony.call) + - [@ohos.telephony.observer](/pages/en/app/application/API%20References/APIs/Telephony%20Service/ohos.telephony.observer) + - [@ohos.telephony.radio](/pages/en/app/application/API%20References/APIs/Telephony%20Service/ohos.telephony.radio) + - [@ohos.telephony.sim](/pages/en/app/application/API%20References/APIs/Telephony%20Service/ohos.telephony.sim) + - [@ohos.telephony.sms](/pages/en/app/application/API%20References/APIs/Telephony%20Service/ohos.telephony.sms) + - [@ohos.telephony.data](/pages/en/app/application/API%20References/APIs/Telephony%20Service/ohos.telephony.data) + + - Network Management + - [@ohos.net.connection](/pages/en/app/application/API%20References/APIs/Network%20Management/ohos.net.connection) + - [@ohos.net.http](/pages/en/app/application/API%20References/APIs/Network%20Management/ohos.net.http) + - [@ohos.request](/pages/en/app/application/API%20References/APIs/Network%20Management/ohos.request) + - [@ohos.net.socket](/pages/en/app/application/API%20References/APIs/Network%20Management/ohos.net.socket) + - [@ohos.net.webSocket](/pages/en/app/application/API%20References/APIs/Network%20Management/ohos.net.webSocket) + + - Connectivity + + - [@ohos.bluetooth](/pages/en/app/application/API%20References/APIs/Connectivity/ohos.bluetooth) + - [@ohos.rpc](/pages/en/app/application/API%20References/APIs/Connectivity/ohos.rpc) + - [@ohos.wifi](/pages/en/app/application/API%20References/APIs/Connectivity/ohos.wifi) + - [@ohos.wifiext](/pages/en/app/application/API%20References/APIs/Connectivity/ohos.wifiext) + + - Basic Features + + - [@ohos.accessibility](/pages/en/app/application/API%20References/APIs/Basic%20Features/ohos.accessibility) + - [@ohos.faultLogger](/pages/en/app/application/API%20References/APIs/Basic%20Features/ohos.faultLogger) + - [@ohos.hiAppEvent](/pages/en/app/application/API%20References/APIs/Basic%20Features/ohos.hiAppEvent) + - [@ohos.hichecker](/pages/en/app/application/API%20References/APIs/Basic%20Features/ohos.hichecker) + - [@ohos.hidebug](/pages/en/app/application/API%20References/APIs/Basic%20Features/ohos.hidebug) + - [@ohos.hilog](/pages/en/app/application/API%20References/APIs/Basic%20Features/ohos.hilog) + - [@ohos.hiTraceChain](/pages/en/app/application/API%20References/APIs/Basic%20Features/ohos.hiTraceChain) + - [@ohos.hiTraceMeter](/pages/en/app/application/API%20References/APIs/Basic%20Features/ohos.hiTraceMeter) + - [@ohos.pasteboard](/pages/en/app/application/API%20References/APIs/Basic%20Features/ohos.pasteboard) + - [@ohos.screenLock](/pages/en/app/application/API%20References/APIs/Basic%20Features/ohos.screenLock) + - [@ohos.systemTime](/pages/en/app/application/API%20References/APIs/Basic%20Features/ohos.systemTime) + - [@ohos.wallpaper](/pages/en/app/application/API%20References/APIs/Basic%20Features/ohos.wallpaper) + - [Timer](/pages/en/app/application/API%20References/APIs/Basic%20Features/Timer) + + - Device Management + + - [@ohos.batteryInfo ](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.batteryInfo%20) + - [@ohos.brightness](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.brightness) + - [@ohos.deviceInfo](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.deviceInfo) + - [@ohos.distributedHardware.deviceManager](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.distributedHardware.deviceManager) + - [@ohos.geolocation](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.geolocation) + - [@ohos.multimodalInput.inputConsumer](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.multimodalInput.inputConsumer) + - [@ohos.multimodalInput.inputDevice](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.multimodalInput.inputDevice) + - [@ohos.multimodalInput.inputMonitor](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.multimodalInput.inputMonitor) + - [@ohos.power](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.power) + - [@ohos.runningLock](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.runningLock) + - [@ohos.sensor](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.sensor) + - [@ohos.systemParameter](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.systemParameter) + - [@ohos.thermal](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.thermal) + - [@ohos.update](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.update) + - [@ohos.usb](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.usb) + - [@ohos.vibrator](/pages/en/app/application/API%20References/APIs/Device%20Management/ohos.vibrator) + + - Account Management + + - [@ohos.account.appAccount](/pages/en/app/application/API%20References/APIs/Account%20Management/ohos.account.appAccount) + - [@ohos.account.distributedAccount](/pages/en/app/application/API%20References/APIs/Account%20Management/ohos.account.distributedAccount) + - [@ohos.account.osAccount](/pages/en/app/application/API%20References/APIs/Account%20Management/ohos.account.osAccount) + + - Language Base Class Library + + - [@ohos.convertxml](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.convertxml) + - [@ohos.process](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.process) + - [@ohos.uri](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.uri) + - [@ohos.url](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.url) + - [@ohos.util](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util) + - [@ohos.util.ArrayList](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.ArrayList) + - [@ohos.util.Deque](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.Deque) + - [@ohos.util.HashMap](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.HashMap) + - [@ohos.util.HashSet](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.HashSet) + - [@ohos.util.LightWeightMap](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.LightWeightMap) + - [@ohos.util.LightWeightSet](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.LightWeightSet) + - [@ohos.util.LinkedList](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.LinkedList) + - [@ohos.util.List](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.List) + - [@ohos.util.PlainArray](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.PlainArray) + - [@ohos.util.Queue](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.Queue) + - [@ohos.util.Stack](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.Stack) + - [@ohos.util.TreeMap](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.TreeMap) + - [@ohos.util.TreeSet](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.TreeSet) + - [@ohos.util.Vector](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.util.Vector) + - [@ohos.worker](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.worker) + - [@ohos.xml](/pages/en/app/application/API%20References/APIs/Language%20Base%20Class%20Library/ohos.xml) + + - APIs No Longer Maintained + + - [@ohos.bytrace](/pages/en/app/application/API%20References/APIs/APIs%20No%20Longer%20Maintained/ohos.bytrace) + - [@ohos.data.storage](/pages/en/app/application/API%20References/APIs/APIs%20No%20Longer%20Maintained/ohos.data.storage) + - [@system.sensor](/pages/en/app/application/API%20References/APIs/APIs%20No%20Longer%20Maintained/system.sensor) + - [@system.vibrator](/pages/en/app/application/API%20References/APIs/APIs%20No%20Longer%20Maintained/system.vibrator) + - [console](/pages/en/app/application/API%20References/APIs/APIs%20No%20Longer%20Maintained/console) \ No newline at end of file diff --git a/website/docs/extras/en/application-dev/windowmanager/Readme-EN.md b/website/docs/extras/en/application-dev/windowmanager/Readme-EN.md new file mode 100644 index 0000000000000000000000000000000000000000..acb77d7cb668300a152db52d8aeba784f4d136a3 --- /dev/null +++ b/website/docs/extras/en/application-dev/windowmanager/Readme-EN.md @@ -0,0 +1,27 @@ +--- +title: "Readme-EN" +prepermalink: /extras/73e7d965c5d7739d265b13c187614337/ +permalink: /extras/73e7d965c5d7739d265b13c187614337/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/windowmanager/Readme-EN.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [Readme-EN] +--- +# Window Manager + +* Window + * [Window Overview](/pages/en/app/application/Development/Basic%20Functions/Window%20Manager/Window/Window%20Overview) + * [Window Development](/pages/en/app/application/Development/Basic%20Functions/Window%20Manager/Window/Window%20Development) +* Display + * [Display Overview](/pages/en/app/application/Development/Basic%20Functions/Window%20Manager/Display/Display%20Overview) + * [Display Development](/pages/en/app/application/Development/Basic%20Functions/Window%20Manager/Display/Display%20Development) +* Screenshot + * [Screenshot Overview](/pages/en/app/application/Development/Basic%20Functions/Window%20Manager/Screenshot/Screenshot%20Overview) + * [Screenshot Development](/pages/en/app/application/Development/Basic%20Functions/Window%20Manager/Screenshot/Screenshot%20Development) + diff --git a/website/docs/extras/en/application-dev/work-scheduler/Readme-EN.md b/website/docs/extras/en/application-dev/work-scheduler/Readme-EN.md new file mode 100644 index 0000000000000000000000000000000000000000..9bdb2b3c2390a53dcbcd272eefccf3d27cacf4fa --- /dev/null +++ b/website/docs/extras/en/application-dev/work-scheduler/Readme-EN.md @@ -0,0 +1,20 @@ +--- +title: "Readme-EN" +prepermalink: /extras/5855eeb270960483eab26b0116ebd0cf/ +permalink: /extras/5855eeb270960483eab26b0116ebd0cf/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/work-scheduler/Readme-EN.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [Readme-EN] +--- +# Work Scheduler + +- Background Tasks + - [Work Scheduler Overview](/extras/68593cbe19ccb399c3816d76605ece1b/) + - [Work Scheduler Development](/extras/fcfd17f1c9f31547bbcaae4a1e8640e6/) diff --git a/website/docs/extras/en/application-dev/work-scheduler/work-scheduler-dev-guide.md b/website/docs/extras/en/application-dev/work-scheduler/work-scheduler-dev-guide.md new file mode 100644 index 0000000000000000000000000000000000000000..4ef3a28bce87a5628177856e44eea41f6aebe84c --- /dev/null +++ b/website/docs/extras/en/application-dev/work-scheduler/work-scheduler-dev-guide.md @@ -0,0 +1,197 @@ +--- +title: "work-scheduler-dev-guide" +prepermalink: /extras/fcfd17f1c9f31547bbcaae4a1e8640e6/ +permalink: /extras/fcfd17f1c9f31547bbcaae4a1e8640e6/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/work-scheduler/work-scheduler-dev-guide.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [work-scheduler-dev-guide] +--- +# Work Scheduler Development + +## When to Use + +If your application needs to execute a non-real-time task, for example, data learning, you can harness the Work Scheduler mechanism, which will schedule the task based on the storage space, power consumption, temperature, and more when the preset conditions are met. + + +## Available APIs +Import the **workScheduler** package to implement registration: +```js +import workScheduler from '@ohos.workScheduler'; +``` + +Import the **WorkSchedulerExtensionAbility** package to implement callback: +```js +import WorkSchedulerExtensionAbility from '@ohos.WorkSchedulerExtensionAbility'; +``` + +### Work Scheduler + +**Table 1** Major workScheduler APIs + + API | Description + ------------------------------------------------------------ | ------------------------------------------------------------ + function startWork(work: WorkInfo): boolean; | Starts a Work Scheduler task. + function stopWork(work: WorkInfo, needCancel?: boolean): boolean; | Stops a Work Scheduler task. + function getWorkStatus(workId: number, callback: AsyncCallback): void; | Obtains the status of a Work Scheduler task. This method uses an asynchronous callback to return the result. + function getWorkStatus(workId: number): Promise; | Obtains the status of a Work Scheduler task. This method uses a promise to return the result. + function obtainAllWorks(callback: AsyncCallback): Array; | Obtains Work Scheduler tasks. This method uses an asynchronous callback to return the result. + function obtainAllWorks(): Promise>; | Obtains Work Scheduler tasks. This method uses a promise to return the result. + function stopAndClearWorks(): boolean; | Stops and clears Work Scheduler tasks. + function isLastWorkTimeOut(workId: number, callback: AsyncCallback): boolean; | Checks whether the last execution of the specified task has timed out. This method uses an asynchronous callback to return the result. It is applicable to repeated tasks. + function isLastWorkTimeOut(workId: number): Promise; | Checks whether the last execution of the specified task has timed out. This method uses a promise to return the result. It is applicable to repeated tasks. + +**Table 2** WorkInfo parameters + +API|Description|Type +---------------------------------------------------------|-----------------------------------------|--------------------------------------------------------- +workId | Work ID. Mandatory.|number +bundleName | Name of the Work Scheduler task bundle. Mandatory.|string +abilityName | Name of the component to be notified by a Work Scheduler callback.|string +networkType | Network type.| NetworkType +isCharging | Whether the device is charging.| bool +chargerType | Charging type.| ChargingType +batteryLevel | Battery level.| number +batteryStatus| Battery status.| BatteryStatus +storageRequest|Storage status.| StorageRequest +isRepeat|Whether the task is repeated.| boolean +repeatCycleTime |Repeat interval.| number +repeatCount |Number of repeat times.| number + +**Table 3** Work Scheduler callbacks + +API | Description +---------------------------------------------------------|----------------------------------------- +function onWorkStart(work: WorkInfo): void; | Triggered when the Work Scheduler task starts. +function onWorkStop(work: WorkInfo): void; | Triggered when the Work Scheduler task stops. + +### How to Develop + +**Implementing WorkSchedulerExtensionAbility** + + import WorkSchedulerExtensionAbility from '@ohos.WorkSchedulerExtensionAbility'; + + export default class MyWorkSchedulerExtensionAbility extends WorkSchedulerExtensionAbility { + onWorkStart(workInfo) { + console.log('MyWorkSchedulerExtensionAbility onWorkStart' + JSON.stringify(workInfo)); + } + onWorkStop(workInfo) { + console.log('MyWorkSchedulerExtensionAbility onWorkStop' + JSON.stringify(workInfo)); + } + } + + +**Registering a Work Scheduler Task** + + import workScheduler from '@ohos.workScheduler'; + + let workInfo = { + workId: 1, + batteryLevel:50, + batteryStatus:workScheduler.BatteryStatus.BATTERY_STATUS_LOW, + isRepeat: false, + isPersisted: true, + bundleName: "com.example.myapplication", + abilityName: "MyExtension" + } + var res = workScheduler.startWork(workInfo); + console.info("workschedulerLog res:" + res); + + +**Canceling the Work Scheduler Task** + + + import workScheduler from '@ohos.workScheduler'; + + let workInfo = { + workId: 1, + batteryLevel:50, + batteryStatus:workScheduler.BatteryStatus.BATTERY_STATUS_LOW, + isRepeat: false, + isPersisted: true, + bundleName: "com.example.myapplication", + abilityName: "MyExtension" + } + var res = workScheduler.stopWork(workInfo, false); + console.info("workschedulerLog res:" + res); + + +**Obtaining a Specified Work Scheduler Task** + +1. Callback syntax + + workScheduler.getWorkStatus(50, (err, res) => { + if (err) { + console.info('workschedulerLog getWorkStatus failed, because:' + err.data); + } else { + for (let item in res) { + console.info('workschedulerLog getWorkStatuscallback success,' + item + ' is:' + res[item]); + } + } + }); + + +2. Promise syntax + + workScheduler.getWorkStatus(50).then((res) => { + for (let item in res) { + console.info('workschedulerLog getWorkStatus success,' + item + ' is:' + res[item]); + } + }).catch((err) => { + console.info('workschedulerLog getWorkStatus failed, because:' + err.data); + }) + + +**Obtaining All Work Scheduler Tasks** + +1. Callback syntax + + workScheduler.obtainAllWorks((err, res) =>{ + if (err) { + console.info('workschedulerLog obtainAllWorks failed, because:' + err.data); + } else { + console.info('workschedulerLog obtainAllWorks success, data is:' + JSON.stringify(res)); + } + }); + +2. Promise syntax + + workScheduler.obtainAllWorks().then((res) => { + console.info('workschedulerLog obtainAllWorks success, data is:' + JSON.stringify(res)); + }).catch((err) => { + console.info('workschedulerLog obtainAllWorks failed, because:' + err.data); + }) + +**Stopping and Clearing Work Scheduler Tasks** + + let res = workScheduler.stopAndClearWorks(); + console.info("workschedulerLog res:" + res); + +**Checking Whether the Last Execution Has Timed Out** + +1. Callback syntax + + workScheduler.isLastWorkTimeOut(500, (err, res) =>{ + if (err) { + console.info('workschedulerLog isLastWorkTimeOut failed, because:' + err.data); + } else { + console.info('workschedulerLog isLastWorkTimeOut success, data is:' + res); + } + }); + +2. Promise syntax + + workScheduler.isLastWorkTimeOut(500) + .then(res => { + console.info('workschedulerLog isLastWorkTimeOut success, data is:' + res); + }) + .catch(err => { + console.info('workschedulerLog isLastWorkTimeOut failed, because:' + err.data); + }); + }) diff --git a/website/docs/extras/en/application-dev/work-scheduler/work-scheduler-overview.md b/website/docs/extras/en/application-dev/work-scheduler/work-scheduler-overview.md new file mode 100644 index 0000000000000000000000000000000000000000..3af83c4450976ddbe6efc667bfec611e470863e4 --- /dev/null +++ b/website/docs/extras/en/application-dev/work-scheduler/work-scheduler-overview.md @@ -0,0 +1,35 @@ +--- +title: "work-scheduler-overview" +prepermalink: /extras/68593cbe19ccb399c3816d76605ece1b/ +permalink: /extras/68593cbe19ccb399c3816d76605ece1b/ +relpath: "OpenHarmony-3.1-Release/en/application-dev/work-scheduler/work-scheduler-overview.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [work-scheduler-overview] +--- +# Work Scheduler Overview + +The Work Scheduler provides a mechanism for applications to execute non-real-time tasks when the system is idle. If the preset conditions are met, the tasks will be placed in the execution queue and scheduled when the system is idle. + +## Usage + +If your application needs to execute a non-real-time task, for example, data learning, you can harness the Work Scheduler mechanism, which will schedule the task based on the storage space, power consumption, temperature, and more when the preset conditions are met. + +## Constraints + +The use of the Work Scheduler must comply with the following restrictions and rules: + +- **Timeout**: The Work Scheduler callback can run only within the specified period of time. After the timeout, the callback automatically stops. +- **WorkInfo setting** + +(1) **workId**, **bundleName**, and **abilityName** are mandatory. **bundleName** must be set to the name of the current application. Otherwise, the verification will fail. + +(2) At least one condition must be set. + +(3) The repeat interval must be at least 20 minutes and must work with the Always repeat pattern or repeat times. diff --git a/website/docs/extras/en/compatibility/readme.md b/website/docs/extras/en/compatibility/readme.md new file mode 100644 index 0000000000000000000000000000000000000000..feeb8cf66695a0bf59516e4d45df10b1ae8e429b --- /dev/null +++ b/website/docs/extras/en/compatibility/readme.md @@ -0,0 +1,16 @@ +--- +title: "readme" +prepermalink: /extras/d3d5cc4a84be7581b0223ee440028092/ +permalink: /extras/d3d5cc4a84be7581b0223ee440028092/ +relpath: "OpenHarmony-3.1-Release/en/compatibility/readme.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [readme] +--- +Todo diff --git a/website/docs/extras/en/contribute/OpenHarmony-64bits-coding-guide.md b/website/docs/extras/en/contribute/OpenHarmony-64bits-coding-guide.md new file mode 100644 index 0000000000000000000000000000000000000000..15f00f0e4b54c20861fa47df43f296dbbd3cff82 --- /dev/null +++ b/website/docs/extras/en/contribute/OpenHarmony-64bits-coding-guide.md @@ -0,0 +1,605 @@ +--- +title: "OpenHarmony-64bits-coding-guide" +prepermalink: /extras/be699528e26fd59c3792372bc1d0da0d/ +permalink: /extras/be699528e26fd59c3792372bc1d0da0d/ +relpath: "OpenHarmony-3.1-Release/en/contribute/OpenHarmony-64bits-coding-guide.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [OpenHarmony-64bits-coding-guide] +--- +# 32- and 64-Bit Portability Coding Guide + +## About This Document + +### Purpose + +OpenHarmony aims to build an open, distributed OS framework for smart IoT devices in the full-scenario, full-connectivity, and full-intelligence era. It has the following technical features: hardware collaboration for resource sharing, one-time development for multi-device deployment, and a unified OS for flexible deployment. +OpenHarmony supports the following system types: + +1. Mini system: a device oriented to devices that have MCU processors such as ARM Cortex-M and 32-bit RISC-V. These devices have limited hardware resources. The minimum device memory is 128 KiB. +2. Small system: a device oriented to devices that have application processors such as 64-bit ARM Cortex-A. The minimum device memory is 1 MiB. +3. Standard system: a device oriented to devices that have application processors such as 64-bit ARM Cortex-A. The minimum device memory is 128 MiB. + +OpenHarmony code can run on 32- and 64-bit devices. For easier code portability, clear coding specifications are necessary. This document stipulates the specifications on code porting and 64-bit coding, helping you improve code standardization and portability. + +### Application Scope + +C and C++ code for the user space and kernel space, without distinguishing the programming language standards. + +### Differences Between 32-Bit OS and 64-Bit OS + +#### Data Type Differences + +Most 32-bit OSs use ILP32, which defines int, long, and pointer as 32 bits. Most 64-bit OSs use LP64, which defines long, long long, and pointer as 64 bits. The Windows OS uses LLP64, which defines long long and pointer as 64 bits. The table below lists the length of each primitive data type. + +| **Type**| **ILP32** | **LP64** | **LLP64** | **LP32** | **ILP64** | +| --------- | --------- | -------- | --------- | -------- | --------- | +| char | 1 | 1 | 1 | 1 | 1 | +| short | 2 | 2 | 2 | 2 | 2 | +| int | 4 | 4 | 4 | 2 | 8 | +| long | **4** | **8** | **4** | 4 | 8 | +| long long | 8 | 8 | 8 | 8 | 8 | +| float | 4 | 4 | 4 | 4 | 4 | +| double | 8 | 8 | 8 | 8 | 8 | +| size_t | **4** | **8** | **8** | 4 | 8 | +| pointer | **4** | **8** | **8** | 4 | 8 | + +The table below lists the length of `sizeof` and `print` in ILP32 and LP64 to show the differences between constants and types. + +| Type | ILP32 sizeof | ILP32 print | LP64 sizeof | LP64 print | Remarks| +| ------------------ | ------------ | ----------- | ----------- | ---------- | ------ | +| bool | 1 | %u | 1 | %u | C++ | +| char | 1 | %d or %c| 1 | %d or %c| | +| unsigned char | 1 | %u | 1 | %u | | +| short | 2 | %d | 2 | %d | | +| unsigned short | 2 | %u | 2 | %u | | +| int | 4 | %d | 4 | %d | | +| unsigned int | 4 | %u | 4 | %u | | +| long | 4 | %ld | **8** | %ld | Differences exist.| +| unsigned long | 4 | %lu | **8** | %lu | Differences exist.| +| long int | 4 | %ld | **8** | %ld | Differences exist.| +| unsigned long int | 4 | %lu | **8** | %lu | Differences exist.| +| long long | 8 | %lld | 8 | %lld | | +| unsigned long long | 8 | %llu | 8 | %llu | | +| type * | 4 | %p | **8** | %p | Differences exist.| +| pid_t | 4 | %d | 4 | %d | | +| socklen_t | 4 | %u | 4 | %u | | +| off_t | 4 | %zd | **8** | %zd | Differences exist.| +| time_t | 4 | %zd | 8 | %zd | Differences exist.| +| pthread_t | 4 | %zu | **8** | %zu | Differences exist.| +| size_t | 4 | %zu | 8 | %zu | Differences exist.| +| ssize_t | 4 | %zd | **8** | %zd | Differences exist.| + +#### Differences in Data Structure Alignment + +##### Alignment of the data structure that contains a pointer + +```c +typedef struct tagFoo { + void *p; + uint32_t i; +} Foo; +``` + +On a 32-bit OS, the pointer length is 4, **Foo** is 4-byte aligned, and **sizeof(Foo)** is 8. On a 64-bit OS, the pointer length is 8, **Foo** is 8-byte aligned, and **sizeof(Foo)** is 16. + +##### Alignment of the data structure that contains a 64-bit integer + +```c +typedef struct tagFoo { + uint64_t p; + uint32_t i; +} Foo; +``` + +Although uint64\_t has a fixed length, **sizeof(Foo)** is different due to alignment. On a 32-bit OS, **Foo** is 4-byte aligned, and **sizeof(Foo)** is 12. On a 64-bit OS, **Foo** is 8-byte aligned, and **sizeof(Foo)** is 16. The preceding statement is also true when uint64\_t is replaced by double. + +### Conventions + +**Rule**: Conventions that must be complied with during programming. + +**Rec**: Conventions that should be complied with during programming. + +## Coding Guide + +### General Principles + +#### [Rule] Follow this coding guide to write code that is applicable to both 32- and 64-bit OSs. + +[Description] OpenHarmony will run in both 32- and 64-bit environments for a long time. To ensure code consistency, you must consider code portability during coding. + +### Data Type Definition and Formatting + +#### [Rule] Use the defined data types to define variables, and avoid custom basic data types without special meanings or requirements. + +[Description] Data types with variable lengths may cause incompatibility issues on 32- and 64-bit OSs. Unified and clear data types are required. OpenHarmony defines the following primitive data types: + +| Type| ILP32 | LP64 | Print| Use Case| +| ---------------- | ----- | ----- | ------- | ------------------------------------------------------------ | +| void | - | - | - | Used only for placeholder and general pointer definition.| +| char | 1 | 1 | %c | Used for strings and arrays.| +| int8_t | 1 | 1 | %d | Used for 1-byte integers.| +| uint8_t | 1 | 1 | %u | Used for 1-byte integers.| +| int16_t | 2 | 2 | %d | Used to replace short.| +| uint16_t | 2 | 2 | %u | Used to replace unsigned short.| +| int32_t | 4 | 4 | %d | Used to replace int.| +| uint32_t | 4 | 4 | %u | Used to replace unsigned int.| +| int64_t | 8 | 8 | %PRId64 | Used to replace long long and macros.| +| uint64_t | 8 | 8 | %PRIu64 | Used to replace unsigned long long and macros.| +| float | 4 | 4 | %f | Used for single-precision floating point numbers.| +| double | 8 | 8 | %lf | Used for double-precision floating point numbers.| +| bool | 1 | 1 | %d | Used for Boolean.| +| uintptr_t | **4** | **8** | %zu | Used for pointer storage. Different lengths are defined for 32- and 64-bit OSs.| +| type * | **4** | **8** | %p | Variable-length type. It is equivalent to uintptr_t, which is recommended for type conversion.| +| nullptr_t | **4** | **8** | %p | Used for pointer initialization.| +| pid_t | 4 | 4 | %d | Built-in for the Linux kernel. It has a fixed length.| +| socklen_t | 4 | 4 | %u | Built-in for the Linux kernel. It has a fixed length.| +| off_t/time_t | **4** | **8** | %zd | Signed, variable-length type.| +| size_t/pthread_t | **4** | **8** | %zu | Unsigned, variable-length type. It is used only for compatibility of calling library functions (for example, size_t is used in an underlying API).| + +The preceding types are defined in the **stddef.h** (C) and **cstdint** (C++) standard libraries. When `#define` is used to redefine related types, the source must be one of these types. + +Do not use non-standard types unless otherwise specified. Do not define common basic types unless they have special meanings. For primitive data types used in third-party interfaces and API calling, refer to their respective rules. + +[Example] Do not customize primitive data types unless necessary. + +```c +// Do not use the following code to redefine a data type. +typedef unsigned int UINT32;// This definition is forbidden. + +// The preceding definition can be replaced by uint32_t. However, you can define a type that has a specific meaning. +typedef uint32_t DB_TABLE_ID; // This definition can be retained. +``` + +[Example] Do not use the following two types, because their lengths are different from the common sense. + +| Type| ILP32 | LP64 | PRINT | Use Case| +| -------- | ------ | ----- | ----- | ---------------------- | +| float_t | **12** | **4** | - | Improper length. Do not use it.| +| double_t | **12** | **8** | - | Improper length. Do not use it.| + +#### [Rec] Do not use custom variable-length variables. A clear description is required if they are used to adapt to platforms or third-party interfaces. + +[Description] The native types such as long, int, short, and size_t have different lengths in the 32- and 64-bit environments. This may cause code risks. If these types are used for external storage or communication, system incompatibility may occur. Therefore, do not use them unless otherwise specified. + +[Exception] Due to platform, third-party interface, or library function reasons, they can be used with a clear description. + +[Example] + +```c +long var; +// This data type is 4-byte long on a 32-bit OS and 8-byte long on a 64-bit OS. You are advised to use uint32_t or uint64_t instead. +``` + +#### [Rule] Do not use uchar to define variables. + +[Description] It is not standard to use uchar or unsigned char to define strings. Instead, use char for strings or uint8_t for unsigned integers. + +For non-ANSI character sequences involving 8-bit encoding, char is recommended. In C++, wchar can be used. + +#### [Rule] Define an integer variable that is used to store a pointer as uintptr_t. + +[Description] The uintptr_t type is used to store data of the pointer length. The length can be automatically adjusted in the 32- and 64-bits environments. + +[Example] + +```c +uintptr_t sessionPtr; + +// When the pointer is stored as a variable, both the forced type conversion and left value should be defined as uintptr_t to adapt to the length changes in different scenarios. +sessionPtr = (uintptr_t) GetMemAddress(); +``` + +#### [Rec] When the type defined by the input parameter or return value of a function does not match the variable type, exercise caution to ensure that the result is correct after conversion following the value assignment and type conversion rules. + +[Description] If type inconsistency is inevitable, convert the type with caution to ensure that the final result meets the application requirements. + +[Example] + +```c +long function (long l); +int main () { + int i = -2; + unsigned int k = 1U; + long n = function(i + k); +} +``` + +Note: The preceding code will fail to be executed on a 64-bit OS because the expression (i + k) is an unsigned 32-bit expression. When it is converted to the long type, the symbols are not extended. The result of the input parameter is incorrect. The solution is to forcibly convert one of the operands to a 64-bit type. + +#### [Rule] Use 64-bit compatible macros, such as %PRId64, %PRIu64, and %PRIx64, to print 64-bit integers. Incompatible macros, such as %d, %ld, %zd, %x, and %lx, are not allowed. + +[Description] If the data to be formatted is of the 64-bit type (defined as uint64_t), format the output as follows: + +```c +#include +#include +#include + +int main() +{ + uint64_t a = 0x1234567fffffff; + printf("a = %"PRIx64"\n", a); + return 0; +} +``` + +The preceding code can output 64-bit numbers in both 32- and 64-bit environments. If other formatting methods are used, compatibility issues may occur, as listed in the following table. + +| Formatting Method| ILP32 Build| ILP32 Result| LP64 Build| LP64 Result| Conclusion| +| ---------- | -------------- | --------- | -------------- | -------- | ---------- | +| %lx | Type mismatch alarm| Incorrect| No alarm| Correct| Incompatible| +| %zx | Type mismatch alarm| Incorrect| No alarm| Correct| Incompatible| +| %llx | No alarm| Correct| Type mismatch alarm| Correct| Incompatible| +| %p | Type mismatch alarm| Incorrect| Type mismatch alarm| Correct| Incompatible| +| %PRIx64 | No alarm| Correct| No alarm| Correct| Compatible| + +[Example]The following is an example of the type mismatch alarm information: + +```bash +# Build on a 32-bit OS +format '%lx' expects argument of type 'long unsigned int', but argument 2 has type 'uint64_t {aka long long unsigned int}' +format '%zx' expects argument of type 'size_t', but argument 2 has type 'uint64_t {aka long long unsigned int}' +format '%p' expects argument of type 'void *', but argument 2 has type 'uint64_t {aka long long unsigned int}' + +# Build on a 64-bit OS +format '%llx' expects argument of type 'long long unsigned int', but argument 2 has type 'uint64_t {aka long unsigned int}' +format '%p' expects argument of type 'void *', but argument 2 has type 'uint64_t {aka long unsigned int}' +``` + +#### [Rule] When printing type-variable data, consider the data length and reserve sufficient space during alignment. + +[Description] On a 32-bit OS, the maximum length of the pointer and size_t is 8 bits (hexadecimal) or 10 bits (decimal). On a 64-bit OS, their maximum length is 20 bits. Therefore, you need to consider the length range when printing the data. + +#### [Rule] Do not use L/UL as the suffix of constants. You can add the suffix U to indicate the unsigned int type and the suffix LL/ULL to indicate the 64-bit length. + +[Description] By default, constants without suffixes are of the int type. When L/UL is used as the suffix, the length may change on 32- and 64-bit OSs. Therefore, use LL/ULL as the suffix to ensure that the length is fixed at 64 bits in both the 32- and 64-bit environments. + +| Constant| ILP32 | LP64 | Scenario| +| -------------- | --------- | ----- | ------------------------------------------------------------ | +| 1 | 4 | 4 | The default type is int32_t, and the length is fixed.| +| 1U | 4 | 4 | The default type is uint32_t, and the length is fixed.| +| 1L | **4** | **8** | The suffix is L. The length is not fixed. Do not use this constant.| +| 1UL | **4** | **8** | The suffix is UL. The length is not fixed. Do not use this constant.| +| 1LL | 8 | 8 | The default type is int64_t. The value is a long integer, and the length is fixed at 64 bits.| +| 1ULL | 8 | 8 | The type is uint64_t, and the value is an unsigned long integer.| +| 0x7FFFFFFF | 4 | 4 | The value is an unsigned number. It can be used within the value range of int32\_t. The default type is int32\_t. | +| 0x7FFFFFFFL | **4** | **8** | The length is not fixed. Do not use this constant.| +| 0x7FFFFFFFLL | 8 | 8 | The length is fixed.| +| 0x80000000 | 4 | 4 | It can be used within the value range of uint32\_t. The type is uint32\_t.| +| 0x80000000L | **4** | **8** | The suffix is L. It can be used within the value range of uint32\_t. This constant is meaningless. Do not use it.| +| 0x80000000LL | 8 | 8 | The suffix is LL. It can be used within the value range of uint32\_t. The length is fixed.| +| 0x8000000000 | **NA or 8**| **8** | No prefix. It can be used when the value range of uint32\_t is exceeded. The compiler uses LL by default or considers the value invalid. On a 64-bit OS, the type is fixed at uint64\_t.| +| 0x8000000000L | **NA or 8**| **8** | The suffix is L. It can be used when the value range of uint32_t is exceeded. This constant is meaningless. Do not use it.| +| 0x8000000000LL | 8 | 8 | The suffix is LL. The type is uint64_t.| + +As shown in the preceding table, a constant with the L or UL suffix has different lengths in the 32- and 64-bit environments. This hinders code portability. Therefore, do not use the L or UL suffix. + +[Example] + +```c +// UL in the following definition is meaningless. It causes an error on a 32-bit OS and is unnecessary on a 64-bit OS. +#define YYY_START_ADDRESS(XXX_START_ADDR + 0x80000000UL) +``` + +#### [Rule] Use macro constants defined in the standard header file. + +[Description] The standard header files **stdint.h** (C) and **cstdint.h** (C++) contain macro constants with the maximum and minimum values. Reference these macro constants, rather than customizing new ones. + +[Example] + +```c +#include +#include + +int main() +{ + std::printf("%zu\n", sizeof(std::int64_t)); + std::printf("%s\n", PRId64); + std::printf("%+" PRId64 "\n", INT64_MIN); + std::printf("%+" PRId64 "\n", INT64_MAX); + + std::int64_t n = 7; + std::printf("%+" PRId64 "\n", n); +} +``` + +#### [Rule] Use unified definitions instead of all Fs to indicate invalid values of constants. + +[Description] The same numeric constant value may be understood differently on 32- and 64-bit OSs, since the 32-bit OS has the signed and unsigned types. Especially, if the most significant bit is 1, this bit is considered as a negative number on a 32-bit OS based on the signed type and a positive number on a 64-bit OS. Use the definitions in **typedef.h** to indicate invalid values. + +```c +// Use the definitions in typedef.h. +#define INVALID_INT8((int8_t)(-1)) +#define INVALID_UINT8((uint8_t)(-1)) +#define INVALID_INT16((int16_t)(-1)) +#define INVALID_UINT16((uint16_t)(-1)) +#define INVALID_INT32((int32_t)(-1)) +#define INVALID_UINT32((uint32_t)(-1)) +#define INVALID_INT64((int64_t)(-1)) +#define INVALID_UINT64((uint64_t)(-1)) +``` + +[Example] + +```c +// On a 32-bit OS, n is a negative number. +long n = 0xFFFFFFFF; +// On a 64-bit OS, n is a positive number. The actual value is 0x00000000FFFFFFFF. +long n = 0xFFFFFFFF; +``` + +#### [Rec] Use uint32_t to define temporary variables whose size does not exceed 32 bits. + +[Description] You do not need to pay special attention to the type of a variable. Use the default uint32_t type to minimize forced type conversions caused by type inconsistency. + +### Structure Alignment and Padding + +#### [Rule] Do not hardcode a constant to specify the variable length and structure length. Use built-in types such as **sizeof** to obtain the variable length and structure length. + +[Description] **sizeof** automatically calculates the variable length and structure length, which might be incorrect if hardcoded. In addition, the running performance will not be adversely affected since the variable length is calculated during build. + +On a 64-bit OS, 8-byte alignment is used by default. Using **sizeof()** to obtain the structure length can avoid length calculation errors caused by structure alignment. + +Pay attention to the length differences on 32- and 64-bit OSs to avoid length calculation errors. Calculate and apply for space based on the maximum length. + +[Example] **sizeof** is not used to calculate the structure length, causing insufficient memory space. + +```c +int32_t *p; +p = (int32_t *)malloc(4 * ELEMENTS_NUMBER); +// This code assumes that the pointer length is 4 bytes. However, in LP64, the pointer length is 8 bytes. + +// The correct method is to use sizeof(). +int32_t *p; +p = (int32_t *)malloc(sizeof(p) * ELEMENTS_NUMBER); +``` + +#### [Rec] In special cases, force the compiler to use a specific alignment mode on the 64-bit OS. + +[Description] If necessary, you can use the specified alignment mode to ensure code compatibility. If the pseudo-instruction **#pragma pack (n)** is used, the compiler aligns data by n bytes. If the pseudo-instruction **#pragma pack ()** is used, the compiler cancels the custom byte alignment mode. + +[Example] + +```c +#pragma pack(push) # Save the current alignment mode. +#pragma pack(1) # Set the alignment mode to 1-byte alignment. +struct test +{ + ...... +}; +#pragma pack(pop) # Restore the previous alignment mode. +``` + +#### [Rule] Uniform the message structures related to multi-device communication. For compatibility purposes, 1-byte alignment is preferred. Do not use 8-byte alignment or 64-bit data types to avoid errors during communication with a 32-bit OS. + +Note: Inter-board communication messages involve inter-board operations. The communication fails unless all software is upgraded synchronously. For the sake of compatibility, use 1-byte alignment for the existing protocols and structures and convert them into the network byte order. For new communication protocols, use 4-byte alignment for higher communication efficiency and processing performance. + +#### [Rule] Avoid structure padding for external APIs and use at least 4-byte alignment. + +[Description] If structure definitions are included in an API header file provided externally, do not pad the structures. It is recommended that natural alignment be used to avoid data holes. Use at least 4-byte alignment. + +#### [Rec] Use member names to access structure members. Do not use the offset mode. + +[Description] The offsets of data structure members are different in the 32- and 64-bit environments. Therefore, the size of each member cannot be used as the offset. A 32-bit OS does not have structures automatically padded. However, on a 64-bit OS, automatic padding may occur. + +[Example] + +```c +Struct A +{ + uint32_t a; + uint32_t *p; + uint32_t b; +}; +``` + +The offset of member b is equal to sizeof(a) + sizeof(p) on a 32-bit OS. This is not true on a 64-bit OS. The correct method is to locate the index based on the variable name. + +```c +xxx.b = 123; +``` + +If the structure definition is special, for example, if the structure is only the message header and there are other fields, then you can redefine the structure so that it does not include padding fields. + +[Example] + +```c +typedef struct { + uint32_t self; /* Structure used for alignment. */ + uint32_t brother; /* Structure used for alignment. */ + uint8_t processedFlag; /* Flag indicating whether the current node has been processed. */ + uint8_t reserve[3]; /* Reserved for 4-byte alignment. */ +} TreeNodeInfo; + +typedef struct { + TreeNodeInfo nodeInfo; /* Tree information data structure of each node */ + void *userInfo; /* User information data structure of each node */ +} TreeNode; +``` + +The **TreeNode** structure has two member structures. In the following code, the address of the first member is the initial address of the second member minus the value of sizeof (the first member). (**inUserInfo** points to the **userInfo** field in the structure.) + +```c +inTreeNodeInfo = (TreeNodeInfo *)((void *)(((char *)inUserInfo) - sizeof(TreeNodeInfo))); +``` + +The structure adopts natural alignment. Note that the length of the substructure **TreeNodeInfo** is 12 bytes on both 32- and 64-bit OSs. On a 32-bit OS, there is no padding between member structures of the **TreeNode** structure, and the structure length is 16 bytes. On a 64-bit OS, **sizeof(TreeNodeInfo)** is 12 and **sizeof(TreeNode)** is 24, which means that there is a 4-byte padding field after the substructure **TreeNodeInfo**. Therefore, when the preceding method is used to obtain the address of the previous field on a 64-bit OS, the 4-byte padding field is not calculated, causing a member access error. + +#### [Rec] When defining a structure, implement 8-byte natural alignment to save storage space and avoid padding on the premise that readability is ensured. + +[Description] If a structure can be naturally aligned, no padding is required, which effectively reduces the invalid space of the structure. You are advised to define 64-bit data types such as size_t and pointer at both ends of the structure without affecting readability. + +[Example] + +```c +// The length of the following structure is 24 bytes in natural alignment mode. +struct Foo +{ + int32_t a; + uint64_t l; + int32_t x; +} + +// After proper adjustment, the size can be reduced to 16 bytes. +struct Foo +{ + uint64_t l; + int32_t a; + int32_t x; +} +``` + +### Data Type Conversion and Calculation + +#### [Rule] Avoid implicit type conversion between different data types. If necessary, use explicit type conversion to avoid result inconsistency between the 32- and 64-bit environments. + +[Description] Exercise caution when performing operations between operands with different lengths and precisions. Pay attention to the following about implicit type conversion: + +1. When the value of a 64-bit variable is assigned to a 32-bit variable, the values of the least significant 32 bits are directly assigned, and the values of the most significant 32 bits are ignored. Then the least significant 32 bits are treated as signed or unsigned based on the left value variable type. + +2. When the value of a 32-bit variable is assigned to a 64-bit variable, sign extension is performed based on whether the 32-bit variable is signed or unsigned, and then the 64-bit variable is treated as signed or unsigned based on the variable type. + +3. For operations of signed and unsigned numbers, if the result type is not specified, the result is treated as unsigned by default. + +The preceding conversion process may cause unexpected results. Therefore, exercise caution to avoid implicit type conversion as much as possible. + +[Example] Example of the correct conversion result + +```c +int32_t t1 = -2; +int64_t t2 = 1; +int32_t t3 = t1 + t2; +printf("t3 = %d\n", t3); + +// Printed: t3 = -1 +``` + +t1 is a 32-bit number, and t2 is a 64-bit number. Before the calculation, t1 is extended to 64 bits. After the calculation, the result is a 64-bit int64_t type. The hexadecimal value stored in the memory is 0xffffffffffffffff. During the value assignment, the value is truncated into 0xffffffff. Then, the value is treated as signed, which is -1. Although the result is correct, data truncation occurs. This may not be the author's intention. + +[Example] Conversion from signed to unsigned + +```c +int64_t t1 = -1; +uint32_t t2 = t1; +printf("t2=%u", t2); + +// Printed: t2=4294967295 +``` + +t1 is a 64-bit int64_t type, which is 0xffffffffffffffff in binary mode. When this value is assigned to a 32-bit int type, the most significant 32 bits are ignored and the least significant 32 bits are displayed. The binary value is 0xffffffff, which is 4294967295 in unsigned mode. + +[Example] Conversion from 32-bit to unsigned 64-bit + +```c +int32_t t1 = -1; +uint64_t t2 = t1; +printf("t2 = %lu\n", t2); + +// Printed: t2 = 18446744073709551615 +``` + +t1 is a signed negative 32-bit number, which must be extended with signs. The most significant bits of the negative number are all fs, and the value after extension is 0xffffffffffffffff. t2 is an unsigned 64-bit number, the value of which is a large positive number. + +#### [Rule] When a pointer is used as the base address and the offset is calculated by byte, the pointer must be forcibly converted to a single-byte pointer such as uintptr_t or uint8_t *. + +[Description] If the pointer is converted to an integer of the uint32_t type, the pointer may be truncated. This will not occur if the pointer is converted to uintptr_t. The pointer can also be converted to a single-byte pointer such as uint8_t * and char *. In this case, the offset is considered as bytes. A one-byte offset will be carried out for the void * type. To clarify the type, you are advised to use the type that is more specific. + +[Example] + +```c +// Incorrect +void *pPkt = (void *)((uint32_t)MSG_GET_DATA_ADDR(msgAddr) + OFFSET); + +// Correct +void *pPkt = (void *)((uintptr_t)MSG_GET_DATA_ADDR(msgAddr) + OFFSET);// C +void *pPkt = reinterpret_cast(reinterpret_cast(MSG_GET_DATA_ADDR(msgAddr)) + OFFSET); // C++ +``` + +#### [Rule] Mutual assignment is forbidden between pointers and uint32_t, including function parameter passing. + +[Description] If the variable to be defined is a length-variable pointer, use void *. If the variable to be defined is a pointer or an integer, use uintptr_t. + +[Example] Conversion between pointers and integers + +```c +int32_t i, *p, *q; +p = &i; +q = (int32_t *) (int32_t)&i; + +// In ARM Cortex-A32, p = q; in A64-LP64, p != q +``` + +To avoid this type conflict, use uintptr_t to indicate the pointer type. + +#### [Rule] Mutual assignment is forbidden between size_t and int32_t/uint32_t, including function parameter passing. + +[Description] The variable-length type cannot be forcibly converted to the 32-bit type. + +[Example] + +```c +int32_t length = (int32_t)strlen(str); // Incorrect +``` + +strlen returns size_t (unsigned long in LP64). When the value is assigned to int32_t, truncation is inevitable. Generally, truncation occurs only when the length of **str** is greater than 2 GB. This is rare in programs. + +#### [Rule] When a large array or large `for` loop index is used on a 64-bit OS, the index type must be consistent with the subscript boundary. + +[Description] If a large array or large loop is used on a 64-bit OS, the index range may exceed 32 bits. In this case, the variable-length type or 64-bit type must be used to define the array subscript or loop variable to prevent full traversal failures caused by an incorrect variable range. + +[Example] + +```c +int64_t count = BIG_NUMBER; +for (unsigned int index = 0; index != count; index++) + ... +``` + +On a 64-bit OS, int64_t is a 64-bit type, and count is a large number. unsigned int is a 32-bit type. As a result, the loop never ends. Therefore, the index type should be changed to int64_t. + +### Bit Field and Byte Order + +#### [Rule] When defining variables based on bit fields, fully consider the basic types and alignment of bit fields to avoid calculation errors in different bit widths. + +[Description] Consider both the width of a bit field and alignment. The structure length is different in different environments. Use the name rather than direct calculation result for the value of a bit field. + +#### [Rule] On a 64-bit OS, consider the length difference caused by the shift operation and the problem that the value generated after shift is implicitly extended to 64 bits. + +[Description] During the shift operation, check whether overflow and rewind occur. Change the data type to 32-bit to avoid result inconsistency. + +[Example] + +```c +int64_t t = 1 << a; // Consider the size of a. +``` + +The maximum value of a is 32 on a 32-bit OS and 64 on a 64-bit OS. If a is a 32-bit variable, the extension to 64 bits must also be considered. + +### Third-Party Libraries and Differentiated Features + +#### [Rule] The third-party class libraries used by a 64-bit OS must support 64-bit. + +[Description] Some library functions and third-party open-source code may not fully support 64-bit. You must evaluate all involved code to ensure that it can run in the 64-bit environment. Some library functions are implemented using different APIs in the 32- and 64-bit environments. Ensure that correct APIs are used. + +[Example] In the 32-bit environment, **mmap** can be used. If the size of the memory to map exceeds 2 GB, **mmap64** is required. In the 64-bit environment, **mmap** is used. + +#### [Rule] Functionalities involving bottom-layer assembly must be debugged separately on the 32- and 64-bit OSs. + +[Description] The number and bit width of registers are different in the 32- and 64-bit environments. The debugging functionalities related to assembly must be adjusted. You must also pay attention to the code validity in the 32-bit and 64-bit environments. + +[Example] For the push-to-stack functionality of the call stack, you must write and debug the assembly code in the 32- and 64-bit environment separately. + +#### [Rule] The patch functionality must support both 32- and 64-bit instructions. + +[Description] The patch mechanism and functionalities must be adopted to the command length changes. + +#### [Rule] All tools used on a 64-bit OS must support 64-bit. + +[Description] If type inconsistency is inevitable, convert the type with caution to ensure that the final result meets the application requirements. diff --git a/website/docs/extras/en/contribute/OpenHarmony-Java-secure-coding-guide.md b/website/docs/extras/en/contribute/OpenHarmony-Java-secure-coding-guide.md new file mode 100644 index 0000000000000000000000000000000000000000..2ed0478b06bbb7b6a4f28c54ec4612ec34cf2604 --- /dev/null +++ b/website/docs/extras/en/contribute/OpenHarmony-Java-secure-coding-guide.md @@ -0,0 +1,2111 @@ +--- +title: "OpenHarmony-Java-secure-coding-guide" +prepermalink: /extras/0ab1737f215b21beae171ea919061f71/ +permalink: /extras/0ab1737f215b21beae171ea919061f71/ +relpath: "OpenHarmony-3.1-Release/en/contribute/OpenHarmony-Java-secure-coding-guide.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [OpenHarmony-Java-secure-coding-guide] +--- +# Java Secure Coding Guide + +This document provides secure coding suggestions for Java-based development. + +# Data Type + +## Prevent integer overflow in numeric operations + +**\[Description]** + +Ensure that numeric operations do not create a numeric value that is outside of a specific integer range, so as to prevent integer overflows which may lead to unintended behavior. + +The built-in integer operators do not indicate overflow or underflow in any way. Common addition, subtraction, multiplication, and division operations may cause integer overflows. In addition, the ranges of Java types are not symmetric (the negation of each minimum value is one more than each maximum value). Therefore, the `java.lang.Math.abs()` method which returns the absolute value of any number can also overflow if given the minimum as an argument. + +Integer overflows can be avoided using precondition testing, Math class, upcasting, `BigInteger`, etc. + +**\[Noncompliant Code Example]** + +```java +public static int multNum(int num1, int num2) { + return num1 * num2; +} +``` + +In this noncompliant code example, when the absolute values of **num1** and **num2** are large and the product of **num1** and **num2** is greater than `Integer.MAX_VALUE` or smaller than `Integer.MIN_VALUE`, the method cannot return the correct result, incurring an overflow. + +**\[Compliant Code Example]** + +```java +public static int multNum(int num1, int num2) { + return Math.multiplyExact(num1, num2); +} +``` + +This compliant code example uses the `Math.multiplyExact()` method, which is added to Java as part of the Java 8 release, when it is impossible to predict whether an overflow may occur in multiplication operations. This method either returns a mathematically correct value or throw `ArithmeticException`. + +## Ensure that division and remainder operations do not result in divide-by-zero errors + +**\[Description]** + +A division or remainder by zero can result in abnormal program termination and denial of service (DoS). Therefore, the divisor in a division or remainder operation must be checked for zero prior to the operation. + +**\[Noncompliant Code Example]** + +```java +long dividendNum = 0; +long divisorNum = 0; +long result1 = dividendNum / divisorNum; +long result2 = dividendNum % divisorNum; +``` + +In this noncompliant code example, the divisor is not checked for zero prior to the operation, which may cause program errors. + +**\[Compliant Code Example]** + +```java +long dividendNum = 0; +long divisorNum = 0; +if (divisorNum != 0) { + long result1 = dividendNum / divisorNum; + long result2 = dividendNum % divisorNum; +} +``` + +This compliant code example tests the divisor to guarantee there is no possibility of divide-by-zero errors before the operation. + +# Expressions + +## Do not use a null in any case where an object is required to prevent null pointer reference + +**\[Description]** + +Using a null in cases where an object is required results in a `NullPointerException` being thrown. Such exceptions should be resolved through pre-check rather than `try...catch`. + +**\[Noncompliant Code Example]** + +```java +String env = System.getenv(SOME_ENV); +if (env.length() > MAX_LENGTH) { + ... +} +``` + +In this noncompliant code example, the return value of `System.getenv()` may be null, but `env` is not checked for null before it is used. As a result, a null pointer reference occurs. + +**\[Compliant Code Example]** + +```java +String env = System.getenv(SOME_ENV); +if (env != null && env.length() > MAX_LENGTH) { + ... +} +``` + +The compliant code example eliminates null pointer reference by adding a null check for the `System.getenv()` return value. + +# Concurrency and Multithreading + +## Ensure that actively held locks are released on exceptional conditions + +**\[Description]** + +An unreleased lock in any thread will prevent other threads from acquiring the same lock, leading to blocking. Programs must release all actively held locks on exceptional conditions. Intrinsic locks of class objects used for method and block synchronization are automatically released on exceptional conditions. However, most Java lock objects are not closeable, so they cannot be automatically released using the try-with-resources feature. In this case, programs must release the locks actively. + +**Noncompliant Code Example** (Checked Exception) + +```java +public final class Foo { + private final Lock lock = new ReentrantLock(); + + public void incorrectReleaseLock() { + try { + lock.lock(); + doSomething(); + lock.unlock(); + } catch (MyBizException ex) { + //Handle the exception + } + } + + private void doSomething() throws MyBizException { + ... + } +} +``` + +This noncompliant code example uses a `ReentrantLock`. However, the catch block fails to release the lock when an exception is thrown by the `doSomething()` method. + +**\[Compliant Code Example]** (**finally** Block) + +```java +public final class Foo { + private final Lock lock = new ReentrantLock(); + + public void correctReleaseLock() { + lock.lock(); + try { + doSomething(); + } catch (MyBizException ex) { + //Handle the exception + } finally { + lock.unlock(); + } + } + + private void doSomething() throws MyBizException { + ... + } +} +``` + +This compliant code example encapsulates operations that could throw an exception in a **try** block immediately after acquiring the lock. The lock is acquired before the **try** block, which ensures that it is held when the **finally** block executes. Calling `lock.unlock()` in the **finally** block ensures that the lock can be released even in the event of an exception. + +**Noncompliant Code Example** (Unchecked Exception) + +```java +final class Foo { + private final Lock lock = new ReentrantLock(); + + public void incorrectReleaseLock(String value) { + lock.lock(); + ... + int index = Integer.parseInt(value); + ... + lock.unlock(); + } +} +``` + +In this noncompliant code example, when the string passed by the `incorrectReleaseLock()` method is not a number, a `NumberFormatException` will be thrown in subsequent operations. Consequently, the lock is not correctly released. + +**\[Compliant Code Example]** (**finally** Block) + +```java +final class Foo { + private final Lock lock = new ReentrantLock(); + + public void correctReleaseLock(String value) { + lock.lock(); + try { + ... + int index = Integer.parseInt(value); + ... + } finally { + lock.unlock(); + } + } +} +``` + +This compliant code example encapsulates operations that could throw an exception in a **try** block immediately after acquiring the lock. The lock is acquired before the **try** block, which ensures that it is held when the **finally** block executes. Calling `lock.unlock()` in the **finally** block ensures that the lock can be released even in the event of an exception. + +## Do not use **Thread.stop()** to terminate threads + +**\[Description]** + +Threads preserve class invariants when they are allowed to exit normally. Some thread APIs were initially introduced to facilitate thread suspension, resumption, and termination but were later deprecated due to inherent design weaknesses. For example, the `Thread.stop()` method causes the thread to immediately throw a `ThreadDeath` exception, which usually stops the thread. Calling `Thread.stop()` results in the release of all locks acquired by a thread, potentially exposing the objects protected by the locks when those objects are in an inconsistent state. + +**\[Noncompliant Code Example]** (Deprecated **Thread.stop()**) + +```java +public final class Foo implements Runnable { + private final Vector vector = new Vector(1000); + + public Vector getVector() { + return vector; + } + + @Override + public synchronized void run() { + Random number = new Random(123L); + int i = vector.capacity(); + while (i > 0) { + vector.add(number.nextInt(100)); + i--; + } + } + + public static void main(String[] args) throws InterruptedException { + Thread thread = new Thread(new Foo()); + thread.start(); + Thread.sleep(5000); + thread.stop(); + } +} +``` + +In this noncompliant code example, a thread fills a vector with pseudorandom numbers. The thread is forcefully stopped after a specific period of time. Because **Vector** is a thread-safe class, the operations performed by multiple threads on the shared instance will leave it in a consistent state. For example, the `Vector.size()` method always returns the correct number of elements in the vector, because the vector instance uses its own intrinsic lock to synchronize state. However, the `Thread.stop()` method causes the thread to stop and throw a `ThreadDeath` exception. All acquired locks are subsequently released. If the thread was in the process of adding a new integer when it was stopped, the vector would be in an inconsistent state. For example, this could result in `Vector.size()` returning an incorrect element count because the element count was incremented after the element is added. + +**\[Compliant Code Example]** (Setting a Thread End Flag) + +```java +public final class Foo implements Runnable { + private final Vector vector = new Vector(1000); + + private boolean done = false; + + public Vector getVector() { + return vector; + } + + public void shutdown() { + done = true; + } + + @Override + public synchronized void run() { + Random number = new Random(123L); + int i = vector.capacity(); + while (!done && i > 0) { + vector.add(number.nextInt(100)); + i--; + } + } + + public static void main(String[] args) throws InterruptedException { + Foo foo = new Foo(); + Thread thread = new Thread(foo); + thread.start(); + Thread.sleep(5000); + foo.shutdown(); + } +} +``` + +This compliant code example uses a flag to request thread termination. The `shutdown()` method is used to set the flag to **true**. The `run()` method of the thread terminates when it finds the flag is **true**. + +**\[Compliant Code Example]** (Interruptible) + +```java +public final class Foo implements Runnable { + private final Vector vector = new Vector(1000); + + public Vector getVector() { + return vector; + } + + @Override + public synchronized void run() { + Random number = new Random(123L); + int i = vector.capacity(); + while (!Thread.interrupted() && i > 0) { + vector.add(number.nextInt(100)); + i--; + } + } + + public static void main(String[] args) throws InterruptedException { + Foo foo = new Foo(); + Thread thread = new Thread(foo); + thread.start(); + Thread.sleep(5000); + thread.interrupt(); + } +} +``` + +The compliant code example calls the `Thread.interrupt()` method to terminate the thread. Calling `Thread.interrupt()` sets an internal termination flag. The thread polls that flag using the `Thread.interrupted()` method, which both returns **true** if the current thread has been terminated and clears the termination flag. + +## Clear customized **ThreadLocal** variables when the thread in the thread pool ends + +**\[Description]** + +Thread pooling reduces thread creation overhead by reusing threads. However, the reuse of threads causes two problems related to the use of `ThreadLocal` variables: + +- Dirty data: `ThreadLocal` variables are not correctly initialized for the current task. Consequently, the task sees `ThreadLocal` variables set by another task executed on the same thread. +- Memory leak: Since `ThreadLocal` variables are not actively released, the memory cannot be actively reclaimed. + +Therefore, the `ThreadLocal` variables used by each task in the thread pool must be automatically cleared after the task ends. + +**\[Compliant Code Example]** + +```java +public class TestThreadLocal { + public static void main(String[] args) { + ThreadPoolExecutor pool = new ThreadPoolExecutor(1, 2, 100, + TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), + Executors.defaultThreadFactory(), new ThreadPoolExecutor.CallerRunsPolicy()); + for (int i = 0; i < 20; i++) { + pool.execute(new TestThreadLocalTask()); + } + } +} + +class TestThreadLocalTask implements Runnable { + private static ThreadLocal localValue = new ThreadLocal<>(); + + @Override + public void run() { + localValue.set(STATE1); + try { + ... + localValue.set(STATE3); + ... + } finally { + localValue.remove(); //Use the remove() method to clear local variables of the thread to avoid memory leak + } + } +} +``` + +# Input/Output + +## Create files with appropriate access permissions on multi-user systems + +**\[Description]** + +Files in multi-user systems are generally owned by a particular user. The owner of the files can specify which other users in the system are allowed to access the files. These file systems use a privilege and permission model to protect file access. When a file is created, the file access permissions dictate who are allowed to access or operate on the file. When a program creates a file with insufficiently restrictive access permissions, an attacker may read or modify the file before the program can modify the permissions. Consequently, files must be created with access permissions that prevent unauthorized file access. + +**\[Noncompliant Code Example]** + +```java +Writer out = new FileWriter("file"); +``` + +The constructors for `FileOutputStream` and `FileWriter` do not allow programmers to explicitly specify file access permissions. In this noncompliant code example, the access permissions of any file created are implementation-defined and may not prevent unauthorized access. + +**\[Compliant Code Example]** + +```java +Path file = new File("file").toPath(); + +//Throw an exception, rather than overwrite an existing file +Set options = new HashSet(); +options.add(StandardOpenOption.CREATE_NEW); +options.add(StandardOpenOption.APPEND); + +//Set file permissions to allow only the owner to read/write the file +Set perms = PosixFilePermissions.fromString("rw-------"); +FileAttribute> attr = + PosixFilePermissions.asFileAttribute(perms); +try (SeekableByteChannel sbc = Files.newByteChannel(file, options, attr)) { + ... //Write data +} +``` + +**\[Exception]** + +When a file is created inside a directory that is both secure and unreadable to untrusted users, the file may be created with the default access permissions. This is the case, for example, if the entire file system is trusted or accessible only to trusted users. + +## Validate and canonicalize path names constructed using external data + +**\[Description]** + +If a path name is constructed using external data, it must be verified. Otherwise, a path traversal vulnerability may occur. + +A path name may be either absolute or relative and may contain file links, such as symbolic links, shortcuts, and shadows, which all affect path name validation. Therefore, path names must be canonicalized before being validated. Be sure to use `getCanonicalPath()`, but not `getAbsolutePath()`, to canonicalize path names, because the latter does not guarantee correct canonicalization on all platforms. + +**\[Noncompliant Code Example]** + +```java +public void doSomething() { + File file = new File(HOME_PATH, fileName); + String path = file.getPath(); + + if (!validatePath(path)) { + throw new IllegalArgumentException("Path Traversal vulnerabilities may exist!") ; + } + ... //Perform read and write operations on the file +} + +private boolean validatePath(String path) { + if (path.startsWith(HOME_PATH)) { + return true; + } else { + return false; + } +} +``` + +In this noncompliant code example, the file name comes from external input and is directly concatenated with a fixed path name to generate the actual path name. Before the file is accessed, `validatePath` is used to check whether the actual path name is under a fixed directory. However, an attacker can still access a file outside **HOME\_PATH** by entering an argument that contains **../**. + +**\[Compliant Code Example]** (**getCanonicalPath()**) + +```java +public void doSomething() { + File file = new File(HOME_PATH, fileName); + try { + String canonicalPath = file.getCanonicalPath(); + if (!validatePath(canonicalPath)) { + throw new IllegalArgumentException("Path Traversal vulnerability!"); + } + ... //Perform read and write operations on the file + } catch (IOException ex) { + throw new IllegalArgumentException("An exception occurred ...", ex); + } +} + +private boolean validatePath(String path) { + if (path.startsWith(HOME_PATH)) { + return true; + } else { + return false; + } +} +``` + +This compliant code example canonicalizes the path name constructed using the externally-supplied file name, and validates the canonicalized path name before performing file read/write operations. This practice can effectively prevent risks like path traversal. + +## Perform security check when decompressing a ZIP archive using **ZipInputStream** + +**\[Description]** + +A number of security concerns must be considered when extracting files from a ZIP archive using `java.util.zip.ZipInputStream`: + +**1\. Extracting files outside the intended directory** + +File names may contain **../** sequences that may cause the files to be extracted outside of the intended directory. Therefore, file names must be validated when files are extracted from a ZIP archive. If the destination path of any file in the ZIP archive is not within the expected directory, either refuse to extract it or extract it to a safe location. + +**2\. Excessive consumption of system resources during file extraction** + +When extracting files from a ZIP archive, both the number and size of the extracted files need to be limited. The zip algorithm can produce very large compression ratios, to compress a huge file into a small ZIP archive. If the actual size of the files in the ZIP archive is not checked, the extracted files may occupy a large amount of system resources, resulting in a ZIP bomb attack. Therefore, programs must refuse to extract files beyond a certain size limit. The actual limit depends on the capabilities of the platform. + +**\[Noncompliant Code Example]** + +```java +public void unzip(String fileName, String dir) throws IOException { + try (FileInputStream fis = new FileInputStream(fileName); + ZipInputStream zis = new ZipInputStream(fis)) { + ZipEntry entry; + File tempFile; + byte[] buf = new byte[10240]; + int length; + + while ((entry = zis.getNextEntry()) != null) { + tempFile = new File(dir, entry.getName()); + if (entry.isDirectory()) { + tempFile.mkdirs(); + continue; + } + + try (FileOutputStream fos = new FileOutputStream(tempFile)) { + while ((length = zis.read(buf)) != -1) { + fos.write(buf, 0, length); + } + } + } + } +} +``` + +This noncompliant code example does not validate the name of the file that is being unzipped. It passes the name directly to the constructor of `FileOutputStream`. It also fails to check the resource consumption of the file that is being unzipped. It permits the operation to run to completion or until local resources are exhausted. + +**\[Compliant Code Example]** + +```java +private static final long MAX_FILE_COUNT = 100L; +private static final long MAX_TOTAL_FILE_SIZE = 1024L * 1024L; + +... + +public void unzip(FileInputStream zipFileInputStream, String dir) throws IOException { + long fileCount = 0; + long totalFileSize = 0; + + try (ZipInputStream zis = new ZipInputStream(zipFileInputStream)) { + ZipEntry entry; + String entryName; + String entryFilePath; + File entryFile; + byte[] buf = new byte[10240]; + int length; + + while ((entry = zis.getNextEntry()) != null) { + entryName = entry.getName(); + entryFilePath = sanitizeFileName(entryName, dir); + entryFile = new File(entryFilePath); + + if (entry.isDirectory()) { + creatDir(entryFile); + continue; + } + + fileCount++; + if (fileCount > MAX_FILE_COUNT) { + throw new IOException("The ZIP package contains too many files."); + } + + try (FileOutputStream fos = new FileOutputStream(entryFile)) { + while ((length = zis.read(buf)) != -1) { + totalFileSize += length; + zipBombCheck(totalFileSize); + fos.write(buf, 0, length); + } + } + } + } +} + +private String sanitizeFileName(String fileName, String dir) throws IOException { + file = new File(dir, fileName); + String canonicalPath = file.getCanonicalPath(); + if (canonicalPath.startsWith(dir)) { + return canonicalPath; + } + throw new IOException("Path Traversal vulnerability: ..."); +} + +private void creatDir(File dirPath) throws IOException { + boolean result = dirPath.mkdirs(); + if (!result) { + throw new IOException("Create dir failed, path is : " + dirPath.getPath()); + } + ... +} + +private void zipBombCheck(long totalFileSize) throws IOException { + if (totalFileSize > MAX_TOTAL_FILE_SIZEG) { + throw new IOException("Zip Bomb! The size of the file extracted from the ZIP package is too large."); + } +} +``` + +This compliant code example validates the name of each file before unzipping it. If a file name is invalid, the extraction is aborted. In fact, a compliant solution could also skip that file and continue the extraction process, or extract the file to a safe location. Furthermore, the code inside the while loop tracks the total size of extracted files and throws an exception if the total size hits the upper limit **MAX\_TOTAL\_FILE\_SIZE**. The code also counts the number of file entries in the ZIP archive and throws an exception if the total number of files hits the upper limit **MAX\_FILE\_COUNT**. + +Note: `entry.getSize()` reads the pre-decompression size of individual files from a fixed field, which may have been tampered with. Therefore, do not use `entry.getSize()` to collect statistics about the extracted file size. + +## Use integer return type of methods that read a character or byte from a stream + +**\[Description]** + +The `InputStream.read()` and `Reader.read()` methods are used to read a byte or character, respectively, from a stream. + +The `InputStream.read()` method reads a single byte from an input source and returns its value as an 8-bit integer in the range 0x00 to 0xff. The `Reader.read()` method reads a single character and returns its value as a 16-bit integer in the range 0x0000 to 0xffff. + +Both methods return the 32-bit integer –1 (0xffffffff) to indicate that the end of the stream has been reached and no data is available. + +Prematurely converting the resulting integer to a **byte** or **char** before testing for the value −1 (0xffffffff) makes it impossible to distinguish between characters read and the end of stream indicator. + +**\[Noncompliant Code Example]** (**byte**) + +```java +FileInputStream in = getReadableStream(); + +byte data; +while ((data = (byte) in.read()) != -1) { + //Use data + ... +} +``` + +This noncompliant code example casts the value returned by the `read()` method directly to a value of the **byte** type and then compares this value with −1 in an attempt to detect the end of the stream. If the `read()` method returns 0xff which is then converted into a signed byte value –1, it will be incorrectly taken as the end of the stream. + +**\[Noncompliant Code Example]** (**char**) + +```java +InputStreamReader in = getReader(); + +char data; +while ((data = (char) in.read()) != -1) { + //Use data + ... +} +``` + +This noncompliant code example casts the value returned by the `read()` method directly to a value of the **char** type and then compares this value with −1 in an attempt to detect the end of the stream. When the end of stream is read, the return value cast to the **char** type is not −1. Consequently, the while loop cannot properly end. The reason is as follows: When the end of stream indicator –1 (0xffffffff) is forcibly converted to the **char** type, it will be converted to 0xffff, instead of –1. Consequently, the test for the end of file never evaluates to true. + +**\[Compliant Code Example]** (**byte**) + +```java +FileInputStream in = getReadableStream(); + +byte data; +int result; +while ((result = in.read()) != -1) { + data = (byte) result; + //Use data + ... +} +``` + +**\[Compliant Code Example]** (**char**) + +```java +InputStreamReader in = getReader(); + +char data; +int result; +while ((result = in.read()) != -1) { + data = (char) result; + //Use data + ... +} +``` + +This compliant code example uses a variable of the **int** type to capture the value returned by `read()`, and uses the return value to determine whether the end of stream is read. If the end of stream is not read, the read content is converted to the **char** or **byte** type, so as to avoid misinterpretation of the end of stream. + +## Do not let external processes block on input and output streams + +**\[Description]** + +Two methods can be used to invoke external processes: + +1. **exec()** of **java.lang.Runtime** +2. **start()** of **java.lang.ProcessBuilder** + +They all return a **java.lang.Process** object which has encapsulated the external processes. + +This process contains an input stream, output stream, and error stream, which must be properly handled to prevent them from being blocked by external processes. + +Incorrect handling can cause unexpected exceptions, DoS, and other security problems. + +1\. Handling the input stream (`Process.getOutputStream()`) of an external process: **From the invoker's perspective, the input stream of an external process is its output stream**: A process that tries to read input on an empty input stream will block until input is supplied. + +2\. Handling the output stream (`Process.getInputStream()`) and error stream (`Process.getErrorStream()`) of an external process: If the external process to be invoked has both output and error streams and the streams are not emptied, the output of the process may exhaust the buffer of the output and error streams. Consequently, the external process is blocked, and the interaction between the invoker and external process is affected. When `java.lang.ProcessBuilder` is used to invoke an external process, the error stream of the process can be redirected to the output stream using the `redirectErrorStream()` method, and the invoker can empty the output stream so that the error stream is emptied together. + +**\[Noncompliant Code Example]** (Incorrectly Handling the Return Result of an External Process) + +```java +public void execExtProcess() throws IOException { + Process proc = Runtime.getRuntime().exec("ProcessMaybeStillRunning"); + int exitVal = proc.exitValue(); +} +``` + +In this noncompliant code example, the program invokes the `exitValue()` method when the ProcessMaybeStillRunning process has not terminated, which may result in an `IllegalThreadStateException`. + +**\[Noncompliant Code Example]** (Failure to Handle the Output and Error Streams of an External Process) + +```java +public void execExtProcess() throws IOException, InterruptedException { + Process proc = Runtime.getRuntime().exec("ProcessMaybeStillRunning"); + int exitVal = proc.waitFor(); +} +``` + +Different from the previous example, this example will not result in an `IllegalThreadStateException`. However, the security problems described in the "Description" part may occur since the output and error streams of ProcessMaybeStillRunning are not handled. + +**\[Compliant Code Example]** + +```java +public class ProcessExecutor { + public void callExtProcess() throws IOException, InterruptedException { + Process proc = Runtime.getRuntime().exec("ProcessHasOutput"); + + StreamConsumer errConsumer = new StreamConsumer(proc.getErrorStream()); + StreamConsumer outputConsumer = new StreamConsumer(proc.getInputStream()); + + errConsumer.start(); + outputConsumer.start(); + + int exitVal = proc.waitFor(); + + errConsumer.join(); + outputConsumer.join(); + } + + class StreamConsumer extends Thread { + InputStream is; + + StreamConsumer(InputStream is) { + this.is = is; + } + + @Override + public void run() { + try { + byte data; + int result; + while ((result = is.read()) != -1) { + data = (byte) result; + handleData(data); + } + } catch (IOException ex) { + //Handle the exception + } + } + + private void handleData(byte data) { + ... + } + } +} +``` + +This compliant code example spawns two threads to read the output and error streams, so that the external process will not indefinitely block on the streams. + +**\[Exception]** + +External processes that do not use input, output, or error streams do not need stream handling. + +## Promptly remove temporary files after use + +**\[Description]** + +Temporary files can be used for many purposes, for example, sharing data between processes, caching memory data, and dynamically constructing class files and library files. They may be created in the shared temporary file directory of the operating system. Files in such a directory may be regularly cleaned up, for example, every night or at system restart. However, if the files are not securely created or are still accessible after fulfilling the intended purpose, an attacker who has access to the local file system can perform operations on the files in shared directories. Removing temporary files when they are no longer required allows file names and other resources (such as secondary storage) to be recycled. Each program is responsible for ensuring that temporary files are removed during normal operation. + +**\[Noncompliant Code Example]** + +```java +public boolean uploadFile(InputStream in) throws IOException { + File tempFile = File.createTempFile("tempname", ".tmp"); + try (FileOutputStream fop = new FileOutputStream(tempFile)) { + int readSize; + do { + readSize = in.read(buffer, 0, MAX_BUFF_SIZE); + if (readSize > 0) { + fop.write(buffer, 0, readSize); + } + } while (readSize >= 0); + ... //Perform other operations on the temporary file + } +} +``` + +In this noncompliant code example, the temporary file is not removed upon completion. + +**\[Compliant Code Example]** + +```java +public boolean uploadFile(InputStream in) throws IOException { + File tempFile = File.createTempFile("tempname", ".tmp"); + try (FileOutputStream fop = new FileOutputStream(tempFile)) { + int readSize; + do { + readSize = in.read(buffer, 0, MAX_BUFF_SIZE); + if (readSize > 0) { + fop.write(buffer, 0, readSize); + } + } while (readSize >= 0); + ... //Perform other operations on the temporary file + } finally { + if (!tempFile.delete()) { + //Ignore + } + } +} +``` + +In this compliant code example, the **finally** statement removes the temporary file after using it. + +# Serialization + +#### Do not deserialize external data directly + +**\[Description]** + +Deserialization is the process of deserializing a binary stream or string into a Java object. Deserializing external data can cause an attacker to construct a specified object, execute malicious code, inject malicious data into an application, or perform other malicious operations. Insecure deserialization can lead to attacks such as arbitrary code execution, privilege escalation, arbitrary file access, and DoS. + +Third-party components are usually used to serialize and deserialize data in JSON, XML, and YAML formats. Common third-party components include fastjson, jackson, XMLDecoder, XStream, and SnakeYmal. + +**\[Noncompliant Code Example]** + +```java +public class DeserializeExample implements Serializable { + private static final long serialVersionUID = -5809782578272943999L; + + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + private void readObject(java.io.ObjectInputStream ois) { + ois.defaultReadObject(); + System.out.println("Hack!"); + } +} + + //Deserialize external data + ObjectInputStream ois2= new ObjectInputStream(fis); + PersionInfo myPerson = (PersionInfo) ois2.readObject(); +``` + +In this noncompliant code example, when the object of the deserialization operation is the serialization result of the **DeserializeExample** object constructed by the attacker, an error will be reported when the `PersionInfo myPerson = (PersionInfo) ois2.readObject()` statement is executed, but the attack code in the `readObject()` method of the **DeserializeExample** object is executed. + +**\[Compliant Code Example]** (Trustlist Validation) + +```java +public final class SecureObjectInputStream extends ObjectInputStream { + public SecureObjectInputStream() throws SecurityException, IOException { + super(); + } + + public SecureObjectInputStream(InputStream in) throws IOException { + super(in); + } + + protected Class resolveClass(ObjectStreamClass desc) + throws IOException, ClassNotFoundException { + if (!desc.getName().equals("com.xxxx.PersionInfo")) {//Trustlist validation + throw new ClassNotFoundException(desc.getName() + " not find"); + } + return super.resolveClass(desc); + } +} +``` + +In this compliant code example, trustlist validation is performed on the class to be deserialized by reloading the `resolveClass()` method in the customized **ObjectInputStream**. It throws an exception when the class name is not in the trustlist. + +**\[Compliant Code Example]** (Using Security Manager) + +It is advised to use the Java security manager provided by the product wherever available. + +(1) Set **enableSubclassImplementation**. + +``` +permission java.io.SerializablePermission "enableSubclassImplementation"; + +``` + +(2) Customize **ObjectInputStream** and reload **resolveClass**. + +```java +public final class HWObjectInputStream extends ObjectInputStream { + public HWObjectInputStream() throws SecurityException, IOException { + super(); + } + + public HWObjectInputStream(InputStream in) throws IOException { + super(in); + } + + protected Class resolveClass(ObjectStreamClass desc) + throws IOException, ClassNotFoundException { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + sm.checkPermission(new SerializablePermission( + "com.xxxx." + desc.getName())); + } + return super.resolveClass(desc); + } +} +``` + +(3) Set a trustlist in the policy file. + +``` +permission java.io.SerializablePermission "com.xxxx.PersionInfo"; + +``` + +# External Data Validation + +## Validate external data before using it + +**\[Description]** + +External data includes but is not limited to the network data, user input (including input in command lines and UIs), commands, files (including program configuration files), environment variables, and inter-process communication (including pipes, messages, shared memory, sockets, and RPCs), and cross-trust domain method parameters (for APIs). + +Data outside the program is generally considered untrusted. Validation must be performed before using such data. Otherwise, incorrect calculation results, runtime exceptions, inconsistent object status, and injection attacks may occur, severely affecting the system. + +**External data validation includes:** + +- API parameter validation +- Data length validation +- Data range validation +- Data type and format validation +- Set size validation +- Validation to ensure that external data only contains permitted characters (trustlist validation), with special attention to special characters in certain cases + +Pay attention to the following points when validating external data: + +- Canonicalize external data before validation wherever necessary. For example, both **"\\uFE64"** and **\<** can represent **\<**. In web applications, if external input is not canonicalized, **"\\uFE64"** can be used to circumvent restrictions on **\<**. +- Modifications to external data must be done before validation to ensure that the validated data is exactly the data to be used. + +For performance and code simplicity, the provider validates only the request information for RESTful APIs, and the consumer validates only the response result. For a method in a call chain, the outermost external public method must be validated, and the internal public method does not need to be validated. + +**Common validation frameworks:** + +Interface: The JSR 380 (Bean Validation 2.0) and JSR 303 (Bean Validation 1.0) JavaBean parameter validation standards defines the core interface **javax.validation.Validator** and many common validation annotations. +Implementation: hibernate-validator and Spring validator + +- hibernate-validator is an implementation of JSR 380 and JSR 303 standards, which extends annotations such as @Email, @Length, @NotEmpty, and @Range. +- Spring validator is also an implementation of JSR 380 and JSR 303, and provides the **MethodValidationPostProcessor** class for validating methods. + +The product can select a proper validation framework or develop one. + +**\[Noncompliant Code Example]** + +```java +/** + * Change company information + * + * @param companies New and old company information + * @return Whether the company information is changed successfully + */ +@RequestMapping(value = "/updating", method = RequestMethod.POST) +public boolean updateCompany(@RequestBody Companies companies) { + return employeeService.updateCompany(companies.getSrcCompany(), + companies.getDestCompany()); +} +``` + +In this noncompliant code example, the `updateCompany()` interface opened by the provider fails to validate the request, which may lead to attacks. + +**\[Compliant Code Example]** + +```java +/** + * Change company information + * + * @param companies New and old company information + * @return Whether the company information is changed successfully + */ +@RequestMapping(value = "/updating", method = RequestMethod.POST) +public boolean updateCompany(@RequestBody @Valid @NotNull Companies companies) { + return employeeService.updateCompany( + companies.getSrcCompany(), companies.getDestCompany()); +} + +@Setter +@Getter +public class Companies { + @Valid + @NotNull + private Company srcCompany; + + @Valid + @NotNull + private Company destCompany; +} + +@Setter +@Getter +@Accessors(chain = true) +public class Company { + @NotBlank + @Size(min = 10, max = 256) + private String name; + + @NotBlank + @Size(min = 10, max = 512) + private String address; + + @Valid + private SubCompany subCompany; +} +``` + +This compliant code example uses the @Valid annotation to trigger parameter validation, and the validation logic is the rule specified by the annotation during object attribute declaration. Since the public method `employeeService.updateCompany()` is invoked inside the current module and parameter validation is performed for the invocation, further validation is not required. + +**\[Noncompliant Code Example]** + +This noncompliant code example directly uses the obtained environment variable value without validating it. + +```java +public static String getFile(String filePath, String fileName) { + //Obtain the class path of the process + String path = System.getProperty(RUNTIME_BASE_DIR); + //Directly use it +} +``` + +**\[Compliant Code Example]** + +This compliant code example uses the `getResource()` and `getResourceAsStream()` methods provided by ClassLoader to obtain resources from the loaded class path. + +```java +public static String getSavePath(String filePath, String fileName) { + return ClassLoader.getSystemResource(fileName).getPath(); +} +``` + +Canonicalize the environment variable value and validate it before using it: + +```java +public static String getFile(String filePath, String fileName) { + //Obtain the class path of the process + String path = System.getProperty(RUNTIME_BASE_DIR); + + //Canonicalization + //Validation, for example, StringUtils.startsWith(path, "/opt/xxxx/release/"); + //Use +} +``` + +**\[Noncompliant Code Example]** + +This noncompliant code example uses the configuration file without validating it. + +```java +@Configuration +@PropertySource("classpath:xxx.properties") +@Component +public class XxxConfig { + @Value("${appId}") + private String appId; + + @Value("${secret}") + private String citySecret; +} +``` + +**\[Compliant Code Example]** + +The Spring Boot framework can use annotations @ConfigurationProperties and @Validated to validate the configuration file: + +```java +@ConfigurationProperties(locations = "classpath: xxx.properties", prefix = "xxx") +@Validated +public class XxxConfig { + @Value("${appId}") + @Pattern(regexp = "[0-9_A-Z]{32}") + private String appId; + + @Value("${secret}") + @Pattern(regexp = "[0-9A-Z]{64,138}", message = "Authentication credential error!") + private String citySecret; + + //Setter and Getter methods +} +``` + +The ServiceComb framework can use the **validation-api** provided by Java to obtain the configuration file object from the Bean context and explicitly invoke the validation method. + +## Do not directly use external data to concatenate SQL statements + +**\[Description]** + +SQL injection occurs when the database operations represented by SQL statements constructed using external data do not behave as expected, which may lead to information leak or data tampering. The root cause is the direct use of external data to concatenate the SQL statements. The following measures can help prevent SQL injection: + +- Parameterized query: the most effective, but not applicable to table names and field names in SQL statements; +- Trustlist validation on external data: applicable to table names and field names used to concatenate SQL statements; +- Escaping special characters related to SQL injection in external data: applicable to scenarios where SQL statements must be concatenated using strings. Only fields with quotation marks can be escaped. + +Parameterized query is preferred because it is an easy way to effectively prevent SQL injection. In addition, parameterized query can improve database access performance. For example, SQL Server and Oracle databases cache a query plan for reuse when the same query statement is executed repeatedly. Common ORM frameworks (such as Hibernate and iBATIS) also support parameterized query. + +**\[Noncompliant Code Example]** (Dynamically Building SQL Statements in Java Code) + +```java +Statement stmt = null; +ResultSet rs = null; +try { + String userName = request.getParameter("name"); + String password = request.getParameter("password"); + ... + String sqlStr = "SELECT * FROM t_user_info WHERE name = '" + userName + + "' AND password = '" + password + "'"; + stmt = connection.createStatement(); + rs = stmt.executeQuery(sqlString); + ... //Handle the result set +} catch (SQLException ex) { + //Handle the exception +} +``` + +This noncompliant code example uses the user-supplied user name and password to construct the SQL statement and verifies the user name and password. The SQL statement is constructed through concatenation, leading to SQL injection risks. An ill-intentioned user who knows the user name can perform the query using `zhangsan' OR 'a' = 'a` and an **arbitrary password**. + +**\[Compliant Code Example]** (Using **PreparedStatement** for Parameterized Query) + +```java +PreparedStatement stmt = null; +ResultSet rs = null; +try { + String userName = request.getParameter("name"); + String password = request.getParameter("password"); + ... //Ensure that the lengths of userName and password are valid + String sqlStr = "SELECT * FROM t_user_info WHERE name=? AND password =?"; + stmt = connection.prepareStatement(sqlStr); + stmt.setString(1, userName); + stmt.setString(2, password); + rs = stmt.executeQuery(); + ... //Handle the result set +} catch (SQLException ex) { + //Handle the exception +} +``` + +In parameterized query, placeholders are used to represent parameter values required at execution time. In this way, the semantic logic of the SQL query is pre-defined, and the actual parameter value is determined at the execution time. Parameterized query helps databases distinguish semantic logic from parameters in SQL statements, ensuring that user input cannot change the expected semantic logic of the SQL query. If the attacker enters `zhangsan' OR 'a' = 'a` as the user name, the string is used only as the value of the **name** field. + +**\[Compliant Code Example]** (Escaping the Input) + +```java +public List queryBooks(List queryCondition) { + ... + try { + StringBuilder sb = new StringBuilder("select * from t_book where "); + Codec oe = new OracleCodec(); + if (queryCondition != null && !queryCondition.isEmpty()) { + for (Expression e : queryCondition) { + String exprString = e.getColumn() + e.getOperator(); + String safeValue = XXXEncoder.encodeForSQL(oe, e.getValue()); + sb.append(exprString).append("'").append(safeValue).append("' and "); + } + sb.append("1=1"); + Statement stat = connection.createStatement(); + ResultSet rs = stat.executeQuery(sb.toString()); + ... //Other code + } + } + ... +} +``` + +Although parameterized query is the most convenient and effective way to prevent SQL injection, it is not applicable to all scenarios, because not any part of an SQL statement can be replaced by a placeholder before execution. When an SQL statement is dynamically constructed using external data that cannot be replaced by placeholders before execution, the external data must be validated. Each DBMS has its own escape mechanism to tell the database that the input should be treated as data, not code logic. Therefore, as long as the input data is properly escaped, SQL injection will not occur. + +**Note**: If the passed data is a field name or table name, trustlist validation is recommended. + +Similar to concatenating parameters in program code, concatenating parameter values to create query strings in stored procedures also has SQL injection risks. + +**\[Noncompliant Code Example]** (Dynamically Building SQL Statements in Stored Procedure) + +SQL Server stored procedure: + +```sql +CREATE PROCEDURE sp_queryItem + @userName varchar(50), + @password varchar(50) +AS +BEGIN + DECLARE @sql nvarchar(500); + SET @sql = 'SELECT * FROM t_user_info + WHERE name= ''' + @userName + ''' + AND password= ''' + @password + ''''; + EXEC(@sql); +END +GO +``` + +Similar to concatenating parameters in program code, concatenating parameter values to create query strings in stored procedures also has SQL injection risks. + +**\[Compliant Code Example]** (Parameterized Query in Stored Procedure) + +SQL Server stored procedure: + +```sql +CREATE PROCEDURE sp_queryItem + @userName varchar(50), + @password varchar(50) +AS +BEGIN + SELECT * FROM t_user_info + WHERE name = @userName + AND password = @password; +END +GO +``` + +Use parameterized query in stored procedures and avoid insecure dynamic building of SQL statements. When compiling these stored procedures, the database will generate a SELECT query execution plan to allow only original SQL semantics to be executed and prohibit the execution of any parameter values, even injected SQL statements. + +## Do not use external data to construct format strings + +**\[Description]** + +Format in Java can convert an object into a character string in a specified format. A format string controls the length, content, and style of the final character string. If the format specified in the format string does not match the format object, an exception may be thrown. An attacker who can directly control a format string can cause information leak, DoS, system functional anomalies, and other risks. + +**\[Noncompliant Code Example]** + +```java +public String formatInfo(String formatStr) { + String value = getData(); + return String.format(formatStr, value)); +} + +String formatStr = req.getParameter("format"); +String formattedValue = formatInfo(formatStr); +``` + +In this noncompliant code example, an externally specified format is used to format a character string. If the externally specified format is not a character type (for example, **%d**), an exception will occur during the format operation. + +**\[Compliant Code Example]** + +```java +public String formatInfo() { + String value = getData(); + return String.format("my format: %s", value)); +} +``` + +This compliant code example excludes user input from the format string. + +## Do not pass external data to the **Runtime.exec()** method or **java.lang.ProcessBuilder** class + +**\[Description]** + +The `Runtime.exec()` method or `java.lang.ProcessBuilder` class is used to start a new process and execute commands in the new process. Directly executing a command constructed using external data, for example, `Runtime.getRuntime().exec("ping 127.0.0.1")`, may incur the following risks: + +- The command to be executed is split using the command interpreter. In this mode, multiple commands can be executed, causing command injection risks. +- Parameters are injected into the command using spaces, double quotation marks, or strings starting **-/**, leading to parameter injection risks. + +**Using external data to construct non-shell commands** + +**\[Noncompliant Code Example]** + +```java +String cmd = "ping" + ip; +Runtime rt = Runtime.getRuntime(); +Process proc = rt.exec(cmd); +``` + +When the value of **ip** is **127.0.0.1 -t**, the **-t** parameter is injected into the executed command. As a result, the ping process is continuously executed. + +The solutions to command injection or parameter injection are as follows: + +1\. **Do not directly run the command** + +To use the functions provided by standard Java libraries or open-source components, use the APIs of the libraries or components to avoid running commands. + +If command execution is inevitable, validate and sanitize external data. + +2\. **Validate external data** + +**\[Compliant Code Example]** (Data Validation) + +```java +... +//The str value comes from the user input +if (!Pattern.matches("[0-9A-Za-z@]+", str)) { + //Handle the error +} +... +``` + +When external data is used to concatenate commands, validate external data using a trustlist and exclude special characters that may incur injection risks. + +3\. **Escape external data** + +**\[Compliant Code Example]** (Escape) + +```java +String encodeIp = XXXXEncoder.encodeForOS(new WindowsCodec(), ip); +String cmd = "cmd.exe /c ping " + encodeIp; +Runtime rt = Runtime.getRuntime(); +Process proc = rt.exec(cmd); +... +``` + +If risky special characters cannot be avoided through input validation during command execution, the external input must be escaped. Using escaped fields to concatenate commands can effectively prevent command injection. + +Remarks: The correct practice is to escape only external input, but not the entire concatenated command. The escape method can effectively prevent command injection, but not parameter injection. + +## Do not directly use external data to concatenate XML + +**\[Description]** + +Using unverified data to construct XML will result in XML injection vulnerabilities. If users are allowed to enter structured XML segments, they can inject XML tags into the XML data domain to rewrite the structure and content of the target XML file. These tags are identified and interpreted by the XML parser and may cause XML injection. + +**\[Noncompliant Code Example]** + +```java +private void createXMLStream(BufferedOutputStream outStream, User user) + throws IOException { + String xmlString; + xmlString = "operator" + user.getUserId() + + "" + user.getDescription() + ""; + ... //Parse the XML string +} +``` + +An ill-intentioned user may use the following string as the user ID: + +``` +"joeadministratorjoe" + +``` + +And enter the following normal input in the description field: + +``` +"I want to be an administrator" + +``` + +Eventually, the entire XML string becomes the following: + +```xml + + operator + joe + administrator + joe + I want to be an administrator + +``` + +The SAX parser (org.xml.sax and javax.xml.parsers.SAXParser) overwrites the value of the second **role** field when interpreting the XML file. As a result, the user is escalated from an operator to an administrator. + +**\[Noncompliant Code Example]** (XML Schema or DTD Validation) + +```java +private void createXMLStream(BufferedOutputStream outStream, User user) + throws IOException { + String xmlString; + xmlString = "" + user.getUserId() + + "operator" + user.getDescription() + + ""; + + StreamSource xmlStream = new StreamSource(new StringReader(xmlString)); + + //Create an SAX parser that uses the schema to perform validation + SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + StreamSource ss = new StreamSource(new File("schema.xsd")); + try { + Schema schema = sf.newSchema(ss); + Validator validator = schema.newValidator(); + validator.validate(xmlStream); + } catch (SAXException ex) { + throw new IOException("Invalid userId", ex); + } + + //The XML is valid and is processed + outStream.write(xmlString.getBytes(StandardCharsets.UTF_8)); + outStream.flush(); +} +``` + +The schema definition in the **schema.xsd** file is as follows: + +```xml + + + + + + + + + + + +``` + +An ill-intentioned user may use the following string as the user ID: + +``` +"joeAdministratorI want to be an administrator" + +``` + +Eventually, the entire XML string becomes the following: + +```xml + + joe + Administrator + I want to be an administrator + +``` + +The `` at the beginning of the description field will comment out the role information hard coded in the XML string. Although the user role has been changed to the administrator by an attacker, the entire XML string can still be verified by the schema. XML schema or DTD validation ensures that the XML format is valid, but attackers can tamper with the XML content without breaking the original XML format. + +**\[Compliant Code Example]** (Trustlist Validation) + +```java +private void createXMLStream(BufferedOutputStream outStream, User user) + throws IOException { + //Write the XML string only when the user ID contains only letters, digits, and underscores (_) + if (!Pattern.matches("[_a-bA-B0-9]+", user.getUserId())) { + //Handle the error + } + if (!Pattern.matches("[_a-bA-B0-9]+", user.getDescription())) { + //Handle the error + } + String xmlString = "" + user.getUserId() + + "operator" + + user.getDescription() + ""; + outStream.write(xmlString.getBytes(StandardCharsets.UTF_8)); + outStream.flush(); +} +``` + +The trustlist validation ensures that the user ID contains only letters, digits, and underscores (\_) + +**\[Compliant Code Example]** (Using a Secure XML Library) + +```java +public static void buidlXML(FileWriter writer, User user) throws IOException { + Document userDoc = DocumentHelper.createDocument(); + Element userElem = userDoc.addElement("user"); + Element idElem = userElem.addElement("id"); + idElem.setText(user.getUserId()); + Element roleElem = userElem.addElement("role"); + roleElem.setText("operator"); + Element descrElem = userElem.addElement("description"); + descrElem.setText(user.getDescription()); + XMLWriter output = null; + try { + OutputFormat format = OutputFormat.createPrettyPrint(); + format.setEncoding("UTF-8"); + output = new XMLWriter(writer, format); + output.write(userDoc); + output.flush(); + } finally { + //Close the stream + } +} +``` + +This compliant code example uses Dom4j, a well-defined, open-source XML tool library, to construct XML. Dom4j will encode the text data field in XML format to protect the original structure and format of the XML from damage. + +In this example, if the attacker enters the following string as the user ID: + +``` +"joeAdministratorI want to be an administrator" + +``` + +The generated XML will take the following format: + +```xml + + joe</id><role>Administrator</role><!-- + operator + --><description>I want to be an administrator + +``` + +As shown above, **\<** and **>** are replaced with **\<** and **\>** respectively after XML encoding. As a result, the attacker fails to escalate from an operator to an administrator. + +**\[Compliant Code Example]** (Encoding) + +```java +private void createXMLStream(BufferedOutputStream outStream, User user) + throws IOException { + ... + String encodeUserId = XXXXEncoder.encodeForXML(user.getUserId()); + String encodeDec = XXXXEncoder.encodeForXML(user.getDescription()); + + String xmlString = "" + encodeUserId + + "operator" + encodeDec + + ""; + outStream.write(xmlString.getBytes(StandardCharsets.UTF_8)); + outStream.flush(); +} +``` + +In this compliant code example, external data is encoded before the XML string is concatenated, to prevent tampering with the XML string structure. + +## Prevent XML External Entity (XXE) attacks caused by parsing external XML + +**\[Description]** + +XML entities include internal and external entities. An external entity takes the format of `` or ``. In Java, protocols that introduce external entities include HTTP, HTTPS, FTP, file, JAR, netdoc, and mailto. The XXE vulnerability occurs when an application parses external XML data or files without forbidding the loading of external entities, causing arbitrary file reading, intranet port scanning, intranet website attacks, DoS, and other attacks. + +1\. Use the external entity reference function to read arbitrary files: + +```xml + + ]> + + Joe + &file; + ... + +``` + +2\. Use parameter entities and **\** to avoid XML parsing syntax errors and the parsing of malicious entities. + +XML file: Construct the parameter entities **% start**, **% goodies**, **% end**, and **% dtd** to define a malicious **combine.dtd**. + +```xml + + + + "> + + %dtd; + ]> +&all; +``` + +Define the **\&all** entity in the malicious DTD **combine.dtd**. + +```xml + + +``` + +An ill-intentioned user can even construct a malicious **combine.dtd** to send the result to the destination address and finally obtain the **file:///etc/fstab** file. + +```xml + +"> +%send; +``` + +**\[Noncompliant Code Example]** + +In this example, an external XML file is parsed. The parsing of DTDs or external entities is not disabled. + +```java +private void parseXmlFile(String filePath) { + try { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document doc = db.parse(new File(filePath)); + ... //Parse the XML file + } catch (ParserConfigurationException ex) { + //Handle the exception + } + ... +} +``` + +This noncompliant code example does not provide security protection for XML parsing. When the XML file is crafted by an attacker, the system is vulnerable to XXE attacks. + +**\[Complaint Code Example]** (Disabling DTD Parsing) + +```java +private void parserXmlFileDisableDtds(String filePath) { + try { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + + dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + dbf.setFeature("http://xml.org/sax/features/external-general-entities", false); + dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document doc = db.parse(new File(filePath)); + ... //Parse the XML file + } catch (ParserConfigurationException ex) { + //Handle the exception + } + ... +} +``` + +The compliant code example disables the parsing of DTDs, which can prevent both XXE and internal entity attacks. + +**\[Compliant Code Example]** (Disabling the Parsing of External General Entities and Parameter Entities) + +This compliant code example can prevent XXE attacks but not XML internal entity attacks. + +```java +private void parserXmlFileDisableExternalEntityes(String filePath) { + try { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", false); + dbf.setFeature("http://xml.org/sax/features/external-general-entities", false); + dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document doc = db.parse(new File(filePath)); + ... //Parse the XML file + } catch (ParserConfigurationException ex) { + //Handle the exception + } + ... +} +``` + +**\[Compliant Code Example]** (Trustlist Validation on External Entities) + +The compliant code example defines a **CustomResolver** class to implement interface `org.xml.sax.EntityResolver`. A customized mechanism for processing external entities is implemented in this class. The customized entity parsing method uses a simple trustlist for validation. If a match is found in the trustlist, the corresponding file content is returned; if no match is found, the returned result is empty. + +```java +private static void parserXmlFileValidateEntities(String filePath) { + try { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + db.setEntityResolver(new ValidateEntityResolver()); + Document doc = db.parse(new File(filePath)); + ... //Parse the XML file + } catch (ParserConfigurationException ex) { + //Handle the exception + } + ... +} + +class ValidateEntityResolver implements EntityResolver { + private static final String GOOD_ENTITY = "file:/Users/onlinestore/good.xml"; + + public InputSource resolveEntity(String publicId, String systemId) + throws SAXException, IOException { + if (publicId != null && publicId.equals(GOOD_ENTITY)) { + return new InputSource(publicId); + } else if (systemId != null && systemId.equals(GOOD_ENTITY)) { + return new InputSource(systemId); + } else { + return new InputSource(); + } + } +} +``` + +If external entities must be used in XML operations in the system, the external entities must be validated against the trustlist. As shown in the above example, a `ValidateEntityResolver` class is customized (with implementation interface `org.xml.sax.EntityResolver`) to validate XXEs using the `resolveEntity` method. XXEs not in the trustlist are not parsed. + +Remarks: The XML parser used above is only an example. When a program loads external XML data, you can disable the parsing of external entities by setting attributes or other methods that take effect on the parser, and construct malicious XML content as shown in the above example to check the program response, so as to determine whether the set attributes take effect. + +## Prevent XML Entity Expansion (XEE) attacks caused by parsing external XML + +**\[Description]** + +The content of XML internal entities has been declared in Doctype. An internal entity takes the format of or ``. XEE attack is a common internal entity attack. It mainly attempts to consume the server memory resources of the target program to cause DoS attacks. XXE and XEE attacks have different protection measures (disabling DTD parsing can prevent both). + +Parsing the malicious internal entity in the following example occupies many server memory resources, causing DoS attacks. + +```xml + + + + + + + + + + + ]> +&lol9; +``` + +**Disabling DTD parsing is the best method to protect** against XEE attacks. You can also limit the number of internal entities to reduce the possibility of XEE attacks. If internal entities are not required, disable DTD parsing. If internal entities are required, strictly limit the number of internal entities and the size of XML content. + +**\[Complaint Code Example]** (Disabling DTD Parsing) + +```java +public void receiveXMLStream(InputStream inStream) + throws ParserConfigurationException, SAXException, IOException { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + dbf.setFeature("http://xml.org/sax/features/external-general-entities", false); + dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false); + DocumentBuilder db = dbf.newDocumentBuilder(); + db.parse(inStream); +} +``` + +**\[Compliant Code Example]** (Limiting the Number of Internal Entities to Be Parsed) + +The default maximum number of entities to be parsed by the JAXP parser in Java is 64,000, while fewer entities need to be parsed by the JAXP parser in fact. Therefore, we can set a smaller number. The following code example limits the number of entities to be parsed by setting the attributes of the DOM parser. + +```java +public void receiveXMLStream(InputStream inStream) + throws ParserConfigurationException, SAXException, IOException { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setAttribute("http://www.oracle.com/xml/jaxp/properties/entityExpansionLimit", + "200"); + DocumentBuilder db = dbf.newDocumentBuilder(); + db.parse(inStream); +} +``` + +Remarks: The **http://www.oracle.com/xml/jaxp/properties/entityExpansionLimit** attribute is supported in JDK 7u45+ and JDK 8. The SAX and StAX parsers in JAXP do not support this attribute. + +**\[Compliant Code Example]** (Limiting the Number of Internal Entities to Be Parsed) + +The following code example limits the number of entities to be parsed by setting system attributes. + +```java +public void receiveXMLStream(InputStream inStream) + throws ParserConfigurationException, SAXException, IOException { + + //Use system attributes to limit the number of entities + System.setProperty("entityExpansionLimit", "200"); + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + db.parse(inStream); +} +``` + +Remarks: The **entityExpansionLimit** attribute is supported in JDK 7u45+ and JDK 8. This method is effective in both SAX and StAX parsers in JAXP. + +Some products use the DOM, SAX, and StAX parsers provided by the Xerces third-party JAR package, where you can set `setFeature("http://javax.xml.XMLConstants/feature/secure-processing", true)` to limit the number of entities to be no more than 100,000. + +**\[Compliant Code Example]** (Limiting the Number of Internal Entities to Be Parsed) + +This compliant code example limits the number of parsed entities in the Xerces package. + +```java +private static void receiveXMLStream(InputStream inStream) + throws ParserConfigurationException, SAXException, IOException { + DocumentBuilderFactory factory = DocumentBuilderFactoryImpl.newInstance(); + factory.setFeature("http://javax.xml.XMLConstants/feature/secure-processing", true); + DocumentBuilder db = factory.newDocumentBuilder(); + org.w3c.dom.Document doc = db.parse(inStream); + doc.getChildNodes(); +} +``` + +Remarks: The XML parser used above is only an example. When a program loads external XML data, you can disable the parsing of internal entities by setting attributes or other methods that take effect on the parser, and construct malicious XML content as shown in the above example to check the program response, so as to determine whether the set attributes take effect. + +## Do not use insecure XSLT to convert XML files + +**\[Description]** + +Extensible stylesheet language transformation (XSLT) can convert XML data into other XML format or other formats such as HTML and pure text. XSLT can be exploited to execute arbitrary code. Therefore, when **TransformerFactory** is used to convert XML data, security policies need to be added to prevent insecure XSLT code execution. + +**\[Noncompliant Code Example]** + +```java +public void XsltTrans(String src, String dst, String xslt) { + //Obtain the transformer factory + TransformerFactory tf = TransformerFactory.newInstance(); + try { + //Obtain the transformer object instance + Transformer transformer = tf.newTransformer(new StreamSource(xslt)); + + //Carry out transformation + transformer.transform(new StreamSource(src), + new StreamResult(new FileOutputStream(dst))); + ... + } catch (TransformerException ex) { + //Handle the exception + } + ... +} +``` + +In this example, XSLT is not restricted and is called directly. When XSLT code resembling the following is executed, command execution vulnerabilities may occur: + +```xml + + + + + + + +``` + +**\[Compliant Code Example]** + +```java +public void xsltTrans(String src, String dst, String xslt) { + //Obtain the transformer factory + TransformerFactory tf = TransformerFactory.newInstance(); + try { + //Set a blocklist for the transformer factory to prohibit some insecure methods, which is similar to XXE protection + tf.setFeature("http://javax.xml.XMLConstants/feature/secure-processing", true); + + //Obtain the transformer object instance + Transformer transformer = tf.newTransformer(new StreamSource(xslt)); + + //Remove + transformer.setOutputProperty("omit-xml-declaration", "yes"); + + //Carry out transformation + transformer.transform(new StreamSource(src), + new StreamResult(new FileOutputStream(dst))); + ... + } catch (TransformerException ex) { + //Handle the exception + } + ... +} +``` + +A security policy can be added to **TransformerFactory**. Java has a built-in blocklist for XSLT. Here some insecure methods are disabled by setting **http://javax.xml.XMLConstants/feature/secure-processing** to **true**. + +## Try best to simplify the regular expression (regex) to prevent regular expression denial of service (ReDoS) attacks + +**\[Description]** + +ReDoS attacks are common security risks caused by inappropriate regexes. The NFA engine is used for regex matching in Java. Due to the backtracking mechanism of the NFA engine, the time consumed when a regex is not matched is longer than the time consumed when the regex is matched. That's because the regex needs to be matched against all possible paths before a mismatch is determined and a failure is returned. ReDoS attacks rarely occur when a simple regex without groups is used. The following types of regexes are vulnerable to ReDoS attacks: + +1\. Regexes containing self-repeating groups, for example: + +`^(\d+)+$` + + `^(\d*)*$` + + `^(\d+)*$` + + `^(\d+|\s+)*$` + +2\. Regexes containing repetitive groups with replacement, for example: + +`^(\d|\d|\d)+$` + +`^(\d|\d?)+$` + +Measures for defending against ReDoS attacks are as follows: + +- Check the text length before regex matching. +- Avoid using complex regexes and minimize groups. Take `^(([a-z])+\.)+[A-Z]([a-z])+$` (which has the ReDoS risk) as an example. You can delete the redundant group `^([a-z]+\.)+[A-Z][a-z]+$` without altering the check rule, eliminating the ReDoS risk. +- Do not dynamically construct regexes. Implement strict trustlist validation when using external data to construct regexes. + +**\[Noncompliant Code Example]** + +```java +private static final Pattern REGEX_PATTER = Pattern.compile("a(b|c+)+d"); + +public static void main(String[] args) { + ... + Matcher matcher = REGEX_PATTER.matcher(args[0]); + if (matcher.matches()) { + ... + } else { + ... + } + ... +} +``` + +This noncompliant code example uses the `a(b|c+)+d` regex which has the ReDoS risk. When the matched string resembles **accccccccccccccccx**, the code execution time sees exponential growth with the increase in the number of **c** characters. + +**\[Compliant Code Example]** + +```java +private static final Pattern REGEX_PATTER = Pattern.compile("a[bc]+d"); + +public static void main(String[] args) { + ... + Matcher matcher = REGEX_PATTER.matcher(args[0]); + if (matcher.matches()) { + ... + } else { + ... + } + ... +} +``` + +This compliant code example simplifies the regex into `a[bc]+d` without changing the function, eliminating the ReDoS risk. + +**\[Noncompliant Code Example]** + +```java +String key = request.getParameter("keyword"); +... +String regex = "[a-zA-Z0-9_-]+@" + key + "\\.com"; +Pattern searchPattern = Pattern.compile(regex); +... +``` + +This noncompliant code example uses the keyword specified by an external input source to construct the regex. The ReDoS risk may occur when the keyword contains repetitive groups. Therefore, during code development, do not use external data directly as regexes or to construct regexes. + +## Do not use external data directly as the class or method name in the reflection operation + +**\[Description]** + +Using external data as the class or method name in the reflection operation can lead to an unexpected logic process, that is, unsafe reflection. This can be exploited by ill-intentioned users to bypass security checks or execute arbitrary code. If external data is required for reflection operations, the data must be validated against a class or method trustlist. Besides, the program could also allow users to select classes or methods in a given scope to protect reflection operations. + +**\[Noncompliant Code Example]** + +```java +String className = request.getParameter("class"); +... +Class objClass = Class.forName(className); +BaseClass obj = (BaseClass) objClass.newInstance(); +obj.doSomething(); +``` + +This noncompliant code example uses an external class name to directly construct an object through reflection. An ill-intentioned user can construct a malicious `BaseClass` subclass object, take control over a `BaseClass` subclass, and execute arbitrary code in the `doSomething()` method of the subclass. An ill-intentioned user can further use the code to execute the default constructor of any class. Even if an `ClassCastException` is thrown in class conversion, the code in the constructor is executed as expected by the ill-intentioned user. + +**\[Compliant Code Example]** + +```java +String classIndex = request.getParameter("classIndex"); +String className = (String) reflectClassesMap.get(classIndex); +if (className != null) { + Class objClass = Class.forName(className); + BaseClass obj = (BaseClass) objClass.newInstance(); + obj.doSomething(); +} else { + throw new IllegalStateException("Invalid reflect class!"); +} +... +``` + +In this compliant code example, an external user can only specify the class index. If this class index can be mapped to a class name, the reflection operation is performed; if not, the program considers it invalid. + +# Log Auditing + +#### Do not log external data + +**\[Description]** + +Recording external data into logs may incur the following risks: + +- Log injection: Ill-intentioned users can use characters such as carriage returns and line feeds to inject a complete log. +- Leak of sensitive information: Recording user-supplied sensitive information into logs may leak the sensitive information. +- Junk log or log overwriting: If a user enters very long strings, a large number of junk logs may be generated. If logs are cyclically overwritten, valid logs may be maliciously overwritten. + +Therefore, do not record external data in logs. If external data must be logged, validate and sanitize the external data and truncate long strings. Before being recorded in logs, sensitive data such as keys and passwords must be masked with a fixed number of asterisks (\*), and other sensitive data, such as mobile numbers and email addresses, need to be anonymized. + +**\[Noncompliant Code Example]** + +```java +String jsonData = getRequestBodyData(request); +if (!validateRequestData(jsonData)) { + LOG.error("Request data validate fail! Request Data : " + jsonData); +} +``` + +In this noncompliant code example, the requested JSON data will be directly logged when the validation fails. Sensitive data, if any, in the JSON string may be leaked. An ill-intentioned user can use carriage returns and line feeds to inject a crafted log into the JSON string. A long JSON string can lead to redundant logs. + +**\[Compliant Code Example]** + +Newline characters, such as **\\r\\n** in external data, could be replaced before being recorded in logs to prevent log injection. The following code example shows a compliant implementation: + +```java +public String replaceCRLF(String message) { + if (message == null) { + return ""; + } + return message.replace('\n', '_').replace('\r', '_'); +} +``` + +#### Do not log sensitive information such as passwords and keys + +**\[Description]** + +Sensitive data, such as passwords and keys as well as their ciphertext forms, shall not be recorded in logs. Otherwise, the sensitive data may be leaked. If such data is absolutely needed in logs, replace it with a fixed number of asterisks (\*). + +**\[Noncompliant Code Example]** + +```java +private static final Logger LOGGER = Logger.getLogger(TestCase1.class); +... +LOGGER.info("Login success, user is " + userName + ", password is " + + encrypt(pwd.getBytes(StandardCharsets.UTF_8))); +``` + +**\[Compliant Code Example]** + +```java +private static final Logger LOGGER = Logger.getLogger(TestCase1.class); +... +LOGGER.info("Login success, user is " + userName + ", password is ********."); +``` + +# Performance and Resource Management + +#### Release resources in **try-with-resource** or **finally** during I/O operations + +**\[Description]** + +Resources need to be released in a timely manner when they are no longer needed. However, when exceptions occur, resource release is often ignored. This requires explicitly use of `close()` or another method in the **finally** block of the **try-catch-finally** structure to release resources during database and I/O operations. If multiple I/O objects need to be released using `close()`, each `close()` invocation must be done in a separate **try-catch** structure, so as to prevent a release failure of one I/O object from affecting the release of other I/O objects. + +Java 7 provides the automatic resource management feature **try-with-resource**. It takes precedence over **try-finally**, so the resulting code is more concise and clear, and the resulting exceptions are more valuable. Especially for multiple resources or exceptions, **try-finally** may lose the previous exception, while **try-with-resource** retains the first exception and treats subsequent exceptions as suppressed exceptions, which can be checked based on the array returned by `getSuppressed()`. + +**try-finally** is also used in scenarios such as `lock()` and `unlock()`. + +**\[Compliant Code Example]** + +```java +try (FileInputStream in = new FileInputStream(inputFileName); + FileOutputStream out = new FileOutputStream(outputFileName)) { + copy(in, out); +} +``` + +# Miscellaneous + +#### Use cryptographically secure random numbers in security scenarios + +**\[Description]** + +Insecure random numbers may be partially or entirely predicted, causing security risks in the system. Therefore, cryptographically secure random numbers must be used in security scenarios. Cryptographic secure random numbers fall into two types: + +- Random numbers generated by true random number generators (TRNGs). +- Random numbers generated by pseudo random number generators (PRNGs) which use the few random numbers generated by TRNGs as seeds + +In Java, `SecureRandom` is a cryptographically secure PRNG. When using PRNGs to generate random numbers, make sure to use true random numbers as seeds. + +Common security scenarios include: + +- Generation of IVs, salts, keys, etc. for cryptographic algorithm purposes +- Generation of session IDs +- Generation of random numbers in the challenge algorithm +- Generation of random numbers of verification codes + +**\[Noncompliant Code Example]** + +```java +public byte[] generateSalt() { + byte[] salt = new byte[8]; + Random random = new Random(123456L); + random.nextBytes(salt); + return salt; +} +``` + +`Random` only generates insecure random numbers, which cannot be used as salts. + +**\[Noncompliant Code Example]** + +```java +public byte[] generateSalt() { + byte[] salt = new byte[8]; + SecureRandom random = new SecureRandom(); + random.nextBytes(salt); + return salt; +} +``` + +#### Use SSLSocket, but not Socket, for secure data exchange + +**\[Description]** + +Programs must use SSLSocket, but not Socket, for network communications involving cleartext sensitive information. Socket provides cleartext communication wherein the sensitive data may be intercepted by attackers, so that the attackers can launch man-in-the-middle attacks to tamper with packets. SSLSocket provides security protection on the basis of Socket, such as identity authentication, data encryption, and integrity protection. + +**\[Noncompliant Code Example]** + +```java +try { + Socket socket = new Socket(); + socket.connect(new InetSocketAddress(ip, port), 10000); + os = socket.getOutputStream(); + os.write(userInfo.getBytes(StandardCharsets.UTF_8)); + ... +} catch (IOException ex) { + //Handle the exception +} finally { + //Close the stream +} +``` + +This noncompliant code example uses Socket to transfer cleartext packets. Sensitive information, if any, in the packets may be leaked or tampered with. + +**\[Compliant Code Example]** + +```java +try { + SSLSocketFactory sslSocketFactory = + (SSLSocketFactory) SSLSocketFactory.getDefault(); + SSLSocket sslSocket = (SSLSocket) sslSocketFactory.createSocket(ip, port); + os = sslSocket.getOutputStream(); + os.write(userInfo.getBytes(StandardCharsets.UTF_8)); + ... +} catch (IOException ex) { + //Handle the exception +} finally { + //Close the stream +} +``` + +This compliant code example uses SSLSocket to protect packets using SSL/TLS. + +**\[Exception]** + +The mechanisms that SSLSocket provides to ensure the secure transfer of packets may result in significant performance overhead. Regular sockets are sufficient under the following circumstances: + +- The data being sent over the socket is not sensitive. +- The data is sensitive but properly encrypted. + +#### Avoid public network addresses in code + + + +**\[Description]** + +Providing public network addresses that are invisible and unknown to users in code or scripts can raise doubts among customers. + +Public network addresses (including public IP addresses, public URLs/domain names, and email addresses) contained in the released software (including software packages and patch packages) must meet the following requirements: +1\. Avoid public network addresses that are invisible on UIs or not disclosed in product documentation. +2\. Do not write disclosed public IP addresses in code or scripts. They can be stored in configuration files or databases. + +The public IP addresses built in open-source or third-party software must meet the first requirement. + +**\[Exception]** + +This requirement is not mandatory when public network addresses must be specified as required by standard protocols. For example, an assembled public network URL must be specified for the namespace of functions based on the SOAP protocol. W3.org addresses on HTTP pages and feature names in XML parsers are also exceptions. \ No newline at end of file diff --git a/website/docs/extras/en/contribute/OpenHarmony-JavaScript-coding-style-guide.md b/website/docs/extras/en/contribute/OpenHarmony-JavaScript-coding-style-guide.md new file mode 100644 index 0000000000000000000000000000000000000000..1ec783d3980dc4b15f71b177c260bdf2635a2a2e --- /dev/null +++ b/website/docs/extras/en/contribute/OpenHarmony-JavaScript-coding-style-guide.md @@ -0,0 +1,773 @@ +--- +title: "OpenHarmony-JavaScript-coding-style-guide" +prepermalink: /extras/a9c4ef53ea515e95661a76f5c3e405ce/ +permalink: /extras/a9c4ef53ea515e95661a76f5c3e405ce/ +relpath: "OpenHarmony-3.1-Release/en/contribute/OpenHarmony-JavaScript-coding-style-guide.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [OpenHarmony-JavaScript-coding-style-guide] +--- +# JavaScript Coding Style Guide + +## Goal +Rules are not perfect. Prohibiting features that are useful in specific situations can have an impact on code implementation, but we set the rules for the benefit of most programmers. If we identify a rule cannot be followed in the operations, we should work together to improve the rule. You are supposed to have the basic JavaScript language capabilities to refer to this guide, instead of learning the JavaScript language from it. + +## General Principles +The code is required to be **readable, maintainable, secure, reliable, testable, efficient, and portable** on the premise that the functions are correct. + +## Convention + +**Rule**: Conventions that must be complied with during programming +**Recommendation**: Conventions that must be considered during programming + +It is important to understand why this convention is so stated in both "Rules" or "Recommendations" and make efforts to comply. + +## Exceptions + +If the General Principle is not violated, the rules can be properly violated after full consideration and sufficient reasons are provided. +Exceptions compromise code consistency so please avoid exceptions. Exceptions to "Rules" should be rare. + +The style consistency principle is preferred in the following situations: +**When modifying external open-source code and third-party code, comply with the existing rules of the open-source code and third-party code and keep the style consistent. ** + +## Programming Regulations + +### Naming Regulations + +#### Rule 1.1 Use correct English spellings to name, no use of pinyin spellings. + +**Counterexample:**`xingming`,`zhanghao` + +**Example:**`username`,`account` + +#### Rule 1.2 Use abbreviations as few as possible, except for common words or professional words. For example, `context` can be shortened to `ctx`, `request` can be shortened to `req`, and `response` can be shortened to `resp`. + +**Note:** Complete spelling of words can avoid unnecessary misunderstanding. + +**Exceptions:** The variable name of the cyclic condition can be ` i` or ` j` in the cyclic language. + +#### Rule 1.3 Class name, enumeration name and namespace name should comply the `upperCamelCase` style. + +**Example:** + +```javascript +// Class name +class User { + constructor(username) { + this.username = username; + } + + sayHi() { + console.log(`hi, ${this.username}`); + } +} + +// Enumeration name +const UserType = { + TEACHER: 0, + STUDENT: 1 +}; + +// Namespace +const Base64Utils = { + encrypt: function(text) { + // todo encrypt + }, + decrypt: function(text) { + // todo decrypt + } +}; +``` + +#### Rule 1.4 Variable name, method name, and parameter name should comply the `lowerCamelCase` style. + +**Example:** + +```javascript +let msg = 'Hello world'; + +function sendMsg(msg) { + // todo send message +} + +function findUser(userID) { + // todo find user by user ID +} +``` + +#### Rule 1.5 The names of static constants and enumeration values must be in upper case, and words are separated by underscores (_). + +**Example:** + +```javascript +const MAX_USER_SIZE = 10000; + +const UserType = { + TEACHER: 0, + STUDENT: 1 +}; +``` + +#### Recommendation 1.6 Do not use negative Boolean variable names. Local variables or methods of the Boolean type must be prefixed with expressions with the meaning of right or wrong. + +**Counterexample:** + +```javascript +let isNoError = true; +let isNotFound = false; +function empty() {} +function next() {} +``` + +**Example:** + +```javascript +let isError = false; +let isFound = true; +function isEmpty() {} +function hasNext() {} +``` + +### Code Format + +#### Rule 2.1 Use two spaces to indent, and do not use the `tab` character. + +**Note:** Only spaces are allowed for indentation. Two spaces are allowed at a time. Tab characters are not allowed for indentation. + +**Example:** + +```javascript +const dataSource = [ + { + id: 1, + title: 'Title 1', + content: 'Content 1' + }, + { + id: 2, + title: 'Title 2', + content: 'Content 2' + } +]; + +function render(container, dataSource) { + if (!container || !dataSource || !dataSource.length) { + return void 0; + } + + const fragment = document.createDocumentFragment(); + for (let data of dataSource) { + if (!data || !data.id || !data.title || !data.content) { + continue; + } + const element = document.createElement("div"); + const textNode = document.createTextNode(`${data.title}: ${data.content}`); + element.appendChild(textNode); + element.setAttribute("id", data.id); + fragment.appendChild(element); + } + container.appendChild(fragment); +} + +``` + +#### Rule 2.2 The line width cannot exceed 120 characters. + +**Note:** It is recommended that each line should contain no more than 120 characters. Use a proper method to break the line if the line contain more than 120 characters. + +**Exception:** If a line of comments contains more than 120 characters of commands or URLs, keep it in one line for easy copying, pasting, and searching by running the grep command. The preprocessed error information is easy to read and understand in one line, even if it contains more than 120 characters. + +#### Rule 2.3 The use of braces must comply with the following conventions: + +1. If the value in the braces is empty, the value can be abbreviated as `{}` without a newline. +2. The left braces do not contain a line feed, and the left braces are followed by a line feed. +3. Line feeds before the right brace. If there is `else` or `catch` after the brace, line feeds are not required. In other cases, line feeds are required. + +#### Rule 2.4 Implementations of conditional and loop statements must be enclosed in braces, even if there is only one statement. + +**Counterexample:** + +```javascript +if (condition) + console.log('success'); + +for(let idx = 0; idx < 5; ++idx) + console.log(idx); +``` + +**Example:** + +```javascript +if (condition) { + console.log('success'); +} + +for(let idx = 0; idx < 5; ++idx) { + console.log(idx); +} +``` + +#### Rule 2.5 Condition statements and loop statements cannot be written in one line. + +**Counterexample:** + +```javascript +if (condition) { /* todo something */ } else { /* todo other */ } + +let idx = 0; +while(idx < 10) console.log(idx); +``` + +**Example:** + +```javascript +if (condition) { + /* todo something */ +} else { + /* todo other */ +} + +let idx = 0; +while(idx < 10) { + console.log(idx); +} +``` + +#### Rule 2.6 The `case` and `default` in the `switch` statement must be indented by one layer. + +**Example:** + +```javascript +switch(condition) { + case 0: + doSomething(); + break; + case 1: { // the braces is not necessary + doOtherthing(); + break; + } + default: + break; +} +``` + +#### Rule 2.7 The line feeds of expressions must be consistent, and the operator must be placed at the end of the line. + +**Note:** If a long expression does not meet the line width requirement, you need to wrap the line in a proper position. Generally, in the late phrase of the lower-priority operator or connector, the operator or connector should be placed at the end of the line. The operator and separator are placed at the end of the line, indicating that there is not the end. + +**Example:** + +```javascript +// if the condition statement exceeds the line width. +if (userCount > MAX_USER_COUNT || + userCount < MIN_USER_COUNT) { + doSomething(); +} + +const sum = + number1 + + number2 + + number3 + + number4 + + number5 + + number6 + + number7 + + number8 + + number9; +``` + +#### Rule 2.8 Multiple variable definitions and assignment statements cannot be written in one line. + +**Counterexample:** + +```javascript +let maxCount = 10, isCompleted = false; + +let pointX, pointY; +pointX = 10; pointY = 0; +``` + +**Example:** + +```javascript +let maxCount = 10; +let isCompleted = false; + +let pointX = 0; +let pointY = 0; +``` + +#### Rule 2.9 Spaces should highlight keywords and important information. Avoid unnecessary spaces. + +**Note:** Spaces reduce code density and increase code readability. The general rules are as follows: + +1. Add a spaces after keywords `if`、`elseif`、`else`、`switch`、`while`、`for`. +2. No space is added between the parentheses. +3. Spaces must be added on both sides of the braces, except for simple scenarios such as `{}`. +4. No space is added between multiple parentheses. +5. No space is added after unary operators (`&`, `*`, `+`, `-`, `!`,etc.). +6. Add a space on the left and right side of binary operators `=`、`+`、`-`、`*`、`/`、`%`、`|`、`&`、`||`、`&&`、`<`、`>`、`<=`、`>=`、`==`、`!=`、`===`、`!==`, etc.) +7. Add a space on the left and right side of ternary operator (`?: `). +8. No space is added between the preceded or post-decrease (`++`, `--`) and variables. +9. Add a space before a comma (`, `). +10. Add a space after `//` in a single line. +11. No space is added at the end of the line. + +#### Rule 2.10 Expression statements must end with a semicolon. + +**Counterexample:** + +```javascript +let username = 'jack' +let birthday = '1997-09-01' + +console.log(`${username}'s birthday is ${birthday}`) +``` + +**Example:** + +```javascript +let username = 'jack'; +let birthday = '1997-09-01'; + +console.log(`${username}'s birthday is ${birthday}`); +``` + +#### Recommendation 2.11 Use single quotation marks to wrap strings first. + +**Example:** + +```javascript +let message = 'wolrd'; +console.log(message); +``` + +### Code instructions + +#### Rule 3.1 When declaring a variable, use the keyword `var`, `let`, or `const` to prevent the variable from being exposed to the global scope. + +**Note:** If the keyword `var`, `let`, or `const` is not used to declare a variable, the variable will be exposed to the global scope, which may overwrite the variable with the same name in the global scope. As a result, the GC cannot effectively reclaim the memory. In addition, when a variable contains sensitive information, exposuring to the global scope may result in information leakage. ** Use `const` instead of `var` for all references; Use `let` instead of `var` if you need a variable reference.** Because the scope of `const` and `let` is smaller, writing code is easier to control. Const ensures that the reference cannot be re-assigned. The pointer referenced by const is immutable, and an error will be reported during re-assignment, avoiding overwriting. + +**Counterexample:** + +```javascript +function open() { + url = 'http://127.0.0.1:8080'; //url will be exposed to the global scope + //todo something +} +open(); +console.log(url); //url can be accessed, output: http://127.0.0.1:8080 +``` + +**Example:** + +```javascript +function open() { + let url = 'http://127.0.0.1:8080'; + // todo something +} +open(); +console.log(url); //Report: Uncaught ReferenceError: url is not defined +``` + +```javascript +function open() { + const url = 'http://127.0.0.1:8080'; + //todo something +} +open(); +console.log(url); //Report: Uncaught ReferenceError: url is not defined +``` + +#### Rule 3.2 Function expressions must be used to declare functions in function blocks. + +**Note:** Although many JS engines support in-block declaration functions, they do not belong to the ECMAScript specification. The poor implementation of browsers is incompatible with each other, and some are contrary to the future ECMAScript draft. In addition, ECMAScript5 does not support block scopes. All control flows are not independent scopes. Variables or functions declared in the control flows are in the scope of their parent functions or scripts. As a result, the declaration of functions or variables in blocks may be overwritten. If you do need to define a function in a block, you should initialize it using a function expression. + +**Counterexample:** + +```javascript +function bar(name) { + if (name === "hotel") { + // 1. Define a foo function. The function scope is not the 'if' code block but the 'bar' function scope. + function foo() { + console.log("hotel foo A"); + } + } else { + // 2. Define the 'foo' function again to overwrite the 'foo' function definition under the 'if' condition branch. + function foo() { + console.log("hotel foo 2"); + } + } + foo && foo(); +} +bar("hotel"); // output is shown as"hotel foo 2" +``` + +**Example:** + +```javascript +function bar(name) { + var foo; + if (name == "hotel") { + foo = function () { + console.log("hotel foo 1"); + }; + } else { + foo = function () { + console.log("hotel foo 2"); + } + } + foo && foo(); +} +bar("hotel"); // Correct output"hotel foo 1" +``` + +#### Rule 3.3 Encapsulation of Basic Types is prohibited + +**Note:** JavaScript has five basic data types: Undefined, Null, Boolean, Number, and String. The value of the base data type is unchangeable. The basic data type object used in JavaScript is only a value. It does not contain the methods and attributes of the object encapsulated by the object. When the attributes and methods are not required, the encapsulation type of the object does not need to be used. + +**Counterexample:** + +```javascript +var isShow = new Boolean(false); +if (isShow) { + alert('hi'); //It is executed, and the following information is displayed: hi +} +``` + +**Example:** + +```javascript +var isShow = false; +if (isShow) { + alert('hi'); +} +``` + +#### Rule 3.4 The use of `with` is prohibited + +**Note:** Using 'with' makes your code semantically unclear, because objects of 'with' may conflict with local variables, changing the original meaning of the program. + +**Counterexample:** + +```javascript +var foo = { x: 5 }; +with(foo) { + var x = 3; + console.log(x); //Output: 5 +} +``` + +#### Rule 3.5 `this` can only be used in object constructors, methods, and closures. + +**Note:** In JavaScript, the "this" pointer represents the owner of the object that executes the current code. This has special semantics: + ++ Global objects (in most cases) ++ Scope of the caller (when eval is used) ++ Nodes in the DOM tree (when adding event handling functions) ++ Newly created object (using a constructor) ++ Other objects (if the function is called() or apply()) + +```javascript +var User = function(username) { + this.username = username; +}; +var user = new User('John'); +console.log(user.username); // Output: John + +var ClickCounter = { + value: 0, + click: function() { + ++this.value; + }, + getValue() { + return this.value; + } +}; +console.log(Counter.getValue()); //Output: 0 +Counter.click(); +console.log(Counter.getValue()); //Output: 1 +``` + +#### Rule 3.6 Do not use conditional comments in IE. + +**Note:** Conditional compilation can be activated using the `\@cc_on` statement or the `\@if` or `\@set` statement in IE. Although comments can be made to be compatible with browsers other than IE, they hinder the execution of automation tools because they change the JavaScript syntax tree at run time. + +**Counterexample:** + +```javascript +var f = function () { + /*@cc_on @*/ + /*@if (@_jscript_version >= 4) + alert("JavaScript version 4 or better"); + @else @*/ + alert("Conditional compilation not supported by this scripting engine."); + /*@end @*/ +}; +``` + +#### Rule 3.7 Prototypes of built-in objects cannot be modified. + +**Note:** As a set of public interfaces, built-in objects have conventional behaviors. Modifying the prototype may damage the interface semantics or cause abnormalities during debugging. + +**Counterexample:** + +```javascript +Array.prototype.indexOf = function () { return -1 } +var arr = [1, 1, 1, 1, 1, 2, 1, 1, 1]; +console.log(aar.indexOf(2)); // Output:-1 +``` + +#### Rule 3.8 Do not directly use the built-in attribute of `Object.prototype`. + +**Note:** ECMAScript 5.1 adds `Object.create`, which creates a new object and uses an existing object to provide the proto of the newly created object. `Object.create(null)` is a common pattern for creating objects used as maps. Unexpected behavior or vulnerability may occur when the object has an attribute with the same name as `Object.prototype`. For example, it is not safe for a web server to parse JSON input from a client and use `hasOwnProperty` to directly invoke the generated object, because a malicious client may send a similar JSON value `' {"hasOwnProperty": 1} '` and cause the server to crash. + +**Counterexample:** + +```javascript +var hasBarProperty = foo.hasOwnProperty("bar"); +var isPrototypeOfBar = foo.isPrototypeOf(bar); +var barIsEnumerable = foo.propertyIsEnumerable("bar"); +``` + +**Example:** + +```javascript +var hasBarProperty = Object.prototype.hasOwnProperty.call(foo, "bar"); +var isPrototypeOfBar = Object.prototype.isPrototypeOf.call(foo, bar); +var barIsEnumerable = {}.propertyIsEnumerable.call(foo, "bar"); +``` + +#### Rule 3.9 Use the `Object.getPrototypeOf` function instead of `_proto_` + +**Note:** ES5 introduces the `Object.getPrototypeOf` function as the standard API for obtaining object prototypes, but a large number of JavaScript engines have long used a special `proto' attribute to achieve the same purpose. However, `proto` is essentially an internal attribute rather than a formal external API. Currently, this attribute must be deployed in browsers, but not in other running environments. Therefore, this attribute is not fully compatible. For example, objects with null prototypes are handled differently in different environments. + +```javascript +var empty = Object.create(null); +"_proto_" in empty; //Some environments false is returned, some environments true is returned. +``` + +Therefore, use `Object.getPrototypeOf()` instead of using the proto attribute in terms of semantics and compatibility. The `Object.getPrototypeOf' function is valid in any environment and is a more standard and portable method for extracting object prototypes. + +#### Rule 3.10 Do not create functions with function constructors. + +**Note:** There are three methods for defining a function: function declaration, function constructor, and function expression. Regardless of in which method you define a function, they are instances of the Function object and inherit all default or custom methods and properties of the Function object. The method of creating a function using a function constructor is similar to the character string `eval()`. Any character string can be used as the function body, which may cause security vulnerabilities. + +**Counterexample:** + +```javascript +var func = new Function('a', 'b', 'return a + b'); +var func2 = new Function('alert("Hello")'); +``` + +**Example:** + +```javascript +function func(a, b) { + return a + b; +} + +var func2 = function(a, b) { + return a + b; +} +``` + +#### Suggestion 3.11 When using the prototype `prototype' to implement inheritance, try to use the existing stable library methods instead of self-implementing them. + +**Note:** The multi-level prototype structure refers to the inheritance relationship in JavaScript. When you define a class D and use class B as its prototype, you get a multilevel prototype structure. These prototype structures can get complicated. Using existing stable library methods such as `goog.inherits()` of the Closure library or other similar functions can avoid unnecessary coding errors. + +#### Suggestion 3.12 When defining a class, you should define the method under the prototype and the attributes within the constructor. + +**Note:** There are multiple methods in JavaScript to add methods or members to constructors. However, using a prototype to define methods can reduce memory usage and improve running efficiency. + +**Counterexample:** + +```javascript +function Animals() { + this.walk = function() {}; // This causes a walk method to be created on each instance. +} +``` + +**Example:** + +```javascript +function Animals() {} + +Animals.prototype.walk = function() {}; +``` + +#### Suggestion 3.13 When using closures, avoid cyclic reference, which may cause memory leakage. + +**Note:** +JavaScript is a garbage collection language in which the memory of an object is allocated to the object based on its creation and is reclaimed by the browser when there is no reference to the object. JavaScript's garbage collection mechanism is fine on its own, but browsers are somewhat different in the way they allocate and recover memory for DOM objects. Both IE and Firefox use reference counting to process memory for DOM objects. In the reference counting system, each referenced object keeps a count to see how many objects are referencing it. If the count is zero, the object is destroyed and the memory it occupies is returned to the heap. While this solution is generally effective, there are some blind spots in circular references. When two objects refer to each other, they form a circular reference, where the reference counting values of the objects are assigned to 1. In pure garbage collection systems, circular references are not a problem: if one of the two objects involved is referenced by any other object, both objects will be garbage collected. In a reference counting system, neither of these objects can be destroyed because reference counting can never be 0. In a hybrid system that uses both garbage collection and reference counting, a leak occurs because the system does not correctly recognize circular references. In this case, neither the DOM object nor the JavaScript object can be destroyed. Circular references are easy to create. Circular references are particularly prominent in closures, one of JavaScript's most convenient programming structures. Closures hold references to their external scopes (including local variables, parameters, and methods). When the closure itself is held by scope members (usually DOM objects), circular references are formed, which further leads to memory leaks. + +**Counterexample:** + +```javascript +function setClickListener(element, a, b) { + element.onclick = function() { + // Use a and b here + }; +}; +``` + +In the above code, the closure retains references to elements, a, and b even if element is not used. Because the element also retains the reference to the closure, a circular reference is generated and cannot be recycled by the GC. + +**Example:** + +```javascript +function setClickListener(element, a, b) { + element.onclick = createHandler(a, b); +} + +function createHandler(a, b) { + // By adding another function to avoid the closure itself, you can organize memory leaks. + return function() { + // Use a and b here + } +} +``` + +#### Suggestion 3.14 Watch out for JavaScript floating point numbers. + +**Note:** JavaScript has a single numeric type: `IEEE 754` double-precision floating point number. Having a single numeric type is one of the best features of JavaScript. Multiple number types can be a source of complexity, confusion and error. However, one of the biggest drawbacks of the binary floating-point type is that it does not accurately represent the fractional part, causing unexpected precision problems, as shown in the following examples. + +Sample Code1: + +```javascript +console.log(0.1 + 0.2 === 0.3); // Output: false. Therefore, do not use == or === to compare floating-point numbers. +``` + +Sample Code2: + +```javascript +var sum1 = (0.1 + 0.2) + 0.3; +console.log(sum1); // Output: 0.6000000000000001 + +var sum2 = 0.1 + (0.2 + 0.3); +console.log(sum2); // Output: 0.6. Therefore, for binary floating-point numbers, (a + b) + c cannot be guaranteed to produce the same result as a + (b + c). +``` + +The effective solutions are as follows: + +1. Use integers as much as possible because integers do not need to be rounded. + +2. The native JavaScript method `Number.prototype.toFixed(digits)`,`digist` is used to indicate the number of digits after the decimal point. The exponential method is not used. If necessary, the number is rounded off. This method is used to reduce the precision of the calculation result before determining the floating-point number calculation result. The sample code is as follows: + + ```javascript + parseFloat(0.1 + 0.2).toFixed(1); //0.3 + ``` + +3. A very small constant `Number.EPSILON =.220446049250313e-16 ` is added to ES6, which is about 0.00000000000000022204. `Number.EPSILON` is used to determine the calculation error of floating-point numbers. If the calculation error of floating-point numbers is less than or equal to the value of `Number.EPSILON`, such an error is acceptable. The sample code is as follows: + + ```javascript + function isNumberEquals(one, other) { + return Math.abs(one - other) < Number.EPSILON; + } + var one = 0.1 + 0.2; + var other = 0.3; + console.log(isNumberEquals(one, other)); // Output: true + ``` + +4. Use some class library methods that support precise calculation, such as `math.js`. + + ```html + + + + + + + + + + + + ``` + +#### Suggestion 3.15 Do not use the array constructor with variable arguments. + +**Note:** The method of constructor `new Array` is not recommended to construct a new array. If the constructor has only one parameter, exceptions may occur. In addition, the global definition of the array may be modified. Therefore, it is recommended to use the array literal notation, that is, `[]` notation, to create an array. + +**Counterexample:** + +```javascript +const arr1 = new Array(x1, x2, x3); +const arr2 = new Array(x1, x2); +const arr3 = new Array(x1); +const arr4 = new Array(); +``` + +Except for the third case, all other functions can work properly. If `x1` is an integer, `arr3` is an array whose length is `x1` and values are `undefined`. If `x1` is any other number, an exception is thrown, and if it is anything else, it is an array of cells. + +**Example:** + +```javascript +const arr1 = [x1, x2, x3]; +const arr2 = [x1, x2]; +const arr3 = [x1]; +const arr4 = []; +``` + +This way, you'll save a lot of trouble. + +Similarly, use `{}` instead of `new Object()` to create objects. + +#### Rule 3.16 String templates are preferred over string links when constructing strings. + +**Note:** The template character strings are more concise and readable. + +**Counterexample:** + +```javascript +function sayHi(name) { + console.log('hi, ' + name); +} +``` + +**Example:** + +```javascript +function sayHi(name) { + console.log(`hi, ${name}`); +} +``` + +#### Rule 3.17 Use `for...of` for array traversal and `for...in` for object traversal. + +**Counterexample:** + +```javascript +let numbers = [1, 2, 3, 4]; +let sum = 0; +for (let number in numbers) { + sum += number; +} +// sum === 00123; +``` + +**Example:** + +```javascript +let numbers = [1, 2, 3, 4]; +let sum = 0; +for (let number of numbers) { + sum += number; +} +// sum === 10 +``` + diff --git a/website/docs/extras/en/contribute/OpenHarmony-Log-guide.md b/website/docs/extras/en/contribute/OpenHarmony-Log-guide.md new file mode 100644 index 0000000000000000000000000000000000000000..231e26a83a8129b44cb2d777112dd20fa493f668 --- /dev/null +++ b/website/docs/extras/en/contribute/OpenHarmony-Log-guide.md @@ -0,0 +1,251 @@ +--- +title: "OpenHarmony-Log-guide" +prepermalink: /extras/68cd659d6d5788f37b46237d8614c144/ +permalink: /extras/68cd659d6d5788f37b46237d8614c144/ +relpath: "OpenHarmony-3.1-Release/en/contribute/OpenHarmony-Log-guide.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [OpenHarmony-Log-guide] +--- +# Logging Guide + +## Introduction +In OpenHarmony, HiLog is used to export logs to the log services. Logs record user operations and system running statuses. Logs are an important part of a system, and quality logs are a must for system development. + +Logging has a significant negative impact on system performance. Therefore, it is necessary to make logging reasonably simple. Do not log unnecessary information to overwhelm developers. + +## Log Level + +- **[Rule] Use the appropriate log level based on actual conditions.** + +**Note:** The log level must match the log content. The following log levels are available: + +FATAL: indicates that a program or functionality is about to crash and the fault cannot be rectified. + +ERROR: indicates a program or functional error that affects the normal running or use of the functionality and can be fixed at a high cost, for example, by resetting data. + +WARN: indicates a severe, unexpected fault that has little impact on users and can be rectified by the programs themselves or through simple operations. + +INFO: used to record key service process nodes and exceptions (for example, no network signal or login failure) that occur during service running. These logs should be recorded by the dominant module in the service to avoid repeated logging conducted by multiple invoked modules or low-level functions. + +DEBUG: used to record more detailed process information than INFO logs to help developers analyze service processes and locate faults. DEBUG logs are not recorded in official versions by default. They are available in debug versions or in official versions with the debug function enabled. + +## Log Content + +- **[Rule] Describe the log content in fluent English (grammatically correct and clear description with no typos).** + +**Note:** The log content must be clear and concise so that developers can know what happened by reading the log, instead of analyzing the related code. A syntax- and semantics-compliant log also helps the log analysis tool automatically parse the log. Example: + +A log recording "1234" is meaningless to anyone except the coder themselves. + +A log recording "Error happened" does not indicate where the error occurred or the cause of the error. Such a log is not helpful for fault locating. + +- **[Rule] Do not log privacy information.** + +**Note:** Privacy information, such as hardware serial numbers, personal accounts, passwords, and identities, should not be logged. The scope of the privacy information complies with national and regional policies. + +- **[Rule] Do not log service-irrelevant information.** + +**Note:** Do not log any information irrelevant to the service code, such as the issue number, requirement number, department name, developer name, employee ID, name abbreviation, weather, and mood. + +- **[Rule] Do not log repeated information.** + +**Note:** Do not print logs with the same content in different places. It would hinder developers in locating the code during fault locating. + +- **[Rule] Do not call service interface functions in logs.** + +**Note:** Logging should not affect the normal service process. Generally, the impact of log code on the service logic is ignored during fault locating or code walk-through. + +- **[Rule] Do not commit logs used during development and debugging to the code repository.** + +**Note:** To speed up fault locating, you may print a line of logs for each step in the code or print various variables (which may include privacy information). +You must delete these code lines before committing the final code to the code repository. + +- **[Recommendation] Display the log content in one line.** + +**Note:** A line usually contains about 100 characters. Try your best not to include more than 160 characters in a log. + +## When to Print + +- **[Rule] Do not print logs in the normal process of high-frequency code.** + +**Note:** Do not print logs for frequently called interface functions in big data processing, high-frequency software and hardware interrupt processing, protocol data stream processing, multimedia audio and video stream processing, display screen refresh processing, and other scenarios where the code keeps running as long as the system does not sleep. However, you can print logs in their error branches. Logs added during development and debugging must be cleared or disabled when code is committed to the code repository. + +- **[Rule] Restrict the logging frequency for logs that may be recorded repeatedly.** + +**Note:** If it is proved that some log records may occur multiple times, you are advised to restrict the logging frequency to avoid a large number of log copies with identical (or very similar) information. + +- **[Rule] Print logs for events that are unlikely to happen.** + +**Note:** According to Murphy's Law, anything that can go wrong will go wrong. Always print logs for points that are unlikely to happen. + +- **[Recommendation] Generate log strings during logging.** + +**Note:** Log strings should be generated as late as possible, best at the time when the log is printed. In this way, the strings will not be generated when the log function is disabled, therefore minimizing the system overhead. + +## Log Format + + +- **[Rule] Log events in the who-does-what format.** + +- **[Rule] Log status changes in the format of state\_name:s1->s2, reason:msg.** + +- **[Rule] Log parameter values in the format of name1=value1, name2=value2...**. + +- **[Rule] Log successful code execution using the statement "xxx successful".** + +- **[Rule] Log code execution failures using the statement "xxx failed. Please xxx." Include possible solutions in the logs.** + + Example: "Connection to the server failed. Please check network configuration." + +## Guide for Printing Common Logs + +### Process Logs + + +- **[Recommendation] Log key service process nodes, including the service start point, key condition branch, error processing point, and service end point.** + +### Database Logs + +- **[Recommendation] Log database operations and related information.** + +**Note:** Common database operations include +Create, Read, Update, Delete (CRUD). The initiator, type, and result (successful or failed) of each operation should be logged. However, the detailed content of the operation and operation result should not be logged to prevent user privacy leakage. The number of returned results can be logged. + +- **[Recommendation] Record the operation duration in database operation logs for performance-sensitive services.** + +**Note:** For performance-sensitive services, database operations (including reading and writing data) are key performance nodes, and the operation duration should be logged and used as a reference for performance profiling. + +- **[Recommendation] Log database job information.** + +**Note:** Log the job name, execution content, start time, end time, and execution result. + +### File Logs +- **[Recommendation] Log operations on files and related information.** + +**Note:** Common file operations include creating, opening, reading, writing, closing, and deleting files as well as obtaining file attributes. The initiator, type, and result of each operation should be logged. However, the file content should not be logged to prevent user privacy leakage or system vulnerability exposure. The system file name and file handle value can be logged, but the user file name should not. + +- **[Recommendation] Print only one log for batch file operations.** + +**Note:** For example, if files are deleted in batches, do not record a log for each file deletion. Instead, log the number of deleted files. If the directory where a deleted file is located is created by the system, log the directory name as well. + +### Key Object/Object Pool Logs + +**Note:** A key object/object pool may be a class or struct, a queue or stack data structure, or a simple variable of the primitive data type. It plays a key role in the system and is used for system scheduling control, status recording, and information transfer. + +- **[Recommendation] Log the operations, results, and status changes of key objects.** + +**Note:** Object operations include creating, loading, unloading, and releasing objects. For key object operations, log the operation subject, type, and result. For status operations, log the values before and after the status change. + +### Thread Logs + +- **[Recommendation] Log thread operations and related information.** + +**Note:** Thread operations include creating, starting, pausing, and terminating threads. Record the operation type, operation result, thread number, and thread name in the log. (A thread name must be set for important threads.) + +- **[Recommendation] Logs must be recorded when a thread enters an infinite loop or deadlock.** + +**Note:** A mechanism must be provided for detecting deadlocks or infinite loops that occur in threads with logic such as lock waiting, asynchronous processing, and cyclic processing, and logs must be recorded when an error occurs. + +- **[Recommendation] Log message processing information for message processing threads.** + +**Note:** Log the information such as the message name, processing result, and processing duration. For high-frequency messages, you can record logs only when an error occurs during message processing. + +### Concurrency Control Logs + +**Note:** Concurrency control objects may be locks, critical sections, and semaphores. + +- **[Recommendation] Log operations on concurrency control objects and related information.** + +**Note:** Concurrency control operations include creating, occupying, releasing, and waiting. Log information such as the operation type, operation object name, operation result, and operation location. + +### Shared Memory Logs + +**Note:** Shared memory is a common inter-process communication method in software systems. It is used to share or transfer data between modules. The data stored in the shared memory may be configuration data, database data, and the like. + +- **[Recommendation] Log operations on the shared memory and related information.** + +**Note:** The operations on the shared memory include creating, deleting, setting, querying, and destroying data. Log the operator, operation type, and operation result. + +### Interface Interaction Logs + + +There are internal and external system interfaces. Internal interfaces refer to the interfaces between subsystems and modules within the system. These interfaces include inter-module message sending interfaces, IPC interfaces, and RPC interfaces. + +- **[Recommendation] Record interface interaction information.** + +**Note:** Interface interaction information includes the interface caller, message content, processing result, and return value. User privacy information must be excluded from the message content and return value. + +### State Machine Logs + +- **[Recommendation] Log state machine operations and state change information.** + +**Note:** The operations on a state machine include creating, starting, ending, and destroying the state machine as well as changing its state. The state machine is usually driven by external conditions (such as messages and resources). State change information must be logged, such as the state names before and after the state change and the external conditions that cause the change. + +### Other OS Resources +The other OS resources refer to resources that are not mentioned in the preceding sections, such as sockets and timers. OS resources such as files and threads are mentioned before and are not covered in this part. + +- **[Recommendation] Log the process and result of socket connection establishment, connection maintenance, disconnection, and causes.** + +- **[Recommendation] Log the timer startup, reset, destruction, and timeout processes.** + +- **[Recommendation] Comply with the preceding logging principles when using other similar OS resources.** + +## HiLog API Usage Specifications + + +- **[Rule] Each service domain must have an independent domain ID.** + +**Note:** Before using the HiLog API to print logs, every service domain must apply for a domain ID from the DFX. The domain ID is used to measure and control the quality of a single service log. You can use the domain ID to filter out your own service logs for analysis. Do not use domain IDs of others. For test code, use the domain ID 0xD000F00. + +Range of the domain IDs: **0xD000001\-0xD00FFFF** + +- **[Recommendation] Use the domain ID allocated to your domain based on a certain layer and module granularity.** + +**Note:** A domain ID is a 32-bit integer expressed in 16-bit format. The domain ID is the format of 0xD0xxxyy, where D0 is the domain ID, the most significant 12 bits of ***xxx*** are the value allocated by the DFX, and the least significant 8 bits of ***yy*** are for internal use in the service domain. Domain IDs allocated among your service domain must be able to locate your internal organizations or modules and reflect their log quality. The DFX conducts logging control based on the domain IDs to prevent the logging of a single module from affecting other modules in the same service domain. For example, the BT service domain is further divided as follows by module: + + + APP | BT-App1 BT-App2 + --------------------------------------- + Framework | BT-Service1 BT-Service2 + --------------------------------------- + HAL | BT-HAL + --------------------------------------- + Kernel | BT-Driver1 BT-Driver2 + +Therefore, domain IDs allocated to BT can be further divided as follows: +| Domain Name| Domain ID | +|----|----| +| BT | 0xD000100 | +| BT-App1 | 0xD000101 | +| BT-App2 | 0xD000102 | +| BT-Service1 | 0xD000103 | +| BT-Service2 | 0xD000104 | +| BT-HAL | 0xD000105 | +| BT-Driver1 | 0xD000106 | +| BT-Driver2 | 0xD000107 | + +- **[Rule] The log service controls the log traffic of each service. Changing the default traffic threshold must be approved by the DFX.** + +**Note:** The default log traffic threshold of each domain is **2048 KB/s** for an official version and **10240 KB/s** for a trial version. Any change to the default threshold must be approved by the DFX. + +- **[Rule] Correctly set the log formatting privacy tags {public} and {private}**. + +**Note:** Privacy parameter IDs {public} and {private} indicate whether the log content of each parameter contains sensitive privacy information. The HiLog API automatically outputs the content of the {public} parameter in plaintext and filters the content of the {private} parameter using <private>. Set privacy parameter IDs only after you analyze the log content. Example: + +Source code: + + + HiLog.info(LABEL, "Device Name:%{public}s, IP:%{private}s.", DeviceName, ip); + + +Log output: + + + 11-11 09:19:00.932 1513 1513 E 00500/Settings: MyPad001, IP: diff --git a/website/docs/extras/en/contribute/OpenHarmony-c-coding-style-guide.md b/website/docs/extras/en/contribute/OpenHarmony-c-coding-style-guide.md new file mode 100644 index 0000000000000000000000000000000000000000..db4b048edfc0451515031b954e71692a405b64e7 --- /dev/null +++ b/website/docs/extras/en/contribute/OpenHarmony-c-coding-style-guide.md @@ -0,0 +1,2113 @@ +--- +title: "OpenHarmony-c-coding-style-guide" +prepermalink: /extras/b722072f00469d305168945eed1d2f64/ +permalink: /extras/b722072f00469d305168945eed1d2f64/ +relpath: "OpenHarmony-3.1-Release/en/contribute/OpenHarmony-c-coding-style-guide.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [OpenHarmony-c-coding-style-guide] +--- +# C Coding Style Guide + +## Purpose + +Rules are not perfect. They might disable useful features in specific situations and therefore affect code implementation. However, the purpose of developing rules is to get more benefits for most programmers. If a rule cannot be followed in your team operation, we can improve the rule together. Before referring to this coding style guide, you are expected to have the following basic capabilities of the C programming language: + +1. Understand the ISO standard of C. +2. Be familiar with the basic features of C. +3. Understand the standard library of C. + +## General Principles + +Code must meet the requirements for **readability**, **maintainability**, **security**, **reliability**, **testability**, **efficiency**, and **portability** while ensuring functionality correctness. + +## Conventions + +**Rule**: Conventions that must be followed during programming. +**Rec**: Conventions that must be considered during programming. + +It is necessary to understand the reason for these conventions and try to comply with them, no matter if they are rules or recommendations. + +## Exceptions + +The only acceptable exceptions are those that do not violate the general principles and provide appropriate reasons for their existence. +Try to avoid exceptions because they affect the code consistency. Exceptions to 'Rules' should be very rare. + +The style consistency principle is preferred in the following case: +**When you modify open-source or third-party code, comply with their respective code specifications.** + +# 1 Naming + +Names include file, function, variable, type, and macro names. + +Naming is considered the most difficult and important thing in software development. +The name of an identifier must be clear, well defined, easy to understand, and accounting for reading habits. + +The unified naming style is the most direct expression of the consistency principle. + +## General Conventions + +**CamelCase** +CamelCase is the practice of writing compound words or phrases so that each word or abbreviation in the phrase begins with a capital letter, and with no intervening spaces or punctuation. +There are two conventions: **UpperCamelCase and lowerCamelCase**. + +**Unix\_like** +Unix\_like is also known as the snake style. In the Unix\_like style, words contain only lowercase letters and are separated by underscores (\_). +Example: 'test_result' + +### Rule 1.1 Name identifiers in the CamelCase style. + +| Type| Naming Style +|----------|---------- +| Function, struct, enum, union| UpperCamelCase +| Variable, function parameter, macro parameter, struct body, union member| lowerCamelCase +| Macro, constant, enumerated value, goto tag| All capitalized, separated by underscores (\_) + +Note: +**Constant** in the above table refers to the variable that is of the basic data type, enum type, and string type and modified by **const** under the global scope, excluding arrays, structs, and unions. +**Variable** indicates the variables excluding those defined in **Constant**. These variables use the lowerCamelCase style. +Unix\_like can be used for Linux or Unix friendly code. +For code that is using the Unix\_like style, you can continue using this style. +The same naming style must be used for the same function, struct, or union. + +### Rec 1.1 Use more accurate names for identifiers with a large scope. + +Different from C++, C does not have namespace or class.Therefore, the names of identifiers in the global scope must not conflict with each other. +Names of global functions, global variables, macros, types, and enums must be accurately described and unique in the global scope. + +Example: + +```c +int GetCount(void); // Bad: inaccurate description +int GetActiveConnectCount(void); // Good +``` + +For purposes of accurate naming, a module prefix can be added if necessary. +The module prefix and the naming body can be connected by following the CamelCase style. +Example: + +```c +int PrefixFuncName(void); // OK: CamelCase, a prefix in the content, but not in the format + +enum XxxMyEnum { // OK + ... +}; +``` + +## File Naming + +### Rec 1.2 Use lowercase file names. + +Only lowercase letters, numbers, and underscores (\_) are allowed in file names. +File names should be as short, accurate, and unambiguous as possible. +The reason for using lowercase file names is that different systems process file names in different ways. (For example, file names in MS-DOS and Windows are not case sensitive, but those in Unix/Linux and macOS are case sensitive by default). + +Good example: +`dhcp_user_log.c` + +Bad examples: +`dhcp_user-log.c`: It is not recommended that you separate words with the hyphen (-). +`dhcpuserlog.c`: The words are not separated, causing poor readability. + +## Function Naming + +Functions are named in the UpperCamelCase style. + +### Rec 1.3 Name functions to comply with reading habits. + +The "verb + object" structure can be used for action related function names. Example: + +```c +AddTableEntry() // OK +DeleteUser() // OK +GetUserInfo() // OK +``` + +An adjective or a prefix "is" can be used in a function returning a Boolean value. Example: + +```c +DataReady() // OK +IsRunning() // OK +JobDone() // OK +``` + +Data or Getter function: + +```c +TotalCount() // OK +GetTotalCount() // OK +``` + +## Variable Naming + +Variables are named in the lowerCamelCase style. This includes global variables, local variables, parameters in the function declaration or definition as well as parameters in function-like macro. + +### Rule 1.2 Add the 'g_' prefix to global variables, but not to static variables in a function. + +Global variables should be used as little as possible, and special attention should be paid to their use. This prefix highlights global variables so that developers can be more careful when handling them. +Global static variables and global variables are named in the same way. Static variables in functions and common local variables are named in the same way. + +```c +int g_activeConnectCount; + +void Func(void) +{ + static int pktCount = 0; + ... +} +``` + +Notes: Constants are also global variables in essence. However, if constants are named using uppercase letters separated by underscores (\_), the current rule does not apply. + +### Rec 1.4 Keep local variables short and to the point. + +The name of a local variable should be short on the premise that meanings can be expressed through context. + +Example: + +```c +int Func(...) +{ + enum PowerBoardStatus powerBoardStatusOfSlot; // Not good: Long redundant local variable + powerBoardStatusOfSlot = GetPowerBoardStatus(slot); + if (powerBoardStatusOfSlot == POWER_OFF) { + ... + } + ... +} +``` + +Better writing style: + +```c +int Func(...) +{ + enum PowerBoardStatus status; // Good: The status can be clearly expressed in context. + status = GetPowerBoardStatus(slot); + if (status == POWER_OFF) { + ... + } + ... +} +``` + +Similarly, "tmp" can be used to address any type of temporary variable. +A short variable name should be used with caution, but sometimes a single-character variable is allowed, for example, a counter variable in a loop statement. + +```c +int i; +... +for (i = 0; i < COUNTER_RANGE; i++) { + ... +} +``` + +Or, variables in simple math functions: + +```c +int Mul(int a, int b) +{ + return a * b; +} +``` + +## Type Naming + +Types are named in the UpperCamelCase style. +The type can be a struct, a union, or an enum. + +Example: + +```c +struct MsgHead { + enum MsgType type; + int msgLen; + char *msgBuf; +}; + +union Packet { + struct SendPacket send; + struct RecvPacket recv; +}; + +enum BaseColor { + RED, // Note: The enum is in the UpperCamelCase style whereas the enumerated values adopt the macro naming style. + GREEN, + BLUE +}; + +typedef int (*NodeCmpFunc)(struct Node *a, struct Node *b); +``` + +When you use `typedef` to set an alias for a struct, a union, or an enum, try to use the anonymous type. +If you need self-nesting pointers, you can add a 'tag' prefix or an underscore suffix. + +```c +typedef struct { // Good: The anonymous struct is used because self-nesting is not required. + int a; + int b; +} MyType; // The struct alias uses the UpperCamelCase style. + +​```c +typedef struct tagNode { // Good: Add the 'tag' prefix or use 'Node_'. + struct tagNode *prev; + struct tagNode *next; +} Node; // UpperCamelCase. +``` + +## Macro, Constant, and Enum Naming + +Use uppercase letters separated by underscores (\_) for macro names and enumerated values. +You are advised to use uppercase letters separated with underscores (\_) for constant names. Global const variables can be named with the same style of global variables. +The constants here are defined as global const variables of the basic data type, enum type, or string type. + +Use uppercase letters separated by underscores (\_) for function-like macros. +Exceptions: +1. Functions that use macros to implement generic functions, for example, macros that implement functions such as list and map, can be named in the same way as functions, using the UpperCamelCase style. +2. A function-like macro that is used to replace a function in the earlier version can be named in the same way as functions, using the UpperCamelCase style. +3. Macros for printing logs can be named in the same way as functions, using the UpperCamelCase style. +Note: Function-like macros named in the UpperCamelCase style must be marked as macros in the API description. + +Macro example: + +```c +#define PI 3.14 +#define MAX(a, b) (((a) < (b)) ? (b) : (a)) +``` + +```c +#ifdef SOME_DEFINE +void Bar(int); +#define Foo(a) Bar(a) // The function-like macro is named in the same way as a function. +#else +void Foo(int); +#endif +``` + +Constant example: + +```c +const int VERSION = 200; // OK. + +const enum Color DEFAULT_COLOR = BLUE; // OK + +const char PATH_SEP = '/'; // OK + +const char * const GREETINGS = "Hello, World!"; // OK +``` + +Non-constant example: + +```c +// A struct that does not meet the definition of constants +const struct MyType g_myData = { ... }; // OK: Name it in lowerCamelCase style. + +// An array that does not meet the definition of constants +const int g_xxxBaseValue[4] = { 1, 2, 4, 8 }; // OK: Name it in lowerCamelCase style. + +int Foo(...) +{ + // A local const variable that does not meet the definition of constants + const int bufSize = 100; // OK: Name it in lowerCamelCase style. + ... +} +``` + +Enum example: + +```c +// Note: The enum type name is in the UpperCamelCase style, whereas the enumerated value is in uppercase letters separated by underscores (\_). +enum BaseColor { + RED, + GREEN, + BLUE +}; +``` + +### Rec 1.5 Avoid temporary variables in function-like macros from polluting external scopes. + +**If possible, use a function instead of a function-like macro. Define a function-like macro only when necessary.** + +When defining local variables for a function-like macro, use double underscores at the end to avoid name conflicts with local variables in external functions. Example: +```c +#define SWAP_INT(a, b) do { \ + int tmp__ = a; \ + a = b; \ + b = tmp__; \ +} while (0) +``` + +# 2 Formatting + +## Line Length + +### Rule 2.1 Include 120 characters or less in each line. + +A longer line makes it more difficult for reading. +To meet the line length requirement, you can shorten the names of functions and variables and reduce the number of nesting layers. This improves code readability. +Unless a long line is necessary to maintain readability and present complete information, steer your document clear of long lines. +Even on a high-resolution monitor, a long line increases the difficulty of reading. Strive for clearness and conciseness. + +Exceptions: + +- For code lines or comments, the use of the line feed causes content truncation and increases the search difficulty (grep). +- The #include and #error statements are allowed to exceed the line length requirement. However, you should try to avoid this. + +Example: + +```c +#ifndef XXX_YYY_ZZZ +#error Header aaaa/bbbb/cccc/abc.h must only be included after xxxx/yyyy/zzzz/xyz.h +#endif +``` + +## Indentation + +### Rule 2.2 Use spaces to indent and indent four spaces at a time. + +Only spaces can be used for indentation. Four spaces are indented each time. Do not use the Tab character to indent. +Currently, almost all integrated development environments (IDEs) and code editors support automatic conversion of a Tab input to fours spaces. Configure your code editor to support indentation with spaces. + +## Braces + +### Rule 2.3 Use the K\&R indentation style. + +**K\&R style** +While wrapping a line, the left brace of the function starts a new line and takes a single line. Other left braces are placed at the end of the line along with the statement. +The right brace takes a single line, unless it is followed by the rest of the same statement, such as `while` in the `do` statement, `else` or `else if` in the `if` statement, a comma, or a semicolon. + +Example: + +```c +struct MyType { // Good: The left brace is placed at the end of the line along with the statement, and one space is used for indentation. + ... +}; // Good: The right brace is followed by the semicolon. + +int Foo(int a) +{ // Good: The left brace of the function starts a new line, and nothing else is placed on the line. + if (...) { + ... + } else { // Good: The right brace is followed by the `else` statement. + ... + } // Good: The right brace takes a single line. +} +``` + +## Function Declaration and Definition + +### Rule 2.4 Keep the return type and function name of the function declaration or definition in the same line, and align the function parameter list appropriately if it needs to be wrapped. + +When a function is declared and defined, the return value type of the function should be in the same line as the function name. + +When the function parameter list is wrapped, it should be aligned appropriately. +The left parenthesis of a parameter list is always in the same line as the function name. The right parenthesis always follows the last parameter. + +Example: + +```c +ReturnType FunctionName(ArgType paramName1, ArgType paramName2) // Good: All in one line +{ + ... +} + +ReturnType VeryVeryVeryLongFunctionName(ArgType paramName1, // Each added parameter starts on a new line because the line length limit is exceeded. + ArgType paramName2, // Good: Aligned with the previous line + ArgType paramName3) +{ + ... +} + +ReturnType LongFunctionName(ArgType paramName1, ArgType paramName2, // Parameters are wrapped because the line length limit is exceeded. + ArgType paramName3, ArgType paramName4, ArgType paramName5) // Good: 4 spaces are used for indentation. +{ + ... +} + +ReturnType ReallyReallyReallyReallyLongFunctionName( // The line length cannot accommodate even the first parameter, and a line break is required. + ArgType paramName1, ArgType paramName2, ArgType paramName3) // Good: 4 spaces are used for indentation. +{ + ... +} +``` + +## Function Calls + +### Rule 2.5 Align the parameter list appropriately if it needs to be wrapped. + +In a function call, if the function parameter list is wrapped, it should be aligned appropriately. +The left parenthesis is always followed by a function name, and the right parenthesis always follows the last parameter. + +Example: + +```c +ReturnType result = FunctionName(paramName1, paramName2); // Good: Function parameters are placed in one line. + +ReturnType result = FunctionName(paramName1, + paramName2, // Good: Aligned with the above parameters + paramName3); + +ReturnType result = FunctionName(paramName1, paramName2, + paramName3, paramName4, paramName5); // Good: 4 spaces are used for indentation. + +ReturnType result = VeryVeryVeryLongFunctionName( // The line length cannot accommodate the first parameter, and therefore line feed is used. + paramName1, paramName2, paramName3); // 4 spaces are used for indentation. +``` + +If the parameters in a function call are associated with each other, you can group the parameters for better understanding, rather than strictly adhering to the formatting requirements. + +```c +// Good: The parameters in each line represent a group of data structures with a strong correlation.They are placed on one line for ease of understanding. +int result = DealWithStructureLikeParams(left.x, left.y, // Indicates a group of parameters. + right.x, right.y); // Indicates another group of related parameters. +``` + +## Conditional Statements + +### Rule 2.6 Use braces for conditional statements. + +Use braces to enclose conditional statements, even if there is only one statement. +Reason: + +- Logic is intuitive and easy to read. +- It is not easy to make mistakes when adding new code to the existing conditional statement. +- Function-like macros without braces are used in conditional statements, can be error prone if braces do not surround the conditional statement. + +```c +if (objectIsNotExist) { // Good: Braces are added to a single-line conditional statement. + return CreateNewObject(); +} +``` + +### Rule 2.7 Do not place `if`, `else`, and `else if` in the same line. + +In a conditional statement, branches, if any, should be written in different lines. + +Good example: + +```c +if (someConditions) { + ... +} else { // Good: The `else` statement is in a different line of `if`. + ... +} +``` + +Bad example: + +```c +if (someConditions) { ... } else { ... } // Bad: They are in the same line. +``` + +## Loops + +### Rule 2.8 Use braces for loop statements. + +Use braces to enclose the `for` and `while` statements, even if there is only one loop. + +```c +for (int i = 0; i < someRange; i++) { // Good: Braces are used. + DoSomething(); +} +``` + +```c +while (condition) { } // Good: The entire loop body is empty. And braces are used. +``` + +```c +while (condition) { + continue; // Good: The continue keyword highlights the end of the empty loop. And braces are used. +} +``` + +Bad example: + +```c +for (int i = 0; i < someRange; i++) + DoSomething(); // Bad: Braces should be added. +``` + +```c +while (condition); // Bad: The semicolon may be treated as part of the `while` statement. +``` + +## `switch` Statements + +### Rule 2.9 Indent the `case` or `default` statement in a `switch` statement block. + +Use the following indentation style for the `switch` statement: + +```c +switch (var) { + case 0: // Good: Indented + DoSomething1(); // Good: Indented + break; + case 1: { // Good: Braces are added. + DoSomething2(); + break; + } + default: + break; +} +``` + +```c +switch (var) { +case 0: // Bad: 'case' not indented + DoSomething(); + break; +default: // Bad: 'default' not indented + break; +} +``` + +## Expressions + +### Rec 2.1 Keep a consistent line break style for expressions and ensure that operators are placed at the end of the line. + +A long expression that does not meet the line length requirement must be wrapped appropriately. Generally, the expression is wrapped after a lower-priority operator or a hyphen, and the operator or hyphen is placed at the end of the line, indicating that the operation is to be continued. + +Example: + +```c +// Assume that the first line does not meet the line length requirement. +if ((currentValue > MIN) && // Good: The Boolean operator is placed at the end of the line. + (currentValue < MAX)) { + DoSomething(); + ... +} + +int result = reallyReallyLongVariableName1 + // Good: The plus sign is placed at the end of the line. + reallyReallyLongVariableName2; +``` + +After an expression is wrapped, ensure that the lines are properly aligned or indented by 4 spaces. Example: + +```c +int sum = longVaribleName1 + longVaribleName2 + longVaribleName3 + + longVaribleName4 + longVaribleName5 + longVaribleName6; // OK: indented with 4 spaces + +int sum = longVaribleName1 + longVaribleName2 + longVaribleName3 + + longVaribleName4 + longVaribleName5 + longVaribleName6; // OK: aligned +``` + +## Variable Assignment + +### Rule 2.10 Do not write multiple variable definitions or assignment statements in one line. + +It is recommended that each line contain only one variable initialization statement, which is easier to read and understand. + +```c +int maxCount = 10; +bool isCompleted = false; +``` + +Bad example: + +```c +int maxCount = 10; bool isCompleted = false; // Bad: Multiple initialization statements are placed in one line. +int x, y = 0; // Bad: Multiple variable definitions are placed in one line.Each definition occupies one line. + +int pointX; +int pointY; +... +pointX = 1; pointY = 2; // Bad: Multiple variable assignment statements are placed in one line. +``` + +Exceptions: +If multiple variable definitions have strong correlation and do not need to be initialized, you can define the variables in a line for code compactness. + +```c +int i, j; // Good: Multiple variable definitions that do not need to be initialized are written in one line. +for (i = 0; i < row; i++) { + for (j = 0; j < col; j++) { + ... + } +} +``` + +## Initialization + +Initialization is applicable to structs, unions, and arrays. + +### Rule 2.11 Use indentation or make a reasonable alignment for a new line. + +For the struct or array initialization, use 4 spaces for indentation if a line break is made. +From better readability, make a reasonable alignment. + +```c +// Good: No line break for a short line. +int arr[4] = { 1, 2, 3, 4 }; + +// Good: A line break makes better readability. +const int rank[] = { + 16, 16, 16, 16, 32, 32, 32, 32, + 64, 64, 64, 64, 32, 32, 32, 32 +}; +``` + +For complex data, the initialization should be clear and compact. +Refer to the following format: + +```c +int a[][4] = { + { 1, 2, 3, 4 }, { 2, 2, 3, 4 }, // OK + { 3, 2, 3, 4 }, { 4, 2, 3, 4 } +}; + +int b[][8] = { + { 1, 2, 3, 4, 5, 6, 7, 8 }, // OK + { 2, 2, 3, 4, 5, 6, 7, 8 } +}; +``` + +```c +int c[][8] = { + { + 1, 2, 3, 4, 5, 6, 7, 8 // OK + }, { + 2, 2, 3, 4, 5, 6, 7, 8 + } +}; +``` + +Note: + +- If the left brace is placed at the end of the line, the corresponding right brace shoud be placed into a new line. +- If the left brace is followed by the content, the corresponding right brace should also follow the content. + +### Rule 2.12 Initialize each member in a separate line during struct and union member initialization. + +The C99 standard supports the initialization of the struct and union members in their definition. This is called the designated initializer. In such a way, each member should be initialized in a separate line. + +```c +struct Date { + int year; + int month; + int day; +}; + +struct Date date = { // Good: When the designated initializer is used, each member is initialized in a separate line. + .year = 2000, + .month = 1, + .day = 1 +}; +``` + +## Pointers + +### Rec 2.2 Ensure that the asterisk (\*) in the pointer type is followed by the variable name or follows the type. There must be a space before or after the asterisk. + +When you declare or define a pointer variable or return a pointer type function, the asterisk can be placed on the left (following the type) or right (followed by the variable name). There must be only one space before or after the asterisk. + +```c +int *p1; // OK +int* p2; // OK + +int*p3; // Bad: No space +int * p4; // Bad: Space on both sides +``` + +Choose a style and stay consistent. + +If you use the asterisk to follow the type, do not declare multiple variables with pointers in a line. + +```c +int* a, b; // Bad: b may be treated as a pointer. +``` + +Do not use the asterisk followed by the variable name if this style is not suitable in all cases. +Keep style consistency first. + +```c +char * const VERSION = "V100"; // OK +int Foo(const char * restrict p); // OK +``` + +Do not use the asterisk to follow the `const` or `restrict` keywords. + +## Compilation Preprocessing + +### Rule 2.13 Place the number sign (#) at the beginning of a line for compilation preprocessing. In nested compilation preprocessing, the number sign (#) can be indented. + +The number sign (#) must be placed at the beginning of a line for compilation preprocessing, even if the code is embedded in the function body. +Try your best not to use compilation preprocessing macros. If they are needed in deed, they should be managed by dedicated personnel in a unified manner. + +## Whitespace + +### Rule 2.14 Use horizontal whitespaces to highlight keywords and important information, and avoid unnecessary whitespaces. + +Horizontal spaces should be used to highlight keywords and important information. Do not add spaces at the end of each line of code. The general rules are as follows: + +- Add spaces after keywords such as `if`, `switch`, `case`, `do`, `while`, and `for`. +- Do not add spaces after the left parenthesis or before the right parenthesis. +- Add a space before and after each binary operator (= + - \< > \* / % \| \& \^ \<= >= == !=). +- Do not add a space after any unary operator (\& \* + - ~!). +- Add a space before and after each ternary operator (? :). +- Add spaces before and after the colon of bit field description. +- Do not add spaces between ++/-- and variables. +- Do not add spaces before and after the struct member operator (. ->). +- Adding or not adding spaces inside the brace must be consistent. +- Do not add spaces before commas, semicolons, or colons (excluding the colon in the ternary operator or the bit field description). Add spaces after them. +- Do not add spaces between the parentheses of the function parameter list and the function name. +- Do not add spaces between the parenthesis of the type cast and the object being converted. +- Do not add spaces between the square bracket of the array and the array name. +- Spaces at the end of the line can be omitted. + +For spaces inside the braces, the following **recommendations** are available: + +- It is recommended that spaces be added after the left brace and before the right brace. +- For an empty constant or a constant with a single identifier or a single word, spaces are not required, for example, '{}', '{0}', '{NULL}', '{"hi"}'. +- Spaces between consecutively nested multiple parentheses are not required, for example, '{{0}}', '{{ 1, 2 }}'. '{ 0, {1}}' is a bad example, since it is not a consecutively nested scene and the spaces inside the outermost braces are inconsistent. + +In normal cases: + +```c +int i = 0; // Good: When the variable is initialized, there should be spaces before and after the =. Do not leave a space before the semicolon. +int buf[BUF_SIZE] = {0}; // Good: For array initialization, spaces in curly braces are optional. +int arr[] = { 10, 20 }; // Good: A space is added before and after the brace. +``` + +Function definition and call: + +```c +int result = Foo(arg1,arg2); + ^ // Bad: There is no space after the comma. + +int result = Foo( arg1, arg2 ); + ^ ^ // Bad: No space should be added to either side in the parentheses. +``` + +Pointer and address-of operator: + +```c +x = *p; // Good: There is no space between the operator (*) and the pointer p. +p = &x; // Good: There is no space between the operator (&) and the variable x. +x = r.y; // Good: When a member variable is accessed through the operator (.), no space is added. +x = r->y; // Good: When a member variable is accessed through the operator (->), no space is added. +``` + +Operator: + +```c +x = 0; // Good: There is a space before and after the assignment operator (=). +x = -5; // Good: There is no space between the minus sign (-) and the number. +++++x; // Good: There is no space between ++/-- and the variable. +x--; + +if (x && !y) // Good: There is a space before and after the Boolean operator, and there is no space between the operator (!) and variable. +v = w * x + y / z; // Good: There is a space before and after binary operators. +v = w * (x + z); // Good: There is no space before and after the expression in the parentheses. +``` + +Loops and conditional statements: + +```c +if (condition) { // Good: A space is added between the `if` keyword and the parenthesis, and no space is added before or after the conditional statement inside the parentheses. + ... +} else { // Good: A space is added between the `else` keyword and the curly brace. + ... +} + +while (condition) {} // Good: A space is added between the `while` keyword and the parenthesis, and no space is added before or after the conditional statement inside the parentheses. + +for (int i = 0; i < someRange; ++i) { // Good: A space is added between the `for` keyword and the parenthesis, and after the semicolons (;). + ... +} + +switch (var) { // Good: A space is added after the `switch` keyword. + case 0: // Good: No space is added between the `case` conditional statement and the colon (:). + ... + break; + ... + default: + ... + break; +} +``` + +Note: The current IDE and code editor can be set to delete spaces at the end of a line. Configure your editor correctly. + +### Rec 2.3 Arrange blank lines reasonably to keep the code compact. + +Reduce unnecessary blank lines so that more code can be displayed for easy reading. The following rules are recommended: + +- Make a reasonable arrangement of blank lines according to the degree of relevance of neighboring content. +- Do not put two or more consecutive blank lines inside a function, a type definition, a macro, or an initialization expression. +- Do not use **three** or more consecutive blank lines. +- Do not add blank lines at the start and end of a code block defined by braces. + +```c +ret = DoSomething(); + +if (ret != OK) { // Bad: Return value judgment should follow the function call. + return -1; +} +``` + +```c +int Foo(void) +{ + ... +} + + + +int Bar(void) // Bad: Use no more than two continuous blank lines. +{ + ... +} +``` + +```c +int Foo(void) +{ + + DoSomething(); // Bad: The blank lines above and below are unnecessary. + ... + +} +``` + +# 3 Comments + +Generally, clear architecture and good symbol naming are recommended to improve code readability, and comments are provided only when necessary. +Comments help readers quickly understand code. Therefore, **comments should be provided when necessary** for the sake of readers. + +The comments must be concise, clear, and unambiguous, ensuring that the information is complete and not redundant. + +**Comments are as important as code.** +When writing a comment, you need to step into the reader's shoes and use comments to express what the reader really needs. Comments are used to express the code functionality and intention, rather than repeating code. +When modifying the code, ensure that the comments are consistent. It is impolite to only modify code and not update the comments. This destroys the consistency between code and comments, and may cause confusion or even misleading. + +Comment code in fluent **English**. + +Comments must be added in the following scenarios (including but not limited to the listed scenarios): +1. Functions in the external interface header file provided by the module +2. Global variables being defined +3. Core algorithms +4. A function that contains more than 50 lines + +## Comment Style + +In C code, both `/*` `*/` and `//` can be used. +Comments can be classified into different types depending on the purpose and position, such as file header comments, function header comments, and general comments. +Comments of the same type must keep a consistent style. + +Note: The sample code used in this article sees extensive use of the '//' post-comment. This is only for better understanding, and does not mean that this comment style is better. + +## File Header Comments + +### Rule 3.1 Include the copyright license in the file header comments. + +/\* + +* Copyright (c) 2020 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. \*/ + +## Function Header Comments + +### Rule 3.2 Do not use empty function header comments with no content. + +Not all functions need function header comments. +Function header comments must be added for any information that cannot be expressed just with function prototype. + +Function header comments are placed above the function declaration or definition. +Select and use one of the following styles: +**Use '//' to start the function header.** + +```c +// Single-line function header +int Func1(void); + +// Multi-line function header +// Second line +int Func2(void); +``` + +**Use '/\*' '\*/' to start the function header.** + +```c +/* Single-line function header */ +int Func1(void); + +/* + * Single-line or multi-line function header + * Second line + */ +int Func2(void); +``` + +Use function names to describe functions, and only add function header comments if necessary. +Do not write useless or redundant function headers. Do not write empty function headers with no content. + +The following content is **optional** in the function header comment: function description, return value, performance constraint, usage, memory convention, algorithm implementation, and reentering requirement. +In the function interface declaration in the external header file of the module, the function header comment should clearly describe important and useful information. + +Example: + +```c +/* + * The number of written bytes is returned. If -1 is returned, the write operation fails. + * Note that the memory buffer is released by the caller. + */ +int WriteString(char *buf, int len); +``` + +Bad example: + +```c +/* + * Function name: WriteString + * Function: Write a character string. + * Parameter: + * Return value: + */ +int WriteString(char *buf, int len); +``` + +Problems in the preceding example are as follows: + +- The 'Parameter' and 'Return value' headings have no content. +- The function name has redundant information. +- It does not clearly state the party that should release the buffer. + +## Code Comments + +### Rule 3.3 Place code comments above or to the right of the code. + +### Rule 3.4 Add a space between the comment character and the comment content, and one space between the comment and code if the comment is placed to the right of the code. + +Comments placed above code should be indented to the same level as the code. +Select and use one of the following styles: +**Use '//' to start the comment.** + +```c +// Single-line comment +DoSomething(); + +// Multi-line comment +// Second line +DoSomething(); +``` + +**Use '/\*' '\*/' to start the comment.** + +```c +/* Single-line comment */ +DoSomething(); + +/* + * Single-/Multi-line comment + * Second line + */ +DoSomething(); +``` + +Leave at least one space between the code and the comment on the right. No more than four spaces is recommended. +You can use the extended Tab key to indent 1-4 spaces. + +Select and use one of the following styles: + +```c +int foo = 100; // Comment on the right +int bar = 200; /* Comment on the right */ +``` + +It is more appealing sometimes when the comment is placed to the right of code and the comments and code are aligned vertically. +After the alignment, ensure that the comment is 1–4 spaces separated from the closest code line on the left. +Example: + +```c +#define A_CONST 100 /* Related comments of the same type can be aligned vertically. */ +#define ANOTHER_CONST 200 /* Leave spaces after code to align comments vertically. */ +``` + +If the comment on the right exceeds the permitted line length, the comment can be placed above the code. + +### Rule 3.5 Delete unused code segments. Do not comment them out. + +Code that is commented out cannot be maintained. If you attempt to restore the code, it is very likely to introduce ignorable defects. +The correct method is to delete unnecessary code. If necessary, consider porting or rewriting the code. + +Here, commenting out refers to the removal of code from compilation without actually deleting it. This is done by using /\* \*/, //, #if 0, #ifdef NEVER\_DEFINED, and so on. + +### Rec 3.1 Provide comments if `break` or `return` is not added to the end of the `case` statement block (fall-through). + +Sometimes, the same thing is needed for multiple `case` tags. When a `case` statement ends without `break` or `return`, the statement in the next `case` tag will be executed.This is called "fall-through". +In this case, add comments for the "fall-through" to clearly express your intention, or at least explicitly specify the "fall-through". + +For example, to explicitly specify the "fall-through": + +```c +switch (var) { + case 0: + DoSomething(); + /* fall-through */ + case 1: + DoSomeOtherThing(); + ... + break; + default: + DoNothing(); + break; +} +``` + +If the `case` statement is empty, no comment is required to explain the "fall-through". + +```c +switch (var) { + case 0: + case 1: + DoSomething(); + break; + default: + DoNothing(); + break; +} +``` + +# 4 Header Files + +**For the C programming language, the design of the header file reflects most of the system design.** +The correct use of the header file makes code more readable, reduces file size, and speeds up compilation and build performance. + +The following programming specifications aim to help you properly plan header files. + +## Header File Responsibility + +A header file is an external interface of a module or file. +The interface declaration for most functions (except inline functions) is suitable in the header file. Interface implementations are not allowed in the header file. +Header responsibility should be simple. A complex header file will make dependencies complex and cause a long compilation time. + +### Rec 4.1 For each .c file, provide a corresponding .h file, which is used to declare the interfaces that need to be provided externally. + +Generally, each .c file has a corresponding .h file (not necessarily with the same name), which is used to store the function declarations, macro definitions, and type definitions that are to be exposed externally. +If a .c file does not need to open any interface externally, it should not exist. + +Exceptions: the entry point of the program (for example, the file where the main function is located), unit test code, and dynamic library code. + +Example: +Content of **foo.h**: + +```c +#ifndef FOO_H +#define FOO_H + +int Foo(void); // Good: Declare an external interface in the header file. + +#endif +``` + +Content of **foo.c**: + +```c +static void Bar(void); // Good: The declaration of the internal function is placed in the header of the .c file, declaring its static scope. + +void Foo(void) +{ + Bar(); +} + +static void Bar(void) +{ + // Do something; +} +``` + +Internally used functions declarations, macros, enums, structs, and others should not be placed in header files. + +In some products, one .c file corresponds to two .h files. One is used to store external public interfaces, and the other is used to store definitions and declarations among others for internal use to limit the number of code lines in the .c file. +This style is not recommended. It is used only because the .c file is too large. You should consider splitting the .c file first. +In addition, if private definitions and declarations are placed in independent header files, they technically cannot avoid inclusion. + +This rule, in turn, is not necessarily correct. Example: +Some simple header files, such as the command ID definition header file, do not need to have the corresponding .c file. +If a set of interface protocols has multiple instances and the interface is fixed, one .h file can have multiple .c files. + +### Rec 4.2 Use .h as the extension of the header file, rather than other unconventional extensions, for example, .inc. + +Some products use .inc as the header file name extension, which does not comply with the C programming language.A header file using .inc as the file name extension usually indicates a private header file. However, in practice, this recommendation is not followed properly. An .inc file is generally contained in multiple .c files. It is not recommended that private definitions be stored in header files. For details, see [Rec 4.1](#a4-1). + +## Header File Dependency + +The header file contains a dependency, and the dependency should be stable. +Generally, an unstable module depends on a stable module. When the unstable module changes, the build of the stable module is not affected. + +Dependency direction is as follows: Products depend on the platform, and the platform depends on the standard library. + +In addition to unstable modules depending on stable modules, each module depends on the interface. In this way, in case of any internal implementation changes to one module, users do not need to recompile another module. +It is assumed that the interface is the most stable. + +### Rule 4.1 Forbid cyclic dependency of header files. + +Cyclic dependency (also known as a circular dependency) of header files means that a.h contains b.h, b.h contains c.h, and c.h contains a.h. If any header file is modified, all code containing a.h, b.h, and c.h needs to be recompiled. +For a unidirectional dependency: a.h contains b.h, b.h contains c.h, and c.h does not contain any header file, modifying a.h does not mean a need to recompile the source code for b.h or c.h. + +The cyclic dependency of header files reflects an obviously unreasonable architecture design, which can be avoided through optimization. + +### Rule 4.2 Include the internal #include protection character (#define protection) in the header file. + +To prevent header files from being included multiple times, all header files should be protected by #define. Do not use #pragma once. + +When defining a protection character, comply with the following rules: + +- Use a unique name for the protection character in the format of subsystem\_component\_file. +- Do not place code or comments before or after the protected part, except for file header comments. + +Assume that the **timer.h** file of the timer component of the util subsystem is stored in the **timer/include/timer.h** directory. If `TIME_H` is used as the protection character, name conflicts may occur. Use the following protection characters instead: +```c +#ifndef UTIL_TIMER_TIMER_H +#define UTIL_TIMER_TIMER_H + +... + +#endif // UTIL_TIMER_TIMER_H +``` + +### Rule 4.3 Do not reference external function interfaces and variables by using declaration. + +You can use the interfaces provided by other modules or files only by using header files. +Using external function interfaces and variables with an extern declaration may cause inconsistency between declarations and definitions when external interfaces are changed. +In addition, this kind of implicit dependency may cause architecture corruption. + +Cases that do not comply with specifications: +Content of **a.c**: + +```c +extern int Foo(void); // Bad: Reference external functions by using the extern declaration. +void Bar(void) +{ + int i = Foo(); // Here, the external interface Foo is used. + ... +} +``` + +It should be changed to: +Content of **a.c**: + +```c +#include "b.h" // Good: Use the interfaces provided by another .c file by including the header file. +void Bar(void) +{ + int i = Foo(); + ... +} +``` + +Content of **b.h**: + +```c +int Foo(void); +``` + +Content of **b.c**: + +```c +int Foo(void) +{ + // Do something +} +``` + +In some scenarios, if internal functions need to be referenced with no intrusion to the code, the extern declaration mode can be used. +Example: +When performing unit testing on an internal function, you can use the extern declaration to reference the tested function. +When a function needs to be stubbed or patched, the function can be declared using extern. + +### Rule 4.4 Do not include header files in extern "C". + +If a header file is included in extern "C", extern "C" may be nested. Some compilers restrict the number of nesting layers of extern "C". Too many nesting layers may cause compilation errors. + +extern "C" usually occurs in mixed programming using both C and C++. If extern "C" includes a header file, the original intent behind the header file may be hindered, for example, when linkage specifications are changed incorrectly. + +Assume that there are two header files: **a.h** and **b.h**. +Content of **a.h**: + +```c +... +#ifdef __cplusplus +void Foo(int); +#define A(value) Foo(value) +#else +void A(int) +#endif +``` + +Content of **b.h**: + +```c +... +#ifdef __cplusplus +extern "C" { +#endif + +#include "a.h" +void B(void); + +#ifdef __cplusplus +} +#endif +``` + +When you use the C++ preprocessor to expand **b.h**, the following information is displayed: + +```c +extern "C" { + void Foo(int); + void B(void); +} +``` + +In the **a.h** file, the **Foo** function is intended to be a C++ free function following the C++ specifications. However, in the **b.h** file, because `#include "a.h"` is placed inside `extern "C"`, the linking specification of the **Foo** function is changed incorrectly. + +Exceptions: In the C++ compilation environment, if you want to reference a header file written in pure C, a non-intrusive approach is to exclude the C header file from `extern "C"`. + +# 5 Functions + +Functions help avoid repeated code and increase reusability. Functions are layered to reduce complexity and hide implementation details, making programs more modular and facilitating code reading and maintenance. + +Functions should be concise and short. +One function completes only one thing. + +## Function Design + +The essence of function design is to write clean functions and organize code effectively.The code should be simple and not conceal the designer's intention, using clean abstractions and straightforward control statements to organize the function naturally. + +### Rule 5.1 Avoid long functions and ensure that functions contain no more than 50 lines (excluding blank lines and comments). + +A function should be able to be displayed on one screen (fewer than 50 lines). It does only one thing and does it well. + +A long function usually means that it aims to implement complex functionalities or contains excess details. + +Exceptions: +Considering the code's aggregation and functionality, some functions may exceed 50 lines, but only if the code is readable and concise. +These exceptions should be minimal, such as specific algorithm processing. + +Even if a large function works well in the moment, once someone modifies it, new problems may occur. It may even cause bugs that are difficult to discover. +It is recommended that you split the code into several functions that are simpler and easier to manage so that others can easily read and modify the code. + +### Rule 5.2 Avoid nesting a code block more than four times within a function. + +The nested code block depth of a function refers to the layered depth of a code control block (created by statements such as `if`, `for`, `while`, and `switch`). +Each layer of nesting increases the difficulty in reading the code. +Further functional decomposition should be done for better understanding. + +Using `guard clauses` can effectively reduce the nesting layers of the `if` statements. Example: +Three nesting layers are used originally: + +```c +int Foo(...) +{ + if (received) { + type = GetMsgType(msg); + if (type != UNKNOWN) { + return DealMsg(...); + } + } + return -1; +} +``` + +Two nesting layers after code reconstruction using `guard clauses`: + +```c +int Foo(...) +{ + if (!received) { // Good: Use the 'guardian statement'. + return -1; + } + + type = GetMsgType(msg); + if (type == UNKNOWN) { + return -1; + } + + return DealMsg(..); +} +``` + +Exceptions: +Considering the code's aggregation and functionality, some functions may contain 4 or more nesting layers, but only if the code is readable and concise. +These exceptions should be rare. + +### Rec 5.1 Process all returned error codes. + +A function (in a standard library, a third-party library, or a user-defined function) must be able to indicate errors. This can be done by using error tags, special return data, or other means. No matter when a function provides such a mechanism, the caller should immediately check the error indication after the function returns. + +Example: + +```c +char fileHead[128]; +ReadFileHead(fileName, fileHead, sizeof(fileHead)); // Bad: The return value is not checked. + +DealWithFileHead(fileHead, sizeof(fileHead)); // The 'fileHead' is possibly invalid. +``` + +The correct format is as follows: + +```c +char fileHead[128]; +ret = ReadFileHead(fileName, fileHead, sizeof(fileHead)); +if (ret != OK) { // Good: Ensure that the 'fileHead' is written. + return ERROR; +} + +DealWithFileHead(fileHead, sizeof(fileHead)); // Process the file header. +``` + +If the return value of a function is ignored and `void` is returned frequently, check whether the return value of the function is designed properly. +Only if the caller of a function really doesn't need a return value, should you design the function to return `void`. + +## Function Parameters + +### Rec 5.2 Use the return value instead of the output parameter when designing a function. + +Using return values rather than output parameters improves readability and usually provides the same or better performance. + +Readability can be improved by naming functions such as GetXxx, FindXxx, IsXxx, OnXxx, or directly using a single noun, to directly return the corresponding object. + +Exceptions: +1. When multiple values are returned, you can design an output parameter for the function. +2. If memory allocation is involved, you can design an output parameter. The caller passes the allocated memory as an output parameter, and memory allocation is not performed in the function. + +### Rec 5.3 Define function parameters in the sequence of input, output, and input/output parameters. + +You are advised to define function parameters in the sequence of input, output, and input/output parameters. + +### Rule 5.3 Provide a release function if allocation of resources, such as memory, locks, and queues, is involved. + +Resources should be released from where they are applied for. If a function applies for resources, the module must provide resource functions. + +### Rec 5.4 Use strongly typed parameters. Do not use void\*. + +While different languages have their own views on strong typing and weak typing, it is generally believed that C/C++ is a strongly typed language. Since we use such a strongly typed language, we should keep this style. +The advantage of this strongly typed style is to prevent evasive errors by catching errors at the compilation stage. + +Strong types help the compiler find more errors.Pay attention to the usage of the `FooListAddNode` function in the following code: + +```c +struct FooNode { + struct List link; + int foo; +}; + +struct BarNode { + struct List link; + int bar; +} + +void FooListAddNode(void *node) // Bad: Here, the void * type is used to pass parameters. +{ + FooNode *foo = (FooNode *)node; + ListAppend(&g_fooList, &foo->link); +} + +void MakeTheList(...) +{ + FooNode *foo; + BarNode *bar; + ... + + FooListAddNode(bar); // Wrong: In this example, the bar parameter rather than the foo parameter is passed.No error is reported immediately and issues may occur as a result. +} + +``` + +The preceding problems may be difficult to expose and are more destructive than compiler errors. +If the parameter type of `FooListAddNode` is specified clearly, instead of with the `void *` type, the preceding problem can be detected during compilation. + +```c +void FooListAddNode(FooNode *foo) +{ + ListAppend(&g_fooList, &foo->link); +} +``` + +Exceptions: For some generic interfaces, you can use the input parameter `void *` to pass different types of pointers. + +### Rec 5.5 It is the caller's responsibility to check the validity of internal function parameters of a module. + +Validity check must be performed on parameters passed from external modules to protect programs from being damaged by invalid input data. +When calling internal functions, by default, the caller is responsible for ensuring the validity of any returned data. If the callee takes responsibility for checking data validity, checks may be performed multiple times and redundant code is generated. This is not concise. + +When the caller ensures the validity of any received data, this contractual programming makes logic simpler and code more readable. +Example: + +```c +int SomeProc(...) +{ + int data; + + bool dataOK = GetData(&data); // Get data. + if (!dataOK) { // Check the result of the previous step to ensure data validity. + return -1; + } + + DealWithData(data); // Call the data processing function. + ... +} + +void DealWithData(int data) +{ + if (data < MIN || data > MAX) { // Bad: The caller has already ensured data validity. + return; + } + + ... +} +``` + +### Rec 5.5 Declare the pointer argument of a function as 'const' if it is not used to modify the pointed object. + +The const pointer argument, which restricts the function from modifying the object through the pointer, makes code stronger and safer. + +Example: In the example of the strncmp in the 7.21.4.4 of the C99 standard, the invariant parameter is declared as const. + +```c +int strncmp(const char *s1, const char *s2, size_t n); // Good: The invariant parameter is declared as const. +``` + +Note: Whether to declare the pointer parameter as `const` depends on the function design, but not on whether there is a "modify object" action in the function entity. + +### Rec 5.6 Include no more than 5 parameters in a function. + +If a function has too many parameters, the function is easy to be affected by changes in external code, hindering maintenance. Too many function parameters will also increases the workload for testing. + +The number of parameters in a function must not exceed 5. If the number of parameters exceeds 5, consider the following: + +- Check whether the function can be split. +- Check whether any related parameters can be combined and defined as a struct. + +## Inline Functions + +An inline function is a function optimization method introduced by C99. Function inlining can eliminate the overhead of function calls; thanks to inlining, combination with the called code is implemented, so that the compiler can achieve further code optimization from a larger perspective. The inline function is similar to a function-like macro. For details, see [Rec 6.1](#a6-1). + +### Rec 5.7 Include no more than 10 lines in an inline function (excluding blank lines and comments). + +Defining a function as an inline function generally aims to improve performance, though it may fail to do so.If the function body is short, function inlining can effectively reduce the size of the target code and improve the function execution efficiency. +Vice versa, if the function body is large, inlining will cause expansion of the target code, especially when there are many call points. +It is recommended that inline functions be controlled to within **10** lines. + +Do not abuse inline functions to improve performance. Avoid premature optimization. In general, a function can be defined as an inline function only when actual test data proves that the inlining achieves higher performance. Functions such as setter and getter functions, which are short and called frequently, can be defined as inline functions. + +### Rule 5.3 Define inline functions that will be called by multiple source files in the header file. + +Inline functions are unfolded in compilation. Therefore, the inline function definition must be visible in each source file that calls this function. +As shown in the following code, **inline.h** contains the declaration of the `SomeInlineFunc` function but not the definition. The **other.c** file includes **inline.h**. As a result, inlining fails when `SomeInlineFunc` is called. + +inline.h + +```c +inline int SomeInlineFunc(void); +``` + +inline.c + +```c +inline int SomeInlineFunc(void) +{ + // Implementation code +} +``` + +other.c + +```c +#include "inline.h" +int OtherFunc(void) +{ + int ret = SomeInlineFunc(); +} +``` + +Due to this restriction, if multiple source files need to call the same inline function, the definition of the inline function must be placed in the header file. +The inline function implementation in **gnu89** differs from that in the **C99** standard. For compatibility, you can declare the function as **static inline**. + +# 6 Macros + +## Function-like Macros + +A function-like macro is a macro (as shown in the following example) similar to a function. It contains several statements to implement a specific function. + +```c +#define ASSERT(x) do { \ + if (!(x)) { \ + printk(KERN_EMERG "assertion failed %s: %d: %s\n", \ + __FILE__, __LINE__, #x); \ + BUG(); \ + } \ +} while (0) +``` + +### Rec 6.1 Use functions instead of function-like macros. + +Before defining a function-like macro, consider whether it can be replaced with a function. If yes, you are advised to use a function for replacement. +The disadvantages of the function-like macro are as follows: + +- Function-like macros haves no type check, which is not as strict as the function call check. For the example code, see [Below](#macro_lack_of_type_check__example). +- If macro parameters are not calculated during macro expansion, unexpected results may be generated. For details, see [Rule 6.1](#r6-1) and [Rule 6.3](#r6-3). +- A macro has no independent scope. When it is used together with control flow statements, unexpected results described in [Rule 6.2](#r6-2) may be generated. +- There are high skill requirements on the proper use of macros (for example, the usage of `#` and wide use of parentheses), which reduces readability. +- Extensions of some macros can only be implemented by specific compilers in specific scenarios, such as `statement expression` of `gcc`, reducing the portability. +- After the macro is expanded during precompilation, it is invisible during subsequent compilation, linking, and debugging. Besides, macros that contain multiple lines are expanded into a line. +- Macros containing a large number of statements must be expanded at each call point. If there are many call points, the code will be expanded. + +Example code of a function-like macro lacking type check: + +```c +#define MAX(a, b) (((a) < (b)) ? (b) : (a)) + +int Max(int a, int b) +{ + return (a < b) ? b : a; +} + +int TestMacro(void) +{ + unsigned int a = 1; + int b = -1; + + (void)printf("MACRO: max of a(%u) and b(%d) is %d\n", a, b, MAX(a, b)); + (void)printf("FUNC : max of a(%u) and b(%d) is %d\n", a, b, Max(a, b)); + return 0; +} +``` + +Due to the lack of type check, the comparison between `a` and `b` in `MAX` is changed to a comparison ignoring the sign status. The result is **a \< b**. The output is as follows: + +``` +MACRO: max of a(1) and b(-1) is -1 +FUNC : max of a(1) and b(-1) is 1 +``` + +The function does not have the preceding macro disadvantages. However, compared with macros, the biggest disadvantage of functions is its low execution efficiency (increasing the overhead of function calls and the difficulty of compiler optimization). +Therefore, the C99 standard introduces inline functions (gcc introduces inline functions ahead of this standard). + +The inline function is similar to the macro, as it is also expanded at the call point. The difference is that inline functions are expanded during compilation. +Inline functions have the advantages of both functions and macros: + +- Strict type checking is performed for inline functions and functions. +- Each input parameter of an inline function or function is calculated only once. +- Inline functions are unfolded in place and there is no overhead for function calls. +- Inline functions are better optimized than standard functions. + +For performance-sensitive code, consider using inline functions instead of function-like macros. +Functions and inline functions cannot completely replace function-like macros, since function-like macros are more suitable for certain scenarios. +For example, in a log scenario, using a function-like macro with variable parameters and default parameters is more convenient. + +```c +int ErrLog(const char *file, unsigned long line, const char *fmt, ...); +#define ERR_LOG(fmt, ...) ErrLog(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +``` + +### Rule 6.1 Use complete parentheses for macro parameters when defining a macro. + +The macro parameter is replaced by text only when the macro is expanded. The value is calculated when the macro is compiled. After the text replacement, the statements contained in the macro are combined with called code. +The expression after combination may result in a different result than expected, especially when the macro parameter is in an expression. + +The following is an incorrect format: + +```c +#define SUM(a, b) a + b // Bad +``` + +When the macro is used, the execution result is inconsistent with the expected result. +`100 / SUM(2, 8)` is expanded to `(100 / 2) + 8`. The expected result is `100 / (2 + 8)`. +This problem can be solved by adding parentheses to the entire expression, as shown in the following: + +```c +#define SUM(a, b) (a + b) // Bad +``` + +However, this method has the following problems: +`SUM(1 << 2, 8)` is extended to `1 << (2 + 8)` (because the priority of `<<` is lower than that of `+`), which is inconsistent with the expected result `(1 << 2) + 8`. + +To solve this problem, add parentheses to each macro parameter, as shown in the following: + +```c +#define SUM(a, b) (a) + (b) // Bad +``` + +The third scenario is as follows: `SUM(2, 8) * 10` . The result after the extension is `(2) + ((8) * 10)`, which is inconsistent with the expected result `(2 + 8) * 10`. + +In conclusion, the correct format is as follows: + +```c +#define SUM(a, b) ((a) + (b)) // Good. +``` + +Avoid abusing parentheses. As shown in the following, adding parentheses to a single identifier or a positive number is meaningless. + +```c +#define SOME_CONST 100 // Good: No parentheses needed for a single positive number. +#define ANOTHER_CONST (-1) // Good: Parentheses needed for a negative number. + +#define THE_CONST SOME_CONST // Good: No parentheses needed for a single identifier. +``` + +Notes: + +- Do not add parentheses to macro parameters when they are involved in the '#' or '##' operation. +- Do not add parentheses to macro parameters when they are used for string concatenation. +- If a macro parameter is used as a separate part in one side of an assignment expression (including +=, -=, etc.), parentheses are not required. +- If a macro parameter is used as a separate part in comma expressions, functions or macro call lists, parentheses are not required. + +Example: + +```c +#define MAKE_STR(x) #x // No parentheses for 'x' + +#define HELLO_STR(obj) "Hello, " obj // No parentheses for 'obj' + +#define ADD_3(sum, a, b, c) (sum = (a) + (b) + (c)) // 'a', 'b', and 'c' need parentheses, whereas 'sum' does not. + +#define FOO(a, b) Bar((a) + 1, b) // 'a' needs parentheses, whereas 'b' does not. +``` + +### Rule 6.2 Place implementation statements of function-like macros that contain multiple statements in a `do-while(0)`. + +Macros do not have code blocks. When a macro is expanded at the call point, the expressions and variables defined in the macro are integrated into the calling code. As a result, variable name conflict and segmentation of macro statements may occur. Use `do-while(0)` to add a boundary to the macro so that the macro has an independent scope. In addition, a single statement can be formed by combining the macro with a semicolon (;) to avoid this problem. + +Incorrect example: + +```c +// Not Good +#define FOO(x) \ + (void)printf("arg is %d\n", (x)); \ + DoSomething((x)); +``` + +When the macro is called as shown in the following example code, the `for` loop only executes the first statement of the macro, and the next statement of the macro is executed only after the loop ends. + +```c +for (i = 1; i < 10; i++) + FOO(i); +``` + +To solve the preceding problem, use braces to enclose the statements defined by `FOO`. + +```c +#define FOO(x) { \ + (void)printf("arg is %d\n", (x)); \ + DoSomething((x)); \ +} +``` + +The brackets are not associated with semicolons (;). The semicolon following the braces is another statement. +In the following code example, the "suspended else' compilation error message is displayed. + +```c +if (condition) + FOO(10); +else + FOO(20); +``` + +The correct format is to wrap the executed body using a `do-while(0)`, as shown in the following: + +```c +// Good +#define FOO(x) do { \ + (void)printf("arg is %d\n", (x)); \ + DoSomething((x)); \ +} while (0) +``` + +Exceptions: + +- Macros that contain 'break' or 'continue' statements can be treated as exceptions. Do use these macros carefully. +- An exception can be made when the macro contains an incomplete statement. For example, use a macro to encapsulate the conditional part of the `for` loop. +- An exception can be a non-multiple statement, or a single `if`, `for`, `while`, or `switch` statement. + +### Rule 6.3 Do not pass expressions with side effects to a function-like macro. + +Since macros are replaced by text, if a function-like macro uses the same macro parameter multiple times and transfers expressions with side effects as macro parameters, unexpected results may occur. +As shown in the following example, the macro `SQUARE` is normal, but the `a++` expression with side effects is passed to the macro. As a result, the value of `a` is different from the expected value after the `SQUARE` macro is executed. + +```c +#define SQUARE(a) ((a) * (a)) + +int a = 5; +int b; +b = SQUARE(a++); // Bad: 'a' is added twice. +``` + +`SQUARE(a++)` is expanded to `((a++) * (a++))` the variable `a` is added twice, and its value is `7` instead of the expected `6`. + +The correct format is as follows: + +```c +b = SQUARE(a); +a++; // Result: a = 6, which is added only once. +``` + +In addition, if the macro parameter contains a function call, the function may be called repeatedly after the macro is expanded. +If the function execution results are the same, it is a waste; if the results are different, the execution result may not meet the expected value. + +### Rec 6.2 Exercise caution when you use the statements such as `return`, `goto`, `continue`, and `break` in a function-like macro definition. + +Although process changing statements, such as `return`, `goto`, `continue`, and `break`, in a macro can simplify the code, they hide the real process, which hinders understanding and easily causes resource leakage. + +First, the macro encapsulation of the `return` statement can easily lead to excessive encapsulation and use. +As shown in the following code, the judgment of `status` is a part of the main process. After being encapsulated in macros, the purpose is not intuitive. The `RETURN_IF` macro is ignored, causing a confused understanding. + +```c +#define LOG_AND_RETURN_IF_FAIL(ret, fmt, ...) do { \ + if ((ret) != OK) { \ + (void)ErrLog(fmt, ##__VA_ARGS__); \ + return (ret); \ + } \ +} while (0) + +#define RETURN_IF(cond, ret) do { \ + if (cond) { \ + return (ret); \ + } \ +} while (0) + +ret = InitModuleA(a, b, &status); +LOG_AND_RETURN_IF_FAIL(ret, "Init module A failed!"); // OK + +RETURN_IF(status != READY, ERR_NOT_READY); // Bad: The most important logic is not obvious. + +ret = InitModuleB(c); +LOG_AND_RETURN_IF_FAIL(ret, "Init module B failed!"); // OK +``` + +Second, if `return` is encapsulated in a macro, it may also cause a memory leak. Example: + +```c +#define CHECK_PTR(ptr, ret) do { \ + if ((ptr) == NULL) { \ + return (ret); \ + } \ +} while (0) + +... + +mem1 = MemAlloc(...); +CHECK_PTR(mem1, ERR_CODE_XXX); + +mem2 = MemAlloc(...); +CHECK_PTR(mem2, ERR_CODE_XXX); // Wrong: Memory leak. +``` + +If `mem2` fails to apply for memory, `CHECK_PTR` will return a message instead of releasing `mem1`. +Besides, the name of the `CHECK_PTR` macro is not good. The macro name only reflects the check action and does not specify the result. Readers can see that a failure is returned when the pointer is null only after viewing the macro implementation. It's not inherently obvious. + +In summary, it is not recommended to encapsulate process changing statements, such as `return`, `goto`, `continue`, and `break`, in macro definitions. +However, these macros can be used in special scenarios, such as return value judgment. + +Note: **Macro names must contain descriptive keywords if process changing statements, such as `return`, `goto`, `continue`, and `break`, are used.** + +### Rec 6.3 Include no more than 10 lines in a function-like macro (excluding blank lines and comments). + +A function-like macro is more difficult to debug and locate than a function, especially when the macro is too long. +Macro expansion will also lead to more compiled code. It is recommended that function-like macros contain no more than 10 lines. + +# 7 Variables + +In C language coding, variables are the most important except for functions. +When using a variable, you should always follow the principle of "single responsibility". +By scope, variables can be classified into global variables and local variables. + +## Global Variables + +Do not use or avoid using global variables. +In program design, global variables are variables that are accessible to all scopes. Using unnecessary global variables is generally considered a bad habit. + +Disadvantages of global variables: + +- Destroys the independence and portability of a function. Functions can be dependent on global variables and increased coupling results. +- Reduces readability and maintainability. When multiple functions read and write to global variables, their values may not be determinate, which is unfavorable for comprehension and maintenance. +- In a concurrent programming environment, global variables will hinder reentry of functions. Additional synchronization protection must be added to ensure data security. + +If unavoidable, the read and write of global variables should be encapsulated in a centralized manner. + +### Rule 7.1 Do not use global variables as interfaces between modules. + +Global variables are for the internal implementation of modules and should not be exposed as interfaces. +Global variables should be as centralized as possible. If the data of this module needs to be disclosed to external modules, a function as an interface to this data should be provided. + +## Local Variables + +### Rule 7.2 Do not use uninitialized variables as rvalues. + +The variable here refers to a local dynamic variable, and also includes a memory block obtained on a memory heap. +Because their initial values are unpredictable, it is prohibited to use them directly as rvalues without effective initialization. + +```c +void Foo(...) +{ + int data; + Bar(data); // Bad: Uninitialized variables are used as rvalues. + ... +} +``` + +If there are different branches, ensure that all branches are initialized before being used as rvalues. + +```c +void Foo(...) +{ + int data; + if (...) { + data = 100; + } + Bar(data); // Bad: This value is not initialized in some branches. + ... +} +``` + +Uninitialized rvalues can be found by generic static check tools. +For example, the PCLint tool reports a warning for the following two examples. + +> Warning 530: Symbol 'data' (line ...) not initialized Warning 644: Variable 'data' (line ...) may not have been initialized + +### Rule 7.3 Forbid invalid and redundant variable initialization. + +If the initial value is not determined before initialization is performed, it is not concise or secure and may cause problems that are more difficult to discover. + +Common redundant initialization: + +```c +int cnt = 0; // Bad: Redundant initialization. It will be overwritten by later initialization. +... +cnt = GetXxxCnt(); +... +``` + +Variables with conditional values can be initialized to default values during definition. + +```c +char *buf = NULL; // Good: NULL as the default value +if (condition) { + buf = malloc(MEM_SIZE); +} +... +if (buf != NULL) { // Check whether memory has been allocated. + free(buf); +} +``` + +Even worse, redundant clearing for arrays may affect the performance. + +```c +char buf[VERY_BIG_SIZE] = {0}; +memset(buf, 0, sizeof(buf)); // Bad: Redundant clearing +``` + +Invalid initialization, which hides a more severe problem: + +```c +void Foo(...) +{ + int data = 0; // Bad: regular initialization + + UseData(data); // UseData should be placed after GetData. + data = GetData(...); // Get data. + ... +} +``` + +In the preceding code, if 0 is not assigned before initialization, the static check tool can help find the problem of "direct use without being initialized". +However, due to invalid initialization, the defect of placing "UseData" before "GetData" cannot be easily found. + +Therefore, simple code should be written to initialize variables or memory blocks as required. + +The C99 does not limit the definition position of local variables to before the first statement in a function. That is, a variable can now be defined close to a variable. +This concise approach not only limits the scope of the variable scope, but also solves the problem of how to initialize the variable when it is defined. +If this compilation environment is supported, you are advised to define local variables in this way. + +**Exceptions:** +**As 'Secure Coding Standard' required, pointers, resource variables, and boolean variables can be treated as exceptions of this rule.** + +### Rule 7.4 Do not use magic numbers. + +The so-called magic numbers are the numbers that are unintelligible and difficult to understand. +The magic number is not a concept that can be defined literally. It varies depending on context and service knowledge. + +For example, the number 12 varies in different contexts. +`type = 12;` is not intelligible, but `month = year * 12;` can be understood. +The number 0 is sometimes seen as a magic number. For example, the `status = 0;` cannot truly express any status information. + +Solution: +Comments can be added for numbers that are used only once. +For numbers that are used multiple times, macro or const variables must be defined and self-commented with symbolic naming. + +The following cases are forbidden: +The name is not used to explain the meaning of a number, for example, `#define ZERO 0`. +The value is limited by the name, for example, `#define XX_TIMER_INTERVAL_300MS 300`. + +# 8 Programming Practice + +## Expressions + +### Rec 8.1 When comparing expressions, follow the principle that the left side tends to change and the right side tends to remain unchanged. + +When a variable is compared with a constant, placing the constant on the left, for example, `if (MAX == v)` does not read naturally, and `if (MAX > v)` is more difficult to understand. +The constant should be placed on the right according to the normal reading order and habit. The expression is written as follows: + +```c +if (v == MAX) ... +if (v < MAX) ... +``` + +There are special cases: for example, the expression `if (MIN < v && v < MAX)` is used to check for a range. This first constant should be placed on the left. + +You do not need to worry about accidentally writing '==' as '=' because a compilation alarm will be generated for `if (v = MAX)` and an error will be reported by other static check tools. Use these tools to solve such writing errors and ensure that that code is readable. + +### Do not reference a variable again in an expression containing an increment (++) or decrement (--) operator. + +In an expression containing a variable increment or decrement operator, if the variable is referenced again, the result is not explicitly defined in the C standard, which may vary between compilers or different compiler versions. +For better portability, you should not make any assumptions about the operation sequence not defined in any standards. + +Note that this problem cannot be solved by using parentheses because it is not a problem of priority. + +Example: + +```c +x = b[i] + i++; // Bad: b[i] operation and i++, the order is not clear. +``` + +The correct way is to add a separate line of increment or decrement: + +```c +x = b[i] + i; +i++; // Good: Single line. +``` + +Function parameter: + +```c +Func(i++, i); // Bad: When passing the second parameter, it is not sure whether the increment operation has occurred. +``` + +The correct way: + +```c +i++; // Good: Single line. +x = Func(i, i); +``` + +### Rec 8.2 Use parentheses to specify the sequence of expressions, instead of using the default priority. + +Parentheses can be used to better emphasize the purpose of used operators. This will prevent program errors due to the inconsistency between default priority and the intended design. +However, too many parentheses muddy the code, reducing readability. Use them moderately. + +Parentheses are recommended when expressions contain operators that are not commonly used and are confusing, such as bitwise operators. + +```c +c = (a & 0xFF) + b; /* Parentheses are required while using bit operators. */ +``` + +## Statements + +### Rule 8.2 Provide a 'default' branch for the `switch` statement. + +In most cases, the 'default' branch exists in the switch statement to ensure that there is a default processing action when the case tag is missing. + +Exceptions: +If the switch condition variable is of the enum type and the case branches cover all values, then the default branch is redundant. +A modern compiler can check whether the case branch of some enumerated values is missing in the switch statement. A warning will be displayed. + +```c +enum Color { + RED, + BLUE +}; + +// The switch condition variable is an enumerated value. Therefore, you do not need to add the 'default' processing branch. +switch (color) { + case RED: + DoRedThing(); + break; + case BLUE: + DoBlueThing(); + ... + break; +} +``` + +### Rec 8.3 Exercise caution when using the `goto` statement. + +The `goto` statement destroys the program. Avoid using it if possible. You can only jump to statements following the `goto` statement, and only within the one function. + +The `goto` statement is used to implement function return to a single point within a function. +If a function has a large number of identical logics that cannot be encapsulated, for example, repeated file execution, the processed part of code after the file operation failure (for example, closing the file handle and releasing memory that is dynamically applied for) is usually placed in the last part of the function body. And the goto statement is placed right before these. In this way, the code becomes clear and concise. It can also be encapsulated in functions or macros, but doing so makes code less straightforward. + +Example: + +```c +// Good: Use a goto statement to implement function return at a single point. +int SomeInitFunc(void) +{ + void *p1; + void *p2 = NULL; + void *p3 = NULL; + + p1 = malloc(MEM_LEN); + if (p1 == NULL) { + goto EXIT; + } + + p2 = malloc(MEM_LEN); + if (p2 == NULL) { + goto EXIT; + } + + p3 = malloc(MEM_LEN); + if (p3 == NULL) { + goto EXIT; + } + + DoSomething(p1, p2, p3); + return 0; // OK. + +EXIT: + if (p3 != NULL) { + free(p3); + } + if (p2 != NULL) { + free(p2); + } + if (p1 != NULL) { + free(p1); + } + return -1; // Failed! +} +``` + +## Type Conversion + +### Rec 8.4 Minimize unnecessary type conversion and forced conversion. + +When the data type is forcibly changed, the meaning of the data and the value after conversion may change. If details are not considered, potential risks may be generated. + +In the following assignment, most compilers do not generate warnings, but the values are slightly changed. + +```c +char ch; +unsigned short int exam; + +ch = -1; +exam = ch; // Bad: Compilers does not generate any warnings. In this case, the value of exam is 0xFFFF. +``` diff --git a/website/docs/extras/en/contribute/OpenHarmony-c-cpp-secure-coding-guide.md b/website/docs/extras/en/contribute/OpenHarmony-c-cpp-secure-coding-guide.md new file mode 100644 index 0000000000000000000000000000000000000000..4945976a36f11a8890e691f5e84a0d35c43d198e --- /dev/null +++ b/website/docs/extras/en/contribute/OpenHarmony-c-cpp-secure-coding-guide.md @@ -0,0 +1,3103 @@ +--- +title: "OpenHarmony-c-cpp-secure-coding-guide" +prepermalink: /extras/e4d5ad6182d72c212c21a29905bcde44/ +permalink: /extras/e4d5ad6182d72c212c21a29905bcde44/ +relpath: "OpenHarmony-3.1-Release/en/contribute/OpenHarmony-c-cpp-secure-coding-guide.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [OpenHarmony-c-cpp-secure-coding-guide] +--- +# C&C++ Secure Coding Guide + +This document provides some secure coding suggestions based on the C\&C++ language to guide development. + +# Functions + +## Check the validity of all values received from external sources + +**\[Description]** +External sources are networks, user input, command lines, files (including program configuration files), environment variables, user-mode data (for kernel programs), inter-process communications (including pipes, messages, shared memory, sockets, RPCs, and communications between different boards in a device), API parameters, and global variables. + +Data from outside programs is often considered untrusted and needs to be properly checked for validity before being used. If data from an external source is not checked before use, unexpected security risks may occur. + +Note: Do not use assertions to check external input data. Assertions should be used to prevent incorrect program assumptions but cannot be used to check for runtime errors in a released version. + +Data from outside programs must be checked before being used. Typical scenarios include: + +**Used as an array index**If untrusted data is used as an array index, the array upper bound may be exceeded, causing invalid memory access. **Used as a memory offset address** +Using untrusted data as the pointer offset for memory access may result in invalid memory access and cause further damages, for example, any address read/write. **Used as a memory allocation size parameter** +Zero-byte allocation may cause invalid memory access; an unrestricted memory allocation size leads to excessive resource consumption. **Used a loop condition** +If untrusted data is used as a loop condition, problems such as buffer overflow, out-of-bounds read/write, and infinite loop may occur. **Used as a divisor** +Divide-by-zero errors may occur. **Used as a command line parameter** +Command injection vulnerabilities may occur. **Used as the parameter of a database query statement**SQL injection vulnerabilities may occur. **Used as an input/output format string** +Format string vulnerabilities may occur. **Used as a memory copy length** +Buffer overflows may occur. **Used a file path** +Direct access to an untrusted file path may result in directory traversal attacks. As a result, the system is controlled by the attacker who can perform file operations without permissions. + +Input validation includes but is not limited to: + +- API parameter validity check +- Data length check +- Data range check +- Data type and format check +- Check on inputs that can only contain permitted characters (in the trustlist), especially special characters in certain cases. + +**External Data Validation Principles + +1. Trust boundary** + External data is untrusted. Therefore, if data is transmitted and processed across different trust boundaries during system operation, validity check must be performed on data from modules outside the trust boundaries to prevent attacks from spreading. (a) Different so (or dll) modules + As an independent third-party module, the so or dll module is used to export common API functions for other modules to call. The so/dll module is unable to determine whether the caller passes on valid arguments. Therefore, the common function of the so/dll module needs to check the validity of the arguments provided by the caller. The so/dll module should be designed in low coupling and high reusability. Although the so/dll module is designed to be used only in this software in certain cases, different so/dll modules should still be regarded as different trust boundaries. (b) Different processes + To prevent privilege escalation through processes with high permissions, the IPC communications between processes (including IPC communications between boards and network communications between hosts) should be regarded as communications across different trust boundaries. (c) Application layer processes and operating system kernel + The operating system kernel has higher permissions than the application layer. The interface provided by the kernel for the application layer should process the data from the application layer as untrusted data. (d) Internal and external environments of TEE + To prevent attacks from spreading to the TEE, the interfaces provided by the TEE and SGX for external systems should process external data as untrusted data. + +**2. External data validation** +The external data received by a module must be validated before being used. After data validation is completed, the data stored in the module does not need to be verified again by other internal subfunctions in the module. + +**\[Noncompliant Code Example]** +The **Foo()** function processes external data. Because the buffer does not necessarily end with '\\0', the **nameLen** value returned by **strlen** may exceed **len**. As a result, out-of-bounds read occurs. + +```cpp +void Foo(const unsigned char* buffer, size_t len) +{ + // "buffer" may be a null pointer and may not end with '\0'. + const char* s = reinterpret_cast(buffer); + size_t nameLen = strlen(s); + std::string name(s, nameLen); + Foo2(name); + ... +} +``` + +**\[Compliant Code Example]** +External data is checked for validity. In this example, **strnlen** is used to calculate the string length to reduce the risk of out-of-bounds read. + +```cpp +void Foo(const unsigned char* buffer, size_t len) +{ + // Parameter validity check must be performed. + if (buffer == nullptr || len == 0 || len >= MAX_BUFFER_LEN) { + ... // Error handling + } + + const char* s = reinterpret_cast(buffer); + size_t nameLen = strnlen(s, len); // strnlen is used to mitigate the risk of out-of-bounds read. + if (nameLen == len) { + ... // Error handling + } + std::string name(s, nameLen); + ... + Foo2(name); + ... +} +``` + +```cpp +namespace ModuleA { +// Foo2() is an internal function of the module. Parameter validity is ensured by the caller as agreed. +static void Foo2(const std::string& name) +{ + ... + Bar(name.c_str()); // Call the function in MODULE_B. +} + +// Foo() is an external interface of the module. Parameter validity check must be performed. +void Foo(const unsigned char* buffer, size_t len) +{ + // Check the null pointer and valid parameter range. + if (buffer == nullptr || len <= sizeof(int)) { + // Error handling + ... + } + + int nameLen = *(reinterpret_cast(buffer)); // Obtain the length of the name character string from the packet. + // nameLen is untrusted data and its validity must be checked. + if (nameLen <= 0 || static_cast(nameLen) > len - sizeof(int)) { + // Error handling + ... + } + + std::string name(reinterpret_cast(buffer), nameLen); + Foo2(name); // Call the internal functions of the module. + ... +} +} +``` + +The following code is the code in `MODULE_B` written using the C language: + +```cpp +// Bar is a common function of MODULE_B. +// If name is not nullptr, the string must be a valid string, which is longer than 0 bytes and null terminated. +void Bar(const char* name) +{ + // Parameter validity check must be performed. + if (name == nullptr || name[0] == '\0') { + // Error handling + ... + } + size_t nameLen = strlen(name); // strnlen does not need to be used. + ... +} +``` + +For module A, the buffer is an external untrusted input, which must be strictly verified. Validity check is performed while the name is parsed from the buffer. The name is valid in module A, and validity check is not required when the name is transferred to internal subfunctions as a parameter. (If the name content needs to be parsed, it must be verified.) If the name in module A needs to be transferred to other modules across the trusted plane (in this example, the common function of module B is directly called, or by means of file, pipe, or network transfer), the name is untrusted data for module B and therefore validity check must be performed. + +# Classes + +## Class member variables must be explicitly initialized + +**\[Description]** +If a class member variable is not explicitly initialized, the object will have an indeterminate value. If the class member variable has a default constructor, it does not need to be explicitly initialized. + +**\[Noncompliant Code Example]** + +```cpp +class Message { +public: + void Process() + { + ... + } + +private: + uint32_t msgId; // Noncompliant: The member variable is not initialized. + size_t msgLength; // Noncompliant: The member variable is not initialized. + unsigned char* msgBuffer; // Noncompliant: The member variable is not initialized. + std::string someIdentifier; // Only this member variable is initialized by the default constructor. +}; + +Message message; // The message member variable is not completely initialized. +message.Process(); // Potential risks exist in subsequent use. +``` + +**\[Compliant Code Example]** +One practice is to explicitly initialize the class member variable in declarations. + +```cpp +class Message { +public: + void Process() + { + ... + } + +private: + uint32_t msgId{0}; + size_t msgLength{0}; + unsigned char* msgBuffer{nullptr}; + std::string someIdentifier; // The default constructor is used, and explicit initialization is not required. +}; +``` + +Another option is to initialize the list using a constructor. + +```cpp +class Message { +public: + Message() : msgId(0), msgLength(0), msgBuffer(nullptr) {} + void Process() + { + ... + } + +private: + uint32_t msgId; + size_t msgLength; + unsigned char* msgBuffer; + std::string someIdentifier; // The default constructor is used, and explicit initialization is not required. +}; +``` + +## Clearly define the special member functions to be implemented + +**\[Description]** +**Rule of three** +If a class requires a user-defined destructor, a user-defined copy constructor, or a user-defined copy assignment operator, it almost certainly requires all three. + +```cpp +class Foo { +public: + Foo(const char* buffer, size_t size) { Init(buffer, size); } + Foo(const Foo& other) { Init(other.buf, other.size); } + + Foo& operator=(const Foo& other) + { + Foo tmp(other); + Swap(tmp); + return *this; + } + + ~Foo() { delete[] buf; } + + void Swap(Foo& other) noexcept + { + using std::swap; + swap(buf, other.buf); + swap(size, other.size); + } + +private: + void Init(const char* buffer, size_t size) + { + this->buf = new char[size]; + memcpy(this->buf, buffer, size); + this->size = size; + } + + char* buf; + size_t size; +}; +``` + +The implicitly-defined special member functions are typically incorrect if the class manages a resource whose handle is an object of non-class type (such as the raw pointer or POSIX file descriptor), whose destructor does nothing and copy constructor/assignment operator performs a "shallow copy". + +Classes that manage non-copyable resources through copyable handles may have to declare copy assignment and copy constructor private and not provide their definitions or define them as deleted. + +**Rule of five** +The presence of a user-defined destructor, copy-constructor, or copy-assignment operator can prevent implicit definition of the move constructor and the move assignment operator. Therefore, any class for which move semantics are desirable has to declare all five special member functions. + +```cpp +class Foo { +public: + Foo(const char* buffer, size_t size) { Init(buffer, size); } + Foo(const Foo& other) { Init(other.buf, other.size); } + + Foo& operator=(const Foo& other) + { + Foo tmp(other); + Swap(tmp); + return *this; + } + + Foo(Foo&& other) noexcept : buf(std::move(other.buf)), size(std::move(other.size)) + { + other.buf = nullptr; + other.size = 0; + } + + Foo& operator=(Foo&& other) noexcept + { + Foo tmp(std::move(other)); + Swap(tmp); + return *this; + } + + ~Foo() { delete[] buf; } + + void Swap(Foo& other) noexcept + { + using std::swap; + swap(buf, other.buf); + swap(size, other.size); + } + +private: + void Init(const char* buffer, size_t size) + { + this->buf = new char[size]; + memcpy(this->buf, buffer, size); + this->size = size; + } + + char* buf; + size_t size; +}; +``` + +However, failure to provide the move constructor and move assignment operator is usually not an error, but a missed optimization opportunity. + +**Rule of zero** +If a class does not need to deal exclusively with resource ownership, the class should not have custom destructors, copy/move constructors, or copy/move assignment operators. + +```cpp +class Foo { +public: + Foo(const std::string& text) : text(text) {} + +private: + std::string text; +}; +``` + +As long as a copy constructor, copy assignment operator, or destructor is declared for a class, the compiler will not implicitly generate move constructors or move assignment operators. As a result, the move operation of this class becomes a copy operation at a higher cost. As long as a move constructor or move assignment operator is declared for a class, the compiler will define the implicitly generated copy constructor or copy assignment operator as deleted. As a result, the class can only be moved but cannot be copied. Therefore, if any of the functions is declared, all the other functions should be declared to avoid unexpected results. + +Likewise, if a base class needs to define the virtual destructor as public, all related special member functions need to be implicitly defined: + +```cpp +class Base { +public: + ... + Base(const Base&) = default; + Base& operator=(const Base&) = default; + Base(Base&&) = default; + Base& operator=(Base&&) = default; + virtual ~Base() = default; + ... +}; +``` + +However, if a copy constructor/copy assignment operator is declared for a base class, slicing may occur. Therefore, the copy constructor/copy assignment operator in the base class is often explicitly defined as deleted, and other special member functions are also explicitly defined as deleted: + +```cpp +class Base { +public: + ... + Base(const Base&) = delete; + Base& operator=(const Base&) = delete; + Base(Base&&) = delete; + Base& operator=(Base&&) = delete; + virtual ~Base() = default; + ... +}; +``` + +## The copy constructor, copy assignment operator, move constructor, and move assignment operator in the base class must be defined as non-public or deleted + +**\[Description]** +Slicing occurs if a derived class object is directly assigned to a base class object. In this case, only the base class part is copied or moved, which undermines polymorphism. + +**\[Noncompliant Code Example]** +In the following code, the copy constructor and copy assignment operator of the base class are declared as default. Slicing occurs if a derived class object is assigned to the base class object. The copy constructor and copy assignment operator can be declared as deleted so that the compiler can check such assignment behavior. + +```cpp +class Base { +public: + Base() = default; + Base(const Base&) = default; + Base& operator=(const Base&) = default; + ... + virtual void Fun() { std::cout << "Base" << std::endl; } +}; + +class Derived : public Base { + ... + void Fun() override { std::cout << "Derived" << std::endl; } +}; + +void Foo(const Base& base) +{ + Base other = base; // Noncompliant: Slicing occurs. + other.Fun(); // The Fun() function of the base class is called. +} +Derived d; +Foo(d); +``` + +## The resources of the source object must be correctly reset in move constructors and move assignment operators + +**\[Description]** +The move constructor and move assignment operator move the ownership of a resource from one object to another. Once the resource is moved, the resource of the source object should be reset correctly. This can prevent the source object from freeing the moved resources in destructors. + +Some non-resource data can be retained in the moved object, but the moved object must be in a state that can be properly destructed. Therefore, after an object is moved, do not reply on the value of the moved object unless the object is explicitly specified. lvalue reference may lead to unexpected behavior. + +**\[Noncompliant Code Example]** + +```cpp +class Foo { +public: + ... + Foo(Foo&& foo) noexcept : data(foo.data) + { + } + + Foo& operator=(Foo&& foo) + { + data = foo.data; + return *this; + } + + ~Foo() + { + delete[] data; + } + +private: + char* data = nullptr; +}; +``` + +The move constructor and move assignment operator of the **Foo()** function do not correctly reset the resources of the source object. When the source object is destructed, the resources will be released. As a result, the resources taken over by the newly created object become invalid. + +**\[Compliant Code Example]** + +```cpp +class Foo { +public: + ... + Foo(Foo&& foo) noexcept : data(foo.data) + { + foo.data = nullptr; + } + + Foo& operator=(Foo&& foo) + { + if (this == &foo) { + return *this; + } + delete[] data; + data = foo.data; + foo.data = nullptr; + return *this; + } + + ~Foo() + { + delete[] data; + } + +private: + char* data = nullptr; +}; +``` + + In some standard libraries, the implementation of std::string may implement the short string optimization (SSO). The content of the character string to be moved may not be altered during the implementation of move semantics. As a result, the output of the following code may not be the expected b but ab, causing compatibility issues. + +```cpp +std::string str{"a"}; +std::string other = std::move(str); + +str.append(1, 'b'); +std::cout << str << std::endl; +``` + +## The base class destructor must be declared as virtual when a derived class is released through a base class pointer + +**\[Description]** +The destructor of the derived class can be called through polymorphism only when the base class destructor is declared as virtual. If the base class destructor is not declared as virtual, only the base class destructor (instead of the derived class destructor) is called when the derived class is released through a base class pointer, causing memory leaks. + +**\[Noncompliant Code Example]** +Memory leaks occur because the base class destructor is not declared as virtual. + +```cpp +class Base { +public: + Base() = default; + ~Base() { std::cout << "~Base" << std::endl; } + virtual std::string GetVersion() = 0; +}; +class Derived : public Base { +public: + Derived() + { + const size_t numberCount = 100; + numbers = new int[numberCount]; + } + + ~Derived() + { + delete[] numbers; + std::cout << "~Derived" << std::endl; + } + + std::string GetVersion() + { + return std::string("hello!"); + } + +private: + int* numbers; +}; +void Foo() +{ + Base* base = new Derived(); + delete base; // The base class destructor is called, causing resource leaks. +} +``` + +## Avoid slicing during object assignment and initialization + +**\[Description]** + +Slicing occurs when a derived class object is assigned to a base class object, damaging polymorphism. + +If the object needs to be sliced, it is recommended that an explicit operation be defined for slicing, thereby avoiding misunderstanding and improving maintainability. + +**\[Noncompliant Code Example]** + +```cpp +class Base { + virtual void Fun(); +}; + +class Derived : public Base { + ... +}; +void Foo(const Base& base) +{ + Base other = base; // Noncompliant: Slicing occurs. + other.Fun(); // The Fun() function of the base class is called. +} +Derived d; +Base b{d}; // Noncompliant: Only base is constructed. +b = d; // Noncompliant: Assigned only to base. + +Foo(d); +``` + +# Expressions and Statements + +## Ensure that objects have been initialized before being used + +**\[Description]** +Initialization is the process of setting the expected value for an object by means of explicit initialization, default constructor initialization, and value assignment. Reading an uninitialized value may result in undefined behaviour. Therefore, ensure that objects have been initialized before being used. + +**\[Noncompliant Code Example]** + +```cpp +void Bar(int data); +... +void Foo() +{ + int data; + Bar(data); // Noncompliant: Not initialized before being used + ... +} +``` + +If there are different branches, ensure that all branches are initialized before being used as values. + +```cpp +void Bar(int data); +... +void Foo(int condition) +{ + int data; + if (condition > 0) { + data = CUSTOMIZED_SIZE; + } + Bar(data); // Noncompliant: Values not initialized for some branches + ... +} +``` + +**\[Compliant Code Example]** + +```cpp +void Bar(int data); +... +void Foo() +{ + int data{0}; // Compliant: Explicit initialization + Bar(data); + ... +} +void InitData(int& data); +... +void Foo() +{ + int data; + InitData(data); // Compliant: Initialization using functions + ... +} +std::string data; // Compliant: Default constructor initialization +... +``` + +## Avoid using reinterpret\_cast + +**\[Description]** +`reinterpret_cast` is used to convert irrelevant types. `reinterpret_cast` tries to cast one type to another type, which destroys the type of security and reliability. It is an unsafe conversion. It is advised to use reinterpret\_cast as little as possible. + +## Avoid using const\_cast + +**\[Description]** +`const_cast` is used to remove the `const` and `volatile` attributes of an object. + +Using a pointer or reference converted by **const\_cast** to modify a **const** or **volatile** object will result in undefined behavior. + +**\[Noncompliant Code Example]** + +```cpp +const int i = 1024; +int* p = const_cast(&i); +*p = 2048; // Undefined behavior +class Foo { +public: + void SetValue(int v) { value = v; } + +private: + int value{0}; +}; + +int main() +{ + const Foo foo; + Foo* p = const_cast(&foo); + p->SetValue(2); // Undefined behavior + return 0; +} +``` + +## Ensure no overflows in signed integer operations + +**\[Description]** +In the C++ standard, signed integer overflow is undefined behavior. Therefore, signed integer overflows are handled differently in implementations. For example, after defining a signed integer type as a modulus, the compiler may not detect integer overflows. + +Using overflowed values may cause out-of-bounds read/write risks in the buffer. For security purposes, ensure that operations do not cause overflows when signed integers in external data are used in the following scenarios: + +- Integer operand of pointer operation (pointer offset value) +- Array index +- Length of the variable-length array (and the length operation expression) +- Memory copy length +- Parameter of the memory allocation function +- Loop judgment condition + +Integer promotion needs to be considered when the operation is performed for the integer types whose precision is less than **int**. Programmers also need to master integer conversion rules, including implicit conversion rules, to design secure arithmetic operations. + +**\[Noncompliant Code Example]** +In the following code example, the integers involved in the subtraction operation are external data and are not validated before being used. As a result, integer overflow may occur, which further results in buffer overflow due to memory copy operations. + +```cpp +unsigned char* content = ... // Pointer to the packet header +size_t contentSize = ... // Total length of the buffer +int totalLen = ... // Total length of the packet +int skipLen = ... // Data length that needs to be ignored from the parsed message + +std::vector dest; + +// Using totalLen - skipLen to calculate the length of the remaining data is likely to cause integer overflows. +std::copy_n(&content[skipLen], totalLen - skipLen, std::back_inserter(dest)); +... +``` + +**\[Compliant Code Example]** +In the following code example, code is refactored to use the variable of the `size_t` type to indicate the data length and check whether the external data length is valid. + +```cpp +unsigned char* content = ... // Pointer to the packet header +size_t contentSize = ... // Total length of the buffer +size_t totalLen = ... // Total length of the packet +size_t skipLen = ... // Data length that needs to be ignored from the parsed message + +if (skipLen >= totalLen || totalLen > contentSize) { + ... // Error handling +} + +std::vector dest; +std::copy_n(&content[skipLen], totalLen - skipLen, std::back_inserter(dest)); +... +``` + +**\[Noncompliant Code Example]** +In the following code example, the value range of external data is validated. However, the second type is `int`, and `std::numeric_limits::max()` is incorrectly used as a validation condition. As a result, integer overflow occurs. + +```cpp +int second = ... // External data + + //The value range of unsigned long is incorrectly used for upper limit validation. +if (second < 0 || second > (std::numeric_limits::max() / 1000)) { + return -1; +} +int millisecond = second * 1000; // Integer overflow may occur. +... +``` + +**\[Compliant Code Example]** +One option is to change the second type to `unsigned long`. This solution is applicable to the scenario where the new variable type is more fit for service logic. + +```cpp +unsigned long second = ... // Refactor the type to unsigned long. + +if (second > (std::numeric_limits::max() / 1000)) { + return -1; +} +int millisecond = second * 1000; +... +``` + +Another method is to change the upper limit to `std::numeric_limits::max()`. + +```cpp +int second = ... // External data + +if (second < 0 || second > (std::numeric_limits::max() / 1000)) { + return -1; +} +int millisecond = second * 1000; +``` + +**\[Impact]** +Integer overflows may cause buffer overflows and arbitrary code execution. + +## Ensure that unsigned integer operations do not wrap + +**\[Description]** +Integer wrap may occur in the arithmetic operation results of unsigned integers, which may cause risks such as out-of-bounds read/write in the buffer. For security purposes, ensure that operations do not cause wrapping when unsigned integers in external data are used in the following scenarios: + +- Pointer offset value (integer operands in pointer arithmetic operations) +- Array index value +- Memory copy length +- Parameter of the memory allocation function +- Loop judgment condition + +**\[Noncompliant Code Example]** +In the following code example, the program checks whether the total length of the next sub-packet and the processed packet exceeds the maximum packet length. The addition operation in the check condition may cause integer wrapping, causing potential validation bypassing issues. + +```cpp +size_t totalLen = ... // Total length of the packet +size_t readLen = 0; // Record the length of the processed packet. +... +size_t pktLen = ParsePktLen(); // Length of the next sub-packet parsed from the network packet +if (readLen + pktLen > totalLen) { // Integer wrapping may occur. + ... // Error handling +} +... +readLen += pktLen; +... +``` + +**\[Compliant Code Example]** +The readLen variable is the length of the processed packet and is definitely less than totalLen. Therefore, the use of the subtraction operation instead of the addition operation will not bypass the condition check. + +```cpp +size_t totalLen = ... // Total length of the packet +size_t readLen = 0; // Record the length of the processed packet. +... +size_t pktLen = ParsePktLen(); // From the network packet +if (pktLen > totalLen - readLen) { + ... // Error handling +} +... +readLen += pktLen; +... +``` + +**\[Noncompliant Code Example]** +In the following code example, integer wrapping may occur in the operation of len validation, resulting in condition check bypassing. + +```cpp +size_t len =... // From the user-mode input + +if (SCTP_SIZE_MAX - len < sizeof(SctpAuthBytes)) { // Integer wrapping may occur in subtraction. + ... // Error handling +} +... = kmalloc(sizeof(SctpAuthBytes) + len, gfp); // Integer wrapping may occur. +... +``` + +**\[Compliant Code Example]** +In the following code example, the subtraction operation is relocated (ensure that the value of the subtraction expression is not reversed during compilation) to avoid integer wrapping. + +```cpp +size_t len =... // From the user-mode input + +if (len > SCTP_SIZE_MAX - sizeof(SctpAuthBytes)) { // Ensure no integer wrapping for the subtraction expression value during compilation. + ... // Error handling +} +... = kmalloc(sizeof(SctpAuthBytes) + len, gfp); +... +``` + +**\[Exception]** +Unsigned integers can exhibit modulo behavior (wrapping) when necessary for the proper execution of the program. It is recommended that the variable declaration and each operation on that integer be clearly commented as supporting modulo behavior. + +**\[Impact]** +Integer wrapping is likely to cause buffer overflows and arbitrary code execution. + +## Ensure that division and remainder operations do not cause divide-by-zero errors + +**\[Description]** +Division remainder operations performed on integers with the divisor of zero are undefined behavior. Ensure that the divisor is not 0 in division and remainder operations. + +The ISO/IEEE 754-1985 standard for binary floating-point arithmetic specifies the behavior and results of floating-point number division by zero. However, the presence of undefined behavior depends on whether the hardware and software environments comply with this standard. Therefore, before dividing a floating point number by zero, ensure that the hardware and software environments comply with the binary floating-point arithmetic. Otherwise, undefined behavior still exists. + +**\[Noncompliant Code Example]** + +```c +size_t a = ReadSize(); // From external data +size_t b = 1000 / a; // Noncompliant: a may be 0 +size_t c = 1000 % a; // Noncompliant: a may be 0 +... +``` + +**\[Compliant Code Example]** +In the following code example, a=0 validation is added to prevent divide-by-zero errors. + +```c +size_t a = ReadSize(); // From external data +if (a == 0) { + ... // Error handling +} +size_t b = 1000 / a; // Compliant: Ensure that a is not 0. +size_t c = 1000 % a; // Compliant: Ensure that a is not 0. +... +``` + +**\[Impact]** +Divide-by-zero errors are likely to cause DoS. + +## Bitwise operations can be performed only on unsigned integers + +**\[Description]** +Undefined behavior may occur during bitwise operations on signed integers. To avoid undefined behavior, ensure that bitwise operations are performed only on unsigned integers. In addition, the unsigned integer type with less precision than **int** is promoted when a bitwise operation is performed on the unsigned integer. Then the bitwise operation is performed on the promoted integer. Therefore, beware of the bitwise operations on such unsigned integers to avoid unexpected results. The bitwise operators are as follows: + +- `~` (Complement operator) +- `&` (AND) +- `|` (OR) +- `^` (XOR) +- `>>` (Right shift operator) +- `<<` (Left shift operator) +- `&=` +- `^=` +- `|=` +- `>>=` +- `<<=` + +C++20 defines bitwise shift operations on signed integers, and such operations can be performed in compliance with C++20. + +**\[Noncompliant Code Example]** +In versions earlier than C++20, the right shift operation `data >> 24` can be implemented as arithmetic (signed) shift or logic (unsigned) shift. If the value in `value << data` is a negative number or the result of the left shift operation is out of the representable range of the promoted integer type, undefined behavior occurs. + +```cpp +int32_t data = ReadByte(); +int32_t value = data >> 24; // The result of the right shift operation on a signed integer is implementation-defined. + +... // Check the valid data range. + +int32_t mask = value << data; // The left shift operation on a signed integer may cause undefined behavior. +``` + +**\[Compliant Code Example]** + +```cpp +uint32_t data = static_cast(ReadByte()); +uint32_t value = data >> 24; // Bitwise operations are performed only on unsigned integers. + +... // Check the valid data range. + +uint32_t mask = value << data; +``` + +If bitwise operations are performed on unsigned integers with less precision than `int`, the operation results may be unexpected due to integer promotions. In this case, you need to immediately convert the operation results to the expected types to avoid unexpected results. + +**\[Noncompliant Code Example]** + +```cpp +uint8_t mask = 1; +uint8_t value = (~mask) >> 4; // Noncompliant: The result of the ~ operation contains high-order data, which may not meet the expectation. +``` + +**\[Compliant Code Example]** + +```cpp +uint8_t mask = 1; +uint8_t value = (static_cast(~mask)) >> 4; // Compliant: The result is converted to the expected type immediately after the ~ operation. +``` + +**\[Exception]** + +- A signed integer constant or enumerated value used as a bit flag can be used as an operand for the \& and \| operators. + +```cpp +int fd = open(fileName, O_CREAT | O_EXCL, S_IRWXU | S_IRUSR); +``` + +- If a signed positive integer is known at compile time, it can be used as the right operand of a shift operator. + +```cpp +constexpr int SHIFT_BITS = 3; +... +uint32_t id = ...; +uint32_t type = id >> SHIFT_BITS; +``` + +# Resource Management + +## Ensure validation of external data that is used as an array index or memory operation length + +**\[Description]** +When external data is used as an array index for memory access, the data size must be strictly validated to ensure that the array index is within the valid scope. Otherwise, serious errors may occur. Buffer overflows will occur if data is copied to the memory space insufficient for storing the data. To prevent such errors, limit the size of data to be copied based on the target capacity or ensure that the target capacity is sufficient to store the data to be copied. + +**\[Noncompliant Code Example]** +In the following code example, the **SetDevId()** function has an off-by-one error. When index equals `DEV_NUM`, an element is written out of bounds. + +```cpp +struct Dev { + int id; + char name[MAX_NAME_LEN]; +}; + +static Dev devs[DEV_NUM]; + +int SetDevId(size_t index, int id) +{ + if (index > DEV_NUM) { // Off-by-one error + ... // Error handling + } + + devs[index].id = id; + return 0; +} +``` + +**\[Compliant Code Example]** +In the following code example, the index validation condition is modified to avoid the off-by-one error. + +```cpp +struct Dev { + int id; + char name[MAX_NAME_LEN]; +}; + +static Dev devs[DEV_NUM]; + +int SetDevId(size_t index, int id) +{ + if (index >= DEV_NUM) { + ... // Error handling + } + devs[index].id = id; + return 0; +} +``` + +**\[Noncompliant Code Example]** +External input data may not be directly used as the memory copy length, but may be indirectly involved in memory copy operations. In the following code, **inputTable.count** is from external packets. It is used as the upper limit of the **for** loop body and indirectly involved in memory copy operations, instead of being directly used as the memory copy length. Buffer overflows may occur because the length is not validated. + +```cpp +struct ValueTable { + size_t count; + int val[MAX_NUMBERS]; +}; + +void ValueTableDup(const ValueTable& inputTable) +{ + ValueTable outputTable = {0, {0}}; + ... + for (size_t i = 0; i < inputTable.count; i++) { + outputTable.val[i] = inputTable.val[i]; + } + ... +} +``` + +**\[Compliant Code Example]** +In the following code example, **inputTable.count** is validated. + +```cpp +struct ValueTable { + size_t count; + int val[MAX_NUMBERS]; +}; + +void ValueTableDup(const ValueTable& inputTable) +{ + ValueTable outputTable = {0, {0}}; + ... + // Based on application scenarios, validate the cyclic length inputTable.count of external packets + // and the array size outputTable.val to prevent buffer overflows. + if (inputTable->count > + sizeof(outputTable.val) / sizeof(outputTable.val[0])) { + ... // Error handling + } + for (size_t i = 0; i < inputTable.count; i++) { + outputTable.val[i] = inputTable.val[i]; + } + ... +} +``` + +**\[Impact]** +If the length of the copied data is externally controllable, buffer overflows may occur during data copy operations, which may cause arbitrary code execution vulnerabilities. + +## Verify the requested memory size before requesting memory + +**\[Description]** +When the requested memory size is an external input, it must be verified to prevent the request for zero-length memory or excessive and illegal memory requests. This is because memory resources are limited and can be exhausted. If the requested memory is too large (memory requested at a time is too large, or requested multiple times in a loop), resources may be used up unexpectedly. Unexpected buffer allocation may result from incorrect parameter values, improper range checks, integer overflows, or truncation. If memory requests are controlled by attackers, security issues such as buffer overflows may occur. + +**\[Noncompliant Code Example]** +In the following code example, the memory space specified by **size** is dynamically allocated. However, **size** is not validated. + +```c +// size is not validated before being passed into to the DoSomething() function. +int DoSomething(size_t size) +{ + ... + char* buffer = new char[size]; // size is not validated before being used in this function. + ... + delete[] buffer; +} +``` + +**\[Compliant Code Example]** +In the following code example, before the memory space specified by **size** is dynamically allocated, the validity check required by the program is performed. + +```c +// size is not validated before being passed into to the DoSomething() function. +int DoSomething(size_t size) +{ + // In this function, size is validated before being used. FOO_MAX_LEN is defined as the maximum memory space expected. + if (size == 0 || size > FOO_MAX_LEN) { + ... // Error handling + } + char* buffer = new char[size]; + ... + delete[] buffer; +} +``` + +**\[Impact]** +If the size of the requested memory is externally controllable, resources may be exhausted, resulting in DoS. + +## An array should not be passed as a pointer separately when it is passed into a function as a parameter + +**\[Description]** +When the function parameter type is array (not array reference) or pointer, the array that is being passed into a function is degraded to a pointer. As a result, the array length information is lost, causing potential out-of-bounds read/write issues. If a function receives only fixed-length arrays as parameters, define the parameter type as an array reference or `std::array`. If the function receives a pointer without a length, then the length should also be passed into the function as a parameter. + +**\[Noncompliant Code Example]** + +```cpp +constexpr int MAX_LEN = 1024; +constexpr int SIZE = 10; + +void UseArr(int arr[]) +{ + for (int i = 0; i < MAX_LEN; i++) { + std::cout << arr[i] << std::endl; + } +} + +void Test() +{ + int arr[SIZE] = {0}; + UseArr(arr); +} +``` + +**\[Compliant Code Example]** + +It is easier to use the combination of the pointer and length as a type. The following is a simple encapsulation example: + +```cpp +template +class Slice { +public: + template + Slice(T (&arr)[N]) : data(arr), len(N) {} + + template + Slice(std::array arr) : data(arr.data()), len(N) {} + + Slice(T* arr, size_t n) : data(arr), len(n) {} + ... + +private: + T* data; + size_t len; +}; + +void UseArr(Slice arr) +{ + for (int i = 0; i < arr.size(); i++) { + std::cout << arr[i] << std::endl; + } +} + +constexpr int SIZE = 10; + +void Test() +{ + int arr[SIZE] = {0}; + Slice s{arr}; + UseArr(s); +} +``` + +If project conditions permit, it is advised to use a mature library for parameter passing, such as the `std::span` type in C++20. + +If these utility classes are not used, you can pass the pointer and length as two parameters. + +```cpp +void UseArr(int arr[], size_t len) +{ + for (int i = 0; i < len; i++) { + std::cout << arr[i] << std::endl; + } +} + +constexpr int SIZE = 10; + +void Test() +{ + int arr[SIZE] = {0}; + UseArr(arr, sizeof(arr)); +} +``` + +## When a lambda escapes the current scope, do not capture local variables by reference + +**\[Description]** +If a lambda is not limited to local use (for example, when it is transferred to the outside of a function or to another thread), do not capture local variables by reference. Capturing by reference in a lambda means storing a reference to a local object. If the life cycle of the lambda is longer than that of local variables, memory may be insecure. + +**\[Noncompliant Code Example]** + +```cpp +void Foo() +{ + int local = 0; + // The local is captured by reference. The local no longer exists after the function is executed. Therefore, the Process() behavior is undefined. + threadPool.QueueWork([&] { Process(local); }); +} +``` + +**\[Compliant Code Example]** + +```cpp +void Foo() +{ + int local = 0; + // Capture the local by value. The local is always valid when Process() is called. + threadPool.QueueWork([local] { Process(local); }); +} +``` + +## Assign a new value to the variable pointing to a resource handle or descriptor immediately after the resource is freed + +**\[Description]** +Variables pointing to resource handles or descriptors include pointers, file descriptors, socket descriptors, and other variables pointing to resources. Take a pointer as an example. If a pointer that has successfully obtained a memory segment is not immediately set to **nullptr** after the memory segment is freed and no new object is allocated, the pointer is a dangling pointer. Operations on a dangling pointer may lead to double-free and access-freed-memory vulnerabilities. An effective way to mitigate these vulnerabilities is to immediately set freed pointers to new values, such as **nullptr**. For a global resource handle or descriptor, a new value must be set immediately after the resource is freed, so as to prevent the invalid value from being used. For a resource handle or descriptor that is used only in a single function, ensure that the invalid value is not used again after the resource is freed. + +**\[Noncompliant Code Example]** +In the following code example, the message is processed based on the message type. After the message is processed, the memory to which the **body** points is freed, but the pointer is not set to **nullptr**. If other functions process the message structure again, double-free and access-freed-memory errors may occur. + +```c +int Fun() +{ + SomeStruct *msg = nullptr; + + ... // Use new to allocate the memory space for msg and msg->body and initialize msg. + + if (msg->type == MESSAGE_A) { + ... + delete msg->body; // Noncompliant: The pointer is not set to bnullptrb after memory is freed. + } + + ... + + // msg is saved to the global queue, and the freed body member may be used. + if (!InsertMsgToQueue(msg)) { + delete msg->body; // The memory to which the bbodyb points may be freed again. + delete msg; + return -1; + } + return 0; +} +``` + +**\[Compliant Code Example]** +In the following code example, the released pointer is immediately set to **nullptr** to avoid double-free errors. + +```c +int Fun() +{ + SomeStruct *msg = nullptr; + + ... // Use new to allocate the memory space for msg and msg->body and initialize msg. + + if (msg->type == MESSAGE_A) { + ... + delete msg->body; + msg->body = nullptr; + } + + ... + + // msg saved to the global queue + if (!InsertMsgToQueue(msg)) { + delete msg->body; // No need to assign nullptr because the pointer leaves the scope soon + delete msg; // No need to assign nullptr because the pointer leaves the scope soon + return -1; + } + return 0; +} +``` + +The default memory freeing function does not perform any action on NULL pointers. + +**\[Noncompliant Code Example]** +In the following code example, no new value is assigned to the file descriptor after it is closed. + +```c +SOCKET s = INVALID_SOCKET; +int fd = -1; +... +closesocket(s); +... +close(fd); +... +``` + +**\[Compliant Code Example]** +In the following code example, a new value is assigned to the corresponding variable immediately after the resource is freed. + +```c +SOCKET s = INVALID_SOCKET; +int fd = -1; +... +closesocket(s); +s = INVALID_SOCKET; +... +close(fd); +fd = -1; +... +``` + +**\[Impact]** +The practices of using the freed memory, freeing the freed memory again, or using the freed resources may cause DoS or arbitrary code execution. + +## new and delete operators must be used in pairs, and new\[] and delete\[] operators must also be used in pairs. + +**\[Description]** +The object created using the new operator can be destroyed only using the delete operator. The object array created using the new\[] operator can be destroyed only using the delete\[] operator. + +**\[Noncompliant Code Example]** + +```cpp +class C { +public: + C(size_t len) : arr(new int[len]) {} + ~C() + { + delete arr; // delete[] arr; should be used. + } + +private: + int* arr; +}; +``` + +**\[Compliant Code Example]** + +```cpp +class C { +public: + C(size_t len) : arr(new int[len]) {} + ~C() { delete[] arr; } + +private: + int* arr; +}; +``` + +## The custom operators new and delete must be defined in pairs, and the behavior specified in the operators must be the same as that of the operators to be replaced + +**\[Description]** +The custom operators new and delete as well as new\[] and delete\[] must be defined in pairs. The behavior specified in the new/delete operators must be the same as that of the operators to be replaced. + +**\[Noncompliant Code Example]** + +```cpp +// If the custom operator new is defined, the corresponding operator delete must be defined. +struct S { + static void* operator new(size_t sz) + { + ... // Custom operation + return ::operator new(sz); + } +}; +``` + +**\[Compliant Code Example]** + +```cpp +struct S { + static void* operator new(size_t sz) + { + ... // Custom operation + return ::operator new(sz); + } + static void operator delete(void* ptr, size_t sz) + { + ... // Custom operation + ::operator delete(ptr); + } +}; +``` + +The default operator new throws an exception `std::bad_alloc` when memory allocation fails, whereas the operator new that uses the `std::nothrow` parameter returns **nullptr** in the case of a memory allocation failure. The behavior specified the custom operators new and delete must be the same as that of built-in operators. + +**\[Noncompliant Code Example]** + +```cpp +// Function declared in the header file of the memory management module +extern void* AllocMemory(size_t size); // nullptr is returned in the case of a memory allocation failure. +void* operator new(size_t size) +{ + return AllocMemory(size); +} +``` + +**\[Compliant Code Example]** + +```cpp +// Function declared in the header file of the memory management module +extern void* AllocMemory(size_t size); // nullptr is returned in the case of a memory allocation failure. +void* operator new(size_t size) +{ + void* ret = AllocMemory(size); + if (ret != nullptr) { + return ret; + } + throw std::bad_alloc(); // An exception is thrown in the case of an allocation failure. +} + +void* operator new(size_t size, const std::nothrow_t& tag) +{ + return AllocMemory(size); +} +``` + +# Error Handling + +## Throw an object itself instead of the pointer to the object when throwing an exception + +**\[Description]** +The recommended exception throwing method in C++ is to throw the object itself instead of the pointer to the object. + +When the throw statement is used to throw an exception, a temporary object, called an exception object, is constructed. The life cycle of the exception object is clearly defined in the C++ standard: The exception object is constructed when it is thrown. It is destructed when a catch statement of the exception object does not end with `throw` (that is, it is not thrown again) or when the `std::exception_ptr` object that captures the exception is destructed. + +If a pointer is thrown, the responsibility for recycling the thrown object is unclear. Whether you are obligated to perform the `delete` operation on the pointer where the exception is caught depends on how the object is allocated (for example, static variables, or allocation using `new`) and whether the object is shared. However, the pointer type itself does not indicate the life cycle or ownership of the object, and therefore it is impossible to determine whether the `delete` operation should be performed on the object. If the `delete` operation is not performed on the object that should be deleted, memory leaks occur. If the `delete` operation is performed on the object that should not be deleted, memory will be freed twice. + +**\[Noncompliant Code Example]** + +Do not throw pointers. + +```cpp +static SomeException exc1("reason 1"); + +try { + if (SomeFunction()) { + throw &exc1; // Noncompliant: This is the pointer to the static object, which should not be deleted. + } else { + throw new SomeException("reason 2"); // Noncompliant: The dynamically allocated object should be deleted. + } +} catch (const SomeException* e) { + delete e; // Noncompliant: It is uncertain whether the delete operation is required. +} +``` + +**\[Compliant Code Example]** + +Always throw the exception object itself. + +```cpp +try { + if (SomeFunction()) { + throw SomeException("reason 1"); + } else { + throw SomeException("reason 2"); + } +} catch (const SomeException& e) { + ... // Compliant. It can be determined that the delete operation is not required. +} +``` + +## Never throw exceptions from destructors + +**\[Description]** + +By default, destructors have the `noexcept` attribute. If they throw exceptions, `std::terminate` will be present. Since C++ 11, destructors can be marked as `noexcept(false)`. However, if a destructor is called during stack unwinding (for example, another exception is thrown, causing local variables on the stack to be destructed), `std::terminate` occurs. The destructors are mostly used to deallocate local variables regardless of whether the return value is normal or whether an exception is thrown. Therefore, it is generally not good to throw exceptions from destructors. + +# Standard Library + +## Do not create a std::string from a null pointer + +**\[Description]** +The null pointer is dereferenced when it is passed to the std::string constructor, causing undefined behavior. + +**\[Noncompliant Code Example]** + +```cpp +void Foo() +{ + const char* path = std::getenv("PATH"); + std::string str(path); // Error: No check on whether the return value of getenv is nullptr + std::cout << str << std::endl; +} +``` + +**\[Compliant Code Example]** + +```cpp +void Foo() +{ + const char* path = std::getenv("PATH"); + if (path == nullptr) { + ... // Error reporting + return; + } + std::string str(path); + ... + std::cout << str << std::endl; +} +void Foo() +{ + const char* path = std::getenv("PATH"); + std::string str(path == nullptr ? path : ""); + ... // Check on the null string + std::cout << str << std::endl; // Check on the null string if necessary +} +``` + +## Do not save the pointers returned by the **c\_str()** and **data()** member functions of std::string + +**\[Description]** +To ensure the validity of the reference values returned by the **c\_str()** and **data()** member functions of the std::string object, do not save the **c\_str()** and **data()** results of std::string. Instead, call them directly when needed (the call overhead is optimized through compiler inlining). Otherwise, when the std::string object is modified by calling its modify method, or when the std::string object is out of the scope, the stored pointer becomes invalid. Using an invalid pointer will result in undefined behavior. + +**\[Noncompliant Code Example]** + +```cpp +void Bar(const char* data) +{ + ... +} + +void Foo1() +{ + std::string name{"demo"}; + const char* text = name.c_str(); // After the expression ends, the life cycle of name is still in use and the pointer is valid. + + // If a non-const member function (such as operator[] and begin()) of std::string is called and the name is therefore modified, + // the text content may become unavailable or may not be the original character string. + name = "test"; + name[1] = '2'; + ... + Bar(text); // The text no longer points to the valid memory space. +} + +void Foo2() +{ + std::string name{"demo"}; + std::string test{"test"}; + const char* text = (name + test).c_str(); // After the expression ends, the temporary object generated by the + operator is destroyed. + ... + Bar(text); // The text no longer points to the valid memory space. +} + +void Foo3(std::string& s) +{ + const char* data = s.data(); + ... + s.replace(0, 3, "***"); + ... + Bar(data); // The data no longer points to the valid memory space. +} +``` + +**\[Compliant Code Example]** + +```cpp +void Foo1() +{ + std::string name{"demo"}; + + name = "test"; + name[1] = '2'; + ... + Bar(name.c_str()); +} + +void Foo2() +{ + std::string name{"demo"}; + std::string test{"test"}; + name += test; + ... + Bar(name.c_str()); +} + +void Foo3(std::string& s) +{ + ... + s.replace(0, 3, "***"); + ... + Bar(s.data()); +} +``` + +**\[Exception]** +In rare cases where high performance coding is required, you can temporarily save the pointer returned by the c\_str() method of std::string to match the existing functions which support only the input parameters of the `const char*` type. However, you should ensure that the life cycle of the std::string object is longer than that of the saved pointer, and that the std::string object is not modified within the life cycle of the saved pointer. + +## Ensure that the buffer for strings has sufficient space for character data and terminators, and that the string is null-terminated + +**\[Description]** +A C-style character string is a continuous sequence of characters, which is terminated by the first null character and contains the null character. + +When copying or storing a C-style string, ensure that the buffer has sufficient space to hold the character sequence including the null terminator, and that the string is null terminated. Otherwise, buffer overflows may occur. + +- Preferentially use std::string to indicate a string because it is easier to operate and more likely to be correctly used. This can prevent overflows and null-terminator missing due to improper use of C-style strings. +- When using the C-style strings provided by the C/C++ standard library for function operations, ensure that the input string is null terminated, that the string is not read or written beyond the string buffer, and that the string after the storage operation is null terminated. + +**\[Noncompliant Code Example]** + +```cpp +char buf[BUFFER_SIZE]; +std::cin >> buf; +void Foo(std::istream& in) +{ + char buffer[BUFFER_SIZE]; + if (!in.read(buffer, sizeof(buffer))) { // Note: in.read() does not ensure null termination. + ... // Error handling + return; + } + + std::string str(buffer); // Noncompliant: The string is not null terminated. + ... +} +void Foo(std::istream& in) +{ + std::string s; + in >> s; // Noncompliant: The length of the data to be read is not restricted, which may cause resource consumption or attacks. + ... +} +``` + +**\[Compliant Code Example]** + +```cpp +char buf[BUFFER_SIZE] = {0}; +std::cin.width(sizeof(buf) - 1); // The buffer length must be N–1 to reserve space for a null terminator. +std::cin >> buf; +void Foo(std::istream& in) +{ + char buffer[BUFFER_SIZE]; + + if (!in.read(buffer, sizeof(buffer)) { // Note: in.read() does not ensure null termination. + ... // Error handling + return; + } + + std::string str(buffer, in.gcount()); // Ensure that the std::string constructor reads only characters of a specified length. + ... +} +void Foo(std::istream& in) +{ + std::string s; + in.width(MAX_NEED_SIZE); + in >> s; // Compliant: The maximum length of the data to be read is restricted. + ... +} +``` + +**\[Impact]** +Setting no limits to the integer values in external data is likely to cause DoS, buffer overflows, information leaks, or arbitrary code execution. + +## Do not use std::string to store sensitive information + +**\[Description]** +The std::string class is a string management class defined in C++. If sensitive information (such as passwords) is operated using std::string, it may be scattered in memory during program running and cannot be cleared. + +**\[Noncompliant Code Example]** +In the following code example, the **Foo()** function obtains the password, saves it to the std::string variable **password**, and then passes it to the **VerifyPassword()** function. In this process, two copies of the password exist in memory. + +```cpp +bool VerifyPassword(std::string password) +{ + ... +} + +void Foo() +{ + std::string password = GetPassword(); + VerifyPassword(password); +} +``` + +**\[Impact]** +Sensitive information is not deleted in due time, which may cause information leaks. + +## Ensure that the external data used as container indexes or iterators is within the valid range + +**\[Description]** +External data is untrusted. When it is used as container or array indexes, ensure that its value is within the valid range of the elements that can be accessed by containers or arrays. When external data is used for iterator offset, ensure that the iterator offset value range is \[begin(), end()] of the container associated with the iterator (created from the begin() method of the container object c), that is, greater than or equal to c.begin() and less than or equal to c.end(). + +For a container (such as std::vector, std::set, or std::map) with the at() method, if the corresponding index is out of range or the key-value does not exist, the method throws an exception. If the index of the corresponding operator\[] is out of range, undefined behavior occurs. If the default key-value fails to be constructed when the corresponding key-value does not exist, undefined behavior also occurs. + +**\[Noncompliant Code Example]** + +```cpp +int main() +{ + // Obtain an integer (index) from external input. + int index; + if (!(std::cin >> index)) { + ... // Error handling + return -1; + } + + std::vector c{'A', 'B', 'C', 'D'}; + + // Noncompliant: The index range is not correctly verified, causing out-of-bounds read: Ensure that the index is within the range of the container element. + std::cout << c[index] << std::endl; + + // Noncompliant: Ensure that the index is within the range of the container or array element. + for (auto pos = std::cbegin(c) + index; pos < std::cend(c); ++pos) { + std::cout << *pos << std::endl; + } + return 0; +} +void Foo(size_t n) +{ + std::vector v{0, 1, 2, 3}; + + // n is the index transferred through an external API, which may cause out-of-bounds access. + for_each_n(v.cbegin(), n, [](int x) { std::cout << x; }); +} +``` + +**\[Compliant Code Example]** + +```cpp +int main() +{ + // Obtain an integer (index) from external input. + int index; + if (!(std::cin >> index)) { + ... // Error handling + return -1; + } + + // std::vector is used as an example. Code such as std::cbegin(c) also applies to std::string + // and C array (not applicable to the char* variable and the static character string represented by char*). + std::vector c{'A', 'B', 'C', 'D'}; + + try { + std::cout << c.at(index) << std::endl; // Compliant: When the index is out of range, the at() function throws an exception + } catch (const std::out_of_range& e) { + ... // Out-of-bounds exception handling + } + + // In subsequent code, the valid index must be used for container element index or iterator offset. + // The index range is correctly verified: The index is within the range of the container element. + if (index < 0 || index >= c.size()) { + ... // Error handling + return -1; + } + + std::cout << c[index] << std::endl; // Compliant: The index range has been validated. + + // Compliant: The index has been validated. + for (auto pos = std::cbegin(c) + index; pos < std::cend(c); ++pos) { + std::cout << *pos << std::endl; + } + return 0; +} +void Foo(size_t n) +{ + std::vector v{0, 1, 2, 3}; + + // Ensure that the iteration range [first, first + count) of for_each_n is valid. + if (n > v.size()) { + ... // Error handling + return; + } + for_each_n(v.cbegin(), n, [](int x) { std::cout << x; }); +} +``` + +## Use valid format strings when calling formatted input/output functions + +**\[Description]** +When using C-style formatted input/output functions, ensure that the format strings are valid and strictly match the corresponding parameter types. Otherwise, unexpected behavior occurs. + +In addition to C-style formatted input/output functions, similar functions in C must also use valid format strings, for example, the **std::format()** function in C++20. + +For a custom C-style formatted function, you can use the attributes supported by the compiler to automatically check its correctness. For example, the GCC can automatically check custom formatted functions (such as printf, scanf, strftime, and strfmon). For details, see Common Function Attributes in the GCC manual: + +```c +extern int CustomPrintf(void* obj, const char* format, ...) + __attribute__ ((format (printf, 2, 3))); +``` + +**\[Noncompliant Code Example]** +In the following code example, an integer is formatted into the macAddr variable, but macAddr is of the unsigned char type, and %x indicates a parameter of the int type. After the function is executed, out-of-bounds write occurs. + +```c +unsigned char macAddr[6]; +... +// The data format in macStr is e2:42:a4:52:1e:33. +int ret = sscanf(macStr, "%x:%x:%x:%x:%x:%x\n", + &macAddr[0], &macAddr[1], + &macAddr[2], &macAddr[3], + &macAddr[4], &macAddr[5]); +... +``` + +**\[Compliant Code Example]** +In the following code example, %hhx is used to ensure that the format string strictly matches the parameter type. + +```c +unsigned char macAddr[6]; +... +// The data format in macStr is e2:42:a4:52:1e:33. +int ret = sscanf(macStr, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx\n", + &macAddr[0], &macAddr[1], + &macAddr[2], &macAddr[3], + &macAddr[4], &macAddr[5]); +... +``` + +Note: It is not advised to use C library functions, such as **sscanf()** and **sprintf()**, in C++. You can use std::istringstream, std::ostringstream, and std::stringstream instead. + +**\[Impact]** +An incorrect format string may cause memory damage or abnormal program termination. + +## Ensure that the format parameter is not controlled by external data when a formatted input/output function is called + +**\[Description]** +When a formatted function is called, the **format** parameter provided or concatenated by external data will cause a string formatting vulnerability. Take the formatted output function of the C standard library as an example. When the **format** parameter is externally controllable, an attacker can use the %n convertor to write an integer to a specified address, use the %x or %d convertor to view the stack or register content, or use the %s convertor to cause process crashes or other issues. + +Common formatted functions are as follows: + +- Formatted output functions: **sprintf()**, **vsprintf()**, **snprintf()**, **vsnprintf()**, etc. +- Formatted input functions: **sscanf()**, **vsscanf()**, **fscanf()**, **vscanf()**, etc. +- Formatted error message functions: **err()**, **verr()**, **errx()**, **verrx()**, **warn()**, **vwarn()**, **warnx()**, **vwarnx()**, **error()**, and **error\_at\_line()** +- Formatted log functions: **syslog()** and **vsyslog()** +- **std::format()** provided by C++20 + +When a formatted function is called, the constant string should be used as the format string. The format string must not be externally controllable: + +```cpp +Box v{MAX_COUNT}; +std::cout << std::format("{:#x}", v); +``` + +**\[Noncompliant Code Example]** +In the following code example, the **Log()** function is used to directly log external data, which may cause a format string vulnerability. + +```c +void Foo() +{ + std::string msg = GetMsg(); + ... + syslog(priority, msg.c_str()); // Noncompliant: A format string vulnerability exists. +} +``` + +**\[Compliant Code Example]** +The following practice is recommended: Use the %s converter to log external data to avoid the format string vulnerability. + +```c +void Foo() +{ + std::string msg = GetMsg(); + ... + syslog(priority, "%s", msg.c_str()); // Compliant: No format string vulnerability exists. +} +``` + +**\[Impact]** +If the format string is externally controllable, attackers can crash the process, view the stack content, view the memory content, or write data to any memory location, and then execute any code with the permission of the compromised process. + +## Do not use external controllable data as parameters for process startup functions or for the loading functions of dlopen/LoadLibrary and other modules + +**\[Description]** +Process startup functions in this requirement include **system()**, **popen()**, **execl()**, **execlp()**, **execle()**, **execv()**, and **execvp()**. Each of these functions such as **system()** and **popen()** will create a process. If external controllable data is used as the parameters of these functions, injection vulnerabilities may occur. When functions such as **execl()** are used to execute new processes, command injection risks also exist if shell is used to start new processes. The use of **execlp()**, **execvp()**, and **execvpe()** functions depends on the program paths searched using the system environment variable PATH. Consider the risks of external environment variables when using these functions, or avoid using these functions. + +Therefore, C standard functions are always preferred to implement the required functions. If you need to use these functions, use the trustlist mechanism to ensure that the parameters of these functions are not affected by any external data. + +The **dlopen()** and **LoadLibrary()** functions load external modules. If external controllable data is used as parameters of these functions, the modules prepared by attackers may be loaded. If these functions need to be used, take one of the following measures: + +- Use the trustlist mechanism to ensure that the parameters of these functions are not affected by any external data. +- Use the digital signature mechanism to protect the modules to be loaded, ensuring their integrity. +- After the security of the dynamic library loaded locally is ensured by means of permission and access control, the dynamic library is automatically loaded using a specific directory. +- After the security of the local configuration file is ensured by means of permission and access control, the dynamic library specified in the configuration file is automatically loaded. + +**\[Noncompliant Code Example]** +In the following code example, external controllable data is directly used as the parameter of the **LoadLibrary()** function, which may implant Trojan horses into the program. + +```c +char* msg = GetMsgFromRemote(); +LoadLibrary(msg); +``` + +In the following code example, the external **cmd** command is executed by the **system()** function. Attackers can execute any command: + +```c +std::string cmd = GetCmdFromRemote(); +system(cmd.c_str()); +``` + +In the following code example, a part of the **cmd** command executed by the **system()** function is external data. An attacker may enter `some dir;reboot` to cause system reboot: + +```cpp +std::string name = GetDirNameFromRemote(); +std::string cmd{"ls " + name}; +system(cmd.c_str()); +``` + +When using **exec()** functions to prevent command injection, do not use command parsers (such as **/bin/sh**) for the **path** and **file** parameters in the functions. + +```c +int execl(const char* path, const char* arg, ...); +int execlp(const char* file, const char* arg, ...); +int execle(const char* path, const char* arg, ...); +int execv(const char* path, char* const argv[]); +int execvp(const char* file, char* const argv[]); +int execvpe(const char* file, char* const argv[], char* const envp[]); +``` + +For example, do not use the following methods: + +```c +std::string cmd = GetDirNameFromRemote(); +execl("/bin/sh", "sh", "-c", cmd.c_str(), nullptr); +``` + +You can use library functions or write a small amount of code to avoid using the **system()** function to call commands. For example, the `mkdir()` function can implement the function of the `mkdir` command. In the following code, avoid using the `cat` command to copy file content. + +```c +int WriteDataToFile(const char* dstFile, const char* srcFile) +{ + ... // Argument validation + std::ostringstream oss; + oss << "cat " << srcFile << " > " << dstFile; + + std::string cmd{oss.str()}; + system(cmd.c_str()); + ... +} +``` + +**\[Compliant Code Example]** + +Some command functions can be implemented through a small amount of coding. The following code implements the file copy function to avoid calling the `cat` or `cp` command. Note that the following code does not consider the impact of signal interruption for easy description. + +```cpp +bool WriteDataToFile(const std::string& dstFilePath, const std::string& srcFilePath) +{ + const int bufferSize = 1024; + std::vector buffer (bufferSize + 1, 0); + + std::ifstream srcFile(srcFilePath, std::ios::binary); + std::ofstream dstFile(dstFilePath, std::ios::binary); + + if (!dstFile || !dstFile) { + ... // Error handling + return false; + } + + while (true) { + // Read the block content from srcFile. + srcFile.read(buffer.data(), bufferSize); + std::streamsize size = srcFile ? bufferSize : srcFile.gcount(); + + // Write the block content to dstFile. + if (size > 0 && !dstFile.write(buffer.data(), size)) { + ... // Error handling + break; + } + + if (!srcFile) { + ... // Error check: An error is recorded before eof() is returned. + break; + } + } + // srcFile and dstFile are automatically closed when they exit the scope. + return true; +} +``` + +Avoid calling the command processor to execute external commands if functionality can be implemented by using library functions (as shown in the preceding example). If a single command needs to be called, use the **exec\*** function for parameterized calling and implement trustlist management on the called command. In addition, avoid using the **execlp()**, **execvp()**, and **execvpe()** functions because these functions depend on the external PATH environment variable. In this case, the externally input **fileName** is only used as a parameter of the **some\_tool** command, posing no command injection risks. + +```cpp +pid_t pid; +char* const envp[] = {nullptr}; +... +std::string fileName = GetDirNameFromRemote(); +... +pid = fork(); +if (pid < 0) { + ... +} else if (pid == 0) { + // Use some_tool to process the specified file. + execle("/bin/some_tool", "some_tool", fileName.c_str(), nullptr, envp); + _Exit(-1); +} +... +int status; +waitpid(pid, &status, 0); +std::ofstream ofs(fileName, std::ios::in); +... +``` + +When the system command parsers (such as system) must be used to execute commands, the entered command strings must be checked based on an appropriate trustlist to prevent command injection. + +```cpp +std::string cmd = GetCmdFromRemote(); + +// Use the trustlist to check whether the command is valid. Only the "some_tool_a" and "some_tool_b" commands are allowed, and external control is not allowed. +if (!IsValidCmd(cmd.c_str())) { + ... // Error handling +} +system(cmd.c_str()); +... +``` + +**\[Impact]** + +- If the command string passed to **system()**, **popen()**, or other command handler functions is externally controllable, an attacker may execute any command that exists in the system using the permission of the compromised process. +- If a dynamic library file is externally controllable, attackers can replace the dynamic library file, which may cause arbitrary code execution vulnerabilities in some cases. + +# Other C Coding Specifications + +## Do not apply the sizeof operator to function parameters of array type when taking the size of an array + +**\[Description]** + +The **sizeof** operator yields the size (in bytes) of its operand, which can be an expression or the parenthesized name of a type, for example, `sizeof(int)` or `sizeof(int *)`. Footnote 103 in section 6.5.3.4 of the C11 standard states that: + +> When applied to a parameter declared to have array or function type, the **sizeof** operator yields the size of the adjusted (pointer) type. + +Arguments declared as arrays in the argument list will be adjusted to pointers of corresponding types. For example, although the inArray argument in the `void Func(int inArray[LEN])` function is declared as an array, it is actually adjusted to an int pointer, that is, `void Func(int *inArray)`. As a result, `sizeof(inArray)` is equal to `sizeof(int *)` in this function, leading to unexpected result. For example, in the IA-32 architecture, `sizeof(inArray)` is 4, not the inArray size. + +**\[Noncompliant Code Example]**In the following code example, the **ArrayInit()** function is used to initialize array elements. This function has a parameter declared as `int inArray[]`. When this function is called, a 256-element integer array **data** is passed to it. The **ArrayInit()** function uses `sizeof(inArray) / sizeof(inArray[0])` to determine the number of elements in the input array. However, **inArray** is a function parameter and therefore has a pointer type. As a result, `sizeof(inArray)` is equal to `sizeof(int *)`. The expression `sizeof(inArray) / sizeof(inArray[0])` evaluates to 1, regardless of the length of the array passed to the **ArrayInit()** function, leading to unexpected behavior. + +```c +#define DATA_LEN 256 +void ArrayInit(int inArray[]) +{ + // Noncompliant: sizeof(inArray) is used to calculate the array size. + for (size_t i = 0; i < sizeof(inArray) / sizeof(inArray[0]); i++) { + ... + } +} + +void FunctionData(void) +{ + int data[DATA_LEN]; + + ... + ArrayInit(data); // Call ArrayInit() to initialize array data. + ... +} +``` + +**\[Compliant Code Example]** +In the following code example, the function definition is modified, an array size parameter is added, and the array size is correctly passed to the function. + +```c +#define DATA_LEN 256 +// Function description: Argument len is the length of inArray. +void ArrayInit(int inArray[], size_t len) +{ + for (size_t i = 0; i < len; i++) { + ... + } +} + +void FunctionData(void) +{ + int data[DATA_LEN]; + + ArrayInit(data, sizeof(data) / sizeof(data[0])); + ... +} +``` + +**\[Noncompliant Code Example]** +In the following code example, `sizeof(inArray)` does not equal `ARRAY_MAX_LEN * sizeof(int)`, because the **sizeof** operator, when applied to a parameter declared to have array type, yields the size of the adjusted (pointer) type even if the parameter declaration specifies a length. In this case, `sizeof(inArray)` is equal to `sizeof(int *)`. + +```c +#define ARRAY_MAX_LEN 256 + +void ArrayInit(int inArray[ARRAY_MAX_LEN]) +{ + // Noncompliant: sizeof(inArray), pointer size rather than array size, which is not as expected + for (size_t i = 0; i < sizeof(inArray) / sizeof(inArray[0]); i++) { + ... + } +} + +int main(void) +{ + int masterArray[ARRAY_MAX_LEN]; + + ... + ArrayInit(masterArray); + + return 0; +} +``` + +**\[Compliant Code Example]** +In the following code example, the specified array length is indicated by the **len** argument. + +```c +#define ARRAY_MAX_LEN 256 + +// Function description: Argument len is the length of the argument array. +void ArrayInit(int inArray[], size_t len) +{ + for (size_t i = 0; i < len; i++) { + ... + } +} + +int main(void) +{ + int masterArray[ARRAY_MAX_LEN]; + + ArrayInit(masterArray, ARRAY_MAX_LEN); + ... + + return 0; +} +``` + +## Do not perform the **sizeof** operation on pointer variables to obtain the array size + +**\[Description]** +Performing the **sizeof** operation on a pointer that is used as an array leads to an unexpected result. For example, in the variable definition `char *p = array` where array is defined as `char array[LEN]`, the result of the expression `sizeof(p)` is the same as that of `sizeof(char *)`, but not the size of the array. + +**\[Noncompliant Code Example]** +In the following code example, **buffer** is a pointer while **path** is an array. The programmer wants to clear the two memory segments. However, the programmer mistakenly writes the memory size as `sizeof(buffer)`, leading to an unexpected result. + +```c +char path[MAX_PATH]; +char *buffer = (char *)malloc(SIZE); +... + +... +memset(path, 0, sizeof(path)); + +// sizeof causes an unexpected result because its result will be the pointer size but not the buffer size. +memset(buffer, 0, sizeof(buffer)); +``` + +**\[Compliant Code Example]** +In the following code example, `sizeof(buffer)` is changed to the size of the requested buffer: + +```c +char path[MAX_PATH]; +char *buffer = (char *)malloc(SIZE); +... + +... +memset(path, 0, sizeof(path)); +memset(buffer, 0, SIZE); // Use the requested buffer size. +``` + +## Do not directly use external data to concatenate SQL statements + +**\[Description]** +An SQL injection vulnerability arises when an SQL query is dynamically altered to form an altogether different query. Execution of this altered query may result in information leaks or data tampering. The root cause of SQL injection is the use of external data to concatenate SQL statements. In C/C++, external data is used to concatenate SQL statements in the following scenarios (but not limited to): + +- Argument for calling **mysql\_query()** and **Execute()** when connecting to MySQL +- Argument for calling **dbsqlexec()** of the db-library driver when connecting to the SQL server +- SQL statement parameter for calling **SQLprepare()** of the ODBC driver when connecting to the database +- Argument for calling **otl\_stream()** and **otl\_column\_desc()** in OTL class library in C++ language +- Input argument for calling **ExecuteWithResSQL()** when connecting to the Oracle database in C++ language + +The following methods can be used to prevent SQL injection: + +- Use parameterized query (also known as a prepared statement): Parameterized query is a simple and effective way to prevent SQL injection and must be used preferentially. The databases MySQL and Oracle (OCI) support parameterized query. +- Use parameterized query (driven by ODBC): supported by Oracle, SQL server, PostgreSQL, and GaussDB databases. +- Verify external data (trustlist verification is recommended). +- Escape external SQL special characters. + +**\[Noncompliant Code Example]** +The following code concatenates user input without checking the input, causing SQL injection risks: + +```c +char name[NAME_MAX]; +char sqlStatements[SQL_CMD_MAX]; +int ret = GetUserInput(name, NAME_MAX); +... +ret = sprintf(sqlStatements, + "SELECT childinfo FROM children WHERE name= ‘%s’", + name); +... +ret = mysql_query(&myConnection, sqlStatements); +... +``` + +**\[Compliant Code Example]** +Use prepared statements for parameterized query to defend against SQL injection attacks: + +```c +char name[NAME_MAX]; +... +MYSQL_STMT *stmt = mysql_stmt_init(myConnection); +char *query = "SELECT childinfo FROM children WHERE name= ?"; +if (mysql_stmt_prepare(stmt, query, strlen(query))) { + ... +} +int ret = GetUserInput(name, NAME_MAX); +... +MYSQL_BIND params[1]; +(void)memset(params, 0, sizeof(params)); +... +params[0].bufferType = MYSQL_TYPE_STRING; +params[0].buffer = (char *)name; +params[0].bufferLength = strlen(name); +params[0].isNull = 0; + +bool isCompleted = mysql_stmt_bind_param(stmt, params); +... +ret = mysql_stmt_execute(stmt); +... +``` + +**\[Impact]** + +If the string of a concatenated SQL statement is externally controllable, attackers can inject specific strings to deceive programs into executing malicious SQL commands, causing information leakage, permission bypass, and data tampering. + +## Clear sensitive information from memory immediately after using it + +**\[Description]** +Sensitive information (such as passwords and keys) in memory must be cleared immediately after being used to prevent it from being obtained by attackers or accidentally disclosed to low-privilege users. Memory includes but is not limited to: + +- Dynamically allocated memory +- Statically allocated memory +- Automatically allocated (stack) memory +- Memory cache +- Disk cache + +**\[Noncompliant Code Example]** +Generally, memory data does not need to be cleared before memory resources are released to prevent extra overheads during running. Therefore, after memory resources are released, the data remains in memory. In this case, sensitive information in the data may be leaked accidentally. To prevent sensitive information leakage, you must clear sensitive information from memory before releasing memory resources. In the following code example, the sensitive information **secret** stored in the referenced dynamic memory is copied to the newly dynamically allocated buffer **newSecret**, and is finally released through **free()**. As data is not cleared before the memory block is released, the memory block may be reallocated to another part of the program, and sensitive information stored in **newSecret** may be accidentally disclosed. + +```c +char *secret = NULL; +/* + * Assume that secret points to sensitive information whose content is less than SIZE_MAX + * and ends with null. + */ + +size_t size = strlen(secret); +char *newSecret = NULL; +newSecret = (char *)malloc(size + 1); +if (newSecret == NULL) { + ... // Error handling +} else { + errno_t ret = strcpy(newSecret, secret); + ... // Process ret + + ... // Process newSecret... + + free(newSecret); + newSecret = NULL; +} +... +``` + +**\[Compliant Code Example]** +In the following code example, to prevent information leakage, clear the dynamic memory that contains sensitive information (by filling the memory space with '\\0') and then release it. + +```c +char *secret = NULL; +/* + * Assume that secret points to sensitive information whose content is less than SIZE_MAX + * and ends with null. + */ +size_t size = strlen(secret); +char *newSecret = NULL; +newSecret = (char *)malloc(size + 1); +if (newSecret == NULL) { + ... // Error handling +} else { + errno_t ret = strcpy(newSecret, secret); + ... // Process ret + + ... // Process newSecret... + + (void)memset(newSecret, 0, size + 1); + free(newSecret); + newSecret = NULL; +} +... +``` + +**\[Compliant Code Example]** +The following code is another scenario involving sensitive information clearance. After obtaining the password, the code saves the password to **password** for verification. After the password is used, `memset()` is used to clear the password. + +```c +int Foo(void) +{ + char password[MAX_PWD_LEN]; + if (!GetPassword(password, sizeof(password))) { + ... + } + if (!VerifyPassword(password)) { + ... + } + ... + (void)memset(password, 0, sizeof(password)); + ... +} +``` + +**NOTE**: Ensure that the code for clearing sensitive information is always valid even if the compiler has been optimized. + +For example, the following code uses an invalid statement in the optimized compiler. + +```c +int SecureLogin(void) +{ + char pwd[PWD_SIZE]; + if (RetrievePassword(pwd, sizeof(pwd))) { + ... // Password check and other processing + } + memset(pwd, 0, sizeof(pwd)); // Compiler optimizations may invalidate this statement. + ... +} +``` + +Some compilers do not execute the code during optimization if they consider the code do not change program execution results. Therefore, the **memset()** function may become invalid after optimization. + +If the compiler supports the **#pragma** instruction, the instruction can be used to instruct the compiler not to optimize. + +```c +void SecureLogin(void) +{ + char pwd[PWD_SIZE]; + if (RetrievePassword(pwd, sizeof(pwd))) { + ... // Password check and other processing + } + #pragma optimize("", off) + // Clear memory. + ... + #pragma optimize("", on) + ... +} +``` + +**\[Impact]** + +Failure to rapidly clear sensitive information may cause information leakage. + +## Create files with appropriate access permissions explicitly specified + +**\[Description]** +If no appropriate access permissions are explicitly specified when a file is created, unauthorized users may access the file, causing information leakage, file data tampering, and malicious code injection into the file. + +Although file access permissions depend on the file system, many file creation functions (POSIX **open()** functions, etc.) provide mechanisms to set (or influence) file access permissions. Therefore, when these functions are used to create files, appropriate file access permissions must be explicitly specified to prevent unintended access. + +**\[Noncompliant Code Example]** +The POSIX **open()** function is used to create a file but the access permission for the file is not specified, which may cause the file to be created with excessive access permissions. This may lead to vulnerabilities (e.g. CVE-2006-1174). + +```c +void Foo(void) +{ + int fd = -1; + char *filename = NULL; + + ... // Initialize filename. + + fd = open(filename, O_CREAT | O_WRONLY); // Access permission not explicitly specified + if (fd == -1) { + ... // Error handling + } + ... +} +``` + +**\[Compliant Code Example]** +Access permissions for the newly created file should be explicitly specified in the third argument to **open()**. Access permissions for a file can be set based on actual applications of the file. + +```c +void Foo(void) +{ + int fd = -1; + char *filename = NULL; + + ... // Initialize filename and specify its access permissions. + + // Explicitly specify necessary access permissions for a file. + int fd = open(filename, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR); + if (fd == -1) { + ... // Error handling + } + ... +} +``` + +**\[Impact]** + +Creating files with weak access permissions may cause unauthorized access to these files. + +## Canonicalize and validate file paths before using them + +**\[Description]** +File paths from external data must be validated. Otherwise, system files may be accessed randomly. However, direct validation is not allowed. The file paths must be canonicalized before validation because a file can be described and referenced by paths in various forms. For example, a file path can be an absolute path or a relative path, and the path name, directory name, or file name may contain characters (for example, "." or "..") that make validation difficult and inaccurate. In addition, the file may also be a symbolic link, which further obscures the actual location or identity of the file, making validation difficult and inaccurate. Therefore, file paths must be canonicalized to make it much easier to validate a path, directory, or file name, thereby improving validation accuracy. + +Because the canonical form may vary with operating systems and file systems, it is best to use a canonical form consistent with the current system features. + +Take an example as follows: + +```c +Canonicalize file paths coming from external data. Without canonicalization, attackers have chances to construct file paths for unauthorized access to files. +For example, an attacker can construct "../../../etc/passwd" to access any file. +``` + +**\[Noncompliant Code Example]** +In this noncompliant code example, **inputFilename** contains a file name that originates from a tainted source, and the file is opened for writing. Before this file name is used for file operations, it should be validated to ensure that it references an expected and valid file. Unfortunately, the file name referenced by **inputFilename** may contain special characters, such as directory characters, which make validation difficult or even impossible. In addition, **inputFilename** may contain a symbolic link to any file path. Even if the file name passes validation, it is invalid. In this scenario, even if the file name is directly validated, the expected result cannot be obtained. The call to **fopen()** may result in unintended access to a file. + +```c +... + +if (!verify_file(inputFilename) { // inputFilename is validated without being canonicalized. + ... // Error handling +} + +if (fopen(inputFilename, "w") == NULL) { + ... // Error handling +} + +... +``` + +**\[Compliant Code Example]** +Canonicalizing file names is difficult because it requires an understanding of the underlying file system. The POSIX **realpath()** function can help convert path names to a canonical form. According to Standard for Information Technology—Portable Operating System Interface (POSIX®), Base Specifications, Issue 7 \[IEEE Std 1003.1:2013]: + +- The **realpath()** function shall derive, from the pathname pointed to by **filename**, an absolute pathname that names the same file, whose resolution does not involve a dot (.), double dots (..), or symbolic links. Further verification, such as ensuring that two consecutive slashes or special files do not appear in the file name, must be performed after canonicalization. For more information about how to perform path name resolution, see section 4.12 "Pathname Resolution" of IEEE Std 1003.1:2013. There are many precautions for using the **realpath()** function. With an understanding of the preceding principles, the following solution can be taken to address the noncompliant code example. + +```c +char *realpathRes = NULL; + +... + +// Canonicalize inputFilename before validation. +realpathRes = realpath(inputFilename, NULL); +if (realpathRes == NULL) { + ... // Canonicalization error handling +} + +// Validate the file path after canonicalizing it +if (!verify_file(realpathRes) { + ... // Validation error handling +} + +// Use +if (fopen(realpathRes, "w") == NULL) { + ... // Operation error handling +} + +... + +free(realpathRes); +realpathRes = NULL; +... +``` + +**\[Compliant Code Example]** +Based on the actual scenario, a second solution can also be used. The description is as follows: If `PATH_MAX` is defined as a constant in **limits.h**, it is also safe to call **realpath()** with a non-null `resolved_path` value. In this example, the **realpath()** function expects `resolved_path` to refer to a character array that is large enough to hold the canonicalized path. If **PATH\_MAX** is defined, allocate a buffer of size `PATH_MAX` to hold the result of **realpath()**. The compliant code example is as follows: + +```c +char *realpathRes = NULL; +char *canonicalFilename = NULL; +size_t pathSize = 0; + +... + +pathSize = (size_t)PATH_MAX; + +if (VerifyPathSize(pathSize) == true) { + canonicalFilename = (char *)malloc(pathSize); + + if (canonicalFilename == NULL) { + ... // Error handling + } + + realpathRes = realpath(inputFilename, canonicalFilename); +} + +if (realpathRes == NULL) { + ... // Error handling +} + +if (VerifyFile(realpathRes) == false) { + ... // Error handling +} + +if (fopen(realpathRes, "w") == NULL ) { + ... // Error handling +} + +... + +free(canonicalFilename); +canonicalFilename = NULL; +... +``` + +**\[Noncompliant Code Example]** +The following code obtains file names from external data, concatenates them into a file path, and directly reads the file content. As a result, attackers can read the content of any file. + +```c +char *filename = GetMsgFromRemote(); +... +int ret = sprintf(untrustPath, "/tmp/%s", filename); +... +char *text = ReadFileContent(untrustPath); +``` + +**\[Compliant Code Example]** +Canonicalize the file path and then check whether the path is valid in the program. + +```c +char *filename = GetMsgFromRemote(); +... +sprintf(untrustPath, "/tmp/%s", filename); +char path[PATH_MAX]; +if (realpath(untrustPath, path) == NULL) { + ... // Error handling +} +if (!IsValidPath(path)) { // Check whether the file path is valid. + ... // Error handling +} +char *text = ReadFileContent(path); +``` + +**\[Exception]** + +File paths can be manually entered on the console where the command line program runs. + +```c +int main(int argc, char **argv) +{ + int fd = -1; + + if (argc == 2) { + fd = open(argv[1], O_RDONLY); + ... + } + + ... + return 0; +} +``` + +**\[Impact]** + +Failure to canonicalize and validate untrusted file paths may cause access to any file. + +## Do not create temporary files in shared directories + +**\[Description]** +A shared directory refers to a directory that can be accessed by non-privileged users. The temporary files of a program must be exclusively used by the program. If you place the temporary files of the program in the shared directory, other sharing users may obtain additional information about the program, resulting in information leakage. Therefore, do not create temporary files that are used only by a program itself in any shared directory. + +Temporary files are commonly used for auxiliary storage of data that cannot reside in memory or temporary data and also as a means of inter-process communication (by transmitting data through the file system). For example, one process creates a temporary file with a well-known name or a temporary name in a shared directory. The file can then be used to share information among processes. This practice is dangerous because files in a shared directory can be easily hijacked or manipulated by an attacker. Mitigation strategies include the following: + +1. Use other low-level inter-process communication (IPC) mechanisms, such as sockets or shared memory. +2. Use higher-level IPC mechanisms, such as remote procedure call (RPC). +3. Use secure directories that can be accessed only by a program itself (Avoid race conditions in the case of multiple threads or processes.) + +The following lists several methods for creating temporary files. Product teams can use one or more of these methods as required or customize their own methods. + +1. Files must have appropriate permissions so that they can be accessed only by authorized users. +2. The name of a created file is unique or unpredictable. +3. Files can be created and opened only if the files do not exist (atomic create and open). +4. Open the files with exclusive access to avoid race conditions. +5. Remove files before the program exits. + +In addition, when two or more users or a group of users have read/write permission to a directory, the potential security risk of the shared directory is far greater than that of the access to temporary files in the directory. + +Creating temporary files in a shared directory is vulnerable. For example, code that works for a locally mounted file system may be vulnerable when shared with a remotely mounted file system. The secure solution is not to create temporary files in shared directories. + +**\[Noncompliant Code Example]** +The program creates a temporary file with a hard-coded file name in the shared directory **/tmp** to store temporary data. Because the file name is hard-coded and consequently predictable, an attacker only needs to replace the file with a symbolic link. The target file referenced by the link is then opened and new content can be written. + +```c +void ProcData(const char *filename) +{ + FILE *fp = fopen(filename, "wb+"); + if (fp == NULL) { + ... // Error handling + } + + ... // Write a file. + + fclose(fp); +} + +int main(void) +{ + // Noncompliant: 1. A temporary file is created in shared directories. 2. The temporary file name is hard-coded. + char *pFile = "/tmp/data"; + ... + + ProcData(pFile); + + ... + return 0; +} +``` + +****\[Compliant Code Example]**** + +```c +Do not create temporary files that are used only by a program itself in this directory. +``` + +**\[Impact]** + +Creating temporary files in an insecure manner may cause unauthorized access to the files and privilege escalation in the local system. + +## Do not access shared objects in signal handlers + +**\[Description]** +Accessing or modifying shared objects in signal handlers can result in race conditions that can leave data in an uncertain state. This rule is not applicable to the following scenarios (see paragraph 5 in section 5.1.2.3 of the C11 standard): + +- Read/write operations on lock-free atomic object +- Read/write operations on objects of the **volatile sig\_atomic\_t** type. An object of the **volatile sig\_atomic\_t** type can be accessed as an atomic entity even in the presence of asynchronous interrupts, and is asynchronous-safe. + +**\[Noncompliant Code Example]** +In the signal handler, the program attempts to use `g_msg` as the shared object and update the shared object when the SIGINT signal is delivered. However, `g_msg` is not a variable of type `volatile sig_atomic_t`, and is not asynchronous-safe. + +```c +#define MAX_MSG_SIZE 32 +static char g_msgBuf[MAX_MSG_SIZE] = {0}; +static char *g_msg = g_msgBuf; + +void SignalHandler(int signum) +{ + // It is noncompliant to use g_msg because it is not asynchronous-safe. + (void)memset(g_msg,0, MAX_MSG_SIZE); + errno_t ret = strcpy(g_msg, "signal SIGINT received."); + ... // Process ret +} + +int main(void) +{ + errno_t ret = strcpy(g_msg, "No msg yet."); // Initialize message content. + ... // Process ret + + signal(SIGINT, SignalHandler); // Set the SIGINT signal handler. + + ... // Main code loop + + return 0; +} +``` + +**\[Compliant Code Example]** +In the following code example, only the `volatile sig_atomic_t` type is used as a shared object in signal handlers. + +```c +#define MAX_MSG_SIZE 32 +volatile sig_atomic_t g_sigFlag = 0; + +void SignalHandler(int signum) +{ + g_sigFlag = 1; // Compliant +} + +int main(void) +{ + signal(SIGINT, SignalHandler); + char msgBuf[MAX_MSG_SIZE]; + errno_t ret = strcpy(msgBuf, "No msg yet."); // Initialize message content. + ... // Process ret + + ... // Main code loop + + if (g_sigFlag == 1) { // Update message content based on g_sigFlag status after exiting the main loop. + ret = strcpy(msgBuf, "signal SIGINT received."); + ... // Process ret + } + + return 0; +} +``` + +**\[Impact]** + +Accessing or modifying shared objects in signal handlers may cause inconsistent status access data. + +## Do not use rand() to generate pseudorandom numbers for security purposes + +**\[Description]** +The **rand()** function in the C language standard library generates pseudorandom numbers, which does not ensure the quality of the random sequence produced. In the C11 standard, the range of random numbers generated by the **rand()** function is `[0, RAND_MAX(0x7FFF)]`, which has a relatively short cycle, and the numbers can be predictable. Therefore, do not use the random numbers generated by the **rand()** function for security purposes. Use secure random number generation methods. + +Typical scenarios for security purposes include but are not limited to the following: + +- Generation of session IDs; +- Generation of random numbers in the challenge algorithm; +- Generation of random numbers of verification codes; +- Generation of random numbers for cryptographic algorithm purposes (for example, generating IVs, salt values, and keys). + +**\[Noncompliant Code Example]** +The programmer wants the code to generate a unique HTTP session ID that is not predictable. However, the ID is a random number produced by calling the **rand()** function, and is predictable and has limited randomness. + +**\[Impact]** + +Using the **rand()** function may result in random numbers that are predictable. + +## Do not output the address of an object or function in a released version + +**\[Description]** +Do not output the address of an object or function in a released version. For example, do not output the address of a variable or function to a client, log, or serial port. + +Before launching an advanced attack, the attacker usually needs to obtain the memory address (such as the variable address and function address) of the target program and then modify the content of the specified memory for attacks. If the program itself outputs the addresses of objects or functions, the attacker can take this advantage and use these addresses and offsets to calculate the addresses of other objects or functions and launch attacks. In addition, the protection function of address space randomization also fails due to memory address leakage. + +**\[Noncompliant Code Example]** +In the following code example, the address to which the pointer points is logged in the %p format. + +```c +int Encode(unsigned char *in, size_t inSize, unsigned char *out, size_t maxSize) +{ + ... + Log("in=%p, in size=%zu, out=%p, max size=%zu\n", in, inSize, out, maxSize); + ... +} +``` + +Note: This example uses only the %p format for logging pointers. In scenarios where pointers are converted to integers and then logged, the same risk exists. + +**\[Compliant Code Example]** +In the following code example, the code for logging the address is deleted. + +```c +int Encode(unsigned char *in, size_t inSize, unsigned char *out, size_t maxSize) +{ + ... + Log("in size=%zu, max size=%zu\n", inSize, maxSize); + ... +} +``` + +**\[Exception]** +When the program crashes and exits, the memory address and other information can be output in the crash exception information. + +**\[Impact]** + +Memory address leakage creates vulnerabilities to adversaries, probably leading to an address space randomization protection failure. + +## Do not include public IP addresses in code + +**\[Description]** + +If the public IP addresses that are invisible and unknown to users are included in code or scripts, customers may doubt code security. + +Public network addresses (including public IP addresses, public URLs/domain names, and email addresses) contained in the released software (including software packages and patch packages) must meet the following requirements: 1\. Do not contain any public network address that is invisible on UIs or not disclosed in product documentation. 2\. Do not write disclosed public IP addresses in code or scripts. They can be stored in configuration files or databases. + +The public IP addresses built in open-source or third-party software must meet the first requirement at least. + +**\[Exception]** + +- This requirement is not mandatory when public network addresses must be specified as required by standard protocols. For example, an assembled public network URL must be specified for the namespace of functions based on the SOAP protocol. W3.org addresses on HTTP pages are also exceptions. + +# Secure Kernel Coding + +## Ensure that the mapping start address and space size in kernel mmap are validated + +**\[Description]** + +**Note:** In the mmap interface of the kernel, the **remap\_pfn\_range()** function is often used to map the physical memory of a device to a user process space. If the parameters (such as the mapping start address) are controlled by the user mode and no validation is performed, the user mode can read and write any kernel address through the mapping. An attacker can even construct arguments to run arbitrary code in the kernel. + +**\[Noncompliant Code Example]** + +When **remap\_pfn\_range()** is used for memory mapping in the following code, the user-controllable mapping start address and space size are not validated. As a result, the kernel may crash or any code may be executed. + +```c +static int incorrect_mmap(struct file *file, struct vm_area_struct *vma) +{ + unsigned long size; + size = vma->vm_end - vma->vm_start; + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); + // Error: The mapping start address and space size are not validated. + if (remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff, size, vma->vm_page_prot)) { + err_log("%s, remap_pfn_range fail", __func__); + return EFAULT; + } else { + vma->vm_flags &= ~VM_IO; + } + + return EOK; +} +``` + +**\[Compliant Code Example]** + +Add the validity check on parameters such as the mapping start address. + +```c +static int correct_mmap(struct file *file, struct vm_area_struct *vma) +{ + unsigned long size; + size = vma->vm_end - vma->vm_start; + // Modification: Add a function to check whether the mapping start address and space size are valid. + if (!valid_mmap_phys_addr_range(vma->vm_pgoff, size)) { + return EINVAL; + } + + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); + if (remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff, size, vma->vm_page_prot)) { + err_log( "%s, remap_pfn_range fail ", __func__); + return EFAULT; + } else { + vma->vm_flags &= ~VM_IO; + } + + return EOK; +} +``` + +## Kernel programs must use kernel-specific functions to read and write user-mode buffers + +**\[Description]** + +During data exchange between the user mode and kernel mode, if no check (such as address range check and null pointer check) is performed in the kernel and the user mode input pointer is directly referenced, the kernel may crash and any address may be read or written when an invalid pointer is input in the user mode. Therefore, do not use unsafe functions such as **memcpy()** and **sprintf()**. Instead, use the dedicated functions provided by the kernel, such as **copy\_from\_user()**, **copy\_to\_user()**, **put\_user()**, and **get\_user()**, to read and write the user-mode buffer. Input validation is added to these functions. + +The forbidden functions are **memcpy()**, **bcopy()**, **memmove()**, **strcpy()**, **strncpy()**, **strcat()**, **strncat()**, **sprintf()**, **vsprintf()**, **snprintf()**, **vsnprintf()**, **sscanf()** and **vsscanf()**. + +**\[Noncompliant Code Example]** + +The kernel mode directly uses the buf pointer input by the user mode as the argument of **snprintf()**. When **buf** is **NULL**, the kernel may crash. + +```c +ssize_t incorrect_show(struct file *file, char__user *buf, size_t size, loff_t *data) +{ + // Error: The user-mode pointer is directly referenced. If the value of buf is NULL, a null pointer causes kernel crashes. + return snprintf(buf, size, "%ld\n", debug_level); +} +``` + +**\[Compliant Code Example]** + +Use the **copy\_to\_user()** function instead of **snprintf()**. + +```c +ssize_t correct_show(struct file *file, char __user *buf, size_t size, loff_t *data) +{ + int ret = 0; + char level_str[MAX_STR_LEN] = {0}; + snprintf(level_str, MAX_STR_LEN, "%ld \n", debug_level); + if(strlen(level_str) >= size) { + return EFAULT; + } + + // Modification: Use the dedicated function copy_to_user() to write data to the user-mode buf and prevent buffer overflow. + ret = copy_to_user(buf, level_str, strlen(level_str)+1); + return ret; +} +``` + +**\[Noncompliant Code Example]** + +The pointer **user\_buf** transferred in user mode is used as the data source to perform the **memcpy()** operation in kernel mode. When **user\_buf** is **NULL**, the kernel may crash. + +```c +size_t incorrect_write(struct file *file, const char __user *user_buf, size_t count, loff_t *ppos) +{ + ... + char buf [128] = {0}; + int buf_size = 0; + buf_size = min(count, (sizeof(buf)-1)); + // Error: The user-mode pointer is directly referenced. If user_buf is NULL, the kernel may crash. + (void)memcpy(buf, user_buf, buf_size); + ... +} +``` + +**\[Compliant Code Example]** + +Replace **memcpy()** with **copy\_from\_user()**. + +```c +ssize_t correct_write(struct file *file, const char __user *user_buf, size_t count, loff_t *ppos) +{ + ... + char buf[128] = {0}; + int buf_size = 0; + + buf_size = min(count, (sizeof(buf)-1)); + // Modification: Use the dedicated function copy_from_user() to write data to the kernel-mode buf and prevent buffer overflows. + if (copy_from_user(buf, user_buf, buf_size)) { + return EFAULT; + } + + ... +} +``` + +## Verify the copy length of **copy\_from\_user()** to prevent buffer overflows + +**Note:** The **copy\_from\_user()** function is used in kernel mode to copy data from the user mode. If the length of the copied data is not validated or is improperly validated, the kernel buffer overflows, causing kernel panic or privilege escalation. + +**\[Noncompliant Code Example]** + +The copy length is not validated. + +```c +static long gser_ioctl(struct file *fp, unsigned cmd, unsigned long arg) +{ + char smd_write_buf[GSERIAL_BUF_LEN]; + switch (cmd) + { + case GSERIAL_SMD_WRITE: + if (copy_from_user(&smd_write_arg, argp, sizeof(smd_write_arg))) {...} + // Error: The value of smd_write_arg.size is entered by the user and is not validated. + copy_from_user(smd_write_buf, smd_write_arg.buf, smd_write_arg.size); + ... + } +} +``` + +**\[Compliant Code Example]** + +Length validation is added. + +```c +static long gser_ioctl(struct file *fp, unsigned cmd, unsigned long arg) +{ + char smd_write_buf[GSERIAL_BUF_LEN]; + switch (cmd) + { + case GSERIAL_SMD_WRITE: + if (copy_from_user(&smd_write_arg, argp, sizeof(smd_write_arg))){...} + // Modification: Add validation. + if (smd_write_arg.size >= GSERIAL_BUF_LEN) {......} + copy_from_user(smd_write_buf, smd_write_arg.buf, smd_write_arg.size); + ... + } +} +``` + +## Initialize the data copied by **copy\_to\_user()** to prevent information leakage + +**\[Description]** + +**Note:** When **copy\_to\_user()** is used in kernel mode to copy data to the user mode, sensitive information (such as the pointer on the stack) may be leaked if the data is not completely initialized (for example, the structure member is not assigned a value, or the memory fragmentation is caused by byte alignment). Attackers can bypass security mechanisms such as Kaslr. + +**\[Noncompliant Code Example]** + +The data structure members are not completely initialized. + +```c +static long rmnet_ctrl_ioctl(struct file *fp, unsigned cmd, unsigned long arg) +{ + struct ep_info info; + switch (cmd) { + case FRMNET_CTRL_EP_LOOKUP: + info.ph_ep_info.ep_type = DATA_EP_TYPE_HSUSB; + info.ipa_ep_pair.cons_pipe_num = port->ipa_cons_idx; + info.ipa_ep_pair.prod_pipe_num = port->ipa_prod_idx; + // Error: The info structure has four members, not all of which are assigned with values. + ret = copy_to_user((void __user *)arg, &info, sizeof(info)); + ... + } +} +``` + +**\[Compliant Code Example]** + +Initialize all data. + +```c +static long rmnet_ctrl_ioctl(struct file *fp, unsigned cmd, unsigned long arg) +{ + struct ep_info info; + // Modification: Use memset to initialize the buffer to ensure that no memory fragmentation exists due to byte alignment or no value assignment. + (void)memset(&info, '0', sizeof(ep_info)); + switch (cmd) { + case FRMNET_CTRL_EP_LOOKUP: + info.ph_ep_info.ep_type = DATA_EP_TYPE_HSUSB; + info.ipa_ep_pair.cons_pipe_num = port->ipa_cons_idx; + info.ipa_ep_pair.prod_pipe_num = port->ipa_prod_idx; + ret = copy_to_user((void __user *)arg, &info, sizeof(info)); + ... + } +} +``` + +## Do not use the BUG\_ON macro in exception handling to avoid kernel panic + +**\[Description]** + +The BUG\_ON macro calls the **panic()** function of the kernel to print error information and suspend the system. In normal logic processing (for example, the **cmd** parameter of the **ioctl** interface cannot be identified), the system should not crash. Do not use the BUG\_ON macro in such exception handling scenarios. The WARN\_ON macro is recommended. + +**\[Noncompliant Code Example]** + +The BUG\_ON macro is used in the normal process. + +```c +/ * Determine whether the timer on the Q6 side is busy. 1: busy; 0: not busy */ +static unsigned int is_modem_set_timer_busy(special_timer *smem_ptr) +{ + int i = 0; + if (smem_ptr == NULL) { + printk(KERN_EMERG"%s:smem_ptr NULL!\n", __FUNCTION__); + // Error: The system BUG_ON macro calls panic() after printing the call stack, which causes kernel DoS and should not be used in normal processes. + BUG_ON(1); + return 1; + } + + ... +} +``` + +**\[Compliant Code Example]** + +Remove the BUG\_ON macro. + +```c +/ * Determine whether the timer on the Q6 side is busy. 1: busy; 0: not busy */ +static unsigned int is_modem_set_timer_busy(special_timer *smem_ptr) +{ + int i = 0; + if (smem_ptr == NULL) { + printk(KERN_EMERG"%s:smem_ptr NULL!\n", __FUNCTION__); + // Modification: Remove the BUG_ON call or use WARN_ON. + return 1; + } + + ... +} +``` + +## Do not use functions that may cause the process hibernation in the interrupt handler or in the context code of the process that holds the spin lock + +**\[Description]** + +Processes as the scheduling unit. In the interrupt context, only the interrupt with a higher priority can be interrupted. The system cannot schedule processes during interrupt processing. If the interrupt handler is in hibernation state, the kernel cannot be woken up, paralyzing the kernel. + +Spin locks disable preemption. If the spin lock enters the hibernation state after being locked, other processes will stop running because they cannot obtain the CPU (single-core CPU). In this case, the system does not respond and is suspended. + +Therefore, functions that may cause hibernation (such as **vmalloc()** and **msleep()**), block (such as **copy\_from\_user()**, **copy\_to\_user()**), or consume a large amount of time (such as **printk()**) should not be used in the interrupt processing program or the context code of the process that holds the spin lock. + +## Use the kernel stack properly to prevent kernel stack overflows + +**\[Description]** + +The kernel stack size is fixed (8 KB for a 32-bit system and 16 KB for a 64-bit system). Improper use of the kernel stack may cause stack overflows and system suspension. Therefore, the following requirements must be met: + +- The memory space requested on the stack cannot exceed the size of the kernel stack. +- Pay attention to the number of function nestings. +- Do not define excessive variables. + +**\[Noncompliant Code Example]** + +The variables defined in the following code are too large, causing stack overflows. + +```c +... +struct result +{ + char name[4]; + unsigned int a; + unsigned int b; + unsigned int c; + unsigned int d; +}; // The size of the result structure is 20 bytes. + +int foo() +{ + struct result temp[512]; + // Error: The temp array contains 512 elements. The total size is 10 KB, which is far greater than the kernel stack size. + (void)memset(temp, 0, sizeof(result) * 512); + ... // use temp do something + return 0; +} + +... +``` + +The **temp** array has 512 elements, and the total size is 10 KB, which is far greater than the kernel size (8 KB). The stack overflows obviously. + +**\[Compliant Code Example]** + +Use **kmalloc()** instead. + +```c +... +struct result +{ + char name[4]; + unsigned int a; + unsigned int b; + unsigned int c; + unsigned int d; +}; // The size of the result structure is 20 bytes. + +int foo() +{ + struct result *temp = NULL; + temp = (result *)kmalloc(sizeof(result) * 512, GFP_KERNEL); // Modification: Use kmalloc() to apply for memory. + ... // check temp is not NULL + (void)memset(temp, 0, sizeof(result) * 512); + ... // use temp do something + ... // free temp + return 0; +} +... +``` + +## Restore address validation after the operation is complete + +**\[Description]** + +The SMEP security mechanism prevents the kernel from executing the code in the user space (PXN is the SMEP of the ARM version). System calls (such as **open()** and **write()**) are originally provided for user space programs to access. By default, these functions validate the input address. If it is not a user space address, an error is reported. Therefore, disable address validation before using these system calls in a kernel program. **set\_fs()**/**get\_fs()** is used to address this problem. For details, see the following code: + +```c +... +mmegment_t old_fs; +printk("Hello, I'm the module that intends to write message to file.\n"); +if (file == NULL) { + file = filp_open(MY_FILE, O_RDWR | O_APPEND | O_CREAT, 0664); +} + +if (IS_ERR(file)) { + printk("Error occured while opening file %s, exiting ...\n", MY_FILE); + return 0; +} + +sprintf(buf, "%s", "The Message."); +old_fs = get_fs(); // get_fs() is used to obtain the upper limit of the user space address. + // #define get_fs() (current->addr_limit +set_fs(KERNEL_DS); // set_fs is used to increase the upper limit of the address space to KERNEL_DS so that the kernel code can call system functions. +file->f_op->write(file, (char *)buf, sizeof(buf), &file->f_pos); // The kernel code can call the write() function. +set_fs(old_fs); // Restore the address limit of the user space in time after use. +... +``` + +According to the preceding code, it is vital to restore address validation immediately after the operation is complete. Otherwise, the SMEP/PXN security mechanism will fail, making it easy to exploit many vulnerabilities. + +**\[Noncompliant Code Example]** + +The program error processing branch does not use **set\_fs()** to restore address validation. + +```c +... +oldfs = get_fs(); +set_fs(KERNEL_DS); +/* Create a done file in the timestamp directory. */ +fd = sys_open(path, O_CREAT | O_WRONLY, FILE_LIMIT); +if (fd < 0) { + BB_PRINT_ERR("sys_mkdir[%s] error, fd is[%d]\n", path, fd); + return; // Error: Address validation is not restored in the error processing program branch. +} + +sys_close(fd); +set_fs(oldfs); +... +``` + +**\[Compliant Code Example]** + +Address validation is restored in the error processing program. + +```c +... +oldfs = get_fs(); +set_fs(KERNEL_DS); + +/* Create a done file in the timestamp directory. */ +fd = sys_open(path, O_CREAT | O_WRONLY, FILE_LIMIT); +if (fd < 0) { + BB_PRINT_ERR("sys_mkdir[%s] error, fd is[%d] \n", path, fd); + set_fs(oldfs); // Modification: Restore address validation in the error processing program branch. + return; +} + +sys_close(fd); +set_fs(oldfs); +... +``` \ No newline at end of file diff --git a/website/docs/extras/en/contribute/OpenHarmony-cpp-coding-style-guide.md b/website/docs/extras/en/contribute/OpenHarmony-cpp-coding-style-guide.md new file mode 100644 index 0000000000000000000000000000000000000000..769b983de19c870d88b6d0e970e60bc4e946251a --- /dev/null +++ b/website/docs/extras/en/contribute/OpenHarmony-cpp-coding-style-guide.md @@ -0,0 +1,2931 @@ +--- +title: "OpenHarmony-cpp-coding-style-guide" +prepermalink: /extras/534acf231214287ea9f41e7094a836ec/ +permalink: /extras/534acf231214287ea9f41e7094a836ec/ +relpath: "OpenHarmony-3.1-Release/en/contribute/OpenHarmony-cpp-coding-style-guide.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [OpenHarmony-cpp-coding-style-guide] +--- +# C++ Coding Style Guide + +## Purpose +Rules are not perfect. They might disable useful features in specific situations and therefore affect code implementation. However, the purpose of developing rules is to get more benefits for most programmers. If a rule cannot be followed in your team operation, we can improve the rule together. +Before referring to this coding style guide, you are expected to have the following basic capabilities of the C++programming language: +1. Have a general knowledge of ISO standards for C++. +2. Be familiar with the basic features of C++, including those of C++ 03/11/14/17. +3. Have a general knowledge of the C++ standard library. + +## General Principles +Code must meet the requirements for readability, maintainability, security, reliability, testability, efficiency, and portability while ensuring functionality correctness. + +## Key Points +1. C++ programming style, such as naming and typesetting. +2. C++ modular design, including how to design header files, classes, interfaces, and functions. +3. Best practices of C++ features, including constants, type casting, resource management, and templates. +4. Best practices of modern C++, including conventions that can improve code maintainability and reliability in C++ 11/14/17. +5. This coding style guide is preferentially applicable to C++17. + +## Conventions +**Rule**: Conventions that must be followed during programming. + +**Rec**: Conventions that must be considered during programming. + +This document is applicable to standard C++ versions (C++ 03/11/14/17) unless otherwise specified. + +## Exceptions +It is necessary to understand the reason for these conventions and try to comply with them, no matter if they are rules or recommendations. +However, some rules and recommendations have exceptions. + +The only acceptable exceptions are those that do not violate the general principles and provide appropriate reasons for the exception. +Try to avoid exceptions because they affect the code consistency. Exceptions to 'Rules' should be very rare. + +The style consistency principle is preferred in the following case: +When you modify open-source or third-party code, comply with their respective code specifications. + +# 2 Naming +## General Naming Rules +__CamelCase__ +CamelCase is the practice of writing compound words or phrases so that each word or abbreviation in the phrase begins with a capital letter, and with no intervening spaces or punctuation. +There are two conventions: UpperCamelCase and lowerCamelCase. + + +| Type | Naming Style | +| ---------------------------------------- | ---------------------------------------- | +| Class, struct, enumeration, union, scope name| UpperCamelCase | +| Functions (including global functions, scope functions, and member functions) | UpperCamelCase | +| Global variables (including variables of the global and namespace scopes, and class static variables), local variables, function parameters, and class, struct, and union member variables | lowerCamelCase | +| Macro, constant, enumerated value, goto tag| All capitalized, separated by underscores (\_)| + +Note: +**Constant** in the above table refers to the variable that is of the basic data type, enumeration type, and string type and modified by **const** or **constexpr** under the global scope, the namespace scope, and the scope of a static member of a class, excluding arrays and other variables. +**Variable** indicates the variables excluding those defined in **Constant**. These variables use the lowerCamelCase style. + +## File Naming +### Rule 2.2.1 Use .cpp as the C++ file name extension and .h as the header file name extension. +It is recommended that you use .h as the file name extension of a header file so that the header file is compatible with C and C++. +It is recommended that you use .cpp as the file name extension of an implementation file. In this way, you can easily distinguish C++ code from C code. + +At present, there are some other file name extensions used by programmers: + +- Header files: .hh, .hpp, .hxx +- Implementation files: .cc, .cxx, .C + +If your project team uses a specific file name extension, you can continue to use it and keep the style consistent. +This document uses .h and .cpp extensions. + + +### Rule 2.2.2 Keep C++ file names the same as the class name. +The names of the C++ header file and the C++ implementation file must be the same as the class name. Use the unix\_like style and keep the style consistent. + +For example, if there is a class named DatabaseConnection, the corresponding file names are as follows: +- database_connection.h +- database_connection.cpp + +The naming rules of struct, namespace, and enumeration definition files are similar to the rules above. + +## Function Naming +Functions are named in the UpperCamelCase style. Generally, the verb or verb-object structure is used. +```cpp +class List { +public: + void AddElement(const Element& element); + Element GetElement(const unsigned int index) const; + bool IsEmpty() const; +}; + +namespace Utils { + void DeleteUser(); +} +``` + +## Type Naming + +Types are named in the UpperCamelCase style. +All types, such as classes, structs, unions, typedefs, and enumerations, use the same conventions. Example: +```cpp +// Classes, structs, and unions +class UrlTable { ... +class UrlTableTester { ... +struct UrlTableProperties { ... +union Packet { ... + +// typedefs +typedef std::map PropertiesMap; + +// Enums +enum UrlTableErrors { ... +``` + +For namespace naming, UpperCamelCase is recommended. +```cpp +// Namespaces +namespace OsUtils { + +namespace FileUtils { + +} + +} +``` + + +### Rec 2.4.1 Do not abuse typedef or #define to set alias for the basic data types. +Unless otherwise specified, do not use typedef or #define to redefine basic data types. +The basic data types found in the `` header file are preferable. + +| Signed Type | Unsigned Type | Description | +| ----------- | ------------- | ---------------------------------------- | +| int8_t | uint8_t | The signed or unsigned 8-bit integer type. | +| int16_t | uint16_t | The signed or unsigned 16-bit integer type. | +| int32_t | uint32_t | The signed or unsigned 32-bit integer type. | +| int64_t | uint64_t | The signed or unsigned 64-bit integer type. | +| intptr_t | uintptr_t | The signed or unsigned integer type large enough to hold a pointer. | + + +## Variable Naming +General variables, including global variables, function parameters, local variables, and member variables, are named in the lowerCamelCase style. +```cpp +std::string tableName; // Good: Recommended style. +std::string tablename; // Bad: Forbidden style. +std::string path; // Good: When there is only one word, lowerCamelCase (all lowercase) is used. +``` + +### Rule 2.5.1 Add the prefix 'g_' to global variables. Do not add a prefix to a static variable. +Global variables should be used as little as possible, and special attention should be paid to their use. This prefix highlights global variables so that developers can be more careful when handling them. +- Global static variables and global variables are named in the same way. +- Static variables in functions and common local variables are named in the same way. +- Static member variables in classes and common member variables are named in the same way. + +```cpp +int g_activeConnectCount; + +void Func() +{ + static int packetCount = 0; + ... +} +``` + +### Rule 2.5.2 Name member variables in classes in the unix\_like style. + +```cpp +class Foo { +private: + std::string fileName_; // Add the underscore (\_) as the suffix, similar to the K&R naming style. +}; +``` +Use the lowerCamelCase style and do not add prefixes or suffixes to name a member variable of the struct or union type. Keep the naming style consistent with that for a local variable. + +## Macro, Constant, and Enum Naming +Use uppercase letters separated by underscores (\_) for macro names and enumerated values. +In the global scope, constants of named and unnamed namespaces and static member constants should be capitalized and separated with underscores (\_).Local constants and ordinary const member variables use the lowerCamelCase naming style. + +```cpp +#define MAX(a, b) (((a) < (b))? (b): (a)) // Example of naming a macro only. + +enum BaseColor { // Note: The enum type name is in the UpperCamelCase style, whereas the enumerated value is in uppercase letters separated by underscores (\_). + RED, + DARK_RED, + GREEN, + LIGHT_GREEN +}; + +int Func(...) +{ + const unsigned int bufferSize = 100; // Local variable + char *p = new char[bufferSize]; + ... +} + +namespace Utils { + const unsigned int DEFAULT_FILE_SIZE_KB = 200; // Global variable +} + +``` + +# 3 Formatting + +## Line Length + +### Rule 3.1.1 Include 120 characters or less in each line. +If the line of code exceeds the permitted length, wrap the line appropriately. + +Exceptions: +- If a line of comment contains a command or URL of more than 120 characters, you can keep the line for easy copy, paste, and search using the grep command. +- The #include and #error statements are allowed to exceed the line length requirement. However, you should try to avoid this. +- The error information in preprocessor directives can exceed the permitted length. + Put the error information of preprocessor directives in one line to facilitate reading and understanding even if the line contains more than 120 characters. +```cpp +#ifndef XXX_YYY_ZZZ +#error Header aaaa/bbbb/cccc/abc.h must only be included after xxxx/yyyy/zzzz/xyz.h, because xxxxxxxxxxxxxxxxxxxxxxxxxxxxx +#endif +``` + +## Indentation + +### Rule 3.2.1 Use spaces to indent and indent 4 spaces at a time. +Only spaces can be used for indentation. Four spaces are indented each time. Do not use the Tab character to indent. +Currently, almost all integrated development environments (IDEs) support automatic conversion of a Tab input to four spaces. Configure your IDE to support indentation with spaces. + +## Braces +### Rule 3.3.1 Use the K&R indentation style. +__K&R style__ +While wrapping a line, the left brace of the function (excluding the lambda statement) starts a new line and takes a single line. Other left braces are placed at the end of the line along with the statement. +The right brace takes a single line, unless it is followed by the rest of the same statement, such as `while` in the `do` statement, `else` or `else if` in the `if` statement, a comma, or a semicolon. + +Example: +```cpp +struct MyType { // The left brace is placed at the end of the line along with the statement, and one space is used for indentation. + ... +}; + +int Foo(int a) +{ // The left brace of the function starts a new line, and nothing else is placed on the line. + if (...) { + ... + } else { + ... + } +} +``` +The reasons for recommending this style are as follows: + +- Code is more compact. +- Placing the brace at the end of the statement makes the code more continuous in reading rhythm than starting a new line. +- This style complies with mainstream norms and habits of programming languages. +- Most modern IDEs have an automatic code indentation, alignment and display. Placing the brace at the end of a line does not impact understanding. + + +If no function body is inside the braces, the braces can be put on the same line. +```cpp +class MyClass { +public: + MyClass() : value_(0) {} + +private: + int value_; +}; +``` + +## Function Declarations and Definitions + +### Rule 3.4.1 Keep the return type and function name of the function declaration or definition in the same line, and align the function parameter list appropriately if it needs to be wrapped. +When a function is declared and defined, the return value type of the function should be in the same line as the function name. When the function parameter list is wrapped, it should be aligned appropriately. +The left parenthesis of a parameter list is always in the same line as the function name. The right parenthesis always follows the last parameter. + +Example: +```cpp +ReturnType FunctionName(ArgType paramName1, ArgType paramName2) // Good: All are in the same line. +{ + ... +} + +ReturnType VeryVeryVeryLongFunctionName(ArgType paramName1, // Each added parameter starts on a new line because the line length limit is exceeded. + ArgType paramName2, // Good: aligned with the previous parameter. + ArgType paramName3) +{ + ... +} + +ReturnType LongFunctionName(ArgType paramName1, ArgType paramName2, // Parameters are wrapped because the line length limit is exceeded. + ArgType paramName3, ArgType paramName4, ArgType paramName5) // Good: After the line break, 4 spaces are used for indentation. +{ + ... +} + +ReturnType ReallyReallyReallyReallyLongFunctionName( // The line length cannot accommodate even the first parameter, and a line break is required. + ArgType paramName1, ArgType paramName2, ArgType paramName3) // Good: After the line break, 4 spaces are used for indentation. +{ + ... +} +``` + +## Function Calls +### Rule 3.5.1 A function call parameter list should be placed on one line. When the parameter list exceeds the line length and requires a line break, the parameters should be properly aligned. +A function call parameter list should be placed on one line. When the parameter list exceeds the line length and requires a line break, the parameters should be properly aligned. +The left parenthesis always follows the function name, and the right parenthesis always follows the last parameter. + +The following are examples of proper line breaks: +```cpp +ReturnType result = FunctionName(paramName1, paramName2); // Good: All function parameters are on one line. + +ReturnType result = FunctionName(paramName1, + paramName2, // Good: aligned with the previous parameter + paramName3); + +ReturnType result = FunctionName(paramName1, paramName2, + paramName3, paramName4, paramName5); // Good: Parameters are wrapped. After the line break, 4 spaces are used for indentation. + +ReturnType result = VeryVeryVeryLongFunctionName( // The line length cannot accommodate even the first parameter, and a line break is required. + paramName1, paramName2, paramName3); // After the line break, 4 spaces are used for indentation. +``` + +If some of the parameters called by a function are associated with each other, you can group them for better understanding. +```cpp +// Good: The parameters in each line represent a group of data structures with strong correlation. They are placed on a line for ease of understanding. +int result = DealWithStructureLikeParams(left.x, left.y, // A group of related parameters. + right.x, right.y); // Another group of related parameters. +``` + +## if Statements + +### Rule 3.6.1 Use braces to include an if statement. +We require that all if statements use braces, even if there is only one statement. + +Reasons: +- The logic is intuitive and easy to read. +- It is less prone to mistakes when new code is added to the existing if statement. +- If function-like macros are used in a conditional statement, it is less prone to mistakes (in case the braces are missing when macros are defined). + +```cpp +if (objectIsNotExist) { // Good: Braces are added to a single-line conditional statement. + return CreateNewObject(); +} +``` +### Rule 3.6.2 Place if, else, and else if keywords on separate lines. +If there are multiple branches in a conditional statement, they should be placed on separate lines. + +Good example: + +```cpp +if (someConditions) { + DoSomething(); + ... +} else { // Good: Put the if and else keywords on separate lines. + ... +} +``` + +Bad example: + +```cpp +if (someConditions) { ... } else { ... } // Bad: The if and else keywords are put on the same line. +``` + +## Loop Statements +### Rule 3.7.1 Use braces after loop statements. +Similar to if statements, we require that the for and while loop statements contain braces, even if the loop body is empty or there is only one loop statement. +```cpp +for (int i = 0; i < someRange; i++) { // Good: Braces are used. + DoSomething(); +} +``` +```cpp +while (condition) {} // Good: The while loop body is empty. Braces should be used. +``` +```cpp +while (condition) { + continue; // Good: The continue keyword highlights the end of the empty loop. Braces should be used. +} +``` + +Bad example: +```cpp +for (int i = 0; i < someRange; i++) + DoSomething(); // Bad: Braces are mandatory. +``` +```cpp +while (someCondition) ; // Bad: Using a semicolon here will make people misunderstand that it is a part of the while statement and not the end to it. +``` + +## Switch Statements +### Rule 3.8.1 Indent case and default in a switch statement with four spaces. +The indentation style of the switch statement is as follows: +```cpp +switch (var) { + case 0: // Good: Indented + DoSomething1(); // Good: Indented + break; + case 1: { // Good: Braces are added. + DoSomething2(); + break; + } + default: + break; +} +``` + +```cpp +switch (var) { +case 0: // Bad: case is not indented. + DoSomething(); + break; +default: // Bad: default is not indented. + break; +} +``` + +## Expressions + +### Rec 3.9.1 Keep a consistent line break style for expressions and ensure that operators are placed at the end of a line. +A long expression that does not meet the line length requirement must be wrapped appropriately. Generally, the expression is wrapped at an operator of a lower priority or a connector, and the operator or connector is placed at the end of the line. +Placing these at the end of a line indicates that the operation is to be continued on the next line. +Example: + +// Assume that the first line exceeds the length limit. +```cpp +if (currentValue > threshold && // Good: After the line break, the logical-AND operators are placed at the end of the line. + someConditionsion) { + DoSomething(); + ... +} + +int result = reallyReallyLongVariableName1 + // Good + reallyReallyLongVariableName2; +``` +After an expression is wrapped, ensure that the lines are aligned appropriately or indented with 4 spaces. See the following example. + +```cpp +int sum = longVaribleName1 + longVaribleName2 + longVaribleName3 + + longVaribleName4 + longVaribleName5 + longVaribleName6; // Good: indented with 4 spaces + +int sum = longVaribleName1 + longVaribleName2 + longVaribleName3 + + longVaribleName4 + longVaribleName5 + longVaribleName6; // Good: The lines are aligned. +``` +## Variable Assignment + +### Rule 3.10.1 Multiple variable definitions and assignment statements cannot be written on one line. +Each line should have only one variable initialization statement. It is easier to read and understand. + +```cpp +int maxCount = 10; +bool isCompleted = false; +``` + +Bad example: + +```cpp +int maxCount = 10; bool isCompleted = false; // Bad: Multiple variable initialization statements must be separated on different lines. Each variable initialization statement occupies one line. +int x, y = 0; // Bad: Multiple variable definitions must be separated on different lines. Each definition occupies one line. + +int pointX; +int pointY; +... +pointX = 1; pointY = 2; // Bad: Multiple variable assignment statements must be separated on different lines. +``` +Exception: Multiple variables can be declared and initialized in the for loop header, if initialization statement (C++17), and structured binding statement (C++17). Multiple variable declarations in these statements have strong associations. Forcible division into multiple lines may cause problems such as scope inconsistency and separation of declaration from initialization. + +## Initialization +Initialization is applicable to structs, unions, and arrays. + +### Rule 3.11.1 When an initialization list is wrapped, ensure that the line after the break is indented and aligned properly. +If a structure or array initialization list is wrapped, the line after the break is indented with four spaces. +Choose the wrap location and alignment style for best comprehension. + +```cpp +const int rank[] = { + 16, 16, 16, 16, 32, 32, 32, 32, + 64, 64, 64, 64, 32, 32, 32, 32 +}; +``` + +## Pointers and References +### Rec 3.12.1 The pointer type `*` follows a variable name or type. There can be only one space to the side of it. +Pointer naming: There can be only one space next to `*`. +```cpp +int* p = NULL; // Good +int *p = NULL; // Good + +int*p = NULL; // Bad +int * p = NULL; // Bad +``` + +Exception: When a variable is modified by const or restrict, `*` cannot follow the variable or type. +```cpp +const char * const VERSION = "V100"; +``` + +### Rec 3.12.2 The reference type `&` follows a variable name or type. There can be only one space to the side of it. +Reference naming: There can be only one space around `&`. +```cpp +int i = 8; + +int& p = i; // Good +int &p = i; // Good +int*& rp = pi; // Good: The reference type `*&` follows the type. +int *&rp = pi; // Good: The reference type `*&` follows the variable name. +int* &rp = pi; // Good: The pointer type `*` follows the type and the eference type `&` follows the variable name. + +int & p = i; // Bad +int&p = i; // Bad +``` + +## Compilation Preprocessing +### Rule 3.13.1 Place a number sign (#) at the beginning of a line for compilation preprocessing. In nested compilation preprocessing, the number sign (#) can be indented. +The number sign (#) must be placed at the beginning of a line for compilation preprocessing, even if the code is embedded in the function body. + +### Rule 3.13.2 Do not use macros. +Macros do not obey scope, type system, and other rules, and may easily lead to issues. Avoid macro definitions wherever possible. If you must use macros, give them unique names. +In C++, there are many ways to avoid using macros: +- Use `const` or `enum` to define constants that are easy to understand. +- Use namespaces to avoid name conflicts. +- Use the `inline` function to avoid function call overhead. +- Use the `template` function to handle multiple types. +Macros can be used in scenarios such as header guards, conditional compilation, and logging. + +### Rule 3.13.3 Do not use macros to represent constants. +Macros involve simple text replacement, which is completed during preprocessing. When an error occurs, the macro value is reported without the macro name. During tracing and debugging, the macro name is not displayed either. Besides, macros do not have type checking or scopes. + +### Rule 3.13.4 Do not use function-like macros. +Before defining a function-like macro, consider whether it can be replaced with a function. If yes, you are advised to use a function for replacement. +The disadvantages of the function-like macro are as follows: +- Function-like macros have no type check, which is not as strict as the function call check. +- If macro parameters are not evaluated during macro expansion, unexpected results may occur. +- A macro has no independent scope. +- There are high skill requirements on the proper use of macros (for example, the usage of `#` and wide use of parentheses), which reduces readability. +- Extensions of some macros can only be implemented by specific compilers in specific scenarios, such as `statement expression` of `gcc`, reducing the portability. +- After the macro is expanded during precompilation, it is invisible during subsequent compilation, linking, and debugging. Besides, macros that contain multiple lines are expanded into a line. Function-like macros are difficult to debug, set breakpoints, and locate in case of bugs. +- Macros containing a large number of statements must be expanded at each call point. If there are many call points, the code will be expanded. + +Unlike macros, functions do not have these disadvantages. However, the biggest disadvantage of functions is low execution efficiency (increasing the overhead of function calls and the difficulty of compiler optimization). +In light of this, you can use inline functions when necessary. Similar to macros, inline functions are expanded at the call point. The difference is that inline functions are expanded during compilation. + +Inline functions have the advantages of both functions and macros: +- Strict type checking is performed for inline functions. +- Parameters are evaluated only once for inline functions. +- Inline functions are expanded in place and there is no overhead for function calls. +- Inline functions are better optimized than standard functions. +For performance-sensitive code, consider using inline functions instead of standard functions. + +Exceptions: +In logging scenarios, only function-like macros can be used to keep information such as the file name (__FILE__) and line number (__LINE__) of the call point. + +## Whitespace +### Rule 3.14.1 Ensure that horizontal spaces are used to highlight keywords and important information, and avoid unnecessary whitespace. +Horizontal spaces are used to highlight keywords and important information. Spaces are not allowed at the end of each code line. The general rules are as follows: + +- Add spaces after keywords such as if, switch, case, do, while, and for. +- Do not add spaces after the left parenthesis or before the right parenthesis. +- For expressions enclosed by braces, either add a space on either side or avoid a space on either side. +- Do not add spaces after any unary operator (& * + - ~ !). +- Add a space to the left and right sides of each binary operator (= + -< > * /% | & ^ <= >= == !=). +- Add spaces to the left and right sides of a ternary operator (? :). +- Do not add spaces between a prefix or suffix increment (++) or decrement (--) operator and a variable. +- Do not add spaces before or after a struct member operator (. ->). +- Do not add spaces before commas. Add spaces after commas. +- Do not add spaces between a template or type conversion operator (<>) and a type. +- Do not add spaces before or after a domain operator (::). +- Determine whether to add spaces before and after a colon (:) based on the actual situation. + +In normal cases: +```cpp +void Foo(int b) { // Good: A space is added before the left brace. + +int i = 0; // Good: During variable initialization, there should be spaces before and after =. Do not leave a space before the semicolon. + +int buf[BUF_SIZE] = {0}; // Good: Spaces are not added in braces. +``` + +Function definition and call: +```cpp +int result = Foo(arg1,arg2); + ^ // Bad: A space should be added after the comma. + +int result = Foo( arg1, arg2 ); + ^ ^ // Bad: Spaces should not be added after the left parenthesis or before the right parenthesis. +``` + +Pointer and Address Operator +```cpp +x = *p; // Good: There is no space between the operator * and the pointer p. +p = &x; // Good: There is no space between the operator & and the variable x. +x = r.y; // Good: When a member variable is accessed through the operator (.), no space is added. +x = r->y; // Good: When a member variable is accessed through the operator (->), no space is added. +``` + +Other Operators: +```cpp +x = 0; // Good: There is a space before and after the assignment operator (=). +x = -5; // Good: There is no space between the minus sign (–) and the number. +++x; //Good: Do not add spaces between a prefix or suffix increment (++) or decrement (--) operator and a variable.. +x--; + +if (x && !y) // Good: There is a space before and after the Boolean operator. There is no space between the ! operator and the variable. +v = w * x + y / z; // Good: There is a space before and after the binary operator. +v = w * (x + z); // Good: There is no space before or after the expression in the parentheses. + +int a = (x < y) ? x : y; // Good: Ternary operator. There is a space before and after ? and : +``` + +Loops and Conditional Statements: +```cpp +if (condition) { // Good: There is a space between the if keyword and the left parenthesis, and no space before or after the conditional statement in the parentheses. + ... +} else { // Good: There is a space between the else keyword and the left brace. + ... +} + +while (conditions) {} // Good: There is a space between the while keyword and the left parenthesis. There is no space before or after the conditional statement in the parentheses. + +for (int i = 0; i < someRange; ++i) { // Good: There is a space between the for keyword and the left parenthesis, and after the semicolon. + ... +} + +switch (condition) { // Good: There is a space after the switch keyword. + case 0: // Good: There is no space between the case condition and the colon. + ... + break; + ... + default: + ... + break; +} +``` + +Templates and Conversions +```cpp +// Angle brackets (< and >) are not adjacent to space. There is no space before < or between > and (. +vector x; +y = static_cast(x); + +// There can be a space between the type and the pointer operator. Keep the spacing style consistent. +vector x; +``` + +Scope Operators +```cpp +std::cout; // Good: Namespace access. Do not leave spaces. + +int MyClass::GetValue() const {} // Good: Do not leave spaces in the definition of member functions. +``` + +Colons +```cpp +// Scenarios when space is required + +// Good: // Add a space before or after the colon in a derived class definition. +class Sub : public Base { + +}; + +// Add a space before or after the colon in the initialization list of a constructor function. +MyClass::MyClass(int var) : someVar_(var) +{ + DoSomething(); +} + +// Add a space before or after the colon in a bit-field. +struct XX { + char a : 4; + char b : 5; + char c : 4; +}; +``` + +```cpp +// Scenarios when space is not required + +// Good: // No space is added before or after the colon next to a class access permission (public or private). +class MyClass { +public: + MyClass(int var); +private: + int someVar_; +}; + +// No space is added before or after the colon in a switch statement. +switch (value) +{ + case 1: + DoSomething(); + break; + default: + break; +} +``` + +Note: Currently, all IDEs support automatic deletion of spaces at the end of a line. Please configure your IDE correctly. + +### Rec 3.14.1 Use blank lines only when necessary to keep code compact. + +There must be as few blank lines as possible so that more code can be displayed for easy reading. Recommendations: +- Add blank lines according to the correlation between lines. +- Consecutive blank lines are not allowed inside functions, type definitions, macros, and initialization expressions. +- A maximum of **two** consecutive blank lines can be used. +- Do not add blank lines on the first and last lines of a code block in braces. This recommendation is not applicable to code block in braces of a namespace. + +```cpp +int Foo() +{ + ... +} + + + +int bar() {// Bad: More than one blank lines are used between two function definitions. +{ + ... +} + + +if (...) { + // Bad: Do not add blank lines on the first and last lines of a code block. + ... + // Bad: Do not add blank lines on the first and last lines of a code block. +} + +int Foo(...) +{ + // Bad: Do not add blank lines before the first statement in a function body. + ... +} +``` + +## Classes +### Rule 3.15.1 Class access specifier declarations are in the sequence: public, protected, private. Indent these specifiers to the same level as the class keyword. +```cpp +class MyClass : public BaseClass { +public: // Not indented. + MyClass(); // Indented with 4 spaces. + explicit MyClass(int var); + ~MyClass() {} + + void SomeFunction(); + void SomeFunctionThatDoesNothing() + { + } + + void SetVar(int var) { someVar_ = var; } + int GetVar() const { return someVar_; } + +private: + bool SomeInternalFunction(); + + int someVar_; + int someOtherVar_; +}; +``` + +In each part, it is recommended that similar statements be put together and in the following order: Type (including typedef, using, nested structs and classes), Constant, Factory Function, Constructor, Assignment Operator, Destructor, Other Member Function, and Data Member + + +### Rule 3.15.2 The constructor initialization list must be on the same line or wrapped and aligned with four spaces of indentation. +```cpp +// If all variables can be placed on the same line +MyClass::MyClass(int var) : someVar_(var) +{ + DoSomething(); +} + +// If the variables cannot be placed on the same line +// Wrapped at the colon and indented with four spaces +MyClass::MyClass(int var) + : someVar_(var), someOtherVar_(var + 1) // Good: Add a space after the comma. +{ + DoSomething(); +} + +// If an initialization list needs to be placed in multiple lines, put each member on a separate line and align between lines. +MyClass::MyClass(int var) + someVar(var), // Four spaces of indentation. + someOtherVar_(var + 1) +{ + DoSomething(); +} +``` + +# 4 Comments +Generally, clear architecture and good naming are recommended to improve code readability, and comments are provided only when necessary. +Comments are used to help readers quickly understand code. Therefore, **comments should be provided for the sake of readers**. + +Comments must be concise, clear, and unambiguous, ensuring that information is complete and not redundant. + +**Comments are as important as code**. +When writing a comment, you need to step into the reader's shoes and use comments to express what the reader really needs. Comments are used to express the function and intention of code, rather than repeating code. +When modifying the code, ensure that the comments are consistent with the modified code. It is not polite to modify only code and keep the old comments, which will undermine the consistency between code and comments, and may confuse or even mislead readers. + +Comments should be made in English. + +## Comment Style + +In C++ code, both ` /* */` and ` // ` can be used for commenting. +Comments can be classified into different types, such as file header comments, function header comments, and code comments. This is based on their purposes and positions. +Comments of the same type must keep a consistent style. + +Note: Example code in this document uses comments in the `//` format only to better describe the rules and recommendations. This does not mean this comment format is better. + +## File Header Comments +### Rule 4.2.1 File header comments must contain the copyright notice. + +/* + * Copyright (c) 2020 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. + */ + +## Function Header Comments +### Rule 4.3.1 Write function header comments for public functions. +Public functions are interfaces provided by classes for external systems. To use public functions, the caller must understand the functionalities, parameter value ranges, return values, and precautions of the functions. +Write function header comments for the function value range, return value, and precautions, since they cannot be self-explained. + +### Rule 4.3.2 Function header comments with no content are forbidden. +Not all functions need function header comments. +For information that cannot be described by function signatures, add function header comments. + +Function header comments are placed above the function declaration or definition. Use one of the following styles: +Use '//' to start the function header. + +```cpp +// Single-line function header +int Func1(void); + +// Multi-line function header +// Second line +int Func2(void); +``` + +Use `/* */` to start the function header. +```cpp +/* Single-line function header */ +int Func1(void); + +/* + * Another single-line function header + */ +int Func2(void); + +/* + * Multi-line function header + * Second line + */ +int Func3(void); +``` +Use function names to describe functions, and add function header comments if necessary. +Do not write useless or redundant function headers. Do not write empty function headers with no content. + +The function header comment content will depend on the function and includes but is not limited to: a function description, return value, performance constraints, usage comments, memory conventions, algorithm implementation, reentering requirements. +In the function interface declaration in the external header file, the function header comment should clearly describe important and useful information. + +Good example: + +```cpp +/* + * The number of written bytes is returned. If -1 is returned, the write operation failed. + * Note that the memory buffer should be released by the caller. + */ +int WriteString(const char *buf, int len); +``` + +Bad example: +```cpp +/* + * Function name: WriteString + * Function: Write a character string. + * Parameters: + * Return value: + */ +int WriteString(const char *buf, int len); +``` +Problems: + +- The 'Parameters' and 'Return value' have no content. +- The function name is redundant. +- The most import thing, that is, who needs to release the buffer, is not clearly stated. + +## Code Comments +### Rule 4.4.1 Code comments are placed above or on the right of the corresponding code. +### Rule 4.4.2 There must be a space between the comment character and the comment content. At least one space is required between the comment and code if the comment is placed to the right of code. +Comments placed above code should be indented the same as that of the code. +Use one of the following styles: +Use "//". +```cpp + +// Single-line comment +DoSomething(); + +// Multi-line comment +// Second line +DoSomething(); +``` + +Use `/* */`. +```cpp +/* Single-line comment */ +DoSomething(); + +/* + * Multi-line comment in another mode + * Second line + */ +DoSomething(); +``` +Leave at least one space between the code and the comment on the right. It is recommended that no more than four spaces be left. +You can use the Tab key to indent 1–4 spaces. + +Select and use one of the following styles: + +```cpp +int foo = 100; // Comment on the right +int bar = 200; /* Comment on the right */ +``` +It is more appealing sometimes when the comment is placed on the right of code and the comments and code are aligned vertically. +After the alignment, ensure that the comment is 1–4 spaces away from the widest line of code. +Example: + +```cpp +const int A_CONST = 100; /* Related comments of the same type can be aligned vertically. */ +const int ANOTHER_CONST = 200; /* Leave spaces after code to align comments vertically. */ +``` +When the comment on the right exceeds the line width, consider placing the comment above the code. + +### Rule 4.4.3 Delete unused code segments. Do not comment them out. +Code that is commented out cannot be maintained. If you attempt to restore the code, it is very likely to introduce ignorable defects. +The correct method is to delete unnecessary code directly. If necessary, consider porting or rewriting the code. + +Here, commenting out refers to the removal of code from compilation without actually deleting it. This is done by using /* */, //, #if 0, #ifdef NEVER_DEFINED, and so on. + +### Rec 4.4.1 Delivered code cannot contain a TODO/TBD/FIXME comment. +TODO/TBD comments are used to describe required improvements and supplements. +FIXME comments are used to describe defects that need fixing. +They should have a standardized style, which facilitates text search. Example: + +```cpp +// TODO(): XX +// FIXME: XX +``` + + +# 5 Header Files +## Header File Responsibility +A header file is an external interface of a module or file. The design of a header file shows most of the system design. +The interface declaration for most functions is more suitable placed in the header file, but implementation (except inline functions) cannot be placed in the header file. Functions, macros, enumerations, and structure definitions that need to be used in .cpp files cannot be placed in the header file. +The header responsibility should be simple. An overly complex header file will make dependencies complex and cause long compilation times. + +### Rec 5.1.1 Each .cpp file should have a .h file with the same name. It should be used to declare the classes and interfaces that need to be exposed externally. +Generally, each .cpp file has a corresponding .h file. This .cpp file is used to store the function declarations, macro definitions, and class definitions that are to be exposed. +If a .cpp file does not need to open any interface externally, it should not exist. +Exception: __An entry point (for example, the file where the main function is located), unit tests, and dynamic libraries __ + +Example: +```cpp +// Foo.h + +#ifndef FOO_H +#define FOO_H + +class Foo { +public: + Foo(); + void Fun(); + +private: + int value_; +}; + +#endif +``` + +```cpp +// Foo.cpp +#include "Foo.h" + +namespace { // Good: The declaration of the internal function is placed in the header of the .cpp file, and has been limited to the unnamed namespace or static scope. + void Bar() + { + } +} + +... + +void Foo::Fun() +{ + Bar(); +} +``` + +## Header File Dependency +### Rule 5.2.1 Header file cyclic dependency is forbidden. +An example of cyclic dependency (also known as circular dependency) is: a.h contains b.h, b.h contains c.h, and c.h contains a.h. If any of these header files is modified, all code containing a.h, b.h, and c.h needs to be recompiled. +For a unidirectional dependency, for example if: a.h contains b.h, b.h contains c.h, and c.h does not contain any header file, modifying a.h does not mean that we need to recompile the source code for b.h or c.h. + +The cyclic dependency of header files reflects an obviously unreasonable architecture design, which can be avoided through optimization. + + +### Rule 5.2.2 Header files should have #define guards to prevent multiple inclusion. +To prevent header files from being included multiple times, all header files should be protected by #define. Do not use #pragma once. + +When defining a protection character, comply with the following rules: +1) The protection character uses a unique name. +2) Do not place code or comments (except for file header comments) before or after the protected part. + +Example: Assume that the timer.h file of the timer module is in the timer/include/timer.h directory. Perform the following operations to safeguard the timer.h file: + +```cpp +#ifndef TIMER_INCLUDE_TIMER_H +#define TIMER_INCLUDE_TIMER_H +... +#endif +``` + +### Rule 5.2.3 It is prohibited to reference external function interfaces and variables in extern declaration mode. +Interfaces provided by other modules or files can be used only by including header files. +Using external function interfaces and variables in extern declaration mode may cause inconsistency between declarations and definitions when external interfaces are changed. +In addition, this kind of implicit dependency may cause architecture corruption. + +Cases that do not comply with specifications: + +// a.cpp content +```cpp +extern int Fun(); // Bad: Use external functions in extern mode. + +void Bar() +{ + int i = Fun(); + ... +} +``` + +// b.cpp content +```cpp +int Fun() +{ + // Do something +} +``` +Should be changed to: + +// a.cpp content +```cpp +#include "b.h" // Good: Use the interface provided by other .cpp by including its corresponding header file. + +void Bar() +{ + int i = Fun(); + ... +} +``` + +// b.h content +```cpp +int Fun(); +``` + +// b.cpp content +```cpp +int Fun() +{ + // Do something +} +``` +In some scenarios, if internal functions need to be referenced with no intrusion to the code, the extern declaration mode can be used. +Example: +When performing unit testing on an internal function, you can use the extern declaration to reference the tested function. +When a function needs to be stubbed or patched, the function can be declared using extern. + +### Rule 5.2.4 Do not include header files in extern "C". +If a header file is included in extern "C", extern "C" may be nested. Some compilers restrict the nesting of extern "C". If there are too many nested layers, compilation errors may occur. + +When C and C++ programmings are used together and if extern "C" includes a header file, the original intent behind the header file may be hindered. For example, when the link specifications are modified incorrectly. + +For example, assume that there are two header files a.h and b.h. + +// a.h content +```cpp +... +#ifdef __cplusplus +void Foo(int); +#define A(value) Foo(value) +#else +void A(int) +#endif +``` +// b.h content +```cpp +... +#ifdef __cplusplus +extern "C" { +#endif + +#include "a.h" +void B(); + +#ifdef __cplusplus +} +#endif +``` + +Using the C++ preprocessor to expand b.h, the following information is displayed: +```cpp +extern "C" { + void Foo(int); + void B(); +} +``` + +According to the author of a.h, the function Foo is a C++ free function following the "C++" link specification. +However, because `#include "a.h"` is placed inside `extern "C"` in b.h, the link specification of function Foo is changed incorrectly. + +Exceptions: +In the C++ compilation environment, if you want to reference the header file of pure C, the C header files should not contain `extern "C"`. The non-intrusive approach is to include the C header file in `extern "C"`. + +### Rec 5.2.1 Use `#include` instead of a forward declaration to include header files. +A forward declaration is for the declaration of classes, functions, and templates and is not meant for its definition. + +- Advantages: + 1. Forward declarations can save compilation time. Redundant `#include `statements force the compiler to expand more files and process more input. + 2. Forward declarations can save unnecessary recompilation time. The use of #include will force your code to be recompiled multiple times due to unrelated changes in header files. +- Disadvantages: + 1. Forward declarations hide dependency relationship. When a header file is modified, user code will skip the necessary recompilation process. + 2. A forward declaration may be broken by subsequent changes to the library. Forward declarations of functions and templates sometimes prevent header file developers from changing APIs. For example, widening a formal parameter type, adding a template parameter with a default value, and so on. + 3. Forward declaration of symbols from the namespace `std::` is seen as undefined behavior (as specified in the C++ 11 standard specification). + 4. Forward declaration of multiple symbols from a header file can be more verbose than simply including (#include) the header. + 5. Structuring code only for forward declaration (for example, using pointer members instead of object members) can make the code more complex and slower. + 6. It is difficult to determine whether a forward declaration or `#include` is needed. In some scenarios, replacing `#include` with a forward declaration may cause unexpected results. + +Therefore, we should avoid using forward declarations as much as possible. Instead, we use the #include statement to include a header file and ensure dependency. + +# 6 Scopes + +## Namespaces + +### Rec 6.1.1 For code that does not need to be exported from the .cpp file, you are advised to use an unnamed namespace for encapsulation or use static to modify the variables, constants, or functions that need hiding. +In the C++ 2003 standard, using static to modify the external availability of functions and variables was marked as deprecated. Therefore, unnamed namespaces are the recommended method. + +Main Reasons: +1. There are too many meanings for static in C++: static function member variable, static member function, static global variable, and static function local variable. Each of them has special processing. +2. Static can only be used to define variables, constants, and functions that are not referenced outside the current .cpp file, while namespaces can also be used to encapsulate types. +3. Use a namespace to control the scope instead of using both static and namespaces. +4. Unnamed namespaces can be used to instantiate templates rather than functions modified by the static keyword. + +Do not use unnamed namespaces or static in header files. + +```cpp +// Foo.cpp + +namespace { + const int MAX_COUNT = 20; + void InternalFun(){}; +} + +void Foo::Fun() +{ + int i = MAX_COUNT; + + InternalFun(); +} + +``` + +### Rule 6.1.1 Do not use "using" to import namespace in a header file or before #include statements. +Note: Using "using" to import namespace will affect any subsequent code and may cause symbol conflicts. +Example: + +```cpp +// Header file a.h +namespace NamespaceA { + int Fun(int); +} +``` + +```cpp +// Header file b.h +namespace NamespaceB { + int Fun(int); +} + +using namespace NamespaceB; + +void G() +{ + Fun(1); +} +``` + +```cpp +// Source code a.cpp +#include "a.h" +using namespace NamespaceA; +#include "b.h" + +void main() +{ + G(); // "using namespace NamespaceA" before #include "b.h", will cause conflicts when calling NamespaceA::Fun and NamespaceB::Fun. +} +``` + +Using "using" to import a symbol or define an alias in a header file is allowed in customized namespaces of modules, but is prohibited in the global namespace. +```cpp +// foo.h + +#include +using fancy::string; // Bad: It is prohibited to import symbols to the global namespace. + +namespace Foo { + using fancy::string; // Good: Symbols can be imported in customized namespaces of modules. + using MyVector = fancy::vector; // Good: In C++11, aliases can be defined in customized namespaces. +} +``` + + +## Global Functions and Static Member Functions + +### Rec 6.2.1 Use namespaces to manage global functions. If global functions are closely tied to a class, you can use static member functions. +Note: Placing non-member functions in a namespace avoids polluting the global scope. Do not use "class + static member function" to simply manage global functions. If a global function is closely tied to a class, it can be used as a static member function of the class. + +If you need to define some global functions for a .cpp file, use unnamed namespaces for management. +```cpp +namespace MyNamespace { + int Add(int a, int b); +} + +class File { +public: + static File CreateTempFile(const std::string& fileName); +}; +``` + +## Global Constants and Static Member Constants + +### Rec 6.3.1 Use namespaces to manage global constants. If global constants are closely tied to a class, you can use static member constants. +Note: Placing global constants in a namespace avoids polluting the global scope. Do not use "class + static member constant" to simply manage global constants. If a global constant is closely tied to a class, it can be used as a static member constant of the class. + +If you need to define some global constants only for a .cpp file, use unnamed namespaces for management. +```cpp +namespace MyNamespace { + const int MAX_SIZE = 100; +} + +class File { +public: + static const std::string SEPARATOR; +}; +``` + +## Global Variables + +### Rec 6.4.1 Do not use global variables. Use the singleton pattern instead. +Note: Global variables can be modified and read, which results in data coupling between production code and the global variables. +```cpp +int g_counter = 0; + +// a.cpp +g_counter++; + +// b.cpp +g_counter++; + +// c.cpp +cout << g_counter << endl; +``` + +Singleton +```cpp +class Counter { +public: + static Counter& GetInstance() + { + static Counter counter; + return counter; + } // Simple example of a singleton implementation + + void Increase() + { + value_++; + } + + void Print() const + { + std::cout << value_ << std::endl; + } + +private: + Counter() : value_(0) {} + +private: + int value_; +}; + +// a.cpp +Counter::GetInstance().Increase(); + +// b.cpp +Counter::GetInstance().Increase(); + +// c.cpp +Counter::GetInstance().Print(); +``` + +After the singleton is implemented, there is a unique global instance, which can functions as a global variable. However, the singleton provides better encapsulation. + +Exception: In some cases, the scope of a global variable is contained inside a module. Multiple instances of the same global variable may exist, and each module holds one copy. In this case, a singleton cannot be used as it is limited to one instance. + +# 7 Classes + +## Constructors, Copy/Move Constructors, Copy/Move Assignment Operators, and Destructors +Constructors, copy/move constructors, copy/move assignment operators, and destructors provide lifetime management methods for objects. +- Constructor: `X()` +- Copy constructor: `X(const X&)` +- Copy assignment operator: `operator=(const X&)` +- Move constructor: `X (X&&)` *Provided in versions later than C++ 11*. +- Move assignment operator: `operator=(X&&)` *Provided in versions later than C++ 11*. +- Destructor: `~X()` + +### Rule 7.1.1 The member variables of a class must be initialized explicitly. +Note: If a class has members but no constructor and a default constructor is defined, the compiler will automatically generate a constructor, but it will not initialize member variables. The content of each object is uncertain. + +Exceptions: +- If the member variables in a class have a default constructor, explicit initialization is not required. + +Example: The following code has no constructor, and private data members cannot be initialized: +```cpp +class Message { +public: + void ProcessOutMsg() + { + //... + } + +private: + unsigned int msgID_; + unsigned int msgLength_; + unsigned char* msgBuffer_; + std::string someIdentifier_; +}; + +Message message; // The message member is not initialized. +message.ProcessOutMsg(); // Potential risks exist in subsequent use. + +// Therefore, it is necessary to define a default constructor as follows: +class Message { +public: + Message() : msgID_(0), msgLength_(0), msgBuffer_(NULL) + { + } + + void ProcessOutMsg() + { + // ... + } + +private: + unsigned int msgID_; + unsigned int msgLength_; + unsigned char* msgBuffer_; + std::string someIdentifier; // The member variable has a default constructor. Therefore, explicit initialization is not required. +}; +``` + +### Rec 7.1.1 Initialization during declaration (C++ 11) and initialization using the constructor initialization list are preferred for member variables. +Note: Initialization during declaration (C++11) is preferred because initialized values of member variables can be easily understood. If initialized values of certain member variables are relevant to constructors, or C++ 11 is not supported, the constructor initialization list is used preferentially to initialize these member variables. Compared with the assignment statements in constructors, code of the constructor initialization list is simpler and has higher performance, and can be used to initialize constant and reference members. + +```cpp +class Message { +public: + Message() : msgLength(0) { // Good: The constructor initialization list is preferred. + { + msgBuffer = NULL; // Bad: Values cannot be assigned in constructors. + } + +private: + unsigned int msgID{0}; // Good: Used in C++11. + unsigned int msgLength_; + unsigned char* msgBuffer_; +}; +``` + +### Rule 7.1.2 Declare single-parameter constructors as explicit to prevent implicit conversion. +Note: If a single-parameter constructor is not declared as explicit, it will become an implicit conversion function. +Example: + +```cpp +class Foo { +public: + explicit Foo(const string& name): name_(name) + { + } +private: + string name_; +}; + + +void ProcessFoo(const Foo& foo){} + +int main(void) +{ + std::string test = "test"; + ProcessFoo(test); // Compiling failed. + return 0; +} +``` + +The preceding code fails to be compiled because the parameter required by `ProcessFoo` is of the Foo type, which mismatch with the input string type. + +If the explicit keyword of the Foo constructor is removed, implicit conversion is triggered and a temporary Foo object is generated when `ProcessFoo` is called with the string parameter. Usually, this implicit conversion is confusing and bugs are apt to be hidden, due to unexpected type conversion. Therefore, single-parameter constructors require explicit declaration. + +### Rule 7.1.3 If copy/move constructors and copy/move assignment operators are not needed, clearly prohibit them. +Note: If users do not define it, the compiler will generate copy constructors and copy assignment operators, move constructors and move assignment operators (move semantic functions will be available in versions later than C++ 11). +If we do not use copy constructors or copy assignment operators, explicitly delete them. + +1. Set copy constructors or copy assignment operators to private and do not implement them. +```cpp +class Foo { +private: + Foo(const Foo&); + Foo& operator=(const Foo&); +}; +``` +2. Use delete provided by C++ 11. For details, see Rule 10.1.3 in chapter 10 Modern C++ Features. + + +3. You are advised to inherit **NoCopyable** and **NoMovable**. Do not use macros such as **DISALLOW_COPY_AND_MOVE**, **DISALLOW_COPY**, and **DISALLOW_MOVE**. +```cpp +class Foo : public NoCopyable, public NoMovable { +}; +``` +Implementation of NoCopyable and NoMovable: +```cpp +class NoCopyable { +public: + NoCopyable() = default; + NoCopyable(const NoCopyable&) = delete; + NoCopyable& operator = (NoCopyable&) = delete; +}; + +class NoMovable { +public: + NoMovable() = default; + NoMovable(NoMovable&&) noexcept = delete; + NoMovable& operator = (NoMovable&&) noexcept = delete; +}; +``` + +### Rule 7.1.4 Copy constructors and copy assignment operators should be implemented or forbidden together. +Both copy constructors and copy assignment operators provide copy semantics. They should be implemented or hidden together. + +```cpp +// The copy constructor and the copy assignment operator are implemented together. +class Foo { +public: + ... + Foo(const Foo&); + Foo& operator=(const Foo&); + ... +}; + +// The copy constructor and the copy assignment operator are both set to default, as supported by C++ 11. +class Foo { +public: + Foo(const Foo&) = default; + Foo& operator=(const Foo&) = default; +}; + +// The copy constructor and the copy assignment operator are hidden together. You should use the delete keyword if C++11 features are available. +class Foo { +private: + Foo(const Foo&); + Foo& operator=(const Foo&); +}; +``` + +### Rule 7.1.5 Move constructors and move assignment operators should be implemented or hidden together. +The move operation is added in C++ 11. If a class is required to support the move operation, move constructors and move assignment operators need to be implemented. + +Both move constructors and move assignment operators provide move semantics. They should be implemented or hidden together. +```cpp +// The copy constructor and the copy assignment operator are implemented together. +class Foo { +public: + ... + Foo(Foo&&); + Foo& operator=(Foo&&); + ... +}; + +// The copy constructor and the copy assignment operator are both set to default, as supported by C++ 11. +class Foo { +public: + Foo(Foo&&) = default; + Foo& operator=(Foo&&) = default; +}; + +// The copy constructor and the copy assignment operator are hidden together. You should use the delete keyword if C++11 features are available. +class Foo { +public: + Foo(Foo&&) = delete; + Foo& operator=(Foo&&) = delete; +}; +``` + +### Rule 7.1.6 It is prohibited to call virtual functions in constructors and destructors. +Note: Calling a virtual function of the current object in a constructor or destructor will cause behaviors of non-polymorphism. +In C++, a base class constructs only one complete object at a time. + +Example: Base indicates the base class, and Sub indicates the derived class. +```cpp +class Base { +public: + Base(); + virtual void Log() = 0; // Different derived classes call different log files. +}; + +Base::Base() // Base class constructor +{ + Log(); // Call the virtual function log. +} + +class Sub : public Base { +public: + virtual void Log(); +}; +``` + +When running the following statement: +`Sub sub;` +The constructor of the derived class is executed first. However, the constructor of the base class is called first. Because the constructor of the base class calls the virtual function log, the log is in the base class version. The derived class is constructed only after the base class is constructed. As a result, behaviors of non-polymorphism are caused. +This also applies to destructors. + +### Rule 7.1.7 The copy constructors, copy assignment operators, move constructors, and move assignment operators in polymorphic base classes must be non-public or delete functions. +Slicing occurs if the value of a derived class object is directly assigned to a base class object. In this case, only the base class part is copied or moved, which undermines polymorphism. +[Counterexample] +In the following code example, the copy constructor and copy assignment operator are not defined in the base class. The compiler automatically generates two special member functions. +If the value of a derived class object is assigned to the base class object, slicing occurs. The copy constructor and copy assignment operator can be declared as **deleted** so that the compiler can check such assignment behavior. +```cpp +class Base { +public: + Base() = default; + virtual ~Base() = default; + ... + virtual void Fun() { std::cout << "Base" << std::endl;} +}; + +class Derived : public Base { + ... + void Fun() override { std::cout << "Derived" << std::endl; } +}; + +void Foo(const Base &base) +{ + Base other = base; // Bad: Slicing occurs + other.Fun(); // The Fun() function of the base class is called. +} +``` +```cpp +Derived d; +Foo(d); // A derived class object is passed. +``` +1. Set copy constructors or copy assignment operators to **private** and do not implement them. + +## Inheritance + +### Rule 7.2.1 Declare destructors of a base class as virtual, and declare the class that is not to be inherited as final. +Note: Destructors of the derived class can be called during polymorphism invocation only when destructors of the base class are virtual. + +Example: There will be memory leak if destructors of the base class are not declared as virtual. +```cpp +class Base { +public: + virtual std::string getVersion() = 0; + + ~Base() + { + std::cout << "~Base" << std::endl; + } +}; +``` + +```cpp +class Sub : public Base { +public: + Sub() : numbers_(NULL) + { + } + + ~Sub() + { + delete[] numbers_; + std::cout << "~Sub" << std::endl; + } + + int Init() + { + const size_t numberCount = 100; + numbers_ = new (std::nothrow) int[numberCount]; + if (numbers_ == NULL) { + return -1; + } + + ... + } + + std::string getVersion() + { + return std::string("hello!"); + } +private: + int* numbers_; +}; +``` + +```cpp +int main(int argc, char* args[]) +{ + Base* b = new Sub(); + + delete b; + return 0; +} +``` +Because destructors of the base class are not declared as virtual, only destructors of the base class are called when an object is destroyed. Destructors of the derived class Sub are not called. As a result, a memory leak occurs. +Exceptions: +For classes such as **NoCopyable** and **NoMovable** that have no behavior and are used only as identifiers, you do not need to define them as final. + +### Rule 7.2.2 Do not use default parameter values for virtual functions. +Note: In C++, virtual functions are dynamically bound, but the default parameters of functions are statically bound during compilation. This means that the function you finally execute is a virtual function that is defined in the derived class but uses the default parameter value in the base class. To avoid confusion and other problems caused by inconsistent default parameter declarations during overriding of virtual functions, it is prohibited to declare default parameter values for all virtual functions. +Example: The default value of parameter "text" of the virtual function "Display" is determined at compilation time instead of runtime, which does not fit with polymorphism. +```cpp +class Base { +public: + virtual void Display(const std::string& text = "Base!") + { + std::cout << text << std::endl; + } + + virtual ~Base(){} +}; + +class Sub : public Base { +public: + virtual void Display(const std::string& text = "Sub!") + { + std::cout << text << std::endl; + } + + virtual ~Sub(){} +}; + +int main() +{ + Base* base = new Sub(); + Sub* sub = new Sub(); + + ... + + base->Display(); // The program output is as follows: Base! The expected output is as follows: Sub! + sub->Display(); // The program output is as follows: Sub! + + delete base; + delete sub; + return 0; +}; +``` + +### Rule 7.2.3 Do not redefine inherited non-virtual functions. +Note: Non-virtual functions cannot be dynamically bound (only virtual functions can be dynamically bound). You can obtain the correct result by operating on the pointer of the base class. + +Example: +```cpp +class Base { +public: + void Fun(); +}; + +class Sub : public Base { +public: + void Fun(); +}; + +Sub* sub = new Sub(); +Base* base = sub; + +sub->Fun(); // Call Fun of the derived class. +base->Fun(); // Call Fun of the base class. +//... + +``` + +## Multiple Inheritance +In the actual development process, multiple inheritance is seldom used because the following typical problems may occur: +1. Data duplication and name ambiguity caused by "diamond" inheritance. C++ introduces virtual inheritance to solve these problems. +2. In addition to "diamond" inheritance, names of multiple base classes may also conflict with each other, resulting in name ambiguity. +3. If a derived class needs to be extended or needs to override methods of multiple base classes, the responsibilities of the derived classes are unclear and semantics are muddled. +4. Compared with delegation, inheritance is seen as white box reuse, that is, a derived class can access the protected members of the base class, which leads to more coupling. Multiple inheritance, due to the coupling of multiple base classes, leads to even more coupling. + +Multiple inheritance has the following advantages: +Multiple inheritance provides a simpler method for assembling and reusing multiple interfaces or classes. + +Therefore, multiple inheritance can be used only in the following cases: + +### Rec 7.3.1 Use multi-inheritance to implement interface separation and multi-role combination. +If a class requires multiple interfaces, combine multiple separated interfaces by using multiple inheritance. This is similar to the Traits mixin of the Scala language. + +```cpp +class Role1 {}; +class Role2 {}; +class Role3 {}; + +class Object1 : public Role1, public Role2 { + // ... +}; + +class Object2 : public Role2, public Role3 { + // ... +}; + +``` + +The C++ standard library has a similar implementation example: +```cpp +class basic_istream {}; +class basic_ostream {}; + +class basic_iostream : public basic_istream, public basic_ostream { + +}; +``` + +## Overloading + +Overload operators should be used when there are sufficient reasons, and they do not change the original perception of the operators. For example, do not use the plus sign (+) to perform subtraction. +Operator overloading can make code more intuitive but has some disadvantages: +- It is often mistaken that the operation is as fast as a built-in operator, which has no performance degradation. +- There is no naming to aid debugging. It is more convenient to search by function name than by operator. +- Overloading operators can cause confusion if behavior definitions are not intuitive (for example, if the "+" operator is used for subtraction). +- The implicit conversion caused by the overloading of assignment operators may lead to entrenched bugs. Functions such as Equals () and CopyFrom () can be defined to replace the = and == operators. + + + +# 8 Functions +## Function Design +### Rule 8.1.1 Avoid long functions and ensure that each function contains no more than 50 lines (non-null and non-comment). +A function should be displayed on one screen (no longer than 50 lines). It should do only one thing, and do it well. + +Long functions often mean that the functions are too complex to implement in more than one function, or overly detailed but not further abstracted. + +Exception: Some algorithms may be longer than 50 lines due to algorithm convergence and functional comprehensiveness. + +Even if a long function works very well now, once someone modifies it, new problems may occur. It might even cause bugs that are difficult to find. +It is recommended that you split a long function into several functions that are simpler and easier to manage, facilitating comprehension and modification. + +## Inline Functions + +### Rec 8.2.1 An inline function cannot exceed 10 lines. +**Note**: An inline function has the same characteristics of a normal function. The difference between an inline function and a normal function lies in the processing of function calls. When a general function is called, the program execution right is transferred to the called function, and then returned to the function that calls it. When an inline function is called, the invocation expression is replaced with an inline function body. + +Inline functions are only suitable for small functions with only 1-10 lines. For a large function that contains many statements, the function call and return overheads are relatively trivial and do not need the help of an inline function. Most compilers may abandon the inline mode and use the common method to call the function. + +If an inline function contains complex control structures, such as loop, branch (switch), and try-catch statements, the compiler may regard the function as a common function. +**Virtual functions and recursive functions cannot be used as inline functions**. + +## Function Parameters + +### Rec 8.3.1 Use a reference instead of a pointer for function parameters. + +**Note**: A reference is more secure than a pointer because it is not empty and does not point to other targets. Using a reference stops the need to check for illegal null pointers. + +If a product is being developed for an older platform, the processing used by the old platform is preferred. +Use const to avoid parameter modification, so that readers can clearly know that a parameter is not going to be modified. This greatly enhances code readability. + +Exception: When the input parameter is an array with an unknown compile-time length, you can use a pointer instead of a reference. + +### Rec 8.3.2 Use strongly typed parameters. Do not use void*. +While different languages have their own views on strong typing and weak typing, it is generally believed that C and C++ are strongly typed languages. Since we use such a strongly typed language, we should keep to this style. +An advantage of this is the compiler can find type mismatch problems at the compilation stage. + +Using strong typing helps the compiler find more errors for us. Pay attention to the usage of the FooListAddNode function in the following code: +```cpp +struct FooNode { + struct List link; + int foo; +}; + +struct BarNode { + struct List link; + int bar; +} + +void FooListAddNode(void *node) // Bad: Here, the void * type is used to transfer parameters. +{ + FooNode *foo = (FooNode *)node; + ListAppend(&g_FooList, &foo->link); +} + +void MakeTheList() +{ + FooNode *foo = NULL; + BarNode *bar = NULL; + ... + + FooListAddNode(bar); // Wrong: In this example, the foo parameter was supposed to be transferred, but the bar parameter is accidentally transferred instead. However, no error is reported. +} +``` + +1. You can use a template function to change the parameter type. +2. A base class pointer can be used to implement this according to polymorphism. + +### Rec 8.3.3 A function can have a maximum of five parameters. +If a function has too many parameters, it is apt to be affected by external changes, and therefore maintenance is affected. Too many function parameters will also increase the testing workload. + +If a function has more than five parameters, you can: +- Split the function. +- Combine related parameters into a struct. + +# 9 Other C++ Features + +## Constants and Initialization + +Unchanged values are easier to understand, trace, and analyze. Therefore, use constants instead of variables as much as possible. When defining values, use const as a default. + +### Rule 9.1.1 Do not use macros to replace constants. + +**Note**: Macros are a simple text replacement that is completed in the preprocessing phase. When an error is reported, the corresponding value is reported. During tracing and debugging, the value is also displayed instead of the macro name. A macro does not support type checking and is insecure. A macro has no scope. + +```cpp +#define MAX_MSISDN_LEN 20 // Bad + +// Use const in C++. +const int MAX_MSISDN_LEN = 20; // Good + +// In versions later than C++ 11, constexpr can be used. +constexpr int MAX_MSISDN_LEN = 20; +``` + +### Rec 9.1.1 A group of related integer constants must be defined as an enumeration. + +**Note**: Enumerations are more secure than `#define` or `const int`. The compiler checks whether a parameter value is within the enumerated value range to avoid errors. + +```cpp +// Good example: +enum Week { + SUNDAY, + MONDAY, + TUESDAY, + WEDNESDAY, + THURSDAY, + FRIDAY, + SATURDAY +}; + +enum Color { + RED, + BLACK, + BLUE +}; + +void ColorizeCalendar(Week today, Color color); + +ColorizeCalendar(BLUE, SUNDAY); // Compilation error. The parameter type is incorrect. + +// Bad example: +const int SUNDAY = 0; +const int MONDAY = 1; + +const int BLACK = 0; +const int BLUE = 1; + +bool ColorizeCalendar(int today, int color); +ColorizeCalendar(BLUE, SUNDAY); // No error is reported. +``` + +When an enumeration value needs to correspond to a specific value, explicit value assignment is required during declaration. Otherwise, do not assign explicit values. This will prevent repeated assignment and reduce the maintenance workload (when adding and deleting members). + +```cpp +// Good example: Device ID defined in the S protocol. It is used to identify a device type. +enum DeviceType { + DEV_UNKNOWN = -1, + DEV_DSMP = 0, + DEV_ISMG = 1, + DEV_WAPPORTAL = 2 +}; +``` + +Do not assign explicit values when enumeration is used internally, and only for classification. + +```cpp +// Good example: Enumeration definition is used to identify session status in a program. +enum SessionState { + INIT, + CLOSED, + WAITING_FOR_RESPONSE +}; +``` + +Try to avoid repeating enumeration values. If it is required, use the already defined enumeration values instead. + +```cpp +enum RTCPType { + RTCP_SR = 200, + RTCP_MIN_TYPE = RTCP_SR, + RTCP_RR = 201, + RTCP_SDES = 202, + RTCP_BYE = 203, + RTCP_APP = 204, + RTCP_RTPFB = 205, + RTCP_PSFB = 206, + RTCP_XR = 207, + RTCP_RSI = 208, + RTCP_PUBPORTS = 209, + RTCP_MAX_TYPE = RTCP_PUBPORTS +}; +``` + +### Rule 9.1.2 Magic numbers cannot be used. +So-called magic numbers are numbers that are unintelligible and difficult to understand. + +Some numbers can be understood based on context. +For example, the number 12 varies in different contexts. +type = 12; is not intelligible (and a magic number), but `month = year * 12`; can be understood, so we wouldn't really class this as a magic number. +The number 0 is often seen as a magic number. For example, `status = 0`; cannot truly express any status information. + +Solution: +Comments can be added for numbers that are used locally. +For the numbers that are used multiple times, you must define them as constants and give them descriptive names. + +The following cases are forbidden: +No symbol is used to explain the meaning of a number, for example, ` const int ZERO = 0`. +The symbol name limits the value. For example, for example, `const int XX_TIMER_INTERVAL_300MS = 300`. Use `XX_TIMER_INTERVAL_MS` instead. + +### Rule 9.1.3 Ensure that a constant has only one responsibility. + +**Note**: A constant is used for only one specific function, that is, a constant cannot be used for multiple purposes. + +```cpp +// Good example: For protocol A and protocol B, the length of the MSISDN is 20. +const unsigned int A_MAX_MSISDN_LEN = 20; +const unsigned int B_MAX_MSISDN_LEN = 20; + +// Using different namespaces: +namespace Namespace1 { + const unsigned int MAX_MSISDN_LEN = 20; +} + +namespace Namespace2 { + const unsigned int MAX_MSISDN_LEN = 20; +} +``` + +### Rule 9.1.4 Do not use memcpy_s or memset_s to initialize non-POD objects. + +**Note**: `POD` is short for `Plain Old Data`, which is a concept introduced in the C++ 98 standard (ISO/IEC 14882, first edition, 1998-09-01). The `POD` types include the original types and aggregate types such as `int`, `char`, `float`, `double`, `enumeration`, `void`, and pointer. Encapsulation and object-oriented features cannot be used (for example, user-defined constructors, assignment operators, destructors, base classes, and virtual functions). + +For non-POD classes, such as class objects of non-aggregate types, virtual functions may exist. Memory layout is uncertain, and is related to the compiler. Misuse of memory copies may cause serious problems. + +Even if a class of the aggregate type is directly copied and compared, and any functions hiding information or protecting data are destroyed, the `memcpy_s` and `memset_s` operations are not recommended. + +For details about the POD type, see the appendix. + +### Rec 9.1.2 Declare and initialize variables only when they are used. + +**Note**: It is a common low-level programming error that a variable is not assigned an initial value before being used. Declaring and initializing a variable just before using it will prevent this. + +If all variables are declared at the beginning of a function before they are used, their scope covers the entire function, which may lead to the following problems: +* The program may become difficult to understand and maintain. The definition and use of variables are separated. +* These variables are difficult to initialize properly. At the beginning of a function, there is often insufficient information for variable initialization, and a default null value (such as 0) is often assigned as the initial value. If a variable is used before it is assigned a valid value, it will also cause errors. + +Following the minimization principle of variable scopes and the principle of proximity declaration will make it easier to read code and understand variable types and initial values. In particular, use initialization to replace declaration and then assign values. + +```cpp +// Bad example: Declaration is separated from initialization. +string name; // The variable is not initialized in the declaration, and a default constructor is called. +name = "zhangsan"; // An assignment operator is called again. Declaration is separate from definition, which is difficult to understand. + +// Good example: Declaration and initialization are together, and easy to understand. +string name("zhangsan"); // Invoke a constructor. +``` + + +## Expressions +### Rule 9.2.1 A variable cannot be referenced again if it is contained in an increment or decrement operation in an expression. +In an expression where the increment or decrement operations are performed on a variable, the variable cannot be referenced again. The result of a second referencing is not explicitly defined in C++ standards. The results in different compilers or different versions of a compiler may be different. +Therefore, it is recommended that an undefined operation sequence not be assumed. + +Note that the problem of operation sequence cannot be solved by using parentheses because this is not a priority problem. + +Example: +```cpp +x = b[i] + i++; // Bad: Whether the position of b[i] is before or after the i++ is unclear. +``` +The increment or decrement operation should be placed in a single line: +```cpp +x = b[i] + i; +i++; // Good: i++ is placed in a single line. +``` + +Function parameter +```cpp +Func(i++, i); // Bad: Whether the increment operation happens for the second parameter is unclear +``` + +Good example: +```cpp +i++; // Good: i++ is placed in a single line. +x = Func(i, i); +``` + +### Rule 9.2.2 A switch statement must have a default branch. +In most cases, a switch statement requires a default branch to ensure that there is a default action when the case tag is missing for a processed value. + +Exceptions: +If the switch condition variables are enumerated and the case branch covers all values, the default branch is redundant. +Because modern compilers can check which case branches are missing in the switch statement and provide an advanced warning. + +```cpp +enum Color { + RED = 0, + BLUE +}; + +// The switch condition variables are enumerated. Therefore, you do not need to add a default branch. +switch (color) { + case RED: + DoRedThing(); + break; + case BLUE: + DoBlueThing(); + ... + break; +} +``` + +### Rec 9.2.1 When comparing expressions, follow the principle that the left side tends to change and the right side tends to remain unchanged. +When a variable is compared with a constant, placing the constant on the left, for example, if (MAX == v), does not comply with standard reading habits and is more difficult to understand. +The constant should be placed on the right. The expression is written as follows: +```cpp +if (value == MAX) { + +} + +if (value < MAX) { + +} +``` +There are special cases: for example, if the expression `if (MIN < value && value < MAX)` is used to describe a range, the first half, as a constant, should be placed on the left. + +You do not need to worry about writing '==' as '=' because a compilation alarm will be generated for `if (value = MAX)` and an error will be reported by other static check tools. Use these tools to solve such writing errors and ensure that that code is readable. + +### Rec 9.2.2 Use parentheses to specify the operator precedence. +Use parentheses to specify the operator precedence. This will prevent program errors due to the inconsistency between default priority and the intended design. At the same time, it makes the code clearer and more readable. However, too many parentheses muddy the code, reducing readability. The following is a recommendation on their correct usage. + +- For binary and ternary operators, if multiple operators are involved, parentheses should be used. +```cpp +x = a + b + c; /* The operator does not change, and thus parentheses are not required. */ +x = Foo(a + b, c); /* The operator does not change, and thus parentheses are not required. */ +x = 1 << (2 + 3); /* More than one operator is used and thus parentheses are required. */ +x = a + (b / 5); /* More than one operator is used and thus parentheses are required. */ +x = (a == b) ? a : (a – b); /* More than one operator is used and thus parentheses are required. */ +``` + + +## Type Casting + +Do not use type branches to customize behaviors. Type branch customization behavior is prone to errors and is an obvious sign of attempting to compile C code using C++. This is very inflexible technology. If you forget to modify all branches when adding a new type to a compiler, you will not be notified. Use templates and virtual functions to let the type define itself rather than letting the calling side determine behavior. + +It is recommended that type casting be avoided. We should consider the data type in the code design instead of overusing type casting to solve type conflicts. When designing a basic type, consider the following: +- Whether it is unsigned or signed. +- Is it suitable for float or double? +- Should you use int8, int16, int32, or int64 bit lengths? + +However, we cannot prohibit the use of type casting because the C++ language is a machine-oriented programming language, involving pointer addresses, and we interact with various third-party or underlying APIs. Their type design may not be reasonable and type casting tends to occur in the adaptation process. + +Exception: When calling a function, if we do not want to process the result of the function, first consider whether this is your best choice. If you do not want to process the return value of the function, cast it to void. + +### Rule 9.3.1 If type casting is required, use the type casting provided by the C++ instead of the C style. + +**Note**: + +The type casting provided by C++ is more targeted, easy to read, and more secure than the C style. C++ provides the following types of casting: +- Type casting: +1. `dynamic_cast`: Used to inherit the downstream transformation of the system. `dynamic_cast` has the type check function. Design the base class and derived class to avoid using dynamic_cast for casting. +2. `static_cast`: Similar to the C style casting, which can be used to convert a value, or to convert the pointer or reference of a derived class into a base class pointer or reference. This casting is often used to eliminate type ambiguity brought on by multiple inheritance, which is relatively safe. If it is a pure arithmetic conversion, use the braces as stated in the following text. +3. `reinterpret_cast`: Used to convert irrelevant types. `reinterpret_cast` forces the compiler to reinterpret the memory of a certain type of objects into another type, which is an unsafe conversion. It is recommended that `reinterpret_cast` be used as little as possible. +4. `const_cast`: Used to remove the `const` attribute of an object so that the object can be modified. You are advised to use `const_cast` as little as possible. + +- Arithmetic conversion: (Supported by C++ 11 and later versions) + If the type information is not lost, for example, the casting from float to double, or from int32 to int64, the braces syntax is recommended. +```cpp + double d{ someFloat }; + int64_t i{ someInt32 }; +``` + +### Rec 9.3.1 Avoid using `dynamic_cast`. +1. `dynamic_cast` depends on the RTTI of C++ so that the programmer can identify the type of the object in C++ at run time. +2. `dynamic_cast` indicates that a problem has occurred in the design of the base class and derived class.The derived class destroys the contract of the base class and it is necessary to use `dynamic_cast` to convert the class to a subclass for special processing. In this case, it is more desirable to improve the design of the class, instead of using `dynamic_cast` to solve the problem. + +### Rec 9.3.2 Avoid using `reinterpret_cast`. + +**Note**: `reinterpret_cast` is used to convert irrelevant types. Trying to use `reinterpret_cast` to force a type to another type destroys the security and reliability of the type and is an insecure casting method. Avoid casting between completely different types. + +### Rec 9.3.3 Avoid using `const_cast`. + +**Note**: The `const_cast` command is used to remove the `const` and `volatile` properties of an object. + +The action of using a pointer or reference after the const_cast conversion to modify the const property of an object is undefined. + +```cpp +// Bad example: +const int i = 1024; +int* p = const_cast(&i); +*p = 2048; // The action is undefined. +``` + +```cpp +// Bad example: +class Foo { +public: + Foo() : i(3) {} + + void Fun(int v) + { + i = v; + } + +private: + int i; +}; + +int main(void) +{ + const Foo f; + Foo* p = const_cast(&f); + p->Fun(8); // The action is undefined. +} + +``` + + +## Resource Allocation and Release + +### Rule 9.4.1 When a single object is released, delete is used. When an array object is released, delete [] is used. +Note: To delete a single object, use delete; to delete an array object, use delete []. The reasons are as follows: + +- new: Apply for memory from the system and call the corresponding constructor to initialize an object. +- new[n]: Apply for memory for n objects and call the constructor n times for each object to initialize them. +- delete: Call the corresponding destructor first and release the memory of an object. +- delete[]: Call the corresponding destructor for each object and release their memory. + +If the usage of new and delete does not match this format, the results are unknown. For a non-class type, new and delete will not call the constructor or destructor. + +Bad example: +```cpp +const int MAX_ARRAY_SIZE = 100; +int* numberArray = new int[MAX_ARRAY_SIZE]; +... +delete numberArray; +numberArray = NULL; +``` + +Good example: +```cpp +const int MAX_ARRAY_SIZE = 100; +int* numberArray = new int[MAX_ARRAY_SIZE]; +... +delete[] numberArray; +numberArray = NULL; +``` + +### Rec 9.4.1 Use the RAII feature to trace dynamic allocation. + +Note: RAII is an acronym for Resource Acquisition Is Initialization. It is a simple technology that controls program resources (such as memory, file handle, network connections, and mutexes) by using the object lifecycle. + +The common practice is as follows: When the object is constructed, the resource is obtained, and the access to the resource is controlled so that the resource is always valid in the life cycle of the object. Finally, the resource is released when the object is destructed. This approach has two advantages: +- We do not need to explicitly release resources. +- The resources required by the object are always valid throughout the lifecycle of the object. This way, you do not need to check the validity of the resources, which simplifies logic and improves efficiency. + + +In the following example, RAII removes the need for explicit release of mutex resources. + +```cpp +class LockGuard { +public: + LockGuard(const LockType& lockType): lock_(lockType) + { + lock_.Aquire(); + } + + ~LockGuard() + { + lock_.Relase(); + } + +private: + LockType lock_; +}; + + +bool Update() +{ + LockGuard lockGuard(mutex); + if (...) { + return false; + } else { + // Data operations + } + + return true; +} +``` + +## Standard Template Library + +The standard template library (STL) varies between products. The following table lists some basic rules and suggestions for each team. + +### Rule 9.5.1 Do not save the pointer returned by c_str () of std::string. + +Note: The C++ standard does not specify that the string::c_str () pointer is permanently valid. Therefore, the STL implementation used can return a temporary storage area and release it quickly when calling string::c_str (). Therefore, to ensure the portability of the program, do not save the result of string::c_str (). Instead, call it directly. + +Example: + +```cpp +void Fun1() +{ + std::string name = "demo"; + const char* text = name.c_str(); // After the expression ends, the life cycle of name is still in use and the pointer is valid. + + // If a non-const member function (such as operator[] and begin()) of the string type is invoked and the string is modified, + // The text may become unavailable or may not be the original string. + name = "test"; + name[1] = '2'; + + // When the text pointer is used next time, the string is no longer "demo". +} + +void Fun2() +{ + std::string name = "demo"; + std::string test = "test"; + const char* text = (name + test).c_str(); // After the expression ends, the temporary object generated by the + operator may be destroyed, and the pointer may be invalid. + + // When the text pointer is used next time, it no longer points to the valid memory space. +} +``` +Exception: In rare cases where high performance coding is required , you can temporarily save the pointer returned by string::c_str() to match the existing functions which support only the input parameters of the const char* type. However, you should ensure that the lifecycle of the string object is longer than that of the saved pointer, and that the string object is not modified within the lifecycle of the saved pointer. + + +### Rec 9.5.1 Use std::string instead of char*. + +Note: Using string instead of `char*` has the following advantages: +1. There is no need to consider the null character '\0' at the end. +2. You can directly use operators such as `+`, `=`, and `==`, and other character and string operation functions. +3. There is no need to consider memory allocation operations.This helps avoid explicit usage of `new` and `delete` and the resulting errors. + +Note that in some STL implementations, string is based on the copy-on-write policy, which causes two problems. One is that the copy-on-write policy of some versions does not implement thread security, and the program breaks down in multi-threaded environments. Second, dangling pointers may be caused when a dynamic link library transfers the string based on the copy-on-write policy, due to the fact that reference count cannot be reduced when the library is unloaded. Therefore, it is important to select a reliable STL implementation to ensure the stability of the program. + +Exception: +When an API of a system or other third-party library is called, only `char*` can be used for defined interfaces. However, before calling the interfaces, you can use string. When calling the interfaces, you can use `string::c_str()` to obtain the character pointer. +When a character array is allocated as a buffer on the stack, you can directly define the character array without using string or containers such as `vector`. + +### Rule 9.5.2 Do not use auto_ptr. +Note: The `std::auto_ptr` in the STL library has an implicit ownership transfer behavior. The code is as follows: +```cpp +auto_ptr p1(new T); +auto_ptr p2 = p1; +``` +After the second line of statements is executed, p1 does not point to the object allocated in line 1 and becomes `NULL`. Therefore, `auto_ptr` cannot be placed in any standard containers. +This ownership transfer behavior is not expected. In scenarios where ownership must be transferred, implicit transfer should not be used. This often requires the programmer to keep extra attention on code that uses `auto_ptr`, otherwise access to a null pointer will occur. +There are two common scenarios for using auto_ptr . One is to transfer it as a smart pointer to outside the function that generates the auto_ptr , and the other is to use auto_ptr as the RAII management class. Resources are automatically released when the lifecycle of auto_ptr expires. +In the first scenario, you can use std::shared_ptr instead. +In the second scenario, you can use std::unique_ptr in the C++ 11 standard. std::unique_ptr is a substitute for std::auto_ptr and supports explicit ownership transfer. + +Exception: +Before the C++ 11 standard is widely used, std::auto_ptr can be used in scenarios where ownership needs to be transferred. However, it is recommended that std::auto_ptr be encapsulated. The copy constructor and assignment operator of the encapsulation class should not be used in a standard container. + + +### Rec 9.5.2 Use the new standard header files. + +Note: +When using the standard header file of C++, use `` instead of ``. + +## Usage of const +Add the keyword const before the declared variable or parameter (example: `const int foo`) to prevent the variable from being tampered with. Add the const qualifier to the function in the class (example: `class Foo {int Bar (char c) const;} ;`) to make sure the function does not modify the status of the class member variable. const variables, data members, functions, and parameters ensure that the type detection during compilation is accurate and errors are found as soon as possible. Therefore, we strongly recommend that const be used in any possible case. +Sometimes it is better to use constexpr from C++ 11 to define real constants. + +### Rule 9.6.1 For formal parameters of pointer and reference types, if the parameters do not need to be modified, use const. +Unchanging values are easier to understand, trace, and analyze. `const` is used as the default option and is checked during compilation to make the code more secure and reliable. +```cpp +class Foo; + +void PrintFoo(const Foo& foo); +``` + +### Rule 9.6.2 For member functions that do not modify member variables, use const. +Declare the member function as `const` whenever possible. The access function should always be const. So long as the function of a member is not modified, the function is declared with const. +When you need to modify data members in a virtual function, take all classes in the inheritance chain into account instead of only focusing on the implementation of a single class. +```cpp +class Foo { +public: + + // ... + + int PrintValue() const // const modifies member functions and does not modify member variables. + { + std::cout << value_ << std::endl; + } + + int GetValue() const // const modifies member functions and does not modify member variables. + { + return value_; + } + +private: + int value_; +}; +``` + +### Rec 9.6.1 Member variables that will not be modified after initialization should be defined as constants. + +```cpp +class Foo { +public: + Foo(int length) : dataLength_(length) {} +private: + const int dataLength_; +}; +``` + +## Exceptions + +### Rec 9.7.1 If the function does not throw an exception, the declaration is `noexcept`. +**Reasons:** +1. If the function does not throw an exception, the declaration is `noexcept`, which enables the compiler to optimize the function to the maximum extent, for example, reducing the execution paths and improving the efficiency of exiting when an error occurs. +2. For STL containers such as `vector`, to ensure the interface robustness, if the `move ` constructor of saved items is not declared as `noexcept`, the `copy machanism` instead of the `move machanism` is used when the items are removed from the container. This would cause performance loss risks. If the function does not throw an exception, or a program does not intercept and process an exception thrown by the function, new `noexcept` keywords can be used to modify the function, indicating that the function does not throw an exception or the thrown exception is not intercepted or processed. For example: + +```cpp +extern "C" double sqrt(double) noexcept; // No exceptions are thrown. + +// noexcept can still be used when exceptions may be thrown. +// The exception of memory exhaustion is not processed. The function is simply declared as noexcept. +std::vector MyComputation(const std::vector& v) noexcept +{ + std::vector res = v; // Exceptions may be thrown. + // do something + return res; +} +``` + +**Example:** + +```cpp +RetType Function(Type params) noexcept; // Maximized optimization +RetType Function(Type params) noexcept; // No optimization + +// Declaration as noexcept for the move operation of std::vector is needed. +class Foo1 { +public: + Foo1(Foo1&& other); // no noexcept +}; + +std::vector a1; +a1.push_back(Foo1()); +a1.push_back(Foo1()); // The copy constructor is called to enable the container expansion and removal of existing items. + +class Foo2 { +public: + Foo2(Foo2&& other) noexcept; +}; + +std::vector a2; +a2.push_back(Foo2()); +a2.push_back(Foo2()); //Triggers container expansion and invokes the move constructor to move existing elements. +``` + +**Note** +The default constructor, destructor, `swap` function, and `move` operator should not throw an exception. + +## Templates and Generic Programming + +### Rule 9.8.1 Do not use generic programming. +OpenHarmony adopts object-oriented programming, which has ideas, concepts, and techniques totally different from those of generic programming. + +Generic programming in C++ allows for extremely flexible interfaces that are type safe and high performance, enabling reuse of code of different types but with the same behavior. + +However, generic programming has the following disadvantages: + +1. People who are not familiar with generic programming often write into templates object-oriented logic or members that do not depend on template parameters, making the code unreadable or bloated. +2. The techniques used in generic programming are often obscure to anyone but language experts. Template code can be unreadable in certain cases. +3. Generic programming often leads to extremely poor compile time error messages. The uncalled-for implementation details of APIs are displayed to users in the error messages, making even a simple API difficult to debug. +4. Inappropriate use of templates cause code bloat during runtime. +5. It is difficult to modify or refactor the template code. The template code is expanded in multiple contexts, and it is hard to verify that the code refactoring makes sense in all of them. + +Only __a few components of OpenHarmony__ support generic programming, and the templates developed using generic programming must have detailed comments. +Exceptions: +1. The STL adaptation layer can use generic programming. + +## Macros +In the C++ language, it is strongly recommended that complex macros be used as little as possible. +- For constant definitions, use `const` or `enum` as stated in the preceding sections. +- For macro functions, try to be as simple as possible, comply with the following principles, and use inline functions and template functions for replacement. + +```cpp +// The macro function is not recommended. +#define SQUARE(a, b) ((a) * (b)) + +// Use the template function and inline function as a replacement. +template T Square(T a, T b) { return a * b; } +``` + +For details about how to use macros, see the related chapters about the C language specifications. +**Exception**: For some common and mature applications, for example, encapsulation for new and delete, the use of macros can be retained. + +# 10 Modern C++ Features + +As the ISO released the C++ 11 language standard in 2011 and released the C++ 17 in March 2017, the modern C++ (C++ 11/14/17) adds a large number of new language features and standard libraries that improve programming efficiency and code quality. +This chapter describes some guidelines for modern C++ use, to avoid language pitfalls. + +## Code Simplicity and Security Improvement +### Rec 10.1.1 Use `auto` properly. +**Reasons** + +* `auto` can help you avoid writing verbose, repeated type names, and can also ensure initialization when variables are defined. +* The `auto` type deduction rules are complex and need to be read carefully. +* If using `auto` makes the code clearer, use a specific type of it and use it only for local variables. + +**Example** + +```cpp +// Avoid verbose type names. +std::map::iterator iter = m.find(val); +auto iter = m.find(val); + +// Avoid duplicate type names. +class Foo {...}; +Foo* p = new Foo; +auto p = new Foo; + +// Ensure that the initialization is successful. +int x; // The compilation is correct but the variable is not initialized. +auto x; // The compilation failed. Initialization is needed. +``` + +`auto` type deduction may cause the following problems: + +```cpp +auto a = 3; // int +const auto ca = a; // const int +const auto& ra = a; // const int& +auto aa = ca; // int, const and reference are neglected. +auto ila1 = { 10 }; // std::initializer_list +auto ila2{ 10 }; // std::initializer_list + +auto&& ura1 = x; // int& +auto&& ura2 = ca; // const int& +auto&& ura3 = 10; // int&& + +const int b[10]; +auto arr1 = b; // const int* +auto& arr2 = b; // const int(&)[10] +``` + +If you do not pay attention to `auto` type deduction and ignore the reference, hard-to-find performance problems may be created. + +```cpp +std::vector v; +auto s1 = v[0]; // auto deduction changes s1 to std::string in order to copy v[0]. +``` + +If `auto` is used to define an interface, such as a constant in a header file, the type may be changed if the developer has modified the value. + +### Rule 10.1.1 Use the keyword `override` when rewriting virtual functions. +**Reason:** +The keyword `override` ensures that the function is a virtual function and an overridden virtual function of the base class. If the subclass function is different from the base class function prototype, a compilation alarm is generated. `final` also ensures that virtual functions are not overridden by subclasses. + +If you modify the prototype of a base class virtual function but forget to modify the virtual function overridden by the subclass, you can find inconsistency during compilation. You can also avoid forgetting to modify the overridden function when there are multiple subclasses. + +**Example** + +```cpp +class Base { +public: + virtual void Foo(); + virtual void Foo(int var); + void Bar(); +}; + +class Derived : public Base { +public: + void Foo() const override; // Compilation failed: derived::Foo is different from that of the prototype of base::Foo and is not overridden. + void Foo() override; // Compilation successful: derived::Foo overrode base::Foo. + void Foo(int var) final; // Compilation successful: Derived::Foo(int) rewrites Base::Foo(int), and the derived class of Derived cannot override this function. + void Bar() override; // Compilation failed: base::Bar is not a virtual function. +}; +``` + +**Summary** +1. When defining the virtual function for the first time based on the base class, use the keyword `virtual`. +2. When overriding the virtual function by a subclass in a base class, including destructors, use the keyword `override` or `final` instead of `virtual`. +3. For the non-virtual function, do not use `virtual` or `override`. + +### Rule: 10.1.2 Use the keyword `delete` to delete functions. +**Reason** +The `delete` keyword is clearer and the application scope is wider than a class member function that is declared as private and not implemented. + +**Example:** + +```cpp +class Foo { +private: + // Whether the copy structure is deleted or not is unknown because usually only the header file is checked. + Foo(const Foo&); +}; + +class Foo { +public: + // Explicitly delete the copy assignment operator. + Foo& operator=(const Foo&) = delete; +}; +``` + +The `delete` keyword can also be used to delete non-member functions. + +```cpp +template +void Process(T value); + +template<> +void Process(void) = delete; +``` + +### Rule 10.1.3 Use `nullptr` instead of `NULL` or `0`. +**Reason:** +For a long time, C++ has not had a keyword that represents a null pointer, which is embarrassing: + +```cpp +#define NULL ((void *)0) + +char* str = NULL; // Error: void* cannot be automatically converted to char*. + +void(C::*pmf)() = &C::Func; +if (pmf == NULL) {} // Error: void* cannot be automatically converted to the pointer that points to the member function. +``` + +If `NULL` is defined as `0` or `0L`, the above problems can be solved. + +Alternatively, use `0` directly in places where null pointers are required. However, another problem occurs. The code is not clear, especially when `auto` is used for automatic deduction. + +```cpp +auto result = Find(id); +if (result == 0) { // Does Find() return a pointer or an integer? + // do something +} +``` + +Literally `0` is of the `int` type (`0L` is the `long` type). Therefore, neither `NULL` nor `0` is a pointer type. +When a function of the pointer or integer type is overloaded, `NULL` or `0` calls only the overloaded pointer function. + +```cpp +void F(int); +void F(int*); + +F(0); // Call F(int) instead of F(int*). +F(NULL); // Call F(int) instead of F(int*). +``` + +In addition, `sizeof(NULL) == sizeof(void*)` does not always make sense, which is a potential risk. + +Summary: If `0` or `0L` is directly used, the code is not clear and type security cannot be ensured. If `NULL` is used, the type security cannot be ensured. These are all potential risks. + +`nullptr` has many advantages. It literally represents the null pointer and makes the code clearer. More to the point, it is no longer an integer type. + +`nullptr` is of the `std::nullptr_t` type. `std::nullptr_t` can be implicitly converted into all original pointer types, so that `nullptr` can represent a null pointer that points to any type. + +```cpp +void F(int); +void F(int*); +F(nullptr); // Call F(int*). + +auto result = Find(id); +if (result == nullptr) { // Find() returns a pointer. + // do something +} +``` + +### Rule 10.1.4 Use `using` instead of `typedef`. +For versions earlier than `C++11`, you can define the alias of the type by using `typedef`. No one wants to repeat code like `std::map>`. + +```cpp +typedef std::map> SomeType; +``` + +Using alias for the type is actually encapsulating the type. This encapsulation makes the code clearer, and to a large extent avoids the bulk modification caused by the type change. +For versions supporting C++ 11 features, `using` is provided to implement `alias declarations`: + +```cpp +using SomeType = std::map>; +``` + +Compare the two formats: + +```cpp +typedef Type Alias; // It cannot be told whether the original Type or Alias is at the front. +using Alias = Type; // The format confirms to the assignment rule. It is easy to understand and helps reduce errors. +``` + +If this is not enough to prove the advantages of `using`, the alias template may be a better example: + +```cpp +//: Only one line of code is need to define an alias for a template. +template +using MyAllocatorVector = std::vector>; + +MyAllocatorVector data; // An alias for a template defined with "using". + +template +class MyClass { +private: + MyAllocatorVector data_; // Another. +}; +``` + +`typedef` does not support alias templates and they have to be hacked in. + +```cpp +// A template is used for packaging typedef. Therefore, a template class is needed. +template +struct MyAllocatorVector { + typedef std::vector> type; +}; + +MyAllocatorVector::type data; // ::type needs to be added when using typedef to define an alias. + +template +class MyClass { +private: + typename MyAllocatorVector::type data_; // For a template class, typename is also needed in addition to ::type. +}; +``` + +### Rule 10.1.5 Do not use std::move to operate the const object. +Literally, `std::move` means moving an object. The const object cannot be modified and cannot be moved. Therefore, using `std::move` to operate the const object may confuse code readers. +Regarding actual functions, `std::move` converts an object to the rvalue reference type. It can convert the const object to the rvalue reference of const. Because few types define the move constructor and the move assignment operator that use the const rvalue reference as the parameter, the actual function of code is often degraded to object copy instead of object movement, which brings performance loss. + +**Bad example:** +```cpp +std::string g_string; +std::vector g_stringList; + +void func() +{ + const std::string myString = "String content"; + g_string = std::move(myString); // Bad: myString is not moved. Instead, it is copied. + const std::string anotherString = "Another string content"; + g_stringList.push_back(std::move(anotherString)); // Bad: anotherString is not moved. Instead, it is copied. +} +``` + +## Smart Pointers +### Rule 10.2.1 Preferentially use the original pointer source instead of the smart pointer for singletons and class members that are not held by multiple parties. +**Reason:** +Smart pointers automatically release object resources to prevent resource leakage, but they require extra resource overheads. For example, the classes, constructors, and destructors automatically generated by smart pointers consume more resources such as memory. + +When singletons, class members, and the like are not held by multiple parties, resources can be released only in class destructors. In this case, smart pointers should not be used. + +**Example:** + +```cpp +class Foo; +class Base { +public: + Base() {} + virtual ~Base() + { + delete foo_; + } +private: + Foo* foo_ = nullptr; +}; +``` + +**Exceptions** +1. When a created object is returned, a smart pointer can be used if the pointer destructor is required. +```cpp +class User; +class Foo { +public: + std::unique_ptr CreateUniqueUser() // Use unique_ptr to ensure that the object is created and released in the same runtime. + { + sptr ipcUser = iface_cast(remoter); + return std::unique_ptr(::new User(ipcUser), [](User *user) { + user->Close(); + ::delete user; + }); + } + + std::shared_ptr CreateSharedUser() // Use shared_ptr to ensure that the object is created and released in the same runtime. + { + sptr ipcUser = iface_cast(remoter); + return std::shared_ptr(ipcUser.GetRefPtr(), [ipcUser](User *user) mutable { + ipcUser = nullptr; + }); + } +}; +``` +2. When the created object is returned and needs to be referenced by multiple parties, `shared_ptr` can be used. + +### Rule 10.2.2 Use `unique_ptr` instead of `shared_ptr`. +**Reasons:** +1. Using `shared_ptr` a lot has an overhead (atomic operations on the `shared_ptr`s reference count have a measurable cost). +2. Shared ownership in some cases (such as circular dependency) may create objects that can never be released. +3. Shared ownership can be an attractive alternative to careful ownership design but it may obfuscate the design of a system. + +### Rule 10.2.2 Use `std::make_unique` instead of `new` to create a `unique_ptr`. +**Reasons:** +1. `make_unique` provides a simpler creation method. +2. `make_unique` ensures the exception safety of complex expressions. + +**Example:** + +```cpp +// Bad: MyClass appears twice, which carries a risk of inconsistency. +std::unique_ptr ptr(new MyClass(0, 1)); +// Good: MyClass appears once and there is no possibility of inconsistency. +auto ptr = std::make_unique(0, 1); +``` + +Recurrence of types may cause serious problems, and it is difficult to find them: + +```cpp +// The code compiles fine, but new and delete usage does not match. +std::unique_ptr ptr(new uint8_t[10]); +std::unique_ptr ptr(new uint8_t); +// No exception safety: The compiler may calculate parameters in the following order: +// 1. Allocate the memory of Foo. +// 2. Construct Foo. +// 3. Call Bar. +// 4. Construct unique_ptr. +// If Bar throws an exception, Foo is not destroyed and a memory leak occurs. +F(unique_ptr(new Foo()), Bar()); + +// Exception safety: Calling of function is not interrupted. +F(make_unique(), Bar()); +``` + +**Exception:** +`std::make_unique` does not support user-defined `deleter`. +In the scenario where the `deleter` needs to be customized, it is recommended that `make_unique` be implemented in the customized version's own namespace. +Using `new` to create `unique_ptr` with the user-defined `deleter` is the last choice. + +### Rule 10.2.4 Create `shared_ptr` by using `std::make_shared` instead of `new`. +**Reason:** +In addition to the consistency factor similar to that in `std::make_unique` when using `std::make_shared`, performance is also a factor to consider. +`std::shared_ptr` manages two entities: +* Control block (storing reference count, `deleter`, etc.) +* Managed objects + +When `std::make_shared` creates `std::shared_ptr`, it allocates sufficient memory for storing control blocks and managed objects on the heap at a time. When `std::shared_ptr(new MyClass)`is used to create a `std::shared_ptr`, not only does `new MyClass` trigger heap allocation, but the constructor function of `std::shard_ptr` triggers a second heap allocation, resulting in extra overhead. + +**Exception:** +Similar to `std::make_unique`, `std::make_shared` does not support `deleter` customization. + +## Lambda +### Rec 10.3.1 Use `lambda` to capture local variables or write local functions when normal functions do not work. +**Reason:** +Functions cannot capture local variables or be declared at local scope. If you need those things, choose `lambda` instead of handwritten `functor`. +On the other hand, `lambda` and `functor` objects do not support overloading. If overloading is required, use a function. +If both `lambda` and functions work, a function is preferred. Use the simplest tool. + +**Example:** + +```cpp +// Write a function that accepts only an int or string. +// -- Overloading is more natural. +void F(int); +void F(const string&); + +// The local state needs to be captured or appear in the statement or expression range. +// -- A lambda is more natural. +vector v = LotsOfWork(); +for (int taskNum = 0; taskNum < max; ++taskNum) { + pool.Run([=, &v] {...}); +} +pool.Join(); +``` + +### Rule 10.3.1 Avoid capturing by reference in lambdas that will not be used locally. +**Reason:** +Using `lambdas` at a "nonlocal" scope includes returning, storing on the heap, and passing to another thread. Local pointers and references should not outlive their scope. Capturing by reference in `lambdas` indicates storing a reference to a local object. If this leads to a reference that exceeds the lifecycle of a local variable, capturing by reference should not be used. + +**Example:** + +```cpp +// Bad +void Foo() +{ + int local = 42; + // Capture a reference to a local variable. + // After the function returns results, local no longer exists, + // Process() call will have undefined behavior. + threadPool.QueueWork([&]{ Process(local); }); +} + +// Good +void Foo() +{ + int local = 42; + // Capture a copy of local. + // Since a copy of local is made, it will be always available for the call. + threadPool.QueueWork([=]{ Process(local); }); +} +``` + +### Rec 10.3.2 All variables are explicitly captured if `this` is captured. +**Reason:** +The `[=]` in the member function seems to indicate capturing by value but actually it is capturing data members by reference because it captures the invisible `this` pointer by value. Generally, it is recommended that capturing by reference be avoided. If it is necessary to do so, write `this` explicitly. + +**Example:** + +```cpp +class MyClass { +public: + void Foo() + { + int i = 0; + + auto Lambda = [=]() { Use(i, data_); }; // Bad: It looks like we are copying or capturing by value but member variables are actually captured by reference. + + data_ = 42; + Lambda(); // Call use(42); + data_ = 43; + Lambda(); // Call use(43); + + auto Lambda2 = [i, this]() { Use(i, data_); }; // Good: the most explicit and least confusing method. + } + +private: + int data_ = 0; +}; +``` + +### Rec 10.3.3 Avoid default capture modes. +**Reason:** +The lambda expression provides two default capture modes: by-reference (&) and by-value (=). +By default, the "by-reference" capture mode will implicitly capture the reference of all local variables, which will easily lead to dangling references. By contrast, explicitly writing variables that need to be captured can make it easier to check the lifecycle of an object and reduce the possibility of making a mistake. +By default, the "by-value" capture mode will implicitly capture this pointer, and it is difficult to find out which variables the lambda function depends on.If a static variable exists, the reader mistakenly considers that the lambda has copied a static variable. +Therefore, it is required to clearly state the variables that lambda needs to capture, instead of using the default capture mode. + +**Bad example:** +```cpp +auto func() +{ + int addend = 5; + static int baseValue = 3; + + return [=]() { // Only addend is actually copied. + ++baseValue; // The modification will affect the value of the static variable. + return baseValue + addend; + }; +} +``` + +**Good example:** +```cpp +auto func() +{ + int addend = 5; + static int baseValue = 3; + + return [addend, baseValue = baseValue]() mutable { // Uses the C++14 capture initialization to copy a variable. + ++baseValue; // Modifying the copy of a static variable does not affect the value of the static variable. + return baseValue + addend; + }; +} +``` + +Reference: Effective Modern C++: Item 31: Avoid default capture modes. + +## Interfaces +### Rec 10.4.1 Use `T*` or `T&` arguments instead of a smart pointer in scenarios where ownership is not involved. +**Reasons:** +1. Passing a smart pointer to transfer or share ownership should only be used when the ownership mechanism is explicitly required. +2. Passing a smart pointer (for example, passing the `this` smart pointer) restricts the use of a function to callers using smart pointers. +3. Passing a shared smart pointer adds a runtime performance cost. + +**Example:** + +```cpp +// Accept any int*. +void F(int*); + +// Accept only integers for which you want to transfer ownership. +void G(unique_ptr); + +// Accept only integers for which you want to share ownership. +void G(shared_ptr); + +// Does not need to change the ownership but requires ownership of the caller. +void H(const unique_ptr&); + +// Accept any int. +void H(int&); + +// Bad +void F(shared_ptr& w) +{ + // ... + Use(*w); // When only w is used, lifecycle management is not required. + // ... +}; +``` diff --git a/website/docs/extras/en/contribute/OpenHarmony-hdf-coding-guide.md b/website/docs/extras/en/contribute/OpenHarmony-hdf-coding-guide.md new file mode 100644 index 0000000000000000000000000000000000000000..6d8db190d5c35276a73bcaebc349d9191c1645db --- /dev/null +++ b/website/docs/extras/en/contribute/OpenHarmony-hdf-coding-guide.md @@ -0,0 +1,650 @@ +--- +title: "OpenHarmony-hdf-coding-guide" +prepermalink: /extras/43ea9b0c9cd7413e590a371da3c7550c/ +permalink: /extras/43ea9b0c9cd7413e590a371da3c7550c/ +relpath: "OpenHarmony-3.1-Release/en/contribute/OpenHarmony-hdf-coding-guide.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [OpenHarmony-hdf-coding-guide] +--- +# HDF Driver Coding Guide + +## About This Document + +### Purpose + +OpenHarmony aims to build an open, distributed OS framework for smart IoT devices in the full-scenario, full-connectivity, and full-intelligence era. It has the following technical features: hardware collaboration for resource sharing, one-time development for multi-device deployment, and a unified OS for flexible deployment. + +The Hardware Driver Foundation (HDF) provides the following driver framework capabilities: driver loading, driver service management, and driver message mechanism. This unified driver architecture system is designed to provide a more precise and efficient development environment, where you can perform one-time driver development for multi-system deployment. + +As such, certain coding specifications are required for the OpenHarmony driver implemented based on the HDF. This document stipulates the specifications on the driver code, helping you improve code standardization and portability. + +## Coding Guide + +### General Principles + +#### [Rule] Use the capabilities provided by the HDF to implement drivers. + +[Description] The HDF supports driver loading, driver service management, and driver message mechanism. It provides the Operating System Abstraction Layer (OSAL) and Platform Abstraction Layer (PAL) to support cross-system and cross-platform driver deployment. It also provides capabilities such as driver model abstraction, common tools, and peripheral component framework. You should develop drivers based on these capabilities to ensure that the drivers can be deployed on various devices powered by OpenHarmony. + +#### [Rule] Follow this coding guide to develop drivers that can run in both the kernel space and user space. + +[Description] Kernel-mode drivers are different from user-mode drivers in essence. They apply to different use cases. You must follow this guide during service design and development and use the HDF OSAL and PAL to shield the differences, so as to ensure that the drivers can run in both the kernel space and user space. + +#### [Rec] Include the drivers/framework/include directory instead of a subdirectory in the build script. + +[Description] The **drivers/framework/include** directory is the root directory of the header file exposed by the HDF externally. This directory contains multiple subdirectories to represent different modules such as the core framework, OSAL, and PAL. When using a header file, you are advised to include the **drivers/framework/include** directory in the build script. This avoids repeated inclusion when the script is referenced in the code. + +[Example] + +```gn +config("xxxx_private_config") { + include_dirs = [ + "//drivers/framework/include", + "//drivers/framework/include/core", # Not recommended. + ] +} +``` + +```c +#include +#include // Not recommended. +``` + +### HDF Core Framework + +#### [Rule] Implement the Bind, Init, and Release methods based on the responsibility definitions in the HdfDriverEntry object. + +[Description] The **HdfDriverEntry** object is the entry of an HDF driver. The **Bind**, **Init**, and **Release** methods have their own responsibilities. You must implement the corresponding functions based on the responsibilities. + +```c +struct HdfDriverEntry g_sampleDriverEntry = { + .moduleVersion = 1, + .moduleName = "sample_driver", + .Bind = SampleDriverBind, // Responsibility: Bind the service interface provided by the driver to the HDF. + .Init = SampleDriverInit, // Responsibility: Initialize the driver service. + .Release = SampleDriverRelease, // Responsibility: Release driver resources. It is invoked when an exception occurs. +}; + +HDF_INIT(g_sampleDriverEntry); +``` + +#### [Rule] The first member in the driver service structure must be of the IDeviceIoService type. + +[Description] The first member of the service interface defined by the driver must be of the **IDeviceIoService** type. + +[Example] + +```c +struct ISampleDriverService { + struct IDeviceIoService ioService; // The first member must be of the IDeviceIoService type. + int32_t (*FunctionA)(void); // The first service interface of the driver. + int32_t (*FunctionB)(uint32_t inputCode); // The second service interface of the driver. More service interfaces can be added here. +}; +``` + +[Example] + +```c +struct ISampleDriverService { + struct IDeviceIoService ioService; // The first member must be of the IDeviceIoService type. + void *instance; // A service instance can be encapsulated here to provide service interfaces. +}; +``` + +#### [Rule] All driver service interfaces must be bound using the Bind method of the HdfDriverEntry object. All service interfaces must be defined. They cannot be defined as null. + +[Description] The service interfaces defined by the driver are exposed externally. If a service interface is not defined or is defined as null, exceptions may occur during external invocation. + +[Example] + +```c +int32_t SampleDriverBind(struct HdfDeviceObject *deviceObject) +{ + static struct ISampleDriverService sampleDriver = { + .FunctionA = SampleDriverServiceA, + .FunctionB = NULL, // The service interface cannot be defined as null. + }; + // Bind ioService to the device object created by the HDF. + deviceObject->service = &sampleDriver.ioService; + return HDF_SUCCESS; +} +``` + +#### [Rec] Call the HdfDeviceSetClass interface in the Init method of the HdfDriverEntry object to define the driver type. + +[Description] Based on the driver type, you can classify the drivers of the current device and query the driver capabilities of the current device. For better driver management, you are advised to call **HdfDeviceSetClass** to set the driver type. + +[Example] + +```c +int32_t SampleDriverInit(struct HdfDeviceObject *deviceObject) +{ + // Set the driver type to DISPLAY. + if (!HdfDeviceSetClass(deviceObject, DEVICE_CLASS_DISPLAY)) { + HDF_LOGE("HdfDeviceSetClass failed"); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} +``` + +### HCS + +HDF Configuration Source (HCS) describes the configuration source code of the HDF in the form of key-value pairs. It decouples configuration code from driver code, making it easy for you to manage the driver configuration. + +The driver configuration consists of the driver device description defined by the HDF and the private configuration of a driver. + +**Driver Device Description** + +The driver loading information required by the HDF comes from the driver device description. Therefore, you must add the driver device description to the **device_info.hcs** file defined by the HDF. + +#### [Rule] Before configuring a driver, determine the hardware to which the driver belongs and the deployment mode, and plan the directories and files to be configured. + +[Description] In the **vendor** directory of the OpenHarmony source code, plan the directories based on the chip vendor, development board, and configuration. The HDF driver configuration is stored in the **hdf\_config** directory. According to the hardware specifications, the **hdf\_config** directory stores kernel-mode configuration information or both kernel- and user-mode configuration information. You should determine the directory where the driver is to be configured based on the driver hardware and deployment mode. + +[Example] + +```bash +$openharmony_src_root/vendor/hisilicon/hispark_taurus/hdf_config # Directory for storing the kernel-mode configuration file. There are no user-mode configuration files. + +$openharmony_src_root/vendor/hisilicon/Hi3516DV300/hdf_config/khdf # Directory for storing the kernel-mode configuration file. +$openharmony_src_root/vendor/hisilicon/Hi3516DV300/hdf_config/uhdf # Directory for storing the user-mode configuration file. +$openharmony_src_root/vendor/hisilicon/Hi3516DV300/hdf_config/khdf/device_info/device_info.hcs # Device description file of the kernel-mode driver. +$openharmony_src_root/vendor/hisilicon/Hi3516DV300/hdf_config/khdf/lcd/lcd_config.hcs # Private configuration file of the kernel-mode driver. +``` + +#### [Rule] Use existing configuration information and inherit existing configuration templates during driver configuration. + +[Description] The **host**, **device**, and **deviceNode** templates have been configured in the **device_info.hcs** file. When configuring a driver, make full use of the existing configuration information and inherit HCS features to minimize your configuration workload. + +[Example] + +``` +root { + device_info { + match_attr = "hdf_manager"; + template host { // host template + hostName = ""; + priority = 100; // Host startup priority. The value ranges from 0 to 200. A larger value indicates a lower priority. The default value 100 is recommended. If the priorities are the same, the host loading sequence cannot be ensured. + template device { // device template + template deviceNode { // deviceNode template + policy = 0; // Policy for publishing drive services. + priority = 100; // Driver startup priority. The value ranges from 0 to 200. A larger value indicates a lower priority. The default value 100 is recommended. If the priorities are the same, the device loading sequence cannot be ensured. + preload = 0; // The driver is loaded as required. + permission = 0664; // Permission for the driver to create a device node. + moduleName = ""; + serviceName = ""; + deviceMatchAttr = ""; + } + } + } + // To use the default values in the template, the node fields can be not included. + sample_host :: host { // sample_host inherits the host template. + hostName = "host0"; // Host name. The host node is a container used to store a type of drivers. + device_sample :: device { // device_sample inherits the device template. + device0 :: deviceNode { // device0 inherits the deviceNode template. + policy = 1; // Overwrite the policy in the template. + moduleName = "sample_driver"; // Driver name. The value of this field must be the same as that of moduleName in the HdfDriverEntry structure. + serviceName = "sample_service"; // Service name of the driver, which must be unique. + deviceMatchAttr = "sample_config"; // Keyword for matching the private data of the driver. The value must be the same as that of match_attr in the private data configuration table of the driver. + } + } + } + } +} +``` + +#### [Rule] Use the defined types during driver model design and classification. Do not configure hosts and devices repeatedly. + +[Description] The HDF places the same type of devices in the same host. You can develop and deploy the driver functionalities of the host by layer, so that one driver has multiple nodes. The following figure shows the HDF driver model. + + + +Place devices of the same type in the same host. When adding a device, check whether the host of the same type already exists. If such a host already exists, configure the device in the host. Do not configure the same host again. A device belongs to only one driver. Therefore, do not configure the same device in different hosts. + +#### [Rule] Set publication policies for driver services based on service rules. + +[Description] The driver service is the object of capabilities provided by the driver to external systems and is managed by the HDF in a unified manner. The HDF uses the **policy** field in the configuration file to define policies for drivers to publish services externally. The values and meanings of this field are as follows: + +```c +typedef enum { + /* The driver does not provide services.*/ + SERVICE_POLICY_NONE = 0, + /* The driver provides services for kernel-space applications. */ + SERVICE_POLICY_PUBLIC = 1, + /* The driver provides services for both kernel- and user-space applications. */ + SERVICE_POLICY_CAPACITY = 2, + /** Driver services are not published externally but can be subscribed to. */ + SERVICE_POLICY_FRIENDLY = 3, + /* Driver services are not published externally and cannot be subscribed to. */ + SERVICE_POLICY_PRIVATE = 4, + /** Invalid policy. */ + SERVICE_POLICY_INVALID +} ServicePolicy; +``` + +You must set the policies based on service rules. Do not set unnecessary policies, for example, setting user-mode publication policies for kernel-mode drivers. + +[Example] + +``` +root { + device_info { + sample_host { + sample_device { + device0 { + policy = 1; // The driver provides services for kernel-space applications. + ... + } + } + } + } +} +``` + +#### [Rule] The permission to create device nodes for a driver must match the publication policy of the driver. + +[Description] In the **device_info.hcs** file, the **permission** field specifies the permission used by the driver to create a device node. This field is a 4-digit octal number and uses the Unix file permissions, for example, 0644. This field takes effect only when the driver provides services for user-space applications (policy = 2). + +You must ensure that the publication policy of the driver service matches the device node permission. Otherwise, access to the driver service may fail or the permission of the device node may be inappropriate. + +[Example] + +``` +root { + device_info { + sample_host { + sample_device { + device0 { + policy = 2; // The driver provides services for both kernel- and user-space applications. + permission = 0640; // Recommended value + ... + } + } + } + } +} +``` + +[Counterexample] + +``` +root { + device_info { + sample_host { + sample_device { + device0 { + policy = 2; // The driver provides services for both kernel- and user-space applications. + permission = 0777; // Excessive permission. + ... + } + } + } + } +} +``` + +[Counterexample] + +``` +root { + device_info { + sample_host { + sample_device { + device0 { + policy = 1; // The driver provides services for kernel-space applications but does not create a device node. + permission = 0640; // Redundancy configuration + ... + } + } + } + } +} +``` + +#### [Rule] Configure whether to load a driver as required based on service requirements. + +[Description] In the **device_info.hcs**, **preload** specifies the driver loading mode. The values and meanings of this field are as follows: + +```c +typedef enum { + /* The driver is loaded by default during the system boot process. */ + DEVICE_PRELOAD_ENABLE = 0, + /* The driver is loaded after a quick start is complete if the system supports quick start. If the system does not support quick start, this value has the same meaning as DEVICE\_PRELOAD\_ENABLE. */ + DEVICE_PRELOAD_ENABLE_STEP2, + /* The driver is not loaded during the system boot process. When a user-mode process requests the driver service, the HDF attempts to dynamically load the driver if the driver service does not exist. */ + DEVICE_PRELOAD_DISABLE, + /** Invalid value. */ + DEVICE_PRELOAD_INVALID +} DevicePreload; +``` + +Set the **preload** field based on the service requirements. + +[Example] + +``` +root { + device_info { + sample_host { + sample_device { + device0 { + preload = 2; // The driver is loaded as required. + ... + } + } + } + } +} +``` + +#### [Rec] When the preload field is set to 0, configure the loading priority based on the service requirements. + +[Description] In the **device_info.hcs** file, the **priority** field indicates the host and driver loading priority. The value of this field is an integer ranging from 0 to 200. For drivers in different hosts, a smaller priority value of the host indicates a higher driver loading priority. For drivers in the same host, a smaller priority value of the driver indicates a higher driver loading priority. The default value of the **priority** field is 100. If this field is not set or set to the same value for different drivers, the driver loading sequence cannot be ensured. You should configure the **priority** field based on the service requirements to ensure the driver loading sequence. + +[Example] + +``` +root { + device_info { + sample_host0 { + priority = 100; + sample_device { + device0 { + preload = 0; // The driver is loaded by default. + priority = 100; // The HDF ensures that the driver is loaded before device1. + ... + } + device1 { + preload = 0; // The driver is loaded by default. + priority = 200; // The HDF ensures that the driver is loaded after device0. + ... + } + } + } + sample_host1 { + priority = 100; // The HDF does not ensure the loading sequence because this host has the same priority as sample_host0. + ... + } + } +} +``` + +**Private Configuration Information of the Driver** + +If a driver has private configurations, you can add a driver configuration file to fill in default configurations of the driver. When loading the driver, the HDF obtains the configuration information, saves it in the **property** field of **HdfDeviceObject**, and passes it to the driver through **Bind** and **Init**. + +#### [Rule] Store the private configuration files of the drivers in different directories according to the component type or module. + +[Description] You must properly plan the directory for storing private configuration files of drivers. Do not store them in the root directory. + +[Example] + +```bash +$openharmony_src_root/vendor/hisilicon/Hi3516DV300/hdf_config/khdf/sample/sample_config.hcs # Correct. The private configuration file is stored in the sample directory. + +$openharmony_src_root/vendor/hisilicon/Hi3516DV300/hdf_config/khdf/sample_config.hcs # Incorrect. The private configuration file is placed in the root directory. +``` + +#### [Rule] Add the private configuration file of a driver to the hdf.hcs file in the hdf_config directory. + +[Description] The **hdf.hcs** file summarizes the configuration information. The HDF parses the file content and loads the private configuration information of the driver to the device node during the build and runtime. Include the private configuration file of the driver in the **hdf.hcs** file to trigger driver initialization. + +[Example] + +```c +#include "device_info/device_info.hcs" +#include "sample/sample_config.hcs" // The file contains the private configuration file of a driver. + +root { + module = "hisilicon,hi35xx_chip"; +} +``` + +#### [Rule] The value of the matchAttr field in the private configuration file of the driver must be the same as that of the deviceMatchAttr field in device_info.hcs. + +[Description] The HDF associates with the driver device through the **match_attr** field. A mismatch causes a failure to obtain the private configuration information. + +[Example] + +``` +root { + sample_config { + ... + match_attr = "sample_config"; // The value of this field must be the same as that of deviceMatchAttr in device_info.hcs. + } +} +``` + +#### [Rule] Use underscores (_) in field names in the private configuration file. + +[Description] According to the naming rules in the C/C++ coding guide, use underscores (_) in field names in the private configuration file of a driver. In this way, the naming rule is satisfied during the definition of the private configuration data structure in the implementation code. It also makes unified management of the code and configuration files easier. + +[Example] + +``` +root { + sample_config { + sample_version = 1; // Use an underscore (_) in the field name. + sample_bus = "I2C_0"; + match_attr = "sample_config"; + } +} +``` + +### HCS Macros + +The private configuration information of a driver is loaded to **property** of **HdfDeviceObject**. This occupies memory space, which should be avoided for mini- and small-system devices. To minimize the memory usage, the HDF provides HCS macros to parse the private configuration information. + +#### [Rule] Use HCS macros to parse the private configuration information in memory-sensitive or cross-system scenario. + +[Description] You should specify the use cases of drivers. In memory-sensitive scenarios or if a driver needs to be used in mini-, small-, and standard-system devices, use HCS macros to parse the private configuration information for higher performance and portability. + +[Example] + +```c +#include + +#define SAMPLE_CONFIG_NODE HCS_NODE(HCS_ROOT, sample_config) + +ASSERT_EQ(HCS_PROP(SAMPLE_CONFIG_NODE, sampleVersion), 1); +ASSERT_EQ(HCS_PROP(SAMPLE_CONFIG_NODE, sample_bus), "I2C_0"); +ASSERT_EQ(HCS_PROP(SAMPLE_CONFIG_NODE, match_attr), "sample_config"); +``` + +### HDF Tools + +#### [Rule] Determine the communication scenario and HdfSbuf type. + +[Description] **HdfSbuf** is a data structure used for data transfer. This structure is classified into different types based on the communication scenario. These types are defined in the **hdf_sbuf.h** header file. + +```c +enum HdfSbufType { + SBUF_RAW = 0, /* SBUF used for communication between the user space and the kernel space. */ + SBUF_IPC, /* SBUF used for inter-process communication (IPC). */ + SBUF_IPC_HW, /* Reserved for extension. */ + SBUF_TYPE_MAX, /* Maximum value of the SBUF type. */ +}; +``` + +Determine whether the data transfer is IPC in the user space or between the user space and kernel space, and then create the corresponding **HdfSbuf** structure. + +[Example] + +```c +void SampleDispatchBetweenUserAndKernel() +{ + int32_t ret; + /* Communication between the user space and kernel space. */ + struct HdfSBuf *data = HdfSBufTypedObtain(SBUF_RAW); + ... + ret = sample->dispatcher->Dispatch(&sample->object, CMD_SAMPLE_DISPATCH, data, NULL); + ... + HdfSBufRecycle(data); +} +``` + +[Example] + +```c++ +void SampleDispatchIpc() +{ + /* IPC */ + struct HdfSBuf *data = HdfSBufTypedObtain(SBUF_IPC); + ... + int ret = sample->dispatcher->Dispatch(sample, CMD_SAMPLE_DISPATCH, data, nullptr); + ... + HdfSBufRecycle(data); +} +``` + +#### [Rule] Define the HDF_LOG_TAG macro when using HDF logging. + +[Description] The HDF provides the **hdf_log.h** tool ,using which you can output driver run logs. The **HDF_LOG_TAG** macro specifies the log tag. You must define this macro before printing logs. + +[Example] + +```c +#include + +#define HDF_LOG_TAG sample_driver // Define the log tag. + +int32_t SampleDriverInit(struct HdfDeviceObject *deviceObject) +{ + HDF_LOGI("sample driver is initialized"); // Use the tool to print logs. + return HDF_SUCCESS; +} +``` + +#### [Rule] Verify the return values of the HDF methods and use the error codes provided by the HDF. + +[Description] The HDF methods have specific return values. You should verify them rather than ignoring them. The return values correspond to error codes in the **hdf_base.h** header file. Use the error codes provided by the HDF when using the HDF or implementing custom methods. + +[Example] + +```c +int32_t SampleDriverInit(struct HdfDeviceObject *deviceObject) +{ + int32_t ret; + // Check whether the device type is successfully set. + if (!HdfDeviceSetClass(deviceObject, DEVICE_CLASS_DISPLAY)) { + HDF_LOGE("HdfDeviceSetClass failed"); + return HDF_FAILURE; + } + ret = InitDiver(); + // A custom method uses an error code provided by the HDF. + if (ret != HDF_SUCCESS) { + HDF_LOGE("init drvier is failed"); + return ret; + } + return HDF_SUCCESS; +} +``` + +### OSAL + +The HDF OSAL shields the interface differences between OpenHarmony subsystems and provides unified OS interfaces, including memory management, threads, mutexes, spin locks, semaphores, timers, files, IRQ, time, atoms, firmware, and I/O operation modules. + +#### [Rule] Use OS interfaces through the OSAL for drivers used across mini-, small-, and standard-system devices. + +[Description] The OSAL shields the differences between OS interfaces. You should operate these OS interfaces based on the OSAL to ensure that drivers can run on different types of systems. + +[Example] + +```c +#include +#include + +struct DevHandle *SampleInit(void) +{ + struct DevHandle *handle = (struct DevHandle *)OsalMemCalloc(sizeof(struct DevHandle)); + if (handle == NULL) { + HDF_LOGE("OsalMemCalloc handle failed"); + return NULL; + } + return handle; +} +``` + +[Example] + +```c +#include + +void SampleSleep(uint32_t timeMs) +{ + OsalMSleep(timeMs); +} +``` + +### PAL + +The HDF PAL abstracts platform drivers and provides unified operation interfaces for modules such as the GPIO, I2C, SPI, UART, RTC, SDIO, eMMC, DSI, PWM, and watchdog. + +#### [Rule] Use platform drivers across mini, small, and standard systems through the PAL. + +[Description] The PAL masks the differences between platform driver interfaces of different system types. You should operate these interfaces based on PAL to ensure that drivers can run on different types of systems. + +[Example] + +```c +#include +#include +#include +#include + +static uint32_t g_irqCnt; + +/* Sample function of the GPIO IRQ service */ +static int32_t SampleGpioIrqHandler(uint16_t gpio, void *data) +{ + HDF_LOGE("%s: irq triggered, on gpio:%u, data=%p", __func__, gpio, data); + g_irqCnt++; /* If the IRQ function is triggered, the number of global counters is incremented by 1. */ + return GpioDisableIrq(gpio); +} + +/* GPIO sample function */ +static int32_t SampleGpioIrqEdge(void) +{ + int32_t ret; + uint16_t valRead; + uint16_t mode; + uint16_t gpio = 83; // Number of the GPIO pin to test + uint32_t timeout; + + /* Set the output direction for the pin. */ + ret = GpioSetDir(gpio, GPIO_DIR_OUT); + ... + /* Disable the IRP of this pin. */ + ret = GpioDisableIrq(gpio); + ... + /* Set the IRR function for the pin. The trigger mode is both rising edge and falling edge. */ + mode = OSAL_IRQF_TRIGGER_RISING | OSAL_IRQF_TRIGGER_FALLING; + ret = GpioSetIrq(gpio, mode, SampleGpioIrqHandler, NULL); + ... + /* Enable the IRQ for this pin. */ + ret = GpioEnableIrq(gpio); + ... + g_irqCnt = 0; /* Reset the global counter. */ + timeout = 0; /* Reset the waiting time. */ + /* Wait for the IRQ function of this pin to trigger. The timeout duration is 1000 ms. */ + while (g_irqCnt <= 0 && timeout < 1000) { + ret = GpioRead(gpio, &valRead); + ... + ret = GpioWrite(gpio, (valRead == GPIO_VAL_LOW) ? GPIO_VAL_HIGH : GPIO_VAL_LOW); + ... + OsalMDelay(200); // Wait for an interrupt to be triggered. + timeout += 200; + } + ret = GpioUnSetIrq(gpio); + ... + return (g_irqCnt > 0) ? HDF_SUCCESS : HDF_FAILURE; +} +``` diff --git a/website/docs/extras/en/contribute/OpenHarmony-security-design-guide.md b/website/docs/extras/en/contribute/OpenHarmony-security-design-guide.md new file mode 100644 index 0000000000000000000000000000000000000000..74848aa4f630e55646b745bd53147983c928ff96 --- /dev/null +++ b/website/docs/extras/en/contribute/OpenHarmony-security-design-guide.md @@ -0,0 +1,220 @@ +--- +title: "OpenHarmony-security-design-guide" +prepermalink: /extras/fb812297537d947af7c7dccb18dcb579/ +permalink: /extras/fb812297537d947af7c7dccb18dcb579/ +relpath: "OpenHarmony-3.1-Release/en/contribute/OpenHarmony-security-design-guide.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [OpenHarmony-security-design-guide] +--- +# OpenHarmony Security Design Specifications + +With reference to industry standards and best practices, the document provides OpenHarmony security design specifications. + +## 1\. Access Channel Control + +1-1 To prevent unauthorized access to the system and resources, all system management interfaces unless otherwise specified by standards protocols must be provided with access control mechanisms (enabled by default) + +**Description:** To reduce the attack surface of the system, authentication mechanisms must be enabled for system management interfaces (including those used for configuration, upgrade, and commissioning) to prevent unauthorized access. + +1-2 All external connections of the system must be necessary for system operation and maintenance. All unnecessary connections and ports must be disabled + +**Description:** Disabling unnecessary communication ports can greatly reduce security threats and is a basic means of system security protection. + +## 2\. Application Security + +2-1 The session ID and user permission must be verified for each access request if authorization is required + +**Description:** It is a means to prevent unauthorized access. + +2-2 User authentication must be conducted on the server since it may be easily bypassed if being conducted on the client + +## 3\. Encryption + +3-1 Use verified, secure, and open encryption algorithms + +**Description:** The security of an algorithm does not mean its confidentiality. + +**Example:** Recommended cipher algorithms are as follows: +(1) Block cipher algorithm: AES (key length of 128 bits or longer) +(2) Stream cipher algorithm: AES (key length of 128 bits or longer) (OFB/CTR mode) +(3) Asymmetric encryption algorithm: RSA (recommended: 3072 bits) +(4) Hash algorithm: SHA-2 (256 bits or above) +(5) Key exchange algorithm: DH (recommended: 3072 bits) +(6) Hash-based message authentication code (HMAC) algorithm: HMAC-SHA-2 +The following are some examples of insecure cipher algorithms: MD5, DES, 3DES (Do not use 3DES in TLS/SSH, and ensure K1≠K2≠K3 in non-cryptographic protocols), HMAC-SHA2-256-96, HMAC-SHA1-96, HMAC-MD5, HMAC-MD5-96, SSH CBC, anonymous algorithm suites, DH512, DH1024, SKIPJACK, RC2, RSA (1024 bits or shorter), MD2, MD4, Blowfish, and RC4. 3-2 Do not use algorithms for error control coding, such as parity check and CRC, to perform integrity check, unless otherwise specified in standard protocols + +3-3 Cipher algorithms must use cryptographically secure random numbers for security purposes + +**Description:** The use of insecure random numbers may easily weaken a cipher algorithm or even render it ineffective. + +**Example:** The following interfaces can be used to generate secure random numbers: + +(1) **RAND\_bytes** or **RAND\_priv\_bytes** of OpenSSL +(2) DRBG implemented in the OpenSSL FIPS module +(3) **java.security.SecureRandom** of the JDK +(4) **/dev/random** file of Unix-like platforms + +3-4 By default, use secure cipher algorithms and disable/prohibit insecure cipher algorithms. Use cipher algorithm libraries that are certified by authoritative organizations, recognized by open-source communities in the industry, or assessed and approved by OpenHarmony. + +**Description:** In the context of advances in cryptographic technologies and enhancement in computing capabilities, some cipher algorithms may become insecure. Using such algorithms may bring risks to user data. In addition, unknown flaws may exist in cipher algorithms that are developed by amateurs and not analyzed/verified by the industry. In this regard, use cipher algorithm libraries that are certified by authoritative organizations, recognized by open-source communities in the industry, or assessed and approved by OpenHarmony. + +**Example:** For examples of cipher algorithms, see 3-1. + +3-5 The GCM mode is preferred when block cipher algorithms are used + +3-6 The OAEP padding scheme is preferred when RSA is used for encryption + +**Description:** PKCS1 padding has been known to be insecure in the industry and academic field. If OAEP padding is not used, attackers can easily decrypt the ciphertext. + +3-7 Do not use private keys to encrypt sensitive data when asymmetric encryption is used for protecting data confidentiality + +**Description:** Using private key for encryption cannot ensure data confidentiality. + +3-8 Use different key pairs for asymmetric encryption and signing + +3-9 Use the sign-then-encrypt mode when both symmetric encryption and digital signature are required. Check the order in which cipher algorithms are called, and do not sign cipher text hashes (i.e., do not perform private key operations on cipher text hashes) + +**Description:** If a cipher text is signed (i.e., the cipher text hash is signed), attackers can obtain the cipher text hash (also the cipher text) through network sniffing. In this case, attackers can tamper with the ciphertext signature + +3-10 If the public keys received from peers during key exchange using the DH algorithm are special public keys 0, 1, p-1, or p, negotiation must be performed again + +**Description:** If the public keys received from peers during key exchange using the DH algorithm are special key values, the negotiated keys must also be known values. In this case, attackers may easily decrypt the cipher text within five attempts. + +3-11 In SSL and TLS protocols, if DH or ECDH algorithm is used for key exchange, use the cipher suite that contains DHE or ECDHE key exchange algorithm to achieve perfect forward secrecy; do not use the cipher suite that only contains DH/ECDH + +3-12 Do not use truncated message authentication codes (MACs) in cryptographic protocols + +**Description:** In cryptographic protocols (such as TLS, SSH, and IKE), MACs are usually used to verify the integrity of messages. Some protocols support truncated MACs. Truncation reduces MAC security. For example, SLOTH attacks against multiple cryptographic protocols (such as TLS and SSH) may craft collisions using truncated hash values. + +**Example:** The following are some examples of truncated MACs. The standard output lengths of HMAC-MD5-96, HMAC-SHA1-96, and HMAC-SHA2-256-96 configured in SSH are listed below. A shorter length is considered a truncation. +(1) SHA-1/HMAC-SHA-1: The standard output length is 160 bits. +(2) SHA-224/HMAC-SHA-224: The standard output length is 224 bits. +(3) SHA-256/HMAC-SHA-256: The standard output length is 256 bits. +(4) SHA-384/HMAC-SHA-384: The standard output length is 384 bits. +(5) SHA-512/HMAC-SHA-512: The standard output length is 512 bits. +(6) SHA-512/224/HMAC-SHA-512/224: The standard output length is 224 bits. +(7) SHA-512/256/HMAC-SHA-512/256: The standard output length is 256 bits. + +3-13 When HMAC is used for data integrity protection, do not use the calculation result of hash(key\|\|message) or hash(message\|\|key) as the MAC value + +**Description:** Attackers may add any information to the end of the original plaintext information to compromise data integrity. + +3-14 Use different symmetric keys for data encryption and MAC calculation in the same transaction + +**Description:** If the same key is used for data encryption and MAC calculation, key exposure creates vulnerabilities for attackers to tamper with confidential information. + +3-15 Do not use fixed IVs (for example, IVs hard-coded or fixed in configuration files) for encryption + +**Description:** The randomness of IV in CBC mode ensures the generation of different cipher texts based on the same piece of data in plain text and key. If such randomness cannot be ensured, attackers can easily replace the cipher text. For other block cipher modes, such as OFB and CRT, attackers can easily decrypt the cipher text. + +3-16 Do not select anonymous authentication, non-encryption, weak authentication, weak key exchange, weak symmetric key algorithms, or weak message authentication algorithm cipher suites in cryptographic protocols + +**Description:** Their use may compromise system security. + +**Example:** +The following are examples of anonymous authentication: TLS\_DH\_anon\_WITH\_3DES\_EDE\_CBC\_SHA and TLS\_DH\_anon\_WITH\_AES\_256\_CBC\_SHA. +The following is an example of weak authentication: RSA/DSA, with a key length less than 2048 bits. + +3-17 It is recommended that only ECDHE be used as the cipher suite of the key exchange algorithm + +3-18 Do not hardcode keys used for data encryption/decryption. Use the root key or other means for encryption, and protect the root key with a proper security mechanism (for example, hardcode only some key components) + +**Description:** Hard-coded keys are likely to be cracked by reverse engineering. + +3-19 It is recommended that the function design cover the working key update methods (such as manual or automatic key update) and update rules (online update, offline update, and update time, etc.) + +**Description:** The longer a key is in use, the more likely it is to be cracked. The larger the amount of data encrypted using the key, the greater the chance for attackers to obtain ciphertext data as it is easier to analyze the ciphertexts encrypted using the same key. If the key is leaked, the loss incurred increases with its service period. + +**Example:** The system generates new keys based on key generation rules, uses the old key to decrypt the data, uses the new key to encrypt the data again, and destroys the old key. In scenarios where mass data needs to be encrypted, consider reserving the old key to decrypt the old data and use the new key to encrypt the new data. + +3-20 Key materials and components must be subject to strict access control (such as permission 600 or 400) + +3-21 For keys saved in memory, overwrite the memory by other data (such as 0x00) before freeing it + +## 4\. Sensitive Data Protection + +4-1 Store authentication credentials such as passwords in ciphertext and apply access control + +4-2 Use irreversible algorithms such as PBKDF2 for encryption in scenarios where authentication credentials do not need to be restored. HMAC (authentication credentials and salt values) can be used in scenarios where performance is sensitive and the security requirement is not high. (Note: Password and salt value locations can be exchanged.) + +**Example:** + +1. When calculating the one-way password hash using PBKDF2, the number of iterations is at least 1000. +2. A salt value is a cryptographically secure random number generated by the system. The salt value has at least 16 bytes and is unique to each user. +3. Avoid using HASH(user name\|\|password), HMAC(user name, password), and HASH(password XOR salt). + +4-3 If sensitive data needs to be transmitted over untrusted networks, ensure that sensitive data is transmitted over secure paths or is transmitted after being encrypted + +4-4 For access to sensitive data, use appropriate security mechanisms (such as authentication, authorization, or encryption) based on risks. Files and directories containing sensitive data (for example, configuration files, log files, personal sensitive data files, user password files, key files, certificate files, drive files, and backup files) shall be accessible only to their owners or permitted users + +4-5 Filter out or shield authentication credentials in logs, debugging information, and error messages + +## 5\. System Management and Maintenance Security + +5-1 Adopt one or more of the following protection measures for login authentication on system O\&M interfaces to support anti-brute force cracking based on actual scenarios and risks: +(1) Account lockout +(2) IP address lockout +(3) Login postponed +(4) Verification code required + +5-2 By default, all the passwords entered by users on the GUI for system O\&M purposes are not displayed in plaintext + +5-3 The password in a text box cannot be copied out + +5-4 Use appropriate security protocols, and disable insecure protocols by default + +**Example:** The following are examples of security protocols: SSHv2, TLS 1.2, TLS 1.3, IPsec, SFTP, SNMPv3, and their latest versions. It is recommended that AES in OFB or CTR mode or ChaCha20 be used to replace RC4. The following are examples of insecure protocols: TFTP, FTP, Telnet, SSL 2.0, SSL 3.0, TLS 1.0, TLS 1.1, SNMPv1/v2, and SSHv1.x. + +5-5 Do not assign a role to a new account or assign a role with the least privilege (for example, read only) by default in line with the principle of least privilege + +**Description:** In this way, unauthorized users cannot but obtain the least privilege when the authorization mechanism is faulty or bypassed. + +## 6\. Privacy Protection + +6-1 Explicitly notify users and obtain their consent before collecting/using their personal data or forwarding the data to third parties + +**Description:** It is to increase transparency and grant users more control over their data in compliance with laws and regulations such as GDPR. + +6-2 Provide necessary security protection mechanisms (such as authentication, access control, and logging) for personal data collection, processing, and storage as required by normal services to prevent personal data from being disclosed, lost, or damaged + +6-3 Describe the product functions involving user privacy in documentation, including the purpose, scope, method, and period of personal data processing, and require that the function should be used in compliance with local laws and regulations + +**Description:** It is to increase transparency in compliance with laws and regulations such as GDPR. + +6-4 Support filtering, anonymization, or pseudonymization for personal data to be displayed (for example, on UIs or in stored or exported files) + +**Description:** It is to reduce the risk of personal privacy breaches. + +6-5 To prevent location tracking, do not identify precise locations of users for maintenance purposes (such as troubleshooting) unless it is explicitly required + +**Description:** Precise location information is very sensitive, and is not needed in troubleshooting. + +6-6 Collect personal data necessary for stated purposes in compliance with the data minimization principle. Comply with the data minimization principle when displaying personal data in fault diagnosis logs. + +**Description:** The display of personal data in fault diagnosis logs may arouse users' doubts. Therefore, personal data should not be displayed in fault diagnosis logs. If it has to be displayed (for example, for debugging purpose) anonymization is required. + +6-7 In scenarios involving personal data processing, provide mechanisms to ensure that data subjects can query, update, and erase their personal data + +**Description:** It is to protect data subjects' rights. + +## Terms + +| No. | Term | Definition | +| :--: | :--------------------------: | ------------------------------------------------------------ | +| 1 | authentication credential | Private or public data declared to prove identity authenticity. Common authentication credentials include passwords, pre-shared keys, private keys, SNMP community names, smart cards, dynamic tokens, fingerprints, and retinas. | +| 2 | personal data | Any information relating to an identified or identifiable natural person ("data subject") who can be identified, directly or indirectly, in particular by reference to an identifier such as a name, an identification number, and location data or to one or more factors specific to the physical, physiological, genetic, mental, economic, cultural, or social identity of that natural person. Personal data includes a natural person's email address, telephone number, biometric information (such as a fingerprint), location data, IP address, health care information, religious belief, social security number, marital status, and so on. | +| 3 | sensitive personal data | An important subset of personal data, referring to the information involving most private data of a data subject, or the data, once leaked or modified, may result in adverse impacts to a data subject. Sensitive personal data includes data revealing racial or ethnic origin, political opinions, religious or philosophical beliefs, trade-union membership, genetic data, biometric information, data concerning health, sex life, or sexual orientation, as well as bank account numbers, ID card numbers, passports, passwords, and other information associated with a natural person's identity. Sensitive personal data requires additional and stricter protection measures. | +| 4 | sensitive data | The scope of sensitive data varies with product application scenarios, and should be analyzed and determined based on risks in specific scenarios. Typical sensitive data includes authentication credentials (such as passwords, private keys, and dynamic token cards), encryption keys, sensitive personal data, etc. | +| 5 | data subject | An individual who provides the data controller and processor with personal data. A data subject can be identified directly by personal data (such as a name) or indirectly by the combination of personal data. | +| 6 | anonymization | A process of irreversibly de-identifying personal data such that the person cannot be identified by using reasonable time, cost, technology either by the controller or by any other person to identify that individual. | +| 7 | pseudonymization | In order to restrict the ability of using personal data to identify a data subject, identity information contained in personal data can be replaced by aliases. The substitution is considered pseudonymization, which has the following features: (1) The remaining attributes linked to the alias do not suffice to identify the data subject to whom they relate; and (2) The alias assignment cannot be reversed by reasonable efforts of the privacy stakeholders (such as the data controller) other than those that performed assignment. Pseudonymized data is still personal data. Pseudonyms are also known as aliases. | +| 8 | precise location information | Precise longitude and latitude. For example, the GPS can locate an object with the precision of dozens of meters. The criterion of precise location information is that the information is precise enough for locating a natural person. | +| 9 | standard protocol | An international standard protocol (e.g., ETSI, 3GPP, or ITU-T standard, or that from some other standard-setting organization), regional standard (e.g., standard developed by the European Union), national industry standard (e.g., standard formulated by the Ministry of Industry and Information Technology of China), or de facto industry standard (e.g., industry standard defined by UPnP). | + diff --git a/website/docs/extras/en/contribute/Readme-EN.md b/website/docs/extras/en/contribute/Readme-EN.md new file mode 100644 index 0000000000000000000000000000000000000000..d62c6052832e94b3818a579fb1672ad7ce873108 --- /dev/null +++ b/website/docs/extras/en/contribute/Readme-EN.md @@ -0,0 +1,27 @@ +--- +title: "Readme-EN" +prepermalink: /extras/92055fcf6aef7363e530174041c4bd07/ +permalink: /extras/92055fcf6aef7363e530174041c4bd07/ +relpath: "OpenHarmony-3.1-Release/en/contribute/Readme-EN.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [Readme-EN] +--- +# Contributing Documents + +- [Contribution](/pages/en/overview/Contribution/Contribution) +- [Code of Conduct](/pages/en/overview/Contribution/Code%20of%20Conduct) +- [Code Contribution](/pages/en/overview/Contribution/Code%20Contribution) +- [Contribution Process](/pages/en/overview/Contribution/Contribution%20Process) +- [Auto-Test](/pages/en/overview/Contribution/Auto-Test) +- [Documentation Contribution](/pages/en/overview/Contribution/Documentation%20Contribution) +- [Writing Instructions](/pages/en/overview/Contribution/Writing%20Instructions) +- [Communication in Community](/pages/en/overview/Contribution/Communication%20in%20Community) +- [FAQs](/pages/en/overview/Contribution/FAQs) + diff --git a/website/docs/extras/en/contribute/docs-release-process.md b/website/docs/extras/en/contribute/docs-release-process.md new file mode 100644 index 0000000000000000000000000000000000000000..6791486b0b9c87427d6e2d90e21c0a99fe3721af --- /dev/null +++ b/website/docs/extras/en/contribute/docs-release-process.md @@ -0,0 +1,133 @@ +--- +title: "docs-release-process" +prepermalink: /extras/0dcc69207baa534975ec7d65d9e93477/ +permalink: /extras/0dcc69207baa534975ec7d65d9e93477/ +relpath: "OpenHarmony-3.1-Release/en/contribute/docs-release-process.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [docs-release-process] +--- +# Writing Documents for a Release + +To help developers efficiently use each release, OpenHarmony provides related documents (such as the guide, API reference, development examples, release notes, API changelog, and FAQs) based on the feature requirements planned for the release. Some requirements involve new features and documents, and others require updates to the existing features and documents. + +## OpenHarmony Document Development Process + +When planning a feature requirement, each service Special Interest Group (SIG) should determine whether the requirement involves new documents or updates to existing documents. If new documents or updates are involved, they should break down the requirement to the Docs SIG for document requirement tracking. The Docs SIG will provide document design suggestions based on the requirement and cooperate with the service SIG in document review, translation, and release. The document development process is shown below. + +![OpenHarmony Document Development Process](../../../images/en/contribute/figures/abb0313941d5d40ec6661ee6175ae5e6.png) + +## Actions for Service SIG Members or Other Developers + +Members in each service SIG write basic documents for the release. Developers in the community are welcome to participate in the development of feature documents. + +### Breaking Down Document Requirements + +1. Provide the **Documents** breakdown in the service SIG requirement issue. If new documents or updates to the existing documents are required, this requirement issue must be liked to the Docs SIG. + +2. View the feature requirements of the release in [OpenHarmony Roadmap]( https://gitee.com/openharmony/release-management/blob/master/OpenHarmony-RoadMap.md). This roadmap provides the release time plan, features to deliver, feature status, and SIG information. + + If a feature requirement involves document delivery, add **Yes** in the **Need Docs** column so that the Docs SIG can track the document delivery. + + +### Developing Documents + +If you are a member of a service SIG and are responsible for developing a new feature, you should cooperate with the Docs SIG to ensure that feature documents are available before the release. Any feature that is not provided with related documents may be removed from the release. + +If you need help in the document structure, ask questions in the `#SIG-Docs` Zulip. + +1. Contact the documentation owner in the Docs SIG for suggestions on document design by referring to [Document Reviewers](/extras/162f5e4278b1afb6659f6d1a99d9c024/). +2. Obtain the corresponding [document template](template) and learn the document writing instructions. +3. Provide detailed documents and usage instructions for the feature as much as possible. After you finish a draft, submit a pull request (PR) and include the link to the corresponding issue in the PR description. + +### Submitting Documents for Review Through PRs + +To ensure the accuracy of technical description, ask technical experts in the service SIGs to review all new contents. In addition, ask documentation experts in the Docs SIG to review the standardization of the documents. For details, see [Document Reviewers](/extras/162f5e4278b1afb6659f6d1a99d9c024/). To assign experts for review, enter the at sign (@) followed by the experts' usernames in the PR comment area. You can also provide review requirements in the `#SIG-Docs` Zulip. + +You should update the draft against all the review comments. The PR can be merged only after both of the following conditions are met: + +- The technical expert completes the review and provides the comment `TechApprove`. +- The documentation expert completes the review and provides the comment `DocsApprove`. + +### Submitting Documents for Test + +Submit your documents for version testing. Testers in the test SIG will submit issues to the Docs repository for any document issues they find. Confirm their comments and update the documents accordingly. + +### Submitting Documents for Translation + +#### For Documents in the Docs Repository + +The OpenHarmony community provides Chinese and English documents. After the Chinese documents are reviewed, tested, and finalized, they can be submitted for translation in the form of issues. Translators in the Docs SIG will complete the English documents. + +Translators submit English documents through PRs and provide the link to the corresponding issue in the PR description. To ensure the accuracy of every English document, the translator should ask technical experts in the service SIG for technical review, by entering the at sign (@) followed by the experts' usernames in the PR comment area. The technical experts can be the author of the Chinese document or others. For details, see [Document Reviewers](/extras/162f5e4278b1afb6659f6d1a99d9c024/). + +The translator should update the English document against all the review comments. The PR can be merged only after the following conditions are met: + +- The technical expert completes the review and provides the comment `TechApprove`. +- The English documentation expert completes the review and provides the comment `DocsApprove`. + +#### For Documents in Non-Docs Repositories + +To provide a translation requirement for a document in a non-Docs repository (such as translation for API comments), submit a translation requirement issue in the Docs repository. Translators in the Docs SIG will complete the English document. + +When submitting a translation requirement, ensure that: + +1. The Chinese document meets the quality standards stipulated for deliverables. +2. The PR related to the Chinese document or the Chinese document path is provided. +3. Temporary Chinese documents can be submitted to the [Docs Repository](https://gitee.com/openharmony/community/tree/master/sig/). + +## Actions for Docs SIG Members or Document Contributors + +Members in the Docs SIG or document contributors should cooperate with each service SIG in reviewing and optimizing documents and translating Chinese documents into English. They should ensure that the output meets the release requirements. + +### Understanding Feature Plans of Each Release + +To know feature and release plans of a release, you can attend the meeting [SIG Release](https://gitee.com/openharmony/release-management/blob/master/README.md) held on Friday every two weeks. Understand the release progress, requirement delivery progress, and document delivery progress. + +You can also view feature requirements of a release in [OpenHarmony Roadmap](https://gitee.com/openharmony/release-management/blob/master/OpenHarmony-RoadMap.md). You can select feature issues marked with SIG_Docs and associated document PRs. + + +### Reviewing Chinese Documents Submitted in PRs + +When reviewing a feature document, you are advised to provide review suggestions from the following aspects: + +#### Language description specifications + +- The logical expression is smooth, and consistent terms are used. +- The language is official, not colloquial. +- There are no words that may infringe the intellectual property rights of third parties. + +#### Easy to understand + +- The content logic is clear and consistent. +- The content is easy to read and understand. There are no obscure or uncommon words. +- Clear steps are provided to guide developers to complete development tasks. + +#### Chart and figures specifications + +- Clear images with pictures and texts are used. +- Each table has a table header and a table title. There are no single rows or single lists. +- The hyphen (-) or the word "NA" is used if there is no content in a cell. + +#### Website style + +- If a PR involves the addition of a Markdown page, ensure that: + - The correct content template is used on the page. + - The definition of the Markdown file name complies with the specifications. + - The page is properly displayed in the navigation of the **README** file. + +- When a Markdown page is deleted or a Markdown page name is changed, ensure that: + - The page does not affect links in other documents in the community. You are advised to check the links locally. + - The contents in the **README** file is updated. + +For more detailed specifications, see [Writing Instructions](/pages/en/overview/Contribution/Writing%20Instructions). + +### Translating Documents from Chinese to English + +Translation requirement issues in the community will be translated by translators in the Docs SIG. Document contributors are also welcome to take up translation requirement tasks and submit English documents through PRs. diff --git a/website/docs/extras/en/contribute/docs-reviewers.md b/website/docs/extras/en/contribute/docs-reviewers.md new file mode 100644 index 0000000000000000000000000000000000000000..ba8a7bd03524c0175d257125b26d3c3f519d61c4 --- /dev/null +++ b/website/docs/extras/en/contribute/docs-reviewers.md @@ -0,0 +1,47 @@ +--- +title: "docs-reviewers" +prepermalink: /extras/162f5e4278b1afb6659f6d1a99d9c024/ +permalink: /extras/162f5e4278b1afb6659f6d1a99d9c024/ +relpath: "OpenHarmony-3.1-Release/en/contribute/docs-reviewers.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [docs-reviewers] +--- +# Document Reviewers + +## Document Standardization Reviewers +### Device Development Document Reviewers + +| Feature | Docs Reviewers | +| ------------ | ------------------------------------------------------------ | +| Getting Started| [@duangavin123](https://gitee.com/duangavin123) | +| Source Code Acquisition| [@duangavin123](https://gitee.com/duangavin123) | +| Kernel| [@Austin23](https://gitee.com/Austin23) | +| Driver| [@Qianchenya](https://gitee.com/Qianchenya) | +| Device Development Guidelines| [@Austin23](https://gitee.com/Austin23) | +| Porting and Adaptation| [@Austin23](https://gitee.com/Austin23) | +| Bundle Development| [@Qianchenya](https://gitee.com/Qianchenya) | +| Privacy and Security| [@Qianchenya](https://gitee.com/Qianchenya) | +| Subsystem| [@Qianchenya](https://gitee.com/Qianchenya) | +| Overview| [@zengyawen](https://gitee.com/zengyawen) | +| Glossary| [@bj9854](https://gitee.com/bj9854) | +| Community public documents| [@neeen](https://gitee.com/neeen) [@yan-tingting666](https://gitee.com/yan-tingting666) | + +### Application Development Document Reviewers + +| Feature | Docs Reviewers | +| ------------ | ----------------------------------------- | +| JS Reference Specifications| [@zengyawen](https://gitee.com/zengyawen) | +| Media| [@zengyawen](https://gitee.com/zengyawen) | +| Getting Started| [@ge-yafang](https://gitee.com/ge-yafang) | +| UI | [@ge-yafang](https://gitee.com/ge-yafang) | +| App Development Overview| [@zengyawen](https://gitee.com/zengyawen) | +| Network and Connectivity| [@RayShih](https://gitee.com/RayShih) | + +## Technical Accuracy Reviewers (to be supplemented) diff --git a/website/docs/extras/en/contribute/template/concept-overview-template.md b/website/docs/extras/en/contribute/template/concept-overview-template.md new file mode 100644 index 0000000000000000000000000000000000000000..f979a525a07a2e0715ed154eb01c936e22d9905a --- /dev/null +++ b/website/docs/extras/en/contribute/template/concept-overview-template.md @@ -0,0 +1,126 @@ +--- +title: "concept-overview-template" +prepermalink: /extras/54aece9a78335f361102b896357d425f/ +permalink: /extras/54aece9a78335f361102b896357d425f/ +relpath: "OpenHarmony-3.1-Release/en/contribute/template/concept-overview-template.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [concept-overview-template] +--- +# Overview Template + +## Basic Concepts + +***[Writing Requirements]*** + +*Mandatory. Describe basic concepts related to a development task to help developers better understand the task. The table below describes the writing requirements. After finishing the writing, check your content against these requirements one by one.* + +| Requirement| Satisfied or Not| +| -------- | -------- | +| Common concepts in the industry are not described.| | +| Common terms in the industry, rather than internal terms, are used.| | + + +***[Example]*** + + +The XX system provides the audio module for your application to implement audio-related features, including audio playback, recording, and volume management. + + +It is considered good practice that you understand the following concepts before starting application development: + + +- Sampling + Sampling is a process where analog signals are converted into digital signals that can be represented by 0101. + +- Sampling rate + Sampling rate is the number of samples extracted from a continuous signal per second to form a discrete signal. It is measured in Hz. Generally, human hearing range is from 20 Hz to 20 kHz. Common audio sampling rates include 8 kHz, 11.025 kHz, 22.05 kHz, 16 kHz, 37.8 kHz, 44.1 kHz, 48 kHz, 96 kHz, and 192 kHz. + +- Channel + Channels refer to different spatial positions where independent audio signals are recorded or played. The number of channels is the number of audio sources used during audio recording, or the number of speakers used for audio playback. + +- Audio frame + Audio data is in stream form. For the convenience of audio algorithm processing and transmission, it is generally agreed that a data amount in a unit of 2.5 to 60 milliseconds is one audio frame. This unit is called sampling time, and its length is specific to codecs and the application requirements. + + +## Working Principles + +***[Writing Requirements]*** + +*Optional. You can delete this section if the working principles are simple and the basic concepts in the **Overview** section are enough for understanding.* + +*Describe the implementation principles, for example, the time for calling the APIs and triggering callbacks related to key steps, to help developers better understand the basic operation principles, carry out development tasks, and locate problems.* + +*The table below describes the writing requirements. After finishing the writing, check your content against these requirements one by one.* + +| Requirement| Satisfied or Not| +| -------- | -------- | +| Only principles related to the development task are described.| | +| Supplementary graphics are used, such as sequence diagrams and flowcharts. The text description is consistent with the figure description.| | + +***[Example 1]*** + +- Semaphore initialization: The system allocates memory for the semaphores configured (the value of *N* can be configured by users and is limited by the memory), initializes all semaphores to be unused semaphores, and adds them to a linked list for the system to use. + +- Semaphore creation: The system obtains a semaphore from the linked list of unused semaphores and assigns an initial value to the semaphore. + +- Semaphore request: If the counter value is greater than 0, the system allocates a semaphore, decreases the value by 1, and returns a success message. Otherwise, the system blocks the task and adds the task to the end of a task queue waiting for semaphores. The wait timeout period can be set. + +- When a semaphore is released, if there is no task waiting for it, the counter is increased by 1. Otherwise, the first task in the wait queue is woken up. + +- Semaphore deletion: The system sets a semaphore in use to the unused state and inserts it to the linked list of unused semaphores. + +- Semaphore allows only a specified number of tasks to access a shared resource at a time. When the number of tasks accessing the resource reaches the limit, other tasks will be blocked until the semaphore is released. + + +***[Example 2]*** + +**Working Principles of Mutexes** + +In a multi-task environment, multiple tasks may access the same shared resource. However, certain shared resources are not shared, and can only be accessed exclusively by tasks. A mutex can be used to address this issue. + +When non-shared resources are accessed by a task, the mutex is locked. Other tasks will be blocked until the mutex is released by the task. The mutex allows only one task to access the shared resources at a time, ensuring integrity of operations on the shared resources. + + + +## Limitations and Constraints + +***[Writing Requirements]*** + +*Mandatory. Describe the constraints of the development task and the negative impact of the constraints, including but not limited to the following:* + +- ***Function Limitations*** + - *Application scope of the function (specify scenarios that are not supported)* + - *Specification limitations* + +- ***Operation Limitations*** + + - *Operations on known issues* + - *Potentially risky operations (such as performance deterioration)* + - *Operations that may cause performance deterioration* + +*The table below describes the writing requirements. After finishing the writing, check your content against these requirements one by one.* + +| Requirement| Satisfied or Not| +| -------- | -------- | +| The function limitations or operation restrictions are clearly specified.| | +| Only constraints that affect task development or user experience are described.| | +| Operations that are prone to errors are described in the procedure but not described in this section.| | + +***[Example]*** + +**Limitations and Constraints on Mutexes:** + +- Two tasks cannot lock the same mutex. If a task attempts to lock a mutex held by another task, the task will be blocked until the mutex is unlocked. + +- Mutexes cannot be used in the interrupt service program. + +- When using the LiteOS-A kernel, the xx system must ensure real-time task scheduling and avoid long-time task blocking. Therefore, a mutex must be released as soon as possible. + +- When a mutex is held by a task, the task priority cannot be changed by using APIs such as **LOS_TaskPriSet**. diff --git a/website/docs/extras/en/contribute/template/faq-template.md b/website/docs/extras/en/contribute/template/faq-template.md new file mode 100644 index 0000000000000000000000000000000000000000..ba1459d7c0128233a8aeed8b1b5a9fa6666f8960 --- /dev/null +++ b/website/docs/extras/en/contribute/template/faq-template.md @@ -0,0 +1,55 @@ +--- +title: "faq-template" +prepermalink: /extras/513b2fb9904d65bd11e4e31ea08e61b0/ +permalink: /extras/513b2fb9904d65bd11e4e31ea08e61b0/ +relpath: "OpenHarmony-3.1-Release/en/contribute/template/faq-template.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [faq-template] +--- +# FAQ Template + +FAQs describe issues encountered during development and provide solutions to the issues. + +## Title Requirements + +Briefly describe the key information about an issue in the title. + +## Template for Writing Minor Issues + +Briefly describe the operations, issues, and solutions. + +## Template for Writing Complex Issues + +**Symptom** + +- System software and version in use +- Problem description and trigger conditions + +- Error messages + +- Screenshots, if available + + +**Possible Causes** + +Analyze the causes of the issue. If there are multiple possible causes, list them one by one. + +1. XXX +2. XXX + +**Solutions** + +- If there are multiple solutions, arrange them in order from least complex to most complex, and provide their respective scenarios. +- If possible, provide screenshots to help understand the steps. +- If the code has print output, provide the output content separately to help understand the solution procedure. + +1. XXX +2. XXX + diff --git a/website/docs/extras/en/contribute/template/guide-template.md b/website/docs/extras/en/contribute/template/guide-template.md new file mode 100644 index 0000000000000000000000000000000000000000..ff68c9cd2c919c36557e039c54148778d87ac2fd --- /dev/null +++ b/website/docs/extras/en/contribute/template/guide-template.md @@ -0,0 +1,151 @@ +--- +title: "guide-template" +prepermalink: /extras/654a67be47d3036110c27ad092a0496b/ +permalink: /extras/654a67be47d3036110c27ad092a0496b/ +relpath: "OpenHarmony-3.1-Release/en/contribute/template/guide-template.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [guide-template] +--- +# Development Guidelines + +***[Writing Requirements]*** + + +*Mandatory. Describe how a developer completes tasks in a specific scenario. Include one scenario in each section. The table below describes the writing requirements. After finishing the writing, check your content against these requirements one by one.* + + +| Requirement| Satisfied or Not| +| -------- | -------- | +| Each section covers only one scenario. If there are multiple scenarios, provide development guidelines for each scenario in separate sections. For example, you can use the following sections in **Audio**: **Development Guidelines on Audio Playback**, **Development Guidelines on Volume Management**, and **Development Guidelines on Sound Playback**.| | +| Use verbs + nouns to describe task operations in titles.| | + + +## When to Use + +***[Writing Requirements]*** + +*Mandatory. Describe in which scenario, what problem is solved, and what the final effect is. Use the SCQA method.* + +- *S: situation. Introduce a familiar scenario.* + +- *C: complication. Describe the conflict between the situation and requirement.* + +- *Q: question. Ask a question. What can I do in such a case?* + +- *A: answer. Describe the solution.* + +*The table below describes the writing requirements. After finishing the writing, check your content against these requirements one by one.* + +| Requirement| Satisfied or Not| +| -------- | -------- | +| Clearly describe the background, what operations are done when and where, what problems are solved, and what benefits are delivered.| | + +***[Example]*** + +You can use APIs described in this section to convert audio data into audible analog signals, play the audio signals using output devices, and manage playback tasks. + + +## Available APIs + +***[Writing Requirements]*** + +*Mandatory. Describe APIs involved in the development guideline to help developers have a general understanding of the APIs, thereby improving development efficiency. The table below describes the writing requirements. After finishing the writing, check your content against these requirements one by one.* + +| Requirement| Satisfied or Not| +| -------- | -------- | +| Include only APIs relevant to the development task.| | +| If there are more than 10 APIs, you can provide only main APIs.| | + +***[Example]*** + +The **AudioRenderer** class provides open audio playback capabilities. For details about the APIs, see the API reference. + +**Table 1** Audio playback APIs + +| API| Description| +| -------- | -------- | +| AudioRenderer(AudioRendererInfo audioRendererInfo, PlayMode pm) throws IllegalArgumentException | A constructor used to create an **AudioRenderer** instance based on the specified playback parameters, the specified playback mode, and the default playback device.| +| AudioRenderer(AudioRendererInfo audioRendererInfo, PlayMode pm, AudioDeviceDescriptor outputDevice) throws IllegalArgumentException | A constructor used to create an **AudioRenderer** instance based on the specified playback parameters, playback mode, and playback device.| +| boolean play() | Plays audio streams.| +| boolean write(byte[] data, int offset, int size) | Writes audio data in the specified byte array into an audio receiver for playback.| + + +## How to Develop + +***[Writing Requirements]*** + + *Mandatory. Describe the overall process to help developers quickly complete the task. The table below describes the writing requirements. After finishing the writing, check your content against these requirements one by one.* + +| Requirement| Satisfied or Not| +| -------- | -------- | +| **Writing a Development Procedure**| | +| Complete: All mandatory steps are provided.| | +| Clear: The logic of the writing is clear and reasonable. The overview, preparations, and operations in the document are described by following certain logic, and the chapters are not broken or contradictory.| | +| Sentence pattern for tasks: Use verbs + nouns to describe actions in titles or sentences.| | +| Prevention in advance: Describe the restrictions, error-prone operations, and potential risks in advance. Use general icons and styles.| | +| Clear steps-1: Describe the purpose of each step, no matter whether it is simple or not.| | +| Clear steps-2: Specify the environment, tools, operations, and how-to.| | +| If an operation is optional, specify the optional conditions.| | +| After the development procedure is complete, specify the expected results.| | +| **Writing a Code Segment**| | +| If a code segment involves commands to be copied by developers, display the commands in editable mode, instead of using screenshots. Use code snippets to wrap the commands.| | +| Highlight key code segments in blue (RGB: 0.0.255), and comment out key steps.| | +| The code display meets the code indentation requirements.| | +| If an API call is involved in a step, provide the API and its usage description or sample code. The code comes from specific instances.| | + +***[Example]*** + +1. Use **AudioStreamInfo.Builder** to create an **AudioStreamInfo** instance for audio stream parameters. The following example uses the default values of the input parameters for **AudioStreamInfo.Builder**. You need to set the parameters based on the audio stream specification. + ``` + AudioStreamInfo audioStreamInfo = new AudioStreamInfo.Builder().sampleRate( AudioStreamInfo.SAMPLE_RATE_UNSPECIFIED) .audioStreamFlag(AudioStreamInfo.AudioStreamFlag.AUDIO_STREAM_FLAG_NONE) .encodingFormat(AudioStreamInfo.EncodingFormat.ENCODING_INVALID) .channelMask(AudioStreamInfo.ChannelMask.CHANNEL_INVALID) .streamUsage(AudioStreamInfo.StreamUsage.STREAM_USAGE_UNKNOWN) .build(); + ``` + + Example code for playing a PCM stream: + ``` + AudioStreamInfo audioStreamInfo = new AudioStreamInfo.Builder().sampleRate(44100)// 44.1 kHz .audioStreamFlag(AudioStreamInfo.AudioStreamFlag.AUDIO_STREAM_FLAG_MAY_DUCK)// Set audio ducking. .encodingFormat(AudioStreamInfo.EncodingFormat.ENCODING_PCM_16BIT)//16-bit PCM .channelMask(AudioStreamInfo.ChannelMask.CHANNEL_OUT_STEREO)// Set the dual output channel. .streamUsage(AudioStreamInfo.StreamUsage.STREAM_USAGE_MEDIA)// Set the stream to be used for media. .build(); + ``` + +2. Build the playback parameter structure via **AudioRendererInfo** for the audio stream created in Step 1, and use **AudioRendererInfo.Builder** to create an instance. The following example uses the default parameter values of the **AudioRendererInfo.Builder** instance. You need to set the playback parameters based on the audio playback specification. + ``` + AudioRendererInfo audioRendererInfo = new AudioRendererInfo.Builder().audioStreamInfo(audioStreamInfo) .audioStreamOutputFlag(AudioRendererInfo.AudioStreamOutputFlag.AUDIO_STREAM_OUTPUT_FLAG_NONE) .bufferSizeInBytes(0) .distributedDeviceId("") .isOffload(false) .sessionID(AudioRendererInfo.SESSION_ID_UNSPECIFIED) .build(); + ``` + + Example code for playing a PCM stream: + ``` + AudioRendererInfo audioRendererInfo = new AudioRendererInfo.Builder().audioStreamInfo(audioStreamInfo) .audioStreamOutputFlag(AudioRendererInfo.AudioStreamOutputFlag.AUDIO_STREAM_OUTPUT_FLAG_DIRECT_PCM)// Set direct PCM output .bufferSizeInBytes(100) .distributedDeviceId("E54***5E8")// Use distributed device E54***5E8 for playback. .isOffload(false)// Value false indicates that the audio stream is transmitted to the buffer on a segment-by-segment basis for several times and then played. Value true indicates that the audio stream is transmitted to the HAL layer at a time. .build(); + ``` + +3. Specify the playback mode based on the audio stream to be played. The playback modes differ only in the data writing process. Create an **AudioRenderer** instance using a constructor that fits your need. + .... + +4. After the playback task is complete, call the **release()** method on the **AudioRenderer** instance to release resources. + + +## (Optional) Commissioning and Verification + +***[Writing Requirements]*** + +*Optional. After the development is complete, perform commissioning and verification to ensure that the operation is successful. The operation procedure requirements are the same as those in **Development Guidelines**. Other specific writing requirements are as follows. After finishing the writing, check your content against these requirements one by one.* + +| Requirement| Satisfied or Not| +| -------- | -------- | +| Describe the final service commissioning process. The operation result of each step should be verified after the corresponding development task is complete.| | +| Specify the criteria for development success.| | + +## Development Example +***[Writing Requirements]*** + +*Provide a complete sample, briefly describe the principle and implementation of the sample, and provide a link to the source code repository.* + +The following sample is provided to help you better understand how to xx: + +- xxx (A link to the source code repository) + + This sample xxx. diff --git a/website/docs/extras/en/contribute/template/js-template.md b/website/docs/extras/en/contribute/template/js-template.md new file mode 100644 index 0000000000000000000000000000000000000000..b3aec16ff00883d86667085f3937349dc91e136c --- /dev/null +++ b/website/docs/extras/en/contribute/template/js-template.md @@ -0,0 +1,265 @@ +--- +title: "js-template" +prepermalink: /extras/87c702e1815d5fba144da36d08246dd6/ +permalink: /extras/87c702e1815d5fba144da36d08246dd6/ +relpath: "OpenHarmony-3.1-Release/en/contribute/template/js-template.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [js-template] +--- +# JS API Reference Template + +> *Writing Instructions* +> +> 0.1 - Delete all writing instructions after you finish the writing. +> +> 0.2 - Upload JS API reference documents to **docs/en/application-dev/reference/apis**. If these documents contain figures, upload the figures to the **figures** folder. +> +> 0.3 - Use a .d.ts file for a JS API reference document. **The file name must be in the following format: js-apis-.md**. Examples: +> For @ohos.multimedia.audio in the Media subsystem, the file name is **js-apis-audio.md**. +> For @ohos.telephony.sms in the Telephony subsystem, the file name is **js-apis-sms.md**. +> +> 0.4 - After uploading a JS API reference document, update the **Readme-EN.md** file in **docs/en/application-dev/reference/apis**. +> +> 0.5 - **Document Title**: Use phrases that summarize the module functionalities. +> +> 0.6 - Use the document title as the level-1 heading. Use the attributes, functions, classes, interfaces, enums, and types under the namespace as level-2 headings. Use the attributes and functions under classes as level-3 headings. +> +> **Version Description** +> +> 0.7 - **When introducing an API to an existing module, use the \ tag to mark its earliest version.** +> Example: For an existing module of API 6, if an attribute is added in API 7, suffix the \ tag to the name of the new attribute, for example, **newAttribute7+**. +> If a method is added, suffix the \ tag to the method name, for example, **sim.getSimIccId7+**. The processing of new interfaces, classes, and enums is similar. +> +> 0.8 - **Deprecated content**: Do not delete the deprecated content directly from the document. Instead, suffix **deprecated** as a superscript to the content, and use the greater-than symbol (>) to introduce the substitute method plus the corresponding link. +> Example: abandonmentMethod(deprecated) +> +> > This APIs is no longer maintained since API version 7. You are advised to use [newMethod](#newMethod) instead. +> +> 0.9 - For **empty APIs that will be implemented only in the MR version**, add the following information to the interface description: +> This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR. +> +> **Required Permissions, System Capabilities, and System APIs** +> +> 0.10 - **Required permissions**: Maintain consistency with the code implementation. State the required permissions at the level of methods, enumerations, and attributes. Format: +> (Permissions that can be requested by all applications) **Required permissions**: ohos.permission.xxxx +> (Permissions that can be requested only by system applications) **Required permissions**: ohos.permission.xxxx (available only to system applications) +> +> 0.11 - **System capabilities**: +> Add the following information for each function: **System capability**: SystemCapability.xxx.xxx +> There are two cases for the information about system capabilities added to each table (attributes, enums, constants, and variables). +> Add the following description if all the items in a table require the same system capabilities: +> SystemCapability.xxx.xxx +> Add the following description if the items in a table require different system capabilities: +> The items in the table below require different system capabilities. For details, see the table. +> +> 0.12 - **System APIs**: Add the following description for system APIs: This is a system API and cannot be called by third-party applications. +> The following describes the instructions for writing a specific API. + +*** +> *Writing Instructions* +> +> 1.1 - Use the greater-than symbol (>) to describe the initial version of an API. +> +> 1.2 - A module has only one initial version. +> +> 1.3 - Use the following sentence: "The initial APIs of this module are supported since API version ***x***. Newly added APIs will be marked with a superscript to indicate their earliest API version." Change ***x*** to the actual version. + + + +> **Note** +> +> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. + +Describe the module from its functionalities, use cases, and use suggestions in this section. + + + +## Modules to Import + +> *Writing Instructions* +> +> 2.1 - Write the modules to import based on the actual conditions. Provide the **import** statement in the form of a code segment. +> +> 2.2 - If no module needs to be imported, change "Modules to Import" to "How to Use" and provide a usage description. +> Example of **How to Use**: +> Before using the **AbilityContext**, obtain the **Context** object through **[getContext()]**(***API-reference***.md). +> +> ```js +> import ability_featureAbility from '@ohos.ability.featureAbility'; +> var context = ability_featureAbility.getContext(); +> ``` + +```js +import call from '@ohos.telephony.call'; +``` + + +## Attributes + +> *Writing Instructions* +> +> 4.1 - Optional. Delete this heading if there is no attribute. +> +> 4.2 - If an attribute is of a custom type, create a link to the corresponding interface or enum. +> +> 4.3 - For a readable attribute, if it has a limited number of values with special meanings, enumerate the values. +> +> 4.4 - For a writable attribute, if only fixed fields are supported, describe them. +> +> 4.5 - If the items in the table require different system capabilities, add the following description: The items in the table below require different system capabilities. For details, see the table. Then, describe the system capabilities for each item. See [Enumeration](#Enumeration). + +**System capability**: SystemCapability.xxx.xxx (Mandatory) + +| Name | Type | Readable| Writable| Description | +| ---------------- | ----------------------------------------- | ---- | ---- | ------------------------------------------ | +| pluggedType | [BatteryPluggedType](#BatteryPluggedType) | Yes | No | Charger type of the current device. | +| isBatteryPresent | boolean | Yes | No | Whether the battery is supported or present.| + +## Enums + +> *Writing Instructions* +> +> 5.1 - Optional. Delete this heading if there is no enum. If there are multiple enums, describe them in separate level-2 headings. To create a level-2 heading, use two number signs (#). +> +> 5.2 - Use the actual enum name as the level-2 heading, for example, **BatteryHealthState**. + +Provide a brief description of the enum type. Example: Enumerates charger types. + +**System capability**: The items in the table below require different system capabilities. For details, see the table. (Mandatory) + +| Name| Value | Description | +| ---- | ---- | ------------------------------------------------------------ | +| NONE | 1 | Unknown type.
**System capability**: SystemCapability.xxx.xxx (mandatory)| + +## Methods + +> *Writing Instructions* +> +> 6.1 - Optional. Delete this heading if there is no method. If there are multiple methods, describe them in separate level-2 headings. To create a level-2 heading, use two number signs (#). +> +> 6.2 - Use the actual method name, in the format of ClassName.methodName, as the level-2 heading. For a subscription method, add the subscription event to the method name. +> Example of a common method: sim.getSimIccId +> Example of a subscription method: sim.on('exampleEvent') +> +> 6.3 - **Method calling mode**: The description must be the same as that in the .d.ts file. The description must include the parameter type, parameter name, and return value type. +> Example: getNetworkState(slotId: number, callback: AsyncCallback\): void +> Note: The angle bracket (<>) may be identified as a label and not displayed. To ensure normal display, you can either add a backslash (\\) (in the format of "\\<>") or use escape characters \< and \>. +> +> 6.4.1 - **Method description**: Describe the features implemented by the method and include the prerequisites for using the method, the impact of the method, and the permissions and system capabilities required to use the method. (*Example of prerequisites: This method can be called only after the xx method is called; you must ensure that the connection to the Internet is normal. Example of impact: xx does not take effect after this method is called.*) +> +> 6.4.2 - **Asynchronous method**: If there are asynchronous methods, describe their return type in the method description. The return type can be a callback function or a **Promise** instance. +> +> 6.4.3 - **Line feed in a table**: Use \
for line feed. + +Provide the method name in the following format: (**static** if it is a static method) methodName (parameterName1: parameterType1, parameterName2: parameterType2, ...): returnValueType + +Describe the method. For details, see 6.4.1 and 6.4.2. + +**Required permissions**: ohos.permission.xxx (Delete this part if no permission is involved. If a system permission is required, specify it.) + +**System capability**: SystemCapability.xxx.xxx (mandatory) + +**Parameters** (Optional. Delete this heading if there is no parameter.) + +| Name | Type | Mandatory| Description | +| ------------ | --------------------------------------------- | ---- | ------------------------------------------------------------ | +| parameterOne | number \| string \| [CustomType](#CustomType) | Yes | Describe the parameter. Provide the value range and recommended value. If there is a fixed format, provide a format example, especially for the URI.
Provide a link for each custom parameter type.| +| callback | Callback\> | No | Describe the parameter. For an optional parameter, describe the consequences if it is not specified.
Example: If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.| + +**Return value** (Optional. Delete this heading if there is no return value.) + +| Type | Description | +| ------------------------------------------ | -------------------------------------------- | +| string | Describe the return value, for example, what can be done after the return value is obtained.| +| Promise\> | Describe the return value, for example, what is obtained through the **Promise** instance. | + +**Example** + +```js +// This part is mandatory. +// Check all sample code provided in the example. +// Minor errors such as missing symbols and variable inconsistency are unacceptable. +// Declare all variables that are used. +// Write an actual case that can be easily used, rather than the parameter names themselves. +// Use comments to describe the content that are not user-defined. +// Example: var result = xxx.createExample(parameterOne); // parameterOne is automatically obtained by scanning. +``` + +## Classes/Interfaces + +> *Writing Instructions* +> +> 7.1 - Optional. Delete this heading if there is no class or interface. If there are multiple classes or interfaces, describe them in multiple level-2 headings. To create a level-2 heading, use two number signs (#). +> +> 7.2 - Use the actual class or interface name as the level-2 heading. +> +> 7.3 - If the class or interface contains both attributes and methods, write the attributes above the methods. Write their actual names in separate level-3 headings. +> If the class of interface contains only attributes, you do not need to create a level-3 heading. Instead, use a table to display the attributes. For details, see [CustomType](#CustomType). + +Describe the class or interface. If there are usage restrictions, describe them as well, for example, whether there is a prerequisite and whether an instance needs to be created by using any method. + +### Attributes + +> *Writing Instructions* +> +> Except that a level-3 heading is used, other instructions are the same as those listed under [Attributes](#Attributes). + +### Methods in Classes/Interfaces + +> *Writing Instructions* +> +> 7.4 - Use the actual method name as the level-3 heading. **Do not add a prefix**. For a subscription method, add the corresponding subscription event to the method name. +> Example of a common method: getSimIccId +> Example of a subscription method: on('exampleEvent') +> The other instructions are the same as those stipulated in [Methods](#Methods). + +Describe the method calling mode. For details, see 6.3. + +Describe the method. For details, see 6.4.1 and 6.4.2. + +**Required permissions**: ohos.permission.xxx (Delete this part if no permission is involved. If a system permission is required, specify it.) + +**System capability**: SystemCapability.xxx.xxx (mandatory) + +**Parameters** (Optional. Delete this heading if there is no parameter.) + +| Name | Type | Mandatory| Description | +| ------------ | --------------------------------------------- | ---- | ------------------------------------------------------------ | +| parameterOne | number \| string \| [CustomType](#CustomType) | Yes | Describe the parameter. Provide the value range and recommended value. If there is a fixed format, provide a format example, especially for the URI.
Provide a link for each custom parameter type.| +| callback | Callback\> | No | Describe the parameter. For an optional parameter, describe the consequences if it is not specified.
Example: If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.| + +**Return value** (Optional. Delete this heading if there is no return value.) + +| Type | Description | +| ------------------------------------------ | -------------------------------------------- | +| string | Describe the return value, for example, what can be done after the return value is obtained.| +| Promise\> | Describe the return value, for example, what is obtained through the **Promise** instance. | + +**Example** + +```js +// This part is mandatory. +// Check all sample code provided in the example. +// Minor errors such as missing symbols and variable inconsistency are unacceptable. +// Declare all variables that are used. +// Write an actual case that can be easily used, rather than the parameter names themselves. +// Use comments to describe the content that are not user-defined. +// Example: var result = xxx.createExample(parameterOne); // parameterOne is automatically obtained by scanning. +``` + +## CustomType + +The following is an example of the custom type of a key-value pair. +**System capability**: SystemCapability.xxx.xxx (Mandatory) + +| Name | Type | Readable| Writable| Description | +| ------------ | ------------------- | ---- | ---- | ------------------------------------------------------------ | +| parameterUrl | string | Yes | Yes | Media output URI. The following types of URIs are supported:
1. Relative path whose protocol type is internal. Examples:
Temporary directory: internal://cache/test.mp4

2. Absolute path. Examples:
file:///data/data/ohos.xxx.xxx/files/test.mp4
| +| parameterOne | [CustomEnum](#Enumeration)| Yes | Yes | Describe the attributes. The requirements are similar to those for the parameter description. | diff --git a/website/docs/extras/en/contribute/template/readme-template.md b/website/docs/extras/en/contribute/template/readme-template.md new file mode 100644 index 0000000000000000000000000000000000000000..7bfe5eeffb62fe01c43e3f60a0a854630eba104a --- /dev/null +++ b/website/docs/extras/en/contribute/template/readme-template.md @@ -0,0 +1,162 @@ +--- +title: "readme-template" +prepermalink: /extras/37b4919a064a439d8762cb3ad4714e87/ +permalink: /extras/37b4919a064a439d8762cb3ad4714e87/ +relpath: "OpenHarmony-3.1-Release/en/contribute/template/readme-template.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [readme-template] +--- +# ***ExampleName*** Subsystem/Part + + +[Title Description] Use **Subsystem** or **Part** based on the Readme file type. + + +![Subsystem-readme](../../../../images/en/contribute/template/figures/ad185e4fd6e5d1428a5caf7ea3cf33a1.png) + + +## Introduction + + +[Writing Instructions] **Mandatory**. The following contents must be included: + +**Overall introduction.** Describe the subsystem from the following aspects: background (role in the entire OpenHarmony architecture), functions, use cases, and supported devices. + +**Architecture diagram.** Provide an architecture diagram and explain the main components in the architecture. + +**If this document is about a part, which is part of a subsystem, and related concepts of the subsystem can help understand the part, you are advised to include the following information:** + +**For more concepts related to the ***exampleName*** subsystem, see ***exampleName***. (Provide the link to the subsystem readme.)** + + +The precautions for writing are as follows: + + +| Item| Requirement| +| -------- | -------- | +| **A.1** | **Content**| +| A.1.1 | Style: Use formal language and avoid colloquial language.| +| A.1.2 | Compliance: Do not use terms that have compliance and legal risks, such as concepts specific to third-party intellectual property rights.| +| A.1.3 | Concise: Provide only necessary and minimum information to instruct developers to complete operations as soon as possible.| +| A.1.4 | Correct: The code and parameters in the Readme file must be consistent with the actual product information.| +| A.1.5 | Accurate: Use accurate rather than ambiguous description.| +| A.1.6 | Consistent: Words and concepts in the Readme file must be used consistently across the file and compliant with the glossary. The full name of an acronym or abbreviation must be provided when it appears for the first time in the file.| +| A.1.7 | Specific: Use specific words. For example, when indicating the quantity or degree, do not use "more" or "less". Use specific numbers instead.| +| **A.2** | **Format**| +| A.2.1 | Use punctuation correctly. End a sentence with punctuation.| +| A.2.2 | Present the content clearly, for example, by using bullets or categories. Do not include a single bullet or extra empty lines.| +| A.2.3 | Do not add a space between an English word and Chinese word.| +| A.2.4 | Use valid and specific links that provide direct redirection or download. It is recommended that relative links in Gitee instead of absolute links be used.| +| A.2.5 | For auxiliary description, use the "Note" format. For declaration in advance, use the "Notice" format.| +| **A.3** | **Tables**| +| A.3.1 | Include a caption for each table. Use nouns or noun phrases in the caption.| +| A.3.2 | Include a header for each table. Ensure that a table contains at least two rows and two columns.| +| A.3.3 | If there is no content in a table cell, use an underscore (_) in the cell, rather than leaving it blank.| +| **A.4** | **Figures**| +| A.4.1 | Do not include figures of religious beliefs.| +| A.4.2 | Include a caption for each figure. Use nouns or noun phrases in the caption.| +| A.4.3 | Figures must be clear, legible, complete, and easy to read. For example, a flowchart must contain "Start" and "End".| +| A.4.4 | Each figure must have clear logic and be provided with relevant text descriptions.| +| A.4.5 | It is recommended that each figure, in .png format, have the size less than or equal to 150 KB, the height about 640 px, and the width less than or equal to 820 px.| +| A.4.6 | Try not to include text in figures. If text is required, make sure the text language is consistent with your file's language.| + + +The following shows an architecture diagram. Pay attention to the **color and format requirements**. + +**Figure 1** Subsystem architecture +![Architecture](../../../../images/en/contribute/template/figures/2731b56deff4fc4291a1523ab3fc5f03.png) + + + +## Directory Structure + +[Writing Instructions] **Mandatory**. Describe the code directory structure of the project repository and function description of the corresponding directory. + +```undefined +/foundation/ace +├── frameworks # Framework code +│ └── lite +│ ├── examples # Sample code +│ ├── include # Exposed header files +│ ├── packages # JS implementation +│ ├── src # Source code +│ ├── targets # Configuration file of each target device +│ └── tools # Tool code +├── interfaces # APIs exposed externally +│ └── innerkits # Header files for internal subsystems +│ └── builtin # Third-party module APIs provided by the JS application framework +``` + + + +## Constraints + +[Writing Instructions] **Optional**. Include the conditions for project running, for example, a specific programming language or a specific operating system with a given version. + +| Item| Requirement| +| -------- | -------- | +| D.1.1 | Clearly specify the function limitations or operation restrictions.| +| D.1.2 | Describe only constraints that affect task development or user experience.| +| D.1.3 | Describe operations that are prone to errors in the procedure, but not in this section.| + + +## Compilation and Building + +[Writing Instructions] **Optional**. This section is not required for a subsystem Readme file. Include this section in a part Readme file based on the actual conditions. + + +## Usage + + +### Available APIs + +[Writing Instructions] **Optional**. Describe the APIs related to the development guide so that developers can have a general understanding of the APIs before development. **This section is not required for a subsystem Readme file.** Determine whether this section is required for a part Readme file based on the actual conditions. If the corresponding API reference is available, you do not need to include this section. The precautions for writing are as follows: + +| Item| Requirement| +| -------- | -------- | +| J.1.1 | Include only APIs relevant to the development task.| +| J.1.2 | Provide only main APIs if there are too many APIs.| + + +### How to Use + +[Writing Instructions] **Optional**. Provide a concept introduction for a subsystem Readme file and function introduction for a part Readme file. If the corresponding development guide is available, you can provide a link, rather than details here. + +The table below describes the writing requirements. After finishing the writing, check your content against these requirements one by one. + +| Item| Requirement| +| -------- | -------- | +| **F.1** | **Writing a Development Procedure**| +| F.1.1 | Complete: Provide all mandatory steps.| +| F.1.2 | Clear: The logic of the writing must be clear and reasonable. The overview, preparations, and operations in the document must be described by following certain logic, and the chapters should not be broken or contradictory.| +| F.1.3 | Sentence pattern for tasks: Use verbs + nouns to describe actions in titles or sentences.| +| F.1.4 | Prevention in advance: If the operation involves restrictions, errors, or potential risks, describe them in advance.| +| F.1.5 | Clear steps-1: Describe the purpose of each step, no matter whether it is simple or not.| +| F.1.6 | Clear steps-2: Specify the environment, tools, operations, and how-to.| +| F.1.7 | If an operation is optional, specify the conditions in which the operation is required.| +| F.1.8 | After the development procedure is complete, specify the expected results.| +| **F.2** | **Writing a Code Segment**| +| F.2.1 | If a code segment involves commands to be copied by developers, display the commands in editable mode, instead of using screenshots. Use code snippets to wrap the commands.| +| F.2.2 | Provide comments for key sections and key steps in the code.| +| F.2.3 | The code display meets the code indentation requirements.| +| F.2.4 | If an API call is involved in a step, provide the API and its usage description or sample code. The code should come from specific instances.| + + +## Repositories Involved + +[Writing Instructions] **Mandatory**. List the links of all related repositories of the subsystem where the current repository is located and mark the current repository in bold. + +Example: + +[Kernel](https://gitee.com/openharmony/docs/blob/master/en/readme/kernel-subsystem.md) + +[drivers\_liteos](https://gitee.com/openharmony/drivers_liteos/blob/master/README.md) + +**kernel\_liteos\_a** \ No newline at end of file diff --git a/website/docs/extras/en/contribute/template/tutorial-template.md b/website/docs/extras/en/contribute/template/tutorial-template.md new file mode 100644 index 0000000000000000000000000000000000000000..33d00fcf602b6821032293740dbb4b3b6ee3884d --- /dev/null +++ b/website/docs/extras/en/contribute/template/tutorial-template.md @@ -0,0 +1,63 @@ +--- +title: "tutorial-template" +prepermalink: /extras/3c4fd526fbf546847d957b27ca5681d4/ +permalink: /extras/3c4fd526fbf546847d957b27ca5681d4/ +relpath: "OpenHarmony-3.1-Release/en/contribute/template/tutorial-template.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [tutorial-template] +--- +# Tutorial Template + +A tutorial describes how to develop a complex task, feature, and application. Usually, the development process is divided into several sections, each with a series of steps. In addition, code examples are provided to help developers understand the specific feature implementation. + +You should explain basic concepts mentioned in the tutorial, and suggest developers refer to specific corresponding topics in developer-oriented documents for in-depth concepts. + +When you write the tutorial page, create a **MarkDown** file in the **others** directory. + +## Overview + +Content: Describe the tasks that developers will do and the features and effects that developers will achieve after learning this tutorial. If multiple goals can be achieved, it is recommended that you use a bulleted list. + +If possible, provide pictures or short videos to demonstrate the effect. + +## Preparations + +- Provide the information about the required software, hardware, tools, and their version information. +- Describe required permissions. + +## _XXX_ \(Key Task 1\) + +Break down the tutorial into several sequential critical tasks or parallel scenario-specific tasks. + +1. XXXX + + ``` + // Sample code + ``` + +2. XXXX + +Comply with the following writing instructions on how to describe operations: + +1. Specify the operation scenario and purpose for each step, and clarify the actor of each action. +2. Provide API descriptions and related sample codes if needed. +3. Provide screenshots of GUI-based steps for better understanding. +4. Ensure that code logic and syntax are correct. +5. Provides comments for key steps in the code. +6. Provide the output content if any. + +## XXX \(Key Task 2\) + +1. XXXX + +## Next + +Describe the subsequent development tasks that may be associated with this tutorial. If there are no associated tasks, skip this topic. + diff --git a/website/docs/extras/en/contribute/template/xxboard-template.md b/website/docs/extras/en/contribute/template/xxboard-template.md new file mode 100644 index 0000000000000000000000000000000000000000..951e2d708c4d368e364024c678596a48858cc414 --- /dev/null +++ b/website/docs/extras/en/contribute/template/xxboard-template.md @@ -0,0 +1,96 @@ +--- +title: "xxboard-template" +prepermalink: /extras/4c4601b938492a0fd14952ca4bb37b99/ +permalink: /extras/4c4601b938492a0fd14952ca4bb37b99/ +relpath: "OpenHarmony-3.1-Release/en/contribute/template/xxboard-template.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [xxboard-template] +--- +# ***ExampleName*** Development Board +*Template positioning: When a third-party development board is introduced to OpenHarmony, the board vendor needs to provide an introduction to the board for developers to quickly understand the board.* + +## Introduction + +*[Writing Instructions]* + +*Describe the functions, scenarios, and key features supported by the development board.* + +*Provide a picture to show the appearance of the development board.* + +*Provide a bottom board picture.* + +*Provide a functional block diagram and an introduction.* + +*Name the figures after the development board.* + +*Reference document: https://gitee.com/openharmony/docs/blob/master/en/device-dev/quick-start/quickstart-lite-introduction-hi3861.md* + +******** +## Development Board Specifications + +*[Writing Instructions] Provide the module and hardware specifications of the development board.* + +## (Optional) Constraints + +*[Writing Instructions] Describe the restrictions and suggestions on functions, features, and specifications of the development board, if any.* + +******** + + +## Key Features +*[Writing Instructions] List supported key features of OpenHarmony.* + +## Pin Definition +*[Writing Instruction] Describe the definitions of I/O pins, and how to configure pins and connect pins to external components.* + +## Setting Up the Development Environment + +### System Requirements + +*[Writing Instruction] Describe the dependency of the development board on the OpenHarmony system, software environment, and hardware environment.* + +### Required Tools + +*[Writing Instruction] Provide the paths for downloading the tools used to build and debug the development board.* + +### Setup Process + +*[Writing Instruction] Describe the procedure for setting up the environment step by step.* + +## Building and Debugging + +### Building + +*[Writing Instruction] Describe how to use OpenHarmony and update OpenHarmony binary files and devices on the development board.* + +### Burning + +*[Writing Instruction] Describe how to burn images step by step.* + +### Running + +*[Writing Instruction] Describe how to check whether the lighting, running, and output of the development board are proper.* + + +### Debugging + +*[Writing Instruction] Describe how to debug common errors on the development board.* + +## First Demo + +*[Writing Instruction] Provide a quick start example and running effect based on the development board, or provide the link of the demo source code.* + +## References + +*[Writing Instruction] Provide links to the reference documents, samples, and FAQs.* + +## (Optional) Acknowledgments + +*[Writing Instruction] Provide acknowledgements to third-party contributors.* diff --git a/website/docs/extras/en/contribute/third-party-open-source-software-and-license-notice.md b/website/docs/extras/en/contribute/third-party-open-source-software-and-license-notice.md new file mode 100644 index 0000000000000000000000000000000000000000..c83e13243803b2d2f97a4418cbaa37847227d437 --- /dev/null +++ b/website/docs/extras/en/contribute/third-party-open-source-software-and-license-notice.md @@ -0,0 +1,115 @@ +--- +title: "third-party-open-source-software-and-license-notice" +prepermalink: /extras/b65f2031dbe607101ebe8d06484bdc98/ +permalink: /extras/b65f2031dbe607101ebe8d06484bdc98/ +relpath: "OpenHarmony-3.1-Release/en/contribute/third-party-open-source-software-and-license-notice.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [third-party-open-source-software-and-license-notice] +--- +# Third-Party Open-Source Software and License Notice + +The following table lists the licenses of the third-party open source software used by OpenHarmony. + +| Open Source Software (Repository)| License | Description| +| :----- | :----- | :----- | +| third_party_bounds_checking_function | Mulan Permissive Software License, Version 2| The license does not require any product that uses such a repository to open their code.| +| third_party_cJSON | MIT License | The license does not require any product that uses such a repository to open their code.| +| third_party_JSON-C | MIT License | The license does not require any product that uses such a repository to open their code.| +| third_party_libuuid | BSD 3-Clause License | The license does not require any product that uses such a repository to open their code.| +| third_party_popt | MIT License | The license does not require any product that uses such a repository to open their code.| +| third_party_LVM2 | GPL V2.0 | third\_party\_LVM2 is an independent process and will not cause other processes to be affected by the GPL.| +| third_party_cryptsetup | GPL V2.0 | third\_party\_cryptsetup is an independent process and will not cause other processes to be affected by the GPL.| +| third_party_cmsis | Apache License V2.0 | The license does not require any product that uses such a repository to open their code.| +| third_party_curl | Curl License | The license does not require any product that uses such a repository to open their code.| +| third_party_FatFs | FatFs license (BSD-style licenses)| The license does not require any product that uses such a repository to open their code.| +| third_party_FreeBSD | BSD 2-Clause License | The license does not require any product that uses such a repository to open their code.| +| third_party_freetype | The FreeType Project License | The license does not require any product that uses such a repository to open their code.| +| third_party_giflib | MIT License | The license does not require any product that uses such a repository to open their code.| +| third_party_googletest | BSD 3-Clause License | The license does not require any product that uses such a repository to open their code.| +| third_party_harfbuzz | MIT License | The license does not require any product that uses such a repository to open their code.| +| third_party_iniparser | MIT License | The license does not require any product that uses such a repository to open their code.| +| third_party_jerryscript | Apache License V2.0 | The license does not require any product that uses such a repository to open their code.| +| third_party_libjpeg | Libjpeg License (JPEG License) | The license does not require any product that uses such a repository to open their code.| +| third_party_libpng | libpng license | The license does not require any product that uses such a repository to open their code.| +| third_party_Linux_Kernel | GPL V2.0+EXCEPTION | The third\_party\_Linux\_Kernel repository contains two modules, jffs2 and scripts.
1. The jffs2 module is introduced to be compatible with Journalling Flash File System version 2 (JFFS2). This module uses the GNU General Public License version 2 (GPLv2) and EXCEPTION licenses, which are available at https://gitee.com/openharmony/third_party_Linux_Kernel/blob/master/fs/jffs2/LICENCE.
OpenHarmony compiles the jffs2 module and uses links in a way that meets the EXCEPTION requirements. The use will not cause other code to be affected by GPLv2.
2. The scripts module is an independent compiler. It is only used to generate the conf and mconf tools during compilation, and its code is not packaged into kernel\_liteos\_a. Therefore, it will not cause kernel_\liteos\_a to be affected by the GPL.| +| third_party_ltp | GPL V2.0 | third\_party\_ltp is an independent process used to test kernel\_liteos\_a APIs across processes. It will not cause kernel_\liteos\_a to be affected by the GPL.| +| third_party_lwip | BSD 3-Clause License | The license does not require any product that uses such a repository to open their code.| +| third_party_mbedtls | Apache License V2.0 | The license does not require any product that uses such a repository to open their code.| +| third_party_mtd_utils | GPL V2.0 | third\_party\_mtd\_utils is used to compile and generate a tool that is used for packaging rootfs and userfs images in JFFS2 format. Its code is not packaged into kernel\_liteos\_a. It will not cause kernel_\liteos\_a to be affected by the GPL.| +| third_party_musl | BSD 2-Clause License | The license does not require any product that uses such a repository to open their code.| +| third_party_NuttX | BSD 3-Clause License | The license does not require any product that uses such a repository to open their code.| +| third_party_openssl | OpenSSL License and Original SSLeay License | The license does not require any product that uses such a repository to open their code.| +| third_party_qrcodegen| MIT License | The license does not require any product that uses such a repository to open their code.| +| third_party_unity | MIT License | The license does not require any product that uses such a repository to open their code.| +| third_party_wpa_supplicant | BSD 3-Clause License | The license does not require any product that uses such a repository to open their code.| +| third_party_zlib | zlib/libpng License | The license does not require any product that uses such a repository to open their code.| +| third_party_rt_thread | Apache License V2.0 | The license does not require any product that uses such a repository to open their code.| +| vendor_hisi_hi35xx_middleware_source_third_party_ffmpeg | LGPL V2.1 | OpenHarmony uses the ffmpeg repository in the GNU Lesser General Public License (LGPL) through a dynamic link. The use will not cause other code to be affected by the LGPL.| +| vendor_hisi_hi35xx_thirdparty_uboot_src | GPL-2.0+ | u-boot is an independent process. Any software other than boot is not affected by the GPL.| +| u-boot in the vendor_hisi_hi3861_hi3861 repository| GPL-2.0+ | u-boot is an independent process. Any software other than boot is not affected by the GPL.| +| third_party_XKeyboardConfig | MIT License | The license does not require any product that uses such a repository to open their code.| +| third_party_abseil-cpp | Apache License V2.0 | The license does not require any product that uses such a repository to open their code.| +| third_party_boost | Boost Software License V1.0 | The license does not require any product that uses such a repository to open their code. Some GPLv2 files in the **tools** and **libs** directories are test files, which are not used during runtime. The use of these files will not cause OpenHarmony processes to be affected by the GPL.| +| third_party_boringssl | OpenSSL License,MIT License,ISC License | The license does not require any product that uses such a repository to open their code.| +| third_party_cares | MIT License | The license does not require any product that uses such a repository to open their code.| +| third_party_css-what | BSD 2-Clause License | The license does not require any product that uses such a repository to open their code.| +| third_party_easymock | Apache License V2.0 | The license does not require any product that uses such a repository to open their code.| +| third_party_eudev | GPL V2.0/LGPL V2.0 | third\_party\_eudev is an independent process invoked by the init process. It will not cause OpenHarmony processes to be affected by the GPL.| +| third_party_expat | MIT License | The license does not require any product that uses such a repository to open their code.| +| third_party_flatbuffers | Apache License V2.0 | The license does not require any product that uses such a repository to open their code.| +| third_party_flutter | BSD 3-Clause License | The license does not require any product that uses such a repository to open their code. Some files use GNU General Public License v2.0 w/Bison exception, but these files are not used in OpenHarmony and will not be packaged. Some files use GPLv2, but they are used only for generating documents and will not cause OpenHarmony processes to be affected by GPLv2.| +| third_party_glib | LGPL V2.1 | third\_party_\glib is called through a dynamic link. It will not cause OpenHarmony processes to be affected by the LGPL.| +| third_party_gn | BSD 3-clause License | The license does not require any product that uses such a repository to open their code.| +| third_party_grpc | Apache License V2.0 | The license does not require any product that uses such a repository to open their code.| +| third_party_gstreamer | LGPL V2.0 | third\_party_\gstreamer is called through a dynamic link. It will not cause OpenHarmony processes to be affected by the LGPL.| +| third_party_javapoet | Apache License V2.0 | The license does not require any product that uses such a repository to open their code.| +| third_party_jinja2 | BSD 3-clause License | The license does not require any product that uses such a repository to open their code.| +| third_party_jsframework | Apache License V2.0 | The license does not require any product that uses such a repository to open their code.| +| third_party_json | MIT License | The license does not require any product that uses such a repository to open their code.| +| third_party_jsoncpp | MIT License | The license does not require any product that uses such a repository to open their code.| +| third_party_junit | EPL V1.0 | This repository is used only for test and involves no changes. It meets the EPL requirements.| +| third_party_libcoap | BSD 3-Clause License | The license does not require any product that uses such a repository to open their code. Some build scripts use Autoconf exception to GPL 2.0 or later, but these scripts are not used in OpenHarmony.| +| third_party_libdrm | MIT license | The license does not require any product that uses such a repository to open their code. Some files use GPL-2.0 WITH Linux-syscall-note, but these files are not used in OpenHarmony. The use of these files will not cause OpenHarmony processes to be affected by GPL-2.0 WITH Linux-syscall-note.| +| third_party_libevdev | MIT License | The license does not require any product that uses such a repository to open their code. Some files use GPL-2.0 WITH Linux-syscall-note, which is the normal use by the UAPI. The use of these files will not cause OpenHarmony processes to be affected by the GPL.| +| third_party_libffi | MIT License | The license does not require any product that uses such a repository to open their code.| +| third_party_libinput | MIT License | The license does not require any product that uses such a repository to open their code. Some files use GPL-2.0 WITH Linux-syscall-note, which is the normal use by the UAPI. The use of these files will not cause OpenHarmony processes to be affected by the GPL.| +| third_party_libphonenumber | Apache License V2.0 | The license does not require any product that uses such a repository to open their code.| +| third_party_libunwind | MIT License | The license does not require any product that uses such a repository to open their code.| +| third_party_libuv | MIT License | The license does not require any product that uses such a repository to open their code.| +| third_party_libxkbcommon | MIT License | The license does not require any product that uses such a repository to open their code.| +| third_party_libxml2 | MIT License | The license does not require any product that uses such a repository to open their code.| +| third_party_markupsafe | BSD 3-clause License | The license does not require any product that uses such a repository to open their code.| +| third_party_mingw-w64 | Zope Public License V2.1 | The license does not require any product that uses such a repository to open their code. Some build scripts use Autoconf exception to GPL 2.0 or later. The use meets its requirements and will not cause OpenHarmony processes to be affected by the GPL. Some header files use LGPL-2.1+ and are invoked through a dynamic link. The use of these files will not cause OpenHarmony processes to be affected by the GPL.| +| third_party_mtdev | MIT License | The license does not require any product that uses such a repository to open their code.| +| third_party_ninja | Apache License V2.0 | The license does not require any product that uses such a repository to open their code.| +| third_party_node | Apache License V2.0
Artistic License 2.0
BSD 2-Clause License
BSD 3-Clause License
ICU License
MIT License
OpenSSL License
Public Domain
SSLeay License
UNICODE INC. LICENSE AGREEMENT - DATA FILES AND SOFTWARE
c-ares license
zlib/libpng License
| The components corresponding to Artistic License 2.0 contained in the software is not used in OpenHarmony. Other licenses do not require the products that use such a repository to open their code.| +| third_party_objenesis | Apache License V2.0 | The license does not require any product that uses such a repository to open their code.| +| third_party_pixman | MIT license | The license does not require any product that uses such a repository to open their code.| +| third_party_protobuf | BSD 3-Clause License | The license does not require any product that uses such a repository to open their code.| +| third_party_python | Python Software Foundation License V2 | The license does not require any product that uses such a repository to open their code. Some build scripts use Autoconf exception to GPL 2.0 or later. The use meets its requirements and will not cause OpenHarmony processes to be affected by the GPL.| +| third_party_re2 | BSD 3-Clause License | The license does not require any product that uses such a repository to open their code.| +| third_party_sqlite | Public Domain | The license does not require any product that uses such a repository to open their code.| +| third_party_wayland-ivi-extension | Apache License V2.0 | The license does not require any product that uses such a repository to open their code.| +| third_party_wayland-protocols_standard | MIT license | The license does not require any product that uses such a repository to open their code. Some build scripts use Autoconf exception to GPL 2.0 or later, but these scripts are not used in OpenHarmony.| +| third_party_wayland_standard | MIT license | The license does not require any product that uses such a repository to open their code. Some build scripts use Autoconf exception to GPL 2.0 or later, but these scripts are not used in OpenHarmony. Some files use Libtool Exception. The use meets its requirements.| +| third_party_weston | MIT license | The license does not require any product that uses such a repository to open their code.| +| third_party_lz4 | BSD 2-Clause License | The license does not require any product that uses such a repository to open their code.| +| third_party_bzip2 | bzip2 and libbzip2 License | The license does not require any product that uses such a repository to open their code.| +| third_party_mksh | MirOS License | The license does not require any product that uses such a repository to open their code.| +| third_party_toybox | Public Domain License | The license does not require any product that uses such a repository to open their code.| +| third_party_optimized_routines | MIT License | The license does not require any product that uses such a repository to open their code.| +| third_party_libsnd | LGPL v2.1 | The license does not require any product that uses such a repository to open their code. Some test code uses GPL-3.0-or-later, and some uses GPL-2.0-or-later.| +| third_party_pulseaudio | LGPL v2.1 | The license does not require any product that uses such a repository to open their code.| +| third_party_ffmpeg | LGPL v2.1 | OpenHarmony uses the ffmpeg repository in the LGPL through a dynamic link. The use will not cause other code to be affected by the LGPL.| +| third_party_quickjs | MIT licence | The license does not require any product that uses such a repository to open their code.| +| third_party_icu | BSD 3-Clause License, ICU License, UNICODE INC. LICENSE AGREEMENT - DATA FILES AND SOFTWARE | The license does not require any product that uses such a repository to open their code.| +| third_party_ejdb | MIT License| The license does not require any product that uses such a repository to open their code.| +| third_party_iowow | MIT License| The license does not require any product that uses such a repository to open their code.| +| third_party_glfw | zlib/libpng License | The license does not require any product that uses such a repository to open their code.| diff --git a/website/docs/extras/en/design/API-Review-Template.md b/website/docs/extras/en/design/API-Review-Template.md new file mode 100644 index 0000000000000000000000000000000000000000..11131938a9e236cb24af28540dfbe5265e324688 --- /dev/null +++ b/website/docs/extras/en/design/API-Review-Template.md @@ -0,0 +1,152 @@ +--- +title: "API-Review-Template" +prepermalink: /extras/91db9f949d0361be6e96e5cf1d820b6e/ +permalink: /extras/91db9f949d0361be6e96e5cf1d820b6e/ +relpath: "OpenHarmony-3.1-Release/en/design/API-Review-Template.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [API-Review-Template] +--- +# Review Application for the API in the OpenHarmony Subsystem + +## Background + +* API type: [Public API | Test API | HDI] +* API requirement source: +* API usage scenario: +* Belonging subsystem: +* Expected API release version: +* Contributor: +* Number of APIs involved in this review: + +| Change Type| Quantity| Programming Language| +|---|---|---| +| Added| | | +| Behavior changed| | +| Deprecated| | | +| Deleted| | | + +## API Description + +### Necessity of the Changes + +> Based on the as-is and gap analysis, describe what the application scenarios and benefits of the APIs are. + +### Feature Overview + +> Describe features implemented by the APIs. + +## Review Conclusion + +### Review Conclusion from Committers + +### Review Conclusion from Domain SIGs + +## Self-Check Table + +| Self-Check Item| Self-Check Result| +|---|---| +| Is the spelling check completed?| | +| Are coding specifications complied with?| | +| Are parts of speech (noun, adjective, adverb) used correctly?| | +| Does the API name fully describe the API logic?| | +|Is the number of API parameters appropriate? (Generally, there should be fewer than 7 parameters.)| | +|Are abbreviations properly used? (Abbreviations used should be well known.)| | +|Is it really that the caller of a void API does not need a return value?| | +|Is the inheritance system appropriate? Does every method of a parent class apply to its child classes?| | +|Are all possible error states included and defined?| | +| Is the group of antonyms used correctly, for example:
add/remove, create/destroy, insert/delete, start/stop, begin/end,
send/receive, up/down, show/hide, open/close, source/target,
source/destination, increase/decrease, first/last, next/previous| | +|Are the description and semantic hierarchy of new APIs consistent with those of existing APIs in the same module?| | +| Are asynchronous counterparts needed for synchronous APIs?| | +| Are all the public APIs truly required by developers?| | + +## API Description + +> Enter the code commit address. + +* Code address: + +## API Permission Design + +> Specify whether developers need to apply for certain permissions to use the APIs. + +## API Privacy Protection Design + +> If user privacy data is involved, privacy protection must be considered. + +## Developer Guide + +> Optional. + +## API Code Example + +> Select either of the following: + +* Code address: +* Code snippet: + +## API Updates + +> Only required for existing APIs. + +### Behavior Change + +> The API behavior change indicates that the API only has its behavior changed. +> The new API behavior must be released in a new version. You should not change the API behavior without releasing a new version (except for defect rectification). + +#### Related APIs + +#### Reason for the Change + +### Deprecated APIs + +> Add the `@deprecated` annotation to the description of deprecated APIs (including JS, TS, C, and C++ APIs). + +#### Related APIs + +> State the version from which the API is annotated by `@deprecated`. + +#### Reason for Deprecation + +#### Substitute APIs + +> List the APIs provided to substitute the deprecated ones. If there are no substitute APIs provided, describe the reason. + +### Deleted APIs + +> An API can be deleted only after five API versions have been released since it is marked as deprecated. + +#### Related APIs + +#### Reason for Deletion + +#### Substitute APIs + +> List the APIs provided to substitute the deleted ones. If there are no substitute APIs provided, describe the reason. + +## DFX + +### Compatibility + +### Performance + +### Power Consumption + +### Reliability + +### Testability + +> Automatic API test cases must be delivered for all APIs. + +## Review Conclusion + +* Reviewed on: +* Reviewers: +* Review conclusion: [Pass | Fail] +* Review meeting minutes: diff --git a/website/docs/extras/en/design/OpenHarmony-API-governance.md b/website/docs/extras/en/design/OpenHarmony-API-governance.md new file mode 100644 index 0000000000000000000000000000000000000000..49d2a5d832fe25c0e32f86efd720e43ebfe9b819 --- /dev/null +++ b/website/docs/extras/en/design/OpenHarmony-API-governance.md @@ -0,0 +1,220 @@ +--- +title: "OpenHarmony-API-governance" +prepermalink: /extras/b807da2beb4ff2e22b6e5f79844d8777/ +permalink: /extras/b807da2beb4ff2e22b6e5f79844d8777/ +relpath: "OpenHarmony-3.1-Release/en/design/OpenHarmony-API-governance.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [OpenHarmony-API-governance] +--- +# OpenHarmony API Governance Charter + +## Introduction + +To help the OpenHarmony ecosystem develop and evolve in a healthy and orderly way, this Charter defines the governance process and lifecycle (create, change, deprecate, and delete) of OpenHarmony APIs. It also specifies basic design requirements of OpenHarmony APIs. + +This Charter is formulated by the API SIG and approved by the PMC for release. Any revision to this Charter will be released only after being reviewed by the API SIG and approved by the PMC. + +## Overview + +### Scope and Definition + +The OpenHarmony software stack contains multiple roles. Naturally, OpenHarmony APIs have multiple types. + + + +Different types of APIs have different compatibility requirements, as described in the table below. + +| Type| Prepared By| Used By| Compatibility Requirement| Guarding Method| +|---|---|---|---|---| +| Public API | System and framework| All application developers| 5 API versions| X test suite (XTS)| +| Test API | Test framework| All application developers| 3 API versions| To be built| +| System API | System and framework|System application developers|Not guaranteed| To be built| +| HDI | HDF| System services| 4 API versions| XTS | +| Driver API | HDF | Driver developers| Not guaranteed| None| +| Inner API | System parts| System parts| Not guaranteed| None| + +The APIs are described as follows: + +* Public API: APIs provided for all application developers. +* Test API: APIs provided for developers to test their applications. +* System API: APIs provided for privileged system applications. Common applications cannot use these APIs. +* HDI: APIs that describe hardware capabilities. +* Driver API: APIs provided for driver developers. +* Inner API: APIs to implement mutual calling between the system service and framework. They are used only inside the system and do not guarantee compatibility. + +### APIs and Programming Languages + +OpenHarmony aims to build a next-generation Operating System (OS) for the Internet of Everything (IoE) era. The following programming languages and more can be used: + +* C/C++ +* JavaScript +* TypeScript + +The content described in this Charter is irrelevant to the programming language in use. Regardless of the programming language, APIs must comply with this Charter while meeting the programming language requirements. + +## API Governance + +### Roles and Responsibilities + +|**Role**|**Responsibilities in API Governance**| +| - | - | +|Contributor|Commit API code and design documents.| +|Committer|Review the code and submit a pre-review comment on an API commit.| +|Domain SIG|Comment on the commits of new API code, so the passed commits can be merged.
Submit a pre-review comment on updated API code.| +|API SIG|Comment on updated API code.| +|PMC|Release API version plans. Review amendments of this Charter, revise the terms, and publish this Charter.| + +### API Review Process +The API review process is as follows: + + + +The main process is as follows: + +1. Initiate API review and commit code (contributor). If any APIs are added or modified, the contributor must additionally submit an API review application to specify the API requirement source, usage scenario, permission design, and privacy protection design. For details, see "API Review Application Composites" below. To avoid rework, the contributor can send an email to submit the API design document to the committer, domain SIG, and API SIG for pre-review before the formal API review application and code commit. +1. Review code (committer). After the code review is approved, the committer should submit the APIs to the domain SIG. If the API code involves multiple domains, they should be submitted to the committers of the corresponding domains. The next review step can be performed only after all committers review and approve the code. +1. Review APIs (domain SIG). The code of new APIs can be merged only after being reviewed and approved by the domain SIG. If there are changes to existing APIs, the domain SIG should submit them to the API SIG. If the new APIs involve multiple domains, they should be submitted to the SIGs of the corresponding domains. The code can be merged after being reviewed and approved by one of the domain SIGs. If the changed APIs involve multiple domains, they should be submitted to the SIGs of the corresponding domains. The next review step can be performed only after all domain SIGs approve the APIs. +1. Review API changes (owner: API SIG): The code of changed APIs can be merged only after being reviewed and approved by the API SIG. +1. The review is complete. + +### API Review Application Composites + +If an API is added or changed, the corresponding API review application must be submitted. For details on the application template, see [API Review Template](/extras/91db9f949d0361be6e96e5cf1d820b6e/). + +For new APIs, you must: +1. (Mandatory) Describe the requirement source and usage scenario. +1. (Mandatory) Analyze the API as-is and gaps, and describe the necessity of adding or changing APIs. +1. (Mandatory) Describe the API prototype design and usage. (Optional) When necessary, add use examples. +1. (Mandatory) Provide the API permission design. +1. (Mandatory) Clarify the API privacy protection solution and requirements fulfillment. +1. (Mandatory) Submit the corresponding API reference when committing the code. (Optional) When necessary, submit the corresponding developer guide. +1. (Optional) Describe the compatibility, performance, power consumption, reliability, and tests. (If "API Design Requirements" of this Charter are not met, the description must be included.) + +For changed APIs, except the preceding operations, you must: +1. (Mandatory) Describe how earlier APIs are handled (deprecated, hidden, or permanently deleted) and compatibility measures for developing applications using old SDKs. +2. (Mandatory) Describe the change impact, substitute APIs, and corresponding application adaptation solution. +3. (Mandatory) Update the ChangeLog file. Update the API-diff file (Mandatory if JS or native API changes are involved.) + +## API Design Requirements + + +### Consistency +1. Concept: Scenario-based service models must be abstracted to form coherent, consistent, and self-consistent OpenHarmony user program models and service concepts. +1. Term: Service terms must be nouns. Multiple nouns with similar semantic meanings are not allowed to represent the same service object. Similarly, to avoid confusion, it is not allowed to use the same noun or linguistically close nouns for different service objects. +1. Operation: Every operation action must be expressed using a unique verb. +1. Parameter sequence: The location and sequence of the same parameter or parameter sequence in multiple APIs must be the same. +1. Mechanism and algorithm: The communication mechanism, calling mode, authentication mechanism, and encryption algorithm must be consistent. +1. API reference, demo, and template style: The layout and usage must be consistent. + +### Ease to Use +Design APIs from the perspective of their users rather than providers. +1. Readability: API naming and features must be easy to understand. +1. Ease of use: Provide easy-to-use APIs by reducing unnecessary coupling between APIs, avoiding dependencies on the calling sequence of multiple unrelated APIs, and avoiding calling multiple methods from different packages, modules, or classes at the same time when using a single feature. +1. Avoiding misleading: Provide capabilities complying with user expectations to avoid misuse. +1. Provide required API reference documents. + +### Naming +1. Be able to express the capabilities clearly. Use full descriptive words. +1. Avoid misleading. Misleading names are more harmful than ill-stated ones. +1. Use words with clear meaning. Do not use words with common meanings, such as info, data, and object. +1. The larger the scope is, the more precise the naming should be. +1. Eliminate or minimize the use of abbreviations. Common terms in the industry must comply with industry conventions and can be abbreviated. +1. Bundle name/Module name/Namespace prefix convention: + 1. JS API module name: @ohos.\*. + 2. Native API namespace: namespace OHOS.\*. + 3. If external open-source code is referenced, retain the original bundle name, module name, or namespace, or replace the bundle name according to the preceding rules. +1. The bundle name, module name, and namespace must contain 2 to 4 segments. One word is recommended for each segment, and a maximum of two words are allowed. +1. The class name, method name, function name, member variable, and variable name cannot exceed four words. + +### Permission Control +1. Completeness: All behaviors across application sandboxes must be limited by permission control. +1. Optimal granularity: One permission protects only one type of object. Developers only need to apply for one permission to access an interface. +1. Clearness: The protected object, permission scope, and sensitivity level must be clearly specified in the permission definition. +1. Minimum scope: A permission is assigned only to applications that have service requirements to minimize permission scope. + +### Privacy Protection +1. The response returned from API calling should contain only necessary information. +1. Mobile phone users' personal data cannot be obtained through API calling unless required permissions are assigned by users. +1. In case that an API is called by multiple applications, if personal data needs to be disclosed to the API to be called, the caller must specify the disclosed data type, data receiver, and data use purpose in the privacy statement. +1. When an API needs to access sensitive user data (such as phone calls, contacts, and media content), the system picker mechanism must be used to prevent the API from accessing the data through sensitive permission application. +1. API openness does not allow unrelated features. + +### Documentation +1. The API reference document must be written in English. +1. The API reference document must include the brief and detailed descriptions of modules and packages. +1. The API reference document must include brief descriptions of classes, methods, interfaces, enumerations, and member variables. +1. The API reference document can optionally include detailed descriptions of classes, methods, interfaces, enumerations, and member variables. +1. The API reference document must contain descriptions of all input parameters of every method or interface. +1. If a method or interface has a return value, the API reference document must contain a return value description. +1. If an exception may be thrown during the execution, the API reference document must contain the exception description. +1. The starting version of the API (annotated with @since) must be included. +1. The version of a module or class (annotated with @version) is optionally included. +1. If incompatible API changes are involved, both API-Diff and ChangeLog files must be delivered. + +### Compatibility +1. The API compatibility requirements in descending order are as follows: contract compatibility > binary-code compatibility > source-code compatibility. + 1. Source-code compatibility: After version evolution, the existing source code can be compiled properly. + 1. Binary-code compatibility: After version evolution, the existing programs can be linked to and run properly without recompilation. + 1. Contract compatibility: also called semantic compatibility. After version evolution, the original program behaviors remain unchanged. +1. API backward compatibility must meet binary-code compatibility requirements. Exceptions must be reviewed by the API SIG and approved by the PMC. Common API changes that break binary-code compatibility include: + 1. Delete any API elements. + 1. Reduce the visibility of a method. For example, change from protected to private or from public to protected. + 1. Change the class type. For example, change from an abstract class to a non-abstract class, or from an interface class to a non-interface class. + 1. Change the method prototype. For example, change the return value type, input parameter sequence, or input parameter type. + 1. Change the member attributes. For example, change the member attribute from non-final to final or from non-static to static. +1. Do not modify APIs with the same prototype but incompatible features. You can modify APIs by deprecating old APIs and adding new ones with restrictions. +1. Depending on the release type, the API lifecycle and compatibility requirements are as follows: + +![](../../../images/en/design/figures/7461841a548d4669142e1a3223ca1c5e.png) + + 1. Canary version: API Preview version released at an earlier date, which cannot ensure API stability. + 1. Canary versions are compatible with the previous Release version. + 1. Different Canary versions of the same API version are not required to keep compatible. + 1. Beta version: publicly released beta version, which cannot ensure API stability. + 1. Beta versions are compatible with the previous Release version. + 1. Beta versions are not compatible with the early Canary versions of the same API version. + 1. Different Beta versions of the same API version are not required to keep compatible. + 1. The APIs are frozen after the API Stable version is released. API additions or changes are not allowed for later Beta versions. + 1. Release version: official API release version. + Released APIs must comply with the contractual commitments made to developers. In principle, incompatible changes cannot be made on released APIs, and deprecation of released APIs is restricted. The basic requirements for deprecating released APIs are as follows: + 1. Add the @deprecated annotation. + 1. Provide substitute APIs. + 1. Retain the deprecated APIs in at least five API versions released since the deprecation. + +### Performance +1. Respond in a timely manner to avoid callers waiting. If an API call takes a long time, use an asynchronous API. +2. Pay attention to the impact of the API call timing and frequency on the RAM usage. +3. Pay attention to the impact of the API call timing and frequency on power consumption. +4. Resources must be released in a timely manner when APIs that use resources are called. A fault tolerance mechanism must be provided for abnormal scenarios to ensure timely resource release. + +### Power Consumption + +1. Evaluate the impact of the API call timing and frequency on power consumption, and perform related design if there is any impact. +2. The power consumption should not deteriorate during version evolution. + +### Reliability + +1. APIs cannot crash due to external input (such as input parameters, system status, and external data), internal status, or data exceptions. It must return a specific error code or throw a predefined exception. +2. It must be specified whether an API is called synchronously or asynchronously. If an API is called synchronously, specify the timeout duration or allow the caller to set the timeout duration to prevent service response failure caused by call suspension. +3. APIs must support multi-thread reentrant. +4. APIs must meet the idempotence requirement, which means that the same effect should be obtained for one or multiple API call requests with the same service meaning (except that API call depends on external resource changes). For reentrant API call, avoid introducing time-varying factors, such as system ticks, static variables, and global variables without mutual exclusion protection. For repeated call of the same client, **contextID**, **clientToken**, and **squenceNo** can be used as input parameters. +5. The lifecycle of objects created in APIs must have an end to prevent object resource leakage. +6. The APIs must specify the maximum number of retries allowed after a call failure. + +### Testing +1. Automatic API test cases must be delivered for all new APIs. +2. Use a test case for each single scenario. One test case covers a single function of an API, simplifying the code logic of each single test case. +3. The test case execution must be efficient. The execution time of each test case must be limited to milliseconds. +4. Automatic API test cases must be available for all APIs. +5. Assertions with functional logic are required in addition to the capability of throwing exceptions. + +### Programming Languages + +Regardless of the programming language in use, APIs must comply with the OpenHarmony programming language specifications. diff --git a/website/docs/extras/en/design/OpenHarmony-part-design.md b/website/docs/extras/en/design/OpenHarmony-part-design.md new file mode 100644 index 0000000000000000000000000000000000000000..dd1b21156842c61ace64d5c071957b45d326b2a7 --- /dev/null +++ b/website/docs/extras/en/design/OpenHarmony-part-design.md @@ -0,0 +1,131 @@ +--- +title: "OpenHarmony-part-design" +prepermalink: /extras/5ff37003f88339fa9472668f12057c5f/ +permalink: /extras/5ff37003f88339fa9472668f12057c5f/ +relpath: "OpenHarmony-3.1-Release/en/design/OpenHarmony-part-design.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [OpenHarmony-part-design] +--- +# OpenHarmony Part Design Guide + +## About This Document + +For easy software design and management, OpenHarmony decouples software from physical components, parts, and modules. A **component** can be independently deployed and reused at the binary level. A **part** can be independently developed, built, and tested. A **module** can be reused at the code level. + +OpenHarmony abstracts system capabilities as parts, so you can customize OSs for different devices by assembling and configuring these parts. + +## Part Definition + +A part is the basic unit of system capabilities. Divided based on source code, every part has independent files and directories, and can be instantiated into libraries or executable files on different devices. + +## Part Division + +Follow the following rules for part classification: + +- A part must have an independent code directory for compiling libraries or executable files. + +- A part must be able to be independently deployed in the small system or standard system. Optional parts can be tailored without causing system exceptions. + +- Functions of a part must be able to be independently tested and verified. + +A part always belongs to a specific subsystem. A subsystem is a logical concept and consists of specific parts. + +Note the following: + +- External APIs provided by a part must be the same regardless of whether the configurable features of the part are configured. + +- Dependent third-party open source software libraries and parts that provide basic capabilities are called **dependent parts**, which must be deployed with other parts. + +- If a part can be split into smaller functional modules and provide APIs for applications, these modules are called **child parts**, which must be deployed with the parent part. A child part depends on a parent part, but a parent part does not depend on a child part. + +## Basic Principles + +Comply with the following rules and recommendations during parts design and development: + +**Rule 1.1** Parts must be developed individually to ensure decoupling and independence. + +**Rule 1.2** Parts must be managed in a decentralized manner. The dependency between parts must be simple, clear, and reasonable. + +**Rule 1.3** Reverse dependency and cyclic dependency between parts are prohibited. Lower-layer parts must not depend on upper-layer parts. + +**Rule 1.4** It is prohibited that the implementation of a part depends on a specific development board or product form. + +**Rule 1.5** APIs provided by a part must be stable and compatible. Changes to released APIs are prohibited. + +**Rec 1.1** Parts should support automated build and verification. + +## Naming Rules + +#### **Part Name** + +The name must reflect the key function of a part and must be globally unique in the system. The name can contain a maximum of 63 characters and must be in the unix\_like style, where only lowercase letters separated by underscores (\_) are used. + +#### **Repository Name** + +The part repository is named in the format of \_. For example, the repository name of the storage service part in the file management subsystem is **filemanagement\_storage\_service**. The repository name can contain a maximum of 100 characters. + +> Note: +> +> 1. In principle, there is a one-to-one mapping between parts and repositories. In some cases, multiple parts can share a repository, but they must have independent directories. +> +> 2. For a third-party open source part, use the original name with the prefix **third\_party**. All third-party open source parts are stored in the **third\_party** directory. +> +> 3. The subsystem names in the repository name and path should not contain underscores (\_). + +#### **Path** + +The part name must be in the format of //, for example, **foundation/filemanagement/storage_service**. + +#### **Part Directory Structure** + +```xml +├── interfaces # APIs +│ ├── kits # Application APIs (optional) +│ │ ├── js # JS APIs (optional) +│ │ └── native # C/C++ APIs (optional) +│ └── inner_api # Internal APIs of parts +├── frameworks # Implementation of the part without independent processes (optional) +│ ├── native # C/C++ API implementation (optional) +│ └── js # JS API implementation (optional) +│ ├── napi # Native API implementation (optional) +│ ├── builtin # Specific to LiteOS-M (optional) +│ └── plugin # Specific to ArkUI (optional) +├── services # Implementation of parts with independent processes (optional) +├── test # Test code (mandatory) +├── BUILD.gn # Entry to build (mandatory) +└── bundle.json # Part description file (mandatory) +``` + +## Adding, Deleting, or Modifying Parts + +The addition, deletion, and modification of parts must be reviewed by the architecture SIG and [related domain SIGs](https://gitee.com/openharmony/community/blob/master/sig/sigs_subsystem_list.md). The review process is as follows: + +1. Prepare the following part attribute review form. + +Table 1 Part attribute review form + +| Part Attribute| Description| +| ------------ | ------------------------------------------------------------ | +| Part name| The name must reflect the key function of a part and must be globally unique in the system. The name can contain a maximum of 63 characters and must be in the unix\_like style, where only lowercase letters separated by underscores (\_) are used.| +| Subsystem| Subsystem to which the part belongs.| +| Function description| Brief description of the functions of the part in one or two sentences.| +| Configurable features| Features that can be configured externally.| +| Applicable systems| Mini system, small system, standard system, or their combinations.| +| Source code directory| Root directory of the source code of the part.| +| ROM | ROM baseline value of the part.| +| RAM | RAM baseline value of the part.| +| Dependencies| Parts and open source software on which the part depends.| + + +2. Send an email to the architecture SIG (dev@openharmony.io) and the [related domain SIG leaders](https://gitee.com/openharmony/community/blob/master/sig/sigs_subsystem_list.md) for review. Use "Application for Adding/Deleting/Modifying OpenHarmony Parts" as the email subject, and include the filled-in **Table 1 Part Attribute Review Form** in the email body. + +> Note: For modified parts, provide a before and after comparison of the part attributes. For deleted parts, provide the plan for stopping part maintenance. Exercise caution when deleting or modifying parts and evaluate the impact on existing versions. + +3. After the review is passed, create a part repository and modify the manifest according to [SIG Management Regulations](https://gitee.com/openharmony/community/blob/master/sig/README-EN.md). After the SIG is incubated, incorporate it into the main code library of OpenHarmony. diff --git a/website/docs/extras/en/device-dev/Readme-EN.md b/website/docs/extras/en/device-dev/Readme-EN.md new file mode 100644 index 0000000000000000000000000000000000000000..3447c42906c3c085075ca2bdd55c567cd5758183 --- /dev/null +++ b/website/docs/extras/en/device-dev/Readme-EN.md @@ -0,0 +1,74 @@ +--- +title: "Readme-EN" +prepermalink: /extras/69fd38f03840594f002cad0d5bad3962/ +permalink: /extras/69fd38f03840594f002cad0d5bad3962/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/Readme-EN.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [Readme-EN] +--- +# Device + +- [Device Development Overview](/pages/en/device/device/Device%20Development%20Guide) +- Learn About OpenHarmony + - [OpenHarmony Community](/pages/en/overview/OpenHarmony%20Project) + - [Glossary](/pages/en/overview/Glossary) + - [Release Notes](/extras/348bb39c5ace3e332174966f24395f95/) +- Quick Start + - [Mini and Small Systems](/extras/989355ccbbb782c8a0724811e8302ac3/) + - [Standard System](/extras/e0c7fb7adf8f26e1f508dc8bd7bd89c7/) +- Compatibility and Security + - [Privacy and Security](/extras/f6ea01c30c3dafebebd15b2f9d77896c/) +- Porting + - [Third-Party Library Porting Guide for Mini and Small Systems](/extras/9949eaeec6b11b95dd62f95a73f7c4cc/) + - [Mini System SoC Porting Guide](/extras/b4177a347580663ec15dd4c5ef19d569/) + - [Small System SoC Porting Guide](/extras/c9e561e6c3dae45fda2531abc17abcfa/) + - [Standard System SoC Porting Guide](/pages/en/device/device/Porting/Standard%20System%20SoC%20Porting%20Guide/Standard%20System%20Porting%20Guide) +- Subsystem Development + - Kernel + - [Kernel for the Mini System](/extras/bf8496454cb9a8c0712aa081ac032dae/) + - [Kernel for the Small System](/extras/b1a8758905970b3469be3718a08589d4/) + - [Kernel for the Standard System](/extras/6b7b37f37bac90610514997ec2249095/) + - [Driver](/extras/14d9c71d2671b2a4a270579c16336f6c/) + - [Compilation and Building](/extras/2ce98dbc2719223219b20eb0f7d00e31/) + - [Distributed Remote Startup](/pages/en/device/device/Subsystem%20Development/Distributed%20Remote%20Startup) + - [Graphics](/extras/c0ebe908e23b0532ab29175059c8af86/) + - [Multimedia](/extras/b47c31807da4c3c1d56185bd379d1d88/) + - [Utils](/extras/86c0c3274782b6d8968985efa173550a/) + - [AI Framework](/extras/ed79ebf1ef1b2b3a4fd6c31dfc897698/) + - [Data Management](/extras/0f8610ee82cd7d9cc57373357c80c126/) + - [Sensor](/extras/0661059c61750192d79b4d239fbb8b9f/) + - [USB](/extras/b369b4c707832a118f0debb612ae80e7/) + - [Application Framework](/extras/19da893c74d774705f66901ba9ac7e84/) + - [OTA Upgrade](/pages/en/device/device/Subsystem%20Development/OTA%20Upgrade) + - [Telephony Service](/extras/75efd89b92d7bbfda3c18d517d2afd6d/) + - [Security](/extras/761e170abf654d46030b51062e52da28/) + - [Startup](/extras/b03067b48ab81658870f4365d35e1754/) + - [DFX](/extras/23b00c9d5647ac514773855c0421a371/) +- Featured Topics + - [HPM Bundle](/extras/fda6a7a1a53e32f5c0b7d543e424f102/) +- Device Development Examples + - [Mini- and Small-System Devices](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Mini-%20and%20Small-System%20Devices) + - [Standard-System Devices](/pages/en/device/device/Device%20Development%20Examples/Standard-System%20Devices/Standard-System%20Devices) +- Debugging + - [Test Subsystem](/pages/en/device/device/Debugging/Test%20Subsystem) + - [R&D Tools](/pages/en/device/device/Debugging/R%26D%20Tools/R%26D%20Tools) +- XTS Certification + - [XTS](/pages/en/device/device/XTS%20Certification/XTS) +- Tools + - [Docker Environment](/pages/en/device/device/Tools/Docker%20Environment) + - [IDE](/pages/en/device/device/Tools/IDE) + +- Hands-On Tutorials + - [Samples](https://gitee.com/openharmony/app_samples/blob/master/README.md) + - [Codelabs](https://gitee.com/openharmony/codelabs/blob/master/README.md) +- References + - [FAQs](/extras/9fc267037ba49a324b4bb03cd7f6abe7/) +- Contribution + - [How to Contribute](/pages/en/overview/Contribution/Contribution) \ No newline at end of file diff --git a/website/docs/extras/en/device-dev/bundles/Readme-EN.md b/website/docs/extras/en/device-dev/bundles/Readme-EN.md new file mode 100644 index 0000000000000000000000000000000000000000..e9bf4f967859ee390e8f3c82b2e1edee9edeaf6e --- /dev/null +++ b/website/docs/extras/en/device-dev/bundles/Readme-EN.md @@ -0,0 +1,20 @@ +--- +title: "Readme-EN" +prepermalink: /extras/fda6a7a1a53e32f5c0b7d543e424f102/ +permalink: /extras/fda6a7a1a53e32f5c0b7d543e424f102/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/bundles/Readme-EN.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [Readme-EN] +--- +# Bundles + +- [HPM Part Overview](/pages/en/device/device/Featured%20Topics/HPM%20Bundle/HPM%20Part%20Overview) +- [HPM Part Development](/pages/en/device/device/Featured%20Topics/HPM%20Bundle/HPM%20Part%20Development) +- [HPM Part Reference](/pages/en/device/device/Featured%20Topics/HPM%20Bundle/HPM%20Part%20Reference) diff --git a/website/docs/extras/en/device-dev/driver/Readme-EN.md b/website/docs/extras/en/device-dev/driver/Readme-EN.md new file mode 100644 index 0000000000000000000000000000000000000000..11229201a682fbccde541a04ee9724b083d525f5 --- /dev/null +++ b/website/docs/extras/en/device-dev/driver/Readme-EN.md @@ -0,0 +1,64 @@ +--- +title: "Readme-EN" +prepermalink: /extras/14d9c71d2671b2a4a270579c16336f6c/ +permalink: /extras/14d9c71d2671b2a4a270579c16336f6c/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/driver/Readme-EN.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [Readme-EN] +--- +# Drivers + +- [HDF](/extras/d2551de5b6d3b8974848851e5f27fcb1/) + - [HDF Overview](/pages/en/device/device/Subsystem%20Development/Driver/HDF/HDF%20Overview) + - [Driver Development](/pages/en/device/device/Subsystem%20Development/Driver/HDF/Driver%20Development) + - [Driver Service Management](/pages/en/device/device/Subsystem%20Development/Driver/HDF/Driver%20Service%20Management) + - [Driver Message Mechanism Management](/pages/en/device/device/Subsystem%20Development/Driver/HDF/Driver%20Message%20Mechanism%20Management) + - [Driver Configuration Management](/pages/en/device/device/Subsystem%20Development/Driver/HDF/Driver%20Configuration%20Management) + - [HDF Development Example](/pages/en/device/device/Subsystem%20Development/Driver/HDF/HDF%20Development%20Example) +- [Platform Driver Development](/extras/19111b13a03f8ad3e8db558338312852/) + - [ADC](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Development/ADC) + - [GPIO](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Development/GPIO) + - [HDMI](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Development/HDMI) + - [I2C](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Development/I2C) + - [I3C](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Development/I3C) + - [MIPI CSI](https://www.openharmony.cn/404/driver-platform-mipicsi-develop.md) + - [MIPI DSI](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Development/MIPI%20DSI) + - [MMC](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Development/MMC) + - [Pin](/extras/868242fe4bd5c4273dc5eed7318ae654/) + - [PWM](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Development/PWM) + - [Regulator](/extras/b5feae5028d87c42c529613d04cfad1c/) + - [RTC](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Development/RTC) + - [SDIO](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Development/SDIO) + - [SPI](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Development/SPI) + - [UART](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Development/UART) + - [Watchdog](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Development/Watchdog) +- [Platform Driver Usage](/extras/b8a2d4bd1adb53721f2eb736dffeefde/) + - [ADC](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Usage/ADC) + - [GPIO](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Usage/GPIO) + - [HDMI](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Usage/HDMI) + - [I2C](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Usage/I2C) + - [I3C](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Usage/I3C) + - [MIPI CSI](/extras/b3e48ac8c5f33df76f82989b158f6a71/) + - [MIPI DSI](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Usage/MIPI%20DSI) + - [PWM](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Usage/PWM) + - [Regulator](/extras/8af710ed51e79c71b8036f24b1022b54/) + - [RTC](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Usage/RTC) + - [SDIO](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Usage/SDIO) + - [SPI](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Usage/SPI) + - [UART](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Usage/UART) + - [Watchdog](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Usage/Watchdog) +- [Peripheral Driver Usage](/extras/11ca76760a0ffd994b59a81dff37a91f/) + - [LCD](/pages/en/device/device/Subsystem%20Development/Driver/Peripheral%20Driver%20Usage/LCD) + - [Touchscreen](/pages/en/device/device/Subsystem%20Development/Driver/Peripheral%20Driver%20Usage/Touchscreen) + - [Sensor](/pages/en/device/device/Subsystem%20Development/Driver/Peripheral%20Driver%20Usage/Sensor) + - [WLAN](/pages/en/device/device/Subsystem%20Development/Driver/Peripheral%20Driver%20Usage/WLAN) + - [Audio](/pages/en/device/device/Subsystem%20Development/Driver/Peripheral%20Driver%20Usage/Audio) + - [USB](/pages/en/device/device/Subsystem%20Development/Driver/Peripheral%20Driver%20Usage/USB) + - [Camera](/pages/en/device/device/Subsystem%20Development/Driver/Peripheral%20Driver%20Usage/Camera) \ No newline at end of file diff --git a/website/docs/extras/en/device-dev/driver/driver-develop.md b/website/docs/extras/en/device-dev/driver/driver-develop.md new file mode 100644 index 0000000000000000000000000000000000000000..8a8ee9d1a8aa1c5f566f9ae76cb040147604300a --- /dev/null +++ b/website/docs/extras/en/device-dev/driver/driver-develop.md @@ -0,0 +1,46 @@ +--- +title: "driver-develop" +prepermalink: /extras/19111b13a03f8ad3e8db558338312852/ +permalink: /extras/19111b13a03f8ad3e8db558338312852/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/driver/driver-develop.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [driver-develop] +--- +# Platform Driver Development + +- **[ADC](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Development/ADC)** + +- **[GPIO](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Development/GPIO)** + +- **[HDMI](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Development/HDMI)** + +- **[I2C](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Development/I2C)** + +- **[I3C](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Development/I3C)** + +- **[MIPI CSI](https://www.openharmony.cn/404/driver-platform-mipicsi-develop.md)** + +- **[MIPI DSI](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Development/MIPI%20DSI)** + +- **[MMC](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Development/MMC)** + +- **[PWM](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Development/PWM)** + +- **[RTC](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Development/RTC)** + +- **[SDIO](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Development/SDIO)** + +- **[SPI](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Development/SPI)** + +- **[UART](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Development/UART)** + +- **[Watchdog](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Development/Watchdog)** + + diff --git a/website/docs/extras/en/device-dev/driver/driver-hdf.md b/website/docs/extras/en/device-dev/driver/driver-hdf.md new file mode 100644 index 0000000000000000000000000000000000000000..0a84168e908ffb0bff7f841378556bc525146657 --- /dev/null +++ b/website/docs/extras/en/device-dev/driver/driver-hdf.md @@ -0,0 +1,30 @@ +--- +title: "driver-hdf" +prepermalink: /extras/d2551de5b6d3b8974848851e5f27fcb1/ +permalink: /extras/d2551de5b6d3b8974848851e5f27fcb1/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/driver/driver-hdf.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [driver-hdf] +--- +# HDF + +- **[HDF Overview](/pages/en/device/device/Subsystem%20Development/Driver/HDF/HDF%20Overview)** + +- **[Driver Development](/pages/en/device/device/Subsystem%20Development/Driver/HDF/Driver%20Development)** + +- **[Driver Service Management](/pages/en/device/device/Subsystem%20Development/Driver/HDF/Driver%20Service%20Management)** + +- **[Driver Message Mechanism Management](/pages/en/device/device/Subsystem%20Development/Driver/HDF/Driver%20Message%20Mechanism%20Management)** + +- **[Driver Configuration Management](/pages/en/device/device/Subsystem%20Development/Driver/HDF/Driver%20Configuration%20Management)** + +- **[HDF Development Example](/pages/en/device/device/Subsystem%20Development/Driver/HDF/HDF%20Development%20Example)** + + diff --git a/website/docs/extras/en/device-dev/driver/driver-peripherals-light-des.md b/website/docs/extras/en/device-dev/driver/driver-peripherals-light-des.md new file mode 100644 index 0000000000000000000000000000000000000000..52e25e470cf53ec35fc5e428086c042865b71a79 --- /dev/null +++ b/website/docs/extras/en/device-dev/driver/driver-peripherals-light-des.md @@ -0,0 +1,404 @@ +--- +title: "driver-peripherals-light-des" +prepermalink: /extras/8b1b6f90ab8193d6b62a67745f46ad0f/ +permalink: /extras/8b1b6f90ab8193d6b62a67745f46ad0f/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/driver/driver-peripherals-light-des.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [driver-peripherals-light-des] +--- +# Light + + +## Overview + +### Light + +The light driver model provides APIs for the upper-layer light hardware service layer to control lights, including obtaining the light type, setting the lighting mode and blinking effect, and turning on or off a light. This model implements functionalities such as cross-OS migration and differentiated configurations based on the Hardware Driver Foundation (HDF) to achieve the goal of "one-time development for cross-system deployment" of the light driver. The figure below shows the light driver model. + +**Figure 1** Light driver model + +![Light driver model](../../../../images/en/device-dev/driver/figures/388a98b602ce37bc4acbeaa8440232e0.png) + +### Working Principles + +The figure below shows how the light driver works. + +**Figure 2** How light driver works + +![How light driver works](../../../../images/en/device-dev/driver/figures/8e903d2444475adf1c3b4b4c847f8255.png) + +The following uses the Hi3516D V300 development board powered by the standard system as an example to describe how the light driver works. + +1. The light driver reads the light device management configuration from **Light Host** in the **device_info.hcs** file. +2. The light driver reads the light data configuration from the **light_config.hcs** file. +3. The light driver parses information about the light device management configuration and associates with the corresponding device driver. +4. The light proxy delivers an instruction to the light stub. +5. The light stub delivers an instruction to the light controller. +6. The light abstract driver interface is started. + +## Development Guidelines + +### When to Use + +Light control is widely used in daily life. For example, a light is blinking when a mobile phone receives an SMS message or has low battery level, and a light changes its colors based on the device charging status. These actions are implemented by calling the APIs provided by the light driver model. + +### Available APIs + +The light driver model provides APIs to obtain information about all the lights in the system and dynamically set the blinking mode and duration. The light hardware service calls the **GetLightInfo** method to obtain basic information about the light and calls the **TurnOnLight** method to make the light blinking. The table below describes the APIs of the light driver model. + +**Table 1** APIs of the light driver model + +| API | Description | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| int32_t (*GetLightInfo)(struct LightInfo **lightInfo, uint32_t *count) | Obtains information about all lights in the system. **lightInfo** indicates the double pointer to the basic light information. **count** indicates the pointer to the number of lights.| +| int32_t (*TurnOnLight)(uint32_t type, struct LightEffect *effect) | Turns on available lights in the list based on the specified light type. **type** indicates the light type, and **effect** indicates the pointer to the blinking effect.| +| int32_t (*TurnOffLight)(uint32_t type) | Turns off available lights in the light list based on the specified light type. **type** indicates the light type. | + +### How to Develop +1. Based on the HDF and the driver entry, complete the light abstract driver development (using the **Bind**, **Init**, **Release**, and **Dispatch** functions), resource configuration, and HCS parsing. Configure the light driver device information. + + - Call **HDF_INIT** to register the driver entry with the HDF. Generally, the HDF calls the **Bind** function and then the **Init** function to load the driver. If **Init** fails to be called, the HDF calls **Release** to release driver resources and exit. + The light driver model uses HDF configuration source (HCS). For details about HCS fields, see [Configuration Management](https://gitee.com/openharmony/docs/blob/master/en/device-dev/driver/driver-hdf-manage.md). + The light driver entry is defined as follows: + + ```c + /* Register the light entry data structure object. */ + struct HdfDriverEntry g_lightDriverEntry = { + .moduleVersion = 1, // Light module version. + .moduleName = "HDF_LIGHT", // Light module name, which must be the same as the value of moduleName in the device_info.hcs file. + .Bind = BindLightDriver, // BInd the light driver. + .Init = InitLightDriver, // Initialize the light driver. + .Release = ReleaseLightDriver, // Release the light resources. + }; + /* Call HDF_INIT to register the driver entry with the HDF. The HDF calls the Bind function and then the Init function to load a driver. If Init fails to be called, the HDF calls Release to release driver resources and exit. */ + HDF_INIT(g_lightDriverEntry); + ``` + + - Develop the light abstract driver. Specifically, implement the **Bind**, **Init**, **Release**, and **Dispatch** functions. + + ```c + /* Dispatch the light driver. */ + static int32_t DispatchLight(struct HdfDeviceIoClient *client, + int32_t cmd, struct HdfSBuf *data, struct HdfSBuf *reply) + { + ..... + if (cmd == LIGHT_IO_CMD_GET_INFO_LIST) { + CHECK_LIGHT_NULL_PTR_RETURN_VALUE(reply, HDF_ERR_INVALID_PARAM); + return GetAllLightInfo(data, reply); + } + + CHECK_LIGHT_NULL_PTR_RETURN_VALUE(data, HDF_ERR_INVALID_PARAM); + (void)OsalMutexLock(&drvData->mutex); + if (!HdfSbufReadInt32(data, &lightType)) { + HDF_LOGE("%s: sbuf read lightType failed", __func__); + (void)OsalMutexUnlock(&drvData->mutex); + return HDF_ERR_INVALID_PARAM; + } + ..... + ret = DispatchCmdHandle(lightType, data, reply); + (void)OsalMutexUnlock(&drvData->mutex); + return ret; + } + + /* Bind the external service provided by the light driver to the HDF. */ + int32_t BindLightDriver(struct HdfDeviceObject *device) + { + struct LightDriverData *drvData = NULL; + + CHECK_LIGHT_NULL_PTR_RETURN_VALUE(device, HDF_FAILURE); + /* Allocate resources for private interfaces. */ + drvData = (struct LightDriverData *)OsalMemCalloc(sizeof(*drvData)); + CHECK_LIGHT_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_MALLOC_FAIL); + /* Functions to be dispatched. */ + drvData->ioService.Dispatch = DispatchLight; + drvData->device = device; + device->service = &drvData->ioService; + g_lightDrvData = drvData; + return HDF_SUCCESS; + } + + /* Initialize the light driver. */ + int32_t InitLightDriver(struct HdfDeviceObject *device) + { + ..... + /* Initialize the workqueue. */ + if (HdfWorkQueueInit(&drvData->workQueue, LIGHT_WORK_QUEUE_NAME) != HDF_SUCCESS) { + HDF_LOGE("%s: init workQueue fail!", __func__); + return HDF_FAILURE; + } + /* Initialize work items. */ + if (HdfWorkInit(&drvData->work, LightWorkEntry, (void*)drvData) != HDF_SUCCESS) { + HDF_LOGE("%s: init workQueue fail!", __func__); + return HDF_FAILURE; + } + /* Parse the HCS. */ + if (GetLightConfigData(device->property) != HDF_SUCCESS) { + HDF_LOGE("%s: get light config fail!", __func__); + return HDF_FAILURE; + } + + return HDF_SUCCESS; + } + + /* Release the resources allocated for driver initialization. */ + void ReleaseLightDriver(struct HdfDeviceObject *device) + { + ..... + /* Release the allocated resources. */ + for (i = LIGHT_TYPE_NONE; i < LIGHT_TYPE_BUTT; ++i) { + + if (drvData->info[i] != NULL) { + OsalMemFree(drvData->info[i]); + drvData->info[i] = NULL; + } + } + /* Destroy workqueue resources. */ + HdfWorkDestroy(&drvData->work); + HdfWorkQueueDestroy(&drvData->workQueue); + (void)OsalMutexDestroy(&drvData->mutex); + (void)OsalMemFree(drvData); + g_lightDrvData = NULL; + } + ``` + + - The light device management module dispatches light device APIs in the system. During the system startup process, the HDF loads the device management driver from the HCS of the light host. + + ``` + /* Light device HCS */ + device_light :: device { + device0 :: deviceNode { + policy = 2; // Driver service dispatch policy (0: no service is dispatched; 1: services are dispatched to the kernel mode; 2: services are dispatched to both the kernel mode and user mode) + priority = 100; // Light driver startup priority. The value ranges from 0 to 200. A larger value indicates a lower priority. The value 100 is recommended. If the priorities are the same, the device loading sequence cannot be ensured. + preload = 0; // Field for specifying whether to load the driver. The value 0 means to load the driver, and 2 means the opposite. + permission = 0664; // Permission for the driver to create a device node. + moduleName = "HDF_LIGHT"; // Light driver name. The value of this field must be the same as that of moduleName in the HdfDriverEntry structure. + serviceName = "hdf_light"; // Service name of the driver, which must be unique. + deviceMatchAttr = "hdf_light_driver"; // Keyword for matching the private data of the driver. The value must be the same as that of match_attr in the private data configuration table of the driver. + } + ``` + +2. Parse the device attribute information and registers, and register them with the light device management module. + + ```c + /* Allocate resources and parse the HCS. */ + static int32_t ParseLightInfo(const struct DeviceResourceNode *node) + { + ..... + /* Obtain the number of supported light types from the HCS. */ + drvData->lightNum = parser->GetElemNum(light, "lightType"); + .... + for (i = 0; i < drvData->lightNum; ++i) { + /* Obtains the light type information. */ + ret = parser->GetUint32ArrayElem(light, "lightType", i, &temp, 0); + CHECK_LIGHT_PARSER_RESULT_RETURN_VALUE(ret, "lightType"); + } + + for (i = 0; i < drvData->lightNum; ++i) { + ..... + /* Types are used as subscripts to create space. */ + drvData->info[temp] = (struct LightDeviceInfo *)OsalMemCalloc(sizeof(struct LightDeviceInfo)); + ..... + /* Fill in the light device information. */ + ret = parser->GetUint32(light, "busRNum", &drvData->info[temp]->busRNum, 0); + CHECK_LIGHT_PARSER_RESULT_RETURN_VALUE(ret, "busRNum"); + ret = parser->GetUint32(light, "busGNum", &drvData->info[temp]->busGNum, 0); + CHECK_LIGHT_PARSER_RESULT_RETURN_VALUE(ret, "busGNum"); + ret = parser->GetUint32(light, "busBNum", &drvData->info[temp]->busBNum, 0); + CHECK_LIGHT_PARSER_RESULT_RETURN_VALUE(ret, "busBNum"); + ..... + return HDF_SUCCESS; + } + ``` + +3. Call related APIs to obtain the light type, turn on and off lights, and create and delete the timer based on the blinking mode. + + ```c + /* Call GetAllLightInfo to obtain the light type. Call Enable to enable the blinking mode. + Call Disable to stop blinking. */ + static int32_t GetAllLightInfo(struct HdfSBuf *data, struct HdfSBuf *reply) + { + ..... + /* Obtain the number of light types. */ + if (!HdfSbufWriteUint32(reply, drvData->lightNum)) { + HDF_LOGE("%s: write sbuf failed", __func__); + return HDF_FAILURE; + } + for (i = 0; i < LIGHT_TYPE_BUTT; ++i) { + if (drvData->info[i] == NULL) { + continue; + } + lightInfo.lightType = i; + lightInfo.reserved = NULL; + /* Fill the light device information into the reply. */ + if (!HdfSbufWriteBuffer(reply, &lightInfo, sizeof(lightInfo))) { + HDF_LOGE("%s: write sbuf failed", __func__); + return HDF_FAILURE; + } + } + + return HDF_SUCCESS; + } + + /* Enable lights based on the specified light type and input parameters. */ + static int32_t Enable(uint32_t lightType, struct HdfSBuf *data, struct HdfSBuf *reply) + { + ..... + /* Set the light color based on the brightness value passed in. Red: bits 16–31; Green: bits 8–15; Blue: bits 0–7 */ + if ((drvData->info[lightType]->lightBrightness & LIGHT_MAKE_R_BIT) != 0) { + drvData->info[lightType]->busNum = drvData->info[lightType]->busRNum; + } else if ((drvData->info[lightType]->lightBrightness & LIGHT_MAKE_G_BIT) != 0) { + drvData->info[lightType]->busNum = drvData->info[lightType]->busGNum; + } else if ((drvData->info[lightType]->lightBrightness & LIGHT_MAKE_B_BIT) != 0) { + drvData->info[lightType]->busNum = drvData->info[lightType]->busBNum; + } + /* The light is steady on. */ + if (buf->flashEffect.flashMode == LIGHT_FLASH_NONE) { + + if (GpioWrite(drvData->info[lightType]->busNum, GPIO_VAL_HIGH) != HDF_SUCCESS) { + return HDF_FAILURE; + } + } + /* The light is blinking. */ + if (buf->flashEffect.flashMode == LIGHT_FLASH_TIMED) { + drvData->info[lightType]->lightState = LIGHT_STATE_START; + /* If the specified blinking duration is less than the minimum time period supported by the system, the time configured by the system (in HCS) is used. */ + drvData->info[lightType]->onTime = buf->flashEffect.onTime < drvData->info[lightType]->onTime ? + drvData->info[lightType]->onTime : buf->flashEffect.onTime; + drvData->info[lightType]->offTime = buf->flashEffect.offTime < drvData->info[lightType]->offTime ? + drvData->info[lightType]->offTime : buf->flashEffect.offTime; + /* Create a timer. */ + if (OsalTimerCreate(&drvData->timer, drvData->info[lightType]->onTime, + LightTimerEntry, (uintptr_t)lightType) != HDF_SUCCESS) { + HDF_LOGE("%s: create light timer fail!", __func__); + return HDF_FAILURE; + } + /* Start the periodic timer. */ + if (OsalTimerStartLoop(&drvData->timer) != HDF_SUCCESS) { + HDF_LOGE("%s: start light timer fail!", __func__); + return HDF_FAILURE; + } + } + return HDF_SUCCESS; + } + + /* Turn off lights based on the specified light type. */ + static int32_t Disable(uint32_t lightType, struct HdfSBuf *data, struct HdfSBuf *reply) + { + /* Delete the timer. */ + if (drvData->timer.realTimer != NULL) { + + if (OsalTimerDelete(&drvData->timer) != HDF_SUCCESS) { + HDF_LOGE("%s: delete haptic timer fail!", __func__); + } + } + /* Power off the corresponding GPIO. */ + if (GpioWrite(drvData->info[lightType]->busRNum, GPIO_VAL_LOW) != HDF_SUCCESS){ + HDF_LOGE("%s: gpio write failed", __func__); + return HDF_FAILURE; + } + + return HDF_SUCCESS; + } + ``` + +### Verification + +After the driver is developed, develop auto-test cases in the light unit test to verify the basic functionalities of the driver. Use the developer self-test platform as the test environment. + +```c++ +/* Initialize the light interface instance before executing the test case. */ +void HdfLightTest::SetUpTestCase() +{ + g_lightDev = NewLightInterfaceInstance(); + if (g_lightDev == nullptr) { + printf("test light get Module instance failed\n\r"); + } + int32_t ret = g_lightDev->GetLightInfo(&g_lightInfo, &g_count); + if (ret == -1) { + printf("get light informations failed\n\r"); + } +} + +/* After the test case is executed, release the resources used by the test case. */ +void HdfLightTest::TearDownTestCase() +{ + if(g_lightDev != nullptr){ + FreeLightInterfaceInstance(); + g_lightDev = nullptr; + } +} + +/* Obtain the light type. */ +HWTEST_F(HdfLightTest, GetLightList001, TestSize.Level1) +{ + struct LightInfo *info = nullptr; + + if (g_lightInfo == nullptr) { + EXPECT_NE(nullptr, g_lightInfo); + return; + } + + printf("get light list num[%d]\n\r", g_count); + info = g_lightInfo; + + for (int i = 0; i < g_count; ++i) { + printf("get lightId[%d]\n\r", info->lightType); + EXPECT_GE(info->lightType, g_minLightType); + EXPECT_LE(info->lightType, g_maxLightType); + info++; + } +} + +/* Verify the steady on state of the light. */ +HWTEST_F(HdfLightTest, EnableLight001, TestSize.Level1) +{ + int32_t i; + int32_t ret; + struct LightEffect effect; + effect->lightBrightness = 0x80000000; + effect->flashEffect.flashMode = LIGHT_FLASH_NONE; + effect->flashEffect.onTime = 0; + effect->flashEffect.offTime = 0; + + for (i = 0; i < g_count; ++i) { + + ret = g_lightDev->TurnOnLight(g_lightInfo[i]->lightType, effect); + EXPECT_EQ(0, ret); + + OsalSleep(LIGHT_WAIT_TIME); + + ret = g_lightDev->TurnOffLight(type); + EXPECT_EQ(0, ret); + } +} + +/* Verify the blinking mode of the light. */ +HWTEST_F(HdfLightTest, EnableLight002, TestSize.Level1) +{ + int32_t i; + int32_t ret; + struct LightEffect effect; + effect->lightBrightness = 0x80000000; + effect->flashEffect.flashMode = LIGHT_FLASH_TIMED; + effect->flashEffect.onTime = g_onTime; + effect->flashEffect.offTime = g_offTime; + + for (i = 0; i < g_count; ++i) { + + ret = g_lightDev->TurnOnLight(g_lightInfo[i]->lightType, effect); + EXPECT_EQ(0, ret); + + OsalSleep(LIGHT_WAIT_TIME); + + ret = g_lightDev->TurnOffLight(type); + EXPECT_EQ(0, ret); + } +} +``` diff --git a/website/docs/extras/en/device-dev/driver/driver-peripherals-vibrator-des.md b/website/docs/extras/en/device-dev/driver/driver-peripherals-vibrator-des.md new file mode 100644 index 0000000000000000000000000000000000000000..988f8d97942ba9fc58ed08e4fb7e18dafbe7c878 --- /dev/null +++ b/website/docs/extras/en/device-dev/driver/driver-peripherals-vibrator-des.md @@ -0,0 +1,383 @@ +--- +title: "driver-peripherals-vibrator-des" +prepermalink: /extras/fcf34e91ab7dad52627656099390bd41/ +permalink: /extras/fcf34e91ab7dad52627656099390bd41/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/driver/driver-peripherals-vibrator-des.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [driver-peripherals-vibrator-des] +--- +# Vibrator + +## Overview + +### Introduction + +Developed on the Hardware Driver Foundation (HDF), the vibrator driver model makes vibrator driver development easier. This model masks the interaction between the device driver and system, provides unified and stable driver interfaces for the hardware service layer, and offers open interfaces and interface parsing capabilities for driver developers. This document provides guidance for developing vibrator drivers and deploying vibrators in different OSs. The figure below shows the vibrator driver model. + +**Figure 1** Vibrator driver model + +![Vibrator driver model](../../../../images/en/device-dev/driver/figures/7dd30ec8a411ee05560630e6446572fd.png) + +### Basic Concepts + +The system controls device vibration by invoking the vibrator. There are two vibration modes: + +- One-shot vibration + + The vibrator vibrates for a specified duration. + +- Periodic vibration + + The vibrator vibrates with a preset effect. For example, if the preset effect is "haptic.clock.timer" = [600, 600, 200, 600], the vibrator waits for 600 ms, vibrates for 600 ms, waits for 200 ms, and vibrates for 600 ms. + +### Working Principles + +Based on the loading and running process (shown below) of the vibrator driver model, the relationships between key modules in the model and associated modules are clearly defined. + +**Figure 2** How vibrator driver works + +![How vibrator driver works](../../../../images/en/device-dev/driver/figures/180f4f68803a397c8dbc381311db0f2f.png) + +The following uses the vibrator driver on the Hi3516D V300 development board of the standard system as an example to describe the driver loading and running process. + +1. The vibrator host reads the vibrator management configuration from the Vibrator Host node of the device_info HCS (vibrator device information HCS). +2. The vibrator host parses the vibrator management configuration and associates it with the corresponding vibrator abstract driver. +3. The vibrator host reads the vibrator data configuration from the linear_vibrator_config HCS (vibrator private configuration HCS). +4. The vibrator host parses the vibrator data configuration and associates it with the corresponding vibrator haptic driver. +5. The vibrator proxy delivers an instruction to the vibrator stub. +6. The vibrator stub calls the vibrator controller. +7. The vibrator host initializes the vibrator abstract driver interfaces. +8. The vibrator haptic driver starts a thread to parse the vibrator haptic module. +9. The vibrator haptic driver calls the **Start** interface in the vibrator abstract driver. +10. The vibrator abstract driver calls the **Start** interface in the vibrator chipset driver. + +## Development Guidelines + +### When to Use + +You can set different vibration effects as needed, for example, customizing vibration effects with different intensities and durations for buttons on the device, and customizing one-shot or periodic vibration effects with different intensities and durations for alarm clocks and incoming calls. + +### Available APIs + +The vibrator driver model supports static HDF Configuration Source (HCS) configurations and dynamic parameter configurations. The vibrator hardware service calls the **StartOnce** interface to trigger continuous vibration and calls the **Start** interface to trigger vibration with a specified effect. The table below lists the APIs provided by the vibrator driver model for the hardware service layer. + +**Table 1** External APIs of the vibrator driver model + +| API | Description | +| -------------------------------------- | -------------------------------------------------------- | +| int32_t StartOnce(uint32_t duration) | Triggers vibration with a given **duration**. | +| int32_t Start(const char *effectType) | Triggers vibration with a given effect, which is specified by **effectType**.| +| int32_t Stop(enum VibratorMode mode) | Stops vibration. | + +### How to Develop + +The vibrator driver model provides stable interfaces for the upper-layer hardware service to trigger a one-shot vibration with a given duration, trigger vibration with a given effect, and stop vibration. The model implements functionalities such as cross-OS migration and differentiated configurations. To develop a vibrator, perform the following steps: + +1. Develop the vibrator abstract driver based on the driver entry. Specifically, implement the **Bind**, **Init**, **Release**, and **Dispatch** functions, configure resources, and parse HCS configurations. + + - Call **HDF_INIT** to register the driver entry with the HDF. During driver loading, the HDF calls the **Bind** function and then the **Init** function to load the driver. If the **Init** function fails to be called, the HDF calls **Release** to release the driver resources and exit the vibrator driver model. The vibrator driver model uses the HCS as the configuration source code. For details about HCS fields, see [Driver Configuration Management](https://gitee.com/openharmony/docs/blob/master/en/device-dev/driver/driver-hdf-manage.md). The driver entry function is defined as follows: + + ```c + /* Register the entry structure object of the vibrator abstract driver. */ + struct HdfDriverEntry g_vibratorDriverEntry = { + .moduleVersion = 1, // Version of the vibrator module. + .moduleName = "HDF_VIBRATOR", // Vibrator module name. The value must be the same as the value of moduleName in the device_info.hcs file. + .Bind = BindVibratorDriver, // Function for binding a vibrator. + .Init = InitVibratorDriver, // Function for initializing a vibrator. + .Release = ReleaseVibratorDriver, // Function for releasing vibrator resources. + }; + + HDF_INIT(g_vibratorDriverEntry); + ``` + + - Develop the vibrator abstract driver. Specifically, implement the **Bind**, **Init**, **Release**, and **Dispatch** functions. + + ```c + /* External service published by the vibrator driver. */ + static int32_t DispatchVibrator(struct HdfDeviceIoClient *client, + int32_t cmd, struct HdfSBuf *data, struct HdfSBuf *reply) + { + int32_t loop; + + for (loop = 0; loop < sizeof(g_vibratorCmdHandle) / sizeof(g_vibratorCmdHandle[0]); ++loop) { + if ((cmd == g_vibratorCmdHandle[loop].cmd) && (g_vibratorCmdHandle[loop].func != NULL)) { + return g_vibratorCmdHandle[loop].func(data, reply); + } + } + + return HDF_SUCCESS; + } + + /* Bind the external service provided by the vibrator driver to the HDF. */ + int32_t BindVibratorDriver(struct HdfDeviceObject *device) + { + struct VibratorDriverData *drvData = NULL; + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(device, HDF_FAILURE); + + drvData = (struct VibratorDriverData *)OsalMemCalloc(sizeof(*drvData)); + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_MALLOC_FAIL); + + drvData->ioService.Dispatch = DispatchVibrator; + drvData->device = device; + device->service = &drvData->ioService; + g_vibratorDrvData = drvData; + + return HDF_SUCCESS; + } + + /* Entry function for vibrator driver initialization. */ + int32_t InitVibratorDriver(struct HdfDeviceObject *device) + { + struct VibratorDriverData *drvData = NULL; + + drvData->mode = VIBRATOR_MODE_BUTT; + drvData->state = VIBRATOR_STATE_IDLE; + ...... + if (CreateVibratorHaptic(device) != HDF_SUCCESS) { + HDF_LOGE("%s: init workQueue fail!", __func__); + return HDF_FAILURE; + } + + return HDF_SUCCESS; + } + + /* Release the resources allocated during vibrator driver initialization. */ + void ReleaseVibratorDriver(struct HdfDeviceObject *device) + { + struct VibratorDriverData *drvData = NULL; + ...... + (void)DestroyVibratorHaptic(); + (void)OsalMutexDestroy(&drvData->mutex); + (void)OsalMemFree(drvData); + g_vibratorDrvData = NULL; + } + ``` + + - During system startup, the HDF configuration management loads the vibrator abstract driver based on the device information HCS and publishes the vibrator driver interfaces. + + ```c + /* Device information HCS. */ + vibrator :: host { + hostName = "vibrator_host"; + device_vibrator :: device { + device0 :: deviceNode { + policy = 2; // Policy for publishing the driver service. + priority = 100; // Driver startup priority (0–200). A larger value indicates a lower priority. The default value 100 is recommended. The sequence for loading devices with the same priority is random. + preload = 0; // Field for specifying whether to load the driver. The value 0 means to load the driver, and 2 means the opposite. + permission = 0664; // Permission for the driver to create a device node. + moduleName = "HDF_VIBRATOR"; // Driver name. The value must be the same as that of moduleName in the driver entry structure. + serviceName = "hdf_misc_vibrator"; // Name of the service provided by the driver. The name must be unique. + deviceMatchAttr = "hdf_vibrator_driver"; // Keyword matching the private data of the driver. The value must be the same as that of match_attr in the private data configuration table of the driver. + } + } + ``` + +2. Create a vibrator haptic model and parse the haptic HCS configuration. + + - Create a vibrator haptic model. + + ```hcs + /* Create a vibrator haptic model, allocate resources, and parse the haptic HCS configuration. */ + int32_t CreateVibratorHaptic(struct HdfDeviceObject *device) + { + struct VibratorHapticData *hapticData = NULL; + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(device, HDF_FAILURE); + + hapticData = (struct VibratorHapticData *)OsalMemCalloc(sizeof(*hapticData)); + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(hapticData, HDF_ERR_MALLOC_FAIL); + g_vibratorHapticData = hapticData; + hapticData->supportHaptic = false; + + if (OsalMutexInit(&hapticData->mutex) != HDF_SUCCESS) { + HDF_LOGE("%s: fail to init mutex", __func__); + goto EXIT; + } + + DListHeadInit(&hapticData->effectSeqHead); + + /* Parse the haptic HCS configuration. */ + if (ParserVibratorHapticConfig(device->property) != HDF_SUCCESS) { + HDF_LOGE("%s: parser haptic config fail!", __func__); + goto EXIT; + } + + return HDF_SUCCESS; + EXIT: + OsalMemFree(hapticData); + return HDF_FAILURE; + } + ``` + + - The vibrator effect model uses the HCS. For details about HCS fields, see [Driver Configuration Management](https://gitee.com/openharmony/docs/blob/master/en/device-dev/driver/driver-hdf-manage.md). + + ``` + /* Vibrator data configuration template (vibrator_config.hcs). */ + root { + vibratorConfig { + boardConfig { + match_attr = "hdf_vibrator_driver"; // The value must be the same as that of the match_attr field configured for the vibrator. + vibratorAttr { + /* The value 0 means a rotor vibrator, and 1 means a linear vibrator. */ + deviceType = 1; // Device type. + supportPreset = 1; // Supported preset type. + } + vibratorHapticConfig { + haptic_clock_timer { + effectName = "haptic.clock.timer"; + type = 1; // The value 0 means the built-in mode, and 1 means the time sequence. + seq = [600, 600, 200, 600]; // Time sequence. + } + haptic_default_effect { + effectName = "haptic.default.effect"; + type = 0; + seq = [0, 3, 800, 1]; + } + } + } + } + } + ``` + +3. Develop the interfaces for starting and stopping vibration. A timer will be created and destroyed based on the vibration effect. + + The vibrator hardware service calls **StartOnce** to start one-shot vibration with a given duration and calls **StartEffect** to start vibration with a specified effect. + + ```c + /* Trigger vibration with a given duration. */ + static int32_t StartOnce(struct HdfSBuf *data, struct HdfSBuf *reply) + { + uint32_t duration; + int32_t ret; + struct VibratorEffectCfg config; + struct VibratorDriverData *drvData = GetVibratorDrvData(); + (void)reply; + ...... + config.cfgMode = VIBRATOR_MODE_ONCE; + config.duration = duration; + config.effect = NULL; + /* Create a timer based on the vibration effect. */ + ret = StartHaptic(&config); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: start haptic fail!", __func__); + return ret; + } + + return HDF_SUCCESS; + } + + /* Trigger vibration with a given effect. */ + static int32_t StartEffect(struct HdfSBuf *data, struct HdfSBuf *reply) + { + int32_t ret; + const char *effect = NULL; + struct VibratorEffectCfg config; + struct VibratorDriverData *drvData = GetVibratorDrvData(); + (void)reply; + ...... + config.cfgMode = VIBRATOR_MODE_PRESET; + config.duration = 0; + config.effect = effect; + + ret = StartHaptic(&config); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: start haptic fail!", __func__); + return ret; + } + + return HDF_SUCCESS; + } + + /* Stop vibration based on the specified vibration mode. */ + static int32_t Stop(struct HdfSBuf *data, struct HdfSBuf *reply) + { + int32_t ret; + int32_t mode; + struct VibratorDriverData *drvData = GetVibratorDrvData(); + (void)reply; + ...... + /* Stop vibration and destroy the timer. */ + ret = StopHaptic(); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: stop haptic fail!", __func__); + return ret; + } + + (void)OsalMutexLock(&drvData->mutex); + drvData->mode = VIBRATOR_MODE_BUTT; + (void)OsalMutexUnlock(&drvData->mutex); + + return HDF_SUCCESS; + } + ``` + +4. Implement the interfaces for the vibrator chipset driver. + + - Register the vibrator chipset driver interfaces when the vibrator chipset driver is initialized successfully. + + ```c + /* Register the vibrator chipset driver interfaces. */ + int32_t RegisterVibrator(struct VibratorOps *ops) + { + struct VibratorDriverData *drvData = GetVibratorDrvData(); + + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(ops, HDF_FAILURE); + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(drvData, HDF_FAILURE); + + (void)OsalMutexLock(&drvData->mutex); + drvData->ops.Start = ops->Start; + drvData->ops.StartEffect = ops->StartEffect; + drvData->ops.Stop = ops->Stop; + (void)OsalMutexUnlock(&drvData->mutex); + + return HDF_SUCCESS; + } + ``` + + - The vibrator driver model provides vibrator chipset driver interfaces. Implement these interfaces as follows: + + ```c + /* Start a linear vibrator to vibrate with a given duration. */ + static int32_t StartLinearVibrator() + { + int32_t ret; + struct VibratorLinearDriverData *drvData = GetLinearVibratorData(); + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(drvData, HDF_FAILURE); + ...... + ret = GpioWrite(drvData->gpioNum, GPIO_VAL_LOW); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: pull gpio%d to %d level failed", __func__, drvData->gpioNum, GPIO_VAL_LOW); + return ret; + } + return HDF_SUCCESS; + } + + /* Start a linear vibration to vibrate with a given effect. */ + static int32_t StartEffectLinearVibrator(uint32_t effectType) + { + (void)effectType; + HDF_LOGE("%s: vibrator set build-in effect no support!", __func__); + return HDF_SUCCESS; + } + + /* Stop a linear vibration based on the specified vibration mode. */ + static int32_t StopLinearVibrator() + { + int32_t ret; + struct VibratorLinearDriverData *drvData = GetLinearVibratorData(); + CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(drvData, HDF_FAILURE); + ...... + ret = GpioWrite(drvData->gpioNum, GPIO_VAL_HIGH); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: pull gpio%d to %d level failed", __func__, drvData->gpioNum, GPIO_VAL_HIGH); + return ret; + } + return HDF_SUCCESS; + } + ``` diff --git a/website/docs/extras/en/device-dev/driver/driver-peripherals.md b/website/docs/extras/en/device-dev/driver/driver-peripherals.md new file mode 100644 index 0000000000000000000000000000000000000000..ac0d94fcabf83eb493f88d9bda5ee53ef2a97cbf --- /dev/null +++ b/website/docs/extras/en/device-dev/driver/driver-peripherals.md @@ -0,0 +1,31 @@ +--- +title: "driver-peripherals" +prepermalink: /extras/11ca76760a0ffd994b59a81dff37a91f/ +permalink: /extras/11ca76760a0ffd994b59a81dff37a91f/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/driver/driver-peripherals.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [driver-peripherals] +--- +# Peripheral Driver Usage + +- **[LCD](/pages/en/device/device/Subsystem%20Development/Driver/Peripheral%20Driver%20Usage/LCD)** + +- **[Touchscreen](/pages/en/device/device/Subsystem%20Development/Driver/Peripheral%20Driver%20Usage/Touchscreen)** + +- **[Sensor](/pages/en/device/device/Subsystem%20Development/Driver/Peripheral%20Driver%20Usage/Sensor)** + +- **[WLAN](/pages/en/device/device/Subsystem%20Development/Driver/Peripheral%20Driver%20Usage/WLAN)** + +- **[Audio](/pages/en/device/device/Subsystem%20Development/Driver/Peripheral%20Driver%20Usage/Audio)** + +- **[USB](/pages/en/device/device/Subsystem%20Development/Driver/Peripheral%20Driver%20Usage/USB)** + +- **[Camera](/pages/en/device/device/Subsystem%20Development/Driver/Peripheral%20Driver%20Usage/Camera)** + diff --git a/website/docs/extras/en/device-dev/driver/driver-platform-mipicsi-des.md b/website/docs/extras/en/device-dev/driver/driver-platform-mipicsi-des.md new file mode 100644 index 0000000000000000000000000000000000000000..4961e4d0b05607075d082c19a2f417f052dcd9cf --- /dev/null +++ b/website/docs/extras/en/device-dev/driver/driver-platform-mipicsi-des.md @@ -0,0 +1,685 @@ +--- +title: "driver-platform-mipicsi-des" +prepermalink: /extras/b3e48ac8c5f33df76f82989b158f6a71/ +permalink: /extras/b3e48ac8c5f33df76f82989b158f6a71/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/driver/driver-platform-mipicsi-des.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [driver-platform-mipicsi-des] +--- +# MIPI CSI + +## Overview + +Defined by the Mobile Industry Processor Interface (MIPI) Alliance, the Camera Serial Interface (CSI) is a specification that allows data to be transmitted from the camera to the host processor on mobile platforms. As the second release, the MIPI CSI-2 consists of the application layer, protocol layer, and physical layer. It supports a maximum of four-lane data transmission and a single-lane transmission rate of 1 Gbit/s. + +The physical layer supports the high speed (HS) and low power (LP) modes. Using low-voltage differential signaling (LVDS), the HS mode delivers 80 Mbit/s to 1 Gbit/s transmission speed but high power consumption. The unidirectional LP mode provides lower power consumption but lower transmission speed (< 10 Mbit/s). The blend of the two modes ensures high-speed transmission of massive data (such as images) and minimized power consumption when less data is transmitted. + +The figure below shows a simplified CSI. The D-PHY transmits data by using one pair of source-synchronized differential clocks and one to four pairs of differential data lanes. Data is transmitted in Double Data Rate (DDR) mode, that is, data is transmitted on both the rising and falling edges of the clock. + +**Figure 1** CSI TX and RX interfaces +![](../../../../images/en/device-dev/driver/figures/d939390afc1af20d08f2d4aa10cf8e05.png) + +### ComboDevAttr Structure + +**Table 1** ComboDevAttr structure + + + +| Name | Description | +| --------- | ----------------------------------------------------- | +| devno | Device number. | +| inputMode | Input mode, which can be MIPI, LVDS, sub-LVDS, HiSPI, or DC. | +| dataRate | Input rate of the MIPI RX scalable low voltage signaling (SLVS). | +| imgRect | Crop area of the MIPI RX device (same as the size of the input image of the sensor).| +| MIPIAttr | Attributes of the MIPI device. | +| lvdsAttr | Attributes of the LVDS, sub-LVDS, or HiSPi device. | + +### ExtDataType Structure + +**Table 2** ExtDataType structure + + + +| Name | Description | +| --------------- | ------------------------------- | +| devno | Device number. | +| num | Sensor number. | +| extDataBitWidth | Bit depth of an image. | +| extDataType | Pointer to the YUV, raw data format, and bit depth.| + +### Available APIs + +**Table 3** MIPI CSI APIs + + + + | Category| API| +| -------- | -------- | +| Opening or closing the MIPI CSI controller operation handle| **MipiCsiOpen**: opens the MIPI CSI controller operation handle.
**MipiCsiClose**: closes the MIPI CSI controller operation handle.| +| Setting MIPI CSI parameters| **MipiCsiSetComboDevAttr**: sets parameters of the MIPI, CMOS, or LVDS camera to the controller. The parameters include the working mode, image area, image depth, data rate, and physical channel.
**MipiCsiSetExtDataType** (optional): sets the YUV and RAW data formats and bit depths.
**MipiCsiSetHsMode**: sets the MIPI RX lane distribution. Set the mode based on the hardware connection.
**MipiCsiSetPhyCmvmode**: sets the common-mode voltage (CMV) mode.| +| Resetting a sensor or deasserting the reset of a sensor| **MipiCsiResetSensor**: resets a sensor.
**MipiCsiUnresetSensor**: deasserts the reset of a sensor.| +| Resetting the MIPI RX or deasserting the reset of the MIPI RX| **MipiCsiResetRx**: resets the MIPI&nbsp;RX. The value of **enSnsType** varies depending on the value of **s32WorkingViNum**.
**MipiCsiUnresetRx**: deasserts the reset on the MIPI&nbsp;RX.| +| Enabling or disabling the MIPI clock| **MipiCsiEnableClock**: enables the MIPI clock. The **enSnsType** passed by the upper-layer function during electrophoresis determines whether MIPI or LVDS is used.
**MipiCsiDisableClock**: disables the MIPI clock.| +| Enabling or disabling the MIPI sensor clock| **MipiCsiEnableSensorClock**: enables the MIPI sensor clock.
**MipiCsiDisableSensorClock**: disables the MIPI sensor clock.| + + +## Usage Guidelines + +### How to Use + +The figure below shows the process of using a MIPI CSI device. + +**Figure 2** MIPI CSI usage process + + +![](../../../../images/en/device-dev/driver/figures/80733ecf973b102c6c13e4ed347471cd.png) + +### Opening the MIPI CSI Controller Operation Handle + +Before starting MIPI CSI communication, call **MipiCsiOpen** to open the MIPI CSI device handle. This function returns the MIPI CSI device handle with the specified lane ID. + +```c +DevHandle MipiCsiOpen(uint8_t id); +``` + +**Table 4** Description of MipiCsiOpen + + + +| Parameter | Description | +| ---------- | ----------------------------------------------- | +| id | MIPI CSI lane ID. | +| **Return Value**| **Description** | +| NULL | The operation fails. | +| Device handle | MIPI CSI device handle with the specified lane ID. The data type is **DevHandle**.| + +For example, open the controller operation handle for MIPI CSI lane 0: + +```c +DevHandle mipiCsiHandle = NULL; /* Device handle */ +id = 0; /* MIPI CSI lane ID */ + +/* Open the controller operation handle. */ +MipiCsiHandle = MipiCsiOpen(id); +if (MipiCsiHandle == NULL) { + HDF_LOGE("MipiCsiOpen: failed\n"); + return; +} +``` + +### Setting MIPI CSI Parameters + +- Set MIPI CSI parameters. + + ```c + int32_t MipiCsiSetComboDevAttr(DevHandle handle, ComboDevAttr *pAttr); + ``` + + **Table 5** Description of MipiCsiSetComboDevAttr + + + + | Parameter | Description | + | ---------- | -------------------------- | + | handle | Controller operation handle. | + | pAttr | Pointer to the MIPI CSI structure.| + | **Return Value**| **Description** | + | 0 | The operation is successful. | + | Negative value | The operation fails. | + + ```c + int32_t ret; + struct ComboDevAttr attr; + + /* The current configuration is as follows: */ + (void)memset_s(&attr, sizeof(ComboDevAttr), 0, sizeof(ComboDevAttr)); + attr.devno = 0; /* Device 0 */ + attr.inputMode = INPUT_MODE_MIPI; /* The input mode is MIPI. */ + attr.dataRate = MIPI_DATA_RATE_X1; /* The data rate is 1 pixel per clock cycle. */ + attr.imgRect.x = 0; /* The value 0 indicates the upper left position of the image sensor. */ + attr.imgRect.y = 0; /* The value 0 indicates the upper right position of the image sensor. */ + attr.imgRect.width = 2592; /* The width of the image sensor is 2592. */ + attr.imgRect.height = 1944; /* The height of the image sensor is 1944. */ + /* Write the MIPI CSI configuration. */ + ret = MipiCsiSetComboDevAttr(MipiCsiHandle, &attr); + if (ret != 0) { + HDF_LOGE("%s: MipiCsiSetComboDevAttr fail! ret=%d\n", __func__, ret); + return -1; + } + ``` + +- Set the YUV, RAW data format, and bit depth. + + ```c + int32_t MipiCsiSetExtDataType(DevHandle handle, ExtDataType* dataType); + ``` + + **Table 6** Description of MipiCsiSetExtDataType + + + + | Parameter | Description | + | ---------- | ------------------------------- | + | handle | Controller operation handle. | + | dataType | Pointer to the YUV, raw data format, and bit depth.| + | **Return Value**| **Description** | + | 0 | The operation is successful. | + | Negative value | The operation fails. | + + ```c + int32_t ret; + struct ExtDataType dataType; + + /* Set the YUV, raw data format, and bit depth. */ + dataType.devno = 0; /* Device 0 */ + dataType.num = 0; /* sensor 0 */ + dataType.extDataBitWidth[0] = 12; /* Bit depth array element 0 */ + dataType.extDataBitWidth[1] = 12; /* Bit depth array element 1 */ + dataType.extDataBitWidth[2] = 12; /* Bit depth array element 2 */ + + dataType.extDataType[0] = 0x39; /* Define YUV, raw data format, and bit depth element 0. */ + dataType.extDataType[1] = 0x39; /* Define YUV, raw data format, and bit depth element 1. */ + dataType.extDataType[2] = 0x39; /* Define YUV, raw data format, and bit depth element 2. */ + /* Set the YUV, raw data format, and bit depth. */ + ret = MipiCsiSetExtDataType(MipiCsiHandle, &dataType); + if (ret != 0) { + HDF_LOGE("%s: MipiCsiSetExtDataType fail! ret=%d\n", __func__, ret); + return -1; + } + ``` + +- Set the MIPI RX lane distribution. + + ```c + int32_t MipiCsiSetHsMode(DevHandle handle, LaneDivideMode laneDivideMode); + ``` + + **Table 7** Description of MipiCsiSetHsMode + + + + | Parameter | Description | + | -------------- | -------------- | + | handle | Controller operation handle.| + | laneDivideMode | Lane mode. | + | **Return Value** | **Description**| + | 0 | The operation is successful. | + | Negative value | The operation fails. | + + ```c + int32_t ret; + enum LaneDivideMode mode; + + /* Set the lane mode to 0. */ + mode = LANE_DIVIDE_MODE_0; + /* Set the MIPI RX lane distribution. */ + ret = MipiCsiSetHsMode(MipiCsiHandle, mode); + if (ret != 0) { + HDF_LOGE("%s: MipiCsiSetHsMode fail! ret=%d\n", __func__, ret); + return -1; + } + ``` + +- Set the CMV mode. + + ```c + int32_t MipiCsiSetPhyCmvmode(DevHandle handle, uint8_t devno, PhyCmvMode cmvMode); + ``` + + **Table 8** Description of MipiCsiSetPhyCmvmode + + + + | Parameter | Description | + | ---------- | ---------------- | + | handle | Controller operation handle. | + | cmvMode | CMV mode.| + | devno | Device number. | + | **Return Value**| **Description** | + | 0 | The operation is successful. | + | Negative value | The operation fails. | + + ```c + int32_t ret; + enum PhyCmvMode mode; + uint8_t devno; + + /* Set the CMV mode to 0. */ + mode = PHY_CMV_GE1200MV; + /* The device number is 0. */ + devno = 0; + /* Set the CMV mode. */ + ret = MipiCsiSetPhyCmvmode(MipiCsiHandle, devno, mode); + if (ret != 0) { + HDF_LOGE("%s: MipiCsiSetPhyCmvmode fail! ret=%d\n", __func__, ret); + return -1; + } + ``` + +### Resetting a Sensor or Deasserting the Reset of a Sensor + +- Reset a sensor. + + ```c + int32_t MipiCsiResetSensor(DevHandle handle, uint8_t snsResetSource); + ``` + + **Table 9** Description of MipiCsiResetSensor + + + + | Parameter | Description | + | -------------- | ------------------------------------------------ | + | handle | Controller operation handle. | + | snsResetSource | Sensor's reset signal cable number, which is called reset source of the sensor in software.| + | **Return Value** | **Description** | + | 0 | The operation is successful. | + | Negative value | The operation fails. | + + ```c + int32_t ret; + uint8_t snsResetSource; + + /* The sensor's reset signal cable number is 0. */ + snsResetSource = 0; + /* Reset the sensor. */ + ret = MipiCsiResetSensor(MipiCsiHandle, snsResetSource); + if (ret != 0) { + HDF_LOGE("%s: MipiCsiResetSensor fail! ret=%d\n", __func__, ret); + return -1; + } + ``` + +- Deassert the reset of a sensor. + + ```c + int32_t MipiCsiUnresetSensor(DevHandle handle, uint8_t snsResetSource); + ``` + + **Table 10** Description of MipiCsiUnresetSensor + + + + | Parameter | Description | + | -------------- | ------------------------------------------------ | + | handle | Controller operation handle. | + | snsResetSource | Sensor's reset signal cable number, which is called reset source of the sensor in software.| + | **Return Value** | **Description** | + | 0 | The operation is successful. | + | Negative value | The operation fails. | + + ```c + int32_t ret; + uint8_t snsResetSource; + + /* The sensor's reset signal cable number is 0. */ + snsResetSource = 0; + /* Deassert the reset of the sensor. */ + ret = MipiCsiUnresetSensor(MipiCsiHandle, snsResetSource); + if (ret != 0) { + HDF_LOGE("%s: MipiCsiUnresetSensor fail! ret=%d\n", __func__, ret); + return -1; + } + ``` + +### Resetting the MIPI RX or Deasserting the Reset of the MIPI RX + +- Reset the MIPI RX. + + ```c + int32_t MipiCsiResetRx(DevHandle handle, uint8_t comboDev); + ``` + + **Table 11** Description of MipiCsiResetRx + + + + | Parameter | Description | + | ---------- | --------------------- | + | handle | Controller operation handle. | + | comboDev | MIPI RX or LVDS channel number.| + | **Return Value**| **Description** | + | 0 | The operation is successful. | + | Negative value | The operation fails. | + + ```c + int32_t ret; + uint8_t comboDev; + + /* The channel number is 0.*/ + comboDev = 0; + /* Reset the MIPI RX. */ + ret = MipiCsiResetRx(MipiCsiHandle, comboDev); + if (ret != 0) { + HDF_LOGE("%s: MipiCsiResetRx fail! ret=%d\n", __func__, ret); + return -1; + } + ``` + +- Deassert the reset of the MIPI RX. + + ```c + int32_t MipiCsiUnresetRx(DevHandle handle, uint8_t comboDev); + ``` + + **Table 12** Description of MipiCsiUnresetRx + + + + | Parameter | Description | + | ---------- | --------------------- | + | handle | Controller operation handle. | + | comboDev | MIPI RX or LVDS channel number.| + | **Return Value**| **Description** | + | 0 | The operation is successful. | + | Negative value | The operation fails. | + + ```c + int32_t ret; + uint8_t comboDev; + + /* The channel number is 0.*/ + comboDev = 0; + /* Deassert the reset of the MIPI RX. */ + ret = MipiCsiUnresetRx(MipiCsiHandle, comboDev); + if (ret != 0) { + HDF_LOGE("%s: MipiCsiUnresetRx fail! ret=%d\n", __func__, ret); + return -1; + } + ``` + +### Enabling or Disabling the MIPI Clock + +- Enable the MIPI clock. + + ```c + int32_t MipiCsiEnableClock(DevHandle handle, uint8_t comboDev); + ``` + + **Table 13** Description of MipiCsiEnableClock + + + + | Parameter | Description | + | ---------- | -------------- | + | handle | Controller operation handle.| + | comboDev | Channel number. | + | **Return Value**| **Description**| + | 0 | The operation is successful. | + | Negative value | The operation fails. | + + ```c + int32_t ret; + uint8_t comboDev; + + /* The channel number is 0.*/ + comboDev = 0; + /* Enable the MIPI clock. */ + ret = MipiCsiEnableClock(MipiCsiHandle, comboDev); + if (ret != 0) { + HDF_LOGE("%s: MipiCsiEnableClock fail! ret=%d\n", __func__, ret); + return -1; + } + ``` + +- Disable the MIPI clock. + + ```c + int32_t MipiCsiDisableClock(DevHandle handle, uint8_t comboDev); + ``` + + **Table 14** Description of MipiCsiDisableClock + + + + | Parameter | Description | + | ---------- | -------------- | + | handle | Controller operation handle.| + | comboDev | Channel number. | + | **Return Value**| **Description**| + | 0 | The operation is successful. | + | Negative value | The operation fails. | + + ```c + int32_t ret; + uint8_t comboDev; + + /* The channel number is 0.*/ + comboDev = 0; + /* Disable the MIPI clock. */ + ret = MipiCsiDisableClock(MipiCsiHandle, comboDev); + if (ret != 0) { + HDF_LOGE("%s: MipiCsiDisableClock fail! ret=%d\n", __func__, ret); + return -1; + } + ``` + +### Enabling or Disabling the MIPI Sensor Clock + +- Enable the MIPI sensor clock. + + ```c + int32_t MipiCsiEnableSensorClock(DevHandle handle, uint8_t snsClkSource); + ``` + + **Table 15** Description of MipiCsiEnableSensorClock + + + + | Parameter | Description | + | ------------ | ------------------------------------------------ | + | handle | Controller operation handle. | + | snsClkSource | Sensor's clock signal cable number, which is called clock source of the sensor in software.| + | **Return Value** | **Description** | + | 0 | The operation is successful. | + | Negative value | The operation fails. | + + ```c + int32_t ret; + uint8_t snsClkSource; + + /* The sensor's clock signal cable number is 0. */ + snsClkSource = 0; + /* Enable the MIPI sensor clock. */ + ret = MipiCsiEnableSensorClock(MipiCsiHandle, snsClkSource); + if (ret != 0) { + HDF_LOGE("%s: MipiCsiEnableSensorClock fail! ret=%d\n", __func__, ret); + return -1; + } + ``` + +- Disable the MIPI sensor clock. + + ```c + int32_t MipiCsiDisableSensorClock(DevHandle handle, uint8_t snsClkSource); + ``` + + **Table 16** Description of MipiCsiDisableSensorClock + + + + | Parameter | Description | + | ------------ | ------------------------------------------------ | + | handle | Controller operation handle. | + | snsClkSource | Sensor's clock signal cable number, which is called clock source of the sensor in software.| + | **Return Value** | **Description** | + | 0 | The operation is successful. | + | Negative value | The operation fails. | + + ```c + int32_t ret; + uint8_t snsClkSource; + + /* The sensor's clock signal cable number is 0. */ + snsClkSource = 0; + /* Disable the MIPI sensor clock. */ + ret = MipiCsiDisableSensorClock(MipiCsiHandle, snsClkSource); + if (ret != 0) { + HDF_LOGE("%s: MipiCsiDisableSensorClock fail! ret=%d\n", __func__, ret); + return -1; + } + ``` + +### Closing a MIPI CSI Controller Operation Handle + +After the MIPI CSI communication, close the MIPI CSI controller handle by calling the following function: + +```c +void MipiCsiClose(DevHandle handle); +``` + +This function releases the resources requested by **MipiCsiOpen**. + +**Table 17** Description of MipiCsiClose + + + + | Parameter | Description | + | ------------ | ------------------------------------------------ | + | handle | MIPI CSI controller operation handle. | + +```c +MipiCsiClose(MIPIHandle); /* Close the operation handle of the MIPI CSI controller. */ +``` + +## Development Example + +The sample code is as follows: + +```c +#include "hdf.h" +#include "MIPI_csi_if.h" + +void PalMipiCsiTestSample(void) +{ + uint8_t id; + int32_t ret; + uint8_t comboDev; + uint8_t snsClkSource; + uint8_t devno; + enum LaneDivideMode mode; + enum PhyCmvMode mode; + struct ComboDevAttr attr; + struct ExtDataType dataType; + DevHandle MipiCsiHandle = NULL; + + /* Controller ID */ + id = 0; + /* Open the controller operation handle. */ + MipiCsiHandle = MipiCsiOpen(id); + if (MipiCsiHandle == NULL) { + HDF_LOGE("MipiCsiOpen: failed!\n"); + return; + } + + /* Set the lane mode to 0. */ + mode = LANE_DIVIDE_MODE_0; + /* Set the MIPI RX lane distribution. */ + ret = MipiCsiSetHsMode(MipiCsiHandle, mode); + if (ret != 0) { + HDF_LOGE("%s: MipiCsiSetHsMode fail! ret=%d\n", __func__, ret); + return; + } + + /* The channel number is 0.*/ + comboDev = 0; + /* Enable the MIPI clock. */ + ret = MipiCsiEnableClock(MipiCsiHandle, comboDev); + if (ret != 0) { + HDF_LOGE("%s: MipiCsiEnableClock fail! ret=%d\n", __func__, ret); + return; + } + + /* Reset the MIPI RX. */ + ret = MipiCsiResetRx(MipiCsiHandle, comboDev); + if (ret != 0) { + HDF_LOGE("%s: MipiCsiResetRx fail! ret=%d\n", __func__, ret); + return; + } + + /* The sensor's clock signal cable number is 0. */ + snsClkSource = 0; + /* Enable the MIPI sensor clock. */ + ret = MipiCsiEnableSensorClock(MipiCsiHandle, snsClkSource); + if (ret != 0) { + HDF_LOGE("%s: MipiCsiEnableSensorClock fail! ret=%d\n", __func__, ret); + return; + } + + /* Reset the sensor. */ + ret = MipiCsiResetSensor(MipiCsiHandle, snsResetSource); + if (ret != 0) { + HDF_LOGE("%s: MipiCsiResetSensor fail! ret=%d\n", __func__, ret); + return; + } + + /* Set MIPI parameters. */ + (void)memset_s(&attr, sizeof(ComboDevAttr), 0, sizeof(ComboDevAttr)); + attr.devno = 0; /* Device 0 */ + attr.inputMode = INPUT_MODE_MIPI; /* The input mode is MIPI. */ + attr.dataRate = MIPI_DATA_RATE_X1; /* The data rate is 1 pixel per clock cycle. */ + attr.imgRect.x = 0; /* The value 0 indicates the upper left position of the image sensor. */ + attr.imgRect.y = 0; /* The value 0 indicates the upper right position of the image sensor. */ + attr.imgRect.width = 2592; /* The width of the image sensor is 2592. */ + attr.imgRect.height = 1944; /* The height of the image sensor is 1944. */ + /* Write the MIPI CSI configuration. */ + ret = MipiCsiSetComboDevAttr(MipiCsiHandle, &attr); + if (ret != 0) { + HDF_LOGE("%s: MipiCsiSetComboDevAttr fail! ret=%d\n", __func__, ret); + return; + } + + /* Set the CMV mode to 0. */ + mode = PHY_CMV_GE1200MV; + /* The device number is 0. */ + devno = 0; + /* Set the CMV mode. */ + ret = MipiCsiSetPhyCmvmode(MipiCsiHandle, devno, mode); + if (ret != 0) { + HDF_LOGE("%s: MipiCsiSetPhyCmvmode fail! ret=%d\n", __func__, ret); + return; + } + + /* The channel number is 0.*/ + comboDev = 0; + /* Deassert the reset of the MIPI RX. */ + ret = MipiCsiUnresetRx(MipiCsiHandle, comboDev); + if (ret != 0) { + HDF_LOGE("%s: MipiCsiUnresetRx fail! ret=%d\n", __func__, ret); + return; + } + + /* Disable the MIPI clock. */ + ret = MipiCsiDisableClock(MipiCsiHandle, comboDev); + if (ret != 0) { + HDF_LOGE("%s: MipiCsiDisableClock fail! ret=%d\n", __func__, ret); + return; + } + + /* The sensor's reset signal cable number is 0. */ + snsResetSource = 0; + /* Deassert the reset of the sensor. */ + ret = MipiCsiUnresetSensor(MipiCsiHandle, snsResetSource); + if (ret != 0) { + HDF_LOGE("%s: MipiCsiUnresetSensor fail! ret=%d\n", __func__, ret); + return; + } + + /* Disable the MIPI sensor clock. */ + ret = MipiCsiDisableSensorClock(MipiCsiHandle, snsClkSource); + if (ret != 0) { + HDF_LOGE("%s: MipiCsiDisableSensorClock fail! ret=%d\n", __func__, ret); + return; + } + + /* Close the MIPI CSI device handle. */ + MipiCsiClose(MipiCsiHandle); +} +``` diff --git a/website/docs/extras/en/device-dev/driver/driver-platform-pin-develop.md b/website/docs/extras/en/device-dev/driver/driver-platform-pin-develop.md new file mode 100644 index 0000000000000000000000000000000000000000..5077ee0476ee3d00dcc889f27565df04f44951e2 --- /dev/null +++ b/website/docs/extras/en/device-dev/driver/driver-platform-pin-develop.md @@ -0,0 +1,329 @@ +--- +title: "driver-platform-pin-develop" +prepermalink: /extras/868242fe4bd5c4273dc5eed7318ae654/ +permalink: /extras/868242fe4bd5c4273dc5eed7318ae654/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/driver/driver-platform-pin-develop.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [driver-platform-pin-develop] +--- +# Pin + + +## Overview + +The pin module controls the states and functionalities of system pins. In the Hardware Driver Foundation (HDF), the pin module uses the service-free mode for API adaptation. The service-free mode applies to devices that do not provide user-mode APIs or the OS system that does not distinguish the user mode and the kernel mode. In the service-free mode, DevHandle (a void pointer) directly points to the kernel-mode address of the device object. + +Figure 1 Service-free mode +![image1](../../../../images/en/device-dev/driver/figures/a9d62594b759a333e3f86bc10b145bf4.png "service-free-mode") + +## Available APIs + +**PinCntlrMethod**: + +```c +struct PinCntlrMethod { + int32_t (*SetPinPull)(struct PinCntlr *cntlr, uint32_t index, enum PinPullType pullType); + int32_t (*GetPinPull)(struct PinCntlr *cntlr, uint32_t index, enum PinPullType *pullType); + int32_t (*SetPinStrength)(struct PinCntlr *cntlr, uint32_t index, uint32_t strength); + int32_t (*GetPinStrength)(struct PinCntlr *cntlr, uint32_t index, uint32_t *strength); + int32_t (*SetPinFunc)(struct PinCntlr *cntlr, uint32_t index, const char *funcName); + int32_t (*GetPinFunc)(struct PinCntlr *cntlr, uint32_t index, const char **funcName); +}; +``` + +**Table 1** APIs for the members in the PinCntlrMethod structure + +| API | Input Parameter | Return Value| Description| +| ------------ | ------------------------------------------- | ------ | ---- | +| SetPinPull | **cntlr**: structure pointer to the pin controller at the core layer.
**index**: pin index, which is a uint32_t variable.
**pullType**: pull type of the pin. It is an enum constant.|HDF_STATUS|Sets the pull type of a pin.| +| GetPinPull | **cntlr**: structure pointer to the pin controller at the core layer.
**index**: pin index, which is a uint32_t variable.
**pullType**: pointer to the pull type of the pin.| HDF_STATUS| Obtains the pull type of a pin.| +| SetPinStrength | **cntlr**: structure pointer to the pin controller at the core layer.
**index**: pin index, which is a uint32_t variable.
**strength**: pull strength of the pin. It is a uint32_t variable.| HDF_STATUS| Sets the pull strength of a pin.| +| GetPinStrength | **cntlr**: structure pointer to the pin controller at the core layer.
**index**: pin index, which is a uint32_t variable.
**strength**: pointer to the pull strength of the pin.| HDF_STATUS| Obtains the pull strength of a pin.| +| SetPinFunc | **cntlr**: structure pointer to the pin controller at the core layer.
**index**: pin index, which is a uint32_t variable.
**funcName**: char pointer to the pin functionality.| HDF_STATUS| Sets the pin functionality.| +| GetPinFunc | **cntlr**: structure pointer to the pin controller at the core layer.
**index**: pin index, which is a uint32_t variable.
**funcName**: char double pointer to the pin functionality.| HDF_STATUS| Obtains the pin functionalities.| + +## How to Develop + +The pin module adaptation involves the following steps: + +1. Instantiate the driver entry. + + - Instantiate the **HdfDriverEntry** structure. + - Call **HDF_INIT** to register the **HdfDriverEntry** instance with the HDF. + +2. Configure attribute files. + + - Add the **deviceNode** information to the **device_info.hcs** file. + - (Optional) Add the **pin_config.hcs** file. + +3. Instantiate the pin controller object. + + - Initialize the **PinCntlr** object. + + - Instantiate **PinCntlrMethod** in the **PinCntlr** object. + + >![](../../../../images/en/device-dev/public_sys-resources/ae89e6a5f31e3d03603c1d114c8400cf.gif) **NOTE** + + >For details, see [Available APIs](#section2_PINDevelop). + +4. Debug the driver. + + - (Optional) Verify basic functionalities of new drivers. For example, verify the information returned when the driver is loaded and whether data is successfully transmitted. + +## Development Example + +The following uses **pin_hi35xx.c** as an example to present the content to be provided by the vendor to implement device functionalities. + +1. Instantiate the driver entry. The driver entry must be a global variable of the **HdfDriverEntry** type (defined in **hdf\_device\_desc.h**), and the value of **moduleName** must be the same as that in **device\_info.hcs**. In the HDF, the start address of each **HdfDriverEntry** object of all loaded drivers are collected to form a segment address space similar to an array for the upper layer to invoke. + + Generally, the HDF calls the **Bind** function and then the **Init** function to load the driver. If **Init** fails to be called, the HDF calls **Release** to release driver resources and exit. + + Pin driver entry reference: + + ```c + static struct HdfDriverEntry g_hi35xxPinDriverEntry = { + .moduleVersion = 1, + .Bind = Hi35xxPinBind, + .Init = Hi35xxPinInit, + .Release = Hi35xxPinRelease, + .moduleName = "hi35xx_pin_driver",// (Mandatory) The value must be the same as that of moduleName in the .hcs file. + }; + // Call HDF_INIT to register the driver entry with the HDF. + HDF_INIT(g_hi35xxPinDriverEntry); + ``` + +2. Add **deviceNode** to the **device\_info.hcs** file, and set the device attributes in the **pin\_config.hcs** file. The **deviceNode** information is related to registration of the driver entry. The device attribute values are closely related to the default values or value ranges of the **PinCntlr** members at the core layer. + + >![](../../../../images/en/device-dev/public_sys-resources/ae89e6a5f31e3d03603c1d114c8400cf.gif) **NOTE** + >If there are multiple devices, add the **deviceNode** information to the **device\_info** file and add the corresponding device attributes to the **pin\_config** file. + + - **device\_info.hcs** reference: + + ```c + root { + device_info { + platform :: host { + hostName = "platform_host"; + priority = 50; + device_pin :: device { + device0:: deviceNode { // Set an HDF device node for each pin controller. + policy = 0; // 2: visible in user mode; 1: visible in kernel mode; 0: no service required. + priority = 10; // Driver startup priority. + permission = 0644; // Permission to create device nodes for the driver. + /* (Mandatory) Driver name, which must be the same as the moduleName in the driver entry. */ + moduleName = "hi35xx_Pin_driver"; + /* (Mandatory) Set the controller private data, which must be same as that in Pin_config.hcs. */ + deviceMatchAttr = "hisilicon_hi35xx_Pin_0"; + } + device1 :: deviceNode { + policy = 0; + priority = 10; + permission = 0644; + moduleName = "hi35xx_Pin_driver"; + deviceMatchAttr = "hisilicon_hi35xx_Pin_1"; + } + ... + } + } + } + } + ``` + + - **Pin\_config.hcs** reference: + + ```c + root { + platform { + Pin_config_hi35xx { + template Pin_controller { // (Mandatory) Template configuration. In the template, you can configure the common parameters shared by device nodes. + number = 0; // (Mandatory) Controller ID. + regStartBasePhy = 0; // (Mandatory) Start physical base address of the register. + regSize = 0; // (Mandatory) Register bit width. + PinCount = 0; // (Mandatory) Number of pins. + match_attr = ""; + template Pin_desc { + PinName = ""; // (Mandatory) Pin name. + init = 0; // (Mandatory) Default value of the register. + F0 = ""; // (Mandatory) Functionality 0. + F1 = ""; // Functionality 1. + F2 = ""; // Functionality 2. + F3 = ""; // Functionality 3. + F4 = ""; // Functionality 4. + F5 = ""; // Functionality 5. + } + } + controller_0 :: Pin_controller { + number = 0; + regStartBasePhy = 0x10FF0000; + regSize = 0x48; + PinCount = 18; + match_attr = "hisilicon_hi35xx_Pin_0"; + T1 :: Pin_desc { + PinName = "T1"; + init = 0x0600; + F0 = "EMMC_CLK"; + F1 = "SFC_CLK"; + F2 = "SFC_BOOT_MODE"; + } + ... + } + ...// Each pin controller corresponds to a controller node. If there are multiple pin controllers, add the corresponding controller nodes one by one. + } + } + } + ``` + +3. Initialize the **PinCntlr** object at the core layer, including initializing the vendor custom structure (passing parameters and data), instantiating **PinCntlrMethod** (used to call underlying functions of the driver) in **PinCntlr**, and implementing the **HdfDriverEntry** member functions (**Bind**, **Init**, and **Release**). + + - Initializing the vendor custom structure + + The **PinCntlr** structure holds parameters and data for the driver. The HDF obtains the values in **pin\_config.hcs** using **DeviceResourceIface**. + + ```c + // PinCntlr is the controller structure at the core layer. Its members are assigned with values by using the Init function. + struct PinCntlr { + struct IDeviceIoService service; + struct HdfDeviceObject *device; + struct PinCntlrMethod *method; + struct DListHead node; + OsalSPinlock sPin; + uint16_t number; + uint16_t PinCount; + struct PinDesc *Pins; + void *priv; + }; + + struct PinDesc { + const char *PinName; // Pointer to the pin name. + void *priv; + }; + ``` + + - Instantiating **PinCntlrMethod** (other members are initialized by **Init**) + + ```c + // Example of Pin_hi35xx.c: Instantiate the hook. + static struct PinCntlrMethod g_method = { + .SetPinPull = Hi35xxPinSetPull, + .GetPinPull = Hi35xxPinGetPull, + .SetPinStrength = Hi35xxPinSetStrength, + .GetPinStrength = Hi35xxPinGetStrength, + .SetPinFunc = Hi35xxPinSetFunc, + .GetPinFunc = Hi35xxPinGetFunc, + }; + ``` + + - **Init** function + + Input parameters: + + **HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs configuration. + + Return value: + + **HDF\_STATUS** (The following table lists some states. For more details, see **HDF\_STATUS** in **/drivers/framework/include/utils/hdf\_base.h**.) + + **Table 2** HDF\_STATUS + + + + + + + + + + + + + + + + + + + + + + + + +

State

+

Description

+

HDF_ERR_INVALID_OBJECT

+

Invalid controller object

+

HDF_ERR_MALLOC_FAIL

+

Failed to allocate memory

+

HDF_ERR_INVALID_PARAM

+

Invalid parameter

+

HDF_ERR_IO

+

I/O error

+

HDF_SUCCESS

+

Initialization successful

+

HDF_FAILURE

+

Initialization failed

+
+ + Function description: + + Initializes the custom structure and **PinCntlr** members, and connects to the pin controller by calling the **PinCntlrAdd** function at the core layer. + + ```c + static int32_t Hi35xxPinInit(struct HdfDeviceObject *device) + { + ... + struct Hi35xxPinCntlr *hi35xx = NULL; + ... + ret = Hi35xxPinCntlrInit(device, hi35xx); // Obtain .hcs information. + ... + DEV_RES_NODE_FOR_EACH_CHILD_NODE(device->property, childNode) { + ret = Hi35xxPinParsePinNode(childNode, hi35xx, index); // (Mandatory) The implementation is as follows: + ... + } + + hi35xx->cntlr.method = &g_method; // Instantiate OPS. + ret = PinCntlrAdd(&hi35xx->cntlr); // Connect to the controller. + ... + } + + static int32_t Hi35xxPinParsePinNode(const struct DeviceResourceNode *node, + struct Hi35xxPinCntlr *hi35xx, + int32_t index) + { + ... + hi35xx->cntlr.Pins[index].PinName = hi35xx->desc[index].PinName; // Instantiate PinName. + hi35xx->cntlr.Pins[index].priv = (void *)node; // Instantiate nodes. + ... + } + + + - **Release** function + + Input parameters: + + **HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs configuration. + + Return value: + + – + + Function description: + + Releases memory and deletes the controller. This function assigns a value to the **Release** API in the driver entry structure. If the HDF fails to call the **Init** function to initialize the driver, the **Release** function can be called to release driver resources. + + ```c + static void Hi35xxPinRelease(struct HdfDeviceObject *device) + { + struct PinCntlr *cntlr = NULL; + ... + PinCntlrRemove(cntlr);// (Mandatory) Call the function at the core layer to release pin controller devices and services. + ... + } + ``` diff --git a/website/docs/extras/en/device-dev/driver/driver-platform-regulator-des.md b/website/docs/extras/en/device-dev/driver/driver-platform-regulator-des.md new file mode 100644 index 0000000000000000000000000000000000000000..49e4cd4230bc653210df4649a051756edf15851d --- /dev/null +++ b/website/docs/extras/en/device-dev/driver/driver-platform-regulator-des.md @@ -0,0 +1,478 @@ +--- +title: "driver-platform-regulator-des" +prepermalink: /extras/8af710ed51e79c71b8036f24b1022b54/ +permalink: /extras/8af710ed51e79c71b8036f24b1022b54/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/driver/driver-platform-regulator-des.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [driver-platform-regulator-des] +--- +# Regulator + +## Overview + +The regulator module controls the voltage and current supplies of some devices in the system. In an embedded system (especially a mobile phone), it is important to control the power consumption, which directly affects the battery endurance. You can use a regulator to shut down the power supply to an idle module in the system or reduce the voltage and current for the module. + +- The regulator APIs provide a set of functions for managing a regulator, including those for: + - Opening or closing a regulator device handle + - Setting the output voltage and current for a regulator + - Enabling or disabling a regulator + - Obtaining the voltage, current, and status of a regulator + +## Available APIs + +**Table 1** Regulator APIs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
CategoryAPIDescription
Operating a regulator device handleRegulatorOpenOpens a regulator device handle.
RegulatorCloseCloses a regulator device handle.
Enabling or disable a regulatorRegulatorEnableEnables a regulator.
RegulatorDisableDisables a regulator.
RegulatorForceDisableForcibly disables a regulator.
Setting or obtaining the output voltageRegulatorSetVoltageSets the output voltage for a regulator.
RegulatorGetVoltageObtains the output voltage of a regulator.
Setting or obtaining the output currentRegulatorSetCurrentSets the output current for a regulator.
RegulatorGetCurrentObtains the output current of a regulator.
Querying the regulator statusRegulatorGetStatusObtains the regulator status.
+ +>![](../../../../images/en/device-dev/public_sys-resources/ae89e6a5f31e3d03603c1d114c8400cf.gif) **NOTE** +>The regulator module can be used in kernel mode but not in user mode. + +## Usage Guidelines + +### How to Use + +During the OS startup process, the driver management module loads the regulator driver based on the configuration file. Then, the regulator driver detects the regulator devices and initializes the driver. + +The figure below shows the process of using a regulator. + +**Figure 1** Process of using a regulator + + +![](../../../../images/en/device-dev/driver/figures/23d9e1758c78c7098a1f52ab27e74226.png) + +### Opening a Regulator Device Handle + +Before operating a regulator, call **RegulatorOpen** to open the device handle of the regulator. This function returns the device handle of the regulator. + +```c +DevHandle RegulatorOpen(const char *name); +``` + +**Table 2** Description of RegulatorOpen + + + +| **Parameter** | **Description** | +| ---------- | ----------------------------- | +| name | Name of the target regulator. | +| **Return Value**| **Description** | +| handle | The regulator device handle is returned if the operation is successful.| +| NULL | The operation fails. | + + +```c +/* Regulator name. */ +const char *name = "regulator_virtual_1"; +DevHandle handle = NULL; + +/* Open the regulator device handle. */ +handle = RegulatorOpen(name); +if (handle == NULL) { + /* Error handling. */ +} +``` + +### Closing a Regulator Device Handle + +Call **RegulatorClose** to close the regulator device handle to release resources. + +```c +void RegulatorClose(DevHandle handle); +``` + +**Table 3** Description of RegulatorClose + + + +| **Parameter** | **Description** | +| ------ | ----------------- | +| handle | Regulator device handle to close.| + + +```c +/* Close the regulator device handle. */ +RegulatorClose(handle); +``` + +### Enabling a Regulator + +Call **RegulatorEnable** to enable a regulator. + +```c +int32_t RegulatorEnable(DevHandle handle); +``` + +**Table 4** Description of RegulatorEnable + + + +| **Parameter** | **Description** | +| ---------- | ----------------- | +| handle | Device handle of the regulator to enable.| +| **Return Value**| **Description** | +| 0 | The operation is successful. | +| Negative value | The operation fails. | + +```c +int32_t ret; + +/* Enable the regulator. */ +ret = RegulatorEnable(handle); +if (ret != 0) { + /* Error handling. */ +} +``` + +### Disabling a Regulator + +Call **RegulatorDisable** to disable a regulator. The operation will fail if the regulator status is set to always on or if a child node of the regulator is not disabled. + +```c +int32_t RegulatorDisable(DevHandle handle); +``` + +**Table 5** Description of RegulatorDisable + + + +| **Parameter** | **Description** | +| ---------- | ----------------- | +| handle | Device handle of the regulator to disable.| +| **Return Value**| **Description** | +| 0 | The operation is successful. | +| Negative value | The operation fails. | + +```c +int32_t ret; + +/* Disable the regulator. */ +ret = RegulatorDisable(handle); +if (ret != 0) { + /* Error handling. */ +} +``` + +### Forcibly Disabling a Regulator + +Call **RegulatorForceDisable** to forcibly disable a regulator. The regulator will be disabled event if its status is set to always on or its child node is still enabled. + +```c +int32_t RegulatorForceDisable(DevHandle handle); +``` + +**Table 6** Description of RegulatorForceDisable + + + +| **Parameter** | **Description** | +| ---------- | ----------------- | +| handle | Device handle of the target regulator.| +| **Return Value**| **Description** | +| 0 | The operation is successful. | +| Negative value | The operation fails. | + +```c +int32_t ret; + +/* Forcibly disable the regulator. */ +ret = RegulatorForceDisable(handle); +if (ret != 0) { + /* Error handling. */ +} +``` +### Setting the Output Voltage Range for a Regulator + +Call **RegulatorSetVoltage** to set the output voltage range for a regulator. + +```c +int32_t RegulatorSetVoltage(DevHandle handle, uint32_t minUv, uint32_t maxUv); +``` + +**Table 7** Description of RegulatorSetVoltage + + + +| **Parameter** | **Description** | +| ---------- | ----------------- | +| handle | Device handle of the target regulator.| +| minUv | Minimum voltage to set. | +| maxUv | Maximum voltage to set. | +| **Return Value**| **Description** | +| 0 | The operation is successful. | +| Negative value | The operation fails. | + +```c +int32_t ret; +int32_t minUv = 0; // Set the minimum voltage to 0 µV. +int32_t maxUv = 20000; // Set the maximum voltage to 20000 µV. + +/* Set the output voltage range for the regulator. */ +ret = RegulatorSetVoltage(handle, minUv, maxUv); +if (ret != 0) { + /* Error handling. */ +} +``` +### Obtaining Regulator Voltage Information + +Call **RegulatorGetVoltage** to obtain voltage information of a regulator. + +```c +int32_t RegulatorGetVoltage(DevHandle handle, uint32_t *voltage); +``` + +**Table 8** Description of RegulatorGetVoltage + + + +| **Parameter** | **Description** | +| ---------- | ----------------- | +| handle | Device handle of the target regulator.| +| *voltage | Pointer to the regulator voltage information. | +| **Return Value**| **Description** | +| 0 | The operation is successful. | +| Negative value | The operation fails. | + +```c +int32_t ret; +uint32_t voltage; + +/* Obtain the regulator voltage information. */ +ret = RegulatorGetVoltage(handle, &voltage); +if (ret != 0) { + /* Error handling. */ +} +``` + + +### Setting the Output Current Range for a Regulator + +Call **RegulatorSetCurrent** to set the output current range for a regulator. + +```c +int32_t RegulatorSetCurrent(DevHandle handle, uint32_t minUa, uint32_t maxUa); +``` + +**Table 9** Description of RegulatorSetCurrent + + + +| **Parameter** | **Description** | +| ---------- | ----------------- | +| handle | Device handle of the target regulator.| +| minUa | Minimum current to set. | +| maxUa | Maximum current to set. | +| **Return Value**| **Description** | +| 0 | The operation is successful. | +| Negative value | The operation fails. | + +```c +int32_t ret; +int32_t minUa = 0; // Set the minimum current to 0 μA. +int32_t maxUa = 200; // Set the maximum current to 200 μA. + +/* Set the output current range for the regulator. */ +ret = RegulatorSetCurrent(handle, minUa, maxUa); +if (ret != 0) { + /* Error handling. */ +} +``` + +### Obtaining Regulator Current Information + +Call **RegulatorGetCurrent** to obtain current information of a regulator. + +```c +int32_t RegulatorGetCurrent(DevHandle handle, uint32_t *regCurrent); +``` + +**Table 10** Description of RegulatorGetCurrent + + + +| **Parameter** | **Description** | +| ----------- | ----------------- | +| handle | Device handle of the target regulator.| +| *regCurrent | Pointer to the regulator current information. | +| **Return Value** | **Description** | +| 0 | The operation is successful. | +| Negative value | The operation fails. | + +```c +int32_t ret; +uint32_t regCurrent; + +/* Obtain the regulator current information. */ +ret = RegulatorGetCurrent(handle, ®Current); +if (ret != 0) { + /* Error handling. */ +} +``` +### Obtaining Regulator Status + +Call **RegulatorGetStatus** to obtain the regulator status. + +```c +int32_t RegulatorGetStatus(DevHandle handle, uint32_t *status); +``` + +**Table 11** Description of RegulatorGetStatus + + + +| **Parameter** | **Description** | +| ---------- | ----------------- | +| handle | Device handle of the target regulator.| +| *status | Pointer to the regulator status information. | +| **Return Value**| **Description** | +| 0 | The operation is successful. | +| Negative value | The operation fails. | + +```c +int32_t ret; +uint32_t status; + +/* Obtain the regulator status. */ +ret = RegulatorGetStatus(handle, &status); +if (ret != 0) { + /* Error handling. */ +} +``` + +## Development Example + +The following is an example of using a regulator. + +```c +void RegulatorTestSample(void) +{ + int32_t ret; + + /* Regulator name. */ + const char *name = "regulator_virtual_1"; + DevHandle handle = NULL; + + /* Open the regulator device handle. */ + handle = RegulatorOpen(name); + if (handle == NULL) { + HDF_LOGE("RegulatorOpen: failed!\n"); + return; + } + + /* Enable the regulator. */ + ret = RegulatorEnable(handle); + if (ret != 0) { + HDF_LOGE("RegulatorEnable: failed, ret %d\n", ret); + goto _ERR; + } + + int32_t minUv = 0; // Set the minimum voltage to 0 µV. + int32_t maxUv = 20000; // Set the maximum voltage to 20000 µV. + + /* Set the output voltage range for the regulator. */ + ret = RegulatorSetVoltage(handle, minUv, maxUv); + if (ret != 0) { + HDF_LOGE("RegulatorSetVoltage: failed, ret %d\n", ret); + goto _ERR; + } + + uint32_t voltage; + + /* Obtain the regulator voltage information. */ + ret = RegulatorGetVoltage(handle, &voltage); + if (ret != 0) { + HDF_LOGE("RegulatorGetVoltage: failed, ret %d\n", ret); + goto _ERR; + } + + uint32_t status; + + /* Obtain the regulator status. */ + ret = RegulatorGetStatus(handle, &status); + if (ret != 0) { + HDF_LOGE("RegulatorGetStatus: failed, ret %d\n", ret); + goto _ERR; + } + + /* Disable the regulator. */ + ret = RegulatorDisable(handle); + if (ret != 0) { + HDF_LOGE("RegulatorDisable: failed, ret %d\n", ret); + goto _ERR; + } + +_ERR: + /* Close the regulator device handle. */ + RegulatorClose(handle); +} +``` diff --git a/website/docs/extras/en/device-dev/driver/driver-platform-regulator-develop.md b/website/docs/extras/en/device-dev/driver/driver-platform-regulator-develop.md new file mode 100644 index 0000000000000000000000000000000000000000..b857c1d761f12dc4ef845413052ab49e1ee5dca5 --- /dev/null +++ b/website/docs/extras/en/device-dev/driver/driver-platform-regulator-develop.md @@ -0,0 +1,351 @@ +--- +title: "driver-platform-regulator-develop" +prepermalink: /extras/b5feae5028d87c42c529613d04cfad1c/ +permalink: /extras/b5feae5028d87c42c529613d04cfad1c/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/driver/driver-platform-regulator-develop.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [driver-platform-regulator-develop] +--- +# Regulator + + +## Overview + +The regulator module controls the voltage and current supplies of some devices in the system. In the Hardware Driver Foundation (HDF), the regulator module uses the unified service mode for API adaptation. In this mode, a device service is used as the regulator manager to handle external access requests in a unified manner, which is reflected in the configuration file. The unified service mode applies to the scenario where there are many device objects of the same type, for example, when the regulator has more than 10 controllers. If the independent service mode is used, more device nodes need to be configured and more memory resources will be consumed by services. + +**Figure 1** Unified service mode +![image1](../../../../images/en/device-dev/driver/figures/c487f7fbfe7baef57f16cb32aff1e866.png) + +## Available APIs + +**RegulatorMethod** structure: + +```c +struct RegulatorMethod { + int32_t (*open)(struct RegulatorNode *node); + int32_t (*close)(struct RegulatorNode *node); + int32_t (*release)(struct RegulatorNode *node); + int32_t (*enable)(struct RegulatorNode *node); + int32_t (*disable)(struct RegulatorNode *node); + int32_t (*forceDisable)(struct RegulatorNode *node); + int32_t (*setVoltage)(struct RegulatorNode *node, uint32_t minUv, uint32_t maxUv); + int32_t (*getVoltage)(struct RegulatorNode *node, uint32_t *voltage); + int32_t (*setCurrent)(struct RegulatorNode *node, uint32_t minUa, uint32_t maxUa); + int32_t (*getCurrent)(struct RegulatorNode *node, uint32_t *regCurrent); + int32_t (*getStatus)(struct RegulatorNode *node, uint32_t *status); +}; +``` + +**Table 1** APIs for the members in the RegulatorMethod structure + +| Method | Input Parameter | Return Value| Description| +| ------------ | ------------------------------------------- | ------ | ---- | +| open | **node**: structure pointer to the regulator node at the core layer.|HDF_STATUS|Opens a device.| +| close | **node**: structure pointer to the regulator node at the core layer.| HDF_STATUS| Closes a device.| +| release | **node**: structure pointer to the regulator node at the core layer.| HDF_STATUS| Releases a device handle.| +| enable | **node**: structure pointer to the regulator node at the core layer.| HDF_STATUS| Enables a device.| +| disable | **node**: structure pointer to the regulator node at the core layer.| HDF_STATUS| Disables a device.| +| forceDisable | **node**: structure pointer to the regulator node at the core layer.| HDF_STATUS| Forcibly disables a device.| +| setVoltage | **node**: structure pointer to the regulator node at the core layer.
**minUv**: minimum voltage to set. It is a uint32_t variable.
**maxUv**: maximum voltage to set. It is a uint32_t variable.| HDF_STATUS| Sets the output voltage range.| +| getVoltage | **node**: structure pointer to the regulator node at the core layer.
**voltage**: pointer to the output voltage value.| HDF_STATUS| Obtains the voltage.| +| setCurrent | **node**: structure pointer to the regulator node at the core layer.
**minUa**: minimum current to set. It is a uint32_t variable.
**maxUa**: maximum current to set. It is a uint32_t variable.| HDF_STATUS| Sets the output current range.| +| getCurrent | **node**: structure pointer to the regulator node at the core layer.
**regCurrent**: pointer to the output current, which is of the uint32_t type.| HDF_STATUS| Obtains the current.| +| getStatus | **node**: structure pointer to the regulator node at the core layer.
**status**: pointer to the output status, which is of the uint32_t type.| HDF_STATUS| Obtains the device status.| + +## How to Develop + +The regulator module adaptation involves the following steps: + +1. Instantiate the driver entry. + + - Instantiate the **HdfDriverEntry** structure. + - Call **HDF_INIT** to register the **HdfDriverEntry** instance with the HDF. + +2. Configure attribute files. + + - Add the **deviceNode** information to the **device_info.hcs** file. + - (Optional) Add the **regulator_config.hcs** file. + +3. Instantiate the regulator controller object. + + - Initialize **RegulatorNode** members. + + - Instantiate **RegulatorMethod**. + + >![](../../../../images/en/device-dev/public_sys-resources/ae89e6a5f31e3d03603c1d114c8400cf.gif) **NOTE** + + >For details, see [Available APIs](#availableapis). + +4. Debug the driver. + - (Optional) Verify basic functionalities of new drivers. For example, verify the information returned when the driver is loaded and whether data is successfully transmitted. + +## Development Example + +The following uses **regulator_virtual.c** as an example to present the content to be provided by the vendor to implement device functionalities. + +1. Instantiate the driver entry. The driver entry must be a global variable of the **HdfDriverEntry** type (defined in **hdf\_device\_desc.h**), and the value of **moduleName** must be the same as that in **device\_info.hcs**. In the HDF, the start address of each **HdfDriverEntry** object of all loaded drivers are collected to form a segment address space similar to an array for the upper layer to invoke. + + Generally, the HDF calls the **Bind** function and then the **Init** function to load the driver. If **Init** fails to be called, the HDF calls **Release** to release driver resources and exit. + + Regulator driver entry reference: + + ```c + struct HdfDriverEntry g_regulatorDriverEntry = { + .moduleVersion = 1, + .moduleName = "virtual_regulator_driver",// (Mandatory) The value must be the same as that of moduleName in the .hcs file. + .Init = VirtualRegulatorInit, + .Release = VirtualRegulatorRelease, + }; + // Call HDF_INIT to register the driver entry with the HDF framework. + HDF_INIT(g_regulatorDriverEntry); + ``` + +2. Add **deviceNode** to the **device\_info.hcs** file, and set the device attributes in the **regulator\_config.hcs** file. The **deviceNode** information is related to registration of the driver entry. The device attribute values are closely related to the default values or value ranges of the **RegulatorNode** members at the core layer. + + + >If there are multiple devices, add the **deviceNode** information to the **device\_info** file and add the corresponding device attributes to the **regulator\_config** file. + + - **device\_info.hcs** reference: + + ```c + root { + device_info { + platform :: host { + hostName = "platform_host"; + priority = 50; + device_regulator :: device { + device0 :: deviceNode { // Configure an HDF device node for each regulator controller. + policy = 1; // 2: visible in user mode; 1: visible in kernel mode; 0: no service required. + priority = 50; // Driver startup priority. + permission = 0644; // Permission to create device nodes of the driver. + /* (Mandatory) Driver name, which must be the same as the moduleName in the driver entry. */ + moduleName = "HDF_PLATFORM_REGULATOR_MANAGER"; + serviceName = "HDF_PLATFORM_REGULATOR_MANAGER"; // (Mandatory) Unique name of the service published by the driver. + /* (Mandatory) Set the controller private data, which must be same as that in regulator_config.hcs. */ + deviceMatchAttr = "hdf_platform_regulator_manager"; + } + device1 :: deviceNode { + policy = 0; + priority = 55; + permission = 0644; + moduleName = "linux_regulator_adapter"; + deviceMatchAttr = "linux_regulator_adapter"; + } + } + } + } + } + ``` + + - **regulator\_config.hcs** reference: + + ```c + root { + platform { + regulator_config { + match_attr = "linux_regulator_adapter"; + template regulator_controller { // (Mandatory) Template configuration. In the template, you can configure the common parameters shared by device nodes. + device_num = 1; + name = ""; + devName = "regulator_adapter_consumer01"; + supplyName = ""; + mode = 1; + minUv = 0; + maxUv = 20000; + minUa = 0; + maxUa = 0; + } + controller_0x130d0000 :: regulator_controller { + device_num = 1; + name = "regulator_adapter_1"; + devName = "regulator_adapter_consumer01"; + supplyName = "virtual-regulator-hdf-adapter"; + mode = 1; + minUv = 1000; + maxUv = 50000; + minUa = 0; + maxUa = 0; + } + /* Each regulator controller corresponds to a controller node. If there are multiple regulator controllers, add the corresponding controller nodes one by one.*/ + controller_0x130d0001 :: regulator_controller { + device_num = 1; + name = "regulator_adapter_2"; + devName = "regulator_adapter_consumer01"; + supplyName = "virtual2-regulator-hdf-adapter"; + mode = 2; + minUv = 0; + maxUv = 0; + minUa = 1000; + maxUa = 50000; + } + } + } + } + ``` + +3. Initialize the **RegulatorNode** object at the core layer, including initializing the vendor custom structure (passing parameters and data), instantiating **RegulatorMethod** (used to call underlying functions of the driver) in **PinCntlr**, and implementing the **HdfDriverEntry** member functions (**Bind**, **Init**, and **Release**). + + - Initializing the vendor custom structure + + The **RegulatorNode** structure holds parameters and data for the driver. The HDF obtains the values in **regulator\_config.hcs** using **DeviceResourceIface**. + + ```c + // RegulatorNode is the controller structure at the core layer. Its members are assigned with values by using the Init function. + struct RegulatorNode { + struct RegulatorDesc regulatorInfo; + struct DListHead node; + struct RegulatorMethod *ops; + void *priv; + struct OsalMutex lock; + }; + + struct RegulatorDesc { + const char *name; /* Regulator name. */ + const char *parentName; /* Regulator parent node name. */ + struct RegulatorConstraints constraints; /* Regulator constraint information. */ + uint32_t minUv; /* Minimum output voltage. */ + uint32_t maxUv; /* Maximum output voltage. */ + uint32_t minUa; /* Minimum output current. */ + uint32_t maxUa; /* Maximum output current. */ + uint32_t status; /* Regulator status, which can be on or off. */ + int useCount; + int consumerRegNums; /* Number of regulator consumers. */ + RegulatorStatusChangecb cb; /* Variable used to notify the regulator status changes. */ + }; + + struct RegulatorConstraints { + uint8_t alwaysOn; /* Whether the regulator is always on. */ + uint8_t mode; /* Voltage or current. */ + uint32_t minUv; /* Minimum output voltage allowed. */ + uint32_t maxUv; /* Maximum output voltage allowed. */ + uint32_t minUa; /* Minimum output current allowed. */ + uint32_t maxUa; /* Maximum output current allowed. */ + }; + ``` + + - Instantiating **RegulatorMethod** (other members are initialized by **Init**) + + ```c + // Example of regulator_virtual.c: Instantiate the hook. + static struct RegulatorMethod g_method = { + .enable = VirtualRegulatorEnable, + .disable = VirtualRegulatorDisable, + .setVoltage = VirtualRegulatorSetVoltage, + .getVoltage = VirtualRegulatorGetVoltage, + .setCurrent = VirtualRegulatorSetCurrent, + .getCurrent = VirtualRegulatorGetCurrent, + .getStatus = VirtualRegulatorGetStatus, + }; + ``` + + - **Init** function + + Input parameters: + + **HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs configuration. + + Return value: + + **HDF\_STATUS** (The following table lists some states. For more details, see **HDF\_STATUS** in **/drivers/framework/include/utils/hdf\_base.h**.) + + **Table 2** HDF\_STATUS + + + + + + + + + + + + + + + + + + + + + + + + +

State

+

Description

+

HDF_ERR_INVALID_OBJECT

+

Invalid controller object.

+

HDF_ERR_MALLOC_FAIL

+

Failed to allocate memory.

+

HDF_ERR_INVALID_PARAM

+

Invalid parameter.

+

HDF_ERR_IO

+

I/O error.

+

HDF_SUCCESS

+

Initialization successful.

+

HDF_FAILURE

+

Initialization failed.

+
+ Function description: + Initializes the custom structure and **RegulatorNode** members, and adds the regulator controller by calling the **RegulatorNodeAdd** function at the core layer. + + ```c + static int32_t VirtualRegulatorInit(struct HdfDeviceObject *device) + { + int32_t ret; + const struct DeviceResourceNode *childNode = NULL; + ... + DEV_RES_NODE_FOR_EACH_CHILD_NODE(device->property, childNode) { + ret = VirtualRegulatorParseAndInit(device, childNode);// (Mandatory) The implementation is as follows: + ... + } + ... + } + + static int32_t VirtualRegulatorParseAndInit(struct HdfDeviceObject *device, const struct DeviceResourceNode *node) + { + int32_t ret; + struct RegulatorNode *regNode = NULL; + (void)device; + + regNode = (struct RegulatorNode *)OsalMemCalloc(sizeof(*regNode));// Load the .hcs file. + ... + ret = VirtualRegulatorReadHcs(regNode, node);// Read .hcs information. + ... + regNode->priv = (void *)node; // Instantiate the node. + regNode->ops = &g_method; // Instantiate OPS. + + ret = RegulatorNodeAdd(regNode); // Add the node. + ... + } + + + - **Release** function + + Input parameters: + + **HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs configuration. + + Return value: + + – + + Function description: + + Releases memory and deletes the controller. This function assigns a value to the **Release** API in the driver entry structure. If the HDF fails to call the **Init** function to initialize the driver, the **Release** function can be called to release driver resources. + + ```c + static void VirtualRegulatorRelease(struct HdfDeviceObject *device) + { + ... + RegulatorNodeRemoveAll();// (Mandatory) Call the function at the core layer to release regulator controller devices and services. + } diff --git a/website/docs/extras/en/device-dev/driver/driver-platform.md b/website/docs/extras/en/device-dev/driver/driver-platform.md new file mode 100644 index 0000000000000000000000000000000000000000..6ac827f5f5dec4623fec781565e490fe559e96e5 --- /dev/null +++ b/website/docs/extras/en/device-dev/driver/driver-platform.md @@ -0,0 +1,42 @@ +--- +title: "driver-platform" +prepermalink: /extras/b8a2d4bd1adb53721f2eb736dffeefde/ +permalink: /extras/b8a2d4bd1adb53721f2eb736dffeefde/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/driver/driver-platform.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [driver-platform] +--- +# Driver Platform Usage + +- **[ADC](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Usage/ADC)** + +- **[GPIO](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Usage/GPIO)** + +- **[HDMI](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Usage/HDMI)** + +- **[I2C](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Usage/I2C)** + +- **[I3C](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Usage/I3C)** + +- **[MIPI CSI](/extras/b3e48ac8c5f33df76f82989b158f6a71/)** + +- **[MIPI DSI](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Usage/MIPI%20DSI)** + +- **[PWM](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Usage/PWM)** + +- **[RTC](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Usage/RTC)** + +- **[SDIO](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Usage/SDIO)** + +- **[SPI](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Usage/SPI)** + +- **[UART](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Usage/UART)** + +- **[Watchdog](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Usage/Watchdog)** diff --git a/website/docs/extras/en/device-dev/driver/driver.md b/website/docs/extras/en/device-dev/driver/driver.md new file mode 100644 index 0000000000000000000000000000000000000000..9cdb0ac4a4fc80526796f883cc62e4b92945fb96 --- /dev/null +++ b/website/docs/extras/en/device-dev/driver/driver.md @@ -0,0 +1,26 @@ +--- +title: "driver" +prepermalink: /extras/cb26919f50447d6fa00725a9b1560489/ +permalink: /extras/cb26919f50447d6fa00725a9b1560489/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/driver/driver.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [driver] +--- +# Drivers + +- **[HDF](/extras/d2551de5b6d3b8974848851e5f27fcb1/)** + +- **[Platform Driver Development](/extras/19111b13a03f8ad3e8db558338312852/)** + +- **[Platform Driver Usage](/extras/b8a2d4bd1adb53721f2eb736dffeefde/)** + +- **[Peripheral Driver Usage](/extras/11ca76760a0ffd994b59a81dff37a91f/)** + + diff --git a/website/docs/extras/en/device-dev/faqs/Readme-EN.md b/website/docs/extras/en/device-dev/faqs/Readme-EN.md new file mode 100644 index 0000000000000000000000000000000000000000..09280ec7a74eb9f4283a1bd96bcaac91e98475ac --- /dev/null +++ b/website/docs/extras/en/device-dev/faqs/Readme-EN.md @@ -0,0 +1,26 @@ +--- +title: "Readme-EN" +prepermalink: /extras/9fc267037ba49a324b4bb03cd7f6abe7/ +permalink: /extras/9fc267037ba49a324b4bb03cd7f6abe7/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/faqs/Readme-EN.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [Readme-EN] +--- +# FAQs + +- [Overview of FAQs](/pages/en/device/device/References/FAQs/Overview%20of%20FAQs) +- [Environment Setup](/pages/en/device/device/References/FAQs/Environment%20Setup) +- [Compilation and Building Subsystem](/pages/en/device/device/References/FAQs/Compilation%20and%20Building%20Subsystem) +- [Burning](/pages/en/device/device/References/FAQs/Burning) +- [Kernel](/pages/en/device/device/References/FAQs/Kernel) +- [Porting](/pages/en/device/device/References/FAQs/Porting) +- [Startup](/pages/en/device/device/References/FAQs/Startup) +- [System Applications](/pages/en/device/device/References/FAQs/System%20Applications) + diff --git a/website/docs/extras/en/device-dev/get-code/Readme-EN.md b/website/docs/extras/en/device-dev/get-code/Readme-EN.md new file mode 100644 index 0000000000000000000000000000000000000000..022293288b05776b9cf9478ab193d9a511fb273e --- /dev/null +++ b/website/docs/extras/en/device-dev/get-code/Readme-EN.md @@ -0,0 +1,22 @@ +--- +title: "Readme-EN" +prepermalink: /extras/3d52733783e6e4713d640983fcfbf4ab/ +permalink: /extras/3d52733783e6e4713d640983fcfbf4ab/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/get-code/Readme-EN.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [Readme-EN] +--- +# Source Code Acquisition + +- [Source Code Acquisition](/pages/en/device/device/Quick%20Start/Obtaining%20Source%20Code) +- [Tool Acquisition](/extras/91aa4095789f64fa53b14553074cad08/) + - [Docker Environment](/pages/en/device/device/Tools/Docker%20Environment) + - [IDE](/pages/en/device/device/Tools/IDE) + diff --git a/website/docs/extras/en/device-dev/get-code/gettools.md b/website/docs/extras/en/device-dev/get-code/gettools.md new file mode 100644 index 0000000000000000000000000000000000000000..f7498817cb41831ad2a5911da9c249c29f25656d --- /dev/null +++ b/website/docs/extras/en/device-dev/get-code/gettools.md @@ -0,0 +1,22 @@ +--- +title: "gettools" +prepermalink: /extras/91aa4095789f64fa53b14553074cad08/ +permalink: /extras/91aa4095789f64fa53b14553074cad08/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/get-code/gettools.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [gettools] +--- +# Tool Acquisition + +- **[Docker Environment](/pages/en/device/device/Tools/Docker%20Environment)** + +- **[IDE](/pages/en/device/device/Tools/IDE)** + + diff --git a/website/docs/extras/en/device-dev/get-code/sourcecode.md b/website/docs/extras/en/device-dev/get-code/sourcecode.md new file mode 100644 index 0000000000000000000000000000000000000000..06dfe38ef9207cbe559073fb069a901e94cfcd46 --- /dev/null +++ b/website/docs/extras/en/device-dev/get-code/sourcecode.md @@ -0,0 +1,20 @@ +--- +title: "sourcecode" +prepermalink: /extras/68ec4baf29cd98b78f7295d6fc85ccce/ +permalink: /extras/68ec4baf29cd98b78f7295d6fc85ccce/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/get-code/sourcecode.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [sourcecode] +--- +# Source Code Acquisition + +- **[Source Code Acquisition](/pages/en/device/device/Quick%20Start/Obtaining%20Source%20Code)** + + diff --git a/website/docs/extras/en/device-dev/glossary/Readme-EN.md b/website/docs/extras/en/device-dev/glossary/Readme-EN.md new file mode 100644 index 0000000000000000000000000000000000000000..d643ef7ea0283ba2f188d91eb31e03f79a671aef --- /dev/null +++ b/website/docs/extras/en/device-dev/glossary/Readme-EN.md @@ -0,0 +1,19 @@ +--- +title: "Readme-EN" +prepermalink: /extras/c5984b908f0888c538d4ebefbb37b74d/ +permalink: /extras/c5984b908f0888c538d4ebefbb37b74d/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/glossary/Readme-EN.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [Readme-EN] +--- +# Glossary + +[Glossary](/pages/en/overview/Glossary) + diff --git a/website/docs/extras/en/device-dev/guide/Readme-EN.md b/website/docs/extras/en/device-dev/guide/Readme-EN.md new file mode 100644 index 0000000000000000000000000000000000000000..054571ddd8d31828a1065c2550a17af649ed7402 --- /dev/null +++ b/website/docs/extras/en/device-dev/guide/Readme-EN.md @@ -0,0 +1,49 @@ +--- +title: "Readme-EN" +prepermalink: /extras/c62366874368f3b555de35376f0d61ff/ +permalink: /extras/c62366874368f3b555de35376f0d61ff/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/guide/Readme-EN.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [Readme-EN] +--- +# Development Examples + +- [Mini- and Small-System Devices](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Mini-%20and%20Small-System%20Devices) + - [WLAN-connected Products](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/WLAN-connected%20Products/WLAN-connected%20Products) + - [LED Peripheral Control](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/WLAN-connected%20Products/LED%20Peripheral%20Control) + - [Third-Party SDK Integration](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/WLAN-connected%20Products/Third-Party%20SDK%20Integration) + - [Cameras Without a Screen](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20Without%20a%20Screen/Cameras%20Without%20a%20Screen) + - [Camera Control](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20Without%20a%20Screen/Camera%20Control/Camera%20Control) + - [Overview](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20Without%20a%20Screen/Camera%20Control/Overview) + - [Development Guidelines](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20Without%20a%20Screen/Camera%20Control/Development%20Guidelines/Development%20Guidelines) + - [Photographing](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20Without%20a%20Screen/Camera%20Control/Development%20Guidelines/Photographing) + - [Video Recording](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20Without%20a%20Screen/Camera%20Control/Development%20Guidelines/Video%20Recording) + - [Use Case](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20Without%20a%20Screen/Camera%20Control/Use%20Case) + - [Cameras with a Screen](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20with%20a%20Screen/Cameras%20with%20a%20Screen) + - [Screen and Camera Control](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20with%20a%20Screen/Screen%20and%20Camera%20Control/Screen%20and%20Camera%20Control) + - [Overview](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20with%20a%20Screen/Screen%20and%20Camera%20Control/Overview) + - [Development Guidelines](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20with%20a%20Screen/Screen%20and%20Camera%20Control/Development%20Guidelines/Development%20Guidelines) + - [Photographing](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20with%20a%20Screen/Screen%20and%20Camera%20Control/Development%20Guidelines/Photographing) + - [Video Recording](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20with%20a%20Screen/Screen%20and%20Camera%20Control/Development%20Guidelines/Video%20Recording) + - [Previewing](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20with%20a%20Screen/Screen%20and%20Camera%20Control/Development%20Guidelines/Previewing) + - [Use Case](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20with%20a%20Screen/Screen%20and%20Camera%20Control/Use%20Case) + - [Visual Application Development](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20with%20a%20Screen/Visual%20Application%20Development/Visual%20Application%20Development) + - [Overview](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20with%20a%20Screen/Visual%20Application%20Development/Overview) + - [Preparations](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20with%20a%20Screen/Visual%20Application%20Development/Preparations) + - [Adding Pages](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20with%20a%20Screen/Visual%20Application%20Development/Adding%20Pages) + - [Building the Home Page](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20with%20a%20Screen/Visual%20Application%20Development/Building%20the%20Home%20Page) + - [Building the Details Page](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20with%20a%20Screen/Visual%20Application%20Development/Building%20the%20Details%20Page) + - [Debugging and Packaging](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20with%20a%20Screen/Visual%20Application%20Development/Debugging%20and%20Packaging) + - [Running on the Device](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20with%20a%20Screen/Visual%20Application%20Development/Running%20on%20the%20Device) + - [FAQs](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20with%20a%20Screen/Visual%20Application%20Development/FAQs) +- [Standard-System Devices](/pages/en/device/device/Device%20Development%20Examples/Standard-System%20Devices/Standard-System%20Devices) + - [Development Guidelines on Clock Apps](/pages/en/device/device/Device%20Development%20Examples/Standard-System%20Devices/Development%20Guidelines%20on%20Clock%20Apps) + - [Development Example for Platform Drivers](/pages/en/device/device/Device%20Development%20Examples/Standard-System%20Devices/Development%20Example%20for%20Platform%20Drivers) + - [Development Example for Peripheral Drivers](/pages/en/device/device/Device%20Development%20Examples/Standard-System%20Devices/Development%20Example%20for%20Peripheral%20Drivers) \ No newline at end of file diff --git a/website/docs/extras/en/device-dev/guide/device-wlan-led.md b/website/docs/extras/en/device-dev/guide/device-wlan-led.md new file mode 100644 index 0000000000000000000000000000000000000000..513a80d4bc5ca6024a91727c206baafcfa6563f1 --- /dev/null +++ b/website/docs/extras/en/device-dev/guide/device-wlan-led.md @@ -0,0 +1,20 @@ +--- +title: "device-wlan-led" +prepermalink: /extras/b0cc7525f5bc7e4f1dc3ef7dcefe52cb/ +permalink: /extras/b0cc7525f5bc7e4f1dc3ef7dcefe52cb/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/guide/device-wlan-led.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [device-wlan-led] +--- +# LED Peripheral Control + +- **[LED Peripheral Control](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/WLAN-connected%20Products/LED%20Peripheral%20Control)** + + diff --git a/website/docs/extras/en/device-dev/guide/device.md b/website/docs/extras/en/device-dev/guide/device.md new file mode 100644 index 0000000000000000000000000000000000000000..27f40faf9909982d464a7d18535f9478984f6642 --- /dev/null +++ b/website/docs/extras/en/device-dev/guide/device.md @@ -0,0 +1,22 @@ +--- +title: "device" +prepermalink: /extras/7533f87adc376dd24e3057b51c55f018/ +permalink: /extras/7533f87adc376dd24e3057b51c55f018/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/guide/device.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [device] +--- +# Devices + +- **[Mini- and Small-System Devices](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Mini-%20and%20Small-System%20Devices)** + +- **[Standard-System Devices](/pages/en/device/device/Device%20Development%20Examples/Standard-System%20Devices/Standard-System%20Devices)** + + diff --git a/website/docs/extras/en/device-dev/kernel/Readme-EN.md b/website/docs/extras/en/device-dev/kernel/Readme-EN.md new file mode 100644 index 0000000000000000000000000000000000000000..7577ab69af4b5848a3e52567b6a066e6fc904136 --- /dev/null +++ b/website/docs/extras/en/device-dev/kernel/Readme-EN.md @@ -0,0 +1,191 @@ +--- +title: "Readme-EN" +prepermalink: /extras/92f95e9e98bc7c8c3fe1cf8a5b5d1ace/ +permalink: /extras/92f95e9e98bc7c8c3fe1cf8a5b5d1ace/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/kernel/Readme-EN.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [Readme-EN] +--- +# Kernel + +- [Kernel for Mini Systems](/extras/bf8496454cb9a8c0712aa081ac032dae/) + - [Kernel Overview](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Kernel%20Overview) + - [Basic Kernel](/extras/ab69393149b0cfdc7adcdb5a1d77bfbf/) + - [Interrupt Management](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Basic%20Kernel/Interrupt%20Management) + - [Task Management](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Basic%20Kernel/Task%20Management) + - [Memory Management](/extras/db31368bb5c0a9ae45a89739b4479357/) + - [Basic Concepts](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Basic%20Kernel/Memory%20Management/Basic%20Concepts) + - [Static Memory](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Basic%20Kernel/Memory%20Management/Static%20Memory) + - [Dynamic Memory](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Basic%20Kernel/Memory%20Management/Dynamic%20Memory) + - [Kernel Communication Mechanisms](/extras/1549e017f616615c51508ecf0e5ca0a8/) + - [Event](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Basic%20Kernel/Kernel%20Communication%20Mechanisms/Event) + - [Mutex](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Basic%20Kernel/Kernel%20Communication%20Mechanisms/Mutex) + - [Queue](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Basic%20Kernel/Kernel%20Communication%20Mechanisms/Queue) + - [Semaphore](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Basic%20Kernel/Kernel%20Communication%20Mechanisms/Semaphore) + - [Time Management](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Basic%20Kernel/Time%20Management) + - [Software Timer](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Basic%20Kernel/Software%20Timer) + - [Extended Components](/extras/60843d28981ce872ecb65d2c2e96f770/) + - [C++ Support](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Extended%20Components/C%2B%2B%20Support) + - [CPUP](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Extended%20Components/CPUP) + - [Dynamic Loading](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Extended%20Components/Dynamic%20Loading) + - [File System](/extras/916e02d6a4d0a19d0fe8f7b4696421cc/) + - [FAT](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Extended%20Components/File%20System/FAT) + - [LittleFS](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Extended%20Components/File%20System/LittleFS) + - [Kernel Debugging](/extras/14558de3712212a3527c224592aab031/) + - [Memory Debugging](/extras/90db22b9c9eaf74a0cda5222b0b3084e/) + - [Memory Information Statistics](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Kernel%20Debugging/Memory%20Debugging/Memory%20Information%20Statistics) + - [Memory Leak Check](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Kernel%20Debugging/Memory%20Debugging/Memory%20Leak%20Check) + - [Memory Corruption Check](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Kernel%20Debugging/Memory%20Debugging/Memory%20Corruption%20Check) + - [Exception Debugging](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Kernel%20Debugging/Exception%20Debugging) + - [Trace](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Kernel%20Debugging/Trace) + - [LMS](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Kernel%20Debugging/LMS) + - [Appendix](/extras/4280d4f33ecdf285afb14e29ccbbbd7c/) + - [Kernel Coding Specification](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Appendix/Kernel%20Coding%20Specification) + - [Basic Data Structure](/extras/0d4df9938b6caa7ec459bcbf6e3401da/) + - [Doubly Linked List](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Appendix/Basic%20Data%20Structure/Doubly%20Linked%20List) + - [Standard Libraries](/extras/ded573feb6bab3c2e65fd119eacf1e21/) + - [CMSIS Support](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Appendix/Standard%20Libraries/CMSIS%20Support) + - [POSIX Support](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Appendix/Standard%20Libraries/POSIX%20Support) +- [Kernel for Small Systems](/extras/b1a8758905970b3469be3718a08589d4/) + - [Kernel Overview](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Kernel%20Overview) + - [Kernel Startup](/extras/133870a58c9b9fb419b38d9ec1009964/) + - [Startup in Kernel Space](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Kernel%20Startup/Startup%20in%20Kernel%20Space) + - [Startup in User Space](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Kernel%20Startup/Startup%20in%20User%20Space) + - [Basic Kernel](/extras/78ec94b49b111be049b66228f0df7d34/) + - [Interrupt and Exception Handling](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Interrupt%20and%20Exception%20Handling) + - [Process Management](/extras/980e1da9bf8cae80e2871575b44ae371/) + - [Process](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Process%20Management/Process) + - [Task](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Process%20Management/Task) + - [Scheduler](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Process%20Management/Scheduler) + - [Memory Management](/extras/354df90922c0fd497e0ea82dd0345c53/) + - [Heap Memory Management](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Memory%20Management/Heap%20Memory%20Management) + - [Physical Memory Management](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Memory%20Management/Physical%20Memory%20Management) + - [Virtual Memory Management](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Memory%20Management/Virtual%20Memory%20Management) + - [Virtual-to-Physical Mapping](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Memory%20Management/Virtual-to-Physical%20Mapping) + - [Kernel Communication Mechanisms](/extras/52f81c016abf09fffa3d9efb6c6d88e2/) + - [Event](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Kernel%20Communication%20Mechanisms/Event) + - [Semaphore](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Kernel%20Communication%20Mechanisms/Semaphore) + - [Mutex](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Kernel%20Communication%20Mechanisms/Mutex) + - [Queue](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Kernel%20Communication%20Mechanisms/Queue) + - [RW Lock](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Kernel%20Communication%20Mechanisms/RW%20Lock) + - [Futex](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Kernel%20Communication%20Mechanisms/Futex) + - [Signal](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Kernel%20Communication%20Mechanisms/Signal) + - [Time Management](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Time%20Management) + - [Software Timer](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Software%20Timer) + - [Atomic Operation](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Atomic%20Operation) + - [Extension Components](/extras/f7b390a50a5516e394c1ef54968ab731/) + - [System Call](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Extension%20Components/System%20Call) + - [Dynamic Loading and Linking](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Extension%20Components/Dynamic%20Loading%20and%20Linking) + - [Virtual Dynamic Shared Object](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Extension%20Components/Virtual%20Dynamic%20Shared%20Object) + - [LiteIPC](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Extension%20Components/LiteIPC) + - [File Systems](/extras/1cf17f18bff1bfb4d5dfa620acb63acb/) + - [Virtual File System](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Extension%20Components/File%20Systems/Virtual%20File%20System) + - [Supported File Systems](/extras/92e1896e294ca006a04935bc511e4a43/) + - [FAT](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Extension%20Components/File%20Systems/Supported%20File%20Systems/FAT) + - [JFFS2](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Extension%20Components/File%20Systems/Supported%20File%20Systems/JFFS2) + - [NFS](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Extension%20Components/File%20Systems/Supported%20File%20Systems/NFS) + - [Ramfs](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Extension%20Components/File%20Systems/Supported%20File%20Systems/Ramfs) + - [procfs](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Extension%20Components/File%20Systems/Supported%20File%20Systems/procfs) + - [File System Adaptation](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Extension%20Components/File%20Systems/File%20System%20Adaptation) + - [Debugging and Tools](/extras/aed7ed5206f77a2c4e8a99c65cd4ad25/) + - [Shell](/extras/de21524a8b147ddd67e0b0411e172c6b/) + - [Introduction to the Shell](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Introduction%20to%20the%20Shell) + - [Shell Command Development Guidelines](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Development%20Guidelines) + - [Shell Command Programming Example](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Programming%20Example) + - [Shell Command Reference](/extras/f9baf32e9301d3bbcde624cf8ede20f3/) + - [System Commands](/extras/7ad916f43aaaf9889b12d59877c01f3b/) + - [cpup](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/cpup) + - [date](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/date) + - [dmesg](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/dmesg) + - [exec](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/exec) + - [free](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/free) + - [help](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/help) + - [hwi](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/hwi) + - [kill](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/kill) + - [log](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/log) + - [memcheck](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/memcheck) + - [oom](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/oom) + - [pmm](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/pmm) + - [reset](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/reset) + - [sem](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/sem) + - [stack](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/stack) + - [su](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/su) + - [swtmr](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/swtmr) + - [systeminfo](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/systeminfo) + - [task](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/task) + - [uname](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/uname) + - [vmm](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/vmm) + - [watch](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/watch) + - [File Commands](/extras/9102c912c33a6e25d8ccd8f508fa120e/) + - [cat](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/cat) + - [cd](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/cd) + - [chgrp](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/chgrp) + - [chmod](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/chmod) + - [chown](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/chown) + - [cp](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/cp) + - [format](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/format) + - [ls](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/ls) + - [lsfd](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/lsfd) + - [mkdir](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/mkdir) + - [mount](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/mount) + - [partinfo](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/partinfo) + - [partition](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/partition) + - [pwd](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/pwd) + - [rm](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/rm) + - [rmdir](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/rmdir) + - [statfs](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/statfs) + - [sync](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/sync) + - [touch](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/touch) + - [writeproc](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/writeproc) + - [umount](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/umount) + - [Network Commands](/extras/dcf839d6c3fe6cd028f71510e9f91807/) + - [arp](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/Network%20Commands/arp) + - [dhclient](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/Network%20Commands/dhclient) + - [ifconfig](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/Network%20Commands/ifconfig) + - [ipdebug](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/Network%20Commands/ipdebug) + - [netstat](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/Network%20Commands/netstat) + - [ntpdate](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/Network%20Commands/ntpdate) + - [ping](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/Network%20Commands/ping) + - [ping6](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/Network%20Commands/ping6) + - [telnet](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/Network%20Commands/telnet) + - [tftp](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/Network%20Commands/tftp) + - [Magic Key](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Magic%20Key) + - [User-Space Exception Information](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/User-Space%20Exception%20Information) + - [Trace](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Trace) + - [perf](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/perf) + - [LMS](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/LMS) + - [Process Commissioning](/extras/f8a12d5cd04099ccd66f14e3bee9ffd8/) + - [CPUP](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Process%20Commissioning/CPUP) + - [Memory Debugging](/extras/b94151258cef10457175c738baf57967/) + - [Memory Information Statistics](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Memory%20Debugging/Memory%20Information%20Statistics) + - [Memory Leak Check](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Memory%20Debugging/Memory%20Leak%20Check) + - [Memory Corruption Check](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Memory%20Debugging/Memory%20Corruption%20Check) + - [User-Mode Memory Debugging](/extras/ba464eebba5f11da71c5fbc39ede1874/) + - [Basic Concepts](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/User-Mode%20Memory%20Debugging/Basic%20Concepts) + - [Working Principles](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/User-Mode%20Memory%20Debugging/Working%20Principles) + - [Usage](/extras/2079e670c57611ba785dd3124885dbcc/) + - [API Description](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/User-Mode%20Memory%20Debugging/Usage/API%20Description) + - [How to Use](/extras/611e555638e4ece45d20a3f20e8ec21b/) + - [Calling APIs](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/User-Mode%20Memory%20Debugging/Usage/How%20to%20Use/Calling%20APIs) + - [Using the CLI](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/User-Mode%20Memory%20Debugging/Usage/How%20to%20Use/Using%20the%20CLI) + - [Typical Memory Problems](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/User-Mode%20Memory%20Debugging/Typical%20Memory%20Problems) + - [Other Kernel Debugging Methods](/extras/25c92d52997655b370d21851b5a2cf1e/) + - [Dying Gasp](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Other%20Kernel%20Debugging%20Methods/Dying%20Gasp) + - [Common Fault Locating Methods](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Other%20Kernel%20Debugging%20Methods/Common%20Fault%20Locating%20Methods) + - [Appendix](/extras/a548faed2939a065b131219e2fba3bc0/) + - [Basic Data Structure](/extras/305d42810427764633984b4303f33328/) + - [Doubly Linked List](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Appendix/Basic%20Data%20Structure/Doubly%20Linked%20List) + - [Bitwise Operation](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Appendix/Basic%20Data%20Structure/Bitwise%20Operation) + - [Standard Library](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Appendix/Standard%20Library) + +- [Kernel for Standard Systems](/extras/6b7b37f37bac90610514997ec2249095/) + - [Linux Kernel Overview](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Standard%20Systems/Linux%20Kernel%20Overview) + - [Applying Patches on OpenHarmony Development Boards](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Standard%20Systems/Applying%20Patches%20on%20OpenHarmony%20Development%20Boards) + - [Guidelines for Building the Linux Kernel](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Standard%20Systems/Guidelines%20for%20Building%20the%20Linux%20Kernel) \ No newline at end of file diff --git a/website/docs/extras/en/device-dev/kernel/kernel-mini-app.md b/website/docs/extras/en/device-dev/kernel/kernel-mini-app.md new file mode 100644 index 0000000000000000000000000000000000000000..43d811030a685b31806cb80366484214927acc49 --- /dev/null +++ b/website/docs/extras/en/device-dev/kernel/kernel-mini-app.md @@ -0,0 +1,24 @@ +--- +title: "kernel-mini-app" +prepermalink: /extras/4280d4f33ecdf285afb14e29ccbbbd7c/ +permalink: /extras/4280d4f33ecdf285afb14e29ccbbbd7c/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/kernel/kernel-mini-app.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [kernel-mini-app] +--- +# Appendix + +- **[Kernel Coding Specification](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Appendix/Kernel%20Coding%20Specification)** + +- **[Basic Data Structure](/extras/0d4df9938b6caa7ec459bcbf6e3401da/)** + +- **[Standard Libraries](/extras/ded573feb6bab3c2e65fd119eacf1e21/)** + + diff --git a/website/docs/extras/en/device-dev/kernel/kernel-mini-appx-data.md b/website/docs/extras/en/device-dev/kernel/kernel-mini-appx-data.md new file mode 100644 index 0000000000000000000000000000000000000000..d58add0b530e76ee68508537dc97f94ec6006f08 --- /dev/null +++ b/website/docs/extras/en/device-dev/kernel/kernel-mini-appx-data.md @@ -0,0 +1,20 @@ +--- +title: "kernel-mini-appx-data" +prepermalink: /extras/0d4df9938b6caa7ec459bcbf6e3401da/ +permalink: /extras/0d4df9938b6caa7ec459bcbf6e3401da/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/kernel/kernel-mini-appx-data.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [kernel-mini-appx-data] +--- +# Basic Data Structure + +- **[Doubly Linked List](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Appendix/Basic%20Data%20Structure/Doubly%20Linked%20List)** + + diff --git a/website/docs/extras/en/device-dev/kernel/kernel-mini-appx-lib.md b/website/docs/extras/en/device-dev/kernel/kernel-mini-appx-lib.md new file mode 100644 index 0000000000000000000000000000000000000000..27e2273fbdc5d36e76ace75f6a2b09669700c5f5 --- /dev/null +++ b/website/docs/extras/en/device-dev/kernel/kernel-mini-appx-lib.md @@ -0,0 +1,22 @@ +--- +title: "kernel-mini-appx-lib" +prepermalink: /extras/ded573feb6bab3c2e65fd119eacf1e21/ +permalink: /extras/ded573feb6bab3c2e65fd119eacf1e21/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/kernel/kernel-mini-appx-lib.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [kernel-mini-appx-lib] +--- +# Standard Libraries + +- **[CMSIS Support](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Appendix/Standard%20Libraries/CMSIS%20Support)** + +- **[POSIX Support](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Appendix/Standard%20Libraries/POSIX%20Support)** + + diff --git a/website/docs/extras/en/device-dev/kernel/kernel-mini-basic-ipc.md b/website/docs/extras/en/device-dev/kernel/kernel-mini-basic-ipc.md new file mode 100644 index 0000000000000000000000000000000000000000..31140ac98fbca3b8eb244c03dde45e42dac9a071 --- /dev/null +++ b/website/docs/extras/en/device-dev/kernel/kernel-mini-basic-ipc.md @@ -0,0 +1,26 @@ +--- +title: "kernel-mini-basic-ipc" +prepermalink: /extras/1549e017f616615c51508ecf0e5ca0a8/ +permalink: /extras/1549e017f616615c51508ecf0e5ca0a8/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/kernel/kernel-mini-basic-ipc.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [kernel-mini-basic-ipc] +--- +# Kernel Communication Mechanisms + +- **[Event](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Basic%20Kernel/Kernel%20Communication%20Mechanisms/Event)** + +- **[Mutex](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Basic%20Kernel/Kernel%20Communication%20Mechanisms/Mutex)** + +- **[Queue](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Basic%20Kernel/Kernel%20Communication%20Mechanisms/Queue)** + +- **[Semaphore](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Basic%20Kernel/Kernel%20Communication%20Mechanisms/Semaphore)** + + diff --git a/website/docs/extras/en/device-dev/kernel/kernel-mini-basic-memory.md b/website/docs/extras/en/device-dev/kernel/kernel-mini-basic-memory.md new file mode 100644 index 0000000000000000000000000000000000000000..ea68fcaaec449718b9cacd7ed46c088500cab12f --- /dev/null +++ b/website/docs/extras/en/device-dev/kernel/kernel-mini-basic-memory.md @@ -0,0 +1,24 @@ +--- +title: "kernel-mini-basic-memory" +prepermalink: /extras/db31368bb5c0a9ae45a89739b4479357/ +permalink: /extras/db31368bb5c0a9ae45a89739b4479357/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/kernel/kernel-mini-basic-memory.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [kernel-mini-basic-memory] +--- +# Memory Management + +- **[Basic Concepts](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Basic%20Kernel/Memory%20Management/Basic%20Concepts)** + +- **[Static Memory](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Basic%20Kernel/Memory%20Management/Static%20Memory)** + +- **[Dynamic Memory](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Basic%20Kernel/Memory%20Management/Dynamic%20Memory)** + + diff --git a/website/docs/extras/en/device-dev/kernel/kernel-mini-basic.md b/website/docs/extras/en/device-dev/kernel/kernel-mini-basic.md new file mode 100644 index 0000000000000000000000000000000000000000..2bcb15bedb6d947e8319871748132429b33e9fa6 --- /dev/null +++ b/website/docs/extras/en/device-dev/kernel/kernel-mini-basic.md @@ -0,0 +1,30 @@ +--- +title: "kernel-mini-basic" +prepermalink: /extras/ab69393149b0cfdc7adcdb5a1d77bfbf/ +permalink: /extras/ab69393149b0cfdc7adcdb5a1d77bfbf/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/kernel/kernel-mini-basic.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [kernel-mini-basic] +--- +# Basic Kernel + +- **[Interrupt Management](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Basic%20Kernel/Interrupt%20Management)** + +- **[Task Management](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Basic%20Kernel/Task%20Management)** + +- **[Memory Management](/extras/db31368bb5c0a9ae45a89739b4479357/)** + +- **[Kernel Communication Mechanisms](/extras/1549e017f616615c51508ecf0e5ca0a8/)** + +- **[Time Management](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Basic%20Kernel/Time%20Management)** + +- **[Software Timer](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Basic%20Kernel/Software%20Timer)** + + diff --git a/website/docs/extras/en/device-dev/kernel/kernel-mini-debug.md b/website/docs/extras/en/device-dev/kernel/kernel-mini-debug.md new file mode 100644 index 0000000000000000000000000000000000000000..339162d70860053115e2e48e088ef0dcd0b74c87 --- /dev/null +++ b/website/docs/extras/en/device-dev/kernel/kernel-mini-debug.md @@ -0,0 +1,26 @@ +--- +title: "kernel-mini-debug" +prepermalink: /extras/14558de3712212a3527c224592aab031/ +permalink: /extras/14558de3712212a3527c224592aab031/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/kernel/kernel-mini-debug.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [kernel-mini-debug] +--- +# Kernel Debugging + +- **[Memory Debugging](/extras/90db22b9c9eaf74a0cda5222b0b3084e/)** + +- **[Exception Debugging](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Kernel%20Debugging/Exception%20Debugging)** + +- **[Trace](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Kernel%20Debugging/Trace)** + +- **[LMS](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Kernel%20Debugging/LMS)** + + diff --git a/website/docs/extras/en/device-dev/kernel/kernel-mini-extend-file.md b/website/docs/extras/en/device-dev/kernel/kernel-mini-extend-file.md new file mode 100644 index 0000000000000000000000000000000000000000..4e88b8b032d2465dbd2652ee59089efdca7b9128 --- /dev/null +++ b/website/docs/extras/en/device-dev/kernel/kernel-mini-extend-file.md @@ -0,0 +1,219 @@ +--- +title: "kernel-mini-extend-file" +prepermalink: /extras/916e02d6a4d0a19d0fe8f7b4696421cc/ +permalink: /extras/916e02d6a4d0a19d0fe8f7b4696421cc/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/kernel/kernel-mini-extend-file.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [kernel-mini-extend-file] +--- +# File System + +The OpenHarmony LiteOS-M kernel supports File Allocation Table file system \(FATFS\) and LittleFS file systems. Like the OpenHarmony LiteOS-A kernel, the OpenHarmony LiteOS-M kernel provides POSIX over the virtual file system \(VFS\) to ensure interface consistency. However, the VFS of the LiteOS-M kernel is light due to insufficient resources and does not provide advanced functions \(such as pagecache\). Therefore, the VFS of the LiteOS-M kernel implements only API standardization and adaptation. The file systems handle specific transactions. The following table lists the functions supported by the file systems. + +**Table 1** Function list + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Function

+

API

+

Description

+

FATFS

+

LITTLEFS

+

File management

+

open

+

Opens a file.

+

Supported

+

Supported

+

close

+

Closes a file.

+

Supported

+

Supported

+

read

+

Reads a file.

+

Supported

+

Supported

+

write

+

Writes data to a file.

+

Supported

+

Supported

+

lseek

+

Sets the file offset.

+

Supported

+

Supported

+

unlink

+

Deletes a file.

+

Supported

+

Supported

+

rename

+

Renames a file.

+

Supported

+

Supported

+

fstat

+

Obtains file information based on the file handle.

+

Supported

+

Supported

+

stat

+

Obtains file information based on the file path name.

+

Supported

+

Supported

+

fsync

+

Saves file updates to a storage device.

+

Supported

+

Supported

+

Directory management

+

mkdir

+

Creates a directory.

+

Supported

+

Supported

+

opendir

+

Opens a directory.

+

Supported

+

Supported

+

readdir

+

Reads the content of a directory.

+

Supported

+

Supported

+

closedir

+

Closes a directory.

+

Supported

+

Supported

+

rmdir

+

Deletes a directory.

+

Supported

+

Supported

+

Partition management

+

mount

+

Mounts a partition.

+

Supported

+

Supported

+

umount

+

Unmounts a partition.

+

Supported

+

Supported

+

umount2

+

Forcibly unmounts a partition using the MNT_FORCE parameter.

+

Supported

+

Not supported

+

statfs

+

Obtains partition information.

+

Supported

+

Not supported

+
+ +- **[FAT](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Extended%20Components/File%20System/FAT)** + +- **[LittleFS](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Extended%20Components/File%20System/LittleFS)** + + diff --git a/website/docs/extras/en/device-dev/kernel/kernel-mini-extend.md b/website/docs/extras/en/device-dev/kernel/kernel-mini-extend.md new file mode 100644 index 0000000000000000000000000000000000000000..c21ad6b10fc286d1fe8cf82e7d6ddd29a991c434 --- /dev/null +++ b/website/docs/extras/en/device-dev/kernel/kernel-mini-extend.md @@ -0,0 +1,26 @@ +--- +title: "kernel-mini-extend" +prepermalink: /extras/60843d28981ce872ecb65d2c2e96f770/ +permalink: /extras/60843d28981ce872ecb65d2c2e96f770/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/kernel/kernel-mini-extend.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [kernel-mini-extend] +--- +# Extended Components + +- **[C++ Support](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Extended%20Components/C%2B%2B%20Support)** + +- **[CPUP](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Extended%20Components/CPUP)** + +- **[Dynamic Loading](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Extended%20Components/Dynamic%20Loading)** + +- **[File System](/extras/916e02d6a4d0a19d0fe8f7b4696421cc/)** + + diff --git a/website/docs/extras/en/device-dev/kernel/kernel-mini-memory-debug.md b/website/docs/extras/en/device-dev/kernel/kernel-mini-memory-debug.md new file mode 100644 index 0000000000000000000000000000000000000000..a08a0d99ee5512a5e669d0861f52d62c667f480d --- /dev/null +++ b/website/docs/extras/en/device-dev/kernel/kernel-mini-memory-debug.md @@ -0,0 +1,26 @@ +--- +title: "kernel-mini-memory-debug" +prepermalink: /extras/90db22b9c9eaf74a0cda5222b0b3084e/ +permalink: /extras/90db22b9c9eaf74a0cda5222b0b3084e/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/kernel/kernel-mini-memory-debug.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [kernel-mini-memory-debug] +--- +# Memory Debugging + +The purpose of memory debugging is to locate problems related to dynamic memory. The kernel provides a variety of memory debugging methods. Dynamic memory pool statistics helps you learn the memory pool waterline and fragmentation rate. Memory leak check helps you accurately locate the code where memory leak occurs and analyze the memory usage of each module. Memory corruption check helps you locate memory corruptions. + +- **[Memory Information Statistics](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Kernel%20Debugging/Memory%20Debugging/Memory%20Information%20Statistics)** + +- **[Memory Leak Check](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Kernel%20Debugging/Memory%20Debugging/Memory%20Leak%20Check)** + +- **[Memory Corruption Check](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Kernel%20Debugging/Memory%20Debugging/Memory%20Corruption%20Check)** + + diff --git a/website/docs/extras/en/device-dev/kernel/kernel-mini.md b/website/docs/extras/en/device-dev/kernel/kernel-mini.md new file mode 100644 index 0000000000000000000000000000000000000000..2683b25ebbe9ebf96cc3495f9041a87f895eda57 --- /dev/null +++ b/website/docs/extras/en/device-dev/kernel/kernel-mini.md @@ -0,0 +1,28 @@ +--- +title: "kernel-mini" +prepermalink: /extras/bf8496454cb9a8c0712aa081ac032dae/ +permalink: /extras/bf8496454cb9a8c0712aa081ac032dae/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/kernel/kernel-mini.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [kernel-mini] +--- +# Kernel for the Mini System + +- **[Kernel Overview](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Kernel%20Overview)** + +- **[Basic Kernel](/extras/ab69393149b0cfdc7adcdb5a1d77bfbf/)** + +- **[Extended Components](/extras/60843d28981ce872ecb65d2c2e96f770/)** + +- **[Kernel Debugging](/extras/14558de3712212a3527c224592aab031/)** + +- **[Appendix](/extras/4280d4f33ecdf285afb14e29ccbbbd7c/)** + + diff --git a/website/docs/extras/en/device-dev/kernel/kernel-small-apx-structure.md b/website/docs/extras/en/device-dev/kernel/kernel-small-apx-structure.md new file mode 100644 index 0000000000000000000000000000000000000000..0ca6557b8044efda4e8ec976cf2f1cc435b65477 --- /dev/null +++ b/website/docs/extras/en/device-dev/kernel/kernel-small-apx-structure.md @@ -0,0 +1,22 @@ +--- +title: "kernel-small-apx-structure" +prepermalink: /extras/305d42810427764633984b4303f33328/ +permalink: /extras/305d42810427764633984b4303f33328/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/kernel/kernel-small-apx-structure.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [kernel-small-apx-structure] +--- +# Basic Data Structure + +- **[Doubly Linked List](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Appendix/Basic%20Data%20Structure/Doubly%20Linked%20List)** + +- **[Bitwise Operation](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Appendix/Basic%20Data%20Structure/Bitwise%20Operation)** + + diff --git a/website/docs/extras/en/device-dev/kernel/kernel-small-apx.md b/website/docs/extras/en/device-dev/kernel/kernel-small-apx.md new file mode 100644 index 0000000000000000000000000000000000000000..d19d353c7e652c76d700f3398e8143a0971c97c0 --- /dev/null +++ b/website/docs/extras/en/device-dev/kernel/kernel-small-apx.md @@ -0,0 +1,22 @@ +--- +title: "kernel-small-apx" +prepermalink: /extras/a548faed2939a065b131219e2fba3bc0/ +permalink: /extras/a548faed2939a065b131219e2fba3bc0/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/kernel/kernel-small-apx.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [kernel-small-apx] +--- +# Appendix + +- **[Basic Data Structure](/extras/305d42810427764633984b4303f33328/)** + +- **[Standard Library](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Appendix/Standard%20Library)** + + diff --git a/website/docs/extras/en/device-dev/kernel/kernel-small-basic-memory.md b/website/docs/extras/en/device-dev/kernel/kernel-small-basic-memory.md new file mode 100644 index 0000000000000000000000000000000000000000..9c4ad83f022cf158ed8285d7f313824f46115c7a --- /dev/null +++ b/website/docs/extras/en/device-dev/kernel/kernel-small-basic-memory.md @@ -0,0 +1,26 @@ +--- +title: "kernel-small-basic-memory" +prepermalink: /extras/354df90922c0fd497e0ea82dd0345c53/ +permalink: /extras/354df90922c0fd497e0ea82dd0345c53/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/kernel/kernel-small-basic-memory.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [kernel-small-basic-memory] +--- +# Memory Management + +- **[Heap Memory Management](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Memory%20Management/Heap%20Memory%20Management)** + +- **[Physical Memory Management](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Memory%20Management/Physical%20Memory%20Management)** + +- **[Virtual Memory Management](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Memory%20Management/Virtual%20Memory%20Management)** + +- **[Virtual-to-Physical Mapping](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Memory%20Management/Virtual-to-Physical%20Mapping)** + + diff --git a/website/docs/extras/en/device-dev/kernel/kernel-small-basic-process.md b/website/docs/extras/en/device-dev/kernel/kernel-small-basic-process.md new file mode 100644 index 0000000000000000000000000000000000000000..8ec88bb655bcf43f43563b54fa6ec3c0ca3bb0fd --- /dev/null +++ b/website/docs/extras/en/device-dev/kernel/kernel-small-basic-process.md @@ -0,0 +1,24 @@ +--- +title: "kernel-small-basic-process" +prepermalink: /extras/980e1da9bf8cae80e2871575b44ae371/ +permalink: /extras/980e1da9bf8cae80e2871575b44ae371/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/kernel/kernel-small-basic-process.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [kernel-small-basic-process] +--- +# Process Management + +- **[Process](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Process%20Management/Process)** + +- **[Task](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Process%20Management/Task)** + +- **[Scheduler](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Process%20Management/Scheduler)** + + diff --git a/website/docs/extras/en/device-dev/kernel/kernel-small-basic-trans.md b/website/docs/extras/en/device-dev/kernel/kernel-small-basic-trans.md new file mode 100644 index 0000000000000000000000000000000000000000..2dd6fdfba6807ecf09721bd8e93338b683683935 --- /dev/null +++ b/website/docs/extras/en/device-dev/kernel/kernel-small-basic-trans.md @@ -0,0 +1,32 @@ +--- +title: "kernel-small-basic-trans" +prepermalink: /extras/52f81c016abf09fffa3d9efb6c6d88e2/ +permalink: /extras/52f81c016abf09fffa3d9efb6c6d88e2/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/kernel/kernel-small-basic-trans.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [kernel-small-basic-trans] +--- +# Kernel Communication Mechanisms + +- **[Event](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Kernel%20Communication%20Mechanisms/Event)** + +- **[Semaphore](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Kernel%20Communication%20Mechanisms/Semaphore)** + +- **[Mutex](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Kernel%20Communication%20Mechanisms/Mutex)** + +- **[Queue](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Kernel%20Communication%20Mechanisms/Queue)** + +- **[RW Lock](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Kernel%20Communication%20Mechanisms/RW%20Lock)** + +- **[Futex](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Kernel%20Communication%20Mechanisms/Futex)** + +- **[Signal](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Kernel%20Communication%20Mechanisms/Signal)** + + diff --git a/website/docs/extras/en/device-dev/kernel/kernel-small-basics.md b/website/docs/extras/en/device-dev/kernel/kernel-small-basics.md new file mode 100644 index 0000000000000000000000000000000000000000..78fe7ac55e09bbe4506793a6dc8409851039f4d3 --- /dev/null +++ b/website/docs/extras/en/device-dev/kernel/kernel-small-basics.md @@ -0,0 +1,32 @@ +--- +title: "kernel-small-basics" +prepermalink: /extras/78ec94b49b111be049b66228f0df7d34/ +permalink: /extras/78ec94b49b111be049b66228f0df7d34/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/kernel/kernel-small-basics.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [kernel-small-basics] +--- +# Basic Kernel + +- **[Interrupt and Exception Handling](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Interrupt%20and%20Exception%20Handling)** + +- **[Process Management](/extras/980e1da9bf8cae80e2871575b44ae371/)** + +- **[Memory Management](/extras/354df90922c0fd497e0ea82dd0345c53/)** + +- **[Kernel Communication Mechanisms](/extras/52f81c016abf09fffa3d9efb6c6d88e2/)** + +- **[Time Management](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Time%20Management)** + +- **[Software Timer](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Software%20Timer)** + +- **[Atomic Operation](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Atomic%20Operation)** + + diff --git a/website/docs/extras/en/device-dev/kernel/kernel-small-bundles-fs-support.md b/website/docs/extras/en/device-dev/kernel/kernel-small-bundles-fs-support.md new file mode 100644 index 0000000000000000000000000000000000000000..747b0566acf119c4f7a221936b0a17fb0e1e0705 --- /dev/null +++ b/website/docs/extras/en/device-dev/kernel/kernel-small-bundles-fs-support.md @@ -0,0 +1,28 @@ +--- +title: "kernel-small-bundles-fs-support" +prepermalink: /extras/92e1896e294ca006a04935bc511e4a43/ +permalink: /extras/92e1896e294ca006a04935bc511e4a43/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/kernel/kernel-small-bundles-fs-support.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [kernel-small-bundles-fs-support] +--- +# Supported File Systems + +- **[FAT](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Extension%20Components/File%20Systems/Supported%20File%20Systems/FAT)** + +- **[JFFS2](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Extension%20Components/File%20Systems/Supported%20File%20Systems/JFFS2)** + +- **[NFS](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Extension%20Components/File%20Systems/Supported%20File%20Systems/NFS)** + +- **[Ramfs](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Extension%20Components/File%20Systems/Supported%20File%20Systems/Ramfs)** + +- **[procfs](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Extension%20Components/File%20Systems/Supported%20File%20Systems/procfs)** + + diff --git a/website/docs/extras/en/device-dev/kernel/kernel-small-bundles-fs.md b/website/docs/extras/en/device-dev/kernel/kernel-small-bundles-fs.md new file mode 100644 index 0000000000000000000000000000000000000000..2839890e9d28c9a15a3fe39457c30c9b7ed3c254 --- /dev/null +++ b/website/docs/extras/en/device-dev/kernel/kernel-small-bundles-fs.md @@ -0,0 +1,31 @@ +--- +title: "kernel-small-bundles-fs" +prepermalink: /extras/1cf17f18bff1bfb4d5dfa620acb63acb/ +permalink: /extras/1cf17f18bff1bfb4d5dfa620acb63acb/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/kernel/kernel-small-bundles-fs.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [kernel-small-bundles-fs] +--- +# File Systems + +A file system \(often abbreviated to FS\) provides an input and output manner for an OS. It implements the interaction with internal and external storage devices. + +The file system provides standard POSIX operation APIs for the upper-layer system through the C library. For details, see the API reference of the C library. The Virtual File System \(VFS\) layer in kernel mode shields the differences between file systems. The basic architecture is as follows: + +**Figure 1** Overall file system architecture +![](../../../../images/en/device-dev/kernel/figures/5abb9f520b243fc6d6d501287cc18ddc.png "overall-file-system-architecture") + +- **[Virtual File System](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Extension%20Components/File%20Systems/Virtual%20File%20System)** + +- **[Supported File Systems](/extras/92e1896e294ca006a04935bc511e4a43/)** + +- **[File System Adaptation](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Extension%20Components/File%20Systems/File%20System%20Adaptation)** + + diff --git a/website/docs/extras/en/device-dev/kernel/kernel-small-bundles.md b/website/docs/extras/en/device-dev/kernel/kernel-small-bundles.md new file mode 100644 index 0000000000000000000000000000000000000000..b53de7ac66cafa498d5b3d2330c2706babc930ce --- /dev/null +++ b/website/docs/extras/en/device-dev/kernel/kernel-small-bundles.md @@ -0,0 +1,28 @@ +--- +title: "kernel-small-bundles" +prepermalink: /extras/f7b390a50a5516e394c1ef54968ab731/ +permalink: /extras/f7b390a50a5516e394c1ef54968ab731/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/kernel/kernel-small-bundles.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [kernel-small-bundles] +--- +# Extended Components + +- **[System Call](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Extension%20Components/System%20Call)** + +- **[Dynamic Loading and Linking](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Extension%20Components/Dynamic%20Loading%20and%20Linking)** + +- **[Virtual Dynamic Shared Object](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Extension%20Components/Virtual%20Dynamic%20Shared%20Object)** + +- **[LiteIPC](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Extension%20Components/LiteIPC)** + +- **[File Systems](/extras/1cf17f18bff1bfb4d5dfa620acb63acb/)** + + diff --git a/website/docs/extras/en/device-dev/kernel/kernel-small-debug-memory.md b/website/docs/extras/en/device-dev/kernel/kernel-small-debug-memory.md new file mode 100644 index 0000000000000000000000000000000000000000..cf5690b615014410cd9084770c7c4e6491a3c668 --- /dev/null +++ b/website/docs/extras/en/device-dev/kernel/kernel-small-debug-memory.md @@ -0,0 +1,24 @@ +--- +title: "kernel-small-debug-memory" +prepermalink: /extras/b94151258cef10457175c738baf57967/ +permalink: /extras/b94151258cef10457175c738baf57967/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/kernel/kernel-small-debug-memory.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [kernel-small-debug-memory] +--- +# Kernel-Mode Memory Debugging + +- **[Memory Information Statistics](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Memory%20Debugging/Memory%20Information%20Statistics)** + +- **[Memory Leak Check](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Memory%20Debugging/Memory%20Leak%20Check)** + +- **[Memory Corruption Check](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Memory%20Debugging/Memory%20Corruption%20Check)** + + diff --git a/website/docs/extras/en/device-dev/kernel/kernel-small-debug-other.md b/website/docs/extras/en/device-dev/kernel/kernel-small-debug-other.md new file mode 100644 index 0000000000000000000000000000000000000000..463649f08270c37ceac171abbe301c074077be27 --- /dev/null +++ b/website/docs/extras/en/device-dev/kernel/kernel-small-debug-other.md @@ -0,0 +1,22 @@ +--- +title: "kernel-small-debug-other" +prepermalink: /extras/25c92d52997655b370d21851b5a2cf1e/ +permalink: /extras/25c92d52997655b370d21851b5a2cf1e/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/kernel/kernel-small-debug-other.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [kernel-small-debug-other] +--- +# Other Kernel Debugging Methods + +- **[Dying Gasp](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Other%20Kernel%20Debugging%20Methods/Dying%20Gasp)** + +- **[Common Fault Locating Methods](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Other%20Kernel%20Debugging%20Methods/Common%20Fault%20Locating%20Methods)** + + diff --git a/website/docs/extras/en/device-dev/kernel/kernel-small-debug-process.md b/website/docs/extras/en/device-dev/kernel/kernel-small-debug-process.md new file mode 100644 index 0000000000000000000000000000000000000000..5465b6f8bd5efc4035d9dd4e93af9739c36bdbb9 --- /dev/null +++ b/website/docs/extras/en/device-dev/kernel/kernel-small-debug-process.md @@ -0,0 +1,20 @@ +--- +title: "kernel-small-debug-process" +prepermalink: /extras/f8a12d5cd04099ccd66f14e3bee9ffd8/ +permalink: /extras/f8a12d5cd04099ccd66f14e3bee9ffd8/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/kernel/kernel-small-debug-process.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [kernel-small-debug-process] +--- +# Process Commissioning + +- **[CPUP](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Process%20Commissioning/CPUP)** + + diff --git a/website/docs/extras/en/device-dev/kernel/kernel-small-debug-shell-cmd-reboot.md b/website/docs/extras/en/device-dev/kernel/kernel-small-debug-shell-cmd-reboot.md new file mode 100644 index 0000000000000000000000000000000000000000..a698914617481497213b0856939b25312ba6e4dc --- /dev/null +++ b/website/docs/extras/en/device-dev/kernel/kernel-small-debug-shell-cmd-reboot.md @@ -0,0 +1,48 @@ +--- +title: "kernel-small-debug-shell-cmd-reboot" +prepermalink: /extras/54dd2d44008a595368787e6cfe3db677/ +permalink: /extras/54dd2d44008a595368787e6cfe3db677/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/kernel/kernel-small-debug-shell-cmd-reboot.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [kernel-small-debug-shell-cmd-reboot] +--- +# reboot + +- [Command Function](#section20643141481314) +- [Syntax](#section1075441721316) +- [Parameters](#section1472810220135) +- [Usage](#section186772414131) +- [Example](#section4764192791314) +- [Output](#section5791253155517) + +## Command Function + +This command is used to restart a device. + +## Syntax + +reboot + +## Parameters + +None + +## Usage + +After the **reboot** command is executed, the device restarts immediately. + +## Example + +reboot + +## Output + +None + diff --git a/website/docs/extras/en/device-dev/kernel/kernel-small-debug-shell-cmd-top.md b/website/docs/extras/en/device-dev/kernel/kernel-small-debug-shell-cmd-top.md new file mode 100644 index 0000000000000000000000000000000000000000..a63f8de9e8212ac3ef2229fdb53d552a65dc8413 --- /dev/null +++ b/website/docs/extras/en/device-dev/kernel/kernel-small-debug-shell-cmd-top.md @@ -0,0 +1,193 @@ +--- +title: "kernel-small-debug-shell-cmd-top" +prepermalink: /extras/d26279999d71b9963902d10494ee9ab4/ +permalink: /extras/d26279999d71b9963902d10494ee9ab4/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/kernel/kernel-small-debug-shell-cmd-top.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [kernel-small-debug-shell-cmd-top] +--- +# top + +- [Command Function](#section20643141481314) +- [Syntax](#section1075441721316) +- [Parameters](#section1472810220135) +- [Usage](#section186772414131) +- [Example](#section4764192791314) +- [Output](#section5791253155517) + +## Command Function + +This command is used to query process and thread information. + +## Syntax + +top \[_-a_\] + +## Parameters + +**Table 1** Parameter description + + + + + + + + + + + + + + + + + + + +

Parameter

+

Description

+

Default Value

+

Value Range

+

--help

+

Displays the parameters supported by the top command.

+

N/A

+
  

-a

+

Displays detailed information.

+

N/A

+
  
+ +## Usage + +If no parameter is specified, this command displays process and thread information of some tasks by default. + +## Example + +Run **top**. + +## Output + +Command output + +``` +OHOS:/$ top + allCpu(%): 4.68 sys, 195.32 idle + PID PPID PGID UID Status VirtualMem ShareMem PhysicalMem CPUUSE10s PName + 1 -1 1 0 Pending 0x33b000 0xbb000 0x4e01c 0.0 init + 2 -1 2 0 Pending 0xd838c0 0 0xd838c0 1.16 KProcess + 3 1 3 7 Pending 0x72e000 0x1a3000 0x1d29dc 0.0 foundation + 4 1 4 8 Pending 0x362000 0xbb000 0x5cc19 0.0 bundle_daemon + 5 1 5 1 Pending 0xdfa000 0x2e7000 0x148a0a 0.0 appspawn + 6 1 6 0 Pending 0x688000 0x137000 0x11c1ba 0.0 media_server + 7 1 7 0 Pending 0x9d2000 0x103000 0xa21f9 0.87 wms_server + 8 1 8 2 Pending 0x1f5000 0x48000 0x462dc 0.0 mksh + 11 1 11 0 Pending 0x4d4000 0x112000 0xe0d9c 0.0 deviceauth_service + 12 1 12 0 Pending 0x34f000 0xbd000 0x51cb3 0.0 sensor_service + 13 1 13 2 Pending 0x34e000 0xb3000 0x5269e 0.0 ai_server + 14 1 14 0 Pending 0x61f000 0x13b000 0x16858b 0.45 softbus_server + 43 8 43 2 Running 0x1d7000 0x3a000 0x1e9f5 0.0 toybox + TID PID Affi CPU Status StackSize WaterLine CPUUSE10s MEMUSE TaskName + 23 1 0x3 -1 Pending 0x3000 0xcf4 0.0 0 init + 1 2 0x1 -1 Pending 0x4000 0x2c4 0.33 0 Swt_Task + 2 2 0x3 -1 Pending 0x4000 0x204 0.0 0 system_wq + 3 2 0x2 -1 Pending 0x4000 0x514 0.75 0 Swt_Task + 4 2 0x3 -1 Pending 0x1000 0x3ac 0.0 0 ResourcesTask + 7 2 0x3 -1 Pending 0x4e20 0xa5c 0.0 0 PlatformWorkerThread + 8 2 0x3 -1 Pending 0x4e20 0xa6c 0.0 0 PlatformWorkerThread + 9 2 0x3 -1 Pending 0x4e20 0xbf4 0.0 0 PlatformWorkerThread + 10 2 0x3 -1 Pending 0x3000 0x4dc 0.0 0 bcache_async_task + 11 2 0x3 -1 PendTime 0x4000 0x3e4 0.5 0 hi_vdec_thread + 12 2 0x3 -1 Pending 0x2710 0x224 0.0 0 LiteOS usb pnp notify handle kt + 13 2 0x3 -1 Pending 0x3000 0x37c 0.0 0 bcache_async_task + 14 2 0x3 -1 Pending 0x4000 0x204 0.0 0 vibrator_queue + 15 2 0x3 -1 Pending 0x20000 0x35c 0.0 0 eth_irq_Task + 16 2 0x3 -1 PendTime 0x2000 0x354 0.0 0 MessageDispatcher + 18 2 0x3 -1 Pending 0x2710 0x200 0.0 0 GPIO_IRQ_TSK_0_4 + 19 2 0x3 -1 Pending 0x4000 0x204 0.0 0 dispWQ + 20 2 0x3 -1 Pending 0x4000 0x204 0.0 0 hdf_sensor_test_work_queue + 21 2 0x3 -1 PendTime 0x6000 0x40c 0.2 0 tcpip_thread + 22 2 0x3 -1 Pending 0x4000 0x36c 0.0 0 SendToSer + 61 2 0x3 -1 Pending 0x4000 0x244 0.0 0 USB_GIANT_Task + 63 2 0x3 -1 Pending 0x4000 0x244 0.0 0 USB_NGIAN_ISOC_Task + 64 2 0x3 -1 Pending 0x4000 0x244 0.0 0 USB_NGIAN_BULK_TasK +``` + +**Table 2** Output description + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Parameter

+

Description

+

PID

+

Process ID

+

PPID

+

Parent process ID

+

PGID

+

Process group ID

+

UID

+

User ID

+

Status

+

Current task status

+

CPUUSE10s

+

CPU usage within last 10 seconds

+

PName

+

Process name

+

TID

+

Task ID

+

StackSize

+

Size of the task stack

+

WaterLine

+

Peak value of the stack used

+

MEMUSE

+

Memory usage

+

TaskName

+

Task name

+
+ diff --git a/website/docs/extras/en/device-dev/kernel/kernel-small-debug-shell-cmd.md b/website/docs/extras/en/device-dev/kernel/kernel-small-debug-shell-cmd.md new file mode 100644 index 0000000000000000000000000000000000000000..9b0eec489de2a87969c860e947ae9004aa82868d --- /dev/null +++ b/website/docs/extras/en/device-dev/kernel/kernel-small-debug-shell-cmd.md @@ -0,0 +1,66 @@ +--- +title: "kernel-small-debug-shell-cmd" +prepermalink: /extras/7ad916f43aaaf9889b12d59877c01f3b/ +permalink: /extras/7ad916f43aaaf9889b12d59877c01f3b/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/kernel/kernel-small-debug-shell-cmd.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [kernel-small-debug-shell-cmd] +--- +# System Commands + +- **[cpup](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/cpup)** + +- **[date](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/date)** + +- **[dmesg](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/dmesg)** + +- **[exec](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/exec)** + +- **[free](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/free)** + +- **[help](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/help)** + +- **[hwi](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/hwi)** + +- **[kill](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/kill)** + +- **[log](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/log)** + +- **[memcheck](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/memcheck)** + +- **[oom](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/oom)** + +- **[pmm](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/pmm)** + +- **[reset](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/reset)** + +- **[sem](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/sem)** + +- **[stack](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/stack)** + +- **[su](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/su)** + +- **[swtmr](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/swtmr)** + +- **[systeminfo](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/systeminfo)** + +- **[task](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/task)** + +- **[uname](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/uname)** + +- **[vmm](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/vmm)** + +- **[watch](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/watch)** + +- **[reboot](/extras/54dd2d44008a595368787e6cfe3db677/)** + +- **[top](/extras/d26279999d71b9963902d10494ee9ab4/)** + + diff --git a/website/docs/extras/en/device-dev/kernel/kernel-small-debug-shell-details.md b/website/docs/extras/en/device-dev/kernel/kernel-small-debug-shell-details.md new file mode 100644 index 0000000000000000000000000000000000000000..1d1cff3f9aabedd678f603745bcc003f4a1a3b15 --- /dev/null +++ b/website/docs/extras/en/device-dev/kernel/kernel-small-debug-shell-details.md @@ -0,0 +1,28 @@ +--- +title: "kernel-small-debug-shell-details" +prepermalink: /extras/f9baf32e9301d3bbcde624cf8ede20f3/ +permalink: /extras/f9baf32e9301d3bbcde624cf8ede20f3/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/kernel/kernel-small-debug-shell-details.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [kernel-small-debug-shell-details] +--- +# Shell Command Reference + +This chapter describes the functions, syntax, parameter ranges, usage, and examples of key system commands. + +For details about the commands that are not described in this document, see the output of the [help](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/help) command. You can also use the **-h | --help** option of a command to view the help information about the command. + +- **[System Commands](/extras/7ad916f43aaaf9889b12d59877c01f3b/)** + +- **[File Commands](/extras/9102c912c33a6e25d8ccd8f508fa120e/)** + +- **[Network Commands](/extras/dcf839d6c3fe6cd028f71510e9f91807/)** + + diff --git a/website/docs/extras/en/device-dev/kernel/kernel-small-debug-shell-file-du.md b/website/docs/extras/en/device-dev/kernel/kernel-small-debug-shell-file-du.md new file mode 100644 index 0000000000000000000000000000000000000000..1cbe09fc15528232c56e8023345f99bad69bbd17 --- /dev/null +++ b/website/docs/extras/en/device-dev/kernel/kernel-small-debug-shell-file-du.md @@ -0,0 +1,108 @@ +--- +title: "kernel-small-debug-shell-file-du" +prepermalink: /extras/2e611c6efd7ba72eb515a7e1256f6cfa/ +permalink: /extras/2e611c6efd7ba72eb515a7e1256f6cfa/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/kernel/kernel-small-debug-shell-file-du.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [kernel-small-debug-shell-file-du] +--- +# du + +- [Command Function](#section201149459368) +- [Syntax](#section579813484364) +- [Parameters](#section168065311366) +- [Usage](#section19190125723612) +- [Example](#section10383416372) +- [Output](#section16633113552815) + +## Command Function + +This command is used to query the disk space occupied by a file. + +## Syntax + +du \[_-kKmh_\] \[_file..._\] + +## Parameters + +**Table 1** Parameter description + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Parameter

+

Description

+

Value Range

+

--help

+

Displays the parameters supported by the du command.

+

N/A

+

-k

+

Displays the occupied blocks, each of which is 1024 bytes by default.

+

N/A

+

-K

+

Displays the occupied blocks, each of which is 512 bytes (POSIX).

+

N/A

+

-m

+

Displays the disk space in MB.

+

N/A

+

-h

+

Displays the disk space in human-readable format K, M, and G, for example, 1K, 243M, or 2G.

+

N/A

+

file

+

Specifies the target file.

+

N/A

+
+ +## Usage + +- The **du** command is used to obtain the disk usage of a file rather than a directory. +- The value of **file** must be the file name. It cannot contain the directory where the file is located. + +## Example + +Run **du -h testfile**. + +## Output + +Command output + +``` +OHOS:/$ du -h testfile +1.8K testfile +``` + diff --git a/website/docs/extras/en/device-dev/kernel/kernel-small-debug-shell-file-mv.md b/website/docs/extras/en/device-dev/kernel/kernel-small-debug-shell-file-mv.md new file mode 100644 index 0000000000000000000000000000000000000000..b2a24e98c0cf685ba74fc284b11179bd5b0f0ad4 --- /dev/null +++ b/website/docs/extras/en/device-dev/kernel/kernel-small-debug-shell-file-mv.md @@ -0,0 +1,149 @@ +--- +title: "kernel-small-debug-shell-file-mv" +prepermalink: /extras/676cab357201d7eb138cd21f92a2a0df/ +permalink: /extras/676cab357201d7eb138cd21f92a2a0df/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/kernel/kernel-small-debug-shell-file-mv.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [kernel-small-debug-shell-file-mv] +--- +# mv + +- [Command Function](#section201149459368) +- [Syntax](#section579813484364) +- [Parameters](#section168065311366) +- [Usage](#section19190125723612) +- [Example](#section10383416372) +- [Output](#section131601649114511) + +## Command Function + +This command is used to move files. + +## Syntax + +mv \[_-fivn_\] _SOURCE... DEST_ + +## Parameters + +**Table 1** Parameter description + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Parameter

+

Description

+

Value Range

+

-help

+

Displays help information.

+

N/A

+

-f

+

Forcibly overwrites the target file.

+

N/A

+

-i

+

Provides a prompt before moving a file that would overwrite an existing file. Enter y to overwrite the file or enter n to cancel the operation.

+

N/A

+

-n

+

Do not overwrite any existing file or directory.

+

N/A

+

-v

+

This parameter does not take effect although it is supported by the latest Toybox code.

+

N/A

+

SOURCE

+

Specifies the path of the source file.

+

This command cannot be used to move a directory. It can be used to move multiple files at a time.

+

DEST

+

Specifies the destination file path.

+

Both a directory and a file are supported.

+
+ +## Usage + +- **SOURCE** supports wildcard characters \* and ?. The asterisk \(\*\) indicates any number of characters, and the question mark \(?\) represents a single character. **DEST** does not support wildcard characters. If the specified **SOURCE** matches multiple files, **DEST** must be a directory. +- If **DEST** is a directory, this directory must exist. In this case, the destination file is named after the source file. +- If **DEST** is a file, the directory for this file must exist. +- If the destination file already exists, it will be overwritten. + +## Example + +Run the following commands: + +- mv -i test.txt testpath/ +- mv test?.txt testpath/ \(Move **test3.txt**, **testA.txt**, and **test\_.txt**\) + +## Output + +Example 1: moving a file + +``` +OHOS:/$ touch test.txt +OHOS:/$ mkdir testpath +OHOS:/$ touch testpath/test.txt +OHOS:/$ mv -i test.txt testpath/ +mv: overwrite 'testpath//test.txt' (Y/n):y +OHOS:/$ ls +bin etc proc storage testpath usr +dev lib sdcard system userdata vendor +OHOS:/$ cp testpath/test.txt ./ +OHOS:/$ ls +bin etc proc storage test.txt userdata vendor +dev lib sdcard system testpath usr +OHOS:/$ mv -i test.txt testpath/ +mv: overwrite 'testpath//test.txt' (Y/n):n +OHOS:/$ ls +bin etc proc storage test.txt userdata vendor +dev lib sdcard system testpath usr +``` + +Example 2: moving files using wildcards + +``` +OHOS:/$ ls +bin etc proc storage test.txt testA.txt testpath usr +dev lib sdcard system test3.txt test_.txt userdata vendor +OHOS:/$ mv test?.txt testpath/ +OHOS:/$ ls +bin etc proc storage test.txt userdata vendor +dev lib sdcard system testpath usr +OHOS:/$ ls testpath/ +test.txt test3.txt testA.txt test_.txt +``` + diff --git a/website/docs/extras/en/device-dev/kernel/kernel-small-debug-shell-file.md b/website/docs/extras/en/device-dev/kernel/kernel-small-debug-shell-file.md new file mode 100644 index 0000000000000000000000000000000000000000..bf9a3fd46cfd56c8573eea61f401b4ddb325441f --- /dev/null +++ b/website/docs/extras/en/device-dev/kernel/kernel-small-debug-shell-file.md @@ -0,0 +1,64 @@ +--- +title: "kernel-small-debug-shell-file" +prepermalink: /extras/9102c912c33a6e25d8ccd8f508fa120e/ +permalink: /extras/9102c912c33a6e25d8ccd8f508fa120e/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/kernel/kernel-small-debug-shell-file.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [kernel-small-debug-shell-file] +--- +# File Commands + +- **[cat](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/cat)** + +- **[cd](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/cd)** + +- **[chgrp](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/chgrp)** + +- **[chmod](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/chmod)** + +- **[chown](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/chown)** + +- **[cp](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/cp)** + +- **[format](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/format)** + +- **[ls](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/ls)** + +- **[lsfd](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/lsfd)** + +- **[mkdir](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/mkdir)** + +- **[mount](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/mount)** + +- **[partinfo](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/partinfo)** + +- **[partition](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/partition)** + +- **[pwd](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/pwd)** + +- **[rm](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/rm)** + +- **[rmdir](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/rmdir)** + +- **[statfs](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/statfs)** + +- **[sync](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/sync)** + +- **[touch](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/touch)** + +- **[writeproc](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/writeproc)** + +- **[umount](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/umount)** + +- **[du](/extras/2e611c6efd7ba72eb515a7e1256f6cfa/)** + +- **[mv](/extras/676cab357201d7eb138cd21f92a2a0df/)** + + diff --git a/website/docs/extras/en/device-dev/kernel/kernel-small-debug-shell-net.md b/website/docs/extras/en/device-dev/kernel/kernel-small-debug-shell-net.md new file mode 100644 index 0000000000000000000000000000000000000000..234a20b5d41233c447a26775f16d16250a40e079 --- /dev/null +++ b/website/docs/extras/en/device-dev/kernel/kernel-small-debug-shell-net.md @@ -0,0 +1,38 @@ +--- +title: "kernel-small-debug-shell-net" +prepermalink: /extras/dcf839d6c3fe6cd028f71510e9f91807/ +permalink: /extras/dcf839d6c3fe6cd028f71510e9f91807/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/kernel/kernel-small-debug-shell-net.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [kernel-small-debug-shell-net] +--- +# Network Commands + +- **[arp](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/Network%20Commands/arp)** + +- **[dhclient](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/Network%20Commands/dhclient)** + +- **[ifconfig](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/Network%20Commands/ifconfig)** + +- **[ipdebug](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/Network%20Commands/ipdebug)** + +- **[netstat](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/Network%20Commands/netstat)** + +- **[ntpdate](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/Network%20Commands/ntpdate)** + +- **[ping](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/Network%20Commands/ping)** + +- **[ping6](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/Network%20Commands/ping6)** + +- **[telnet](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/Network%20Commands/telnet)** + +- **[tftp](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/Network%20Commands/tftp)** + + diff --git a/website/docs/extras/en/device-dev/kernel/kernel-small-debug-shell.md b/website/docs/extras/en/device-dev/kernel/kernel-small-debug-shell.md new file mode 100644 index 0000000000000000000000000000000000000000..e7b61a4833e775700591a8c388ea03861869d5d2 --- /dev/null +++ b/website/docs/extras/en/device-dev/kernel/kernel-small-debug-shell.md @@ -0,0 +1,30 @@ +--- +title: "kernel-small-debug-shell" +prepermalink: /extras/de21524a8b147ddd67e0b0411e172c6b/ +permalink: /extras/de21524a8b147ddd67e0b0411e172c6b/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/kernel/kernel-small-debug-shell.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [kernel-small-debug-shell] +--- +# Shell + +- **[Introduction to the Shell](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Introduction%20to%20the%20Shell)** + +- **[Shell Command Development Guidelines](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Development%20Guidelines)** + +- **[Shell Command Programming Example](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Programming%20Example)** + +- **[Shell Command Reference](/extras/f9baf32e9301d3bbcde624cf8ede20f3/)** + +- **[Magic Key](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Magic%20Key)** + +- **[User-Mode Exception Information](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/User-Space%20Exception%20Information)** + + diff --git a/website/docs/extras/en/device-dev/kernel/kernel-small-debug-user-guide-use.md b/website/docs/extras/en/device-dev/kernel/kernel-small-debug-user-guide-use.md new file mode 100644 index 0000000000000000000000000000000000000000..b96cf82f8201cd071196e79984a68e10eaf2cca7 --- /dev/null +++ b/website/docs/extras/en/device-dev/kernel/kernel-small-debug-user-guide-use.md @@ -0,0 +1,32 @@ +--- +title: "kernel-small-debug-user-guide-use" +prepermalink: /extras/611e555638e4ece45d20a3f20e8ec21b/ +permalink: /extras/611e555638e4ece45d20a3f20e8ec21b/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/kernel/kernel-small-debug-user-guide-use.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [kernel-small-debug-user-guide-use] +--- +# How to Use + +By default, the OpenHarmony debug version is compiled when a project is built. The libc library of the debug version has integrated the APIs for memory debugging. You can enable memory debugging as required. + +You can perform heap memory debugging by using either of the following: + +- API: By calling APIs, you can accurately check the heap memory information of a specific code logic segment. However, you have to modify user code. +- CLI: By using the CLI, you do not need to modify user code. However, you cannot accurately check the heap memory information of a specific logic segment. + +>![](../../../../images/en/device-dev/public_sys-resources/ae89e6a5f31e3d03603c1d114c8400cf.gif) **NOTE:** +>After memory debugging is enabled, a heap memory leak check and a heap memory integrity check will be performed by default when a process exits. If memory debugging is disabled, the heap memory statistics, heap memory leak check, and heap memory integrity check cannot be enabled, and there is no response to the calling of any debug API. + +- **[Calling APIs](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/User-Mode%20Memory%20Debugging/Usage/How%20to%20Use/Calling%20APIs)** + +- **[Using the CLI](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/User-Mode%20Memory%20Debugging/Usage/How%20to%20Use/Using%20the%20CLI)** + + diff --git a/website/docs/extras/en/device-dev/kernel/kernel-small-debug-user-guide.md b/website/docs/extras/en/device-dev/kernel/kernel-small-debug-user-guide.md new file mode 100644 index 0000000000000000000000000000000000000000..91cda3a210d784e2e7d133e8b1021fa1731e3303 --- /dev/null +++ b/website/docs/extras/en/device-dev/kernel/kernel-small-debug-user-guide.md @@ -0,0 +1,22 @@ +--- +title: "kernel-small-debug-user-guide" +prepermalink: /extras/2079e670c57611ba785dd3124885dbcc/ +permalink: /extras/2079e670c57611ba785dd3124885dbcc/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/kernel/kernel-small-debug-user-guide.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [kernel-small-debug-user-guide] +--- +# Usage + +- **[API Description](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/User-Mode%20Memory%20Debugging/Usage/API%20Description)** + +- **[How to Use](/extras/611e555638e4ece45d20a3f20e8ec21b/)** + + diff --git a/website/docs/extras/en/device-dev/kernel/kernel-small-debug-user.md b/website/docs/extras/en/device-dev/kernel/kernel-small-debug-user.md new file mode 100644 index 0000000000000000000000000000000000000000..a67a1037375b5236f826668c047241b11bc061d4 --- /dev/null +++ b/website/docs/extras/en/device-dev/kernel/kernel-small-debug-user.md @@ -0,0 +1,26 @@ +--- +title: "kernel-small-debug-user" +prepermalink: /extras/ba464eebba5f11da71c5fbc39ede1874/ +permalink: /extras/ba464eebba5f11da71c5fbc39ede1874/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/kernel/kernel-small-debug-user.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [kernel-small-debug-user] +--- +# User-Mode Memory Debugging + +- **[Basic Concepts](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/User-Mode%20Memory%20Debugging/Basic%20Concepts)** + +- **[Working Principles](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/User-Mode%20Memory%20Debugging/Working%20Principles)** + +- **[Usage](/extras/2079e670c57611ba785dd3124885dbcc/)** + +- **[Typical Memory Problems](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/User-Mode%20Memory%20Debugging/Typical%20Memory%20Problems)** + + diff --git a/website/docs/extras/en/device-dev/kernel/kernel-small-debug.md b/website/docs/extras/en/device-dev/kernel/kernel-small-debug.md new file mode 100644 index 0000000000000000000000000000000000000000..ec8c733fd9b8db2962c7c4c978a0865f76c47285 --- /dev/null +++ b/website/docs/extras/en/device-dev/kernel/kernel-small-debug.md @@ -0,0 +1,34 @@ +--- +title: "kernel-small-debug" +prepermalink: /extras/aed7ed5206f77a2c4e8a99c65cd4ad25/ +permalink: /extras/aed7ed5206f77a2c4e8a99c65cd4ad25/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/kernel/kernel-small-debug.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [kernel-small-debug] +--- +# Debugging and Tools + +- **[Shell](/extras/de21524a8b147ddd67e0b0411e172c6b/)** + +- **[Trace](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Trace)** + +- **[perf](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/perf)** + +- **[LMS](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/LMS)** + +- **[Process Commissioning](/extras/f8a12d5cd04099ccd66f14e3bee9ffd8/)** + +- **[Kernel-Mode Memory Debugging](/extras/b94151258cef10457175c738baf57967/)** + +- **[User-Mode Memory Debugging](/extras/ba464eebba5f11da71c5fbc39ede1874/)** + +- **[Other Kernel Debugging Methods](/extras/25c92d52997655b370d21851b5a2cf1e/)** + + diff --git a/website/docs/extras/en/device-dev/kernel/kernel-small-start.md b/website/docs/extras/en/device-dev/kernel/kernel-small-start.md new file mode 100644 index 0000000000000000000000000000000000000000..9b86bf46765c9307c3cc3498d9fa5438b0ef47f3 --- /dev/null +++ b/website/docs/extras/en/device-dev/kernel/kernel-small-start.md @@ -0,0 +1,22 @@ +--- +title: "kernel-small-start" +prepermalink: /extras/133870a58c9b9fb419b38d9ec1009964/ +permalink: /extras/133870a58c9b9fb419b38d9ec1009964/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/kernel/kernel-small-start.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [kernel-small-start] +--- +# Kernel Startup + +- **[Startup in Kernel Mode](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Kernel%20Startup/Startup%20in%20Kernel%20Space)** + +- **[Startup in User Mode](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Kernel%20Startup/Startup%20in%20User%20Space)** + + diff --git a/website/docs/extras/en/device-dev/kernel/kernel-small.md b/website/docs/extras/en/device-dev/kernel/kernel-small.md new file mode 100644 index 0000000000000000000000000000000000000000..5d9800b50879d3bc89a3f412cf5effb17f22b3f1 --- /dev/null +++ b/website/docs/extras/en/device-dev/kernel/kernel-small.md @@ -0,0 +1,30 @@ +--- +title: "kernel-small" +prepermalink: /extras/b1a8758905970b3469be3718a08589d4/ +permalink: /extras/b1a8758905970b3469be3718a08589d4/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/kernel/kernel-small.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [kernel-small] +--- +# Kernel for the Small System + +- **[Kernel Overview](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Kernel%20Overview)** + +- **[Kernel Startup](/extras/133870a58c9b9fb419b38d9ec1009964/)** + +- **[Basic Kernel](/extras/78ec94b49b111be049b66228f0df7d34/)** + +- **[Extended Components](/extras/f7b390a50a5516e394c1ef54968ab731/)** + +- **[Debugging and Tools](/extras/aed7ed5206f77a2c4e8a99c65cd4ad25/)** + +- **[Appendix](/extras/a548faed2939a065b131219e2fba3bc0/)** + + diff --git a/website/docs/extras/en/device-dev/kernel/kernel-standard.md b/website/docs/extras/en/device-dev/kernel/kernel-standard.md new file mode 100644 index 0000000000000000000000000000000000000000..f75c6e56dbc2535f1f3984088efe97781c4d009c --- /dev/null +++ b/website/docs/extras/en/device-dev/kernel/kernel-standard.md @@ -0,0 +1,24 @@ +--- +title: "kernel-standard" +prepermalink: /extras/6b7b37f37bac90610514997ec2249095/ +permalink: /extras/6b7b37f37bac90610514997ec2249095/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/kernel/kernel-standard.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [kernel-standard] +--- +# Kernel for Standard Systems + +- **[Linux Kernel Overview](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Standard%20Systems/Linux%20Kernel%20Overview)** + +- **[Guidelines for Using Patches on OpenHarmony Development Boards](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Standard%20Systems/Applying%20Patches%20on%20OpenHarmony%20Development%20Boards)** + +- **[Guidelines for Compiling and Building the Linux Kernel](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Standard%20Systems/Guidelines%20for%20Building%20the%20Linux%20Kernel)** + + diff --git a/website/docs/extras/en/device-dev/kernel/kernel.md b/website/docs/extras/en/device-dev/kernel/kernel.md new file mode 100644 index 0000000000000000000000000000000000000000..5670504b20a64320610f52006fb60e4131b3def3 --- /dev/null +++ b/website/docs/extras/en/device-dev/kernel/kernel.md @@ -0,0 +1,24 @@ +--- +title: "kernel" +prepermalink: /extras/b12a0f3d6ade1eddad1d0777c80cf1dc/ +permalink: /extras/b12a0f3d6ade1eddad1d0777c80cf1dc/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/kernel/kernel.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [kernel] +--- +# Kernel + +- **[Kernel for Mini Systems](/extras/bf8496454cb9a8c0712aa081ac032dae/)** + +- **[Kernel for Small Systems](/extras/b1a8758905970b3469be3718a08589d4/)** + +- **[User-Mode Memory Debugging](/extras/ba464eebba5f11da71c5fbc39ede1874/)** + + diff --git a/website/docs/extras/en/device-dev/porting/Readme-EN.md b/website/docs/extras/en/device-dev/porting/Readme-EN.md new file mode 100644 index 0000000000000000000000000000000000000000..c2f2fc4a14ea2ac4ff140ad9b90fadb554c1d1eb --- /dev/null +++ b/website/docs/extras/en/device-dev/porting/Readme-EN.md @@ -0,0 +1,74 @@ +--- +title: "Readme-EN" +prepermalink: /extras/f216d9210cbbfb0dd27125e3a3cfadf7/ +permalink: /extras/f216d9210cbbfb0dd27125e3a3cfadf7/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/porting/Readme-EN.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [Readme-EN] +--- +# Introduction + +OpenHarmony has organized a Special Interest Group (SIG) [SIG_DevBoard](https://gitee.com/openharmony/community/blob/master/sig/sig-devboard/sig_devboard.md) to provide support for third-party development boards. + +Before learning about how to port the code of a development board, take a look at the device classification on OpenHarmony. The porting methods vary according to the device type. + +| Device Type| Hardware Requirement| Supported Kernel| +|---------|-------------|----------------| +| Mini-system devices| Memory > 128 KB| LiteOS-M | +| Small-system devices| Memory > 1 MB, with MMU| LiteOS-A and Linux| +| Standard-system devices| Memory > 128 MB| Linux | + +# Code Preparation + +OpenHarmony has created repositories for vendors in openharmony-sig. To participate in the repository development, you need to use the following method to initialize and download the code. + +```shell +repo init -u https://gitee.com/openharmony-sig/manifest.git -b master -m devboard.xml --no-repo-verify +``` + +The download steps for other resources are the same as those in the mainline version. + +# Porting Procedure + +- [Mini System SoC Porting Guide](/extras/b4177a347580663ec15dd4c5ef19d569/) + - [Porting Preparations](/extras/30d41a46676dd647425216e847bd7f05/) + - [Before You Start](/pages/en/device/device/Porting/Mini%20System%20SoC%20Porting%20Guide/Porting%20Preparations/Before%20You%20Start) + - [Building Adaptation Process](/pages/en/device/device/Porting/Mini%20System%20SoC%20Porting%20Guide/Porting%20Preparations/Building%20Adaptation%20Process) + - [Kernel Porting](/extras/63dc519e859eea247b63c89fa41cd569/) + - [Overview](/pages/en/device/device/Porting/Mini%20System%20SoC%20Porting%20Guide/Kernel%20Porting/Overview) + - [Basic Kernel Adaptation](/pages/en/device/device/Porting/Mini%20System%20SoC%20Porting%20Guide/Kernel%20Porting/Basic%20Kernel%20Adaptation) + - [Kernel Porting Verification](/pages/en/device/device/Porting/Mini%20System%20SoC%20Porting%20Guide/Kernel%20Porting/Kernel%20Porting%20Verification) + - [Board-Level OS Porting](/extras/2152e96f76cf7eb3dac9380001ccfcba/) + - [Overview](/pages/en/device/device/Porting/Mini%20System%20SoC%20Porting%20Guide/Board-Level%20OS%20Porting/Overview) + - [Board-Level Driver Adaptation](/pages/en/device/device/Porting/Mini%20System%20SoC%20Porting%20Guide/Board-Level%20OS%20Porting/Board-Level%20Driver%20Adaptation) + - [Implementation of APIs at the HAL](/pages/en/device/device/Porting/Mini%20System%20SoC%20Porting%20Guide/Board-Level%20OS%20Porting/Implementation%20of%20APIs%20at%20the%20HAL) + - [System Modules](/pages/en/device/device/Porting/Mini%20System%20SoC%20Porting%20Guide/Board-Level%20OS%20Porting/System%20Modules) + - [lwIP Module Adaptation](/pages/en/device/device/Porting/Mini%20System%20SoC%20Porting%20Guide/Board-Level%20OS%20Porting/lwIP%20Module%20Adaptation) + - [Third-party Module Adaptation](/pages/en/device/device/Porting/Mini%20System%20SoC%20Porting%20Guide/Board-Level%20OS%20Porting/Third-party%20Module%20Adaptation) + - [XTS](/pages/en/device/device/Porting/Mini%20System%20SoC%20Porting%20Guide/Board-Level%20OS%20Porting/XTS) + - [FAQ](/pages/en/device/device/Porting/Mini%20System%20SoC%20Porting%20Guide/FAQ) +- [Small System SoC Porting Guide](/extras/c9e561e6c3dae45fda2531abc17abcfa/) + - [Porting Preparations](/extras/806ceb0123439b426dbbd94372a74f59/) + - [Before You Start](/pages/en/device/device/Porting/Small%20System%20SoC%20Porting%20Guide/Porting%20Preparations/Before%20You%20Start) + - [Compilation and Building](/pages/en/device/device/Porting/Small%20System%20SoC%20Porting%20Guide/Porting%20Preparations/Compilation%20and%20Building) + - [Kernel Porting](/extras/5ea32b5795c247d3966abcb74f7b541d/) + - [LiteOS Cortex-A](/pages/en/device/device/Porting/Small%20System%20SoC%20Porting%20Guide/Kernel%20Porting/LiteOS%20Cortex-A) + - [Linux Kernel](/pages/en/device/device/Porting/Small%20System%20SoC%20Porting%20Guide/Kernel%20Porting/Linux%20Kernel) + - [Driver Porting](/extras/3ffaa817fd8921204a5468600e1344cd/) + - [Overview](/pages/en/device/device/Porting/Small%20System%20SoC%20Porting%20Guide/Driver%20Porting/Overview) + - [Platform Driver Porting](/pages/en/device/device/Porting/Small%20System%20SoC%20Porting%20Guide/Driver%20Porting/Platform%20Driver%20Porting) + - [Device Driver Porting](/pages/en/device/device/Porting/Small%20System%20SoC%20Porting%20Guide/Driver%20Porting/Device%20Driver%20Porting) +- Standard System SoC Porting Guide + - [Standard System Porting Guide](/pages/en/device/device/Porting/Standard%20System%20SoC%20Porting%20Guide/Standard%20System%20Porting%20Guide) + - [A Method for Rapidly Porting the OpenHarmony Linux Kernel](/pages/en/device/device/Porting/Standard%20System%20SoC%20Porting%20Guide/A%20Method%20for%20Rapidly%20Porting%20the%20OpenHarmony%20Linux%20Kernel) +- [Third-Party Library Porting Guide for Mini and Small Systems](/extras/9949eaeec6b11b95dd62f95a73f7c4cc/) + - [Overview](/pages/en/device/device/Porting/Third-Party%20Library%20Porting%20Guide%20for%20Mini%20and%20Small%20Systems/Overview) + - [Porting a Library Built Using CMake](/pages/en/device/device/Porting/Third-Party%20Library%20Porting%20Guide%20for%20Mini%20and%20Small%20Systems/Porting%20a%20Library%20Built%20Using%20CMake) + - [Porting a Library Built Using Makefile](/pages/en/device/device/Porting/Third-Party%20Library%20Porting%20Guide%20for%20Mini%20and%20Small%20Systems/Porting%20a%20Library%20Built%20Using%20Makefile) \ No newline at end of file diff --git a/website/docs/extras/en/device-dev/porting/porting-chip-board.md b/website/docs/extras/en/device-dev/porting/porting-chip-board.md new file mode 100644 index 0000000000000000000000000000000000000000..f865becb3e8745f406960d17c26c25fccb309c61 --- /dev/null +++ b/website/docs/extras/en/device-dev/porting/porting-chip-board.md @@ -0,0 +1,32 @@ +--- +title: "porting-chip-board" +prepermalink: /extras/2152e96f76cf7eb3dac9380001ccfcba/ +permalink: /extras/2152e96f76cf7eb3dac9380001ccfcba/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/porting/porting-chip-board.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [porting-chip-board] +--- +# Board-Level OS Porting + +- **[Overview](/pages/en/device/device/Porting/Mini%20System%20SoC%20Porting%20Guide/Board-Level%20OS%20Porting/Overview)** + +- **[Board-Level Driver Adaptation](/pages/en/device/device/Porting/Mini%20System%20SoC%20Porting%20Guide/Board-Level%20OS%20Porting/Board-Level%20Driver%20Adaptation)** + +- **[Implementation of APIs at the HAL](/pages/en/device/device/Porting/Mini%20System%20SoC%20Porting%20Guide/Board-Level%20OS%20Porting/Implementation%20of%20APIs%20at%20the%20HAL)** + +- **[System Modules](/pages/en/device/device/Porting/Mini%20System%20SoC%20Porting%20Guide/Board-Level%20OS%20Porting/System%20Modules)** + +- **[lwIP Module Adaptation](/pages/en/device/device/Porting/Mini%20System%20SoC%20Porting%20Guide/Board-Level%20OS%20Porting/lwIP%20Module%20Adaptation)** + +- **[Third-party Module Adaptation](/pages/en/device/device/Porting/Mini%20System%20SoC%20Porting%20Guide/Board-Level%20OS%20Porting/Third-party%20Module%20Adaptation)** + +- **[XTS](/pages/en/device/device/Porting/Mini%20System%20SoC%20Porting%20Guide/Board-Level%20OS%20Porting/XTS)** + + diff --git a/website/docs/extras/en/device-dev/porting/porting-chip-kernel.md b/website/docs/extras/en/device-dev/porting/porting-chip-kernel.md new file mode 100644 index 0000000000000000000000000000000000000000..236d6d70863194b3f4950423380b390cdb9cb966 --- /dev/null +++ b/website/docs/extras/en/device-dev/porting/porting-chip-kernel.md @@ -0,0 +1,24 @@ +--- +title: "porting-chip-kernel" +prepermalink: /extras/63dc519e859eea247b63c89fa41cd569/ +permalink: /extras/63dc519e859eea247b63c89fa41cd569/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/porting/porting-chip-kernel.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [porting-chip-kernel] +--- +# Kernel Porting + +- **[Overview](/pages/en/device/device/Porting/Mini%20System%20SoC%20Porting%20Guide/Kernel%20Porting/Overview)** + +- **[Basic Kernel Adaptation](/pages/en/device/device/Porting/Mini%20System%20SoC%20Porting%20Guide/Kernel%20Porting/Basic%20Kernel%20Adaptation)** + +- **[Kernel Porting Verification](/pages/en/device/device/Porting/Mini%20System%20SoC%20Porting%20Guide/Kernel%20Porting/Kernel%20Porting%20Verification)** + + diff --git a/website/docs/extras/en/device-dev/porting/porting-chip-prepare.md b/website/docs/extras/en/device-dev/porting/porting-chip-prepare.md new file mode 100644 index 0000000000000000000000000000000000000000..a2ea7c766711884df28e20dd37033f4fb611781c --- /dev/null +++ b/website/docs/extras/en/device-dev/porting/porting-chip-prepare.md @@ -0,0 +1,22 @@ +--- +title: "porting-chip-prepare" +prepermalink: /extras/30d41a46676dd647425216e847bd7f05/ +permalink: /extras/30d41a46676dd647425216e847bd7f05/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/porting/porting-chip-prepare.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [porting-chip-prepare] +--- +# Porting Preparations + +- **[Before You Start](/pages/en/device/device/Porting/Mini%20System%20SoC%20Porting%20Guide/Porting%20Preparations/Before%20You%20Start)** + +- **[Building Adaptation Process](/pages/en/device/device/Porting/Mini%20System%20SoC%20Porting%20Guide/Porting%20Preparations/Building%20Adaptation%20Process)** + + diff --git a/website/docs/extras/en/device-dev/porting/porting-minichip.md b/website/docs/extras/en/device-dev/porting/porting-minichip.md new file mode 100644 index 0000000000000000000000000000000000000000..d49967f3ea777438ac67c9240b55343a169ffc7d --- /dev/null +++ b/website/docs/extras/en/device-dev/porting/porting-minichip.md @@ -0,0 +1,26 @@ +--- +title: "porting-minichip" +prepermalink: /extras/b4177a347580663ec15dd4c5ef19d569/ +permalink: /extras/b4177a347580663ec15dd4c5ef19d569/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/porting/porting-minichip.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [porting-minichip] +--- +# Mini System SoC Porting Guide + +- **[Porting Preparations](/extras/30d41a46676dd647425216e847bd7f05/)** + +- **[Kernel Porting](/extras/63dc519e859eea247b63c89fa41cd569/)** + +- **[Board-Level OS Porting](/extras/2152e96f76cf7eb3dac9380001ccfcba/)** + +- **[FAQ](/pages/en/device/device/Porting/Mini%20System%20SoC%20Porting%20Guide/FAQ)** + + diff --git a/website/docs/extras/en/device-dev/porting/porting-smallchip-driver.md b/website/docs/extras/en/device-dev/porting/porting-smallchip-driver.md new file mode 100644 index 0000000000000000000000000000000000000000..f243b4baad6625c72e1bd3abf42e6c522bb4185e --- /dev/null +++ b/website/docs/extras/en/device-dev/porting/porting-smallchip-driver.md @@ -0,0 +1,24 @@ +--- +title: "porting-smallchip-driver" +prepermalink: /extras/3ffaa817fd8921204a5468600e1344cd/ +permalink: /extras/3ffaa817fd8921204a5468600e1344cd/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/porting/porting-smallchip-driver.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [porting-smallchip-driver] +--- +# Driver Porting + +- **[Overview](/pages/en/device/device/Porting/Small%20System%20SoC%20Porting%20Guide/Driver%20Porting/Overview)** + +- **[Platform Driver Porting](/pages/en/device/device/Porting/Small%20System%20SoC%20Porting%20Guide/Driver%20Porting/Platform%20Driver%20Porting)** + +- **[Device Driver Porting](/pages/en/device/device/Porting/Small%20System%20SoC%20Porting%20Guide/Driver%20Porting/Device%20Driver%20Porting)** + + diff --git a/website/docs/extras/en/device-dev/porting/porting-smallchip-kernel.md b/website/docs/extras/en/device-dev/porting/porting-smallchip-kernel.md new file mode 100644 index 0000000000000000000000000000000000000000..b9a2de72091d23f2f9530c06a52de548e1b719d1 --- /dev/null +++ b/website/docs/extras/en/device-dev/porting/porting-smallchip-kernel.md @@ -0,0 +1,22 @@ +--- +title: "porting-smallchip-kernel" +prepermalink: /extras/5ea32b5795c247d3966abcb74f7b541d/ +permalink: /extras/5ea32b5795c247d3966abcb74f7b541d/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/porting/porting-smallchip-kernel.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [porting-smallchip-kernel] +--- +# Kernel Porting + +- **[LiteOS Cortex-A](/pages/en/device/device/Porting/Small%20System%20SoC%20Porting%20Guide/Kernel%20Porting/LiteOS%20Cortex-A)** + +- **[Linux Kernel](/pages/en/device/device/Porting/Small%20System%20SoC%20Porting%20Guide/Kernel%20Porting/Linux%20Kernel)** + + diff --git a/website/docs/extras/en/device-dev/porting/porting-smallchip-prepare.md b/website/docs/extras/en/device-dev/porting/porting-smallchip-prepare.md new file mode 100644 index 0000000000000000000000000000000000000000..f2f6511db9be9a8658dbd51385f4a3b015df35aa --- /dev/null +++ b/website/docs/extras/en/device-dev/porting/porting-smallchip-prepare.md @@ -0,0 +1,22 @@ +--- +title: "porting-smallchip-prepare" +prepermalink: /extras/806ceb0123439b426dbbd94372a74f59/ +permalink: /extras/806ceb0123439b426dbbd94372a74f59/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/porting/porting-smallchip-prepare.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [porting-smallchip-prepare] +--- +# Porting Preparations + +- **[Before You Start](/pages/en/device/device/Porting/Small%20System%20SoC%20Porting%20Guide/Porting%20Preparations/Before%20You%20Start)** + +- **[Compilation and Building](/pages/en/device/device/Porting/Small%20System%20SoC%20Porting%20Guide/Porting%20Preparations/Compilation%20and%20Building)** + + diff --git a/website/docs/extras/en/device-dev/porting/porting-smallchip.md b/website/docs/extras/en/device-dev/porting/porting-smallchip.md new file mode 100644 index 0000000000000000000000000000000000000000..81904be1afc607b01c45f5699d84da94486d3bfc --- /dev/null +++ b/website/docs/extras/en/device-dev/porting/porting-smallchip.md @@ -0,0 +1,24 @@ +--- +title: "porting-smallchip" +prepermalink: /extras/c9e561e6c3dae45fda2531abc17abcfa/ +permalink: /extras/c9e561e6c3dae45fda2531abc17abcfa/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/porting/porting-smallchip.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [porting-smallchip] +--- +# Small System SoC Porting Guide + +- **[Porting Preparations](/extras/806ceb0123439b426dbbd94372a74f59/)** + +- **[Kernel Porting](/extras/5ea32b5795c247d3966abcb74f7b541d/)** + +- **[Driver Porting](/extras/3ffaa817fd8921204a5468600e1344cd/)** + + diff --git a/website/docs/extras/en/device-dev/porting/porting-thirdparty.md b/website/docs/extras/en/device-dev/porting/porting-thirdparty.md new file mode 100644 index 0000000000000000000000000000000000000000..3edfb14e7efb834a936d1afc60774e9cc0159028 --- /dev/null +++ b/website/docs/extras/en/device-dev/porting/porting-thirdparty.md @@ -0,0 +1,24 @@ +--- +title: "porting-thirdparty" +prepermalink: /extras/9949eaeec6b11b95dd62f95a73f7c4cc/ +permalink: /extras/9949eaeec6b11b95dd62f95a73f7c4cc/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/porting/porting-thirdparty.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [porting-thirdparty] +--- +# Third-Party Library Porting Guide for Mini and Small Systems + +- **[Overview](/pages/en/device/device/Porting/Third-Party%20Library%20Porting%20Guide%20for%20Mini%20and%20Small%20Systems/Overview)** + +- **[Porting a Library Built Using CMake](/pages/en/device/device/Porting/Third-Party%20Library%20Porting%20Guide%20for%20Mini%20and%20Small%20Systems/Porting%20a%20Library%20Built%20Using%20CMake)** + +- **[Porting a Library Built Using Makefile](/pages/en/device/device/Porting/Third-Party%20Library%20Porting%20Guide%20for%20Mini%20and%20Small%20Systems/Porting%20a%20Library%20Built%20Using%20Makefile)** + + diff --git a/website/docs/extras/en/device-dev/porting/porting.md b/website/docs/extras/en/device-dev/porting/porting.md new file mode 100644 index 0000000000000000000000000000000000000000..fb71895589b620decaa9df575fba0203d52d12ac --- /dev/null +++ b/website/docs/extras/en/device-dev/porting/porting.md @@ -0,0 +1,26 @@ +--- +title: "porting" +prepermalink: /extras/5e19ad83e7f3fc0db5d7bec871ecaf66/ +permalink: /extras/5e19ad83e7f3fc0db5d7bec871ecaf66/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/porting/porting.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [porting] +--- +# Porting + +- **[Third-Party Library Porting Guide](/extras/9949eaeec6b11b95dd62f95a73f7c4cc/)** + +- **[Mini System SoC Porting Guide](/extras/b4177a347580663ec15dd4c5ef19d569/)** + +- **[Small System SoC Porting Guide](/extras/c9e561e6c3dae45fda2531abc17abcfa/)** + +- **[Standard System Porting Guide](/pages/en/device/device/Porting/Standard%20System%20SoC%20Porting%20Guide/Standard%20System%20Porting%20Guide)** + + diff --git a/website/docs/extras/en/device-dev/quick-start/Readme-EN.md b/website/docs/extras/en/device-dev/quick-start/Readme-EN.md new file mode 100644 index 0000000000000000000000000000000000000000..c91a2a8ddc6467c27c99916de6c4596a6ee0654a --- /dev/null +++ b/website/docs/extras/en/device-dev/quick-start/Readme-EN.md @@ -0,0 +1,51 @@ +--- +title: "Readme-EN" +prepermalink: /extras/e1b285bd9b4b16964cbfeff3af87c98b/ +permalink: /extras/e1b285bd9b4b16964cbfeff3af87c98b/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/quick-start/Readme-EN.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [Readme-EN] +--- +# Getting Started + +- [Mini and Small Systems](/extras/989355ccbbb782c8a0724811e8302ac3/) + - [Overview](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/Overview) + - [Introduction](/extras/5a0aae350d3fad7fb440ae5df71f0c38/) + - [Hi3861 Development Board](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/Introduction/Hi3861%20Development%20Board) + - [Hi3516 Development Board](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/Introduction/Hi3516%20Development%20Board) + - [Hi3518 Development Board](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/Introduction/Hi3518%20Development%20Board) + - [Environment Setup](/extras/544a7aa48d1a332d56ab6048bbd10528/) + - [Overview](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/Environment%20Setup/Overview) + - [Setting Up Windows Development Environment](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/Environment%20Setup/Setting%20Up%20Windows%20Development%20Environment) + - [Setting Up Ubuntu Development Environment](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/Environment%20Setup/Setting%20Up%20Ubuntu%20Development%20Environment) + - [FAQs](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/Environment%20Setup/FAQs) + - [How to Develop](/extras/34ae1f0033013a2c06c5fcf4f5c141ec/) + - [Hi3861](/extras/529708e9f3bb7a7246247c0d4afb9312/) + - [Setting Up the Environment](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/How%20to%20Develop/Hi3861/Setting%20Up%20the%20Environment) + - [Setting Up WLAN Connection](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/How%20to%20Develop/Hi3861/Setting%20Up%20WLAN%20Connection) + - [Running a Hello World Program](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/How%20to%20Develop/Hi3861/Running%20a%20Hello%20World%20Program) + - [FAQs](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/How%20to%20Develop/Hi3861/FAQs) + - [Hi3516](/extras/6ba34b45d768c1e096a084d67a594b40/) + - [Setting Up the Environment](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/How%20to%20Develop/Hi3516/Setting%20Up%20the%20Environment) + - [Running a Hello OHOS Program](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/How%20to%20Develop/Hi3516/Running%20a%20Hello%20OHOS%20Program) + - [Developing a Driver](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/How%20to%20Develop/Hi3516/Developing%20a%20Driver) + - [FAQs](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/How%20to%20Develop/Hi3516/FAQs) + - [Hi3518](/extras/9eb239088d3db326f6d41989ad891055/) + - [Setting Up the Environment](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/How%20to%20Develop/Hi3518/Setting%20Up%20the%20Environment) + - [Running a Hello OHOS Program](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/How%20to%20Develop/Hi3518/Running%20a%20Hello%20OHOS%20Program) + - [FAQs](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/How%20to%20Develop/Hi3518/FAQs) +- [Standard System](/extras/e0c7fb7adf8f26e1f508dc8bd7bd89c7/) + - [Introduction](/pages/en/device/device/Quick%20Start/Standard%20System/Introduction) + - [Setting Up Windows Development Environment](/pages/en/device/device/Quick%20Start/Standard%20System/Setting%20Up%20Windows%20Development%20Environment) + - [Setting Up Ubuntu Development Environment in Docker Mode](/pages/en/device/device/Quick%20Start/Standard%20System/Setting%20Up%20Ubuntu%20Development%20Environment%20in%20Docker%20Mode) + - [Setting Up Ubuntu Development Environment with Installation Package](/pages/en/device/device/Quick%20Start/Standard%20System/Setting%20Up%20Ubuntu%20Development%20Environment%20with%20Installation%20Package) + - [Burning Images](/pages/en/device/device/Quick%20Start/Standard%20System/Burning%20Images) + - [Running an Image](/pages/en/device/device/Quick%20Start/Standard%20System/Running%20an%20Image) + - [FAQs](/pages/en/device/device/Quick%20Start/Standard%20System/FAQs) \ No newline at end of file diff --git a/website/docs/extras/en/device-dev/quick-start/quickstart-lite-env-setup.md b/website/docs/extras/en/device-dev/quick-start/quickstart-lite-env-setup.md new file mode 100644 index 0000000000000000000000000000000000000000..11d3add716e2bd2b53678ccf29ccaf47b7897ffd --- /dev/null +++ b/website/docs/extras/en/device-dev/quick-start/quickstart-lite-env-setup.md @@ -0,0 +1,26 @@ +--- +title: "quickstart-lite-env-setup" +prepermalink: /extras/544a7aa48d1a332d56ab6048bbd10528/ +permalink: /extras/544a7aa48d1a332d56ab6048bbd10528/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/quick-start/quickstart-lite-env-setup.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [quickstart-lite-env-setup] +--- +# Environment Setup + +- **[Overview](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/Environment%20Setup/Overview)** + +- **[Setting Up Windows Development Environment](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/Environment%20Setup/Setting%20Up%20Windows%20Development%20Environment)** + +- **[Setting Up Ubuntu Development Environment](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/Environment%20Setup/Setting%20Up%20Ubuntu%20Development%20Environment)** + +- **[FAQs](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/Environment%20Setup/FAQs)** + + diff --git a/website/docs/extras/en/device-dev/quick-start/quickstart-lite-introduction.md b/website/docs/extras/en/device-dev/quick-start/quickstart-lite-introduction.md new file mode 100644 index 0000000000000000000000000000000000000000..d4bd5aba417a8ef1d77b41cafd815b6503352e39 --- /dev/null +++ b/website/docs/extras/en/device-dev/quick-start/quickstart-lite-introduction.md @@ -0,0 +1,24 @@ +--- +title: "quickstart-lite-introduction" +prepermalink: /extras/5a0aae350d3fad7fb440ae5df71f0c38/ +permalink: /extras/5a0aae350d3fad7fb440ae5df71f0c38/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/quick-start/quickstart-lite-introduction.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [quickstart-lite-introduction] +--- +# Introduction + +- **[Hi3861 Development Board](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/Introduction/Hi3861%20Development%20Board)** + +- **[Hi3516 Development Board](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/Introduction/Hi3516%20Development%20Board)** + +- **[Hi3518 Development Board](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/Introduction/Hi3518%20Development%20Board)** + + diff --git a/website/docs/extras/en/device-dev/quick-start/quickstart-lite-steps-hi3516.md b/website/docs/extras/en/device-dev/quick-start/quickstart-lite-steps-hi3516.md new file mode 100644 index 0000000000000000000000000000000000000000..0168e6335aedd75e399b0b6086cc4d977c6ede64 --- /dev/null +++ b/website/docs/extras/en/device-dev/quick-start/quickstart-lite-steps-hi3516.md @@ -0,0 +1,26 @@ +--- +title: "quickstart-lite-steps-hi3516" +prepermalink: /extras/6ba34b45d768c1e096a084d67a594b40/ +permalink: /extras/6ba34b45d768c1e096a084d67a594b40/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/quick-start/quickstart-lite-steps-hi3516.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [quickstart-lite-steps-hi3516] +--- +# Hi3516 + +- **[Setting Up the Environment](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/How%20to%20Develop/Hi3516/Setting%20Up%20the%20Environment)** + +- **[Running a Hello OHOS Program](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/How%20to%20Develop/Hi3516/Running%20a%20Hello%20OHOS%20Program)** + +- **[Developing a Driver](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/How%20to%20Develop/Hi3516/Developing%20a%20Driver)** + +- **[FAQs](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/How%20to%20Develop/Hi3516/FAQs)** + + diff --git a/website/docs/extras/en/device-dev/quick-start/quickstart-lite-steps-hi3518.md b/website/docs/extras/en/device-dev/quick-start/quickstart-lite-steps-hi3518.md new file mode 100644 index 0000000000000000000000000000000000000000..870196fb9e7adca9fb113e50bb0efe069947d9df --- /dev/null +++ b/website/docs/extras/en/device-dev/quick-start/quickstart-lite-steps-hi3518.md @@ -0,0 +1,24 @@ +--- +title: "quickstart-lite-steps-hi3518" +prepermalink: /extras/9eb239088d3db326f6d41989ad891055/ +permalink: /extras/9eb239088d3db326f6d41989ad891055/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/quick-start/quickstart-lite-steps-hi3518.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [quickstart-lite-steps-hi3518] +--- +# Hi3518 + +- **[Setting Up the Environment](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/How%20to%20Develop/Hi3518/Setting%20Up%20the%20Environment)** + +- **[Running a Hello OHOS Program](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/How%20to%20Develop/Hi3518/Running%20a%20Hello%20OHOS%20Program)** + +- **[FAQs](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/How%20to%20Develop/Hi3518/FAQs)** + + diff --git a/website/docs/extras/en/device-dev/quick-start/quickstart-lite-steps-hi3861.md b/website/docs/extras/en/device-dev/quick-start/quickstart-lite-steps-hi3861.md new file mode 100644 index 0000000000000000000000000000000000000000..71d6cffa8dcdc4241d4bac34698078e5a64a063b --- /dev/null +++ b/website/docs/extras/en/device-dev/quick-start/quickstart-lite-steps-hi3861.md @@ -0,0 +1,26 @@ +--- +title: "quickstart-lite-steps-hi3861" +prepermalink: /extras/529708e9f3bb7a7246247c0d4afb9312/ +permalink: /extras/529708e9f3bb7a7246247c0d4afb9312/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/quick-start/quickstart-lite-steps-hi3861.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [quickstart-lite-steps-hi3861] +--- +# Hi3861 + +- **[Setting Up the Environment](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/How%20to%20Develop/Hi3861/Setting%20Up%20the%20Environment)** + +- **[Setting Up WLAN Connection](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/How%20to%20Develop/Hi3861/Setting%20Up%20WLAN%20Connection)** + +- **[Running a Hello World Program](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/How%20to%20Develop/Hi3861/Running%20a%20Hello%20World%20Program)** + +- **[FAQs](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/How%20to%20Develop/Hi3861/FAQs)** + + diff --git a/website/docs/extras/en/device-dev/quick-start/quickstart-lite-steps.md b/website/docs/extras/en/device-dev/quick-start/quickstart-lite-steps.md new file mode 100644 index 0000000000000000000000000000000000000000..becde1e79c3fd40772c2a02184ec87d1bddf2441 --- /dev/null +++ b/website/docs/extras/en/device-dev/quick-start/quickstart-lite-steps.md @@ -0,0 +1,24 @@ +--- +title: "quickstart-lite-steps" +prepermalink: /extras/34ae1f0033013a2c06c5fcf4f5c141ec/ +permalink: /extras/34ae1f0033013a2c06c5fcf4f5c141ec/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/quick-start/quickstart-lite-steps.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [quickstart-lite-steps] +--- +# How to Develop + +- **[Hi3861](/extras/529708e9f3bb7a7246247c0d4afb9312/)** + +- **[Hi3516](/extras/6ba34b45d768c1e096a084d67a594b40/)** + +- **[Hi3518](/extras/9eb239088d3db326f6d41989ad891055/)** + + diff --git a/website/docs/extras/en/device-dev/quick-start/quickstart-lite.md b/website/docs/extras/en/device-dev/quick-start/quickstart-lite.md new file mode 100644 index 0000000000000000000000000000000000000000..ec8dc5547090d8756f6179aac938b7557e805c39 --- /dev/null +++ b/website/docs/extras/en/device-dev/quick-start/quickstart-lite.md @@ -0,0 +1,26 @@ +--- +title: "quickstart-lite" +prepermalink: /extras/989355ccbbb782c8a0724811e8302ac3/ +permalink: /extras/989355ccbbb782c8a0724811e8302ac3/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/quick-start/quickstart-lite.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [quickstart-lite] +--- +# Mini and Small Systems + +- **[Overview](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/Overview)** + +- **[Introduction](/extras/5a0aae350d3fad7fb440ae5df71f0c38/)** + +- **[Environment Setup](/extras/544a7aa48d1a332d56ab6048bbd10528/)** + +- **[How to Develop](/extras/34ae1f0033013a2c06c5fcf4f5c141ec/)** + + diff --git a/website/docs/extras/en/device-dev/quick-start/quickstart-standard.md b/website/docs/extras/en/device-dev/quick-start/quickstart-standard.md new file mode 100644 index 0000000000000000000000000000000000000000..d450b5d893a1f3c3a8743363e627582c75de6fe9 --- /dev/null +++ b/website/docs/extras/en/device-dev/quick-start/quickstart-standard.md @@ -0,0 +1,32 @@ +--- +title: "quickstart-standard" +prepermalink: /extras/e0c7fb7adf8f26e1f508dc8bd7bd89c7/ +permalink: /extras/e0c7fb7adf8f26e1f508dc8bd7bd89c7/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/quick-start/quickstart-standard.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [quickstart-standard] +--- +# Standard System + +- **[Introduction](/pages/en/device/device/Quick%20Start/Standard%20System/Introduction)** + +- **[Setting Up a Windows Development Environment](/pages/en/device/device/Quick%20Start/Standard%20System/Setting%20Up%20Windows%20Development%20Environment)** + +- **[Setting Up a Ubuntu Development Environment in Docker Mode](/pages/en/device/device/Quick%20Start/Standard%20System/Setting%20Up%20Ubuntu%20Development%20Environment%20in%20Docker%20Mode)** + +- **[Setting Up a Ubuntu Development Environment Using the Installation Package](/pages/en/device/device/Quick%20Start/Standard%20System/Setting%20Up%20Ubuntu%20Development%20Environment%20with%20Installation%20Package)** + +- **[Burning Images](/pages/en/device/device/Quick%20Start/Standard%20System/Burning%20Images)** + +- **[Running an Image](/pages/en/device/device/Quick%20Start/Standard%20System/Running%20an%20Image)** + +- **[FAQs](/pages/en/device/device/Quick%20Start/Standard%20System/FAQs)** + + diff --git a/website/docs/extras/en/device-dev/quick-start/quickstart.md b/website/docs/extras/en/device-dev/quick-start/quickstart.md new file mode 100644 index 0000000000000000000000000000000000000000..a466ef4460bbf6deeee1ea8238ae4953d9fcfaad --- /dev/null +++ b/website/docs/extras/en/device-dev/quick-start/quickstart.md @@ -0,0 +1,22 @@ +--- +title: "quickstart" +prepermalink: /extras/b67fcbb4cfe645ff3325eb862f9a4520/ +permalink: /extras/b67fcbb4cfe645ff3325eb862f9a4520/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/quick-start/quickstart.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [quickstart] +--- +# Getting Started + +- **[Mini and Small Systems](/extras/989355ccbbb782c8a0724811e8302ac3/)** + +- **[Standard System](/extras/e0c7fb7adf8f26e1f508dc8bd7bd89c7/)** + + diff --git a/website/docs/extras/en/device-dev/security/Readme-EN.md b/website/docs/extras/en/device-dev/security/Readme-EN.md new file mode 100644 index 0000000000000000000000000000000000000000..e9680759d0fc926d7c1bf080a9cf0250d37a0b66 --- /dev/null +++ b/website/docs/extras/en/device-dev/security/Readme-EN.md @@ -0,0 +1,20 @@ +--- +title: "Readme-EN" +prepermalink: /extras/f6ea01c30c3dafebebd15b2f9d77896c/ +permalink: /extras/f6ea01c30c3dafebebd15b2f9d77896c/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/security/Readme-EN.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [Readme-EN] +--- +# Privacy and Security + +- [Privacy Protection](/pages/en/device/device/Compatibility%20and%20Security/Privacy%20Protection) +- [Security Guidelines](/pages/en/device/device/Compatibility%20and%20Security/Security%20Guidelines) + diff --git a/website/docs/extras/en/device-dev/security/security.md b/website/docs/extras/en/device-dev/security/security.md new file mode 100644 index 0000000000000000000000000000000000000000..0c6f2db73d7c101e5da0bc70d25d4edb5d2ca55d --- /dev/null +++ b/website/docs/extras/en/device-dev/security/security.md @@ -0,0 +1,22 @@ +--- +title: "security" +prepermalink: /extras/51f8b09faccbde106b8a01c390e8acc7/ +permalink: /extras/51f8b09faccbde106b8a01c390e8acc7/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/security/security.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [security] +--- +# Privacy and Security + +- **[Privacy Protection](/pages/en/device/device/Compatibility%20and%20Security/Privacy%20Protection)** + +- **[Security Guidelines](/pages/en/device/device/Compatibility%20and%20Security/Security%20Guidelines)** + + diff --git a/website/docs/extras/en/device-dev/subsystems/Readme-EN.md b/website/docs/extras/en/device-dev/subsystems/Readme-EN.md new file mode 100644 index 0000000000000000000000000000000000000000..b1b1b80dd543449632ee9999e8fa090a1e0014af --- /dev/null +++ b/website/docs/extras/en/device-dev/subsystems/Readme-EN.md @@ -0,0 +1,113 @@ +--- +title: "Readme-EN" +prepermalink: /extras/d48e6372e0564ee89020c61c997fe13a/ +permalink: /extras/d48e6372e0564ee89020c61c997fe13a/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/subsystems/Readme-EN.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [Readme-EN] +--- +# Subsystems + +- [Compilation and Building](/extras/2ce98dbc2719223219b20eb0f7d00e31/) + - [Building Guidelines for Mini and Small Systems](/pages/en/device/device/Subsystem%20Development/Compilation%20and%20Building/Building%20Guidelines%20for%20Mini%20and%20Small%20Systems) + - [Building Guidelines for Standard Systems](/pages/en/device/device/Subsystem%20Development/Compilation%20and%20Building/Building%20Guidelines%20for%20Standard%20Systems) + - [Build System Coding Specifications and Best Practices](/pages/en/device/device/Subsystem%20Development/Compilation%20and%20Building/Build%20System%20Coding%20Specifications%20and%20Best%20Practices) + - [Building the Kconfig Visual Configuration](/pages/en/device/device/Subsystem%20Development/Compilation%20and%20Building/Building%20the%20Kconfig%20Visual%20Configuration) +- [Distributed Remote Startup](/pages/en/device/device/Subsystem%20Development/Distributed%20Remote%20Startup) +- [Graphics](/extras/c0ebe908e23b0532ab29175059c8af86/) + - [Graphics](/pages/en/device/device/Subsystem%20Development/Graphics/Graphics) + - [Development Guidelines on Container Components](/pages/en/device/device/Subsystem%20Development/Graphics/Development%20Guidelines%20on%20Container%20Components) + - [Development Guidelines on Layout Container Components](/pages/en/device/device/Subsystem%20Development/Graphics/Development%20Guidelines%20on%20Layout%20Container%20Components) + - [Development Guidelines on Common Components](/pages/en/device/device/Subsystem%20Development/Graphics/Development%20Guidelines%20on%20Common%20Components) + - [Development Guidelines on Animators](/pages/en/device/device/Subsystem%20Development/Graphics/Development%20Guidelines%20on%20Animators) +- [Multimedia](/extras/b47c31807da4c3c1d56185bd379d1d88/) + - [Camera](/extras/022683ace7aa7b9476c708f21b6233be/) + - [Overview](/pages/en/device/device/Subsystem%20Development/Multimedia/Camera/Overview) + - [Development Guidelines on Photographing](/pages/en/device/device/Subsystem%20Development/Multimedia/Camera/Development%20Guidelines%20on%20Photographing) + - [Development Guidelines on Video Recording](/pages/en/device/device/Subsystem%20Development/Multimedia/Camera/Development%20Guidelines%20on%20Video%20Recording) + - [Development Guidelines on Previewing](/pages/en/device/device/Subsystem%20Development/Multimedia/Camera/Development%20Guidelines%20on%20Previewing) + - [Audio/Video](/extras/ab459733feb658557f68b92fb3a3c5d1/) + - [Overview](/pages/en/device/device/Subsystem%20Development/Multimedia/Audio%20Video/Overview) + - [Development Guidelines on Media Playback](/pages/en/device/device/Subsystem%20Development/Multimedia/Audio%20Video/Development%20Guidelines%20on%20Media%20Playback) + - [Development Guidelines on Media Recording](/pages/en/device/device/Subsystem%20Development/Multimedia/Audio%20Video/Development%20Guidelines%20on%20Media%20Recording) +- [Utils](/extras/86c0c3274782b6d8968985efa173550a/) + - [Utils Overview](/pages/en/device/device/Subsystem%20Development/Utils/Utils%20Overview) + - [Utils Development Guidelines](/pages/en/device/device/Subsystem%20Development/Utils/Utils%20Development%20Guidelines) + - [Utils FAQ](/pages/en/device/device/Subsystem%20Development/Utils/Utils%20FAQ) +- [AI Framework](/extras/ed79ebf1ef1b2b3a4fd6c31dfc897698/) + - [AI Engine Framework](/pages/en/device/device/Subsystem%20Development/AI%20Framework/AI%20Engine%20Framework) + - [Development Environment](/pages/en/device/device/Subsystem%20Development/AI%20Framework/Development%20Environment) + - [Technical Specifications](/extras/f147770186bee4b022223af4068ccbd1/) + - [Code Management](/pages/en/device/device/Subsystem%20Development/AI%20Framework/Technical%20Specifications/Code%20Management) + - [Naming](/pages/en/device/device/Subsystem%20Development/AI%20Framework/Technical%20Specifications/Naming) + - [API Development](/pages/en/device/device/Subsystem%20Development/AI%20Framework/Technical%20Specifications/API%20Development) + - [Development Guidelines](/extras/bed6bfa817d5531d06586e64d9257cb3/) + - [SDK](/pages/en/device/device/Subsystem%20Development/AI%20Framework/Development%20Guidelines/SDK) + - [Plug-in](/pages/en/device/device/Subsystem%20Development/AI%20Framework/Development%20Guidelines/Plug-in) + - [Configuration File](/pages/en/device/device/Subsystem%20Development/AI%20Framework/Development%20Guidelines/Configuration%20File) + - [Development Examples](/extras/776f64719d8638378854b1c96bd62685/) + - [KWS SDK](/pages/en/device/device/Subsystem%20Development/AI%20Framework/Development%20Examples/KWS%20SDK) + - [KWS Plug-in](/pages/en/device/device/Subsystem%20Development/AI%20Framework/Development%20Examples/KWS%20Plug-in) + - [KWS Configuration File](/pages/en/device/device/Subsystem%20Development/AI%20Framework/Development%20Examples/KWS%20Configuration%20File) +- [Data Management](/extras/0f8610ee82cd7d9cc57373357c80c126/) + - [RDB](/extras/51aefd991d857a613ce5b293c134117f/) + - [RDB Overview](/pages/en/device/device/Subsystem%20Development/Data%20Management/RDB/RDB%20Overview) + - [RDB Development](/pages/en/device/device/Subsystem%20Development/Data%20Management/RDB/RDB%20Development) + - [Lightweight Data Store](/extras/3a488785e23a0f904dc2de40694e7567/) + - [Lightweight Data Store Overview](/pages/en/device/device/Subsystem%20Development/Data%20Management/Lightweight%20Data%20Store/Lightweight%20Data%20Store%20Overview) + - [Lightweight Data Store Development](/pages/en/device/device/Subsystem%20Development/Data%20Management/Lightweight%20Data%20Store/Lightweight%20Data%20Store%20Development) +- [Sensor](/extras/0661059c61750192d79b4d239fbb8b9f/) + - [Sensor Overview](/pages/en/device/device/Subsystem%20Development/Sensor/Sensor%20Overview) + - [Sensor Usage Guidelines](/pages/en/device/device/Subsystem%20Development/Sensor/Sensor%20Usage%20Guidelines) + - [Sensor Usage Example](/pages/en/device/device/Subsystem%20Development/Sensor/Sensor%20Usage%20Example) +- [USB](/extras/b369b4c707832a118f0debb612ae80e7/) + - [[USB Overview](/pages/en/device/device/Subsystem%20Development/USB/%5BUSB%20Overview) + - [USB Usage Guidelines](/pages/en/device/device/Subsystem%20Development/USB/USB%20Usage%20Guidelines) + - [USB Usage Example](/pages/en/device/device/Subsystem%20Development/USB/USB%20Usage%20Example) +- [Application Framework](/extras/19da893c74d774705f66901ba9ac7e84/) + - [Overview](/pages/en/device/device/Subsystem%20Development/Application%20Framework/Overview) + - [Setting Up a Development Environment](/pages/en/device/device/Subsystem%20Development/Application%20Framework/Setting%20Up%20a%20Development%20Environment) + - [Development Guidelines](/pages/en/device/device/Subsystem%20Development/Application%20Framework/Development%20Guidelines) + - [Development Example](/pages/en/device/device/Subsystem%20Development/Application%20Framework/Development%20Example) +- [OTA Upgrade](/pages/en/device/device/Subsystem%20Development/OTA%20Upgrade) +- [Telephony Service ](/extras/75efd89b92d7bbfda3c18d517d2afd6d/) + - [Telephony Service](/pages/en/device/device/Subsystem%20Development/Telephony%20Service/Telephony%20Service) + - [Development Guidelines](/pages/en/device/device/Subsystem%20Development/Telephony%20Service/Development%20Guidelines) +- [Security](/extras/761e170abf654d46030b51062e52da28/) + - [Overview](/pages/en/device/device/Subsystem%20Development/Security/Overview) + - [Development Guidelines on Application Signature Verification](/pages/en/device/device/Subsystem%20Development/Security/Development%20Guidelines%20on%20Application%20Signature%20Verification) + - [Development Guidelines on Application Permission Management](/pages/en/device/device/Subsystem%20Development/Security/Development%20Guidelines%20on%20Application%20Permission%20Management) + - [Development Guidelines on IPC Authentication](/pages/en/device/device/Subsystem%20Development/Security/Development%20Guidelines%20on%20IPC%20Authentication) +- [Startup](/extras/b03067b48ab81658870f4365d35e1754/) + - [Startup](/pages/en/device/device/Subsystem%20Development/Startup/Startup) + - [init Module](/pages/en/device/device/Subsystem%20Development/Startup/init%20Module) + - [appspawn Module](/pages/en/device/device/Subsystem%20Development/Startup/appspawn%20Module) + - [appspawn Module for the Standard System](/extras/c1c3af76688ce9c27f2158c27d39985b/) + - [bootstrap Module](/pages/en/device/device/Subsystem%20Development/Startup/bootstrap%20Module) + - [syspara Module](/pages/en/device/device/Subsystem%20Development/Startup/syspara%20Module) + - [FAQs](/pages/en/device/device/Subsystem%20Development/Startup/FAQs) + - [Reference](/pages/en/device/device/Subsystem%20Development/Startup/Reference) +- [Testing](/pages/en/device/device/Debugging/Test%20Subsystem) +- [DFX](/extras/23b00c9d5647ac514773855c0421a371/) + - [DFX](/pages/en/device/device/Subsystem%20Development/DFX/DFX) + - [HiLog Development](/pages/en/device/device/Subsystem%20Development/DFX/HiLog%20Development) + - [HiLog\_Lite Development](/pages/en/device/device/Subsystem%20Development/DFX/HiLog_Lite%20Development) + - [HiTrace Development](/pages/en/device/device/Subsystem%20Development/DFX/HiTrace%20Development) + - [HiCollie Development](/pages/en/device/device/Subsystem%20Development/DFX/HiCollie%20Development) + - [HiSysEvent Development](/extras/8b93462f97c66d411c0154687f88c435/) + - [HiSysEvent Logging Configuration](/pages/en/device/device/Subsystem%20Development/DFX/HiSysEvent%20Development/HiSysEvent%20Logging%20Configuration) + - [HiSysEvent Logging](/pages/en/device/device/Subsystem%20Development/DFX/HiSysEvent%20Development/HiSysEvent%20Logging) + - [HiSysEvent Listening](/pages/en/device/device/Subsystem%20Development/DFX/HiSysEvent%20Development/HiSysEvent%20Listening) + - [HiSysEvent Query](/pages/en/device/device/Subsystem%20Development/DFX/HiSysEvent%20Development/HiSysEvent%20Query) + - [HiSysEvent Tool Usage](/pages/en/device/device/Subsystem%20Development/DFX/HiSysEvent%20Development/HiSysEvent%20Tool%20Usage) +- [R&D Tools](/pages/en/device/device/Debugging/R%26D%20Tools/R%26D%20Tools) + - [bytrace Usage Guidelines](/pages/en/device/device/Debugging/R%26D%20Tools/bytrace%20Usage%20Guidelines) + - [hdc\_std Usage Guidelines](/pages/en/device/device/Debugging/R%26D%20Tools/hdc_std%20Usage%20Guidelines) +- [XTS](/pages/en/device/device/XTS%20Certification/XTS) \ No newline at end of file diff --git a/website/docs/extras/en/device-dev/subsystems/subsys-aiframework-demo.md b/website/docs/extras/en/device-dev/subsystems/subsys-aiframework-demo.md new file mode 100644 index 0000000000000000000000000000000000000000..f2cc200d33f8c918e67043ed2a46e82ee369b263 --- /dev/null +++ b/website/docs/extras/en/device-dev/subsystems/subsys-aiframework-demo.md @@ -0,0 +1,28 @@ +--- +title: "subsys-aiframework-demo" +prepermalink: /extras/776f64719d8638378854b1c96bd62685/ +permalink: /extras/776f64719d8638378854b1c96bd62685/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/subsystems/subsys-aiframework-demo.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [subsys-aiframework-demo] +--- +# Development Examples + +For your better understanding, a KWS application is used as an example to walk you through the development process. You can develop the KWS SDK and plug-in based on the AI engine framework on the Hi3516D V300 development board, compile an image for the new version, and burn the image into the version. Then, develop an application with the KWS function. The application can receive external audio and pass the audio to the SDK API. If the audio contains specified keywords, the application will be able to recognize these keywords and print them in the command line. + +This example uses a fixed keyword **Hi, xiaowen** for illustration. If the input audio contains **Hi, xiaowen**, the application prints **\[Hi, xiaowen\]**; otherwise, the application prints **\[UNKNOWN\]**. + +- **[KWS SDK](/pages/en/device/device/Subsystem%20Development/AI%20Framework/Development%20Examples/KWS%20SDK)** + +- **[KWS Plug-in](/pages/en/device/device/Subsystem%20Development/AI%20Framework/Development%20Examples/KWS%20Plug-in)** + +- **[KWS Configuration File](/pages/en/device/device/Subsystem%20Development/AI%20Framework/Development%20Examples/KWS%20Configuration%20File)** + + diff --git a/website/docs/extras/en/device-dev/subsystems/subsys-aiframework-devguide.md b/website/docs/extras/en/device-dev/subsystems/subsys-aiframework-devguide.md new file mode 100644 index 0000000000000000000000000000000000000000..8a6be64b6a1af38bcd8daef2911555c24f29fe7d --- /dev/null +++ b/website/docs/extras/en/device-dev/subsystems/subsys-aiframework-devguide.md @@ -0,0 +1,26 @@ +--- +title: "subsys-aiframework-devguide" +prepermalink: /extras/bed6bfa817d5531d06586e64d9257cb3/ +permalink: /extras/bed6bfa817d5531d06586e64d9257cb3/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/subsystems/subsys-aiframework-devguide.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [subsys-aiframework-devguide] +--- +# Development Guidelines + +To access the AI engine framework, you need to develop the SDKs and plug-ins shown in [Figure 1](/pages/en/device/device/Subsystem%20Development/AI%20Framework/AI%20Engine%20Framework#fig143186187187). In this way, you can call the APIs provided by the SDKs to call the algorithm capabilities of plug-ins to implement lifecycle management and on-demand deployment of AI capabilities. + +- **[SDK](/pages/en/device/device/Subsystem%20Development/AI%20Framework/Development%20Guidelines/SDK)** + +- **[Plug-in](/pages/en/device/device/Subsystem%20Development/AI%20Framework/Development%20Guidelines/Plug-in)** + +- **[Configuration File](/pages/en/device/device/Subsystem%20Development/AI%20Framework/Development%20Guidelines/Configuration%20File)** + + diff --git a/website/docs/extras/en/device-dev/subsystems/subsys-aiframework-tech.md b/website/docs/extras/en/device-dev/subsystems/subsys-aiframework-tech.md new file mode 100644 index 0000000000000000000000000000000000000000..8b13e16edb30f1d73ad69b79b0d24c62136f815b --- /dev/null +++ b/website/docs/extras/en/device-dev/subsystems/subsys-aiframework-tech.md @@ -0,0 +1,30 @@ +--- +title: "subsys-aiframework-tech" +prepermalink: /extras/f147770186bee4b022223af4068ccbd1/ +permalink: /extras/f147770186bee4b022223af4068ccbd1/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/subsystems/subsys-aiframework-tech.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [subsys-aiframework-tech] +--- +# Technical Specifications + +**Conventions** + +**Rule**: a convention that must be observed + +**Recommendation**: a convention that should be considered + +- **[Code Management](/pages/en/device/device/Subsystem%20Development/AI%20Framework/Technical%20Specifications/Code%20Management)** + +- **[Naming](/pages/en/device/device/Subsystem%20Development/AI%20Framework/Technical%20Specifications/Naming)** + +- **[API Development](/pages/en/device/device/Subsystem%20Development/AI%20Framework/Technical%20Specifications/API%20Development)** + + diff --git a/website/docs/extras/en/device-dev/subsystems/subsys-aiframework.md b/website/docs/extras/en/device-dev/subsystems/subsys-aiframework.md new file mode 100644 index 0000000000000000000000000000000000000000..1cd82e83afc3b29109c2ac86de481e0f2bd32068 --- /dev/null +++ b/website/docs/extras/en/device-dev/subsystems/subsys-aiframework.md @@ -0,0 +1,28 @@ +--- +title: "subsys-aiframework" +prepermalink: /extras/ed79ebf1ef1b2b3a4fd6c31dfc897698/ +permalink: /extras/ed79ebf1ef1b2b3a4fd6c31dfc897698/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/subsystems/subsys-aiframework.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [subsys-aiframework] +--- +# AI Framework + +- **[AI Engine Framework](/pages/en/device/device/Subsystem%20Development/AI%20Framework/AI%20Engine%20Framework)** + +- **[Development Environment](/pages/en/device/device/Subsystem%20Development/AI%20Framework/Development%20Environment)** + +- **[Technical Specifications](/extras/f147770186bee4b022223af4068ccbd1/)** + +- **[Development Guidelines](/extras/bed6bfa817d5531d06586e64d9257cb3/)** + +- **[Development Examples](/extras/776f64719d8638378854b1c96bd62685/)** + + diff --git a/website/docs/extras/en/device-dev/subsystems/subsys-application-framework.md b/website/docs/extras/en/device-dev/subsystems/subsys-application-framework.md new file mode 100644 index 0000000000000000000000000000000000000000..6416465eadc6cc11dd8d6729adde8b2cf5e2e20e --- /dev/null +++ b/website/docs/extras/en/device-dev/subsystems/subsys-application-framework.md @@ -0,0 +1,26 @@ +--- +title: "subsys-application-framework" +prepermalink: /extras/19da893c74d774705f66901ba9ac7e84/ +permalink: /extras/19da893c74d774705f66901ba9ac7e84/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/subsystems/subsys-application-framework.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [subsys-application-framework] +--- +# Application Framework + +- **[Overview](/pages/en/device/device/Subsystem%20Development/Application%20Framework/Overview)** + +- **[Setting Up a Development Environment](/pages/en/device/device/Subsystem%20Development/Application%20Framework/Setting%20Up%20a%20Development%20Environment)** + +- **[Development Guidelines](/pages/en/device/device/Subsystem%20Development/Application%20Framework/Development%20Guidelines)** + +- **[Development Example](/pages/en/device/device/Subsystem%20Development/Application%20Framework/Development%20Example)** + + diff --git a/website/docs/extras/en/device-dev/subsystems/subsys-boot-appspawn-standard.md b/website/docs/extras/en/device-dev/subsystems/subsys-boot-appspawn-standard.md new file mode 100644 index 0000000000000000000000000000000000000000..291795673de99ada0df7c54ffb6742600135a68e --- /dev/null +++ b/website/docs/extras/en/device-dev/subsystems/subsys-boot-appspawn-standard.md @@ -0,0 +1,173 @@ +--- +title: "subsys-boot-appspawn-standard" +prepermalink: /extras/c1c3af76688ce9c27f2158c27d39985b/ +permalink: /extras/c1c3af76688ce9c27f2158c27d39985b/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/subsystems/subsys-boot-appspawn-standard.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [subsys-boot-appspawn-standard] +--- +# appspawn Module for the Standard System + +## Overview + +After being started by the init process, the appspawn process waits for inter-process communication (IPC) messages. Upon receiving a message, the appspawn process starts an application service based on the message content, and grants the corresponding permission to the application service. + +### Introduction + +- Security control +
Support for setting of SELinux tags for applications + +- Application process control + + - Support for setting of AccessToken for applications + - Support for simultaneous stopping of all spawn application processes (after stopping of the appspawn process and before a restart) + +- Cold start +
Support for cold start of applications by using the **aa** command + + ``` + param set appspawn.cold.boot true // Enable cold start. + aa start -d 12345 -a $name -b $package -C + Example: + aa start -d 12345 -a ohos.acts.startup.sysparam.function.MainAbility -b ohos.acts.startup.sysparam.function -C + +### Basic Concepts + +**appspawn** is a registered service name. The appspawn process receives requests from the client by listening to messages over the local socket. The message type is an **AppProperty** structure. It is defined in **base/startup/appspawn_standard/interfaces/innerkits/include/sclient_socket.h**. + +**Table 1** Field description + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Field

+

Description

+

processName

+

Name of the service process to be started. The value contains a maximum of 256 bytes.

+

bundleName

+

Bundle name of the application to be started. The value contains a maximum of 256 bytes.

+

soPath

+

Path of the dynamic library specified by the application. The value contains a maximum of 256 bytes.

+

uid

+

UID of the application process to be started. The value must be a positive number.

+

gid

+

GID of the application process to be started. The value must be a positive number.

+

gidTable

+

Information about the application process group to be started. Its length is specified by **gidCount**. A maximum of 64 process groups are supported. The value must be a positive number.

+

gidCount

+

Number of application process groups to be started.

+

accessTokenId

+

Token ID for application process permission control.

+

apl

+

APL for application process permission control. The value contains a maximum of 32 bytes.

+
+ +## Development Guidelines + + The API definitions are provided in **base/startup/appspawn_standard/interfaces/innerkits/include/client_socket.h**. Table 2 is a list of available APIs. + +### Available APIs + +**Table 2** Available APIs + + + + + + + + + + + + + + + + + + + + +

Field

+

Description

+

CreateClient

+

Creates a client.

+

CloseClient

+

Closes a client.

+

ConnectSocket

+

Sends a connection request to the appspawn service.

+

WriteSocketMessage

+

Sends a message to the appspawn service.

+

ReadSocketMessage

+

Receives a message from the appspawn service.

+
+ +### Development Example + +
The following is an example of using related APIs: +``` + std::shared_ptr clientSocket = std::make_unique("AppSpawn"); + if (clientSocket == nullptr) { + return -1; + } + if (clientSocket->CreateClient() != ERR_OK) { + return -1; + } + if (clientSocket->ConnectSocket() != ERR_OK) { + return -1;; + } + // Construct AppProperty based on the specified property. + clientSocket->WriteSocketMessage((void *)&property, sizeof(AppSpawn::AppProperty)); + // Read the result. + int pid; + clientSocket->ReadSocketMessage((void *)&pid, sizeof(pid)); + // Normally, the process ID of the application is returned. If the PID is less than or equal to 0, an error has occurred. +``` + +## FAQ + +### Cold Start Failure + +   **Symptom** +
    Cold start failed because of a command execution failure. + +   **Solution** +
    1. Check whether cold start is enabled. +
    2. Check whether the cold start command is correct. diff --git a/website/docs/extras/en/device-dev/subsystems/subsys-boot.md b/website/docs/extras/en/device-dev/subsystems/subsys-boot.md new file mode 100644 index 0000000000000000000000000000000000000000..546ac2b3850d8f626bec377552499e8cd545575b --- /dev/null +++ b/website/docs/extras/en/device-dev/subsystems/subsys-boot.md @@ -0,0 +1,32 @@ +--- +title: "subsys-boot" +prepermalink: /extras/b03067b48ab81658870f4365d35e1754/ +permalink: /extras/b03067b48ab81658870f4365d35e1754/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/subsystems/subsys-boot.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [subsys-boot] +--- +# Startup + +- **[Startup](/pages/en/device/device/Subsystem%20Development/Startup/Startup)** + +- **[init Module](/pages/en/device/device/Subsystem%20Development/Startup/init%20Module)** + +- **[appspawn Module](/pages/en/device/device/Subsystem%20Development/Startup/appspawn%20Module)** + +- **[bootstrap Module](/pages/en/device/device/Subsystem%20Development/Startup/bootstrap%20Module)** + +- **[syspara Module](/pages/en/device/device/Subsystem%20Development/Startup/syspara%20Module)** + +- **[FAQs](/pages/en/device/device/Subsystem%20Development/Startup/FAQs)** + +- **[Reference](/pages/en/device/device/Subsystem%20Development/Startup/Reference)** + + diff --git a/website/docs/extras/en/device-dev/subsystems/subsys-build.md b/website/docs/extras/en/device-dev/subsystems/subsys-build.md new file mode 100644 index 0000000000000000000000000000000000000000..a9d7b00ad37452beec40cd3367199a4ccd62ad7c --- /dev/null +++ b/website/docs/extras/en/device-dev/subsystems/subsys-build.md @@ -0,0 +1,24 @@ +--- +title: "subsys-build" +prepermalink: /extras/2ce98dbc2719223219b20eb0f7d00e31/ +permalink: /extras/2ce98dbc2719223219b20eb0f7d00e31/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/subsystems/subsys-build.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [subsys-build] +--- +# Compilation and Building + +- **[Building Mini and Small Systems](/pages/en/device/device/Subsystem%20Development/Compilation%20and%20Building/Building%20Guidelines%20for%20Mini%20and%20Small%20Systems)** + +- **[Building a Standard System](/pages/en/device/device/Subsystem%20Development/Compilation%20and%20Building/Building%20Guidelines%20for%20Standard%20Systems)** + +- **[Build System Coding Specifications and Best Practices](/pages/en/device/device/Subsystem%20Development/Compilation%20and%20Building/Build%20System%20Coding%20Specifications%20and%20Best%20Practices)** + +- **[Building the Kconfig Visual Configuration](/pages/en/device/device/Subsystem%20Development/Compilation%20and%20Building/Building%20the%20Kconfig%20Visual%20Configuration)** diff --git a/website/docs/extras/en/device-dev/subsystems/subsys-data-relational-database.md b/website/docs/extras/en/device-dev/subsystems/subsys-data-relational-database.md new file mode 100644 index 0000000000000000000000000000000000000000..fa7122cb84154379c320e1ba9ef15727c17a451b --- /dev/null +++ b/website/docs/extras/en/device-dev/subsystems/subsys-data-relational-database.md @@ -0,0 +1,20 @@ +--- +title: "subsys-data-relational-database" +prepermalink: /extras/51aefd991d857a613ce5b293c134117f/ +permalink: /extras/51aefd991d857a613ce5b293c134117f/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/subsystems/subsys-data-relational-database.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [subsys-data-relational-database] +--- +# RDB + +- **[RDB Overview](/pages/en/device/device/Subsystem%20Development/Data%20Management/RDB/RDB%20Overview)** + +- **[RDB Development](/pages/en/device/device/Subsystem%20Development/Data%20Management/RDB/RDB%20Development)** diff --git a/website/docs/extras/en/device-dev/subsystems/subsys-data-storage.md b/website/docs/extras/en/device-dev/subsystems/subsys-data-storage.md new file mode 100644 index 0000000000000000000000000000000000000000..daa9d08f3b70fd4370b4e8930c67d180d7c7a00f --- /dev/null +++ b/website/docs/extras/en/device-dev/subsystems/subsys-data-storage.md @@ -0,0 +1,20 @@ +--- +title: "subsys-data-storage" +prepermalink: /extras/3a488785e23a0f904dc2de40694e7567/ +permalink: /extras/3a488785e23a0f904dc2de40694e7567/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/subsystems/subsys-data-storage.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [subsys-data-storage] +--- +# Lightweight Data Store + +- **[Lightweight Data Store Overview](/pages/en/device/device/Subsystem%20Development/Data%20Management/Lightweight%20Data%20Store/Lightweight%20Data%20Store%20Overview)** + +- **[Lightweight Data Store Development](/pages/en/device/device/Subsystem%20Development/Data%20Management/Lightweight%20Data%20Store/Lightweight%20Data%20Store%20Development)** diff --git a/website/docs/extras/en/device-dev/subsystems/subsys-data.md b/website/docs/extras/en/device-dev/subsystems/subsys-data.md new file mode 100644 index 0000000000000000000000000000000000000000..1d77ac0a298bbc95a3bea17d5f16c4579250bec2 --- /dev/null +++ b/website/docs/extras/en/device-dev/subsystems/subsys-data.md @@ -0,0 +1,19 @@ +--- +title: "subsys-data" +prepermalink: /extras/0f8610ee82cd7d9cc57373357c80c126/ +permalink: /extras/0f8610ee82cd7d9cc57373357c80c126/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/subsystems/subsys-data.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [subsys-data] +--- +# Data Management + +- **[RDB](/extras/51aefd991d857a613ce5b293c134117f/)** +- **[Lightweight Data Store](/extras/3a488785e23a0f904dc2de40694e7567/)** diff --git a/website/docs/extras/en/device-dev/subsystems/subsys-dfx-hisysevent.md b/website/docs/extras/en/device-dev/subsystems/subsys-dfx-hisysevent.md new file mode 100644 index 0000000000000000000000000000000000000000..7aa61215ead2ac3be44b3418bdb9d04622f64afe --- /dev/null +++ b/website/docs/extras/en/device-dev/subsystems/subsys-dfx-hisysevent.md @@ -0,0 +1,28 @@ +--- +title: "subsys-dfx-hisysevent" +prepermalink: /extras/8b93462f97c66d411c0154687f88c435/ +permalink: /extras/8b93462f97c66d411c0154687f88c435/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/subsystems/subsys-dfx-hisysevent.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [subsys-dfx-hisysevent] +--- +# HiSysEvent Development + +- **[HiSysEvent Logging Configuration](/pages/en/device/device/Subsystem%20Development/DFX/HiSysEvent%20Development/HiSysEvent%20Logging%20Configuration)** + +- **[HiSysEvent Logging](/pages/en/device/device/Subsystem%20Development/DFX/HiSysEvent%20Development/HiSysEvent%20Logging)** + +- **[HiSysEvent Listening](/pages/en/device/device/Subsystem%20Development/DFX/HiSysEvent%20Development/HiSysEvent%20Listening)** + +- **[HiSysEvent Query](/pages/en/device/device/Subsystem%20Development/DFX/HiSysEvent%20Development/HiSysEvent%20Query)** + +- **[HiSysEvent Tool Usage](/pages/en/device/device/Subsystem%20Development/DFX/HiSysEvent%20Development/HiSysEvent%20Tool%20Usage)** + + diff --git a/website/docs/extras/en/device-dev/subsystems/subsys-dfx.md b/website/docs/extras/en/device-dev/subsystems/subsys-dfx.md new file mode 100644 index 0000000000000000000000000000000000000000..994911ffb27a5895fefbe632911b53b329653ff8 --- /dev/null +++ b/website/docs/extras/en/device-dev/subsystems/subsys-dfx.md @@ -0,0 +1,29 @@ +--- +title: "subsys-dfx" +prepermalink: /extras/23b00c9d5647ac514773855c0421a371/ +permalink: /extras/23b00c9d5647ac514773855c0421a371/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/subsystems/subsys-dfx.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [subsys-dfx] +--- +# DFX Development Guide + +- [DFX Overview](/pages/en/device/device/Subsystem%20Development/DFX/DFX) +- [HiLog Development](/pages/en/device/device/Subsystem%20Development/DFX/HiLog%20Development) +- [HiLog_Lite Development](/pages/en/device/device/Subsystem%20Development/DFX/HiLog_Lite%20Development) +- [HiTrace Development](/pages/en/device/device/Subsystem%20Development/DFX/HiTrace%20Development) +- [HiCollie Development](/pages/en/device/device/Subsystem%20Development/DFX/HiCollie%20Development) +- [HiSysEvent Development](/extras/8b93462f97c66d411c0154687f88c435/) + - [HiSysEvent Logging Configuration](/pages/en/device/device/Subsystem%20Development/DFX/HiSysEvent%20Development/HiSysEvent%20Logging%20Configuration) + - [HiSysEvent Logging](/pages/en/device/device/Subsystem%20Development/DFX/HiSysEvent%20Development/HiSysEvent%20Logging) + - [HiSysEvent Listening](/pages/en/device/device/Subsystem%20Development/DFX/HiSysEvent%20Development/HiSysEvent%20Listening) + - [HiSysEvent Query](/pages/en/device/device/Subsystem%20Development/DFX/HiSysEvent%20Development/HiSysEvent%20Query) + - [HiSysEvent Tool Usage](/pages/en/device/device/Subsystem%20Development/DFX/HiSysEvent%20Development/HiSysEvent%20Tool%20Usage) + diff --git a/website/docs/extras/en/device-dev/subsystems/subsys-graphics.md b/website/docs/extras/en/device-dev/subsystems/subsys-graphics.md new file mode 100644 index 0000000000000000000000000000000000000000..e6271bbc9ad531e297fdaf511b37b08a159c1805 --- /dev/null +++ b/website/docs/extras/en/device-dev/subsystems/subsys-graphics.md @@ -0,0 +1,28 @@ +--- +title: "subsys-graphics" +prepermalink: /extras/c0ebe908e23b0532ab29175059c8af86/ +permalink: /extras/c0ebe908e23b0532ab29175059c8af86/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/subsystems/subsys-graphics.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [subsys-graphics] +--- +# Graphics + +- **[Graphics](/pages/en/device/device/Subsystem%20Development/Graphics/Graphics)** + +- **[Development Guidelines on Container Components](/pages/en/device/device/Subsystem%20Development/Graphics/Development%20Guidelines%20on%20Container%20Components)** + +- **[Development Guidelines on Layout Container Components](/pages/en/device/device/Subsystem%20Development/Graphics/Development%20Guidelines%20on%20Layout%20Container%20Components)** + +- **[Development Guidelines on Common Components](/pages/en/device/device/Subsystem%20Development/Graphics/Development%20Guidelines%20on%20Common%20Components)** + +- **[Development Guidelines on Animators](/pages/en/device/device/Subsystem%20Development/Graphics/Development%20Guidelines%20on%20Animators)** + + diff --git a/website/docs/extras/en/device-dev/subsystems/subsys-multimedia-camera.md b/website/docs/extras/en/device-dev/subsystems/subsys-multimedia-camera.md new file mode 100644 index 0000000000000000000000000000000000000000..21845b949738b63f426978d03bc11201dd3a41af --- /dev/null +++ b/website/docs/extras/en/device-dev/subsystems/subsys-multimedia-camera.md @@ -0,0 +1,26 @@ +--- +title: "subsys-multimedia-camera" +prepermalink: /extras/022683ace7aa7b9476c708f21b6233be/ +permalink: /extras/022683ace7aa7b9476c708f21b6233be/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/subsystems/subsys-multimedia-camera.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [subsys-multimedia-camera] +--- +# Camera + +- **[Overview](/pages/en/device/device/Subsystem%20Development/Multimedia/Camera/Overview)** + +- **[Development Guidelines on Photographing](/pages/en/device/device/Subsystem%20Development/Multimedia/Camera/Development%20Guidelines%20on%20Photographing)** + +- **[Development Guidelines on Video Recording](/pages/en/device/device/Subsystem%20Development/Multimedia/Camera/Development%20Guidelines%20on%20Video%20Recording)** + +- **[Development Guidelines on Previewing](/pages/en/device/device/Subsystem%20Development/Multimedia/Camera/Development%20Guidelines%20on%20Previewing)** + + diff --git a/website/docs/extras/en/device-dev/subsystems/subsys-multimedia-video.md b/website/docs/extras/en/device-dev/subsystems/subsys-multimedia-video.md new file mode 100644 index 0000000000000000000000000000000000000000..543c4c8aef3176299039c438a1ec75bf49845f96 --- /dev/null +++ b/website/docs/extras/en/device-dev/subsystems/subsys-multimedia-video.md @@ -0,0 +1,24 @@ +--- +title: "subsys-multimedia-video" +prepermalink: /extras/ab459733feb658557f68b92fb3a3c5d1/ +permalink: /extras/ab459733feb658557f68b92fb3a3c5d1/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/subsystems/subsys-multimedia-video.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [subsys-multimedia-video] +--- +# Audio/Video + +- **[Overview](/pages/en/device/device/Subsystem%20Development/Multimedia/Audio%20Video/Overview)** + +- **[Development Guidelines on Media Playback](/pages/en/device/device/Subsystem%20Development/Multimedia/Audio%20Video/Development%20Guidelines%20on%20Media%20Playback)** + +- **[Development Guidelines on Media Recording](/pages/en/device/device/Subsystem%20Development/Multimedia/Audio%20Video/Development%20Guidelines%20on%20Media%20Recording)** + + diff --git a/website/docs/extras/en/device-dev/subsystems/subsys-multimedia.md b/website/docs/extras/en/device-dev/subsystems/subsys-multimedia.md new file mode 100644 index 0000000000000000000000000000000000000000..59b19f6f8e36962ca138a02b22d22f2ae292080a --- /dev/null +++ b/website/docs/extras/en/device-dev/subsystems/subsys-multimedia.md @@ -0,0 +1,22 @@ +--- +title: "subsys-multimedia" +prepermalink: /extras/b47c31807da4c3c1d56185bd379d1d88/ +permalink: /extras/b47c31807da4c3c1d56185bd379d1d88/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/subsystems/subsys-multimedia.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [subsys-multimedia] +--- +# Multimedia + +- **[Camera](/extras/022683ace7aa7b9476c708f21b6233be/)** + +- **[Audio/Video](/extras/ab459733feb658557f68b92fb3a3c5d1/)** + + diff --git a/website/docs/extras/en/device-dev/subsystems/subsys-security-devicesecuritylevel.md b/website/docs/extras/en/device-dev/subsystems/subsys-security-devicesecuritylevel.md new file mode 100644 index 0000000000000000000000000000000000000000..737fc7a9587fe386c4ab290bb48471a98e466bbe --- /dev/null +++ b/website/docs/extras/en/device-dev/subsystems/subsys-security-devicesecuritylevel.md @@ -0,0 +1,496 @@ +--- +title: "subsys-security-devicesecuritylevel" +prepermalink: /extras/6db114282cf275cd3db518b13c91e3b8/ +permalink: /extras/6db114282cf275cd3db518b13c91e3b8/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/subsystems/subsys-security-devicesecuritylevel.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [subsys-security-devicesecuritylevel] +--- +# Development on Device Security Level Management + +## Overview + +### DSLM + +The OpenHarmony distributed technology can converge resources from different devices to form a Super Device. Poor security capabilities of any device may threaten the security of the Super Device. + +The Device Security Level Management (DSLM) module is introduced to manage the security levels of OpenHarmony devices. When different types of user data are hopped or processed in OpenHarmony distributed services, the DSLM APIs can be called to obtain the security levels of related devices for subsequent processing. + +### Basic Concepts + +- Device security level + + The security level of an OpenHarmony device depends on the system security capabilities of the device. The OpenHarmony system security capabilities are based on the root of trust (RoT) for boot, RoT for storage, and RoT for compute on the hardware. Security technologies and capabilities focus on device integrity protection, data confidentiality protection, and vulnerability defense. + + The following figure shows the OpenHarmony security architecture. + + ![OpenHarmony system security architecture](../../../../images/en/device-dev/subsystems/figure/a04244c3e8d2402b6dc95a102ceb9692.png) + + The above figure shows the typical security architecture for a single device. The architecture may vary depending on the risk level as well as the software and hardware resources of the device. The security capabilities of OpenHarmony devices are classified into five levels from SL1 to SL5, based on an industry standard security classification model and actual OpenHarmony service scenarios and device types. In the OpenHarmony ecosystem, higher security levels include all the capabilities of lower security levels by default. The figure below shows the security levels of OpenHarmony devices. + + ![OpenHarmony device security levels](../../../../images/en/device-dev/subsystems/figure/e81be037565b04f169ad54a2c80b49c0.png) + + - SL1: SL1 is the lowest security level of OpenHarmony devices. Usually equipped with a lightweight operating system and low-end microprocessors, such devices implement simple services and do not need to process sensitive data. SL1 devices are required to support software integrity protection and eliminate common errors. Devices that cannot meet the requirements of SL1 can only be controlled by OpenHarmony devices. They cannot control OpenHarmony devices for more complex service collaboration. + + - SL2: OpenHarmony devices of SL2 can label their own data and define access control rules to implement discretionary access control (DAC). These devices must have basic anti-penetration capabilities. Devices of this level support a lightweight, secure, and isolated environment for deploying a small number of necessary security services. + + - SL3: OpenHarmony devices of SL3 have comprehensive security protection capabilities, and their operating systems have relatively complete security semantics and support mandatory access control (MAC). The system data can be structured as critical elements and non-critical elements. The critical elements are protected by a well-defined security policy model. Devices of this level must have certain anti-penetration capabilities to defend against common vulnerability exploits. + + - SL4: OpenHarmony devices of SL4 must have simplified trusted computing base (TCB) and come with anti-tampering capabilities. The implementation of SL4 should be concise and secure enough. Adequate authentication and arbitration are required for any access to critical elements. Devices of this level have considerable anti-penetration capabilities and can defend against most software attacks. + + - SL5: SL5 indicates the highest security protection capabilities for OpenHarmony devices. The system core software modules must have passed formal verification. Key hardware modules, such as the RoT and cryptographic computing engine, must be able to defend against physical attacks and attacks simulated in labs. Devices at this level must have high-security units, such as dedicated security chips, to enhance the boot, storage, and running of the root of trust (RoT). + +- DSLM + + DSLM is a module to manage the security levels of OpenHarmony devices. It verifies and updates device security level information for OpenHarmony devices in collaboration. It also provides an interface for querying the security level of each device. + +### Working Principles + +The security level of each device in a Super Device provides the decision-making criteria for processing or hopping various user data. For example, the distributed file storage service does not allow sensitive data to be stored on devices with security level lower than SL3. + +### Constraints + +The default security level of OpenHarmony devices is SL1. Device manufacturers can customize a higher security level based on service requirements. For details, see [Customizing Device Security Levels](#customizingdevicesecuritylevels). + +## Development Guidelines + +### When to Use + +When processing or hopping various user data, a subsystem can invoke the APIs provided by the DSLM module to obtain the security level information of related devices. Then, the subsystems determine the subsequent processing based on the security level and data to be processed. + +### Available APIs + +All the APIs are native C interfaces for implementing underlying capabilities and are not open to apps. The APIs are described as follows: +| API| Description| +| :----------------------------------------------------------- | :------------------------------------------- | +| int32_t RequestDeviceSecurityInfo(const DeviceIdentify \*identify, const RequestOption \*option, DeviceSecurityInfo \*\*info); | Requests the security level information of a device synchronously.| +| int32_t RequestDeviceSecurityInfoAsync(const DeviceIdentify \*identify, const RequestOption \*option, DeviceSecurityInfoCallback callback); | Requests the security level information of a device asynchronously.| +| void FreeDeviceSecurityInfo(DeviceSecurityInfo \*info); | Releases the device security level information.| +| int32\_t GetDeviceSecurityLevelValue(const DeviceSecurityInfo \*info, int32_t \*level); | Obtains the device security level from the security level information.| + +### How to Develop + +1. Add the dependencies for compilation. + + ```undefined + external_deps += [ "device_security_level:dslm_sdk" ] + ``` + +2. Add the header files of dependencies. + + ```cpp + #include "device_security_defines.h" // Header file for defining critical data structures. + #include "device_security_info.h" // Header file for defining APIs. + ``` + +3. Call APIs. + + ```cpp + // Obtain the unique device identifier (UDID) of the device of which the security level is to be queried. + const DeviceIdentify *device = GetDestDeviceUdid(); + + // Obtain the RequestOption. + const RequestOption *option = DEFAULT_OPTION; + + // Define a pointer to the device security level obtained. + DeviceSecurityInfo *info = NULL; + + // Call RequestDeviceSecurityInfo to obtain the device security level information of the peer device. + int32_t ret = RequestDeviceSecurityInfo(device, DEFAULT_OPTION, &info); + + int32_t level = 0; + // Obtain the device security level from the device security level information. + ret = GetDeviceSecurityLevelValue(info, &level); + if (ret == SUCCESS) { + // The operation is successful. + return; + } + // Release the memory before the processing is complete. + FreeDeviceSecurityInfo(info); + ``` + +### Development Example + +A service with the file sharing function needs to be developed. To prevent sensitive files from being shared unintentionally, the following judgments must be performed before any file is sent: + +- If the security level of the destination device is SL3 or higher, the service sends the file. +- If the security level of the destination device is lower than SL3, the service denies the file transfer and display a dialog box to notify the user. + +**Example of synchronously obtaining the device security level** + +```cpp +void CheckDestDeviceSecurityLevel(const DeviceIdentify *device, RequestOption *option) +{ + // Pointer to the device security level information. + DeviceSecurityInfo *info = NULL; + // Obtain the security level information of the device. + int32_t ret = RequestDeviceSecurityInfo(device, option, &info); + if (ret != SUCCESS) { + // Failed to obtain the information. You can develop a retry process as required. + return; + } + int32_t level = 0; + // Obtain the device security level from the device security level information. + ret = GetDeviceSecurityLevelValue(info, &level); + if (ret != SUCCESS) { + // Failed to obtain the security level. You can develop a retry process as required. + return; + } + // After the device security level is successfully obtained, check the lowest security level required for the current operation. + // The lowest device security level required for the current operation is 3. + if (level >= 3) { + // The security level of the target device meets the requirements. Services are processed properly. + } else { + // The security level of the target device does not meet the requirements. An alert or dialog box is displayed as required. + } + // Release the memory before the processing is complete. + FreeDeviceSecurityInfo(info); +} +``` + +**Example of asynchronously obtaining the device security level** + +```cpp +// Callback +void DeviceSecurityInfoCallback(const DeviceIdentify *identify, struct DeviceSecurityInfo *info) +{ + int32_t level = 0; + // Obtain the device security level from the device security level information. + int32_t ret = GetDeviceSecurityLevelValue(info, &level); + if (ret != SUCCESS) { + // Failed to obtain the information. You can develop a retry process as required. + return; + } + // After the device security level is successfully obtained, check the lowest security level required for the current operation. + // The lowest device security level required for the current operation is 3. + if (level >= 3) { + // The security level of the target device meets the requirements. Services are processed properly. + } else { + // The security level of the target device does not meet the requirements. An alert or dialog box is displayed as required. + } + // Release the memory before the processing is complete. + FreeDeviceSecurityInfo(info); +} + +void CheckDestDeviceSecurityLevelAsync(const DeviceIdentify *device, RequestOption *option) +{ + // Invoke the asynchronous callback to return the device security level obtained. + int ret = RequestDeviceSecurityInfoAsync(device, option, DeviceSecurityInfoCallback); + if (ret != SUCCESS) { + // Failed to obtain the security level. You can develop a retry process as required. + // In this case, the callback will not be invoked. + return; + } + // The callback is invoked. Wait for the callback to return the device security level. +} +``` + +## Customizing Device Security Levels + +### Device Security Level Credential + +To ensure its integrity and non-repudiation, the security level information must be encapsulated in a "device security level credential" (credential for short) file for transmission between devices. In addition to the security level information of the device, the credential may include device attributes, such as the device model and version. Moreover, the credential must be signed using the public key infrastructure (PKI) technology. Other basic security capabilities of OpenHarmony, such as [Device Authentication](https://gitee.com/openharmony/security_deviceauth) and [HUKS](https://gitee.com/openharmony/security_huks), are used to ensure secure transmission of credentials. + +### Default Implementation + +The DSLM module provides default implementation of security level information synchronization and verification. It is assumed that the security level of all OpenHarmony devices is SL1, and a loose verification scheme is used. For details, see the [source code](https://gitee.com/openharmony/security_device_security_level/tree/master/oem_property/ohos). + +You can change the device security level as required. For details about the OpenHarmony device security levels, see [Basic Concepts](#basicconcepts). You can also use more severe verification schemes, including but are not limited to using device-specific credential, periodically downloading updated credentials from a server and strictly authenticating the issuer and validity period of the credentials, and using Trusted Execution Environment (TEE) or even Secure Element (SE) to sign credential files. + +### Generating a Credential File + +The credential file consists of four Base64-encoded strings, separated by periods (.). The following is an example: + +```undefined +... +``` + +#### 1. Construct the `header`. + +The header is a fixed JSON string in the following format: + +``` json +{ + "typ": "DSL" +} +``` + +Encode the header string to Base64 format to obtain ``. + +```undefined +eyJ0eXAiOiAiRFNMIn0= +``` + +#### 2. Construct the `payload`. + +Construct the payload in a JSON string. The following is an example: + +``` json +{ + "type": "debug", + "manufacture": "ohos", + "brand": "rk3568", + "model": "rk3568", + "softwareVersion": "3.2.2", + "securityLevel": "SL1", + "signTime": "20220209150259", + "version": "1.0.1" +} +``` + +Encode the payload string to Base64 format to obtain ``. + +```undefined +eyJ0eXBlIjogImRlYnVnIiwgIm1hbnVmYWN0dXJlIjogIm9ob3MiLCAiYnJhbmQiOiAicmszNTY4IiwgIm1vZGVsIjogInJrMzU2OCIsICJzb2Z0d2FyZVZlcnNpb24iOiAiMy4yLjIiLCAic2VjdXJpdHlMZXZlbCI6ICJTTDEiLCAic2lnblRpbWUiOiAiMjAyMjAyMDkxNTAyNTkiLCAidmVyc2lvbiI6ICIxLjAuMSJ9 +``` + +The fields in the `payload` are described as follows: + +| Field| Description| Mandatory| Value Range| +| :-------------- | :----------------- | :----------- | :-------------------- | +| type | Credential type.| Yes| [debug release] | +| manufacture | Device manufacturer information.| Yes| string [0..128] | +| brand | Device brand.| Yes| string [0..128] | +| model | Device model.| Yes| string [0..128] | +| softwareVersion | Device software version.| Yes| string [0..128] | +| securityLevel | Device security level.| Yes| [SL1 SL2 SL3 SL4 SL5] | +| signTime | Time when the credential was signed.| Yes| string [0..128] | +| version | Credential version.| Yes| string [0..32] | +| sn | Device SN.| No| string [0..128] | +| udid | Device UDID.| No| string [0..128] | + +#### 3. Construct the `signature`. + +Construct the signature of the header and payload. + +##### 3.1 Construct the raw data to be signed. + +Combine the Base64-encoded header and payload with a period (.) in between to obtain `.`. +Example: + +```undefined +eyJ0eXAiOiAiRFNMIn0=.eyJ0eXBlIjogImRlYnVnIiwgIm1hbnVmYWN0dXJlIjogIm9ob3MiLCAiYnJhbmQiOiAicmszNTY4IiwgIm1vZGVsIjogInJrMzU2OCIsICJzb2Z0d2FyZVZlcnNpb24iOiAiMy4yLjIiLCAic2VjdXJpdHlMZXZlbCI6ICJTTDEiLCAic2lnblRpbWUiOiAiMjAyMjAyMDkxNTAyNTkiLCAidmVyc2lvbiI6ICIxLjAuMSJ9 +``` + +##### 3.2 Generate a private key for signature. + +The Elliptic Curve Digital Signature algorithm (ECDSA) is used to sign the raw data in the credential file. Generate an ECDSA key pair `` and `` first. + +> ![notice](../../../../images/en/device-dev/public_sys-resources/3c2bfebc1c47f1a731db079ade8001fc.gif)**NOTICE** +> +> This step must be performed in a secure and reliable environment, for example, a cryptographic machine that meets related security requirements, to ensure that the key used for signature is not disclosed. + +##### 3.3 Sign the raw data. + +Use the ECC private key `` to sign `.`, and encode the signature to Base64 format to obtain ``. + +```undefined +MGUCMDb9xoiFzTWVkHDU3VWSVQ59gLyw4TchZ0+eQ3vUfQsLt3Hkg0r7a/PmhkNr3X/mTgIxAIywIRE6vRTRs0xk6xKp8A0XwMMiIyjZlujPJfasCvFonpsvXLAqCAIYbe1J0k4Zfg== +``` + +#### 4. Construct the `attestation`. + +> ![notice](../../../../images/en/device-dev/public_sys-resources/3c2bfebc1c47f1a731db079ade8001fc.gif)**NOTICE** +> +> This step must be performed in a secure and reliable environment, for example, a cryptographic machine that meets related security requirements, to ensure that the key used for signature is not disclosed. +> The key pairs involved in this step do not need to be generated each time. Secure key pairs can be reused. + +##### 4.1 Generate level-3 signature verification information. + +1. Generate an ECDSA key pair `` and `` for a level-2 signature. +2. Use `` to sign `` (generated in step 3.2) to obtain ``. +3. Combine `` and `` into a JSON string. The following is an example: + +``` json +{ + "userPublicKey": "", + "signature": "" +} +``` + +##### 4.2 Generate level-2 signature verification information. + +1. Generate an ECDSA key pair `` and `` for a level-1 signature. +2. Use `` to sign `` (generated in step 4.1) to obtain ``. +3. Combine `` and `` into a JSON string. The following is an example: + +``` json +{ + "userPublicKey": "", + "signature": "" +} +``` + +##### 4.3 Generate root signature verification information. + +1. Use `` to sign the `` (generated in step 4.2) to obtain `` (a self-signature). +2. Combine `` and `` into a JSON string. The following is an example: + +``` json +{ + "userPublicKey": "", + "signature": "" +} +``` + +##### 4.4 Generate the `attestation`. + +1. Combine the preceding three pieces of signature information into a JSON array. + + ```json + [ + { + "userPublicKey": "", + "signature": "" + }, + { + "userPublicKey": "", + "signature": "" + }, + { + "userPublicKey": "", + "signature": "" + } + ] + ``` + +2. Encode the JSON array to Base64 format to obtain ``. + + ```undefined + W3sidXNlclB1YmxpY0tleSI6ICJNSG93RkFZSEtvWkl6ajBDQVFZSkt5UURBd0lJQVFFTEEySUFCREdOMU9xYWZrWFc2a0l1SEZrMVQ0TS84RVJUY3p0eWRDaGtramFROEkzNEc2Q3E1aTNJcnczVnRhQS9KTTF2a0lHOUZDVWRUaHZFUlJFUTFUdG9xemdxZW9SUzVwQW1EYUUyalEwYzdDem8rOHVUWTRIYW1weXZ1TENtenlYUXFnPT0iLCAic2lnbmF0dXJlIjogIk1HTUNMeHVjUnoyZndKZ092QkxyU1U3K1hlVTA3R0EyVXhZbDFMbEJLUnVIUS9wZlNWVHBEd0ZHSTNTb3h5ODR3NThIQWpBeGRtNEY3b3YvYUtEL0NFZi9QZlZDWHVlbE1mQys1L3pkUExXUUJEVnlGdWQrNVdYL3g4U083VXM5UGFhRW1mZz0ifSwgeyJ1c2VyUHVibGljS2V5IjogIk1Ib3dGQVlIS29aSXpqMENBUVlKS3lRREF3SUlBUUVMQTJJQUJHMWU3TDJVd1AyWWxTajB2RWViUGJpNVpLMDh5NS9UeHRWb3VrRFpIUGtSNlRtb2JoVGpyMVRVNzZpUkU4bDlWQlhuU1h1QVB6cjBuSHdKVkdVZVJMdmp4MVh0YUZReE9QNjhjNlIvRTdFWkZ2STdRUFg1N0tvRkhYdkEvVlJaNnc9PSIsICJzaWduYXR1cmUiOiAiTUdRQ01FUVdFNnk0Rm42SFg1ekFvTzNkYzl5cG1Sd2lBclplc2o5aVBROTZEaEhuNXJkRTdNaGFMdWNRZ0MvaXhjSWJsZ0l3QkN5aFBvRUg2RjFITFlwM2xqbWVncVlZQ1E5NHEyZm1kbDB6dHhrWEVTOVpPOVRNSUZQRVpKYlpmUnU5ZHcyOSJ9LCB7InVzZXJQdWJsaWNLZXkiOiAiTUhvd0ZBWUhLb1pJemowQ0FRWUpLeVFEQXdJSUFRRUxBMklBQkZRUUlDWmpWUTV4bkE0c2RMbUJzUmVaMzRJeWdkSmZhanA3SnRReFBzU2RwWTJXV0FneXp6Rm40OFFRRWhoU1BtdzhJYUU3VlJKRENBT3FYRnhGektJbFBFTDFvcFJDUmhhWmJrRzc5Y3ZrWC9HVVhlaFVYc2V2ZGhyb2VRVERFdz09IiwgInNpZ25hdHVyZSI6ICJNR1FDTUdQRndvSDJLbHhwbVZhWXRWV1ViMHpDSUJxYXFXY2F6czFqOVp4YklLUmVkR2tJY0VJdHN0UFoxdnVTanYvNDJnSXdSeGZPcTRoQTdNMHlGV2ZPSndqRTlTc2JsYXhvRDNiRTZCYzN2QjUyMmsyQ0ZJNWJqelpkeUFTVW04d2J2TW5WIn1d + ``` + +#### 5. Construct a complete credential. + +Put the four pieces of data together with a period (.) in between to obtain `...`. The following is an example: + +```undefined +eyJ0eXAiOiAiRFNMIn0=.eyJ0eXBlIjogImRlYnVnIiwgIm1hbnVmYWN0dXJlIjogIm9ob3MiLCAiYnJhbmQiOiAicmszNTY4IiwgIm1vZGVsIjogInJrMzU2OCIsICJzb2Z0d2FyZVZlcnNpb24iOiAiMy4yLjIiLCAic2VjdXJpdHlMZXZlbCI6ICJTTDEiLCAic2lnblRpbWUiOiAiMjAyMjAyMDkxNTAyNTkiLCAidmVyc2lvbiI6ICIxLjAuMSJ9.MGUCMDb9xoiFzTWVkHDU3VWSVQ59gLyw4TchZ0+eQ3vUfQsLt3Hkg0r7a/PmhkNr3X/mTgIxAIywIRE6vRTRs0xk6xKp8A0XwMMiIyjZlujPJfasCvFonpsvXLAqCAIYbe1J0k4Zfg==.W3sidXNlclB1YmxpY0tleSI6ICJNSG93RkFZSEtvWkl6ajBDQVFZSkt5UURBd0lJQVFFTEEySUFCREdOMU9xYWZrWFc2a0l1SEZrMVQ0TS84RVJUY3p0eWRDaGtramFROEkzNEc2Q3E1aTNJcnczVnRhQS9KTTF2a0lHOUZDVWRUaHZFUlJFUTFUdG9xemdxZW9SUzVwQW1EYUUyalEwYzdDem8rOHVUWTRIYW1weXZ1TENtenlYUXFnPT0iLCAic2lnbmF0dXJlIjogIk1HTUNMeHVjUnoyZndKZ092QkxyU1U3K1hlVTA3R0EyVXhZbDFMbEJLUnVIUS9wZlNWVHBEd0ZHSTNTb3h5ODR3NThIQWpBeGRtNEY3b3YvYUtEL0NFZi9QZlZDWHVlbE1mQys1L3pkUExXUUJEVnlGdWQrNVdYL3g4U083VXM5UGFhRW1mZz0ifSwgeyJ1c2VyUHVibGljS2V5IjogIk1Ib3dGQVlIS29aSXpqMENBUVlKS3lRREF3SUlBUUVMQTJJQUJHMWU3TDJVd1AyWWxTajB2RWViUGJpNVpLMDh5NS9UeHRWb3VrRFpIUGtSNlRtb2JoVGpyMVRVNzZpUkU4bDlWQlhuU1h1QVB6cjBuSHdKVkdVZVJMdmp4MVh0YUZReE9QNjhjNlIvRTdFWkZ2STdRUFg1N0tvRkhYdkEvVlJaNnc9PSIsICJzaWduYXR1cmUiOiAiTUdRQ01FUVdFNnk0Rm42SFg1ekFvTzNkYzl5cG1Sd2lBclplc2o5aVBROTZEaEhuNXJkRTdNaGFMdWNRZ0MvaXhjSWJsZ0l3QkN5aFBvRUg2RjFITFlwM2xqbWVncVlZQ1E5NHEyZm1kbDB6dHhrWEVTOVpPOVRNSUZQRVpKYlpmUnU5ZHcyOSJ9LCB7InVzZXJQdWJsaWNLZXkiOiAiTUhvd0ZBWUhLb1pJemowQ0FRWUpLeVFEQXdJSUFRRUxBMklBQkZRUUlDWmpWUTV4bkE0c2RMbUJzUmVaMzRJeWdkSmZhanA3SnRReFBzU2RwWTJXV0FneXp6Rm40OFFRRWhoU1BtdzhJYUU3VlJKRENBT3FYRnhGektJbFBFTDFvcFJDUmhhWmJrRzc5Y3ZrWC9HVVhlaFVYc2V2ZGhyb2VRVERFdz09IiwgInNpZ25hdHVyZSI6ICJNR1FDTUdQRndvSDJLbHhwbVZhWXRWV1ViMHpDSUJxYXFXY2F6czFqOVp4YklLUmVkR2tJY0VJdHN0UFoxdnVTanYvNDJnSXdSeGZPcTRoQTdNMHlGV2ZPSndqRTlTc2JsYXhvRDNiRTZCYzN2QjUyMmsyQ0ZJNWJqelpkeUFTVW04d2J2TW5WIn1d +``` + +### Credential Exchange Protocol + +When detecting a device goes online, the DSLM module requests the device security level credential from the device through the channel provided by [DSoftBus](https://gitee.com/openharmony/communication_dsoftbus). + +The packet for requesting the credential is in the following format: + +``` json +{ + "message": 1, + "payload": { + "version": 196608, + "challenge": "0102030405060708", + "support": [ + 300 + ] + } +} +``` + +The fields in the request message are described as follows: + +| Field| Description| +| :-------- | :------------------------------------ | +| message | Message header. The value **1** indicates a request for the device security level credential.| +| payload | Message payload, which is the specific request information.| +| version | Version of the protocol used by the requester.| +| challenge | Challenge value corresponding to this request.| +| support | List of credential formats supported by the requester.| + +After receiving the request, the peer device returns a response in the following format: + +``` json +{ + "message": 2, + "payload": { + "version": 196608, + "type": 300, + "challenge": "0102030405060708", + "info": "YWJjZAEDBQcJ..." + } +} +``` + +The fields in the response message are described as follows: +| Field| Description| +| :-------- | :--------------------------------------------------------- | +| message | Message header. The value **2** indicates a response to the request for the device security level credential.| +| payload | Message payload, which is the specific response information.| +| version | Version of the protocol used by the responder. | +| type | Format of the credential returned, which describes how to parse the **info** field.| +| challenge | Challenge value corresponding to this response message.| +| info | Signed credential information, which also includes the device information and challenge value verification information.| + +### Tool + +The DSLM module provides a [credential tool](https://gitee.com/openharmony/security_device_security_level/blob/master/oem_property/ohos/dslm_cred_tool.py) to help you better understand the issuing and verification of credentials. This tool is a Python script encapsulated with OpenSSL commands. +You can use the tool as follows: + +1. Initialize the signature key. + + ``` undefined + ./dslm_cred_tool.py init + ``` + +2. Generate a credential. + + For example, to generate a credential file **cred.txt** with the device model of **rk3568**, device version of **3.0.0**, and device security level of **SL3**, run the following command: + + ``` undefined + ./dslm_cred_tool.py create --field-manufacture OHOS --field-brand rk3568 --field-model rk3568 --field-software-version 3.0.0 --field-security-level SL3 --cred-file cred.txt + ``` + + A credential file is generated as follows: + + ``` undefined + cat cred.txt + eyJ0eXAiOiAiRFNMIn0=.eyJ0eXBlIjogImRlYnVnIiwgIm1hbnVmYWN0dXJlIjogIk9IT1MiLCAiYnJhbmQiOiAicmszNTY4IiwgIm1vZGVsIjogInJrMzU2OCIsICJzb2Z0d2FyZVZlcnNpb24iOiAiMy4wLjAiLCAic2VjdXJpdHlMZXZlbCI6ICJTTDMiLCAic2lnblRpbWUiOiAiMjAyMjAyMDkxNTUzMDMiLCAidmVyc2lvbiI6ICIxLjAuMSJ9.MGQCMEqZy/snsRyjMupnEvTpQfhQn+IcdCc5Q3NGxllNQVhoZX8PNyw6ATTgyx+26ghmtQIwVH5KwQ4/VejxckeHmtkBVhofhgmRapzvyVnyiB3PdsU7nvHk8A/zC7PFy1CWBG3z.W3sidXNlclB1YmxpY0tleSI6ICJNSG93RkFZSEtvWkl6ajBDQVFZSkt5UURBd0lJQVFFTEEySUFCQzFXRUxSVlU1NGp1U1ZXWlUrT29CM3hacFd5MWg3QW5uSFdKWm5QbTB3S2l0ZlJZelJKZ3FiUGQyZ3ltVXBUWVl1cmhyRDQxbFdPbUNzcmt0VWdaNTFXdGNCTmc5SG1GODkzc2ZHVFM5eUJNS0JoMGcxSHZaSVFSN1k0S3FXaWpnPT0iLCAic2lnbmF0dXJlIjogIk1HUUNNRFVicTZ2Z2R1YVF0bFVwOTR0azd4VjRJcEx2WVZWY3Y4aFNOTkw0azdPRHhmbEVGTHJFaUdPRWhwMUcweGFGYlFJd1pUbTk1cWx4OTBFZnptV3VIOGlEY2ZWYVlQS2N5SEYwR2ZFcEUzb1NESzQwZEFOZ0FJMWVQY09rTzBPOTdnTFAifSwgeyJ1c2VyUHVibGljS2V5IjogIk1Ib3dGQVlIS29aSXpqMENBUVlKS3lRREF3SUlBUUVMQTJJQUJGKzY1a0lSYTM2dkE4QVZWNXFrcUozYXpXTkdGQy9oaVdPL0tFNHR0S1pMOUsyNlhzQ2hQbjVNc3BlT2F3b1dqSU02bTVLOFZTcU1DYlZNN0svY0VRU0tYdDJTeVJGZERVZU9TaFZmQm9YVmxqaXRUU2puN0V5Q2pERVZiWjFRNEE9PSIsICJzaWduYXR1cmUiOiAiTUdRQ01HanF2cnZ5VW1YNVZLVVc1UkFkUTNkZ2hBYmNBazBRQnppQlFWMVFZUTNQMVFPSzdMckM1b0RObXh6T2Y0QUtmd0l3SzVWU2x3ZG5JSUR6Zm9PUXBEUVAycGhTVGgxSGVjbXJRK1F4VGxWelo0aHJsdnJyd2xCNnp0T3pWRFdNblRELyJ9LCB7InVzZXJQdWJsaWNLZXkiOiAiTUhvd0ZBWUhLb1pJemowQ0FRWUpLeVFEQXdJSUFRRUxBMklBQkZCa2FDNE9mc2VTREt2cW8vbU5VaUtXQ3JtK1VDNGFQcjVsODRNM2tMVCtDdkd3OWhqOGJ6d2I1MzNtVVlFZVhWWWtUdFlRYWRURkRJZXV1dGIzNU1QZDlEKytNMFRFWnZvcTY4NFhoYTVQMzBUbVRhK0ZvOG02UWliZWc3TmFQdz09IiwgInNpZ25hdHVyZSI6ICJNR1FDTURJcmpNYzhvODVPRHFZT0R4c05PcmpYdUhvWjM5endpZlhVTkdDc0lkN2xjU2FWcnhCVlNqRjRyaWg5Y1R6T3dRSXdWQXA3RUF5c1pucEI5REJWVWczQzlMeGQ3eTQxWEMwYVVPcGZUKzI3REVvWmM1WVVldDFGa1FwdmFQckduaFhVIn1d + ``` + +3. Verify a credential. + + ``` undefined + ./dslm_cred_tool.py verify --cred-file cred.txt + ``` + + The command output is as follows: + + ``` undefined + head: + { + "typ": "DSL" + } + payload: + { + "type": "debug", + "manufacture": "OHOS", + "brand": "rk3568", + "model": "rk3568", + "softwareVersion": "3.0.0", + "securityLevel": "SL3", + "signTime": "20220209155303", + "version": "1.0.1" + } + verify success! + ``` + +## FAQs + +- Q: How can I use the credential tool in a production environment? + + A: The credential tool cannot be directly used in the production environment. It is used to demonstrate the format and generation process of credentials. In the production environment, you are advised to generate credentials and save related keys in a cryptographic machine that meets related security requirements. + +- Q: How do I verify a credential in a production environment? + + A: You are advised to use a properly kept private key to sign the credential and use more severe signature verification process instead of the default verification process provided by the DSLM module. For example, allow only the credentials issued by trusted certification authorities (CAs), and bind the credential and device ID to enhance the security. + +## References + +None diff --git a/website/docs/extras/en/device-dev/subsystems/subsys-security.md b/website/docs/extras/en/device-dev/subsystems/subsys-security.md new file mode 100644 index 0000000000000000000000000000000000000000..cc786a700eff07897de7197303fb870c8e52fdc0 --- /dev/null +++ b/website/docs/extras/en/device-dev/subsystems/subsys-security.md @@ -0,0 +1,27 @@ +--- +title: "subsys-security" +prepermalink: /extras/761e170abf654d46030b51062e52da28/ +permalink: /extras/761e170abf654d46030b51062e52da28/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/subsystems/subsys-security.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [subsys-security] +--- +# Security + +- **[Overview](/pages/en/device/device/Subsystem%20Development/Security/Overview)** + +- **[Development on Application Signature Verification] (subsys-security-sigverify.md)** + +- **[Development on Application Permission Management](/pages/en/device/device/Subsystem%20Development/Security/Development%20Guidelines%20on%20Application%20Permission%20Management)** + +- **[Development on IPC Authentication](/pages/en/device/device/Subsystem%20Development/Security/Development%20Guidelines%20on%20IPC%20Authentication)** + +- **[Development on Device Security Level Management](/extras/6db114282cf275cd3db518b13c91e3b8/)** + diff --git a/website/docs/extras/en/device-dev/subsystems/subsys-sensor.md b/website/docs/extras/en/device-dev/subsystems/subsys-sensor.md new file mode 100644 index 0000000000000000000000000000000000000000..f752383775c5c3ea6b8fe9dbbf267c0170c574b7 --- /dev/null +++ b/website/docs/extras/en/device-dev/subsystems/subsys-sensor.md @@ -0,0 +1,24 @@ +--- +title: "subsys-sensor" +prepermalink: /extras/0661059c61750192d79b4d239fbb8b9f/ +permalink: /extras/0661059c61750192d79b4d239fbb8b9f/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/subsystems/subsys-sensor.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [subsys-sensor] +--- +# Sensor + +- **[Sensor Overview](/pages/en/device/device/Subsystem%20Development/Sensor/Sensor%20Overview)** + +- **[Sensor Usage Guidelines](/pages/en/device/device/Subsystem%20Development/Sensor/Sensor%20Usage%20Guidelines)** + +- **[Sensor Usage Example](/pages/en/device/device/Subsystem%20Development/Sensor/Sensor%20Usage%20Example)** + + diff --git a/website/docs/extras/en/device-dev/subsystems/subsys-tel.md b/website/docs/extras/en/device-dev/subsystems/subsys-tel.md new file mode 100644 index 0000000000000000000000000000000000000000..dd8174d2ed244404a8d7c81f5771573cd6072712 --- /dev/null +++ b/website/docs/extras/en/device-dev/subsystems/subsys-tel.md @@ -0,0 +1,21 @@ +--- +title: "subsys-tel" +prepermalink: /extras/75efd89b92d7bbfda3c18d517d2afd6d/ +permalink: /extras/75efd89b92d7bbfda3c18d517d2afd6d/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/subsystems/subsys-tel.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [subsys-tel] +--- +# Subsystems + +- [Telephony Service](/pages/en/device/device/Subsystem%20Development/Telephony%20Service/Telephony%20Service) + - [Telephony Service](/pages/en/device/device/Subsystem%20Development/Telephony%20Service/Telephony%20Service) + - [Development Guidelines](/pages/en/device/device/Subsystem%20Development/Telephony%20Service/Development%20Guidelines) + diff --git a/website/docs/extras/en/device-dev/subsystems/subsys-testguide-envbuild.md b/website/docs/extras/en/device-dev/subsystems/subsys-testguide-envbuild.md new file mode 100644 index 0000000000000000000000000000000000000000..ad72889d445f9a5bba5f40054c7ac5e301823375 --- /dev/null +++ b/website/docs/extras/en/device-dev/subsystems/subsys-testguide-envbuild.md @@ -0,0 +1,97 @@ +--- +title: "subsys-testguide-envbuild" +prepermalink: /extras/1cadfdbd2f8e258e93402f3eb61ab9a8/ +permalink: /extras/1cadfdbd2f8e258e93402f3eb61ab9a8/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/subsystems/subsys-testguide-envbuild.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [subsys-testguide-envbuild] +--- +# Setting Up the Environment + +## Basic Test Framework Environment + +|Environment|Operating System|Linux Extended Component|Python|Python Plug-ins|NFS Server|HDC| +|------------|------------|------------|------------|------------|------------|------------| +|Version|Ubuntu 18.04 or later|libreadline-dev|3.7.5 or later|- pySerial 3.3 or later
- Paramiko 2.7.1 or later
- Setuptools 40.8.0 or later
- rsa4.0 or later|haneWIN NFS Server 1.2.50 or later, or NFS v4 or later| 1.1.0 or later| +|Description|Provides code build environment.|Plug-in used to read commands.|Language used by the test framework.|- pySerial: supports Python serial port communication.
- Paramiko: allows Python to use SSH.
- Setuptools: allows Python packages to be created and distributed easily.
- rsa: implements RSA encryption in Python.|Enables devices to be connected through the serial port.| A tool that enables devices to be connected through the HarmonyOS Device Connector (HDC).| + +## Installation Process +1. Run the following command to install the Linux extended component libreadline: + ``` + sudo apt-get install libreadline-dev + ``` + The installation is successful if the following information is displayed: + ``` + Reading package lists... Done + Building dependency tree + Reading state information... Done + libreadline-dev is already the newest version (7.0-3). + 0 upgraded, 0 newly installed, 0 to remove and 11 not upgraded. + ``` +2. Run the following command to install the Setuptools plug-in: + ``` + pip3 install setuptools + ``` + The installation is successful if the following information is displayed: + ``` + Requirement already satisfied: setuptools in d:\programs\python37\lib\site-packages (41.2.0) + ``` +3. Run the following command to install the Paramiko plug-in: + ``` + pip3 install paramiko + ``` + The installation is successful if the following information is displayed: + ``` + Installing collected packages: pycparser, cffi, pynacl, bcrypt, cryptography, paramiko + Successfully installed bcrypt-3.2.0 cffi-1.14.4 cryptography-3.3.1 paramiko-2.7.2 pycparser-2.20 pynacl-1.4.0 + ``` +4. Run the following command to install the ras plug-in: + ``` + pip3 install rsa + ``` + The installation is successful if the following information is displayed: + ``` + Installing collected packages: pyasn1, rsa + Successfully installed pyasn1-0.4.8 rsa-4.7 + ``` +5. Run the following command to install the pySerial plug-in: + ``` + pip3 install pyserial + ``` + The installation is successful if the following information is displayed: + ``` + Requirement already satisfied: pyserial in d:\programs\python37\lib\site-packages\pyserial-3.4-py3.7.egg (3.4) + ``` +6. Install the NFS server if the device outputs results only through the serial port. + - In Windows, install, for example, haneWIN NFS Server 1.2.50. + - In Linux, run the following command to install the NFS server: + ``` + sudo apt install nfs-kernel-server + ``` + The installation is successful if the following information is displayed: + ``` + Reading package lists... Done + Building dependency tree + Reading state information... Done + nfs-kernel-server is already the newest version (1:1.3.4-2.1ubuntu5.3). + 0 upgraded, 0 newly installed, 0 to remove and 11 not upgraded. + ``` +7. Install the HDC tool if the device supports HDC connections. For details about the installation process, see: + + https://gitee.com/openharmony/developtools_hdc_standard/blob/master/README.md + +## Checking the Environment + +| Check Item|Operation|Requirements| +| --- | --- | --- | +| Check whether Python is installed successfully.|Run the **python --version** command.|The Python version is 3.7.5 or later.| +| Check whether Python plug-ins are successfully installed.|Go to the **test/developertest** directory and run **start.bat** or **start.sh**.| The **>>>** prompt is displayed.| +|Check the NFS server status (for the devices that support only serial port output).|Log in to the development board through the serial port and run the **mount** command to mount the NFS.|The file directory can be mounted.| +|Check whether the HDC tool is successfully installed.|Run the **hdc_std -v** command.|The HDC version is 1.1.0 or later.| diff --git a/website/docs/extras/en/device-dev/subsystems/subsys-usbservice.md b/website/docs/extras/en/device-dev/subsystems/subsys-usbservice.md new file mode 100644 index 0000000000000000000000000000000000000000..f1d13766a748e1e0fbfa31e8224ba74c18be2888 --- /dev/null +++ b/website/docs/extras/en/device-dev/subsystems/subsys-usbservice.md @@ -0,0 +1,22 @@ +--- +title: "subsys-usbservice" +prepermalink: /extras/b369b4c707832a118f0debb612ae80e7/ +permalink: /extras/b369b4c707832a118f0debb612ae80e7/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/subsystems/subsys-usbservice.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [subsys-usbservice] +--- +# USB + +- **[USB Overview](/pages/en/device/device/Subsystem%20Development/USB/%5BUSB%20Overview)** + +- **[USB Usage Guidelines](/pages/en/device/device/Subsystem%20Development/USB/USB%20Usage%20Guidelines)** + +- **[USB Usage Example](/pages/en/device/device/Subsystem%20Development/USB/USB%20Usage%20Example)** \ No newline at end of file diff --git a/website/docs/extras/en/device-dev/subsystems/subsys-utils.md b/website/docs/extras/en/device-dev/subsystems/subsys-utils.md new file mode 100644 index 0000000000000000000000000000000000000000..228b2452f8c6801fd7836c7fdb0b9ff5f59cae28 --- /dev/null +++ b/website/docs/extras/en/device-dev/subsystems/subsys-utils.md @@ -0,0 +1,24 @@ +--- +title: "subsys-utils" +prepermalink: /extras/86c0c3274782b6d8968985efa173550a/ +permalink: /extras/86c0c3274782b6d8968985efa173550a/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/subsystems/subsys-utils.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [subsys-utils] +--- +# Utils + +- **[Utils Overview](/pages/en/device/device/Subsystem%20Development/Utils/Utils%20Overview)** + +- **[Utils Development Guidelines](/pages/en/device/device/Subsystem%20Development/Utils/Utils%20Development%20Guidelines)** + +- **[Utils FAQ](/pages/en/device/device/Subsystem%20Development/Utils/Utils%20FAQ)** + + diff --git a/website/docs/extras/en/device-dev/subsystems/subsys.md b/website/docs/extras/en/device-dev/subsystems/subsys.md new file mode 100644 index 0000000000000000000000000000000000000000..629986d6e41d45bb604387a3cd527559b304b61a --- /dev/null +++ b/website/docs/extras/en/device-dev/subsystems/subsys.md @@ -0,0 +1,50 @@ +--- +title: "subsys" +prepermalink: /extras/61a738db80a157de624ae1673a9578da/ +permalink: /extras/61a738db80a157de624ae1673a9578da/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/subsystems/subsys.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [subsys] +--- +# Subsystem Development Guidelines + +- **[Compilation and Building](/extras/2ce98dbc2719223219b20eb0f7d00e31/)** + +- **[Distributed Remote Startup](/pages/en/device/device/Subsystem%20Development/Distributed%20Remote%20Startup)** + +- **[Graphics](/extras/c0ebe908e23b0532ab29175059c8af86/)** + +- **[Multimedia](/extras/b47c31807da4c3c1d56185bd379d1d88/)** + +- **[Data Management](/extras/0f8610ee82cd7d9cc57373357c80c126/)** + +- **[Utils](/extras/86c0c3274782b6d8968985efa173550a/)** + +- **[AI Framework](/extras/ed79ebf1ef1b2b3a4fd6c31dfc897698/)** + +- **[Sensors](/extras/0661059c61750192d79b4d239fbb8b9f/)** + +- **[Application Framework](/extras/19da893c74d774705f66901ba9ac7e84/)** + +- **[OTA Upgrade](/pages/en/device/device/Subsystem%20Development/OTA%20Upgrade)** + +- **[Security](/extras/761e170abf654d46030b51062e52da28/)** + +- **[Startup](/extras/b03067b48ab81658870f4365d35e1754/)** + +- **[Testing](/pages/en/device/device/Debugging/Test%20Subsystem)** + +- **[DFX](/extras/23b00c9d5647ac514773855c0421a371/)** + +- **[R&D Tools](/pages/en/device/device/Debugging/R%26D%20Tools/R%26D%20Tools)** + +- **[XTS](/pages/en/device/device/XTS%20Certification/XTS)** + + diff --git a/website/docs/extras/en/device-dev/website.md b/website/docs/extras/en/device-dev/website.md new file mode 100644 index 0000000000000000000000000000000000000000..75f433f0f30064e52bb95eeb9f7ac2bc904c9eb2 --- /dev/null +++ b/website/docs/extras/en/device-dev/website.md @@ -0,0 +1,461 @@ +--- +title: "website" +prepermalink: /extras/ab3503eb8a9473d5aa59eb8ecc04bedd/ +permalink: /extras/ab3503eb8a9473d5aa59eb8ecc04bedd/ +relpath: "OpenHarmony-3.1-Release/en/device-dev/website.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [website] +--- +- [Device Development Guide](/pages/en/device/device/Device%20Development%20Guide) +- Quick Start + - Mini and Small Systems + - [Overview](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/Overview) + - Introduction + - [Hi3861 Development Board](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/Introduction/Hi3861%20Development%20Board) + - [Hi3516 Development Board](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/Introduction/Hi3516%20Development%20Board) + - [Hi3518 Development Board](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/Introduction/Hi3518%20Development%20Board) + - Environment Setup + - [Overview](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/Environment%20Setup/Overview) + - [Setting Up Windows Development Environment](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/Environment%20Setup/Setting%20Up%20Windows%20Development%20Environment) + - [Setting Up Ubuntu Development Environment](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/Environment%20Setup/Setting%20Up%20Ubuntu%20Development%20Environment) + - [FAQs](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/Environment%20Setup/FAQs) + - How to Develop + - Hi3861 + - [Setting Up the Environment](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/How%20to%20Develop/Hi3861/Setting%20Up%20the%20Environment) + - [Setting Up WLAN Connection](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/How%20to%20Develop/Hi3861/Setting%20Up%20WLAN%20Connection) + - [Running a Hello World Program](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/How%20to%20Develop/Hi3861/Running%20a%20Hello%20World%20Program) + - [FAQs](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/How%20to%20Develop/Hi3861/FAQs) + - Hi3516 + - [Setting Up the Environment](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/How%20to%20Develop/Hi3516/Setting%20Up%20the%20Environment) + - [Running a Hello OHOS Program](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/How%20to%20Develop/Hi3516/Running%20a%20Hello%20OHOS%20Program) + - [Developing a Driver](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/How%20to%20Develop/Hi3516/Developing%20a%20Driver) + - [FAQs](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/How%20to%20Develop/Hi3516/FAQs) + - Hi3518 + - [Setting Up the Environment](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/How%20to%20Develop/Hi3518/Setting%20Up%20the%20Environment) + - [Running a Hello OHOS Program](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/How%20to%20Develop/Hi3518/Running%20a%20Hello%20OHOS%20Program) + - [FAQs](/pages/en/device/device/Quick%20Start/Mini%20and%20Small%20Systems/How%20to%20Develop/Hi3518/FAQs) + - Standard System + - [Introduction](/pages/en/device/device/Quick%20Start/Standard%20System/Introduction) + - [Setting Up Windows Development Environment](/pages/en/device/device/Quick%20Start/Standard%20System/Setting%20Up%20Windows%20Development%20Environment) + - [Setting Up Ubuntu Development Environment in Docker Mode](/pages/en/device/device/Quick%20Start/Standard%20System/Setting%20Up%20Ubuntu%20Development%20Environment%20in%20Docker%20Mode) + - [Setting Up Ubuntu Development Environment with Installation Package](/pages/en/device/device/Quick%20Start/Standard%20System/Setting%20Up%20Ubuntu%20Development%20Environment%20with%20Installation%20Package) + - [Burning Images](/pages/en/device/device/Quick%20Start/Standard%20System/Burning%20Images) + - [Running an Image](/pages/en/device/device/Quick%20Start/Standard%20System/Running%20an%20Image) + - [FAQs](/pages/en/device/device/Quick%20Start/Standard%20System/FAQs) + - [Obtaining Source Code](/pages/en/device/device/Quick%20Start/Obtaining%20Source%20Code) +- Compatibility and Security + - [Privacy Protection](/pages/en/device/device/Compatibility%20and%20Security/Privacy%20Protection) + - [Security Guidelines](/pages/en/device/device/Compatibility%20and%20Security/Security%20Guidelines) +- Porting + - Mini System SoC Porting Guide + - Porting Preparations + - [Before You Start](/pages/en/device/device/Porting/Mini%20System%20SoC%20Porting%20Guide/Porting%20Preparations/Before%20You%20Start) + - [Building Adaptation Process](/pages/en/device/device/Porting/Mini%20System%20SoC%20Porting%20Guide/Porting%20Preparations/Building%20Adaptation%20Process) + - Kernel Porting + - [Overview](/pages/en/device/device/Porting/Mini%20System%20SoC%20Porting%20Guide/Kernel%20Porting/Overview) + - [Basic Kernel Adaptation](/pages/en/device/device/Porting/Mini%20System%20SoC%20Porting%20Guide/Kernel%20Porting/Basic%20Kernel%20Adaptation) + - [Kernel Porting Verification](/pages/en/device/device/Porting/Mini%20System%20SoC%20Porting%20Guide/Kernel%20Porting/Kernel%20Porting%20Verification) + - Board-Level OS Porting + - [Overview](/pages/en/device/device/Porting/Mini%20System%20SoC%20Porting%20Guide/Board-Level%20OS%20Porting/Overview) + - [Board-Level Driver Adaptation](/pages/en/device/device/Porting/Mini%20System%20SoC%20Porting%20Guide/Board-Level%20OS%20Porting/Board-Level%20Driver%20Adaptation) + - [Implementation of APIs at the HAL](/pages/en/device/device/Porting/Mini%20System%20SoC%20Porting%20Guide/Board-Level%20OS%20Porting/Implementation%20of%20APIs%20at%20the%20HAL) + - [System Modules](/pages/en/device/device/Porting/Mini%20System%20SoC%20Porting%20Guide/Board-Level%20OS%20Porting/System%20Modules) + - [lwIP Module Adaptation](/pages/en/device/device/Porting/Mini%20System%20SoC%20Porting%20Guide/Board-Level%20OS%20Porting/lwIP%20Module%20Adaptation) + - [Third-party Module Adaptation](/pages/en/device/device/Porting/Mini%20System%20SoC%20Porting%20Guide/Board-Level%20OS%20Porting/Third-party%20Module%20Adaptation) + - [XTS](/pages/en/device/device/Porting/Mini%20System%20SoC%20Porting%20Guide/Board-Level%20OS%20Porting/XTS) + - [FAQ](/pages/en/device/device/Porting/Mini%20System%20SoC%20Porting%20Guide/FAQ) + - Small System SoC Porting Guide + - Porting Preparations + - [Before You Start](/pages/en/device/device/Porting/Small%20System%20SoC%20Porting%20Guide/Porting%20Preparations/Before%20You%20Start) + - [Compilation and Building](/pages/en/device/device/Porting/Small%20System%20SoC%20Porting%20Guide/Porting%20Preparations/Compilation%20and%20Building) + - Kernel Porting + - [LiteOS Cortex-A](/pages/en/device/device/Porting/Small%20System%20SoC%20Porting%20Guide/Kernel%20Porting/LiteOS%20Cortex-A) + - [Linux Kernel](/pages/en/device/device/Porting/Small%20System%20SoC%20Porting%20Guide/Kernel%20Porting/Linux%20Kernel) + - Driver Porting + - [Overview](/pages/en/device/device/Porting/Small%20System%20SoC%20Porting%20Guide/Driver%20Porting/Overview) + - [Platform Driver Porting](/pages/en/device/device/Porting/Small%20System%20SoC%20Porting%20Guide/Driver%20Porting/Platform%20Driver%20Porting) + - [Device Driver Porting](/pages/en/device/device/Porting/Small%20System%20SoC%20Porting%20Guide/Driver%20Porting/Device%20Driver%20Porting) + - Standard System SoC Porting Guide + - [Standard System Porting Guide](/pages/en/device/device/Porting/Standard%20System%20SoC%20Porting%20Guide/Standard%20System%20Porting%20Guide) + - [A Method for Rapidly Porting the OpenHarmony Linux Kernel](/pages/en/device/device/Porting/Standard%20System%20SoC%20Porting%20Guide/A%20Method%20for%20Rapidly%20Porting%20the%20OpenHarmony%20Linux%20Kernel) + - Third-Party Library Porting Guide for Mini and Small Systems + - [Overview](/pages/en/device/device/Porting/Third-Party%20Library%20Porting%20Guide%20for%20Mini%20and%20Small%20Systems/Overview) + - [Porting a Library Built Using CMake](/pages/en/device/device/Porting/Third-Party%20Library%20Porting%20Guide%20for%20Mini%20and%20Small%20Systems/Porting%20a%20Library%20Built%20Using%20CMake) + - [Porting a Library Built Using Makefile](/pages/en/device/device/Porting/Third-Party%20Library%20Porting%20Guide%20for%20Mini%20and%20Small%20Systems/Porting%20a%20Library%20Built%20Using%20Makefile) +- Subsystem Development + - Kernel + - Kernel for Mini Systems + - [Kernel Overview](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Kernel%20Overview) + - Basic Kernel + - [Interrupt Management](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Basic%20Kernel/Interrupt%20Management) + - [Task Management](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Basic%20Kernel/Task%20Management) + - Memory Management + - [Basic Concepts](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Basic%20Kernel/Memory%20Management/Basic%20Concepts) + - [Static Memory](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Basic%20Kernel/Memory%20Management/Static%20Memory) + - [Dynamic Memory](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Basic%20Kernel/Memory%20Management/Dynamic%20Memory) + - Kernel Communication Mechanisms + - [Event](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Basic%20Kernel/Kernel%20Communication%20Mechanisms/Event) + - [Mutex](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Basic%20Kernel/Kernel%20Communication%20Mechanisms/Mutex) + - [Queue](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Basic%20Kernel/Kernel%20Communication%20Mechanisms/Queue) + - [Semaphore](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Basic%20Kernel/Kernel%20Communication%20Mechanisms/Semaphore) + - [Time Management](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Basic%20Kernel/Time%20Management) + - [Software Timer](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Basic%20Kernel/Software%20Timer) + - Extended Components + - [C++ Support](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Extended%20Components/C%2B%2B%20Support) + - [CPUP](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Extended%20Components/CPUP) + - [Dynamic Loading](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Extended%20Components/Dynamic%20Loading) + - File System + - [FAT](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Extended%20Components/File%20System/FAT) + - [LittleFS](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Extended%20Components/File%20System/LittleFS) + - Kernel Debugging + - Memory Debugging + - [Memory Information Statistics](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Kernel%20Debugging/Memory%20Debugging/Memory%20Information%20Statistics) + - [Memory Leak Check](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Kernel%20Debugging/Memory%20Debugging/Memory%20Leak%20Check) + - [Memory Corruption Check](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Kernel%20Debugging/Memory%20Debugging/Memory%20Corruption%20Check) + - [Exception Debugging](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Kernel%20Debugging/Exception%20Debugging) + - [Trace](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Kernel%20Debugging/Trace) + - [LMS](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Kernel%20Debugging/LMS) + - Appendix + - [Kernel Coding Specification](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Appendix/Kernel%20Coding%20Specification) + - Basic Data Structure + - [Doubly Linked List](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Appendix/Basic%20Data%20Structure/Doubly%20Linked%20List) + - Standard Libraries + - [CMSIS Support](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Appendix/Standard%20Libraries/CMSIS%20Support) + - [POSIX Support](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Mini%20Systems/Appendix/Standard%20Libraries/POSIX%20Support) + - Kernel for Small Systems + - [Kernel Overview](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Kernel%20Overview) + - Kernel Startup + - [Startup in Kernel Space](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Kernel%20Startup/Startup%20in%20Kernel%20Space) + - [Startup in User Space](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Kernel%20Startup/Startup%20in%20User%20Space) + - Basic Kernel + - [Interrupt and Exception Handling](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Interrupt%20and%20Exception%20Handling) + - Process Management + - [Process](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Process%20Management/Process) + - [Task](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Process%20Management/Task) + - [Scheduler](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Process%20Management/Scheduler) + - Memory Management + - [Heap Memory Management](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Memory%20Management/Heap%20Memory%20Management) + - [Physical Memory Management](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Memory%20Management/Physical%20Memory%20Management) + - [Virtual Memory Management](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Memory%20Management/Virtual%20Memory%20Management) + - [Virtual-to-Physical Mapping](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Memory%20Management/Virtual-to-Physical%20Mapping) + - Kernel Communication Mechanisms + - [Event](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Kernel%20Communication%20Mechanisms/Event) + - [Semaphore](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Kernel%20Communication%20Mechanisms/Semaphore) + - [Mutex](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Kernel%20Communication%20Mechanisms/Mutex) + - [Queue](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Kernel%20Communication%20Mechanisms/Queue) + - [RW Lock](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Kernel%20Communication%20Mechanisms/RW%20Lock) + - [Futex](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Kernel%20Communication%20Mechanisms/Futex) + - [Signal](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Kernel%20Communication%20Mechanisms/Signal) + - [Time Management](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Time%20Management) + - [Software Timer](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Software%20Timer) + - [Atomic Operation](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Basic%20Kernel/Atomic%20Operation) + - Extension Components + - [System Call](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Extension%20Components/System%20Call) + - [Dynamic Loading and Linking](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Extension%20Components/Dynamic%20Loading%20and%20Linking) + - [Virtual Dynamic Shared Object](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Extension%20Components/Virtual%20Dynamic%20Shared%20Object) + - [LiteIPC](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Extension%20Components/LiteIPC) + - File Systems + - [Virtual File System](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Extension%20Components/File%20Systems/Virtual%20File%20System) + - Supported File Systems + - [FAT](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Extension%20Components/File%20Systems/Supported%20File%20Systems/FAT) + - [JFFS2](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Extension%20Components/File%20Systems/Supported%20File%20Systems/JFFS2) + - [NFS](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Extension%20Components/File%20Systems/Supported%20File%20Systems/NFS) + - [Ramfs](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Extension%20Components/File%20Systems/Supported%20File%20Systems/Ramfs) + - [procfs](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Extension%20Components/File%20Systems/Supported%20File%20Systems/procfs) + - [File System Adaptation](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Extension%20Components/File%20Systems/File%20System%20Adaptation) + - Debugging and Tools + - Shell + - [Introduction to the Shell](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Introduction%20to%20the%20Shell) + - [Shell Command Development Guidelines](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Development%20Guidelines) + - [Shell Command Programming Example](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Programming%20Example) + - Shell Command Reference + - System Commands + - [cpup](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/cpup) + - [date](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/date) + - [dmesg](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/dmesg) + - [exec](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/exec) + - [free](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/free) + - [help](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/help) + - [hwi](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/hwi) + - [kill](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/kill) + - [log](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/log) + - [memcheck](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/memcheck) + - [oom](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/oom) + - [pmm](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/pmm) + - [reset](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/reset) + - [sem](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/sem) + - [stack](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/stack) + - [su](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/su) + - [swtmr](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/swtmr) + - [systeminfo](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/systeminfo) + - [task](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/task) + - [uname](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/uname) + - [vmm](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/vmm) + - [watch](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/System%20Commands/watch) + - File Commands + - [cat](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/cat) + - [cd](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/cd) + - [chgrp](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/chgrp) + - [chmod](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/chmod) + - [chown](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/chown) + - [cp](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/cp) + - [format](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/format) + - [ls](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/ls) + - [lsfd](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/lsfd) + - [mkdir](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/mkdir) + - [mount](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/mount) + - [partinfo](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/partinfo) + - [partition](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/partition) + - [pwd](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/pwd) + - [rm](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/rm) + - [rmdir](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/rmdir) + - [statfs](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/statfs) + - [sync](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/sync) + - [touch](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/touch) + - [writeproc](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/writeproc) + - [umount](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/File%20Commands/umount) + - Network Commands + - [arp](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/Network%20Commands/arp) + - [dhclient](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/Network%20Commands/dhclient) + - [ifconfig](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/Network%20Commands/ifconfig) + - [ipdebug](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/Network%20Commands/ipdebug) + - [netstat](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/Network%20Commands/netstat) + - [ntpdate](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/Network%20Commands/ntpdate) + - [ping](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/Network%20Commands/ping) + - [ping6](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/Network%20Commands/ping6) + - [telnet](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/Network%20Commands/telnet) + - [tftp](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Shell%20Command%20Reference/Network%20Commands/tftp) + - [Magic Key](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/Magic%20Key) + - [User-Space Exception Information](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Shell/User-Space%20Exception%20Information) + - [Trace](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Trace) + - [perf](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/perf) + - [LMS](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/LMS) + - Process Commissioning + - [CPUP](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Process%20Commissioning/CPUP) + - Memory Debugging + - [Memory Information Statistics](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Memory%20Debugging/Memory%20Information%20Statistics) + - [Memory Leak Check](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Memory%20Debugging/Memory%20Leak%20Check) + - [Memory Corruption Check](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Memory%20Debugging/Memory%20Corruption%20Check) + - User-Mode Memory Debugging + - [Basic Concepts](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/User-Mode%20Memory%20Debugging/Basic%20Concepts) + - [Working Principles](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/User-Mode%20Memory%20Debugging/Working%20Principles) + - Usage + - [API Description](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/User-Mode%20Memory%20Debugging/Usage/API%20Description) + - How to Use + - [Calling APIs](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/User-Mode%20Memory%20Debugging/Usage/How%20to%20Use/Calling%20APIs) + - [Using the CLI](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/User-Mode%20Memory%20Debugging/Usage/How%20to%20Use/Using%20the%20CLI) + - [Typical Memory Problems](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/User-Mode%20Memory%20Debugging/Typical%20Memory%20Problems) + - Other Kernel Debugging Methods + - [Dying Gasp](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Other%20Kernel%20Debugging%20Methods/Dying%20Gasp) + - [Common Fault Locating Methods](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Debugging%20and%20Tools/Other%20Kernel%20Debugging%20Methods/Common%20Fault%20Locating%20Methods) + - Appendix + - Basic Data Structure + - [Doubly Linked List](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Appendix/Basic%20Data%20Structure/Doubly%20Linked%20List) + - [Bitwise Operation](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Appendix/Basic%20Data%20Structure/Bitwise%20Operation) + - [Standard Library](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Small%20Systems/Appendix/Standard%20Library) + - Kernel for Standard Systems + - [Linux Kernel Overview](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Standard%20Systems/Linux%20Kernel%20Overview) + - [Applying Patches on OpenHarmony Development Boards](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Standard%20Systems/Applying%20Patches%20on%20OpenHarmony%20Development%20Boards) + - [Guidelines for Building the Linux Kernel](/pages/en/device/device/Subsystem%20Development/Kernel/Kernel%20for%20Standard%20Systems/Guidelines%20for%20Building%20the%20Linux%20Kernel) + - Driver + - HDF + - [HDF Overview](/pages/en/device/device/Subsystem%20Development/Driver/HDF/HDF%20Overview) + - [Driver Development](/pages/en/device/device/Subsystem%20Development/Driver/HDF/Driver%20Development) + - [Driver Service Management](/pages/en/device/device/Subsystem%20Development/Driver/HDF/Driver%20Service%20Management) + - [Driver Message Mechanism Management](/pages/en/device/device/Subsystem%20Development/Driver/HDF/Driver%20Message%20Mechanism%20Management) + - [Driver Configuration Management](/pages/en/device/device/Subsystem%20Development/Driver/HDF/Driver%20Configuration%20Management) + - [HDF Development Example](/pages/en/device/device/Subsystem%20Development/Driver/HDF/HDF%20Development%20Example) + - Platform Driver Development + - [ADC](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Development/ADC) + - [GPIO](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Development/GPIO) + - [HDMI](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Development/HDMI) + - [I2C](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Development/I2C) + - [I3C](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Development/I3C) + - [MIPI DSI](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Development/MIPI%20DSI) + - [MMC](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Development/MMC) + - [PWM](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Development/PWM) + - [RTC](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Development/RTC) + - [SDIO](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Development/SDIO) + - [SPI](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Development/SPI) + - [UART](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Development/UART) + - [Watchdog](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Development/Watchdog) + - Platform Driver Usage + - [ADC](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Usage/ADC) + - [GPIO](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Usage/GPIO) + - [HDMI](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Usage/HDMI) + - [I2C](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Usage/I2C) + - [I3C](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Usage/I3C) + - [MIPI DSI](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Usage/MIPI%20DSI) + - [PWM](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Usage/PWM) + - [RTC](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Usage/RTC) + - [SDIO](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Usage/SDIO) + - [SPI](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Usage/SPI) + - [UART](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Usage/UART) + - [Watchdog](/pages/en/device/device/Subsystem%20Development/Driver/Platform%20Driver%20Usage/Watchdog) + - Peripheral Driver Usage + - [LCD](/pages/en/device/device/Subsystem%20Development/Driver/Peripheral%20Driver%20Usage/LCD) + - [Touchscreen](/pages/en/device/device/Subsystem%20Development/Driver/Peripheral%20Driver%20Usage/Touchscreen) + - [Sensor](/pages/en/device/device/Subsystem%20Development/Driver/Peripheral%20Driver%20Usage/Sensor) + - [WLAN](/pages/en/device/device/Subsystem%20Development/Driver/Peripheral%20Driver%20Usage/WLAN) + - [Audio](/pages/en/device/device/Subsystem%20Development/Driver/Peripheral%20Driver%20Usage/Audio) + - [USB](/pages/en/device/device/Subsystem%20Development/Driver/Peripheral%20Driver%20Usage/USB) + - [Camera](/pages/en/device/device/Subsystem%20Development/Driver/Peripheral%20Driver%20Usage/Camera) + - Compilation and Building + - [Building Guidelines for Mini and Small Systems](/pages/en/device/device/Subsystem%20Development/Compilation%20and%20Building/Building%20Guidelines%20for%20Mini%20and%20Small%20Systems) + - [Building Guidelines for Standard Systems](/pages/en/device/device/Subsystem%20Development/Compilation%20and%20Building/Building%20Guidelines%20for%20Standard%20Systems) + - [Build System Coding Specifications and Best Practices](/pages/en/device/device/Subsystem%20Development/Compilation%20and%20Building/Build%20System%20Coding%20Specifications%20and%20Best%20Practices) + - [Building the Kconfig Visual Configuration](/pages/en/device/device/Subsystem%20Development/Compilation%20and%20Building/Building%20the%20Kconfig%20Visual%20Configuration) + - [Distributed Remote Startup](/pages/en/device/device/Subsystem%20Development/Distributed%20Remote%20Startup) + - Graphics + - [Graphics](/pages/en/device/device/Subsystem%20Development/Graphics/Graphics) + - [Development Guidelines on Container Components](/pages/en/device/device/Subsystem%20Development/Graphics/Development%20Guidelines%20on%20Container%20Components) + - [Development Guidelines on Layout Container Components](/pages/en/device/device/Subsystem%20Development/Graphics/Development%20Guidelines%20on%20Layout%20Container%20Components) + - [Development Guidelines on Common Components](/pages/en/device/device/Subsystem%20Development/Graphics/Development%20Guidelines%20on%20Common%20Components) + - [Development Guidelines on Animators](/pages/en/device/device/Subsystem%20Development/Graphics/Development%20Guidelines%20on%20Animators) + - Multimedia + - Camera + - [Overview](/pages/en/device/device/Subsystem%20Development/Multimedia/Camera/Overview) + - [Development Guidelines on Photographing](/pages/en/device/device/Subsystem%20Development/Multimedia/Camera/Development%20Guidelines%20on%20Photographing) + - [Development Guidelines on Video Recording](/pages/en/device/device/Subsystem%20Development/Multimedia/Camera/Development%20Guidelines%20on%20Video%20Recording) + - [Development Guidelines on Previewing](/pages/en/device/device/Subsystem%20Development/Multimedia/Camera/Development%20Guidelines%20on%20Previewing) + - Audio/Video + - [Overview](/pages/en/device/device/Subsystem%20Development/Multimedia/Audio%20Video/Overview) + - [Development Guidelines on Media Playback](/pages/en/device/device/Subsystem%20Development/Multimedia/Audio%20Video/Development%20Guidelines%20on%20Media%20Playback) + - [Development Guidelines on Media Recording](/pages/en/device/device/Subsystem%20Development/Multimedia/Audio%20Video/Development%20Guidelines%20on%20Media%20Recording) + - Utils + - [Utils Overview](/pages/en/device/device/Subsystem%20Development/Utils/Utils%20Overview) + - [Utils Development Guidelines](/pages/en/device/device/Subsystem%20Development/Utils/Utils%20Development%20Guidelines) + - [Utils FAQ](/pages/en/device/device/Subsystem%20Development/Utils/Utils%20FAQ) + - AI Framework + - [AI Engine Framework](/pages/en/device/device/Subsystem%20Development/AI%20Framework/AI%20Engine%20Framework) + - [Development Environment](/pages/en/device/device/Subsystem%20Development/AI%20Framework/Development%20Environment) + - Technical Specifications + - [Code Management](/pages/en/device/device/Subsystem%20Development/AI%20Framework/Technical%20Specifications/Code%20Management) + - [Naming](/pages/en/device/device/Subsystem%20Development/AI%20Framework/Technical%20Specifications/Naming) + - [API Development](/pages/en/device/device/Subsystem%20Development/AI%20Framework/Technical%20Specifications/API%20Development) + - Development Guidelines + - [SDK](/pages/en/device/device/Subsystem%20Development/AI%20Framework/Development%20Guidelines/SDK) + - [Plug-in](/pages/en/device/device/Subsystem%20Development/AI%20Framework/Development%20Guidelines/Plug-in) + - [Configuration File](/pages/en/device/device/Subsystem%20Development/AI%20Framework/Development%20Guidelines/Configuration%20File) + - Development Examples + - [KWS SDK](/pages/en/device/device/Subsystem%20Development/AI%20Framework/Development%20Examples/KWS%20SDK) + - [KWS Plug-in](/pages/en/device/device/Subsystem%20Development/AI%20Framework/Development%20Examples/KWS%20Plug-in) + - [KWS Configuration File](/pages/en/device/device/Subsystem%20Development/AI%20Framework/Development%20Examples/KWS%20Configuration%20File) + - Data Management + - RDB + - [RDB Overview](/pages/en/device/device/Subsystem%20Development/Data%20Management/RDB/RDB%20Overview) + - [RDB Development](/pages/en/device/device/Subsystem%20Development/Data%20Management/RDB/RDB%20Development) + - Lightweight Data Store + - [Lightweight Data Store Overview](/pages/en/device/device/Subsystem%20Development/Data%20Management/Lightweight%20Data%20Store/Lightweight%20Data%20Store%20Overview) + - [Lightweight Data Store Development](/pages/en/device/device/Subsystem%20Development/Data%20Management/Lightweight%20Data%20Store/Lightweight%20Data%20Store%20Development) + - Sensor + - [Sensor Overview](/pages/en/device/device/Subsystem%20Development/Sensor/Sensor%20Overview) + - [Sensor Usage Guidelines](/pages/en/device/device/Subsystem%20Development/Sensor/Sensor%20Usage%20Guidelines) + - [Sensor Usage Example](/pages/en/device/device/Subsystem%20Development/Sensor/Sensor%20Usage%20Example) + - USB + - [[USB Overview](/pages/en/device/device/Subsystem%20Development/USB/%5BUSB%20Overview) + - [USB Usage Guidelines](/pages/en/device/device/Subsystem%20Development/USB/USB%20Usage%20Guidelines) + - [USB Usage Example](/pages/en/device/device/Subsystem%20Development/USB/USB%20Usage%20Example) + - Application Framework + - [Overview](/pages/en/device/device/Subsystem%20Development/Application%20Framework/Overview) + - [Setting Up a Development Environment](/pages/en/device/device/Subsystem%20Development/Application%20Framework/Setting%20Up%20a%20Development%20Environment) + - [Development Guidelines](/pages/en/device/device/Subsystem%20Development/Application%20Framework/Development%20Guidelines) + - [Development Example](/pages/en/device/device/Subsystem%20Development/Application%20Framework/Development%20Example) + - [OTA Upgrade](/pages/en/device/device/Subsystem%20Development/OTA%20Upgrade) + - Telephony Service + - [Telephony Service](/pages/en/device/device/Subsystem%20Development/Telephony%20Service/Telephony%20Service) + - [Development Guidelines](/pages/en/device/device/Subsystem%20Development/Telephony%20Service/Development%20Guidelines) + - Security + - [Overview](/pages/en/device/device/Subsystem%20Development/Security/Overview) + - [Development Guidelines on Application Signature Verification](/pages/en/device/device/Subsystem%20Development/Security/Development%20Guidelines%20on%20Application%20Signature%20Verification) + - [Development Guidelines on Application Permission Management](/pages/en/device/device/Subsystem%20Development/Security/Development%20Guidelines%20on%20Application%20Permission%20Management) + - [Development Guidelines on IPC Authentication](/pages/en/device/device/Subsystem%20Development/Security/Development%20Guidelines%20on%20IPC%20Authentication) + - Startup + - [Startup](/pages/en/device/device/Subsystem%20Development/Startup/Startup) + - [init Module](/pages/en/device/device/Subsystem%20Development/Startup/init%20Module) + - [appspawn Module](/pages/en/device/device/Subsystem%20Development/Startup/appspawn%20Module) + - [bootstrap Module](/pages/en/device/device/Subsystem%20Development/Startup/bootstrap%20Module) + - [syspara Module](/pages/en/device/device/Subsystem%20Development/Startup/syspara%20Module) + - [FAQs](/pages/en/device/device/Subsystem%20Development/Startup/FAQs) + - [Reference](/pages/en/device/device/Subsystem%20Development/Startup/Reference) + - [Testing](/pages/en/device/device/Debugging/Test%20Subsystem) + - DFX + - [DFX](/pages/en/device/device/Subsystem%20Development/DFX/DFX) + - [HiLog Development](/pages/en/device/device/Subsystem%20Development/DFX/HiLog%20Development) + - [HiLog_Lite Development](/pages/en/device/device/Subsystem%20Development/DFX/HiLog_Lite%20Development) + - [HiTrace Development](/pages/en/device/device/Subsystem%20Development/DFX/HiTrace%20Development) + - [HiCollie Development](/pages/en/device/device/Subsystem%20Development/DFX/HiCollie%20Development) + - HiSysEvent Development + - [HiSysEvent Logging Configuration](/pages/en/device/device/Subsystem%20Development/DFX/HiSysEvent%20Development/HiSysEvent%20Logging%20Configuration) + - [HiSysEvent Logging](/pages/en/device/device/Subsystem%20Development/DFX/HiSysEvent%20Development/HiSysEvent%20Logging) + - [HiSysEvent Listening](/pages/en/device/device/Subsystem%20Development/DFX/HiSysEvent%20Development/HiSysEvent%20Listening) + - [HiSysEvent Query](/pages/en/device/device/Subsystem%20Development/DFX/HiSysEvent%20Development/HiSysEvent%20Query) + - [HiSysEvent Tool Usage](/pages/en/device/device/Subsystem%20Development/DFX/HiSysEvent%20Development/HiSysEvent%20Tool%20Usage) +- Featured Topics + - HPM Bundle + - [HPM Part Overview](/pages/en/device/device/Featured%20Topics/HPM%20Bundle/HPM%20Part%20Overview) + - [HPM Part Development](/pages/en/device/device/Featured%20Topics/HPM%20Bundle/HPM%20Part%20Development) + - [HPM Part Reference](/pages/en/device/device/Featured%20Topics/HPM%20Bundle/HPM%20Part%20Reference) +- Device Development Examples + - [Mini- and Small-System Devices](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Mini-%20and%20Small-System%20Devices) + - [WLAN-connected Products](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/WLAN-connected%20Products/WLAN-connected%20Products) + - [LED Peripheral Control](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/WLAN-connected%20Products/LED%20Peripheral%20Control) + - [Third-Party SDK Integration](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/WLAN-connected%20Products/Third-Party%20SDK%20Integration) + - [Cameras Without a Screen](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20Without%20a%20Screen/Cameras%20Without%20a%20Screen) + - [Camera Control](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20Without%20a%20Screen/Camera%20Control/Camera%20Control) + - [Overview](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20Without%20a%20Screen/Camera%20Control/Overview) + - [Development Guidelines](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20Without%20a%20Screen/Camera%20Control/Development%20Guidelines/Development%20Guidelines) + - [Photographing](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20Without%20a%20Screen/Camera%20Control/Development%20Guidelines/Photographing) + - [Video Recording](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20Without%20a%20Screen/Camera%20Control/Development%20Guidelines/Video%20Recording) + - [Use Case](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20Without%20a%20Screen/Camera%20Control/Use%20Case) + - [Cameras with a Screen](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20with%20a%20Screen/Cameras%20with%20a%20Screen) + - [Screen and Camera Control](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20with%20a%20Screen/Screen%20and%20Camera%20Control/Screen%20and%20Camera%20Control) + - [Overview](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20with%20a%20Screen/Screen%20and%20Camera%20Control/Overview) + - [Development Guidelines](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20with%20a%20Screen/Screen%20and%20Camera%20Control/Development%20Guidelines/Development%20Guidelines) + - [Photographing](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20with%20a%20Screen/Screen%20and%20Camera%20Control/Development%20Guidelines/Photographing) + - [Video Recording](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20with%20a%20Screen/Screen%20and%20Camera%20Control/Development%20Guidelines/Video%20Recording) + - [Previewing](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20with%20a%20Screen/Screen%20and%20Camera%20Control/Development%20Guidelines/Previewing) + - [Use Case](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20with%20a%20Screen/Screen%20and%20Camera%20Control/Use%20Case) + - [Visual Application Development](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20with%20a%20Screen/Visual%20Application%20Development/Visual%20Application%20Development) + - [Overview](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20with%20a%20Screen/Visual%20Application%20Development/Overview) + - [Preparations](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20with%20a%20Screen/Visual%20Application%20Development/Preparations) + - [Adding Pages](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20with%20a%20Screen/Visual%20Application%20Development/Adding%20Pages) + - [Building the Home Page](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20with%20a%20Screen/Visual%20Application%20Development/Building%20the%20Home%20Page) + - [Building the Details Page](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20with%20a%20Screen/Visual%20Application%20Development/Building%20the%20Details%20Page) + - [Debugging and Packaging](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20with%20a%20Screen/Visual%20Application%20Development/Debugging%20and%20Packaging) + - [Running on the Device](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20with%20a%20Screen/Visual%20Application%20Development/Running%20on%20the%20Device) + - [FAQs](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20with%20a%20Screen/Visual%20Application%20Development/FAQs) + - [Standard-System Devices](/pages/en/device/device/Device%20Development%20Examples/Standard-System%20Devices/Standard-System%20Devices) + - [Development Guidelines on Clock Apps](/pages/en/device/device/Device%20Development%20Examples/Standard-System%20Devices/Development%20Guidelines%20on%20Clock%20Apps) + - [Development Example for Platform Drivers](/pages/en/device/device/Device%20Development%20Examples/Standard-System%20Devices/Development%20Example%20for%20Platform%20Drivers) + - [Development Example for Peripheral Drivers](/pages/en/device/device/Device%20Development%20Examples/Standard-System%20Devices/Development%20Example%20for%20Peripheral%20Drivers) +- Debugging + - [Test Subsystem](/pages/en/device/device/Debugging/Test%20Subsystem) + - [R&D Tools](/pages/en/device/device/Debugging/R%26D%20Tools/R%26D%20Tools) + - [bytrace Usage Guidelines](/pages/en/device/device/Debugging/R%26D%20Tools/bytrace%20Usage%20Guidelines) + - [hdc_std Usage Guidelines](/pages/en/device/device/Debugging/R%26D%20Tools/hdc_std%20Usage%20Guidelines) +- XTS Certification + - [XTS](/pages/en/device/device/XTS%20Certification/XTS) +- Tools + - [Docker Environment](/pages/en/device/device/Tools/Docker%20Environment) + - [IDE](/pages/en/device/device/Tools/IDE) +- Hands-On Tutorials + - [Samples](https://gitee.com/openharmony/app_samples/blob/master/README.md) + - [Codelabs](https://gitee.com/openharmony/codelabs/blob/master/README.md) +- References + - FAQs + - [Overview of FAQs](/pages/en/device/device/References/FAQs/Overview%20of%20FAQs) + - [Environment Setup](/pages/en/device/device/References/FAQs/Environment%20Setup) + - [Compilation and Building Subsystem](/pages/en/device/device/References/FAQs/Compilation%20and%20Building%20Subsystem) + - [Burning](/pages/en/device/device/References/FAQs/Burning) + - [Kernel](/pages/en/device/device/References/FAQs/Kernel) + - [Porting](/pages/en/device/device/References/FAQs/Porting) + - [Startup](/pages/en/device/device/References/FAQs/Startup) + - [System Applications](/pages/en/device/device/References/FAQs/System%20Applications) \ No newline at end of file diff --git a/website/docs/extras/en/readme.md b/website/docs/extras/en/readme.md new file mode 100644 index 0000000000000000000000000000000000000000..6d34e852c4951df725b7b4286e71f34fbdcdc974 --- /dev/null +++ b/website/docs/extras/en/readme.md @@ -0,0 +1,98 @@ +--- +title: "readme" +prepermalink: /extras/1aaaaefbdefb26bd296cec91a5594d66/ +permalink: /extras/1aaaaefbdefb26bd296cec91a5594d66/ +relpath: "OpenHarmony-3.1-Release/en/readme.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [readme] +--- +# Overview + +This project stores OpenHarmony documentation, including the quick start guide, development guides, and API reference. We appreciate your contribution to the OpenHarmony documentation. + +## Contents + +- [OpenHarmony Overview](/pages/en/overview/OpenHarmony%20Project) +- Device development + - Mini and Small System Development Guidelines \(Reference Memory < 128 MB\) + - Device development + - **overview**: [Device Development Overview](/extras/69fd38f03840594f002cad0d5bad3962/) + - **quick-start**: [Quick Start](/extras/e1b285bd9b4b16964cbfeff3af87c98b/) \(covering environment setup, source code acquisition, build, and burning\) + - Basic development capabilities + - **Kernel**: [Kernel for Mini Systems](/extras/bf8496454cb9a8c0712aa081ac032dae/) + - **Kernel:**[Kernel for Small Systems](/extras/b1a8758905970b3469be3718a08589d4/) + - **Drivers**: [drivers](/extras/14d9c71d2671b2a4a270579c16336f6c/) + - **Subsystems**: [subsystems](/extras/d48e6372e0564ee89020c61c997fe13a/) \(such as compilation and building, graphics, DFX, and XTS\) + - **Security**: [privacy and security](/extras/f6ea01c30c3dafebebd15b2f9d77896c/) + - **guide**: + - [WLAN-connected Products](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/WLAN-connected%20Products/WLAN-connected%20Products) \(LED peripheral control and third-party SDK integration\) + - [Screenless Cameras](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20Without%20a%20Screen/Camera%20Control/Camera%20Control) \(camera control\) + - [Cameras with a Screen](/pages/en/device/device/Device%20Development%20Examples/Mini-%20and%20Small-System%20Devices/Cameras%20with%20a%20Screen/Cameras%20with%20a%20Screen) \(screen and camera control, visual application development\) + - **porting**: + - [Third-Party Library Porting Guide for Mini and Small Systems](/extras/9949eaeec6b11b95dd62f95a73f7c4cc/) + - [Mini System SoC Porting Guide](/extras/b4177a347580663ec15dd4c5ef19d569/) + - [Small System SoC Porting Guide](/extras/c9e561e6c3dae45fda2531abc17abcfa/) + - **bundles**: + - [HPM Bundle Development Specifications](https://www.openharmony.cn/404/device-dev/bundles/bundles-standard-rules.md) + - [HPM Bundle Development Guidelines](https://www.openharmony.cn/404/device-dev/bundles/bundles-guide.md) + - [HPM User Guide](https://www.openharmony.cn/404/device-dev/bundles/bundles-demo.md) + - Standard System Development Guidelines \(Reference Memory ≥ 128 MB\) + - Device development + - **overview**: [Device Development Overview](/extras/69fd38f03840594f002cad0d5bad3962/) + - **quick-start**: [Quick Start](/extras/e0c7fb7adf8f26e1f508dc8bd7bd89c7/) \(covering environment setup, source code acquisition, build, and burning\) + - Basic development capabilities + - **Kernel**: [Kernel for the Standard System](/extras/6b7b37f37bac90610514997ec2249095/) + - **Drivers**: [Drivers](/extras/14d9c71d2671b2a4a270579c16336f6c/) + - **Subsystems**: [Subsystems](/extras/d48e6372e0564ee89020c61c997fe13a/) \(such as compilation and building, graphics, DFX, and XTS\) + - **Security**: [Privacy and Security](/extras/f6ea01c30c3dafebebd15b2f9d77896c/) + - **guide**: + - [Development Guidelines on Clock Apps](/pages/en/device/device/Device%20Development%20Examples/Standard-System%20Devices/Development%20Guidelines%20on%20Clock%20Apps) + - [Development Example for Platform Drivers](/pages/en/device/device/Device%20Development%20Examples/Standard-System%20Devices/Development%20Example%20for%20Platform%20Drivers) + - [Development Example for Peripheral Drivers](/pages/en/device/device/Device%20Development%20Examples/Standard-System%20Devices/Development%20Example%20for%20Peripheral%20Drivers) + - **porting**: + - [Standard System SoC Porting Guide](/pages/en/device/device/Porting/Standard%20System%20SoC%20Porting%20Guide/Standard%20System%20Porting%20Guide) + - [A Method for Rapidly Porting the OpenHarmony Linux Kernel ](/pages/en/device/device/Porting/Standard%20System%20SoC%20Porting%20Guide/A%20Method%20for%20Rapidly%20Porting%20the%20OpenHarmony%20Linux%20Kernel) + - **bundles**: + - [HPM Bundle Development Specifications](https://www.openharmony.cn/404/device-dev/bundles/bundles-standard-rules.md) + - [HPM Bundle Development Guidelines](https://www.openharmony.cn/404/device-dev/bundles/bundles-guide.md) + - [HPM User Guide](https://www.openharmony.cn/404/device-dev/bundles/bundles-demo.md) + - [FAQs](/extras/9fc267037ba49a324b4bb03cd7f6abe7/) + + +- App development + - **Overview**: [Application Development Overview](/pages/en/app/application/Application%20Development%20Overview) + - **quick-start**: [Quick Start](/extras/9e490855207b24d31c829b990a496bab/) + - **ui**: [UI](https://www.openharmony.cn/404/application-dev/ui/Readme-EN.md) + - **media**: [Media](/extras/6c7e1611868af12071e07b3b820f6298/) + - **security**: [Security](/extras/f49961f963597b8b33da99dbbc96c4fe/) + - **connectivity**: [Connectivity](/extras/85a1b375c4c8c3286b1779df1f3dc372/) + - **Database**:[Data Management](https://www.openharmony.cn/404/application-dev/database/Readme-CN.md) + - **usb**: [USB Service](https://www.openharmony.cn/404/application-dev//usb/Readme-EN.md) + - **dfx**: [DFX](/extras/49e0a2bd226574ea119b2e39cf905f95/) + - **reference**: [Development References](/extras/a2937dfaaa001286821ae286f1e8e453/) +- **glossary**: [Glossary](/pages/en/overview/Glossary) + +## Version Change History + +For details, see [OpenHarmony Release Notes](/extras/348bb39c5ace3e332174966f24395f95/). + +## Third-Party Open-Source Software and License Notice + +3rd-Party-License: [Third-Party Open-Source Software and License Notice](/extras/b65f2031dbe607101ebe8d06484bdc98/) + + +## How to Contribute + +A great open-source project wouldn't be possible without the hard work of many contributors. We'd like to invite anyone from around the world to [participate](/pages/en/overview/Contribution/Contribution) in this exciting journey, and we're grateful for your time, passion, and efforts! + +You can evaluate available documents, make simple modifications, provide feedback on document quality, and contribute your original content. For details, see [Documentation Contribution](/pages/en/overview/Contribution/Documentation%20Contribution). + +Excellent contributors will be awarded and the contributions will be publicized in the developer community. + diff --git a/website/docs/extras/en/readme/DeviceProfile.md b/website/docs/extras/en/readme/DeviceProfile.md new file mode 100644 index 0000000000000000000000000000000000000000..e700cb6c85daf2875fcd00b42975978302d80392 --- /dev/null +++ b/website/docs/extras/en/readme/DeviceProfile.md @@ -0,0 +1,204 @@ +--- +title: "DeviceProfile" +prepermalink: /extras/3908b62527d30cc3057afabe9c9f1153/ +permalink: /extras/3908b62527d30cc3057afabe9c9f1153/ +relpath: "OpenHarmony-3.1-Release/en/readme/DeviceProfile.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [DeviceProfile] +--- +# DeviceProfile + +## Introduction + +DeviceProfile is used to manage device hardware capabilities and system software features. A typical device profile includes the device type, device name, OS type, and OS version. By allowing quick access to local and remote device profiles, DeviceProfile lays the foundation for initiating distributed services. It provides the following features: + +- Querying, inserting, and deleting local device profile information +- Querying remote device profile information +- Synchronizing profile information across devices +- Subscribing to remote device profile changes + +Below is the architecture of the DeviceProfile subsystem. + +## Architecture + +**Figure 1** Architecture of the DeviceProfile subsystem + +![](../../../images/en/readme/figures/8957dd0be50dbd91c1fe448621445dc7.png) + +## Directory Structure + +The main code directory structure of DeviceProfile is as follows: + +``` +├── interfaces +│   └── innerkits +│ └── distributeddeviceprofile // Internal APIs +├── ohos.build +├── sa_profile // SAID profile +│   ├── 6001.xml +│   └── BUILD.gn +├── services +│   └── distributeddeviceprofile +│   ├── BUILD.gn +│   ├── include +│ │ ├── contentsensor // Header file for content sensor data collection +│ │ ├── dbstorage // Header file for database operations +│ │ ├── devicemanager // Header file for device management +│ │ └── subscribemanager // Header file for subscription management +│   ├── src +│ │ ├── contentsensor // Implementation of content sensor data collection +│ │ ├── dbstorage // Implementation of database operations +│ │ ├── devicemanager // Implementation of device management +│ │ ├── subscribemanager // Implementation of subscription management +│ └── test // Test cases +└── tools + └── dp // Auxiliary test tool +``` + +## Constraints + +- The devices between which you want to set up a connection must be in the same LAN. +- Before setting up a connection between two devices, you must bind the devices. For details about the binding process, see relevant descriptions in the Security subsystem readme file. + +## Usage + +### Querying Profile Information + +* Parameters of GetDeviceProfile + +| Name| Type| Mandatory| Description| +| --------- | ---------------------------- | ---- | ----------------------------------- | +| deviceId | std::string | Yes| ID of the device whose profile is to be queried. A null value indicates the local device.| +| serviceId | std::string | Yes| Service ID (ID of the service data record).| +| profile | ServiceCharacteristicProfile | Yes| Return value.| + +* Example + +```c++ +// Declare the return value. +ServiceCharacteristicProfile profile; +// Call GetDeviceProfile. +DistributedDeviceProfileClient::GetInstance().GetDeviceProfile(deviceId, serviceId, profile); +std::string jsonData = profile.GetCharacteristicProfileJson(); +result.append("jsonData:" + jsonData + "\n"); +``` + +### Inserting Profile Information + +* Parameters of PutDeviceProfile + +| Name| Type| Mandatory| Description| +| --------- | ---------------------------- | ---- | ----------------------------------- | +| profile | ServiceCharacteristicProfile | Yes| Profile information to insert.| + +* Example + +```c++ +// Declare and fill in the data to insert. +ServiceCharacteristicProfile profile; +profile.SetServiceId(serviceId); +profile.SetServiceType(serviceType); +nlohmann::json j; +j["testVersion"] = "3.0.0"; +j["testApiLevel"] = API_LEVEL; +profile.SetCharacteristicProfileJson(j.dump()); +// Call PutDeviceProfile. +DistributedDeviceProfileClient::GetInstance().PutDeviceProfile(profile); +``` + +### Deleting Profile Information + +* Parameters of DeleteDeviceProfile + +| Name| Type| Mandatory| Description| +| --------- | ---------------------------- | ---- | ----------------------------------- | +| serviceId | std::string | Yes| ID of the service record to delete.| + +* Example + +```c++ +// Declare and fill in the data to delete. +std::string serviceId = "test"; +// DeleteDeviceProfile +DistributedDeviceProfileClient::GetInstance().DeleteDeviceProfile(serviceId); +``` + +### Synchronizing Profile Information + +* Parameters of SyncDeviceProfile + +| Name| Type| Mandatory| Description| +| --------- | ---------------------------- | ---- | ----------------------------------- | +| syncOption| SyncOption | Yes| Synchronization mode and range.| +| syncCb | IProfileEventCallback | Yes| Callback used to return the synchronization result.| + +* Example + +```c++ +// Define the synchronization mode and range. +SyncOptions syncOption; +syncOption.SetSyncMode((OHOS::DistributedKv::SyncMode)atoi(mode.c_str())); +for (const auto& deviceId : deviceIds) { + syncOption.AddDevice(deviceId); +} +// Call SyncDeviceProfile. +DistributedDeviceProfileClient::GetInstance().SyncDeviceProfile(syncOption, + std::make_shared()); +``` + +### Subscribing to Profile Events (Synchronization and Change Events) + +* Parameters of SubscribeProfileEvents + +| Name| Type| Mandatory| Description| +| -------------- | ---------------------------- | ---- | ----------------------------------- | +| subscribeInfos | SubscribeInfo | Yes| Type of the event to subscribe to.| +| eventCb | IProfileEventCallback | Yes| Callback for the subscribed event.| +| failedEvents | ProfileEvent | Yes| Failure event.| + +* Example + +```c++ +auto callback = std::make_shared(); +std::list subscribeInfos; +ExtraInfo extraInfo; +extraInfo["deviceId"] = deviceId; +extraInfo["serviceIds"] = serviceIds; + +// Subscribe to the EVENT_PROFILE_CHANGED event. +SubscribeInfo info1; +info1.profileEvent = ProfileEvent::EVENT_PROFILE_CHANGED; +info1.extraInfo = std::move(extraInfo); +subscribeInfos.emplace_back(info1); + +// Subscribe to the EVENT_SYNC_COMPLETED event. +SubscribeInfo info2; +info2.profileEvent = ProfileEvent::EVENT_SYNC_COMPLETED; +info2.extraInfo = std::move(extraInfo); +subscribeInfos.emplace_back(info2); + +std::list failedEvents; +// Call SubscribeProfileEvents. +DistributedDeviceProfileClient::GetInstance().SubscribeProfileEvents(subscribeInfos, + callback, failedEvents); +sleep(SUBSCRIBE_SLEEP_TIME); +std::list profileEvents; +profileEvents.emplace_back(ProfileEvent::EVENT_PROFILE_CHANGED); +failedEvents.clear(); +// Cancel the subscription. +DistributedDeviceProfileClient::GetInstance().UnsubscribeProfileEvents(profileEvents, + callback, failedEvents); +``` + +## Repositories Involved + +**DeviceProfile subsystem** + +[device\_profile\_core](https://gitee.com/openharmony/device_profile_core) diff --git a/website/docs/extras/en/readme/SAMGR.md b/website/docs/extras/en/readme/SAMGR.md new file mode 100644 index 0000000000000000000000000000000000000000..0400a027c70ebb6e52fe862ccb7e6e2dd29393ef --- /dev/null +++ b/website/docs/extras/en/readme/SAMGR.md @@ -0,0 +1,50 @@ +--- +title: "SAMGR" +prepermalink: /extras/07d9d6de8347a6792555d2431ff767bd/ +permalink: /extras/07d9d6de8347a6792555d2431ff767bd/ +relpath: "OpenHarmony-3.1-Release/en/readme/SAMGR.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [SAMGR] +--- +# System Ability Manager() + +## Introduction + +The System Ability Manager (SAMGR) subsystem implements the system service framework. It provides the functions of starting, registering, and querying system services, and querying cross-device distributed system services. + + +## System Architecture + +**Figure 1** SAMGR architecture + + +![](../../../images/en/readme/figures/e6a8d8c19aaab8ca3c6dd3f35095e8bd.png) + +## Directory Structure + +``` +/foundation/distributedschedule +├── safwk # System ability framework +├── samgr # System ability manager +├── safwk_lite # Lightweight foundation process +├── samgr_lite # Lightweight system ability manager +``` + +## Repositories Involved + +**SAMGR** + +distributedschedule\_safwk + +distributedschedule\_samgr + +distributedschedule\_safwk\_lite + +distributedschedule\_samgr\_lite diff --git a/website/docs/extras/en/readme/account.md b/website/docs/extras/en/readme/account.md new file mode 100644 index 0000000000000000000000000000000000000000..c13dc32ebd39e7c1086fd984b0bb5a923ee627a1 --- /dev/null +++ b/website/docs/extras/en/readme/account.md @@ -0,0 +1,54 @@ +--- +title: "account" +prepermalink: /extras/ebb55c31ab3865a7c6238edcf78b8074/ +permalink: /extras/ebb55c31ab3865a7c6238edcf78b8074/ +relpath: "OpenHarmony-3.1-Release/en/readme/account.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [account] +--- +# Account + +## Introduction + +In a standard system, the Account subsystem supports login status management of distributed cloud accounts, interconnection with vendors' cloud account apps on the device side, and query and update of the cloud account login status. + +## Architecture + +**Figure 1** Account subsystem architecture + + +![](../../../images/en/readme/figures/672af8e6e55de9ae6c88b16905da6320.png) + +## Directory Structure + +``` +/base/account +└── os_account # OS account module + ├── common # Common basic code + ├── interfaces # APIs exposed externally + ├── kits # Development framework + ├── sa_profile # SA profile + ├── services # Service code + └── test # Test code + └── resource # Test resources +``` + +## Usage Guidelines + +Using the available classes for managing distributed accounts, you can query and update the account login status, including login, logout, unregistration, and token expiration. + +To query and update the login status of a distributed account, you must obtain the required system permission. These APIs are supported only by system apps. + +## Repositories Involved + +**Account subsystem** + +account\_os\_account + diff --git a/website/docs/extras/en/readme/ai.md b/website/docs/extras/en/readme/ai.md new file mode 100644 index 0000000000000000000000000000000000000000..86a81fbdfdac514053d839d0c245505396e23c56 --- /dev/null +++ b/website/docs/extras/en/readme/ai.md @@ -0,0 +1,442 @@ +--- +title: "ai" +prepermalink: /extras/13a237d78cd1bfd1e9abdbf6f2a52a3a/ +permalink: /extras/13a237d78cd1bfd1e9abdbf6f2a52a3a/ +relpath: "OpenHarmony-3.1-Release/en/readme/ai.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [ai] +--- +# AI + +## Introduction + +The AI subsystem is the part of OpenHarmony that provides native distributed AI capabilities. At the heart of the subsystem is a unified AI engine framework, which implements quick integration of AI algorithm plug-ins. The framework consists of the plug-in management, module management, and communication management modules, fulfilling lifecycle management and on-demand deployment of AI algorithms. Under this framework, AI algorithm APIs will be standardized to facilitate distributed calling of AI capabilities. In addition, unified inference APIs will be provided to adapt to different inference framework hierarchies. + +**Figure 1** AI engine framework +![](../../../images/en/readme/figures/eec7621973283895d8f078ae2d592f24.png "ai-engine-framework") + +## Directory Structure + +``` +/foundation/ai/engine # Home directory of the AI subsystem +├── interfaces +│ └── kits # External APIs of the AI subsystem +└── services +│ ├── client # Client module of the AI subsystem +│ │ ├── client_executor # Executor of the client module +│ │ └── communication_adapter # Communication adaptation layer for the client module, with extension supported +│ ├── common # Common tools and protocol modules of the AI subsystem +│ │ ├── platform +│ │ ├── protocol +│ │ └── utils +│ └── server # Server module of the AI subsystem +│ │ ├── communication_adapter # Communication adaptation layer for the server module, with extension supported +│ │ ├── plugin +│ │ ├── asr +│ │ └── keyword_spotting # ASR algorithm plug-in reference: keyword spotting +│ │ └── cv +│ │ └── image_classification # CV algorithm plug-in reference: image classification +│ │ ├── plugin_manager +│ │ └── server_executor # Executor of the server module +``` + +## Constraints + +* **Programming language**: C/C++ + +* **Operating system**: OpenHarmony + +* **Others**: The System Ability Manager \(Samgr\) has been started and is running properly. + +## Usage + +1. Compile the AI subsystem. + + The source code for lightweight AI framework is available at **//foundation/ai/engine/services**. + + The compilation procedure is as follows: + + 1. Set the compilation path. + + ``` + hb set -root dir (root dir is the root directory of the project code.) + ``` + + 2. Specify the product for compilation. \(After the product list is displayed using the following command, move to the desired product with arrow keys and press **Enter**.\) + + ``` + hb set -p + ``` + + 3. Start compilation. + + ``` + hb build -f (Use this command if you want to compile the entire repository.) + hb build ai_engine (Use this command if you want to compile only the ai_engine module.) + ``` + + >**Note**: For details about the hb configuration, see the readme of the build\_lite subsystem. + +2. Develop the plug-in, with keyword spotting as an example. + + Directory: //foundation/ai/engine/services/server/plugin/asr/keyword\_spotting + + >**Note**: The plug-in must implement the **IPlugin** and **IPluginCallback** APIs provided by the server. + + ``` + #include "plugin/i_plugin.h + class KWSPlugin : public IPlugin { # Inherits the public base class of the IPlugin API for Keywords Spotting Plugin (KWSPlugin). + KWSPlugin(); + ~KWSPlugin(); + + const long long GetVersion() const override; + const char* GetName() const override; + const char* GetInferMode() const override; + + int32_t Prepare(long long transactionId, const DataInfo &amp;inputInfo, DataInfo &amp;outputInfo) override; + int32_t SetOption(int optionType, const DataInfo &amp;inputInfo) override; + int32_t GetOption(int optionType, const DataInfo &amp;inputInfo, DataInfo &amp;outputInfo) override; + int32_t SyncProcess(IRequest *request, IResponse *&amp;response) override; + int32_t AsyncProcess(IRequest *request, IPluginCallback*callback) override; + int32_t Release(bool isFullUnload, long long transactionId, const DataInfo &amp;inputInfo) override; + . + . + . + }; + ``` + + >**Note**: Depending on the algorithm in use, you only need to implement the **SyncProcess** or **AsyncProcess** API. Use an empty function as a placeholder for the other API. In this example, the KWS plug-in uses the synchronous algorithm. Therefore, you need to implement **SyncProcess** API and use an empty function as a placeholder for the **SyncProcess** API. + + ``` + #include "aie_log.h" + #include "aie_retcode_inner.h" + . + . + . + + const long long KWSPlugin::GetVersion() const + { + return ALGOTYPE_VERSION_KWS; + } + + const char *KWSPlugin::GetName() const + { + return ALGORITHM_NAME_KWS.c_str(); + } + + const char *KWSPlugin::GetInferMode() const + { + return DEFAULT_INFER_MODE.c_str(); + } + . + . + . + int32_t KWSPlugin::AsyncProcess(IRequest *request, IPluginCallback *callback) + { + return RETCODE_SUCCESS; + } + ``` + +3. Develop the SDK, with keyword spotting as an example. + + Directory: //foundation/ai/engine/services/client/algorithm\_sdk/asr/keyword\_spotting + + Keyword spotting SDK: + + ``` + class KWSSdk { + public: + KWSSdk(); + virtual ~KWSSdk(); + + /** + * @brief Create a new session with KWS Plugin + * + * @return Returns KWS_RETCODE_SUCCESS(0) if the operation is successful, + * returns a non-zero value otherwise. + */ + int32_t Create(); + + /** + * @brief Synchronously execute keyword spotting once + * + * @param audioInput pcm data. + * @return Returns KWS_RETCODE_SUCCESS(0) if the operation is successful, + * returns a non-zero value otherwise. + */ + int32_t SyncExecute(const Array &audioInput); + + /** + * @brief Asynchronously execute keyword spotting once + * + * @param audioInput pcm data. + * @return Returns KWS_RETCODE_SUCCESS(0) if the operation is successful, + * returns a non-zero value otherwise. + */ + int32_t AsyncExecute(const Array &audioInput); + + /** + * @brief Set callback + * + * @param callback Callback function that will be called during the process. + * @return Returns KWS_RETCODE_SUCCESS(0) if the operation is successful, + * returns a non-zero value otherwise. + */ + int32_t SetCallback(const std::shared_ptr &callback); + + /** + * @brief Destroy the created session with KWS Plugin + * + * @return Returns KWS_RETCODE_SUCCESS(0) if the operation is successful, + * returns a non-zero value otherwise. + */ + int32_t Destroy(); + ``` + + >**Note**: The sequence for the SDK to call client APIs of the AI engine is as follows: AieClientInit -\> AieClientPrepare -\> AieClientSyncProcess/AieClientAsyncProcess -\> AieClientRelease -\> AieClientDestroy. An exception will be thrown if the call sequence is violated. In addition, all these APIs must be called. Otherwise, a memory leakage may occur. + + ``` + int32_t KWSSdk::KWSSdkImpl::Create() + { + if (kwsHandle_ != INVALID_KWS_HANDLE) { + HILOGE("[KWSSdkImpl]The SDK has been created"); + return KWS_RETCODE_FAILURE; + } + if (InitComponents() != RETCODE_SUCCESS) { + HILOGE("[KWSSdkImpl]Fail to init sdk components"); + return KWS_RETCODE_FAILURE; + } + int32_t retCode = AieClientInit(configInfo_, clientInfo_, algorithmInfo_, nullptr); + if (retCode != RETCODE_SUCCESS) { + HILOGE("[KWSSdkImpl]AieClientInit failed. Error code[%d]", retCode); + return KWS_RETCODE_FAILURE; + } + if (clientInfo_.clientId == INVALID_CLIENT_ID) { + HILOGE("[KWSSdkImpl]Fail to allocate client id"); + return KWS_RETCODE_FAILURE; + } + DataInfo inputInfo = { + .data = nullptr, + .length = 0, + }; + DataInfo outputInfo = { + .data = nullptr, + .length = 0, + }; + retCode = AieClientPrepare(clientInfo_, algorithmInfo_, inputInfo, outputInfo, nullptr); + if (retCode != RETCODE_SUCCESS) { + HILOGE("[KWSSdkImpl]AieclientPrepare failed. Error code[%d]", retCode); + return KWS_RETCODE_FAILURE; + } + if (outputInfo.data == nullptr || outputInfo.length <= 0) { + HILOGE("[KWSSdkImpl]The data or length of output info is invalid"); + return KWS_RETCODE_FAILURE; + } + MallocPointerGuard pointerGuard(outputInfo.data); + retCode = PluginHelper::UnSerializeHandle(outputInfo, kwsHandle_); + if (retCode != RETCODE_SUCCESS) { + HILOGE("[KWSSdkImpl]Get handle from inputInfo failed"); + return KWS_RETCODE_FAILURE; + } + return KWS_RETCODE_SUCCESS; + } + + int32_t KWSSdk::KWSSdkImpl::SyncExecute(const Array &audioInput) + { + intptr_t newHandle = 0; + Array kwsResult = { + .data = nullptr, + .size = 0 + }; + DataInfo inputInfo = { + .data = nullptr, + .length = 0 + }; + DataInfo outputInfo = { + .data = nullptr, + .length = 0 + }; + int32_t retCode = PluginHelper::SerializeInputData(kwsHandle_, audioInput, inputInfo); + if (retCode != RETCODE_SUCCESS) { + HILOGE("[KWSSdkImpl]Fail to serialize input data"); + callback_->OnError(KWS_RETCODE_SERIALIZATION_ERROR); + return RETCODE_FAILURE; + } + retCode = AieClientSyncProcess(clientInfo_, algorithmInfo_, inputInfo, outputInfo); + if (retCode != RETCODE_SUCCESS) { + HILOGE("[KWSSdkImpl]AieClientSyncProcess failed. Error code[%d]", retCode); + callback_->OnError(KWS_RETCODE_PLUGIN_EXECUTION_ERROR); + return RETCODE_FAILURE; + } + if (outputInfo.data == nullptr || outputInfo.length <= 0) { + HILOGE("[KWSSdkImpl] The data or length of outputInfo is invalid. Error code[%d]", retCode); + callback_->OnError(KWS_RETCODE_NULL_PARAM); + return RETCODE_FAILURE; + } + MallocPointerGuard pointerGuard(outputInfo.data); + retCode = PluginHelper::UnSerializeOutputData(outputInfo, newHandle, kwsResult); + if (retCode != RETCODE_SUCCESS) { + HILOGE("[KWSSdkImpl]UnSerializeOutputData failed. Error code[%d]", retCode); + callback_->OnError(KWS_RETCODE_UNSERIALIZATION_ERROR); + return retCode; + } + if (kwsHandle_ != newHandle) { + HILOGE("[KWSSdkImpl]The handle[%lld] of output data is not equal to the current handle[%lld]", + (long long)newHandle, (long long)kwsHandle_); + callback_->OnError(KWS_RETCODE_PLUGIN_SESSION_ERROR); + return RETCODE_FAILURE; + } + callback_->OnResult(kwsResult); + return RETCODE_SUCCESS; + } + + int32_t KWSSdk::KWSSdkImpl::Destroy() + { + if (kwsHandle_ == INVALID_KWS_HANDLE) { + return KWS_RETCODE_SUCCESS; + } + DataInfo inputInfo = { + .data = nullptr, + .length = 0 + }; + int32_t retCode = PluginHelper::SerializeHandle(kwsHandle_, inputInfo); + if (retCode != RETCODE_SUCCESS) { + HILOGE("[KWSSdkImpl]SerializeHandle failed. Error code[%d]", retCode); + return KWS_RETCODE_FAILURE; + } + retCode = AieClientRelease(clientInfo_, algorithmInfo_, inputInfo); + if (retCode != RETCODE_SUCCESS) { + HILOGE("[KWSSdkImpl]AieClientRelease failed. Error code[%d]", retCode); + return KWS_RETCODE_FAILURE; + } + retCode = AieClientDestroy(clientInfo_); + if (retCode != RETCODE_SUCCESS) { + HILOGE("[KWSSdkImpl]AieClientDestroy failed. Error code[%d]", retCode); + return KWS_RETCODE_FAILURE; + } + mfccProcessor_ = nullptr; + pcmIterator_ = nullptr; + callback_ = nullptr; + kwsHandle_ = INVALID_KWS_HANDLE; + return KWS_RETCODE_SUCCESS; + } + ``` + +4. Develop a sample application. For details, see the [keyword spotting demo](https://gitee.com/openharmony/applications_sample_camera/tree/master/ai). + + Directory: //applications/sample/camera/ai/asr/keyword\_spotting + + Call the **Create** API. + + ``` + bool KwsManager::PreparedInference() + { + if (capturer_ == nullptr) { + printf("[KwsManager] only load plugin after AudioCapturer ready\n"); + return false; + } + if (plugin_ != nullptr) { + printf("[KwsManager] stop created InferencePlugin at first\n"); + StopInference(); + } + plugin_ = std::make_shared(); + if (plugin_ == nullptr) { + printf("[KwsManager] fail to create inferencePlugin\n"); + return false; + } + if (plugin_->Create() != SUCCESS) { + printf("[KwsManager] KWSSdk fail to create.\n"); + return false; + } + std::shared_ptr callback = std::make_shared(); + if (callback == nullptr) { + printf("[KwsManager] new Callback failed.\n"); + return false; + } + plugin_->SetCallback(callback); + return true; + } + ``` + + Call the **SyncExecute** API. + + ``` + void KwsManager::ConsumeSamples() + { + uintptr_t sampleAddr = 0; + size_t sampleSize = 0; + int32_t retCode = SUCCESS; + while (status_ == RUNNING) { + { + std::lock_guard lock(mutex_); + if (cache_ == nullptr) { + printf("[KwsManager] cache_ is nullptr.\n"); + break; + } + sampleSize = cache_->GetCapturedBuffer(sampleAddr); + } + if (sampleSize == 0 || sampleAddr == 0) { + continue; + } + Array input = { + .data = (int16_t *)(sampleAddr), + .size = sampleSize >> 1 + }; + { + std::lock_guard lock(mutex_); + if (plugin_ == nullptr) { + printf("[KwsManager] cache_ is nullptr.\n"); + break; + } + if ((retCode = plugin_->SyncExecute(input)) != SUCCESS) { + printf("[KwsManager] SyncExecute KWS failed with retCode = [%d]\n", retCode); + continue; + } + } + } + } + ``` + + Call the **Destroy** API. + + ``` + void KwsManager::StopInference() + { + printf("[KwsManager] StopInference\n"); + if (plugin_ != nullptr) { + int ret = plugin_->Destroy(); + if (ret != SUCCESS) { + printf("[KwsManager] plugin_ destroy failed.\n"); + } + plugin_ = nullptr; + } + } + ``` + + +## Repositories Involved + +[AI subsystem](https://gitee.com/openharmony/docs/blob/master/en/readme/ai.md) + +[ai_engine](https://gitee.com/openharmony/ai_engine) + +Dependency repositories: + +[build\_lite](https://gitee.com/openharmony/build_lite/blob/master/README.md) + +[distributedschedule\_samgr\_lite](https://gitee.com/openharmony/distributedschedule_samgr_lite/blob/master/README.md) + +[startup\_init\_lite](https://gitee.com/openharmony/startup_init_lite/blob/master/README.md) + +## Reference + +[AI Engine Framework Development Guide](https://gitee.com/openharmony/docs/blob/master/en/device-dev/subsystems/subsys-aiframework-guide.md) + + diff --git a/website/docs/extras/en/readme/ark-runtime.md b/website/docs/extras/en/readme/ark-runtime.md new file mode 100644 index 0000000000000000000000000000000000000000..14714695e5b1cfa30afb41505c934750fa32938f --- /dev/null +++ b/website/docs/extras/en/readme/ark-runtime.md @@ -0,0 +1,74 @@ +--- +title: "ark-runtime" +prepermalink: /extras/5cbe9c8a0f04d6d61af9e7e9f10f4084/ +permalink: /extras/5cbe9c8a0f04d6d61af9e7e9f10f4084/ +relpath: "OpenHarmony-3.1-Release/en/readme/ark-runtime.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [ark-runtime] +--- +# ARK Runtime Subsystem + +## Introduction + +ARK is a unified programming platform developed. Its key components include a compiler, toolchain, and runtime. ARK supports compilation and execution of high-level programming languages on the multiple hardware platform and accelerates the execution of the OpenHarmony operating system and its applications and services on mobile phones, PCs, tablets, TVs, automobiles, and smart wearables. The ARK-JS open sourced this time provides the capability of compiling and running the JavaScript \(JS\) language on the standard system of OpenHarmony. + +The ARK-JS consists of two parts: JS compiler toolchain and JS runtime. The JS compiler toolchain compiles JS source code into ARK bytecodes. The JS runtime executes the generated ARK bytecodes. Unless otherwise specified, bytecodes refer to ARK bytecodes in this document. + +The following figure shows the architecture of the JS compiler toolchain. + +![](../../../images/en/readme/figures/fa9f20beca9e819865c0aee8b54315dc.png) + +The JS front-end compiler parses the JS source code into an abstract syntax tree \(AST\), which is processed by the AST transformer, bytecode generator, and register allocator. The native emiter generates the ARK bytecode file \(.abc\). + +The following figure shows the JS runtime architecture. + +![](../../../images/en/readme/figures/bd1319e2bfb1a3be7736d9812ecf0d6b.png) + +ARK-JS Runtime runs ARK bytecode files to implement JS semantic logic. + +ARK-JS Runtime consists of the following: + +- Core Runtime + + Core Runtime consists of basic language-irrelevant runtime libraries, including ARK File, Tooling, and ARK Base. ARK File provides bytecodes. Tooling supports Debugger. ARK Base is responsible for implementing system calls. + +- Execution Engine + + The Execution Engine consists of an interpreter that executes bytecodes, Inline Caches that store hidden classes, and Profiler that analyzes and records runtime types. + +- ECMAScript Runtime + + ECMAScript Runtime consists of the JS object allocator, garbage collector \(GC\), and an internal library that supports ECMAScript specifications. + +- ARK Foreign Function Interface \(AFFI\) + + The AFFI provides a C++ function interface for ARK-JS runtime. + + +## Directory Structure + +``` +/ark +├── js_runtime # JS runtime module +├── runtime_core # Runtime common module +└── ts2abc # JS front-end tool +``` + +## Usage Guide + +[ARK-Runtime-Usage-Guide](https://gitee.com/openharmony/ark_js_runtime/blob/master/docs/ARK-Runtime-Usage-Guide.md) + +## Repositories Involved + +[ark\_runtime\_core](https://gitee.com/openharmony/ark_runtime_core) + +[ark\_js\_runtime](https://gitee.com/openharmony/ark_js_runtime) + +[ark\_ts2abc](https://gitee.com/openharmony/ark_ts2abc) diff --git a/website/docs/extras/en/readme/bundle-management.md b/website/docs/extras/en/readme/bundle-management.md new file mode 100644 index 0000000000000000000000000000000000000000..dceb470aac630f8ccab0c28bd9ab428cd22e1eef --- /dev/null +++ b/website/docs/extras/en/readme/bundle-management.md @@ -0,0 +1,197 @@ +--- +title: "bundle-management" +prepermalink: /extras/02bbaa52066f953b935faf5543664f38/ +permalink: /extras/02bbaa52066f953b935faf5543664f38/ +relpath: "OpenHarmony-3.1-Release/en/readme/bundle-management.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [bundle-management] +--- +# **Bundle Management** + +## Introduction + +The Bundle Management subsystem allows you to query, install, update, and uninstall capabilities for application bundles as well as store bundle information. + +Below is the architecture of the Bundle Management subsystem. + +![](../../../images/en/readme/figures/279f3a04dbc188b772b239d0542ef7cd.png) + + +## Responsibilities of Modules + +| Module Name | Description | +| ---------------- | ------------------------------------------------------------ | +| Bundle management interface module | 1. Provides external interfaces for installation, update, uninstallation, and notification.
2. Provides external interfaces for querying bundle, component, and permission information.
3. Provides external interfaces for querying application permissions.
4. Provides external interfaces for clearing data.| +| Scanning module | 1. Scans pre-installed applications.
2. Scans installed third-party applications.
3. Parses bundle configuration files.| +| Security management module | 1. Verifies signatures during installation.
2. Grants the permissions requested by the application during installation.
3. Verifies permissions during application running.| +| DBMS module | Obtains the ability information about a specified device. | +| Installation management module | Provides installation, update, and uninstallation logic processing and result notification. | +| Bundle information management module | Stores and synchronizes bundle and component information. | +| Device status listening module| Listens for the online and offline status changes of devices. | +| Installed module | Provides privileged processes for:
(1) Creating and deleting directories
(2) Creating and deleting files
(3) Sandbox UID/GID operations in the device directory| +| DFX | Provides bundle maintenance and testing. | + + +## Directory Structure + +``` +foundation/appexecfwk/standard +├── kits +│   └── appkit # Core code for Appkit implementation +├── common +│   └── log # Log component +├── interfaces +│   └── innerkits # Internal interfaces +├── services +│   └── bundlemgr # Framework code of the bundle management service +│   └── dbms # Framework code of the distributed bundle management service +├── test # Testing +└── tools # bm commands +``` + + +### bm Commands +bm is a tool used to facilitate debugging. It is encapsulated in the HDC tool. You can use it by running bm commands in the HDC shell. +| Command| Description| +| ------- | ---------- | +| help | Displays the commands supported by the bm tool.| +| install | Installs an application.| +| uninstall | Uninstalls an application.| +| dump | Queries application information.| +| clean | Clears the cache and data of an application.| +| enable | Enables an application.| +| disable | Disables an application.| +| get | Obtains the UDID of a device.| +#### Help Command +| Command| Description| +| ------- | ---------- | +| bm help | Displays the commands supported by the bm tool.| + +* Example +```Bash +# Display help information. +bm help +``` +#### Installation Command +This command can be run with different options to achieve different purposes. The table below lists some examples. +| Command| Description| +| ----------------------------------- | -------------------------- | +| bm install -h | Displays the commands supported by **install**.| +| bm install -p    | Installs HAPs. You can specify a path to install one or more HAPs at the same time.| +| bm install -p -u    |Installs a HAP for a specified user.| +| bm install -r -p | Installs a HAP in overwrite mode.| +| bm install -r -p -u | Installs a HAP for a specified user in overwrite mode.| + +* Example +```Bash +# Install a HAP. +bm install -p /data/app/ohosapp.hap +# Install a HAP in overwrite mode. +bm install -p /data/app/ohosapp.hap -r +``` +#### Uninstallation Command +This command can be run with different options to achieve different purposes. The table below lists some examples. If **-u** is not specified, the command applies to all users. +| Command| Description| +| ----------------------------- | ------------------------ | +| bm uninstall -h | Displays the commands supported by **uninstall**.| +| bm uninstall -n | Uninstalls an application based on the specified bundle name.| +| bm uninstall -n -u | Uninstalls an application based on the specified bundle name and user.| +| bm uninstall -n -m | Uninstalls a specific module of an application based on the specified bundle name.| + +* Example +```Bash +# Uninstall a HAP. +bm uninstall -n com.ohos.app +# Uninstall an ability of the HAP. +bm uninstall -n com.ohos.app -m com.ohos.app.MainAbility +``` +#### Query Command +This command can be run with different options to achieve different purposes. The table below lists some examples. If **-u** is not specified, the command applies to all users. +| Command| Description| +| ---------- | -------------------------- | +| bm dump -h | Displays the commands supported by **dump**.| +| bm dump -a | Queries all applications installed in the system.| +| bm dump -i | Queries details about all applications installed in the system.| +| bm dump -n | Queries details about a specified bundle.| +| bm dump -n -s | Queries the shortcut information of a specified bundle.| +| bm dump -n -d | Queries information about a bundle on a remote device.| +| bm dump -n -u | Queries details about a specified bundle of a specified user.| + +* Example +```Bash +# Display the names of all applications installed in the system. +bm dump -a +# Display details about a specific application. +bm dump -n com.ohos.app +``` +#### Clean Command +If **-u** is not specified, the command applies to all active users. +| Command| Description| +| ---------- | -------------------------- | +| bm clean -h | Displays the commands supported by **clean**.| +| bm clean -n -c | Clears the cache data of the specified bundle.| +| bm clean -n -d | Clears the data directory of the specified bundle.| +| bm clean -n -c -u | Clears the cached data of the specified bundle for the specified user.| +| bm clean -n -d -u | Clears the data directory of the specified bundle for the specified user.| + +* Example +```Bash +# Clear the cache data of the specified bundle. +bm clean -n com.ohos.app -c +# Clear the user data of the specified bundle. +bm clean -n com.ohos.app -d +``` +#### Enable Command +If **-u** is not specified, the command applies to all active users. +| Command| Description| +| ---------- | -------------------------- | +| bm enable -h | Displays the commands supported by **enable**.| +| bm enable -n | Enables the application that matches the specified bundle name.| +| bm enable -n -a | Enables a specific ability module of the application that matches the specified bundle name.| +| bm enable -n -u | Enables the application that matches the specified bundle name for the specified user.| + +* Example +```Bash +# Enable the specified application. +bm enable -n com.ohos.app +``` +#### Disable Command +If **-u** is not specified, the command applies to all active users. +| Command| Description| +| ---------- | -------------------------- | +| bm disable -h | Displays the commands supported by **disable**.| +| bm disable -n | Disables the application that matches the specified bundle name.| +| bm disable -n -a | Disables a specific ability module of the application that matches the specified bundle name.| +| bm disable -n -u | Disables the application that matches the specified bundle name for the specified user.| + +* Example +```Bash +# Disable the specified application. +bm disable -n com.ohos.app +``` +#### Command for Obtaining the UDID +| Command| Description| +| ---------- | -------------------------- | +| bm get -h | Displays the commands supported by **get**.| +| bm get -u | Obtains the UDID of a device.| + +* Example +```Bash +# Obtain the UDID of a device. +bm get -u +``` + +## Repositories Involved + +Bundle Management Subsystem + +**appexecfwk_standard** + +developtools_packing_tool diff --git a/website/docs/extras/en/readme/common-event-notification.md b/website/docs/extras/en/readme/common-event-notification.md new file mode 100644 index 0000000000000000000000000000000000000000..7d15ffbe9e338198aa456ae8039a68611349b6e3 --- /dev/null +++ b/website/docs/extras/en/readme/common-event-notification.md @@ -0,0 +1,60 @@ +--- +title: "common-event-notification" +prepermalink: /extras/6c92d77bda3cdf987f995ce50daf24a7/ +permalink: /extras/6c92d77bda3cdf987f995ce50daf24a7/ +relpath: "OpenHarmony-3.1-Release/en/readme/common-event-notification.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [common-event-notification] +--- +# Common Event and Notification + +## Introduction + +OpenHarmony provides a Common Event Service (CES) for applications to subscribe to, publish, and unsubscribe from common events. + +Common events in OpenHarmony are classified into system common events and custom common events. + +- System common event: sent by the system based on system policies to the applications that have subscribed to the event. This type of event is typically system events published by key system services, such as HAP installation, update, and uninstallation. + +- Custom common events: customized by applications to implement cross-application event communication. + +Each application can subscribe to common events as required. After your application subscribes to a common event, the system sends it to your application every time the event is published. Such an event may be published by the system, other applications, or your own application. + +### Architecture + + + +## Directory Structure + +``` +/base/notification/ces_standard/ +│── frameworks # Component directory +│ |── common/log # Logs +│ |── core # Internal implementation code of native APIs +│ ├── native # Implementation code of native APIs +│── interface # External APIs +| |── innerkits # Definition of native APIs +| |── kits/napi # NAPI implementation +├── sa_profile # Service configuration profile +├── services # Service implementation +├── tools # Tools +│── ohos.build # Build script + +``` + +## How to Use + +For details, see *CommonEvent Development Guidelines*. + +## Repositories Involved + +Common Event and Notification + +**notification_ces_standard** diff --git a/website/docs/extras/en/readme/dfx.md b/website/docs/extras/en/readme/dfx.md new file mode 100644 index 0000000000000000000000000000000000000000..127b8abc81d4220ec3c186825768d72a2db480e5 --- /dev/null +++ b/website/docs/extras/en/readme/dfx.md @@ -0,0 +1,71 @@ +--- +title: "dfx" +prepermalink: /extras/d99080770180e1de37bb60812c77f873/ +permalink: /extras/d99080770180e1de37bb60812c77f873/ +relpath: "OpenHarmony-3.1-Release/en/readme/dfx.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [dfx] +--- +# DFX + +## Introduction + +[Design for X](https://en.wikipedia.org/wiki/Design_for_X) \(DFX\) refers to the software design that aims to improve the quality attribute in OpenHarmony. It mainly consists of two parts: design for reliability \(DFR\) and design for testability \(DFT\). + +The DFX subsystem provides the following capabilities: + +- HiLog: Implements logging. + +- Hiview: Functions as the plug-in platform. +- FaultLoggerd: Implements fault information collection and subscription. +- HiAppEvent: Implements logging of application events. +- HiSysEvent: Implements logging of system events. + +## Architecture + +**Figure 1** Architecture of the DFX subsystem + + +![](../../../images/en/readme/figures/c1a0815c9dc026d522958bf104c9d3d3.png) + +## Directory Structure + +``` +base/hiviewdfx # DFX base repository, which stores compilation-related configurations +├── hiview # Hiview module, which implements the plug-in platform and event handler capabilities +├── hiview_lite # Hiview_Lite module, which implements the logging task capability for the mini system +├── hilog # HiLog module, which implements logging for the system +├── hilog_lite # HiLog_Lite module, which implements logging for the mini and small systems +├── hievent_lite # HiEvent_Lite module, which implements event logging for the mini system +├── hiappevent # HiAppEvent module, which implements application event logging framework and APIs +├── hisysevent # HiSysEvent module, which implements system event logging APIs and services +├── faultloggerd # FaultLoggerd module, which implements collection of application fault logs +``` + +## Repositories Involved + +**DFX subsystem** + +[hiviewdfx\_hiview](https://gitee.com/openharmony/hiviewdfx_hiview/blob/master/README.md) + +[hiviewdfx\_hilog](https://gitee.com/openharmony/hiviewdfx_hilog/blob/master/README.md) + +[hiviewdfx\_hiappevent](https://gitee.com/openharmony/hiviewdfx_hiappevent/blob/master/README.md) + +[hiviewdfx\_hisysevent](https://gitee.com/openharmony/hiviewdfx_hisysevent/blob/master/README.md) + +[hiviewdfx\_faultloggerd](https://gitee.com/openharmony/hiviewdfx_faultloggerd/blob/master/README.md) + +[hiviewdfx\_hilog\_lite](https://gitee.com/openharmony/hiviewdfx_hilog_lite/blob/master/README.md) + +[hiviewdfx\_hievent\_lite](https://gitee.com/openharmony/hiviewdfx_hievent_lite/blob/master/README.md) + +[hiviewdfx\_hiview\_lite](https://gitee.com/openharmony/hiviewdfx_hiview_lite/blob/master/README.md) + diff --git a/website/docs/extras/en/readme/distributed-data-management.md b/website/docs/extras/en/readme/distributed-data-management.md new file mode 100644 index 0000000000000000000000000000000000000000..786dd186a3f31784f7e8306ff420c0404718fdbc --- /dev/null +++ b/website/docs/extras/en/readme/distributed-data-management.md @@ -0,0 +1,116 @@ +--- +title: "distributed-data-management" +prepermalink: /extras/bd82bb3bb25cf285d45794f8aee4ecd2/ +permalink: /extras/bd82bb3bb25cf285d45794f8aee4ecd2/ +relpath: "OpenHarmony-3.1-Release/en/readme/distributed-data-management.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [distributed-data-management] +--- +# Distributed Data Management + +## Introduction + +**About the Subsystem** + +The Distributed Data Management subsystem can persistently store various structured data of a single device and also supports data synchronization and sharing across devices. In this regard, you can seamlessly integrate distributed application data among different devices, ensuring consistent user experience in the same application across these devices. + +- Local data management + + This module allows you to store and access structured data on a single device. It uses the SQLite engine to provide the relational database \(RDB\) and preferences database. With these databases, you can persistently store and access app data using different models. + + +- Distributed data service + + This service can synchronize data across devices, so that users can access consistent data on different devices. DDS isolates data based on a triplet of the account, app, and database. DDS synchronizes data between trusted devices to provide the cross-device data access capability. + + +**Architecture of the Subsystem** + +**Figure 1** Architecture + + +![](../../../images/en/readme/figures/07234075c00d5da0a46540b68920965b.png) + +## Directory Structure + +Level 1 and 2 directories of the distributed data management subsystem are as follows: + +``` +distributeddatamgr/ # Distributed data management +├── appdatamgr # Local data management +└── distributeddatamgr # Distributed Data Service + +third_party/ # Open-source software +├── flatbuffers # flatbuffers code +└── sqlite # SQLite code +``` + +## Usage + +### Local Data Management + +- Relational database \(RDB\) + + Some basic concepts are as follows: + + - **RDB** + + A database created on the basis of relational models. The RDB stores data in rows and columns. + + - **Result set** + + A set of query results used to access the data. You can access the required data in a result set in flexible modes. + + - **SQLite database** + + A lightweight RDB in compliance with the atomicity, consistency, isolation, and durability \(ACID\) properties. It is an open-source database. + + +- Preferences database + + Some basic concepts are as follows: + + - **Key-value database** + + A database that stores data in key-value pairs. The **key** indicates keyword, and **value** indicates the corresponding value. + + - **Non-relational database** + + A database not in compliance with the atomicity, consistency, isolation, and durability \(ACID\) database management properties of relational data transactions. Instead, the data in a non-relational database is independent and scalable. + + - **Preference** **data** + + A type of data that is frequently accessed and used. + + + +### Distributed Data Service + +DDS provides apps with the capability to store data in the databases of different devices. It uses the KV data model. + +- **KV data model** + + KV is short for key-value. The KV database is a type of NoSQL database. Data in this type of database is organized, indexed, and stored in the form of key-value pairs. + + The KV data model is suitable for storing service data that does not involve too many data or service relationships. It provides better read and write performance than the SQL database. The KV data model is widely used in distributed scenarios because it handles conflict more easily in database version compatibility and data synchronization. The distributed database is based on the KV data model and provides KV-based access interfaces. + + +## Repositories Involved + +Distributed Data Management subsystem + +distributeddatamgr\_appdatamgr + +distributeddatamgr\_distributeddatamgr + +third\_party\_sqlite + +third\_party\_flatbuffers + diff --git a/website/docs/extras/en/readme/distributed-file.md b/website/docs/extras/en/readme/distributed-file.md new file mode 100644 index 0000000000000000000000000000000000000000..92943e67f5399ed0b3beb6debe9123769761b432 --- /dev/null +++ b/website/docs/extras/en/readme/distributed-file.md @@ -0,0 +1,284 @@ +--- +title: "distributed-file" +prepermalink: /extras/c403293d19298f4c84be1acc348c9182/ +permalink: /extras/c403293d19298f4c84be1acc348c9182/ +relpath: "OpenHarmony-3.1-Release/en/readme/distributed-file.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [distributed-file] +--- +# Distributed File + +## Introduction + +Currently, the Distributed File subsystem provides apps with JavaScript APIs for I/O capabilities, including APIs for managing files and directories, obtaining file information, reading and writing data streams of files, and receiving URIs rather than absolute paths. + +### Architecture + +Currently, the Distributed File subsystem provides only local JavaScript file APIs for apps through the FileIO and File modules. The Distributed File subsystem uses LibN to abstract APIs at the NAPI layer, providing basic capabilities such as the basic type system, memory management, and general programming models for the subsystem. This subsystem depends on the engine layer of the JS application development framework to provide the capability of converting JavaScript APIs into C++ code, depends on the application framework to provide app-related directories, and depends on the GLIBC runtimes to provide I/O capabilities. + +**Figure 1** Distributed File subsystem architecture +![](../../../images/en/readme/figures/3c037e255ea43d4c301b959fecd6bad8.png "distributed-file-subsystem-architecture") + +## Directory Structure + +``` +foundation/distributeddatamgr/distributedfile +└── interfaces # APIs + └── kits # APIs exposed externally +``` + +## Constraints + +Constraints on local I/O APIs: + +- Only UTF-8/16 encoding is supported. +- The URIs cannot include external storage directories. + +## Usage + +### Available APIs + +Currently, the Distributed File subsystem provides APIs for accessing local files and directories. The following table describes the API types classified by function. + +**Table 1** API types + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

API Type

+

Function

+

Related Module

+

Example API (Class Name.Method Name)

+

Basic file API

+

Creates, modifies, and accesses files, and changes file permissions based on the specified absolute paths or file descriptors.

+

@OHOS.distributedfile.fileio

+

accessSync

+

chownSync

+

chmodSync

+

Basic directory API

+

Reads directories and determines file types based on the specified absolute paths.

+

@OHOS.distributedfile.fileio

+

Dir.openDirSync

+

Basic statistical API

+

Collects basic statistics including the file size, access permission, and modification time based on the specified absolute paths.

+

@OHOS.distributedfile.fileio

+

Stat.statSync

+

Streaming file API

+

Reads and writes data streams of files based on the specified absolute paths or file descriptors.

+

@OHOS.distributedfile.fileio

+

Stream.createStreamSync

+

Stream.fdopenStreamSync

+

Sandbox file API

+

Provides a subset or a combination of the capabilities provided by the basic file, directory, and statistical APIs based on the specified URIs.

+

@system.file

+

move

+

copy

+

list

+
+ +The URIs used in sandbox file APIs are classified into three types, as described in the following table. + +**Table 2** URI types + + + + + + + + + + + + + + + + + + + + + + + + +

Directory Type

+

Prefix

+

Access Visibility

+

Description

+

Temporary directory

+

internal://cache/

+

Current app only

+

Readable and writable, and can be cleared at any time. This directory is usually used for temporary downloads or caches.

+

Private directory of an app

+

internal://app/

+

Current app only

+

Deleted when the app is uninstalled.

+

External storage

+

internal://share/

+

All apps

+

Deleted when the app is uninstalled. Other apps with granted permissions can read and write files in this directory.

+
+ +### Usage Guidelines + +The I/O APIs provided by the Distributed File subsystem can be classified into the following types based on the programming model: + +- Synchronous programming model + + APIs whose names contain **Sync** are implemented as a synchronous model. When a synchronous API is called, the calling process waits until a value is returned. + + The following example opens a file stream in read-only mode, attempts to read the first 4096 bytes, converts them into a UTF-8-encoded string, and then closes the file stream: + + ``` + import fileio from '@OHOS.distributedfile.fileio'; + + try { + var ss = fileio.Stream.createStreamSync("tmp", "r") + buf = new ArrayBuffer(4096) + ss.readSync(buf) + console.log(String.fromCharCode.apply(null, new Uint8Array(buf))) + ss.closeSync() + } + catch (e) { + console.log(e); + } + ``` + + +- Asynchronous programming model: Promise + + In the **@OHOS.distributedfile.fileio** module, the APIs whose names do not contain **Sync** and to which a callback is not passed as their input parameter are implemented as the Promise asynchronous model. The Promise asynchronous model is one of the OHOS standard asynchronous models. When an asynchronous API using the Promise model is called, the API returns a Promise object while executing the concerned task asynchronously. The Promise object represents the asynchronous operation result. When there is more than one result, the results are returned as properties of the Promise object. + + In the following example, a Promise chain is used to open a file stream in read-only mode, attempt to read the first 4096 bytes of the file, display the length of the content read, and then close the file: + + ``` + import fileio from '@OHOS.distributedfile.fileio'; + + try { + let openedStream + fileio.Stream.createStream("test.txt", "r") + .then(function (ss) { + openedStream = ss; + return ss.read(new ArrayBuffer(4096)) + }) + .then(function (res) { + console.log(res.bytesRead); + console.log(String.fromCharCode.apply(null, new Uint8Array(res.buffer))) + return openedStream.close() + }) + .then(function (undefined) { + console.log("Stream is closed") + }) + .catch(function (e) { + console.log(e) + }) + } catch (e) { + console.log(e) + } + ``` + + +- Asynchronous programming model: Callback + + In the **@OHOS.distributedfile.fileio** module, the APIs whose names do not contain **Sync** and to which a callback is directly passed as their input parameter are implemented as the callback asynchronous model. The callback asynchronous model is also one of the OHOS standard asynchronous models. When an asynchronous API with a callback passed is called, the API executes the concerned task asynchronously and returns the execution result as the input parameters of the registered callback. The first parameter is of the **undefined** or **Error** type, indicating that the execution succeeds or fails, respectively. + + The following example creates a file stream asynchronously, reads the first 4096 bytes of the file asynchronously in the callback invoked when the file stream is created, and then closes the file asynchronously in the callback invoked when the file is read: + + ``` + import fileio from '@OHOS.distributedfile.fileio'; + + try { + fileio.Stream.createStream("./testdir/test_stream.txt", "r", function (err, ss) { + if (!err) { + ss.read(new ArrayBuffer(4096), {}, function (err, buf, readLen) { + if (!err) { + console.log('readLen: ' + readLen) + console.log('data: ' + String.fromCharCode.apply(null, new Uint8Array(buf))) + } else { + console.log('Cannot read from the stream ' + err) + } + ss.close(function (err) { + console.log(`Stream is ${err ? 'not' : ''}closed`) + }); + }) + } else { + console.log('Cannot open the stream ' + err) + } + }) + } catch (e) { + console.log(e) + } + ``` + + +- Asynchronous programming model: Legacy + + All APIs in the **@system.file** module are implemented as the legacy asynchronous model. When calling such an API, you need to implement three callbacks \(including **success**, **fail**, and **complete**\) to be invoked when the execution is successful, fails, or is complete, respectively. If the input parameters are correct, the API calls the **success** or **fail** callback based on whether the asynchronous task is successful after the task execution is complete, and finally calls the **complete** callback. + + The following example asynchronously checks whether the file pointed to by the specified URI exists and provides three callbacks to print the check result: + + ``` + import file from '@system.file' + + file.access({ + uri: 'internal://app/test.txt', + success: function() { + console.log('call access success.'); + }, + fail: function(data, code) { + console.error('call fail callback fail, code: ' + code + ', data: ' + data); + }, + complete: function () { + console.log('call access finally.'); + } + }); + + console.log("file access tested done") + ``` + + +## Repositories Involved + +**Distributed File subsystem** + +distributeddatamgr_distributedfile + diff --git a/website/docs/extras/en/readme/driver-subsystem.md b/website/docs/extras/en/readme/driver-subsystem.md new file mode 100644 index 0000000000000000000000000000000000000000..076de4914633857a1665c223044c8e78c6bb232f --- /dev/null +++ b/website/docs/extras/en/readme/driver-subsystem.md @@ -0,0 +1,164 @@ +--- +title: "driver-subsystem" +prepermalink: /extras/13f58a706f3563be25a691f63b399b51/ +permalink: /extras/13f58a706f3563be25a691f63b399b51/ +relpath: "OpenHarmony-3.1-Release/en/readme/driver-subsystem.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [driver-subsystem] +--- +# Driver Subsystem + +## Overview + +The OpenHarmony driver subsystem is constructed using the C object-oriented programming \(OOP\). It provides a unified driver platform through platform decoupling, kernel decoupling, and compatible kernels. This unified driver architecture platform is designed to provide a more precise and efficient development environment, where you develop a driver that can be deployed on different systems supporting HDF. + +The OpenHarmony driver subsystem provides the following key features and capabilities to shorten the driver development period and make third-party device driver integration much easier: + +- Flexible framework capabilities + + Based on the traditional driver framework, the OpenHarmony driver subsystem builds flexible framework capabilities to deploy terminal products with the capacity ranging from hundreds KB to hundreds MB of memory. + + +- Standardized driver APIs + + The OpenHarmony driver subsystem provides you with abundant and stable driver APIs, which are compatible with those of future-proof smartphones, tablets, smart TVs. + + +- Component-based driver models + + The OpenHarmony driver subsystem supports component-based driver models. It provides more refined driver management to dismantle components, enabling you to focus on the interaction between the hardware and driver. + + The subsystem also presets some template-based driver model components, such as the network device models. + + +- Normalized configuration GUIs + + The OpenHarmony driver subsystem provides a unified configuration GUI and a cross-platform tool for configuration conversion and generation to implement seamless switchover across platforms. + + +You can use DevEco to manage driver projects, generate driver templates, and manage settings to make the development of OpenHarmony drivers easier. + +## Architecture + +The OpenHarmony driver framework adopts the primary/secondary mode and is developed based on the framework, model, competence library, and tool. + +**Figure 1** Driver subsystem architecture +![](../../../images/en/readme/figures/10c12859a05048e60ed443e90eb6bd27.png "driver-subsystem-architecture") + +- Driver framework stored in the **framework/core** directory + - Loads and starts drivers. + - Deploys and expands the driver framework flexibly through the object manager. + +- Driver model stored in the **framework/model** directory + - Provides model-based driving capabilities, such as network device models. + +- Driver capability library stored in the **framework/ability** directory + - Provides basic driver models, such as the I/O communication model. + +- Driver tools stored in the **framework/tools** directory + - Provides tools for HDI API conversion, and driver configuration and driver compilation. + +- Driver APIs stored in the **lite/hdi** directory + - Provides standardized driver APIs. + +- Support stored in the **framework/support** directory + - Provides platform driver APIs and system APIs with normalized abstraction capabilities. + + +## Directory Structure + +``` +drivers +├── adapter # Adaptation code for differentiated platforms +├── framework # Core code of the HDF +└── peripheral # Peripheral driver code +``` + +## Use + +**Figure 2** Interaction between the driver and framework +![](../../../images/en/readme/figures/1fc3f5cf5812eb8aef01a248e1d0ada5.png "interaction-between-the-driver-and-framework") + +Driver loading is mostly done by the driver framework, and you only need to register and configure required APIs. The driver framework will load and initialize the driver based on the parsing content. + +Driver development based on the HDF consists of the following three parts: + +1. Driver: Develop the functions. + +2. Information configuration: Present the loading information of the driver. + +3. Resource configuration: Configure the hardware information of the driver. + +The driver mainly aims to develop the functions. + +The first part that catches your eyes is the driver entry, which is described through **DriverEntry**. + +Three APIs are available, namely **bind**, **init**, and **release**. + +``` +struct HdfDriverEntry g_deviceSample = { + .moduleVersion = 1, + .moduleName = "sample_driver", + .Bind = SampleDriverBind, + .Init = SampleDriverInit, + .Release = SampleDriverRelease, +}; +``` + +**Bind**: This API is used to bind driver devices and its functions. + +``` +int32_t SampleDriverBind(struct HdfDeviceObject *deviceObject) +{ + // TODO: Bind device service to device object. + // And you can also initialize device resources here. + return HDF_SUCCESS; +} +``` + +**Init**: When devices are successfully bound, the framework calls **Init** to initialize the driver. After initialization is complete, the driver framework will determine whether to create external service interfaces based on the configuration file. If the driver fails to be initialized, the driver framework will automatically release the created device interface. + +``` +int32_t SampleDriverInit(struct HdfDeviceObject *deviceObject) +{ + // TODO: Init hardware or other resources here. + return HDF_SUCCESS; +} +``` + +**Release**: When you need to uninstall a driver, the driver framework calls this function to release the driver resources. Then, other internal resources will be released. + +``` +void SampleDriverRelease(struct HdfDeviceObject *deviceObject) +{ + // Release all resources. + return; +} +``` + +## Installation + +The OpenHarmony driver is mainly deployed in the kernel space using the static link mode. It is compiled and packed with the kernel subsystem and system image. + +**Figure 3** Driver installation +![](../../../images/en/readme/figures/13ca4da6eaee7a36ece5df3cdf01c748.png "driver-installation") + +## Repositories Involved + +**Driver subsystem** + +[drivers\_framework](https://gitee.com/openharmony/drivers_framework/blob/master/README.md) + +[drivers\_adapter](https://gitee.com/openharmony/drivers_adapter/blob/master/README.md) + +[drivers\_adapter\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_khdf_linux/blob/master/README.md) + +[drivers\_peripheral](https://gitee.com/openharmony/drivers_peripheral/blob/master/README.md) + diff --git a/website/docs/extras/en/readme/dsoftbus.md b/website/docs/extras/en/readme/dsoftbus.md new file mode 100644 index 0000000000000000000000000000000000000000..3c1ba2dd1caa21e4c969daa51568f18af24a600a --- /dev/null +++ b/website/docs/extras/en/readme/dsoftbus.md @@ -0,0 +1,93 @@ +--- +title: "dsoftbus" +prepermalink: /extras/754e0b7940aba6adfd890927b8e4e68d/ +permalink: /extras/754e0b7940aba6adfd890927b8e4e68d/ +relpath: "OpenHarmony-3.1-Release/en/readme/dsoftbus.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [dsoftbus] +--- +# DSoftBus + +## Introduction + +The DSoftBus subsystem provides communication capabilities for OpenHarmony, including WLAN, Bluetooth, DSoftBus, and remote procedure call \(RPC\). + +WLAN: basic WLAN functions, peer-to-peer \(P2P\) connection, and WLAN notification, enabling your application to communicate with other devices through a WLAN + +Bluetooth: classic Bluetooth and Bluetooth Low Energy \(BLE\) + +DSoftBus: distributed communications between near-field devices, and device discovery, connection setup, networking, and data transmission capabilities regardless of communication modes + +RPC: communications between processes on a device or across devices + +## Architecture + +**Figure 1** DSoftBus subsystem architecture + + +![](../../../images/en/readme/figures/39989ebd7c575bfeea763fa323a9d79d.png) + +## Directory Structure + +The main code directory structure of the DSoftBus subsystem is as follows: + +``` +/foundation/communication +├── bluetooth # Bluetooth code +├── dsoftbus # DSoftBus code +├── ipc # IPC code +└── wifi # WLAN code +``` + +## Constraints + +- Networking: Devices must be in the same LAN. + +## Usage Guidelines + +### RPC + +In RPC, the requesting process \(client\) can obtain the proxy of the process that provides the service \(server\). Through the proxy, the two processes can communicate with each other. + +1. Implement the server and its capabilities. +2. To be more specific, the client obtains a proxy of the server. This proxy provides the same capabilities as the server. Then the client can call a method of the server by accessing the corresponding method of the proxy. The proxy forwards the request to the server. +3. The server processes the received request and returns the result to the proxy via the driver. +4. The proxy returns the result to the client. + +### DSoftBus + +- Networking + +1. After the service is started, obtain the list of online devices. +2. Register a listener for device status changes. +3. Obtain the device ID, name, and type. +4. Obtain extended information about the device, such as the device type, networking type, and device capability. +5. Delete the registered listener. + +- Transmission + +1. Create a session server and register a callback. +2. After a device goes online, open a session with the device. +3. Send data through the session. +4. Close the session if you no longer need it. +5. Remove the created session server if you no longer want to use distributed transmission \(such as exiting the process\). + +## Repositories Involved + +**DSoftBus subsystem** + +communication\_bluetooth + +communication\_dsoftbus + +communication\_ipc + +communication\_wifi + diff --git a/website/docs/extras/en/readme/globalization.md b/website/docs/extras/en/readme/globalization.md new file mode 100644 index 0000000000000000000000000000000000000000..4802d044e2b1b1c54a525f25faf442e35375c952 --- /dev/null +++ b/website/docs/extras/en/readme/globalization.md @@ -0,0 +1,96 @@ +--- +title: "globalization" +prepermalink: /extras/661e8b0a8d6a85515a8c403fec17f1a1/ +permalink: /extras/661e8b0a8d6a85515a8c403fec17f1a1/ +relpath: "OpenHarmony-3.1-Release/en/readme/globalization.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [globalization] +--- +# Globalization + +## Introduction + +If OpenHarmony devices and applications need to be used globally, they must meet the requirements of users in different regions on languages and cultures. The Globalization subsystem provides the multi-language and multi-cultural capabilities for global use, including: + +- **Resource management** + + The subsystem loads, parses, and initializes system and application resources based on device types and system configurations, and provides APIs for obtaining resources such as character strings and media files. + +- **Internationalization \(i18n\)** + + The subsystem provides the bottom-layer resource backtracking capabilities, with a wide array of i18n APIs for implementing functions such as date/time formatting, number formatting, phone number formatting, and singular-plural formatting. + + +## Architecture + +**Figure 1** Architecture of the globalization subsystem + + +![](../../../images/en/readme/figures/dfc8ddf5c028d3ed121501d79c41bc5a.png "architecture-of-the-globalization-subsystem") + +## Directory Structure + +The source code of the Globalization subsystem is stored in the **/base/global** directory. + +The directory structure of the Globalization subsystem for the mini and small systems is as follows: + +``` +/base/global/ +├── i18n_lite # Code repository for the i18n framework +│ ├── frameworks # Core code of the i18n framework +│ │ ├── i18n # i18n module +│ │ │ ├── include # Header files +│ │ │ ├── src # Implementation code +│ │ │ └── test # Test code +│ ├── interfaces # APIs +│ │ ├── kits # Application APIs +│ │ │ ├── i18n # C/C++ i18n APIs +│ │ │ └── js # C/C++ support for JavaScript APIs +├── resmgr_lite # Code repository for the Resmgr framework +│ ├── frameworks # Core code of the Resmgr framework +│ │ ├── resmgr # Resource parsing code +│ │ │ ├── include # Header files +│ │ │ └── src # Implementation code +│ ├── interfaces # APIs +│ │ └── innerkits # APIs for internal subsystems +``` + +The directory structure of the Globalization subsystem for the standard system is as follows: + +``` +/base/global +├── i18n_standard # Code repository for the i18n framework +│ ├── frameworks # Core code of the i18n framework +│ ├── interfaces # APIs +│ │ ├── js # JavaScript APIs +│ │ └── native # Native APIs +├── resmgr_standard # Code repository for the Resmgr module +│ ├── frameworks # Core code +│ │ ├── resmgr # Resource parsing code +│ │ │ ├── include # Header files +│ │ │ ├── src # Implementation code +│ │ │ └── test # Test code +│ ├── interfaces # APIs +│ │ ├── innerkits # APIs for internal subsystems +│ │ └── js # JavaScript APIs +``` + +## Repositories Involved + +**Globalization subsystem** + +[global\_i18n\_lite](https://gitee.com/openharmony/global_i18n_lite) + +[global\_i18n\_standard](https://gitee.com/openharmony/global_i18n_standard) + +[global\_resmgr\_lite](https://gitee.com/openharmony/global_resmgr_lite) + +[global\_resmgr\_standard](https://gitee.com/openharmony/global_resmgr_standard) + diff --git a/website/docs/extras/en/readme/graphics.md b/website/docs/extras/en/readme/graphics.md new file mode 100644 index 0000000000000000000000000000000000000000..04c05567f0dd0071b07ba9e8c759b57f20e32b31 --- /dev/null +++ b/website/docs/extras/en/readme/graphics.md @@ -0,0 +1,165 @@ +--- +title: "graphics" +prepermalink: /extras/bb6dead1872dc412a2d52fcae2956dba/ +permalink: /extras/bb6dead1872dc412a2d52fcae2956dba/ +relpath: "OpenHarmony-3.1-Release/en/readme/graphics.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [graphics] +--- +# Graphics + +The Graphics subsystem mainly consists of user interface \(UI\) components, layout, animator, font, input event, window management, and rendering and drawing modules. It is an application framework that can be built on the LiteOS to develop OpenHarmony applications for Internet of Things \(IoT\) devices with limited hardware resources or on the standard OS to develop OpenHarmony applications for standard- and large-system devices \(for example, tablet and lite smart devices\). + +## 1.1 Mini System + +### Introduction + +The Graphics subsystem mainly consists of user interface \(UI\) components, layout, animator, font, input event, window management, and rendering and drawing modules. It is an application framework that can be built on the LiteOS to develop OpenHarmony applications for Internet of Things \(IoT\) devices with limited hardware resources. + +**Figure 1** Graphics subsystem architecture +![](../../../images/en/readme/figures/2ea46adee63b43c222437d3d43ba63c2.png "graphics-subsystem-architecture") + +The related modules are described as follows: + +- View: provides application components, including UIView, UIViewGroup, UIButton, UILabel, UILabelButton, UIList, and UISlider. +- Animator: defines functions for customizing animators. +- Layout: lays out components, including Flexlayout, GridLayout, and ListLayout. +- Transform: rotates, translates, or scales images. +- Event: processes basic events, including click, press, drag, and long press events. +- Rendering engine: performs rendering and drawing operations. +- 2D graphics library: draws 2D graphical elements including lines, rectangles, circles, arcs, images, and texts. Functions of this module include software drawing and hardware acceleration capability interconnection. +- Multi-language: processes the line feed and shaping of texts in different languages. +- Image library: parses and operates images of different types and formats, such as PNG, JPEG, ARGB8888, and ARGB565. +- WindowManager: manages windows, including creating, showing, hiding a window, and combining windows. +- InputManager: processes input events. + +### Directory Structure + +``` +/foundation/graphic +├── surface # Shared memory +├── ui # UI module, including UI components, animations, and fonts. +├── utils # Basic graphics library and hardware adaptation layer +└── wms # Window and input event management +``` + +### Constraints + +- The Graphics subsystem does not support multi-thread concurrent operations. You are advised to perform related operations in UI threads. +- The **utils/interfaces/innerkits/graphic\_config.h** file provides the configuration information about macro switches that can be used to enable or disable graphics features. You need to configure these switches before compilation. Note that some switches are configured depending on the platform. + +### Usage + +For details, see the README and **test** directory of each repository. + +### Repositories Involved + +**Graphics subsystem** + +graphic\_surface + +graphic\_ui + +graphic\_wms + +graphic\_utils + +## 1.2 Standard System + +### Introduction + +The Graphics subsystem provides graphics APIs and window management capabilities, which can be invoked by using Java or JS APIs. It is applicable to all devices that run the standard system. + +The following figure shows the architecture of the Graphics subsystem. + +![](../../../images/en/readme/figures/eeddffae154ed6f3f9e723acfb86185d.png) + +- Surface + + Provides APIs for managing the graphics buffer and the efficient and convenient rotation buffer. + +- Vsync + + Provides APIs for managing registration and response of all vertical sync signals. + +- WindowManager + + Provides APIs for creating and managing windows. + +- WaylandProtocols + + Provides the communication protocols between the window manager and synthesizer. + +- Compositor + + Implements synthesis of layers. + +- Renderer + + Functions as the back-end rendering module of the synthesizer. + +- Wayland protocols + + Provides Wayland inter-process communication protocols. + +- Shell + + Provides multi-window capabilities. + +- Input Manager + + Functions as the multimodal input module that receives input events. + + +### Directory Structure + +``` +foundation/graphic/standard/ +├── frameworks # Framework code +│ ├── bootanimation # BootAnimation code +│ ├── surface # Surface code +│ ├── vsync # Vsync code +│ └── wm # WindowManager code +├── interfaces # External APIs +│ ├── innerkits # Native APIs +│ └── kits # JS APIs and NAPIs +└── utils # Utilities +``` + +### Constraints + +Language version: C++ 11 or later + +### Compilation and Building + +The dependent APIs include the following: + +- graphic\_standard:libwms\_client +- graphic\_standard:libsurface +- graphic\_standard:libvsync\_client + +### Usage + +For details, see the README and **test** directory of each repository. + +### Repositories Involved + +**Graphics subsystem** + +graphic\_standard + +ace\_ace\_engine + +aafwk\_standard + +multimedia\_media\_standard + +multimedia\_camera\_standard + diff --git a/website/docs/extras/en/readme/js-ui-framework.md b/website/docs/extras/en/readme/js-ui-framework.md new file mode 100644 index 0000000000000000000000000000000000000000..8eba8347eb07659bb4ac3fe33b36beac9f565765 --- /dev/null +++ b/website/docs/extras/en/readme/js-ui-framework.md @@ -0,0 +1,130 @@ +--- +title: "js-ui-framework" +prepermalink: /extras/548a1184a4adc1361f864a8eb3caf664/ +permalink: /extras/548a1184a4adc1361f864a8eb3caf664/ +relpath: "OpenHarmony-3.1-Release/en/readme/js-ui-framework.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [js-ui-framework] +--- +# JS UI Framework + +## Introduction + +The OpenHarmony JS UI framework provides basic, container, and canvas UI components and standard CSS animation capabilities. It supports the web-development-like programming paradigm. + +- **Web-development-like paradigm** + + The JS UI framework supports languages that are similar to those for web development, such as HTML and CSS. You can use them to describe the page layout and style, and use JavaScript \(conforming to the ECMAScript specification\) for page behavior. This paradigm allows you to avoid code for UI state switching. The view configuration information is intuitive. + + +**Figure 1** JS UI framework + + +![](../../../images/en/readme/figures/1d863643724060f83258983395521b5b.png) + +The JS UI framework consists of the application, framework, engine, and porting layers. + +- **Application** + + Contains applications with Feature Abilities \(FAs\) developed with the JS UI framework. The FA application in this document refers to the application with FAs developed using JavaScript. + +- **Framework** + + Parses UI pages and provides the Model-View-ViewModel \(MVVM\), page routing, custom components and more for front end development. + +- **Engine** + + Accomplishes animation parsing, Document Object Model \(DOM\) building, layout computing, rendering command–based building and drawing, and event management. + +- **Porting Layer** + + Abstracts the platform layer to provide interfaces for the interconnection with the OS. For example, interconnections of events, rendering pipelines, and lifecycles. + + +## Directory Structure + +The source code of the framework is stored in **/foundation/ace**. The following shows the directory structure. + +``` +/foundation/ace +├── ace_engine # JS UI framework +├── ace_engine_lite # JS UI framework for the mini system and above +└── napi # JS APIs for extending the native development module +``` + +## Usage + +- JavaScript FA development directory + +After a project is created, its **js** directory is displayed. + +**Figure 2** Development directory +![](../../../images/en/readme/figures/f135f44d52e5797a68ada92eb4d24d75.png "development-directory") + +The **i18n** directory stores JSON files for various locales. A **pages** subfolder contains multiple pages and each consists of **.hml**, **.css**, and **.js** files. + +- **main \> js \> default \> i18n \> en-US.json**: defines the variables displayed on pages in English. Similarly, **zh-CN.json** defines the page content in Chinese. + + ``` + { + "strings": { + "hello": "Hello", + "world": "World" + } + } + ``` + +- **main \> js \> default \> pages \> index \> index.hml**: describes the layout of the **index** page, components used on the page, and the hierarchy of these components. For example, there is a text component for displaying **Hello World**. + + ``` +
+ + {{ $t('strings.hello') }} {{title}} + +
+ ``` + +- **main \> js \> default \> pages \> index \> index.css**: defines the style of the **index** page. For example, the following **index.css** code snippet describes how **container** and **title** will be displayed on the page: + + ``` + .container { + flex-direction: column; + justify-content: center; + align-items: center; + } + .title { + font-size: 100px; + } + ``` + +- **main \> js \> default \> pages \> index \> index.js**: defines the service logic on the **index** page, such as data binding and event processing. In this example, the string **World** is assigned to **title**. + + ``` + export default { + data: { + title: '', + }, + onInit() { + this.title = this.$t('strings.world'); + }, + } + ``` + + +## Repositories Involved + +JS UI framework + +ace\_ace\_engine + +ace\_ace\_engine\_lite + +ace\_napi + diff --git a/website/docs/extras/en/readme/kernel.md b/website/docs/extras/en/readme/kernel.md new file mode 100644 index 0000000000000000000000000000000000000000..b3208cc4793197be0851f4d60721e9546baaa76e --- /dev/null +++ b/website/docs/extras/en/readme/kernel.md @@ -0,0 +1,229 @@ +--- +title: "kernel" +prepermalink: /extras/4510a5dbfda3e6686608db27b805ec68/ +permalink: /extras/4510a5dbfda3e6686608db27b805ec68/ +relpath: "OpenHarmony-3.1-Release/en/readme/kernel.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [kernel] +--- +# Kernel + +## Introduction + +OpenHarmony provides LiteOS and Linux for different levels of systems. LiteOS applies to mini and small systems. Linux applies to small and standard systems. + + + + + + + + + + + + + + + + + +

System Level

+

Mini System

+

Small System

+

Standard System

+

LiteOS

+

+

+

×

+

Linux

+

×

+

+

+
+ +## LiteOS + +OpenHarmony LiteOS is a real-time OS kernel developed for IoT devices. It boasts lightweight features as the real-time operating system (RTOS) and is easy-to-use like Linux. + +LiteOS provides basic kernel functions, such as process and thread scheduling, memory management, inter-process communication (IPC), and timer management. + +The LiteOS source code is stored in **kernel\\_liteos\\_a** and **kernel\\_liteos\\_m** repositories. The **kernel\\_liteos\\_a** repository stores kernel code for small and standard systems. The **kernel\\_liteos\\_m** repository stores kernel code for mini systems. This document describes the **kernel\\_liteos\\_a** repository. Figure 1 shows the architecture of OpenHarmony LiteOS-A. + +**Figure 1** OpenHarmony LiteOS-A kernel architecture +![](../../../images/en/readme/figures/4c68b9077300306cb8d6eb43c8ae71bb.png "OpenHarmony-LiteOS-A Kernel Architecture") + +## Linux + +Evolved from the open-source Linux kernel LTS 4.19.y and 5.10.y, the OpenHarmony Linux kernel has incorporated CVE patches and OpenHarmony features as the OpenHarmony common kernel baseline. Vendors can complete the kernel adaptation by applying the driver patches for boards. + +For more information about Linux LTS 4.19.y, visit the [official kernel website](https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/log/?h=linux-4.19.y). + +For more information about Linux LTS 5.10.y, visit the [official kernel website](https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/log/?h=linux-5.10.y). + +During the build process, you can merge the driver code based on the chip platform and build the kernel image. All patches are licensed under GNU General Public License (GPL) 2.0. + +## Directory Structure + +``` +kernel/ +├── linux +│ ├── linux-4.19 # OpenHarmony linux-4.19 common kernel +│ ├── linux-5.10 # OpenHarmony linux-5.10 common kernel +│ ├── build +│ │ ├── BUILD.gn # GN file of the build framework +│ │ ├── kernel.mk # Kernel build file +│ │ └── ohos.build # Kernel build component file +│ ├── patches +│ │ ├── linux-4.19 # linux-4.19 patches +│ │ │   └── hi3516dv300_patch +│ │ │   ├── hi3516dv300.patch # linux-4.19 Hi3516D V300 SOC patches +│ │ │   └── hdf.patch # linux-4.19 Hi3516D V300 HDF patches +│ │ └── linux-5.10 +│ │    └── hi3516dv300_patch +│ │    ├── hi3516dv300.patch # linux-5.10 Hi3516D V300 SOC patches +│ │    └── hdf.patch # linux-5.10 Hi3516D V300 HDF patches +│ └── config +│ ├── linux-4.19 +│ │   └── arch +│ │   └── arm +│ │   └── configs +│ │ ├── hi3516dv300_small_defconfig # Small-system defconfig of the open-source Hi3516D V300 development board from HiSilicon +│ │ ├── hi3516dv300_standard_defconfig # Standard-system defconfig of the open-source Hi3516D V300 development board from HiSilicon +│ │ ├── small_common_defconfig # Common defconfig of the small-system kernel +│ │ └── standard_common_defconfig # Common defconfig of the standard-system kernel +│ └── linux-5.10 +│ └── arch +│ └── arm +│ └── configs +│ ├── hi3516dv300_small_defconfig # Small-system defconfig of the open-source Hi3516D V300 development board from HiSilicon +│ ├── hi3516dv300_standard_defconfig # Standard-system defconfig of the open-source Hi3516D V300 development board from HiSilicon +│ ├── small_common_defconfig # Common defconfig of the small-system kernel +│ └── standard_common_defconfig # Common defconfig of the standard-system kernel +└── liteos_a # Baseline code of the LiteOS kernel + ├── apps # User-mode init and shell applications + ├── arch # Directory of the system architecture, such as arm + │ └── arm # Code for arm + ├── bsd # Code of the driver and adaptation layer module related to the FreeBSD, such as the USB module + ├── compat # Kernel API compatibility + │ └── posix # POSIX APIs + ├── drivers # Kernel drivers + │ └── char # Character device + │ ├── mem # Driver for accessing physical input/output (I/O) devices + │ ├── quickstart # APIs for quick system start + │ ├── random # Driver for random number generators + │ └── video # Framework of the framebuffer driver + ├── fs # File system module, which derives from the NuttX open-source project + │ ├── fat # FAT file system + │ ├── jffs2 # JFFS2 file system + │ ├── include # Header files exposed externally + │ ├── nfs # NFS file system + │ ├── proc # proc file system + │ ├── ramfs # Ramfs file system + │ └── vfs # VFS layer + ├── kernel # Kernel modules including the process, memory, and IPC modules + │ ├── base # Basic kernel modules, including the scheduling and memory modules + │ ├── common # Common components of the kernel + │ ├── extended # Extended kernel modules, including the dynamic loading, vDSO, and LiteIPC modules + │ ├── include # Header files exposed externally + │ └── user # Init process loading + ├── lib # Kernel library + ├── net # Network module, which mainly derives from the lwIP open-source project + ├── platform # Code for supporting different systems on a chip (SOCs), such as Hi3516D V300 + │ ├── hw # Logic code related to clocks and interrupts + │ ├── include # Header files exposed externally + │ └── uart # Logic code related to the serial port + ├── platform # Code for supporting different SOCs, such as Hi3516D V300 + ├── security # Code related to security features, including process permission management and virtual ID mapping management + ├── syscall # System calling + └── tools # Building tools as well as related configuration and code +``` + +## Constraints + +LiteOS: + +By default, the Hi3518E V300 uses the JFFS2 file system, and Hi3516D V300 uses the FAT file system. Adaptation must be performed if you want to use other file systems. + +## Usage + +### LiteOS + +For details, see "Usage" in LiteOS-A Kernel [README](https://gitee.com/openharmony/kernel_liteos_a/blob/master/README.md) and LiteOS-M Kernel [README](https://gitee.com/openharmony/kernel_liteos_m/blob/master/README.md). + +### Linux + +1. Apply HDF patches. + + Apply the HDF kernel patches matching your kernel version. For details, see the method in **kernel.mk** in the **kernel/linux/build** repository. + + ``` + $(OHOS_BUILD_HOME)/drivers/adapter/khdf/linux/patch_hdf.sh $(OHOS_BUILD_HOME) $(KERNEL_SRC_TMP_PATH) $(HDF_PATCH_FILE) + ``` + +2. Apply the chip driver patches. + + The following uses Hi3516D V300 as an example. + + Place the patches for the chip component in the corresponding path based on the path and naming rules for the patches of the chip component in **kernel.mk** in the **kernel/linux/build** repository. + + ``` + DEVICE_PATCH_DIR := $(OHOS_BUILD_HOME)/kernel/linux/patches/${KERNEL_VERSION}/$(DEVICE_NAME)_patch + DEVICE_PATCH_FILE := $(DEVICE_PATCH_DIR)/$(DEVICE_NAME).patch + ``` + +3. Modify the **config** file to build. + + Place the **config** file for the chip component in the corresponding path based on the path and naming rules of the chip component in **kernel.mk** in the **kernel/linux/build** repository. + + ``` + KERNEL_CONFIG_PATH := $(OHOS_BUILD_HOME)/kernel/linux/config/${KERNEL_VERSION} + DEFCONFIG_FILE := $(DEVICE_NAME)_$(BUILD_TYPE)_defconfig + ``` + + > **Note**: + > + >In the OpenHarmony project build process, patches are installed after **kernel/linux/linux-\*\.\*** is copied. Before using the version-level build command of OpenHarmony, ensure that the **kernel/linux/linux-\*\.\*** source code is available. + > + >The kernel built is generated in the **kernel** directory under the **out** directory. Modify the **config** file based on the kernel built, and copy the generated **.config** file to the corresponding path in the **config** repository. Then, the configuration takes effect. + +## Build + +The following uses the Hi3516D V300 development board and Ubuntu x86 server as an example. + +Perform a full build for the project to generate the **uImage** kernel image. + +``` +./build.sh --product-name Hi3516DV300 # Build the Hi3516D V300 image. + --build-target build_kernel # Build the uImage kernel image of Hi3516D V300. + --gn-args linux_kernel_version=\"linux-5.10\" # Build the specified kernel version. +``` + +## Repositories Involved + +**Kernel** + +LiteOS: + +[drivers\_liteos](https://gitee.com/openharmony/drivers_liteos/blob/master/README.md) + +[kernel\_liteos\_a](https://gitee.com/openharmony/kernel_liteos_a/blob/master/README.md) + +[kernel\_liteos\_m](https://gitee.com/openharmony/kernel_liteos_m/blob/master/README.md) + +[device\_qemu](https://gitee.com/openharmony/device_qemu/blob/master/README.md) + +[prebuilts\_lite\_sysroot](https://gitee.com/openharmony/prebuilts_lite_sysroot/blob/master/README.md) + +Linux: + +[kernel\_linux\_4.19](https://gitee.com/openharmony/kernel_linux_4.19/blob/master/README) + +[kernel\_linux\_5.10](https://gitee.com/openharmony/kernel_linux_5.10/blob/master/README) diff --git a/website/docs/extras/en/readme/liteipc_driver.md b/website/docs/extras/en/readme/liteipc_driver.md new file mode 100644 index 0000000000000000000000000000000000000000..0497801f36147f721bc63e10da72d9f085f4bc32 --- /dev/null +++ b/website/docs/extras/en/readme/liteipc_driver.md @@ -0,0 +1,200 @@ +--- +title: "liteipc_driver" +prepermalink: /extras/98e5b6261ce2da9fabf5db59ed4ef13e/ +permalink: /extras/98e5b6261ce2da9fabf5db59ed4ef13e/ +relpath: "OpenHarmony-3.1-Release/en/readme/liteipc_driver.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [liteipc_driver] +--- +# LiteIPC driver + +## Overview +LiteIPC is an OpenHarmony extension to the LiteOS(a) kernel which provides a means for processes on the same device to communicate with each other. It is a somewhat higher level mechanism than POSIX IPC methods such as message queues or shared memory, providing automatic management of resources used for IPC and control of access rights to send messages to other processes. IPC messages are exchanged between tasks. An IPC service is a task which has been set up to receive request type messages. Access rights are granted to processes, if a process has access to a service then all tasks in the process are able to send requests to the service. + +## API +*Application-layer Interface* +//foundation/communication/ipc_lite/frameworks/liteipc/include/liteipc.h +//foundation/communication/ipc_lite/interfaces/kits/liteipc_adapter.h + +*Implementation* +//kernel/liteos_a/kernel/extended/liteipc/hm_liteipc.h +//kernel/liteos_a/kernel/extended/liteipc/hm_liteipc.c + +`LITEIPC_DRIVER` specifies the name of the character device used to communicate with the LiteIPC driver (currently /dev/lite_ipc). + +Memory mapping allocates a memory area for storing messages received by the process' tasks. ioctl calls to the driver before it has been memory mapped return with error **ENOMEM**. + +The IpcMsg structure is the basic unit of transaction for LiteIPC. +| Member | Type | Description | +| --------- | ----------- | ----------- | +| type | MsgType | The message's type. It can be one of the following values **MT_REQUEST**, **MT_REPLY**, **MT_FAILED_REPLY**, **MT_DEATH_NOTIFY**. | +| target | SvcIdentity | Specifies the message's recipient. | +| flag | IpcFlag | Indicates whether the message can be replied to or is one-way. It can be one of the following values **LITEIPC_FLAG_DEFAULT**, **LITEIPC_FLAG_ONEWAY**. | +| dataSz | UINT32 | The size of the message data in bytes pointed to by data (cannot exceed IPC_MSG_DATA_SZ_MAX, currently 1024 bytes). | +| data | void* | Pointer to the message data. | +| spObjNum | UINT32 | The number of special objects contained in the message data (cannot exceed IPC_MSG_OBJECT_NUM_MAX). | +| offsets | void* | An array of offsets relative to data pointing to SpecialObj special objects in data. | +| code | UINT32 | Service function code. | +| timestamp | UINT64 | Timestamp for when the message was sent. Automatically set by the IPC system for requests and death notifications. | +| taskID | UINT32 | Specifies the message's sender. Automatically set by the IPC system. | +| processID | UINT32 | Additional information on the message's sender. Automatically set by the IPC system. | + +SpecialObj +| Member | Type | Description | +| ------- | ---------- | ----------- | +| type | ObjType | The type of special object. It can be one of the following values **OBJ_FD**, **OBJ_PTR**, **OBJ_SVC**. | +| content | ObjContent | The special object. | + +ObjContent +| SpecialObj type | Member | Type | Description | +| --------------- | ------ | ----------- | ----------- | +| OBJ_FD | fd | UINT32 | File descriptor referring to the file description to be sent. | +| OBJ_PTR | ptr | BuffPtr | Auxiliary data to be sent (not limited by IPC_MSG_DATA_SZ_MAX). | +| OBJ_SVC | svc | SvcIdentity | A service to give the recipient permission to send requests to. | + +`IPC_SEND_RECV_MSG` is the primary request which provides the ability to send and receive IpcMsg messages as well as free memory used by unneeded messages. Its argument is a pointer to an IpcContent structure. + +IpcContent +| Member | Type | Description | +| ---------- | ----------- | ----------- | +| flag | UINT32 | Specifies the operation(s) to be performed. It is the bitwise-or of one or more of the following flags **SEND**, **RECV**, **BUFF_FREE**. | +| outMsg | IpcMsg* | Points to a message to be sent. | +| inMsg | IpcMsg* | Points to a message that has been received. | +| buffToFree | void* | Points to IPC memory to be freed (a previously received message which is no longer needed). | + +- The **SEND** flag indicates a request to send outMsg. Returns with error **EINVAL** if any member of the message has been given an invalid value. + - Sending a message with type **MT_REQUEST** returns with error **EACCES** if the task doesn't have access rights to the recipient, and **EINVAL** for an invalid recipient. All tasks have access rights to the CMS (see IPC_SET_CMS), and to their own process' IPC services. + - Sending a message with type **MT_REPLY** or **MT_FAILED_REPLY** returns with error **EINVAL** if any of the following are not satisifed: + - buffToFree must point at the message being replied to and the **BUFF_FREE** flag must be set. + - The outMsg recipient (target.handle) must match the buffToFree sender (taskID). + - The outMsg and buffToFree timestamps must match. + - buffToFree must be a **MT_REQUEST** type message and cannot be marked as **LITEIPC_FLAG_ONEWAY**. + - buffToFree must be addressed to a service of the current process. + + Trying to reply to a message sent more than LITEIPC_TIMEOUT_NS nanoseconds ago (currently 5 seconds) returns with error **ETIME**. + + The message is copied into memory allocated from the IPC memory area of the process for the recipient task specified by target.handle. Returns with error **ENOMEM** if the memory cannot be allocated. Special objects in offsets are then processed. For each **OBJ_FD**, a file descriptor that refers to the specified file description is created for the recipient and the recipient's copy of the **OBJ_FD** is updated with the new file descriptor, discards the message and returns with error **EPERM** if the sender doesn't have permission to create the file descriptor, **EBADF** for a bad file descriptor, or **ESRCH** for other problem creating the file descriptor. **OBJ_PTR** objects' data is copied into memory allocated from the recipient's IPC memory area, discards the message and returns with error **EINVAL** if unable to allocate enough memory. **OBJ_SVC** objects grant the recipient access rights to the service specified by the object if the sender already has access and the service is set as an IPC task (see IPC_SET_IPC_THREAD), discards the message and returns with error **EACCES** if the sender doesn't have access or **EINVAL** if the service isn't running. Access rights are not revokable, on error any access rights granted before the special object which caused the error will remain. The message is then added to the tail end of the recipient's list of received messages, the recipient is woken and the scheduler is called. +- The **BUFF_FREE** flag indicates a request to free the memory used by the buffToFree message so it can be used again later for receiving messages. Returns with error **EFAULT** if buffToFree doesn't point to a received message. Returns with error **EINVAL** if an invalid address. +- The **RECV** flag indicates a request to receive a message. + - If the **SEND** flag is set the task will wait for a message for up to LITEIPC_TIMEOUT_MS milliseconds (currently 5 seconds). Returns with error **ETIME** on timeout. Messages with a type of **MT_REQUEST** and **MT_REPLY** or **MT_FAILED_REPLY** type messages which don't match outMsg (matching timestamp or matching code and target.token depending on kernel configuration) are discarded (resets timer). Sets inMsg to point at the received message and removes it from the list of received messages for **MT_REPLY** or **MT_DEATH_NOTIFY** type messages. Note that receiving a **MT_DEATH_NOTIFY** makes it impossible to receive the reply so send/receive requests shouldn't be used by services which might receive death notifications. Discards the message and returns with error **ENOENT** without changing inMsg if the received message has type **MT_FAILED_REPLY**. + - If the **SEND** flag is not set, the task will sleep until a message with type **MT_REQUEST** or **MT_DEATH_NOTIFY** is received. Sets inMsg to point at the received message, and removes the message from its list of received messages. Discards **MT_REPLY** or **MT_FAILED_REPLY** type messages received while waiting. + +For a single request the operations are processed in the order **SEND**->**BUFF_FREE**->**RECV** with **BUFF_FREE** being processed even if there was an error in **SEND**. Error checking on buffToFree occurs before **SEND**, an error in buffToFree will abort the request without doing anything. + +The `IPC_SET_IPC_THREAD` request designates the current task as the IPC task for the current process. It can only be performed once per process. Returns the ID of the task set as IPC task on success, subsequent calls return with error **EINVAL**. The IPC task receives the death notifications from IPC services the process has access rights to when those services terminate. A service which has been set as IPC task can have access rights to itself distributed through special objects without using the CMS. + +IPC_SEND_RECV_MSG and IPC_SET_IPC_THREAD both return with error **EINVAL** if the CMS has not been set. + +### Internal functions +The first task to use the `IPC_SET_CMS` request sets itself as the system's CMS. OpenHarmony assigns this role to the distributed scheduler's samgr. Once set it cannot be changed. Returns with error **EEXIST** if the CMS has already been set. Messages are sent to the CMS by setting a recipient handle of 0. The argument to the request specifies the maximum size of a message sent to the CMS. Sending a message whose total size including IpcMsg data structure, data size, size of special object offsets, and data in any BuffPtr special objects exceeds the maximum size (currently 256 bytes) returns with error **EINVAL**. + +The `IPC_CMS_CMD` request provides various service related utility functions to the CMS. It can only be used by the CMS, any other task making this request will get an **EACCES** error. The argument to the request is a pointer to a CmsCmdContent structure. The cmd member indicates the function to be performed. +- **CMS_GEN_HANDLE** creates a service handle for the task specified by taskID member and stores the handle in the serviceHandle member. The CMS always has access rights to any created IPC services. +- **CMS_REMOVE_HANDLE** unregisters the service handle specified by the serviceHandle member. +- **CMS_ADD_ACCESS** gives the task specified by the taskID member access rights to the service specified by the serviceHandle member. + +LiteIPC includes utility functions for the kernel to manage the IPC system. +`OsLiteIpcInit` initializes the IPC system and must be called before it can be used. +`LiteIpcPoolInit` performs basic initialization of a ProcIpcInfo. Called by the kernel on task creation to initialize the IPC variables in the task's control block. +`LiteIpcPoolReInit` initializes the IPC variables of a child task from it's parent's task. Called by the kernel on the creation of child tasks for basic initialization. +`LiteIpcPoolDelete` removes a process' IPC memory pool allocated by memory mapping and all the process' access rights. Called by the kernel on process deletion for automatic memory and IPC resource management. +`LiteIpcRemoveServiceHandle` deregisters a service, clearing out the service task's message list and the list of processes with access rights to the service and sending death notification messages to any services with a set IPC task which had access. Death notification messages are only sent once, if there is an error in the send (**ENOMEM**) the recipient will not get the death notification. Death notification messages set target.token to the sevice handle of the service which terminated. Called by the kernel on task deletion for automatic IPC resource management. + +### Sample code +1. Initialization before we can use LiteIPC. + ``` + #include "liteipc_adapter.h" + #include "liteipc.h" + + int fd = open(LITEIPC_DRIVER, O_RDONLY); + mmap(NULL, 10000, PROT_READ, MAP_PRIVATE, fd, 0); + ``` + +2. Send a message to the CMS. For simplicity let's say we have a primitive CMS which simply gives us access to and returns the handle of the service named in the request we send to it. + ``` + #define SVCNAME "wakeup service" + IpcMsg msg = { + .type = MT_REQUEST, + .target = { 0, 0, 0 }, + .flag = LITEIPC_FLAG_DEFAULT, + .dataSz = sizeof(SVCNAME), + .data = SVCNAME, + .spObjNum = 0, + .offsets = NULL + }; + IpcContent content = { + .flag = SEND | RECV, + .outMsg = &msg + }; + + // Send a message to the CMS + if (ioctl(fd, IPC_SEND_RECV_MSG, &content) < 0) { + goto ERROR; + } + ``` + +3. Set our IPC task and send a message to the wakeup service. + ``` + // Set ourselves as IPC task so we can distribute access on our own + int myId = ioctl(fd, IPC_SET_IPC_THREAD, 0); + + struct { + char summary[20]; + SpecialObj command; + SpecialObj svc; + } wakeupData = { + .summary = "one wakeup" + }; + char commandStr[100] = "Wake me up at 9:00 in the morning."; + void* wakeupOffsets[2] = { + (void*)((uintptr_t)&wakeupData.command - (uintptr_t)&wakeupData), + (void*)((uintptr_t)&wakeupData.svc - (uintptr_t)&wakeupData) + }; + + // Send a request to the wakeup service and free the CMS's reply + content.flag = SEND | BUFF_FREE; + content.buffToFree = content.inMsg; + msg.type = MT_REQUEST; + // Set the recipient from the CMS' reply + msg.target.handle = *(uint32_t*)content.inMsg->data; + // Add the auxiliary data. + wakeupData.command.type = OBJ_PTR; + wakeupData.command.content.ptr.buffSz = sizeof(commandStr); + wakeupData.command.content.ptr.buff = commandStr; + // Give the wakeup service access to send us requests. + wakeupData.svc.type = OBJ_SVC; + wakeupData.svc.content.svc.handle = myId; + // Complete the message and send it. + msg.data = &wakeupData; + msg.dataSz = sizeof(wakeupData); + msg.offsets = wakeupOffsets; + msg.spObjNum = 2; + if (ioctl(fd, IPC_SEND_RECV_MSG, &content) < 0) { + goto ERROR; + } + ``` + +4. Wait for wakeup and process the wakeup message. + ``` + // Enter "server" mode, wait for the service to wake us up. + content.flag = RECV; + ioctl(fd, IPC_SEND_RECV_MSG, &content); + + // Free the received message + content.flag = BUFF_FREE; + content.buffToFree = content.inMsg; + ioctl(fd, IPC_SEND_RECV_MSG, &content); + ``` + +5. LiteIPC automatically cleans up our IPC resources when we exit, but closing the file descriptor when we're done using it is a good habit. + ``` + ERROR: + close(fd); + ``` diff --git a/website/docs/extras/en/readme/misc-services.md b/website/docs/extras/en/readme/misc-services.md new file mode 100644 index 0000000000000000000000000000000000000000..984f92fcbf4e7748bd353be8dbf6ae60f5ba411c --- /dev/null +++ b/website/docs/extras/en/readme/misc-services.md @@ -0,0 +1,37 @@ +--- +title: "misc-services" +prepermalink: /extras/9f3ff0f28c70c0b0606484807af895f4/ +permalink: /extras/9f3ff0f28c70c0b0606484807af895f4/ +relpath: "OpenHarmony-3.1-Release/en/readme/misc-services.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [misc-services] +--- +# Misc Services + +## Introduction + +The Misc services subsystem provides APIs for setting the system time. + +**Figure 1** Subsystem architecture +![](../../../images/en/readme/figures/b263842943f6a2b1ba2ab0eddddab6e9.png "subsystem-architecture") + +## Directory Structure + +``` +/base/miscservices +└── time # Time service module +``` + +## Repositories Involved + +**Misc services subsystem** + +miscservices\_time + diff --git a/website/docs/extras/en/readme/multimedia.md b/website/docs/extras/en/readme/multimedia.md new file mode 100644 index 0000000000000000000000000000000000000000..8ca89beddee98000555447232128b4bc62368980 --- /dev/null +++ b/website/docs/extras/en/readme/multimedia.md @@ -0,0 +1,126 @@ +--- +title: "multimedia" +prepermalink: /extras/41d5ea7ec72aa2879e72d590683ab1f1/ +permalink: /extras/41d5ea7ec72aa2879e72d590683ab1f1/ +relpath: "OpenHarmony-3.1-Release/en/readme/multimedia.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [multimedia] +--- +# Multimedia + +## Introduction + +The multimedia subsystem provides a set of simple and easy-to-use APIs for you to access the system and media resources. + +This subsystem offers various media services covering audio, videos, and cameras, which provide the following capabilities: + +- Audio playback and recording +- Video playback and recording +- Photographing and recording \(with cameras\) + +## System Architecture + +**Figure 1** Architecture of the multimedia subsystem + +![](../../../images/en/readme/figures/95528cfb37e984e6e556ec92c5f7d4a8.png) + +- **Media**: provides playback and recording APIs for applications, and invokes the Gstreamer, Histreamer, or other engines through cross-process calling or direct calling. + - For the mini system, the media component invokes Histreamer to support audio playback. + - For the small system, the media component invokes recorder_lite to support audio/video recording and invokes player_lite by default to support audio/video playback. If the system variable **debug.media_service.histreamer** is set to **1**, the component invokes Histreamer to support audio/video playback. For details, see [syspara Module](https://gitee.com/openharmony/docs/blob/master/en/device-dev/subsystems/subsys-boot-syspara.md) or [syspara_lite](https://gitee.com/openharmony/startup_syspara_lite). + - For the standard system, the media component invokes Gstreamer to support audio/video playback and recording. +- **Audio**: supports audio input and output, policy management, and audio focus management. +- **Camera**: provides camera operation APIs for preview, photographing, and video recording. +- **Image**: supports encoding and decoding of common image formats. +- **MediaLibrary**: supports local and distributed media data access management. +- **Histreamer**: a lightweight media engine that supports file/network streaming media input, audio/video decoding and playback, audio/video encoding and recording, and plugin extension. +- **Gstreamer**: an open-source GStreamer engine that supports streaming media, audio and video playback, and recording. + +## Directory Structure + +The structure of the repository directory is as follows: + +``` +/foundation/multimedia # Service code +├── audio_lite # Audio module for the small system +│ ├── figures # Architecture and process figures of the audio module for the small system +│ ├── frameworks # Audio framework implementation for the small system +│ └── interfaces # Audio module APIs for the small system +├── audio_standard # Audio module for the standard system +│ ├── figures # Architecture and process figures of the audio module for the standard system +│ ├── frameworks # Audio framework implementation for the standard system +│ ├── interfaces # Audio module APIs for the standard system +│ ├── sa_profile # Audio service profile for the standard system +│ └── services # Audio service implementation for the standard system +├── camera_lite # Camera module for the small system +│ ├── figures # Architecture and process figures of the camera module for the small system +│ ├── frameworks # Camera framework implementation for the small system +│ └── interfaces # Camera module APIs for the small system +├── camera_standard # Camera module for the standard system +│ ├── figures # Architecture and process figures of the camera module for the standard system +│ ├── frameworks # Camera framework implementation for the standard system +│ └── interfaces # Camera module APIs for the standard system +├── media_lite # Playback and recording module for the small system +│ ├── figures # Architecture and process figures of the playback and recording module for the small system +│ ├── frameworks # Playback and recording framework implementation for the small system +│ ├── interfaces # Playback and recording module APIs for the small system +│ └── services # Playback and recording service implementation for the small system +├── media_standard # Playback and recording module for the standard system +│ ├── figures # Architecture and process figures of the playback and recording module for the standard system +│ ├── frameworks # Playback and recording framework implementation for the standard system +│ └── interfaces # Playback and recording module APIs for the standard system +├── histreamer # Histreamer engine +│ └── engine # Media engine +│ ├── player # Encapsulated player +│ ├── foundation # Basic tools +│ ├── pipeline # Pipeline framework +│ └── plugin # Plugin framework +│ └── plugins # Platform software plugins +└── utils # Subsystem utility module + └── lite # Utility module for the small system + ├── figures # Architecture and process figures of the utility module for the small system + ├── hals # Hardware abstraction interfaces of the subsystem for the small system + ├── interfaces # Utility module APIs for the standard system + └── src # Utility module framework implementation for the small system +``` + +## Constraints + +Hardware-based decoding and encoding functions of audio and video data are device-specific. + +## Usage Guidelines + +You can use the APIs in any of the provided classes based on your development requirements. + +- For details about how to call media APIs to implement the video recording, preview, and playback, see [Multimedia Development Guide](https://gitee.com/openharmony/docs/blob/master/en/device-dev/subsystems/subsys-multimedia.md). +- For a simple player, use **Player** and **Recorder** classes to quickly implement the playback and recording features. +- The **CameraKit** class provides a group of effective methods for controlling a camera, which facilitates the camera development. +- You can create a **CameraKit** object and register various callbacks to respond to many events in the multimedia module. Then, create a **Camera** object to operate camera resources, for example, to start preview, recording, and stream capturing, and set related parameters. + +## Installation + +Load the kernel and related drivers before installing the repository. For details, see readme files of kernel and driver subsystems. + +## Repositories Involved + +[multimedia\_camera\_lite](https://gitee.com/openharmony/multimedia_camera_lite) + +[multimedia\_audio\_lite](https://gitee.com/openharmony/multimedia_audio_lite) + +[multimedia\_media\_lite](https://gitee.com/openharmony/multimedia_media_lite) + +[multimedia\_utils\_lite](https://gitee.com/openharmony/multimedia_utils_lite) + +[multimedia\_histreamer](https://gitee.com/openharmony/multimedia_histreamer) + +[multimedia\_camera\_standard](https://gitee.com/openharmony/multimedia_camera_standard) + +[multimedia\_audio\_standard](https://gitee.com/openharmony/multimedia_audio_standard) + +[multimedia\_media\_standard](https://gitee.com/openharmony/multimedia_media_standard) diff --git a/website/docs/extras/en/readme/multimodal-input.md b/website/docs/extras/en/readme/multimodal-input.md new file mode 100644 index 0000000000000000000000000000000000000000..281623fe463270b0c3bbffc01af5e5c88256e3a1 --- /dev/null +++ b/website/docs/extras/en/readme/multimodal-input.md @@ -0,0 +1,46 @@ +--- +title: "multimodal-input" +prepermalink: /extras/4442e7fbc36251cb8cccf67926a5a379/ +permalink: /extras/4442e7fbc36251cb8cccf67926a5a379/ +relpath: "OpenHarmony-3.1-Release/en/readme/multimodal-input.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [multimodal-input] +--- +# Multimodal Input + +## Overview + +OpenHarmony provides a Natural User Interface \(NUI\) for you to interact with your users. Unlike conventional categorization of input methods, OpenHarmony combines input methods of different dimensions into multimodal inputs, so you can easily arm your application with multi-dimensional, natural interaction features by using the application framework and system built-in UI components or APIs. + +Specifically, OpenHarmony currently supports traditional input methods such as key and touch inputs. + +## Directory Structure + +``` +/foundation/multimodalinput/input +├── common # Common code +├── interfaces # External APIs +│ └── native # Native APIs +│ └── innerkits # Native APIs provided for internal subsystems +├── service # Service framework code +├── sa_profile # Service startup configuration file +├── uinput # Input event injection module +``` + +## Usage + +Available APIs of Multimodal Input are event injection ones, which are open only to system apps currently. + +## Repositories Involved + +**Multimodal input subsystem** + +multimodalinput\_input + diff --git a/website/docs/extras/en/readme/pan-sensor.md b/website/docs/extras/en/readme/pan-sensor.md new file mode 100644 index 0000000000000000000000000000000000000000..579279107c2e0c0c86b5eff5e5098685e4174cd7 --- /dev/null +++ b/website/docs/extras/en/readme/pan-sensor.md @@ -0,0 +1,59 @@ +--- +title: "pan-sensor" +prepermalink: /extras/94fbdb68e38dac49ef74a2d1b5f8c852/ +permalink: /extras/94fbdb68e38dac49ef74a2d1b5f8c852/ +relpath: "OpenHarmony-3.1-Release/en/readme/pan-sensor.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [pan-sensor] +--- +# Pan-Sensor + +## Introduction + +The pan-sensor service subsystem provides a lightweight sensor service framework, through which you can perform the following operations: + +- Query the sensor list. +- Enable or disable a sensor. +- Subscribe to or unsubscribe from sensor data. +- Set the data reporting mode of a sensor. + +The following figure shows the architecture of the pan-sensor service framework. + +**Figure1** Pan-sensor service architecture + +![](../../../images/en/readme/figures/b0cdd11c42cacc66ee9d521e0a1bb8e2.png) + +## Directory Structure + +``` +/base/sensors +├── sensor_lite # Sensor directory +│ ├── frameworks # Framework code +│ ├── interfaces # Native APIs +│ └── services # Code of services +└── miscdevice_lite # Misc device directory +``` + +## Usage + +The following modules work cooperatively to implement pan-sensor capabilities: Sensor API, Sensor Framework, and Sensor Service. + +- Sensor API: provides APIs for performing basic operations on sensors, including querying the sensor list, enabling or disabling sensors, and subscribing to or unsubscribing from sensor data. +- Sensor Framework: manages sensor data subscription, creates and destroys data channels, subscribes to or unsubscribes from sensor data, and implements communication with the Sensor Service module. +- Sensor Service: interacts with the HDF module to receive, parse, and distribute data, manages sensor services and sensor data reporting, and controls sensor permissions. + +## Repositories Involved + +**Pan-sensor subsystem** + +[sensors_sensor_lite](https://gitee.com/openharmony/sensors_sensor_lite/blob/master/README.md) + +[sensors_miscdevice_lite](https://gitee.com/openharmony/sensors_miscdevice_lite/blob/master/README.md) + diff --git a/website/docs/extras/en/readme/power-management.md b/website/docs/extras/en/readme/power-management.md new file mode 100644 index 0000000000000000000000000000000000000000..dbfe22c0b76be4dc72501094d9e370acd448eedf --- /dev/null +++ b/website/docs/extras/en/readme/power-management.md @@ -0,0 +1,75 @@ +--- +title: "power-management" +prepermalink: /extras/2f3d15dde0acd4e383fb2bddf3105cc3/ +permalink: /extras/2f3d15dde0acd4e383fb2bddf3105cc3/ +relpath: "OpenHarmony-3.1-Release/en/readme/power-management.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [power-management] +--- +# Power Management + +## Introduction + +The power management subsystem provides the following functions: + +1. System restarting: restarts or shuts down the system. +2. System power management: manages the system power status and running lock. +3. Display-related power consumption adjustment: adjusts the backlight brightness based on the ambient light and turns off the screen based on the proximity light. +4. Power saving: works in low power consumption mode without compromising main functions and performance. +5. Battery management: supports charging and discharging, battery and charging status monitoring (including status updating and reporting), and charging upon power-off. +6. Temperature control: restricts temperature rise through application, SoC, and peripheral control when the device temperature reaches the specified limit. +7. Power consumption statistics: collects statistics on the power consumption of software, hardware, and a single application. +8. Battery service for mini-, small-, and standard-system devices +9. Power management service for mini-, small-, and standard-system devices + +**Figure 1** Power management subsystem architecture + + +![](../../../images/en/readme/figures/d577232a1aedfdd7ad7ee515692b6309.png) + +## Directory Structure + +``` +/base/powermgr +├── battery_lite # Battery service for mini-, small-, and standard-system devices +├── battery_manager # Battery service +├── battery_statistics # Power consumption statistics service +├── display_manager # Display energy efficiency management service +├── power_manager # System power management service +├── powermgr_lite # Power management service for mini-, small-, and standard-system devices +└── thermal_manager # Temperature control and thermal management service +``` + +## Usage + +As shown in the system architecture, the power management subsystem consists of seven modules. Some modules provide external APIs or public event notifications. You can use them based on your use cases. The functions of key modules are described as follows: + +- Power Manager: provides APIs to request and release the running lock, enable the power saving mode, adjust the brightness, and restart or power off the device. It also provides public events for you to observe changes of the power saving mode and power-off status. +- Battery Manager: provides APIs to query battery information. It also provides public events for you to observer changes of the battery status and charging/discharging status. +- Thermal Manager: provides APIs to query the temperature rise status of a device. It also allows you to register callbacks and public events to listen for the temperature rise status of a device. +- Battery Statistics: provides power consumption statistics on hardware and software. It allows you to query the power consumption of hardware or applications. + +## Repositories Involved + +**Power Management Subsystem** + +[powermgr_power_manager](https://gitee.com/openharmony/powermgr_power_manager) + +[powermgr_display_manager](https://gitee.com/openharmony/powermgr_display_manager) + +[powermgr_battery_manager](https://gitee.com/openharmony/powermgr_battery_manager) + +[powermgr_thermal_manager](https://gitee.com/openharmony/powermgr_thermal_manager) + +[powermgr_battery_statistics](https://gitee.com/openharmony/powermgr_battery_statistics) + +[powermgr_battery_lite](https://gitee.com/openharmony/powermgr_battery_lite) + +[powermgr_powermgr_lite](https://gitee.com/openharmony/powermgr_powermgr_lite) diff --git a/website/docs/extras/en/readme/programming-language-runtime.md b/website/docs/extras/en/readme/programming-language-runtime.md new file mode 100644 index 0000000000000000000000000000000000000000..89153f99c14ceadd9af0540d8a6a3933096f82d3 --- /dev/null +++ b/website/docs/extras/en/readme/programming-language-runtime.md @@ -0,0 +1,61 @@ +--- +title: "programming-language-runtime" +prepermalink: /extras/14162893fa1c089258a48caa0acd9df0/ +permalink: /extras/14162893fa1c089258a48caa0acd9df0/ +relpath: "OpenHarmony-3.1-Release/en/readme/programming-language-runtime.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [programming-language-runtime] +--- +# Programming Language Runtime + +## Introduction + +This subsystem provides the compilation and execution environment for programs developed with JavaScript, and C/C++, basic libraries that support the runtime, and the runtime-associated APIs, compilers, and auxiliary tools. Modules in this subsystem are classified based on the currently supported programming languages: JavaScript, and C/C++. Each module can be compiled independently and can be combined and separated based on development scenarios. + +**Figure 1** Subsystem architecture +![](../../../images/en/readme/figures/d2a9906e016b7d51a3a0682312c2178a.png "subsystem-architecture-1") + +This subsystem consists of the runtime, libraries, and compilers that support the running of JavaScript, and C/C++ programs, and provides the basic libraries, API , JavaScript engine capability, and a toolchain that supports language compilation. + +## Directory Structure + +``` +/prebuilts/mingw-w64/ohos/linux-x86_64 # cross-compilation toolchain for Linux platform + └── clang-mingw + ├── bin + ├── lib + ├── libexec + ├── NOTICE + ├── share + └── x86_64-w64-mingw32 +``` + +## Constraints + +1. You are not allowed to add or modify the APIs without permission. +2. The implementation of the JavaScript engine is restricted by the subsystem. There is no configuration item for external systems. + +## Usage + +Basic language capabilities are supported through library files. Some capabilities are integrated into Native, and JavaScript SDKs and integrated into DevEco Studio releases. For details about the usage, see the readme file of each module. + +The following list shows the repositories of third-party software and precompilation toolchains that are referenced. + +/third\_party/boost + +/third\_party/quickjs + +/third\_party/jerryscript + +/third\_party/mingw-w64 + +## Repositories Involved + +**Programming language runtime subsystem** diff --git a/website/docs/extras/en/readme/startup.md b/website/docs/extras/en/readme/startup.md new file mode 100644 index 0000000000000000000000000000000000000000..bc9e50fb786dca5b75c36b5a2b9f7ed3a09e8fec --- /dev/null +++ b/website/docs/extras/en/readme/startup.md @@ -0,0 +1,313 @@ +--- +title: "startup" +prepermalink: /extras/9b4534ff1cacc1ea58fa5927893c3887/ +permalink: /extras/9b4534ff1cacc1ea58fa5927893c3887/ +relpath: "OpenHarmony-3.1-Release/en/readme/startup.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [startup] +--- +# Startup + +## Introduction + +The Startup subsystem provides the functions of starting key system processes and services after the kernel is started and before applications are started, and restoring the system to factory settings. The subsystem consists of the following modules: + +- init\_lite + + This module can be used on the Hi3516D V300 and Hi3518E V300 platforms powered by LiteOS Cortex-A. + + It starts system service processes from the time the kernel loads the first user-space process to the time the first application is started. In addition to loading key system processes, the module needs to configure their permissions during the startup and keep the specified process alive after sub-processes are started. If a process exits abnormally, the module needs to restart it, and to perform system reset for a special process. + + +- appspawn\_lite + + This module can be used on the Hi3516D V300 and Hi3518E V300 platforms powered by LiteOS Cortex-A. + + This module spawns application processes upon receiving commands from the application framework, configures permissions for new processes, and calls the entry function of the application framework. + +- bootstrap\_lite + + This module can be used on the Hi3861 platform powered by LiteOS Cortex-M. + + This module provides entry identifiers for starting services and features. When Samgr starts, it will call the entry function identified by bootstrap\_lite and start system services. + +- syspara\_lite + + This module obtains and sets system attributes. + + It can be used on the Hi3861, Hi3516D V300, and Hi3518E V300 platforms powered by LiteOS Cortex-M and LiteOS Cortex-A. Supported system attributes consist of default, OEM-specified, and custom system attributes. OEM-specified system attributes provide only default values. The specific values need to be adjusted as required. For details, see [Usage Guidelines](#section8533192617117). + + +## Directory Structure + +**Table 1** Directory structure of the source code for the startup subsystem + + + + + + + + + + + + + + + + + + + + + + + + +

Directory

+

Description

+

Applicable Platform

+

base/startup/appspawn_lite

+

appspawn_lite module for spawning application processes. It receives Ability Manager Service (AMS) messages via IPC, parses the messages, starts application processes based on the parsing result, and grants permissions to them.

+

Hi3516D V300

+

Hi3518E V300

+

base/startup/bootstrap_lite

+

bootstrap_lite module for starting all services except core system services.

+

Hi3861

+

base/startup/init_lite

+

init_lite module for implementing the init process, which is the first user-space process loaded after the kernel is initialized. Upon startup, the process parses the configuration file in /etc/init.cfg. Based on the parsing result, the process then starts other key system processes and grants required permissions to them.

+

Hi3516D V300

+

Hi3518E V300

+

base/startup/syspara_lite

+

syspara_lite module that provides APIs to obtain device information, including the product name, brand name, category name, and manufacturer name.

+

Hi3861

+

Hi3516D V300

+

Hi3518E V300

+
+ +``` +base/startup/ +├── appspawn_standard # appspawn_lite module for the standard system +│ ├── include # Header files +│ ├── parameter # System parameters +│ ├── src # Source files +│ └── test # Test cases +├── appspawn_lite # appspawn_lite module for the mini system +│ └── services +│ ├── include # Header files +│ ├── src # Source files +│ └── test # Test cases +├── bootstrap_lite # bootstrap_lite module +│ └── services +│ └── source # Source files +├── init_lite # init_lite module +│ ├── initsync # Source files +│ ├── interfaces # External APIs +│ └── services +│ ├── include # Header files +│ ├── src # Source files +│ └── test # Test cases +└── syspara_lite # syspara_lite module + ├── adapter # Adaptation code + ├── frameworks # Source files + ├── hals # Header files for the hardware abstraction layer (HAL) + ├── interfaces # External APIs + └── simulator # Simulator adaptation +``` + +## Constraints + +OEM-specified system attributes provide only default values. The specific values need to be adjusted as required. + +## Usage Guidelines + +- Configuration file of the init\_lite module + + The configuration file **init.cfg** of the init\_lite module contains service names, executable file paths, permissions, and other attributes of all key system services that need to be started by the init process. The file is stored in **/vendor/hisilicon/hispark\_aries/init\_configs/** under **/etc/**. It is in JSON format, and its size cannot exceed 100 KB. + + After the init process starts, it reads the **/etc/init.cfg** file, parses the JSON content, and loads system services in sequence based on the parsing result. The format and content of the configuration file are described as follows: + + +``` +{ + "jobs" : [{ + "name" : "pre-init", -------- Job executed before the initialization. It can be used to store some operations (for example, creating a directory) performed before the init process is started. + "cmds" : [ -------- Commands supported by the current job. Currently, only start, mkdir, chmod, chown, and mount are currently supported. + -------- The command name and the parameters (128 bytes or less) must be separated by only one space. + "mkdir /testdir", -------- Command for creating a directory. mkdir and the target directory must be separated by only one space. + "chmod 0700 /testdir", -------- Command for modifying the permission. chmod, permission, and the target directory must be separated by only one space. The permission must be in the 0xxx format. + "chown 99 99 /testdir",-------- Command for modifying the owner group. chown, UID, GID, and the target directory must be separated by only one space. + "mkdir /testdir2", + "mount vfat /dev/mmcblk0p0 /testdir2 noexec nosuid" -------- mount command in the following format: mount file system type source target flags data + -------- Supported flags include only nodev, noexec, nosuid, and rdonly, which are separated by a space. + ] + }, { + "name" : "init", -------- Job name, which currently supports only pre-init, init, and post-init. + "cmds" : [ -------- A single job currently supports a maximum of 30 commands. + "start service1", -------- Service startup command 1. + "start service2" -------- Service startup command 2. The sequence of the commands in the array can be adjusted as required. The init process then executes the commands in the same sequence as they are parsed. + ] + }, { + "name" : "post-init", -------- Job executed after the initialization. It can be used to store some operations performed after the init process is started. + "cmds" : [] + } + ], + "services" : [{ -------- Service set (in an array), including all system services that need to be started by the init process. Currently, a maximum of 100 services are supported. + "name" : "service1", -------- Name of the current service. A maximum of 32 bytes must be specified for the name. + "path" : "/bin/process1" -------- Full path of the executable file of the current service. A maximum of 64 bytes must be specified for the path. + "uid" : 1, -------- UID of the current service process. + "gid" : 1, -------- GID of the current service process. + "once" : 0, -------- Whether the current service process is a one-off process. + 0 --- The current service process is not a one-off process. If the process exits for a certain reason, the init_lite module restarts the service process upon receiving the SIGCHLD signal. + non-0 --- The current service process is a one-off process. If the process exits for a certain reason, the init_lite module does not restart the service process. + "importance" : 1, -------- Whether the current service process is a key system process + 0 --- The current service process is not a key system process. If the process exits due to any reason, the init_lite module does not reset the system. + non-0 --- The current service process is a key system process. If the process exits due to any reason, the init_lite module resets and restarts the system upon receiving the SIGCHLD signal. + "caps" : [0, 1, 2, 5] -------- Capabilities required by the current service. They are determined by the capabilities supported by the security subsystem and configured in accordance with the principle of least permission. (Currently, a maximum of 100 values can be configured.) + }, { + "name" : "service2", -------- Next service that needs to be started by the init_lite module. The service sequence is irrelevant to the startup sequence, which is determined by the command sequence in the previous job. + "path" : "/bin/process2", + "uid" : 2, + "gid" : 2, + "once" : 1, + "importance" : 0, + "caps" : [ ] + } + ] +} +``` + +**Table 2** Supported commands + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Name

+

Syntax

+

Description

+

start

+

start ServiceName (Only one space is allowed.)

+

Starts a service. The service name must be the same as that in the services array in the file.

+

mkdir

+

mkdir /xxxx/xxx (Only one space is allowed.)

+

Creates a directory.

+

chmod

+

chmod 0xxx /xxx/xx (Only one space is allowed.)

+

Changes the permission. The permission value must be in 0xxx format, for example, 0755 or 0600. This configuration must comply with the principle of least permission.

+

chown

+

chown uid gid /xxx/xx (Only one space is allowed.)

+

Changes the owner group.

+

mount

+

mount fileSysType source target flags data (Only one space is allowed.)

+

Mounts data. Currently, flags can only be nodev, noexec, nosuid, or rdonly, and other strings are considered as data.

+
+ +It is worth noting that the modified **init.cfg** file must be in JSON format. Otherwise, the init process fails to parse the file, and no service will be started. The configured service permission **uid/gid/capability** must meet the requirements imposed by the security subsystem and comply with the principle of least permission. In addition, if the values of **once** and **importance** of a service are both **0** and the service exits for more than four consecutive times within four minutes, the init process will stop restarting the service. + +- System parameters + - OEM-specific system attributes + + For Hi3516D V300 and Hi3518E V300 development boards, you need to modify the source files in the **vendor/hisilicon/hispark\_aries/hals/utils/sys\_param** directory. + + ``` + static const char HOS_PRODUCT_TYPE[] = {"****"}; + static const char HOS_MANUFACTURE[] = {"****"}; + static const char HOS_BRAND[] = {"****"}; + static const char HOS_MARKET_NAME[] = {"****"}; + static const char HOS_PRODUCT_SERIES[] = {"****"}; + static const char HOS_PRODUCT_MODEL[] = {"****"}; + static const char HOS_SOFTWARE_MODEL[] = {"****"}; + static const char HOS_HARDWARE_MODEL[] = {"****"}; + static const char HOS_HARDWARE_PROFILE[] = {"aout:true,display:true"}; + static const char HOS_BOOTLOADER_VERSION[] = {"bootloader"}; + static const char HOS_SECURE_PATCH_LEVEL[] = {"2020-6-5"}; + static const char HOS_ABI_LIST[] = {"****"}; + ``` + + For Hi3861 development boards, you need to modify the source files in the **vendor/hisilicon/hispark\_pegasus/hals/utils/sys\_param** directory. + + ``` + static const char HOS_PRODUCT_TYPE[] = {"****"}; + static const char HOS_MANUFACTURE[] = {"****"}; + static const char HOS_BRAND[] = {"****"}; + static const char HOS_MARKET_NAME[] = {"****"}; + static const char HOS_PRODUCT_SERIES[] = {"****"}; + static const char HOS_PRODUCT_MODEL[] = {"****"}; + static const char HOS_SOFTWARE_MODEL[] = {"****"}; + static const char HOS_HARDWARE_MODEL[] = {"****"}; + static const char HOS_HARDWARE_PROFILE[] = {"aout:true,display:true"}; + static const char HOS_BOOTLOADER_VERSION[] = {"bootloader"}; + static const char HOS_SECURE_PATCH_LEVEL[] = {"2020-6-5"}; + static const char HOS_ABI_LIST[] = {"****"}; + ``` + + - Obtaining default system attributes + + ``` + const char* value1 = GetProductType(); + printf("Product type =%s\n", value1); + const char* value2 = GetManufacture(); + printf("Manufacture =%s\n", value2); + const char* value3 = GetBrand(); + printf("GetBrand =%s\n", value3); + ``` + + + - Obtaining custom system attributes + + ``` + const char* defSysParam = "data of sys param ***..."; + char key[] = "rw.parameter.key"; + char value[] = "OEM-hisi-10.1.0"; + int ret = SetParameter(key, value); + char valueGet[128] = {0}; + ret = GetParameter(key, defSysParam, valueGet, 128); + printf("value = %s\n", valueGet); + ``` + + + +## Repositories Involved + +Startup subsystem + +startup\_syspara\_lite + +startup\_appspawn\_lite + +startup\_bootstrap\_lite + +startup\_init\_lite + diff --git a/website/docs/extras/en/readme/system-apps.md b/website/docs/extras/en/readme/system-apps.md new file mode 100644 index 0000000000000000000000000000000000000000..dd25bd97b827cd86693ef306d8773c8e1bed54d5 --- /dev/null +++ b/website/docs/extras/en/readme/system-apps.md @@ -0,0 +1,49 @@ +--- +title: "system-apps" +prepermalink: /extras/87bbcef17a7a0ce79e22ca52bc7122fa/ +permalink: /extras/87bbcef17a7a0ce79e22ca52bc7122fa/ +relpath: "OpenHarmony-3.1-Release/en/readme/system-apps.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [system-apps] +--- +# System Apps + +## Introduction + +This module provides some system apps that are applicable to the OpenHarmony standard system, such as Launcher, SystemUI, and Settings. It also provides specific examples for you to build standard-system apps, which can be installed on all devices running the standard system. + +Currently, OpenHarmony supports the following system apps: + +1. Launcher: acts as a main entry for all apps and provides UIs for display and human-machine interactions of installed apps. +2. SystemUI: consists of the navigation bar and system status bar. The navigation bar provides page navigation, and the status bar displays the system status, such as the time and charging status. +3. Settings: provides functions such as device management, app management, and brightness setting. + +## Directory Structure + +``` +/applications/standard/ +├── launcher # Launcher app code +├── systemui # SystemUI app code +├── settings # Settings app code +├── hap # Binary code for system apps +``` + +## Repositories Involved + +**System apps** + +applications\_standard\_settings + +applications\_standard\_launcher + +applications\_standard\_systemui + +applications\_standard\_hap + diff --git a/website/docs/extras/en/readme/telephony.md b/website/docs/extras/en/readme/telephony.md new file mode 100644 index 0000000000000000000000000000000000000000..f6a0434ccef5d8cd617b0bc56d89587b441ff23e --- /dev/null +++ b/website/docs/extras/en/readme/telephony.md @@ -0,0 +1,161 @@ +--- +title: "telephony" +prepermalink: /extras/a5f85fdef2150383f4b68063d0c63394/ +permalink: /extras/a5f85fdef2150383f4b68063d0c63394/ +relpath: "OpenHarmony-3.1-Release/en/readme/telephony.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [telephony] +--- +# Telephony + +- [Introduction](#section104mcpsimp) +- [Directory Structure](#section119mcpsimp) +- [Constraints](#section123mcpsimp) +- [Usage](#section128mcpsimp) + - [Obtaining the Current Cellular Network Signal Information](#section1458213210369) + - [Observing Changes to the Cellular Network Status](#section750135512369) + +- [Repositories Involved](#section152mcpsimp) + +## Introduction + +The Telephony subsystem provides APIs for obtaining information about the wireless cellular network and SIM card. Applications can call these APIs to obtain information such as the name of the currently registered network, network service status, signal strength, and SIM card information. + +The Telephony subsystem consists of the following modules: + +- Telephony core service: initializes the Radio Interface Layer (RIL) Manager, SIM card module, and radio module. +- Call Manager module: manages three types of calls – circuit switched \(CS\), IP multimedia subsystem \(IMS\), and over the top \(OTT\) calls. It is responsible for applying for the audio and video resources required for a call and resolving conflicts in a multi-channel call. +- Cellular call module: implements basic calls over carrier networks. +- Cellular data module: implements cellular data services over carrier networks. +- SMS & MMS module: provides the capabilities of sending and receiving short message service \(SMS\) messages and encoding and decoding multimedia messaging service \(MMS\) messages. +- State registry module: provides APIs to register and deregister an observer that listens for various callback events of the telephony subsystem. +- Data storage module: stores persistent data and provides **DataAbility** access APIs. +- RIL Adapter module: implements adaptation of the modem communication interfaces. + +**Figure 1** Telephony subsystem architecture + +![](../../../images/en/readme/figures/e13e7dd26d556e17a90b33f5a6437784.png) + +## Directory Structure + +``` +base/telephony/ +├── core_service # Telephony core service +├── call_manager # Call Manager module +├── cellular_call # Cellular call module +├── cellular_data # Cellular data module +├── sms_mms # SMS & MMS module +├── state_registry # State registry module +├── data_storage # Data storage module +└── ril_adapter # RIL Adapter module +``` + +## Constraints + +1. The open-source version currently provides the cellular call (CS call only), SMS & MMS, and cellular data services and supports the dual-SIM framework. +2. The Hardware Device Interface (HDI) support is subject to the chip vendors' adaptation capability. For details, see [Telephony Service Development](https://gitee.com/openharmony/docs/blob/master/en/device-dev/subsystems/subsys-tel.md). + +## Usage Guidelines + +To learn more about the usage of each subsystem module, refer to the respective README. The following illustrates API usage by exemplifying how to obtain the current cellular network signal information and observe the cellular network status changes. + +### Obtaining the Current Cellular Network Signal Information + +1. Import the **radio** namespace from **@ohos.telephony.radio.d.ts**. +2. Call the **getSignalInformation\(slotId: number\)** function via callback or promise. This function works in asynchronous mode. +3. Obtain the result from the **SignalInformation** array in the callback. +4. Traverse the **SignalInformation** array to obtain the **signalLevel** (signal strength) for each **signalType** (radio access technology). + + ``` + // Import the radio package. + import radio from "@ohos.telephony.radio"; + + // Set the value of slotId. + let slotId = 0; + + // Call the API in callback mode. + radio.getSignalInformation(slotId, (err, value) => { + if (err) { + // If the API call fails, err is not empty. + console.error(`failed to getSignalInformation because ${err.message}`); + return; + } + // If the API call is successful, err is empty. + for (let i = 0; i < value.length; i++) { + console.log(`success to getSignalInformation: type is ${value[i].signalType}, level is ${value[i].signalLevel}`); + } + }); + + // Call the API in promise mode. + let promise = radio.getSignalInformation(slotId); + promise.then((value) => { + // The API call is successful. + for (let i = 0; i < value.length; i++) { + console.log(`success to getSignalInformation: type is ${value[i].signalType}, level is ${value[i].signalLevel}`); + } + }).catch((err) => { + // The API call fails. + console.error(`failed to getSignalInformation because ${err.message}`); + }); + ``` + + +### Observing Cellular Network Status Changes + +Adding an Observer + +1. Import the **observer** namespace from **@ohos.telephony.observer.d.ts**. +2. Call the **on\(type:'networkStateChange'\)** function with **slotId** (slot ID, optional) and **callback** (callback processing function) passed in. +3. Register an **observer** instance for callback events of network status changes. + + ``` + // Import the observer package. + import observer from '@ohos.telephony.observer'; + + // Registers an observer. + observer.on('networkStateChange', {slotId: 0}, (value) => { + console.log(`network state is ` + value); + }); + ``` + + +Removing the Observer + +1. Import the **observer** namespace from **@ohos.telephony.observer.d.ts**. +2. Call the **off\(type: 'networkStateChange'\)** function with the **callback** object passed to **observer**. + + ``` + // Import the observer package. + import observer from '@ohos.telephony.observer'; + + // Unregister the observer. + observer.off('networkStateChange'); + ``` + + +## Repositories Involved + +**Telephony Subsystem** + +[telephony\_core\_service](https://gitee.com/openharmony/telephony_core_service/blob/master/README.md) + +[telephony\_call\_manager](https://gitee.com/openharmony/telephony_call_manager/blob/master/README.md) + +[telephony\_cellular\_call](https://gitee.com/openharmony/telephony_cellular_call/blob/master/README.md) + +[telephony\_cellular\_data](https://gitee.com/openharmony/telephony_cellular_data/blob/master/README.md) + +[telephony\_sms\_mms](https://gitee.com/openharmony/telephony_sms_mms/blob/master/README.md) + +[telephony\_state\_registry](https://gitee.com/openharmony/telephony_state_registry/blob/master/README.md) + +telephony\_data\_storage + +[telephony\_ril\_adapter](https://gitee.com/openharmony/telephony_ril_adapter/blob/master/README.md) diff --git a/website/docs/extras/en/readme/test.md b/website/docs/extras/en/readme/test.md new file mode 100644 index 0000000000000000000000000000000000000000..48001e8f7b86017c3e7b53d730d899654a79bdd3 --- /dev/null +++ b/website/docs/extras/en/readme/test.md @@ -0,0 +1,859 @@ +--- +title: "test" +prepermalink: /extras/19b06ff672386b48159b0436f6e7bd39/ +permalink: /extras/19b06ff672386b48159b0436f6e7bd39/ +relpath: "OpenHarmony-3.1-Release/en/readme/test.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [test] +--- +# Test Subsystem +OpenHarmony provides a comprehensive auto-test framework for designing test cases. Detecting defects in the development process can improve code quality. + +This document describes how to use the OpenHarmony test framework. +## Setting Up the Environment +The test framework depends on the Python running environment. Before using the test framework, set up the environment as follows: + - [Setting Up the Environment](/extras/1cadfdbd2f8e258e93402f3eb61ab9a8/) + - [Obtaining Source Code](/pages/en/device/device/Quick%20Start/Obtaining%20Source%20Code) + + +## Directory Structure +The directory structure of the test framework is as follows: +``` +test # Test subsystem +├── developertest # Developer test module +│ ├── aw # Static library of the test framework +│ ├── config # Test framework configuration +│ │ │ ... +│ │ └── user_config.xml # User configuration +│ ├── examples # Examples of test cases +│ ├── src # Source code of the test framework +│ ├── third_party # Adaptation code for third-party components on which the test framework depends +│ ├── reports # Test reports +│ ├── BUILD.gn # Build entry of the test framework +│ ├── start.bat # Test entry for Windows +│ └── start.sh # Test entry for Linux +└── xdevice # Modules on which the test framework depends +``` +## Writing Test Cases +### Designing the Test Case Directory +Design the test case directory as follows: +``` +subsystem # Subsystem +├── partA # Part A +│ ├── moduleA # Module A +│ │ ├── include +│ │ ├── src # Service code +│ │ └── test # Test directory +│ │ ├── unittest # Unit test +│ │ │ ├── common # Common test cases +│ │ │ │ ├── BUILD.gn # Build file of test cases +│ │ │ │ └── testA_test.cpp # Source code of unit test cases +│ │ │ ├── phone # Test cases for mobile phones +│ │ │ ├── ivi # Test cases for head units +│ │ │ └── liteos-a # Test cases for the IP cameras that use the LiteOS kernel +│ │ ├── moduletest # Module test +│ │ ... +│ │ +│ ├── moduleB # Module B +│ ├── test +│ │ └── resource # Dependency resources +│ │ ├── moduleA # Module A +│ │ │ ├── ohos_test.xml # Resource configuration file +│ │ ... └── 1.txt # Resource +│ │ +│ ├── ohos_build # Build entry configuration +│ ... +│ +... +``` +> **Note:** Test cases are classified into common test cases and device-specific test cases. You are advised to place common test cases in the **common** directory and device-specific test cases in the directories of the related devices. + +### Writing Test Cases +This test framework supports test cases written in multiple programming languages and provides different templates for different languages. + +#### C++ Test Case Example + +- Naming rules for source files + + The source file name of test cases must be the same as that of the test suite. The file names must use lowercase letters and in the [Function]\_[Sub-function]\_**test** format. More specific sub-functions can be added as required. +Example: + ``` + calculator_sub_test.cpp + ``` + +- Test case example + ``` + /* + * Copyright (c) 2021 XXXX 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 "calculator.h" + #include + + using namespace testing::ext; + + class CalculatorSubTest : public testing::Test { + public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + }; + + void CalculatorSubTest::SetUpTestCase(void) + { + // Set a setup function, which will be called before all test cases. + } + + void CalculatorSubTest::TearDownTestCase(void) + { + // Set a teardown function, which will be called after all test cases. + } + + void CalculatorSubTest::SetUp(void) + { + // Set a setup function, which will be called before each test case. + } + + void CalculatorSubTest::TearDown(void) + { + // Set a teardown function, which will be called after each test case. + } + + /** + * @tc.name: integer_sub_001 + * @tc.desc: Verify the sub-function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + HWTEST_F(CalculatorSubTest, integer_sub_001, TestSize.Level1) + { + // Step 1 Call the function to obtain the result. + int actual = Sub(4, 0); + + // Step 2 Use an assertion to compare the obtained result with the expected result. + EXPECT_EQ(4, actual); + } + ``` + The procedure is as follows: + 1. Add comment information to the test case file header. + ``` + /* + * Copyright (c) 2021 XXXX 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. + */ + ``` + 2. Add the test framework header file and namespace. + ``` + #include + + using namespace testing::ext; + ``` + 3. Add the header file of the test class. + ``` + #include "calculator.h" + ``` + 4. Define the test suite (test class). + ``` + class CalculatorSubTest : public testing::Test { + public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + }; + + void CalculatorSubTest::SetUpTestCase(void) + { + // Set a setup function, which will be called before all test cases. + } + + void CalculatorSubTest::TearDownTestCase(void) + { + // Set a teardown function, which will be called after all test cases. + } + + void CalculatorSubTest::SetUp(void) + { + // Set a setup function, which will be called before each test case. + } + + void CalculatorSubTest::TearDown(void) + { + // Set a teardown function, which will be called after each test case. + } + ``` + > **Note**: When defining a test suite, ensure that the test suite name is the same as the target to build and uses the upper camel case style. + + 5. Add implementation of the test cases, including test case comments and logic. + ``` + /** + * @tc.name: integer_sub_001 + * @tc.desc: Verify the sub function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ + HWTEST_F(CalculatorSubTest, integer_sub_001, TestSize.Level1) + { + // Step 1 Call the function to obtain the test result. + int actual = Sub(4, 0); + + // Step 2 Use an assertion to compare the obtained result with the expected result. + EXPECT_EQ(4, actual); + } + ``` + The following test case templates are provided for your reference. + + | Template| Description| + | ------------| ------------| + | HWTEST(A,B,C)| Use this template if the test case execution does not depend on setup or teardown.| + | HWTEST_F(A,B,C)| Use this template if the test case execution (excluding parameters) depends on setup and teardown.| + | HWTEST_P(A,B,C)| Use this template if the test case execution (including parameters) depends on setup and teardown.| + + In the template names: + - *A* indicates the test suite name. + - *B* indicates the test case name, which is in the *Function*\_*No.* format. The *No.* is a three-digit number starting from **001**. + - *C* indicates the test case level. There are five test case levels: guard-control level 0 and non-guard-control level 1 to level 4. Of levels 1 to 4, a smaller value indicates a more important function verified by the test case. + + **Note**: + - The expected result of each test case must have an assertion. + - The test case level must be specified. + - It is recommended that the test be implemented step by step according to the template. + - The comment must contain the test case name, description, type, and requirement number, which are in the @tc.*xxx*: *value* format. The test case description must be in the @tc.xxx format. The test case type @tc.type can be any of the following: + + | Test Case Type|Code| + | ------------|------------| + |Function test |FUNC| + |Performance test |PERF| + |Reliability test |RELI| + |Security test |SECU| + |Fuzz test |FUZZ| + + +#### JavaScript Test Case Example + +- Naming rules for source files + + The source file name of a test case must be in the [Function]\[Sub-function]Test format, and each part must use the upper camel case style. More specific sub-functions can be added as required. +Example: + ``` + AppInfoTest.js + ``` + +- Test case example + ``` + /* + * Copyright (C) 2021 XXXX 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. + */ + import app from '@system.app' + + import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' + + describe("AppInfoTest", function () { + beforeAll(function() { + // Set a setup function, which will be called before all test cases. + console.info('beforeAll caled') + }) + + afterAll(function() { + // Set a teardown function, which will be called after all test cases. + console.info('afterAll caled') + }) + + beforeEach(function() { + // Set a setup function, which will be called before each test case. + console.info('beforeEach caled') + }) + + afterEach(function() { + // Set a teardown function, which will be called after each test case. + console.info('afterEach caled') + }) + + /* + * @tc.name:appInfoTest001 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("appInfoTest001", 0, function () { + // Step 1 Call the function to obtain the test result. + var info = app.getInfo() + + // Step 2 Use an assertion to compare the obtained result with the expected result. + expect(info != null).assertEqual(true) + }) + }) + ``` + The procedure is as follows: + 1. Add comment information to the test case file header. + ``` + /* + * Copyright (C) 2021 XXXX 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. + */ + ``` + 2. Import the APIs and JSUnit test library to test. + ``` + import app from '@system.app' + + import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' + ``` + 3. Define the test suite (test class). + ``` + describe("AppInfoTest", function () { + beforeAll(function() { + // Set a setup function, which will be called before all test cases. + console.info('beforeAll caled') + }) + + afterAll(function() { + // Set a teardown function, which will be called after all test cases. + console.info('afterAll caled') + }) + + beforeEach(function() { + // Set a setup function, which will be called before each test case. + console.info('beforeEach caled') + }) + + afterEach(function() { + // Set a teardown function, which will be called after each test case. + console.info('afterEach caled') + }) + ``` + 4. Add implementation of the test cases. + ``` + /* + * @tc.name:appInfoTest001 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("appInfoTest001", 0, function () { + // Step 1 Call the function to obtain the test result. + var info = app.getInfo() + + // Step 2 Use an assertion to compare the obtained result with the expected result. + expect(info != null).assertEqual(true) + }) + ``` + +### Writing the Build File for Test Cases +When a test case is executed, the test framework searches for the build file of the test case in the test case directory and builds the test case located. The following describes how to write build files (GN files) in different programming languages. + +#### Writing Build Files for Test Cases +The following provides templates for different languages for your reference. + +- **Test case build file example (C++)** + ``` + # Copyright (c) 2021 XXXX Device Co., Ltd. + + import("//build/test.gni") + + module_output_path = "subsystem_examples/calculator" + + config("module_private_config") { + visibility = [ ":*" ] + + include_dirs = [ "../../../include" ] + } + + ohos_unittest("CalculatorSubTest") { + module_out_path = module_output_path + + sources = [ + "../../../include/calculator.h", + "../../../src/calculator.cpp", + ] + + sources += [ "calculator_sub_test.cpp" ] + + configs = [ ":module_private_config" ] + + deps = [ "//third_party/googletest:gtest_main" ] + } + + group("unittest") { + testonly = true + deps = [":CalculatorSubTest"] + } + ``` + The build file is configured as follows: + + 1. Add comment information for the file header. + ``` + # Copyright (c) 2021 XXXX Device Co., Ltd. + ``` + 2. Import the build template. + ``` + import("//build/test.gni") + ``` + 3. Specify the file output path. + ``` + module_output_path = "subsystem_examples/calculator" + ``` + > **Note**: The output path is ***Part name*/*Module name***. + + 4. Configure the directories for dependencies. + + ``` + config("module_private_config") { + visibility = [ ":*" ] + + include_dirs = [ "../../../include" ] + } + ``` + > **Note**: Generally, the dependency directories are configured here and directly referenced in the build script of the test case. + + 5. Set the output build file for the test cases. + + ``` + ohos_unittest("CalculatorSubTest") { + } + ``` + 6. Write the build script (add the source file, configuration, and dependencies) for the test cases. + ``` + ohos_unittest("CalculatorSubTest") { + module_out_path = module_output_path + sources = [ + "../../../include/calculator.h", + "../../../src/calculator.cpp", + "../../../test/calculator_sub_test.cpp" + ] + sources += [ "calculator_sub_test.cpp" ] + configs = [ ":module_private_config" ] + deps = [ "//third_party/googletest:gtest_main" ] + } + ``` + + > **Note:** Set the test type based on actual requirements. The following test types are available: + > - **ohos_unittest**: unit test + > - **ohos_moduletest**: module test + > - **ohos_systemtest**: system test + > - **ohos_performancetest**: performance test + > - **ohos_securitytest**: security test + > - **ohos_reliabilitytest**: reliability test + > - **ohos_distributedtest**: distributed test + + 7. Group the test case files by test type. + + ``` + group("unittest") { + testonly = true + deps = [":CalculatorSubTest"] + } + ``` + > **Note**: Grouping test cases by test type allows you to execute a specific type of test cases when required. + +- **Test case build file example (JavaScript)** + + ``` + # Copyright (C) 2021 XXXX Device Co., Ltd. + + import("//build/test.gni") + + module_output_path = "subsystem_examples/app_info" + + ohos_js_unittest("GetAppInfoJsTest") { + module_out_path = module_output_path + + hap_profile = "./config.json" + certificate_profile = "//test/developertest/signature/openharmony_sx.p7b" + } + + group("unittest") { + testonly = true + deps = [ ":GetAppInfoJsTest" ] + } + ``` + + The procedure is as follows: + + 1. Add comment information for the file header. + + ``` + # Copyright (C) 2021 XXXX Device Co., Ltd. + ``` + 2. Import the build template. + + ``` + import("//build/test.gni") + ``` + 3. Specify the file output path. + + ``` + module_output_path = "subsystem_examples/app_info" + ``` + > **Note**: The output path is ***Part name*/*Module name***. + + 4. Set the output build file for the test cases. + + ``` + ohos_js_unittest("GetAppInfoJsTest") { + } + ``` + > **Note:** + >- Use the **ohos\_js\_unittest** template to define the JavaScript test suite. Pay attention to the difference between JavaScript and C++. + >- The file generated for the JavaScript test suite must be in .hap format and named after the test suite name defined here. The test suite name must end with **JsTest**. + + 5. Configure the **config.json** file and signature file, which are mandatory. + + ``` + ohos_js_unittest("GetAppInfoJsTest") { + module_out_path = module_output_path + + hap_profile = "./config.json" + certificate_profile = "//test/developertest/signature/openharmony_sx.p7b" + } + ``` + **config.json** is the configuration file required for HAP build. You need to set **target** based on the tested SDK version. Default values can be retained for other items. The following is an example: + + ``` + { + "app": { + "bundleName": "com.example.myapplication", + "vendor": "example", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5 // Set it based on the tested SDK version. In this example, SDK5 is used. + } + }, + "deviceConfig": {}, + "module": { + "package": "com.example.myapplication", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "com.example.myapplication.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "MyApplication", + "type": "page", + "launchType": "standard" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } + } + ``` + 6. Group the test case files by test type. + ``` + group("unittest") { + testonly = true + deps = [ ":GetAppInfoJsTest" ] + } + ``` + > **Note**: Grouping test cases by test type allows you to execute a specific type of test cases when required. + +#### Configuring ohos.build + +Configure the part build file to associate with specific test cases. +``` +"partA": { + "module_list": [ + + ], + "inner_list": [ + + ], + "system_kits": [ + + ], + "test_list": [ + "//system/subsystem/partA/calculator/test:unittest" // Configure test under calculator. + ] + } +``` +> **Note**: **test_list** contains the test cases of the corresponding module. + +### Configuring Test Case Resources +Test case resources include external file resources, such as image files, video files, and third-party libraries, required for test case execution. + +Perform the following steps: +1. Create the **resource** directory in the **test** directory of the part, and create a directory for the module in the **resource** directory to store resource files of the module. + +2. In the module directory under **resource**, create the **ohos_test.xml** file in the following format: + ``` + + + + + + + + ``` +3. In the build file of the test cases, configure **resource\_config\_file** to point to the resource file **ohos\_test.xml**. + ``` + ohos_unittest("CalculatorSubTest") { + resource_config_file = "//system/subsystem/partA/test/resource/calculator/ohos_test.xml" + } + ``` + >**Note:** + >- **target_name** indicates the test suite name defined in the **BUILD.gn** file in the **test** directory. + >- **preparer** indicates the action to perform before the test suite is executed. + >- **src="res"** indicates that the test resources are in the **resource** directory under the **test** directory. + >- **src="out"** indicates that the test resources are in the **out/release/$(part)** directory. +## Executing Test Cases +Before executing test cases, you need to modify the configuration based on the device used. + +### Modifying user_config.xml +``` + + + + false + + false + + true + + + + + + + + + + + + + cmd + 115200 + 8 + 1 + 1 + + + + + + + + + + + + + + + + + + +``` +>**Note**: If HDC is connected to the device before the test cases are executed, you only need to configure the device IP address and port number, and retain the default settings for other parameters. + +### Executing Test Cases on Windows +#### Building Test Cases + +Test cases cannot be built on Windows. You need to run the following command to build test cases on Linux: +``` +./build.sh --product-name Hi3516DV300 --build-target make_test +``` +When the build is complete, the test cases are automatically saved in the **out/hi3516dv300/packages/phone/images/tests** directory. + +>**Note:** In the command, **Hi3516DV300** is the platform supported by the current version, and **make_test** indicates all test cases. You can set the build options based on requirements: +> - --**product-name**: specifies the name of the product to build. It is mandatory. +> - --**build-target**: specifies the target to build. It is optional. + +#### Setting Up the Execution Environment +1. On Windows, create the **Test** directory in the test framework and then create the **testcase** directory in the **Test** directory. + +2. Copy **developertest** and **xdevice** from the Linux environment to the **Test** directory on Windows, and copy the test cases to the **testcase** directory. +>**Note**: Port the test framework and test cases from the Linux environment to the Windows environment for subsequent execution. + +3. Modify the **user_config.xml** file. + ``` + + + false + + + + D:\Test\testcase\tests + + ``` + >**Note**: `` indicates whether to build test cases. `` indicates the path for searching for test cases. + +#### Executing Test Cases +1. Start the test framework. + ``` + start.bat + ``` +2. Select the product. + + After the test framework starts, you are asked to select a product. Select the development board to test, for example, **Hi3516DV300**. + +3. Execute test cases. + + Run the following command to execute test cases: + ``` + run -t UT -ts CalculatorSubTest -tc interger_sub_00l + ``` + In the command: + ``` + -t [TESTTYPE]: specifies the test type, which can be UT, MST, ST, or PERF. This parameter is mandatory. + -tp [TESTPART]: specifies the part to test. This parameter can be used independently. + -tm [TESTMODULE]: specifies the module to test. This parameter must be used together with -tp. + -ts [TESTSUITE]: specifies the test suite. This parameter can be used independently. + -tc [TESTCASE]: specifies the test case. This parameter must be used together with -ts. + You can run -h to display help information. + ``` +### Executing Test Cases on Linux +#### Mapping Remote Port +To enable test cases to be executed on a remote Linux server or a Linux VM, map the port to enable communication between the device and the remote server or VM. Configure port mapping as follows: +1. On the HDC server, run the following commands: + ``` + hdc_std kill + hdc_std -m -s 0.0.0.0:8710 + ``` + >**Note**: The IP address and port number are default values. + +2. On the HDC client, run the following command: + ``` + hdc_std -s xx.xx.xx.xx:8710 list targets + ``` + >**Note**: Enter the IP address of the device to test. + +#### Executing Test Cases +1. Start the test framework. + ``` + ./start.sh + ``` +2. Select the product. + + After the test framework starts, you are asked to select a product. Select the development board to test, for example, **Hi3516DV300**. + +3. Execute test cases. + + The test framework locates the test cases based on the command, and automatically builds and executes the test cases. + ``` + run -t UT -ts CalculatorSubTest -tc interger_sub_00l + ``` + In the command: + ``` + -t [TESTTYPE]: specifies the test type, which can be UT, MST, ST, or PERF. This parameter is mandatory. + -tp [TESTPART]: specifies the part to test. This parameter can be used independently. + -tm [TESTMODULE]: specifies the module to test. This parameter must be used together with -tp. + -ts [TESTSUITE]: specifies the test suite. This parameter can be used independently. + -tc [TESTCASE]: specifies the test case. This parameter must be used together with -ts. + You can run -h to display help information. + ``` + +## Viewing the Test Report +After the test cases are executed, the test result will be automatically generated. You can view the detailed test result in the related directory. + +### Test Result +You can obtain the test result in the following directory: +``` +test/developertest/reports/xxxx_xx_xx_xx_xx_xx +``` +>**Note**: The folder for test reports is automatically generated. + +The folder contains the following files: +| Type| Description| +| ------------ | ------------ | +| result/ |Test cases in standard format| +| log/plan_log_xxxx_xx_xx_xx_xx_xx.log | Test case logs| +| summary_report.html | Test report summary| +| details_report.html | Detailed test report| + +### Test Framework Logs +``` +reports/platform_log_xxxx_xx_xx_xx_xx_xx.log +``` + +### Latest Test Report +``` +reports/latest +``` + +## Repositories Involved + +[test\_xdevice](https://gitee.com/openharmony/test_xdevice/blob/master/README.md) diff --git a/website/docs/extras/en/readme/update.md b/website/docs/extras/en/readme/update.md new file mode 100644 index 0000000000000000000000000000000000000000..1955fca62e2df14dffe1bed076fb1b9b32b7a290 --- /dev/null +++ b/website/docs/extras/en/readme/update.md @@ -0,0 +1,92 @@ +--- +title: "update" +prepermalink: /extras/72e687d195deaa8cda2ae3c793b533e5/ +permalink: /extras/72e687d195deaa8cda2ae3c793b533e5/ +relpath: "OpenHarmony-3.1-Release/en/readme/update.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [update] +--- +# Update + +## Introduction + +The Update subsystem helps you implement over the air \(OTA\) update of OpenHarmony devices. The update subsystem consists of the following: + +1. Packaging tool + + The packaging tool is developed using Python and deployed on the PC to prepare update packages. It packages each update image, signs the update package, generates the update package execution script, and finally creates an update package. After the execution script is run on a OpenHarmony device, the device parses and executes the script to complete the update process. + + The update package contains two files: **build\_tools.zip** and **update.bin**. + + - **build\_tools.zip**: update assistance tools, including the executable files and scripts. + - **update.bin**: TLV-encoded file, in which update contents are serialized and stored in the TLV format. + + The packaging tool signs the **update.bin** file and the generated update package \(**.zip** file\) independently. + +2. Update service + + The update service is used to search, download, and trigger updates. + +3. Updater + + The updater is the core module of the update subsystem. It provides the following functions: + + 1. Obtains update commands from the misc partition and executes different tasks depending on the commands. + 2. Decompresses the update package and verifies its validity. + 3. Starts the update process and parses the update script. + 4. Installs the related component packages based on the update script. + 5. Performs post-processing after the update is complete, for example, deleting the update package and recording the update status. + +4. Update app + + The upgrade app is used to trigger search and download of update packages. + + +Before you get started, familiarize yourself with the following concepts: + +- OTA + + OTA is an implementation of update over a wireless connection. The update package is downloaded to the device through a wireless connection. The device then performs update through the update subsystem. + +- Full package + + A full package is actually a complete image. The update subsystem writes the full package to a partition to update this partition. + +- Differential package + + A differential package is created based on the difference data of two specific versions \(source version and target version\), which is generated by using bsdiff. + + +## Directory Structure + +``` +base/update # Update subsystem repository +├── app # Update app code +├── packaging_tools # Packaging tool code +├── updater # Updater code +│ ├── interfaces # External APIs +│ ├── resources # UI image resources of the update subsystem, such as animations and progress bar images +│ ├── services # Updater logic code +│ └── utils # Common code of the update subsystem, including the string processing functions and file processing functions +└── updateservice # Update service code +``` + +## Repositories Involved + +**Update subsystem** + +update\_app + +update\_updateservice + +update\_updater + +update\_packaging\_tools + diff --git a/website/docs/extras/en/readme/user-iam.md b/website/docs/extras/en/readme/user-iam.md new file mode 100644 index 0000000000000000000000000000000000000000..6dbd43316bab0e6f4f9c09c4af93f11eda03a35c --- /dev/null +++ b/website/docs/extras/en/readme/user-iam.md @@ -0,0 +1,71 @@ +--- +title: "user-iam" +prepermalink: /extras/bfbee4ff9c4dcba5ed88aeb799ed53f9/ +permalink: /extras/bfbee4ff9c4dcba5ed88aeb799ed53f9/ +relpath: "OpenHarmony-3.1-Release/en/readme/user-iam.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [user-iam] +--- +# User IAM Subsystem + +## Introduction + +The user identity and access management (IAM) subsystem provides a unified framework for user credential management and user identity authentication in OpenHarmony. It allows multiple users to set their own authentication credential information and authenticates their identities based on the information set. This subsystem is widely used in security-sensitive scenarios such as screen lock. The subsystem also provides APIs for third-party developers to call the identity authentication capabilities to control user access. + +**Figure 1** Subsystem architecture + +User IAM subsystem architecture + +The user IAM subsystem consists of the unified user authentication framework and authentication executor. The unified user authentication framework consists of the following parts: + +- Unified user authentication: provides unified user identity authentication externally and provides open biometric authentication capabilities for third-party applications to invoke. +- User credential management: provides a unified user credential information management interface for the upper layer and invokes authentication resources in the system through the authentication executor management part to implement lifecycle management and secure storage of user credentials. +- Authentication executor management: provides authentication resource management and authentication session management, and supports unified management, scheduling, and connection of various authentication executors in the system. + +Based on the unified user authentication framework, the system can be extended to support multiple authentication capabilities. Currently, the authentication executors supported by OpenHarmony are password and facial authentication. To implement a new authentication executor, you only need to implement authentication capabilities in a new part and connect the new part to the unified user authentication framework based on the interfaces defined by the authentication executor management part. + +*Note: In the user IAM subsystem, an authentication executor is the minimum execution unit of a user identity authentication operation. For example, a password authentication module is responsible for password collection, password processing and comparison, and secure storage, and therefore it can be abstracted as a password authentication executor.* + +## Directory Structure + + +```undefined +//base/user_iam +├── auth_executor_mgr # Authentication executor management part, which supports unified authentication resource management and scheduling +├── face_auth # Facial authentication module, which connects to the authentication executor management part and supports facial information recording, deletion, and verification +├── pin_auth # Password authentication module, which connects to the authentication executor management part and supports password recording, deletion, and verification +├── user_auth # Unified user authentication part +└── user_idm # User credential management part + +``` + +## Constraints + +1. User credential management is a key operation in the system, and interfaces used for user credential management can be invoked only by basic system applications. +2. The authentication executors process user authentication credentials and their capabilities can only be implemented by system services for interconnection with the authentication executor management part. + +## Usage + +### How to Use + +1. The unified user authentication framework must work with an authentication executor. +2. The first default authentication executor in the system must be password authentication. + +## Repositories Involved + +[useriam_auth_executor_mgr](https://gitee.com/openharmony/useriam_auth_executor_mgr) + +[useriam_user_idm](https://gitee.com/openharmony/useriam_user_idm) + +[useriam_user_auth](https://gitee.com/openharmony/useriam_user_auth) + +[useriam_pin_auth](https://gitee.com/openharmony/useriam_pin_auth) + +[useriam_faceauth](https://gitee.com/openharmony/useriam_faceauth) diff --git a/website/docs/extras/en/readme/utils.md b/website/docs/extras/en/readme/utils.md new file mode 100644 index 0000000000000000000000000000000000000000..fbbbe60c0618af4f72d4d1d4cb42606e5a358b6b --- /dev/null +++ b/website/docs/extras/en/readme/utils.md @@ -0,0 +1,44 @@ +--- +title: "utils" +prepermalink: /extras/4dd80a8c6c2c511e35e9f2c38d8b2fbb/ +permalink: /extras/4dd80a8c6c2c511e35e9f2c38d8b2fbb/ +relpath: "OpenHarmony-3.1-Release/en/readme/utils.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [utils] +--- +# utils + +## Introduction + +The **utils** repository provides ndk_libraries_config and system functions. + +## Directory Structure + +``` +utils +├── native # Utility class implementation at the Native layer +├── ndk_libraries_config # Configuration of the NDK library +└── system # System-related predefined values and security policy configuration +``` + +## Usage + +For details, see the API Reference. + +## Repositories Involved + +Utils subsystem + +**utils** + +utils\_native + +[utils\_native\_lite](https://gitee.com/openharmony/utils_native_lite) + diff --git a/website/docs/extras/en/readme/window-manager.md b/website/docs/extras/en/readme/window-manager.md new file mode 100644 index 0000000000000000000000000000000000000000..c1700fcd4f3b0cd8042348ccc50b2fb2c82ec2a1 --- /dev/null +++ b/website/docs/extras/en/readme/window-manager.md @@ -0,0 +1,74 @@ +--- +title: "window-manager" +prepermalink: /extras/5b0ab00d1fb8b5c2de0ec70b39b1393e/ +permalink: /extras/5b0ab00d1fb8b5c2de0ec70b39b1393e/ +relpath: "OpenHarmony-3.1-Release/en/readme/window-manager.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [window-manager] +--- +# Window Manager + +## Introduction + +The Window Manager subsystem provides basic capabilities of window and display management. It is the basis for UI display. The following figure shows the architecture of the Window Manager subsystem. + +**Figure 1** Architecture of the Window Manager subsystem + +![WindowManager-subsystem-architecture](../../../images/en/readme/figures/ea06c874563d94a0479037a4c5e7efbf.png) + +- **Window Manager Client** + + Provides window object abstraction and window management interfaces, and connects to the ability and UI framework. + +- **Display Manager Client** + + Provides display information abstraction and display management interfaces. + +- **Window Manager Server** + + Provides capabilities such as window layout, Z-order control, window tree structure, window dragging, and window snapshot, and offers the window layout and focus window for multimodal input. + +- **Display Manager Server** + + Provides display information, screenshot, screen on/off, and brightness processing control, and processes the mapping between the display and screen. + +## Directory Structure + +```text +foundation/windowmanager/ +├── dm # Stores Display Manager Client implementation code +├── dmserver # Stores Display Manager Server implementation code +├── interfaces # Stores external APIs +│ ├── innerkits # Stores native APIs +│ └── kits # Stores JS APIs and native APIs +├── resources # Stores resource files used by the framework +├── sa_profile # Stores system service configuration files +├── snapshot # Stores implementation code of the screenshot command line tool +├── utils # Stores tools +├── wm # Stores Window Manager Client implementation code +├── wmserver # Stores Window Manager Server implementation code +``` + +## Constraints + +- Programming language version + - C++ 11 or later + +## Available APIs + +- [Window](https://gitee.com/openharmony/docs/blob/master/en/application-dev/reference/apis/js-apis-window.md) +- [Display](https://gitee.com/openharmony/docs/blob/master/en/application-dev/reference/apis/js-apis-display.md) + +## Repositories Involved + +- graphic_standard +- ace_ace_engine +- aafwk_standard +- multimodalinput_input diff --git a/website/docs/extras/en/readme/xts.md b/website/docs/extras/en/readme/xts.md new file mode 100644 index 0000000000000000000000000000000000000000..b95434fb6709a0bad1cbf695c876cc3196345656 --- /dev/null +++ b/website/docs/extras/en/readme/xts.md @@ -0,0 +1,649 @@ +--- +title: "xts" +prepermalink: /extras/b4f7235de3eb2fecbb67e50ddf03cedf/ +permalink: /extras/b4f7235de3eb2fecbb67e50ddf03cedf/ +relpath: "OpenHarmony-3.1-Release/en/readme/xts.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [xts] +--- +# XTS + +## Introduction + +The X test suite \(XTS\) subsystem contains a set of OpenHarmony certification test suites, including the currently supported application compatibility test suite \(ACTS\) and the device compatibility test suite \(DCTS\) that will be supported in the future. + +This subsystem contains the ACTS and **tools** software package. + +- The **acts** directory stores the source code and configuration files of ACTS test cases. The ACTS helps device vendors detect the software incompatibility as early as possible and ensures that the software is compatible to OpenHarmony during the entire development process. +- The **tools** software package stores the test case development framework related to **acts**. + +## System Types + +OpenHarmony supports the following system types: + +- Mini system + + A mini system runs on the devices whose memory is greater than or equal to 128 KiB and that are equipped with MCU processors such as ARM Cortex-M and 32-bit RISC-V. This system provides multiple lightweight network protocols and graphics frameworks, and a wide range of read/write components for the IoT bus. Typical products include connection modules, sensors, and wearables for smart home. + +- Small system + + A small system runs on the devices whose memory is greater than or equal to 1 MiB and that are equipped with application processors such as ARM Cortex-A. This system provides higher security capabilities, standard graphics frameworks, and video encoding and decoding capabilities. Typical products include smart home IP cameras, electronic cat eyes, and routers, and event data recorders \(EDRs\) for smart travel. + +- Standard system + + A standard system runs on the devices whose memory is greater than or equal to 128 MiB and that are equipped with application processors such as ARM Cortex-A. This system provides a complete application framework supporting the enhanced interaction, 3D GPU, hardware composer, diverse components, and rich animations. This system applies to high-end refrigerator displays. + + +## Directory Structure + +``` +/test/xts +├── acts # Test code +│ └── subsystem # Source code of subsystem test cases for the standard system +│ └── subsystem_lite # Source code of subsystems test cases for mini and small systems +│ └── BUILD.gn # Build configuration of test cases for the standard system +│ └── build_lite +│ └── BUILD.gn # Build configuration of test cases for mini and small systems +└── tools # Test tool code +``` + +## Constraints + +Test cases for the mini system must be developed based on C, and those for the small system must be developed based on C++. + +## Usage Guidelines + +**Table 1** Test case levels + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Level

+

Definition

+

Scope

+

Level0

+

Smoke

+

Verifies basic functionalities of key features and basic DFX attributes with the most common input. The pass result indicates that the features are runnable.

+

Level1

+

Basic

+

Verifies basic functionalities of key features and basic DFX attributes with common input. The pass result indicates that the features are testable.

+

Level2

+

Major

+

Verifies basic functionalities of key features and basic DFX attributes with common input and errors. The pass result indicates that the features are functional and ready for beta testing.

+

Level3

+

Regular

+

Verifies functionalities of all key features, and all DFX attributes with common and uncommon input combinations or normal and abnormal preset conditions.

+

Level4

+

Rare

+

Verifies functionalities of key features under extremely abnormal presets and uncommon input combinations.

+
+ +**Table 2** Test case granularities + + + + + + + + + + + + + + + + + + + + +

Test Scale

+

Test Objects

+

Test Environment

+

LargeTest

+

Service functionalities, all-scenario features, and mechanical power environment (MPE) and scenario-level DFX

+

Devices close to real devices

+

MediumTest

+

Modules, subsystem functionalities after module integration, and DFX

+

Single device that is actually used. You can perform message simulation, but do not mock functions.

+

SmallTest

+

Modules, classes, and functions

+

Local PC. Use a large number of mocks to replace dependencies with other modules.

+
+ +**Table 3** Test types + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Type

+

Definition

+

Function

+

Tests the correctness of both service and platform functionalities provided by the tested object for end users or developers.

+

Performance

+

Tests the processing capability of the tested object under specific preset conditions and load models. The processing capability is measured by the service volume that can be processed in a unit time, for example, call per second, frame per second, or event processing volume per second.

+

Power

+

Tests the power consumption of the tested object in a certain period of time under specific preset conditions and load models.

+

Reliability

+

Tests the service performance of the tested object under common and uncommon input conditions, or specified service volume pressure and long-term continuous running pressure. The test covers stability, pressure handling, fault injection, and Monkey test times.

+

Security

+
  • Tests the capability of defending against security threats, including but not limited to unauthorized access, use, disclosure, damage, modification, and destruction, to ensure information confidentiality, integrity, and availability.
  • Tests the privacy protection capability to ensure that the collection, use, retention, disclosure, and disposal of users' private data comply with laws and regulations.
  • Tests the compliance with various security specifications, such as security design, security requirements, and security certification of the Ministry of Industry and Information Technology (MIIT).
+

Global

+

Tests the internationalized data and localization capabilities of the tested object, including multi-language display, various input/output habits, time formats, and regional features, such as currency, time, and culture taboos.

+

Compatibility

+
  • Tests backward compatibility of an application with its own data, the forward and backward compatibility with the system, and the compatibility with different user data, such as audio file content of the player and smart SMS messages.
  • Tests system backward compatibility with its own data and the compatibility of common applications in the ecosystem.
  • Tests software compatibility with related hardware.
+

User

+

Tests user experience of the object in real user scenarios. All conclusions and comments should come from the users, which are all subjective evaluation in this case.

+

Standard

+

Tests the compliance with industry and company-specific standards, protocols, and specifications. The standards here do not include any security standards that should be classified into the security test.

+

Safety

+

Tests the safety property of the tested object to avoid possible hazards to personal safety, health, and the object itself.

+

Resilience

+

Tests the resilience property of the tested object to ensure that it can withstand and maintain the defined running status (including downgrading) when being attacked, and recover from and adapt defense to the attacks to approach mission assurance.

+
+ +## Test Case Development Guidelines + +You should select the appropriate programming language and your target test framework to develop test cases. + +**Table 4** Test frameworks and test case languages for different systems + + + + + + + + + + + + + + + + + + + + +

System

+

Test Framework

+

Language

+

Mini

+

HCTest

+

C

+

Small

+

HCPPTest

+

C++

+

Standard

+

HJSUnit and HCPPTest

+

JavaScript and C++

+
+ +### C-based Test Case Development and Compilation \(for the Mini System\) + +**Developing test cases for the mini system** + +The HCTest framework is used to support test cases developed with the C language. HCTest is enhanced and adapted based on the open-source test framework Unity. + +1. Access the **test/xts/acts** repository where the test cases will be stored. + + ``` + ├── acts + │ └──subsystem_lite + │ │ └── module_hal + │ │ │ └── BUILD.gn + │ │ │ └── src + │ └──build_lite + │ │ └── BUILD.gn + ``` + +2. Write the test case in the **src** directory. + + 1 Import the test framework header file. + + ``` + #include "hctest.h" + ``` + + 2. Use the **LITE\_TEST\_SUIT** macro to define names of the subsystem, module, and test suite. + + ``` + /** + * @brief Registers a test suite named IntTestSuite. + * @param test Subsystem name + * @param example Module name + * @param IntTestSuite Test suite name + */ + LITE_TEST_SUIT(test, example, IntTestSuite); + ``` + + 3. Define Setup and TearDown. + + Format: Test suite name+Setup, Test suite name+TearDown. + + The Setup and TearDown functions must exist, but function bodies can be empty. + + 4. Use the **LITE\_TEST\_CASE** macro to write the test case. + + Three parameters are involved: test suite name, test case name, and test case properties \(including type, granularity, and level\). + + ``` + LITE_TEST_CASE(IntTestSuite, TestCase001, Function | MediumTest | Level1) + { + // Do something + }; + ``` + + 5. Use the **RUN\_TEST\_SUITE** macro to register the test suite. + + ``` + RUN_TEST_SUITE(IntTestSuite); + ``` + +3. Create the configuration file \(**BUILD.gn**\) of the test module. + + Create a **BUILD.gn** \(example\) build file in each test module directory. Specify the name of the built static library and its dependent header file and library in the build file. The format is as follows: + + ``` + import("//test/xts/tools/lite/build/suite_lite.gni") + hctest_suite("ActsDemoTest") { + suite_name = "acts" + sources = [ + "src/test_demo.c", + ] + include_dirs = [ ] + cflags = [ "-Wno-error" ] + } + ``` + +4. Add build options to the **BUILD.gn** file in the **acts** directory. + + You need to add the test module to the **test/xts/acts/build\_lite/BUILD.gn** script in the **acts** directory. + + ``` + lite_component("acts") { + ... + if(board_name == "liteos_m") { + features += [ + ... + "//xts/acts/subsystem_lite/module_hal:ActsDemoTest" + ] + } + } + ``` + +5. Run build commands. + + Test suites are built along with version build. The ACTS is built together with the debug version. + + >![](../../../images/en/readme/public_sys-resources/ae89e6a5f31e3d03603c1d114c8400cf.gif) **NOTE:** + >The ACTS build middleware is a static library, which will be linked to the image. + + +### C-based Test Case Execution \(for the Mini System\) + +**Executing test cases for the mini system** + +Burn the image into the development board. + +**Executing the test** + +1. Use a serial port tool to log in to the development board and save information about the serial port. +2. Restart the device and view serial port logs. + +**Analyzing the test result** + +View the serial port logs, whose format is as follows: + +The log for each test suite starts with **Start to run test suite:** and ends with **xx Tests xx Failures xx Ignored**. + +### C++-based Test Case Development and Compilation \(for Standard and Small Systems\) + +**Developing test cases for small-system devices** \(For examples of the standard system, go to the **global/i18n\_standard directory**.\) + +The HCPPTest framework is enhanced and adapted based on the open-source framework Googletest. + +1. Access the **test/xts/acts** repository where the test cases will be stored. + + ``` + ├── acts + │ └──subsystem_lite + │ │ └── module_posix + │ │ │ └── BUILD.gn + │ │ │ └── src + │ └──build_lite + │ │ └── BUILD.gn + ``` + +2. Write the test case in the **src** directory. + + 1. Import the test framework header file. + + The following statement includes **gtest.h**. + + ``` + #include "gtest/gtest.h" + ``` + + 2. Define Setup and TearDown. + + ``` + using namespace std; + using namespace testing::ext; + class TestSuite: public testing::Test { + protected: + // Preset action of the test suite, which is executed before the first test case + static void SetUpTestCase(void){ + } + // Test suite cleanup action, which is executed after the last test case + static void TearDownTestCase(void){ + } + // Preset action of the test case + virtual void SetUp() + { + } + // Cleanup action of the test case + virtual void TearDown() + { + } + }; + ``` + + 3. Use the **HWTEST** or **HWTEST\_F** macro to write the test case. + + **HWTEST**: definition of common test cases, including the test suite name, test case name, and case annotation. + + **HWTEST\_F**: definition of SetUp and TearDown test cases, including the test suite name, test case name, and case annotation. + + Three parameters are involved: test suite name, test case name, and test case properties \(including type, granularity, and level\). + + ``` + HWTEST_F(TestSuite, TestCase_0001, Function | MediumTest | Level1) { + // Do something + } + ``` + +3. Create a configuration file \(**BUILD.gn**\) of the test module. + + Create a **BUILD.gn** build file in each test module directory. Specify the name of the built static library and its dependent header file and library in the build file. Each test module is independently built into a **.bin** executable file, which can be directly pushed to the development board for testing. + + Example: + + ``` + import("//test/xts/tools/lite/build/suite_lite.gni") + hcpptest_suite("ActsDemoTest") { + suite_name = "acts" + sources = [ + "src/TestDemo.cpp" + ] + + include_dirs = [ + "src", + ... + ] + deps = [ + ... + ] + cflags = [ "-Wno-error" ] + } + ``` + +4. Add build options to the **BUILD.gn** file in the **acts** directory. + + Add the test module to the **test/xts/acts/build\_lite/BUILD.gn** script in the **acts** directory. + + ``` + lite_component("acts") { + ... + else if(board_name == "liteos_a") { + features += [ + ... + "//xts/acts/subsystem_lite/module_posix:ActsDemoTest" + ] + } + } + ``` + +5. Run build commands. + + Test suites are built along with the version build. The ACTS is built together with the debug version. + + >![](../../../images/en/readme/public_sys-resources/ae89e6a5f31e3d03603c1d114c8400cf.gif) **NOTE:** + >The ACTS for the small system is independently built to an executable file \(.bin\) and archived in the **suites\\acts** directory of the build result. + + +### C++-based Test Case Execution \(for Standard and Small Systems\) + +**Executing test cases for the small system** + +Currently, test cases are shared by the NFS and mounted to the development board for execution. + +**Setting up the environment** + +1. Use a network cable or wireless network to connect the development board to your PC. +2. Configure the IP address, subnet mask, and gateway for the development board. Ensure that the development board and the PC are in the same network segment. +3. Install and register the NFS server on the PC and start the NFS service. +4. Run the **mount** command for the development board to ensure that the development board can access NFS shared files on the PC. + + Format: **mount** _NFS server IP address_**:/**_NFS shared directory_ **/**_development board directory_ **nfs** + + Example: + + ``` + mount 192.168.1.10:/nfs /nfs nfs + ``` + + +**Executing test cases** + +Execute **ActsDemoTest.bin** to trigger test case execution, and analyze serial port logs generated after the execution is complete. + +### JavaScript-based Test Case Development \(for the Standard System\) + +The HJSUnit framework is used to support automated test of OpenHarmony apps that are developed using the JavaScript language based on the JS application framework. + +**Basic syntax of test cases** + +The test cases are developed with the JavaScript language and must meet the programming specifications of the language. + +**Table 5** + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Syntax

+

Description

+

Mandatory

+

beforeAll

+

Presets a test-suite-level action executed only once before all test cases are executed. You can pass the action function as the only parameter.

+

No

+

afterAll

+

Presets a test-suite-level clear action executed only once after all test cases are executed. You can pass the clear function as the only parameter.

+

No

+

beforeEach

+

Presets a test-case-level action executed before each test case is executed. The number of execution times is the same as the number of test cases defined by it. You can pass the action function as the only parameter.

+

No

+

afterEach

+

Presets a test-case-level clear action executed after each test case is executed. The number of execution times is the same as the number of test cases defined by it. You can pass the clear function as the only parameter.

+

No

+

describe

+

Defines a test suite. You can pass two parameters: test suite name and test suite function. The describe statement supports nesting. You can use beforeall, beforeEach, afterEach, and afterAll in each describe statement.

+

Yes

+

it

+

Defines a test case. You can pass three parameters: test case name, filter parameter, and test case function.

+

Usage of the filter parameter:

+

The value of the filter parameter is a 32-bit integer. Setting different bits to 1 means different configurations:

+
  • bit 0: whether the filter parameter takes effect. 1 means that the test case is used for the function test and other settings of the parameter do not take effect.
  • Bits 0-10: test case categories
  • Bits 16-18: test case scales
  • Bits 24-28: test levels
+

Test case categories: Bits 0-10 indicate FUNCTION (function test), PERFORMANCE (performance test), POWER (power consumption test), RELIABILITY (reliability test), SECURITY (security compliance test), GLOBAL (integrity test), COMPATIBILITY (compatibility test), USER (user test), STANDARD (standard test), SAFETY (security feature test), and RESILIENCE (resilience test), respectively.

+

Test case scales: Bits 16-18 indicate SMALL (small-scale test), MEDIUM (medium-scale test), and LARGE (large-scale test), respectively.

+

Test levels: Bits 24-28 indicate LEVEL0 (level-0 test), LEVEL1 (level-1 test), LEVEL2 (level-2 test), LEVEL3 (level-3 test), and LEVEL4 (level-4 test), respectively.

+

Yes

+
+ +Use the standard syntax of Jasmine to write test cases. The ES6 specification is supported. + +1. Store the test cases in the **entry/src/main/js/test** directory, whose structure is as follows: + + ``` + ├── BUILD.gn + │ └──entry + │ │ └──src + │ │ │ └──main + │ │ │ │ └──js + │ │ │ │ │ └──default + │ │ │ │ │ │ └──pages + │ │ │ │ │ │ │ └──index + │ │ │ │ │ │ │ │ └──index.js # Entry file + │ │ │ │ │ └──test # Test code + │ │ │ └── resources # HAP resources + │ │ │ └── config.json # HAP configuration file + ``` + +2. Start the JS test framework and load test cases. The following is an example for **index.js**. + + ``` + // Start the JS test framework and load test cases. + import {Core, ExpectExtend} from 'deccjsunit/index' + + export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + core.addService('expect', expectExtend) + core.init() + const configService = core.getDefaultService('config') + configService.setConfig(this) + require('../../../test/List.test') + core.execute() + }, + onReady() { + }, + } + ``` + +3. Write a unit test case by referring to the following example: + + ``` + // Use HJSUnit to perform the unit test. + describe('appInfoTest', function () { + it('app_info_test_001', 0, function () { + var info = app.getInfo() + expect(info.versionName).assertEqual('1.0') + expect(info.versionCode).assertEqual('3') + }) + }) + ``` + + +### JavaScript-based Test Case Packaging \(for the Standard System\) + +For details about how to build a HAP, see the JS application development guide of the standard system [Building and Creating HAPs](https://developer.harmonyos.com/en/docs/documentation/doc-guides/build_overview-0000001055075201). + diff --git a/website/docs/extras/en/release-notes/OpenHarmony-v3.0.2-LTS.md b/website/docs/extras/en/release-notes/OpenHarmony-v3.0.2-LTS.md new file mode 100644 index 0000000000000000000000000000000000000000..854c088d04f02f1a312d5b951ddf8d9d3d73b6fe --- /dev/null +++ b/website/docs/extras/en/release-notes/OpenHarmony-v3.0.2-LTS.md @@ -0,0 +1,141 @@ +--- +title: "OpenHarmony-v3.0.2-LTS" +prepermalink: /extras/229818abf55130c590e32f4e82d91b32/ +permalink: /extras/229818abf55130c590e32f4e82d91b32/ +relpath: "OpenHarmony-3.1-Release/en/release-notes/OpenHarmony-v3.0.2-LTS.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [OpenHarmony-v3.0.2-LTS] +--- +# OpenHarmony 3.0.2 LTS + + +## Version Description + +OpenHarmony 3.0.2 LTS is a maintenance version of OpenHarmony 3.0 LTS. This version has rectified certain issues and security vulnerabilities detected in OpenHarmony 3.0.1 LTS. It is the latest stable release with a tag. + + +## Version Mapping + + **Table 1** Version mapping of software and tools + +| Software/Tool| Version| Remarks| +| -------- | -------- | -------- | +| OpenHarmony | 3.0.2 LTS | NA | +| SDK | 3.0.0.0 (API Version 7 release) | NA | +| (Optional) HUAWEI DevEco Studio| 3.0 Beta1 | Recommended for developing OpenHarmony applications| +| (Optional) HUAWEI DevEco Device Tool| 2.2 Beta2 | Recommended for developing OpenHarmony smart devices| + + +## Source Code Acquisition + + +### Acquiring Source Code Using the repo Tool + +Method 1 \(recommended\): Use the **repo** tool to download the source code over SSH. \(You must have an SSH public key for access to Gitee.\) + + +``` +repo init -u git@gitee.com:openharmony/manifest.git -b refs/tags/OpenHarmony-v3.0.2-LTS --no-repo-verify +repo sync -c +repo forall -c 'git lfs pull' +``` + +Method 2: Use the **repo** tool to download the source code over HTTPS. + + +``` +repo init -u https://gitee.com/openharmony/manifest.git -b refs/tags/OpenHarmony-v3.0.2-LTS --no-repo-verify +repo sync -c +repo forall -c 'git lfs pull' +``` + + +### Acquiring Source Code from Mirrors + + **Table 2** Mirrors for acquiring source code + +| LTS Code| Version| Mirror| SHA-256 Checksum| +| -------- | -------- | -------- | -------- | +| Full code base (for mini, small, and standard systems)| 3.0.2 | [Download](https://repo.huaweicloud.com/harmonyos/os/3.0.2/code-v3.0.2-LTS.tar.gz)| [Download](https://repo.huaweicloud.com/harmonyos/os/3.0.2/code-v3.0.2-LTS.tar.gz.sha256)| +| Standard system solution (binary)| 3.0.2 | [Download](https://repo.huaweicloud.com/harmonyos/os/3.0.2/standard.tar.gz) | [Download](https://repo.huaweicloud.com/harmonyos/os/3.0.2/standard.tar.gz.sha256) | +| Mini system Hi3861 solution (binary)| 3.0.2 | [Download](https://repo.huaweicloud.com/harmonyos/os/3.0.2/hispark_pegasus.tar.gz) | [Download](https://repo.huaweicloud.com/harmonyos/os/3.0.2/hispark_pegasus.tar.gz.sha256) | +| Small system Hi3516 solution - LiteOS (binary)| 3.0.2 | [Download](https://repo.huaweicloud.com/harmonyos/os/3.0.2/hispark_taurus.tar.gz) | [Download](https://repo.huaweicloud.com/harmonyos/os/3.0.2/hispark_taurus.tar.gz.sha256) | +| Small system Hi3516 solution - Linux (binary)| 3.0.2 | [Download](https://repo.huaweicloud.com/harmonyos/os/3.0.2/hispark_taurus_linux.tar.gz) | [Download](https://repo.huaweicloud.com/harmonyos/os/3.0.2/hispark_taurus_linux.tar.gz.sha256) | + + +## What's New + +This version has the following updates to OpenHarmony 3.0.1 LTS. + + +### Feature Updates + +This version does not involve feature updates. + + +### API Updates + +This version does not involve API updates. + + +### Chip and Development Board Adaptation + +For details about the adaptation status, see [SIG-Devboard](https://gitee.com/openharmony/community/blob/master/sig/sig-devboard/sig_devboard.md). + + +## Resolved Issues + + **Table 3** Issues resolved for the mini and small systems + +| Issue No.| Description| +| -------- | -------- | +| [I4UZ7U](https://gitee.com/openharmony/xts_acts/issues/I4UZ7U?from=project-issue) | There may be 35 failed items during the XTS test on a small-system device.| +| [I4V2DN](https://gitee.com/openharmony/xts_acts/issues/I4V2DN?from=project-issue) | The execution of two test cases times out during the ActsLwipTest module test.| +| [I4V3KC](https://gitee.com/openharmony/xts_acts/issues/I4V3KC?from=project-issue) | The test case testPublish0010 fails in the Distributed Scheduler.| +| [I4URGA](https://gitee.com/openharmony/applications_sample_camera/issues/I4URGA?from=project-issue) | A blue screen may appear when users search for WLAN signals on the **Settings** page.| +| [I4SDCK](https://gitee.com/openharmony/aafwk_aafwk_lite/issues/I4SDCK?from=project-issue) | An empty path or garbled characters are returned when users run **GetSrcPath** or **GetDataPath** on the Hi3516 development board of a small-system device.| +| [I4T6KZ](https://gitee.com/openharmony/communication_dsoftbus/issues/I4T6KZ) | The execution of **SendMessage** and **SendData4Data** fails during the transmission test.| +| I4UOUS | Plaintext passwords are printed in the logs of the serial port interface on the Hi3516 development board of a small-system device.| +| [I4OWZO](https://gitee.com/openharmony/third_party_toybox/issues/I4OWZO) | An error message is displayed when the **toybox mv** command is run to move a file in the NFS path.| +| [I4NCSF](https://gitee.com/openharmony/graphic_ui/issues/I4NCSF) | In the UI module of the Graphics subsystem, the linear pointer does not refresh in real time.| +| [I4NU92](https://gitee.com/openharmony/communication_wifi/issues/I4NU92) | There is one failed test item in the Hi3516 Linux ActsLwipTest.bin test suite.| +| [I4NVCK](https://gitee.com/openharmony/applications_sample_camera/issues/I4NVCK) | Audio capture does not function properly.| +| [I4NESQ](https://gitee.com/openharmony/kernel_liteos_a/issues/I4NESQ) | An error occurs during the los_disk_cache_clear conditional compilation.| +| [I4O67U](https://gitee.com/openharmony/kernel_liteos_a/issues/I4O67U) | All processes are terminated when **Ctrl+C** is pressed.| +| [I4R4D3](https://gitee.com/openharmony/kernel_liteos_m/issues/I4R4D3) | The **detach** attribute is not set for the thread created by **pthread_create**. After the thread proactively exits and **OsGetAllTskInfo** is invoked, the related task name contains garbled characters.| +| [I4R4A5](https://gitee.com/openharmony/kernel_liteos_m/issues/I4R4A5) | Compute overflow occurs in the implementation of the **pthread_cond_timedwait** interface.| +| [I4QJT4](https://gitee.com/openharmony/drivers_adapter_khdf_linux/issues/I4QJT4) | The UartRead test case fails.| +| [I4U1DM](https://gitee.com/openharmony/distributedschedule_samgr_lite/issues/I4U1DM) | No lock is added when the LFQUE_Pop function is invoked by the QUEUE_Popfunction of samgr, causing potential data competition.| + + **Table 4** Issues resolved for the standard system + +| Issue No.| Description| +| -------- | -------- | +| [I4UJNU](https://gitee.com/openharmony/applications_settings/issues/I4UJNU) | The WLAN password is displayed in plaintext in the hilog when the WLAN is connected.| +| [I4MSWM](https://gitee.com/openharmony/xts_acts/issues/I4MSWM?from=project-issue) | During the XT test, there is one failed item in the faultloggertest case of the ActsFaultLoggerTest module.| +| [I4MSVV](https://gitee.com/openharmony/xts_acts/issues/I4MSVV?from=project-issue) | During the XTS test, there are three failed items in the HiCollieCppTest case of the ActsHiCollieCppTest module.| +| [I4PPXV](https://gitee.com/openharmony/appexecfwk_standard/issues/I4PPXV?from=project-issue) | The application icon is missing after a user opens an application, exits the application, and then returns to the home screen.| +| [I4OF9A](https://gitee.com/openharmony/distributeddatamgr_file/issues/I4OF9A?from=project-issue) | The **text** value read by the **file.readText** interface is unstable.| +| [I4OWWM](https://gitee.com/openharmony/xts_acts/issues/I4OWWM) | The JSON file corresponding to the WeekPluralNumbertest module is incorrectly configured. When a test case is executed, "required device does not exist" is reported, and the test suite cannot be executed.| +| [I4OUVQ](https://gitee.com/openharmony/xts_tools/issues/I4OUVQ?from=project-issue) | During repeated pressure tests of XTS JS cases, the system stops responding and the test cannot continue.| +| [I4NMXQ](https://gitee.com/openharmony/xts_acts/issues/I4NMXQ?from=project-issue) | The storagefileioperformancejstest and storagefilestabilityjstest test suites fail to run on XTS.| +| [I4NTKG](https://gitee.com/openharmony/xts_acts/issues/I4NTKG) | Two failed items are displayed when the XTS test suite WeekPluralNumberTest is executed.| +| [I4NPHG](https://gitee.com/openharmony/xts_acts/issues/I4NPHG?from=project-issue) | The timer test suite TimerJSApiTest.hap is not compiled with the version.| + + + **Table 5** Fixed security vulnerabilities + +| Issue No.| Description| +| -------- | -------- | +| I4QT0K | Fixed the CVE-2021-44732 and CVE-2021-45450 security vulnerabilities of the third_party_mbedtls component.| +| I4NZ16 | Upgraded the third_party_sqlite component to 3.36.0, and fixed the CVE-2021-36690 security vulnerability.| +| I4NW0B | Fixed the CVE-2021-3522 security vulnerability of the third_party_gstreamer component.| +| I4SR8C | Fixed the CVE-2021-4160 security vulnerability of the third_party_openssl component.| +| I4U4B0 | Upgraded the third_party_expat component to 2.4.1, and fixed the security vulnerabilities such as CVE-2022-25313/25314/25315/25235/252256/23990/23852/22827/46143/45960.| diff --git a/website/docs/extras/en/release-notes/Readme.md b/website/docs/extras/en/release-notes/Readme.md new file mode 100644 index 0000000000000000000000000000000000000000..8e66396dae77f634237b3c51328ba62eed2188ad --- /dev/null +++ b/website/docs/extras/en/release-notes/Readme.md @@ -0,0 +1,33 @@ +--- +title: "Readme" +prepermalink: /extras/348bb39c5ace3e332174966f24395f95/ +permalink: /extras/348bb39c5ace3e332174966f24395f95/ +relpath: "OpenHarmony-3.1-Release/en/release-notes/Readme.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [Readme] +--- +# OpenHarmony Release Notes +## OpenHarmony 3.x Releases +- [OpenHarmony 3.1 Beta (2021-12-31)](/pages/en/overview/OpenHarmony%20Release%20Notes/OpenHarmony%203.x%20Releases/OpenHarmony%20v3.1%20Beta%20%282021-12-31%29) +- [OpenHarmony 3.0.2 LTS (2022-01-12)](/extras/229818abf55130c590e32f4e82d91b32/) +- [OpenHarmony 3.0.1 LTS (2022-01-12)](/pages/en/overview/OpenHarmony%20Release%20Notes/OpenHarmony%203.x%20Releases/OpenHarmony%20v3.0.1%20LTS%20%282022-01-12%29) +- [OpenHarmony 3.0 LTS (2021-09-30)](/pages/en/overview/OpenHarmony%20Release%20Notes/OpenHarmony%203.x%20Releases/OpenHarmony%20v3.0%20LTS%20%282021-09-30%29) + +## OpenHarmony 2.x Releases +- [OpenHarmony 2.2 beta2 (2021-08-04)](/pages/en/overview/OpenHarmony%20Release%20Notes/OpenHarmony%202.x%20Releases/OpenHarmony%20v2.2%20beta2%20%282021-08-04%29) +- [OpenHarmony 2.0 Canary (2021-06-01)](/pages/en/overview/OpenHarmony%20Release%20Notes/OpenHarmony%202.x%20Releases/OpenHarmony%202.0%20Canary%20%282021-06-01%29) +## OpenHarmony 1.x Releases +- [OpenHarmony 1.1.4 LTS (2022-02-11)](/pages/en/overview/OpenHarmony%20Release%20Notes/%20OpenHarmony%201.x%20Releases/OpenHarmony%20v1.1.4%20LTS%20%282022-02-11%29) +- [OpenHarmony 1.1.3 LTS (2021-09-30)](/pages/en/overview/OpenHarmony%20Release%20Notes/%20OpenHarmony%201.x%20Releases/OpenHarmony%20v1.1.3%20LTS%20%282021-09-30%29) +- [OpenHarmony 1.1.2 LTS (2021-08-04)](/pages/en/overview/OpenHarmony%20Release%20Notes/%20OpenHarmony%201.x%20Releases/OpenHarmony%20v1.1.2%20LTS%20%282021-08-04%29) +- [OpenHarmony 1.1.1 LTS (2021-06-22)](/pages/en/overview/OpenHarmony%20Release%20Notes/%20OpenHarmony%201.x%20Releases/OpenHarmony%201.1.1%20LTS%20%282021-06-22%29) +- [OpenHarmony 1.1.0 LTS (2021-04-01)](/pages/en/overview/OpenHarmony%20Release%20Notes/%20OpenHarmony%201.x%20Releases/OpenHarmony%201.1.0%20LTS%20%282021-04-01%29) +- [OpenHarmony 1.0 (2020-09-10)](/pages/en/overview/OpenHarmony%20Release%20Notes/%20OpenHarmony%201.x%20Releases/OpenHarmony%201.0%20%282020-09-10%29) + diff --git a/website/docs/extras/en/release-notes/api-change/v3.0-LTS/js-apidiff-v3.0-lts.md b/website/docs/extras/en/release-notes/api-change/v3.0-LTS/js-apidiff-v3.0-lts.md new file mode 100644 index 0000000000000000000000000000000000000000..59dff1069bff3d4e6b132d627eaf7ee290c62139 --- /dev/null +++ b/website/docs/extras/en/release-notes/api-change/v3.0-LTS/js-apidiff-v3.0-lts.md @@ -0,0 +1,640 @@ +--- +title: "js-apidiff-v3.0-lts" +prepermalink: /extras/eecccc798c60d8ef7806efe2b724fb6c/ +permalink: /extras/eecccc798c60d8ef7806efe2b724fb6c/ +relpath: "OpenHarmony-3.1-Release/en/release-notes/api-change/v3.0-LTS/js-apidiff-v3.0-lts.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [js-apidiff-v3.0-lts] +--- +# JS API Differences +This document describes the changes of APIs in OpenHarmony 3.0 LTS when compared with OpenHarmony 2.2 Beta2. +## Standard System API Changes + +| Module| API| Change Type| Change Description| +| -------- | -------- | -------- | -------- | +|Multi-language Runtime-worker|postMessage(obj):void|Added|Used by the host thread to transfer data to the worker.| +|Multi-language Runtime-worker|postMessage(message: Object, options?: PostMessageOptions):void|Added|Used by the host thread to transfer the data control permission of the array buffer to the worker.| +|Multi-language Runtime-worker|terminate():void|Added|Used by the host thread to proactively terminate the worker.| +|Multi-language Runtime-worker|on(type: string, listener: EventListener): void|Added|Adds a callback for the worker.| +|Multi-language Runtime-worker|once(type: string, listener: EventListener): void|Added|Adds a one-shot callback for the worker.| +|Multi-language Runtime-worker|off(type: string, listener?: EventListener): void|Added|Deletes a callback added for the worker.| +|Multi-language Runtime-worker|addEventListener(type: string, listener: EventListener): void|Added|Adds a callback for the worker.| +|Multi-language Runtime-worker|removeEventListener(type: string, listener?: EventListener): void|Added|Deletes a callback added for the worker.| +|Multi-language Runtime-worker|removeAllListener(): void|Added|Deletes all callbacks added for the worker.| +|Multi-language Runtime-worker|dispatchEvent(event: Event): boolean|Added|Dispatches a specific event to the worker.| +|Multi-language Runtime-parentPort|postMessage(obj):void|Added|Used by the worker to transfer data to the host thread.| +|Multi-language Runtime-parentPort|postMessage(message: Object, options?: PostMessageOptions):void|Added|Used by the worker to transfer the data control permission of the array buffer to the host thread.| +|Multi-language Runtime-parentPort|close(): void|Added|Used by the worker to proactively terminate itself.| +|Multi-language Runtime-Util|printf(format: string, ...args: Object[]): string|Added|-| +|Multi-language Runtime-Util|getErrorString(errno: number): string|Added|-| +|Multi-language Runtime-Util|callbackWrapper(original: Function): (err: Object, value: Object) => void|Added|-| +|Multi-language Runtime-Util|promiseWrapper(original: (err: Object, value: Object) => void): Object|Added|-| +|Multi-language Runtime-Util|new TextDecoder([encoding[, options]])|Added|-| +|Multi-language Runtime-Util|decode([input[, options]]):string|Added|-| +|Multi-language Runtime-Util|new TextEncoder()|Added|-| +|Multi-language Runtime-Util|encode(input?: string): Uint8Array;|Added|-| +|Multi-language Runtime-Util|"encodeInto(input: string,dest: Uint8Array,): { read: number; written: number };"|Added|-| +|Multi-language Runtime-Util|readonly encoding: string;|Added|-| +|Multi-language Runtime-Util|readonly fatal: boolean;|Added|-| +|Multi-language Runtime-Util|readonly ignoreBOM = false;|Added|-| +|Multi-language Runtime-Util|readonly encoding = "utf-8";|Added|-| +|Multi-language Runtime-URL|new URL(url: string, base?: string/URL)|Added|-| +|Multi-language Runtime-URL|toString(): string;|Added|-| +|Multi-language Runtime-URL|toJSON(): string;|Added|-| +|Multi-language Runtime-URL|new URSearchParams()|Added|-| +|Multi-language Runtime-URL|new URSearchParams(string)|Added|-| +|Multi-language Runtime-URL|new URSearchParams(obj)|Added|-| +|Multi-language Runtime-URL|new URSearchParams(iterable)|Added|-| +|Multi-language Runtime-URL|append(name: string, value: string): void;|Added|-| +|Multi-language Runtime-URL|delete(name: string): void;|Added|-| +|Multi-language Runtime-URL|entries(): IterableIterator<[string, string]>;|Added|-| +|Multi-language Runtime-URL|forEach(callbackfn: (value: string, key: string, parent: this) => void, thisArg?: any,): void;|Added|-| +|Multi-language Runtime-URL|get(name: string): string / null;|Added|-| +|Multi-language Runtime-URL|getAll(name: string): string[];|Added|-| +|Multi-language Runtime-URL|has(name: string): boolean;|Added|-| +|Multi-language Runtime-URL|keys(): IterableIterator;|Added|-| +|Multi-language Runtime-URL|set(name: string, value: string): void;|Added|-| +|Multi-language Runtime-URL|sort():void;|Added|-| +|Multi-language Runtime-URL|toString():string|Added|-| +|Multi-language Runtime-URL|values(): IterableIterator;|Added|-| +|Multi-language Runtime-URL|URSearchParams[Symbol.iterator]()|Added|-| +|Multi-language Runtime-URL|hash: string;|Added|-| +|Multi-language Runtime-URL|host: string;|Added|-| +|Multi-language Runtime-URL|hostname: string;|Added|-| +|Multi-language Runtime-URL|href: string;|Added|-| +|Multi-language Runtime-URL|readonly origin: string;|Added|-| +|Multi-language Runtime-URL|password: string;|Added|-| +|Multi-language Runtime-URL|pathname: string;|Added|-| +|Multi-language Runtime-URL|port: string;|Added|-| +|Multi-language Runtime-URL|protocol: string;|Added|-| +|Multi-language Runtime-URL|search: string;|Added|-| +|Multi-language Runtime-URL|readonly searchParams: URLSearchParams;|Added|-| +|Multi-language Runtime-URL|username: string;|Added|-| +|Multi-language Runtime-ChildProcess|readonly pid: number;|Added|-| +|Multi-language Runtime-ChildProcess|readonly ppid: number;|Added|-| +|Multi-language Runtime-ChildProcess|readonly exitCode: number;|Added|-| +|Multi-language Runtime-ChildProcess|readonly killed: boolean;|Added|-| +|Multi-language Runtime-ChildProcess|wait(): Promise;|Added|-| +|Multi-language Runtime-ChildProcess|getOutput(): Promise;|Added|-| +|Multi-language Runtime-ChildProcess|getErrorOutput(): Promise;|Added|-| +|Multi-language Runtime-ChildProcess|close(): void;|Added|-| +|Multi-language Runtime-ChildProcess|kill(signal: number): void;|Added|-| +|Multi-language Runtime-process|runCmd(command: string,options?: { timeout : number, killSignal : number / string, maxBuffer : number }): ChildProcess;|Added|-| +|Multi-language Runtime-process|getPid(): number;|Added|-| +|Multi-language Runtime-process|getPpid(): number;|Added|-| +|Multi-language Runtime-process|abort(): void;|Added|-| +|Multi-language Runtime-process|on(type: string, listener: EventListener): void;|Added|-| +|Multi-language Runtime-process|exit(code?:number): void;|Added|-| +|Multi-language Runtime-process|cwd(): string;|Added|-| +|Multi-language Runtime-process|chdir(dir: string): void;|Added|-| +|Multi-language Runtime-process|getEgid(): number;|Added|-| +|Multi-language Runtime-process|getEuid(): number;|Added|-| +|Multi-language Runtime-process|getGid(): number|Added|-| +|Multi-language Runtime-process|getUid(): number;|Added|-| +|Multi-language Runtime-process|uptime(): number;|Added|-| +|Multi-language Runtime-process|getGroups(): number[];|Added|-| +|Multi-language Runtime-process|kill(signal?: number, pid?: number): boolean;|Added|-| +|Update Subsystem-Updater|checkNewVersion(): Promise;|Added| -| +|Update Subsystem-Updater|rebootAndCleanUserData(callback: AsyncCallback): void;|Added| -| +|Update Subsystem-Updater|rebootAndCleanCache(): Promise;|Added| -| +|Update Subsystem-Updater|function getUpdaterFromOther(device: string, updateType?: UpdateTypes): Updater;|Added| -| +|Update Subsystem-Updater|cancel(): void;|Added| -| +|Update Subsystem-Updater|upgrade(): void;|Added| -| +|Update Subsystem-Updater|off(eventType: 'downloadProgress', callback?: UpdateProgressCallback): void;|Added| -| +|Update Subsystem-Updater|getUpdatePolicy(callback: AsyncCallback): void;|Added| -| +|Update Subsystem-Updater|function getUpdaterForOther(device: string, updateType?: UpdateTypes): Updater;|Added| -| +|Update Subsystem-Updater|setUpdatePolicy(policy: UpdatePolicy, callback: AsyncCallback): void;|Added| -| +|Update Subsystem-Updater|getNewVersionInfo(): Promise;|Added| -| +|Update Subsystem-Updater|function getUpdater(updateType?: UpdateTypes): Updater;|Added| -| +|Update Subsystem-Updater|applyNewVersion(callback: AsyncCallback): void;|Added| -| +|Update Subsystem-Updater|rebootAndCleanUserData(): Promise;|Added| -| +|Update Subsystem-Updater|off(eventType: 'verifyProgress', callback?: UpdateProgressCallback): void;|Added| -| +|Update Subsystem-Updater|on(eventType: 'upgradeProgress', callback: UpdateProgressCallback): void;|Added| -| +|Update Subsystem-Updater|checkNewVersion(callback: AsyncCallback): void;|Added| -| +|Update Subsystem-Updater|on(eventType: 'downloadProgress', callback: UpdateProgressCallback): void;|Added| -| +|Update Subsystem-Updater|getUpdatePolicy(): Promise;|Added| -| +|Update Subsystem-Updater|download(): void;|Added| -| +|Update Subsystem-Updater|off(eventType: 'upgradeProgress', callback?: UpdateProgressCallback): void;|Added| -| +|Update Subsystem-Updater|getNewVersionInfo(callback: AsyncCallback): void;|Added| -| +|Update Subsystem-Updater|on(eventType: 'verifyProgress', callback: UpdateProgressCallback): void;|Added| -| +|Update Subsystem-Updater|verifyUpdatePackage(upgradeFile: string, certsFile: string): void;|Added| -| +|Update Subsystem-Updater|setUpdatePolicy(policy: UpdatePolicy): Promise;|Added| -| +|Update Subsystem-Updater|rebootAndCleanCache(callback: AsyncCallback): void;|Added| -| +|Update Subsystem-Updater|applyNewVersion(): Promise;|Added| -| +|Globalization Subsystem-I18n|getSystemLanguages(): Array;|Added| -| +|Globalization Subsystem-I18n|getSystemCountries(language: string): Array;|Added| -| +|Globalization Subsystem-I18n|isSuggested(language: string, region?: string): boolean;|Added| -| +|Globalization Subsystem-I18n|getSystemLanguage(): string;|Added| -| +|Globalization Subsystem-I18n|setSystemLanguage(language: string);|Added| -| +|Globalization Subsystem-I18n|getSystemRegion(): string;|Added| -| +|Globalization Subsystem-I18n|setSystemRegion(region: string);|Added| -| +|Globalization Subsystem-I18n|"getDisplayCountry(locale: string, displayLocale: string,sentenceCase?: boolean): string;"|Added| -| +|Globalization Subsystem-I18n|getSystemLocale(): string;|Added| -| +|Globalization Subsystem-I18n|setSystemLocale(locale: string);|Added| -| +|Globalization Subsystem-I18n|"getDisplayLanguage(locale: string, displayLocale: string,sentenceCase?: boolean): string;"|Added| -| +|Telephony Subsystem-radio|getNetworkState(callback: AsyncCallback): void;getNetworkState(slotId: number, callback: AsyncCallback): void;getNetworkState(slotId?: number): Promise;|Added| -| +|Telephony Subsystem-sim|getSimAccountInfo(slotId: number, callback: AsyncCallback): void;getSimAccountInfo(slotId: number): Promise;|Added| -| +|Telephony Subsystem-sim|getDefaultVoiceSlotId(callback: AsyncCallback): void;getDefaultVoiceSlotId(): Promise;|Added| -| +|Telephony Subsystem-sim|getSimSpn(slotId: number, callback: AsyncCallback): void;getSimSpn(slotId: number): Promise;|Added| -| +|Telephony Subsystem-sim|getISOCountryCodeForSim(slotId: number, callback: AsyncCallback): void;getISOCountryCodeForSim(slotId: number): Promise;|Added| -| +|Telephony Subsystem-sim|getSimIccId(slotId: number, callback: AsyncCallback): void;getSimIccId(slotId: number): Promise;|Added| -| +|Telephony Subsystem-sim|getSimGid1(slotId: number, callback: AsyncCallback): void;getSimGid1(slotId: number): Promise;|Added| -| +|Telephony Subsystem-sim|getISOCountryCodeForSim(slotId: number, callback: AsyncCallback): void;getISOCountryCodeForSim(slotId: number): Promise;|Added| -| +|Telephony Subsystem-sim|getSimOperatorNumeric(slotId: number, callback: AsyncCallback): void;getSimOperatorNumeric(slotId: number): Promise;|Added| -| +|Telephony Subsystem-sim|getSimSpn(slotId: number, callback: AsyncCallback): void;getSimSpn(slotId: number): Promise;|Added| -| +|Telephony Subsystem-sim|getSimIccId(slotId: number, callback: AsyncCallback): void;getSimIccId(slotId: number): Promise;|Added| -| +|Telephony Subsystem-sim|getIMSI(slotId: number, callback: AsyncCallback): void;getIMSI(slotId: number): Promise;|Added| -| +|Telephony Subsystem-call|combineConference(callId: number, callback: AsyncCallback): void;combineConference(callId: number): Promise;|Added| -| +|Telephony Subsystem-call|startDTMF(callId: number, character: string, callback: AsyncCallback): void;startDTMF(callId: number, character: string): Promise;|Added| -| +|Telephony Subsystem-call|stopDTMF(callId: number, callback: AsyncCallback): void;stopDTMF(callId: number): Promise;|Added| -| +|Telephony Subsystem-sim|setDefaultVoiceSlotId(slotId: number, callback: AsyncCallback): void;setDefaultVoiceSlotId(slotId: number): Promise;|Added| -| +|Telephony Subsystem-sim|unlockPin(slotId: number, pin: string, callback: AsyncCallback): void;unlockPin(slotId: number, pin: string): Promise;|Added| -| +|Telephony Subsystem-sim|alterPin(slotId: number, newPin: string, oldPin: string, callback: AsyncCallback): void;alterPin(slotId: number, newPin: string, oldPin: string): Promise;|Added| -| +|Telephony Subsystem-sim|setLockState(slotId: number, pin: string, enable: number, callback: AsyncCallback): void;setLockState(slotId: number, pin: string, enable: number): Promise;|Added| -| +|Telephony Subsystem-sim|getSimState(slotId: number, callback: AsyncCallback): void;getSimState(slotId: number): Promise;|Added| -| +|Telephony Subsystem-sim|getSimState(slotId: number, callback: AsyncCallback): void;getSimState(slotId: number): Promise;|Added| -| +|Telephony Subsystem-sim|getSimState(slotId: number, callback: AsyncCallback): void;getSimState(slotId: number): Promise;|Added| -| +|Telephony Subsystem-sim|getSimState(slotId: number, callback: AsyncCallback): void;getSimState(slotId: number): Promise;|Added| -| +|Telephony Subsystem-call|isEmergencyPhoneNumber(phoneNumber: string, callback: AsyncCallback): void;isEmergencyPhoneNumber(phoneNumber: string, options: EmergencyNumberOptions, callback: AsyncCallback): void;isEmergencyPhoneNumber(phoneNumber: string, options?: EmergencyNumberOptions): Promise;|Added| -| +|Telephony Subsystem-sms|createMessage(pdu: Array, specification: string, callback: AsyncCallback): void;createMessage(pdu: Array, specification: string): Promise;|Added| -| +|Telephony Subsystem-call|hasCall(callback: AsyncCallback): void;hasCall(): Promise;|Added| -| +|Telephony Subsystem-sms|sendMessage(options: SendMessageOptions): void;|Added| -| +|Telephony Subsystem-call|dial(phoneNumber: string, callback: AsyncCallback): void;dial(phoneNumber: string, options: DialOptions, callback: AsyncCallback): void;dial(phoneNumber: string, options?: DialOptions): Promise;|Added| -| +|Telephony Subsystem-call|interface DialOptions {extras?: boolean; }|Added| -| +|Telephony Subsystem-sms|sendMessage(options: SendMessageOptions): void;|Added| -| +|Telephony Subsystem-sms|getDefaultSmsSlotId(callback: AsyncCallback): void;getDefaultSmsSlotId(): Promise;|Added| -| +|Telephony Subsystem-call|formatPhoneNumber(phoneNumber: string, callback: AsyncCallback): void;formatPhoneNumber(phoneNumber: string, options: NumberFormatOptions, callback: AsyncCallback): void;formatPhoneNumber(phoneNumber: string, options?: NumberFormatOptions): Promise;|Added| -| +|Telephony Subsystem-call|formatPhoneNumber(phoneNumber: string, callback: AsyncCallback): void;formatPhoneNumber(phoneNumber: string, options: NumberFormatOptions, callback: AsyncCallback): void;formatPhoneNumber(phoneNumber: string, options?: NumberFormatOptions): Promise;|Added| -| +|Telephony Subsystem-call|formatPhoneNumberToE164(phoneNumber: string, countryCode: string, callback: AsyncCallback): void;formatPhoneNumberToE164(phoneNumber: string, countryCode: string): Promise;|Added| -| +|Telephony Subsystem-sms|setDefaultSmsSlotId(slotId: number, callback: AsyncCallback): void;setDefaultSmsSlotId(slotId: number): Promise;|Added| -| +|Telephony Subsystem-call|getCallState(callback: AsyncCallback): void;getCallState(): Promise;|Added| -| +|Telephony Subsystem-sms|setSmscAddr(slotId: number, smscAddr: string, callback: AsyncCallback): void;setSmscAddr(slotId: number, smscAddr: string): Promise;|Added| -| +|Telephony Subsystem-sms|getSmscAddr(slotId: number, callback: AsyncCallback): void;getSmscAddr(slotId: number): Promise;|Added| -| +|Telephony Subsystem-sms|addSimMessage(options: SimMessageOptions, callback: AsyncCallback): void;addSimMessage(options: SimMessageOptions): Promise;|Added| -| +|Telephony Subsystem-sms|delSimMessage(slotId: number, msgIndex: number, callback: AsyncCallback): void;delSimMessage(slotId: number, msgIndex: number): Promise;|Added| -| +|Telephony Subsystem-radio|getISOCountryCodeForNetwork(slotId: number, callback: AsyncCallback): void;getISOCountryCodeForNetwork(slotId: number): Promise;|Added| -| +|Telephony Subsystem-sms|updateSimMessage(options: UpdateSimMessageOptions, callback: AsyncCallback): void;updateSimMessage(options: UpdateSimMessageOptions): Promise;|Added| -| +|Telephony Subsystem-radio|getISOCountryCodeForNetwork(slotId: number, callback: AsyncCallback): void;getISOCountryCodeForNetwork(slotId: number): Promise;|Added| -| +|Telephony Subsystem-sms|getAllSimMessages(slotId: number, callback: AsyncCallback>): void;getAllSimMessages(slotId: number): Promise>;|Added| -| +|Telephony Subsystem-call|isInEmergencyCall(callback: AsyncCallback): void;isInEmergencyCall(): Promise;|Added| -| +|Telephony Subsystem-sms|setCBConfig(options: CBConfigOptions, callback: AsyncCallback): void;setCBConfig(options: CBConfigOptions): Promise;|Added| -| +|Telephony Subsystem-call|answer(callId: number, callback: AsyncCallback): void;answer(callId: number): Promise;|Added| -| +|Telephony Subsystem-call|hangup(callId: number, callback: AsyncCallback): void;hangup(callId: number): Promise;|Added| -| +|Telephony Subsystem-call|reject(callId: number, callback: AsyncCallback): void;reject(callId: number, options: RejectMessageOptions, callback: AsyncCallback): void;reject(callId: number, options?: RejectMessageOptions): Promise;|Added| -| +|Telephony Subsystem-call|holdCall(callId: number, callback: AsyncCallback): void;holdCall(callId: number): Promise;|Added| -| +|Telephony Subsystem-call|unHoldCall(callId: number, callback: AsyncCallback): void;unHoldCall(callId: number): Promise;|Added| -| +|Telephony Subsystem-call|switchCall(callId: number, callback: AsyncCallback): void;switchCall(callId: number): Promise;|Added| -| +|Telephony Subsystem-radio|setNetworkSelectionMode(options: NetworkSelectionModeOptions, callback: AsyncCallback): void;setNetworkSelectionMode(options: NetworkSelectionModeOptions): Promise;|Added| -| +|Telephony Subsystem-radio|getNetworkSearchInformation(slotId: number, callback: AsyncCallback): void;getNetworkSearchInformation(slotId: number): Promise;|Added| -| +|Telephony Subsystem-radio|getNetworkSelectionMode(slotId: number, callback: AsyncCallback): void;getNetworkSelectionMode(slotId: number): Promise;|Added| -| +|Telephony Subsystem-radio|isRadioOn(callback: AsyncCallback): void;isRadioOn(): Promise;|Added| -| +|Telephony Subsystem-radio|turnOnRadio(callback: AsyncCallback): void;turnOnRadio(): Promise;|Added| -| +|Telephony Subsystem-radio|turnOffRadio(callback: AsyncCallback): void;turnOffRadio(): Promise;|Added| -| +|Telephony Subsystem-radio|getSignalInformation(slotId: number, callback: AsyncCallback>): void;getSignalInformation(slotId: number): Promise>;|Added| -| +|Telephony Subsystem-radio|getRadioTech(slotId: number, callback: AsyncCallback<{psRadioTech: RadioTechnology, csRadioTech: RadioTechnology}>): void;getRadioTech(slotId: number): Promise<{psRadioTech: RadioTechnology, csRadioTech: RadioTechnology}>;|Added| -| +|Telephony Subsystem-radio|getRadioTech(slotId: number, callback: AsyncCallback<{psRadioTech: RadioTechnology, csRadioTech: RadioTechnology}>): void;getRadioTech(slotId: number): Promise<{psRadioTech: RadioTechnology, csRadioTech: RadioTechnology}>;|Added| -| +|Telephony Subsystem-radio|getRadioTech(slotId: number, callback: AsyncCallback<{psRadioTech: RadioTechnology, csRadioTech: RadioTechnology}>): void;getRadioTech(slotId: number): Promise<{psRadioTech: RadioTechnology, csRadioTech: RadioTechnology}>;|Added| -| +|Data Management-distributeddata|put(key:string, value:Uint8Array / string / boolean / number, callback: AsyncCallback):void put(key:string, value:Uint8Array / string / boolean / number):Promise|Added| -| +|Data Management-distributeddata|delete(key: string, callback: AsyncCallback): void delete(key: string): Promise|Added| -| +|Data Management-distributeddata|on(event:'dataChange', subType: SubscribeType, observer: Callback): void|Added| -| +|Data Management-distributeddata|get(key:string, callback:AsyncCallback):void get(key:string):Promise|Added| -| +|Data Management-distributeddata|sync(deviceIdList:string[], mode:SyncMode, allowedDelayMs?:number):void|Added| -| +|Data Management-distributeddata|createKVManager(config: KVManagerConfig, callback: AsyncCallback): void;createKVManager(config: KVManagerConfig): Promise;|Added| -| +|Data Management-distributeddata|getKVStore(options: Options, storeId: string): Promise;getKVStore(options: Options, storeId: string, callback: AsyncCallback): void;|Added| -| +|Data Management-distributeddata|on(event:'syncComplete', syncCallback: Callback>):void|Added| -| +|Data Management-rdb|type ValueType = number / string / boolean;|Added| -| +|Data Management-rdb|type ValuesBucket = { [key: string]: ValueType / Uint8Array / null; }|Added| -| +|Data Management-rdb|name: string;|Added| -| +|Data Management-rdb|constructor(name: string)|Added| -| +|Data Management-rdb|equalTo(field: string, value: ValueType): RdbPredicates;|Added| -| +|Data Management-rdb|notEqualTo(field: string, value: ValueType): RdbPredicates;|Added| -| +|Data Management-rdb|beginWrap(): RdbPredicates;|Added| -| +|Data Management-rdb|endWrap(): RdbPredicates;|Added| -| +|Data Management-rdb|function getRdbStore(config: StoreConfig, version: number, callback: AsyncCallback): void;function getRdbStore(config: StoreConfig, version: number): Promise;|Added| -| +|Data Management-rdb|function deleteRdbStore(name: string, callback: AsyncCallback): void;function deleteRdbStore(name: string): Promise;|Added| -| +|Data Management-rdb|insert(name: string, values: ValuesBucket, callback: AsyncCallback): void;insert(name: string, values: ValuesBucket): Promise;|Added| -| +|Data Management-rdb|update(values: ValuesBucket, rdbPredicates: RdbPredicates, callback: AsyncCallback): void;update(values: ValuesBucket, rdbPredicates: RdbPredicates): Promise;|Added| -| +|Data Management-rdb|delete(rdbPredicates: RdbPredicates, callback: AsyncCallback): void;delete(rdbPredicates: RdbPredicates): Promise;|Added| -| +|Data Management-rdb|query(rdbPredicates: RdbPredicates, columns: Array, callback: AsyncCallback): void;query(rdbPredicates: RdbPredicates, columns: Array): Promise;|Added| -| +|Data Management-rdb|executeSql(sql: string, bindArgs: Array, callback: AsyncCallback): void;executeSql(sql: string, bindArgs: Array): Promise;|Added| -| +|Data Management-rdb|like(field: string, value: string): RdbPredicates;|Added| -| +|Data Management-rdb|glob(field: string, value: string): RdbPredicates;|Added| -| +|Data Management-rdb|between(field: string, low: ValueType, high: ValueType): RdbPredicates;|Added| -| +|Data Management-rdb|notBetween(field: string, low: ValueType, high: ValueType): RdbPredicates;|Added| -| +|Data Management-rdb|greaterThan(field: string, value: ValueType): RdbPredicates;|Added| -| +|Data Management-rdb|lessThan(field: string, value: ValueType): RdbPredicates;|Added| -| +|Data Management-rdb|greaterThanOrEqualTo(field: string, value: ValueType): RdbPredicates;|Added| -| +|Data Management-rdb|lessThanOrEqualTo(field: string, value: ValueType): RdbPredicates;|Added| -| +|Data Management-rdb|or(): RdbPredicates;|Added| -| +|Data Management-rdb|and(): RdbPredicates;|Added| -| +|Data Management-rdb|contains(field: string, value: string): RdbPredicates;|Added| -| +|Data Management-rdb|beginsWith(field: string, value: string): RdbPredicates;|Added| -| +|Data Management-rdb|endsWith(field: string, value: string): RdbPredicates;|Added| -| +|Data Management-rdb|isNull(field: string): RdbPredicates;|Added| -| +|Data Management-rdb|isNotNull(field: string): RdbPredicates;|Added| -| +|Data Management-rdb|isEnded: boolean;|Added| -| +|Data Management-rdb|isStarted: boolean;|Added| -| +|Data Management-rdb|isClosed: boolean;|Added| -| +|Data Management-rdb|getColumnIndex(columnName: string): number;|Added| -| +|Data Management-rdb|getColumnName(columnIndex: number): string;|Added| -| +|Data Management-rdb|goTo(offset: number): boolean;|Added| -| +|Data Management-rdb|goToRow(position: number): boolean;|Added| -| +|Data Management-rdb|goToFirstRow(): boolean;|Added| -| +|Data Management-rdb|goToLastRow(): boolean;|Added| -| +|Data Management-rdb|goToNextRow(): boolean;|Added| -| +|Data Management-rdb|goToPreviousRow(): boolean;|Added| -| +|Data Management-rdb|getBlob(columnIndex: number): Uint8Array;|Added| -| +|Data Management-rdb|getString(columnIndex: number): string;|Added| -| +|Data Management-rdb|getLong(columnIndex: number): number;|Added| -| +|Data Management-rdb|getDouble(columnIndex: number): number;|Added| -| +|Data Management-dataAbility|orderByDesc(field: string): DataAbilityPredicates;|Added| -| +|Data Management-dataAbility|distinct(): DataAbilityPredicates;|Added| -| +|Data Management-dataAbility|limitAs(value: number): DataAbilityPredicates;|Added| -| +|Data Management-dataAbility|offsetAs(rowOffset: number): DataAbilityPredicates;|Added| -| +|Data Management-dataAbility|groupBy(fields: Array): DataAbilityPredicates;|Added| -| +|Data Management-dataAbility|indexedBy(field: string): DataAbilityPredicates;|Added| -| +|Data Management-dataAbility|in(field: string, value: Array): DataAbilityPredicates;|Added| -| +|Data Management-dataAbility|notIn(field: string, value: Array): DataAbilityPredicates;|Added| -| +|Data Management-dataAbility|glob(field: string, value: string): DataAbilityPredicates;|Added| -| +|Data Management-dataAbility|between(field: string, low: ValueType, high: ValueType): DataAbilityPredicates;|Added| -| +|Data Management-dataAbility|notBetween(field: string, low: ValueType, high: ValueType): DataAbilityPredicates;|Added| -| +|Data Management-dataAbility|greaterThan(field: string, value: ValueType): DataAbilityPredicates;|Added| -| +|Data Management-dataAbility|lessThan(field: string, value: ValueType): DataAbilityPredicates;|Added| -| +|Data Management-dataAbility|greaterThanOrEqualTo(field: string, value: ValueType): DataAbilityPredicates;|Added| -| +|Data Management-dataAbility|lessThanOrEqualTo(field: string, value: ValueType): DataAbilityPredicates;|Added| -| +|Data Management-dataAbility|orderByAsc(field: string): DataAbilityPredicates;|Added| -| +|Data Management-rdb|isColumnNull(columnIndex: number): boolean;|Added| -| +|Data Management-rdb|close(): void;|Added| -| +|Data Management-dataAbility|function createRdbPredicates(name: string, dataAbilityPredicates: DataAbilityPredicates): rdb.RdbPredicates;|Added| -| +|Data Management-dataAbility|equalTo(field: string, value: ValueType): DataAbilityPredicates;|Added| -| +|Data Management-dataAbility|notEqualTo(field: string, value: ValueType): DataAbilityPredicates;|Added| -| +|Data Management-dataAbility|beginWrap():DataAbilityPredicates;|Added| -| +|Data Management-dataAbility|endWrap(): DataAbilityPredicates;|Added| -| +|Data Management-rdb|orderByAsc(field: string): RdbPredicates;|Added| -| +|Data Management-rdb|orderByDesc(field: string): RdbPredicates;|Added| -| +|Data Management-rdb|distinct(): RdbPredicates;|Added| -| +|Data Management-rdb|limitAs(value: number): RdbPredicates;|Added| -| +|Data Management-rdb|offsetAs(rowOffset: number): RdbPredicates;|Added| -| +|Data Management-rdb|groupBy(fields: Array): RdbPredicates;|Added| -| +|Data Management-rdb|indexedBy(field: string): RdbPredicates;|Added| -| +|Data Management-dataAbility|or(): DataAbilityPredicates;|Added| -| +|Data Management-dataAbility|and(): DataAbilityPredicates;|Added| -| +|Data Management-dataAbility|contains(field: string, value: string): DataAbilityPredicates;|Added| -| +|Data Management-dataAbility|beginsWith(field: string, value: string): DataAbilityPredicates;|Added| -| +|Data Management-dataAbility|endsWith(field: string, value: string): DataAbilityPredicates;|Added| -| +|Data Management-dataAbility|isNull(field: string): DataAbilityPredicates;|Added| -| +|Data Management-dataAbility|isNotNull(field: string): DataAbilityPredicates;|Added| -| +|Data Management-dataAbility|like(field: string, value: string): DataAbilityPredicates;|Added| -| +|Data Management-rdb|in(field: string, value: Array): RdbPredicates;|Added| -| +|Data Management-rdb|notIn(field: string, value: Array): RdbPredicates;|Added| -| +|Data Management-rdb|columnNames: Array;|Added| -| +|Data Management-rdb|columnCount: number;|Added| -| +|Data Management-rdb|rowCount: number;|Added| -| +|Data Management-rdb|rowIndex: number;|Added| -| +|Data Management-rdb|isAtFirstRow: boolean;|Added| -| +|Data Management-rdb|isAtLastRow: boolean;|Added| -| +|Common Event and Notification Subsystem-notification|title: string;|Added| -| +|Common Event and Notification Subsystem-notification|sound?: string;|Added| -| +|Common Event and Notification Subsystem-notification|text: string;|Added| -| +|Common Event and Notification Subsystem-notification|vibrationValues?: Array;|Added| -| +|Common Event and Notification Subsystem-wantAgent|want?: Want;|Added| -| +|Common Event and Notification Subsystem-notification|vibrationEnabled?: boolean;|Added| -| +|Common Event and Notification Subsystem-notification|badgeFlag?: boolean;|Added| -| +|Common Event and Notification Subsystem-notification|type: notification.SlotType;|Added| -| +|Common Event and Notification Subsystem-wantAgent|code: number;|Added| -| +|Common Event and Notification Subsystem-notification|contentType: ContentType;|Added| -| +|Common Event and Notification Subsystem-notification|picture: image.PixelMap;|Added| -| +|Common Event and Notification Subsystem-notification|briefText: string;|Added| -| +|Common Event and Notification Subsystem-notification|briefText: string;|Added| -| +|Common Event and Notification Subsystem-notification|briefText: string;|Added| -| +|Common Event and Notification Subsystem-notification|bypassDnd?: boolean;|Added| -| +|Common Event and Notification Subsystem-notification|additionalText?: string;|Added| -| +|Common Event and Notification Subsystem-wantagent|function cancel(info: WantAgentInfo, callback: AsyncCallback): void;|Added| -| +|Common Event and Notification Subsystem-wantAgent|enum OperationType|Added| -| +|Common Event and Notification Subsystem-wantAgent|enum WantAgentFlags|Added| -| +|Common Event and Notification Subsystem-wantAgent|permission?: string;|Added| -| +|Common Event and Notification Subsystem-notification|picture?: NotificationPictureContent;|Added| -| +|Common Event and Notification Subsystem-notification|normal?: NotificationBasicContent;|Added| -| +|Common Event and Notification Subsystem-notification|expandedTitle: string;|Added| -| +|Common Event and Notification Subsystem-notification|expandedTitle: string;|Added| -| +|Common Event and Notification Subsystem-wantAgent|function trigger(info: WantAgentInfo, triggerInfo: TriggerInfo, callback: AsyncCallback): void;|Added| -| +|Common Event and Notification Subsystem-wantAgent|extraInfo?: {[key: string]: any};|Added| -| +|Common Event and Notification Subsystem-notification|multiLine?: NotificationMultiLineContent;|Added| -| +|Common Event and Notification Subsystem-notification|level?: notification.SlotLevel;|Added| -| +|Common Event and Notification Subsystem-notification|lightColor?: number;|Added| -| +|Common Event and Notification Subsystem-notification|lightEnabled?: boolean;|Added| -| +|Common Event and Notification Subsystem-notification|lines: Array;|Added| -| +|Common Event and Notification Subsystem-notification|lockscreenVisibility?: number;|Added| -| +|Common Event and Notification Subsystem-notification|longText: string;|Added| -| +|Common Event and Notification Subsystem-wantAgent|function getBundleName(info: WantAgentInfo, callback: AsyncCallback): void;|Added| -| +|Common Event and Notification Subsystem-notification|longText?: NotificationLongTextContent;|Added| -| +|Common Event and Notification Subsystem-notification|longTitle: string;|Added| -| +|Common Event and Notification Subsystem-wantAgent|function judgeEquality(info: WantAgentInfo, info2: WantAgentInfo, callback: AsyncCallback): void;|Added| -| +|Common Event and Notification Subsystem-wantAgent|function getUid(info: WantAgentInfo, callback: AsyncCallback): void;|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_IVI_TEMPERATURE_ABNORMAL = common.event.IVI_TEMPERATURE_ABNORMAL,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_IVI_VOLTAGE_RECOVERY = common.event.IVI_VOLTAGE_RECOVERY,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_IVI_TEMPERATURE_RECOVERY = common.event.IVI_TEMPERATURE_RECOVERY,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_IVI_ACTIVE = common.event.IVI_ACTIVE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_USB_DEVICE_ATTACHED = usual.event.hardware.usb.action.USB_DEVICE_ATTACHED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_USB_DEVICE_DETACHED = usual.event.hardware.usb.action.USB_DEVICE_DETACHED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_IVI_PAUSE = common.event.IVI_PAUSE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_IVI_STANDBY = common.event.IVI_STANDBY,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_IVI_LASTMODE_SAVE = common.event.IVI_LASTMODE_SAVE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_IVI_VOLTAGE_ABNORMAL = common.event.IVI_VOLTAGE_ABNORMAL,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_IVI_HIGH_TEMPERATURE = common.event.IVI_HIGH_TEMPERATURE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_IVI_EXTREME_TEMPERATURE = common.event.IVI_EXTREME_TEMPERATURE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_DISK_UNMOUNTABLE = usual.event.data.DISK_UNMOUNTABLE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_DISK_EJECT = usual.event.data.DISK_EJECT,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_VISIBLE_ACCOUNTS_UPDATED = usual.event.data.VISIBLE_ACCOUNTS_UPDATED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_ACCOUNT_DELETED = usual.event.data.ACCOUNT_DELETED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_FOUNDATION_READY = common.event.FOUNDATION_READY,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_AIRPLANE_MODE_CHANGED = usual.event.AIRPLANE_MODE|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_USB_ACCESSORY_ATTACHED = usual.event.hardware.usb.action.USB_ACCESSORY_ATTACHED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_USB_ACCESSORY_DETACHED = usual.event.hardware.usb.action.USB_ACCESSORY_DETACHED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_DISK_REMOVED = usual.event.data.DISK_REMOVED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_DISK_UNMOUNTED = usual.event.data.DISK_UNMOUNTED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_DISK_MOUNTED = usual.event.data.DISK_MOUNTED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_DISK_BAD_REMOVAL = usual.event.data.DISK_BAD_REMOVAL,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_NFC_ACTION_RF_FIELD_OFF_DETECTED = usual.event.nfc.action.RF_FIELD_OFF_DETECTED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_DISCHARGING = usual.event.DISCHARGING,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_CHARGING = usual.event.CHARGING,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_DEVICE_IDLE_MODE_CHANGED = usual.event.DEVICE_IDLE_MODE_CHANGED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_POWER_SAVE_MODE_CHANGED = usual.event.POWER_SAVE_MODE_CHANGED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_USER_ADDED = usual.event.USER_ADDED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_USER_REMOVED = usual.event.USER_REMOVED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_ABILITY_ADDED = common.event.ABILITY_ADDED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_ABILITY_REMOVED = common.event.ABILITY_REMOVED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_ABILITY_UPDATED = common.event.ABILITY_UPDATED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_LOCATION_MODE_STATE_CHANGED = usual.event.location.MODE_STATE_CHANGED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_IVI_SLEEP = common.event.IVI_SLEEP,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BLUETOOTH_HOST_NAME_UPDATE = usual.event.bluetooth.host.NAME_UPDATE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BLUETOOTH_A2DPSINK_CONNECT_STATE_UPDATE = usual.event.bluetooth.a2dpsink.CONNECT_STATE_UPDATE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BLUETOOTH_A2DPSINK_PLAYING_STATE_UPDATE = usual.event.bluetooth.a2dpsink.PLAYING_STATE_UPDATE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BLUETOOTH_A2DPSINK_AUDIO_STATE_UPDATE = usual.event.bluetooth.a2dpsink.AUDIO_STATE_UPDATE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_NFC_ACTION_ADAPTER_STATE_CHANGED = usual.event.nfc.action.ADAPTER_STATE_CHANGED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_NFC_ACTION_RF_FIELD_ON_DETECTED = usual.event.nfc.action.RF_FIELD_ON_DETECTED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BLUETOOTH_HOST_REQ_ENABLE = usual.event.bluetooth.host.REQ_ENABLE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BLUETOOTH_HOST_REQ_DISABLE = usual.event.bluetooth.host.REQ_DISABLE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BLUETOOTH_HOST_SCAN_MODE_UPDATE = usual.event.bluetooth.host.SCAN_MODE_UPDATE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BLUETOOTH_HOST_DISCOVERY_STARTED = usual.event.bluetooth.host.DISCOVERY_STARTED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BLUETOOTH_HOST_DISCOVERY_FINISHED = usual.event.bluetooth.host.DISCOVERY_FINISHED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_WIFI_P2P_CONN_STATE = usual.event.wifi.p2p.CONN_STATE_CHANGE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_WIFI_P2P_STATE_CHANGED = usual.event.wifi.p2p.STATE_CHANGE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_WIFI_P2P_PEERS_STATE_CHANGED = usual.event.wifi.p2p.DEVICES_CHANGE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_WIFI_P2P_CURRENT_DEVICE_STATE_CHANGED = usual.event.wifi.p2p.CURRENT_DEVICE_CHANGE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_WIFI_P2P_GROUP_STATE_CHANGED = usual.event.wifi.p2p.GROUP_STATE_CHANGED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_CONNECT_STATE_UPDATE = usual.event.bluetooth.handsfree.ag.CONNECT_STATE_UPDATE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_CURRENT_DEVICE_UPDATE = usual.event.bluetooth.handsfree.ag.CURRENT_DEVICE_UPDATE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_AUDIO_STATE_UPDATE = usual.event.bluetooth.handsfree.ag.AUDIO_STATE_UPDATE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CONNECT_STATE_UPDATE = usual.event.bluetooth.a2dpsource.CONNECT_STATE_UPDATE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CURRENT_DEVICE_UPDATE = usual.event.bluetooth.a2dpsource.CURRENT_DEVICE_UPDATE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_WIFI_RSSI_VALUE = usual.event.wifi.RSSI_VALUE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_WIFI_CONN_STATE = usual.event.wifi.CONN_STATE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_WIFI_HOTSPOT_STATE = usual.event.wifi.HOTSPOT_STATE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_WIFI_AP_STA_JOIN = usual.event.wifi.WIFI_HS_STA_JOIN,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_WIFI_AP_STA_LEAVE = usual.event.wifi.WIFI_HS_STA_LEAVE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_WIFI_MPLINK_STATE_CHANGE = usual.event.wifi.mplink.STATE_CHANGE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_HWID_LOGOUT = common.event.HWID_LOGOUT,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_HWID_TOKEN_INVALID = common.event.HWID_TOKEN_INVALID,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_HWID_LOGOFF = common.event.HWID_LOGOFF,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_WIFI_POWER_STATE = usual.event.wifi.POWER_STATE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_WIFI_SCAN_FINISHED = usual.event.wifi.SCAN_FINISHED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|clearAbortCommonEvent(): Promise;|Added| -| +|Common Event and Notification Subsystem-commonEvent|bundleName?: string;|Added| -| +|Common Event and Notification Subsystem-commonEvent|code?: number;|Added| -| +|Common Event and Notification Subsystem-commonEvent|data?: string;|Added| -| +|Common Event and Notification Subsystem-commonEvent|subscriberPermissions?: Array;|Added| -| +|Common Event and Notification Subsystem-commonEvent|isOrdered?: boolean;|Added| -| +|Common Event and Notification Subsystem-commonEvent|isSticky?: boolean;|Added| -| +|Common Event and Notification Subsystem-commonEvent|abortCommonEvent(callback: AsyncCallback): void;|Added| -| +|Common Event and Notification Subsystem-commonEvent|abortCommonEvent(): Promise;|Added| -| +|Common Event and Notification Subsystem-commonEvent|function createSubscriber(subscribeInfo: CommonEventSubscribeInfo): Promise;|Added| -| +|Common Event and Notification Subsystem-commonEvent|function createSubscriber(subscribeInfo: CommonEventSubscribeInfo, callback: AsyncCallback): void;|Added| -| +|Common Event and Notification Subsystem-commonEvent|function subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback): void;|Added| -| +|Common Event and Notification Subsystem-commonEvent|function publish(event: string, options: CommonEventPublishData, callback: AsyncCallback): void;|Added| -| +|Common Event and Notification Subsystem-commonEvent|isOrderedCommonEvent(callback: AsyncCallback): void;|Added| -| +|Common Event and Notification Subsystem-commonEvent|isOrderedCommonEvent(): Promise;|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BOOT_COMPLETED = usual.event.BOOT_COMPLETED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_LOCKED_BOOT_COMPLETED = usual.event.LOCKED_BOOT_COMPLETED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_SHUTDOWN = usual.event.SHUTDOWN,|Added| -| +|Common Event and Notification Subsystem-commonEvent|isStickyCommonEvent(): Promise;|Added| -| +|Common Event and Notification Subsystem-commonEvent|getData(callback: AsyncCallback): void;|Added| -| +|Common Event and Notification Subsystem-commonEvent|getData(): Promise;|Added| -| +|Common Event and Notification Subsystem-commonEvent|getSubscribeInfo(callback: AsyncCallback): void;|Added| -| +|Common Event and Notification Subsystem-commonEvent|getSubscribeInfo(): Promise;|Added| -| +|Common Event and Notification Subsystem-commonEvent|function publish(event: string, callback: AsyncCallback): void;|Added| -| +|Common Event and Notification Subsystem-commonEvent|event: string|Added| -| +|Common Event and Notification Subsystem-commonEvent|bundleName?: string;|Added| -| +|Common Event and Notification Subsystem-commonEvent|code?: number;|Added| -| +|Common Event and Notification Subsystem-commonEvent|data?: string;|Added| -| +|Common Event and Notification Subsystem-commonEvent|setCode(code: number, callback: AsyncCallback): void;|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_DRIVE_MODE = common.event.DRIVE_MODE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_HOME_MODE = common.event.HOME_MODE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_OFFICE_MODE = common.event.OFFICE_MODE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_USER_STARTED = usual.event.USER_STARTED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_USER_BACKGROUND = usual.event.USER_BACKGROUND,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_USER_FOREGROUND = usual.event.USER_FOREGROUND,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_USER_SWITCHED = usual.event.USER_SWITCHED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_USER_STARTING = usual.event.USER_STARTING,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_USER_UNLOCKED = usual.event.USER_UNLOCKED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_USER_STOPPING = usual.event.USER_STOPPING,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_USER_STOPPED = usual.event.USER_STOPPED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_HWID_LOGIN = common.event.HWID_LOGIN,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_PACKAGE_VERIFIED = usual.event.PACKAGE_VERIFIED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_EXTERNAL_APPLICATIONS_AVAILABLE = usual.event.EXTERNAL_APPLICATIONS_AVAILABLE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_EXTERNAL_APPLICATIONS_UNAVAILABLE = usual.event.EXTERNAL_APPLICATIONS_UNAVAILABLE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_CONFIGURATION_CHANGED = usual.event.CONFIGURATION_CHANGED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_LOCALE_CHANGED = usual.event.LOCALE_CHANGED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_MANAGE_PACKAGE_STORAGE = usual.event.MANAGE_PACKAGE_STORAGE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_PACKAGES_UNSUSPENDED = usual.event.PACKAGES_UNSUSPENDED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_MY_PACKAGE_SUSPENDED = usual.event.MY_PACKAGE_SUSPENDED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_MY_PACKAGE_UNSUSPENDED = usual.event.MY_PACKAGE_UNSUSPENDED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_UID_REMOVED = usual.event.UID_REMOVED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_PACKAGE_FIRST_LAUNCH = usual.event.PACKAGE_FIRST_LAUNCH,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_PACKAGE_NEEDS_VERIFICATION = usual.event.PACKAGE_NEEDS_VERIFICATION,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_SCREEN_OFF = usual.event.SCREEN_OFF,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_SCREEN_ON = usual.event.SCREEN_ON,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_USER_PRESENT = usual.event.USER_PRESENT,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_TIME_TICK = usual.event.TIME_TICK,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_TIME_CHANGED = usual.event.TIME_CHANGED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_DATE_CHANGED = usual.event.DATE_CHANGED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BATTERY_CHANGED = usual.event.BATTERY_CHANGED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BATTERY_LOW = usual.event.BATTERY_LOW,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BATTERY_OKAY = usual.event.BATTERY_OKAY,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_POWER_CONNECTED = usual.event.POWER_CONNECTED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_POWER_DISCONNECTED = usual.event.POWER_DISCONNECTED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|function unsubscribe(subscriber: CommonEventSubscriber, callback?: AsyncCallback): void;|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_ACL_CONNECTED = usual.event.bluetooth.remotedevice.ACL_CONNECTED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_ACL_DISCONNECTED = usual.event.bluetooth.remotedevice.ACL_DISCONNECTED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|getAbortCommonEvent(callback: AsyncCallback): void;|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_NAME_UPDATE = usual.event.bluetooth.remotedevice.NAME_UPDATE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|getAbortCommonEvent(): Promise;|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_CONNECT_STATE_UPDATE = usual.event.bluetooth.handsfreeunit.CONNECT_STATE_UPDATE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIR_STATE = usual.event.bluetooth.remotedevice.PAIR_STATE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|getCode(callback: AsyncCallback): void;|Added| -| +|Common Event and Notification Subsystem-commonEvent|setCode(code: number): Promise;|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_AUDIO_STATE_UPDATE = usual.event.bluetooth.handsfreeunit.AUDIO_STATE_UPDATE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_BATTERY_VALUE_UPDATE = usual.event.bluetooth.remotedevice.BATTERY_VALUE_UPDATE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|getCode(): Promise;|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_AG_COMMON_EVENT = usual.event.bluetooth.handsfreeunit.AG_COMMON_EVENT,|Added| -| +|Common Event and Notification Subsystem-commonEvent|setCodeAndData(code: number, data: string, callback: AsyncCallback): void;|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_SDP_RESULT = usual.event.bluetooth.remotedevice.SDP_RESULT,|Added| -| +|Common Event and Notification Subsystem-commonEvent|isStickyCommonEvent(callback: AsyncCallback): void;|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BLUETOOTH_HANDSFREEUNIT_AG_CALL_STATE_UPDATE = usual.event.bluetooth.handsfreeunit.AG_CALL_STATE_UPDATE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|setCodeAndData(code: number, data: string): Promise;|Added| -| +|Common Event and Notification Subsystem-commonEvent|events: Array;|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BLUETOOTH_HOST_STATE_UPDATE = usual.event.bluetooth.host.STATE_UPDATE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BLUETOOTH_A2DPSOURCE_PLAYING_STATE_UPDATE = usual.event.bluetooth.a2dpsource.PLAYING_STATE_UPDATE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|setData(data: string, callback: AsyncCallback): void;|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BLUETOOTH_A2DPSOURCE_AVRCP_CONNECT_STATE_UPDATE = usual.event.bluetooth.a2dpsource.AVRCP_CONNECT_STATE_UPDATE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BLUETOOTH_HOST_REQ_DISCOVERABLE = usual.event.bluetooth.host.REQ_DISCOVERABLE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|publisherPermission?: string;|Added| -| +|Common Event and Notification Subsystem-commonEvent|setData(data: string): Promise;|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_UUID_VALUE = usual.event.bluetooth.remotedevice.UUID_VALUE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|publisherDeviceId?: string;|Added| -| +|Common Event and Notification Subsystem-commonEvent|clearAbortCommonEvent(callback: AsyncCallback): void;|Added| -| +|Common Event and Notification Subsystem-commonEvent|userId?: number;|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_TIMEZONE_CHANGED = usual.event.TIMEZONE_CHANGED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIRING_REQ = usual.event.bluetooth.remotedevice.PAIRING_REQ,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_DISCOVERED = usual.event.bluetooth.remotedevice.DISCOVERED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|priority?: number;|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BUNDLE_REMOVED = usual.event.BUNDLE_REMOVED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CLASS_VALUE_UPDATE = usual.event.bluetooth.remotedevice.CLASS_VALUE_UPDATE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIRING_CANCEL = usual.event.bluetooth.remotedevice.PAIRING_CANCEL,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_CLOSE_SYSTEM_DIALOGS = usual.event.CLOSE_SYSTEM_DIALOGS,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_PACKAGE_ADDED = usual.event.PACKAGE_ADDED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CONNECT_REQ = usual.event.bluetooth.remotedevice.CONNECT_REQ,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_PACKAGE_FULLY_REMOVED = usual.event.PACKAGE_FULLY_REMOVED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_PACKAGE_REPLACED = usual.event.PACKAGE_REPLACED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CONNECT_REPLY = usual.event.bluetooth.remotedevice.CONNECT_REPLY,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_MY_PACKAGE_REPLACED = usual.event.MY_PACKAGE_REPLACED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_PACKAGE_CHANGED = usual.event.PACKAGE_CHANGED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_CONNECT_CANCEL = usual.event.bluetooth.remotedevice.CONNECT_CANCEL,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_PACKAGE_REMOVED = usual.event.PACKAGE_REMOVED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_PACKAGE_RESTARTED = usual.event.PACKAGE_RESTARTED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_PACKAGE_DATA_CLEARED = usual.event.PACKAGE_DATA_CLEARED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_PACKAGES_SUSPENDED = usual.event.PACKAGES_SUSPENDED,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CODEC_VALUE_UPDATE = usual.event.bluetooth.a2dpsource.CODEC_VALUE_UPDATE,|Added| -| +|Common Event and Notification Subsystem-commonEvent|COMMON_EVENT_WIFI_P2P_PEERS_DISCOVERY_STATE_CHANGED = usual.event.wifi.p2p.PEER_DISCOVERY_STATE_CHANGE,|Added| -| +|Common Event and Notification Subsystem-notification|LEVEL_NONE = 0,|Added| -| +|Common Event and Notification Subsystem-notification|LEVEL_MIN = 1,|Added| -| +|Common Event and Notification Subsystem-notification|LEVEL_LOW = 2,|Added| -| +|Common Event and Notification Subsystem-notification|LEVEL_DEFAULT = 3,|Added| -| +|Common Event and Notification Subsystem-notification|label?: string;|Added| -| +|Common Event and Notification Subsystem-notification|bundle: string;|Added| -| +|Common Event and Notification Subsystem-notification|uid?: number;|Added| -| +|Common Event and Notification Subsystem-notification|NOTIFICATION_CONTENT_MULTILINE,|Added| -| +|Common Event and Notification Subsystem-notification|UNKNOWN_TYPE = 0,|Added| -| +|Common Event and Notification Subsystem-notification|SOCIAL_COMMUNICATION = 1,|Added| -| +|Common Event and Notification Subsystem-notification|LEVEL_HIGH = 4,|Added| -| +|Common Event and Notification Subsystem-notification|NOTIFICATION_CONTENT_BASIC_TEXT,|Added| -| +|Common Event and Notification Subsystem-notification|NOTIFICATION_CONTENT_LONG_TEXT,|Added| -| +|Common Event and Notification Subsystem-notification|NOTIFICATION_CONTENT_PICTURE,|Added| -| +|Common Event and Notification Subsystem-notification|isFloatingIcon?: boolean;|Added| -| +|Common Event and Notification Subsystem-notification|label?: string;|Added| -| +|Common Event and Notification Subsystem-notification|badgeIconStyle?: number;|Added| -| +|Common Event and Notification Subsystem-notification|showDeliveryTime?: boolean;|Added| -| +|Common Event and Notification Subsystem-notification|isAlertOnce?: boolean;|Added| -| +|Common Event and Notification Subsystem-notification|function getActiveNotifications(callback: AsyncCallback>): void;|Added| -| +|Common Event and Notification Subsystem-notification|isStopwatch?: boolean;|Added| -| +|Common Event and Notification Subsystem-notification|isCountDown?: boolean;|Added| -| +|Common Event and Notification Subsystem-notification|function getActiveNotifications(): Promise>;|Added| -| +|Common Event and Notification Subsystem-notification|function getActiveNotificationCount(callback: AsyncCallback): void;|Added| -| +|Common Event and Notification Subsystem-notification|readonly creatorUid?: number;|Added| -| +|Common Event and Notification Subsystem-notification|function getActiveNotificationCount(): Promise;|Added| -| +|Common Event and Notification Subsystem-notification|readonly creatorPid?: number;|Added| -| +|Common Event and Notification Subsystem-notification|function cancel(id: number, label?: string): Promise;|Added| -| +|Common Event and Notification Subsystem-notification|classification?: string;|Added| -| +|Common Event and Notification Subsystem-notification|readonly hashCode?: string;|Added| -| +|Common Event and Notification Subsystem-notification|function cancelAll(callback: AsyncCallback): void;|Added| -| +|Common Event and Notification Subsystem-notification|actionButtons?: Array;|Added| -| +|Common Event and Notification Subsystem-notification|function cancelAll(): Promise;|Added| -| +|Common Event and Notification Subsystem-notification|smallIcon?: image.PixelMap;|Added| -| +|Common Event and Notification Subsystem-notification|isUnremovable?: boolean;|Added| -| +|Common Event and Notification Subsystem-notification|largeIcon?: image.PixelMap;|Added| -| +|Common Event and Notification Subsystem-notification|deliveryTime?: number;|Added| -| +|Common Event and Notification Subsystem-notification|readonly creatorBundleName?: string;|Added| -| +|Common Event and Notification Subsystem-notification|tapDismissed?: boolean;|Added| -| +|Common Event and Notification Subsystem-notification|function publish(request: NotificationRequest): Promise;|Added| -| +|Common Event and Notification Subsystem-notification|autoDeletedTime?: number;|Added| -| +|Common Event and Notification Subsystem-notification|function cancel(id: number, callback: AsyncCallback): void;|Added| -| +|Common Event and Notification Subsystem-notification|content: NotificationContent;|Added| -| +|Common Event and Notification Subsystem-notification|wantAgent?: WantAgentInfo;|Added| -| +|Common Event and Notification Subsystem-notification|function cancel(id: number, label: string, callback: AsyncCallback): void;|Added| -| +|Common Event and Notification Subsystem-notification|function getSlot(slotType: SlotType, callback: AsyncCallback): void;|Added| -| +|Common Event and Notification Subsystem-notification|extraInfo?: {[key: string]: any};|Added| -| +|Common Event and Notification Subsystem-notification|function getSlot(slotType: SlotType): Promise;|Added| -| +|Common Event and Notification Subsystem-notification|SERVICE_INFORMATION = 2,|Added| -| +|Common Event and Notification Subsystem-notification|color?: number;|Added| -| +|Common Event and Notification Subsystem-notification|id?: number;|Added| -| +|Common Event and Notification Subsystem-notification|function getSlots(callback: AsyncCallback>): void;|Added| -| +|Common Event and Notification Subsystem-notification|CONTENT_INFORMATION = 3,|Added| -| +|Common Event and Notification Subsystem-notification|slotType?: notification.SlotType;|Added| -| +|Common Event and Notification Subsystem-notification|colorEnabled?: boolean;|Added| -| +|Common Event and Notification Subsystem-notification|OTHER_TYPES = 0xFFFF,|Added| -| +|Common Event and Notification Subsystem-notification|isOngoing?: boolean;|Added| -| +|Common Event and Notification Subsystem-notification|function addSlot(type: SlotType, callback: AsyncCallback): void;|Added| -| +|Common Event and Notification Subsystem-notification|id: number;|Added| -| +|Common Event and Notification Subsystem-notification|function addSlot(type: SlotType): Promise;|Added| -| +|Common Event and Notification Subsystem-notification|desc?: string;|Added| -| +|Common Event and Notification Subsystem-notification|function publish(request: NotificationRequest, callback: AsyncCallback): void;|Added| -| +|Common Event and Notification Subsystem-notification|function removeAllSlots(callback: AsyncCallback): void;|Added| -| +|Common Event and Notification Subsystem-notification|function removeAllSlots(): Promise;|Added| -| +|Common Event and Notification Subsystem-notification|function getSlots(): Promise>;|Added| -| +|Common Event and Notification Subsystem-notification|function removeSlot(slotType: SlotType, callback: AsyncCallback): void;|Added| -| +|Common Event and Notification Subsystem-notification|function removeSlot(slotType: SlotType): Promise;|Added| -| +|Globalization Subsystem-resourceManager|getString(resId: number, callback: AsyncCallback);getString(resId: number): Promise;|Added| -| +|Globalization Subsystem-resourceManager|getStringArray(resId: number, callback: AsyncCallback>);getStringArray(resId: number): Promise>;|Added| -| +|Globalization Subsystem-resourceManager|getConfiguration(callback: AsyncCallback);getConfiguration(): Promise;|Added| -| +|Globalization Subsystem-resourceManager|getDeviceCapability(callback: AsyncCallback);getDeviceCapability(): Promise;|Added| -| +|Globalization Subsystem-resourceManager|getMedia(resId: number, callback: AsyncCallback);getMedia(resId: number): Promise;getMediaBase64(resId: number, callback: AsyncCallback);getMediaBase64(resId: number): Promise;|Added| -| +|Globalization Subsystem-resourceManager|"getPluralString(resId: number, num: number, callback: AsyncCallback);getPluralString(resId: number, num: number): Promise;"|Added| -| +|Globalization Subsystem-resourceManager|DeviceCapability|Added| -| +|Globalization Subsystem-resourceManager|"getMediaBase64(resId: number, callback: AsyncCallback);getMediaBase64(resId: number): Promise;"|Added| -| +|Globalization Subsystem-resourceManager|"getResourceManager(callback: AsyncCallback);getResourceManager(bundleName: string, callback: AsyncCallback);getResourceManager(): Promise;getResourceManager(bundleName: string): Promise;"|Added| -| +|Globalization Subsystem-resourceManager|DeviceType|Added| -| +|Globalization Subsystem-resourceManager|Direction|Added| -| +|Globalization Subsystem-resourceManager|Configuration|Added| -| +|Globalization Subsystem-resourceManager|ScreenDensity|Added| -| +|Globalization Subsystem-resourceManager|deviceType|Added| -| +|Globalization Subsystem-resourceManager|locale|Added| -| +|Globalization Subsystem-resourceManager|direction|Added| -| +|Globalization Subsystem-resourceManager|screenDensity|Added| -| +|Power Management Subsystem-batteryInfo|batteryInfo:const batterySOC: number;|Added| -| +|Power Management Subsystem-batteryInfo|batteryInfo:const technology: string;|Added| -| +|Power Management Subsystem-batteryInfo|batteryInfo:const isBatteryPresent: boolean;|Added| -| +|Power Management Subsystem-batteryInfo|batteryInfo:const batteryTemperature: number;|Added| -| +|Power Management Subsystem-batteryInfo|batteryInfo:const pluggedType: BatteryPluggedType;|Added| -| +|Power Management Subsystem-batteryInfo|batteryInfo:const chargingStatus: BatteryChargeState;|Added| -| +|Power Management Subsystem-batteryInfo|batteryInfo:const healthStatus: BatteryHealthState;|Added| -| +|Power Management Subsystem-batteryInfo|batteryInfo:const voltage: number;|Added| -| +|Power Management Subsystem-batteryInfo|BatteryChargeState:NONE|Added| -| +|Power Management Subsystem-batteryInfo|BatteryChargeState:DISABLE|Added| -| +|Power Management Subsystem-batteryInfo|BatteryChargeState:ENABLE,|Added| -| +|Power Management Subsystem-batteryInfo|BatteryChargeState:FULL|Added| -| +|Power Management Subsystem-batteryInfo|BatteryHealthState:COLD|Added| -| +|Power Management Subsystem-batteryInfo|BatteryHealthState:OVERHEAT|Added| -| +|Power Management Subsystem-batteryInfo|BatteryHealthState:OVERVOLTAGE|Added| -| +|Power Management Subsystem-batteryInfo|BatteryHealthState:DEAD|Added| -| +|Power Management Subsystem-batteryInfo|BatteryHealthState:UNKNOWN|Added| -| +|Power Management Subsystem-batteryInfo|BatteryHealthState:GOOD|Added| -| +|Power Management Subsystem-batteryInfo|BatteryPluggedType:WIRELESS|Added| -| +|Power Management Subsystem-batteryInfo|BatteryPluggedType:NONE|Added| -| +|Power Management Subsystem-batteryInfo|BatteryPluggedType:AC|Added| -| +|Power Management Subsystem-batteryInfo|BatteryPluggedType:USB|Added| -| +|Power Management Subsystem-runningLock|RunningLock:unlock()|Added| -| +|Power Management Subsystem-runningLock|runningLock:isRunningLockTypeSupported(type: RunningLockType, callback: AsyncCallback): void;|Added| -| +|Power Management Subsystem-runningLock|runningLock:createRunningLock(name: string, type: runningLockType): RunningLock|Added| -| +|Power Management Subsystem-runningLock|RunningLock:lock(timeout: number)|Added| -| +|Power Management Subsystem-runningLock|RunningLock:isUsed(): boolean|Added| -| +|Power Management Subsystem-runninglock|RunningLockType:BACKGROUND|Added| -| +|Power Management Subsystem-runninglock|RunningLockType:PROXIMITY_SCREEN_CONTROL|Added| -| +|Power Management Subsystem-power|power:rebootDevice(reason ?: string)|Added| -| +|Power Management Subsystem-power|power:isScreenOn(callback: AsyncCallback): void;|Added| -| diff --git a/website/docs/extras/en/release-notes/api-change/v3.1-LTS/js-apidiff-v3.1-LTS.md b/website/docs/extras/en/release-notes/api-change/v3.1-LTS/js-apidiff-v3.1-LTS.md new file mode 100644 index 0000000000000000000000000000000000000000..293a2cc4cca37b12a5b090fbdf7688d9f7d13ad1 --- /dev/null +++ b/website/docs/extras/en/release-notes/api-change/v3.1-LTS/js-apidiff-v3.1-LTS.md @@ -0,0 +1,29 @@ +--- +title: "js-apidiff-v3.1-LTS" +prepermalink: /extras/6a7f280002c78f7e8a0933f7f3bb475a/ +permalink: /extras/6a7f280002c78f7e8a0933f7f3bb475a/ +relpath: "OpenHarmony-3.1-Release/en/release-notes/api-change/v3.1-LTS/js-apidiff-v3.1-LTS.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [js-apidiff-v3.1-LTS] +--- +# JS API Diff + +This document describes the changes of APIs in OpenHarmony 3.1 LTS when compared with OpenHarmony 3.1 Beta. + +## API Changes + +| Module| API| Change Type| Change Description| +| -------- | -------- | -------- | -------- | +| Distributed Hardware Subsystem - DeviceManager| release(): void | Deleted| This API is deleted to reduce security risks.| +| Distributed Hardware Subsystem - DeviceManager| getTrustedDeviceListSync(): Array | Deleted| This API is deleted to reduce security risks.| +| Distributed Hardware Subsystem - DeviceManager| on(type: 'deviceStateChange', callback: Callback<{ action: DeviceStateChangeAction, device: DeviceInfo }>): void | Deleted| This API is deleted to reduce security risks.| +| Distributed Hardware Subsystem - DeviceManager| off(type: 'deviceStateChange', callback?: Call back<{ action: DeviceStateChangeAction, device: DeviceInfo }>): void | Deleted| This API is deleted to reduce security risks.| +| Distributed Hardware Subsystem - DeviceManager| on(type: 'serviceDie', callback: () => void): void | Deleted| This API is deleted to reduce security risks.| +| Distributed Hardware Subsystem - DeviceManager| off(type: 'serviceDie', callback?: () => void): void | Deleted| This API is deleted to reduce security risks.| diff --git a/website/docs/extras/en/release-notes/api-change/v3.1-beta/changelog-v3.1-beta.md b/website/docs/extras/en/release-notes/api-change/v3.1-beta/changelog-v3.1-beta.md new file mode 100644 index 0000000000000000000000000000000000000000..4b9be2fc3f5d5db8a1d617380437b31d61edbdcf --- /dev/null +++ b/website/docs/extras/en/release-notes/api-change/v3.1-beta/changelog-v3.1-beta.md @@ -0,0 +1,57 @@ +--- +title: "changelog-v3.1-beta" +prepermalink: /extras/2457499784394bf04f09974b72c4620f/ +permalink: /extras/2457499784394bf04f09974b72c4620f/ +relpath: "OpenHarmony-3.1-Release/en/release-notes/api-change/v3.1-beta/changelog-v3.1-beta.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [changelog-v3.1-beta] +--- +# Changelog +##### Key API/Component Changes +## IPC Subsystem +#### cl.rpc.1 sendRequest Return Value Type Change + +##### Change Impact + +The **sendRequest** method in the JS modules **RemoteProxy** and **RemoteObject** is changed to an asynchronous interface. The new version uses a **Promise** object to return a **SendRequestResult** instance. Existing applications need to be adapted. + +##### Key API/Component Changes + +``` +Module: ohos.rpc.IRemoteObject, ohos.rpc.RemoteProxy and ohos.rpc.RemoteObject +Old method: sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): boolean + +New method: +sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): Promise +``` + +**Adaptation Guidelines** + +``` +import rpc from "@ohos.rpc" + +let option = new rpc.MessageOption() +let data = rpc.MessageParcel.create() +let reply = rpc.MessageParcel.create() +proxy.sendRequest(1, data, reply, option) + .then(function(result) { + console.info("send request done") + if (result.errCode === 0) { + // read result from result.reply + } + }) + .catch(function(e) { + console.error("send request failed: " + e) + }) + .finally(() => { + data.reclaim() + reply.reclaim() + }) +``` diff --git a/website/docs/extras/en/release-notes/api-change/v3.1-beta/js-apidiff-v3.1-beta.md b/website/docs/extras/en/release-notes/api-change/v3.1-beta/js-apidiff-v3.1-beta.md new file mode 100644 index 0000000000000000000000000000000000000000..977e080ad56a51ab83e0bbc29cee8c2d26eff21e --- /dev/null +++ b/website/docs/extras/en/release-notes/api-change/v3.1-beta/js-apidiff-v3.1-beta.md @@ -0,0 +1,442 @@ +--- +title: "js-apidiff-v3.1-beta" +prepermalink: /extras/06a9a16aab5351049eed92b525958d28/ +permalink: /extras/06a9a16aab5351049eed92b525958d28/ +relpath: "OpenHarmony-3.1-Release/en/release-notes/api-change/v3.1-beta/js-apidiff-v3.1-beta.md" +navbar: true +sidebar: false +prev: false +next: false +search: false +article: false +comment: false +editLink: false +categories: [js-apidiff-v3.1-beta] +--- +# JS API Differences + +This document describes the changes of APIs in OpenHarmony 3.1 Beta when compared with OpenHarmony 3.0 LTS. + +## Standard System API Changes + +| Module| API| Change Type| Change Description| +| -------- | -------- | -------- | -------- | +| System Application - settings| getUri(name: string): string | Added| Added the API for obtaining the URI of a string.| +| System Application - settings| getValue(dataAbilityHelper: DataAbilityHelper, name: string, defValue: string): string | Added| Added the API for obtaining the value of a string in the database.| +| System Application - settings| setValue(dataAbilityHelper: DataAbilityHelper, name: string, value: string): boolean | Added| Added the API for saving a string name and its value in the database.| +| Misc Services - systemTime| getCurrentTime(callback: AsyncCallback): void | Added| Added the API for obtaining the number of milliseconds elapsed since the Unix epoch.| +| Misc Services - systemTime| getCurrentTime(): Promise | Added| Added the API for obtaining the number of milliseconds elapsed since the Unix epoch.| +| Misc Services - systemTime| getCurrentTimeNs(callback: AsyncCallback): void | Added| Added the API for obtaining the number of nanoseconds elapsed since the Unix epoch.| +| Misc Services - systemTime| getCurrentTimeNs(): Promise | Added| Added the API for obtaining the number of nanoseconds elapsed since the Unix epoch.| +| Misc Services - systemTime| getRealActiveTime(callback: AsyncCallback): void | Added| Added the API for obtaining the number of milliseconds elapsed since the system boot, excluding the deep sleep time.| +| Misc Services - systemTime| getRealActiveTime(): Promise | Added| Added the API for obtaining the number of milliseconds elapsed since the system boot, excluding the deep sleep time.| +| Misc Services - systemTime| getRealActiveTimeNs(callback: AsyncCallback): void | Added| Added the API for obtaining the number of nanoseconds elapsed since the system boot, excluding the deep sleep time.| +| Misc Services - systemTime| getRealActiveTimeNs(): Promise | Added| Added the API for obtaining the number of nanoseconds elapsed since the system boot, excluding the deep sleep time.| +| Misc Services - systemTime| getRealTime(callback: AsyncCallback): void | Added| Added the API for obtaining the number of milliseconds elapsed since the system boot, including the deep sleep time.| +| Misc Services - systemTime| getRealTime(): Promise | Added| Added the API for obtaining the number of milliseconds elapsed since the system boot, including the deep sleep time.| +| Misc Services - systemTime| getRealTimeNs(callback: AsyncCallback): void | Added| Added the API for obtaining the number of nanoseconds elapsed since the system boot, including the deep sleep time.| +| Misc Services - systemTime| getRealTimeNs(): Promise | Added| Added the API for obtaining the number of nanoseconds elapsed since the system boot, including the deep sleep time.| +| Misc Services - systemTime| getDate(callback: AsyncCallback): void | Added| Added the API for obtaining the system date.| +| Misc Services - systemTime| getDate(): Promise | Added| Added the API for obtaining the system date.| +| Misc Services - systemTime| getTimeZone(callback: AsyncCallback): void | Added| Added the API for obtaining the system time zone.| +| Misc Services - systemTime| getTimeZone(): Promise | Added| Added the API for obtaining the system time zone.| +| ArkUI Framework - Universal Events| onAreaChange (Component Area Change Event)| Added| Added the API for subscribing to component area (including the size and position) changes.| +| ArkUI Framework - Universal Attributes| responseRegion| Added| Added the attribute for touch hotspot settings.| +| ArkUI Framework - Universal Attributes| touchable| Added| Added the attribute that specifies whether a component is touchable.| +| ArkUI Framework - Universal Attributes| stateStyle| Added| Added the attribute that specifies the styles of the pressed and disabled states of a component.| +| ArkUI Framework - Basic Gestures| SwipeGesture | Added| Added the SwipeGesture module.| +| ArkUI Framework - Basic Components| Marquee | Added| Added the **\** component.| +| ArkUI Framework - Basic Components| PluginComponent | Added| Added the **\** component.| +| ArkUI Framework - Basic Components| TextArea | Added| Added the **\